@surething/cockpit 1.1.8 → 1.1.9

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 (598) hide show
  1. package/.next-prod/BUILD_ID +1 -1
  2. package/.next-prod/app-path-routes-manifest.json +9 -5
  3. package/.next-prod/build-manifest.json +2 -2
  4. package/.next-prod/cockpit-build.json +1 -1
  5. package/.next-prod/prerender-manifest.json +3 -3
  6. package/.next-prod/routes-manifest.json +24 -0
  7. package/.next-prod/server/app/_global-error/page.js +2 -2
  8. package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
  9. package/.next-prod/server/app/_global-error.html +1 -1
  10. package/.next-prod/server/app/_global-error.rsc +1 -1
  11. package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
  12. package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  13. package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/.next-prod/server/app/_not-found/page.js +1 -1
  15. package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
  16. package/.next-prod/server/app/api/agent/test/route.js +1 -1
  17. package/.next-prod/server/app/api/bash/route.js +1 -1
  18. package/.next-prod/server/app/api/bots/[id]/route.js +1 -1
  19. package/.next-prod/server/app/api/bots/files/route.js +1 -1
  20. package/.next-prod/server/app/api/bots/route.js +1 -1
  21. package/.next-prod/server/app/api/chat/codex/route.js +1 -1
  22. package/.next-prod/server/app/api/chat/deepseek/route.js +1 -1
  23. package/.next-prod/server/app/api/chat/glm/route.js +1 -1
  24. package/.next-prod/server/app/api/chat/grok/route.js +1 -1
  25. package/.next-prod/server/app/api/chat/kimi/route.js +1 -1
  26. package/.next-prod/server/app/api/chat/ollama/route.js +1 -1
  27. package/.next-prod/server/app/api/chat/route.js +1 -1
  28. package/.next-prod/server/app/api/chat/stop/route.js +1 -1
  29. package/.next-prod/server/app/api/claude-stats/route.js +1 -1
  30. package/.next-prod/server/app/api/commands/route.js +1 -1
  31. package/.next-prod/server/app/api/comments/route.js +1 -1
  32. package/.next-prod/server/app/api/db/columns/route.js +1 -1
  33. package/.next-prod/server/app/api/db/connect/route.js +1 -1
  34. package/.next-prod/server/app/api/db/disconnect/route.js +1 -1
  35. package/.next-prod/server/app/api/db/export/route.js +1 -1
  36. package/.next-prod/server/app/api/db/query/route.js +1 -1
  37. package/.next-prod/server/app/api/db/schemas/route.js +2 -2
  38. package/.next-prod/server/app/api/deepseek/balance/route.js +1 -1
  39. package/.next-prod/server/app/api/deepseek/credentials/route.js +1 -1
  40. package/.next-prod/server/app/api/deepseek/models/route.js +1 -1
  41. package/.next-prod/server/app/api/dev/spans/route.js +1 -1
  42. package/.next-prod/server/app/api/extension/version/route.js +1 -1
  43. package/.next-prod/server/app/api/file/route.js +1 -1
  44. package/.next-prod/server/app/api/files/blame/route.js +1 -1
  45. package/.next-prod/server/app/api/files/clipboard/route.js +1 -1
  46. package/.next-prod/server/app/api/files/copy/route.js +1 -1
  47. package/.next-prod/server/app/api/files/delete/route.js +1 -1
  48. package/.next-prod/server/app/api/files/expanded/route.js +1 -1
  49. package/.next-prod/server/app/api/files/index/route.js +1 -1
  50. package/.next-prod/server/app/api/files/init/route.js +1 -1
  51. package/.next-prod/server/app/api/files/paste/route.js +1 -1
  52. package/.next-prod/server/app/api/files/read/route.js +1 -1
  53. package/.next-prod/server/app/api/files/readdir/route.js +1 -1
  54. package/.next-prod/server/app/api/files/recent/route.js +1 -1
  55. package/.next-prod/server/app/api/files/save/route.js +1 -1
  56. package/.next-prod/server/app/api/files/search/route.js +1 -1
  57. package/.next-prod/server/app/api/files/stat/route.js +1 -1
  58. package/.next-prod/server/app/api/files/text/route.js +1 -1
  59. package/.next-prod/server/app/api/fs/dirs/route.js +1 -1
  60. package/.next-prod/server/app/api/git/blob/route.js +1 -1
  61. package/.next-prod/server/app/api/git/branch-diff/route.js +1 -1
  62. package/.next-prod/server/app/api/git/branches/route.js +1 -1
  63. package/.next-prod/server/app/api/git/commit-diff/route.js +1 -1
  64. package/.next-prod/server/app/api/git/commits/route.js +1 -1
  65. package/.next-prod/server/app/api/git/current-branch/route.js +1 -1
  66. package/.next-prod/server/app/api/git/diff/route.js +1 -1
  67. package/.next-prod/server/app/api/git/discard/route.js +1 -1
  68. package/.next-prod/server/app/api/git/stage/route.js +1 -1
  69. package/.next-prod/server/app/api/git/status/route.js +1 -1
  70. package/.next-prod/server/app/api/git/unstage/route.js +1 -1
  71. package/.next-prod/server/app/api/git/worktree/route.js +1 -1
  72. package/.next-prod/server/app/api/glm/credentials/route.js +1 -1
  73. package/.next-prod/server/app/api/glm/models/route.js +1 -1
  74. package/.next-prod/server/app/api/glm/usage/route.js +1 -1
  75. package/.next-prod/server/app/api/global-state/route.js +2 -2
  76. package/.next-prod/server/app/api/grok/models/route.js +1 -1
  77. package/.next-prod/server/app/api/health/route.js +1 -1
  78. package/.next-prod/server/app/api/html-apps/[id]/route.js +1 -1
  79. package/.next-prod/server/app/api/html-apps/files/route.js +1 -1
  80. package/.next-prod/server/app/api/html-apps/route.js +1 -1
  81. package/.next-prod/server/app/api/instructions/config/route.js +1 -1
  82. package/.next-prod/server/app/api/kimi/credentials/route.js +1 -1
  83. package/.next-prod/server/app/api/kimi/models/route.js +1 -1
  84. package/.next-prod/server/app/api/kimi/usage/route.js +1 -1
  85. package/.next-prod/server/app/api/lsp/definition/route.js +1 -1
  86. package/.next-prod/server/app/api/lsp/hover/route.js +1 -1
  87. package/.next-prod/server/app/api/lsp/references/route.js +1 -1
  88. package/.next-prod/server/app/api/lsp/status/route.js +1 -1
  89. package/.next-prod/server/app/api/lsp/warmup/route.js +1 -1
  90. package/.next-prod/server/app/api/mobile-link/route.js +1 -1
  91. package/.next-prod/server/app/api/mysql/columns/route.js +2 -2
  92. package/.next-prod/server/app/api/mysql/connect/route.js +1 -1
  93. package/.next-prod/server/app/api/mysql/disconnect/route.js +1 -1
  94. package/.next-prod/server/app/api/mysql/export/route.js +1 -1
  95. package/.next-prod/server/app/api/mysql/query/route.js +1 -1
  96. package/.next-prod/server/app/api/mysql/schemas/route.js +2 -2
  97. package/.next-prod/server/app/api/neo4j/connect/route.js +1 -1
  98. package/.next-prod/server/app/api/neo4j/disconnect/route.js +1 -1
  99. package/.next-prod/server/app/api/neo4j/query/route.js +1 -1
  100. package/.next-prod/server/app/api/neo4j/schema/route.js +1 -1
  101. package/.next-prod/server/app/api/note/list/route.js +1 -1
  102. package/.next-prod/server/app/api/note/route.js +1 -1
  103. package/.next-prod/server/app/api/ollama/config/route.js +1 -1
  104. package/.next-prod/server/app/api/ollama/default-model/route.js +1 -1
  105. package/.next-prod/server/app/api/ollama/models/route.js +1 -1
  106. package/.next-prod/server/app/api/ollama/start/route.js +1 -1
  107. package/.next-prod/server/app/api/open-cursor/route.js +1 -1
  108. package/.next-prod/server/app/api/open-vscode/route.js +1 -1
  109. package/.next-prod/server/app/api/pi/thinking/route.js +1 -1
  110. package/.next-prod/server/app/api/pinned-sessions/route.js +1 -1
  111. package/.next-prod/server/app/api/project-settings/route.js +1 -1
  112. package/.next-prod/server/app/api/project-state/route.js +2 -2
  113. package/.next-prod/server/app/api/projectGraph/affected/route.js +1 -1
  114. package/.next-prod/server/app/api/projectGraph/callees/route.js +1 -1
  115. package/.next-prod/server/app/api/projectGraph/callers/route.js +1 -1
  116. package/.next-prod/server/app/api/projectGraph/coedit/route.js +1 -1
  117. package/.next-prod/server/app/api/projectGraph/edges/route.js +1 -0
  118. package/.next-prod/server/app/api/projectGraph/edges/route.js.nft.json +1 -0
  119. package/.next-prod/server/app/api/projectGraph/edges/route_client-reference-manifest.js +1 -0
  120. package/.next-prod/server/app/api/projectGraph/file/route.js +1 -1
  121. package/.next-prod/server/app/api/projectGraph/file-functions/route.js +1 -1
  122. package/.next-prod/server/app/api/projectGraph/impact/route.js +1 -1
  123. package/.next-prod/server/app/api/projectGraph/maps/route.js +1 -0
  124. package/.next-prod/server/app/api/projectGraph/maps/route.js.nft.json +1 -0
  125. package/.next-prod/server/app/api/projectGraph/maps/route_client-reference-manifest.js +1 -0
  126. package/.next-prod/server/app/api/projectGraph/related/route.js +1 -1
  127. package/.next-prod/server/app/api/projectGraph/search/route.js +1 -1
  128. package/.next-prod/server/app/api/projectGraph/symbols/route.js +1 -1
  129. package/.next-prod/server/app/api/projects/route.js +1 -1
  130. package/.next-prod/server/app/api/push/public-key/route.js +1 -1
  131. package/.next-prod/server/app/api/push/subscribe/route.js +1 -1
  132. package/.next-prod/server/app/api/push/unsubscribe/route.js +1 -1
  133. package/.next-prod/server/app/api/redis/command/route.js +1 -1
  134. package/.next-prod/server/app/api/redis/connect/route.js +1 -1
  135. package/.next-prod/server/app/api/redis/delete/route.js +1 -1
  136. package/.next-prod/server/app/api/redis/disconnect/route.js +1 -1
  137. package/.next-prod/server/app/api/redis/get/route.js +1 -1
  138. package/.next-prod/server/app/api/redis/keys/route.js +1 -1
  139. package/.next-prod/server/app/api/redis/set/route.js +1 -1
  140. package/.next-prod/server/app/api/restart/route.js +1 -1
  141. package/.next-prod/server/app/api/scheduled-tasks/route.js +2 -2
  142. package/.next-prod/server/app/api/services/config/route.js +1 -1
  143. package/.next-prod/server/app/api/services/scripts/route.js +1 -1
  144. package/.next-prod/server/app/api/session/[sessionId]/fork/route.js +1 -1
  145. package/.next-prod/server/app/api/session/[sessionId]/history/route.js +1 -1
  146. package/.next-prod/server/app/api/session/[sessionId]/turn/route.js +2 -2
  147. package/.next-prod/server/app/api/session/image/route.js +1 -1
  148. package/.next-prod/server/app/api/session/user-messages/route.js +1 -1
  149. package/.next-prod/server/app/api/session-bots/route.js +1 -1
  150. package/.next-prod/server/app/api/session-by-path/route.js +1 -1
  151. package/.next-prod/server/app/api/session-context/route.js +2 -2
  152. package/.next-prod/server/app/api/session-title/route.js +1 -1
  153. package/.next-prod/server/app/api/session-title/suggest/route.js +1 -1
  154. package/.next-prod/server/app/api/sessions/delegate/route.js +1 -1
  155. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js +1 -1
  156. package/.next-prod/server/app/api/sessions/projects/route.js +1 -1
  157. package/.next-prod/server/app/api/sessions/search/route.js +1 -1
  158. package/.next-prod/server/app/api/sessions/status/route.js +1 -1
  159. package/.next-prod/server/app/api/settings/route.js +1 -1
  160. package/.next-prod/server/app/api/shutdown/route.js +1 -1
  161. package/.next-prod/server/app/api/skills/[id]/route.js +1 -1
  162. package/.next-prod/server/app/api/skills/builtin/route.js +1 -1
  163. package/.next-prod/server/app/api/skills/content/route.js +1 -1
  164. package/.next-prod/server/app/api/skills/files/route.js +1 -1
  165. package/.next-prod/server/app/api/skills/route.js +1 -1
  166. package/.next-prod/server/app/api/snapshots/blob/route.js +1 -1
  167. package/.next-prod/server/app/api/snapshots/diff/route.js +1 -1
  168. package/.next-prod/server/app/api/snapshots/mark/route.js +1 -0
  169. package/.next-prod/server/app/api/snapshots/mark/route.js.nft.json +1 -0
  170. package/.next-prod/server/app/api/snapshots/mark/route_client-reference-manifest.js +1 -0
  171. package/.next-prod/server/app/api/snapshots/range-diff/route.js +1 -1
  172. package/.next-prod/server/app/api/snapshots/restore/route.js +1 -0
  173. package/.next-prod/server/app/api/snapshots/restore/route.js.nft.json +1 -0
  174. package/.next-prod/server/app/api/snapshots/restore/route_client-reference-manifest.js +1 -0
  175. package/.next-prod/server/app/api/snapshots/route.js +1 -1
  176. package/.next-prod/server/app/api/terminal/aliases/route.js +1 -1
  177. package/.next-prod/server/app/api/terminal/autocomplete/route.js +1 -1
  178. package/.next-prod/server/app/api/terminal/bubble-order/route.js +1 -1
  179. package/.next-prod/server/app/api/terminal/env/route.js +1 -1
  180. package/.next-prod/server/app/api/terminal/history/route.js +1 -1
  181. package/.next-prod/server/app/api/terminal/running/route.js +1 -1
  182. package/.next-prod/server/app/api/update/route.js +1 -1
  183. package/.next-prod/server/app/api/update-state/route.js +1 -1
  184. package/.next-prod/server/app/api/version/route.js +1 -1
  185. package/.next-prod/server/app/apps/[...path]/route.js +1 -1
  186. package/.next-prod/server/app/favicon.ico/route.js +1 -1
  187. package/.next-prod/server/app/m/page.js +2 -1
  188. package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
  189. package/.next-prod/server/app/manifest.webmanifest/route.js +1 -1
  190. package/.next-prod/server/app/page.js +1 -1
  191. package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
  192. package/.next-prod/server/app/project/page.js +1 -1
  193. package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
  194. package/.next-prod/server/app-paths-manifest.json +9 -5
  195. package/.next-prod/server/chunks/2493.js +13 -13
  196. package/.next-prod/server/chunks/4949.js +1 -1
  197. package/.next-prod/server/chunks/6610.js +34 -34
  198. package/.next-prod/server/chunks/7270.js +1 -1
  199. package/.next-prod/server/chunks/9830.js +2 -2
  200. package/.next-prod/server/chunks/9998.js +1 -1
  201. package/.next-prod/server/middleware-build-manifest.js +1 -1
  202. package/.next-prod/server/next-font-manifest.js +1 -1
  203. package/.next-prod/server/next-font-manifest.json +1 -1
  204. package/.next-prod/server/pages/500.html +1 -1
  205. package/.next-prod/server/server-reference-manifest.json +1 -1
  206. package/.next-prod/static/LwAYWBEgXwTIkuj7U9BpE/_buildManifest.js +1 -0
  207. package/.next-prod/static/chunks/{50189-b59a96372658a46a.js → 55541-994b26deaa23f4e6.js} +2 -2
  208. package/.next-prod/static/chunks/{731-fd4b8bcd1d40dfe9.js → 6837-78c0d1a8165d46f7.js} +21 -21
  209. package/.next-prod/static/chunks/92000-46024df89fb50e16.js +41 -0
  210. package/.next-prod/static/chunks/98596-4ca2d2544138aefd.js +733 -0
  211. package/.next-prod/static/chunks/app/_global-error/page-6af5bc188af96106.js +1 -0
  212. package/.next-prod/static/chunks/app/api/agent/test/route-6af5bc188af96106.js +1 -0
  213. package/.next-prod/static/chunks/app/api/bash/route-6af5bc188af96106.js +1 -0
  214. package/.next-prod/static/chunks/app/api/bots/[id]/route-6af5bc188af96106.js +1 -0
  215. package/.next-prod/static/chunks/app/api/bots/files/route-6af5bc188af96106.js +1 -0
  216. package/.next-prod/static/chunks/app/api/bots/route-6af5bc188af96106.js +1 -0
  217. package/.next-prod/static/chunks/app/api/chat/codex/route-6af5bc188af96106.js +1 -0
  218. package/.next-prod/static/chunks/app/api/chat/deepseek/route-6af5bc188af96106.js +1 -0
  219. package/.next-prod/static/chunks/app/api/chat/glm/route-6af5bc188af96106.js +1 -0
  220. package/.next-prod/static/chunks/app/api/chat/grok/route-6af5bc188af96106.js +1 -0
  221. package/.next-prod/static/chunks/app/api/chat/kimi/route-6af5bc188af96106.js +1 -0
  222. package/.next-prod/static/chunks/app/api/chat/ollama/route-6af5bc188af96106.js +1 -0
  223. package/.next-prod/static/chunks/app/api/chat/route-6af5bc188af96106.js +1 -0
  224. package/.next-prod/static/chunks/app/api/chat/stop/route-6af5bc188af96106.js +1 -0
  225. package/.next-prod/static/chunks/app/api/claude-stats/route-6af5bc188af96106.js +1 -0
  226. package/.next-prod/static/chunks/app/api/commands/route-6af5bc188af96106.js +1 -0
  227. package/.next-prod/static/chunks/app/api/comments/route-6af5bc188af96106.js +1 -0
  228. package/.next-prod/static/chunks/app/api/db/columns/route-6af5bc188af96106.js +1 -0
  229. package/.next-prod/static/chunks/app/api/db/connect/route-6af5bc188af96106.js +1 -0
  230. package/.next-prod/static/chunks/app/api/db/disconnect/route-6af5bc188af96106.js +1 -0
  231. package/.next-prod/static/chunks/app/api/db/export/route-6af5bc188af96106.js +1 -0
  232. package/.next-prod/static/chunks/app/api/db/query/route-6af5bc188af96106.js +1 -0
  233. package/.next-prod/static/chunks/app/api/db/schemas/route-6af5bc188af96106.js +1 -0
  234. package/.next-prod/static/chunks/app/api/deepseek/balance/route-6af5bc188af96106.js +1 -0
  235. package/.next-prod/static/chunks/app/api/deepseek/credentials/route-6af5bc188af96106.js +1 -0
  236. package/.next-prod/static/chunks/app/api/deepseek/models/route-6af5bc188af96106.js +1 -0
  237. package/.next-prod/static/chunks/app/api/dev/spans/route-6af5bc188af96106.js +1 -0
  238. package/.next-prod/static/chunks/app/api/extension/version/route-6af5bc188af96106.js +1 -0
  239. package/.next-prod/static/chunks/app/api/file/route-6af5bc188af96106.js +1 -0
  240. package/.next-prod/static/chunks/app/api/files/blame/route-6af5bc188af96106.js +1 -0
  241. package/.next-prod/static/chunks/app/api/files/clipboard/route-6af5bc188af96106.js +1 -0
  242. package/.next-prod/static/chunks/app/api/files/copy/route-6af5bc188af96106.js +1 -0
  243. package/.next-prod/static/chunks/app/api/files/delete/route-6af5bc188af96106.js +1 -0
  244. package/.next-prod/static/chunks/app/api/files/expanded/route-6af5bc188af96106.js +1 -0
  245. package/.next-prod/static/chunks/app/api/files/index/route-6af5bc188af96106.js +1 -0
  246. package/.next-prod/static/chunks/app/api/files/init/route-6af5bc188af96106.js +1 -0
  247. package/.next-prod/static/chunks/app/api/files/paste/route-6af5bc188af96106.js +1 -0
  248. package/.next-prod/static/chunks/app/api/files/read/route-6af5bc188af96106.js +1 -0
  249. package/.next-prod/static/chunks/app/api/files/readdir/route-6af5bc188af96106.js +1 -0
  250. package/.next-prod/static/chunks/app/api/files/recent/route-6af5bc188af96106.js +1 -0
  251. package/.next-prod/static/chunks/app/api/files/save/route-6af5bc188af96106.js +1 -0
  252. package/.next-prod/static/chunks/app/api/files/search/route-6af5bc188af96106.js +1 -0
  253. package/.next-prod/static/chunks/app/api/files/stat/route-6af5bc188af96106.js +1 -0
  254. package/.next-prod/static/chunks/app/api/files/text/route-6af5bc188af96106.js +1 -0
  255. package/.next-prod/static/chunks/app/api/fs/dirs/route-6af5bc188af96106.js +1 -0
  256. package/.next-prod/static/chunks/app/api/git/blob/route-6af5bc188af96106.js +1 -0
  257. package/.next-prod/static/chunks/app/api/git/branch-diff/route-6af5bc188af96106.js +1 -0
  258. package/.next-prod/static/chunks/app/api/git/branches/route-6af5bc188af96106.js +1 -0
  259. package/.next-prod/static/chunks/app/api/git/commit-diff/route-6af5bc188af96106.js +1 -0
  260. package/.next-prod/static/chunks/app/api/git/commits/route-6af5bc188af96106.js +1 -0
  261. package/.next-prod/static/chunks/app/api/git/current-branch/route-6af5bc188af96106.js +1 -0
  262. package/.next-prod/static/chunks/app/api/git/diff/route-6af5bc188af96106.js +1 -0
  263. package/.next-prod/static/chunks/app/api/git/discard/route-6af5bc188af96106.js +1 -0
  264. package/.next-prod/static/chunks/app/api/git/stage/route-6af5bc188af96106.js +1 -0
  265. package/.next-prod/static/chunks/app/api/git/status/route-6af5bc188af96106.js +1 -0
  266. package/.next-prod/static/chunks/app/api/git/unstage/route-6af5bc188af96106.js +1 -0
  267. package/.next-prod/static/chunks/app/api/git/worktree/route-6af5bc188af96106.js +1 -0
  268. package/.next-prod/static/chunks/app/api/glm/credentials/route-6af5bc188af96106.js +1 -0
  269. package/.next-prod/static/chunks/app/api/glm/models/route-6af5bc188af96106.js +1 -0
  270. package/.next-prod/static/chunks/app/api/glm/usage/route-6af5bc188af96106.js +1 -0
  271. package/.next-prod/static/chunks/app/api/global-state/route-6af5bc188af96106.js +1 -0
  272. package/.next-prod/static/chunks/app/api/grok/models/route-6af5bc188af96106.js +1 -0
  273. package/.next-prod/static/chunks/app/api/health/route-6af5bc188af96106.js +1 -0
  274. package/.next-prod/static/chunks/app/api/html-apps/[id]/route-6af5bc188af96106.js +1 -0
  275. package/.next-prod/static/chunks/app/api/html-apps/files/route-6af5bc188af96106.js +1 -0
  276. package/.next-prod/static/chunks/app/api/html-apps/route-6af5bc188af96106.js +1 -0
  277. package/.next-prod/static/chunks/app/api/instructions/config/route-6af5bc188af96106.js +1 -0
  278. package/.next-prod/static/chunks/app/api/kimi/credentials/route-6af5bc188af96106.js +1 -0
  279. package/.next-prod/static/chunks/app/api/kimi/models/route-6af5bc188af96106.js +1 -0
  280. package/.next-prod/static/chunks/app/api/kimi/usage/route-6af5bc188af96106.js +1 -0
  281. package/.next-prod/static/chunks/app/api/lsp/definition/route-6af5bc188af96106.js +1 -0
  282. package/.next-prod/static/chunks/app/api/lsp/hover/route-6af5bc188af96106.js +1 -0
  283. package/.next-prod/static/chunks/app/api/lsp/references/route-6af5bc188af96106.js +1 -0
  284. package/.next-prod/static/chunks/app/api/lsp/status/route-6af5bc188af96106.js +1 -0
  285. package/.next-prod/static/chunks/app/api/lsp/warmup/route-6af5bc188af96106.js +1 -0
  286. package/.next-prod/static/chunks/app/api/mobile-link/route-6af5bc188af96106.js +1 -0
  287. package/.next-prod/static/chunks/app/api/mysql/columns/route-6af5bc188af96106.js +1 -0
  288. package/.next-prod/static/chunks/app/api/mysql/connect/route-6af5bc188af96106.js +1 -0
  289. package/.next-prod/static/chunks/app/api/mysql/disconnect/route-6af5bc188af96106.js +1 -0
  290. package/.next-prod/static/chunks/app/api/mysql/export/route-6af5bc188af96106.js +1 -0
  291. package/.next-prod/static/chunks/app/api/mysql/query/route-6af5bc188af96106.js +1 -0
  292. package/.next-prod/static/chunks/app/api/mysql/schemas/route-6af5bc188af96106.js +1 -0
  293. package/.next-prod/static/chunks/app/api/neo4j/connect/route-6af5bc188af96106.js +1 -0
  294. package/.next-prod/static/chunks/app/api/neo4j/disconnect/route-6af5bc188af96106.js +1 -0
  295. package/.next-prod/static/chunks/app/api/neo4j/query/route-6af5bc188af96106.js +1 -0
  296. package/.next-prod/static/chunks/app/api/neo4j/schema/route-6af5bc188af96106.js +1 -0
  297. package/.next-prod/static/chunks/app/api/note/list/route-6af5bc188af96106.js +1 -0
  298. package/.next-prod/static/chunks/app/api/note/route-6af5bc188af96106.js +1 -0
  299. package/.next-prod/static/chunks/app/api/ollama/config/route-6af5bc188af96106.js +1 -0
  300. package/.next-prod/static/chunks/app/api/ollama/default-model/route-6af5bc188af96106.js +1 -0
  301. package/.next-prod/static/chunks/app/api/ollama/models/route-6af5bc188af96106.js +1 -0
  302. package/.next-prod/static/chunks/app/api/ollama/start/route-6af5bc188af96106.js +1 -0
  303. package/.next-prod/static/chunks/app/api/open-cursor/route-6af5bc188af96106.js +1 -0
  304. package/.next-prod/static/chunks/app/api/open-vscode/route-6af5bc188af96106.js +1 -0
  305. package/.next-prod/static/chunks/app/api/pi/thinking/route-6af5bc188af96106.js +1 -0
  306. package/.next-prod/static/chunks/app/api/pinned-sessions/route-6af5bc188af96106.js +1 -0
  307. package/.next-prod/static/chunks/app/api/project-settings/route-6af5bc188af96106.js +1 -0
  308. package/.next-prod/static/chunks/app/api/project-state/route-6af5bc188af96106.js +1 -0
  309. package/.next-prod/static/chunks/app/api/projectGraph/affected/route-6af5bc188af96106.js +1 -0
  310. package/.next-prod/static/chunks/app/api/projectGraph/callees/route-6af5bc188af96106.js +1 -0
  311. package/.next-prod/static/chunks/app/api/projectGraph/callers/route-6af5bc188af96106.js +1 -0
  312. package/.next-prod/static/chunks/app/api/projectGraph/coedit/route-6af5bc188af96106.js +1 -0
  313. package/.next-prod/static/chunks/app/api/projectGraph/edges/route-6af5bc188af96106.js +1 -0
  314. package/.next-prod/static/chunks/app/api/projectGraph/file/route-6af5bc188af96106.js +1 -0
  315. package/.next-prod/static/chunks/app/api/projectGraph/file-functions/route-6af5bc188af96106.js +1 -0
  316. package/.next-prod/static/chunks/app/api/projectGraph/impact/route-6af5bc188af96106.js +1 -0
  317. package/.next-prod/static/chunks/app/api/projectGraph/maps/route-6af5bc188af96106.js +1 -0
  318. package/.next-prod/static/chunks/app/api/projectGraph/related/route-6af5bc188af96106.js +1 -0
  319. package/.next-prod/static/chunks/app/api/projectGraph/search/route-6af5bc188af96106.js +1 -0
  320. package/.next-prod/static/chunks/app/api/projectGraph/symbols/route-6af5bc188af96106.js +1 -0
  321. package/.next-prod/static/chunks/app/api/projects/route-6af5bc188af96106.js +1 -0
  322. package/.next-prod/static/chunks/app/api/push/public-key/route-6af5bc188af96106.js +1 -0
  323. package/.next-prod/static/chunks/app/api/push/subscribe/route-6af5bc188af96106.js +1 -0
  324. package/.next-prod/static/chunks/app/api/push/unsubscribe/route-6af5bc188af96106.js +1 -0
  325. package/.next-prod/static/chunks/app/api/redis/command/route-6af5bc188af96106.js +1 -0
  326. package/.next-prod/static/chunks/app/api/redis/connect/route-6af5bc188af96106.js +1 -0
  327. package/.next-prod/static/chunks/app/api/redis/delete/route-6af5bc188af96106.js +1 -0
  328. package/.next-prod/static/chunks/app/api/redis/disconnect/route-6af5bc188af96106.js +1 -0
  329. package/.next-prod/static/chunks/app/api/redis/get/route-6af5bc188af96106.js +1 -0
  330. package/.next-prod/static/chunks/app/api/redis/keys/route-6af5bc188af96106.js +1 -0
  331. package/.next-prod/static/chunks/app/api/redis/set/route-6af5bc188af96106.js +1 -0
  332. package/.next-prod/static/chunks/app/api/restart/route-6af5bc188af96106.js +1 -0
  333. package/.next-prod/static/chunks/app/api/scheduled-tasks/route-6af5bc188af96106.js +1 -0
  334. package/.next-prod/static/chunks/app/api/services/config/route-6af5bc188af96106.js +1 -0
  335. package/.next-prod/static/chunks/app/api/services/scripts/route-6af5bc188af96106.js +1 -0
  336. package/.next-prod/static/chunks/app/api/session/[sessionId]/fork/route-6af5bc188af96106.js +1 -0
  337. package/.next-prod/static/chunks/app/api/session/[sessionId]/history/route-6af5bc188af96106.js +1 -0
  338. package/.next-prod/static/chunks/app/api/session/[sessionId]/turn/route-6af5bc188af96106.js +1 -0
  339. package/.next-prod/static/chunks/app/api/session/image/route-6af5bc188af96106.js +1 -0
  340. package/.next-prod/static/chunks/app/api/session/user-messages/route-6af5bc188af96106.js +1 -0
  341. package/.next-prod/static/chunks/app/api/session-bots/route-6af5bc188af96106.js +1 -0
  342. package/.next-prod/static/chunks/app/api/session-by-path/route-6af5bc188af96106.js +1 -0
  343. package/.next-prod/static/chunks/app/api/session-context/route-6af5bc188af96106.js +1 -0
  344. package/.next-prod/static/chunks/app/api/session-title/route-6af5bc188af96106.js +1 -0
  345. package/.next-prod/static/chunks/app/api/session-title/suggest/route-6af5bc188af96106.js +1 -0
  346. package/.next-prod/static/chunks/app/api/sessions/delegate/route-6af5bc188af96106.js +1 -0
  347. package/.next-prod/static/chunks/app/api/sessions/projects/[encodedPath]/route-6af5bc188af96106.js +1 -0
  348. package/.next-prod/static/chunks/app/api/sessions/projects/route-6af5bc188af96106.js +1 -0
  349. package/.next-prod/static/chunks/app/api/sessions/search/route-6af5bc188af96106.js +1 -0
  350. package/.next-prod/static/chunks/app/api/sessions/status/route-6af5bc188af96106.js +1 -0
  351. package/.next-prod/static/chunks/app/api/settings/route-6af5bc188af96106.js +1 -0
  352. package/.next-prod/static/chunks/app/api/shutdown/route-6af5bc188af96106.js +1 -0
  353. package/.next-prod/static/chunks/app/api/skills/[id]/route-6af5bc188af96106.js +1 -0
  354. package/.next-prod/static/chunks/app/api/skills/builtin/route-6af5bc188af96106.js +1 -0
  355. package/.next-prod/static/chunks/app/api/skills/content/route-6af5bc188af96106.js +1 -0
  356. package/.next-prod/static/chunks/app/api/skills/files/route-6af5bc188af96106.js +1 -0
  357. package/.next-prod/static/chunks/app/api/skills/route-6af5bc188af96106.js +1 -0
  358. package/.next-prod/static/chunks/app/api/snapshots/blob/route-6af5bc188af96106.js +1 -0
  359. package/.next-prod/static/chunks/app/api/snapshots/diff/route-6af5bc188af96106.js +1 -0
  360. package/.next-prod/static/chunks/app/api/snapshots/mark/route-6af5bc188af96106.js +1 -0
  361. package/.next-prod/static/chunks/app/api/snapshots/range-diff/route-6af5bc188af96106.js +1 -0
  362. package/.next-prod/static/chunks/app/api/snapshots/restore/route-6af5bc188af96106.js +1 -0
  363. package/.next-prod/static/chunks/app/api/snapshots/route-6af5bc188af96106.js +1 -0
  364. package/.next-prod/static/chunks/app/api/terminal/aliases/route-6af5bc188af96106.js +1 -0
  365. package/.next-prod/static/chunks/app/api/terminal/autocomplete/route-6af5bc188af96106.js +1 -0
  366. package/.next-prod/static/chunks/app/api/terminal/bubble-order/route-6af5bc188af96106.js +1 -0
  367. package/.next-prod/static/chunks/app/api/terminal/env/route-6af5bc188af96106.js +1 -0
  368. package/.next-prod/static/chunks/app/api/terminal/history/route-6af5bc188af96106.js +1 -0
  369. package/.next-prod/static/chunks/app/api/terminal/running/route-6af5bc188af96106.js +1 -0
  370. package/.next-prod/static/chunks/app/api/update/route-6af5bc188af96106.js +1 -0
  371. package/.next-prod/static/chunks/app/api/update-state/route-6af5bc188af96106.js +1 -0
  372. package/.next-prod/static/chunks/app/api/version/route-6af5bc188af96106.js +1 -0
  373. package/.next-prod/static/chunks/app/apps/[...path]/route-6af5bc188af96106.js +1 -0
  374. package/.next-prod/static/chunks/app/{layout-f0ff0ab277c84dc6.js → layout-7107ed4eeac1f693.js} +1 -1
  375. package/.next-prod/static/chunks/app/m/page-0c8e79e2f753aecb.js +2 -0
  376. package/.next-prod/static/chunks/app/manifest.webmanifest/route-6af5bc188af96106.js +1 -0
  377. package/.next-prod/static/chunks/app/{page-d2ccfc2cb47ac4af.js → page-338a2c84319778b1.js} +1 -1
  378. package/.next-prod/static/chunks/app/project/{page-d2ccfc2cb47ac4af.js → page-338a2c84319778b1.js} +1 -1
  379. package/.next-prod/static/chunks/next/dist/client/components/builtin/app-error-6af5bc188af96106.js +1 -0
  380. package/.next-prod/static/chunks/next/dist/client/components/builtin/forbidden-6af5bc188af96106.js +1 -0
  381. package/.next-prod/static/chunks/next/dist/client/components/builtin/not-found-6af5bc188af96106.js +1 -0
  382. package/.next-prod/static/chunks/next/dist/client/components/builtin/unauthorized-6af5bc188af96106.js +1 -0
  383. package/.next-prod/static/css/fa34d3b1412ca27a.css +1 -0
  384. package/.next-prod/trace +86 -15
  385. package/.next-prod/trace-build +1 -1
  386. package/.next-prod/types/app/api/projectGraph/edges/route.ts +353 -0
  387. package/.next-prod/types/app/api/projectGraph/maps/route.ts +353 -0
  388. package/.next-prod/types/app/api/snapshots/mark/route.ts +353 -0
  389. package/.next-prod/types/app/api/snapshots/restore/route.ts +353 -0
  390. package/.next-prod/types/routes.d.ts +5 -1
  391. package/.next-prod/types/validator.ts +36 -0
  392. package/README.md +6 -0
  393. package/bin/rotateLog.mjs +6 -5
  394. package/desktop-checksums.json +4 -4
  395. package/dist/{anthropicCompat-PQWSZ3O7.mjs → anthropicCompat-4HZVLIFE.mjs} +3 -2
  396. package/dist/auth.mjs +19 -3
  397. package/dist/authAudit.mjs +79 -0
  398. package/dist/{chunk-6QDJ3QAX.mjs → chunk-6QHHEA3D.mjs} +11 -9
  399. package/dist/{chunk-2PDNZOMA.mjs → chunk-HJT5ZRYY.mjs} +2 -2
  400. package/dist/{chunk-S7FDWHAF.mjs → chunk-LSFNZJMR.mjs} +26825 -29730
  401. package/dist/{chunk-3S5JGONK.mjs → chunk-N3DTLFZE.mjs} +14 -12
  402. package/dist/{chunk-AKBWZB3V.mjs → chunk-QPFJKR3B.mjs} +2 -2
  403. package/dist/{chunk-LQISLDJ5.mjs → chunk-SI632CNY.mjs} +1 -1
  404. package/dist/{chunk-G747UZSS.mjs → chunk-T4M6CNFO.mjs} +132 -34
  405. package/dist/chunk-WSSVELJX.mjs +2920 -0
  406. package/dist/{chunk-2O6IH2TF.mjs → chunk-X4R5HO25.mjs} +2 -2
  407. package/dist/deepseek-YEPNQ2GX.mjs +13 -0
  408. package/dist/glm-SGT2LTOS.mjs +15 -0
  409. package/dist/httpApi.mjs +9 -8
  410. package/dist/kimi-FDXILCYU.mjs +15 -0
  411. package/dist/scheduledTasks.mjs +41 -15
  412. package/dist/{sessionStore-FF2VHKXM.mjs → sessionStore-WJGMZM4A.mjs} +2 -1
  413. package/dist/wsServer.mjs +63 -26
  414. package/package.json +3 -3
  415. package/public/html-lib/markdown.js +1 -1
  416. package/server.mjs +6 -1
  417. package/skills/cr/SKILL.md +184 -11
  418. package/skills/dl/SKILL.md +5 -0
  419. package/skills/rf/SKILL.md +124 -0
  420. package/skills/rf/axes.md +87 -0
  421. package/skills/rf/converge.md +50 -0
  422. package/skills/rf/fix.md +138 -0
  423. package/skills/rf/lenses.md +76 -0
  424. package/skills/rf/report.md +133 -0
  425. package/skills/rf/sources.md +129 -0
  426. package/.next-prod/static/AO-RPvB4uxOb6-XZ_0YXg/_buildManifest.js +0 -1
  427. package/.next-prod/static/chunks/17220-89a26ee102272095.js +0 -732
  428. package/.next-prod/static/chunks/45590-d1a8b4e539cc8dda.js +0 -42
  429. package/.next-prod/static/chunks/app/_global-error/page-42efcb4fd08c5099.js +0 -1
  430. package/.next-prod/static/chunks/app/api/agent/test/route-42efcb4fd08c5099.js +0 -1
  431. package/.next-prod/static/chunks/app/api/bash/route-42efcb4fd08c5099.js +0 -1
  432. package/.next-prod/static/chunks/app/api/bots/[id]/route-42efcb4fd08c5099.js +0 -1
  433. package/.next-prod/static/chunks/app/api/bots/files/route-42efcb4fd08c5099.js +0 -1
  434. package/.next-prod/static/chunks/app/api/bots/route-42efcb4fd08c5099.js +0 -1
  435. package/.next-prod/static/chunks/app/api/chat/codex/route-42efcb4fd08c5099.js +0 -1
  436. package/.next-prod/static/chunks/app/api/chat/deepseek/route-42efcb4fd08c5099.js +0 -1
  437. package/.next-prod/static/chunks/app/api/chat/glm/route-42efcb4fd08c5099.js +0 -1
  438. package/.next-prod/static/chunks/app/api/chat/grok/route-42efcb4fd08c5099.js +0 -1
  439. package/.next-prod/static/chunks/app/api/chat/kimi/route-42efcb4fd08c5099.js +0 -1
  440. package/.next-prod/static/chunks/app/api/chat/ollama/route-42efcb4fd08c5099.js +0 -1
  441. package/.next-prod/static/chunks/app/api/chat/route-42efcb4fd08c5099.js +0 -1
  442. package/.next-prod/static/chunks/app/api/chat/stop/route-42efcb4fd08c5099.js +0 -1
  443. package/.next-prod/static/chunks/app/api/claude-stats/route-42efcb4fd08c5099.js +0 -1
  444. package/.next-prod/static/chunks/app/api/commands/route-42efcb4fd08c5099.js +0 -1
  445. package/.next-prod/static/chunks/app/api/comments/route-42efcb4fd08c5099.js +0 -1
  446. package/.next-prod/static/chunks/app/api/db/columns/route-42efcb4fd08c5099.js +0 -1
  447. package/.next-prod/static/chunks/app/api/db/connect/route-42efcb4fd08c5099.js +0 -1
  448. package/.next-prod/static/chunks/app/api/db/disconnect/route-42efcb4fd08c5099.js +0 -1
  449. package/.next-prod/static/chunks/app/api/db/export/route-42efcb4fd08c5099.js +0 -1
  450. package/.next-prod/static/chunks/app/api/db/query/route-42efcb4fd08c5099.js +0 -1
  451. package/.next-prod/static/chunks/app/api/db/schemas/route-42efcb4fd08c5099.js +0 -1
  452. package/.next-prod/static/chunks/app/api/deepseek/balance/route-42efcb4fd08c5099.js +0 -1
  453. package/.next-prod/static/chunks/app/api/deepseek/credentials/route-42efcb4fd08c5099.js +0 -1
  454. package/.next-prod/static/chunks/app/api/deepseek/models/route-42efcb4fd08c5099.js +0 -1
  455. package/.next-prod/static/chunks/app/api/dev/spans/route-42efcb4fd08c5099.js +0 -1
  456. package/.next-prod/static/chunks/app/api/extension/version/route-42efcb4fd08c5099.js +0 -1
  457. package/.next-prod/static/chunks/app/api/file/route-42efcb4fd08c5099.js +0 -1
  458. package/.next-prod/static/chunks/app/api/files/blame/route-42efcb4fd08c5099.js +0 -1
  459. package/.next-prod/static/chunks/app/api/files/clipboard/route-42efcb4fd08c5099.js +0 -1
  460. package/.next-prod/static/chunks/app/api/files/copy/route-42efcb4fd08c5099.js +0 -1
  461. package/.next-prod/static/chunks/app/api/files/delete/route-42efcb4fd08c5099.js +0 -1
  462. package/.next-prod/static/chunks/app/api/files/expanded/route-42efcb4fd08c5099.js +0 -1
  463. package/.next-prod/static/chunks/app/api/files/index/route-42efcb4fd08c5099.js +0 -1
  464. package/.next-prod/static/chunks/app/api/files/init/route-42efcb4fd08c5099.js +0 -1
  465. package/.next-prod/static/chunks/app/api/files/paste/route-42efcb4fd08c5099.js +0 -1
  466. package/.next-prod/static/chunks/app/api/files/read/route-42efcb4fd08c5099.js +0 -1
  467. package/.next-prod/static/chunks/app/api/files/readdir/route-42efcb4fd08c5099.js +0 -1
  468. package/.next-prod/static/chunks/app/api/files/recent/route-42efcb4fd08c5099.js +0 -1
  469. package/.next-prod/static/chunks/app/api/files/save/route-42efcb4fd08c5099.js +0 -1
  470. package/.next-prod/static/chunks/app/api/files/search/route-42efcb4fd08c5099.js +0 -1
  471. package/.next-prod/static/chunks/app/api/files/stat/route-42efcb4fd08c5099.js +0 -1
  472. package/.next-prod/static/chunks/app/api/files/text/route-42efcb4fd08c5099.js +0 -1
  473. package/.next-prod/static/chunks/app/api/fs/dirs/route-42efcb4fd08c5099.js +0 -1
  474. package/.next-prod/static/chunks/app/api/git/blob/route-42efcb4fd08c5099.js +0 -1
  475. package/.next-prod/static/chunks/app/api/git/branch-diff/route-42efcb4fd08c5099.js +0 -1
  476. package/.next-prod/static/chunks/app/api/git/branches/route-42efcb4fd08c5099.js +0 -1
  477. package/.next-prod/static/chunks/app/api/git/commit-diff/route-42efcb4fd08c5099.js +0 -1
  478. package/.next-prod/static/chunks/app/api/git/commits/route-42efcb4fd08c5099.js +0 -1
  479. package/.next-prod/static/chunks/app/api/git/current-branch/route-42efcb4fd08c5099.js +0 -1
  480. package/.next-prod/static/chunks/app/api/git/diff/route-42efcb4fd08c5099.js +0 -1
  481. package/.next-prod/static/chunks/app/api/git/discard/route-42efcb4fd08c5099.js +0 -1
  482. package/.next-prod/static/chunks/app/api/git/stage/route-42efcb4fd08c5099.js +0 -1
  483. package/.next-prod/static/chunks/app/api/git/status/route-42efcb4fd08c5099.js +0 -1
  484. package/.next-prod/static/chunks/app/api/git/unstage/route-42efcb4fd08c5099.js +0 -1
  485. package/.next-prod/static/chunks/app/api/git/worktree/route-42efcb4fd08c5099.js +0 -1
  486. package/.next-prod/static/chunks/app/api/glm/credentials/route-42efcb4fd08c5099.js +0 -1
  487. package/.next-prod/static/chunks/app/api/glm/models/route-42efcb4fd08c5099.js +0 -1
  488. package/.next-prod/static/chunks/app/api/glm/usage/route-42efcb4fd08c5099.js +0 -1
  489. package/.next-prod/static/chunks/app/api/global-state/route-42efcb4fd08c5099.js +0 -1
  490. package/.next-prod/static/chunks/app/api/grok/models/route-42efcb4fd08c5099.js +0 -1
  491. package/.next-prod/static/chunks/app/api/health/route-42efcb4fd08c5099.js +0 -1
  492. package/.next-prod/static/chunks/app/api/html-apps/[id]/route-42efcb4fd08c5099.js +0 -1
  493. package/.next-prod/static/chunks/app/api/html-apps/files/route-42efcb4fd08c5099.js +0 -1
  494. package/.next-prod/static/chunks/app/api/html-apps/route-42efcb4fd08c5099.js +0 -1
  495. package/.next-prod/static/chunks/app/api/instructions/config/route-42efcb4fd08c5099.js +0 -1
  496. package/.next-prod/static/chunks/app/api/kimi/credentials/route-42efcb4fd08c5099.js +0 -1
  497. package/.next-prod/static/chunks/app/api/kimi/models/route-42efcb4fd08c5099.js +0 -1
  498. package/.next-prod/static/chunks/app/api/kimi/usage/route-42efcb4fd08c5099.js +0 -1
  499. package/.next-prod/static/chunks/app/api/lsp/definition/route-42efcb4fd08c5099.js +0 -1
  500. package/.next-prod/static/chunks/app/api/lsp/hover/route-42efcb4fd08c5099.js +0 -1
  501. package/.next-prod/static/chunks/app/api/lsp/references/route-42efcb4fd08c5099.js +0 -1
  502. package/.next-prod/static/chunks/app/api/lsp/status/route-42efcb4fd08c5099.js +0 -1
  503. package/.next-prod/static/chunks/app/api/lsp/warmup/route-42efcb4fd08c5099.js +0 -1
  504. package/.next-prod/static/chunks/app/api/mobile-link/route-42efcb4fd08c5099.js +0 -1
  505. package/.next-prod/static/chunks/app/api/mysql/columns/route-42efcb4fd08c5099.js +0 -1
  506. package/.next-prod/static/chunks/app/api/mysql/connect/route-42efcb4fd08c5099.js +0 -1
  507. package/.next-prod/static/chunks/app/api/mysql/disconnect/route-42efcb4fd08c5099.js +0 -1
  508. package/.next-prod/static/chunks/app/api/mysql/export/route-42efcb4fd08c5099.js +0 -1
  509. package/.next-prod/static/chunks/app/api/mysql/query/route-42efcb4fd08c5099.js +0 -1
  510. package/.next-prod/static/chunks/app/api/mysql/schemas/route-42efcb4fd08c5099.js +0 -1
  511. package/.next-prod/static/chunks/app/api/neo4j/connect/route-42efcb4fd08c5099.js +0 -1
  512. package/.next-prod/static/chunks/app/api/neo4j/disconnect/route-42efcb4fd08c5099.js +0 -1
  513. package/.next-prod/static/chunks/app/api/neo4j/query/route-42efcb4fd08c5099.js +0 -1
  514. package/.next-prod/static/chunks/app/api/neo4j/schema/route-42efcb4fd08c5099.js +0 -1
  515. package/.next-prod/static/chunks/app/api/note/list/route-42efcb4fd08c5099.js +0 -1
  516. package/.next-prod/static/chunks/app/api/note/route-42efcb4fd08c5099.js +0 -1
  517. package/.next-prod/static/chunks/app/api/ollama/config/route-42efcb4fd08c5099.js +0 -1
  518. package/.next-prod/static/chunks/app/api/ollama/default-model/route-42efcb4fd08c5099.js +0 -1
  519. package/.next-prod/static/chunks/app/api/ollama/models/route-42efcb4fd08c5099.js +0 -1
  520. package/.next-prod/static/chunks/app/api/ollama/start/route-42efcb4fd08c5099.js +0 -1
  521. package/.next-prod/static/chunks/app/api/open-cursor/route-42efcb4fd08c5099.js +0 -1
  522. package/.next-prod/static/chunks/app/api/open-vscode/route-42efcb4fd08c5099.js +0 -1
  523. package/.next-prod/static/chunks/app/api/pi/thinking/route-42efcb4fd08c5099.js +0 -1
  524. package/.next-prod/static/chunks/app/api/pinned-sessions/route-42efcb4fd08c5099.js +0 -1
  525. package/.next-prod/static/chunks/app/api/project-settings/route-42efcb4fd08c5099.js +0 -1
  526. package/.next-prod/static/chunks/app/api/project-state/route-42efcb4fd08c5099.js +0 -1
  527. package/.next-prod/static/chunks/app/api/projectGraph/affected/route-42efcb4fd08c5099.js +0 -1
  528. package/.next-prod/static/chunks/app/api/projectGraph/callees/route-42efcb4fd08c5099.js +0 -1
  529. package/.next-prod/static/chunks/app/api/projectGraph/callers/route-42efcb4fd08c5099.js +0 -1
  530. package/.next-prod/static/chunks/app/api/projectGraph/coedit/route-42efcb4fd08c5099.js +0 -1
  531. package/.next-prod/static/chunks/app/api/projectGraph/file/route-42efcb4fd08c5099.js +0 -1
  532. package/.next-prod/static/chunks/app/api/projectGraph/file-functions/route-42efcb4fd08c5099.js +0 -1
  533. package/.next-prod/static/chunks/app/api/projectGraph/impact/route-42efcb4fd08c5099.js +0 -1
  534. package/.next-prod/static/chunks/app/api/projectGraph/related/route-42efcb4fd08c5099.js +0 -1
  535. package/.next-prod/static/chunks/app/api/projectGraph/search/route-42efcb4fd08c5099.js +0 -1
  536. package/.next-prod/static/chunks/app/api/projectGraph/symbols/route-42efcb4fd08c5099.js +0 -1
  537. package/.next-prod/static/chunks/app/api/projects/route-42efcb4fd08c5099.js +0 -1
  538. package/.next-prod/static/chunks/app/api/push/public-key/route-42efcb4fd08c5099.js +0 -1
  539. package/.next-prod/static/chunks/app/api/push/subscribe/route-42efcb4fd08c5099.js +0 -1
  540. package/.next-prod/static/chunks/app/api/push/unsubscribe/route-42efcb4fd08c5099.js +0 -1
  541. package/.next-prod/static/chunks/app/api/redis/command/route-42efcb4fd08c5099.js +0 -1
  542. package/.next-prod/static/chunks/app/api/redis/connect/route-42efcb4fd08c5099.js +0 -1
  543. package/.next-prod/static/chunks/app/api/redis/delete/route-42efcb4fd08c5099.js +0 -1
  544. package/.next-prod/static/chunks/app/api/redis/disconnect/route-42efcb4fd08c5099.js +0 -1
  545. package/.next-prod/static/chunks/app/api/redis/get/route-42efcb4fd08c5099.js +0 -1
  546. package/.next-prod/static/chunks/app/api/redis/keys/route-42efcb4fd08c5099.js +0 -1
  547. package/.next-prod/static/chunks/app/api/redis/set/route-42efcb4fd08c5099.js +0 -1
  548. package/.next-prod/static/chunks/app/api/restart/route-42efcb4fd08c5099.js +0 -1
  549. package/.next-prod/static/chunks/app/api/scheduled-tasks/route-42efcb4fd08c5099.js +0 -1
  550. package/.next-prod/static/chunks/app/api/services/config/route-42efcb4fd08c5099.js +0 -1
  551. package/.next-prod/static/chunks/app/api/services/scripts/route-42efcb4fd08c5099.js +0 -1
  552. package/.next-prod/static/chunks/app/api/session/[sessionId]/fork/route-42efcb4fd08c5099.js +0 -1
  553. package/.next-prod/static/chunks/app/api/session/[sessionId]/history/route-42efcb4fd08c5099.js +0 -1
  554. package/.next-prod/static/chunks/app/api/session/[sessionId]/turn/route-42efcb4fd08c5099.js +0 -1
  555. package/.next-prod/static/chunks/app/api/session/image/route-42efcb4fd08c5099.js +0 -1
  556. package/.next-prod/static/chunks/app/api/session/user-messages/route-42efcb4fd08c5099.js +0 -1
  557. package/.next-prod/static/chunks/app/api/session-bots/route-42efcb4fd08c5099.js +0 -1
  558. package/.next-prod/static/chunks/app/api/session-by-path/route-42efcb4fd08c5099.js +0 -1
  559. package/.next-prod/static/chunks/app/api/session-context/route-42efcb4fd08c5099.js +0 -1
  560. package/.next-prod/static/chunks/app/api/session-title/route-42efcb4fd08c5099.js +0 -1
  561. package/.next-prod/static/chunks/app/api/session-title/suggest/route-42efcb4fd08c5099.js +0 -1
  562. package/.next-prod/static/chunks/app/api/sessions/delegate/route-42efcb4fd08c5099.js +0 -1
  563. package/.next-prod/static/chunks/app/api/sessions/projects/[encodedPath]/route-42efcb4fd08c5099.js +0 -1
  564. package/.next-prod/static/chunks/app/api/sessions/projects/route-42efcb4fd08c5099.js +0 -1
  565. package/.next-prod/static/chunks/app/api/sessions/search/route-42efcb4fd08c5099.js +0 -1
  566. package/.next-prod/static/chunks/app/api/sessions/status/route-42efcb4fd08c5099.js +0 -1
  567. package/.next-prod/static/chunks/app/api/settings/route-42efcb4fd08c5099.js +0 -1
  568. package/.next-prod/static/chunks/app/api/shutdown/route-42efcb4fd08c5099.js +0 -1
  569. package/.next-prod/static/chunks/app/api/skills/[id]/route-42efcb4fd08c5099.js +0 -1
  570. package/.next-prod/static/chunks/app/api/skills/builtin/route-42efcb4fd08c5099.js +0 -1
  571. package/.next-prod/static/chunks/app/api/skills/content/route-42efcb4fd08c5099.js +0 -1
  572. package/.next-prod/static/chunks/app/api/skills/files/route-42efcb4fd08c5099.js +0 -1
  573. package/.next-prod/static/chunks/app/api/skills/route-42efcb4fd08c5099.js +0 -1
  574. package/.next-prod/static/chunks/app/api/snapshots/blob/route-42efcb4fd08c5099.js +0 -1
  575. package/.next-prod/static/chunks/app/api/snapshots/diff/route-42efcb4fd08c5099.js +0 -1
  576. package/.next-prod/static/chunks/app/api/snapshots/range-diff/route-42efcb4fd08c5099.js +0 -1
  577. package/.next-prod/static/chunks/app/api/snapshots/route-42efcb4fd08c5099.js +0 -1
  578. package/.next-prod/static/chunks/app/api/terminal/aliases/route-42efcb4fd08c5099.js +0 -1
  579. package/.next-prod/static/chunks/app/api/terminal/autocomplete/route-42efcb4fd08c5099.js +0 -1
  580. package/.next-prod/static/chunks/app/api/terminal/bubble-order/route-42efcb4fd08c5099.js +0 -1
  581. package/.next-prod/static/chunks/app/api/terminal/env/route-42efcb4fd08c5099.js +0 -1
  582. package/.next-prod/static/chunks/app/api/terminal/history/route-42efcb4fd08c5099.js +0 -1
  583. package/.next-prod/static/chunks/app/api/terminal/running/route-42efcb4fd08c5099.js +0 -1
  584. package/.next-prod/static/chunks/app/api/update/route-42efcb4fd08c5099.js +0 -1
  585. package/.next-prod/static/chunks/app/api/update-state/route-42efcb4fd08c5099.js +0 -1
  586. package/.next-prod/static/chunks/app/api/version/route-42efcb4fd08c5099.js +0 -1
  587. package/.next-prod/static/chunks/app/apps/[...path]/route-42efcb4fd08c5099.js +0 -1
  588. package/.next-prod/static/chunks/app/m/page-50e48b4ba0942454.js +0 -1
  589. package/.next-prod/static/chunks/app/manifest.webmanifest/route-42efcb4fd08c5099.js +0 -1
  590. package/.next-prod/static/chunks/next/dist/client/components/builtin/app-error-42efcb4fd08c5099.js +0 -1
  591. package/.next-prod/static/chunks/next/dist/client/components/builtin/forbidden-42efcb4fd08c5099.js +0 -1
  592. package/.next-prod/static/chunks/next/dist/client/components/builtin/not-found-42efcb4fd08c5099.js +0 -1
  593. package/.next-prod/static/chunks/next/dist/client/components/builtin/unauthorized-42efcb4fd08c5099.js +0 -1
  594. package/.next-prod/static/css/74144fec62c7ff43.css +0 -1
  595. package/dist/deepseek-5QJ2IWS3.mjs +0 -12
  596. package/dist/glm-SIOUQCWL.mjs +0 -14
  597. package/dist/kimi-NKL4WBNS.mjs +0 -14
  598. /package/.next-prod/static/{AO-RPvB4uxOb6-XZ_0YXg → LwAYWBEgXwTIkuj7U9BpE}/_ssgManifest.js +0 -0
@@ -1,42 +0,0 @@
1
- "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[45590],{1767:(e,t,r)=>{r.d(t,{BotsModal:()=>P});var n=r(95155),s=r(12115),o=r(63393),l=r(33210),a=r(96035),i=r(68459),d=r(49619),c=r(42129),u=r(79114),m=r(86957),x=r(95045),h=r(75346),f=r(23348),p=r(67415),g=r(37640),b=r(33442),v=r(34075),j=r(66109),w=r(99161),k=r(83448),y=r(20832),N=r(59461),C=r(92689),S=r(32456),M=r(7578),L=r(4768);let E=(e,t)=>e.bot===t.name||e.cwd===t.path||e.cwd.startsWith(t.path+"/");function P({isOpen:e,onClose:t,onOpenSession:r}){let{t:a}=(0,u.Bd)(),[i,d]=(0,s.useState)([]),[c,w]=(0,s.useState)(!1),[y,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(""),[M,L]=(0,s.useState)(null),[E,B]=(0,s.useState)("files"),[D,A]=(0,s.useState)(null),[O,W]=(0,s.useState)([]),[_,z]=(0,s.useState)([]),q=(0,s.useCallback)(async()=>{w(!0);let[e,t]=await Promise.all([m.t4.runPromiseExit((0,f.jm)()),m.t4.runPromiseExit((0,p.VU)())]);"Success"===e._tag?d(e.value):(0,v.oR)((0,g.oh)(e.cause,a("bots.loadFailed")),"error"),"Success"===t._tag?z(t.value):(0,v.oR)((0,g.oh)(t.cause,a("bots.loadFailed")),"error"),w(!1)},[a]);(0,s.useEffect)(()=>{if(!e){L(null),A(null);return}q(),m.t4.runPromiseExit((0,k.z2)()).then(e=>{"Success"===e._tag&&W(e.value)})},[e,q]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&(y?N(!1):t())};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[y,e,t]);let V=(0,s.useMemo)(()=>{let e=C.trim().toLowerCase();return e?i.filter(t=>{let r=t.valid?t.description:t.error;return`${t.name}
2
- ${r}
3
- ${t.path}`.toLowerCase().includes(e)}):i},[i,C]),U=(0,s.useMemo)(()=>{let e=(e,t)=>e.name.localeCompare(t.name);return[{key:"mine",labelKey:"bots.mine",items:V.filter(e=>!e.builtin).slice().sort(e)},{key:"builtin",labelKey:"bots.builtin",items:V.filter(e=>e.builtin).slice().sort(e)}].filter(e=>e.items.length>0)},[V]),K=(0,s.useMemo)(()=>{let e=C.trim().toLowerCase(),t=[..._].sort((e,t)=>(e.name??e.title).localeCompare(t.name??t.title));return e?t.filter(t=>`${t.title}
4
- ${t.cwd}`.toLowerCase().includes(e)):t},[_,C]),Q=(0,s.useMemo)(()=>[...U.flatMap(e=>e.items.map(e=>e.id)),...K.map(T)],[U,K]),G=M?i.find(e=>e.id===M)??null:null,J=M?_.find(e=>T(e)===M)??null:null;(0,s.useEffect)(()=>{!e||G||J||L(Q[0]??null)},[e,G,J,Q]);let Y=(0,s.useMemo)(()=>i.filter(e=>!e.builtin).length+_.length,[i,_]),X=C.trim().length>0,Z=(0,s.useCallback)(async e=>{let t=await m.t4.runPromiseExit((0,p.i2)(e.cwd,e.sessionId));"Success"===t._tag?(z(t=>t.filter(t=>T(t)!==T(e))),(0,b._)(),(0,v.oR)(a("bots.removed"),"success")):(0,v.oR)((0,g.oh)(t.cause,a("bots.removeFailed")),"error")},[a]),ee=(0,s.useCallback)(async e=>{let t=await m.t4.runPromiseExit((0,f.Eo)(e));"Success"===t._tag?(d(t=>t.filter(t=>t.id!==e)),(0,b._)(),(0,v.oR)(a("bots.removed"),"success")):(0,v.oR)((0,g.oh)(t.cause,a("bots.removeFailed")),"error")},[a]),et=(0,s.useCallback)(e=>{(0,x.F)(h.n.OpenProject,{cwd:e,file:"BOT.md"}),t()},[t]),er=(0,s.useCallback)(()=>N(!0),[]),en=(0,s.useCallback)(()=>N(!1),[]),es=(0,s.useCallback)(async()=>{N(!1),await q()},[q]);return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:j.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:a("bots.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{value:C,onChange:e=>S(e.target.value),placeholder:a("bots.search"),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsxs)("button",{onClick:er,className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border hover:bg-hover",children:[(0,n.jsx)(o.A,{className:"w-4 h-4"}),a("bots.addExisting")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground",children:(0,n.jsx)(l.A,{className:"w-5 h-5"})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsx)("div",{className:"w-full md:w-[300px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:c&&0===i.length?(0,n.jsx)("p",{className:"text-center text-sm text-muted-foreground py-8",children:a("common.loading")}):(0,n.jsxs)("div",{className:"p-3 space-y-3",children:[U.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center",children:[(0,n.jsx)("span",{children:a(e.labelKey)}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(e=>(0,n.jsx)(I,{bot:e,selected:e.id===M,onSelect:L},e.id))})]},e.key)),K.length>0&&(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center",children:[(0,n.jsx)("span",{"data-tooltip":a("bots.sessionGroupHint"),children:a("bots.sessionGroup")}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:K.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:K.map(e=>(0,n.jsx)($,{bot:e,selected:T(e)===M,onSelect:L},T(e)))})]}),0===Q.length&&X&&(0,n.jsx)("p",{className:"text-center text-xs text-muted-foreground py-6",children:a("bots.emptyNoMatch")}),!X&&0===Y&&(0,n.jsxs)("div",{className:"text-center text-muted-foreground py-4 text-xs space-y-2",children:[(0,n.jsx)("p",{children:a("bots.emptyNoBots")}),(0,n.jsxs)("p",{children:[a("bots.emptyCreatePrefix")," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-foreground font-mono text-xs",children:"/bot"})," ",a("bots.emptyCreateSuffix")]}),(0,n.jsx)("p",{children:(0,n.jsx)("button",{type:"button",onClick:er,className:"text-brand hover:underline",children:a("bots.emptyAddExisting")})})]})]})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:G?(0,n.jsx)(F,{bot:G,tab:E,onTab:B,sessions:O,confirmingRemove:D===G.id,onAskRemove:()=>A(G.id),onCancelRemove:()=>A(null),onRemove:()=>{A(null),ee(G.id)},onOpenAsProject:()=>et(G.path),onOpenSession:(e,n)=>{r(e,n),t()},onClose:t},G.id):J?(0,n.jsx)(R,{bot:J,confirmingRemove:D===T(J),onAskRemove:()=>A(T(J)),onCancelRemove:()=>A(null),onRemove:()=>{A(null),Z(J)},onOpenSession:()=>{r(J.cwd,J.sessionId),t()}},T(J)):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:a("bots.selectHint")})})]})]}),y&&(0,n.jsx)(H,{onCancel:en,onAdded:es})]}):null}let T=e=>`session:${e.cwd}
5
- ${e.sessionId}`,$=(0,s.memo)(function({bot:e,selected:t,onSelect:r}){let s,{t:o}=(0,u.Bd)(),l=!e.name||!e.engine;return(0,n.jsxs)("div",{onClick:()=>r(T(e)),className:`rounded-md px-2 py-2 cursor-pointer transition-colors ${t?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)(a.A,{className:"w-4 h-4 text-brand flex-shrink-0"}),(0,n.jsx)("span",{className:`font-medium text-xs truncate flex-1 min-w-0 ${l?"text-muted-foreground":"text-foreground"}`,"data-tooltip":e.title,children:e.name?`@${e.name}`:e.title}),l&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:o("bots.invalid")})]}),(0,n.jsx)("p",{className:`text-xs mt-0.5 pl-6 truncate ${l?"text-destructive":"text-muted-foreground"}`,"data-tooltip":e.cwd,children:e.engine?e.name?(s=e.cwd).split(/[\\/]/).filter(Boolean).pop()??s:o("bots.sessionNameInvalid"):o("bots.sessionGone")})]})});function R({bot:e,confirmingRemove:t,onAskRemove:r,onCancelRemove:s,onRemove:o,onOpenSession:l}){let{t:a}=(0,u.Bd)();return(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:e.name?`@${e.name}`:e.title}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:e.name?a("bots.sessionUsage",{name:e.name}):a("bots.sessionNameInvalid")})]}),t?(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:o,className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:a("bots.removeSession")}),(0,n.jsx)("button",{onClick:s,className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:a("common.cancel")})]}):(0,n.jsx)("button",{onClick:r,className:"p-1.5 rounded text-muted-foreground hover:text-destructive hover:bg-red-9/10 flex-shrink-0","data-tooltip":a("bots.removeSession"),"aria-label":a("bots.removeSession"),children:(0,n.jsx)(i.A,{className:"w-4 h-4"})})]}),e.engine?(0,n.jsx)(y.p,{cwd:e.cwd,sessionId:e.sessionId,subtitle:e.title,emptyText:a("bots.noSessions"),onOpenSession:l}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:a("bots.sessionGone")})]})}let I=(0,s.memo)(function({bot:e,selected:t,onSelect:r}){let{t:s}=(0,u.Bd)(),o=e.valid?e.description:e.error;return(0,n.jsxs)("div",{onClick:()=>r(e.id),className:`rounded-md px-2 py-2 cursor-pointer transition-colors ${t?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)(d.A,{className:"w-4 h-4 text-brand flex-shrink-0"}),(0,n.jsxs)("span",{className:"font-medium text-xs text-foreground truncate flex-1 min-w-0","data-tooltip":e.path,children:["@",e.name]}),!e.valid&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:s("bots.invalid")})]}),(0,n.jsx)("p",{className:`text-xs mt-0.5 pl-6 truncate ${e.valid?"text-muted-foreground":"text-destructive"}`,"data-tooltip":o||void 0,children:o})]})});function F({bot:e,tab:t,onTab:r,sessions:o,confirmingRemove:l,onAskRemove:a,onCancelRemove:d,onRemove:x,onOpenAsProject:h,onOpenSession:f,onClose:p}){let{t:g}=(0,u.Bd)(),b=function(e,t){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=!1;return m.t4.runPromiseExit((0,k.QW)((0,L.O)(e.path))).then(e=>{t||(n("Success"===e._tag?e.value:[]),l(Date.now()))}),()=>{t=!0}},[e.path]),{rows:(0,s.useMemo)(()=>{let n=new Map(t.map(e=>[B(e.cwd,e.sessionId),e])),s=new Map;for(let t of r??[]){let r=t.sessionId||(t.path.split("/").pop()||"").replace(/\.jsonl$/,""),o=B(e.path,r),l=n.get(o);s.set(o,{cwd:e.path,sessionId:r,title:t.title,time:Math.max(Date.parse(t.modifiedAt)||0,l?.lastActive??0),engine:t.engine,bot:t.bot,status:l?.status,lastMessage:l?.lastUserMessage??t.lastMessages[t.lastMessages.length-1]??t.firstMessages[0]})}for(let r of t){if(!E(r,e))continue;let t=B(r.cwd,r.sessionId);s.has(t)||s.set(t,{cwd:r.cwd,sessionId:r.sessionId,title:r.title||r.sessionId,time:r.lastActive,engine:r.engine,bot:r.bot,status:r.status,lastMessage:r.lastUserMessage})}return[...s.values()].sort((e,t)=>t.time-e.time)},[r,t,e]),loading:null===r,loadedAt:o}}(e,o),v=(e,s)=>(0,n.jsx)("button",{onClick:()=>r(e),className:`px-3 py-1 transition-colors ${t===e?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:s}),j=(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-xs",children:[v("files",g("bots.tabFiles")),v("sessions",`${g("bots.tabSessions")}${b.rows.length?` ${b.rows.length}`:""}`)]}),(0,n.jsx)("button",{onClick:h,className:"p-1.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover","data-tooltip":g("bots.open"),"aria-label":g("bots.open"),children:(0,n.jsx)(c.A,{className:"w-4 h-4"})}),e.builtin?null:l?(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:x,className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:g("bots.remove")}),(0,n.jsx)("button",{onClick:d,className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:g("common.cancel")})]}):(0,n.jsx)("button",{onClick:a,className:"p-1.5 rounded text-muted-foreground hover:text-destructive hover:bg-red-9/10","data-tooltip":g("bots.remove"),"aria-label":g("bots.remove"),children:(0,n.jsx)(i.A,{className:"w-4 h-4"})})]});return"files"===t?(0,n.jsx)(w.g,{endpoint:"/api/bots/files",id:e.id,entryFile:"BOT.md",title:`@${e.name}`,actions:j,onClose:p}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("h2",{className:"text-sm font-medium text-foreground truncate",children:["@",e.name]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:g("bots.sessionsScope")})]}),j]}),(0,n.jsx)(A,{data:b,onOpenSession:f})]})}let B=(e,t)=>`${e}
6
- ${t}`,D=[{key:"today",labelKey:"sessions.dateToday"},{key:"yesterday",labelKey:"sessions.dateYesterday"},{key:"last7Days",labelKey:"sessions.dateLast7Days"},{key:"earlier",labelKey:"sessions.dateEarlier"}];function A({data:e,onOpenSession:t}){let{t:r}=(0,u.Bd)(),{rows:o,loading:l,loadedAt:a}=e,[i,d]=(0,s.useState)(null),c=o.find(e=>B(e.cwd,e.sessionId)===i)??o[0]??null,m=(0,s.useMemo)(()=>{let e=new Map;for(let t of o){let r=(0,N.j)(t.time,a),n=e.get(r);n?n.push(t):e.set(r,[t])}return D.map(t=>({...t,items:e.get(t.key)??[]})).filter(e=>e.items.length>0)},[o,a]);return l&&0===o.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:r("common.loading")}):0===o.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:r("bots.noSessions")}):(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsx)("div",{className:"w-72 flex-shrink-0 border-r border-border overflow-y-auto",children:(0,n.jsx)("div",{className:"p-2 space-y-2",children:m.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center",children:[(0,n.jsx)("span",{children:r(e.labelKey)}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(e=>{let s=B(e.cwd,e.sessionId),o=!!c&&B(c.cwd,c.sessionId)===s;return(0,n.jsxs)("div",{onClick:()=>d(s),onDoubleClick:()=>t(e.cwd,e.sessionId),className:`rounded-md px-2 py-2 cursor-pointer transition-colors ${o?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)(C.S,{engine:e.engine}),(0,n.jsx)("span",{className:"text-xs font-medium text-foreground truncate flex-1 min-w-0","data-tooltip":e.title,children:e.title}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:(0,S.fw)(r,e.time)}),(0,n.jsx)(M.l,{status:(0,M.S)(e.status),statusLabel:(0,S.Mm)(r,e.status),bot:e.bot})]}),e.lastMessage&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-[22px]","data-tooltip":e.lastMessage,children:e.lastMessage})]},s)})})]},e.key))})}),(0,n.jsx)("div",{className:"flex-1 flex min-w-0",children:c&&(0,n.jsx)(y.p,{cwd:c.cwd,sessionId:c.sessionId,subtitle:c.title,emptyText:r("sessions.noSessionMessages"),onOpenSession:()=>t(c.cwd,c.sessionId)},B(c.cwd,c.sessionId))})]})}function H({onCancel:e,onAdded:t}){let{t:r}=(0,u.Bd)(),[o,l]=(0,s.useState)(""),[a,i]=(0,s.useState)(!1),d=(0,s.useCallback)(async()=>{let e=o.trim();if(!e||a)return;i(!0);let n=await m.t4.runPromiseExit((0,f.zB)(e));if(i(!1),"Success"===n._tag){let{alreadyExists:e}=n.value;(0,v.oR)(r(e?"bots.alreadyAdded":"bots.added"),e?"info":"success"),e||(0,b._)(),t()}else(0,v.oR)((0,g.oh)(n.cause,r("bots.saveFailed")),"error")},[o,a,t,r]);return(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:()=>!a&&e()}),(0,n.jsxs)("div",{className:"relative w-full max-w-md rounded-xl border border-border bg-card p-5 shadow-xl",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-4",children:r("bots.addExisting")}),(0,n.jsx)("input",{autoFocus:!0,value:o,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||d()},placeholder:r("bots.pathPlaceholder"),className:"w-full px-3 py-2 text-sm font-mono border border-border rounded bg-background"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-3",children:r("bots.addHint")}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-5",children:[(0,n.jsx)("button",{disabled:a,onClick:e,className:"px-3 py-1.5 text-xs rounded border border-border",children:r("common.cancel")}),(0,n.jsx)("button",{disabled:a||!o.trim(),onClick:()=>void d(),className:"px-3 py-1.5 text-xs rounded bg-brand text-white disabled:opacity-50",children:a?r("common.loading"):r("common.confirm")})]})]})]})}},2228:(e,t,r)=>{r.d(t,{ProjectItem:()=>p});var n=r(95155),s=r(12115),o=r(79114),l=r(86957),a=r(16147),i=r(68287),d=r(2111),c=r(39872),u=r(53213),m=r(49387);function x({badge:e,onSelect:t}){return(0,n.jsx)("button",{type:"button",onClick:r=>{r.stopPropagation(),t(e.sessionId)},className:"flex flex-shrink-0 items-center justify-center rounded-full transition-transform hover:scale-125",title:e.bot?`@${e.bot}`:e.label,children:(0,n.jsx)(a.w,{wash:(0,i.JQ)(e.status,!1),ring:(0,i.QV)(e.status),bot:e.bot,children:e.label})})}let h=[],f=()=>{};function p({index:e,name:t,cwd:r,isActive:a,collapsed:i,hasUnread:g,isLoading:b,hasDraft:v,sessionBadges:j,onClick:w,onSelectSession:k,onRemove:y,onOpenNote:N}){let{t:C}=(0,o.Bd)(),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),P=(0,s.useCallback)(()=>{l.t4.runPromiseExit((0,u.ue)(r)).then(e=>{"Success"===e._tag&&E(e.value.branch)})},[r]);(0,s.useEffect)(()=>{P()},[P]);let T=(0,s.useCallback)(e=>{e?.type==="watch"&&Array.isArray(e.data)&&e.data.some(e=>"git"===e.type)&&P()},[P]);(0,d.h)({url:`/ws/watch?cwd=${encodeURIComponent(r)}`,onMessage:T});let $=j??h,R=L?i?`${t} \xb7 ${L}`:L:r;return(0,n.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1 rounded-lg cursor-pointer transition-colors relative ${i?"justify-center":""} ${a?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary hover:text-foreground"}`,onClick:w,onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),"data-tooltip":R,children:[(0,n.jsxs)("span",{className:"relative flex-shrink-0",children:[(0,n.jsx)(c.B,{number:e+1,status:i?b?"loading":g&&!a?"unread":"normal":"normal",isActive:a}),v&&(0,n.jsx)("span",{className:"absolute -right-1.5 -top-1.5 flex h-3 w-3 items-center justify-center rounded-full bg-secondary text-muted-foreground",title:C("workspace.unsentDraft"),children:(0,n.jsx)(m.A,{className:"h-2 w-2",strokeWidth:2.5})})]}),!i&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:`flex-1 truncate text-sm ${a?"text-brand":""}`,children:t}),S&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[N&&(0,n.jsx)("button",{className:"p-1 rounded hover:bg-hover text-muted-foreground hover:text-foreground transition-colors",onClick:e=>{e.stopPropagation(),N()},title:C("workspace.projectNotes"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"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,n.jsx)("button",{className:"p-1 rounded hover:bg-red-500/20 text-muted-foreground hover:text-red-11 transition-colors",onClick:e=>{e.stopPropagation(),y()},title:C("workspace.closeProject"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),$.length>0&&(0,n.jsx)("div",{className:"flex items-center gap-1 flex-shrink-0",children:$.map(e=>(0,n.jsx)(x,{badge:e,onSelect:k??f},e.sessionId))})]})]})}},2349:(e,t,r)=>{r.d(t,{j:()=>m});var n=r(95155),s=r(12115),o=r(79114),l=r(2111),a=r(34075),i=r(86957),d=r(47650);function c({open:e,anchorRef:t,initialValue:r,onCancel:l,onSave:a}){let{t:i}=(0,o.Bd)(),[u,m]=(0,s.useState)(r),[x,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)(null),g=(0,s.useRef)(null),b=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(e){m(r),h(!1);let e=requestAnimationFrame(()=>{g.current?.focus(),g.current?.select()});return()=>cancelAnimationFrame(e)}p(null)},[e,r]);let v=(0,s.useCallback)(()=>{let e=t.current;if(!e)return;let r=e.getBoundingClientRect(),n=b.current?.offsetHeight??0,s=r.bottom+4;if(n&&s+n>window.innerHeight-8){let e=r.top-4-n;e>=8&&(s=e)}let o=r.left;p({top:s,left:o=Math.max(o=Math.min(o,window.innerWidth-260-8),8)})},[t]);if((0,s.useLayoutEffect)(()=>{if(e)return v(),window.addEventListener("resize",v),window.addEventListener("scroll",v,!0),()=>{window.removeEventListener("resize",v),window.removeEventListener("scroll",v,!0)}},[e,v]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&(e.preventDefault(),l())},n=e=>{let r=e.target;b.current?.contains(r)||t.current?.contains(r)||l()};return window.addEventListener("keydown",r),document.addEventListener("mousedown",n,!0),()=>{window.removeEventListener("keydown",r),document.removeEventListener("mousedown",n,!0)}},[e,l,t]),!e||"u"<typeof document)return null;let j=async()=>{if(!x){h(!0);try{await a(u.trim())}finally{h(!1)}}};return(0,d.createPortal)((0,n.jsxs)("div",{ref:b,style:{top:f?.top??0,left:f?.left??0,width:260,visibility:f?"visible":"hidden"},className:"fixed z-[100] rounded-lg border border-border bg-card p-3 shadow-lv3",children:[(0,n.jsx)("div",{className:"mb-2 text-sm font-medium text-foreground",children:i("shortIdBadge.dialogTitle")}),(0,n.jsx)("input",{ref:g,type:"text",value:u,onChange:e=>m(e.target.value.slice(0,64)),onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||229===e.keyCode||(e.preventDefault(),j())},placeholder:i("shortIdBadge.dialogPlaceholder"),maxLength:64,className:"w-full rounded border border-border bg-background px-2 py-1.5 text-sm font-mono outline-none focus:border-brand"}),(0,n.jsxs)("div",{className:"mt-3 flex justify-end gap-2 text-sm",children:[(0,n.jsx)("button",{onClick:l,className:"rounded px-3 py-1 text-muted-foreground hover:bg-hover",disabled:x,children:i("common.cancel")}),(0,n.jsx)("button",{onClick:()=>void j(),className:"rounded bg-brand px-3 py-1 text-white hover:opacity-90 disabled:opacity-50",disabled:x,children:x?"…":i("common.save")})]})]}),document.body)}var u=r(94720);let m=(0,s.memo)(function({shortId:e,type:t,onRegister:r,onUnregister:d,fullId:m,projectCwd:x,tabId:h,registered:f}){let{t:p}=(0,o.Bd)(),[g,b]=(0,s.useState)(!1),v=f??g,[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)(!1),N=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!m||!x||!h)return;let e=!1;return i.t4.runPromiseExit((0,u.MR)(x,h)).then(t=>{if(e||"Success"!==t._tag)return;let r=t.value[m];"string"==typeof r&&w(r)}),()=>{e=!0}},[m,x,h]),(0,l.h)({url:"/ws/global-state",enabled:!!m&&!!x&&!!h,onMessage:e=>{"console-delta"!==e.type||"rename"!==e.op||e.cwd!==x||e.tabId!==h||e.titles&&m&&Object.prototype.hasOwnProperty.call(e.titles,m)&&w(e.titles[m]??"")}});let C=(0,s.useCallback)(async n=>{if(n.stopPropagation(),v)await d(),b(!1),(0,a.oR)(p("toast.disconnected",{id:e}));else{await r(),b(!0);let n=`${"3456"===window.location.port?"cockpit-dev":"cockpit"} ${t} ${e}`;navigator.clipboard.writeText(n),(0,a.oR)(p("toast.copiedCommand",{command:n}))}},[v,e,t,r,d,p]),S=!!(m&&x&&h),M=(0,s.useCallback)(e=>{e.stopPropagation(),S&&y(!0)},[S]),L=(0,s.useCallback)(async e=>{m&&x&&h&&("Success"===(await i.t4.runPromiseExit((0,u.y8)(x,h,m,e)))._tag&&w(e),y(!1))},[m,x,h]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:C,onDoubleClick:e=>e.stopPropagation(),className:"inline-flex items-center gap-1 text-[10px] font-mono leading-none px-1.5 py-0.5 rounded flex-shrink-0 transition-colors bg-muted/60 hover:bg-muted text-muted-foreground",title:v?p("shortIdBadge.clickToDisconnect"):p("shortIdBadge.clickToRegister"),children:[(0,n.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${v?"bg-green-500":"bg-muted-foreground/40"}`}),e]}),S&&(j?(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-[10px] leading-none flex-shrink-0 text-muted-foreground",title:p("shortIdBadge.titleSet",{title:j})||j,children:[(0,n.jsx)("span",{className:"px-1 py-0.5 rounded bg-muted/40 max-w-[120px] truncate",children:j}),(0,n.jsx)("button",{ref:N,onClick:M,className:"opacity-50 hover:opacity-100 transition-opacity","aria-label":p("shortIdBadge.editTitle"),title:p("shortIdBadge.editTitle"),children:"✎"})]}):(0,n.jsxs)("button",{ref:N,onClick:M,className:"inline-flex items-center gap-0.5 text-[10px] leading-none flex-shrink-0 text-muted-foreground/50 hover:text-muted-foreground italic transition-colors",title:p("shortIdBadge.setTitle"),children:["(",p("shortIdBadge.setTitlePlaceholder"),") ✎"]})),(0,n.jsx)(c,{open:k,anchorRef:N,initialValue:j,onCancel:()=>y(!1),onSave:L})]})})},4768:(e,t,r)=>{r.d(t,{O:()=>n});function n(e){let t=e.replace(/[^a-zA-Z0-9]/g,"-");return t.length<=200?t:`${t.slice(0,200)}-${function(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r)|0;return Math.abs(t).toString(36)}(e)}`}},6632:(e,t,r)=>{r.d(t,{TabManager:()=>sV});var n=r(95155),s=r(12115),o=r(79114),l=r(64428),a=r(57125),i=r(53317);let d="claude-opus-5-5",c="gpt-6.2-sol",u=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultracode",label:"Ultracode"},{id:"ultrathink",label:"Ultrathink"}],m=[{id:"claude-sonnet-5-5",label:"Claude Sonnet 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium"},{id:"claude-sonnet-5",label:"Claude Sonnet 5",effort:["low","medium","high","xhigh","max","ultrathink"],defaultEffort:"high"},{id:"claude-opus-5-5",label:"Claude Opus 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium",fast:!0},{id:"claude-opus-5",label:"Claude Opus 5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",fast:!0},{id:"claude-fable-5-1",label:"Claude Fable 5.1",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high"},{id:"claude-haiku-5-5",label:"Claude Haiku 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium"},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5",thinking:!0}],x=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultra",label:"Ultra",description:"Max reasoning with parallel agents"}],h=[{id:"gpt-6.2-sol",label:"GPT-6.2 Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"high"},{id:"gpt-6.2-astra",label:"GPT-6.2 Astra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"high"},{id:"gpt-6.1-terra",label:"GPT-6.1 Terra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"medium"},{id:"gpt-6.1-sol",label:"GPT-6.1 Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"high"},{id:"gpt-6-astra",label:"GPT-6 Astra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"high"},{id:"gpt-6-sol",label:"GPT-6 Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"high"},{id:"gpt-6-luna",label:"GPT-6 Luna",reasoning:["low","medium","high","xhigh","max"],defaultReasoning:"medium"},{id:"gpt-5.6-sol",label:"GPT-5.6 Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"high"},{id:"gpt-5.6-terra",label:"GPT-5.6 Terra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"medium"},{id:"gpt-5.6-luna",label:"GPT-5.6 Luna",reasoning:["low","medium","high","xhigh","max"],defaultReasoning:"medium"}];function f(e){return h.find(t=>t.id===e)?.defaultReasoning??"medium"}function p(e,t){let r=h.find(t=>t.id===e)?.reasoning;return t&&(!r||r.includes(t))?t:f(e)}function g(e,t){return e.find(e=>e.id===t)?.label??t}function b(e){return m.find(t=>t.id===e)?.fast===!0}function v(e){return m.find(t=>t.id===e)?.thinking===!0}function j(e){let t=m.find(t=>t.id===e);return t?t.defaultEffort:"high"}function w(e,t){let r=m.find(t=>t.id===e),n=r?.effort;return t&&(!r||n?.includes(t))?t:j(e)}function k({value:e,selected:t,label:r,description:s,defaultValue:o,onSelect:l}){return(0,n.jsxs)("button",{type:"button",onClick:()=>l(e),className:`flex w-full items-start gap-2 px-3 py-2 text-left text-xs transition-colors ${t?a.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(a.hG,{selected:t})}),(0,n.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"block truncate",children:r}),s&&(0,n.jsx)("span",{className:"mt-0.5 block text-[10px] text-muted-foreground",children:s})]}),(0,n.jsx)("span",{className:"shrink-0",children:o&&(0,n.jsx)("span",{className:"rounded bg-muted px-1.5 text-[10px] font-medium text-muted-foreground",children:"Default"})})]})}function y({title:e,selected:t,value:r,items:o,onSelect:i,icon:d,testId:c}){let u=(0,s.useRef)(null),m=(0,s.useRef)(null),[x,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)({top:0,left:0}),g=(0,l.F2)(),b=o.find(e=>e.id===t)?.description,v=()=>{let e=u.current?.getBoundingClientRect();if(!e)return;let t=g?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;p({top:e.bottom+4-n,left:e.left-r})};return(0,s.useEffect)(()=>{if(!x)return;let e=e=>{let t=e.target;m.current?.contains(t)||u.current?.contains(t)||h(!1)},t=()=>v();return document.addEventListener("mousedown",e),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[x]),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(a.XY,{buttonRef:u,label:r,labelMaxWidth:"max-w-[180px]",title:`${e}: ${r}${b?`
7
- ${b}`:""}`,onClick:()=>{x||v(),h(e=>!e)},icon:d,testId:c}),x&&(0,n.jsx)(l.ZL,{children:(0,n.jsxs)("div",{ref:m,className:`${a.ys} min-w-[190px]`,style:{top:f.top,left:f.left},children:[(0,n.jsx)("div",{className:"px-3 pb-1 text-[11px] font-medium text-muted-foreground",children:e}),(0,n.jsx)("div",{className:"flex flex-col",children:o.map(e=>(0,n.jsx)(k,{value:e.id,selected:t===e.id,label:e.label,description:e.description,defaultValue:e.defaultValue,onSelect:e=>{i(e),h(!1)}},e.id))})]})})]})}function N(e){let t,r,s,o=e.engine??"claude",l=e.claudeModel??d,k=j(l),N=(t=m.find(e=>e.id===l)?.effort)?t.map(e=>u.find(t=>t.id===e)??{id:e,label:e}):[],C=w(l,e.claudeEffort),S=e.claudeFastMode??!1,M=e.claudeThinking??!1,L=e.codexModel??c,E=f(L),P=(r=h.find(e=>e.id===L)?.reasoning)?r.map(e=>x.find(t=>t.id===e)??{id:e,label:e}):x,T=p(L,e.codexReasoningEffort);return"claude"!==o?(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(y,{title:"Model",selected:L,value:h.find(e=>e.id===L)?.label??(0,i.U)(L),items:h.map(e=>({id:e.id,label:e.label,defaultValue:e.id===c})),onSelect:t=>{e.onCodexModelChange?.(t),e.onCodexReasoningEffortChange?.(f(t))},icon:(0,n.jsx)(a.eV,{engine:"codex"}),testId:"codex-model-picker"}),(0,n.jsx)(y,{title:"Reasoning",selected:T,value:g(x,T),items:P.map(e=>({...e,defaultValue:e.id===E})),onSelect:t=>e.onCodexReasoningEffortChange?.(t),testId:"codex-reasoning-picker"})]}):(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(y,{title:"Model",selected:l,value:(s=m.find(e=>e.id===l))?s.label:l.startsWith("claude-")?`Claude ${(0,i.J)(l)}`:l,items:m.map(e=>({id:e.id,label:e.label,defaultValue:e.id===d})),onSelect:t=>{e.onClaudeModelChange?.(t);let r=j(t);r&&e.onClaudeEffortChange?.(r),b(t)||e.onClaudeFastModeChange?.(!1),v(t)||e.onClaudeThinkingChange?.(!1)},icon:(0,n.jsx)(a.eV,{engine:"claude"}),testId:"claude-model-picker"}),C&&N.length>0&&(0,n.jsx)(y,{title:"Reasoning",selected:C,value:g(u,C),items:N.map(e=>({...e,defaultValue:e.id===k})),onSelect:t=>e.onClaudeEffortChange?.(t),testId:"claude-reasoning-picker"}),b(l)&&(0,n.jsx)(y,{title:"Fast Mode",selected:S?"on":"off",value:S?"Fast On":"Fast Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeFastModeChange?.("on"===t),testId:"claude-fast-mode-picker"}),v(l)&&(0,n.jsx)(y,{title:"Thinking",selected:M?"on":"off",value:M?"Thinking On":"Thinking Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeThinkingChange?.("on"===t),testId:"claude-thinking-picker"})]})}let C=(0,s.createContext)(null);function S({value:e,children:t}){return(0,n.jsx)(C.Provider,{value:e,children:t})}var M=r(59461),L=r(47650),E=r(72312),P=r(86957),T=r(60938),$=r(51145),R=r(53213),I=r(45619),F=r(24602),B=r(5135),D=r(30133),A=r(48661),H=r(88780),O=r(20080);let W=(e,t,r)=>`/api/git/blob?cwd=${encodeURIComponent(e)}&rev=${encodeURIComponent(t)}&file=${encodeURIComponent(r)}`;function _({cwd:e,filePath:t,oldRev:r,newRev:s,newNode:o}){return(0,n.jsx)(O.K,{filePath:t,oldSrc:r?W(e,r,t):null,newSrc:s?W(e,s,t):null,newNode:o})}var z=r(94287),q=r(34075);let V=(0,s.memo)(function({cwd:e,filePath:t,onLocateInTree:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate",title:t,children:t}),(0,n.jsx)(z.m,{content:s("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,q.oR)(s("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 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"})})})}),r&&(0,n.jsx)(z.m,{content:s("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),r(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})})]})});var U=r(82292),K=r(47215),Q=r(56045);function G({preview:e,onClose:t,search:r,preRef:s}){return(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-[90%] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:e.filePath}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(Q._,{search:r}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-secondary",children:(0,n.jsx)("pre",{ref:s,className:"whitespace-pre-wrap break-words font-mono text-foreground",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:(0,K.xb)(e.content)})})]})})}var J=r(48347),Y=r(62111),X=r(61043);function Z({isOpen:e,onClose:t,commit:r,cwd:l,embedded:a=!1,initialFilePath:i,onContentSearch:d,onLocateInTree:c}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)([]),[h,f]=(0,s.useState)([]),[p,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(null),[L,E]=(0,s.useState)(null),[T,$]=(0,s.useState)(null),O=(0,s.useCallback)(()=>$(null),[]),W=(0,s.useCallback)(()=>M(null),[]),[z,q]=(0,s.useState)("compact"),[ee,et]=(0,s.useState)("unified"),er=(0,s.useRef)(null),en=(0,Q.o)(er),es=(0,J.r)(),eo=r?.shortHash,el=(0,s.useCallback)(e=>{eo&&es?.sendMessage(u("explain.commitFileMessage",{hash:eo,path:e}))},[es,u,eo]);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&S){e.preventDefault(),en.open();return}if("Escape"===e.key){if(en.isVisible)return void en.close();if(L)return void E(null);if(T)return void $(null);if(S)return void M(null);(0,Y.k)(),t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,L,T,S,en]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{x([]),f([]),v(null),w(null),y(!0)}),P.t4.runPromiseExit((0,R.Zi)(l,r.hash)).then(e=>{if("Success"===e._tag){let t=e.value.files??[];x(t);let n=(0,H.Do)(t);if(f(n),g(new Set((0,H.Sz)(n))),i&&t.length>0){let e=t.find(e=>e.path===i);e&&setTimeout(()=>{v(e),P.t4.runPromiseExit((0,R.Zi)(l,r.hash,e.path)).then(e=>{"Success"===e._tag?w(e.value):console.error(e.cause)})},0)}}else console.error(e.cause);y(!1)}))},[e,r,l,i]);let ea=(0,s.useCallback)(e=>{r&&(v(e),C(!0),P.t4.runPromiseExit((0,R.Zi)(l,r.hash,e.path)).then(e=>{"Success"===e._tag?w(e.value):console.error(e.cause),C(!1)}))},[l,r]),ei=(0,s.useCallback)(e=>{g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ed=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,l,a;return e=new Date(r.date),t=new Date,n=e.getFullYear()===t.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),l=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${l}:${a}`:`${e.getFullYear()}-${s}-${o} ${l}:${a}`}return r.time?new Date(1e3*r.time).toLocaleString():""},[r]),ec=j?.filePath,eu=(0,s.useMemo)(()=>ec?(0,n.jsx)(V,{cwd:l,filePath:ec,onLocateInTree:c}):null,[l,ec,c]);if(!e||!r)return null;let em=!!j&&(!0===j.isImage||(0,U.u)(j.filePath)),ex=(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-2",children:r.subject}),r.body&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground whitespace-pre-wrap mb-3 max-h-32 overflow-y-auto border-l-2 border-border pl-3",children:r.body}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:u("commitDetail.hash")}),(0,n.jsx)("span",{className:"font-mono bg-accent px-1.5 py-0.5 rounded",children:r.hash})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:u("commitDetail.author")}),(0,n.jsx)("span",{children:r.author}),(0,n.jsxs)("span",{className:"text-foreground-subtle",children:["<",r.authorEmail,">"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:u("commitDetail.date")}),(0,n.jsx)("span",{children:ed}),r.relativeDate&&(0,n.jsxs)("span",{className:"text-foreground-subtle",children:["(",r.relativeDate,")"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:u("commitDetail.files")}),(0,n.jsx)("span",{children:u("commitDetail.nChanges",{count:m.length})})]}),!em&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[(0,n.jsx)(D.y,{value:z,onChange:q}),(0,n.jsx)(A.q,{value:ee,onChange:et})]})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)(X.q,{children:k?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:u("commitDetail.loadingFiles")}):(0,n.jsxs)(n.Fragment,{children:[m.length>0&&(0,n.jsx)(H.WY,{files:m}),(0,n.jsx)(H.VO,{files:h,selectedPath:b?.path||null,expandedPaths:p,onSelect:e=>e.file&&ea(e.file),onToggle:ei,cwd:l,showChanges:!0,showChangeClass:!0,emptyMessage:u("commitDetail.noFileChanges"),className:"py-1",onExplain:es&&eo?el:void 0,explainDisabled:es?.isLoading})]})}),(0,n.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:N?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:u("commitDetail.loadingDiff")}):j?em?(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)("div",{className:"flex-shrink-0 px-2 py-1 border-b border-border bg-accent",children:eu}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(_,{cwd:l,filePath:j.filePath,oldRev:j.oldRev??(j.isNew?null:`${r.hash}^1`),newRev:j.newRev??(j.isDeleted?null:r.hash)})})]}):"unified"===ee?(0,n.jsx)(I.xU,{oldContent:j.oldContent,newContent:j.newContent,filePath:j.filePath,cwd:l,enableComments:!0,compact:"compact"===z,headerLeading:eu,onPreview:j.isDeleted?void 0:(0,K.aR)(j.filePath)?()=>E({content:j.newContent,filePath:j.filePath}):(0,K.e$)(j.filePath)?()=>$({content:j.newContent,filePath:j.filePath}):j.filePath.endsWith(".json")?()=>M({content:j.newContent,filePath:j.filePath}):void 0,previewLabel:j.filePath.endsWith(".json")?u("common.readable"):u("common.preview"),onContentSearch:d}):(0,n.jsx)(I.xZ,{oldContent:j.oldContent,newContent:j.newContent,filePath:j.filePath,isNew:j.isNew,isDeleted:j.isDeleted,cwd:l,enableComments:!0,compact:"compact"===z,headerLeading:eu,onPreview:j.isDeleted?void 0:(0,K.aR)(j.filePath)?()=>E({content:j.newContent,filePath:j.filePath}):(0,K.e$)(j.filePath)?()=>$({content:j.newContent,filePath:j.filePath}):j.filePath.endsWith(".json")?()=>M({content:j.newContent,filePath:j.filePath}):void 0,previewLabel:j.filePath.endsWith(".json")?u("common.readable"):u("common.preview"),onContentSearch:d}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:u("commitDetail.selectFileToView")})})]})]}),eh=S&&(0,n.jsx)(G,{preview:S,onClose:W,search:en,preRef:er}),ef=L&&(0,n.jsx)(F.N,{filePath:L.filePath,content:L.content,cwd:l,onClose:()=>E(null)}),ep=T&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:O,children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(B.M,{content:T.content,filePath:T.filePath,cwd:l,onClose:O})})});return a?(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-2 right-2 z-10 p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",title:u("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),ex,eh,ef,ep]}):(0,n.jsx)("div",{className:"fixed inset-0 z-[60] bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:u("commitDetail.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),ex,eh,ef,ep]})})}var ee=r(64702),et=r(70188),er=r(14575);let en={M:{text:"text-amber-11",bg:"bg-amber-9/20"},A:{text:"text-green-11",bg:"bg-green-9/20"},D:{text:"text-red-11",bg:"bg-red-9/20"},R:{text:"text-blue-11",bg:"bg-blue-9/20"}},es=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:l,onToggle:a,onContextMenu:i,renderActions:d}){let{node:c,level:u,gitStatus:m,hasChangedChildren:x}=e,h=m?en[m]:null,f=(0,s.useCallback)(()=>{c.isDirectory?a(c.path):l(c.path)},[c.isDirectory,c.path,l,a]),p=(0,s.useCallback)(e=>{i(e,c.path,c.isDirectory)},[c.path,c.isDirectory,i]),g=!c.isDirectory&&(".env"===c.name||c.name.startsWith(".env.")),b=m?h.text:x?"text-amber-11":g?"text-yellow-600 dark:text-yellow-500":t&&!c.isDirectory?"text-brand":"text-foreground";return(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 cursor-pointer hover:bg-hover ${t?"bg-brand/10":""}`,style:{paddingLeft:`${12*u+8}px`},onClick:f,onContextMenu:p,children:[c.isDirectory?o?(0,n.jsxs)("svg",{className:"w-4 h-4 flex-shrink-0 text-muted-foreground animate-spin",viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.3"}),(0,n.jsx)("path",{d:"M14 8a6 6 0 0 0-6-6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):(0,n.jsx)("svg",{className:`w-4 h-4 flex-shrink-0 text-muted-foreground transition-transform ${r?"rotate-90":""}`,viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M6 4 L10 8 L6 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}):(0,n.jsx)(er.o,{name:c.name,size:16,className:"flex-shrink-0 ml-4"}),(0,n.jsx)("span",{className:`text-sm truncate flex-1 ${b}`,"data-tooltip":c.isSymlink&&c.symlinkTarget?`${c.path} → ${c.symlinkTarget}`:c.path,children:c.name}),c.isSymlink&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:"→"}),m&&(0,n.jsx)("span",{className:`text-xs font-mono px-1 rounded ${h.text} ${h.bg} flex-shrink-0`,children:m}),c.isDirectory&&x&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-9 flex-shrink-0"}),d?.(c)]})});function eo({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:l=null,loadingDirs:a,onSelect:i,onToggle:d,cwd:c,shouldScrollToSelected:u=!1,onScrolledToSelected:m,className:x,renderActions:h,onCreateFile:f,onDelete:p,onRefresh:g,onCopyFile:b,onPaste:v,onExplain:j,explainDisabled:w}){let k=(0,s.useRef)(null),{contextMenu:y,showContextMenu:N,hideContextMenu:C}=(0,et.Ee)(),S=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let l=[];for(let a of t){if(null!==n&&!n.has(a.path))continue;let t=s?.get(a.path),i=a.isDirectory?function(e,t){if(!t)return!1;let r=e+"/";for(let e of t.keys())if(e.startsWith(r))return!0;return!1}(a.path,s):void 0;l.push({node:a,level:o,gitStatus:t,hasChangedChildren:i}),a.isDirectory&&a.children&&r.has(a.path)&&l.push(...e(a.children,r,n,s,o+1))}return l})(e,r,o,l),[e,r,o,l]),M=(0,ee.Te)({count:S.length,getScrollElement:()=>k.current,estimateSize:()=>26,overscan:10}),L=(0,s.useRef)(m);return(L.current=m,(0,s.useEffect)(()=>{if(u&&t&&S.length>0){let e=S.findIndex(e=>e.node.path===t);if(e>=0){let t=setTimeout(()=>{M.scrollToIndex(e,{align:"center"}),L.current?.()},150);return()=>clearTimeout(t)}}},[u,t,S,M]),0===S.length)?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:"No files"}):(0,n.jsxs)("div",{ref:k,className:x||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${M.getTotalSize()}px`,width:"100%",position:"relative"},children:M.getVirtualItems().map(e=>{let s=S[e.index];return(0,n.jsx)("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},children:(0,n.jsx)(es,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:a?.has(s.node.path),onSelect:i,onToggle:d,onContextMenu:N,renderActions:h})},s.node.path)})}),y&&(0,n.jsx)(et.ft,{x:y.x,y:y.y,path:y.path,cwd:c,isDirectory:y.isDirectory,onClose:C,onCreateFile:f,onDelete:p,onRefresh:g,onCopyFile:b,onPaste:v,onExplain:j,explainDisabled:w})]})}var el=r(38408),ea=r(32041),ei=r(14341),ed=r(42804),ec=r(22164),eu=r(34582),em=r(86304),ex=r(43595),eh=r(88403),ef=r(85269);function ep({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),l=o>=0?e.slice(0,o+1):"",a=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],l="",a=!1;for(let s=0;s<e.length;s++){let i=t+s,d=r.has(i);d!==a&&l&&(o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-${s}`):(0,n.jsx)("span",{children:l},`${t}-${s}`)),l=""),a=d,l+=e[s]}return l&&o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-end`):(0,n.jsx)("span",{children:l},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[l&&i(l,0,"text-muted-foreground"),i(a,l.length,"text-foreground")]})}function eg({files:e,fileIndex:t,recentFiles:r,onSelectFile:a,onClose:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(""),[m,x]=(0,s.useState)(0),h=(0,s.useRef)(null),f=(0,s.useRef)(null),p=(0,s.useMemo)(()=>{let r,n;return t??(r=[],(n=e=>{for(let t of e)t.isDirectory&&t.children?n(t.children):t.isDirectory||r.push(t.path)})(e),r)},[t,e]),g=(0,s.useMemo)(()=>{if(!c.trim()){let e=new Set(r);return[...r.map(e=>({path:e,score:0,matchedIndices:[]})),...p.filter(t=>!e.has(t)).slice(0,50).map(e=>({path:e,score:0,matchedIndices:[]}))]}let e=[];for(let t of p){let n=function(e,t){let r=e.toLowerCase(),n=t.toLowerCase(),s=[],o=0,l=0,a=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),a===i-1&&(l+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(l+=10),i>e.lastIndexOf("/")&&(l+=3),e[i]===t[o]&&(l+=1),a=i,o++);return o<n.length?null:(l-=.1*e.length,{path:e,score:l,matchedIndices:s})}(t,c.trim());n&&(r.includes(t)&&(n.score+=20),e.push(n))}return e.sort((e,t)=>t.score-e.score),e.slice(0,50)},[c,p,r]),b=(0,s.useCallback)(e=>{u(e),x(0)},[]);(0,s.useEffect)(()=>{h.current?.focus()},[]),(0,s.useEffect)(()=>{if(f.current){let e=f.current.children[m];e?.scrollIntoView({block:"nearest"})}},[m]);let v=(0,s.useCallback)(e=>{a(e),i()},[a,i]),j=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing)switch(e.key){case"ArrowDown":e.preventDefault(),x(e=>Math.min(e+1,g.length-1));break;case"ArrowUp":e.preventDefault(),x(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),g[m]&&v(g[m].path);break;case"Escape":e.preventDefault(),i()}},[g,m,v,i]);return(0,n.jsx)(l.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-start justify-center pt-[15vh]",onClick:i,children:(0,n.jsxs)("div",{className:"w-[680px] max-h-[60vh] bg-card border border-border rounded-lg shadow-lv3 overflow-hidden flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),(0,n.jsx)("input",{ref:h,value:c,onChange:e=>b(e.target.value),onKeyDown:j,placeholder:d("quickFileOpen.placeholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none",autoComplete:"off",autoCorrect:"off",spellCheck:"false"}),(0,n.jsx)("kbd",{className:"text-[10px] text-muted-foreground px-1.5 py-0.5 rounded border border-border bg-secondary",children:"ESC"})]}),(0,n.jsx)("div",{ref:f,className:"flex-1 overflow-y-auto py-1",children:0===g.length?(0,n.jsx)("div",{className:"px-3 py-8 text-center text-sm text-muted-foreground",children:d("quickFileOpen.noMatch")}):g.map((e,t)=>(0,n.jsxs)("div",{className:`px-3 py-1.5 flex items-center gap-2 cursor-pointer transition-colors ${t===m?"bg-brand/15 text-foreground":"hover:bg-hover text-foreground"}`,"data-tooltip":e.path,onClick:()=>v(e.path),children:[(0,n.jsx)(er.o,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(ep,{path:e.path,matchedIndices:e.matchedIndices}),!c.trim()&&r.includes(e.path)&&(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground px-1.5 py-0.5 rounded bg-secondary flex-shrink-0",children:d("quickFileOpen.recent")})]},e.path))}),(0,n.jsxs)("div",{className:"px-3 py-1.5 border-t border-border flex items-center gap-3 text-[10px] text-muted-foreground",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"↑↓"})," ",d("quickFileOpen.selectHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Enter"})," ",d("quickFileOpen.openHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Esc"})," ",d("quickFileOpen.closeHint")]})]})]})})})}var eb=r(2111),ev=r(41474),ej=r(61878),ew=r(33210),ek=r(48368),ey=r(91958),eN=r(45916),eC=r(31794),eS=r(69048),eM=r(97567),eL=r(68806),eE=r(52475);function eP({kind:e,qname:t,className:r}){let s=`${(function(e,t){if("__file__"===t||"__preamble__"===t||t&&t.startsWith("__heading_"))return"text-muted-foreground/60";switch(e){case"function":case"method":return"text-violet-11";case"class":return"text-amber-11";case"interface":return"text-blue-11";default:return"text-muted-foreground/60"}})(e,t)} ${r??""}`.trim();if("__file__"===t)return(0,n.jsx)(ek.A,{className:s});if("__preamble__"===t)return(0,n.jsx)(eN.A,{className:s});if(t&&t.startsWith("__heading_"))return(0,n.jsx)(eC.A,{className:s});switch(e){case"function":case"method":return(0,n.jsx)(eS.A,{className:s});case"class":return(0,n.jsx)(eM.A,{className:s});case"interface":return(0,n.jsx)(eL.A,{className:s});default:return(0,n.jsx)(eE.A,{className:s})}}var eT=r(49433),e$=r(82680);let eR=new Map,eI=(e,t,r=!1)=>`${e}::${r?"project":"file"}::${t}`;function eF(e){if(!e)return void eR.clear();let t=`${e}::`;for(let e of eR.keys())e.startsWith(t)&&eR.delete(e)}async function eB(e,t,r=!1,n=!1){let s=eI(e,t,n);if(r)eF(e);else{let e=eR.get(s);if(e)return e}let o=eT.$mh({try:async()=>{let s=new URLSearchParams({cwd:e,path:t});r&&s.set("refresh","1"),n&&s.set("relations","1");let o=await fetch(`/api/projectGraph/file-functions?${s}`);if(404===o.status)return"not-found";if(!o.ok)throw Error((await o.json().catch(()=>({error:`HTTP ${o.status}`}))).error||`HTTP ${o.status}`);return await o.json()},catch:e=>new e$.uV({message:"fetchFileFunctions failed",cause:e})}),l=P.t4.runPromiseExit(o).then(e=>{if("Success"===e._tag)return e.value;let t="Fail"===e.cause._tag?e.cause.error:null,r=t?.cause;if(r instanceof Error)throw r;throw Error(t?.message??"fetchFileFunctions failed")}).finally(()=>{eR.get(s)===l&&eR.delete(s)});return eR.set(s,l),l}function eD(e,t,r=!1){let[n,o]=(0,s.useState)({state:"idle"}),l=(0,s.useRef)(!0);(0,s.useEffect)(()=>(l.current=!0,()=>{l.current=!1}),[]);let a=(0,s.useRef)(""),i=(0,s.useRef)(0),d=(0,s.useCallback)((e,t,n,s=!1,d=r)=>{let c=eI(e,t,r);a.current=c;let u=++i.current;s||o({state:"loading"}),eB(e,t,n,d).then(e=>{l.current&&a.current===c&&i.current===u&&("not-found"===e?o({state:"notFound"}):o({state:"ready",data:e}))}).catch(e=>{l.current&&a.current===c&&i.current===u&&!s&&o({state:"error",message:e.message})})},[r]);(0,s.useEffect)(()=>{e&&t?d(e,t,!1):o({state:"idle"})},[e,t,d]);let c=(0,s.useCallback)(()=>{e&&t&&d(e,t,!0)},[e,t,d]),u=(0,s.useCallback)(()=>{e&&t&&d(e,t,!1,!0)},[e,t,d]),m="ready"===n.state&&!0===n.data.crossFilePending,x=(0,s.useCallback)(()=>{eF(e),t&&d(e,t,!1,!0,!1)},[e,t,d]),h=(0,s.useCallback)(t=>{t?.type==="graphProgress"&&t.data?.cwd===e&&"done"===t.data.phase&&x()},[e,x]);return(0,eb.h)({url:`/ws/watch?cwd=${encodeURIComponent(e)}`,onMessage:h,onOpen:x,enabled:m}),{state:n,refresh:c,reload:u}}function eA({cwd:e}){let{t}=(0,o.Bd)(),[r,l]=(0,s.useState)(null);(0,s.useEffect)(()=>{l(null)},[e]);let a=(0,s.useCallback)(t=>{t?.type==="graphProgress"&&t.data&&t.data.cwd===e&&l(t.data)},[e]);(0,eb.h)({url:`/ws/watch?cwd=${encodeURIComponent(e)}`,onMessage:a});let i=(0,s.useRef)("");if(r?.currentFile&&(i.current=r.currentFile),!r)return(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:t("blockViewer.fileMode.loading","Loading…")});let d=t(`blockViewer.buildProgress.${r.phase}`,eH[r.phase]),c=Math.max(0,Math.min(100,Math.round(r.percent)));return(0,n.jsx)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 px-8",children:(0,n.jsxs)("div",{className:"w-full max-w-md flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex items-baseline justify-between text-xs text-muted-foreground",children:[(0,n.jsx)("span",{children:d}),(0,n.jsx)("span",{className:"tabular-nums",children:"parsing"===r.phase&&r.filesTotal>0?`${r.filesDone} / ${r.filesTotal}`:`${c}%`})]}),(0,n.jsx)("div",{className:"h-1 w-full overflow-hidden rounded-full bg-muted",children:(0,n.jsx)("div",{className:"h-full rounded-full bg-primary transition-[width] duration-150 ease-linear",style:{width:`${c}%`}})}),(0,n.jsx)("div",{className:"h-4 truncate text-left font-mono text-[11px] leading-4 text-muted-foreground/70",dir:"rtl",title:"done"===r.phase?"":i.current,children:"done"===r.phase?"":i.current})]})})}let eH={listing:"Listing files…",contexts:"Reading project config…",parsing:"Parsing files",resolving:"Resolving imports…",edges:"Building call graph…",done:"Finishing up…"};var eO=r(1058),eW=r(90717),e_=r(3238),ez=r(17196);function eq({entries:e,onSelect:t,onClear:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex-1 min-h-0 bg-card flex flex-col","data-testid":"function-history-drawer",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border flex items-center justify-between gap-1",children:[(0,n.jsx)("div",{className:"flex items-center text-xs text-muted-foreground font-mono min-w-0",children:(0,n.jsx)("span",{className:"truncate",children:0===e.length?s("blockViewer.history.title"):`${s("blockViewer.history.title")} \xb7 ${e.length}/15`})}),e.length>0&&(0,n.jsx)(z.m,{content:s("blockViewer.history.clear"),children:(0,n.jsx)("button",{onClick:r,className:"flex-shrink-0 text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-secondary",children:(0,n.jsx)(ew.A,{className:"w-3 h-3"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===e.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:s("blockViewer.history.empty")}):e.map((e,r)=>{var s;let o;return(0,n.jsx)(z.m,{content:`${e.qname} \xb7 ${e.filePath}`,children:(0,n.jsxs)("button",{onClick:()=>t(e),className:"w-full text-left px-2 py-1.5 border-b border-border/50 hover:transition-colors group flex items-start gap-1.5",children:[(0,n.jsx)(eP,{kind:e.kind??"unknown",qname:e.qname,className:"w-3 h-3 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-mono font-medium truncate",children:e.name}),(0,n.jsxs)("div",{className:"text-[10px] text-muted-foreground/70 truncate",children:[(o=(s=e.filePath).lastIndexOf("/"))>=0?s.slice(o+1):s,e.kind&&(0,n.jsxs)("span",{className:"ml-1 opacity-60",children:["\xb7 ",e.kind]})]})]})]})},`${e.filePath}::${e.qname}::${r}`)})})]})}function eV(e,t){let r=e.filter(e=>e.filePath!==t.filePath||e.qname!==t.qname),n=[t,...r];return n.length>15?n.slice(0,15):n}let eU=new Set(["function","class","method"]);function eK(e){return eU.has(e.kind)}function eQ({functions:e,counts:t,totalLines:r,currentQname:l,onSelect:a,notIndexed:i,onRebuild:d}){let{t:c}=(0,o.Bd)(),u=(0,s.useMemo)(()=>e.filter(eK),[e]);return(0,n.jsxs)("div",{className:"flex-1 min-h-0 bg-card flex flex-col","data-testid":"file-toc-section",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border text-xs text-muted-foreground font-mono truncate",children:[c("blockViewer.toc.title"),u.length>0&&` \xb7 ${u.length}`,null!=r&&` \xb7 ${r} ${c("common.lines")}`]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===u.length?i?(0,n.jsxs)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/80 leading-relaxed flex flex-col gap-2",children:[(0,n.jsx)("span",{className:"italic",children:c("blockViewer.toc.notIndexed")}),d&&(0,n.jsx)("button",{type:"button",onClick:d,className:"self-start px-2 py-1 rounded border border-border bg-secondary/60 hover:bg-secondary text-[10px] text-foreground transition-colors",children:c("blockViewer.refresh")})]}):(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:c("blockViewer.toc.empty")}):u.map(e=>{let r=l===e.qualifiedName,s=t?.get(e.qualifiedName),o=s?[s.in>0&&["in",s.in,"text-amber-11/80"],s.out>0&&["out",s.out,"text-green-11/80"],s.self>0&&["self",s.self,"text-muted-foreground/60"]].filter(Boolean):[];return(0,n.jsx)(z.m,{content:`${e.qualifiedName} \xb7 L${e.declLine}`,children:(0,n.jsxs)("button",{onClick:()=>a(e.qualifiedName,e.startLine),className:`w-full text-left px-2 py-1 transition-colors flex items-start gap-1.5 min-w-0 ${r?"bg-brand/15 hover:bg-brand/20":"hover:bg-secondary/60"}`,children:[(0,n.jsx)(eP,{kind:e.kind,qname:e.qualifiedName,className:"w-3 h-3 flex-shrink-0 mt-0.5"}),(0,n.jsxs)("span",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)("span",{className:`flex-1 min-w-0 text-xs font-mono truncate ${r?"font-semibold text-brand":""}`,children:e.name}),(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground/50 tabular-nums",children:e.endLine-e.startLine+1})]}),o.length>0&&(0,n.jsx)("span",{className:"block text-[10px] font-mono truncate",children:o.map(([e,t,r],s)=>(0,n.jsxs)("span",{className:r,children:[s>0&&(0,n.jsx)("span",{className:"text-muted-foreground/30",children:" \xb7 "}),e," ",t]},e))})]})]})},e.qualifiedName)})})]})}var eG=r(27570),eJ=r(96035);function eY({comments:e,startLine:t,endLine:r,lineHeight:s,bodyTopOffset:o,rowOf:l,onCommentClick:a}){let i=new Map;for(let n of e){if(n.endLine<t||n.endLine>r)continue;let e=i.get(n.endLine);e?e.push(n):i.set(n.endLine,[n])}return 0===i.size?null:(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-6 pointer-events-none",children:Array.from(i.entries()).map(([e,r])=>{let i=l?l(e):e-t,d=r[0],c=r.length-1;return(0,n.jsx)(z.m,{content:1===r.length?d.content:`${r.length} comments — click to view`,children:(0,n.jsxs)("button",{onClick:e=>a(d,e),className:"pointer-events-auto absolute right-1 w-4 h-4 rounded-full bg-amber-9/70 hover:bg-amber-11 text-white flex items-center justify-center shadow-lv1 transition-colors",style:{top:`${o+i*s+s/2-8}px`},children:[(0,n.jsx)(eJ.A,{className:"w-2.5 h-2.5"}),c>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 bg-amber-11 text-white rounded-full text-[8px] leading-none w-3 h-3 flex items-center justify-center",children:c+1})]})},e)})})}function eX(e,t){for(let r=0;r<e.blocks.length;r++){let n=e.blocks[r];if(t>=n.startLine&&t<=n.endLine)return e.prefix[r]+(t-n.startLine)}return null}function eZ({addedLines:e,blockRanges:t,viewportRange:r,onJumpToLine:o}){let l,a=(0,s.useRef)(null),i=(0,s.useMemo)(()=>(function(e){let t=[...e].sort((e,t)=>e.startLine-t.startLine),r=[0];for(let e of t){let t=Math.max(0,e.endLine-e.startLine+1);r.push(r[r.length-1]+t)}return{blocks:t,prefix:r,total:r[r.length-1]}})(t),[t]),d=(0,s.useMemo)(()=>{if(i.total<=0||0===e.size)return[];let t=[];for(let r of e){let e=i.blocks.find(e=>r>=e.startLine&&r<=e.endLine);e&&t.push({line:r,qname:e.qname})}t.sort((e,t)=>e.line-t.line);let r=[],n=null;for(let e of t)n&&e.line===n.end+1&&e.qname===n.qname?n.end=e.line:(n&&r.push(n),n={start:e.line,end:e.line,qname:e.qname});return n&&r.push(n),r},[e,i]);if(i.total<=0)return null;let c=(e,t)=>{let r=eX(i,e),n=eX(i,t);return null===r||null===n?null:{top:r/i.total*100,heightPct:(n-r+1)/i.total*100}};return(0,n.jsxs)("div",{ref:a,onClick:e=>{let t=a.current;if(!t)return;let r=t.getBoundingClientRect();if(r.height<=0)return;let n=function(e,t){if(e.total<=0)return null;let r=Math.max(0,Math.min(e.total-1,t));for(let t=0;t<e.blocks.length;t++){let n=e.prefix[t],s=e.prefix[t+1];if(r>=n&&r<s){let s=e.blocks[t];return{qname:s.qname,line:s.startLine+Math.round(r-n)}}}return null}(i,(e.clientY-r.top)/r.height*i.total);if(!n)return;let s=n.line,l=d.find(e=>e.qname===n.qname&&s>=e.start&&s<=e.end);if(l)return void o(l.qname,s);if(d.length>0){let e=Math.max(2,Math.round(.05*i.total)),t=eX(i,s);if(null!==t){let r=null,n=1/0;for(let e of d){let s=eX(i,e.start),o=eX(i,e.end);if(null===s||null===o)continue;let l=t<s?s-t:t>o?t-o:0;l<n&&(r=e,n=l)}if(r&&n<=e){let e=s<r.start?r.start:s>r.end?r.end:s;o(r.qname,e);return}}}let c=i.blocks.find(e=>e.qname===n.qname);c&&o(c.qname,c.startLine)},className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",title:"Diff minimap — click to jump",children:[d.map(e=>{let t=c(e.start,e.end);return t?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-green-9 pointer-events-none",style:{top:`${t.top}%`,height:`${t.heightPct}%`,minHeight:"2px"}},`run:${e.qname}:${e.start}-${e.end}`):null}),r&&r.end>=r.start&&((l=c(r.start,r.end))?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border pointer-events-none",style:{top:`${l.top}%`,height:`${Math.max(1.2,l.heightPct)}%`}}):null)]})}var e0=r(19502),e1=r(89109),e2=r(7320),e5=r(37614);let e4={state:"loading"};function e3(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function e6(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}let e8="flex-shrink-0 h-4 leading-4 px-1.5 rounded text-[10px] text-brand hover:bg-brand/10 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent";function e9({symbol:e,fileSource:t,hasChange:r,onHighlighted:l,comments:a,onCommentClick:i,addedLines:d,upstream:c,downstream:u,fold:m,onExpandGap:x}){let{resolvedTheme:h}=(0,e_.DP)(),{t:f}=(0,o.Bd)(),p=(0,J.r)(),g=(c?.length??0)+(u?.length??0)>0,b=(0,s.useMemo)(()=>(0,ez.sQ)(e.filePath),[e.filePath]),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!t)return void j(null);let r=!1;return(async()=>{try{let n=t.split("\n").slice(e.startLine-1,e.endLine).join("\n"),s=(await (0,ez.kS)()).codeToTokens(n,{lang:b,theme:"dark"===h?"github-dark":"github-light"});r||(j(s.tokens.map(e=>(0,ez.b8)(e))),k(null))}catch(e){r||k(e instanceof Error?e.message:"highlight failed")}})(),()=>{r=!0}},[t,e.startLine,e.endLine,b,h]);let y=(0,s.useMemo)(()=>{if(!v)return null;let t=t=>{let r=v[t-e.startLine]??"",n=d?.has(t)?" bg-green-9/15":"";return`<div class="flex${n}" style="min-width:max-content" data-line="${t}"><span class="select-none pr-3 text-muted-foreground/60 tabular-nums" style="min-width:3.2rem;text-align:right">${t}</span><span class="whitespace-pre">${r}</span></div>`};return m?m.segments.map(e=>{if("gap"===e.kind){var r;let t,n,s;return r=e.startLine,n=e6(f("diffViewer.gap.hidden",{count:t=e.endLine-r+1})),s=e6(f("diffViewer.gap.expandAll",{count:t})),`<div class="flex items-center cursor-pointer select-none hover:bg-hover" style="min-width:max-content;height:${tt}px" data-fold-gap="${r}" title="${s}"><span class="select-none pr-3 text-muted-foreground/40" style="min-width:3.2rem;text-align:right">⋯</span><span class="text-[10px] text-muted-foreground/60 whitespace-pre">${n}</span></div>`}let n="";for(let r=e.startLine;r<=e.endLine;r++)n+=t(r);return n}).join(""):v.map((r,n)=>t(e.startLine+n)).join("")},[v,m,d,e.startLine,f]);(0,s.useEffect)(()=>{(null!==v||null!==w)&&l(e.qualifiedName)},[v,w,e.qualifiedName,l]);let N=(0,s.useCallback)(t=>{if(!x)return;let r=t.target,n=r?.closest?.("[data-fold-gap]");if(!n)return;let s=Number(n.getAttribute("data-fold-gap"));Number.isFinite(s)&&x(e.qualifiedName,s)},[x,e.qualifiedName]);return(0,n.jsxs)("div",{className:"flex-1 min-w-0 bg-card border border-border rounded overflow-hidden relative",children:[(0,n.jsxs)("div",{"data-block-header":!0,className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border text-xs",children:[(0,n.jsx)(eP,{kind:e.kind,qname:e.qualifiedName,className:"w-3.5 h-3.5 flex-shrink-0"}),!e.qualifiedName.startsWith("__code_")&&(0,n.jsxs)("span",{className:"font-mono truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:e.name}),void 0!==e.params&&(0,n.jsxs)("span",{className:"text-muted-foreground/80",children:["(",e.params.join(", "),")"]})]}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground/70 flex-shrink-0",children:["unknown"!==e.kind&&`${e.kind} \xb7 `,e.endLine-e.startLine+1," ",f("common.lines")]}),p&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>p.sendMessage(f("explain.symbolMessage",{name:e.name,path:e.filePath,lines:`${e.startLine}-${e.endLine}`})),disabled:p.isLoading,title:p.isLoading?f("comments.aiResponding"):void 0,className:e8,children:f("explain.action")}),g&&(0,n.jsx)("button",{onClick:()=>p.sendMessage(f("deps.symbolMessage",{name:e.name,path:e.filePath,lines:`${e.startLine}-${e.endLine}`,...function(e,t,r){let n=e=>{switch(e.kind){case"cross":case"self":return`${e.external.name} (${e.external.filePath})`;case"method":return`${e.receiverName}.${e.methodName}()`;case"ext":return null}},s=e=>{let t=e.map(n).filter(e=>null!==e);return t.length?t.join(", "):r},o=new Map;for(let e of t){if("ext"!==e.kind)continue;let t=o.get(e.packageSpec);t?t.push(e.name):o.set(e.packageSpec,[e.name])}let l=[...o].map(([e,t])=>`${e} (${t.join(", ")})`);return{callers:s(e),callees:s(t),externals:l.length?l.join("; "):r}}(c??[],u??[],f("deps.none"))})),disabled:p.isLoading,title:p.isLoading?f("comments.aiResponding"):void 0,className:e8,children:f("deps.action")})]}),(0,n.jsx)("span",{className:"flex-1"}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 w-2 h-2 rounded-full bg-amber-11","data-tooltip":"File has uncommitted change"})]}),(0,n.jsxs)("div",{"data-block-body":!0,className:"text-[11px] font-mono px-2 py-2 overflow-auto",style:{lineHeight:`${tt}px`},onClick:N,children:[!t&&(0,n.jsx)("span",{className:"text-muted-foreground",children:"Loading…"}),w&&(0,n.jsx)("span",{className:"text-red-11",children:w}),y&&(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:y}})]}),a&&a.length>0&&i&&(0,n.jsx)(eY,{comments:a,startLine:e.startLine,endLine:e.endLine,lineHeight:tt,bodyTopOffset:tr+tn,rowOf:m?.rowOf,onCommentClick:i})]})}function e7({side:e,pin:t,accent:r,onClick:s}){let o,l,a,i,d,c,u,m=t.lines.length;"ext"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",l="ext",a="text-muted-foreground/60",i=t.name,d=t.packageSpec,c="external",u=t.packageSpec):"method"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",l="method",a="text-muted-foreground/60",i=`${t.receiverName}.${t.methodName}`,d=null,c="method (unresolved)",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):"self"===t.kind?(o="bg-secondary/40 border-border hover:border-muted-foreground",l="self",a="text-muted-foreground/70",i=t.external.name,d=null,c="same-file",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):(o="in"===e?"bg-amber-9/15 border-amber-9/40 hover:border-amber-11":"bg-green-9/15 border-green-9/40 hover:border-green-11",l=e,a="in"===e?"text-amber-11":"text-green-11",i=t.external.name,d=e3(t.external.filePath),c="in"===e?"caller":"callee",u=t.external.filePath);let x=r&&"ext"!==t.kind&&"method"!==t.kind?" ring-1 ring-amber-9/70 ring-offset-0":"";return(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),s()},className:`${o}${x} w-full text-left border rounded px-1.5 py-0.5 text-[10px] font-mono cursor-pointer transition-colors block`,"data-tooltip":`${c} \xb7 ${i}${u?" \xb7 "+u:""}`,children:(0,n.jsxs)("span",{className:"block h-[26px] leading-[13px] overflow-hidden",children:[(0,n.jsx)("span",{className:`${a} float-left mr-1.5 text-[9px] uppercase tracking-wider font-semibold`,children:l}),(d||m>1)&&(0,n.jsxs)("span",{className:"float-right clear-both ml-1.5 max-w-[60%] truncate text-muted-foreground/70",children:[d,m>1&&(0,n.jsxs)("span",{className:"text-muted-foreground/60",children:[d?" ":"","\xb7",m,"\xd7"]})]}),(0,n.jsx)("span",{className:"font-medium break-all",children:i})]})})}let te="w-44 @min-[900px]:w-52 @min-[1100px]:w-60 @min-[1400px]:w-72 @min-[1800px]:w-80 @min-[2400px]:w-96",tt=18,tr=29,tn=8;function ts(e,t){switch(t.kind){case"cross":return`${e}:x:${t.external.filePath}::${t.external.qualifiedName}`;case"self":return`${e}:s:${t.external.filePath}::${t.external.qualifiedName}`;case"ext":return`${e}:e:${t.packageSpec}::${t.name}`;case"method":return`${e}:m:${t.receiverName}::${t.methodName}`}}function to(e,t){return"ext"!==e.kind&&"method"!==e.kind&&(t?.has(e.external.qualifiedName)??!1)}function tl(e){return{filePath:e.filePath,qname:e.qualifiedName,name:e.name,kind:e.kind}}function ta({symbol:e,fileSource:t,hasChange:r,upstream:s,downstream:o,onPinClick:l,onHighlighted:a,comments:i,onCommentClick:d,accentQnames:c,addedLines:u,fold:m,onExpandGap:x}){let h=function(e,t,r){if(0===e.length)return[];let n=e.map((e,r)=>{var n,s;return{i:r,line:(n=e.lines[0]??t.startLine,s=t.startLine,Math.max(s,Math.min(t.endLine,n)))}});n.sort((e,t)=>e.line-t.line||e.i-t.i);let s=Array(e.length).fill(0),o=-1/0;for(let{i:e,line:l}of n){let n=Math.max(tr+tn+(r?r.rowOf(l):l-t.startLine)*tt,o);s[e]=n,o=n+34}return s}(o,e,m);return(0,n.jsxs)("div",{"data-block-qname":e.qualifiedName,"data-start-line":e.startLine,"data-end-line":e.endLine,className:"flex gap-2 items-stretch scroll-mt-2",children:[(0,n.jsx)("div",{className:`${te} flex-shrink-0 flex flex-col gap-1 pt-1`,children:0===s.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5",children:"no callers"}):s.map(t=>(0,n.jsx)(e7,{side:"in",pin:t,accent:to(t,c),onClick:()=>l(t,e)},ts("in",t)))}),(0,n.jsx)(e9,{symbol:e,fileSource:t,hasChange:r,onHighlighted:a,comments:i,onCommentClick:d,addedLines:u,upstream:s,downstream:o,fold:m,onExpandGap:x}),(0,n.jsx)("div",{className:`${te} flex-shrink-0 relative`,children:0===o.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5 pt-1",children:"no callees"}):o.map((t,r)=>(0,n.jsx)("div",{className:"absolute left-0 right-0",style:{top:`${h[r]}px`},children:(0,n.jsx)(e7,{side:"out",pin:t,accent:to(t,c),onClick:()=>l(t,e)})},ts("out",t)))})]})}function ti({cwd:e,onSelect:t,onClose:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(""),[d,c]=(0,s.useState)({files:[],symbols:[]}),[u,m]=(0,s.useState)(0),[x,h]=(0,s.useState)(!1),f=(0,s.useMemo)(()=>[...d.files,...d.symbols],[d]);(0,s.useEffect)(()=>{let t=a.trim();if(!t)return void c({files:[],symbols:[]});h(!0);let r=setTimeout(async()=>{let r=new URLSearchParams({cwd:e,q:t,limit:"12"}),n=await P.t4.runPromiseExit((0,R.MB)(r));"Success"===n._tag&&(c(n.value),m(0)),h(!1)},120);return()=>clearTimeout(r)},[a,e]);let p=(0,s.useCallback)(e=>{if("Escape"===e.key)return void r();if(0!==f.length){if("ArrowDown"===e.key)e.preventDefault(),m(e=>Math.min(e+1,f.length-1));else if("ArrowUp"===e.key)e.preventDefault(),m(e=>Math.max(e-1,0));else if("Enter"===e.key){e.preventDefault();let r=f[u];r&&t(r)}}},[f,u,r,t]);return(0,n.jsx)("div",{className:"absolute inset-0 bg-background/40 z-20 flex items-start justify-center pt-24",onClick:r,children:(0,n.jsxs)("div",{className:"w-[480px] max-w-[80%] bg-card border border-border rounded shadow-lv3 overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[(0,n.jsx)(ej.A,{className:"w-4 h-4 text-muted-foreground"}),(0,n.jsx)("input",{autoFocus:!0,value:a,onChange:e=>i(e.target.value),onKeyDown:p,placeholder:l("blockViewer.search.hint","Start typing to search"),className:"flex-1 bg-transparent border-0 outline-none text-sm"}),x&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"…"}),(0,n.jsx)("button",{onClick:r,className:"text-muted-foreground hover:text-foreground",children:(0,n.jsx)(ew.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[0===f.length&&a&&!x&&(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:l("blockViewer.search.noResults","No matches")}),(0,n.jsx)(td,{label:l("blockViewer.search.files","Files"),hits:d.files,startIdx:0,activeIdx:u,onSelect:t,setActive:m}),(0,n.jsx)(td,{label:l("blockViewer.search.symbols","Symbols"),hits:d.symbols,startIdx:d.files.length,activeIdx:u,onSelect:t,setActive:m})]})]})})}function td({label:e,hits:t,startIdx:r,activeIdx:s,onSelect:o,setActive:l}){return 0===t.length?null:(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-secondary/40",children:e}),t.map((e,t)=>{let a=r+t,i=a===s;return(0,n.jsxs)("button",{onMouseEnter:()=>l(a),onClick:()=>o(e),className:`w-full text-left px-3 py-1.5 text-xs flex items-start gap-2 ${i?"bg-secondary":"hover:bg-secondary/60"}`,children:["file"===e.type?(0,n.jsx)(ek.A,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 text-muted-foreground"}):(0,n.jsx)(eP,{kind:e.target.kind,qname:e.target.qualifiedName,className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),e.hint&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground truncate",children:e.hint})]})]},`${e.type}:${e.label}:${t}`)})]})}function tc({cwd:e,highlightedFilePath:t,changedFiles:r,onSwitchToCode:l,enableComments:a=!1,onContentSearch:i,onFocalChange:d,qnameFilter:c,qnameFilterFile:u,accentQnames:m,accentFile:x,addedLines:h,addedLinesFile:f,compact:p=!1,headerExtraLeft:g,headerExtraRight:b}){let{t:v}=(0,o.Bd)(),[j,w]=(0,s.useState)("toc"),[k,y]=(0,s.useState)(null),N=k??t??null;(0,s.useEffect)(()=>{y(null)},[t]),(0,s.useEffect)(()=>{d?.(N)},[N,d]);let{state:C,refresh:S,reload:M}=eD(e,N,!0),L="ready"===C.state&&C.data.crossFilePending?e4:C,[E,$]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!N)return void $(null);let t=!1;return $(null),(async()=>{let r=new URLSearchParams({cwd:e,path:N}),n=await P.t4.runPromiseExit((0,T.eA)(r));t||("Success"===n._tag?$({content:n.value.content,mtimeMs:n.value.mtimeMs}):console.error("[BlockViewer] failed to load file source for",N,n.cause))})(),()=>{t=!0}},[e,N]);let R=(0,s.useMemo)(()=>E?E.content.split("\n").length:null,[E]),I=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!E||"ready"!==L.state)return;let e=L.data.mtimeMs;!e||E.mtimeMs<=e||I.current!==E.mtimeMs&&(I.current=E.mtimeMs,M())},[E,L,M]);let[F,B]=(0,s.useState)([]),[D,A]=(0,s.useState)(!1),[H,O]=(0,s.useState)(null),W=(0,s.useRef)(0),_=(0,s.useRef)(0),[z,q]=(0,s.useState)(()=>new Set),V="ready"===L.state?L.data.filePath:null;(0,s.useEffect)(()=>{q(new Set)},[V]);let U=(0,s.useCallback)(e=>{q(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),A(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let K=(0,s.useCallback)((e,t)=>{if("ext"===e.kind||"method"===e.kind){let e=t.filePath;if(!e)return;W.current+=1,O({filePath:e,qname:"__imports__",nonce:W.current});return}let r=tl(t),n=tl(e.external);B(e=>eV(eV(e,r),n)),y(n.filePath),W.current+=1,O({filePath:n.filePath,qname:n.qname,nonce:W.current})},[]),Q=(0,s.useCallback)(e=>{y(e.filePath),W.current+=1,O({filePath:e.filePath,qname:e.qname,nonce:W.current})},[]),G=(0,s.useCallback)(e=>{A(!1),y(e.target.filePath),"symbol"===e.type&&(W.current+=1,O({filePath:e.target.filePath,qname:e.target.qualifiedName,line:e.target.startLine,nonce:W.current}))},[]),Y=(0,s.useCallback)((e,t)=>{N&&(W.current+=1,O({filePath:N,qname:e,line:t,nonce:W.current}))},[N]),[X,Z]=(0,s.useState)(()=>new Set),ee=(0,s.useCallback)((e,t)=>{Z(r=>{let n=new Set(r);return n.add(`${N}#${e}#${t}`),n})},[N]),[et,er]=(0,s.useState)(null),[en,es]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!et)return;let e=null,t=()=>{e=null;let t=et.getBoundingClientRect();if(t.height<=0)return;let r=et.querySelectorAll("[data-block-qname]"),n=1/0,s=-1/0;r.forEach(e=>{let r=e.dataset.startLine,o=e.dataset.endLine;if(!r||!o)return;let l=Number(r),a=Number(o);if(!Number.isFinite(l)||!Number.isFinite(a))return;let i=e.getBoundingClientRect();if(i.height<=0||i.bottom<=t.top||i.top>=t.bottom)return;let d=Math.max(0,t.top-i.top),c=Math.min(i.height,t.bottom-i.top),u=a-l+1,m=Math.floor(d/i.height*u),x=Math.ceil(c/i.height*u)-1,h=l+Math.max(0,m),f=l+Math.min(u-1,Math.max(0,x));h<n&&(n=h),f>s&&(s=f)}),n===1/0||s===-1/0?es(null):es(e=>e&&e.start===n&&e.end===s?e:{start:n,end:s})},r=()=>{null===e&&(e=requestAnimationFrame(t))};r(),et.addEventListener("scroll",r,{passive:!0});let n=new ResizeObserver(r);n.observe(et);let s=new MutationObserver(r);return s.observe(et,{childList:!0,subtree:!0}),()=>{et.removeEventListener("scroll",r),n.disconnect(),s.disconnect(),null!==e&&cancelAnimationFrame(e)}},[et]);let eo=(0,s.useMemo)(()=>{if("ready"!==L.state||!en)return null;let e=L.data.functions;if(0===e.length)return null;let t=(en.start+en.end)/2;for(let r of e)if(r.startLine<=t&&t<=r.endLine)return r.qualifiedName;let r=null;for(let t of e)t.startLine<=en.start&&(!r||t.startLine>r.startLine)&&(r=t);return r?.qualifiedName??null},[L,en]),el=a&&!!e&&!!N,ea=(0,J.r)(),{comments:ei,addComment:ed,updateComment:ec,deleteComment:eu,refresh:em}=(0,eO._)({cwd:e,filePath:N??""}),[ex,eh]=(0,s.useState)(null),{toolbarRef:ef,bumpRef:ep,clearToolbar:eg}=(0,eG.L)({enabled:el,container:ex,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,r=t?.closest("[data-line]");if(!r||!ex||!ex.contains(r))return null;let n=r.getAttribute("data-line");if(!n)return null;let s=parseInt(n,10);return Number.isFinite(s)?{start:s,end:s}:null},buildLineSnapshot:({start:e,end:t})=>{let r=E?.content;return r?r.split("\n").slice(e-1,t).join("\n"):""}}),[eb,ev]=(0,s.useState)(null),[ej,ew]=(0,s.useState)(null),[ek,ey]=(0,s.useState)(null),eN=(0,s.useCallback)(()=>{let e=ef.current;e&&(ev({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),eg())},[eg,ef]),eC=(0,s.useCallback)(()=>{let e=ef.current;e&&(ew({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),eg())},[eg,ef]),eS=(0,s.useCallback)(()=>{let e=ef.current;e&&ea&&N&&(eg(),(0,eW.Ff)(ea.sendMessage,{filePath:N,startLine:e.range.start,endLine:e.range.end,codeContent:e.lineSnapshot},v("explain.selectionMessage")))},[ea,N,eg,ef,v]),eM=(0,s.useCallback)(()=>{let e=ef.current;if(!e||!i)return;let t=e.selectedText.trim();eg(),t&&i(t)},[i,eg,ef]),eL=(0,s.useCallback)(async e=>{eb&&(await ed(eb.range.start,eb.range.end,e,eb.selectedText),ev(null))},[eb,ed]),eE=(0,s.useCallback)(async(t,r)=>{if(ea&&e&&N)try{let n=(await (0,eW.$3)(e)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));n.push({filePath:N,startLine:t.range.start,endLine:t.range.end,codeContent:t.lineSnapshot});let s=(0,eW.Gw)(n,r);ea.sendMessage(s),await (0,eW.RP)(e),em()}catch(e){console.error("[BlockViewer] send to AI failed:",e)}},[ea,e,N,em]),eP=(0,s.useCallback)(e=>{ej&&eE(ej,e)},[ej,eE]),eT=(0,s.useCallback)(e=>{eb&&eE(eb,e)},[eb,eE]),e$=(0,s.useCallback)((e,t)=>{t.stopPropagation(),ey({comment:e,x:t.clientX,y:t.clientY}),eg(),ev(null),ew(null)},[eg]);if((0,s.useEffect)(()=>{if(!H||_.current>=H.nonce||"ready"!==L.state||!E||L.data.filePath!==H.filePath)return;let e=Math.max(1,new Set((u===L.data.filePath&&c?L.data.functions.filter(e=>c.has(e.qualifiedName)):L.data.functions).map(e=>e.qualifiedName)).size);if(z.size<e)return;_.current=H.nonce;let t=null,r=requestAnimationFrame(()=>{let e=H.qname.indexOf(">"),r=e>=0?H.qname.slice(0,e):H.qname,n=document.querySelector(`[data-block-qname="${CSS.escape(r)}"]`);if(!n)return;if("number"==typeof H.line){let e=n.querySelector(`[data-line="${H.line}"]`);if(e instanceof HTMLElement){e.scrollIntoView({behavior:"instant",block:"center"}),e.classList.remove("line-flash"),e.offsetWidth,e.classList.add("line-flash"),t=window.setTimeout(()=>{e.classList.remove("line-flash")},1700);return}}n.scrollIntoView({behavior:"instant",block:"start"});let s=n.querySelector("[data-block-header]");s instanceof HTMLElement&&(s.classList.remove("block-flash"),s.offsetWidth,s.classList.add("block-flash"),t=window.setTimeout(()=>{s.classList.remove("block-flash")},1700))});return()=>{cancelAnimationFrame(r),null!==t&&window.clearTimeout(t)}},[H,L,E,z,c,u]),!N)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(tm,{focalFile:null,fileCount:null,onSwitchToCode:l,onSearch:()=>A(!0),onRefresh:S,refreshDisabled:!0,extraLeft:g,extraRight:b}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-sm text-muted-foreground gap-2 px-4 text-center",children:[(0,n.jsx)("span",{children:v("blockViewer.empty.body","Select a file in the left tree to see its function call graph.")}),(0,n.jsx)("span",{className:"text-xs",children:v("blockViewer.empty.hint","or press ⌘K to search.")})]}),D&&(0,n.jsx)(ti,{cwd:e,onSelect:G,onClose:()=>A(!1)})]});if("idle"===L.state||"loading"===L.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(tm,{focalFile:N,fileCount:null,onSwitchToCode:l,onSearch:()=>A(!0),onRefresh:S,refreshDisabled:!0,extraLeft:g,extraRight:b}),(0,n.jsx)(eA,{cwd:e})]});if("notFound"===L.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(tm,{focalFile:N,fileCount:null,onSwitchToCode:l,onSearch:()=>A(!0),onRefresh:S,extraLeft:g,extraRight:b}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-4 text-center",children:v("blockViewer.fileMode.notFound","This file is not indexed (unsupported language or beyond the file cap).")}),D&&(0,n.jsx)(ti,{cwd:e,onSelect:G,onClose:()=>A(!1)})]});if("error"===L.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(tm,{focalFile:N,fileCount:null,onSwitchToCode:l,onSearch:()=>A(!0),onRefresh:S,extraLeft:g,extraRight:b}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-sm",children:[(0,n.jsx)("span",{className:"text-red-11",children:L.message}),(0,n.jsx)("button",{onClick:S,className:"px-3 py-1 rounded bg-secondary hover:bg-secondary/80",children:v("blockViewer.retry","Retry")})]})]});let eR=L.data,eI=eR.functions;if(0===eI.length&&E){let e=Math.max(1,R??1);eI=[{filePath:eR.filePath,qualifiedName:"__file__",name:e3(eR.filePath),kind:"unknown",startLine:1,endLine:e,declLine:1}]}let eF=u&&u===eR.filePath,eB=x&&x===eR.filePath,eH=f&&f===eR.filePath;eF&&c&&(eI=eI.filter(e=>c.has(e.qualifiedName)));let e_=eB?m:void 0,ez=eH?h:void 0,eU=new Map;if(p&&ez)for(let e of eI)eU.set(e.qualifiedName,function(e,t,r,n,s=e0.aj){if(t<e)return null;let o=[];for(let n of r)n>=e&&n<=t&&o.push(n);o.sort((e,t)=>e-t);let l=[];for(let r of o){let n=Math.max(e,r-s),o=Math.min(t,r+s),a=l[l.length-1];a&&n<=a.endLine+1?o>a.endLine&&(a.endLine=o):l.push({startLine:n,endLine:o})}let a=[],i=e;for(let e of l)e.startLine>i&&a.push({startLine:i,endLine:e.startLine-1}),i=e.endLine+1;i<=t&&a.push({startLine:i,endLine:t});let d=[],c=[];for(let e of a)e.endLine-e.startLine+1<2||n(e.startLine)?c.push(e):d.push(e);if(0===d.length)return null;l=function(e){let t=[...e].sort((e,t)=>e.startLine-t.startLine),r=[];for(let e of t){let t=r[r.length-1];t&&e.startLine<=t.endLine+1?e.endLine>t.endLine&&(t.endLine=e.endLine):r.push({...e})}return r}([...l,...c]);let u=[];for(let e of[...l.map(e=>({kind:"lines",...e})),...d.map(e=>({kind:"gap",...e}))].sort((e,t)=>e.startLine-t.startLine))u.push(e);let m=[],x=0;for(let e of u)m.push(x),x+="gap"===e.kind?1:e.endLine-e.startLine+1;let h=x;return{segments:u,visibleRuns:l,hiddenCount:d.reduce((e,t)=>e+(t.endLine-t.startLine+1),0),rowOf:t=>{for(let e=0;e<u.length;e++){let r=u[e];if(t<r.startLine)break;if(t<=r.endLine)return"gap"===r.kind?m[e]:m[e]+(t-r.startLine)}return t<e?0:Math.max(0,h-1)}}}(e.startLine,e.endLine,ez,t=>X.has(`${eR.filePath}#${e.qualifiedName}#${t}`)));let eK=tu(eR.upstreamCalls),eJ=tu(eR.downstreamCalls),eY=new Map(eI.map(e=>[e.qualifiedName,e])),eX=new Map,e6=new Map;for(let e of eR.intraCalls){let t=eY.get(e.to),r=eY.get(e.from);if(t){let r=eX.get(e.from),n={kind:"self",external:t,lines:e.lines};r?r.push(n):eX.set(e.from,[n])}if(r){let t=e6.get(e.to),n={kind:"self",external:r,lines:e.lines};t?t.push(n):e6.set(e.to,[n])}}let e8=new Map;for(let e of eR.externalCalls??[]){let t=e8.get(e.focalQname),r={kind:"ext",name:e.external.name,packageSpec:e.external.packageSpec,lines:e.lines};t?t.push(r):e8.set(e.focalQname,[r])}let e9=new Map;for(let e of eR.methodCalls??[]){let t=e9.get(e.focalQname),r={kind:"method",receiverName:e.receiverName,methodName:e.methodName,lines:e.lines};t?t.push(r):e9.set(e.focalQname,[r])}let e7=new Map;for(let e of eI){let t=e.qualifiedName,r={in:eK.get(t)?.length??0,out:eJ.get(t)?.length??0,self:(e6.get(t)?.length??0)+(eX.get(t)?.length??0)};(r.in||r.out||r.self)&&e7.set(t,r)}let tt=r.has(eR.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,n.jsx)(tm,{focalFile:N,fileCount:eR.fileCount,functionCount:eR.functions.length,upstreamCount:eR.upstreamCalls.length,downstreamCount:eR.downstreamCalls.length,onSwitchToCode:l,onSearch:()=>A(!0),onRefresh:S,extraLeft:g,extraRight:b}),(0,n.jsxs)("div",{ref:eh,className:"@container flex-1 relative min-h-0 flex",children:[(eR.crossFileStale||eR.indexUpdateError)&&(0,n.jsx)("div",{className:"absolute top-0 right-0 z-10 px-2 py-1 text-xs bg-background text-muted-foreground border border-border rounded",children:eR.indexUpdateError??v("blockViewer.relationsStale","Project relations need a refresh")}),(0,n.jsxs)("div",{className:`${te} flex-shrink-0 border-r border-border flex flex-col`,children:[(0,n.jsx)("div",{className:"flex-shrink-0 flex border-b border-border",children:[["toc",v("blockViewer.tabs.toc")],["history",v("blockViewer.tabs.history")]].map(([e,t])=>(0,n.jsx)("button",{onClick:()=>w(e),className:`flex-1 px-2 py-1.5 text-xs font-medium transition-colors ${j===e?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground"}`,children:t},e))}),(0,n.jsx)("div",{className:"toc"===j?"flex-1 min-h-0 flex flex-col":"hidden",children:(0,n.jsx)(eQ,{functions:eI,counts:e7,totalLines:R,currentQname:eo,onSelect:Y,notIndexed:eR.notIndexed,onRebuild:S})}),(0,n.jsx)("div",{className:"history"===j?"flex-1 min-h-0 flex flex-col":"hidden",children:(0,n.jsx)(eq,{entries:F,onSelect:Q,onClear:()=>B([])})})]}),(0,n.jsx)("div",{ref:er,className:"@container flex-1 min-w-0 overflow-auto",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 p-3",children:eI.map(e=>{let t,r,s,o,l,a;return(0,n.jsx)(ta,{symbol:e,fileSource:E?.content??null,hasChange:tt,upstream:(t=eK.get(e.qualifiedName),r=e6.get(e.qualifiedName),[...(t??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...r??[]]),downstream:(s=eJ.get(e.qualifiedName),o=eX.get(e.qualifiedName),l=e9.get(e.qualifiedName),a=e8.get(e.qualifiedName),[...(s??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...o??[],...l??[],...a??[]]),onPinClick:K,onHighlighted:U,comments:el?ei:void 0,onCommentClick:el?e$:void 0,accentQnames:e_,addedLines:ez,fold:eU.get(e.qualifiedName),onExpandGap:ee},`${e.qualifiedName}#${e.startLine}`)})})}),el&&ex&&(0,n.jsx)(e1.fS,{floatingToolbarRef:ef,bumpRef:ep,container:ex,onAddComment:eN,onSendToAI:eC,onSearch:i?eM:void 0,onExplain:ea&&N?eS:void 0,isChatLoading:ea?.isLoading}),el&&eb&&(0,n.jsx)(e2.t,{x:eb.x,y:eb.y,range:eb.range,filePath:N??void 0,lineSnapshot:eb.lineSnapshot,container:ex,onSubmit:eL,onSendToAI:ea&&N?eT:void 0,onClose:()=>ev(null),isChatLoading:ea?.isLoading}),el&&ej&&N&&(0,n.jsx)(e2.G,{x:ej.x,y:ej.y,range:ej.range,filePath:N,lineSnapshot:ej.lineSnapshot,container:ex,onSubmit:eP,onClose:()=>ew(null),isChatLoading:ea?.isLoading}),el&&ek&&(0,n.jsx)(e5.t,{x:ek.x,y:ek.y,comment:ek.comment,container:ex,onClose:()=>ey(null),onUpdateComment:ec,onDeleteComment:eu}),ez&&ez.size>0&&eI.length>0&&(0,n.jsx)(eZ,{addedLines:ez,blockRanges:eI.flatMap(e=>{let t=eU.get(e.qualifiedName);return t?t.visibleRuns.map(t=>({qname:e.qualifiedName,startLine:t.startLine,endLine:t.endLine})):[{qname:e.qualifiedName,startLine:e.startLine,endLine:e.endLine}]}),viewportRange:en,onJumpToLine:Y}),D&&(0,n.jsx)(ti,{cwd:e,onSelect:G,onClose:()=>A(!1)})]})]})}function tu(e){let t=new Map;for(let r of e){let e=t.get(r.focalQname);if(!e){t.set(r.focalQname,[r]);continue}e.some(e=>e.external.filePath===r.external.filePath&&e.external.qualifiedName===r.external.qualifiedName)||e.push(r)}return t}function tm({focalFile:e,fileCount:t,functionCount:r,upstreamCount:s,downstreamCount:l,onSwitchToCode:a,onSearch:i,onRefresh:d,refreshDisabled:c,extraLeft:u,extraRight:m}){let{t:x}=(0,o.Bd)(),h={focalFile:e,blockCount:r??0,upstreamCount:s??0,downstreamCount:l??0};return(0,n.jsxs)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border flex items-center justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 text-xs text-muted-foreground font-mono",children:[(0,n.jsx)("span",{className:"truncate min-w-0",children:e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-foreground",children:e}),"number"==typeof r&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",r," blocks"]}),"number"==typeof s&&"number"==typeof l&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",s," in \xb7 ",l," out"]})]}):(0,n.jsx)("span",{children:null!==t?`${t} files`:"…"})}),u&&(0,n.jsx)("span",{className:"flex items-center gap-1 flex-shrink-0",children:u(h)})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[m&&(0,n.jsx)("span",{className:"flex items-center gap-1",children:m(h)}),(0,n.jsxs)("button",{onClick:i,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground flex items-center gap-1","data-tooltip":x("blockViewer.search.tooltip","Search (⌘K)"),children:[(0,n.jsx)(ej.A,{className:"w-3 h-3"})," ⌘K"]}),(0,n.jsx)("button",{onClick:d,disabled:c,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground disabled:opacity-50 disabled:hover:bg-transparent","data-tooltip":x("blockViewer.refresh","Rebuild project graph"),children:(0,n.jsx)(ey.A,{className:"w-3 h-3"})}),a&&(0,n.jsx)("button",{onClick:a,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground",children:x("common.code","Code")})]})]})}var tx=r(22576);function th(e){let t=0xdeadbeef,r=0x41c6ce57;for(let n=0;n<e.length;n++){let s=e.charCodeAt(n);t=Math.imul(t^s,0x9e3779b1),r=Math.imul(r^s,0x5f356495)}return t=Math.imul(t^t>>>16,0x85ebca6b)^Math.imul(r^r>>>13,0xc2b2ae35),(0x100000000*(2097151&(r=Math.imul(r^r>>>16,0x85ebca6b)^Math.imul(t^t>>>13,0xc2b2ae35)))+(t>>>0)>>>0).toString(16)}function tf(e){return e.replace(/\s+/g," ").trim()}function tp(e,t){return e?`${e}>${t}`:t}function tg(e){let t=e.childForFieldName("name");if(t)return t.text;for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);if(r&&("identifier"===r.type||"type_identifier"===r.type||"property_identifier"===r.type))return r.text}return"<anonymous>"}function tb(e,t,r,n,s=[],o){return{qualifiedName:tp(n,t),name:t,kind:r,startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,declLine:function(e){for(let t=0;t<e.childCount;t++){let r=e.child(t);if(r&&"decorator"!==r.type&&"comment"!==r.type)return r.startPosition.row}return e.startPosition.row}(e)+1,contentHash:th(tf(e.text)),children:s,params:o}}function tv(e){let t=e.childForFieldName("parameter");if(t)return[t.text];let r=e.childForFieldName("parameters");if(!r)return;let n=[];for(let e=0;e<r.namedChildCount;e++){let t=r.namedChild(e);t&&n.push(function e(t){switch(t.type){case"required_parameter":case"optional_parameter":{let r=t.childForFieldName("pattern");return r?e(r):t.text}case"assignment_pattern":{let r=t.childForFieldName("left");return r?e(r):t.text}case"default_parameter":case"typed_default_parameter":{let e=t.childForFieldName("name");return e?e.text:t.text}case"typed_parameter":for(let e=0;e<t.namedChildCount;e++){let r=t.namedChild(e);if(r?.type==="identifier")return r.text}return t.text;default:return t.text}}(t))}return n}let tj={theorem:"function",def:"function",abbrev:"function",example:"function",instance:"const",structure:"class",inductive:"type",axiom:"const",opaque:"const",constant:"const"};function tw(e){let t=e.split("/").pop()?.toLowerCase()??"";switch(t.includes(".")?t.split(".").pop():""){case"ts":return"typescript";case"tsx":case"jsx":return"tsx";case"js":case"mjs":case"cjs":return"javascript";case"py":case"pyi":return"python";case"go":return"go";case"rs":return"rust";case"lean":return"lean";default:return null}}var tk=r(14066);let ty="/tree-sitter",tN=null,tC=new Map;async function tS(e){let t,r=await (!(t=tC.get(e))&&(t=(async()=>(await (!tN&&(tN=tk.iX.init({locateFile:e=>`${ty}/${e}`})),tN),tk.TM.load(`${ty}/tree-sitter-${e}.wasm`)))(),tC.set(e,t)),t),n=new tk.iX;return n.setLanguage(r),n}function tM(e){return e.qualifiedName.startsWith("__code_")||e.qualifiedName.startsWith("__heading_")}function tL(e){return!tM(e)&&"__file__"!==e.qualifiedName}async function tE(e,t){if(!e)return[];let r=tw(t);if(!r)return null;let n=(await tS(r)).parse(e);if(!n)return null;try{return function(e,t){var r;let n,s,o=[],l=function(e){let t=[],r=-1,n=-1;for(let s=0;s<e.namedChildCount;s++){let o=e.namedChild(s);if(o){if("import_statement"===o.type||"export_statement"===o.type&&null!==o.childForFieldName("source")||"import_from_statement"===o.type||"future_import_statement"===o.type||"import"===o.type)t.push(o),r<0&&(r=o.startPosition.row+1),n=o.endPosition.row+1;else if(r>=0)break}}return r<0?null:{qualifiedName:"__imports__",name:"imports",kind:"unknown",startLine:r,endLine:n,declLine:r,contentHash:th(tf(t.map(e=>e.text).join("\n"))),children:[]}}(e);if(l&&o.push(l),"lean"===t)o.push(...function(e){let t=[],r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s)continue;switch(s.type){case"namespace":r.push(s.childForFieldName("name")?.text??null);continue;case"section":r.push(null);continue;case"end":r.pop();continue}let o=null;if("declaration"===s.type)for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t&&t.type in tj){o=t;break}}else s.type in tj&&(o=s);if(!o)continue;let l=o.childForFieldName("name")?.text??o.type,a=r.filter(e=>null!==e);t.push({qualifiedName:[...a,l].join("."),name:l,kind:tj[o.type],startLine:s.startPosition.row+1,endLine:function(e){let t=e.endPosition.row+1,r=e.text.replace(/\s+$/,""),n=e.text.slice(r.length);if(!n)return t;let s=n.split("\n").length-1;return Math.max(e.startPosition.row+1,t-s)}(s),declLine:o.startPosition.row+1,contentHash:th(tf(s.text)),children:[]})}return t}(e));else for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);r&&o.push(...function e(t,r,n=!1){switch(t.type){case"export_statement":case"export_default_declaration":{let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);o&&n.push(...e(o,r,!0))}return n}case"function_declaration":case"generator_function_declaration":case"function_definition":return[tb(t,tg(t),"function",r,[],tv(t))];case"class_declaration":case"abstract_class_declaration":{let e=tg(t),n=tp(r,e),s=function(e,t){if(!e)return[];let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(s){if("method_definition"===s.type)r.push(tb(s,tg(s),"method",t,[],tv(s)));else if("public_field_definition"===s.type){let e=s.childForFieldName("value");e&&("arrow_function"===e.type||"function_expression"===e.type)&&r.push(tb(s,tg(s),"method",t,[],tv(e)))}}}return r}(t.childForFieldName("body"),n);return[tb(t,e,"class",r,s)]}case"interface_declaration":return[tb(t,tg(t),"interface",r)];case"type_alias_declaration":return[tb(t,tg(t),"type",r)];case"enum_declaration":return[tb(t,tg(t),"enum",r)];case"lexical_declaration":case"variable_declaration":return function(e,t){let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s||"variable_declarator"!==s.type)continue;let o=s.childForFieldName("name"),l=s.childForFieldName("value");if(!o)continue;let a=o.text,i=function e(t,r=0){if(!t||r>8)return null;if("arrow_function"===t.type||"function_expression"===t.type)return t;if(["parenthesized_expression","as_expression","satisfies_expression","non_null_expression"].includes(t.type))return e(t.namedChild(0),r+1);if("call_expression"!==t.type)return null;let n=t.childForFieldName("function");if(!n)return null;let s="member_expression"===n.type?n.childForFieldName("object"):null,o=s?.type==="identifier"?s.text:"identifier"===n.type?n.text:null;if(!o)return null;let l=t;for(;l.parent;)l=l.parent;let a=(function(e){let t=[];for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);if(n)if("import_statement"===n.type){let e=n.childForFieldName("source");e?function(e,t,r){var n;let s=(n=t.text).length>=2&&('"'===n[0]||"'"===n[0])&&n[n.length-1]===n[0]?n.slice(1,-1):n,o=null;for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);if(r?.type==="import_clause"){o=r;break}}if(o)for(let e=0;e<o.namedChildCount;e++){let t=o.namedChild(e);if(t){if("identifier"===t.type)r.push({specifier:s,importedName:"default",localName:t.text});else if("namespace_import"===t.type){let e=function(e,t){for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);if(n?.type===t)return n}return null}(t,"identifier");e&&r.push({specifier:s,importedName:"*",localName:e.text})}else if("named_imports"===t.type)for(let e=0;e<t.namedChildCount;e++){let n=t.namedChild(e);if(!n||"import_specifier"!==n.type)continue;let o=n.childForFieldName("name"),l=n.childForFieldName("alias");o&&r.push({specifier:s,importedName:o.text,localName:l?.text??o.text})}}}}(n,e,t):function(e,t){for(let r=0;r<e.childCount;r++){let n=e.child(r);if(n&&"name"===e.fieldNameForChild(r)){if("dotted_name"===n.type){let e=n.text,r=e.split(".")[0];t.push({specifier:e,importedName:"*",localName:r})}else if("aliased_import"===n.type){let e=n.childForFieldName("name"),r=n.childForFieldName("alias");e?.type==="dotted_name"&&r&&t.push({specifier:e.text,importedName:"*",localName:r.text})}}}}(n,t)}else"import_from_statement"===n.type&&function(e,t){let r=e.childForFieldName("module_name"),n="";if(r){if("dotted_name"===r.type)n=r.text;else if("relative_import"===r.type){let e="",t="";for(let n=0;n<r.namedChildCount;n++){let s=r.namedChild(n);s&&("import_prefix"===s.type?e=s.text:"dotted_name"===s.type&&(t=s.text))}n=e+t}}if(!n)return;let s=!1;for(let r=0;r<e.childCount;r++){let o=e.child(r);if(!o)continue;let l=e.fieldNameForChild(r);if("wildcard_import"===o.type){s=!0;continue}if("name"===l){if("dotted_name"===o.type){let e=o.text;t.push({specifier:n,importedName:e,localName:e})}else if("aliased_import"===o.type){let e=o.childForFieldName("name"),r=o.childForFieldName("alias");e?.type==="dotted_name"&&r&&t.push({specifier:n,importedName:e.text,localName:r.text})}}}s&&t.push({specifier:n,importedName:"*",localName:"*"})}(n,t)}return t})(l).find(e=>e.localName===o);if(!a)return null;let i=s?n.childForFieldName("property")?.text:a.importedName,d="*"===a.importedName||"default"===a.importedName;return(!s||d)&&("@cockpit/effect-runtime/server"===a.specifier?"handler"===i||"dynamicHandler"===i:"react"===a.specifier&&["memo","forwardRef","useCallback"].includes(i??""))?e(t.childForFieldName("arguments")?.namedChild(0)??null,r+1):null}(l),d=null!==i,c=i?tv(i):void 0;if(r.push(tb(e,a,d?"function":"const",t,[],c)),l&&"object"===l.type&&!d){let e=t?`${t}>${a}`:a;for(let t=0;t<l.namedChildCount;t++){let n=l.namedChild(t);if(n){if("pair"===n.type){let t=n.childForFieldName("key"),s=n.childForFieldName("value");if(!t||!s||"property_identifier"!==t.type&&"identifier"!==t.type||"arrow_function"!==s.type&&"function_expression"!==s.type)continue;r.push(tb(n,t.text,"method",e,[],tv(s)))}else if("method_definition"===n.type){let t=tg(n);t&&r.push(tb(n,t,"method",e,[],tv(n)))}}}}}return r}(t,r);case"class_definition":{let e=tg(t),n=tp(r,e),s=function e(t,r){if(!t)return[];let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);if(o){if("function_definition"===o.type)n.push(tb(o,tg(o),"method",r,[],tv(o)));else if("decorated_definition"===o.type){let t=o.childForFieldName("definition");if(t?.type==="function_definition")n.push({...tb(t,tg(t),"method",r,[],tv(t)),startLine:o.startPosition.row+1,contentHash:th(tf(o.text))});else if(t?.type==="class_definition"){let s=tg(t),l=tp(r,s),a=e(t.childForFieldName("body"),l);n.push({...tb(t,s,"class",r,a),startLine:o.startPosition.row+1,contentHash:th(tf(o.text))})}}else if("class_definition"===o.type){let t=tg(o),s=tp(r,t),l=e(o.childForFieldName("body"),s);n.push(tb(o,t,"class",r,l))}}}return n}(t.childForFieldName("body"),n);return[tb(t,e,"class",r,s)]}case"decorated_definition":{let n=t.childForFieldName("definition");if(!n)return[];return e(n,r,!1).map(e=>({...e,startLine:t.startPosition.row+1,contentHash:th(tf(t.text))}))}case"expression_statement":{let e=[];for(let n=0;n<t.namedChildCount;n++){let s=t.namedChild(n);if(s?.type==="assignment"){let n=function(e,t,r){let n=t.childForFieldName("left");if(!n||"identifier"!==n.type)return null;let s=n.text;return{qualifiedName:tp(r,s),name:s,kind:"const",startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,declLine:e.startPosition.row+1,contentHash:th(tf(e.text)),children:[]}}(t,s,r);n&&e.push(n)}}return e.push(...function(e,t){let r=null;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);if(n){if("call_expression"===n.type){r=n;break}if("await_expression"===n.type){for(let e=0;e<n.namedChildCount;e++){let t=n.namedChild(e);if(t?.type==="call_expression"){r=t;break}}break}}}if(!r)return[];let n=r.childForFieldName("function"),s=r.childForFieldName("arguments");if(!n||!s)return[];let o=null,l=[];for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t){if(null===o&&("string"===t.type||"template_string"===t.type)){let e=t.text;o=e.length>=2&&/^["'`]/.test(e)?e.slice(1,-1):e}("arrow_function"===t.type||"function_expression"===t.type)&&l.push(t)}}if(0===l.length||!o)return[];let a=function e(t){if("identifier"===t.type)return t.text;if("member_expression"===t.type){let e=t.childForFieldName("property");return e?.text??""}if("call_expression"===t.type){let r=t.childForFieldName("function");return r?e(r):""}return""}(n),i=a?`${a} ${o}`:o;return l.map((e,r)=>tb(e,l.length>1?`${i} #${r+1}`:i,"function",t,[],tv(e)))}(t,r)),e}default:return[]}}(r,void 0,!1))}return!function(e,t){for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);if(n?.type!=="export_statement")continue;let s=n.childForFieldName("declaration");if(!s||s.startPosition.row===n.startPosition.row)continue;let o=s.startPosition.row+1;for(let e of t)"unknown"!==e.kind&&e.startLine===o&&(e.startLine=n.startPosition.row+1)}let r=new Map;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);if(!n||!function(e){if("attribute_item"===e.type)return!0;if(!e.type.endsWith("comment"))return!1;for(let t=0;t<e.namedChildCount;t++)if(e.namedChild(t)?.type==="inner_doc_comment_marker")return!1;return!0}(n))continue;let s=0===n.endPosition.column&&n.endPosition.row>n.startPosition.row?n.endPosition.row-1:n.endPosition.row;r.set(s+1,n)}if(0===r.size)return;let n=new Set;for(let e of t)for(let t=e.startLine;t<=e.endLine;t++)n.add(t);for(let e of t){if("unknown"===e.kind)continue;let t=e.startLine;for(;;){let e=r.get(t-1);if(!e)break;let s=e.startPosition.row+1,o=!1;for(let e=s;e<=t-1;e++)if(n.has(e)){o=!0;break}if(o)break;t=s}if(t!==e.startLine){for(let r=t;r<e.startLine;r++)n.add(r);e.startLine=t}}}(e,o),o.push(...function(e,t){let r=e.text.split("\n"),n=r.length;if(0===n)return[];let s=new Uint8Array(n+2);for(let e of t){let t=Math.max(1,e.startLine),r=Math.min(n,e.endLine);for(let e=t;e<=r;e++)s[e]=1}let o=[],l=(e,t)=>{let n=!1;for(let s=e;s<=t;s++){let e=r[s-1];if(e&&e.trim().length>0){n=!0;break}}if(!n)return;let s=r.slice(e-1,t).join("\n");o.push({qualifiedName:`__code_${e}_${t}__`,name:"code",kind:"unknown",startLine:e,endLine:t,declLine:e,contentHash:th(tf(s)),children:[]})},a=-1;for(let e=1;e<=n;e++)s[e]?a>=0&&(l(a,e-1),a=-1):a<0&&(a=e);return a>=0&&l(a,n),o}(e,o)),r=o,n=new Map,(s=e=>{for(let t of e){let e=(n.get(t.qualifiedName)??0)+1;n.set(t.qualifiedName,e),e>1&&(t.qualifiedName=`${t.qualifiedName}#${e}`),s(t.children)}})(r),o}(n.rootNode,r)}finally{n.delete()}}function tP(e,t){if(0===t.size)return[];let r=[];for(let n of e)if(tL(n)){for(let e=n.startLine;e<n.declLine;e++)if(t.has(e)){r.push(n.qualifiedName);break}}return r}async function tT(e,t,r,n,s){let o=new Set,l=new Set;if(e!==t)for(let r of(0,tx.X)(n?"":e,s?"":t))"added"===r.type&&void 0!==r.newLineNum?o.add(r.newLineNum):"removed"===r.type&&void 0!==r.oldLineNum&&l.add(r.oldLineNum);if(!tw(r))return{addedLines:o};let[a,i]=await Promise.all([tE(n?"":e,r),tE(s?"":t,r)]),d=a??[],c=i??[],u=function(e,t){let r=new Map;for(let t of e)r.set(t.qualifiedName,t);let n=new Map;for(let e of t)n.set(e.qualifiedName,e);let s=[];for(let e of t){let t=r.get(e.qualifiedName);t?t.contentHash!==e.contentHash&&s.push({id:`mod:${e.qualifiedName}`,changeKind:"modified",qname:e.qualifiedName}):s.push({id:`add:${e.qualifiedName}`,changeKind:"added",qname:e.qualifiedName})}for(let t of e)n.has(t.qualifiedName)||s.push({id:`del:${t.qualifiedName}`,changeKind:"deleted",qname:t.qualifiedName});return s}(d.filter(tL),c.filter(tL)),m=new Set;for(let e of u)"deleted"!==e.changeKind&&m.add(e.qname);for(let e of function(e,t){if(0===t.size)return[];let r=[];for(let n of e)if(tM(n)){for(let e of t)if(e>=n.startLine&&e<=n.endLine){r.push(n.qualifiedName);break}}return r}(c,o))m.add(e);for(let e of tP(c,o))m.add(e);let x=new Set(c.map(e=>e.qualifiedName));for(let e of tP(d,l))x.has(e)&&m.add(e);return{changedQnames:m,addedLines:o}}function t$({cwd:e,filePath:t,oldContent:r,newContent:o,isNew:l=!1,isDeleted:a=!1,changedFiles:i,fileGitStatusMap:d,enableComments:c=!1,compact:u=!0,onContentSearch:m,onSwitchToCode:x,headerExtraLeft:h,headerExtraRight:f}){let[p,g]=(0,s.useState)(t);(0,s.useEffect)(()=>{g(t)},[t]);let[b,v]=(0,s.useState)(null);return(0,s.useEffect)(()=>{let n=!1;return v(null),(async()=>{try{let s=await tR(p,t,r,o,l,a,i,d,e);if(n||!s)return;let c=await tT(s.oldContent,s.newContent,p,s.isNew,s.isDeleted);if(n)return;v(c)}catch(e){n||console.error("[BlockDiffViewer] projection failed:",e)}})(),()=>{n=!0}},[p,t,r,o,l,a,i,d,e]),(0,n.jsx)(tc,{cwd:e,highlightedFilePath:t,changedFiles:i,enableComments:c,qnameFilter:u?b?.changedQnames:void 0,qnameFilterFile:p,accentQnames:b?.changedQnames,accentFile:p,addedLines:b?.addedLines,addedLinesFile:p,compact:u,onFocalChange:e=>e&&g(e),onContentSearch:m,onSwitchToCode:x,headerExtraLeft:h,headerExtraRight:f})}async function tR(e,t,r,n,s,o,l,a,i){if(e===t)return{oldContent:r,newContent:n,isNew:s,isDeleted:o};if(!l.has(e))return null;let d=a?.get(e);if(!d)return null;let c=new URLSearchParams({cwd:i,file:e,type:d}),u=await P.t4.runPromiseExit((0,R.oh)(c));if("Success"!==u._tag)return null;let m=u.value;return{oldContent:m.oldContent,newContent:m.newContent,isNew:m.isNew??!1,isDeleted:m.isDeleted??!1}}var tI=r(50860);let tF=(e,t,r)=>`/api/git/blob?cwd=${encodeURIComponent(e)}&rev=${encodeURIComponent(t)}&file=${encodeURIComponent(r)}`;function tB({cwd:e,selected:t,diff:r,showMarkdownPreview:l,setShowMarkdownPreview:a,changedFiles:i,fileGitStatusMap:d,onContentSearch:c,locateInTree:u,setJsonPreview:m,onTokenHover:x,onTokenHoverLeave:h,onTokenHoverCancel:f}){let{t:p}=(0,o.Bd)(),g="unstaged"===t.type?{onTokenHover:x,onTokenHoverLeave:h,onTokenHoverCancel:f}:{},[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)("file"),[k,y]=(0,s.useState)("compact"),[N,C]=(0,s.useState)("unified"),S=t.file.path,M=t.file.oldPath||S,L=(0,U.u)(S),E=S.startsWith("/")?S:e?`${e.replace(/\/$/,"")}/${S}`:S,{state:P}=eD(e,S),T=(0,s.useMemo)(()=>{if("ready"===P.state)return P.data.functions.filter(eK).map(e=>({name:e.name,startLine:e.startLine,endLine:e.endLine,params:e.params}))},[P]);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[L||"map"!==j?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:S}),(0,n.jsx)(z.m,{content:p("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(`${e}/${S}`),(0,q.oR)(p("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(z.m,{content:p("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(S)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${"staged"===t.type?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===t.type?p("fileBrowser.staged"):p("fileBrowser.unstaged")}),(0,n.jsx)("div",{className:"flex-1"}),!L&&(0,n.jsx)(D.y,{value:k,onChange:y}),!L&&"file"===j&&(0,n.jsx)(A.q,{value:N,onChange:C}),!L&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),w(e)},className:`px-2 py-0.5 text-xs transition-colors ${j===e?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:p("file"===e?"common.file":"common.codeMap")},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:L?(0,n.jsx)(O.K,{filePath:S,oldSrc:r.isNew?null:tF(e,"staged"===t.type?"HEAD":":0","staged"===t.type?M:S),newSrc:r.isDeleted||"staged"!==t.type?null:tF(e,":0",S),newNode:r.isDeleted||"staged"===t.type?void 0:(0,n.jsx)(tI.I,{cwd:e,path:S,className:"flex items-center justify-center",imgClassName:"max-w-full max-h-[60vh] object-contain",alt:S})}):"unified"===N?(0,n.jsx)(I.xU,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,cwd:e,enableComments:!0,compact:"compact"===k,onPreview:!r.isDeleted&&(0,K.e$)(S)?()=>a(!0):!r.isDeleted&&(0,K.aR)(S)?()=>v(!0):!r.isDeleted&&S.endsWith(".json")?()=>m({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:S.endsWith(".json")?p("common.readable"):p("common.preview"),onContentSearch:c,...g}):(0,n.jsx)(I.xZ,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,isNew:r.isNew,isDeleted:r.isDeleted,cwd:e,enableComments:!0,compact:"compact"===k,symbols:T,onPreview:!r.isDeleted&&(0,K.e$)(S)?()=>a(!0):!r.isDeleted&&(0,K.aR)(S)?()=>v(!0):!r.isDeleted&&S.endsWith(".json")?()=>m({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:S.endsWith(".json")?p("common.readable"):p("common.preview"),onContentSearch:c,...g})})]}):(0,n.jsx)(t$,{cwd:e,filePath:r.filePath,oldContent:r.oldContent,newContent:r.newContent,isNew:r.isNew,isDeleted:r.isDeleted,changedFiles:i,fileGitStatusMap:d,enableComments:!0,compact:"compact"===k,onContentSearch:c,headerExtraLeft:({focalFile:t})=>{if(!t)return null;let r=d.get(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(z.m,{content:p("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,q.oR)(p("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(z.m,{content:p("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),r&&(0,n.jsx)("span",{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 ${"staged"===r?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===r?p("fileBrowser.staged"):p("fileBrowser.unstaged")})]})},headerExtraRight:()=>(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(D.y,{value:k,onChange:y}),(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),w(e)},className:`px-2 py-0.5 text-[11px] transition-colors ${j===e?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:p("file"===e?"common.file":"common.codeMap")},e))})]})}),l&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:()=>a(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(B.M,{content:r.newContent,filePath:r.filePath,cwd:e,onClose:()=>a(!1)})})}),b&&(0,n.jsx)(F.N,{filePath:E,content:r.newContent,cwd:e,onClose:()=>v(!1)})]})}function tD({branches:e,selectedBranch:t,onSelect:r,isLoading:l,pinnedBranches:a=[]}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(""),x=(0,s.useRef)(null),h=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{d&&h.current&&h.current.focus()},[d]);let f=u.toLowerCase(),p=new Set([...e?.local||[],...e?.remote||[]]),g=a.filter(e=>p.has(e)&&e.toLowerCase().includes(f)),b=new Set(g),v=e?.local.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],j=e?.remote.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],w=e=>{r(e),c(!1),m("")};return(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsxs)("button",{onClick:()=>c(!d),disabled:l,className:"w-full px-3 py-1.5 text-sm border border-border rounded bg-card text-foreground text-left flex items-center justify-between hover:border-slate-6 dark:hover:border-slate-6 transition-colors",children:[(0,n.jsxs)("span",{className:"truncate flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t||i("git.selectBranch"),e?.current===t&&(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["(",i("git.currentBranch"),")"]})]}),(0,n.jsx)("svg",{className:`w-4 h-4 text-foreground-subtle transition-transform ${d?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),d&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full bg-card border border-border rounded-lg shadow-lv2 max-h-80 flex flex-col",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:h,type:"text",value:u,onChange:e=>m(e.target.value),placeholder:i("git.searchBranch"),className:"w-full px-2 py-1 text-sm border border-border rounded bg-secondary text-foreground"})}),(0,n.jsxs)("div",{className:"overflow-y-auto flex-1",children:[g.length>0&&g.map(r=>(0,n.jsxs)("div",{onClick:()=>w(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},`pinned-${r}`)),v.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-popover sticky top-0",children:i("git.localBranches")}),v.map(r=>(0,n.jsxs)("div",{onClick:()=>w(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},r))]}),j.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-popover sticky top-0",children:i("git.remoteBranches")}),j.map(e=>(0,n.jsxs)("div",{onClick:()=>w(e),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${e===t?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:e}),e===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},e))]}),0===g.length&&0===v.length&&0===j.length&&(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("git.noMatchingBranches")})]})]})]})}let tA=96/72;function tH({cwd:e,path:t,refreshKey:o}){let l=(0,s.useRef)(null),[a,i]=(0,s.useState)({kind:"loading"}),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(0),[x,h]=(0,s.useState)(null),[f,p]=(0,s.useState)(0),[g,b]=(0,s.useState)({kind:"auto"}),[v,j]=(0,s.useState)(1),[w,k]=(0,s.useState)(!0);(0,s.useEffect)(()=>{let n=!1;i({kind:"loading"}),c(null),m(0),h(null),j(1);let s=null;return(async()=>{try{let l=await Promise.all([r.e(52084),r.e(49304)]).then(r.bind(r,66898));l.GlobalWorkerOptions.workerSrc="/pdfjs/pdf.worker.min.mjs";let a=`/api/files/read?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}&v=${encodeURIComponent(String(o??""))}`;s=l.getDocument({url:a});let d=await s.promise;if(n)return;let u=await Promise.all(Array.from({length:d.numPages},(e,t)=>d.getPage(t+1).then(e=>{let t=e.getViewport({scale:1});return{w:t.width,h:t.height}})));if(n)return;c(d),m(d.numPages),h(u),i({kind:"ready"})}catch(e){n||i({kind:"error",message:e instanceof Error?e.message:"Failed to load PDF"})}})(),()=>{n=!0;try{s?.destroy()}catch{}}},[e,t,o]),(0,s.useEffect)(()=>{let e=l.current;if(!e)return;let t=()=>p(Math.max(0,e.clientWidth-32));t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[]);let y=(0,s.useMemo)(()=>x?.length?Math.max(...x.map(e=>e.w)):0,[x]),N=Math.min(y>0&&f>0?f/y:tA,tA),C="auto"===g.kind?N:g.factor*tA,S=Math.round(C/tA*100),M=(0,s.useMemo)(()=>x?x.map(e=>e.h*C+16):[],[x,C]),L=y*C,E=(0,s.useRef)(1);E.current=N/tA;let P=(0,s.useRef)(M);P.current=M;let T=(0,ee.Te)({count:u,getScrollElement:()=>l.current,estimateSize:e=>P.current[e]??0,overscan:2});(0,s.useEffect)(()=>{M.length>0&&T.measure()},[M,T]);let $=(0,s.useCallback)(()=>{let e=l.current;if(!e||0===u)return;let t=e.scrollTop,r=T.getVirtualItems().find(e=>e.end>t);j((r?r.index:u-1)+1)},[T,u]),R=(0,s.useCallback)(e=>{b(t=>({kind:"fixed",factor:Math.min(4,Math.max(.25,("auto"===t.kind?E.current:t.factor)*e))}))},[]),I=(0,s.useCallback)(()=>R(1.2),[R]),F=(0,s.useCallback)(()=>R(.8333333333333334),[R]),B=(0,s.useCallback)(()=>b({kind:"auto"}),[]),D=(0,s.useCallback)(()=>k(e=>!e),[]),A=(0,s.useCallback)(e=>{T.scrollToIndex(e,{align:"start"}),j(e+1)},[T]),H=T.getVirtualItems(),O=T.getTotalSize(),W=(0,s.useMemo)(()=>(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border text-muted-foreground text-xs select-none",children:[(0,n.jsx)("button",{onClick:D,className:`px-1.5 py-0.5 rounded hover:bg-hover transition-colors ${w?"text-foreground":""}`,title:w?"Hide thumbnails":"Show thumbnails","aria-label":"Toggle thumbnails",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),(0,n.jsx)("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),(0,n.jsx)("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]})}),(0,n.jsx)("span",{className:"tabular-nums",children:u>0?`${v} / ${u}`:"—"}),(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:F,className:"px-1.5 py-0.5 rounded hover:bg-hover transition-colors",title:"Zoom out","aria-label":"Zoom out",children:"−"}),(0,n.jsxs)("button",{onClick:B,className:`px-1.5 py-0.5 rounded hover:bg-hover transition-colors tabular-nums min-w-[3.5rem] ${"auto"===g.kind?"":"text-foreground"}`,title:"Reset to automatic zoom",children:[S,"%"]}),(0,n.jsx)("button",{onClick:I,className:"px-1.5 py-0.5 rounded hover:bg-hover transition-colors",title:"Zoom in","aria-label":"Zoom in",children:"+"})]})]}),[u,v,S,g.kind,I,F,B,w,D]);return"error"===a.kind?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-secondary",children:[W,(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-sm text-red-11",children:a.message})})]}):(0,n.jsxs)("div",{className:"h-full flex flex-col bg-secondary",children:[W,(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[w&&d&&x&&(0,n.jsx)(tO,{doc:d,numPages:u,sizes:x,maxPageW:y,currentPage:v,onSelect:A}),(0,n.jsx)("div",{ref:l,onScroll:$,className:"flex-1 overflow-auto px-4 py-4",children:"loading"!==a.kind&&d&&x&&!(L<=0)?(0,n.jsx)("div",{style:{height:O,width:Math.max(L,f),position:"relative"},children:H.map(e=>(0,n.jsx)("div",{"data-index":e.index,className:"absolute left-0 top-0 w-full flex justify-center",style:{transform:`translateY(${e.start}px)`,paddingBottom:16},children:(0,n.jsx)(tW,{doc:d,pageNumber:e.index+1,scale:C,width:x[e.index].w*C,height:x[e.index].h*C})},e.key))}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})})})]})]})}function tO({doc:e,numPages:t,sizes:r,maxPageW:o,currentPage:l,onSelect:a}){let i=(0,s.useRef)(null),d=o>0?100/o:0,c=(0,s.useMemo)(()=>r.map(e=>e.h*d+18+12),[r,d]),u=(0,s.useRef)(c);u.current=c;let m=(0,ee.Te)({count:t,getScrollElement:()=>i.current,estimateSize:e=>u.current[e]??0,overscan:3});(0,s.useEffect)(()=>{c.length>0&&m.measure()},[c,m]),(0,s.useEffect)(()=>{t>0&&m.scrollToIndex(l-1,{align:"auto"})},[l]);let x=m.getVirtualItems();return(0,n.jsx)("div",{ref:i,className:"shrink-0 overflow-auto border-r border-border py-2",style:{width:132},children:(0,n.jsx)("div",{style:{height:m.getTotalSize(),width:"100%",position:"relative"},children:x.map(t=>{let s=l===t.index+1;return(0,n.jsxs)("div",{className:"absolute left-0 top-0 w-full flex flex-col items-center",style:{transform:`translateY(${t.start}px)`,paddingBottom:12},children:[(0,n.jsx)("button",{onClick:()=>a(t.index),className:`rounded-sm overflow-hidden transition-shadow ${s?"ring-2 ring-brand":"ring-1 ring-border hover:ring-muted-foreground"}`,title:`Page ${t.index+1}`,"aria-label":`Go to page ${t.index+1}`,children:(0,n.jsx)(tW,{doc:e,pageNumber:t.index+1,scale:d,width:r[t.index].w*d,height:r[t.index].h*d})}),(0,n.jsx)("span",{className:`mt-0.5 text-[11px] tabular-nums leading-none ${s?"text-foreground font-medium":"text-muted-foreground"}`,style:{height:18},children:t.index+1})]},t.key)})})})}function tW({doc:e,pageNumber:t,scale:r,width:o,height:l}){let a=(0,s.useRef)(null);return(0,s.useEffect)(()=>{let n=!1,s=null;return(async()=>{let o=await e.getPage(t);if(n)return;let l=a.current;if(!l)return;let i=Math.min(window.devicePixelRatio||1,2),d=o.getViewport({scale:r*i});l.width=Math.floor(d.width),l.height=Math.floor(d.height),l.style.width=`${l.width/i}px`,l.style.height=`${l.height/i}px`,s=o.render({canvas:l,viewport:d});try{await s.promise}catch{}})(),()=>{n=!0;try{s?.cancel()}catch{}}},[e,t,r]),(0,n.jsx)("div",{className:"bg-white shadow-lv2",style:{width:o,height:l},children:(0,n.jsx)("canvas",{ref:a,className:"block"})})}var t_=r(69809);function tz(e){let t=e.split(".").pop()?.toLowerCase();return t?["ts","tsx","js","jsx","mjs","cjs"].includes(t)?"typescript":["py","pyi"].includes(t)?"python":null:null}let tq=(e,t)=>eT.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()},catch:t=>new e$.uV({message:`${e} failed`,cause:t})});function tV(e){return e.replace(/^\([^)]+\)\s*/,"")}function tU(e){let t=tV(e),r=t.match(/^(?:function|const|let|var|class|interface|type|enum|async function)\s+([a-zA-Z_$][\w$]*)/);if(r)return r[1];let n=e.match(/\([^)]+\)\s+(?:[\w$]+\.)*([a-zA-Z_$][\w$]*)/);if(n)return n[1];let s=t.match(/([a-zA-Z_$][\w$]*)/);return s?s[1]:t.split(/[(\s:]/)[0]}let tK=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:l,container:a,onMouseEnter:i,onMouseLeave:d,onFindReferences:c,onSearch:u,onExplain:m,explainDisabled:x},h){let{t:f}=(0,o.Bd)(),p=(0,s.useRef)(null);(0,s.useImperativeHandle)(h,()=>p.current,[]);let g=a.getBoundingClientRect(),b=r-g.left,v=l-g.top,j=(0,s.useMemo)(()=>tV(e),[e]),w=(0,s.useMemo)(()=>(function(e){let t,r=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b/g,s=[],o=0,l=0,a=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b|"[^"]*"|'[^']*'|\b\d+\b/g;for(;null!==(t=a.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},l++));let a=t[0];/^["']/.test(a)?s.push((0,n.jsx)("span",{className:"text-green-11",children:a},l++)):/^\d+$/.test(a)?s.push((0,n.jsx)("span",{className:"text-orange-11",children:a},l++)):r.test(a)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-violet-11",children:a},l++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:a},l++)),o=t.index+a.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},l++)),s})(j),[j]);return(0,s.useEffect)(()=>{if(!p.current)return;let e=p.current,t=a.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=l-t.top;s+n.width>t.width-8&&(s=t.width-n.width-8),s<8&&(s=8),o+n.height>t.height-8&&(o=o-n.height-24),e.style.left=`${s}px`,e.style.top=`${o}px`},[r,l,a]),(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] max-w-lg bg-card border border-border rounded-lg shadow-lv3 px-3 py-2 pointer-events-none",style:{left:b,top:v},children:[(0,n.jsx)("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all leading-relaxed",children:w}),t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground whitespace-pre-wrap",children:t})]}),(c||u||m)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1.5"}),(0,n.jsxs)("div",{className:"flex items-center gap-3 pointer-events-auto",onMouseEnter:i,onMouseLeave:d,children:[c&&(0,n.jsx)("button",{onClick:c,className:"text-[11px] text-brand hover:underline cursor-pointer",children:f("hoverTooltip.findReferences")}),u&&(0,n.jsx)("button",{onClick:()=>u(tU(e)),className:"text-[11px] text-brand hover:underline cursor-pointer",children:f("hoverTooltip.search")}),m&&(0,n.jsx)("button",{onClick:()=>m(tU(e)),disabled:x,title:x?f("comments.aiResponding"):void 0,className:"text-[11px] text-brand hover:underline cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed disabled:no-underline",children:f("explain.action")})]})]})]})});function tQ({references:e,loading:t,onSelect:r,onClose:l}){let{t:a}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(0,s.useRef)(0);return(0,s.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()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,ez.kS)();if(t!==l.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let l=(0,ez.sQ)(r.file);if("text"!==l)try{let e=n.codeToTokens(r.lineText,{lang:l,theme:s}),a=(0,ez.b8)(e.tokens[0]||[]);a&&o.set(t,a)}catch{}}t===l.current&&r(o)})()},[e,n]),t}(e),d=[],c=new Map;for(let t=0;t<e.length;t++){let r=e[t],n=c.get(r.file);void 0===n&&(n=d.length,c.set(r.file,n),d.push({file:r.file,items:[]})),d[n].items.push({ref:r,idx:t})}return(0,n.jsxs)("div",{className:"border-t border-border bg-card flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[a("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:l,className:"p-0.5 rounded hover:bg-hover text-muted-foreground",children:(0,n.jsx)(ew.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:a("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:a("references.notFound")}):d.map(({file:e,items:t})=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card sticky top-0",children:e}),t.map(({ref:e,idx:t})=>(0,n.jsxs)("button",{onClick:()=>r(e),className:"w-full text-left px-3 py-0.5 hover:bg-hover flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:e.line}),i.has(t)?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:i.get(t)}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:e.lineText||""})]},`${e.line}-${e.column}-${t}`))]},e))})]})}function tG({results:e,loading:t,totalMatches:r,onSelect:l,onClose:a,scope:i,onScopeChange:d,selectedPath:c}){let{t:u}=(0,o.Bd)(),m=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(0,s.useRef)(0);return(0,s.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()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,ez.kS)(),o=new Map;for(let t of e){let e=(0,ez.sQ)(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let l=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),a=(0,ez.b8)(t.tokens[0]||[]);a&&o.set(l,a)}catch{}}}t===l.current&&r(o)})()},[e,n]),t}(e),x="selected"===i?e.filter(e=>e.path===c):e,h=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsxs)("div",{className:"border-t border-border bg-card flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground truncate",children:[u("searchResults.title")," ",!t&&u("searchResults.nMatches",{count:"selected"===i?h:r})]}),(0,n.jsxs)("div",{className:"flex items-center rounded border border-border overflow-hidden text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>d("selected"),className:`px-2 py-0.5 ${"selected"===i?"bg-brand/15 text-brand":"text-muted-foreground hover:bg-hover"}`,children:u("searchResults.scopeSelected")}),(0,n.jsx)("button",{onClick:()=>d("all"),className:`px-2 py-0.5 border-l border-border ${"all"===i?"bg-brand/15 text-brand":"text-muted-foreground hover:bg-hover"}`,children:u("searchResults.scopeAll")})]})]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-hover text-muted-foreground flex-shrink-0",children:(0,n.jsx)(ew.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:u("searchResults.searching")}):0===x.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:u("searchResults.noResults")}):x.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card sticky top-0",children:e.path}),e.matches.map((t,r)=>{let s=`${e.path}:${t.lineNumber}`,o=m.get(s);return(0,n.jsxs)("button",{onClick:()=>l(e.path,t.lineNumber),className:"w-full text-left px-3 py-0.5 hover:bg-hover flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:t.lineNumber}),o?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:o}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:t.content||""})]},`${t.lineNumber}-${r}`)})]},e.path))})]})}var tJ=r(63728),tY=r(79237);let tX=s.memo(function({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:a,initialSearchQuery:i,searchQueryTrigger:d,fileOpenRequest:c}){var u;let m,x,h,f,p,g,b,v,j,w,k,y,N,{t:C}=(0,o.Bd)(),S=(0,J.r)(),M=(0,s.useCallback)(e=>{S?.sendMessage(C("explain.fileMessage",{path:e}))},[S,C]),F=(0,s.useCallback)(e=>{S?.sendMessage(C("explain.stagedFileMessage",{path:e}))},[S,C]),O=(0,s.useCallback)(e=>{S?.sendMessage(C("explain.unstagedFileMessage",{path:e}))},[S,C]),W=(0,em.P)(),z=(0,ex.U)(),Y=(0,eh.Q)(),{activeView:X,onViewChange:ee}=(0,tJ.R8)(),[er,en]=(0,s.useState)(r),[es,ep]=(0,s.useState)("code"),ej=(0,s.useRef)(null),ew=(0,s.useRef)(!1),[ek,ey]=(0,s.useState)(null),[eN,eC]=(0,s.useState)(null),[eS,eM]=(0,s.useState)(!1),eL=(0,s.useRef)(1),eE=(0,s.useRef)(null),[eP,eR]=(0,s.useState)(null),eI=(0,s.useRef)(null),[eF,eB]=(0,s.useState)({isDirty:!1,isSaving:!1}),[eD,eA]=(0,s.useState)(!1),[eH,eO]=(0,s.useState)(null),[eW,e_]=(0,s.useState)(null),[ez,eq]=(0,s.useState)("compact"),[eV,eU]=(0,s.useState)("unified"),[eK,eQ]=(0,s.useState)("full"),[eG,eJ]=(0,s.useState)("unified"),[eY,eX]=(0,s.useState)(320),eZ=(0,s.useRef)(null),e0=(0,s.useCallback)(e=>{"mouse"===e.pointerType&&0===e.button&&(e.preventDefault(),eZ.current={startX:e.clientX,startWidth:eY},e.currentTarget.setPointerCapture(e.pointerId))},[eY]),e1=(0,s.useCallback)(e=>{let t=eZ.current;t&&eX(Math.min(480,Math.max(320,t.startWidth+(e.clientX-t.startX))))},[]),e2=(0,s.useCallback)(e=>{eZ.current&&(eZ.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))},[]),e5=(0,s.useRef)(null),e4=(0,Q.o)(e5),e3=(0,s.useRef)(null),e6=(0,Q.o)(e3),e8=function(e){let[t,r]=(0,s.useState)(!1);return{goToDefinition:(0,s.useCallback)(async(t,n,s)=>{r(!0);let o=await P.t4.runPromiseExit(tq("/api/lsp/definition",{cwd:e,filePath:t,line:n,column:s}));return(r(!1),"Success"===o._tag)?o.value.definitions??[]:(console.error("[useLSP] definition error:",o.cause),[])},[e]),loading:t}}(t),e9=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),l=(0,s.useRef)(0),a=(0,s.useRef)(!1),i=(0,s.useRef)(null),d=(0,s.useRef)({x:0,y:0}),c=(0,s.useCallback)(e=>{i.current=e},[]);(0,s.useEffect)(()=>{let e=e=>{d.current.x=e.clientX,d.current.y=e.clientY};return document.addEventListener("mousemove",e),()=>document.removeEventListener("mousemove",e)},[]);let u=(0,s.useRef)(!1),m=(0,s.useRef)(null),x=(0,s.useCallback)(()=>{let e=i.current;e&&u.current&&(e.style.pointerEvents="none"),u.current=!1,m.current&&(i.current?.removeEventListener("mouseleave",m.current),m.current=null)},[]),h=(0,s.useCallback)(()=>{let e=i.current;if(!e||u.current)return;u.current=!0,a.current=!0,e.style.pointerEvents="auto";let t=()=>{a.current=!1,x(),l.current++,r(null)};m.current=t,e.addEventListener("mouseleave",t)},[x]),f=(0,s.useCallback)((t,s,a,i)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let d=++l.current;n.current=setTimeout(async()=>{let n=await P.t4.runPromiseExit(tq("/api/lsp/hover",{cwd:e,filePath:t,line:s,column:a}));if(d!==l.current||"Success"!==n._tag)return;let o=n.value.hover;o&&o.displayString&&r({...o,x:i.x,y:i.y,filePath:t,line:s,column:a})},300)},[e]),p=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),l.current++,o.current=setTimeout(function(){if(a.current)return;let e=i.current;if(e){let t=e.getBoundingClientRect(),{x:r,y:n}=d.current;if(r>=t.left&&r<=t.right&&n>=t.top&&n<=t.bottom)return void h()}r(null)},150)},[h]),g=(0,s.useCallback)(()=>{a.current=!0,o.current&&clearTimeout(o.current)},[]),b=(0,s.useCallback)(()=>{a.current=!1,l.current++,r(null)},[]),v=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),a.current=!1,x(),l.current++,r(null)},[x]);return(0,s.useEffect)(()=>{t||x()},[t,x]),{hoverInfo:t,onTokenMouseEnter:f,onTokenMouseLeave:p,onCardMouseEnter:g,onCardMouseLeave:b,clearHover:v,setTooltipEl:c}}(t),e7=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[l,a]=(0,s.useState)(!1);return{references:t,loading:n,visible:l,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),a(!0);let l=await P.t4.runPromiseExit(tq("/api/lsp/references",{cwd:e,filePath:t,line:n,column:s}));"Success"===l._tag?r(l.value.references??[]):(console.error("[useLSP] references error:",l.cause),r([])),o(!1)},[e]),closeReferences:(0,s.useCallback)(()=>{a(!1),r([])},[])}}(t),te=(m=(0,s.useRef)([]),x=(0,s.useRef)([]),h=(0,s.useCallback)(e=>{m.current.push(e),m.current.length>50&&(m.current=m.current.slice(-50)),x.current=[]},[]),f=(0,s.useCallback)(e=>{if(0===m.current.length)return null;let t=m.current.pop();return x.current.push(e),x.current.length>50&&(x.current=x.current.slice(-50)),t},[]),p=(0,s.useCallback)(e=>{if(0===x.current.length)return null;let t=x.current.pop();return m.current.push(e),m.current.length>50&&(m.current=m.current.slice(-50)),t},[]),{push:h,goBack:f,goForward:p,canGoBack:(0,s.useCallback)(()=>m.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>x.current.length>0,[])}),tt=(0,ev.F)(),tr=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[l,a]=(0,s.useState)(new Set),[i,d]=(0,s.useState)([]),[c,u]=(0,s.useState)(null),[m,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(new Set),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(""),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)(!0),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),R=(0,s.useRef)(null),[I,F]=(0,s.useState)(!1),[B,D]=(0,s.useState)(null),[A,H]=(0,s.useState)("center"),[O,W]=(0,s.useState)(null),[_,z]=(0,s.useState)(null),[q,V]=(0,s.useState)(!1),[K,Q]=(0,s.useState)([]),[G,J]=(0,s.useState)(!1),[Y,X]=(0,s.useState)(null),[Z,ee]=(0,s.useState)(null),[et,er]=(0,s.useState)(!0),[en,es]=(0,s.useState)(!1),[eo,el]=(0,s.useState)(!1),ea=(0,s.useMemo)(()=>i.map(e=>e.path).filter(Boolean),[i]),ei=(0,s.useMemo)(()=>(0,U.v3)(ea),[ea]),ed=(0,s.useMemo)(()=>new Set((0,U.tW)(ei)),[ei]),ec=(0,s.useMemo)(()=>b?n?(0,U.KH)(n,b,j):(0,U.q3)(t,b,j):null,[t,n,b,j]);(0,s.useEffect)(()=>{if(!ec||0===ec.size)return void g(null);let e=new Set;if(n){let t=new Set(n);for(let r of ec)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&ec.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}g(e)},[ec,t,n]);let eu=p??h,em=(0,s.useRef)(null),ex=(0,s.useCallback)(t=>{em.current&&clearTimeout(em.current),em.current=setTimeout(()=>{P.t4.runFork((0,T.Ft)(e,Array.from(t)).pipe(eT.sFT(e=>eT.OH5(()=>console.error("Error saving expanded paths:",e))),eT.NWQ(()=>eT.rIH)))},500)},[e]),eh=(0,s.useCallback)(async()=>{C(!0),E(null),await P.t4.runPromise((0,T.mP)(e).pipe(eT.YWq({onSuccess:e=>{e.error?E(e.error):(r(e.files??[]),e.expandedPaths&&Array.isArray(e.expandedPaths)&&f(new Set(e.expandedPaths)))},onFailure:e=>{console.error("Error loading files:",e),E("Failed to load files")}}))),C(!1)},[e]),ef=(0,s.useCallback)(()=>{P.t4.runPromise((0,T.DZ)(e).pipe(eT.YWq({onSuccess:e=>{e.paths&&o(e.paths)},onFailure:e=>{console.error("Error loading file index:",e)}})))},[e]),ep=(0,s.useCallback)(async t=>{a(e=>new Set([...e,t])),await P.t4.runPromise((0,T.gZ)(e,t).pipe(eT.YWq({onSuccess:e=>{e.children&&r(r=>{if(!t){let t=new Map(r.map(e=>[e.path,e]));return e.children.map(e=>{let r=t.get(e.path);return r?.children&&e.isDirectory?{...e,children:r.children}:e})}let n=structuredClone(r),s=(0,U.MB)(n,t);return s&&(s.children=e.children),n})},onFailure:e=>{console.error("Error loading directory:",e)}}))),a(e=>{let r=new Set(e);return r.delete(t),r})},[e]),eg=(0,s.useRef)(l);eg.current=l,(0,s.useEffect)(()=>{for(let e of p??h){let r=(0,U.MB)(t,e);r&&r.isDirectory&&!r.children&&!eg.current.has(e)&&ep(e)}},[t,h,p,ep]);let eb=(0,s.useCallback)(async()=>{await P.t4.runPromise((0,T.r9)(e).pipe(eT.YWq({onSuccess:e=>d(e.files??[]),onFailure:e=>console.error("Error loading recent files:",e)})))},[e]),ev=(0,s.useCallback)(async t=>{d(e=>{let r=e.filter(e=>e.path!==t);return[{path:t},...r].slice(0,15)}),await P.t4.runPromise((0,T.YW)(e,t).pipe(eT.sFT(e=>eT.OH5(()=>console.error("Error adding to recent files:",e))),eT.NWQ(()=>eT.rIH)))},[e]),ej=(0,s.useCallback)((t,r,n,s)=>{d(e=>e.map(e=>e.path===t?{...e,scrollLine:r,cursorLine:n,cursorCol:s}:e)),P.t4.runFork((0,T.YW)(e,t,{scrollLine:r,cursorLine:n,cursorCol:s}).pipe(eT.NWQ(()=>eT.rIH)))},[e]),ew=(0,s.useCallback)(e=>i.find(t=>t.path===e),[i]),ek=(0,s.useCallback)(async t=>{let r=t||c;r&&(J(!0),X(null),await P.t4.runPromise((0,T.eE)(e,r).pipe(eT.YWq({onSuccess:e=>{e.error?X(e.error):Q(e.blame??[])},onFailure:e=>{console.error("Error loading blame:",e),X("Failed to load blame info")}}))),J(!1))},[e,c]),ey=(0,s.useCallback)(async t=>{M(!0),x(null),V(!1),Q([]),X(null),ee(null);let r=eT.JkU(function*(){let r=yield*(0,T.r6)(e,t);if(!r.ok)return{type:"error",message:r.data?.error||"Failed to stat file"};let n=r.data??{};if(!n.exists)return{type:"error",message:"File not found"};if("dir"===n.kind)return{type:"error",message:"Path is a directory"};switch(n.category){case"image":return{type:"image",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}};case"pdf":return{type:"pdf",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}};case"too-large":return{type:"error",message:"File too large to preview",size:n.size,mtime:n.mtimeMs};default:{let r=yield*(0,$.K)(e,t);if(409===r.status)return{type:"binary",message:r.data?.error||"Cannot preview binary file",size:n.size,mtime:n.mtimeMs};if(!r.ok)return{type:"error",message:r.data?.error||"Failed to load file"};let s=r.data??{};return{type:"text",content:s.content,size:s.size,mtime:s.mtimeMs,...s.isSymlink?{isSymlink:!0,symlinkTarget:s.symlinkTarget}:{}}}}});await P.t4.runPromise(r.pipe(eT.YWq({onSuccess:e=>x(e),onFailure:e=>{console.error("Error loading file content:",e),x({type:"error",message:"Failed to load file"})}}))),ev(t),ek(t),M(!1)},[e,ev,ek]),eN=(0,s.useCallback)(()=>{q?V(!1):(V(!0),0===K.length&&ek())},[q,K.length,ek]),eC=(0,s.useCallback)((e,t)=>{if(!e)return;if(u(e),D(t??null),null==t){let t=i.find(t=>t.path===e);t?.scrollLine?(D(t.scrollLine),H("start"),W(t.cursorLine??null),z(t.cursorCol??null)):(H("center"),W(null),z(null))}else H("center"),W(null),z(null);ey(e);let r=e.split("/");if(r.length>1){let e=[];for(let t=1;t<r.length;t++)e.push(r.slice(0,t).join("/"));f(t=>{let r=new Set(t),n=!1;for(let t of e)r.has(t)||(r.add(t),n=!0);return n&&ex(r),n?r:t})}},[ey,ex,i]),eS=(0,s.useCallback)(e=>{if(p)g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r});else{let r=!h.has(e);if(f(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),ex(r),r}),r){let r=(0,U.MB)(t,e);r&&r.isDirectory&&!r.children&&ep(e)}}},[p,ex,h,t,ep]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:l,expandedPaths:h,setExpandedPaths:f,searchTreeExpandedPaths:p,setSearchTreeExpandedPaths:g,effectiveExpandedPaths:eu,searchQuery:b,setSearchQuery:v,searchExactMatch:j,setSearchDirExact:w,matchedPaths:ec,creatingItem:k,setCreatingItem:y,isLoadingFiles:N,fileError:L,searchInputRef:R,shouldScrollToSelected:I,setShouldScrollToSelected:F,targetLineNumber:B,setTargetLineNumber:D,targetScrollAlign:A,setTargetScrollAlign:H,initialCursorLine:O,initialCursorCol:_,setInitialCursorLine:W,setInitialCursorCol:z,selectedPath:c,setSelectedPath:u,fileContent:m,setFileContent:x,isLoadingContent:S,recentFiles:i,recentFilePaths:ea,setRecentFiles:d,recentFilesTree:ei,recentTreeDirPaths:ed,showBlame:q,setShowBlame:V,blameLines:K,isLoadingBlame:G,blameError:Y,blameSelectedCommit:Z,setBlameSelectedCommit:ee,previewMarkdown:et,setPreviewMarkdown:er,previewHtml:en,setPreviewHtml:es,showEditor:eo,setShowEditor:el,saveExpandedPaths:ex,loadFiles:eh,loadFileIndex:ef,loadDirectory:ep,loadRecentFiles:eb,addToRecentFiles:ev,updateRecentFilePosition:ej,getRecentFilePosition:ew,loadFileContent:ey,loadBlame:ek,handleToggleBlame:eN,handleSelectFile:eC,handleToggle:eS}}({cwd:t});u=tr.selectedPath,g=(0,s.useRef)(null),(0,s.useEffect)(()=>{u&&u!==g.current&&tz(u)&&(g.current=u,P.t4.runFork(tq("/api/lsp/warmup",{cwd:t,filePath:u}).pipe(eT.NLW).pipe(eT.NWQ(()=>eT.rIH))))},[t,u]);let tn=(0,s.useMemo)(()=>{let e=tr.fileContent,t=tr.selectedPath;return e&&"text"===e.type&&"string"==typeof e.content&&t&&(0,K.Hz)(t)?(0,K.xb)(e.content,K.cG):null},[tr.fileContent,tr.selectedPath]),[ts,to]=(0,s.useState)({version:0,collapsed:!1});(0,s.useEffect)(()=>{to(e=>e.collapsed?{version:e.version+1,collapsed:!1}:e)},[tr.selectedPath]);let tl=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,l]=(0,s.useState)([]),[a,i]=(0,s.useState)(!1),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(new Set),[x,h]=(0,s.useState)({caseSensitive:!1,wholeWord:!1,regex:!1,fileType:""}),[f,p]=(0,s.useState)(null),g=(0,s.useRef)(null),b=(0,s.useCallback)(async r=>{let n=r.trim();if(!n){l([]),p(null);return}if(n.length<2)return void c(t_.A.t("fileBrowser.searchMinChars"));i(!0),c(null);let s=new URLSearchParams({cwd:e,q:r,caseSensitive:String(x.caseSensitive),wholeWord:String(x.wholeWord),regex:String(x.regex),fileType:x.fileType}),o=eT.$mh({try:async()=>{let e=await fetch(`/api/files/search?${s}`),t=await e.json();if(t.error)throw Error(t.error);return t},catch:e=>new e$.uV({message:"content search failed",cause:e})});await P.t4.runPromise(o.pipe(eT.YWq({onSuccess:e=>{l(e.results),p({totalFiles:e.totalFiles,totalMatches:e.totalMatches,truncated:e.truncated}),m(new Set(e.results.map(e=>e.path))),e.results.length>0&&t?.()},onFailure:e=>{c(e.cause instanceof Error?e.cause.message:"Search failed"),l([])}}))),i(!1)},[e,x,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:a,searchError:d,searchExpandedPaths:u,searchOptions:x,setSearchOptions:h,searchStats:f,contentSearchInputRef:g,performContentSearch:b,handleSearchToggle:(0,s.useCallback)(e=>{m(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>eA(!0)}),ta=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(!1),[a,i]=(0,s.useState)(null),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(null),[x,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)(new Set),[g,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)([]),[w,k]=(0,s.useState)([]),y=(0,s.useMemo)(()=>{let e=new Set((0,H.Sz)(v));for(let t of f)e.delete(t);return e},[v,f]),N=(0,s.useMemo)(()=>{let e=new Set((0,H.Sz)(w));for(let t of g)e.delete(t);return e},[w,g]),[C,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)(0),E=(0,s.useCallback)(async()=>{l(!0),i(null),await P.t4.runPromise((0,R.lv)(e).pipe(eT.YWq({onSuccess:e=>{n(e);let t=(0,H.Do)(e.staged),r=(0,H.Do)(e.unstaged);j(t),k(r)},onFailure:e=>{i(e.cause instanceof Error?e.cause.message:"Unknown error")}}))),l(!1)},[e]),T=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),$=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),I=(0,s.useCallback)((e,r)=>{c({file:e,type:r}),t(e.path)},[t]),F=(0,s.useCallback)(async(e,t,r,n)=>{let s=await P.t4.runPromiseExit(e);"Success"===s._tag?(await E(),(0,q.oR)(t,"success")):(console.error(r,s.cause),(0,q.oR)(n,"error"))},[E]),B=(0,s.useCallback)(t=>F((0,R.Iz)(e,[t]),t_.A.t("toast.staged"),"Error staging file:",t_.A.t("toast.stageFailed")),[e,F]),D=(0,s.useCallback)(t=>F((0,R.X0)(e,[t]),t_.A.t("toast.unstaged"),"Error unstaging file:",t_.A.t("toast.unstageFailed")),[e,F]),A=(0,s.useCallback)(async t=>{0!==t.length&&await F((0,R.Iz)(e,t),t_.A.t("toast.stagedNFiles",{count:t.length}),"Error staging files:",t_.A.t("toast.stageFailed"))},[e,F]),O=(0,s.useCallback)(async t=>{0!==t.length&&await F((0,R.X0)(e,t),t_.A.t("toast.unstagedNFiles",{count:t.length}),"Error unstaging files:",t_.A.t("toast.unstageFailed"))},[e,F]),W=(0,s.useCallback)(async t=>{if(0===t.length)return;let r=t.filter(e=>"untracked"===e.status).map(e=>e.path),n=t.filter(e=>"untracked"!==e.status).map(e=>e.path),s=eT.JkU(function*(){r.length>0&&(yield*(0,R.Ub)(e,r,!0)),n.length>0&&(yield*(0,R.Ub)(e,n,!1))});await F(s,t_.A.t("toast.discardedNFiles",{count:t.length}),"Error discarding files:",t_.A.t("toast.discardFailed"))},[e,F]),_=(0,s.useCallback)(async()=>{r?.unstaged.length&&await F((0,R.Iz)(e,r.unstaged.map(e=>e.path)),t_.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"Error staging all files:",t_.A.t("toast.stageFailed"))},[e,r,F]),z=(0,s.useCallback)(async()=>{r?.staged.length&&await F((0,R.X0)(e,r.staged.map(e=>e.path)),t_.A.t("toast.unstagedNFiles",{count:r.staged.length}),"Error unstaging all files:",t_.A.t("toast.unstageFailed"))},[e,r,F]),V=(0,s.useCallback)(async t=>{let r="untracked"===t.status;await F((0,R.Ub)(e,[t.path],r),r?t_.A.t("toast.deletedFile"):t_.A.t("toast.discardedChanges"),"Error discarding file:",t_.A.t("toast.discardFailed"))},[e,F]),U=(0,s.useCallback)(async()=>{if(!r?.unstaged.length||!await (0,q.lJ)(t_.A.t("git.discardAllConfirm",{count:r.unstaged.length}),{danger:!0}))return;let t=r.unstaged.filter(e=>"untracked"===e.status).map(e=>e.path),n=r.unstaged.filter(e=>"untracked"!==e.status).map(e=>e.path),s=r.unstaged.length,o=eT.JkU(function*(){n.length>0&&(yield*(0,R.Ub)(e,n,!1)),t.length>0&&(yield*(0,R.Ub)(e,t,!0))});await F(o,t_.A.t("toast.discardedNFiles",{count:s}),"Error discarding all:",t_.A.t("toast.discardFailed"))},[e,r,F]);return(0,s.useEffect)(()=>{d?(h(!0),P.t4.runPromiseExit((0,R.w2)(e,d.file.path,d.type)).then(e=>{"Success"===e._tag?m(e.value):console.error("Error fetching diff:",e.cause),h(!1)})):m(null)},[d,e,M]),{status:r,setStatus:n,statusLoading:o,statusError:a,statusSelectedFile:d,statusDiff:u,statusDiffLoading:x,stagedExpandedPaths:y,unstagedExpandedPaths:N,stagedTree:v,setStagedTree:j,unstagedTree:w,setUnstagedTree:k,showStatusDiffPreview:C,setShowStatusDiffPreview:S,fetchStatus:E,handleStagedToggle:T,handleUnstagedToggle:$,handleStatusFileSelect:I,handleStage:B,handleUnstage:D,handleStageFiles:A,handleUnstageFiles:O,handleDiscardFiles:W,handleStageAll:_,handleUnstageAll:z,handleDiscardFile:V,handleDiscardAll:U,refreshDiff:(0,s.useCallback)(()=>L(e=>e+1),[])}}({cwd:t,addToRecentFiles:tr.addToRecentFiles}),ti=(0,s.useMemo)(()=>{let e=new Set;if(ta.status){for(let t of ta.status.staged)e.add(t.path);for(let t of ta.status.unstaged)e.add(t.path)}return e},[ta.status]),td=(0,s.useMemo)(()=>{let e=new Map;if(ta.status){for(let t of ta.status.staged)e.set(t.path,"staged");for(let t of ta.status.unstaged)e.set(t.path,"unstaged")}return e},[ta.status]),tu=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(""),[a,i]=(0,s.useState)([]),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)([]),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(new Set),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)(!1),[y,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)(!0),[E,T]=(0,s.useState)(!1),[$,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)(null),D=(0,s.useRef)(null),[A,O]=(0,s.useState)(null),[W,_]=(0,s.useState)(!1),[z,q]=(0,s.useState)(""),[V,K]=(0,s.useState)(""),[Q,G]=(0,s.useState)([]),[J,Y]=(0,s.useState)([]),[X,Z]=(0,s.useState)(new Set),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)(null),[es,eo]=(0,s.useState)(!1),[el,ea]=(0,s.useState)(!1),[ei,ed]=(0,s.useState)("worktree"),ec=(0,s.useRef)(W);ec.current=W;let eu=(0,s.useRef)(ei);eu.current=ei;let em=(0,s.useRef)(V);em.current=V;let ex=(0,s.useRef)(ee);ex.current=ee;let eh=(0,s.useCallback)(()=>{k(!0),B(null),P.t4.runPromise((0,R.r4)(e).pipe(eT.YWq({onSuccess:e=>{e.local&&e.current?(n(e),l(e.current),e.upstream&&q(e.upstream)):(B(t_.A.t("git.cannotGetBranches")),n(null))},onFailure:e=>{console.error(e),"NotFoundError"===e._tag?B(t_.A.t("git.notGitRepo")):B(t_.A.t("git.getBranchesFailed")),n(null)}}))).finally(()=>k(!1))},[e]),ef=(0,s.useCallback)(t=>{N(!0),c(null),m([]),h([]),b(null),j(null),L(!0),P.t4.runPromise((0,R.Bj)(e,t,U.B_).pipe(eT.YWq({onSuccess:e=>{let t=e.commits||[];i(t),L(t.length>=U.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>N(!1))},[e]),ep=(0,s.useCallback)(()=>{if(C||!M||!o)return;S(!0);let t=a.length;P.t4.runPromise((0,R.Bj)(e,o,U.B_,t).pipe(eT.YWq({onSuccess:e=>{let t=e.commits||[];t.length>0&&i(e=>[...e,...t]),L(t.length>=U.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>S(!1))},[e,o,a.length,C,M]),eg=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&ep()},[ep]),eb=(0,s.useCallback)(t=>{c(t),b(null),j(null),T(!0),P.t4.runPromise((0,R.Zi)(e,t.hash).pipe(eT.YWq({onSuccess:e=>{let t=e.files||[];m(t);let r=(0,H.Do)(t);h(r),p(new Set((0,H.Sz)(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>T(!1))},[e]),ev=(0,s.useCallback)(r=>{d&&(b(r),t(r.path),I(!0),P.t4.runPromise((0,R.Zi)(e,d.hash,r.path).pipe(eT.YWq({onSuccess:e=>j(e),onFailure:e=>{console.error(e)}}))).finally(()=>I(!1)))},[e,d,t]),ej=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ew=(0,s.useCallback)((t,r)=>{eo(!0),et(null),en(null),P.t4.runPromise((0,R.yy)(e,t,void 0,r??eu.current).pipe(eT.YWq({onSuccess:e=>{let t=e.files||[];G(t);let r=(0,H.Do)(t);Y(r),Z(new Set((0,H.Sz)(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>eo(!1))},[e]),ek=(0,s.useCallback)(r=>{et(r),t(r.path),ea(!0),P.t4.runPromise((0,R.yy)(e,V,r.path,eu.current).pipe(eT.YWq({onSuccess:e=>en(e),onFailure:e=>{console.error(e)}}))).finally(()=>ea(!1))},[e,V,t]),ey=(0,s.useCallback)(()=>{if(!ec.current||"worktree"!==eu.current)return;let t=em.current;if(!t)return;P.t4.runPromise((0,R.yy)(e,t,void 0,"worktree").pipe(eT.YWq({onSuccess:e=>{let t=e.files||[];G(t);let r=(0,H.Do)(t);Y(r),Z(e=>{let t=new Set(e);for(let n of(0,H.Sz)(r))e.has(n)||t.add(n);return t})},onFailure:e=>console.error(e)})));let r=ex.current;r&&P.t4.runPromise((0,R.yy)(e,t,r.path,"worktree").pipe(eT.YWq({onSuccess:e=>en(e),onFailure:e=>console.error(e)})))},[e]),eN=(0,s.useCallback)(e=>{if(eu.current===e)return;eu.current=e,ed(e);let t=em.current;ec.current&&t&&ew(t,e)},[ew]),eC=(0,s.useCallback)(e=>{Z(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eS=(0,s.useCallback)(e=>{if(_(e),e){let e="origin/main";K(e),ew(e)}else G([]),Y([]),et(null),en(null),K("")},[z,ew]);return{branches:r,selectedBranch:o,setSelectedBranch:l,commits:a,setCommits:i,selectedCommit:d,setSelectedCommit:c,historyFiles:u,historyFileTree:x,historyExpandedPaths:f,historySelectedFile:g,historyFileDiff:v,isLoadingBranches:w,isLoadingCommits:y,isLoadingMore:C,hasMoreCommits:M,setHasMoreCommits:L,isLoadingHistoryFiles:E,isLoadingHistoryDiff:$,historyError:F,commitListRef:D,tooltipPos:A,loadBranches:eh,loadCommits:ef,loadMoreCommits:ep,handleCommitListScroll:eg,handleSelectCommit:eb,handleSelectHistoryFile:ev,handleHistoryToggle:ej,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{O({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{O(null)},[]),compareMode:W,toggleCompareMode:eS,compareBaseBranch:V,setCompareBaseBranch:K,upstreamBranch:z,compareFiles:Q,compareFileTree:J,compareExpandedPaths:X,compareSelectedFile:ee,compareFileDiff:er,isLoadingCompareFiles:es,isLoadingCompareDiff:el,handleSelectCompareFile:ek,handleCompareToggle:eC,loadCompareFiles:ew,compareDiffMode:ei,setCompareDiffMode:eN,refreshCompare:ey}}({cwd:t,addToRecentFiles:tr.addToRecentFiles}),tm=tu.compareFileDiff,tx=tm?.filePath??"",th=(0,s.useMemo)(()=>{if(!tm||tm.isDeleted)return;let e={content:tm.newContent,filePath:tm.filePath};return(0,K.e$)(tm.filePath)?()=>e_(e):tm.filePath.endsWith(".json")?()=>eO(e):void 0},[tm]),tf=(0,s.useCallback)(()=>e_(null),[]),tp=(0,s.useCallback)(()=>eO(null),[]);(0,s.useEffect)(()=>{e_(null)},[tm]);let tg=(0,s.useCallback)(e=>{S?.sendMessage(C("worktree"===tu.compareDiffMode?"explain.compareFileWorktreeMessage":"explain.compareFileMessage",{base:tu.compareBaseBranch,path:e}))},[S,C,tu.compareBaseBranch,tu.compareDiffMode]),tb=(0,s.useRef)(!1),tv=(0,s.useCallback)(e=>{tr.setFileContent(t=>t?.type==="text"?{...t,content:e}:t),tr.showEditor||(tb.current=!0,tr.setShowEditor(!0))},[tr]);(0,s.useEffect)(()=>{tr.showEditor&&tb.current&&(eI.current?.markDirty(),tb.current=!1)},[tr.showEditor]);let tj=(0,s.useCallback)(e=>{tr.setShowEditor(!0)},[tr]),tw=(0,s.useCallback)(async()=>{if(!tr.fileContent||"text"!==tr.fileContent.type||!tr.fileContent.content)return;let e=await P.t4.runPromiseExit((0,T.OJ)({cwd:t,path:tr.selectedPath,content:tr.fileContent.content}));try{if("Failure"===e._tag||!e.value.ok)throw Error("Failed to save file");let t=e.value.data?.mtime;t&&tr.setFileContent(e=>e?.type==="text"?{...e,mtime:t}:e),(0,q.oR)(C("toast.savedSuccess"),"success")}catch{(0,q.oR)(C("toast.saveFailed"),"error")}},[t,tr]),tk=(0,s.useCallback)(()=>{if(!tr.selectedPath)return;let e=eL.current,t=eE.current;e>0&&tr.updateRecentFilePosition(tr.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[tr]),ty=(0,s.useCallback)(async(e,t)=>{let r=e!==tr.selectedPath;if(r&&tr.showEditor){if(eF.isDirty&&(!await (0,q.lJ)(C("fileBrowser.saveBeforeSwitch"),{confirmText:C("fileBrowser.saveAndSwitch"),cancelText:C("common.cancel")})||(await eI.current?.save(),eI.current?.isDirty)))return;tr.setShowEditor(!1)}r&&tk(),tr.handleSelectFile(e,t)},[tr,tk,eF.isDirty,C]),tN=(0,s.useMemo)(()=>{let e=tl.contentSearchResults;if(0===e.length)return{files:[],expandDirs:new Set,matchMap:new Map};let t=new Map,r=[];for(let n of e)t.set(n.path,n),r.push(n.path);let n=(0,U.v3)(r),s=new Set((0,U.tW)(n));return{files:n,expandDirs:s,matchMap:t}},[tl.contentSearchResults]),[tC,tS]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{tS(tN.expandDirs)},[tN.expandDirs]);let tM=(0,s.useCallback)(e=>{tS(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),tL=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=tN.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[tN.matchMap]),tE=eD&&tl.contentSearchResults.length>0,[tP,tT]=(0,s.useState)("selected");(0,s.useEffect)(()=>{tT("selected")},[tl.contentSearchResults]);let tR=!!tr.selectedPath&&null!==tz(tr.selectedPath),[tF,tA]=(0,s.useState)(!1),tO=(0,s.useCallback)(async(e,r)=>{if(!tr.selectedPath||!tR)return;let n=await e8.goToDefinition(tr.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=(0,tY.y)(t,s.file)||s.file;te.push({filePath:tr.selectedPath,lineNumber:eL.current}),o===tr.selectedPath?tr.setTargetLineNumber(s.line):ty(o,s.line)},[tr,t,tR,e8,te]),tW=(0,s.useCallback)((e,t,r,n,s)=>{e&&null!==tz(e)&&(tA(t),e9.onTokenMouseEnter(e,r,n,s))},[e9]),tV=(0,s.useCallback)((e,t,r)=>{tR&&tW(tr.selectedPath,!1,e,t,r)},[tr.selectedPath,tR,tW]),tU=(0,s.useCallback)(e=>{let r=(0,tY.y)(t,e.file)||e.file;tr.selectedPath&&te.push({filePath:tr.selectedPath,lineNumber:eL.current}),r===tr.selectedPath?tr.setTargetLineNumber(e.line):ty(r,e.line)},[tr,t,te]),tX=(0,s.useMemo)(()=>{if(!ta.status)return null;let e=new Map,t=e=>{switch(e){case"modified":default:return"M";case"added":case"untracked":return"A";case"deleted":return"D";case"renamed":return"R"}};for(let r of ta.status.staged)e.set(r.path,t(r.status));for(let r of ta.status.unstaged)e.set(r.path,t(r.status));return e},[ta.status]),tZ=(0,s.useMemo)(()=>{if(!ta.status)return null;let e=new Map;for(let t of ta.status.staged)"renamed"===t.status&&t.oldPath&&e.set(t.path,t.oldPath);return e},[ta.status]),t0=(0,s.useCallback)(e=>{en("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)},[tl.setContentSearchQuery,tl.performContentSearch]),t1=function({cwd:e,selectedPath:t,gitStatusMap:r,renameOldPaths:n,isText:o,refreshKey:l}){let a=t?r?.get(t):void 0,i=o&&("M"===a||"R"===a),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(()=>new Set),f=(0,s.useRef)(new Set),p=i&&!!t&&x.has(t);return(0,s.useEffect)(()=>{!t||f.current.has(t)||!r||o&&(f.current.add(t),i&&h(e=>new Set(e).add(t)))},[t,r,o,i]),(0,s.useEffect)(()=>{if(!p||!t)return void c(null);let r=!1;return m(!0),P.t4.runPromiseExit((0,R.w2)(e,t,"worktree",n?.get(t)).pipe(eT.fRP("explorer.treeFileDiff"))).then(e=>{r||("Success"===e._tag?c(e.value):(console.error("Error fetching tree file diff:",e.cause),c(null)),m(!1))}),()=>{r=!0}},[p,t,e,l,n]),{canDiff:i,showDiff:p,toggleDiff:(0,s.useCallback)(()=>{t&&h(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},[t]),diff:d,isLoadingDiff:u}}({cwd:t,selectedPath:tr.selectedPath,gitStatusMap:tX,renameOldPaths:tZ,isText:tr.fileContent?.type==="text",refreshKey:tr.fileContent?.mtime}),t2="tree"===er&&t1.showDiff;(0,s.useEffect)(()=>{ey(ej.current)},[]),(0,s.useEffect)(()=>{en(r)},[r,a]),(0,s.useEffect)(()=>{i&&(en("search"),tl.setContentSearchQuery(i),tl.performContentSearch(i))},[d]);let t5=(0,s.useCallback)(e=>{en(e),tr.setBlameSelectedCommit(null),"history"===e&&tu.selectedBranch&&tu.loadCommits(tu.selectedBranch)},[tr,tu.selectedBranch,tu.loadCommits]),t4=(0,s.useCallback)(()=>{if(!tr.selectedPath)return;let e={filePath:tr.selectedPath,lineNumber:eL.current},t=te.goBack(e);t&&(t.filePath===tr.selectedPath?tr.setTargetLineNumber(t.lineNumber):ty(t.filePath,t.lineNumber))},[tr,te]),t3=(0,s.useCallback)(()=>{if(!tr.selectedPath)return;let e={filePath:tr.selectedPath,lineNumber:eL.current},t=te.goForward(e);t&&(t.filePath===tr.selectedPath?tr.setTargetLineNumber(t.lineNumber):ty(t.filePath,t.lineNumber))},[tr,te]),t6=(0,s.useCallback)(async e=>{let r=e.split("/").pop()||e;"Success"===(await P.t4.runPromiseExit((0,T.__)({cwd:t,path:e})))._tag?(0,q.oR)(C("toast.copiedName",{name:r}),"success"):(0,q.oR)(C("toast.copyFailed"),"error")},[t,C]),t8=(0,s.useCallback)(async e=>{let r=await P.t4.runPromiseExit((0,T.dt)());if("Success"!==r._tag||!r.value.path)return void(0,q.oR)(C("toast.noFileToPaste"),"info");let n=r.value.path,s=await P.t4.runPromiseExit((0,T.Nn)({cwd:t,targetDir:e,sourceAbsPath:n}));if("Success"===s._tag)(0,q.oR)(C("toast.pastedFile",{name:s.value.newName}),"success"),tr.loadDirectory(e),tr.loadFileIndex();else{let e="Fail"===s.cause._tag?s.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:C("toast.pasteFailed");(0,q.oR)(r,"error")}},[t,tr,C]),t9=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===X;if(t.ctrlKey&&!t.metaKey&&"Minus"===t.code){if(t.preventDefault(),!r)return;t.shiftKey?t3():t4();return}if((t.metaKey||t.ctrlKey)&&"p"===t.key&&!t.shiftKey&&!t.altKey){t.preventDefault(),r?eM(e=>!e):(ee("explorer"),eM(!0));return}if(r&&(t.metaKey||t.ctrlKey)&&"c"===t.key&&!t.shiftKey){let e=t.target?.tagName,r=window.getSelection()?.toString();if(("tree"===er||"recent"===er)&&tr.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),t6(tr.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===er||"recent"===er)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),t8((0,U.S7)(tr.selectedPath,tr.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(eH){t.preventDefault(),e6.open();return}if(tr.previewMarkdown&&tr.selectedPath&&(0,K.Hz)(tr.selectedPath)){t.preventDefault(),e4.open();return}}if(r&&"Escape"===t.key){if(eS)return void eM(!1);if(e6.isVisible)return void e6.close();if(e4.isVisible)return void e4.close();if(eW)return void e_(null);if(eH)return void eO(null);let t=Date.now();if(t-t9.current<3e3)return;t9.current=t,e7.visible?e7.closeReferences():eD?eA(!1):tr.blameSelectedCommit?tr.setBlameSelectedCommit(null):tr.showBlame?tr.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,tr.showBlame,tr.blameSelectedCommit,tr,eS,e7.visible,e7.closeReferences,eD,t4,t3,e4,eH,eW,e6,er,t6,t8,X,ee]),(0,s.useEffect)(()=>{tr.loadFiles(),tr.loadFileIndex(),tr.loadRecentFiles(),ta.fetchStatus(),tu.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{ta.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[ta.fetchStatus]);let t7=(0,s.useRef)(tt),re=(0,s.useRef)(tt);(0,s.useEffect)(()=>{tt&&!re.current?re.current=!0:tt&&!t7.current&&(tr.loadFiles(),tr.loadFileIndex(),tr.loadRecentFiles(),ta.fetchStatus(),tu.loadBranches()),t7.current=tt},[tt]),(0,s.useEffect)(()=>{tu.selectedBranch&&tu.loadCommits(tu.selectedBranch)},[tu.selectedBranch,tu.loadCommits]);let rt=(0,s.useRef)(er),rr=(0,s.useRef)(!1);(0,s.useEffect)(()=>{let e=rt.current;if(rt.current=er,"tree"===er&&rr.current){rr.current=!1;return}if(("tree"===er||"recent"===er)&&tr.recentFiles.length>0){let t=tr.recentFiles[0].path;tr.selectedPath&&("status"!==e&&"history"!==e||tr.selectedPath===t)||(tr.setShouldScrollToSelected(!0),ty(t))}},[er,tr.recentFiles,tr.selectedPath,ty,tr]);let rn=(0,s.useRef)(tu.selectedBranch);rn.current=tu.selectedBranch;let rs=(0,s.useRef)(tr.selectedPath);rs.current=tr.selectedPath;let ro=(0,s.useRef)(tr.fileContent?.type);ro.current=tr.fileContent?.type;let rl=(0,s.useCallback)(async e=>{try{let{data:r}=e;if(!Array.isArray(r))return;let n=r.some(e=>"git"===e.type),s=r.some(e=>"file"===e.type),o=[];if((s||n)&&(o.push(P.t4.runPromise((0,T.mP)(t)).then(e=>{e.error||tr.setFiles(t=>(0,U.HR)(e.files??[],t))}).catch(()=>{})),o.push(P.t4.runPromise((0,T.DZ)(t)).then(e=>{e.paths&&tr.setFileIndex(e.paths)}).catch(()=>{})),o.push(P.t4.runPromise((0,T.r9)(t)).then(e=>{tr.setRecentFiles(e.files??[])}).catch(()=>{}))),n||s){o.push(P.t4.runPromise((0,R.lv)(t)).then(e=>{ta.setStatus(e);let t=(0,H.Do)(e.staged),r=(0,H.Do)(e.unstaged);ta.setStagedTree(t),ta.setUnstagedTree(r)}).catch(()=>{})),ta.refreshDiff(),tu.refreshCompare(),n&&tu.loadBranches();let e=rn.current;e&&o.push(P.t4.runPromise((0,R.Bj)(t,e,U.B_)).then(e=>{let t=e.commits??[];tu.setCommits(t),tu.setHasMoreCommits(t.length>=U.B_)}).catch(()=>{}))}let l=rs.current,a=ro.current;l&&"text"===a&&o.push(P.t4.runPromise((0,$.K)(t,l)).then(e=>{let t=e.ok?e.data:null;t&&"string"==typeof t.content&&tr.setFileContent({type:"text",content:t.content,size:t.size,mtime:t.mtimeMs,...t.isSymlink?{isSymlink:!0,symlinkTarget:t.symlinkTarget}:{}})}).catch(()=>{})),await Promise.all(o)}catch(e){console.error("File watch handler error:",e)}},[t]);(0,eb.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:rl,enabled:tt});let ra=(0,s.useCallback)(e=>{ty(e),tr.setShouldScrollToSelected(!0),en("tree")},[tr,ty]),ri=(0,s.useRef)(ty);(0,s.useEffect)(()=>{ri.current=ty},[ty]);let rd=(0,s.useRef)(null),{setPreviewMarkdown:rc,setPreviewHtml:ru,setShouldScrollToSelected:rm}=tr;(0,s.useEffect)(()=>{!c||tr.isLoadingFiles||rd.current!==c.nonce&&(rd.current=c.nonce,rr.current=!0,ep("code"),en("tree"),ru(!1),null!=c.lineNumber&&rc(!1),ri.current(c.path,c.lineNumber),rm(!0))},[c,tr.isLoadingFiles,rc,ru,rm]);let rx=(0,s.useCallback)(({focalFile:e})=>e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${t}/${e}`),(0,q.oR)(C("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:C("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ra(e)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:C("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]}),[t,ra,C]),rh=(0,s.useCallback)(({focalFile:e})=>"tree"===er&&t1.canDiff&&e===tr.selectedPath?(0,n.jsxs)(n.Fragment,{children:[t1.showDiff&&(0,n.jsx)(D.y,{value:eK,onChange:eQ}),(0,n.jsx)("button",{onClick:t1.toggleDiff,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${t1.showDiff?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,title:t1.showDiff?C("fileBrowser.exitDiff"):C("fileBrowser.viewDiff"),children:C("common.diff")})]}):null,[er,t1.canDiff,t1.showDiff,t1.toggleDiff,tr.selectedPath,eK,C]),[rf,rp]=(0,s.useState)(null),rg=(0,s.useCallback)((e,t)=>{tr.setPreviewMarkdown(!0),tr.setPreviewHtml(!1),ra(e),rp(t),t&&setTimeout(()=>rp(null),400)},[tr,ra]);return(0,n.jsxs)(et.SU,{container:ek,children:[(0,n.jsxs)("div",{ref:ej,className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:eY},children:[(0,n.jsxs)("div",{className:"flex border-b border-border",children:[(0,n.jsx)("button",{onClick:()=>t5("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===er?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:C("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>t5("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===er?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:C("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>t5("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===er?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:C("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>t5("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===er?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:C("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>t5("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===er?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:C("fileBrowser.historyTab")})]}),"tree"===er&&(0,n.jsxs)("div",{className:"p-2 border-b border-border flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:tr.searchInputRef,type:"text",value:tr.searchQuery,onChange:e=>tr.setSearchQuery(e.target.value),placeholder:C("fileBrowser.searchFiles"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),tr.searchQuery&&(0,n.jsx)("button",{onClick:()=>{tr.setSearchQuery(""),tr.searchInputRef.current?.focus()},className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:C("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>tr.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${tr.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:tr.searchExactMatch?C("fileBrowser.exactMatchOn"):C("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>tr.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:C("fileBrowser.refreshTree"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"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,n.jsx)("button",{onClick:()=>tr.searchTreeExpandedPaths?tr.setSearchTreeExpandedPaths(new Set):tr.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:C("fileBrowser.collapseAll"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})]})]}),"search"===er&&(0,n.jsxs)("div",{className:"p-2 border-b border-border space-y-2",children:[(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:tl.contentSearchInputRef,type:"text",value:tl.contentSearchQuery,onChange:e=>tl.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&tl.performContentSearch(tl.contentSearchQuery)},placeholder:C("fileBrowser.searchFileContent"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),tl.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>{tl.setContentSearchQuery(""),tl.contentSearchInputRef.current?.focus()},className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:C("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>tl.performContentSearch(tl.contentSearchQuery),disabled:tl.isSearching||!tl.contentSearchQuery.trim(),className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",children:tl.isSearching?"...":C("common.search")})]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 text-xs",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:tl.searchOptions.caseSensitive,onChange:e=>tl.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:C("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:tl.searchOptions.wholeWord,onChange:e=>tl.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:C("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:tl.searchOptions.regex,onChange:e=>tl.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:C("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:tl.searchOptions.fileType,onChange:e=>tl.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:C("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground"})]})]}),"history"===er&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:tu.compareMode?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 px-3 py-1.5 text-sm border border-border rounded bg-secondary text-foreground flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:tu.branches?.current||"HEAD"}),(0,n.jsx)("div",{className:"flex flex-shrink-0 items-center rounded border border-border overflow-hidden text-xs",children:["head","worktree"].map(e=>(0,n.jsx)("button",{onClick:()=>tu.setCompareDiffMode(e),className:`px-1.5 py-0.5 transition-colors ${tu.compareDiffMode===e?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:C("head"===e?"fileBrowser.compareScopeHeadHint":"fileBrowser.compareScopeWorktreeHint"),children:C("head"===e?"fileBrowser.compareScopeHead":"fileBrowser.compareScopeWorktree")},e))})]}),(0,n.jsx)("button",{onClick:()=>tu.toggleCompareMode(!1),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors bg-brand text-white",title:C("fileBrowser.compareModeOff"),children:C("fileBrowser.compareMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0 pl-1",children:"vs"}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(tD,{branches:tu.branches,selectedBranch:tu.compareBaseBranch,onSelect:e=>{tu.setCompareBaseBranch(e),tu.loadCompareFiles(e)},isLoading:tu.isLoadingBranches,pinnedBranches:["origin/main",...tu.upstreamBranch&&"origin/main"!==tu.upstreamBranch?[tu.upstreamBranch]:[]]})})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(tD,{branches:tu.branches,selectedBranch:tu.selectedBranch,onSelect:e=>{tu.setSelectedBranch(e)},isLoading:tu.isLoadingBranches,pinnedBranches:["origin/main",...tu.upstreamBranch&&"origin/main"!==tu.upstreamBranch?[tu.upstreamBranch]:[]]})}),(0,n.jsx)("button",{onClick:()=>tu.toggleCompareMode(!0),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors text-muted-foreground hover:text-foreground hover:bg-hover border border-border",title:C("fileBrowser.compareModeOn"),children:C("fileBrowser.compareMode")})]})}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,n.jsxs)("div",{className:`flex-1 flex flex-col min-h-0 ${"tree"===er?"":"hidden"}`,children:[tr.creatingItem&&(0,n.jsxs)("div",{className:"px-2 py-1.5 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:tr.creatingItem.parentPath?C("fileBrowser.createFileIn",{path:tr.creatingItem.parentPath}):C("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:C("fileBrowser.fileName"),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring",onCompositionStart:()=>{ew.current=!0},onCompositionEnd:()=>{ew.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if(ew.current)return;let r=e.target.value.trim();if(!r)return;let n=tr.creatingItem.parentPath,s=n?`${n}/${r}`:r,o=await P.t4.runPromiseExit((0,T.OJ)({cwd:t,path:s,content:""}));if("Success"===o._tag&&o.value.ok)(0,q.oR)(C("toast.createdFile",{name:r}),"success"),tr.setCreatingItem(null),tr.loadDirectory(n),tr.loadFileIndex(),n&&tr.setExpandedPaths(e=>new Set([...e,n])),ty(s);else if("Success"===o._tag){let e=o.value.data?.error;(0,q.oR)(e||C("toast.createFailed"),"error")}else(0,q.oR)(C("toast.createFailed"),"error")}else"Escape"===e.key&&tr.setCreatingItem(null)},onBlur:()=>tr.setCreatingItem(null)})]}),tr.isLoadingFiles&&0===tr.files.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:C("common.loading")}):tr.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:tr.fileError}):(0,n.jsx)(eo,{files:tr.files,selectedPath:tr.selectedPath,expandedPaths:tr.effectiveExpandedPaths,matchedPaths:tr.matchedPaths,gitStatusMap:tX,loadingDirs:tr.loadingDirs,onSelect:e=>{tr.setShouldScrollToSelected(!1),ty(e)},onToggle:tr.handleToggle,cwd:t,shouldScrollToSelected:tr.shouldScrollToSelected,onScrolledToSelected:()=>tr.setShouldScrollToSelected(!1),onCreateFile:e=>tr.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>eC({path:e,isDirectory:t,name:r}),onRefresh:()=>tr.loadFiles(),onCopyFile:t6,onPaste:t8,onExplain:S?M:void 0,explainDisabled:S?.isLoading})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===er?"":"hidden"}`,children:tl.isSearching?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):tl.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:tl.searchError}):0===tl.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:tl.contentSearchQuery?C("fileBrowser.noContentSearchResults"):C("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[tl.searchStats&&(0,n.jsxs)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground border-b border-border flex-shrink-0",children:[C("fileBrowser.nFilesNMatches",{files:tl.searchStats.totalFiles,matches:tl.searchStats.totalMatches}),tl.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",C("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(eo,{files:tN.files,selectedPath:tr.selectedPath,expandedPaths:tC,onSelect:e=>{let t=tN.matchMap.get(e);ty(e,t?.matches[0]?.lineNumber),eD||eA(!0)},onToggle:tM,cwd:t,onExplain:S?M:void 0,explainDisabled:S?.isLoading,renderActions:tL,className:"flex-1 overflow-y-auto py-1 min-w-max"})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"recent"===er?"":"hidden"}`,children:0===tr.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:C("fileBrowser.noRecentFiles")}):(0,n.jsx)(eo,{files:tr.recentFilesTree,selectedPath:tr.selectedPath,expandedPaths:tr.recentTreeDirPaths,onSelect:ty,onToggle:U.tE,cwd:t,onExplain:S?M:void 0,explainDisabled:S?.isLoading})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===er?"":"hidden"}`,children:ta.statusLoading?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ta.statusError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center p-4",children:(0,n.jsx)("span",{className:"text-red-11 text-sm",children:ta.statusError})}):(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:C("fileBrowser.stagingArea",{count:ta.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>ta.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:C("fileBrowser.refreshChanges"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 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"})})}),ta.status&&ta.status.staged.length>0&&(0,n.jsx)(H.ab,{files:ta.status.staged,className:"ml-1"})]}),(ta.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:ta.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:C("fileBrowser.unstageAll")})]}),(0,n.jsx)(H.VO,{files:ta.stagedTree,selectedPath:ta.statusSelectedFile?.type==="staged"?ta.statusSelectedFile.file.path:null,expandedPaths:ta.stagedExpandedPaths,onSelect:e=>e.file&&ta.handleStatusFileSelect(e.file,"staged"),onToggle:ta.handleStagedToggle,cwd:t,showChanges:!0,showChangeClass:!0,hideIndicatorsOnHover:!0,emptyMessage:C("fileBrowser.noStagedFiles"),className:"py-1",onExplain:S?F:void 0,explainDisabled:S?.isLoading,renderActions:e=>{if(e.isDirectory){let t=(0,H.wI)(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ta.handleUnstageFiles(t.map(e=>e.path))},className:"hidden group-hover:block p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-colors",title:C("fileBrowser.unstageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}return(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ta.handleUnstage(e.path)},className:"hidden group-hover:block p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-colors",title:C("fileBrowser.unstageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:C("fileBrowser.workspace",{count:ta.status?.unstaged.length||0})}),ta.status&&ta.status.unstaged.length>0&&(0,n.jsx)(H.ab,{files:ta.status.unstaged,className:"ml-1"})]}),(ta.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:ta.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:C("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:ta.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:C("fileBrowser.stageAll")})]})]}),(0,n.jsx)(H.VO,{files:ta.unstagedTree,selectedPath:ta.statusSelectedFile?.type==="unstaged"?ta.statusSelectedFile.file.path:null,expandedPaths:ta.unstagedExpandedPaths,onSelect:e=>e.file&&ta.handleStatusFileSelect(e.file,"unstaged"),onToggle:ta.handleUnstagedToggle,cwd:t,showChanges:!0,showChangeClass:!0,hideIndicatorsOnHover:!0,emptyMessage:C("fileBrowser.noUnstagedChanges"),className:"py-1",onExplain:S?O:void 0,explainDisabled:S?.isLoading,renderActions:e=>{if(e.isDirectory){let t=(0,H.wI)(e);if(0===t.length)return null;let r=t.map(e=>e.file).filter(Boolean);return(0,n.jsxs)("div",{className:"hidden group-hover:flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ta.handleDiscardFiles(r)},className:"p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-colors",title:C("fileBrowser.discardNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ta.handleStageFiles(t.map(e=>e.path))},className:"p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-colors",title:C("fileBrowser.stageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]})}return e.file?(0,n.jsxs)("div",{className:"hidden group-hover:flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ta.handleDiscardFile(e.file)},className:"p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-colors",title:C("fileBrowser.discardChanges"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ta.handleStage(e.path)},className:"p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-colors",title:C("fileBrowser.stageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]}):null}})]})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"history"===er?"":"hidden"}`,children:tu.historyError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-foreground-faint mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,n.jsx)("p",{className:"text-muted-foreground",children:tu.historyError})]})}):tu.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden",children:tu.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:C("fileBrowser.loadingDiff")}):0===tu.compareFiles.length?(0,n.jsxs)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:[(0,n.jsx)("div",{children:C("fileBrowser.noDiffFiles")}),"head"===tu.compareDiffMode&&(0,n.jsx)("button",{onClick:()=>tu.setCompareDiffMode("worktree"),className:"mt-2 text-xs text-brand hover:underline",children:C("fileBrowser.noDiffFilesHeadHint")})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(H.WY,{files:tu.compareFiles,label:C("worktree"===tu.compareDiffMode?"fileBrowser.nFilesChangedWorktree":"fileBrowser.nFilesChanged",{count:tu.compareFiles.length,branch:tu.compareBaseBranch})}),(0,n.jsx)(H.VO,{files:tu.compareFileTree,expandedPaths:tu.compareExpandedPaths,onToggle:tu.handleCompareToggle,selectedPath:tu.compareSelectedFile?.path||null,onSelect:e=>{e.file&&tu.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0,showChangeClass:!0,onExplain:S?tg:void 0,explainDisabled:S?.isLoading})]})}):(0,n.jsx)("div",{ref:tu.commitListRef,className:"flex-1 overflow-y-auto",onScroll:tu.handleCommitListScroll,children:tu.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:C("fileBrowser.loadingCommits")}):0===tu.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:C("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[tu.commits.map(e=>(0,n.jsxs)("div",{onClick:()=>tu.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-hover ${tu.selectedCommit?.hash===e.hash?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[e.changeClass&&(0,n.jsx)(E.N,{cls:e.changeClass}),(0,n.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),(0,n.jsxs)("span",{className:"text-xs text-foreground-subtle","data-tooltip":e.date,children:[e.relativeDate," \xb7 ",(0,U.r6)(e.date)]})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5","data-tooltip":e.subject,children:e.subject}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.author})]},e.hash)),tu.isLoadingMore&&(0,n.jsx)("div",{className:"p-3 text-center",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),!tu.hasMoreCommits&&tu.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-foreground-subtle",children:C("fileBrowser.allLoaded",{count:tu.commits.length})})]})})})]})]}),(0,n.jsx)("div",{onPointerDown:e0,onPointerMove:e1,onPointerUp:e2,onPointerCancel:e2,className:"w-[5px] flex-shrink-0 relative cursor-col-resize group",children:(0,n.jsx)("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border group-hover:bg-brand transition-colors"})}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[("tree"===er||"search"===er||"recent"===er)&&(tr.blameSelectedCommit?(0,n.jsx)(Z,{isOpen:!0,onClose:()=>tr.setBlameSelectedCommit(null),commit:tr.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:tr.selectedPath||void 0,onLocateInTree:ra,onContentSearch:e=>{en("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}}):"map"===es?t2&&t1.diff?(0,n.jsx)(t$,{cwd:t,filePath:t1.diff.filePath,oldContent:t1.diff.oldContent,newContent:t1.diff.newContent,isNew:t1.diff.isNew,isDeleted:t1.diff.isDeleted,changedFiles:ti,fileGitStatusMap:td,compact:"compact"===eK,enableComments:!0,onSwitchToCode:()=>ep("code"),onContentSearch:t0,headerExtraLeft:rx,headerExtraRight:rh}):(0,n.jsx)(tc,{cwd:t,highlightedFilePath:tr.selectedPath,changedFiles:ti,onSwitchToCode:()=>ep("code"),enableComments:!0,onContentSearch:t0,headerExtraLeft:rx,headerExtraRight:rh}):tr.selectedPath?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 border-b border-border flex-shrink-0 flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate",children:tr.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${tr.selectedPath}`),(0,q.oR)(C("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:C("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ra(tr.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:C("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:tr.showEditor?(0,n.jsxs)(n.Fragment,{children:[eF.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:C("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>eI.current?.save(),disabled:!eF.isDirty||eF.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${eF.isDirty&&!eF.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:eF.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):C("common.save")}),(0,n.jsx)("button",{onClick:()=>eI.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:C("fileBrowser.closeEdit"),children:C("fileBrowser.closeBtn")})]}):t2?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(D.y,{value:eK,onChange:eQ}),(0,n.jsx)(A.q,{value:eG,onChange:eJ}),!(0,K.e$)(tr.selectedPath)&&!(0,K.aR)(tr.selectedPath)&&!(0,K.Hz)(tr.selectedPath)&&!(0,K.Zy)(tr.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ep("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:C("blockViewer.viewerToggle.toBlock"),children:C("common.codeMap")}),(0,n.jsx)("button",{onClick:t1.toggleDiff,className:"px-1.5 py-0.5 text-xs rounded transition-colors bg-brand text-white",children:C("fileBrowser.exitDiff")})]}):(0,n.jsxs)(n.Fragment,{children:["tree"===er&&t1.canDiff&&(0,n.jsx)("button",{onClick:t1.toggleDiff,className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:C("fileBrowser.viewDiff"),children:C("common.diff")}),tr.fileContent?.type==="text"&&(0,K.Hz)(tr.selectedPath)&&tr.previewMarkdown&&!tr.showBlame&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:[!0,!1].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),to(t=>({version:t.version+1,collapsed:e}))},className:`px-2 py-0.5 text-xs transition-colors ${ts.collapsed===e?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:C(e?"fileBrowser.collapseAllJson":"fileBrowser.expandAllJson")},String(e)))}),tr.fileContent?.type==="text"&&((0,K.e$)(tr.selectedPath)||(0,K.aR)(tr.selectedPath)||(0,K.Hz)(tr.selectedPath)||(0,K.Zy)(tr.selectedPath))&&(v=(b=(0,K.aR)(tr.selectedPath))?tr.previewHtml:tr.previewMarkdown,(0,n.jsx)("button",{onClick:()=>b?tr.setPreviewHtml(e=>!e):tr.setPreviewMarkdown(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${v?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:v?C("fileBrowser.exitPreview"):C("common.preview")})),tr.fileContent?.type==="text"&&((0,K.C_)(tr.selectedPath||"")||(0,K.OG)(tr.selectedPath||""))&&(w=(j=tr.selectedPath||"").startsWith("/")?j:t?`${t.replace(/\/$/,"")}/${j}`:j,k=(0,K.OG)(j),(0,n.jsx)("button",{onClick:()=>void(k?Y(w):z(w)),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:C(k?"bots.addTooltip":"skills.addTooltip"),children:(0,n.jsx)(ei.A,{className:"w-3.5 h-3.5"})})),tr.fileContent?.type==="text"&&(0,K.aR)(tr.selectedPath)&&(N=(y=tr.selectedPath||"").startsWith("/")?y:t?`${t.replace(/\/$/,"")}/${y}`:y,(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>W(N),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:C("htmlApps.addTooltip"),children:(0,n.jsx)(ei.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>window.dispatchEvent(new CustomEvent("console-open-browser",{detail:{url:N}})),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:C("common.openInConsole"),children:(0,n.jsx)(ed.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>{let e=(0,eu.Xe)(N);window.open((0,eu.PB)(e,window.location.origin),"_blank")},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:C("browser.openInNewWindow"),children:(0,n.jsx)(ec.A,{className:"w-3.5 h-3.5"})})]})),tr.fileContent?.type==="text"&&!(tr.previewMarkdown&&((0,K.e$)(tr.selectedPath)||(0,K.Hz)(tr.selectedPath)||(0,K.Zy)(tr.selectedPath))||tr.previewHtml&&(0,K.aR)(tr.selectedPath))&&(0,n.jsx)("button",{onClick:tr.handleToggleBlame,disabled:tr.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${tr.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-hover"} disabled:opacity-50`,title:C("fileBrowser.viewBlame"),children:tr.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),tr.fileContent?.type==="text"&&!(tr.previewMarkdown&&((0,K.e$)(tr.selectedPath)||(0,K.Hz)(tr.selectedPath)||(0,K.Zy)(tr.selectedPath))||tr.previewHtml&&(0,K.aR)(tr.selectedPath))&&(0,n.jsx)("button",{onClick:()=>tr.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:C("fileBrowser.editFile"),children:C("common.edit")}),tr.fileContent?.type==="text"&&tr.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(tr.fileContent.content),(0,q.oR)(C("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:C("fileBrowser.copyFileContent"),children:C("common.copy")}),tr.fileContent?.type==="text"&&!(0,K.e$)(tr.selectedPath)&&!(0,K.aR)(tr.selectedPath)&&!(0,K.Hz)(tr.selectedPath)&&!(0,K.Zy)(tr.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ep("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:C("blockViewer.viewerToggle.toBlock"),children:C("common.codeMap")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:tr.isLoadingContent?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):tr.fileContent?"text"===tr.fileContent.type&&"string"==typeof tr.fileContent.content?t2?t1.isLoadingDiff&&!t1.diff?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):t1.diff?"unified"===eG?(0,n.jsx)(I.xU,{oldContent:t1.diff.oldContent,newContent:t1.diff.newContent,filePath:t1.diff.filePath,cwd:t,enableComments:!0,compact:"compact"===eK,onContentSearch:t0,onTokenHover:(e,t,r)=>tW(t1.diff?.filePath,!0,e,t,r),onTokenHoverLeave:e9.onTokenMouseLeave,onTokenHoverCancel:e9.clearHover}):(0,n.jsx)(I.xZ,{oldContent:t1.diff.oldContent,newContent:t1.diff.newContent,filePath:t1.diff.filePath,isNew:t1.diff.isNew,isDeleted:t1.diff.isDeleted,cwd:t,enableComments:!0,compact:"compact"===eK,onContentSearch:t0,onTokenHover:(e,t,r)=>tW(t1.diff?.filePath,!0,e,t,r),onTokenHoverLeave:e9.onTokenMouseLeave,onTokenHoverCancel:e9.clearHover}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{children:C("fileBrowser.diffLoadFailed")}),(0,n.jsx)("button",{onClick:t1.toggleDiff,className:"mt-2 text-brand hover:underline text-sm",children:C("fileBrowser.exitDiff")})]})}):tr.showBlame&&tr.blameError?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-red-11",children:tr.blameError}),(0,n.jsx)("button",{onClick:()=>tr.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:C("fileBrowser.backToPreview")})]})}):tr.showBlame&&0===tr.blameLines.length&&tr.isLoadingBlame?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):tr.previewMarkdown&&(0,K.Hz)(tr.selectedPath)&&!tr.showBlame?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-background text-foreground",children:[(0,n.jsx)(Q._,{search:e4}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:e5,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:(0,n.jsx)(K.d9.Provider,{value:ts,children:tn})})})]}):tr.previewMarkdown&&(0,K.Zy)(tr.selectedPath)&&!tr.showBlame?(0,n.jsx)(ea.C0,{content:tr.fileContent.content,filePath:tr.selectedPath,className:"h-full"}):tr.previewMarkdown&&(0,K.e$)(tr.selectedPath)&&!tr.showBlame?(0,n.jsx)("div",{className:"h-full flex flex-col",children:(0,n.jsx)(B.M,{content:tr.fileContent.content,filePath:tr.selectedPath,cwd:t,embedded:!0,onLocalFileLink:rg,scrollToAnchor:rf})}):tr.previewHtml&&(0,K.aR)(tr.selectedPath)&&!tr.showBlame?(0,n.jsx)(ef.O,{content:tr.fileContent.content,filePath:tr.selectedPath,cwd:t,onContentSearch:e=>{en("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}}):(0,n.jsx)(el.Cv,{ref:eI,content:tr.fileContent.content,filePath:tr.selectedPath,cwd:t,enableComments:!0,scrollToLine:eP??tr.targetLineNumber,scrollToLineAlign:null!=eP?"start":tr.targetScrollAlign,onScrollToLineComplete:()=>{eR(null),tr.setTargetLineNumber(null)},highlightKeyword:"search"===er?tl.contentSearchQuery:null,visibleLineRef:eL,viStateRef:eE,initialCursorLine:tr.initialCursorLine,initialCursorCol:tr.initialCursorCol,onInitialCursorSet:()=>{tr.setInitialCursorLine(null),tr.setInitialCursorCol(null)},onCmdClick:tR?tO:void 0,onTokenHover:tR?tV:void 0,onTokenHoverLeave:tR?e9.onTokenMouseLeave:void 0,onTokenHoverCancel:tR?e9.clearHover:void 0,blameLines:tr.showBlame&&tr.blameLines.length>0?tr.blameLines:void 0,inlineBlameLines:tr.blameLines.length>0?tr.blameLines:void 0,onSelectCommit:tr.setBlameSelectedCommit,editable:tr.showEditor,initialMtime:tr.fileContent.mtime,onEditorClose:e=>{tr.setShowEditor(!1),eR(e)},onSaved:()=>{let e=eL.current??1;tr.loadFileContent(tr.selectedPath),tr.setShowEditor(!1),eR(e)},onEditorStateChange:eB,viMode:!0,onContentMutate:tv,onEnterInsertMode:tj,onViSave:tw,onContentSearch:e=>{en("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}}):"image"===tr.fileContent.type&&tr.selectedPath?(0,n.jsx)(tI.I,{cwd:t,path:tr.selectedPath,refreshKey:tr.fileContent.mtime,alt:tr.selectedPath}):"pdf"===tr.fileContent.type&&tr.selectedPath?(0,n.jsx)(tH,{cwd:t,path:tr.selectedPath,refreshKey:tr.fileContent.mtime}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-foreground-faint mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("p",{children:tr.fileContent.message||C("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:C("fileBrowser.selectFileToPreview")})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-foreground-faint mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsx)("p",{children:C("fileBrowser.selectFileToPreview")})]})})),"status"===er&&(ta.statusSelectedFile&&ta.statusDiff?(0,n.jsx)(tB,{cwd:t,selected:ta.statusSelectedFile,diff:ta.statusDiff,showMarkdownPreview:ta.showStatusDiffPreview,setShowMarkdownPreview:ta.setShowStatusDiffPreview,changedFiles:ti,fileGitStatusMap:td,onContentSearch:e=>{en("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)},locateInTree:ra,setJsonPreview:eO,onTokenHover:(e,t,r)=>tW(ta.statusDiff?.filePath,!0,e,t,r),onTokenHoverLeave:e9.onTokenMouseLeave,onTokenHoverCancel:e9.clearHover}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-foreground-subtle",children:(0,n.jsx)("span",{children:C("fileBrowser.selectFileToViewDiff")})})),"history"===er&&!tu.historyError&&(tu.compareMode?tu.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:C("fileBrowser.loadingDiffContent")}):tu.compareFileDiff?(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border flex-shrink-0",children:[(0,n.jsx)(V,{cwd:t,filePath:tu.compareFileDiff.filePath,onLocateInTree:ra}),!(0,U.u)(tu.compareFileDiff.filePath)&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[(0,n.jsx)(D.y,{value:ez,onChange:eq}),(0,n.jsx)(A.q,{value:eV,onChange:eU})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,U.u)(tu.compareFileDiff.filePath)?(0,n.jsx)(_,{cwd:t,filePath:tu.compareFileDiff.filePath,oldRev:tu.compareFileDiff.oldRev??(tu.compareFileDiff.isNew?null:tu.compareBaseBranch),newRev:"worktree"===tu.compareDiffMode?null:tu.compareFileDiff.newRev??(tu.compareFileDiff.isDeleted?null:"HEAD"),newNode:tu.compareFileDiff.newWorktree?(0,n.jsx)(tI.I,{cwd:t,path:tu.compareFileDiff.filePath}):void 0}):"unified"===eV?(0,n.jsx)(I.xU,{oldContent:tu.compareFileDiff.oldContent,newContent:tu.compareFileDiff.newContent,filePath:tu.compareFileDiff.filePath,cwd:t,enableComments:!0,compact:"compact"===ez,onPreview:th,previewLabel:tx.endsWith(".json")?C("common.readable"):C("common.preview"),onContentSearch:e=>{en("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}}):(0,n.jsx)(I.xZ,{oldContent:tu.compareFileDiff.oldContent,newContent:tu.compareFileDiff.newContent,filePath:tu.compareFileDiff.filePath,isNew:tu.compareFileDiff.isNew,isDeleted:tu.compareFileDiff.isDeleted,cwd:t,enableComments:!0,compact:"compact"===ez,onPreview:th,previewLabel:tx.endsWith(".json")?C("common.readable"):C("common.preview"),onContentSearch:e=>{en("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}})}),eW&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:()=>e_(null),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(B.M,{content:eW.content,filePath:eW.filePath,cwd:t,onClose:tf})})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-foreground-subtle",children:(0,n.jsx)("span",{children:tu.compareFiles.length>0?C("fileBrowser.selectFileToViewDiff"):C("fileBrowser.clickCompareToLoad")})}):tu.selectedCommit?(0,n.jsx)(Z,{isOpen:!0,onClose:()=>tu.setSelectedCommit(null),commit:tu.selectedCommit,cwd:t,embedded:!0,onLocateInTree:ra,onContentSearch:e=>{en("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-foreground-subtle",children:(0,n.jsx)("span",{children:C("fileBrowser.selectCommitToView")})})),eH&&(0,n.jsx)(G,{preview:eH,onClose:tp,search:e6,preRef:e3})]})]}),eS&&(0,n.jsx)(eg,{files:tr.files,fileIndex:tr.fileIndex,recentFiles:tr.recentFilePaths,onSelectFile:e=>{ty(e),tr.setShouldScrollToSelected(!0),en("tree")},onClose:()=>eM(!1)}),(tE||e7.visible)&&(0,n.jsxs)("div",{className:`flex ${e7.visible&&tE?"":"flex-col"}`,children:[tE&&(0,n.jsx)("div",{className:e7.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(tG,{results:tl.contentSearchResults,loading:tl.isSearching,totalMatches:tl.searchStats?.totalMatches??0,onSelect:(e,t)=>{tr.selectedPath&&te.push({filePath:tr.selectedPath,lineNumber:eL.current}),ep("code"),ty(e,t)},onClose:()=>eA(!1),scope:tP,onScopeChange:tT,selectedPath:tr.selectedPath})}),e7.visible&&(0,n.jsx)("div",{className:tE?"flex-1 min-w-0":"",children:(0,n.jsx)(tQ,{references:e7.references,loading:e7.loading,onSelect:tU,onClose:e7.closeReferences})})]})]}),eN&&(0,n.jsx)(l.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim",onClick:()=>eC(null),children:(0,n.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-lv3 p-4 max-w-sm w-full mx-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-2",children:C("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:C("fileBrowser.confirmDeleteMessage",{name:eN.name}).split(/<\/?file>/g).map((e,t)=>1===t?(0,n.jsx)("span",{className:"font-mono text-foreground",children:e},t):e)}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>eC(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-hover transition-colors",children:C("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=eN;eC(null);let n=await P.t4.runPromiseExit((0,T.VK)({cwd:t,path:e}));if("Success"===n._tag){(0,q.oR)(C("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";tr.loadDirectory(t),tr.loadFileIndex(),tr.selectedPath===e&&ty("")}else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:C("toast.deleteFailed");(0,q.oR)(r,"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:C("common.delete")})]})]})})}),e9.hoverInfo&&ek&&(0,L.createPortal)((0,n.jsx)(tK,{ref:e9.setTooltipEl,displayString:e9.hoverInfo.displayString,documentation:e9.hoverInfo.documentation,x:e9.hoverInfo.x,y:e9.hoverInfo.y,container:ek,onMouseEnter:e9.onCardMouseEnter,onMouseLeave:e9.onCardMouseLeave,onFindReferences:tF?void 0:()=>{let{filePath:e,line:t,column:r}=e9.hoverInfo;e9.clearHover(),e7.findReferences(e,t,r)},onSearch:e=>{e9.clearHover(),en("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)},onExplain:S?e=>{let{filePath:t,line:r}=e9.hoverInfo;e9.clearHover(),S.sendMessage(C("explain.symbolMessage",{name:e,path:t,lines:String(r)}))}:void 0,explainDisabled:S?.isLoading}),ek)]})});var tZ=r(95045),t0=r(75346);function t1({isOpen:e,onClose:t,cwd:r}){let l,{t:a}=(0,o.Bd)(),[i,d]=(0,s.useState)([]),[c,u]=(0,s.useState)(null),[m,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(""),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)([]),[L,E]=(0,s.useState)(""),[T,$]=(0,s.useState)(!1),I=(0,s.useCallback)((e,t)=>e?._tag==="Fail"&&e.error?.cause instanceof Error?e.error.cause.message:a(t),[a]),F=(0,s.useCallback)(async()=>{f(!0);let e=await P.t4.runPromiseExit((0,R.FK)(r));if("Success"===e._tag){let t=e.value;d(t.worktrees),u(t.nextPath),x(t.nextRandomWord),t.gitUserName&&y(t.gitUserName)}else console.error("Failed to load worktrees:",e.cause),(0,q.oR)(a("toast.worktreeLoadFailed"),"error");f(!1)},[r,a]),B=(0,s.useCallback)(e=>{let{local:t,remote:r}=e;return r.includes("origin/main")?"origin/main":r.includes("origin/master")?"origin/master":t.includes("main")?"main":t.includes("master")?"master":r.length>0?r[0]:t.length>0?t[0]:"main"},[]);(0,s.useEffect)(()=>{e&&(F(),v(null))},[e,F]);let D=async()=>{if(!c)return;let e="origin/main",t=await P.t4.runPromiseExit((0,R.r4)(r));"Success"===t._tag&&(e=B(t.value));let n=m||function(){let e="bcdfghjklmnprstvwz",t=["a","e","i","o","u","ai","au","ea","ee","ia","io","oa","oo","ou","ui"],r="";for(let n=0;n<2;n++)r+=e[Math.floor(Math.random()*e.length)],r+=t[Math.floor(Math.random()*t.length)];return r}(),s=k?`${k}/${n}`:n;g(!0);let o=await P.t4.runPromiseExit((0,R.CM)({action:"add",cwd:r,path:c,newBranch:s,baseBranch:e}));"Success"===o._tag?((0,q.oR)(a("toast.worktreeCreateSuccess",{name:s}),"success"),F()):(console.error("Failed to create worktree:",o.cause),(0,q.oR)(I(o.cause,"toast.worktreeCreateFailed"),"error")),g(!1)},A=async()=>{$(!0),E(""),C(!0);let e=await P.t4.runPromiseExit((0,R.r4)(r));if("Success"===e._tag){let t=e.value,r=t.local??[],n=t.remote??[],s=new Set(i.map(e=>e.branch).filter(Boolean));M([...r.filter(e=>!s.has(e)),...n.filter(e=>!s.has(e)&&!r.includes(e.replace(/^origin\//,"")))])}else(0,q.oR)(a("toast.loadBranchFailed"),"error");$(!1)},H=async e=>{if(!c)return;C(!1),g(!0);let t=await P.t4.runPromiseExit((0,R.CM)({action:"add",cwd:r,path:c,branch:e}));"Success"===t._tag?((0,q.oR)(a("toast.worktreeCreateSuccess",{name:e}),"success"),F()):(console.error("Failed to create worktree:",t.cause),(0,q.oR)(I(t.cause,"toast.worktreeCreateFailed"),"error")),g(!1)},O=async()=>{if(!b)return;w(!0);let e=await P.t4.runPromiseExit((0,R.CM)({action:"remove",cwd:r,path:b.path}));"Success"===e._tag?((0,q.oR)(a("toast.worktreeDeleted"),"success"),v(null),F()):(console.error("Failed to delete worktree:",e.cause),(0,q.oR)(I(e.cause,"toast.worktreeDeleteFailed"),"error")),w(!1)},W=async e=>{let t=e.isLocked?"unlock":"lock",n=await P.t4.runPromiseExit((0,R.CM)({action:t,cwd:r,path:e.path}));"Success"===n._tag?((0,q.oR)(e.isLocked?a("toast.worktreeUnlocked"):a("toast.worktreeLocked"),"success"),F()):(console.error("Failed to toggle lock:",n.cause),(0,q.oR)(I(n.cause,"toast.operationFailed"),"error"))};return e?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-lv3 w-[480px] max-h-[80vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground",children:"Git Worktrees"}),(0,n.jsx)("button",{onClick:t,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:a("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:h?(0,n.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):(0,n.jsx)("div",{className:"space-y-2",children:i.map(e=>{let s,o=e.path===r;return(0,n.jsxs)("div",{className:`group p-3 rounded-lg border transition-colors ${o?"border-brand bg-brand/5":"border-border hover:bg-hover cursor-pointer"}`,onClick:()=>{e.path!==r&&((0,tZ.F)(t0.n.OpenProject,{cwd:e.path}),t())},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${o?"bg-brand":"bg-muted-foreground/30"}`}),(0,n.jsx)("span",{className:"font-medium text-foreground truncate",children:e.branch||(e.isDetached?"detached":"unknown")}),e.isLocked&&(0,n.jsx)("span",{className:"text-amber-11",title:a("git.worktree.locked"),children:"\uD83D\uDD12"}),o&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",a("common.current"),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:!o&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),W(e)},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary rounded transition-colors",title:e.isLocked?a("git.worktree.unlock"):a("git.worktree.lock"),children:e.isLocked?(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"})}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-secondary rounded transition-colors",title:a("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})})]}),(0,n.jsxs)("div",{className:"mt-1 flex items-center justify-between gap-2 pl-4",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:e.path}),null!=e.createdAt&&(s=(0,U.fw)(e.createdAt/1e3),(0,n.jsx)("span",{className:`text-xs flex-shrink-0 ${"just now"===s?"text-brand":"text-muted-foreground/70"}`,"data-tooltip":new Date(e.createdAt).toLocaleString(),children:s}))]}),e.isDetached&&(0,n.jsx)("div",{className:"mt-1 text-xs text-amber-11 pl-4",children:"(detached HEAD)"})]},e.path)})})}),N&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-3 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)("input",{value:L,onChange:e=>E(e.target.value),placeholder:a("git.worktree.searchBranch"),className:"flex-1 bg-secondary text-sm text-foreground rounded px-2.5 py-1.5 outline-none",autoFocus:!0,autoComplete:"off",spellCheck:"false"}),(0,n.jsx)("button",{onClick:()=>C(!1),className:"text-xs text-muted-foreground hover:text-foreground px-2 py-1.5",children:a("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:T?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:a("common.loading")}):0===(l=S.filter(e=>e.toLowerCase().includes(L.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:a("git.worktree.noBranches")}):l.map(e=>(0,n.jsx)("button",{onClick:()=>H(e),className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-hover transition-colors truncate",children:(0,n.jsx)("span",{className:`${e.startsWith("origin/")?"text-muted-foreground":"text-foreground"}`,children:e})},e))})]}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:a("git.worktree.count",{count:i.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:A,disabled:!c||p,className:`px-3 py-1.5 text-sm rounded transition-colors ${c&&!p?"bg-secondary text-foreground hover:bg-hover":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:a("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:D,disabled:!c||p,className:`px-3 py-1.5 text-sm rounded transition-colors ${c&&!p?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:p?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):a("git.worktree.addWorktree")})]})]}),b&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-scrim rounded-lg",onClick:()=>v(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-lv3 w-[360px] p-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-3",children:a("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:a("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:a("git.worktree.path")}),(0,n.jsx)("span",{className:"text-foreground",children:b.path})]}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:a("git.worktree.branch")}),(0,n.jsx)("span",{className:"text-foreground",children:b.branch||"detached"})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>v(null),className:"px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:a("common.cancel")}),(0,n.jsx)("button",{onClick:O,disabled:j,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 transition-colors disabled:opacity-50",children:j?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):a("common.delete")})]})]})})]})}):null}function t2(e){let t=e.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")}async function t5(e,t){let r=await P.t4.runPromiseExit(((e,t,r=!1)=>{let n,s;return n="open",s={params:{url:e,tab:!0,show:r,cwd:t}},eT.$mh({try:async()=>{let e=await fetch(`/api/browser/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),t=await e.json();if(!e.ok||!t.ok)throw Error(t.error||`HTTP ${e.status}`);return t.data},catch:e=>new e$.uV({message:e instanceof Error?e.message:`POST /api/browser/${n} failed`,cause:e})})})(e.trim(),t,!0));if("Success"===r._tag){let{shortId:e,cli:t}=r.value;(0,q.oR)(t_.A.t("browser.openedInChrome",{command:`${t||"cockpit"} browser ${e}`}));return}window.open(e.trim(),"_blank","noopener"),(0,q.oR)(t_.A.t("browser.openInTabFallback"))}var t4=r(67635),t3=r(73300),t6=r(20986),t8=r(9921),t9=r(66088),t7=r(42790);function re(e){let t=function(e){let t=0xffffffff;for(let r=0;r<e.length;r++){t^=e.charCodeAt(r);for(let e=0;e<8;e++)t=t>>>1^(1&t?0xedb88320:0)}return(0xffffffff^t)>>>0}(e),r="",n=t;for(let e=0;e<4;e++)r+=String.fromCharCode(97+n%26),n=Math.floor(n/26);return r}var rt=r(2349),rr=r(12786),rn=r(94720);let rs=(0,s.lazy)(()=>Promise.resolve().then(r.bind(r,96901)).then(e=>({default:e.XtermRenderer}))),ro={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},rl=/\x1b\[[0-9;]*m/g;function ra({output:e,query:t,mode:r,currentIdx:o,matchListRef:l}){let a=(0,s.useRef)(null);a.current||(a.current=new t7.v,a.current.use_classes=!0);let i=e.split("\n"),d=t.toLowerCase(),c=0;return l.current=[],(0,n.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap break-words select-text",children:i.map((e,t)=>{let s=e.replace(rl,""),i=s.toLowerCase().includes(d);if("filter"===r&&!i)return null;if(!i){let r=a.current.ansi_to_html(e);return(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:r}},t)}let u=[],m=0,x=s.toLowerCase(),h=0;for(;h<x.length;){let e=x.indexOf(d,h);if(-1===e)break;e>m&&u.push((0,n.jsx)("span",{children:s.slice(m,e)},`t${m}`));let t=c++,r=t===o;u.push((0,n.jsx)("mark",{ref:e=>{l.current[t]=e},className:r?"bg-brand/40 text-foreground":"bg-yellow-300/40 text-foreground",children:s.slice(e,e+d.length)},`m${e}`)),h=m=e+d.length}return m<s.length&&u.push((0,n.jsx)("span",{children:s.slice(m)},`t${m}`)),(0,n.jsx)("div",{children:u},t)})})}let ri=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:l,output:a,exitCode:i,isRunning:d,selected:c,onSelect:u,onInterrupt:m,onStdin:x,onDelete:h,onRerun:f,timestamp:p,usePty:g,subscribePtyOutput:b,subscribePtyReset:v,subscribePtyRefresh:j,onPtyResize:w,onToggleMaximize:k,maximized:y,expandedHeight:N,bubbleContentHeight:C,onTitleMouseDown:S}){let{t:M}=(0,o.Bd)(),L=(0,s.useRef)(null),E=(0,s.useRef)(null),T=(0,s.useRef)(!0),$=(0,s.useRef)(null),R=(0,s.useRef)(null),I=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`})(p),F=e&&t?re(t+e):void 0,[B,D]=(0,s.useState)(!1),[A,H]=(0,s.useState)(""),O=(0,s.useRef)(null),W=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!b||!e)return;let t=()=>O.current?b(e,O.current.write):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[b,e]),(0,s.useEffect)(()=>{if(!v||!e)return;let t=()=>O.current?v(e,O.current.reset):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[v,e]),(0,s.useEffect)(()=>{if(!j||!e)return;let t=()=>O.current?j(e,O.current.refresh):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[j,e]);let[_,z]=(0,s.useState)(!1),[V,U]=(0,s.useState)(""),[K,Q]=(0,s.useState)("search"),[G,J]=(0,s.useState)(0),Y=(0,s.useRef)([]),X=(0,s.useRef)(null),Z=(0,s.useRef)(0);(0,s.useEffect)(()=>{X.current||(X.current=new t7.v,X.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=E.current;if(e&&X.current){if(a.length<Z.current&&(X.current=new t7.v,X.current.use_classes=!0,Z.current=0,e.innerHTML=""),a.length>Z.current){let t=a.slice(Z.current),r=X.current.ansi_to_html(t);Z.current=a.length,e.insertAdjacentHTML("beforeend",r)}if(L.current){let e=L.current.scrollHeight>L.current.clientHeight;D(e),e&&(L.current.scrollTop=L.current.scrollHeight)}}},[a]),(0,s.useEffect)(()=>(d&&T.current&&L.current&&(null!==$.current&&cancelAnimationFrame($.current),$.current=requestAnimationFrame(()=>{L.current&&(L.current.scrollTop=L.current.scrollHeight),$.current=null})),()=>{null!==$.current&&cancelAnimationFrame($.current)}),[a,d]),(0,s.useEffect)(()=>{if(!y)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),k?.())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[y,k]);let ee=a?a.split("\n").length:0,et=(0,s.useCallback)(()=>{z(!0),requestAnimationFrame(()=>W.current?.focus())},[]),er=(0,s.useCallback)(()=>{z(!1),U(""),J(0),O.current?.clearSearch()},[]),en=(0,s.useCallback)(e=>{e.trim()&&(g?O.current?.findNext(e):J(e=>{let t=e+1,r=Y.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(Y.current[0]?.scrollIntoView({block:"nearest"}),0)}))},[g]),es=(0,s.useCallback)(e=>{e.trim()&&(g?O.current?.findPrevious(e):J(e=>{let t=e-1;if(t>=0)return Y.current[t]?.scrollIntoView({block:"nearest"}),t;let r=Y.current.length-1;return r>=0&&Y.current[r]?.scrollIntoView({block:"nearest"}),Math.max(r,0)}))},[g]);(0,s.useEffect)(()=>{if(!c)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key){e.preventDefault(),e.stopPropagation(),et();return}if("Escape"===e.key&&_){e.preventDefault(),e.stopPropagation(),er();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[c,_,et,er]);let eo=y&&N?N-41:C??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-card text-foreground dark:text-slate-11 relative overflow-hidden border transition-colors cursor-pointer ${y?"rounded-none border-0":"rounded-2xl rounded-bl-md rounded-br-md"} ${y?"":c?"border-brand":"border-brand/30"}`,onClick:u,children:[y?(0,n.jsxs)("div",{onDoubleClick:()=>k?.(),className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41,flexShrink:0},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded bg-muted text-muted-foreground",children:">_"}),(0,n.jsx)("span",{className:"flex-1 text-xs text-muted-foreground truncate font-mono",children:l}),d&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse"}),M("console.runningText")]}),d&&m&&(0,n.jsx)("button",{onClick:m,className:"text-xs px-3 py-1 rounded-md font-medium bg-destructive text-destructive-foreground transition-all duration-150 hover:bg-destructive/80 hover:shadow-lv2 active:scale-95 active:bg-destructive/70 cursor-pointer select-none",children:"Ctrl+C"}),(0,n.jsx)("button",{onClick:()=>k?.(),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:M("console.restoreTooltip",{modKey:(0,rr.Mu)()}),children:(0,n.jsx)(ew.A,{className:"w-4 h-4"})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>S?.(),onDoubleClick:e=>{e.stopPropagation(),k?.()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing ${c?"border-brand":"border-brand/30"}`,children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:">_"}),F&&e&&t&&(0,n.jsx)(rt.j,{shortId:F,type:"terminal",onRegister:()=>{P.t4.runFork((0,rn.Ok)({tabId:t,commandId:e,command:l,projectCwd:r}).pipe(eT.NWQ(()=>eT.rIH)))},onUnregister:()=>{P.t4.runFork((0,rn.jO)({commandId:e}).pipe(eT.NWQ(()=>eT.rIH)))},fullId:e,projectCwd:r,tabId:t}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:l}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(l),(0,q.oR)(M("toast.copiedCmd"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:M("console.copyCommand"),children:(0,n.jsx)(t4.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),B&&!d&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:M("console.totalLines",{count:ee})}),a&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=a.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,q.oR)(M("toast.copiedOutput"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:M("console.copyOutput"),children:(0,n.jsx)(t3.A,{className:"w-3.5 h-3.5"})}),f&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),f()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:M("console.rerun"),children:(0,n.jsx)(t6.A,{className:"w-3.5 h-3.5"})}),h&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:M("console.deleteRecord"),children:(0,n.jsx)(ew.A,{className:"w-3.5 h-3.5"})})]}),_&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card",style:{flexShrink:0},children:[(0,n.jsx)(ej.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:W,value:V,onChange:e=>{let t=e.target.value;U(t),J(0),g&&(t.trim()?O.current?.findNext(t):O.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?es(V):en(V))},placeholder:M("console.searchPlaceholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none",autoComplete:"off",spellCheck:"false"}),!g&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>Q("search"),className:`px-1.5 py-0.5 rounded transition-colors ${"search"===K?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:M("console.searchMode")}),(0,n.jsx)("button",{onClick:()=>Q("filter"),className:`px-1.5 py-0.5 rounded transition-colors ${"filter"===K?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:M("console.filterMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>es(V),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:M("console.prevShiftEnter"),children:(0,n.jsx)(t8.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>en(V),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:M("console.nextEnter"),children:(0,n.jsx)(t9.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("button",{onClick:er,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)(ew.A,{className:"w-3.5 h-3.5"})})]}),g?(0,n.jsxs)("div",{className:"relative group",style:{height:eo,overflow:"hidden"},children:[(0,n.jsx)(s.Suspense,{fallback:(0,n.jsx)("div",{className:"px-4 py-2 text-xs text-muted-foreground",style:{height:eo},children:M("console.loadingTerminal")}),children:(0,n.jsx)(rs,{ref:O,output:a,isRunning:d,onInput:x,onResize:w,maximized:y,height:eo,directWrite:!!b})}),!d&&(0,n.jsx)("div",{className:"absolute inset-0 bg-background/50 pointer-events-none"}),!d&&f&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",onClick:e=>{e.stopPropagation(),f()},children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-tooltip text-tooltip-foreground text-xs",children:[(0,n.jsx)(t6.A,{className:"w-3.5 h-3.5"}),M("console.rerun")]})})]}):(0,n.jsx)("div",{ref:L,className:"overflow-auto px-4 py-2",style:{height:eo},onScroll:()=>{if(L.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=L.current;T.current=t-e-r<50}},children:_&&V.trim()?(0,n.jsx)(ra,{output:a,query:V,mode:K,currentIdx:G,matchListRef:Y}):(0,n.jsx)("pre",{ref:E,className:"text-sm font-mono whitespace-pre-wrap break-words select-text"})}),d&&!y&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse flex-shrink-0"}),g?(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-1",children:M("console.clickToInput")}):x?(0,n.jsx)("input",{ref:R,value:A,onChange:e=>H(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=ro[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),x(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),x(A+"\n"),H("")),"Tab"===e.key&&(e.preventDefault(),x(" "))},placeholder:M("console.stdinPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-xs font-mono text-foreground outline-none",autoComplete:"off",spellCheck:"false"}):(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:M("console.runningText")}),m&&(0,n.jsx)("button",{onClick:m,className:"flex-shrink-0 text-xs text-destructive hover:brightness-125 transition-colors cursor-pointer select-none",children:"Ctrl+C"}),I&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:I})]}),!d&&void 0!==i&&!y&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${0===i?"bg-green-500":"bg-red-500"}`}),(0,n.jsx)("span",{children:M("console.exitCode",{code:i})}),(0,n.jsx)("span",{className:"flex-1"}),I&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:I})]})]})})}),rd=new Map;function rc(e){rd.set(e.type,e)}function ru(e){return rd.get(e)}function rm(e){for(let t of rd.values())if(t.match(e))return t;return null}let rx=(e,t)=>eT.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:t=>new e$.uV({message:`POST ${e} failed`,cause:t})}),rh=(e,t)=>P.t4.runPromise(rx(`/api/${e}/disconnect`,{id:t}).pipe(eT.NWQ(()=>eT.rIH))),rf=e=>P.t4.runPromise(rx("/api/browser/unregister",{id:e}).pipe(eT.NWQ(()=>eT.rIH))),rp=e=>P.t4.runPromise(e.pipe(eT.h9N(e=>eT.OH5(()=>{if(e.cause instanceof Error)throw e.cause;throw Error(e.message)})))),rg=(e,t)=>{if(e&&"object"==typeof e&&"error"in e){let t=e.error;if("string"==typeof t&&t.length>0)return t;if(t&&"object"==typeof t){let e=t.message;if("string"==typeof e&&e.length>0)return e;let r=t._tag;if("string"==typeof r&&r.length>0)return r}}return`HTTP ${t}`},rb=(e,t)=>rp(eT.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json();if(!r.ok)throw Error(rg(n,r.status));return n},catch:t=>new e$.uV({message:`POST ${e} failed`,cause:t})})),rv=(e,t)=>rp(eT.$mh({try:async()=>{let r=new URLSearchParams(t),n=await fetch(`${e}?${r}`),s=await n.json();if(!n.ok)throw Error(rg(s,n.status));return s},catch:t=>new e$.uV({message:`GET ${e} failed`,cause:t})})),rj=(e,t)=>rp(eT.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`);return r.blob()},catch:t=>new e$.uV({message:`POST blob ${e} failed`,cause:t})}));function rw(e){let t=e.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")}function rk({url:e,id:t,selected:r,maximized:l,expandedHeight:a,bubbleContentHeight:i,onSelect:d,onClose:c,onToggleMaximize:u,onNewTab:m,timestamp:x,onTitleMouseDown:h,initialSleeping:f,onSleep:p,onWake:g,projectCwd:b,baseCwd:v,tabId:j,autoConnect:w}){let{t:k,i18n:y}=(0,o.Bd)(),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(null),L=rw(e),[E,P]=(0,s.useState)(e),[T,$]=(0,s.useState)(null),[R,I]=(0,s.useState)(f??!1),F=(0,s.useRef)(null),B=(0,s.useRef)(null),D=(0,s.useRef)(null);(0,s.useEffect)(()=>{P(e)},[e]);let A=(0,s.useRef)(!0),H=(0,s.useCallback)(()=>{R||(I(!0),$(null),p?.(t))},[R,t,p]),O=(0,s.useCallback)(()=>{F.current&&(clearTimeout(F.current),F.current=null)},[]),{shortId:W,connected:_,connect:z,disconnect:V}=function(e,t,r,n,o){let l=(0,s.useMemo)(()=>re(e),[e]),[a,i]=(0,s.useState)(!1),d=(0,s.useRef)(null),c=(0,s.useRef)([]),u=(0,s.useRef)(null),m=(0,s.useRef)(!1),x=(0,s.useRef)(r);(0,s.useEffect)(()=>{x.current=r});let h=(0,s.useRef)([]),f=(0,s.useCallback)((e,t,r,n)=>{let s=d.current;e&&s&&s.readyState===WebSocket.OPEN&&s.send(JSON.stringify({type:"browser:cmd-result",reqId:e,ok:t,data:r,error:n}))},[]),p=(0,s.useCallback)(e=>{let r=t.current;if(!r)return void f(e,!1,void 0,"bubble iframe not mounted (sleeping?)");let n=new URLSearchParams(window.location.search).get("cwd")||"";window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!0}})),(0,tZ.F)(t0.n.ScreenshotPrepare,{cwd:n}),requestAnimationFrame(()=>requestAnimationFrame(()=>requestAnimationFrame(()=>{setTimeout(()=>{let t=r.getBoundingClientRect(),n=window.devicePixelRatio||1,s=t.x,o=t.y;try{let e=window;for(;e!==e.top;){let t=e.frameElement;if(t){let e=t.getBoundingClientRect();s+=e.x,o+=e.y}e=e.parent}}catch{}f(e,!0,{x:Math.round(s*n),y:Math.round(o*n),width:Math.round(t.width*n),height:Math.round(t.height*n),dpr:n})},150)})))},[t,f]),g=(0,s.useCallback)(e=>{"ensure-ready"===e.op?x.current?f(e.reqId,!0,{ready:!0}):e.reqId&&c.current.push(e.reqId):"prepare-screenshot"===e.op?p(e.reqId):"screenshot-done"===e.op&&(window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!1}})),(0,tZ.F)(t0.n.ScreenshotDone,{}))},[p,f]);(0,s.useEffect)(()=>{if(!a)return;let t=!1;return m.current=!0,!function r(){if(t||!m.current)return;let s="https:"===window.location.protocol?"wss:":"ws:",l=new URLSearchParams({fullId:e});n&&l.set("projectCwd",n),o&&l.set("tabId",o);let a=new WebSocket(`${s}//${window.location.host}/ws/browser?${l.toString()}`);d.current=a,a.onopen=()=>{for(let e of h.current)e();h.current=[]},a.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}"browser:ui"===t.type&&g(t)},a.onclose=()=>{d.current=null,!t&&m.current&&(u.current=setTimeout(r,3e3))},a.onerror=()=>a.close()}(),()=>{t=!0,m.current=!1,u.current&&clearTimeout(u.current),d.current&&(d.current.close(),d.current=null),h.current=[]}},[a,e,g,n,o]),(0,s.useEffect)(()=>{if(r&&c.current.length>0){for(let e of c.current)f(e,!0,{ready:!0});c.current=[]}},[r,f]);let b=(0,s.useCallback)(()=>a&&d.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{h.current.push(e),a||i(!0)}),[a]);return{shortId:l,connected:a,connect:b,disconnect:(0,s.useCallback)(()=>{i(!1)},[])}}(t,D,!!T&&!R&&!N,b,j),U=(0,s.useRef)(_);U.current=_;let K=(0,s.useRef)(!1);(0,s.useEffect)(()=>{L||!w||K.current||(K.current=!0,z())},[L,w,z]),(0,s.useEffect)(()=>{let e=B.current;if(!e||R)return;let t=new IntersectionObserver(([e])=>{A.current=e.isIntersecting,e.isIntersecting||U.current?O():(F.current&&clearTimeout(F.current),F.current=setTimeout(H,3e5))});return t.observe(e),()=>t.disconnect()},[R,H,O]),(0,s.useEffect)(()=>{R?V():_?O():A.current||(F.current&&clearTimeout(F.current),F.current=setTimeout(H,3e5))},[_,R,V,O,H]),(0,s.useEffect)(()=>{f&&$(null)},[]);let Q=(0,s.useCallback)(()=>{(I(!1),g?.(t),rw(e))?$(e):$((0,eu.YQ)(e,v))},[e,t,g,v]),G=(0,s.useRef)(()=>{});G.current=()=>{L||(R&&Q(),z())},(0,eb.h)({url:"/ws/global-state",enabled:!!W,onMessage:e=>{"browser-wake"===e.type&&e.shortId===W&&G.current()}}),(0,s.useEffect)(()=>{if(!e||R){e||$(null);return}rw(e)?$(e):$((0,eu.YQ)(e,v))},[e,R,v]);let J=(0,s.useCallback)(()=>{C(!1);let e=D.current?.contentWindow;if(!e)return;let t=document.documentElement.classList.contains("dark");e.postMessage({type:"THEME_CHANGE",theme:t?"dark":"light"},"*"),e.postMessage({type:"cockpit:language-change",lang:y.language},"*")},[y]);(0,s.useEffect)(()=>{let e=B.current;if(!e)return;let t=null,r=e.parentElement;for(;r;){let{overflowY:e}=getComputedStyle(r);if("auto"===e||"scroll"===e){t=r;break}r=r.parentElement}if(!t)return;let n="",s=0,o=!1,l=()=>{o&&t&&(t.scrollTop=s)},a=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",l)},i=()=>{o=!1,t.removeEventListener("scroll",l),t.style.overflow=n};return e.addEventListener("mouseenter",a),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",a),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",l),o&&(t.style.overflow=n)}},[]),(0,s.useEffect)(()=>{let e=e=>{if(!e.data||"string"!=typeof e.data.type||!e.data.type.startsWith("cockpit:"))return;let r=B.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?m?.(e.data.url,t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&P(e.data.url)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,m]);let Y=(0,s.useCallback)(()=>{C(!1),M(k("browser.pageLoadFailed"))},[]),X=(0,s.useCallback)(()=>{if(R)return void Q();let e=B.current?.querySelector("iframe");if(e&&T){C(!0),M(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[R,Q,T]);(0,s.useEffect)(()=>{e&&!R&&(C(!0),M(null))},[e,R]);let Z=(0,s.useCallback)(()=>{if(!E)return;let e=rw(E)?E:(0,eu.YQ)(E,v);window.open((0,eu.PB)(e,window.location.origin),"_blank")},[E,v]);(0,s.useEffect)(()=>{if(!r&&!l)return;let e=e=>{"Escape"===e.key&&l&&(e.stopPropagation(),u()),"m"===e.key&&(e.metaKey||e.ctrlKey)&&r&&(e.preventDefault(),e.stopPropagation(),u())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[l,r,u]);let ee=function(e){if(!e)return"";try{let t=new URL(e);return t.port?`${t.hostname}:${t.port}`:t.hostname}catch{return e.split("/").pop()||e}}(E),et=l&&a?a-41:i??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
8
- relative transition-colors cursor-pointer
9
- ${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
10
- ${l?"":r?"border-brand":"border-brand/30"}`,onClick:l?void 0:d,children:[l?(0,n.jsxs)("div",{onDoubleClick:u,className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})})}),W&&!L&&(0,n.jsx)(rt.j,{shortId:W,type:"browser",registered:_,onRegister:()=>z(),onUnregister:async()=>{V(),await rf(W)},fullId:t,projectCwd:b,tabId:j}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate font-mono",children:E||k("browser.blankPage")}),E&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(E),(0,q.oR)(k("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.copyUrl"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("span",{className:"flex-1"}),N&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),(0,n.jsx)("button",{onClick:X,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 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,n.jsx)("button",{onClick:Z,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.openInNewWindow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),(0,n.jsx)("button",{onClick:u,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.exitMaximize",{modKey:(0,rr.Mu)()}),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>h?.(),onDoubleClick:e=>{e.stopPropagation(),u()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing
11
- ${r?"border-brand":"border-brand/30"}`,children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-3 h-3 inline-block",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})})}),W&&!L&&(0,n.jsx)(rt.j,{shortId:W,type:"browser",registered:_,onRegister:()=>z(),onUnregister:async()=>{V(),await rf(W)},fullId:t,projectCwd:b,tabId:j}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:E||k("browser.blankPage")}),E&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(E),(0,q.oR)(k("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.copyUrl"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("span",{className:"flex-1"}),N&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),Z()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.openInNewWindow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),X()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 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,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:k("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{ref:B,className:"w-full",style:{height:et},children:R?(0,n.jsxs)("div",{className:"relative overflow-hidden cursor-pointer group h-full",onClick:e=>{e.stopPropagation(),X()},children:[(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-muted/30",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-2 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground/60",children:ee})]}),(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-black/60 text-white text-xs",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 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"})}),k("browser.clickToWake")]})})]}):e?L?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 text-muted-foreground p-6 h-full text-center",children:[(0,n.jsx)("svg",{className:"w-9 h-9 mb-1 opacity-70",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),(0,n.jsx)("p",{className:"text-sm text-foreground",children:k("browser.movedToChrome")}),(0,n.jsx)("p",{className:"text-xs break-all opacity-70",children:e}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),t5(e,b??v)},className:"mt-1 px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:k("browser.openInChrome")})]}):S?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center text-muted-foreground p-6 h-full",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-3 text-red-11",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,n.jsx)("p",{className:"text-xs",children:S}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),X()},className:"mt-2 px-3 py-1 text-xs bg-secondary text-foreground rounded hover:bg-hover transition-colors",children:k("common.retry")})]}):(0,n.jsxs)("div",{className:"relative overflow-hidden h-full",style:{contain:"strict"},children:[N&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-card/80 z-10",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),T?(0,n.jsx)("iframe",{ref:D,src:T,className:"border-0 bg-white",allow:"clipboard-write; clipboard-read",style:l?{width:"100%",height:"100%"}:{position:"absolute",top:0,left:0,width:"200%",height:"200%",transform:"scale(0.5)",transformOrigin:"top left"},name:`cockpit-bubble-${t}`,onLoad:J,onError:Y,title:`Browser: ${ee}`,"data-browser-id":t}):(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center text-muted-foreground h-full",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-2 text-foreground-faint",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})}),(0,n.jsx)("p",{className:"text-xs",children:k("browser.blankPage")})]})}),!l&&e&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full flex-shrink-0 ${R?"bg-yellow-500":N?"bg-brand animate-pulse":S?"bg-red-500":"bg-green-500"}`}),(0,n.jsx)("span",{className:"truncate",children:R?k("browser.sleeping"):N?k("browser.loadingPage"):S?k("browser.loadFailed"):ee}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:function(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}(x)})]})]})})}rc({type:"browser",idPrefix:"browser",match(e){let t=e.trim().toLowerCase();return t.endsWith(".html")||t.endsWith(".htm")||(0,eu.Kx)(t)},parse:e=>({url:e.trim(),cwd:""}),fromHistory:e=>({url:e.url,cwd:e.cwd??"",autoConnect:!!e.autoConnect}),toHistory:e=>({url:e.url,cwd:e.cwd??"",...e.autoConnect?{autoConnect:!0}:{}}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:d,onTitleMouseDown:c,extra:u}){return(0,n.jsx)(rk,{id:e.id,url:e.url,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:d,onTitleMouseDown:c,onNewTab:u?.addBrowserItem,initialSleeping:u?.initialSleeping,onSleep:u?.onSleep,onWake:u?.onWake,projectCwd:u?.projectCwd,baseCwd:e.cwd||u?.projectCwd,tabId:u?.tabId,autoConnect:e.autoConnect})}});let ry=[{value:"=",label:"="},{value:"!=",label:"≠"},{value:">",label:">"},{value:"<",label:"<"},{value:">=",label:"≥"},{value:"<=",label:"≤"},{value:"LIKE",label:"LIKE"},{value:"NOT LIKE",label:"NOT LIKE"},{value:"IN",label:"IN"},{value:"IS NULL",label:"IS NULL"},{value:"IS NOT NULL",label:"IS NOT NULL"}];function rN(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}function rC(e){return`"${e.replace(/"/g,'""')}"`}function rS(e){return null==e?"":"object"==typeof e?JSON.stringify(e):String(e)}function rM({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,maxW:600,maxH:300,above:!0}),i=(0,s.useRef)(null),d=(0,s.useRef)(null),c=(0,s.useRef)(!1),u=(0,l.F2)(),m=(0,s.useCallback)(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{c.current||r(!1)},80)},[]),x=(0,s.useCallback)(()=>{d.current&&clearTimeout(d.current),c.current=!1,d.current=setTimeout(()=>{let e=i.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=u?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,l=n?.width??window.innerWidth,d=n?.height??window.innerHeight,c=t.left-s,m=t.top-o,x=t.bottom-o,h=Math.min(600,l-c-8),f=m-8,p=d-x-8,g=f>p&&f>80,b=g?f-4:p-4;a({x:h<200?Math.max(8,l-600-8):c,y:g?m-4:x+4,maxW:h<200?Math.min(600,l-16):h,maxH:Math.max(60,b),above:g}),r(!0)},350)},[u]),h=(0,s.useCallback)(()=>{m()},[m]),f=(0,s.useCallback)(()=>{c.current=!0,d.current&&clearTimeout(d.current)},[]),p=(0,s.useCallback)(()=>{c.current=!1,m()},[m]);return(0,n.jsxs)("span",{ref:i,className:"block truncate",onMouseEnter:x,onMouseLeave:h,children:[e,t&&(0,n.jsx)(l.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lv2 whitespace-pre-wrap break-all select-text cursor-text",style:{left:o.x,top:o.y,maxWidth:o.maxW,maxHeight:o.maxH,transform:o.above?"translateY(-100%)":void 0},onMouseEnter:f,onMouseLeave:p,children:function(e){try{let t=JSON.parse(e);if("object"==typeof t&&null!==t)return JSON.stringify(t,null,2)}catch{}return e}(e)})})]})}function rL({id:e,connectionString:t,displayName:r,selected:l,maximized:a,expandedHeight:i,bubbleContentHeight:d,onSelect:c,onClose:u,onToggleMaximize:m,timestamp:x,onTitleMouseDown:h}){let{t:f}=(0,o.Bd)(),{showToast:p}=(0,q.dj)(),[g,b]=(0,s.useState)("connecting"),[v,j]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)("public"),[C,S]=(0,s.useState)([]),[M,L]=(0,s.useState)(null),[E,P]=(0,s.useState)("table"),[T,$]=(0,s.useState)("data"),[R,I]=(0,s.useState)([]),[F,B]=(0,s.useState)([]),[D,A]=(0,s.useState)([]),[H,O]=(0,s.useState)([]),[W,_]=(0,s.useState)(null),[z,V]=(0,s.useState)(0),[U,K]=(0,s.useState)(!1),[Q,G]=(0,s.useState)(0),[J,Y]=(0,s.useState)(new Set),[X,Z]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)({}),[es,eo]=(0,s.useState)(!1),[el,ea]=(0,s.useState)({}),[ei,ed]=(0,s.useState)({}),[ec,eu]=(0,s.useState)(null),[em,ex]=(0,s.useState)(""),[eh,ef]=(0,s.useState)(null),[ep,eg]=(0,s.useState)(""),[eb,ev]=(0,s.useState)(!1),ej=(0,s.useRef)(null),ew=(0,s.useCallback)(async()=>{b("connecting"),j("");try{let r=await rb("/api/db/connect",{id:e,connectionString:t});k(r.schemas||[]),r.schemas?.length>0&&!r.schemas.includes("public")&&N(r.schemas[0]),b("connected")}catch(e){j(e instanceof Error?e.message:String(e)),b("error")}},[e,t]);(0,s.useEffect)(()=>{ew()},[ew]);let ek=(0,s.useCallback)(async()=>{if("connected"===g)try{let r=await rv("/api/db/schemas",{id:e,connectionString:t,schema:y});S(r.tables||[])}catch{}},[e,t,y,g]);(0,s.useEffect)(()=>{ek()},[ek]);let ey=(0,s.useCallback)(async(r,n,s,o)=>{K(!0);let l=s??ei,a=void 0!==o?o:ec;try{let s=`${rC(y)}.${rC(r)}`,{where:o,params:i}=function(e){let t=[],r=[],n=1;for(let[s,o]of Object.entries(e)){if(!o.enabled)continue;let e=rC(s);if("IS NULL"===o.op)t.push(`${e} IS NULL`);else if("IS NOT NULL"===o.op)t.push(`${e} IS NOT NULL`);else if("IN"===o.op){let s=o.value.split(",").map(e=>e.trim()).filter(Boolean);if(0===s.length)continue;let l=s.map(e=>(r.push(e),`$${n++}`));t.push(`${e}::text IN (${l.join(", ")})`)}else"LIKE"===o.op||o.op,t.push(`${e}::text ${o.op} $${n++}`),r.push(o.value)}return{where:t.length>0?` WHERE ${t.join(" AND ")}`:"",params:r}}(l),d=a?` ORDER BY ${rC(a.column)} ${a.dir}`:"",c=`SELECT * FROM ${s}${o}${d} LIMIT 50 OFFSET ${50*n}`,u=await rb("/api/db/query",{id:e,connectionString:t,sql:c,params:i});_(u);let m=`SELECT count(*)::int AS cnt FROM ${s}${o}`,x=await rb("/api/db/query",{id:e,connectionString:t,sql:m,params:i});G(x.rows?.[0]?.cnt??0)}catch{}K(!1)},[e,t,y,ei,ec]),eN=(0,s.useCallback)(async r=>{L(r),V(0),et(null),eo(!1),Y(new Set),Z(!1),ed({}),eu(null);try{let n=await rv("/api/db/columns",{id:e,connectionString:t,schema:y,table:r});I(n.columns||[]),B(n.primaryKeys||[]),A(n.foreignKeys||[]),O(n.indexes||[])}catch{}ey(r,0,{},null)},[e,t,y,ey]),eC=(0,s.useCallback)(async()=>{if(em.trim()){ev(!0),eg(""),ef(null);try{let r=await rb("/api/db/query",{id:e,connectionString:t,sql:em});ef(r)}catch(e){eg(e instanceof Error?e.message:String(e))}ev(!1)}},[e,t,em]),eS=(0,s.useCallback)(async()=>{if(null===ee||!W||!M)return;let r=W.rows[ee],n=[],s=[],o=1;for(let e of R)void 0!==er[e.name]&&er[e.name]!==rS(r[e.name]??"")&&(n.push(`${rC(e.name)} = $${o}`),s.push(""===er[e.name]&&e.nullable?null:er[e.name]),o++);if(0===n.length)return void et(null);let l=F.length>0?F:R.map(e=>e.name),a=[];for(let e of l)null===r[e]||void 0===r[e]?a.push(`${rC(e)} IS NULL`):(a.push(`${rC(e)} = $${o}`),s.push(r[e]),o++);let i=`UPDATE ${rC(y)}.${rC(M)} SET ${n.join(", ")} WHERE ${a.join(" AND ")}`;try{await rb("/api/db/query",{id:e,connectionString:t,sql:i,params:s}),et(null),ey(M,z,ei,ec)}catch(e){alert(`Update failed: ${e instanceof Error?e.message:String(e)}`)}},[ee,W,M,R,F,er,e,t,y,ey,z,ei,ec]),eM=(0,s.useCallback)(async()=>{if(!M)return;let r=[],n=[],s=[],o=1;for(let e of R)void 0!==el[e.name]&&""!==el[e.name]&&(r.push(rC(e.name)),n.push(el[e.name]),s.push(`$${o}`),o++);if(0===r.length)return;let l=`INSERT INTO ${rC(y)}.${rC(M)} (${r.join(", ")}) VALUES (${s.join(", ")})`;try{await rb("/api/db/query",{id:e,connectionString:t,sql:l,params:n}),eo(!1),ea({}),ey(M,z,ei,ec)}catch(e){alert(`Insert failed: ${e instanceof Error?e.message:String(e)}`)}},[M,R,el,e,t,y,ey,z,ei,ec]),eL=(0,s.useCallback)(async()=>{if(0===J.size||!W||!M)return;let r=F.length>0?F:R.map(e=>e.name),n=0;for(let s of Array.from(J).sort((e,t)=>t-e)){let o=W.rows[s];if(!o)continue;let l=[],a=[],i=1;for(let e of r)null===o[e]||void 0===o[e]?l.push(`${rC(e)} IS NULL`):(l.push(`${rC(e)} = $${i}`),a.push(o[e]),i++);let d=`DELETE FROM ${rC(y)}.${rC(M)} WHERE ctid = (SELECT ctid FROM ${rC(y)}.${rC(M)} WHERE ${l.join(" AND ")} LIMIT 1)`;try{await rb("/api/db/query",{id:e,connectionString:t,sql:d,params:a})}catch{n++}}Y(new Set),Z(!1),ey(M,z,ei,ec),n>0&&alert(f("database.deleteRowsFailed",{count:n}))},[J,W,M,F,R,e,t,y,ey,z,ei,ec]),eE=(0,s.useCallback)(async r=>{if(!M)return;if(J.size>0&&W){let e,t=W.fields.map(e=>e.name),n=Array.from(J).sort((e,t)=>e-t).map(e=>W.rows[e]).filter(Boolean);if("json"===r)e=JSON.stringify(n,null,2);else{let r=[t.join(",")];for(let e of n)r.push(t.map(t=>{let r=e[t];if(null==r)return"";let n="object"==typeof r?JSON.stringify(r):String(r);return n.includes(",")||n.includes('"')||n.includes("\n")?`"${n.replace(/"/g,'""')}"`:n}).join(","));e=r.join("\n")}navigator.clipboard.writeText(e);return}let n=`SELECT * FROM ${rC(y)}.${rC(M)}`;try{let s=await rj("/api/db/export",{id:e,connectionString:t,sql:n,format:r}),o=URL.createObjectURL(s),l=document.createElement("a");l.href=o,l.download=`${M}.${r}`,l.click(),URL.revokeObjectURL(o)}catch(e){alert(`Export failed: ${e instanceof Error?e.message:String(e)}`)}},[M,e,t,y,J,W]),eP=(0,s.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),eC())},[eC]),eT=Math.max(1,Math.ceil(Q/50)),e$=(0,s.useCallback)(e=>{M&&(V(e),ey(M,e,ei,ec))},[M,ey,ei,ec]),eR=(0,s.useCallback)((e,t)=>{let r={...ei};t?r[e]=t:delete r[e],ed(r),V(0),Y(new Set),M&&ey(M,0,r,ec)},[ei,ec,M,ey]),eI=(0,s.useCallback)(()=>{ed({}),V(0),Y(new Set),M&&ey(M,0,{},ec)},[ec,M,ey]),eF=(0,s.useCallback)(e=>{eu(e),V(0),Y(new Set),M&&ey(M,0,ei,e)},[ei,M,ey]);return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
12
- relative transition-colors cursor-pointer
13
- ${a?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
14
- ${a?"":l?"border-brand":"border-brand/30"}`,onClick:a?void 0:c,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:h,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${a?"bg-card":"bg-card/50"}`,style:a?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"\uD83D\uDC18"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===g&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===g&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:f("database.connectionFailed")}),"connected"===g&&(0,n.jsx)("span",{className:"text-[10px] text-green-11 flex-shrink-0",children:f("database.connected")}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:rN(x)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:a?f("browser.exitMaximize",{modKey:(0,rr.Mu)()}):f("browser.maximize",{modKey:(0,rr.Mu)()}),children:a?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:f("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:a&&i?i-41:d??360},className:"flex overflow-hidden",children:["connecting"===g&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),f("database.connecting")]}),"error"===g&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:v}),(0,n.jsx)("button",{onClick:ew,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:f("common.retry")})]}),"connected"===g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[w.length>1?(0,n.jsx)("select",{value:y,onChange:e=>{N(e.target.value),L(null)},className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1",children:w.map(e=>(0,n.jsx)("option",{value:e,children:e},e))}):(0,n.jsx)("span",{className:"flex-1 min-w-0 text-xs text-muted-foreground truncate",children:y}),(0,n.jsx)("button",{onClick:ek,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-hover active:bg-active transition-colors",title:f("database.refreshTableList"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsx)("div",{className:"flex items-center border-b border-border",children:["table","view"].map(e=>(0,n.jsx)("button",{onClick:()=>P(e),className:`flex-1 py-1 text-[10px] font-medium transition-colors ${E===e?"text-brand border-b border-brand":"text-muted-foreground hover:text-foreground"}`,children:{table:f("database.filterTable"),view:f("database.filterView")}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[C.filter(e=>"table"===E?"view"!==e.type:"view"===e.type).map(e=>(0,n.jsxs)("div",{onClick:()=>eN(e.name),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer truncate transition-colors ${M===e.name?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground",children:"view"===e.type?"V":"T"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:(0,n.jsx)(rM,{text:e.name})}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.rowEstimate>0?`~${e.rowEstimate}`:""})]},e.name)),0===C.length&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:f("database.noTables")})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["structure","data","sql"].map(e=>(0,n.jsx)("button",{onClick:()=>$(e),className:`px-3 py-1.5 text-xs transition-colors ${T===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{structure:f("database.tabStructure"),data:f("database.tabData"),sql:"SQL"}[e]},e)),M&&"data"===T&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[Object.values(ei).some(e=>e.enabled)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-brand",children:f("database.filterActive",{count:Object.values(ei).filter(e=>e.enabled).length})}),(0,n.jsx)("button",{onClick:eI,className:"px-1 py-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors",title:f("database.clearAllFilters"),children:"✕"}),(0,n.jsx)("span",{className:"text-border",children:"|"})]}),J.size>0&&!X&&(0,n.jsx)("button",{onClick:()=>Z(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:f("database.deleteNRows",{count:J.size})}),X&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-destructive",children:f("database.confirmDeleteRows")}),(0,n.jsx)("button",{onClick:eL,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:f("common.confirm")}),(0,n.jsx)("button",{onClick:()=>Z(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:f("common.cancel")})]}),(0,n.jsx)("button",{onClick:()=>eE("csv"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:J.size>0?f("database.copyCsvSelected"):f("database.copyCsvAll"),children:J.size>0?f("database.copyCSV"):f("database.CSV")}),(0,n.jsx)("button",{onClick:()=>eE("json"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:J.size>0?f("database.copyJsonSelected"):f("database.copyJsonAll"),children:J.size>0?f("database.copyJSON"):f("database.JSON")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:M||"sql"===T?"structure"===T?(0,n.jsx)(rE,{columns:R,primaryKeys:F,foreignKeys:D,indexes:H}):"data"===T?(0,n.jsx)(rT,{result:W,loading:U,columns:R,page:z,totalPages:eT,totalRows:Q,onPageChange:e$,filters:ei,sort:ec,onFilterChange:eR,onSortChange:eF,selectedRows:J,onSelectedRowsChange:e=>{Y(e),Z(!1)},editingRowIdx:ee,editValues:er,onStartEdit:e=>{if(!W)return;let t=W.rows[e],r={};for(let e of R)r[e.name]=null==t[e.name]?"":rS(t[e.name]);en(r),et(e)},onEditChange:(e,t)=>en(r=>({...r,[e]:t})),onSaveEdit:eS,onCancelEdit:()=>et(null),isAddingRow:es,newRowValues:el,onStartAdd:()=>{eo(!0),ea({})},onNewRowChange:(e,t)=>ea(r=>({...r,[e]:t})),onSaveNewRow:eM,onCancelAdd:()=>{eo(!1),ea({})},onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)(r$,{sqlInput:em,onSqlChange:ex,onExecute:eC,onKeyDown:eP,result:eh,error:ep,loading:eb,sqlRef:ej,onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:f("database.selectTable")})})]})]})]}),!a&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===g?"bg-green-500":"error"===g?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:f("common.connecting"),connected:f("common.connected"),error:f("common.connectionFailed")}[g]}),"connected"===g&&M&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:M}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:rN(x)})]})]})})}function rE({columns:e,primaryKeys:t,foreignKeys:r,indexes:s}){let{t:l}=(0,o.Bd)();return 0===e.length?(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:l("database.selectTableToView")}):(0,n.jsxs)("div",{className:"p-2 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:l("database.columns")}),(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"text-left text-muted-foreground border-b border-border",children:[(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("database.colName")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("database.colType")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("database.colNullable")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("database.colDefault")})]})}),(0,n.jsx)("tbody",{children:e.map(e=>(0,n.jsxs)("tr",{className:"border-b border-border/50 hover:bg-hover",children:[(0,n.jsxs)("td",{className:"px-1.5 py-1 font-mono",children:[e.isPrimaryKey&&(0,n.jsx)("span",{className:"text-amber-11 mr-1",title:l("database.primaryKey"),children:"\uD83D\uDD11"}),e.name]}),(0,n.jsxs)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono",children:[e.type,e.maxLength?`(${e.maxLength})`:""]}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground",children:e.nullable?"YES":"NO"}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono truncate max-w-[120px]",children:e.default||""})]},e.name))})]})]}),r.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:l("database.foreignKeys")}),(0,n.jsx)("div",{className:"space-y-0.5",children:r.map((e,t)=>(0,n.jsxs)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground",children:[e.column," → ",e.refSchema,".",e.refTable,".",e.refColumn]},t))})]}),s.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:l("database.indexes")}),(0,n.jsx)("div",{className:"space-y-0.5",children:s.map(e=>(0,n.jsx)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground truncate","data-tooltip":e.definition,children:e.name},e.name))})]})]})}function rP({filter:e,onApply:t,onClear:r,onToggle:a,onClose:i,colName:d,anchorRect:c}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)(e?.op||"="),[h,f]=(0,s.useState)(e?.value||""),p=(0,s.useRef)(null),g=(0,l.F2)();(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&i()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[i]);let b="IS NULL"!==m&&"IS NOT NULL"!==m,v=()=>{(!b||h.trim())&&t({op:m,value:h.trim(),enabled:!0})},j=g?.getBoundingClientRect(),w=j?.left??0,k=j?.top??0,y=j?.width??window.innerWidth,N=c.left-w;N+220>y-8&&(N=y-220-8),N<8&&(N=8);let C=c.bottom+2-k;return(0,n.jsx)(l.ZL,{children:(0,n.jsxs)("div",{ref:p,className:"fixed z-[9998] w-[220px] bg-popover border border-border rounded-md shadow-lv2 p-2 space-y-2",style:{left:N,top:C},onClick:e=>e.stopPropagation(),children:[e&&(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:e=>a(e.target.checked),className:"w-3 h-3 accent-brand"}),u("database.enable")]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono truncate max-w-[120px]",children:d})]}),(0,n.jsx)("select",{value:m,onChange:e=>x(e.target.value),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 focus:outline-none focus:ring-1 focus:ring-ring",children:ry.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),b&&(0,n.jsx)("input",{type:"text",value:h,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v())},placeholder:u("IN"===m?"database.commaValues":"LIKE"===m?"database.likePattern":"database.valuePlaceholder"),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:v,disabled:b&&!h.trim(),className:"flex-1 px-2 py-1 text-[10px] bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-40 transition-colors",children:u("database.apply")}),e&&(0,n.jsx)("button",{onClick:r,className:"flex-1 px-2 py-1 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground transition-colors",children:u("database.clearFilter")})]})]})})}function rT({result:e,loading:t,columns:r,page:l,totalPages:a,totalRows:i,onPageChange:d,filters:c,sort:u,onFilterChange:m,onSortChange:x,selectedRows:h,onSelectedRowsChange:f,editingRowIdx:p,editValues:g,onStartEdit:b,onEditChange:v,onSaveEdit:j,onCancelEdit:w,isAddingRow:k,newRowValues:y,onStartAdd:N,onNewRowChange:C,onSaveNewRow:S,onCancelAdd:M,onCellCopy:L}){let{t:E}=(0,o.Bd)(),[P,T]=(0,s.useState)(null),[$,R]=(0,s.useState)({left:0,bottom:0});if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(null!==P?(e.stopPropagation(),T(null)):null!==p?(e.stopPropagation(),w()):k&&(e.stopPropagation(),M()))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[P,p,k,w,M]),!e&&!t)return(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:E("database.selectTableForData")});let I=e?.fields||[],F=e?.rows||[],B={};for(let e of r)B[e.name]=e.type+(e.maxLength?`(${e.maxLength})`:"");let D=F.length>0&&h.size===F.length,A=h.size>0&&!D;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",children:[t&&(0,n.jsx)("div",{className:"absolute inset-0 bg-background/50 flex items-center justify-center z-10",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[2]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-1 py-1 border-b border-border w-8 text-center",children:(0,n.jsx)("input",{type:"checkbox",checked:D,ref:e=>{e&&(e.indeterminate=A)},onChange:()=>{D?f(new Set):f(new Set(F.map((e,t)=>t)))},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(e=>{let t=u?.column===e.name?u.dir:null,r=c[e.name],s=r?.enabled;return(0,n.jsxs)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono relative",children:[(0,n.jsxs)("span",{className:"cursor-pointer select-none hover:text-foreground transition-colors",onClick:()=>{var t;return t=e.name,void(u?.column===t?"ASC"===u.dir?x({column:t,dir:"DESC"}):x(null):x({column:t,dir:"ASC"}))},children:[e.name,B[e.name]&&(0,n.jsx)("span",{className:"ml-1 text-[9px] text-muted-foreground/60 font-normal",children:B[e.name]}),"ASC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↑"}),"DESC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↓"})]}),(0,n.jsx)("button",{onClick:t=>{if(t.stopPropagation(),P===e.name)return void T(null);let r=t.currentTarget.closest("th").getBoundingClientRect();R({left:r.left,bottom:r.bottom}),T(e.name)},className:`ml-1 inline-flex items-center transition-colors ${s?"text-brand":"text-muted-foreground/40 hover:text-muted-foreground"}`,children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 16 16",fill:"currentColor",children:(0,n.jsx)("path",{d:"M1 2h14l-5.5 6.5V14l-3-2v-3.5z"})})}),P===e.name&&(0,n.jsx)(rP,{filter:r||null,onApply:t=>{m(e.name,t),T(null)},onClear:()=>{m(e.name,null),T(null)},onToggle:t=>{r&&m(e.name,{...r,enabled:t})},onClose:()=>T(null),colName:e.name,anchorRect:$})]},e.name)})]})}),(0,n.jsxs)("tbody",{children:[k&&(0,n.jsxs)("tr",{className:"bg-emerald-500/5",children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border text-center",children:(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:S,className:"text-[10px] text-green-11 hover:text-green-9",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:M,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]})}),I.map(e=>(0,n.jsx)("td",{className:"px-0.5 py-0.5 border-b border-border",children:(0,n.jsx)("input",{type:"text",value:y[e.name]??"",onChange:t=>C(e.name,t.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]",placeholder:"NULL"})},e.name))]}),F.map((e,t)=>(0,n.jsxs)("tr",{className:`hover:bg-hover ${h.has(t)?"bg-brand/5":""} ${p===t?"bg-blue-500/5":""}`,children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border/50 text-center",children:p===t?(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:j,className:"text-[10px] text-green-11 hover:text-green-9",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:w,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]}):(0,n.jsx)("input",{type:"checkbox",checked:h.has(t),onChange:()=>{let e;(e=new Set(h)).has(t)?e.delete(t):e.add(t),f(e)},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(r=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onDoubleClick:()=>{null===p&&b(t)},onContextMenu:t=>{t.preventDefault(),L(rS(e[r.name]))},children:p===t?(0,n.jsx)("input",{type:"text",value:g[r.name]??"",onChange:e=>v(r.name,e.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]"}):null===e[r.name]||void 0===e[r.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rM,{text:rS(e[r.name])})},r.name))]},t))]})]}),0===F.length&&!t&&(0,n.jsx)("div",{className:"p-4 text-xs text-muted-foreground text-center",children:E("common.noData")})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-2 py-1 border-t border-border text-[10px] text-muted-foreground bg-card/30 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:N,disabled:k,className:"px-1.5 py-0.5 text-[10px] text-green-11 hover:text-green-9 disabled:opacity-30",children:E("database.addRow")}),(0,n.jsx)("span",{children:E("database.totalRows",{count:i})}),e?.duration!==void 0&&(0,n.jsxs)("span",{children:[e.duration,"ms"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>d(l-1),disabled:0===l,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"◀"}),(0,n.jsxs)("span",{children:[l+1," / ",a]}),(0,n.jsx)("button",{onClick:()=>d(l+1),disabled:l>=a-1,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"▶"})]})]})]})}function r$({sqlInput:e,onSqlChange:t,onExecute:r,onKeyDown:s,result:l,error:a,loading:i,sqlRef:d,onCellCopy:c}){let{t:u}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 p-2 border-b border-border",children:[(0,n.jsx)("textarea",{ref:d,value:e,onChange:e=>t(e.target.value),onKeyDown:s,placeholder:u("database.sqlPlaceholder",{modKey:(0,rr.Mu)()}),className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("button",{onClick:r,disabled:i||!e.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:u(i?"database.executing":"database.execute")}),l?.duration!==void 0&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[l.command&&!l.fields?u("database.rowsAffected",{command:l.command,count:l.rowCount,duration:l.duration}):u("database.queryRows",{count:l.rows?.length??0,duration:l.duration}),l.truncated&&` ${u("database.resultTruncated")}`]})]})]}),a&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-destructive bg-destructive/5 border-b border-border break-all",children:a}),l?.fields&&l.rows&&(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:l.fields.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e.name},e.name))})}),(0,n.jsx)("tbody",{children:l.rows.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-hover",children:l.fields.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onContextMenu:r=>{r.preventDefault(),c(rS(e[t.name]))},children:null===e[t.name]||void 0===e[t.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rM,{text:rS(e[t.name])})},t.name))},t))})]})})]})}rc({type:"database",idPrefix:"db",match(e){let t=e.trim().toLowerCase();return t.startsWith("postgresql://")||t.startsWith("postgres://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"postgres";r=`${n}@${e.hostname}${e.port?":"+e.port:""}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(rL,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await rh("db",e.id)}});let rR=[{value:"=",label:"="},{value:"!=",label:"!="},{value:">",label:">"},{value:"<",label:"<"},{value:">=",label:">="},{value:"<=",label:"<="},{value:"LIKE",label:"LIKE"},{value:"NOT LIKE",label:"NOT LIKE"},{value:"IN",label:"IN"},{value:"IS NULL",label:"IS NULL"},{value:"IS NOT NULL",label:"IS NOT NULL"}];function rI(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}function rF(e){return`\`${e.replace(/`/g,"``")}\``}function rB(e){try{let t=e.match(/\/\/[^/]+\/([^?]+)/);if(t)return t[1]}catch{}return""}function rD(e){return null==e?"":"object"==typeof e?JSON.stringify(e):String(e)}function rA({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,maxW:600,maxH:300,above:!0}),i=(0,s.useRef)(null),d=(0,s.useRef)(null),c=(0,s.useRef)(!1),u=(0,l.F2)(),m=(0,s.useCallback)(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{c.current||r(!1)},80)},[]),x=(0,s.useCallback)(()=>{d.current&&clearTimeout(d.current),c.current=!1,d.current=setTimeout(()=>{let e=i.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=u?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,l=n?.width??window.innerWidth,d=n?.height??window.innerHeight,c=t.left-s,m=t.top-o,x=t.bottom-o,h=Math.min(600,l-c-8),f=m-8,p=d-x-8,g=f>p&&f>80,b=g?f-4:p-4;a({x:h<200?Math.max(8,l-600-8):c,y:g?m-4:x+4,maxW:h<200?Math.min(600,l-16):h,maxH:Math.max(60,b),above:g}),r(!0)},350)},[u]),h=(0,s.useCallback)(()=>{m()},[m]),f=(0,s.useCallback)(()=>{c.current=!0,d.current&&clearTimeout(d.current)},[]),p=(0,s.useCallback)(()=>{c.current=!1,m()},[m]);return(0,n.jsxs)("span",{ref:i,className:"block truncate",onMouseEnter:x,onMouseLeave:h,children:[e,t&&(0,n.jsx)(l.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lv2 whitespace-pre-wrap break-all select-text cursor-text",style:{left:o.x,top:o.y,maxWidth:o.maxW,maxHeight:o.maxH,transform:o.above?"translateY(-100%)":void 0},onMouseEnter:f,onMouseLeave:p,children:function(e){try{let t=JSON.parse(e);if("object"==typeof t&&null!==t)return JSON.stringify(t,null,2)}catch{}return e}(e)})})]})}function rH({id:e,connectionString:t,displayName:r,selected:l,maximized:a,expandedHeight:i,bubbleContentHeight:d,onSelect:c,onClose:u,onToggleMaximize:m,timestamp:x,onTitleMouseDown:h}){let{t:f}=(0,o.Bd)(),{showToast:p}=(0,q.dj)(),[g,b]=(0,s.useState)("connecting"),[v,j]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)(()=>rB(t)),[C,S]=(0,s.useState)([]),[M,L]=(0,s.useState)(null),[E,P]=(0,s.useState)("table"),[T,$]=(0,s.useState)("data"),[R,I]=(0,s.useState)([]),[F,B]=(0,s.useState)([]),[D,A]=(0,s.useState)([]),[H,O]=(0,s.useState)([]),[W,_]=(0,s.useState)(null),[z,V]=(0,s.useState)(0),[U,K]=(0,s.useState)(!1),[Q,G]=(0,s.useState)(0),[J,Y]=(0,s.useState)(new Set),[X,Z]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)({}),[es,eo]=(0,s.useState)(!1),[el,ea]=(0,s.useState)({}),[ei,ed]=(0,s.useState)({}),[ec,eu]=(0,s.useState)(null),[em,ex]=(0,s.useState)(""),[eh,ef]=(0,s.useState)(null),[ep,eg]=(0,s.useState)(""),[eb,ev]=(0,s.useState)(!1),ej=(0,s.useRef)(null),ew=(0,s.useCallback)(async()=>{b("connecting"),j("");try{let r=await rb("/api/mysql/connect",{id:e,connectionString:t});k(r.schemas||[]);let n=rB(t);r.schemas?.length>0&&n&&r.schemas.includes(n)?N(n):r.schemas?.length>0&&N(r.schemas[0]),b("connected")}catch(e){j(e instanceof Error?e.message:String(e)),b("error")}},[e,t]);(0,s.useEffect)(()=>{ew()},[ew]);let ek=(0,s.useCallback)(async()=>{if("connected"===g)try{let r=await rv("/api/mysql/schemas",{id:e,connectionString:t,schema:y});S(r.tables||[])}catch{}},[e,t,y,g]);(0,s.useEffect)(()=>{ek()},[ek]);let ey=(0,s.useCallback)(async(r,n,s,o)=>{K(!0);let l=s??ei,a=void 0!==o?o:ec;try{let s=`${rF(y)}.${rF(r)}`,{where:o,params:i}=function(e){let t=[],r=[];for(let[n,s]of Object.entries(e)){if(!s.enabled)continue;let e=rF(n);if("IS NULL"===s.op)t.push(`${e} IS NULL`);else if("IS NOT NULL"===s.op)t.push(`${e} IS NOT NULL`);else if("IN"===s.op){let n=s.value.split(",").map(e=>e.trim()).filter(Boolean);if(0===n.length)continue;let o=n.map(e=>(r.push(e),"?"));t.push(`${e} IN (${o.join(", ")})`)}else"LIKE"===s.op||s.op,t.push(`${e} ${s.op} ?`),r.push(s.value)}return{where:t.length>0?` WHERE ${t.join(" AND ")}`:"",params:r}}(l),d=a?` ORDER BY ${rF(a.column)} ${a.dir}`:"",c=`SELECT * FROM ${s}${o}${d} LIMIT 50 OFFSET ${50*n}`,u=await rb("/api/mysql/query",{id:e,connectionString:t,sql:c,params:i});_(u);let m=`SELECT count(*) AS cnt FROM ${s}${o}`,x=await rb("/api/mysql/query",{id:e,connectionString:t,sql:m,params:i});G(x.rows?.[0]?.cnt??0)}catch{}K(!1)},[e,t,y,ei,ec]),eN=(0,s.useCallback)(async r=>{L(r),V(0),et(null),eo(!1),Y(new Set),Z(!1),ed({}),eu(null);try{let n=await rv("/api/mysql/columns",{id:e,connectionString:t,schema:y,table:r});I(n.columns||[]),B(n.primaryKeys||[]),A(n.foreignKeys||[]),O(n.indexes||[])}catch{}ey(r,0,{},null)},[e,t,y,ey]),eC=(0,s.useCallback)(async()=>{if(em.trim()){ev(!0),eg(""),ef(null);try{let r=await rb("/api/mysql/query",{id:e,connectionString:t,sql:em});ef(r)}catch(e){eg(e instanceof Error?e.message:String(e))}ev(!1)}},[e,t,em]),eS=(0,s.useCallback)(async()=>{if(null===ee||!W||!M)return;let r=W.rows[ee],n=[],s=[];for(let e of R)void 0!==er[e.name]&&er[e.name]!==rD(r[e.name]??"")&&(n.push(`${rF(e.name)} = ?`),s.push(""===er[e.name]&&e.nullable?null:er[e.name]));if(0===n.length)return void et(null);let o=F.length>0?F:R.map(e=>e.name),l=[];for(let e of o)null===r[e]||void 0===r[e]?l.push(`${rF(e)} IS NULL`):(l.push(`${rF(e)} = ?`),s.push(r[e]));let a=`UPDATE ${rF(y)}.${rF(M)} SET ${n.join(", ")} WHERE ${l.join(" AND ")}`;try{await rb("/api/mysql/query",{id:e,connectionString:t,sql:a,params:s}),et(null),ey(M,z,ei,ec)}catch(e){alert(`Update failed: ${e instanceof Error?e.message:String(e)}`)}},[ee,W,M,R,F,er,e,t,y,ey,z,ei,ec]),eM=(0,s.useCallback)(async()=>{if(!M)return;let r=[],n=[],s=[];for(let e of R)void 0!==el[e.name]&&""!==el[e.name]&&(r.push(rF(e.name)),n.push(el[e.name]),s.push("?"));if(0===r.length)return;let o=`INSERT INTO ${rF(y)}.${rF(M)} (${r.join(", ")}) VALUES (${s.join(", ")})`;try{await rb("/api/mysql/query",{id:e,connectionString:t,sql:o,params:n}),eo(!1),ea({}),ey(M,z,ei,ec)}catch(e){alert(`Insert failed: ${e instanceof Error?e.message:String(e)}`)}},[M,R,el,e,t,y,ey,z,ei,ec]),eL=(0,s.useCallback)(async()=>{if(0===J.size||!W||!M)return;let r=F.length>0?F:R.map(e=>e.name),n=0;for(let s of Array.from(J).sort((e,t)=>t-e)){let o=W.rows[s];if(!o)continue;let l=[],a=[];for(let e of r)null===o[e]||void 0===o[e]?l.push(`${rF(e)} IS NULL`):(l.push(`${rF(e)} = ?`),a.push(o[e]));let i=`DELETE FROM ${rF(y)}.${rF(M)} WHERE ${l.join(" AND ")} LIMIT 1`;try{await rb("/api/mysql/query",{id:e,connectionString:t,sql:i,params:a})}catch{n++}}Y(new Set),Z(!1),ey(M,z,ei,ec),n>0&&alert(f("mysql.deleteRowsFailed",{count:n}))},[J,W,M,F,R,e,t,y,ey,z,ei,ec]),eE=(0,s.useCallback)(async r=>{if(!M)return;if(J.size>0&&W){let e,t=W.fields.map(e=>e.name),n=Array.from(J).sort((e,t)=>e-t).map(e=>W.rows[e]).filter(Boolean);if("json"===r)e=JSON.stringify(n,null,2);else{let r=[t.join(",")];for(let e of n)r.push(t.map(t=>{let r=e[t];if(null==r)return"";let n="object"==typeof r?JSON.stringify(r):String(r);return n.includes(",")||n.includes('"')||n.includes("\n")?`"${n.replace(/"/g,'""')}"`:n}).join(","));e=r.join("\n")}navigator.clipboard.writeText(e);return}let n=`SELECT * FROM ${rF(y)}.${rF(M)}`;try{let s=await rj("/api/mysql/export",{id:e,connectionString:t,sql:n,format:r}),o=URL.createObjectURL(s),l=document.createElement("a");l.href=o,l.download=`${M}.${r}`,l.click(),URL.revokeObjectURL(o)}catch(e){alert(`Export failed: ${e instanceof Error?e.message:String(e)}`)}},[M,e,t,y,J,W]),eP=(0,s.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),eC())},[eC]),eT=Math.max(1,Math.ceil(Q/50)),e$=(0,s.useCallback)(e=>{M&&(V(e),ey(M,e,ei,ec))},[M,ey,ei,ec]),eR=(0,s.useCallback)((e,t)=>{let r={...ei};t?r[e]=t:delete r[e],ed(r),V(0),Y(new Set),M&&ey(M,0,r,ec)},[ei,ec,M,ey]),eI=(0,s.useCallback)(()=>{ed({}),V(0),Y(new Set),M&&ey(M,0,{},ec)},[ec,M,ey]),eF=(0,s.useCallback)(e=>{eu(e),V(0),Y(new Set),M&&ey(M,0,ei,e)},[ei,M,ey]);return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
15
- relative transition-colors cursor-pointer
16
- ${a?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
17
- ${a?"":l?"border-brand":"border-brand/30"}`,onClick:a?void 0:c,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:h,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${a?"bg-card":"bg-card/50"}`,style:a?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"\uD83D\uDC2C"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===g&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===g&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:f("mysql.connectionFailed")}),"connected"===g&&(0,n.jsx)("span",{className:"text-[10px] text-green-11 flex-shrink-0",children:f("mysql.connected")}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:rI(x)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:a?f("browser.exitMaximize",{modKey:(0,rr.Mu)()}):f("browser.maximize",{modKey:(0,rr.Mu)()}),children:a?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:f("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:a&&i?i-41:d??360},className:"flex overflow-hidden",children:["connecting"===g&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),f("mysql.connecting")]}),"error"===g&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:v}),(0,n.jsx)("button",{onClick:ew,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:f("common.retry")})]}),"connected"===g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[w.length>1?(0,n.jsx)("select",{value:y,onChange:e=>{N(e.target.value),L(null)},className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1",children:w.map(e=>(0,n.jsx)("option",{value:e,children:e},e))}):(0,n.jsx)("span",{className:"flex-1 min-w-0 text-xs text-muted-foreground truncate",children:y}),(0,n.jsx)("button",{onClick:ek,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-hover active:bg-active transition-colors",title:f("mysql.refreshTableList"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsx)("div",{className:"flex items-center border-b border-border",children:["table","view"].map(e=>(0,n.jsx)("button",{onClick:()=>P(e),className:`flex-1 py-1 text-[10px] font-medium transition-colors ${E===e?"text-brand border-b border-brand":"text-muted-foreground hover:text-foreground"}`,children:{table:f("mysql.filterTable"),view:f("mysql.filterView")}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[C.filter(e=>"table"===E?"view"!==e.type:"view"===e.type).map(e=>(0,n.jsxs)("div",{onClick:()=>eN(e.name),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer truncate transition-colors ${M===e.name?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground",children:"view"===e.type?"V":"T"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:(0,n.jsx)(rA,{text:e.name})}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.rowEstimate>0?`~${e.rowEstimate}`:""})]},e.name)),0===C.length&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:f("mysql.noTables")})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["structure","data","sql"].map(e=>(0,n.jsx)("button",{onClick:()=>$(e),className:`px-3 py-1.5 text-xs transition-colors ${T===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{structure:f("mysql.tabStructure"),data:f("mysql.tabData"),sql:"SQL"}[e]},e)),M&&"data"===T&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[Object.values(ei).some(e=>e.enabled)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-brand",children:f("mysql.filterActive",{count:Object.values(ei).filter(e=>e.enabled).length})}),(0,n.jsx)("button",{onClick:eI,className:"px-1 py-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors",title:f("mysql.clearAllFilters"),children:"✕"}),(0,n.jsx)("span",{className:"text-border",children:"|"})]}),J.size>0&&!X&&(0,n.jsx)("button",{onClick:()=>Z(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:f("mysql.deleteNRows",{count:J.size})}),X&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-destructive",children:f("mysql.confirmDeleteRows")}),(0,n.jsx)("button",{onClick:eL,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:f("common.confirm")}),(0,n.jsx)("button",{onClick:()=>Z(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:f("common.cancel")})]}),(0,n.jsx)("button",{onClick:()=>eE("csv"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:J.size>0?f("mysql.copyCsvSelected"):f("mysql.copyCsvAll"),children:J.size>0?f("mysql.copyCSV"):f("mysql.CSV")}),(0,n.jsx)("button",{onClick:()=>eE("json"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:J.size>0?f("mysql.copyJsonSelected"):f("mysql.copyJsonAll"),children:J.size>0?f("mysql.copyJSON"):f("mysql.JSON")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:M||"sql"===T?"structure"===T?(0,n.jsx)(rO,{columns:R,primaryKeys:F,foreignKeys:D,indexes:H}):"data"===T?(0,n.jsx)(r_,{result:W,loading:U,columns:R,page:z,totalPages:eT,totalRows:Q,onPageChange:e$,filters:ei,sort:ec,onFilterChange:eR,onSortChange:eF,selectedRows:J,onSelectedRowsChange:e=>{Y(e),Z(!1)},editingRowIdx:ee,editValues:er,onStartEdit:e=>{if(!W)return;let t=W.rows[e],r={};for(let e of R)r[e.name]=null==t[e.name]?"":rD(t[e.name]);en(r),et(e)},onEditChange:(e,t)=>en(r=>({...r,[e]:t})),onSaveEdit:eS,onCancelEdit:()=>et(null),isAddingRow:es,newRowValues:el,onStartAdd:()=>{eo(!0),ea({})},onNewRowChange:(e,t)=>ea(r=>({...r,[e]:t})),onSaveNewRow:eM,onCancelAdd:()=>{eo(!1),ea({})},onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)(rz,{sqlInput:em,onSqlChange:ex,onExecute:eC,onKeyDown:eP,result:eh,error:ep,loading:eb,sqlRef:ej,onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:f("mysql.selectTable")})})]})]})]}),!a&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===g?"bg-green-500":"error"===g?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:f("common.connecting"),connected:f("common.connected"),error:f("common.connectionFailed")}[g]}),"connected"===g&&M&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:M}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:rI(x)})]})]})})}function rO({columns:e,primaryKeys:t,foreignKeys:r,indexes:s}){let{t:l}=(0,o.Bd)();return 0===e.length?(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:l("mysql.selectTableToView")}):(0,n.jsxs)("div",{className:"p-2 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:l("mysql.columns")}),(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"text-left text-muted-foreground border-b border-border",children:[(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("mysql.colName")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("mysql.colType")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("mysql.colNullable")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("mysql.colDefault")})]})}),(0,n.jsx)("tbody",{children:e.map(e=>(0,n.jsxs)("tr",{className:"border-b border-border/50 hover:bg-hover",children:[(0,n.jsxs)("td",{className:"px-1.5 py-1 font-mono",children:[e.isPrimaryKey&&(0,n.jsx)("span",{className:"text-amber-11 mr-1",title:l("mysql.primaryKey"),children:"\uD83D\uDD11"}),e.name]}),(0,n.jsxs)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono",children:[e.type,e.maxLength?`(${e.maxLength})`:""]}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground",children:e.nullable?"YES":"NO"}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono truncate max-w-[120px]",children:e.default||""})]},e.name))})]})]}),r.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:l("mysql.foreignKeys")}),(0,n.jsx)("div",{className:"space-y-0.5",children:r.map((e,t)=>(0,n.jsxs)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground",children:[e.column," → ",e.refSchema,".",e.refTable,".",e.refColumn]},t))})]}),s.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:l("mysql.indexes")}),(0,n.jsx)("div",{className:"space-y-0.5",children:s.map(e=>(0,n.jsx)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground truncate","data-tooltip":e.definition,children:e.name},e.name))})]})]})}function rW({filter:e,onApply:t,onClear:r,onToggle:a,onClose:i,colName:d,anchorRect:c}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)(e?.op||"="),[h,f]=(0,s.useState)(e?.value||""),p=(0,s.useRef)(null),g=(0,l.F2)();(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&i()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[i]);let b="IS NULL"!==m&&"IS NOT NULL"!==m,v=()=>{(!b||h.trim())&&t({op:m,value:h.trim(),enabled:!0})},j=g?.getBoundingClientRect(),w=j?.left??0,k=j?.top??0,y=j?.width??window.innerWidth,N=c.left-w;N+220>y-8&&(N=y-220-8),N<8&&(N=8);let C=c.bottom+2-k;return(0,n.jsx)(l.ZL,{children:(0,n.jsxs)("div",{ref:p,className:"fixed z-[9998] w-[220px] bg-popover border border-border rounded-md shadow-lv2 p-2 space-y-2",style:{left:N,top:C},onClick:e=>e.stopPropagation(),children:[e&&(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:e=>a(e.target.checked),className:"w-3 h-3 accent-brand"}),u("mysql.enable")]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono truncate max-w-[120px]",children:d})]}),(0,n.jsx)("select",{value:m,onChange:e=>x(e.target.value),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 focus:outline-none focus:ring-1 focus:ring-ring",children:rR.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),b&&(0,n.jsx)("input",{type:"text",value:h,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v())},placeholder:u("IN"===m?"mysql.commaValues":"LIKE"===m?"mysql.likePattern":"mysql.valuePlaceholder"),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:v,disabled:b&&!h.trim(),className:"flex-1 px-2 py-1 text-[10px] bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-40 transition-colors",children:u("mysql.apply")}),e&&(0,n.jsx)("button",{onClick:r,className:"flex-1 px-2 py-1 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground transition-colors",children:u("mysql.clearFilter")})]})]})})}function r_({result:e,loading:t,columns:r,page:l,totalPages:a,totalRows:i,onPageChange:d,filters:c,sort:u,onFilterChange:m,onSortChange:x,selectedRows:h,onSelectedRowsChange:f,editingRowIdx:p,editValues:g,onStartEdit:b,onEditChange:v,onSaveEdit:j,onCancelEdit:w,isAddingRow:k,newRowValues:y,onStartAdd:N,onNewRowChange:C,onSaveNewRow:S,onCancelAdd:M,onCellCopy:L}){let{t:E}=(0,o.Bd)(),[P,T]=(0,s.useState)(null),[$,R]=(0,s.useState)({left:0,bottom:0});if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(null!==P?(e.stopPropagation(),T(null)):null!==p?(e.stopPropagation(),w()):k&&(e.stopPropagation(),M()))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[P,p,k,w,M]),!e&&!t)return(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:E("mysql.selectTableForData")});let I=e?.fields||[],F=e?.rows||[],B={};for(let e of r)B[e.name]=e.type+(e.maxLength?`(${e.maxLength})`:"");let D=F.length>0&&h.size===F.length,A=h.size>0&&!D;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",children:[t&&(0,n.jsx)("div",{className:"absolute inset-0 bg-background/50 flex items-center justify-center z-10",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[2]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-1 py-1 border-b border-border w-8 text-center",children:(0,n.jsx)("input",{type:"checkbox",checked:D,ref:e=>{e&&(e.indeterminate=A)},onChange:()=>{D?f(new Set):f(new Set(F.map((e,t)=>t)))},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(e=>{let t=u?.column===e.name?u.dir:null,r=c[e.name],s=r?.enabled;return(0,n.jsxs)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono relative",children:[(0,n.jsxs)("span",{className:"cursor-pointer select-none hover:text-foreground transition-colors",onClick:()=>{var t;return t=e.name,void(u?.column===t?"ASC"===u.dir?x({column:t,dir:"DESC"}):x(null):x({column:t,dir:"ASC"}))},children:[e.name,B[e.name]&&(0,n.jsx)("span",{className:"ml-1 text-[9px] text-muted-foreground/60 font-normal",children:B[e.name]}),"ASC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↑"}),"DESC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↓"})]}),(0,n.jsx)("button",{onClick:t=>{if(t.stopPropagation(),P===e.name)return void T(null);let r=t.currentTarget.closest("th").getBoundingClientRect();R({left:r.left,bottom:r.bottom}),T(e.name)},className:`ml-1 inline-flex items-center transition-colors ${s?"text-brand":"text-muted-foreground/40 hover:text-muted-foreground"}`,children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 16 16",fill:"currentColor",children:(0,n.jsx)("path",{d:"M1 2h14l-5.5 6.5V14l-3-2v-3.5z"})})}),P===e.name&&(0,n.jsx)(rW,{filter:r||null,onApply:t=>{m(e.name,t),T(null)},onClear:()=>{m(e.name,null),T(null)},onToggle:t=>{r&&m(e.name,{...r,enabled:t})},onClose:()=>T(null),colName:e.name,anchorRect:$})]},e.name)})]})}),(0,n.jsxs)("tbody",{children:[k&&(0,n.jsxs)("tr",{className:"bg-emerald-500/5",children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border text-center",children:(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:S,className:"text-[10px] text-green-11 hover:text-green-9",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:M,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]})}),I.map(e=>(0,n.jsx)("td",{className:"px-0.5 py-0.5 border-b border-border",children:(0,n.jsx)("input",{type:"text",value:y[e.name]??"",onChange:t=>C(e.name,t.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]",placeholder:"NULL"})},e.name))]}),F.map((e,t)=>(0,n.jsxs)("tr",{className:`hover:bg-hover ${h.has(t)?"bg-brand/5":""} ${p===t?"bg-blue-500/5":""}`,children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border/50 text-center",children:p===t?(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:j,className:"text-[10px] text-green-11 hover:text-green-9",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:w,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]}):(0,n.jsx)("input",{type:"checkbox",checked:h.has(t),onChange:()=>{let e;(e=new Set(h)).has(t)?e.delete(t):e.add(t),f(e)},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(r=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onDoubleClick:()=>{null===p&&b(t)},onContextMenu:t=>{t.preventDefault(),L(rD(e[r.name]))},children:p===t?(0,n.jsx)("input",{type:"text",value:g[r.name]??"",onChange:e=>v(r.name,e.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]"}):null===e[r.name]||void 0===e[r.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rA,{text:rD(e[r.name])})},r.name))]},t))]})]}),0===F.length&&!t&&(0,n.jsx)("div",{className:"p-4 text-xs text-muted-foreground text-center",children:E("common.noData")})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-2 py-1 border-t border-border text-[10px] text-muted-foreground bg-card/30 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:N,disabled:k,className:"px-1.5 py-0.5 text-[10px] text-green-11 hover:text-green-9 disabled:opacity-30",children:E("mysql.addRow")}),(0,n.jsx)("span",{children:E("mysql.totalRows",{count:i})}),e?.duration!==void 0&&(0,n.jsxs)("span",{children:[e.duration,"ms"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>d(l-1),disabled:0===l,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"◀"}),(0,n.jsxs)("span",{children:[l+1," / ",a]}),(0,n.jsx)("button",{onClick:()=>d(l+1),disabled:l>=a-1,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"▶"})]})]})]})}function rz({sqlInput:e,onSqlChange:t,onExecute:r,onKeyDown:s,result:l,error:a,loading:i,sqlRef:d,onCellCopy:c}){let{t:u}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 p-2 border-b border-border",children:[(0,n.jsx)("textarea",{ref:d,value:e,onChange:e=>t(e.target.value),onKeyDown:s,placeholder:u("mysql.sqlPlaceholder",{modKey:(0,rr.Mu)()}),className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("button",{onClick:r,disabled:i||!e.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:u(i?"mysql.executing":"mysql.execute")}),l?.duration!==void 0&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[l.command&&!l.fields?u("mysql.rowsAffected",{command:l.command,count:l.rowCount,duration:l.duration}):u("mysql.queryRows",{count:l.rows?.length??0,duration:l.duration}),l.truncated&&` ${u("mysql.resultTruncated")}`]})]})]}),a&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-destructive bg-destructive/5 border-b border-border break-all",children:a}),l?.fields&&l.rows&&(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:l.fields.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e.name},e.name))})}),(0,n.jsx)("tbody",{children:l.rows.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-hover",children:l.fields.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onContextMenu:r=>{r.preventDefault(),c(rD(e[t.name]))},children:null===e[t.name]||void 0===e[t.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rA,{text:rD(e[t.name])})},t.name))},t))})]})})]})}rc({type:"mysql",idPrefix:"mysql",match:e=>e.trim().toLowerCase().startsWith("mysql://"),parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"mysql";r=`${n}@${e.hostname}${e.port?":"+e.port:""}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(rH,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await rh("mysql",e.id)}});let rq={string:{label:"S",color:"text-emerald-600 dark:text-emerald-400 bg-emerald-500/15"},hash:{label:"H",color:"text-blue-600 dark:text-blue-400 bg-blue-500/15"},list:{label:"L",color:"text-orange-600 dark:text-orange-400 bg-orange-500/15"},set:{label:"SET",color:"text-teal-600 dark:text-teal-400 bg-teal-500/15"},zset:{label:"Z",color:"text-purple-600 dark:text-purple-400 bg-purple-500/15"},stream:{label:"STR",color:"text-pink-600 dark:text-pink-400 bg-pink-500/15"}};function rV({type:e}){let t=rq[e]||{label:"?",color:"text-muted-foreground bg-muted"};return(0,n.jsx)("span",{className:`inline-block text-[9px] font-mono font-bold leading-none px-1 py-0.5 rounded flex-shrink-0 ${t.color}`,children:t.label})}function rU({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,above:!0}),i=(0,s.useRef)(null),d=(0,s.useRef)(null),c=(0,l.F2)(),u=(0,s.useCallback)(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{let e=i.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=c?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,l=n?.height??window.innerHeight,d=t.top-o,u=t.bottom-o,m=d>l/2;a({x:t.left-s,y:m?d-4:u+4,above:m}),r(!0)},350)},[c]),m=(0,s.useCallback)(()=>{d.current&&clearTimeout(d.current),r(!1)},[]);return(0,n.jsxs)("span",{ref:i,className:"block truncate",onMouseEnter:u,onMouseLeave:m,children:[e,t&&(0,n.jsx)(l.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] max-w-[500px] max-h-[200px] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lv2 whitespace-pre-wrap break-all select-text",style:{left:o.x,top:o.y,transform:o.above?"translateY(-100%)":void 0},children:e})})]})}function rK({id:e,connectionString:t,displayName:r,selected:l,maximized:a,expandedHeight:i,bubbleContentHeight:d,onSelect:c,onClose:u,onToggleMaximize:m,timestamp:x,onTitleMouseDown:h}){var f;let{t:p}=(0,o.Bd)(),{showToast:g}=(0,q.dj)(),[b,v]=(0,s.useState)("connecting"),[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)([]),[S,M]=(0,s.useState)("0"),[L,E]=(0,s.useState)(!1),[P,T]=(0,s.useState)("*"),[$,R]=(0,s.useState)(!1),[I,F]=(0,s.useState)(null),[B,D]=(0,s.useState)(null),[A,H]=(0,s.useState)(!1),[O,W]=(0,s.useState)(null),[_,z]=(0,s.useState)(!1),[V,U]=(0,s.useState)("data"),[K,Q]=(0,s.useState)(""),[G,J]=(0,s.useState)(""),[Y,X]=(0,s.useState)([]),[Z,ee]=(0,s.useState)(!1),et=(0,s.useRef)(null),er=(0,s.useRef)(null),en=(0,s.useCallback)(async()=>{v("connecting"),w("");try{let r=await rb("/api/redis/connect",{id:e,connectionString:t});y(r),v("connected")}catch(e){w(e instanceof Error?e.message:String(e)),v("error")}},[e,t]);(0,s.useEffect)(()=>{en()},[en]);let es=(0,s.useCallback)(async(r,n,s)=>{R(!0);try{let o=await rb("/api/redis/keys",{id:e,connectionString:t,pattern:r,cursor:n,count:200});C(e=>s?[...e,...o.keys]:o.keys),M(o.cursor),E(o.hasMore)}catch{}R(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===b&&es(P,"0",!1)},[b]);let eo=(0,s.useCallback)(()=>{F(null),D(null),es(P,"0",!1)},[P,es]),el=(0,s.useCallback)(async r=>{F(r),H(!0),W(null),z(!1);try{let n=await rb("/api/redis/get",{id:e,connectionString:t,key:r});D(n)}catch(e){D(null),g(e instanceof Error?e.message:p("redis.loadFailed"))}H(!1)},[e,t,g]),ea=(0,s.useCallback)(async()=>{if(I)try{await rb("/api/redis/delete",{id:e,connectionString:t,keys:[I]}),F(null),D(null),z(!1),es(P,"0",!1)}catch(e){g(e instanceof Error?e.message:p("redis.deleteFailed"))}},[I,e,t,P,es,g]),ei=(0,s.useCallback)(async()=>{if(I&&null!==O)try{await rb("/api/redis/set",{id:e,connectionString:t,key:I,value:O,type:"string"}),W(null),el(I),g(p("common.saved"))}catch(e){g(e instanceof Error?e.message:p("redis.saveFailed"))}},[I,O,e,t,el,g]),ed=(0,s.useCallback)(async()=>{try{let r=await rb("/api/redis/command",{id:e,connectionString:t,command:"INFO"});Q("string"==typeof r.result?r.result:String(r.result))}catch{}},[e,t]);(0,s.useEffect)(()=>{"connected"===b&&"info"===V&&ed()},[b,V,ed]);let ec=(0,s.useCallback)(async()=>{let r,n=G.trim();if(!n)return;ee(!0),J("");let s=[],o=/(?:"([^"]*)")|(?:'([^']*)')|(\S+)/g;for(;null!==(r=o.exec(n));)s.push(r[1]??r[2]??r[3]);let l=s[0]||"",a=s.slice(1);try{let r=await rb("/api/redis/command",{id:e,connectionString:t,command:l,args:a});X(e=>[...e,{command:n,result:r.result,duration:r.duration,isError:!1}])}catch(e){X(t=>[...t,{command:n,result:e instanceof Error?e.message:String(e),duration:0,isError:!0}])}ee(!1)},[G,e,t]);return(0,s.useEffect)(()=>{et.current?.scrollIntoView({behavior:"smooth"})},[Y]),(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
18
- relative transition-colors cursor-pointer
19
- ${a?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
20
- ${a?"":l?"border-brand":"border-brand/30"}`,onClick:a?void 0:c,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:h,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${a?"bg-card":"bg-card/50"}`,style:a?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"♦"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===b&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===b&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:p("common.connectionFailed")}),"connected"===b&&k&&(0,n.jsxs)("span",{className:"text-[10px] text-red-11 flex-shrink-0",children:["v",k.version," \xb7 ",k.dbSize," keys \xb7 ",k.memory]}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:function(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}(x)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:a?p("browser.exitMaximize",{modKey:(0,rr.Mu)()}):p("browser.maximize",{modKey:(0,rr.Mu)()}),children:a?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:p("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:a&&i?i-41:d??360},className:"flex overflow-hidden",children:["connecting"===b&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),p("common.connecting"),"..."]}),"error"===b&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:j}),(0,n.jsx)("button",{onClick:en,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:p("common.retry")})]}),"connected"===b&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[(0,n.jsx)("input",{type:"text",value:P,onChange:e=>T(e.target.value),onKeyDown:e=>{"Enter"===e.key&&eo()},placeholder:p("redis.scanPlaceholder"),className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("button",{onClick:eo,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-hover active:bg-active transition-colors",title:p("redis.scanSearch"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"6.5",cy:"6.5",r:"4.5"}),(0,n.jsx)("path",{d:"M10 10l4 4"})]})}),(0,n.jsx)("button",{onClick:()=>es(P,"0",!1),className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-hover active:bg-active transition-colors",title:p("common.refresh"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[N.map(e=>(0,n.jsxs)("div",{onClick:()=>el(e.key),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer transition-colors ${I===e.key?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)(rV,{type:e.type}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:(0,n.jsx)(rU,{text:e.key})})]},e.key)),0===N.length&&!$&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:p("redis.noKeys")}),$&&(0,n.jsx)("div",{className:"p-2 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"})}),L&&!$&&(0,n.jsx)("button",{onClick:()=>es(P,S,!0),className:"w-full py-1.5 text-[10px] text-brand hover:text-brand/80 transition-colors",children:p("redis.loadMore")})]}),(0,n.jsxs)("div",{className:"px-2 py-1 border-t border-border text-[10px] text-muted-foreground",children:[N.length," keys",L?"+":"",k?` / ${k.dbSize} total`:""]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["data","info","cli"].map(e=>(0,n.jsx)("button",{onClick:()=>U(e),className:`px-3 py-1.5 text-xs transition-colors ${V===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{data:p("redis.tabData"),info:p("redis.tabInfo"),cli:"CLI"}[e]},e)),I&&"data"===V&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[B&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:["TTL: ",function(e,t){if(-1===e)return t("redis.neverExpires");if(-2===e)return t("redis.expired");if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m${e%60>0?` ${e%60}s`:""}`;let r=Math.floor(e/3600),n=Math.floor(e%3600/60);return`${r}h${n>0?` ${n}m`:""}`}(B.ttl,p),null!==B.size?` \xb7 ${null==(f=B.size)?"":f<1024?`${f} B`:f<1048576?`${(f/1024).toFixed(1)} KB`:`${(f/1048576).toFixed(1)} MB`}`:""]}),_?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-[10px] text-destructive",children:[p("common.confirm"),"?"]}),(0,n.jsx)("button",{onClick:ea,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:p("common.confirm")}),(0,n.jsx)("button",{onClick:()=>z(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:p("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>z(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:p("common.delete")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:"data"===V?(0,n.jsx)(rQ,{selectedKey:I,keyValue:B,keyLoading:A,editingValue:O,onStartEdit:e=>W(e),onEditChange:W,onSaveEdit:ei,onCancelEdit:()=>W(null),onCellCopy:e=>{navigator.clipboard.writeText(e),g(p("common.copied"))}}):"info"===V?(0,n.jsx)(rG,{infoText:K,onRefresh:ed}):(0,n.jsx)(rJ,{cliInput:G,onInputChange:J,onExecute:ec,history:Y,loading:Z,endRef:et,inputRef:er})})]})]})]})]})})}function rQ({selectedKey:e,keyValue:t,keyLoading:r,editingValue:s,onStartEdit:l,onEditChange:a,onSaveEdit:i,onCancelEdit:d,onCellCopy:c}){let{t:u}=(0,o.Bd)();if(!e)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.selectKey")});if(r)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if(!t)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.keyNotExist")});let{type:m,value:x}=t;if("string"===m){let t=String(x??""),r=null!==s;return(0,n.jsxs)("div",{className:"p-3 h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)(rV,{type:"string"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsx)("span",{className:"flex-1"}),r?(0,n.jsxs)("div",{className:"flex gap-1",children:[(0,n.jsx)("button",{onClick:i,className:"px-2 py-0.5 text-[10px] text-white bg-brand rounded hover:bg-brand/90",children:u("common.save")}),(0,n.jsx)("button",{onClick:d,className:"px-2 py-0.5 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground",children:u("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>l(t),className:"px-2 py-0.5 text-[10px] text-brand hover:text-brand/80 bg-brand/10 rounded transition-colors",children:u("common.edit")})]}),r?(0,n.jsx)("textarea",{value:s,onChange:e=>a(e.target.value),className:"flex-1 w-full px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-none focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}):(0,n.jsx)("pre",{className:"flex-1 overflow-auto text-xs font-mono bg-muted/30 rounded p-2 whitespace-pre-wrap break-all select-text cursor-text",onContextMenu:e=>{e.preventDefault(),c(t)},children:t})]})}if("hash"===m){let t=Object.entries(x||{});return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rV,{type:"hash"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[t.length," fields"]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-1/3",children:"Field"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Value"})]})}),(0,n.jsx)("tbody",{children:t.map(([e,t])=>(0,n.jsxs)("tr",{className:"hover:bg-hover",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[150px]",onContextMenu:t=>{t.preventDefault(),c(e)},children:(0,n.jsx)(rU,{text:e})}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:e=>{e.preventDefault(),c(t)},children:(0,n.jsx)(rU,{text:t})})]},e))})]})})]})}if("list"===m){let t=x?.items||[],r=x?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rV,{type:"list"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nItems",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-16",children:"#"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Value"})]})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsxs)("tr",{className:"hover:bg-hover",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 text-muted-foreground",children:t}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:t=>{t.preventDefault(),c(e)},children:(0,n.jsx)(rU,{text:e})})]},t))})]})})]})}if("set"===m){let t=x?.items||[],r=x?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rV,{type:"set"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nMembers",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Member"})})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-hover",children:(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[400px]",onContextMenu:t=>{t.preventDefault(),c(e)},children:(0,n.jsx)(rU,{text:e})})},t))})]})})]})}if("zset"===m){let t=x?.items||[],r=x?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rV,{type:"zset"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nMembers",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Member"}),(0,n.jsx)("th",{className:"px-2 py-1 text-right text-muted-foreground font-medium border-b border-border w-28",children:"Score"})]})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsxs)("tr",{className:"hover:bg-hover",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:t=>{t.preventDefault(),c(e.member)},children:(0,n.jsx)(rU,{text:e.member})}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono text-right text-muted-foreground",children:e.score})]},t))})]})})]})}if("stream"===m){let t=x?.entries||[],r=x?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rV,{type:"stream"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nEntries",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-40",children:"ID"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Fields"})]})}),(0,n.jsx)("tbody",{children:t.map(([e,t])=>{let r=[];for(let e=0;e<t.length;e+=2)r.push(`${t[e]}: ${t[e+1]}`);return(0,n.jsxs)("tr",{className:"hover:bg-hover",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono text-muted-foreground",children:e}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",children:(0,n.jsx)(rU,{text:r.join(", ")})})]},e)})})]})})]})}return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.unsupportedType",{type:m})})}function rG({infoText:e,onRefresh:t}){let{t:r}=(0,o.Bd)();if(!e)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})});let s=[],l=null;for(let t of e.split("\n")){let e=t.trim();if(e){if(e.startsWith("#"))l={title:e.replace(/^#\s*/,""),items:[]},s.push(l);else if(l&&e.includes(":")){let t=e.indexOf(":");l.items.push({key:e.slice(0,t),value:e.slice(t+1)})}}}return(0,n.jsxs)("div",{className:"p-2 space-y-3 overflow-auto h-full",children:[(0,n.jsx)("div",{className:"flex justify-end",children:(0,n.jsx)("button",{onClick:t,className:"px-2 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:r("common.refresh")})}),s.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1 font-medium",children:e.title}),(0,n.jsx)("div",{className:"space-y-0",children:e.items.map(({key:e,value:t})=>(0,n.jsxs)("div",{className:"flex items-start gap-2 px-1.5 py-0.5 text-xs hover:bg-hover rounded",children:[(0,n.jsx)("span",{className:"text-muted-foreground font-mono flex-shrink-0 w-48 truncate",children:e}),(0,n.jsx)("span",{className:"font-mono text-foreground break-all",children:t})]},e))})]},e.title))]})}function rJ({cliInput:e,onInputChange:t,onExecute:r,history:s,loading:l,endRef:a,inputRef:i}){let{t:d}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto p-2 font-mono text-xs space-y-2",onClick:()=>i.current?.focus(),children:[0===s.length&&(0,n.jsx)("div",{className:"text-muted-foreground text-center py-4",children:d("redis.cliHint")}),s.map((e,t)=>(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"text-brand",children:[(0,n.jsx)("span",{className:"text-muted-foreground mr-1",children:">"}),e.command,e.duration>0&&(0,n.jsxs)("span",{className:"text-muted-foreground/50 ml-2",children:["(",e.duration,"ms)"]})]}),(0,n.jsx)("pre",{className:`whitespace-pre-wrap break-all mt-0.5 ${e.isError?"text-destructive":"text-foreground"}`,children:e.isError?`(error) ${e.result}`:function e(t,r=0){let n=" ".repeat(r);return null===t?`${n}(nil)`:"number"==typeof t?`${n}(integer) ${t}`:"string"==typeof t?`${n}"${t}"`:Array.isArray(t)?0===t.length?`${n}(empty array)`:t.map((t,r)=>`${n}${r+1}) ${e(t,0)}`).join("\n"):`${n}${String(t)}`}(e.result)})]},t)),(0,n.jsx)("div",{ref:a})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1.5 border-t border-border bg-card/30 flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-xs text-brand font-mono flex-shrink-0",children:">"}),(0,n.jsx)("input",{ref:i,type:"text",value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{"Enter"!==e.key||l||r()},placeholder:d("redis.cliPlaceholder"),className:"flex-1 min-w-0 text-xs font-mono bg-transparent border-0 focus:outline-none",autoComplete:"off",spellCheck:!1,disabled:l}),l&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"})]})]})}rc({type:"redis",idPrefix:"redis",match(e){let t=e.trim().toLowerCase();return t.startsWith("redis://")||t.startsWith("rediss://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"0";r=`db${n}@${e.hostname}${e.port?":"+e.port:":6379"}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(rK,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await rh("redis",e.id)}});let rY=/^([\d.]+)\s+([\d.]+)%\s+([\d.]+)%$/;function rX(e,t,r){if(!e)return r;let n=getComputedStyle(e).getPropertyValue(t).trim();if(!n)return r;let s=rY.exec(n);if(!s)return n;let o=Number(s[1]),l=Number(s[2])/100,a=Number(s[3])/100,i=(1-Math.abs(2*a-1))*l,d=i*(1-Math.abs(o/60%2-1)),c=a-i/2,[u,m,x]=[[i,d,0],[d,i,0],[0,i,d],[0,d,i],[d,0,i],[i,0,d]][Math.floor(o/60)%6],h=e=>Math.round((e+c)*255).toString(16).padStart(2,"0");return`#${h(u)}${h(m)}${h(x)}`}let rZ=["#4C8BF5","#E74C3C","#2ECC71","#F39C12","#9B59B6","#1ABC9C","#E67E22","#3498DB","#E91E63","#00BCD4"];function r0(e,t){return rZ[t.indexOf(e)%rZ.length]}function r1(e){if(!e)return"";let t=new Date(e);return isNaN(t.getTime())?"":`${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function r2({nodes:e,rels:t,allLabels:r}){let o=(0,s.useRef)(null),l=(0,s.useRef)(null),a=(0,e_.Ql)()?.resolvedTheme??"dark",i=(0,s.useRef)([]),d=(0,s.useRef)(0),c=(0,s.useRef)(null),u=(0,s.useRef)({w:0,h:0}),m=(0,s.useRef)(new Map),[x,h]=(0,s.useState)(null),f=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=o.current;if(!e)return;let t=new ResizeObserver(e=>{let{width:t,height:r}=e[0].contentRect,n=u.current;if(t===n.w&&r===n.h)return;if(n.w>0&&n.h>0&&i.current.length>0){let e=t/n.w,s=r/n.h;i.current.forEach(t=>{t.x=(t.x||0)*e,t.y=(t.y||0)*s})}u.current={w:t,h:r};let s=l.current;s&&(s.width=t,s.height=r)});return t.observe(e),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{let{w:t,h:r}=u.current,n=t||o.current?.clientWidth||600,s=r||o.current?.clientHeight||400;0===t&&(u.current={w:n,h:s}),i.current=e.map((t,r)=>({...t,x:t.x??n/2+Math.cos(2*r*Math.PI/e.length)*Math.min(n,s)*.3,y:t.y??s/2+Math.sin(2*r*Math.PI/e.length)*Math.min(n,s)*.3,vx:0,vy:0})),m.current=new Map(i.current.map(e=>[e.id,e]))},[e]),(0,s.useEffect)(()=>{let e=m.current,n=l.current,s=rX(n,"--foreground-faint","#666"),o=rX(n,"--foreground-subtle","#999"),a=rX(n,"--accent","#27272a"),x=rX(n,"--foreground","#fff");return d.current=requestAnimationFrame(function n(){let{w:m,h}=u.current;if(0===m||0===h){d.current=requestAnimationFrame(n);return}let p=i.current;p.forEach(e=>{e.vx=(e.vx||0)+(m/2-(e.x||0))*.001,e.vy=(e.vy||0)+(h/2-(e.y||0))*.001});for(let e=0;e<p.length;e++)for(let t=e+1;t<p.length;t++){let r=(p[e].x||0)-(p[t].x||0),n=(p[e].y||0)-(p[t].y||0),s=Math.sqrt(r*r+n*n)||1,o=2e3/(s*s),l=r/s*o,a=n/s*o;p[e].vx+=l,p[t].vx-=l,p[e].vy+=a,p[t].vy-=a}t.forEach(t=>{let r=e.get(t.startId),n=e.get(t.endId);if(!r||!n)return;let s=(n.x||0)-(r.x||0),o=(n.y||0)-(r.y||0),l=Math.sqrt(s*s+o*o)||1,a=(l-100)*.01,i=s/l*a,d=o/l*a;r.vx+=i,n.vx-=i,r.vy+=d,n.vy-=d}),p.forEach(e=>{c.current?.nodeId!==e.id&&(e.vx=.6*(e.vx||0),e.vy=.6*(e.vy||0),e.x=Math.max(20,Math.min(m-20,(e.x||0)+.1*(e.vx||0))),e.y=Math.max(20,Math.min(h-20,(e.y||0)+.1*(e.vy||0))))});let g=l.current?.getContext("2d");g&&(g.clearRect(0,0,m,h),g.lineWidth=1.5,t.forEach(t=>{let r=e.get(t.startId),n=e.get(t.endId);if(!r||!n)return;g.strokeStyle=s,g.beginPath(),g.moveTo(r.x,r.y),g.lineTo(n.x,n.y),g.stroke();let l=Math.atan2(n.y-r.y,n.x-r.x),a=n.x-24*Math.cos(l),i=n.y-24*Math.sin(l);g.fillStyle=s,g.beginPath(),g.moveTo(a,i),g.lineTo(a-8*Math.cos(l-.3),i-8*Math.sin(l-.3)),g.lineTo(a-8*Math.cos(l+.3),i-8*Math.sin(l+.3)),g.closePath(),g.fill(),g.font="9px system-ui",g.fillStyle=o,g.textAlign="center",g.fillText(t.type,(r.x+n.x)/2,(r.y+n.y)/2-4)}),p.forEach(e=>{let t=e.labels[0]||"",n=t?r0(t,r):"#6b7280";g.beginPath(),g.arc(e.x,e.y,20,0,2*Math.PI),g.fillStyle=n,g.fill();let s=f.current?.id===e.id;g.strokeStyle=s?x:a,g.lineWidth=s?2.5:1,g.stroke(),g.font="10px system-ui",g.fillStyle="#fff",g.textAlign="center",g.textBaseline="middle";let o=String(e.properties.name||e.properties.title||e.properties.id||t||e.id);g.fillText(o.length>8?o.slice(0,7)+"…":o,e.x,e.y)}),d.current=requestAnimationFrame(n))}),()=>cancelAnimationFrame(d.current)},[e,t,r,a]);let p=(0,s.useCallback)(e=>{let t=l.current?.getBoundingClientRect();if(!t)return null;let r=e.clientX-t.left,n=e.clientY-t.top;return i.current.find(e=>{let t=(e.x||0)-r,s=(e.y||0)-n;return t*t+s*s<400})||null},[]);return(0,n.jsxs)("div",{ref:o,className:"relative w-full h-full",children:[(0,n.jsx)("canvas",{ref:l,className:"cursor-grab active:cursor-grabbing absolute inset-0",onMouseDown:e=>{let t=p(e);if(t){let r=l.current.getBoundingClientRect();c.current={nodeId:t.id,offsetX:e.clientX-r.left-(t.x||0),offsetY:e.clientY-r.top-(t.y||0)}}},onMouseMove:e=>{if(c.current){let t=l.current.getBoundingClientRect(),r=i.current.find(e=>e.id===c.current.nodeId);r&&(r.x=e.clientX-t.left-c.current.offsetX,r.y=e.clientY-t.top-c.current.offsetY,r.vx=0,r.vy=0)}else{let t=p(e);f.current=t,h(t)}},onMouseUp:()=>{c.current=null},onMouseLeave:()=>{c.current=null,f.current=null,h(null)}}),x&&!c.current&&(0,n.jsxs)("div",{className:"absolute top-2 left-2 bg-popover text-popover-foreground border border-border rounded px-2 py-1 text-xs max-w-[300px] pointer-events-none",children:[(0,n.jsxs)("div",{className:"font-medium",children:[x.labels.join(", ")," #",String(x.id)]}),Object.entries(x.properties).slice(0,8).map(([e,t])=>(0,n.jsxs)("div",{className:"truncate",children:[(0,n.jsxs)("span",{className:"text-muted-foreground",children:[e,":"]})," ",String(t)]},e))]})]})}function r5({id:e,connectionString:t,displayName:r,selected:o,maximized:l,expandedHeight:a,bubbleContentHeight:i,onSelect:d,onClose:c,onToggleMaximize:u,timestamp:m,onTitleMouseDown:x}){let[h,f]=(0,s.useState)("connecting"),[p,g]=(0,s.useState)(""),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)("labels"),[S,M]=(0,s.useState)(""),[L,E]=(0,s.useState)(null),[P,T]=(0,s.useState)(!1),[$,R]=(0,s.useState)(""),I=(0,s.useRef)(null),[F,B]=(0,s.useState)([]),[D,A]=(0,s.useState)([]),[H,O]=(0,s.useState)("schema"),W=(0,s.useCallback)(async()=>{f("connecting");try{let r=await rb("/api/neo4j/connect",{id:e,connectionString:t});v(r),f("connected")}catch(e){g(e instanceof Error?e.message:String(e)),f("error")}},[e,t]);(0,s.useEffect)(()=>{W()},[W]);let _=(0,s.useCallback)(async()=>{y(!0);try{let r=await rb("/api/neo4j/schema",{id:e,connectionString:t});w(r)}catch{}y(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===h&&_()},[h,_]);let z=(0,s.useCallback)(async r=>{let n=r||S.trim();if(n){T(!0),R("");try{var s;let r,o,l=await rb("/api/neo4j/query",{id:e,connectionString:t,cypher:n});E(l);let{nodes:a,rels:i}=(s=l.records,r=new Map,o=[],s.forEach(e=>Object.values(e).forEach(function e(t){if(t&&"object"==typeof t)if("node"===t._type){let e=t._id;r.has(e)||r.set(e,{id:e,labels:t._labels||[],properties:Object.fromEntries(Object.entries(t).filter(([e])=>!e.startsWith("_")))})}else if("relationship"===t._type)o.push({id:t._id,type:t._relType,startId:t._start,endId:t._end,properties:Object.fromEntries(Object.entries(t).filter(([e])=>!e.startsWith("_")))});else if("path"===t._type){let r=t.segments;r?.forEach(t=>{e(t.start),e(t.relationship),e(t.end)})}else Array.isArray(t)&&t.forEach(e)})),{nodes:Array.from(r.values()),rels:o});a.length>0&&(B(a),A(i))}catch(e){R(e instanceof Error?e.message:String(e))}T(!1)}},[e,t,S]),q=(0,s.useCallback)(e=>{let t=`MATCH (n:\`${e}\`) RETURN n LIMIT 25`;M(t),O("cypher"),z(t)},[z]),V=(0,s.useCallback)(e=>{let t=`MATCH (a)-[r:\`${e}\`]->(b) RETURN a, r, b LIMIT 25`;M(t),O("graph"),z(t)},[z]);return(0,n.jsx)("div",{className:"flex flex-col items-start",onClick:d,children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground relative transition-colors ${o?"ring-1 ring-ring":""} rounded-lg overflow-hidden`,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:u,onMouseDown:x,className:"flex items-center gap-2 px-4 py-1.5 border-b border-border cursor-grab active:cursor-grabbing select-none",children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"⬡"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===h&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"connected"===h&&(0,n.jsx)("span",{className:"text-[10px] text-green-11 flex-shrink-0",children:"Connected"}),"error"===h&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:"Error"}),m&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:r1(m)}),"connected"===h&&b&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:["v",b.version," \xb7 ",b.nodeCount.toLocaleString(),"n \xb7 ",b.relationshipCount.toLocaleString(),"r"]}),(0,n.jsx)("span",{className:"flex-1"}),"connected"===h&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),_(),W()},disabled:k,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0 disabled:opacity-40",title:"Refresh",children:(0,n.jsx)("svg",{className:`w-3.5 h-3.5 ${k?"animate-spin":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.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,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:l?(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 9V4.5M9 9H4.5M9 9L3.75 3.75M9 15v4.5M9 15H4.5M9 15l-5.25 5.25M15 9h4.5M15 9V4.5M15 9l5.25-5.25M15 15h4.5M15 15v4.5m0-4.5l5.25 5.25"}):(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9M3.75 20.25v-4.5m0 4.5h4.5m-4.5 0L9 15M20.25 3.75h-4.5m4.5 0v4.5m0-4.5L15 9m5.25 11.25h-4.5m4.5 0v-4.5m0 4.5L15 15"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:l&&a?a-41:i??360},className:"flex flex-col overflow-hidden",children:["connecting"===h&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Connecting..."]}),"error"===h&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-xs p-4 gap-2",children:[(0,n.jsx)("p",{className:"text-destructive",children:p}),(0,n.jsx)("button",{onClick:W,className:"px-3 py-1 rounded text-xs bg-brand text-white hover:bg-brand/90 transition-colors",children:"Retry"})]}),"connected"===h&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:["schema","cypher","graph"].map(e=>(0,n.jsx)("button",{onClick:()=>O(e),className:`px-3 py-1.5 text-xs transition-colors ${H===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{schema:"Schema",cypher:"Cypher",graph:"Graph"}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden flex",children:["schema"===H&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-40 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:(0,n.jsx)("div",{className:"flex-1 overflow-y-auto text-xs",children:[{key:"labels",label:"Labels",count:j?.labels.length},{key:"relationships",label:"Relationships",count:j?.relationshipTypes.length},{key:"properties",label:"Properties",count:j?.propertyKeys.length},{key:"indexes",label:"Indexes",count:j?.indexes.length},{key:"constraints",label:"Constraints",count:j?.constraints.length}].map(e=>(0,n.jsxs)("div",{onClick:()=>C(e.key),className:`flex items-center gap-1.5 px-2 py-1.5 cursor-pointer truncate transition-colors ${N===e.key?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:e.label}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count??0})]},e.key))})}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[k&&(0,n.jsxs)("div",{className:"flex items-center justify-center p-4 gap-2 text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"})," Loading..."]}),!k&&"labels"===N&&j?.labels.map(e=>(0,n.jsxs)("div",{onClick:()=>q(e.name),className:"flex items-center gap-1.5 px-2 py-1 cursor-pointer hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:r0(e.name,j.labels.map(e=>e.name))}}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:e.name}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count.toLocaleString()})]},e.name)),!k&&"relationships"===N&&j?.relationshipTypes.map(e=>(0,n.jsxs)("div",{onClick:()=>V(e.name),className:"flex items-center gap-1.5 px-2 py-1 cursor-pointer hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:"→"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:e.name}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count.toLocaleString()})]},e.name)),!k&&"properties"===N&&j?.propertyKeys.map(e=>(0,n.jsx)("div",{className:"px-2 py-1 font-mono text-muted-foreground hover:bg-brand/10 transition-colors",children:e},e)),!k&&"indexes"===N&&j?.indexes.map(e=>(0,n.jsxs)("div",{className:"px-2 py-1 border-b border-border/50 hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("div",{className:"font-mono text-foreground",children:e.name}),(0,n.jsxs)("div",{className:"text-muted-foreground",children:[e.type," \xb7 ",e.labelsOrTypes?.join(", ")," \xb7 (",e.properties?.join(", "),") \xb7 ",e.state]})]},e.name)),!k&&"constraints"===N&&j?.constraints.map(e=>(0,n.jsxs)("div",{className:"px-2 py-1 border-b border-border/50 hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("div",{className:"font-mono text-foreground",children:e.name}),(0,n.jsxs)("div",{className:"text-muted-foreground",children:[e.type," \xb7 ",e.labelsOrTypes?.join(", ")," \xb7 (",e.properties?.join(", "),")"]})]},e.name))]})]}),"cypher"===H&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("textarea",{ref:I,value:S,onChange:e=>M(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),z())},placeholder:`Enter Cypher query (${(0,rr.Mu)()}+Enter to run)`,className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center justify-between mt-1",children:[(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[(0,rr.Mu)(),"+Enter to execute"]}),(0,n.jsx)("button",{onClick:()=>z(),disabled:P||!S.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:P?"Running...":"Execute"})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto",children:[$&&(0,n.jsx)("div",{className:"p-2 text-xs text-destructive",children:$}),L&&!$&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-2 py-1 text-[10px] text-muted-foreground border-b border-border flex items-center gap-2",children:[(0,n.jsxs)("span",{children:[L.records.length," rows"]}),(0,n.jsxs)("span",{children:[L.duration,"ms"]}),Object.entries(L.counters).filter(([,e])=>e>0).map(([e,t])=>(0,n.jsxs)("span",{children:[e,": ",t]},e))]}),L.records.length>0&&(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:L.keys.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e},e))})}),(0,n.jsx)("tbody",{children:L.records.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-hover",children:L.keys.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",children:null===e[t]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):function(e){if(null==e)return"null";if("object"==typeof e){if("node"===e._type){let t=e._labels?.[0]||"",r=e.name||e.title||e.id||"";return`(${t}${r?": "+r:""})`}return"relationship"===e._type?`[${e._relType}]`:JSON.stringify(e)}return String(e)}(e[t])},t))},t))})]})]})]})]}),"graph"===H&&(0,n.jsx)("div",{className:"flex-1 relative",children:0===F.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-xs text-muted-foreground gap-2",children:[(0,n.jsx)("p",{children:"Run a Cypher query that returns nodes to visualize"}),(0,n.jsx)("button",{onClick:()=>{let e="MATCH (a)-[r]->(b) RETURN a, r, b LIMIT 50";M(e),z(e)},className:"px-3 py-1 rounded text-xs bg-brand text-white hover:bg-brand/90 transition-colors",children:"Load sample graph"})]}):(0,n.jsx)(r2,{nodes:F,rels:D,allLabels:j?.labels.map(e=>e.name)||[]})})]})]})]}),!l&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===h?"bg-green-500":"error"===h?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:"Connecting",connected:"Connected",error:"Error"}[h]}),"connected"===h&&b&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:b.edition}),(0,n.jsx)("span",{className:"flex-1"}),m&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:r1(m)})]})]})})}rc({type:"neo4j",idPrefix:"neo4j",match(e){let t=e.trim().toLowerCase();return t.startsWith("neo4j://")||t.startsWith("neo4j+s://")||t.startsWith("bolt://")||t.startsWith("bolt+s://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t);r=`${e.hostname}${e.port?":"+e.port:":7687"}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(r5,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await rh("neo4j",e.id)}});var r4=r(71077);let r3=(0,s.memo)(function({item:e,selected:t,maximized:r,initialSleeping:s,tabId:o,projectCwd:l,expandedHeight:a,bubbleContentHeight:i,onDragStart:d,onDragOver:c,onDragEnter:u,onDragLeave:m,onDrop:x,onDragEnd:h,onSelectId:f,onInterruptId:p,onStdin:g,onDeleteCommand:b,onRerun:v,subscribePtyOutput:j,subscribePtyReset:w,subscribePtyRefresh:k,ptySizeRef:y,resizePty:N,onToggleMaximizeId:C,onTitleMouseDown:S,onClosePlugin:M,addBrowserItem:L,onSleep:E,onWake:P}){let T={draggable:!0,onDragStart:t=>d(t,e.data.id),onDragOver:t=>c(t,e.data.id),onDragEnter:u,onDragLeave:m,onDrop:x,onDragEnd:h};if("command"===e.type){let s=e.data;return(0,n.jsx)("div",{"data-bubble-id":s.id,className:"group/cmd rounded-lg transition-shadow",...T,children:(0,n.jsx)(ri,{commandId:s.id,tabId:o,projectCwd:l,command:s.command,output:s.output,exitCode:s.exitCode,isRunning:s.isRunning,selected:t,onSelect:()=>{f(s.id)},onInterrupt:s.isRunning?()=>p(s.id):void 0,onStdin:s.isRunning?e=>g(s.id,e):void 0,onDelete:()=>{s.isRunning&&s.pid&&(0,r4.HV)(s.pid),b(s.id)},onRerun:()=>v(s.id),timestamp:s.timestamp,usePty:s.usePty,subscribePtyOutput:s.usePty?j:void 0,subscribePtyReset:s.usePty?w:void 0,subscribePtyRefresh:s.usePty?k:void 0,onPtyResize:(e,t)=>{y.current.set(s.id,{cols:e,rows:t}),N(s.id,e,t)},onToggleMaximize:()=>C(s.id),maximized:r,expandedHeight:a,bubbleContentHeight:i,onTitleMouseDown:S})})}let $=ru(e.type);if(!$)return null;let R=$.Component,I=e.data;return(0,n.jsx)("div",{"data-bubble-id":I.id,className:"rounded-lg transition-shadow",...T,children:(0,n.jsx)(R,{item:I,selected:t,maximized:r,expandedHeight:a,bubbleContentHeight:i,timestamp:I.timestamp,onSelect:()=>{f(I.id)},onClose:()=>M(I.id),onToggleMaximize:()=>C(I.id),onTitleMouseDown:S,extra:{addBrowserItem:L,initialSleeping:s,onSleep:E,onWake:P,projectCwd:l,tabId:o}})})});var r6=r(68459),r8=r(51914);function r9({cwd:e,tabId:t,onClose:r,onSave:l}){let{t:a}=(0,o.Bd)(),[i,d]=(0,s.useState)({}),[c,u]=(0,s.useState)(""),[m,x]=(0,s.useState)(""),[h,f]=(0,s.useState)(!0),p=(0,s.useCallback)(async()=>{f(!0);let r=await P.t4.runPromiseExit((0,rn.QF)(e,t));"Success"===r._tag?d(r.value.env):console.error("Failed to load env:",r.cause),f(!1)},[e,t]);(0,s.useEffect)(()=>{p()},[p]);let g=()=>{c.trim()&&(d(e=>({...e,[c.trim()]:m})),u(""),x(""))},b=async()=>{let n=await P.t4.runPromiseExit((0,rn.Vv)({cwd:e,tabId:t,env:i}));"Success"===n._tag?(l(i),r()):console.error("Failed to save env:",n.cause)};return(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-lv3 w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-lg font-semibold",children:a("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?a("envManager.tabScope"):a("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-hover transition-colors",children:(0,n.jsx)(ew.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:h?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:a("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(i).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"flex-1 px-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void d(t=>({...t,[e]:r}))},placeholder:a("envManager.valuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"}),(0,n.jsx)("button",{onClick:()=>{d(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors",children:(0,n.jsx)(r6.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsx)("input",{type:"text",value:c,onChange:e=>u(e.target.value),placeholder:a("envManager.varNamePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),g())}}),(0,n.jsx)("input",{type:"text",value:m,onChange:e=>x(e.target.value),placeholder:a("envManager.varValuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),g())}}),(0,n.jsx)("button",{onClick:g,disabled:!c.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(r8.A,{className:"w-4 h-4"})})]}),0===Object.keys(i).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:a("envManager.noVars")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 rounded-lg text-sm hover:bg-hover transition-colors",children:a("common.cancel")}),(0,n.jsx)("button",{onClick:b,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:a("common.save")})]})]})})}var r7=r(10762);function ne({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[l,a]=(0,s.useState)({}),[i,d]=(0,s.useState)(""),[c,u]=(0,s.useState)(""),[m,x]=(0,s.useState)(!0),h=(0,s.useCallback)(async()=>{x(!0);let e=await P.t4.runPromiseExit((0,rn.Jn)());"Success"===e._tag?a(e.value):console.error("Failed to load aliases:",e.cause),x(!1)},[]);(0,s.useEffect)(()=>{h()},[h]);let f=()=>{i.trim()&&c.trim()&&(a(e=>({...e,[i.trim()]:c.trim()})),d(""),u(""))},p=async()=>{let r=await P.t4.runPromiseExit((0,rn.cv)(l));"Success"===r._tag?(t(l),e()):console.error("Failed to save aliases:",r.cause)};return(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-lv3 w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[(0,n.jsx)(r7.A,{className:"w-5 h-5"}),r("aliasManager.title")]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:r("aliasManager.description")})]}),(0,n.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-hover transition-colors",children:(0,n.jsx)(ew.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:m?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:r("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(l).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2 group",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"})]}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void a(t=>({...t,[e]:r}))},placeholder:r("aliasManager.fullCommandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"})]}),(0,n.jsx)("button",{onClick:()=>{a(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors opacity-0 group-hover:opacity-100",children:(0,n.jsx)(r6.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>d(e.target.value),placeholder:r("aliasManager.aliasPlaceholder"),className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),f())}})]}),(0,n.jsx)("input",{type:"text",value:c,onChange:e=>u(e.target.value),placeholder:r("aliasManager.commandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),f())}})]}),(0,n.jsx)("button",{onClick:f,disabled:!i.trim()||!c.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(r8.A,{className:"w-4 h-4"})})]}),(0,n.jsxs)("div",{className:"mt-4 p-3 bg-accent rounded-lg",children:[(0,n.jsxs)("p",{className:"text-sm text-muted-foreground",children:[(0,n.jsx)("strong",{children:r("aliasManager.usage")}),r("aliasManager.usageDesc")]}),(0,n.jsxs)("div",{className:"mt-2 space-y-1 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ ll"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"ls -la"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ gs"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"git status"})]})]})]}),0===Object.keys(l).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:r("aliasManager.noAliases")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:e,className:"px-4 py-2 rounded-lg text-sm hover:bg-hover transition-colors",children:r("common.cancel")}),(0,n.jsx)("button",{onClick:p,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:r("common.save")})]})]})})}var nt=r(53961),nr=r(15813),nn=r(37595),ns=r(49698),no=r(20232);function nl({onAdd:e,onCancel:t}){let{t:r}=(0,o.Bd)(),[l,a]=(0,s.useState)(""),[i,d]=(0,s.useState)("");return(0,n.jsxs)("div",{className:"flex gap-1 mb-1",children:[(0,n.jsx)("input",{type:"text",value:l,onChange:e=>a(e.target.value),placeholder:r("console.namePlaceholder"),className:"w-24 flex-shrink-0 px-2 py-1 text-xs rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring",autoFocus:!0,onKeyDown:e=>{"Escape"===e.key&&t()}}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>d(e.target.value),placeholder:r("console.commandPlaceholder"),className:"flex-1 min-w-0 px-2 py-1 text-xs font-mono rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring",onKeyDown:r=>{"Enter"!==r.key||r.nativeEvent.isComposing?"Escape"===r.key&&t():(r.preventDefault(),r.stopPropagation(),l.trim()&&i.trim()&&e(l.trim(),i.trim()))}})]})}function na({label:e,commands:t,isAdding:r,onStartAdd:s,onAdd:l,onCancelAdd:a,onDelete:i,onExecute:d}){let{t:c}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1",children:e}),(0,n.jsx)("button",{type:"button",onClick:s,className:"p-0.5 text-muted-foreground hover:text-foreground rounded",children:(0,n.jsx)(r8.A,{className:"w-3.5 h-3.5"})})]}),r&&(0,n.jsx)(nl,{onAdd:(e,t)=>l(e,t),onCancel:a}),0===t.length&&!r&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:c("console.noCustomCommands")}),t.map((e,t)=>(0,n.jsx)(z.m,{content:e.command,children:(0,n.jsxs)("div",{className:"flex items-center group min-w-0",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>d(e.command),className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",children:[(0,n.jsx)(no.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:e.name})]}),(0,n.jsx)("button",{type:"button",onClick:()=>i(t),className:"p-1 text-muted-foreground hover:text-destructive rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:(0,n.jsx)(ew.A,{className:"w-3 h-3"})})]})},t))]})}function ni({cwd:e,show:t,onClose:r,onExecute:l,onAddPluginItem:a}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)([]),[u,m]=(0,s.useState)([]),[x,h]=(0,s.useState)(null),f=(0,s.useRef)(null),p=(0,s.useCallback)(async()=>{let[t,r]=await Promise.all([P.t4.runPromiseExit((0,rn.Yj)()),P.t4.runPromiseExit((0,rn.UV)(e))]);"Success"===t._tag&&c(t.value.customCommands||[]),"Success"===r._tag&&m(r.value.customCommands||[])},[e]);(0,s.useEffect)(()=>{t&&queueMicrotask(()=>p())},[t,p]),(0,s.useEffect)(()=>{if(!t)return;let e=e=>{f.current&&!f.current.contains(e.target)&&(r(),h(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]);let g=(0,s.useCallback)(async e=>{c(e);let t=await P.t4.runPromiseExit((0,rn.Cb)({scope:"global",customCommands:e}));"Failure"===t._tag?console.error("Failed to save global commands:",t.cause):t.value?.customCommands&&c(t.value.customCommands)},[]),b=(0,s.useCallback)(async t=>{m(t);let r=await P.t4.runPromiseExit((0,rn.Cb)({cwd:e,customCommands:t}));"Failure"===r._tag?console.error("Failed to save project commands:",r.cause):r.value?.customCommands&&m(r.value.customCommands)},[e]),v=(0,s.useCallback)(e=>{r();let t=rm(e);t?a?.(t.type,e.trim()):l(e)},[r,l,a]);return t?(0,n.jsxs)("div",{ref:f,className:"absolute bottom-full left-0 mb-2 w-72 bg-popover border border-border rounded-lg shadow-lv2 z-50 max-h-[70vh] overflow-y-auto",children:[(0,n.jsx)(na,{label:i("console.globalCommands"),commands:d,isAdding:"global"===x,onStartAdd:()=>h("global"),onAdd:(e,t)=>{g([...d,{name:e,command:t}]),h(null)},onCancelAdd:()=>h(null),onDelete:e=>g(d.filter((t,r)=>r!==e)),onExecute:v}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(na,{label:i("console.projectCommands"),commands:u,isAdding:"project"===x,onStartAdd:()=>h("project"),onAdd:(e,t)=>{b([...u,{name:e,command:t}]),h(null)},onCancelAdd:()=>h(null),onDelete:e=>b(u.filter((t,r)=>r!==e)),onExecute:v})]}):null}var nd=r(63040);function nc({cwd:e,currentCwd:t,commandHistoryRef:r,gridLayout:l,onGridLayoutChange:a,onExecute:i,onAddPluginItem:d,onShowEnvManager:c,onOpenShell:u,onOpenNote:m}){let{t:x}=(0,o.Bd)(),[h,f]=(0,s.useState)(""),[p,g]=(0,s.useState)(-1),[b,v]=(0,s.useState)(""),[j,w]=(0,s.useState)([]),[k,y]=(0,s.useState)(0),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)([]),[T,$]=(0,s.useState)([]),[R,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)(0),D=(0,s.useRef)(null),A=(0,s.useRef)(null),H=(0,s.useRef)(!1),{projectCommands:O,globalCommands:W,expandCustomCommand:_,loadQuickCommands:z}=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)([]),l=(0,s.useCallback)(async()=>{let[t,n]=await Promise.all([P.t4.runPromiseExit((0,rn.UV)(e)),P.t4.runPromiseExit((0,rn.Yj)())]);"Success"===t._tag&&r(t.value.customCommands||[]),"Success"===n._tag&&o(n.value.customCommands||[])},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>l())},[l]);let a=[...t,...n],i=(0,s.useCallback)(e=>{let r=e.trim().split(/\s+/),s=r[0];if(!s.startsWith("/")||s.length<=1)return null;let o=s.slice(1),l=t.find(e=>e.name===o)??n.find(e=>e.name===o);return l?l.command+(r.length>1?" "+r.slice(1).join(" "):""):null},[t,n]);return{quickCustomCommands:a,projectCommands:t,globalCommands:n,expandCustomCommand:i,loadQuickCommands:l}}(e);(0,s.useEffect)(()=>{D.current?.focus()},[]),(0,s.useEffect)(()=>{let e=!1,t=()=>{P.t4.runPromiseExit((0,nd.mi)()).then(t=>{e||"Success"!==t._tag||E(t.value.filter(e=>!1!==e.valid&&e.name&&e.path).map(e=>({name:e.name,path:e.path})))})};t();let r=null;return"u">typeof BroadcastChannel&&(r=new BroadcastChannel("cockpit-html-apps")).addEventListener("message",e=>{e.data?.type==="changed"&&t()}),()=>{e=!0,r?.close()}},[]),(0,s.useEffect)(()=>{if(h.startsWith("/")){let e=h.slice(1).toLowerCase(),t=L.filter(t=>t.name.toLowerCase().startsWith(e)).map(e=>({kind:"html",name:e.name,path:e.path})),r=t=>"string"==typeof t?.name&&t.name.toLowerCase().startsWith(e),n=[...t,...[...O.filter(r).map(e=>({...e,scope:"project"})),...W.filter(r).map(e=>({...e,scope:"global"}))].map(e=>({kind:"cmd",cmd:e}))];queueMicrotask(()=>{$(n),I(n.length>0),B(0)})}else queueMicrotask(()=>I(!1))},[h,O,W,L]),(0,s.useEffect)(()=>{if(R&&A.current){let e=A.current.children[F];e?.scrollIntoView({block:"nearest"})}},[F,R]);let q=(0,s.useCallback)(e=>{if(I(!1),"html"===e.kind){d?.("browser",e.path),f("");return}let t=e.cmd.command,r=rm(t);r?d?.(r.type,t.trim()):i(t),f("")},[i,d]),V=(0,s.useCallback)(e=>{if(e.preventDefault(),H.current||!h.trim())return;if(h.startsWith("/")){let e=h.slice(1).trim(),t=L.find(t=>t.name===e);if(t){d?.("browser",t.path),f(""),g(-1),v(""),I(!1);return}}let t=_(h)??h,r=rm(t);r?d?.(r.type,t.trim()):i(t),f(""),g(-1),v("")},[h,i,d,_,L]),U=(0,s.useCallback)(async()=>{if(!D.current)return;let e=D.current.selectionStart||0,r=await P.t4.runPromiseExit((0,rn.tp)({cwd:t,input:h,cursorPosition:e}));if("Success"===r._tag){let t=r.value,n=t.suggestions;if(n&&n.length>0&&(w(n),y(0),C(!0),1===n.length)){let r=h.substring(0,t.replaceStart??0),s=h.substring(t.replaceEnd??e);f(r+n[0]+s),C(!1),setTimeout(()=>{if(D.current){let e=(t.replaceStart??0)+n[0].length;D.current.setSelectionRange(e,e)}},0)}}else console.error("Autocomplete error:",r.cause)},[t,h]),K=(0,s.useCallback)(e=>{if(!D.current)return;let t=D.current.selectionStart||0,r=h.substring(0,t),n=h.substring(t),s=r.split(/\s+/),o=t-(s[s.length-1]||"").length;f(h.substring(0,o)+e+n),C(!1),setTimeout(()=>{if(D.current){let t=o+e.length;D.current.setSelectionRange(t,t)}},0)},[h]),Q=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing)return;if(R&&T.length>0){if("ArrowUp"===e.key){e.preventDefault(),B(e=>(e-1+T.length)%T.length);return}if("ArrowDown"===e.key){e.preventDefault(),B(e=>(e+1)%T.length);return}if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),q(T[F]);return}if("Escape"===e.key){e.preventDefault(),I(!1);return}}if("Tab"===e.key){if(e.preventDefault(),N&&j.length>0){let e=(k+1)%j.length;y(e),K(j[e])}else U();return}if("Escape"===e.key&&N){e.preventDefault(),C(!1);return}let t=r.current;if(t&&0!==t.length){if("ArrowUp"===e.key){e.preventDefault(),-1===p&&v(h);let r=-1===p?t.length-1:Math.max(0,p-1);g(r),f(t[r])}else if("ArrowDown"===e.key){if(e.preventDefault(),-1===p)return;let r=p+1;r>=t.length?(g(-1),f(b)):(g(r),f(t[r]))}}},[p,h,b,N,j,k,U,K,R,T,F,q,r]);return(0,n.jsx)("div",{className:"border-t border-border p-4",children:(0,n.jsxs)("form",{onSubmit:V,className:"relative flex gap-2 items-center",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{S||z(),M(!S)},className:`p-2 rounded-lg transition-all ${S?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:x("console.quickCommands"),children:(0,n.jsx)(nt.A,{className:"w-4 h-4"})}),(0,n.jsx)(ni,{cwd:e,show:S,onClose:()=>M(!1),onExecute:i,onAddPluginItem:d})]}),m&&(0,n.jsx)("button",{type:"button",onClick:m,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:x("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"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,n.jsx)("button",{type:"button",onClick:()=>a(!l),className:`p-2 rounded-lg transition-all ${l?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:l?x("console.singleColumn"):x("console.dualColumn"),children:l?(0,n.jsx)(nr.A,{className:"w-4 h-4"}):(0,n.jsx)(nn.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{type:"button",onClick:c,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:x("console.envVars"),children:(0,n.jsx)(ns.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{type:"button",onClick:u,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:x("console.launchShell"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}),(0,n.jsx)("input",{ref:D,type:"text",value:h,onChange:e=>{f(e.target.value),-1!==p&&(g(-1),v("")),C(!1)},onKeyDown:Q,onCompositionStart:()=>{H.current=!0},onCompositionEnd:()=>{H.current=!1},placeholder:x("console.inputPlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm focus:outline-none focus:ring-2 focus:ring-ring font-mono"}),R&&T.length>0&&(0,n.jsx)("div",{ref:A,className:"absolute bottom-full left-0 right-0 mb-1 max-h-64 overflow-y-auto bg-popover border border-border rounded-lg shadow-lv2 z-50",children:T.map((e,t)=>(0,n.jsx)("div",{onClick:()=>q(e),className:`flex items-center gap-3 px-3 py-1.5 cursor-pointer text-sm ${t===F?"bg-brand/10":"hover:bg-hover"}`,children:"html"===e.kind?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"font-mono font-medium text-foreground",children:["/",e.name]}),(0,n.jsx)("span",{className:"flex-1 text-muted-foreground truncate",children:e.path}),(0,n.jsx)("span",{className:"text-[10px] text-brand/70 flex-shrink-0",children:"HTML"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"font-mono font-medium text-foreground",children:["/",e.cmd.name]}),(0,n.jsx)("span",{className:"flex-1 text-muted-foreground truncate",children:e.cmd.command}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/60 flex-shrink-0",children:"project"===e.cmd.scope?x("console.scopeProject"):x("console.scopeGlobal")})]})},"html"===e.kind?`html-${e.name}`:`cmd-${e.cmd.scope}-${e.cmd.name}`))}),N&&j.length>1&&(0,n.jsxs)("div",{className:"absolute bottom-full left-0 mb-1 bg-popover border border-border rounded-lg shadow-lv2 max-h-48 overflow-y-auto z-50",children:[(0,n.jsx)("div",{className:"py-1",children:j.map((e,t)=>(0,n.jsx)("button",{type:"button",onClick:()=>K(e),className:`w-full px-3 py-1.5 text-left text-sm font-mono hover:bg-hover transition-colors ${t===k?"bg-accent":""}`,children:e},t))}),(0,n.jsx)("div",{className:"border-t border-border px-3 py-1 text-xs text-muted-foreground",children:x("console.tabSwitchEscClose")})]})]})})}function nu({showTop:e,showBottom:t,onScrollTop:r,onScrollBottom:s}){let{t:l}=(0,o.Bd)();return(0,n.jsxs)(n.Fragment,{children:[e&&(0,n.jsx)("button",{onClick:r,className:"absolute top-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-lv2 rounded-full transition-all hover:shadow-lv2 active:scale-95 z-10",title:l("chat.jumpToStart"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),t&&(0,n.jsx)("button",{onClick:s,className:"absolute bottom-20 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-lv2 rounded-full transition-all hover:shadow-lv2 active:scale-95 z-10",title:l("chat.jumpToLatest"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]})}var nm=r(50605);function nx(){return`cmd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`}let nh="__cockpit_open_preferred_shell__",nf="shell",np=new Set([nh,"zsh","bash","sh","fish","nu","python","python3","node","irb","lua","vim","nvim","vi","nano","emacs","top","htop","less","man"]),ng=[{key:"command",label:"console.bubbleCommand",triggers:["ls","git status","npm run dev"]},{key:"pty",label:"console.bubbleInteractive",triggers:["zsh","bash","vim","python"]},{key:"browser",label:"console.bubbleBrowser",triggers:["https://…","*.html"],notes:["console.bubbleBrowserNoteIframe","console.bubbleBrowserNoteCookie"]},{key:"database",label:"console.bubbleDatabase",triggers:["postgresql://","mysql://","redis://","neo4j://"]},{key:"filePreview",label:"console.bubbleFilePreview",triggers:[...eu.GV]}],nb=(0,s.memo)(function({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:l,onOpenNote:a,focusBubble:i,isActive:d=!0}){let{t:c}=(0,o.Bd)(),{consoleItems:u,scrollRef:m,selectedCommandId:x,setSelectedCommandId:h,interruptCommand:f,sendStdin:p,deleteCommand:g,rerunCommand:b,ptySizeRef:v,resizePty:j,executeCommand:w,addPluginItem:k,closePluginItem:y,sleepingBubbles:N,handleBubbleSleep:C,handleBubbleWake:S,scrollToBottom:M,currentCwd:L,commandHistoryRef:E,setCustomEnv:T,setAliases:$,saveBubbleOrder:R,hasMoreHistory:I,loadHistory:F,currentPage:B,isLoadingHistory:D,subscribePtyOutput:A,subscribePtyReset:H,subscribePtyRefresh:O}=function({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:n}){let[o,l]=(0,s.useState)([]),[a,i]=(0,s.useState)([]),[d,c]=(0,s.useState)(new Set),[u,m]=(0,s.useState)(t||e),[x,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(0),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)({}),y=(0,s.useRef)(""),[N,C]=(0,s.useState)({}),[S,M]=(0,s.useState)(null),L=(0,s.useRef)(null),E=(0,s.useRef)(new Map),T=(0,s.useRef)(new Map),$=(0,s.useRef)(new Set),R=(0,s.useRef)([]),I=(0,s.useRef)(new Map),F=(0,s.useRef)(new Map),B=(0,s.useRef)(new Map),D=(0,s.useRef)(null),A=(0,s.useRef)(null),H=(0,s.useRef)([]),O=(0,s.useRef)("");O.current||(O.current="u">typeof crypto&&crypto.randomUUID?crypto.randomUUID():`s_${Date.now()}_${Math.random().toString(36).slice(2)}`);let W=(0,s.useRef)(null);(0,s.useEffect)(()=>{n?.(e)},[]);let _=(0,s.useCallback)(()=>{if(E.current.size>0){let e=new Map(E.current);E.current.clear(),l(t=>t.map(t=>{let r=e.get(t.id);return void 0!==r?{...t,output:r}:t}))}L.current=null},[]),z=(0,s.useCallback)((e,t)=>{if($.current.has(e)){let r=F.current.get(e);if(r&&r.size>0)for(let e of r)e(t);else B.current.has(e)||B.current.set(e,[]),B.current.get(e).push(t);return}let r=(T.current.get(e)||"")+t;if(r.length>2097152){let t=function(e){let t=e.slice(-2097152),r=0;if(t.length>0){let e=t.charCodeAt(0);e>=56320&&e<=57343&&(r=1)}let n=Math.min(t.length,64);for(let e=r;e<n;e++){let n=t.charCodeAt(e);if(27===n){r=e;break}if((!(n>=48)||!(n<=63))&&59!==n&&63!==n&&32!==n){n>=64&&n<=126&&(r=e+1);break}}return r>0?t.slice(r):t}(r);T.current.set(e,t),E.current.set(e,t)}else T.current.set(e,r),E.current.set(e,r);null===L.current&&(L.current=requestAnimationFrame(_))},[_]),q=(0,s.useCallback)((e,t=!1)=>{T.current.delete(e),$.current.delete(e),E.current.delete(e),B.current.delete(e),t||(F.current.delete(e),U.current.delete(e))},[]),V=(0,s.useCallback)((e,t)=>{F.current.has(e)||F.current.set(e,new Set),F.current.get(e).add(t);let r=B.current.get(e);if(r&&r.length>0){for(let e of r)t(e);B.current.delete(e)}return()=>{F.current.get(e)?.delete(t)}},[]),U=(0,s.useRef)(new Map),K=(0,s.useCallback)((e,t)=>(U.current.has(e)||U.current.set(e,new Set),U.current.get(e).add(t),()=>{U.current.get(e)?.delete(t)}),[]),Q=(0,s.useRef)(new Map),G=(0,s.useCallback)((e,t)=>(Q.current.has(e)||Q.current.set(e,new Set),Q.current.get(e).add(t),()=>{Q.current.get(e)?.delete(t)}),[]);(0,s.useEffect)(()=>{if(!S)return;let e=requestAnimationFrame(()=>{for(let e of Q.current.values())for(let t of e)t()});return()=>cancelAnimationFrame(e)},[S]);let J=(0,s.useCallback)(e=>(null!==L.current&&(cancelAnimationFrame(L.current),L.current=null),_(),T.current.get(e)||""),[_]),Y=(0,s.useCallback)(()=>{W.current&&(W.current.scrollTop=W.current.scrollHeight)},[]),X=(0,s.useCallback)(async(t=0)=>{if(r){h(!0);try{let n=await P.t4.runPromise((0,rn.uc)(e,r,t,100)).catch(e=>(console.error("Failed to load history:",e),null));if(n){let e=[],r=[],s=new Set;for(let t of n.entries){let n=ru(t.type);if(n){let e=n.fromHistory(t);r.push({id:t.id,_type:t.type,timestamp:t.timestamp,...e}),t.sleeping&&s.add(t.id)}else{if(t.running)continue;let r=t.id.includes("-")&&3===t.id.split("-").length?t.id:nx();e.push({id:r,command:t.command,output:t.output,exitCode:t.exitCode,isRunning:!1,timestamp:t.timestamp,cwd:t.cwd,usePty:t.usePty})}}0===t?(l(e),i(r),s.size>0&&c(s)):(l(t=>{let r=new Set(t.map(e=>e.id)),n=e.filter(e=>!r.has(e.id));return[...t,...n]}),i(e=>{let t=new Set(e.map(e=>e.id)),n=r.filter(e=>!t.has(e.id));return[...e,...n]})),p(n.hasMore),b(t)}}catch(e){console.error("Failed to load history:",e)}finally{h(!1)}}},[e,r]),Z=(0,s.useCallback)(async t=>{r&&await P.t4.runPromise((0,rn.AJ)(e,r,{id:t.id,command:t.command,output:t.output,exitCode:t.exitCode,timestamp:t.timestamp,cwd:u},O.current).pipe(eT.sFT(e=>eT.OH5(()=>console.error("Failed to save cd history:",e))),eT.NWQ(()=>eT.rIH)))},[e,r,u]),ee=(0,s.useCallback)(async t=>{try{let n=await (0,r4.If)(e);if(t.current)return;for(let s of n){if(r&&s.tabId!==r)continue;if(t.current)break;let n=s.commandId;l(e=>e.find(e=>e.id===n)?e.map(e=>e.id===n?{...e,isRunning:!0,exitCode:void 0,pid:s.pid,...s.usePty?{usePty:!0}:{}}:e):[...e,{id:n,command:s.command,output:"",isRunning:!0,pid:s.pid,timestamp:s.timestamp,cwd:s.cwd,...s.usePty?{usePty:!0}:{}}]),T.current.set(n,""),s.usePty&&$.current.add(n),await (0,r4.TN)({commandId:n,projectCwd:e,onData:(e,t)=>{if("pid"===e)"string"==typeof t.command&&l(e=>e.map(e=>e.id===n?{...e,command:t.command}:e));else if("stdout"===e||"stderr"===e)z(n,t.data);else if("exit"===e){let e=J(n);q(n),l(r=>r.map(r=>r.id===n?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:()=>{l(e=>e.map(e=>e.id===n&&e.isRunning?{...e,isRunning:!1}:e))}})}}catch{}},[e,r,z,J,q]),et=(0,s.useCallback)((t,r)=>{T.current.set(t,""),r&&$.current.add(t),(0,r4.TN)({commandId:t,projectCwd:e,onData:(e,r)=>{if("pid"===e)l(e=>e.map(e=>e.id===t?{...e,pid:r.pid,..."string"==typeof r.command?{command:r.command}:{}}:e));else if("stdout"===e||"stderr"===e)z(t,r.data);else if("exit"===e){let e=J(t);q(t),l(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:()=>{l(e=>e.map(e=>e.id===t&&e.isRunning?{...e,isRunning:!1}:e))}}).catch(()=>{})},[e,z,J,q]),er=(0,s.useCallback)(e=>{let t=e?.id;if(!e||!t||H.current.some(e=>e.data.id===t))return;let r=e.type,n=r?ru(r):void 0;if(n)i(s=>s.some(e=>e.id===t)?s:[...s,{id:t,_type:r,timestamp:e.timestamp??new Date().toISOString(),...n.fromHistory(e)}]),e.sleeping&&c(e=>new Set(e).add(t));else{let r=!!e.running;l(n=>n.some(e=>e.id===t)?n:[...n,{id:t,command:e.command??"",output:e.output??"",exitCode:e.exitCode,isRunning:r,timestamp:e.timestamp??new Date().toISOString(),cwd:e.cwd,usePty:e.usePty}]),r&&et(t,!!e.usePty)}M(e=>e&&!e.includes(t)?[...e,t]:e)},[et]),en=(0,s.useCallback)(e=>{if("add"===e.op)e.entry&&er(e.entry);else if("rerun"===e.op){let t=e.entry,r=t?.id;if(!t||!r)return;if(!H.current.some(e=>e.data.id===r))return void er(t);let n=!!t.usePty;if(n){let e=U.current.get(r);if(e)for(let t of e)t()}q(r,n),l(e=>e.map(e=>e.id===r?{...e,output:"",exitCode:void 0,isRunning:!0,pid:void 0}:e)),et(r,n)}else if("update"===e.op){let t=e.id,r=e.fields;if(!t||!r)return;void 0!==r.sleeping&&c(e=>{let n=new Set(e);return r.sleeping?n.add(t):n.delete(t),n}),(void 0!==r.exitCode||void 0!==r.running)&&l(e=>e.map(e=>e.id===t?{...e,...void 0!==r.exitCode?{exitCode:r.exitCode}:{},...void 0!==r.running?{isRunning:r.running}:{}}:e))}else if("delete"===e.op){let t=e.id;if(!t)return;l(e=>e.filter(e=>e.id!==t)),i(e=>e.filter(e=>e.id!==t)),M(e=>e?e.filter(e=>e!==t):e),c(e=>{if(!e.has(t))return e;let r=new Set(e);return r.delete(t),r}),q(t)}else"clear"===e.op?(l([]),i([]),M([]),c(new Set)):"reorder"===e.op&&Array.isArray(e.order)&&M(e.order)},[er,et,q]);(0,eb.h)({url:"/ws/global-state",enabled:!!e&&!!r,onMessage:t=>{"console-delta"!==t.type||t.cwd!==e||t.tabId!==r||t.sourceId&&t.sourceId===O.current||en(t)}});let es=(0,s.useCallback)(async t=>{let s,o=t.trim().split(/\s+/),a=o[0],i=t;if(N[a]&&(i=N[a]+(o.length>1?" "+o.slice(1).join(" "):"")),t2(i)&&!/\s/.test(i.trim()))return void t5(i,e);let d=rm(i);if(d)return void A.current?.(d.type,i.trim());let c=nx(),x=new Date().toISOString(),h=(s=i.trim().split(/\s+/)[0],np.has(s)),f={id:c,command:i===nh?nf:t,output:i!==t&&i!==nh?`→ ${i}
21
- `:"",isRunning:!0,timestamp:x,cwd:u,...h?{usePty:!0}:{}};if(l(e=>e.some(e=>e.id===c)?e:[...e,f]),j(c),T.current.set(c,f.output),h&&$.current.add(c),setTimeout(Y,100),i.trim().startsWith("cd ")){let e=i.trim().substring(3).trim(),t=u;(0,nm.P)(e)?t=y.current?(0,nm.D)(e,y.current):u:e.startsWith("/")?t=e:".."===e?t=u.split("/").slice(0,-1).join("/")||"/":"."!==e&&(t=`${u}/${e}`.replace(/\/+/g,"/")),m(t),n?.(t),l(e=>e.map(e=>{if(e.id===c){let r={...e,output:`Changed directory to: ${t}`,exitCode:0,isRunning:!1};return Z(r),r}return e}));return}try{await (0,r4.RS)({cwd:u,command:i,commandId:c,tabId:r||"",projectCwd:e,env:w,usePty:h,sourceId:O.current,onData:(e,t)=>{if("pid"===e)l(e=>e.map(e=>e.id===c?{...e,pid:t.pid,..."string"==typeof t.command?{command:t.command}:{}}:e));else if("stdout"===e||"stderr"===e)z(c,t.data);else if("exit"===e){let e=J(c);q(c),l(r=>r.map(r=>r.id===c?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:e=>{let t=J(c);q(c),l(r=>r.map(r=>r.id===c?{...r,output:t+`
22
- Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:r))}})}catch(t){let e=J(c);q(c),l(r=>r.map(r=>r.id===c?{...r,output:e+`
23
- Error: ${t.message}`,exitCode:1,isRunning:!1,pid:void 0}:r))}},[N,u,w,r,e,z,J,q,Y,n,Z]),eo=(0,s.useCallback)(e=>{let t=o.find(t=>t.id===e);t?.isRunning&&t.pid&&(0,r4.HV)(t.pid)},[o]),el=(0,s.useCallback)(async t=>{let n=o.find(e=>e.id===t);if(!n)return;n.isRunning&&n.pid&&((0,r4.HV)(n.pid),await new Promise(e=>setTimeout(e,200)));let s=n.command.trim().split(/\s+/),a=s[0],i=n.usePty&&n.command===nf,d=i?nh:n.command;!i&&N[a]&&(d=N[a]+(s.length>1?" "+s.slice(1).join(" "):""));let c=n.usePty||!1;if(c){let e=U.current.get(t);if(e)for(let t of e)t()}q(t,c);let m=d!==n.command?`→ ${d}
24
- `:"";c||T.current.set(t,m),c&&$.current.add(t),l(e=>e.map(e=>e.id===t?{...e,output:c?"":m,exitCode:void 0,isRunning:!0,pid:void 0}:e));let x=I.current.get(t);try{await (0,r4.RS)({cwd:n.cwd||u,command:d,commandId:t,tabId:r||"",projectCwd:e,env:w,usePty:c,sourceId:O.current,...c&&x?{cols:x.cols,rows:x.rows}:{},onData:(e,r)=>{if("pid"===e)l(e=>e.map(e=>e.id===t?{...e,pid:r.pid,..."string"==typeof r.command?{command:r.command}:{}}:e));else if("stdout"===e||"stderr"===e)z(t,r.data);else if("exit"===e){let e=J(t);q(t),l(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:e=>{let r=J(t);q(t),l(n=>n.map(n=>n.id===t?{...n,output:r+`
25
- Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:n))}})}catch(r){let e=J(t);q(t),l(n=>n.map(n=>n.id===t?{...n,output:e+`
26
- Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,N,u,w,r,e,z,J,q]),ea=(0,s.useCallback)(async t=>{l(e=>e.filter(e=>e.id!==t)),q(t),r&&await P.t4.runPromise((0,rn.SN)(e,r,t,O.current).pipe(eT.sFT(e=>eT.OH5(()=>console.error("Failed to delete command:",e))),eT.NWQ(()=>eT.rIH)))},[e,r,q]),ei=(0,s.useCallback)((t,n,s)=>{var o;let l=ru(t);if(!l)return;let a=l.parse(n);"cwd"in a&&!a.cwd&&(a.cwd=u);let d={id:(o=l.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...a};if(i(e=>[...e,d]),j(d.id),setTimeout(Y,100),s){let t=S&&S.length>0?[...S]:H.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,d.id):t.push(d.id),M(t),r&&P.t4.runFork((0,rn.cm)(e,r,t,O.current).pipe(eT.NWQ(()=>eT.rIH)))}if(r){let n=l.toHistory(d);P.t4.runFork((0,rn.AJ)(e,r,{type:t,id:d.id,timestamp:d.timestamp,...n},O.current).pipe(eT.sFT(e=>eT.OH5(()=>console.error(`Failed to save ${t} item:`,e))),eT.NWQ(()=>eT.rIH)))}},[Y,e,r,S]),ed=(0,s.useCallback)(async t=>{let n=a.find(e=>e.id===t);if(i(e=>e.filter(e=>e.id!==t)),j(e=>e===t?null:e),c(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=ru(n._type);e?.onClose?.(n)}r&&P.t4.runFork((0,rn.SN)(e,r,t,O.current).pipe(eT.sFT(e=>eT.OH5(()=>console.error("Failed to delete plugin item:",e))),eT.NWQ(()=>eT.rIH)))},[a,e,r]);A.current=ei,D.current=es;let ec=(0,s.useCallback)((t,n)=>{r&&P.t4.runFork((0,rn.bv)(e,r,t,{sleeping:n},O.current).pipe(eT.NWQ(()=>eT.rIH)))},[e,r]),eu=(0,s.useCallback)(e=>{c(t=>new Set(t).add(e)),ec(e,!0)},[ec]),em=(0,s.useCallback)(e=>{c(t=>{let r=new Set(t);return r.delete(e),r}),ec(e,!1)},[ec]),ex=(0,s.useCallback)(async t=>{M(t),r&&await P.t4.runPromise((0,rn.cm)(e,r,t,O.current).pipe(eT.NWQ(()=>eT.rIH)))},[e,r]),eh=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...a.map(e=>({type:e._type,data:e}))];if(!S||0===S.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(S.map((e,t)=>[e,t])),r=[],n=[];for(let s of e)t.has(s.data.id)?r.push(s):n.push(s);return r.sort((e,r)=>t.get(e.data.id)-t.get(r.data.id)),n.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime()),[...r,...n]},[o,a,S]);H.current=eh,(0,s.useEffect)(()=>{R.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let ef=async()=>{let t=await P.t4.runPromise((0,rn.QF)(e,r).pipe(eT.sFT(e=>eT.OH5(()=>console.error("Failed to load env:",e))),eT.DM4(()=>({env:{},home:""}))));k(t.env),y.current=t.home},ep=async()=>{C(await P.t4.runPromise((0,rn.Jn)().pipe(eT.sFT(e=>eT.OH5(()=>console.error("Failed to load aliases:",e))),eT.DM4(()=>({})))))},eg=async()=>{if(!r)return;let t=await P.t4.runPromise((0,rn.DN)(e,r).pipe(eT.DM4(()=>[])));t.length>0&&M(t)};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await X(0),e.current||await ee(e)})(),ef(),ep(),eg(),()=>{e.current=!0}},[X,ee]),(0,s.useEffect)(()=>()=>{null!==L.current&&cancelAnimationFrame(L.current)},[]),(0,s.useEffect)(()=>()=>{(0,r4.AS)()},[]),{commands:o,pluginItems:a,sleepingBubbles:d,consoleItems:eh,currentCwd:u,selectedCommandId:v,setSelectedCommandId:j,customEnv:w,setCustomEnv:k,aliases:N,setAliases:C,isLoadingHistory:x,hasMoreHistory:f,currentPage:g,scrollRef:W,commandHistoryRef:R,ptySizeRef:I,executeCommandRef:D,executeCommand:es,interruptCommand:eo,rerunCommand:el,deleteCommand:ea,addPluginItem:ei,closePluginItem:ed,handleBubbleSleep:eu,handleBubbleWake:em,loadHistory:X,scrollToBottom:Y,saveBubbleOrder:ex,sendStdin:r4.tr,resizePty:r4.mO,subscribePtyOutput:V,subscribePtyReset:K,subscribePtyRefresh:G}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:l}),[W,_]=(0,s.useState)(null),[z,V]=(0,s.useState)(0),[U,K]=(0,s.useState)(0),[Q,G]=(0,s.useState)(!0),[J,Y]=(0,s.useState)(!1),[X,Z]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(!1),[er,en]=(0,s.useState)(!1),es=(0,s.useRef)(null),eo=(0,s.useRef)(null),el=(0,s.useRef)(null),ea=(0,s.useRef)(!1),ei=(0,s.useRef)(null),ed=(0,s.useRef)(null),ec=(0,s.useRef)([]);(0,s.useEffect)(()=>{ec.current=u},[u]);let eu=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[m]),em=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollTop<50},[m]),ex=(0,s.useCallback)(()=>{et(!em()),en(!eu())},[eu,em]),eh=(0,s.useCallback)(()=>{eo.current?.scrollIntoView({behavior:"smooth"})},[]),ef=async()=>{let t=await P.t4.runPromiseExit((0,rn.D0)(e));if("Success"===t._tag){let e=t.value.settings;e?.gridLayout!==void 0&&G(e.gridLayout)}else console.error("Failed to load project settings:",t.cause)};(0,s.useEffect)(()=>{queueMicrotask(()=>ef())},[]);let ep=(0,s.useCallback)(()=>{ea.current=!0},[]),eg=(0,s.useCallback)((e,t)=>{if(!ea.current)return void e.preventDefault();ea.current=!1,ei.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t),e.currentTarget.style.opacity="0.4";let r=e.currentTarget.querySelector("[data-drag-handle]");if(r){let t=r.cloneNode(!0);t.style.cssText="position:fixed;top:-9999px;left:-9999px;width:"+r.offsetWidth+"px;background:hsl(var(--card));color:hsl(var(--foreground));box-shadow:var(--elevation-2);border-radius:8px;padding:4px 12px;opacity:0.9;",document.body.appendChild(t),e.dataTransfer.setDragImage(t,20,16),requestAnimationFrame(()=>document.body.removeChild(t))}},[]),ev=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",ed.current=t},[]),ej=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ew=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ek=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ey=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=ei.current,r=ed.current;if(ei.current=null,ed.current=null,!t||!r||t===r)return;let n=ec.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let l=[...n];l[s]=r,l[o]=t,R(l)},[R]),eN=(0,s.useCallback)(e=>{_(t=>t===e?null:e)},[]),eC=(0,s.useCallback)((t,r)=>t2(t)?void t5(t,e):k("browser",t,r),[k,e]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),x&&eN(x))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[d,x,eN]),(0,s.useEffect)(()=>{let e=m.current;if(!e)return;let t=new ResizeObserver(([e])=>{K(e.contentRect.height)});return t.observe(e),K(e.clientHeight),()=>t.disconnect()},[m]),(0,s.useEffect)(()=>{let e=m.current;if(e)return W?V(e.clientHeight):(e.style.overflow="",V(0)),()=>{e&&(e.style.overflow="")}},[W,m]),(0,s.useEffect)(()=>{let e=m.current;if(!e||!W||!z)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${W}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[W,z,m]);let[eS,eM]=(0,s.useState)(null);(0,s.useEffect)(()=>{i&&(_(null),eM(i.commandId))},[i]),(0,s.useEffect)(()=>{if(!eS||!u.some(e=>e.data.id===eS))return;let e=requestAnimationFrame(()=>{let e=m.current,t=e?.querySelector(`[data-bubble-id="${CSS.escape(eS)}"]`);if(!e||!t)return;eM(null),h(eS);let r=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r.top-n.top-Math.max(0,(n.height-r.height)/2);e.scrollTo({top:e.scrollTop+s,behavior:"smooth"})});return()=>cancelAnimationFrame(e)},[eS,u,m,h]),(0,s.useEffect)(()=>{if(!eS)return;let e=setTimeout(()=>{eM(null),(0,q.oR)(c("runningTerminals.notFound"),"error")},3e3);return()=>clearTimeout(e)},[eS,c]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&w(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[w]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.url;t&&k("browser",t)};return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[k]);let eL=U>0?Math.floor((U-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:es,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:m,onScroll:ex,className:`console-scroll-root flex-1 overflow-y-auto ${W?"":"py-4 px-4"}`,children:0===u.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"w-full max-w-md flex flex-col gap-4 text-sm",children:[(0,n.jsx)("p",{className:"text-muted-foreground",children:c("console.emptyIntro")}),(0,n.jsx)("ul",{className:"flex flex-col gap-2",children:ng.map(e=>(0,n.jsxs)("li",{className:"flex items-start gap-3",children:[(0,n.jsx)("span",{className:"w-16 flex-shrink-0 text-foreground font-medium",children:c(e.label)}),(0,n.jsxs)("span",{className:"flex-1 flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"flex flex-wrap gap-1",children:e.triggers.map(e=>(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-xs font-mono text-muted-foreground",children:e},e))}),e.notes?.map(e=>(0,n.jsx)("span",{className:"text-xs leading-snug text-muted-foreground/70",children:c(e)},e))]})]},e.key))}),(0,n.jsxs)("button",{type:"button",onClick:()=>w(nh),title:c("console.launchShell"),className:"self-start flex items-center gap-2 px-4 py-2 rounded-lg border border-input bg-background text-sm text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 transition-all",children:[(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),"New PTY"]})]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:eo}),I&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>F(B+1),disabled:D,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors disabled:opacity-50",children:D?c("console.loadingMore"):c("console.loadMoreHistory")})}),(0,n.jsx)("div",{className:W?"flex flex-col gap-3":Q?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:u.map(t=>(0,n.jsx)(r3,{item:t,selected:d&&x===t.data.id,maximized:W===t.data.id,initialSleeping:N.has(t.data.id),tabId:r,projectCwd:e,expandedHeight:z,bubbleContentHeight:eL,onDragStart:eg,onDragOver:ev,onDragEnter:ej,onDragLeave:ew,onDrop:ek,onDragEnd:ey,onSelectId:h,onInterruptId:f,onStdin:p,onDeleteCommand:g,onRerun:b,subscribePtyOutput:A,subscribePtyReset:H,subscribePtyRefresh:O,ptySizeRef:v,resizePty:j,onToggleMaximizeId:eN,onTitleMouseDown:ep,onClosePlugin:y,addBrowserItem:eC,onSleep:C,onWake:S},t.data.id))}),(0,n.jsx)("div",{ref:el})]})}),!W&&u.length>0&&(0,n.jsx)(nu,{showTop:ee,showBottom:er,onScrollTop:eh,onScrollBottom:M}),(0,n.jsx)(nc,{cwd:e,currentCwd:L,commandHistoryRef:E,gridLayout:Q,onGridLayoutChange:t=>{G(t),P.t4.runFork((0,rn.Yn)({cwd:e,settings:{gridLayout:t}}).pipe(eT.sFT(e=>eT.OH5(()=>console.error("Failed to save project settings:",e))),eT.NWQ(()=>eT.rIH)))},onExecute:w,onAddPluginItem:k,onShowEnvManager:()=>Y(!0),onOpenShell:()=>w(nh),onOpenNote:a}),J&&(0,n.jsx)(r9,{cwd:e,tabId:r,onClose:()=>Y(!1),onSave:e=>T(e)}),X&&(0,n.jsx)(ne,{onClose:()=>Z(!1),onSave:e=>$(e)})]})});var nv=r(83897),nj=r(54271);function nw(e,t,r,n){return n&&r&&t.includes(e)}var nk=r(54356),ny=r(16220),nN=r(24058),nC=r(56058),nS=r(32880),nM=r(8183),nL=r(41948),nE=r(29899),nP=r(98307),nT=r(65153),n$=r(83448),nR=r(48050),nI=r(45720);function nF({cwd:e,sessionId:t,engine:r,onOpenProjectSessions:l,onOpenSessionBrowser:a,onOpenSettings:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(!1),m=t?(0,nI.X)(r,t):null;return(0,n.jsx)("div",{className:"border-b border-border px-4 py-3 bg-card",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6"}),(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"One seat. One AI. Everything under control."})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e&&(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help","data-tooltip":`CWD: ${e}`,children:e}),!e&&t&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground max-w-md truncate","data-tooltip":t,children:["Session: ",t]}),e&&(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.browseAllSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),m&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(m).then(()=>{u(!0),setTimeout(()=>u(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-11 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:c?d("chat.copiedCommandTooltip"):d("chat.copyCommandTooltip",{command:m}),children:c?(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})})}),(0,n.jsx)("button",{onClick:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("settings.title"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]})]})})}function nB(e){return e>=1e6?`${+(e/1e6).toFixed(e%1e6?1:0)}M`:e>=1e3?`${+(e/1e3).toFixed(e>=1e5?0:1)}K`:String(e)}function nD({tokenUsage:e,rateLimitInfo:t,onOpenContext:r,contextWindow:l}){let{t:a}=(0,o.Bd)(),[i,d]=(0,s.useState)(()=>Date.now());(0,s.useEffect)(()=>{if(!t?.resetsAt)return;let e=setInterval(()=>d(Date.now()),3e4);return()=>clearInterval(e)},[t?.resetsAt]);let c=t?.status==="rejected"?"text-red-11":t?.status==="allowed_warning"?"text-amber-11":"text-muted-foreground",u=t?.status==="rejected"?a("chat.rateLimitRejected","Rate Limited"):t?.status==="allowed_warning"?a("chat.rateLimitWarning","Approaching Limit"):null,m=e=>{if(!e)return"";let t=(e<1e12?1e3*e:e)-i;if(t<=0)return"";let r=Math.ceil(t/6e4);if(r<60)return`${r}m`;let n=Math.floor(r/60),s=r%60;return s>0?`${n}h${s}m`:`${n}h`},x=e=>e?e.replace(/_/g," "):"",h=e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens+e.outputTokens,f=l?h/l:null,p=[l?`${h.toLocaleString()} / ${l.toLocaleString()}`:null,r?a("contextInspector.open"):null].filter(Boolean).join(" \xb7 ")||void 0,g=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),null===f?(0,n.jsxs)("span",{children:[a("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:h.toLocaleString()})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{children:[a("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:nB(h)})," / ",nB(l)]}),(0,n.jsx)("span",{className:"w-10 h-1 rounded-full bg-muted overflow-hidden","aria-hidden":!0,children:(0,n.jsx)("span",{className:`block h-full rounded-full ${null===f?"":f>=.9?"bg-red-9":f>=.7?"bg-amber-9":"bg-brand"}`,style:{width:`${Math.min(100,Math.max(2,100*f))}%`}})}),(0,n.jsxs)("strong",{className:`tabular-nums ${(null===f?"":f>=.9?"text-red-11":f>=.7?"text-amber-11":"")||"text-foreground"}`,children:[Math.round(100*f),"%"]})]})]});return(0,n.jsx)("div",{className:"px-4 py-1.5",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[t&&u&&(0,n.jsxs)("span",{className:`flex items-center gap-1 ${c}`,"data-tooltip":[t.rateLimitType&&`Type: ${x(t.rateLimitType)}`,null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&`Resets in: ${m(t.resetsAt)}`,t.isUsingOverage&&"Using overage"].filter(Boolean).join(" \xb7 "),children:["rejected"===t.status?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:[(0,n.jsx)("strong",{children:u}),null!=t.utilization&&` ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&` \xb7 ${m(t.resetsAt)}`]})]}),t&&!u&&t.resetsAt&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5","data-tooltip":[t.rateLimitType&&x(t.rateLimitType),null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,`Resets in: ${m(t.resetsAt)}`].filter(Boolean).join(" \xb7 "),children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),null!=t.utilization?(0,n.jsxs)("span",{children:[(100*t.utilization).toFixed(0),"%"]}):(0,n.jsx)("span",{children:m(t.resetsAt)})]}),r?(0,n.jsx)("button",{type:"button",onClick:r,className:"flex items-center gap-1.5 rounded px-1 -mx-1 hover:bg-hover hover:text-foreground transition-colors","data-tooltip":p,children:g}):(0,n.jsx)("span",{className:"flex items-center gap-1.5","data-tooltip":p,children:g}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),(0,n.jsxs)("span",{children:[a("chat.output"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:e.outputTokens.toLocaleString()})]})]}),(e.cacheReadInputTokens>0||e.cacheCreationInputTokens>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-brand",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})}),(0,n.jsxs)("span",{children:["Cache: ",(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens)*100).toFixed(0),"%"]})]}),e.totalCostUsd>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-green-11",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:["$",e.totalCostUsd.toFixed(4)]})]})]})})}let nA=["prompt","memory","tools","skills","messages","tool_io","reasoning","other"],nH={light:["#2a78d6","#eb6834","#1baf7a","#eda100","#e87ba4","#008300","#4a3aa7","#e34948"],dark:["#3987e5","#d95926","#199e70","#c98500","#d55181","#008300","#9085e9","#e66767"]},nO={system:"prompt",instructions:"prompt",environment:"prompt",memory:"memory",tools:"tools",mcp:"tools",skills:"skills",agents:"skills",messages:"messages",summary:"messages",tool_io:"tool_io",reasoning:"reasoning",other:"other"};function nW(e){return e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e4?`${Math.round(e/1e3)}K`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}let n_=(e,t)=>null===e?"—":`${t?"":"≈"}${nW(e)}`,nz=(0,s.memo)(function({item:e,selected:t,onSelect:r}){return(0,n.jsxs)("button",{onClick:()=>r(e.id),className:`w-full flex items-center gap-2 pl-7 pr-3 py-1 text-left text-xs transition-colors ${t?"bg-selected text-foreground":"text-muted-foreground hover:bg-hover hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:`flex-1 truncate font-mono ${void 0===e.content?"opacity-60":""}`,children:e.label}),(0,n.jsx)("span",{className:"tabular-nums flex-shrink-0",children:n_(e.tokens,e.exact??!1)})]})}),nq=(0,s.memo)(function({category:e,index:t,color:r,label:l,expanded:a,selectedKey:i,onToggle:d,onSelect:c}){let{t:u}=(0,o.Bd)(),m=(0,s.useCallback)(e=>c(`${t}:${e}`),[t,c]);return(0,n.jsxs)("div",{className:"border-b border-border last:border-b-0",children:[(0,n.jsxs)("button",{onClick:()=>d(t),className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-hover transition-colors",children:[(0,n.jsx)("svg",{className:`w-3 h-3 text-muted-foreground transition-transform flex-shrink-0 ${a?"rotate-90":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-sm flex-shrink-0",style:{backgroundColor:r}}),(0,n.jsx)("span",{className:"flex-1 text-sm text-foreground truncate",children:l}),(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:u("contextInspector.items",{count:e.items.length})}),(0,n.jsx)("span",{className:"text-xs font-medium text-foreground tabular-nums w-14 text-right flex-shrink-0",children:n_(e.tokens,e.exact)})]}),a&&(0,n.jsx)("div",{className:"pb-1",children:e.items.map(e=>(0,n.jsx)(nz,{item:e,selected:i===`${t}:${e.id}`,onSelect:m},e.id))})]})});function nV({isOpen:e,onClose:t,cwd:r,sessionId:l}){let{t:a,i18n:i}=(0,o.Bd)(),{resolvedTheme:d}=(0,e_.DP)(),c=nH["dark"===d?"dark":"light"],[u,m]=(0,s.useState)({status:"idle"}),[x,h]=(0,s.useState)(()=>new Set),[f,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(0),[v,j]=(0,s.useState)(!1);(0,Y.E)(t,e),(0,s.useEffect)(()=>{if(!e||!r||!l)return;let t=!1;return queueMicrotask(()=>{t||m({status:"loading"})}),P.t4.runPromiseExit((0,n$._l)(r,l)).then(e=>{t||("Success"===e._tag?m({status:"ready",data:e.value}):m({status:"error",message:a("contextInspector.loadFailed")}))}),()=>{t=!0}},[e,r,l,g,a]);let w="ready"===u.status?u.data:null,k=(0,s.useMemo)(()=>{let e=new Map;for(let t of w?.categories??[])e.set(nO[t.id],(e.get(nO[t.id])??0)+t.tokens);return nA.map((t,r)=>({group:t,color:c[r],tokens:e.get(t)??0})).filter(e=>e.tokens>0)},[w,c]),y=(0,s.useCallback)(e=>c[nA.indexOf(nO[e])],[c]),N=(0,s.useCallback)(e=>{h(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),C=(0,s.useCallback)(e=>{p(e),j(!1)},[]),S=(0,s.useMemo)(()=>{if(!w||!f)return null;let e=f.indexOf(":"),t=w.categories[Number(f.slice(0,e))],r=t?.items.find(t=>t.id===f.slice(e+1));return t&&r?{category:t,item:r}:null},[w,f]),M=(0,s.useCallback)(()=>{S?.item.content&&navigator.clipboard.writeText(S.item.content).then(()=>j(!0),()=>j(!1))},[S]);if(!e)return null;let L=k.reduce((e,t)=>e+t.tokens,0),E=w?.usedTokens??null,T=Math.max(w?.contextWindow??0,E??0,L,1),$=w?.contextWindow!=null&&null!=E?Math.max(0,w.contextWindow-E):null,R=e=>e.name??a(`contextInspector.categories.${e.id}`),I=w?.capturedAt?new Date(w.capturedAt).toLocaleString(i.language):null;return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-lv3 w-full max-w-6xl mx-4 h-[85vh] flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:a("contextInspector.title")}),w&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground truncate",children:[w.engine,w.model?` \xb7 ${w.model}`:""]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>b(e=>e+1),className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:a("contextInspector.refresh")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),l?"error"===u.status?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-red-11",children:u.message}):w?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-5 py-3 border-b border-border flex-shrink-0 space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-baseline gap-4 text-xs text-muted-foreground",children:[(0,n.jsxs)("span",{children:[a("contextInspector.used"),": ",(0,n.jsx)("strong",{className:"text-foreground text-sm tabular-nums",children:null===E?"—":E.toLocaleString()})]}),(0,n.jsx)("span",{children:w.contextWindow?(0,n.jsxs)(n.Fragment,{children:[a("contextInspector.window"),": ",(0,n.jsx)("strong",{className:"text-foreground tabular-nums",children:w.contextWindow.toLocaleString()}),null!==E&&` (${Math.round(E/w.contextWindow*100)}%)`]}):a("contextInspector.unknownWindow")}),null!==$&&(0,n.jsxs)("span",{children:[a("contextInspector.free"),": ",(0,n.jsx)("span",{className:"tabular-nums",children:$.toLocaleString()})]}),(0,n.jsx)("span",{className:"flex-1"}),I&&(0,n.jsx)("span",{children:a("contextInspector.capturedAt",{time:I})})]}),(0,n.jsx)("div",{className:"flex h-3 w-full rounded bg-muted overflow-hidden gap-[2px]",children:k.map(e=>(0,n.jsx)("div",{className:"h-full first:rounded-l last:rounded-r min-w-[2px]",style:{width:`${e.tokens/T*100}%`,backgroundColor:e.color},"data-tooltip":`${a(`contextInspector.groups.${e.group}`)} \xb7 ${e.tokens.toLocaleString()}`},e.group))}),(0,n.jsx)("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-[11px] text-muted-foreground",children:k.map(e=>(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-sm",style:{backgroundColor:e.color}}),a(`contextInspector.groups.${e.group}`),(0,n.jsx)("span",{className:"text-foreground tabular-nums",children:nW(e.tokens)})]},e.group))}),w.notes.length>0&&(0,n.jsx)("ul",{className:"text-[11px] text-muted-foreground space-y-0.5 list-disc pl-4",children:w.notes.map(e=>(0,n.jsx)("li",{children:a(`contextInspector.notes.${e}`)},e))})]}),(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsx)("div",{className:"w-[38%] min-w-[280px] border-r border-border overflow-y-auto",children:0===w.categories.length?(0,n.jsx)("div",{className:"p-6 text-sm text-muted-foreground text-center",children:a("contextInspector.empty")}):w.categories.map((e,t)=>(0,n.jsx)(nq,{category:e,index:t,color:y(e.id),label:R(e),expanded:x.has(t),selectedKey:x.has(t)?f:null,onToggle:N,onSelect:C},`${e.id}:${t}`))}),(0,n.jsx)("div",{className:"flex-1 min-w-0 flex flex-col",children:S?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-sm flex-shrink-0",style:{backgroundColor:y(S.category.id)}}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-sm text-foreground font-mono truncate",children:S.item.label}),(0,n.jsxs)("div",{className:"text-[11px] text-muted-foreground truncate",children:[R(S.category),S.item.path&&` \xb7 ${S.item.path}`,null!==S.item.tokens&&` \xb7 ${n_(S.item.tokens,S.item.exact??!1)} tokens`]})]}),void 0!==S.item.content&&(0,n.jsx)("button",{onClick:M,className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors flex-shrink-0",children:v?a("contextInspector.copied"):a("contextInspector.copy")})]}),S.item.truncated&&(0,n.jsx)("div",{className:"px-4 py-1 text-[11px] text-amber-11 border-b border-border flex-shrink-0",children:a("contextInspector.truncated",{count:S.item.content?.length??0})}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:void 0===S.item.content?(0,n.jsx)("div",{className:"p-6 text-sm text-muted-foreground",children:a("contextInspector.noContent")}):(0,n.jsx)("pre",{className:"px-4 py-3 text-xs leading-relaxed font-mono text-foreground whitespace-pre-wrap break-words",children:S.item.content})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-6 text-center",children:a("contextInspector.selectItem")})})]})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:a("common.loading")}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:a("contextInspector.noSession")})]})]})}var nU=r(66109);function nK({isOpen:e,onClose:t,cwd:r,sessionId:a,onSelectMessage:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(null),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(""),[p,g]=(0,s.useState)(null),b=(0,s.useRef)(0);(0,s.useEffect)(()=>()=>{++b.current},[e,r,a]);let v=(0,s.useRef)(null),j=(0,s.useRef)(null);(0,Y.E)(t,e),(0,s.useEffect)(()=>{if(!e){u(null),x(!1),f(""),g(null);return}if(!r||!a)return void u([]);let t=!1;return P.t4.runPromiseExit((0,n$.nM)(r,a)).then(e=>{t||("Success"===e._tag?u(e.value.messages):(console.error("Failed to load user message index:",e.cause),x(!0),u([])))}),()=>{t=!0}},[e,r,a]);let w=(0,s.useMemo)(()=>{if(!c)return[];let e=c.map((e,t)=>({entry:e,ordinal:t+1})),t=h.trim().toLowerCase();return t?e.filter(e=>e.entry.content.toLowerCase().includes(t)):e},[c,h]),k=h.trim().length>0;(0,s.useEffect)(()=>{if(!e||k||!c)return;let t=v.current;t&&(t.scrollTop=t.scrollHeight)},[e,k,c]);let y=(0,s.useCallback)(async e=>{let r=++b.current;g(e.id);try{let n=await i(e);r===b.current&&"scrolled"===n.status&&t()}finally{r===b.current&&g(null)}},[i,t]);if(!e)return null;let N=null===c,C=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:nU.iG,onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:d("userMessages.title")}),c&&c.length>0&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:d("userMessages.count",{shown:w.length,total:c.length})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:j,type:"text",autoFocus:!0,placeholder:d("userMessages.searchPlaceholder"),value:h,onChange:e=>f(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),h&&(0,n.jsx)("button",{onClick:()=>{f(""),j.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:d("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{ref:v,className:"flex-1 overflow-y-auto",children:N?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("common.loading")}):m?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("userMessages.loadFailed")}):0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noMessages")}):0===w.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noResults")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:w.map(({entry:e,ordinal:t})=>{let r,s=e.timestamp?function(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let r=new Date;return t.toDateString()===r.toDateString()?t.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}(e.timestamp):"";return(0,n.jsx)("button",{onClick:()=>{y(e)},className:"w-full px-4 py-3 text-left hover:bg-hover transition-colors","data-tooltip":(r=e.content.trim()).length>500?`${r.slice(0,500)}…`:r,children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[t,"."]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-sm text-foreground truncate",children:e.content.replace(/\s+/g," ").trim()}),p===e.id&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:d("userMessages.jumping")})]}),s&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:s})]})},e.id)})})})]})});return(0,n.jsx)(l.ZL,{children:C})}function nQ(e,t,r=t.id){let n=t.sourceRef;return e.find(e=>n?n.sourceId?e.sourceRef?.sourceId===n.sourceId:e.id===n.id&&e.sourceRef?.prefix===n.prefix:e.id===r)}var nG=r(97938),nJ=r(20917),nY=r(74086),nX=r(38719),nZ=r(36351);function n0({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=async t=>{t.stopPropagation();try{var n;if(!navigator.clipboard?.write||"u"<typeof ClipboardItem)throw Error("Clipboard image write is unavailable");let t=await (n=e.preview,new Promise((e,t)=>{let r=new Image;r.onload=()=>{let n=document.createElement("canvas");n.width=r.naturalWidth,n.height=r.naturalHeight;let s=n.getContext("2d");s?(s.drawImage(r,0,0),n.toBlob(r=>{r?e(r):t(Error("Could not encode image"))},"image/png")):t(Error("Canvas is unavailable"))},r.onerror=()=>t(Error("Could not load image")),r.src=n}));await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),(0,q.oR)(r("imagePreview.copiedImage"),"success")}catch{(0,q.oR)(r("common.copyFailed"),"error")}},a=(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,n.jsxs)("div",{className:"absolute top-4 right-4 flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",title:r("imagePreview.copyImage"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V5a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2M7 7h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2Z"})})}),(0,n.jsx)("button",{type:"button",onClick:t,className:"w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,n.jsx)(l.ZL,{children:a})}function n1({images:e,onRemove:t,disabled:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(null);return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 p-2 border-b border-border",children:e.map(e=>(0,n.jsxs)("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-border cursor-pointer",onClick:()=>i(e),children:[(0,n.jsx)("img",{src:e.preview,alt:l("imagePreview.previewImage"),className:"w-full h-full object-cover hover:opacity-90 transition-opacity"}),(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),t(e.id)},className:"absolute top-0 right-0 w-5 h-5 bg-black/60 hover:bg-black/80 text-white text-xs flex items-center justify-center rounded-bl-lg opacity-0 group-hover:opacity-100 transition-opacity",title:l("imagePreview.deleteImage"),children:"✕"})]},e.id))}),a&&(0,n.jsx)(n0,{image:a,onClose:()=>i(null)})]})}var n2=r(38798),n5=r(94514),n4=r(59883),n3=r(56204),n6=r(49387),n8=r(21362),n9=r(63393);let n7=()=>Math.random().toString(36).slice(2,10),se=e=>e.replace(/\\n/g,"\n");function st(e){let t=[],r=null;for(let[n,s]of e.split(/\r?\n/).entries()){if(!s.trim())continue;let e=s.match(/^\s*-(?:\s+(.*))?$/);if(e){let t=(e[1]??"").trim();if(!r)return{ok:!1,line:n+1};r.isGroup=!0,t&&r.children.push(se(t));continue}if(/^\s/.test(s))return{ok:!1,line:n+1};let o=s.trim();o&&(r={text:se(o),children:[],isGroup:!1},t.push(r))}return{ok:!0,nodes:t.map(e=>e.isGroup?{id:n7(),name:e.text,items:e.children.map(e=>({id:n7(),text:e}))}:{id:n7(),text:e.text})}}function sr({title:e,nodes:t,onSave:r,onClose:a}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(()=>t.flatMap(e=>(0,n$._9)(e)?[e.name.replace(/\n/g,"\\n"),...e.items.length>0?e.items.map(e=>`- ${e.text.replace(/\n/g,"\\n")}`):["- "]]:[e.text.replace(/\n/g,"\\n")]).join("\n")),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(!1),f=st(d);(0,Y.E)(a);let p=(0,s.useCallback)(async()=>{let e=st(d);!e.ok||u||((m(!0),h(!1),await r(e.nodes))?a():(m(!1),h(!0)))},[a,r,u,d]);return(0,n.jsx)(l.ZL,{children:(0,n.jsx)("div",{"data-quick-instruction-layer":"",className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":e,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:e}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:i("chat.quickInstructionsMarkdownHint")})]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":i("common.cancel"),children:(0,n.jsx)(ew.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,wrap:"off",value:d,onChange:e=>c(e.target.value),placeholder:i("chat.quickInstructionsMarkdownPlaceholder"),rows:24,spellCheck:!1,className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y overflow-x-auto whitespace-pre px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:f.ok?x?i("chat.saveQuickInstructionsFailed"):"":i("chat.quickInstructionsMarkdownError",{line:f.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:i("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!f.ok||u,onClick:p,className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:i(u?"chat.savingQuickInstructions":"common.save")})]})]})]})})})}let sn="data-quick-instruction-layer",ss=()=>Math.random().toString(36).slice(2,10);function so({groups:e,value:t,onChange:r,onSubmit:l,onCancel:a}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[x,h]=(0,s.useState)(0),f=(0,s.useRef)(null),p=(0,s.useRef)(null),g=[null,...e.map(e=>e.id)],b=null===t?i("chat.instructionGroupNone"):e.find(e=>e.id===t)?.name??i("chat.instructionGroupNone"),v=(0,s.useCallback)(()=>{let r=f.current?.getBoundingClientRect();r&&(m(((e,t,r)=>{let n=Math.min(e.width,r.width-16),s=Math.min(Math.max(8,e.left),Math.max(8,r.width-n-8)),o=r.height-e.bottom-2-8,l=e.top-2-8,a=28*t+8;if(o>=Math.min(a,96)||o>=l)return{left:s,top:e.bottom+2,width:n,maxHeight:Math.max(28,Math.min(a,o))};let i=Math.max(28,Math.min(a,l));return{left:s,top:e.top-2-i,width:n,maxHeight:i}})(r,e.length+1,{width:window.innerWidth,height:window.innerHeight})),h(Math.max(0,g.indexOf(t))),c(!0))},[e.length,g,t]),j=(0,s.useCallback)(()=>{c(!1),m(null),f.current?.focus()},[]),w=(0,s.useCallback)(e=>{r(e),j()},[r,j]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;p.current?.contains(t)||f.current?.contains(t)||(c(!1),m(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]),(0,s.useEffect)(()=>{if(!d)return;let e=()=>{c(!1),m(null)};return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[d]);let k=(0,s.useCallback)(e=>{d?"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),j()):"ArrowDown"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.min(g.length-1,e+1))):"ArrowUp"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.max(0,e-1))):"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),w(g[x]??null)):"ArrowDown"===e.key||" "===e.key?(e.preventDefault(),e.stopPropagation(),v()):"Enter"===e.key?(e.preventDefault(),e.stopPropagation(),l()):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),a())},[d,v,j,w,g,x,l,a]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:f,type:"button",onClick:()=>d?j():v(),onKeyDown:k,className:"w-[140px] min-w-0 flex-shrink-0 px-2 py-1 flex items-center gap-1 text-xs rounded border border-input bg-background hover:bg-hover focus:outline-none focus:ring-1 focus:ring-ring transition-colors",title:i("chat.instructionGroupLabel"),children:[(0,n.jsx)(n2.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-left ${null===t?"text-muted-foreground":""}`,children:b}),(0,n.jsx)(t9.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"})]}),d&&u&&(0,L.createPortal)((0,n.jsx)("div",{ref:p,[sn]:"",role:"listbox",style:{left:u.left,top:u.top,width:u.width,maxHeight:u.maxHeight},className:"fixed z-[60] py-1 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:g.map((r,s)=>{let o=r===t;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":o,onClick:()=>w(r),onMouseEnter:()=>h(s),className:`w-full min-w-0 px-2 py-1 flex items-center gap-1.5 text-xs text-left transition-colors ${s===x?"bg-hover":""}`,children:[(0,n.jsx)(n5.A,{className:`w-3 h-3 flex-shrink-0 ${o?"text-brand":"opacity-0"}`}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate ${null===r?"text-muted-foreground":""}`,children:null===r?i("chat.instructionGroupNone"):e.find(e=>e.id===r)?.name})]},r??"__none__")})}),document.body)]})}function sl({initialValue:e,placeholder:t,groupChoices:r,initialGroupId:o,onCommit:l,onCancel:a}){let[i,d]=(0,s.useState)(e),[c,u]=(0,s.useState)(o??null),m=(0,s.useCallback)(()=>{let e=i.trim();e&&l(e,c)},[i,c,l]),x=(0,s.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing?"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),a()):(e.preventDefault(),e.stopPropagation(),m())},[m,a]);return(0,n.jsxs)("div",{className:"mb-1 flex items-center gap-1",children:[(0,n.jsx)("input",{type:"text",value:i,onChange:e=>d(e.target.value),onKeyDown:x,placeholder:t,autoFocus:!0,className:"flex-1 min-w-0 px-2 py-1 text-xs rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring"}),r&&r.length>0&&(0,n.jsx)(so,{groups:r,value:c,onChange:u,onSubmit:m,onCancel:a})]})}let sa=(e,t)=>`flex items-center group min-w-0 rounded transition-opacity ${e?"opacity-50":""} ${t?"border-t-2 border-brand":""}`,si="p-1 text-muted-foreground hover:text-foreground rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",sd=(0,s.memo)(function({item:e,isDragging:t,isDragOver:r,onSelect:s,onInsert:l,onEdit:a,onDelete:i,onDragStart:d,onDragOver:c,onDrop:u,onDragEnd:m,management:x=!0}){let{t:h}=(0,o.Bd)();return(0,n.jsxs)("div",{draggable:x,onDragStart:x?()=>d(e.id):void 0,onDragOver:x?t=>c(t,e.id):void 0,onDrop:x?()=>u(e.id):void 0,onDragEnd:x?m:void 0,className:sa(t,r),children:[x&&(0,n.jsx)(n4.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsx)(z.m,{content:e.text,children:(0,n.jsxs)("button",{type:"button",onClick:()=>s(e.text),className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",children:[(0,n.jsx)(n3.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:e.text})]})}),(0,n.jsx)("button",{type:"button",onClick:()=>l(e.text),className:si,title:h("chat.insertQuickInstruction"),children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>a(e.id),className:si,title:h("common.edit"),children:(0,n.jsx)(n6.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(e.id),className:`${si} hover:text-destructive`,title:h("common.delete"),children:(0,n.jsx)(ew.A,{className:"w-3 h-3"})})]})]})}),sc=(0,s.memo)(function({group:e,isOpen:t,isDragging:r,isDragOver:l,isDragActive:a,onHoverOpen:i,onHoverClose:d,onToggle:c,onRename:u,onDelete:m,onDragStart:x,onDragOver:h,onDrop:f,onDragEnd:p,management:g=!0}){let{t:b}=(0,o.Bd)(),v=(0,s.useRef)(null),j=(0,s.useCallback)(()=>v.current?.getBoundingClientRect(),[]);return(0,n.jsxs)("div",{ref:v,draggable:g,onDragStart:g?()=>x(e.id):void 0,onDragOver:g?t=>h(t,e.id):void 0,onDrop:g?()=>f(e.id):void 0,onDragEnd:g?p:void 0,onMouseEnter:()=>{if(a)return;let t=j();t&&i(e.id,t)},onMouseLeave:()=>{a||d()},className:`${sa(r,l)} ${t?"bg-hover":""}`,children:[g&&(0,n.jsx)(n4.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{let t=j();t&&c(e.id,t)},className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",title:e.name,children:[(0,n.jsx)(n2.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.name}),(0,n.jsxs)("span",{className:"ml-auto flex items-center gap-1 flex-shrink-0 text-[10px] text-muted-foreground",children:[e.items.length>0&&e.items.length,(0,n.jsx)(n8.A,{className:"w-3 h-3"})]})]}),g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>u(e.id),className:si,title:b("common.edit"),children:(0,n.jsx)(n6.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>m(e.id),className:`${si} hover:text-destructive`,title:b("common.delete"),children:(0,n.jsx)(ew.A,{className:"w-3 h-3"})})]})]})});function su({group:e,position:t,groupChoices:r,editId:s,isAdding:l,isDragActive:a,dragId:i,dragOverId:d,onMouseEnter:c,onMouseLeave:u,onSelect:m,onInsert:x,onStartEdit:h,onCommitEdit:f,onCancelEdit:p,onDelete:g,onStartAdd:b,onCommitAdd:v,onCancelAdd:j,onDragStart:w,onDragOver:k,onDrop:y,onDragEnd:N,management:C=!0}){let{t:S}=(0,o.Bd)();return(0,L.createPortal)((0,n.jsxs)("div",{[sn]:"",onMouseEnter:c,onMouseLeave:()=>{a||u()},style:{left:t.left,top:t.top,width:t.width,maxHeight:t.maxHeight},className:"fixed z-50 p-2 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1 truncate",children:e.name}),C&&(0,n.jsx)("button",{type:"button",onClick:b,className:"p-0.5 text-muted-foreground hover:text-foreground rounded flex-shrink-0",title:S("chat.addQuickInstruction"),children:(0,n.jsx)(r8.A,{className:"w-3.5 h-3.5"})})]}),C&&l&&(0,n.jsx)(sl,{initialValue:"",placeholder:S("chat.quickInstructionPlaceholder"),onCommit:e=>v(e),onCancel:j}),0===e.items.length&&!l&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:S("chat.noQuickInstructions")}),e.items.map(t=>s===t.id?(0,n.jsx)(sl,{initialValue:t.text,placeholder:S("chat.quickInstructionPlaceholder"),groupChoices:r,initialGroupId:e.id,onCommit:(e,r)=>f(t.id,e,r),onCancel:p},`edit-${t.id}`):(0,n.jsx)(sd,{item:t,isDragging:i===t.id,isDragOver:d===t.id&&i!==t.id,onSelect:m,onInsert:x,onEdit:h,onDelete:g,onDragStart:w,onDragOver:k,onDrop:y,onDragEnd:N,management:C},t.id))]}),document.body)}function sm({label:e,nodes:t,scope:r,openGroupId:l,flyoutPosition:a,onOpenFlyout:i,onCloseFlyout:d,onKeepFlyout:c,onSave:u,onSelect:m,onInsert:x,management:h=!0,onManage:f}){let{t:p}=(0,o.Bd)(),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[y,N]=(0,s.useState)(null),[C,S]=(0,s.useState)(null),M=t.filter(n$._9),L=l?M.find(e=>e.id===l)??null:null,E=(0,s.useRef)(t);E.current=t;let P=(0,s.useRef)(l);P.current=l;let T=(0,s.useRef)(null);(0,s.useEffect)(()=>{j(!1)},[l]);let $=(0,s.useCallback)(e=>{k(null),u(r,e)},[u,r]),R=(0,s.useCallback)(e=>{b(null),$([...E.current,{id:ss(),text:e}])},[$]),I=(0,s.useCallback)(e=>{b(null),$([...E.current,{id:ss(),name:e,items:[]}])},[$]),F=(0,s.useCallback)((e,t,r,n)=>{let s=E.current,o={id:e,text:t};if(r===n)return void $(s.map(t=>(0,n$._9)(t)?t.id===n?{...t,items:t.items.map(t=>t.id===e?o:t)}:t:null===n&&t.id===e?o:t));let l=null===r?s.filter(t=>(0,n$._9)(t)||t.id!==e):s.map(t=>(0,n$._9)(t)&&t.id===r?{...t,items:t.items.filter(t=>t.id!==e)}:t);$(null===n?[...l,o]:l.map(e=>(0,n$._9)(e)&&e.id===n?{...e,items:[...e.items,o]}:e))},[$]),B=(0,s.useCallback)((e,t)=>{$(E.current.map(r=>(0,n$._9)(r)&&r.id===e?{...r,name:t}:r))},[$]),D=(0,s.useCallback)(async e=>{let t=E.current.find(t=>t.id===e);if(t&&(0,n$._9)(t)&&t.items.length>0){if(!await (0,q.lJ)(p("chat.deleteInstructionGroupConfirm",{name:t.name,count:t.items.length}),{danger:!0,confirmText:p("common.delete")}))return;d()}k(null),$(E.current.filter(t=>t.id!==e))},[$,p,d]),A=(0,s.useCallback)(e=>{let t=P.current;t&&$(E.current.map(r=>(0,n$._9)(r)&&r.id===t?e(r):r))},[$]),H=(0,s.useCallback)(e=>{j(!1),A(t=>({...t,items:[...t.items,{id:ss(),text:e}]}))},[A]),O=(0,s.useCallback)(e=>{k(null),A(t=>({...t,items:t.items.filter(t=>t.id!==e)}))},[A]),W=(0,s.useCallback)((e,t,r)=>{F(e,t,P.current,r)},[F]),_=(0,s.useCallback)(e=>{T.current=e,N(e)},[]),z=(0,s.useCallback)(()=>{_(null),S(null)},[_]),V=(0,s.useCallback)(e=>{_(e),d()},[_,d]),U=(0,s.useCallback)((e,t)=>{e.preventDefault(),S(t)},[]),K=(e,t,r)=>{let n=e.findIndex(e=>e.id===t),s=e.findIndex(e=>e.id===r);if(n<0||s<0)return e;let o=[...e],[l]=o.splice(n,1);return o.splice(s,0,l),o},Q=(0,s.useCallback)(e=>{let t=T.current;z(),t&&t!==e&&$(K(E.current,t,e))},[$,z]),G=(0,s.useCallback)(e=>{let t=T.current;z(),t&&t!==e&&A(r=>({...r,items:K(r.items,t,e)}))},[A,z]),J=e=>{let t=E.current.find(t=>(0,n$._9)(t)&&t.id===e);return t&&(0,n$._9)(t)?t.items.length:0},Y=(0,s.useCallback)((e,t)=>{i(r,e,t,J(e),!1)},[i,r]),X=(0,s.useCallback)((e,t)=>{P.current===e?d():i(r,e,t,J(e),!0)},[i,d,r]);return(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1",children:e}),h?(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{k(null),b("group")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:p("chat.addInstructionGroup"),children:(0,n.jsx)(n9.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>{k(null),b("instruction")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:p("chat.addQuickInstruction"),children:(0,n.jsx)(r8.A,{className:"w-3.5 h-3.5"})})]}):f?(0,n.jsx)("button",{type:"button",onClick:f,className:"p-1 text-muted-foreground hover:text-brand rounded hover:bg-hover transition-colors",title:p("common.edit"),"aria-label":p("common.edit"),children:(0,n.jsx)(n6.A,{className:"w-3.5 h-3.5"})}):null]}),"instruction"===g&&(0,n.jsx)(sl,{initialValue:"",placeholder:p("chat.quickInstructionPlaceholder"),onCommit:e=>R(e),onCancel:()=>b(null)}),"group"===g&&(0,n.jsx)(sl,{initialValue:"",placeholder:p("chat.instructionGroupNamePlaceholder"),onCommit:e=>I(e),onCancel:()=>b(null)}),0===t.length&&!g&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:p("chat.noQuickInstructions")}),t.map(e=>w===e.id?(0,n$._9)(e)?(0,n.jsx)(sl,{initialValue:e.name,placeholder:p("chat.instructionGroupNamePlaceholder"),onCommit:t=>B(e.id,t),onCancel:()=>k(null)},`edit-${e.id}`):(0,n.jsx)(sl,{initialValue:e.text,placeholder:p("chat.quickInstructionPlaceholder"),groupChoices:M,initialGroupId:null,onCommit:(t,r)=>F(e.id,t,null,r),onCancel:()=>k(null)},`edit-${e.id}`):(0,n$._9)(e)?(0,n.jsx)(sc,{group:e,isOpen:l===e.id,isDragging:y===e.id,isDragOver:C===e.id&&y!==e.id,isDragActive:null!==y,onHoverOpen:Y,onHoverClose:d,onToggle:X,onRename:k,onDelete:D,onDragStart:V,onDragOver:U,onDrop:Q,onDragEnd:z,management:h},e.id):(0,n.jsx)(sd,{item:e,isDragging:y===e.id,isDragOver:C===e.id&&y!==e.id,onSelect:m,onInsert:x,onEdit:k,onDelete:D,onDragStart:V,onDragOver:U,onDrop:Q,onDragEnd:z,management:h},e.id)),L&&a&&(0,n.jsx)(su,{group:L,position:a,groupChoices:M,editId:w,isAdding:v,isDragActive:null!==y,dragId:y,dragOverId:C,onMouseEnter:c,onMouseLeave:d,onSelect:m,onInsert:x,onStartEdit:k,onCommitEdit:W,onCancelEdit:()=>k(null),onDelete:O,onStartAdd:()=>{k(null),j(!0)},onCommitAdd:H,onCancelAdd:()=>j(!1),onDragStart:_,onDragOver:U,onDrop:G,onDragEnd:z,management:h})]})}function sx({cwd:e,anchorRef:t,onClose:r,onSelect:l,onInsert:a}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)([]),[u,m]=(0,s.useState)([]),[x,h]=(0,s.useState)(null),[f,p]=(0,s.useState)(null),g=(0,s.useRef)(null),b=(0,s.useRef)(null),v=(0,s.useRef)(null),j=(0,s.useCallback)(()=>{b.current&&(clearTimeout(b.current),b.current=null),v.current&&(clearTimeout(v.current),v.current=null)},[]);(0,s.useEffect)(()=>j,[j]),(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([P.t4.runPromiseExit((0,n$.ZQ)()),e?P.t4.runPromiseExit((0,n$.$x)(e)):null]);!t&&("Success"===r._tag?c(r.value.instructions??[]):console.error("Failed to load global instructions:",r.cause),n&&"Success"===n._tag?m(n.value.instructions??[]):n&&console.error("Failed to load project instructions:",n.cause))})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{let n;if((n=e.target)instanceof Element&&null!==n.closest(`[${sn}]`))return;let s=t.current;s&&!s.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]),(0,s.useEffect)(()=>{if(!x)return;let e=()=>{j(),h(null)},t=t=>{let r=g.current;r&&t.target instanceof Node&&t.target.contains(r)&&e()};return window.addEventListener("resize",e),window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",t,!0)}},[x,j]);let w=(0,s.useCallback)((e,t,r,n,s)=>{j();let o=()=>{var s;let o,l,a,i,d,c,u;return h({scope:e,groupId:t,position:(l=(s={width:window.innerWidth,height:window.innerHeight}).width-r.right-4-8,a=r.left-4-8,i=288,l>=288?o=r.right+4:a>=288?o=r.left-4-288:l>=a?(i=Math.max(180,l),o=r.right+4):(i=Math.max(180,a),o=r.left-4-i),o=Math.min(Math.max(8,o),Math.max(8,s.width-i-8)),c=Math.min(d=Math.max(90,.6*s.height),30*n+40),(u=r.top-4)+c>s.height-8&&(u=s.height-8-c),{left:o,top:u=Math.max(8,u),width:i,maxHeight:d})})};s?o():b.current=setTimeout(o,150)},[j]),k=(0,s.useCallback)(()=>{j(),v.current=setTimeout(()=>h(null),300)},[j]),y=(0,s.useCallback)(()=>j(),[j]),N=(0,s.useCallback)(async(t,r)=>{let n="global"===t?c:m;n(r);let s=await P.t4.runPromiseExit((0,n$.hZ)("global"===t?{scope:"global",instructions:r}:{cwd:e,instructions:r}));return"Failure"===s._tag?(console.error(`Failed to save ${t} instructions:`,s.cause),!1):(s.value?.instructions&&n(s.value.instructions),!0)},[e]),C=(0,s.useCallback)(e=>{r(),l(e)},[r,l]),S=(0,s.useCallback)(e=>{r(),a(e)},[r,a]),M=(0,s.useCallback)(async e=>!!f&&N(f,e),[f,N]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{ref:g,className:"absolute bottom-full left-0 mb-2 w-80 max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 max-h-[70vh] overflow-y-auto",children:[(0,n.jsx)(sm,{label:i("chat.globalInstructions"),nodes:d,scope:"global",openGroupId:x?.scope==="global"?x.groupId:null,flyoutPosition:x?.scope==="global"?x.position:null,onOpenFlyout:w,onCloseFlyout:k,onKeepFlyout:y,onSave:N,onSelect:C,onInsert:S,management:!1,onManage:()=>{j(),h(null),p("global")}}),e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(sm,{label:i("chat.projectInstructions"),nodes:u,scope:"project",openGroupId:x?.scope==="project"?x.groupId:null,flyoutPosition:x?.scope==="project"?x.position:null,onOpenFlyout:w,onCloseFlyout:k,onKeepFlyout:y,onSave:N,onSelect:C,onInsert:S,management:!1,onManage:()=>{j(),h(null),p("project")}})]})]}),f&&(0,n.jsx)(sr,{title:i("global"===f?"chat.editGlobalInstructions":"chat.editProjectInstructions"),nodes:"global"===f?d:u,onSave:M,onClose:()=>p(null)})]})}var sh=r(96625);let sf=(0,s.memo)(function({onSend:e,disabled:t,running:r,cwd:l,engine:a,onShowGitStatus:i,onShowComments:d,hasComments:c,onOpenNote:u,draft:m,setDraft:x,draftImages:h,setDraftImages:f,suggestion:p,sessionId:g}){let{t:b}=(0,o.Bd)(),v=(0,s.useState)(""),j=(0,s.useState)([]),[w,k]=void 0!==m&&x?[m,x]:v,[y,N]=void 0!==h&&f?[h,f]:j,[C,S]=(0,s.useState)(!1),M=(0,s.useRef)(null),L=(0,s.useRef)(null),E=(0,s.useCallback)(()=>{let e=M.current;if(!e)return;e.style.height="auto";let t=Math.max(38,Math.min(e.scrollHeight,200));e.style.height=`${t}px`},[]);(0,s.useLayoutEffect)(()=>{E()},[w,E]);let P=(0,s.useMemo)(()=>a&&"claude"!==a?[]:[{name:"/plan",description:"Enable plan mode (read-only). /plan <task> to plan a task; /plan off to disable.",source:"builtin",argumentHint:"[task|off]"}],[a]),T=(0,sh.n)({value:w,onChange:k,textareaRef:M,extraCommands:P,selfSessionId:g}),$=(0,s.useCallback)(()=>{let r=w.trim();(r||y.length>0)&&!t&&(e(r,y.length>0?y:void 0),k(""),N([]),M.current&&(M.current.style.height="auto"))},[w,y,t,e]),R=(0,s.useCallback)(r=>{t||e(r)},[t,e]),I=(0,s.useCallback)(e=>{k(t=>{let r=t.replace(/\s+$/,"");return r?`${r}
27
- ${e}`:e}),requestAnimationFrame(()=>{let e=M.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))})},[]),F=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&!T.handleKeyDown(e)){if("Tab"===e.key&&!e.shiftKey&&p&&!w){e.preventDefault(),k(p);return}"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),$())}},[T,$,p,w,k]),B=(0,s.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let r=["image/png","image/jpeg","image/webp","image/gif"];for(let n of Array.from(t)){let t=r.find(e=>n.type===e);if(t){e.preventDefault();let r=n.getAsFile();if(!r)continue;if(r.size>5242880){alert(b("chat.imageSizeLimit",{size:(r.size/1024/1024).toFixed(2)}));continue}let s=new FileReader;s.onload=e=>{let r=e.target?.result;if(!r)return;let n=r.replace(/^data:image\/\w+;base64,/,""),s={id:`img-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,data:n,preview:r,media_type:t};N(e=>[...e,s])},s.readAsDataURL(r)}}},[b]),D=(0,s.useCallback)(e=>{N(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"bg-card relative",children:[(0,n.jsx)(n1,{images:y,onRemove:D,disabled:t}),(0,n.jsx)(sh.V,{ac:T,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64"}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[i&&(0,n.jsx)("button",{onClick:i,className:"p-2 text-brand hover:text-teal-10 hover:bg-brand/10 active:bg-brand/20 active:scale-95 rounded-lg transition-all",title:b("chat.viewGitChanges"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 8v10M18 8v4c0 2-2 4-6 4"})]})}),d&&(0,n.jsx)("button",{onClick:d,className:`p-2 rounded-lg transition-all active:scale-95 ${c?"text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted"}`,title:b("chat.viewAllComments"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),u&&(0,n.jsx)("button",{onClick:u,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:b("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,n.jsxs)("div",{className:"relative",ref:L,children:[(0,n.jsx)("button",{onClick:()=>S(!C),className:`p-2 rounded-lg transition-all ${C?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:b("chat.quickInstructions"),children:(0,n.jsx)(nZ.A,{className:"w-5 h-5"})}),C&&(0,n.jsx)(sx,{cwd:l,anchorRef:L,onClose:()=>S(!1),onSelect:R,onInsert:I})]}),(0,n.jsx)("textarea",{ref:M,value:w,onChange:e=>{k(e.target.value),T.trackCaret(e.target)},onSelect:e=>T.trackCaret(e.currentTarget),onKeyDown:F,onPaste:B,placeholder:t?b("chat.placeholderDisabled"):r?b("chat.placeholderRunning"):p||b("chat.placeholder"),rows:1,className:"flex-1 resize-none px-4 py-2 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-ring bg-card text-foreground"})]})]})});function sp(e){return"env"===e?"from env var":"default"===e?"default":null}function sg({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[i,d]=(0,s.useState)([]),[c,u]=(0,s.useState)(!1),[m,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)(""),[N,C]=(0,s.useState)("default"),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)(""),[T,$]=(0,s.useState)("default"),[R,I]=(0,s.useState)(""),[F,B]=(0,s.useState)(!1),D=(0,s.useRef)(null),A=(0,s.useRef)(null),H=(0,s.useRef)(null),[O,W]=(0,s.useState)({top:0,left:0}),_=(0,l.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{A.current&&!A.current.contains(e.target)&&D.current&&!D.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let z=(0,s.useCallback)(async()=>{u(!0),x(null);let e=await P.t4.runPromiseExit((0,n$.qD)(()=>f(!0)));if(f(!1),"Failure"===e._tag)x("Connection error");else{let t=e.value;switch(t._tag){case"ok":d(t.models);break;case"not-installed":case"error":x(t.message);break;case"not-running":x("Ollama is not running")}}u(!1)},[]),q=(0,s.useCallback)(e=>{y(e.baseUrl),C(e.baseUrlSource),M(e.hasKey),E(e.maskedKey),$(e.keySource),I(""),B(!1)},[]),V=(0,s.useCallback)(async()=>{g(!0),w(null);let e=await P.t4.runPromiseExit((0,n$.F4)());"Failure"===e._tag?w("Failed to load config"):q(e.value),g(!1)},[q]),U=async()=>{v(!0),w(null);let e=await P.t4.runPromiseExit((0,n$.yS)({baseUrl:k}));"Failure"===e._tag?w("Save failed"):(q(e.value),await z()),v(!1)},K=async()=>{let e=R.trim();if(!e)return;v(!0),w(null);let t=await P.t4.runPromiseExit((0,n$.yS)({apiKey:e}));"Failure"===t._tag?w("Save failed"):q(t.value),v(!1)},Q=async()=>{v(!0),w(null);let e=await P.t4.runPromiseExit((0,n$.yS)({apiKey:""}));"Failure"===e._tag?w("Clear failed"):q(e.value),v(!1)},G=e?e.replace(/:latest$/,""):"Select model",J=sp(N),Y=sp(T),X=r?(0,n.jsx)(l.ZL,{children:(0,n.jsxs)("div",{ref:A,className:`${a.ys} min-w-[300px]`,style:{top:O.top,left:O.left},children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Server URL"}),J&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:J})]}),p?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"text",value:k,onChange:e=>y(e.target.value),onKeyDown:e=>{"Enter"===e.key&&U()},placeholder:"http://127.0.0.1:11434",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${a.Fx}`}),(0,n.jsx)("button",{onClick:U,disabled:b,className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${a.$T}`,children:b?"...":"Save"})]})]}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),Y&&S&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:Y})]}),p?null:S&&!F?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:L}),(0,n.jsx)("button",{onClick:()=>{B(!0),I(""),setTimeout(()=>H.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:b,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:b,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:H,type:"password",value:R,onChange:e=>I(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"optional — for authenticated servers",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${a.Fx}`}),(0,n.jsx)("button",{onClick:K,disabled:b||!R.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${a.$T}`,children:b?"...":"Save"}),S&&(0,n.jsx)("button",{onClick:()=>{B(!1),I("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),j&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:j})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),(0,n.jsx)("div",{className:"px-3 pt-1 pb-0.5",children:(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Model"})}),(0,n.jsx)("div",{className:"max-h-[240px] overflow-y-auto",children:c||h?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),h?"Starting Ollama...":"Loading models..."]}):m?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-11",children:m}):0===i.length?(0,n.jsxs)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:["No models found. Run ",(0,n.jsx)("code",{className:"bg-secondary px-1 rounded",children:"ollama pull <model>"})]}):i.map(r=>{var s;let l=r.name===e;return(0,n.jsxs)("button",{onClick:()=>{t(r.name),o(!1)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-xs transition-colors ${l?a.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(a.hG,{selected:l}),(0,n.jsx)("span",{className:"truncate",children:r.name.replace(/:latest$/,"")}),(0,n.jsx)("span",{className:"ml-auto pl-2 text-muted-foreground flex-shrink-0",children:r.parameter_size||((s=r.size)<1e9?`${(s/1e6).toFixed(0)}M`:`${(s/1e9).toFixed(1)}G`)})]},r.name)})})]})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(a.XY,{buttonRef:D,label:G,title:"Configure Ollama",onClick:()=>{if(!r){if(D.current){let e=D.current.getBoundingClientRect(),t=_?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;W({top:e.bottom+4-n,left:e.left-r})}V(),z()}o(e=>!e)},icon:(0,n.jsx)(a.eV,{engine:"ollama"}),testId:"ollama-config-picker"}),X]})}var sb=r(95595);function sv(e){let t=sb.M7,r=e.model&&"grok-build"!==e.model?e.model:sb.yR,s=t.models.find(e=>e.id===r),o=t.models.map(e=>({id:e.id,label:e.label,defaultValue:e.id===t.defaultModel}));o.some(e=>e.id===r)||o.unshift({id:r,label:(0,i.J)(r),defaultValue:!1});let l=s?.reasoning??t.models[0].reasoning,d=l.some(t=>t.id===e.reasoningEffort)?e.reasoningEffort:s?.defaultReasoning??sb.ZL;return(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(y,{title:"Model",selected:r,value:s?.label??o.find(e=>e.id===r).label,items:o,onSelect:r=>{e.onModelChange?.(r),e.onReasoningEffortChange?.(t.models.find(e=>e.id===r)?.defaultReasoning??sb.ZL)},icon:(0,n.jsx)(a.eV,{engine:"grok"}),testId:"grok-model-picker"}),(0,n.jsx)(y,{title:"Reasoning",selected:d,value:l.find(e=>e.id===d)?.label??d,items:l.map(e=>({...e,defaultValue:e.id===(s?.defaultReasoning??sb.ZL)})),onSelect:t=>e.onReasoningEffortChange?.(t),testId:"grok-reasoning-picker"})]})}let sj={deepseek:{label:"DeepSeek",apiKeysUrl:"https://platform.deepseek.com/api_keys",modelsEndpoint:"/v1/models"},kimi:{label:"Kimi",apiKeysUrl:"https://www.kimi.com/code/console",modelsEndpoint:"/coding/v1/models"},glm:{label:"GLM",apiKeysUrl:"https://bigmodel.cn/apikey/platform",modelsEndpoint:"/coding/paas/v4/models",regions:[{id:"cn",label:"中国大陆",hint:"open.bigmodel.cn"},{id:"global",label:"International",hint:"api.z.ai"}]}};function sw({engine:e,currentModel:t,onModelChange:r,onHasKeyChange:o}){let i=sj[e],[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(""),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(!1),[y,N]=(0,s.useState)(null),[C,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)([]),[E,T]=(0,s.useState)(null),[$,R]=(0,s.useState)(null),I=(0,s.useRef)(null),F=(0,s.useRef)(null),B=(0,s.useRef)(null),D=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{D.current&&clearTimeout(D.current)},[]);let A=(0,s.useRef)(t),H=(0,s.useRef)(r),O=(0,s.useRef)(o);(0,s.useEffect)(()=>{A.current=t,H.current=r,O.current=o}),(0,s.useEffect)(()=>{O.current?.(u)},[u]);let[W,_]=(0,s.useState)({top:0,left:0}),z=(0,l.F2)();(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([P.t4.runPromiseExit((0,n$.Hw)(e)),P.t4.runPromiseExit((0,n$.td)())]);if(t||"Failure"===r._tag)return;m(r.value.hasKey),h(r.value.maskedKey);let s="Success"===n._tag?n.value?.engines?.[e]:void 0,o=s?.builtinModel;!A.current&&o&&H.current(o)})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{if(!d)return;let e=e=>{F.current&&!F.current.contains(e.target)&&I.current&&!I.current.contains(e.target)&&c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let q=(0,s.useCallback)(async()=>{j(!0),N(null),T(null);let[n,s]=await Promise.all([P.t4.runPromiseExit((0,n$.Hw)(e)),P.t4.runPromiseExit((0,n$.td)())]);if("Failure"===n._tag){N("Failed to load settings"),j(!1);return}m(n.value.hasKey),h(n.value.maskedKey),p(""),b(!1);let o="Success"===s._tag?s.value:void 0,l=o?.engines?.[e],a=l?.builtinModel;i.regions&&R(l?.region??("en"===o?.language?"global":"cn"));let d=[];if(n.value.hasKey){let t=await P.t4.runPromiseExit((0,n$.Fi)(e));"Success"===t._tag?d=t.value.models:T("Failed to load models — check the API key")}L(d);let c=d.map(e=>e.id),u=a&&c.includes(a)?a:c[0];!u||t&&c.includes(t)||r(u),j(!1)},[e,t,r,i.regions]),V=(0,s.useCallback)(async t=>{let r=await P.t4.runPromiseExit((0,n$.td)()),n=("Success"===r._tag?r.value:{}).engines||{},s={...n,[e]:{...n[e]||{},builtinModel:t}};if("Failure"===(await P.t4.runPromiseExit((0,n$.em)({engines:s})))._tag)throw Error("Failed to save settings")},[e]),U=(0,s.useCallback)(async t=>{R(t);let r=await P.t4.runPromiseExit((0,n$.td)()),n=("Success"===r._tag?r.value:{}).engines||{};"Failure"===(await P.t4.runPromiseExit((0,n$.em)({engines:{...n,[e]:{...n[e]||{},region:t}}})))._tag?N("Failed to save region"):q()},[e,q]),K=async()=>{let t=f.trim();if(!t)return;k(!0),N(null);let r=await P.t4.runPromiseExit((0,n$.dQ)(e,t));"Failure"===r._tag?N("Save failed"):(m(r.value.hasKey),h(r.value.maskedKey),p(""),b(!1),q()),k(!1)},Q=async()=>{k(!0),N(null);let t=await P.t4.runPromiseExit((0,n$.dQ)(e,""));"Failure"===t._tag?N("Clear failed"):(m(t.value.hasKey),h(t.value.maskedKey),p(""),b(!1),L([])),k(!1)},G=async()=>{let t=await P.t4.runPromiseExit((0,n$.Ny)(e));if("Failure"===t._tag||!t.value.apiKey)return void N("Copy failed");try{await navigator.clipboard.writeText(t.value.apiKey)}catch{N("Clipboard unavailable");return}N(null),S(!0),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>S(!1),1500)},J=async e=>{r(e);try{await V(e)}catch{}},Y=u?t||"Select model":"Set API key",X=u?void 0:a.Aw,Z=t||"",ee=d?(0,n.jsx)(l.ZL,{children:(0,n.jsx)("div",{ref:F,className:`${a.ys} min-w-[280px]`,style:{top:W.top,left:W.left},children:v?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),(0,n.jsx)("a",{href:i.apiKeysUrl,target:"_blank",rel:"noopener","data-testid":`${e}-api-keys-link`,title:`Open ${i.label} API keys page`,"aria-label":`Open ${i.label} API keys page`,className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]}),u&&!g?(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:x}),(0,n.jsx)("button",{onClick:G,"data-testid":`${e}-copy-api-key`,title:C?"Copied":"Copy API key","aria-label":"Copy API key",className:`p-1 rounded transition-colors ${C?"text-green-11":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,disabled:w,children:C?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:()=>{b(!0),p(""),setTimeout(()=>B.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:w,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:w,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:B,type:"password",value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"sk-...",className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${a.Fx}`,autoFocus:!0}),(0,n.jsx)("button",{onClick:K,disabled:w||!f.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${a.$T}`,children:w?"Saving...":"Save"}),u&&(0,n.jsx)("button",{onClick:()=>{b(!1),p("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),y&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:y})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),i.regions&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Region"}),(0,n.jsx)("div",{className:"inline-flex rounded-md border border-border overflow-hidden text-xs",role:"group","data-testid":`${e}-region-toggle`,children:i.regions.map(t=>(0,n.jsx)("button",{type:"button","data-testid":`${e}-region-${t.id}`,onClick:()=>U(t.id),title:t.hint,className:`px-2 py-0.5 ${$===t.id?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-hover"}`,children:t.label},t.id))})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"})]}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Model"}),E&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-red-11",children:E}),!E&&0===M.length&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-muted-foreground",children:u?`No models returned by ${i.modelsEndpoint}`:"Save an API key to list models"}),(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:M.map(e=>{var t;let r=Z===e.id,s=(t=e.contextTokens)&&!(t<=0)?t>=1048576?`${Math.round(t/1048576)}M`:`${Math.round(t/1024)}K`:null;return(0,n.jsxs)("button",{onClick:()=>J(e.id),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?a.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(a.hG,{selected:r}),(0,n.jsx)("span",{className:"truncate",children:e.id}),e.label&&e.label!==e.id&&(0,n.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:e.label}),s&&(0,n.jsx)("span",{className:"ml-auto pl-2 text-[10px] text-muted-foreground flex-shrink-0",children:s})]},e.id)})})]})]})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(a.XY,{buttonRef:I,label:Y,labelClassName:X,title:`Configure ${i.label}`,onClick:()=>{if(!d){if(I.current){let e=I.current.getBoundingClientRect(),t=z?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;_({top:e.bottom+4-n,left:e.left-r})}q()}c(e=>!e)},icon:(0,n.jsx)(a.eV,{engine:e}),testId:`${e}-config-picker`}),ee]})}function sk({options:e,level:t,onChange:r}){if(!e||!t||"none"===e.mode||!e.levels.some(e=>"off"!==e))return null;let s=t=>{let r=e.labels[t]??t;return r.charAt(0).toUpperCase()+r.slice(1)};return e.levels.length<=1?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",title:"This model requires thinking","data-testid":"pi-thinking-required",children:s(t)}):(0,n.jsx)(y,{title:"required"===e.mode?"Thinking (required)":"Thinking",selected:t,value:s(t),items:e.levels.map(t=>({id:t,label:s(t),defaultValue:t===e.defaultLevel})),onSelect:r,testId:"pi-thinking-picker"})}let sy=["ollama","deepseek","kimi","glm"];var sN=r(77725);let sC={CNY:"\xa5",USD:"$"};function sS({hasKey:e}){let{t}=(0,o.Bd)(),[r,l]=(0,s.useState)(!1),[i,d]=(0,s.useState)(null),[c,u]=(0,s.useState)(null),m=(0,s.useCallback)(async()=>{l(!0),u(null);let e=await P.t4.runPromiseExit((0,n$.he)());"Failure"===e._tag?(d(null),u(t("chat.balanceFailed",{defaultValue:"Query failed — check the API key"}))):d(e.value),l(!1)},[t]),x=i?i.balances.map(e=>`${sC[e.currency]??(e.currency?`${e.currency} `:"")}${e.totalBalance}`).join(" / "):"",h=!!(i&&!i.isAvailable);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[r&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!r&&c&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:c}),!r&&!c&&i&&(0,n.jsx)("span",{className:`text-xs font-mono ${h?"text-red-11":a.pe.deepseek}`,"data-tooltip":h?t("chat.balanceUnavailable",{defaultValue:"Account is not available for requests"}):void 0,"data-testid":"deepseek-balance-value",children:x||t("chat.balanceEmpty",{defaultValue:"No balance returned"})}),(0,n.jsx)("button",{type:"button","data-testid":"deepseek-balance-button",disabled:!e||r,onClick:m,"data-tooltip":e?void 0:t("chat.balanceNeedsKey",{defaultValue:"Set a DeepSeek API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:t("chat.checkBalance",{defaultValue:"Check balance"})}),(0,n.jsx)("a",{href:"https://platform.deepseek.com/usage",target:"_blank",rel:"noopener","data-testid":"deepseek-usage-link",title:t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),"aria-label":t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}let sM={kimi:"https://www.kimi.com/code/console",glm:"https://bigmodel.cn/coding-plan/personal/usage"};function sL(e){let t=e.remaining??"?",r=e.limit??"?";return`${e.label} ${t}/${r}`}function sE({engine:e,hasKey:t}){let{t:r}=(0,o.Bd)(),[l,i]=(0,s.useState)(!1),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(null),x=(0,s.useCallback)(async()=>{i(!0),m(null);let t=await P.t4.runPromiseExit((0,n$.dM)(e));"Failure"===t._tag?(c(null),m(r("chat.quotaFailed",{defaultValue:"Quota unavailable — check the API key"}))):c(t.value),i(!1)},[r,e]),h=d?.windows??[],f=[d?.tier,...h.map(sL)].filter(Boolean).join(" \xb7 "),p=function(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:`${t.getMonth()+1}/${t.getDate()} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}(h.reduce((e,t)=>t.resetTime&&(!e||t.resetTime>e)?t.resetTime:e,null)),g=h.some(e=>0===e.remaining);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[l&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!l&&u&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:u}),!l&&!u&&d&&(0,n.jsx)("span",{className:`text-xs font-mono ${g?"text-red-11":a.pe[e]}`,"data-tooltip":p?r("chat.quotaResetAt",{defaultValue:"Resets {{time}}",time:p}):void 0,"data-testid":`${e}-quota-value`,children:f||r("chat.quotaEmpty",{defaultValue:"No quota returned"})}),(0,n.jsx)("button",{type:"button","data-testid":`${e}-quota-button`,disabled:!t||l,onClick:x,"data-tooltip":t?void 0:r("chat.quotaNeedsKey",{defaultValue:"Set an API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:r("chat.checkQuota",{defaultValue:"Check quota"})}),(0,n.jsx)("a",{href:sM[e],target:"_blank",rel:"noopener","data-testid":`${e}-console-link`,title:r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),"aria-label":r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}var sP=r(67889),sT=r(46456);function s$(e){if(0===e.length)return"";let t=[t_.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===eW.Un),n=e.filter(e=>e.filePath!==eW.Un);for(let e of(n.length>0&&n.forEach((e,r)=>{let n=e.startLine>0||e.endLine>0?`:${e.startLine}-${e.endLine}`:"";t.push(`[${r+1}] ${e.filePath}${n}`),t.push("```"),t.push(e.codeContent),t.push("```"),e.content&&t.push(t_.A.t("comments.note",{content:e.content})),t.push("")}),r)){let r=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");t.push(r),e.content&&t.push(e.content),t.push("")}return t.join("\n").trim()}function sR({isOpen:e,onClose:t,cwd:r,onNavigateToComment:a}){let{t:i}=(0,o.Bd)(),d=(0,J.r)(),[c,u]=(0,s.useState)([]),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),j=(0,s.useCallback)(async()=>{if(!r)return;x(!0);let e=await P.t4.runPromiseExit((0,sT.$)(r));"Success"===e._tag?u(e.value.comments??[]):console.error("Failed to load comments:",e.cause),x(!1)},[r]);(0,s.useEffect)(()=>{e&&j()},[e,j]);let w=async e=>{let t=await P.t4.runPromiseExit((0,sT.Tu)(r,e));"Success"===t._tag?(u(t=>t.filter(t=>t.id!==e)),(0,eW.Cm)()):console.error("Failed to delete comment:",t.cause)},k=async e=>{f(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await P.t4.runPromiseExit((0,$.K)(r,e.filePath));if("Success"!==n._tag||!n.value.ok)throw Error("Failed to read file");t=(n.value.data?.content||"").split("\n").slice(e.startLine-1,e.endLine).join("\n")}let n={filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,content:e.content,codeContent:t},s=s$([n]);await navigator.clipboard.writeText(s),(0,q.oR)(i("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{f(null)}},y=async()=>{if(0!==c.length){g(!0);try{let e=await (0,eW.$3)(r),t=s$(e);await navigator.clipboard.writeText(t),(0,q.oR)(i("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{g(!1)}}},N=async()=>{if(0!==c.length&&d&&!d.isLoading&&!b){v(!0);try{let e=(await (0,eW.$3)(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0})),n=(0,eW.Gw)(e,"");d.sendMessage(n),await (0,eW.RP)(r),u([]),t()}catch(e){console.error("Failed to send comments to AI:",e)}finally{v(!1)}}},C=c.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let S=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim p-4",onClick:t,children:(0,n.jsxs)("div",{className:"w-full max-w-2xl max-h-[80vh] bg-card border border-border rounded-lg shadow-lv3 flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border ",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:i("comments.allComments")}),c.length>0&&(0,n.jsx)("button",{onClick:y,disabled:p,className:"p-1 rounded hover:bg-hover text-muted-foreground disabled:opacity-50",title:i("comments.copyAllComments"),children:p?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-hover text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:m?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:i("common.loading")}):0===c.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,n.jsx)("svg",{className:"w-12 h-12 mb-3 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsx)("span",{children:i("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(C).map(([e,t])=>(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground font-mono",children:e===eW.Un?i("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",i("comments.nComments",{count:t.length}),")"]})]}),(0,n.jsx)("div",{className:"divide-y divide-border",children:t.map(e=>{var t;return(0,n.jsx)("div",{className:"px-3 py-2 hover:bg-hover cursor-pointer group",onClick:()=>a?.(e),children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[e.startLine>0||e.endLine>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-brand font-mono",children:[i("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",i("comments.linesCount",{count:e.endLine-e.startLine+1}),")"]})]}):e.selectedText?(0,n.jsxs)("span",{className:"text-xs text-muted-foreground italic truncate max-w-[200px]",children:["“",e.selectedText.slice(0,50),e.selectedText.length>50?"...":"","”"]}):null,(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:(t=e.updatedAt||e.createdAt)?new Date(t).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"}):""})]}),(0,n.jsx)("p",{className:"text-sm text-foreground line-clamp-2",children:e.content||(0,n.jsx)("span",{className:"text-muted-foreground italic",children:i("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),k(e)},disabled:h===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover text-muted-foreground transition-opacity disabled:opacity-50",title:i("common.copy"),children:h===e.id?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),w(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover text-muted-foreground hover:text-red-9 transition-opacity",title:i("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)})})]},e))})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:i("comments.totalComments",{count:c.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[d&&(0,n.jsx)("button",{onClick:N,disabled:0===c.length||d.isLoading||b,className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",title:d.isLoading?i("comments.aiResponding"):void 0,children:b?i("comments.submitting"):i("comments.sendToAI")}),(0,n.jsx)("button",{onClick:async()=>{0===c.length||await (0,eW.RP)(r)&&u([])},disabled:0===c.length,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 disabled:opacity-50 disabled:cursor-not-allowed",children:i("comments.clearAll")})]})]})]})});return(0,n.jsx)(l.ZL,{children:S})}var sI=r(67183),sF=r(58453);let sB=`${sP.o.replace(" border-b border-border","")} pl-3 pr-20 bg-card/50`;function sD({tabId:e,initialCwd:t,initialSessionId:r,engine:l,onEngineChange:a,ollamaModel:i,onOllamaModelChange:u,deepseekModel:m,onDeepseekModelChange:x,kimiModel:h,onKimiModelChange:f,glmModel:g,onGlmModelChange:b,claudeModel:v,onClaudeModelChange:j,claudeEffort:k,onClaudeEffortChange:y,claudeFastMode:S,onClaudeFastModeChange:E,claudeThinking:T,onClaudeThinkingChange:$,codexModel:R,onCodexModelChange:I,codexReasoningEffort:F,onCodexReasoningEffortChange:B,grokModel:D,onGrokModelChange:A,grokReasoningEffort:H,onGrokReasoningEffortChange:O,planMode:W,onPlanModeChange:_,noHistory:z,onNoHistoryChange:V,hideHeader:U,hideSidebar:K,isActive:Q=!0,isVisible:G=Q,isFocused:J=Q,peerTabId:Y,peerSide:X,refreshSignal:Z,onLoadingChange:ee,onDraftPresenceChange:et,onSessionIdChange:er,onTitleChange:en,onBotChange:es,onShowGitStatus:eo,onOpenNote:el,onOpenSession:ea,onContentSearch:ei,onShowFileDiff:ed,onOpenFileLink:ec,onOpenSessionBrowser:eu,onOpenSettings:em}){let ex,{t:eh}=(0,o.Bd)(),ef=(0,s.useContext)(C),[ep,eg]=(0,s.useState)(""),[eb,ev]=(0,s.useState)([]),ej=(0,nv.nH)(),[ew,ek]=(0,s.useState)(null),[ey,eN]=(0,s.useState)(!1),[eC,eS]=(0,s.useState)(!1),[eM,eL]=(0,s.useState)(!1),eE=function(e){let[t,r]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{if(!e)return void r(!1);let t=!1,n=async()=>{let n=await P.t4.runPromiseExit((0,sT.lb)(e));t||"Success"!==n._tag||r((n.value.comments?.length??0)>0)};n();let s=(0,eW.zL)(n);return()=>{t=!0,s()}},[e]),t}(t),[eP,e$]=(0,s.useState)(!1),[eR,eI]=(0,s.useState)(null),[eF,eB]=(0,s.useState)(!1),eD=W??eF,eA=(0,s.useCallback)(e=>{eB(e),_?.(e)},[_]),[eH,eO]=(0,s.useState)(!1),e_=z??eH,ez=(0,s.useCallback)(e=>{eO(e),V?.(e)},[V]),[eq,eV]=(0,s.useState)(!1),eU=(0,s.useRef)(null),eK=(0,s.useRef)(null),eQ=(0,s.useCallback)(async e=>{if(!t)return;let r=await P.t4.runPromiseExit((0,nR.iS)(t,e));"Success"===r._tag&&r.value&&"string"==typeof r.value.title?("number"==typeof r.value.titleRevision&&(0,nM.X4)({...r.value,cwd:t,sessionId:e}),en?.((0,nM.iM)((0,nM.V6)(),t,e,r.value.title,r.value.titleRevision))):"Failure"===r._tag&&console.error("Failed to fetch session title:",r.cause)},[t,en]),[eG,eJ]=(0,s.useState)(!1),[eY,eX]=(0,s.useState)(null),[eZ,e0]=(0,s.useState)(null),[e1,e2]=(0,s.useState)(nJ.R),e5=(0,s.useMemo)(()=>(0,nY.hC)(),[]),e4=(0,s.useRef)(!1);(0,s.useEffect)(()=>{e4.current=eG},[eG]);let{messages:e3,recoveryCopies:e6,onRecoveryDeleted:e8,onRecoveryDismissed:e9,setMessages:e7,onLiveSnapshotStart:te,onWriterIdle:tt,setRunMessages:tr,onRunAccepted:tn,onSendFailure:ts,onInputRejected:to,onLiveRunEnd:tl,onSenderStart:ta,isLoadingHistory:ti,isLoadingMore:td,hasMoreHistory:tc,loadMoreHistory:tu,ensureTurnLoaded:tm,cancelTurnLoad:tx,loadHistoryByCwdAndSessionId:th,loadedSessionId:tf,loadedEngine:tp,loadedModel:tg,loadedBot:tb}=(0,nG.m)(ew,{cwd:t,initialSessionId:r,onSessionId:ek,onTitleChange:en,onTokenUsage:eI,enabled:G,liveRunning:eG}),tv=tp??l??void 0;(0,s.useEffect)(()=>{es?.(tb)},[tb,es]);let tj=!tv||"claude"===tv,tw="codex"===tv,tk=v??d,ty=w(tk,k),tN=R??c,tC=D??("grok"===tp?tg??void 0:void 0),tS=p(tN,F),tM="deepseek"===tv||"kimi"===tv||"glm"===tv?tv:null,tL="kimi"===tM?h:"glm"===tM?g:m,tE=function(e,t,r,n,o){let[l,a]=(0,s.useState)(0),[i,d]=(0,s.useState)(),c=JSON.stringify([e,t,r,n,o,l]),u=(0,sN.Z)((0,s.useMemo)(()=>sy.some(t=>t===e)&&t&&("ollama"===e||o)?(0,n$.sy)(e,t,r,n).pipe(eT.TjK(e=>({key:c,options:e}))):eT.PyW(void 0),[e,t,r,n,o,c]),[c]),m="success"===u.status&&u.data?.key===c?u.data.options:void 0,x=i&&i.engine===e&&i.cwd===r&&(i.sessionId===n||null===i.sessionId)?i.level:void 0,h=m?x&&m.levels.includes(x)?x:m.selectedLevel:void 0;return{options:m,level:h,onChange:(0,s.useCallback)(t=>{e&&d({engine:e,cwd:r,sessionId:n,level:t})},[e,r,n]),retry:(0,s.useCallback)(()=>a(e=>e+1),[]),error:"error"===u.status?u.error:void 0}}(tv,"ollama"===tv?i:tL,t,ew,eq),tP="kimi"===tM?f:"glm"===tM?b:x,tT="ollama"===tv||null!==tM||tj||tw||"grok"===tv;(0,s.useEffect)(()=>{tp&&l!==tp&&a?.(tp)},[l,tp,a]);let t$=(0,s.useRef)({ollama:u,deepseek:x,kimi:f,glm:b});t$.current={ollama:u,deepseek:x,kimi:f,glm:b},(0,s.useEffect)(()=>{if(!tg||!tp)return;let e=t$.current;tp in e&&e[tp]?.(tg)},[tf,tg,tp]);let{drainingSubscriptions:tR,isLoading:tI,tokenUsage:tF,liveOutputTokens:tB,runningStartedAt:tD,rateLimitInfo:tA,apiRetryInfo:tH,backgroundTasks:tO,promptSuggestion:tW,handleSend:t_,handleStop:tz,injectMessage:tq}=(0,nJ.e)(e3,tr,{sessionId:ew,cwd:t,engine:tv,planMode:eD,noHistory:e_,ollamaModel:i,engineModel:tL,piThinkingLevel:tE.level,claudeModel:tk,claudeEffort:ty,claudeFastMode:S,claudeThinking:T,codexModel:tN,grokModel:tC,codexReasoningEffort:tS,grokReasoningEffort:H,onSessionId:ek,onFetchTitle:eQ,onSendStart:ta,onRunAccepted:tn,onSendFailure:ts,onInputRejected:to,onRunEnd:tl,onRecoveryDeleted:e8,taskStore:e5}),tV=(tj||tw||"grok"===tv||["ollama","deepseek","kimi","glm"].includes(tv??""))&&!!(tf||ew),tU=(0,s.useCallback)((e,t,r)=>{eU.current?.pinNextUserMessage();let n=tf||ew;return tV&&n&&(tI||e4.current)?tq(e,t,n).catch(t=>{eg(t=>t||e),(0,q.oR)(t instanceof Error?t.message:String(t),"error")}):t_(e,t,r)},[t_,tq,tV,tI,tf,ew]),tK=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(tj){let t=/^\/plan(?:\s+([\s\S]*))?$/.exec(e.trim());if(t){let e=(t[1]??"").trim();"off"===e.toLowerCase()?(eA(!1),(0,q.oR)(eh("chat.planModeOff",{defaultValue:"Plan mode off"}),"info")):""===e?(eA(!0),(0,q.oR)(eh("chat.planModeOn",{defaultValue:"Plan mode on"}),"success")):(eA(!0),tU(e,r,{permissionMode:"plan"}));return}}if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void tU(e,r);let o=e.split("\n").slice(1).join("\n").trim(),l=await P.t4.runPromiseExit((0,n$.JC)({command:s,cwd:t}));if("Success"===l._tag){let e=l.value,t=[e.stdout,e.stderr].filter(Boolean).join("\n")||"(no output)",n=eh("chat.executedCommand",{command:s,exitInfo:e.exitCode?` (exit code: ${e.exitCode})`:"",output:t});o&&(n+=`
28
-
29
- ${o}`),tU(n,r)}else tU(eh("chat.executedCommandFailed",{command:s,error:l.cause}),r);return}tU(e,r)},[tU,t,eh,tj,eA]),tQ=(0,s.useCallback)(()=>{eA(!1),tU(eh("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[tU,eA,eh]),tG=tf||ew,tJ=G&&!tI&&!!tG;(0,nT.u)(tG,tr,tJ,tv,{onSnapshotStart:te,onWriterIdle:tt,onRunEnd:tl,onRecoveryDeleted:e8,onRunningChange:e=>{e4.current=e,eJ(e)},onLiveOutputTokens:eX,onRunStartedAt:e0,onBackgroundTasks:e=>e2(e.length?e:nJ.R),taskStore:e5}),(0,s.useEffect)(()=>{tJ||(eJ(!1),eX(null),e0(null),e2(nJ.R))},[tJ]);let tY=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!Z||Z.nonce===tY.current)return;tY.current=Z.nonce;let e=ew||tf;!t||!e||Z.sessionId!==ew&&Z.sessionId!==tf||tI||eG||th(t,e,!0,10,void 0,!0)},[Z,ew,tf,t,tI,eG,th]);let[tX,t1]=(0,s.useState)(!1),t2=(0,s.useCallback)(()=>t1(!0),[]),t5=(0,s.useCallback)(()=>t1(!1),[]),[t4,t3]=(0,s.useState)(null),t6=ew||tf,t8=tI||eG;(0,s.useEffect)(()=>{if(!t||!t6||t8)return;let e=`${t}\0${t6}`,r=!1;return P.t4.runPromiseExit((0,n$.Ay)(t,t6)).then(t=>{r||"Success"!==t._tag||t3({key:e,value:t.value.contextWindow})}),()=>{r=!0}},[t,t6,t8]);let t9=t4&&t4.key===`${t}\0${t6}`?t4.value:null,t7=tF||eR,re=tI?tB:eG?eY:null,rt=tI?tD:eG?eZ:null,rr=tI?tO:eG?e1:nJ.R;(0,s.useEffect)(()=>{ew&&er?.(ew)},[ew,er]);let rn=ep.trim().length>0||eb.length>0;(0,s.useEffect)(()=>{if(rn&&et)return et(!0),()=>et(!1)},[rn,et]);let rs=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(ee?.(tI),rs.current&&!tI&&t&&ew){let e;for(let t=e3.length-1;t>=0;t--)if("user"===e3[t].role&&e3[t].content){e=(0,sF.e9)((0,sI.a)(e3[t].content)).slice(0,100);break}(0,tZ.F)(t0.n.SessionComplete,{cwd:t,sessionId:ew,lastUserMessage:e})}rs.current=tI},[tI,ee,t]),(0,s.useEffect)(()=>{if(e&&ej&&(ej.setChatLoading(e,Q&&tI&&!tV),Q))return()=>{ej.setChatLoading(e,!1)}},[e,tI,Q,ej,tV]),(0,s.useEffect)(()=>{if(e&&ej)return ej.registerChat(e=>{eK.current?.(e)},e),()=>{ej.unregisterChat(e)}},[e,ej]),(0,s.useEffect)(()=>{e&&Q&&J&&ej&&ej.setActiveTab(e)},[e,Q,J,ej]),(0,s.useEffect)(()=>{eK.current=tK},[tK]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&ey&&(tI||eG)&&tz()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ey,tI,eG,tz]);let ro=(0,s.useCallback)(async(e,r)=>{let n=tf??ew;if(!t||!n)return;let s=await P.t4.runPromiseExit((0,n$.Zr)(n,{cwd:t,fromMessageUuid:e,scope:r}));if("Success"===s._tag&&s.value.newSessionId){let e=s.value.newSessionId;ea?ea(e,"single"===r?"Excerpt":"Fork"):(0,tZ.F)(t0.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===s._tag&&(console.error("Fork failed:",s.cause),(0,q.oR)("single"===r?eh("toast.excerptFailed",{defaultValue:"Failed to excerpt this turn"}):eh("toast.forkFailed",{defaultValue:"Failed to fork session"}),"error"))},[t,tf,ew,ea,eh]),rl=(0,s.useRef)(ro);rl.current=ro;let ra=(0,s.useRef)((e,t)=>rl.current(e,t)).current,ri=(0,s.useCallback)(async e=>{let r=tf??ew;if(!t||!r||tI||eG)return;let n=Math.max(10,(0,nL.l)(e3).length),s=await P.t4.runPromiseExit((0,n$.$N)(r,{cwd:t,messageUuid:e}));"Success"===s._tag?(s.value.recoveryDeletion&&e8(s.value.recoveryDeletion),e7(t=>(0,nL.T)(t,e)),await th(t,r,!1,n,void 0,!0),(0,q.oR)(eh("toast.turnDeleted",{defaultValue:"Turn deleted"}),"success")):(console.error("Delete turn failed:",s.cause),(0,q.oR)(eh("toast.deleteTurnFailed",{defaultValue:"Failed to delete this turn"}),"error"))},[t,tf,ew,tI,eG,e3,th,e8,eh]),rd=(0,s.useRef)(ri);rd.current=ri;let rc=(0,s.useRef)(e=>rd.current(e)).current,ru=(0,s.useCallback)(e=>{if(Y&&ej){if(!ej.sendToTab(Y,e))return void(0,q.oR)(eh("toast.sendToPeerFailed",{defaultValue:"Failed to send to the other pane"}),"error");(0,q.oR)(eh("toast.sentToPeer",{defaultValue:"Sent to the other pane"}),"success")}},[Y,ej,eh]),rm=(0,s.useRef)(ru);rm.current=ru;let rx=(0,s.useRef)(e=>rm.current(e)).current,rh=(0,s.useCallback)(()=>{eL(!0)},[]),rf=(0,s.useCallback)(()=>{e$(!0)},[]),rp=function(e,t,r,n,o,l){let a=(0,s.useRef)(t);(0,s.useLayoutEffect)(()=>{a.current=t},[t]);let i=(0,s.useRef)(null),[d,c]=(0,s.useState)(0),u=(0,s.useCallback)(()=>{l?.(),i.current?.finish({status:"cancelled"}),i.current=null},[l]);(0,s.useLayoutEffect)(()=>u,[e,u]),(0,s.useLayoutEffect)(()=>{let e=i.current;if(!e||e.loading||!r)return;let t=requestAnimationFrame(()=>{if(i.current!==e)return;let t=nQ(a.current,e.target,e.id),r=t?o(t.id)?"scrolled":"failed":e.target.sourceRef&&!e.target.sourceRef.sourceId?"stale":"missing";e.finish({status:r}),i.current=null});return()=>cancelAnimationFrame(t)},[t,r,d,o]);let m=(0,s.useCallback)(e=>(u(),new Promise(t=>{let r={id:e.id,loading:!0,target:e,finish:t};i.current=r;let s=nQ(a.current,e);(s?Promise.resolve({status:"ready",messageId:s.id}):n(e.turnIndex,e.sourceRef)).then(n=>{if(i.current===r){if("ready"!==n.status){i.current=null,t(n);return}r.id=n.messageId??e.id,r.loading=!1,c(e=>e+1)}},()=>{i.current===r&&(i.current=null,t({status:"failed"}))})})),[n,u]);return(0,s.useMemo)(()=>Object.assign(m,{cancel:u}),[m,u])}(`${t}:${tf??ew}`,e3,Q,tm,(0,s.useCallback)(e=>eU.current?.scrollToMessage(e)??!1,[]),tx),rg=(0,s.useCallback)(()=>{rp.cancel(),e$(!1)},[rp]),rb=(0,s.useCallback)(async e=>{let t=await rp(e);return"scrolled"!==t.status&&"cancelled"!==t.status&&(0,q.oR)(eh("chat.messageNavigationFailed",{defaultValue:"The message could not be located. Refresh the message list and try again."}),"error"),t},[rp,eh]),rv=tT?(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eh("chat.noHistoryDesc",{defaultValue:"each prompt is independent"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"nohistory-toggle",checked:e_,onChange:e=>ez(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${e_?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(nE.A,{className:"w-3.5 h-3.5"}),eh("chat.noHistory",{defaultValue:"No history context"})]})]}):null;return(0,n.jsxs)(nY.I$.Provider,{value:e5,children:[tR,(0,n.jsxs)("div",{className:`flex ${U&&K?"h-full":"h-screen"} bg-card`,children:[(0,n.jsxs)("div",{id:"chat-screen",className:"flex-1 flex flex-col min-w-0 relative",onMouseEnter:()=>eN(!0),onMouseLeave:()=>eN(!1),children:[!U&&(0,n.jsx)(nF,{cwd:t,sessionId:ew,engine:tv,onOpenProjectSessions:()=>eS(!0),onOpenSessionBrowser:eu,onOpenSettings:em}),(tj||tw)&&(0,n.jsxs)("div",{className:sB,children:[(0,n.jsx)(N,{engine:tw?"codex":"claude",claudeModel:tk,onClaudeModelChange:j,claudeEffort:ty,onClaudeEffortChange:y,claudeFastMode:S,onClaudeFastModeChange:E,claudeThinking:T,onClaudeThinkingChange:$,codexModel:tN,onCodexModelChange:I,codexReasoningEffort:tS,onCodexReasoningEffortChange:B}),tj&&(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eh("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:eD,onChange:e=>eA(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${eD?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(nP.A,{className:"w-3.5 h-3.5"}),eh("chat.planMode",{defaultValue:"Plan mode"})]})]}),rv]}),"grok"===tv&&(0,n.jsxs)("div",{className:sB,children:[(0,n.jsx)(sv,{model:tC,onModelChange:A,reasoningEffort:H,onReasoningEffortChange:O}),rv]}),"ollama"===tv&&(0,n.jsxs)("div",{className:sB,children:[u&&(0,n.jsx)(sg,{currentModel:i,onModelChange:u}),(0,n.jsx)(sk,{...tE}),rv]}),tM&&(0,n.jsxs)("div",{className:sB,children:[tP&&(0,n.jsx)(sw,{engine:tM,currentModel:tL,onModelChange:tP,onHasKeyChange:eV}),(0,n.jsx)(sk,{...tE}),rv,(0,n.jsx)("div",{className:"ml-auto pl-2",children:"deepseek"===tM?(0,n.jsx)(sS,{hasKey:eq}):(0,n.jsx)(sE,{engine:tM,hasKey:eq})})]}),ti?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:eh("sessions.loadingHistory")})}):(0,n.jsx)(nX.M,{ref:eU,snapshotsEnabled:G,messages:e3,recoveryCopies:e6,onDismissRecoveryCopy:e9,isLoading:tI||eG,liveOutputTokens:re,runningStartedAt:rt,cwd:t,sessionId:ew,engine:tv,botName:tb,apiRetryInfo:tH,backgroundTasks:rr,hasMoreHistory:tc,isLoadingMore:td,onLoadMore:tu,onFork:ra,onDeleteTurn:rc,onSendToPeer:rx,peerSide:X,isActive:Q,onContentSearch:ei,onShowFileDiff:ed,onOpenFileLink:ec,onApprovePlan:tQ,onShowUserMessages:rf}),t7&&(0,n.jsx)(nD,{tokenUsage:t7,rateLimitInfo:tA,onOpenContext:t2,contextWindow:t9}),(0,n.jsx)(nV,{isOpen:tX,onClose:t5,cwd:t,sessionId:ew||tf}),ef&&!J?null:(ex=(0,n.jsx)(sf,{onSend:tK,disabled:(tI||eG)&&!tV,running:tI||eG,cwd:t,engine:tv,onShowGitStatus:eo,onShowComments:t?rh:void 0,hasComments:eE,onOpenNote:el,draft:ep,setDraft:eg,draftImages:eb,setDraftImages:ev,suggestion:tW,sessionId:tf||ew||void 0}),ef?(0,L.createPortal)(ex,ef):ex)]}),!U&&t&&(0,n.jsx)(M.Q,{isOpen:eC,onClose:()=>eS(!1),cwd:t}),t&&(0,n.jsx)(sR,{isOpen:eM,onClose:()=>eL(!1),cwd:t}),(0,n.jsx)(nK,{isOpen:eP,onClose:rg,cwd:t,sessionId:tf??ew,onSelectMessage:rb})]})]})}function sA({tabId:e,cwd:t,sessionId:r,engine:o,onEngineChange:l,ollamaModel:a,onOllamaModelChange:i,deepseekModel:d,onDeepseekModelChange:c,kimiModel:u,onKimiModelChange:m,glmModel:x,onGlmModelChange:h,claudeModel:f,onClaudeModelChange:p,claudeEffort:g,onClaudeEffortChange:b,claudeFastMode:v,onClaudeFastModeChange:j,claudeThinking:w,onClaudeThinkingChange:k,codexModel:y,onCodexModelChange:N,codexReasoningEffort:C,onCodexReasoningEffortChange:S,grokModel:M,onGrokModelChange:L,grokReasoningEffort:E,onGrokReasoningEffortChange:P,planMode:T,onPlanModeChange:$,noHistory:R,onNoHistoryChange:I,isActive:F,isVisible:B,isFocused:D,peerTabId:A,peerSide:H,refreshSignal:O,onDraftChange:W,onStateChange:_,onShowGitStatus:z,onOpenNote:q,onOpenSession:V,onContentSearch:U,onShowFileDiff:K,onOpenFileLink:Q}){let G=(0,s.useCallback)(t=>{_(e,{isLoading:t})},[e,_]),J=(0,s.useCallback)(t=>{W?.(e,t)},[e,W]),Y=(0,s.useCallback)(t=>{_(e,{sessionId:t})},[e,_]),X=(0,s.useCallback)(t=>{_(e,{title:t})},[e,_]),Z=(0,s.useCallback)(t=>{_(e,{bot:t??void 0})},[e,_]),ee=(0,s.useCallback)(t=>{l?.(e,t)},[e,l]),et=(0,s.useCallback)(t=>{i?.(e,t)},[e,i]),er=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),en=(0,s.useCallback)(t=>{m?.(e,t)},[e,m]),es=(0,s.useCallback)(t=>{h?.(e,t)},[e,h]),eo=(0,s.useCallback)(t=>{p?.(e,t)},[e,p]),el=(0,s.useCallback)(t=>{b?.(e,t)},[e,b]),ea=(0,s.useCallback)(t=>{j?.(e,t)},[e,j]),ei=(0,s.useCallback)(t=>{k?.(e,t)},[e,k]),ed=(0,s.useCallback)(t=>{N?.(e,t)},[e,N]),ec=(0,s.useCallback)(t=>{L?.(e,t)},[e,L]),eu=(0,s.useCallback)(t=>{S?.(e,t)},[e,S]),em=(0,s.useCallback)(t=>{P?.(e,t)},[e,P]),ex=(0,s.useCallback)(t=>{$?.(e,t)},[e,$]),eh=(0,s.useCallback)(t=>{I?.(e,t)},[e,I]);return(0,n.jsx)(sD,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,onEngineChange:ee,ollamaModel:a,onOllamaModelChange:et,deepseekModel:d,onDeepseekModelChange:er,kimiModel:u,onKimiModelChange:en,glmModel:x,onGlmModelChange:es,claudeModel:f,onClaudeModelChange:eo,claudeEffort:g,onClaudeEffortChange:el,claudeFastMode:v,onClaudeFastModeChange:ea,claudeThinking:w,onClaudeThinkingChange:ei,codexModel:y,grokModel:M,onCodexModelChange:ed,onGrokModelChange:ec,codexReasoningEffort:C,grokReasoningEffort:E,onCodexReasoningEffortChange:eu,onGrokReasoningEffortChange:em,planMode:T,onPlanModeChange:ex,noHistory:R,onNoHistoryChange:eh,hideHeader:!0,hideSidebar:!0,isActive:F,isVisible:B,isFocused:D,peerTabId:A,peerSide:H,refreshSignal:O,onLoadingChange:G,onDraftPresenceChange:W?J:void 0,onSessionIdChange:Y,onTitleChange:X,onBotChange:Z,onShowGitStatus:z,onOpenNote:q,onOpenSession:V,onContentSearch:U,onShowFileDiff:K,onOpenFileLink:Q})}var sH=r(69895),sO=r(23121),sW=r(88292),s_=r(76900);function sz(e,t){if(!t.split)return{};let r=t.panes.indexOf(e);return -1===r?{}:{peerTabId:t.panes[1-r],peerSide:0===r?"right":"left"}}function sq({tabId:e,panes:t,activePane:r,row:s,maximized:l,onFocusPane:a,onClosePane:i,onToggleMaximize:d,layoutToggle:c,children:u}){let{t:m}=(0,o.Bd)(),x=t.indexOf(e),h=t.length>1;return(0,n.jsxs)("div",{onMouseDownCapture:h?()=>a(x):void 0,style:s&&-1!==x&&!l?{order:x}:void 0,className:`group/pane ${function(e,t,r,n,s){let o=t.indexOf(e);if(-1===o)return"relative hidden";if(s)return"absolute inset-0 z-30 border-y border-y-transparent";if(!n)return"relative h-full block";let l=t.length>1?` border-y ${o===r?"border-y-brand":"border-y-transparent"}`:"";return`relative h-full flex-1 min-w-0${l}${o>0?" border-l border-border":""}`}(e,t,r,s,l)}`,children:[(c||h&&-1!==x)&&(0,n.jsxs)("div",{className:"absolute top-1 right-1 z-20 flex items-center gap-0.5",children:[h&&-1!==x&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 opacity-0 pointer-events-none transition-opacity focus-within:opacity-100 focus-within:pointer-events-auto group-hover/pane:opacity-100 group-hover/pane:pointer-events-auto",children:[(0,n.jsx)("button",{type:"button",onClick:()=>d(x),title:m(l?"chat.restorePane":"chat.maximizePane"),"aria-label":m(l?"chat.restorePane":"chat.maximizePane"),"aria-pressed":l,className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:l?(0,n.jsx)(nC.A,{className:"w-3.5 h-3.5"}):(0,n.jsx)(nS.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(x),title:m("chat.closePane"),"aria-label":m("chat.closePane"),className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),c]}),u]})}function sV({initialCwd:e,initialSessionId:t,initialBlank:r,initialView:a,initialFile:i,initialBubble:u}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(a??"agent"),[f,p]=(0,s.useState)(null),{tabs:g,titlesLoading:b,activeTabId:v,activeTab:j,paneTabIds:w,activePane:k,toggleSideBySide:y,focusPane:N,closePane:C,unreadTabs:L,globalLoadingTabs:E,pageVisible:T,dragTabIndex:$,dragOverTabIndex:R,closeTab:I,closeAllTabs:F,switchTab:B,handleSelectSession:D,handleNewTab:A,handleNewCodexTab:H,handleNewGrokTab:O,handleNewKimiTab:W,handleNewGlmTab:_,handleNewOllamaTab:z,handleNewDeepseekTab:q,handleOpenSession:V,updateTabState:U,updateTabEngine:K,updateTabOllamaModel:Q,updateTabDeepseekModel:G,updateTabKimiModel:J,updateTabGlmModel:Y,updateTabClaudeModel:X,updateTabClaudeEffort:Z,updateTabClaudeFastMode:ee,updateTabClaudeThinking:et,updateTabCodexModel:er,updateTabGrokModel:en,updateTabCodexReasoningEffort:es,updateTabGrokReasoningEffort:eo,updateTabPlanMode:el,updateTabNoHistory:ea,handleTabDragStart:ei,handleTabDragOver:ed,handleTabDrop:ec,handleTabDragEnd:eu}=(0,nk.useTabState)({initialCwd:e,initialSessionId:t,initialBlank:r,activeView:x}),{isPinned:em,pinSession:ex,unpinSession:eh}=(0,sH.P)(),{createTask:ef}=(0,sO.nS)(),ep=(0,s.useCallback)(e=>{let t=g.find(t=>t.id===e);return!!t?.sessionId&&em(t.sessionId)},[g,em]),eg=(0,s.useCallback)(t=>{let r=g.find(e=>e.id===t);r?.sessionId&&(em(r.sessionId)?eh(r.sessionId):ex(r.sessionId,r.cwd||e||"",r.title))},[g,em,ex,eh,e]),ev=(0,s.useCallback)((t,r)=>{let n=g.find(e=>e.id===t),s=n?.cwd||e;if(n&&s){var o;let e,l;ef({...r,...(l="grok"===(e=(o={...n,cwd:s,tabId:t}).engine)?o.grokModel:"ollama"===e?o.ollamaModel:"kimi"===e?o.kimiModel:"glm"===e?o.glmModel:"deepseek"===e?o.deepseekModel:"codex"===e?o.codexModel??c:o.claudeModel??d,{cwd:o.cwd,tabId:o.tabId,sessionId:o.sessionId??crypto.randomUUID(),engine:e,...l&&{model:l}})})}},[g,e,ef]),[ej,ew]=(0,s.useState)(!1),[ek,ey]=(0,s.useState)(!1),[eN,eC]=(0,s.useState)(!1),[eS,eM]=(0,s.useState)(null),[eL,eE]=(0,s.useState)(!1),[eP,e$]=(0,s.useState)("tree"),[eR,eI]=(0,s.useState)(0),[eF,eB]=(0,s.useState)(null),[eD,eA]=(0,s.useState)(0),[eH,eO]=(0,s.useState)(i?{path:i,nonce:0}:null),[eW,e_]=(0,s.useState)(u?{commandId:u,nonce:0}:null),ez=(0,s.useRef)(()=>{}),[eq,eV]=(0,s.useState)(null),eU=null!==eq,eK=(0,s.useMemo)(()=>{let e;return{panes:e=eU?[v]:w,activePane:eU?0:k,row:e.length>1||eU,split:e.length>1,diffOrder:e.length}},[w,k,v,eU]),[eQ,eG]=(0,s.useState)(null),[eJ,eY]=(0,s.useState)();(0,s.useEffect)(()=>{window.parent.postMessage({type:"GET_PROJECT_NUMBER",cwd:e},"*")},[e]),(0,s.useEffect)(()=>{e&&!a&&P.t4.runPromiseExit((0,s_.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&h(t.activeView)}})},[e,a]);let[eX,eZ]=(0,s.useState)(!1),e0=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(e0.current=x,h("console"),eZ(!0)):(eZ(!1),e0.current&&"console"!==e0.current&&h(e0.current),e0.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[x]);let e1=(0,s.useCallback)(t=>{h(t),e&&(P.t4.runFork((0,s_.Yn)({cwd:e,settings:{activeView:t}}).pipe(eT.NWQ(()=>eT.rIH))),P.t4.runFork(eT.qIB(sW.d,r=>r.publish(t0.n.ViewChange,{cwd:e,view:t}))))},[e]);(0,s.useEffect)(()=>{let e=()=>e1("console");return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[e1]);let e2=(0,s.useCallback)(async()=>{if(!e)return;let t=await P.t4.runPromiseExit((0,s_.b2)(e));if("Success"===t._tag){let r=t.value;if(eE(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&eM(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>e2())},[e2]);let e5=(0,s.useCallback)(e=>{let{data:t}=e;Array.isArray(t)&&t.some(e=>"git"===e.type)&&e2()},[e2]);(0,eb.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:e5,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),e1("agent")):"2"===e.key?(e.preventDefault(),e1("explorer")):"3"===e.key?(e.preventDefault(),e1("console")):"s"===e.key&&e.preventDefault())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{e&&window.parent!==window&&window.parent.postMessage({type:"SESSION_NUMBERS",cwd:e,sessionIds:g.map(e=>e.sessionId??null)},"*")},[e,g]);let e4=(0,s.useRef)(new Set),[e3,e6]=(0,s.useState)(!1),e8=(0,s.useCallback)((e,t)=>{let r=e4.current;t?r.add(e):r.delete(e),e6(r.size>0)},[]);(0,s.useEffect)(()=>{e&&window.parent!==window&&window.parent.postMessage({type:"PROJECT_DRAFT",cwd:e,hasDraft:e3},"*")},[e,e3]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="PROJECT_NUMBER"&&"number"==typeof t.data?.projectNumber)return void eY(t.data.projectNumber);if(t.data?.type==="IFRAME_VISIBILITY"&&"number"==typeof t.data?.projectNumber&&eY(t.data.projectNumber),t.data?.type==="GET_SESSION_NUMBERS"&&t.data?.requestId&&e)return void window.parent.postMessage({type:"SESSION_NUMBERS",requestId:t.data.requestId,cwd:e,sessionIds:g.map(e=>e.sessionId??null)},"*");if(t.data?.type==="SWITCH_SESSION"){let{sessionId:e,switchToAgent:r}=t.data;e&&(D(e),r&&e1("agent"),g.find(t=>t.sessionId===e)&&eG(t=>({sessionId:e,nonce:(t?.nonce??0)+1})))}t.data?.type==="OPEN_FILE"&&"string"==typeof t.data?.path&&ez.current({path:t.data.path}),t.data?.type==="FOCUS_CONSOLE_BUBBLE"&&"string"==typeof t.data?.commandId&&(e1("console"),e_(e=>({commandId:t.data.commandId,nonce:(e?.nonce??0)+1})))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[D,e1,e,g]);let e9=(0,s.useCallback)(()=>{e$("status"),eI(e=>e+1),e1("explorer")},[e1]),e7=(0,s.useCallback)(e=>{eB(e),eA(e=>e+1),e1("explorer")},[e1]),te=(0,s.useCallback)(()=>e1("agent"),[e1]),[tt,tr]=(0,s.useState)(!1);(0,s.useEffect)(()=>{eU||tr(!1)},[eU]);let[tn,ts]=(0,s.useState)(!1),to=tn&&eK.split?eK.panes[eK.activePane]??null:null;(0,s.useEffect)(()=>{eK.split||ts(!1)},[eK.split]);let tl=(0,s.useCallback)(e=>{ts(e=>!e),N(e)},[N]),ta=(0,s.useCallback)(()=>tr(e=>!e),[]),ti=(0,s.useCallback)(()=>eV(null),[]),td=(0,s.useRef)(null),tc=(0,s.useCallback)(e=>{let t=td.current;if(!t)return;let r=e.offset>0&&null!==e.target&&t.contains(e.target);if("move"===e.phase){if(!r)return;let n=Math.min(.5*e.offset,t.offsetWidth);t.style.transition="none",t.style.transform=`translateX(${n}px)`;return}r&&e.triggered?(t.style.transition="transform 140ms ease-out, opacity 140ms ease-out",t.style.transform="translateX(100%)",t.style.opacity="0",window.setTimeout(ti,140)):(t.style.transition="transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1)",t.style.transform="")},[ti]);(0,s.useEffect)(()=>{let e=td.current;e&&(e.style.transition="",e.style.transform="",e.style.opacity="")},[eq]);let tu=(0,s.useRef)(eU);(0,s.useEffect)(()=>{tu.current=eU},[eU]);let tm=(0,s.useRef)(to);(0,s.useEffect)(()=>{tm.current=to},[to]);let tx=(0,s.useCallback)(()=>{tu.current?ti():null!==tm.current?ts(!1):y()},[y,ti]),th=to??eK.panes[eK.panes.length-1],tf=(0,s.useMemo)(()=>{let e=eK.split?m("chat.singlePane"):m("chat.splitPane");return(0,n.jsx)("button",{type:"button",onClick:tx,title:e,"aria-label":e,"aria-pressed":eK.split,className:"flex items-center justify-center w-6 h-6 rounded text-muted-foreground transition-colors hover:text-foreground hover:bg-hover",children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",strokeWidth:2}),!eK.split&&(0,n.jsx)("path",{strokeWidth:2,d:"M12 4v16"})]})})},[eK.split,tx,m]),tp=(0,s.useCallback)((e,t,r,n,s)=>{eV(o=>{var l;return l={messageId:e,toolCalls:t,cwd:r,sessionId:n},!0!==s?l:o?.messageId!==l.messageId?o:{...o,toolCalls:l.toolCalls}}),s||e1("agent")},[e1]),tg=(0,s.useCallback)(e=>{eO({...e,nonce:Date.now()}),e1("explorer")},[e1]);(0,s.useEffect)(()=>{ez.current=tg},[tg]);let tb=(0,s.useCallback)(()=>{e&&P.t4.runFork(eT.qIB(sW.d,t=>t.publish(t0.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(nv.k_,{children:(0,n.jsx)(tJ.fY,{activeView:x,onViewChange:e1,onOverscroll:tc,children:(0,n.jsxs)("div",{className:"flex h-screen bg-card",children:[(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,n.jsx)(ny.TabManagerTopBar,{initialCwd:e,activeTab:j,isGitRepo:eL,currentBranch:eS,onOpenWorktree:()=>ey(!0),onOpenAliasManager:()=>eC(!0),onBranchSwitched:e2}),eX&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-1 bg-brand/15 text-brand text-xs font-medium border-b border-brand/20",children:[(0,n.jsx)("span",{className:"animate-pulse",children:"●"}),m("console.screenshotting")]}),e?(0,n.jsxs)(tJ.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(l.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex",children:[(0,n.jsx)(nN.TabBar,{tabs:g,titlesLoading:b,selectedTabId:v,visibleTabIds:w,unreadTabs:L,globalLoadingTabs:E,dragTabIndex:$,dragOverTabIndex:R,isPinned:ep,onTogglePin:eg,onScheduleTask:ev,onSwitchTab:B,onCloseTab:I,onCloseAllTabs:F,onNewTab:A,onNewCodexTab:H,onNewGrokTab:O,onNewKimiTab:W,onNewGlmTab:_,onNewOllamaTab:z,onNewDeepseekTab:q,onOpenProjectSessions:()=>ew(!0),onDragStart:ei,onDragOver:ed,onDrop:ec,onDragEnd:eu}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 h-full flex flex-col",children:[(0,n.jsx)(S,{value:eK.split?f:null,children:(0,n.jsxs)("div",{className:`flex-1 overflow-hidden relative ${eK.row?"flex":""}`,children:[g.map(e=>(0,n.jsx)(sq,{tabId:e.id,panes:eK.panes,activePane:eK.activePane,row:eK.row,maximized:to===e.id,layoutToggle:e.id===th?tf:void 0,onFocusPane:N,onClosePane:C,onToggleMaximize:tl,children:(0,n.jsx)(sA,{tabId:e.id,...sz(e.id,eK),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:K,ollamaModel:e.ollamaModel,onOllamaModelChange:Q,deepseekModel:e.deepseekModel,onDeepseekModelChange:G,kimiModel:e.kimiModel,onKimiModelChange:J,glmModel:e.glmModel,onGlmModelChange:Y,claudeModel:e.claudeModel,onClaudeModelChange:X,claudeEffort:e.claudeEffort,onClaudeEffortChange:Z,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:ee,claudeThinking:e.claudeThinking,onClaudeThinkingChange:et,codexModel:e.codexModel,grokModel:e.grokModel,onCodexModelChange:er,onGrokModelChange:en,codexReasoningEffort:e.codexReasoningEffort,grokReasoningEffort:e.grokReasoningEffort,onCodexReasoningEffortChange:es,onGrokReasoningEffortChange:eo,planMode:e.planMode,onPlanModeChange:el,noHistory:e.noHistory,onNoHistoryChange:ea,isActive:nw(e.id,w,"agent"===x,T),isVisible:nw(e.id,eK.panes,"agent"===x&&!tt,T)&&(!to||to===e.id),isFocused:e.id===v,refreshSignal:eQ,onDraftChange:e8,onStateChange:U,onShowGitStatus:e9,onContentSearch:e7,onShowFileDiff:tp,onOpenFileLink:tg,onOpenNote:tb,onOpenSession:V})},e.id)),eq&&(0,n.jsx)("div",{ref:td,"data-diff-column":"",className:tt?"absolute inset-0 z-30 bg-card":"h-full flex-1 min-w-0 border-l border-border",style:tt?void 0:{order:eK.diffOrder},children:(0,n.jsx)(nj.e$,{toolCalls:eq.toolCalls,cwd:eq.cwd,sessionId:eq.sessionId,onClose:ti,onContentSearch:e7,fullscreen:tt,onToggleFullscreen:ta},eq.messageId)})]})}),eK.split&&(0,n.jsx)("div",{ref:p,className:"flex-shrink-0"})]})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden relative",children:(0,n.jsx)(l.a9,{children:(0,n.jsx)(tX,{onClose:te,cwd:e,initialTab:eP,tabSwitchTrigger:eR,initialSearchQuery:eF,searchQueryTrigger:eD,fileOpenRequest:eH})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(l.a9,{children:(0,n.jsx)(nb,{cwd:e,tabId:"default",onOpenNote:tb,focusBubble:eW,isActive:"console"===x})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)(nN.TabBar,{tabs:g,titlesLoading:b,selectedTabId:v,visibleTabIds:w,unreadTabs:L,globalLoadingTabs:E,dragTabIndex:$,dragOverTabIndex:R,isPinned:ep,onTogglePin:eg,onScheduleTask:ev,onSwitchTab:B,onCloseTab:I,onCloseAllTabs:F,onNewTab:A,onNewCodexTab:H,onNewGrokTab:O,onNewKimiTab:W,onNewGlmTab:_,onNewDeepseekTab:q,onDragStart:ei,onDragOver:ed,onDrop:ec,onDragEnd:eu}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 h-full flex flex-col",children:[(0,n.jsx)(S,{value:eK.split?f:null,children:(0,n.jsx)("div",{className:`flex-1 overflow-hidden relative ${eK.row?"flex":""}`,children:g.map(e=>(0,n.jsx)(sq,{tabId:e.id,panes:eK.panes,activePane:eK.activePane,row:eK.row,maximized:to===e.id,layoutToggle:e.id===th?tf:void 0,onFocusPane:N,onClosePane:C,onToggleMaximize:tl,children:(0,n.jsx)(sA,{tabId:e.id,...sz(e.id,eK),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:K,ollamaModel:e.ollamaModel,onOllamaModelChange:Q,deepseekModel:e.deepseekModel,onDeepseekModelChange:G,kimiModel:e.kimiModel,onKimiModelChange:J,glmModel:e.glmModel,onGlmModelChange:Y,claudeModel:e.claudeModel,onClaudeModelChange:X,claudeEffort:e.claudeEffort,onClaudeEffortChange:Z,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:ee,claudeThinking:e.claudeThinking,onClaudeThinkingChange:et,codexModel:e.codexModel,grokModel:e.grokModel,onCodexModelChange:er,onGrokModelChange:en,codexReasoningEffort:e.codexReasoningEffort,grokReasoningEffort:e.grokReasoningEffort,onCodexReasoningEffortChange:es,onGrokReasoningEffortChange:eo,planMode:e.planMode,onPlanModeChange:el,noHistory:e.noHistory,onNoHistoryChange:ea,isActive:nw(e.id,w,!0,T),isVisible:nw(e.id,eK.panes,!tt,T)&&(!to||to===e.id),isFocused:e.id===v,refreshSignal:eQ,onDraftChange:e8,onStateChange:U,onOpenSession:V})},e.id))})}),eK.split&&(0,n.jsx)("div",{ref:p,className:"flex-shrink-0"})]})]})]}),e&&(0,n.jsx)(M.Q,{isOpen:ej,onClose:()=>ew(!1),cwd:e,onSelectSession:D,projectNumber:eJ,openSessionIds:g.map(e=>e.sessionId)}),e&&eL&&(0,n.jsx)(t1,{isOpen:ek,onClose:()=>ey(!1),cwd:e}),eN&&(0,n.jsx)(ne,{onClose:()=>eC(!1),onSave:()=>eC(!1)})]})})})}},6856:(e,t,r)=>{r.d(t,{BootstrapScripts:()=>l});var n=r(95155),s=r(12115),o=r(73321);function l({bootScript:e,buildId:t,forceUpdate:r}){let a=(0,s.useRef)(!1);return(0,o.useServerInsertedHTML)(()=>a.current?null:(a.current=!0,(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("script",{id:"cockpit-boot",dangerouslySetInnerHTML:{__html:e}}),(0,n.jsx)("script",{id:"cockpit-build",dangerouslySetInnerHTML:{__html:`window.__COCKPIT_BUILD_ID__=${JSON.stringify(t).replace(/</g,"\\u003c")};window.__COCKPIT_FORCE_UPDATE__=${JSON.stringify(r)};`}})]}))),null}},7578:(e,t,r)=>{r.d(t,{S:()=>l,l:()=>a});var n=r(95155),s=r(68287),o=r(16147);function l(e){return"loading"===e||"unread"===e?e:"normal"}function a({projectNumber:e,sessionNumber:t,coordinate:r,status:l="normal",statusLabel:i,bot:d,className:c=""}){if(r){let[n,s]=r.split(".");e??=n,t??=s}if(null==e&&null==t&&"normal"!==l&&(t="\xb7"),null==e&&null==t)return null;let u=[e,t].filter(e=>null!=e).join(".");return(0,n.jsxs)("span",{className:`inline-flex items-center gap-1 font-mono text-[9px] font-medium leading-none tabular-nums flex-shrink-0 ${c}`,"aria-label":i?`${u} \xb7 ${i}`:u,children:[null!=e&&(0,n.jsx)("span",{className:`flex h-4 w-4 items-center justify-center border rounded-[4px] ${(0,s.ci)("normal",!1)}`,children:e}),null!=t&&(0,n.jsx)(o.w,{wash:(0,s.JQ)(l,!1),ring:(0,s.QV)(l),bot:d,title:i,children:t})]})}},12786:(e,t,r)=>{r.d(t,{L:()=>s,Mu:()=>o});var n=r(41463);function s(){return!("u"<typeof navigator)&&(/Mac|iPhone|iPad/.test(navigator.platform||"")||navigator.userAgentData?.platform==="macOS")}function o(){return s()?"⌘":"Ctrl+"}n.platform,n.platform,n.platform},13886:(e,t,r)=>{r.d(t,{ProjectSidebar:()=>eh});var n=r(95155),s=r(12115),o=r(79114),l=r(52252),a=r(49619),i=r(2228),d=r(50538),c=r(68287),u=r(75347),m=r(8183),x=r(66109),h=r(86957),f=r(83448),p=r(92689),g=r(7578),b=r(20832),v=r(84444),j=r(32456),w=r(34075);let k=/https:\/\/github\.com\/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)\/pull\/(\d+)/;var y=r(45720);let N=e=>{let t=e.pr.createdAt?Date.parse(e.pr.createdAt):NaN;return Number.isNaN(t)?e.session.lastActive:t};function C({sessions:e,isLoading:t,error:r,sessionNumbers:l,titleOf:a,onOpenSession:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(""),[m,x]=(0,s.useState)(""),[h,f]=(0,s.useState)(""),[p,g]=(0,s.useState)(null),[v,j]=(0,s.useState)(()=>new Set),w=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=setTimeout(()=>w.current?.focus(),0);return()=>clearTimeout(e)},[]);let y=(0,s.useMemo)(()=>(function(e,t){let r=new Map;for(let t of e)for(let e of t.pullRequests??[]){let n={key:`${e.url}
30
- ${t.cwd}
31
- ${t.sessionId}`,session:t,pr:e},s=r.get(e.url);s?s.push(n):r.set(e.url,[n])}let n=[];for(let[e,s]of r){s.sort((e,t)=>N(e)-N(t));let r=s[0];n.push({url:e,repo:r.pr.repo,number:r.pr.number,title:s.find(e=>e.pr.title)?.pr.title??t(r.session),createdAt:N(r),links:s})}return n.sort((e,t)=>t.createdAt-e.createdAt)})(e,a),[e,a]),E=(0,s.useMemo)(()=>[...new Set(y.map(e=>e.repo))].sort(),[y]),P=(0,s.useMemo)(()=>[...new Set(y.flatMap(e=>e.links.map(e=>e.session.engine||"claude")))].sort(),[y]),T=(0,s.useMemo)(()=>{let e=function(e){let t=e.trim();if(!t)return null;let r=function(e){let t=k.exec(e);if(!t)return null;let r=`${t[1]}/${t[2]}`,n=Number(t[3]);return{url:`https://github.com/${r}/pull/${n}`,repo:r,number:n}}(t);if(r)return{number:r.number,repo:r.repo.toLowerCase()};let n=/^(?:([A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)?)#|#)?(\d+)$/.exec(t);return n?{number:Number(n[2]),repo:n[1]?.toLowerCase()}:null}(c),t=c.trim().toLowerCase();return y.filter(r=>{if(m&&r.repo!==m||h&&!r.links.some(e=>(e.session.engine||"claude")===h))return!1;if(!t)return!0;if(e){if(r.number!==e.number)return!1;if(!e.repo)return!0;let t=r.repo.toLowerCase();return e.repo.includes("/")?t===e.repo:t.split("/")[1]===e.repo}return r.title.toLowerCase().includes(t)||r.repo.toLowerCase().includes(t)||r.links.some(e=>a(e.session).toLowerCase().includes(t))})},[y,c,m,h,a]),$=(0,s.useMemo)(()=>T.flatMap(e=>v.has(e.url)?e.links:[e.links[0]]),[T,v]),R=(0,s.useMemo)(()=>{let e=T.find(e=>e.links.some(e=>e.key===p)),t=e?.links.find(e=>e.key===p);return e&&t?{row:e,link:t}:null},[T,p]);(0,s.useEffect)(()=>{R||g($[0]?.key??null)},[R,$]);let I=(0,s.useCallback)(e=>{window.open(e,"_blank","noopener,noreferrer")},[]),F=(0,s.useCallback)(e=>{j(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-full md:w-[360px] min-h-0 flex-shrink-0 md:border-r border-border flex flex-col",children:[(0,n.jsxs)("div",{className:"p-3 flex-shrink-0 border-b border-border space-y-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:w,type:"text",placeholder:d("sessions.searchPullRequests"),value:c,onChange:e=>u(e.target.value),onKeyDown:e=>{if("ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),0===$.length)return;let t=$.findIndex(e=>e.key===p),r="ArrowDown"===e.key?Math.min($.length-1,t+1):Math.max(0,t-1);g($[r].key)}else"Enter"===e.key&&R&&!e.nativeEvent.isComposing&&(e.preventDefault(),e.metaKey||e.ctrlKey?I(R.row.url):i(R.link.session))},className:"w-full px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),c&&(0,n.jsx)("button",{onClick:()=>{u(""),w.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:d("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)(L,{className:"flex-1 min-w-0",value:m,allLabel:d("sessions.allRepos"),options:E,onChange:x}),(0,n.jsx)(L,{className:"w-28",value:h,allLabel:d("sessions.allEngines"),options:P,onChange:f})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:(0,n.jsx)("div",{className:"p-2 space-y-2",children:(()=>{if(0===e.length&&t)return(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:d("sessions.loadingSessions")});if(0===e.length&&r)return(0,n.jsx)("div",{className:"text-xs text-red-11 text-center py-6",children:r});if(0===y.length)return(0,n.jsxs)("div",{className:"text-xs text-muted-foreground text-center py-6 space-y-1",children:[(0,n.jsx)("div",{children:d("sessions.noPullRequests")}),(0,n.jsx)("div",{className:"text-foreground-subtle",children:d("sessions.noPullRequestsHint")})]});if(0===T.length)return(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:d("sessions.noMatchingPullRequests")});let s=new Date,o=[];for(let e of T){let t=function(e,t){let r=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime();return e>=r?"dateToday":e>=r-864e5?"dateYesterday":e>=r-5184e5?"dateLast7Days":"dateEarlier"}(e.createdAt,s),r=o[o.length-1];r?.group===t?r.rows.push(e):o.push({group:t,rows:[e]})}return o.map(({group:e,rows:t})=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"sticky top-0 z-10 bg-card px-3 py-1 text-[11px] font-medium text-muted-foreground",children:d(`sessions.${e}`)}),(0,n.jsx)("div",{className:"space-y-0.5",children:t.map(e=>{var t;let r,o,d;return(0,n.jsx)(S,{row:e,selectedKey:e.links.some(e=>e.key===p)?p:null,isExpanded:v.has(e.url),clock:(t=e.createdAt,r=new Date(t),o=e=>String(e).padStart(2,"0"),d=`${o(r.getHours())}:${o(r.getMinutes())}`,r.toDateString()===s.toDateString()?d:`${o(r.getMonth()+1)}-${o(r.getDate())} ${d}`),sessionNumbers:l,titleOf:a,onSelect:g,onOpenSession:i,onToggleExpanded:F},e.url)})})]},e))})()})})]}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0 flex-col",children:R?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(M,{row:R.row,link:R.link,onOpenSession:i,onOpenPullRequest:I}),(0,n.jsx)("div",{className:"flex-1 min-h-0 flex",children:(0,n.jsx)(b.p,{cwd:R.link.session.cwd,sessionId:R.link.session.sessionId,subtitle:a(R.link.session),emptyText:d("sessions.noSessionMessages"),onOpenSession:()=>i(R.link.session)},`${R.link.session.cwd}
32
- ${R.link.session.sessionId}`)})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:d("sessions.selectPullRequestHint")})})]})}let S=(0,s.memo)(function({row:e,selectedKey:t,isExpanded:r,clock:s,sessionNumbers:l,titleOf:a,onSelect:i,onOpenSession:d,onToggleExpanded:c}){let u,{t:m}=(0,o.Bd)(),x=e.links[0],h=e=>l[`${e.session.cwd}
33
- ${e.session.sessionId}`];return(0,n.jsxs)("div",{className:`rounded-md ${t?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{onClick:()=>i(x.key),onDoubleClick:()=>d(x.session),className:`px-3 py-2 rounded-md cursor-pointer transition-colors ${t?"":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground truncate","data-tooltip":e.url,children:[(u=e.repo).split("/").pop()||u,"#",e.number]}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0 tabular-nums",children:s})]}),(0,n.jsx)("div",{className:"text-xs text-foreground truncate mt-0.5","data-tooltip":e.title,children:e.title}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mt-1",children:[(0,n.jsx)(p.S,{engine:x.session.engine,size:"sm"}),(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground truncate","data-tooltip":x.session.cwd,children:(0,j.Qr)(x.session.cwd)}),(0,n.jsx)(g.l,{coordinate:h(x),bot:x.session.bot}),e.links.length>1&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),c(e.url)},className:"ml-auto text-[11px] text-muted-foreground hover:text-foreground flex-shrink-0",children:[r?"▾":"▸"," ",m("sessions.pullRequestSessions",{count:e.links.length})]})]})]}),r&&e.links.length>1&&(0,n.jsx)("div",{className:"pb-1",children:e.links.map((r,s)=>(0,n.jsxs)("div",{onClick:()=>i(r.key),onDoubleClick:()=>d(r.session),className:`flex items-center gap-1.5 ml-6 mr-2 px-2 py-1 rounded text-[11px] cursor-pointer ${r.key===t?"bg-brand/15 text-foreground":"text-muted-foreground hover:bg-hover"}`,children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:s===e.links.length-1?"└":"├"}),(0,n.jsx)("span",{className:"truncate flex-1","data-tooltip":a(r.session),children:a(r.session)}),(0,n.jsx)(g.l,{coordinate:h(r),bot:r.session.bot})]},r.key))})]})});function M({row:e,link:t,onOpenSession:r,onOpenPullRequest:s}){let{t:l}=(0,o.Bd)(),a=(0,y.X)(t.session.engine,t.session.sessionId),i="px-2.5 py-1 text-xs rounded border border-border text-foreground hover:bg-hover transition-colors";return(0,n.jsxs)("div",{className:"px-4 py-2.5 border-b border-border flex-shrink-0 space-y-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate","data-tooltip":e.title,children:e.title}),(0,n.jsx)("span",{className:"ml-auto flex-shrink-0",children:(0,n.jsx)(p.S,{engine:t.session.engine})})]}),(0,n.jsxs)("div",{className:"text-[11px] text-muted-foreground truncate","data-tooltip":e.url,children:[e.repo,"#",e.number]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:()=>r(t.session),className:i,title:"↩",children:l("scheduledTasks.openSession")}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(a).then(()=>(0,w.oR)(l("sessions.resumeCommandCopied",{command:a})),()=>(0,w.oR)(l("sessions.copyFailed")))},className:i,title:a,children:l("sessions.copyResumeCommand")}),(0,n.jsxs)("button",{onClick:()=>s(e.url),className:i,title:"⌘↩",children:[l("sessions.openPullRequest")," ↗"]})]})]})}function L({value:e,allLabel:t,options:r,onChange:o,className:l=""}){let[a,i]=(0,s.useState)(!1),d=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!a)return;let e=e=>{d.current?.contains(e.target)||i(!1)},t=e=>{"Escape"===e.key&&(e.stopPropagation(),i(!1))};return window.addEventListener("pointerdown",e),window.addEventListener("keydown",t,!0),()=>{window.removeEventListener("pointerdown",e),window.removeEventListener("keydown",t,!0)}},[a]);let c=["",...r];return(0,n.jsxs)("div",{ref:d,className:`relative ${l}`,children:[(0,n.jsxs)("button",{type:"button",onClick:()=>i(e=>!e),"aria-haspopup":"listbox","aria-expanded":a,className:`w-full flex items-center gap-1 px-2 py-1 text-xs rounded border bg-card text-left transition-colors ${a?"border-brand":"border-border hover:border-foreground-subtle"} ${e?"text-foreground":"text-muted-foreground"}`,children:[(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e||t}),(0,n.jsx)("svg",{className:`w-3 h-3 flex-shrink-0 text-foreground-subtle transition-transform ${a?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&(0,n.jsx)("div",{role:"listbox",className:"absolute left-0 top-full mt-1 z-30 min-w-full max-w-[320px] max-h-64 overflow-y-auto bg-card border border-border rounded-lg shadow-lv2 py-1",children:c.map(r=>(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":r===e,onClick:()=>{o(r),i(!1)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-xs text-left whitespace-nowrap hover:bg-hover transition-colors ${r===e?"text-brand":"text-foreground"}`,children:[(0,n.jsx)("span",{className:"w-3 flex-shrink-0",children:r===e?"✓":""}),(0,n.jsx)("span",{className:"truncate","data-tooltip":r||void 0,children:r||t})]},r||"__all__"))})]})}let E=(e,t)=>`${e}
34
- ${t}`;function P({isOpen:e,onClose:t,onSwitchProject:r,sessionNumbers:l={},projectOrder:a,currentCwd:i,liveSessions:d}){let{t:c}=(0,o.Bd)(),w=(0,u.bc)(),[k,y]=(0,s.useState)([]),[N,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)(null),[T,$]=(0,s.useState)(""),R=(0,s.useRef)(null),[I,F]=(0,s.useState)(null),[B,D]=(0,s.useState)("sessions"),A=(0,s.useCallback)(async()=>{S(!0),L(null);let e=await h.t4.runPromiseExit((0,f.z2)());"Success"===e._tag?y([...e.value]):L(c("sessions.loadSessionsFailed")),S(!1)},[c]);(0,s.useEffect)(()=>{e?(A(),setTimeout(()=>{R.current?.focus(),R.current?.select()},100)):(F(null),D("sessions"))},[e,A]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let H=(0,s.useMemo)(()=>{let e=new Map(d.map(e=>[E(e.cwd,e.sessionId),e])),t=k.map(t=>{let r=e.get(E(t.cwd,t.sessionId));return r?(e.delete(E(t.cwd,t.sessionId)),{...t,...r,searchText:r.searchText??t.searchText,pullRequests:r.pullRequests??t.pullRequests}):t});return(0,v.H)([...t,...e.values()])},[k,d]),O=(0,s.useMemo)(()=>{if(!T)return H;let e=T.toLowerCase();return H.filter(t=>!!(0,m.iM)(w,t.cwd,t.sessionId,t.title||t.sessionId,t.titleRevision).toLowerCase().includes(e)||(void 0!==t.searchText?t.searchText.includes(e):t.cwd.toLowerCase().includes(e)||(t.title?.toLowerCase().includes(e)??!1)||(t.lastUserMessage?.toLowerCase().includes(e)??!1)||(t.firstMessages?.some(t=>t.toLowerCase().includes(e))??!1)||(t.lastMessages?.some(t=>t.toLowerCase().includes(e))??!1)))},[H,T,w]),W=(0,s.useMemo)(()=>(0,j.wG)(O),[O]),_=H.filter(e=>"loading"===e.status).length,z=H.filter(e=>"unread"===e.status).length,q=I?H.find(e=>E(e.cwd,e.sessionId)===I)??null:null;(0,s.useEffect)(()=>{if(!e||"sessions"!==B||q)return;let t=O[0];F(t?E(t.cwd,t.sessionId):null)},[e,B,q,O]);let V=(0,s.useCallback)(e=>{r(e.cwd,e.sessionId),t()},[r,t]),U=(0,s.useCallback)(e=>(0,m.iM)(w,e.cwd,e.sessionId,e.title||e.sessionId,e.titleRevision),[w]),K=e=>{let t=E(e.cwd,e.sessionId),r=t===I;return(0,n.jsxs)("div",{onClick:()=>F(t),onDoubleClick:()=>V(e),className:`group/session-title rounded-md px-3 py-2 cursor-pointer transition-colors ${r?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(p.S,{engine:e.engine}),(0,n.jsx)("span",{className:"text-xs font-medium text-foreground flex items-center gap-1 flex-1 min-w-0","data-tooltip":U(e),children:(0,n.jsx)(u.dh,{cwd:e.cwd,sessionId:e.sessionId,title:e.title||e.sessionId,titleRevision:e.titleRevision})}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:(0,j.fw)(c,e.lastActive)}),(0,n.jsx)(g.l,{coordinate:l[t],status:(0,g.S)(e.status),statusLabel:(0,j.Mm)(c,e.status),bot:e.bot})]}),e.lastUserMessage&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-[22px]","data-tooltip":e.lastUserMessage,children:e.lastUserMessage})]},t)};return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:x.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:c("sessions.recentSessions")}),(0,n.jsx)("div",{className:"flex items-center gap-0.5 p-0.5 rounded-md bg-muted",role:"tablist",children:["sessions","pullRequests"].map(e=>(0,n.jsx)("button",{role:"tab","aria-selected":B===e,onClick:()=>D(e),className:`px-2.5 py-0.5 text-xs rounded transition-colors ${B===e?"bg-card text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,children:c("sessions"===e?"sessions.sessionsTab":"sessions.pullRequestsTab")},e))}),_>0&&(0,n.jsx)("span",{className:"text-xs text-orange-11",children:c("sessions.runningCount",{count:_})}),z>0&&(0,n.jsx)("span",{className:"text-xs text-orange-11",children:c("sessions.unreadCount",{count:z})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 flex min-h-0",children:"pullRequests"===B?(0,n.jsx)(C,{sessions:H,isLoading:N,error:M,sessionNumbers:l,titleOf:U,onOpenSession:V}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-full md:w-[360px] min-h-0 flex-shrink-0 md:border-r border-border flex flex-col",children:[(0,n.jsx)("div",{className:"p-3 flex-shrink-0 border-b border-border",children:(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:R,type:"text",placeholder:c("sessions.searchSessions"),value:T,onChange:e=>$(e.target.value),className:"w-full px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),T&&(0,n.jsx)("button",{onClick:()=>{$(""),R.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:c("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:(0,n.jsx)("div",{className:"p-3 space-y-3",children:0===H.length&&N?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:c("sessions.loadingSessions")}):0===H.length&&M?(0,n.jsx)("div",{className:"text-xs text-red-11 text-center py-6",children:M}):0===O.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:T?c("sessions.noMatchingSessions"):c("sessions.noSessions")}):W.map(e=>{let t=e.items.filter(e=>"loading"===e.status).length,r=e.items.filter(e=>"unread"===e.status).length;return(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)(j.wX,{cwd:e.cwd,projectOrder:a,currentCwd:i,children:[r>0&&(0,n.jsxs)("span",{className:"text-orange-11",children:["\xb7 ",c("sessions.unreadCount",{count:r})]}),t>0&&(0,n.jsxs)("span",{className:"text-orange-11",children:["\xb7 ",c("sessions.runningCount",{count:t})]}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(K)})]},e.cwd)})})})]}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:q?(0,n.jsx)(b.p,{cwd:q.cwd,sessionId:q.sessionId,subtitle:U(q),emptyText:c("sessions.noSessionMessages"),onOpenSession:()=>V(q)},E(q.cwd,q.sessionId)):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:c("sessions.selectSessionHint")})})]})})]})]}):null}function T({projectOrder:e,currentCwd:t,onSwitchProject:r,onResolveSessionNumbers:l,collapsed:a,sessions:i}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)({}),p=(0,s.useRef)(0),g=(0,s.useCallback)(()=>{x(!0);let e=++p.current;f({}),l().then(t=>{p.current===e&&f(t)})},[l]),b=(0,s.useCallback)(()=>{x(!1),p.current+=1},[]),v=i.filter(e=>"loading"===e.status).length,j=i.filter(e=>"unread"===e.status).length;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:g,className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${a?"w-full justify-center":"w-full"}`,title:a?u("sessions.recentSessions"):void 0,children:[(0,n.jsx)(d.A,{className:"w-5 h-5 flex-shrink-0"}),!a&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:u("sessions.recentSessions")}),v>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-xs font-medium rounded-full flex items-center justify-center ${(0,c.ci)("loading",!1)} ${a?"absolute -top-1 -right-1":""}`,children:v}),j>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 bg-orange-11/15 text-orange-11 text-xs font-medium rounded-full flex items-center justify-center ${a&&!v?"absolute -top-1 -right-1":""}`,children:j})]}),(0,n.jsx)(P,{isOpen:m,onClose:b,onSwitchProject:r,sessionNumbers:h,projectOrder:e,currentCwd:t,liveSessions:i})]})}let $=(e,t)=>e<t.top+t.height/2?"before":"after";var R=r(49433);let I=(e,t)=>`${e}
35
- ${t}`;function F({collapsed:e,pinnedSessions:t,sessionNumbers:r,projectOrder:l,currentCwd:a,onSwitchProject:i,onUnpin:d,onReorder:c}){let{t:v}=(0,o.Bd)(),w=(0,u.bc)(),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),S=N?t.find(e=>e.sessionId===N)??null:null,M=(0,s.useMemo)(()=>(0,j.wG)(t),[t]),[L,E]=(0,s.useState)(null),[P,T]=(0,s.useState)(null),[B,D]=(0,s.useState)({});(0,s.useEffect)(()=>{k&&h.t4.runPromise((0,f.z2)().pipe(R.YWq({onSuccess:e=>D(Object.fromEntries(e.map(e=>[I(e.cwd,e.sessionId),e]))),onFailure:()=>{}})))},[k]),(0,s.useEffect)(()=>{k&&!S&&C(t[0]?.sessionId??null)},[k,S,t]);let A=(0,s.useCallback)(()=>{y(!1),C(null),E(null),T(null)},[]);(0,s.useEffect)(()=>{if(!k)return;let e=e=>{"Escape"===e.key&&A()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[k,A]);let H=(0,s.useCallback)(e=>{i(e.cwd,e.sessionId),A()},[i,A]),O=(0,s.useCallback)((e,t)=>{e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.sessionId);let r=e.currentTarget.parentElement;r&&e.dataTransfer.setDragImage(r,16,r.clientHeight/2),E(t),T(null)},[]),W=(0,s.useCallback)((e,t)=>{if(!L||t.cwd!==L.cwd||(e.preventDefault(),e.dataTransfer.dropEffect="move",t.sessionId===L.sessionId))return void T(null);let r=e.currentTarget.getBoundingClientRect(),n=$(e.clientY,r);T(e=>e?.sessionId===t.sessionId&&e.cwd===t.cwd&&e.side===n?e:{cwd:t.cwd,sessionId:t.sessionId,side:n})},[L]),_=(0,s.useCallback)(()=>{E(null),T(null)},[]),z=(0,s.useCallback)((e,r)=>{if(e.preventDefault(),e.stopPropagation(),!L||r.cwd!==L.cwd||r.sessionId===L.sessionId)return void _();let n=$(e.clientY,e.currentTarget.getBoundingClientRect()),s=M.flatMap(e=>e.cwd!==r.cwd?e.items:function(e,t,r,n){let s=e.find(e=>e.sessionId===t);if(!s||t===r||!e.some(e=>e.sessionId===r))return[...e];let o=e.filter(e=>e.sessionId!==t),l=o.findIndex(e=>e.sessionId===r);return o.splice(l+ +("after"===n),0,s),o}(e.items,L.sessionId,r.sessionId,n));s.some((e,r)=>e!==t[r])&&c(s),_()},[L,M,t,c,_]),q=e=>(0,m.iM)(w,e.cwd,e.sessionId,e.title||B[I(e.cwd,e.sessionId)]?.title||e.sessionId),V=e=>{let t=B[I(e.cwd,e.sessionId)],s=e.sessionId===N,o=L?.cwd===e.cwd&&L.sessionId===e.sessionId,l=P?.cwd===e.cwd&&P.sessionId===e.sessionId?P.side:null;return(0,n.jsxs)("div",{onDragOver:t=>W(t,e),onDrop:t=>z(t,e),onDragLeave:t=>{t.relatedTarget instanceof Node&&t.currentTarget.contains(t.relatedTarget)||T(t=>t?.cwd===e.cwd&&t.sessionId===e.sessionId?null:t)},onDragEnd:_,onClick:()=>C(e.sessionId),onDoubleClick:()=>H(e),className:`group relative rounded-md px-2 py-2 cursor-pointer transition-colors flex items-start gap-1.5 ${s?"bg-brand/10":"hover:bg-hover"} ${o?"opacity-35":""}`,children:[l&&(0,n.jsx)("div",{"aria-hidden":"true",className:`pointer-events-none absolute left-1 right-1 z-10 h-0.5 rounded-full bg-brand ${"before"===l?"-top-px":"-bottom-px"}`,children:(0,n.jsx)("span",{className:"absolute -left-0.5 -top-0.5 h-1.5 w-1.5 rounded-full bg-brand"})}),(0,n.jsx)("span",{draggable:!0,onDragStart:t=>O(t,e),onClick:e=>e.stopPropagation(),title:v("sessions.dragToReorder"),className:`mt-1 text-muted-foreground/30 hover:text-foreground flex-shrink-0 select-none ${L?"cursor-grabbing":"cursor-grab"}`,children:(0,n.jsxs)("svg",{className:"w-3 h-3",viewBox:"0 0 10 16",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"3",cy:"2",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"2",r:"1.5"}),(0,n.jsx)("circle",{cx:"3",cy:"8",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"8",r:"1.5"}),(0,n.jsx)("circle",{cx:"3",cy:"14",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"14",r:"1.5"})]})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(p.S,{engine:t?.engine}),(0,n.jsx)("span",{className:"flex items-center gap-1 text-xs font-medium text-foreground flex-1 min-w-0",children:(0,n.jsx)(u.dh,{cwd:e.cwd,sessionId:e.sessionId,title:q(e),editable:!1})}),t?.lastActive?(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0 group-hover:hidden",children:(0,j.fw)(v,t.lastActive)}):null,(0,n.jsx)(g.l,{coordinate:r?.[I(e.cwd,e.sessionId)],status:(0,g.S)(t?.status),statusLabel:(0,j.Mm)(v,t?.status),bot:t?.bot}),(0,n.jsx)("div",{className:"flex-shrink-0 hidden group-hover:flex items-center gap-0.5",children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),d(e.sessionId)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:v("sessions.removeFavorite"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]}),t?.lastUserMessage&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-[22px]","data-tooltip":t.lastUserMessage,children:t.lastUserMessage})]})]},e.sessionId)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>y(!0),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${e?"w-full justify-center":"w-full"}`,title:e?v("sessions.favorites"):void 0,children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"})}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:v("sessions.favorites")}),e&&t.length>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-popover border border-border",children:t.length})]}),k&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:A}),(0,n.jsxs)("div",{className:x.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:v("sessions.favorites")}),t.length>0&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.length})]}),(0,n.jsx)("button",{onClick:A,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 flex min-h-0",children:0===t.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:v("sessions.noFavorites")})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-full md:w-[360px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:(0,n.jsx)("div",{className:"p-3 space-y-3",children:M.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsx)(j.wX,{cwd:e.cwd,projectOrder:l,currentCwd:a,children:(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(V)})]},e.cwd))})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:S?(0,n.jsx)(b.p,{cwd:S.cwd,sessionId:S.sessionId,subtitle:q(S),emptyText:v("sessions.noSessionMessages"),onOpenSession:()=>H(S)},I(S.cwd,S.sessionId)):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:v("sessions.selectFavoriteHint")})})]})})]})]})]})}var B=r(80860),D=r(23121),A=r(93777),H=r(95686);function O({task:e,onOpenSession:t}){let{t:r}=(0,o.Bd)();return(0,n.jsx)(b.p,{cwd:e.cwd,sessionId:e.sessionId,subtitle:(0,D.Q_)(e),emptyText:r("scheduledTasks.noTaskMessages"),onOpenSession:t})}var W=r(15317);function _(e){return e.engine||"claude"}function z(e){return!!e.completed&&!e.firingSince}function q(e){return e.lastFiredAt??e.createdAt}let V=e=>!!e.unread||z(e);function U({collapsed:e,tasks:t,unreadCount:r,sessionNumbers:l,projectOrder:a,currentCwd:i,onSwitchProject:d,onPause:c,onResume:u,onTrigger:m,onDelete:b,onUpdateTask:v}){let{t:k}=(0,o.Bd)(),[y,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(null),M=(0,s.useRef)(null),L=(0,s.useRef)(null),[E,P]=(0,s.useState)(null),T=(0,s.useCallback)(()=>{S(null),M.current=null,P(null)},[]),[$,R]=(0,s.useState)(null),[I,F]=(0,s.useState)(null),[K,Q]=(0,s.useState)(null),[G,J]=(0,s.useState)(null),Y=t.filter(e=>!z(e)),X=Y.filter(e=>!e.paused).length,Z=(0,s.useMemo)(()=>(0,j.wG)(function(e){let t=[],r=[],n=[];for(let s of e)s.unread||z(s)?t.push(s):s.paused?n.push(s):r.push(s);return t.sort((e,t)=>Number(!!t.unread)-Number(!!e.unread)||q(t)-q(e)),r.sort((e,t)=>(e.nextFireTime||Number.MAX_SAFE_INTEGER)-(t.nextFireTime||Number.MAX_SAFE_INTEGER)),n.sort((e,t)=>q(t)-q(e)),[...t,...r,...n]}(t)),[t]),ee=K?t.find(e=>e.id===K)??null:null;(0,s.useEffect)(()=>{if(!y||ee)return;let e=Z[0]?.items[0];Q(e?.id??null)},[y,ee,Z]);let[,et]=(0,s.useState)(0);(0,s.useEffect)(()=>{if(!y)return;let e=setInterval(()=>et(e=>e+1),1e4);return()=>clearInterval(e)},[y]),(0,s.useEffect)(()=>{if(!$)return;let e=!1;return F(null),h.t4.runPromiseExit((0,f.an)($)).then(t=>{e||("Success"===t._tag&&void 0!==t.value.content?F(t.value.content):((0,w.oR)(k("toast.readFileFailed"),"error"),R(null)))}),()=>{e=!0}},[$,k]);let er=(0,s.useCallback)(()=>{R(null),F(null)},[]),en=(0,s.useCallback)(async e=>{let t=!!e.taskFile;try{await navigator.clipboard.writeText(t?e.taskFile:e.message),(0,w.oR)(k(t?"common.copiedPath":"toast.copiedMessage"),"success")}catch{(0,w.oR)(k("common.copyFailed"),"error")}},[k]),es=(0,s.useCallback)(()=>{N(!1),Q(null)},[]);(0,s.useEffect)(()=>{if(!y)return;let e=e=>{if("Escape"===e.key){if($)return void er();if(C)return void T();es()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[y,C,$,er,es,T]),(0,s.useLayoutEffect)(()=>{if(!C)return;let e=()=>{let e=M.current,t=L.current;if(!e||!t)return;let r=e.getBoundingClientRect();if(!r.width&&!r.height)return;let{width:n,height:s}=t.getBoundingClientRect(),o=r.right+8;if(o+n>window.innerWidth-8){let e=r.left-n-8;o=e>=8?e:Math.max(8,window.innerWidth-n-8)}let l=Math.max(8,Math.min(r.top,window.innerHeight-s-8));P(e=>e&&e.top===l&&e.left===o?e:{top:l,left:o})};e();let t=new ResizeObserver(e);return L.current&&t.observe(L.current),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[C]);let eo=(0,s.useCallback)(e=>{d(e.cwd,e.sessionId),es()},[d,es]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>N(!0),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${e?"w-full justify-center":"w-full"}`,title:e?k("scheduledTasks.title"):void 0,children:[(0,n.jsx)(B.A,{className:"w-5 h-5 flex-shrink-0"}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:k("scheduledTasks.title")}),r>0?(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 bg-orange-11/15 text-orange-11 text-xs font-medium rounded-full flex items-center justify-center ${e?"absolute -top-1 -right-1":""}`,children:r}):e&&t.length>0?(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-popover border border-border",children:t.length}):null]}),y&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:es}),(0,n.jsxs)("div",{className:x.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:k("scheduledTasks.title")}),Y.length>0&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[k("scheduledTasks.activeCount",{running:X}),Y.length-X>0?` \xb7 ${k("scheduledTasks.pausedCount",{paused:Y.length-X})}`:""]})]}),(0,n.jsx)("button",{onClick:es,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 flex min-h-0",children:0===t.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:k("scheduledTasks.noScheduledTasks")})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-full md:w-[360px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:(0,n.jsx)("div",{className:"p-3 space-y-3",children:Z.map(e=>{let t=e.items.filter(V).length;return(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)(j.wX,{cwd:e.cwd,projectOrder:a,currentCwd:i,children:[t>0&&(0,n.jsxs)("span",{className:"text-orange-11",children:["\xb7 ",k("scheduledTasks.pendingCount",{count:t})]}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(e=>{let t,r;return t=e.id===K,(0,n.jsxs)("div",{onClick:()=>Q(e.id),onMouseLeave:()=>J(t=>t===e.id?null:t),className:`group rounded-md px-3 py-2 cursor-pointer transition-colors ${t?"bg-brand/10":e.unread?"bg-brand/5 hover:bg-hover":"hover:bg-hover"} ${z(e)?"opacity-70":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)(p.S,{engine:_(e),tooltip:(r=_(e),e.model?`${r} \xb7 ${e.model}`:r)}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-1 min-w-0 truncate",children:e.firingSince?k("scheduledTasks.inFlight"):z(e)?k("scheduledTasks.completed"):e.paused?k("scheduledTasks.paused"):k("common.running")}),(0,n.jsx)(g.l,{coordinate:l?.[`${e.cwd}
36
- ${e.sessionId}`]}),G===e.id?(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),J(null),b(e.id)},className:"px-2 py-0.5 text-[10px] rounded bg-red-9 text-white hover:bg-red-10",children:k("common.confirm")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),J(null)},className:"px-2 py-0.5 text-[10px] rounded border border-border text-muted-foreground hover:text-foreground",children:k("common.cancel")})]}):(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.taskFile&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),R(e.taskFile)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:k("common.preview"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),en(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:k(e.taskFile?"common.copyPath":"common.copy"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),m(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-brand",title:k("scheduledTasks.runNow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{d:"M8 5v14l11-7z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),M.current=t.currentTarget,S(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:k("common.edit"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"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"})})}),z(e)?null:e.paused?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),u(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-green-11",title:k("scheduledTasks.resume"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"})})}):(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),c(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-amber-11",title:k("scheduledTasks.pause"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 9v6m4-6v6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),J(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:k("common.delete"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{className:"text-xs text-foreground line-clamp-3 mb-1 whitespace-pre-wrap break-words","data-tooltip":(0,D.Q_)(e),children:(0,D.Q_)(e)}),(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"truncate",children:function(e,t){if("once"===e.type)return t("scheduledTasks.onceType",{duration:(0,W.dp)(e.delayMinutes??0,t)});if("interval"===e.type){var r;let n,s,o,l=t("scheduledTasks.everyDuration",{duration:(0,W.dp)(e.intervalMinutes??0,t)});return(e.startAt&&(l+=` \xb7 ${t("scheduledTasks.fromTime",{time:(n=new Date(r=e.startAt),s=e=>String(e).padStart(2,"0"),o=`${s(n.getHours())}:${s(n.getMinutes())}`,r>Date.now()?`${n.getMonth()+1}/${n.getDate()} ${o}`:o)})}`),e.activeFrom&&e.activeTo)?`${l} (${e.activeFrom}-${e.activeTo})`:l}return"cron"===e.type?e.cron||"cron":e.type}(e,k)}),(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsx)("span",{className:"flex-shrink-0",children:e.firingSince?k("scheduledTasks.inFlight"):z(e)?"success"===e.lastResult?k("scheduledTasks.success"):"interrupted"===e.lastResult?k("scheduledTasks.interrupted"):k("scheduledTasks.failure"):e.paused?k("scheduledTasks.paused"):function(e,t){if(!e)return"-";let r=e-Date.now();if(r<=0)return t("scheduledTasks.aboutToTrigger");if(r<6e4)return t("scheduledTasks.secondsLater",{count:Math.ceil(r/1e3)});if(r<36e5)return t("scheduledTasks.minutesLater",{count:Math.ceil(r/6e4)});if(r<864e5){let e=Math.floor(r/36e5),n=Math.ceil(r%36e5/6e4);return n>0?t("scheduledTasks.hoursMinutesLater",{h:e,m:n}):t("scheduledTasks.hoursLater",{h:e})}return new Date(e).toLocaleDateString("zh-CN",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(e.nextFireTime,k)}),!z(e)&&!e.firingSince&&e.lastFiredAt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsxs)("span",{className:"flex-shrink-0",children:[k("scheduledTasks.lastResult"),":"," ","success"===e.lastResult?"✓":"interrupted"===e.lastResult?k("scheduledTasks.interrupted"):"✗"]})]})]})]},e.id)})})]},e.cwd)})})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:ee?(0,n.jsx)(O,{task:ee,onOpenSession:()=>eo(ee)},ee.id):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:k("scheduledTasks.selectTaskHint")})})]})})]})]}),$&&null!==I&&(0,n.jsx)(H.x,{filePath:$,content:I,cwd:$.slice(0,Math.max(0,$.lastIndexOf("/"))),onClose:er,zClassName:"z-[80]"}),C&&(0,n.jsx)("div",{ref:L,className:"fixed z-[100]",style:{top:E?.top??0,left:E?.left??0,visibility:E?"visible":"hidden"},children:(0,n.jsx)(A.E,{onClose:T,onCreate:()=>{},editTask:{id:C.id,message:C.message,taskFile:C.taskFile,type:C.type,delayMinutes:C.delayMinutes,intervalMinutes:C.intervalMinutes,activeFrom:C.activeFrom,activeTo:C.activeTo,startAt:C.startAt,cron:C.cron},onUpdate:(e,t)=>{v(e,t),T()}})})]})}var K=r(42804),Q=r(997),G=r(33210),J=r(39872),Y=r(2111),X=r(94720),Z=r(2349),ee=r(96901),et=r(71077);function er({terminal:e,subtitle:t,onOpenTerminal:r}){let{t:l}=(0,o.Bd)(),{projectCwd:a,commandId:i,usePty:d}=e,c=(0,s.useRef)(null),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(void 0),f=(0,s.useRef)(d?[]:null),p=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=!0,t=(0,et.d$)({projectCwd:a,commandId:i,onAttached:e=>{let t;e?h(e):(t=f.current,f.current=null,t?.length&&c.current?.write(t.join("")))},onOutput:t=>{if(d)return void(f.current?f.current.push(t):c.current?.write(t));let r=t.replace(/\r?\n/g,"\r\n");e&&r&&!r.endsWith("\n")&&(r+="\r\n"),e=!1,c.current?.write(r)},onEnd:()=>m(!0)});return p.current=t.sendInput,()=>{p.current=null,t.close()}},[a,i,d]),(0,s.useEffect)(()=>{if(!x||!f.current)return;let e=f.current;f.current=null,e.length&&c.current?.write(e.join(""))},[x]);let g=(0,s.useCallback)(e=>p.current?.(e),[]);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2.5 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-xs font-medium text-foreground font-mono truncate","data-tooltip":e.command,children:e.title||e.command.split("\n")[0]}),(0,n.jsx)("div",{className:"text-[11px] text-muted-foreground font-mono truncate","data-tooltip":e.cwd,children:t})]}),u?(0,n.jsx)("span",{className:"flex-shrink-0 text-xs text-muted-foreground",children:l("runningTerminals.ended")}):d?(0,n.jsx)("span",{className:"flex-shrink-0 text-[11px] text-foreground-subtle",children:l("runningTerminals.typeHint")}):null]}),(0,n.jsxs)("div",{className:"relative flex-1 min-h-0",children:[(0,n.jsx)("div",{className:"h-full pt-2 pb-16",children:(0,n.jsx)(ee.XtermRenderer,{ref:c,output:"",isRunning:!1,directWrite:!0,fixedSize:d?x:void 0,onInput:d&&!u?g:void 0})}),(0,n.jsx)("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-center pb-4",children:(0,n.jsxs)("button",{onClick:r,className:"pointer-events-auto flex items-center gap-1.5 px-5 py-2.5 rounded-full bg-brand text-white text-sm font-medium shadow-lv3 hover:bg-brand/90",children:[(0,n.jsx)("span",{children:l("runningTerminals.openTerminal")}),(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14 5l7 7-7 7M3 12h18"})})]})})]})]})}function en(e){return e.split(/[\\/]/).filter(Boolean).pop()||e}function es(e){var t,r;let n=(t=e.cwd,r=e.projectCwd,t&&t!==r?t.startsWith(r+"/")?t.slice(r.length+1):t:"");return[e.title?e.command.split("\n")[0]:"",n].filter(Boolean).join(" \xb7 ")}function eo({collapsed:e,currentCwd:t,projectOrder:r,onFocusTerminal:l}){let{t:a}=(0,o.Bd)(),{terminals:i,refresh:d}=function(){let[e,t]=(0,s.useState)([]),r=(0,s.useRef)(null),n=(0,s.useCallback)(()=>{h.t4.runPromiseExit((0,X.D5)()).then(e=>{"Success"===e._tag&&t(e.value)})},[]),o=(0,s.useCallback)(()=>{r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{r.current=null,n()},150)},[n]);return(0,s.useEffect)(()=>(n(),()=>{r.current&&clearTimeout(r.current)}),[n]),(0,Y.h)({url:"/ws/global-state",onMessage:e=>{("running-terminals-changed"===e.type||"console-delta"===e.type&&"rename"===e.op)&&o()}}),{terminals:e,refresh:n}}(),[c,u]=(0,s.useState)(!1),[m,f]=(0,s.useState)(()=>Date.now()),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(null),[j,k]=(0,s.useState)(()=>new Set),y=(0,s.useRef)(new Map),N=(0,s.useMemo)(()=>{let e=new Map;for(let t of i){let r=e.get(t.projectCwd);r?r.push(t):e.set(t.projectCwd,[t])}let n=e=>{if(e===t)return -1;let n=r.indexOf(e);return n>=0?n:Number.MAX_SAFE_INTEGER};return[...e.entries()].sort(([e],[t])=>n(e)-n(t)||e.localeCompare(t)).map(([e,t])=>({cwd:e,number:r.indexOf(e)+1,items:[...t].sort((e,t)=>e.timestamp.localeCompare(t.timestamp))}))},[i,t,r]),C=(0,s.useMemo)(()=>N.flatMap(e=>e.items),[N]),S=(0,s.useCallback)(()=>{u(!1),v(null),g(null)},[]),M=p?C.find(e=>e.commandId===p)??null:null;(0,s.useEffect)(()=>{c&&!M&&g(C[0]?.commandId??null)},[c,M,C]);let L=(0,s.useCallback)(()=>{d(),f(Date.now()),u(!0)},[d]);(0,s.useEffect)(()=>{if(!c)return;let e=setInterval(()=>f(Date.now()),1e3);return()=>clearInterval(e)},[c]),(0,s.useEffect)(()=>{let e=new Set(i.map(e=>e.commandId));for(let[t,r]of(k(t=>{let r=new Set([...t].filter(t=>e.has(t)));return r.size===t.size?t:r}),y.current))e.has(t)||(clearTimeout(r),y.current.delete(t))},[i]),(0,s.useEffect)(()=>{let e=y.current;return()=>{for(let t of e.values())clearTimeout(t)}},[]);let E=(0,s.useCallback)(e=>{S(),l(e.projectCwd,e.commandId)},[S,l]),P=(0,s.useCallback)(e=>{v(null),k(t=>new Set(t).add(e.commandId));let t=()=>{y.current.delete(e.commandId),k(t=>{let r=new Set(t);return r.delete(e.commandId),r}),(0,w.oR)(a("runningTerminals.stopFailed"),"error")};h.t4.runPromiseExit((0,X.px)(e.commandId)).then(r=>{"Success"!==r._tag?t():r.value.interrupted?y.current.set(e.commandId,setTimeout(t,3e3)):d()})},[d,a]);(0,s.useEffect)(()=>{if(!c)return;let e=e=>{let t=!!e.target?.closest?.(".xterm");if("Escape"===e.key&&!t){e.preventDefault(),b?v(null):S();return}if(t||0===C.length)return;let r=C.findIndex(e=>e.commandId===p);if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault();let t="ArrowDown"===e.key?1:-1,n=r<0?t>0?0:C.length-1:(r+t+C.length)%C.length;g(C[n].commandId),v(null);return}let n=r>=0?C[r]:null;n&&("Enter"===e.key?(e.preventDefault(),b===n.commandId?P(n):E(n)):("Delete"===e.key||"Backspace"===e.key)&&(e.preventDefault(),j.has(n.commandId)||v(n.commandId)))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[c,C,p,b,j,S,E,P]);let T=e=>{let t,r,s,o,l=j.has(e.commandId),i=b===e.commandId,d=es(e),c=e.title||e.command.split("\n")[0];return(0,n.jsxs)("div",{"data-running-terminal":e.commandId,onClick:()=>g(e.commandId),onDoubleClick:()=>{l||E(e)},className:`group rounded-md px-3 py-2 transition-colors cursor-pointer ${l?"opacity-50":""} ${p===e.commandId?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"flex-shrink-0 text-muted-foreground",title:a(e.usePty?"runningTerminals.modePty":"runningTerminals.modePipe"),"aria-label":a(e.usePty?"runningTerminals.modePty":"runningTerminals.modePipe"),children:e.usePty?(0,n.jsx)(K.A,{className:"w-3.5 h-3.5"}):(0,n.jsx)(Q.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)(Z.j,{shortId:e.shortId,type:"terminal",onRegister:()=>{h.t4.runFork((0,X.Ok)({tabId:e.tabId,commandId:e.commandId,command:e.command,projectCwd:e.projectCwd}).pipe(R.NWQ(()=>R.rIH)))},onUnregister:()=>{h.t4.runFork((0,X.jO)({commandId:e.commandId}).pipe(R.NWQ(()=>R.rIH)))}}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-sm font-mono text-foreground","data-tooltip":`${e.command}
37
- pid ${e.pid}`,children:c}),(0,n.jsx)("span",{className:"flex-shrink-0 text-xs tabular-nums text-muted-foreground",children:(r=Math.floor((t=Math.max(0,Math.floor((m-new Date(e.timestamp).getTime())/1e3)))/86400),s=Math.floor(t%86400/3600),o=Math.floor(t%3600/60),r>0?`${r}d ${s}h`:s>0?`${s}h ${o}m`:o>0?`${o}m`:`${t}s`)}),l?(0,n.jsx)("span",{className:"flex-shrink-0 text-xs text-muted-foreground",children:a("runningTerminals.stopping")}):i?null:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e.commandId)},onDoubleClick:e=>e.stopPropagation(),className:"flex-shrink-0 p-0.5 rounded text-muted-foreground hover:text-destructive hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:a("runningTerminals.stop"),"aria-label":a("runningTerminals.stop"),children:(0,n.jsx)(G.A,{className:"w-3.5 h-3.5"})})]}),d&&!i&&(0,n.jsx)("div",{className:"mt-0.5 pl-[22px] text-xs text-muted-foreground truncate font-mono","data-tooltip":[e.title?e.command:"",e.cwd].filter(Boolean).join("\n"),children:d}),i&&(0,n.jsxs)("div",{className:"mt-1.5 flex items-center justify-end gap-2",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:a("runningTerminals.confirmStop")}),(0,n.jsx)("button",{onClick:()=>v(null),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:a("common.cancel")}),(0,n.jsx)("button",{onClick:()=>P(e),className:"px-2 py-0.5 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:a("runningTerminals.stop")})]})]},e.commandId)},$=i.length;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:L,className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${e?"w-full justify-center":"w-full"}`,title:e?a("runningTerminals.title"):void 0,"data-testid":"running-terminals-entry",children:[(0,n.jsx)(K.A,{className:"w-5 h-5 flex-shrink-0"}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:a("runningTerminals.title")}),$>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-popover border border-border ${e?"absolute -top-1 -right-1":""}`,children:$})]}),c&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:S}),(0,n.jsxs)("div",{className:x.aO,"data-testid":"running-terminals-board",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("div",{className:"flex items-center gap-3 min-w-0",children:(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:a("runningTerminals.title")})}),(0,n.jsx)("button",{onClick:S,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),0===$?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:a("runningTerminals.empty")}):(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsx)("div",{className:"w-full md:w-[360px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:(0,n.jsx)("div",{className:"p-3 space-y-3",children:N.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center gap-1.5",children:[e.number>0&&(0,n.jsx)(J.B,{number:e.number,isActive:e.cwd===t}),(0,n.jsx)("span",{className:"truncate","data-tooltip":e.cwd,children:en(e.cwd)}),e.cwd===t&&(0,n.jsxs)("span",{className:"text-foreground-subtle",children:["\xb7 ",a("runningTerminals.currentProject")]})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(T)})]},e.cwd))})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:M?(0,n.jsx)(er,{terminal:M,subtitle:[en(M.projectCwd),es(M)].filter(Boolean).join(" \xb7 "),onOpenTerminal:()=>E(M)},M.commandId):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:a("runningTerminals.selectHint")})})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 px-4 py-1.5 border-t border-border text-xs text-muted-foreground","data-testid":"running-terminals-status",children:[(0,n.jsx)("span",{className:"tabular-nums",children:a("runningTerminals.status",{count:$,projects:N.length})}),$>0&&(0,n.jsx)("span",{className:"truncate text-foreground-subtle",children:a("runningTerminals.keys")})]})]})]})]})}var el=r(69895),ea=r(76900),ei=r(72363),ed=r(94852),ec=r(60285);let eu=e=>"unread"===e?0:"loading"===e?1:2;function em({className:e=""}){return(0,n.jsxs)("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"6",height:"6",rx:"1.5"}),(0,n.jsx)("rect",{x:"4",y:"14",width:"6",height:"6",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"6",height:"6",rx:"1.5"}),(0,n.jsx)("path",{d:"M17 3v8"}),(0,n.jsx)("path",{d:"M13 7h8"})]})}function ex({collapsed:e,previews:t,activePath:r,onOpenApps:l,onShowPreview:a}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(!1),u=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{u.current?.contains(e.target)||c(!1)};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[d]);let m=t.length>3,x=t.slice(0,3),h=t.slice(3),f=e=>{a(e),c(!1)},p=e=>(0,n.jsxs)("button",{type:"button",onClick:()=>f(e),className:`w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left hover:bg-hover transition-colors ${r===e.path?"text-brand":"text-muted-foreground hover:text-foreground"}`,title:e.path,children:[(0,n.jsx)("span",{className:"h-6 w-6 flex-shrink-0 rounded-md border border-border/70 flex items-center justify-center",children:e.icon?(0,n.jsx)("span",{className:"text-sm leading-none",children:e.icon}):(0,n.jsx)(ed.A,{className:"w-3.5 h-3.5"})}),(0,n.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"block text-xs font-medium truncate",children:e.title}),(0,n.jsx)("span",{className:"block text-[10px] font-mono text-muted-foreground truncate",children:e.path})]})]},e.path),g=(e,t)=>(0,n.jsx)("div",{className:"absolute left-full bottom-0 ml-2 w-64 rounded-lg border border-border bg-card shadow-lv3 z-50",children:(0,n.jsxs)("div",{className:"max-h-[19.75rem] overflow-y-auto p-1.5 space-y-1",children:[t&&(0,n.jsxs)("button",{type:"button",onClick:()=>{l(),c(!1)},className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:[(0,n.jsx)("span",{className:"h-6 w-6 flex-shrink-0 rounded-md border border-border/70 flex items-center justify-center",children:(0,n.jsx)(em,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"text-xs font-medium truncate",children:i("workspace.apps")})]}),e.map(p)]})});return e?(0,n.jsxs)("div",{ref:u,className:"relative",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>t.length?c(e=>!e):l(),className:`relative w-full flex items-center justify-center px-2 py-2 rounded-lg hover:bg-hover transition-colors ${r?"text-brand":"text-muted-foreground hover:text-foreground"}`,title:i("workspace.apps"),children:[(0,n.jsx)(em,{className:"w-5 h-5 flex-shrink-0"}),t.length>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-popover border border-border",children:t.length})]}),d&&g(t,!0)]}):(0,n.jsxs)("div",{ref:u,className:"relative flex items-center gap-1 rounded-lg hover:bg-hover transition-colors",children:[(0,n.jsxs)("button",{type:"button",onClick:l,className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-2 text-muted-foreground hover:text-foreground",children:[(0,n.jsx)(em,{className:"w-5 h-5 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm",children:i("workspace.apps")})]}),t.length>0&&(0,n.jsxs)("div",{className:"flex items-center gap-1 pr-1.5 flex-shrink-0",children:[x.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>f(e),className:`h-6 w-6 rounded-md border flex items-center justify-center transition-colors ${r===e.path?"border-brand/80 text-brand":"border-border/70 text-muted-foreground hover:border-brand/70 hover:text-brand"}`,"data-tooltip":e.title,"aria-label":e.title,children:e.icon?(0,n.jsx)("span",{className:"text-sm leading-none",children:e.icon}):(0,n.jsx)(ed.A,{className:"w-3.5 h-3.5"})},e.path)),m&&(0,n.jsx)("button",{type:"button",onClick:()=>c(e=>!e),className:"h-6 w-6 rounded-md border border-border/70 text-muted-foreground hover:border-brand/70 hover:text-brand flex items-center justify-center transition-colors","data-tooltip":i("common.loadMore"),"aria-label":i("common.loadMore"),children:(0,n.jsx)(ec.A,{className:"w-3.5 h-3.5"})})]}),d&&g(h,!1)]})}function eh({projects:e,activeIndex:t,collapsed:r,currentCwd:d,onSelectProject:c,onRemoveProject:u,onReorderProjects:m,onToggleCollapse:x,onOpenSessionBrowser:f,onOpenSettings:p,onOpenNote:g,onOpenSkills:b,onOpenBots:v,onOpenApps:j,htmlAppPreviews:k,activeHtmlAppPreviewPath:y,onShowHtmlAppPreview:N,onSwitchProject:C,onFocusTerminal:S,onResolveSessionNumbers:M,sessionOrders:L,draftCwds:E,sessionNumbers:P}){let $,R,{t:I,i18n:B}=(0,o.Bd)(),A=(0,s.useMemo)(()=>e.map(e=>e.cwd),[e]),{latest:H,hasUpdate:O}=function(){let[e,t]=(0,s.useState)(),[r,n]=(0,s.useState)();(0,s.useEffect)(()=>{let e=!1;h.t4.runPromiseExit((0,ea.Wr)()).then(r=>{!e&&"Success"===r._tag&&r.value.version&&t(r.value.version)});let r=new AbortController,s=setTimeout(()=>r.abort(),3e3);return fetch("https://registry.npmjs.org/@surething/cockpit/latest",{signal:r.signal}).then(e=>e.ok?e.json():null).then(t=>{if(e)return;let r=t?.version;"string"==typeof r&&n(r)}).catch(()=>{}).finally(()=>clearTimeout(s)),()=>{e=!0,r.abort(),clearTimeout(s)}},[]);let[o,l]=(0,s.useState)(!1);(0,s.useEffect)(()=>{l(!0===window.__COCKPIT_FORCE_UPDATE__)},[]);let a=!!e&&!!r&&function(e,t){let r=e=>e.replace(/^v/,"").split("-")[0].split(".").map(e=>parseInt(e,10)||0),n=r(e),s=r(t),o=Math.max(n.length,s.length);for(let e=0;e<o;e++){let t=n[e]??0,r=s[e]??0;if(t!==r)return t-r}return 0}(r,e)>0;return{current:e,latest:o?r??"999.0.0":r,hasUpdate:!!o||a}}(),[W,_]=(0,s.useState)(!1),z=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!W)return;let e=e=>{z.current?.contains(e.target)||_(!1)},t=()=>_(!1);return document.addEventListener("mousedown",e,!0),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e,!0),window.removeEventListener("blur",t)}},[W]);let q=(0,s.useCallback)(()=>{navigator.clipboard.writeText("cockpit update"),(0,w.oR)(I("workspace.upgradeCommandCopied")),_(!1)},[I]),{isUpdating:V,start:K}=($=(0,s.useSyncExternalStore)(ei.N4,ei.fX,ei.fX),R=(0,s.useCallback)(()=>{(0,ei._I)()},[]),{isUpdating:$.visible&&"done"!==$.stage&&"failed"!==$.stage,start:R}),Q=(0,s.useCallback)(()=>{_(!1),K()},[K]),{pinnedSessions:G,unpinSession:J,reorder:X}=(0,el.P)(),{tasks:Z,unreadCount:ee,reload:et,pauseTask:er,resumeTask:en,triggerTask:es,deleteTask:ed,updateTask:ec}=(0,D.nS)(),[em,ef]=(0,s.useState)(null),[ep,eg]=(0,s.useState)(null),[eb,ev]=(0,s.useState)([]),ej=(0,s.useRef)(eb);(0,s.useEffect)(()=>{ej.current=eb});let ew=(0,s.useRef)(et);(0,s.useEffect)(()=>{ew.current=et});let ek=(0,s.useCallback)(e=>{try{var t;t=ew.current,!e||"object"!=typeof e||("task-fired"===e.type?t():"global-state"===e.type&&Array.isArray(e.data?.sessions)&&ev(e.data.sessions))}catch{}},[]);(0,Y.h)({url:"/ws/global-state",onMessage:ek});let ey=new Set(eb.filter(e=>"loading"===e.status).map(e=>e.cwd)),eN=new Set(eb.filter(e=>"unread"===e.status).map(e=>e.cwd)),eC=(0,s.useMemo)(()=>{let t=new Map;for(let r of e){let e=L[r.cwd]??[],n=eb.filter(e=>e.cwd===r.cwd).map(t=>({session:t,position:e.indexOf(t.sessionId)})).filter(({session:e,position:t})=>t>=0||"loading"===e.status||"unread"===e.status).sort((e,t)=>{let r=eu(e.session.status)-eu(t.session.status);return 0!==r?r:t.session.lastActive-e.session.lastActive}),s=n.find(({session:e})=>2===eu(e.status)),o=n.filter(({session:e})=>2>eu(e.status)||e===s?.session).slice(0,3).sort((e,t)=>e.position<0?t.position<0?0:1:t.position<0?-1:e.position-t.position).map(({session:e,position:t})=>({sessionId:e.sessionId,label:t>=0?String(t+1):"\xb7",status:"loading"===e.status?"loading":"unread"===e.status?"unread":"normal",...e.bot?{bot:e.bot}:{}}));o.length>0&&t.set(r.cwd,o)}return t},[e,eb,L]),eS=(0,s.useCallback)(e=>{ef(e)},[]),eM=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==em&&em!==t&&eg(t)},[em]),eL=(0,s.useCallback)(t=>{if(null!==em&&em!==t){let r=[...e],[n]=r.splice(em,1);r.splice(t,0,n),m(r)}ef(null),eg(null)},[em,e,m]),eE=(0,s.useCallback)(()=>{ef(null),eg(null)},[]);return(0,n.jsxs)("div",{className:`h-full bg-card border-r border-border flex flex-col transition-all duration-200 ${r?"w-12":"w-56"}`,children:[(0,n.jsxs)("div",{className:"group p-2 border-b border-border relative",children:[(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${r?"justify-center":""}`,onClick:f,title:r?I("workspace.openProject"):void 0,children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M12 10v6m3-3H9m-4 7h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:I("workspace.openProject")})]}),r?(0,n.jsx)("button",{className:"absolute inset-0 m-2 flex items-center justify-center px-2 py-2 rounded-lg bg-popover shadow-lv1 text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:x,title:I("workspace.expandSidebar"),children:(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0 rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}):(0,n.jsx)("button",{className:"absolute top-1/2 -translate-y-1/2 right-2 p-2 rounded-lg bg-popover shadow-lv1 text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:x,title:I("workspace.collapseSidebar"),children:(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:e.map((e,s)=>{var o;let l;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>eS(s),onDragOver:e=>eM(e,s),onDrop:()=>eL(s),onDragEnd:eE,className:`${ep===s?"border-t-2 border-brand":""} ${em===s?"opacity-50":""}`,children:(0,n.jsx)(i.ProjectItem,{index:s,name:(l=(o=e.cwd).split("/").filter(Boolean))[l.length-1]||o,cwd:e.cwd,isActive:s===t,collapsed:r,hasUnread:eN.has(e.cwd),isLoading:ey.has(e.cwd),hasDraft:E.has(e.cwd),sessionBadges:eC.get(e.cwd),onClick:()=>c(s),onSelectSession:t=>C(e.cwd,t),onRemove:()=>u(s),onOpenNote:()=>g(e.cwd)})},e.cwd)})}),(0,n.jsxs)("div",{className:"p-2 border-t border-border space-y-1",children:[(0,n.jsx)(T,{projectOrder:A,currentCwd:d,onSwitchProject:C,onResolveSessionNumbers:M,collapsed:r,sessions:eb}),(0,n.jsx)(F,{collapsed:r,projectOrder:A,currentCwd:d,pinnedSessions:G,sessionNumbers:P,onSwitchProject:C,onUnpin:J,onReorder:X}),(0,n.jsx)(U,{collapsed:r,projectOrder:A,currentCwd:d,tasks:Z,unreadCount:ee,sessionNumbers:P,onSwitchProject:C,onPause:er,onResume:en,onTrigger:es,onDelete:ed,onUpdateTask:ec}),(0,n.jsx)(eo,{collapsed:r,currentCwd:d,projectOrder:A,onFocusTerminal:S}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${r?"justify-center":""}`,onClick:()=>g(),title:r?I("workspace.notes"):void 0,children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:I("workspace.notes")})]}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${r?"justify-center":""}`,onClick:b,title:r?I("workspace.skills"):void 0,children:[(0,n.jsx)(l.A,{className:"w-5 h-5 flex-shrink-0"}),!r&&(0,n.jsx)("span",{className:"text-sm",children:I("workspace.skills")})]}),(0,n.jsx)(ex,{collapsed:r,previews:k,activePath:y,onOpenApps:j,onShowPreview:N}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${r?"justify-center":""}`,onClick:v,title:r?I("workspace.bots"):void 0,children:[(0,n.jsx)(a.A,{className:"w-5 h-5 flex-shrink-0"}),!r&&(0,n.jsx)("span",{className:"text-sm",children:I("workspace.bots")})]}),(0,n.jsxs)("div",{className:`relative flex items-center gap-2 px-2 py-2 rounded-lg cursor-pointer text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${r?"justify-center":""}`,onClick:p,title:I("workspace.settings"),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),r&&O&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500",title:H?I("workspace.updateAvailable",{version:H}):void 0})]}),!r&&(0,n.jsx)("span",{className:"flex-1 text-sm",children:I("workspace.settings")}),!r&&O&&H&&(0,n.jsxs)("div",{ref:z,className:"relative -mr-2",children:[(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),_(e=>!e)},className:"px-1.5 py-0.5 rounded text-xs font-mono font-medium text-brand hover:bg-brand/10 transition-colors",title:I("workspace.updateAvailable",{version:H}),"aria-label":I("workspace.updateAvailable",{version:H}),children:["v",H]}),W&&(0,n.jsxs)("div",{className:"absolute left-full bottom-full ml-2 mb-1 w-56 rounded-lg border border-border bg-popover shadow-lv2 p-2 z-50",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2 px-1",children:I("workspace.updateAvailable",{version:H})}),(0,n.jsxs)("button",{type:"button",onClick:Q,disabled:V,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm text-left\n hover:bg-hover transition-colors disabled:opacity-60 disabled:cursor-default",children:[V?(0,n.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:4}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.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,n.jsx)("span",{className:"flex-1",children:V?I("workspace.updating"):I("workspace.updateNow")})]}),(0,n.jsxs)("button",{type:"button",onClick:q,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm text-left hover:bg-hover transition-colors",children:[(0,n.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2})]}),(0,n.jsx)("span",{className:"flex-1",children:I("workspace.copyUpgradeCommand")})]}),(0,n.jsxs)("a",{href:`https://opencockpit.dev/${B.language?.startsWith("zh")?"zh":"en"}/changelog/`,target:"_blank",rel:"noopener",onClick:()=>_(!1),className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm hover:bg-hover transition-colors",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("span",{className:"flex-1",children:I("workspace.viewChangelog")}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]}),!r&&(0,n.jsx)("a",{href:`https://opencockpit.dev/${B.language?.startsWith("zh")?"zh":"en"}/docs/get-started/quickstart/`,target:"_blank",rel:"noopener",className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",onClick:e=>e.stopPropagation(),title:I("workspace.help"),"aria-label":I("workspace.help"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2})]})})]})]})]})}},15317:(e,t,r)=>{r.d(t,{LV:()=>o,dp:()=>l,wJ:()=>s});let n={minute:1,hour:60,day:1440};function s(e){return e>0&&e%n.day==0?{value:e/n.day,unit:"day"}:e>0&&e%n.hour==0?{value:e/n.hour,unit:"hour"}:{value:e,unit:"minute"}}function o(e,t){let r=parseFloat(e);return!Number.isFinite(r)||r<=0?0:Math.round(r*n[t])}function l(e,t){let{value:r,unit:n}=s(e);return t(`scheduledTasks.duration.${n}`,{count:r})}},16147:(e,t,r)=>{r.d(t,{w:()=>o});var n=r(95155);let s="font-mono text-[9px] font-medium leading-none tabular-nums transition-colors";function o({children:e,wash:t,ring:r="",bot:l,className:a="",tooltip:i,title:d,role:c,ariaLabel:u,ariaHidden:m}){let x={title:d,role:c,"aria-label":u,"aria-hidden":m?"true":void 0,"data-tooltip":i??(l?`@${l}`:void 0)};return l?(0,n.jsx)("span",{className:`relative -m-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center ${r} ${a}`,...x,children:(0,n.jsx)("span",{className:`session-number-bot flex h-full w-full items-center justify-center ${s} ${t}`,children:(0,n.jsx)("span",{className:"translate-y-[1.5px]",children:e})})}):(0,n.jsx)("span",{className:`flex h-4 w-4 flex-shrink-0 items-center justify-center rounded-full border ${s} ${r} ${t} ${a}`,...x,children:e})}},16220:(e,t,r)=>{r.d(t,{TabManagerTopBar:()=>j});var n=r(95155),s=r(12115),o=r(63728),l=r(34075),a=r(79114),i=r(95045),d=r(75346),c=r(49433),u=r(86957),m=r(53213),x=r(45720),h=r(76900),f=r(74281);function p({cwd:e,sessionId:t}){let{t:r}=(0,a.Bd)(),[o,l]=(0,s.useState)(!1),[i,d]=(0,s.useState)(!1),[m,x]=(0,s.useState)({status:"loading"}),g=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e;l(!("localhost"===(e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase())||e.endsWith(".localhost")||"::1"===e||"0.0.0.0"===e||/^127(?:\.\d{1,3}){3}$/.test(e)))},[]),(0,s.useEffect)(()=>{if(!i)return;let r=!1;x({status:"loading"});let n=c.JkU(function*(){var r,n;let s,o,l=yield*(0,h.O2)(),a=(r=window.location.origin,n={cwd:e,sessionId:t,token:l},s=new URLSearchParams,n.cwd&&n.sessionId&&(s.set("cwd",n.cwd),s.set("sessionId",n.sessionId)),n.token&&s.set("token",n.token),o=s.toString(),`${r}/m${o?`?${o}`:""}`);return{svg:yield*(0,h.GS)(a),hasToken:null!==l}});return u.t4.runPromiseExit(n).then(e=>{r||x("Success"===e._tag?{status:"ready",...e.value}:{status:"error"})}),()=>{r=!0}},[i,e,t]),(0,s.useEffect)(()=>{if(!i)return;let e=e=>{g.current&&!g.current.contains(e.target)&&d(!1)},t=e=>{"Escape"===e.key&&d(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[i]);let b=(0,s.useCallback)(()=>d(e=>!e),[]);return o?(0,n.jsxs)("div",{className:"relative",ref:g,children:[(0,n.jsx)("button",{onClick:b,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:r("tabManagerTopBar.openOnPhone"),children:(0,n.jsx)(f.A,{className:"w-5 h-5"})}),i&&(0,n.jsxs)("div",{className:"absolute top-full right-0 mt-1 w-60 p-3 bg-popover border border-border rounded-lg shadow-lv2 z-50",children:[(0,n.jsx)("div",{className:"w-full aspect-square rounded-md bg-white p-2 flex items-center justify-center",children:"ready"===m.status?(0,n.jsx)("div",{className:"w-full h-full [&>svg]:w-full [&>svg]:h-full",dangerouslySetInnerHTML:{__html:m.svg}}):(0,n.jsx)("span",{className:"text-xs text-neutral-500",children:r("error"===m.status?"tabManagerTopBar.phoneQrFailed":"common.loading")})}),(0,n.jsx)("p",{className:"mt-2 text-xs text-foreground text-center",children:r(e&&t?"tabManagerTopBar.phoneQrSessionHint":"tabManagerTopBar.phoneQrHint")}),"ready"===m.status&&m.hasToken&&(0,n.jsx)("p",{className:"mt-1 text-xs text-muted-foreground text-center",children:r("tabManagerTopBar.phoneQrTokenWarning")})]})]}):null}function g({className:e}){return(0,n.jsxs)("svg",{className:e,fill:"none",viewBox:"0 0 100 100","aria-hidden":"true",children:[(0,n.jsx)("path",{fill:"#0065A9",d:"M96.461 10.796 75.857.876a6.23 6.23 0 0 0-7.107 1.207l-67.451 61.5a4.167 4.167 0 0 0 .004 6.162l5.51 5.009a4.167 4.167 0 0 0 5.32.236l81.228-61.62c2.725-2.067 6.639-.124 6.639 3.297v-.24a6.25 6.25 0 0 0-3.539-5.63Z"}),(0,n.jsx)("path",{fill:"#007ACC",d:"m96.461 89.204-20.604 9.92a6.229 6.229 0 0 1-7.107-1.207l-67.451-61.5a4.167 4.167 0 0 1 .004-6.162l5.51-5.009a4.167 4.167 0 0 1 5.32-.236l81.228 61.62c2.725 2.067 6.639.124 6.639-3.297v.24a6.25 6.25 0 0 0-3.539 5.63Z"}),(0,n.jsx)("path",{fill:"#1F9CF0",d:"M75.858 99.126a6.232 6.232 0 0 1-7.108-1.21c2.306 2.307 6.25.674 6.25-2.588V4.672c0-3.262-3.944-4.895-6.25-2.589a6.232 6.232 0 0 1 7.108-1.21l20.6 9.908A6.25 6.25 0 0 1 100 16.413v67.174a6.25 6.25 0 0 1-3.541 5.633l-20.601 9.906Z"})]})}function b({className:e}){return(0,n.jsx)("svg",{className:e,viewBox:"0 0 466.73 532.09",fill:"currentColor","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M457.43,125.94L244.42,2.96c-6.84-3.95-15.28-3.95-22.12,0L9.3,125.94c-5.75,3.32-9.3,9.46-9.3,16.11v247.99c0,6.65,3.55,12.79,9.3,16.11l213.01,122.98c6.84,3.95,15.28,3.95,22.12,0l213.01-122.98c5.75-3.32,9.3-9.46,9.3-16.11v-247.99c0-6.65-3.55-12.79-9.3-16.11h-.01ZM444.05,151.99l-205.63,356.16c-1.39,2.4-5.06,1.42-5.06-1.36v-233.21c0-4.66-2.49-8.97-6.53-11.31L24.87,145.67c-2.4-1.39-1.42-5.06,1.36-5.06h411.26c5.84,0,9.49,6.33,6.57,11.39h-.01Z"})})}function v({cwd:e,currentBranch:t,onSwitched:r}){let{t:o}=(0,a.Bd)(),[i,d]=(0,s.useState)(!1),[c,x]=(0,s.useState)([]),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[j,w]=(0,s.useState)(""),k=(0,s.useRef)(null),y=(0,s.useRef)(null),N=(0,s.useCallback)(async()=>{p(!0);let t=await u.t4.runPromiseExit((0,m.r4)(e));if("Success"===t._tag){let e=t.value,r=e.local??[];x([...r,...(e.remote??[]).filter(e=>!r.includes(e.replace(/^origin\//,"")))])}else(0,l.oR)(o("toast.loadBranchFailed"),"error");p(!1)},[e,o]),C=(0,s.useCallback)(()=>{d(!0),w(""),N()},[N]),S=(0,s.useCallback)(()=>{d(!1)},[]);(0,s.useEffect)(()=>{if(!i)return;let e=e=>{k.current&&!k.current.contains(e.target)&&S()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[i,S]),(0,s.useEffect)(()=>{i&&setTimeout(()=>y.current?.focus(),50)},[i]);let M=async t=>{b(!0);let n=await u.t4.runPromiseExit((0,h.Kl)({action:"checkout",cwd:e,path:e,branch:t}));if("Success"===n._tag){let e=t.replace(/^origin\//,"");(0,l.oR)(o("toast.switchedToBranch",{branch:e}),"success"),S(),r()}else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:o("toast.switchBranchFailed");(0,l.oR)(r,"error")}b(!1)},L=c.filter(e=>e!==t&&e.toLowerCase().includes(j.toLowerCase()));return(0,n.jsxs)("div",{className:"relative",ref:k,children:[(0,n.jsx)("button",{onClick:i?S:C,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:o("git.switchBranch"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"})})}),i&&(0,n.jsxs)("div",{className:"absolute top-full left-0 mt-1 w-64 bg-popover border border-border rounded-lg shadow-lv2 z-50 overflow-hidden",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:y,type:"text",value:j,onChange:e=>w(e.target.value),placeholder:o("git.searchBranch"),className:"w-full px-2.5 py-1.5 text-sm bg-muted rounded border-none outline-none",onKeyDown:e=>{"Escape"===e.key&&S()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:f?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:o("common.loading")}):0===L.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:j?o("git.noMatchingBranches"):o("git.noBranches")}):L.map(e=>(0,n.jsx)("button",{onClick:()=>M(e),disabled:g,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-hover transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function j({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:m,onOpenAliasManager:f,onBranchSwitched:w}){let{t:k}=(0,a.Bd)(),y=t?.sessionId?(0,x.X)(t.engine,t.sessionId):null;return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6 cursor-pointer",title:k("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,l.oR)(k("toast.copiedPageUrl"),"success")})}}),e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help","data-tooltip":`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,l.oR)(k("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:k("tabManagerTopBar.copyDirPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}):(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"})]}),r&&e&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsxs)("button",{onClick:m,className:"flex items-center gap-1.5 px-2 py-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:"Git Worktrees",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 17h8m0 0l-4-4m4 4l-4 4M3 7v6a4 4 0 004 4h5"})}),(0,n.jsx)("span",{className:"text-sm",children:s||"main"})]}),(0,n.jsx)(v,{cwd:e,currentBranch:s,onSwitched:()=>w?.()})]})]}),(0,n.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2",children:(0,n.jsx)(o.gT,{})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(p,{cwd:t?.cwd??e,sessionId:t?.sessionId}),(0,n.jsx)("button",{onClick:()=>window.location.reload(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.refreshProject"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 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,n.jsx)("button",{onClick:()=>{t?.cwd&&u.t4.runFork((0,h.em)(t.cwd).pipe(c.NWQ(()=>c.rIH)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)(g,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&u.t4.runFork((0,h.Q1)(t.cwd).pipe(c.NWQ(()=>c.rIH)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.openInCursor"),children:(0,n.jsx)(b,{className:"w-4 h-4"})}),y&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(y).then(()=>{(0,l.oR)(k("toast.copiedCommand",{command:y}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("chat.copyCommandTooltip",{command:y}),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:f,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.aliasesGlobal"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 12h-6m-4 0a8 8 0 1116 0 8 8 0 01-16 0zm4 0h.01"})})}),(0,n.jsx)("button",{onClick:()=>(0,i.F)(d.n.OpenTokenStats,{}),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.tokenStats"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})})}),(0,n.jsx)("button",{onClick:()=>window.open("https://surething.io?from=cockpit","_blank"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.openSurething"),children:(0,n.jsx)("img",{src:"https://surething.io/logo.png?from=cockpit",alt:"Surething",className:"w-5 h-5 rounded-sm"})})]})]})})}},20832:(e,t,r)=>{r.d(t,{p:()=>c});var n=r(95155),s=r(12115),o=r(79114),l=r(86957),a=r(33199),i=r(97938),d=r(32456);function c({cwd:e,sessionId:t,subtitle:r,emptyText:u,onOpenSession:m}){let{t:x}=(0,o.Bd)(),[h,f]=(0,s.useState)(null),p=(0,s.useRef)(void 0);(0,s.useEffect)(()=>{let r=!1,n=async()=>{let n=await l.t4.runPromiseExit((0,i.z)({cwd:e,sessionId:t,limit:10,ifFingerprint:p.current}));if(r)return;if("Success"!==n._tag||!n.value)return void f(e=>e??[]);let s=n.value;s.fingerprint&&(p.current=s.fingerprint),!s.notModified&&s.messages&&f(s.messages)};n();let s=setInterval(n,5e3);return()=>{r=!0,clearInterval(s)}},[e,t]);let g=(0,s.useRef)(null),b=(0,s.useRef)(null),v=(0,s.useRef)(!0),[j,w]=(0,s.useState)(!0),k=(0,s.useCallback)(()=>{let e=g.current;if(!e)return;let t=e.scrollTop+e.clientHeight>=e.scrollHeight-40;v.current=t,w(t||e.scrollTop<=40)},[]);return(0,s.useLayoutEffect)(()=>{let e=g.current;e&&v.current&&(e.scrollTop=e.scrollHeight)},[h]),(0,s.useEffect)(()=>{let e=b.current;if(!e)return;let t=new ResizeObserver(k);return t.observe(e),()=>t.disconnect()},[k,h]),(0,n.jsxs)("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[(0,n.jsx)("div",{className:"flex items-center gap-2 px-4 py-2.5 border-b border-border flex-shrink-0",children:(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-xs font-medium text-foreground truncate","data-tooltip":e,children:(0,d.Qr)(e)}),(0,n.jsx)("div",{className:"text-[11px] text-muted-foreground truncate","data-tooltip":r,children:r})]})}),(0,n.jsxs)("div",{className:"relative flex-1 min-h-0 flex",children:[(0,n.jsx)("div",{ref:g,onScroll:k,className:"flex-1 overflow-y-auto px-8 py-4",children:null===h||0===h.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:null===h?x("common.loading"):u}):(0,n.jsx)("div",{ref:b,className:"mx-auto w-full max-w-[var(--chat-column)] [&_a]:pointer-events-none",children:h.map(t=>(0,n.jsx)(a.s,{message:t,cwd:e,disableOverlays:!0},t.id))})}),(0,n.jsx)("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-center pb-4",children:(0,n.jsxs)("button",{onClick:m,className:`flex items-center gap-1.5 px-5 py-2.5 rounded-full bg-brand text-white text-sm font-medium shadow-lv3 hover:bg-brand/90 transition-opacity ${j?"opacity-100 pointer-events-auto":"opacity-0"}`,title:x("scheduledTasks.openSession"),children:[(0,n.jsx)("span",{children:x("scheduledTasks.openSession")}),(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14 5l7 7-7 7M3 12h18"})})]})})]})]})}},21484:(e,t,r)=>{r.d(t,{SettingsModal:()=>h});var n=r(95155),s=r(12115),o=r(79114),l=r(3238),a=r(34075),i=r(12786),d=r(86957),c=r(49433),u=r(91281),m=r(80286),x=r(76900);function h({isOpen:e,onClose:t}){let{t:r,i18n:f}=(0,o.Bd)(),{theme:p,setTheme:g}=(0,l.DP)(),[b,v]=(0,s.useState)([]),[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)(""),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)("auto"),[L,E]=(0,s.useState)(!0);(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,x.M5)()).then(e=>{"Success"===e._tag&&(e.value.language&&M(e.value.language),E(!1!==e.value.codexPromptSuggestions))})},[e]);let P=(0,s.useCallback)(e=>{M(e),d.t4.runFork((0,x.DZ)({language:e}).pipe(c.NWQ(()=>c.rIH)));let t="auto"===e?navigator.language.startsWith("zh")?"zh":"en":e;f.changeLanguage(t)},[f]),T=(0,s.useCallback)(e=>{E(e),d.t4.runFork((0,x.DZ)({codexPromptSuggestions:e}).pipe(c.NWQ(()=>c.rIH)))},[]),$=b.length?"installed":"not-installed",R=b[0]?.version??null,I=b.map(e=>e.browser).filter(Boolean).join(", ");if((0,s.useEffect)(()=>{if(!e)return;let t=d.t4.runFork((0,x.IG)().pipe(c.Mim(e=>c.OH5(()=>v(e))),c.NWQ(()=>c.rIH),c.uxO(u.ji("3 seconds"))));return()=>{d.t4.runFork(m.G(t))}},[e]),(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,x.Wr)()).then(e=>{"Success"===e._tag&&(e.value.version&&y(e.value.version),e.value.agents&&C(e.value.agents))})},[e]),(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,x.Or)()).then(e=>{"Success"===e._tag&&e.value.path&&w(e.value.path)})},[e]),!e)return null;let F=[{value:"system",label:r("settings.themeSystem"),icon:"\uD83D\uDCBB"},{value:"light",label:r("settings.themeLight"),icon:"☀️"},{value:"dark",label:r("settings.themeDark"),icon:"\uD83C\uDF19"}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 w-full max-w-2xl mx-4 overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:r("settings.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.theme")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:F.map(e=>(0,n.jsxs)("button",{onClick:()=>g(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${p===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.language")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:[{value:"auto",label:r("settings.languageAuto"),icon:"\uD83C\uDF10"},{value:"en",label:"English",icon:"\uD83C\uDDFA\uD83C\uDDF8"},{value:"zh",label:"中文",icon:"\uD83C\uDDE8\uD83C\uDDF3"}].map(e=>(0,n.jsxs)("button",{onClick:()=>P(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${S===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.codexSection")}),(0,n.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:L,onChange:e=>T(e.target.checked),className:"mt-0.5 accent-brand"}),(0,n.jsxs)("span",{className:"space-y-0.5",children:[(0,n.jsx)("span",{className:"block text-xs font-medium text-foreground",children:r("settings.codexSuggestions")}),(0,n.jsx)("span",{className:"block text-xs text-muted-foreground leading-relaxed",children:r("settings.codexSuggestionsDescription")})]})]})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.browserExtension")}),(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full flex-shrink-0 ${"installed"===$?"bg-green-500":"bg-slate-400"}`}),(0,n.jsxs)("span",{children:["installed"===$&&`${r("settings.extensionInstalled")}${R?` (v${R})`:""}${I?` \xb7 ${I}`:""}`,"not-installed"===$&&r("settings.extensionNotInstalled")]})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r("settings.extensionDescription")}),"installed"!==$&&(0,n.jsxs)("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-md p-2 space-y-1",children:[(0,n.jsx)("p",{className:"font-medium text-foreground",children:r("settings.installSteps")}),(0,n.jsxs)("p",{children:[r("settings.step1")," ",(0,n.jsx)("code",{className:"px-1 py-0.5 bg-muted rounded text-foreground",children:"chrome://extensions"})]}),(0,n.jsx)("p",{children:r("settings.step2")}),(0,n.jsx)("p",{children:r("settings.step3")}),(0,i.L)()&&(0,n.jsx)("p",{dangerouslySetInnerHTML:{__html:r("settings.step4mac")}})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>{let e=j||"chrome-extension";navigator.clipboard.writeText(e),(0,a.oR)(r("toast.copiedName",{name:e}))},className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:r("settings.copyExtensionPath")}),"installed"===$&&(0,n.jsx)("button",{onClick:()=>{d.t4.runFork((0,x.Bt)().pipe(c.NWQ(()=>c.rIH))),(0,a.oR)(r("toast.pluginReloading"))},className:"px-3 py-1.5 text-xs border border-border text-foreground rounded-md hover:bg-muted transition-colors",children:r("settings.reloadExtension")})]}),j&&(0,n.jsx)("p",{className:"text-[11px] text-muted-foreground font-mono truncate",children:j})]})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.about")}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground space-y-1",children:[(0,n.jsxs)("p",{children:["Cockpit",k?` v${k}`:""]}),(N?.claude||N?.codex)&&(0,n.jsx)("p",{className:"text-muted-foreground/60",children:[N.claude&&`Claude Code ${N.claude}`,N.codex&&`Codex ${N.codex}`,r("settings.agentsBundled")].filter(Boolean).join(" \xb7 ")}),(0,n.jsx)("p",{className:"text-muted-foreground/60",children:"One seat. One AI. Everything under control."})]})]})]})]})]})}},23121:(e,t,r)=>{r.d(t,{Q_:()=>m,nS:()=>f});var n=r(12115),s=r(95045),o=r(75346),l=r(49433),a=r(69809),i=r(34075),d=r(86957),c=r(82680);let u=(e,t,r)=>l.$mh({try:async()=>{let n=await fetch(e,{method:t,headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:r=>new c.uV({message:`${t} ${e} failed`,cause:r})});function m(e){return e.resolvedPrompt||e.message||e.taskFile||""}let x="SCHEDULED_TASKS_CHANGED";function h(){(0,s.F)(o.n.ScheduledTasksChanged,{}),document.querySelectorAll("iframe").forEach(e=>{try{e.contentWindow?.postMessage({type:x},"*")}catch{}})}function f(){let[e,t]=(0,n.useState)([]),[r,s]=(0,n.useState)(0),o=(0,n.useRef)(0),m=(0,n.useCallback)(()=>{let e,r=++o.current;d.t4.runPromise((e="/api/scheduled-tasks",l.$mh({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new c.uV({message:`fetch ${e} failed`,cause:t})})).pipe(l.YWq({onSuccess:e=>{r===o.current&&(t(e.tasks??[]),s(e.unreadCount??0))},onFailure:()=>{}})))},[]);(0,n.useEffect)(()=>{m()},[m]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type===x&&m()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[m]);let f=(0,n.useCallback)(async e=>{let t=await d.t4.runPromiseExit(u("/api/scheduled-tasks","POST",{language:a.A.language,...e}));if("Success"!==t._tag)return null;let r=t.value;return r.task?(m(),h(),r.task):null},[m]),p=(0,n.useCallback)(async e=>{await d.t4.runPromise(u("/api/scheduled-tasks","PATCH",e).pipe(l.NLW).pipe(l.NWQ(()=>l.rIH))),m(),h()},[m]),g=(0,n.useCallback)(e=>p({id:e,action:"pause"}),[p]),b=(0,n.useCallback)(e=>p({id:e,action:"resume"}),[p]),v=(0,n.useCallback)(async e=>{await d.t4.runPromise(u("/api/scheduled-tasks","DELETE",{id:e}).pipe(l.NLW).pipe(l.as(!0),l.DM4(()=>!1)))||(0,i.oR)(a.A.t("scheduledTasks.deleteFailed"),"error"),m(),h()},[m]),j=(0,n.useCallback)((e,t)=>p({id:e,action:"update",fields:{...t,language:a.A.language}}),[p]),w=(0,n.useCallback)(e=>p({id:e,action:"trigger"}),[p]),k=(0,n.useCallback)(e=>p({id:e,action:"markRead"}),[p]);return{tasks:e,unreadCount:r,reload:m,createTask:f,pauseTask:g,resumeTask:b,triggerTask:w,deleteTask:v,updateTask:j,markRead:k,markAllRead:(0,n.useCallback)(()=>p({action:"markAllRead"}),[p]),reorderTasks:(0,n.useCallback)(e=>p({action:"reorder",fields:{orderedIds:e}}),[p])}}},24058:(e,t,r)=>{r.d(t,{TabBar:()=>k});var n=r(95155),s=r(12115),o=r(68287),l=r(16147),a=r(57125),i=r(93777),d=r(67889),c=r(75347),u=r(92689),m=r(64428),x=r(79114),h=r(51914),f=r(85942),p=r(94290),g=r(80860),b=r(50538);function v({number:e,status:t,statusLabel:r,isActive:s,pinned:a,bot:i}){let d="normal"!==t?(0,o.JQ)(t,s):a?"border-transparent bg-amber-9 text-black/80":s?"border-transparent bg-brand/25 text-brand":"border-transparent bg-muted-foreground/25 text-foreground/75";return(0,n.jsx)(l.w,{wash:d,ring:(0,o.QV)(t),bot:i,role:"normal"!==t?"status":void 0,ariaLabel:i?[r,`Bot session: @${i}`].filter(Boolean).join(" \xb7 "):r,ariaHidden:"normal"===t&&!i,children:e})}function j({onNewTab:e,onNewCodexTab:t,onNewGrokTab:r,onNewKimiTab:o,onNewGlmTab:l,onNewOllamaTab:i,onNewDeepseekTab:d}){let[c,u]=(0,s.useState)(!1),f=(0,s.useRef)(null),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({top:0,left:0}),v=(0,s.useRef)(0),w=(0,m.F2)(),{t:k}=(0,x.Bd)();return(0,s.useEffect)(()=>{if(!c)return;let e=e=>{p.current&&!p.current.contains(e.target)&&f.current&&!f.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[c]),(0,s.useLayoutEffect)(()=>{let e=p.current;if(!c||!e)return;let t=e.getBoundingClientRect();t.bottom>window.innerHeight-8&&b(e=>({...e,top:Math.max(8,v.current-t.height)}))},[c]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:f,onClick:()=>{if(!c&&f.current){let e=f.current.getBoundingClientRect(),t=w?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;b({top:e.bottom+4-n,left:e.left-r}),v.current=e.top-4-n}u(e=>!e)},className:"flex-shrink-0 flex items-center gap-1.5 pl-2 pr-3 py-1.5 text-sm text-foreground hover:bg-hover rounded-md transition-colors",children:[(0,n.jsx)(h.A,{className:"w-5 h-5"}),k("tabBar.newTab")]}),c&&(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{ref:p,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lv2 py-1 min-w-[140px]",style:{top:g.top,left:g.left},children:a.CX.map(s=>(0,n.jsxs)("button",{onClick:()=>{u(!1),"codex"===s?t?.():"grok"===s?r?.():"kimi"===s?o?.():"glm"===s?l?.():"ollama"===s?i?.():"deepseek"===s?d?.():e()},className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)(a.eV,{engine:s,className:"h-3.5 w-3.5"}),a.H[s]]},s))})})]})}function w({anchor:e,onClose:t,onCreate:r}){let o=(0,s.useRef)(null),[l,a]=(0,s.useState)(e.top);return(0,s.useLayoutEffect)(()=>{let t=o.current;if(!t)return;let r=t.getBoundingClientRect().bottom-(window.innerHeight-8);a(r>0?Math.max(8,e.top-r):e.top)},[e.top]),(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{ref:o,className:"fixed z-[9999]",style:{top:l,left:e.left},children:(0,n.jsx)(i.E,{unanchored:!0,onClose:t,onCreate:r})})})}function k({tabs:e,titlesLoading:t=!1,selectedTabId:r,visibleTabIds:o,unreadTabs:l,globalLoadingTabs:a,dragTabIndex:i,dragOverTabIndex:h,isPinned:y,onTogglePin:N,onScheduleTask:C,onSwitchTab:S,onCloseTab:M,onCloseAllTabs:L,onNewTab:E,onNewCodexTab:P,onNewGrokTab:T,onNewKimiTab:$,onNewGlmTab:R,onNewOllamaTab:I,onNewDeepseekTab:F,onOpenProjectSessions:B,onDragStart:D,onDragOver:A,onDrop:H,onDragEnd:O}){let{t:W}=(0,x.Bd)(),[_,z]=(0,s.useState)(320),q=(0,s.useRef)(null),V=(0,s.useRef)(null),U=(0,m.F2)(),[K,Q]=(0,s.useState)(null),G=(0,s.useCallback)(e=>{"mouse"===e.pointerType&&0===e.button&&(e.preventDefault(),q.current={startX:e.clientX,startWidth:_},e.currentTarget.setPointerCapture(e.pointerId))},[_]),J=(0,s.useCallback)(e=>{let t=q.current;t&&z(Math.min(480,Math.max(320,t.startWidth+(e.clientX-t.startX))))},[]),Y=(0,s.useCallback)(e=>{q.current&&(q.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))},[]);return(0,n.jsxs)("div",{ref:V,className:"relative flex-shrink-0 h-full flex flex-col border-r border-border bg-card",style:{width:_},children:[(0,n.jsx)("div",{onPointerDown:G,onPointerMove:J,onPointerUp:Y,onPointerCancel:Y,className:"absolute inset-y-0 -right-[3px] w-[5px] z-10 cursor-col-resize group",children:(0,n.jsx)("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2 w-px group-hover:bg-brand transition-colors"})}),(0,n.jsx)("div",{className:`${d.o} px-2`,children:(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex items-center gap-0.5",children:[(0,n.jsxs)("span",{className:"pl-1 text-sm font-medium text-foreground truncate",children:[W("sessions.projectSessions"),(0,n.jsx)("span",{className:"ml-1.5 text-xs font-normal text-muted-foreground tabular-nums",children:e.length})]}),L&&(0,n.jsx)(n.Fragment,{children:(0,n.jsx)("button",{onClick:L,className:"ml-auto flex-shrink-0 p-1.5 text-muted-foreground hover:text-destructive hover:bg-hover rounded transition-colors",title:W("tabBar.closeAll"),"aria-label":W("tabBar.closeAll"),children:(0,n.jsx)(f.A,{className:"w-4 h-4"})})})]})}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto p-1.5 space-y-0.5",children:[e.map((e,s)=>{let d=e.id===r,m=!d&&(o?.includes(e.id)??!1),x=y?.(e.id)??!1,f=e.isLoading||a.has(e.id)?"loading":l.has(e.id)&&!d?"unread":"normal";return(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>D(s),onDragOver:e=>A(e,s),onDrop:()=>H(s),onDragEnd:O,onClick:()=>S(e.id),className:`group group/session-title flex items-center gap-2 px-2 py-1.5 text-sm cursor-pointer rounded-md transition-colors ${d?"bg-brand/10 text-foreground font-medium":m?"bg-secondary/60 text-foreground":"text-muted-foreground hover:bg-hover hover:text-foreground"} ${i===s?"opacity-50":""} ${h===s&&i!==s?"ring-1 ring-inset ring-brand":""}`,children:[(0,n.jsx)("div",{className:"h-4 w-4 flex-shrink-0",children:(0,n.jsx)(v,{number:s+1,status:f,statusLabel:"loading"===f?W("sessions.running"):"unread"===f?W("sessions.done"):void 0,isActive:d,pinned:x,bot:e.bot})}),(0,n.jsx)("span",{className:"flex flex-1 items-center gap-1 min-w-0",children:(0,n.jsx)(c.dh,{cwd:e.cwd||"",sessionId:e.sessionId||"",title:e.title,initialTitleReady:e.titleReady||t})}),N&&e.sessionId&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),N(e.id)},className:`hidden group-hover:flex group-focus-within:flex h-5 w-5 shrink-0 items-center justify-center rounded hover:bg-muted ${x?"text-amber-9":"text-muted-foreground hover:text-amber-9"}`,"data-tooltip":W(x?"sessions.removeFavorite":"sessions.addFavorite"),"aria-label":W(x?"sessions.removeFavorite":"sessions.addFavorite"),"aria-pressed":x,children:(0,n.jsx)(p.A,{className:"h-3.5 w-3.5",fill:x?"currentColor":"none"})}),C&&e.cwd&&(0,n.jsx)("button",{onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),((e,t)=>{if(K?.tabId===e)return Q(null);let r=U?.getBoundingClientRect(),n=t.getBoundingClientRect(),s=V.current?.getBoundingClientRect().right??n.right;Q({tabId:e,top:n.top-(r?.top??0),left:s+8-(r?.left??0)})})(e.id,t.currentTarget.closest("[draggable]"))},className:`${K?.tabId===e.id?"flex text-brand bg-brand/10":"hidden group-hover:flex group-focus-within:flex text-muted-foreground hover:text-foreground hover:bg-muted"} h-5 w-5 shrink-0 items-center justify-center rounded`,"data-tooltip":W("chat.scheduledTasks"),"aria-label":W("chat.scheduledTasks"),children:(0,n.jsx)(g.A,{className:"h-3.5 w-3.5"})}),(0,n.jsxs)("span",{className:"relative h-4 w-4 shrink-0",children:[(0,n.jsx)("span",{className:"absolute inset-0 inline-flex items-center justify-center transition-opacity group-hover:opacity-0 group-focus-within:opacity-0",children:(0,n.jsx)(u.S,{engine:e.engine,size:"sm"})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),M(e.id)},className:"absolute inset-0 flex items-center justify-center rounded opacity-0 transition-opacity hover:bg-muted group-hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","data-tooltip":W("tabBar.closeTab"),"aria-label":W("tabBar.closeTab"),children:(0,n.jsx)("svg",{className:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]},e.id)}),(0,n.jsxs)("div",{className:"flex items-center justify-center gap-1 pt-1",children:[(0,n.jsx)(j,{onNewTab:E,onNewCodexTab:P,onNewGrokTab:T,onNewKimiTab:$,onNewGlmTab:R,onNewOllamaTab:I,onNewDeepseekTab:F}),B&&(0,n.jsx)("button",{onClick:B,className:"flex-shrink-0 p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-md transition-colors",title:W("sessions.projectSessions"),"aria-label":W("sessions.projectSessions"),children:(0,n.jsx)(b.A,{className:"w-5 h-5"})})]})]}),K&&C&&(0,n.jsx)(w,{anchor:K,onClose:()=>Q(null),onCreate:e=>C(K.tabId,e)},K.tabId)]})}},27068:(e,t,r)=>{r.d(t,{Providers:()=>b});var n=r(95155),s=r(75347),o=r(47617),l=r(3238),a=r(34075),i=r(12115),d=r(47650);function c(e){let t=e;for(;t;){let e=t.dataset?.tooltip;if(e)return e;t=t.parentElement}return null}function u(){let[e,t]=(0,i.useState)(null),r=(0,i.useRef)(null);r.current=e;let s=(0,i.useRef)(null),o=(0,i.useRef)(null),[l,a]=(0,i.useState)({left:0,top:0}),[u,m]=(0,i.useState)(!1);return((0,i.useEffect)(()=>m(!0),[]),(0,i.useEffect)(()=>{let e=()=>{s.current&&(clearTimeout(s.current),s.current=null)},n=n=>{let o=c(n.target);if(!o){e(),r.current&&t(null);return}if(r.current&&r.current.text===o)return void t({text:o,x:n.clientX,y:n.clientY});e();let l=n.clientX,a=n.clientY;s.current=setTimeout(()=>{t({text:o,x:l,y:a}),s.current=null},300)},o=n=>{if(!r.current)return;let s=c(n.target);if(!s){e(),t(null);return}t({text:s,x:n.clientX,y:n.clientY})},l=()=>{e(),r.current&&t(null)};return document.addEventListener("mouseover",n,!0),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",l),document.addEventListener("mousedown",l),()=>{document.removeEventListener("mouseover",n,!0),document.removeEventListener("mousemove",o),document.removeEventListener("mouseleave",l),document.removeEventListener("mousedown",l),e()}},[]),(0,i.useLayoutEffect)(()=>{if(!e||!o.current)return;let t=o.current.getBoundingClientRect(),r=window.innerWidth,n=window.innerHeight,s=e.x+12,l=e.y+16;s+t.width>r-8&&(s=r-t.width-8),s<8&&(s=8),l+t.height>n-8&&(l=e.y-t.height-8),a({left:s,top:l})},[e]),u&&e)?(0,d.createPortal)((0,n.jsx)("div",{ref:o,className:"fixed z-[10001] max-w-[min(80vw,64rem)] px-2 py-1 bg-tooltip text-tooltip-foreground text-xs font-mono rounded shadow-lv3 border border-line-1 whitespace-pre-wrap break-words pointer-events-none",style:{left:l.left,top:l.top},children:e.text}),document.body):null}var m=r(79114),x=r(72363),h=r(2111);let f=new Set(["preparing","installing","repairing","rolling-back","restarting"]);function p(){return(0,n.jsxs)("svg",{className:"h-4 w-4 flex-shrink-0 animate-spin text-brand",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:4}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]})}function g(){let{t:e}=(0,m.Bd)(),t=(0,i.useSyncExternalStore)(x.N4,x.fX,x.fX),[r,s]=(0,i.useState)(()=>Date.now()),o=(0,i.useRef)(!1),{stale:l}=function(){let[e,t]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let r=window.__COCKPIT_BUILD_ID__;if(!r)return;let n=!1,s=async()=>{if(!n&&!e)try{let e=await fetch("/api/health",{cache:"no-store",signal:AbortSignal.timeout(3e3)});if(!e.ok)return;let s=await e.json();if(!s.buildId)return;n||s.buildId===r||t(!0)}catch{}},o=(0,h.D)(s);return()=>{n=!0,o()}},[e]),{stale:e}}(),[d,c]=(0,i.useState)(!1),[u,g]=(0,i.useState)(!1);(0,i.useEffect)(()=>{g(window.self===window.top)},[]),(0,i.useEffect)(()=>{u&&!o.current&&(o.current=!0,(0,x.$2)())},[u]);let b=t.visible&&f.has(t.stage);(0,i.useEffect)(()=>{if(!b)return;s(Date.now());let e=window.setInterval(()=>s(Date.now()),1e3);return()=>window.clearInterval(e)},[b]);let v=(0,i.useCallback)(()=>{navigator.clipboard.writeText(t.fixCommand),(0,a.oR)(e("workspace.updateCardFixCopied"))},[t.fixCommand,e]),j=!t.visible&&l&&!d;if(!u||!t.visible&&!j)return null;let w=t.startedAt?Math.max(0,Math.round((r-t.startedAt)/1e3)):0,k=t.baselineMs?Math.round(t.baselineMs/1e3):null,y=j||"done"===t.stage,N=j||!f.has(t.stage),C=y&&!t.upToDate,S=j?e("workspace.serverRestarted"):(()=>{switch(t.stage){case"preparing":return e("workspace.updateCardPreparing");case"installing":return e("workspace.updateCardInstalling");case"repairing":return e("workspace.updateCardRepairing");case"rolling-back":return e("workspace.updateCardRollingBack");case"restarting":return e("workspace.updateCardRestarting");case"done":if(!t.installedVersion)return e("workspace.updateComplete");return t.upToDate?e("workspace.updateCardUpToDate",{version:t.installedVersion}):e("workspace.updateCardDone",{version:t.installedVersion});case"failed":return e("workspace.updateFailed")}})();return(0,n.jsx)("div",{className:"fixed top-4 right-4 z-[110] w-80 rounded-lg border border-border\n bg-background/95 p-3 shadow-lv2 backdrop-blur",role:"status","aria-live":"polite",children:(0,n.jsxs)("div",{className:"flex items-start gap-2.5",children:[b?(0,n.jsx)(p,{}):y?(0,n.jsx)("svg",{className:"h-4 w-4 flex-shrink-0 text-brand",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"h-4 w-4 flex-shrink-0 text-destructive",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v4m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-sm text-foreground",children:S}),b&&(0,n.jsxs)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:[e("workspace.updateCardElapsed",{seconds:w}),null!==k&&(0,n.jsxs)(n.Fragment,{children:[" \xb7 ",e("workspace.updateCardBaseline",{seconds:k})]})]}),b&&!t.live&&(0,n.jsx)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground/80",children:e("workspace.updateCardNoLiveStatus")}),b&&(0,n.jsx)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:e("workspace.updateRestartNote")}),!j&&"failed"===t.stage&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"mt-1 break-words text-[11px] leading-snug text-muted-foreground",children:t.error}),t.rolledBack&&(0,n.jsx)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:e("workspace.updateCardRolledBack")}),(0,n.jsx)("div",{className:"mt-2 text-[11px] leading-snug text-muted-foreground",children:e("workspace.updateCardManualHint")}),(0,n.jsx)("code",{className:"mt-1 block break-all rounded bg-hover px-2 py-1.5 text-[11px]\n leading-snug text-foreground",children:t.fixCommand}),(0,n.jsx)("button",{type:"button",onClick:v,className:"mt-1.5 w-full rounded-md border border-border px-2.5 py-1.5 text-xs\n text-foreground transition-colors hover:bg-hover",children:e("workspace.updateCardCopyFix")}),t.logPath&&(0,n.jsx)("div",{className:"mt-1.5 break-all text-[11px] leading-snug text-muted-foreground/80",children:e("workspace.updateCardLogHint",{path:t.logPath})})]}),C&&(0,n.jsx)("button",{type:"button",onClick:()=>window.location.reload(),className:"mt-2 w-full rounded-md bg-primary px-2.5 py-1.5 text-xs\n text-primary-foreground transition-opacity hover:opacity-90",children:e("workspace.reloadNow")})]}),N&&(0,n.jsx)("button",{type:"button",onClick:()=>{c(!0),j||(0,x.fZ)()},"aria-label":e("common.close"),className:"-mr-1 -mt-1 rounded p-1 text-muted-foreground transition-colors hover:bg-hover",children:(0,n.jsx)("svg",{className:"h-3.5 w-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})})}function b({children:e,initialLanguage:t}){return(0,i.useEffect)(()=>{let e=e=>{e.preventDefault()};return document.addEventListener("contextmenu",e),()=>document.removeEventListener("contextmenu",e)},[]),(0,n.jsx)(o.I18nProvider,{initialLanguage:t,children:(0,n.jsx)(l.NP,{children:(0,n.jsxs)(a.tE,{children:[(0,n.jsx)(s.hc,{}),e,(0,n.jsx)(u,{}),(0,n.jsx)(g,{})]})})})}},32456:(e,t,r)=>{r.d(t,{Mm:()=>a,Qr:()=>o,fw:()=>l,wG:()=>i,wX:()=>d});var n=r(95155),s=r(39872);let o=e=>e.split("/").pop()||e;function l(e,t){let r=Math.floor((Date.now()-t)/6e4);if(r<1)return e("common.justNow");if(r<60)return e("common.minutesAgo",{count:r});let n=Math.floor(r/60);return n<24?e("common.hoursAgo",{count:n}):e("common.daysAgo",{count:Math.floor(n/24)})}function a(e,t){return"loading"===t?e("sessions.running"):"unread"===t?e("sessions.done"):void 0}function i(e){let t=new Map;for(let r of e){let e=t.get(r.cwd);e?e.push(r):t.set(r.cwd,[r])}return[...t].map(([e,t])=>({cwd:e,items:t}))}function d({cwd:e,projectOrder:t,currentCwd:r,children:l}){let a=t.indexOf(e)+1;return(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center gap-1.5",children:[a>0&&(0,n.jsx)(s.B,{number:a,isActive:e===r}),(0,n.jsx)("span",{className:"truncate","data-tooltip":e,children:o(e)}),l]})}},39872:(e,t,r)=>{r.d(t,{B:()=>o});var n=r(95155),s=r(68287);function o({number:e,status:t="normal",isActive:r=!1}){return(0,n.jsx)("span",{className:`flex h-[18px] w-[18px] flex-shrink-0 items-center justify-center rounded-[4px] border font-mono text-[10px] font-medium leading-none tabular-nums transition-colors ${(0,s.ci)(t,r)}`,"aria-hidden":"true",children:e})}},41474:(e,t,r)=>{r.d(t,{F:()=>s});var n=r(12115);function s(){let[e,t]=(0,n.useState)(()=>"u"<typeof document||"visible"===document.visibilityState),[r,s]=(0,n.useState)(()=>window.parent===window);return(0,n.useEffect)(()=>{let e=()=>{t("visible"===document.visibilityState)};document.addEventListener("visibilitychange",e);let r=e=>{(e.data?.type==="IFRAME_VISIBILITY"||e.data?.type==="PROJECT_NUMBER")&&"boolean"==typeof e.data.visible&&s(e.data.visible)};return window.addEventListener("message",r),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("message",r)}},[]),e&&r}},45720:(e,t,r)=>{r.d(t,{X:()=>n});function n(e,t){switch(e){case"codex":return`codex resume ${t}`;case"grok":return`grok --resume ${t}`;case"kimi":case"glm":case"deepseek":case"ollama":return`${e} ${t}`;default:return`claude -r ${t}`}}},47617:(e,t,r)=>{r.d(t,{I18nProvider:()=>d});var n=r(95155),s=r(12115),o=r(79114),l=r(69809),a=r(86957),i=r(76900);function d({children:e,initialLanguage:t}){return(0,s.useState)(()=>(t&&l.A.language!==t&&l.A.changeLanguage(t),null)),(0,s.useEffect)(()=>{a.t4.runPromiseExit((0,i.M5)()).then(e=>{var t;let r="auto"!==(t=("Success"===e._tag?e.value.language:"auto")||"auto")&&t?t:navigator.language.startsWith("zh")?"zh":"en";l.A.language!==r&&l.A.changeLanguage(r)})},[]),(0,s.useEffect)(()=>{let e=e=>(function(e){for(let t of document.querySelectorAll("iframe"))try{t.contentWindow?.postMessage({type:"cockpit:language-change",lang:e},"*")}catch{}})(e);return l.A.on("languageChanged",e),()=>{l.A.off("languageChanged",e)}},[]),(0,s.useEffect)(()=>{if(window===window.parent)return;let e=e=>{e.data?.type==="cockpit:language-change"&&e.data.lang&&l.A.language!==e.data.lang&&l.A.changeLanguage(e.data.lang)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,n.jsx)(o.xC,{i18n:l.A,children:e})}},52153:(e,t,r)=>{r.d(t,{SessionBrowser:()=>b});var n=r(95155),s=r(12115),o=r(79114),l=r(66109),a=r(95045),i=r(75346),d=r(86957),c=r(76900),u=r(64702);let m=(e,t)=>e.endsWith(t)?e:e+t,x=(0,s.memo)(function({entry:e,index:t,highlighted:r,top:s,onEnter:o,onPick:l,onHover:a}){return(0,n.jsxs)("div",{role:"option","aria-selected":r,onClick:()=>o(e.path),onDoubleClick:()=>l(e.path),onMouseMove:()=>a(t),style:{position:"absolute",top:s,left:0,right:0,height:30},className:`flex items-center gap-2 px-3 text-xs cursor-pointer select-none ${r?"bg-hover text-foreground":"text-foreground"} ${e.hidden?"opacity-60":""}`,children:[(0,n.jsx)("svg",{className:"w-4 h-4 shrink-0 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsx)("span",{className:"flex-1 truncate",children:e.name}),e.git&&(0,n.jsx)("span",{className:"shrink-0 text-[10px] text-muted-foreground border border-border rounded px-1",children:"git"})]})});function h({onPick:e}){let t,r,l,{t:a}=(0,o.Bd)(),[i,f]=(0,s.useState)(""),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(-1),N=(0,s.useRef)(null),C=(0,s.useRef)(null),S=(0,s.useRef)(0),M=p?.sep??"/",{base:L,prefix:E}=(t="\\"===M?Math.max(i.lastIndexOf("/"),i.lastIndexOf("\\")):i.lastIndexOf("/"),r=i.slice(0,t+1),l=i.slice(t+1),""===r&&"~"===l?{base:"~",prefix:""}:{base:r,prefix:l});(0,s.useEffect)(()=>{let e=++S.current;d.t4.runPromiseExit((0,c.fz)("")).then(t=>{"Success"===t._tag&&e===S.current&&(g(t.value),v(m(t.value.path,t.value.sep)),f(m(t.value.path,t.value.sep)))}),N.current?.focus()},[]),(0,s.useEffect)(()=>{if(null===b||L===b)return;let e=setTimeout(()=>{let e=++S.current;d.t4.runPromiseExit((0,c.fz)(L)).then(t=>{"Success"===t._tag&&e===S.current&&(g(t.value),v(L))})},60);return()=>clearTimeout(e)},[L,b]);let P=b!==L,T=(0,s.useMemo)(()=>{if(!p)return[];let e=E.toLowerCase(),t=p.dirs.filter(t=>j||!t.hidden||e.startsWith("."));return e?[...t.filter(t=>t.name.toLowerCase().startsWith(e)),...t.filter(t=>!t.name.toLowerCase().startsWith(e)&&t.name.toLowerCase().includes(e))]:t},[p,E,j]);(0,s.useEffect)(()=>{y(E&&T.length>0?0:-1)},[E,T]);let $=(0,s.useMemo)(()=>!p||p.error||P?null:E?T.find(e=>e.name.toLowerCase()===E.toLowerCase())?.path??null:p.path,[p,E,T,P]),R=(0,s.useCallback)(e=>{f(m(e,M)),N.current?.focus()},[M]),I=(0,u.Te)({count:T.length,getScrollElement:()=>C.current,estimateSize:()=>30,overscan:8});(0,s.useEffect)(()=>{k>=0&&I.scrollToIndex(k)},[k,I]);let F=p?.error&&!P?a(`folderPicker.${p.error}`):null;return(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col gap-2 p-4",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:N,type:"text",value:i,onChange:e=>f(e.target.value),onKeyDown:t=>{if("Enter"===t.key&&(t.metaKey||t.ctrlKey))t.preventDefault(),$&&e($);else if("ArrowDown"===t.key)t.preventDefault(),y(e=>Math.min(e+1,T.length-1));else if("ArrowUp"===t.key)t.preventDefault(),y(e=>Math.max(e-1,0));else if("Tab"===t.key||"Enter"===t.key){let e=T[k];e?(t.preventDefault(),R(e.path)):"Tab"===t.key&&t.preventDefault()}},placeholder:a("folderPicker.placeholder"),spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",className:"flex-1 min-w-0 px-2.5 py-1.5 text-xs font-mono border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,n.jsx)("button",{onClick:()=>$&&e($),disabled:!$,"data-tooltip":$??void 0,className:"shrink-0 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",children:a("folderPicker.open")})]}),(0,n.jsx)("div",{className:"flex items-center gap-0.5 min-h-6 overflow-x-auto text-xs text-muted-foreground whitespace-nowrap",children:p?.segments.map((e,t)=>(0,n.jsxs)("span",{className:"flex items-center",children:[t>1&&(0,n.jsx)("span",{className:"px-0.5 text-foreground-subtle",children:"›"}),(0,n.jsx)("button",{onClick:()=>R(e.path),className:"px-1 py-0.5 rounded hover:bg-hover hover:text-foreground transition-colors",children:e.name})]},e.path))}),(0,n.jsx)("div",{ref:C,role:"listbox",className:`flex-1 min-h-0 overflow-y-auto border border-border rounded transition-opacity ${P?"opacity-60":""}`,children:F?(0,n.jsx)("div",{className:"p-3 text-xs text-red-11",children:F}):p&&0===T.length?(0,n.jsx)("div",{className:"p-3 text-xs text-muted-foreground",children:a(E?"folderPicker.noMatch":"folderPicker.empty")}):(0,n.jsx)("div",{style:{height:I.getTotalSize(),position:"relative"},children:I.getVirtualItems().map(t=>(0,n.jsx)(x,{entry:T[t.index],index:t.index,highlighted:t.index===k,top:t.start,onEnter:R,onPick:e,onHover:y},T[t.index].path))})}),(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 text-xs",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[p&&(0,n.jsx)("button",{onClick:()=>R(p.home),className:"px-2 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:"~"}),p?.roots.map(e=>(0,n.jsx)("button",{onClick:()=>R(e),className:"px-2 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors font-mono",children:e},e))]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 text-muted-foreground cursor-pointer select-none",children:[(0,n.jsx)("input",{type:"checkbox",checked:j,onChange:e=>w(e.target.checked)}),a("folderPicker.showHidden")]}),(0,n.jsx)("span",{className:"hidden md:inline text-foreground-subtle",children:a("folderPicker.hint")})]})]})}var f=r(7578),p=r(92689),g=r(75347);function b({isOpen:e,onClose:t,onSelectSession:r,onAddProject:u,sessionNumbers:m={},projectNumbers:x={}}){let{t:v}=(0,o.Bd)(),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)([]),[N,C]=(0,s.useState)({}),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),[P,T]=(0,s.useState)(""),$=(0,s.useRef)(null),R=(0,s.useCallback)(async()=>{M(!0),E(null),C({});let e=await d.t4.runPromiseExit((0,c.H7)());"Success"===e._tag?y(e.value):E("Failed to load projects"),M(!1)},[]),I=(0,s.useCallback)(async e=>{C(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await d.t4.runPromiseExit((0,c.QW)(e));"Success"===t._tag?C(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):C(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),F=(0,s.useCallback)(e=>{let t=N[e];t?.isExpanded?C(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?C(t=>({...t,[e]:{...t[e],isExpanded:!0}})):I(e)},[N,I]);(0,s.useEffect)(()=>{e&&(w(!1),R(),setTimeout(()=>{$.current?.focus(),$.current?.select()},100))},[e,R]);let B=(0,s.useCallback)(e=>{u?.(e),t()},[u,t]);return((0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&(j?w(!1):t())};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,j,t]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:j?"relative w-full max-w-[min(42rem,calc((100vw_-_28rem)*0.9))] h-[min(70vh,36rem)] mx-4 bg-card rounded-lg shadow-lv3 flex flex-col overflow-hidden":l.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[j?(0,n.jsxs)("button",{onClick:()=>w(!1),className:"flex items-center gap-1 text-sm font-medium text-foreground hover:text-brand transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),v("folderPicker.title")]}):(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:v("sessions.projectList")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[!j&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:$,type:"text",placeholder:v("workspace.searchProjectPath"),value:P,onChange:e=>T(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),P&&(0,n.jsx)("button",{onClick:()=>{T(""),$.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:v("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),u&&!j&&(0,n.jsxs)("button",{onClick:()=>w(!0),className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m3-3H9m-4 7h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),v("sessions.openFolder")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),j?(0,n.jsx)(h,{onPick:B}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[S&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:v("workspace.loadingProjects")})]})}),L&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:L})}),!S&&!L&&0===k.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:v("workspace.projectNotFound")})}),!S&&!L&&k.filter(e=>e.fullPath.toLowerCase().includes(P.toLowerCase())).map(e=>{let t=N[e.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null},s=x[e.fullPath];return(0,n.jsxs)("div",{className:"mb-3",children:[(0,n.jsxs)("button",{onClick:()=>F(e.encodedPath),className:"w-full flex items-center gap-2 p-2 rounded hover:bg-hover transition-colors text-left",children:[(0,n.jsx)("svg",{className:`w-3 h-3 text-muted-foreground transition-transform ${t.isExpanded?"rotate-90":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),s&&(0,n.jsx)(f.l,{projectNumber:s}),(0,n.jsx)("span",{className:"flex-1 text-xs font-medium text-foreground truncate","data-tooltip":e.fullPath,children:e.fullPath}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",e.sessionCount,")"]})]}),t.isExpanded&&(0,n.jsxs)("div",{className:"ml-6 mt-2",children:[t.isLoading&&(0,n.jsxs)("div",{className:"flex items-center gap-2 p-3 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-3 w-3",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:v("sessions.loadingSessions")})]}),t.error&&(0,n.jsx)("div",{className:"p-3 text-xs text-red-11",children:t.error}),!t.isLoading&&!t.error&&(0,n.jsx)("div",{className:l.jL,children:t.sessions.map(t=>{let s=t.path.split("/").pop()||"",o=t.sessionId||s.replace(".jsonl",""),l=m[`${e.fullPath}
38
- ${o}`],[d,c]=l?.split(".")??[];return(0,n.jsxs)("div",{onClick:()=>{var n;let s,o;return n=e.fullPath,s=t.path.split("/").pop()||"",o=t.sessionId||s.replace(".jsonl",""),void(r?r(n,o):(0,a.F)(i.n.OpenProject,{cwd:n,sessionId:o}))},className:"group/session-title p-3 rounded border border-border hover:border-brand hover:shadow-lv2 cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)(p.S,{engine:t.engine}),(0,n.jsx)("h4",{className:"flex flex-1 min-w-0 items-center gap-1 text-xs font-medium text-foreground",children:(0,n.jsx)(g.dh,{cwd:e.fullPath,sessionId:t.sessionId||t.path.split("/").pop()?.replace(/\.jsonl$/,"")||"",title:t.title,titleRevision:t.titleRevision})}),l&&(0,n.jsx)(f.l,{projectNumber:d,sessionNumber:c,bot:t.bot,className:"ml-auto"})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(t.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[t.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate","data-tooltip":e,children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`first-${t}`)),t.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-foreground-subtle text-center py-0.5",children:"\xb7\xb7\xb7"}),t.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate","data-tooltip":e,children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`last-${t}`))]})]},t.path)})})]})]},e.encodedPath)})]})]})]}):null}},53213:(e,t,r)=>{r.d(t,{Bj:()=>d,CM:()=>v,FK:()=>b,Iz:()=>x,MB:()=>j,Ub:()=>f,X0:()=>h,Zi:()=>c,lv:()=>m,oh:()=>g,r4:()=>a,ue:()=>i,w2:()=>p,yy:()=>u});var n=r(49433),s=r(82680);let o=e=>n.$mh({try:async()=>{let t=await fetch(e);if(!t.ok){let e;try{e=(await t.json()).error}catch{}throw Error(e||`HTTP ${t.status}`)}return await t.json()},catch:t=>new s.uV({message:`fetch ${e} failed`,cause:t})}),l=(e,t)=>n.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),a=e=>o(`/api/git/branches?cwd=${encodeURIComponent(e)}`).pipe(n.qIB(t=>"Failed to get branches"===t.error?n.fJG(new s.m_({resource:"git-repo",id:e})):n.PyW(t))),i=e=>o(`/api/git/current-branch?cwd=${encodeURIComponent(e)}`),d=(e,t,r,n)=>o(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${r}${"number"==typeof n?`&offset=${n}`:""}`),c=(e,t,r)=>o(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),u=(e,t,r,n="worktree")=>o(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}&mode=${n}${r?`&file=${encodeURIComponent(r)}`:""}`),m=e=>o(`/api/git/status?cwd=${encodeURIComponent(e)}`),x=(e,t)=>l("/api/git/stage",{cwd:e,files:t}),h=(e,t)=>l("/api/git/unstage",{cwd:e,files:t}),f=(e,t,r)=>l("/api/git/discard",{cwd:e,files:t,isUntracked:r}),p=(e,t,r,n)=>{let s=new URLSearchParams({cwd:e,file:t,type:r});return n&&s.set("oldPath",n),o(`/api/git/diff?${s}`)},g=e=>o(`/api/git/diff?${e.toString()}`),b=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),v=e=>n.$mh({try:async()=>{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),r=await t.json().catch(()=>null);if(!t.ok)throw Error(r?.error||`HTTP ${t.status}`);return r},catch:e=>new s.uV({message:"POST /api/git/worktree failed",cause:e})}),j=e=>o(`/api/projectGraph/search?${e.toString()}`)},53317:(e,t,r)=>{function n(e){return e.replace(/^claude-/,"").replace(/-\d{8}$/,"").replace(/(\d)-(?=\d)/g,"$1.").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function s(e){return e.split("-").map((e,t)=>0===t?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1)).join("-")}r.d(t,{J:()=>n,U:()=>s})},54356:(e,t,r)=>{r.d(t,{useTabState:()=>N});var n=r(12115),s=r(41474),o=r(2111),l=r(95045),a=r(75346),i=r(49433),d=r(80286),c=r(86957),u=r(96472),m=r(82680);let x=e=>`cockpit:active-tab:${e}`;var h=r(48050),f=r(83448);function p(e){let t,r=!1,n=Promise.resolve(),s=async()=>{if(!r){r=!0;try{for(;void 0!==t;){let r=t;t=void 0;try{await e(r)}catch{}}}finally{r=!1}}};return{enqueue(e){t=e,r||(n=s())},whenIdle:()=>n}}let g=e=>`Session ${e}`;function b(e,t,r,n,s){let o=new Set(t.map(e=>e.id)),l=new Set([...e].filter(e=>o.has(e))),a=new Map;for(let e of r){if(e.cwd!==n)continue;let t="codex"===e.engine?w(e.sessionId):e.sessionId;a.set(t,e.status??"normal")}for(let e of t){if(!e.sessionId)continue;let t=a.get(e.sessionId);void 0!==t&&(t===s?l.add(e.id):l.delete(e.id))}return l}function v(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}let j=/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:\.jsonl)?$/i;function w(e){let t=e.match(j);return t?.[1]??e}function k(e,t){if(e.engine&&t.engine&&e.engine!==t.engine)return!1;if(e.sessionId===t.sessionId)return!0;let r=e.engine??t.engine;return("codex"===r||!r&&/rollout-/.test(e.sessionId+t.sessionId))&&w(e.sessionId)===w(t.sessionId)}function y(e,t,r){let n=new Set(t.map(e=>e.id)),s=new Set(e.filter(e=>n.has(e))),o=[],l=[];for(let a of e){if(n.has(a)&&!l.includes(a)){l.push(a);continue}let e=new Set([...l,...s]),i=[...t].reverse().find(t=>!e.has(t.id));if(i){l.push(i.id),s.add(i.id);continue}let d={id:`tab-${Date.now()}-pane${o.length}`,cwd:r,title:"New Chat"};o.push(d),l.push(d.id)}return{panes:l,created:o}}function N({initialCwd:e,initialSessionId:t,initialBlank:r,activeView:j}){let C=(0,n.useRef)(!1),S=(0,n.useRef)(!0),[M,L]=(0,n.useState)(!1),[E,P]=(0,n.useState)(null),[T,$]=(0,n.useState)(!!e),R=(0,n.useCallback)(()=>{S.current=!1,L(!0)},[]),I=(0,s.F)(),[F,B]=(0,n.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:t?g(t):"New Chat"}]),[D,A]=(0,n.useState)(()=>[F[0]?.id??""]),[H,O]=(0,n.useState)(0),W=(0,n.useRef)(H);(0,n.useEffect)(()=>{W.current=H},[H]);let _=(0,n.useRef)(D);(0,n.useEffect)(()=>{_.current=D},[D]);let z=D[H]??D[0]??"",q=(0,n.useCallback)(e=>{A(t=>{let r=t.indexOf(e);if(-1!==r)return r!==W.current&&O(r),t;let n=[...t];return n[W.current]=e,n})},[]),[V,U]=(0,n.useState)(new Set),[K,Q]=(0,n.useState)(new Set),G=(0,n.useRef)(F);(0,n.useEffect)(()=>{G.current=F},[F]);let J=(0,n.useRef)([]),Y=(0,n.useRef)(z);(0,n.useEffect)(()=>{Y.current=z},[z]);let X=(0,n.useRef)(null),Z=(0,n.useRef)(new Set),ee=F.find(e=>e.id===z),et=(0,n.useRef)(void 0);(0,n.useLayoutEffect)(()=>(et.current=M&&I&&(!j||"agent"===j)?ee:void 0,()=>{et.current=void 0}),[M,I,j,ee]);let er=(0,n.useMemo)(()=>p(async t=>{let r=()=>!!t.sessionId&&et.current?.id===t.id&&et.current.sessionId===t.sessionId&&et.current.engine===t.engine&&"visible"===document.visibilityState;if(!e||!t.sessionId||!r())return;let n=await c.t4.runPromise((0,u.AH)(e,t.sessionId,t.engine,r));if(null===n||!r()||et.current?.isLoading)return;let s=J.current.filter(r=>r.cwd===e&&k(r,{sessionId:t.sessionId,engine:t.engine}));if(!s.some(e=>"loading"===e.status||(e.lastActive??0)>n)){for(let e of s)e.status="normal";U(e=>{if(!e.has(t.id))return e;let r=new Set(e);return r.delete(t.id),r})}}),[e]),en=(0,n.useCallback)((e,t)=>{let r=et.current;r?.sessionId&&(!e||k({sessionId:r.sessionId,engine:r.engine},{sessionId:e,engine:t}))&&er.enqueue(r)},[er]);(0,n.useEffect)(()=>{en()},[en,M,I,j,z,ee?.sessionId,ee?.engine,ee?.isLoading]);let es=(0,n.useCallback)(t=>{e&&(Q(r=>{let n=b(r,G.current,t,e,"loading");return v(r,n)?r:n}),U(r=>{let n=b(r,G.current,t,e,"unread");return v(r,n)?r:n}))},[e]);(0,n.useEffect)(()=>{M&&es(J.current)},[M,F,es]);let[eo,el]=(0,n.useState)(null),[ea,ei]=(0,n.useState)(null);(0,n.useEffect)(()=>{!e||C.current||(C.current=!0,(async()=>{let n=c.t4.runSync(i.SvU({try:()=>{let t=window.sessionStorage.getItem(x(e));if(!t)return null;let r=JSON.parse(t);return"blank"===r.kind?{kind:"blank"}:"session"===r.kind&&"string"==typeof r.sessionId&&r.sessionId?{kind:"session",sessionId:r.sessionId}:null},catch:e=>new m.uV({message:"load active tab target failed",cause:e})}).pipe(i.h9N(()=>i.PyW(null)))),s=await c.t4.runPromise((0,u.n8)(e).pipe(i.h9N(()=>i.PyW(null))));if(s){let o=s.engines||{},l={};for(let[e,t]of Object.entries(o))l["codex"===t?w(e):e]=t;let a=[];for(let e of s.sessions||[]){let t="codex"===o[e]?w(e):e;a.includes(t)||a.push(t)}let i=s.activeSessionId&&"codex"===o[s.activeSessionId]?w(s.activeSessionId):s.activeSessionId,d=s.ollamaModels||{},c=s.deepseekModels||{},u=s.kimiModels||{},m=s.glmModels||{},x=s.claudeModels||{},h=s.claudeEfforts||{},f=s.claudeFastModes||{},p=s.claudeThinkings||{},b=s.codexModels||{},v=s.grokModels||{},j=s.codexReasoningEfforts||{},k=s.grokReasoningEfforts||{},N=s.planModes||{},C=s.noHistories||{},S=n?.kind==="session"?n.sessionId:void 0,M=[...a];t&&!M.includes(t)&&(M=[t,...M]),S&&!M.includes(S)&&(M=[S,...M]),P(M);let L=new Map((s.sessionTitles??[]).map(e=>[e.sessionId,e.title]));if(M.length>0){let a=G.current,E=M.map((t,r)=>{let n=a.find(e=>e.sessionId===t),s=L.get(t)||n?.title;return{id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:s||g(t),titleReady:!0,engine:l[t]||n?.engine||void 0,ollamaModel:d[t]||n?.ollamaModel||void 0,deepseekModel:c[t]||n?.deepseekModel||void 0,kimiModel:u[t]||n?.kimiModel||void 0,glmModel:m[t]||n?.glmModel||void 0,claudeModel:x[t]||n?.claudeModel||void 0,claudeEffort:h[t]||n?.claudeEffort||void 0,claudeFastMode:f[t]??n?.claudeFastMode,claudeThinking:p[t]??n?.claudeThinking,codexModel:b[t]||n?.codexModel||void 0,grokModel:v[t]||n?.grokModel||void 0,codexReasoningEffort:j[t]||n?.codexReasoningEffort||void 0,grokReasoningEffort:k[t]||n?.grokReasoningEffort||void 0,planMode:N[t]??n?.planMode,noHistory:C[t]??n?.noHistory}}),P=S||t||i,T=P?M.indexOf(P):-1;T<0&&(T=0);let $=n?.kind!=="blank"&&(n||t||!r&&null!==i)?void 0:{id:`tab-${Date.now()}-blank`,cwd:e,title:"New Chat"},I=$?[...E,$]:E,F=$?.id??E[T].id,D=s.paneSessionIds;if(Array.isArray(D)&&D.length>1){let{panes:t,created:r}=y(D.slice(0,2).map(e=>{let t=e&&"codex"===o[e]?w(e):e;return t&&E.find(e=>e.sessionId===t)?.id||""}),I,e),n=t.indexOf(F);-1===n&&(t[0]=F,n=0);let s=t[0]===t[1];B([...I,...r]),A(s?[t[0]]:t),O(s?0:n)}else B(I),q(F);setTimeout(R,0)}else R()}else P(t?[t]:[]),R()})())},[e,t,r,R]),(0,n.useEffect)(()=>{if(!e||null===E)return;if(0===E.length)return void $(!1);let t=!0;$(!1);let r=c.t4.runFork((0,h.S6)(e,E).pipe(i.Mim(r=>i.OH5(()=>{if(!t)return;let n=new Map(r.map(e=>[e.sessionId,e]));B(t=>t.map(t=>{if(!t.sessionId||(t.cwd||e)!==e||!E.includes(t.sessionId))return t;let r=n.get(t.sessionId);return{...t,title:r?.title??t.title,titleReady:!0}}))})),i.h9N(e=>i.FFw("Cannot load initial project titles",e)),i.yeE(i.OH5(()=>{t&&$(!1)}))));return()=>{t=!1,c.t4.runFork(d.G(r))}},[e,E]),(0,n.useEffect)(()=>{if(!M||!e)return;let t=F.map(e=>e.sessionId).filter(e=>!!e),r=F.find(e=>e.id===z),n=r?.sessionId??null,s={},o={},l={},a={},i={},d={},m={},x={},h={},f={},g={},b={},v={},j={},w={};for(let e of F)e.sessionId&&e.engine&&(s[e.sessionId]=e.engine),e.sessionId&&e.ollamaModel&&(o[e.sessionId]=e.ollamaModel),e.sessionId&&e.deepseekModel&&(l[e.sessionId]=e.deepseekModel),e.sessionId&&e.kimiModel&&(a[e.sessionId]=e.kimiModel),e.sessionId&&e.glmModel&&(i[e.sessionId]=e.glmModel),e.sessionId&&e.claudeModel&&(d[e.sessionId]=e.claudeModel),e.sessionId&&e.claudeEffort&&(m[e.sessionId]=e.claudeEffort),e.sessionId&&e.codexModel&&(f[e.sessionId]=e.codexModel),e.sessionId&&e.codexReasoningEffort&&(b[e.sessionId]=e.codexReasoningEffort),e.sessionId&&e.grokModel&&(g[e.sessionId]=e.grokModel),e.sessionId&&void 0!==e.grokReasoningEffort&&(v[e.sessionId]=e.grokReasoningEffort),e.sessionId&&(void 0!==e.planMode&&(j[e.sessionId]=e.planMode),void 0!==e.noHistory&&(w[e.sessionId]=e.noHistory),void 0!==e.claudeFastMode&&(x[e.sessionId]=e.claudeFastMode),void 0!==e.claudeThinking&&(h[e.sessionId]=e.claudeThinking));let k=[...Z.current],y={cwd:e,sessions:t,activeSessionId:n,paneSessionIds:D.map(e=>F.find(t=>t.id===e)?.sessionId??null),engines:s,ollamaModels:o,deepseekModels:l,kimiModels:a,glmModels:i,claudeModels:d,claudeEfforts:m,claudeFastModes:x,claudeThinkings:h,codexModels:f,grokModels:g,codexReasoningEfforts:b,grokReasoningEfforts:v,planModes:j,noHistories:w,...k.length?{closedSessionIds:k}:{}};X.current||(X.current=p(async e=>{let t=await c.t4.runPromiseExit((0,u.ej)(e));if("Success"===t._tag)for(let t of e.closedSessionIds??[])Z.current.delete(t);else console.error("Failed to save sessions:",t.cause)})),X.current.enqueue(y)},[F,z,D,e,M]),(0,n.useLayoutEffect)(()=>{if(S.current||!e)return;let t=F.find(e=>e.id===z)?.sessionId,r=t?{kind:"session",sessionId:t}:{kind:"blank"};c.t4.runSync(i.SvU({try:()=>window.sessionStorage.setItem(x(e),JSON.stringify(r)),catch:e=>new m.uV({message:"save active tab target failed",cause:e})}).pipe(i.h9N(()=>i.rIH))),(0,l.F)(a.n.SessionChange,{cwd:e,sessionId:t??null})},[z,F,e,M]);let ed=(0,n.useCallback)(t=>{e&&c.t4.runPromise((0,u.n8)(e).pipe(i.h9N(()=>i.PyW(null)))).then(r=>{if(!r)return;let n=r.engines||{},s={};for(let[e,t]of Object.entries(n))s["codex"===t?w(e):e]=t;let o=[];for(let e of r.sessions||[]){let t="codex"===n[e]?w(e):e;o.includes(t)||o.push(t)}let l=r.ollamaModels||{},a=r.deepseekModels||{},i=r.kimiModels||{},d=r.glmModels||{},c=r.claudeModels||{},u=r.claudeEfforts||{},m=r.claudeFastModes||{},x=r.claudeThinkings||{},h=r.codexModels||{},f=r.grokModels||{},p=r.codexReasoningEfforts||{},b=r.grokReasoningEfforts||{},v=r.planModes||{},j=r.noHistories||{},k=G.current,N=new Set(t),C=k.filter(e=>!e.sessionId||!N.has(e.sessionId)),S=new Set(C.map(e=>e.sessionId).filter(Boolean)),M=o.filter(e=>!S.has(e));if(C.length===k.length&&0===M.length)return;let L=[...C,...M.map((t,r)=>({id:`tab-${Date.now()}-sync-${r}`,cwd:e,sessionId:t,title:g(t),engine:s[t]||void 0,ollamaModel:l[t]||void 0,deepseekModel:a[t]||void 0,kimiModel:i[t]||void 0,glmModel:d[t]||void 0,claudeModel:c[t]||void 0,claudeEffort:u[t]||void 0,claudeFastMode:m[t]??void 0,claudeThinking:x[t]??void 0,codexModel:h[t]||void 0,grokModel:f[t]||void 0,codexReasoningEffort:p[t]||void 0,grokReasoningEffort:b[t]||void 0,planMode:v[t]||void 0,noHistory:j[t]||void 0}))];0===L.length&&(L=[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]);let{panes:E,created:P}=y(_.current,L,e);P.length&&(L=[...L,...P]),B(L),A(E)})},[e]),ec=(0,n.useCallback)(t=>{if(e){if("global-state"===t.type&&Array.isArray(t.data?.sessions)){if(J.current=t.data.sessions,!S.current)for(let r of(es(t.data.sessions),t.data.sessions))r.cwd===e&&"unread"===r.status&&en(r.sessionId,r.engine);return}"task-fired"===t.type&&t.cwd===e&&t.sessionId&&en(t.sessionId),S.current||"project-state-changed"!==t.type||t.cwd!==e||ed(t.closedSessionIds??[])}},[e,ed,es,en]);(0,o.h)({url:"/ws/global-state",enabled:!!e,onMessage:ec});let eu=(0,n.useCallback)((e,t,r,n)=>{let{engine:s,ollamaModel:o,deepseekModel:l,kimiModel:a,glmModel:i,claudeModel:d,claudeEffort:c,claudeFastMode:u,claudeThinking:m,codexModel:x,codexReasoningEffort:h,grokModel:f,grokReasoningEffort:p,planMode:b,noHistory:v,appendToEnd:j=!1}=n??{},w={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?g(t):"New Chat"),engine:s,ollamaModel:o,deepseekModel:l,kimiModel:a,glmModel:i,claudeModel:d,claudeEffort:c,claudeFastMode:u,claudeThinking:m,codexModel:x,grokModel:f,codexReasoningEffort:h,grokReasoningEffort:p,planMode:b,noHistory:v};return B(e=>{if(j)return[...e,w];let t=e.findIndex(e=>e.id===z);if(-1===t)return[...e,w];let r=[...e];return r.splice(t+1,0,w),r}),q(w.id),w.id},[z]),em=(0,n.useCallback)(t=>{let r=G.current.find(e=>e.id===t);r?.sessionId&&Z.current.add(r.sessionId);let n=G.current.filter(e=>e.id!==t),{panes:s,created:o}=y(_.current,n,e);B([...n,...o]),A(s)},[e]),ex=(0,n.useCallback)(()=>{O(0),G.current.forEach(e=>{e.sessionId&&Z.current.add(e.sessionId)});let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};q(t.id),B([t])},[e]),eh=(0,n.useCallback)((t,r)=>{let n=F.find(e=>e.sessionId===t);if(n){q(n.id),en(t);return}e?c.t4.runPromise((0,u.n8)(e).pipe(i.h9N(()=>i.PyW(null)))).then(n=>{let s=G.current.find(e=>e.sessionId===t);if(s){q(s.id),en(t);return}eu(e,t,r,{engine:n?.engines?.[t],ollamaModel:n?.ollamaModels?.[t],deepseekModel:n?.deepseekModels?.[t],kimiModel:n?.kimiModels?.[t],glmModel:n?.glmModels?.[t],claudeModel:n?.claudeModels?.[t],claudeEffort:n?.claudeEfforts?.[t],claudeFastMode:n?.claudeFastModes?.[t],claudeThinking:n?.claudeThinkings?.[t],codexModel:n?.codexModels?.[t],grokModel:n?.grokModels?.[t],codexReasoningEffort:n?.codexReasoningEfforts?.[t],grokReasoningEffort:n?.grokReasoningEfforts?.[t],planMode:n?.planModes?.[t],noHistory:n?.noHistories?.[t],appendToEnd:!0})}):eu(e,t,r,{appendToEnd:!0})},[F,e,eu,en]),ef=(0,n.useCallback)(()=>{eu(e,void 0,void 0,{appendToEnd:!0})},[e,eu]),ep=(0,n.useCallback)(()=>{eu(e,void 0,"New Codex Chat",{engine:"codex",appendToEnd:!0})},[e,eu]),eg=(0,n.useCallback)(()=>{eu(e,void 0,"New Grok Chat",{engine:"grok",appendToEnd:!0})},[e,eu]),eb=(0,n.useCallback)(()=>{eu(e,void 0,"New Kimi Chat",{engine:"kimi",kimiModel:"k3",appendToEnd:!0})},[e,eu]),ev=(0,n.useCallback)(()=>{eu(e,void 0,"New GLM Chat",{engine:"glm",glmModel:"glm-5.3",appendToEnd:!0})},[e,eu]),ej=(0,n.useRef)(void 0),ew=(0,n.useCallback)(()=>{let t=eu(e,void 0,"New Ollama Chat",{engine:"ollama",ollamaModel:ej.current,appendToEnd:!0});c.t4.runPromise((0,f.Vm)()).then(e=>{e&&(ej.current=e,B(r=>r.map(r=>r.id!==t||r.ollamaModel?r:{...r,ollamaModel:e})))})},[e,eu]),ek=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e&&r.engine!==t?{...r,engine:t}:r))},[]),ey=(0,n.useCallback)((e,t)=>{ej.current=t,B(r=>r.map(r=>r.id===e?{...r,ollamaModel:t}:r))},[]),eN=(0,n.useCallback)(()=>{eu(e,void 0,"New DeepSeek Chat",{engine:"deepseek",deepseekModel:"deepseek-v4-pro",appendToEnd:!0})},[e,eu]),eC=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,deepseekModel:t}:r))},[]),eS=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,kimiModel:t}:r))},[]),eM=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,glmModel:t}:r))},[]),eL=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,claudeModel:t}:r))},[]),eE=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,claudeEffort:t}:r))},[]),eP=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,claudeFastMode:t}:r))},[]),eT=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,claudeThinking:t}:r))},[]),e$=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,codexModel:t}:r))},[]),eR=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,grokModel:t}:r))},[]),eI=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,codexReasoningEffort:t}:r))},[]),eF=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,grokReasoningEffort:t}:r))},[]),eB=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,planMode:t}:r))},[]),eD=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,noHistory:t}:r))},[]),eA=(0,n.useCallback)((t,r)=>{let n=G.current.find(e=>e.id===Y.current);eu(e,t,r,{engine:n?.engine,ollamaModel:n?.ollamaModel,deepseekModel:n?.deepseekModel,kimiModel:n?.kimiModel,glmModel:n?.glmModel,claudeModel:n?.claudeModel,claudeEffort:n?.claudeEffort,claudeFastMode:n?.claudeFastMode,claudeThinking:n?.claudeThinking,codexModel:n?.codexModel,grokModel:n?.grokModel,codexReasoningEffort:n?.codexReasoningEffort,grokReasoningEffort:n?.grokReasoningEffort})},[e,eu]),eH=(0,n.useCallback)((e,t)=>{let r=G.current.find(t=>t.id===e);r?.isLoading&&!1===t.isLoading&&(et.current?.id===e?en(t.sessionId||r.sessionId):U(t=>new Set(t).add(e))),B(r=>r.map(r=>r.id===e?{...r,...t,titleReady:void 0!==t.sessionId&&t.sessionId!==r.sessionId?void 0:r.titleReady}:r))},[en]),eO=(0,n.useCallback)(()=>{let t=_.current;if(t.length>1){A([t[W.current]]),O(0);return}let r=G.current,n=r.findIndex(e=>e.id===t[0]),s=r[n+1]??r[n-1];if(s){A([t[0],s.id]),O(0);return}let o={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};B(e=>[...e,o]),A([t[0],o.id]),O(1)},[e]),eW=(0,n.useCallback)(e=>{let t=_.current;t.length<2||(A(t.filter((t,r)=>r!==e)),O(0))},[]),e_=(0,n.useCallback)(e=>{O(e)},[]),ez=(0,n.useCallback)(e=>{q(e);let t=G.current.find(t=>t.id===e)?.sessionId;t&&en(t)},[q,en]),eq=(0,n.useCallback)(e=>{el(e)},[]),eV=(0,n.useCallback)((e,t)=>{e.preventDefault(),null!==eo&&eo!==t&&ei(t)},[eo]),eU=(0,n.useCallback)(e=>{null!==eo&&eo!==e&&B(t=>{let r=[...t],[n]=r.splice(eo,1);return r.splice(e,0,n),r}),el(null),ei(null)},[eo]),eK=(0,n.useCallback)(()=>{el(null),ei(null)},[]),eQ=F.find(e=>e.id===z);return{tabs:F,titlesLoading:T,activeTabId:z,activeTab:eQ,paneTabIds:D,activePane:H,unreadTabs:V,globalLoadingTabs:K,pageVisible:I,dragTabIndex:eo,dragOverTabIndex:ea,addTab:eu,toggleSideBySide:eO,focusPane:e_,closePane:eW,closeTab:em,closeAllTabs:ex,switchTab:ez,handleSelectSession:eh,handleNewTab:ef,handleNewCodexTab:ep,handleNewGrokTab:eg,handleNewKimiTab:eb,handleNewGlmTab:ev,handleNewOllamaTab:ew,handleNewDeepseekTab:eN,handleOpenSession:eA,updateTabState:eH,updateTabEngine:ek,updateTabOllamaModel:ey,updateTabDeepseekModel:eC,updateTabKimiModel:eS,updateTabGlmModel:eM,updateTabClaudeModel:eL,updateTabClaudeEffort:eE,updateTabClaudeFastMode:eP,updateTabClaudeThinking:eT,updateTabCodexModel:e$,updateTabGrokModel:eR,updateTabCodexReasoningEffort:eI,updateTabGrokReasoningEffort:eF,updateTabPlanMode:eB,updateTabNoHistory:eD,handleTabDragStart:eq,handleTabDragOver:eV,handleTabDrop:eU,handleTabDragEnd:eK}}},59461:(e,t,r)=>{r.d(t,{Q:()=>w,j:()=>v});var n=r(95155),s=r(75347),o=r(8183),l=r(12115),a=r(79114),i=r(66109),d=r(95045),c=r(75346),u=r(86957),m=r(4768),x=r(83448),h=r(92689),f=r(7578),p=r(20832),g=r(32456);let b=[{key:"today",labelKey:"sessions.dateToday"},{key:"yesterday",labelKey:"sessions.dateYesterday"},{key:"last7Days",labelKey:"sessions.dateLast7Days"},{key:"earlier",labelKey:"sessions.dateEarlier"}];function v(e,t=Date.now()){let r=new Date(t);r.setHours(0,0,0,0);let n=r.getTime();return e>=n?"today":e>=n-864e5?"yesterday":e>=n-5184e5?"last7Days":"earlier"}let j=e=>e.sessionId||(e.path.split("/").pop()||"").replace(".jsonl","");function w({isOpen:e,onClose:t,cwd:r,onSelectSession:k,projectNumber:y,openSessionIds:N=[]}){let{t:C}=(0,a.Bd)(),S=(0,s.bc)(),[M,L]=(0,l.useState)([]),[E,P]=(0,l.useState)(0),[T,$]=(0,l.useState)(!1),[R,I]=(0,l.useState)(null),[F,B]=(0,l.useState)(""),D=(0,l.useRef)(null),[A,H]=(0,l.useState)(null),O=(0,l.useCallback)(async()=>{if(!r)return;$(!0),I(null);let e=(0,m.O)(r),t=await u.t4.runPromiseExit((0,x.QW)(e));"Success"===t._tag?(L(t.value),P(Date.now())):I("Failed to load sessions"),$(!1)},[r]);(0,l.useEffect)(()=>{e?(O(),setTimeout(()=>{D.current?.focus(),D.current?.select()},100)):H(null)},[e,O]),(0,l.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let W=e=>{let n=j(e);k?(k(n,(0,o.iM)(S,r,n,e.title,e.titleRevision)),t()):(0,d.F)(c.n.OpenProject,{cwd:r,sessionId:n})},_=(0,l.useMemo)(()=>{let e=[...M].sort((e,t)=>Date.parse(t.modifiedAt)-Date.parse(e.modifiedAt));if(!F)return e;let t=F.toLowerCase();return e.filter(e=>!!(0,o.iM)(S,r,j(e),e.title,e.titleRevision).toLowerCase().includes(t)||(void 0!==e.searchText?e.searchText.includes(t):(0,o.iM)(S,r,j(e),e.title,e.titleRevision).toLowerCase().includes(t)||e.firstMessages.some(e=>e.toLowerCase().includes(t))||e.lastMessages.some(e=>e.toLowerCase().includes(t))))},[M,S,r,F]),z=(0,l.useMemo)(()=>{let e={today:[],yesterday:[],last7Days:[],earlier:[]};for(let t of _)e[v(Date.parse(t.modifiedAt),E)].push(t);return e},[_,E]),q=A?M.find(e=>j(e)===A)??null:null;if((0,l.useEffect)(()=>{if(!e||q)return;let t=_[0];H(t?j(t):null)},[e,q,_]),!e)return null;let V=e=>{let t=j(e),o=N.indexOf(t),l=t===A,a=e.lastMessages[e.lastMessages.length-1]??e.firstMessages[0];return(0,n.jsxs)("div",{onClick:()=>H(t),onDoubleClick:()=>W(e),className:`group/session-title rounded-md px-3 py-2 cursor-pointer transition-colors ${l?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(h.S,{engine:e.engine}),(0,n.jsx)("span",{className:"text-xs font-medium text-foreground flex items-center gap-1 flex-1 min-w-0",children:(0,n.jsx)(s.dh,{cwd:r,sessionId:t,title:e.title,titleRevision:e.titleRevision})}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:(0,g.fw)(C,Date.parse(e.modifiedAt))}),y&&o>=0&&(0,n.jsx)(f.l,{projectNumber:y,sessionNumber:o+1,bot:e.bot})]}),a&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-[22px]",children:a})]},e.path)};return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:i.iG,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:C("sessions.sessionList")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate","data-tooltip":r,children:r})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 ml-4 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsxs)("div",{className:"w-full md:w-[360px] min-h-0 flex-shrink-0 md:border-r border-border flex flex-col",children:[(0,n.jsx)("div",{className:"p-3 flex-shrink-0 border-b border-border",children:(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:D,type:"text",placeholder:C("sessions.searchSessions"),value:F,onChange:e=>B(e.target.value),className:"w-full px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),F&&(0,n.jsx)("button",{onClick:()=>{B(""),D.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:C("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:(0,n.jsx)("div",{className:"p-3 space-y-3",children:0===M.length&&T?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:C("sessions.loadingSessions")}):0===M.length&&R?(0,n.jsx)("div",{className:"text-xs text-red-11 text-center py-6",children:R}):0===_.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:F?C("sessions.noMatchingSessions"):C("sessions.noSessionsYet")}):b.map(({key:e,labelKey:t})=>{let r=z[e];return 0===r.length?null:(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center gap-1.5",children:[(0,n.jsx)("span",{children:C(t)}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:r.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:r.map(V)})]},e)})})})]}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:q?(0,n.jsx)(p.p,{cwd:r,sessionId:j(q),subtitle:(0,o.iM)(S,r,j(q),q.title,q.titleRevision),emptyText:C("sessions.noSessionMessages"),onOpenSession:()=>W(q)},j(q)):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:C("sessions.selectSessionHint")})})]})]})]})}},60865:(e,t,r)=>{r.d(t,{NoteModal:()=>ed});var n=r(95155),s=r(12115),o=r(79114),l=r(69809),a=r(13439),i=r(58940),d=r(43561),c=r(5989),u=r(76065),m=r(43203),x=r(6268),h=r(48434),f=r(82159),p=r(44695);let g={todo:"doing",doing:"done",done:"todo"},b={todo:"false",doing:"mixed",done:"true"},v=/^\s*(\[([ x/])?\])\s$/,j=p.L.extend({addAttributes:()=>({status:{default:"todo",keepOnSplit:!1,parseHTML:e=>(function(e){let t=e.getAttribute("data-status");if("todo"===t||"doing"===t||"done"===t)return t;let r=e.getAttribute("data-checked");return""===r||"true"===r?"done":"todo"})(e),renderHTML:e=>({"data-status":e.status,"data-checked":"done"===e.status?"true":"false"})}}),addStorage:()=>({markdown:{serialize(e,t){var r;e.write(`${"done"===(r=t.attrs.status)?"[x]":"doing"===r?"[/]":"[ ]"} `),e.renderContent(t)}}}),addInputRules(){return[(0,f.tG)({find:v,type:this.type,getAttributes:e=>{let t=e[e.length-1];return{status:"x"===t?"done":"/"===t?"doing":"todo"}}})]},renderHTML({HTMLAttributes:e}){return["li",(0,f.KV)(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},addNodeView(){return({node:e,getPos:t,editor:r})=>{let n=document.createElement("li");n.setAttribute("data-type",this.name);let s=document.createElement("label");s.classList.add("task-marker"),s.contentEditable="false";let o=document.createElement("span");o.classList.add("task-marker-box"),o.setAttribute("role","checkbox"),s.appendChild(o);let l=document.createElement("div");n.append(s,l);let a=e=>{let t=e.attrs.status??"todo";n.dataset.status=t,n.dataset.checked="done"===t?"true":"false",o.setAttribute("aria-checked",b[t])};return a(e),s.addEventListener("mousedown",e=>e.preventDefault()),s.addEventListener("click",e=>{if(e.preventDefault(),!r.isEditable||"function"!=typeof t)return;let n=t();"number"==typeof n&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=e.doc.nodeAt(n);if(!t)return!1;let r=t.attrs.status??"todo";return e.setNodeMarkup(n,void 0,{...t.attrs,status:g[r]}),!0}).run()}),{dom:n,contentDOM:l,update:t=>t.type===e.type&&(a(t),!0)}}}});var w=r(59265),k=r(26932),y=r(27050),N=r(52740),C=r(76865),S=r(63197);let M=new C.hs("headingFold");function L(e){let t=e.attrs.foldState;return"folded"===t||"children"===t?t:"expanded"}function E(e){let t=[],r=[];return e.forEach((e,n)=>{let s=n+e.nodeSize;if("heading"===e.type.name){let o=e.attrs.level;for(;r.length&&r[r.length-1].level>=o;)r.pop();let l=L(e),a=r.some(e=>"folded"===e.state),i=["note-heading"];"expanded"!==l&&i.push("is-collapsed"),a&&i.push("note-folded-hidden"),t.push(S.NZ.node(n,s,{class:i.join(" ")})),t.push(S.NZ.widget(n+1,(e,t)=>{let r;return(r=document.createElement("span")).className="note-fold-toggle",r.contentEditable="false",r.setAttribute("data-fold-state",l),r.addEventListener("mousedown",r=>{r.preventDefault(),r.stopPropagation();let n=t();if(null==n)return;let s=n-1,o=e.state.doc.nodeAt(s);o&&"heading"===o.type.name&&e.dispatch(e.state.tr.setNodeMarkup(s,void 0,{...o.attrs,foldState:"expanded"===L(o)?"folded":"expanded"}))}),r},{side:-1,key:`fold-${n}-${l}`})),r.push({level:o,state:l})}else r.some(e=>"folded"===e.state||"children"===e.state)&&t.push(S.NZ.node(n,s,{class:"note-folded-hidden"}))}),S.zF.create(e,t)}let P=N.A.extend({addAttributes(){return{...this.parent?.(),foldState:{default:"expanded",keepOnSplit:!1,parseHTML:e=>"true"===e.getAttribute("data-collapsed")?"folded":"expanded",renderHTML:e=>e.foldState&&"expanded"!==e.foldState?{"data-collapsed":"true"}:{}}}},addKeyboardShortcuts(){let e=this.name;return{Tab:()=>{var t;let r,n,s,{state:o}=this.editor,{$from:l}=o.selection;if(l.parent.type.name!==e)return!1;let a=l.before(l.depth),i=o.doc.nodeAt(a);if(!i||i.type.name!==e)return!1;let d=i.attrs.level,c=(t=o.doc,n=[],s=!1,t.forEach((t,r)=>{if(r===a){s=!0;return}if(s&&t.type.name===e){if(t.attrs.level<=d){s=!1;return}n.push(r)}}),n),u=c.length>0,m=L(i),x=null;return u?"expanded"===m?r="folded":(r="folded"===m?"children":"expanded",x="expanded"):r="expanded"===m?"folded":"expanded",this.editor.chain().command(({tr:t})=>{if(t.setNodeMarkup(a,void 0,{...i.attrs,foldState:r}),x)for(let r of c){let n=t.doc.nodeAt(r);n&&n.type.name===e&&t.setNodeMarkup(r,void 0,{...n.attrs,foldState:x})}return!0}).run()}}},addStorage:()=>({markdown:{serialize(e,t){e.write(e.repeat("#",t.attrs.level)+" "),e.renderInline(t,!1),"expanded"!==L(t)&&e.write(" \x3c!-- fold --\x3e"),e.closeBlock(t)},parse:{updateDOM(e){e.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach(e=>{let t=e.lastChild;for(;t&&3===t.nodeType&&!(t.textContent||"").trim();){let r=t.previousSibling;e.removeChild(t),t=r}if(t&&8===t.nodeType&&/^\s*fold\s*$/.test(t.textContent||"")){let r=t.previousSibling;e.removeChild(t),r&&3===r.nodeType&&(r.textContent=(r.textContent||"").replace(/\s+$/,"")),e.setAttribute("data-collapsed","true")}})}}}}),addProseMirrorPlugins:()=>[new C.k_({key:M,state:{init:(e,{doc:t})=>E(t),apply:(e,t)=>e.docChanged?E(e.doc):t},props:{decorations:e=>M.getState(e)}})]});function T(e){let t=[];return e.forEach((e,r)=>t.push({node:e,start:r,end:r+e.nodeSize})),t}function $(e,t){return"heading"===e.type.name&&e.attrs.level<=t}function R(e){for(let t=e.depth;t>0;t--){let r=e.node(t).type.name;if("listItem"===r||"taskItem"===r)return t}return -1}function I(e,t,r,n,s){let o=t.slice(r,n),l=t.slice(n,s);e.replaceWith(r,s,l.content.append(o.content))}function F(e,t){let r=Math.max(0,Math.min(t,e.doc.content.size));e.setSelection(C.U3.near(e.doc.resolve(r)))}let B=new Set(["paragraph","bulletList","orderedList","taskList"]);function D(e,t,r){let{doc:n,selection:s}=e,o=s.$from,l=o.before(1),a=T(n),i=a.findIndex(e=>e.start===l);if(i<0)return!1;let d=i;for(;d>0&&B.has(a[d-1].node.type.name);)d--;let c=i;for(;c<a.length-1&&B.has(a[c+1].node.type.name);)c++;let u=[],m=-1,x="paragraph"===a[i].node.type.name?-1:o.index(1);for(let e=d;e<=c;e++){let t=a[e].node;if("paragraph"===t.type.name)e===i&&(m=u.length),u.push({kind:"paragraph",node:t});else{let r=t.type.name,n=0;t.forEach(t=>{e===i&&n===x&&(m=u.length),u.push({kind:r,node:t}),n++})}}if(m<0)return!1;let h=m+(r>0?1:-1);if(h<0||h>=u.length)return!1;if(t){let r,n,s,l=u[m];u[m]=u[h],u[h]=l;let i=function(e,t){let r=[],n=0;for(;n<e.length;){if("paragraph"===e[n].kind){r.push(e[n].node),n++;continue}let s=e[n].kind,o=[];for(;n<e.length&&e[n].kind===s;)o.push(e[n].node),n++;r.push(t.schema.nodes[s].create(null,o))}return y.FK.from(r)}(u,e),x=a[d].start,f=a[c].end,p=e.tr;p.replaceWith(x,f,i);let g=(r=0,n=0,s=-1,i.forEach(e=>{if(!(s>=0))if("paragraph"===e.type.name)r===h&&(s=n+1),r++,n+=e.nodeSize;else{let t=n+1;e.forEach(e=>{s>=0||(r===h&&(s=t+2),r++,t+=e.nodeSize)}),n+=e.nodeSize}}),s);F(p,g>=0?x+g+o.parentOffset:x),t(p.scrollIntoView())}return!0}function A(e,t,r){let n=e.selection.$from;if(1===n.depth&&"heading"===n.parent.type.name)return function(e,t,r){let{doc:n,selection:s}=e,o=s.$from.before(1),l=T(n),a=l.findIndex(e=>e.start===o);if(a<0)return!1;let i=l[a].node.attrs.level,d=a+1;for(;d<l.length&&!$(l[d].node,i);)d++;let c=l[a].start,u=l[d-1].end;if(r>0){if(d>=l.length)return!1;let r=l[d].node.attrs.level,o=d+1;for(;o<l.length&&!$(l[o].node,r);)o++;let a=l[o-1].end;if(t){let r=e.tr,o=n.slice(u,a).content.size;I(r,n,c,u,a),F(r,c+o+(s.from-c)),t(r.scrollIntoView())}return!0}if(0===a)return!1;let m=a-1;for(;m>=0&&!$(l[m].node,i);)m--;if(m<0||l[m].node.attrs.level<i)return!1;let x=l[m].start;if(t){let r=e.tr;I(r,n,x,c,u),F(r,x+(s.from-c)),t(r.scrollIntoView())}return!0}(e,t,r);let s=R(n);if(s>0){let o=n.node(s-1),l=n.index(s-1);return(r>0?l<o.childCount-1:l>0)?function(e,t,r,n){let{doc:s,selection:o}=e,l=o.$from,a=l.node(n),i=l.node(n-1),d=l.index(n-1),c=l.before(n),u=c+a.nodeSize;if(r>0){if(d>=i.childCount-1)return!1;let r=u+i.child(d+1).nodeSize;if(t){let n=e.tr,l=s.slice(u,r).content.size;I(n,s,c,u,r),F(n,c+l+(o.from-c)),t(n.scrollIntoView())}return!0}if(d<=0)return!1;let m=c-i.child(d-1).nodeSize;if(t){let r=e.tr;I(r,s,m,c,u),F(r,m+(o.from-c)),t(r.scrollIntoView())}return!0}(e,t,r,s):2===s&&D(e,t,r)}let o=n.depth>=1?n.node(n.depth-1).type.name:"doc";return"paragraph"===n.parent.type.name&&"doc"===o&&D(e,t,r)}function H(e,t){let{state:r}=e,n=r.selection.$from,s=n.parent.type.name;if("doc"===(n.depth>=1?n.node(n.depth-1).type.name:"doc")&&("heading"===s||"paragraph"===s)){let r=(("heading"===s?n.parent.attrs.level-1:3)+(t>0?1:-1)+4)%4;return 3===r?e.chain().setParagraph().run():e.chain().setHeading({level:r+1}).run()}let o=R(n);if(o>0){let r=n.node(o).type.name;return t<0?e.commands.liftListItem(r):e.commands.sinkListItem(r)}return!1}function O(e,t){let{state:r}=e,n=r.selection;if(!n.empty)return!1;let s=n.$from,o=t>0?1:-1;for(let t=s.depth;t>0;t--)if("taskItem"===s.node(t).type.name){let n=s.before(t),l=r.doc.nodeAt(n);if(!l)return!1;let a=l.attrs.status??"todo",i=(("doing"===a?2:"done"===a?3:1)+o+4)%4;if(0===i)return e.chain().toggleTaskList().run();let d=2===i?"doing":3===i?"done":"todo";return e.chain().command(({tr:e})=>{let t=e.doc.nodeAt(n);return!!t&&(e.setNodeMarkup(n,void 0,{...t.attrs,status:d}),!0)}).run()}if("paragraph"!==s.parent.type.name)return!1;let l=s.depth>=1?s.node(s.depth-1).type.name:"doc";return("doc"===l||"listItem"===l)&&(1==(0+o+4)%4?e.chain().toggleTaskList().run():e.chain().toggleTaskList().command(({tr:e})=>(function(e,t){let r=e.selection.$from;for(let n=r.depth;n>0;n--)if("taskItem"===r.node(n).type.name){let s=r.before(n),o=e.doc.nodeAt(s);o&&e.setNodeMarkup(s,void 0,{...o.attrs,status:t});break}return!0})(e,"done")).run())}let W=f.YY.create({name:"noteOrgKeymap",addKeyboardShortcuts(){return{"Alt-ArrowUp":()=>this.editor.commands.command(({state:e,dispatch:t})=>A(e,t,-1)),"Alt-ArrowDown":()=>this.editor.commands.command(({state:e,dispatch:t})=>A(e,t,1)),"Alt-ArrowLeft":()=>H(this.editor,-1),"Alt-ArrowRight":()=>H(this.editor,1),"Shift-ArrowRight":()=>O(this.editor,1),"Shift-ArrowLeft":()=>O(this.editor,-1)}}});function _(e){return e.storage.markdown.getMarkdown()}function z(){return[{label:l.A.t("slashCommands.heading1"),icon:"H1",description:l.A.t("slashCommands.heading1Desc"),action:e=>e.chain().focus().toggleHeading({level:1}).run()},{label:l.A.t("slashCommands.heading2"),icon:"H2",description:l.A.t("slashCommands.heading2Desc"),action:e=>e.chain().focus().toggleHeading({level:2}).run()},{label:l.A.t("slashCommands.heading3"),icon:"H3",description:l.A.t("slashCommands.heading3Desc"),action:e=>e.chain().focus().toggleHeading({level:3}).run()},{label:l.A.t("slashCommands.bulletList"),icon:"•",description:l.A.t("slashCommands.bulletListDesc"),action:e=>e.chain().focus().toggleBulletList().run()},{label:l.A.t("slashCommands.orderedList"),icon:"1.",description:l.A.t("slashCommands.orderedListDesc"),action:e=>e.chain().focus().toggleOrderedList().run()},{label:l.A.t("slashCommands.taskList"),icon:"☑",description:l.A.t("slashCommands.taskListDesc"),action:e=>e.chain().focus().toggleTaskList().run()},{label:l.A.t("slashCommands.blockquote"),icon:"❝",description:l.A.t("slashCommands.blockquoteDesc"),action:e=>e.chain().focus().toggleBlockquote().run()},{label:l.A.t("slashCommands.codeBlock"),icon:"<>",description:l.A.t("slashCommands.codeBlockDesc"),action:e=>e.chain().focus().toggleCodeBlock().run()},{label:l.A.t("slashCommands.table"),icon:"▦",description:l.A.t("slashCommands.tableDesc"),action:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},{label:l.A.t("slashCommands.horizontalRule"),icon:"──",description:l.A.t("slashCommands.horizontalRuleDesc"),action:e=>e.chain().focus().setHorizontalRule().run()},{label:l.A.t("slashCommands.link"),icon:"\uD83D\uDD17",description:l.A.t("slashCommands.linkDesc"),action:e=>{window.dispatchEvent(new CustomEvent("tiptap-insert-link"))}}]}function q({editor:e,query:t,position:r,onClose:o}){let[l,a]=(0,s.useState)(0),i=(0,s.useRef)(null),d=z().filter(e=>e.label.toLowerCase().includes(t.toLowerCase())||e.description.toLowerCase().includes(t.toLowerCase()));(0,s.useEffect)(()=>{queueMicrotask(()=>a(0))},[t]);let c=r=>{e.chain().focus().deleteRange({from:e.state.selection.from-t.length-1,to:e.state.selection.from}).run(),r.action(e),o()};return((0,s.useEffect)(()=>{let e=e=>{"ArrowDown"===e.key?(e.preventDefault(),a(e=>(e+1)%d.length)):"ArrowUp"===e.key?(e.preventDefault(),a(e=>(e-1+d.length)%d.length)):"Enter"===e.key?(e.preventDefault(),d[l]&&c(d[l])):"Escape"===e.key&&(e.preventDefault(),o())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[d,l,o]),0===d.length)?null:(0,n.jsx)("div",{ref:i,className:"slash-command-menu fixed z-[60] bg-popover border border-border rounded-lg shadow-lv2 py-1 w-56 max-h-64 overflow-y-auto",style:{top:r.top,left:r.left},children:d.map((e,t)=>(0,n.jsxs)("button",{className:`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors ${t===l?"bg-accent text-foreground":"text-muted-foreground hover:bg-hover hover:text-foreground"}`,onClick:()=>c(e),onMouseEnter:()=>a(t),children:[(0,n.jsx)("span",{className:"w-6 text-center text-xs font-mono flex-shrink-0",children:e.icon}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-medium",children:e.label}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:e.description})]})]},e.label))})}z();var V=r(76043),U=r(86957),K=r(49433),Q=r(34075),G=r(66109),J=r(39872),Y=r(92451),X=r(76900);let Z=/^\s*[-*+]\s+(?:\\?\[ \\?\]|\\?\[[xX/]\\?\])\s*$/,ee=/^\s*(```|~~~)/;function et(e){return e.classList.contains("task-list-item")}let er=/^\s*\[\/\]\s?/,en=f.YY.create({name:"markdownTaskListFix",addStorage:()=>({markdown:{parse:{updateDOM(e){var t;for(let r of Array.from(e.querySelectorAll("li"))){if(et(r))continue;let e=r.parentElement;e&&"UL"===e.tagName&&(t=r.textContent||"",/^\s*\[\/\]/.test(t)&&(!function(e){let t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=t.nextNode();for(;r&&!(r.nodeValue&&""!==r.nodeValue.trim());)r=t.nextNode();r&&r.nodeValue&&(r.nodeValue=r.nodeValue.replace(er,""))}(r),r.classList.add("task-list-item"),r.setAttribute("data-type","taskItem"),r.setAttribute("data-status","doing"),e.classList.add("contains-task-list")))}!function(e){for(let t of Array.from(e.querySelectorAll("ul.contains-task-list"))){let e=Array.from(t.children).filter(e=>"LI"===e.tagName);if(0===e.length)continue;let r=function(e){let t=[];for(let r of e){let e=t[t.length-1];e&&e.isTask===r.isTask?e.items.push(r):t.push({isTask:r.isTask,items:[r]})}return t}(e.map(e=>({isTask:et(e),el:e})));if(r.length<=1){r[0]?.isTask&&t.setAttribute("data-type","taskList");continue}let n=t.ownerDocument,s=n.createDocumentFragment();for(let e of r){let t=n.createElement("ul");for(let{el:r}of(e.isTask&&(t.setAttribute("class","contains-task-list"),t.setAttribute("data-type","taskList")),e.items))t.appendChild(r);s.appendChild(t)}t.replaceWith(s)}}(e)}}}})});var es=r(8242);let eo=new Set(["taskItem","listItem"]),el=f.YY.create({name:"dropShellCleanup",addProseMirrorPlugins:()=>[new C.k_({key:new C.hs("dropShellCleanup"),appendTransaction(e,t,r){let n=[];if(e.forEach((t,r)=>{let s;if("drop"!==t.getMeta("uiEvent")||!t.docChanged)return;let o=(s=[],t.steps.forEach((e,r)=>{e instanceof es.Ln&&(0!==e.slice.size||e.from>=e.to||s.push(t.mapping.slice(r+1).map(e.from)))}),s);for(let t=r+1;t<e.length;t++)o=o.map(r=>e[t].mapping.map(r));n.push(...o)}),0===n.length)return null;let s=r.tr,o=!1;for(let e of n){let t=function(e,t){if(t<0||t>e.content.size)return null;let r=e.resolve(t);for(let e=r.depth;e>0;e--){var n;if(n=r.node(e),!eo.has(n.type.name)||1!==n.childCount||null===n.firstChild||!n.firstChild.isTextblock||0!==n.firstChild.content.size)continue;let t=e;for(;t>1&&1===r.node(t-1).childCount;)t--;return{from:r.before(t),to:r.after(t)}}return null}(s.doc,s.mapping.map(e));if(t)try{s.delete(t.from,t.to),o=!0}catch{}}return o?s:null}})]}),ea=e=>e.split("/").filter(Boolean).pop()||e,ei=e=>e??"";function ed({isOpen:e,onClose:t,projectCwd:r,currentCwd:f,projectOrder:p}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)(r??null),N=(0,s.useRef)(ei(r??null)),C=(0,s.useRef)(r??null),[S,M]=(0,s.useState)([]),[L,E]=(0,s.useState)(""),[T,$]=(0,s.useState)(!0),[R,I]=(0,s.useState)(!1),F=(0,s.useRef)(null),B=(0,s.useRef)(!1),D=(0,s.useRef)(void 0),[A,H]=(0,s.useState)(null),O=(0,s.useRef)(null),z=(0,s.useCallback)(()=>{U.t4.runPromiseExit((0,X.zv)()).then(e=>{"Success"===e._tag&&M(e.value)})},[]),et=(0,s.useCallback)(async(e,t)=>{let r=function(e){if(!e)return e;let t=e.split("\n"),r=[],n=!1;for(let e of t){if(ee.test(e)){n=!n,r.push(e);continue}if(n){r.push(e);continue}Z.test(e)||r.push(e)}let s=[],o=0,l=!1;for(let e of r){if(ee.test(e)){l=!l,s.push(e),o=0;continue}if(!l&&""===e.trim()){if((o+=1)>=2)continue;s.push(e);continue}o=0,s.push(e)}return s.join("\n")}(t);I(!0);let n=D.current,s=await U.t4.runPromiseExit((0,X.Cq)(e,r,n).pipe(K.sFT(e=>K.OH5(()=>console.error("Failed to save note:",e))))),o=N.current===ei(e);if("Success"===s._tag){let e=s.value;e.conflict&&!o?(0,Q.oR)(g("editor.conflictReloaded"),"info"):e.conflict?(eo.current?.commands.setContent(e.content,{emitUpdate:!1}),D.current=e.mtime,B.current=!1,(0,Q.oR)(g("editor.conflictReloaded"),"info")):o&&(D.current=e.mtime,B.current=!1),z()}I(!1)},[g,z]),er=(0,s.useCallback)(e=>{B.current=!0,F.current&&clearTimeout(F.current);let t=C.current;F.current=setTimeout(()=>{et(t,e)},5e3)},[et]),es=(0,a.hG)({immediatelyRender:!1,extensions:[i.A.configure({heading:!1,link:!1}),P.configure({levels:[1,2,3]}),W,d.A.configure({placeholder:()=>l.A.t("editor.placeholder")}),c.XI.configure({resizable:!0}),u.H,m.n,x.A,h._,w.Ay.configure({autolink:!0,linkOnPaste:!0,openOnClick:!1,HTMLAttributes:{class:"tiptap-link",target:"_blank",rel:"noopener noreferrer"}}),j.configure({nested:!0}),en,el,k.o.configure({html:!0,transformCopiedText:!1,transformPastedText:!0})],editorProps:{attributes:{class:"tiptap-editor focus:outline-none min-h-[60vh] px-6 py-4"},clipboardTextSerializer:e=>e.content.textBetween(0,e.content.size,"\n").replace(/\n+$/,""),transformCopied:e=>{let t=e=>!!e&&e.isTextblock&&0===e.content.size,r=e.content,{openStart:n,openEnd:s}=e;for(;r.childCount>1&&t(r.lastChild);)r=r.cut(0,r.size-r.lastChild.nodeSize),s=0;for(;r.childCount>1&&t(r.firstChild);)r=r.cut(r.firstChild.nodeSize),n=0;return new y.Ji(r,n,s)},handleClick:(e,t,r)=>{if(r.metaKey||r.ctrlKey){let r=e.state.doc.resolve(t).marks().find(e=>"link"===e.type.name)?.attrs;if(r?.href)return window.open(r.href,"_blank","noopener,noreferrer"),!0}return!1},handleKeyDown:(e,t)=>{if("Backspace"===t.key&&eo.current){let e=eo.current;if(e.isActive("codeBlock")){let{$from:t}=e.state.selection,r=t.node(t.depth);if("codeBlock"===r.type.name&&""===r.textContent)return e.chain().focus().toggleCodeBlock().run(),!0}}return"/"!==t.key||A||setTimeout(()=>{if(!eo.current)return;let{from:e}=eo.current.state.selection;if("/"===eo.current.state.doc.textBetween(Math.max(0,e-1),e,"\n")){O.current=e;let t=eo.current.view.coordsAtPos(e);H({query:"",position:{top:t.bottom+4,left:t.left}})}},0),!1}},onUpdate:({editor:e})=>{if(er(_(e)),null!==O.current){let{from:t}=e.state.selection;if(t<O.current)H(null),O.current=null;else{let r=e.state.doc.textBetween(O.current,t,"\n");r.includes(" ")||r.includes("\n")?(H(null),O.current=null):H(e=>e?{...e,query:r}:null)}}}}),eo=(0,s.useRef)(null);(0,s.useEffect)(()=>{eo.current=es},[es]),(0,s.useEffect)(()=>{if(!e)return;let t=r??null;C.current=t,N.current=ei(t),v(t),E(""),z()},[e,r,z]),(0,s.useEffect)(()=>{if(!e||!es)return;$(!0),H(null),O.current=null;let t=!1;return U.t4.runPromiseExit((0,X.zF)(b)).then(e=>{t||("Success"===e._tag?(es.commands.setContent(e.value.content||"",{emitUpdate:!1}),D.current=e.value.mtime,F.current&&(clearTimeout(F.current),F.current=null),B.current=!1):console.error("Failed to load note:",e.cause),$(!1))}),()=>{t=!0}},[e,es,b]);let ec=(0,s.useCallback)(()=>{F.current&&(clearTimeout(F.current),F.current=null),B.current&&es&&(et(C.current,_(es)),B.current=!1)},[es,et]),eu=(0,s.useCallback)(e=>{ei(e)!==N.current&&(ec(),C.current=e,N.current=ei(e),v(e))},[ec]),em=(0,s.useCallback)(()=>{ec(),H(null),O.current=null,t()},[ec,t]);(0,s.useEffect)(()=>()=>{F.current&&clearTimeout(F.current)},[]),(0,s.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&(A?(H(null),O.current=null):em())};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,em,A]);let ex=(0,s.useMemo)(()=>{let e=new Map(S.map(e=>[ei(e.cwd),e])),t=new Set([""]),n=[{cwd:null,entry:e.get("")}];for(let s of[r??null,f??null])!s||t.has(ei(s))||e.has(ei(s))||(t.add(ei(s)),n.push({cwd:s}));for(let e of[...S].sort((e,t)=>t.mtime-e.mtime))t.has(ei(e.cwd))||(t.add(ei(e.cwd)),n.push({cwd:e.cwd,entry:e}));return n},[S,r,f]),eh=(0,s.useCallback)(e=>e?ea(e):g("editor.globalNote"),[g]),ef=(0,s.useMemo)(()=>{let e=L.trim().toLowerCase();return e?ex.filter(({cwd:t,entry:r})=>eh(t).toLowerCase().includes(e)||(t?.toLowerCase().includes(e)??!1)||(r?.searchText.includes(e)??!1)):ex},[ex,L,eh]);if(!e)return null;let ep=ei(b);return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:em}),(0,n.jsxs)("div",{className:G.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:b?g("editor.noteTitle",{name:ea(b)}):g("editor.globalNote")}),R&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:g("editor.saving")})]}),(0,n.jsx)("button",{onClick:em,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsxs)("div",{className:"hidden md:flex w-[300px] min-h-0 flex-shrink-0 border-r border-border flex-col",children:[(0,n.jsx)("div",{className:"p-3 flex-shrink-0 border-b border-border",children:(0,n.jsx)("input",{type:"text",placeholder:g("editor.searchNotes"),value:L,onChange:e=>E(e.target.value),className:"w-full px-2 py-1 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto p-2 space-y-0.5",children:ef.map(({cwd:e,entry:t})=>{let r=e?p.indexOf(e)+1:0,s=ei(e)===ep;return(0,n.jsxs)("div",{onClick:()=>eu(e),title:e??void 0,className:`rounded-md px-3 py-2 cursor-pointer transition-colors ${s?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[null===e?(0,n.jsx)(Y.A,{className:"w-[18px] h-[18px] p-0.5 flex-shrink-0 text-muted-foreground"}):r>0?(0,n.jsx)(J.B,{number:r,isActive:e===f}):(0,n.jsx)("span",{className:"w-[18px] flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs font-medium text-foreground truncate flex-1 min-w-0",children:eh(e)}),t&&t.mtime>0&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:function(e,t){let r=Math.floor((Date.now()-t)/6e4);if(r<1)return e("common.justNow");if(r<60)return e("common.minutesAgo",{count:r});let n=Math.floor(r/60);return n<24?e("common.hoursAgo",{count:n}):e("common.daysAgo",{count:Math.floor(n/24)})}(g,t.mtime)})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-6",children:t?.firstLine||g("editor.emptyNote")})]},ei(e)||"(global)")})})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsx)(V.NoteToolbar,{editor:es}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:T?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:(0,n.jsx)("span",{children:g("common.loading")})}):(0,n.jsx)(a.$Z,{editor:es})})]})]})]}),A&&es&&(0,n.jsx)(q,{editor:es,query:A.query,position:A.position,onClose:()=>{H(null),O.current=null}})]})}},63728:(e,t,r)=>{r.d(t,{R8:()=>i,c0:()=>c,fY:()=>d,gT:()=>u});var n=r(95155),s=r(12115);let o=["agent","explorer","console"],l={agent:"AGENT",explorer:"EXPLORER",console:"CONSOLE"},a=(0,s.createContext)(null);function i(){let e=(0,s.useContext)(a);if(!e)throw Error("useSwipeContext must be used within SwipeableViewContainer");return e}function d({activeView:e,onViewChange:t,children:r,onOverscroll:l}){let i=(0,s.useRef)(null),c=(0,s.useRef)(!1),u=(0,s.useRef)(0),m=(0,s.useRef)(0),x=(0,s.useRef)(null),h=(0,s.useRef)(null),f=(0,s.useRef)(0),p=(0,s.useRef)(l);(0,s.useEffect)(()=>{p.current=l},[l]);let[g,b]=(0,s.useState)(0),[v,j]=(0,s.useState)(!1),w=o.indexOf(e),k=o.length-1;(0,s.useEffect)(()=>{u.current=0,m.current=0,h.current=null,queueMicrotask(()=>b(0))},[e]),(0,s.useEffect)(()=>{let e=e=>{if(Math.abs(e.deltaX)>Math.abs(e.deltaY)&&Math.abs(e.deltaX)>2){var r,n,s;let l=e.target;if("IFRAME"===l.tagName)return;let a=performance.now(),d=(r=f.current,n=h.current,s=()=>(function(e){for(;e;){let t=window.getComputedStyle(e).overflowX;if(("auto"===t||"scroll"===t)&&e.scrollWidth-e.clientWidth>1)return!0;e=e.parentElement}return!1})(l),null!==n&&a-r<=180?n:s()?"inner":"switcher");if(h.current=d,f.current=a,"inner"===d)return;e.preventDefault(),e.stopPropagation(),c.current&&(c.current=!1);let g=window.innerWidth,v=u.current-6*e.deltaX,y=w>0,N=w<k,C=!1;!y&&v>0&&(m.current+=v,x.current=l,v=0,C=!0),!N&&v<0&&(m.current+=v,x.current=l,v=0,C=!0),C&&p.current?.({offset:m.current,phase:"move",triggered:!1,target:l}),u.current=v=Math.max(-g,Math.min(g,v)),b(v),j(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{let e=u.current,r=m.current,n=x.current;m.current=0,x.current=null;let s=.12*g;j(!1),c.current=!0;let l=w;e<-s&&w<k?l=w+1:e>s&&w>0&&(l=w-1),u.current=0,b(0),l!==w&&t(o[l]),l===w&&0!==r&&p.current?.({offset:r,phase:"release",triggered:Math.abs(r)>.2*g,target:n}),setTimeout(()=>{c.current=!1},80)},60)}};return document.addEventListener("wheel",e,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",e,{capture:!0})},[w,k,t]);let[y,N]=(0,s.useState)(!1);(0,s.useEffect)(()=>{queueMicrotask(()=>N(!0))},[]);let C={activeView:e,onViewChange:t,dragOffset:(()=>{if(!y)return 0;let e=window.innerWidth;return e?g/e:0})(),isDragging:y&&v};return(0,n.jsx)(a.Provider,{value:C,children:r})}function c({children:e}){let t,r,{activeView:l,dragOffset:a,isDragging:d}=i(),u=(0,s.useRef)(null),m=(0,s.useRef)(null),x=o.indexOf(l),h=o.length;return(0,s.useEffect)(()=>{let e=u.current;if(!e)return;let t=()=>{0!==e.scrollLeft&&(e.scrollLeft=0)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[]),(0,n.jsx)("div",{ref:u,className:"flex-1 overflow-hidden relative",style:{overscrollBehaviorX:"none"},children:(0,n.jsx)("div",{ref:m,className:d?"flex":"flex transition-transform duration-100 ease-out",style:{position:"absolute",top:"0px",bottom:"0px",left:"0px",width:`${100*o.length}%`,transform:(t=a/h*100,r=-(100/h*x)+(Number.isFinite(t)?t:0),`translateX(${r}%)`)},children:e})})}function u(){let{activeView:e,onViewChange:t,dragOffset:r,isDragging:a}=i(),d=(0,s.useRef)(null),c=(0,s.useRef)([]),[u,m]=(0,s.useState)({left:0,width:0}),x=o.indexOf(e),h=()=>{if(!d.current||0===c.current.length)return{left:0,width:0};let e=d.current.getBoundingClientRect(),t=c.current.filter(Boolean);if(t.length!==o.length)return{left:0,width:0};let n=Number.isFinite(r)?r:0,s=Math.max(0,Math.min(o.length-1,x-n)),l=Math.floor(s),a=Math.ceil(s),i=s-l,u=t[l],m=t[a];if(!u||!m)return{left:0,width:0};let h=u.getBoundingClientRect(),f=m.getBoundingClientRect();return{left:h.left+(f.left-h.left)*i-e.left,width:h.width+(f.width-h.width)*i}};(0,s.useEffect)(()=>{queueMicrotask(()=>m(h()))},[x,r]),(0,s.useEffect)(()=>{let e=()=>{m(h())};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[x,r]);let f=Number.isFinite(r)?r:0,p=Math.round(Math.max(0,Math.min(o.length-1,x-f)));return(0,n.jsxs)("div",{ref:d,className:"relative flex gap-4",children:[o.map((e,r)=>(0,n.jsx)("button",{ref:e=>{c.current[r]=e},onClick:()=>t(e),className:`px-4 py-1 text-sm font-medium transition-colors ${p===r?"text-brand":"text-muted-foreground hover:text-foreground"}`,children:l[e]},e)),(0,n.jsx)("div",{className:`absolute bottom-0 h-0.5 bg-brand ${a?"":"transition-all duration-100 ease-out"}`,style:{left:u.left,width:u.width}})]})}},66109:(e,t,r)=>{r.d(t,{aO:()=>n,iG:()=>s,jL:()=>o});let n="relative w-full max-w-[calc((100vw_-_28rem)*0.9)] h-[90vh] mx-4 bg-card rounded-lg shadow-lv3 flex flex-col overflow-hidden",s="relative w-full max-w-[calc((100vw_-_14rem)*0.9)] h-[90vh] mx-4 bg-card rounded-lg shadow-lv3 flex flex-col overflow-hidden",o="grid grid-cols-[repeat(auto-fill,minmax(320px,1fr))] gap-3"},71077:(e,t,r)=>{r.d(t,{AS:()=>y,HV:()=>j,If:()=>w,RS:()=>p,TN:()=>g,d$:()=>C,mO:()=>v,tr:()=>b});let n=null,s="",o=0,l=null,a=!1,i=new Map,d=null,c=null;function u(e){let t="https:"===window.location.protocol?"wss:":"ws:";return`${t}//${window.location.host}/ws/terminal?projectCwd=${encodeURIComponent(e)}`}function m(e){let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ping"===r)return;if("running"===r){d&&(d(t.commands),d=null);return}let n=t.commandId;if(!n)return;let s=i.get(n);if(s){if("error"===r)s.onError(t.error);else{let{commandId:e,type:n,...o}=t;s.onData(r,o)}("exit"===r||"error"===r)&&i.delete(n)}}function x(e){n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify(e))}function h(e){let t=u(e);s===t&&n||(y(),a=!1,s=t,function e(){if(a||!s)return;let t=new WebSocket(s);n=t,t.onopen=()=>{for(let e of(o=0,i.keys()))t.send(JSON.stringify({type:"attach",commandId:e}))},t.onmessage=m,t.onclose=()=>{if(n!==t||(n=null,a))return;l&&clearTimeout(l);let r=Math.min(1e3*Math.pow(1.5,o),1e4);o++,l=setTimeout(e,r)},t.onerror=()=>{}}())}function f(){return new Promise((e,t)=>{if(n?.readyState===WebSocket.OPEN)return void e();let r=setInterval(()=>{n?.readyState===WebSocket.OPEN&&(clearInterval(r),clearTimeout(s),e())},50),s=setTimeout(()=>{clearInterval(r),t(Error("WebSocket connection timeout"))},5e3)})}async function p(e){let{cwd:t,command:r,commandId:n,tabId:s,projectCwd:o,env:l,usePty:a,cols:d,rows:c,sourceId:u,onData:m,onError:p}=e;h(o);try{await f()}catch{p("WebSocket connection failed");return}i.delete(n),i.set(n,{onData:m,onError:p}),x({type:"exec",commandId:n,command:r,cwd:t,tabId:s,env:l,...a?{usePty:!0}:{},...d?{cols:d,rows:c}:{},...u?{sourceId:u}:{}})}async function g(e){let{commandId:t,projectCwd:r,onData:n,onError:s}=e;h(r);try{await f()}catch{s("WebSocket connection failed");return}i.set(t,{onData:n,onError:s}),x({type:"attach",commandId:t})}function b(e,t){x({type:"stdin",commandId:e,data:t})}function v(e,t,r){x({type:"resize",commandId:e,cols:t,rows:r})}function j(e){x({type:"interrupt",pid:e})}function w(e){return c||(c=k(e))}async function k(e){try{h(e);try{await f()}catch{return[]}return await new Promise(e=>{d=t=>{e(t)},x({type:"running"}),setTimeout(()=>{d&&(d=null,e([]))},3e3)})}finally{c=null}}function y(){if(a=!0,l&&(clearTimeout(l),l=null),n){let e=n;n=null,e.close()}i.clear(),d&&(d([]),d=null),c=null,s="",o=0}let N=/^(?:\x1b\[\??[\d;]*R|\x1b\[[?>][\d;]*c|\x1b\]\d+;[^\x07\x1b]*(?:\x07|\x1b\\))$/;function C(e){let{projectCwd:t,commandId:r,onOutput:n,onEnd:s,onAttached:o}=e,l=new WebSocket(u(t));return l.onopen=()=>l.send(JSON.stringify({type:"attach",commandId:r})),l.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.commandId===r)if("pid"===t.type){let e="number"==typeof t.cols&&"number"==typeof t.rows;o?.(e?{cols:t.cols,rows:t.rows}:void 0)}else"stdout"===t.type||"stderr"===t.type?n(String(t.data??"")):("exit"===t.type||"error"===t.type)&&s()},{close:()=>{l.onopen=null,l.onmessage=null,l.close()},sendInput:e=>{N.test(e)||l.readyState!==WebSocket.OPEN||l.send(JSON.stringify({type:"stdin",commandId:r,data:e}))}}}},72363:(e,t,r)=>{r.d(t,{$2:()=>j,N4:()=>c,_I:()=>v,fX:()=>u,fZ:()=>m});let n="cockpit update",s={visible:!1,stage:"preparing",startedAt:0,baselineMs:null,installedVersion:null,upToDate:!1,error:null,rolledBack:!1,fixCommand:n,logPath:null,live:!1},o="cockpit:update-seen-at",l=s,a=new Set,i=!1;function d(e){l={...l,...e},a.forEach(e=>e())}function c(e){return a.add(e),()=>a.delete(e)}function u(){return l}function m(){try{window.localStorage.setItem(o,String(Date.now()))}catch{}d({visible:!1})}let x=e=>new Promise(t=>setTimeout(t,e));async function h(){try{let e=await fetch("/api/health",{cache:"no-store",signal:AbortSignal.timeout(2e3)});if(!e.ok)return null;let t=await e.json();return{pid:"number"==typeof t.pid?t.pid:null,version:t.version??null}}catch{return null}}async function f(){try{let e=await fetch("/api/update-state",{cache:"no-store",signal:AbortSignal.timeout(2e3)});if(!e.ok)return{state:null,logPath:null};let t=await e.json();return{state:t.state??null,logPath:t.logPath??null}}catch{return{state:null,logPath:null}}}async function p(e){try{let t=await fetch(`http://127.0.0.1:${e}/`,{cache:"no-store",signal:AbortSignal.timeout(1500)});if(!t.ok)return null;return await t.json()}catch{return null}}function g(e){switch(e){case"installing":return"installing";case"repairing":return"repairing";case"rolling-back":return"rolling-back";case"restarting":case"done":return"restarting";default:return"preparing"}}function b(e,t={}){d({stage:"failed",error:e,...t})}async function v(){if(!i){i=!0,d({...s,visible:!0,stage:"preparing",startedAt:Date.now()});try{let e=await f();d({baselineMs:e.state?.installMs??e.state?.prevInstallMs??null,logPath:e.logPath});let t=await h(),r=t?.pid??null,s=t?.version??null,o=await fetch("/api/update",{method:"POST"});if(!o.ok){let e=await o.json().catch(()=>({}));b(e.error??`HTTP ${o.status}`);return}let a=await o.json().catch(()=>({})),i=a.statusPort??null;d({logPath:a.logPath??l.logPath});let c=0,u=null!==i,m=Date.now()+3e5;for(;Date.now()<m;){if(await x(1e3),u&&null!==i){let e=await p(i);if(e){if(c=0,d({live:!0}),"failed"===e.phase)return void b(e.error??"install failed",{rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n,live:!0});d({stage:g(e.phase),installedVersion:e.installed??l.installedVersion,baselineMs:l.baselineMs??e.prevInstallMs??null})}else++c>=3&&(u=!1,d({live:!1}))}let e=await h();if(e?.pid!=null&&(null===r||e.pid!==r)){let{state:t}=await f();if(t?.phase==="failed")return void b(t.error??"update failed",{rolledBack:!0===t.rolledBack,fixCommand:t.fixCommand??n});let r=e.version??l.installedVersion;d({stage:"done",installedVersion:r,upToDate:null!==r&&r===s});return}}b("timeout")}catch(e){b(e instanceof Error?e.message:String(e))}finally{i=!1}}}async function j(){if(i||l.visible)return;let{state:e,logPath:t}=await f();if(!e?.phase||"done"===e.phase)return;let r=e.startedAt??0,a=e.installMs??e.prevInstallMs??null;if("failed"===e.phase){let l=0;try{l=Number(window.localStorage.getItem(o))||0}catch{}if((e.finishedAt??0)<=l)return;d({...s,visible:!0,stage:"failed",startedAt:r,baselineMs:a,error:e.error??"unknown error",rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n,logPath:t});return}if(!(!r||Date.now()-r>6e5)){i=!0,d({...s,visible:!0,stage:g(e.phase),startedAt:r,baselineMs:a,logPath:t});try{let e=r+3e5;for(;Date.now()<e;){await x(1e3);let{state:e}=await f();if(e?.phase){if("failed"===e.phase)return void b(e.error??"install failed",{rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n});if("done"===e.phase)return void d({stage:"done",installedVersion:e.installed??null,upToDate:!0===e.unchanged});d({stage:g(e.phase)})}}b("timeout")}finally{i=!1}}}},76043:(e,t,r)=>{r.d(t,{NoteToolbar:()=>a});var n=r(95155),s=r(12115),o=r(79114);function l({editor:e,onClose:t,position:r}){let{t:a}=(0,o.Bd)(),[i,d]=(0,s.useState)(()=>e.getAttributes("link").href||""),c=(0,s.useRef)(null);(0,s.useEffect)(()=>{c.current?.focus()},[]);let u=()=>{let r=i.trim();if(r){let t=r.match(/^https?:\/\//)?r:`https://${r}`;e.chain().focus().extendMarkRange("link").setLink({href:t}).run()}else e.chain().focus().extendMarkRange("link").unsetLink().run();t()},m=r?{top:r.top,left:r.left}:{};return(0,n.jsxs)("div",{className:`${r?"fixed":"absolute top-full left-0 mt-1"} z-[60] bg-popover border border-border rounded-lg shadow-lv2 p-2 flex items-center gap-2`,style:m,children:[(0,n.jsx)("input",{ref:c,type:"text",value:i,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),u()):"Escape"===e.key&&(e.preventDefault(),t())},placeholder:a("editor.linkPlaceholder"),className:"bg-background border border-border rounded px-2 py-1 text-sm w-64 outline-none focus:border-brand"}),(0,n.jsx)("button",{onClick:u,className:"p-1 rounded text-sm font-medium text-brand hover:bg-brand/10 transition-colors",title:a("editor.confirmLink"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})})}),e.isActive("link")&&(0,n.jsx)("button",{onClick:()=>{e.chain().focus().extendMarkRange("link").unsetLink().run(),t()},className:"p-1 rounded text-sm font-medium text-red-11 hover:bg-red-500/10 transition-colors",title:a("editor.removeLink"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]})}function a({editor:e}){let{t}=(0,o.Bd)(),[r,i]=(0,s.useState)(!1),d=(0,s.useRef)(null),[,c]=(0,s.useState)(0);if((0,s.useEffect)(()=>{if(!e)return;let t=()=>c(e=>e+1);return e.on("selectionUpdate",t),e.on("transaction",t),()=>{e.off("selectionUpdate",t),e.off("transaction",t)}},[e]),(0,s.useEffect)(()=>{let e=()=>i(!0);return window.addEventListener("tiptap-insert-link",e),()=>window.removeEventListener("tiptap-insert-link",e)},[]),!e)return null;let u=e=>`p-1.5 rounded text-xs font-medium transition-colors ${e?"bg-brand/15 text-brand":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,m="w-px h-5 bg-border mx-0.5",x=e.isActive("table");return(0,n.jsxs)("div",{className:"flex items-center gap-0.5 px-4 py-1.5 border-b border-border flex-shrink-0 flex-wrap",children:[(0,n.jsx)("button",{className:u(e.isActive("heading",{level:1})),onClick:()=>e.chain().focus().toggleHeading({level:1}).run(),title:t("editor.heading1"),children:"H1"}),(0,n.jsx)("button",{className:u(e.isActive("heading",{level:2})),onClick:()=>e.chain().focus().toggleHeading({level:2}).run(),title:t("editor.heading2"),children:"H2"}),(0,n.jsx)("button",{className:u(e.isActive("heading",{level:3})),onClick:()=>e.chain().focus().toggleHeading({level:3}).run(),title:t("editor.heading3"),children:"H3"}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("bold")),onClick:()=>e.chain().focus().toggleBold().run(),title:t("editor.bold"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z"})})}),(0,n.jsx)("button",{className:u(e.isActive("italic")),onClick:()=>e.chain().focus().toggleItalic().run(),title:t("editor.italic"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z"})})}),(0,n.jsx)("button",{className:u(e.isActive("strike")),onClick:()=>e.chain().focus().toggleStrike().run(),title:t("editor.strikethrough"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z"})})}),(0,n.jsx)("button",{className:u(e.isActive("code")),onClick:()=>e.chain().focus().toggleCode().run(),title:t("editor.inlineCode"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"})})}),(0,n.jsx)("div",{className:m}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{ref:d,className:u(e.isActive("link")),onClick:()=>i(!r),title:t("editor.link"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})})}),r&&(0,n.jsx)(l,{editor:e,onClose:()=>i(!1),position:null})]}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("bulletList")),onClick:()=>e.chain().focus().toggleBulletList().run(),title:t("editor.bulletList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z"})})}),(0,n.jsx)("button",{className:u(e.isActive("orderedList")),onClick:()=>e.chain().focus().toggleOrderedList().run(),title:t("editor.orderedList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M2 17h2v.5H3v1h1v.5H2v1h3v-4H2v1zm1-9h1V4H2v1h1v3zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2v1zm5-6v2h14V5H7zm0 14h14v-2H7v2zm0-6h14v-2H7v2z"})})}),(0,n.jsx)("button",{className:u(e.isActive("taskList")),onClick:()=>e.chain().focus().toggleTaskList().run(),title:t("editor.taskList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14zM17.99 9l-1.41-1.42-6.59 6.59-2.58-2.57-1.42 1.41 4 3.99z"})})}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("blockquote")),onClick:()=>e.chain().focus().toggleBlockquote().run(),title:t("editor.blockquote"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z"})})}),(0,n.jsx)("button",{className:u(e.isActive("codeBlock")),onClick:()=>e.chain().focus().toggleCodeBlock().run(),title:t("editor.codeBlock"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M20 3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H4V5h16v14zm-7.5-4.5L15 12l-2.5-2.5L11 11l1.5 1.5L11 14l1.5 1.5zM9.5 14.5L7 12l2.5-2.5L11 11 9.5 12.5 11 14l-1.5.5z"})})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),title:t("editor.table"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M20 2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-9 15H4v-4h7v4zm0-6H4V7h7v4zm9 6h-7v-4h7v4zm0-6h-7V7h7v4z"})})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().setHorizontalRule().run(),title:t("editor.horizontalRule"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4 11h16v2H4z"})})}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addRowBefore().run(),title:t("editor.insertRowAbove"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v2h20V6c0-1.1-.9-2-2-2zm0 6H2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V10zM11 17H4v-2h7v2zm0-4H4v-2h7v2zm9 4h-7v-2h7v2zm0-4h-7v-2h7v2z"}),(0,n.jsx)("path",{d:"M14 1h-4v2H8v2h2v2h4V5h2V3h-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addRowAfter().run(),title:t("editor.insertRowBelow"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v10h20V6c0-1.1-.9-2-2-2zM11 12H4v-2h7v2zm0-4H4V6h7v2zm9 4h-7v-2h7v2zm0-4h-7V6h7v2z"}),(0,n.jsx)("path",{d:"M14 19h-4v2H8v2h2v-2h4v2h2v-2h-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addColumnBefore().run(),title:t("editor.insertColumnLeft"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M6 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h2V4H6zm4 0v20h10c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2H10zm7 11H10v-2h7v2zm0-4H10V9h7v2z"}),(0,n.jsx)("path",{d:"M1 14v-4h2V8h2v2h-2v4h2v2H3v-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addColumnAfter().run(),title:t("editor.insertColumnRight"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M4 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h10V4H4zm7 11H4v-2h7v2zm0-4H4V9h7v2z"}),(0,n.jsx)("path",{d:"M18 4v20h2c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-2z"}),(0,n.jsx)("path",{d:"M21 14v-4h2V8h2v2h-2v4h2v2h-2v-2z",opacity:".6"})]})}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-orange-11 hover:bg-orange-500/10",onClick:()=>e.chain().focus().deleteRow().run(),title:t("editor.deleteRow"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v2h20V6c0-1.1-.9-2-2-2zm0 6H2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V10zm-8 8H4v-2h8v2z"}),(0,n.jsx)("path",{d:"M15 13l-1.41 1.41L15.17 16l-1.58 1.59L15 19l1.59-1.59L18.17 19l1.42-1.41L18 16l1.59-1.59L18.17 13 16.59 14.41z",fill:"currentColor"})]})}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-orange-11 hover:bg-orange-500/10",onClick:()=>e.chain().focus().deleteColumn().run(),title:t("editor.deleteColumn"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M6 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h2V4H6zm4 0v20h10c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2H10zm7 7H10V9h7v2z"}),(0,n.jsx)("path",{d:"M13 16l-1.41 1.41L13.17 19l-1.58 1.59L13 22l1.59-1.59L16.17 22l1.42-1.41L16 19l1.59-1.59L16.17 16l-1.58 1.41z",fill:"currentColor"})]})}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-red-11 hover:bg-red-500/10",onClick:()=>e.chain().focus().deleteTable().run(),title:t("editor.deleteTable"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]}),e.isActive("codeBlock")&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-red-11 hover:bg-red-500/10",onClick:()=>e.chain().focus().toggleCodeBlock().run(),title:t("editor.deleteCodeBlock"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]})]})}},76288:(e,t,r)=>{r.d(t,{EmptyState:()=>o});var n=r(95155),s=r(79114);function o({onBrowseProjects:e}){let{t}=(0,s.Bd)();return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-5 bg-card",children:[(0,n.jsx)("svg",{className:"w-14 h-14 text-muted-foreground/40",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V7z"})}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground",children:t("workspace.selectProject")}),(0,n.jsxs)("button",{onClick:e,className:"flex items-center gap-2 px-4 py-2 text-sm rounded-lg bg-primary text-primary-foreground hover:opacity-90 transition-opacity",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m3-3H9m-4 7h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),t("workspace.openProject")]})]})}},76900:(e,t,r)=>{r.d(t,{Bt:()=>p,Cq:()=>j,D0:()=>y,DZ:()=>d,GS:()=>u,H7:()=>w,IG:()=>f,Kl:()=>E,M5:()=>i,O2:()=>c,Or:()=>x,Q1:()=>M,QW:()=>k,Wr:()=>m,Yn:()=>N,b2:()=>L,em:()=>S,fz:()=>C,zF:()=>b,zv:()=>v});var n=r(49433),s=r(82680),o=r(84230);let l=(e,t)=>n.$mh({try:async()=>{let r=await fetch(e,t);if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()},catch:r=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:r})}),a=(e,t)=>l(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),i=()=>(0,o.F)("/api/settings",l("/api/settings")),d=e=>l("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).pipe(n.yeE(n.OH5(()=>(0,o.T)("/api/settings")))),c=()=>l("/api/mobile-link",{cache:"no-store"}).pipe(n.TjK(e=>e.token??null)),u=e=>n.$mh({try:async()=>(await r.e(768).then(r.t.bind(r,768,19))).toString(e,{type:"svg",margin:1,errorCorrectionLevel:"M"}),catch:e=>new s.uV({message:"QR code generation failed",cause:e})}),m=()=>l("/api/version"),x=()=>l("/api/extension/version"),h=e=>l(e,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"}),f=()=>h("/api/browser/extensions").pipe(n.TjK(e=>e.data??[])),p=()=>h("/api/browser/extension_reload"),g=e=>e?`/api/note?cwd=${encodeURIComponent(e)}`:"/api/note",b=e=>l(g(e)),v=()=>l("/api/note/list").pipe(n.TjK(e=>e.notes??[])),j=(e,t,r)=>n.$mh({try:async()=>{let n=g(e),s=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,baseMtime:r})});if(409===s.status){let e=await s.json();return{conflict:!0,content:e.content??"",mtime:e.mtime}}if(!s.ok)throw Error(`HTTP ${s.status}`);return{conflict:!1,mtime:(await s.json()).mtime}},catch:t=>new s.uV({message:`POST ${g(e)} failed`,cause:t})}),w=()=>l("/api/sessions/projects"),k=e=>l(`/api/sessions/projects/${encodeURIComponent(e)}`),y=e=>l(`/api/project-settings?cwd=${encodeURIComponent(e)}`),N=e=>a("/api/project-settings",e),C=e=>l(`/api/fs/dirs?path=${encodeURIComponent(e)}`),S=e=>a("/api/open-vscode",{cwd:e}),M=e=>a("/api/open-cursor",{cwd:e}),L=e=>l(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),E=e=>a("/api/git/worktree",e)},80039:(e,t,r)=>{r.d(t,{Workspace:()=>ev});var n=r(95155),s=r(12115),o=r(79114),l=r(13886),a=r(76288),i=r(52153),d=r(21484),c=r(34075),u=r(66109),m=r(61878),x=r(33210),h=r(51914),f=r(20986),p=r(24371),g=r(42804),b=r(22164),v=r(42129),j=r(68459),w=r(94852),k=r(67635),y=r(60241),N=r(95045),C=r(75346),S=r(86957),M=r(34582),L=r(85269),E=r(99161),P=r(63563),T=r(63040);function $({isOpen:e,htmlAppPreviews:t,activeHtmlAppPreviewPath:r,onShowHtmlAppPreview:l,onMinimizeHtmlAppPreview:a,onCloseHtmlAppPreview:i,onClose:d,onOpenApp:I}){let F,B,D,{t:A,i18n:H}=(0,o.Bd)(),[O,W]=(0,s.useState)([]),[_,z]=(0,s.useState)(!1),[q,V]=(0,s.useState)(""),[U,K]=(0,s.useState)(!1),[Q,G]=(0,s.useState)(""),[J,Y]=(0,s.useState)(!1),[X,Z]=(0,s.useState)({}),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)(0),[es,eo]=(0,s.useState)("files"),[el,ea]=(0,s.useState)(null),ei=(0,s.useRef)(null),ed=(0,s.useCallback)(async()=>{z(!0);let e=await S.t4.runPromiseExit((0,T.mi)());"Success"===e._tag?W(e.value):console.error("Failed to load html apps",e.cause),z(!1)},[]);(0,s.useEffect)(()=>{e&&(ed(),setTimeout(()=>{ei.current?.focus(),ei.current?.select()},100))},[e,ed]);let ec=(0,s.useCallback)(()=>{K(!1),et(null),ea(null),d()},[d]);(0,s.useEffect)(()=>{if(!e&&!r)return;let t=e=>{if("Escape"===e.key){if(r)return void i(r);if(U){K(!1),G("");return}ec()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,r,ec,i,U]);let eu=(0,s.useMemo)(()=>{let e=q.trim().toLowerCase();return e?O.filter(t=>t.name.toLowerCase().includes(e)||t.title.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):O},[O,q]),em=(0,s.useMemo)(()=>[{key:"mine",labelKey:"htmlApps.mine",items:eu.filter(e=>!e.builtin)},{key:"builtin",labelKey:"htmlApps.builtin",items:eu.filter(e=>e.builtin)}].filter(e=>e.items.length>0),[eu]),ex=ee?O.find(e=>e.id===ee)??null:null,eh=em[0]?.items[0]?.id??null;(0,s.useEffect)(()=>{e&&!ex&&eh&&(et(eh),eo("files"))},[e,ex,eh]);let ef=(0,s.useMemo)(()=>O.filter(e=>!e.builtin).length,[O]),ep=q.trim().length>0,eg=H.resolvedLanguage?.startsWith("zh")?"https://opencockpit.dev/zh/docs/agent/html-apps/":"https://opencockpit.dev/en/docs/agent/html-apps/",eb=(0,s.useCallback)(async()=>{let e=Q.trim();if(!e)return;Y(!0);let t=await S.t4.runPromiseExit((0,T.ot)(e));if("Success"===t._tag)t.value.alreadyExists?(0,c.oR)(A("htmlApps.alreadyAdded"),"info"):((0,c.oR)(A("htmlApps.added"),"success"),(0,P.N)()),G(""),K(!1),await ed();else{let e="Fail"===t.cause._tag?t.cause.error:null,r=e?.cause,n=r instanceof Error?r.message:A("htmlApps.addFailed");(0,c.oR)(n,"error")}Y(!1)},[Q,ed,A]),ev=(0,s.useCallback)(async e=>{"Success"===(await S.t4.runPromiseExit((0,T.m3)(e)))._tag?(W(t=>t.filter(t=>t.id!==e)),et(t=>t===e?null:t),(0,P.N)()):(0,c.oR)(A("common.deleteFailed"),"error")},[A]),ej=(0,s.useCallback)(e=>{I?I(e):window.dispatchEvent(new CustomEvent("console-open-browser",{detail:{url:e}})),ec()},[ec,I]),ew=(0,s.useCallback)(e=>{I?I(e):window.dispatchEvent(new CustomEvent("console-open-browser",{detail:{url:e}})),a()},[a,I]),ek=(0,s.useCallback)(e=>{let t=(0,M.Xe)(e);window.open((0,M.PB)(t,window.location.origin),"_blank")},[]),ey=(0,s.useCallback)(e=>{Z(t=>({...t,[e]:(t[e]||0)+1}))},[]),eN=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,c.oR)(A("common.copiedPath"),"success")}catch{(0,c.oR)(A("common.copyFailed"),"error")}},[A]);return(0,n.jsxs)(n.Fragment,{children:[e&&(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:ec}),(0,n.jsxs)("div",{className:u.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:A("htmlApps.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(m.A,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-foreground-subtle pointer-events-none"}),(0,n.jsx)("input",{ref:ei,type:"text",value:q,onChange:e=>V(e.target.value),placeholder:A("htmlApps.searchPlaceholder"),className:"pl-7 pr-6 py-1 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),q&&(0,n.jsx)("button",{onClick:()=>{V(""),ei.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:A("fileBrowser.clear"),children:(0,n.jsx)(x.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("button",{onClick:()=>K(!0),className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:A("htmlApps.addHtmlApp"),children:[(0,n.jsx)(h.A,{className:"w-4 h-4"})," ",A("htmlApps.add")]}),(0,n.jsx)("button",{onClick:ec,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",title:A("common.close"),children:(0,n.jsx)(x.A,{className:"w-5 h-5"})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsx)("div",{className:"w-full md:w-[300px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:_&&0===O.length?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:A("common.loading")}):(0,n.jsxs)("div",{className:"p-3 space-y-3",children:[em.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center",children:[(0,n.jsx)("span",{children:A(e.labelKey)}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(e=>(0,n.jsx)(R,{app:e,selected:e.id===ee,onSelect:()=>{et(e.id),ea(null),en(0),eo("files")}},e.id))})]},e.key)),0===eu.length&&ep&&(0,n.jsx)("div",{className:"text-center text-muted-foreground py-6 text-xs",children:A("htmlApps.emptyNoMatch")}),!ep&&0===ef&&(0,n.jsxs)("div",{className:"text-center text-muted-foreground py-4 text-xs space-y-2",children:[(0,n.jsx)("p",{children:A("htmlApps.emptyNoApps")}),(0,n.jsxs)("p",{children:[A("htmlApps.emptyCreatePrefix")," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-foreground font-mono text-xs",children:"/html"})," ",A("htmlApps.emptyCreateSuffix")]}),(0,n.jsxs)("p",{children:[(0,n.jsx)("button",{type:"button",onClick:()=>K(!0),className:"text-brand hover:underline",children:A("htmlApps.addExisting")})," \xb7 ",(0,n.jsx)("a",{href:eg,target:"_blank",rel:"noreferrer",className:"text-brand hover:underline",children:A("htmlApps.viewDocs")})]})]})]})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0 flex-col",children:ex?(F=(e,t)=>(0,n.jsx)("button",{onClick:()=>eo(e),disabled:"run"===e&&!ex.valid,className:`px-3 py-1 transition-colors disabled:opacity-40 ${es===e?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:t}),B=(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-xs mr-1",children:[F("files",A("htmlApps.tabFiles")),F("run",A("htmlApps.tabRun"))]}),ex.valid&&(0,n.jsxs)(n.Fragment,{children:["run"===es&&(0,n.jsx)("button",{onClick:()=>en(e=>e+1),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded","data-tooltip":A("common.refresh"),"aria-label":A("common.refresh"),children:(0,n.jsx)(f.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>{l({path:ex.path,title:ex.title,icon:ex.icon}),ec()},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded","data-tooltip":A("htmlApps.openFull"),"aria-label":A("htmlApps.openFull"),children:(0,n.jsx)(p.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>ej(ex.path),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded","data-tooltip":A("common.openInConsole"),"aria-label":A("common.openInConsole"),children:(0,n.jsx)(g.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>ek(ex.path),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded","data-tooltip":A("browser.openInNewWindow"),"aria-label":A("browser.openInNewWindow"),children:(0,n.jsx)(b.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("button",{onClick:()=>{let e=ex.path.split("/");(0,N.F)(C.n.OpenProject,{cwd:e.slice(0,-1).join("/"),file:e[e.length-1]}),ec()},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded","data-tooltip":A("common.openAsProject"),"aria-label":A("common.openAsProject"),children:(0,n.jsx)(v.A,{className:"w-4 h-4"})}),ex.builtin?null:el===ex.id?(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>{ea(null),ev(ex.id)},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:A("common.confirm")}),(0,n.jsx)("button",{onClick:()=>ea(null),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:A("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>ea(ex.id),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded","data-tooltip":A("common.delete"),"aria-label":A("common.delete"),children:(0,n.jsx)(j.A,{className:"w-4 h-4"})})]}),D=(0,n.jsxs)("span",{className:"flex items-center gap-2 min-w-0",children:[ex.icon?(0,n.jsx)("span",{className:"text-base leading-none flex-shrink-0",children:ex.icon}):(0,n.jsx)(w.A,{className:"w-4 h-4 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:ex.title})]}),"files"===es?(0,n.jsx)(E.g,{endpoint:"/api/html-apps/files",id:ex.id,entryFile:ex.path.split("/").pop()||"index.html",title:D,actions:B},ex.id):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:D}),(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0 mt-0.5",children:[(0,n.jsx)("span",{className:"font-mono text-xs text-muted-foreground truncate","data-tooltip":ex.path,children:ex.path}),(0,n.jsx)("button",{onClick:()=>eN(ex.path),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded flex-shrink-0",title:A("common.copyPath"),"aria-label":A("common.copyPath"),children:(0,n.jsx)(k.A,{className:"w-3.5 h-3.5"})})]})]}),B]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,n.jsx)(L.O,{filePath:ex.path,reloadKey:er},ex.id)})]})):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground px-6 text-center",children:A("htmlApps.selectHint")})})]})]})]}),e&&U&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:()=>{J||(K(!1),G(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:A("htmlApps.addHtmlApp")}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:A("htmlApps.pathLabel")}),(0,n.jsx)("input",{type:"text",value:Q,onChange:e=>G(e.target.value),onKeyDown:e=>{"Enter"!==e.key||J||eb()},placeholder:"/Users/you/.../report.html",autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-4",children:[(0,n.jsx)("button",{onClick:()=>{K(!1),G("")},disabled:J,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors disabled:opacity-50",children:A("common.cancel")}),(0,n.jsx)("button",{onClick:eb,disabled:J||!Q.trim(),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 transition-colors disabled:opacity-50",children:J?A("htmlApps.adding"):A("htmlApps.add")})]})]})]}),t.map(e=>{let t=r===e.path;return(0,n.jsx)("div",{className:t?"fixed inset-0 z-[60] flex items-center justify-center bg-scrim p-0 md:p-4":"hidden",onClick:a,children:(0,n.jsxs)("div",{className:"bg-card shadow-lv3 border border-brand/30 w-full h-full md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.icon?(0,n.jsx)("span",{className:"text-base leading-none flex-shrink-0",children:e.icon}):(0,n.jsx)(w.A,{className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate max-w-[35%]","data-tooltip":e.title,children:e.title}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground flex-shrink-0","aria-hidden":"true",children:"-"}),(0,n.jsx)("span",{className:"font-mono text-sm text-muted-foreground truncate min-w-0","data-tooltip":e.path,children:e.path}),(0,n.jsx)("button",{onClick:()=>eN(e.path),className:"text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:A("common.copyPath"),"aria-label":A("common.copyPath"),children:(0,n.jsx)(k.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("button",{onClick:a,className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:A("common.minimize"),children:(0,n.jsx)(y.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>ew(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:A("common.openInConsole"),children:(0,n.jsx)(g.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>ek(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:A("browser.openInNewWindow"),children:(0,n.jsx)(b.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>ey(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:A("common.refresh"),children:(0,n.jsx)(f.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>i(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsx)(x.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,n.jsx)(L.O,{filePath:e.path,reloadKey:X[e.path]||0})})]})},e.path)})]})}function R({app:e,selected:t,onSelect:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{onClick:r,className:`rounded-md px-2 py-2 cursor-pointer transition-colors ${t?"bg-brand/10":"hover:bg-hover"} ${e.valid?"":"opacity-60"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"w-5 h-5 flex-shrink-0 flex items-center justify-center rounded bg-brand/10 text-brand text-xs",children:e.icon?(0,n.jsx)("span",{children:e.icon}):(0,n.jsx)(w.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"text-xs font-medium text-foreground truncate min-w-0","data-tooltip":e.title,children:e.title}),(0,n.jsxs)("span",{className:"font-mono text-[10px] text-muted-foreground truncate flex-1 min-w-0","data-tooltip":e.path,children:["/",e.name]}),!e.valid&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded bg-red-9/15 text-red-11",children:s("htmlApps.invalid")})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-7","data-tooltip":e.description||void 0,children:e.description||(0,n.jsx)("span",{className:"italic opacity-60",children:s("htmlApps.noDescription")})})]})}var I=r(3238),F=r(62111),B=r(83448),D=r(53317);let A={"claude-fable-5-1":{input:10,output:50,cacheRead:.25,cacheWrite:12.5},"claude-mythos-5-1":{input:10,output:50,cacheRead:.25,cacheWrite:12.5},"claude-fable-5":{input:10,output:50,cacheRead:1,cacheWrite:12.5},"claude-mythos-5":{input:10,output:50,cacheRead:1,cacheWrite:12.5},"claude-opus-5-5":{input:4,output:20,cacheRead:.2,cacheWrite:5},"claude-opus-5":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-8":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-7":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-6":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-5":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-sonnet-5-5":{input:2,output:10,cacheRead:.2,cacheWrite:2.5},"claude-sonnet-5":{input:2,output:10,cacheRead:.2,cacheWrite:2.5},"claude-sonnet-4-6":{input:3,output:15,cacheRead:.3,cacheWrite:3.75},"claude-sonnet-4-5":{input:3,output:15,cacheRead:.3,cacheWrite:3.75},"claude-haiku-5-5":{input:.1,output:.5,cacheRead:.01,cacheWrite:.125},"claude-haiku-4-5":{input:1,output:5,cacheRead:.1,cacheWrite:1.25}},H={input:3,output:15,cacheRead:.3,cacheWrite:3.75},O={light:["#2a78d6","#eb6834","#1baf7a","#eda100","#e87ba4","#008300","#4a3aa7","#e34948"],dark:["#3987e5","#d95926","#199e70","#c98500","#d55181","#008300","#9085e9","#e66767"]},W={light:{messages:"#2a78d6",toolCalls:"#1baf7a",messagesRgb:"42, 120, 214"},dark:{messages:"#3987e5",toolCalls:"#199e70",messagesRgb:"57, 135, 229"}};function _(e){return e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function z(e){return e>=1e3?`$${e.toFixed(0)}`:e>=100?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function q({data:e,height:t=200,formatValue:r=_}){let o=(0,s.useRef)(null),l=(0,s.useRef)(null),[a,i]=(0,s.useState)(null),d=(0,s.useRef)([]),c=(0,s.useCallback)(()=>{let n=o.current,s=l.current;if(!n||!s)return;let a=window.devicePixelRatio||1,i=s.getBoundingClientRect().width;n.width=i*a,n.height=t*a,n.style.width=`${i}px`,n.style.height=`${t}px`;let c=n.getContext("2d");c.scale(a,a),c.clearRect(0,0,i,t);let{labels:u,datasets:m}=e;if(0===u.length)return;let x=i-50-12,h=t-8-28,f=function(e){if(e<=0)return 1;let t=Math.pow(10,Math.floor(Math.log10(e))),r=e/t;return r<=1?t:r<=2?2*t:r<=5?5*t:10*t}(Math.max(1,...u.map((e,t)=>m.reduce((e,r)=>e+r.data[t],0))));c.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",c.font="10px ui-monospace, monospace",c.textAlign="right",c.textBaseline="middle";for(let e=0;e<=4;e++){var p;let t=f/4*e,s=8+h-t/f*h;c.fillText(r(t),44,s),c.strokeStyle=(p="--line-2",getComputedStyle(n).getPropertyValue(p).trim()||"#333"),c.lineWidth=.5,c.beginPath(),c.moveTo(50,s),c.lineTo(50+x,s),c.stroke()}let g=x/u.length,b=Math.max(4,Math.min(.6*g,32)),v=[];u.forEach((e,t)=>{let r=50+t*g+(g-b)/2,s=0;m.forEach(n=>{var o,l,a,i,d,u;let m=n.data[t];if(m<=0)return;let x=Math.max(1,m/f*h),p=8+h-s-x;c.fillStyle=n.color,o=c,l=r,a=p,i=b,u=2,(d=x)<1||(u=Math.min(u,d/2,i/2),o.beginPath(),o.moveTo(l+u,a),o.lineTo(l+i-u,a),o.quadraticCurveTo(l+i,a,l+i,a+u),o.lineTo(l+i,a+d-u),o.quadraticCurveTo(l+i,a+d,l+i-u,a+d),o.lineTo(l+u,a+d),o.quadraticCurveTo(l,a+d,l,a+d-u),o.lineTo(l,a+u),o.quadraticCurveTo(l,a,l+u,a),o.fill()),v.push({x:r,y:p,w:b,h:x,label:e,value:m,dataset:n.label,color:n.color}),s+=x}),c.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",c.font="9px ui-monospace, monospace",c.textAlign="center",c.textBaseline="top",t%(u.length>20?Math.ceil(u.length/15):1)==0&&c.fillText(e,r+b/2,8+h+6)}),d.current=v},[e,t,r]);(0,s.useEffect)(()=>{c();let e=new ResizeObserver(()=>c());return l.current&&e.observe(l.current),()=>e.disconnect()},[c]);let u=(0,s.useCallback)(e=>{let t=o.current?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left,s=e.clientY-t.top,l=d.current.find(e=>n>=e.x&&n<=e.x+e.w&&s>=e.y&&s<=e.y+e.h);l?i({x:e.clientX-t.left,y:l.y-4,content:`${l.dataset}: ${r(l.value)}`}):i(null)},[r]);return(0,n.jsxs)("div",{ref:l,className:"relative w-full text-muted-foreground",children:[(0,n.jsx)("canvas",{ref:o,className:"w-full",style:{height:t},onMouseMove:u,onMouseLeave:()=>i(null)}),a&&(0,n.jsx)("div",{className:"absolute pointer-events-none bg-popover text-popover-foreground text-[10px] px-2 py-1 rounded shadow-lv2 border border-border whitespace-nowrap z-10",style:{left:a.x,top:a.y,transform:"translate(-50%, -100%)"},children:a.content})]})}function V({hourCounts:e}){let{t}=(0,o.Bd)(),{resolvedTheme:r}=(0,I.DP)(),s=W[r],l=Math.max(1,...Object.values(e)),a=Array.from({length:24},(e,t)=>t);return(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:t("tokenStats.activeHours")}),(0,n.jsx)("div",{className:"flex gap-[2px] items-end h-16",children:a.map(r=>{let o=e[String(r)]||0,a=o/l;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-0.5",title:t("tokenStats.hourSessions",{h:r,count:o}),children:[(0,n.jsx)("div",{className:"w-full rounded-sm transition-all",style:{height:`${Math.max(2,48*a)}px`,backgroundColor:a>0?`rgba(${s.messagesRgb}, ${.2+.8*a})`:"var(--muted)"}}),r%3==0&&(0,n.jsx)("span",{className:"text-[8px] text-muted-foreground",children:r})]},r)})})]})}function U({isOpen:e,onClose:t}){var r;let l,a,{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(!0),[x,h]=(0,s.useState)("day"),[f,p]=(0,s.useState)("tokens"),[g,b]=(0,s.useState)(null),{resolvedTheme:v}=(0,I.DP)();(0,s.useEffect)(()=>{e&&(queueMicrotask(()=>m(!0)),S.t4.runPromiseExit((0,B.Cr)()).then(e=>{if("Success"===e._tag){let t=e.value;t.error||queueMicrotask(()=>c(t))}queueMicrotask(()=>m(!1))}))},[e]);let j=(0,s.useMemo)(()=>{var e;let t,r,n=Object.keys(d?.modelUsage||{}).filter(e=>!e.startsWith("<")),s=new Map;for(let e of d?.dailyModelTokens||[])for(let[t,r]of Object.entries(e.tokensByModel)){let n=s.get(t);r>0&&(!n||e.date<n)&&s.set(t,e.date)}return e=[...n].sort((e,t)=>(s.get(e)??"￿").localeCompare(s.get(t)??"￿")||e.localeCompare(t)),t=O[v],r={},e.forEach((e,n)=>{r[e]=t[n%t.length]}),r},[d,v]),w=(0,s.useMemo)(()=>d?.modelUsage?Object.entries(d.modelUsage).filter(([e])=>!e.startsWith("<")).map(([e,t])=>{let r;return{id:e,label:(0,D.J)(e),color:j[e],usage:t,cost:(r=function(e){let t=e.replace(/-\d{8}$/,""),r=A[t];if(r)return r;let n=t.toLowerCase();return n.includes("fable")||n.includes("mythos")?{input:10,output:50,cacheRead:1,cacheWrite:12.5}:n.includes("opus")?{input:5,output:25,cacheRead:.5,cacheWrite:6.25}:n.includes("haiku")?{input:1,output:5,cacheRead:.1,cacheWrite:1.25}:H}(e),t.inputTokens/1e6*r.input+t.outputTokens/1e6*r.output+t.cacheReadInputTokens/1e6*r.cacheRead+t.cacheCreationInputTokens/1e6*r.cacheWrite),totalTokens:t.inputTokens+t.outputTokens+t.cacheReadInputTokens+t.cacheCreationInputTokens}}).sort((e,t)=>t.cost-e.cost):[],[d,j]),k=(0,s.useMemo)(()=>w.reduce((e,t)=>e+t.cost,0),[w]),y=(0,s.useMemo)(()=>w.map(e=>e.id),[w]),N=(0,s.useMemo)(()=>{let e={};for(let t of w)e[t.id]=t.totalTokens>0?t.cost/t.totalTokens:0;return e},[w]),{activityChart:C,tokenChart:M,costChart:L}=(0,s.useMemo)(()=>{let e=d?.dailyActivity||[],t=d?.dailyModelTokens||[];if("day"===x){let r=e.slice(-60),n=t.slice(-60),s={labels:r.map(e=>e.date.slice(5)),datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messageCount),color:W[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.toolCallCount),color:W[v].toolCalls}]},o=n.map(e=>e.date.slice(5));return{activityChart:s,tokenChart:{labels:o,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:n.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:o,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:n.map(t=>(t.tokensByModel[e]||0)*(N[e]||0)),color:j[e]}))}}}if("week"===x){let r=function(e,t){let r=new Map;for(let t of e){let e=new Date(t.date),n=new Date(e);n.setDate(e.getDate()-e.getDay());let s=n.toISOString().slice(0,10),o=s.slice(5);r.has(s)||r.set(s,{label:o,messages:0,sessions:0,tools:0,tokensByModel:{}});let l=r.get(s);l.messages+=t.messageCount,l.sessions+=t.sessionCount,l.tools+=t.toolCallCount}for(let e of t){let t=new Date(e.date),n=new Date(t);n.setDate(t.getDate()-t.getDay());let s=n.toISOString().slice(0,10);r.has(s)||r.set(s,{label:s.slice(5),messages:0,sessions:0,tools:0,tokensByModel:{}});let o=r.get(s);for(let[t,r]of Object.entries(e.tokensByModel))o.tokensByModel[t]=(o.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:W[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:W[v].toolCalls}]};return{activityChart:s,tokenChart:{labels:n,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:r.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:n,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:r.map(t=>(t.tokensByModel[e]||0)*(N[e]||0)),color:j[e]}))}}}let r=function(e,t){let r=new Map;for(let t of e){let e=t.date.slice(0,7);r.has(e)||r.set(e,{label:e,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(e);n.messages+=t.messageCount,n.sessions+=t.sessionCount,n.tools+=t.toolCallCount}for(let e of t){let t=e.date.slice(0,7);r.has(t)||r.set(t,{label:t,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(t);for(let[t,r]of Object.entries(e.tokensByModel))n.tokensByModel[t]=(n.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:W[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:W[v].toolCalls}]};return{activityChart:s,tokenChart:{labels:n,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:r.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:n,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:r.map(t=>(t.tokensByModel[e]||0)*(N[e]||0)),color:j[e]}))}}},[d,x,y,N,j,i]),E=g&&j[g]?g:null,P=(0,s.useMemo)(()=>{let e="tokens"===f?M:L;return E?{...e,datasets:e.datasets.filter(e=>e.id===E)}:e},[M,L,f,E]);if((0,F.E)(t,e),!e)return null;let T=[{key:"day",label:i("tokenStats.day")},{key:"week",label:i("tokenStats.week")},{key:"month",label:i("tokenStats.month")}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-lv3 w-full max-w-4xl mx-4 max-h-[90vh] flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:i("tokenStats.title")}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:T.map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${x===e.key?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>h(e.key),children:e.label},e.key))})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-6",children:u?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("common.loading")}):d?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-3",children:[(0,n.jsx)(K,{label:i("tokenStats.totalSessions"),value:String(d.totalSessions??0)}),(0,n.jsx)(K,{label:i("tokenStats.totalMessages"),value:_(d.totalMessages??0)}),(0,n.jsx)(K,{label:i("tokenStats.equivalentApiCost"),value:z(k),highlight:!0}),(0,n.jsx)(K,{label:i("tokenStats.longestSession"),value:d.longestSession?(l=Math.floor((r=d.longestSession.duration)/36e5),a=Math.floor(r%36e5/6e4),l>0?`${l}h ${a}m`:`${a}m`):"-"}),(0,n.jsx)(K,{label:i("tokenStats.firstUse"),value:d.firstSessionDate?d.firstSessionDate.slice(0,10):"-"})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.activityTrend")}),(0,n.jsxs)("div",{className:"flex items-center gap-3 text-[10px]",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:W[v].messages}}),i("tokenStats.messages")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:W[v].toolCalls}}),i("tokenStats.toolCalls")]})]})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(q,{data:C,height:180})})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.byModel")}),(0,n.jsxs)("div",{className:"flex bg-muted rounded-md p-0.5",children:[(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"tokens"===f?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>p("tokens"),children:i("tokenStats.tokenUsage")}),(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"cost"===f?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>p("cost"),children:i("tokenStats.equivalentCost")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-3 text-[10px] flex-wrap",children:w.map(e=>(0,n.jsxs)("button",{onClick:()=>b(E===e.id?null:e.id),className:`flex items-center gap-1 rounded-sm transition-opacity hover:opacity-100 ${E&&E!==e.id?"opacity-40":""}`,children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:e.color}}),e.label]},e.id))})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(q,{data:P,height:180,formatValue:"tokens"===f?_:z})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:i("tokenStats.modelCostDetail")}),(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden",children:(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"bg-muted/50 text-muted-foreground",children:[(0,n.jsx)("th",{className:"text-left px-3 py-2 font-medium",children:i("tokenStats.model")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Input"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Output"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Read"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Write"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.share")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.equivalentCost")})]})}),(0,n.jsxs)("tbody",{children:[w.map(e=>(0,n.jsxs)("tr",{className:"border-t border-border",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-mono text-foreground",children:(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.label]})}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:_(e.usage.inputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:_(e.usage.outputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:_(e.usage.cacheReadInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:_(e.usage.cacheCreationInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:k>0?`${(e.cost/k*100).toFixed(1)}%`:"-"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-medium text-foreground",children:z(e.cost)})]},e.id)),(0,n.jsxs)("tr",{className:"border-t-2 border-border bg-muted/30",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-medium text-foreground",children:i("tokenStats.total")}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:_(w.reduce((e,t)=>e+t.usage.inputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:_(w.reduce((e,t)=>e+t.usage.outputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:_(w.reduce((e,t)=>e+t.usage.cacheReadInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:_(w.reduce((e,t)=>e+t.usage.cacheCreationInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:"100%"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-bold text-foreground",children:z(k)})]})]})]})})]}),d.hourCounts&&Object.keys(d.hourCounts).length>0&&(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(V,{hourCounts:d.hourCounts})})]}):(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("tokenStats.notFound")})})]})]})}function K({label:e,value:t,highlight:r}){return(0,n.jsxs)("div",{className:"bg-muted/30 rounded-lg px-3 py-2.5",children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground",children:e}),(0,n.jsx)("div",{className:`text-sm font-semibold mt-0.5 ${r?"text-brand":"text-foreground"}`,children:t})]})}var Q=r(60865),G=r(52252),J=r(48764),Y=r(58250);function X({skillId:e,name:t,actions:r,onClose:l}){let{t:a}=(0,o.Bd)(),[i,d]=(0,s.useState)(void 0);(0,s.useEffect)(()=>{if(t)return;let r=!1;return S.t4.runPromiseExit((0,J.Bz)(e)).then(e=>{r||"Success"!==e._tag||d(e.value.name)}),()=>{r=!0}},[e,t]);let c=t??i;return(0,n.jsx)(E.g,{endpoint:"/api/skills/files",id:e,entryFile:"SKILL.md",title:c?`/${c}`:a("skills.previewTitle"),actions:r,onClose:l})}let Z="builtin",ee=e=>e.split("/").slice(0,-2).join("/")||"/";function et({isOpen:e,onClose:t}){let{t:r,i18n:l}=(0,o.Bd)(),[a,i]=(0,s.useState)([]),[d,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(""),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)([]),[M,L]=(0,s.useState)(null),[E,P]=(0,s.useState)(null),T=(0,s.useRef)(null),$=(0,s.useCallback)(async()=>{m(!0);let e=await S.t4.runPromiseExit((0,J.Hy)());"Success"===e._tag?i(e.value):console.error("Failed to load skills",e.cause);let t=await S.t4.runPromiseExit((0,J.Wd)());"Success"===t._tag&&y(t.value),m(!1)},[]);(0,s.useEffect)(()=>{e||(L(null),P(null)),e&&($(),setTimeout(()=>{T.current?.focus(),T.current?.select()},100))},[e,$]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{if("Escape"===e.key){if(f){p(!1),b("");return}t()}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,f]);let R=(0,s.useCallback)(e=>{let t=x.trim().toLowerCase();return!t||e.name.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)||e.path.toLowerCase().includes(t)},[x]),I=(0,s.useMemo)(()=>{let e=new Map;for(let t of a){if(!R(t))continue;let r=ee(t.path),n=e.get(r);n?n.push(t):e.set(r,[t])}let t=[...e.entries()].sort(([e,t],[r,n])=>n.length-t.length||e.localeCompare(r)).map(([e,t])=>({key:e,items:[...t].sort((e,t)=>e.name.localeCompare(t.name))})),r=k.filter(R);return r.length>0&&t.push({key:Z,items:r}),t},[a,k,R]),F=(0,s.useMemo)(()=>I.flatMap(e=>e.items),[I]),B=M?[...a,...k].find(e=>e.id===M)??null:null;(0,s.useEffect)(()=>{e&&!B&&L(F[0]?.id??null)},[e,B,F]);let D=l.resolvedLanguage?.startsWith("zh")?"https://opencockpit.dev/zh/docs/agent/skills/":"https://opencockpit.dev/en/docs/agent/skills/",A=(0,s.useCallback)(async()=>{let e=g.trim();if(!e)return;w(!0);let t=await S.t4.runPromiseExit((0,J.L5)(e));if("Success"===t._tag)(0,c.oR)(t.value.alreadyExists?r("skills.alreadyAdded"):r("skills.added"),t.value.alreadyExists?"info":"success"),b(""),p(!1),await $(),t.value.alreadyExists||(0,Y.k)();else{let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause,s=n instanceof Error?n.message:r("skills.addFailed");(0,c.oR)(s,"error")}w(!1)},[g,$,r]),H=(0,s.useCallback)(async e=>{"Success"===(await S.t4.runPromiseExit((0,J.hp)(e)))._tag?(i(t=>t.filter(t=>t.id!==e)),(0,Y.k)()):(0,c.oR)(r("common.deleteFailed"),"error")},[r]);return e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:u.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:r("skills.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:T,type:"text",value:x,onChange:e=>h(e.target.value),placeholder:r("skills.searchPlaceholder"),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),x&&(0,n.jsx)("button",{onClick:()=>{h(""),T.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:r("skills.clearSearch"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("button",{onClick:()=>p(!0),className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),r("skills.addSkill")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),d&&0===a.length&&0===k.length?(0,n.jsx)("div",{className:"flex-1 text-center text-muted-foreground py-8 text-sm",children:r("common.loading")}):(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsxs)("div",{className:"w-full md:w-[340px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:[0===a.length&&(0,n.jsxs)("div",{className:"text-center text-muted-foreground px-4 pt-6 pb-2 text-xs space-y-2",children:[(0,n.jsx)("p",{children:r("skills.emptyNoSkills")}),(0,n.jsxs)("p",{children:[r("skills.emptyIntroPrefix")," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-foreground font-mono text-xs",children:"/skillify"})," ",r("skills.emptyIntroSuffix")]}),(0,n.jsxs)("p",{children:[(0,n.jsx)("button",{type:"button",onClick:()=>p(!0),className:"text-brand hover:underline",children:r("skills.addSkill")})," \xb7 ",(0,n.jsx)("a",{href:D,target:"_blank",rel:"noreferrer",className:"text-brand hover:underline",children:r("skills.viewDocs")})]})]}),(0,n.jsx)("div",{className:"p-3 space-y-3",children:0===I.length&&x?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-6 text-xs",children:r("skills.emptyNoMatch")}):I.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center gap-1.5","data-tooltip":e.key===Z?void 0:e.key,children:[(0,n.jsx)("span",{className:"truncate font-mono",children:e.key===Z?r("skills.builtinGroup"):e.key.replace(/^\/(?:Users|home)\/[^/]+(?=\/|$)/,"~")}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(e=>(0,n.jsx)(er,{skill:e,selected:e.id===M,onSelect:()=>{L(e.id),P(null)}},e.id))})]},e.key))})]}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:B?(0,n.jsx)(X,{skillId:B.id,name:B.name,onClose:t,actions:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{let e=B.path.split("/").slice(0,-1).join("/");(0,N.F)(C.n.OpenProject,{cwd:e,file:"SKILL.md"}),t()},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors flex-shrink-0","data-tooltip":r("common.openAsProject"),"aria-label":r("common.openAsProject"),children:(0,n.jsx)(v.A,{className:"w-4 h-4"})}),B.id.startsWith("builtin:")?(0,n.jsx)("span",{className:"text-[11px] text-foreground-subtle flex-shrink-0",children:r("skills.builtinReadOnly")}):E===B.id?(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{P(null),H(B.id)},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:r("common.confirm")}),(0,n.jsx)("button",{onClick:()=>P(null),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:r("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>P(B.id),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors flex-shrink-0",title:r("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6M1 7h22M9 7V4a1 1 0 011-1h4a1 1 0 011 1v3"})})})]})},B.id):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:r("skills.selectHint")})})]})]})]}),f&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:()=>{j||(p(!1),b(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:r("skills.addSkill")}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:r("skills.pathLabel")}),(0,n.jsx)("input",{type:"text",value:g,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"!==e.key||j||A()},placeholder:r("skills.pathPlaceholder"),autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-4",children:[(0,n.jsx)("button",{onClick:()=>{p(!1),b("")},disabled:j,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors disabled:opacity-50",children:r("common.cancel")}),(0,n.jsx)("button",{onClick:A,disabled:j||!g.trim(),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 transition-colors disabled:opacity-50",children:j?r("skills.adding"):r("skills.add")})]})]})]})]}):null}function er({skill:e,selected:t,onSelect:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{onClick:r,className:`rounded-md px-2 py-2 cursor-pointer transition-colors ${t?"bg-brand/10":"hover:bg-hover"} ${e.valid?"":"opacity-60"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"w-5 h-5 flex-shrink-0 flex items-center justify-center rounded bg-brand/10 text-brand text-xs",children:e.icon?(0,n.jsx)("span",{children:e.icon}):(0,n.jsx)(G.A,{className:"w-3.5 h-3.5"})}),(0,n.jsxs)("span",{className:"font-mono text-xs font-medium text-foreground truncate flex-1 min-w-0",children:["/",e.name]}),!e.valid&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded bg-red-9/15 text-red-11",children:s("skills.invalid")})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-7","data-tooltip":e.description||void 0,children:e.description||(0,n.jsx)("span",{className:"italic opacity-60",children:s("skills.noDescription")})})]})}var en=r(1767),es=r(25237);function eo(){let{t:e}=(0,o.Bd)(),[t,r]=(0,s.useState)(!1);return((0,s.useEffect)(()=>{let e=window.matchMedia("(max-width: 767px)"),t=()=>r(e.matches);return t(),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[]),t)?(0,n.jsxs)("button",{type:"button",onClick:()=>window.location.assign("/m"+window.location.search),className:"fixed bottom-4 right-4 z-40 flex items-center gap-1.5 rounded-full border border-border bg-popover px-3 py-2 text-sm text-foreground shadow-lv2 active:bg-active",children:[(0,n.jsx)(es.A,{className:"h-4 w-4"}),e("mobile.useMobile")]}):null}var el=r(47650),ea=r(7578);let ei=[],ed=[];function ec(){ed.forEach(e=>e())}function eu(e){ei=ei.filter(t=>t.id!==e),ec()}function em({onNavigate:e}){let t=function(){let[,e]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=()=>e(e=>e+1);return ed.push(t),()=>{ed=ed.filter(e=>e!==t)}},[]),ei}();return 0===t.length?null:(0,el.createPortal)((0,n.jsx)("div",{className:"fixed bottom-4 left-4 z-[100] flex flex-col gap-2 pointer-events-none",children:t.map(t=>(0,n.jsx)(ex,{item:t,onNavigate:e,onRemove:eu},t.id))}),document.body)}function ex({item:e,onNavigate:t,onRemove:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(!1),d=(0,s.useRef)(void 0),c=(0,s.useCallback)(()=>{i(!0),setTimeout(()=>r(e.id),300)},[e.id,r]);(0,s.useEffect)(()=>(d.current=setTimeout(c,5e3),()=>clearTimeout(d.current)),[c]);let u=(0,s.useCallback)(()=>{clearTimeout(d.current),t(e.cwd,e.sessionId),r(e.id)},[e,t,r]),m=(0,s.useCallback)(()=>{clearTimeout(d.current)},[]),x=(0,s.useCallback)(()=>{d.current=setTimeout(c,2e3)},[c]);return(0,n.jsxs)("div",{className:`group pointer-events-auto relative bg-popover border border-border rounded-lg shadow-lv3 px-3 py-3 min-h-[84px] min-w-[260px] max-w-[340px] cursor-pointer transition-all ${a?"opacity-0 -translate-x-4":"opacity-100 translate-x-0"}`,style:{animation:a?void 0:"slideInLeft 0.3s ease-out"},onClick:u,onMouseEnter:m,onMouseLeave:x,children:[(0,n.jsx)("div",{className:"pointer-events-none absolute inset-0 rounded-lg bg-hover opacity-0 group-hover:opacity-100 transition-opacity"}),(0,n.jsxs)("div",{className:"relative flex items-start gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-green-9 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:e.projectName}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:l("common.done")}),(0,n.jsx)(ea.l,{projectNumber:e.projectNumber,sessionNumber:e.sessionNumber,className:"ml-auto"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c()},className:"p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.message&&(0,n.jsx)("div",{className:"relative text-xs text-muted-foreground line-clamp-2 break-words mt-1 ml-6",children:e.message})]})}var eh=r(77725),ef=r(49433),ep=r(82680);let eg=ef.$mh({try:async()=>{let e=await fetch("/api/projects");if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()},catch:e=>new ep.uV({message:"fetch /api/projects failed",cause:e})});var eb=r(96472);function ev({initialCwd:e,initialSessionId:t,initialBlank:r}){let{t:c}=(0,o.Bd)(),[u,m]=(0,s.useState)([]),[x,h]=(0,s.useState)(0),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(!1),[y,N]=(0,s.useState)(!1),[C,M]=(0,s.useState)(null),[L,E]=(0,s.useState)(!1),[P,T]=(0,s.useState)(!1),[R,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)([]),[D,A]=(0,s.useState)(null),[H,O]=(0,s.useState)({}),[W,_]=(0,s.useState)({}),[z,q]=(0,s.useState)(()=>new Set),[V,K]=(0,s.useState)(!1),[G,J]=(0,s.useState)(new Set),Y=(0,s.useRef)(new Map),X=(0,s.useRef)(new Map),Z=(0,s.useRef)(new Map),ee=(0,s.useRef)(null),er=(0,eh.Z)(eg,[]);(0,s.useEffect)(()=>{if("success"===er.status){let e=er.data;m([...e.projects||[]]),h(e.activeIndex||0),p(e.collapsed||!1),K(!0)}else"error"===er.status&&(console.error("Failed to load projects:",er.error),K(!0))},[er]);let es=(0,s.useCallback)(async(e,t,r)=>{let n,s=await S.t4.runPromise((n={projects:e,activeIndex:t,collapsed:r},ef.$mh({try:async()=>{let e=await fetch("/api/projects",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)});if(!e.ok)throw Error(`HTTP ${e.status}`)},catch:e=>new ep.uV({message:"save /api/projects failed",cause:e})})).pipe(ef.gPK));"Left"===s._tag&&console.error("Failed to save projects:",s.left)},[]),el=(0,s.useCallback)((e,t)=>{var r,n;let s=u[x]?.cwd,o=(r=s?{cwd:s,sessionId:Z.current.get(s)}:void 0,n={cwd:e,sessionId:t},r?.cwd&&r.sessionId&&(r.cwd!==n.cwd||n.sessionId&&r.sessionId!==n.sessionId)?{cwd:r.cwd,sessionId:r.sessionId}:null);o&&S.t4.runFork((0,eb.T$)(o.cwd,o.sessionId).pipe(ef.h9N(()=>ef.rIH)))},[u,x]);(0,s.useEffect)(()=>{let e=u[x]?.cwd;e&&J(t=>t.has(e)?t:new Set(t).add(e))},[x,u]),(0,s.useEffect)(()=>{for(let[e,t]of Y.current.entries()){let r=u[x]?.cwd===e;t.contentWindow?.postMessage({type:"IFRAME_VISIBILITY",visible:r,projectNumber:u.findIndex(t=>t.cwd===e)+1},"*")}},[x,u]);let ea=(0,s.useCallback)(e=>{let t=u[x]?.cwd,r=t?Y.current.get(t):null,n=r?.contentWindow;if(!n)return;let s=n.document.createEvent("CustomEvent");s.initCustomEvent("console-open-browser",!1,!1,{url:e}),n.dispatchEvent(s)},[x,u]),ed=(0,s.useCallback)(e=>{B(t=>t.some(t=>t.path===e.path)?t:[...t,e]),A(e.path)},[]),eu=(0,s.useCallback)(()=>{A(null)},[]),ex=(0,s.useCallback)(e=>{B(t=>t.filter(t=>t.path!==e)),A(t=>t===e?null:t)},[]);(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type!=="SESSION_NUMBERS")return;let t=e.data.cwd;if("string"!=typeof t||!Array.isArray(e.data.sessionIds))return;let r=e.data.sessionIds.map(e=>"string"==typeof e?e:null);_(e=>{let n=e[t];return n&&n.length===r.length&&n.every((e,t)=>e===r[t])?e:{...e,[t]:r}})};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type!=="PROJECT_DRAFT")return;let{cwd:t,hasDraft:r}=e.data;"string"==typeof t&&q(e=>{if(e.has(t)===!!r)return e;let n=new Set(e);return r?n.add(t):n.delete(t),n})};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let ej=(0,s.useMemo)(()=>u.map(e=>e.cwd),[u]),ew=(0,s.useMemo)(()=>{let e={};return u.forEach((t,r)=>{(W[t.cwd]??[]).forEach((n,s)=>{n&&(e[`${t.cwd}
39
- ${n}`]=`${r+1}.${s+1}`)})}),e},[u,W]),ek=(0,s.useCallback)(()=>{let e=crypto.randomUUID(),t=new Map(u.map((e,t)=>[e.cwd,t+1])),r=[...Y.current.values()];return 0===r.length?Promise.resolve({}):new Promise(n=>{let s={},o=new Set(r.map(e=>e.contentWindow).filter(Boolean)),l=()=>{window.removeEventListener("message",a),clearTimeout(i),O(s),n(s)},a=r=>{if(r.data?.type!=="SESSION_NUMBERS"||r.data?.requestId!==e||!o.delete(r.source))return;let n=t.get(r.data.cwd);n&&Array.isArray(r.data.sessionIds)&&r.data.sessionIds.forEach((e,t)=>{"string"==typeof e&&(s[`${r.data.cwd}
40
- ${e}`]=`${n}.${t+1}`)}),0===o.size&&l()};window.addEventListener("message",a);let i=window.setTimeout(l,300);r.forEach(t=>t.contentWindow?.postMessage({type:"GET_SESSION_NUMBERS",requestId:e},"*"))})},[u]),ey=Object.fromEntries(u.map((e,t)=>[e.cwd,t+1]));(0,s.useEffect)(()=>{g&&ek()},[g,ek]);let eN=(0,s.useCallback)((e,t,r=!1)=>{let n=new URL(window.location.href);n.searchParams.set("cwd",e),t?n.searchParams.set("sessionId",t):n.searchParams.delete("sessionId"),r?n.searchParams.set("newChat","1"):n.searchParams.delete("newChat"),window.history.replaceState({},"",n.toString());let s=e.split("/").filter(Boolean).pop();document.title=s||"Cockpit"},[]),eC=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(!V||eC.current||!e)return;eC.current=!0,t?(X.current.set(e,{sessionId:t}),Z.current.set(e,t)):r&&(X.current.set(e,{blank:!0}),Z.current.set(e,null));let n=u.findIndex(t=>t.cwd===e);if(n>=0)n!==x&&(h(n),es(u,n,f));else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),es(t,r,f)}eN(e,t,r)},[V,e,t,r,u,x,f,es,eN]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="GET_PROJECT_NUMBER"){let t=u.findIndex(t=>t.cwd===e.data.cwd);t>=0&&e.source&&"postMessage"in e.source&&e.source.postMessage({type:"PROJECT_NUMBER",projectNumber:t+1,visible:t===x},"*");return}if(e.data?.type==="SESSION_CHANGE"&&e.data?.cwd&&"sessionId"in e.data){let{cwd:t,sessionId:r}=e.data;"string"==typeof r&&r?Z.current.set(t,r):Z.current.set(t,null);let n=u[x];n?.cwd===t&&eN(t,"string"==typeof r?r:void 0,null===r)}if(e.data?.type==="SESSION_COMPLETE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:t,sessionId:r,lastUserMessage:n}=e.data,s=u[x];if(s?.cwd!==t){let e=t.split("/").pop()||t;ek().then(s=>{let o,[l,a]=s[`${t}
41
- ${r}`]?.split(".")??[],i=u.findIndex(e=>e.cwd===t);o=`session-toast-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,ei=[...ei,{projectName:e,message:n,cwd:t,sessionId:r,projectNumber:l??(i>=0?i+1:void 0),sessionNumber:a,id:o}],ec()})}}if(e.data?.type==="OPEN_TOKEN_STATS"&&k(!0),e.data?.type==="OPEN_NOTE"&&e.data?.cwd&&(M(e.data.cwd),N(!0)),e.data?.type==="SCREENSHOT_PREPARE"&&e.data?.cwd){ee.current=x;let t=e.data.cwd,r=u.findIndex(e=>e.cwd===t);r>=0&&r!==x&&h(r);return}if(e.data?.type==="SCREENSHOT_DONE"){null!==ee.current&&ee.current!==x&&h(ee.current),ee.current=null;return}if(e.data?.type==="OPEN_PROJECT"&&e.data?.cwd){let{cwd:t,sessionId:r,switchToAgent:n,file:s}=e.data,o=r||"";el(t,o||void 0),Z.current.set(t,o);let l=u.findIndex(e=>e.cwd===t);if(l>=0){if(o){let e=Y.current.get(t);e?.contentWindow?e.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:o,...n?{switchToAgent:!0}:{}},"*"):X.current.set(t,{sessionId:o,...n?{switchToAgent:!0}:{}})}if(s){let e=Y.current.get(t);e?.contentWindow?e.contentWindow.postMessage({type:"OPEN_FILE",path:s},"*"):X.current.set(t,{...X.current.get(t),file:s})}l!==x&&(h(l),es(u,l,f))}else{let e=[...u,{cwd:t}],r=e.length-1;m(e),h(r),es(e,r,f),(o||s)&&X.current.set(t,{...o?{sessionId:o}:{},...n?{switchToAgent:!0}:{},...s?{file:s}:{}})}eN(t,o)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[u,x,f,eN,es,ek,el]),(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&!e.altKey){if(!e.shiftKey&&("p"===e.key||"f"===e.key||"s"===e.key))return void e.preventDefault();e.ctrlKey&&!e.metaKey&&"Minus"===e.code&&e.preventDefault()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let eS=(0,s.useCallback)(e=>{let t=u[e];if(t&&(e!==x&&el(t.cwd,Z.current.get(t.cwd)),h(e),es(u,e,f),t?.cwd)){let e=Z.current.get(t.cwd);eN(t.cwd,e??void 0,null===e)}},[u,x,f,es,eN,el]),eM=(0,s.useCallback)(e=>{let t=u.filter((t,r)=>r!==e),r=x;e<x?r=x-1:e===x&&r>=t.length&&(r=Math.max(0,t.length-1)),m(t),h(r),es(t,r,f)},[u,x,f,es]),eL=(0,s.useCallback)(e=>{let t=u[x],r=e.findIndex(e=>e.cwd===t?.cwd);m(e),h(r>=0?r:0),es(e,r>=0?r:0,f)},[u,x,f,es]),eE=(0,s.useCallback)(()=>{let e=!f;p(e),es(u,x,e)},[u,x,f,es]),eP=(0,s.useCallback)((e,t)=>{el(e,t),Z.current.set(e,t);let r=u.findIndex(t=>t.cwd===e);if(r>=0){let n=Y.current.get(e);n?.contentWindow?n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"):X.current.set(e,{sessionId:t,switchToAgent:!0}),h(r),es(u,r,f)}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),es(r,n,f),X.current.set(e,{sessionId:t,switchToAgent:!0})}eN(e,t),b(!1)},[u,f,es,eN,el]),eT=(0,s.useCallback)((e,t)=>{el(e,t),Z.current.set(e,t);let r=u.findIndex(t=>t.cwd===e);if(r>=0){let n=Y.current.get(e);n?.contentWindow?n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"):X.current.set(e,{sessionId:t,switchToAgent:!0}),r!==x&&(h(r),es(u,r,f))}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),es(r,n,f),X.current.set(e,{sessionId:t,switchToAgent:!0})}eN(e,t)},[u,x,f,es,eN,el]),e$=(0,s.useCallback)((e,t)=>{let r=Z.current.get(e)??void 0;el(e,r);let n=u.findIndex(t=>t.cwd===e);if(n>=0){let r=Y.current.get(e);r?.contentWindow?r.contentWindow.postMessage({type:"FOCUS_CONSOLE_BUBBLE",commandId:t},"*"):X.current.set(e,{...X.current.get(e),bubble:t}),n!==x&&(h(n),es(u,n,f))}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),es(r,n,f),X.current.set(e,{bubble:t})}eN(e,r)},[u,x,f,es,eN,el]);return V?(0,n.jsxs)("div",{className:"h-screen flex bg-background overflow-hidden",children:[(0,n.jsx)(l.ProjectSidebar,{projects:u,activeIndex:x,collapsed:f,currentCwd:u[x]?.cwd,onSelectProject:eS,onRemoveProject:eM,onReorderProjects:eL,onToggleCollapse:eE,onOpenSessionBrowser:()=>b(!0),onOpenSettings:()=>j(!0),onOpenNote:e=>{M(e??null),N(!0)},onOpenSkills:()=>E(!0),onOpenBots:()=>T(!0),onOpenApps:()=>I(!0),htmlAppPreviews:F,activeHtmlAppPreviewPath:D,onShowHtmlAppPreview:ed,onSwitchProject:eT,onFocusTerminal:e$,onResolveSessionNumbers:ek,sessionOrders:W,draftCwds:z,sessionNumbers:ew}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:0===u.length?(0,n.jsx)(a.EmptyState,{onBrowseProjects:()=>b(!0)}):(0,n.jsx)("div",{className:"flex-1 relative overflow-hidden",children:u.map((e,t)=>{var r;let s,o,l;return G.has(e.cwd)&&(0,n.jsx)("iframe",{ref:t=>{t?Y.current.set(e.cwd,t):Y.current.delete(e.cwd)},src:(s=X.current.get(e.cwd),r=e.cwd,o=`/project?cwd=${encodeURIComponent(r)}`,s?.sessionId?o+=`&sessionId=${encodeURIComponent(s.sessionId)}`:s?.blank&&(o+="&newChat=1"),s?.file?o+=`&file=${encodeURIComponent(s.file)}`:s?.bubble&&(o+=`&bubble=${encodeURIComponent(s.bubble)}`),(l=s?.file?"explorer":s?.bubble?"console":s?.sessionId&&s.switchToAgent?"agent":null)&&(o+=`&view=${l}`),o),className:`absolute inset-0 w-full h-full border-0 ${t===x?"block":"hidden"}`,title:`Project: ${e.cwd}`},e.cwd)})})}),(0,n.jsx)(i.SessionBrowser,{isOpen:g,onClose:()=>b(!1),onSelectSession:eP,sessionNumbers:H,projectNumbers:ey,onAddProject:e=>{let t=u.findIndex(t=>t.cwd===e);if(el(e,t>=0?Z.current.get(e):void 0),t>=0)h(t),es(u,t,f);else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),es(t,r,f)}b(!1)}}),(0,n.jsx)(d.SettingsModal,{isOpen:v,onClose:()=>j(!1)}),(0,n.jsx)(U,{isOpen:w,onClose:()=>k(!1)}),(0,n.jsx)(Q.NoteModal,{isOpen:y,onClose:()=>{N(!1),M(null)},projectCwd:C,currentCwd:u[x]?.cwd,projectOrder:ej}),(0,n.jsx)(et,{isOpen:L,onClose:()=>E(!1)}),(0,n.jsx)(en.BotsModal,{isOpen:P,onClose:()=>T(!1),onOpenSession:eT}),(0,n.jsx)($,{isOpen:R,htmlAppPreviews:F,activeHtmlAppPreviewPath:D,onShowHtmlAppPreview:ed,onMinimizeHtmlAppPreview:eu,onCloseHtmlAppPreview:ex,onClose:()=>I(!1),onOpenApp:ea}),(0,n.jsx)(em,{onNavigate:eT}),(0,n.jsx)(eo,{})]}):(0,n.jsx)("div",{className:"h-screen flex items-center justify-center bg-card",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:c("workspace.loadingText")})]})})}},92689:(e,t,r)=>{r.d(t,{S:()=>o});var n=r(95155),s=r(57125);function o({engine:e,tooltip:t,size:r="md"}){let l=e||"claude";return(0,s.ch)(l)?(0,n.jsx)("span",{className:"shrink-0 inline-flex items-center","data-tooltip":t??s.H[l],children:(0,n.jsx)(s.eV,{engine:l,className:"sm"===r?"h-3 w-3":"h-3.5 w-3.5"})}):(0,n.jsx)("span",{className:"shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded bg-muted text-muted-foreground","data-tooltip":t??l,children:l})}},93777:(e,t,r)=>{r.d(t,{E:()=>m});var n=r(95155),s=r(12115),o=r(79114),l=r(69809),a=r(12786),i=r(96625),d=r(15317);let c={once:[{labelKey:"scheduledTasks.5minLater",value:5},{labelKey:"scheduledTasks.15minLater",value:15},{labelKey:"scheduledTasks.30minLater",value:30},{labelKey:"scheduledTasks.1hourLater",value:60},{labelKey:"scheduledTasks.3hoursLater",value:180},{labelKey:"scheduledTasks.6hoursLater",value:360},{labelKey:"scheduledTasks.1dayLater",value:1440},{labelKey:"scheduledTasks.3daysLater",value:4320}],interval:[{labelKey:"scheduledTasks.every15min",value:15},{labelKey:"scheduledTasks.every30min",value:30},{labelKey:"scheduledTasks.every1hour",value:60},{labelKey:"scheduledTasks.every2hours",value:120},{labelKey:"scheduledTasks.every6hours",value:360},{labelKey:"scheduledTasks.every12hours",value:720},{labelKey:"scheduledTasks.everyDay",value:1440}],cron:[{labelKey:"scheduledTasks.daily9am",value:"0 9 * * *"},{labelKey:"scheduledTasks.daily6pm",value:"0 18 * * *"},{labelKey:"scheduledTasks.weeklyMon9am",value:"0 9 * * 1"},{labelKey:"scheduledTasks.monthly1st9am",value:"0 9 1 * *"}]},u=["minute","hour","day"];function m({onClose:e,unanchored:t,onCreate:r,editTask:x,onUpdate:h}){let f,p,{t:g}=(0,o.Bd)(),b=!!x,[v,j]=(0,s.useState)(x?.type||"once"),[w,k]=(0,s.useState)(x?.message||""),[y,N]=(0,s.useState)(x?.taskFile?"file":"message"),[C,S]=(0,s.useState)(x?.taskFile||""),[M]=(0,s.useState)(()=>{let e=x?.delayMinutes||x?.intervalMinutes;return e?(0,d.wJ)(e):null}),[L,E]=(0,s.useState)(M?String(M.value):""),[P,T]=(0,s.useState)(M?.unit??"minute"),[$,R]=(0,s.useState)(x?.cron||""),[I,F]=(0,s.useState)(x?.activeFrom||"09:00"),[B,D]=(0,s.useState)(x?.activeTo||"18:00"),[A,H]=(0,s.useState)(x?.startAt?(f=new Date(x.startAt),p=e=>String(e).padStart(2,"0"),`${f.getFullYear()}-${p(f.getMonth()+1)}-${p(f.getDate())}T${p(f.getHours())}:${p(f.getMinutes())}`):""),[O,W]=(0,s.useState)(!!(x?.activeFrom&&x?.activeTo)),[_,z]=(0,s.useState)(null),q=(0,s.useRef)(null),V=(0,s.useRef)(null),U=(0,i.n)({value:w,onChange:k,textareaRef:V});(0,s.useEffect)(()=>{V.current?.focus()},[]),(0,s.useEffect)(()=>{let t=t=>{q.current&&!q.current.contains(t.target)&&e()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[e]);let K=(0,s.useCallback)(()=>{let t="file"===y,n=t?{message:"",taskFile:C.trim()}:{message:w.trim(),taskFile:""};if(t?!n.taskFile:!n.message)return;let s=null;if("once"===v){let e=_||(0,d.LV)(L,P);if(!e||e<=0)return;s={...n,type:"once",delayMinutes:e}}else if("interval"===v){let e=_||(0,d.LV)(L,P);if(!e||e<=0)return;s={...n,type:"interval",intervalMinutes:e,startAt:A?new Date(A).getTime():null,...O?{activeFrom:I,activeTo:B}:{}}}else if("cron"===v){let e=_||$.trim();if(!e)return;s={...n,type:"cron",cron:e}}s&&(b&&x&&h?h(x.id,s):r(s),e())},[w,y,C,v,_,L,P,$,A,O,I,B,r,e,b,x,h]);return(0,n.jsxs)("div",{ref:q,className:`w-[28rem] max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 ${b||t?"":"absolute bottom-full left-0 mb-2"}`,onKeyDown:t=>{"Escape"===t.key?e():"Enter"===t.key&&(t.metaKey||t.ctrlKey)&&K()},children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:b?g("scheduledTasks.editTask"):g("scheduledTasks.createTask")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4 max-h-[min(52rem,calc(100vh-3rem))] overflow-y-auto",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"flex gap-1 mb-1.5",children:["message","file"].map(e=>(0,n.jsx)("button",{onClick:()=>N(e),className:`px-2 py-1 text-xs rounded transition-colors ${y===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"message"===e?g("scheduledTasks.sendMessage"):g("scheduledTasks.taskFile")},e))}),"message"===y?(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("textarea",{ref:V,value:w,onChange:e=>{k(e.target.value),U.trackCaret(e.target)},onSelect:e=>U.trackCaret(e.currentTarget),onKeyDown:e=>{U.handleKeyDown(e)},placeholder:g("scheduledTasks.messagePlaceholder"),rows:5,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring resize-y min-h-[6rem]"}),(0,n.jsx)(i.V,{ac:U,className:"absolute top-full left-0 right-0 mt-1 max-h-48 z-10"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:C,onChange:e=>S(e.target.value),placeholder:g("scheduledTasks.taskFilePlaceholder"),className:"w-full px-2 py-1.5 text-sm font-mono border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:g("scheduledTasks.taskFileHint")})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:g("scheduledTasks.type")}),(0,n.jsx)("div",{className:"flex gap-1",children:["once","interval","cron"].map(e=>(0,n.jsx)("button",{onClick:()=>{j(e),z(null),E(""),T("minute"),R("")},className:`flex-1 px-2 py-1 text-xs rounded transition-colors ${v===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"once"===e?g("scheduledTasks.once"):"interval"===e?g("scheduledTasks.interval"):"Cron"},e))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:g("scheduledTasks.quickSelect")}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-1",children:c[v].map(e=>(0,n.jsx)("button",{onClick:()=>{if(z(e.value),"cron"===v)R(String(e.value));else{let{value:t,unit:r}=(0,d.wJ)(e.value);E(String(t)),T(r)}},className:`px-2 py-1 text-xs rounded border transition-colors ${_===e.value?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:g(e.labelKey)},e.labelKey))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:"cron"===v?g("scheduledTasks.customCron"):g("scheduledTasks.customDuration")}),"cron"===v?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:$,onChange:e=>{R(e.target.value),z(null)},placeholder:g("scheduledTasks.cronPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring font-mono"}),$.trim()&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:function(e){let t=l.A.t,r=e.trim().split(/\s+/);if(5!==r.length)return null;let[n,s,o,a,i]=r,d={0:t("cron.dowSun"),1:t("cron.dowMon"),2:t("cron.dowTue"),3:t("cron.dowWed"),4:t("cron.dowThu"),5:t("cron.dowFri"),6:t("cron.dowSat")},c={1:`1${t("cron.monthPrefix")}`,2:`2${t("cron.monthPrefix")}`,3:`3${t("cron.monthPrefix")}`,4:`4${t("cron.monthPrefix")}`,5:`5${t("cron.monthPrefix")}`,6:`6${t("cron.monthPrefix")}`,7:`7${t("cron.monthPrefix")}`,8:`8${t("cron.monthPrefix")}`,9:`9${t("cron.monthPrefix")}`,10:`10${t("cron.monthPrefix")}`,11:`11${t("cron.monthPrefix")}`,12:`12${t("cron.monthPrefix")}`};try{let e="";if(n.includes("/")||s.includes("/")){if("*"===s&&n.includes("/"))return t("cron.everyNMinutes",{n:n.split("/")[1]});if("0"===n&&s.includes("/"))return t("cron.everyNHours",{n:s.split("/")[1]});return null}let r=parseInt(s,10),l=parseInt(n,10);if(isNaN(r)&&"*"!==s||isNaN(l)&&"*"!==n)return null;e="*"===s&&"*"===n?t("cron.everyMinute"):"*"===s?t("cron.everyHourAtMin",{m:l}):"*"===n?t("cron.hourlyEveryMin",{h:r}):`${String(r).padStart(2,"0")}:${String(l).padStart(2,"0")}`;let u=[];if("*"!==a){let e=a.split(",").map(e=>c[e]||`${e}${t("cron.monthPrefix")}`);u.push(e.join(", "))}if("*"!==o)if(o.includes("-")){let[e,r]=o.split("-");u.push(t("cron.dayRange",{a:e,b:r}))}else o.includes(",")?u.push(o.split(",").map(e=>`${e}${t("cron.dayOfMonth")}`).join(", ")):u.push(`${o}${t("cron.dayOfMonth")}`);if("*"!==i)if("1-5"===i)u.push(t("cron.weekdays"));else if("0,6"===i||"6,0"===i)u.push(t("cron.weekends"));else{let e=i.split(",").map(e=>{if(e.includes("-")){let[r,n]=e.split("-");return t("cron.weekdayRange",{a:d[r]||r,b:d[n]||n})}return`${t("cron.weekdayPrefix")}${d[e]||e}`});u.push(e.join(", "))}if(0===u.length&&"*"===o&&"*"===a&&"*"===i)return t("cron.daily",{time:e});return`${u.join(" ")} ${e}`}catch{return null}}($.trim())||(0,n.jsx)("span",{className:"text-destructive",children:g("scheduledTasks.cronFormat")})})]}):(0,n.jsxs)("div",{className:"flex gap-1",children:[(0,n.jsx)("input",{type:"number",value:L,onChange:e=>{E(e.target.value),z(null)},placeholder:g("scheduledTasks.amountPlaceholder"),min:1,className:"flex-1 min-w-0 px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),u.map(e=>(0,n.jsx)("button",{onClick:()=>{T(e),z(null)},className:`px-3 text-xs rounded border transition-colors ${P===e?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:g(`scheduledTasks.unit.${e}`)},e))]})]}),"interval"===v&&(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:g("scheduledTasks.startAt")}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{type:"datetime-local",value:A,onChange:e=>H(e.target.value),className:"flex-1 min-w-0 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),A&&(0,n.jsx)("button",{onClick:()=>H(""),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground hover:border-foreground/30 transition-colors",children:g("scheduledTasks.clear")})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:g("scheduledTasks.startAtHint")})]}),"interval"===v&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs text-muted-foreground mb-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:O,onChange:e=>W(e.target.checked),className:"rounded border-border"}),g("scheduledTasks.limitTimeRange")]}),O&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("input",{type:"time",value:I,onChange:e=>F(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:g("scheduledTasks.to")}),(0,n.jsx)("input",{type:"time",value:B,onChange:e=>D(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]})]}),(0,n.jsx)("button",{onClick:K,disabled:!(("file"===y?!!C.trim():!!w.trim())&&("once"===v||"interval"===v?!!(_||(0,d.LV)(L,P)>0):"cron"===v&&!!(_||$.trim()))),className:"w-full py-1.5 text-sm font-medium rounded bg-brand text-white hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:b?g("scheduledTasks.saveBtn",{modKey:(0,a.Mu)()}):g("scheduledTasks.createBtn",{modKey:(0,a.Mu)()})})]})]})}},94720:(e,t,r)=>{r.d(t,{AJ:()=>v,Cb:()=>T,D0:()=>M,D5:()=>$,DN:()=>h,Jn:()=>u,MR:()=>f,Ok:()=>N,QF:()=>c,SN:()=>j,UV:()=>P,Vv:()=>k,Yj:()=>E,Yn:()=>L,bv:()=>w,cm:()=>p,cv:()=>y,jO:()=>C,px:()=>R,tp:()=>S,uc:()=>b,y8:()=>g});var n=r(49433),s=r(82680),o=r(84230);let l=e=>n.$mh({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new s.uV({message:`fetch ${e} failed`,cause:t})}),a=(e,t)=>n.$mh({try:async()=>{let r=await fetch(e,t);if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:r=>new s.uV({message:`${t.method} ${e} failed`,cause:r})}),i=(e,t)=>a(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),d=(e,t)=>n.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),c=(e,t)=>n.JkU(function*(){let r=new URLSearchParams({cwd:e});t&&r.set("tabId",t);let n=yield*l(`/api/terminal/env?${r}`);return{env:n.env||{},home:n.home||""}}),u=()=>l("/api/terminal/aliases").pipe(n.TjK(e=>e.aliases||{})),m=(e,t)=>{let r=`/api/terminal/bubble-order?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}`;return(0,o.F)(r,l(r))},x=n.OH5(()=>(0,o.T)("/api/terminal/bubble-order")),h=(e,t)=>m(e,t).pipe(n.TjK(e=>e.order||[])),f=(e,t)=>m(e,t).pipe(n.TjK(e=>e.titles||{})),p=(e,t,r,s)=>i("/api/terminal/bubble-order",{cwd:e,tabId:t,order:r,sourceId:s}).pipe(n.yeE(x)),g=(e,t,r,s)=>i("/api/terminal/bubble-order",{cwd:e,tabId:t,titles:{[r]:s}}).pipe(n.yeE(x)),b=(e,t,r,n=100)=>l(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}&page=${r}&pageSize=${n}`),v=(e,t,r,n)=>i("/api/terminal/history",{cwd:e,tabId:t,entry:r,sourceId:n}),j=(e,t,r,n)=>a(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}&commandId=${encodeURIComponent(r)}${n?`&sourceId=${encodeURIComponent(n)}`:""}`,{method:"DELETE"}),w=(e,t,r,n,s)=>a("/api/terminal/history",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:t,id:r,fields:n,sourceId:s})}),k=e=>i("/api/terminal/env",e),y=e=>i("/api/terminal/aliases",{aliases:e}),N=e=>i("/api/terminal/register",e),C=e=>i("/api/terminal/unregister",e),S=e=>n.$mh({try:async()=>{let t=await fetch("/api/terminal/autocomplete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"POST /api/terminal/autocomplete failed",cause:e})}),M=e=>l(`/api/project-settings?cwd=${encodeURIComponent(e)}`),L=e=>i("/api/project-settings",e),E=()=>l("/api/services/config?scope=global"),P=e=>l(`/api/services/config?cwd=${encodeURIComponent(e)}`),T=e=>d("/api/services/config",e),$=()=>l("/api/terminal/running"),R=e=>d("/api/terminal/running",{commandId:e})},96472:(e,t,r)=>{r.d(t,{AH:()=>u,T$:()=>c,ej:()=>d,n8:()=>i});var n=r(49433),s=r(82680),o=r(8183),l=r(95045),a=r(75346);let i=e=>n.$mh({try:async()=>{let t=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"loadProjectState failed",cause:e})}).pipe(n.Mim(e=>n.OH5(()=>(0,o.EF)(e.sessionTitles??[])))),d=e=>n.$mh({try:async()=>{let t=await fetch("/api/project-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"saveProjectState failed",cause:e})}),c=(e,t)=>n.$mh({try:async()=>{let r=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,action:"touch"})});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:e=>new s.uV({message:"touchRecentSession failed",cause:e})}),u=(e,t,r,o)=>n.DYE(()=>{if(!o())return n.PyW(null);let i=(e,t)=>n.$mh({try:async()=>{let t=await fetch(`${e}?readBoundary=1`,{cache:"no-store"});if(!t.ok)throw Error(`HTTP ${t.status}`);let{readBefore:r}=await t.json();if("number"!=typeof r||!Number.isFinite(r))throw Error("Invalid read boundary");return r},catch:e=>new s.uV({message:"Read boundary request failed",cause:e})}).pipe(n.qIB(e=>n.DYE(()=>o()?t(e).pipe(n.as(e)):n.PyW(null))));return n.Q7R([n.gPK(i("/api/global-state",o=>{let l;return l={readBefore:o,engine:r},n.$mh({try:async()=>{let r=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:"normal",action:"status",...l})});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})})})),n.gPK(i("/api/scheduled-tasks",o=>((e,t={})=>n.$mh({try:async()=>{let r=await fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:e,...t}})});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:e=>new s.uV({message:"markScheduledTasksReadBySession failed",cause:e})}).pipe(n.Mim(()=>n.OH5(()=>(0,l.F)(a.n.ScheduledTasksChanged,{})))))(t,{cwd:e,readBefore:o,engine:r})))],{concurrency:"unbounded"}).pipe(n.qIB(([e,r])=>n.jJl([e,r],e=>"Left"===e._tag?n.FFw("Session read failed").pipe(n.swY({sessionId:t,cause:e.left})):n.rIH).pipe(n.as("Right"===e._tag?e.right:null))))})},96625:(e,t,r)=>{r.d(t,{V:()=>x,n:()=>m});var n=r(95155),s=r(12115),o=r(79114),l=r(58250),a=r(23348),i=r(33442),d=r(67415),c=r(86957),u=r(83448);function m({value:e,onChange:t,textareaRef:r,extraCommands:n,selfSessionId:o}){let[x,h]=(0,s.useState)(e.length),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)([]),[v,j]=(0,s.useState)([]),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)(0),[C,S]=(0,s.useState)(()=>e.length>0),M=(0,s.useRef)(null);(0,s.useEffect)(()=>{c.t4.runPromiseExit((0,u.M5)()).then(e=>{"Success"===e._tag?p(e.value):console.error("Failed to load commands:",e.cause)})},[]);let L=(0,s.useCallback)(async()=>{let e=await c.t4.runPromiseExit((0,u.l1)());if("Success"===e._tag){let t=e.value.skills??e.value;b((Array.isArray(t)?t:[]).filter(e=>e.valid&&!!e.name).map(e=>({name:`/${e.name}`,description:e.description||"",source:"skill",skillPath:e.path,argumentHint:e.argumentHint})))}else console.error("Failed to load skills:",e.cause)},[]);(0,s.useEffect)(()=>(L(),(0,l.U)(L)),[L]);let E=(0,s.useRef)(0),P=(0,s.useCallback)(async()=>{let e=++E.current,t=await c.t4.runPromiseExit((0,a.jm)());e===E.current&&("Success"===t._tag?j(t.value.flatMap(e=>e.valid?[{name:`@${e.name}`,description:e.description,source:"bot"}]:[])):console.error("Failed to load bots:",t.cause))},[]);(0,s.useEffect)(()=>(P(),(0,i.a)(P)),[P]);let T=(0,s.useMemo)(()=>{let t=0===x?0:e.lastIndexOf("\n",x-1)+1,r=e.indexOf("\n",x),n=-1===r?e.length:r;return{text:e.slice(t,n),start:t,end:n}},[e,x]),$=(0,s.useMemo)(()=>{let e=T.text.match(/^\s*(\/@|\/|@)([a-zA-Z0-9-]*)$/);if(e)return{marker:e[1],verb:e[2].toLowerCase(),text:e[2]};let t=T.text.match(/^\s*@(\S.*)$/);return t?{marker:"@",verb:null,text:t[1]}:null},[T.text]),R=(0,s.useRef)(0),I=(0,s.useCallback)(async()=>{let e=++R.current,t=await c.t4.runPromiseExit((0,d.VU)());e===R.current&&("Success"===t._tag?k(t.value.flatMap(e=>{let t;return e.name&&e.engine?[{name:`@${e.name}`,description:(t=e.cwd).split(/[\\/]/).filter(Boolean).pop()??t,source:"session",sessionKey:`${e.cwd}
42
- ${e.sessionId}`,sessionId:e.sessionId}]:[]})):console.error("Failed to load session Bots:",t.cause))},[]);(0,s.useEffect)(()=>(0,i.a)(I),[I]);let F=$?.marker==="@";(0,s.useEffect)(()=>{F&&I()},[F,I]);let B=(0,s.useMemo)(()=>{if(!$)return[];let{verb:e,text:t}=$,r=t=>null!==e&&t.name.slice(1).toLowerCase().startsWith(e);if("@"===$.marker){let e=t.toLowerCase();if(/\s$/.test(e)&&w.some(t=>t.name.slice(1).toLowerCase()===e.trimEnd()))return[];let n=w.filter(e=>e.sessionId!==o).filter(t=>t.name.slice(1).toLowerCase().includes(e)),s=n.filter(t=>t.name.slice(1).toLowerCase().startsWith(e));return[...v.filter(r),...s,...n.filter(e=>!s.includes(e))]}return[...(n??[]).filter(r),...f.filter(r),...g.filter(r)]},[$,n,f,g,v,w,o]),D=!C&&!!$&&B.length>0,A=(0,s.useRef)(e);(0,s.useLayoutEffect)(()=>{A.current!==e&&(queueMicrotask(()=>N(0)),C&&queueMicrotask(()=>S(!1)),A.current=e)},[e,C]),(0,s.useLayoutEffect)(()=>{if(D&&M.current){let e=M.current.children[y];e&&e.scrollIntoView({block:"nearest"})}},[y,D]);let H=(0,s.useCallback)(e=>{h(e.selectionStart??0)},[]),O=(0,s.useCallback)(n=>{let s=$?.marker??"/",o=`${s}${n.name.slice(1)} `,l=e.slice(0,T.start),a=e.slice(T.end),i=l.length+o.length;t(l+o+a),h(i),requestAnimationFrame(()=>{let e=r.current;e&&(e.focus(),e.setSelectionRange(i,i))})},[e,T,$,t,r]),W=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing||!D||0===B.length)return!1;let t=()=>{e.preventDefault(),e.stopPropagation()};return"ArrowDown"===e.key?(t(),N(e=>(e+1)%B.length),!0):"ArrowUp"===e.key?(t(),N(e=>(e-1+B.length)%B.length),!0):"Enter"===e.key||"Tab"===e.key?(t(),O(B[y]),!0):"Escape"===e.key&&(t(),S(!0),!0)},[D,B,y,O]);return{isOpen:D,items:B,selectedIndex:y,marker:$?.marker??"/",listRef:M,selectCommand:O,handleKeyDown:W,trackCaret:H}}function x({ac:e,className:t=""}){let{t:r}=(0,o.Bd)(),{isOpen:s,items:l,selectedIndex:a,marker:i,listRef:d,selectCommand:c}=e;return s&&0!==l.length?(0,n.jsx)("div",{ref:d,className:`overflow-y-auto bg-card border border-border rounded-lg shadow-lv2 ${t}`,children:l.map((e,t)=>{let s=t>0?l[t-1]:null,o="skill"===e.source&&(!s||"skill"!==s.source),d=e=>e?.source==="bot"||e?.source==="session",u=d(e)&&!d(s),m="builtin"===e.source&&0===t;return(0,n.jsxs)("div",{children:[m&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Commands"}),o&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Skills"}),u&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Bots"}),(0,n.jsxs)("div",{onClick:()=>c(e),className:`px-4 py-2 cursor-pointer ${t===a?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:i+e.name.slice(1)}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:"builtin"===e.source?r(`commands.${e.name.slice(1)}`,{defaultValue:e.description}):e.description}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${(e=>{switch(e){case"builtin":return"bg-brand/15 text-brand dark:bg-brand/25 dark:text-teal-11";case"skill":return"bg-purple-9/15 text-purple-11 dark:bg-purple-9/25 dark:text-purple-11";case"bot":return"bg-teal-9/15 text-teal-11 dark:bg-teal-9/25 dark:text-teal-11";case"session":return"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25 dark:text-amber-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return r("common.builtin");case"skill":return"Skill";case"bot":return"Bot";case"session":return r("bots.sessionBadge")}})(e.source)})]}),"skill"===e.source&&e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 pl-0 truncate",children:e.argumentHint})]})]},e.sessionKey??e.name)})}):null}},96901:(e,t,r)=>{r.r(t),r.d(t,{XtermRenderer:()=>x});var n=r(95155),s=r(12115),o=r(8422),l=r(63606),a=r(93090),i=r(3238);let d={foreground:"#d4d4d8",cursor:"#d4d4d8",cursorAccent:"#1a1a2e",selectionBackground:"#3b82f680",black:"#27272a",red:"#f87171",green:"#4ade80",yellow:"#facc15",blue:"#60a5fa",magenta:"#c084fc",cyan:"#22d3ee",white:"#e4e4e7",brightBlack:"#52525b",brightRed:"#fca5a5",brightGreen:"#86efac",brightYellow:"#fde047",brightBlue:"#93c5fd",brightMagenta:"#d8b4fe",brightCyan:"#67e8f9",brightWhite:"#fafafa"},c={foreground:"#1d2126",cursor:"#1d2126",cursorAccent:"#ffffff",selectionBackground:"#3b82f640",black:"#1d2126",red:"#ce2c31",green:"#18774c",yellow:"#a13812",blue:"#0d74ce",magenta:"#5746af",cyan:"#1c5454",white:"#60636c",brightBlack:"#787b87",brightRed:"#e5484d",brightGreen:"#2b9c67",brightYellow:"#bd4b00",brightBlue:"#0478d7",brightMagenta:"#6d54cf",brightCyan:"#3a7877",brightWhite:"#1d2126"},u={light:"#ffffff",dark:"#1b1b1d"};function m(e,t){let r=u[t];if(!e)return r;let n=getComputedStyle(e).getPropertyValue("--card").trim(),s=/^([\d.]+)\s+([\d.]+)%\s+([\d.]+)%$/.exec(n);if(!s)return r;let o=Number(s[1]),l=Number(s[2])/100,a=Number(s[3])/100,i=(1-Math.abs(2*a-1))*l,d=i*(1-Math.abs(o/60%2-1)),c=a-i/2,[m,x,h]=[[i,d,0],[d,i,0],[0,i,d],[0,d,i],[d,0,i],[i,0,d]][Math.floor(o/60)%6],f=e=>Math.round((e+c)*255).toString(16).padStart(2,"0");return`#${f(m)}${f(x)}${f(h)}`}let x=(0,s.memo)((0,s.forwardRef)(function({output:e,isRunning:t,onInput:r,onResize:u,maximized:x,height:h,directWrite:f,fixedSize:p},g){let b=(0,s.useRef)(null),v=(0,s.useRef)(null),j=(0,s.useRef)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(0),y=(0,s.useRef)(r),N=(0,s.useRef)(u),C=(0,s.useRef)(p);C.current=p,(0,s.useEffect)(()=>{y.current=r},[r]),(0,s.useEffect)(()=>{N.current=u},[u]);let S=(0,i.Ql)()?.resolvedTheme??"dark",M="dark"===S?d:c,L=(0,s.useRef)(M);L.current=M;let E=(0,s.useRef)(S);E.current=S,(0,s.useEffect)(()=>{let e=v.current;e&&(e.options.theme={...M,background:m(b.current,S)})},[M,S]),(0,s.useImperativeHandle)(g,()=>({findNext:e=>w.current?.findNext(e,{caseSensitive:!1,decorations:{matchBackground:"#facc1550",matchBorder:"#facc15",matchOverviewRuler:"#facc15",activeMatchBackground:"#facc1590",activeMatchBorder:"#facc15",activeMatchColorOverviewRuler:"#facc15"}})??!1,findPrevious:e=>w.current?.findPrevious(e,{caseSensitive:!1,decorations:{matchBackground:"#facc1550",matchBorder:"#facc15",matchOverviewRuler:"#facc15",activeMatchBackground:"#facc1590",activeMatchBorder:"#facc15",activeMatchColorOverviewRuler:"#facc15"}})??!1,clearSearch:()=>{w.current?.clearDecorations()},write:e=>{v.current?.write(e)},reset:()=>{v.current?.reset()},refresh:()=>{let e=v.current;if(e){try{j.current?.fit()}catch{}try{e.refresh(0,e.rows-1)}catch{}}}}),[]),(0,s.useEffect)(()=>{if(!b.current)return;let e=new o.B({convertEol:!1,scrollback:5e3,fontSize:13,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace',cursorStyle:"block",cursorBlink:!0,disableStdin:!1,allowProposedApi:!0,theme:{...L.current,background:m(b.current,E.current)}}),t=new l.Y,r=new a.n;e.loadAddon(t),e.loadAddon(r),e.open(b.current),e.parser.registerOscHandler(52,()=>!0),e.onData(e=>{y.current?.(e)});try{t.fit(),N.current&&N.current(e.cols,e.rows)}catch{}return v.current=e,j.current=t,w.current=r,k.current=0,()=>{e.dispose(),v.current=null,j.current=null,w.current=null,k.current=0}},[]),(0,s.useEffect)(()=>{let t=v.current;if(!t)return;if(f){e&&0===k.current&&(t.write(e),k.current=e.length);return}let r=!1;if(e.length<k.current&&(t.reset(),k.current=0,r=!0),e.length>k.current){let r=e.slice(k.current);t.write(r),k.current=e.length}r&&y.current&&requestAnimationFrame(()=>t.focus())},[e,f]),(0,s.useEffect)(()=>{t&&v.current&&v.current.focus()},[t]);let P=(0,s.useCallback)(()=>{let e=v.current,t=j.current;if(e&&t&&!C.current)try{t.fit(),N.current&&N.current(e.cols,e.rows)}catch{}},[]),T=p?.cols,$=p?.rows;return(0,s.useEffect)(()=>{let e=v.current;if(e&&T&&$)try{e.resize(T,$)}catch{}},[T,$]),(0,s.useEffect)(()=>{requestAnimationFrame(()=>{P(),requestAnimationFrame(P)})},[x,P]),(0,s.useEffect)(()=>{let e=b.current;if(!e)return;let t=new ResizeObserver(P);return t.observe(e),()=>t.disconnect()},[P]),(0,s.useEffect)(()=>{let e=b.current;if(!e)return;let t=t=>{let r=e.querySelector(".xterm-viewport");if(!r)return;let n=r.scrollHeight-r.clientHeight,s=t.deltaY<0&&r.scrollTop<=0,o=t.deltaY>0&&r.scrollTop>=n-1;(n<=0||s||o)&&t.preventDefault()};return e.addEventListener("wheel",t,{passive:!1}),()=>e.removeEventListener("wheel",t)},[]),(0,n.jsx)("div",{ref:b,className:"xterm-renderer px-2",style:{height:h??"100%",overflow:p?"auto":"hidden"}})}))},99161:(e,t,r)=>{r.d(t,{g:()=>b});var n=r(95155),s=r(12115),o=r(79114),l=r(5135),a=r(38408),i=r(34075),d=r(48764),c=r(86957),u=r(21362),m=r(38798),x=r(48368),h=r(78916);let f=/^(history|reports?|cache|caches|logs?|outputs?|tmp|temp|dist|build|runs?)$/i,p=(0,s.memo)(function({files:e,selected:t,onSelect:r}){let o=(0,s.useMemo)(()=>(function(e){let t={name:"",path:"",children:[]};for(let{path:r}of e){let e=r.split("/"),n=t;e.forEach((t,r)=>{let s=r===e.length-1,o=e.slice(0,r+1).join("/"),l=n.children.find(e=>e.name===t&&!!e.children==!s);l||(l=s?{name:t,path:o}:{name:t,path:o,children:[],count:0},n.children.push(l)),s||(l.count=(l.count??0)+1),n=l})}let r=e=>{e.sort((e,t)=>!!e.children!=!!t.children?e.children?-1:1:e.name.localeCompare(t.name)),e.forEach(e=>e.children&&r(e.children))};return r(t.children),t.children})(e),[e]),[l,a]=(0,s.useState)(()=>new Set),i=(e,s)=>e.map(e=>{if(e.children){let t,r=(t=!f.test(e.name),l.has(e.path)?!t:t);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:()=>{let t;return t=e.path,a(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},style:{paddingLeft:8+12*s},"data-tooltip":e.path+"/",className:"flex items-center gap-1 pr-2 py-1 rounded cursor-pointer text-xs text-muted-foreground hover:bg-hover",children:[(0,n.jsx)(u.A,{className:`w-3 h-3 flex-shrink-0 transition-transform ${r?"rotate-90":""}`}),(0,n.jsx)(m.A,{className:"w-3.5 h-3.5 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:e.name}),(0,n.jsx)("span",{className:"ml-auto text-[10px] tabular-nums text-foreground-subtle",children:e.count})]}),r&&i(e.children,s+1)]},`d:${e.path}`)}let o=/\.(md|markdown|txt)$/i.test(e.name)?x.A:h.A;return(0,n.jsxs)("div",{onClick:()=>r(e.path),style:{paddingLeft:8+12*s+16},className:`flex items-center gap-1 pr-2 py-1 rounded cursor-pointer text-xs ${e.path===t?"bg-brand/10 text-foreground":"text-muted-foreground hover:bg-hover hover:text-foreground"}`,"data-tooltip":e.path,children:[(0,n.jsx)(o,{className:"w-3.5 h-3.5 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate font-mono",children:e.name})]},`f:${e.path}`)});return(0,n.jsx)("div",{className:"p-1 space-y-px",children:i(o,0)})}),g=()=>{};function b({endpoint:e,id:t,entryFile:r,title:u,actions:m,onClose:x=g}){let{t:h}=(0,o.Bd)(),[f,v]=(0,s.useState)("preview"),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)(""),[N,C]=(0,s.useState)(r),[S,M]=(0,s.useState)(null),[L,E]=(0,s.useState)(224),P=(0,s.useRef)(null),T=(0,s.useCallback)(e=>{"mouse"===e.pointerType&&0===e.button&&(e.preventDefault(),P.current={startX:e.clientX,startWidth:L},e.currentTarget.setPointerCapture(e.pointerId))},[L]),$=(0,s.useCallback)(e=>{let t=P.current;t&&E(Math.min(336,Math.max(224,t.startWidth+(e.clientX-t.startX))))},[]),R=(0,s.useCallback)(e=>{P.current&&(P.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))},[]);(0,s.useEffect)(()=>{let r=!1;return c.t4.runPromiseExit((0,d.De)(e,t)).then(e=>{r||("Success"===e._tag?(w(e.value.files),y(e.value.dir)):w(void 0))}),()=>{r=!0}},[e,t]),(0,s.useEffect)(()=>{let r=!1;return M(null),c.t4.runPromiseExit((0,d.Ek)(e,t,N)).then(e=>{r||M("Success"===e._tag?e.value:{path:N,kind:"binary",size:0})}),()=>{r=!0}},[e,t,N]);let I=k?`${k}/${N}`:"",F=/\.(md|markdown)$/i.test(N),B=!!j&&j.length>1,D=(0,s.useCallback)(async()=>{if(I)try{await navigator.clipboard.writeText(I),(0,i.oR)(h("common.copiedPath"),"success")}catch{(0,i.oR)(h("common.copyFailed"),"error")}},[I,h]),A=e=>(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:e});return(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:u}),(0,n.jsx)("button",{onClick:D,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:h("skills.copyPath"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),I&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono truncate mt-0.5","data-tooltip":I,children:I})]}),(0,n.jsxs)("div",{className:`flex items-center rounded-md border border-border overflow-hidden text-xs flex-shrink-0 ${F?"":"invisible"}`,children:[(0,n.jsx)("button",{onClick:()=>v("preview"),className:`px-3 py-1 transition-colors ${"preview"===f?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:h("common.preview")}),(0,n.jsx)("button",{onClick:()=>v("source"),className:`px-3 py-1 transition-colors ${"source"===f?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:h("skills.source")})]}),m]}),(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[B&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex-shrink-0 overflow-y-auto",style:{width:L},children:(0,n.jsx)(p,{files:j,selected:N,onSelect:C})}),(0,n.jsx)("div",{onPointerDown:T,onPointerMove:$,onPointerUp:R,onPointerCancel:R,className:"w-[5px] flex-shrink-0 relative cursor-col-resize group",children:(0,n.jsx)("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border group-hover:bg-brand transition-colors"})})]}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:(()=>{if(void 0===j)return A(h("skills.cannotRead"));if(!S)return A(h("common.loading"));if("text"!==S.kind)return A("tooLarge"===S.kind?h("skills.fileTooLarge"):h("skills.fileNotPreviewable"));let e=S.content??"";if(!F||"source"===f){let t;return t=I||N,(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsx)(a.XO,{content:e,filePath:t,className:"min-h-full"})})}return(0,n.jsx)(l.M,{content:e,filePath:I||N,cwd:k,embedded:!0,onClose:x,tocDefaultCollapsed:!0})})()})]})]})}}}]);