@seqyuan/annovibe 0.8.92 → 0.8.93

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 (248) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +8 -7
  3. package/.next/build-manifest.json +2 -2
  4. package/.next/prerender-manifest.json +3 -3
  5. package/.next/required-server-files.js +1 -1
  6. package/.next/required-server-files.json +1 -1
  7. package/.next/routes-manifest.json +8 -0
  8. package/.next/server/app/_global-error/page.js +3 -3
  9. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  10. package/.next/server/app/_global-error.html +1 -1
  11. package/.next/server/app/_global-error.rsc +1 -1
  12. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  14. package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  15. package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  16. package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  17. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  18. package/.next/server/app/_not-found/page.js +2 -2
  19. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  20. package/.next/server/app/_not-found.html +1 -1
  21. package/.next/server/app/_not-found.rsc +1 -1
  22. package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  23. package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  24. package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  25. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  26. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  27. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  28. package/.next/server/app/api/agent/[id]/events/route.js +2 -2
  29. package/.next/server/app/api/agent/[id]/prepare/route.js +1 -0
  30. package/.next/server/app/api/agent/[id]/prepare/route_client-reference-manifest.js +1 -0
  31. package/.next/server/app/api/agent/[id]/route.js +1 -1
  32. package/.next/server/app/api/agent/new/route.js +1 -1
  33. package/.next/server/app/api/agent/runtime/route.js +1 -1
  34. package/.next/server/app/api/apps/[id]/[[...path]]/route.js +2 -2
  35. package/.next/server/app/api/apps/route.js +2 -2
  36. package/.next/server/app/api/auth/all-providers/route.js +1 -1
  37. package/.next/server/app/api/auth/api-key/[provider]/route.js +1 -1
  38. package/.next/server/app/api/auth/login/[provider]/route.js +1 -1
  39. package/.next/server/app/api/auth/login/route.js +1 -1
  40. package/.next/server/app/api/auth/logout/[provider]/route.js +1 -1
  41. package/.next/server/app/api/auth/providers/route.js +1 -1
  42. package/.next/server/app/api/auth/status/route.js +1 -1
  43. package/.next/server/app/api/auth/totp/route.js +1 -1
  44. package/.next/server/app/api/default-cwd/route.js +1 -1
  45. package/.next/server/app/api/files/[...path]/route.js +2 -2
  46. package/.next/server/app/api/harness/route.js +1 -1
  47. package/.next/server/app/api/home/route.js +1 -1
  48. package/.next/server/app/api/im/cancel/route.js +1 -1
  49. package/.next/server/app/api/im/gateway-status/route.js +1 -1
  50. package/.next/server/app/api/im/gateway-token/route.js +1 -1
  51. package/.next/server/app/api/im/project/route.js +2 -2
  52. package/.next/server/app/api/im/projects/route.js +2 -2
  53. package/.next/server/app/api/im/session-ids/route.js +1 -1
  54. package/.next/server/app/api/im/turn/route.js +2 -2
  55. package/.next/server/app/api/images/upload/route.js +1 -1
  56. package/.next/server/app/api/internal/runtime/route.js +1 -1
  57. package/.next/server/app/api/memory/dismiss/route.js +2 -2
  58. package/.next/server/app/api/memory/promote/route.js +2 -2
  59. package/.next/server/app/api/models/route.js +1 -1
  60. package/.next/server/app/api/models-config/discover/route.js +1 -1
  61. package/.next/server/app/api/models-config/route.js +1 -1
  62. package/.next/server/app/api/models-config/test/route.js +1 -1
  63. package/.next/server/app/api/plot-kernels/route.js +1 -1
  64. package/.next/server/app/api/plot-kernels/save/route.js +1 -1
  65. package/.next/server/app/api/plot-kernels/status/route.js +1 -1
  66. package/.next/server/app/api/plot-kernels/stop/route.js +1 -1
  67. package/.next/server/app/api/projects/browse/route.js +1 -1
  68. package/.next/server/app/api/projects/route.js +2 -2
  69. package/.next/server/app/api/search/route.js +1 -1
  70. package/.next/server/app/api/sessions/[id]/context/route.js +1 -1
  71. package/.next/server/app/api/sessions/[id]/kernel-state/route.js +1 -1
  72. package/.next/server/app/api/sessions/[id]/plan/route.js +2 -2
  73. package/.next/server/app/api/sessions/[id]/route.js +1 -1
  74. package/.next/server/app/api/sessions/[id]/workbench-artifact/route.js +1 -1
  75. package/.next/server/app/api/sessions/[id]/workbench-review/route.js +1 -1
  76. package/.next/server/app/api/sessions/new/route.js +1 -1
  77. package/.next/server/app/api/sessions/route.js +2 -2
  78. package/.next/server/app/api/settings/route.js +1 -1
  79. package/.next/server/app/api/skills/install/route.js +2 -2
  80. package/.next/server/app/api/skills/route.js +2 -2
  81. package/.next/server/app/api/skills/search/route.js +1 -1
  82. package/.next/server/app/api/soul/route.js +1 -1
  83. package/.next/server/app/api/subagents/status/route.js +1 -1
  84. package/.next/server/app/api/version/route.js +1 -1
  85. package/.next/server/app/favicon.ico/route.js +1 -1
  86. package/.next/server/app/icon.svg/route.js +1 -1
  87. package/.next/server/app/index.html +1 -1
  88. package/.next/server/app/index.rsc +2 -2
  89. package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  90. package/.next/server/app/index.segments/_full.segment.rsc +2 -2
  91. package/.next/server/app/index.segments/_head.segment.rsc +1 -1
  92. package/.next/server/app/index.segments/_index.segment.rsc +1 -1
  93. package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  94. package/.next/server/app/login/page.js +2 -2
  95. package/.next/server/app/login/page_client-reference-manifest.js +1 -1
  96. package/.next/server/app/login.html +1 -1
  97. package/.next/server/app/login.rsc +1 -1
  98. package/.next/server/app/login.segments/_full.segment.rsc +1 -1
  99. package/.next/server/app/login.segments/_head.segment.rsc +1 -1
  100. package/.next/server/app/login.segments/_index.segment.rsc +1 -1
  101. package/.next/server/app/login.segments/_tree.segment.rsc +1 -1
  102. package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
  103. package/.next/server/app/login.segments/login.segment.rsc +1 -1
  104. package/.next/server/app/page.js +28 -28
  105. package/.next/server/app/page_client-reference-manifest.js +1 -1
  106. package/.next/server/app/smoke/page.js +3 -3
  107. package/.next/server/app/smoke/page_client-reference-manifest.js +1 -1
  108. package/.next/server/app/smoke.html +1 -1
  109. package/.next/server/app/smoke.rsc +1 -1
  110. package/.next/server/app/smoke.segments/_full.segment.rsc +1 -1
  111. package/.next/server/app/smoke.segments/_head.segment.rsc +1 -1
  112. package/.next/server/app/smoke.segments/_index.segment.rsc +1 -1
  113. package/.next/server/app/smoke.segments/_tree.segment.rsc +1 -1
  114. package/.next/server/app/smoke.segments/smoke/__PAGE__.segment.rsc +1 -1
  115. package/.next/server/app/smoke.segments/smoke.segment.rsc +1 -1
  116. package/.next/server/app-paths-manifest.json +8 -7
  117. package/.next/server/middleware-build-manifest.js +1 -1
  118. package/.next/server/pages/404.html +1 -1
  119. package/.next/server/pages/500.html +1 -1
  120. package/.next/server/server-reference-manifest.json +1 -1
  121. package/.next/static/chunks/app/_global-error/page-fa0c1cd2174c1f0b.js +1 -0
  122. package/.next/static/chunks/app/api/agent/[id]/events/route-fa0c1cd2174c1f0b.js +1 -0
  123. package/.next/static/chunks/app/api/agent/[id]/prepare/route-fa0c1cd2174c1f0b.js +1 -0
  124. package/.next/static/chunks/app/api/agent/[id]/route-fa0c1cd2174c1f0b.js +1 -0
  125. package/.next/static/chunks/app/api/agent/new/route-fa0c1cd2174c1f0b.js +1 -0
  126. package/.next/static/chunks/app/api/agent/runtime/route-fa0c1cd2174c1f0b.js +1 -0
  127. package/.next/static/chunks/app/api/apps/[id]/[[...path]]/route-fa0c1cd2174c1f0b.js +1 -0
  128. package/.next/static/chunks/app/api/apps/route-fa0c1cd2174c1f0b.js +1 -0
  129. package/.next/static/chunks/app/api/auth/all-providers/route-fa0c1cd2174c1f0b.js +1 -0
  130. package/.next/static/chunks/app/api/auth/api-key/[provider]/route-fa0c1cd2174c1f0b.js +1 -0
  131. package/.next/static/chunks/app/api/auth/login/[provider]/route-fa0c1cd2174c1f0b.js +1 -0
  132. package/.next/static/chunks/app/api/auth/login/route-fa0c1cd2174c1f0b.js +1 -0
  133. package/.next/static/chunks/app/api/auth/logout/[provider]/route-fa0c1cd2174c1f0b.js +1 -0
  134. package/.next/static/chunks/app/api/auth/providers/route-fa0c1cd2174c1f0b.js +1 -0
  135. package/.next/static/chunks/app/api/auth/status/route-fa0c1cd2174c1f0b.js +1 -0
  136. package/.next/static/chunks/app/api/auth/totp/route-fa0c1cd2174c1f0b.js +1 -0
  137. package/.next/static/chunks/app/api/default-cwd/route-fa0c1cd2174c1f0b.js +1 -0
  138. package/.next/static/chunks/app/api/files/[...path]/route-fa0c1cd2174c1f0b.js +1 -0
  139. package/.next/static/chunks/app/api/harness/route-fa0c1cd2174c1f0b.js +1 -0
  140. package/.next/static/chunks/app/api/home/route-fa0c1cd2174c1f0b.js +1 -0
  141. package/.next/static/chunks/app/api/im/cancel/route-fa0c1cd2174c1f0b.js +1 -0
  142. package/.next/static/chunks/app/api/im/gateway-status/route-fa0c1cd2174c1f0b.js +1 -0
  143. package/.next/static/chunks/app/api/im/gateway-token/route-fa0c1cd2174c1f0b.js +1 -0
  144. package/.next/static/chunks/app/api/im/project/route-fa0c1cd2174c1f0b.js +1 -0
  145. package/.next/static/chunks/app/api/im/projects/route-fa0c1cd2174c1f0b.js +1 -0
  146. package/.next/static/chunks/app/api/im/session-ids/route-fa0c1cd2174c1f0b.js +1 -0
  147. package/.next/static/chunks/app/api/im/turn/route-fa0c1cd2174c1f0b.js +1 -0
  148. package/.next/static/chunks/app/api/images/upload/route-fa0c1cd2174c1f0b.js +1 -0
  149. package/.next/static/chunks/app/api/internal/runtime/route-fa0c1cd2174c1f0b.js +1 -0
  150. package/.next/static/chunks/app/api/memory/dismiss/route-fa0c1cd2174c1f0b.js +1 -0
  151. package/.next/static/chunks/app/api/memory/promote/route-fa0c1cd2174c1f0b.js +1 -0
  152. package/.next/static/chunks/app/api/models/route-fa0c1cd2174c1f0b.js +1 -0
  153. package/.next/static/chunks/app/api/models-config/discover/route-fa0c1cd2174c1f0b.js +1 -0
  154. package/.next/static/chunks/app/api/models-config/route-fa0c1cd2174c1f0b.js +1 -0
  155. package/.next/static/chunks/app/api/models-config/test/route-fa0c1cd2174c1f0b.js +1 -0
  156. package/.next/static/chunks/app/api/plot-kernels/route-fa0c1cd2174c1f0b.js +1 -0
  157. package/.next/static/chunks/app/api/plot-kernels/save/route-fa0c1cd2174c1f0b.js +1 -0
  158. package/.next/static/chunks/app/api/plot-kernels/status/route-fa0c1cd2174c1f0b.js +1 -0
  159. package/.next/static/chunks/app/api/plot-kernels/stop/route-fa0c1cd2174c1f0b.js +1 -0
  160. package/.next/static/chunks/app/api/projects/browse/route-fa0c1cd2174c1f0b.js +1 -0
  161. package/.next/static/chunks/app/api/projects/route-fa0c1cd2174c1f0b.js +1 -0
  162. package/.next/static/chunks/app/api/search/route-fa0c1cd2174c1f0b.js +1 -0
  163. package/.next/static/chunks/app/api/sessions/[id]/context/route-fa0c1cd2174c1f0b.js +1 -0
  164. package/.next/static/chunks/app/api/sessions/[id]/kernel-state/route-fa0c1cd2174c1f0b.js +1 -0
  165. package/.next/static/chunks/app/api/sessions/[id]/plan/route-fa0c1cd2174c1f0b.js +1 -0
  166. package/.next/static/chunks/app/api/sessions/[id]/route-fa0c1cd2174c1f0b.js +1 -0
  167. package/.next/static/chunks/app/api/sessions/[id]/workbench-artifact/route-fa0c1cd2174c1f0b.js +1 -0
  168. package/.next/static/chunks/app/api/sessions/[id]/workbench-review/route-fa0c1cd2174c1f0b.js +1 -0
  169. package/.next/static/chunks/app/api/sessions/new/route-fa0c1cd2174c1f0b.js +1 -0
  170. package/.next/static/chunks/app/api/sessions/route-fa0c1cd2174c1f0b.js +1 -0
  171. package/.next/static/chunks/app/api/settings/route-fa0c1cd2174c1f0b.js +1 -0
  172. package/.next/static/chunks/app/api/skills/install/route-fa0c1cd2174c1f0b.js +1 -0
  173. package/.next/static/chunks/app/api/skills/route-fa0c1cd2174c1f0b.js +1 -0
  174. package/.next/static/chunks/app/api/skills/search/route-fa0c1cd2174c1f0b.js +1 -0
  175. package/.next/static/chunks/app/api/soul/route-fa0c1cd2174c1f0b.js +1 -0
  176. package/.next/static/chunks/app/api/subagents/status/route-fa0c1cd2174c1f0b.js +1 -0
  177. package/.next/static/chunks/app/api/version/route-fa0c1cd2174c1f0b.js +1 -0
  178. package/.next/static/chunks/app/favicon.ico/route-fa0c1cd2174c1f0b.js +1 -0
  179. package/.next/static/chunks/app/page-130dbbfd958ed443.js +67 -0
  180. package/.next/static/chunks/next/dist/client/components/builtin/app-error-fa0c1cd2174c1f0b.js +1 -0
  181. package/.next/static/chunks/next/dist/client/components/builtin/forbidden-fa0c1cd2174c1f0b.js +1 -0
  182. package/.next/static/chunks/next/dist/client/components/builtin/not-found-fa0c1cd2174c1f0b.js +1 -0
  183. package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-fa0c1cd2174c1f0b.js +1 -0
  184. package/package.json +1 -1
  185. package/.next/static/chunks/app/_global-error/page-8ad668871a6e9fed.js +0 -1
  186. package/.next/static/chunks/app/api/agent/[id]/events/route-8ad668871a6e9fed.js +0 -1
  187. package/.next/static/chunks/app/api/agent/[id]/route-8ad668871a6e9fed.js +0 -1
  188. package/.next/static/chunks/app/api/agent/new/route-8ad668871a6e9fed.js +0 -1
  189. package/.next/static/chunks/app/api/agent/runtime/route-8ad668871a6e9fed.js +0 -1
  190. package/.next/static/chunks/app/api/apps/[id]/[[...path]]/route-8ad668871a6e9fed.js +0 -1
  191. package/.next/static/chunks/app/api/apps/route-8ad668871a6e9fed.js +0 -1
  192. package/.next/static/chunks/app/api/auth/all-providers/route-8ad668871a6e9fed.js +0 -1
  193. package/.next/static/chunks/app/api/auth/api-key/[provider]/route-8ad668871a6e9fed.js +0 -1
  194. package/.next/static/chunks/app/api/auth/login/[provider]/route-8ad668871a6e9fed.js +0 -1
  195. package/.next/static/chunks/app/api/auth/login/route-8ad668871a6e9fed.js +0 -1
  196. package/.next/static/chunks/app/api/auth/logout/[provider]/route-8ad668871a6e9fed.js +0 -1
  197. package/.next/static/chunks/app/api/auth/providers/route-8ad668871a6e9fed.js +0 -1
  198. package/.next/static/chunks/app/api/auth/status/route-8ad668871a6e9fed.js +0 -1
  199. package/.next/static/chunks/app/api/auth/totp/route-8ad668871a6e9fed.js +0 -1
  200. package/.next/static/chunks/app/api/default-cwd/route-8ad668871a6e9fed.js +0 -1
  201. package/.next/static/chunks/app/api/files/[...path]/route-8ad668871a6e9fed.js +0 -1
  202. package/.next/static/chunks/app/api/harness/route-8ad668871a6e9fed.js +0 -1
  203. package/.next/static/chunks/app/api/home/route-8ad668871a6e9fed.js +0 -1
  204. package/.next/static/chunks/app/api/im/cancel/route-8ad668871a6e9fed.js +0 -1
  205. package/.next/static/chunks/app/api/im/gateway-status/route-8ad668871a6e9fed.js +0 -1
  206. package/.next/static/chunks/app/api/im/gateway-token/route-8ad668871a6e9fed.js +0 -1
  207. package/.next/static/chunks/app/api/im/project/route-8ad668871a6e9fed.js +0 -1
  208. package/.next/static/chunks/app/api/im/projects/route-8ad668871a6e9fed.js +0 -1
  209. package/.next/static/chunks/app/api/im/session-ids/route-8ad668871a6e9fed.js +0 -1
  210. package/.next/static/chunks/app/api/im/turn/route-8ad668871a6e9fed.js +0 -1
  211. package/.next/static/chunks/app/api/images/upload/route-8ad668871a6e9fed.js +0 -1
  212. package/.next/static/chunks/app/api/internal/runtime/route-8ad668871a6e9fed.js +0 -1
  213. package/.next/static/chunks/app/api/memory/dismiss/route-8ad668871a6e9fed.js +0 -1
  214. package/.next/static/chunks/app/api/memory/promote/route-8ad668871a6e9fed.js +0 -1
  215. package/.next/static/chunks/app/api/models/route-8ad668871a6e9fed.js +0 -1
  216. package/.next/static/chunks/app/api/models-config/discover/route-8ad668871a6e9fed.js +0 -1
  217. package/.next/static/chunks/app/api/models-config/route-8ad668871a6e9fed.js +0 -1
  218. package/.next/static/chunks/app/api/models-config/test/route-8ad668871a6e9fed.js +0 -1
  219. package/.next/static/chunks/app/api/plot-kernels/route-8ad668871a6e9fed.js +0 -1
  220. package/.next/static/chunks/app/api/plot-kernels/save/route-8ad668871a6e9fed.js +0 -1
  221. package/.next/static/chunks/app/api/plot-kernels/status/route-8ad668871a6e9fed.js +0 -1
  222. package/.next/static/chunks/app/api/plot-kernels/stop/route-8ad668871a6e9fed.js +0 -1
  223. package/.next/static/chunks/app/api/projects/browse/route-8ad668871a6e9fed.js +0 -1
  224. package/.next/static/chunks/app/api/projects/route-8ad668871a6e9fed.js +0 -1
  225. package/.next/static/chunks/app/api/search/route-8ad668871a6e9fed.js +0 -1
  226. package/.next/static/chunks/app/api/sessions/[id]/context/route-8ad668871a6e9fed.js +0 -1
  227. package/.next/static/chunks/app/api/sessions/[id]/kernel-state/route-8ad668871a6e9fed.js +0 -1
  228. package/.next/static/chunks/app/api/sessions/[id]/plan/route-8ad668871a6e9fed.js +0 -1
  229. package/.next/static/chunks/app/api/sessions/[id]/route-8ad668871a6e9fed.js +0 -1
  230. package/.next/static/chunks/app/api/sessions/[id]/workbench-artifact/route-8ad668871a6e9fed.js +0 -1
  231. package/.next/static/chunks/app/api/sessions/[id]/workbench-review/route-8ad668871a6e9fed.js +0 -1
  232. package/.next/static/chunks/app/api/sessions/new/route-8ad668871a6e9fed.js +0 -1
  233. package/.next/static/chunks/app/api/sessions/route-8ad668871a6e9fed.js +0 -1
  234. package/.next/static/chunks/app/api/settings/route-8ad668871a6e9fed.js +0 -1
  235. package/.next/static/chunks/app/api/skills/install/route-8ad668871a6e9fed.js +0 -1
  236. package/.next/static/chunks/app/api/skills/route-8ad668871a6e9fed.js +0 -1
  237. package/.next/static/chunks/app/api/skills/search/route-8ad668871a6e9fed.js +0 -1
  238. package/.next/static/chunks/app/api/soul/route-8ad668871a6e9fed.js +0 -1
  239. package/.next/static/chunks/app/api/subagents/status/route-8ad668871a6e9fed.js +0 -1
  240. package/.next/static/chunks/app/api/version/route-8ad668871a6e9fed.js +0 -1
  241. package/.next/static/chunks/app/favicon.ico/route-8ad668871a6e9fed.js +0 -1
  242. package/.next/static/chunks/app/page-95a20c639bd2605d.js +0 -67
  243. package/.next/static/chunks/next/dist/client/components/builtin/app-error-8ad668871a6e9fed.js +0 -1
  244. package/.next/static/chunks/next/dist/client/components/builtin/forbidden-8ad668871a6e9fed.js +0 -1
  245. package/.next/static/chunks/next/dist/client/components/builtin/not-found-8ad668871a6e9fed.js +0 -1
  246. package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-8ad668871a6e9fed.js +0 -1
  247. /package/.next/static/{YyOm-oLPna9JyGTclkwP_ → LGbNm6rizDBchmYepXdui}/_buildManifest.js +0 -0
  248. /package/.next/static/{YyOm-oLPna9JyGTclkwP_ → LGbNm6rizDBchmYepXdui}/_ssgManifest.js +0 -0
@@ -1,67 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{43322:(e,t,r)=>{Promise.resolve().then(r.bind(r,96643))},96643:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>nB});var n=r(95155),i=r(12115),o=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"..."+n+i.slice(-2).join(n)}function s(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function a({open:e,cwd:t,homeDir:r,onClose:o,onSelectSession:d}){let[c,p]=(0,i.useState)(""),[u,h]=(0,i.useState)("current"),[x,g]=(0,i.useState)([]),[f,v]=(0,i.useState)(!1),[m,y]=(0,i.useState)(null),[b,j]=(0,i.useState)(!1),k=(0,i.useRef)(null);if((0,i.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&o()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,o]),(0,i.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),y(null),j(!1);return}let n=new AbortController,i=setTimeout(async()=>{v(!0),y(null);try{let e=new URLSearchParams({q:r,scope:u});t&&e.set("cwd",t);let i=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();if(o.error)throw Error(o.error);g(o.results??[]),j(o.truncated??!1)}catch(e){"AbortError"!==e.name&&y(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(i),n.abort()}},[e,c,u,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&o()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>p(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:o,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:u===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":u===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===u&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),m&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:m}),w.length>=2&&!f&&!m&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:s(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:s(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let i=e.toLowerCase().indexOf(r.toLowerCase());return i<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,i),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(i,i+r.length)}),e.slice(i+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${b?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function d({open:e,initialPath:t,onClose:r,onSelect:o}){let[l,s]=(0,i.useState)(""),[a,c]=(0,i.useState)(null),[p,u]=(0,i.useState)([]),[h,x]=(0,i.useState)([]),[g,f]=(0,i.useState)(""),[v,m]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null),j=(0,i.useCallback)(async e=>{m(!0),b(null);try{let t=e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",r=await fetch(t),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);s(n.current??""),c(n.parent??null),u(n.directories??[]),x(n.drives??[]),f(n.current??"")}catch(e){b(e instanceof Error?e.message:String(e))}finally{m(!1)}},[]);return((0,i.useEffect)(()=>{e&&j(t||void 0)},[j,t,e]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e]),e)?(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Select project path"}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Server filesystem"})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault();let t=g.trim();t&&o(t)},style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:g,onChange:e=>f(e.target.value),placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>{let e=g.trim();e&&j(e)},disabled:!g.trim()||v,style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:g.trim()&&!v?"var(--text-muted)":"var(--text-dim)",cursor:g.trim()&&!v?"pointer":"default",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"submit",disabled:!g.trim(),style:{height:32,padding:"0 11px",border:"none",borderRadius:6,background:g.trim()?"var(--accent)":"var(--bg-hover)",color:g.trim()?"#fff":"var(--text-dim)",cursor:g.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use Path"})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>a&&void j(a),disabled:!a,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:a?"var(--bg)":"transparent",color:a?"var(--text-muted)":"var(--text-dim)",cursor:a?"pointer":"default",padding:0},title:"Up",children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 6.5 5 3.5 8 6.5"})})}),h.length>0&&(0,n.jsxs)("select",{value:h.find(e=>l.toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&j(e.target.value)},style:{height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("option",{value:"",children:"Drive"}),h.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:l,children:l})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:v?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):y?(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:y}):0===p.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):p.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void j(e.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},title:e.path,children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path))}),(0,n.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l,children:l}),(0,n.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>l&&o(l),disabled:!l,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:l?"var(--accent)":"var(--bg-hover)",color:l?"#fff":"var(--text-dim)",cursor:l?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}let c="AnnoVibe",p="annovibe:sidebar:collapsed-projects",u="annovibe:sidebar:collapsed-projects:init-v3";function h(e){window.localStorage.setItem(p,JSON.stringify([...e]))}async function x(e,t){let r=`${e}: HTTP ${t.status}`;try{let n=await t.json();return"string"==typeof n.error&&n.error?`${e}: ${n.error}`:r}catch{return r}}function g(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),i=Math.floor(r/36e5),o=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:i<24?`${i}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}function f(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"…/"+i.slice(-2).join(n)}function v(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||f(e,t)}let m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function y(){let[e,t]=(0,i.useState)(!1),[r,o]=(0,i.useState)(!1),l=(0,i.useRef)(null),s=function(e,t){let[r,n]=(0,i.useState)(e),o=(0,i.useRef)(null),l=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,i=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:m[Math.floor(Math.random()*m.length)]).join("")),l.current<r?o.current=requestAnimationFrame(i):n(e)};return o.current=requestAnimationFrame(i),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),r}(e?"v0.8.92":c,r),a=(0,i.useCallback)(e=>{t(e),o(!0),setTimeout(()=>o(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,i.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,i.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:s})}function b({selectedSessionId:e,onSelectSession:t,onNewSession:r,onNewWorkbench:o,initialSessionId:l,onInitialRestoreDone:s,refreshKey:c,onSessionDeleted:g,selectedCwd:m,onCwdChange:T}){let[z,I]=(0,i.useState)([]),[M,R]=(0,i.useState)([]),[W,L]=(0,i.useState)(!0),[E,$]=(0,i.useState)(null),[P,D]=(0,i.useState)(null),[A,B]=(0,i.useState)(""),[N,O]=(0,i.useState)(null),[H,F]=(0,i.useState)(!1),[_,U]=(0,i.useState)("project"),[K,J]=(0,i.useState)(null),[V,q]=(0,i.useState)(!1),[Y,G]=(0,i.useState)(!1),[Z,X]=(0,i.useState)(()=>new Set),[Q,ee]=(0,i.useState)(()=>(function(){try{let e=window.localStorage.getItem(p)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[et,er]=(0,i.useState)(null),[en,ei]=(0,i.useState)(null),[eo,el]=(0,i.useState)(null),[es,ea]=(0,i.useState)(!1),ed=(0,i.useRef)(null),[ec,ep]=(0,i.useState)(!1),eu=(0,i.useRef)(!1),eh=(0,i.useRef)(!1),ex=(0,i.useRef)(!1),eg=(0,i.useCallback)(async(e=!1)=>{try{e&&($(null),L(!0));let t=new AbortController,r=setTimeout(()=>t.abort(new DOMException("Loading timed out","TimeoutError")),3e4),n=await fetch("/api/projects?sessions=false",{signal:t.signal});if(!n.ok)throw Error(await x("projects",n));let i=await n.json(),o=i.projects.filter(e=>!0===e.pinned).map(e=>e.cwd),l=ek.current,s=l&&o.includes(l)?o:l?[...o,l]:o,a=[];if(s.length>0){let e=s.map(e=>encodeURIComponent(e)).join(","),r=await fetch(`/api/sessions?cwds=${e}`,{signal:t.signal});if(!r.ok)throw Error(await x("sessions",r));a=(await r.json()).sessions??[]}clearTimeout(r),I(a),R(i.projects),$(null)}catch(e){$(e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?"Loading timed out. Codex may still be starting; try the refresh button.":e instanceof Error?e.message:String(e))}finally{e&&L(!1)}},[]),ef=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!ef.current;ef.current=!0,eg(e)},[eg,c]),(0,i.useEffect)(()=>{let e=window.setInterval(()=>{eg(!1)},15e3);return()=>window.clearInterval(e)},[eg]),(0,i.useEffect)(()=>{let e=()=>{eg(!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[eg]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&B(e.home)}).catch(()=>{})},[]);let ev=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(eu.current){eu.current=!1;return}if(eh.current){eh.current=!1;return}T?.(P)},[P,T]);let em=(0,i.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return O(n.error??`HTTP ${r.status}`),!1;return eg(!1),!0}catch(e){return O(e instanceof Error?e.message:String(e)),!1}},[eg]),ey=(0,i.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),eb=(0,i.useCallback)(e=>{eh.current=!0,D(e),O(null),ee(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),h(r),r}),T?.(e),ey(e)},[T,ey]);(0,i.useEffect)(()=>{if((0!==z.length||0!==M.length)&&null===P){if(l&&!ev.current){ev.current=!0;let e=z.find(e=>e.id===l);if(e){D(e.cwd),ey(e.cwd),t(e,!0);return}s?.()}let e=M[0]?.cwd;e&&(D(e),ey(e))}},[z,M,P,l,t,s,ey]);let ej=m??P,ek=(0,i.useRef)(ej);ek.current=ej;let ew=(0,i.useCallback)(e=>{if(!e){U("agent"),F(!0);return}let t="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;r?.(t,e)},[r]),eS=(0,i.useCallback)(e=>{if(!e){U("workbench"),F(!0);return}o?.(e)},[o]),eC=(0,i.useCallback)(async e=>{await em(e,!0)&&(eb(e),F(!1),O(null),"agent"===_&&ew(e),"workbench"===_&&eS(e))},[eb,ew,eS,_,em]),eT=(0,i.useCallback)(e=>{J(e),q(!0)},[]),ez=(0,i.useCallback)(()=>{q(!1),J(null)},[]),eI=(0,i.useCallback)(e=>{let t=K??ej;ez(),"agent"===e?ew(t):eS(t)},[ez,ew,eS,ej,K]),eM=(0,i.useCallback)(()=>{eT(ej)},[ej,eT]),eR=(0,i.useCallback)(()=>{U("project"),O(null),F(!0)},[]),eW=(0,i.useMemo)(()=>[...ej&&!M.some(e=>e.cwd===ej)?[{cwd:ej,displayName:v(ej,A),chatCount:z.filter(e=>e.cwd===ej).length,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...M].sort((e,t)=>{let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n="number"==typeof e.sortOrder?e.sortOrder:Number.MAX_SAFE_INTEGER,i="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==i?n-i:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[z,ej,A,M]),eL=(0,i.useMemo)(()=>{let e=new Map;for(let t of z){let r=t.cwd||"";e.has(r)||e.set(r,[]),e.get(r).push(t)}let t=t=>{let r=[...e.get(t.cwd)??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||""));return{project:t,cwd:t.cwd,displayName:t.displayName||v(t.cwd,A),sessions:r,lastAccessed:(t.lastAccessed??t.created??"")||r[0]?.modified||""}},r=eW.filter(e=>!0===e.pinned).map(t);if(ej){let e=eW.find(e=>e.cwd===ej);e&&!0!==e.pinned&&r.push(t(e))}return r},[z,ej,A,eW]);(0,i.useEffect)(()=>{if(0===eL.length||ex.current||(ex.current=!0,!eL[0]?.cwd||window.localStorage.getItem(u)))return;let e=new Set(eL.slice(1).map(e=>e.cwd));ee(t=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(t,e)?(h(e),e):t),window.localStorage.setItem(u,"1")},[eL]);let eE=(0,i.useCallback)((e,r=!1)=>{e.cwd!==ej&&(eu.current=!0,D(e.cwd)),ee(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),h(r),r}),ey(e.cwd),t(e,r)},[t,ej,ey]),e$=(0,i.useCallback)(e=>{ee(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),h(r),r})},[]),eP=(0,i.useCallback)(e=>{X(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eD=(0,i.useCallback)(async e=>{el("reorder");try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:e})}),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);R(r.projects??[]),$(null)}catch(e){$(e instanceof Error?e.message:String(e)),eg(!1)}finally{el(null)}},[eg]),eA=(0,i.useCallback)(async(e,t)=>{el(`pin:${e}`);try{let r=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,pinned:t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);R(n.projects??[]),$(null)}catch(e){$(e instanceof Error?e.message:String(e)),eg(!1)}finally{el(null)}},[eg]),eB=(0,i.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eW.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),i=r.indexOf(t);if(-1===n||-1===i)return;let o=[...r];o.splice(n,1);let l=o.indexOf(t);o.splice(l,0,e),eD(o)},[eD,eW]),eN=(0,i.useCallback)(async()=>{ep(!0);try{let e=eW.filter(e=>!0===e.pinned).map(e=>e.cwd);e.length>0?await Promise.all(e.map(e=>fetch(`/api/sessions?cwd=${encodeURIComponent(e)}`,{signal:AbortSignal.timeout(3e4)}).then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(t=>{I(r=>[...r.filter(t=>t.cwd!==e),...t.sessions??[]])}).catch(()=>{}))):await eg(!1)}finally{ep(!1)}},[eg,eW]);return(0,i.useEffect)(()=>{if(!es)return;let e=e=>{ed.current&&!ed.current.contains(e.target)&&ea(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[es]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)(y,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eM,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",height:32,paddingLeft:10,paddingRight:12,borderRadius:7,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:ej?`New chat in ${ej}`:"New chat in a project path",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New Chat"]}),(0,n.jsx)("button",{onClick:()=>G(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:"Search conversations",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,n.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]})})]})]})}),(0,n.jsx)(a,{open:Y,cwd:ej,homeDir:A,onClose:()=>G(!1),onSelectSession:e=>{eE(e)}}),(0,n.jsxs)("div",{ref:ed,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>ea(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:ej?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:ej?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:ej??"Select project",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:ej?"var(--text)":"var(--text-dim)"},children:ej?eW.find(e=>e.cwd===ej)?.displayName??f(ej,A):"Select project…"}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:es?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),ej&&(0,n.jsx)(k,{pinned:eW.find(e=>e.cwd===ej)?.pinned===!0,onToggle:()=>void eA(ej,eW.find(e=>e.cwd===ej)?.pinned!==!0)}),es&&(0,n.jsxs)("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:10,right:10,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:280,overflowY:"auto"},children:[0===eW.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eW.map(e=>{let t=e.cwd===ej;return(0,n.jsx)(w,{project:e,homeDir:A,isCurrent:t,onSelect:()=>{eb(e.cwd),ea(!1)},onTogglePinned:()=>void eA(e.cwd,!0!==e.pinned)},e.cwd)}),(0,n.jsxs)("button",{type:"button",onClick:()=>{ea(!1),eR()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eW.length>0?"1px solid var(--border)":"none",color:"var(--accent)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"Add project…"]})]})]}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"10px 10px 6px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase"},children:"Projects"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:[(0,n.jsx)("button",{type:"button",onClick:eN,disabled:ec,title:"Refresh projects and chats","aria-label":"Refresh projects and chats",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:ec?"var(--accent)":"var(--text-dim)",cursor:ec?"default":"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:ec?"spin 0.9s linear infinite":void 0},children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,n.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,n.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,n.jsxs)("button",{type:"button",onClick:eR,title:"New project","aria-label":"New project",style:{height:26,display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"0 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,transition:"background 0.12s, color 0.12s, border-color 0.12s",flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v4.5A1.5 1.5 0 0 1 13 12H3a1.5 1.5 0 0 1-1.5-1.5v-6Z"}),(0,n.jsx)("path",{d:"M11 7v3M9.5 8.5h3"})]}),"New Project"]})]})]}),N&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:N})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[W&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),E&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:E}),!W&&!E&&0===eL.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!W&&!E&&eL.map(t=>{let r=Q.has(t.cwd),i=t.cwd===ej,o=Z.has(t.cwd),l=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let i=function(e){let n=r.get(e),i=new Set;for(;n&&!i.has(n);){if(i.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);i?t.get(i).children.push(e):n.push(e)}let i=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>i(e.children))};return i(n),n}(t.sessions),s=l.length,a=l;if(s>10&&!o){a=l.slice(0,10);let t=l.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!a.includes(t)&&(a=[...a,t])}let d=s-a.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:en===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(en===t.cwd),opacity:et===t.cwd?.55:1},onDragOver:e=>{et&&et!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",ei(t.cwd))},onDragLeave:()=>{en===t.cwd&&ei(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||et;ei(null),er(null),r&&eB(r,t.cwd)},children:[(0,n.jsx)(S,{group:t,isCurrent:i,isCollapsed:r,isDragging:et===t.cwd,pinBusy:eo===`pin:${t.cwd}`,onToggle:()=>e$(t.cwd),onSelect:()=>eb(t.cwd),onTogglePinned:()=>void eA(t.cwd,!0!==t.project.pinned),onDragStart:e=>{er(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{er(null),ei(null)}}),!r&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[0===t.sessions.length?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-muted)",textAlign:"left",fontSize:12},children:"No sessions yet. Use New Chat above to start one."}):a.map(t=>(0,n.jsx)(C,{node:t,selectedSessionId:e,onSelectSession:eE,onRenamed:eg,onSessionDeleted:e=>{g?.(e),eg()},depth:0},t.session.id)),(o||d>0)&&s>10&&(0,n.jsx)("button",{type:"button",onClick:()=>eP(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:o?"Show less":`Show ${Math.max(0,d)} more`})]})]},t.cwd||"__no_project")})]}),V&&(0,n.jsx)(j,{cwd:K,onChoose:eI,onClose:ez}),(0,n.jsx)(d,{open:H,initialPath:ej,onClose:()=>F(!1),onSelect:e=>eC(e)})]})}function j({cwd:e,onChoose:t,onClose:r}){let i=e?v(e):"Choose a project path next";return(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.28)"},children:(0,n.jsxs)("div",{style:{width:"min(420px, 100%)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"14px 16px 12px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Start a new session"}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11},children:"Current project"}),(0,n.jsx)("div",{title:e??void 0,style:{marginTop:2,color:"var(--text)",fontSize:12,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),e&&(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},children:"x"})]}),(0,n.jsxs)("div",{style:{padding:14,display:"grid",gap:10},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>t("agent"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750},children:"Agent Chat"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"General coding or analysis chat in this project."})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>t("workbench"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:10,background:"rgba(37,99,235,0.08)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--accent)"},children:"Workbench"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"Dedicated R/Python warm-runtime session for data loading, plots, and artifacts."})]})]})]})})}function k({pinned:e,onToggle:t}){return(0,n.jsx)("button",{type:"button",onClick:t,title:e?"Unpin project":"Pin project to sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:"auto",padding:0,border:"1px solid var(--border)",borderRadius:7,background:e?"rgba(234,179,8,0.12)":"var(--bg-hover)",color:e?"#ca8a04":"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:e?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})}function w({project:e,homeDir:t,isCurrent:r,onSelect:o,onTogglePinned:l}){let[s,a]=(0,i.useState)(!1),d=e.displayName||v(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":s?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,n.jsxs)("button",{type:"button",onClick:o,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin to sidebar",tabIndex:s?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,marginRight:4,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!s,pointerEvents:s?"auto":"none"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})]})}function S({group:e,isCurrent:t,isCollapsed:r,isDragging:o,pinBusy:l,onToggle:s,onSelect:a,onTogglePinned:d,onDragStart:c,onDragEnd:p}){let[u,h]=(0,i.useState)(!1),x=e.lastAccessed,f=Math.max(0,e.project.chatCount??e.sessions.length??0),v=!0===e.project.pinned,m=(0,i.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:m,onDragStart:c,onDragEnd:p,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),m())},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":u?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:o?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:o?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!u&&f>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[f," ",1===f?"chat":"chats"]}),!u&&x&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:g(x)}),v?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:u?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:u?1:.85,transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:"Pin project to sidebar",tabIndex:u?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:+!!u,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:u?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function C({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s}){let[a,d]=(0,i.useState)(!1),c=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[s>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*s+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(T,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:o,onDeleted:e=>l?.(e),depth:s,hasChildren:c,collapsed:a,onToggleCollapse:()=>d(e=>!e)})]}),c&&!a&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(C,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function T({session:e,isSelected:t,onClick:r,onRenamed:o,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let[p,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(!1),[f,v]=(0,i.useState)(""),[m,y]=(0,i.useState)(!1),[b,j]=(0,i.useState)(!1),k=(0,i.useRef)(null),w=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),S=(0,i.useCallback)(t=>{t.stopPropagation(),v(e.name??""),x(!0),setTimeout(()=>k.current?.select(),0)},[e.name]),C=(0,i.useCallback)(async()=>{let t=f.trim();if(x(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),o?.()}catch{}},[f,e.id,e.name,o]),z=(0,i.useCallback)(e=>{e.stopPropagation(),y(!0)},[]),I=(0,i.useCallback)(async t=>{t.stopPropagation(),y(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),M=(0,i.useCallback)(e=>{e.stopPropagation(),y(!1)},[]),R="workbench"===e.sessionKind;return(0,n.jsx)("div",{onClick:m||h?void 0:r,onMouseEnter:()=>u(!0),onMouseLeave:()=>{u(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:m||h?"default":"pointer",background:m?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",borderLeft:m?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:b?.5:1,gap:6,overflow:"hidden"},children:m?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",w.slice(0,22),w.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:I,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,n.jsx)("button",{onClick:M,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):h?(0,n.jsx)("input",{ref:k,value:f,onChange:e=>v(e.target.value),onBlur:C,onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&x(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,n.jsxs)(n.Fragment,{children:[s>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),0===s&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:5,height:5,borderRadius:"50%",background:t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0}}),R&&(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:t?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:R?"var(--accent)":"var(--text)"},title:w,children:w}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:g(e.modified)}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]}),!1===e.cwdExists&&(0,n.jsx)("span",{title:`Project path missing: ${e.cwd}`,style:{color:"#f87171"},children:"missing path"})]})]}),a&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c?.()},title:d?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:d?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),p&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:S,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,n.jsx)("button",{onClick:z,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var z=r(94456);let I="subagent",M=["retain","recall","reflect"],R=[],W=["read","bash","edit","write"],L=["bash","read","edit","write","grep","find","ls"],E=[...L,"kernel_plot_run","kernel_plot_render","kernel_plot_inspect","kernel_plot_stop","kernel_plot_artifacts"],$=[...L,I];function P(e){return[...e].sort().join(",")}function D(e){switch(e){case"none":return R;case"default":return W;case"workbench":return E;case"agent":return $;default:return L}}function A(e,t){return[...new Set([...D(e),...t])]}let B=new Map,N=["off","default","full","agent"],O={off:"none",default:"default",full:"full",agent:"agent"},H={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},F={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},_=["auto","off","minimal","low","medium","high","xhigh"],U={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},K=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function J({doc:e,onRemove:t}){var r;let i=e.fileName.split(".").pop()?.toLowerCase()??"",o=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(i),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:o.color,fontSize:14,flexShrink:0},children:o.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[i.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function V(e){return e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&apos;/g,"'")}async function q(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,i=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&i.push(`Page ${e}
2
- ${r}`)}return i.join("\n\n")}async function Y(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),i=["word/document.xml",...Object.keys(n.files).filter(e=>/^word\/(footnotes|endnotes|comments)\.xml$/i.test(e)).sort()],o=[];for(let e of i){let t=n.file(e);if(!t)continue;let r=[...(await t.async("string")).replace(/<w:(br|cr)[^>]*\/>/g,"\n").replace(/<\/w:p>/g,"\n").matchAll(/<w:t[^>]*>([\s\S]*?)<\/w:t>/g)];o.push(...r.map(e=>V(e[1])))}return o.join("").replace(/[ \t]+\n/g,"\n")}async function G(e){let t=await Promise.all([r.e(3524),r.e(8436)]).then(r.bind(r,15967)),n=t.read(e,{type:"array"});return n.SheetNames.map(e=>{let r=n.Sheets[e],i=t.utils.sheet_to_csv(r);return`Sheet: ${e}
3
- ${i}`}).join("\n\n")}async function Z(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),i=Object.keys(n.files).map(e=>({name:e,match:/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e)})).filter(e=>null!==e.match).sort((e,t)=>Number(e.match[1])-Number(t.match[1])),o=[];for(let{name:e,match:t}of i){let r=[...(await n.file(e).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(e=>V(e[1]).trim()).filter(Boolean);r.length&&o.push(`Slide ${t[1]}
4
- ${r.join("\n")}`)}return o.join("\n\n")}async function X(e,t){let r=e.name.split(".").pop()?.toLowerCase()??"";try{let n,i="";if(e.type.startsWith("text/")||["csv","tsv","md","txt","json","xml"].includes(r))i=new TextDecoder("utf-8").decode(t);else if("pdf"===r||"application/pdf"===e.type)i=await q(t);else if("docx"===r)i=await Y(t);else if("xlsx"===r)i=await G(t);else{if("pptx"!==r)return{extractionError:"Text extraction is not supported for this file type"};i=await Z(t)}let{text:o,truncated:l}=(n=i.replace(/\r\n/g,"\n").replace(/\n{4,}/g,"\n\n\n").trim()).length<=6e4?{text:n,truncated:!1}:{text:`${n.slice(0,6e4)}
5
-
6
- [truncated after 60000 characters]`,truncated:!0};if(!o)return{extractionError:"No extractable text found"};return{extractedText:o,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let Q=(0,i.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:o,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:p,onAbortCompaction:u,isCompacting:h,compactError:x,toolPreset:g,sessionKind:f,onToolPresetChange:v,memoryTools:m,onMemoryToolsChange:y,thinkingLevel:b,onThinkingLevelChange:j,availableThinkingLevels:k,thinkingLevelMap:w,retryInfo:S,soundEnabled:C,onSoundToggle:T,planMode:z,onPlanModeChange:I,cornerBadge:R,promptHistory:W,sessionHistoryKey:L,activeFilePath:E,onDismissFileContext:$},P){let D,A,V,[q,Y]=(0,i.useState)(""),[G,Z]=(0,i.useState)(!1),[Q,ee]=(0,i.useState)(null),[et,er]=(0,i.useState)(!1),[en,ei]=(0,i.useState)(!1),[eo,el]=(0,i.useState)(!1),[es,ea]=(0,i.useState)(!1),[ed,ec]=(0,i.useState)(!1),[ep,eu]=(0,i.useState)(null),[eh,ex]=(0,i.useState)([]),[eg,ef]=(0,i.useState)([]),ev=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),em=ev?{display:"none"}:void 0,ey=ev?28:32,eb=ev?"6px 8px":"8px 12px",ej=ev?160:180,ek=ev&&!l,ew=ed?"var(--text)":"var(--text-muted)",eS={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},eC=ev?{position:"sticky",bottom:0,zIndex:30,padding:"8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px)",background:"linear-gradient(to top, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 86%, transparent))",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",borderTop:"1px solid color-mix(in srgb, var(--border) 65%, transparent)"}:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},[eT,ez]=(0,i.useState)(null),eI=(0,i.useRef)(null),eM=(0,i.useRef)(null),eR=(0,i.useRef)(null),eW=(0,i.useRef)(null),eL=(0,i.useRef)(null),eE=(0,i.useRef)(null),e$=(0,i.useRef)(null),eP=(0,i.useRef)(null),eD=(0,i.useRef)(null),eA=(0,i.useRef)(null),eB=(0,i.useCallback)(e=>{let t=eI.current;if(!t)return void Y(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,i=t.value.slice(0,r),o=t.value.slice(n),l=!(i.length>0)||i.endsWith(" ")||i.endsWith("\n")?"":" ";Y(i+l+e+o),requestAnimationFrame(()=>{let t=eI.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,i.useImperativeHandle)(P,()=>({insertIfEmpty(e){let t=eI.current;(t?t.value:q).trim()||(Y(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eB(e)},addImages(e){eN(e)},addFiles(e){eO(e)}}));let eN=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));ex(e=>[...e,...r])},[]),eO=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&eN(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,i=await X(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...i})},n.onerror=r,n.readAsArrayBuffer(e)})));ef(t=>[...t,...e])}},[eN]),eH=(0,i.useCallback)(e=>{ex(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eF=(0,i.useCallback)(e=>{ef(t=>{let r=[...t];return r.splice(e,1),r})},[]),e_=(0,i.useCallback)(()=>{ex(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ef([])},[]),eU=d&&d.length>0?d.map(e=>({provider:e.provider,modelId:e.id,name:e.name,input:e.input})):Object.entries(a??{}).map(([e,t])=>({provider:s?.provider??"unknown",modelId:e,name:t})),eK=[];for(let e of eU){let t=eK.find(t=>t.provider===e.provider);t?t.options.push(e):eK.push({provider:e.provider,options:[e]})}let eJ=s?eU.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:eU.length>0?eU[0].name:null,eV=s?eU.find(e=>e.modelId===s.modelId&&e.provider===s.provider):eU[0],eq=eV?.input?.includes("image")??!0,eY=eh.length>0&&eV?.input!==void 0&&!eq,eG=(!!q.trim()||eh.length>0||eg.length>0)&&!eY,eZ=p?K:K.filter(e=>"/compact"!==e.command),eX=eZ.filter(e=>"native"===e.kind),eQ=eZ.filter(e=>"shortcut"===e.kind),e0=m??[],e1=e0.length>0?`${e0.length} enabled`:"off",e2=eU.length>0&&!!eJ&&!!c,e5=!!j,e4=!!v&&"workbench"!==f,e3=!!y,e8=eJ??"Default",e6=(()=>{let e=b??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})(),e7=(g??"full")==="workbench"?"workbench":Object.entries(O).find(([,e])=>e===(g??"full"))?.[0]??"full",e9=ev?26:32,te=ev?7:9,tt=ev?3:6,tr={position:"fixed",left:8,right:8,bottom:"calc(env(safe-area-inset-bottom, 0px) + 8px)",zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 -6px 24px rgba(0,0,0,0.14)",overflow:"hidden",maxHeight:"min(60dvh, 420px)"},tn=ev&&(G||et||en||eo||es||ed);(0,i.useEffect)(()=>{eY||ez(null)},[eY]);let ti=(0,i.useCallback)(e=>{if(!q.trim()){Y(e),requestAnimationFrame(()=>{let t=eI.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eB(e)},[eB,q]),to=(0,i.useCallback)(()=>{let t=q.trim();if(t||eh.length||eg.length){if(eh.length&&!eq)return void ez("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!eh.length&&!eg.length&&p){h?u?.():p(),Y(""),eI.current&&(eI.current.style.height="auto");return}e(t,eh.length?eh:void 0,eg.length?eg:void 0),Y(""),e_(),eI.current&&(eI.current.style.height="auto")}}},[q,eh,eg,eq,l,e,e_,p,u,h]),tl=(0,i.useCallback)(e=>{let t=q.trim();if(!t&&!eh.length&&!eg.length)return;if(eh.length&&!eq)return void ez("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=eh.length?eh:void 0,i=eg.length?eg:void 0;"steer"===e&&r?r(t,n,i):"followup"===e&&o&&o(t,n,i),Y(""),e_(),eI.current&&(eI.current.style.height="auto")},[q,eh,eg,eq,r,o,e_]),ts=W??[],ta=L??null,td=(0,i.useCallback)(e=>{if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&ts.length>0){let t=eI.current;if(!t)return;let r=t.selectionStart??0;if(t.value.slice(0,r).includes("\n"))return;e.preventDefault();let n=function(e,t,r){let n;if(!e||0===r.length)return null;let i=((n=B.get(e))||(n={cursor:-1,draftSnapshot:""},B.set(e,n)),n);if(-1===i.cursor)i.draftSnapshot=t,i.cursor=0;else{if(!(i.cursor<r.length-1))return null;i.cursor+=1}return r[i.cursor]??null}(ta,t.value,ts);null!==n&&(Y(n),requestAnimationFrame(()=>{t.setSelectionRange(n.length,n.length)}));return}if("ArrowDown"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&function(e){if(!e)return!1;let t=B.get(e);return(t?.cursor??-1)>=0}(ta)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=B.get(e);if(!r||-1===r.cursor)return null;if(r.cursor>0)return r.cursor-=1,{text:t[r.cursor]??"",returnedToPresent:!1};let n=r.draftSnapshot;return r.cursor=-1,r.draftSnapshot="",{text:n,returnedToPresent:!0}}(ta,ts);t&&(Y(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=eI.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),ta&&B.set(ta,{cursor:-1,draftSnapshot:""}),l&&(r||o)?tl(r?"steer":"followup"):to())},[l,r,o,tl,to,ts,ta]),tc=(0,i.useCallback)(()=>{let e=eI.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tp=(0,i.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eO(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eO]);return(0,i.useEffect)(()=>{if(!G&&!et&&!en&&!eo&&!es&&!ed)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!eM.current?.contains(t),n=!!eR.current?.contains(t);r||n||Z(!1),eW.current?.contains(t)||er(!1),eL.current?.contains(t)||ei(!1),eE.current?.contains(t)||el(!1),e$.current?.contains(t)||ea(!1),eP.current?.contains(t)||ec(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[G,et,en,eo,es,ed]),(0,i.useEffect)(()=>{if(!v)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||eu(!!t?.ready)}).catch(()=>{e||eu(!1)}),()=>{e=!0}},[v]),(0,n.jsxs)("div",{style:eC,children:[tn&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{Z(!1),er(!1),ei(!1),el(!1),ea(!1),ec(!1)},style:{position:"fixed",inset:0,zIndex:490,background:"rgba(15, 23, 42, 0.18)",backdropFilter:"blur(1.5px)",WebkitBackdropFilter:"blur(1.5px)"}}),(0,n.jsx)("input",{ref:eD,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eN(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eA,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",multiple:!0,style:{display:"none"},onChange:e=>{eO(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:ev?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:ev?"0 8px":void 0,boxSizing:"border-box"},children:[R&&(0,n.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:R}),S&&(0,n.jsxs)("div",{style:{marginBottom:ev?6:8,padding:ev?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:ev?11:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]}),"Retrying (",S.attempt,"/",S.maxAttempts,")…",S.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",S.errorMessage]})]}),E&&(0,n.jsxs)("div",{style:{marginBottom:ev?6:8,padding:ev?"3px 8px":"4px 10px",background:"color-mix(in srgb, var(--accent) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 25%, transparent)",borderRadius:6,fontSize:ev?11:12,color:"var(--text-muted)",display:"inline-flex",alignItems:"center",gap:6,maxWidth:"100%"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:E.replace(/^.*[\\/]/,"")}),$&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),$()},title:"Stop including this file in context",style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:14,lineHeight:1,padding:"0 2px",flexShrink:0},children:"\xd7"})]}),(eh.length>0||eg.length>0)&&(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"flex-end"},children:[eh.map((e,t)=>(0,n.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:`1px solid ${eY?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eH(t),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,n.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},`img-${t}`)),eg.map((e,t)=>(0,n.jsx)(J,{doc:e,onRemove:()=>eF(t)},`doc-${t}`))]}),(eY||eT)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:ev?11:12,color:"rgba(185,28,28,0.95)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),(0,n.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),(0,n.jsx)("span",{children:eT??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:ev?4:8,alignItems:ev?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||o)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:ev?13:14,padding:ev?"8px 8px 8px 10px":"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)("textarea",{ref:eI,value:q,onChange:e=>Y(e.target.value),onKeyDown:td,onInput:tc,onPaste:tp,placeholder:l&&(r||o)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:ev?"stretch":void 0,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto",paddingTop:+!!ev,paddingBottom:+!!ev}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:ev?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>tl("steer"),disabled:!eG,title:eY?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!ev,padding:ev?"6px 8px":"7px 12px",background:eG?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eG?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),!ev&&"Steer"]}),o&&(0,n.jsxs)("button",{onClick:()=>tl("followup"),disabled:!eG,title:eY?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!ev,padding:ev?"6px 8px":"7px 12px",background:eG?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eG?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,n.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,n.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),!ev&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:to,disabled:!eG,title:eY?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:ev?3:6,padding:ev?"5px 9px":"7px 14px",marginBottom:+!!ev,background:eG?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eG?"#fff":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:ev?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eG?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:ev?13:14,height:ev?13:14,viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,n.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),"Send"]})]}),(0,n.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:ev?5:8,display:"flex",alignItems:ev?"flex-start":"center",gap:tt,flexWrap:ev?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:ev?"1 1 100%":"0 0 auto",width:ev?"100%":void 0,display:"flex",alignItems:"center",gap:2*!ev,flexWrap:ev?"wrap":"nowrap",rowGap:4*!!ev},children:[(0,n.jsx)("button",{onClick:()=>eD.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e9,height:e9,padding:0,background:"none",border:"none",borderRadius:te,color:eh.length||eg.length?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=eh.length||eg.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=eh.length||eg.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eA.current?.click()},children:(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,n.jsxs)("div",{ref:eW,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(er(e=>!e),ei(!1),Z(!1),el(!1),ea(!1),ec(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e9,height:e9,padding:0,background:et?"var(--bg-hover)":"none",border:"none",borderRadius:te,color:x?"#ef4444":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:15,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=x?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=et?"var(--bg-hover)":"none",e.currentTarget.style.color=x?"#ef4444":"var(--text-muted)"},children:["/",x&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"#ef4444"}})]}),et&&(0,n.jsxs)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:320,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:x?"1px solid var(--border)":"none"},children:"Commands"}),x&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#ef4444",background:"rgba(239,68,68,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:x}),eX.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Native"}),eX.map(e=>(0,n.jsxs)("button",{onClick:()=>{(er(!1),"/compact"===e.command&&h)?u?.():ti(e.command)},style:{display:"flex",alignItems:"center",gap:ev?6:8,width:"100%",padding:eb,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"/compact"===e.command&&h?"#ef4444":"var(--text-dim)"},children:"/compact"===e.command&&h?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]})}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:"/compact"===e.command&&h?"停止压缩":e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"/compact"===e.command&&h?"中止当前压缩任务":e.description})]})]},e.command))]}),eQ.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(eX.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:eX.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eQ.map(e=>(0,n.jsxs)("button",{onClick:()=>{er(!1),ti(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:eb,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:13},children:"/"}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:e.description})]})]},e.command))]})]})]}),y&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(ei(e=>!e),er(!1),Z(!1),el(!1),ea(!1),ec(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:ey,padding:0,background:en?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:e0.length>0?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:13,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=e0.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=en?"var(--bg-hover)":"none",e.currentTarget.style.color=e0.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),e0.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),en&&(0,n.jsxs)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:280,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:"1px solid var(--border)"},children:"Memory Tools"}),M.map(e=>{let t=e0.includes(e),r=F[e];return(0,n.jsxs)("button",{onClick:()=>{y(t?e0.filter(t=>t!==e):[...e0,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:eb,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:r.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:r.description})]})]},e)})]})]}),e2&&(0,n.jsxs)("div",{ref:eM,style:{position:"relative",flex:ev?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!ev){let t=e.currentTarget.getBoundingClientRect();ee({top:t.top,left:t.left,width:t.width})}er(!1),ei(!1),el(!1),ea(!1),ec(!1),Z(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:eb,height:ey,width:ev?"100%":void 0,maxWidth:ev?"100%":220,overflow:"hidden",background:G?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=G?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:eJ})]}),G&&(ev?(0,n.jsxs)("div",{ref:eR,style:{...tr,display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"8px 12px 6px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Models"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:eJ})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:eK.map((e,t)=>(0,n.jsxs)("div",{children:[eK.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{Z(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"10px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,whiteSpace:"normal",lineHeight:1.35},children:e.name}),e.input?.includes("image")&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:8},children:"image"})]},`${e.provider}:${e.modelId}`)})]},e.provider))})]}):Q&&(A=(D=window.visualViewport?.height??window.innerHeight)-Q.top+6,V=Math.max(120,Math.min(Q.top-8,.6*D)),(0,n.jsx)("div",{ref:eR,style:{position:"fixed",bottom:A,left:Q.left,zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",width:"max-content",minWidth:Q.width,maxHeight:V,overflowY:"auto"},children:eK.map((e,t)=>(0,n.jsxs)("div",{children:[eK.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{Z(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0},children:e.name}),e.input?.includes("image")&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:12},children:"image"})]},`${e.provider}:${e.modelId}`)})]},e.provider))})))]}),ev&&!l&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{ref:eP,style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>{er(!1),ei(!1),Z(!1),el(!1),ea(!1),ec(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:ed?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ew,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=ed?"var(--bg-hover)":"none",e.currentTarget.style.color=ed?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),ed&&(0,n.jsxs)("div",{style:{...tr,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[e2&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),ea(!1),el(!1),ei(!1),Z(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:e8})]}),(e5||e4)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e5&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),el(!1),ei(!1),ea(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e6})]}),e4&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),ea(!1),ei(!1),el(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e7})]})]}),e3&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),ea(!1),el(!1),ei(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:e0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:e1})]}),void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),I(!z)},style:{...eS,border:z?"1px solid rgba(59,130,246,0.24)":"none",background:z?"rgba(59,130,246,0.06)":"none"},children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Mode"}),(0,n.jsx)("div",{style:{fontSize:12,color:z?"#3b82f6":"var(--text)",marginTop:2},children:z?"Plan(只读规划)":"Code(可执行)"})]})]})]})]}),(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:"none",border:"none",borderRadius:8,color:C?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:C?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=C?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=C?"1":"0.55"},children:C?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:ek?"none":void 0,flex:ev?"0 0 auto":1,width:ev?0:void 0,height:ev?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",width:ev?"auto":void 0,display:"flex",alignItems:"center",gap:ev?4:2,marginLeft:ev?0:"auto",marginTop:0},children:[ek&&!ev&&(0,n.jsxs)("div",{ref:eP,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{er(!1),ei(!1),Z(!1),el(!1),ea(!1),ec(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:ed?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ew,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=ed?"var(--bg-hover)":"none",e.currentTarget.style.color=ed?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),ed&&(0,n.jsxs)("div",{style:{...tr,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[e2&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),ea(!1),el(!1),ei(!1),Z(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:e8})]}),(e5||e4)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e5&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),el(!1),ei(!1),ea(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e6})]}),e4&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),ea(!1),ei(!1),el(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e7})]})]}),e3&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),ea(!1),el(!1),ei(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:e0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:e1})]})]})]})]}),(!ek&&!l||ev&&es)&&j&&(0,n.jsxs)("div",{ref:e$,style:{position:"relative"},children:[!ek&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(er(!1),ei(!1),Z(!1),el(!1),ec(!1),ea(e=>!e))},disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:ev?3:5,padding:eb,height:ey,background:es?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=es?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9.5 2A5.5 5.5 0 0 0 4 7.5c0 1.7.78 3.21 2 4.21V14a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-2.29c1.22-1 2-2.51 2-4.21A5.5 5.5 0 0 0 9.5 2z"}),(0,n.jsx)("line",{x1:"7",y1:"18",x2:"12",y2:"18"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"11",y2:"21"})]}),(0,n.jsx)("span",{style:em,children:(()=>{let e=b??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})()})]}),es&&(0,n.jsx)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:ej},overflow:"hidden"},children:_.filter(e=>!k||"auto"===e||k.includes(e)).map(e=>{let t=(b??"auto")===e,r=U[e],i="auto"!==e&&w?w[e]:void 0,o=null!=i&&i!==e?i:e,l=null!=i&&i!==e;return(0,n.jsxs)("button",{onClick:()=>{ea(!1),t||j(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[o,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),(!ek&&!l||ev&&eo)&&e4&&(0,n.jsxs)("div",{ref:eE,style:{position:"relative"},children:[!ek&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(er(!1),ei(!1),Z(!1),ea(!1),ec(!1),el(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:ev?3:5,padding:eb,height:ey,background:eo?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=(g??"full")==="workbench"?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eo?"var(--bg-hover)":"none",e.currentTarget.style.color=(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)"},children:[(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(0,n.jsx)("span",{style:em,children:e7})]}),eo&&(0,n.jsx)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:120},overflow:"hidden"},children:N.map(e=>{let t=O[e],r=(g??"full")===t,i="agent"===e&&!1===ep,o=i?"需安装 pi-subagents":H[e];return(0,n.jsxs)("button",{onClick:()=>{!i&&(el(!1),r||v(t))},disabled:i,title:i?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:i?"not-allowed":"pointer",fontSize:ev?11:12,textAlign:"left",fontWeight:r?600:400,opacity:i?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:o})]},e)})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:ey,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:ev?8:9,color:"#ef4444",cursor:"pointer",fontSize:ev?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]}),!ek&&void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{l||I(!z)},disabled:l,title:z?"切换到 Code 模式(可执行代码)":"切换到 Plan 模式(只读规划)",style:{display:"flex",alignItems:"center",gap:6,padding:eb,height:ey,background:z?"rgba(59,130,246,0.08)":"none",border:z?"1px solid rgba(59,130,246,0.24)":"none",borderRadius:ev?8:9,color:z?"#3b82f6":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background=z?"rgba(59,130,246,0.14)":"var(--bg-hover)",e.currentTarget.style.color=z?"#3b82f6":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=z?"rgba(59,130,246,0.08)":"none",e.currentTarget.style.color=z?"#3b82f6":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsx)("span",{style:em,children:z?"Plan":"Code"})]}),!ev&&void 0!==T&&(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:ev?28:32,height:ev?28:32,padding:0,background:"none",border:"none",borderRadius:ev?8:9,color:C?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:C?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=C?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=C?"1":"0.55"},children:C?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]})]})]})});function ee(e){return"user"===e.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function et({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:o}){let[l,s]=(0,i.useState)(0),[a,d]=(0,i.useState)(1),[c,p]=(0,i.useState)(!1),[u,h]=(0,i.useState)([]),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(null),m=(0,i.useRef)(!1),y=(0,i.useRef)(null),b=(0,i.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,i.useRef)(b);j.current=b;let k=(0,i.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,i=t-n;p(i>20),i<=0?(s(0),d(1)):(s(e.scrollTop/i),d(n/t));let l=o.current,a=[],c=0,u=j.current;for(let r=0;r<u.length;r++){let n=u[r];if("user"!==n.role&&"assistant"!==n.role)continue;let i=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&i&&t>0){let r=i.getBoundingClientRect(),o=e.getBoundingClientRect(),l=r.top-o.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,i.useCallback)(()=>k.current(),[]);(0,i.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,i.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,i.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,i.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),i=n>=0&&n<=a?n:a/2;S(r-i);let o=e=>{m.current&&S((e.clientY-t.top)/t.height-i)},s=()=>{m.current=!1,window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",s)},[c,a,l,S]),T=y.current?.clientHeight??600,z=(0,i.useMemo)(()=>{if(!x||0===u.length)return[];let e=u.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,u,T]);if(!c)return null;let I=l*(1-a)*100,M=100*a,R=null!==f&&u.length>0?u.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(u[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${I}%`,height:`${M}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),u.map(e=>{let t=ee(e.msg),r=x&&R===e.index,i="user"===e.msg.role,o=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${o}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:i?8:6,height:i?8:6,borderRadius:i?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&u.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),i=ee(e.msg),o=R===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${o?i.border:"var(--border)"}`,borderRight:`1px solid ${o?i.border:"var(--border)"}`,borderBottom:`1px solid ${o?i.border:"var(--border)"}`,borderLeft:`2px solid ${i.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:o?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:o?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function er(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function en(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function ei(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function eo(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function el(e){let t=new Map;for(let r of e){if("custom"===r.role&&"subagent-notify"===r.customType&&"string"==typeof r.content){let e=r.content.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*(?:\s+\((.+?)\))?/);if(e){let n=`bg-${e[2]}-${r.timestamp??""}`;t.set(n,{id:n,agent:e[2],status:e[1],task:e[3],summary:en(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,i=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),o="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${i}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:i,status:"running",task:o,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!er(t))return{...e,summary:en(r)};let i=Array.isArray(t.results)?t.results.filter(er):[],o=i[0],l=o?.progressSummary,s=o&&(n=o.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=ei(o?.finalOutput,o?.output,r);return{...e,mode:ei(t.mode),runId:ei(t.runId),agent:ei(o?.agent,e.agent)??e.agent,task:ei(o?.task,e.task),summary:en(a),model:ei(o?.model),durationMs:eo(l?.durationMs),toolCount:eo(l?.toolCount),tokens:eo(l?.tokens),outputPath:ei(o?.savedOutputPath,o?.artifactPaths?.outputPath),sessionFile:ei(o?.sessionFile,o?.artifactPaths?.jsonlPath),artifacts:s,resultCount:i.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return er(t)&&Array.isArray(t.results)&&t.results.some(e=>er(e)&&"number"==typeof e.exitCode&&0!==e.exitCode)?"failed":"completed"}(r)},r.details,n))}}return Array.from(t.values()).sort((e,t)=>(t.timestamp??0)-(e.timestamp??0))}function es({messages:e,runs:t}){let r=(0,i.useMemo)(()=>el(e??[]),[e]),o=t??r,l=o.filter(e=>"running"===e.status),s=o.filter(e=>"running"!==e.status);return 0===o.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(ea,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(ea,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function ea({title:e,runs:t,compact:r}){return(0,n.jsxs)("div",{style:{marginBottom:r?10:16},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:e}),t.map(e=>(0,n.jsx)(ed,{run:e},e.id))]})}function ed({run:e}){let[t,r]=(0,i.useState)(!1),o="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":o?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":o?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":o?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${s}`,background:a,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(ec,{running:o,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:en(e.task,150)}),t&&c&&(0,n.jsxs)("div",{style:{borderTop:`1px solid ${s}`,background:"var(--bg)",padding:"8px 10px",display:"flex",flexDirection:"column",gap:7},children:[e.summary&&(0,n.jsx)("pre",{style:{margin:0,color:"var(--text-muted)",fontSize:11,lineHeight:1.45,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:e.summary}),(0,n.jsx)(ep,{run:e})]})]})}function ec({running:e,color:t}){return(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:t,display:"inline-block",animation:e?"pulse 1.5s infinite":void 0,flexShrink:0}})}function ep({run:e}){let t=[e.model?["model",e.model]:void 0,e.runId?["run",e.runId]:void 0,e.outputPath?["output",e.outputPath]:void 0,e.sessionFile?["session",e.sessionFile]:void 0,...(e.artifacts??[]).slice(0,4).map((e,t)=>[`artifact ${t+1}`,e])].filter(Boolean);return 0===t.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:3},children:t.map(([e,t])=>(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"58px minmax(0, 1fr)",gap:6,fontSize:10},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",textTransform:"uppercase"},children:e}),(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:t,children:t})]},`${e}:${t}`))})}function eu({sessionKind:e,toolPreset:t,initialSourcePath:r,initialKernel:i,isNew:o,isStreaming:l=!1,onResume:s,onDismiss:a}){if(o||"workbench"!==e)return null;let d=r?r.replace(/\\/g,"/").split("/").filter(Boolean).pop()??r:null,c="workbench"===t;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",background:"rgba(37,99,235,0.06)",borderBottom:"1px solid rgba(37,99,235,0.18)",fontSize:12,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("span",{style:{color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["This is an ",(0,n.jsxs)("strong",{children:[c?"active":"inactive"," Workbench"]})," session",d&&(0,n.jsxs)("span",{style:{color:"var(--text-muted)"},children:[" \xb7 Source: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent)"},children:d})]}),i&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",i.toUpperCase()]})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:a,style:{border:"1px solid var(--border)",borderRadius:6,padding:"2px 10px",height:26,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:"Dismiss"}),(0,n.jsx)("button",{type:"button",onClick:s,disabled:l,title:l?"Wait until the agent finishes before updating Workbench":c?"Reload the initial data source into the warm runtime":"Restore Workbench tools and reload the initial data source",style:{border:"1px solid rgba(37,99,235,0.45)",borderRadius:6,padding:"2px 12px",height:26,background:"rgba(37,99,235,0.12)",color:"var(--accent)",cursor:l?"not-allowed":"pointer",fontSize:11,fontWeight:600,opacity:l?.55:1,whiteSpace:"nowrap"},children:c?"Reload Initial Data":"Resume Workbench"})]})}function eh(e){if("assistant"!==e.role)return e;let t=e.content;if(!Array.isArray(t))return e;let r=t.map(e=>("object"!=typeof e||null===e||Array.isArray(e)||"toolCall"!==e.type?null:{type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input})??e);return{...e,content:r}}async function ex(e,t){let r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return n.data}var eg=r(28999);async function ef(e,t){if(!t.length)return[];let r=await fetch("/api/images/upload",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,images:t.map(e=>({data:e.data,mimeType:e.mimeType,name:e.name}))})}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`Upload failed (HTTP ${r.status})`);return(n.uploaded??[]).map((e,r)=>({...e,previewUrl:t[r]?.previewUrl}))}async function ev(e,t,r){let n=new TextDecoder,i="",o=new Promise(e=>{r?.aborted?e():r?.addEventListener("abort",()=>e(),{once:!0})});for(;;){let r=await Promise.race([e.read(),o.then(()=>({done:!0,value:void 0}))]);if(r.done)break;let l=(i+=n.decode(r.value,{stream:!0})).split("\n");for(let e of(i=l.pop()||"",l)){if(!e.startsWith("data: "))continue;let r=e.slice(6);if("[DONE]"!==r)try{t(r)}catch{}}}if(i.trim())for(let e of i.split("\n")){if(!e.startsWith("data: "))continue;let r=e.slice(6);if("[DONE]"!==r)try{t(r)}catch{}}}let em="__annovibeStreamSessions__",ey="__annovibeStreamListeners__",eb="__annovibeStreamErrorCallbacks__";function ej(){let e=globalThis;return e[em]||(e[em]=new Map),e[em]}function ek(){let e=globalThis;return e[eb]||(e[eb]=new Map),e[eb]}function ew(e){return{sessionId:e,phase:"idle",startedAt:null,lastEventAt:null,lastHeartbeatAt:null,reconnectCount:0,lastSyncReason:null,accumulatedText:"",toolCalls:[],toolResults:[],statusText:null,streamingMessage:null,isStreaming:!1,error:null}}function eS(e,t){let r;for(let n of(!(r=globalThis)[ey]&&(r[ey]=new Map),r[ey]).get(e)??[])try{n(t)}catch{}}function eC(e){e.textThrottleTimer&&(clearTimeout(e.textThrottleTimer),e.textThrottleTimer=null),e.textDirty&&(e.textDirty=!1,ez(e))}function eT(e,t=!1){let r=Date.now();if(e.snapshot.lastEventAt=r,!t){e.textDirty=!0,e.textThrottleTimer||(e.textThrottleTimer=setTimeout(()=>{e.textThrottleTimer=null,e.textDirty&&(e.textDirty=!1,ez(e))},100));return}eC(e),ez(e)}function ez(e,t){let r=Date.now(),n=function(e){let t=[];for(let r of e.toolCalls.values())t.push({type:"toolCall",toolCallId:r.toolCallId,toolName:r.toolName,input:r.input??{}});let r=e.accumulatedText.trim();return r&&t.push({type:"text",text:r}),t}(e),i=(t??e.snapshot.phase)==="active";e.snapshot={...e.snapshot,phase:t??e.snapshot.phase,lastEventAt:r,accumulatedText:e.accumulatedText,toolCalls:[...e.toolCalls.values()],toolResults:[...e.toolResults.values()],statusText:i?function(e){if(e.activeToolId){let t=e.toolCalls.get(e.activeToolId);if(t){let e=Math.max(0,Math.floor((Date.now()-t.startedAt)/1e3));return`Running ${t.toolName||"tool"}… (${e}s)`}}return e.accumulatedText.trim()?"Generating response…":e.toolCalls.size>0?"Finishing tool results…":null}(e):e.snapshot.statusText,streamingMessage:i&&n.length>0?{role:"assistant",content:n}:null,isStreaming:i},eS(e.snapshot.sessionId,{type:"snapshot-updated",snapshot:e.snapshot})}function eI(e){eM(e),e.idleCheckTimer=setInterval(()=>{if("connected"!==e.connectionState)return;let t=Math.max(e.snapshot.lastEventAt??0,e.snapshot.lastHeartbeatAt??0);if(Date.now()-t>=18e4){eR(e),eC(e);let t="Stream idle timeout — no activity for 180s.";e.snapshot={...e.snapshot,phase:"error",isStreaming:!1,streamingMessage:null,statusText:null,error:t},eM(e),eS(e.snapshot.sessionId,{type:"error",snapshot:e.snapshot});let r=ek().get(e.snapshot.sessionId);if(r)try{r(e.snapshot.sessionId,t)}catch{}}},1e4)}function eM(e){e.idleCheckTimer&&(clearInterval(e.idleCheckTimer),e.idleCheckTimer=null)}function eR(e){e.toolProgressTimer&&(clearInterval(e.toolProgressTimer),e.toolProgressTimer=null)}function eW(e){let t=ej(),r=t.get(e);return r||(r={snapshot:ew(e),accumulatedText:"",toolCalls:new Map,toolResults:new Map,toolProgressTimer:null,activeToolId:null,textThrottleTimer:null,textDirty:!1,connectionState:"idle",idleCheckTimer:null},t.set(e,r)),r}function eL(e,t){let r=ek();return r.set(e,t),()=>{r.get(e)===t&&r.delete(e)}}function eE(e){let t=ej(),r=t.get(e);r&&(eR(r),eM(r),eC(r)),t.delete(e)}function e$(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}let eP=["read","bash","grep","find","ls"],eD=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function eA(e){return eD.some(t=>e.type.startsWith(t))}function eB({agentPhase:e,startedAt:t}){let[r,o]=(0,i.useState)(0);return(0,i.useEffect)(()=>{if(!t)return void o(0);let e=()=>o(Math.max(0,Math.floor((Date.now()-t)/1e3)));e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t]),(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.args??e.name);return 0===t.length?"Running tool…":1===t.length?`Running ${t[0]}…`:`Running ${t.slice(0,2).join(", ")}${t.length>2?` (+${t.length-2})`:""}…`}return e?.kind==="waiting_model"?"Waiting for model…":"Working…"}(e),"\xa0\xa0",function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);return`${t}m ${String(e%60).padStart(2,"0")}s`}(r)]})})}function eN(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function eO({goal:e,planTasks:t,isRunning:r,onExecutePlan:o,onContinuePlanning:l,onEditPlan:s}){let[a,d]=(0,i.useState)(!1),c=(0,i.useCallback)(()=>d(e=>!e),[]),p=e&&"dropped"!==e.status,u=t&&t.length>0;if(!p&&!u)return null;let h=(0,i.useMemo)(()=>!e?.tokenBudget||e.tokenBudget<=0?null:Math.min(100,Math.round(e.tokensUsed/e.tokenBudget*100)),[e?.tokenBudget,e?.tokensUsed]),x=t?.filter(e=>"completed"===e.status).length??0,g=!!t&&x===t.length;return(0,n.jsxs)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:[p&&(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:u?"1px solid var(--border)":"none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#fff",background:function(e){switch(e){case"active":return"rgba(37,99,235,0.85)";case"complete":return"rgba(34,197,94,0.85)";case"budget-limited":return"rgba(245,158,11,0.85)";case"paused":return"rgba(148,163,184,0.85)";case"dropped":return"rgba(239,68,68,0.85)"}}(e.status)},children:function(e){switch(e){case"active":return"进行中";case"paused":return"已暂停";case"budget-limited":return"预算受限";case"complete":return"已完成";case"dropped":return"已放弃"}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:"Goal"})]}),(0,n.jsx)("p",{style:{margin:"0 0 6px",fontSize:13,lineHeight:1.5,color:"var(--text)",whiteSpace:"pre-wrap"},children:e.objective}),(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"4px 16px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m ${String(e%60).padStart(2,"0")}s`;let r=Math.floor(t/60);return`${r}h ${t%60}m`}(e.timeUsedSeconds)}),(0,n.jsxs)("span",{children:[eN(e.tokensUsed),e.tokenBudget?` / ${eN(e.tokenBudget)} tokens`:" tokens"]}),null!=h&&(0,n.jsxs)("span",{children:[h,"%"]})]}),null!=h&&(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,overflow:"hidden",background:"var(--border)"},children:(0,n.jsx)("div",{style:{height:"100%",borderRadius:999,background:h>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(h,100)}%`,transition:"width 0.3s"}})})]}),u&&(0,n.jsxs)("div",{style:{padding:"4px 14px 10px"},children:[(0,n.jsxs)("div",{onClick:c,role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&c()},"aria-expanded":!a,style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,cursor:"pointer",padding:"6px 0"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsxs)("span",{style:{fontSize:12,fontWeight:500,color:"#3b82f6"},children:["Plan \xb7 ",t.length," 步"]}),g&&(0,n.jsxs)("span",{style:{borderRadius:4,padding:"0 6px",fontSize:10,fontWeight:600,background:"rgba(34,197,94,0.12)",color:"rgba(34,197,94,0.85)"},children:["已完成 ",x,"/",t.length]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[(s||l||o)&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[s&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),s()},disabled:r,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:r?"not-allowed":"pointer",opacity:r?.55:1},children:"修改计划"}),l&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},disabled:r,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:r?"not-allowed":"pointer",opacity:r?.55:1},children:"继续规划"}),o&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),o()},disabled:r,style:{borderRadius:5,padding:"3px 10px",fontSize:11,fontWeight:500,color:"#fff",background:r?"rgba(59,130,246,0.3)":"#3b82f6",border:"none",cursor:r?"not-allowed":"pointer"},children:"执行计划"})]}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:a?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!a&&(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:t.map(e=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,borderRadius:4,padding:"3px 8px",background:"inProgress"===e.status?"rgba(59,130,246,0.04)":"transparent"},children:[(0,n.jsx)("div",{style:{marginTop:1},children:function(e){switch(e){case"completed":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"rgba(34,197,94,0.12)",stroke:"rgba(34,197,94,0.6)",strokeWidth:"1.5"}),(0,n.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"rgba(34,197,94,0.9)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});case"inProgress":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"rgba(59,130,246,0.2)",strokeWidth:"2.5"}),(0,n.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10",stroke:"rgba(59,130,246,0.85)",strokeWidth:"2.5",strokeLinecap:"round",children:(0,n.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"1.5s",repeatCount:"indefinite"})})]});default:return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"var(--border)",strokeWidth:"1.5"})})}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:12,lineHeight:1.5,...function(e){switch(e){case"completed":return{color:"rgba(34,197,94,0.85)",textDecoration:"line-through"};case"inProgress":return{color:"#3b82f6",fontWeight:500};default:return{color:"var(--text-muted)"}}}(e.status)},children:e.step})]},e.id))})]})]})}function eH(e){let t=e.findIndex(e=>"completed"!==e.status);return t<0?e:e.map((e,r)=>r===t?{...e,status:"completed"}:r===t+1&&"pending"===e.status?{...e,status:"inProgress"}:e)}let eF=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","build a reproducible report.","run R/Python plots.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."];function e_({phrases:e}){let[t,r]=(0,i.useState)(()=>Math.floor(Math.random()*e.length)),[o,l]=(0,i.useState)(""),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(!0);return(0,i.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,i.useEffect)(()=>{let n,i=e[t];if(s||o!==i)if(s&&""===o)a(!1),r(t=>(t+1)%e.length);else{let e=s?i.slice(0,o.length-1):i.slice(0,o.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[o,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[o,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function eU({status:e}){let t=e?.current??"0.8.92"??"0.0.0";if(e?.updateAvailable){let r=e.latest?`v${e.latest}`:"latest";return(0,n.jsxs)("span",{title:`Current v${t}; latest ${r}; run ${e.updateCommand}`,style:{display:"block",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:11,color:"var(--accent)"},children:["Update: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",color:"var(--accent)"},children:e.updateCommand})]})}return(0,n.jsxs)("span",{title:`AnnoVibe v${t}`,style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap"},children:["v",t]})}function eK({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:d,onSessionStatsChange:p,onContextUsageChange:u,onToolPresetActive:h,generativeUI:x,activeFilePath:g,onOpenFileAtLine:f}){var v;let m,[y,b]=(0,i.useState)(null),[j,k]=(0,i.useState)(!1),[w,S]=(0,i.useState)([]),[C,T]=(0,i.useState)(""),[R,D]=(0,i.useState)(!1),B=(0,i.useRef)(!1),[N,O]=(0,i.useState)(!1),H=g&&!N?g:null;(0,i.useEffect)(()=>{O(!1)},[g]);let{data:F,loading:_,error:U,messages:K,entryIds:J,streamState:V,agentRunning:q,modelNames:Y,modelList:G,modelThinkingLevels:Z,modelThinkingLevelMaps:X,toolPreset:ee,memoryTools:er,thinkingLevel:en,retryInfo:ei,contextUsage:eo,forkingEntryId:ea,isCompacting:ed,compactError:ec,displayModel:ep,sessionStats:em,agentPhase:ey,agentError:eb,isNew:ek,messagesEndRef:ez,scrollContainerRef:eD,lastUserMsgRef:eN,handleSend:eJ,handleAbort:eV,handleFork:eq,handleNavigate:eY,handleModelChange:eG,handleCompact:eZ,handleSteer:eX,handleFollowUp:eQ,handleAbortCompaction:e0,handleToolPresetChange:e1,handleMemoryToolsChange:e2,handleThinkingLevelChange:e5,handleAgentEventRef:e4}=function(e){let{session:t,newSessionCwd:r,planMode:n=!1,onAgentEnd:o,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,onBranchDataChange:d,onPlanModeState:c}=e,p=null===t&&null!==r,[u,h]=(0,i.useState)(null),[x,g]=(0,i.useState)(!p),[f,v]=(0,i.useState)(null),[m,y]=(0,i.useState)(null),[b,j]=(0,i.useState)([]),[k,w]=(0,i.useState)([]),[S,C]=(0,i.useReducer)(e$,{isStreaming:!1,streamingMessage:null}),[T,z]=(0,i.useState)(!1),[R,D]=(0,i.useState)({}),[B,N]=(0,i.useState)([]),[O,H]=(0,i.useState)({}),[F,_]=(0,i.useState)({}),[U,K]=(0,i.useState)(null),[J,V]=(0,i.useState)("full"),[q,Y]=(0,i.useState)([...M]),[G,Z]=(0,i.useState)("auto"),[X,Q]=(0,i.useState)(null),[ee,et]=(0,i.useState)(null),[er,en]=(0,i.useState)(null),[ei,eo]=(0,i.useState)(null),[el,es]=(0,i.useState)(null),[ea,ed]=(0,i.useState)(null),[ec,ep]=(0,i.useState)(!1),[eu,em]=(0,i.useState)(null),[ey,eb]=(0,i.useState)(null),[ek,ez]=(0,i.useState)(null),eD=(0,i.useRef)(null),eA=(0,i.useRef)(t?.id??null),eB=(0,i.useRef)(!1),eN=(0,i.useRef)(null),eO=(0,i.useRef)(null),eH=(0,i.useRef)(null),eF=(0,i.useRef)(!1),e_=(0,i.useRef)(null),eU=(0,i.useRef)(!1),eK=(0,i.useRef)(null),eJ=(0,i.useRef)(null),eV=e.setNewSessionModel??K,eq=e.setToolPreset??V,eY=e.setMemoryTools??Y,eG=el??u?.context.model??ea??null,eZ=p?U:eG,eX=(0,i.useCallback)(()=>n?eP:A(J,q),[q,n,J]),eQ=(0,i.useCallback)(e=>e?.length?e.map((e,t)=>{let r=`Attachment ${t+1}: ${e.fileName} (${e.mimeType||"application/octet-stream"}, ${e.size} bytes)`;if(e.extractedText){let t=e.truncated?"\n[The extracted text was truncated before sending.]":"";return`${r}
7
- ${t}
8
- ${e.extractedText}`.trim()}return`${r}
9
- [Text extraction unavailable: ${e.extractionError??"unsupported file type"}]`}).join("\n\n---\n\n"):"",[]),e0=(()=>{let e={input:0,output:0,cacheRead:0,cacheWrite:0},t=0;for(let r of b){if("assistant"!==r.role)continue;let n=r.usage;n&&(e.input+=n.input??0,e.output+=n.output??0,e.cacheRead+=n.cacheRead??0,e.cacheWrite+=n.cacheWrite??0,t+=n.cost?.total??0)}return e.input+e.output+e.cacheRead+e.cacheWrite>0?{tokens:e,cost:t}:null})(),e1=(0,i.useCallback)(async(e,t=!1,r=!1)=>{try{t&&g(!0);let n=r?`/api/sessions/${encodeURIComponent(e)}?includeState`:`/api/sessions/${encodeURIComponent(e)}`,i=await fetch(n);if(eA.current&&eA.current!==e)return null;if(404===i.status)return t&&(h(null),y(null),j([]),v(null)),null;if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();return h(o),y(o.leafId),j(o.context.messages),w(o.context.entryIds??[]),es(null),v(null),!o.agentState?.state?.thinkingLevel&&o.context.thinkingLevel&&"off"!==o.context.thinkingLevel&&Z(o.context.thinkingLevel),o.agentState?.state?.planMode&&c?.(o.agentState.state.planMode),o.agentState??null}catch(e){return v(String(e)),null}finally{t&&g(!1)}},[c]),e2=(0,i.useCallback)(async(e,t)=>{try{let r=t?`/api/sessions/${encodeURIComponent(e)}/context?leafId=${encodeURIComponent(t)}`:`/api/sessions/${encodeURIComponent(e)}/context`,n=await fetch(r);if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.json();j(i.context.messages),w(i.context.entryIds??[])}catch(e){console.error("Failed to load context:",e)}},[]),e5=(0,i.useCallback)(async e=>{try{let t=await ex(e,{type:"get_tools"});if(t){let e,r,n,i;eq((r=(e=t.filter(e=>e.active).map(e=>e.name)).filter(e=>!M.includes(e)),n=P(e),i=P(r),""===n?"none":n===P(W)?"default":n===P(L)?"full":n===P(E)?"workbench":n===P($)?"agent":""===i?"none":i===P(W)?"default":i===P(L)?"full":i===P(E)?"workbench":i===P($)||e.includes(I)?"agent":"default")),eY(M.filter(e=>t.some(t=>t.active&&t.name===e)))}}catch(e){console.error("Failed to load tools:",e)}},[eY,eq]),e4=(0,i.useCallback)((e,t={})=>{eD.current?.close(),eD.current=null;let r=`/api/agent/${encodeURIComponent(e)}/events${t.replay?"?replay=1":""}`;return!function(e){let t=eW(e);if("active"===t.snapshot.phase)return eT(t,!0),eI(t),t.snapshot;let r=Date.now();t.snapshot={...ew(e),phase:"active",startedAt:r,lastEventAt:r,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},eI(t),eT(t,!0),t.snapshot}(e),new Promise((n,i)=>{let o=!1,l=null,s=e=>{if(!o){if(o=!0,clearTimeout(a),e){l?.close(),eD.current===l&&(eD.current=null),i(e);return}n()}},a=setTimeout(()=>{t.requireConnected?s(Error("Timed out waiting for event stream connection")):s()},t.timeoutMs??1e4);eD.current=l=function(e){let{url:t,onEvent:r,onStateChange:n,onFatalError:i,maxReconnectAttempts:o=1/0,reconnectBaseMs:l=1e3,reconnectMaxMs:s=3e4,autoReconnect:a=!0}=e,d="idle",c=new AbortController,p=0,u=null,h=!1,x=e=>{d!==e&&(d=e,n?.(e))},g=()=>{null!==u&&(clearTimeout(u),u=null)},f=()=>{if(h)return;if(!a)return void x("error");if(p>=o){x("error"),i?.(Error(`Max reconnect attempts (${o}) reached`));return}let e=Math.min(s,l*2**p);p+=1,x("connecting"),u=setTimeout(()=>{u=null,v()},e)},v=async()=>{if(!h){g(),c=new AbortController,x("connecting");try{let e=await fetch(t,{signal:c.signal,headers:{Accept:"text/event-stream","Cache-Control":"no-cache"}});if(!e.ok)throw Error(`HTTP ${e.status}: ${e.statusText}`);let n=e.body;if(!n)throw Error("Response has no readable body");let i=n.getReader();x("connected"),p=0,await ev(i,r,c.signal),i.releaseLock(),x("closed"),!h&&a&&f()}catch(e){if(h||e instanceof DOMException&&"AbortError"===e.name)return void x("closed");x("error"),a&&f()}}};return{get state(){return d},connect:()=>{h=!1,p=0,g(),v()},close:()=>{h=!0,g(),c.abort(),x("closed")},get abortController(){return c}}}({url:r,onEvent:e=>{try{let t=JSON.parse(e);"connected"===t.type&&s(),eN.current?.(t)}catch{}},onStateChange:r=>{!function(e,t){let r=ej().get(e);if(!r)return;let n=r.connectionState;r.connectionState=t,"connected"===t&&"connected"!==n&&(r.snapshot={...r.snapshot,lastEventAt:Date.now(),lastHeartbeatAt:Date.now()},eI(r)),"connected"!==t&&"connected"===n&&eM(r)}(e,r),t.requireConnected&&"error"===r&&s(Error("Failed to connect event stream"))},reconnectBaseMs:1e3,reconnectMaxMs:3e4}),l.connect()})},[]),e3=(0,i.useCallback)(async(e,t="manual")=>{if(e&&eA.current===e)try{let t=await fetch(`/api/agent/${encodeURIComponent(e)}`),r=await t.json().catch(()=>({}));if(eA.current!==e)return;if(r.running){if(eB.current=!0,z(!0),eb(e=>e??{kind:"waiting_model"}),!eD.current||"closed"===eD.current.state||"error"===eD.current.state){let t;(t=ej().get(e))&&(t.snapshot={...t.snapshot,reconnectCount:t.snapshot.reconnectCount+1,lastSyncReason:"sse-reconnect",lastEventAt:Date.now()},eT(t,!0)),e4(e,{replay:!0})}}else eB.current=!1,eD.current?.close(),eD.current=null,eE(e),z(!1),eb(null),Q(null),C({type:"end"}),await e1(e);r.state?.contextUsage!==void 0&&et(r.state.contextUsage??null),r.state?.systemPrompt!==void 0&&en(r.state.systemPrompt??null),r.state?.isCompacting!==void 0&&ep(r.state.isCompacting),r.state?.thinkingLevel!==void 0&&Z(r.state.thinkingLevel??"auto"),r.state?.planMode!==void 0&&c?.(r.state.planMode)}catch{}},[e4,e1,c]);(0,i.useEffect)(()=>{eO.current=e3},[e3]),(0,i.useEffect)(()=>{eB.current=T},[T]),eN.current=(0,i.useCallback)(e=>{let t=eA.current;switch(t&&function(e,t){let r=eW(e),n=Date.now();switch(t.type){case"agent_start":if("active"===r.snapshot.phase)return eT(r,!0),r.snapshot;return eR(r),r.accumulatedText="",r.toolCalls.clear(),r.toolResults.clear(),r.activeToolId=null,r.snapshot={...ew(e),phase:"active",startedAt:n,lastEventAt:n,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},eI(r),eT(r,!0),r.snapshot;case"message_update":{let e=t.message;if(!e||"assistant"!==e.role)return r.snapshot;let i=e.content;for(let e of Array.isArray(i)?i:[])"object"==typeof e&&null!==e&&"type"in e&&("text"===e.type?r.accumulatedText=e.text??"":"toolCall"===e.type&&e.toolCallId&&!r.toolCalls.has(e.toolCallId)&&r.toolCalls.set(e.toolCallId,{...e,startedAt:n}));return eT(r,!1),r.snapshot}case"tool_execution_start":{let e="string"==typeof t.toolCallId?t.toolCallId:"",i="string"==typeof t.toolName?t.toolName:"tool",o=t.input??{};if(!e)return r.snapshot;let l=r.toolCalls.get(e);return r.toolCalls.set(e,{type:"toolCall",toolCallId:e,toolName:i,input:l?.input??o,startedAt:l?.startedAt??n}),r.activeToolId=e,eR(r),r.activeToolId&&(r.toolProgressTimer=setInterval(()=>eT(r,!0),1e3)),eT(r,!0),r.snapshot}case"tool_execution_end":{let e="string"==typeof t.toolCallId?t.toolCallId:"",i="string"==typeof t.toolName?t.toolName:"tool",o="string"==typeof t.result?t.result:JSON.stringify(t.result??"");if(e){let l=r.toolCalls.get(e);l&&r.toolCalls.set(e,{...l,endedAt:n}),r.toolResults.set(e,{role:"toolResult",toolCallId:e,toolName:i,content:[{type:"text",text:o}],isError:!!t.isError,timestamp:n}),r.activeToolId===e&&(r.activeToolId=null,eR(r))}return eT(r,!0),r.snapshot}case"message_end":return eC(r),eT(r,!0),r.snapshot;case"agent_end":{eC(r),eR(r),eM(r);let n="string"==typeof t.error?t.error:null;return r.activeToolId=null,r.snapshot={...r.snapshot,phase:n?"error":"completed",isStreaming:!1,streamingMessage:null,statusText:null,error:n},eS(e,n?{type:"error",snapshot:r.snapshot}:{type:"completed",snapshot:r.snapshot}),r.snapshot}case"heartbeat":return r.snapshot={...r.snapshot,lastHeartbeatAt:n},r.snapshot;default:return r.snapshot}}(t,e),e.type){case"agent_start":ez(null),eB.current=!0,z(!0),eb({kind:"waiting_model"}),C({type:"start"});break;case"agent_end":eB.current=!1,eD.current?.close(),eD.current=null,z(!1),eb(null),Q(null),C({type:"end"}),eA.current&&(e1(eA.current),fetch(`/api/agent/${encodeURIComponent(eA.current)}`).then(e=>e.json()).then(e=>{!1===e.running&&(z(!1),eb(null),C({type:"end"})),e.state?.contextUsage!==void 0&&et(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&en(e.state.systemPrompt??null),e.state?.isCompacting!==void 0&&ep(e.state.isCompacting)}).catch(()=>{})),o?.();break;case"message_start":case"message_update":{let t=e.message;if(t?.role==="user")break;t&&C({type:"update",message:eh(t)}),eb(null);break}case"message_end":{let t=e.message;t&&"user"!==t.role&&j(e=>[...e,eh(t)]),C({type:"reset"}),eb({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,r=e.toolName,n=e.args,i="bash"===r&&"string"==typeof n?.command?n.command:void 0;eb(e=>{let n=e?.kind==="running_tools"?[...e.tools]:[];return n.some(e=>e.id===t)||n.push({id:t,name:r,args:i}),{kind:"running_tools",tools:n}});break}case"tool_execution_end":{let t=e.toolCallId;eb(e=>{if(e?.kind!=="running_tools")return e;let r=e.tools.filter(e=>e.id!==t);return 0===r.length?{kind:"waiting_model"}:{kind:"running_tools",tools:r}});break}case"auto_retry_start":Q({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":Q(null);break;case"auto_compaction_start":case"compaction_start":ep(!0),em(null);break;case"auto_compaction_end":case"compaction_end":ep(!1),e.errorMessage?em(e.errorMessage):!e.aborted&&eA.current&&e1(eA.current)}},[e1,o]);let e8=(0,i.useCallback)(async(e,i,o,s)=>{if(!e.trim()&&!i?.length&&!o?.length||T)return;let a=eQ(o),d=e.trim()?a?`${e}
10
-
11
- Attached document text:
12
-
13
- ${a}`:e:a?`Attached document text:
14
-
15
- ${a}`:"",c=[],h=p?r:t?.cwd??u?.info?.cwd;if(i?.length&&h)try{c=await ef(h,i)}catch(e){ez(e instanceof Error?e.message:String(e));return}let x=c.length?c.map(e=>{var t;return{type:"image",path:e.path,mimeType:e.mimeType,name:e.name,source:{type:"url",url:(t=e.path,`/api/files/${(0,eg.HG)(t)}?type=read`),media_type:e.mimeType}}}):i?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),g={role:"user",content:x?.length?[...d.trim()?[{type:"text",text:d}]:[],...x]:d,timestamp:Date.now()};j(e=>[...e,g]),ez(null),eB.current=!0,z(!0),eb({kind:"waiting_model"}),C({type:"start"}),eU.current=!0;let f=B.find(e=>e.provider===eG?.provider&&e.id===eG?.modelId)?.input,v=!f||0===f.length||f.includes("image")?i?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})):void 0;try{if(p&&r){U&&ed(U);let t=s??eX(),i=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,type:"prompt",message:d,toolNames:t,planMode:n,...v?.length?{images:v}:{},...U?{provider:U.provider,modelId:U.modelId}:{},..."auto"!==G?{thinkingLevel:G}:{}})}),o=await i.json().catch(()=>({}));if(!i.ok||o.error||!o.sessionId)throw Error(o.error??`HTTP ${i.status}`);let a=o.sessionId;eA.current=a,eH.current?.(),eH.current=eL(a,()=>{eA.current===a&&(z(!1),eb(null))}),await e4(a,{requireConnected:!0}),await ex(a,{type:"prompt",message:d,toolNames:t,planMode:n,...v?.length?{images:v}:{}}),l?.({id:a,path:"",cwd:r,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:1,firstMessage:e})}else if(t){let e=s??eX();eH.current?.(),eH.current=eL(t.id,()=>{eA.current===t.id&&(z(!1),eb(null))}),await e4(t.id,{requireConnected:!0}),await ex(t.id,{type:"prompt",message:d,toolNames:e,planMode:n,...v?.length?{images:v}:{}})}}catch(e){console.error("Failed to send message:",e),ez(e instanceof Error?e.message:String(e)),eB.current=!1,z(!1),eb(null),C({type:"end"})}},[p,r,U,eX,G,t,u?.info?.cwd,T,e4,l,eQ,n,B,eG]),e6=(0,i.useCallback)(async()=>{let e=eA.current;if(e){eB.current=!1,ez(null),z(!1),eb(null),C({type:"end"}),eD.current?.close(),eD.current=null,eE(e);try{await ex(e,{type:"abort"}),await e1(e)}catch(t){console.error("Failed to abort:",t),await e1(e)}}},[e1]),e7=(0,i.useCallback)(async e=>{let t=eA.current;if(t){eo(e);try{let{cancelled:r,newSessionId:n}=await ex(t,{type:"fork",entryId:e})??{};!r&&n&&s?.(n)}catch(e){console.error("Fork failed:",e)}finally{eo(null)}}},[s]),e9=(0,i.useCallback)(async e=>{let t=eA.current;t&&(ex(t,{type:"navigate_tree",targetId:e}).catch(()=>{}),y(e),await e2(t,e))},[e2]),te=(0,i.useCallback)(async e=>{y(e);let t=eA.current;t&&(await e2(t,e),e&&ex(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[e2]),tt=(0,i.useCallback)(async(e,t)=>{if(p)return void eV({provider:e,modelId:t});let r=eA.current;if(r)try{await ex(r,{type:"set_model",provider:e,modelId:t}),es({provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}},[p,eV]),tr=(0,i.useCallback)(async()=>{let e=eA.current;if(e&&!ec){ep(!0),em(null);try{await ex(e,{type:"compact"}),await e1(e,!0)}catch(e){em(e instanceof Error?e.message:String(e))}finally{ep(!1)}}},[ec,e1]),tn=(0,i.useCallback)(async(e,t,r)=>{let n=eA.current;if(!n)return;let i=eQ(r),o=e.trim()?i?`${e}
16
-
17
- Attached document text:
18
-
19
- ${i}`:e:i?`Attached document text:
20
-
21
- ${i}`:"",l={role:"user",content:`[steer] ${o}`,timestamp:Date.now()};j(e=>[...e,l]);let s=B.find(e=>e.provider===eG?.provider&&e.id===eG?.modelId)?.input,a=!s||0===s.length||s.includes("image")?t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})):void 0;try{await ex(n,{type:"steer",message:o,...a?.length?{images:a}:{}})}catch(e){console.error("Failed to steer:",e)}},[eQ,B,eG]),ti=(0,i.useCallback)(async(e,t,r)=>{let n=eA.current;if(!n)return;let i=eQ(r),o=e.trim()?i?`${e}
22
-
23
- Attached document text:
24
-
25
- ${i}`:e:i?`Attached document text:
26
-
27
- ${i}`:"",l={role:"user",content:o,timestamp:Date.now()};j(e=>[...e,l]);let s=B.find(e=>e.provider===eG?.provider&&e.id===eG?.modelId)?.input,a=!s||0===s.length||s.includes("image")?t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})):void 0;try{await ex(n,{type:"follow_up",message:o,...a?.length?{images:a}:{}})}catch(e){console.error("Failed to follow up:",e)}},[eQ,B,eG]),to=(0,i.useCallback)(async()=>{let e=eA.current;if(e)try{await ex(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),tl=(0,i.useCallback)(async e=>{if(Z(e),"auto"===e)return;let t=eA.current;if(t)try{await ex(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),ts=(0,i.useCallback)(async e=>{eq(e);let t=A(e,q),r=eA.current;if(r)try{await ex(r,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[q,eq]),ta=(0,i.useCallback)(async e=>{eY(e);let t=A(J,e),r=eA.current;if(r)try{await ex(r,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set memory tools:",e)}},[eY,J]),td=(0,i.useCallback)((e="smooth")=>{eK.current?.scrollIntoView({behavior:e})},[]),tc=(0,i.useCallback)(()=>{let e=eJ.current,t=e_.current;if(!e||!t)return;let r=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop;e.scrollTo({top:r-16,behavior:"smooth"})},[]);return(0,i.useEffect)(()=>{if(t){var e;let r;eA.current=t.id;let n=(e=t.id,(r=ej().get(e))&&"idle"!==r.snapshot.phase?r.snapshot:null);n?.phase==="active"&&(z(!0),eb({kind:"waiting_model"}),C({type:"start"}),e4(t.id,{replay:!0})),(async()=>{let e=await e1(t.id,!0,!0);eA.current===t.id&&(await e5(t.id),e?.running&&(n&&"active"===n.phase||(z(!0),eb({kind:"waiting_model"}),C({type:"start"}),e4(t.id,{replay:!0})),eH.current?.(),eH.current=eL(t.id,()=>{eA.current===t.id&&(z(!1),eb(null))})),e?.state&&(void 0!==e.state.isCompacting&&ep(e.state.isCompacting),void 0!==e.state.contextUsage&&et(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&en(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&Z(e.state.thinkingLevel??"auto"),void 0!==e.state.planMode&&c?.(e.state.planMode)))})()}return()=>{eD.current?.close(),eD.current=null,eH.current?.(),eH.current=null}},[e4,e1,e5,d,c,t]),(0,i.useEffect)(()=>{let e=()=>{let e=eA.current;e&&e3(e,"foreground")},t=()=>{"visible"===document.visibilityState&&e()};return document.addEventListener("visibilitychange",t),window.addEventListener("focus",e),()=>{document.removeEventListener("visibilitychange",t),window.removeEventListener("focus",e)}},[e3]),(0,i.useEffect)(()=>{let e=eA.current;if(!e)return;let t=window.setInterval(()=>{eB.current||e1(e)},15e3);return()=>window.clearInterval(t)},[e1]),(0,i.useEffect)(()=>{d&&d(u?.tree??[],m,te)},[u?.tree,m,te,d]),(0,i.useEffect)(()=>{b.length>0&&(eU.current?(eU.current=!1,eF.current=!0,tc()):eF.current?eB.current||td("smooth"):(eF.current=!0,td("instant")))},[b.length,T,td,tc]),(0,i.useEffect)(()=>{fetch("/api/models").then(e=>e.json()).then(e=>{if(D(e.models),e.thinkingLevels&&H(e.thinkingLevels),e.thinkingLevelMaps&&_(e.thinkingLevelMaps),e.modelList&&(N(e.modelList),p&&e.modelList.length>0)){let t=e.defaultModel,r=t&&e.modelList.find(e=>e.id===t.modelId&&e.provider===t.provider);eV(r?{provider:r.provider,modelId:r.id}:{provider:e.modelList[0].provider,modelId:e.modelList[0].id})}}).catch(()=>{})},[p,a,eV]),(0,i.useEffect)(()=>{if(!eu)return;let e=setTimeout(()=>em(null),3e3);return()=>clearTimeout(e)},[eu]),{data:u,loading:x,error:f,activeLeafId:m,messages:b,entryIds:k,streamState:S,agentRunning:T,modelNames:R,modelList:B,modelThinkingLevels:O,modelThinkingLevelMaps:F,newSessionModel:U,toolPreset:J,memoryTools:q,thinkingLevel:G,retryInfo:X,contextUsage:ee,systemPrompt:er,forkingEntryId:ei,isCompacting:ec,compactError:eu,currentModel:eG,displayModel:eZ,sessionStats:e0,agentPhase:ey,agentError:ek,isNew:p,sessionIdRef:eA,sseReaderRef:eD,messagesEndRef:eK,scrollContainerRef:eJ,lastUserMsgRef:e_,pendingScrollToUserRef:eU,initialScrollDoneRef:eF,handleSend:e8,handleAbort:e6,handleFork:e7,handleNavigate:e9,handleModelChange:tt,handleCompact:tr,handleSteer:tn,handleFollowUp:ti,handleAbortCompaction:to,handleToolPresetChange:ts,handleMemoryToolsChange:ta,handleThinkingLevelChange:tl,loadTools:e5,setActiveLeafId:y,setData:h,setMessages:j,dispatch:C,setAgentRunning:z,setForkingEntryId:eo,handleAgentEventRef:eN}}({session:e,newSessionCwd:t,planMode:j,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,onBranchDataChange:d,onPlanModeState:(0,i.useCallback)(e=>{let t;k(e.enabled),D(e.executing);let r=(t=e.todos.findIndex(e=>!e.completed),e.todos.map((e,r)=>({id:`plan-${e.step||r+1}`,step:e.text,status:e.completed?"completed":r===t?"inProgress":"pending"})));e.enabled||e.executing||r.length>0?S(r):S([])},[])}),{soundEnabled:e3,onSoundToggle:e8,playDoneSound:e6}=function(){let[e,t]=(0,i.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),r=(0,i.useRef)(e);return(0,i.useEffect)(()=>{r.current=e},[e]),{soundEnabled:e,onSoundToggle:(0,i.useCallback)(()=>{t(e=>{let t=!e;return localStorage.setItem("pi-sound-enabled",String(t)),t})},[]),playDoneSound:(0,i.useCallback)(()=>{if(r.current)try{let e=new AudioContext;"suspended"===e.state&&e.resume().catch(()=>{});let t=e.currentTime;[523.25,659.25].forEach((r,n)=>{let i=e.createOscillator(),o=e.createGain();i.connect(o),o.connect(e.destination),i.type="sine",i.frequency.value=r;let l=t+.18*n;o.gain.setValueAtTime(0,l),o.gain.linearRampToValueAtTime(.18,l+.02),o.gain.exponentialRampToValueAtTime(.001,l+.45),i.start(l),i.stop(l+.45)}),setTimeout(()=>e.close(),1200)}catch{}},[]),soundEnabledRef:r}}(),e7=(0,i.useRef)(e6);e7.current=e6;let e9=(0,i.useRef)(e3);e9.current=e3,(0,i.useEffect)(()=>{q&&!y&&b(Date.now()),q||b(null)},[q,y]);let te=e4.current;(0,i.useEffect)(()=>{e4.current=e=>{"agent_start"===e.type&&(b(Date.now()),B.current=!1),"tool_execution_end"===e.type&&R&&(B.current=!0,S(eH)),"agent_end"===e.type&&(b(null),R&&!B.current&&S(eH)),"agent_end"===e.type&&e9.current&&e7.current(),te?.(e)}},[te,e4,R]);let tt=em?`${em.tokens.input}|${em.tokens.output}|${em.tokens.cacheRead}|${em.tokens.cacheWrite}|${em.cost??0}`:null,tr=(0,i.useRef)(em);tr.current=em,(0,i.useEffect)(()=>{p?.(tr.current)},[tt,p]),(0,i.useEffect)(()=>()=>{p?.(null)},[p]),(0,i.useEffect)(()=>(h?.("workbench"===ee),()=>{h?.(!1)}),[ee,h]);let tn=eo?`${eo.percent??"null"}|${eo.contextWindow}|${eo.tokens??"null"}`:null,ti=(0,i.useRef)(eo);ti.current=eo,(0,i.useEffect)(()=>{u?.(ti.current)},[tn,u]),(0,i.useEffect)(()=>()=>{u?.(null)},[u]);let to=(0,i.useCallback)(e=>{a?.current?.addFiles(e)},[a]),tl=(0,i.useCallback)((e,t,r)=>{let n=r?.findIndex(t=>t.src===e)??-1;tg({src:e,gallery:r,index:n>=0?n:0})},[]),{isDragOver:ts,handleDragEnter:ta,handleDragOver:td,handleDragLeave:tc,handleDrop:tp}=function(e){let[t,r]=(0,i.useState)(!1),n=(0,i.useRef)(0),o=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(eA)&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(eA)&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:o,handleDragOver:l,handleDragLeave:(0,i.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,i.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}(to),[tu,th]=(0,i.useState)(null),[tx,tg]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!ek)return;let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&th(t)}).catch(()=>{}),()=>{e=!0}},[ek]);let tf=K.filter(e=>"user"===e.role||"assistant"===e.role),tv=(v=tf.length,(m=(0,i.useRef)([])).current=Array(v).fill(null).map((e,t)=>m.current[t]??null),m),tm=(0,i.useMemo)(()=>{let e=new Map;for(let t of K)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[K]),ty=ek&&0===K.length&&!V.isStreaming&&!q,tb=F?.info?.cwd??e?.cwd??t??null,tj=function(e){if(!e)return null;let t=e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return t[t.length-1]||e}(tb),tk=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e-1}px)`),n=()=>r(t.matches);return(n(),"function"==typeof t.addEventListener)?(t.addEventListener("change",n),()=>t.removeEventListener("change",n)):(t.addListener(n),()=>t.removeListener(n))},[e]),t}(),[tw,tS]=(0,i.useState)(!1),[tC,tT]=(0,i.useState)(!1),tz=el(K),tI=tz.filter(e=>"running"===e.status).length;(0,i.useEffect)(()=>{0===tz.length&&tw&&tS(!1)},[tz.length,tw]),(0,i.useEffect)(()=>{tk&&tw&&tS(!1)},[tk,tw]),(0,i.useEffect)(()=>{tT(!1)},[e?.id]);let tM=(0,i.useCallback)(()=>{e?.id&&!q&&(async()=>{await e1("workbench");let e=F?.sessionMeta;if(e?.initialSourcePath&&e.initialKernel){let t=`Resume this Workbench session. Reload only the initial data file \`${e.initialSourcePath}\` using the ${e.initialKernel.toUpperCase()} runtime. Do not rerun previous analyses or load extra files unless I ask. Use the chat history only as context for what to do next.`;await eJ(t)}})()},[q,F?.sessionMeta,eJ,e1,e?.id]),tR=ep?Z[`${ep.provider}:${ep.modelId}`]??null:null,tW=ep?X[`${ep.provider}:${ep.modelId}`]??null:null,tL=F?.sessionMeta?.sessionKind??null,tE=e?.id??t??"new-chat",t$=(0,i.useMemo)(()=>(function(e){let t=[];for(let r=e.length-1;r>=0;r-=1){let n=e[r];if("user"!==n.role)continue;let i=n.text.trim();i&&t.push(i)}return t})(tf.map(e=>{let t;return{role:e.role,text:"string"==typeof(t=e.content)?t:Array.isArray(t)?t.filter(e=>!!e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n"):""}})),[tf]),tP=(0,i.useCallback)(()=>{let t=!j;k(t);let r=e?.id;r&&ex(r,{type:"set_tools",toolNames:t?["read","bash","grep","find","ls"]:A(ee,er),planMode:t}).catch(()=>{}),t&&D(!1)},[er,j,e?.id,ee]),tD=(0,i.useCallback)(async(e,t,r)=>{if("/plan"===e.trim()||e.trim().startsWith("/plan "))return void tP();let n=e;H&&e.trim()&&(n=`${e}
28
-
29
- [Current file: \`${H}\`]`),await eJ(n,t,r)},[tP,eJ,H]),tA=(0,n.jsx)(Q,{ref:a,onSend:tD,onAbort:eV,onSteer:q?eX:void 0,onFollowUp:q?eQ:void 0,isStreaming:q,model:ep,modelNames:Y,modelList:G,onModelChange:eG,onCompact:e||ek?eZ:void 0,onAbortCompaction:e0,isCompacting:ed,compactError:ec,toolPreset:ee,sessionKind:tL,onToolPresetChange:e||ek?e1:void 0,memoryTools:er,onMemoryToolsChange:e||ek?e2:void 0,thinkingLevel:en,onThinkingLevelChange:e||ek?e5:void 0,availableThinkingLevels:tR,thinkingLevelMap:tW,retryInfo:ei,soundEnabled:e3,onSoundToggle:e8,cornerBadge:ty?(0,n.jsx)(eU,{status:tu}):void 0,promptHistory:t$,sessionHistoryKey:tE,planMode:j,onPlanModeChange:()=>tP(),activeFilePath:H,onDismissFileContext:()=>O(!0)});(0,i.useEffect)(()=>{if(!j){R||S([]);return}let e=[...K].reverse().find(e=>"assistant"===e.role);if(!e||!Array.isArray(e.content)){S([]),T("");return}let t=e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");if(!t){S([]),T("");return}let r=[];for(let e of t.matchAll(/^\s*(\d+)[.)]\s+\*{0,2}([^*\n]+)/gm)){let t=e[2].trim().replace(/\*{1,2}$/,"").trim().replace(/\s+/g," ");t.length>3&&r.push({id:`task-${r.length}`,step:t.slice(0,80),status:"pending"})}T(t),S(r)},[K,R,j]);let tB=(0,i.useCallback)(()=>{q||0===w.length||eJ("请继续完善这个计划,补充遗漏的风险、步骤和验证方式。保持编号列表格式。")},[q,eJ,w.length]),tN=(0,i.useCallback)(()=>{if(q||0===w.length)return;let e=C||w.map((e,t)=>`${t+1}. ${e.step}`).join("\n");a?.current?.insertText(`请按以下修改后的计划继续规划:
30
-
31
- ${e}`)},[q,a,w,C]),tO=(0,i.useCallback)(()=>{let t=e?.id;t&&!q&&0!==w.length&&(async()=>{let e=await fetch(`/api/sessions/${encodeURIComponent(t)}/plan`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planText:C,tasks:w})});if(!e.ok)throw Error(`Failed to save plan: HTTP ${e.status}`);let r=A(ee,er);await ex(t,{type:"set_tools",toolNames:r,planMode:!1}),k(!1),D(!0),S(e=>e.map((e,t)=>({...e,status:0===t?"inProgress":"pending"}))),await eJ(`Execute the approved plan from .annovibe-plan.md. Start with: ${w[0].step}`,void 0,void 0,r)})().catch(()=>{})},[q,eJ,er,w,C,e?.id,ee]);(0,i.useEffect)(()=>{R&&w.length>0&&w.every(e=>"completed"===e.status)&&D(!1)},[R,w]);let tH=(0,i.useCallback)(e=>{q?a?.current?.insertText(e):eJ(e)},[q,a,eJ]),tF=(0,i.useCallback)((e,t,r)=>{if(q)return;let n=e.includes("```")?"````":"```",i=`${n}${t||""}
32
- ${e}
33
- ${n}`,o=r?` to \`${r}\``:" to the appropriate file";eJ(`Please write the following code${o} and then run it to show the result:
34
-
35
- ${i}`)},[q,eJ]),t_=(0,i.useCallback)((e,t)=>{if(q)return;let r=e.includes("```")?"````":"```",n=`${r}${t||""}
36
- ${e}
37
- ${r}`;eJ(`Please run the following code and show the output:
38
-
39
- ${n}`)},[q,eJ]),tU=(0,i.useCallback)((e,t)=>{if(q)return;let r=t?` to \`${t}\``:"",n=e.includes("```")?"````":"```",i=`${n}diff
40
- ${e}
41
- ${n}`;eJ(`Please apply this diff${r}:
42
-
43
- ${i}`)},[q,eJ]);return _?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):U?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:U}):(0,n.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:ta,onDragOver:td,onDragLeave:tc,onDrop:tp,children:[ts&&(0,n.jsxs)("div",{className:"pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[rgba(37,99,235,0.06)] backdrop-blur-[1px]",children:[(0,n.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(e=>(0,n.jsx)("div",{className:"absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[rgba(37,99,235,0.5)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]",style:{transformOrigin:"center",animationDelay:`${e}s`}},e))}),(0,n.jsxs)("svg",{width:"280",height:"280",viewBox:"0 0 140 140",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"drop-shadow-[0_6px_18px_rgba(37,99,235,0.18)]",children:[(0,n.jsx)("rect",{x:"28",y:"44",width:"84",height:"60",rx:"8",fill:"rgba(37,99,235,0.08)",stroke:"rgba(37,99,235,0.50)",strokeWidth:"1.8"}),(0,n.jsx)("path",{d:"M36 100 L54 72 L68 88 L80 74 L104 100Z",fill:"rgba(37,99,235,0.16)",stroke:"rgba(37,99,235,0.40)",strokeWidth:"1.4",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"96",cy:"58",r:"8",fill:"rgba(37,99,235,0.22)",stroke:"rgba(37,99,235,0.55)",strokeWidth:"1.6"}),(0,n.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,n.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,n.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,n.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,n.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,n.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,n.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,n.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),!tC&&(0,n.jsx)(eu,{sessionKind:tL,toolPreset:ee,initialSourcePath:F?.sessionMeta?.initialSourcePath??null,initialKernel:F?.sessionMeta?.initialKernel??null,isNew:ek,isStreaming:q,onResume:tM,onDismiss:()=>tT(!0)}),ty?(0,n.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-8",children:(0,n.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,n.jsxs)("div",{className:"mb-3",style:{display:"flex",flexDirection:"column",alignItems:"stretch",justifyContent:"flex-start",gap:10,marginLeft:16,marginRight:16,fontFamily:"var(--font-mono)"},children:[tj&&(0,n.jsxs)("div",{style:{padding:tk?"7px 9px":"9px 12px",border:"1px solid var(--border)",borderRadius:tk?9:10,background:"linear-gradient(180deg, var(--bg-panel), rgba(127,127,127,0.03))",minWidth:0,display:"flex",alignItems:"flex-start",gap:tk?8:10,boxShadow:tk?"0 2px 10px rgba(0,0,0,0.04)":"none"},children:[(0,n.jsx)("div",{"aria-hidden":!0,style:{flex:"0 0 auto",width:tk?18:20,height:tk?18:20,borderRadius:6,marginTop:1,background:"rgba(37,99,235,0.10)",border:"1px solid rgba(37,99,235,0.20)",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--accent)"},children:(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 7.5 12 4l9 3.5-9 3.5-9-3.5Z"}),(0,n.jsx)("path",{d:"M7 10v4.5c0 .8 2.2 2 5 2s5-1.2 5-2V10"})]})}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:9,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.08em",marginBottom:2},children:"Current Project"}),(0,n.jsx)("div",{style:{fontSize:tk?12.5:14,color:"var(--text)",fontWeight:700,lineHeight:1.3,wordBreak:"break-word"},children:tj}),tb&&(0,n.jsx)("div",{title:tb,style:{fontSize:10.5,color:"var(--text-dim)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:tb})]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0,flex:1,lineHeight:1.4},children:[(0,n.jsx)("span",{style:{fontSize:23,color:"var(--text)",fontWeight:750,letterSpacing:0},children:c}),(0,n.jsx)("span",{style:{fontSize:14,minWidth:0,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:(0,n.jsx)(e_,{phrases:eF})})]})]}),tA]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,n.jsx)("div",{ref:eD,className:"flex-1 overflow-y-auto pt-4 [scrollbar-width:none]",children:(0,n.jsxs)("div",{className:"mx-auto max-w-[820px] px-4",style:tk?{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 128px)"}:void 0,children:[(0,n.jsx)(eO,{goal:F?.sessionMeta?.goal??null,planTasks:w,isRunning:q,onExecutePlan:j&&w.length>0?tO:void 0,onContinuePlanning:j&&w.length>0?tB:void 0,onEditPlan:j&&w.length>0?tN:void 0}),(()=>{let r=-1;for(let e=K.length-1;e>=0;e--)if("user"===K[e].role){r=e;break}let i=0;return K.map((o,l)=>{let s="user"===o.role&&l>0&&"assistant"===K[l-1].role?J[l-1]:void 0,d="user"===o.role||"assistant"===o.role,c=d?i++:-1,p=!1;if("assistant"===o.role){p=!0;for(let e=l+1;e<K.length;e++){let t=K[e].role;if("user"===t)break;if("assistant"===t){p=!1;break}}p&&V.isStreaming&&l===K.length-1&&(p=!1)}let u=(0,n.jsx)(z.D,{message:o,toolResults:tm,modelNames:Y,entryId:J[l],onFork:q||ek||0===l&&"user"===o.role?void 0:eq,forking:ea===J[l],onNavigate:q?void 0:eY,prevAssistantEntryId:q?void 0:s,onEditContent:e=>a?.current?.insertIfEmpty(e),onSendMessage:tH,showTimestamp:p,prevTimestamp:l>0?K[l-1].timestamp:void 0,renderVisualCodeBlocks:!!x,cwd:F?.info?.cwd??e?.cwd??t??void 0,onOpenImage:tl,activeFilePath:H,agentRunning:q,onApplyToFile:tF,onRunCode:t_,onOpenFileAtLine:f,onAcceptDiff:tU},l);return d?(0,n.jsx)("div",{ref:e=>{tv.current[c]=e,l===r&&(eN.current=e)},children:u},l):u})})(),q&&(0,n.jsx)(eB,{agentPhase:ey,startedAt:y}),V.isStreaming&&V.streamingMessage&&(0,n.jsx)(z.D,{message:V.streamingMessage,isStreaming:!0,toolResults:tm,modelNames:Y,onSendMessage:tH,renderVisualCodeBlocks:!!x,cwd:F?.info?.cwd??e?.cwd??t??void 0,activeFilePath:H,agentRunning:q,onApplyToFile:tF,onRunCode:t_,onOpenFileAtLine:f,onAcceptDiff:tU}),q&&!V.streamingMessage&&(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.name);return 0===t.length?"Running tool...":1===t.length?`Running ${t[0]}...`:t.length<=3?`Running ${t.join(", ")}...`:`Running ${t.slice(0,2).join(", ")} (+${t.length-2})...`}return e?.kind==="waiting_model"?"Waiting for model...":"Thinking..."}(ey)})}),F?.info?.cwd&&!1===F.info.cwdExists&&(0,n.jsxs)("div",{className:"my-3 rounded-[7px] border border-[rgba(248,113,113,0.35)] bg-[rgba(248,113,113,0.07)] px-3 py-2 text-[12px] leading-relaxed text-red-400",children:["Project directory no longer exists: ",(0,n.jsx)("code",{className:"font-mono",children:F.info.cwd})]}),eb&&(0,n.jsx)("div",{className:"my-3 rounded-[7px] border border-[rgba(248,113,113,0.35)] bg-[rgba(248,113,113,0.07)] px-3 py-2 text-[12px] leading-relaxed text-red-400",children:eb}),q&&(0,n.jsx)("div",{style:{height:eD.current?eD.current.clientHeight:"80vh"}}),(0,n.jsx)("div",{ref:ez})]})}),!tk&&(0,n.jsx)(et,{messages:K,streamingMessage:V.streamingMessage,scrollContainer:eD,messageRefs:tv}),tz.length>0&&(0,n.jsxs)("button",{onClick:()=>tS(e=>!e),title:tw?"Hide subagent runs":"Show subagent runs",style:{position:"absolute",right:tk?8:tw?260:40,top:8,minWidth:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:tI>0||tz.length>1?"0 8px":0,background:tw?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:tw?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:e=>{tw||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{tw||(e.currentTarget.style.color="var(--text-dim)")},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,n.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,n.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),(tI>0||tz.length>1)&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,color:tI>0?"var(--accent)":"var(--text-dim)"},children:[tI>0&&(0,n.jsxs)("span",{children:[tI," active"]}),(0,n.jsx)("span",{children:tz.length})]})]}),tw&&tz.length>0&&(0,n.jsxs)("div",{style:{position:"absolute",right:tk?8:48,top:4,bottom:4,width:tk?"calc(100vw - 16px)":250,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"-2px 0 12px rgba(0,0,0,0.08)",zIndex:25,overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 12px",fontSize:11,fontWeight:600,color:"var(--text-dim)",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Subagents"}),(0,n.jsx)(es,{runs:tz})]})]}),(0,n.jsx)("div",{className:"relative",children:tA})]}),tx&&(0,n.jsxs)("div",{style:{position:"fixed",inset:0,zIndex:100,background:"rgba(0,0,0,0.85)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out"},onClick:()=>tg(null),children:[tx.gallery&&tx.gallery.length>1&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{style:{position:"absolute",left:16,top:"50%",transform:"translateY(-50%)",background:"rgba(255,255,255,0.15)",border:"none",borderRadius:8,color:"#fff",fontSize:28,width:44,height:44,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:101},onClick:e=>{e.stopPropagation();let t=((tx.index??0)-1+tx.gallery.length)%tx.gallery.length;tg({...tx,src:tx.gallery[t].src,index:t})},children:"←"}),(0,n.jsx)("button",{style:{position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",background:"rgba(255,255,255,0.15)",border:"none",borderRadius:8,color:"#fff",fontSize:28,width:44,height:44,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:101},onClick:e=>{e.stopPropagation();let t=((tx.index??0)+1)%tx.gallery.length;tg({...tx,src:tx.gallery[t].src,index:t})},children:"→"})]}),(0,n.jsx)("img",{src:tx.src,alt:"",style:{maxWidth:"95vw",maxHeight:"95vh",objectFit:"contain",borderRadius:8,boxShadow:"0 8px 40px rgba(0,0,0,0.5)"}}),(0,n.jsx)("div",{style:{position:"absolute",bottom:16,left:"50%",transform:"translateX(-50%)",background:"rgba(0,0,0,0.5)",color:"rgba(255,255,255,0.7)",borderRadius:6,padding:"4px 12px",fontSize:12},children:tx.gallery&&tx.gallery.length>1?`${(tx.index??0)+1} / ${tx.gallery.length}`:"Click anywhere to close"})]})]})}var eJ=r(25618),eV=r(76577);class eq extends i.Component{static getDerivedStateFromError(e){return{hasError:!0,message:e instanceof Error?e.message:String(e)}}componentDidCatch(e,t){console.error("File viewer crashed",{filePath:this.props.filePath,error:e,componentStack:t.componentStack})}componentDidUpdate(e){e.filePath!==this.props.filePath&&this.state.hasError&&this.setState({hasError:!1,message:null})}render(){return this.state.hasError?(0,n.jsx)(eV.fj,{style:{background:"var(--bg)"},children:(0,n.jsx)(eV.nG,{tone:"error",children:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,alignItems:"center",textAlign:"center"},children:[(0,n.jsx)("div",{children:"Preview crashed for this file."}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",maxWidth:560,wordBreak:"break-word"},children:this.props.filePath}),this.state.message&&(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",maxWidth:560,wordBreak:"break-word"},children:this.state.message})]})})}):this.props.children}constructor(...e){super(...e),this.state={hasError:!1,message:null}}}function eY(e,t,r){return Math.min(Math.max(e,t),r)}function eG({id:e,filePath:t,fileName:r,cwd:o,active:l,stackIndex:s,zIndex:a,onClose:d,onFocus:c,onOpenFile:p}){let[u,h]=(0,i.useState)(()=>{let e,t,r,n,i,o,l;return e=window.innerWidth,t=window.innerHeight,n=(r=e<720||t<560)?8:36,o=Math.max(320,e-2*n-(i=r?0:s%6*28)),l=Math.max(260,t-2*n-i),{left:n+i,top:n+i,width:r?o:Math.min(1180,o),height:r?l:Math.min(820,l),maximized:!1}}),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(!1),m=(0,i.useRef)(null),y=(0,i.useRef)(null),b=(0,i.useRef)(null);(0,i.useEffect)(()=>{l&&m.current?.focus({preventScroll:!0})},[l]),(0,i.useEffect)(()=>{let e=()=>{h(e=>{if(e.maximized)return e;let t=Math.max(320,window.innerWidth-16),r=Math.max(260,window.innerHeight-16),n=Math.min(e.width,t),i=Math.min(e.height,r);return{...e,width:n,height:i,left:eY(e.left,8,Math.max(8,window.innerWidth-n-8)),top:eY(e.top,8,Math.max(8,window.innerHeight-i-8))}})};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let j=(0,i.useCallback)(t=>{c(e),0!==t.button||u.maximized||(t.preventDefault(),t.currentTarget.setPointerCapture(t.pointerId),y.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,left:u.left,top:u.top},g(!0))},[u.left,u.maximized,u.top,e,c]),k=(0,i.useCallback)(e=>{let t=y.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.left+e.clientX-t.startX,n=t.top+e.clientY-t.startY;h(e=>({...e,left:eY(r,8,Math.max(8,window.innerWidth-120)),top:eY(n,8,Math.max(8,window.innerHeight-48))}))},[]),w=(0,i.useCallback)(e=>{let t=y.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),y.current=null,g(!1))},[]),S=(0,i.useCallback)(()=>{c(e),h(e=>({...e,maximized:!e.maximized}))},[e,c]),C=(0,i.useCallback)(t=>{c(e),0!==t.button||u.maximized||(t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture(t.pointerId),b.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,width:u.width,height:u.height},v(!0))},[u.height,u.maximized,u.width,e,c]),T=(0,i.useCallback)(e=>{let t=b.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.width+e.clientX-t.startX,n=t.height+e.clientY-t.startY;h(e=>({...e,width:eY(r,360,Math.max(360,window.innerWidth-e.left-8)),height:eY(n,280,Math.max(280,window.innerHeight-e.top-8))}))},[]),z=(0,i.useCallback)(e=>{let t=b.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),b.current=null,v(!1))},[]),I=u.maximized?{position:"fixed",inset:12,zIndex:a}:{position:"fixed",left:u.left,top:u.top,width:u.width,height:u.height,zIndex:a};return(0,n.jsxs)("div",{ref:m,role:"dialog","aria-label":`Preview ${r}`,tabIndex:-1,onPointerDown:()=>c(e),onKeyDown:t=>{"Escape"===t.key&&d(e)},style:{...I,display:"flex",flexDirection:"column",minWidth:u.maximized?void 0:360,minHeight:u.maximized?void 0:280,background:"var(--bg)",border:l?"1px solid rgba(37,99,235,0.55)":"1px solid var(--border)",borderRadius:8,boxShadow:l?"0 18px 60px rgba(0,0,0,0.26)":"0 10px 34px rgba(0,0,0,0.20)",overflow:"hidden",outline:"none"},children:[(0,n.jsxs)("div",{onPointerDown:j,onPointerMove:k,onPointerUp:w,onPointerCancel:w,style:{height:34,display:"flex",alignItems:"center",gap:8,padding:"0 8px 0 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",cursor:u.maximized?"default":x?"grabbing":"grab",flexShrink:0,userSelect:"none"},children:[(0,n.jsx)("div",{style:{minWidth:0,flex:1},children:(0,n.jsx)("div",{title:t,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:650,color:"var(--text)"},children:r})}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:S,title:u.maximized?"Restore preview":"Maximize preview","aria-label":u.maximized?"Restore preview":"Maximize preview",style:eZ,children:u.maximized?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M6 3.5h6.5V10"}),(0,n.jsx)("path",{d:"M3.5 6H10v6.5H3.5z"})]}):(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M4 4h8v8H4z"})})}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>d(e),title:"Close preview","aria-label":"Close preview",style:eZ,children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"4",y1:"4",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"4",x2:"4",y2:"12"})]})})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflow:"hidden",background:"var(--bg)"},children:(0,n.jsx)(eq,{filePath:t,children:(0,n.jsx)(eJ.h,{filePath:t,cwd:o,onOpenFile:p})})}),!u.maximized&&(0,n.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize preview",title:"Resize preview",onPointerDown:C,onPointerMove:T,onPointerUp:z,onPointerCancel:z,style:{position:"absolute",right:0,bottom:0,width:18,height:18,cursor:"nwse-resize",color:"var(--text-dim)",display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:3,background:"linear-gradient(135deg, transparent 0 48%, rgba(127,127,127,0.18) 48% 52%, transparent 52% 100%)"}})]})}let eZ={width:26,height:24,padding:0,border:"1px solid transparent",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},eX="var(--text-dim)";function eQ({size:e=14,open:t=!1}){return t?(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5h7.5v1H1V4.5Z",fill:eX}),(0,n.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:eX,strokeWidth:"1",fill:eX,fillOpacity:"0.12"})]}):(0,n.jsx)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5H14a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4.5Z",stroke:eX,strokeWidth:"1",fill:eX,fillOpacity:"0.1"})})}function e0({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("path",{d:"M3 2h7l3 3v9H3V2Z",stroke:eX,strokeWidth:"1",fill:eX,fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:eX,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function e1({label:e,size:t=14}){let r=t/14;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:eX,strokeWidth:"0.9",fill:eX,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:eX,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("text",{x:"7",y:"9.5",textAnchor:"middle",fontSize:3.4*r,fontFamily:"var(--font-mono), monospace",fontWeight:"600",fill:eX,letterSpacing:"0",children:e})]})}function e2({size:e=14}){return(0,n.jsx)(e1,{label:"TS",size:e})}function e5({size:e=14}){return(0,n.jsx)(e1,{label:"TSX",size:e})}function e4({size:e=14}){return(0,n.jsx)(e1,{label:"JS",size:e})}function e3({size:e=14}){return(0,n.jsx)(e1,{label:"JSX",size:e})}function e8({size:e=14}){return(0,n.jsx)(e1,{label:"PY",size:e})}function e6({size:e=14}){return(0,n.jsx)(e1,{label:"{}",size:e})}function e7({size:e=14}){return(0,n.jsx)(e1,{label:"CSS",size:e})}function e9({size:e=14}){return(0,n.jsx)(e1,{label:"SC",size:e})}function te({size:e=14}){return(0,n.jsx)(e1,{label:"HTM",size:e})}function tt({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:eX,strokeWidth:"0.9",fill:eX,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:eX,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:eX,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:eX,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function tr({size:e=14}){return(0,n.jsx)(e1,{label:"YML",size:e})}function tn({size:e=14}){return(0,n.jsx)(e1,{label:"TOM",size:e})}function ti({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:eX,strokeWidth:"0.9",fill:eX,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:eX,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:eX,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M7.5 10.5h2.5",stroke:eX,strokeWidth:"0.95",strokeLinecap:"round"})]})}function to({size:e=14}){return(0,n.jsx)(e1,{label:"RS",size:e})}function tl({size:e=14}){return(0,n.jsx)(e1,{label:"GO",size:e})}function ts({size:e=14}){return(0,n.jsx)(e1,{label:"SQL",size:e})}function ta({size:e=14}){return(0,n.jsx)(e1,{label:"GQL",size:e})}function td({size:e=14}){return(0,n.jsx)(e1,{label:"TF",size:e})}function tc({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:eX,strokeWidth:"0.9",fill:eX,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:eX,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("rect",{x:"3.5",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:eX,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:eX,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:eX,strokeWidth:"0.8"})]})}function tp({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:eX,strokeWidth:"0.9",fill:eX,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:eX,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:eX,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:eX,strokeWidth:"0.9",strokeLinecap:"round"})]})}function tu({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:eX,strokeWidth:"0.9",fill:eX,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:eX,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:eX,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:eX,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:eX,strokeWidth:"0.85"}),(0,n.jsx)("path",{d:"M5 7.5V9",stroke:eX,strokeWidth:"0.85",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:eX,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function th({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:eX,strokeWidth:"0.9",fill:eX,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:eX,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("rect",{x:"4.5",y:"8.5",width:"5",height:"3",rx:"0.6",stroke:eX,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:eX,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function tx({size:e=14}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,n.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:eX,strokeWidth:"0.9",fill:eX,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:eX,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:eX,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 6.5v.7M7 10.3v.7M5 8.5h.7M8.3 8.5H9M5.5 6.9l.5.5M8.5 9.6l-.5-.5M5.5 10.1l.5-.5M8.5 7.4l-.5.5",stroke:eX,strokeWidth:"0.8",strokeLinecap:"round"})]})}function tg(e,t=14){let r=e.toLowerCase(),i=r.split(".").pop()??"";if("dockerfile"===r||r.startsWith("dockerfile."))return(0,n.jsx)(tc,{size:t});if(".env"===r||r.startsWith(".env."))return(0,n.jsx)(tp,{size:t});if(".gitignore"===r||".gitattributes"===r||".gitmodules"===r)return(0,n.jsx)(tu,{size:t});if("package-lock.json"===r||"yarn.lock"===r||"bun.lock"===r||"pnpm-lock.yaml"===r||"cargo.lock"===r)return(0,n.jsx)(th,{size:t});if(r.endsWith(".config.ts")||r.endsWith(".config.js")||r.endsWith(".config.mjs")||r.endsWith(".config.cjs")||[".eslintrc",".eslintrc.js",".eslintrc.json",".eslintrc.yml","eslint.config.mjs","eslint.config.js"].includes(r))return(0,n.jsx)(tx,{size:t});switch(i){case"ts":return(0,n.jsx)(e2,{size:t});case"tsx":return(0,n.jsx)(e5,{size:t});case"js":case"mjs":case"cjs":return(0,n.jsx)(e4,{size:t});case"jsx":return(0,n.jsx)(e3,{size:t});case"py":return(0,n.jsx)(e8,{size:t});case"json":case"jsonl":return(0,n.jsx)(e6,{size:t});case"css":case"less":return(0,n.jsx)(e7,{size:t});case"scss":return(0,n.jsx)(e9,{size:t});case"html":case"htm":return(0,n.jsx)(te,{size:t});case"md":case"mdx":return(0,n.jsx)(tt,{size:t});case"yaml":case"yml":return(0,n.jsx)(tr,{size:t});case"toml":return(0,n.jsx)(tn,{size:t});case"sh":case"bash":case"zsh":case"fish":return(0,n.jsx)(ti,{size:t});case"rs":return(0,n.jsx)(to,{size:t});case"go":return(0,n.jsx)(tl,{size:t});case"sql":return(0,n.jsx)(ts,{size:t});case"graphql":case"gql":return(0,n.jsx)(ta,{size:t});case"tf":case"hcl":return(0,n.jsx)(td,{size:t});case"lock":return(0,n.jsx)(th,{size:t});default:return(0,n.jsx)(e0,{size:t})}}async function tf(e){let t=(0,eg.HG)(e),r=await fetch(`/api/files/${t}?type=list`);return r.ok?((await r.json()).entries??[]).map(t=>({name:t.name,fullPath:(0,eg.e_)(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir})):[]}function tv(e,t){let r=t.trim().toLowerCase();return!!(!r||e.name.toLowerCase().includes(r))||(e.children??[]).some(e=>tv(e,r))}function tm(e){return!!Array.from(e.types).includes("Files")||Array.from(e.items).some(e=>"file"===e.kind)}function ty(e){return Array.from(e.files).filter(e=>!!e.name)}function tb(e,t){return e===t?".":(0,eg.qP)(e,t)}function tj({node:e,depth:t,cwd:r,onOpenFile:o,onExploreFile:l,onAtMention:s,expandedPaths:a,onToggleExpanded:d,onUploadFiles:c,uploadTargetPath:p,refreshKey:u,searchQuery:h}){let x=!!h?.trim(),g=x?e.isDir:a.has(e.fullPath),[f,v]=(0,i.useState)(e.children??[]),[m,y]=(0,i.useState)(e.loaded??!1),[b,j]=(0,i.useState)(!1),[k,w]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!1),T=e.isDir&&(S||p===e.fullPath),z=!!s&&k,I=!!l&&k&&!e.isDir&&e.name.toLowerCase().endsWith(".h5ad"),M=z||I,R=x?f.filter(e=>tv(e,h??"")):f,W=(0,i.useCallback)(async(t=!1)=>{if(!m||t){j(!0);try{let t=await tf(e.fullPath);v(t),y(!0)}catch{}finally{j(!1)}}},[m,e.fullPath]),L=(0,i.useRef)(m);(0,i.useEffect)(()=>{L.current=m}),(0,i.useEffect)(()=>{g&&m&&W(!0)},[u]);let E=(0,i.useCallback)(()=>{if(e.isDir){let t=!g;d(e.fullPath,t),t&&!m&&W()}else o(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,m,g,W,o,d]),$=(0,i.useCallback)(t=>{e.isDir&&tm(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy",C(!0))},[e.isDir]),P=(0,i.useCallback)(t=>{e.isDir&&tm(t.dataTransfer)&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy")},[e.isDir]),D=(0,i.useCallback)(t=>{if(!e.isDir)return;let r=t.relatedTarget;r instanceof Node&&t.currentTarget.contains(r)||C(!1)},[e.isDir]),A=(0,i.useCallback)(t=>{if(!e.isDir||!tm(t.dataTransfer))return;t.preventDefault(),t.stopPropagation(),C(!1);let r=ty(t.dataTransfer);r.length>0&&(c(r,e.fullPath),g||d(e.fullPath,!0),m||W())},[W,m,e.fullPath,e.isDir,d,c,g]);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:E,onMouseEnter:()=>w(!0),onMouseLeave:()=>w(!1),onDragEnter:$,onDragOver:P,onDragLeave:D,onDrop:A,style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:M?z&&I?146:82:8,height:24,cursor:"pointer",background:T?"rgba(37,99,235,0.14)":k?"var(--bg-hover)":"transparent",outline:T?"1px solid rgba(37,99,235,0.42)":"none",outlineOffset:-1,borderRadius:4,userSelect:"none",transition:"background 0.12s, outline-color 0.12s"},children:[e.isDir&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:g?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),!e.isDir&&(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,n.jsx)(eQ,{size:14,open:g}):tg(e.name,14)}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:e.fullPath,children:e.name}),b&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),M&&(0,n.jsxs)("div",{style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",gap:4},children:[I&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),l?.(e.fullPath,e.name)},title:"Explore H5AD",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,n.jsx)("path",{d:"M16 16l4 4"}),(0,n.jsx)("path",{d:"M8.5 11h5"}),(0,n.jsx)("path",{d:"M11 8.5v5"})]}),"@explore"]}),z&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),s?.((0,eg.qP)(e.fullPath,r))},title:"Insert path into chat",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]}),"@mention"]})]})]}),e.isDir&&g&&(0,n.jsxs)("div",{children:[R.map(e=>(0,n.jsx)(tj,{node:e,depth:t+1,cwd:r,onOpenFile:o,onExploreFile:l,onAtMention:s,expandedPaths:a,onToggleExpanded:d,onUploadFiles:c,uploadTargetPath:p,refreshKey:u,searchQuery:h},e.fullPath)),0===R.length&&m&&!x&&(0,n.jsx)("div",{style:{paddingLeft:8+(t+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"})]})]})}function tk({cwd:e,onOpenFile:t,onExploreFile:r,refreshKey:o,onAtMention:l,searchQuery:s="",onSearchChange:a}){let[d,c]=(0,i.useState)([]),[p,u]=(0,i.useState)(!0),[h,x]=(0,i.useState)(null),[g,f]=(0,i.useState)(new Set),[v,m]=(0,i.useState)(!1),[y,b]=(0,i.useState)(null),[j,k]=(0,i.useState)(null),w=(0,i.useRef)(null),S=(0,i.useRef)(null),C=(0,i.useRef)(0),T=(0,i.useCallback)((e,t)=>(u(t),x(null),tf(e).then(e=>c(e)).catch(e=>x(String(e))).finally(()=>u(!1))),[]),z=(0,i.useCallback)((e,t)=>{f(r=>{let n=new Set(r);return t?n.add(e):n.delete(e),n})},[]);(0,i.useEffect)(()=>{let t=w.current!==e;w.current=e,t&&f(new Set),T(e,t)},[e,o,T]),(0,i.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]);let I=(0,i.useCallback)(()=>{T(e,0===d.length)},[e,d.length,T]),M=(0,i.useCallback)(()=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>k(null),5e3)},[]),R=(0,i.useCallback)((t,r)=>{if(0===t.length)return;C.current=0,m(!1),S.current&&clearTimeout(S.current);let n=t.reduce((e,t)=>e+t.size,0),i=tb(r,e);b(r),k({phase:"uploading",targetPath:r,fileCount:t.length,loaded:0,total:n,message:`Uploading ${t.length} file${1===t.length?"":"s"} to ${i}`});let o=new FormData;t.forEach(e=>o.append("files",e,e.name));let l=new XMLHttpRequest,s=(0,eg.HG)(r);l.open("POST",`/api/files/${s}?type=upload`),l.upload.onprogress=e=>{e.lengthComputable&&k(t=>t?{...t,loaded:e.loaded,total:e.total}:t)},l.onload=()=>{b(null);let e={};try{e=JSON.parse(l.responseText)}catch{e={}}if(l.status>=200&&l.status<300){let o=e.uploaded??[],l=e.failed??[],s=[...o.filter(e=>e.name!==e.originalName).slice(0,3).map(e=>`${e.originalName} saved as ${e.name}`),...l.slice(0,3).map(e=>`${e.name}: ${e.error}`)];k({phase:l.length>0?"warning":"success",targetPath:r,fileCount:t.length,loaded:n,total:n,message:l.length>0?`Uploaded ${o.length}, ${l.length} failed`:`Uploaded ${o.length} file${1===o.length?"":"s"} to ${i}`,details:s}),I(),M()}else{let i=e.error??`Upload failed (HTTP ${l.status})`;k({phase:(l.status,"error"),targetPath:r,fileCount:t.length,loaded:0,total:n,message:i,details:403===l.status?["Check directory write permission or project access."]:void 0}),M()}},l.onerror=()=>{b(null),k({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload failed due to a network error"}),M()},l.onabort=()=>{b(null),k({phase:"error",targetPath:r,fileCount:t.length,loaded:0,total:n,message:"Upload canceled"}),M()},l.send(o)},[e,I,M]),W=(0,i.useCallback)(e=>{tm(e.dataTransfer)&&(e.preventDefault(),C.current+=1,m(!0))},[]),L=(0,i.useCallback)(e=>{tm(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")},[]),E=(0,i.useCallback)(()=>{C.current-=1,C.current<=0&&(C.current=0,m(!1))},[]),$=(0,i.useCallback)(t=>{if(!tm(t.dataTransfer))return;t.preventDefault(),C.current=0,m(!1);let r=ty(t.dataTransfer);r.length>0&&R(r,e)},[e,R]),P=s.trim()?d.filter(e=>tv(e,s)):d,D=s.trim().length>0;return p?(0,n.jsx)(tw,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:W,onDragOver:L,onDragLeave:E,onDrop:$,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."})}):h?(0,n.jsx)(tw,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:W,onDragOver:L,onDragLeave:E,onDrop:$,children:(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:h})}):(0,n.jsx)(tw,{cwd:e,isDraggingFiles:v,uploadState:j,onDragEnter:W,onDragOver:L,onDragLeave:E,onDrop:$,children:(0,n.jsxs)("div",{style:{padding:"2px 4px"},children:[P.map(i=>(0,n.jsx)(tj,{node:i,depth:0,cwd:e,onOpenFile:t,onExploreFile:r,onAtMention:l,expandedPaths:g,onToggleExpanded:z,onUploadFiles:R,uploadTargetPath:y,refreshKey:o,searchQuery:s},i.fullPath)),0===P.length&&(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:D?"No matching files":"No files found"})]})})}function tw({cwd:e,isDraggingFiles:t,uploadState:r,onDragEnter:i,onDragOver:o,onDragLeave:l,onDrop:s,children:a}){let d=r&&r.total>0?Math.max(0,Math.min(100,Math.round(r.loaded/r.total*100))):r?.phase==="uploading"?8:100,c=r?.phase==="success"?"#22c55e":r?.phase==="warning"?"#f59e0b":r?.phase==="error"?"#ef4444":"var(--accent)";return(0,n.jsxs)("div",{onDragEnter:i,onDragOver:o,onDragLeave:l,onDrop:s,style:{position:"relative",display:"flex",flexDirection:"column",height:"100%",minHeight:0,outline:t?"1px solid rgba(37,99,235,0.45)":"none",outlineOffset:-1,background:t?"rgba(37,99,235,0.04)":void 0,transition:"background 0.12s, outline-color 0.12s"},children:[(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",overscrollBehavior:"contain",scrollbarWidth:"thin"},children:a}),t&&(0,n.jsx)("div",{style:{pointerEvents:"none",position:"absolute",inset:6,top:42,border:"1px dashed rgba(37,99,235,0.62)",borderRadius:8,background:"rgba(37,99,235,0.07)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:2},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontSize:12,boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"17 8 12 3 7 8"}),(0,n.jsx)("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),"Drop to upload into ",tb(e,e)]})}),r&&(0,n.jsxs)("div",{style:{margin:"6px",padding:"7px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:999,background:c,flexShrink:0}}),(0,n.jsx)("span",{title:r.message,style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11,fontWeight:600},children:r.message}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,flexShrink:0},children:"uploading"===r.phase?`${d}%`:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],r=e,n=0;for(;r>=1024&&n<t.length-1;)r/=1024,n+=1;return`${r>=10||0===n?Math.round(r):r.toFixed(1)} ${t[n]}`}(r.total)})]}),(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,background:"var(--bg)",overflow:"hidden"},children:(0,n.jsx)("div",{style:{width:`${d}%`,height:"100%",borderRadius:999,background:c,transition:"width 0.15s ease"}})}),r.details&&r.details.length>0&&(0,n.jsx)("div",{style:{marginTop:5,display:"grid",gap:2},children:r.details.map(e=>(0,n.jsx)("div",{title:e,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:e},e))})]})]})}function tS({cwd:e,refreshKey:t=0,onOpenFile:r,onExploreFile:o,onAtMention:l}){let[s,a]=(0,i.useState)(""),[d,c]=(0,i.useState)(0);return(0,i.useEffect)(()=>{c(e=>e+1)},[t]),(0,n.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--bg)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"9px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Files"}),(0,n.jsx)("div",{title:e??"",style:{marginTop:2,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:e??"No project selected"})]}),(0,n.jsx)("button",{type:"button",onClick:()=>c(e=>e+1),disabled:!e,title:"Refresh files",style:{width:28,height:28,padding:0,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:e?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center",opacity:e?1:.55},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.3 6.4"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.3 5.6"}),(0,n.jsx)("path",{d:"M18 2v4h4"}),(0,n.jsx)("path",{d:"M6 22v-4H2"})]})})]}),(0,n.jsxs)("div",{style:{position:"relative",marginTop:9},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",left:8,top:"50%",transform:"translateY(-50%)",color:"var(--text-dim)",pointerEvents:"none"},"aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,n.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]}),(0,n.jsx)("input",{value:s,onChange:e=>a(e.target.value),placeholder:"Filter files...",disabled:!e,style:{width:"100%",height:30,boxSizing:"border-box",padding:"0 28px 0 26px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none",opacity:e?1:.6}}),s&&(0,n.jsx)("button",{type:"button",onClick:()=>a(""),title:"Clear filter",style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",width:20,height:20,display:"flex",alignItems:"center",justifyContent:"center",border:"none",borderRadius:4,background:"transparent",color:"var(--text-dim)",cursor:"pointer",padding:0},children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,n.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflow:"hidden"},children:e?(0,n.jsx)(tk,{cwd:e,onOpenFile:r,onExploreFile:o,refreshKey:d,onAtMention:l,searchQuery:s,onSearchChange:a}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:18,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"Select a project to browse files."})})]})}var tC=r(27568),tT=r(96793);let tz={__soul__:{apiPath:"/api/soul",title:"SOUL.md"},__harness__:{apiPath:"/api/harness",title:"HARNESS.md"}};function tI({filePath:e}){let t=tz[e],{isDark:r}=(0,tT.D)(),[o,l]=(0,i.useState)(""),[s,a]=(0,i.useState)(!0),[d,c]=(0,i.useState)(null),[p,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(!1);(0,i.useEffect)(()=>{t&&(a(!0),fetch(t.apiPath).then(e=>e.json()).then(e=>l(e.content??"")).catch(e=>c(String(e))).finally(()=>a(!1)))},[t]);let g=(0,i.useCallback)(async()=>{if(t){u(!0);try{await fetch(t.apiPath,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:o})}),x(!0),setTimeout(()=>x(!1),2e3)}catch(e){c(String(e))}finally{u(!1)}}},[t,o]);return t?s?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading…"}):d?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:d}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:600,color:"var(--text)"},children:t.title}),(0,n.jsx)("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--text-dim)"},children:"Global"}),h&&(0,n.jsx)("span",{style:{color:"#4ade80",fontWeight:600,animation:"saved-pop 0.3s ease"},children:"✓ Saved"}),(0,n.jsx)("button",{onClick:g,disabled:p,title:"Save (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:p?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:p?.6:1},children:p?"Saving…":"Save"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(tC.g,{initialContent:o,language:"markdown",isDark:r,onChange:l,onSave:g})})]}):null}function tM(){document.body.style.cursor="",document.body.style.userSelect=""}function tR({side:e,onResize:t,onResizeStart:r,onResizeEnd:o,ariaLabel:l}){let s=(0,i.useRef)(null),a=(0,i.useRef)(!1),d=(0,i.useRef)(0),[c,p]=(0,i.useState)(!1),u=(0,i.useCallback)(e=>{if(!a.current)return;a.current=!1,p(!1);let t=s.current;t&&void 0!==e&&t.hasPointerCapture(e)&&t.releasePointerCapture(e),tM(),o?.()},[o]),h=(0,i.useCallback)(e=>{0===e.button&&e.isPrimary&&(e.preventDefault(),a.current=!0,d.current=e.clientX,p(!0),r?.(),e.currentTarget.setPointerCapture(e.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none")},[r]),x=(0,i.useCallback)(e=>{if(!a.current)return;e.preventDefault();let r=e.clientX-d.current;d.current=e.clientX,t(r)},[t]),g=(0,i.useCallback)(e=>{e.preventDefault(),u(e.pointerId)},[u]),f=(0,i.useCallback)(e=>{u(e.pointerId)},[u]);return(0,i.useEffect)(()=>()=>{a.current&&(a.current=!1,tM(),o?.())},[o]),(0,n.jsx)("div",{ref:s,role:"separator","aria-label":l??"Resize panel","aria-orientation":"vertical",className:`resize-handle${c?" resize-handle-dragging":""}`,"data-side":e,onPointerDown:h,onPointerMove:x,onPointerUp:g,onPointerCancel:f,style:{alignSelf:"stretch",cursor:"col-resize",display:"flex",flexShrink:0,justifyContent:"center",marginLeft:-5,marginRight:-5,position:"relative",touchAction:"none",width:10,zIndex:250},children:(0,n.jsx)("div",{className:"resize-handle-line"})})}function tW(e){return"running"===e?"#22c55e":"starting"===e?"rgba(234,179,8,0.95)":"error"===e?"#ef4444":"var(--text-dim)"}function tL(e){return"h5adexp"===e?"H5AD Exp":"stexp"}function tE(e,t,r){return Math.min(Math.max(e,t),r)}function t$(e){if(!e||"object"!=typeof e||!("app"in e))return null;let t=e.app;return t&&"object"==typeof t&&"id"in t?t:null}function tP({appType:e,filePath:t,cwd:r,sessionId:o,appId:l,onClose:s,onAppChanged:a,onOpenTools:d}){var c;let[p,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[g,f]=(0,i.useState)(!1),[v,m]=(0,i.useState)(!1),[y,b]=(0,i.useState)(0),[j,k]=(0,i.useState)(()=>{let e,t,r,n,i,o;return e=window.innerWidth,t=window.innerHeight,n=(r=e<720||t<560)?8:34,i=Math.max(360,e-2*n),o=Math.max(320,t-2*n),{left:n,top:n,width:r?i:Math.min(1280,i),height:r?o:Math.min(880,o),maximized:!1}}),[w,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(!1),z=(0,i.useRef)(null),I=(0,i.useRef)(null),M=(0,i.useRef)(null),R=!!t||!!l,W=t?(0,eg.WP)(t):p?(0,eg.WP)(p.filePath):"",L=t&&r?(0,eg.qP)(t,r):p?.filePath&&p.cwd?(0,eg.qP)(p.filePath,p.cwd):t??p?.filePath??"",E=p?.status??"idle",$=(0,i.useMemo)(()=>p?.logs?.join("\n")??"",[p?.logs]),P=p?.appType==="h5adexp"?p.url:p?.directUrl??p?.url??"",D=(0,i.useCallback)(e=>{u(e),a?.(e)},[a]),A=(0,i.useCallback)(async e=>{let t=await fetch(`/api/apps?appId=${encodeURIComponent(e)}`),r=await t.json(),n=t$(r);if(!t.ok||!n)throw Error(r&&"object"==typeof r&&"error"in r?String(r.error):`HTTP ${t.status}`);return D(n),n},[D]),B=(0,i.useCallback)(async()=>{if(t&&r&&!g){f(!0),x(null);try{let n=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"start",appType:e,filePath:t,cwd:r,sessionId:o})}),i=await n.json(),l=t$(i);if(!n.ok||!l){let e=i&&"object"==typeof i&&"error"in i?String(i.error):`HTTP ${n.status}`;throw Error(e)}D(l),b(e=>e+1)}catch(e){x(e instanceof Error?e.message:String(e))}finally{f(!1)}}},[e,D,g,r,t,o]);(0,i.useEffect)(()=>{if(R){if(x(null),m(!1),l)return void A(l).then(()=>b(e=>e+1)).catch(e=>x(e instanceof Error?e.message:String(e)));u(null),B()}},[R,l,t]),(0,i.useEffect)(()=>{if(!p?.id||"stopped"===p.status||"error"===p.status)return;let e=window.setInterval(()=>{A(p.id).catch(()=>{})},2500);return()=>window.clearInterval(e)},[p?.id,p?.status,A]),(0,i.useEffect)(()=>{R&&z.current?.focus({preventScroll:!0})},[R,p?.id]),(0,i.useEffect)(()=>{let e=()=>{k(e=>{if(e.maximized)return e;let t=Math.max(360,window.innerWidth-16),r=Math.max(320,window.innerHeight-16),n=Math.min(e.width,t),i=Math.min(e.height,r);return{...e,width:n,height:i,left:tE(e.left,8,Math.max(8,window.innerWidth-n-8)),top:tE(e.top,8,Math.max(8,window.innerHeight-i-8))}})};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let N=(0,i.useCallback)(async()=>{if(p?.id&&!g){f(!0),x(null);try{let e=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"stop",appId:p.id})}),t=await e.json(),r=t$(t);if(!e.ok||!r){let r=t&&"object"==typeof t&&"error"in t?String(t.error):`HTTP ${e.status}`;throw Error(r)}D(r)}catch(e){x(e instanceof Error?e.message:String(e))}finally{f(!1)}}},[p?.id,D,g]),O=(0,i.useCallback)(e=>{0!==e.button||j.maximized||(e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),I.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,left:j.left,top:j.top},S(!0))},[j.left,j.maximized,j.top]),H=(0,i.useCallback)(e=>{let t=I.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.left+e.clientX-t.startX,n=t.top+e.clientY-t.startY;k(e=>({...e,left:tE(r,8,Math.max(8,window.innerWidth-120)),top:tE(n,8,Math.max(8,window.innerHeight-48))}))},[]),F=(0,i.useCallback)(e=>{let t=I.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),I.current=null,S(!1))},[]),_=(0,i.useCallback)(e=>{0!==e.button||j.maximized||(e.preventDefault(),e.stopPropagation(),e.currentTarget.setPointerCapture(e.pointerId),M.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,width:j.width,height:j.height},T(!0))},[j.height,j.maximized,j.width]),U=(0,i.useCallback)(e=>{let t=M.current;if(!t||t.pointerId!==e.pointerId)return;let r=t.width+e.clientX-t.startX,n=t.height+e.clientY-t.startY;k(e=>({...e,width:tE(r,420,Math.max(420,window.innerWidth-e.left-8)),height:tE(n,340,Math.max(340,window.innerHeight-e.top-8))}))},[]),K=(0,i.useCallback)(e=>{let t=M.current;t?.pointerId===e.pointerId&&(e.currentTarget.releasePointerCapture(e.pointerId),M.current=null,T(!1))},[]),J=(0,i.useCallback)(()=>{d?.(),s()},[s,d]),V=(0,i.useCallback)(()=>{k(e=>({...e,maximized:!e.maximized}))},[]);if(!R)return null;let q=j.maximized?{position:"fixed",inset:12,zIndex:900}:{position:"fixed",left:j.left,top:j.top,width:j.width,height:j.height,zIndex:900};return(0,n.jsxs)("div",{ref:z,role:"dialog","aria-label":`${p?.title??tL(e)} window`,tabIndex:-1,onKeyDown:e=>{"Escape"===e.key&&J()},style:{...q,display:"flex",flexDirection:"column",minWidth:j.maximized?void 0:420,minHeight:j.maximized?void 0:340,background:"var(--bg)",border:"1px solid rgba(37,99,235,0.5)",borderRadius:8,boxShadow:"0 18px 60px rgba(0,0,0,0.26)",overflow:"hidden",outline:"none"},children:[(0,n.jsxs)("div",{onPointerDown:O,onPointerMove:H,onPointerUp:F,onPointerCancel:F,style:{display:"flex",alignItems:"center",gap:8,padding:"8px 9px 8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0,userSelect:"none",cursor:j.maximized?"default":w?"grabbing":"grab"},children:[(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:700,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p?.title??tL(e)}),(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:tW(E),flexShrink:0}}),(0,n.jsx)("span",{style:{fontSize:11,color:tW(E),textTransform:"capitalize",flexShrink:0},children:E}),p?.pid&&(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:["pid ",p.pid]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:(c=p?.rssBytes)&&Number.isFinite(c)?c<1048576?`${(c/1024).toFixed(0)}K`:c<0x40000000?`${(c/1024/1024).toFixed(1)}M`:`${(c/1024/1024/1024).toFixed(1)}G`:"-"})]}),(0,n.jsx)("div",{title:t??p?.filePath??"",style:{marginTop:2,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:L||W})]}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>b(e=>e+1),disabled:!P||p?.status==="stopped",style:tD,title:"Reload",children:"Reload"}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>m(e=>!e),style:{...tD,background:v?"var(--bg-selected)":"var(--bg)",color:v?"var(--text)":"var(--text-muted)"},title:"Toggle logs",children:"Logs"}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:J,style:tD,title:"Show in Tools",children:"Tools"}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:()=>void N(),disabled:!p||"stopped"===p.status||g,style:{...tD,border:"1px solid rgba(239,68,68,0.35)",background:"rgba(239,68,68,0.08)",color:"#ef4444",opacity:!p||"stopped"===p.status||g?.55:1},title:"Stop process",children:"Stop"}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:J,"aria-label":"Minimize",title:"Minimize",style:tA,children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round","aria-hidden":"true",children:(0,n.jsx)("line",{x1:"4",y1:"11",x2:"12",y2:"11"})})}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:V,"aria-label":j.maximized?"Restore":"Maximize",title:j.maximized?"Restore":"Maximize",style:tA,children:j.maximized?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M6 3.5h6.5V10"}),(0,n.jsx)("path",{d:"M3.5 6H10v6.5H3.5z"})]}):(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M4 4h8v8H4z"})})}),(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.stopPropagation(),onClick:s,"aria-label":"Close window",title:"Close window",style:tA,children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"4",y1:"4",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"4",x2:"4",y2:"12"})]})})]}),(h||p?.error)&&(0,n.jsx)("div",{style:{padding:"8px 12px",borderBottom:"1px solid rgba(248,113,113,0.25)",background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:12},children:h??p?.error}),(0,n.jsxs)("div",{style:{flex:1,minHeight:0,display:"flex",background:"var(--bg)"},children:[(0,n.jsx)("div",{style:{flex:1,minWidth:0,position:"relative"},children:g&&!p?.url?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:["Starting ",tL(e),"..."]}):P&&p?.status!=="stopped"?(0,n.jsx)("iframe",{src:P,title:`${p?.title??tL(e)} - ${W}`,style:{width:"100%",height:"100%",border:"none",display:"block",background:"#fff"}},`${P}:${y}`):(0,n.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:10,color:"var(--text-muted)",fontSize:13},children:[(0,n.jsxs)("div",{children:[tL(e)," is stopped."]}),t&&r&&(0,n.jsx)("button",{type:"button",onClick:()=>void B(),disabled:g,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:g?"not-allowed":"pointer",fontSize:12,fontWeight:650},children:"Start again"})]})}),v&&(0,n.jsxs)("div",{style:{width:360,borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",display:"flex",flexDirection:"column",minHeight:0},children:[(0,n.jsx)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-muted)",fontWeight:650},children:"Process Logs"}),(0,n.jsx)("pre",{style:{flex:1,margin:0,padding:10,overflow:"auto",fontSize:11,lineHeight:1.45,color:"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap"},children:$||"No logs yet."})]})]}),!j.maximized&&(0,n.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize explore window",title:"Resize",onPointerDown:_,onPointerMove:U,onPointerUp:K,onPointerCancel:K,style:{position:"absolute",right:0,bottom:0,width:18,height:18,cursor:"nwse-resize",background:"linear-gradient(135deg, transparent 0 48%, rgba(127,127,127,0.22) 48% 52%, transparent 52% 100%)"}})]})}let tD={height:30,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,flexShrink:0},tA={width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,padding:0};function tB(e){return"running"===e?"#22c55e":"starting"===e?"rgba(234,179,8,0.95)":"error"===e?"#ef4444":"var(--text-dim)"}function tN(e){return"waiting_model"===e?"rgba(234,179,8,0.95)":"running_tools"===e?"#38bdf8":"streaming"===e?"#22c55e":"compacting"===e?"#a78bfa":"var(--text-dim)"}function tO(e){return e&&Number.isFinite(e)?e<1048576?`${(e/1024).toFixed(0)}K`:e<0x40000000?`${(e/1024/1024).toFixed(1)}M`:`${(e/1024/1024/1024).toFixed(1)}G`:"-"}function tH(e){if(!e||!Number.isFinite(e))return"-";let t=Math.max(0,Math.floor(e/1e3)),r=Math.floor(t/3600),n=Math.floor(t%3600/60),i=t%60;return r>0?`${r}h ${n}m`:n>0?`${n}m ${i}s`:`${i}s`}function tF({refreshKey:e=0,visibleAppId:t,cwd:r,onOpenApp:o,onAppChanged:l,onAppsChanged:s,agentRuntimeExtra:a}){let[d,c]=(0,i.useState)([]),[p,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[g,f]=(0,i.useState)(null),[v,m]=(0,i.useState)(null),[y,b]=(0,i.useState)(null),[j,k]=(0,i.useState)(null),[w,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[z,I]=(0,i.useState)(null),M=(0,i.useMemo)(()=>[...d].sort((e,t)=>{let r=+!!e.running,n=+!!t.running;return r!==n?n-r:Date.parse(t.lastActivity)-Date.parse(e.lastActivity)}),[d]),R=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/apps",{cache:"no-store"}),t=await e.json();if(!e.ok||!Array.isArray(t.apps))throw Error(t.error??`HTTP ${e.status}`);c(t.apps),s?.(t.apps),f(null)}catch(e){f(e instanceof Error?e.message:String(e))}},[s]),W=(0,i.useCallback)(async()=>{try{let e=new URLSearchParams;r&&e.set("cwd",r);let t=await fetch(`/api/agent/runtime${e.toString()?`?${e}`:""}`,{cache:"no-store"}),n=await t.json();if(!t.ok||!Array.isArray(n.sessions))throw Error(n.error??`HTTP ${t.status}`);u(n),x(n.memory??null),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}},[r]);(0,i.useEffect)(()=>{R(),W()},[R,W,e]),(0,i.useEffect)(()=>{let e=window.setInterval(()=>{R(),W()},3e3);return()=>window.clearInterval(e)},[R,W]);let L=(0,i.useCallback)(async e=>{S(e.id),f(null);try{let t=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"stop",appId:e.id})}),r=await t.json();if(!t.ok||!r.app)throw Error(r.error??`HTTP ${t.status}`);c(e=>e.map(e=>e.id===r.app.id?r.app:e)),l?.(r.app),await R()}catch(e){f(e instanceof Error?e.message:String(e))}finally{S(null)}},[R,l]),E=(0,i.useCallback)(async e=>{T(e.sessionId),m(null);try{let t=await fetch(`/api/agent/${encodeURIComponent(e.sessionId)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"abort"})}),r=await t.json().catch(()=>({}));if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);await W()}catch(e){m(e instanceof Error?e.message:String(e))}finally{T(null)}},[W]),$=(0,i.useCallback)(async(e,t)=>{if(r){k(`${e}:${t}`),b(null);try{let n=await fetch("/api/memory/promote",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,memoryId:e,target:t})}),i=await n.json().catch(()=>({}));if(!n.ok)throw Error(i.error??`HTTP ${n.status}`);await W()}catch(e){b(e instanceof Error?e.message:String(e))}finally{k(null)}}},[r,W]),P=(0,i.useCallback)(async e=>{if(r){k(`dismiss:${e}`),b(null);try{let t=await fetch("/api/memory/dismiss",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,memoryId:e})}),n=await t.json().catch(()=>({}));if(!t.ok)throw Error(n.error??`HTTP ${t.status}`);await W()}catch(e){b(e instanceof Error?e.message:String(e))}finally{k(null)}}},[r,W]),D=d.filter(e=>e.running).length,A=d.reduce((e,t)=>e+(t.running?t.rssBytes??0:0),0),B=p?.sessions??[],N=B.filter(e=>e.busy),O=N.filter(e=>"waiting_model"===e.phase);return(0,n.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--bg)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"10px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Status"}),(0,n.jsxs)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)"},children:[N.length," agent running \xb7 ",D," explore \xb7 ",tO(A)]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>{R(),W()},style:tV,title:"Refresh status",children:"Refresh"})]}),g&&(0,n.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:g}),v&&(0,n.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:v}),y&&(0,n.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:y})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",padding:10},children:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[(0,n.jsxs)("section",{children:[(0,n.jsx)(t_,{title:"Agent Runtime",subtitle:O.length>0?`${O.length} waiting for model first token`:`${N.length} active chat${1===N.length?"":"s"}`}),a,0===B.length?(0,n.jsx)(tU,{label:"No agent runtime is active."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:B.map(e=>{var t;let r=e.model?`${e.model.provider}/${e.model.id}`:"-",i=e.cwd?(0,eg.WP)(e.cwd)||e.cwd:"-",o=e.activeTools.map(e=>e.name).join(", ");return(0,n.jsxs)("div",{style:{border:`1px solid ${e.busy?"rgba(37,99,235,0.35)":"var(--border)"}`,borderRadius:8,background:e.busy?"var(--bg-selected)":"var(--bg-panel)",padding:10},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:tN(e.phase),marginTop:5,flexShrink:0}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:tN(e.phase),textTransform:"uppercase",flexShrink:0},children:"waiting_model"===(t=e.phase)?"waiting model":"running_tools"===t?"running tools":"streaming"===t?"streaming":"compacting"===t?"compacting":"idle"}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:r,children:r})]}),(0,n.jsxs)("div",{title:e.cwd??void 0,style:{marginTop:3,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[i," \xb7 ",e.sessionId.slice(0,8)]})]})]}),(0,n.jsxs)("div",{style:{marginTop:9,display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)(tK,{label:"uptime",value:tH(e.uptimeMs)}),(0,n.jsx)(tK,{label:"wait",value:tH(e.waitingForModelMs),color:"waiting_model"===e.phase?tN(e.phase):void 0}),(0,n.jsx)(tK,{label:"pending",value:null===e.pendingMessageCount?"-":String(e.pendingMessageCount)}),(0,n.jsx)(tK,{label:"event",value:e.lastEventType??"-"}),(0,n.jsx)(tK,{label:"tools",value:o||"-"}),(0,n.jsx)(tK,{label:"ops",value:e.operations.join(", ")||"-"})]}),"waiting_model"===e.phase&&(e.waitingForModelMs??0)>8e3&&(0,n.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,background:"rgba(234,179,8,0.08)",color:"rgba(234,179,8,0.95)",fontSize:11,lineHeight:1.45},children:"Waiting before the first model token. If another chat uses the same provider or gateway, the upstream may be queueing requests."}),e.errorMessage&&(0,n.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11,lineHeight:1.45},children:e.errorMessage}),(0,n.jsx)("div",{style:{marginTop:10,display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:(0,n.jsx)("button",{type:"button",onClick:()=>void E(e),disabled:!e.busy||C===e.sessionId,style:{...tV,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:e.busy&&C!==e.sessionId?1:.55},children:"Abort"})})]},e.sessionId)})})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)(t_,{title:"Memory",subtitle:h?`${h.count} stored \xb7 ${h.candidateCount} candidates`:r?"loading":"No project selected"}),r?h?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:10},children:[(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)(tK,{label:"fact",value:String(h.byType.fact)}),(0,n.jsx)(tK,{label:"context",value:String(h.byType.context)}),(0,n.jsx)(tK,{label:"decision",value:String(h.byType.decision)}),(0,n.jsx)(tK,{label:"preference",value:String(h.byType.preference)}),(0,n.jsx)(tK,{label:"note",value:String(h.byType.note)}),(0,n.jsx)(tK,{label:"candidates",value:String(h.candidateCount),color:h.candidateCount>0?"var(--accent)":void 0})]}),(0,n.jsx)("div",{title:h.filePath,style:{marginTop:8,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(0,eg.qP)(h.filePath,r)})]}),(0,n.jsx)(tJ,{title:"Promotion Candidates",emptyLabel:"No promotion candidates yet.",items:h.topCandidates,onPromote:$,onDismiss:P,busyAction:j}),(0,n.jsx)(tJ,{title:"Recent Memory",emptyLabel:"No memory stored for this project.",items:h.recent})]}):(0,n.jsx)(tU,{label:"Memory status unavailable."}):(0,n.jsx)(tU,{label:"Select a project to inspect memory status."})]}),(0,n.jsxs)("section",{children:[(0,n.jsx)(t_,{title:"Explore Tools",subtitle:`${D} running \xb7 ${tO(A)}`}),0===M.length?(0,n.jsx)(tU,{label:"No explore tools are running."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:M.map(e=>{let i,l=t===e.id,s=z===e.id;return(0,n.jsxs)("div",{style:{border:`1px solid ${l?"rgba(37,99,235,0.5)":"var(--border)"}`,borderRadius:8,background:l?"var(--bg-selected)":"var(--bg-panel)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:10},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:tB(e.status),marginTop:5,flexShrink:0}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)",textTransform:"uppercase",flexShrink:0},children:e.appType}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.filePath,children:(0,eg.WP)(e.filePath)})]}),(0,n.jsx)("div",{title:e.filePath,style:{marginTop:3,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(i=r&&e.filePath.startsWith(r)?r:e.cwd,(0,eg.qP)(e.filePath,i))})]})]}),(0,n.jsxs)("div",{style:{marginTop:9,display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)(tK,{label:"status",value:e.status,color:tB(e.status)}),(0,n.jsx)(tK,{label:"pid",value:e.pid?String(e.pid):"-"}),(0,n.jsx)(tK,{label:"memory",value:tO(e.rssBytes)}),(0,n.jsx)(tK,{label:"uptime",value:tH(e.uptimeMs)}),(0,n.jsx)(tK,{label:"port",value:String(e.port)}),(0,n.jsx)(tK,{label:"session",value:e.sessionId?e.sessionId.slice(0,8):"-"})]}),(0,n.jsxs)("div",{style:{marginTop:10,display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>o(e),style:tV,children:"Open"}),(0,n.jsx)("button",{type:"button",onClick:()=>I(t=>t===e.id?null:e.id),style:{...tV,background:s?"var(--bg-selected)":"var(--bg)"},children:"Logs"}),(0,n.jsx)("button",{type:"button",onClick:()=>void L(e),disabled:!e.running||w===e.id,style:{...tV,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:e.running&&w!==e.id?1:.55},children:"Stop"})]})]}),s&&(0,n.jsx)("pre",{style:{maxHeight:220,overflow:"auto",margin:0,padding:10,borderTop:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",fontSize:11,lineHeight:1.45,fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap"},children:e.logs.join("\n")||"No logs yet."})]},e.id)})})]})]})})]})}function t_({title:e,subtitle:t}){return(0,n.jsxs)("div",{style:{marginBottom:8,display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:e}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]})}function tU({label:e}){return(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:"18px 10px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:e})}function tK({label:e,value:t,color:r}){return(0,n.jsxs)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:5},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",flexShrink:0},children:e}),(0,n.jsx)("span",{style:{color:r??"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:t})]})}function tJ({title:e,emptyLabel:t,items:r,onPromote:i,onDismiss:o,busyAction:l}){return(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:12,fontWeight:700,color:"var(--text)"},children:e}),0===r.length?(0,n.jsx)("div",{style:{padding:"14px 10px",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:t}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:r.map((e,t)=>(0,n.jsxs)("div",{style:{padding:"9px 10px",borderTop:0===t?"none":"1px solid var(--border)",display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:10,color:"project_memory"===e.candidate?"#f59e0b":"spark"===e.candidate?"var(--accent)":"var(--text-dim)",fontWeight:700,textTransform:"uppercase",flexShrink:0},children:"none"===e.candidate?e.memoryType:e.candidate}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",flexShrink:0},children:e.importance.toFixed(2)}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:new Date(e.timestamp).toLocaleString()})]}),(0,n.jsx)("div",{title:e.content,style:{fontSize:12,color:"var(--text)",lineHeight:1.45,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:e.content}),(i||o)&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[i&&(0,n.jsx)("button",{type:"button",disabled:e.promotedTo.includes("memory")||l===`${e.id}:memory`,onClick:()=>void i(e.id,"memory"),style:{...tV,height:24,padding:"0 8px",opacity:e.promotedTo.includes("memory")||l===`${e.id}:memory`?.55:1},children:e.promotedTo.includes("memory")?"In MEMORY.md":l===`${e.id}:memory`?"Saving...":"To MEMORY.md"}),o&&(0,n.jsx)("button",{type:"button",disabled:l===`dismiss:${e.id}`||l===`${e.id}:memory`,onClick:()=>void o(e.id),style:{...tV,height:24,padding:"0 8px",opacity:l===`dismiss:${e.id}`||l===`${e.id}:memory`?.55:1,borderColor:"var(--text-dim)",color:"var(--text-dim)"},children:l===`dismiss:${e.id}`?"Dismissing…":"Ignore"})]})]},e.id))})]})}let tV={height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:550};function tq({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:o,onAskAI:l}){let[s,a]=(0,i.useState)(null);return(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:e.map(e=>{let i=e.id===t,d=!1!==e.closable;return(0,n.jsxs)("div",{onClick:()=>r(e.id),style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:i?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:i?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,n.jsx)("span",{style:{flexShrink:0,opacity:i?1:.7,display:"flex",alignItems:"center"},children:"files"===e.icon?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 7.5V6a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v1.5"}),(0,n.jsx)("path",{d:"M3 7.5h18l-1.6 9.6A2 2 0 0 1 17.4 19H6.6a2 2 0 0 1-2-1.9z"})]}):"report"===e.icon?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,n.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,n.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}):"tools"===e.icon?(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.1-3.1a6 6 0 0 1-7.9 7.9l-5.7 5.7a2.1 2.1 0 0 1-3-3l5.7-5.7a6 6 0 0 1 7.9-7.9z"})}):tg(e.filePath??e.label,13)}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:i?500:400},title:e.filePath??e.label,children:e.label}),d&&(0,n.jsxs)(n.Fragment,{children:[i&&l&&e.filePath&&!e.icon&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),l(e.filePath)},title:`Ask AI about ${e.label}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:"transparent",border:"none",borderRadius:3,color:"var(--accent)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s"},children:(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M15 18H3"}),(0,n.jsx)("path",{d:"M17 6H3"}),(0,n.jsx)("path",{d:"M21 12H3"})]})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),o(e.id)},onMouseEnter:()=>a(e.id),onMouseLeave:()=>a(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:s===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:s===e.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:"Close",children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,n.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]})]},e.id)})})}function tY(e){return"python"===e?"#3572A5":"#198CE7"}let tG=new Set(["png","jpg","jpeg","webp","gif","svg"]);function tZ(e){let t=e.split("/").filter(Boolean).map(encodeURIComponent);return`/api/files/${t.join("/")}?type=read&raw=1`}function tX(e){return!Number.isFinite(e)||e<=0?"0.0G":`${(e/1024/1024/1024).toFixed(1)}G`}function tQ({active:e,label:t,count:r,onClick:i}){return(0,n.jsxs)("button",{type:"button",onClick:i,style:{height:26,padding:"0 9px",border:`1px solid ${e?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:5,background:e?"var(--bg-selected)":"var(--bg)",color:e?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[t,"number"==typeof r?` (${r})`:""]})}let t0={height:24,padding:"0 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:10,fontWeight:600,whiteSpace:"nowrap"};function t1({status:e}){return(0,n.jsx)("span",{style:{color:"succeeded"===e?"#34d399":"failed"===e?"#f87171":"var(--text-dim)",fontSize:10,fontWeight:700,fontFamily:"var(--font-mono)"},children:"succeeded"===e?"✅":"failed"===e?"❌":"⬜"})}function t2({sessionId:e,cwd:t,onAskAboutCell:r,onAskAboutArtifact:o,onEditArtifact:l,onOpenArtifact:s}){let[a,d]=(0,i.useState)(null),[c,p]=(0,i.useState)(!0),[u,h]=(0,i.useState)(null),[x,g]=(0,i.useState)(new Set),[f,v]=(0,i.useState)("runs"),[m,y]=(0,i.useState)(null),[b,j]=(0,i.useState)(!1),[k,w]=(0,i.useState)(null),[S,C]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!e)return;let t=!1;p(!0),h(null),w(null),y(null),v("runs");let r=()=>{t||fetch(`/api/sessions/${encodeURIComponent(e)}/kernel-state`).then(async e=>{let r=await e.json().catch(()=>({}));if(!e.ok||r.error)throw Error(r.error??`HTTP ${e.status}`);t||d(r)}).catch(e=>{t||h(e instanceof Error?e.message:String(e))}).finally(()=>{t||p(!1)})};r();let n=window.setInterval(r,15e3);return()=>{t=!0,window.clearInterval(n)}},[e]);let T=(0,i.useCallback)(async()=>{if(e)try{let r=new URLSearchParams;r.set("sessionId",e),t&&r.set("cwd",t);let n=await fetch(`/api/plot-kernels/status?${r}`),i=await n.json();if(!n.ok||i.error)throw Error(i.error??`HTTP ${n.status}`);y(i)}catch{}},[e,t]);(0,i.useEffect)(()=>{T();let e=window.setInterval(T,8e3);return()=>window.clearInterval(e)},[T]);let z=(0,i.useCallback)(async()=>{if(!b&&e){j(!0),w(null);try{let t=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:e})}),r=await t.json();if(!t.ok||!r.success)throw Error(r.error??`HTTP ${t.status}`);y(null)}catch(e){w(e instanceof Error?e.message:String(e))}finally{j(!1)}}},[e,b]),I=(0,i.useCallback)(async()=>{if(e){C(!0);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/workbench-review`),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);d(e=>e?{...e,review:r}:e)}catch{}finally{C(!1)}}},[e]),M=(0,i.useCallback)(()=>{if(!a||0===a.cells.length)return;let t="r"===a.language?"R":"python",r=new Blob([JSON.stringify({nbformat:4,nbformat_minor:5,metadata:{kernelspec:{display_name:"R"===t?"R":"Python 3",language:t.toLowerCase(),name:"R"===t?"ir":"python3"},language_info:{name:t.toLowerCase()}},cells:a.cells.map(e=>{let t=[];for(let r of(e.stdoutPreview&&t.push({output_type:"stream",name:"stdout",text:e.stdoutPreview}),e.stderrPreview&&t.push({output_type:"stream",name:"stderr",text:e.stderrPreview}),e.artifacts)){let e=r.path.split(".").pop()?.toLowerCase();t.push(e&&tG.has(e)?{output_type:"display_data",data:{"image/png":""},metadata:{"annovibe-artifact":r.path}}:{output_type:"display_data",data:{"text/plain":r.path},metadata:{"annovibe-artifact":r.path}})}return{cell_type:"code",metadata:{},source:e.code.split("\n").map(e=>e+"\n"),outputs:t,execution_count:null}})},null,2)],{type:"application/x-ipynb+json"}),n=URL.createObjectURL(r),i=document.createElement("a");i.href=n,i.download=`workbench_${e.slice(0,8)}.ipynb`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(n)},[a,e]),R=(0,i.useCallback)(()=>{if(!a?.notes)return;let e=a.notes.map(e=>`#${e.cellIndex} ${e.title}
44
- ${e.summary}`).join("\n\n");navigator.clipboard.writeText(e)},[a]),W=(0,i.useMemo)(()=>a?.artifacts??[],[a]),L=(0,i.useMemo)(()=>{if(!a)return null;let e="python"===a.language?"Python":"r"===a.language?"R":"?",t=[e,a.kernelId,`${a.totalRuns} runs`].filter(Boolean).join(" \xb7 ");return{langLabel:e,subtitle:t}},[a]),E=(0,i.useMemo)(()=>m?.kernels?m.kernels.filter(t=>t.sessionId===e):[],[m,e]);if(c)return(0,n.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"Loading workbench state..."});if(u)return u.includes("no kernel state found")||u.includes("404")?(0,n.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No workbench runs yet."}):(0,n.jsxs)("div",{style:{padding:24,textAlign:"center",color:"#f87171",fontSize:12},children:["Failed to load workbench state: ",u]});if(!a||0===a.cells.length)return(0,n.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No workbench runs yet."});let{cells:$}=a,P=a.review?.issues.length??0;return(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",background:"var(--bg)",fontSize:12},children:[m&&m.currentSessionBytes>0&&(0,n.jsxs)("div",{style:{margin:10,padding:12,borderRadius:8,border:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Runtime Memory"}),(0,n.jsx)("div",{style:{marginTop:3,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:(0,n.jsxs)("span",{style:{fontSize:12,color:"var(--text)",fontVariantNumeric:"tabular-nums"},children:[(0,n.jsx)("span",{style:{color:"var(--accent)",fontWeight:600},children:tX(m.currentSessionBytes)}),m.totalBytes!==m.currentSessionBytes&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" / ",tX(m.totalBytes)," total"]})]})}),E.length>0&&(0,n.jsx)("div",{style:{marginTop:8,display:"flex",flexDirection:"column",gap:4},children:E.map((e,t)=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:[(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:tY(e.language),flexShrink:0}}),(0,n.jsx)("span",{style:{color:tY(e.language),fontWeight:600},children:e.language.toUpperCase()}),(0,n.jsx)("span",{children:tX(e.rssBytes)}),(0,n.jsxs)("span",{style:{color:"var(--text-dim)",fontSize:10},children:["PID ",e.pid]}),e.lastActivity&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto"},children:new Date(e.lastActivity).toLocaleString()})]},e.pid||t))})]}),(0,n.jsx)("button",{type:"button",onClick:z,disabled:b,style:{flexShrink:0,height:30,padding:"0 12px",border:"1px solid rgba(239,68,68,0.35)",borderRadius:6,background:b?"var(--bg)":"rgba(239,68,68,0.08)",color:b?"var(--text-dim)":"#ef4444",cursor:b?"default":"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap",opacity:b?.55:1},children:b?"Releasing...":"Release Memory"})]}),k&&(0,n.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:k})]}),L&&(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Workbench"}),(0,n.jsxs)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)"},children:[L.subtitle," \xb7 ","live"===a.freshness?"live inspected":"inferred from executed cells"]}),a.review&&(0,n.jsxs)("div",{style:{marginTop:6,fontSize:10,color:a.review.issueCounts.error>0?"#f87171":a.review.issueCounts.warning>0?"#fbbf24":"#34d399"},children:["Review: ",0===P?"no issues":`${P} traceability issues`]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexShrink:0,flexWrap:"wrap",justifyContent:"flex-end"},children:["notes"===f&&(0,n.jsx)("button",{type:"button",onClick:R,style:t0,children:"Copy"}),"review"===f&&(0,n.jsx)("button",{type:"button",onClick:I,disabled:S,style:{...t0,opacity:S?.55:1},children:S?"Reviewing...":"Refresh"}),(0,n.jsx)("button",{type:"button",onClick:M,title:"Export as Jupyter notebook",style:t0,children:"Export .ipynb"})]})]}),(0,n.jsxs)("div",{style:{marginTop:10,display:"flex",gap:6,overflowX:"auto",paddingBottom:1},children:[(0,n.jsx)(tQ,{active:"runs"===f,label:"Runs",count:$.length,onClick:()=>v("runs")}),(0,n.jsx)(tQ,{active:"artifacts"===f,label:"Artifacts",count:W.length,onClick:()=>v("artifacts")}),(0,n.jsx)(tQ,{active:"notes"===f,label:"Notes",count:a.notes?.length??$.length,onClick:()=>v("notes")}),(0,n.jsx)(tQ,{active:"review"===f,label:"Review",count:P,onClick:()=>v("review")})]}),a.imports.length>0&&"runs"===f&&(0,n.jsxs)("div",{style:{marginTop:8},children:[(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:3},children:"Historically imported:"}),(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:3},children:[a.imports.slice(0,12).map(e=>(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:3,background:"var(--bg-selected)",color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:e.length<=30?e:e.slice(0,30)+"..."},e)),a.imports.length>12&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:["+",a.imports.length-12," more"]})]})]}),("live"===a.freshness?a.liveObjects.length>0:a.loadedObjects.length>0)&&"runs"===f&&(0,n.jsxs)("div",{style:{marginTop:6},children:[(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:3},children:"live"===a.freshness?"Live objects:":"Historically loaded:"}),(0,n.jsx)("div",{children:("live"===a.freshness?a.liveObjects:a.loadedObjects).slice(0,6).map(e=>(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 6px",marginRight:4,borderRadius:3,background:"rgba(37,99,235,0.1)",color:"var(--accent)",fontFamily:"var(--font-mono)"},title:"live"===a.freshness&&"type"in e?`${e.type}${e.shape?` (${e.shape})`:""}`:void 0,children:e.name},e.name))})]})]}),"artifacts"===f&&(0,n.jsx)("div",{style:{padding:10},children:0===W.length?(0,n.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No generated artifacts yet."}):(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(150px, 1fr))",gap:8},children:W.map(e=>(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg-panel)"},children:["image"===e.kind?(0,n.jsx)("button",{type:"button",onClick:()=>s?.(e.path),style:{display:"block",width:"100%",padding:0,border:"none",background:"transparent",cursor:"pointer"},children:(0,n.jsx)("img",{src:tZ(e.path),alt:e.fileName,loading:"lazy",style:{width:"100%",height:118,objectFit:"cover",display:"block"}})}):(0,n.jsx)("button",{type:"button",onClick:()=>s?.(e.path),style:{width:"100%",height:118,border:"none",background:"var(--bg)",color:"var(--text-muted)",fontSize:11,cursor:"pointer",textTransform:"uppercase"},children:e.kind}),(0,n.jsxs)("div",{style:{padding:8},children:[(0,n.jsx)("div",{title:e.path,style:{fontSize:10,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.fileName}),(0,n.jsxs)("div",{style:{marginTop:5,display:"flex",alignItems:"center",gap:5,color:"var(--text-dim)",fontSize:10},children:[(0,n.jsxs)("span",{children:["#",e.provenance.cellIndex]}),(0,n.jsx)(t1,{status:e.provenance.status}),(0,n.jsx)("span",{children:e.provenance.language})]}),(0,n.jsxs)("div",{style:{marginTop:7,display:"flex",gap:5,flexWrap:"wrap"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>o?.(e),style:t0,children:"Ask"}),(0,n.jsx)("button",{type:"button",onClick:()=>l?.(e),style:t0,children:"Edit"}),(0,n.jsx)("button",{type:"button",onClick:()=>s?.(e.path),style:t0,children:"Open"})]})]})]},e.id))})}),"notes"===f&&(0,n.jsx)("div",{style:{padding:12},children:0===(a.notes??[]).length?(0,n.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No research notes yet."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:(a.notes??[]).map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",paddingBottom:9},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11},children:[(0,n.jsxs)("span",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",minWidth:28},children:["#",e.cellIndex]}),(0,n.jsx)(t1,{status:e.status}),(0,n.jsx)("span",{style:{color:"var(--text)",fontWeight:650,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.title})]}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-muted)",fontSize:12,lineHeight:1.45},children:e.summary})]},e.id))})}),"review"===f&&(0,n.jsx)("div",{style:{padding:12},children:a.review&&0!==a.review.issues.length?(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:a.review.issues.map(e=>(0,n.jsxs)("div",{style:{padding:10,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{color:"error"===e.severity?"#f87171":"warning"===e.severity?"#fbbf24":"var(--text-dim)",fontSize:11,fontWeight:700},children:e.severity.toUpperCase()}),e.cellIndex&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)",fontSize:10},children:["Cell #",e.cellIndex]})]}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text)",fontSize:12,fontWeight:650},children:e.title}),(0,n.jsx)("div",{style:{marginTop:4,color:"var(--text-muted)",fontSize:11,lineHeight:1.45},children:e.detail})]},e.id))}):(0,n.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No deterministic traceability issues found."})}),"runs"===f&&(0,n.jsx)("div",{children:$.map(e=>{let t,i=x.has(e.index),o="failed"===e.status;return(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:0,background:i?"var(--bg-selected)":"transparent",transition:"background 0.1s"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{var t;return t=e.index,void g(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0,padding:"6px 14px",border:"none",background:"transparent",cursor:"pointer",fontSize:11,color:"var(--text)",textAlign:"left"},children:[(0,n.jsx)("span",{style:{flexShrink:0,fontSize:10},children:i?"v":">"}),(0,n.jsxs)("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",minWidth:24},children:["#",e.index]}),(0,n.jsx)(t1,{status:e.status}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:e.title||"kernel_plot_run"}),(0,n.jsx)("span",{style:{flexShrink:0,fontSize:9,padding:"1px 5px",borderRadius:3,background:"var(--bg-hover)",color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:e.runtime??"kernel-lite"}),e.language&&(0,n.jsx)("span",{style:{flexShrink:0,fontSize:9,padding:"1px 5px",borderRadius:3,background:tY(e.language)+"18",color:tY(e.language),fontFamily:"var(--font-mono)"},children:e.language})]}),r&&(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),r(e.code,e.index)},title:"Ask about this cell in chat",style:{...t0,marginRight:10,height:22},children:"Ask"})]}),i&&(0,n.jsxs)("div",{style:{padding:"0 14px 10px"},children:[(0,n.jsx)("pre",{style:{margin:"8px 0 0",padding:10,borderRadius:6,background:"var(--bg-panel)",border:"1px solid var(--border)",fontSize:11,lineHeight:1.5,color:"var(--text)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:400,overflow:"auto"},children:e.code}),(e.stdoutPreview||e.stderrPreview)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"grid",gap:4},children:[e.stdoutPreview&&(0,n.jsx)("pre",{style:{margin:0,padding:8,borderRadius:4,background:"var(--bg-panel)",border:"1px solid var(--border)",fontSize:10,lineHeight:1.45,color:o?"#fbbf24":"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:e.stdoutPreview}),e.stderrPreview&&(0,n.jsx)("pre",{style:{margin:0,padding:8,borderRadius:4,background:"rgba(248,113,113,0.08)",border:"1px solid rgba(248,113,113,0.2)",fontSize:10,lineHeight:1.45,color:"#f87171",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:e.stderrPreview})]}),e.artifacts.length>0&&(0,n.jsxs)("div",{style:{marginTop:6},children:[(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:4},children:["Artifacts (",e.artifacts.length,"):"]}),(0,n.jsx)("div",{style:{display:"grid",gap:2},children:e.artifacts.map((e,t)=>(0,n.jsx)("div",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-muted)",padding:"2px 0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.path,children:e.path},t))})]}),0===(t=e.artifacts.filter(e=>{let t=e.path.split(".").pop()?.toLowerCase();return t&&tG.has(t)})).length?null:(0,n.jsxs)("div",{style:{marginTop:8},children:[(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:4},children:"Previews:"}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(120px, 1fr))",gap:6},children:[t.slice(0,8).map((e,t)=>(0,n.jsx)("button",{type:"button",onClick:()=>s?.(e.path),title:e.path.split("/").pop()||e.path,style:{display:"block",border:"1px solid var(--border)",borderRadius:6,overflow:"hidden",background:"var(--bg-panel)",padding:0,cursor:"pointer"},children:(0,n.jsx)("img",{src:tZ(e.path),alt:e.path.split("/").pop()||`Output ${t+1}`,loading:"lazy",style:{width:"100%",height:100,objectFit:"cover",display:"block"}})},t)),t.length>8&&(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",padding:8,textAlign:"center"},children:["+",t.length-8," more"]})]})]})]})]},e.toolCallId)})})]})}function t5(e){let t=e,r=0;for(;1===t.children.length;)t=t.children[0],r++;return{node:t,skipped:r}}function t4({node:e,activePathIds:t,depth:r,isLast:i,parentLines:o,onSelect:l}){let{node:s,skipped:a}=t5(e),d=t.has(s.entry.id),c=t.has(e.entry.id)||t.has(s.entry.id),p=function(e){if("message"===e.type&&"message"in e){let t=e.message,r=t.content,n="";if("string"==typeof r?n=r:Array.isArray(r)&&(n=r.filter(e=>"text"===e.type).map(e=>e.text).join(" ")),n.length>40&&(n=n.slice(0,40)+"…"),n)return n;if("assistant"===t.role)return"[assistant]"}return e.type}(s.entry),u="message"===s.entry.type&&"message"in s.entry?s.entry.message.role:null;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>l(s.entry.id),children:[o.map((e,t)=>(0,n.jsx)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:e&&(0,n.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:0,width:1,background:"var(--border)"}})},t)),(0,n.jsxs)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:i?"50%":0,width:1,background:"var(--border)"}}),(0,n.jsx)("div",{style:{position:"absolute",left:7,top:"50%",width:9,height:1,background:"var(--border)"}})]}),(0,n.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:d?"var(--accent)":c?"var(--text-muted)":"var(--border)",border:d?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),u&&(0,n.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===u?"var(--accent)":"var(--text-dim)",background:"user"===u?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===u?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===u?"U":"A"}),a>0&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",a]}),(0,n.jsx)("span",{style:{fontSize:11,color:d?"var(--text)":c?"var(--text-muted)":"var(--text-dim)",fontWeight:d?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:p})]}),s.children.map((e,a)=>(0,n.jsx)(t4,{node:e,activePathIds:t,depth:r+1,isLast:a===s.children.length-1,parentLines:[...o,!i],onSelect:l},e.entry.id))]})}function t3({tree:e,activeLeafId:t,onLeafChange:r,inline:o,containerRef:l,open:s,onToggle:a,hasSession:d,embedded:c}){let[p,u]=(0,i.useState)(!1),h=void 0!==s?s:p,x=(0,i.useRef)(null),[g,f]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!h||!o)return;let e=l?.current??x.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();f({top:t.bottom,left:t.left,width:t.width})};t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[h,o,l]);let v=(0,i.useMemo)(()=>t?new Set(function e(r,n){for(let i of r){let r=[...n,i.entry.id];if(i.entry.id===t)return r;let o=e(i.children,r);if(o)return o}return null}(e,[])??[]):new Set,[e,t]),m=(0,i.useCallback)(e=>{r(e)},[r]),y=d?!function e(t){for(let r of t)if(r.children.length>1||e(r.children))return!0;return!1}(e)?"This session has no branches":null:"No active session",b=e.length>0?t5(e[0]):null,j=b?.node??null,k=!y&&j&&j.children.length>1,w=(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:k?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),S=(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{marginLeft:2,transform:h?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return c?(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"8px 10px",borderBottom:k?"1px solid var(--border)":"none"},children:[w,(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Branches"})]}),k&&j?(0,n.jsx)("div",{style:{padding:"4px 10px 8px",maxHeight:260,overflowY:"auto"},children:j.children.map((e,t)=>(0,n.jsx)(t4,{node:e,activePathIds:v,depth:0,isLast:t===j.children.length-1,parentLines:[],onSelect:m},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"0 10px 10px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:y??"This session has no branches"})]}):o?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,n.jsxs)("button",{ref:x,className:"topbar-branches-button",onClick:()=>a?a():u(e=>!e),title:"Branches","aria-label":"Branches",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:h?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${h?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:h?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, border-color 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=h?"var(--text)":"var(--text-muted)",e.currentTarget.style.background=h?"var(--bg-selected)":"var(--bg-panel)"},children:[(0,n.jsx)("span",{className:"topbar-branches-icon",children:w}),(0,n.jsx)("span",{className:"topbar-branches-label",children:"Branches"})]}),h&&g&&(0,n.jsx)("div",{style:{position:"fixed",top:g.top,left:g.left,width:g.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:k&&j?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:j.children.map((e,t)=>(0,n.jsx)(t4,{node:e,activePathIds:v,depth:0,isLast:t===j.children.length-1,parentLines:[],onSelect:m},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:y})})]}):(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>u(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 12px",background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:11,textAlign:"left"},children:[w,(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:"Branches"}),S]}),h&&(0,n.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,background:"var(--bg)",borderBottom:"1px solid var(--border)",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100},children:k&&j?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:j.children.map((e,t)=>(0,n.jsx)(t4,{node:e,activePathIds:v,depth:0,isLast:t===j.children.length-1,parentLines:[],onSelect:m},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:y??"This session has no branches"})})]})}function t8(e,t="0 0 24 24"){let r=({size:r=24,style:i})=>(0,n.jsx)("svg",{width:r,height:r,viewBox:t,fill:"none",style:i,children:e});return r.displayName="ProviderIcon",r}let t6=t8((0,n.jsx)("path",{d:"M17.5 3H6.5L3 21h4l1.2-6h7.6l1.2 6h4L17.5 3zm-2.3 9H8.8L12 5.5 15.2 12z",fill:"currentColor"})),t7=t8((0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round"})),t9=t8((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),(0,n.jsx)("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),(0,n.jsx)("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),(0,n.jsx)("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]})),re=t8((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#4D6BFE"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"10",fontWeight:"bold",fontFamily:"sans-serif",children:"DS"})]})),rt=t8((0,n.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),rr=t8((0,n.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),rn=t8((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),ri=t8((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#00D4AA"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"MM"})]})),ro=t8((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),rl=t8((0,n.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 5h2v3h-2V7zm0 4h2v2h-2v-2zm3 5H7v-2h7v2z",fill:"#FFD21E"})),rs=t8((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#E84026"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"CB"})]})),ra=t8((0,n.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),rd=t8((0,n.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),rc=t8((0,n.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 5l4 3-4 3V7z",fill:"#F38020"})),rp={anthropic:{Icon:t6,hasColor:!1},openai:{Icon:t7,hasColor:!1},"openai-codex":{Icon:t7,hasColor:!1},google:{Icon:t9,hasColor:!0},"google-vertex":{Icon:t9,hasColor:!0},deepseek:{Icon:re,hasColor:!0},groq:{Icon:rt,hasColor:!1},mistral:{Icon:rr,hasColor:!0},moonshotai:{Icon:rn,hasColor:!1},"moonshotai-cn":{Icon:rn,hasColor:!1},moonshot:{Icon:rn,hasColor:!1},minimax:{Icon:ri,hasColor:!0},"minimax-cn":{Icon:ri,hasColor:!0},fireworks:{Icon:ro,hasColor:!0},huggingface:{Icon:rl,hasColor:!0},cerebras:{Icon:rs,hasColor:!0},openrouter:{Icon:ra,hasColor:!1},xai:{Icon:rd,hasColor:!1},"cloudflare-ai-gateway":{Icon:rc,hasColor:!0},"cloudflare-workers-ai":{Icon:rc,hasColor:!0},"vercel-ai-gateway":{Icon:t8((0,n.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),hasColor:!1},"github-copilot":{Icon:t8((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1},"amazon-bedrock":{Icon:t8((0,n.jsx)("path",{d:"M3 15h2l1-3h2l1 3h2V9H9v3L8 9H6l-1 3V9H3v6zm9 0h2v-2h2v-2h-2V9h-2v2h-2v2h2v2z",fill:"#FF9900"})),hasColor:!0},"azure-openai-responses":{Icon:t8((0,n.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),hasColor:!0},"kimi-coding":{Icon:t8((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#6C5CE7"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"10",fontWeight:"bold",fontFamily:"sans-serif",children:"Ki"})]})),hasColor:!0},qwen:{Icon:t8((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#615CED"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"QW"})]})),hasColor:!0},zai:{Icon:t8((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#3859FF"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"ZP"})]})),hasColor:!0},cohere:{Icon:t8((0,n.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),hasColor:!0},perplexity:{Icon:t8((0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"#1DB954",strokeWidth:"1.5",fill:"none",strokeLinejoin:"round"})),hasColor:!0},together:{Icon:t8((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),hasColor:!0},grok:{Icon:t8((0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1}},ru=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],rh="openai-completions",rx={off:"none",xhigh:"xhigh"};function rg(e){return e?.toLowerCase().replace(/\s+/g,"-")??""}function rf(e){return/(^|[^a-z0-9])gpt-5($|[.-])/.test(rg(e))}function rv(e){return/[.-](minimal|low|medium|high|xhigh)$/.test(rg(e))}function rm(e){return rf(e.id)||rf(e.name)}function ry(e,t=rh){if(!rm(e))return e;let r=e.api??("openai-responses"===t?void 0:"openai-responses");if(rm(e)&&(rv(e.id)||rv(e.name))){let{reasoning:t,thinkingLevelMap:n,...i}=e;return{...i,api:r}}return{...e,api:r,reasoning:e.reasoning??!0,thinkingLevelMap:e.thinkingLevelMap??rx}}function rb({label:e,children:t}){return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("label",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:e}),t]})}let rj={padding:"6px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",width:"100%",boxSizing:"border-box"};function rk({value:e,onChange:t,placeholder:r,mono:i}){return(0,n.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:r,style:{...rj,fontFamily:i?"var(--font-mono)":"inherit"}})}function rw({value:e,onChange:t,placeholder:r,mono:o,onKeyDown:l,autoComplete:s="off",spellCheck:a=!1,style:d}){let[c,p]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{e||p(!1)},[e]),(0,n.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,n.jsx)("input",{type:c?"text":"password",value:e,onChange:e=>t(e.target.value),onKeyDown:l,placeholder:r,style:{...rj,paddingRight:34,fontFamily:o?"var(--font-mono)":"inherit"},autoComplete:s,spellCheck:a}),(0,n.jsx)("button",{type:"button",onClick:()=>p(e=>!e),"aria-label":c?"Hide API key":"Show API key",title:c?"Hide API key":"Show API key",style:{position:"absolute",right:5,top:"50%",transform:"translateY(-50%)",width:24,height:24,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:c?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C7 20 2.73 16.89 1 12a18.45 18.45 0 0 1 5.06-6.94"}),(0,n.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c5 0 9.27 3.11 11 8a18.5 18.5 0 0 1-2.16 3.19"}),(0,n.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,n.jsx)("path",{d:"M1 1l22 22"})]}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function rS({value:e,onChange:t,placeholder:r}){return(0,n.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:r,style:rj})}function rC({value:e,onChange:t,options:r,required:i}){return(0,n.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...rj,color:e?"var(--text)":"var(--text-dim)"},children:[!i&&(0,n.jsx)("option",{value:"",children:"— inherit / none —"}),r.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})}function rT({label:e,checked:t,onChange:r}){return(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:12,color:"var(--text-muted)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:t,onChange:e=>r(e.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),e]})}function rz({children:e}){return(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:e})}function rI({name:e,provider:t,onChange:r,onRename:o,onDelete:l}){let[s,a]=(0,i.useState)(e);(0,i.useEffect)(()=>a(e),[e]);let d=(e,n)=>r({...t,[e]:n});return(0,i.useEffect)(()=>{t.api||r({...t,api:"openai-completions"})},[t.api]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(rz,{children:"Provider"}),(0,n.jsx)("button",{onClick:l,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11},children:"Delete"})]}),(0,n.jsxs)(rb,{label:"Provider name",children:[(0,n.jsx)(rk,{value:s,onChange:a,placeholder:"provider-name",mono:!0}),s!==e&&s.trim()&&(0,n.jsx)("button",{onClick:()=>o(s.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:"Rename"})]}),(0,n.jsx)(rb,{label:"Base URL",children:(0,n.jsx)(rk,{value:t.baseUrl??"",onChange:e=>d("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,n.jsxs)(rb,{label:"API Key",children:[(0,n.jsx)(rw,{value:t.apiKey??"",onChange:e=>d("apiKey",e||void 0),placeholder:"ENV_VAR_NAME, !shell-command, or literal key",mono:!0}),(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:["Prefix with ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"!"})," to run a shell command, or use an env var name"]})]}),(0,n.jsx)(rb,{label:"API",children:(0,n.jsx)(rC,{value:t.api??"openai-completions",onChange:e=>d("api",e),options:ru,required:!0})})]})}let rM=["off","minimal","low","medium","high","xhigh"],rR={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function rW({value:e,onChange:t}){let r=e??{},i=(e,n)=>{let i={...r};"omit"===n?delete i[e]:i[e]=n,t(Object.keys(i).length?i:void 0)};return(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:rM.map(e=>{let t=r[e],o=e in r?null===t?"null":"string":"omit",l="string"==typeof t?t:"",s=rR[e],a={padding:"4px 10px",fontSize:10,border:"none",cursor:"pointer",fontWeight:400,transition:"background 0.1s, color 0.1s",whiteSpace:"nowrap",background:"var(--bg-panel)",color:"var(--text-dim)"},d={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:s,flexShrink:0,opacity:"null"===o?.3:1}}),(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===o?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===o?"line-through":"none"},children:e})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>i(e,"omit"),style:{...a,..."omit"===o?d:{}},children:"Default"}),(0,n.jsx)("button",{onClick:()=>i(e,null),style:{...a,borderLeft:"1px solid var(--border)",..."null"===o?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===o?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,n.jsx)("button",{onClick:()=>i(e,l||e),style:{...a,..."string"===o?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,n.jsx)("input",{value:l,onChange:t=>i(e,t.target.value),onFocus:()=>{"string"!==o&&i(e,l||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===o?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===o?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let rL={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function rE({providerName:e,provider:t,model:r,onChange:o,onDelete:l}){let[s,a]=(0,i.useState)({phase:"idle"}),d=(e,t)=>o({...r,[e]:t}),c=e=>{o(ry(e,t.api??rh))},p=(()=>{if("idle"===s.phase)return null;if("testing"===s.phase)return"Testing model connection...";let e=[void 0!==s.latencyMs?`${s.latencyMs}ms`:null,void 0!==s.status?`HTTP ${s.status}`:null].filter(Boolean);return"success"===s.phase?["Connected",...e,s.responseText||null].filter(Boolean).join(" \xb7 "):["Failed",...e,s.message].filter(Boolean).join(" \xb7 ")})();(0,i.useEffect)(()=>{a({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,r.id,r.api]);let u=(0,i.useCallback)(async()=>{if(r.id.trim()&&"testing"!==s.phase){a({phase:"testing"});try{let n=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:t,model:r})}),i=await n.json();if(!n.ok||!i.ok)return void a({phase:"error",message:i.error??`HTTP ${n.status}`,latencyMs:i.latencyMs,status:i.status});a({phase:"success",latencyMs:i.latencyMs,status:i.status,responseText:i.responseText})}catch(e){a({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[r,t,e,s.phase]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(rz,{children:"Model"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[p&&(0,n.jsx)("span",{title:p,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===s.phase?"#fecaca":"success"===s.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===s.phase?"#fee2e2":"success"===s.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:p}),(0,n.jsxs)("button",{onClick:u,disabled:!r.id.trim()||"testing"===s.phase,title:"Test model connection",style:{height:24,padding:"0 8px",background:"success"===s.phase?"#16a34a":"none",border:`1px solid ${"success"===s.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===s.phase?"#fff":r.id.trim()&&"testing"!==s.phase?"var(--text-muted)":"var(--text-dim)",cursor:r.id.trim()&&"testing"!==s.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===s.phase&&(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===s.phase?"Testing…":"success"===s.phase?"OK":"Test"]}),(0,n.jsx)("button",{onClick:l,style:{height:24,padding:"0 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,boxSizing:"border-box"},children:"Remove"})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(rb,{label:"ID *",children:(0,n.jsx)(rk,{value:r.id,onChange:e=>c({...r,id:e}),placeholder:"model-id",mono:!0})}),(0,n.jsx)(rb,{label:"Name",children:(0,n.jsx)(rk,{value:r.name??"",onChange:e=>c({...r,name:e||void 0}),placeholder:"Display name"})})]}),(0,n.jsx)(rb,{label:"API override",children:(0,n.jsx)(rC,{value:r.api??"",onChange:e=>d("api",e||void 0),options:ru})}),(0,n.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,n.jsx)(rT,{label:"Reasoning / thinking",checked:r.reasoning??!1,onChange:e=>d("reasoning",e||void 0)}),(0,n.jsx)(rT,{label:"Image input",checked:r.input?.includes("image")??!1,onChange:e=>d("input",e?["text","image"]:["text"])})]}),r.reasoning&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(rT,{label:"DeepSeek thinking compat",checked:r.compat?.thinkingFormat==="deepseek",onChange:e=>o(function(e,t){if(t)return{...e,compat:{...e.compat??{},...rL}};if(!e.compat)return e;let r={...e.compat};return delete r.thinkingFormat,delete r.requiresReasoningContentOnAssistantMessages,{...e,compat:Object.keys(r).length?r:void 0}}(r,e))}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[(0,n.jsx)(rz,{children:"Thinking level map"}),r.thinkingLevelMap&&(0,n.jsx)("button",{onClick:()=>d("thinkingLevelMap",void 0),style:{fontSize:10,padding:"2px 7px",background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",cursor:"pointer"},children:"clear all"})]}),(0,n.jsx)(rW,{value:r.thinkingLevelMap,onChange:e=>d("thinkingLevelMap",e)})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(rb,{label:"Context window (tokens)",children:(0,n.jsx)(rS,{value:void 0!==r.contextWindow?String(r.contextWindow):"",onChange:e=>d("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,n.jsx)(rb,{label:"Max output tokens",children:(0,n.jsx)(rS,{value:void 0!==r.maxTokens?String(r.maxTokens):"",onChange:e=>d("maxTokens",e?parseInt(e):void 0),placeholder:"16384"})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(rz,{children:"Cost (per million tokens)"}),(0,n.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:8},children:["input","output","cacheRead","cacheWrite"].map(e=>(0,n.jsx)(rb,{label:e,children:(0,n.jsx)(rS,{value:r.cost?.[e]!==void 0?String(r.cost[e]):"",onChange:t=>{let n;return n=parseFloat(t),void o({...r,cost:{...r.cost??{},[e]:isNaN(n)?void 0:n}})},placeholder:"0"})},e))})]})]})}function r$({provider:e,onRefresh:t}){let[r,o]=(0,i.useState)({phase:"idle"}),[l,s]=(0,i.useState)(""),a=(0,i.useRef)(null),d=(0,i.useRef)(null);(0,i.useEffect)(()=>{("auth"===r.phase||"prompt"===r.phase)&&setTimeout(()=>d.current?.focus(),50)},[r.phase]),(0,i.useEffect)(()=>{o({phase:"idle"}),s(""),a.current?.close(),a.current=null},[e.id]),(0,i.useEffect)(()=>()=>{a.current?.close()},[]);let c=(0,i.useCallback)(()=>{a.current?.close(),o({phase:"connecting"}),s("");let r=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);a.current=r,r.onmessage=e=>{let n=JSON.parse(e.data);"auth"===n.type?(o({phase:"auth",url:n.url,instructions:n.instructions??null,token:n.token}),window.open(n.url,"_blank","noopener,noreferrer")):"device_code"===n.type?(o({phase:"device_code",userCode:n.userCode,verificationUri:n.verificationUri,intervalSeconds:n.intervalSeconds??null,expiresInSeconds:n.expiresInSeconds??null}),window.open(n.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===n.type?o({phase:"prompt",message:n.message,placeholder:n.placeholder??null,token:n.token}):"select_request"===n.type?o({phase:"select",message:n.message,options:n.options??[],token:n.token}):"progress"===n.type?o({phase:"progress",message:n.message}):"success"===n.type?(r.close(),o({phase:"success"}),t()):"error"===n.type?(r.close(),o({phase:"error",message:n.message})):"cancelled"===n.type&&(r.close(),o({phase:"idle"}))},r.onerror=()=>{r.close(),o(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),p=(0,i.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),o({phase:"idle"}),t()},[e.id,t]),u=(0,i.useCallback)(async(t,r)=>{if(r.trim()){o({phase:"progress",message:"Verifying…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r.trim()})});if(!n.ok){let e=await n.json().catch(()=>({}));o({phase:"error",message:e.error??`Server error ${n.status}`});return}s("")}catch(e){o({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),h=(0,i.useCallback)(async(t,r)=>{o({phase:"progress",message:"Continuing…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r})});if(!n.ok){let e=await n.json().catch(()=>({}));o({phase:"error",message:e.error??`Server error ${n.status}`})}}catch(e){o({phase:"error",message:e instanceof Error?e.message:"Network error"})}},[e.id]),x="connecting"===r.phase||"progress"===r.phase||"auth"===r.phase||"device_code"===r.phase||"prompt"===r.phase||"select"===r.phase;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(rz,{children:"Subscription"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.loggedIn?"#4ade80":"var(--text-dim)"},children:e.loggedIn?"connected":"not connected"})]})]}),(0,n.jsxs)("div",{style:{minHeight:48},children:["idle"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.loggedIn?"Already connected. You can re-login or disconnect.":`Connect your ${e.name} account.`}),"connecting"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:"Opening browser…"}),"select"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:r.message}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.options.map(e=>(0,n.jsx)("button",{onClick:()=>h(r.token,e.id),style:{padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:e.label},e.id))})]}),("auth"===r.phase||"prompt"===r.phase)&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===r.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":r.message}),"auth"===r.phase&&(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,n.jsx)("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{ref:d,value:l,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&u(r.token,l)},placeholder:"auth"===r.phase?"http://localhost:1455/auth/callback?code=…":r.placeholder??"Enter value…",style:{flex:1,padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,n.jsx)("button",{onClick:()=>u(r.token,l),disabled:!l.trim(),style:{padding:"6px 12px",background:l.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:l.trim()?"#fff":"var(--text-dim)",cursor:l.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:"Submit"})]})]}),"device_code"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Open the verification page and enter this code:"}),(0,n.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:16,fontWeight:700,fontFamily:"var(--font-mono)",letterSpacing:0},children:r.userCode}),(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,n.jsx)("a",{href:r.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:r.verificationUri}),r.expiresInSeconds?` Expires in ${Math.ceil(r.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:r.message}),"success"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:"Connected successfully."}),"error"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:r.message})]}),(0,n.jsx)("div",{style:{display:"flex",gap:8},children:x?(0,n.jsx)("button",{onClick:()=>{a.current?.close(),o({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:c,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:e.loggedIn?"Re-login":"Login"}),e.loggedIn&&(0,n.jsx)("button",{onClick:p,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:"Disconnect"})]})})]})}function rP({provider:e,onRefresh:t}){let[r,o]=(0,i.useState)(""),[l,s]=(0,i.useState)(!1),[a,d]=(0,i.useState)(!1),[c,p]=(0,i.useState)(null),[u,h]=(0,i.useState)(!1);(0,i.useEffect)(()=>{o(""),p(null),h(!1)},[e.id]);let x=(0,i.useCallback)(async()=>{if(r.trim()){s(!0),p(null),h(!1);try{let n=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:r.trim()})}),i=await n.json();!n.ok||i.error?p(i.error??`HTTP ${n.status}`):(o(""),h(!0),setTimeout(()=>h(!1),2e3),t())}catch(e){p(String(e))}finally{s(!1)}}},[r,e.id,t]),g=(0,i.useCallback)(async()=>{d(!0),p(null);try{let r=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),n=await r.json();!r.ok||n.error?p(n.error??`HTTP ${r.status}`):t()}catch(e){p(String(e))}finally{d(!1)}},[e.id,t]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(rz,{children:"API Key"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.configured?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.configured?"#4ade80":"var(--text-dim)"},children:e.configured?"configured":"not configured"})]})]}),(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.configured?"API key is stored. Enter a new key below to replace it, or disconnect to remove it.":`Enter your ${e.displayName} API key to enable ${e.modelCount} model${1!==e.modelCount?"s":""}.`}),(0,n.jsx)(rb,{label:"API Key",children:(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(rw,{value:r,onChange:o,onKeyDown:e=>{"Enter"===e.key&&r.trim()&&x()},placeholder:e.configured?"Enter new key to replace…":"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,n.jsxs)("button",{onClick:x,disabled:l||!r.trim()||u,style:{padding:"6px 12px",background:u?"#16a34a":r.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:r.trim()||u?"#fff":"var(--text-dim)",cursor:l||!r.trim()||u?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[u&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),u?"Saved":l?"Saving…":"Save"]})]})}),c&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c}),e.configured&&(0,n.jsx)("button",{onClick:g,disabled:a,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:a?"not-allowed":"pointer",fontSize:12},children:a?"Removing…":"Disconnect"})]})}function rD({id:e,size:t}){let r=rp[e];return r?r.hasColor?(0,n.jsx)(r.Icon,{size:t}):(0,n.jsx)(r.Icon,{size:t,style:{color:"var(--text-muted)"}}):null}function rA({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:r,onSelectApiKey:o,onAddCustom:l,onDiscover:s,onClose:a}){let[d,c]=(0,i.useState)(""),p=(0,i.useRef)(null);(0,i.useEffect)(()=>{setTimeout(()=>p.current?.focus(),30)},[]);let u=d.trim().toLowerCase(),h=e.filter(e=>!e.loggedIn&&(!u||e.name.toLowerCase().includes(u))),x=t.filter(e=>!e.configured&&(!u||e.displayName.toLowerCase().includes(u)||e.id.toLowerCase().includes(u))),g=!u||"custom".includes(u)||"openai-compatible".includes(u)||"anthropic-compatible".includes(u),f=!u||"discover".includes(u)||"base url".includes(u)||"model import".includes(u),v=h.length+x.length+ +!!g+ +!!f,m={display:"flex",flexDirection:"row",alignItems:"center",gap:8,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,boxSizing:"border-box",cursor:"pointer",minWidth:0,textAlign:"left",transition:"border-color 0.12s, background 0.12s",width:"100%"};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&a()},children:(0,n.jsxs)("div",{style:{width:820,maxWidth:"calc(100vw - 32px)",maxHeight:"min(72vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",flexShrink:0,display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,n.jsx)("input",{ref:p,value:d,onChange:e=>c(e.target.value),onKeyDown:e=>{"Escape"===e.key&&a()},placeholder:"Search providers…",style:{flex:1,background:"none",border:"none",outline:"none",color:"var(--text)",fontSize:13,boxSizing:"border-box"}})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:14},children:0===v?(0,n.jsx)("div",{style:{padding:"20px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:"No providers match"}):(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(240px, 100%), 1fr))",gap:8},children:[g&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Custom"}),g&&(0,n.jsxs)("button",{onClick:()=>{l(),a()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"OpenAI / Anthropic compatible"}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Custom endpoint format"})]}),(0,n.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px dashed var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)"},children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),f&&(0,n.jsxs)("button",{onClick:()=>{s(),a()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"Discover models from Base URL"}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OpenAI-compatible / Ollama catalog"})]}),(0,n.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-muted)"},children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})})]}),h.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!g,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Subscriptions"}),h.map(e=>(0,n.jsxs)("button",{onClick:()=>{r(e.id),a()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OAuth"})]}),(0,n.jsx)(rD,{id:e.id,size:28})]},e.id)),x.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(h.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),x.map(e=>(0,n.jsxs)("button",{onClick:()=>{o(e.id),a()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:[e.modelCount," models"]})]}),(0,n.jsx)(rD,{id:e.id,size:28})]},e.id))]})})]})})}function rB({existingProviders:e,onImport:t,onClose:r}){let[o,l]=(0,i.useState)(""),[s,a]=(0,i.useState)(""),[d,c]=(0,i.useState)("custom-provider"),[p,u]=(0,i.useState)(new Set),[h,x]=(0,i.useState)({phase:"idle"}),g=(0,i.useCallback)(async()=>{let e=o.trim();if(e&&"loading"!==h.phase){x({phase:"loading"});try{let t=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:e,apiKey:s,provider:d,enrich:!1})}),r=await t.json();if(!t.ok||!r.ok||!r.models||!r.piModels||!r.endpoint)return void x({phase:"error",message:r.error??`HTTP ${t.status}`});x({phase:"success",endpoint:r.endpoint,models:r.models,piModels:r.piModels}),u(new Set(r.piModels.map(e=>e.id)))}catch(e){x({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[s,o,d,h.phase]),f="success"===h.phase?h:null,v=p.size,m=!!(f&&d.trim()&&v>0);return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&r()},children:(0,n.jsxs)("div",{style:{width:880,maxWidth:"calc(100vw - 32px)",height:"min(78vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:"Discover models"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:2},children:"Fetch model catalog from a Base URL and import selected models."})]}),(0,n.jsx)("button",{onClick:r,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{padding:16,borderBottom:"1px solid var(--border)",display:"grid",gridTemplateColumns:"1.4fr 1fr 0.9fr auto",gap:10,alignItems:"end",flexShrink:0},children:[(0,n.jsx)(rb,{label:"Base URL",children:(0,n.jsx)(rk,{value:o,onChange:l,placeholder:"https://api.example.com",mono:!0})}),(0,n.jsx)(rb,{label:"API Key",children:(0,n.jsx)(rw,{value:s,onChange:a,placeholder:"optional for local providers",mono:!0})}),(0,n.jsx)(rb,{label:"Provider name",children:(0,n.jsx)(rk,{value:d,onChange:c,placeholder:"provider-name",mono:!0})}),(0,n.jsx)("button",{onClick:g,disabled:!o.trim()||"loading"===h.phase,style:{height:31,padding:"0 14px",background:o.trim()&&"loading"!==h.phase?"var(--accent)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:o.trim()&&"loading"!==h.phase?"#fff":"var(--text-dim)",cursor:o.trim()&&"loading"!==h.phase?"pointer":"not-allowed",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:"loading"===h.phase?"Fetching...":"Fetch models"})]}),(0,n.jsxs)("div",{style:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column"},children:["idle"===h.phase&&(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Enter a Base URL to discover available models."}),"loading"===h.phase&&(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Fetching model catalog..."}),"error"===h.phase&&(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12,lineHeight:1.6},children:h.message}),f&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 16px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[f.piModels.length," models from ",f.endpoint]}),(0,n.jsx)("button",{onClick:()=>{if(f){if(p.size===f.piModels.length)return void u(new Set);u(new Set(f.piModels.map(e=>e.id)))}},style:{padding:"2px 8px",fontSize:11,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer"},children:p.size===f.piModels.length?"Clear":"Select all"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto"},children:f.piModels.map((e,t)=>{let r=f.models[t],i=p.has(e.id);return(0,n.jsxs)("label",{style:{display:"grid",gridTemplateColumns:"24px minmax(0, 1fr) 90px 90px 90px 70px",gap:10,alignItems:"center",padding:"8px 16px",borderBottom:"1px solid rgba(127,127,127,0.12)",background:i?"var(--bg-subtle)":"transparent",cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:i,onChange:()=>{var t;return t=e.id,void u(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},style:{width:14,height:14,accentColor:"var(--accent)"}}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.id}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r?.ownedBy??"unknown"})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:e.contextWindow}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:e.maxTokens}),(0,n.jsx)("span",{style:{fontSize:10,color:e.reasoning?"var(--accent)":"var(--text-dim)"},children:e.reasoning?"reasoning":""}),(0,n.jsx)("span",{style:{fontSize:10,color:e.input?.includes("image")?"var(--accent)":"var(--text-dim)"},children:e.input?.includes("image")?"image":""})]},e.id)})})]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,padding:"10px 16px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:[v," selected"]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsx)("button",{onClick:r,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Cancel"}),(0,n.jsx)("button",{onClick:()=>{if(!f||!m)return;let n=o.trim().replace(/\/+$/,""),i=s.trim(),l=Object.entries(e).find(([,e])=>(e.baseUrl??"").replace(/\/+$/,"")===n&&(e.apiKey??"")===i),a=l?.[0]??d.trim(),c=e[a],u=new Map((c?.models??[]).map(e=>[e.id,e])),h=c?.api??rh,x=0;for(let e of f.piModels)p.has(e.id)&&!u.has(e.id)&&(u.set(e.id,ry(e,h)),x+=1);t(a,{...c??{},baseUrl:n,api:h,...i?{apiKey:i}:{},models:Array.from(u.values())},x),r()},disabled:!m,style:{padding:"6px 16px",background:m?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:6,color:m?"#fff":"var(--text-dim)",cursor:m?"pointer":"not-allowed",fontSize:13,fontWeight:600},children:"Import selected"})]})]})]})})}function rN({onClose:e,embedded:t=!1}){let[r,o]=(0,i.useState)({providers:{}}),[l,s]=(0,i.useState)(!0),[a,d]=(0,i.useState)(!1),[c,p]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(null),[m,y]=(0,i.useState)([]),[b,j]=(0,i.useState)([]),[k,w]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!1),T=(0,i.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>y(e.providers)).catch(()=>{})},[]),z=(0,i.useCallback)(()=>{fetch("/api/auth/all-providers").then(e=>e.json()).then(e=>j(e.providers)).catch(()=>{})},[]);(0,i.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};o(t);let r=Object.keys(t.providers??{});r.length>0&&v({type:"provider",name:r[0]})}).catch(()=>o({providers:{}})).finally(()=>s(!1)),T(),z()},[T,z]);let I=(0,i.useCallback)(()=>{let e="new-provider",t=1;for(;r.providers?.[e];)e=`new-provider-${t++}`;o(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),v({type:"provider",name:e})},[r.providers]),M=(0,i.useCallback)((e,t)=>{o(r=>({...r,providers:{...r.providers??{},[e]:t}}))},[]),R=(0,i.useCallback)((e,t)=>{o(r=>{let n=Object.entries(r.providers??{}),i=n.findIndex(([t])=>t===e);return -1===i?r:(n[i]=[t,n[i][1]],{...r,providers:Object.fromEntries(n)})}),v(r=>r?"provider"===r.type&&r.name===e?{type:"provider",name:t}:"model"===r.type&&r.providerName===e?{...r,providerName:t}:r:r)},[]),W=(0,i.useCallback)(e=>{o(t=>{let r={...t.providers??{}};return delete r[e],{...t,providers:r}}),o(e=>{let t=Object.keys(e.providers??{});return v(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),L=(0,i.useCallback)(e=>{o(t=>{let r=t.providers?.[e]??{},n=[...r.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...r,models:n}}}}),o(t=>{let r=(t.providers?.[e]?.models?.length??1)-1;return v({type:"model",providerName:e,index:r}),t})},[]),E=(0,i.useCallback)((e,t,r)=>{o(n=>{let i=n.providers?.[e]??{},o=[...i.models??[]];return o[t]=r,{...n,providers:{...n.providers??{},[e]:{...i,models:o}}}})},[]),$=(0,i.useCallback)((e,t)=>{o(r=>{let n=r.providers?.[e]??{},i=[...n.models??[]];return i.splice(t,1),{...r,providers:{...r.providers??{},[e]:{...n,models:i.length?i:void 0}}}}),v({type:"provider",name:e})},[]),P=(0,i.useCallback)((e,t,r)=>{o(r=>({...r,providers:{...r.providers??{},[e]:t}})),v({type:"provider",name:e}),g(!1),p(null),h(`${r} model${1===r?"":"s"} imported. Click Save to write models.json.`)},[]),D=(0,i.useCallback)(async()=>{d(!0),p(null),h(null),g(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),t=await e.json();!e.ok||t.error?p(t.error??`HTTP ${e.status}`):(g(!0),setTimeout(()=>g(!1),2e3))}catch(e){p(String(e))}finally{d(!1)}},[r]),A=Object.entries(r.providers??{}),B=m.filter(e=>e.loggedIn),N=b.filter(e=>e.configured),O=(()=>{if(!f)return null;if("oauth"===f.type){let e=m.find(e=>e.id===f.providerId);return e?(0,n.jsx)(r$,{provider:e,onRefresh:T},e.id):null}if("apikey"===f.type){let e=b.find(e=>e.id===f.providerId);return e?(0,n.jsx)(rP,{provider:e,onRefresh:z},e.id):null}if("provider"===f.type){let e=r.providers?.[f.name];return e?(0,n.jsx)(rI,{name:f.name,provider:e,onChange:e=>M(f.name,e),onRename:e=>R(f.name,e),onDelete:()=>W(f.name)},f.name):null}let e=r.providers?.[f.providerName],t=e?.models?.[f.index];return t?(0,n.jsx)(rE,{providerName:f.providerName,provider:e,model:t,onChange:e=>E(f.providerName,f.index,e),onDelete:()=>$(f.providerName,f.index)},`${f.providerName}-${f.index}`):null})();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:t?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:r=>{t||r.target!==r.currentTarget||e()},children:(0,n.jsxs)("div",{style:{width:t?"100%":860,height:t?"100%":"78vh",background:"var(--bg)",border:t?"none":"1px solid var(--border)",borderRadius:10*!t,display:"flex",flexDirection:"column",boxShadow:t?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!t&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Models"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"})]}),(0,n.jsx)("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[B.map(e=>{let t=f?.type==="oauth"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>v({type:"oauth",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)(rD,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.id)}),N.map(e=>{let t=f?.type==="apikey"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>v({type:"apikey",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)(rD,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName})]},e.id)}),(B.length>0||N.length>0)&&A.length>0&&(0,n.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),l?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):A.map(([e,t])=>{let r=f?.type==="provider"&&f.name===e,i=t.models??[];return(0,n.jsxs)("div",{style:{marginBottom:2},children:[(0,n.jsxs)("div",{onClick:()=>v({type:"provider",name:e}),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:r?"var(--bg-selected)":"none"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:r?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),i.map((t,r)=>{let i=f?.type==="model"&&f.providerName===e&&f.index===r;return(0,n.jsxs)("div",{onClick:()=>v({type:"model",providerName:e,index:r}),style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:i?"var(--bg-selected)":"none"},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:t.id?"var(--text-muted)":"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.id||"new model"}),t.reasoning&&(0,n.jsx)("span",{style:{fontSize:9,padding:"1px 4px",background:"rgba(99,102,241,0.12)",color:"rgba(99,102,241,0.8)",borderRadius:3,flexShrink:0},children:"T"})]},r)}),(0,n.jsx)("div",{onClick:t=>{t.stopPropagation(),L(e)},style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px 4px 26px",borderRadius:5,cursor:"pointer",color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,n.jsx)("span",{style:{fontSize:11},children:"+ model"})})]},e)})]}),(0,n.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,n.jsx)("button",{onClick:()=>w(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:"100%",padding:"6px 0",background:"none",border:"1px dashed var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.color="var(--text-muted)"},children:"+ Add provider"})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:l?null:O??(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a provider or model"})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[c?(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:c}):u?(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",flex:1},children:u}):null,(0,n.jsx)("button",{onClick:e,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Cancel"}),(0,n.jsxs)("button",{onClick:D,disabled:a||x,style:{position:"relative",padding:"6px 16px",minWidth:92,background:x?"#16a34a":a?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:x?"#fff":a?"var(--text-muted)":"#fff",cursor:a||x?"default":"pointer",fontSize:13,fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,transition:"background-color 0.2s ease, color 0.2s ease",animation:x?"saved-pop 0.45s ease":void 0},children:[x&&(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0},children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,n.jsx)("span",{children:x?"Saved":a?"Saving…":"Save"})]})]})]})}),k&&(0,n.jsx)(rA,{oauthProviders:m,apiKeyProviders:b,onSelectOAuth:e=>v({type:"oauth",providerId:e}),onSelectApiKey:e=>v({type:"apikey",providerId:e}),onAddCustom:I,onDiscover:()=>C(!0),onClose:()=>w(!1)}),S&&(0,n.jsx)(rB,{existingProviders:r.providers??{},onImport:P,onClose:()=>C(!1)})]})}function rO(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function rH(e){let t=e.sourceInfo?.source,r=e.sourceInfo?.scope;return"user"===r||"user"===t?"global":"project"===r||"project"===t?"project":"path"}function rF({enabled:e,loading:t,onToggle:r}){return(0,n.jsx)("button",{onClick:r,disabled:t,title:e?"Visible in model prompt — click to disable":"Hidden from model prompt — click to enable",style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:t?"wait":"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none"},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:e?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function r_({skill:e,cwd:t,onToggle:r,toggling:i,saveError:o}){let l=rH(e),s=!e.disableModelInvocation;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===l?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===l?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:l}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e){if("project"===l&&e.startsWith(t)){let r=e.slice(t.length).replace(/^[/\\]/,"");return`./${r}`}return rO(e)}(e.filePath)}),(0,n.jsx)(rF,{enabled:s,loading:i,onToggle:()=>r(e)}),o&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:o})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Name"}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:e.name})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Description"}),(0,n.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:e.description})]})]})}function rU({cwd:e,onInstalled:t}){let[r,o]=(0,i.useState)(""),[l,s]=(0,i.useState)([]),[a,d]=(0,i.useState)(!1),[c,p]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),[x,g]=(0,i.useState)(null),[f,v]=(0,i.useState)(null),[m,y]=(0,i.useState)([]),[b,j]=(0,i.useState)(new Set),[k,w]=(0,i.useState)("global"),S=(0,i.useRef)(null),C=(0,i.useRef)(null);(0,i.useEffect)(()=>{S.current?.focus()},[]),(0,i.useEffect)(()=>()=>{C.current?.abort()},[]);let T=(0,i.useCallback)(async e=>{if(e.trim()){d(!0),p(null),s([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),r=await t.json();if(r.error)return void p(r.error);s(r.results??[]),0===(r.results??[]).length&&p("No skills found")}catch(e){p(String(e))}finally{d(!1)}}},[]),z=(0,i.useCallback)(async r=>{let n=new AbortController;C.current=n,h(r),g(null),v("Starting installer"),y(["Starting installer"]);try{let i=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:r,scope:k,cwd:e,stream:!0}),signal:n.signal});if(!i.ok||!i.body){let e=await i.json().catch(()=>null);g(e?.error??`HTTP ${i.status}`);return}let o=i.body.getReader(),l=new TextDecoder,s="",a=!1,d=e=>{"progress"===e.type?(e.stage&&v(e.stage),e.line&&y(t=>(t.at(-1)===e.line?t:[...t,e.line]).slice(-8))):"done"===e.type&&e.success?(a=!0,v("Installed"),y(e=>[...e,"Installed"].slice(-8))):"error"===e.type&&g(e.error??"Install failed")};for(;;){let{value:e,done:t}=await o.read(),r=(s+=l.decode(e??new Uint8Array,{stream:!t})).split("\n");for(let e of(s=r.pop()??"",r))e.trim()&&d(JSON.parse(e));if(t)break}s.trim()&&d(JSON.parse(s)),a&&(j(e=>new Set(e).add(r)),t())}catch(e){n.signal.aborted?(v("Canceled"),y(e=>[...e,"Canceled"].slice(-8))):g(String(e))}finally{C.current===n&&(C.current=null),h(null)}},[t,k,e]),I=(0,i.useCallback)(()=>{C.current?.abort()},[]),M="global"===k?"~/.pi/agent/skills/":`${rO(e)}/.pi/agent/skills/`;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:"Add Skill"}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{ref:S,value:r,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"===e.key&&T(r)},placeholder:"e.g. react, testing, deploy",style:{flex:1,padding:"7px 10px",fontSize:13,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,n.jsx)("button",{onClick:()=>T(r),disabled:a||!r.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:a||!r.trim()?"not-allowed":"pointer",opacity:a||!r.trim()?.5:1,flexShrink:0},children:a?"Searching…":"Search"})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(e=>(0,n.jsx)("button",{onClick:()=>w(e),style:{padding:"3px 10px",border:"none",cursor:"pointer",background:k===e?"var(--bg-selected)":"none",color:k===e?"var(--text)":"var(--text-dim)",fontWeight:k===e?600:400,borderRight:"global"===e?"1px solid var(--border)":"none"},children:e},e))}),(0,n.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",M]})]}),c&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:c}),x&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:x}),u&&(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:10,display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{width:10,height:10,borderRadius:"50%",border:"2px solid var(--border)",borderTopColor:"var(--accent)",animation:"spin 0.8s linear infinite",flexShrink:0}}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f??"Installing"}),(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]}),(0,n.jsx)("button",{onClick:I,style:{padding:"4px 9px",fontSize:12,borderRadius:5,border:"1px solid var(--border)",background:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0},children:"Cancel"})]}),m.length>0&&(0,n.jsx)("div",{style:{maxHeight:120,overflow:"auto",fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.6,color:"var(--text-dim)",borderTop:"1px solid var(--border)",paddingTop:8},children:m.map((e,t)=>(0,n.jsx)("div",{children:e},`${t}-${e}`))})]})]}),l.length>0?(0,n.jsx)("div",{style:{flex:1,overflowY:"auto"},children:l.map(e=>{let t=b.has(e.package),r=u===e.package,i=e.package.indexOf("@"),o=i>-1?e.package.slice(0,i):e.package,l=i>-1?e.package.slice(i+1):null;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:l??o}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:o}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:e.installs}),e.url&&(0,n.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,n.jsx)("button",{onClick:()=>{t||null!==u||z(e.package)},disabled:t||null!==u,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:r?"wait":t||null!==u?"not-allowed":"pointer",background:t?"rgba(34,197,94,0.1)":r?"rgba(59,130,246,0.08)":"none",color:t?"#16a34a":r?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:t?"✓ Installed":r?"Installing":"Install"})]},e.package)})}):!c&&!a&&(0,n.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,n.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"})," ","to discover and install skills for your agent."]})]})}function rK({cwd:e,onClose:t,embedded:r=!1}){let[o,l]=(0,i.useState)([]),[s,a]=(0,i.useState)(!0),[d,c]=(0,i.useState)(null),[p,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(new Set),[g,f]=(0,i.useState)(null),[v,m]=(0,i.useState)(!1),y=(0,i.useCallback)(()=>{a(!0),c(null),fetch(`/api/skills?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{if(e.error)return void c(e.error);let t=e.skills??[];l(t),t.length>0&&!p&&u(t[0].filePath)}).catch(e=>c(String(e))).finally(()=>a(!1))},[e,p]);(0,i.useEffect)(()=>{y()},[e]);let b=(0,i.useCallback)(async e=>{let t=!e.disableModelInvocation;x(t=>new Set(t).add(e.filePath)),f(null);try{let r=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:e.filePath,disableModelInvocation:t})}),n=await r.json();if(!r.ok||n.error)return void f(n.error??`HTTP ${r.status}`);l(r=>r.map(r=>r.filePath===e.filePath?{...r,disableModelInvocation:t}:r))}catch(e){f(String(e))}finally{x(t=>{let r=new Set(t);return r.delete(e.filePath),r})}},[]),j=o.find(e=>e.filePath===p)??null;return(0,n.jsx)("div",{style:r?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{r||e.target!==e.currentTarget||t()},children:(0,n.jsxs)("div",{style:{width:r?"100%":860,height:r?"100%":"78vh",background:"var(--bg)",border:r?"none":"1px solid var(--border)",borderRadius:10*!r,display:"flex",flexDirection:"column",boxShadow:r?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!r&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Skills"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:rO(e)})]}),(0,n.jsx)("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:s?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):d?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:d}):0===o.length?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No skills found"}):(()=>{let e=[];for(let t of["project","global","path"]){let r=o.filter(e=>rH(e)===t);r.length>0&&e.push({label:t,skills:r})}return e.map(({label:e,skills:t})=>(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:e}),t.map(e=>{let t=!v&&p===e.filePath,r=e.disableModelInvocation;return(0,n.jsxs)("div",{onClick:()=>{u(e.filePath),m(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:r?"var(--border)":"var(--accent)",boxShadow:r?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:t?600:400,color:r?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.filePath)})]},e))})()}),(0,n.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{onClick:()=>m(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:v?"var(--bg-selected)":"none",color:v?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{v||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{v||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add skill"]})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:v?(0,n.jsx)(rU,{cwd:e,onInstalled:()=>{y()}}):s?null:j?(0,n.jsx)(r_,{skill:j,cwd:e,onToggle:b,toggling:h.has(j.filePath),saveError:g},j.filePath):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a skill"})})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsx)("button",{onClick:t,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Close"})})]})})}let rJ=[{label:"30m",value:18e5},{label:"2h",value:72e5},{label:"6h",value:216e5},{label:"24h",value:864e5},{label:"48h",value:1728e5},{label:"Never",value:0}];function rV(e){return e?e.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function rq(e){if(e<=0)return"never";let t=e/60/1e3;if(t<60)return`${Math.round(t)}m`;let r=t/60;return Number.isInteger(r)?`${r}h`:`${r.toFixed(1)}h`}function rY(e){return{id:"",language:e,displayName:"",command:"python"===e?"python3":"R",argsText:JSON.stringify("python"===e?["-u"]:["--slave","--vanilla"]),envText:"{}"}}function rG(e){return{id:e.id,language:e.language,displayName:e.displayName,command:e.command,argsText:JSON.stringify(e.args),envText:JSON.stringify(e.env,null,2)}}let rZ={height:30,padding:"0 11px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,whiteSpace:"nowrap"},rX={width:"100%",minWidth:0,padding:"7px 9px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)"};function rQ({label:e,children:t}){return(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:e}),t]})}function r0({cwd:e}){let[t,r]=(0,i.useState)("python"),[o,l]=(0,i.useState)(null),[s,a]=(0,i.useState)(!0),[d,c]=(0,i.useState)(null),[p,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[g,f]=(0,i.useState)([]),[v,m]=(0,i.useState)(null),[y,b]=(0,i.useState)("view"),[j,k]=(0,i.useState)(()=>rY("python")),[w,S]=(0,i.useState)(1728e5),[C,T]=(0,i.useState)("pdf"),[z,I]=(0,i.useState)(300),[M,R]=(0,i.useState)(800),[W,L]=(0,i.useState)(600),[E,$]=(0,i.useState)(!1),P=(0,i.useCallback)(async()=>{a(!0),u(null);try{let r=e?`?cwd=${encodeURIComponent(e)}`:"",n=await fetch(`/api/plot-kernels${r}`),i=await n.json();if(!n.ok||i.error)throw Error(i.error??`HTTP ${n.status}`);l(i),f([]),x(null),m(e=>{if(e&&i.kernels.some(t=>t.id===e))return e;let r=i.kernels.find(e=>e.language===t&&e.isEffective);return r?.id??i.kernels.find(e=>e.language===t)?.id??null})}catch(e){u(e instanceof Error?e.message:String(e))}finally{a(!1)}},[e,t]);(0,i.useEffect)(()=>{P()},[P]),(0,i.useEffect)(()=>{let e=!1;return fetch("/api/settings").then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(t=>{e||"number"!=typeof t.settings?.plotIdleTimeoutMs||S(t.settings.plotIdleTimeoutMs),e||("string"==typeof t.settings?.saveFormat&&["pdf","png","svg"].includes(t.settings.saveFormat)&&T(t.settings.saveFormat),"number"==typeof t.settings?.saveDpi&&I(t.settings.saveDpi),"number"==typeof t.settings?.saveWidth&&R(t.settings.saveWidth),"number"==typeof t.settings?.saveHeight&&L(t.settings.saveHeight))}).catch(()=>{}),()=>{e=!0}},[]);let D=(0,i.useMemo)(()=>(o?.kernels??[]).filter(e=>e.language===t),[t,o?.kernels]),A=D.find(e=>e.id===v)??null;(0,i.useEffect)(()=>{if("new"===y)return void k(rY(t));let e=A??D.find(e=>e.isEffective)??D[0]??null;e?(v!==e.id&&m(e.id),k(rG(e)),b("view")):(m(null),k(rY(t)),b("new"))},[t,o?.kernels]);let B=(0,i.useCallback)(async(t,r)=>{c(r),u(null),x(null),f([]);try{let r=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,...t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return l(n),f(n.errors??[]),n}catch(e){return u(e instanceof Error?e.message:String(e)),null}finally{c(null)}},[e]),N=(0,i.useCallback)(async e=>{let t=await B({action:"scan",..."all"===e?{}:{language:e}},"scan");t&&x(`Scan added ${t.added?.length??0} kernel${(t.added?.length??0)===1?"":"s"}${t.skipped?`, skipped ${t.skipped} existing`:""}.`)},[B]),O=(0,i.useCallback)(async e=>{await B({action:"select",language:e.language,kernelId:e.id},"select")&&x(`Selected ${e.displayName} for this project.`)},[B]),H=(0,i.useCallback)(async e=>{await B({action:"setDefault",language:e.language,kernelId:e.id},"default")&&x(`Set ${e.displayName} as global default.`)},[B]),F=(0,i.useCallback)(async()=>{let e=j.id.trim();if(!e)return void u("Kernel ID is required");try{let t=function(e){let t=JSON.parse(e.argsText||"[]"),r=JSON.parse(e.envText||"{}");if(!Array.isArray(t))throw Error("Args must be a JSON array");if(!r||"object"!=typeof r||Array.isArray(r))throw Error("Env must be a JSON object");return{language:e.language,command:e.command.trim(),displayName:e.displayName.trim(),args:t.map(e=>String(e)),env:Object.fromEntries(Object.entries(r).map(([e,t])=>[e,String(t)]))}}(j);if(!t.command)throw Error("Command is required");if(!await B({action:"new"===y?"add":"edit",kernelId:e,kernel:t},"save"))return;m(e),b("view"),x("new"===y?"Kernel added.":"Kernel saved.")}catch(e){u(e instanceof Error?e.message:String(e))}},[j,y,B]),_=(0,i.useCallback)(async e=>{let r=await B({action:"delete",kernelId:e.id},"delete");if(!r)return;let n=r.kernels.find(e=>e.language===t&&e.isEffective)??r.kernels.find(e=>e.language===t)??null;m(n?.id??null),b(n?"view":"new"),x("Kernel deleted.")},[t,B]),U=()=>{b("new"),m(null),k(rY(t)),u(null),x(null)},K=(0,i.useCallback)(async e=>{S(e),$(!0),u(null);try{let t=await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{plotIdleTimeoutMs:e}})}),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);"number"==typeof r.settings?.plotIdleTimeoutMs&&(S(r.settings.plotIdleTimeoutMs),x(`Workbench idle timeout set to ${rq(r.settings.plotIdleTimeoutMs)}.`))}catch(e){S(w),u(e instanceof Error?e.message:String(e))}finally{$(!1)}},[w]),J=(0,i.useCallback)(async()=>{$(!0),u(null);try{let e=await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{saveFormat:C,saveDpi:z,saveWidth:M,saveHeight:W}})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);x("Save defaults updated.")}catch(e){u(e instanceof Error?e.message:String(e))}finally{$(!1)}},[C,z,M,W]);return(0,n.jsxs)("div",{style:{height:"100%",minHeight:0,display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{flexShrink:0,padding:"12px 16px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:"Workbench Runtime"}),(0,n.jsx)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Manage the warm R/Python kernels used by Workbench sessions and iterative analysis turns."})]}),(0,n.jsxs)("div",{style:{flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"12px 16px",borderBottom:"1px solid var(--border)",flexWrap:"wrap"},children:[(0,n.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:["python","r"].map(e=>{let i=t===e;return(0,n.jsx)("button",{type:"button",onClick:()=>r(e),style:{height:26,padding:"0 12px",border:"none",borderRadius:5,background:i?"var(--bg)":"transparent",color:i?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:i?600:500},children:"python"===e?"Python":"R"},e)})}),(0,n.jsxs)("button",{type:"button",onClick:()=>void N(t),disabled:!!d,style:{...rZ,opacity:d?.55:1},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.3 6.4"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.3 5.6"}),(0,n.jsx)("path",{d:"M18 2v4h4"}),(0,n.jsx)("path",{d:"M6 22v-4H2"})]}),"scan"===d?"Scanning...":`Scan ${"python"===t?"Python":"R"}`]}),(0,n.jsx)("button",{type:"button",onClick:()=>void N("all"),disabled:!!d,style:{...rZ,opacity:d?.55:1},children:"Scan all"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginLeft:"auto"},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"Idle"}),(0,n.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:rJ.map(e=>{let t=w===e.value;return(0,n.jsx)("button",{type:"button",onClick:()=>{t||K(e.value)},disabled:E,title:`Close inactive Workbench kernels after ${rq(e.value)}`,style:{height:24,padding:"0 8px",border:"none",borderRadius:5,background:t?"var(--bg)":"transparent",color:t?"var(--accent)":"var(--text-muted)",cursor:E?"default":"pointer",fontSize:11,fontWeight:t?700:500,opacity:E?.65:1},children:e.label},e.label)})})]}),(0,n.jsxs)("button",{type:"button",onClick:U,style:{...rZ,marginLeft:"auto",color:"var(--accent)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add kernel"]})]}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"10px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Save defaults"}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"Format"}),(0,n.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:["pdf","png","svg"].map(e=>{let t=C===e;return(0,n.jsx)("button",{type:"button",onClick:()=>T(e),style:{height:24,padding:"0 8px",border:"none",borderRadius:5,background:t?"var(--bg)":"transparent",color:t?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:t?700:500},children:e.toUpperCase()},e)})}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"DPI"}),(0,n.jsx)("input",{type:"number",value:z,onChange:e=>I(Number(e.target.value)||300),min:72,max:1200,style:{width:60,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"W"}),(0,n.jsx)("input",{type:"number",value:M,onChange:e=>R(Number(e.target.value)||800),min:100,max:8e3,style:{width:65,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"H"}),(0,n.jsx)("input",{type:"number",value:W,onChange:e=>L(Number(e.target.value)||600),min:100,max:8e3,style:{width:65,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,n.jsx)("button",{type:"button",onClick:()=>void J(),disabled:E,style:{...rZ,background:"var(--accent)",borderColor:"var(--accent)",color:"#fff",opacity:E?.6:1},children:E?"Saving...":"Save"})]}),(p||h||g.length>0)&&(0,n.jsxs)("div",{style:{flexShrink:0,padding:"8px 16px",borderBottom:"1px solid var(--border)",fontSize:12,lineHeight:1.5},children:[p&&(0,n.jsx)("div",{style:{color:"#f87171"},children:p}),h&&(0,n.jsx)("div",{style:{color:"var(--text-muted)"},children:h}),g.map(e=>(0,n.jsx)("div",{style:{color:"rgba(234,179,8,0.95)"},children:e},e))]}),(0,n.jsxs)("div",{style:{flex:1,minHeight:0,display:"flex",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:290,flexShrink:0,borderRight:"1px solid var(--border)",background:"var(--bg-panel)",display:"flex",flexDirection:"column",minHeight:0},children:[(0,n.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,n.jsxs)("div",{children:["Global: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:rV(o?.paths.global??"")})]}),e&&(0,n.jsxs)("div",{children:["Project: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:rV(o?.paths.project??"")})]}),!e&&(0,n.jsx)("div",{children:"Project selection requires an active cwd."})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",padding:"8px 6px"},children:s?(0,n.jsx)("div",{style:{padding:"10px 8px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}):0===D.length?(0,n.jsx)("div",{style:{padding:"10px 8px",color:"var(--text-dim)",fontSize:12},children:"No kernels found"}):D.map(e=>{let t=v===e.id&&"new"!==y;return(0,n.jsxs)("button",{type:"button",onClick:()=>{m(e.id),b("view"),k(rG(e)),u(null),x(null)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"8px 9px",border:"none",borderRadius:6,background:t?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:e.isEffective?"var(--accent)":"var(--border)",flexShrink:0}}),(0,n.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("span",{style:{display:"block",color:"var(--text)",fontSize:12,fontWeight:t?600:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,n.jsx)("span",{style:{display:"block",color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.id})]}),(e.isProjectSelected||e.isDefault)&&(0,n.jsxs)("span",{style:{flexShrink:0,display:"flex",gap:3},children:[e.isProjectSelected&&(0,n.jsx)("span",{title:"Project selected",style:{fontSize:9,color:"var(--accent)",border:"1px solid rgba(37,99,235,0.35)",borderRadius:4,padding:"1px 4px"},children:"P"}),e.isDefault&&(0,n.jsx)("span",{title:"Global default",style:{fontSize:9,color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:4,padding:"1px 4px"},children:"D"})]})]},e.id)})}),(0,n.jsxs)("div",{style:{padding:"8px 10px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:["Last scan: ",function(e){if(!e)return"never";let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}(o?.scanCache?.lastScan)]})]}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,minHeight:0,overflowY:"auto",padding:18},children:"view"===y&&A?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16,maxWidth:760},children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("h3",{style:{margin:0,color:"var(--text)",fontSize:15,lineHeight:1.3},children:A.displayName}),A.isEffective&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",border:"1px solid rgba(37,99,235,0.35)",borderRadius:4,padding:"1px 5px"},children:"active"})]}),(0,n.jsx)("div",{style:{marginTop:5,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:A.id})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsx)(rQ,{label:"Command",children:(0,n.jsx)("input",{readOnly:!0,value:A.command,style:{...rX,color:"var(--text-muted)"}})}),(0,n.jsx)(rQ,{label:"Args",children:(0,n.jsx)("input",{readOnly:!0,value:JSON.stringify(A.args),style:{...rX,color:"var(--text-muted)"}})})]}),(0,n.jsx)(rQ,{label:"Environment",children:(0,n.jsx)("textarea",{readOnly:!0,value:JSON.stringify(A.env,null,2),rows:5,style:{...rX,resize:"vertical",color:"var(--text-muted)"}})}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>e&&void O(A),disabled:!e||"select"===d,style:{...rZ,background:e?"var(--accent)":"var(--bg-panel)",color:e?"#fff":"var(--text-dim)",opacity:"select"===d?.6:1},children:"Use for project"}),(0,n.jsx)("button",{type:"button",onClick:()=>void H(A),disabled:"default"===d,style:{...rZ,opacity:"default"===d?.6:1},children:"Set default"}),(0,n.jsx)("button",{type:"button",onClick:()=>{b("edit"),m(A.id),k(rG(A)),u(null),x(null)},style:rZ,children:"Edit"}),!A.id.startsWith("default-")&&(0,n.jsx)("button",{type:"button",onClick:()=>void _(A),disabled:"delete"===d,style:{...rZ,color:"#f87171",opacity:"delete"===d?.6:1},children:"Delete"})]})]}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:14,maxWidth:760},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("h3",{style:{margin:0,color:"var(--text)",fontSize:15},children:"new"===y?"Add Kernel":"Edit Kernel"}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"python"===t?"Python":"R"})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsx)(rQ,{label:"Kernel ID",children:(0,n.jsx)("input",{value:j.id,readOnly:"edit"===y,onChange:e=>k(t=>({...t,id:e.target.value})),placeholder:"python"===t?"my-python":"my-r",style:{...rX,color:"edit"===y?"var(--text-muted)":"var(--text)"}})}),(0,n.jsx)(rQ,{label:"Display name",children:(0,n.jsx)("input",{value:j.displayName,onChange:e=>k(t=>({...t,displayName:e.target.value})),placeholder:"python"===t?"Python 3 (Project)":"R (Project)",style:rX})})]}),(0,n.jsx)(rQ,{label:"Command",children:(0,n.jsx)("input",{value:j.command,onChange:e=>k(t=>({...t,command:e.target.value})),placeholder:"/usr/bin/python3",style:rX})}),(0,n.jsx)(rQ,{label:"Args JSON",children:(0,n.jsx)("input",{value:j.argsText,onChange:e=>k(t=>({...t,argsText:e.target.value})),style:rX})}),(0,n.jsx)(rQ,{label:"Env JSON",children:(0,n.jsx)("textarea",{value:j.envText,onChange:e=>k(t=>({...t,envText:e.target.value})),rows:6,style:{...rX,resize:"vertical"}})}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("button",{type:"button",onClick:()=>void F(),disabled:"save"===d,style:{...rZ,background:"var(--accent)",borderColor:"var(--accent)",color:"#fff",opacity:"save"===d?.6:1},children:"save"===d?"Saving...":"Save"}),(0,n.jsx)("button",{type:"button",onClick:()=>{let e=A??D.find(e=>e.isEffective)??D[0]??null;e?(m(e.id),k(rG(e)),b("view")):U(),u(null)},style:rZ,children:"Cancel"})]})]})})]})]})}var r1=r(7834);function r2({text:e,label:t="Copy",title:r,onCopied:o,onError:l}){let[s,a]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!s)return;let e=setTimeout(()=>a(!1),1500);return()=>clearTimeout(e)},[s]);let d=(0,i.useCallback)(async()=>{try{await (0,r1.D)(e),a(!0),o?.()}catch(e){l?.(e instanceof Error?e:Error(String(e)))}},[o,l,e]);return(0,n.jsx)("button",{type:"button",onClick:()=>void d(),title:r??(s?"Copied":t),style:{height:24,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-hover)",color:s?"#22c55e":"var(--text-muted)",fontSize:10,fontWeight:600,cursor:"pointer",flexShrink:0},children:s?"Copied":t})}r(41463);let r5="annovibe-im-gateway";function r4({cwd:e,embedded:t=!1}){let[r,o]=(0,i.useState)(null),[l,s]=(0,i.useState)(null),[a,d]=(0,i.useState)(null),[c,p]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(""),[m,y]=(0,i.useState)(""),[b,j]=(0,i.useState)(!1),[k,w]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!1),[T,z]=(0,i.useState)(null),[I,M]=(0,i.useState)(null),R=(0,i.useCallback)((e,t)=>{"success"===t?(M(e),z(null),setTimeout(()=>M(null),4500)):(z(e),M(null))},[]),W=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/im/gateway-status",{cache:"no-store"}),t=await e.json();if(!e.ok||!t.gateway)return;d(t.gateway)}catch{}},[]),L=(0,i.useCallback)(async()=>{j(!0),z(null);try{let t=await fetch(`/api/im/project?cwd=${encodeURIComponent(e)}`,{cache:"no-store"}),r=await t.json();if(!t.ok||!("enabled"in r))throw Error(r.error??`HTTP ${t.status}`);o(r),s(r.gatewayToken??null),p(r.botId),g(r.requireMentionInGroup),v(r.boundChatId??""),y(r.allowedUsers.join("\n")),h("")}catch(e){R(e instanceof Error?e.message:String(e),"error")}finally{j(!1)}},[e,R]);(0,i.useEffect)(()=>{L()},[L]),(0,i.useEffect)(()=>{if(!r?.enabled)return void d(null);W();let e=setInterval(()=>{W()},12e3);return()=>clearInterval(e)},[r?.enabled,W]);let E=(0,i.useCallback)(async t=>{w(!0),z(null),M(null);try{let r=await fetch("/api/im/project",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,config:t})}),n=await r.json();if(!r.ok||!("enabled"in n))throw Error(n.error??`HTTP ${r.status}`);o(n),s(n.gatewayToken??null),h(""),R("IM settings saved.","success")}catch(e){R(e instanceof Error?e.message:String(e),"error")}finally{w(!1)}},[e,R]),$=(0,i.useCallback)(e=>{E({enabled:e,botId:c.trim(),botSecret:u.trim()||void 0,requireMentionInGroup:x,boundChatId:f.trim()||null,allowedUsers:r7(m)})},[c,u,x,f,m,E]),P=(0,i.useCallback)(()=>{E({enabled:r?.enabled??!1,botId:c.trim(),botSecret:u.trim()||void 0,requireMentionInGroup:x,boundChatId:f.trim()||null,allowedUsers:r7(m)})},[r?.enabled,c,u,x,f,m,E]),D=(0,i.useCallback)(()=>{E({regeneratePairingCode:!0})},[E]),A=(0,i.useCallback)(async()=>{if(r?.sessionId&&window.confirm("Reset the IM thread for this project?\n\nThis clears the stored WeCom session. Pairing and bot settings are kept. The next IM message starts a fresh session.")){C(!0);try{let t=await fetch(`/api/im/session-ids?cwd=${encodeURIComponent(e)}`,{method:"DELETE"}),r=await t.json();if(!t.ok||!r.ok)throw Error(r.error??`HTTP ${t.status}`);o(e=>e?{...e,sessionId:null}:null),R("IM thread reset.","success")}catch(e){R(e instanceof Error?e.message:String(e),"error")}finally{C(!1)}}},[r?.sessionId,e,R]);if(b&&!r)return(0,n.jsx)(nt,{label:"Loading IM settings..."});let B=r?.enabled??!1;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,paddingTop:12*!!t},children:[(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",padding:12,display:"flex",flexDirection:"column",gap:12},children:[(0,n.jsx)(r6,{label:"WeCom bot for this project",description:B?"启动 im-gateway 后即可通过企业微信 AI bot 与此项目交互。":"关闭 — 开启后可绑定企业微信 bot 到此项目。",checked:B,disabled:k,onChange:$}),B?(0,n.jsxs)(n.Fragment,{children:[a?(0,n.jsx)(r3,{status:a}):null,(0,n.jsx)(r9,{label:"Bot ID",value:c,onChange:p,placeholder:"从企业微信 AI bot 控制台获取"}),(0,n.jsx)(r9,{label:r?.hasSecret?"Bot Secret(留空则不修改)":"Bot Secret",value:u,onChange:h,placeholder:r?.hasSecret?"留空保留现有 secret":"从企业微信 AI bot 控制台获取",secret:!0}),(0,n.jsx)(r6,{label:"群聊中需要 @提及 bot 才响应",description:"开启后,群聊中用户必须 @bot 才会被处理。",checked:x,disabled:k,compact:!0,onChange:g}),(0,n.jsx)(r9,{label:"绑定群聊 ID(可选)",value:f,onChange:v,placeholder:"限制仅此群聊可交互"}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:"允许用户 ID(一行一个)"}),(0,n.jsx)("textarea",{value:m,onChange:e=>y(e.target.value),rows:3,style:ni,placeholder:"用户也可通过配对码自助授权"})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[(0,n.jsx)(ne,{primary:!0,disabled:k,onClick:P,children:k?"保存中…":"保存 IM 配置"}),(0,n.jsx)(ne,{disabled:k,onClick:D,children:"重新生成配对码"})]})]}):null]}),B&&r?(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",padding:12,fontSize:11,color:"var(--text-muted)",display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsx)(r8,{label:"配对码",value:r.pairingCode,copyLabel:"复制配对码"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,flexWrap:"wrap"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"IM session:"})," ",r.sessionId?`${r.sessionId.slice(0,12)}…`:"尚未启动"]}),r.sessionId?(0,n.jsx)(ne,{danger:!0,disabled:k||S,onClick:()=>void A(),children:S?"重置中…":"重置 IM thread"}):null]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"Gateway token:"})," ",l?`${l.slice(0,8)}…`:"保存时生成"]}),(0,n.jsx)(r8,{label:"Gateway 启动命令",value:r5,copyLabel:"复制命令",mono:!0}),(0,n.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["启动 ",(0,n.jsx)("code",{style:nr,children:"annovibe"})," 后,在",(0,n.jsx)("strong",{style:{color:"var(--text-muted)",fontWeight:600},children:"同一 Linux 账户"}),"中运行"," ",(0,n.jsx)("code",{style:nr,children:r5}),"。 Gateway 通过本地 API 读取已启用的项目配置和 bot secret —— 无需手动复制文件。"]}),(0,n.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["配置文件: ",(0,n.jsxs)("code",{style:nr,children:["<project>","/.annovibe/im.json"]})," \xb7 Secrets: ",(0,n.jsx)("code",{style:nr,children:"~/.pi/agent/im-secrets/"})]}),T&&(0,n.jsx)("div",{style:{padding:"6px 10px",background:"rgba(239,68,68,0.08)",borderRadius:6,border:"1px solid rgba(239,68,68,0.3)",color:"#ef4444",fontSize:12},children:T}),I&&(0,n.jsx)("div",{style:{padding:"6px 10px",background:"rgba(34,197,94,0.08)",borderRadius:6,border:"1px solid rgba(34,197,94,0.3)",color:"#22c55e",fontSize:12},children:I})]}):null]})}function r3({status:e}){var t,r,i,o;let l=function(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}(e.startedAt),s=e.alive&&e.pid?`pid ${e.pid}${l?` \xb7 since ${l}`:""}`:l?`last started ${l}`:"在同一个 Linux 账户下运行 annovibe-im-gateway";return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"8px 10px",borderRadius:8,border:`1px solid ${"running"===(t=e.tone)?"rgba(34,197,94,0.28)":"stale"===t?"rgba(245,158,11,0.28)":"rgba(248,113,113,0.28)"}`,background:"running"===(r=e.tone)?"rgba(34,197,94,0.08)":"stale"===r?"rgba(245,158,11,0.08)":"rgba(248,113,113,0.08)"},children:[(0,n.jsx)("span",{"aria-hidden":!0,style:{width:8,height:8,borderRadius:"50%",marginTop:4,flexShrink:0,background:"running"===(i=e.tone)?"#22c55e":"stale"===i?"#f59e0b":"#f87171"}}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:650,color:"running"===(o=e.tone)?"#22c55e":"stale"===o?"#f59e0b":"#f87171"},children:e.label}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:3,lineHeight:1.45},children:s})]})]})}function r8({label:e,value:t,copyLabel:r,mono:i}){return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsxs)("strong",{style:{color:"var(--text)"},children:[e,":"]})," ",(0,n.jsx)("code",{style:{...nr,...i?{wordBreak:"break-all"}:{}},children:t})]}),(0,n.jsx)(r2,{text:t,label:r})]})}function r6({label:e,description:t,checked:r,disabled:i,compact:o,onChange:l}){return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:o?"2px 0":"10px 12px",borderRadius:8*!o,border:o?"none":`1px solid ${r?"color-mix(in srgb, var(--accent) 35%, var(--border))":"var(--border)"}`,background:o?"transparent":r?"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))":"var(--bg)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:o?11:13,fontWeight:o?500:650,color:"var(--text)"},children:e}),t?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:4,lineHeight:1.45},children:t}):null]}),(0,n.jsx)("button",{type:"button",role:"switch","aria-checked":r,disabled:i,onClick:()=>l(!r),style:{position:"relative",width:44,height:26,borderRadius:999,border:"none",flexShrink:0,background:r?"var(--accent)":"color-mix(in srgb, var(--text-dim) 35%, var(--border))",cursor:i?"default":"pointer",opacity:i?.55:1,transition:"background 0.15s",padding:0},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:r?21:3,width:20,height:20,borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.18)",transition:"left 0.15s"}})})]})}function r7(e){return e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean)}function r9({label:e,value:t,onChange:r,placeholder:i,secret:o}){return(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:e}),(0,n.jsx)("input",{type:o?"password":"text",value:t,onChange:e=>r(e.target.value),placeholder:i,style:nn})]})}function ne({children:e,disabled:t,primary:r,danger:i,onClick:o}){return(0,n.jsx)("button",{type:"button",disabled:t,onClick:o,style:{height:28,padding:"0 10px",borderRadius:6,border:r?"none":i?"1px solid rgba(248,113,113,0.45)":"1px solid var(--border)",background:r?"var(--accent)":i?"rgba(248,113,113,0.08)":"var(--bg-hover)",color:r?"#fff":i?"#f87171":"var(--text)",fontSize:11,fontWeight:r?600:400,cursor:t?"default":"pointer",opacity:t?.55:1},children:e})}function nt({label:e}){return(0,n.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:"18px 10px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:e})}let nr={fontFamily:"var(--font-mono)",fontSize:"0.95em"},nn={height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"},ni={padding:"8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",resize:"vertical"},no={border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)"},nl={height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12};function ns({cwd:e}){let[t,r]=(0,i.useState)(null),[o,l]=(0,i.useState)(!0),[s,a]=(0,i.useState)(null),[d,c]=(0,i.useState)(null),p=(0,i.useCallback)(async()=>{l(!0),c(null);try{let t=await fetch(`/api/plot-kernels?cwd=${encodeURIComponent(e)}`),n=await t.json().catch(()=>({}));if(!t.ok||n.error||!Array.isArray(n.kernels))throw Error(n.error??`HTTP ${t.status}`);r(n)}catch(e){r(null),c(e instanceof Error?e.message:String(e))}finally{l(!1)}},[e]);(0,i.useEffect)(()=>{p()},[p]);let u=(0,i.useCallback)(async(t,n)=>{a(t),c(null);try{let i=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"select",cwd:e,language:t,kernelId:n})}),o=await i.json().catch(()=>({}));if(!i.ok||o.error||!Array.isArray(o.kernels))throw Error(o.error??`HTTP ${i.status}`);r(o)}catch(e){c(e instanceof Error?e.message:String(e))}finally{a(null)}},[e]),h=e=>{let r=t?.kernels.filter(t=>t.language===e)??[],i=r.find(e=>e.isEffective)??r[0]??null;return(0,n.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"r"===e?"Default R kernel":"Default Python kernel"}),(0,n.jsx)("select",{value:i?.id??"",disabled:o||s===e||0===r.length,onChange:t=>{t.target.value&&u(e,t.target.value)},style:{height:32,padding:"0 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12},children:0===r.length?(0,n.jsx)("option",{value:"",children:o?"Loading...":"No configured kernel"}):r.map(e=>(0,n.jsxs)("option",{value:e.id,children:[e.displayName,e.isProjectSelected?" \xb7 project":e.isDefault?" \xb7 global":""," — ",e.command," ",(e.args??[]).join(" ")]},e.id))})]})};return(0,n.jsxs)("section",{style:{...no,padding:14,display:"grid",gap:12},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Default kernels"}),(0,n.jsx)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)",lineHeight:1.45},children:"Used as the default R/Python kernels for Workbench sessions. Normal chats also use these when they call Workbench kernel tools for analysis."})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",gap:10},children:[h("r"),h("python")]}),d&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:d})]})}function na({activeCwd:e,onSelectProject:t,onProjectsChanged:r}){let[o,l]=(0,i.useState)([]),[s,a]=(0,i.useState)(e),[c,p]=(0,i.useState)(null),[u,h]=(0,i.useState)(!0),[x,g]=(0,i.useState)(null),[f,v]=(0,i.useState)(""),[m,y]=(0,i.useState)(!1),[b,j]=(0,i.useState)(null),[k,w]=(0,i.useState)(null),[S,C]=(0,i.useState)(""),[T,z]=(0,i.useState)(null),[I,M]=(0,i.useState)(null),R=(0,i.useRef)(null),W=o.find(e=>e.cwd===s)??o.find(t=>t.cwd===e)??o[0]??null,L=(0,i.useCallback)(async()=>{try{h(!0);let t=await fetch("/api/projects"),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);let n=r.projects??[];l(n),a(t=>t&&n.some(e=>e.cwd===t)?t:e&&n.some(t=>t.cwd===e)?e:n[0]?.cwd??null),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}finally{h(!1)}},[e]);(0,i.useEffect)(()=>{L()},[L]),(0,i.useEffect)(()=>{e&&o.some(t=>t.cwd===e)&&a(e)},[e,o]);let E=(0,i.useMemo)(()=>({projects:o.length,chats:o.reduce((e,t)=>e+t.chatCount,0)}),[o]),$=(0,i.useCallback)(async()=>{let e=f.trim();if(e){j("add"),g(null);try{let n=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),i=await n.json();if(!n.ok||i.error)throw Error(i.error??`HTTP ${n.status}`);v(""),a(e),r?.(),t?.(e),L()}catch(e){g(e instanceof Error?e.message:String(e))}finally{j(null)}}},[L,r,t,f]),P=(0,i.useCallback)(async e=>{j("add"),g(null);try{let n=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),i=await n.json();if(!n.ok||i.error)throw Error(i.error??`HTTP ${n.status}`);v(""),y(!1),a(e),r?.(),t?.(e),L()}catch(e){g(e instanceof Error?e.message:String(e))}finally{j(null)}},[L,r,t]),D=(0,i.useCallback)(async e=>{j(`rename:${e}`),g(null);try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,name:S})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);w(null),C(""),await L(),r?.()}catch(e){g(e instanceof Error?e.message:String(e))}finally{j(null)}},[L,r,S]),A=(0,i.useCallback)(async e=>{if(window.confirm("Remove this project from AnnoVibe? Sessions on disk will not be deleted.")){j(`remove:${e}`),g(null);try{let t=await fetch("/api/projects",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),n=await t.json();if(!t.ok||n.error)throw Error(n.error??`HTTP ${t.status}`);a(t=>t===e?null:t),await L(),r?.()}catch(e){g(e instanceof Error?e.message:String(e))}finally{j(null)}}},[L,r]),B=(0,i.useCallback)(e=>{w(e.cwd),C(e.displayName),requestAnimationFrame(()=>R.current?.focus())},[]),N=(0,i.useCallback)(async e=>{try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:e})});if(!t.ok)throw Error(`HTTP ${t.status}`);r?.()}catch{L()}},[L,r]),O=(0,i.useCallback)((e,t)=>{"reorder"!==b&&(z(e),t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/project-cwd",e))},[b]),H=(0,i.useCallback)((e,t)=>{t.preventDefault(),t.dataTransfer.dropEffect="move",M(e)},[]),F=(0,i.useCallback)(e=>{if(M(null),!T||T===e)return void z(null);let t=o.map(e=>e.cwd).filter(Boolean),r=t.indexOf(T),n=t.indexOf(e);r<0||n<0?z(null):(t.splice(r,1),t.splice(n,0,T),l(e=>{let r=new Map(e.map(e=>[e.cwd,e]));return t.map(e=>r.get(e)).filter(Boolean)}),z(null),N(t))},[T,N,o]),_=(0,i.useCallback)(()=>{z(null),M(null)},[]);return(0,n.jsxs)("div",{style:{height:"100%",overflow:"hidden",display:"flex",flexDirection:"column"},children:[x&&(0,n.jsx)("div",{style:{marginBottom:12,padding:"10px 12px",borderRadius:8,border:"1px solid rgba(248,113,113,0.35)",background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:12},children:x}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,marginBottom:14,flexShrink:0},children:[(0,n.jsx)("div",{style:{position:"relative",flex:1,minWidth:0},children:(0,n.jsx)("input",{type:"text",value:f,onChange:e=>v(e.target.value),onKeyDown:e=>{"Enter"===e.key&&$()},placeholder:"/path/to/project",style:{width:"100%",height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",outline:"none"}})}),(0,n.jsx)("button",{type:"button",disabled:"add"===b,onClick:()=>void $(),style:{height:30,padding:"0 11px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12,fontWeight:500},children:"Add"}),(0,n.jsx)("button",{type:"button",onClick:()=>y(!0),style:{...nl,height:30},children:"Browse…"})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(220px, 34%) minmax(0, 1fr)",gap:14,minHeight:0,flex:1},children:[(0,n.jsxs)("aside",{style:{...no,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:700},children:[E.projects," Projects"]}),(0,n.jsxs)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11},children:[E.chats," chats total"]})]}),(0,n.jsx)("div",{style:{overflow:"auto",padding:8,display:"grid",gap:6},children:u?(0,n.jsx)("div",{style:{padding:12,color:"var(--text-muted)",fontSize:12},children:"Loading projects..."}):0===o.length?(0,n.jsx)("div",{style:{padding:12,color:"var(--text-muted)",fontSize:12},children:"No projects yet."}):o.map(t=>{var r;let i,o=t.cwd===e,l=t.cwd===W?.cwd,s=T===t.cwd,d=I===t.cwd&&T!==t.cwd,u=c===t.cwd&&!l;return(0,n.jsxs)("button",{type:"button",draggable:!0,onClick:()=>a(t.cwd),onDragStart:e=>O(t.cwd,e),onDragOver:e=>H(t.cwd,e),onDrop:()=>F(t.cwd),onDragEnd:_,onMouseEnter:()=>p(t.cwd),onMouseLeave:()=>p(null),style:{display:"grid",gap:4,width:"100%",textAlign:"left",padding:"9px 10px",border:`1px solid ${d?"rgba(37,99,235,0.45)":l?"color-mix(in srgb, var(--accent) 45%, var(--border))":"transparent"}`,borderRadius:8,background:d?"rgba(37,99,235,0.06)":l?"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))":"transparent",color:"var(--text)",cursor:"pointer",opacity:s?.55:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12.5,fontWeight:l?750:600},children:t.displayName}),o&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontWeight:700},children:"current"}),u&&(0,n.jsx)("span",{onClick:e=>{e.stopPropagation(),A(t.cwd)},style:{color:"#f87171",fontSize:11,fontWeight:650},children:"remove"})]}),(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontSize:10.5,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:t.cwd,children:(i=(r=t.cwd).split(/[\\/]/).filter(Boolean)).length<=3?r:`.../${i.slice(-3).join("/")}`})]},t.cwd)})})]}),(0,n.jsx)("main",{style:{minHeight:0,overflow:"auto"},children:W?(0,n.jsxs)("div",{style:{display:"grid",gap:14},children:[(0,n.jsx)("section",{style:{...no,padding:14,display:"grid",gap:12},children:(0,n.jsxs)("div",{style:{display:"flex",gap:12,alignItems:"flex-start"},children:[(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[k===W.cwd?(0,n.jsx)("input",{ref:R,value:S,onChange:e=>C(e.target.value),onKeyDown:e=>{"Enter"===e.key&&D(W.cwd),"Escape"===e.key&&w(null)},style:{width:"min(420px, 100%)",height:32,padding:"0 9px",border:"1px solid var(--accent)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontSize:13,outline:"none"}}):(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:16,fontWeight:750},children:W.displayName}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:W.cwd}),(0,n.jsxs)("div",{style:{marginTop:7,color:"var(--text-muted)",fontSize:11},children:[W.chatCount," chats / last ",function(e){if(!e)return"Never";let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),i=Math.floor(r/36e5),o=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:i<24?`${i}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}(W.lastAccessed??W.created??null),W.exists?"":" / path missing"]})]}),(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",justifyContent:"flex-end"},children:k===W.cwd?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",disabled:b===`rename:${W.cwd}`,onClick:()=>void D(W.cwd),style:{...nl,border:"none",background:"var(--accent)",color:"#fff"},children:"Save"}),(0,n.jsx)("button",{type:"button",onClick:()=>w(null),style:nl,children:"Cancel"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>t?.(W.cwd),style:{...nl,background:W.cwd===e?"var(--accent)":"var(--bg-panel)",color:W.cwd===e?"#fff":"var(--text-muted)"},children:W.cwd===e?"Current":"Switch"}),(0,n.jsx)("button",{type:"button",onClick:()=>B(W),style:nl,children:"Rename"}),(0,n.jsx)("button",{type:"button",disabled:b===`remove:${W.cwd}`,onClick:()=>void A(W.cwd),style:{...nl,border:"1px solid rgba(248,113,113,0.35)",background:"transparent",color:"#f87171"},children:"Remove"})]})})]})}),(0,n.jsx)(ns,{cwd:W.cwd}),(0,n.jsxs)("section",{style:{...no,padding:14,display:"grid",gap:12},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"WeCom IM"}),(0,n.jsx)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)"},children:"Project notification and chat gateway settings."})]}),(0,n.jsx)(r4,{cwd:W.cwd,embedded:!0})]})]}):(0,n.jsx)("div",{style:{...no,padding:18,color:"var(--text-muted)",fontSize:12},children:"Select a project to edit settings."})})]}),(0,n.jsx)(d,{open:m,initialPath:e,onClose:()=>y(!1),onSelect:e=>void P(e)})]})}var nd=r(768);let nc=["127.0.0.0/8","::1","10.0.0.0/8","172.16.0.0/12","192.168.0.0/16"];function np({checked:e,onChange:t}){return(0,n.jsx)("button",{type:"button",onClick:t,"aria-pressed":e,style:{width:44,height:24,borderRadius:999,border:"none",padding:0,cursor:"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",flexShrink:0},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:e?23:3,width:18,height:18,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function nu({label:e,description:t,checked:r,onChange:i}){return(0,n.jsxs)("label",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"10px 12px",borderRadius:8,border:`1px solid ${r?"var(--accent)":"var(--border)"}`,background:r?"rgba(37,99,235,0.04)":"var(--bg)",cursor:"pointer",fontSize:12},children:[(0,n.jsx)("input",{type:"radio",checked:r,onChange:i,style:{marginTop:2,accentColor:"var(--accent)"}}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontWeight:600,color:"var(--text)",lineHeight:1.4},children:e}),(0,n.jsx)("div",{style:{color:"var(--text-dim)",lineHeight:1.5,marginTop:2},children:t})]})]})}function nh(){let[e,t]=(0,i.useState)(null),[r,o]=(0,i.useState)(!0),[l,s]=(0,i.useState)(null),[a,d]=(0,i.useState)(null),[c,p]=(0,i.useState)(""),[u,h]=(0,i.useState)(""),[x,g]=(0,i.useState)(null),[f,v]=(0,i.useState)(null),[m,y]=(0,i.useState)(null),[b,j]=(0,i.useState)(!1),[k,w]=(0,i.useState)("always"),[S,C]=(0,i.useState)(nc),[T,z]=(0,i.useState)(""),I=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/auth/totp"),r=await e.json();t(r),w(r.requireMode??"always"),C(r.trustedNetworks??nc)}catch{}finally{o(!1)}},[]);(0,i.useEffect)(()=>{I()},[I]);let M=async()=>{if(e){if(g(null),"enabled"===e.status){if(!u||!/^\d{6}$/.test(u))return void g("Enter your 6-digit authenticator code to disable");j(!0);try{let e=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"disable",code:u})}),r=await e.json();e.ok?(t({status:"disabled",enabled:!1,requireMode:"always",trustedNetworks:nc}),h(""),s(null),d(null),y(null),v("Two-factor authentication disabled")):g(r.error??"Failed to disable")}catch{g("Network error")}finally{j(!1)}return}j(!0);try{let e=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"setup"})}),r=await e.json();if(e.ok&&r.uri){d(r.uri);let e=await nd.toDataURL(r.uri,{width:200,margin:1});s(e),t({status:"pending",enabled:!1,requireMode:k,trustedNetworks:S}),v(null)}else g(r.error??"Failed to start setup")}catch{g("Network error")}finally{j(!1)}}},R=async()=>{if(!c||!/^\d{6}$/.test(c))return void g("Enter the 6-digit code from your authenticator app");j(!0),g(null);try{let e=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"verify-setup",code:c})}),r=await e.json();e.ok&&r.success?(await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-require-mode",requireMode:k})}),await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:S})}),t({status:"enabled",enabled:!0,requireMode:k,trustedNetworks:S}),p(""),s(null),d(null),r.recoveryCodes&&y(r.recoveryCodes),v("Two-factor authentication enabled!")):g(r.error??"Invalid code")}catch{g("Network error")}finally{j(!1)}},W=async()=>{s(null),d(null),p(""),g(null);try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"disable"})}),t({status:"disabled",enabled:!1,requireMode:"always",trustedNetworks:nc})}catch{}},L=(0,i.useCallback)(async r=>{if(w(r),e?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-require-mode",requireMode:r})}),t(e=>e?{...e,requireMode:r}:e)}catch{w(e.requireMode)}},[e]),E=(0,i.useCallback)(async()=>{let r=T.trim();if(!r||S.includes(r))return;let n=r.split("/");if(2!==n.length)return void g("Invalid CIDR format (e.g. 192.168.1.0/24)");let i=parseInt(n[1],10);if(isNaN(i)||i<0||i>128)return void g("Invalid CIDR prefix length");g(null);let o=[...S,r];if(C(o),z(""),e?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:o})}),t(e=>e?{...e,trustedNetworks:o}:e)}catch{C(S)}},[T,S,e]),$=(0,i.useCallback)(async r=>{let n=S.filter(e=>e!==r);if(C(n),e?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:n})}),t(e=>e?{...e,trustedNetworks:n}:e)}catch{C(S)}},[S,e]);return r?(0,n.jsx)("div",{style:{padding:20,fontSize:13,color:"var(--text-muted)"},children:"Loading…"}):(0,n.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,n.jsxs)("div",{style:{maxWidth:600,display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",lineHeight:1.35},children:"Two-Factor Authentication"}),(0,n.jsx)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Require a time-based one-time code in addition to your password."})]}),(0,n.jsx)(np,{checked:e?.status==="enabled",onChange:()=>{}})]}),e&&(0,n.jsx)("div",{style:{fontSize:11,padding:"4px 10px",borderRadius:999,background:"enabled"===e.status?"rgba(34,197,94,0.12)":"pending"===e.status?"rgba(250,204,21,0.12)":"var(--bg-hover)",color:"enabled"===e.status?"#16a34a":"pending"===e.status?"#ca8a04":"var(--text-dim)",display:"inline-flex",alignSelf:"flex-start",fontWeight:600},children:"enabled"===e.status?"● Active":"pending"===e.status?"◐ Setup in progress":"○ Inactive"}),x&&(0,n.jsx)("div",{style:{fontSize:12,color:"#ef4444",padding:"8px 12px",background:"rgba(239,68,68,0.06)",borderRadius:6},children:x}),f&&!x&&(0,n.jsx)("div",{style:{fontSize:12,color:"#16a34a",padding:"8px 12px",background:"rgba(34,197,94,0.06)",borderRadius:6},children:f}),e?.status==="pending"&&l&&(0,n.jsxs)("div",{style:{padding:20,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",display:"flex",flexDirection:"column",alignItems:"center",gap:14},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:"Scan with your authenticator app"}),(0,n.jsx)("div",{style:{background:"#fff",padding:12,borderRadius:8,border:"1px solid var(--border)"},children:(0,n.jsx)("img",{src:l,alt:"TOTP QR Code",style:{display:"block",width:200,height:200}})}),a&&(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",textAlign:"center",maxWidth:280},children:[(0,n.jsx)("div",{style:{marginBottom:4},children:"Or enter this key manually:"}),(0,n.jsx)("code",{style:{fontSize:11,fontFamily:"var(--font-mono), monospace",wordBreak:"break-all",background:"var(--bg)",padding:"4px 8px",borderRadius:4},children:a.split("secret=")[1]?.split("&")[0]??"—"})]}),(0,n.jsxs)("div",{style:{width:"100%",maxWidth:260},children:[(0,n.jsx)("label",{style:{fontSize:12,color:"var(--text-dim)",display:"block",marginBottom:6},children:"Enter the 6-digit code to verify"}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:c,onChange:e=>p(e.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000 000",style:{flex:1,padding:"8px 12px",fontSize:16,fontFamily:"var(--font-mono), monospace",letterSpacing:"0.12em",textAlign:"center",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,n.jsx)("button",{type:"button",disabled:b||6!==c.length,onClick:R,style:{padding:"8px 16px",fontSize:13,fontWeight:600,background:6===c.length?"var(--accent)":"var(--bg-hover)",color:6===c.length?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:6===c.length?"pointer":"not-allowed"},children:b?"…":"Verify"})]})]}),(0,n.jsx)("button",{type:"button",onClick:W,style:{fontSize:12,color:"var(--text-dim)",background:"none",border:"none",cursor:"pointer"},children:"Cancel setup"})]}),m&&m.length>0&&(0,n.jsxs)("div",{style:{padding:20,border:"1px solid rgba(34,197,94,0.3)",borderRadius:8,background:"rgba(34,197,94,0.04)"},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:6},children:"Recovery codes"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:12,lineHeight:1.55},children:"Save these codes in a safe place. Each can be used once to sign in if you lose access to your authenticator app. They will not be shown again."}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:6,fontFamily:"var(--font-mono), monospace",fontSize:12,color:"var(--text)"},children:m.map((e,t)=>(0,n.jsx)("code",{style:{padding:"6px 10px",background:"var(--bg)",borderRadius:4,border:"1px solid var(--border)"},children:e},t))}),(0,n.jsx)("button",{type:"button",onClick:()=>{y(null),v(null)},style:{marginTop:14,padding:"8px 18px",fontSize:13,fontWeight:600,background:"var(--accent)",color:"#fff",border:"none",borderRadius:6,cursor:"pointer"},children:"I've saved these codes"})]}),(e?.status==="enabled"||e?.status==="pending")&&!m&&(0,n.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:12},children:"Scope"}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:14},children:[(0,n.jsx)(nu,{label:"Require on all networks",description:"TOTP code is always required during login, even from localhost or LAN.",checked:"always"===k,onChange:()=>L("always")}),(0,n.jsx)(nu,{label:"Skip on trusted networks",description:"TOTP code is only required when signing in from outside localhost or LAN.",checked:"untrusted"===k,onChange:()=>L("untrusted")})]}),"untrusted"===k&&(0,n.jsxs)("div",{style:{padding:"10px 12px",background:"var(--bg)",borderRadius:8,border:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",marginBottom:8,lineHeight:1.5},children:"Trusted CIDR blocks (TOTP will be skipped for requests from these IP ranges):"}),(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:S.map(e=>(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 8px",borderRadius:999,background:"var(--bg-panel)",border:"1px solid var(--border)",fontSize:11,fontFamily:"var(--font-mono), monospace",color:"var(--text)"},children:[e,(0,n.jsx)("button",{type:"button",onClick:()=>$(e),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-dim)",fontSize:13,lineHeight:1,padding:0},title:"Remove",children:"\xd7"})]},e))}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{type:"text",value:T,onChange:e=>z(e.target.value),onKeyDown:e=>{"Enter"===e.key&&E()},placeholder:"e.g. 192.168.1.0/24",style:{flex:1,padding:"6px 10px",fontSize:12,fontFamily:"var(--font-mono), monospace",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:E,style:{padding:"6px 12px",fontSize:12,fontWeight:600,background:T.trim()?"var(--accent)":"var(--bg-hover)",color:T.trim()?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:T.trim()?"pointer":"not-allowed"},children:"Add"})]})]})]}),e?.status==="enabled"&&!m&&(0,n.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Disable two-factor authentication"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:12,lineHeight:1.5},children:"Enter your current authenticator code to disable 2FA. This will make your account less secure."}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:u,onChange:e=>h(e.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000 000",style:{flex:1,padding:"8px 12px",fontSize:16,fontFamily:"var(--font-mono), monospace",letterSpacing:"0.12em",textAlign:"center",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,n.jsx)("button",{type:"button",disabled:b||6!==u.length,onClick:M,style:{padding:"8px 16px",fontSize:13,fontWeight:600,background:6===u.length?"rgba(239,68,68,0.85)":"var(--bg-hover)",color:6===u.length?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:6===u.length?"pointer":"not-allowed"},children:b?"…":"Disable 2FA"})]})]}),e?.status==="disabled"&&(0,n.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"When enabled, you'll need to enter a 6-digit code from your authenticator app (Google Authenticator, Authy, 1Password, etc.) each time you sign in from a new browser or after your session expires."}),(0,n.jsx)("button",{type:"button",disabled:b,onClick:M,style:{marginTop:14,padding:"8px 18px",fontSize:13,fontWeight:600,background:"var(--accent)",color:"#fff",border:"none",borderRadius:6,cursor:"pointer",opacity:b?.6:1},children:b?"Setting up…":"Set up authenticator"})]})]})})}function nx({checked:e,onChange:t}){return(0,n.jsx)("button",{type:"button",onClick:t,"aria-pressed":e,style:{width:44,height:24,borderRadius:999,border:"none",padding:0,cursor:"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",flexShrink:0},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:e?23:3,width:18,height:18,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function ng(){return(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.51a2 2 0 0 1 1-1.72l.15-.1a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function nf(e){return"projects"===e?(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}):"models"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"})]}):"skills"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,n.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,n.jsx)("path",{d:"M2 12l10 5 10-5"})]}):"authenticator"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}),(0,n.jsx)("circle",{cx:"12",cy:"16",r:"1"})]}):"generative-ui"===e?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("path",{d:"M16 17h5"}),(0,n.jsx)("path",{d:"M18.5 14.5v5"})]}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 3v18h18"}),(0,n.jsx)("path",{d:"m19 9-5 5-4-4-3 3"}),(0,n.jsx)("path",{d:"M14 9h5v5"})]})}function nv({cwd:e,generativeUI:t,initialTab:r="projects",onGenerativeUIToggle:o,onClose:l,onModelsChanged:s,onProjectSelect:a,onProjectsChanged:d}){let[c,p]=(0,i.useState)(r);(0,i.useEffect)(()=>{p(r)},[r]),(0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&l()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l]);let u=[{id:"projects",label:"Project",description:e?"Overview and paths":"Add or select a project",icon:nf("projects")},{id:"models",label:"Models",description:"~/.pi/agent/models.json",icon:nf("models")},{id:"authenticator",label:"Authenticator",description:"Two-factor authentication",icon:nf("authenticator")},{id:"skills",label:"Skills",description:e?"Project and global skills":"Select a project first",disabled:!e,icon:nf("skills")},{id:"generative-ui",label:"Generative UI",description:t?"Enabled":"Disabled",icon:nf("generative-ui")},{id:"workbench-runtime",label:"Kernels",description:e?"Project R / Python kernels":"Global R / Python kernels",icon:nf("workbench-runtime")}],h=u.find(e=>e.id===c)??u[0];return(0,n.jsx)("div",{className:"settings-dialog-backdrop",onClick:e=>{e.target===e.currentTarget&&l()},children:(0,n.jsxs)("div",{className:"settings-dialog-shell",children:[(0,n.jsxs)("div",{className:"settings-dialog-header",children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:9,minWidth:0},children:[(0,n.jsx)("span",{style:{color:"var(--text-muted)",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,n.jsx)(ng,{})}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:15,fontWeight:700,color:"var(--text)",lineHeight:1.25},children:"Settings"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.label})]})]}),(0,n.jsx)("button",{type:"button",onClick:l,title:"Close settings","aria-label":"Close settings",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsxs)("div",{className:"settings-dialog-body",children:[(0,n.jsx)("div",{className:"settings-dialog-tabs",children:u.map(e=>{let t=c===e.id;return(0,n.jsxs)("button",{type:"button",disabled:e.disabled,onClick:()=>p(e.id),className:"settings-dialog-tab",style:{background:t?"var(--bg-selected)":"transparent",color:t?"var(--text)":"var(--text-muted)",opacity:e.disabled?.45:1,cursor:e.disabled?"not-allowed":"pointer"},onMouseEnter:r=>{t||e.disabled||(r.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{style:{flexShrink:0,color:t?"var(--accent)":"currentColor",display:"flex"},children:e.icon}),(0,n.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("span",{style:{display:"block",fontSize:12,fontWeight:t?700:600,lineHeight:1.25},children:e.label}),(0,n.jsx)("span",{style:{display:"block",marginTop:2,fontSize:10,color:"var(--text-dim)",lineHeight:1.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.description})]})]},e.id)})}),(0,n.jsxs)("div",{className:"settings-dialog-panel",children:["projects"===c&&(0,n.jsx)(na,{activeCwd:e,onSelectProject:a,onProjectsChanged:d}),"models"===c&&(0,n.jsx)(rN,{embedded:!0,onClose:()=>{s?.(),l()}}),"authenticator"===c&&(0,n.jsx)(nh,{}),"skills"===c&&e&&(0,n.jsx)(rK,{cwd:e,embedded:!0,onClose:l}),"generative-ui"===c&&(0,n.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,n.jsxs)("div",{style:{maxWidth:720,display:"flex",flexDirection:"column",gap:18},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:18,padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",lineHeight:1.35},children:"Generative UI"}),(0,n.jsx)("div",{style:{marginTop:5,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Render structured widgets and safe visual code blocks directly in chat when the assistant produces UI content."})]}),(0,n.jsx)(nx,{checked:t,onChange:o})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,n.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"When enabled"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"The agent prompt favors compact visual artifacts for icons, forms, dashboards, and small interactive UI when useful."})]}),(0,n.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"Fallback rendering"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"Assistant SVG and safe HTML code blocks can be previewed instead of appearing only as source text."})]})]})]})}),"workbench-runtime"===c&&(0,n.jsx)(r0,{cwd:e})]})]})]})})}function nm(e){return e?e.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function ny(e){return!Number.isFinite(e)||e<=0?"0.0G":`${(e/1024/1024/1024).toFixed(1)}G`}let nb={height:32,padding:"0 12px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12};function nj({cwd:e,runtime:t,runtimeError:r,busy:o=!1,onClose:l,onLaunch:s,onReleaseCurrentRuntime:a,onOpenSettings:d}){let[c,p]=(0,i.useState)("r"),[u,h]=(0,i.useState)(!1),[x,g]=(0,i.useState)(null),[f,v]=(0,i.useState)([]),[m,y]=(0,i.useState)(!1),[b,j]=(0,i.useState)(null),[k,w]=(0,i.useState)(""),[S,C]=(0,i.useState)(""),[T,z]=(0,i.useState)(!1),[I,M]=(0,i.useState)([]),[R,W]=(0,i.useState)(""),[L,E]=(0,i.useState)(!1),[$,P]=(0,i.useState)(null);(0,i.useEffect)(()=>{w(""),C(""),p("r"),g(null),z(!1),h(!1)},[e]),(0,i.useEffect)(()=>{if(!e){v([]),g(null);return}let t=!1;return y(!0),j(null),fetch(`/api/plot-kernels?cwd=${encodeURIComponent(e)}`).then(async e=>{let r=await e.json().catch(()=>({}));if(!e.ok||r.error||!Array.isArray(r.kernels))throw Error(r.error??`HTTP ${e.status}`);t||v(r.kernels)}).catch(e=>{t||(v([]),j(e instanceof Error?e.message:String(e)))}).finally(()=>{t||y(!1)}),()=>{t=!0}},[e]);let D=(0,i.useMemo)(()=>f.filter(e=>e.language===c),[c,f]),A=(0,i.useMemo)(()=>D.find(e=>e.id===x)??D.find(e=>e.isEffective)??D[0]??null,[x,D]);(0,i.useEffect)(()=>{g(e=>e&&D.some(t=>t.id===e)?e:A?.id??null)},[c,f,D,A?.id]);let B=(0,i.useCallback)(async e=>{if(e){E(!0),P(null);try{let t=e.split("/").filter(Boolean).map(encodeURIComponent).join("/"),r=await fetch(`/api/files/${t}?type=list`);if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`HTTP ${r.status}`)}let n=await r.json();M(n.entries),W(n.path)}catch(e){P(e instanceof Error?e.message:String(e)),M([])}finally{E(!1)}}},[]),N=(0,i.useCallback)(()=>{e&&(z(!0),B(e))},[e,B]),O=(0,i.useCallback)(e=>{B(R?`${R.replace(/\/+$/,"")}/${e}`:e)},[R,B]),H=(0,i.useCallback)(e=>{w(R?`${R.replace(/\/+$/,"")}/${e}`:e),z(!1)},[R]),F="r"===c?[".rds",".qs"]:"python"===c?[".h5ad"]:[];return(0,n.jsx)("div",{className:"settings-dialog-backdrop",onClick:e=>{e.target!==e.currentTarget||o||l()},children:(0,n.jsxs)("div",{style:{width:"min(720px, calc(100vw - 40px))",maxHeight:"min(760px, calc(100vh - 40px))",overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 24px 80px rgba(0,0,0,0.28)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16,padding:"18px 18px 14px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:18,fontWeight:700,color:"var(--text)"},children:"Workbench"}),(0,n.jsxs)("div",{style:{marginTop:6,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:["Starts a dedicated top-level Workbench session in the current project.",e?` Project: ${nm(e)}`:""]})]}),(0,n.jsx)("button",{type:"button",onClick:l,disabled:o,style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:20,lineHeight:1,opacity:o?.5:1},children:"x"})]}),(0,n.jsxs)("div",{style:{padding:18,display:"grid",gap:18},children:[(0,n.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Kernel"}),(0,n.jsx)("div",{style:{display:"flex",gap:8},children:[{id:"r",label:"R",desc:"Seurat, rds, qs, Bioconductor workflows"},{id:"python",label:"Python",desc:"AnnData, h5ad, pandas, scanpy workflows"}].map(e=>{let t=c===e.id;return(0,n.jsxs)("button",{type:"button",onClick:()=>p(e.id),style:{flex:1,textAlign:"left",padding:"12px 13px",borderRadius:10,border:`1px solid ${t?"rgba(37,99,235,0.45)":"var(--border)"}`,background:t?"var(--bg-selected)":"var(--bg-panel)",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer"},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700},children:e.label}),(0,n.jsx)("div",{style:{marginTop:4,fontSize:11,lineHeight:1.5},children:e.desc})]},e.id)})})]}),(0,n.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Mode"}),(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 13px",borderRadius:10,border:`1px solid ${u?"rgba(37,99,235,0.45)":"var(--border)"}`,background:u?"var(--bg-selected)":"var(--bg-panel)",cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:u,onChange:e=>h(e.target.checked),style:{accentColor:"var(--accent)"}}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:u?"var(--text)":"var(--text-muted)"},children:"I describe, you code"}),(0,n.jsx)("div",{style:{marginTop:2,fontSize:11,color:"var(--text-dim)",lineHeight:1.45},children:"Describe the analysis in domain terms. The agent will plan the approach, suggest methods, and write the code."})]})]})]}),(0,n.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Kernel runtime"}),(0,n.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["Specific ","r"===c?"R":"Python"," kernel"]}),(0,n.jsx)("select",{value:A?.id??"",onChange:e=>g(e.target.value||null),disabled:o||m||0===D.length,style:{height:34,padding:"0 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",fontSize:12},children:0===D.length?(0,n.jsx)("option",{value:"",children:m?"Loading kernels...":"No configured kernel"}):D.map(e=>(0,n.jsxs)("option",{value:e.id,children:[e.displayName,e.isEffective?" \xb7 current":""," — ",e.command," ",(e.args??[]).join(" ")]},e.id))}),b&&(0,n.jsx)("span",{style:{fontSize:11,color:"#f87171"},children:b}),(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.45},children:"Launching will select this kernel for the current project before starting the Workbench session."})]})]}),(0,n.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Sources"}),(0,n.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"Primary object or dataset path"}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{value:k,onChange:e=>w(e.target.value),placeholder:"r"===c?"e.g. ./data/sample.rds or ./objects/integrated.qs":"e.g. ./data/sample.h5ad",style:{flex:1,height:34,padding:"0 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"}}),(0,n.jsx)("button",{type:"button",onClick:N,disabled:!e||o,title:"Browse project files",style:{...nb,whiteSpace:"nowrap",opacity:!e||o?.5:1,cursor:!e||o?"not-allowed":"pointer"},children:T?"Collapse":"Browse"})]})]}),T&&e&&(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",maxHeight:260,overflow:"auto",fontSize:12},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"6px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>{z(!1)},style:{border:"none",background:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,padding:0},children:"✕"}),(0,n.jsx)("span",{style:{color:"var(--text-dim)"},children:"|"}),R?(()=>{let e=R.replace(/^\/+/,"").split("/"),t=[];for(let r=0;r<e.length;r++){let n="/"+e.slice(0,r+1).join("/");t.push({label:0===r?nm(n):e[r],dir:n})}return t.map((t,r)=>(0,n.jsxs)("span",{children:[r>0&&(0,n.jsx)("span",{style:{margin:"0 2px",color:"var(--text-dim)"},children:"/"}),(0,n.jsx)("button",{type:"button",onClick:()=>B(t.dir),style:{border:"none",background:"none",color:r===e.length-1?"var(--text)":"var(--text-muted)",cursor:r===e.length-1?"default":"pointer",fontSize:11,padding:"2px 1px",fontWeight:r===e.length-1?600:400},children:t.label})]},t.dir))})():(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:"Loading..."})]}),L?(0,n.jsx)("div",{style:{padding:"16px 10px",color:"var(--text-dim)",textAlign:"center"},children:"Loading..."}):$?(0,n.jsx)("div",{style:{padding:"16px 10px",color:"#f87171",textAlign:"center"},children:$}):0===I.length?(0,n.jsx)("div",{style:{padding:"16px 10px",color:"var(--text-dim)",textAlign:"center"},children:"empty directory"}):(0,n.jsxs)("div",{children:[R!==e&&(0,n.jsxs)("div",{onClick:()=>{B(R.replace(/\/+$/,"").split("/").slice(0,-1).join("/")||"/")},style:{display:"flex",alignItems:"center",gap:6,padding:"5px 10px",cursor:"pointer",color:"var(--text-muted)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M10 3L5 8l5 5",stroke:"var(--text-dim)",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,n.jsx)("span",{style:{fontSize:11},children:".."})]}),I.map(e=>{let t,r=!e.isDir&&(t=e.name.toLowerCase(),F.some(e=>t.endsWith(e)));return(0,n.jsxs)("div",{onClick:()=>{e.isDir?O(e.name):H(e.name)},style:{display:"flex",alignItems:"center",gap:6,padding:"5px 10px",cursor:(e.isDir,"pointer"),color:e.isDir?"var(--text)":r?"var(--accent)":"var(--text-muted)",fontWeight:r?600:400},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.isDir?(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5H14a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4.5Z",stroke:"var(--text-dim)",strokeWidth:"1",fill:"var(--text-dim)",fillOpacity:"0.1"})}):(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("path",{d:"M3 2h7l3 3v9H3V2Z",stroke:r?"var(--accent)":"var(--text-dim)",strokeWidth:"1",fill:r?"var(--accent)":"var(--text-dim)",fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:r?"var(--accent)":"var(--text-dim)",strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]}),(0,n.jsx)("span",{style:{fontSize:12},children:e.name}),r&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",background:"rgba(37,99,235,0.1)",padding:"0 5px",borderRadius:3,lineHeight:"16px"},children:e.name.split(".").pop()})]},e.name)})]})]}),(0,n.jsxs)("label",{style:{display:"grid",gap:6,marginTop:4},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"Notes or extra file hints"}),(0,n.jsx)("textarea",{value:S,onChange:e=>C(e.target.value),placeholder:"Optional: metadata table paths, desired comparison, object name hints, or initialization notes.",rows:5,style:{width:"100%",resize:"vertical",minHeight:96,padding:"10px",borderRadius:8,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",fontSize:12,lineHeight:1.55}})]})]}),(0,n.jsxs)("section",{style:{display:"grid",gap:10,padding:14,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Runtime"}),(0,n.jsxs)("div",{style:{display:"flex",gap:16,flexWrap:"wrap",fontSize:12,color:"var(--text-muted)"},children:[(0,n.jsxs)("span",{children:["Total memory ",ny(t.totalBytes)]}),(0,n.jsxs)("span",{children:["Current session ",ny(t.currentSessionBytes)]}),(0,n.jsxs)("span",{children:["Idle timeout ",t.idleTimeoutLabel]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[a&&(0,n.jsx)("button",{type:"button",onClick:a,style:nb,children:"Release current chat"}),d&&(0,n.jsx)("button",{type:"button",onClick:d,style:nb,children:"Runtime settings"})]}),r&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171",lineHeight:1.5},children:r})]})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"0 18px 18px"},children:[(0,n.jsx)("button",{type:"button",onClick:l,disabled:o,style:nb,children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>void s({kernel:c,kernelId:A?.id??null,kernelDisplayName:A?.displayName??null,sourcePath:k.trim(),notes:S.trim(),isDescribeMode:u}),disabled:o||!e||0===D.length,style:{...nb,border:"1px solid rgba(37,99,235,0.45)",background:"rgba(37,99,235,0.12)",color:"var(--accent)",opacity:o||!e?.55:1,cursor:o||!e?"not-allowed":"pointer"},children:o?"Launching...":"Launch Workbench"})]})]})})}function nk(e){return e&&Number.isFinite(e)&&!(e<=0)?e<1048576?`${(e/1024).toFixed(0)}K`:e<0x40000000?`${(e/1024/1024).toFixed(1)}M`:`${(e/1024/1024/1024).toFixed(1)}G`:"0.0G"}function nw(e){return[...e].sort((e,t)=>t.totalBytes-e.totalBytes||e.id.localeCompare(t.id))}function nS(e){let t=new Map;for(let r of e){let e=r.sessionId?`session:${r.sessionId}`:`process:${r.pid}`;t.set(e,[...t.get(e)??[],r])}return[...t.entries()].map(([e,t])=>({id:e,kind:t[0]?.sessionId?"session":"process",sessionId:t[0]?.sessionId??null,cwd:t[0]?.cwd??null,kernels:t,totalBytes:t.reduce((e,t)=>e+t.rssBytes,0),lastActivity:function(e){let t=0;for(let r of e){if(!r.lastActivity)continue;let e=new Date(r.lastActivity).getTime();Number.isFinite(e)&&(t=Math.max(t,e))}return t>0?new Date(t).toISOString():null}(t)}))}let nC={height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},nT={...nC,color:"#ef4444",border:"1px solid rgba(239,68,68,0.35)",background:"rgba(239,68,68,0.08)"};function nz({open:e,anchorRef:t,status:r,error:o,currentSessionId:l,currentCwd:s,idleTimeoutLabel:a,busyPid:d,onClose:c,onRefresh:p,onReleaseKernels:u,onOpenSettings:h,onOpenStatus:x}){let g=function(){let[e,t]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let e=window.matchMedia("(max-width: 640px)"),r=()=>t(e.matches);return r(),e.addEventListener?.("change",r),()=>e.removeEventListener?.("change",r)},[]),e}(),f=function(e,t,r){let[n,o]=(0,i.useState)({top:56,left:12});return(0,i.useEffect)(()=>{if(!t||r)return;let n=()=>{let t=e.current?.getBoundingClientRect();if(!t)return;let r=Math.min(620,window.innerWidth-24),n=Math.max(12,Math.min(t.right-r,window.innerWidth-r-12));o({top:Math.min(t.bottom+8,window.innerHeight-120),left:n})};return n(),window.addEventListener("resize",n),window.addEventListener("scroll",n,!0),()=>{window.removeEventListener("resize",n),window.removeEventListener("scroll",n,!0)}},[e,r,t]),n}(t,e,g),v=(0,i.useMemo)(()=>r?.kernels??[],[r?.kernels]),m=(0,i.useMemo)(()=>nS(v),[v]),y=(0,i.useMemo)(()=>(function(e,t,r){let n=[],i=[],o=[],l=[];for(let a of nS(e))if(t&&a.sessionId===t)n.push(a);else if("process"===a.kind)l.push(a);else{var s;r&&(s=a.cwd,s&&r&&s.replace(/\/+$/,"")===r.replace(/\/+$/,""))?i.push(a):o.push(a)}return[{id:"current",title:"Current session",subtitle:`${nk(n.reduce((e,t)=>e+t.totalBytes,0))} retained`,groups:nw(n)},{id:"project",title:"Other sessions in this project",subtitle:`${i.length} session${1===i.length?"":"s"}`,groups:nw(i)},{id:"other",title:"Other projects",subtitle:`${nk(o.reduce((e,t)=>e+t.totalBytes,0))}`,groups:nw(o)},{id:"untracked",title:"Unattributed",subtitle:`${l.length} process${1===l.length?"":"es"}`,groups:nw(l)}].filter(e=>e.groups.length>0)})(v,l,s),[s,l,v]),b=r?.totalBytes??0,j=r?.currentSessionBytes??0;if((0,i.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&c()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[c,e]),!e)return null;let k=g?{position:"fixed",left:0,right:0,bottom:0,maxHeight:"82dvh",borderRadius:"12px 12px 0 0"}:{position:"fixed",top:f.top,left:f.left,width:"min(620px, calc(100vw - 24px))",maxHeight:"min(680px, calc(100vh - 72px))",borderRadius:10};return(0,n.jsx)("div",{onMouseDown:c,style:{position:"fixed",inset:0,zIndex:900,background:g?"rgba(0,0,0,0.34)":"transparent"},children:(0,n.jsxs)("div",{onMouseDown:e=>e.stopPropagation(),role:"dialog","aria-modal":g?"true":"false","aria-label":"Workbench runtime",style:{...k,overflow:"hidden",border:"1px solid var(--border)",background:"var(--bg)",boxShadow:"0 18px 60px rgba(0,0,0,0.26)",display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--text)"},children:"Workbench Runtime"}),(0,n.jsxs)("span",{style:{fontSize:11,color:j>0?"var(--accent)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums"},children:[nk(j)," current / ",nk(b)," total"]})]}),(0,n.jsxs)("div",{style:{marginTop:4,display:"flex",gap:10,flexWrap:"wrap",fontSize:11,color:"var(--text-dim)"},children:[(0,n.jsxs)("span",{children:[m.length," session",1===m.length?"":"s"]}),(0,n.jsxs)("span",{children:[v.length," kernel",1===v.length?"":"s"]}),(0,n.jsxs)("span",{children:["idle timeout ",a]}),r?.generatedAt&&(0,n.jsxs)("span",{children:["updated ",new Date(r.generatedAt).toLocaleTimeString()]})]})]}),(0,n.jsx)("button",{type:"button",onClick:c,title:"Close","aria-label":"Close",style:{...nC,width:28,padding:0,fontSize:18,lineHeight:1},children:"x"})]}),(0,n.jsxs)("div",{style:{marginTop:10,display:"flex",gap:7,flexWrap:"wrap"},children:[(0,n.jsx)("button",{type:"button",onClick:p,style:nC,children:"Refresh"}),x&&(0,n.jsx)("button",{type:"button",onClick:x,style:nC,children:"Open Status"}),(0,n.jsx)("button",{type:"button",onClick:h,style:nC,children:"Runtime Settings"})]}),o&&(0,n.jsx)("div",{style:{marginTop:9,border:"1px solid rgba(248,113,113,0.25)",borderRadius:7,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11,lineHeight:1.45,padding:"7px 8px"},children:o})]}),(0,n.jsx)("div",{style:{overflow:"auto",padding:10},children:0===y.length?(0,n.jsx)("div",{style:{padding:"28px 12px",textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No active Workbench runtime."}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:y.map(e=>(0,n.jsxs)("section",{children:[(0,n.jsxs)("div",{style:{marginBottom:7,display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:750,color:"var(--text)"},children:e.title}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums"},children:e.subtitle})]}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:e.groups.map(e=>{var t;let r=!!l&&e.sessionId===l,i=e.kernels.some(e=>d===e.pid),o=e.kernels.map(e=>e.pid).join(", ");return(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:g?"1fr":"minmax(0, 1fr) auto",gap:g?9:12,alignItems:"center",border:`1px solid ${r?"rgba(37,99,235,0.42)":"var(--border)"}`,borderRadius:8,background:r?"var(--bg-selected)":"var(--bg-panel)",padding:10},children:[(0,n.jsxs)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("span",{style:{minWidth:42,height:28,padding:"0 7px",display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:6,border:"1px solid rgba(37,99,235,0.28)",background:"rgba(37,99,235,0.08)",color:"var(--accent)",fontSize:11,fontWeight:800,fontFamily:"var(--font-mono)",flexShrink:0},children:[...new Set(e.kernels.map(e=>"r"===e.language?"R":"Python"))].join(" + ")}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:760,color:r?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums",flexShrink:0},children:nk(e.totalBytes)}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.sessionId??void 0,children:r?"Current session":"session"===e.kind?`Session ${(t=e.sessionId)?t.slice(0,8):"untracked"}`:"Unattributed kernel"})]}),(0,n.jsxs)("div",{style:{marginTop:4,display:"flex",alignItems:"center",gap:8,minWidth:0,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.cwd??void 0,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e){if(!e)return"Unknown project";let t=e.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean);return t[t.length-1]||e}(e.cwd)}),(0,n.jsxs)("span",{title:`pid ${o}`,style:{flexShrink:0},children:["pid ",o]}),(0,n.jsx)("span",{style:{flexShrink:0},children:function(e){if(!e)return"activity unknown";let t=new Date(e).getTime();if(!Number.isFinite(t))return"activity unknown";let r=Math.floor(Math.max(0,Date.now()-t)/6e4);if(r<1)return"active now";if(r<60)return`${r}m idle`;let n=Math.floor(r/60);return n<24?`${n}h idle`:`${Math.floor(n/24)}d idle`}(e.lastActivity)})]}),(0,n.jsx)("div",{title:e.cwd??void 0,style:{marginTop:3,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e){if(!e)return"-";let t=e.replace(/\/+$/,"").replace(/^\/(?:Users|home)\/[^/]+/,"~");if(t.length<=44)return t;let r=t.split("/").filter(Boolean);return r.length<=2?t:`${t.startsWith("/")?"/":""}${r[0]}/.../${r[r.length-1]}`}(e.cwd)})]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>{window.confirm("Release this Workbench runtime?\n\nWarm variables and loaded data will be cleared. Saved files and chat history stay.")&&u(e.kernels)},disabled:i,title:"Release this Workbench runtime",style:{...nT,justifySelf:g?"stretch":"end",opacity:i?.55:1,cursor:i?"not-allowed":"pointer"},children:i?"Releasing...":"Release"})]},e.id)})})]},e.id))})})]})})}function nI({initialWidth:e,minWidth:t,maxWidth:r,storageKey:n,direction:o="right"}){let[l,s]=(0,i.useState)(e),[a,d]=(0,i.useState)(!1),c=(0,i.useRef)(e),p=(0,i.useCallback)(e=>{let i=Math.max(t,Math.min(r,e));s(i),c.current=i,document.documentElement.style.setProperty(n,`${i}px`)},[t,r,n]);(0,i.useEffect)(()=>{try{let e=localStorage.getItem(n);if(e){let n=parseInt(e,10);if(!isNaN(n)&&n>=t&&n<=r)return void p(n)}}catch{}p(c.current)},[n,t,r,p]);let u=(0,i.useCallback)(()=>{d(!0)},[]),h=(0,i.useCallback)(e=>{let t="left"===o?-1:1;p(c.current+e*t)},[p,o]);return{beginResize:u,endResize:(0,i.useCallback)(()=>{d(!1);try{localStorage.setItem(n,String(c.current))}catch{}},[n]),isResizing:a,resizeBy:h,width:l,widthRef:c}}function nM(e,t){return e.length<=t?e:`${e.slice(0,t)}
45
- ...`}function nR(e){return[`Explain this Workbench artifact: ${e.path}`,`Generated by cell #${e.provenance.cellIndex}: ${e.provenance.title}`,`Status: ${e.provenance.status}`,`Runtime: ${e.provenance.runtime??"unknown"}; language: ${e.provenance.language}`,"","Code:","```",nM(e.provenance.code,4e3),"```",e.provenance.stdoutPreview?`
46
- Stdout excerpt:
47
- \`\`\`
48
- ${nM(e.provenance.stdoutPreview,1500)}
49
- \`\`\``:"",e.provenance.stderrPreview?`
50
- Stderr excerpt:
51
- \`\`\`
52
- ${nM(e.provenance.stderrPreview,1500)}
53
- \`\`\``:""].filter(Boolean).join("\n")}function nW(e){return[`Revise this Workbench artifact: ${e.path}`,`It was generated by cell #${e.provenance.cellIndex}: ${e.provenance.title}.`,"Edit the generating code or create a new follow-up cell, save a new artifact instead of silently overwriting the original, and briefly explain what changed.","Requested change:","","Original code:","```",nM(e.provenance.code,4e3),"```",e.provenance.stdoutPreview?`
54
- Stdout excerpt:
55
- \`\`\`
56
- ${nM(e.provenance.stdoutPreview,1500)}
57
- \`\`\``:"",e.provenance.stderrPreview?`
58
- Stderr excerpt:
59
- \`\`\`
60
- ${nM(e.provenance.stderrPreview,1500)}
61
- \`\`\``:""].filter(Boolean).join("\n")}let nL=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function nE(e){return!Number.isFinite(e)||e<=0?"0.0G":`${(e/1024/1024/1024).toFixed(1)}G`}function n$(e){if(e<=0)return"never";let t=e/60/60/1e3;return t>=24&&Number.isInteger(t/24)?`${t/24}d`:Number.isInteger(t)?`${t}h`:`${Math.round(e/60/1e3)}m`}function nP(e){let t=e.toLowerCase();return t.endsWith(".rds")||t.endsWith(".qs")}function nD(e){return e.toLowerCase().endsWith(".h5ad")}function nA(e){let t=(e.split(/[\\/]/).pop()??e).toLowerCase().split(".").pop()??"";return nL.has(t)}function nB(){let e=(0,o.useRouter)(),t=(0,o.useSearchParams)(),{isDark:r,toggleTheme:l}=(0,tT.D)(),s=function(){let[e,t]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let e=()=>t(window.innerWidth<=768);return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),e}(),[a,d]=(0,i.useState)(null),[c,p]=(0,i.useState)(null),[u,h]=(0,i.useState)(0),[x,g]=(0,i.useState)(0),[f,v]=(0,i.useState)(0),[m,y]=(0,i.useState)(0),[j,k]=(0,i.useState)(!1),[w,S]=(0,i.useState)("projects"),[C,T]=(0,i.useState)({generativeUI:!0,plotIdleTimeoutMs:1728e5}),[z,I]=(0,i.useState)(!0),M=nI({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--pi-sidebar-width"}),R=nI({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--pi-right-panel-width",direction:"left"}),W=(0,i.useRef)(null),L=(0,i.useRef)(null),E=(0,i.useRef)(null),[$,P]=(0,i.useState)([]),[A,B]=(0,i.useState)(null),N=(0,i.useRef)(null),O=(0,i.useCallback)((e,t,r)=>{P(e),B(t),N.current=r},[]),H=(0,i.useCallback)(e=>{N.current?.(e)},[]),[F,_]=(0,i.useState)(!1),[U,K]=(0,i.useState)(""),J=(0,i.useRef)(null),V=(0,i.useRef)(!1);(0,i.useEffect)(()=>{_(!1)},[a?.id]);let q=(0,i.useCallback)(e=>e?e.name||e.firstMessage.slice(0,80)||e.id.slice(0,12):"",[]),Y=(0,i.useCallback)(()=>{a&&(V.current=!1,K(a.name||q(a)),_(!0),setTimeout(()=>J.current?.select(),0))},[q,a]),G=(0,i.useCallback)(async()=>{if(V.current){V.current=!1,_(!1);return}if(!a)return void _(!1);let e=U.trim(),t=q(a);if(_(!1),e!==(a.name??"")&&(a.name||e!==t))try{(await fetch(`/api/sessions/${encodeURIComponent(a.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})})).ok&&(d(t=>t&&t.id===a.id?{...t,name:e}:t),h(e=>e+1))}catch{}},[q,a,U]),Z=(0,i.useCallback)(e=>{"Enter"===e.key?(e.preventDefault(),G()):"Escape"===e.key&&(V.current=!0,_(!1))},[G]);(0,i.useEffect)(()=>{let e=!1;return fetch("/api/settings").then(e=>e.ok?e.json():null).then(t=>{e||T(e=>({generativeUI:"boolean"==typeof t?.settings?.generativeUI?t.settings.generativeUI:e.generativeUI,plotIdleTimeoutMs:"number"==typeof t?.settings?.plotIdleTimeoutMs?t.settings.plotIdleTimeoutMs:e.plotIdleTimeoutMs}))}).catch(()=>{}),()=>{e=!0}},[]);let X=(0,i.useCallback)(()=>{let e=!C.generativeUI;T(t=>({...t,generativeUI:e})),fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{generativeUI:e}})}).then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(e=>{T(t=>({...t,..."boolean"==typeof e.settings?.generativeUI?{generativeUI:e.settings.generativeUI}:{},..."number"==typeof e.settings?.plotIdleTimeoutMs?{plotIdleTimeoutMs:e.settings.plotIdleTimeoutMs}:{}}))}).catch(()=>T(e=>({...e,generativeUI:!e.generativeUI})))},[C.generativeUI]),[Q,ee]=(0,i.useState)(null),et=(0,i.useCallback)(e=>{ee(e)},[]),[er,en]=(0,i.useState)(null),ei=(0,i.useCallback)(e=>{en(e)},[]),[eo,el]=(0,i.useState)(!1),[es,ea]=(0,i.useState)(!1),[ed,ec]=(0,i.useState)(null),[ep,eu]=(0,i.useState)(!1),[eh,ex]=(0,i.useState)(!1),[eg,ef]=(0,i.useState)(null);(0,i.useEffect)(()=>{let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&ef(t)}).catch(()=>{}),()=>{e=!0}},[]);let ev=eg?.updateAvailable&&eg.latest?{label:`Update ${eg.latest}`,title:`Current: v${eg.current}
62
- Latest: v${eg.latest}
63
- Run: ${eg.updateCommand}`}:null,[em,ey]=(0,i.useState)([]),[eb,ej]=(0,i.useState)("files"),[ek,ew]=(0,i.useState)(!1),[eS,eC]=(0,i.useState)(null),[eT,ez]=(0,i.useState)(0),[eI,eM]=(0,i.useState)([]),eR=(0,i.useCallback)(e=>{W.current?.insertText("`"+e+"`")},[]),[eW]=(0,i.useState)(()=>t.get("session")),[eL,eE]=(0,i.useState)(null),[e$,eP]=(0,i.useState)(()=>!t.get("session")),eD=(0,i.useRef)(!1),eA=(0,i.useCallback)(t=>{eE(t),eC(null),el(!1),ec(null),t&&!eD.current&&(d(e=>e&&e.cwd!==t?null:e),p(e=>e&&e!==t?null:e),g(e=>e+1),v(e=>e+1),P([]),B(null),e.replace("/",{scroll:!1}))},[e]),eB=(0,i.useCallback)((e,t)=>{eA(e),t?.closeDialog!==!1&&k(!1),h(e=>e+1)},[eA]),eN=(0,i.useCallback)((t,r=!1)=>{p(null),eE(t.cwd),d(t),el(!1),ec(null),g(e=>e+1),eP(!0),r&&(eD.current=!0,setTimeout(()=>{eD.current=!1},0)),r||e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1})},[e]),eO=(0,i.useCallback)((t,r)=>{d(null),p(r),eE(r),el(!1),ec(null),g(e=>e+1),P([]),B(null),e.replace("/",{scroll:!1})},[e]),eH=(0,i.useCallback)(t=>{p(null),eE(t.cwd),d(t),el(!1),ec(null),h(e=>e+1),e.replace(`?session=${encodeURIComponent(t.id)}`,{scroll:!1}),window.dispatchEvent(new CustomEvent("session-created"))},[e]),eF=(0,i.useCallback)(()=>{h(e=>e+1),v(e=>e+1)},[]),e_=(0,i.useCallback)(t=>{h(e=>e+1),g(e=>e+1),p(null),d(e=>({...e??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:t})),e.replace(`?session=${encodeURIComponent(t)}`,{scroll:!1})},[e]),eU=(0,i.useCallback)(()=>{eP(!0)},[]),eV=(0,i.useCallback)(t=>{if(h(e=>e+1),a?.id===t){let t=a.cwd;d(null),p(t??null),el(!1),ec(null),g(e=>e+1),P([]),B(null),e.replace("/",{scroll:!1})}},[a,e]),eY=a?.cwd??c??eL??null,[eZ,eX]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(null!==eZ){let e=setTimeout(()=>eX(null),500);return()=>clearTimeout(e)}},[eZ]);let eQ=(0,i.useCallback)((e,t)=>{if(nP(e)||nP(t))return void eC({mode:"start",appType:"stexp",filePath:e,cwd:eY,appId:null});if(nA(e)||nA(t)){let r=`preview:${e}`;eM(n=>{let i=n.find(e=>e.id===r),o=n.filter(e=>e.id!==r);return o.push(i?{...i,filePath:e,fileName:t}:{id:r,filePath:e,fileName:t}),o});return}let r=`file:${e}`;ey(n=>n.find(e=>e.id===r)?n:[...n,{id:r,label:t,filePath:e}]),ej(r),ew(!0)},[eY]),e0=(0,i.useCallback)((e,t,r)=>{r&&r>0&&eX(r),eQ(e,t)},[eQ]),e1=(0,i.useCallback)((e,t)=>{(nD(e)||nD(t))&&eC({mode:"start",appType:"h5adexp",filePath:e,cwd:eY,appId:null})},[eY]),e2=(0,i.useCallback)(e=>{ec(e),el(!0)},[]),e5=(0,i.useCallback)(()=>{el(!1),ec(null)},[]),e4=(0,i.useCallback)(()=>{ej("tools"),ew(!0),ez(e=>e+1)},[]),e3=(0,i.useCallback)(e=>{eC({mode:"existing",appType:e.appType,filePath:e.filePath,cwd:e.cwd,appId:e.id}),ez(e=>e+1)},[]),e8=(0,i.useCallback)(e=>{ez(e=>e+1),eC(t=>t&&(t.appId===e.id||t.appType===e.appType&&t.filePath===e.filePath&&t.cwd===e.cwd)?"stopped"===e.status||"error"===e.status?null:{mode:"existing",appType:e.appType,filePath:e.filePath,cwd:e.cwd,appId:e.id}:t)},[]),e6=(0,i.useCallback)(e=>{eM(t=>t.filter(t=>t.id!==e))},[]),e7=(0,i.useCallback)(e=>{eM(t=>{let r=t.findIndex(t=>t.id===e);if(r<0||r===t.length-1)return t;let n=[...t],[i]=n.splice(r,1);return n.push(i),n})},[]),e9=(0,i.useCallback)(e=>{"files"!==e&&(ey(t=>t.filter(t=>t.id!==e)),ej(t=>{if(t!==e)return t;let r=em.filter(t=>t.id!==e);return r.length>0?r[r.length-1].id:"files"}))},[em]),te=c??(null===a&&eL?eL:null),tt=null!==a||null!==te,tr=e$&&!tt,tn=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"tools",label:"Status",closable:!1,icon:"tools"},...a?.sessionKind==="workbench"?[{id:"workbench",label:"Workbench",closable:!1,icon:"report"}]:[],...em],ti=em.find(e=>e.id===eb)??null,to=a?q(a):te?"New chat":"No session",tl=a?.cwd??te??eL??"",ts=tl?tl.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||tl:"",ta=a?.id??null,td=ed??eY,tc=(0,i.useCallback)((e="projects")=>{S(e),k(!0)},[]),[tp,tu]=(0,i.useState)(null),[th,tx]=(0,i.useState)(null),[tg,tf]=(0,i.useState)(null),tv=`${ta??""}|${eY??""}`,tm=tp?.totalBytes??0,ty=tp?.currentSessionBytes??0,tb=(0,i.useCallback)(async()=>{let e=new URLSearchParams;eY&&e.set("cwd",eY),ta&&e.set("sessionId",ta);try{let t=await fetch(`/api/plot-kernels/status${e.toString()?`?${e}`:""}`),r=await t.json();if(!t.ok||!("totalBytes"in r)||!("kernels"in r))throw Error(r.error??`HTTP ${t.status}`);tu(r),tx(null)}catch(e){tx(e instanceof Error?e.message:String(e))}},[ta,eY]);(0,i.useEffect)(()=>{let e=!1,t=async()=>{await tb(),e||(r=window.setTimeout(t,eo||es?3e3:8e3))},r=window.setTimeout(t,0);return()=>{e=!0,window.clearTimeout(r)}},[tb,tv,eo,es]);let tj=(0,i.useCallback)(async()=>{if(ta&&!tg){tf("all"),tx(null);try{let e=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:ta})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);window.setTimeout(()=>{tb()},600)}catch(e){tx(e instanceof Error?e.message:String(e))}finally{tf(null)}}},[tb,tg,ta]),tk=(0,i.useCallback)(async e=>{if(!tg&&0!==e.length){tf(e[0].pid),tx(null);try{for(let t of e){let e=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:t.pid,cwd:t.cwd,sessionId:t.sessionId,language:t.language})}),r=await e.json();if(!e.ok||r.error)throw Error(r.error??`HTTP ${e.status}`)}window.setTimeout(()=>{tb()},600)}catch(e){tx(e instanceof Error?e.message:String(e))}finally{tf(null)}}},[tb,tg]),tw=(0,i.useCallback)(()=>{ea(e=>!e),tb()},[tb]),tC=(0,i.useCallback)(()=>{ea(!1),e4()},[e4]),tz=(0,i.useCallback)(()=>{ea(!1),el(!1),ec(null),tc("workbench-runtime")},[tc]),tM=(0,i.useCallback)(async t=>{let r,n,i;if(!td||ep)return;eu(!0),tx(null);let o=new Date().toISOString(),l=`Workbench \xb7 ${"r"===t.kernel?"R":"Python"}`,s=(r=["Workbench session start.","",`Kernel: ${"r"===t.kernel?"R":"Python"}`],t.kernelId&&r.push(`Kernel ID: ${t.kernelId}${t.kernelDisplayName?` (${t.kernelDisplayName})`:""}`),t.sourcePath?r.push(`Primary source: ${t.sourcePath}`):r.push("Primary source: none selected"),t.notes&&(r.push("Notes:"),r.push(t.notes)),n=t.kernelId?`When calling \`kernel_plot_run\` or \`kernel_plot_render\`, pass kernelId: ${JSON.stringify(t.kernelId)}.`:"Use the current project/default Workbench kernel for tool calls.",i=t.sourcePath?'Initialize this workbench for analysis. Prefer the warm runtime tools (`kernel_plot_run`, `kernel_plot_render`, `kernel_plot_artifacts`, `kernel_plot_stop`) for loading data, inspecting object structure, and generating figures or tables. Use `kernel_plot_render` for quick iterative plots that appear inline. Use `kernel_plot_run` + `runtime: "kernel-lite"` when working with data already in warm memory or when saving final artifacts — this keeps loaded data persistent. First, verify the provided input path, load or inspect only that explicit source plus any files mentioned in Notes, and prepare the session for iterative analysis. Keep the first response concise and operational.':"Quick-start this workbench without loading data. Prefer the warm runtime tools (`kernel_plot_run`, `kernel_plot_render`, `kernel_plot_artifacts`, `kernel_plot_stop`) when the user later asks for analysis, plots, or saved artifacts. Do not search the project for `.rds`, `.qs`, `.h5ad`, or other dataset files unless the user explicitly asks. For now, only confirm the selected kernel/runtime is ready and ask what data or task to use next. Keep the first response concise and operational.",r.push("",n,"","CRITICAL — runtime mode:",'- ALWAYS pass `runtime: "kernel-lite"` to every `kernel_plot_run` call. This keeps loaded data, imported packages (library/import), and variables in warm memory across turns. If you use `runtime: "worker"` (one-shot), all loaded state is lost between calls and the analysis restarts from scratch on the next turn.','- Only use `runtime: "worker"` for quick one-shot scripts where memory persistence is not needed.',"- `kernel_plot_render` is always one-shot and does not share memory — use `kernel_plot_run` with `kernel-lite` for iterative work.",...t.isDescribeMode?["","DESCRIBE MODE — the user is a domain expert, not necessarily a coder:",'- The user will describe what they want in high-level terms (e.g. "compare gene expression between clusters", "make a circos plot").',"- Proactively suggest analysis approaches and explain your reasoning in plain language before writing code.","- After each result, summarize what was found in domain terms and suggest logical next steps.","- When the user mentions a figure type (heatmap, volcano, UMAP, circos, dotplot, etc.), pick the appropriate library and parameters without asking for low-level details.","- If you need a parameter the user didn't specify (e.g. which genes to plot), ask clearly and concisely.","- Always confirm what the output means for the user's research question."]:[],"",i),r.join("\n"));try{if(t.kernelId){let e=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"select",cwd:td,language:t.kernel,kernelId:t.kernelId})}),r=await e.json().catch(()=>({}));if(!e.ok||r.error)throw Error(r.error??`HTTP ${e.status}`)}let r=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:td,type:"prompt",message:s,toolNames:D("workbench"),sessionName:l,workbenchMeta:{sourcePath:t.sourcePath,kernel:t.kernel,kernelId:t.kernelId,kernelDisplayName:t.kernelDisplayName}})}),n=await r.json().catch(()=>({}));if(!r.ok||n.error||!n.sessionId)throw Error(n.error??`HTTP ${r.status}`);e5(),p(null),eE(td),d({id:n.sessionId,path:"",cwd:td,name:l,created:o,modified:o,messageCount:1,firstMessage:s,sessionKind:"workbench",createdBy:"launcher",sessionMeta:{sessionKind:"workbench",lastToolNames:D("workbench"),createdBy:"launcher",createdAt:o,initialSourcePath:t.sourcePath||void 0,initialKernel:t.kernel}}),ej("workbench"),ew(!0),P([]),B(null),g(e=>e+1),h(e=>e+1),e.replace(`?session=${encodeURIComponent(n.sessionId)}`,{scroll:!1}),window.setTimeout(()=>{tb()},600)}catch(e){tx(e instanceof Error?e.message:String(e))}finally{eu(!1)}},[e5,tb,e,ep,td]),tW=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(b,{selectedSessionId:a?.id??null,onSelectSession:eN,onNewSession:eO,onNewWorkbench:e2,initialSessionId:eW,onInitialRestoreDone:eU,refreshKey:u,onSessionDeleted:eV,selectedCwd:a?.cwd??c??eL??null,onCwdChange:eA}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0},children:(0,n.jsx)("button",{type:"button",onClick:()=>tc("projects"),title:"Settings","aria-label":"Settings",style:{width:34,display:"flex",alignItems:"center",justifyContent:"center",height:34,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:"pointer",fontSize:12,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.51a2 2 0 0 1 1-1.72l.15-.1a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})})]});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",height:"100dvh",overflow:"hidden",background:"var(--bg)"},children:[(0,n.jsx)("div",{className:"sidebar-overlay-backdrop",onClick:()=>I(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!z,pointerEvents:z?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{className:`sidebar-container${z?" sidebar-open":" sidebar-closed"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200,width:M.width,minWidth:M.width,transition:z||M.isResizing?"none":void 0},children:tW}),z&&(0,n.jsx)(tR,{side:"right",ariaLabel:"Resize sidebar",onResizeStart:M.beginResize,onResize:M.resizeBy,onResizeEnd:M.endResize}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,n.jsxs)("div",{ref:L,className:"app-topbar",style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,borderBottom:"1px solid var(--border)",height:48,padding:"0 8px",background:"var(--bg)"},children:[(0,n.jsx)("button",{className:"topbar-sidebar-toggle",onClick:()=>I(e=>!e),title:z?"Hide sidebar":"Show sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-panel)"},children:z?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,n.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),(0,n.jsxs)("div",{className:"topbar-title-area",style:{display:"flex",alignItems:"center",gap:7,minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:6},children:F&&a?(0,n.jsx)("input",{ref:J,value:U,onChange:e=>K(e.target.value),onKeyDown:Z,onBlur:()=>void G(),style:{width:"min(360px, 34vw)",height:28,boxSizing:"border-box",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",padding:"0 8px",fontSize:13,fontWeight:500,outline:"none"}}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"topbar-session-title",title:to,style:{minWidth:0,maxWidth:"min(420px, 36vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:tt?"var(--text)":"var(--text-muted)",fontSize:14,fontWeight:600,lineHeight:1.2},children:to}),a&&(0,n.jsx)("button",{type:"button",className:"topbar-rename-button",onClick:Y,title:"Rename session",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="transparent"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 20h9"}),(0,n.jsx)("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]})})]})}),ts&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"topbar-project-crumb",style:{color:"var(--text-dim)",fontSize:12,flexShrink:0},children:"/"}),(0,n.jsx)("span",{className:"topbar-project-crumb",title:tl||ts,style:{minWidth:0,maxWidth:"min(280px, 24vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:12,lineHeight:1.2},children:ts})]})]}),tt&&!s&&(0,n.jsx)("div",{className:"topbar-chat-tools",style:{display:"flex",alignItems:"center",gap:6,height:28,flexShrink:0},children:(0,n.jsxs)("button",{type:"button",className:"topbar-plot-button",ref:E,onClick:tw,title:tm>0?`Open Workbench runtime \xb7 ${nE(tm)}${ty>0?` (this session: ${nE(ty)})`:""}`:"Open Workbench runtime status","aria-label":tm>0?`Open Workbench runtime \xb7 ${nE(tm)}${ty>0?` (this session: ${nE(ty)})`:""}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:es?"var(--bg-selected)":tm>0||eh?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${es||tm>0||eh?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:tm>0||eh?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s",fontVariantNumeric:"tabular-nums"},onMouseEnter:e=>{e.currentTarget.style.color=tm>0||eh?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=tm>0||eh?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=es?"var(--bg-selected)":tm>0||eh?"rgba(37,99,235,0.08)":"var(--bg-panel)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsx)("span",{className:"topbar-plot-label",children:"Workbench"}),tm>0&&(0,n.jsx)("span",{className:"topbar-plot-memory",children:ty>0&&ty!==tm?`${nE(ty)} / ${nE(tm)}`:nE(tm)})]})}),ev&&(0,n.jsx)("button",{type:"button",className:"topbar-update-button",title:ev.title,onClick:()=>navigator.clipboard?.writeText(eg?.updateCommand??"").catch(()=>{}),style:{height:28,padding:"0 9px",borderRadius:7,border:"1px solid rgba(34,197,94,0.35)",background:"rgba(34,197,94,0.10)",color:"rgba(34,197,94,0.95)",cursor:"pointer",fontSize:11,fontWeight:650,whiteSpace:"nowrap",flexShrink:0},children:ev.label}),tt&&s&&(0,n.jsxs)("button",{type:"button",className:"topbar-plot-button",ref:E,onClick:tw,title:tm>0?`Open Workbench runtime \xb7 ${nE(tm)}${ty>0?` (this session: ${nE(ty)})`:""}`:"Open Workbench runtime status","aria-label":tm>0?`Open Workbench runtime \xb7 ${nE(tm)}${ty>0?` (this session: ${nE(ty)})`:""}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:4,height:28,padding:"0 7px",flexShrink:0,background:es?"var(--bg-selected)":tm>0||eh?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${es||tm>0||eh?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:tm>0||eh?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsx)("span",{className:"topbar-plot-label",children:"WB"}),tm>0&&(0,n.jsx)("span",{className:"topbar-plot-memory",children:ty>0&&ty!==tm?`${nE(ty)} / ${nE(tm)}`:nE(tm)})]}),tt&&(Q||er)&&(()=>{let e=Q?.tokens,t=Q?.cost??0,r=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),i=t>0?t>=.01?`$${t.toFixed(2)}`:"<$0.01":null,o="var(--text-muted)",l=null;if(er?.contextWindow){let e=er.percent;null!==e&&e>90?o="#ef4444":null!==e&&e>70&&(o="rgba(234,179,8,0.95)"),l=null!==e?`${e.toFixed(0)}% / ${r(er.contextWindow)}`:`? / ${r(er.contextWindow)}`}let s=[];if(e&&(s.push(`in: ${e.input.toLocaleString()}`),s.push(`out: ${e.output.toLocaleString()}`),s.push(`cache read: ${e.cacheRead.toLocaleString()}`),s.push(`cache write: ${e.cacheWrite.toLocaleString()}`),t>0&&s.push(`cost: $${t.toFixed(4)}`)),er?.contextWindow){let e=er.percent;s.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${er.contextWindow.toLocaleString()} tokens`)}let a=s.join(" | ");return(0,n.jsxs)("div",{className:"topbar-session-stats",title:a,style:{display:"flex",alignItems:"center",gap:10,padding:"0 8px",height:28,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:"default",fontVariantNumeric:"tabular-nums"},children:[e&&e.input>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,n.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),r(e.input)]}),e&&e.output>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),r(e.output)]}),e&&e.cacheRead>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,n.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),r(e.cacheRead)]}),i&&(0,n.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text)",fontWeight:500},children:i}),l&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:o},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),l]})]})})(),(0,n.jsx)("button",{type:"button",className:"topbar-icon-button topbar-generate-ui-toggle",onClick:X,title:`生成式 UI: ${C.generativeUI?"on":"off"}`,"aria-label":`生成式 UI: ${C.generativeUI?"on":"off"}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:C.generativeUI?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${C.generativeUI?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:C.generativeUI?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=C.generativeUI?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=C.generativeUI?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=C.generativeUI?"var(--bg-selected)":"var(--bg-panel)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,n.jsx)("path",{d:"M16 17h5"}),(0,n.jsx)("path",{d:"M18.5 14.5v5"})]})}),(0,n.jsx)("button",{className:"topbar-icon-button topbar-theme-toggle",onClick:e=>{let t=e.currentTarget.getBoundingClientRect();l({x:t.left+t.width/2,y:t.top+t.height/2})},title:r?"Switch to light mode":"Switch to dark mode","aria-label":r?"Switch to light mode":"Switch to dark mode","aria-pressed":r,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-panel)"},children:r?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,n.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,n.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,n.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,n.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,n.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,n.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,n.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,n.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),(0,n.jsx)("button",{className:"topbar-icon-button topbar-right-panel-toggle",onClick:()=>ew(e=>!e),title:ek?"Hide right panel":"Show right panel","aria-label":ek?"Hide right panel":"Show right panel",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:ek?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${ek?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:ek?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color=ek?"var(--accent)":"var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=ek?"var(--accent)":"var(--text-muted)",e.currentTarget.style.background=ek?"var(--bg-selected)":"var(--bg-panel)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:tt?(0,n.jsx)(eK,{session:a,newSessionCwd:te,onAgentEnd:eF,onSessionCreated:eH,onSessionForked:e_,modelsRefreshKey:m,chatInputRef:W,onBranchDataChange:O,onSessionStatsChange:et,onContextUsageChange:ei,onToolPresetActive:ex,generativeUI:C.generativeUI,activeFilePath:ti?.filePath??null,onOpenFileAtLine:e0},x):tr?eL?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:"Select a session from the sidebar"}):(0,n.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,n.jsxs)("svg",{width:"44",height:"44",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.7,flexShrink:0},children:[(0,n.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,n.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Get Started"}),(0,n.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"1."}),"Select a project directory from the sidebar",(0,n.jsx)("br",{}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"2."}),"Add models via the ",(0,n.jsx)("strong",{style:{color:"var(--text)"},children:"Models"})," button at the bottom"]})]})]}):null})]}),ek&&(0,n.jsx)(tR,{side:"left",ariaLabel:"Resize right panel",onResizeStart:R.beginResize,onResize:R.resizeBy,onResizeEnd:R.endResize}),(0,n.jsxs)("div",{className:`right-panel-container${ek?" right-panel-open":" right-panel-closed"}`,style:{display:ek?"flex":"none",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,width:R.width,minWidth:R.width,transition:R.isResizing?"none":void 0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",height:36},children:[(0,n.jsxs)("button",{type:"button",className:"right-panel-back-button",onClick:()=>ew(!1),title:"Back to chat","aria-label":"Back to chat",style:{height:36,padding:"0 10px",border:"none",borderRight:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,alignItems:"center",gap:6,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"19",y1:"12",x2:"5",y2:"12"}),(0,n.jsx)("polyline",{points:"12 19 5 12 12 5"})]}),(0,n.jsx)("span",{children:"Chat"})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(tq,{tabs:tn,activeTabId:eb,onSelectTab:ej,onCloseTab:e9,onAskAI:e=>{let t=`I'm looking at \`${e}\`. `;W?.current?.insertIfEmpty(t)}})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===eb?(0,n.jsx)(tS,{cwd:eL??a?.cwd??c??null,refreshKey:f,onOpenFile:eQ,onExploreFile:e1,onAtMention:eR}):"tools"===eb?(0,n.jsx)(tF,{refreshKey:eT,visibleAppId:eS?.appId??null,cwd:eL??a?.cwd??c??null,onOpenApp:e3,onAppChanged:e8,agentRuntimeExtra:(0,n.jsx)(t3,{tree:$,activeLeafId:A,onLeafChange:H,hasSession:!!a,embedded:!0})}):"workbench"===eb&&a?(0,n.jsx)(t2,{sessionId:a.id,cwd:a.cwd,onAskAboutCell:(e,t)=>{let r=e.length>400?e.slice(0,400)+"...":e;W?.current?.insertText(`Explain the code in workbench cell #${t}:
64
- \`\`\`
65
- ${r}
66
- \`\`\`
67
- `)},onAskAboutArtifact:e=>{W?.current?.insertText(nR(e))},onEditArtifact:e=>{W?.current?.insertText(nW(e))},onOpenArtifact:e=>{let t=e.split(/[\\/]/).pop()||e;eQ(e,t)}}):ti?.filePath?ti.filePath.startsWith("__")?(0,n.jsx)(tI,{filePath:ti.filePath}):(0,n.jsx)(eq,{filePath:ti.filePath,children:(0,n.jsx)(eJ.h,{filePath:ti.filePath,cwd:eL??void 0,onOpenFile:eQ,scrollToLine:eZ,workbenchSessionId:a?.sessionKind==="workbench"?a.id:null,onAskAboutArtifact:e=>W?.current?.insertText(nR(e)),onEditArtifact:e=>W?.current?.insertText(nW(e))})}):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),(0,n.jsx)(nz,{open:es,anchorRef:E,status:tp,error:th,currentSessionId:ta,currentCwd:eY,idleTimeoutLabel:n$(C.plotIdleTimeoutMs),busyPid:"number"==typeof tg?tg:null,onClose:()=>ea(!1),onRefresh:()=>{tb()},onReleaseKernels:e=>{tk(e)},onOpenSettings:tz,onOpenStatus:tC}),j&&(0,n.jsx)(nv,{cwd:eY,generativeUI:C.generativeUI,initialTab:w,onGenerativeUIToggle:X,onModelsChanged:()=>y(e=>e+1),onProjectSelect:eB,onProjectsChanged:()=>h(e=>e+1),onClose:()=>{k(!1),y(e=>e+1)}}),eo&&(0,n.jsx)(nj,{cwd:td,runtime:{totalBytes:tm,currentSessionBytes:ty,idleTimeoutLabel:n$(C.plotIdleTimeoutMs)},runtimeError:th,busy:ep,onClose:e5,onLaunch:e=>tM(e),onReleaseCurrentRuntime:a?.id&&a.cwd===td?()=>{tj()}:void 0,onOpenSettings:tz}),(0,n.jsx)(tP,{appType:eS?.appType??"stexp",filePath:eS?.filePath??null,cwd:eS?.cwd??null,appId:eS?.appId??null,sessionId:a?.id??null,onClose:()=>eC(null),onAppChanged:e8,onOpenTools:e4}),eI.map((e,t)=>(0,n.jsx)(eG,{id:e.id,filePath:e.filePath,fileName:e.fileName,cwd:eL??a?.cwd??c??void 0,active:t===eI.length-1,stackIndex:t,zIndex:700+t,onClose:e6,onFocus:e7,onOpenFile:eQ},e.id))]})}}},e=>{e.O(0,[7330,6079,2941,2995,6280,4936,9901,8441,3794,7358],()=>e(e.s=43322)),_N_E=e.O()}]);