@surething/cockpit 1.0.286 → 1.0.287

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 (355) hide show
  1. package/.next-prod/BUILD_ID +1 -1
  2. package/.next-prod/app-path-routes-manifest.json +3 -3
  3. package/.next-prod/build-manifest.json +2 -2
  4. package/.next-prod/cockpit-build.json +1 -1
  5. package/.next-prod/prerender-manifest.json +3 -3
  6. package/.next-prod/server/app/_global-error/page.js.nft.json +1 -1
  7. package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
  8. package/.next-prod/server/app/_global-error.html +1 -1
  9. package/.next-prod/server/app/_global-error.rsc +1 -1
  10. package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
  11. package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  12. package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  13. package/.next-prod/server/app/_not-found/page.js.nft.json +1 -1
  14. package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
  15. package/.next-prod/server/app/_not-found.html +2 -2
  16. package/.next-prod/server/app/_not-found.rsc +3 -3
  17. package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +3 -3
  18. package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +3 -3
  19. package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  20. package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  21. package/.next-prod/server/app/api/agent/test/route.js +1 -1
  22. package/.next-prod/server/app/api/agent/test/route.js.nft.json +1 -1
  23. package/.next-prod/server/app/api/bash/route.js +1 -1
  24. package/.next-prod/server/app/api/bash/route.js.nft.json +1 -1
  25. package/.next-prod/server/app/api/bots/[id]/route.js +1 -1
  26. package/.next-prod/server/app/api/bots/[id]/route.js.nft.json +1 -1
  27. package/.next-prod/server/app/api/bots/route.js +1 -1
  28. package/.next-prod/server/app/api/bots/route.js.nft.json +1 -1
  29. package/.next-prod/server/app/api/chat/codex/route.js +1 -1
  30. package/.next-prod/server/app/api/chat/codex/route.js.nft.json +1 -1
  31. package/.next-prod/server/app/api/chat/deepseek/route.js +1 -1
  32. package/.next-prod/server/app/api/chat/deepseek/route.js.nft.json +1 -1
  33. package/.next-prod/server/app/api/chat/glm/route.js +1 -1
  34. package/.next-prod/server/app/api/chat/glm/route.js.nft.json +1 -1
  35. package/.next-prod/server/app/api/chat/kimi/route.js +1 -1
  36. package/.next-prod/server/app/api/chat/kimi/route.js.nft.json +1 -1
  37. package/.next-prod/server/app/api/chat/ollama/route.js +1 -1
  38. package/.next-prod/server/app/api/chat/ollama/route.js.nft.json +1 -1
  39. package/.next-prod/server/app/api/chat/route.js +1 -1
  40. package/.next-prod/server/app/api/chat/route.js.nft.json +1 -1
  41. package/.next-prod/server/app/api/chat/stop/route.js +1 -1
  42. package/.next-prod/server/app/api/chat/stop/route.js.nft.json +1 -1
  43. package/.next-prod/server/app/api/claude-stats/route.js +1 -1
  44. package/.next-prod/server/app/api/claude-stats/route.js.nft.json +1 -1
  45. package/.next-prod/server/app/api/commands/route.js +1 -1
  46. package/.next-prod/server/app/api/commands/route.js.nft.json +1 -1
  47. package/.next-prod/server/app/api/comments/route.js +1 -1
  48. package/.next-prod/server/app/api/comments/route.js.nft.json +1 -1
  49. package/.next-prod/server/app/api/db/columns/route.js +1 -1
  50. package/.next-prod/server/app/api/db/columns/route.js.nft.json +1 -1
  51. package/.next-prod/server/app/api/db/connect/route.js +1 -1
  52. package/.next-prod/server/app/api/db/connect/route.js.nft.json +1 -1
  53. package/.next-prod/server/app/api/db/disconnect/route.js +1 -1
  54. package/.next-prod/server/app/api/db/disconnect/route.js.nft.json +1 -1
  55. package/.next-prod/server/app/api/db/export/route.js +1 -1
  56. package/.next-prod/server/app/api/db/export/route.js.nft.json +1 -1
  57. package/.next-prod/server/app/api/db/query/route.js +1 -1
  58. package/.next-prod/server/app/api/db/query/route.js.nft.json +1 -1
  59. package/.next-prod/server/app/api/db/schemas/route.js +1 -1
  60. package/.next-prod/server/app/api/db/schemas/route.js.nft.json +1 -1
  61. package/.next-prod/server/app/api/deepseek/balance/route.js +1 -1
  62. package/.next-prod/server/app/api/deepseek/balance/route.js.nft.json +1 -1
  63. package/.next-prod/server/app/api/deepseek/credentials/route.js +1 -1
  64. package/.next-prod/server/app/api/deepseek/credentials/route.js.nft.json +1 -1
  65. package/.next-prod/server/app/api/deepseek/models/route.js +1 -1
  66. package/.next-prod/server/app/api/deepseek/models/route.js.nft.json +1 -1
  67. package/.next-prod/server/app/api/dev/spans/route.js +1 -1
  68. package/.next-prod/server/app/api/dev/spans/route.js.nft.json +1 -1
  69. package/.next-prod/server/app/api/extension/version/route.js +1 -1
  70. package/.next-prod/server/app/api/extension/version/route.js.nft.json +1 -1
  71. package/.next-prod/server/app/api/file/route.js +1 -1
  72. package/.next-prod/server/app/api/file/route.js.nft.json +1 -1
  73. package/.next-prod/server/app/api/files/blame/route.js +1 -1
  74. package/.next-prod/server/app/api/files/blame/route.js.nft.json +1 -1
  75. package/.next-prod/server/app/api/files/clipboard/route.js +1 -1
  76. package/.next-prod/server/app/api/files/clipboard/route.js.nft.json +1 -1
  77. package/.next-prod/server/app/api/files/copy/route.js +1 -1
  78. package/.next-prod/server/app/api/files/copy/route.js.nft.json +1 -1
  79. package/.next-prod/server/app/api/files/delete/route.js +1 -1
  80. package/.next-prod/server/app/api/files/delete/route.js.nft.json +1 -1
  81. package/.next-prod/server/app/api/files/expanded/route.js +1 -1
  82. package/.next-prod/server/app/api/files/expanded/route.js.nft.json +1 -1
  83. package/.next-prod/server/app/api/files/index/route.js +1 -1
  84. package/.next-prod/server/app/api/files/index/route.js.nft.json +1 -1
  85. package/.next-prod/server/app/api/files/init/route.js +1 -1
  86. package/.next-prod/server/app/api/files/init/route.js.nft.json +1 -1
  87. package/.next-prod/server/app/api/files/paste/route.js +1 -1
  88. package/.next-prod/server/app/api/files/paste/route.js.nft.json +1 -1
  89. package/.next-prod/server/app/api/files/read/route.js +1 -1
  90. package/.next-prod/server/app/api/files/read/route.js.nft.json +1 -1
  91. package/.next-prod/server/app/api/files/readdir/route.js +1 -1
  92. package/.next-prod/server/app/api/files/readdir/route.js.nft.json +1 -1
  93. package/.next-prod/server/app/api/files/recent/route.js +1 -1
  94. package/.next-prod/server/app/api/files/recent/route.js.nft.json +1 -1
  95. package/.next-prod/server/app/api/files/save/route.js +1 -1
  96. package/.next-prod/server/app/api/files/save/route.js.nft.json +1 -1
  97. package/.next-prod/server/app/api/files/search/route.js +1 -1
  98. package/.next-prod/server/app/api/files/search/route.js.nft.json +1 -1
  99. package/.next-prod/server/app/api/files/stat/route.js +1 -1
  100. package/.next-prod/server/app/api/files/stat/route.js.nft.json +1 -1
  101. package/.next-prod/server/app/api/files/text/route.js +1 -1
  102. package/.next-prod/server/app/api/files/text/route.js.nft.json +1 -1
  103. package/.next-prod/server/app/api/fs/dirs/route.js +1 -1
  104. package/.next-prod/server/app/api/fs/dirs/route.js.nft.json +1 -1
  105. package/.next-prod/server/app/api/git/blob/route.js +1 -1
  106. package/.next-prod/server/app/api/git/blob/route.js.nft.json +1 -1
  107. package/.next-prod/server/app/api/git/branch-diff/route.js +1 -1
  108. package/.next-prod/server/app/api/git/branch-diff/route.js.nft.json +1 -1
  109. package/.next-prod/server/app/api/git/branches/route.js +1 -1
  110. package/.next-prod/server/app/api/git/branches/route.js.nft.json +1 -1
  111. package/.next-prod/server/app/api/git/commit-diff/route.js +1 -1
  112. package/.next-prod/server/app/api/git/commit-diff/route.js.nft.json +1 -1
  113. package/.next-prod/server/app/api/git/commits/route.js +1 -1
  114. package/.next-prod/server/app/api/git/commits/route.js.nft.json +1 -1
  115. package/.next-prod/server/app/api/git/current-branch/route.js +1 -1
  116. package/.next-prod/server/app/api/git/current-branch/route.js.nft.json +1 -1
  117. package/.next-prod/server/app/api/git/diff/route.js +1 -1
  118. package/.next-prod/server/app/api/git/diff/route.js.nft.json +1 -1
  119. package/.next-prod/server/app/api/git/discard/route.js +1 -1
  120. package/.next-prod/server/app/api/git/discard/route.js.nft.json +1 -1
  121. package/.next-prod/server/app/api/git/stage/route.js +1 -1
  122. package/.next-prod/server/app/api/git/stage/route.js.nft.json +1 -1
  123. package/.next-prod/server/app/api/git/status/route.js +1 -1
  124. package/.next-prod/server/app/api/git/status/route.js.nft.json +1 -1
  125. package/.next-prod/server/app/api/git/unstage/route.js +1 -1
  126. package/.next-prod/server/app/api/git/unstage/route.js.nft.json +1 -1
  127. package/.next-prod/server/app/api/git/worktree/route.js +1 -1
  128. package/.next-prod/server/app/api/git/worktree/route.js.nft.json +1 -1
  129. package/.next-prod/server/app/api/glm/credentials/route.js +1 -1
  130. package/.next-prod/server/app/api/glm/credentials/route.js.nft.json +1 -1
  131. package/.next-prod/server/app/api/glm/models/route.js +1 -1
  132. package/.next-prod/server/app/api/glm/models/route.js.nft.json +1 -1
  133. package/.next-prod/server/app/api/glm/usage/route.js +1 -1
  134. package/.next-prod/server/app/api/glm/usage/route.js.nft.json +1 -1
  135. package/.next-prod/server/app/api/global-state/route.js +1 -1
  136. package/.next-prod/server/app/api/global-state/route.js.nft.json +1 -1
  137. package/.next-prod/server/app/api/health/route.js +1 -1
  138. package/.next-prod/server/app/api/health/route.js.nft.json +1 -1
  139. package/.next-prod/server/app/api/html-apps/[id]/route.js +1 -1
  140. package/.next-prod/server/app/api/html-apps/[id]/route.js.nft.json +1 -1
  141. package/.next-prod/server/app/api/html-apps/route.js +1 -1
  142. package/.next-prod/server/app/api/html-apps/route.js.nft.json +1 -1
  143. package/.next-prod/server/app/api/instructions/config/route.js +1 -1
  144. package/.next-prod/server/app/api/instructions/config/route.js.nft.json +1 -1
  145. package/.next-prod/server/app/api/kimi/credentials/route.js +1 -1
  146. package/.next-prod/server/app/api/kimi/credentials/route.js.nft.json +1 -1
  147. package/.next-prod/server/app/api/kimi/models/route.js +1 -1
  148. package/.next-prod/server/app/api/kimi/models/route.js.nft.json +1 -1
  149. package/.next-prod/server/app/api/kimi/usage/route.js +1 -1
  150. package/.next-prod/server/app/api/kimi/usage/route.js.nft.json +1 -1
  151. package/.next-prod/server/app/api/lsp/definition/route.js +1 -1
  152. package/.next-prod/server/app/api/lsp/definition/route.js.nft.json +1 -1
  153. package/.next-prod/server/app/api/lsp/hover/route.js +1 -1
  154. package/.next-prod/server/app/api/lsp/hover/route.js.nft.json +1 -1
  155. package/.next-prod/server/app/api/lsp/references/route.js +1 -1
  156. package/.next-prod/server/app/api/lsp/references/route.js.nft.json +1 -1
  157. package/.next-prod/server/app/api/lsp/status/route.js +1 -1
  158. package/.next-prod/server/app/api/lsp/status/route.js.nft.json +1 -1
  159. package/.next-prod/server/app/api/lsp/warmup/route.js +1 -1
  160. package/.next-prod/server/app/api/lsp/warmup/route.js.nft.json +1 -1
  161. package/.next-prod/server/app/api/mysql/columns/route.js +1 -1
  162. package/.next-prod/server/app/api/mysql/columns/route.js.nft.json +1 -1
  163. package/.next-prod/server/app/api/mysql/connect/route.js +1 -1
  164. package/.next-prod/server/app/api/mysql/connect/route.js.nft.json +1 -1
  165. package/.next-prod/server/app/api/mysql/disconnect/route.js +1 -1
  166. package/.next-prod/server/app/api/mysql/disconnect/route.js.nft.json +1 -1
  167. package/.next-prod/server/app/api/mysql/export/route.js +1 -1
  168. package/.next-prod/server/app/api/mysql/export/route.js.nft.json +1 -1
  169. package/.next-prod/server/app/api/mysql/query/route.js +1 -1
  170. package/.next-prod/server/app/api/mysql/query/route.js.nft.json +1 -1
  171. package/.next-prod/server/app/api/mysql/schemas/route.js +1 -1
  172. package/.next-prod/server/app/api/mysql/schemas/route.js.nft.json +1 -1
  173. package/.next-prod/server/app/api/neo4j/connect/route.js +1 -1
  174. package/.next-prod/server/app/api/neo4j/connect/route.js.nft.json +1 -1
  175. package/.next-prod/server/app/api/neo4j/disconnect/route.js +1 -1
  176. package/.next-prod/server/app/api/neo4j/disconnect/route.js.nft.json +1 -1
  177. package/.next-prod/server/app/api/neo4j/query/route.js +1 -1
  178. package/.next-prod/server/app/api/neo4j/query/route.js.nft.json +1 -1
  179. package/.next-prod/server/app/api/neo4j/schema/route.js +1 -1
  180. package/.next-prod/server/app/api/neo4j/schema/route.js.nft.json +1 -1
  181. package/.next-prod/server/app/api/note/route.js +1 -1
  182. package/.next-prod/server/app/api/note/route.js.nft.json +1 -1
  183. package/.next-prod/server/app/api/ollama/config/route.js +1 -1
  184. package/.next-prod/server/app/api/ollama/config/route.js.nft.json +1 -1
  185. package/.next-prod/server/app/api/ollama/default-model/route.js +1 -1
  186. package/.next-prod/server/app/api/ollama/default-model/route.js.nft.json +1 -1
  187. package/.next-prod/server/app/api/ollama/models/route.js +1 -1
  188. package/.next-prod/server/app/api/ollama/models/route.js.nft.json +1 -1
  189. package/.next-prod/server/app/api/ollama/start/route.js +1 -1
  190. package/.next-prod/server/app/api/ollama/start/route.js.nft.json +1 -1
  191. package/.next-prod/server/app/api/open-cursor/route.js +1 -1
  192. package/.next-prod/server/app/api/open-cursor/route.js.nft.json +1 -1
  193. package/.next-prod/server/app/api/open-vscode/route.js +1 -1
  194. package/.next-prod/server/app/api/open-vscode/route.js.nft.json +1 -1
  195. package/.next-prod/server/app/api/output-styles/config/route.js +1 -1
  196. package/.next-prod/server/app/api/output-styles/config/route.js.nft.json +1 -1
  197. package/.next-prod/server/app/api/pinned-sessions/route.js +1 -1
  198. package/.next-prod/server/app/api/pinned-sessions/route.js.nft.json +1 -1
  199. package/.next-prod/server/app/api/project-settings/route.js +1 -1
  200. package/.next-prod/server/app/api/project-settings/route.js.nft.json +1 -1
  201. package/.next-prod/server/app/api/project-state/route.js +1 -1
  202. package/.next-prod/server/app/api/project-state/route.js.nft.json +1 -1
  203. package/.next-prod/server/app/api/projectGraph/affected/route.js +1 -1
  204. package/.next-prod/server/app/api/projectGraph/affected/route.js.nft.json +1 -1
  205. package/.next-prod/server/app/api/projectGraph/callees/route.js +1 -1
  206. package/.next-prod/server/app/api/projectGraph/callees/route.js.nft.json +1 -1
  207. package/.next-prod/server/app/api/projectGraph/callers/route.js +1 -1
  208. package/.next-prod/server/app/api/projectGraph/callers/route.js.nft.json +1 -1
  209. package/.next-prod/server/app/api/projectGraph/coedit/route.js +1 -1
  210. package/.next-prod/server/app/api/projectGraph/coedit/route.js.nft.json +1 -1
  211. package/.next-prod/server/app/api/projectGraph/context/route.js +1 -1
  212. package/.next-prod/server/app/api/projectGraph/context/route.js.nft.json +1 -1
  213. package/.next-prod/server/app/api/projectGraph/file/route.js +1 -1
  214. package/.next-prod/server/app/api/projectGraph/file/route.js.nft.json +1 -1
  215. package/.next-prod/server/app/api/projectGraph/file-functions/route.js +1 -1
  216. package/.next-prod/server/app/api/projectGraph/file-functions/route.js.nft.json +1 -1
  217. package/.next-prod/server/app/api/projectGraph/impact/route.js +1 -1
  218. package/.next-prod/server/app/api/projectGraph/impact/route.js.nft.json +1 -1
  219. package/.next-prod/server/app/api/projectGraph/related/route.js +1 -1
  220. package/.next-prod/server/app/api/projectGraph/related/route.js.nft.json +1 -1
  221. package/.next-prod/server/app/api/projectGraph/risk/route.js +1 -1
  222. package/.next-prod/server/app/api/projectGraph/risk/route.js.nft.json +1 -1
  223. package/.next-prod/server/app/api/projectGraph/search/route.js +1 -1
  224. package/.next-prod/server/app/api/projectGraph/search/route.js.nft.json +1 -1
  225. package/.next-prod/server/app/api/projects/route.js +1 -1
  226. package/.next-prod/server/app/api/projects/route.js.nft.json +1 -1
  227. package/.next-prod/server/app/api/push/public-key/route.js +1 -1
  228. package/.next-prod/server/app/api/push/public-key/route.js.nft.json +1 -1
  229. package/.next-prod/server/app/api/push/subscribe/route.js +1 -1
  230. package/.next-prod/server/app/api/push/subscribe/route.js.nft.json +1 -1
  231. package/.next-prod/server/app/api/push/unsubscribe/route.js +1 -1
  232. package/.next-prod/server/app/api/push/unsubscribe/route.js.nft.json +1 -1
  233. package/.next-prod/server/app/api/redis/command/route.js +1 -1
  234. package/.next-prod/server/app/api/redis/command/route.js.nft.json +1 -1
  235. package/.next-prod/server/app/api/redis/connect/route.js +1 -1
  236. package/.next-prod/server/app/api/redis/connect/route.js.nft.json +1 -1
  237. package/.next-prod/server/app/api/redis/delete/route.js +1 -1
  238. package/.next-prod/server/app/api/redis/delete/route.js.nft.json +1 -1
  239. package/.next-prod/server/app/api/redis/disconnect/route.js +1 -1
  240. package/.next-prod/server/app/api/redis/disconnect/route.js.nft.json +1 -1
  241. package/.next-prod/server/app/api/redis/get/route.js +1 -1
  242. package/.next-prod/server/app/api/redis/get/route.js.nft.json +1 -1
  243. package/.next-prod/server/app/api/redis/keys/route.js +1 -1
  244. package/.next-prod/server/app/api/redis/keys/route.js.nft.json +1 -1
  245. package/.next-prod/server/app/api/redis/set/route.js +1 -1
  246. package/.next-prod/server/app/api/redis/set/route.js.nft.json +1 -1
  247. package/.next-prod/server/app/api/restart/route.js +1 -1
  248. package/.next-prod/server/app/api/restart/route.js.nft.json +1 -1
  249. package/.next-prod/server/app/api/scheduled-tasks/route.js +2 -2
  250. package/.next-prod/server/app/api/scheduled-tasks/route.js.nft.json +1 -1
  251. package/.next-prod/server/app/api/services/config/route.js +1 -1
  252. package/.next-prod/server/app/api/services/config/route.js.nft.json +1 -1
  253. package/.next-prod/server/app/api/services/scripts/route.js +1 -1
  254. package/.next-prod/server/app/api/services/scripts/route.js.nft.json +1 -1
  255. package/.next-prod/server/app/api/session/[sessionId]/fork/route.js +1 -1
  256. package/.next-prod/server/app/api/session/[sessionId]/fork/route.js.nft.json +1 -1
  257. package/.next-prod/server/app/api/session/[sessionId]/history/route.js +1 -1
  258. package/.next-prod/server/app/api/session/[sessionId]/history/route.js.nft.json +1 -1
  259. package/.next-prod/server/app/api/session/[sessionId]/turn/route.js +2 -2
  260. package/.next-prod/server/app/api/session/[sessionId]/turn/route.js.nft.json +1 -1
  261. package/.next-prod/server/app/api/session/user-messages/route.js +1 -1
  262. package/.next-prod/server/app/api/session/user-messages/route.js.nft.json +1 -1
  263. package/.next-prod/server/app/api/session-by-path/route.js +1 -1
  264. package/.next-prod/server/app/api/session-by-path/route.js.nft.json +1 -1
  265. package/.next-prod/server/app/api/sessions/delegate/route.js +1 -1
  266. package/.next-prod/server/app/api/sessions/delegate/route.js.nft.json +1 -1
  267. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js +1 -1
  268. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js.nft.json +1 -1
  269. package/.next-prod/server/app/api/sessions/projects/route.js +1 -1
  270. package/.next-prod/server/app/api/sessions/projects/route.js.nft.json +1 -1
  271. package/.next-prod/server/app/api/sessions/search/route.js +1 -1
  272. package/.next-prod/server/app/api/sessions/search/route.js.nft.json +1 -1
  273. package/.next-prod/server/app/api/sessions/status/route.js +1 -1
  274. package/.next-prod/server/app/api/sessions/status/route.js.nft.json +1 -1
  275. package/.next-prod/server/app/api/settings/route.js +1 -1
  276. package/.next-prod/server/app/api/settings/route.js.nft.json +1 -1
  277. package/.next-prod/server/app/api/shutdown/route.js +1 -1
  278. package/.next-prod/server/app/api/shutdown/route.js.nft.json +1 -1
  279. package/.next-prod/server/app/api/skills/[id]/route.js +1 -1
  280. package/.next-prod/server/app/api/skills/[id]/route.js.nft.json +1 -1
  281. package/.next-prod/server/app/api/skills/content/route.js +1 -1
  282. package/.next-prod/server/app/api/skills/content/route.js.nft.json +1 -1
  283. package/.next-prod/server/app/api/skills/route.js +1 -1
  284. package/.next-prod/server/app/api/skills/route.js.nft.json +1 -1
  285. package/.next-prod/server/app/api/snapshots/blob/route.js +1 -1
  286. package/.next-prod/server/app/api/snapshots/blob/route.js.nft.json +1 -1
  287. package/.next-prod/server/app/api/snapshots/diff/route.js +1 -1
  288. package/.next-prod/server/app/api/snapshots/diff/route.js.nft.json +1 -1
  289. package/.next-prod/server/app/api/snapshots/range-diff/route.js +1 -1
  290. package/.next-prod/server/app/api/snapshots/range-diff/route.js.nft.json +1 -1
  291. package/.next-prod/server/app/api/snapshots/route.js +1 -1
  292. package/.next-prod/server/app/api/snapshots/route.js.nft.json +1 -1
  293. package/.next-prod/server/app/api/terminal/aliases/route.js +1 -1
  294. package/.next-prod/server/app/api/terminal/aliases/route.js.nft.json +1 -1
  295. package/.next-prod/server/app/api/terminal/autocomplete/route.js +1 -1
  296. package/.next-prod/server/app/api/terminal/autocomplete/route.js.nft.json +1 -1
  297. package/.next-prod/server/app/api/terminal/bubble-order/route.js +1 -1
  298. package/.next-prod/server/app/api/terminal/bubble-order/route.js.nft.json +1 -1
  299. package/.next-prod/server/app/api/terminal/env/route.js +1 -1
  300. package/.next-prod/server/app/api/terminal/env/route.js.nft.json +1 -1
  301. package/.next-prod/server/app/api/terminal/history/route.js +1 -1
  302. package/.next-prod/server/app/api/terminal/history/route.js.nft.json +1 -1
  303. package/.next-prod/server/app/api/terminal/running/route.js +1 -1
  304. package/.next-prod/server/app/api/terminal/running/route.js.nft.json +1 -1
  305. package/.next-prod/server/app/api/update/route.js +1 -1
  306. package/.next-prod/server/app/api/update/route.js.nft.json +1 -1
  307. package/.next-prod/server/app/api/update-state/route.js +1 -1
  308. package/.next-prod/server/app/api/update-state/route.js.nft.json +1 -1
  309. package/.next-prod/server/app/api/version/route.js +1 -1
  310. package/.next-prod/server/app/api/version/route.js.nft.json +1 -1
  311. package/.next-prod/server/app/apps/[...path]/route.js +1 -1
  312. package/.next-prod/server/app/apps/[...path]/route.js.nft.json +1 -1
  313. package/.next-prod/server/app/favicon.ico/route.js.nft.json +1 -1
  314. package/.next-prod/server/app/m/page.js +1 -1
  315. package/.next-prod/server/app/m/page.js.nft.json +1 -1
  316. package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
  317. package/.next-prod/server/app/manifest.webmanifest/route.js.nft.json +1 -1
  318. package/.next-prod/server/app/page.js.nft.json +1 -1
  319. package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
  320. package/.next-prod/server/app/project/page.js.nft.json +1 -1
  321. package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
  322. package/.next-prod/server/app-paths-manifest.json +3 -3
  323. package/.next-prod/server/chunks/2493.js +11 -11
  324. package/.next-prod/server/chunks/4983.js +13 -0
  325. package/.next-prod/server/chunks/6495.js +1 -1
  326. package/.next-prod/server/chunks/7438.js +8 -8
  327. package/.next-prod/server/chunks/8490.js +232 -0
  328. package/.next-prod/server/chunks/9830.js +1 -1
  329. package/.next-prod/server/middleware-build-manifest.js +1 -1
  330. package/.next-prod/server/pages/404.html +2 -2
  331. package/.next-prod/server/pages/500.html +1 -1
  332. package/.next-prod/server/server-reference-manifest.json +1 -1
  333. package/.next-prod/static/chunks/{2550-d42d8fc88c0cec98.js → 2550-5ec6ad72e7b4c089.js} +4 -4
  334. package/.next-prod/static/chunks/{9471-8c53bd74ad056e69.js → 4210-b0cf2aaa0f2affb2.js} +2 -2
  335. package/.next-prod/static/chunks/{5313-d734a6541498a6db.js → 5313-21ec8e33f8e39afb.js} +4 -4
  336. package/.next-prod/static/chunks/{4731-3b3290b5ec84f6bd.js → 7109-9c529ec1ed2c5549.js} +2 -2
  337. package/.next-prod/static/chunks/app/{layout-26d284da8922060a.js → layout-984393154fd12d10.js} +1 -1
  338. package/.next-prod/static/chunks/app/m/{page-6a86aa4f5ebeebfd.js → page-7d2452671b0a743a.js} +1 -1
  339. package/.next-prod/static/chunks/app/{page-88b01c311b11942a.js → page-178d75863d53265c.js} +1 -1
  340. package/.next-prod/static/chunks/app/project/{page-88b01c311b11942a.js → page-178d75863d53265c.js} +1 -1
  341. package/.next-prod/static/css/{82bfae948a79a037.css → 59110be5a0eddfe8.css} +1 -1
  342. package/.next-prod/trace +14 -14
  343. package/.next-prod/trace-build +1 -1
  344. package/dist/{chunk-2UCBL4S6.mjs → chunk-7W3MYHMA.mjs} +1 -1
  345. package/dist/{chunk-G6BCSLZX.mjs → chunk-UAWBPZHS.mjs} +6519 -6193
  346. package/dist/httpApi.mjs +4 -2
  347. package/dist/scheduledTasks.mjs +5 -5
  348. package/dist/wsServer.mjs +2 -2
  349. package/package.json +3 -3
  350. package/public/html-lib/markdown.css +49 -0
  351. package/public/html-lib/markdown.js +64 -63
  352. package/server.mjs +4 -4
  353. package/.next-prod/server/chunks/8022.js +0 -244
  354. /package/.next-prod/static/{cwGvPiCgQI4epB2d3stR2 → aNiGFZjpiAOq6qca-1rRz}/_buildManifest.js +0 -0
  355. /package/.next-prod/static/{cwGvPiCgQI4epB2d3stR2 → aNiGFZjpiAOq6qca-1rRz}/_ssgManifest.js +0 -0
@@ -3,7 +3,7 @@ ${r}
3
3
  ${t.path}`.toLowerCase().includes(e)}):l},[l,C]),E=(0,s.useMemo)(()=>l.filter(e=>!e.builtin).length,[l]),P=C.trim().length>0,$=(0,s.useCallback)(async e=>{let t=await u.t4.runPromiseExit((0,h.Eo)(e));"Success"===t._tag?(i(t=>t.filter(t=>t.id!==e)),(0,p._)(),(0,g.oR)(r("bots.removed"),"success")):(0,g.oR)((0,f.oh)(t.cause,r("bots.removeFailed")),"error")},[r]),T=(0,s.useCallback)(e=>{(0,m.F)(x.n.OpenProject,{cwd:e,file:"BOT.md"}),t()},[t]),R=(0,s.useCallback)(()=>N(!0),[]),I=(0,s.useCallback)(()=>N(!1),[]),F=(0,s.useCallback)(async()=>{N(!1),await M()},[M]);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:b.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:r("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:r("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:R,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"}),r("bots.addExisting")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground",children:(0,n.jsx)(a.A,{className:"w-5 h-5"})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:d?(0,n.jsx)("p",{className:"text-center text-sm text-muted-foreground py-8",children:r("common.loading")}):(0,n.jsxs)(n.Fragment,{children:[L.length>0&&(0,n.jsx)("div",{className:b.jL,children:L.map(e=>(0,n.jsx)(j,{bot:e,onOpen:T,onRemove:$},e.id))}),0===L.length&&P&&(0,n.jsx)("p",{className:"text-center text-sm text-muted-foreground py-8",children:r("bots.emptyNoMatch")}),!P&&0===E&&(0,n.jsxs)("div",{className:`text-center text-muted-foreground py-8 text-sm space-y-2${L.length>0?" mt-4 border-t border-border/60":""}`,children:[(0,n.jsx)("p",{children:r("bots.emptyNoBots")}),(0,n.jsxs)("p",{children:[r("bots.emptyCreatePrefix")," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-foreground font-mono text-xs",children:"/bot"})," ",r("bots.emptyCreateSuffix")]}),(0,n.jsx)("p",{children:(0,n.jsx)("button",{type:"button",onClick:R,className:"text-brand hover:underline",children:r("bots.emptyAddExisting")})})]})]})})]}),y&&(0,n.jsx)(w,{onCancel:I,onAdded:F})]}):null}let j=(0,s.memo)(function({bot:e,onOpen:t,onRemove:r}){let{t:o}=(0,c.Bd)(),[a,u]=(0,s.useState)(!1);return(0,n.jsx)("div",{className:"group rounded-lg border border-border bg-card p-3 min-w-0",children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)(l.A,{className:"w-5 h-5 mt-0.5 text-brand flex-shrink-0"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("span",{className:"font-medium text-sm text-foreground",children:["@",e.name]}),e.builtin&&(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-hover text-muted-foreground",children:o("bots.builtin")}),!e.valid&&(0,n.jsx)("span",{className:"text-[10px] text-destructive",children:o("bots.invalid")})]}),(0,n.jsx)("p",{className:`text-xs mt-1 line-clamp-2 ${e.valid?"text-muted-foreground":"text-destructive"}`,children:e.valid?e.description:e.error}),(0,n.jsx)("p",{className:"text-[11px] text-foreground-subtle font-mono mt-2 truncate",title:e.path,children:e.path})]}),(0,n.jsxs)("div",{className:`flex items-center gap-1 transition-opacity ${a?"opacity-100":"opacity-0 group-hover:opacity-100 focus-within:opacity-100"}`,children:[(0,n.jsx)("button",{onClick:()=>t(e.path),className:"p-1 text-foreground-subtle hover:text-foreground",title:o("bots.open"),children:(0,n.jsx)(i.A,{className:"w-4 h-4"})}),e.builtin?null:a?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{u(!1),r(e.id)},className:"px-2 py-1 text-xs rounded bg-destructive text-destructive-foreground hover:bg-destructive/90",children:o("common.confirm")}),(0,n.jsx)("button",{onClick:()=>u(!1),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:o("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>u(!0),className:"p-1 text-foreground-subtle hover:text-destructive",title:o("bots.remove"),children:(0,n.jsx)(d.A,{className:"w-4 h-4"})})]})]})})});function w({onCancel:e,onAdded:t}){let{t:r}=(0,c.Bd)(),[o,a]=(0,s.useState)(""),[l,i]=(0,s.useState)(!1),d=(0,s.useCallback)(async()=>{let e=o.trim();if(!e||l)return;i(!0);let n=await u.t4.runPromiseExit((0,h.zB)(e));if(i(!1),"Success"===n._tag){let{alreadyExists:e}=n.value;(0,g.oR)(r(e?"bots.alreadyAdded":"bots.added"),e?"info":"success"),e||(0,p._)(),t()}else(0,g.oR)((0,f.oh)(n.cause,r("bots.saveFailed")),"error")},[o,l,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:()=>!l&&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=>a(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:l,onClick:e,className:"px-3 py-1.5 text-xs rounded border border-border",children:r("common.cancel")}),(0,n.jsx)("button",{disabled:l||!o.trim(),onClick:()=>void d(),className:"px-3 py-1.5 text-xs rounded bg-brand text-white disabled:opacity-50",children:l?r("common.loading"):r("common.confirm")})]})]})]})}},2228:(e,t,r)=>{r.d(t,{ProjectItem:()=>f});var n=r(95155),s=r(12115),o=r(79114),a=r(86957),l=r(16147),i=r(68287),d=r(2111),c=r(39872),u=r(53213);function m({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)(l.w,{wash:(0,i.JQ)(e.status,!1),ring:(0,i.QV)(e.status),bot:e.bot,children:e.label})})}let x=[],h=()=>{};function f({index:e,name:t,cwd:r,isActive:l,collapsed:i,hasUnread:p,isLoading:g,sessionBadges:b,onClick:v,onSelectSession:j,onRemove:w,onOpenNote:k}){let{t:y}=(0,o.Bd)(),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(null),L=(0,s.useCallback)(()=>{a.t4.runPromiseExit((0,u.ue)(r)).then(e=>{"Success"===e._tag&&M(e.value.branch)})},[r]);(0,s.useEffect)(()=>{L()},[L]);let E=(0,s.useCallback)(e=>{e?.type==="watch"&&Array.isArray(e.data)&&e.data.some(e=>"git"===e.type)&&L()},[L]);(0,d.h)({url:`/ws/watch?cwd=${encodeURIComponent(r)}`,onMessage:E});let P=b??x,$=S?i?`${t} \xb7 ${S}`:S: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":""} ${l?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary hover:text-foreground"}`,onClick:v,onMouseEnter:()=>C(!0),onMouseLeave:()=>C(!1),"data-tooltip":$,children:[(0,n.jsx)(c.B,{number:e+1,status:i?g?"loading":p&&!l?"unread":"normal":"normal",isActive:l}),!i&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:`flex-1 truncate text-sm ${l?"text-brand":""}`,children:t}),N&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[k&&(0,n.jsx)("button",{className:"p-1 rounded hover:bg-hover text-muted-foreground hover:text-foreground transition-colors",onClick:e=>{e.stopPropagation(),k()},title:y("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(),w()},title:y("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"})})})]}),P.length>0&&(0,n.jsx)("div",{className:"flex items-center gap-1 flex-shrink-0",children:P.map(e=>(0,n.jsx)(m,{badge:e,onSelect:j??h},e.sessionId))})]})]})}},4426:(e,t,r)=>{r.d(t,{ProjectSidebar:()=>er});var n=r(95155),s=r(12115),o=r(79114),a=r(52252),l=r(49619),i=r(2228),d=r(50538),c=r(68287),u=r(66109),m=r(86957),x=r(83448),h=r(92689),f=r(7578),p=r(84444);function g({isOpen:e,onClose:t,onSwitchProject:r,sessionNumbers:a={}}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)([]),[c,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)(""),y=(0,s.useRef)(null),N=(0,s.useCallback)(async()=>{b(!0),j(null);let e=await m.t4.runPromiseExit((0,x.z2)());"Success"===e._tag?d([...e.value]):j(l("sessions.loadSessionsFailed")),b(!1)},[l]);(0,s.useEffect)(()=>{e&&(N(),setTimeout(()=>{y.current?.focus(),y.current?.select()},100))},[e,N]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let C=(0,p.H)(i).filter(e=>{if(!w)return!0;let t=w.toLowerCase();return void 0!==e.searchText?e.searchText.includes(t):e.cwd.toLowerCase().includes(t)||(e.title?.toLowerCase().includes(t)??!1)||(e.lastUserMessage?.toLowerCase().includes(t)??!1)||(e.firstMessages?.some(e=>e.toLowerCase().includes(t))??!1)||(e.lastMessages?.some(e=>e.toLowerCase().includes(t))??!1)});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:u.aO,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-1 min-w-0",children:(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:l("sessions.recentSessions")})}),(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:y,type:"text",placeholder:l("sessions.searchSessions"),value:w,onChange:e=>k(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"}),w&&(0,n.jsx)("button",{onClick:()=>{k(""),y.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:l("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.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[c&&(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:l("sessions.loadingSessions")})]})}),v&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:v})}),!c&&!v&&0===C.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:w?l("sessions.noMatchingSessions"):l("sessions.noSessions")})}),!c&&!v&&C.length>0&&(0,n.jsx)("div",{className:u.jL,children:C.map(e=>{let s;return(0,n.jsxs)("div",{onClick:()=>{r(e.cwd,e.sessionId),t()},className:"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)(h.S,{engine:e.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate flex-1","data-tooltip":e.cwd,children:(s=e.cwd).split("/").pop()||s}),(0,n.jsx)(f.l,{coordinate:a[`${e.cwd}
4
4
  ${e.sessionId}`],status:(0,f.S)(e.status),statusLabel:"loading"===e.status?l("sessions.running"):"unread"===e.status?l("sessions.done"):void 0,bot:e.bot,className:"ml-auto"})]}),e.title&&(0,n.jsx)("div",{className:"text-xs font-medium text-foreground truncate mb-1","data-tooltip":e.title,children:e.title}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(e.lastActive).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(e.firstMessages?.length??0)>0||(e.lastMessages?.length??0)>0?(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[e.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}`)),(e.lastMessages?.length??0)>0&&(0,n.jsx)("div",{className:"text-foreground-subtle text-center py-0.5",children:"\xb7\xb7\xb7"}),e.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}`))]}):e.lastUserMessage?(0,n.jsxs)("div",{className:"text-xs text-foreground truncate","data-tooltip":e.lastUserMessage,children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e.lastUserMessage]}):null]},`${e.cwd}-${e.sessionId}`)})})]})]})]}):null}var b=r(53213);let v=e=>e.split("/").pop()||e;function j(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 w(e,t){return"loading"===t?e("sessions.running"):"unread"===t?e("sessions.done"):void 0}function k(){let[e,t]=(0,s.useState)(null),[r,n]=(0,s.useState)({}),o=(0,s.useCallback)((e,r)=>{let s=r.currentTarget.getBoundingClientRect(),o=s.top;o+260>window.innerHeight&&(o=Math.max(8,window.innerHeight-260-8)),t({session:e,top:o,left:s.right+8}),n(t=>e.cwd in t?t:(m.t4.runPromiseExit((0,b.ue)(e.cwd)).then(t=>{"Success"===t._tag&&n(r=>({...r,[e.cwd]:t.value.branch}))}),{...t,[e.cwd]:null}))},[]),a=(0,s.useCallback)(()=>t(null),[]);return{card:e,branch:e?r[e.session.cwd]??null:null,show:o,hide:a}}function y({card:e,branch:t}){if(!e)return null;let{session:r}=e,s=(r.firstMessages?.length??0)>0||(r.lastMessages?.length??0)>0;return(0,n.jsxs)("div",{className:"fixed z-[60] w-72 max-h-[260px] overflow-y-auto bg-popover border border-border rounded-lg shadow-lv2 p-3 pointer-events-none",style:{top:e.top,left:e.left},children:[(0,n.jsx)("div",{className:"text-xs font-medium text-foreground truncate",children:v(r.cwd)}),r.title&&(0,n.jsx)("div",{className:"text-xs font-medium text-foreground truncate mt-0.5",children:r.title}),(0,n.jsx)("div",{className:"text-[10px] text-foreground-faint truncate mt-0.5",children:r.cwd}),t&&(0,n.jsxs)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-normal min-w-0",children:[(0,n.jsxs)("svg",{className:"w-3 h-3 flex-shrink-0 text-brand",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2.5"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2.5"}),(0,n.jsx)("circle",{cx:"18",cy:"7",r:"2.5"}),(0,n.jsx)("path",{strokeLinecap:"round",d:"M6 8.5v7M8.5 6.5h4.5a3 3 0 013 3v0"})]}),(0,n.jsx)("span",{className:"truncate",children:t})]}),s?(0,n.jsxs)("div",{className:"space-y-0.5 text-xs border-t border-border/50 mt-2 pt-2",children:[r.firstMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground/90 truncate",children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`f-${t}`)),(r.lastMessages?.length??0)>0&&(0,n.jsx)("div",{className:"text-foreground-subtle text-center py-0.5",children:"\xb7\xb7\xb7"}),r.lastMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground/90 truncate",children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`l-${t}`))]}):r.lastUserMessage?(0,n.jsx)("div",{className:"text-xs text-foreground/90 border-t border-border/50 mt-2 pt-2 line-clamp-3 break-words",children:r.lastUserMessage}):null]})}function N({currentCwd:e,onSwitchProject:t,onResolveSessionNumbers:r,collapsed:a,sessions:l}){let{t:i}=(0,o.Bd)(),u=(0,s.useMemo)(()=>(0,p.H)(l),[l]),[m,x]=(0,s.useState)(!1),[b,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)({}),L=(0,s.useRef)(0),E=(0,s.useRef)(null),P=k(),{show:$,hide:T}=P;(0,s.useEffect)(()=>{m||T()},[m,T]),(0,s.useEffect)(()=>{if(!m)return;let e=e=>{E.current&&!E.current.contains(e.target)&&x(!1)},t=()=>{x(!1)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[m]);let R=(0,s.useCallback)(e=>{t(e.cwd,e.sessionId),x(!1)},[t]),I=(0,s.useCallback)(()=>{let e=!m;if(x(e),e){let e=++L.current;M({}),r().then(t=>{L.current===e&&M(t)})}else L.current+=1},[m,r]),F=l.filter(e=>"loading"===e.status).length,B=l.filter(e=>"unread"===e.status).length;return(0,n.jsxs)("div",{className:"relative",ref:E,children:[(0,n.jsxs)("button",{onClick:I,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?i("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:i("sessions.recentSessions")}),F>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:F}),B>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&&!F?"absolute -top-1 -right-1":""}`,children:B})]}),m&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 h-[600px] bg-popover border border-border rounded-lg shadow-lv2 z-50 flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg flex items-center",children:[(0,n.jsx)("span",{className:"text-sm font-medium",children:i("sessions.recentSessions")}),F>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-orange-11",children:["(",i("sessions.runningCount",{count:F}),")"]}),B>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-orange-11",children:["(",i("sessions.unreadCount",{count:B}),")"]}),(0,n.jsxs)("button",{onClick:()=>{x(!1),C(!0)},className:"ml-auto flex items-center gap-1 p-1 -mr-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:i("sessions.searchRecentSessions"),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:"m21 21-4.35-4.35m2.35-5.4a7.75 7.75 0 1 1-15.5 0 7.75 7.75 0 0 1 15.5 0Z"})}),(0,n.jsx)("span",{className:"text-xs",children:i("sessions.search")})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===u.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("sessions.noSessions")}):u.map((t,r)=>(0,n.jsx)("button",{onClick:()=>R(t),onMouseEnter:e=>$(t,e),onMouseLeave:T,className:`w-full px-3 py-2 text-left hover:bg-hover transition-colors flex items-start gap-2 ${r!==u.length-1?"border-b border-border/50":""} ${e===t.cwd?"bg-accent/50":""}`,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)(h.S,{engine:t.engine}),(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:v(t.cwd)}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:j(i,t.lastActive)}),(0,n.jsx)(f.l,{coordinate:S[`${t.cwd}
5
5
  ${t.sessionId}`],status:(0,f.S)(t.status),statusLabel:w(i,t.status),bot:t.bot,className:"ml-auto"})]}),t.title&&(0,n.jsx)("div",{className:"text-xs font-medium text-foreground truncate","data-tooltip":t.title,children:t.title}),t.lastUserMessage&&(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:t.lastUserMessage})]})},`${t.cwd}-${t.sessionId}`))})]}),(0,n.jsx)(y,{...P}),(0,n.jsx)(g,{isOpen:b,onClose:()=>C(!1),onSwitchProject:t,sessionNumbers:S})]})}var C=r(49433);let S=(e,t)=>`${e}
6
- ${t}`;function M({collapsed:e,pinnedSessions:t,sessionNumbers:r,currentCwd:a,onSwitchProject:l,onUnpin:i,onUpdateTitle:d,onReorder:c}){let{t:u}=(0,o.Bd)(),[p,g]=(0,s.useState)(!1),b=(0,s.useRef)(null),[N,L]=(0,s.useState)(null),[E,P]=(0,s.useState)(""),$=(0,s.useRef)(null),T=k(),{show:R,hide:I}=T,[F,B]=(0,s.useState)(null),[D,A]=(0,s.useState)(null),[H,z]=(0,s.useState)({});(0,s.useEffect)(()=>{p&&m.t4.runPromise((0,x.z2)().pipe(C.YWq({onSuccess:e=>z(Object.fromEntries(e.map(e=>[S(e.cwd,e.sessionId),e]))),onFailure:()=>{}})))},[p]),(0,s.useEffect)(()=>{if(!p)return;let e=e=>{b.current&&!b.current.contains(e.target)&&(g(!1),L(null))},t=()=>{g(!1),L(null)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[p]),(0,s.useEffect)(()=>{p||I()},[p,I]),(0,s.useEffect)(()=>{N&&($.current?.focus(),$.current?.select())},[N]);let W=(0,s.useCallback)(e=>{N||(l(e.cwd,e.sessionId),g(!1))},[l,N]),O=(0,s.useCallback)((e,t)=>{t.stopPropagation(),I(),L(e.sessionId),P(e.customTitle||"")},[I]),_=(0,s.useCallback)(()=>{N&&E.trim()&&d(N,E.trim()),L(null)},[N,E,d]),q=(0,s.useCallback)(e=>{I(),B(e)},[I]),V=(0,s.useCallback)((e,t)=>{e.preventDefault(),A(t)},[]),U=(0,s.useCallback)(e=>{if(null===F||F===e){B(null),A(null);return}let r=[...t],[n]=r.splice(F,1);r.splice(e,0,n),c(r),B(null),A(null)},[F,t,c]),K=(0,s.useCallback)(()=>{B(null),A(null)},[]);return(0,n.jsxs)("div",{className:"relative",ref:b,children:[(0,n.jsxs)("button",{onClick:()=>g(!p),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?u("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:u("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})]}),p&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 max-h-[450px] bg-popover border border-border rounded-lg shadow-lv2 z-50 flex flex-col",children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:u("sessions.favorites")})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:u("sessions.noFavorites")}):t.map((e,s)=>{let o=H[S(e.cwd,e.sessionId)],l=N===e.sessionId;return(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>q(s),onDragOver:e=>V(e,s),onDrop:()=>U(s),onDragEnd:K,onClick:()=>W(e),onMouseEnter:t=>{l||R(o??{cwd:e.cwd,sessionId:e.sessionId,title:e.customTitle},t)},onMouseLeave:I,className:`group w-full px-3 py-2 text-left hover:bg-hover transition-colors flex items-start gap-2 cursor-pointer ${s!==t.length-1?"border-b border-border/50":""} ${a===e.cwd?"bg-accent/50":""} ${F===s?"opacity-50":""} ${D===s?"border-t-2 border-brand":""}`,children:[(0,n.jsx)("span",{className:"mt-1.5 text-muted-foreground/30 flex-shrink-0 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-2",children:[(0,n.jsx)(h.S,{engine:o?.engine}),(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:v(e.cwd)}),o?.lastActive?(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:j(u,o.lastActive)}):null,(0,n.jsx)(f.l,{coordinate:r?.[S(e.cwd,e.sessionId)],status:(0,f.S)(o?.status),statusLabel:w(u,o?.status),bot:o?.bot,className:"ml-auto"})]}),l?(0,n.jsx)("input",{ref:$,type:"text",value:E,onChange:e=>P(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||("Enter"===e.key&&_(),"Escape"===e.key&&L(null))},onBlur:_,onClick:e=>e.stopPropagation(),className:"w-full text-xs px-1 py-0.5 border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring mt-0.5"}):(0,n.jsx)("div",{className:"text-xs font-medium text-foreground truncate",children:e.customTitle||o?.title||e.sessionId.slice(0,8)}),!l&&o?.lastUserMessage&&(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:o.lastUserMessage})]}),!l&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity mt-0.5",children:[(0,n.jsx)("button",{onClick:t=>O(e,t),className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:u("sessions.editTitle"),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:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),I(),i(e.sessionId)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:u("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"})})})]})]},e.sessionId)})})]}),(0,n.jsx)(y,{...T})]})}var L=r(80860),E=r(34075),P=r(23121),$=r(93777),T=r(95686),R=r(23883),I=r(67589);function F({task:e,onOpenSession:t}){let{t:r}=(0,o.Bd)(),{cwd:a,sessionId:l}=e,[i,d]=(0,s.useState)(null),c=(0,s.useRef)(void 0);(0,s.useEffect)(()=>{let e=!1,t=async()=>{let t=await m.t4.runPromiseExit((0,I.z)({cwd:a,sessionId:l,limit:20,ifFingerprint:c.current}));if(e)return;if("Success"!==t._tag||!t.value)return void d(e=>e??[]);let r=t.value;r.fingerprint&&(c.current=r.fingerprint),!r.notModified&&r.messages&&d(r.messages)};t();let r=setInterval(t,5e3);return()=>{e=!0,clearInterval(r)}},[a,l]);let u=(0,s.useRef)(null),x=(0,s.useRef)(null),h=(0,s.useRef)(!0),[f,p]=(0,s.useState)(!0),g=(0,s.useCallback)(()=>{let e=u.current;if(!e)return;let t=e.scrollTop+e.clientHeight>=e.scrollHeight-40;h.current=t,p(t||e.scrollTop<=40)},[]);return(0,s.useLayoutEffect)(()=>{let e=u.current;e&&h.current&&(e.scrollTop=e.scrollHeight)},[i]),(0,s.useEffect)(()=>{let e=x.current;if(!e)return;let t=new ResizeObserver(g);return t.observe(e),()=>t.disconnect()},[g,i]),(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":a,children:(0,P.P_)(a)}),(0,n.jsx)("div",{className:"text-[11px] text-muted-foreground truncate","data-tooltip":(0,P.Q_)(e),children:(0,P.Q_)(e)})]})}),(0,n.jsxs)("div",{className:"relative flex-1 min-h-0 flex",children:[(0,n.jsx)("div",{ref:u,onScroll:g,className:"flex-1 overflow-y-auto px-8 py-4",children:null===i||0===i.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:r(null===i?"common.loading":"scheduledTasks.noTaskMessages")}):(0,n.jsx)("div",{ref:x,className:"mx-auto w-full max-w-[var(--chat-column)] [&_a]:pointer-events-none",children:i.map(e=>(0,n.jsx)(R.s,{message:e,cwd:a,disableOverlays:!0},e.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:t,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 ${f?"opacity-100 pointer-events-auto":"opacity-0"}`,title:r("scheduledTasks.openSession"),children:[(0,n.jsx)("span",{children:r("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"})})]})})]})]})}var B=r(15317);function D(e){return e.engine||"claude"}function A(e){return!!e.completed&&!e.firingSince}function H(e){return e.lastFiredAt??e.createdAt}let z=[{key:"pendingReview",labelKey:"scheduledTasks.groupPendingReview"},{key:"upcoming",labelKey:"scheduledTasks.groupUpcoming"},{key:"paused",labelKey:"scheduledTasks.paused"}];function W({collapsed:e,tasks:t,unreadCount:r,sessionNumbers:a,onSwitchProject:l,onPause:i,onResume:d,onTrigger:c,onDelete:p,onMarkRead:g,onUpdateTask:b}){let{t:v}=(0,o.Bd)(),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(null),N=(0,s.useRef)(null),C=(0,s.useRef)(null),[S,M]=(0,s.useState)(null),R=(0,s.useCallback)(()=>{y(null),N.current=null,M(null)},[]),[I,O]=(0,s.useState)(null),[_,q]=(0,s.useState)(null),[V,U]=(0,s.useState)(null),[K,Q]=(0,s.useState)(null),J=t.filter(e=>!A(e)),G=J.filter(e=>!e.paused).length,Y=(0,s.useMemo)(()=>(function(e){let t=[],r=[],n=[];for(let s of e)s.unread||A(s)?t.push(s):s.paused?n.push(s):r.push(s);return t.sort((e,t)=>Number(!!t.unread)-Number(!!e.unread)||H(t)-H(e)),r.sort((e,t)=>(e.nextFireTime||Number.MAX_SAFE_INTEGER)-(t.nextFireTime||Number.MAX_SAFE_INTEGER)),n.sort((e,t)=>H(t)-H(e)),{pendingReview:t,upcoming:r,paused:n}})(t),[t]),Z=V?t.find(e=>e.id===V)??null:null;(0,s.useEffect)(()=>{if(!j||Z)return;let e=Y.pendingReview[0]??Y.upcoming[0]??Y.paused[0];U(e?.id??null)},[j,Z,Y]);let[,X]=(0,s.useState)(0);(0,s.useEffect)(()=>{if(!j)return;let e=setInterval(()=>X(e=>e+1),1e4);return()=>clearInterval(e)},[j]),(0,s.useEffect)(()=>{if(!I)return;let e=!1;return q(null),m.t4.runPromiseExit((0,x.an)(I)).then(t=>{e||("Success"===t._tag&&void 0!==t.value.content?q(t.value.content):((0,E.oR)(v("toast.readFileFailed"),"error"),O(null)))}),()=>{e=!0}},[I,v]);let ee=(0,s.useCallback)(()=>{O(null),q(null)},[]),et=(0,s.useCallback)(async e=>{let t=!!e.taskFile;try{await navigator.clipboard.writeText(t?e.taskFile:e.message),(0,E.oR)(v(t?"common.copiedPath":"toast.copiedMessage"),"success")}catch{(0,E.oR)(v("common.copyFailed"),"error")}},[v]),er=(0,s.useCallback)(()=>{w(!1),U(null)},[]);(0,s.useEffect)(()=>{if(!j)return;let e=e=>{if("Escape"===e.key){if(I)return void ee();if(k)return void R();er()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[j,k,I,ee,er,R]),(0,s.useLayoutEffect)(()=>{if(!k)return;let e=()=>{let e=N.current,t=C.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 a=Math.max(8,Math.min(r.top,window.innerHeight-s-8));M(e=>e&&e.top===a&&e.left===o?e:{top:a,left:o})};e();let t=new ResizeObserver(e);return C.current&&t.observe(C.current),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[k]);let en=(0,s.useCallback)(e=>{l(e.cwd,e.sessionId),e.unread&&g(e.id),er()},[l,g,er]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>w(!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("scheduledTasks.title"):void 0,children:[(0,n.jsx)(L.A,{className:"w-5 h-5 flex-shrink-0"}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:v("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]}),j&&(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:er}),(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",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("scheduledTasks.title")}),J.length>0&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[v("scheduledTasks.activeCount",{running:G}),J.length-G>0?` \xb7 ${v("scheduledTasks.pausedCount",{paused:J.length-G})}`:""]})]}),(0,n.jsx)("button",{onClick:er,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("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-4",children:z.map(({key:e,labelKey:t})=>{let r=Y[e];return 0===r.length?null:(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 -mx-3 px-3 py-1 bg-card text-[11px] font-medium text-muted-foreground",children:[v(t)," (",r.length,")"]}),(0,n.jsx)("div",{className:"mt-1 space-y-2",children:r.map(e=>{let t,r;return t=e.id===V,(0,n.jsxs)("div",{onClick:()=>U(e.id),onMouseLeave:()=>Q(t=>t===e.id?null:t),className:`group p-3 rounded border cursor-pointer transition-all hover:border-brand hover:shadow-lv2 ${t?"border-brand bg-brand/5 shadow-lv2":e.unread?"border-brand/40 bg-brand/5":"border-border"} ${A(e)?"opacity-70":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)(h.S,{engine:D(e),tooltip:(r=D(e),e.model?`${r} \xb7 ${e.model}`:r)}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate flex-1","data-tooltip":e.cwd,children:(0,P.P_)(e.cwd)}),(0,n.jsx)(f.l,{coordinate:a?.[`${e.cwd}
6
+ ${t}`;function M({collapsed:e,pinnedSessions:t,sessionNumbers:r,currentCwd:a,onSwitchProject:l,onUnpin:i,onUpdateTitle:d,onReorder:c}){let{t:u}=(0,o.Bd)(),[p,g]=(0,s.useState)(!1),b=(0,s.useRef)(null),[N,L]=(0,s.useState)(null),[E,P]=(0,s.useState)(""),$=(0,s.useRef)(null),T=k(),{show:R,hide:I}=T,[F,B]=(0,s.useState)(null),[D,A]=(0,s.useState)(null),[H,z]=(0,s.useState)({});(0,s.useEffect)(()=>{p&&m.t4.runPromise((0,x.z2)().pipe(C.YWq({onSuccess:e=>z(Object.fromEntries(e.map(e=>[S(e.cwd,e.sessionId),e]))),onFailure:()=>{}})))},[p]),(0,s.useEffect)(()=>{if(!p)return;let e=e=>{b.current&&!b.current.contains(e.target)&&(g(!1),L(null))},t=()=>{g(!1),L(null)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[p]),(0,s.useEffect)(()=>{p||I()},[p,I]),(0,s.useEffect)(()=>{N&&($.current?.focus(),$.current?.select())},[N]);let W=(0,s.useCallback)(e=>{N||(l(e.cwd,e.sessionId),g(!1))},[l,N]),O=(0,s.useCallback)((e,t)=>{t.stopPropagation(),I(),L(e.sessionId),P(e.customTitle||"")},[I]),_=(0,s.useCallback)(()=>{N&&E.trim()&&d(N,E.trim()),L(null)},[N,E,d]),q=(0,s.useCallback)(e=>{I(),B(e)},[I]),V=(0,s.useCallback)((e,t)=>{e.preventDefault(),A(t)},[]),U=(0,s.useCallback)(e=>{if(null===F||F===e){B(null),A(null);return}let r=[...t],[n]=r.splice(F,1);r.splice(e,0,n),c(r),B(null),A(null)},[F,t,c]),K=(0,s.useCallback)(()=>{B(null),A(null)},[]);return(0,n.jsxs)("div",{className:"relative",ref:b,children:[(0,n.jsxs)("button",{onClick:()=>g(!p),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?u("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:u("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})]}),p&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 max-h-[450px] bg-popover border border-border rounded-lg shadow-lv2 z-50 flex flex-col",children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:u("sessions.favorites")})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:u("sessions.noFavorites")}):t.map((e,s)=>{let o=H[S(e.cwd,e.sessionId)],l=N===e.sessionId;return(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>q(s),onDragOver:e=>V(e,s),onDrop:()=>U(s),onDragEnd:K,onClick:()=>W(e),onMouseEnter:t=>{l||R(o??{cwd:e.cwd,sessionId:e.sessionId,title:e.customTitle},t)},onMouseLeave:I,className:`group w-full px-3 py-2 text-left hover:bg-hover transition-colors flex items-start gap-2 cursor-pointer ${s!==t.length-1?"border-b border-border/50":""} ${a===e.cwd?"bg-accent/50":""} ${F===s?"opacity-50":""} ${D===s?"border-t-2 border-brand":""}`,children:[(0,n.jsx)("span",{className:"mt-1.5 text-muted-foreground/30 flex-shrink-0 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-2",children:[(0,n.jsx)(h.S,{engine:o?.engine}),(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:v(e.cwd)}),o?.lastActive?(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:j(u,o.lastActive)}):null,(0,n.jsx)(f.l,{coordinate:r?.[S(e.cwd,e.sessionId)],status:(0,f.S)(o?.status),statusLabel:w(u,o?.status),bot:o?.bot,className:"ml-auto"})]}),l?(0,n.jsx)("input",{ref:$,type:"text",value:E,onChange:e=>P(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||("Enter"===e.key&&_(),"Escape"===e.key&&L(null))},onBlur:_,onClick:e=>e.stopPropagation(),className:"w-full text-xs px-1 py-0.5 border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring mt-0.5"}):(0,n.jsx)("div",{className:"text-xs font-medium text-foreground truncate",children:e.customTitle||o?.title||e.sessionId.slice(0,8)}),!l&&o?.lastUserMessage&&(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:o.lastUserMessage})]}),!l&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity mt-0.5",children:[(0,n.jsx)("button",{onClick:t=>O(e,t),className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:u("sessions.editTitle"),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:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),I(),i(e.sessionId)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:u("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"})})})]})]},e.sessionId)})})]}),(0,n.jsx)(y,{...T})]})}var L=r(80860),E=r(34075),P=r(23121),$=r(93777),T=r(95686),R=r(95539),I=r(67589);function F({task:e,onOpenSession:t}){let{t:r}=(0,o.Bd)(),{cwd:a,sessionId:l}=e,[i,d]=(0,s.useState)(null),c=(0,s.useRef)(void 0);(0,s.useEffect)(()=>{let e=!1,t=async()=>{let t=await m.t4.runPromiseExit((0,I.z)({cwd:a,sessionId:l,limit:20,ifFingerprint:c.current}));if(e)return;if("Success"!==t._tag||!t.value)return void d(e=>e??[]);let r=t.value;r.fingerprint&&(c.current=r.fingerprint),!r.notModified&&r.messages&&d(r.messages)};t();let r=setInterval(t,5e3);return()=>{e=!0,clearInterval(r)}},[a,l]);let u=(0,s.useRef)(null),x=(0,s.useRef)(null),h=(0,s.useRef)(!0),[f,p]=(0,s.useState)(!0),g=(0,s.useCallback)(()=>{let e=u.current;if(!e)return;let t=e.scrollTop+e.clientHeight>=e.scrollHeight-40;h.current=t,p(t||e.scrollTop<=40)},[]);return(0,s.useLayoutEffect)(()=>{let e=u.current;e&&h.current&&(e.scrollTop=e.scrollHeight)},[i]),(0,s.useEffect)(()=>{let e=x.current;if(!e)return;let t=new ResizeObserver(g);return t.observe(e),()=>t.disconnect()},[g,i]),(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":a,children:(0,P.P_)(a)}),(0,n.jsx)("div",{className:"text-[11px] text-muted-foreground truncate","data-tooltip":(0,P.Q_)(e),children:(0,P.Q_)(e)})]})}),(0,n.jsxs)("div",{className:"relative flex-1 min-h-0 flex",children:[(0,n.jsx)("div",{ref:u,onScroll:g,className:"flex-1 overflow-y-auto px-8 py-4",children:null===i||0===i.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:r(null===i?"common.loading":"scheduledTasks.noTaskMessages")}):(0,n.jsx)("div",{ref:x,className:"mx-auto w-full max-w-[var(--chat-column)] [&_a]:pointer-events-none",children:i.map(e=>(0,n.jsx)(R.s,{message:e,cwd:a,disableOverlays:!0},e.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:t,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 ${f?"opacity-100 pointer-events-auto":"opacity-0"}`,title:r("scheduledTasks.openSession"),children:[(0,n.jsx)("span",{children:r("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"})})]})})]})]})}var B=r(15317);function D(e){return e.engine||"claude"}function A(e){return!!e.completed&&!e.firingSince}function H(e){return e.lastFiredAt??e.createdAt}let z=[{key:"pendingReview",labelKey:"scheduledTasks.groupPendingReview"},{key:"upcoming",labelKey:"scheduledTasks.groupUpcoming"},{key:"paused",labelKey:"scheduledTasks.paused"}];function W({collapsed:e,tasks:t,unreadCount:r,sessionNumbers:a,onSwitchProject:l,onPause:i,onResume:d,onTrigger:c,onDelete:p,onMarkRead:g,onUpdateTask:b}){let{t:v}=(0,o.Bd)(),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(null),N=(0,s.useRef)(null),C=(0,s.useRef)(null),[S,M]=(0,s.useState)(null),R=(0,s.useCallback)(()=>{y(null),N.current=null,M(null)},[]),[I,O]=(0,s.useState)(null),[_,q]=(0,s.useState)(null),[V,U]=(0,s.useState)(null),[K,Q]=(0,s.useState)(null),J=t.filter(e=>!A(e)),G=J.filter(e=>!e.paused).length,Y=(0,s.useMemo)(()=>(function(e){let t=[],r=[],n=[];for(let s of e)s.unread||A(s)?t.push(s):s.paused?n.push(s):r.push(s);return t.sort((e,t)=>Number(!!t.unread)-Number(!!e.unread)||H(t)-H(e)),r.sort((e,t)=>(e.nextFireTime||Number.MAX_SAFE_INTEGER)-(t.nextFireTime||Number.MAX_SAFE_INTEGER)),n.sort((e,t)=>H(t)-H(e)),{pendingReview:t,upcoming:r,paused:n}})(t),[t]),Z=V?t.find(e=>e.id===V)??null:null;(0,s.useEffect)(()=>{if(!j||Z)return;let e=Y.pendingReview[0]??Y.upcoming[0]??Y.paused[0];U(e?.id??null)},[j,Z,Y]);let[,X]=(0,s.useState)(0);(0,s.useEffect)(()=>{if(!j)return;let e=setInterval(()=>X(e=>e+1),1e4);return()=>clearInterval(e)},[j]),(0,s.useEffect)(()=>{if(!I)return;let e=!1;return q(null),m.t4.runPromiseExit((0,x.an)(I)).then(t=>{e||("Success"===t._tag&&void 0!==t.value.content?q(t.value.content):((0,E.oR)(v("toast.readFileFailed"),"error"),O(null)))}),()=>{e=!0}},[I,v]);let ee=(0,s.useCallback)(()=>{O(null),q(null)},[]),et=(0,s.useCallback)(async e=>{let t=!!e.taskFile;try{await navigator.clipboard.writeText(t?e.taskFile:e.message),(0,E.oR)(v(t?"common.copiedPath":"toast.copiedMessage"),"success")}catch{(0,E.oR)(v("common.copyFailed"),"error")}},[v]),er=(0,s.useCallback)(()=>{w(!1),U(null)},[]);(0,s.useEffect)(()=>{if(!j)return;let e=e=>{if("Escape"===e.key){if(I)return void ee();if(k)return void R();er()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[j,k,I,ee,er,R]),(0,s.useLayoutEffect)(()=>{if(!k)return;let e=()=>{let e=N.current,t=C.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 a=Math.max(8,Math.min(r.top,window.innerHeight-s-8));M(e=>e&&e.top===a&&e.left===o?e:{top:a,left:o})};e();let t=new ResizeObserver(e);return C.current&&t.observe(C.current),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[k]);let en=(0,s.useCallback)(e=>{l(e.cwd,e.sessionId),e.unread&&g(e.id),er()},[l,g,er]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>w(!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("scheduledTasks.title"):void 0,children:[(0,n.jsx)(L.A,{className:"w-5 h-5 flex-shrink-0"}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:v("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]}),j&&(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:er}),(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",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("scheduledTasks.title")}),J.length>0&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[v("scheduledTasks.activeCount",{running:G}),J.length-G>0?` \xb7 ${v("scheduledTasks.pausedCount",{paused:J.length-G})}`:""]})]}),(0,n.jsx)("button",{onClick:er,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("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-4",children:z.map(({key:e,labelKey:t})=>{let r=Y[e];return 0===r.length?null:(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 -mx-3 px-3 py-1 bg-card text-[11px] font-medium text-muted-foreground",children:[v(t)," (",r.length,")"]}),(0,n.jsx)("div",{className:"mt-1 space-y-2",children:r.map(e=>{let t,r;return t=e.id===V,(0,n.jsxs)("div",{onClick:()=>U(e.id),onMouseLeave:()=>Q(t=>t===e.id?null:t),className:`group p-3 rounded border cursor-pointer transition-all hover:border-brand hover:shadow-lv2 ${t?"border-brand bg-brand/5 shadow-lv2":e.unread?"border-brand/40 bg-brand/5":"border-border"} ${A(e)?"opacity-70":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)(h.S,{engine:D(e),tooltip:(r=D(e),e.model?`${r} \xb7 ${e.model}`:r)}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate flex-1","data-tooltip":e.cwd,children:(0,P.P_)(e.cwd)}),(0,n.jsx)(f.l,{coordinate:a?.[`${e.cwd}
7
7
  ${e.sessionId}`]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0 group-hover:hidden",children:e.firingSince?v("scheduledTasks.inFlight"):A(e)?v("scheduledTasks.completed"):e.paused?v("scheduledTasks.paused"):v("common.running")}),K===e.id?(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),Q(null),p(e.id)},className:"px-2 py-0.5 text-[10px] rounded bg-red-9 text-white hover:bg-red-10",children:v("common.confirm")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),Q(null)},className:"px-2 py-0.5 text-[10px] rounded border border-border text-muted-foreground hover:text-foreground",children:v("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(),O(e.taskFile)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:v("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(),et(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:v(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(),c(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-brand",title:v("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(),N.current=t.currentTarget,y(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:v("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"})})}),A(e)?null:e.paused?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),d(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-green-11",title:v("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(),i(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-amber-11",title:v("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(),Q(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:v("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,P.Q_)(e),children:(0,P.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,B.dp)(e.delayMinutes??0,t)});if("interval"===e.type){var r;let n,s,o,a=t("scheduledTasks.everyDuration",{duration:(0,B.dp)(e.intervalMinutes??0,t)});return(e.startAt&&(a+=` \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)?`${a} (${e.activeFrom}-${e.activeTo})`:a}return"cron"===e.type?e.cron||"cron":e.type}(e,v)}),(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsx)("span",{className:"flex-shrink-0",children:e.firingSince?v("scheduledTasks.inFlight"):A(e)?"success"===e.lastResult?v("scheduledTasks.success"):"interrupted"===e.lastResult?v("scheduledTasks.interrupted"):v("scheduledTasks.failure"):e.paused?v("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,v)}),!A(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:[v("scheduledTasks.lastResult"),":"," ","success"===e.lastResult?"✓":"interrupted"===e.lastResult?v("scheduledTasks.interrupted"):"✗"]})]})]})]},e.id)})})]},e)})})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:Z?(0,n.jsx)(F,{task:Z,onOpenSession:()=>en(Z)},Z.id):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:v("scheduledTasks.selectTaskHint")})})]})})]})]}),I&&null!==_&&(0,n.jsx)(T.x,{filePath:I,content:_,cwd:I.slice(0,Math.max(0,I.lastIndexOf("/"))),onClose:ee,zClassName:"z-[80]"}),k&&(0,n.jsx)("div",{ref:C,className:"fixed z-[100]",style:{top:S?.top??0,left:S?.left??0,visibility:S?"visible":"hidden"},children:(0,n.jsx)($.E,{onClose:R,onCreate:()=>{},editTask:{id:k.id,message:k.message,taskFile:k.taskFile,type:k.type,delayMinutes:k.delayMinutes,intervalMinutes:k.intervalMinutes,activeFrom:k.activeFrom,activeTo:k.activeTo,startAt:k.startAt,cron:k.cron},onUpdate:(e,t)=>{b(e,t),R()}})})]})}var O=r(42804),_=r(39872),q=r(2111),V=r(94720);function U({collapsed:e,currentCwd:t,projectOrder:r,onFocusTerminal:a}){let{t:l}=(0,o.Bd)(),{terminals:i,refresh:d}=function(){let[e,t]=(0,s.useState)([]),r=(0,s.useRef)(null),n=(0,s.useCallback)(()=>{m.t4.runPromiseExit((0,V.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,q.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),[x,h]=(0,s.useState)(()=>Date.now()),[f,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(()=>new Set),w=(0,s.useRef)(new Map),k=(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]),y=(0,s.useMemo)(()=>k.flatMap(e=>e.items),[k]),N=(0,s.useCallback)(()=>{u(!1),b(null)},[]),C=(0,s.useCallback)(()=>{d(),h(Date.now()),u(!0)},[d]);(0,s.useEffect)(()=>{if(!c)return;let e=setInterval(()=>h(Date.now()),1e3);return()=>clearInterval(e)},[c]),(0,s.useEffect)(()=>{let e=new Set(i.map(e=>e.commandId));for(let[t,r]of(j(t=>{let r=new Set([...t].filter(t=>e.has(t)));return r.size===t.size?t:r}),w.current))e.has(t)||(clearTimeout(r),w.current.delete(t))},[i]),(0,s.useEffect)(()=>{let e=w.current;return()=>{for(let t of e.values())clearTimeout(t)}},[]);let S=(0,s.useCallback)(e=>{N(),a(e.projectCwd,e.commandId)},[N,a]),M=(0,s.useCallback)(e=>{b(null),j(t=>new Set(t).add(e.commandId));let t=()=>{w.current.delete(e.commandId),j(t=>{let r=new Set(t);return r.delete(e.commandId),r}),(0,E.oR)(l("runningTerminals.stopFailed"),"error")};m.t4.runPromiseExit((0,V.px)(e.commandId)).then(r=>{"Success"!==r._tag?t():r.value.interrupted?w.current.set(e.commandId,setTimeout(t,3e3)):d()})},[d,l]);(0,s.useEffect)(()=>{if(!c)return;let e=e=>{if("Escape"===e.key){e.preventDefault(),g?b(null):N();return}if(0===y.length)return;let t=y.findIndex(e=>e.commandId===f);if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault();let r="ArrowDown"===e.key?1:-1,n=t<0?r>0?0:y.length-1:(t+r+y.length)%y.length;p(y[n].commandId),b(null);return}let r=t>=0?y[t]:null;r&&("Enter"===e.key?(e.preventDefault(),g===r.commandId?M(r):S(r)):("Delete"===e.key||"Backspace"===e.key)&&(e.preventDefault(),v.has(r.commandId)||b(r.commandId)))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[c,y,f,g,v,N,S,M]);let L=e=>{var t,r;let s,o,a,i,d=v.has(e.commandId),c=g===e.commandId,u=(t=e.cwd,r=e.projectCwd,t&&t!==r?t.startsWith(r+"/")?t.slice(r.length+1):t:""),m=e.title||e.command.split("\n")[0];return(0,n.jsxs)("div",{"data-running-terminal":e.commandId,onClick:()=>{d||S(e)},onMouseEnter:()=>p(e.commandId),title:`${e.command}
8
8
  pid ${e.pid}`,className:`group rounded-md px-3 py-2 transition-colors ${d?"opacity-50 cursor-default":"cursor-pointer"} ${!d&&f===e.commandId?"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 font-mono text-[10px] px-1 rounded bg-muted text-muted-foreground",children:e.shortId}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-sm font-mono text-foreground",children:m}),e.usePty&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-foreground-subtle",children:"PTY"}),(0,n.jsx)("span",{className:"flex-shrink-0 text-xs tabular-nums text-muted-foreground",children:(o=Math.floor((s=Math.max(0,Math.floor((x-new Date(e.timestamp).getTime())/1e3)))/86400),a=Math.floor(s%86400/3600),i=Math.floor(s%3600/60),o>0?`${o}d ${a}h`:a>0?`${a}h ${i}m`:i>0?`${i}m`:`${s}s`)}),d?(0,n.jsx)("span",{className:"flex-shrink-0 text-xs text-muted-foreground",children:l("runningTerminals.stopping")}):c?null:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),b(e.commandId)},className:"flex-shrink-0 px-1.5 py-0.5 text-xs rounded text-muted-foreground hover:text-destructive hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",children:l("runningTerminals.stop")})]}),(u||e.title)&&!c&&(0,n.jsxs)("div",{className:"mt-0.5 pl-9 text-xs text-muted-foreground truncate font-mono",children:[e.title?e.command.split("\n")[0]:u,e.title&&u?` \xb7 ${u}`:""]}),c&&(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:l("runningTerminals.confirmStop")}),(0,n.jsx)("button",{onClick:()=>b(null),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:l("common.cancel")}),(0,n.jsx)("button",{onClick:()=>M(e),className:"px-2 py-0.5 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:l("runningTerminals.stop")})]})]},e.commandId)},P=i.length;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:C,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?l("runningTerminals.title"):void 0,"data-testid":"running-terminals-entry",children:[(0,n.jsx)(O.A,{className:"w-5 h-5 flex-shrink-0"}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:l("runningTerminals.title")}),P>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:P})]}),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:N}),(0,n.jsxs)("div",{className:"relative w-[min(calc(100vw-2rem),max(42rem,60vw))] max-w-6xl h-[70vh] mx-4 bg-card rounded-lg shadow-lv3 flex flex-col overflow-hidden","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:l("runningTerminals.title")})}),(0,n.jsx)("button",{onClick:N,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===P?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:l("runningTerminals.empty")}):(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:k.map(e=>{var r;return(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)(_.B,{number:e.number,isActive:e.cwd===t}),(0,n.jsx)("span",{className:"truncate",title:e.cwd,children:(r=e.cwd).split(/[\\/]/).filter(Boolean).pop()||r}),e.cwd===t&&(0,n.jsxs)("span",{className:"text-foreground-subtle",children:["\xb7 ",l("runningTerminals.currentProject")]})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(L)})]},e.cwd)})})}),(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:l("runningTerminals.status",{count:P,projects:k.length})}),P>0&&(0,n.jsx)("span",{className:"truncate text-foreground-subtle",children:l("runningTerminals.keys")})]})]})]})]})}var K=r(3292),Q=r(76900),J=r(72363),G=r(94852),Y=r(60285);let Z=e=>"unread"===e?0:"loading"===e?1:2;function X({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 ee({item:e,active:t,onClick:r,className:s=""}){return(0,n.jsx)("button",{type:"button",onClick:r,className:`h-8 w-8 rounded-md border bg-transparent text-muted-foreground hover:text-brand hover:border-brand/70 active:scale-95 transition-all flex items-center justify-center ${t?"border-brand/80 text-brand":"border-border/70"} ${s}`,title:`${e.title}
9
9
  ${e.path}`,children:e.icon?(0,n.jsx)("span",{className:"text-base leading-none",children:e.icon}):(0,n.jsx)(G.A,{className:"w-4 h-4"})})}function et({collapsed:e,previews:t,activePath:r,onOpenApps:a,onShowPreview:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(null),u=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{u.current?.contains(e.target)||c(null)};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[d]);let m=t.length>4,x=m?t.slice(0,3):t.slice(0,4),h=m?t.slice(3):[],f=(0,n.jsxs)("button",{type:"button",onClick:()=>{a(),c(null)},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",title:i("htmlApps.title"),children:[(0,n.jsx)("span",{className:"h-7 w-7 flex-shrink-0 rounded-md border border-border/70 bg-transparent flex items-center justify-center",children:(0,n.jsx)(X,{className:"w-4 h-4"})}),(0,n.jsx)("span",{className:"min-w-0 flex-1",children:(0,n.jsx)("span",{className:"block text-xs font-medium truncate",children:i("htmlApps.title")})})]},"html-apps-list"),p=e=>{l(e),c(null)},g=e=>(0,n.jsxs)("div",{className:"max-h-[19.75rem] overflow-y-auto p-1.5 space-y-1",children:[f,e.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>p(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-7 w-7 flex-shrink-0 rounded-md border border-border/70 bg-transparent flex items-center justify-center",children:e.icon?(0,n.jsx)("span",{className:"text-base leading-none",children:e.icon}):(0,n.jsx)(G.A,{className:"w-4 h-4"})}),(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))]});return e?(0,n.jsxs)("div",{ref:u,className:"relative p-2 border-t border-border",children:[(0,n.jsx)("button",{type:"button",onClick:()=>c(e=>"collapsed"===e?null:"collapsed"),className:`w-full h-8 rounded-md border bg-transparent text-muted-foreground hover:text-brand hover:border-brand/70 transition-colors flex items-center justify-center ${r?"border-brand/80 text-brand":"border-border/70"}`,title:i("htmlApps.title"),children:(0,n.jsx)(X,{className:"w-4 h-4"})}),"collapsed"===d&&(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:g(t)})]}):(0,n.jsx)("div",{ref:u,className:"p-2 border-t border-border",children:(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-1.5",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"h-8 w-8 rounded-md border border-border/70 bg-transparent text-muted-foreground hover:text-brand hover:border-brand/70 active:scale-95 transition-all flex items-center justify-center",title:i("htmlApps.title"),children:(0,n.jsx)(X,{className:"w-4 h-4"})}),x.map(e=>(0,n.jsx)(ee,{item:e,active:r===e.path,onClick:()=>p(e)},e.path)),m&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{type:"button",onClick:()=>c(e=>"more"===e?null:"more"),className:"h-8 w-8 rounded-md border border-border/70 bg-transparent text-muted-foreground hover:text-brand hover:border-brand/70 transition-colors flex items-center justify-center",title:i("common.loadMore"),children:(0,n.jsx)(Y.A,{className:"w-4 h-4"})}),"more"===d&&(0,n.jsx)("div",{className:"absolute left-0 bottom-full mb-2 w-64 rounded-lg border border-border bg-card shadow-lv3 z-50",children:g(h)})]})]})})}function er({projects:e,activeIndex:t,collapsed:r,currentCwd:d,onSelectProject:c,onRemoveProject:u,onReorderProjects:x,onToggleCollapse:h,onOpenSessionBrowser:f,onOpenSettings:p,onOpenNote:g,onOpenSkills:b,onOpenBots:v,onOpenApps:j,htmlAppPreviews:w,activeHtmlAppPreviewPath:k,onShowHtmlAppPreview:y,onSwitchProject:C,onFocusTerminal:S,onResolveSessionNumbers:L,sessionOrders:$,sessionNumbers:T}){let R,I,{t:F,i18n:B}=(0,o.Bd)(),D=(0,s.useMemo)(()=>e.map(e=>e.cwd),[e]),{latest:A,hasUpdate:H}=function(){let[e,t]=(0,s.useState)(),[r,n]=(0,s.useState)();(0,s.useEffect)(()=>{let e=!1;m.t4.runPromiseExit((0,Q.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,a]=(0,s.useState)(!1);(0,s.useEffect)(()=>{a(!0===window.__COCKPIT_FORCE_UPDATE__)},[]);let l=!!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||l}}(),[z,O]=(0,s.useState)(!1),_=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!z)return;let e=e=>{_.current?.contains(e.target)||O(!1)},t=()=>O(!1);return document.addEventListener("mousedown",e,!0),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e,!0),window.removeEventListener("blur",t)}},[z]);let V=(0,s.useCallback)(()=>{navigator.clipboard.writeText("cockpit update"),(0,E.oR)(F("workspace.upgradeCommandCopied")),O(!1)},[F]),{isUpdating:G,start:Y}=(R=(0,s.useSyncExternalStore)(J.N4,J.fX,J.fX),I=(0,s.useCallback)(()=>{(0,J._I)()},[]),{isUpdating:R.visible&&"done"!==R.stage&&"failed"!==R.stage,start:I}),X=(0,s.useCallback)(()=>{O(!1),Y()},[Y]),{pinnedSessions:ee,unpinSession:en,updateTitle:es,reorder:eo}=(0,K.P)(),{tasks:ea,unreadCount:el,reload:ei,pauseTask:ed,resumeTask:ec,triggerTask:eu,deleteTask:em,updateTask:ex,markRead:eh}=(0,P.nS)(),[ef,ep]=(0,s.useState)(null),[eg,eb]=(0,s.useState)(null),[ev,ej]=(0,s.useState)([]),ew=(0,s.useRef)(ev);(0,s.useEffect)(()=>{ew.current=ev});let ek=(0,s.useRef)(ei);(0,s.useEffect)(()=>{ek.current=ei});let ey=(0,s.useCallback)(e=>{try{if("task-fired"===e.type)return void ek.current();let{data:t}=e;if(!t)return;ej(t.sessions||[])}catch{}},[]);(0,q.h)({url:"/ws/global-state",onMessage:ey});let eN=new Set(ev.filter(e=>"loading"===e.status).map(e=>e.cwd)),eC=new Set(ev.filter(e=>"unread"===e.status).map(e=>e.cwd)),eS=(0,s.useMemo)(()=>{let t=new Map;for(let r of e){let e=$[r.cwd]??[],n=ev.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=Z(e.session.status)-Z(t.session.status);return 0!==r?r:t.session.lastActive-e.session.lastActive}),s=n.find(({session:e})=>2===Z(e.status)),o=n.filter(({session:e})=>2>Z(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,ev,$]),eM=(0,s.useCallback)(e=>{ep(e)},[]),eL=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==ef&&ef!==t&&eb(t)},[ef]),eE=(0,s.useCallback)(t=>{if(null!==ef&&ef!==t){let r=[...e],[n]=r.splice(ef,1);r.splice(t,0,n),x(r)}ep(null),eb(null)},[ef,e,x]),eP=(0,s.useCallback)(()=>{ep(null),eb(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?F("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:F("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:h,title:F("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:h,title:F("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 a;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>eM(s),onDragOver:e=>eL(e,s),onDrop:()=>eE(s),onDragEnd:eP,className:`${eg===s?"border-t-2 border-brand":""} ${ef===s?"opacity-50":""}`,children:(0,n.jsx)(i.ProjectItem,{index:s,name:(a=(o=e.cwd).split("/").filter(Boolean))[a.length-1]||o,cwd:e.cwd,isActive:s===t,collapsed:r,hasUnread:eC.has(e.cwd),isLoading:eN.has(e.cwd),sessionBadges:eS.get(e.cwd),onClick:()=>c(s),onSelectSession:t=>C(e.cwd,t),onRemove:()=>u(s),onOpenNote:()=>g(e.cwd)})},e.cwd)})}),(0,n.jsx)(et,{collapsed:r,previews:w,activePath:k,onOpenApps:j,onShowPreview:y}),(0,n.jsxs)("div",{className:"p-2 border-t border-border space-y-1",children:[(0,n.jsx)(N,{currentCwd:d,onSwitchProject:C,onResolveSessionNumbers:L,collapsed:r,sessions:ev}),(0,n.jsx)(M,{collapsed:r,pinnedSessions:ee,sessionNumbers:T,currentCwd:d,onSwitchProject:C,onUnpin:en,onUpdateTitle:es,onReorder:eo}),(0,n.jsx)(W,{collapsed:r,tasks:ea,unreadCount:el,sessionNumbers:T,onSwitchProject:C,onPause:ed,onResume:ec,onTrigger:eu,onDelete:em,onMarkRead:eh,onUpdateTask:ex}),(0,n.jsx)(U,{collapsed:r,currentCwd:d,projectOrder:D,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?F("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:F("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?F("workspace.skills"):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:F("workspace.skills")})]}),(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?F("workspace.bots"):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:F("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:F("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&&H&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500",title:A?F("workspace.updateAvailable",{version:A}):void 0})]}),!r&&(0,n.jsx)("span",{className:"flex-1 text-sm",children:F("workspace.settings")}),!r&&H&&A&&(0,n.jsxs)("div",{ref:_,className:"relative -mr-2",children:[(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),O(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:F("workspace.updateAvailable",{version:A}),"aria-label":F("workspace.updateAvailable",{version:A}),children:["v",A]}),z&&(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:F("workspace.updateAvailable",{version:A})}),(0,n.jsxs)("button",{type:"button",onClick:X,disabled:G,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:[G?(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:G?F("workspace.updating"):F("workspace.updateNow")})]}),(0,n.jsxs)("button",{type:"button",onClick:V,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:F("workspace.copyUpgradeCommand")})]}),(0,n.jsxs)("a",{href:`https://opencockpit.dev/${B.language?.startsWith("zh")?"zh":"en"}/changelog/`,target:"_blank",rel:"noopener",onClick:()=>O(!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:F("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:F("workspace.help"),"aria-label":F("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})]})})]})]})]})}},7578:(e,t,r)=>{r.d(t,{S:()=>a,l:()=>l});var n=r(95155),s=r(68287),o=r(16147);function a(e){return"loading"===e||"unread"===e?e:"normal"}function l({projectNumber:e,sessionNumber:t,coordinate:r,status:a="normal",statusLabel:i,bot:d,className:c=""}){if(r){let[n,s]=r.split(".");e??=n,t??=s}if(null==e&&null==t&&"normal"!==a&&(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)(a,!1),ring:(0,s.QV)(a),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},15317:(e,t,r)=>{r.d(t,{LV:()=>o,dp:()=>a,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 a(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:a,className:l="",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??(a?`@${a}`:void 0)};return a?(0,n.jsx)("span",{className:`relative -m-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center ${r} ${l}`,...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} ${l}`,...x,children:e})}},21484:(e,t,r)=>{r.d(t,{SettingsModal:()=>x});var n=r(95155),s=r(12115),o=r(79114),a=r(3238),l=r(34075),i=r(12786),d=r(53853),c=r(86957),u=r(49433),m=r(76900);function x({isOpen:e,onClose:t}){let{t:r,i18n:h}=(0,o.Bd)(),{theme:f,setTheme:p}=(0,a.DP)(),g=(0,d.G)(),[b,v]=(0,s.useState)(""),[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)("auto");(0,s.useEffect)(()=>{e&&c.t4.runPromiseExit((0,m.M5)()).then(e=>{"Success"===e._tag&&e.value.language&&C(e.value.language)})},[e]);let S=(0,s.useCallback)(e=>{C(e),c.t4.runFork((0,m.DZ)({language:e}).pipe(u.NWQ(()=>u.rIH)));let t="auto"===e?navigator.language.startsWith("zh")?"zh":"en":e;h.changeLanguage(t)},[h]),M=g?"installed":"not-installed",L=g?.version??null;if((0,s.useEffect)(()=>{e&&c.t4.runPromiseExit((0,m.Wr)()).then(e=>{"Success"===e._tag&&(e.value.version&&w(e.value.version),e.value.agents&&y(e.value.agents))})},[e]),(0,s.useEffect)(()=>{e&&c.t4.runPromiseExit((0,m.Or)()).then(e=>{"Success"===e._tag&&e.value.path&&v(e.value.path)})},[e]),!e)return null;let E=[{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:E.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 ${f===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:()=>S(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${N===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.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"===M?"bg-green-500":"bg-slate-400"}`}),(0,n.jsxs)("span",{children:["installed"===M&&`${r("settings.extensionInstalled")}${L?` (v${L})`:""}`,"not-installed"===M&&r("settings.extensionNotInstalled")]})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r("settings.extensionDescription")}),"installed"!==M&&(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=b||"chrome-extension";navigator.clipboard.writeText(e),(0,l.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"===M&&(0,n.jsx)("button",{onClick:()=>{g?.id&&window.chrome?.runtime?.sendMessage&&(window.chrome.runtime.sendMessage(g.id,{type:"reload"}),(0,l.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")})]}),b&&(0,n.jsx)("p",{className:"text-[11px] text-muted-foreground font-mono truncate",children:b})]})]}),(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",j?` v${j}`:""]}),(k?.claude||k?.codex)&&(0,n.jsx)("p",{className:"text-muted-foreground/60",children:[k.claude&&`Claude Code ${k.claude}`,k.codex&&`Codex ${k.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,{P_:()=>m,Q_:()=>x,nS:()=>p});var n=r(12115),s=r(95045),o=r(75346),a=r(49433),l=r(69809),i=r(34075),d=r(86957),c=r(82680);let u=(e,t,r)=>a.$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.split("/").pop()||e}function x(e){return e.resolvedPrompt||e.message||e.taskFile||""}let h="SCHEDULED_TASKS_CHANGED";function f(){(0,s.F)(o.n.ScheduledTasksChanged,{}),document.querySelectorAll("iframe").forEach(e=>{try{e.contentWindow?.postMessage({type:h},"*")}catch{}})}function p(){let[e,t]=(0,n.useState)([]),[r,s]=(0,n.useState)(0),o=(0,n.useCallback)(()=>{let e;d.t4.runPromise((e="/api/scheduled-tasks",a.$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(a.YWq({onSuccess:e=>{t(e.tasks??[]),s(e.unreadCount??0)},onFailure:()=>{}})))},[]);(0,n.useEffect)(()=>{o()},[o]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type===h&&o()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[o]);let m=(0,n.useCallback)(async e=>{let t=await d.t4.runPromiseExit(u("/api/scheduled-tasks","POST",{language:l.A.language,...e}));if("Success"!==t._tag)return null;let r=t.value;return r.task?(o(),f(),r.task):null},[o]),x=(0,n.useCallback)(async e=>{await d.t4.runPromise(u("/api/scheduled-tasks","PATCH",e).pipe(a.NLW).pipe(a.NWQ(()=>a.rIH))),o(),f()},[o]),p=(0,n.useCallback)(e=>x({id:e,action:"pause"}),[x]),g=(0,n.useCallback)(e=>x({id:e,action:"resume"}),[x]),b=(0,n.useCallback)(async e=>{await d.t4.runPromise(u("/api/scheduled-tasks","DELETE",{id:e}).pipe(a.NLW).pipe(a.as(!0),a.DM4(()=>!1)))||(0,i.oR)(l.A.t("scheduledTasks.deleteFailed"),"error"),o(),f()},[o]),v=(0,n.useCallback)((e,t)=>x({id:e,action:"update",fields:{...t,language:l.A.language}}),[x]),j=(0,n.useCallback)(e=>x({id:e,action:"trigger"}),[x]),w=(0,n.useCallback)(e=>x({id:e,action:"markRead"}),[x]);return{tasks:e,unreadCount:r,reload:o,createTask:m,pauseTask:p,resumeTask:g,triggerTask:j,deleteTask:b,updateTask:v,markRead:w,markAllRead:(0,n.useCallback)(()=>x({action:"markAllRead"}),[x]),reorderTasks:(0,n.useCallback)(e=>x({action:"reorder",fields:{orderedIds:e}}),[x])}}},24058:(e,t,r)=>{r.d(t,{TabBar:()=>h});var n=r(95155),s=r(12115),o=r(68287),a=r(16147),l=r(57125),i=r(92689),d=r(94287),c=r(64428),u=r(79114);function m({number:e,status:t,statusLabel:r,isActive:s,pinned:l,bot:i}){let d="normal"!==t?(0,o.JQ)(t,s):l?"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)(a.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 x({onNewTab:e,onNewCodexTab:t,onNewKimiTab:r,onNewGlmTab:o,onNewOllamaTab:a,onNewDeepseekTab:i}){let[d,u]=(0,s.useState)(!1),m=(0,s.useRef)(null),h=(0,s.useRef)(null),[f,p]=(0,s.useState)({top:0,right:0}),g=(0,c.F2)();return(0,s.useEffect)(()=>{if(!d)return;let e=e=>{h.current&&!h.current.contains(e.target)&&m.current&&!m.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:m,onClick:()=>{if(!d&&m.current){let e=m.current.getBoundingClientRect(),t=g?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0,s=t?.width??window.innerWidth;p({top:e.bottom+4-n,right:s-(e.right-r)})}u(e=>!e)},className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:"New tab",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"})})}),d&&(0,n.jsx)(c.ZL,{children:(0,n.jsx)("div",{ref:h,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lv2 py-1 min-w-[140px]",style:{top:f.top,right:f.right},children:l.CX.map(s=>(0,n.jsxs)("button",{onClick:()=>{u(!1),"codex"===s?t?.():"kimi"===s?r?.():"glm"===s?o?.():"ollama"===s?a?.():"deepseek"===s?i?.():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)(l.eV,{engine:s,className:"h-3.5 w-3.5"}),l.H[s]]},s))})})]})}function h({tabs:e,selectedTabId:t,unreadTabs:r,globalLoadingTabs:s,dragTabIndex:o,dragOverTabIndex:a,isPinned:l,onSwitchTab:c,onCloseTab:f,onCloseAllTabs:p,onNewTab:g,onNewCodexTab:b,onNewKimiTab:v,onNewGlmTab:j,onNewOllamaTab:w,onNewDeepseekTab:k,onOpenProjectSessions:y,onDragStart:N,onDragOver:C,onDrop:S,onDragEnd:M,sideBySide:L,onToggleSideBySide:E}){let{t:P}=(0,u.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center px-2 gap-1 overflow-x-auto",children:[e.map((e,u)=>{let x=e.id===t,h=l?.(e.id)??!1,p=e.isLoading||s.has(e.id)?"loading":r.has(e.id)&&!x?"unread":"normal";return(0,n.jsx)(d.m,{content:e.title,delay:200,className:"flex-1 min-w-16 max-w-[260px]",children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>N(u),onDragOver:e=>C(e,u),onDrop:()=>S(u),onDragEnd:M,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg border-t-[1.5px] transition-colors ${x?"border-brand bg-slate-4 text-foreground font-medium":"border-transparent text-muted-foreground hover:bg-secondary/50"} ${o===u?"opacity-50":""} ${a===u?"border-l-2 border-brand":""}`,onClick:()=>c(e.id),children:[(0,n.jsx)("div",{className:"h-4 w-4 -translate-x-1 flex-shrink-0",children:(0,n.jsx)(m,{number:u+1,status:p,statusLabel:"loading"===p?P("sessions.running"):"unread"===p?P("sessions.done"):void 0,isActive:x,pinned:h,bot:e.bot})}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.title}),(0,n.jsxs)("span",{className:"relative ml-1 h-4 w-4 translate-x-1 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)(i.S,{engine:e.engine,size:"sm"})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),f(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":P("tabBar.closeTab"),"aria-label":P("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.jsx)(x,{onNewTab:g,onNewCodexTab:b,onNewKimiTab:v,onNewGlmTab:j,onNewOllamaTab:w,onNewDeepseekTab:k}),p&&(0,n.jsx)("button",{onClick:p,className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-destructive hover:bg-hover rounded transition-colors",title:P("tabBar.closeAll"),"aria-label":P("tabBar.closeAll"),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"})})}),y&&(0,n.jsx)("button",{onClick:y,className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:P("sessions.projectSessions"),"aria-label":P("sessions.projectSessions"),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:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),E&&(0,n.jsx)("button",{onClick:E,className:"flex-shrink-0 p-1.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:L?P("chat.singlePane"):P("chat.splitPane"),"aria-label":L?P("chat.singlePane"):P("chat.splitPane"),"aria-pressed":L,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:"3",y:"4",width:"18",height:"16",rx:"2",strokeWidth:2}),!L&&(0,n.jsx)("path",{strokeWidth:2,d:"M12 4v16"})]})})]})})}},27068:(e,t,r)=>{r.d(t,{Providers:()=>g});var n=r(95155),s=r(47617),o=r(3238),a=r(34075),l=r(12115),i=r(47650);function d(e){let t=e;for(;t;){let e=t.dataset?.tooltip;if(e)return e;t=t.parentElement}return null}function c(){let[e,t]=(0,l.useState)(null),r=(0,l.useRef)(null);r.current=e;let s=(0,l.useRef)(null),o=(0,l.useRef)(null),[a,c]=(0,l.useState)({left:0,top:0}),[u,m]=(0,l.useState)(!1);return((0,l.useEffect)(()=>m(!0),[]),(0,l.useEffect)(()=>{let e=()=>{s.current&&(clearTimeout(s.current),s.current=null)},n=n=>{let o=d(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 a=n.clientX,l=n.clientY;s.current=setTimeout(()=>{t({text:o,x:a,y:l}),s.current=null},300)},o=n=>{if(!r.current)return;let s=d(n.target);if(!s){e(),t(null);return}t({text:s,x:n.clientX,y:n.clientY})},a=()=>{e(),r.current&&t(null)};return document.addEventListener("mouseover",n,!0),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",a),document.addEventListener("mousedown",a),()=>{document.removeEventListener("mouseover",n,!0),document.removeEventListener("mousemove",o),document.removeEventListener("mouseleave",a),document.removeEventListener("mousedown",a),e()}},[]),(0,l.useLayoutEffect)(()=>{if(!e||!o.current)return;let t=o.current.getBoundingClientRect(),r=window.innerWidth,n=window.innerHeight,s=e.x+12,a=e.y+16;s+t.width>r-8&&(s=r-t.width-8),s<8&&(s=8),a+t.height>n-8&&(a=e.y-t.height-8),c({left:s,top:a})},[e]),u&&e)?(0,i.createPortal)((0,n.jsx)("div",{ref:o,className:"fixed z-[9999] 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:a.left,top:a.top},children:e.text}),document.body):null}var u=r(79114),m=r(72363),x=r(2111);let h=new Set(["preparing","installing","repairing","rolling-back","restarting"]);function f(){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 p(){let{t:e}=(0,u.Bd)(),t=(0,l.useSyncExternalStore)(m.N4,m.fX,m.fX),[r,s]=(0,l.useState)(()=>Date.now()),o=(0,l.useRef)(!1),{stale:i}=function(){let[e,t]=(0,l.useState)(!1);return(0,l.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,x.D)(s);return()=>{n=!0,o()}},[e]),{stale:e}}(),[d,c]=(0,l.useState)(!1),[p,g]=(0,l.useState)(!1);(0,l.useEffect)(()=>{g(window.self===window.top)},[]),(0,l.useEffect)(()=>{p&&!o.current&&(o.current=!0,(0,m.$2)())},[p]);let b=t.visible&&h.has(t.stage);(0,l.useEffect)(()=>{if(!b)return;s(Date.now());let e=window.setInterval(()=>s(Date.now()),1e3);return()=>window.clearInterval(e)},[b]);let v=(0,l.useCallback)(()=>{navigator.clipboard.writeText(t.fixCommand),(0,a.oR)(e("workspace.updateCardFixCopied"))},[t.fixCommand,e]),j=!t.visible&&i&&!d;if(!p||!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||!h.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)(f,{}):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,m.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 g({children:e}){return(0,l.useEffect)(()=>{let e=e=>{e.preventDefault()};return document.addEventListener("contextmenu",e),()=>document.removeEventListener("contextmenu",e)},[]),(0,n.jsx)(s.I18nProvider,{children:(0,n.jsx)(o.NP,{children:(0,n.jsxs)(a.tE,{children:[e,(0,n.jsx)(c,{}),(0,n.jsx)(p,{})]})})})}},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);return(0,n.useEffect)(()=>{let e=()=>{t("visible"===document.visibilityState)};document.addEventListener("visibilitychange",e);let r=e=>{e.data?.type==="IFRAME_VISIBILITY"&&t(!!e.data.visible)};return window.addEventListener("message",r),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("message",r)}},[]),e}},45720:(e,t,r)=>{r.d(t,{X:()=>n});function n(e,t){switch(e){case"codex":return`codex 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),a=r(69809),l=r(86957),i=r(76900);function d({children:e}){return(0,s.useEffect)(()=>{l.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";a.A.language!==r&&a.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 a.A.on("languageChanged",e),()=>{a.A.off("languageChanged",e)}},[]),(0,s.useEffect)(()=>{if(window===window.parent)return;let e=e=>{e.data?.type==="cockpit:language-change"&&e.data.lang&&a.A.language!==e.data.lang&&a.A.changeLanguage(e.data.lang)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,n.jsx)(o.xC,{i18n:a.A,children:e})}},52153:(e,t,r)=>{r.d(t,{SessionBrowser:()=>g});var n=r(95155),s=r(12115),o=r(79114),a=r(66109),l=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:a,onHover:l}){return(0,n.jsxs)("div",{role:"option","aria-selected":r,onClick:()=>o(e.path),onDoubleClick:()=>a(e.path),onMouseMove:()=>l(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,a,{t:l}=(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),a=i.slice(t+1),""===r&&"~"===a?{base:"~",prefix:""}:{base:r,prefix:a});(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,$=(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&&$.length>0?0:-1)},[E,$]);let T=(0,s.useMemo)(()=>!p||p.error||P?null:E?$.find(e=>e.name.toLowerCase()===E.toLowerCase())?.path??null:p.path,[p,E,$,P]),R=(0,s.useCallback)(e=>{f(m(e,M)),N.current?.focus()},[M]),I=(0,u.Te)({count:$.length,getScrollElement:()=>C.current,estimateSize:()=>30,overscan:8});(0,s.useEffect)(()=>{k>=0&&I.scrollToIndex(k)},[k,I]);let F=p?.error&&!P?l(`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(),T&&e(T);else if("ArrowDown"===t.key)t.preventDefault(),y(e=>Math.min(e+1,$.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=$[k];e?(t.preventDefault(),R(e.path)):"Tab"===t.key&&t.preventDefault()}},placeholder:l("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:()=>T&&e(T),disabled:!T,"data-tooltip":T??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:l("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===$.length?(0,n.jsx)("div",{className:"p-3 text-xs text-muted-foreground",children:l(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.index],index:t.index,highlighted:t.index===k,top:t.start,onEnter:R,onPick:e,onHover:y},$[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)}),l("folderPicker.showHidden")]}),(0,n.jsx)("span",{className:"hidden md:inline text-foreground-subtle",children:l("folderPicker.hint")})]})]})}var f=r(7578),p=r(92689);function g({isOpen:e,onClose:t,onSelectSession:r,onAddProject:u,sessionNumbers:m={},projectNumbers:x={}}){let{t:b}=(0,o.Bd)(),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)({}),[C,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)(null),[E,P]=(0,s.useState)(""),$=(0,s.useRef)(null),T=(0,s.useCallback)(async()=>{S(!0),L(null),N({});let e=await d.t4.runPromiseExit((0,c.H7)());"Success"===e._tag?k(e.value):L("Failed to load projects"),S(!1)},[]),R=(0,s.useCallback)(async e=>{N(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?N(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):N(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),I=(0,s.useCallback)(e=>{let t=y[e];t?.isExpanded?N(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?N(t=>({...t,[e]:{...t[e],isExpanded:!0}})):R(e)},[y,R]);(0,s.useEffect)(()=>{e&&(j(!1),T(),setTimeout(()=>{$.current?.focus(),$.current?.select()},100))},[e,T]);let F=(0,s.useCallback)(e=>{u?.(e),t()},[u,t]);return((0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&(v?j(!1):t())};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,v,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:v?"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":a.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[v?(0,n.jsxs)("button",{onClick:()=>j(!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"})}),b("folderPicker.title")]}):(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:b("sessions.projectList")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[!v&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:$,type:"text",placeholder:b("workspace.searchProjectPath"),value:E,onChange:e=>P(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"}),E&&(0,n.jsx)("button",{onClick:()=>{P(""),$.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:b("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&&!v&&(0,n.jsxs)("button",{onClick:()=>j(!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"})}),b("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"})})})]})]}),v?(0,n.jsx)(h,{onPick:F}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[C&&(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:b("workspace.loadingProjects")})]})}),M&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:M})}),!C&&!M&&0===w.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:b("workspace.projectNotFound")})}),!C&&!M&&w.filter(e=>e.fullPath.toLowerCase().includes(E.toLowerCase())).map(e=>{let t=y[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:()=>I(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:b("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:a.jL,children:t.sessions.map(t=>{let s=t.path.split("/").pop()||"",o=t.sessionId||s.replace(".jsonl",""),a=m[`${e.fullPath}
@@ -23,14 +23,14 @@ ${r}`]?.split(".")??[],i=u.findIndex(e=>e.cwd===t);o=`session-toast-${Date.now()
23
23
  ${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?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 ${l?"bg-card":"bg-card/50"}`,style:l?{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:rj(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:l?f("browser.exitMaximize",{modKey:(0,tQ.Mu)()}):f("browser.maximize",{modKey:(0,tQ.Mu)()}),children:l?(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:l&&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)(rN,{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:()=>R(e),className:`px-3 py-1.5 text-xs transition-colors ${$===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"===$&&(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:"|"})]}),G.size>0&&!Z&&(0,n.jsx)("button",{onClick:()=>X(!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:G.size})}),Z&&(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:()=>X(!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:G.size>0?f("mysql.copyCsvSelected"):f("mysql.copyCsvAll"),children:G.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:G.size>0?f("mysql.copyJsonSelected"):f("mysql.copyJsonAll"),children:G.size>0?f("mysql.copyJSON"):f("mysql.JSON")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:M||"sql"===$?"structure"===$?(0,n.jsx)(rS,{columns:I,primaryKeys:B,foreignKeys:A,indexes:z}):"data"===$?(0,n.jsx)(rL,{result:O,loading:U,columns:I,page:q,totalPages:e$,totalRows:Q,onPageChange:eT,filters:ei,sort:ec,onFilterChange:eR,onSortChange:eF,selectedRows:G,onSelectedRowsChange:e=>{Y(e),X(!1)},editingRowIdx:ee,editValues:er,onStartEdit:e=>{if(!O)return;let t=O.rows[e],r={};for(let e of I)r[e.name]=null==t[e.name]?"":ry(t[e.name]);en(r),et(e)},onEditChange:(e,t)=>en(r=>({...r,[e]:t})),onSaveEdit:eS,onCancelEdit:()=>et(null),isAddingRow:es,newRowValues:ea,onStartAdd:()=>{eo(!0),el({})},onNewRowChange:(e,t)=>el(r=>({...r,[e]:t})),onSaveNewRow:eM,onCancelAdd:()=>{eo(!1),el({})},onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)(rE,{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")})})]})]})]}),!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"===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:rj(x)})]})]})})}function rS({columns:e,primaryKeys:t,foreignKeys:r,indexes:s}){let{t:a}=(0,o.Bd)();return 0===e.length?(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:a("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:a("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:a("mysql.colName")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colType")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colNullable")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("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:a("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:a("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:a("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 rM({filter:e,onApply:t,onClear:r,onToggle:a,onClose:l,colName:i,anchorRect:d}){let{t:c}=(0,o.Bd)(),[u,m]=(0,s.useState)(e?.op||"="),[x,h]=(0,s.useState)(e?.value||""),f=(0,s.useRef)(null),p=(0,b.F2)();(0,s.useEffect)(()=>{let e=e=>{f.current&&!f.current.contains(e.target)&&l()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[l]);let g="IS NULL"!==u&&"IS NOT NULL"!==u,v=()=>{(!g||x.trim())&&t({op:u,value:x.trim(),enabled:!0})},j=p?.getBoundingClientRect(),w=j?.left??0,k=j?.top??0,y=j?.width??window.innerWidth,N=d.left-w;N+220>y-8&&(N=y-220-8),N<8&&(N=8);let C=d.bottom+2-k;return(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:f,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"}),c("mysql.enable")]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono truncate max-w-[120px]",children:i})]}),(0,n.jsx)("select",{value:u,onChange:e=>m(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:rv.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),g&&(0,n.jsx)("input",{type:"text",value:x,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v())},placeholder:c("IN"===u?"mysql.commaValues":"LIKE"===u?"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:g&&!x.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:c("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:c("mysql.clearFilter")})]})]})})}function rL({result:e,loading:t,columns:r,page:a,totalPages:l,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,$]=(0,s.useState)(null),[T,R]=(0,s.useState)({left:0,bottom:0});if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(null!==P?(e.stopPropagation(),$(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 $(null);let r=t.currentTarget.closest("th").getBoundingClientRect();R({left:r.left,bottom:r.bottom}),$(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)(rM,{filter:r||null,onApply:t=>{m(e.name,t),$(null)},onClear:()=>{m(e.name,null),$(null)},onToggle:t=>{r&&m(e.name,{...r,enabled:t})},onClose:()=>$(null),colName:e.name,anchorRect:T})]},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(ry(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)(rN,{text:ry(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(a-1),disabled:0===a,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"◀"}),(0,n.jsxs)("span",{children:[a+1," / ",l]}),(0,n.jsx)("button",{onClick:()=>d(a+1),disabled:a>=l-1,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"▶"})]})]})]})}function rE({sqlInput:e,onSqlChange:t,onExecute:r,onKeyDown:s,result:a,error:l,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,tQ.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")}),a?.duration!==void 0&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[a.command&&!a.fields?u("mysql.rowsAffected",{command:a.command,count:a.rowCount,duration:a.duration}):u("mysql.queryRows",{count:a.rows?.length??0,duration:a.duration}),a.truncated&&` ${u("mysql.resultTruncated")}`]})]})]}),l&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-destructive bg-destructive/5 border-b border-border break-all",children:l}),a?.fields&&a.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:a.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:a.rows.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-hover",children:a.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(ry(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)(rN,{text:ry(e[t.name])})},t.name))},t))})]})})]})}t1({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:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(rC,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await t3("mysql",e.id)}});let rP={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 r$({type:e}){let t=rP[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 rT({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,above:!0}),l=(0,s.useRef)(null),i=(0,s.useRef)(null),d=(0,b.F2)(),c=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{let e=l.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=d?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,i=n?.height??window.innerHeight,c=t.top-o,u=t.bottom-o,m=c>i/2;a({x:t.left-s,y:m?c-4:u+4,above:m}),r(!0)},350)},[d]),u=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),r(!1)},[]);return(0,n.jsxs)("span",{ref:l,className:"block truncate",onMouseEnter:c,onMouseLeave:u,children:[e,t&&(0,n.jsx)(b.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 rR({id:e,connectionString:t,displayName:r,selected:a,maximized:l,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,T.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,$]=(0,s.useState)("*"),[R,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)(null),[D,A]=(0,s.useState)(null),[H,z]=(0,s.useState)(!1),[W,O]=(0,s.useState)(null),[_,q]=(0,s.useState)(!1),[V,U]=(0,s.useState)("data"),[K,Q]=(0,s.useState)(""),[J,G]=(0,s.useState)(""),[Y,Z]=(0,s.useState)([]),[X,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 t7("/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)=>{I(!0);try{let o=await t7("/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{}I(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===b&&es(P,"0",!1)},[b]);let eo=(0,s.useCallback)(()=>{B(null),A(null),es(P,"0",!1)},[P,es]),ea=(0,s.useCallback)(async r=>{B(r),z(!0),O(null),q(!1);try{let n=await t7("/api/redis/get",{id:e,connectionString:t,key:r});A(n)}catch(e){A(null),g(e instanceof Error?e.message:p("redis.loadFailed"))}z(!1)},[e,t,g]),el=(0,s.useCallback)(async()=>{if(F)try{await t7("/api/redis/delete",{id:e,connectionString:t,keys:[F]}),B(null),A(null),q(!1),es(P,"0",!1)}catch(e){g(e instanceof Error?e.message:p("redis.deleteFailed"))}},[F,e,t,P,es,g]),ei=(0,s.useCallback)(async()=>{if(F&&null!==W)try{await t7("/api/redis/set",{id:e,connectionString:t,key:F,value:W,type:"string"}),O(null),ea(F),g(p("common.saved"))}catch(e){g(e instanceof Error?e.message:p("redis.saveFailed"))}},[F,W,e,t,ea,g]),ed=(0,s.useCallback)(async()=>{try{let r=await t7("/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=J.trim();if(!n)return;ee(!0),G("");let s=[],o=/(?:"([^"]*)")|(?:'([^']*)')|(\S+)/g;for(;null!==(r=o.exec(n));)s.push(r[1]??r[2]??r[3]);let a=s[0]||"",l=s.slice(1);try{let r=await t7("/api/redis/command",{id:e,connectionString:t,command:a,args:l});Z(e=>[...e,{command:n,result:r.result,duration:r.duration,isError:!1}])}catch(e){Z(t=>[...t,{command:n,result:e instanceof Error?e.message:String(e),duration:0,isError:!0}])}ee(!1)},[J,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
24
24
  relative transition-colors cursor-pointer
25
25
  ${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
26
- ${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?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 ${l?"bg-card":"bg-card/50"}`,style:l?{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:l?p("browser.exitMaximize",{modKey:(0,tQ.Mu)()}):p("browser.maximize",{modKey:(0,tQ.Mu)()}),children:l?(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:l&&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=>$(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:()=>ea(e.key),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer transition-colors ${F===e.key?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)(r$,{type:e.type}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:(0,n.jsx)(rT,{text:e.key})})]},e.key)),0===N.length&&!R&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:p("redis.noKeys")}),R&&(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&&!R&&(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)),F&&"data"===V&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[D&&(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`:""}`}(D.ttl,p),null!==D.size?` \xb7 ${null==(f=D.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:el,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:()=>q(!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:()=>q(!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)(rI,{selectedKey:F,keyValue:D,keyLoading:H,editingValue:W,onStartEdit:e=>O(e),onEditChange:O,onSaveEdit:ei,onCancelEdit:()=>O(null),onCellCopy:e=>{navigator.clipboard.writeText(e),g(p("common.copied"))}}):"info"===V?(0,n.jsx)(rF,{infoText:K,onRefresh:ed}):(0,n.jsx)(rB,{cliInput:J,onInputChange:G,onExecute:ec,history:Y,loading:X,endRef:et,inputRef:er})})]})]})]})]})})}function rI({selectedKey:e,keyValue:t,keyLoading:r,editingValue:s,onStartEdit:a,onEditChange:l,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)(r$,{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:()=>a(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=>l(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)(r$,{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)(rT,{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)(rT,{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)(r$,{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)(rT,{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)(r$,{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)(rT,{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)(r$,{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)(rT,{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)(r$,{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)(rT,{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 rF({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=[],a=null;for(let t of e.split("\n")){let e=t.trim();if(e){if(e.startsWith("#"))a={title:e.replace(/^#\s*/,""),items:[]},s.push(a);else if(a&&e.includes(":")){let t=e.indexOf(":");a.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 rB({cliInput:e,onInputChange:t,onExecute:r,history:s,loading:a,endRef:l,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:l})]}),(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||a||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:a}),a&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"})]})]})}t1({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:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(rR,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await t3("redis",e.id)}});let rD=/^([\d.]+)\s+([\d.]+)%\s+([\d.]+)%$/;function rA(e,t,r){if(!e)return r;let n=getComputedStyle(e).getPropertyValue(t).trim();if(!n)return r;let s=rD.exec(n);if(!s)return n;let o=Number(s[1]),a=Number(s[2])/100,l=Number(s[3])/100,i=(1-Math.abs(2*l-1))*a,d=i*(1-Math.abs(o/60%2-1)),c=l-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 rH=["#4C8BF5","#E74C3C","#2ECC71","#F39C12","#9B59B6","#1ABC9C","#E67E22","#3498DB","#E91E63","#00BCD4"];function rz(e,t){return rH[t.indexOf(e)%rH.length]}function rW(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 rO({nodes:e,rels:t,allLabels:r}){let o=(0,s.useRef)(null),a=(0,s.useRef)(null),l=(0,eL.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=a.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=a.current,s=rA(n,"--foreground-faint","#666"),o=rA(n,"--foreground-subtle","#999"),l=rA(n,"--accent","#27272a"),x=rA(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),a=r/s*o,l=n/s*o;p[e].vx+=a,p[t].vx-=a,p[e].vy+=l,p[t].vy-=l}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),a=Math.sqrt(s*s+o*o)||1,l=(a-100)*.01,i=s/a*l,d=o/a*l;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=a.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 a=Math.atan2(n.y-r.y,n.x-r.x),l=n.x-24*Math.cos(a),i=n.y-24*Math.sin(a);g.fillStyle=s,g.beginPath(),g.moveTo(l,i),g.lineTo(l-8*Math.cos(a-.3),i-8*Math.sin(a-.3)),g.lineTo(l-8*Math.cos(a+.3),i-8*Math.sin(a+.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?rz(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:l,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,l]);let p=(0,s.useCallback)(e=>{let t=a.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:a,className:"cursor-grab active:cursor-grabbing absolute inset-0",onMouseDown:e=>{let t=p(e);if(t){let r=a.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=a.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 r_({id:e,connectionString:t,displayName:r,selected:o,maximized:a,expandedHeight:l,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,$]=(0,s.useState)(!1),[T,R]=(0,s.useState)(""),I=(0,s.useRef)(null),[F,B]=(0,s.useState)([]),[D,A]=(0,s.useState)([]),[H,z]=(0,s.useState)("schema"),W=(0,s.useCallback)(async()=>{f("connecting");try{let r=await t7("/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 O=(0,s.useCallback)(async()=>{y(!0);try{let r=await t7("/api/neo4j/schema",{id:e,connectionString:t});w(r)}catch{}y(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===h&&O()},[h,O]);let _=(0,s.useCallback)(async r=>{let n=r||S.trim();if(n){$(!0),R("");try{var s;let r,o,a=await t7("/api/neo4j/query",{id:e,connectionString:t,cypher:n});E(a);let{nodes:l,rels:i}=(s=a.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});l.length>0&&(B(l),A(i))}catch(e){R(e instanceof Error?e.message:String(e))}$(!1)}},[e,t,S]),q=(0,s.useCallback)(e=>{let t=`MATCH (n:\`${e}\`) RETURN n LIMIT 25`;M(t),z("cypher"),_(t)},[_]),V=(0,s.useCallback)(e=>{let t=`MATCH (a)-[r:\`${e}\`]->(b) RETURN a, r, b LIMIT 25`;M(t),z("graph"),_(t)},[_]);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:rW(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(),O(),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:a?(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:a&&l?l-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:()=>z(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:rz(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(),_())},placeholder:`Enter Cypher query (${(0,tQ.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,tQ.Mu)(),"+Enter to execute"]}),(0,n.jsx)("button",{onClick:()=>_(),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:[T&&(0,n.jsx)("div",{className:"p-2 text-xs text-destructive",children:T}),L&&!T&&(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),_(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)(rO,{nodes:F,rels:D,allLabels:j?.labels.map(e=>e.name)||[]})})]})]})]}),!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"===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:rW(m)})]})]})})}t1({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:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(r_,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await t3("neo4j",e.id)}});let rq=null,rV="",rU=0,rK=null,rQ=!1,rJ=new Map,rG=null,rY=null;function rZ(e){let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ping"===r)return;if("running"===r){rG&&(rG(t.commands),rG=null);return}let n=t.commandId;if(!n)return;let s=rJ.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)&&rJ.delete(n)}}function rX(e){rq?.readyState===WebSocket.OPEN&&rq.send(JSON.stringify(e))}function r0(e){let t,r=(t="https:"===window.location.protocol?"wss:":"ws:",`${t}//${window.location.host}/ws/terminal?projectCwd=${encodeURIComponent(e)}`);rV===r&&rq||(r9(),rQ=!1,rV=r,function e(){if(rQ||!rV)return;let t=new WebSocket(rV);rq=t,t.onopen=()=>{for(let e of(rU=0,rJ.keys()))t.send(JSON.stringify({type:"attach",commandId:e}))},t.onmessage=rZ,t.onclose=()=>{if(rq!==t||(rq=null,rQ))return;rK&&clearTimeout(rK);let r=Math.min(1e3*Math.pow(1.5,rU),1e4);rU++,rK=setTimeout(e,r)},t.onerror=()=>{}}())}function r1(){return new Promise((e,t)=>{if(rq?.readyState===WebSocket.OPEN)return void e();let r=setInterval(()=>{rq?.readyState===WebSocket.OPEN&&(clearInterval(r),clearTimeout(n),e())},50),n=setTimeout(()=>{clearInterval(r),t(Error("WebSocket connection timeout"))},5e3)})}async function r2(e){let{cwd:t,command:r,commandId:n,tabId:s,projectCwd:o,env:a,usePty:l,cols:i,rows:d,sourceId:c,onData:u,onError:m}=e;r0(o);try{await r1()}catch{m("WebSocket connection failed");return}rJ.delete(n),rJ.set(n,{onData:u,onError:m}),rX({type:"exec",commandId:n,command:r,cwd:t,tabId:s,env:a,...l?{usePty:!0}:{},...i?{cols:i,rows:d}:{},...c?{sourceId:c}:{}})}async function r5(e){let{commandId:t,projectCwd:r,onData:n,onError:s}=e;r0(r);try{await r1()}catch{s("WebSocket connection failed");return}rJ.set(t,{onData:n,onError:s}),rX({type:"attach",commandId:t})}function r4(e,t){rX({type:"stdin",commandId:e,data:t})}function r3(e,t,r){rX({type:"resize",commandId:e,cols:t,rows:r})}function r6(e){rX({type:"interrupt",pid:e})}async function r8(e){try{r0(e);try{await r1()}catch{return[]}return await new Promise(e=>{rG=t=>{e(t)},rX({type:"running"}),setTimeout(()=>{rG&&(rG=null,e([]))},3e3)})}finally{rY=null}}function r9(){if(rQ=!0,rK&&(clearTimeout(rK),rK=null),rq){let e=rq;rq=null,e.close()}rJ.clear(),rG&&(rG([]),rG=null),rY=null,rV="",rU=0}let r7=(0,s.memo)(function({item:e,selected:t,maximized:r,initialSleeping:s,tabId:o,projectCwd:a,expandedHeight:l,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 $={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",...$,children:(0,n.jsx)(tX,{commandId:s.id,tabId:o,projectCwd:a,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&&r6(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:l,bubbleContentHeight:i,onTitleMouseDown:S})})}let T=t2(e.type);if(!T)return null;let R=T.Component,I=e.data;return(0,n.jsx)("div",{"data-bubble-id":I.id,className:"rounded-lg transition-shadow",...$,children:(0,n.jsx)(R,{item:I,selected:t,maximized:r,expandedHeight:l,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:a,tabId:o}})})});var ne=r(68459),nt=r(51914);function nr({cwd:e,tabId:t,onClose:r,onSave:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)({}),[c,m]=(0,s.useState)(""),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!0),g=(0,s.useCallback)(async()=>{p(!0);let r=await u.t4.runPromiseExit((0,tU.QF)(e,t));"Success"===r._tag?d(r.value.env):console.error("Failed to load env:",r.cause),p(!1)},[e,t]);(0,s.useEffect)(()=>{g()},[g]);let b=()=>{c.trim()&&(d(e=>({...e,[c.trim()]:x})),m(""),h(""))},v=async()=>{let n=await u.t4.runPromiseExit((0,tU.Vv)({cwd:e,tabId:t,env:i}));"Success"===n._tag?(a(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:l("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?l("envManager.tabScope"):l("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-hover transition-colors",children:(0,n.jsx)(ei.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:f?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:l("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:l("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)(ne.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=>m(e.target.value),placeholder:l("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(),b())}}),(0,n.jsx)("input",{type:"text",value:x,onChange:e=>h(e.target.value),placeholder:l("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(),b())}}),(0,n.jsx)("button",{onClick:b,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)(nt.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:l("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:l("common.cancel")}),(0,n.jsx)("button",{onClick:v,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:l("common.save")})]})]})})}var nn=r(10762);function ns({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)({}),[i,d]=(0,s.useState)(""),[c,m]=(0,s.useState)(""),[x,h]=(0,s.useState)(!0),f=(0,s.useCallback)(async()=>{h(!0);let e=await u.t4.runPromiseExit((0,tU.Jn)());"Success"===e._tag?l(e.value):console.error("Failed to load aliases:",e.cause),h(!1)},[]);(0,s.useEffect)(()=>{f()},[f]);let p=()=>{i.trim()&&c.trim()&&(l(e=>({...e,[i.trim()]:c.trim()})),d(""),m(""))},g=async()=>{let r=await u.t4.runPromiseExit((0,tU.cv)(a));"Success"===r._tag?(t(a),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)(nn.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)(ei.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:x?(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(a).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 l(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:()=>{l(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)(ne.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(),p())}})]}),(0,n.jsx)("input",{type:"text",value:c,onChange:e=>m(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(),p())}})]}),(0,n.jsx)("button",{onClick:p,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)(nt.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(a).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:g,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 no=r(53961),na=r(15813),nl=r(37595),ni=r(49698),nd=r(20232);function nc({onAdd:e,onCancel:t}){let{t:r}=(0,o.Bd)(),[a,l]=(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:a,onChange:e=>l(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(),a.trim()&&i.trim()&&e(a.trim(),i.trim()))}})]})}function nu({label:e,commands:t,isAdding:r,onStartAdd:s,onAdd:a,onCancelAdd:l,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)(nt.A,{className:"w-3.5 h-3.5"})})]}),r&&(0,n.jsx)(nc,{onAdd:(e,t)=>a(e,t),onCancel:l}),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)($.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)(nd.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)(ei.A,{className:"w-3 h-3"})})]})},t))]})}function nm({cwd:e,show:t,onClose:r,onExecute:a,onAddPluginItem:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)([]),[m,x]=(0,s.useState)([]),[h,f]=(0,s.useState)(null),p=(0,s.useRef)(null),g=(0,s.useCallback)(async()=>{let[t,r]=await Promise.all([u.t4.runPromiseExit((0,tU.Yj)()),u.t4.runPromiseExit((0,tU.UV)(e))]);"Success"===t._tag&&c(t.value.customCommands||[]),"Success"===r._tag&&x(r.value.customCommands||[])},[e]);(0,s.useEffect)(()=>{t&&queueMicrotask(()=>g())},[t,g]),(0,s.useEffect)(()=>{if(!t)return;let e=e=>{p.current&&!p.current.contains(e.target)&&(r(),f(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]);let b=(0,s.useCallback)(async e=>{c(e);let t=await u.t4.runPromiseExit((0,tU.Cb)({scope:"global",customCommands:e}));"Failure"===t._tag?console.error("Failed to save global commands:",t.cause):t.value?.customCommands&&c(t.value.customCommands)},[]),v=(0,s.useCallback)(async t=>{x(t);let r=await u.t4.runPromiseExit((0,tU.Cb)({cwd:e,customCommands:t}));"Failure"===r._tag?console.error("Failed to save project commands:",r.cause):r.value?.customCommands&&x(r.value.customCommands)},[e]),j=(0,s.useCallback)(e=>{r();let t=t5(e);t?l?.(t.type,e.trim()):a(e)},[r,a,l]);return t?(0,n.jsxs)("div",{ref:p,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)(nu,{label:i("console.globalCommands"),commands:d,isAdding:"global"===h,onStartAdd:()=>f("global"),onAdd:(e,t)=>{b([...d,{name:e,command:t}]),f(null)},onCancelAdd:()=>f(null),onDelete:e=>b(d.filter((t,r)=>r!==e)),onExecute:j}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(nu,{label:i("console.projectCommands"),commands:m,isAdding:"project"===h,onStartAdd:()=>f("project"),onAdd:(e,t)=>{v([...m,{name:e,command:t}]),f(null)},onCancelAdd:()=>f(null),onDelete:e=>v(m.filter((t,r)=>r!==e)),onExecute:j})]}):null}var nx=r(63040);function nh({cwd:e,currentCwd:t,commandHistoryRef:r,gridLayout:a,onGridLayoutChange:l,onExecute:i,onAddPluginItem:d,onShowEnvManager:c,onOpenShell:m,onOpenNote:x}){let{t:h}=(0,o.Bd)(),[f,p]=(0,s.useState)(""),[g,b]=(0,s.useState)(-1),[v,j]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)(0),[C,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)(!1),[E,P]=(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:z,globalCommands:W,expandCustomCommand:O,loadQuickCommands:_}=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)([]),a=(0,s.useCallback)(async()=>{let[t,n]=await Promise.all([u.t4.runPromiseExit((0,tU.UV)(e)),u.t4.runPromiseExit((0,tU.Yj)())]);"Success"===t._tag&&r(t.value.customCommands||[]),"Success"===n._tag&&o(n.value.customCommands||[])},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>a())},[a]);let l=[...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),a=t.find(e=>e.name===o)??n.find(e=>e.name===o);return a?a.command+(r.length>1?" "+r.slice(1).join(" "):""):null},[t,n]);return{quickCustomCommands:l,projectCommands:t,globalCommands:n,expandCustomCommand:i,loadQuickCommands:a}}(e);(0,s.useEffect)(()=>{D.current?.focus()},[]),(0,s.useEffect)(()=>{let e=!1,t=()=>{u.t4.runPromiseExit((0,nx.mi)()).then(t=>{e||"Success"!==t._tag||P(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(f.startsWith("/")){let e=f.slice(1).toLowerCase(),t=E.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,...[...z.filter(r).map(e=>({...e,scope:"project"})),...W.filter(r).map(e=>({...e,scope:"global"}))].map(e=>({kind:"cmd",cmd:e}))];queueMicrotask(()=>{T(n),I(n.length>0),B(0)})}else queueMicrotask(()=>I(!1))},[f,z,W,E]),(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),p("");return}let t=e.cmd.command,r=t5(t);r?d?.(r.type,t.trim()):i(t),p("")},[i,d]),V=(0,s.useCallback)(e=>{if(e.preventDefault(),H.current||!f.trim())return;if(f.startsWith("/")){let e=f.slice(1).trim(),t=E.find(t=>t.name===e);if(t){d?.("browser",t.path),p(""),b(-1),j(""),I(!1);return}}let t=O(f)??f,r=t5(t);r?d?.(r.type,t.trim()):i(t),p(""),b(-1),j("")},[f,i,d,O,E]),U=(0,s.useCallback)(async()=>{if(!D.current)return;let e=D.current.selectionStart||0,r=await u.t4.runPromiseExit((0,tU.tp)({cwd:t,input:f,cursorPosition:e}));if("Success"===r._tag){let t=r.value,n=t.suggestions;if(n&&n.length>0&&(k(n),N(0),S(!0),1===n.length)){let r=f.substring(0,t.replaceStart??0),s=f.substring(t.replaceEnd??e);p(r+n[0]+s),S(!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,f]),K=(0,s.useCallback)(e=>{if(!D.current)return;let t=D.current.selectionStart||0,r=f.substring(0,t),n=f.substring(t),s=r.split(/\s+/),o=t-(s[s.length-1]||"").length;p(f.substring(0,o)+e+n),S(!1),setTimeout(()=>{if(D.current){let t=o+e.length;D.current.setSelectionRange(t,t)}},0)},[f]),Q=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing)return;if(R&&$.length>0){if("ArrowUp"===e.key){e.preventDefault(),B(e=>(e-1+$.length)%$.length);return}if("ArrowDown"===e.key){e.preventDefault(),B(e=>(e+1)%$.length);return}if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),q($[F]);return}if("Escape"===e.key){e.preventDefault(),I(!1);return}}if("Tab"===e.key){if(e.preventDefault(),C&&w.length>0){let e=(y+1)%w.length;N(e),K(w[e])}else U();return}if("Escape"===e.key&&C){e.preventDefault(),S(!1);return}let t=r.current;if(t&&0!==t.length){if("ArrowUp"===e.key){e.preventDefault(),-1===g&&j(f);let r=-1===g?t.length-1:Math.max(0,g-1);b(r),p(t[r])}else if("ArrowDown"===e.key){if(e.preventDefault(),-1===g)return;let r=g+1;r>=t.length?(b(-1),p(v)):(b(r),p(t[r]))}}},[g,f,v,C,w,y,U,K,R,$,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:()=>{M||_(),L(!M)},className:`p-2 rounded-lg transition-all ${M?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:h("console.quickCommands"),children:(0,n.jsx)(no.A,{className:"w-4 h-4"})}),(0,n.jsx)(nm,{cwd:e,show:M,onClose:()=>L(!1),onExecute:i,onAddPluginItem:d})]}),x&&(0,n.jsx)("button",{type:"button",onClick:x,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:h("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:()=>l(!a),className:`p-2 rounded-lg transition-all ${a?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:a?h("console.singleColumn"):h("console.dualColumn"),children:a?(0,n.jsx)(na.A,{className:"w-4 h-4"}):(0,n.jsx)(nl.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:h("console.envVars"),children:(0,n.jsx)(ni.A,{className:"w-4 h-4"})}),(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:h("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:f,onChange:e=>{p(e.target.value),-1!==g&&(b(-1),j("")),S(!1)},onKeyDown:Q,onCompositionStart:()=>{H.current=!0},onCompositionEnd:()=>{H.current=!1},placeholder:h("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&&$.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:$.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?h("console.scopeProject"):h("console.scopeGlobal")})]})},"html"===e.kind?`html-${e.name}`:`cmd-${e.cmd.scope}-${e.cmd.name}`))}),C&&w.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:w.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===y?"bg-accent":""}`,children:e},t))}),(0,n.jsx)("div",{className:"border-t border-border px-3 py-1 text-xs text-muted-foreground",children:h("console.tabSwitchEscClose")})]})]})})}function nf({showTop:e,showBottom:t,onScrollTop:r,onScrollBottom:s}){let{t:a}=(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:a("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:a("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 np=r(50605);function ng(){return`cmd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`}let nb="__cockpit_open_preferred_shell__",nv="shell",nj=new Set([nb,"zsh","bash","sh","fish","nu","python","python3","node","irb","lua","vim","nvim","vi","nano","emacs","top","htop","less","man"]),nw=[{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:[...Z.GV]}],nk=(0,s.memo)(function({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a,onOpenNote:l,focusBubble:i}){let{t:d}=(0,o.Bd)(),{consoleItems:c,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:P,setAliases:$,saveBubbleOrder:R,hasMoreHistory:I,loadHistory:F,currentPage:B,isLoadingHistory:D,subscribePtyOutput:A,subscribePtyReset:H,subscribePtyRefresh:z}=function({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:n}){let[o,a]=(0,s.useState)([]),[l,i]=(0,s.useState)([]),[d,c]=(0,s.useState)(new Set),[m,x]=(0,s.useState)(t||e),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(0),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)({}),N=(0,s.useRef)(""),[C,S]=(0,s.useState)({}),[M,L]=(0,s.useState)(null),E=(0,s.useRef)(null),P=(0,s.useRef)(new Map),$=(0,s.useRef)(new Map),T=(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)([]),z=(0,s.useRef)("");z.current||(z.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 O=(0,s.useCallback)(()=>{if(P.current.size>0){let e=new Map(P.current);P.current.clear(),a(t=>t.map(t=>{let r=e.get(t.id);return void 0!==r?{...t,output:r}:t}))}E.current=null},[]),_=(0,s.useCallback)((e,t)=>{if(T.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=($.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);$.current.set(e,t),P.current.set(e,t)}else $.current.set(e,r),P.current.set(e,r);null===E.current&&(E.current=requestAnimationFrame(O))},[O]),q=(0,s.useCallback)((e,t=!1)=>{$.current.delete(e),T.current.delete(e),P.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),J=(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(!M)return;let e=requestAnimationFrame(()=>{for(let e of Q.current.values())for(let t of e)t()});return()=>cancelAnimationFrame(e)},[M]);let G=(0,s.useCallback)(e=>(null!==E.current&&(cancelAnimationFrame(E.current),E.current=null),O(),$.current.get(e)||""),[O]),Y=(0,s.useCallback)(()=>{W.current&&(W.current.scrollTop=W.current.scrollHeight)},[]),Z=(0,s.useCallback)(async(t=0)=>{if(r){f(!0);try{let n=await u.t4.runPromise((0,tU.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=t2(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:ng();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?(a(e),i(r),s.size>0&&c(s)):(a(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]})),g(n.hasMore),v(t)}}catch(e){console.error("Failed to load history:",e)}finally{f(!1)}}},[e,r]),X=(0,s.useCallback)(async t=>{r&&await u.t4.runPromise((0,tU.AJ)(e,r,{id:t.id,command:t.command,output:t.output,exitCode:t.exitCode,timestamp:t.timestamp,cwd:m},z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to save cd history:",e))),eb.NWQ(()=>eb.rIH)))},[e,r,m]),ee=(0,s.useCallback)(async t=>{try{let n=await (rY||(rY=r8(e)));if(t.current)return;for(let s of n){if(r&&s.tabId!==r)continue;if(t.current)break;let n=s.commandId;a(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}:{}}]),$.current.set(n,""),s.usePty&&T.current.add(n),await r5({commandId:n,projectCwd:e,onData:(e,t)=>{if("pid"===e)"string"==typeof t.command&&a(e=>e.map(e=>e.id===n?{...e,command:t.command}:e));else if("stdout"===e||"stderr"===e)_(n,t.data);else if("exit"===e){let e=G(n);q(n),a(r=>r.map(r=>r.id===n?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:()=>{a(e=>e.map(e=>e.id===n&&e.isRunning?{...e,isRunning:!1}:e))}})}}catch{}},[e,r,_,G,q]),et=(0,s.useCallback)((t,r)=>{$.current.set(t,""),r&&T.current.add(t),r5({commandId:t,projectCwd:e,onData:(e,r)=>{if("pid"===e)a(e=>e.map(e=>e.id===t?{...e,pid:r.pid,..."string"==typeof r.command?{command:r.command}:{}}:e));else if("stdout"===e||"stderr"===e)_(t,r.data);else if("exit"===e){let e=G(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:()=>{a(e=>e.map(e=>e.id===t&&e.isRunning?{...e,isRunning:!1}:e))}}).catch(()=>{})},[e,_,G,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?t2(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;a(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)}L(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),a(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)&&a(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;a(e=>e.filter(e=>e.id!==t)),i(e=>e.filter(e=>e.id!==t)),L(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?(a([]),i([]),L([]),c(new Set)):"reorder"===e.op&&Array.isArray(e.order)&&L(e.order)},[er,et,q]);(0,eo.h)({url:"/ws/global-state",enabled:!!e&&!!r,onMessage:t=>{"console-delta"!==t.type||t.cwd!==e||t.tabId!==r||t.sourceId&&t.sourceId===z.current||en(t)}});let es=(0,s.useCallback)(async t=>{let s,o=t.trim().split(/\s+/),l=o[0],i=t;C[l]&&(i=C[l]+(o.length>1?" "+o.slice(1).join(" "):""));let d=t5(i);if(d)return void A.current?.(d.type,i.trim());let c=ng(),u=new Date().toISOString(),h=(s=i.trim().split(/\s+/)[0],nj.has(s)),f={id:c,command:i===nb?nv:t,output:i!==t&&i!==nb?`→ ${i}
26
+ ${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?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 ${l?"bg-card":"bg-card/50"}`,style:l?{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:l?p("browser.exitMaximize",{modKey:(0,tQ.Mu)()}):p("browser.maximize",{modKey:(0,tQ.Mu)()}),children:l?(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:l&&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=>$(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:()=>ea(e.key),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer transition-colors ${F===e.key?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)(r$,{type:e.type}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:(0,n.jsx)(rT,{text:e.key})})]},e.key)),0===N.length&&!R&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:p("redis.noKeys")}),R&&(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&&!R&&(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)),F&&"data"===V&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[D&&(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`:""}`}(D.ttl,p),null!==D.size?` \xb7 ${null==(f=D.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:el,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:()=>q(!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:()=>q(!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)(rI,{selectedKey:F,keyValue:D,keyLoading:H,editingValue:W,onStartEdit:e=>O(e),onEditChange:O,onSaveEdit:ei,onCancelEdit:()=>O(null),onCellCopy:e=>{navigator.clipboard.writeText(e),g(p("common.copied"))}}):"info"===V?(0,n.jsx)(rF,{infoText:K,onRefresh:ed}):(0,n.jsx)(rB,{cliInput:J,onInputChange:G,onExecute:ec,history:Y,loading:X,endRef:et,inputRef:er})})]})]})]})]})})}function rI({selectedKey:e,keyValue:t,keyLoading:r,editingValue:s,onStartEdit:a,onEditChange:l,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)(r$,{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:()=>a(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=>l(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)(r$,{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)(rT,{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)(rT,{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)(r$,{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)(rT,{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)(r$,{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)(rT,{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)(r$,{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)(rT,{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)(r$,{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)(rT,{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 rF({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=[],a=null;for(let t of e.split("\n")){let e=t.trim();if(e){if(e.startsWith("#"))a={title:e.replace(/^#\s*/,""),items:[]},s.push(a);else if(a&&e.includes(":")){let t=e.indexOf(":");a.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 rB({cliInput:e,onInputChange:t,onExecute:r,history:s,loading:a,endRef:l,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:l})]}),(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||a||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:a}),a&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"})]})]})}t1({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:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(rR,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await t3("redis",e.id)}});let rD=/^([\d.]+)\s+([\d.]+)%\s+([\d.]+)%$/;function rA(e,t,r){if(!e)return r;let n=getComputedStyle(e).getPropertyValue(t).trim();if(!n)return r;let s=rD.exec(n);if(!s)return n;let o=Number(s[1]),a=Number(s[2])/100,l=Number(s[3])/100,i=(1-Math.abs(2*l-1))*a,d=i*(1-Math.abs(o/60%2-1)),c=l-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 rH=["#4C8BF5","#E74C3C","#2ECC71","#F39C12","#9B59B6","#1ABC9C","#E67E22","#3498DB","#E91E63","#00BCD4"];function rz(e,t){return rH[t.indexOf(e)%rH.length]}function rW(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 rO({nodes:e,rels:t,allLabels:r}){let o=(0,s.useRef)(null),a=(0,s.useRef)(null),l=(0,eL.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=a.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=a.current,s=rA(n,"--foreground-faint","#666"),o=rA(n,"--foreground-subtle","#999"),l=rA(n,"--accent","#27272a"),x=rA(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),a=r/s*o,l=n/s*o;p[e].vx+=a,p[t].vx-=a,p[e].vy+=l,p[t].vy-=l}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),a=Math.sqrt(s*s+o*o)||1,l=(a-100)*.01,i=s/a*l,d=o/a*l;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=a.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 a=Math.atan2(n.y-r.y,n.x-r.x),l=n.x-24*Math.cos(a),i=n.y-24*Math.sin(a);g.fillStyle=s,g.beginPath(),g.moveTo(l,i),g.lineTo(l-8*Math.cos(a-.3),i-8*Math.sin(a-.3)),g.lineTo(l-8*Math.cos(a+.3),i-8*Math.sin(a+.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?rz(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:l,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,l]);let p=(0,s.useCallback)(e=>{let t=a.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:a,className:"cursor-grab active:cursor-grabbing absolute inset-0",onMouseDown:e=>{let t=p(e);if(t){let r=a.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=a.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 r_({id:e,connectionString:t,displayName:r,selected:o,maximized:a,expandedHeight:l,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,$]=(0,s.useState)(!1),[T,R]=(0,s.useState)(""),I=(0,s.useRef)(null),[F,B]=(0,s.useState)([]),[D,A]=(0,s.useState)([]),[H,z]=(0,s.useState)("schema"),W=(0,s.useCallback)(async()=>{f("connecting");try{let r=await t7("/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 O=(0,s.useCallback)(async()=>{y(!0);try{let r=await t7("/api/neo4j/schema",{id:e,connectionString:t});w(r)}catch{}y(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===h&&O()},[h,O]);let _=(0,s.useCallback)(async r=>{let n=r||S.trim();if(n){$(!0),R("");try{var s;let r,o,a=await t7("/api/neo4j/query",{id:e,connectionString:t,cypher:n});E(a);let{nodes:l,rels:i}=(s=a.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});l.length>0&&(B(l),A(i))}catch(e){R(e instanceof Error?e.message:String(e))}$(!1)}},[e,t,S]),q=(0,s.useCallback)(e=>{let t=`MATCH (n:\`${e}\`) RETURN n LIMIT 25`;M(t),z("cypher"),_(t)},[_]),V=(0,s.useCallback)(e=>{let t=`MATCH (a)-[r:\`${e}\`]->(b) RETURN a, r, b LIMIT 25`;M(t),z("graph"),_(t)},[_]);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:rW(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(),O(),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:a?(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:a&&l?l-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:()=>z(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:rz(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(),_())},placeholder:`Enter Cypher query (${(0,tQ.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,tQ.Mu)(),"+Enter to execute"]}),(0,n.jsx)("button",{onClick:()=>_(),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:[T&&(0,n.jsx)("div",{className:"p-2 text-xs text-destructive",children:T}),L&&!T&&(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),_(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)(rO,{nodes:F,rels:D,allLabels:j?.labels.map(e=>e.name)||[]})})]})]})]}),!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"===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:rW(m)})]})]})})}t1({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:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(r_,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await t3("neo4j",e.id)}});let rq=null,rV="",rU=0,rK=null,rQ=!1,rJ=new Map,rG=null,rY=null;function rZ(e){let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ping"===r)return;if("running"===r){rG&&(rG(t.commands),rG=null);return}let n=t.commandId;if(!n)return;let s=rJ.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)&&rJ.delete(n)}}function rX(e){rq?.readyState===WebSocket.OPEN&&rq.send(JSON.stringify(e))}function r0(e){let t,r=(t="https:"===window.location.protocol?"wss:":"ws:",`${t}//${window.location.host}/ws/terminal?projectCwd=${encodeURIComponent(e)}`);rV===r&&rq||(r9(),rQ=!1,rV=r,function e(){if(rQ||!rV)return;let t=new WebSocket(rV);rq=t,t.onopen=()=>{for(let e of(rU=0,rJ.keys()))t.send(JSON.stringify({type:"attach",commandId:e}))},t.onmessage=rZ,t.onclose=()=>{if(rq!==t||(rq=null,rQ))return;rK&&clearTimeout(rK);let r=Math.min(1e3*Math.pow(1.5,rU),1e4);rU++,rK=setTimeout(e,r)},t.onerror=()=>{}}())}function r1(){return new Promise((e,t)=>{if(rq?.readyState===WebSocket.OPEN)return void e();let r=setInterval(()=>{rq?.readyState===WebSocket.OPEN&&(clearInterval(r),clearTimeout(n),e())},50),n=setTimeout(()=>{clearInterval(r),t(Error("WebSocket connection timeout"))},5e3)})}async function r2(e){let{cwd:t,command:r,commandId:n,tabId:s,projectCwd:o,env:a,usePty:l,cols:i,rows:d,sourceId:c,onData:u,onError:m}=e;r0(o);try{await r1()}catch{m("WebSocket connection failed");return}rJ.delete(n),rJ.set(n,{onData:u,onError:m}),rX({type:"exec",commandId:n,command:r,cwd:t,tabId:s,env:a,...l?{usePty:!0}:{},...i?{cols:i,rows:d}:{},...c?{sourceId:c}:{}})}async function r5(e){let{commandId:t,projectCwd:r,onData:n,onError:s}=e;r0(r);try{await r1()}catch{s("WebSocket connection failed");return}rJ.set(t,{onData:n,onError:s}),rX({type:"attach",commandId:t})}function r4(e,t){rX({type:"stdin",commandId:e,data:t})}function r3(e,t,r){rX({type:"resize",commandId:e,cols:t,rows:r})}function r6(e){rX({type:"interrupt",pid:e})}async function r8(e){try{r0(e);try{await r1()}catch{return[]}return await new Promise(e=>{rG=t=>{e(t)},rX({type:"running"}),setTimeout(()=>{rG&&(rG=null,e([]))},3e3)})}finally{rY=null}}function r9(){if(rQ=!0,rK&&(clearTimeout(rK),rK=null),rq){let e=rq;rq=null,e.close()}rJ.clear(),rG&&(rG([]),rG=null),rY=null,rV="",rU=0}let r7=(0,s.memo)(function({item:e,selected:t,maximized:r,initialSleeping:s,tabId:o,projectCwd:a,expandedHeight:l,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 $={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",...$,children:(0,n.jsx)(tX,{commandId:s.id,tabId:o,projectCwd:a,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&&r6(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:l,bubbleContentHeight:i,onTitleMouseDown:S})})}let T=t2(e.type);if(!T)return null;let R=T.Component,I=e.data;return(0,n.jsx)("div",{"data-bubble-id":I.id,className:"rounded-lg transition-shadow",...$,children:(0,n.jsx)(R,{item:I,selected:t,maximized:r,expandedHeight:l,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:a,tabId:o}})})});var ne=r(68459),nt=r(51914);function nr({cwd:e,tabId:t,onClose:r,onSave:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)({}),[c,m]=(0,s.useState)(""),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!0),g=(0,s.useCallback)(async()=>{p(!0);let r=await u.t4.runPromiseExit((0,tU.QF)(e,t));"Success"===r._tag?d(r.value.env):console.error("Failed to load env:",r.cause),p(!1)},[e,t]);(0,s.useEffect)(()=>{g()},[g]);let b=()=>{c.trim()&&(d(e=>({...e,[c.trim()]:x})),m(""),h(""))},v=async()=>{let n=await u.t4.runPromiseExit((0,tU.Vv)({cwd:e,tabId:t,env:i}));"Success"===n._tag?(a(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:l("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?l("envManager.tabScope"):l("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-hover transition-colors",children:(0,n.jsx)(ei.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:f?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:l("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:l("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)(ne.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=>m(e.target.value),placeholder:l("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(),b())}}),(0,n.jsx)("input",{type:"text",value:x,onChange:e=>h(e.target.value),placeholder:l("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(),b())}}),(0,n.jsx)("button",{onClick:b,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)(nt.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:l("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:l("common.cancel")}),(0,n.jsx)("button",{onClick:v,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:l("common.save")})]})]})})}var nn=r(10762);function ns({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)({}),[i,d]=(0,s.useState)(""),[c,m]=(0,s.useState)(""),[x,h]=(0,s.useState)(!0),f=(0,s.useCallback)(async()=>{h(!0);let e=await u.t4.runPromiseExit((0,tU.Jn)());"Success"===e._tag?l(e.value):console.error("Failed to load aliases:",e.cause),h(!1)},[]);(0,s.useEffect)(()=>{f()},[f]);let p=()=>{i.trim()&&c.trim()&&(l(e=>({...e,[i.trim()]:c.trim()})),d(""),m(""))},g=async()=>{let r=await u.t4.runPromiseExit((0,tU.cv)(a));"Success"===r._tag?(t(a),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)(nn.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)(ei.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:x?(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(a).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 l(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:()=>{l(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)(ne.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(),p())}})]}),(0,n.jsx)("input",{type:"text",value:c,onChange:e=>m(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(),p())}})]}),(0,n.jsx)("button",{onClick:p,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)(nt.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(a).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:g,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 no=r(53961),na=r(15813),nl=r(37595),ni=r(49698),nd=r(20232);function nc({onAdd:e,onCancel:t}){let{t:r}=(0,o.Bd)(),[a,l]=(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:a,onChange:e=>l(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(),a.trim()&&i.trim()&&e(a.trim(),i.trim()))}})]})}function nu({label:e,commands:t,isAdding:r,onStartAdd:s,onAdd:a,onCancelAdd:l,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)(nt.A,{className:"w-3.5 h-3.5"})})]}),r&&(0,n.jsx)(nc,{onAdd:(e,t)=>a(e,t),onCancel:l}),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)($.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)(nd.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)(ei.A,{className:"w-3 h-3"})})]})},t))]})}function nm({cwd:e,show:t,onClose:r,onExecute:a,onAddPluginItem:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)([]),[m,x]=(0,s.useState)([]),[h,f]=(0,s.useState)(null),p=(0,s.useRef)(null),g=(0,s.useCallback)(async()=>{let[t,r]=await Promise.all([u.t4.runPromiseExit((0,tU.Yj)()),u.t4.runPromiseExit((0,tU.UV)(e))]);"Success"===t._tag&&c(t.value.customCommands||[]),"Success"===r._tag&&x(r.value.customCommands||[])},[e]);(0,s.useEffect)(()=>{t&&queueMicrotask(()=>g())},[t,g]),(0,s.useEffect)(()=>{if(!t)return;let e=e=>{p.current&&!p.current.contains(e.target)&&(r(),f(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]);let b=(0,s.useCallback)(async e=>{c(e);let t=await u.t4.runPromiseExit((0,tU.Cb)({scope:"global",customCommands:e}));"Failure"===t._tag?console.error("Failed to save global commands:",t.cause):t.value?.customCommands&&c(t.value.customCommands)},[]),v=(0,s.useCallback)(async t=>{x(t);let r=await u.t4.runPromiseExit((0,tU.Cb)({cwd:e,customCommands:t}));"Failure"===r._tag?console.error("Failed to save project commands:",r.cause):r.value?.customCommands&&x(r.value.customCommands)},[e]),j=(0,s.useCallback)(e=>{r();let t=t5(e);t?l?.(t.type,e.trim()):a(e)},[r,a,l]);return t?(0,n.jsxs)("div",{ref:p,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)(nu,{label:i("console.globalCommands"),commands:d,isAdding:"global"===h,onStartAdd:()=>f("global"),onAdd:(e,t)=>{b([...d,{name:e,command:t}]),f(null)},onCancelAdd:()=>f(null),onDelete:e=>b(d.filter((t,r)=>r!==e)),onExecute:j}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(nu,{label:i("console.projectCommands"),commands:m,isAdding:"project"===h,onStartAdd:()=>f("project"),onAdd:(e,t)=>{v([...m,{name:e,command:t}]),f(null)},onCancelAdd:()=>f(null),onDelete:e=>v(m.filter((t,r)=>r!==e)),onExecute:j})]}):null}var nx=r(63040);function nh({cwd:e,currentCwd:t,commandHistoryRef:r,gridLayout:a,onGridLayoutChange:l,onExecute:i,onAddPluginItem:d,onShowEnvManager:c,onOpenShell:m,onOpenNote:x}){let{t:h}=(0,o.Bd)(),[f,p]=(0,s.useState)(""),[g,b]=(0,s.useState)(-1),[v,j]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)(0),[C,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)(!1),[E,P]=(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:z,globalCommands:W,expandCustomCommand:O,loadQuickCommands:_}=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)([]),a=(0,s.useCallback)(async()=>{let[t,n]=await Promise.all([u.t4.runPromiseExit((0,tU.UV)(e)),u.t4.runPromiseExit((0,tU.Yj)())]);"Success"===t._tag&&r(t.value.customCommands||[]),"Success"===n._tag&&o(n.value.customCommands||[])},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>a())},[a]);let l=[...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),a=t.find(e=>e.name===o)??n.find(e=>e.name===o);return a?a.command+(r.length>1?" "+r.slice(1).join(" "):""):null},[t,n]);return{quickCustomCommands:l,projectCommands:t,globalCommands:n,expandCustomCommand:i,loadQuickCommands:a}}(e);(0,s.useEffect)(()=>{D.current?.focus()},[]),(0,s.useEffect)(()=>{let e=!1,t=()=>{u.t4.runPromiseExit((0,nx.mi)()).then(t=>{e||"Success"!==t._tag||P(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(f.startsWith("/")){let e=f.slice(1).toLowerCase(),t=E.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,...[...z.filter(r).map(e=>({...e,scope:"project"})),...W.filter(r).map(e=>({...e,scope:"global"}))].map(e=>({kind:"cmd",cmd:e}))];queueMicrotask(()=>{T(n),I(n.length>0),B(0)})}else queueMicrotask(()=>I(!1))},[f,z,W,E]),(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),p("");return}let t=e.cmd.command,r=t5(t);r?d?.(r.type,t.trim()):i(t),p("")},[i,d]),V=(0,s.useCallback)(e=>{if(e.preventDefault(),H.current||!f.trim())return;if(f.startsWith("/")){let e=f.slice(1).trim(),t=E.find(t=>t.name===e);if(t){d?.("browser",t.path),p(""),b(-1),j(""),I(!1);return}}let t=O(f)??f,r=t5(t);r?d?.(r.type,t.trim()):i(t),p(""),b(-1),j("")},[f,i,d,O,E]),U=(0,s.useCallback)(async()=>{if(!D.current)return;let e=D.current.selectionStart||0,r=await u.t4.runPromiseExit((0,tU.tp)({cwd:t,input:f,cursorPosition:e}));if("Success"===r._tag){let t=r.value,n=t.suggestions;if(n&&n.length>0&&(k(n),N(0),S(!0),1===n.length)){let r=f.substring(0,t.replaceStart??0),s=f.substring(t.replaceEnd??e);p(r+n[0]+s),S(!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,f]),K=(0,s.useCallback)(e=>{if(!D.current)return;let t=D.current.selectionStart||0,r=f.substring(0,t),n=f.substring(t),s=r.split(/\s+/),o=t-(s[s.length-1]||"").length;p(f.substring(0,o)+e+n),S(!1),setTimeout(()=>{if(D.current){let t=o+e.length;D.current.setSelectionRange(t,t)}},0)},[f]),Q=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing)return;if(R&&$.length>0){if("ArrowUp"===e.key){e.preventDefault(),B(e=>(e-1+$.length)%$.length);return}if("ArrowDown"===e.key){e.preventDefault(),B(e=>(e+1)%$.length);return}if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),q($[F]);return}if("Escape"===e.key){e.preventDefault(),I(!1);return}}if("Tab"===e.key){if(e.preventDefault(),C&&w.length>0){let e=(y+1)%w.length;N(e),K(w[e])}else U();return}if("Escape"===e.key&&C){e.preventDefault(),S(!1);return}let t=r.current;if(t&&0!==t.length){if("ArrowUp"===e.key){e.preventDefault(),-1===g&&j(f);let r=-1===g?t.length-1:Math.max(0,g-1);b(r),p(t[r])}else if("ArrowDown"===e.key){if(e.preventDefault(),-1===g)return;let r=g+1;r>=t.length?(b(-1),p(v)):(b(r),p(t[r]))}}},[g,f,v,C,w,y,U,K,R,$,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:()=>{M||_(),L(!M)},className:`p-2 rounded-lg transition-all ${M?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:h("console.quickCommands"),children:(0,n.jsx)(no.A,{className:"w-4 h-4"})}),(0,n.jsx)(nm,{cwd:e,show:M,onClose:()=>L(!1),onExecute:i,onAddPluginItem:d})]}),x&&(0,n.jsx)("button",{type:"button",onClick:x,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:h("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:()=>l(!a),className:`p-2 rounded-lg transition-all ${a?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:a?h("console.singleColumn"):h("console.dualColumn"),children:a?(0,n.jsx)(na.A,{className:"w-4 h-4"}):(0,n.jsx)(nl.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:h("console.envVars"),children:(0,n.jsx)(ni.A,{className:"w-4 h-4"})}),(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:h("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:f,onChange:e=>{p(e.target.value),-1!==g&&(b(-1),j("")),S(!1)},onKeyDown:Q,onCompositionStart:()=>{H.current=!0},onCompositionEnd:()=>{H.current=!1},placeholder:h("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&&$.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:$.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?h("console.scopeProject"):h("console.scopeGlobal")})]})},"html"===e.kind?`html-${e.name}`:`cmd-${e.cmd.scope}-${e.cmd.name}`))}),C&&w.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:w.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===y?"bg-accent":""}`,children:e},t))}),(0,n.jsx)("div",{className:"border-t border-border px-3 py-1 text-xs text-muted-foreground",children:h("console.tabSwitchEscClose")})]})]})})}function nf({showTop:e,showBottom:t,onScrollTop:r,onScrollBottom:s}){let{t:a}=(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:a("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:a("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 np=r(50605);function ng(){return`cmd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`}let nb="__cockpit_open_preferred_shell__",nv="shell",nj=new Set([nb,"zsh","bash","sh","fish","nu","python","python3","node","irb","lua","vim","nvim","vi","nano","emacs","top","htop","less","man"]),nw=[{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:[...Z.GV]}],nk=(0,s.memo)(function({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a,onOpenNote:l,focusBubble:i,isActive:d=!0}){let{t:c}=(0,o.Bd)(),{consoleItems:m,scrollRef:x,selectedCommandId:h,setSelectedCommandId:f,interruptCommand:p,sendStdin:g,deleteCommand:b,rerunCommand:v,ptySizeRef:j,resizePty:w,executeCommand:k,addPluginItem:y,closePluginItem:N,sleepingBubbles:C,handleBubbleSleep:S,handleBubbleWake:M,scrollToBottom:L,currentCwd:E,commandHistoryRef:P,setCustomEnv:$,setAliases:R,saveBubbleOrder:I,hasMoreHistory:F,loadHistory:B,currentPage:D,isLoadingHistory:A,subscribePtyOutput:H,subscribePtyReset:z,subscribePtyRefresh:W}=function({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:n}){let[o,a]=(0,s.useState)([]),[l,i]=(0,s.useState)([]),[d,c]=(0,s.useState)(new Set),[m,x]=(0,s.useState)(t||e),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(0),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)({}),N=(0,s.useRef)(""),[C,S]=(0,s.useState)({}),[M,L]=(0,s.useState)(null),E=(0,s.useRef)(null),P=(0,s.useRef)(new Map),$=(0,s.useRef)(new Map),T=(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)([]),z=(0,s.useRef)("");z.current||(z.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 O=(0,s.useCallback)(()=>{if(P.current.size>0){let e=new Map(P.current);P.current.clear(),a(t=>t.map(t=>{let r=e.get(t.id);return void 0!==r?{...t,output:r}:t}))}E.current=null},[]),_=(0,s.useCallback)((e,t)=>{if(T.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=($.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);$.current.set(e,t),P.current.set(e,t)}else $.current.set(e,r),P.current.set(e,r);null===E.current&&(E.current=requestAnimationFrame(O))},[O]),q=(0,s.useCallback)((e,t=!1)=>{$.current.delete(e),T.current.delete(e),P.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),J=(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(!M)return;let e=requestAnimationFrame(()=>{for(let e of Q.current.values())for(let t of e)t()});return()=>cancelAnimationFrame(e)},[M]);let G=(0,s.useCallback)(e=>(null!==E.current&&(cancelAnimationFrame(E.current),E.current=null),O(),$.current.get(e)||""),[O]),Y=(0,s.useCallback)(()=>{W.current&&(W.current.scrollTop=W.current.scrollHeight)},[]),Z=(0,s.useCallback)(async(t=0)=>{if(r){f(!0);try{let n=await u.t4.runPromise((0,tU.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=t2(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:ng();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?(a(e),i(r),s.size>0&&c(s)):(a(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]})),g(n.hasMore),v(t)}}catch(e){console.error("Failed to load history:",e)}finally{f(!1)}}},[e,r]),X=(0,s.useCallback)(async t=>{r&&await u.t4.runPromise((0,tU.AJ)(e,r,{id:t.id,command:t.command,output:t.output,exitCode:t.exitCode,timestamp:t.timestamp,cwd:m},z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to save cd history:",e))),eb.NWQ(()=>eb.rIH)))},[e,r,m]),ee=(0,s.useCallback)(async t=>{try{let n=await (rY||(rY=r8(e)));if(t.current)return;for(let s of n){if(r&&s.tabId!==r)continue;if(t.current)break;let n=s.commandId;a(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}:{}}]),$.current.set(n,""),s.usePty&&T.current.add(n),await r5({commandId:n,projectCwd:e,onData:(e,t)=>{if("pid"===e)"string"==typeof t.command&&a(e=>e.map(e=>e.id===n?{...e,command:t.command}:e));else if("stdout"===e||"stderr"===e)_(n,t.data);else if("exit"===e){let e=G(n);q(n),a(r=>r.map(r=>r.id===n?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:()=>{a(e=>e.map(e=>e.id===n&&e.isRunning?{...e,isRunning:!1}:e))}})}}catch{}},[e,r,_,G,q]),et=(0,s.useCallback)((t,r)=>{$.current.set(t,""),r&&T.current.add(t),r5({commandId:t,projectCwd:e,onData:(e,r)=>{if("pid"===e)a(e=>e.map(e=>e.id===t?{...e,pid:r.pid,..."string"==typeof r.command?{command:r.command}:{}}:e));else if("stdout"===e||"stderr"===e)_(t,r.data);else if("exit"===e){let e=G(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:()=>{a(e=>e.map(e=>e.id===t&&e.isRunning?{...e,isRunning:!1}:e))}}).catch(()=>{})},[e,_,G,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?t2(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;a(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)}L(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),a(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)&&a(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;a(e=>e.filter(e=>e.id!==t)),i(e=>e.filter(e=>e.id!==t)),L(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?(a([]),i([]),L([]),c(new Set)):"reorder"===e.op&&Array.isArray(e.order)&&L(e.order)},[er,et,q]);(0,eo.h)({url:"/ws/global-state",enabled:!!e&&!!r,onMessage:t=>{"console-delta"!==t.type||t.cwd!==e||t.tabId!==r||t.sourceId&&t.sourceId===z.current||en(t)}});let es=(0,s.useCallback)(async t=>{let s,o=t.trim().split(/\s+/),l=o[0],i=t;C[l]&&(i=C[l]+(o.length>1?" "+o.slice(1).join(" "):""));let d=t5(i);if(d)return void A.current?.(d.type,i.trim());let c=ng(),u=new Date().toISOString(),h=(s=i.trim().split(/\s+/)[0],nj.has(s)),f={id:c,command:i===nb?nv:t,output:i!==t&&i!==nb?`→ ${i}
27
27
  `:"",isRunning:!0,timestamp:u,cwd:m,...h?{usePty:!0}:{}};if(a(e=>e.some(e=>e.id===c)?e:[...e,f]),w(c),$.current.set(c,f.output),h&&T.current.add(c),setTimeout(Y,100),i.trim().startsWith("cd ")){let e=i.trim().substring(3).trim(),t=m;(0,np.P)(e)?t=N.current?(0,np.D)(e,N.current):m:e.startsWith("/")?t=e:".."===e?t=m.split("/").slice(0,-1).join("/")||"/":"."!==e&&(t=`${m}/${e}`.replace(/\/+/g,"/")),x(t),n?.(t),a(e=>e.map(e=>{if(e.id===c){let r={...e,output:`Changed directory to: ${t}`,exitCode:0,isRunning:!1};return X(r),r}return e}));return}try{await r2({cwd:m,command:i,commandId:c,tabId:r||"",projectCwd:e,env:k,usePty:h,sourceId:z.current,onData:(e,t)=>{if("pid"===e)a(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)_(c,t.data);else if("exit"===e){let e=G(c);q(c),a(r=>r.map(r=>r.id===c?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:e=>{let t=G(c);q(c),a(r=>r.map(r=>r.id===c?{...r,output:t+`
28
28
  Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:r))}})}catch(t){let e=G(c);q(c),a(r=>r.map(r=>r.id===c?{...r,output:e+`
29
29
  Error: ${t.message}`,exitCode:1,isRunning:!1,pid:void 0}:r))}},[C,m,k,r,e,_,G,q,Y,n,X]),ea=(0,s.useCallback)(e=>{let t=o.find(t=>t.id===e);t?.isRunning&&t.pid&&r6(t.pid)},[o]),el=(0,s.useCallback)(async t=>{let n=o.find(e=>e.id===t);if(!n)return;n.isRunning&&n.pid&&(r6(n.pid),await new Promise(e=>setTimeout(e,200)));let s=n.command.trim().split(/\s+/),l=s[0],i=n.usePty&&n.command===nv,d=i?nb:n.command;!i&&C[l]&&(d=C[l]+(s.length>1?" "+s.slice(1).join(" "):""));let c=n.usePty||!1;if(c){let e=U.current.get(t);if(e)for(let t of e)t()}q(t,c);let u=d!==n.command?`→ ${d}
30
30
  `:"";c||$.current.set(t,u),c&&T.current.add(t),a(e=>e.map(e=>e.id===t?{...e,output:c?"":u,exitCode:void 0,isRunning:!0,pid:void 0}:e));let x=I.current.get(t);try{await r2({cwd:n.cwd||m,command:d,commandId:t,tabId:r||"",projectCwd:e,env:k,usePty:c,sourceId:z.current,...c&&x?{cols:x.cols,rows:x.rows}:{},onData:(e,r)=>{if("pid"===e)a(e=>e.map(e=>e.id===t?{...e,pid:r.pid,..."string"==typeof r.command?{command:r.command}:{}}:e));else if("stdout"===e||"stderr"===e)_(t,r.data);else if("exit"===e){let e=G(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:e=>{let r=G(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:r+`
31
31
  Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:n))}})}catch(r){let e=G(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e+`
32
- Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,C,m,k,r,e,_,G,q]),ei=(0,s.useCallback)(async t=>{a(e=>e.filter(e=>e.id!==t)),q(t),r&&await u.t4.runPromise((0,tU.SN)(e,r,t,z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to delete command:",e))),eb.NWQ(()=>eb.rIH)))},[e,r,q]),ed=(0,s.useCallback)((t,n,s)=>{var o;let a=t2(t);if(!a)return;let l=a.parse(n);"cwd"in l&&!l.cwd&&(l.cwd=m);let d={id:(o=a.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...l};if(i(e=>[...e,d]),w(d.id),setTimeout(Y,100),s){let t=M&&M.length>0?[...M]:H.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,d.id):t.push(d.id),L(t),r&&u.t4.runFork((0,tU.cm)(e,r,t,z.current).pipe(eb.NWQ(()=>eb.rIH)))}if(r){let n=a.toHistory(d);u.t4.runFork((0,tU.AJ)(e,r,{type:t,id:d.id,timestamp:d.timestamp,...n},z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error(`Failed to save ${t} item:`,e))),eb.NWQ(()=>eb.rIH)))}},[Y,e,r,M]),ec=(0,s.useCallback)(async t=>{let n=l.find(e=>e.id===t);if(i(e=>e.filter(e=>e.id!==t)),w(e=>e===t?null:e),c(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=t2(n._type);e?.onClose?.(n)}r&&u.t4.runFork((0,tU.SN)(e,r,t,z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to delete plugin item:",e))),eb.NWQ(()=>eb.rIH)))},[l,e,r]);A.current=ed,D.current=es;let eu=(0,s.useCallback)((t,n)=>{r&&u.t4.runFork((0,tU.bv)(e,r,t,{sleeping:n},z.current).pipe(eb.NWQ(()=>eb.rIH)))},[e,r]),em=(0,s.useCallback)(e=>{c(t=>new Set(t).add(e)),eu(e,!0)},[eu]),ex=(0,s.useCallback)(e=>{c(t=>{let r=new Set(t);return r.delete(e),r}),eu(e,!1)},[eu]),eh=(0,s.useCallback)(async t=>{L(t),r&&await u.t4.runPromise((0,tU.cm)(e,r,t,z.current).pipe(eb.NWQ(()=>eb.rIH)))},[e,r]),ef=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...l.map(e=>({type:e._type,data:e}))];if(!M||0===M.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(M.map((e,t)=>[e,t])),r=[],n=[];for(let s of e)t.has(s.data.id)?r.push(s):n.push(s);return r.sort((e,r)=>t.get(e.data.id)-t.get(r.data.id)),n.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime()),[...r,...n]},[o,l,M]);H.current=ef,(0,s.useEffect)(()=>{R.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let ep=async()=>{let t=await u.t4.runPromise((0,tU.QF)(e,r).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to load env:",e))),eb.DM4(()=>({env:{},home:""}))));y(t.env),N.current=t.home},eg=async()=>{S(await u.t4.runPromise((0,tU.Jn)().pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to load aliases:",e))),eb.DM4(()=>({})))))},ev=async()=>{if(!r)return;let t=await u.t4.runPromise((0,tU.DN)(e,r).pipe(eb.DM4(()=>[])));t.length>0&&L(t)};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await Z(0),e.current||await ee(e)})(),ep(),eg(),ev(),()=>{e.current=!0}},[Z,ee]),(0,s.useEffect)(()=>()=>{null!==E.current&&cancelAnimationFrame(E.current)},[]),(0,s.useEffect)(()=>()=>{r9()},[]),{commands:o,pluginItems:l,sleepingBubbles:d,consoleItems:ef,currentCwd:m,selectedCommandId:j,setSelectedCommandId:w,customEnv:k,setCustomEnv:y,aliases:C,setAliases:S,isLoadingHistory:h,hasMoreHistory:p,currentPage:b,scrollRef:W,commandHistoryRef:R,ptySizeRef:I,executeCommandRef:D,executeCommand:es,interruptCommand:ea,rerunCommand:el,deleteCommand:ei,addPluginItem:ed,closePluginItem:ec,handleBubbleSleep:em,handleBubbleWake:ex,loadHistory:Z,scrollToBottom:Y,saveBubbleOrder:eh,sendStdin:r4,resizePty:r3,subscribePtyOutput:V,subscribePtyReset:K,subscribePtyRefresh:J}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a}),[W,O]=(0,s.useState)(null),[_,q]=(0,s.useState)(0),[V,U]=(0,s.useState)(0),[K,Q]=(0,s.useState)(!0),[J,G]=(0,s.useState)(!1),[Y,Z]=(0,s.useState)(!1),[X,ee]=(0,s.useState)(!1),[et,er]=(0,s.useState)(!1),en=(0,s.useRef)(null),es=(0,s.useRef)(null),ea=(0,s.useRef)(null),el=(0,s.useRef)(!1),ei=(0,s.useRef)(null),ed=(0,s.useRef)(null),ec=(0,s.useRef)([]);(0,s.useEffect)(()=>{ec.current=c},[c]);let eu=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[m]),em=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollTop<50},[m]),ex=(0,s.useCallback)(()=>{ee(!em()),er(!eu())},[eu,em]),eh=(0,s.useCallback)(()=>{es.current?.scrollIntoView({behavior:"smooth"})},[]),ef=async()=>{let t=await u.t4.runPromiseExit((0,tU.D0)(e));if("Success"===t._tag){let e=t.value.settings;e?.gridLayout!==void 0&&Q(e.gridLayout)}else console.error("Failed to load project settings:",t.cause)};(0,s.useEffect)(()=>{queueMicrotask(()=>ef())},[]);let ep=(0,s.useCallback)(()=>{el.current=!0},[]),eg=(0,s.useCallback)((e,t)=>{if(!el.current)return void e.preventDefault();el.current=!1,ei.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t),e.currentTarget.style.opacity="0.4";let r=e.currentTarget.querySelector("[data-drag-handle]");if(r){let t=r.cloneNode(!0);t.style.cssText="position:fixed;top:-9999px;left:-9999px;width:"+r.offsetWidth+"px;background:hsl(var(--card));color:hsl(var(--foreground));box-shadow:var(--elevation-2);border-radius:8px;padding:4px 12px;opacity:0.9;",document.body.appendChild(t),e.dataTransfer.setDragImage(t,20,16),requestAnimationFrame(()=>document.body.removeChild(t))}},[]),ev=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",ed.current=t},[]),ej=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ew=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ek=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ey=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=ei.current,r=ed.current;if(ei.current=null,ed.current=null,!t||!r||t===r)return;let n=ec.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let a=[...n];a[s]=r,a[o]=t,R(a)},[R]),eN=(0,s.useCallback)(e=>{O(t=>t===e?null:e)},[]),eC=(0,s.useCallback)((e,t)=>k("browser",e,t),[k]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),x&&eN(x))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[x,eN]),(0,s.useEffect)(()=>{let e=m.current;if(!e)return;let t=new ResizeObserver(([e])=>{U(e.contentRect.height)});return t.observe(e),U(e.clientHeight),()=>t.disconnect()},[m]),(0,s.useEffect)(()=>{let e=m.current;if(e)return W?q(e.clientHeight):(e.style.overflow="",q(0)),()=>{e&&(e.style.overflow="")}},[W,m]),(0,s.useEffect)(()=>{let e=m.current;if(!e||!W||!_)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${W}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[W,_,m]);let[eS,eM]=(0,s.useState)(null);(0,s.useEffect)(()=>{i&&(O(null),eM(i.commandId))},[i]),(0,s.useEffect)(()=>{if(!eS||!c.some(e=>e.data.id===eS))return;let e=requestAnimationFrame(()=>{let e=m.current,t=e?.querySelector(`[data-bubble-id="${CSS.escape(eS)}"]`);if(!e||!t)return;eM(null),h(eS);let r=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r.top-n.top-Math.max(0,(n.height-r.height)/2);e.scrollTo({top:e.scrollTop+s,behavior:"smooth"})});return()=>cancelAnimationFrame(e)},[eS,c,m,h]),(0,s.useEffect)(()=>{if(!eS)return;let e=setTimeout(()=>{eM(null),(0,T.oR)(d("runningTerminals.notFound"),"error")},3e3);return()=>clearTimeout(e)},[eS,d]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&w(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[w]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.url;t&&k("browser",t)};return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[k]);let eL=V>0?Math.floor((V-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:en,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:m,onScroll:ex,className:`console-scroll-root flex-1 overflow-y-auto ${W?"":"py-4 px-4"}`,children:0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"w-full max-w-md flex flex-col gap-4 text-sm",children:[(0,n.jsx)("p",{className:"text-muted-foreground",children:d("console.emptyIntro")}),(0,n.jsx)("ul",{className:"flex flex-col gap-2",children:nw.map(e=>(0,n.jsxs)("li",{className:"flex items-start gap-3",children:[(0,n.jsx)("span",{className:"w-16 flex-shrink-0 text-foreground font-medium",children:d(e.label)}),(0,n.jsxs)("span",{className:"flex-1 flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"flex flex-wrap gap-1",children:e.triggers.map(e=>(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-xs font-mono text-muted-foreground",children:e},e))}),e.notes?.map(e=>(0,n.jsx)("span",{className:"text-xs leading-snug text-muted-foreground/70",children:d(e)},e))]})]},e.key))}),(0,n.jsxs)("button",{type:"button",onClick:()=>w(nb),title:d("console.launchShell"),className:"self-start flex items-center gap-2 px-4 py-2 rounded-lg border border-input bg-background text-sm text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 transition-all",children:[(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),"New PTY"]})]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:es}),I&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>F(B+1),disabled:D,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors disabled:opacity-50",children:D?d("console.loadingMore"):d("console.loadMoreHistory")})}),(0,n.jsx)("div",{className:W?"flex flex-col gap-3":K?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:c.map(t=>(0,n.jsx)(r7,{item:t,selected:x===t.data.id,maximized:W===t.data.id,initialSleeping:N.has(t.data.id),tabId:r,projectCwd:e,expandedHeight:_,bubbleContentHeight:eL,onDragStart:eg,onDragOver:ev,onDragEnter:ej,onDragLeave:ew,onDrop:ek,onDragEnd:ey,onSelectId:h,onInterruptId:f,onStdin:p,onDeleteCommand:g,onRerun:b,subscribePtyOutput:A,subscribePtyReset:H,subscribePtyRefresh:z,ptySizeRef:v,resizePty:j,onToggleMaximizeId:eN,onTitleMouseDown:ep,onClosePlugin:y,addBrowserItem:eC,onSleep:C,onWake:S},t.data.id))}),(0,n.jsx)("div",{ref:ea})]})}),!W&&c.length>0&&(0,n.jsx)(nf,{showTop:X,showBottom:et,onScrollTop:eh,onScrollBottom:M}),(0,n.jsx)(nh,{cwd:e,currentCwd:L,commandHistoryRef:E,gridLayout:K,onGridLayoutChange:t=>{Q(t),u.t4.runFork((0,tU.Yn)({cwd:e,settings:{gridLayout:t}}).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to save project settings:",e))),eb.NWQ(()=>eb.rIH)))},onExecute:w,onAddPluginItem:k,onShowEnvManager:()=>G(!0),onOpenShell:()=>w(nb),onOpenNote:l}),J&&(0,n.jsx)(nr,{cwd:e,tabId:r,onClose:()=>G(!1),onSave:e=>P(e)}),Y&&(0,n.jsx)(ns,{onClose:()=>Z(!1),onSave:e=>$(e)})]})});var ny=r(83897),nN=r(54271);function nC(e,t,r,n){return n&&r&&t.includes(e)}var nS=r(54356),nM=r(76412),nL=r(24058),nE=r(56058),nP=r(32880),n$=r(29899),nT=r(98307),nR=r(65153),nI=r(45720);function nF({cwd:e,sessionId:t,engine:r,onOpenProjectSessions:a,onOpenSessionBrowser:l,onOpenSettings:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(!1),m=t?(0,nI.X)(r,t):null;return(0,n.jsx)("div",{className:"border-b border-border px-4 py-3 bg-card",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6"}),(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"One seat. One AI. Everything under control."})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e&&(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help","data-tooltip":`CWD: ${e}`,children:e}),!e&&t&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Session: ",t.slice(0,8),"..."]}),e&&(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.browseAllSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),m&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(m).then(()=>{u(!0),setTimeout(()=>u(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-11 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:c?d("chat.copiedCommandTooltip"):d("chat.copyCommandTooltip",{command:m}),children:c?(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})})}),(0,n.jsx)("button",{onClick:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("settings.title"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]})]})})}function nB({tokenUsage:e,rateLimitInfo:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(()=>Date.now());(0,s.useEffect)(()=>{if(!t?.resetsAt)return;let e=setInterval(()=>l(Date.now()),3e4);return()=>clearInterval(e)},[t?.resetsAt]);let i=t?.status==="rejected"?"text-red-11":t?.status==="allowed_warning"?"text-amber-11":"text-muted-foreground",d=t?.status==="rejected"?r("chat.rateLimitRejected","Rate Limited"):t?.status==="allowed_warning"?r("chat.rateLimitWarning","Approaching Limit"):null,c=e=>{if(!e)return"";let t=(e<1e12?1e3*e:e)-a;if(t<=0)return"";let r=Math.ceil(t/6e4);if(r<60)return`${r}m`;let n=Math.floor(r/60),s=r%60;return s>0?`${n}h${s}m`:`${n}h`},u=e=>e?e.replace(/_/g," "):"";return(0,n.jsx)("div",{className:"px-4 py-1.5 border-t border-border ",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[t&&d&&(0,n.jsxs)("span",{className:`flex items-center gap-1 ${i}`,"data-tooltip":[t.rateLimitType&&`Type: ${u(t.rateLimitType)}`,null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&`Resets in: ${c(t.resetsAt)}`,t.isUsingOverage&&"Using overage"].filter(Boolean).join(" \xb7 "),children:["rejected"===t.status?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:[(0,n.jsx)("strong",{children:d}),null!=t.utilization&&` ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&` \xb7 ${c(t.resetsAt)}`]})]}),t&&!d&&t.resetsAt&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5","data-tooltip":[t.rateLimitType&&u(t.rateLimitType),null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,`Resets in: ${c(t.resetsAt)}`].filter(Boolean).join(" \xb7 "),children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),null!=t.utilization?(0,n.jsxs)("span",{children:[(100*t.utilization).toFixed(0),"%"]}):(0,n.jsx)("span",{children:c(t.resetsAt)})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsxs)("span",{children:[r("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens).toLocaleString()})]})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),(0,n.jsxs)("span",{children:[r("chat.output"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:e.outputTokens.toLocaleString()})]})]}),(e.cacheReadInputTokens>0||e.cacheCreationInputTokens>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-brand",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})}),(0,n.jsxs)("span",{children:["Cache: ",(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens)*100).toFixed(0),"%"]})]}),e.totalCostUsd>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-green-11",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:["$",e.totalCostUsd.toFixed(4)]})]})]})})}function nD({isOpen:e,onClose:t,cwd:r,sessionId:a,onSelectMessage:l}){let{t:d}=(0,o.Bd)(),[c,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(""),[v,j]=(0,s.useState)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(null);(0,H.E)(t,e),(0,s.useEffect)(()=>{if(!e){x(null),f(!1),g(""),j(null);return}if(!r||!a)return void x([]);let t=!1;return u.t4.runPromiseExit((0,m.nM)(r,a)).then(e=>{t||("Success"===e._tag?x(e.value.messages):(console.error("Failed to load user message index:",e.cause),f(!0),x([])))}),()=>{t=!0}},[e,r,a]);let y=(0,s.useMemo)(()=>{if(!c)return[];let e=c.map((e,t)=>({entry:e,ordinal:t+1})),t=p.trim().toLowerCase();return t?e.filter(e=>e.entry.content.toLowerCase().includes(t)):e},[c,p]),N=p.trim().length>0;(0,s.useEffect)(()=>{if(!e||N||!c)return;let t=w.current;t&&(t.scrollTop=t.scrollHeight)},[e,N,c]);let C=(0,s.useCallback)(async e=>{j(e.id);try{await l(e)}finally{j(null)}t()},[l,t]);if(!e)return null;let S=null===c,M=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:i.iG,onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:d("userMessages.title")}),c&&c.length>0&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:d("userMessages.count",{shown:y.length,total:c.length})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:k,type:"text",autoFocus:!0,placeholder:d("userMessages.searchPlaceholder"),value:p,onChange:e=>g(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),p&&(0,n.jsx)("button",{onClick:()=>{g(""),k.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:d("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{ref:w,className:"flex-1 overflow-y-auto",children:S?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("common.loading")}):h?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("userMessages.loadFailed")}):0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noMessages")}):0===y.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noResults")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:y.map(({entry:e,ordinal:t})=>{let r,s=e.timestamp?function(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let r=new Date;return t.toDateString()===r.toDateString()?t.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}(e.timestamp):"";return(0,n.jsx)("button",{onClick:()=>{C(e)},className:"w-full px-4 py-3 text-left hover:bg-hover transition-colors","data-tooltip":(r=e.content.trim()).length>500?`${r.slice(0,500)}…`:r,children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[t,"."]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-sm text-foreground truncate",children:e.content.replace(/\s+/g," ").trim()}),v===e.id&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:d("userMessages.jumping")})]}),s&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:s})]})},e.id)})})})]})});return(0,n.jsx)(b.ZL,{children:M})}var nA=r(67589),nH=r(20917),nz=r(74086),nW=r(201),nO=r(94290),n_=r(80860),nq=r(36351);function nV({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=async t=>{t.stopPropagation();try{var n;if(!navigator.clipboard?.write||"u"<typeof ClipboardItem)throw Error("Clipboard image write is unavailable");let t=await (n=e.preview,new Promise((e,t)=>{let r=new Image;r.onload=()=>{let n=document.createElement("canvas");n.width=r.naturalWidth,n.height=r.naturalHeight;let s=n.getContext("2d");s?(s.drawImage(r,0,0),n.toBlob(r=>{r?e(r):t(Error("Could not encode image"))},"image/png")):t(Error("Canvas is unavailable"))},r.onerror=()=>t(Error("Could not load image")),r.src=n}));await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),(0,T.oR)(r("imagePreview.copiedImage"),"success")}catch{(0,T.oR)(r("common.copyFailed"),"error")}},a=(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,n.jsxs)("div",{className:"absolute top-4 right-4 flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",title:r("imagePreview.copyImage"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V5a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2M7 7h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2Z"})})}),(0,n.jsx)("button",{type:"button",onClick:t,className:"w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,n.jsx)(b.ZL,{children:a})}function nU({images:e,onRemove:t,disabled:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(null);return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 p-2 border-b border-border",children:e.map(e=>(0,n.jsxs)("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-border cursor-pointer",onClick:()=>i(e),children:[(0,n.jsx)("img",{src:e.preview,alt:a("imagePreview.previewImage"),className:"w-full h-full object-cover hover:opacity-90 transition-opacity"}),(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),t(e.id)},className:"absolute top-0 right-0 w-5 h-5 bg-black/60 hover:bg-black/80 text-white text-xs flex items-center justify-center rounded-bl-lg opacity-0 group-hover:opacity-100 transition-opacity",title:a("imagePreview.deleteImage"),children:"✕"})]},e.id))}),l&&(0,n.jsx)(nV,{image:l,onClose:()=>i(null)})]})}var nK=r(93777),nQ=r(38798),nJ=r(94514),nG=r(59883),nY=r(56204),nZ=r(49387),nX=r(21362),n0=r(63393);let n1=()=>Math.random().toString(36).slice(2,10),n2=e=>e.replace(/\\n/g,"\n");function n5(e){let t=[],r=null;for(let[n,s]of e.split(/\r?\n/).entries()){if(!s.trim())continue;let e=s.match(/^\s*-(?:\s+(.*))?$/);if(e){let t=(e[1]??"").trim();if(!r)return{ok:!1,line:n+1};r.isGroup=!0,t&&r.children.push(n2(t));continue}if(/^\s/.test(s))return{ok:!1,line:n+1};let o=s.trim();o&&(r={text:n2(o),children:[],isGroup:!1},t.push(r))}return{ok:!0,nodes:t.map(e=>e.isGroup?{id:n1(),name:e.text,items:e.children.map(e=>({id:n1(),text:e}))}:{id:n1(),text:e.text})}}function n4({title:e,nodes:t,onSave:r,onClose:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(()=>t.flatMap(e=>(0,m._9)(e)?[e.name.replace(/\n/g,"\\n"),...e.items.length>0?e.items.map(e=>`- ${e.text.replace(/\n/g,"\\n")}`):["- "]]:[e.text.replace(/\n/g,"\\n")]).join("\n")),[c,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(!1),f=n5(i);(0,H.E)(a);let p=(0,s.useCallback)(async()=>{let e=n5(i);!e.ok||c||((u(!0),h(!1),await r(e.nodes))?a():(u(!1),h(!0)))},[a,r,c,i]);return(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{"data-quick-instruction-layer":"",className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":e,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:e}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:l("chat.quickInstructionsMarkdownHint")})]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":l("common.cancel"),children:(0,n.jsx)(ei.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,wrap:"off",value:i,onChange:e=>d(e.target.value),placeholder:l("chat.quickInstructionsMarkdownPlaceholder"),rows:24,spellCheck:!1,className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y overflow-x-auto whitespace-pre px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:f.ok?x?l("chat.saveQuickInstructionsFailed"):"":l("chat.quickInstructionsMarkdownError",{line:f.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:l("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!f.ok||c,onClick:p,className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:l(c?"chat.savingQuickInstructions":"common.save")})]})]})]})})})}let n3="data-quick-instruction-layer",n6=()=>Math.random().toString(36).slice(2,10);function n8({groups:e,value:t,onChange:r,onSubmit:a,onCancel:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[x,h]=(0,s.useState)(0),f=(0,s.useRef)(null),g=(0,s.useRef)(null),b=[null,...e.map(e=>e.id)],v=null===t?i("chat.instructionGroupNone"):e.find(e=>e.id===t)?.name??i("chat.instructionGroupNone"),j=(0,s.useCallback)(()=>{let r=f.current?.getBoundingClientRect();r&&(m(((e,t,r)=>{let n=Math.min(e.width,r.width-16),s=Math.min(Math.max(8,e.left),Math.max(8,r.width-n-8)),o=r.height-e.bottom-2-8,a=e.top-2-8,l=28*t+8;if(o>=Math.min(l,96)||o>=a)return{left:s,top:e.bottom+2,width:n,maxHeight:Math.max(28,Math.min(l,o))};let i=Math.max(28,Math.min(l,a));return{left:s,top:e.top-2-i,width:n,maxHeight:i}})(r,e.length+1,{width:window.innerWidth,height:window.innerHeight})),h(Math.max(0,b.indexOf(t))),c(!0))},[e.length,b,t]),w=(0,s.useCallback)(()=>{c(!1),m(null),f.current?.focus()},[]),k=(0,s.useCallback)(e=>{r(e),w()},[r,w]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;g.current?.contains(t)||f.current?.contains(t)||(c(!1),m(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]),(0,s.useEffect)(()=>{if(!d)return;let e=()=>{c(!1),m(null)};return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[d]);let y=(0,s.useCallback)(e=>{d?"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),w()):"ArrowDown"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.min(b.length-1,e+1))):"ArrowUp"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.max(0,e-1))):"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),k(b[x]??null)):"ArrowDown"===e.key||" "===e.key?(e.preventDefault(),e.stopPropagation(),j()):"Enter"===e.key?(e.preventDefault(),e.stopPropagation(),a()):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l())},[d,j,w,k,b,x,a,l]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:f,type:"button",onClick:()=>d?w():j(),onKeyDown:y,className:"w-[140px] min-w-0 flex-shrink-0 px-2 py-1 flex items-center gap-1 text-xs rounded border border-input bg-background hover:bg-hover focus:outline-none focus:ring-1 focus:ring-ring transition-colors",title:i("chat.instructionGroupLabel"),children:[(0,n.jsx)(nQ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-left ${null===t?"text-muted-foreground":""}`,children:v}),(0,n.jsx)(tO.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"})]}),d&&u&&(0,p.createPortal)((0,n.jsx)("div",{ref:g,[n3]:"",role:"listbox",style:{left:u.left,top:u.top,width:u.width,maxHeight:u.maxHeight},className:"fixed z-[60] py-1 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:b.map((r,s)=>{let o=r===t;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":o,onClick:()=>k(r),onMouseEnter:()=>h(s),className:`w-full min-w-0 px-2 py-1 flex items-center gap-1.5 text-xs text-left transition-colors ${s===x?"bg-hover":""}`,children:[(0,n.jsx)(nJ.A,{className:`w-3 h-3 flex-shrink-0 ${o?"text-brand":"opacity-0"}`}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate ${null===r?"text-muted-foreground":""}`,children:null===r?i("chat.instructionGroupNone"):e.find(e=>e.id===r)?.name})]},r??"__none__")})}),document.body)]})}function n9({initialValue:e,placeholder:t,groupChoices:r,initialGroupId:o,onCommit:a,onCancel:l}){let[i,d]=(0,s.useState)(e),[c,u]=(0,s.useState)(o??null),m=(0,s.useCallback)(()=>{let e=i.trim();e&&a(e,c)},[i,c,a]),x=(0,s.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing?"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l()):(e.preventDefault(),e.stopPropagation(),m())},[m,l]);return(0,n.jsxs)("div",{className:"mb-1 flex items-center gap-1",children:[(0,n.jsx)("input",{type:"text",value:i,onChange:e=>d(e.target.value),onKeyDown:x,placeholder:t,autoFocus:!0,className:"flex-1 min-w-0 px-2 py-1 text-xs rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring"}),r&&r.length>0&&(0,n.jsx)(n8,{groups:r,value:c,onChange:u,onSubmit:m,onCancel:l})]})}let n7=(e,t)=>`flex items-center group min-w-0 rounded transition-opacity ${e?"opacity-50":""} ${t?"border-t-2 border-brand":""}`,se="p-1 text-muted-foreground hover:text-foreground rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",st=(0,s.memo)(function({item:e,isDragging:t,isDragOver:r,onSelect:s,onInsert:a,onEdit:l,onDelete:i,onDragStart:d,onDragOver:c,onDrop:u,onDragEnd:m,management:x=!0}){let{t:h}=(0,o.Bd)();return(0,n.jsxs)("div",{draggable:x,onDragStart:x?()=>d(e.id):void 0,onDragOver:x?t=>c(t,e.id):void 0,onDrop:x?()=>u(e.id):void 0,onDragEnd:x?m:void 0,className:n7(t,r),children:[x&&(0,n.jsx)(nG.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsx)($.m,{content:e.text,children:(0,n.jsxs)("button",{type:"button",onClick:()=>s(e.text),className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",children:[(0,n.jsx)(nY.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:e.text})]})}),(0,n.jsx)("button",{type:"button",onClick:()=>a(e.text),className:se,title:h("chat.insertQuickInstruction"),children:(0,n.jsx)(nq.A,{className:"w-3 h-3"})}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>l(e.id),className:se,title:h("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(e.id),className:`${se} hover:text-destructive`,title:h("common.delete"),children:(0,n.jsx)(ei.A,{className:"w-3 h-3"})})]})]})}),sr=(0,s.memo)(function({group:e,isOpen:t,isDragging:r,isDragOver:a,isDragActive:l,onHoverOpen:i,onHoverClose:d,onToggle:c,onRename:u,onDelete:m,onDragStart:x,onDragOver:h,onDrop:f,onDragEnd:p,management:g=!0}){let{t:b}=(0,o.Bd)(),v=(0,s.useRef)(null),j=(0,s.useCallback)(()=>v.current?.getBoundingClientRect(),[]);return(0,n.jsxs)("div",{ref:v,draggable:g,onDragStart:g?()=>x(e.id):void 0,onDragOver:g?t=>h(t,e.id):void 0,onDrop:g?()=>f(e.id):void 0,onDragEnd:g?p:void 0,onMouseEnter:()=>{if(l)return;let t=j();t&&i(e.id,t)},onMouseLeave:()=>{l||d()},className:`${n7(r,a)} ${t?"bg-hover":""}`,children:[g&&(0,n.jsx)(nG.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{let t=j();t&&c(e.id,t)},className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",title:e.name,children:[(0,n.jsx)(nQ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.name}),(0,n.jsxs)("span",{className:"ml-auto flex items-center gap-1 flex-shrink-0 text-[10px] text-muted-foreground",children:[e.items.length>0&&e.items.length,(0,n.jsx)(nX.A,{className:"w-3 h-3"})]})]}),g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>u(e.id),className:se,title:b("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>m(e.id),className:`${se} hover:text-destructive`,title:b("common.delete"),children:(0,n.jsx)(ei.A,{className:"w-3 h-3"})})]})]})});function sn({group:e,position:t,groupChoices:r,editId:s,isAdding:a,isDragActive:l,dragId:i,dragOverId:d,onMouseEnter:c,onMouseLeave:u,onSelect:m,onInsert:x,onStartEdit:h,onCommitEdit:f,onCancelEdit:g,onDelete:b,onStartAdd:v,onCommitAdd:j,onCancelAdd:w,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S=!0}){let{t:M}=(0,o.Bd)();return(0,p.createPortal)((0,n.jsxs)("div",{[n3]:"",onMouseEnter:c,onMouseLeave:()=>{l||u()},style:{left:t.left,top:t.top,width:t.width,maxHeight:t.maxHeight},className:"fixed z-50 p-2 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1 truncate",children:e.name}),S&&(0,n.jsx)("button",{type:"button",onClick:v,className:"p-0.5 text-muted-foreground hover:text-foreground rounded flex-shrink-0",title:M("chat.addQuickInstruction"),children:(0,n.jsx)(nt.A,{className:"w-3.5 h-3.5"})})]}),S&&a&&(0,n.jsx)(n9,{initialValue:"",placeholder:M("chat.quickInstructionPlaceholder"),onCommit:e=>j(e),onCancel:w}),0===e.items.length&&!a&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:M("chat.noQuickInstructions")}),e.items.map(t=>s===t.id?(0,n.jsx)(n9,{initialValue:t.text,placeholder:M("chat.quickInstructionPlaceholder"),groupChoices:r,initialGroupId:e.id,onCommit:(e,r)=>f(t.id,e,r),onCancel:g},`edit-${t.id}`):(0,n.jsx)(st,{item:t,isDragging:i===t.id,isDragOver:d===t.id&&i!==t.id,onSelect:m,onInsert:x,onEdit:h,onDelete:b,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S},t.id))]}),document.body)}function ss({label:e,nodes:t,scope:r,openGroupId:a,flyoutPosition:l,onOpenFlyout:i,onCloseFlyout:d,onKeepFlyout:c,onSave:u,onSelect:x,onInsert:h,management:f=!0,onManage:p}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)(null),L=t.filter(m._9),E=a?L.find(e=>e.id===a)??null:null,P=(0,s.useRef)(t);P.current=t;let $=(0,s.useRef)(a);$.current=a;let R=(0,s.useRef)(null);(0,s.useEffect)(()=>{w(!1)},[a]);let I=(0,s.useCallback)(e=>{y(null),u(r,e)},[u,r]),F=(0,s.useCallback)(e=>{v(null),I([...P.current,{id:n6(),text:e}])},[I]),B=(0,s.useCallback)(e=>{v(null),I([...P.current,{id:n6(),name:e,items:[]}])},[I]),D=(0,s.useCallback)((e,t,r,n)=>{let s=P.current,o={id:e,text:t};if(r===n)return void I(s.map(t=>(0,m._9)(t)?t.id===n?{...t,items:t.items.map(t=>t.id===e?o:t)}:t:null===n&&t.id===e?o:t));let a=null===r?s.filter(t=>(0,m._9)(t)||t.id!==e):s.map(t=>(0,m._9)(t)&&t.id===r?{...t,items:t.items.filter(t=>t.id!==e)}:t);I(null===n?[...a,o]:a.map(e=>(0,m._9)(e)&&e.id===n?{...e,items:[...e.items,o]}:e))},[I]),A=(0,s.useCallback)((e,t)=>{I(P.current.map(r=>(0,m._9)(r)&&r.id===e?{...r,name:t}:r))},[I]),H=(0,s.useCallback)(async e=>{let t=P.current.find(t=>t.id===e);if(t&&(0,m._9)(t)&&t.items.length>0){if(!await (0,T.lJ)(g("chat.deleteInstructionGroupConfirm",{name:t.name,count:t.items.length}),{danger:!0,confirmText:g("common.delete")}))return;d()}y(null),I(P.current.filter(t=>t.id!==e))},[I,g,d]),z=(0,s.useCallback)(e=>{let t=$.current;t&&I(P.current.map(r=>(0,m._9)(r)&&r.id===t?e(r):r))},[I]),W=(0,s.useCallback)(e=>{w(!1),z(t=>({...t,items:[...t.items,{id:n6(),text:e}]}))},[z]),O=(0,s.useCallback)(e=>{y(null),z(t=>({...t,items:t.items.filter(t=>t.id!==e)}))},[z]),_=(0,s.useCallback)((e,t,r)=>{D(e,t,$.current,r)},[D]),q=(0,s.useCallback)(e=>{R.current=e,C(e)},[]),V=(0,s.useCallback)(()=>{q(null),M(null)},[q]),U=(0,s.useCallback)(e=>{q(e),d()},[q,d]),K=(0,s.useCallback)((e,t)=>{e.preventDefault(),M(t)},[]),Q=(e,t,r)=>{let n=e.findIndex(e=>e.id===t),s=e.findIndex(e=>e.id===r);if(n<0||s<0)return e;let o=[...e],[a]=o.splice(n,1);return o.splice(s,0,a),o},J=(0,s.useCallback)(e=>{let t=R.current;V(),t&&t!==e&&I(Q(P.current,t,e))},[I,V]),G=(0,s.useCallback)(e=>{let t=R.current;V(),t&&t!==e&&z(r=>({...r,items:Q(r.items,t,e)}))},[z,V]),Y=e=>{let t=P.current.find(t=>(0,m._9)(t)&&t.id===e);return t&&(0,m._9)(t)?t.items.length:0},Z=(0,s.useCallback)((e,t)=>{i(r,e,t,Y(e),!1)},[i,r]),X=(0,s.useCallback)((e,t)=>{$.current===e?d():i(r,e,t,Y(e),!0)},[i,d,r]);return(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1",children:e}),f?(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{y(null),v("group")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:g("chat.addInstructionGroup"),children:(0,n.jsx)(n0.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>{y(null),v("instruction")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:g("chat.addQuickInstruction"),children:(0,n.jsx)(nt.A,{className:"w-3.5 h-3.5"})})]}):p?(0,n.jsx)("button",{type:"button",onClick:p,className:"p-1 text-muted-foreground hover:text-brand rounded hover:bg-hover transition-colors",title:g("common.edit"),"aria-label":g("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3.5 h-3.5"})}):null]}),"instruction"===b&&(0,n.jsx)(n9,{initialValue:"",placeholder:g("chat.quickInstructionPlaceholder"),onCommit:e=>F(e),onCancel:()=>v(null)}),"group"===b&&(0,n.jsx)(n9,{initialValue:"",placeholder:g("chat.instructionGroupNamePlaceholder"),onCommit:e=>B(e),onCancel:()=>v(null)}),0===t.length&&!b&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:g("chat.noQuickInstructions")}),t.map(e=>k===e.id?(0,m._9)(e)?(0,n.jsx)(n9,{initialValue:e.name,placeholder:g("chat.instructionGroupNamePlaceholder"),onCommit:t=>A(e.id,t),onCancel:()=>y(null)},`edit-${e.id}`):(0,n.jsx)(n9,{initialValue:e.text,placeholder:g("chat.quickInstructionPlaceholder"),groupChoices:L,initialGroupId:null,onCommit:(t,r)=>D(e.id,t,null,r),onCancel:()=>y(null)},`edit-${e.id}`):(0,m._9)(e)?(0,n.jsx)(sr,{group:e,isOpen:a===e.id,isDragging:N===e.id,isDragOver:S===e.id&&N!==e.id,isDragActive:null!==N,onHoverOpen:Z,onHoverClose:d,onToggle:X,onRename:y,onDelete:H,onDragStart:U,onDragOver:K,onDrop:J,onDragEnd:V,management:f},e.id):(0,n.jsx)(st,{item:e,isDragging:N===e.id,isDragOver:S===e.id&&N!==e.id,onSelect:x,onInsert:h,onEdit:y,onDelete:H,onDragStart:U,onDragOver:K,onDrop:J,onDragEnd:V,management:f},e.id)),E&&l&&(0,n.jsx)(sn,{group:E,position:l,groupChoices:L,editId:k,isAdding:j,isDragActive:null!==N,dragId:N,dragOverId:S,onMouseEnter:c,onMouseLeave:d,onSelect:x,onInsert:h,onStartEdit:y,onCommitEdit:_,onCancelEdit:()=>y(null),onDelete:O,onStartAdd:()=>{y(null),w(!0)},onCommitAdd:W,onCancelAdd:()=>w(!1),onDragStart:q,onDragOver:K,onDrop:G,onDragEnd:V,management:f})]})}function so({cwd:e,anchorRef:t,onClose:r,onSelect:a,onInsert:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)([]),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(null),v=(0,s.useRef)(null),j=(0,s.useRef)(null),w=(0,s.useCallback)(()=>{v.current&&(clearTimeout(v.current),v.current=null),j.current&&(clearTimeout(j.current),j.current=null)},[]);(0,s.useEffect)(()=>w,[w]),(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([u.t4.runPromiseExit((0,m.ZQ)()),e?u.t4.runPromiseExit((0,m.$x)(e)):null]);!t&&("Success"===r._tag?c(r.value.instructions??[]):console.error("Failed to load global instructions:",r.cause),n&&"Success"===n._tag?h(n.value.instructions??[]):n&&console.error("Failed to load project instructions:",n.cause))})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{let n;if((n=e.target)instanceof Element&&null!==n.closest(`[${n3}]`))return;let s=t.current;s&&!s.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]),(0,s.useEffect)(()=>{if(!f)return;let e=()=>{w(),p(null)};return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[f,w]);let k=(0,s.useCallback)((e,t,r,n,s)=>{w();let o=()=>{var s;let o,a,l,i,d,c,u;return p({scope:e,groupId:t,position:(a=(s={width:window.innerWidth,height:window.innerHeight}).width-r.right-4-8,l=r.left-4-8,i=288,a>=288?o=r.right+4:l>=288?o=r.left-4-288:a>=l?(i=Math.max(180,a),o=r.right+4):(i=Math.max(180,l),o=r.left-4-i),o=Math.min(Math.max(8,o),Math.max(8,s.width-i-8)),c=Math.min(d=Math.max(90,.6*s.height),30*n+40),(u=r.top-4)+c>s.height-8&&(u=s.height-8-c),{left:o,top:u=Math.max(8,u),width:i,maxHeight:d})})};s?o():v.current=setTimeout(o,150)},[w]),y=(0,s.useCallback)(()=>{w(),j.current=setTimeout(()=>p(null),300)},[w]),N=(0,s.useCallback)(()=>w(),[w]),C=(0,s.useCallback)(async(t,r)=>{let n="global"===t?c:h;n(r);let s=await u.t4.runPromiseExit((0,m.hZ)("global"===t?{scope:"global",instructions:r}:{cwd:e,instructions:r}));return"Failure"===s._tag?(console.error(`Failed to save ${t} instructions:`,s.cause),!1):(s.value?.instructions&&n(s.value.instructions),!0)},[e]),S=(0,s.useCallback)(e=>{r(),a(e)},[r,a]),M=(0,s.useCallback)(e=>{r(),l(e)},[r,l]),L=(0,s.useCallback)(async e=>!!g&&C(g,e),[g,C]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"absolute bottom-full left-0 mb-2 w-80 max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 max-h-[70vh] overflow-y-auto",children:[(0,n.jsx)(ss,{label:i("chat.globalInstructions"),nodes:d,scope:"global",openGroupId:f?.scope==="global"?f.groupId:null,flyoutPosition:f?.scope==="global"?f.position:null,onOpenFlyout:k,onCloseFlyout:y,onKeepFlyout:N,onSave:C,onSelect:S,onInsert:M,management:!1,onManage:()=>{w(),p(null),b("global")}}),e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(ss,{label:i("chat.projectInstructions"),nodes:x,scope:"project",openGroupId:f?.scope==="project"?f.groupId:null,flyoutPosition:f?.scope==="project"?f.position:null,onOpenFlyout:k,onCloseFlyout:y,onKeepFlyout:N,onSave:C,onSelect:S,onInsert:M,management:!1,onManage:()=>{w(),p(null),b("project")}})]})]}),g&&(0,n.jsx)(n4,{title:i("global"===g?"chat.editGlobalInstructions":"chat.editProjectInstructions"),nodes:"global"===g?d:x,onSave:L,onClose:()=>b(null)})]})}var sa=r(96625);let sl=(0,s.memo)(function({onSend:e,disabled:t,running:r,cwd:a,engine:l,onShowGitStatus:i,onShowComments:d,hasComments:c,onOpenNote:u,isFavorite:m,onToggleFavorite:x,onCreateScheduledTask:h,draft:f,setDraft:p,draftImages:g,setDraftImages:b,suggestion:v}){let{t:j}=(0,o.Bd)(),w=(0,s.useState)(""),k=(0,s.useState)([]),[y,N]=void 0!==f&&p?[f,p]:w,[C,S]=void 0!==g&&b?[g,b]:k,[M,L]=(0,s.useState)(!1),[E,P]=(0,s.useState)(!1),$=(0,s.useRef)(null),T=(0,s.useRef)(null),R=(0,s.useCallback)(()=>{let e=$.current;if(!e)return;e.style.height="auto";let t=Math.max(38,Math.min(e.scrollHeight,200));e.style.height=`${t}px`},[]);(0,s.useLayoutEffect)(()=>{R()},[y,R]);let I=(0,s.useMemo)(()=>l&&"claude"!==l?[]:[{name:"/plan",description:"Enable plan mode (read-only). /plan <task> to plan a task; /plan off to disable.",source:"builtin",argumentHint:"[task|off]"}],[l]),F=(0,sa.n)({value:y,onChange:N,textareaRef:$,extraCommands:I}),B=(0,s.useCallback)(()=>{let r=y.trim();(r||C.length>0)&&!t&&(e(r,C.length>0?C:void 0),N(""),S([]),$.current&&($.current.style.height="auto"))},[y,C,t,e]),D=(0,s.useCallback)(r=>{t||e(r)},[t,e]),A=(0,s.useCallback)(e=>{N(t=>{let r=t.replace(/\s+$/,"");return r?`${r}
32
+ Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,C,m,k,r,e,_,G,q]),ei=(0,s.useCallback)(async t=>{a(e=>e.filter(e=>e.id!==t)),q(t),r&&await u.t4.runPromise((0,tU.SN)(e,r,t,z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to delete command:",e))),eb.NWQ(()=>eb.rIH)))},[e,r,q]),ed=(0,s.useCallback)((t,n,s)=>{var o;let a=t2(t);if(!a)return;let l=a.parse(n);"cwd"in l&&!l.cwd&&(l.cwd=m);let d={id:(o=a.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...l};if(i(e=>[...e,d]),w(d.id),setTimeout(Y,100),s){let t=M&&M.length>0?[...M]:H.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,d.id):t.push(d.id),L(t),r&&u.t4.runFork((0,tU.cm)(e,r,t,z.current).pipe(eb.NWQ(()=>eb.rIH)))}if(r){let n=a.toHistory(d);u.t4.runFork((0,tU.AJ)(e,r,{type:t,id:d.id,timestamp:d.timestamp,...n},z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error(`Failed to save ${t} item:`,e))),eb.NWQ(()=>eb.rIH)))}},[Y,e,r,M]),ec=(0,s.useCallback)(async t=>{let n=l.find(e=>e.id===t);if(i(e=>e.filter(e=>e.id!==t)),w(e=>e===t?null:e),c(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=t2(n._type);e?.onClose?.(n)}r&&u.t4.runFork((0,tU.SN)(e,r,t,z.current).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to delete plugin item:",e))),eb.NWQ(()=>eb.rIH)))},[l,e,r]);A.current=ed,D.current=es;let eu=(0,s.useCallback)((t,n)=>{r&&u.t4.runFork((0,tU.bv)(e,r,t,{sleeping:n},z.current).pipe(eb.NWQ(()=>eb.rIH)))},[e,r]),em=(0,s.useCallback)(e=>{c(t=>new Set(t).add(e)),eu(e,!0)},[eu]),ex=(0,s.useCallback)(e=>{c(t=>{let r=new Set(t);return r.delete(e),r}),eu(e,!1)},[eu]),eh=(0,s.useCallback)(async t=>{L(t),r&&await u.t4.runPromise((0,tU.cm)(e,r,t,z.current).pipe(eb.NWQ(()=>eb.rIH)))},[e,r]),ef=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...l.map(e=>({type:e._type,data:e}))];if(!M||0===M.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(M.map((e,t)=>[e,t])),r=[],n=[];for(let s of e)t.has(s.data.id)?r.push(s):n.push(s);return r.sort((e,r)=>t.get(e.data.id)-t.get(r.data.id)),n.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime()),[...r,...n]},[o,l,M]);H.current=ef,(0,s.useEffect)(()=>{R.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let ep=async()=>{let t=await u.t4.runPromise((0,tU.QF)(e,r).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to load env:",e))),eb.DM4(()=>({env:{},home:""}))));y(t.env),N.current=t.home},eg=async()=>{S(await u.t4.runPromise((0,tU.Jn)().pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to load aliases:",e))),eb.DM4(()=>({})))))},ev=async()=>{if(!r)return;let t=await u.t4.runPromise((0,tU.DN)(e,r).pipe(eb.DM4(()=>[])));t.length>0&&L(t)};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await Z(0),e.current||await ee(e)})(),ep(),eg(),ev(),()=>{e.current=!0}},[Z,ee]),(0,s.useEffect)(()=>()=>{null!==E.current&&cancelAnimationFrame(E.current)},[]),(0,s.useEffect)(()=>()=>{r9()},[]),{commands:o,pluginItems:l,sleepingBubbles:d,consoleItems:ef,currentCwd:m,selectedCommandId:j,setSelectedCommandId:w,customEnv:k,setCustomEnv:y,aliases:C,setAliases:S,isLoadingHistory:h,hasMoreHistory:p,currentPage:b,scrollRef:W,commandHistoryRef:R,ptySizeRef:I,executeCommandRef:D,executeCommand:es,interruptCommand:ea,rerunCommand:el,deleteCommand:ei,addPluginItem:ed,closePluginItem:ec,handleBubbleSleep:em,handleBubbleWake:ex,loadHistory:Z,scrollToBottom:Y,saveBubbleOrder:eh,sendStdin:r4,resizePty:r3,subscribePtyOutput:V,subscribePtyReset:K,subscribePtyRefresh:J}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a}),[O,_]=(0,s.useState)(null),[q,V]=(0,s.useState)(0),[U,K]=(0,s.useState)(0),[Q,J]=(0,s.useState)(!0),[G,Y]=(0,s.useState)(!1),[Z,X]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(!1),[er,en]=(0,s.useState)(!1),es=(0,s.useRef)(null),ea=(0,s.useRef)(null),el=(0,s.useRef)(null),ei=(0,s.useRef)(!1),ed=(0,s.useRef)(null),ec=(0,s.useRef)(null),eu=(0,s.useRef)([]);(0,s.useEffect)(()=>{eu.current=m},[m]);let em=(0,s.useCallback)(()=>{let e=x.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[x]),ex=(0,s.useCallback)(()=>{let e=x.current;return!e||e.scrollTop<50},[x]),eh=(0,s.useCallback)(()=>{et(!ex()),en(!em())},[em,ex]),ef=(0,s.useCallback)(()=>{ea.current?.scrollIntoView({behavior:"smooth"})},[]),ep=async()=>{let t=await u.t4.runPromiseExit((0,tU.D0)(e));if("Success"===t._tag){let e=t.value.settings;e?.gridLayout!==void 0&&J(e.gridLayout)}else console.error("Failed to load project settings:",t.cause)};(0,s.useEffect)(()=>{queueMicrotask(()=>ep())},[]);let eg=(0,s.useCallback)(()=>{ei.current=!0},[]),ev=(0,s.useCallback)((e,t)=>{if(!ei.current)return void e.preventDefault();ei.current=!1,ed.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))}},[]),ej=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",ec.current=t},[]),ew=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ek=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ey=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),eN=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=ed.current,r=ec.current;if(ed.current=null,ec.current=null,!t||!r||t===r)return;let n=eu.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let a=[...n];a[s]=r,a[o]=t,I(a)},[I]),eC=(0,s.useCallback)(e=>{_(t=>t===e?null:e)},[]),eS=(0,s.useCallback)((e,t)=>y("browser",e,t),[y]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),h&&eC(h))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[d,h,eC]),(0,s.useEffect)(()=>{let e=x.current;if(!e)return;let t=new ResizeObserver(([e])=>{K(e.contentRect.height)});return t.observe(e),K(e.clientHeight),()=>t.disconnect()},[x]),(0,s.useEffect)(()=>{let e=x.current;if(e)return O?V(e.clientHeight):(e.style.overflow="",V(0)),()=>{e&&(e.style.overflow="")}},[O,x]),(0,s.useEffect)(()=>{let e=x.current;if(!e||!O||!q)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${O}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[O,q,x]);let[eM,eL]=(0,s.useState)(null);(0,s.useEffect)(()=>{i&&(_(null),eL(i.commandId))},[i]),(0,s.useEffect)(()=>{if(!eM||!m.some(e=>e.data.id===eM))return;let e=requestAnimationFrame(()=>{let e=x.current,t=e?.querySelector(`[data-bubble-id="${CSS.escape(eM)}"]`);if(!e||!t)return;eL(null),f(eM);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)},[eM,m,x,f]),(0,s.useEffect)(()=>{if(!eM)return;let e=setTimeout(()=>{eL(null),(0,T.oR)(c("runningTerminals.notFound"),"error")},3e3);return()=>clearTimeout(e)},[eM,c]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&k(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[k]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.url;t&&y("browser",t)};return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[y]);let eE=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:x,onScroll:eh,className:`console-scroll-root flex-1 overflow-y-auto ${O?"":"py-4 px-4"}`,children:0===m.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:nw.map(e=>(0,n.jsxs)("li",{className:"flex items-start gap-3",children:[(0,n.jsx)("span",{className:"w-16 flex-shrink-0 text-foreground font-medium",children: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:()=>k(nb),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:ea}),F&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>B(D+1),disabled:A,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors disabled:opacity-50",children:A?c("console.loadingMore"):c("console.loadMoreHistory")})}),(0,n.jsx)("div",{className:O?"flex flex-col gap-3":Q?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:m.map(t=>(0,n.jsx)(r7,{item:t,selected:d&&h===t.data.id,maximized:O===t.data.id,initialSleeping:C.has(t.data.id),tabId:r,projectCwd:e,expandedHeight:q,bubbleContentHeight:eE,onDragStart:ev,onDragOver:ej,onDragEnter:ew,onDragLeave:ek,onDrop:ey,onDragEnd:eN,onSelectId:f,onInterruptId:p,onStdin:g,onDeleteCommand:b,onRerun:v,subscribePtyOutput:H,subscribePtyReset:z,subscribePtyRefresh:W,ptySizeRef:j,resizePty:w,onToggleMaximizeId:eC,onTitleMouseDown:eg,onClosePlugin:N,addBrowserItem:eS,onSleep:S,onWake:M},t.data.id))}),(0,n.jsx)("div",{ref:el})]})}),!O&&m.length>0&&(0,n.jsx)(nf,{showTop:ee,showBottom:er,onScrollTop:ef,onScrollBottom:L}),(0,n.jsx)(nh,{cwd:e,currentCwd:E,commandHistoryRef:P,gridLayout:Q,onGridLayoutChange:t=>{J(t),u.t4.runFork((0,tU.Yn)({cwd:e,settings:{gridLayout:t}}).pipe(eb.sFT(e=>eb.OH5(()=>console.error("Failed to save project settings:",e))),eb.NWQ(()=>eb.rIH)))},onExecute:k,onAddPluginItem:y,onShowEnvManager:()=>Y(!0),onOpenShell:()=>k(nb),onOpenNote:l}),G&&(0,n.jsx)(nr,{cwd:e,tabId:r,onClose:()=>Y(!1),onSave:e=>$(e)}),Z&&(0,n.jsx)(ns,{onClose:()=>X(!1),onSave:e=>R(e)})]})});var ny=r(83897),nN=r(54271);function nC(e,t,r,n){return n&&r&&t.includes(e)}var nS=r(54356),nM=r(76412),nL=r(24058),nE=r(56058),nP=r(32880),n$=r(29899),nT=r(98307),nR=r(65153),nI=r(45720);function nF({cwd:e,sessionId:t,engine:r,onOpenProjectSessions:a,onOpenSessionBrowser:l,onOpenSettings:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(!1),m=t?(0,nI.X)(r,t):null;return(0,n.jsx)("div",{className:"border-b border-border px-4 py-3 bg-card",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6"}),(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"One seat. One AI. Everything under control."})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e&&(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help","data-tooltip":`CWD: ${e}`,children:e}),!e&&t&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Session: ",t.slice(0,8),"..."]}),e&&(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.browseAllSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),m&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(m).then(()=>{u(!0),setTimeout(()=>u(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-11 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:c?d("chat.copiedCommandTooltip"):d("chat.copyCommandTooltip",{command:m}),children:c?(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})})}),(0,n.jsx)("button",{onClick:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("settings.title"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]})]})})}function nB({tokenUsage:e,rateLimitInfo:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(()=>Date.now());(0,s.useEffect)(()=>{if(!t?.resetsAt)return;let e=setInterval(()=>l(Date.now()),3e4);return()=>clearInterval(e)},[t?.resetsAt]);let i=t?.status==="rejected"?"text-red-11":t?.status==="allowed_warning"?"text-amber-11":"text-muted-foreground",d=t?.status==="rejected"?r("chat.rateLimitRejected","Rate Limited"):t?.status==="allowed_warning"?r("chat.rateLimitWarning","Approaching Limit"):null,c=e=>{if(!e)return"";let t=(e<1e12?1e3*e:e)-a;if(t<=0)return"";let r=Math.ceil(t/6e4);if(r<60)return`${r}m`;let n=Math.floor(r/60),s=r%60;return s>0?`${n}h${s}m`:`${n}h`},u=e=>e?e.replace(/_/g," "):"";return(0,n.jsx)("div",{className:"px-4 py-1.5 border-t border-border ",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[t&&d&&(0,n.jsxs)("span",{className:`flex items-center gap-1 ${i}`,"data-tooltip":[t.rateLimitType&&`Type: ${u(t.rateLimitType)}`,null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&`Resets in: ${c(t.resetsAt)}`,t.isUsingOverage&&"Using overage"].filter(Boolean).join(" \xb7 "),children:["rejected"===t.status?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:[(0,n.jsx)("strong",{children:d}),null!=t.utilization&&` ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&` \xb7 ${c(t.resetsAt)}`]})]}),t&&!d&&t.resetsAt&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5","data-tooltip":[t.rateLimitType&&u(t.rateLimitType),null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,`Resets in: ${c(t.resetsAt)}`].filter(Boolean).join(" \xb7 "),children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),null!=t.utilization?(0,n.jsxs)("span",{children:[(100*t.utilization).toFixed(0),"%"]}):(0,n.jsx)("span",{children:c(t.resetsAt)})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsxs)("span",{children:[r("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens).toLocaleString()})]})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),(0,n.jsxs)("span",{children:[r("chat.output"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:e.outputTokens.toLocaleString()})]})]}),(e.cacheReadInputTokens>0||e.cacheCreationInputTokens>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-brand",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})}),(0,n.jsxs)("span",{children:["Cache: ",(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens)*100).toFixed(0),"%"]})]}),e.totalCostUsd>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-green-11",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:["$",e.totalCostUsd.toFixed(4)]})]})]})})}function nD({isOpen:e,onClose:t,cwd:r,sessionId:a,onSelectMessage:l}){let{t:d}=(0,o.Bd)(),[c,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(""),[v,j]=(0,s.useState)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(null);(0,H.E)(t,e),(0,s.useEffect)(()=>{if(!e){x(null),f(!1),g(""),j(null);return}if(!r||!a)return void x([]);let t=!1;return u.t4.runPromiseExit((0,m.nM)(r,a)).then(e=>{t||("Success"===e._tag?x(e.value.messages):(console.error("Failed to load user message index:",e.cause),f(!0),x([])))}),()=>{t=!0}},[e,r,a]);let y=(0,s.useMemo)(()=>{if(!c)return[];let e=c.map((e,t)=>({entry:e,ordinal:t+1})),t=p.trim().toLowerCase();return t?e.filter(e=>e.entry.content.toLowerCase().includes(t)):e},[c,p]),N=p.trim().length>0;(0,s.useEffect)(()=>{if(!e||N||!c)return;let t=w.current;t&&(t.scrollTop=t.scrollHeight)},[e,N,c]);let C=(0,s.useCallback)(async e=>{j(e.id);try{await l(e)}finally{j(null)}t()},[l,t]);if(!e)return null;let S=null===c,M=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:i.iG,onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:d("userMessages.title")}),c&&c.length>0&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:d("userMessages.count",{shown:y.length,total:c.length})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:k,type:"text",autoFocus:!0,placeholder:d("userMessages.searchPlaceholder"),value:p,onChange:e=>g(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),p&&(0,n.jsx)("button",{onClick:()=>{g(""),k.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:d("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{ref:w,className:"flex-1 overflow-y-auto",children:S?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("common.loading")}):h?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("userMessages.loadFailed")}):0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noMessages")}):0===y.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noResults")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:y.map(({entry:e,ordinal:t})=>{let r,s=e.timestamp?function(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let r=new Date;return t.toDateString()===r.toDateString()?t.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}(e.timestamp):"";return(0,n.jsx)("button",{onClick:()=>{C(e)},className:"w-full px-4 py-3 text-left hover:bg-hover transition-colors","data-tooltip":(r=e.content.trim()).length>500?`${r.slice(0,500)}…`:r,children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[t,"."]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-sm text-foreground truncate",children:e.content.replace(/\s+/g," ").trim()}),v===e.id&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:d("userMessages.jumping")})]}),s&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:s})]})},e.id)})})})]})});return(0,n.jsx)(b.ZL,{children:M})}var nA=r(67589),nH=r(20917),nz=r(74086),nW=r(201),nO=r(94290),n_=r(80860),nq=r(36351);function nV({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=async t=>{t.stopPropagation();try{var n;if(!navigator.clipboard?.write||"u"<typeof ClipboardItem)throw Error("Clipboard image write is unavailable");let t=await (n=e.preview,new Promise((e,t)=>{let r=new Image;r.onload=()=>{let n=document.createElement("canvas");n.width=r.naturalWidth,n.height=r.naturalHeight;let s=n.getContext("2d");s?(s.drawImage(r,0,0),n.toBlob(r=>{r?e(r):t(Error("Could not encode image"))},"image/png")):t(Error("Canvas is unavailable"))},r.onerror=()=>t(Error("Could not load image")),r.src=n}));await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),(0,T.oR)(r("imagePreview.copiedImage"),"success")}catch{(0,T.oR)(r("common.copyFailed"),"error")}},a=(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,n.jsxs)("div",{className:"absolute top-4 right-4 flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",title:r("imagePreview.copyImage"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V5a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2M7 7h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2Z"})})}),(0,n.jsx)("button",{type:"button",onClick:t,className:"w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,n.jsx)(b.ZL,{children:a})}function nU({images:e,onRemove:t,disabled:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(null);return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 p-2 border-b border-border",children:e.map(e=>(0,n.jsxs)("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-border cursor-pointer",onClick:()=>i(e),children:[(0,n.jsx)("img",{src:e.preview,alt:a("imagePreview.previewImage"),className:"w-full h-full object-cover hover:opacity-90 transition-opacity"}),(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),t(e.id)},className:"absolute top-0 right-0 w-5 h-5 bg-black/60 hover:bg-black/80 text-white text-xs flex items-center justify-center rounded-bl-lg opacity-0 group-hover:opacity-100 transition-opacity",title:a("imagePreview.deleteImage"),children:"✕"})]},e.id))}),l&&(0,n.jsx)(nV,{image:l,onClose:()=>i(null)})]})}var nK=r(93777),nQ=r(38798),nJ=r(94514),nG=r(59883),nY=r(56204),nZ=r(49387),nX=r(21362),n0=r(63393);let n1=()=>Math.random().toString(36).slice(2,10),n2=e=>e.replace(/\\n/g,"\n");function n5(e){let t=[],r=null;for(let[n,s]of e.split(/\r?\n/).entries()){if(!s.trim())continue;let e=s.match(/^\s*-(?:\s+(.*))?$/);if(e){let t=(e[1]??"").trim();if(!r)return{ok:!1,line:n+1};r.isGroup=!0,t&&r.children.push(n2(t));continue}if(/^\s/.test(s))return{ok:!1,line:n+1};let o=s.trim();o&&(r={text:n2(o),children:[],isGroup:!1},t.push(r))}return{ok:!0,nodes:t.map(e=>e.isGroup?{id:n1(),name:e.text,items:e.children.map(e=>({id:n1(),text:e}))}:{id:n1(),text:e.text})}}function n4({title:e,nodes:t,onSave:r,onClose:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(()=>t.flatMap(e=>(0,m._9)(e)?[e.name.replace(/\n/g,"\\n"),...e.items.length>0?e.items.map(e=>`- ${e.text.replace(/\n/g,"\\n")}`):["- "]]:[e.text.replace(/\n/g,"\\n")]).join("\n")),[c,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(!1),f=n5(i);(0,H.E)(a);let p=(0,s.useCallback)(async()=>{let e=n5(i);!e.ok||c||((u(!0),h(!1),await r(e.nodes))?a():(u(!1),h(!0)))},[a,r,c,i]);return(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{"data-quick-instruction-layer":"",className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":e,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:e}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:l("chat.quickInstructionsMarkdownHint")})]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":l("common.cancel"),children:(0,n.jsx)(ei.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,wrap:"off",value:i,onChange:e=>d(e.target.value),placeholder:l("chat.quickInstructionsMarkdownPlaceholder"),rows:24,spellCheck:!1,className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y overflow-x-auto whitespace-pre px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:f.ok?x?l("chat.saveQuickInstructionsFailed"):"":l("chat.quickInstructionsMarkdownError",{line:f.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:l("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!f.ok||c,onClick:p,className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:l(c?"chat.savingQuickInstructions":"common.save")})]})]})]})})})}let n3="data-quick-instruction-layer",n6=()=>Math.random().toString(36).slice(2,10);function n8({groups:e,value:t,onChange:r,onSubmit:a,onCancel:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[x,h]=(0,s.useState)(0),f=(0,s.useRef)(null),g=(0,s.useRef)(null),b=[null,...e.map(e=>e.id)],v=null===t?i("chat.instructionGroupNone"):e.find(e=>e.id===t)?.name??i("chat.instructionGroupNone"),j=(0,s.useCallback)(()=>{let r=f.current?.getBoundingClientRect();r&&(m(((e,t,r)=>{let n=Math.min(e.width,r.width-16),s=Math.min(Math.max(8,e.left),Math.max(8,r.width-n-8)),o=r.height-e.bottom-2-8,a=e.top-2-8,l=28*t+8;if(o>=Math.min(l,96)||o>=a)return{left:s,top:e.bottom+2,width:n,maxHeight:Math.max(28,Math.min(l,o))};let i=Math.max(28,Math.min(l,a));return{left:s,top:e.top-2-i,width:n,maxHeight:i}})(r,e.length+1,{width:window.innerWidth,height:window.innerHeight})),h(Math.max(0,b.indexOf(t))),c(!0))},[e.length,b,t]),w=(0,s.useCallback)(()=>{c(!1),m(null),f.current?.focus()},[]),k=(0,s.useCallback)(e=>{r(e),w()},[r,w]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;g.current?.contains(t)||f.current?.contains(t)||(c(!1),m(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]),(0,s.useEffect)(()=>{if(!d)return;let e=()=>{c(!1),m(null)};return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[d]);let y=(0,s.useCallback)(e=>{d?"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),w()):"ArrowDown"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.min(b.length-1,e+1))):"ArrowUp"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.max(0,e-1))):"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),k(b[x]??null)):"ArrowDown"===e.key||" "===e.key?(e.preventDefault(),e.stopPropagation(),j()):"Enter"===e.key?(e.preventDefault(),e.stopPropagation(),a()):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l())},[d,j,w,k,b,x,a,l]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:f,type:"button",onClick:()=>d?w():j(),onKeyDown:y,className:"w-[140px] min-w-0 flex-shrink-0 px-2 py-1 flex items-center gap-1 text-xs rounded border border-input bg-background hover:bg-hover focus:outline-none focus:ring-1 focus:ring-ring transition-colors",title:i("chat.instructionGroupLabel"),children:[(0,n.jsx)(nQ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-left ${null===t?"text-muted-foreground":""}`,children:v}),(0,n.jsx)(tO.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"})]}),d&&u&&(0,p.createPortal)((0,n.jsx)("div",{ref:g,[n3]:"",role:"listbox",style:{left:u.left,top:u.top,width:u.width,maxHeight:u.maxHeight},className:"fixed z-[60] py-1 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:b.map((r,s)=>{let o=r===t;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":o,onClick:()=>k(r),onMouseEnter:()=>h(s),className:`w-full min-w-0 px-2 py-1 flex items-center gap-1.5 text-xs text-left transition-colors ${s===x?"bg-hover":""}`,children:[(0,n.jsx)(nJ.A,{className:`w-3 h-3 flex-shrink-0 ${o?"text-brand":"opacity-0"}`}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate ${null===r?"text-muted-foreground":""}`,children:null===r?i("chat.instructionGroupNone"):e.find(e=>e.id===r)?.name})]},r??"__none__")})}),document.body)]})}function n9({initialValue:e,placeholder:t,groupChoices:r,initialGroupId:o,onCommit:a,onCancel:l}){let[i,d]=(0,s.useState)(e),[c,u]=(0,s.useState)(o??null),m=(0,s.useCallback)(()=>{let e=i.trim();e&&a(e,c)},[i,c,a]),x=(0,s.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing?"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l()):(e.preventDefault(),e.stopPropagation(),m())},[m,l]);return(0,n.jsxs)("div",{className:"mb-1 flex items-center gap-1",children:[(0,n.jsx)("input",{type:"text",value:i,onChange:e=>d(e.target.value),onKeyDown:x,placeholder:t,autoFocus:!0,className:"flex-1 min-w-0 px-2 py-1 text-xs rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring"}),r&&r.length>0&&(0,n.jsx)(n8,{groups:r,value:c,onChange:u,onSubmit:m,onCancel:l})]})}let n7=(e,t)=>`flex items-center group min-w-0 rounded transition-opacity ${e?"opacity-50":""} ${t?"border-t-2 border-brand":""}`,se="p-1 text-muted-foreground hover:text-foreground rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",st=(0,s.memo)(function({item:e,isDragging:t,isDragOver:r,onSelect:s,onInsert:a,onEdit:l,onDelete:i,onDragStart:d,onDragOver:c,onDrop:u,onDragEnd:m,management:x=!0}){let{t:h}=(0,o.Bd)();return(0,n.jsxs)("div",{draggable:x,onDragStart:x?()=>d(e.id):void 0,onDragOver:x?t=>c(t,e.id):void 0,onDrop:x?()=>u(e.id):void 0,onDragEnd:x?m:void 0,className:n7(t,r),children:[x&&(0,n.jsx)(nG.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsx)($.m,{content:e.text,children:(0,n.jsxs)("button",{type:"button",onClick:()=>s(e.text),className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",children:[(0,n.jsx)(nY.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:e.text})]})}),(0,n.jsx)("button",{type:"button",onClick:()=>a(e.text),className:se,title:h("chat.insertQuickInstruction"),children:(0,n.jsx)(nq.A,{className:"w-3 h-3"})}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>l(e.id),className:se,title:h("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(e.id),className:`${se} hover:text-destructive`,title:h("common.delete"),children:(0,n.jsx)(ei.A,{className:"w-3 h-3"})})]})]})}),sr=(0,s.memo)(function({group:e,isOpen:t,isDragging:r,isDragOver:a,isDragActive:l,onHoverOpen:i,onHoverClose:d,onToggle:c,onRename:u,onDelete:m,onDragStart:x,onDragOver:h,onDrop:f,onDragEnd:p,management:g=!0}){let{t:b}=(0,o.Bd)(),v=(0,s.useRef)(null),j=(0,s.useCallback)(()=>v.current?.getBoundingClientRect(),[]);return(0,n.jsxs)("div",{ref:v,draggable:g,onDragStart:g?()=>x(e.id):void 0,onDragOver:g?t=>h(t,e.id):void 0,onDrop:g?()=>f(e.id):void 0,onDragEnd:g?p:void 0,onMouseEnter:()=>{if(l)return;let t=j();t&&i(e.id,t)},onMouseLeave:()=>{l||d()},className:`${n7(r,a)} ${t?"bg-hover":""}`,children:[g&&(0,n.jsx)(nG.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{let t=j();t&&c(e.id,t)},className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",title:e.name,children:[(0,n.jsx)(nQ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.name}),(0,n.jsxs)("span",{className:"ml-auto flex items-center gap-1 flex-shrink-0 text-[10px] text-muted-foreground",children:[e.items.length>0&&e.items.length,(0,n.jsx)(nX.A,{className:"w-3 h-3"})]})]}),g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>u(e.id),className:se,title:b("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>m(e.id),className:`${se} hover:text-destructive`,title:b("common.delete"),children:(0,n.jsx)(ei.A,{className:"w-3 h-3"})})]})]})});function sn({group:e,position:t,groupChoices:r,editId:s,isAdding:a,isDragActive:l,dragId:i,dragOverId:d,onMouseEnter:c,onMouseLeave:u,onSelect:m,onInsert:x,onStartEdit:h,onCommitEdit:f,onCancelEdit:g,onDelete:b,onStartAdd:v,onCommitAdd:j,onCancelAdd:w,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S=!0}){let{t:M}=(0,o.Bd)();return(0,p.createPortal)((0,n.jsxs)("div",{[n3]:"",onMouseEnter:c,onMouseLeave:()=>{l||u()},style:{left:t.left,top:t.top,width:t.width,maxHeight:t.maxHeight},className:"fixed z-50 p-2 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1 truncate",children:e.name}),S&&(0,n.jsx)("button",{type:"button",onClick:v,className:"p-0.5 text-muted-foreground hover:text-foreground rounded flex-shrink-0",title:M("chat.addQuickInstruction"),children:(0,n.jsx)(nt.A,{className:"w-3.5 h-3.5"})})]}),S&&a&&(0,n.jsx)(n9,{initialValue:"",placeholder:M("chat.quickInstructionPlaceholder"),onCommit:e=>j(e),onCancel:w}),0===e.items.length&&!a&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:M("chat.noQuickInstructions")}),e.items.map(t=>s===t.id?(0,n.jsx)(n9,{initialValue:t.text,placeholder:M("chat.quickInstructionPlaceholder"),groupChoices:r,initialGroupId:e.id,onCommit:(e,r)=>f(t.id,e,r),onCancel:g},`edit-${t.id}`):(0,n.jsx)(st,{item:t,isDragging:i===t.id,isDragOver:d===t.id&&i!==t.id,onSelect:m,onInsert:x,onEdit:h,onDelete:b,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S},t.id))]}),document.body)}function ss({label:e,nodes:t,scope:r,openGroupId:a,flyoutPosition:l,onOpenFlyout:i,onCloseFlyout:d,onKeepFlyout:c,onSave:u,onSelect:x,onInsert:h,management:f=!0,onManage:p}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)(null),L=t.filter(m._9),E=a?L.find(e=>e.id===a)??null:null,P=(0,s.useRef)(t);P.current=t;let $=(0,s.useRef)(a);$.current=a;let R=(0,s.useRef)(null);(0,s.useEffect)(()=>{w(!1)},[a]);let I=(0,s.useCallback)(e=>{y(null),u(r,e)},[u,r]),F=(0,s.useCallback)(e=>{v(null),I([...P.current,{id:n6(),text:e}])},[I]),B=(0,s.useCallback)(e=>{v(null),I([...P.current,{id:n6(),name:e,items:[]}])},[I]),D=(0,s.useCallback)((e,t,r,n)=>{let s=P.current,o={id:e,text:t};if(r===n)return void I(s.map(t=>(0,m._9)(t)?t.id===n?{...t,items:t.items.map(t=>t.id===e?o:t)}:t:null===n&&t.id===e?o:t));let a=null===r?s.filter(t=>(0,m._9)(t)||t.id!==e):s.map(t=>(0,m._9)(t)&&t.id===r?{...t,items:t.items.filter(t=>t.id!==e)}:t);I(null===n?[...a,o]:a.map(e=>(0,m._9)(e)&&e.id===n?{...e,items:[...e.items,o]}:e))},[I]),A=(0,s.useCallback)((e,t)=>{I(P.current.map(r=>(0,m._9)(r)&&r.id===e?{...r,name:t}:r))},[I]),H=(0,s.useCallback)(async e=>{let t=P.current.find(t=>t.id===e);if(t&&(0,m._9)(t)&&t.items.length>0){if(!await (0,T.lJ)(g("chat.deleteInstructionGroupConfirm",{name:t.name,count:t.items.length}),{danger:!0,confirmText:g("common.delete")}))return;d()}y(null),I(P.current.filter(t=>t.id!==e))},[I,g,d]),z=(0,s.useCallback)(e=>{let t=$.current;t&&I(P.current.map(r=>(0,m._9)(r)&&r.id===t?e(r):r))},[I]),W=(0,s.useCallback)(e=>{w(!1),z(t=>({...t,items:[...t.items,{id:n6(),text:e}]}))},[z]),O=(0,s.useCallback)(e=>{y(null),z(t=>({...t,items:t.items.filter(t=>t.id!==e)}))},[z]),_=(0,s.useCallback)((e,t,r)=>{D(e,t,$.current,r)},[D]),q=(0,s.useCallback)(e=>{R.current=e,C(e)},[]),V=(0,s.useCallback)(()=>{q(null),M(null)},[q]),U=(0,s.useCallback)(e=>{q(e),d()},[q,d]),K=(0,s.useCallback)((e,t)=>{e.preventDefault(),M(t)},[]),Q=(e,t,r)=>{let n=e.findIndex(e=>e.id===t),s=e.findIndex(e=>e.id===r);if(n<0||s<0)return e;let o=[...e],[a]=o.splice(n,1);return o.splice(s,0,a),o},J=(0,s.useCallback)(e=>{let t=R.current;V(),t&&t!==e&&I(Q(P.current,t,e))},[I,V]),G=(0,s.useCallback)(e=>{let t=R.current;V(),t&&t!==e&&z(r=>({...r,items:Q(r.items,t,e)}))},[z,V]),Y=e=>{let t=P.current.find(t=>(0,m._9)(t)&&t.id===e);return t&&(0,m._9)(t)?t.items.length:0},Z=(0,s.useCallback)((e,t)=>{i(r,e,t,Y(e),!1)},[i,r]),X=(0,s.useCallback)((e,t)=>{$.current===e?d():i(r,e,t,Y(e),!0)},[i,d,r]);return(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1",children:e}),f?(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{y(null),v("group")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:g("chat.addInstructionGroup"),children:(0,n.jsx)(n0.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>{y(null),v("instruction")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:g("chat.addQuickInstruction"),children:(0,n.jsx)(nt.A,{className:"w-3.5 h-3.5"})})]}):p?(0,n.jsx)("button",{type:"button",onClick:p,className:"p-1 text-muted-foreground hover:text-brand rounded hover:bg-hover transition-colors",title:g("common.edit"),"aria-label":g("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3.5 h-3.5"})}):null]}),"instruction"===b&&(0,n.jsx)(n9,{initialValue:"",placeholder:g("chat.quickInstructionPlaceholder"),onCommit:e=>F(e),onCancel:()=>v(null)}),"group"===b&&(0,n.jsx)(n9,{initialValue:"",placeholder:g("chat.instructionGroupNamePlaceholder"),onCommit:e=>B(e),onCancel:()=>v(null)}),0===t.length&&!b&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:g("chat.noQuickInstructions")}),t.map(e=>k===e.id?(0,m._9)(e)?(0,n.jsx)(n9,{initialValue:e.name,placeholder:g("chat.instructionGroupNamePlaceholder"),onCommit:t=>A(e.id,t),onCancel:()=>y(null)},`edit-${e.id}`):(0,n.jsx)(n9,{initialValue:e.text,placeholder:g("chat.quickInstructionPlaceholder"),groupChoices:L,initialGroupId:null,onCommit:(t,r)=>D(e.id,t,null,r),onCancel:()=>y(null)},`edit-${e.id}`):(0,m._9)(e)?(0,n.jsx)(sr,{group:e,isOpen:a===e.id,isDragging:N===e.id,isDragOver:S===e.id&&N!==e.id,isDragActive:null!==N,onHoverOpen:Z,onHoverClose:d,onToggle:X,onRename:y,onDelete:H,onDragStart:U,onDragOver:K,onDrop:J,onDragEnd:V,management:f},e.id):(0,n.jsx)(st,{item:e,isDragging:N===e.id,isDragOver:S===e.id&&N!==e.id,onSelect:x,onInsert:h,onEdit:y,onDelete:H,onDragStart:U,onDragOver:K,onDrop:J,onDragEnd:V,management:f},e.id)),E&&l&&(0,n.jsx)(sn,{group:E,position:l,groupChoices:L,editId:k,isAdding:j,isDragActive:null!==N,dragId:N,dragOverId:S,onMouseEnter:c,onMouseLeave:d,onSelect:x,onInsert:h,onStartEdit:y,onCommitEdit:_,onCancelEdit:()=>y(null),onDelete:O,onStartAdd:()=>{y(null),w(!0)},onCommitAdd:W,onCancelAdd:()=>w(!1),onDragStart:q,onDragOver:K,onDrop:G,onDragEnd:V,management:f})]})}function so({cwd:e,anchorRef:t,onClose:r,onSelect:a,onInsert:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)([]),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(null),v=(0,s.useRef)(null),j=(0,s.useRef)(null),w=(0,s.useRef)(null),k=(0,s.useCallback)(()=>{j.current&&(clearTimeout(j.current),j.current=null),w.current&&(clearTimeout(w.current),w.current=null)},[]);(0,s.useEffect)(()=>k,[k]),(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([u.t4.runPromiseExit((0,m.ZQ)()),e?u.t4.runPromiseExit((0,m.$x)(e)):null]);!t&&("Success"===r._tag?c(r.value.instructions??[]):console.error("Failed to load global instructions:",r.cause),n&&"Success"===n._tag?h(n.value.instructions??[]):n&&console.error("Failed to load project instructions:",n.cause))})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{let n;if((n=e.target)instanceof Element&&null!==n.closest(`[${n3}]`))return;let s=t.current;s&&!s.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]),(0,s.useEffect)(()=>{if(!f)return;let e=()=>{k(),p(null)},t=t=>{let r=v.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)}},[f,k]);let y=(0,s.useCallback)((e,t,r,n,s)=>{k();let o=()=>{var s;let o,a,l,i,d,c,u;return p({scope:e,groupId:t,position:(a=(s={width:window.innerWidth,height:window.innerHeight}).width-r.right-4-8,l=r.left-4-8,i=288,a>=288?o=r.right+4:l>=288?o=r.left-4-288:a>=l?(i=Math.max(180,a),o=r.right+4):(i=Math.max(180,l),o=r.left-4-i),o=Math.min(Math.max(8,o),Math.max(8,s.width-i-8)),c=Math.min(d=Math.max(90,.6*s.height),30*n+40),(u=r.top-4)+c>s.height-8&&(u=s.height-8-c),{left:o,top:u=Math.max(8,u),width:i,maxHeight:d})})};s?o():j.current=setTimeout(o,150)},[k]),N=(0,s.useCallback)(()=>{k(),w.current=setTimeout(()=>p(null),300)},[k]),C=(0,s.useCallback)(()=>k(),[k]),S=(0,s.useCallback)(async(t,r)=>{let n="global"===t?c:h;n(r);let s=await u.t4.runPromiseExit((0,m.hZ)("global"===t?{scope:"global",instructions:r}:{cwd:e,instructions:r}));return"Failure"===s._tag?(console.error(`Failed to save ${t} instructions:`,s.cause),!1):(s.value?.instructions&&n(s.value.instructions),!0)},[e]),M=(0,s.useCallback)(e=>{r(),a(e)},[r,a]),L=(0,s.useCallback)(e=>{r(),l(e)},[r,l]),E=(0,s.useCallback)(async e=>!!g&&S(g,e),[g,S]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{ref:v,className:"absolute bottom-full left-0 mb-2 w-80 max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 max-h-[70vh] overflow-y-auto",children:[(0,n.jsx)(ss,{label:i("chat.globalInstructions"),nodes:d,scope:"global",openGroupId:f?.scope==="global"?f.groupId:null,flyoutPosition:f?.scope==="global"?f.position:null,onOpenFlyout:y,onCloseFlyout:N,onKeepFlyout:C,onSave:S,onSelect:M,onInsert:L,management:!1,onManage:()=>{k(),p(null),b("global")}}),e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(ss,{label:i("chat.projectInstructions"),nodes:x,scope:"project",openGroupId:f?.scope==="project"?f.groupId:null,flyoutPosition:f?.scope==="project"?f.position:null,onOpenFlyout:y,onCloseFlyout:N,onKeepFlyout:C,onSave:S,onSelect:M,onInsert:L,management:!1,onManage:()=>{k(),p(null),b("project")}})]})]}),g&&(0,n.jsx)(n4,{title:i("global"===g?"chat.editGlobalInstructions":"chat.editProjectInstructions"),nodes:"global"===g?d:x,onSave:E,onClose:()=>b(null)})]})}var sa=r(96625);let sl=(0,s.memo)(function({onSend:e,disabled:t,running:r,cwd:a,engine:l,onShowGitStatus:i,onShowComments:d,hasComments:c,onOpenNote:u,isFavorite:m,onToggleFavorite:x,onCreateScheduledTask:h,draft:f,setDraft:p,draftImages:g,setDraftImages:b,suggestion:v}){let{t:j}=(0,o.Bd)(),w=(0,s.useState)(""),k=(0,s.useState)([]),[y,N]=void 0!==f&&p?[f,p]:w,[C,S]=void 0!==g&&b?[g,b]:k,[M,L]=(0,s.useState)(!1),[E,P]=(0,s.useState)(!1),$=(0,s.useRef)(null),T=(0,s.useRef)(null),R=(0,s.useCallback)(()=>{let e=$.current;if(!e)return;e.style.height="auto";let t=Math.max(38,Math.min(e.scrollHeight,200));e.style.height=`${t}px`},[]);(0,s.useLayoutEffect)(()=>{R()},[y,R]);let I=(0,s.useMemo)(()=>l&&"claude"!==l?[]:[{name:"/plan",description:"Enable plan mode (read-only). /plan <task> to plan a task; /plan off to disable.",source:"builtin",argumentHint:"[task|off]"}],[l]),F=(0,sa.n)({value:y,onChange:N,textareaRef:$,extraCommands:I}),B=(0,s.useCallback)(()=>{let r=y.trim();(r||C.length>0)&&!t&&(e(r,C.length>0?C:void 0),N(""),S([]),$.current&&($.current.style.height="auto"))},[y,C,t,e]),D=(0,s.useCallback)(r=>{t||e(r)},[t,e]),A=(0,s.useCallback)(e=>{N(t=>{let r=t.replace(/\s+$/,"");return r?`${r}
33
33
  ${e}`:e}),requestAnimationFrame(()=>{let e=$.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))})},[]),H=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&!F.handleKeyDown(e)){if("Tab"===e.key&&!e.shiftKey&&v&&!y){e.preventDefault(),N(v);return}"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),B())}},[F,B,v,y,N]),z=(0,s.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let r=["image/png","image/jpeg","image/webp","image/gif"];for(let n of Array.from(t)){let t=r.find(e=>n.type===e);if(t){e.preventDefault();let r=n.getAsFile();if(!r)continue;if(r.size>5242880){alert(j("chat.imageSizeLimit",{size:(r.size/1024/1024).toFixed(2)}));continue}let s=new FileReader;s.onload=e=>{let r=e.target?.result;if(!r)return;let n=r.replace(/^data:image\/\w+;base64,/,""),s={id:`img-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,data:n,preview:r,media_type:t};S(e=>[...e,s])},s.readAsDataURL(r)}}},[j]),W=(0,s.useCallback)(e=>{S(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nU,{images:C,onRemove:W,disabled:t}),(0,n.jsx)(sa.V,{ac:F,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64"}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[i&&(0,n.jsx)("button",{onClick:i,className:"p-2 text-brand hover:text-teal-10 hover:bg-brand/10 active:bg-brand/20 active:scale-95 rounded-lg transition-all",title:j("chat.viewGitChanges"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 8v10M18 8v4c0 2-2 4-6 4"})]})}),d&&(0,n.jsx)("button",{onClick:d,className:`p-2 rounded-lg transition-all active:scale-95 ${c?"text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted"}`,title:j("chat.viewAllComments"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),u&&(0,n.jsx)("button",{onClick:u,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:j("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),x&&(0,n.jsx)("button",{onClick:x,className:`p-2 rounded-lg transition-all ${m?"text-amber-9 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95":"text-muted-foreground hover:text-amber-9 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95"}`,title:j(m?"sessions.removeFavorite":"sessions.addFavorite"),"aria-label":j(m?"sessions.removeFavorite":"sessions.addFavorite"),"aria-pressed":m,children:(0,n.jsx)(nO.A,{className:"w-5 h-5",fill:m?"currentColor":"none"})}),h&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>L(!M),className:`p-2 rounded-lg transition-all ${M?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:j("chat.scheduledTasks"),children:(0,n.jsx)(n_.A,{className:"w-5 h-5"})}),M&&(0,n.jsx)(nK.E,{onClose:()=>L(!1),onCreate:h})]}),(0,n.jsxs)("div",{className:"relative",ref:T,children:[(0,n.jsx)("button",{onClick:()=>P(!E),className:`p-2 rounded-lg transition-all ${E?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:j("chat.quickInstructions"),children:(0,n.jsx)(nq.A,{className:"w-5 h-5"})}),E&&(0,n.jsx)(so,{cwd:a,anchorRef:T,onClose:()=>P(!1),onSelect:D,onInsert:A})]}),(0,n.jsx)("textarea",{ref:$,value:y,onChange:e=>{N(e.target.value),F.trackCaret(e.target)},onSelect:e=>F.trackCaret(e.currentTarget),onKeyDown:H,onPaste:z,placeholder:t?j("chat.placeholderDisabled"):r?j("chat.placeholderRunning"):v||j("chat.placeholder"),rows:1,className:"flex-1 resize-none px-4 py-2 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-ring bg-card text-foreground"})]})]})});var si=r(57125);function sd(e){return"env"===e?"from env var":"default"===e?"default":null}function sc({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)([]),[i,d]=(0,s.useState)(!1),[c,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[y,N]=(0,s.useState)(""),[C,S]=(0,s.useState)("default"),[M,L]=(0,s.useState)(!1),[E,P]=(0,s.useState)(""),[$,T]=(0,s.useState)("default"),[R,I]=(0,s.useState)(""),[F,B]=(0,s.useState)(!1),D=(0,s.useRef)(null),A=(0,s.useRef)(null),H=(0,s.useRef)(null),[z,W]=(0,s.useState)({top:0,left:0}),O=(0,b.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{A.current&&!A.current.contains(e.target)&&D.current&&!D.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let _=(0,s.useCallback)(async()=>{d(!0),x(null);let e=await u.t4.runPromiseExit((0,m.qD)(()=>f(!0)));if(f(!1),"Failure"===e._tag)x("Connection error");else{let t=e.value;switch(t._tag){case"ok":l(t.models);break;case"not-installed":case"error":x(t.message);break;case"not-running":x("Ollama is not running")}}d(!1)},[]),q=(0,s.useCallback)(e=>{N(e.baseUrl),S(e.baseUrlSource),L(e.hasKey),P(e.maskedKey),T(e.keySource),I(""),B(!1)},[]),V=(0,s.useCallback)(async()=>{g(!0),k(null);let e=await u.t4.runPromiseExit((0,m.F4)());"Failure"===e._tag?k("Failed to load config"):q(e.value),g(!1)},[q]),U=async()=>{j(!0),k(null);let e=await u.t4.runPromiseExit((0,m.yS)({baseUrl:y}));"Failure"===e._tag?k("Save failed"):(q(e.value),await _()),j(!1)},K=async()=>{let e=R.trim();if(!e)return;j(!0),k(null);let t=await u.t4.runPromiseExit((0,m.yS)({apiKey:e}));"Failure"===t._tag?k("Save failed"):q(t.value),j(!1)},Q=async()=>{j(!0),k(null);let e=await u.t4.runPromiseExit((0,m.yS)({apiKey:""}));"Failure"===e._tag?k("Clear failed"):q(e.value),j(!1)},J=e?e.replace(/:latest$/,""):"Select model",G=sd(C),Y=sd($),Z=r?(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:A,className:`${si.ys} min-w-[300px]`,style:{top:z.top,left:z.left},children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Server URL"}),G&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:G})]}),p?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"text",value:y,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"===e.key&&U()},placeholder:"http://127.0.0.1:11434",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`}),(0,n.jsx)("button",{onClick:U,disabled:v,className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:v?"...":"Save"})]})]}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),Y&&M&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:Y})]}),p?null:M&&!F?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:E}),(0,n.jsx)("button",{onClick:()=>{B(!0),I(""),setTimeout(()=>H.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:v,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:v,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:H,type:"password",value:R,onChange:e=>I(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"optional — for authenticated servers",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`}),(0,n.jsx)("button",{onClick:K,disabled:v||!R.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:v?"...":"Save"}),M&&(0,n.jsx)("button",{onClick:()=>{B(!1),I("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),w&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:w})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),(0,n.jsx)("div",{className:"px-3 pt-1 pb-0.5",children:(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Model"})}),(0,n.jsx)("div",{className:"max-h-[240px] overflow-y-auto",children:i||h?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),h?"Starting Ollama...":"Loading models..."]}):c?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-11",children:c}):0===a.length?(0,n.jsxs)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:["No models found. Run ",(0,n.jsx)("code",{className:"bg-secondary px-1 rounded",children:"ollama pull <model>"})]}):a.map(r=>{var s;let a=r.name===e;return(0,n.jsxs)("button",{onClick:()=>{t(r.name),o(!1)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-xs transition-colors ${a?si.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(si.hG,{selected:a}),(0,n.jsx)("span",{className:"truncate",children:r.name.replace(/:latest$/,"")}),(0,n.jsx)("span",{className:"ml-auto pl-2 text-muted-foreground flex-shrink-0",children:r.parameter_size||((s=r.size)<1e9?`${(s/1e6).toFixed(0)}M`:`${(s/1e9).toFixed(1)}G`)})]},r.name)})})]})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(si.XY,{buttonRef:D,label:J,title:"Configure Ollama",onClick:()=>{if(!r){if(D.current){let e=D.current.getBoundingClientRect(),t=O?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;W({top:e.bottom+4-n,left:e.left-r})}V(),_()}o(e=>!e)},icon:(0,n.jsx)(si.eV,{engine:"ollama"}),testId:"ollama-config-picker"}),Z]})}let su={deepseek:{label:"DeepSeek",apiKeysUrl:"https://platform.deepseek.com/api_keys",modelsEndpoint:"/v1/models"},kimi:{label:"Kimi",apiKeysUrl:"https://www.kimi.com/code/console",modelsEndpoint:"/coding/v1/models"},glm:{label:"GLM",apiKeysUrl:"https://bigmodel.cn/apikey/platform",modelsEndpoint:"/coding/paas/v4/models",regions:[{id:"cn",label:"中国大陆",hint:"open.bigmodel.cn"},{id:"global",label:"International",hint:"api.z.ai"}]}};function sm({engine:e,currentModel:t,onModelChange:r,onHasKeyChange:o}){let a=su[e],[l,i]=(0,s.useState)(!1),[d,c]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(""),[g,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)([]),[P,$]=(0,s.useState)(null),[T,R]=(0,s.useState)(null),I=(0,s.useRef)(null),F=(0,s.useRef)(null),B=(0,s.useRef)(null),D=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{D.current&&clearTimeout(D.current)},[]);let A=(0,s.useRef)(t),H=(0,s.useRef)(r),z=(0,s.useRef)(o);(0,s.useEffect)(()=>{A.current=t,H.current=r,z.current=o}),(0,s.useEffect)(()=>{z.current?.(d)},[d]);let[W,O]=(0,s.useState)({top:0,left:0}),_=(0,b.F2)();(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([u.t4.runPromiseExit((0,m.Hw)(e)),u.t4.runPromiseExit((0,m.td)())]);if(t||"Failure"===r._tag)return;c(r.value.hasKey),h(r.value.maskedKey);let s="Success"===n._tag?n.value?.engines?.[e]:void 0,o=s?.builtinModel;!A.current&&o&&H.current(o)})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{if(!l)return;let e=e=>{F.current&&!F.current.contains(e.target)&&I.current&&!I.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l]);let q=(0,s.useCallback)(async()=>{w(!0),C(null),$(null);let[n,s]=await Promise.all([u.t4.runPromiseExit((0,m.Hw)(e)),u.t4.runPromiseExit((0,m.td)())]);if("Failure"===n._tag){C("Failed to load settings"),w(!1);return}c(n.value.hasKey),h(n.value.maskedKey),p(""),v(!1);let o="Success"===s._tag?s.value:void 0,l=o?.engines?.[e],i=l?.builtinModel;a.regions&&R(l?.region??("en"===o?.language?"global":"cn"));let d=[];if(n.value.hasKey){let t=await u.t4.runPromiseExit((0,m.Fi)(e));"Success"===t._tag?d=t.value.models:$("Failed to load models — check the API key")}E(d);let x=d.map(e=>e.id),f=i&&x.includes(i)?i:x[0];!f||t&&x.includes(t)||r(f),w(!1)},[e,t,r,a.regions]),V=(0,s.useCallback)(async t=>{let r=await u.t4.runPromiseExit((0,m.td)()),n=("Success"===r._tag?r.value:{}).engines||{},s={...n,[e]:{...n[e]||{},builtinModel:t}};if("Failure"===(await u.t4.runPromiseExit((0,m.em)({engines:s})))._tag)throw Error("Failed to save settings")},[e]),U=(0,s.useCallback)(async t=>{R(t);let r=await u.t4.runPromiseExit((0,m.td)()),n=("Success"===r._tag?r.value:{}).engines||{};"Failure"===(await u.t4.runPromiseExit((0,m.em)({engines:{...n,[e]:{...n[e]||{},region:t}}})))._tag?C("Failed to save region"):q()},[e,q]),K=async()=>{let t=f.trim();if(!t)return;y(!0),C(null);let r=await u.t4.runPromiseExit((0,m.dQ)(e,t));"Failure"===r._tag?C("Save failed"):(c(r.value.hasKey),h(r.value.maskedKey),p(""),v(!1),q()),y(!1)},Q=async()=>{y(!0),C(null);let t=await u.t4.runPromiseExit((0,m.dQ)(e,""));"Failure"===t._tag?C("Clear failed"):(c(t.value.hasKey),h(t.value.maskedKey),p(""),v(!1),E([])),y(!1)},J=async()=>{let t=await u.t4.runPromiseExit((0,m.Ny)(e));if("Failure"===t._tag||!t.value.apiKey)return void C("Copy failed");try{await navigator.clipboard.writeText(t.value.apiKey)}catch{C("Clipboard unavailable");return}C(null),M(!0),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>M(!1),1500)},G=async e=>{r(e);try{await V(e)}catch{}},Y=d?t||"Select model":"Set API key",Z=d?void 0:si.Aw,X=t||"",ee=l?(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{ref:F,className:`${si.ys} min-w-[280px]`,style:{top:W.top,left:W.left},children:j?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),(0,n.jsx)("a",{href:a.apiKeysUrl,target:"_blank",rel:"noopener","data-testid":`${e}-api-keys-link`,title:`Open ${a.label} API keys page`,"aria-label":`Open ${a.label} API keys page`,className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]}),d&&!g?(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:x}),(0,n.jsx)("button",{onClick:J,"data-testid":`${e}-copy-api-key`,title:S?"Copied":"Copy API key","aria-label":"Copy API key",className:`p-1 rounded transition-colors ${S?"text-green-11":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,disabled:k,children:S?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:()=>{v(!0),p(""),setTimeout(()=>B.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:k,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:k,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:B,type:"password",value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"sk-...",className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`,autoFocus:!0}),(0,n.jsx)("button",{onClick:K,disabled:k||!f.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:k?"Saving...":"Save"}),d&&(0,n.jsx)("button",{onClick:()=>{v(!1),p("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),N&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:N})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),a.regions&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Region"}),(0,n.jsx)("div",{className:"inline-flex rounded-md border border-border overflow-hidden text-xs",role:"group","data-testid":`${e}-region-toggle`,children:a.regions.map(t=>(0,n.jsx)("button",{type:"button","data-testid":`${e}-region-${t.id}`,onClick:()=>U(t.id),title:t.hint,className:`px-2 py-0.5 ${T===t.id?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-hover"}`,children:t.label},t.id))})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"})]}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Model"}),P&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-red-11",children:P}),!P&&0===L.length&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-muted-foreground",children:d?`No models returned by ${a.modelsEndpoint}`:"Save an API key to list models"}),(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:L.map(e=>{var t;let r=X===e.id,s=(t=e.contextTokens)&&!(t<=0)?t>=1048576?`${Math.round(t/1048576)}M`:`${Math.round(t/1024)}K`:null;return(0,n.jsxs)("button",{onClick:()=>G(e.id),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?si.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(si.hG,{selected:r}),(0,n.jsx)("span",{className:"truncate",children:e.id}),e.label&&e.label!==e.id&&(0,n.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:e.label}),s&&(0,n.jsx)("span",{className:"ml-auto pl-2 text-[10px] text-muted-foreground flex-shrink-0",children:s})]},e.id)})})]})]})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(si.XY,{buttonRef:I,label:Y,labelClassName:Z,title:`Configure ${a.label}`,onClick:()=>{if(!l){if(I.current){let e=I.current.getBoundingClientRect(),t=_?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;O({top:e.bottom+4-n,left:e.left-r})}q()}i(e=>!e)},icon:(0,n.jsx)(si.eV,{engine:e}),testId:`${e}-config-picker`}),ee]})}var sx=r(53317);let sh="claude-opus-5-5",sf="gpt-6.1-sol",sp=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultracode",label:"Ultracode"},{id:"ultrathink",label:"Ultrathink"}],sg=[{id:"claude-sonnet-5-5",label:"Claude Sonnet 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium"},{id:"claude-sonnet-5",label:"Claude Sonnet 5",effort:["low","medium","high","xhigh","max","ultrathink"],defaultEffort:"high"},{id:"claude-opus-5-5",label:"Claude Opus 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium",fast:!0},{id:"claude-opus-5",label:"Claude Opus 5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",fast:!0},{id:"claude-fable-5-1",label:"Claude Fable 5.1",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high"},{id:"claude-haiku-5-5",label:"Claude Haiku 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium"},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5",thinking:!0}],sb=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultra",label:"Ultra"}],sv=[{id:"gpt-6-astra",label:"GPT-6-Astra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"},{id:"gpt-6.1-sol",label:"GPT-6.1-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"},{id:"gpt-6-sol",label:"GPT-6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"medium"},{id:"gpt-6-luna",label:"GPT-6-Luna",reasoning:["low","medium","high","xhigh","max"],defaultReasoning:"medium"},{id:"gpt-5.6-sol",label:"GPT-5.6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"}];function sj(e){return sv.find(t=>t.id===e)?.defaultReasoning??"low"}function sw(e,t){let r=sv.find(t=>t.id===e)?.reasoning;return t&&(!r||r.includes(t))?t:sj(e)}function sk(e,t){return e.find(e=>e.id===t)?.label??t}function sy(e){return sg.find(t=>t.id===e)?.fast===!0}function sN(e){return sg.find(t=>t.id===e)?.thinking===!0}function sC(e){let t=sg.find(t=>t.id===e);return t?t.defaultEffort:"high"}function sS(e,t){let r=sg.find(t=>t.id===e),n=r?.effort;return t&&(!r||n?.includes(t))?t:sC(e)}function sM({value:e,selected:t,label:r,defaultValue:s,onSelect:o}){return(0,n.jsxs)("button",{type:"button",onClick:()=>o(e),className:`flex w-full items-start gap-2 px-3 py-2 text-left text-xs transition-colors ${t?si.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:t})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:r}),(0,n.jsx)("span",{className:"shrink-0",children:s&&(0,n.jsx)("span",{className:"rounded bg-muted px-1.5 text-[10px] font-medium text-muted-foreground",children:"Default"})})]})}function sL({title:e,selected:t,value:r,items:o,onSelect:a,icon:l,testId:i}){let d=(0,s.useRef)(null),c=(0,s.useRef)(null),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)({top:0,left:0}),f=(0,b.F2)(),p=()=>{let e=d.current?.getBoundingClientRect();if(!e)return;let t=f?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;h({top:e.bottom+4-n,left:e.left-r})};return(0,s.useEffect)(()=>{if(!u)return;let e=e=>{let t=e.target;c.current?.contains(t)||d.current?.contains(t)||m(!1)},t=()=>p();return document.addEventListener("mousedown",e),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[u]),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(si.XY,{buttonRef:d,label:r,labelMaxWidth:"max-w-[180px]",title:`${e}: ${r}`,onClick:()=>{u||p(),m(e=>!e)},icon:l,testId:i}),u&&(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:c,className:`${si.ys} min-w-[190px]`,style:{top:x.top,left:x.left},children:[(0,n.jsx)("div",{className:"px-3 pb-1 text-[11px] font-medium text-muted-foreground",children:e}),(0,n.jsx)("div",{className:"flex flex-col",children:o.map(e=>(0,n.jsx)(sM,{value:e.id,selected:t===e.id,label:e.label,defaultValue:e.defaultValue,onSelect:e=>{a(e),m(!1)}},e.id))})]})})]})}function sE(e){let t,r,s,o=e.engine??"claude",a=e.claudeModel??sh,l=sC(a),i=(t=sg.find(e=>e.id===a)?.effort)?t.map(e=>sp.find(t=>t.id===e)??{id:e,label:e}):[],d=sS(a,e.claudeEffort),c=e.claudeFastMode??!1,u=e.claudeThinking??!1,m=e.codexModel??sf,x=sj(m),h=(r=sv.find(e=>e.id===m)?.reasoning)?r.map(e=>sb.find(t=>t.id===e)??{id:e,label:e}):sb,f=sw(m,e.codexReasoningEffort);return"claude"!==o?(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sL,{title:"Model",selected:m,value:sv.find(e=>e.id===m)?.label??(0,sx.U)(m),items:sv.map(e=>({id:e.id,label:e.label,defaultValue:e.id===sf})),onSelect:t=>{e.onCodexModelChange?.(t),e.onCodexReasoningEffortChange?.(sj(t))},icon:(0,n.jsx)(si.eV,{engine:"codex"}),testId:"codex-model-picker"}),(0,n.jsx)(sL,{title:"Reasoning",selected:f,value:sk(sb,f),items:h.map(e=>({...e,defaultValue:e.id===x})),onSelect:t=>e.onCodexReasoningEffortChange?.(t),testId:"codex-reasoning-picker"})]}):(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sL,{title:"Model",selected:a,value:(s=sg.find(e=>e.id===a))?s.label:a.startsWith("claude-")?`Claude ${(0,sx.J)(a)}`:a,items:sg.map(e=>({id:e.id,label:e.label,defaultValue:e.id===sh})),onSelect:t=>{e.onClaudeModelChange?.(t);let r=sC(t);r&&e.onClaudeEffortChange?.(r),sy(t)||e.onClaudeFastModeChange?.(!1),sN(t)||e.onClaudeThinkingChange?.(!1)},icon:(0,n.jsx)(si.eV,{engine:"claude"}),testId:"claude-model-picker"}),d&&i.length>0&&(0,n.jsx)(sL,{title:"Reasoning",selected:d,value:sk(sp,d),items:i.map(e=>({...e,defaultValue:e.id===l})),onSelect:t=>e.onClaudeEffortChange?.(t),testId:"claude-reasoning-picker"}),sy(a)&&(0,n.jsx)(sL,{title:"Fast Mode",selected:c?"on":"off",value:c?"Fast On":"Fast Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeFastModeChange?.("on"===t),testId:"claude-fast-mode-picker"}),sN(a)&&(0,n.jsx)(sL,{title:"Thinking",selected:u?"on":"off",value:u?"Thinking On":"Thinking Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeThinkingChange?.("on"===t),testId:"claude-thinking-picker"})]})}var sP=r(6489);let s$=/^#\s+(.*)$/;function sT(e,t=[]){let r=new Map(t.map(e=>[e.name,e.id])),n=[];for(let[t,r]of e.split(/\r?\n/).entries()){let e=r.match(s$);if(e){n.push({name:e[1].trim(),line:t+1,body:[]});continue}let s=n[n.length-1];if(!s){if(r.trim())return{ok:!1,line:t+1,reason:"content-before-heading"};continue}s.body.push(r)}let s=new Set,o=[];for(let e of n){let t=e.body.join("\n").trim();if(!e.name||!t)return{ok:!1,line:e.line,reason:"empty-style"};if(s.has(e.name))return{ok:!1,line:e.line,reason:"duplicate-name"};s.add(e.name),o.push({id:r.get(e.name)??"",name:e.name,content:t})}return{ok:!0,styles:o}}function sR({styles:e,onSave:t,onClose:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(()=>e.map(e=>`# ${e.name}
34
34
  ${e.content}`).join("\n\n")),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),x=sT(l,e);(0,H.E)(r);let h=(0,s.useCallback)(async()=>{let n=sT(l,e);if(n.ok&&!d){if(c(!0),m(!1),await t(n.styles))return void r();c(!1),m(!0)}},[r,t,d,e,l]),f=a("chat.editOutputStyles");return(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&r()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":f,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:f}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:a("chat.outputStylesMarkdownHint")})]}),(0,n.jsx)("button",{type:"button",onClick:r,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":a("common.cancel"),children:(0,n.jsx)(ei.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,value:l,onChange:e=>i(e.target.value),placeholder:a("chat.outputStylesMarkdownPlaceholder"),rows:24,spellCheck:!1,"data-testid":"output-styles-editor",className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:x.ok?u?a("chat.saveQuickInstructionsFailed"):"":a(`chat.outputStylesError.${x.reason}`,{line:x.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:r,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:a("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!x.ok||d,onClick:h,"data-testid":"output-styles-save",className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:a(d?"chat.savingQuickInstructions":"common.save")})]})]})]})})})}let sI=[],sF=sI,sB=!1,sD=null,sA=new Set,sH=e=>{sF=e,sA.forEach(e=>e())};function sz(e=!1){return sB&&!e?Promise.resolve():sD||(sD=(async()=>{let e=await u.t4.runPromiseExit((0,m.K4)());(sD=null,"Failure"===e._tag)?console.error("Failed to load output styles:",e.cause):(sB=!0,sH(e.value.styles??sI))})())}async function sW(e){let t=await u.t4.runPromiseExit((0,m.DF)(e));return"Failure"===t._tag?(console.error("Failed to save output styles:",t.cause),!1):(sB=!0,sH(t.value.styles??sI),!0)}let sO=e=>(sA.add(e),()=>{sA.delete(e)}),s_=()=>sF;function sq({value:e,onChange:t}){let{t:r}=(0,o.Bd)(),a=((0,s.useEffect)(()=>{sz()},[]),(0,s.useSyncExternalStore)(sO,s_,()=>sI)),l=(0,s.useRef)(null),i=(0,s.useRef)(null),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)({top:0,left:0}),f=(0,b.F2)(),p=a.find(t=>t.id===e),g=r("chat.outputStyleNone"),v=p?.name??g,j=(0,s.useCallback)(()=>{let e=l.current?.getBoundingClientRect();if(!e)return;let t=f?.getBoundingClientRect();h({top:e.bottom+4-(t?.top??0),left:e.left-(t?.left??0)})},[f]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;i.current?.contains(t)||l.current?.contains(t)||c(!1)};return document.addEventListener("mousedown",e),window.addEventListener("resize",j),window.addEventListener("scroll",j,!0),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("resize",j),window.removeEventListener("scroll",j,!0)}},[d,j]);let w=e=>{t(e),c(!1)},k=e=>`flex w-full items-start gap-2 px-3 py-2 text-left text-xs transition-colors ${e?si.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`;return(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(si.XY,{buttonRef:l,label:v,labelMaxWidth:"max-w-[140px]",title:`${r("chat.outputStyle")}: ${v}`,onClick:()=>{d||(j(),sz(!0)),c(e=>!e)},icon:(0,n.jsx)(sP.A,{className:`h-3.5 w-3.5 flex-shrink-0 ${p?"text-brand":""}`}),testId:"output-style-picker"}),d&&(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:i,className:`${si.ys} min-w-[200px] max-w-[320px]`,style:{top:x.top,left:x.left},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 pb-1",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:r("chat.outputStyle")}),(0,n.jsx)("button",{type:"button",onClick:()=>{c(!1),m(!0)},className:"p-1 text-muted-foreground hover:text-foreground rounded hover:bg-hover",title:r("chat.editOutputStyles"),"data-testid":"output-style-edit",children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})})]}),(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>w(""),className:k(!p),children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:!p})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:g})]}),a.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>w(e.id),className:k(p?.id===e.id),title:e.content,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:p?.id===e.id})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.name})]},e.id)),0===a.length&&(0,n.jsx)("div",{className:"px-3 py-2 text-[11px] text-muted-foreground",children:r("chat.noOutputStyles")})]})]})}),u&&(0,n.jsx)(sR,{styles:a,onSave:sW,onClose:()=>m(!1)})]})}let sV={CNY:"\xa5",USD:"$"};function sU({hasKey:e}){let{t}=(0,o.Bd)(),[r,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[d,c]=(0,s.useState)(null),x=(0,s.useCallback)(async()=>{a(!0),c(null);let e=await u.t4.runPromiseExit((0,m.he)());"Failure"===e._tag?(i(null),c(t("chat.balanceFailed",{defaultValue:"Query failed — check the API key"}))):i(e.value),a(!1)},[t]),h=l?l.balances.map(e=>`${sV[e.currency]??(e.currency?`${e.currency} `:"")}${e.totalBalance}`).join(" / "):"",f=!!(l&&!l.isAvailable);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[r&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!r&&d&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:d}),!r&&!d&&l&&(0,n.jsx)("span",{className:`text-xs font-mono ${f?"text-red-11":si.pe.deepseek}`,"data-tooltip":f?t("chat.balanceUnavailable",{defaultValue:"Account is not available for requests"}):void 0,"data-testid":"deepseek-balance-value",children:h||t("chat.balanceEmpty",{defaultValue:"No balance returned"})}),(0,n.jsx)("button",{type:"button","data-testid":"deepseek-balance-button",disabled:!e||r,onClick:x,"data-tooltip":e?void 0:t("chat.balanceNeedsKey",{defaultValue:"Set a DeepSeek API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:t("chat.checkBalance",{defaultValue:"Check balance"})}),(0,n.jsx)("a",{href:"https://platform.deepseek.com/usage",target:"_blank",rel:"noopener","data-testid":"deepseek-usage-link",title:t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),"aria-label":t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}let sK={kimi:"https://www.kimi.com/code/console",glm:"https://bigmodel.cn/coding-plan/personal/usage"};function sQ(e){let t=e.remaining??"?",r=e.limit??"?";return`${e.label} ${t}/${r}`}function sJ({engine:e,hasKey:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(!1),[i,d]=(0,s.useState)(null),[c,x]=(0,s.useState)(null),h=(0,s.useCallback)(async()=>{l(!0),x(null);let t=await u.t4.runPromiseExit((0,m.dM)(e));"Failure"===t._tag?(d(null),x(r("chat.quotaFailed",{defaultValue:"Quota unavailable — check the API key"}))):d(t.value),l(!1)},[r,e]),f=i?.windows??[],p=[i?.tier,...f.map(sQ)].filter(Boolean).join(" \xb7 "),g=function(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:`${t.getMonth()+1}/${t.getDate()} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}(f.reduce((e,t)=>t.resetTime&&(!e||t.resetTime>e)?t.resetTime:e,null)),b=f.some(e=>0===e.remaining);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[a&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!a&&c&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:c}),!a&&!c&&i&&(0,n.jsx)("span",{className:`text-xs font-mono ${b?"text-red-11":si.pe[e]}`,"data-tooltip":g?r("chat.quotaResetAt",{defaultValue:"Resets {{time}}",time:g}):void 0,"data-testid":`${e}-quota-value`,children:p||r("chat.quotaEmpty",{defaultValue:"No quota returned"})}),(0,n.jsx)("button",{type:"button","data-testid":`${e}-quota-button`,disabled:!t||a,onClick:h,"data-tooltip":t?void 0:r("chat.quotaNeedsKey",{defaultValue:"Set an API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:r("chat.checkQuota",{defaultValue:"Check quota"})}),(0,n.jsx)("a",{href:sK[e],target:"_blank",rel:"noopener","data-testid":`${e}-console-link`,title:r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),"aria-label":r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}var sG=r(67889),sY=r(46456);function sZ(e){if(0===e.length)return"";let t=[tS.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===eM.Un),n=e.filter(e=>e.filePath!==eM.Un);for(let e of(n.length>0&&n.forEach((e,r)=>{let n=e.startLine>0||e.endLine>0?`:${e.startLine}-${e.endLine}`:"";t.push(`[${r+1}] ${e.filePath}${n}`),t.push("```"),t.push(e.codeContent),t.push("```"),e.content&&t.push(tS.A.t("comments.note",{content:e.content})),t.push("")}),r)){let r=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");t.push(r),e.content&&t.push(e.content),t.push("")}return t.join("\n").trim()}function sX({isOpen:e,onClose:t,cwd:r,onNavigateToComment:a}){let{t:l}=(0,o.Bd)(),i=(0,A.r)(),[d,c]=(0,s.useState)([]),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(!1),[v,w]=(0,s.useState)(!1),k=(0,s.useCallback)(async()=>{if(!r)return;x(!0);let e=await u.t4.runPromiseExit((0,sY.$)(r));"Success"===e._tag?c(e.value.comments??[]):console.error("Failed to load comments:",e.cause),x(!1)},[r]);(0,s.useEffect)(()=>{e&&k()},[e,k]);let y=async e=>{let t=await u.t4.runPromiseExit((0,sY.Tu)(r,e));"Success"===t._tag?(c(t=>t.filter(t=>t.id!==e)),(0,eM.Cm)()):console.error("Failed to delete comment:",t.cause)},N=async e=>{f(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await u.t4.runPromiseExit((0,j.K)(r,e.filePath));if("Success"!==n._tag||!n.value.ok)throw Error("Failed to read file");t=(n.value.data?.content||"").split("\n").slice(e.startLine-1,e.endLine).join("\n")}let n={filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,content:e.content,codeContent:t},s=sZ([n]);await navigator.clipboard.writeText(s),(0,T.oR)(l("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{f(null)}},C=async()=>{if(0!==d.length){g(!0);try{let e=await (0,eM.$3)(r),t=sZ(e);await navigator.clipboard.writeText(t),(0,T.oR)(l("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{g(!1)}}},S=async()=>{if(0!==d.length&&i&&!i.isLoading&&!v){w(!0);try{let e=(await (0,eM.$3)(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0})),n=(0,eM.Gw)(e,"");i.sendMessage(n),await (0,eM.RP)(r),c([]),t()}catch(e){console.error("Failed to send comments to AI:",e)}finally{w(!1)}}},M=d.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let L=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim p-4",onClick:t,children:(0,n.jsxs)("div",{className:"w-full max-w-2xl max-h-[80vh] bg-card border border-border rounded-lg shadow-lv3 flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border ",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:l("comments.allComments")}),d.length>0&&(0,n.jsx)("button",{onClick:C,disabled:p,className:"p-1 rounded hover:bg-hover text-muted-foreground disabled:opacity-50",title:l("comments.copyAllComments"),children:p?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-hover text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:m?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:l("common.loading")}):0===d.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,n.jsx)("svg",{className:"w-12 h-12 mb-3 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsx)("span",{children:l("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(M).map(([e,t])=>(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground font-mono",children:e===eM.Un?l("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",l("comments.nComments",{count:t.length}),")"]})]}),(0,n.jsx)("div",{className:"divide-y divide-border",children:t.map(e=>{var t;return(0,n.jsx)("div",{className:"px-3 py-2 hover:bg-hover cursor-pointer group",onClick:()=>a?.(e),children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[e.startLine>0||e.endLine>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-brand font-mono",children:[l("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",l("comments.linesCount",{count:e.endLine-e.startLine+1}),")"]})]}):e.selectedText?(0,n.jsxs)("span",{className:"text-xs text-muted-foreground italic truncate max-w-[200px]",children:["“",e.selectedText.slice(0,50),e.selectedText.length>50?"...":"","”"]}):null,(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:(t=e.updatedAt||e.createdAt)?new Date(t).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"}):""})]}),(0,n.jsx)("p",{className:"text-sm text-foreground line-clamp-2",children:e.content||(0,n.jsx)("span",{className:"text-muted-foreground italic",children:l("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),N(e)},disabled:h===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover text-muted-foreground transition-opacity disabled:opacity-50",title:l("common.copy"),children:h===e.id?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover text-muted-foreground hover:text-red-9 transition-opacity",title:l("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)})})]},e))})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:l("comments.totalComments",{count:d.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[i&&(0,n.jsx)("button",{onClick:S,disabled:0===d.length||i.isLoading||v,className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",title:i.isLoading?l("comments.aiResponding"):void 0,children:v?l("comments.submitting"):l("comments.sendToAI")}),(0,n.jsx)("button",{onClick:async()=>{0===d.length||await (0,eM.RP)(r)&&c([])},disabled:0===d.length,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 disabled:opacity-50 disabled:cursor-not-allowed",children:l("comments.clearAll")})]})]})]})});return(0,n.jsx)(b.ZL,{children:L})}let s0=`${sG.o} pl-3 pr-14 bg-card/50`;function s1({tabId:e,initialCwd:t,initialSessionId:r,engine:l,onEngineChange:i,ollamaModel:x,onOllamaModelChange:h,deepseekModel:g,onDeepseekModelChange:b,kimiModel:v,onKimiModelChange:j,glmModel:w,onGlmModelChange:k,claudeModel:y,onClaudeModelChange:N,claudeEffort:C,onClaudeEffortChange:S,claudeFastMode:M,onClaudeFastModeChange:L,claudeThinking:E,onClaudeThinkingChange:P,codexModel:$,onCodexModelChange:R,codexReasoningEffort:I,onCodexReasoningEffortChange:F,planMode:B,onPlanModeChange:D,noHistory:A,onNoHistoryChange:H,outputStyle:z,onOutputStyleChange:W,hideHeader:O,hideSidebar:_,isActive:q=!0,isFocused:V=q,peerTabId:U,peerSide:K,refreshSignal:Q,onLoadingChange:J,onSessionIdChange:G,onTitleChange:Y,onBotChange:Z,onShowGitStatus:X,onOpenNote:ee,isFavorite:et,onToggleFavorite:er,onCreateScheduledTask:en,onOpenSession:es,onContentSearch:eo,onShowFileDiff:ea,onOpenFileLink:el,onOpenSessionBrowser:ei,onOpenSettings:ed}){let ec,{t:eu}=(0,o.Bd)(),em=(0,s.useContext)(a),[ex,eh]=(0,s.useState)(""),[ef,ep]=(0,s.useState)([]),eg=(0,ny.nH)(),[eb,ev]=(0,s.useState)([]),[ej,ew]=(0,s.useState)(null),[ek,ey]=(0,s.useState)(!1),[eN,eC]=(0,s.useState)(!1),[eS,eL]=(0,s.useState)(!1),eE=function(e){let[t,r]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{if(!e)return void r(!1);let t=!1,n=async()=>{let n=await u.t4.runPromiseExit((0,sY.lb)(e));t||"Success"!==n._tag||r((n.value.comments?.length??0)>0)};n();let s=(0,eM.zL)(n);return()=>{t=!0,s()}},[e]),t}(t),[eP,e$]=(0,s.useState)(!1),[eT,eR]=(0,s.useState)(null),[eI,eF]=(0,s.useState)(!1),eB=B??eI,eD=(0,s.useCallback)(e=>{eF(e),D?.(e)},[D]),[eA,eH]=(0,s.useState)(!1),ez=A??eA,eW=(0,s.useCallback)(e=>{eH(e),H?.(e)},[H]),[eO,e_]=(0,s.useState)(""),eq=z??eO,eV=(0,s.useCallback)(e=>{e_(e),W?.(e)},[W]),[eU,eK]=(0,s.useState)(!1),eQ=(0,s.useRef)(null),eJ=(0,s.useRef)(null),eG=(0,s.useCallback)(async e=>{if(!t)return;let r=await u.t4.runPromiseExit((0,m.n_)({cwd:t,sessionId:e}));"Success"===r._tag&&r.value&&"string"==typeof r.value.title?Y?.(r.value.title):"Failure"===r._tag&&console.error("Failed to fetch session title:",r.cause)},[t,Y]),eY=(0,s.useRef)(null),[eZ,eX]=(0,s.useState)(!1),[e0,e1]=(0,s.useState)(null),[e2,e5]=(0,s.useState)(null),[e4,e3]=(0,s.useState)(nH.R),e6=(0,s.useMemo)(()=>(0,nz.hC)(),[]),e8=(0,s.useRef)(!1);(0,s.useEffect)(()=>{e8.current=eZ},[eZ]);let{isLoadingHistory:e9,isLoadingMore:e7,hasMoreHistory:te,loadMoreHistory:tt,ensureTurnLoaded:tr,loadHistoryByCwdAndSessionId:tn,loadedSessionId:ts,loadedEngine:to,loadedBot:ta}=(0,nA.m)(eb,ev,ej,{cwd:t,initialSessionId:r,onSessionId:ew,onTitleChange:Y,onTokenUsage:eR,liveRunningRef:e8}),tl=to??l??void 0;(0,s.useEffect)(()=>{Z?.(ta)},[ta,Z]);let ti=!tl||"claude"===tl,td="codex"===tl,tc=y??sh,tu=sS(tc,C),tm=$??sf,tx=sw(tm,I),th="deepseek"===tl||"kimi"===tl||"glm"===tl?tl:null,tf="kimi"===th?v:"glm"===th?w:g,tp="kimi"===th?j:"glm"===th?k:b,tg="ollama"===tl||null!==th||ti||td;(0,s.useEffect)(()=>{to&&l!==to&&i?.(to)},[l,to,i]);let{isLoading:tb,tokenUsage:tv,liveOutputTokens:tj,runningStartedAt:tw,rateLimitInfo:tk,apiRetryInfo:ty,backgroundTasks:tN,promptSuggestion:tC,handleSend:tS,handleStop:tM,injectMessage:tL}=(0,nH.e)(eb,ev,{sessionId:ej,cwd:t,engine:tl,planMode:eB,noHistory:ez,outputStyleId:eq,ollamaModel:x,engineModel:tf,claudeModel:tc,claudeEffort:tu,claudeFastMode:M,claudeThinking:E,codexModel:tm,codexReasoningEffort:tx,onSessionId:ew,onFetchTitle:eG,onRunComplete:()=>eY.current?.(),taskStore:e6}),tE=ti&&!!(ts||ej),tP=(0,s.useCallback)((e,t,r)=>{eQ.current?.pinNextUserMessage();let n=ts||ej;return tE&&n&&(tb||e8.current)?tL(e,t,n).catch(t=>{eh(t=>t||e),(0,T.oR)(t instanceof Error?t.message:String(t),"error")}):tS(e,t,r)},[tS,tL,tE,tb,ts,ej]),t$=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(ti){let t=/^\/plan(?:\s+([\s\S]*))?$/.exec(e.trim());if(t){let e=(t[1]??"").trim();"off"===e.toLowerCase()?(eD(!1),(0,T.oR)(eu("chat.planModeOff",{defaultValue:"Plan mode off"}),"info")):""===e?(eD(!0),(0,T.oR)(eu("chat.planModeOn",{defaultValue:"Plan mode on"}),"success")):(eD(!0),tP(e,r,{permissionMode:"plan"}));return}}if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void tP(e,r);let o=e.split("\n").slice(1).join("\n").trim(),a=await u.t4.runPromiseExit((0,m.JC)({command:s,cwd:t}));if("Success"===a._tag){let e=a.value,t=[e.stdout,e.stderr].filter(Boolean).join("\n")||"(no output)",n=eu("chat.executedCommand",{command:s,exitInfo:e.exitCode?` (exit code: ${e.exitCode})`:"",output:t});o&&(n+=`
35
35
 
36
- ${o}`),tP(n,r)}else tP(eu("chat.executedCommandFailed",{command:s,error:a.cause}),r);return}tP(e,r)},[tP,t,eu,ti,eD]),tT=(0,s.useCallback)(()=>{eD(!1),tP(eu("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[tP,eD,eu]),tR=ts||ej,tI=q&&!tb&&!!tR;(0,nR.u)(tR,ev,tI,tl,{onRunningChange:e=>{e8.current=e,eX(e)},onLiveOutputTokens:e1,onRunStartedAt:e5,onBackgroundTasks:e=>e3(e.length?e:nH.R),taskStore:e6,onComplete:()=>{t&&tR&&tn(t,tR,!0,10)}}),(0,s.useEffect)(()=>{tI||(eX(!1),e1(null),e5(null),e3(nH.R))},[tI]),(0,s.useEffect)(()=>{eY.current=()=>{t&&tR&&tn(t,tR,!0,10)}},[t,tR,tn]);let tF=(0,s.useRef)(q);(0,s.useEffect)(()=>{q&&!tF.current&&ej&&t&&!tb&&!eZ&&tn(t,ej,!0,10),tF.current=q},[q,ej,t,tb,eZ,tn]);let tB=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!Q||Q.nonce===tB.current)return;tB.current=Q.nonce;let e=ej||ts;!t||!e||Q.sessionId!==ej&&Q.sessionId!==ts||tb||eZ||tn(t,e,!0,10,void 0,!0)},[Q,ej,ts,t,tb,eZ,tn]);let tD=tv||eT,tA=tb?tj:eZ?e0:null,tH=tb?tw:eZ?e2:null,tz=tb?tN:eZ?e4:nH.R;(0,s.useEffect)(()=>{ej&&G?.(ej)},[ej,G]);let tW=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(J?.(tb),tW.current&&!tb&&t&&ej){let e;for(let t=eb.length-1;t>=0;t--)if("user"===eb[t].role&&eb[t].content){e=eb[t].content.slice(0,100);break}(0,d.F)(c.n.SessionComplete,{cwd:t,sessionId:ej,lastUserMessage:e})}tW.current=tb},[tb,J,t]),(0,s.useEffect)(()=>{if(e&&eg&&(eg.setChatLoading(e,q&&tb&&!tE),q))return()=>{eg.setChatLoading(e,!1)}},[e,tb,q,eg,tE]),(0,s.useEffect)(()=>{if(e&&eg)return eg.registerChat(e=>{eJ.current?.(e)},e),()=>{eg.unregisterChat(e)}},[e,eg]),(0,s.useEffect)(()=>{e&&q&&V&&eg&&eg.setActiveTab(e)},[e,q,V,eg]),(0,s.useEffect)(()=>{eJ.current=t$},[t$]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&ek&&(tb||eZ)&&tM()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ek,tb,eZ,tM]);let tO=(0,s.useCallback)(async(e,r)=>{let n=ts??ej;if(!t||!n)return;let s=await u.t4.runPromiseExit((0,m.Zr)(n,{cwd:t,fromMessageUuid:e,scope:r}));if("Success"===s._tag&&s.value.newSessionId){let e=s.value.newSessionId;es?es(e,"single"===r?"Excerpt":"Fork"):(0,d.F)(c.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===s._tag&&(console.error("Fork failed:",s.cause),(0,T.oR)("single"===r?eu("toast.excerptFailed",{defaultValue:"Failed to excerpt this turn"}):eu("toast.forkFailed",{defaultValue:"Failed to fork session"}),"error"))},[t,ts,ej,es,eu]),t_=(0,s.useRef)(tO);t_.current=tO;let tq=(0,s.useRef)((e,t)=>t_.current(e,t)).current,tV=(0,s.useCallback)(async e=>{let r=ts??ej;if(!t||!r||tb||eZ)return;let n=Math.max(10,eb.filter(e=>"user"===e.role).length),s=await u.t4.runPromiseExit((0,m.$N)(r,{cwd:t,messageUuid:e}));"Success"===s._tag?(ev(t=>{let r=t.findIndex(t=>t.id===e);if(r<0)return t;let n=r;for(;n>=0&&"user"!==t[n].role;)n-=1;if(n<0)return t;let s=n+1;for(;s<t.length&&"user"!==t[s].role;)s+=1;return[...t.slice(0,n),...t.slice(s)]}),await tn(t,r,!1,n,void 0,!0),(0,T.oR)(eu("toast.turnDeleted",{defaultValue:"Turn deleted"}),"success")):(console.error("Delete turn failed:",s.cause),(0,T.oR)(eu("toast.deleteTurnFailed",{defaultValue:"Failed to delete this turn"}),"error"))},[t,ts,ej,tb,eZ,eb,tn,eu]),tU=(0,s.useRef)(tV);tU.current=tV;let tK=(0,s.useRef)(e=>tU.current(e)).current,tQ=(0,s.useCallback)(e=>{if(U&&eg){if(!eg.sendToTab(U,e))return void(0,T.oR)(eu("toast.sendToPeerFailed",{defaultValue:"Failed to send to the other pane"}),"error");(0,T.oR)(eu("toast.sentToPeer",{defaultValue:"Sent to the other pane"}),"success")}},[U,eg,eu]),tJ=(0,s.useRef)(tQ);tJ.current=tQ;let tG=(0,s.useRef)(e=>tJ.current(e)).current,tY=(0,s.useCallback)(()=>{eL(!0)},[]),tZ=(0,s.useCallback)(()=>{e$(!0)},[]),tX=(0,s.useRef)(eb);tX.current=eb;let t0=(0,s.useCallback)(async e=>{if(tX.current.some(t=>t.id===e.id))return void eQ.current?.scrollToMessage(e.id);await tr(e.turnIndex);for(let t=0;t<30;t++)if(await new Promise(e=>requestAnimationFrame(()=>e())),eQ.current?.scrollToMessage(e.id))return},[tr]),t1=(0,s.useMemo)(()=>{if(en&&t&&e)return r=>{en({...r,cwd:t,tabId:e,sessionId:ej??crypto.randomUUID(),engine:tl,..."ollama"===tl&&x&&{model:x},...th&&tf&&{model:tf},...ti&&{model:tc},...td&&{model:tm}})}},[en,t,e,ej,tl,x,th,tf,ti,tc,td,tm]),t2=tg?(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eu("chat.noHistoryDesc",{defaultValue:"each prompt is independent"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"nohistory-toggle",checked:ez,onChange:e=>eW(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${ez?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(n$.A,{className:"w-3.5 h-3.5"}),eu("chat.noHistory",{defaultValue:"No history context"})]})]}):null,t5=(0,n.jsx)(sq,{value:eq,onChange:eV});return(0,n.jsx)(nz.I$.Provider,{value:e6,children:(0,n.jsxs)("div",{className:`flex ${O&&_?"h-full":"h-screen"} bg-card`,children:[(0,n.jsxs)("div",{id:"chat-screen",className:"flex-1 flex flex-col min-w-0 relative",onMouseEnter:()=>ey(!0),onMouseLeave:()=>ey(!1),children:[!O&&(0,n.jsx)(nF,{cwd:t,sessionId:ej,engine:tl,onOpenProjectSessions:()=>eC(!0),onOpenSessionBrowser:ei,onOpenSettings:ed}),(ti||td)&&(0,n.jsxs)("div",{className:s0,children:[(0,n.jsx)(sE,{engine:td?"codex":"claude",claudeModel:tc,onClaudeModelChange:N,claudeEffort:tu,onClaudeEffortChange:S,claudeFastMode:M,onClaudeFastModeChange:L,claudeThinking:E,onClaudeThinkingChange:P,codexModel:tm,onCodexModelChange:R,codexReasoningEffort:tx,onCodexReasoningEffortChange:F}),ti&&(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eu("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:eB,onChange:e=>eD(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${eB?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(nT.A,{className:"w-3.5 h-3.5"}),eu("chat.planMode",{defaultValue:"Plan mode"})]})]}),t2,t5]}),"ollama"===tl&&(0,n.jsxs)("div",{className:s0,children:[h&&(0,n.jsx)(sc,{currentModel:x,onModelChange:h}),t2,t5]}),th&&(0,n.jsxs)("div",{className:s0,children:[tp&&(0,n.jsx)(sm,{engine:th,currentModel:tf,onModelChange:tp,onHasKeyChange:eK}),t2,t5,(0,n.jsx)("div",{className:"ml-auto pl-2",children:"deepseek"===th?(0,n.jsx)(sU,{hasKey:eU}):(0,n.jsx)(sJ,{engine:th,hasKey:eU})})]}),e9?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:eu("sessions.loadingHistory")})}):(0,n.jsx)(nW.M,{ref:eQ,messages:eb,isLoading:tb||eZ,liveOutputTokens:tA,runningStartedAt:tH,cwd:t,sessionId:ej,engine:tl,botName:ta,apiRetryInfo:ty,backgroundTasks:tz,hasMoreHistory:te,isLoadingMore:e7,onLoadMore:tt,onFork:tq,onDeleteTurn:tK,onSendToPeer:tG,peerSide:K,isActive:q,onContentSearch:eo,onShowFileDiff:ea,onOpenFileLink:el,onApprovePlan:tT,onShowUserMessages:tZ}),tD&&(0,n.jsx)(nB,{tokenUsage:tD,rateLimitInfo:tk}),em&&!V?null:(ec=(0,n.jsx)(sl,{onSend:t$,disabled:(tb||eZ)&&!tE,running:tb||eZ,cwd:t,engine:tl,onShowGitStatus:X,onShowComments:t?tY:void 0,hasComments:eE,onOpenNote:ee,isFavorite:et,onToggleFavorite:er,onCreateScheduledTask:t1,draft:ex,setDraft:eh,draftImages:ef,setDraftImages:ep,suggestion:tC}),em?(0,p.createPortal)(ec,em):ec)]}),!O&&t&&(0,n.jsx)(f,{isOpen:eN,onClose:()=>eC(!1),cwd:t}),t&&(0,n.jsx)(sX,{isOpen:eS,onClose:()=>eL(!1),cwd:t}),(0,n.jsx)(nD,{isOpen:eP,onClose:()=>e$(!1),cwd:t,sessionId:ts??ej,onSelectMessage:t0})]})})}function s2({tabId:e,cwd:t,sessionId:r,engine:o,onEngineChange:a,ollamaModel:l,onOllamaModelChange:i,deepseekModel:d,onDeepseekModelChange:c,kimiModel:u,onKimiModelChange:m,glmModel:x,onGlmModelChange:h,claudeModel:f,onClaudeModelChange:p,claudeEffort:g,onClaudeEffortChange:b,claudeFastMode:v,onClaudeFastModeChange:j,claudeThinking:w,onClaudeThinkingChange:k,codexModel:y,onCodexModelChange:N,codexReasoningEffort:C,onCodexReasoningEffortChange:S,planMode:M,onPlanModeChange:L,noHistory:E,onNoHistoryChange:P,outputStyle:$,onOutputStyleChange:T,isActive:R,isFocused:I,peerTabId:F,peerSide:B,refreshSignal:D,onStateChange:A,onShowGitStatus:H,onOpenNote:z,isFavorite:W,onToggleFavorite:O,onCreateScheduledTask:_,onOpenSession:q,onContentSearch:V,onShowFileDiff:U,onOpenFileLink:K}){let Q=(0,s.useCallback)(t=>{A(e,{isLoading:t})},[e,A]),J=(0,s.useCallback)(t=>{A(e,{sessionId:t})},[e,A]),G=(0,s.useCallback)(t=>{A(e,{title:t})},[e,A]),Y=(0,s.useCallback)(t=>{A(e,{bot:t??void 0})},[e,A]),Z=(0,s.useCallback)(t=>{a?.(e,t)},[e,a]),X=(0,s.useCallback)(t=>{i?.(e,t)},[e,i]),ee=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),et=(0,s.useCallback)(t=>{m?.(e,t)},[e,m]),er=(0,s.useCallback)(t=>{h?.(e,t)},[e,h]),en=(0,s.useCallback)(t=>{p?.(e,t)},[e,p]),es=(0,s.useCallback)(t=>{b?.(e,t)},[e,b]),eo=(0,s.useCallback)(t=>{j?.(e,t)},[e,j]),ea=(0,s.useCallback)(t=>{k?.(e,t)},[e,k]),el=(0,s.useCallback)(t=>{N?.(e,t)},[e,N]),ei=(0,s.useCallback)(t=>{S?.(e,t)},[e,S]),ed=(0,s.useCallback)(t=>{L?.(e,t)},[e,L]),ec=(0,s.useCallback)(t=>{P?.(e,t)},[e,P]),eu=(0,s.useCallback)(t=>{T?.(e,t)},[e,T]),em=(0,s.useCallback)(()=>{O?.(e)},[e,O]);return(0,n.jsx)(s1,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,onEngineChange:Z,ollamaModel:l,onOllamaModelChange:X,deepseekModel:d,onDeepseekModelChange:ee,kimiModel:u,onKimiModelChange:et,glmModel:x,onGlmModelChange:er,claudeModel:f,onClaudeModelChange:en,claudeEffort:g,onClaudeEffortChange:es,claudeFastMode:v,onClaudeFastModeChange:eo,claudeThinking:w,onClaudeThinkingChange:ea,codexModel:y,onCodexModelChange:el,codexReasoningEffort:C,onCodexReasoningEffortChange:ei,planMode:M,onPlanModeChange:ed,noHistory:E,onNoHistoryChange:ec,outputStyle:$,onOutputStyleChange:eu,hideHeader:!0,hideSidebar:!0,isActive:R,isFocused:I,peerTabId:F,peerSide:B,refreshSignal:D,onLoadingChange:Q,onSessionIdChange:J,onTitleChange:G,onBotChange:Y,onShowGitStatus:H,onOpenNote:z,isFavorite:W,onToggleFavorite:r&&O?em:void 0,onCreateScheduledTask:_,onOpenSession:q,onContentSearch:V,onShowFileDiff:U,onOpenFileLink:K})}var s5=r(3292),s4=r(23121),s3=r(88292),s6=r(76900),s8=r(96472);function s9(e,t){if(!t.split)return{};let r=t.panes.indexOf(e);return -1===r?{}:{peerTabId:t.panes[1-r],peerSide:0===r?"right":"left"}}function s7({tabId:e,panes:t,activePane:r,row:s,maximized:a,onFocusPane:l,onClosePane:i,onToggleMaximize:d,children:c}){let{t:u}=(0,o.Bd)(),m=t.indexOf(e),x=t.length>1;return(0,n.jsxs)("div",{onMouseDownCapture:x?()=>l(m):void 0,style:s&&-1!==m&&!a?{order:m}:void 0,className:`group/pane ${function(e,t,r,n,s){let o=t.indexOf(e);if(-1===o)return"relative hidden";if(s)return"absolute inset-0 z-30 border-y border-y-transparent";if(!n)return"relative h-full block";let a=t.length>1?` border-y ${o===r?"border-y-brand":"border-y-transparent"}`:"";return`relative h-full flex-1 min-w-0${a}${o>0?" border-l border-border":""}`}(e,t,r,s,a)}`,children:[x&&-1!==m&&(0,n.jsxs)("div",{className:"absolute top-1 right-1 z-20 flex items-center gap-0.5 opacity-0 pointer-events-none transition-opacity focus-within:opacity-100 focus-within:pointer-events-auto group-hover/pane:opacity-100 group-hover/pane:pointer-events-auto",children:[(0,n.jsx)("button",{type:"button",onClick:()=>d(m),title:u(a?"chat.restorePane":"chat.maximizePane"),"aria-label":u(a?"chat.restorePane":"chat.maximizePane"),"aria-pressed":a,className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:a?(0,n.jsx)(nE.A,{className:"w-3.5 h-3.5"}):(0,n.jsx)(nP.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(m),title:u("chat.closePane"),"aria-label":u("chat.closePane"),className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),c]})}function oe({initialCwd:e,initialSessionId:t,initialBlank:r,initialView:a,initialFile:i,initialBubble:d}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(a??"agent"),[p,g]=(0,s.useState)(null),{tabs:v,activeTabId:j,activeTab:w,paneTabIds:k,activePane:y,toggleSideBySide:N,focusPane:C,closePane:S,unreadTabs:M,globalLoadingTabs:L,pageVisible:E,dragTabIndex:P,dragOverTabIndex:$,closeTab:T,closeAllTabs:R,switchTab:I,handleSelectSession:F,handleNewTab:B,handleNewCodexTab:D,handleNewKimiTab:A,handleNewGlmTab:H,handleNewOllamaTab:z,handleNewDeepseekTab:W,handleOpenSession:O,updateTabState:_,updateTabEngine:q,updateTabOllamaModel:V,updateTabDeepseekModel:U,updateTabKimiModel:K,updateTabGlmModel:Q,updateTabClaudeModel:J,updateTabClaudeEffort:G,updateTabClaudeFastMode:Y,updateTabClaudeThinking:Z,updateTabCodexModel:X,updateTabCodexReasoningEffort:ee,updateTabPlanMode:et,updateTabNoHistory:er,updateTabOutputStyle:en,handleTabDragStart:es,handleTabDragOver:ea,handleTabDrop:el,handleTabDragEnd:ei}=(0,nS.useTabState)({initialCwd:e,initialSessionId:t,initialBlank:r,activeView:x}),{isPinned:ed,pinSession:ec,unpinSession:eu}=(0,s5.P)(),{createTask:em}=(0,s4.nS)(),ex=(0,s.useCallback)(e=>{let t=v.find(t=>t.id===e);return!!t?.sessionId&&ed(t.sessionId)},[v,ed]),eh=(0,s.useCallback)(t=>{let r=v.find(e=>e.id===t);r?.sessionId&&(ed(r.sessionId)?eu(r.sessionId):ec(r.sessionId,r.cwd||e||"",r.title))},[v,ed,ec,eu,e]),[ef,ep]=(0,s.useState)(!1),[eg,ev]=(0,s.useState)(!1),[ej,ew]=(0,s.useState)(!1),[ek,ey]=(0,s.useState)(null),[eN,eC]=(0,s.useState)(!1),[eS,eM]=(0,s.useState)("tree"),[eL,eE]=(0,s.useState)(0),[eP,e$]=(0,s.useState)(null),[eT,eR]=(0,s.useState)(0),[eI,eF]=(0,s.useState)(i?{path:i,nonce:0}:null),[eB,eD]=(0,s.useState)(d?{commandId:d,nonce:0}:null),eA=(0,s.useRef)(()=>{}),[eH,ez]=(0,s.useState)(null),eW=null!==eH,eO=(0,s.useMemo)(()=>{let e;return{panes:e=eW?[j]:k,activePane:eW?0:y,row:e.length>1||eW,split:e.length>1,diffOrder:e.length}},[k,y,j,eW]),[e_,eq]=(0,s.useState)(null),[eV,eU]=(0,s.useState)();(0,s.useEffect)(()=>{window.parent.postMessage({type:"GET_PROJECT_NUMBER",cwd:e},"*")},[e]),(0,s.useEffect)(()=>{e&&!a&&u.t4.runPromiseExit((0,s6.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&h(t.activeView)}})},[e,a]);let[eK,eQ]=(0,s.useState)(!1),eJ=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(eJ.current=x,h("console"),eQ(!0)):(eQ(!1),eJ.current&&"console"!==eJ.current&&h(eJ.current),eJ.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[x]);let eG=(0,s.useCallback)(t=>{h(t),e&&(u.t4.runFork((0,s6.Yn)({cwd:e,settings:{activeView:t}}).pipe(eb.NWQ(()=>eb.rIH))),u.t4.runFork(eb.qIB(s3.d,r=>r.publish(c.n.ViewChange,{cwd:e,view:t}))))},[e]);(0,s.useEffect)(()=>{let e=()=>eG("console");return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[eG]);let eY=(0,s.useCallback)(async()=>{if(!e)return;let t=await u.t4.runPromiseExit((0,s6.b2)(e));if("Success"===t._tag){let r=t.value;if(eC(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&ey(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>eY())},[eY]);let eZ=(0,s.useCallback)(e=>{let{data:t}=e;Array.isArray(t)&&t.some(e=>"git"===e.type)&&eY()},[eY]);(0,eo.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:eZ,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),eG("agent")):"2"===e.key?(e.preventDefault(),eG("explorer")):"3"===e.key?(e.preventDefault(),eG("console")):"s"===e.key&&e.preventDefault())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{e&&window.parent!==window&&window.parent.postMessage({type:"SESSION_NUMBERS",cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*")},[e,v]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="PROJECT_NUMBER"&&"number"==typeof t.data?.projectNumber)return void eU(t.data.projectNumber);if(t.data?.type==="IFRAME_VISIBILITY"&&"number"==typeof t.data?.projectNumber&&eU(t.data.projectNumber),t.data?.type==="GET_SESSION_NUMBERS"&&t.data?.requestId&&e)return void window.parent.postMessage({type:"SESSION_NUMBERS",requestId:t.data.requestId,cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*");if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){F(r),n&&eG("agent");let t=v.find(e=>e.sessionId===r);t&&eq(e=>({sessionId:r,nonce:(e?.nonce??0)+1})),e&&!t?.isLoading&&(u.t4.runFork((0,s8.KJ)(e,r,"normal").pipe(eb.NWQ(()=>eb.rIH))),u.t4.runFork((0,s8.M2)(r).pipe(eb.NWQ(()=>eb.rIH))))}}t.data?.type==="OPEN_FILE"&&"string"==typeof t.data?.path&&eA.current({path:t.data.path}),t.data?.type==="FOCUS_CONSOLE_BUBBLE"&&"string"==typeof t.data?.commandId&&(eG("console"),eD(e=>({commandId:t.data.commandId,nonce:(e?.nonce??0)+1})))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[F,eG,e,v]);let eX=(0,s.useCallback)(()=>{eM("status"),eE(e=>e+1),eG("explorer")},[eG]),e0=(0,s.useCallback)(e=>{e$(e),eR(e=>e+1),eG("explorer")},[eG]),e1=(0,s.useCallback)(()=>eG("agent"),[eG]),[e2,e5]=(0,s.useState)(!1);(0,s.useEffect)(()=>{eW||e5(!1)},[eW]);let[e4,e3]=(0,s.useState)(!1),e6=e4&&eO.split?eO.panes[eO.activePane]??null:null;(0,s.useEffect)(()=>{eO.split||e3(!1)},[eO.split]);let e8=(0,s.useCallback)(e=>{e3(e=>!e),C(e)},[C]),e9=(0,s.useCallback)(()=>e5(e=>!e),[]),e7=(0,s.useCallback)(()=>ez(null),[]),te=(0,s.useRef)(null),tt=(0,s.useCallback)(e=>{let t=te.current;if(!t)return;let r=e.offset>0&&null!==e.target&&t.contains(e.target);if("move"===e.phase){if(!r)return;let n=Math.min(.5*e.offset,t.offsetWidth);t.style.transition="none",t.style.transform=`translateX(${n}px)`;return}r&&e.triggered?(t.style.transition="transform 140ms ease-out, opacity 140ms ease-out",t.style.transform="translateX(100%)",t.style.opacity="0",window.setTimeout(e7,140)):(t.style.transition="transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1)",t.style.transform="")},[e7]);(0,s.useEffect)(()=>{let e=te.current;e&&(e.style.transition="",e.style.transform="",e.style.opacity="")},[eH]);let tr=(0,s.useRef)(eW);(0,s.useEffect)(()=>{tr.current=eW},[eW]);let tn=(0,s.useRef)(e6);(0,s.useEffect)(()=>{tn.current=e6},[e6]);let ts=(0,s.useCallback)(()=>{tr.current?e7():null!==tn.current?e3(!1):N()},[N,e7]),to=(0,s.useCallback)((e,t,r,n,s)=>{ez(o=>{var a;return a={messageId:e,toolCalls:t,cwd:r,sessionId:n},!0!==s?a:o?.messageId!==a.messageId?o:{...o,toolCalls:a.toolCalls}}),s||eG("agent")},[eG]),ta=(0,s.useCallback)(e=>{eF({...e,nonce:Date.now()}),eG("explorer")},[eG]);(0,s.useEffect)(()=>{eA.current=ta},[ta]);let tl=(0,s.useCallback)(()=>{e&&u.t4.runFork(eb.qIB(s3.d,t=>t.publish(c.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(ny.k_,{children:(0,n.jsx)(tI.fY,{activeView:x,onViewChange:eG,onOverscroll:tt,children:(0,n.jsxs)("div",{className:"flex h-screen bg-card",children:[(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,n.jsx)(nM.TabManagerTopBar,{initialCwd:e,activeTab:w,isGitRepo:eN,currentBranch:ek,onOpenWorktree:()=>ev(!0),onOpenAliasManager:()=>ew(!0),onBranchSwitched:eY}),eK&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-1 bg-brand/15 text-brand text-xs font-medium border-b border-brand/20",children:[(0,n.jsx)("span",{className:"animate-pulse",children:"●"}),m("console.screenshotting")]}),e?(0,n.jsxs)(tI.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(b.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,n.jsx)(nL.TabBar,{tabs:v,selectedTabId:j,sideBySide:eO.split,onToggleSideBySide:ts,unreadTabs:M,globalLoadingTabs:L,dragTabIndex:P,dragOverTabIndex:$,isPinned:ex,onSwitchTab:I,onCloseTab:T,onCloseAllTabs:R,onNewTab:B,onNewCodexTab:D,onNewKimiTab:A,onNewGlmTab:H,onNewOllamaTab:z,onNewDeepseekTab:W,onOpenProjectSessions:()=>ep(!0),onDragStart:es,onDragOver:ea,onDrop:el,onDragEnd:ei}),(0,n.jsx)(l,{value:eO.split?p:null,children:(0,n.jsxs)("div",{className:`flex-1 overflow-hidden relative ${eO.row?"flex":""}`,children:[v.map(e=>(0,n.jsx)(s7,{tabId:e.id,panes:eO.panes,activePane:eO.activePane,row:eO.row,maximized:e6===e.id,onFocusPane:C,onClosePane:S,onToggleMaximize:e8,children:(0,n.jsx)(s2,{tabId:e.id,...s9(e.id,eO),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:q,ollamaModel:e.ollamaModel,onOllamaModelChange:V,deepseekModel:e.deepseekModel,onDeepseekModelChange:U,kimiModel:e.kimiModel,onKimiModelChange:K,glmModel:e.glmModel,onGlmModelChange:Q,claudeModel:e.claudeModel,onClaudeModelChange:J,claudeEffort:e.claudeEffort,onClaudeEffortChange:G,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Y,claudeThinking:e.claudeThinking,onClaudeThinkingChange:Z,codexModel:e.codexModel,onCodexModelChange:X,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:ee,planMode:e.planMode,onPlanModeChange:et,noHistory:e.noHistory,onNoHistoryChange:er,outputStyle:e.outputStyle,onOutputStyleChange:en,isActive:nC(e.id,k,"agent"===x,E),isFocused:e.id===j,refreshSignal:e_,onStateChange:_,onShowGitStatus:eX,onContentSearch:e0,onShowFileDiff:to,onOpenFileLink:ta,onOpenNote:tl,isFavorite:ex(e.id),onToggleFavorite:eh,onCreateScheduledTask:em,onOpenSession:O})},e.id)),eH&&(0,n.jsx)("div",{ref:te,"data-diff-column":"",className:e2?"absolute inset-0 z-30 bg-card":"h-full flex-1 min-w-0 border-l border-border",style:e2?void 0:{order:eO.diffOrder},children:(0,n.jsx)(nN.e$,{toolCalls:eH.toolCalls,cwd:eH.cwd,sessionId:eH.sessionId,onClose:e7,onContentSearch:e0,fullscreen:e2,onToggleFullscreen:e9},eH.messageId)})]})}),eO.split&&(0,n.jsx)("div",{ref:g,className:"flex-shrink-0"})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden relative",children:(0,n.jsx)(b.a9,{children:(0,n.jsx)(tB,{onClose:e1,cwd:e,initialTab:eS,tabSwitchTrigger:eL,initialSearchQuery:eP,searchQueryTrigger:eT,fileOpenRequest:eI})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(b.a9,{children:(0,n.jsx)(nk,{cwd:e,tabId:"default",onOpenNote:tl,focusBubble:eB})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(nL.TabBar,{tabs:v,selectedTabId:j,sideBySide:eO.split,onToggleSideBySide:ts,unreadTabs:M,globalLoadingTabs:L,dragTabIndex:P,dragOverTabIndex:$,isPinned:ex,onSwitchTab:I,onCloseTab:T,onCloseAllTabs:R,onNewTab:B,onNewCodexTab:D,onNewKimiTab:A,onNewGlmTab:H,onNewDeepseekTab:W,onDragStart:es,onDragOver:ea,onDrop:el,onDragEnd:ei}),(0,n.jsx)(l,{value:eO.split?p:null,children:(0,n.jsx)("div",{className:`flex-1 overflow-hidden relative ${eO.row?"flex":""}`,children:v.map(e=>(0,n.jsx)(s7,{tabId:e.id,panes:eO.panes,activePane:eO.activePane,row:eO.row,maximized:e6===e.id,onFocusPane:C,onClosePane:S,onToggleMaximize:e8,children:(0,n.jsx)(s2,{tabId:e.id,...s9(e.id,eO),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:q,ollamaModel:e.ollamaModel,onOllamaModelChange:V,deepseekModel:e.deepseekModel,onDeepseekModelChange:U,kimiModel:e.kimiModel,onKimiModelChange:K,glmModel:e.glmModel,onGlmModelChange:Q,claudeModel:e.claudeModel,onClaudeModelChange:J,claudeEffort:e.claudeEffort,onClaudeEffortChange:G,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Y,claudeThinking:e.claudeThinking,onClaudeThinkingChange:Z,codexModel:e.codexModel,onCodexModelChange:X,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:ee,planMode:e.planMode,onPlanModeChange:et,noHistory:e.noHistory,onNoHistoryChange:er,outputStyle:e.outputStyle,onOutputStyleChange:en,isActive:nC(e.id,k,!0,E),isFocused:e.id===j,refreshSignal:e_,onStateChange:_,isFavorite:ex(e.id),onToggleFavorite:eh,onCreateScheduledTask:em,onOpenSession:O})},e.id))})}),eO.split&&(0,n.jsx)("div",{ref:g,className:"flex-shrink-0"})]})]}),e&&(0,n.jsx)(f,{isOpen:ef,onClose:()=>ep(!1),cwd:e,onSelectSession:F,projectNumber:eV,openSessionIds:v.map(e=>e.sessionId)}),e&&eN&&(0,n.jsx)(tD,{isOpen:eg,onClose:()=>ev(!1),cwd:e}),ej&&(0,n.jsx)(ns,{onClose:()=>ew(!1),onSave:()=>ew(!1)})]})})})}},96472:(e,t,r)=>{r.d(t,{KJ:()=>l,M2:()=>d,T$:()=>i,ej:()=>a,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.$mh({try:async()=>{let t=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"loadProjectState failed",cause:e})}),a=e=>n.$mh({try:async()=>{let t=await fetch("/api/project-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"saveProjectState failed",cause:e})}),l=(e,t,r)=>n.$mh({try:async()=>{let n=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r,action:"status"})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=(e,t)=>n.$mh({try:async()=>{let r=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,action:"touch"})});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:e=>new s.uV({message:"touchRecentSession failed",cause:e})}),d=e=>n.$mh({try:async()=>{let t=await fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:e}})});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"markScheduledTasksReadBySession failed",cause:e})})},96625:(e,t,r)=>{r.d(t,{V:()=>m,n:()=>u});var n=r(95155),s=r(12115),o=r(79114),a=r(58250),l=r(23348),i=r(33442),d=r(86957),c=r(83448);function u({value:e,onChange:t,textareaRef:r,extraCommands:n}){let[o,m]=(0,s.useState)(e.length),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)([]),[v,j]=(0,s.useState)(0),[w,k]=(0,s.useState)(()=>e.length>0),y=(0,s.useRef)(null);(0,s.useEffect)(()=>{d.t4.runPromiseExit((0,c.M5)()).then(e=>{"Success"===e._tag?h(e.value):console.error("Failed to load commands:",e.cause)})},[]);let N=(0,s.useCallback)(async()=>{let e=await d.t4.runPromiseExit((0,c.l1)());if("Success"===e._tag){let t=e.value.skills??e.value;p((Array.isArray(t)?t:[]).filter(e=>e.valid&&!!e.name).map(e=>({name:`/${e.name}`,description:e.description||"",source:"skill",skillPath:e.path,argumentHint:e.argumentHint})))}else console.error("Failed to load skills:",e.cause)},[]);(0,s.useEffect)(()=>(N(),(0,a.U)(N)),[N]);let C=(0,s.useCallback)(async()=>{let e=await d.t4.runPromiseExit((0,l.jm)());"Success"===e._tag?b(e.value.flatMap(e=>e.valid?[{name:`@${e.name}`,description:e.description,source:"bot"}]:[])):console.error("Failed to load bots:",e.cause)},[]);(0,s.useEffect)(()=>(C(),(0,i.a)(C)),[C]);let S=(0,s.useMemo)(()=>{let t=0===o?0:e.lastIndexOf("\n",o-1)+1,r=e.indexOf("\n",o),n=-1===r?e.length:r;return{text:e.slice(t,n),start:t,end:n}},[e,o]),M=(0,s.useMemo)(()=>{let e=S.text.match(/^\s*(\/@|\/|@)([a-zA-Z0-9-]*)$/);return e?{marker:e[1],verb:e[2].toLowerCase()}:null},[S.text]),L=(0,s.useMemo)(()=>{if(!M)return[];let{verb:e}=M,t=t=>t.name.slice(1).toLowerCase().startsWith(e);return"@"===M.marker?g.filter(t):[...(n??[]).filter(t),...x.filter(t),...f.filter(t)]},[M,n,x,f,g]),E=!w&&!!M&&L.length>0,P=(0,s.useRef)(e);(0,s.useLayoutEffect)(()=>{P.current!==e&&(queueMicrotask(()=>j(0)),w&&queueMicrotask(()=>k(!1)),P.current=e)},[e,w]),(0,s.useLayoutEffect)(()=>{if(E&&y.current){let e=y.current.children[v];e&&e.scrollIntoView({block:"nearest"})}},[v,E]);let $=(0,s.useCallback)(e=>{m(e.selectionStart??0)},[]),T=(0,s.useCallback)(n=>{let s=M?.marker??"/",o=`${s}${n.name.slice(1)} `,a=e.slice(0,S.start),l=e.slice(S.end),i=a.length+o.length;t(a+o+l),m(i),requestAnimationFrame(()=>{let e=r.current;e&&(e.focus(),e.setSelectionRange(i,i))})},[e,S,M,t,r]),R=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing||!E||0===L.length)return!1;let t=()=>{e.preventDefault(),e.stopPropagation()};return"ArrowDown"===e.key?(t(),j(e=>(e+1)%L.length),!0):"ArrowUp"===e.key?(t(),j(e=>(e-1+L.length)%L.length),!0):"Enter"===e.key||"Tab"===e.key?(t(),T(L[v]),!0):"Escape"===e.key&&(t(),k(!0),!0)},[E,L,v,T]);return{isOpen:E,items:L,selectedIndex:v,marker:M?.marker??"/",listRef:y,selectCommand:T,handleKeyDown:R,trackCaret:$}}function m({ac:e,className:t=""}){let{t:r}=(0,o.Bd)(),{isOpen:s,items:a,selectedIndex:l,marker:i,listRef:d,selectCommand:c}=e;return s&&0!==a.length?(0,n.jsx)("div",{ref:d,className:`overflow-y-auto bg-card border border-border rounded-lg shadow-lv2 ${t}`,children:a.map((e,t)=>{let s=t>0?a[t-1]:null,o="skill"===e.source&&(!s||"skill"!==s.source),d="bot"===e.source&&(!s||"bot"!==s.source),u="builtin"===e.source&&0===t;return(0,n.jsxs)("div",{children:[u&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Commands"}),o&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Skills"}),d&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Bots"}),(0,n.jsxs)("div",{onClick:()=>c(e),className:`px-4 py-2 cursor-pointer ${t===l?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:i+e.name.slice(1)}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:"builtin"===e.source?r(`commands.${e.name.slice(1)}`,{defaultValue:e.description}):e.description}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${(e=>{switch(e){case"builtin":return"bg-brand/15 text-brand dark:bg-brand/25 dark:text-teal-11";case"skill":return"bg-purple-9/15 text-purple-11 dark:bg-purple-9/25 dark:text-purple-11";case"bot":return"bg-teal-9/15 text-teal-11 dark:bg-teal-9/25 dark:text-teal-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return r("common.builtin");case"skill":return"Skill";case"bot":return"Bot"}})(e.source)})]}),"skill"===e.source&&e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 pl-0 truncate",children:e.argumentHint})]})]},e.name)})}):null}}}]);
36
+ ${o}`),tP(n,r)}else tP(eu("chat.executedCommandFailed",{command:s,error:a.cause}),r);return}tP(e,r)},[tP,t,eu,ti,eD]),tT=(0,s.useCallback)(()=>{eD(!1),tP(eu("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[tP,eD,eu]),tR=ts||ej,tI=q&&!tb&&!!tR;(0,nR.u)(tR,ev,tI,tl,{onRunningChange:e=>{e8.current=e,eX(e)},onLiveOutputTokens:e1,onRunStartedAt:e5,onBackgroundTasks:e=>e3(e.length?e:nH.R),taskStore:e6,onComplete:()=>{t&&tR&&tn(t,tR,!0,10)}}),(0,s.useEffect)(()=>{tI||(eX(!1),e1(null),e5(null),e3(nH.R))},[tI]),(0,s.useEffect)(()=>{eY.current=()=>{t&&tR&&tn(t,tR,!0,10)}},[t,tR,tn]);let tF=(0,s.useRef)(q);(0,s.useEffect)(()=>{q&&!tF.current&&ej&&t&&!tb&&!eZ&&tn(t,ej,!0,10),tF.current=q},[q,ej,t,tb,eZ,tn]);let tB=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!Q||Q.nonce===tB.current)return;tB.current=Q.nonce;let e=ej||ts;!t||!e||Q.sessionId!==ej&&Q.sessionId!==ts||tb||eZ||tn(t,e,!0,10,void 0,!0)},[Q,ej,ts,t,tb,eZ,tn]);let tD=tv||eT,tA=tb?tj:eZ?e0:null,tH=tb?tw:eZ?e2:null,tz=tb?tN:eZ?e4:nH.R;(0,s.useEffect)(()=>{ej&&G?.(ej)},[ej,G]);let tW=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(J?.(tb),tW.current&&!tb&&t&&ej){let e;for(let t=eb.length-1;t>=0;t--)if("user"===eb[t].role&&eb[t].content){e=eb[t].content.slice(0,100);break}(0,d.F)(c.n.SessionComplete,{cwd:t,sessionId:ej,lastUserMessage:e})}tW.current=tb},[tb,J,t]),(0,s.useEffect)(()=>{if(e&&eg&&(eg.setChatLoading(e,q&&tb&&!tE),q))return()=>{eg.setChatLoading(e,!1)}},[e,tb,q,eg,tE]),(0,s.useEffect)(()=>{if(e&&eg)return eg.registerChat(e=>{eJ.current?.(e)},e),()=>{eg.unregisterChat(e)}},[e,eg]),(0,s.useEffect)(()=>{e&&q&&V&&eg&&eg.setActiveTab(e)},[e,q,V,eg]),(0,s.useEffect)(()=>{eJ.current=t$},[t$]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&ek&&(tb||eZ)&&tM()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ek,tb,eZ,tM]);let tO=(0,s.useCallback)(async(e,r)=>{let n=ts??ej;if(!t||!n)return;let s=await u.t4.runPromiseExit((0,m.Zr)(n,{cwd:t,fromMessageUuid:e,scope:r}));if("Success"===s._tag&&s.value.newSessionId){let e=s.value.newSessionId;es?es(e,"single"===r?"Excerpt":"Fork"):(0,d.F)(c.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===s._tag&&(console.error("Fork failed:",s.cause),(0,T.oR)("single"===r?eu("toast.excerptFailed",{defaultValue:"Failed to excerpt this turn"}):eu("toast.forkFailed",{defaultValue:"Failed to fork session"}),"error"))},[t,ts,ej,es,eu]),t_=(0,s.useRef)(tO);t_.current=tO;let tq=(0,s.useRef)((e,t)=>t_.current(e,t)).current,tV=(0,s.useCallback)(async e=>{let r=ts??ej;if(!t||!r||tb||eZ)return;let n=Math.max(10,eb.filter(e=>"user"===e.role).length),s=await u.t4.runPromiseExit((0,m.$N)(r,{cwd:t,messageUuid:e}));"Success"===s._tag?(ev(t=>{let r=t.findIndex(t=>t.id===e);if(r<0)return t;let n=r;for(;n>=0&&"user"!==t[n].role;)n-=1;if(n<0)return t;let s=n+1;for(;s<t.length&&"user"!==t[s].role;)s+=1;return[...t.slice(0,n),...t.slice(s)]}),await tn(t,r,!1,n,void 0,!0),(0,T.oR)(eu("toast.turnDeleted",{defaultValue:"Turn deleted"}),"success")):(console.error("Delete turn failed:",s.cause),(0,T.oR)(eu("toast.deleteTurnFailed",{defaultValue:"Failed to delete this turn"}),"error"))},[t,ts,ej,tb,eZ,eb,tn,eu]),tU=(0,s.useRef)(tV);tU.current=tV;let tK=(0,s.useRef)(e=>tU.current(e)).current,tQ=(0,s.useCallback)(e=>{if(U&&eg){if(!eg.sendToTab(U,e))return void(0,T.oR)(eu("toast.sendToPeerFailed",{defaultValue:"Failed to send to the other pane"}),"error");(0,T.oR)(eu("toast.sentToPeer",{defaultValue:"Sent to the other pane"}),"success")}},[U,eg,eu]),tJ=(0,s.useRef)(tQ);tJ.current=tQ;let tG=(0,s.useRef)(e=>tJ.current(e)).current,tY=(0,s.useCallback)(()=>{eL(!0)},[]),tZ=(0,s.useCallback)(()=>{e$(!0)},[]),tX=(0,s.useRef)(eb);tX.current=eb;let t0=(0,s.useCallback)(async e=>{if(tX.current.some(t=>t.id===e.id))return void eQ.current?.scrollToMessage(e.id);await tr(e.turnIndex);for(let t=0;t<30;t++)if(await new Promise(e=>requestAnimationFrame(()=>e())),eQ.current?.scrollToMessage(e.id))return},[tr]),t1=(0,s.useMemo)(()=>{if(en&&t&&e)return r=>{en({...r,cwd:t,tabId:e,sessionId:ej??crypto.randomUUID(),engine:tl,..."ollama"===tl&&x&&{model:x},...th&&tf&&{model:tf},...ti&&{model:tc},...td&&{model:tm}})}},[en,t,e,ej,tl,x,th,tf,ti,tc,td,tm]),t2=tg?(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eu("chat.noHistoryDesc",{defaultValue:"each prompt is independent"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"nohistory-toggle",checked:ez,onChange:e=>eW(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${ez?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(n$.A,{className:"w-3.5 h-3.5"}),eu("chat.noHistory",{defaultValue:"No history context"})]})]}):null,t5=(0,n.jsx)(sq,{value:eq,onChange:eV});return(0,n.jsx)(nz.I$.Provider,{value:e6,children:(0,n.jsxs)("div",{className:`flex ${O&&_?"h-full":"h-screen"} bg-card`,children:[(0,n.jsxs)("div",{id:"chat-screen",className:"flex-1 flex flex-col min-w-0 relative",onMouseEnter:()=>ey(!0),onMouseLeave:()=>ey(!1),children:[!O&&(0,n.jsx)(nF,{cwd:t,sessionId:ej,engine:tl,onOpenProjectSessions:()=>eC(!0),onOpenSessionBrowser:ei,onOpenSettings:ed}),(ti||td)&&(0,n.jsxs)("div",{className:s0,children:[(0,n.jsx)(sE,{engine:td?"codex":"claude",claudeModel:tc,onClaudeModelChange:N,claudeEffort:tu,onClaudeEffortChange:S,claudeFastMode:M,onClaudeFastModeChange:L,claudeThinking:E,onClaudeThinkingChange:P,codexModel:tm,onCodexModelChange:R,codexReasoningEffort:tx,onCodexReasoningEffortChange:F}),ti&&(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eu("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:eB,onChange:e=>eD(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${eB?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(nT.A,{className:"w-3.5 h-3.5"}),eu("chat.planMode",{defaultValue:"Plan mode"})]})]}),t2,t5]}),"ollama"===tl&&(0,n.jsxs)("div",{className:s0,children:[h&&(0,n.jsx)(sc,{currentModel:x,onModelChange:h}),t2,t5]}),th&&(0,n.jsxs)("div",{className:s0,children:[tp&&(0,n.jsx)(sm,{engine:th,currentModel:tf,onModelChange:tp,onHasKeyChange:eK}),t2,t5,(0,n.jsx)("div",{className:"ml-auto pl-2",children:"deepseek"===th?(0,n.jsx)(sU,{hasKey:eU}):(0,n.jsx)(sJ,{engine:th,hasKey:eU})})]}),e9?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:eu("sessions.loadingHistory")})}):(0,n.jsx)(nW.M,{ref:eQ,messages:eb,isLoading:tb||eZ,liveOutputTokens:tA,runningStartedAt:tH,cwd:t,sessionId:ej,engine:tl,botName:ta,apiRetryInfo:ty,backgroundTasks:tz,hasMoreHistory:te,isLoadingMore:e7,onLoadMore:tt,onFork:tq,onDeleteTurn:tK,onSendToPeer:tG,peerSide:K,isActive:q,onContentSearch:eo,onShowFileDiff:ea,onOpenFileLink:el,onApprovePlan:tT,onShowUserMessages:tZ}),tD&&(0,n.jsx)(nB,{tokenUsage:tD,rateLimitInfo:tk}),em&&!V?null:(ec=(0,n.jsx)(sl,{onSend:t$,disabled:(tb||eZ)&&!tE,running:tb||eZ,cwd:t,engine:tl,onShowGitStatus:X,onShowComments:t?tY:void 0,hasComments:eE,onOpenNote:ee,isFavorite:et,onToggleFavorite:er,onCreateScheduledTask:t1,draft:ex,setDraft:eh,draftImages:ef,setDraftImages:ep,suggestion:tC}),em?(0,p.createPortal)(ec,em):ec)]}),!O&&t&&(0,n.jsx)(f,{isOpen:eN,onClose:()=>eC(!1),cwd:t}),t&&(0,n.jsx)(sX,{isOpen:eS,onClose:()=>eL(!1),cwd:t}),(0,n.jsx)(nD,{isOpen:eP,onClose:()=>e$(!1),cwd:t,sessionId:ts??ej,onSelectMessage:t0})]})})}function s2({tabId:e,cwd:t,sessionId:r,engine:o,onEngineChange:a,ollamaModel:l,onOllamaModelChange:i,deepseekModel:d,onDeepseekModelChange:c,kimiModel:u,onKimiModelChange:m,glmModel:x,onGlmModelChange:h,claudeModel:f,onClaudeModelChange:p,claudeEffort:g,onClaudeEffortChange:b,claudeFastMode:v,onClaudeFastModeChange:j,claudeThinking:w,onClaudeThinkingChange:k,codexModel:y,onCodexModelChange:N,codexReasoningEffort:C,onCodexReasoningEffortChange:S,planMode:M,onPlanModeChange:L,noHistory:E,onNoHistoryChange:P,outputStyle:$,onOutputStyleChange:T,isActive:R,isFocused:I,peerTabId:F,peerSide:B,refreshSignal:D,onStateChange:A,onShowGitStatus:H,onOpenNote:z,isFavorite:W,onToggleFavorite:O,onCreateScheduledTask:_,onOpenSession:q,onContentSearch:V,onShowFileDiff:U,onOpenFileLink:K}){let Q=(0,s.useCallback)(t=>{A(e,{isLoading:t})},[e,A]),J=(0,s.useCallback)(t=>{A(e,{sessionId:t})},[e,A]),G=(0,s.useCallback)(t=>{A(e,{title:t})},[e,A]),Y=(0,s.useCallback)(t=>{A(e,{bot:t??void 0})},[e,A]),Z=(0,s.useCallback)(t=>{a?.(e,t)},[e,a]),X=(0,s.useCallback)(t=>{i?.(e,t)},[e,i]),ee=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),et=(0,s.useCallback)(t=>{m?.(e,t)},[e,m]),er=(0,s.useCallback)(t=>{h?.(e,t)},[e,h]),en=(0,s.useCallback)(t=>{p?.(e,t)},[e,p]),es=(0,s.useCallback)(t=>{b?.(e,t)},[e,b]),eo=(0,s.useCallback)(t=>{j?.(e,t)},[e,j]),ea=(0,s.useCallback)(t=>{k?.(e,t)},[e,k]),el=(0,s.useCallback)(t=>{N?.(e,t)},[e,N]),ei=(0,s.useCallback)(t=>{S?.(e,t)},[e,S]),ed=(0,s.useCallback)(t=>{L?.(e,t)},[e,L]),ec=(0,s.useCallback)(t=>{P?.(e,t)},[e,P]),eu=(0,s.useCallback)(t=>{T?.(e,t)},[e,T]),em=(0,s.useCallback)(()=>{O?.(e)},[e,O]);return(0,n.jsx)(s1,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,onEngineChange:Z,ollamaModel:l,onOllamaModelChange:X,deepseekModel:d,onDeepseekModelChange:ee,kimiModel:u,onKimiModelChange:et,glmModel:x,onGlmModelChange:er,claudeModel:f,onClaudeModelChange:en,claudeEffort:g,onClaudeEffortChange:es,claudeFastMode:v,onClaudeFastModeChange:eo,claudeThinking:w,onClaudeThinkingChange:ea,codexModel:y,onCodexModelChange:el,codexReasoningEffort:C,onCodexReasoningEffortChange:ei,planMode:M,onPlanModeChange:ed,noHistory:E,onNoHistoryChange:ec,outputStyle:$,onOutputStyleChange:eu,hideHeader:!0,hideSidebar:!0,isActive:R,isFocused:I,peerTabId:F,peerSide:B,refreshSignal:D,onLoadingChange:Q,onSessionIdChange:J,onTitleChange:G,onBotChange:Y,onShowGitStatus:H,onOpenNote:z,isFavorite:W,onToggleFavorite:r&&O?em:void 0,onCreateScheduledTask:_,onOpenSession:q,onContentSearch:V,onShowFileDiff:U,onOpenFileLink:K})}var s5=r(3292),s4=r(23121),s3=r(88292),s6=r(76900),s8=r(96472);function s9(e,t){if(!t.split)return{};let r=t.panes.indexOf(e);return -1===r?{}:{peerTabId:t.panes[1-r],peerSide:0===r?"right":"left"}}function s7({tabId:e,panes:t,activePane:r,row:s,maximized:a,onFocusPane:l,onClosePane:i,onToggleMaximize:d,children:c}){let{t:u}=(0,o.Bd)(),m=t.indexOf(e),x=t.length>1;return(0,n.jsxs)("div",{onMouseDownCapture:x?()=>l(m):void 0,style:s&&-1!==m&&!a?{order:m}:void 0,className:`group/pane ${function(e,t,r,n,s){let o=t.indexOf(e);if(-1===o)return"relative hidden";if(s)return"absolute inset-0 z-30 border-y border-y-transparent";if(!n)return"relative h-full block";let a=t.length>1?` border-y ${o===r?"border-y-brand":"border-y-transparent"}`:"";return`relative h-full flex-1 min-w-0${a}${o>0?" border-l border-border":""}`}(e,t,r,s,a)}`,children:[x&&-1!==m&&(0,n.jsxs)("div",{className:"absolute top-1 right-1 z-20 flex items-center gap-0.5 opacity-0 pointer-events-none transition-opacity focus-within:opacity-100 focus-within:pointer-events-auto group-hover/pane:opacity-100 group-hover/pane:pointer-events-auto",children:[(0,n.jsx)("button",{type:"button",onClick:()=>d(m),title:u(a?"chat.restorePane":"chat.maximizePane"),"aria-label":u(a?"chat.restorePane":"chat.maximizePane"),"aria-pressed":a,className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:a?(0,n.jsx)(nE.A,{className:"w-3.5 h-3.5"}):(0,n.jsx)(nP.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(m),title:u("chat.closePane"),"aria-label":u("chat.closePane"),className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),c]})}function oe({initialCwd:e,initialSessionId:t,initialBlank:r,initialView:a,initialFile:i,initialBubble:d}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(a??"agent"),[p,g]=(0,s.useState)(null),{tabs:v,activeTabId:j,activeTab:w,paneTabIds:k,activePane:y,toggleSideBySide:N,focusPane:C,closePane:S,unreadTabs:M,globalLoadingTabs:L,pageVisible:E,dragTabIndex:P,dragOverTabIndex:$,closeTab:T,closeAllTabs:R,switchTab:I,handleSelectSession:F,handleNewTab:B,handleNewCodexTab:D,handleNewKimiTab:A,handleNewGlmTab:H,handleNewOllamaTab:z,handleNewDeepseekTab:W,handleOpenSession:O,updateTabState:_,updateTabEngine:q,updateTabOllamaModel:V,updateTabDeepseekModel:U,updateTabKimiModel:K,updateTabGlmModel:Q,updateTabClaudeModel:J,updateTabClaudeEffort:G,updateTabClaudeFastMode:Y,updateTabClaudeThinking:Z,updateTabCodexModel:X,updateTabCodexReasoningEffort:ee,updateTabPlanMode:et,updateTabNoHistory:er,updateTabOutputStyle:en,handleTabDragStart:es,handleTabDragOver:ea,handleTabDrop:el,handleTabDragEnd:ei}=(0,nS.useTabState)({initialCwd:e,initialSessionId:t,initialBlank:r,activeView:x}),{isPinned:ed,pinSession:ec,unpinSession:eu}=(0,s5.P)(),{createTask:em}=(0,s4.nS)(),ex=(0,s.useCallback)(e=>{let t=v.find(t=>t.id===e);return!!t?.sessionId&&ed(t.sessionId)},[v,ed]),eh=(0,s.useCallback)(t=>{let r=v.find(e=>e.id===t);r?.sessionId&&(ed(r.sessionId)?eu(r.sessionId):ec(r.sessionId,r.cwd||e||"",r.title))},[v,ed,ec,eu,e]),[ef,ep]=(0,s.useState)(!1),[eg,ev]=(0,s.useState)(!1),[ej,ew]=(0,s.useState)(!1),[ek,ey]=(0,s.useState)(null),[eN,eC]=(0,s.useState)(!1),[eS,eM]=(0,s.useState)("tree"),[eL,eE]=(0,s.useState)(0),[eP,e$]=(0,s.useState)(null),[eT,eR]=(0,s.useState)(0),[eI,eF]=(0,s.useState)(i?{path:i,nonce:0}:null),[eB,eD]=(0,s.useState)(d?{commandId:d,nonce:0}:null),eA=(0,s.useRef)(()=>{}),[eH,ez]=(0,s.useState)(null),eW=null!==eH,eO=(0,s.useMemo)(()=>{let e;return{panes:e=eW?[j]:k,activePane:eW?0:y,row:e.length>1||eW,split:e.length>1,diffOrder:e.length}},[k,y,j,eW]),[e_,eq]=(0,s.useState)(null),[eV,eU]=(0,s.useState)();(0,s.useEffect)(()=>{window.parent.postMessage({type:"GET_PROJECT_NUMBER",cwd:e},"*")},[e]),(0,s.useEffect)(()=>{e&&!a&&u.t4.runPromiseExit((0,s6.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&h(t.activeView)}})},[e,a]);let[eK,eQ]=(0,s.useState)(!1),eJ=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(eJ.current=x,h("console"),eQ(!0)):(eQ(!1),eJ.current&&"console"!==eJ.current&&h(eJ.current),eJ.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[x]);let eG=(0,s.useCallback)(t=>{h(t),e&&(u.t4.runFork((0,s6.Yn)({cwd:e,settings:{activeView:t}}).pipe(eb.NWQ(()=>eb.rIH))),u.t4.runFork(eb.qIB(s3.d,r=>r.publish(c.n.ViewChange,{cwd:e,view:t}))))},[e]);(0,s.useEffect)(()=>{let e=()=>eG("console");return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[eG]);let eY=(0,s.useCallback)(async()=>{if(!e)return;let t=await u.t4.runPromiseExit((0,s6.b2)(e));if("Success"===t._tag){let r=t.value;if(eC(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&ey(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>eY())},[eY]);let eZ=(0,s.useCallback)(e=>{let{data:t}=e;Array.isArray(t)&&t.some(e=>"git"===e.type)&&eY()},[eY]);(0,eo.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:eZ,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),eG("agent")):"2"===e.key?(e.preventDefault(),eG("explorer")):"3"===e.key?(e.preventDefault(),eG("console")):"s"===e.key&&e.preventDefault())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{e&&window.parent!==window&&window.parent.postMessage({type:"SESSION_NUMBERS",cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*")},[e,v]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="PROJECT_NUMBER"&&"number"==typeof t.data?.projectNumber)return void eU(t.data.projectNumber);if(t.data?.type==="IFRAME_VISIBILITY"&&"number"==typeof t.data?.projectNumber&&eU(t.data.projectNumber),t.data?.type==="GET_SESSION_NUMBERS"&&t.data?.requestId&&e)return void window.parent.postMessage({type:"SESSION_NUMBERS",requestId:t.data.requestId,cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*");if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){F(r),n&&eG("agent");let t=v.find(e=>e.sessionId===r);t&&eq(e=>({sessionId:r,nonce:(e?.nonce??0)+1})),e&&!t?.isLoading&&(u.t4.runFork((0,s8.KJ)(e,r,"normal").pipe(eb.NWQ(()=>eb.rIH))),u.t4.runFork((0,s8.M2)(r).pipe(eb.NWQ(()=>eb.rIH))))}}t.data?.type==="OPEN_FILE"&&"string"==typeof t.data?.path&&eA.current({path:t.data.path}),t.data?.type==="FOCUS_CONSOLE_BUBBLE"&&"string"==typeof t.data?.commandId&&(eG("console"),eD(e=>({commandId:t.data.commandId,nonce:(e?.nonce??0)+1})))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[F,eG,e,v]);let eX=(0,s.useCallback)(()=>{eM("status"),eE(e=>e+1),eG("explorer")},[eG]),e0=(0,s.useCallback)(e=>{e$(e),eR(e=>e+1),eG("explorer")},[eG]),e1=(0,s.useCallback)(()=>eG("agent"),[eG]),[e2,e5]=(0,s.useState)(!1);(0,s.useEffect)(()=>{eW||e5(!1)},[eW]);let[e4,e3]=(0,s.useState)(!1),e6=e4&&eO.split?eO.panes[eO.activePane]??null:null;(0,s.useEffect)(()=>{eO.split||e3(!1)},[eO.split]);let e8=(0,s.useCallback)(e=>{e3(e=>!e),C(e)},[C]),e9=(0,s.useCallback)(()=>e5(e=>!e),[]),e7=(0,s.useCallback)(()=>ez(null),[]),te=(0,s.useRef)(null),tt=(0,s.useCallback)(e=>{let t=te.current;if(!t)return;let r=e.offset>0&&null!==e.target&&t.contains(e.target);if("move"===e.phase){if(!r)return;let n=Math.min(.5*e.offset,t.offsetWidth);t.style.transition="none",t.style.transform=`translateX(${n}px)`;return}r&&e.triggered?(t.style.transition="transform 140ms ease-out, opacity 140ms ease-out",t.style.transform="translateX(100%)",t.style.opacity="0",window.setTimeout(e7,140)):(t.style.transition="transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1)",t.style.transform="")},[e7]);(0,s.useEffect)(()=>{let e=te.current;e&&(e.style.transition="",e.style.transform="",e.style.opacity="")},[eH]);let tr=(0,s.useRef)(eW);(0,s.useEffect)(()=>{tr.current=eW},[eW]);let tn=(0,s.useRef)(e6);(0,s.useEffect)(()=>{tn.current=e6},[e6]);let ts=(0,s.useCallback)(()=>{tr.current?e7():null!==tn.current?e3(!1):N()},[N,e7]),to=(0,s.useCallback)((e,t,r,n,s)=>{ez(o=>{var a;return a={messageId:e,toolCalls:t,cwd:r,sessionId:n},!0!==s?a:o?.messageId!==a.messageId?o:{...o,toolCalls:a.toolCalls}}),s||eG("agent")},[eG]),ta=(0,s.useCallback)(e=>{eF({...e,nonce:Date.now()}),eG("explorer")},[eG]);(0,s.useEffect)(()=>{eA.current=ta},[ta]);let tl=(0,s.useCallback)(()=>{e&&u.t4.runFork(eb.qIB(s3.d,t=>t.publish(c.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(ny.k_,{children:(0,n.jsx)(tI.fY,{activeView:x,onViewChange:eG,onOverscroll:tt,children:(0,n.jsxs)("div",{className:"flex h-screen bg-card",children:[(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,n.jsx)(nM.TabManagerTopBar,{initialCwd:e,activeTab:w,isGitRepo:eN,currentBranch:ek,onOpenWorktree:()=>ev(!0),onOpenAliasManager:()=>ew(!0),onBranchSwitched:eY}),eK&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-1 bg-brand/15 text-brand text-xs font-medium border-b border-brand/20",children:[(0,n.jsx)("span",{className:"animate-pulse",children:"●"}),m("console.screenshotting")]}),e?(0,n.jsxs)(tI.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(b.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,n.jsx)(nL.TabBar,{tabs:v,selectedTabId:j,sideBySide:eO.split,onToggleSideBySide:ts,unreadTabs:M,globalLoadingTabs:L,dragTabIndex:P,dragOverTabIndex:$,isPinned:ex,onSwitchTab:I,onCloseTab:T,onCloseAllTabs:R,onNewTab:B,onNewCodexTab:D,onNewKimiTab:A,onNewGlmTab:H,onNewOllamaTab:z,onNewDeepseekTab:W,onOpenProjectSessions:()=>ep(!0),onDragStart:es,onDragOver:ea,onDrop:el,onDragEnd:ei}),(0,n.jsx)(l,{value:eO.split?p:null,children:(0,n.jsxs)("div",{className:`flex-1 overflow-hidden relative ${eO.row?"flex":""}`,children:[v.map(e=>(0,n.jsx)(s7,{tabId:e.id,panes:eO.panes,activePane:eO.activePane,row:eO.row,maximized:e6===e.id,onFocusPane:C,onClosePane:S,onToggleMaximize:e8,children:(0,n.jsx)(s2,{tabId:e.id,...s9(e.id,eO),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:q,ollamaModel:e.ollamaModel,onOllamaModelChange:V,deepseekModel:e.deepseekModel,onDeepseekModelChange:U,kimiModel:e.kimiModel,onKimiModelChange:K,glmModel:e.glmModel,onGlmModelChange:Q,claudeModel:e.claudeModel,onClaudeModelChange:J,claudeEffort:e.claudeEffort,onClaudeEffortChange:G,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Y,claudeThinking:e.claudeThinking,onClaudeThinkingChange:Z,codexModel:e.codexModel,onCodexModelChange:X,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:ee,planMode:e.planMode,onPlanModeChange:et,noHistory:e.noHistory,onNoHistoryChange:er,outputStyle:e.outputStyle,onOutputStyleChange:en,isActive:nC(e.id,k,"agent"===x,E),isFocused:e.id===j,refreshSignal:e_,onStateChange:_,onShowGitStatus:eX,onContentSearch:e0,onShowFileDiff:to,onOpenFileLink:ta,onOpenNote:tl,isFavorite:ex(e.id),onToggleFavorite:eh,onCreateScheduledTask:em,onOpenSession:O})},e.id)),eH&&(0,n.jsx)("div",{ref:te,"data-diff-column":"",className:e2?"absolute inset-0 z-30 bg-card":"h-full flex-1 min-w-0 border-l border-border",style:e2?void 0:{order:eO.diffOrder},children:(0,n.jsx)(nN.e$,{toolCalls:eH.toolCalls,cwd:eH.cwd,sessionId:eH.sessionId,onClose:e7,onContentSearch:e0,fullscreen:e2,onToggleFullscreen:e9},eH.messageId)})]})}),eO.split&&(0,n.jsx)("div",{ref:g,className:"flex-shrink-0"})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden relative",children:(0,n.jsx)(b.a9,{children:(0,n.jsx)(tB,{onClose:e1,cwd:e,initialTab:eS,tabSwitchTrigger:eL,initialSearchQuery:eP,searchQueryTrigger:eT,fileOpenRequest:eI})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(b.a9,{children:(0,n.jsx)(nk,{cwd:e,tabId:"default",onOpenNote:tl,focusBubble:eB,isActive:"console"===x})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(nL.TabBar,{tabs:v,selectedTabId:j,sideBySide:eO.split,onToggleSideBySide:ts,unreadTabs:M,globalLoadingTabs:L,dragTabIndex:P,dragOverTabIndex:$,isPinned:ex,onSwitchTab:I,onCloseTab:T,onCloseAllTabs:R,onNewTab:B,onNewCodexTab:D,onNewKimiTab:A,onNewGlmTab:H,onNewDeepseekTab:W,onDragStart:es,onDragOver:ea,onDrop:el,onDragEnd:ei}),(0,n.jsx)(l,{value:eO.split?p:null,children:(0,n.jsx)("div",{className:`flex-1 overflow-hidden relative ${eO.row?"flex":""}`,children:v.map(e=>(0,n.jsx)(s7,{tabId:e.id,panes:eO.panes,activePane:eO.activePane,row:eO.row,maximized:e6===e.id,onFocusPane:C,onClosePane:S,onToggleMaximize:e8,children:(0,n.jsx)(s2,{tabId:e.id,...s9(e.id,eO),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:q,ollamaModel:e.ollamaModel,onOllamaModelChange:V,deepseekModel:e.deepseekModel,onDeepseekModelChange:U,kimiModel:e.kimiModel,onKimiModelChange:K,glmModel:e.glmModel,onGlmModelChange:Q,claudeModel:e.claudeModel,onClaudeModelChange:J,claudeEffort:e.claudeEffort,onClaudeEffortChange:G,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Y,claudeThinking:e.claudeThinking,onClaudeThinkingChange:Z,codexModel:e.codexModel,onCodexModelChange:X,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:ee,planMode:e.planMode,onPlanModeChange:et,noHistory:e.noHistory,onNoHistoryChange:er,outputStyle:e.outputStyle,onOutputStyleChange:en,isActive:nC(e.id,k,!0,E),isFocused:e.id===j,refreshSignal:e_,onStateChange:_,isFavorite:ex(e.id),onToggleFavorite:eh,onCreateScheduledTask:em,onOpenSession:O})},e.id))})}),eO.split&&(0,n.jsx)("div",{ref:g,className:"flex-shrink-0"})]})]}),e&&(0,n.jsx)(f,{isOpen:ef,onClose:()=>ep(!1),cwd:e,onSelectSession:F,projectNumber:eV,openSessionIds:v.map(e=>e.sessionId)}),e&&eN&&(0,n.jsx)(tD,{isOpen:eg,onClose:()=>ev(!1),cwd:e}),ej&&(0,n.jsx)(ns,{onClose:()=>ew(!1),onSave:()=>ew(!1)})]})})})}},96472:(e,t,r)=>{r.d(t,{KJ:()=>l,M2:()=>d,T$:()=>i,ej:()=>a,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.$mh({try:async()=>{let t=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"loadProjectState failed",cause:e})}),a=e=>n.$mh({try:async()=>{let t=await fetch("/api/project-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"saveProjectState failed",cause:e})}),l=(e,t,r)=>n.$mh({try:async()=>{let n=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r,action:"status"})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=(e,t)=>n.$mh({try:async()=>{let r=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,action:"touch"})});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:e=>new s.uV({message:"touchRecentSession failed",cause:e})}),d=e=>n.$mh({try:async()=>{let t=await fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:e}})});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"markScheduledTasksReadBySession failed",cause:e})})},96625:(e,t,r)=>{r.d(t,{V:()=>m,n:()=>u});var n=r(95155),s=r(12115),o=r(79114),a=r(58250),l=r(23348),i=r(33442),d=r(86957),c=r(83448);function u({value:e,onChange:t,textareaRef:r,extraCommands:n}){let[o,m]=(0,s.useState)(e.length),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)([]),[v,j]=(0,s.useState)(0),[w,k]=(0,s.useState)(()=>e.length>0),y=(0,s.useRef)(null);(0,s.useEffect)(()=>{d.t4.runPromiseExit((0,c.M5)()).then(e=>{"Success"===e._tag?h(e.value):console.error("Failed to load commands:",e.cause)})},[]);let N=(0,s.useCallback)(async()=>{let e=await d.t4.runPromiseExit((0,c.l1)());if("Success"===e._tag){let t=e.value.skills??e.value;p((Array.isArray(t)?t:[]).filter(e=>e.valid&&!!e.name).map(e=>({name:`/${e.name}`,description:e.description||"",source:"skill",skillPath:e.path,argumentHint:e.argumentHint})))}else console.error("Failed to load skills:",e.cause)},[]);(0,s.useEffect)(()=>(N(),(0,a.U)(N)),[N]);let C=(0,s.useCallback)(async()=>{let e=await d.t4.runPromiseExit((0,l.jm)());"Success"===e._tag?b(e.value.flatMap(e=>e.valid?[{name:`@${e.name}`,description:e.description,source:"bot"}]:[])):console.error("Failed to load bots:",e.cause)},[]);(0,s.useEffect)(()=>(C(),(0,i.a)(C)),[C]);let S=(0,s.useMemo)(()=>{let t=0===o?0:e.lastIndexOf("\n",o-1)+1,r=e.indexOf("\n",o),n=-1===r?e.length:r;return{text:e.slice(t,n),start:t,end:n}},[e,o]),M=(0,s.useMemo)(()=>{let e=S.text.match(/^\s*(\/@|\/|@)([a-zA-Z0-9-]*)$/);return e?{marker:e[1],verb:e[2].toLowerCase()}:null},[S.text]),L=(0,s.useMemo)(()=>{if(!M)return[];let{verb:e}=M,t=t=>t.name.slice(1).toLowerCase().startsWith(e);return"@"===M.marker?g.filter(t):[...(n??[]).filter(t),...x.filter(t),...f.filter(t)]},[M,n,x,f,g]),E=!w&&!!M&&L.length>0,P=(0,s.useRef)(e);(0,s.useLayoutEffect)(()=>{P.current!==e&&(queueMicrotask(()=>j(0)),w&&queueMicrotask(()=>k(!1)),P.current=e)},[e,w]),(0,s.useLayoutEffect)(()=>{if(E&&y.current){let e=y.current.children[v];e&&e.scrollIntoView({block:"nearest"})}},[v,E]);let $=(0,s.useCallback)(e=>{m(e.selectionStart??0)},[]),T=(0,s.useCallback)(n=>{let s=M?.marker??"/",o=`${s}${n.name.slice(1)} `,a=e.slice(0,S.start),l=e.slice(S.end),i=a.length+o.length;t(a+o+l),m(i),requestAnimationFrame(()=>{let e=r.current;e&&(e.focus(),e.setSelectionRange(i,i))})},[e,S,M,t,r]),R=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing||!E||0===L.length)return!1;let t=()=>{e.preventDefault(),e.stopPropagation()};return"ArrowDown"===e.key?(t(),j(e=>(e+1)%L.length),!0):"ArrowUp"===e.key?(t(),j(e=>(e-1+L.length)%L.length),!0):"Enter"===e.key||"Tab"===e.key?(t(),T(L[v]),!0):"Escape"===e.key&&(t(),k(!0),!0)},[E,L,v,T]);return{isOpen:E,items:L,selectedIndex:v,marker:M?.marker??"/",listRef:y,selectCommand:T,handleKeyDown:R,trackCaret:$}}function m({ac:e,className:t=""}){let{t:r}=(0,o.Bd)(),{isOpen:s,items:a,selectedIndex:l,marker:i,listRef:d,selectCommand:c}=e;return s&&0!==a.length?(0,n.jsx)("div",{ref:d,className:`overflow-y-auto bg-card border border-border rounded-lg shadow-lv2 ${t}`,children:a.map((e,t)=>{let s=t>0?a[t-1]:null,o="skill"===e.source&&(!s||"skill"!==s.source),d="bot"===e.source&&(!s||"bot"!==s.source),u="builtin"===e.source&&0===t;return(0,n.jsxs)("div",{children:[u&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Commands"}),o&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Skills"}),d&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Bots"}),(0,n.jsxs)("div",{onClick:()=>c(e),className:`px-4 py-2 cursor-pointer ${t===l?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:i+e.name.slice(1)}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:"builtin"===e.source?r(`commands.${e.name.slice(1)}`,{defaultValue:e.description}):e.description}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${(e=>{switch(e){case"builtin":return"bg-brand/15 text-brand dark:bg-brand/25 dark:text-teal-11";case"skill":return"bg-purple-9/15 text-purple-11 dark:bg-purple-9/25 dark:text-purple-11";case"bot":return"bg-teal-9/15 text-teal-11 dark:bg-teal-9/25 dark:text-teal-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return r("common.builtin");case"skill":return"Skill";case"bot":return"Bot"}})(e.source)})]}),"skill"===e.source&&e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 pl-0 truncate",children:e.argumentHint})]})]},e.name)})}):null}}}]);