@changliu007/pi-web 0.8.0

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 (415) hide show
  1. package/.next/BUILD_ID +1 -0
  2. package/.next/app-path-routes-manifest.json +33 -0
  3. package/.next/build-manifest.json +20 -0
  4. package/.next/diagnostics/build-diagnostics.json +6 -0
  5. package/.next/diagnostics/framework.json +1 -0
  6. package/.next/export-marker.json +6 -0
  7. package/.next/images-manifest.json +68 -0
  8. package/.next/next-minimal-server.js.nft.json +1 -0
  9. package/.next/next-server.js.nft.json +1 -0
  10. package/.next/package.json +1 -0
  11. package/.next/prerender-manifest.json +114 -0
  12. package/.next/react-loadable-manifest.json +2270 -0
  13. package/.next/required-server-files.js +345 -0
  14. package/.next/required-server-files.json +345 -0
  15. package/.next/routes-manifest.json +261 -0
  16. package/.next/server/app/_global-error/page.js +32 -0
  17. package/.next/server/app/_global-error/page.js.nft.json +1 -0
  18. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -0
  19. package/.next/server/app/_global-error.html +1 -0
  20. package/.next/server/app/_global-error.meta +16 -0
  21. package/.next/server/app/_global-error.rsc +14 -0
  22. package/.next/server/app/_global-error.segments/_full.segment.rsc +14 -0
  23. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +5 -0
  24. package/.next/server/app/_global-error.segments/_global-error.segment.rsc +5 -0
  25. package/.next/server/app/_global-error.segments/_head.segment.rsc +5 -0
  26. package/.next/server/app/_global-error.segments/_index.segment.rsc +5 -0
  27. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -0
  28. package/.next/server/app/_not-found/page.js +2 -0
  29. package/.next/server/app/_not-found/page.js.nft.json +1 -0
  30. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
  31. package/.next/server/app/_not-found.html +1 -0
  32. package/.next/server/app/_not-found.meta +16 -0
  33. package/.next/server/app/_not-found.rsc +17 -0
  34. package/.next/server/app/_not-found.segments/_full.segment.rsc +17 -0
  35. package/.next/server/app/_not-found.segments/_head.segment.rsc +6 -0
  36. package/.next/server/app/_not-found.segments/_index.segment.rsc +6 -0
  37. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +5 -0
  38. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +5 -0
  39. package/.next/server/app/_not-found.segments/_tree.segment.rsc +3 -0
  40. package/.next/server/app/api/agent/[id]/events/route.js +3 -0
  41. package/.next/server/app/api/agent/[id]/events/route.js.nft.json +1 -0
  42. package/.next/server/app/api/agent/[id]/events/route_client-reference-manifest.js +1 -0
  43. package/.next/server/app/api/agent/[id]/route.js +1 -0
  44. package/.next/server/app/api/agent/[id]/route.js.nft.json +1 -0
  45. package/.next/server/app/api/agent/[id]/route_client-reference-manifest.js +1 -0
  46. package/.next/server/app/api/agent/new/route.js +1 -0
  47. package/.next/server/app/api/agent/new/route.js.nft.json +1 -0
  48. package/.next/server/app/api/agent/new/route_client-reference-manifest.js +1 -0
  49. package/.next/server/app/api/agent/running/events/route.js +3 -0
  50. package/.next/server/app/api/agent/running/events/route.js.nft.json +1 -0
  51. package/.next/server/app/api/agent/running/events/route_client-reference-manifest.js +1 -0
  52. package/.next/server/app/api/auth/all-providers/route.js +1 -0
  53. package/.next/server/app/api/auth/all-providers/route.js.nft.json +1 -0
  54. package/.next/server/app/api/auth/all-providers/route_client-reference-manifest.js +1 -0
  55. package/.next/server/app/api/auth/api-key/[provider]/route.js +1 -0
  56. package/.next/server/app/api/auth/api-key/[provider]/route.js.nft.json +1 -0
  57. package/.next/server/app/api/auth/api-key/[provider]/route_client-reference-manifest.js +1 -0
  58. package/.next/server/app/api/auth/login/[provider]/route.js +3 -0
  59. package/.next/server/app/api/auth/login/[provider]/route.js.nft.json +1 -0
  60. package/.next/server/app/api/auth/login/[provider]/route_client-reference-manifest.js +1 -0
  61. package/.next/server/app/api/auth/logout/[provider]/route.js +1 -0
  62. package/.next/server/app/api/auth/logout/[provider]/route.js.nft.json +1 -0
  63. package/.next/server/app/api/auth/logout/[provider]/route_client-reference-manifest.js +1 -0
  64. package/.next/server/app/api/auth/providers/route.js +1 -0
  65. package/.next/server/app/api/auth/providers/route.js.nft.json +1 -0
  66. package/.next/server/app/api/auth/providers/route_client-reference-manifest.js +1 -0
  67. package/.next/server/app/api/cwd/validate/route.js +3 -0
  68. package/.next/server/app/api/cwd/validate/route.js.nft.json +1 -0
  69. package/.next/server/app/api/cwd/validate/route_client-reference-manifest.js +1 -0
  70. package/.next/server/app/api/default-cwd/route.js +3 -0
  71. package/.next/server/app/api/default-cwd/route.js.nft.json +1 -0
  72. package/.next/server/app/api/default-cwd/route_client-reference-manifest.js +1 -0
  73. package/.next/server/app/api/directories/list/route.js +3 -0
  74. package/.next/server/app/api/directories/list/route.js.nft.json +1 -0
  75. package/.next/server/app/api/directories/list/route_client-reference-manifest.js +1 -0
  76. package/.next/server/app/api/file-index/route.js +3 -0
  77. package/.next/server/app/api/file-index/route.js.nft.json +1 -0
  78. package/.next/server/app/api/file-index/route_client-reference-manifest.js +1 -0
  79. package/.next/server/app/api/files/[...path]/route.js +51 -0
  80. package/.next/server/app/api/files/[...path]/route.js.nft.json +1 -0
  81. package/.next/server/app/api/files/[...path]/route_client-reference-manifest.js +1 -0
  82. package/.next/server/app/api/home/route.js +1 -0
  83. package/.next/server/app/api/home/route.js.nft.json +1 -0
  84. package/.next/server/app/api/home/route_client-reference-manifest.js +1 -0
  85. package/.next/server/app/api/models/route.js +1 -0
  86. package/.next/server/app/api/models/route.js.nft.json +1 -0
  87. package/.next/server/app/api/models/route_client-reference-manifest.js +1 -0
  88. package/.next/server/app/api/models-config/route.js +1 -0
  89. package/.next/server/app/api/models-config/route.js.nft.json +1 -0
  90. package/.next/server/app/api/models-config/route_client-reference-manifest.js +1 -0
  91. package/.next/server/app/api/models-config/test/route.js +1 -0
  92. package/.next/server/app/api/models-config/test/route.js.nft.json +1 -0
  93. package/.next/server/app/api/models-config/test/route_client-reference-manifest.js +1 -0
  94. package/.next/server/app/api/plugins/route.js +1 -0
  95. package/.next/server/app/api/plugins/route.js.nft.json +1 -0
  96. package/.next/server/app/api/plugins/route_client-reference-manifest.js +1 -0
  97. package/.next/server/app/api/sessions/[id]/context/route.js +3 -0
  98. package/.next/server/app/api/sessions/[id]/context/route.js.nft.json +1 -0
  99. package/.next/server/app/api/sessions/[id]/context/route_client-reference-manifest.js +1 -0
  100. package/.next/server/app/api/sessions/[id]/export/route.js +56 -0
  101. package/.next/server/app/api/sessions/[id]/export/route.js.nft.json +1 -0
  102. package/.next/server/app/api/sessions/[id]/export/route_client-reference-manifest.js +1 -0
  103. package/.next/server/app/api/sessions/[id]/route.js +1 -0
  104. package/.next/server/app/api/sessions/[id]/route.js.nft.json +1 -0
  105. package/.next/server/app/api/sessions/[id]/route_client-reference-manifest.js +1 -0
  106. package/.next/server/app/api/sessions/route.js +1 -0
  107. package/.next/server/app/api/sessions/route.js.nft.json +1 -0
  108. package/.next/server/app/api/sessions/route_client-reference-manifest.js +1 -0
  109. package/.next/server/app/api/skills/install/route.js +1 -0
  110. package/.next/server/app/api/skills/install/route.js.nft.json +1 -0
  111. package/.next/server/app/api/skills/install/route_client-reference-manifest.js +1 -0
  112. package/.next/server/app/api/skills/route.js +6 -0
  113. package/.next/server/app/api/skills/route.js.nft.json +1 -0
  114. package/.next/server/app/api/skills/route_client-reference-manifest.js +1 -0
  115. package/.next/server/app/api/skills/search/route.js +1 -0
  116. package/.next/server/app/api/skills/search/route.js.nft.json +1 -0
  117. package/.next/server/app/api/skills/search/route_client-reference-manifest.js +1 -0
  118. package/.next/server/app/api/worktrees/route.js +3 -0
  119. package/.next/server/app/api/worktrees/route.js.nft.json +1 -0
  120. package/.next/server/app/api/worktrees/route_client-reference-manifest.js +1 -0
  121. package/.next/server/app/favicon.ico/route.js +1 -0
  122. package/.next/server/app/favicon.ico/route.js.nft.json +1 -0
  123. package/.next/server/app/favicon.ico.body +0 -0
  124. package/.next/server/app/favicon.ico.meta +1 -0
  125. package/.next/server/app/index.html +1 -0
  126. package/.next/server/app/index.meta +14 -0
  127. package/.next/server/app/index.rsc +16 -0
  128. package/.next/server/app/index.segments/__PAGE__.segment.rsc +6 -0
  129. package/.next/server/app/index.segments/_full.segment.rsc +16 -0
  130. package/.next/server/app/index.segments/_head.segment.rsc +6 -0
  131. package/.next/server/app/index.segments/_index.segment.rsc +6 -0
  132. package/.next/server/app/index.segments/_tree.segment.rsc +3 -0
  133. package/.next/server/app/page.js +76 -0
  134. package/.next/server/app/page.js.nft.json +1 -0
  135. package/.next/server/app/page_client-reference-manifest.js +1 -0
  136. package/.next/server/app-paths-manifest.json +33 -0
  137. package/.next/server/chunks/1030.js +1 -0
  138. package/.next/server/chunks/1048.js +1 -0
  139. package/.next/server/chunks/1198.js +5 -0
  140. package/.next/server/chunks/165.js +1 -0
  141. package/.next/server/chunks/1813.js +1 -0
  142. package/.next/server/chunks/2055.js +1 -0
  143. package/.next/server/chunks/2325.js +80 -0
  144. package/.next/server/chunks/2504.js +79 -0
  145. package/.next/server/chunks/258.js +1 -0
  146. package/.next/server/chunks/2778.js +1 -0
  147. package/.next/server/chunks/2943.js +1 -0
  148. package/.next/server/chunks/3000.js +4 -0
  149. package/.next/server/chunks/3052.js +1 -0
  150. package/.next/server/chunks/3054.js +148 -0
  151. package/.next/server/chunks/3181.js +1 -0
  152. package/.next/server/chunks/319.js +45 -0
  153. package/.next/server/chunks/3379.js +1 -0
  154. package/.next/server/chunks/3397.js +29 -0
  155. package/.next/server/chunks/358.js +19 -0
  156. package/.next/server/chunks/3672.js +1 -0
  157. package/.next/server/chunks/3818.js +1 -0
  158. package/.next/server/chunks/4120.js +148 -0
  159. package/.next/server/chunks/4266.js +1 -0
  160. package/.next/server/chunks/4365.js +43 -0
  161. package/.next/server/chunks/4407.js +23 -0
  162. package/.next/server/chunks/4616.js +1 -0
  163. package/.next/server/chunks/4741.js +18 -0
  164. package/.next/server/chunks/4768.js +80 -0
  165. package/.next/server/chunks/5409.js +1 -0
  166. package/.next/server/chunks/5414.js +1 -0
  167. package/.next/server/chunks/5460.js +255 -0
  168. package/.next/server/chunks/5737.js +24 -0
  169. package/.next/server/chunks/5773.js +104 -0
  170. package/.next/server/chunks/5985.js +24 -0
  171. package/.next/server/chunks/6073.js +64 -0
  172. package/.next/server/chunks/6346.js +1 -0
  173. package/.next/server/chunks/6900.js +90 -0
  174. package/.next/server/chunks/7058.js +166 -0
  175. package/.next/server/chunks/7162.js +287 -0
  176. package/.next/server/chunks/7287.js +141 -0
  177. package/.next/server/chunks/7307.js +1 -0
  178. package/.next/server/chunks/7601.js +3 -0
  179. package/.next/server/chunks/7702.js +93 -0
  180. package/.next/server/chunks/7960.js +1 -0
  181. package/.next/server/chunks/812.js +226 -0
  182. package/.next/server/chunks/8276.js +1 -0
  183. package/.next/server/chunks/8360.js +36 -0
  184. package/.next/server/chunks/8361.js +1 -0
  185. package/.next/server/chunks/8430.js +1 -0
  186. package/.next/server/chunks/8469.js +9 -0
  187. package/.next/server/chunks/8490.js +1 -0
  188. package/.next/server/chunks/8704.js +115 -0
  189. package/.next/server/chunks/9703.js +215 -0
  190. package/.next/server/chunks/9963.js +1 -0
  191. package/.next/server/functions-config-manifest.json +6 -0
  192. package/.next/server/interception-route-rewrite-manifest.js +1 -0
  193. package/.next/server/middleware-build-manifest.js +1 -0
  194. package/.next/server/middleware-manifest.json +6 -0
  195. package/.next/server/middleware-react-loadable-manifest.js +1 -0
  196. package/.next/server/next-font-manifest.js +1 -0
  197. package/.next/server/next-font-manifest.json +1 -0
  198. package/.next/server/pages/404.html +1 -0
  199. package/.next/server/pages/500.html +1 -0
  200. package/.next/server/pages-manifest.json +4 -0
  201. package/.next/server/prefetch-hints.json +1 -0
  202. package/.next/server/server-reference-manifest.js +1 -0
  203. package/.next/server/server-reference-manifest.json +1 -0
  204. package/.next/server/webpack-runtime.js +1 -0
  205. package/.next/static/chunks/122.eef9274869d2a305.js +287 -0
  206. package/.next/static/chunks/1407.28a7fb037c2b2f35.js +43 -0
  207. package/.next/static/chunks/164.ab76942aa0c3ec72.js +1 -0
  208. package/.next/static/chunks/1744.78ed01e4e93054c1.js +93 -0
  209. package/.next/static/chunks/1812.9d1e5ae0d68e6c24.js +76 -0
  210. package/.next/static/chunks/1921.2c58179657f0a6da.js +90 -0
  211. package/.next/static/chunks/1966.b8f83f7ba376c962.js +1 -0
  212. package/.next/static/chunks/1978.260c2b48f817965f.js +1 -0
  213. package/.next/static/chunks/2082.1535d602444ae4c1.js +1 -0
  214. package/.next/static/chunks/288.d969aeba2ab92928.js +1 -0
  215. package/.next/static/chunks/318.3fee3527eeabc956.js +4 -0
  216. package/.next/static/chunks/330.f851561e21edfbbb.js +19 -0
  217. package/.next/static/chunks/348d3b01.d472dd6bc52ab90c.js +148 -0
  218. package/.next/static/chunks/3762.d5c709991fc322ef.js +148 -0
  219. package/.next/static/chunks/3794-e569667691edc8f7.js +32 -0
  220. package/.next/static/chunks/3899.3f761f7e3a944e8c.js +1 -0
  221. package/.next/static/chunks/3916.0ba385e8bbb9cc14.js +1 -0
  222. package/.next/static/chunks/4021.cdd3c8f1def79a10.js +1 -0
  223. package/.next/static/chunks/4178.0212bbaaa6124460.js +115 -0
  224. package/.next/static/chunks/4389.18c637d4861a0624.js +215 -0
  225. package/.next/static/chunks/4784-3a415c7ce1a2a0c6.js +1 -0
  226. package/.next/static/chunks/4823.276e9524d3742f1c.js +141 -0
  227. package/.next/static/chunks/4829.cf1d50e43e6d9db5.js +1 -0
  228. package/.next/static/chunks/4bd1b696-e356ca5ba0218e27.js +1 -0
  229. package/.next/static/chunks/5019.b5a1a2b8daf17525.js +1 -0
  230. package/.next/static/chunks/5326.69460442bdcd6cd3.js +1 -0
  231. package/.next/static/chunks/5336.d3fa82872c826f30.js +79 -0
  232. package/.next/static/chunks/5590.ef62922166d308b4.js +1 -0
  233. package/.next/static/chunks/5627.62050808924cacee.js +23 -0
  234. package/.next/static/chunks/5690.9d6eb1edb1399995.js +1 -0
  235. package/.next/static/chunks/58bb9007.3ddd5d34c5f548be.js +80 -0
  236. package/.next/static/chunks/6071.e9deb627fefd3a20.js +104 -0
  237. package/.next/static/chunks/6600.583c88eef37aa524.js +1 -0
  238. package/.next/static/chunks/6710.5b0cfa12a8f68eb9.js +36 -0
  239. package/.next/static/chunks/744.e67714b764b7bed0.js +166 -0
  240. package/.next/static/chunks/7478.c2572eb272c8f7ac.js +80 -0
  241. package/.next/static/chunks/75.70c23d2729f4ae2c.js +9 -0
  242. package/.next/static/chunks/7563.d8fbeed6a250a962.js +64 -0
  243. package/.next/static/chunks/7704.a79a089b1c6a8099.js +5 -0
  244. package/.next/static/chunks/7874.8db6929b94cdf697.js +1 -0
  245. package/.next/static/chunks/7948.aca281219bad1ab4.js +1 -0
  246. package/.next/static/chunks/8538.9462238529bbdc80.js +226 -0
  247. package/.next/static/chunks/8568.f85d8b36fc9a9037.js +1 -0
  248. package/.next/static/chunks/8603.7619d9ceac35ae03.js +1 -0
  249. package/.next/static/chunks/8783.8586d8ca9ef1dce8.js +24 -0
  250. package/.next/static/chunks/8863.bd7e87f75e046db5.js +1 -0
  251. package/.next/static/chunks/8889.1ed3f1aa3ac49dd9.js +29 -0
  252. package/.next/static/chunks/895.a198d303969f1c01.js +24 -0
  253. package/.next/static/chunks/90542734.b75ad0df50bf68f5.js +1 -0
  254. package/.next/static/chunks/9242.a1894a4c754b979d.js +1 -0
  255. package/.next/static/chunks/9471.a7e240888c3a75bc.js +1 -0
  256. package/.next/static/chunks/9500.1488aec06ee78127.js +1 -0
  257. package/.next/static/chunks/9529.438891449b77abc7.js +1 -0
  258. package/.next/static/chunks/9633.155548b5fca6e580.js +1 -0
  259. package/.next/static/chunks/9779.673004a62d70e36a.js +1 -0
  260. package/.next/static/chunks/app/_global-error/page-6c6d0771675e402f.js +1 -0
  261. package/.next/static/chunks/app/_not-found/page-4129fc0773eb2a79.js +1 -0
  262. package/.next/static/chunks/app/api/agent/[id]/events/route-6c6d0771675e402f.js +1 -0
  263. package/.next/static/chunks/app/api/agent/[id]/route-6c6d0771675e402f.js +1 -0
  264. package/.next/static/chunks/app/api/agent/new/route-6c6d0771675e402f.js +1 -0
  265. package/.next/static/chunks/app/api/agent/running/events/route-6c6d0771675e402f.js +1 -0
  266. package/.next/static/chunks/app/api/auth/all-providers/route-6c6d0771675e402f.js +1 -0
  267. package/.next/static/chunks/app/api/auth/api-key/[provider]/route-6c6d0771675e402f.js +1 -0
  268. package/.next/static/chunks/app/api/auth/login/[provider]/route-6c6d0771675e402f.js +1 -0
  269. package/.next/static/chunks/app/api/auth/logout/[provider]/route-6c6d0771675e402f.js +1 -0
  270. package/.next/static/chunks/app/api/auth/providers/route-6c6d0771675e402f.js +1 -0
  271. package/.next/static/chunks/app/api/cwd/validate/route-6c6d0771675e402f.js +1 -0
  272. package/.next/static/chunks/app/api/default-cwd/route-6c6d0771675e402f.js +1 -0
  273. package/.next/static/chunks/app/api/directories/list/route-6c6d0771675e402f.js +1 -0
  274. package/.next/static/chunks/app/api/file-index/route-6c6d0771675e402f.js +1 -0
  275. package/.next/static/chunks/app/api/files/[...path]/route-6c6d0771675e402f.js +1 -0
  276. package/.next/static/chunks/app/api/home/route-6c6d0771675e402f.js +1 -0
  277. package/.next/static/chunks/app/api/models/route-6c6d0771675e402f.js +1 -0
  278. package/.next/static/chunks/app/api/models-config/route-6c6d0771675e402f.js +1 -0
  279. package/.next/static/chunks/app/api/models-config/test/route-6c6d0771675e402f.js +1 -0
  280. package/.next/static/chunks/app/api/plugins/route-6c6d0771675e402f.js +1 -0
  281. package/.next/static/chunks/app/api/sessions/[id]/context/route-6c6d0771675e402f.js +1 -0
  282. package/.next/static/chunks/app/api/sessions/[id]/export/route-6c6d0771675e402f.js +1 -0
  283. package/.next/static/chunks/app/api/sessions/[id]/route-6c6d0771675e402f.js +1 -0
  284. package/.next/static/chunks/app/api/sessions/route-6c6d0771675e402f.js +1 -0
  285. package/.next/static/chunks/app/api/skills/install/route-6c6d0771675e402f.js +1 -0
  286. package/.next/static/chunks/app/api/skills/route-6c6d0771675e402f.js +1 -0
  287. package/.next/static/chunks/app/api/skills/search/route-6c6d0771675e402f.js +1 -0
  288. package/.next/static/chunks/app/api/worktrees/route-6c6d0771675e402f.js +1 -0
  289. package/.next/static/chunks/app/layout-e01bf47927e03418.js +1 -0
  290. package/.next/static/chunks/app/page-dacc908aa65c55c1.js +75 -0
  291. package/.next/static/chunks/c9a5f755.309e1bea31640a4c.js +119 -0
  292. package/.next/static/chunks/d3ac728e-7964f816a1ca64e5.js +1 -0
  293. package/.next/static/chunks/f2098590.3d4ddddc296bb3a1.js +62 -0
  294. package/.next/static/chunks/framework-711ef29bc66f648c.js +1 -0
  295. package/.next/static/chunks/main-app-c591a2fe7a2f48a1.js +1 -0
  296. package/.next/static/chunks/main-fd40701e10f417d9.js +5 -0
  297. package/.next/static/chunks/next/dist/client/components/builtin/app-error-6c6d0771675e402f.js +1 -0
  298. package/.next/static/chunks/next/dist/client/components/builtin/forbidden-6c6d0771675e402f.js +1 -0
  299. package/.next/static/chunks/next/dist/client/components/builtin/global-error-82c1d2ddfc0ee2bf.js +1 -0
  300. package/.next/static/chunks/next/dist/client/components/builtin/not-found-6c6d0771675e402f.js +1 -0
  301. package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-6c6d0771675e402f.js +1 -0
  302. package/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  303. package/.next/static/chunks/webpack-00559159379c45d2.js +1 -0
  304. package/.next/static/css/88714c00e109ce28.css +1 -0
  305. package/.next/static/css/b5f3d619b27f5372.css +1 -0
  306. package/.next/static/media/15605e25b523335c-s.woff2 +0 -0
  307. package/.next/static/media/1a3dce5cfb5f7760-s.woff2 +0 -0
  308. package/.next/static/media/1cdd02902f937a18-s.woff2 +0 -0
  309. package/.next/static/media/4c4b3b30b6bcb2be-s.woff2 +0 -0
  310. package/.next/static/media/641a7b8a5800ee0e-s.woff2 +0 -0
  311. package/.next/static/media/7deddc85b7ffd1dc-s.p.woff2 +0 -0
  312. package/.next/static/media/KaTeX_AMS-Regular.1608a09b.woff +0 -0
  313. package/.next/static/media/KaTeX_AMS-Regular.4aafdb68.ttf +0 -0
  314. package/.next/static/media/KaTeX_AMS-Regular.a79f1c31.woff2 +0 -0
  315. package/.next/static/media/KaTeX_Caligraphic-Bold.b6770918.woff +0 -0
  316. package/.next/static/media/KaTeX_Caligraphic-Bold.cce5b8ec.ttf +0 -0
  317. package/.next/static/media/KaTeX_Caligraphic-Bold.ec17d132.woff2 +0 -0
  318. package/.next/static/media/KaTeX_Caligraphic-Regular.07ef19e7.ttf +0 -0
  319. package/.next/static/media/KaTeX_Caligraphic-Regular.55fac258.woff2 +0 -0
  320. package/.next/static/media/KaTeX_Caligraphic-Regular.dad44a7f.woff +0 -0
  321. package/.next/static/media/KaTeX_Fraktur-Bold.9f256b85.woff +0 -0
  322. package/.next/static/media/KaTeX_Fraktur-Bold.b18f59e1.ttf +0 -0
  323. package/.next/static/media/KaTeX_Fraktur-Bold.d42a5579.woff2 +0 -0
  324. package/.next/static/media/KaTeX_Fraktur-Regular.7c187121.woff +0 -0
  325. package/.next/static/media/KaTeX_Fraktur-Regular.d3c882a6.woff2 +0 -0
  326. package/.next/static/media/KaTeX_Fraktur-Regular.ed38e79f.ttf +0 -0
  327. package/.next/static/media/KaTeX_Main-Bold.b74a1a8b.ttf +0 -0
  328. package/.next/static/media/KaTeX_Main-Bold.c3fb5ac2.woff2 +0 -0
  329. package/.next/static/media/KaTeX_Main-Bold.d181c465.woff +0 -0
  330. package/.next/static/media/KaTeX_Main-BoldItalic.6f2bb1df.woff2 +0 -0
  331. package/.next/static/media/KaTeX_Main-BoldItalic.70d8b0a5.ttf +0 -0
  332. package/.next/static/media/KaTeX_Main-BoldItalic.e3f82f9d.woff +0 -0
  333. package/.next/static/media/KaTeX_Main-Italic.47373d1e.ttf +0 -0
  334. package/.next/static/media/KaTeX_Main-Italic.8916142b.woff2 +0 -0
  335. package/.next/static/media/KaTeX_Main-Italic.9024d815.woff +0 -0
  336. package/.next/static/media/KaTeX_Main-Regular.0462f03b.woff2 +0 -0
  337. package/.next/static/media/KaTeX_Main-Regular.7f51fe03.woff +0 -0
  338. package/.next/static/media/KaTeX_Main-Regular.b7f8fe9b.ttf +0 -0
  339. package/.next/static/media/KaTeX_Math-BoldItalic.572d331f.woff2 +0 -0
  340. package/.next/static/media/KaTeX_Math-BoldItalic.a879cf83.ttf +0 -0
  341. package/.next/static/media/KaTeX_Math-BoldItalic.f1035d8d.woff +0 -0
  342. package/.next/static/media/KaTeX_Math-Italic.5295ba48.woff +0 -0
  343. package/.next/static/media/KaTeX_Math-Italic.939bc644.ttf +0 -0
  344. package/.next/static/media/KaTeX_Math-Italic.f28c23ac.woff2 +0 -0
  345. package/.next/static/media/KaTeX_SansSerif-Bold.8c5b5494.woff2 +0 -0
  346. package/.next/static/media/KaTeX_SansSerif-Bold.94e1e8dc.ttf +0 -0
  347. package/.next/static/media/KaTeX_SansSerif-Bold.bf59d231.woff +0 -0
  348. package/.next/static/media/KaTeX_SansSerif-Italic.3b1e59b3.woff2 +0 -0
  349. package/.next/static/media/KaTeX_SansSerif-Italic.7c9bc82b.woff +0 -0
  350. package/.next/static/media/KaTeX_SansSerif-Italic.b4c20c84.ttf +0 -0
  351. package/.next/static/media/KaTeX_SansSerif-Regular.74048478.woff +0 -0
  352. package/.next/static/media/KaTeX_SansSerif-Regular.ba21ed5f.woff2 +0 -0
  353. package/.next/static/media/KaTeX_SansSerif-Regular.d4d7ba48.ttf +0 -0
  354. package/.next/static/media/KaTeX_Script-Regular.03e9641d.woff2 +0 -0
  355. package/.next/static/media/KaTeX_Script-Regular.07505710.woff +0 -0
  356. package/.next/static/media/KaTeX_Script-Regular.fe9cbbe1.ttf +0 -0
  357. package/.next/static/media/KaTeX_Size1-Regular.e1e279cb.woff +0 -0
  358. package/.next/static/media/KaTeX_Size1-Regular.eae34984.woff2 +0 -0
  359. package/.next/static/media/KaTeX_Size1-Regular.fabc004a.ttf +0 -0
  360. package/.next/static/media/KaTeX_Size2-Regular.57727022.woff +0 -0
  361. package/.next/static/media/KaTeX_Size2-Regular.5916a24f.woff2 +0 -0
  362. package/.next/static/media/KaTeX_Size2-Regular.d6b476ec.ttf +0 -0
  363. package/.next/static/media/KaTeX_Size3-Regular.9acaf01c.woff +0 -0
  364. package/.next/static/media/KaTeX_Size3-Regular.a144ef58.ttf +0 -0
  365. package/.next/static/media/KaTeX_Size3-Regular.b4230e7e.woff2 +0 -0
  366. package/.next/static/media/KaTeX_Size4-Regular.10d95fd3.woff2 +0 -0
  367. package/.next/static/media/KaTeX_Size4-Regular.7a996c9d.woff +0 -0
  368. package/.next/static/media/KaTeX_Size4-Regular.fbccdabe.ttf +0 -0
  369. package/.next/static/media/KaTeX_Typewriter-Regular.6258592b.woff +0 -0
  370. package/.next/static/media/KaTeX_Typewriter-Regular.a8709e36.woff2 +0 -0
  371. package/.next/static/media/KaTeX_Typewriter-Regular.d97aaf4a.ttf +0 -0
  372. package/.next/static/media/ec14413c594b3356-s.p.woff2 +0 -0
  373. package/.next/static/wlKjHohxndI39oHSsHTlI/_buildManifest.js +1 -0
  374. package/.next/static/wlKjHohxndI39oHSsHTlI/_ssgManifest.js +1 -0
  375. package/.next/trace +73 -0
  376. package/.next/trace-build +1 -0
  377. package/.next/types/app/api/agent/[id]/events/route.ts +351 -0
  378. package/.next/types/app/api/agent/[id]/route.ts +351 -0
  379. package/.next/types/app/api/agent/new/route.ts +351 -0
  380. package/.next/types/app/api/agent/running/events/route.ts +351 -0
  381. package/.next/types/app/api/auth/all-providers/route.ts +351 -0
  382. package/.next/types/app/api/auth/api-key/[provider]/route.ts +351 -0
  383. package/.next/types/app/api/auth/login/[provider]/route.ts +351 -0
  384. package/.next/types/app/api/auth/logout/[provider]/route.ts +351 -0
  385. package/.next/types/app/api/auth/providers/route.ts +351 -0
  386. package/.next/types/app/api/cwd/validate/route.ts +351 -0
  387. package/.next/types/app/api/default-cwd/route.ts +351 -0
  388. package/.next/types/app/api/directories/list/route.ts +351 -0
  389. package/.next/types/app/api/file-index/route.ts +351 -0
  390. package/.next/types/app/api/files/[...path]/route.ts +351 -0
  391. package/.next/types/app/api/home/route.ts +351 -0
  392. package/.next/types/app/api/models/route.ts +351 -0
  393. package/.next/types/app/api/models-config/route.ts +351 -0
  394. package/.next/types/app/api/models-config/test/route.ts +351 -0
  395. package/.next/types/app/api/plugins/route.ts +351 -0
  396. package/.next/types/app/api/sessions/[id]/context/route.ts +351 -0
  397. package/.next/types/app/api/sessions/[id]/export/route.ts +351 -0
  398. package/.next/types/app/api/sessions/[id]/route.ts +351 -0
  399. package/.next/types/app/api/sessions/route.ts +351 -0
  400. package/.next/types/app/api/skills/install/route.ts +351 -0
  401. package/.next/types/app/api/skills/route.ts +351 -0
  402. package/.next/types/app/api/skills/search/route.ts +351 -0
  403. package/.next/types/app/api/worktrees/route.ts +351 -0
  404. package/.next/types/app/layout.ts +87 -0
  405. package/.next/types/app/page.ts +87 -0
  406. package/.next/types/cache-life.d.ts +145 -0
  407. package/.next/types/package.json +1 -0
  408. package/.next/types/routes.d.ts +99 -0
  409. package/.next/types/validator.ts +313 -0
  410. package/LICENSE +21 -0
  411. package/README.md +116 -0
  412. package/README.zh-CN.md +112 -0
  413. package/bin/pi-web.js +83 -0
  414. package/next.config.ts +31 -0
  415. package/package.json +64 -0
@@ -0,0 +1,75 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{14755:(e,t,r)=>{"use strict";r.d(t,{getPresetFromTools:()=>s,xG:()=>a});let n=[],o=["read","bash","edit","write"],i=["bash","read","edit","write","grep","find","ls"],l=new Set(i);function s(e){let t=e.filter(e=>e.active);if(0===t.length)return"none";let r=t.map(e=>e.name).filter(e=>l.has(e)).sort().join(",");return r===[...o].sort().join(",")?"default":r===[...i].sort().join(",")?"full":"default"}function a(e){return"none"===e?[...n]:"full"===e?[...i]:[...o]}},58978:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>nv});var n=r(95155),o=r(12115),i=r(73321);let l="var(--text-dim)";function s({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:l}),(0,n.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:l,strokeWidth:"1",fill:l,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:l,strokeWidth:"1",fill:l,fillOpacity:"0.1"})})}function a({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:l,strokeWidth:"1",fill:l,fillOpacity:"0.08"}),(0,n.jsx)("path",{d:"M10 2v3h3",stroke:l,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function d({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,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:l,letterSpacing:"0",children:e})]})}function c({size:e=14}){return(0,n.jsx)(d,{label:"TS",size:e})}function u({size:e=14}){return(0,n.jsx)(d,{label:"TSX",size:e})}function p({size:e=14}){return(0,n.jsx)(d,{label:"JS",size:e})}function h({size:e=14}){return(0,n.jsx)(d,{label:"JSX",size:e})}function x({size:e=14}){return(0,n.jsx)(d,{label:"PY",size:e})}function g({size:e=14}){return(0,n.jsx)(d,{label:"{}",size:e})}function f({size:e=14}){return(0,n.jsx)(d,{label:"CSS",size:e})}function m({size:e=14}){return(0,n.jsx)(d,{label:"SC",size:e})}function v({size:e=14}){return(0,n.jsx)(d,{label:"HTM",size:e})}function y({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:l,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:l,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function b({size:e=14}){return(0,n.jsx)(d,{label:"YML",size:e})}function k({size:e=14}){return(0,n.jsx)(d,{label:"TOM",size:e})}function j({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:l,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,n.jsx)("path",{d:"M7.5 10.5h2.5",stroke:l,strokeWidth:"0.95",strokeLinecap:"round"})]})}function w({size:e=14}){return(0,n.jsx)(d,{label:"RS",size:e})}function S({size:e=14}){return(0,n.jsx)(d,{label:"GO",size:e})}function C({size:e=14}){return(0,n.jsx)(d,{label:"SQL",size:e})}function T({size:e=14}){return(0,n.jsx)(d,{label:"GQL",size:e})}function L({size:e=14}){return(0,n.jsx)(d,{label:"TF",size:e})}function I({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,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:l,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:l,strokeWidth:"0.8"}),(0,n.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:l,strokeWidth:"0.8"})]})}function z({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:l,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:l,strokeWidth:"0.9",strokeLinecap:"round"})]})}function R({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:l,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:l,strokeWidth:"0.85"}),(0,n.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:l,strokeWidth:"0.85"}),(0,n.jsx)("path",{d:"M5 7.5V9",stroke:l,strokeWidth:"0.85",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:l,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function W({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,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:l,strokeWidth:"0.9"}),(0,n.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:l,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function M({size:e=14}){return(0,n.jsx)(d,{label:"DOC",size:e})}function E({size:e=14}){return(0,n.jsx)(d,{label:"PDF",size:e})}function $({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:l,strokeWidth:"0.9",fill:l,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M8.5 1v3h3",stroke:l,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:l,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:l,strokeWidth:"0.8",strokeLinecap:"round"})]})}function B(e,t=14){let r=e.toLowerCase(),o=r.split(".").pop()??"";if("dockerfile"===r||r.startsWith("dockerfile."))return(0,n.jsx)(I,{size:t});if(".env"===r||r.startsWith(".env."))return(0,n.jsx)(z,{size:t});if(".gitignore"===r||".gitattributes"===r||".gitmodules"===r)return(0,n.jsx)(R,{size:t});if("package-lock.json"===r||"yarn.lock"===r||"bun.lock"===r||"pnpm-lock.yaml"===r||"cargo.lock"===r)return(0,n.jsx)(W,{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)($,{size:t});switch(o){case"ts":return(0,n.jsx)(c,{size:t});case"tsx":return(0,n.jsx)(u,{size:t});case"js":case"mjs":case"cjs":return(0,n.jsx)(p,{size:t});case"jsx":return(0,n.jsx)(h,{size:t});case"py":return(0,n.jsx)(x,{size:t});case"json":case"jsonl":return(0,n.jsx)(g,{size:t});case"css":case"less":return(0,n.jsx)(f,{size:t});case"scss":return(0,n.jsx)(m,{size:t});case"html":case"htm":return(0,n.jsx)(v,{size:t});case"md":case"mdx":return(0,n.jsx)(y,{size:t});case"yaml":case"yml":return(0,n.jsx)(b,{size:t});case"toml":return(0,n.jsx)(k,{size:t});case"sh":case"bash":case"zsh":case"fish":return(0,n.jsx)(j,{size:t});case"rs":return(0,n.jsx)(w,{size:t});case"go":return(0,n.jsx)(S,{size:t});case"sql":return(0,n.jsx)(C,{size:t});case"graphql":case"gql":return(0,n.jsx)(T,{size:t});case"tf":case"hcl":return(0,n.jsx)(L,{size:t});case"docx":return(0,n.jsx)(M,{size:t});case"pdf":return(0,n.jsx)(E,{size:t});case"lock":return(0,n.jsx)(W,{size:t});default:return(0,n.jsx)(a,{size:t})}}function A(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function D(e){return A(e).split("/").filter(Boolean).map(encodeURIComponent).join("/")}function P(e){let t=A(e).replace(/\/+$/,"");return t.split("/").pop()??t}function F(e,t){if(!t)return e;let r=A(e),n=A(t).replace(/\/$/,"");return r.startsWith(n+"/")?r.slice(n.length+1):e}async function N(e){let t=D(e),r=await fetch(`/api/files/${t}?type=list`);if(!r.ok){let e=`Failed to load files (HTTP ${r.status})`;try{let t=await r.json();t.error&&(e=t.error)}catch{}throw Error(e)}return((await r.json()).entries??[]).map(t=>{var r;return{name:t.name,fullPath:(r=t.name,`${A(e).replace(/\/$/,"")}/${r}`),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}})}function O({node:e,depth:t,cwd:r,onOpenFile:i,onAtMention:l,expandedPaths:a,onToggleExpanded:d,refreshKey:c}){let u=a.has(e.fullPath),[p,h]=(0,o.useState)(e.children??[]),[x,g]=(0,o.useState)(e.loaded??!1),[f,m]=(0,o.useState)(!1),[v,y]=(0,o.useState)(!1),b=(0,o.useCallback)(async(t=!1)=>{if(!x||t){m(!0);try{let t=await N(e.fullPath);h(t),g(!0)}catch{}finally{m(!1)}}},[x,e.fullPath]),k=(0,o.useRef)(x);(0,o.useEffect)(()=>{k.current=x}),(0,o.useEffect)(()=>{u&&x&&b(!0)},[c]);let j=(0,o.useCallback)(()=>{if(e.isDir){let t=!u;d(e.fullPath,t),t&&!x&&b()}else i(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,x,u,b,i,d]);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:j,onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:v?"var(--bg-hover)":"transparent",borderRadius:4,userSelect:"none"},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:u?"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)(s,{size:14,open:u}):B(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}),f&&(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"})}),l&&v&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),l(F(e.fullPath,r),e.isDir)},title:"Insert path into chat",style:{position:"absolute",right:e.isDir?4:28,top:"50%",transform:"translateY(-50%)",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"]}),v&&!e.isDir&&(0,n.jsx)("a",{href:`/api/files/${D(e.fullPath)}?type=download`,download:!0,onClick:e=>e.stopPropagation(),title:"Download file",style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 5px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap",textDecoration:"none"},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)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),e.isDir&&u&&(0,n.jsxs)("div",{children:[p.map(e=>(0,n.jsx)(O,{node:e,depth:t+1,cwd:r,onOpenFile:i,onAtMention:l,expandedPaths:a,onToggleExpanded:d,refreshKey:c},e.fullPath)),0===p.length&&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 H({cwd:e,onOpenFile:t,refreshKey:r,onAtMention:i}){let[l,s]=(0,o.useState)([]),[a,d]=(0,o.useState)(!0),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(new Set),x=(0,o.useRef)(null),g=(0,o.useCallback)((e,t)=>{h(r=>{let n=new Set(r);return t?n.add(e):n.delete(e),n})},[]);return((0,o.useEffect)(()=>{let t=x.current!==e;x.current=e,t&&h(new Set),d(t),u(null),N(e).then(e=>s(e)).catch(e=>u(e instanceof Error?e.message:String(e))).finally(()=>d(!1))},[e,r]),a)?(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."}):c?(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:c}):(0,n.jsxs)("div",{style:{padding:"2px 4px"},children:[l.map(o=>(0,n.jsx)(O,{node:o,depth:0,cwd:e,onOpenFile:t,onAtMention:i,expandedPaths:p,onToggleExpanded:g,refreshKey:r},o.fullPath)),0===l.length&&(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"No files found"})]})}var _=r(47650);let U=(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("path",{d:"M1.5 4.5h4l1.2 1.4h8v7.6h-13.2z"})}),K=(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--text-muted)"},children:[(0,n.jsx)("rect",{x:"1.5",y:"4.5",width:"13",height:"8",rx:"1"}),(0,n.jsx)("circle",{cx:"11.5",cy:"8.5",r:"0.9",fill:"currentColor",stroke:"none"}),(0,n.jsx)("path",{d:"M1.5 7h13"})]}),q=(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M8 12V4M4 8l4-4 4 4"})}),V=(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M2 2l8 8M10 2l-8 8"})});function Y({initialPath:e,onSelect:t,onClose:r}){let[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)([]),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(!0),[h,x]=(0,o.useState)(null),g=(0,o.useRef)(null),f=(0,o.useCallback)(async e=>{p(!0),x(null);try{let t=await fetch(`/api/directories/list?path=${encodeURIComponent(e)}`),r=await t.json().catch(()=>({}));if(!t.ok||r.error)return void x(r.error??`HTTP ${t.status}`);l(r.path),c(r.parent),a(r.entries)}catch(e){x(e instanceof Error?e.message:String(e))}finally{p(!1)}},[]);(0,o.useEffect)(()=>{f(e?e.replace(/\\/g,"/"):"")},[f,e]);let m=(0,o.useCallback)(()=>{null!==d&&f(d)},[d,f]),v=(0,o.useCallback)(e=>{f(e)},[f]),y=(0,o.useCallback)(()=>{i&&t(i)},[i,t]);return((0,o.useEffect)(()=>{let e=e=>{if("Escape"===e.key)e.preventDefault(),r();else if("Enter"===e.key)e.preventDefault(),y();else if("Backspace"===e.key){let t=e.target;if(t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName))return;e.preventDefault(),m()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[r,y,m]),"u"<typeof document)?null:(0,_.createPortal)((0,n.jsx)("div",{onClick:r,style:{position:"fixed",inset:0,zIndex:200,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.32)"},children:(0,n.jsxs)("div",{onClick:e=>e.stopPropagation(),role:"dialog","aria-modal":"true",style:{width:"min(960px, calc(100vw - 48px))",height:"min(760px, calc(100vh - 48px))",display:"flex",flexDirection:"column",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg)",boxShadow:"0 24px 70px rgba(0,0,0,0.34)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"9px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{onClick:m,disabled:null===d||u,title:"Parent directory (Backspace)",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",cursor:null===d||u?"not-allowed":"pointer",opacity:null===d||u?.4:1},children:q}),(0,n.jsx)("div",{title:i,style:{flex:1,fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i||"This PC"}),(0,n.jsx)("button",{onClick:r,title:"Close (Esc)",style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,borderRadius:6,border:"none",background:"none",color:"var(--text-muted)",cursor:"pointer"},children:V})]}),(0,n.jsx)("div",{ref:g,style:{flex:1,minHeight:0,overflow:"auto",background:"var(--bg)",padding:8,display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(220px, 1fr))",gap:4,alignContent:"start"},children:u?(0,n.jsx)("div",{style:{padding:20,color:"var(--text-muted)",fontSize:13,gridColumn:"1 / -1"},children:"Loading…"}):h?(0,n.jsx)("div",{style:{padding:20,color:"#dc2626",fontSize:13,overflowWrap:"anywhere",gridColumn:"1 / -1"},children:h}):0===s.length?(0,n.jsx)("div",{style:{padding:20,color:"var(--text-muted)",fontSize:13,gridColumn:"1 / -1"},children:"No sub-directories. Use “Select this directory” to pick the current folder."}):s.map(e=>(0,n.jsxs)("button",{onClick:()=>v(e.fullPath),title:`${e.name}
2
+ ${e.fullPath}
3
+
4
+ Click to open`,style:{display:"flex",alignItems:"center",gap:9,width:"100%",padding:"8px 12px",border:"1px solid transparent",borderRadius:6,background:"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:13},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[/^[A-Z]:$/.test(e.name)?K:U,(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.fullPath))}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"10px 12px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{flex:1,minWidth:0,fontSize:11,color:"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i?(0,n.jsxs)("span",{children:["Open: ",(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:i})]}):(0,n.jsx)("span",{children:"Pick a drive to browse"})}),(0,n.jsx)("button",{onClick:r,style:{padding:"6px 14px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{onClick:y,disabled:!i||u,title:"Select the current directory (Enter)",style:{padding:"6px 16px",borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",fontWeight:600,cursor:!i||u?"not-allowed":"pointer",fontSize:12,opacity:!i||u?.55:1},children:"Select"})]})]})}),document.body)}let J="pi-web:unread-session-ids";function Z(e){let t=new Map;for(let r of e){let e=r.projectRoot??r.cwd;if(!e)continue;let n=t.get(e);(!n||r.modified>n)&&t.set(e,r.modified)}return[...t.entries()].sort((e,t)=>t[1].localeCompare(e[1])).map(([e])=>e)}function X(e,t){return t&&e.startsWith(t)?"~"+e.slice(t.length):e}function G({text:e,style:t}){return(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",minWidth:0,lineHeight:1.35,direction:"rtl",textAlign:"left",...t},children:(0,n.jsx)("span",{style:{unicodeBidi:"plaintext"},children:e})})}function Q({open:e,children:t,style:r}){let[i,l]=(0,o.useState)(e),[s,a]=(0,o.useState)(e);return((0,o.useEffect)(()=>{let t,r;return e?(l(!0),a(!1),t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>a(!0))})):(a(!1),r=setTimeout(()=>l(!1),140)),()=>{void 0!==t&&window.cancelAnimationFrame(t),r&&clearTimeout(r)}},[e]),i)?(0,n.jsx)("div",{style:{...r,opacity:+!!s,transform:s?"translateY(0) scale(1)":"translateY(-8px) scale(0.96)",transformOrigin:"top center",transition:"opacity 140ms ease, transform 140ms ease",pointerEvents:e?"auto":"none"},children:t}):null}let ee="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function et(){let[e,t]=(0,o.useState)(!1),[r,i]=(0,o.useState)(!1),l=(0,o.useRef)(null),s=function(e,t){let[r,n]=(0,o.useState)(e),i=(0,o.useRef)(null),l=(0,o.useRef)(0);return(0,o.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,o=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:ee[Math.floor(Math.random()*ee.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"0.8.0p0.80.6":"Pi Agent Web",r),a=(0,o.useCallback)(e=>{t(e),i(!0),setTimeout(()=>i(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,o.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,o.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:"6ch"},children:s})}function er({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:i,onInitialRestoreDone:l,refreshKey:s,onSessionDeleted:a,selectedCwd:d,onCwdChange:c,onOpenFile:u,explorerRefreshKey:p,onAtMention:h}){let[x,g]=(0,o.useState)([]),[f,m]=(0,o.useState)(!0),[v,y]=(0,o.useState)(null),[b,k]=(0,o.useState)(null),[j,w]=(0,o.useState)(""),[S,C]=(0,o.useState)(!1),[T,L]=(0,o.useState)(""),[I,z]=(0,o.useState)(!1),[R,W]=(0,o.useState)(""),[M,E]=(0,o.useState)(null),[$,B]=(0,o.useState)(!1),A=(0,o.useRef)(null),[D,P]=(0,o.useState)(!1),F=(0,o.useRef)(!1);F.current=D;let N=(0,o.useRef)(null),[O,_]=(0,o.useState)(null),[U,K]=(0,o.useState)(!1),[q,V]=(0,o.useState)(!1),[ee,eo]=(0,o.useState)(""),[ei,el]=(0,o.useState)(null),[es,ea]=(0,o.useState)(!1),[ed,ec]=(0,o.useState)(null),[eu,ep]=(0,o.useState)(null),eh=(0,o.useRef)(null),ex=(0,o.useRef)(null),[eg,ef]=(0,o.useState)(!0),[em,ev]=(0,o.useState)(0),[ey,eb]=(0,o.useState)(!1),[ek,ej]=(0,o.useState)(!1),[ew,eS]=(0,o.useState)(()=>new Set),[eC,eT]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(J);if(!e)return new Set;let t=JSON.parse(e);if(Array.isArray(t))return new Set(t.filter(e=>"string"==typeof e));return new Set}catch{return new Set}})()),eL=(0,o.useRef)(new Set),eI=(0,o.useRef)(!1),ez=(0,o.useRef)(null),eR=(0,o.useRef)(null),eW=(0,o.useCallback)(async(e=!1)=>{try{e&&m(!0);let t=await fetch("/api/sessions");if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();g(r.sessions),eI.current||eS(new Set(r.runningSessionIds??[]));let n=new Set(r.sessions.map(e=>e.id));eT(e=>{if(0===e.size)return e;let t=new Set([...e].filter(e=>n.has(e)));return t.size===e.size?e:t}),y(null),e||(eb(!0),ez.current&&clearTimeout(ez.current),ez.current=setTimeout(()=>eb(!1),2e3))}catch(e){y(String(e))}finally{e&&m(!1)}},[]),eM=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!eM.current;eM.current=!0,eW(e)},[eW,s]),(0,o.useEffect)(()=>{try{0===eC.size?window.localStorage.removeItem(J):window.localStorage.setItem(J,JSON.stringify([...eC]))}catch{}},[eC]),(0,o.useEffect)(()=>{let e=new EventSource("/api/agent/running/events");return e.onmessage=e=>{try{let t=JSON.parse(e.data);"running"===t.type&&(eI.current=!0,eS(new Set(t.runningSessionIds??[])))}catch{}},()=>e.close()},[]),(0,o.useEffect)(()=>{let t=[...eL.current].filter(t=>!ew.has(t)&&t!==e),r=[...ew];(t.length>0||r.length>0)&&eT(e=>{let n=new Set(e);return r.forEach(e=>n.delete(e)),t.forEach(e=>n.add(e)),n}),eL.current=ew},[ew,e]),(0,o.useEffect)(()=>{e&&eT(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),r})},[e]),(0,o.useEffect)(()=>{void 0!==p&&ev(e=>e+1)},[p]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&w(e.home)}).catch(()=>{})},[]);let eE=(0,o.useRef)(!1),e$=(0,o.useCallback)(e=>{if(!e)return null;if(O&&O.forCwd===e||O?.worktrees.some(t=>t.path===e))return O.projectRoot;let t=x.find(t=>t.cwd===e);return t?.projectRoot??e},[O,x]),eB=(0,o.useRef)(null);(0,o.useEffect)(()=>{eB.current!==b&&(eB.current=b,c?.(b,e$(b)))},[b,c,e$]);let eA=(0,o.useRef)(null);(0,o.useEffect)(()=>{d&&d!==eA.current&&(eA.current=d,k(d))},[d]);let[eD,eP]=(0,o.useState)(0);(0,o.useLayoutEffect)(()=>{if(!b){_(null),ep(null);return}let e=!1;return ep(b),fetch(`/api/worktrees?cwd=${encodeURIComponent(b)}`).then(e=>e.json()).then(t=>{if(!e){if(ep(null),t.error||!t.projectRoot)return void _(null);_({forCwd:b,projectRoot:t.projectRoot,isGit:t.isGit??!1,isTopLevel:t.isTopLevel??!1,worktrees:t.worktrees??[]})}}).catch(()=>{e||(ep(null),_(null))}),()=>{e=!0}},[b,eD,s]),(0,o.useEffect)(()=>{if(0!==x.length&&null===b){if(i&&!eE.current){eE.current=!0;let e=x.find(e=>e.id===i);if(e){k(e.cwd),t(e,!0);return}l?.()}let e=Z(x);e.length>0&&k(e[0])}},[x,b,i,t,l]);let eF=(0,o.useCallback)(async()=>{let e=R.trim();if(e&&!$){B(!0),E(null);try{let t=await fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e})}),r=await t.json().catch(()=>({}));if(!t.ok||r.error)return void E(r.error??`HTTP ${t.status}`);k(r.cwd??e),z(!1),W(""),C(!1)}catch(e){E(e instanceof Error?e.message:String(e))}finally{B(!1)}}},[R,$]),eN=(0,o.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&(k(t.cwd),z(!1),W(""),E(null),C(!1))}catch{}},[]),eO=(0,o.useCallback)(async()=>{let e=ee.trim();if(e&&!es&&O){ea(!0),el(null);try{let t=await fetch("/api/worktrees",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:O.projectRoot,branch:e})}),r=await t.json().catch(()=>({}));if(!t.ok||r.error||!r.path)return void el(r.error??`HTTP ${t.status}`);V(!1),eo(""),K(!1),_(t=>t?{...t,forCwd:r.path,worktrees:[...t.worktrees,{path:r.path,branch:e,isMain:!1}]}:t),k(r.path),eP(e=>e+1)}catch(e){el(e instanceof Error?e.message:String(e))}finally{ea(!1)}}},[ee,es,O]),eH=(0,o.useCallback)(async(e,t)=>{if(O&&!es){ea(!0),el(null);try{let r=await fetch("/api/worktrees",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:O.projectRoot,path:e,force:t})}),n=await r.json().catch(()=>({}));if(!r.ok){if(n.dirty&&!t)return void ec(e);el(n.error??`HTTP ${r.status}`);return}ec(null),b===e&&k(O.projectRoot),eP(e=>e+1)}catch(e){el(e instanceof Error?e.message:String(e))}finally{ea(!1)}}},[O,es,b]);(0,o.useEffect)(()=>{let e=e=>{F.current||(N.current&&!N.current.contains(e.target)&&(C(!1),L(""),z(!1),W(""),E(null)),eh.current&&!eh.current.contains(e.target)&&(K(!1),V(!1),eo(""),el(null),ec(null)))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let e_=(0,o.useCallback)(e=>{e.cwd&&k(e.cwd),t(e)},[t]),eU=(0,o.useCallback)(()=>{if(!b)return;let e="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;r?.(e,b)},[b,r]),eK=Z(x),eq=eK.length>8,eV=T.trim()?eK.filter(e=>e.toLowerCase().includes(T.trim().toLowerCase())):eK,eY=e$(b),eJ=eY?x.filter(e=>(e.projectRoot??e.cwd)===eY):x,eZ=!!(O?.isGit&&O.isTopLevel&&b&&eY===O.projectRoot),eX=b&&O&&eY===O.projectRoot&&!eZ?O.isGit?{label:"Open repo root",title:"Open the repository root to manage worktrees."}:{label:"Git repo root only",title:"Worktrees are available in Git repository roots."}:null,eG=!!(b&&eu===b),eQ=eX??(eG&&!eZ?{label:"Worktrees...",title:"Checking worktrees for this directory."}:null),e0=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 o=function(e){let n=r.get(e),o=new Set;for(;n&&!o.has(n);){if(o.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);o?t.get(o).children.push(e):n.push(e)}let o=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>o(e.children))};return o(n),n}(eJ);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("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",marginBottom:10},children:[(0,n.jsx)(et,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsxs)("button",{onClick:eU,disabled:!b,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:b?"var(--text-muted)":"var(--text-dim)",cursor:b?"pointer":"not-allowed",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:b?`New session in ${b}`:"Select a project first",onMouseEnter:e=>{b&&(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=b?"var(--text-muted)":"var(--text-dim)",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"]}),(0,n.jsx)("button",{onClick:()=>eW(!1),style:{display:"flex",alignItems:"center",justifyContent:"center",background:ey?"rgba(74,222,128,0.18)":"var(--bg-hover)",border:`1px solid ${ey?"rgba(74,222,128,0.4)":"var(--border)"}`,color:ey?"#4ade80":"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.3s, color 0.3s, border-color 0.3s"},onMouseEnter:e=>{ey||(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=>{ey||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)")},title:"Refresh",children:ey?(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(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 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"})]})})]})]}),(0,n.jsxs)("div",{ref:N,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>C(e=>!e),title:eY??b??"",style:{width:"100%",display:"flex",alignItems:"center",padding:"6px 10px",background:b?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:b?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left",transition:"border-color 0.15s, background 0.15s"},children:b?(0,n.jsx)(G,{text:X(eY??b,j),style:{flex:1,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text)"}}):(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:i&&!eE.current?"":"Select project…"})}),(0,n.jsxs)(Q,{open:S,style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden"},children:[eq&&(0,n.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,n.jsx)("input",{value:T,onChange:e=>L(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(L(""),C(!1))},placeholder:"Filter projects…",autoFocus:!0,style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}})}),(0,n.jsxs)("div",{style:{maxHeight:"min(50vh, 380px)",overflowY:"auto"},children:[eV.map(e=>(0,n.jsxs)("button",{onClick:()=>{k(e),L(""),z(!1),W(""),E(null),C(!1)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"var(--bg)",border:"none",borderBottom:"1px solid var(--border)",color:e===eY?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:[e===eY&&(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"})}),e!==eY&&(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)(G,{text:X(e,j),style:{flex:1}})]},e)),0===eV.length&&T.trim()&&(0,n.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:"No matching projects"})]}),!I&&(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),eN()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eV.length>0?"1px solid var(--border)":"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("path",{d:"M1 3A1 1 0 0 1 2 2H4L5 3.5H8.5a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5h-7A.5.5 0 0 1 1 8V3Z"})}),(0,n.jsx)("span",{children:"Use default directory"})]}),I?(0,n.jsxs)("div",{style:{padding:"6px 8px",borderTop:eV.length>0?"none":void 0},children:[(0,n.jsx)("input",{ref:A,value:R,onChange:e=>{W(e.target.value),E(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),eF()),"Escape"===e.key&&(z(!1),W(""),E(null))},placeholder:"/path/to/project",style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}}),M&&(0,n.jsx)("div",{style:{marginTop:5,color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:M}),(0,n.jsxs)("button",{onClick:()=>P(!0),style:{display:"flex",alignItems:"center",gap:6,marginTop:6,padding:"4px 0",background:"none",border:"none",color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:500},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",style:{flexShrink:0},children:(0,n.jsx)("path",{d:"M1.5 2.5h2l1 1.2h4v3.8h-7z"})}),"Browse…"]}),D&&(0,n.jsx)(Y,{initialPath:R.trim()||null,onSelect:e=>{W(e),E(null),P(!1)},onClose:()=>P(!1)}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,marginTop:5},children:[(0,n.jsx)("button",{onClick:()=>void eF(),disabled:$||!R.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:$||!R.trim()?"not-allowed":"pointer",opacity:$||!R.trim()?.65:1},children:$?"Checking…":"Open"}),(0,n.jsx)("button",{onClick:()=>{z(!1),W(""),E(null)},style:{flex:1,padding:"4px 0",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer"},children:"Cancel"})]})]}):(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),z(!0),E(null),setTimeout(()=>A.current?.focus(),0)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,n.jsx)("span",{children:"Custom path…"})]})]})]}),eZ&&(()=>{if(!O)return null;let e=O.worktrees.find(e=>e.path===b)??O.worktrees.find(e=>e.isMain);return(0,n.jsxs)("div",{ref:eh,style:{position:"relative",marginTop:6},children:[(0,n.jsxs)("button",{onClick:()=>K(e=>!e),title:e?`Switch worktree: ${e.path}`:"Switch worktree",style:{width:"100%",height:29,boxSizing:"border-box",display:"flex",alignItems:"center",gap:6,padding:"0 10px",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,cursor:"pointer",fontSize:11,lineHeight:1.35,color:"var(--text-muted)",textAlign:"left"},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,color:e&&!e.isMain?"var(--accent)":"var(--text-dim)"},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,n.jsx)(G,{text:e?e.branch??X(e.path,j):"…",style:{flex:1,fontFamily:"var(--font-mono)",color:"var(--text)"}}),e?.isMain&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:"main"}),O.worktrees.length>1&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:O.worktrees.length}),(0,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),(0,n.jsxs)(Q,{open:U,style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{maxHeight:"min(40vh, 300px)",overflowY:"auto"},children:O.worktrees.map(e=>{let t=e.path===b||e.isMain&&!O.worktrees.some(e=>e.path===b);return ed===e.path?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"rgba(239,68,68,0.06)"},children:[(0,n.jsx)("span",{style:{flex:1,fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"Uncommitted changes. Force remove checkout?"}),(0,n.jsx)("button",{onClick:()=>void eH(e.path,!0),disabled:es,style:{padding:"3px 9px",background:"#ef4444",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:"pointer",flexShrink:0},children:"Force"}),(0,n.jsx)("button",{onClick:()=>ec(null),style:{padding:"3px 9px",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer",flexShrink:0},children:"Cancel"})]},e.path):(0,n.jsxs)("div",{className:"wt-row",style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{onClick:()=>{k(e.path),K(!1),el(null)},title:e.path,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px",background:"var(--bg)",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},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)(G,{text:e.branch??X(e.path,j),style:{flex:1}}),e.isMain&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:"main"})]}),!e.isMain&&(0,n.jsx)("button",{onClick:()=>void eH(e.path,!1),disabled:es,title:`Remove worktree checkout ${e.path}; the branch is kept`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:34,height:28,padding:0,marginRight:4,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="#ef4444",e.currentTarget.style.background="rgba(239,68,68,0.08)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},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"})]})})]},e.path)})}),q?(0,n.jsxs)("div",{style:{padding:"6px 8px"},children:[(0,n.jsx)("input",{ref:ex,value:ee,onChange:e=>{eo(e.target.value),el(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),eO()),"Escape"===e.key&&(V(!1),eo(""),el(null))},placeholder:"branch name",style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,marginTop:5},children:[(0,n.jsx)("button",{onClick:()=>void eO(),disabled:es||!ee.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:es||!ee.trim()?"not-allowed":"pointer",opacity:es||!ee.trim()?.65:1},children:es?"Creating…":"Create"}),(0,n.jsx)("button",{onClick:()=>{V(!1),eo(""),el(null)},style:{flex:1,padding:"4px 0",background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer"},children:"Cancel"})]})]}):(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),V(!0),el(null),setTimeout(()=>ex.current?.focus(),0)},title:"Create a worktree checkout for a branch",style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,n.jsx)("span",{children:"New worktree…"})]}),ei&&(0,n.jsx)("div",{style:{padding:"5px 10px 8px",color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:ei})]})]})})(),eQ&&(0,n.jsxs)("button",{type:"button","aria-disabled":"true",tabIndex:-1,title:eQ.title,style:{width:"100%",height:29,boxSizing:"border-box",marginTop:6,display:"flex",alignItems:"center",gap:6,padding:"0 10px",border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-hover)",color:"var(--text-dim)",fontSize:11,lineHeight:1.35,whiteSpace:"nowrap",textAlign:"left",cursor:"default",opacity:.82},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)("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,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:eQ.label})]})]}),(0,n.jsxs)("div",{style:{flex:eg&&(d||b)?"1 1 0":"1 1 auto",overflowY:"auto",padding:"0",minHeight:80},children:[f&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),v&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:v}),!f&&!v&&0===eJ.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"No sessions found"}),e0.map(t=>(0,n.jsx)(en,{node:t,selectedSessionId:e,runningSessionIds:ew,unreadSessionIds:eC,onSelectSession:e_,onRenamed:eW,onSessionDeleted:e=>{a?.(e),eW()},depth:0},t.session.id))]}),(d||b)&&(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border)",display:"flex",flexDirection:"column",flex:eg?"1 1 0":"0 0 auto",minHeight:0,overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0},children:[(0,n.jsxs)("button",{onClick:()=>ef(e=>!e),style:{display:"flex",alignItems:"center",gap:6,flex:1,padding:"6px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",textAlign:"left"},children:[(0,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:eg?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),"Explorer"]}),(0,n.jsx)("button",{onClick:()=>{ev(e=>e+1),ej(!0),eR.current&&clearTimeout(eR.current),eR.current=setTimeout(()=>ej(!1),2e3)},title:"Refresh explorer",style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,marginRight:6,background:ek?"rgba(74,222,128,0.18)":"none",border:"none",color:ek?"#4ade80":"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{ek||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{ek||(e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none")},children:ek?(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(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 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"})]})})]}),eg&&(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",overflowX:"hidden"},children:(0,n.jsx)(H,{cwd:b??d,onOpenFile:u??(()=>{}),refreshKey:em,onAtMention:h})})]})]})}function en({node:e,selectedSessionId:t,runningSessionIds:r,unreadSessionIds:i,onSelectSession:l,onRenamed:s,onSessionDeleted:a,depth:d}){let[c,u]=(0,o.useState)(!1),p=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[d>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*d+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(el,{session:e.session,isSelected:e.session.id===t,isRunning:r.has(e.session.id),isUnread:i.has(e.session.id),onClick:()=>l(e.session),onRenamed:s,onDeleted:e=>a?.(e),depth:d,hasChildren:p,collapsed:c,onToggleCollapse:()=>u(e=>!e)})]}),p&&!c&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(en,{node:e,selectedSessionId:t,runningSessionIds:r,unreadSessionIds:i,onSelectSession:l,onRenamed:s,onSessionDeleted:a,depth:d+1},e.session.id))})]})}function eo(){return(0,n.jsx)("span",{title:"Agent running…","aria-label":"Agent running",style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block"},children:(0,n.jsxs)("g",{children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-3.8-7.4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"}),(0,n.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})]})})})}function ei(){return(0,n.jsx)("span",{title:"New activity","aria-label":"New session activity",style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"#0891b2"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",style:{display:"block"},children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"2.5",fill:"currentColor"}),(0,n.jsxs)("circle",{cx:"7",cy:"7",r:"3",stroke:"currentColor",strokeWidth:"1.4",opacity:"0.32",children:[(0,n.jsx)("animate",{attributeName:"r",values:"3;6;3",dur:"1.6s",repeatCount:"indefinite"}),(0,n.jsx)("animate",{attributeName:"opacity",values:"0.32;0;0.32",dur:"1.6s",repeatCount:"indefinite"})]})]})})}function el({session:e,isSelected:t,isRunning:r,isUnread:i,onClick:l,onRenamed:s,onDeleted:a,depth:d=0,hasChildren:c=!1,collapsed:u=!1,onToggleCollapse:p}){let h,x,g,f,m,[v,y]=(0,o.useState)(!1),[b,k]=(0,o.useState)(!1),[j,w]=(0,o.useState)(""),[S,C]=(0,o.useState)(!1),[T,L]=(0,o.useState)(!1),I=(0,o.useRef)(null),z=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),R=(0,o.useCallback)(t=>{t.stopPropagation(),w(e.name??""),k(!0),setTimeout(()=>I.current?.select(),0)},[e.name]),W=(0,o.useCallback)(async()=>{let t=j.trim();if(k(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),s?.()}catch{}},[j,e.id,e.name,s]),M=(0,o.useCallback)(e=>{e.stopPropagation(),C(!0)},[]),E=(0,o.useCallback)(async t=>{t.stopPropagation(),C(!1),L(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),a?.(e.id)}catch{L(!1)}},[e.id,a]),$=(0,o.useCallback)(e=>{e.stopPropagation(),C(!1)},[]);return(0,n.jsx)("div",{onClick:S||b?void 0:l,onMouseEnter:()=>y(!0),onMouseLeave:()=>{y(!1)},style:{height:54,display:"flex",alignItems:"center",paddingLeft:d>0?12*d+14:14,paddingRight:8,cursor:S||b?"default":"pointer",background:S?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":v?"var(--bg-hover)":"transparent",borderLeft:S?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:T?.5:1,gap:6,overflow:"hidden"},children:S?(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:["“",z.slice(0,22),z.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:E,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:$,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"})]})]}):b?(0,n.jsx)("input",{ref:I,value:j,onChange:e=>w(e.target.value),onBlur:W,onKeyDown:e=>{"Enter"===e.key&&W(),"Escape"===e.key&&k(!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:30}}):(0,n.jsxs)(n.Fragment,{children:[d>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,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,minWidth:0,fontSize:12,fontWeight:t?500:400,lineHeight:1.4,color:"var(--text)"},title:r?`${z} \xb7 Agent running…`:i?`${z} \xb7 New activity`:z,children:[r?(0,n.jsx)(eo,{}):i?(0,n.jsx)(ei,{}):null,(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:z})]}),(0,n.jsxs)("div",{style:{marginTop:2,display:"flex",gap:8,color:"var(--text-dim)",fontSize:11,minWidth:0},children:[(0,n.jsx)("span",{title:e.modified,children:(h=new Date(e.modified),g=Math.floor((x=new Date().getTime()-h.getTime())/6e4),f=Math.floor(x/36e5),m=Math.floor(x/864e5),g<1?"just now":g<60?`${g}m ago`:f<24?`${f}h ago`:m<7?`${m}d ago`:h.toLocaleDateString())}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]}),e.worktreeBranch&&(0,n.jsxs)("span",{title:`Worktree: ${e.cwd}`,style:{display:"flex",alignItems:"center",gap:3,color:"var(--accent)",minWidth:0,overflow:"hidden"},children:[(0,n.jsxs)("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",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,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.worktreeBranch})]})]})]}),c&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),p?.()},title:u?"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:u?"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"})})}),v&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:R,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",flexShrink:0,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:M,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",flexShrink:0,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"})]})})]})]})})}let es=/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/g,ea=/^\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/,ed=/\x1B\[([0-9;]*)m/g,ec=["#1f2937","#dc2626","#16a34a","#d97706","#2563eb","#9333ea","#0891b2","#6b7280"],eu=["#9ca3af","#ef4444","#22c55e","#f59e0b","#3b82f6","#a855f7","#06b6d4","#e5e7eb"];function ep(e){return e.replace(es,"")}function eh(e){let t=[],r=0;for(;r<e.length;){if(27===e.charCodeAt(r)){let t=e.slice(r).match(ea);if(t){r+=t[0].length;continue}}let n=e.codePointAt(r);if(void 0===n)break;let o=String.fromCodePoint(n);t.push({start:r,end:r+o.length,char:o}),r+=o.length}return t}function ex(e,t){let r=eh(e)[t];return r?e.slice(0,r.start)+e.slice(r.end):e}function eg(e){return eh(e)[0]?.char}function ef(e,t={}){return"thinking"===e.type&&!t.isStreaming&&""===e.thinking.trim()}function em(e,t={}){return(e.content??[]).filter(e=>!ef(e,t))}function ev(e,t={}){let r=em(e,t),n=r.findLastIndex(e=>"text"!==e.type&&"image"!==e.type);return -1===n?{answerBlocks:r,processBlocks:[]}:{answerBlocks:r.slice(n+1),processBlocks:r.slice(0,n+1)}}function ey(e){return e.filter(e=>"toolCall"===e.type).length}var eb=r(32316),ek=r(16764),ej=r(7644);let ew=new Set;function eS(e){return ew.add(e),()=>{ew.delete(e)}}function eC(){return"u"<typeof document?"light":document.documentElement.classList.contains("dark")?"dark":"light"}function eT(){return"light"}function eL(){let e=(0,o.useSyncExternalStore)(eS,eC,eT);return{theme:e,toggleTheme:(0,o.useCallback)(e=>{let t="dark"===eC()?"light":"dark",r=()=>{"dark"===t?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark");try{localStorage.setItem("pi-theme",t)}catch{}ew.forEach(e=>e())},n=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;if("function"!=typeof document.startViewTransition||n)return void r();let o=e?.x??window.innerWidth/2,i=e?.y??window.innerHeight/2,l=Math.hypot(Math.max(o,window.innerWidth-o),Math.max(i,window.innerHeight-i));document.startViewTransition(r).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${o}px ${i}px)`,`circle(${l}px at ${o}px ${i}px)`]},{duration:450,easing:"cubic-bezier(0.22, 0.61, 0.36, 1)",pseudoElement:"::view-transition-new(root)"})}).catch(()=>{})},[]),isDark:"dark"===e}}function eI(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);try{let t=document.createElement("textarea");return t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),Promise.resolve()}catch{return Promise.reject()}}function ez(e){try{return decodeURIComponent(e)}catch{return e}}function eR(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function eW(e){let t=eR(e),r=/^[a-zA-Z]:\//.test(t),n=t.startsWith("//"),o=t.startsWith("/")&&!r&&!n,i=[];for(let e of t.split("/"))if(e&&"."!==e){if(".."===e){i.length>0&&".."!==i[i.length-1]?i.pop():o||r||n||i.push(e);continue}i.push(e)}let l=i.join("/");return r?l:n?`//${l}`:o?`/${l}`:l}var eM=r(88374),eE=r(5924),e$=r(94764),eB=r(63835),eA=r(84678),eD=r(98164);let eP={...e$.j,attributes:{...e$.j.attributes,code:[["className",/^language-./,"math-inline","math-display"]]},strip:[...e$.j.strip||[],"iframe","object","style","form"]},eF=[eA.A,eD.A],eN=[eA.A],eO=[eE.A,[eB.A,eP],[eM.A,{throwOnError:!1,strict:!1}]],eH=[eE.A,[eB.A,eP]];function e_({children:e,className:t,isStreaming:r,cwd:i,onOpenFile:l}){let s=(0,o.useMemo)(()=>{var t;let r,n,o;return r=(t=e).includes("\r\n")?"\r\n":"\n",n=t.split(/\r?\n/),o=null,n.map(e=>{let t=e.match(/^ {0,3}(`{3,}|~{3,})/);if(t){let r=t[1][0],n=t[1].length;return o?r===o.marker&&n>=o.size&&(o=null):o={marker:r,size:n},e}if(o)return e;let n=e.match(/^([ \t]{0,3})\$\$(.+)\$\$[ \t]*$/);if(!n)return e;let i=n[2].trim();return i?`${n[1]}$$${r}${i}${r}${n[1]}$$`:e}).join(r)},[e]);return(0,n.jsx)("div",{className:["markdown-body",t].filter(Boolean).join(" "),children:(0,n.jsx)(eb.oz,{remarkPlugins:eF,rehypePlugins:eO,components:{code({className:e,children:t,...o}){let i=e?.replace("language-","").toLowerCase()??"",l=String(t);return e?.includes("language-")||l.includes("\n")?"mermaid"===i?(0,n.jsx)(eU,{code:l.replace(/\n$/,""),isStreaming:r}):(0,n.jsx)(eK,{code:l.replace(/\n$/,""),lang:i}):(0,n.jsx)("code",{className:"markdown-inline-code",...o,children:t})},pre:({children:e})=>(0,n.jsx)(n.Fragment,{children:e}),a({href:e,children:t,...r}){let o=l?function(e,t){let r,n,o,i,l;if(!e)return null;let s=e.split("#",1)[0].split("?",1)[0].trim();if(!s)return null;let a=null,d=null,c=ez(s),u=c.startsWith("\\\\"),p=eR(c),h=p.toLowerCase();if(h.startsWith("/api/")||h.startsWith("/_next/")||!u&&p.startsWith("//")||/^[a-zA-Z][a-zA-Z0-9+.-]*:/i.test(p)&&!h.startsWith("file:")&&!/^[a-zA-Z]:\//.test(p))return null;if(h.startsWith("file:")?d=(a=function(e){try{let t=new URL(e);if("file:"!==t.protocol)return null;let r=ez(t.pathname);if(t.hostname)return`//${t.hostname}${r.startsWith("/")?r:`/${r}`}`;if(/^\/[a-zA-Z]:\//.test(r))return r.slice(1);return r}catch{return null}}(p))?"absolute":null:/^[a-zA-Z]:\//.test(p)||p.startsWith("/")?(a=p,d="absolute"):t&&!(p.startsWith("#")||p.startsWith("?"))&&(p.startsWith("./")||p.startsWith("../")||p.includes("/")||/(^|\/)\.?[^/]+\.[^/.]+$/.test(p))&&(a=`${eR(t).replace(/\/+$/,"")}/${p}`,d="relative"),!a)return null;let x=eW(a).replace(/:\d+(?::\d+)?$/,"");return"relative"===d&&t&&(r=eW(x).replace(/\/+$/,""),n=eW(t).replace(/\/+$/,""),i=(o=/^[a-zA-Z]:\//.test(r)||/^[a-zA-Z]:\//.test(n))?r.toLowerCase():r,!(i===(l=o?n.toLowerCase():n)||i.startsWith(`${l}/`)))?null:x}(e,i):null;return o&&l?(0,n.jsx)("a",{href:e,...r,onClick:e=>{if(e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.currentTarget.getAttribute("target");t&&"_self"!==t||(e.preventDefault(),l(o))},children:t}):(0,n.jsx)("a",{href:e,...r,children:t})},table:({children:e})=>(0,n.jsx)("div",{className:"markdown-table-wrap",children:(0,n.jsx)("table",{children:e})})},children:s})})}function eU({code:e,isStreaming:t}){let{isDark:i}=eL(),[l,s]=(0,o.useState)(!1),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)(null),x=`${i?"dark":"light"}
5
+ ${e}`;(0,o.useEffect)(()=>{if(!l||t)return;let n=!1;return h(null),(async()=>{let{default:t}=await Promise.all([r.e(5958),r.e(3716),r.e(1812)]).then(r.bind(r,28776));if(t.initialize({startOnLoad:!1,securityLevel:"strict",suppressErrorRendering:!0,theme:i?"dark":"default"}),!await t.parse(e,{suppressErrors:!0}))throw Error("Invalid Mermaid diagram");let o="u">typeof crypto&&"randomUUID"in crypto?`mermaid-${crypto.randomUUID()}`:`mermaid-${Date.now()}-${Math.random().toString(36).slice(2)}`,l=await t.render(o,e);n||(d(l.svg),u(x))})().catch(()=>{n||h(x)}),()=>{n=!0}},[e,x,i,t,l]);let g=(0,n.jsx)("button",{onClick:()=>s(e=>!e),disabled:t,title:t?"Preview available after streaming":l?"Show Mermaid source":"Preview Mermaid diagram",className:["markdown-code-action",l?"is-active":""].filter(Boolean).join(" "),children:l?"Source":"Preview"});if(!l||t)return(0,n.jsx)(eK,{code:e,lang:"mermaid",headerAction:g});let f=p===x?(0,n.jsx)("div",{className:"mermaid-block mermaid-block-error",children:"Invalid Mermaid diagram"}):a&&c===x?(0,n.jsx)("div",{className:"mermaid-block",dangerouslySetInnerHTML:{__html:a}}):(0,n.jsx)("div",{className:"mermaid-block mermaid-block-loading","aria-label":"Rendering Mermaid diagram"});return(0,n.jsxs)("div",{className:"markdown-code-block",children:[(0,n.jsxs)("div",{className:"markdown-code-header",children:[(0,n.jsx)("span",{className:"markdown-code-lang",children:"mermaid"}),g]}),f]})}function eK({code:e,lang:t,headerAction:r}){let{isDark:i}=eL(),[l,s]=(0,o.useState)(!1);return(0,n.jsxs)("div",{className:"markdown-code-block",children:[(0,n.jsxs)("div",{className:"markdown-code-header",children:[(0,n.jsx)("span",{className:"markdown-code-lang",children:t||"text"}),(0,n.jsxs)("div",{className:"markdown-code-actions",children:[r,(0,n.jsx)("button",{onClick:()=>{eI(e).then(()=>{s(!0),setTimeout(()=>s(!1),1500)})},className:"markdown-code-action",children:l?"copied":"copy"})]})]}),(0,n.jsx)(ek.A,{language:t||"text",style:i?ej.xJ:ej.vs,showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal"},customStyle:{margin:0,padding:"11px 13px",fontSize:12.5,lineHeight:1.62,borderRadius:0,background:"color-mix(in srgb, var(--bg) 92%, var(--bg-panel))"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},children:e})]})}let eq=/<(read-files|modified-files)>\s*([\s\S]*?)\s*<\/\1>/g,eV=/(?:\r?\n){2,}((?:[ \t]*<(?:read-files|modified-files)>[ \t]*\r?\n[\s\S]*?\r?\n[ \t]*<\/(?:read-files|modified-files)>[ \t]*(?:\r?\n)?)+)\s*$/;function eY(e){return e.split(" ")[0].trim()}function eJ(e){if(!e)return null;let t=new Date(e),r=new Date,n=t.getFullYear()===r.getFullYear()&&t.getMonth()===r.getMonth()&&t.getDate()===r.getDate(),o=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(n)return o;let i=t.toLocaleDateString([],{month:"short",day:"numeric",year:t.getFullYear()!==r.getFullYear()?"numeric":void 0});return`${i} ${o}`}function eZ({message:e,isStreaming:t,toolResults:r,modelNames:o,cwd:i,onOpenFile:l,entryId:s,onFork:a,forking:d,onNavigate:c,prevAssistantEntryId:u,onEditContent:p,showTimestamp:h,prevTimestamp:x}){return"user"===e.role?(0,n.jsx)(eX,{message:e,cwd:i,onOpenFile:l,entryId:s,onFork:a,forking:d,onNavigate:c,prevAssistantEntryId:u,onEditContent:p}):"assistant"===e.role?(0,n.jsx)(eG,{message:e,isStreaming:t,toolResults:r,modelNames:o,cwd:i,onOpenFile:l,showTimestamp:h,prevTimestamp:x}):"toolResult"===e.role?null:"custom"===e.role?"compaction"===e.customType?(0,n.jsx)(e7,{message:e}):(0,n.jsx)(tr,{message:e,cwd:i,onOpenFile:l}):null}function eX({message:e,cwd:t,onOpenFile:r,entryId:i,onFork:l,forking:s,onNavigate:a,prevAssistantEntryId:d,onEditContent:c}){let[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),g="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),f="string"==typeof e.content?[]:e.content.filter(e=>"image"===e.type),m=eJ(e.timestamp),v=!!i&&!!l,y=!!d&&!!a;return(0,n.jsxs)("div",{style:{marginBottom:16,display:"flex",flexDirection:"column",alignItems:"flex-end"},onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",gap:6,maxWidth:"85%"},children:(0,n.jsxs)("div",{style:{flex:1,minWidth:0,background:"var(--user-bg)",border:"1px solid rgba(59,130,246,0.2)",borderRadius:12,padding:"8px 12px",fontSize:14,lineHeight:1.6,color:"var(--text)",wordBreak:"break-word"},children:[f.length>0&&(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!g},children:f.map((e,t)=>{let r=e.source?"base64"===e.source.type?`data:${e.source.media_type};base64,${e.source.data}`:e.source.url??"":e.data?`data:${e.mimeType};base64,${e.data}`:"";return(0,n.jsx)("img",{src:r,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid rgba(59,130,246,0.15)"}},t)})}),g&&(0,n.jsx)(e_,{className:"markdown-user-message",cwd:t,onOpenFile:r,children:g})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:3},children:[(0,n.jsx)("div",{style:{display:"flex",gap:3,opacity:+!!u,pointerEvents:u?"auto":"none",transition:"opacity 0.12s"},children:(0,n.jsxs)("button",{onClick:()=>{eI(g).then(()=>{x(!0),setTimeout(()=>x(!1),1500)})},title:"Copy message",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:h?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{h||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{h||(e.currentTarget.style.color="var(--text-dim)")},children:[h?(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),h?"Copied":"Copy"]})}),(v||y)&&(0,n.jsxs)("div",{style:{display:"flex",gap:3,opacity:u||s?1:0,pointerEvents:u||s?"auto":"none",transition:"opacity 0.12s"},children:[y&&(0,n.jsxs)("button",{onClick:()=>{a(d),c?.(g)},title:"Edit from here — branches within this session",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"15 10 20 15 15 20"}),(0,n.jsx)("path",{d:"M4 4v7a4 4 0 0 0 4 4h12"})]}),"Edit from here"]}),v&&(0,n.jsxs)("button",{onClick:()=>{l(i)},disabled:s,title:s?"Creating new session…":"New session — creates an independent copy from here",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:s?"var(--accent)":"var(--text-dim)",cursor:s?"not-allowed":"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{s||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{s||(e.currentTarget.style.color="var(--text-dim)")},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",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?"Creating…":"New session"]})]}),m&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:m})]})]})}function eG({message:e,isStreaming:t,toolResults:r,modelNames:i,cwd:l,onOpenFile:s,showTimestamp:a,prevTimestamp:d}){var c;let u,p=a?eJ(e.timestamp):null,h=(e.content??[]).map((e,t)=>({block:e,originalIndex:t})).filter(({block:e})=>!ef(e,{isStreaming:t})),x=h.map(({block:e})=>e),[g,f]=(0,o.useState)(!1),[m,v]=(0,o.useState)(!1),y=(0,o.useRef)(null),[b,k]=(0,o.useState)(null),j=(0,o.useRef)(h);j.current=h;let w=(0,o.useRef)(new Map),[S,C]=(0,o.useState)(new Map),T=(0,o.useMemo)(()=>{if(!e.timestamp||!d)return;let t=Math.round((e.timestamp-d)/1e3);return t>0?t:void 0},[e.timestamp,d]),L=(0,o.useMemo)(()=>{let t=new Map;if(!r||!e.timestamp)return t;for(let[n,o]of r)if(o.timestamp&&e.timestamp){let r=Math.round((o.timestamp-e.timestamp)/1e3);r>0&&t.set(n,r)}return t},[r,e.timestamp]),I=x.filter(e=>"text"===e.type).map(e=>e.text).join("\n");return((0,o.useEffect)(()=>{if(!t){let e=new Date().getTime();C(t=>{let r=new Map(t);for(let[t,n]of w.current)r.has(t)||r.set(t,Math.round((e-n)/1e3));return r}),y.current=null,k(null);return}let e=setInterval(()=>{let e=j.current,t=e.map(({block:e})=>e),r=Date.now();e.forEach(({originalIndex:e})=>{w.current.has(e)||w.current.set(e,r)}),C(t=>{let n=!1,o=new Map(t);for(let t=0;t<e.length-1;t++){let i=e[t].originalIndex,l=e[t+1].originalIndex;if(!o.has(i)&&w.current.has(i)){let e=w.current.get(i),t=w.current.get(l)??r;o.set(i,Math.round((t-e)/1e3)),n=!0}}return n?o:t});let n=0;for(let e of t)"text"===e.type?n+=e.text?.length??0:"thinking"===e.type?n+=e.thinking?.length??0:"toolCall"===e.type&&(n+=JSON.stringify(e.input??{}).length);if(0===n)return;null===y.current&&(y.current=r);let o=(r-y.current)/1e3;o>.5&&k(n/4/o)},300);return()=>clearInterval(e)},[t]),0!==x.length||t)?(0,n.jsxs)("div",{style:{marginBottom:16},onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",marginBottom:4,display:"flex",alignItems:"center",gap:6},children:[e.provider&&(0,n.jsx)("span",{children:i?.[`${e.provider}:${e.model}`]??i?.[e.model]??e.model}),t&&(()=>{let e,t=0;for(let e of x)"text"===e.type?t+=e.text?.length??0:"thinking"===e.type?t+=e.thinking?.length??0:"toolCall"===e.type&&(t+=JSON.stringify(e.input??{}).length);let r=Math.round(t/4);return(0,n.jsx)(n.Fragment,{children:r>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:"var(--text)"},title:"Estimated token count while streaming",children:[(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2,fontSize:11,fontWeight:400},children:[(0,n.jsxs)("svg",{width:"10",height:"10",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]}),null!==b&&(e=b>=50?"#53b3cb":b>=30?"#9bc53d":b>=15?"#f9c22e":"#e01a4f",(0,n.jsxs)("span",{style:{marginLeft:6,padding:"1px 6px",borderRadius:4,background:e,color:"#fff",fontSize:11,fontWeight:400},children:[b.toFixed(1)," t/s"]}))]})})})()]}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:h.map(({block:e,originalIndex:o})=>(0,n.jsx)(eQ,{block:e,toolResults:r,isStreaming:t,streamingDuration:S.get(o)??("thinking"===e.type?T:void 0),toolCallDurations:L,cwd:l,onOpenFile:s},o))}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[e.usage&&!t&&(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)"},children:(c=e.usage,u=[],c.input&&u.push(`${c.input.toLocaleString()} in`),c.output&&u.push(`${c.output.toLocaleString()} out`),c.cacheRead&&u.push(`${c.cacheRead.toLocaleString()} cache`),c.cost?.total&&u.push(`$${c.cost.total.toFixed(4)}`),u.join(" \xb7 "))}),I&&!t&&(0,n.jsxs)("button",{onClick:()=>{eI(I).then(()=>{v(!0),setTimeout(()=>v(!1),1500)})},title:"Copy message",style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:m?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",opacity:+!!g,pointerEvents:g?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{m||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{m||(e.currentTarget.style.color="var(--text-dim)")},children:[m?(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),m?"Copied":"Copy"]}),p&&!t&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginLeft:"auto"},children:p})]})]}):null}function eQ({block:e,toolResults:t,isStreaming:r,streamingDuration:o,toolCallDurations:i,cwd:l,onOpenFile:s}){if("text"===e.type)return(0,n.jsx)(e0,{block:e,isStreaming:r,cwd:l,onOpenFile:s});if("thinking"===e.type)return(0,n.jsx)(e1,{block:e,duration:o});if("toolCall"===e.type){let r=t?.get(e.toolCallId),o=i?.get(e.toolCallId);return(0,n.jsx)(e2,{block:e,result:r,duration:o})}return null}function e0({block:e,isStreaming:t,cwd:r,onOpenFile:o}){return(0,n.jsx)(e_,{isStreaming:t,cwd:r,onOpenFile:o,children:e.text})}function e1({block:e,duration:t}){let[r,i]=(0,o.useState)(!1);return(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:6,overflow:"hidden",fontSize:13},children:[(0,n.jsxs)("button",{onClick:()=>i(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"6px 10px",background:"var(--bg-panel)",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:[(0,n.jsx)("span",{children:"Thinking"}),void 0!==t&&(0,n.jsxs)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums"},children:[t,"s"]})]}),r&&(0,n.jsx)("div",{style:{padding:"8px 10px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",background:"var(--bg-panel)",borderTop:"1px solid var(--border)"},children:e.thinking})]})}function e2({block:e,result:t,duration:r}){let i,[l,s]=(0,o.useState)(!1),a=JSON.stringify(e.input,null,2),d="edit"===(i=e.toolName.toLowerCase())||i.startsWith("edit_")||i.endsWith(".edit")||i.endsWith("_edit")||i.includes("str_replace")||i.includes("replace_editor"),c=t&&!t.isError?function(e){var t;let r=e.details;if(!("object"==typeof(t=r)&&null!==t&&!Array.isArray(t)))return null;let n="string"==typeof r.patch?r.patch:null;if(n)return{text:n};let o="string"==typeof r.diff?r.diff:null;return o?{text:o}:null}(t):null,u=t?t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"):null,p=null!==u&&("(no output)"===u.trim()||""===u.trim()),h=t?.isError??!1;return(0,n.jsxs)("div",{style:{borderRadius:7,overflow:"hidden",fontSize:12,border:h?"1px solid rgba(248,113,113,0.45)":"1px solid rgba(34,197,94,0.25)",background:h?"rgba(248,113,113,0.05)":"rgba(34,197,94,0.04)"},children:[(0,n.jsxs)("button",{onClick:()=>s(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"6px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",minWidth:0},children:[(0,n.jsx)("span",{style:{color:h?"#f87171":"#16a34a",fontFamily:"var(--font-mono)",fontWeight:600,fontSize:11,flexShrink:0},children:e.toolName}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:function(e){let t=e.input;if(!t||"object"!=typeof t)return"";let r=Object.keys(t);return 0===r.length?"":"command"in t?String(t.command).slice(0,120):"path"in t?String(t.path).slice(0,120):"file_path"in t?String(t.file_path).slice(0,120):"pattern"in t?String(t.pattern).slice(0,120):"query"in t?String(t.query).slice(0,120):String(t[r[0]]).slice(0,120)}(e)}),void 0!==r&&(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0,fontVariantNumeric:"tabular-nums"},children:[r,"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:{flexShrink:0,transform:l?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),l&&!d&&(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,overflow:"auto",background:"var(--bg-subtle)",borderTop:h?"1px solid rgba(248,113,113,0.25)":"1px solid rgba(34,197,94,0.2)",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:a}),l&&t&&(c?(0,n.jsx)(e4,{diff:c}):(0,n.jsx)(e9,{text:u??"",isEmpty:p,isError:h}))]})}function e4({diff:e}){return(0,n.jsx)("div",{style:{borderTop:"1px solid rgba(34,197,94,0.15)",background:"var(--bg)"},children:(0,n.jsx)(e5,{text:e.text})})}function e5({text:e}){let t=(0,o.useMemo)(()=>(function(e){let t,r=[],n=null,o=0,i=0,l=[],s=[],a=()=>({lineNo:null,text:"",type:"empty"}),d=()=>{if(!n){l=[],s=[];return}let e=Math.max(l.length,s.length);for(let t=0;t<e;t++){let e=l[t]?{lineNo:l[t].lineNo,text:l[t].text,type:"removed"}:a(),r=s[t]?{lineNo:s[t].lineNo,text:s[t].text,type:"added"}:a();n.rows.push({type:"line",left:e,right:r})}l=[],s=[]};for(let a of e.split(/\r?\n/)){if(a.startsWith("--- ")){d(),t=eY(a.slice(4));continue}if(a.startsWith("+++ ")){d(),n={oldPath:t,newPath:eY(a.slice(4)),rows:[]},r.push(n);continue}let e=a.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);if(e){n||(n={rows:[]},r.push(n)),d(),o=Number(e[1]),i=Number(e[2]),n.rows.push({type:"hunk",text:a});continue}if(!n)continue;if(a.startsWith("\\ ")){d(),n.rows.push({type:"hunk",text:a});continue}let c=a[0],u=a.slice(1);" "===c?(d(),n.rows.push({type:"line",left:{lineNo:o++,text:u,type:"context"},right:{lineNo:i++,text:u,type:"context"}})):"-"===c?l.push({lineNo:o++,text:u}):"+"===c?s.push({lineNo:i++,text:u}):""!==a&&(d(),n.rows.push({type:"hunk",text:a}))}d();let c=r.filter(e=>e.rows.some(e=>"line"===e.type));return c.length>0?c:null})(e),[e]);if(!t)return(0,n.jsx)(e3,{text:e});let r=t.length>1;return(0,n.jsx)("div",{style:{maxHeight:560,overflowY:"auto",overflowX:"hidden",background:"var(--bg)"},children:t.map((e,t)=>(0,n.jsxs)("div",{style:{minWidth:0,borderTop:0===t?"none":"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55},children:[r&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",position:"sticky",top:0,zIndex:1,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)(e6,{title:e.oldPath||"Before",side:"left"}),(0,n.jsx)(e6,{title:e.newPath||"After",side:"right"})]}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)"},children:e.rows.map((e,t)=>"hunk"===e.type?null:(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)(e8,{cell:e.left,side:"left"}),(0,n.jsx)(e8,{cell:e.right,side:"right"})]},t))})]},t))})}function e6({title:e,side:t}){return(0,n.jsx)("div",{title:e,style:{padding:"5px 10px",color:"var(--text-dim)",borderRight:"left"===t?"1px solid var(--border)":"none",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})}function e8({cell:e,side:t}){let r="added"===e.type?"rgba(34,197,94,0.12)":"removed"===e.type?"rgba(248,113,113,0.13)":"empty"===e.type?"var(--bg-subtle)":"transparent",o="added"===e.type?"+":"removed"===e.type?"-":" ",i="added"===e.type?"#22c55e":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,n.jsxs)("div",{style:{display:"flex",minWidth:0,background:r,borderRight:"left"===t?"1px solid var(--border)":"none"},children:[(0,n.jsx)("span",{style:{width:42,padding:"0 6px",textAlign:"right",color:"var(--text-dim)",userSelect:"none",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",flexShrink:0},children:e.lineNo??""}),(0,n.jsx)("span",{style:{width:18,padding:"0 5px",color:i,userSelect:"none",fontWeight:"context"===e.type||"empty"===e.type?400:700,flexShrink:0},children:o}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 10px 0 0",color:"empty"===e.type?"var(--text-dim)":"var(--text)",whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:e.text||"\xa0"})]})}function e3({text:e}){let t=e.split(/\r?\n/);return(0,n.jsx)("div",{style:{maxHeight:520,overflowY:"auto",overflowX:"hidden",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55,minWidth:0},children:t.map((e,t)=>{let r=e.startsWith("@@")?"hunk":e.startsWith("+")&&!e.startsWith("+++")?"added":e.startsWith("-")&&!e.startsWith("---")?"removed":"context";return(0,n.jsxs)("div",{style:{display:"flex",background:"added"===r?"rgba(34,197,94,0.12)":"removed"===r?"rgba(248,113,113,0.13)":"hunk"===r?"rgba(96,165,250,0.12)":"transparent",borderLeft:"added"===r?"3px solid #22c55e":"removed"===r?"3px solid #f87171":"hunk"===r?"3px solid var(--accent)":"3px solid transparent"},children:[(0,n.jsx)("span",{style:{width:48,padding:"0 8px",color:"var(--text-dim)",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",textAlign:"right",userSelect:"none",flexShrink:0},children:t+1}),(0,n.jsx)("span",{style:{padding:"0 10px",whiteSpace:"pre-wrap",overflowWrap:"anywhere",color:"added"===r?"#22c55e":"removed"===r?"#f87171":"hunk"===r?"var(--accent)":"var(--text)"},children:e||"\xa0"})]},t)})})}function e9({text:e,isEmpty:t,isError:r}){return(0,n.jsx)("div",{style:{borderTop:`1px solid ${r?"rgba(248,113,113,0.3)":"rgba(34,197,94,0.15)"}`,background:r?"rgba(248,113,113,0.04)":"var(--bg-subtle)"},children:(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:r?"#f87171":t?"var(--text-dim)":"var(--text-muted)",fontSize:12,lineHeight:1.5,overflow:"auto",maxHeight:400,background:"var(--bg)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontStyle:t?"italic":"normal",opacity:t?.6:1},children:t?"(no output)":e})})}function e7({message:e}){let t=tn(e.content),r=(0,o.useMemo)(()=>{let e,r,n,o,i;return e=[],r=[],n=t.match(eV),o=n?.[1]??"",i=n?.index===void 0?t:t.slice(0,n.index),o.replace(eq,(t,n,o)=>{let i=o.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);return"read-files"===n?e.push(...i):r.push(...i),""}),{body:i.trim(),readFiles:e,modifiedFiles:r}},[t]),i=eJ(e.timestamp);return(0,n.jsx)("div",{style:{marginBottom:16},children:(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)"},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:"compaction"}),i&&(0,n.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:i})]}),(0,n.jsxs)("div",{style:{padding:"11px 13px 12px"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:15,fontWeight:700,lineHeight:1.35},children:"Conversation compacted"}),(0,n.jsx)("div",{style:{marginTop:3,marginBottom:10,color:"var(--text)",fontSize:14,lineHeight:1.5},children:"The conversation history before this point was compacted into the following summary:"}),r.body?(0,n.jsx)(e_,{className:"markdown-compaction-message",children:r.body}):(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:"(no summary)"}),(0,n.jsx)(te,{readFiles:r.readFiles,modifiedFiles:r.modifiedFiles})]})]})})}function te({readFiles:e,modifiedFiles:t}){if(0===e.length+t.length)return null;let r=[];return e.length>0&&r.push(`${e.length} read`),t.length>0&&r.push(`${t.length} modified`),(0,n.jsxs)("details",{className:"compaction-file-details",children:[(0,n.jsxs)("summary",{children:["File context: ",r.join(", ")]}),t.length>0&&(0,n.jsx)(tt,{title:"Modified files",files:t}),e.length>0&&(0,n.jsx)(tt,{title:"Read files",files:e})]})}function tt({title:e,files:t}){return(0,n.jsxs)("div",{className:"compaction-file-section",children:[(0,n.jsx)("div",{className:"compaction-file-title",children:e}),(0,n.jsx)("ul",{className:"compaction-file-list",children:t.map(e=>(0,n.jsx)("li",{children:e},e))})]})}function tr({message:e,cwd:t,onOpenFile:r}){var i;let l,s=!1===e.display,[a,d]=(0,o.useState)(!s),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)(!1),x=tn(e.content),g="string"==typeof(i=e.content)?[]:i.filter(e=>"image"===e.type),f=void 0!==e.details,m=f?function(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}(e.details):"",v=e.customType||"extension",y=eJ(e.timestamp);return(0,n.jsx)("div",{style:{marginBottom:16},children:(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:s?"var(--bg-subtle)":"var(--bg)",opacity:s&&!a?.82:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:v}),s&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"hidden extension message"}),y&&(0,n.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:y})]}),a?(0,n.jsxs)("div",{style:{padding:"6px 9px"},children:[g.length>0&&(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!x},children:g.map((e,t)=>{var r;let o=(r=e).source?"base64"===r.source.type?`data:${r.source.media_type};base64,${r.source.data}`:r.source.url??"":r.data?`data:${r.mimeType};base64,${r.data}`:"";return o?(0,n.jsx)("img",{src:o,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid var(--border)"}},t):null})}),x?(0,n.jsx)(e_,{className:"markdown-custom-message",cwd:t,onOpenFile:r,children:x}):(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:"(no message)"})]}):(0,n.jsx)("button",{onClick:()=>d(!0),style:{display:"block",width:"100%",padding:"8px 10px",border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",fontSize:12,textAlign:"left"},children:x&&(l=x.replace(/\s+/g," ").trim())?l.length>140?`${l.slice(0,140)}...`:l:"Show extension message"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 9px",borderTop:"1px solid var(--border)",background:"var(--bg-subtle)"},children:[x||m?(0,n.jsx)("button",{onClick:()=>{eI(x||m).then(()=>{h(!0),setTimeout(()=>h(!1),1500)})},style:{padding:"3px 7px",border:"none",background:"none",color:p?"var(--accent)":"var(--text-dim)",cursor:"pointer",fontSize:11},children:p?"Copied":"Copy"}):null,(f||s)&&(0,n.jsx)("button",{onClick:()=>{s?d(e=>!e):u(e=>!e)},style:{marginLeft:"auto",padding:"3px 7px",border:"none",background:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11},children:s?a?"Collapse":"Expand":c?"Hide details":"Show details"})]}),f&&(s&&a||!s&&c)&&(0,n.jsx)("pre",{style:{margin:0,padding:"9px 10px",borderTop:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:360,overflow:"auto",fontFamily:"var(--font-mono)"},children:m})]})})}function tn(e){return"string"==typeof e?e:e.filter(e=>"text"===e.type).map(e=>e.text).join("\n")}let to=new Map;function ti(e){return{value:e.value,images:e.images.map(e=>({...e}))}}function tl(e){let t=to.get(e);return t?ti(t):null}function ts(e,t){t.value||0!==t.images.length?to.set(e,ti(t)):to.delete(e)}function ta(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let r=/(?:^|\s)@([^\s"]*)$/.exec(e);return r?{start:e.length-(r[1].length+1),query:r[1],quoted:!1}:null}function td(e){let t=0;for(let r=0;r<e.length;r++)"/"===e[r]&&t++;return t}function tc(e,t){if(!e)return!0;let r=0;for(let n=0;n<t.length&&r<e.length;n++)t[n]===e[r]&&r++;return r===e.length}let tu="(max-width: 640px)";function tp(e){if(!window.matchMedia)return()=>{};let t=window.matchMedia(tu);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)}function th(){return!!window.matchMedia&&window.matchMedia(tu).matches}function tx(){return!1}function tg(){return(0,o.useSyncExternalStore)(tp,th,tx)}let tf=["off","default","full"],tm={off:"none",default:"default",full:"full"},tv=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function ty(e,t){return tv.compare(e.name||e.modelId,t.name||t.modelId)||tv.compare(e.provider,t.provider)||tv.compare(e.modelId,t.modelId)}let tb=["auto","off","minimal","low","medium","high","xhigh","max"],tk={auto:"Use pi default",off:"Reasoning off",minimal:"Minimal reasoning",low:"Low reasoning",medium:"Medium reasoning",high:"High reasoning",xhigh:"Extra-high reasoning",max:"Max reasoning"};function tj(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:e.toLocaleString()}let tw=[{name:"compact",description:"Compress context, optionally with instructions",source:"builtin"},{name:"reload",description:"Reload extensions, skills, prompts, and tools",source:"builtin"},{name:"name",description:"Set the session display name",source:"builtin"},{name:"session",description:"Show session message, token, and cost stats",source:"builtin"},{name:"copy",description:"Copy the last assistant message",source:"builtin"}],tS=["builtin","extension","prompt","skill"],tC={builtin:"Built-in",extension:"Extensions",prompt:"Prompts",skill:"Skills"},tT={builtin:0,extension:1,prompt:2,skill:3};function tL(e,t){let r=e.name.toLowerCase(),n=e.description?.toLowerCase()??"";return r===t?0:r.startsWith(t)?1:r.includes(t)?2:n.includes(t)?3:4}function tI(e){return{data:e.data,mimeType:e.mimeType}}function tz(e){return{...e,previewUrl:`data:${e.mimeType};base64,${e.data}`}}function tR(e){e.previewUrl.startsWith("blob:")&&URL.revokeObjectURL(e.previewUrl)}function tW({kind:e,text:t}){return(0,n.jsxs)("div",{title:t,style:{display:"flex",alignItems:"center",gap:8,padding:"3px 10px",fontSize:12,color:"var(--text-muted)",minWidth:0},children:[(0,n.jsx)("span",{style:{flexShrink:0,fontSize:10,fontFamily:"var(--font-mono)",padding:"1px 7px",borderRadius:999,border:`1px solid ${"steer"===e?"color-mix(in srgb, var(--accent) 45%, transparent)":"var(--border)"}`,color:"steer"===e?"var(--accent)":"var(--text-dim)"},children:e}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]})}let tM=(0,o.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:i,isStreaming:l,model:a,isAutoModelSelection:d,modelNames:c,modelList:u,onModelChange:p,onCompact:h,onAbortCompaction:x,isCompacting:g,compactError:f,compactResult:m,toolPreset:v,onToolPresetChange:y,thinkingLevel:b,onThinkingLevelChange:k,availableThinkingLevels:j,thinkingLevelMap:w,retryInfo:S,queuedMessages:C,onRecallQueue:T,slashCommands:L,slashCommandsLoading:I,onLoadSlashCommands:z,onBuiltinCommand:R,soundEnabled:W,onSoundToggle:M,onAudioUnlock:E,onPromptWithStreamingBehavior:$,draftKey:A,cwd:D},P){let F,N,O,H,_,U,K,q,V=tg(),[Y,J]=(0,o.useState)(()=>A?tl(A)?.value??"":""),[Z,X]=(0,o.useState)(!1),[G,Q]=(0,o.useState)(null),[ee,et]=(0,o.useState)(!1),[er,en]=(0,o.useState)(!1),[eo,ei]=(0,o.useState)(!1),[el,es]=(0,o.useState)(()=>A?tl(A)?.images.map(tz)??[]:[]),[ea,ed]=(0,o.useState)(!1),[ec,eu]=(0,o.useState)(0),[ep,eh]=(0,o.useState)(null),[ex,eg]=(0,o.useState)(!1),[ef,em]=(0,o.useState)(0),[ev,ey]=(0,o.useState)(null),[eb,ek]=(0,o.useState)(!1),[ej,ew]=(0,o.useState)(null),eS=(0,o.useRef)(null),eC=(0,o.useRef)(null),eT=(0,o.useRef)(null),eL=(0,o.useRef)(null),eI=(0,o.useRef)(null),ez=(0,o.useRef)(null),eR=(0,o.useRef)(null),eW=(0,o.useRef)(!1),eM=(0,o.useRef)(0),eE=(0,o.useRef)(!1),e$=(0,o.useRef)([]),eB=(0,o.useRef)([]),eA=(0,o.useRef)(null),eD=(0,o.useRef)(null),eP=(0,o.useRef)(A),eF=(0,o.useRef)(Y),eN=(0,o.useRef)(el);eF.current=Y,eN.current=el,(0,o.useImperativeHandle)(P,()=>({insertIfEmpty(e){let t=eS.current;(t?t.value:Y).trim()||(J(e),eh(null),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},prependText(e){if(!e.trim())return;let t=eS.current,r=[e,t?t.value:Y].filter(e=>e.trim()).join("\n\n");J(r),eh(null),requestAnimationFrame(()=>{t&&(t.focus(),t.setSelectionRange(r.length,r.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},insertText(e){let t=eS.current;if(!t)return void J(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,o=t.value.slice(0,r),i=t.value.slice(n),l=o.length>0&&!o.endsWith(" ")?" ":"";J(o+l+e+i),eh(null),requestAnimationFrame(()=>{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`})},addImages(e){eO(e)}}));let eO=(0,o.useCallback)(async e=>{if(l)return;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)})));es(e=>[...e,...r])},[l]),eH=(0,o.useCallback)(e=>{es(t=>{let r=[...t],[n]=r.splice(e,1);return n&&tR(n),r})},[]),e_=(0,o.useCallback)(()=>{es(e=>(e.forEach(tR),[]))},[]),eU=(0,o.useCallback)(()=>{var e;J(""),eh(null),A&&to.delete(A),eP.current&&eP.current!==A&&(e=eP.current,to.delete(e)),e_(),eS.current&&(eS.current.style.height="auto")},[e_,A]);(0,o.useEffect)(()=>{A&&eP.current===A&&ts(A,{value:Y,images:el.map(tI)})},[el,A,Y]),(0,o.useEffect)(()=>{let e=eP.current;if(e===A)return;e&&ts(e,{value:eF.current,images:eN.current.map(tI)});let t=A?tl(A):null;eP.current=A,J(t?.value??""),eh(null),es(e=>(e.forEach(tR),t?.images.map(tz)??[]))},[A]),(0,o.useEffect)(()=>{let e=eS.current;e&&(e.style.height="auto",Y&&(e.style.height=`${Math.min(e.scrollHeight,200)}px`))},[Y]),(0,o.useEffect)(()=>()=>{eN.current.forEach(tR)},[]);let eK=(0,o.useCallback)(async()=>{let t=Y.trim();if((t||el.length)&&!l){if(E?.(),!el.length&&t.startsWith("/")&&R){let e=await R(t);if(e.handled){e.error||eU();return}}e(t,el.length?el:void 0),eU()}},[Y,el,l,R,e,eU,E]),eq=Y.startsWith("/")&&!/\s/.test(Y.slice(1))?Y.slice(1).toLowerCase():null,eV=null===eq?[]:[...l?[]:tw,...L??[]].filter(e=>{let t=e.name.toLowerCase(),r=e.description?.toLowerCase()??"";return t.includes(eq)||r.includes(eq)}).sort((e,t)=>{let r=tL(e,eq)-tL(t,eq);return 0!==r?r:tT[e.source]-tT[t.source]||tv.compare(e.name,t.name)}),eY=(()=>{let e=new Map;for(let t of tS)e.set(t,{source:t,items:[]});return eV.forEach((t,r)=>{e.get(t.source)?.items.push({command:t,index:r})}),tS.map(t=>e.get(t)).filter(e=>e.items.length>0)})(),eJ=1===eV.length?eq?"1 match":"1 command":`${eV.length} ${eq?"matches":"commands"}`,eZ=!!Y.trim()&&0===el.length,eX=(0,o.useCallback)((e,t)=>{if(!D)return void eh(null);let r=t??e.length;eh(ta(e.slice(0,r)))},[D]),eG=ep?.query??null,eQ=o.useMemo(()=>null!==eG&&ev&&ev.cwd===D?function(e,t,r=20){let n=t.toLowerCase();if(!n)return e.slice(0,r);let o=[];for(let t of e){let e=function(e,t){let r=e.path.toLowerCase(),n=0;if(t.includes("/"))r===t?n=100:r.startsWith(t)?n=80:r.includes(t)?n=50:tc(t,r)&&(n=10);else{let e=r.lastIndexOf("/"),o=-1===e?r:r.slice(e+1);o===t?n=100:o.startsWith(t)?n=80:o.includes(t)?n=50:r.includes(t)?n=30:tc(t,r)&&(n=10)}return e.isDir&&n>0&&(n+=10),n}(t,n);e>0&&o.push({entry:t,score:e})}return o.sort((e,t)=>t.score-e.score||td(e.entry.path)-td(t.entry.path)||e.entry.path.localeCompare(t.entry.path)),o.slice(0,r).map(e=>e.entry)}(ev.entries,eG):[],[eG,ev,D]),e0=!!(eG&&ev?.truncated&&ev.cwd===D);(0,o.useEffect)(()=>{if(!e0||!D||!eG)return;let e=setTimeout(()=>{fetch(`/api/file-index?cwd=${encodeURIComponent(D)}&q=${encodeURIComponent(eG)}`).then(e=>{if(!e.ok)throw Error(`file search failed: ${e.status}`);return e.json()}).then(e=>ew({cwd:D,query:eG,matches:e.matches??[]})).catch(()=>{})},150);return()=>clearTimeout(e)},[e0,eG,D]);let e1=e0&&null!==ej&&ej.cwd===D&&ej.query===eG,e2=e1?ej.matches:eQ,e4=null===ep?null:`${ep.start}:${+!!ep.quoted}:${ep.query}`;(0,o.useEffect)(()=>{if(null===e4){eg(!1),em(0);return}eg(!0),em(0)},[e4]);let e5=null!==ep;(0,o.useEffect)(()=>{if(!e5||!D)return;let e=eA.current;e&&e.cwd===D&&Date.now()-e.fetchedAt<1e4||eD.current===D||(eD.current=D,ek(!0),fetch(`/api/file-index?cwd=${encodeURIComponent(D)}`).then(e=>{if(!e.ok)throw Error(`file index failed: ${e.status}`);return e.json()}).then(e=>{ey({cwd:D,entries:function(e){let t=new Set;for(let r of e){let e=r.indexOf("/");for(;-1!==e;)t.add(r.slice(0,e)),e=r.indexOf("/",e+1)}let r=[];for(let e of t)r.push({path:e,isDir:!0});for(let t of e)t&&r.push({path:t,isDir:!1});return r.sort((e,t)=>td(e.path)-td(t.path)||e.path.localeCompare(t.path)),r}(e.files??[]),truncated:!!e.truncated}),eA.current={cwd:D,fetchedAt:Date.now()}}).catch(()=>{eA.current=null}).finally(()=>{eD.current=null,ek(!1)}))},[e5,D]);let e6=(0,o.useCallback)(e=>{if(!ep)return;let t=eS.current,r=t?.selectionStart??Y.length,n=Y.slice(0,ep.start),o=Y.slice(r);ep.quoted&&o.startsWith('"')&&(o=o.slice(1));let i=function(e,t,r=!1){let n=t?`${e}/`:e,o=r||n.includes(" ");if(t){let e=o?`@"${n}"`:`@${n}`;return{text:e,cursorOffset:o?e.length-1:e.length}}let i=o?`@"${n}" `:`@${n} `;return{text:i,cursorOffset:i.length}}(e.path,e.isDir,ep.quoted),l=n+i.text+o,s=n.length+i.cursorOffset;J(l),eh(ta(l.slice(0,s))),requestAnimationFrame(()=>{let e=eS.current;e&&(e.focus(),e.setSelectionRange(s,s),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[ep,Y]);(0,o.useEffect)(()=>{ef>=e2.length&&em(Math.max(0,e2.length-1))},[e2.length,ef]),(0,o.useEffect)(()=>{eB.current.length=e2.length},[e2.length]),(0,o.useEffect)(()=>{ex&&eB.current[ef]?.scrollIntoView({block:"nearest",inline:"nearest"})},[ef,ex]);let e8=(0,o.useCallback)(e=>{let t=`/${e.name} `;J(t),ed(!1),eu(0),requestAnimationFrame(()=>{let e=eS.current;e&&(e.focus(),e.setSelectionRange(t.length,t.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),e3=(0,o.useCallback)(e=>{let t=Y.trim();if((t||el.length)&&!el.length){if(E?.(),t.startsWith("/")&&$){$(t,"steer"===e?"steer":"followUp",el.length?el:void 0),eU();return}"steer"===e&&r?r(t,el.length?el:void 0):"followup"===e&&i&&i(t,el.length?el:void 0),eU()}},[Y,el,$,r,i,eU,E]),e9=(0,o.useCallback)(e=>{let t=eV.length-1;if(t<0)return 0;if("left"===e)return Math.max(0,ec-1);if("right"===e)return Math.min(t,ec+1);let r=e$.current[ec];if(!r)return"down"===e?Math.min(t,ec+1):Math.max(0,ec-1);let n=r.getBoundingClientRect(),o=n.left+n.width/2,i=n.top+n.height/2,l=-1,s=1/0;for(let r=0;r<=t;r+=1){if(r===ec)continue;let t=e$.current[r];if(!t)continue;let n=t.getBoundingClientRect(),a=n.top+n.height/2-i;if("down"===e?a<=4:a>=-4)continue;let d=1e3*Math.abs(a)+Math.abs(n.left+n.width/2-o);d<s&&(l=r,s=d)}return l>=0?l:"down"===e?Math.min(t,ec+1):Math.max(0,ec-1)},[eV.length,ec]),e7=(0,o.useCallback)(e=>{let t=e.nativeEvent,n=Date.now()-eM.current<100,o=eW.current||t.isComposing||229===t.keyCode;if("Enter"===e.key&&!e.shiftKey&&(o||n)){n&&e.preventDefault();return}if(ea&&null!==eq){if("ArrowDown"===e.key){e.preventDefault(),eu(e9("down"));return}if("ArrowUp"===e.key){e.preventDefault(),eu(e9("up"));return}if("ArrowRight"===e.key){e.preventDefault(),eu(e9("right"));return}if("ArrowLeft"===e.key){e.preventDefault(),eu(e9("left"));return}if("Escape"===e.key){e.preventDefault(),ed(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&eV[ec]){e.preventDefault(),e8(eV[ec]);return}}if(ex&&null!==ep&&!o){if("ArrowDown"===e.key){e.preventDefault(),em(e=>Math.min(Math.max(0,e2.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),em(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),eg(!1);return}if(("Tab"===e.key||"Enter"===e.key&&!e.shiftKey)&&e2[ef]){e.preventDefault(),e6(e2[ef]);return}}"Enter"!==e.key||e.shiftKey||(e.preventDefault(),l&&(r||i)?e3(r?"steer":"followup"):eK())},[l,r,i,ea,eq,eV,ec,e8,e3,eK,e9,ex,ep,e2,ef,e6]),te=(0,o.useCallback)(()=>{let e=eS.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tt=(0,o.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>e.type.startsWith("image/"));t.length&&(e.preventDefault(),eO(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eO]);(0,o.useEffect)(()=>{if(null===eq){ed(!1),eu(0),eE.current=!1;return}ed(!0),eu(0),!eE.current&&z&&(eE.current=!0,Promise.resolve(z()).catch(()=>{eE.current=!1}))},[eq,z]),(0,o.useEffect)(()=>{ec>=eV.length&&eu(Math.max(0,eV.length-1))},[eV.length,ec]),(0,o.useEffect)(()=>{e$.current.length=eV.length},[eV.length]),(0,o.useEffect)(()=>{ea&&e$.current[ec]?.scrollIntoView({block:"nearest",inline:"nearest"})},[ec,ea]);let tr=u&&u.length>0?u.map(e=>({provider:e.provider,modelId:e.id,name:e.name})).sort(ty):Object.entries(c??{}).map(([e,t])=>({provider:a?.provider??"unknown",modelId:e,name:t})).sort(ty),tn=[];for(let e of tr){let t=tn.find(t=>t.provider===e.provider);t?t.options.push(e):tn.push({provider:e.provider,options:[e]})}let ti=a?tr.find(e=>e.modelId===a.modelId&&e.provider===a.provider)?.name??a.modelId:null,tu=m?Math.max(0,m.tokensBefore-m.estimatedTokensAfter):0,tp=m?.reason&&"manual"!==m.reason?`${m.reason[0].toUpperCase()}${m.reason.slice(1)} compacted`:"Compacted",th=m?`${tp} ${tj(m.tokensBefore)} -> ${tj(m.estimatedTokensAfter)} tokens (${tj(tu)} saved)`:null,tx="auto"!==(F=b??"auto")&&w?w[F]??F:F,tM=Object.entries(tm).find(([,e])=>e===(v??"default"))?.[0]??"default";return(0,o.useEffect)(()=>{let e=e=>{eC.current&&!eC.current.contains(e.target)&&eT.current&&!eT.current.contains(e.target)&&X(!1),eL.current&&!eL.current.contains(e.target)&&et(!1),eI.current&&!eI.current.contains(e.target)&&en(!1),ez.current&&!ez.current.contains(e.target)&&ei(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,o.useEffect)(()=>{V||ei(!1)},[V]),(0,n.jsxs)("div",{style:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:V?16:52},children:[(0,n.jsx)("input",{ref:eR,type:"file",accept:"image/*",multiple:!0,disabled:l,style:{display:"none"},onChange:e=>{eO(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:820,margin:"0 auto"},children:[(C?.steering.length??0)+(C?.followUp.length??0)>0&&(0,n.jsxs)("div",{style:{marginBottom:8,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:"5px 0"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"2px 8px 4px 10px"},children:[(0,n.jsxs)("span",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:["Queued \xb7 ",(C?.steering.length??0)+(C?.followUp.length??0)]}),T&&(0,n.jsxs)("button",{onClick:T,title:"Remove all queued messages and put them back into the input box for editing",style:{display:"flex",alignItems:"center",gap:6,padding:"4px 12px",fontSize:12,color:"var(--text)",background:"transparent",border:"1px solid var(--border)",borderRadius:7,cursor:"pointer",transition:"background 0.12s, border-color 0.12s",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.borderColor="color-mix(in srgb, var(--accent) 45%, var(--border))"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.borderColor="var(--border)"},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)("polyline",{points:"9 14 4 9 9 4"}),(0,n.jsx)("path",{d:"M20 20v-7a4 4 0 0 0-4-4H4"})]}),"Recall to input"]})]}),C?.steering.map((e,t)=>(0,n.jsx)(tW,{kind:"steer",text:e},`steer-${t}`)),C?.followUp.map((e,t)=>(0,n.jsx)(tW,{kind:"follow-up",text:e},`followup-${t}`))]}),S&&(0,n.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize: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]})]}),th&&(0,n.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"rgba(16,185,129,0.08)",border:"1px solid rgba(16,185,129,0.24)",borderRadius:6,fontSize:12,color:"rgba(5,150,105,0.95)",display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("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)("polyline",{points:"20 6 9 17 4 12"})}),th]}),el.length>0&&(0,n.jsx)("div",{style:{display:"flex",gap:6,marginBottom:6,flexWrap:"wrap"},children:el.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 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"})]})})]},t))}),(0,n.jsxs)("div",{style:{position:"relative"},children:[ea&&null!==eq&&(0,n.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(56vh, 460px)"},children:[(0,n.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)"},children:[(0,n.jsx)("span",{children:I?"Loading commands...":`Slash commands \xb7 ${eJ}`}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:"Tab / Enter"})]}),(0,n.jsx)("div",{style:{maxHeight:"calc(min(56vh, 460px) - 34px)",overflowY:"auto",padding:10},children:I||0!==eV.length?eY.map(e=>(0,n.jsxs)("section",{style:{marginBottom:12},children:[(0,n.jsxs)("div",{style:{position:"sticky",top:-10,zIndex:1,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"4px 0 6px",background:"var(--bg)",color:"var(--text-dim)",fontSize:10,fontWeight:600,textTransform:"uppercase"},children:[(0,n.jsx)("span",{children:tC[e.source]}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:500},children:e.items.length})]}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:8},children:e.items.map(({command:e,index:t})=>{let r=t===ec;return(0,n.jsxs)("button",{ref:e=>{e$.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),e8(e)},onMouseEnter:()=>eu(t),style:{width:"100%",minWidth:0,minHeight:58,display:"flex",flexDirection:"column",gap:4,justifyContent:"center",padding:"9px 10px",border:`1px solid ${r?"var(--accent)":"var(--border)"}`,borderRadius:7,background:r?"var(--bg-selected)":"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",boxShadow:r?"0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent)":"none"},children:[(0,n.jsxs)("span",{style:{fontSize:13,fontFamily:"var(--font-mono)",overflowWrap:"anywhere",wordBreak:"break-word"},children:["/",e.name]}),e.description&&(0,n.jsx)("span",{style:{display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflow:"hidden",fontSize:11,lineHeight:1.35,color:"var(--text-dim)"},children:e.description})]},`${e.source}:${e.name}`)})})]},e.source)):(0,n.jsx)("div",{style:{padding:"2px 2px 4px",fontSize:12,color:"var(--text-dim)"},children:"No extension, prompt, or skill commands found"})})]}),ex&&null!==ep&&(N=eb&&(!ev||ev.cwd!==D),O=1===e2.length?"1 match":`${e2.length} matches`,H=ev?.truncated&&!e1?ep.query?" \xb7 searching all files…":" \xb7 index truncated":"",(0,n.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(48vh, 400px)"},children:[(0,n.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)"},children:[(0,n.jsx)("span",{children:N?"Loading files...":`Files \xb7 ${O}${H}`}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:"Tab / Enter"})]}),(0,n.jsx)("div",{style:{maxHeight:"calc(min(48vh, 400px) - 34px)",overflowY:"auto",padding:4},children:N||0!==e2.length?e2.map((e,t)=>{let r=t===ef,o=e.path.split("/").pop()??e.path,i=e.path.slice(0,e.path.length-o.length);return(0,n.jsxs)("button",{ref:e=>{eB.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),e6(e)},onMouseEnter:()=>em(t),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"6px 8px",border:"none",borderRadius:6,background:r?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,fontFamily:"var(--font-mono)"},children:[(0,n.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,n.jsx)(s,{size:14}):B(o,14)}),(0,n.jsxs)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[i&&(0,n.jsx)("span",{style:{color:"var(--text-dim)"},children:i}),o,e.isDir&&(0,n.jsx)("span",{style:{color:"var(--text-dim)"},children:"/"})]})]},`${e.isDir?"d":"f"}:${e.path}`)}):(0,n.jsx)("div",{style:{padding:"6px 8px",fontSize:12,color:"var(--text-dim)"},children:e0&&!e1?"Searching…":"No matching files"})})]})),(0,n.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center",background:"var(--bg)",border:`1px solid ${l&&(r||i)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:14,padding:"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:eS,value:Y,onChange:e=>{J(e.target.value),eX(e.target.value,e.target.selectionStart)},onSelect:e=>{let t=e.currentTarget;eX(t.value,t.selectionStart)},onKeyDown:e7,onCompositionStart:()=>{eW.current=!0},onCompositionEnd:e=>{eW.current=!1,eM.current=Date.now();let t=e.currentTarget;eX(t.value,t.selectionStart)},onInput:te,onPaste:tt,placeholder:l&&(r||i)?"Steer now / queue follow-up...":l?"Agent is running…":"Message… Type / for commands, @ for files",rows:1,style:{flex:1,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto"}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>e3("steer"),disabled:!eZ,title:el.length?"Image attachments cannot be queued while the agent is running":"Interrupt the current run and inject this message now",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:eZ?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eZ?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eZ?"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"})]}),"Steer"]}),i&&(0,n.jsxs)("button",{onClick:()=>e3("followup"),disabled:!eZ,title:el.length?"Image attachments cannot be queued while the agent is running":"Queue this message after the agent finishes",style:{display:"flex",alignItems:"center",gap:5,padding:"7px 12px",background:eZ?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eZ?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eZ?"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"})]}),"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:eK,disabled:!Y.trim()&&!el.length,style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:6,padding:"7px 14px",background:Y.trim()||el.length?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:Y.trim()||el.length?"#fff":"var(--text-dim)",cursor:Y.trim()||el.length?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:Y.trim()||el.length?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:"14",height:"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",{style:{marginTop:8,display:V?"grid":"flex",gridTemplateColumns:V?"minmax(0, 1fr) auto":void 0,alignItems:"center",gap:6},children:[(0,n.jsxs)("div",{style:{flex:V?"1 1 auto":"0 0 auto",minWidth:0,display:"flex",alignItems:"center",gap:2},children:[(0,n.jsx)("button",{onClick:()=>eR.current?.click(),disabled:l,title:"Attach image",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:el.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=el.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=el.length?"var(--accent)":"var(--text-muted)"},children:(0,n.jsxs)("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)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,n.jsx)("polyline",{points:"21 15 16 10 5 21"})]})}),tr.length>0&&ti&&p&&(0,n.jsxs)("div",{ref:eC,style:{position:"relative",flex:V?"1 1 auto":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();Q({top:t.top,left:t.left,width:t.width}),X(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,justifyContent:V?"flex-start":void 0,padding:V?"8px 10px":"8px 12px",height:32,width:V?"100%":void 0,maxWidth:V?"100%":220,overflow:"hidden",background:Z?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize: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=Z?"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:ti})]}),Z&&G&&(U=(_=window.visualViewport?.height??window.innerHeight)-G.top+6,K=Math.max(120,Math.min(G.top-8,.6*_)),q=V?{left:8,right:8,maxWidth:"calc(100vw - 16px)"}:{left:G.left,width:"max-content",minWidth:G.width},(0,n.jsx)("div",{ref:eT,style:{position:"fixed",bottom:U,...q,zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:K,overflowY:"auto"},children:tn.map((e,t)=>(0,n.jsxs)("div",{children:[tn.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===a?.modelId&&e.provider===a?.provider;return(0,n.jsxs)("button",{onClick:()=>{X(!1),(!t||d)&&p(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}}),e.name]},`${e.provider}:${e.modelId}`)})]},e.provider))}))]})]}),!V&&(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsxs)("div",{ref:ez,style:{flex:"0 0 auto",display:"flex",alignItems:"center",justifyContent:"flex-end",position:"relative",marginLeft:V?0:"auto"},children:[V&&(0,n.jsx)("button",{type:"button",title:eo?void 0:"More controls","aria-label":"More controls","aria-expanded":eo,"aria-hidden":eo||void 0,tabIndex:eo?-1:void 0,onClick:()=>{X(!1),ei(!0)},style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:32,padding:"8px 10px",background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:eo?"default":"pointer",fontSize:12,fontWeight:500,visibility:eo?"hidden":"visible",pointerEvents:eo?"none":"auto",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{eo||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{eo||(e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)")},children:"More"}),(0,n.jsxs)("div",{style:{display:V?eo?"flex":"none":"flex",alignItems:"center",gap:V?1:2,...V?{position:"absolute",right:0,bottom:0,zIndex:60,padding:1,width:"max-content",maxWidth:"calc(100vw - 32px)",flexWrap:"nowrap",justifyContent:"flex-end",border:"1px solid color-mix(in srgb, var(--border) 72%, transparent)",borderRadius:10,background:"color-mix(in srgb, var(--bg-panel) 92%, var(--bg))",boxShadow:"0 8px 24px rgba(0,0,0,0.14)",backdropFilter:"blur(10px)"}:null},children:[!l&&k&&(0,n.jsxs)("div",{ref:eI,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&en(e=>!e),disabled:l,title:`Change reasoning level: ${tx}`,"aria-label":"Change reasoning level",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:V?"0 6px":"8px 12px",width:V?"auto":void 0,height:32,background:er?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize: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=er?"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"})]}),(!V||eo)&&(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:tx})]}),er&&(0,n.jsx)("div",{style:{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)",overflow:"hidden",minWidth:180},children:tb.filter(e=>!j||"auto"===e||j.includes(e)).map(e=>{let t=(b??"auto")===e,r=tk[e],o="auto"!==e&&w?w[e]:void 0,i=null!=o&&o!==e?o:e,l=null!=o&&o!==e;return(0,n.jsxs)("button",{onClick:()=>{en(!1),t||k(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: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:[i,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)})})]}),!l&&y&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&et(e=>!e),disabled:l,title:`Change tool preset: ${tM}`,"aria-label":"Change tool preset",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:V?"0 6px":"8px 12px",width:V?"auto":void 0,height:32,background:ee?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize: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=ee?"var(--bg-hover)":"none",e.currentTarget.style.color="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"})}),(!V||eo)&&(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:tM})]}),ee&&(0,n.jsx)("div",{style:{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)",overflow:"hidden",minWidth:120},children:tf.map(e=>{let t=tm[e],r=(v??"default")===t,o="off"===e?"No tools, read-only":"default"===e?"4 built-in tools":"All built-in tools";return(0,n.jsxs)("button",{onClick:()=>{et(!1),r||y(t)},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:"pointer",fontSize:12,textAlign:"left",fontWeight:r?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{r||(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&&h&&(0,n.jsxs)("div",{style:{position:"relative"},children:[f&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",right:0,background:"#1f2937",color:"#f87171",fontSize:11,padding:"4px 8px",borderRadius:5,whiteSpace:"nowrap",pointerEvents:"none",boxShadow:"0 2px 8px rgba(0,0,0,0.2)",zIndex:50},children:f}),(0,n.jsx)("button",{onClick:g?x:h,disabled:l&&!g,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:V?"0 6px":"8px 12px",width:V?"auto":void 0,height:32,background:g?"rgba(239,68,68,0.08)":"none",border:"none",borderRadius:9,color:g?"#ef4444":"var(--text-muted)",cursor:l&&!g?"not-allowed":"pointer",fontSize:12,opacity:l&&!g?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{(!l||g)&&(e.currentTarget.style.background=g?"rgba(239,68,68,0.16)":"var(--bg-hover)",e.currentTarget.style.color=g?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=g?"rgba(239,68,68,0.08)":"none",e.currentTarget.style.color=g?"#ef4444":"var(--text-muted)"},title:g?"Stop compaction":"Compact context","aria-label":g?"Stop compaction":"Compact context",children:g?(0,n.jsxs)(n.Fragment,{children:[(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"})}),(!V||eo)&&(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:"Compacting…"})]}):(0,n.jsxs)(n.Fragment,{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)("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"})]}),(!V||eo)&&(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:"Compact"})]})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"Stop agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:32,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:9,color:"#ef4444",cursor:"pointer",fontSize: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"]}),void 0!==M&&(0,n.jsx)("button",{onClick:M,title:W?"Disable completion sound":"Enable completion sound","aria-label":W?"Disable completion sound":"Enable completion sound",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:W?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:W?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=W?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=W?"1":"0.55"},children:W?(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"})]})}),V&&eo&&(0,n.jsx)("button",{type:"button",title:"Collapse controls","aria-label":"Collapse controls","aria-expanded":!0,onClick:()=>{et(!1),en(!1),ei(!1)},style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:32,padding:0,marginLeft:0,background:"var(--bg-hover)",border:"none",borderLeft:"1px solid color-mix(in srgb, var(--border) 72%, transparent)",borderRadius:"0 9px 9px 0",color:"var(--text)",cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]})]})]})]})});function tE(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 t$({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(null),v=(0,o.useRef)(!1),y=(0,o.useRef)(null),b=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),k=(0,o.useRef)(b);k.current=b;let j=(0,o.useRef)(null);j.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(s(0),d(1)):(s(e.scrollTop/o),d(n/t));let l=i.current,a=[],c=0,p=k.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,o.useCallback)(()=>j.current(),[]);(0,o.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,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.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,o.useCallback)(e=>{if(!c)return;v.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),o=n>=0&&n<=a?n:a/2;S(r-o);let i=e=>{v.current&&S((e.clientY-t.top)/t.height-o)},s=()=>{v.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},[c,a,l,S]),T=y.current?.clientHeight??600,L=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.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,p,T]);if(!c)return null;let I=l*(1-a)*100,z=100*a,R=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),m(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();m((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:`${z}%`,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}}),p.map(e=>{let t=tE(e.msg),r=x&&R===e.index,o="user"===e.msg.role,i=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${i}%`,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:o?8:6,height:o?8:6,borderRadius:o?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&&p.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),o=tE(e.msg),i=R===e.index;return r&&0!==L.length?(0,n.jsx)("div",{style:{position:"absolute",top:L[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${i?o.border:"var(--border)"}`,borderRight:`1px solid ${i?o.border:"var(--border)"}`,borderBottom:`1px solid ${i?o.border:"var(--border)"}`,borderLeft:`2px solid ${o.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:i?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:i?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function tB(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 tA(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 tD=r(14755);function tP(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}}function tF(e){return{steering:e?.steering??[],followUp:e?.followUp??[]}}let tN=new Set(["ArrowUp","ArrowDown","PageUp","PageDown","Home","End"," ","Space","Spacebar"]);class tO extends Error{constructor(e){super("timeout"===e?"Timed out connecting to the agent event stream. Please try again.":"Failed to connect to the agent event stream. Please try again."),this.status=e,this.name="EventStreamConnectionError"}}function tH(e){return new Promise(t=>setTimeout(t,e))}function t_(e){let t=e.findIndex(e=>!e.exiting);return -1===t?e:e.map((e,r)=>r===t?{...e,exiting:!0}:e)}function tU(e,t){switch(t.type){case"add":if(e.visible.some(e=>e.exiting)||e.visible.length>=5)return{visible:e.visible.some(e=>e.exiting)?e.visible:t_(e.visible),pending:[...e.pending,t.notice]};return{...e,visible:[...e.visible,t.notice]};case"mark_oldest_exiting":return{...e,visible:t_(e.visible)};case"remove":return function(e,t){let r=e,n=t;for(;n.length>0&&r.length<5;){let[e,...t]=n;r=[...r,e],n=t}return n.length>0&&!r.some(e=>e.exiting)&&(r=t_(r)),{visible:r,pending:n}}(e.visible.filter(e=>e.id!==t.id),e.pending);default:return e}}function tK(e){if(!e||"object"!=typeof e||"image"!==e.type)return"";let t=e.source;return t&&"object"==typeof t?["url"===t.type?"url":"base64","string"==typeof t.media_type?t.media_type:"","string"==typeof t.data?t.data:"","string"==typeof t.url?t.url:""].join(":"):["base64","string"==typeof e.mimeType?e.mimeType:"","string"==typeof e.data?e.data:"",""].join(":")}function tq(e){let t,r=e.content;return"string"==typeof r?JSON.stringify({text:r,images:[]}):Array.isArray(r)?JSON.stringify({text:"string"==typeof(t=e.content)?t:Array.isArray(t)?t.map(e=>e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text?e.text:"").filter(Boolean).join("\n"):"",images:r.map(tK).filter(Boolean)}):JSON.stringify({text:"",images:[]})}function tV(e,t){return e&&"object"==typeof e?"number"!=typeof e.tokensBefore||"number"!=typeof e.estimatedTokensAfter?null:{reason:t,tokensBefore:e.tokensBefore,estimatedTokensAfter:e.estimatedTokensAfter}:null}function tY(e,t,r={}){let n={...e,content:t};return r.omitUsage&&(n.usage=void 0),n}function tJ({messageCount:e,toolCallCount:t,children:r}){let[i,l]=(0,o.useState)(!1),s=["Process details",`${e} ${1===e?"message":"messages"}`];return t>0&&s.push(`${t} ${1===t?"tool call":"tool calls"}`),(0,n.jsxs)("div",{style:{marginBottom:14},children:[(0,n.jsxs)("button",{type:"button","aria-expanded":i,onClick:()=>l(e=>!e),style:{display:"flex",alignItems:"center",gap:8,width:"auto",minHeight:24,padding:"2px 0",border:"none",background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},title:i?"Collapse process details":"Expand process details",children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:i?"rotate(90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"4 2.5 7.5 6 4 9.5"})}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.join(" \xb7 ")})]}),i&&(0,n.jsx)("div",{style:{marginTop:8},children:r})]})}function tZ({session:e,newSessionCwd:t,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,chatInputRef:d,onBranchDataChange:c,onSystemPromptChange:u,onSessionStatsChange:p,onSessionStatsPanelOpen:h,onContextUsageChange:x,onOpenFile:g}){var f;let m,{soundEnabled:v,onSoundToggle:y,playDoneSound:b,unlockAudio:k}=function(){let[e,t]=(0,o.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),r=(0,o.useRef)(e);(0,o.useEffect)(()=>{r.current=e},[e]);let n=(0,o.useRef)(null),i=(0,o.useCallback)(()=>{if(n.current&&"closed"!==n.current.state)return n.current;try{n.current=new AudioContext}catch{return null}return n.current},[]),l=(0,o.useCallback)((e=!1)=>{if(!e&&!r.current)return;let t=i();t&&"suspended"===t.state&&t.resume().catch(()=>{})},[i]);return{soundEnabled:e,onSoundToggle:(0,o.useCallback)(()=>{let e=!r.current;e&&l(!0),r.current=e,localStorage.setItem("pi-sound-enabled",String(e)),t(e)},[l]),playDoneSound:(0,o.useCallback)(()=>{if(!r.current)return;let e=i();if(!e)return;let t=()=>{try{let t;t=e.currentTime,[523.25,659.25].forEach((r,n)=>{let o=e.createOscillator(),i=e.createGain();o.connect(i),i.connect(e.destination),o.type="sine",o.frequency.value=r;let l=t+.18*n;i.gain.setValueAtTime(0,l),i.gain.linearRampToValueAtTime(.18,l+.02),i.gain.exponentialRampToValueAtTime(.001,l+.45),o.start(l),o.stop(l+.45)})}catch{}};"suspended"===e.state?e.resume().then(t).catch(()=>{}):t()},[i]),unlockAudio:l,soundEnabledRef:r}}(),j=tg(),w=(0,o.useRef)(b);w.current=b;let S=(0,o.useRef)(v);S.current=v;let{loading:C,error:T,messages:L,entryIds:I,streamState:z,agentRunning:R,modelNames:W,modelList:M,modelThinkingLevels:E,modelThinkingLevelMaps:$,toolPreset:B,thinkingLevel:A,retryInfo:D,contextUsage:P,forkingEntryId:F,isCompacting:N,compactError:O,compactResult:H,displayModel:_,sessionStats:U,slashCommands:K,slashCommandsLoading:q,queuedMessages:V,notices:Y,extensionDialog:J,extensionCustomUi:Z,extensionStatuses:X,extensionWidgets:G,respondToExtensionUi:Q,sendExtensionCustomInput:ee,isAutoModelSelection:et,agentPhase:er,isNew:en,messagesEndRef:eo,scrollContainerRef:ei,lastUserMsgRef:el,handleSend:es,handleAbort:ea,handleFork:ed,handleNavigate:ec,handleModelChange:eu,handleCompact:ep,handleSteer:eh,handleFollowUp:ex,handlePromptWithStreamingBehavior:eg,handleAbortCompaction:ef,handleRecallQueue:eb,handleBuiltinSlashCommand:ek,handleToolPresetChange:ej,handleThinkingLevelChange:ew,loadSlashCommands:eS}=function(e){let{session:t,newSessionCwd:n,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,onBranchDataChange:d,onSystemPromptChange:c,onSessionStatsPanelOpen:u}=e,p=null===t&&null!==n,[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(!p),[m,v]=(0,o.useState)(null),[y,b]=(0,o.useState)(null),[k,j]=(0,o.useState)([]),[w,S]=(0,o.useState)([]),[C,T]=(0,o.useReducer)(tP,{isStreaming:!1,streamingMessage:null}),[L,I]=(0,o.useState)(!1),[z,R]=(0,o.useState)({}),[W,M]=(0,o.useState)([]),[E,$]=(0,o.useState)({}),[B,A]=(0,o.useState)({}),[D,P]=(0,o.useState)(null),[F,N]=(0,o.useState)(null),[O,H]=(0,o.useState)("default"),[_,U]=(0,o.useState)("auto"),[K,q]=(0,o.useState)(null),[V,Y]=(0,o.useState)(null),[J,Z]=(0,o.useState)(null),[X,G]=(0,o.useState)(null),[Q,ee]=(0,o.useState)(null),[et,er]=(0,o.useState)(null),[en,eo]=(0,o.useState)(!1),[ei,el]=(0,o.useState)(null),[es,ea]=(0,o.useState)(null),[ed,ec]=(0,o.useState)(null),[eu,ep]=(0,o.useState)([]),[eh,ex]=(0,o.useState)(!1),[eg,ef]=(0,o.useReducer)(tU,{visible:[],pending:[]}),[em,ev]=(0,o.useState)(null),[ey,eb]=(0,o.useState)(null),[ek,ej]=(0,o.useState)(null),[ew,eS]=(0,o.useState)([]),[eC,eT]=(0,o.useState)([]),[eL,eI]=(0,o.useState)({steering:[],followUp:[]}),ez=(0,o.useRef)(null),eR=(0,o.useRef)(null),eW=(0,o.useRef)(t?.id??null),eM=(0,o.useRef)(!1),eE=(0,o.useRef)(null),e$=(0,o.useRef)(!1),eB=(0,o.useRef)(null),eA=(0,o.useRef)(!1),eD=(0,o.useRef)(!0),eP=(0,o.useRef)(0),eF=(0,o.useRef)(0),eN=(0,o.useRef)(null),eO=(0,o.useRef)(null),eH=(0,o.useRef)(null),e_=(0,o.useRef)(!1),eU=(0,o.useRef)(0),eK=(0,o.useRef)(null),eq=e.setToolPreset??H,eV=Q??h?.context.model??et??null,eY=p?D??F:eV,eJ=(()=>{if(em)return em;let e={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},r=0,n=0,o=0,i=0,l=0;for(let t of k){if("user"===t.role&&(n+=1),"toolResult"===t.role&&(i+=1),"assistant"!==t.role)continue;o+=1;let s=t.usage;l+=t.content.filter(e=>"toolCall"===e.type).length,s&&(e.input+=s.input??0,e.output+=s.output??0,e.cacheRead+=s.cacheRead??0,e.cacheWrite+=s.cacheWrite??0,r+=s.cost?.total??0)}return(e.total=e.input+e.output+e.cacheRead+e.cacheWrite,0===e.total&&0===k.length)?null:{sessionFile:h?.filePath||void 0,sessionId:eW.current??t?.id??"",sessionName:t?.name,userMessages:n,assistantMessages:o,toolCalls:l,toolResults:i,totalMessages:k.length,tokens:e,cost:r,...V?{contextUsage:V}:{}}})(),eZ=(0,o.useCallback)(async(e,t=!1,r=!1)=>{try{t&&f(!0);let n=r?`/api/sessions/${encodeURIComponent(e)}?includeState`:`/api/sessions/${encodeURIComponent(e)}`,o=await fetch(n);if(404===o.status)return t&&(x(null),b(null),j([]),v(null)),null;if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();x(i),b(i.leafId),j(i.context.messages),S(i.context.entryIds??[]),ee(null),v(null);let l=i.agentState?.state;return l?(void 0!==l.contextUsage&&Y(l.contextUsage??null),void 0!==l.systemPrompt&&Z(l.systemPrompt??null),void 0!==l.thinkingLevel&&U(l.thinkingLevel??"auto"),void 0!==l.extensionStatuses&&eS(l.extensionStatuses??[]),void 0!==l.extensionWidgets&&eT(l.extensionWidgets??[]),void 0!==l.queuedMessages&&eI(tF(l.queuedMessages))):i.agentState&&!i.agentState.running&&eI({steering:[],followUp:[]}),!l?.thinkingLevel&&i.context.thinkingLevel&&"off"!==i.context.thinkingLevel&&U(i.context.thinkingLevel),i.agentState??null}catch(e){return v(String(e)),null}finally{t&&f(!1)}},[]),eX=(0,o.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 o=await n.json();j(o.context.messages),S(o.context.entryIds??[])}catch(e){console.error("Failed to load context:",e)}},[]),eG=(0,o.useCallback)(async e=>{try{let t=await tA(e,{type:"get_tools"});if(t){let{getPresetFromTools:e}=await Promise.resolve().then(r.bind(r,14755));eq(e(t))}}catch(e){console.error("Failed to load tools:",e)}},[eq]),eQ=(0,o.useCallback)((e=0,t="(no messages)")=>{let r=eW.current;p&&n&&r&&!e_.current&&(e_.current=!0,l?.({id:r,path:"",cwd:n,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:e,firstMessage:t}))},[p,n,l]),e0=(0,o.useCallback)(async()=>{if(eW.current||!p||!n)return eW.current;if(eH.current)return eH.current;let e=(async()=>{let e=D??F;e&&er(e);let t=(0,tD.xG)(O),r=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,type:"ensure_session",toolNames:t,...e?{provider:e.provider,modelId:e.modelId}:{},..."auto"!==_?{thinkingLevel:_}:{}})});if(!r.ok)throw Error(`HTTP ${r.status}`);let o=(await r.json()).sessionId;return eW.current=o,o})();eH.current=e;try{return await e}finally{eH.current=null}},[p,n,D,F,O,_]),e1=(0,o.useCallback)(async()=>{let e=eW.current??await e0();if(!e)return ep([]),[];ex(!0);try{let t=await tA(e,{type:"get_commands"}),r=t?.commands??[];return ep(r),r}catch(e){return console.error("Failed to load slash commands:",e),ep([]),[]}finally{ex(!1)}},[e0]),e2=(0,o.useCallback)(e=>{ez.current&&(ez.current.close(),ez.current=null,eR.current=null);let t=new EventSource(`/api/agent/${encodeURIComponent(e)}/events`);return ez.current=t,eR.current=e,new Promise(r=>{let n=!1,o=e=>{n||(n=!0,clearTimeout(i),r({status:e,source:t}))},i=setTimeout(()=>o("timeout"),1e4);t.onmessage=e=>{try{let t=JSON.parse(e.data);"connected"===t.type&&o("connected"),eE.current?.(t)}catch{}},t.onerror=()=>{t.readyState===EventSource.CLOSED&&(o("closed"),ez.current===t&&eM.current&&(ez.current=null,eR.current=null,setTimeout(()=>{eM.current&&e2(e)},1e3)))}})},[]),e4=(0,o.useCallback)(async e=>{let t=ez.current;if(t&&eR.current===e&&t.readyState===EventSource.OPEN)return;let r=await e2(e);if("connected"!==r.status&&r.source.readyState!==EventSource.OPEN)throw ez.current===r.source&&(ez.current=null,eR.current=null),r.source.close(),new tO(r.status)},[e2]),e5=(0,o.useCallback)(async(e,t)=>{let r=eW.current;if(eb(t=>t?.id===e.id?null:t),r)try{await tA(r,{type:"extension_ui_response",id:e.id,...t})}catch(e){console.error("Failed to send extension UI response:",e)}},[]),e6=(0,o.useCallback)(async(e,t)=>{let r=eW.current;if(r)try{await tA(r,{type:"extension_ui_input",id:e.id,data:t})}catch(e){console.error("Failed to send extension custom UI input:",e)}},[]),e8=(0,o.useCallback)(e=>{let t=e.message.trim();t&&ef({type:"add",notice:{id:e.id??("u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`),message:t,type:e.type??"info"}})},[]),e3=(0,o.useCallback)(t=>{switch(t.method){case"select":case"confirm":case"input":case"editor":eb(t);break;case"notify":e8({id:t.id,message:t.message,type:t.notifyType??"info"});break;case"setStatus":eS(e=>{let r=e.filter(e=>e.key!==t.statusKey);return t.statusText?[...r,{key:t.statusKey,text:t.statusText}]:r});break;case"setWidget":eT(e=>{let r=e.filter(e=>e.key!==t.widgetKey);return t.widgetLines?[...r,{key:t.widgetKey,lines:t.widgetLines,placement:t.widgetPlacement??"aboveEditor"}]:r});break;case"setTitle":t.title&&(document.title=t.title);break;case"set_editor_text":e.chatInputRef?.current?.insertText(t.text);break;case"custom":ej(e=>t.closed?e?.id===t.id?null:e:t)}},[e8,e.chatInputRef]),e9=(0,o.useCallback)(async(e=eW.current,t)=>{if(void 0===t||eU.current===t)try{e&&await eZ(e)}finally{if(void 0!==t&&eU.current!==t||(eK.current=null,!eM.current))return;eM.current=!1,I(!1),ec(null),q(null),T({type:"end"}),i?.()}},[eZ,i]),e7=(0,o.useCallback)(async(e,t)=>{await tH(800);let r=Date.now();for(;eM.current&&Date.now()-r<2e4;){if(void 0!==t&&eU.current!==t)return;try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(r.ok){let n=await r.json(),o=n.state;if(!n.running||!o||!o.isStreaming&&!o.isPromptRunning)return void await e9(e,t)}}catch{}await tH(600)}},[e9]),te=(0,o.useCallback)(async e=>{if(!eM.current)return;let t=eU.current;try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)return;let n=await r.json();if(eU.current!==t)return;let o=n.state;if(eo(o?.isCompacting??!1),eI(tF(o?.queuedMessages)),n.running&&o&&(o.isStreaming||o.isPromptRunning||o.isCompacting)||!eM.current)return;o&&(void 0!==o.contextUsage&&Y(o.contextUsage??null),void 0!==o.systemPrompt&&Z(o.systemPrompt??null),void 0!==o.extensionStatuses&&eS(o.extensionStatuses??[]),void 0!==o.extensionWidgets&&eT(o.extensionWidgets??[])),await e9(e,t)}catch{}},[e9]);(0,o.useEffect)(()=>{if(!L)return;let e=()=>{let e=eW.current;e&&te(e)},t=()=>{"visible"===document.visibilityState&&e()},r=setInterval(e,15e3);return document.addEventListener("visibilitychange",t),window.addEventListener("online",e),()=>{clearInterval(r),document.removeEventListener("visibilitychange",t),window.removeEventListener("online",e)}},[L,te]),(0,o.useEffect)(()=>{eM.current=L},[L]),eE.current=(0,o.useCallback)(e=>{switch(e.type){case"agent_start":eM.current=!0,I(!0),ec({kind:"waiting_model"}),T({type:"start"});break;case"agent_end":if(!eM.current)break;eM.current=!1,I(!1),ec(null),q(null),T({type:"end"}),eW.current&&(eZ(eW.current),fetch(`/api/agent/${encodeURIComponent(eW.current)}`).then(e=>e.json()).then(e=>{e.state?.contextUsage!==void 0&&Y(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&Z(e.state.systemPrompt??null),e.state?.extensionStatuses!==void 0&&eS(e.state.extensionStatuses??[]),e.state?.extensionWidgets!==void 0&&eT(e.state.extensionWidgets??[]),eI(tF(e.state?.queuedMessages))}).catch(()=>{})),i?.();break;case"prompt_done":if(!eM.current)break;e9(eW.current);break;case"prompt_error":e8({type:"error",message:e.errorMessage??"Command failed"});break;case"extension_error":e8({type:"error",message:e.error??"Extension command failed"});break;case"message_start":case"message_update":{if(!eM.current)break;let t=e.message;if(t?.role==="user")break;t&&T({type:"update",message:tB(t)}),ec(null);break}case"message_end":{if(!eM.current)break;let t=e.message;if(t&&"user"===t.role){let e=tB(t),r=tq(e),n=eK.current;eK.current=null,j(t=>{let o=t[t.length-1];return n&&o?.role==="user"&&tq(o)===n?n===r?t:[...t.slice(0,-1),e]:[...t,e]})}else t&&j(e=>[...e,tB(t)]);T({type:"reset"}),ec({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,r=e.toolName;ec(e=>{let n=e?.kind==="running_tools"?[...e.tools]:[];return n.some(e=>e.id===t)||n.push({id:t,name:r}),{kind:"running_tools",tools:n}});break}case"tool_execution_end":{let t=e.toolCallId;ec(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"queue_update":eI({steering:[...e.steering??[]],followUp:[...e.followUp??[]]});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":eo(!0),el(null),ea(null);break;case"auto_compaction_end":case"compaction_end":eo(!1),e.errorMessage?(el(e.errorMessage),ea(null)):!e.aborted&&(ea(tV(e.result,e.reason??"auto")),eW.current&&eZ(eW.current));break;case"extension_ui_request":e3(e)}},[e8,e9,e3,eZ,i]);let tt=(0,o.useCallback)(async(e,r)=>{let o=e.trim();if(!o&&!r?.length||L)return;let i=!r?.length&&o.startsWith("/"),l=eU.current+1,s=r?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),a={role:"user",content:s?.length?[...e.trim()?[{type:"text",text:e}]:[],...s]:e,timestamp:Date.now()};j(e=>[...e,a]),eK.current=tq(a),eU.current=l,eM.current=!0,I(!0),ec(i?{kind:"running_command"}:{kind:"waiting_model"}),T({type:"start"}),eA.current=!0,eD.current=!0;let d=r?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{let r=null;if(p&&n){let t=eW.current??await eH.current,n=t??await e0();n&&(r=n,D&&(er(D),t&&await tA(n,{type:"set_model",provider:D.provider,modelId:D.modelId})),await e4(n),await tA(n,{type:"prompt",message:e,...d?.length?{images:d}:{}}),eQ(1,e))}else t&&(r=t.id,await e4(t.id),await tA(t.id,{type:"prompt",message:e,...d?.length?{images:d}:{}}));i&&r&&e7(r,l)}catch(e){if(console.error("Failed to send message:",e),e instanceof tO){let t=eK.current;t&&j(e=>{let r=e[e.length-1];return r?.role==="user"&&tq(r)===t?e.slice(0,-1):e}),e8({type:"error",message:e.message})}eK.current=null,eM.current=!1,I(!1),ec(null),T({type:"end"})}},[p,n,D,t,L,e0,e4,eQ,e7,e8]),tr=(0,o.useCallback)(async()=>{let e=eW.current;if(e)try{await tA(e,{type:"abort"})}catch(e){console.error("Failed to abort:",e)}},[]),tn=(0,o.useCallback)(async e=>{let t=eW.current;if(t){G(e);try{let{cancelled:r,newSessionId:n}=await tA(t,{type:"fork",entryId:e})??{};!r&&n&&s?.(n)}catch(e){console.error("Fork failed:",e)}finally{G(null)}}},[s]),to=(0,o.useCallback)(async e=>{let t=eW.current;t&&(tA(t,{type:"navigate_tree",targetId:e}).catch(()=>{}),b(e),await eX(t,e))},[eX]),ti=(0,o.useCallback)(async(e,t)=>{b(e);let r=eW.current;r&&(e&&await tA(r,{type:"navigate_tree",targetId:e,summarize:t?.summarize,customInstructions:t?.customInstructions}).catch(()=>{}),await eX(r,e))},[eX]),tl=(0,o.useCallback)(async(e,t)=>{let r=eW.current;if(r)try{await tA(r,{type:"set_label",targetId:e,label:t}),await eZ(r)}catch(e){console.error("Set label failed:",e)}},[eZ]),ts=(0,o.useCallback)(async(e,t)=>{if(p){P({provider:e,modelId:t}),er({provider:e,modelId:t});let r=eW.current??await eH.current;if(!r)return;try{await tA(r,{type:"set_model",provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}return}let r=eW.current;if(r)try{await tA(r,{type:"set_model",provider:e,modelId:t}),ee({provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}},[p,P]),ta=(0,o.useCallback)(async()=>{let e=eW.current;if(e&&!en){eo(!0),el(null),ea(null);try{let t=await tA(e,{type:"compact"});ea(tV(t,"manual")),await eZ(e,!0)}catch(e){el(e instanceof Error?e.message:String(e)),ea(null)}finally{eo(!1)}}},[en,eZ]),td=(0,o.useCallback)(async e=>{let r=n??t?.cwd??"",o=r?`/api/models?cwd=${encodeURIComponent(r)}`:"/api/models",i=await fetch(o,e?{signal:e}:void 0);if(!i.ok)throw Error(`HTTP ${i.status}`);let l=await i.json();R(l.models),$(l.thinkingLevels??{}),A(l.thinkingLevelMaps??{});let s=l.modelList??[];if(M(s),p){let e=(l.defaultModel?s.find(e=>e.id===l.defaultModel?.modelId&&e.provider===l.defaultModel?.provider):void 0)??s[0];N(e?{provider:e.provider,modelId:e.id}:null)}},[p,n,t?.cwd]),tc=(0,o.useCallback)(async e=>{if(!e.startsWith("/"))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,r,n=""]=t,o=n.trim(),i=eW.current??await e0(),l=e=>(e.handled&&(e.error?e8({type:"error",message:e.error}):"openSessionStats"!==e.action&&e8({type:"success",message:e.message??"Command completed"})),e);try{switch(r){case"compact":{if(!i||en)return l({handled:!0,error:"No active session to compact"});eo(!0),el(null),ea(null);let e=await tA(i,{type:"compact",...o?{customInstructions:o}:{}});return ea(tV(e,"manual")),await eZ(i,!0)&&eQ(),l({handled:!0,message:"Compacted context"})}case"reload":if(!i)return l({handled:!0,error:"No active session to reload"});return await tA(i,{type:"reload"}),await Promise.all([eZ(i,!1,!0),eG(i),e1(),td()]),l({handled:!0,message:"Reloaded session resources"});case"name":if(!i)return l({handled:!0,error:"No active session to name"});if(!o)return l({handled:!0,error:"Usage: /name <name>"});return await tA(i,{type:"set_session_name",name:o}),await eZ(i)&&eQ(),l({handled:!0,message:`Session renamed to ${o}`});case"session":{if(!i)return l({handled:!0,error:"No active session"});let e=await tA(i,{type:"get_session_stats"});return e&&ev(e),u?.(),l({handled:!0,action:"openSessionStats"})}case"copy":{if(!i)return l({handled:!0,error:"No active session"});let e=await tA(i,{type:"get_last_assistant_text"}),t=e?.text??"";if(!t)return l({handled:!0,error:"No assistant message to copy"});return await navigator.clipboard.writeText(t),l({handled:!0,message:"Copied last assistant message"})}default:return{handled:!1}}}catch(e){return l({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{"compact"===r&&eo(!1)}},[e8,e0,en,td,eZ,e1,eG,eQ,u]),tu=(0,o.useCallback)(async(e,t)=>{let r=eW.current;if(!r)return;let n=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await tA(r,{type:"steer",message:e,...n?.length?{images:n}:{}})}catch(e){console.error("Failed to steer:",e)}},[]),tp=(0,o.useCallback)(async(e,t,r)=>{let n=eW.current;if(!n)return;let o=r?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await tA(n,{type:"prompt",message:e,streamingBehavior:t,...o?.length?{images:o}:{}})}catch(e){console.error("Failed to queue prompt:",e)}},[]),th=(0,o.useCallback)(async(e,t)=>{let r=eW.current;if(!r)return;let n=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await tA(r,{type:"follow_up",message:e,...n?.length?{images:n}:{}})}catch(e){console.error("Failed to follow up:",e)}},[]),tx=(0,o.useCallback)(async()=>{let e=eW.current;if(e)try{await tA(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),tg=(0,o.useCallback)(async()=>{let t=eW.current;if(t)try{let r=await tA(t,{type:"clear_queue"});eI({steering:[],followUp:[]});let n=[...r?.steering??[],...r?.followUp??[]];n.length>0&&e.chatInputRef?.current?.prependText(n.join("\n\n"))}catch(e){console.error("Failed to recall queued messages:",e),e8({type:"error",message:"Failed to recall queued messages"})}},[e.chatInputRef,e8]),tf=(0,o.useCallback)(async e=>{if(U(e),"auto"===e)return;let t=eW.current??await eH.current;if(t)try{await tA(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),tm=(0,o.useCallback)(async e=>{let t=(0,tD.xG)(e);eq(e);let r=eW.current??await eH.current;if(r)try{await tA(r,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[eq]),tv=(0,o.useCallback)((e="smooth")=>{eF.current=Date.now()+700,eN.current?.scrollIntoView({behavior:e})},[]),ty=(0,o.useCallback)(()=>{let e=eO.current,t=eB.current;if(!e||!t)return;let r=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop;eF.current=Date.now()+700,e.scrollTo({top:r-16,behavior:"smooth"})},[]),tb=(0,o.useCallback)(e=>{e instanceof KeyboardEvent&&(!tN.has(e.key)||e.target instanceof Element&&e.target.closest("input, textarea, [contenteditable='true']"))||(eP.current=Date.now()+1200)},[]),tk=(0,o.useCallback)(()=>{!eM.current||Date.now()<eF.current||Date.now()>eP.current||(eD.current=!1)},[]);return(0,o.useEffect)(()=>(t&&(eW.current=t.id,eZ(t.id,!0,!0).then(e=>{e?.running&&(eG(t.id),(e.state?.isStreaming||e.state?.isPromptRunning)&&(eM.current=!0,I(!0),ec(e.state.isStreaming?{kind:"waiting_model"}:{kind:"running_command"}),T({type:"start"}),e2(t.id),!e.state.isStreaming&&e.state.isPromptRunning&&e7(t.id))),e?.state&&(void 0!==e.state.isCompacting&&eo(e.state.isCompacting),void 0!==e.state.contextUsage&&Y(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&Z(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&U(e.state.thinkingLevel??"auto"),void 0!==e.state.extensionStatuses&&eS(e.state.extensionStatuses??[]),void 0!==e.state.extensionWidgets&&eT(e.state.extensionWidgets??[]),void 0!==e.state.queuedMessages&&eI(tF(e.state.queuedMessages)))})),()=>{ez.current?.close(),ez.current=null,eR.current=null}),[]),(0,o.useEffect)(()=>{c?.(J)},[J,c]),(0,o.useEffect)(()=>{d&&d(h?.tree??[],y,ti,tl)},[h?.tree,y,ti,d,tl]),(0,o.useEffect)(()=>(window.addEventListener("keydown",tb),window.addEventListener("pointerdown",tb,{passive:!0}),()=>{window.removeEventListener("keydown",tb),window.removeEventListener("pointerdown",tb)}),[tb]),(0,o.useEffect)(()=>{let e=eO.current;if(e)return e.addEventListener("wheel",tb,{passive:!0}),e.addEventListener("touchstart",tb,{passive:!0}),e.addEventListener("scroll",tk,{passive:!0}),()=>{e.removeEventListener("wheel",tb),e.removeEventListener("touchstart",tb),e.removeEventListener("scroll",tk)}},[k.length,g,tk,tb]),(0,o.useEffect)(()=>{k.length>0&&(eA.current?(eA.current=!1,e$.current=!0,ty()):e$.current?!eM.current&&eD.current&&tv("smooth"):(e$.current=!0,tv("instant")))},[k.length,L,tv,ty]),(0,o.useEffect)(()=>{let e=new AbortController;return td(e.signal).catch(e=>{if(e instanceof DOMException&&"AbortError"===e.name)return}),()=>e.abort()},[td,a]),(0,o.useEffect)(()=>{if(!ei)return;let e=setTimeout(()=>el(null),3e3);return()=>clearTimeout(e)},[ei]),(0,o.useEffect)(()=>{if(!es)return;let e=setTimeout(()=>ea(null),6e3);return()=>clearTimeout(e)},[es]),(0,o.useEffect)(()=>{if(0===eg.visible.length)return;let e=eg.visible.find(e=>e.exiting);if(e){let t=setTimeout(()=>{ef({type:"remove",id:e.id})},180);return()=>clearTimeout(t)}if(!eg.visible[0])return;let t=setTimeout(()=>{ef({type:"mark_oldest_exiting"})},5e3);return()=>clearTimeout(t)},[eg.visible]),(0,o.useEffect)(()=>{ev(null)},[k.length,V?.tokens,V?.percent,V?.contextWindow]),{data:h,loading:g,error:m,activeLeafId:y,messages:k,entryIds:w,streamState:C,agentRunning:L,modelNames:z,modelList:W,modelThinkingLevels:E,modelThinkingLevelMaps:B,newSessionModel:D,toolPreset:O,thinkingLevel:_,retryInfo:K,contextUsage:V,systemPrompt:J,forkingEntryId:X,isCompacting:en,compactError:ei,compactResult:es,currentModel:eV,displayModel:eY,sessionStats:eJ,slashCommands:eu,slashCommandsLoading:eh,queuedMessages:eL,notices:eg.visible,extensionDialog:ey,extensionCustomUi:ek,extensionStatuses:ew,extensionWidgets:eC,respondToExtensionUi:e5,sendExtensionCustomInput:e6,isAutoModelSelection:p&&null===D,agentPhase:ed,isNew:p,sessionIdRef:eW,eventSourceRef:ez,messagesEndRef:eN,scrollContainerRef:eO,lastUserMsgRef:eB,pendingScrollToUserRef:eA,initialScrollDoneRef:e$,handleSend:tt,handleAbort:tr,handleFork:tn,handleNavigate:to,handleModelChange:ts,handleCompact:ta,handleSteer:tu,handleFollowUp:th,handlePromptWithStreamingBehavior:tp,handleAbortCompaction:tx,handleRecallQueue:tg,handleBuiltinSlashCommand:tc,handleToolPresetChange:tm,handleThinkingLevelChange:tf,loadTools:eG,loadSlashCommands:e1,setActiveLeafId:b,setData:x,setMessages:j,dispatch:T,setAgentRunning:I,setForkingEntryId:G,handleAgentEventRef:eE}}({session:e,newSessionCwd:t,onAgentEnd:(0,o.useCallback)(()=>{S.current&&w.current(),i?.()},[i]),onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,chatInputRef:d,onBranchDataChange:c,onSystemPromptChange:u,onSessionStatsPanelOpen:h}),eC=U?[U.sessionId,U.sessionFile??"",U.sessionName??"",U.userMessages,U.assistantMessages,U.toolCalls,U.toolResults,U.totalMessages,U.tokens.input,U.tokens.output,U.tokens.cacheRead,U.tokens.cacheWrite,U.tokens.total,U.cost??0].join("|"):null,eT=(0,o.useRef)(U);eT.current=U,(0,o.useEffect)(()=>{p?.(eT.current)},[eC,p]),(0,o.useEffect)(()=>()=>{p?.(null)},[p]);let eL=P?`${P.percent??"null"}|${P.contextWindow}|${P.tokens??"null"}`:null,eI=(0,o.useRef)(P);eI.current=P,(0,o.useEffect)(()=>{x?.(eI.current)},[eL,x]),(0,o.useEffect)(()=>()=>{x?.(null)},[x]);let{isDragOver:ez,handleDragEnter:eR,handleDragOver:eW,handleDragLeave:eM,handleDrop:eE}=function(e){let[t,r]=(0,o.useState)(!1),n=(0,o.useRef)(0),i=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,o.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:i,handleDragOver:l,handleDragLeave:(0,o.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,o.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}((0,o.useCallback)(e=>{R||d?.current?.addImages(e)},[R,d])),e$=(f=L.filter(e=>"user"===e.role||"assistant"===e.role).length,(m=(0,o.useRef)([])).current=Array(f).fill(null).map((e,t)=>m.current[t]??null),m),eB=en&&0===L.length&&!z.isStreaming&&!R,eA=e?.cwd??t??void 0,eD=_?E[`${_.provider}:${_.modelId}`]??null:null,eP=_?$[`${_.provider}:${_.modelId}`]??null:null,eF=(0,n.jsx)(tM,{ref:d,onSend:es,onAbort:ea,onSteer:R?eh:void 0,onFollowUp:R?ex:void 0,onPromptWithStreamingBehavior:R?eg:void 0,isStreaming:R,model:_,isAutoModelSelection:et,modelNames:W,modelList:M,onModelChange:eu,onCompact:e||en?ep:void 0,onAbortCompaction:ef,isCompacting:N,compactError:O,compactResult:H,toolPreset:B,onToolPresetChange:e||en?ej:void 0,thinkingLevel:A,onThinkingLevelChange:e||en?ew:void 0,availableThinkingLevels:eD,thinkingLevelMap:eP,retryInfo:D,queuedMessages:V,onRecallQueue:eb,slashCommands:K,slashCommandsLoading:q,onLoadSlashCommands:eS,onBuiltinCommand:ek,soundEnabled:v,onSoundToggle:y,onAudioUnlock:k,draftKey:e?.id??(t?`new:${t}`:void 0),cwd:e?.cwd??t}),eN=G.filter(e=>"belowEditor"!==e.placement),eO=G.filter(e=>"belowEditor"===e.placement);return C?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):T?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:T}):(0,n.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:eR,onDragOver:eW,onDragLeave:eM,onDrop:eE,children:[ez&&!R&&(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"})]})]})]}),J&&(0,n.jsx)(t0,{request:J,onRespond:Q}),Z&&(0,n.jsx)(t1,{request:Z,onInput:ee}),eB?(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",alignItems:"center",justifyContent:"space-between",gap:12,marginLeft:16,marginRight:52,fontFamily:"var(--font-mono)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0,flex:1,lineHeight:1.4,overflow:"hidden"},children:[(0,n.jsx)("span",{style:{fontSize:28,fontWeight:700,letterSpacing:0,color:"var(--text)",flexShrink:0,whiteSpace:"nowrap"},children:"π"}),(0,n.jsx)("span",{style:{fontSize:22,color:"var(--text)",fontWeight:700,letterSpacing:0,flexShrink:0,whiteSpace:"nowrap"},children:"Pi Agent Web"})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:2,flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["web ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.8.0"]})]}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["pi ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.80.6"]})]})]})]}),(0,n.jsx)(tQ,{notices:Y,align:"right"}),eF]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,n.jsx)("div",{style:{position:"absolute",top:12,left:0,right:36*!j,zIndex:40,padding:"0 16px",pointerEvents:"none"},children:(0,n.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,n.jsx)(tQ,{notices:Y,floating:!0,align:"right"})})}),(0,n.jsx)("div",{ref:ei,className:"flex-1 overflow-y-auto pt-4 [scrollbar-width:none]",children:(0,n.jsx)("div",{style:{padding:"0 16px"},children:(0,n.jsxs)("div",{style:{maxWidth:820,margin:"0 auto"},children:[(0,n.jsx)(tX,{statuses:X}),(0,n.jsx)(tG,{widgets:eN}),(()=>{let e=new Map;for(let t of L)"toolResult"===t.role&&e.set(t.toolCallId,t);let t=-1;for(let e=L.length-1;e>=0;e--)if("user"===L[e].role){t=e;break}let r=new Map,o=0;L.forEach((e,t)=>{("user"===e.role||"assistant"===e.role)&&r.set(t,o++)});let i=(o,i={})=>{let l=i.messageOverride??L[o],s="user"===l.role&&o>0&&"assistant"===L[o-1].role?I[o-1]:void 0,a="user"===l.role||"assistant"===l.role,c=r.get(o),u=i.keyPrefix??"message",p=!1;if("assistant"===l.role){p=!0;for(let e=o+1;e<L.length;e++){let t=L[e].role;if("user"===t)break;if("assistant"===t){p=!1;break}}p&&z.isStreaming&&o===L.length-1&&(p=!1)}void 0!==i.showTimestamp&&(p=i.showTimestamp);let h=(0,n.jsx)(eZ,{message:l,toolResults:e,modelNames:W,cwd:eA,onOpenFile:g,entryId:I[o],onFork:R||en||0===o&&"user"===l.role?void 0:ed,forking:F===I[o],onNavigate:R?void 0:ec,prevAssistantEntryId:R?void 0:s,onEditContent:e=>d?.current?.insertIfEmpty(e),showTimestamp:p,prevTimestamp:o>0?L[o-1].timestamp:void 0},`${u}-view-${o}`);return a&&!1!==i.attachRef&&void 0!==c?(0,n.jsx)("div",{ref:e=>{e$.current[c]=e,o===t&&(el.current=e)},children:h},`${u}-${o}`):h},l=[];for(let e=0;e<L.length;){if("user"!==L[e].role){l.push(i(e)),e+=1;continue}let o=e,s=o+1;for(;s<L.length&&"user"!==L[s].role;)s+=1;let a=function(e,t,r){for(let o=r-1;o>t;o--){var n;if("assistant"===(n=e[o]).role&&ev(n).answerBlocks.some(e=>"image"===e.type||"text"===e.type&&e.text.trim().length>0))return o}for(let n=r-1;n>t;n--)if(e[n]?.role==="assistant")return n;return -1}(L,o,s);if(-1===a||(R||z.isStreaming)&&s===L.length&&o===t){for(let e=o;e<s;e++)l.push(i(e));e=s;continue}l.push(i(o));let d=[];for(let e=o+1;e<a;e++)d.push(e);let c=d.filter(e=>{var t;return"assistant"===(t=L[e]).role?em(t).length>0:"custom"===t.role}),u=L[a],p=ev(u),h=p.processBlocks.length>0?tY(u,p.processBlocks,{omitUsage:!0}):null,x=p.answerBlocks.length>0?tY(u,p.answerBlocks):null,g=c.length+ +!!h;if(g>0){let e=c.map(e=>r.get(e)).find(e=>"number"==typeof e)??(x?void 0:r.get(a)),t=(0,n.jsxs)(tJ,{messageCount:g,toolCallCount:function(e,t){let r=0;for(let n of t){let t=e[n];t?.role==="assistant"&&(r+=ey(em(t)))}return r}(L,c)+ey(p.processBlocks),children:[c.map(e=>i(e,{attachRef:!1,keyPrefix:"process"})),h&&i(a,{attachRef:!1,keyPrefix:"process-final",messageOverride:h,showTimestamp:!1})]});l.push((0,n.jsx)("div",{ref:void 0===e?void 0:t=>{e$.current[e]=t},children:t},`process-group-${o}-${a}`))}x&&l.push(i(a,{messageOverride:x}));for(let e=a+1;e<s;e++)l.push(i(e));e=s}return l})(),z.isStreaming&&z.streamingMessage&&(0,n.jsx)(eZ,{message:z.streamingMessage,isStreaming:!0,modelNames:W,cwd:eA,onOpenFile:g}),R&&!z.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...":e?.kind==="running_command"?"Running command...":"Thinking..."}(er)})}),R&&(0,n.jsx)("div",{style:{height:ei.current?ei.current.clientHeight:"80vh"}}),(0,n.jsx)("div",{ref:eo})]})})}),j?null:(0,n.jsx)(t$,{messages:L,streamingMessage:z.streamingMessage,scrollContainer:ei,messageRefs:e$})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{style:{padding:"0 16px",paddingRight:j?16:52},children:(0,n.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,n.jsx)(tG,{widgets:eO})})}),eF]})]})]})}function tX({statuses:e}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:e.map(e=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,maxWidth:"100%",padding:"4px 8px",border:"1px solid color-mix(in srgb, var(--accent) 24%, var(--border))",borderRadius:6,background:"color-mix(in srgb, var(--accent) 7%, var(--bg))",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:e.key}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.text})]},e.key))})}function tG({widgets:e}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:e.map(e=>(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"5px 9px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:e.key}),(0,n.jsx)("pre",{style:{margin:0,padding:"8px 9px",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:e.lines.join("\n")})]},e.key))})}function tQ({notices:e,floating:t=!1,align:r="left"}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",alignItems:"right"===r?"flex-end":"stretch",marginBottom:10*!t},children:e.map((r,o)=>{let i="error"===r.type?"#ef4444":"warning"===r.type?"#d97706":"success"===r.type?"#10b981":"var(--accent)";return(0,n.jsxs)("div",{className:"notice-shelf-item",style:{display:"flex",alignItems:"center",gap:10,minHeight:60,height:60,maxHeight:60,marginBottom:6*(o!==e.length-1),overflow:"hidden",borderRadius:14,border:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",background:"var(--bg)",color:"var(--text-muted)",width:"fit-content",maxWidth:"min(100%, 620px)",boxShadow:t?"0 1px 2px rgba(15,23,42,0.05), 0 10px 28px -14px rgba(15,23,42,0.24)":"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",fontSize:18,lineHeight:1.45,transformOrigin:"top center",animation:r.exiting?"notice-shelf-out 0.18s ease-in forwards":"notice-shelf-in 0.18s ease-out both",padding:"0 12px"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:i,flexShrink:0}}),(0,n.jsx)("span",{style:{padding:"14px 0",minWidth:0,maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.message})]},r.id)})})}function t0({request:e,onRespond:t}){let[r,i]=(0,o.useState)("editor"===e.method?e.prefill??"":"");(0,o.useEffect)(()=>{i("editor"===e.method?e.prefill??"":"")},[e]);let l=()=>{"confirm"===e.method?t(e,{confirmed:!0}):t(e,{value:r})};return(0,n.jsx)("div",{style:{position:"absolute",inset:0,zIndex:90,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",style:{width:"min(560px, 100%)",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:650},children:e.title}),(0,n.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:"extension request"})]}),(0,n.jsxs)("div",{style:{padding:14},children:["confirm"===e.method&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,lineHeight:1.6,whiteSpace:"pre-wrap"},children:e.message}),"select"===e.method&&(0,n.jsx)("div",{style:{display:"grid",gap:8},children:e.options.map(r=>(0,n.jsx)("button",{onClick:()=>t(e,{value:r}),style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:13},children:r},r))}),"input"===e.method&&(0,n.jsx)("input",{autoFocus:!0,value:r,placeholder:e.placeholder,onChange:e=>i(e.target.value),onKeyDown:r=>{"Enter"===r.key&&l(),"Escape"===r.key&&t(e,{cancelled:!0})},style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",fontSize:13}}),"editor"===e.method&&(0,n.jsx)("textarea",{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:r=>{"Escape"===r.key&&t(e,{cancelled:!0}),(r.metaKey||r.ctrlKey)&&"Enter"===r.key&&l()},style:{width:"100%",minHeight:220,padding:10,borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",resize:"vertical",fontSize:13,lineHeight:1.55,fontFamily:"var(--font-mono)"}})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 14px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{onClick:()=>t(e,{cancelled:!0}),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer"},children:"Cancel"}),"confirm"===e.method?(0,n.jsx)("button",{onClick:l,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:"Confirm"}):"select"!==e.method?(0,n.jsx)("button",{onClick:l,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:"Submit"}):null]})]})})}function t1({request:e,onInput:t}){let r=(0,o.useRef)(null),i=function(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,r=[];for(let n of e){let e=ep(n).trimEnd();if(t.test(e))continue;let o=n,i=eg(o);("│"===i||"┃"===i)&&" "===eg(o=ex(o,0))&&(o=ex(o,0));let l=function(e){let t=eh(e);for(let e=t.length-1;e>=0;e--)if(""!==t[e].char.trim())return e;return -1}(o),s=l>=0?eh(o)[l]?.char:void 0;("│"===s||"┃"===s)&&(o=ex(o,l)),r.push(function(e){let t=e;for(;;){let e=eh(t),r=e[e.length-1];if(!r||""!==r.char.trim())return t;t=t.slice(0,r.start)+t.slice(r.end)}}(o))}for(;r.length>0&&""===ep(r[0]).trim();)r.shift();for(;r.length>0&&""===ep(r[r.length-1]).trim();)r.pop();return r.length?r:e}(e.lines);return(0,o.useEffect)(()=>{r.current?.focus()},[e.id]),(0,n.jsx)("div",{style:{position:"absolute",inset:0,zIndex:95,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,n.jsxs)("div",{ref:r,tabIndex:0,role:"dialog","aria-modal":"true",onKeyDown:r=>{let n=function(e){if(e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length){let t=e.key.toLowerCase();if(t>="a"&&t<="z")return String.fromCharCode(t.charCodeAt(0)-96)}switch(e.key){case"ArrowUp":return"\x1b[A";case"ArrowDown":return"\x1b[B";case"ArrowRight":return"\x1b[C";case"ArrowLeft":return"\x1b[D";case"Enter":return"\r";case"Escape":return"\x1b";case"Backspace":return"";case"Tab":return" ";case" ":return" ";default:if(!e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length)return e.key;return null}}(r);n&&(r.preventDefault(),r.stopPropagation(),t(e,n))},style:{width:"min(920px, 100%)",maxHeight:"min(760px, calc(100vh - 40px))",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden",outline:"none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650},children:"Extension panel"}),(0,n.jsx)("button",{onClick:()=>t(e,"\x03"),style:{padding:"5px 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Close"})]}),(0,n.jsx)("pre",{style:{margin:0,padding:14,maxHeight:"calc(min(760px, 100vh - 40px) - 48px)",overflow:"auto",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.45,whiteSpace:"pre"},children:(i.length?i:[""]).map((e,t,r)=>{var i;return(0,n.jsxs)(o.Fragment,{children:[(i=`line-${t}`,(function(e){let t,r=[],n={},o=0;for(ed.lastIndex=0;null!==(t=ed.exec(e));)t.index>o&&r.push({text:e.slice(o,t.index),style:n}),n=function(e,t){let r={...e};for(let e=0;e<t.length;e++){let n=t[e];if(0===n)for(let e of Object.keys(r))delete r[e];else if(1===n)r.fontWeight=700;else if(2===n)r.opacity=.65;else if(3===n)r.fontStyle="italic";else if(4===n)r.textDecoration="underline";else if(22===n)delete r.fontWeight,delete r.opacity;else if(23===n)delete r.fontStyle;else if(24===n)delete r.textDecoration;else if(39===n)delete r.color;else if(49===n)delete r.backgroundColor;else if(n>=30&&n<=37)r.color=ec[n-30];else if(n>=90&&n<=97)r.color=eu[n-90];else if(n>=40&&n<=47)r.backgroundColor=ec[n-40];else if(n>=100&&n<=107)r.backgroundColor=eu[n-100];else if((38===n||48===n)&&2===t[e+1]){let[o,i,l]=[t[e+2],t[e+3],t[e+4]];[o,i,l].every(e=>"number"==typeof e&&Number.isFinite(e))&&(38===n?r.color=`rgb(${o}, ${i}, ${l})`:r.backgroundColor=`rgb(${o}, ${i}, ${l})`),e+=4}else if((38===n||48===n)&&5===t[e+1]){let o=function(e){if(e>=0&&e<8)return ec[e];if(e>=8&&e<16)return eu[e-8];if(e>=16&&e<=231){let t=e-16,r=Math.floor(t/36),n=Math.floor(t%36/6),o=e=>0===e?0:55+40*e;return`rgb(${o(r)}, ${o(n)}, ${o(t%6)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}(t[e+2]);o&&(38===n?r.color=o:r.backgroundColor=o),e+=2}}return r}(n,t[1]?t[1].split(";").map(e=>Number(e||"0")):[0]),o=t.index+t[0].length;return o<e.length&&r.push({text:e.slice(o),style:n}),r})(e).map((e,t)=>Object.keys(e.style).length>0?(0,n.jsx)("span",{style:e.style,children:e.text},`${i}-${t}`):e.text)),t<r.length-1?"\n":null]},t)})})]})})}let t2={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",avif:"image/avif"},t4={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",oga:"audio/ogg",opus:"audio/ogg",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac",weba:"audio/webm",webm:"audio/webm"};function t5(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}function t6(e,t,r,n={}){let o=D(e),i=new URLSearchParams({type:t});for(let[e,t]of(r&&i.set("sessionId",r),Object.entries(n)))void 0!==t&&i.set(e,String(t));return`/api/files/${o}?${i.toString()}`}function t8({filePath:e,sourceSessionId:t}){return(0,n.jsx)("a",{href:t6(e,"download",t),download:P(e),title:"Download file",style:{display:"flex",alignItems:"center",justifyContent:"center",height:20,padding:"0 5px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,textDecoration:"none"},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)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})}function t3(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function t9({oldContent:e,newContent:t}){let r=function(e,t){let r=e.length,n=t.length,o=r+n,i=Array(2*o+1).fill(0),l=[];for(let s=0;s<=o;s++){l.push([...i]);for(let a=-s;a<=s;a+=2){let d,c=(d=a===-s||a!==s&&i[a-1+o]<i[a+1+o]?i[a+1+o]:i[a-1+o]+1)-a;for(;d<r&&c<n&&e[d]===t[c];)d++,c++;if(i[a+o]=d,d>=r&&c>=n){let i=[],a=r,d=n;for(let r=s;r>0;r--){let n,s=l[r-1],c=a-d;n=c===-r||c!==r&&s[c-1+o]<s[c+1+o]?c+1:c-1;let u=s[n+o],p=u-n;for(;a>u&&d>p;)a--,d--,i.unshift({type:"unchanged",text:e[a],lineNo:a+1});r>0&&(a>u?(a--,i.unshift({type:"removed",text:e[a],lineNo:a+1})):(d--,i.unshift({type:"added",text:t[d],lineNo:d+1})))}for(;a>0&&d>0;)a--,d--,i.unshift({type:"unchanged",text:e[a],lineNo:a+1});return i}}}return[...e.map((e,t)=>({type:"removed",text:e,lineNo:t+1})),...t.map((e,t)=>({type:"added",text:e,lineNo:t+1}))]}(e.split("\n"),t.split("\n"));if(!r.some(e=>"unchanged"!==e.type))return(0,n.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"No changes"});let o=new Set(r.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),i=new Set;for(let e of o)for(let t=Math.max(0,e-3);t<=Math.min(r.length-1,e+3);t++)i.add(t);let l=[],s=0;for(;s<r.length;)if(i.has(s)){let e=[];for(;s<r.length&&i.has(s);)e.push(r[s]),s++;l.push({hidden:!1,lines:e})}else{let e=0;for(;s<r.length&&!i.has(s);)e++,s++;l.push({hidden:!0,count:e})}let a=[],d=1;for(let e of r)"removed"===e.type?a.push(0):a.push(d++);let c=0;return(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6},children:l.map((e,t)=>{if(e.hidden){let r=(0,n.jsxs)("div",{style:{padding:"2px 16px",color:"var(--text-dim)",background:"var(--bg-panel)",fontSize:11,borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:["... ",e.count," unchanged lines ..."]},t);return c+=e.count,r}let r=e.lines.map((e,t)=>{let r=a[c+t],o="added"===e.type?"rgba(0,200,80,0.12)":"removed"===e.type?"rgba(240,60,60,0.14)":"transparent",i="added"===e.type?"+":"removed"===e.type?"-":" ",l="added"===e.type?"#4ade80":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,n.jsxs)("div",{style:{display:"flex",background:o,borderLeft:"added"===e.type?"3px solid #4ade80":"removed"===e.type?"3px solid #f87171":"3px solid transparent"},children:[(0,n.jsx)("span",{style:{minWidth:44,padding:"0 8px 0 16px",textAlign:"right",color:"var(--text-dim)",userSelect:"none",fontSize:11,lineHeight:1.6,borderRight:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:"removed"===e.type?e.lineNo:r||""}),(0,n.jsx)("span",{style:{minWidth:16,padding:"0 6px",color:l,userSelect:"none",flexShrink:0,fontWeight:600},children:i}),(0,n.jsx)("span",{style:{flex:1,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)",overflowX:"auto"},children:e.text||"\xa0"})]},t)});return c+=e.lines.length,(0,n.jsx)("div",{children:r},t)})})}function t7({filePath:e,cwd:t,sourceSessionId:r}){let[i,l]=(0,o.useState)(!1),[s,a]=(0,o.useState)(0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(null),g=(0,o.useRef)(null),f=P(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{a(0),c(null),p(null),x(null),l(!1),g.current&&(g.current.close(),g.current=null);let t=new EventSource(t6(e,"watch",r));return g.current=t,t.addEventListener("connected",()=>l(!0)),t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&c(t.size)}catch{}a(e=>e+1)}),t.addEventListener("error",()=>l(!1)),t.onerror=()=>l(!1),()=>{t.close(),g.current=null}},[e,r]);let m=t6(e,"read",r,s?{v:s}:void 0),v=null!=d?t3(d):null;return(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)"},title:e,children:F(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:f||"image"}),u&&(0,n.jsxs)("span",{children:[u.w," \xd7 ",u.h]}),v&&(0,n.jsx)("span",{children:v}),(0,n.jsxs)("span",{title:i?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:i?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:i?"#4ade80":"var(--border)",display:"inline-block",boxShadow:i?"0 0 4px #4ade80":"none"}}),i?"live":"static"]}),(0,n.jsx)(t8,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",display:"flex",alignItems:"center",justifyContent:"center",padding:16,backgroundImage:"linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%)",backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px"},children:h?(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13},children:h}):(0,n.jsx)("img",{src:m,alt:e,onLoad:e=>{let t=e.currentTarget;p({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>x("Failed to load image"),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function re({filePath:e,cwd:t,sourceSessionId:r}){let[i,l]=(0,o.useState)(!1),[s,a]=(0,o.useState)(0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(null),g=(0,o.useRef)(null),f=P(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{a(0),c(null),p(null),x(null),l(!1),g.current&&(g.current.close(),g.current=null);let t=new EventSource(t6(e,"watch",r));return g.current=t,t.addEventListener("connected",()=>l(!0)),t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&c(t.size)}catch{}p(null),x(null),a(e=>e+1)}),t.addEventListener("error",()=>l(!1)),t.onerror=()=>l(!1),()=>{t.close(),g.current=null}},[e,r]);let m=t6(e,"read",r,s?{v:s}:void 0);return(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)"},title:e,children:F(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:f||"audio"}),null!=u&&(0,n.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),r=Math.floor(t/60);return`${r}:${String(t%60).padStart(2,"0")}`}(u)}),null!=d&&(0,n.jsx)("span",{children:t3(d)}),(0,n.jsxs)("span",{title:i?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:i?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:i?"#4ade80":"var(--border)",display:"inline-block",boxShadow:i?"0 0 4px #4ade80":"none"}}),i?"live":"static"]}),(0,n.jsx)(t8,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,n.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[h&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:h}),(0,n.jsx)("audio",{controls:!0,preload:"metadata",src:m,onLoadedMetadata:e=>p(e.currentTarget.duration),onError:()=>x("Failed to load audio"),style:{width:"100%"}},m)]})})]})}function rt({filePath:e,cwd:t,sourceSessionId:r}){let[i,l]=(0,o.useState)(!1),[s,a]=(0,o.useState)(0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),h=(0,o.useRef)(null),x=t5(e),g="pdf"===x,f=g?t6(e,"read",r,s?{v:s}:void 0):t6(e,"preview",r,s?{v:s}:void 0);return(0,o.useEffect)(()=>{a(0),c(null),p(null),l(!1),h.current&&(h.current.close(),h.current=null),fetch(t6(e,"meta",r)).then(e=>e.json()).then(e=>{e.error&&p(e.error),"number"==typeof e.size&&(c(e.size),!g&&e.size>0xa00000&&p("DOCX too large for preview (>10MB)"))}).catch(e=>p(String(e)));let t=new EventSource(t6(e,"watch",r));return h.current=t,t.addEventListener("connected",()=>l(!0)),t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);if("number"==typeof t.size&&(c(t.size),!g&&t.size>0xa00000))return void p("DOCX too large for preview (>10MB)")}catch{}p(null),a(e=>e+1)}),t.addEventListener("error",()=>l(!1)),t.onerror=()=>l(!1),()=>{t.close(),h.current=null}},[e,g,r]),(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)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:F(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===x?"docx preview":"pdf"}),null!=d&&(0,n.jsx)("span",{children:t3(d)}),(0,n.jsx)(t8,{filePath:e,sourceSessionId:r}),(0,n.jsxs)("span",{title:i?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:i?"#4ade80":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:i?"#4ade80":"var(--border)",display:"inline-block",boxShadow:i?"0 0 4px #4ade80":"none"}}),i?"live":"static"]})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,background:"var(--bg-panel)"},children:u?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"#f87171",fontSize:13,textAlign:"center"},children:u}):(0,n.jsx)("iframe",{src:f,sandbox:g?void 0:"",title:`Preview ${P(e)}`,style:{width:"100%",height:"100%",border:"none",background:g?"var(--bg)":"#eef1f5"}},f)})]})}function rr({filePath:e,cwd:t,sourceSessionId:r}){let o;return null!==(t2[t5(e)]??null)?(0,n.jsx)(t7,{filePath:e,cwd:t,sourceSessionId:r}):null!==(t4[t5(e)]??null)?(0,n.jsx)(re,{filePath:e,cwd:t,sourceSessionId:r}):null!==("pdf"===(o=t5(e))||"docx"===o?o:null)?(0,n.jsx)(rt,{filePath:e,cwd:t,sourceSessionId:r}):(0,n.jsx)(rn,{filePath:e,cwd:t,sourceSessionId:r})}function rn({filePath:e,cwd:t,sourceSessionId:r}){let{isDark:i}=eL(),[l,s]=(0,o.useState)(null),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(!0),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)("source"),[v,y]=(0,o.useState)(!1),[b,k]=(0,o.useState)(!1),[j,w]=(0,o.useState)(0),S=(0,o.useRef)(null),C=(0,o.useCallback)((e,t=!1)=>fetch(t6(e,"read",r)).then(e=>e.json()).then(e=>e.error?(h(e.error),null):(t?(s(t=>(t&&d(t.content),e)),w(e=>e+1)):s(e),e)).catch(e=>(h(String(e)),null)),[r]);if((0,o.useEffect)(()=>{u(!0),h(null),s(null),d(null),g(!1),m("source"),y(!1),w(0),k(!1),S.current&&(S.current.close(),S.current=null),C(e).then(e=>{e?.language==="markdown"&&g(!0)}).finally(()=>u(!1));let t=new EventSource(t6(e,"watch",r));return S.current=t,t.addEventListener("connected",()=>{k(!0)}),t.addEventListener("change",()=>{C(e,!0)}),t.addEventListener("error",()=>{k(!1)}),t.onerror=()=>{k(!1)},()=>{t.close(),S.current=null}},[e,C,r]),c)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading..."});if(p)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:p});if(!l)return null;let T="html"===l.language,L="markdown"===l.language,I=l.content.split("\n"),z=null!==a&&a!==l.content;return(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)"},title:e,children:F(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:l.language}),"source"===f&&(0,n.jsxs)("span",{children:[I.length," lines"]}),(0,n.jsx)("span",{children:t3(l.size)}),(0,n.jsxs)("span",{title:b?"Live sync active":"Not watching",style:{display:"flex",alignItems:"center",gap:4,color:b?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:b?"#4ade80":"var(--border)",display:"inline-block",boxShadow:b?"0 0 4px #4ade80":"none"}}),b?"live":"static"]}),z&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>m("source"),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:"source"===f?"var(--bg-selected)":"var(--bg-hover)",color:"source"===f?"var(--text)":"var(--text-muted)",fontWeight:"source"===f?600:400},children:"Source"}),(0,n.jsxs)("button",{onClick:()=>m("diff"),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:"diff"===f?"var(--bg-selected)":"var(--bg-hover)",color:"diff"===f?"var(--text)":"var(--text-muted)",fontWeight:"diff"===f?600:400},children:["Diff ",j>0&&(0,n.jsxs)("span",{style:{color:"#4ade80",marginLeft:2},children:["+",j]})]})]}),"source"===f&&!x&&(0,n.jsx)("button",{onClick:()=>y(e=>!e),title:v?"Disable word wrap":"Enable word wrap",style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:v?"var(--bg-selected)":"var(--bg-hover)",color:v?"var(--text)":"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:v?600:400},children:"wrap"}),T&&"source"===f&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>g(!1),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:x?"var(--bg-hover)":"var(--bg-selected)",color:x?"var(--text-muted)":"var(--text)",fontWeight:x?400:600},children:"Code"}),(0,n.jsx)("button",{onClick:()=>g(!0),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:x?"var(--bg-selected)":"var(--bg-hover)",color:x?"var(--text)":"var(--text-muted)",fontWeight:x?600:400},children:"Preview"})]}),L&&"source"===f&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>g(!0),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:x?"var(--bg-selected)":"var(--bg-hover)",color:x?"var(--text)":"var(--text-muted)",fontWeight:x?600:400},children:"Preview"}),(0,n.jsx)("button",{onClick:()=>g(!1),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:x?"var(--bg-hover)":"var(--bg-selected)",color:x?"var(--text-muted)":"var(--text)",fontWeight:x?400:600},children:"Raw"})]}),(0,n.jsx)(t8,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg)"},children:"diff"===f&&z?(0,n.jsx)(t9,{oldContent:a,newContent:l.content,language:l.language}):T&&x?(0,n.jsx)("iframe",{srcDoc:l.content,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:"HTML preview"}):L&&x?(0,n.jsx)("div",{className:"markdown-body markdown-file-preview",style:{padding:"24px 32px",maxWidth:800},children:(0,n.jsx)(eb.oz,{remarkPlugins:eN,rehypePlugins:eH,children:l.content})}):(0,n.jsx)(ek.A,{language:"text"===l.language?"plaintext":l.language,style:i?ej.xJ:ej.vs,showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal",minWidth:"3em",paddingRight:"1em"},customStyle:{margin:0,padding:"12px 0",background:"var(--bg)",fontSize:13,lineHeight:1.6,fontFamily:"var(--font-mono)",minHeight:"100%"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},wrapLongLines:v,children:l.content})})]})}function ro({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:i}){let[l,s]=(0,o.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 o=e.id===t;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:o?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:o?"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:o?1:.7,display:"flex",alignItems:"center"},children:B(e.label,13)}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:o?500:400},title:e.filePath,children:e.label}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},onMouseEnter:()=>s(e.id),onMouseLeave:()=>s(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:l===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:l===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)})})}var ri=r(67381),rl=r(64433),rs=r(70350),ra=r(88195),rd=r(9312),rc=r(87275),ru=r(22008),rp=r(95476),rh=r(35029),rx=r(14489),rg=r(78728),rf=r(19872),rm=r(7751),rv=r(92526),ry=r(48238),rb=r(57794),rk=r(41098),rj=r(84604),rw=r(15315),rS=r(74278),rC=r(55457),rT=r(71437),rL=r(29167),rI=r(97283),rz=r(34166),rR=r(33889),rW=r(85486),rM=r(74068),rE=r(83546),r$=r(83709);let rB={anthropic:{Icon:ri.A,hasColor:!1},openai:{Icon:rl.A,hasColor:!1},"openai-codex":{Icon:rl.A,hasColor:!1},google:{Icon:rs.A,hasColor:!0},"google-vertex":{Icon:rs.A,hasColor:!0},"ant-ling":{Icon:rR.A,hasColor:!0},deepseek:{Icon:ra.A,hasColor:!0},groq:{Icon:rd.A,hasColor:!1},mistral:{Icon:rc.A,hasColor:!0},moonshotai:{Icon:ru.A,hasColor:!1},"moonshotai-cn":{Icon:ru.A,hasColor:!1},moonshot:{Icon:ru.A,hasColor:!1},minimax:{Icon:rp.A,hasColor:!0},"minimax-cn":{Icon:rp.A,hasColor:!0},fireworks:{Icon:rh.A,hasColor:!0},huggingface:{Icon:rx.A,hasColor:!0},cerebras:{Icon:rg.A,hasColor:!0},openrouter:{Icon:rf.A,hasColor:!1},xai:{Icon:rm.A,hasColor:!1},"cloudflare-ai-gateway":{Icon:rv.A,hasColor:!0},"cloudflare-workers-ai":{Icon:rv.A,hasColor:!0},"vercel-ai-gateway":{Icon:ry.A,hasColor:!1},"github-copilot":{Icon:rb.A,hasColor:!1},"amazon-bedrock":{Icon:rk.A,hasColor:!0},"azure-openai-responses":{Icon:rj.A,hasColor:!0},"kimi-coding":{Icon:rw.A,hasColor:!0},nvidia:{Icon:rW.A,hasColor:!0},opencode:{Icon:rM.A,hasColor:!1},"opencode-go":{Icon:rM.A,hasColor:!1},qwen:{Icon:rS.A,hasColor:!0},xiaomi:{Icon:rE.A,hasColor:!1},"xiaomi-token-plan-ams":{Icon:rE.A,hasColor:!1},"xiaomi-token-plan-cn":{Icon:rE.A,hasColor:!1},"xiaomi-token-plan-sgp":{Icon:rE.A,hasColor:!1},zai:{Icon:r$.A,hasColor:!1},"zai-coding-cn":{Icon:r$.A,hasColor:!1},zhipu:{Icon:rC.A,hasColor:!0},cohere:{Icon:rT.A,hasColor:!0},perplexity:{Icon:rL.A,hasColor:!0},together:{Icon:rI.A,hasColor:!0},grok:{Icon:rz.A,hasColor:!1}},rA=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function rD({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 rP={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 rF({value:e,onChange:t,placeholder:r,mono:o}){return(0,n.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:r,style:{...rP,fontFamily:o?"var(--font-mono)":"inherit"}})}function rN({value:e,onChange:t,placeholder:r,mono:i,onKeyDown:l,autoComplete:s="off",spellCheck:a=!1,style:d}){let[c,u]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{e||u(!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:{...rP,paddingRight:34,fontFamily:i?"var(--font-mono)":"inherit"},autoComplete:s,spellCheck:a}),(0,n.jsx)("button",{type:"button",onClick:()=>u(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 rO({value:e,onChange:t,placeholder:r}){return(0,n.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:r,style:rP})}function rH({value:e,onChange:t,options:r,required:o}){return(0,n.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...rP,color:e?"var(--text)":"var(--text-dim)"},children:[!o&&(0,n.jsx)("option",{value:"",children:"— inherit / none —"}),r.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})}function r_({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 rU({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 rK({name:e,provider:t,onChange:r,onRename:i,onDelete:l}){let[s,a]=(0,o.useState)(e);(0,o.useEffect)(()=>a(e),[e]);let d=(e,n)=>r({...t,[e]:n});return(0,o.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)(rU,{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)(rD,{label:"Provider name",children:[(0,n.jsx)(rF,{value:s,onChange:a,placeholder:"provider-name",mono:!0}),s!==e&&s.trim()&&(0,n.jsx)("button",{onClick:()=>i(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)(rD,{label:"Base URL",children:(0,n.jsx)(rF,{value:t.baseUrl??"",onChange:e=>d("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,n.jsxs)(rD,{label:"API Key",children:[(0,n.jsx)(rN,{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)(rD,{label:"API",children:(0,n.jsx)(rH,{value:t.api??"openai-completions",onChange:e=>d("api",e),options:rA,required:!0})})]})}let rq=["off","minimal","low","medium","high","xhigh","max"],rV={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c",max:"#ef4444"};function rY({value:e,onChange:t}){let r=e??{},o=(e,n)=>{let o={...r};"omit"===n?delete o[e]:o[e]=n,t(Object.keys(o).length?o:void 0)};return(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:rq.map(e=>{let t=r[e],i=e in r?null===t?"null":"string":"omit",l="string"==typeof t?t:"",s=rV[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"===i?.3:1}}),(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===i?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===i?"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:()=>o(e,"omit"),style:{...a,..."omit"===i?d:{}},children:"Default"}),(0,n.jsx)("button",{onClick:()=>o(e,null),style:{...a,borderLeft:"1px solid var(--border)",..."null"===i?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===i?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,n.jsx)("button",{onClick:()=>o(e,l||e),style:{...a,..."string"===i?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,n.jsx)("input",{value:l,onChange:t=>o(e,t.target.value),onFocus:()=>{"string"!==i&&o(e,l||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===i?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===i?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let rJ={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function rZ({providerName:e,provider:t,model:r,onChange:i,onDelete:l}){let[s,a]=(0,o.useState)({phase:"idle"}),d=(e,t)=>i({...r,[e]:t}),c=(()=>{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,o.useEffect)(()=>{a({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,r.id,r.api]);let u=(0,o.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})}),o=await n.json();if(!n.ok||!o.ok)return void a({phase:"error",message:o.error??`HTTP ${n.status}`,latencyMs:o.latencyMs,status:o.status});a({phase:"success",latencyMs:o.latencyMs,status:o.status,responseText:o.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)(rU,{children:"Model"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[c&&(0,n.jsx)("span",{title:c,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:c}),(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)(rD,{label:"ID *",children:(0,n.jsx)(rF,{value:r.id,onChange:e=>d("id",e),placeholder:"model-id",mono:!0})}),(0,n.jsx)(rD,{label:"Name",children:(0,n.jsx)(rF,{value:r.name??"",onChange:e=>d("name",e||void 0),placeholder:"Display name"})})]}),(0,n.jsx)(rD,{label:"API override",children:(0,n.jsx)(rH,{value:r.api??"",onChange:e=>d("api",e||void 0),options:rA})}),(0,n.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,n.jsx)(r_,{label:"Reasoning / thinking",checked:r.reasoning??!1,onChange:e=>d("reasoning",e||void 0)}),(0,n.jsx)(r_,{label:"Image input",checked:r.input?.includes("image")??!1,onChange:e=>d("input",e?["text","image"]:void 0)})]}),r.reasoning&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r_,{label:"DeepSeek thinking compat",checked:r.compat?.thinkingFormat==="deepseek",onChange:e=>i(function(e,t){if(t)return{...e,compat:{...e.compat??{},...rJ}};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)(rU,{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)(rY,{value:r.thinkingLevelMap,onChange:e=>d("thinkingLevelMap",e)})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(rD,{label:"Context window (tokens)",children:(0,n.jsx)(rO,{value:void 0!==r.contextWindow?String(r.contextWindow):"",onChange:e=>d("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,n.jsx)(rD,{label:"Max output tokens",children:(0,n.jsx)(rO,{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)(rU,{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)(rD,{label:e,children:(0,n.jsx)(rO,{value:r.cost?.[e]!==void 0?String(r.cost[e]):"",onChange:t=>{let n;return n=parseFloat(t),void i({...r,cost:{...r.cost??{},[e]:isNaN(n)?void 0:n}})},placeholder:"0"})},e))})]})]})}function rX({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)({phase:"idle"}),[l,s]=(0,o.useState)(""),a=(0,o.useRef)(null),d=(0,o.useRef)(null);(0,o.useEffect)(()=>{("auth"===r.phase||"prompt"===r.phase)&&setTimeout(()=>d.current?.focus(),50)},[r.phase]),(0,o.useEffect)(()=>{i({phase:"idle"}),s(""),a.current?.close(),a.current=null},[e.id]),(0,o.useEffect)(()=>()=>{a.current?.close()},[]);let c=(0,o.useCallback)(()=>{a.current?.close(),i({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?(i({phase:"auth",url:n.url,instructions:n.instructions??null,token:n.token}),window.open(n.url,"_blank","noopener,noreferrer")):"device_code"===n.type?(i({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?i({phase:"prompt",message:n.message,placeholder:n.placeholder??null,token:n.token}):"select_request"===n.type?i({phase:"select",message:n.message,options:n.options??[],token:n.token}):"progress"===n.type?i({phase:"progress",message:n.message}):"success"===n.type?(r.close(),i({phase:"success"}),t()):"error"===n.type?(r.close(),i({phase:"error",message:n.message})):"cancelled"===n.type&&(r.close(),i({phase:"idle"}))},r.onerror=()=>{r.close(),i(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),u=(0,o.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),i({phase:"idle"}),t()},[e.id,t]),p=(0,o.useCallback)(async(t,r)=>{if(r.trim()){i({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(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`});return}s("")}catch(e){i({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),h=(0,o.useCallback)(async(t,r)=>{i({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(()=>({}));i({phase:"error",message:e.error??`Server error ${n.status}`})}}catch(e){i({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)(rU,{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&&p(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:()=>p(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(),i({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:u,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 rG({provider:e,onRefresh:t}){let[r,i]=(0,o.useState)(""),[l,s]=(0,o.useState)(!1),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!1);(0,o.useEffect)(()=>{i(""),u(null),h(!1)},[e.id]);let x=(0,o.useCallback)(async()=>{if(r.trim()){s(!0),u(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()})}),o=await n.json();!n.ok||o.error?u(o.error??`HTTP ${n.status}`):(i(""),h(!0),setTimeout(()=>h(!1),2e3),t())}catch(e){u(String(e))}finally{s(!1)}}},[r,e.id,t]),g=(0,o.useCallback)(async()=>{d(!0),u(null);try{let r=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),n=await r.json();!r.ok||n.error?u(n.error??`HTTP ${r.status}`):t()}catch(e){u(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)(rU,{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)(rD,{label:"API Key",children:(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(rN,{value:r,onChange:i,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()||p,style:{padding:"6px 12px",background:p?"#16a34a":r.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:r.trim()||p?"#fff":"var(--text-dim)",cursor:l||!r.trim()||p?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[p&&(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"})}),p?"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 rQ({id:e,size:t}){let r=rB[e];if(!r){let r=e.split(/[-_]/).filter(Boolean).slice(0,2).map(e=>e[0]).join("").toUpperCase()||"?";return(0,n.jsx)("span",{"aria-hidden":"true",style:{width:t,height:t,border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,fontSize:Math.max(8,Math.floor(.42*t)),fontWeight:700,lineHeight:1},children:r})}return r.hasColor?(0,n.jsx)(r.Icon,{size:t}):(0,n.jsx)(r.Icon,{size:t,style:{color:"var(--text-muted)"}})}function r0({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:r,onSelectApiKey:i,onAddCustom:l,onClose:s}){let[a,d]=(0,o.useState)(""),c=(0,o.useRef)(null);(0,o.useEffect)(()=>{setTimeout(()=>c.current?.focus(),30)},[]);let u=a.trim().toLowerCase(),p=e.filter(e=>!e.loggedIn&&(!u||e.name.toLowerCase().includes(u))),h=t.filter(e=>!e.configured&&(!u||e.displayName.toLowerCase().includes(u)||e.id.toLowerCase().includes(u))),x=!u||"custom".includes(u)||"openai-compatible".includes(u)||"anthropic-compatible".includes(u),g=p.length+h.length+ +!!x,f={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&&s()},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:c,value:a,onChange:e=>d(e.target.value),onKeyDown:e=>{"Escape"===e.key&&s()},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===g?(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:[x&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Custom"}),x&&(0,n.jsxs)("button",{onClick:()=>{l(),s()},style:f,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"})]})})]}),p.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!x,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Subscriptions"}),p.map(e=>(0,n.jsxs)("button",{onClick:()=>{r(e.id),s()},style:f,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)(rQ,{id:e.id,size:28})]},e.id)),h.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(p.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),h.map(e=>(0,n.jsxs)("button",{onClick:()=>{i(e.id),s()},style:f,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)(rQ,{id:e.id,size:28})]},e.id))]})})]})})}function r1({onClose:e}){let t=tg(),[r,i]=(0,o.useState)({providers:{}}),[l,s]=(0,o.useState)(!0),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(!1),[x,g]=(0,o.useState)(null),[f,m]=(0,o.useState)([]),[v,y]=(0,o.useState)([]),[b,k]=(0,o.useState)(!1),j=(0,o.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>m(e.providers)).catch(()=>{})},[]),w=(0,o.useCallback)(()=>{fetch("/api/auth/all-providers").then(e=>e.json()).then(e=>y(e.providers)).catch(()=>{})},[]);(0,o.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};i(t);let r=Object.keys(t.providers??{});r.length>0&&g({type:"provider",name:r[0]})}).catch(()=>i({providers:{}})).finally(()=>s(!1)),j(),w()},[j,w]);let S=(0,o.useCallback)(()=>{let e="new-provider",t=1;for(;r.providers?.[e];)e=`new-provider-${t++}`;i(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),g({type:"provider",name:e})},[r.providers]),C=(0,o.useCallback)((e,t)=>{i(r=>({...r,providers:{...r.providers??{},[e]:t}}))},[]),T=(0,o.useCallback)((e,t)=>{i(r=>{let n=Object.entries(r.providers??{}),o=n.findIndex(([t])=>t===e);return -1===o?r:(n[o]=[t,n[o][1]],{...r,providers:Object.fromEntries(n)})}),g(r=>r?"provider"===r.type&&r.name===e?{type:"provider",name:t}:"model"===r.type&&r.providerName===e?{...r,providerName:t}:r:r)},[]),L=(0,o.useCallback)(e=>{i(t=>{let r={...t.providers??{}};return delete r[e],{...t,providers:r}}),i(e=>{let t=Object.keys(e.providers??{});return g(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),I=(0,o.useCallback)(e=>{i(t=>{let r=t.providers?.[e]??{},n=[...r.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...r,models:n}}}}),i(t=>{let r=(t.providers?.[e]?.models?.length??1)-1;return g({type:"model",providerName:e,index:r}),t})},[]),z=(0,o.useCallback)((e,t,r)=>{i(n=>{let o=n.providers?.[e]??{},i=[...o.models??[]];return i[t]=r,{...n,providers:{...n.providers??{},[e]:{...o,models:i}}}})},[]),R=(0,o.useCallback)((e,t)=>{i(r=>{let n=r.providers?.[e]??{},o=[...n.models??[]];return o.splice(t,1),{...r,providers:{...r.providers??{},[e]:{...n,models:o.length?o:void 0}}}}),g({type:"provider",name:e})},[]),W=(0,o.useCallback)(async()=>{d(!0),u(null),h(!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?u(t.error??`HTTP ${e.status}`):(h(!0),setTimeout(()=>h(!1),2e3))}catch(e){u(String(e))}finally{d(!1)}},[r]),M=Object.entries(r.providers??{}),E=f.filter(e=>e.loggedIn),$=v.filter(e=>e.configured),B=(()=>{if(!x)return null;if("oauth"===x.type){let e=f.find(e=>e.id===x.providerId);return e?(0,n.jsx)(rX,{provider:e,onRefresh:j},e.id):null}if("apikey"===x.type){let e=v.find(e=>e.id===x.providerId);return e?(0,n.jsx)(rG,{provider:e,onRefresh:w},e.id):null}if("provider"===x.type){let e=r.providers?.[x.name];return e?(0,n.jsx)(rK,{name:x.name,provider:e,onChange:e=>C(x.name,e),onRename:e=>T(x.name,e),onDelete:()=>L(x.name)},x.name):null}let e=r.providers?.[x.providerName],t=e?.models?.[x.index];return t?(0,n.jsx)(rZ,{providerName:x.providerName,provider:e,model:t,onChange:e=>z(x.providerName,x.index,e),onDelete:()=>R(x.providerName,x.index)},`${x.providerName}-${x.index}`):null})();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:t=>{t.target===t.currentTarget&&e()},children:(0,n.jsxs)("div",{style:{width:t?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:t?"calc(100dvh - 16px)":"78vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(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",flexDirection:t?"column":"row",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:t?"100%":210,maxHeight:t?"40vh":void 0,borderRight:t?"none":"1px solid var(--border)",borderBottom:t?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[E.map(e=>{let t=x?.type==="oauth"&&x.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>g({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)(rQ,{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)}),$.map(e=>{let t=x?.type==="apikey"&&x.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>g({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)(rQ,{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)}),(E.length>0||$.length>0)&&M.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…"}):M.map(([e,t])=>{let r=x?.type==="provider"&&x.name===e,o=t.models??[];return(0,n.jsxs)("div",{style:{marginBottom:2},children:[(0,n.jsxs)("div",{onClick:()=>g({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})]}),o.map((t,r)=>{let o=x?.type==="model"&&x.providerName===e&&x.index===r;return(0,n.jsxs)("div",{onClick:()=>g({type:"model",providerName:e,index:r}),style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:o?"var(--bg-selected)":"none"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(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(),I(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:()=>k(!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:B??(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}),(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:W,disabled:a||p,style:{position:"relative",padding:"6px 16px",minWidth:92,background:p?"#16a34a":a?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:p?"#fff":a?"var(--text-muted)":"#fff",cursor:a||p?"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:p?"saved-pop 0.45s ease":void 0},children:[p&&(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:p?"Saved":a?"Saving…":"Save"})]})]})]})}),b&&(0,n.jsx)(r0,{oauthProviders:f,apiKeyProviders:v,onSelectOAuth:e=>g({type:"oauth",providerId:e}),onSelectApiKey:e=>g({type:"apikey",providerId:e}),onAddCustom:S,onClose:()=>k(!1)})]})}function r2(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function r4(e){let t=e.sourceInfo?.source,r=e.sourceInfo?.scope;return"user"===r||"user"===t?"global":"project"===r||"project"===t?"project":"path"}function r5({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 r6({skill:e,cwd:t,onToggle:r,toggling:o,saveError:i}){let l=r4(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 r2(e)}(e.filePath)}),(0,n.jsx)(r5,{enabled:s,loading:o,onToggle:()=>r(e)}),i&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:i})]}),(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 r8({cwd:e,onInstalled:t}){let[r,i]=(0,o.useState)(""),[l,s]=(0,o.useState)([]),[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(null),[f,m]=(0,o.useState)(new Set),[v,y]=(0,o.useState)("global"),b=(0,o.useRef)(null);(0,o.useEffect)(()=>{b.current?.focus()},[]);let k=(0,o.useCallback)(async e=>{if(e.trim()){d(!0),u(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 u(r.error);s(r.results??[]),0===(r.results??[]).length&&u("No skills found")}catch(e){u(String(e))}finally{d(!1)}}},[]),j=(0,o.useCallback)(async r=>{h(r),g(null);try{let n=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:r,scope:v,cwd:e})}),o=await n.json();if(!n.ok||o.error)return void g(o.error??`HTTP ${n.status}`);m(e=>new Set(e).add(r)),t()}catch(e){g(String(e))}finally{h(null)}},[t,v,e]),w="global"===v?"~/.pi/agent/skills/":`${r2(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:b,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&k(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:()=>k(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:()=>y(e),style:{padding:"3px 10px",border:"none",cursor:"pointer",background:v===e?"var(--bg-selected)":"none",color:v===e?"var(--text)":"var(--text-dim)",fontWeight:v===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:["→ ",w]})]}),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})]}),l.length>0?(0,n.jsx)("div",{style:{flex:1,overflowY:"auto"},children:l.map(e=>{let t=f.has(e.package),r=p===e.package,o=e.package.indexOf("@"),i=o>-1?e.package.slice(0,o):e.package,l=o>-1?e.package.slice(o+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??i}),(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:i}),(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&&!r&&j(e.package),disabled:t||r||null!==p,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:t||r||null!==p?"not-allowed":"pointer",background:t?"rgba(34,197,94,0.1)":"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 r3({cwd:e,onClose:t}){let r=tg(),[i,l]=(0,o.useState)([]),[s,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(null),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(new Set),[g,f]=(0,o.useState)(null),[m,v]=(0,o.useState)(!1),y=(0,o.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&&!u&&p(t[0].filePath)}).catch(e=>c(String(e))).finally(()=>a(!1))},[e,u]);(0,o.useEffect)(()=>{y()},[e]);let b=(0,o.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})}},[]),k=i.find(e=>e.filePath===u)??null;return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&t()},children:(0,n.jsxs)("div",{style:{width:r?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:r?"calc(100dvh - 16px)":"78vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(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:r2(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",flexDirection:r?"column":"row",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:r?"100%":210,maxHeight:r?"40vh":void 0,borderRight:r?"none":"1px solid var(--border)",borderBottom:r?"1px solid var(--border)":"none",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===i.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=i.filter(e=>r4(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=!m&&u===e.filePath,r=e.disableModelInvocation;return(0,n.jsxs)("div",{onClick:()=>{p(e.filePath),v(!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:()=>v(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:m?"var(--bg-selected)":"none",color:m?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{m||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{m||(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:m?(0,n.jsx)(r8,{cwd:e,onInstalled:()=>{y()}}):s?null:k?(0,n.jsx)(r6,{skill:k,cwd:e,onToggle:b,toggling:h.has(k.filePath),saveError:g},k.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"})})]})})}function r9(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function r7(e){return`${e.scope}\0${e.source}`}function ne(e){if(e.disabled)return"Disabled";let t=[e.counts.extensions?`${e.counts.extensions} ext`:"",e.counts.skills?`${e.counts.skills} skills`:"",e.counts.prompts?`${e.counts.prompts} prompts`:"",e.counts.themes?`${e.counts.themes} themes`:""].filter(Boolean);return t.length?t.join(" \xb7 "):"No resources"}function nt(e){let t=[];return e.version&&t.push(`installed ${e.version}`),e.configuredVersion&&t.push(`configured ${e.configuredVersion}`),t.length?t.join(" \xb7 "):"Unknown"}function nr(e){return"loaded"===e?"var(--accent)":"installed"===e?"#f59e0b":"disabled"===e?"var(--text-dim)":"#ef4444"}function nn({pkg:e}){let t=[["extension","Extensions"],["skill","Skills"],["prompt","Prompts"],["theme","Themes"]].map(([t,r])=>({kind:t,label:r,resources:e.resources.filter(e=>e.kind===t)})).filter(e=>e.resources.length>0);return 0===t.length?(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)"},children:e.disabled?"Package disabled":"No resolved resources"}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:t.map((e,t)=>(0,n.jsxs)("div",{style:{borderTop:0===t?"none":"1px solid var(--border)",paddingTop:12*(0!==t)},children:[(0,n.jsx)("div",{style:{fontSize:10,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",marginBottom:6},children:e.label}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.resources.map(e=>(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.path,children:e.name}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:1},title:e.path,children:e.relativePath})]},`${e.kind}:${e.path}`))})]},e.kind))})}function no({scope:e}){return(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===e?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===e?"rgba(99,102,241,0.85)":"var(--text-dim)"},children:e})}function ni(e,t){return{padding:"6px 12px",background:t?"rgba(239,68,68,0.08)":"none",border:"1px solid var(--border)",borderRadius:6,color:t?"#ef4444":"var(--text-muted)",cursor:e?"not-allowed":"pointer",fontSize:12,opacity:e?.5:1}}function nl({enabled:e,loading:t,onToggle:r,label:o}){return(0,n.jsx)("button",{type:"button",onClick:r,disabled:t,title:o,"aria-label":o,"aria-pressed":e,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",opacity:t?.65:1},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 ns({value:e,onChange:t}){return(0,n.jsx)("div",{style:{display:"inline-flex",border:"1px solid var(--border)",borderRadius:7,overflow:"hidden",height:30},children:["global","project"].map(r=>{let o=e===r;return(0,n.jsx)("button",{onClick:()=>t(r),style:{width:76,border:"none",borderRight:"global"===r?"1px solid var(--border)":"none",background:o?"var(--bg-selected)":"none",color:o?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12},children:r},r)})})}function na({cwd:e,source:t,scope:r,busy:i,actionError:l,onSourceChange:s,onScopeChange:a,onInstall:d}){let c=(0,o.useRef)(null);return(0,o.useEffect)(()=>{c.current?.focus()},[]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:18,maxWidth:660,minHeight:"100%"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:"Add Plugin"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"project"===r?`${r9(e)}/.pi/agent/{npm,git}`:"~/.pi/agent/{npm,git}"})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("label",{htmlFor:"plugin-source",style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:"Source"}),(0,n.jsx)("input",{id:"plugin-source",ref:c,value:t,onChange:e=>s(e.target.value),placeholder:"npm:@scope/package",style:{width:"100%",height:36,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,outline:"none"},onKeyDown:e=>{"Enter"===e.key&&t.trim()&&!i&&d()}})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)(ns,{value:r,onChange:a}),(0,n.jsx)("button",{type:"button",onClick:d,disabled:i||!t.trim(),style:{...ni(i||!t.trim()),background:"var(--accent)",color:"white",borderColor:"var(--accent)"},children:i?"Installing...":"Install"})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:"Examples"}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:["npm:@scope/pi-plugin","git:https://github.com/user/repo","/absolute/path/to/plugin"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>s(e),style:{width:"100%",minHeight:30,textAlign:"left",padding:"6px 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-dim)",cursor:"pointer",fontFamily:"var(--font-mono)",fontSize:11},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)",e.currentTarget.style.color="var(--text-dim)"},children:e},e))})]}),l&&(0,n.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:l})]})}function nd({pkg:e,cwd:t,busyKey:r,actionError:o,actionMessage:i,sessionId:l,onAction:s,onReloadSession:a}){let d=r7(e),c=r?.endsWith(d)??!1,u="reload"===r,p=!e.disabled;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20,maxWidth:680},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,minWidth:0,flexWrap:"wrap"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:180,flex:1},children:[(0,n.jsx)(nl,{enabled:p,loading:c||u,onToggle:()=>s(e.disabled?"enable":"disable",e),label:e.disabled?"Enable package":"Disable package"}),(0,n.jsx)(no,{scope:e.scope}),e.disabled?(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(120,120,120,0.12)",color:"var(--text-dim)"},children:"disabled"}):e.filtered&&(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(245,158,11,0.12)",color:"#d97706"},children:"filtered"}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,n.jsx)("button",{onClick:()=>s("update",e),disabled:c||u,style:ni(c||u),children:r===`update:${d}`?"Updating...":"Update"}),(0,n.jsx)("button",{onClick:a,disabled:!l||u||c,style:ni(!l||u||c),title:l?"Reload current session":"Open a session to reload",children:u?"Reloading...":"Reload session"}),(0,n.jsx)("button",{onClick:()=>s("remove",e),disabled:c||u,style:ni(c||u,!0),children:r===`remove:${d}`?"Removing...":"Remove"})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(96px, 130px) minmax(0, 1fr)",gap:"9px 14px",fontSize:12,lineHeight:1.45},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Status"}),(0,n.jsx)("div",{style:{color:nr(e.status),textTransform:"capitalize"},children:e.status}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Version"}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:nt(e)}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Package"}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.packageName??"Unknown"}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Resources"}),(0,n.jsx)("div",{style:{color:"var(--text-muted)"},children:ne(e)}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Installed path"}),(0,n.jsx)("div",{style:{color:e.installedPath?"var(--text-muted)":"#ef4444",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.installedPath?r9(e.installedPath):"Not found"}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:"Cwd"}),(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:r9(t)})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Resolved Resources"}),(0,n.jsx)(nn,{pkg:e})]}),i&&(0,n.jsx)("div",{style:{fontSize:12,color:"#16a34a"},children:i}),o&&(0,n.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:o})]})}function nc({cwd:e,sessionId:t,onClose:r,onReloaded:i}){let l=tg(),[s,a]=(0,o.useState)(null),[d,c]=(0,o.useState)(!0),[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(null),[g,f]=(0,o.useState)(!1),[m,v]=(0,o.useState)(""),[y,b]=(0,o.useState)("global"),[k,j]=(0,o.useState)(null),[w,S]=(0,o.useState)(null),[C,T]=(0,o.useState)(null),L=(0,o.useMemo)(()=>s?.packages??[],[s?.packages]),I=L.find(e=>r7(e)===h)??null,z=(0,o.useMemo)(()=>["project","global"].map(e=>({scope:e,packages:L.filter(t=>t.scope===e)})).filter(e=>e.packages.length>0),[L]),R=(0,o.useCallback)(async()=>{c(!0),p(null);try{let t=await fetch(`/api/plugins?cwd=${encodeURIComponent(e)}`),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);a(r),f(e=>0===r.packages.length||e),x(e=>e&&r.packages.some(t=>r7(t)===e)?e:r.packages[0]?r7(r.packages[0]):null)}catch(e){p(e instanceof Error?e.message:String(e))}finally{c(!1)}},[e]);(0,o.useEffect)(()=>{R()},[R]);let W=(0,o.useCallback)(async(t,r)=>{let n=r7(r);j(`${t}:${n}`),S(null),T(null);try{let n=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,source:r.source,scope:r.scope,cwd:e})}),o=await n.json();if(!n.ok||o.error)throw Error(o.error??`HTTP ${n.status}`);a(o),"remove"===t?(x(o.packages[0]?r7(o.packages[0]):null),0===o.packages.length&&f(!0),T("Package removed.")):T({install:"Package installed.",update:"Package updated.",disable:"Package disabled.",enable:"Package enabled."}[t])}catch(e){S(e instanceof Error?e.message:String(e))}finally{j(null)}},[e]),M=(0,o.useCallback)(async()=>{let t=m.trim();if(!t)return;let r=`${y}\0${t}`;j(`install:${r}`),S(null),T(null);try{var n;let o,i,l=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"install",source:t,scope:y,cwd:e})}),s=await l.json();if(!l.ok||s.error)throw Error(s.error??`HTTP ${l.status}`);a(s);let d=(n=s.packages,i=(o=t.trim()).startsWith("npm:")?o.slice(4):o,n.find(e=>e.scope===y&&e.source===o)??n.find(e=>e.scope===y&&e.source===`npm:${i}`)??n.find(e=>e.scope===y&&e.source.endsWith(o)));x(d?r7(d):r),f(!1),v(""),T("Package installed.")}catch(e){S(e instanceof Error?e.message:String(e))}finally{j(null)}},[e,y,m]),E=(0,o.useCallback)(async()=>{if(t){j("reload"),S(null),T(null);try{await tA(t,{type:"reload"}),i?.(),await R(),T("Session reloaded.")}catch(e){S(e instanceof Error?e.message:String(e))}finally{j(null)}}},[R,i,t]),$=k?.startsWith("install:")??!1;return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&r()},children:(0,n.jsxs)("div",{style:{width:l?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:l?"calc(100dvh - 16px)":"76vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(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,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Plugins"}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r9(e)})]}),(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:{flex:1,display:"flex",flexDirection:l?"column":"row",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:l?"100%":245,maxHeight:l?"40vh":void 0,borderRight:l?"none":"1px solid var(--border)",borderBottom:l?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:d?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading..."}):u?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:u}):0===L.length?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No plugins configured"}):z.map(e=>(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"},children:e.scope}),e.packages.map(e=>{let t=r7(e),r=!g&&h===t;return(0,n.jsxs)("div",{onClick:()=>{x(t),f(!1),S(null),T(null)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 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.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:nr(e.status)}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:r?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:ne(e)}),(e.version||e.configuredVersion)&&(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:nt(e)})]})]},t)})]},e.scope))}),(0,n.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("button",{type:"button",onClick:()=>{f(!0),S(null),T(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:g?"var(--bg-selected)":"none",color:g?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{g||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{g||(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 plugin"]})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:g?(0,n.jsx)(na,{cwd:e,source:m,scope:y,busy:$,actionError:w,onSourceChange:v,onScopeChange:b,onInstall:M}):d?null:I?(0,n.jsx)(nd,{pkg:I,cwd:e,busyKey:k,actionError:w,actionMessage:C,sessionId:t,onAction:W,onReloadSession:E},r7(I)):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a package"})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsx)("div",{style:{minWidth:0,flex:1,fontSize:11,color:"var(--text-dim)",overflow:"hidden"},children:s?.diagnostics.length?(0,n.jsxs)("span",{title:s.diagnostics.map(e=>`${e.type}: ${e.source?`${e.source}: `:""}${e.message}`).join("\n"),style:{color:s.diagnostics.some(e=>"error"===e.type)?"#ef4444":"#d97706"},children:[s.diagnostics.length," diagnostic",1===s.diagnostics.length?"":"s"]}):(0,n.jsx)("span",{children:s?`${s.totals.extensions} ext \xb7 ${s.totals.skills} skills \xb7 ${s.totals.prompts} prompts \xb7 ${s.totals.themes} themes`:""})}),(0,n.jsx)("button",{onClick:()=>void R(),disabled:d||null!==k,style:ni(d||null!==k),children:"Refresh"}),(0,n.jsx)("button",{onClick:r,style:ni(!1),children:"Close"})]})]})})}let nu=[{mode:"default",label:"Default",title:"Hide settings/bookkeeping entries"},{mode:"no-tools",label:"No tools",title:"Default minus tool results"},{mode:"user-only",label:"User",title:"Only user messages"},{mode:"labeled-only",label:"Labeled",title:"Only labeled entries"},{mode:"all",label:"All",title:"Show everything"}];function np({row:e,activePathIds:t,onSelect:r,onToggleFold:o,folded:i,onEditLabel:l,maxContentWidth:s}){let{node:a,parentLines:d,isLast:c,showConnector:u}=e,p=a.entry,h=t.has(p.id),x=t.has(p.id),g=function(e){if("message"===e.type&&e.message){let t=e.message.preview;if(t.length>40)return t.slice(0,40)+"…";if(t)return t;if("assistant"===e.message.role)return"[assistant]"}return e.type}(p),f=p.message?.role??null,m=i.has(p.id),v=a.children.length>0,y=void 0!==a.label;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>r(p.id),onDoubleClick:()=>l(p.id,a.label),title:"Click to navigate \xb7 double-click to label",children:[d.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)),u&&(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:c?"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)("button",{onClick:e=>{e.stopPropagation(),o(p.id)},style:{width:13,height:13,flexShrink:0,padding:0,border:"none",background:"none",cursor:v?"pointer":"default",color:"var(--text-dim)",fontSize:10,lineHeight:"13px",display:"flex",alignItems:"center",justifyContent:"center",marginRight:2,opacity:v?1:.3},title:v?m?"Expand":"Collapse":"No children",children:v?m?"⊞":"⊟":"\xb7"}),(0,n.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:h?"var(--accent)":x?"var(--text-muted)":"var(--border)",border:h?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),f&&(0,n.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===f?"var(--accent)":"var(--text-dim)",background:"user"===f?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===f?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===f?"U":"assistant"===f?"A":"toolResult"===f?"T":f[0].toUpperCase()}),y&&(0,n.jsxs)("span",{style:{fontSize:9,color:"var(--accent)",background:"rgba(37,99,235,0.08)",border:"1px solid rgba(37,99,235,0.2)",borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px",maxWidth:120,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:a.label,children:["\uD83C\uDFF7 ",a.label]}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,overflow:"hidden",position:"relative"},children:(0,n.jsx)("div",{style:{fontSize:11,color:h?"var(--text)":x?"var(--text-muted)":"var(--text-dim)",fontWeight:h?500:400,whiteSpace:"nowrap",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"none",maxWidth:s},children:g})})]})}function nh({entryId:e,onChoose:t,onCancel:r}){let[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)("choose");return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.3)"},onClick:r,children:(0,n.jsxs)("div",{style:{background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,padding:16,minWidth:320,maxWidth:480,boxShadow:"0 8px 24px rgba(0,0,0,0.2)"},onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:500,marginBottom:12,color:"var(--text)"},children:"Summarize branch?"}),(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-muted)",marginBottom:12,fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:["→ ",e.slice(0,12),"…"]}),"choose"===s?(0,n.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,n.jsx)("button",{onClick:()=>t({summarize:!1}),style:nx,children:"No summary"}),(0,n.jsx)("button",{onClick:()=>t({summarize:!0}),style:nx,children:"Summarize"}),(0,n.jsx)("button",{onClick:()=>a("custom"),style:nx,children:"Summarize with custom prompt"}),(0,n.jsx)("button",{onClick:r,style:{...nx,marginLeft:"auto",color:"var(--text-dim)"},children:"Cancel"})]}):(0,n.jsxs)("div",{children:[(0,n.jsx)("textarea",{autoFocus:!0,value:i,onChange:e=>l(e.target.value),placeholder:"Custom summarization instructions…",style:{width:"100%",minHeight:64,padding:8,fontSize:12,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",resize:"vertical",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,marginTop:10,justifyContent:"flex-end"},children:[(0,n.jsx)("button",{onClick:()=>a("choose"),style:{...nx,color:"var(--text-dim)"},children:"Back"}),(0,n.jsx)("button",{onClick:()=>t({summarize:!0,customInstructions:i.trim()||void 0}),style:{...nx,background:"var(--accent)",color:"white",borderColor:"var(--accent)"},children:"Summarize"})]})]})]})})}let nx={padding:"6px 12px",fontSize:12,borderRadius:4,background:"var(--bg)",border:"1px solid var(--border)",color:"var(--text)",cursor:"pointer"};function ng({currentLabel:e,onSave:t,onCancel:r}){let[i,l]=(0,o.useState)(e??"");return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.3)"},onClick:r,children:(0,n.jsxs)("div",{style:{background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,padding:16,minWidth:320,maxWidth:480,boxShadow:"0 8px 24px rgba(0,0,0,0.2)"},onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:500,marginBottom:12,color:"var(--text)"},children:"Branch label"}),(0,n.jsx)("input",{autoFocus:!0,value:i,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&t(i.trim()||void 0),"Escape"===e.key&&r()},placeholder:"Label for this branch point (empty to clear)",style:{width:"100%",padding:8,fontSize:12,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text)",boxSizing:"border-box"}}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,marginTop:10,justifyContent:"flex-end"},children:[e&&(0,n.jsx)("button",{onClick:()=>t(void 0),style:{...nx,color:"var(--text-dim)",marginRight:"auto"},children:"Clear"}),(0,n.jsx)("button",{onClick:r,style:{...nx,color:"var(--text-dim)"},children:"Cancel"}),(0,n.jsx)("button",{onClick:()=>t(i.trim()||void 0),style:{...nx,background:"var(--accent)",color:"white",borderColor:"var(--accent)"},children:"Save"})]})]})})}function nf({maxHeight:e,children:t,className:r,contentKey:i}){let l=(0,o.useRef)(null),s=(0,o.useRef)(null),a=(0,o.useRef)(null),[d,c]=(0,o.useState)({height:0,top:0,visible:!1}),u=(0,o.useCallback)(()=>{let e=l.current;if(!e)return;let{scrollHeight:t,clientHeight:r,scrollTop:n}=e;if(t<=r+1)return void c({height:0,top:0,visible:!1});let o=Math.max(24,Math.round(r/t*r)),i=r-o;c({height:o,top:i>0?Math.round(n/(t-r)*i):0,visible:!0})},[]);(0,o.useLayoutEffect)(()=>{u()},[i,u]),(0,o.useEffect)(()=>{let e=l.current;if(!e)return;let t=new ResizeObserver(()=>u());return t.observe(e),e.firstElementChild instanceof Element&&t.observe(e.firstElementChild),()=>t.disconnect()},[u]);let p=(0,o.useCallback)(e=>{e.preventDefault(),e.stopPropagation();let t=l.current;if(!t)return;a.current={startY:e.clientY,startScrollTop:t.scrollTop};let r=e=>{let t=a.current,r=l.current;if(!t||!r)return;let n=e.clientY-t.startY,o=r.clientHeight-d.height;o<=0||(r.scrollTop=t.startScrollTop+n/o*(r.scrollHeight-r.clientHeight))},n=()=>{a.current=null,document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",n)};document.addEventListener("mousemove",r),document.addEventListener("mouseup",n)},[d.height]),h=(0,o.useCallback)(e=>{let t=l.current,r=s.current;if(!t||!r)return;let n=r.getBoundingClientRect(),o=e.clientY-n.top-d.height/2,i=t.clientHeight-d.height;i<=0||(t.scrollTop=o/i*(t.scrollHeight-t.clientHeight))},[d.height]);return(0,n.jsxs)("div",{style:{position:"relative",maxHeight:e,display:"flex"},children:[(0,n.jsx)("div",{ref:l,className:r,onScroll:u,style:{maxHeight:e,overflowY:"auto",overflowX:"hidden",scrollbarWidth:"none",flex:1,minWidth:0},children:t}),d.visible&&(0,n.jsx)("div",{ref:s,onMouseDown:h,style:{position:"absolute",right:0,top:0,bottom:0,width:10,flexShrink:0,cursor:"pointer"},children:(0,n.jsx)("div",{onMouseDown:p,style:{position:"absolute",right:1,top:d.top,height:d.height,width:8,borderRadius:4,background:"var(--text-dim)",cursor:"grab",opacity:.5,transition:"opacity 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.opacity="0.85",e.currentTarget.style.background="var(--text-muted)"},onMouseLeave:e=>{a.current||(e.currentTarget.style.opacity="0.5",e.currentTarget.style.background="var(--text-dim)")}})})]})}function nm({tree:e,activeLeafId:t,onLeafChange:r,onSetLabel:i,inline:l,containerRef:s,open:a,onToggle:d,hasSession:c,compact:u}){let[p,h]=(0,o.useState)(!1),x=void 0!==a?a:p,g=(0,o.useRef)(null),[f,m]=(0,o.useState)(null),[v,y]=(0,o.useState)("default"),[b,k]=(0,o.useState)(new Set),[j,w]=(0,o.useState)(null),[S,C]=(0,o.useState)(null);(0,o.useEffect)(()=>{if(!x||!l)return;let e=s?.current??g.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();m({top:t.bottom,left:t.left,width:t.width})};t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[x,l,s]);let T=(0,o.useMemo)(()=>t?new Set(function e(r,n){for(let o of r){let r=[...n,o.entry.id];if(o.entry.id===t)return r;let i=e(o.children,r);if(i)return i}return null}(e,[])??[]):new Set,[e,t]);(0,o.useEffect)(()=>{k(new Set),y("default")},[e]);let L=(0,o.useCallback)(e=>{k(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),I=(0,o.useCallback)(e=>{e!==t&&w(e)},[t]),z=(0,o.useCallback)(e=>{w(null),j&&null!==e&&r(j,{summarize:e.summarize,customInstructions:e.customInstructions})},[j,r]),R=(0,o.useCallback)((e,t)=>{i&&C({entryId:e,current:t})},[i]),W=(0,o.useCallback)(e=>{S&&(i?.(S.entryId,e),C(null))},[S,i]),M=function e(t){for(let r of t)if(r.children.length>1||e(r.children))return!0;return!1}(e),E=c?0===e.length?"This session has no entries":null:"No active session",$=(0,o.useMemo)(()=>(function(e,t,r,n){let o=[],i=new Map,l=(e,s)=>{for(let a of e)i.set(a.entry.id,a),!s&&function(e,t,r){let n=e.entry;if("message"===n.type&&n.message?.role==="assistant"&&n.id!==r){let e=n.message.preview.trim().length>0,t=void 0!==n.message.stopReason&&"stop"!==n.message.stopReason&&"toolUse"!==n.message.stopReason;if(!e&&!t)return!1}let o="label"===n.type||"custom"===n.type||"model_change"===n.type||"thinking_level_change"===n.type||"session_info"===n.type;switch(t){case"user-only":return"message"===n.type&&n.message?.role==="user";case"no-tools":return!o&&("message"!==n.type||n.message?.role!=="toolResult");case"labeled-only":return void 0!==e.label;case"all":return!0;default:return!o}}(a,t,n)&&o.push(a),l(a.children,s||r.has(a.entry.id))};if(l(e,!1),0===o.length)return[];let s=new Set(o.map(e=>e.entry.id)),a=new Map;for(let e of(a.set(null,[]),o)){let t=e.entry.parentId;for(;null!==t&&!s.has(t);)t=i.get(t)?.entry.parentId??null;a.has(t)||a.set(t,[]),a.get(t).push(e.entry.id)}let d=[],c=a.get(null),u=[];for(let e=c.length-1;e>=0;e--)u.push({id:c[e],indent:0,justBranched:!1,showConnector:!1,isLast:e===c.length-1,parentLines:[]});for(;u.length>0;){let{id:e,indent:t,justBranched:r,showConnector:n,isLast:o,parentLines:l}=u.pop();d.push({node:i.get(e),depth:t,parentLines:l,isLast:o,showConnector:n});let s=a.get(e)||[];if(0===s.length)continue;let c=s.length>1,p=c||r&&t>0?t+1:t,h=n?[...l,!o]:l;for(let e=s.length-1;e>=0;e--)u.push({id:s[e],indent:p,justBranched:c,showConnector:c,isLast:e===s.length-1,parentLines:h})}return d})(e,v,b,t),[e,v,b,t]),B=$.length,A=null===E&&B>0,D=(f?.width??320)-80,P=(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:M?"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"})]}),F=(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:x?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})}),N=A&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,padding:"4px 12px",borderBottom:"1px solid var(--border)",overflowX:"auto",scrollbarWidth:"thin",flexShrink:0},children:[nu.map(e=>(0,n.jsx)("button",{onClick:()=>y(e.mode),title:e.title,style:{padding:"2px 8px",fontSize:10,borderRadius:3,whiteSpace:"nowrap",border:`1px solid ${v===e.mode?"var(--accent)":"var(--border)"}`,background:v===e.mode?"rgba(37,99,235,0.1)":"none",color:v===e.mode?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontWeight:v===e.mode?500:400},children:e.label},e.mode)),(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",alignSelf:"center",marginLeft:"auto",paddingLeft:8,flexShrink:0},children:[B," shown"]})]}),O=(0,n.jsxs)(n.Fragment,{children:[N,A?(0,n.jsx)(nf,{maxHeight:260,className:"branches-scroll",contentKey:$.length,children:(0,n.jsxs)("div",{style:{padding:"4px 12px 8px 12px"},children:[$.map(e=>(0,n.jsx)(np,{row:e,activePathIds:T,onSelect:I,onToggleFold:L,folded:b,onEditLabel:R,maxContentWidth:D},e.node.entry.id)),0===B&&(0,n.jsxs)("div",{style:{padding:"8px 4px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:["No entries match the “",nu.find(e=>e.mode===v)?.label,"” filter."]})]})}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:E??"This session has no entries"})]});return l?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,n.jsxs)("button",{ref:g,onClick:()=>d?d():h(e=>!e),style:{display:"flex",alignItems:"center",gap:6,height:"100%",padding:"0 12px",background:x?"var(--bg-selected)":"none",border:"none",borderTop:x?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:"pointer",color:x?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=x?"var(--text)":"var(--text-muted)"},title:"Branches","aria-label":"Branches","aria-pressed":x,children:[P,!u&&(0,n.jsx)("span",{children:"Branches"})]}),x&&f&&(0,n.jsx)("div",{style:{position:"fixed",top:f.top,left:f.left,width:f.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:O}),j&&(0,n.jsx)(nh,{entryId:j,onChoose:z,onCancel:()=>w(null)}),S&&(0,n.jsx)(ng,{currentLabel:S.current,onSave:W,onCancel:()=>C(null)})]}):(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>h(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:[P,(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:"Branches"}),F]}),x&&(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:O}),j&&(0,n.jsx)(nh,{entryId:j,onChoose:z,onCancel:()=>w(null)}),S&&(0,n.jsx)(ng,{currentLabel:S.current,onSave:W,onCancel:()=>C(null)})]})}function nv(){let e,t,r,l,s,a,d,c,u=(0,i.useRouter)(),p=(0,i.useSearchParams)(),{isDark:h,toggleTheme:x}=eL(),g=tg(),[f,m]=(0,o.useState)(null),[v,y]=(0,o.useState)(null),[b,k]=(0,o.useState)(0),[j,w]=(0,o.useState)(0),[S,C]=(0,o.useState)(0),[T,L]=(0,o.useState)(!1),[I,z]=(0,o.useState)(0),[R,W]=(0,o.useState)(!1),[M,E]=(0,o.useState)(!1),[$,B]=(0,o.useState)(!0),[A,D]=(0,o.useState)(!1);(0,o.useEffect)(()=>{g&&B(!1)},[g]),(0,o.useEffect)(()=>{D(!0)},[]);let F=(0,o.useRef)(null),N=(0,o.useRef)(null),[O,H]=(0,o.useState)([]),[_,U]=(0,o.useState)(null),K=(0,o.useRef)(null),q=(0,o.useRef)(null),V=(0,o.useCallback)((e,t,r,n)=>{H(e),U(t),K.current=r,q.current=n},[]),Y=(0,o.useCallback)((e,t)=>{K.current?.(e,t)},[]),J=(0,o.useCallback)((e,t)=>{q.current?.(e,t)},[]),[Z,X]=(0,o.useState)(null),G=(0,o.useRef)(null),Q=(0,o.useCallback)(e=>{X(e)},[]),[ee,et]=(0,o.useState)(null),en=(0,o.useCallback)(e=>{et(e)},[]),[eo,ei]=(0,o.useState)(null),el=(0,o.useRef)(null),es=(0,o.useCallback)((e,t)=>{eI(t).then(()=>{el.current&&clearTimeout(el.current),ei(e),el.current=setTimeout(()=>ei(null),1400)})},[]);(0,o.useEffect)(()=>()=>{el.current&&clearTimeout(el.current)},[]);let[ea,ed]=(0,o.useState)(null),ec=(0,o.useCallback)(e=>{ed(e)},[]),[eu,ep]=(0,o.useState)(null),[eh,ex]=(0,o.useState)(null),eg=(0,o.useCallback)(e=>{g&&B(!1),ep(t=>t===e?null:e)},[g]),ef=(0,o.useCallback)(()=>{g&&B(!1),ep("session")},[g]),em=(0,o.useCallback)(()=>{g&&ep(null),B(e=>!e)},[g]);(0,o.useEffect)(()=>{if(!eu||!N.current)return;let e=()=>{let e=N.current.getBoundingClientRect();ex({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(N.current),()=>t.disconnect()},[eu]);let[ev,ey]=(0,o.useState)([]),[eb,ek]=(0,o.useState)(null),[ej,ew]=(0,o.useState)(!1),eS=(0,o.useCallback)((e,t)=>{let r;F.current?.insertText((r=t?`${e}/`:e).includes(" ")?`@"${r}" `:`@${r} `)},[]),[eC]=(0,o.useState)(()=>p.get("session")),[eT,ez]=(0,o.useState)(null),[eR,eW]=(0,o.useState)(()=>!p.get("session")),eM=(0,o.useRef)(!1),eE=(0,o.useCallback)((e,t)=>{if(ez(e),!e)return;if(eM.current){eM.current=!1;return}let r=t??e;f&&(f.projectRoot??f.cwd)===r||(m(null),y(t=>t&&t!==e?null:t),w(e=>e+1),H([]),U(null),X(null),ep(null),u.replace("/",{scroll:!1}))},[u,f]),e$=(0,o.useCallback)((e,t=!1)=>{y(null),m(e),w(e=>e+1),X(null),eW(!0),g&&!t&&B(!1),t&&(eM.current=!0),t||u.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[u,g]),eB=(0,o.useCallback)((e,t)=>{m(null),y(t),w(e=>e+1),H([]),U(null),X(null),ep(null),g&&B(!1),u.replace("/",{scroll:!1})},[u,g]),eA=(0,o.useCallback)(e=>{fetch("/api/sessions").then(e=>e.ok?e.json():null).then(t=>{let r=t?.sessions.find(t=>t.id===e);r&&m(t=>t&&t.id===e&&!t.projectRoot?r:t)}).catch(()=>{})},[]),eD=(0,o.useCallback)(e=>{y(null),m(e),k(e=>e+1),eA(e.id),u.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[u,eA]),eP=(0,o.useCallback)(()=>{k(e=>e+1),C(e=>e+1)},[]),eF=(0,o.useCallback)(e=>{k(e=>e+1),w(e=>e+1),y(null),m(t=>({...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e})),eA(e),u.replace(`?session=${encodeURIComponent(e)}`,{scroll:!1})},[u,eA]),eN=(0,o.useCallback)(()=>{eW(!0)},[]),eO=(0,o.useCallback)(e=>{if(k(e=>e+1),f?.id===e){let e=f.cwd;m(null),y(e??null),w(e=>e+1),H([]),U(null),X(null),ep(null),u.replace("/",{scroll:!1})}},[f,u]),eH=(0,o.useCallback)((e,t,r)=>{let n=`file:${e}`;ey(o=>{let i=o.find(e=>e.id===n);return i?r&&i.sourceSessionId!==r?o.map(e=>e.id===n?{...e,sourceSessionId:r}:e):o:[...o,{id:n,label:t,filePath:e,sourceSessionId:r}]}),ek(n),ew(!0),g&&B(!1)},[g]),e_=(0,o.useCallback)(e=>{eH(e,P(e),f?.id??null)},[eH,f?.id]),eU=(0,o.useCallback)(e=>{ey(t=>{let r=t.filter(t=>t.id!==e);return 0===r.length&&ew(!1),r}),ek(t=>{if(t!==e)return t;let r=ev.filter(t=>t.id!==e);return r.length>0?r[r.length-1].id:null})},[ev]),eK=(0,o.useCallback)(()=>{f&&(window.location.href=`/api/sessions/${encodeURIComponent(f.id)}/export`)},[f]),eq=v??(null===f&&eT?eT:null),eV=null!==f||null!==eq,eY=eR&&!eV,eJ=ev.find(e=>e.id===eb)??null,eZ=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(er,{selectedSessionId:f?.id??null,onSelectSession:e$,onNewSession:eB,initialSessionId:eC,onInitialRestoreDone:eN,refreshKey:b,onSessionDeleted:eO,selectedCwd:f?.cwd??v??null,onCwdChange:eE,onOpenFile:eH,explorerRefreshKey:S,onAtMention:eS}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0,display:"flex",justifyContent:"space-between",gap:4},children:[{label:"Models",onClick:()=>L(!0),disabled:!1,icon:(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:"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"})]})},{label:"Skills",onClick:()=>W(!0),disabled:!eT&&!f?.cwd&&!v,icon:(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:"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"})]})},{label:"Plugins",onClick:()=>E(!0),disabled:!eT&&!f?.cwd&&!v,icon:(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:"M9 7V2"}),(0,n.jsx)("path",{d:"M15 7V2"}),(0,n.jsx)("path",{d:"M6 13V8a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v5a6 6 0 0 1-12 0Z"}),(0,n.jsx)("path",{d:"M12 19v3"})]})}].map(({label:e,onClick:t,disabled:r,icon:o})=>(0,n.jsxs)("button",{onClick:t,disabled:r,title:e,style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:r?"default":"pointer",fontSize:12,opacity:r?.35:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{r||(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:[o,e]},e))})]});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("style",{children:`
6
+ @keyframes session-info-pop {
7
+ 0% {
8
+ opacity: 0;
9
+ transform: translateY(-24px);
10
+ filter: blur(6px);
11
+ box-shadow: 0 2px 8px rgba(0,0,0,0);
12
+ }
13
+ 55% {
14
+ opacity: 1;
15
+ transform: translateY(0);
16
+ filter: blur(0);
17
+ background: color-mix(in srgb, var(--accent) 8%, var(--bg-panel));
18
+ box-shadow: 0 18px 44px rgba(37,99,235,0.16);
19
+ }
20
+ 100% {
21
+ opacity: 1;
22
+ transform: translateY(0);
23
+ filter: blur(0);
24
+ background: var(--bg-panel);
25
+ box-shadow: 0 10px 28px rgba(0,0,0,0.10);
26
+ }
27
+ }
28
+ @keyframes session-info-light-wash {
29
+ 0% {
30
+ opacity: 0;
31
+ transform: translateX(-110%) skewX(-16deg);
32
+ }
33
+ 24% {
34
+ opacity: 0.42;
35
+ }
36
+ 100% {
37
+ opacity: 0;
38
+ transform: translateX(115%) skewX(-16deg);
39
+ }
40
+ }
41
+ .session-info-popover {
42
+ position: relative;
43
+ overflow: hidden;
44
+ transform-origin: top right;
45
+ animation: session-info-pop 360ms ease-out both;
46
+ will-change: transform, opacity, filter, background, box-shadow;
47
+ }
48
+ .session-info-popover::after {
49
+ content: "";
50
+ position: absolute;
51
+ top: 0;
52
+ bottom: 0;
53
+ left: 0;
54
+ width: 44%;
55
+ pointer-events: none;
56
+ background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 24%, transparent), transparent);
57
+ animation: session-info-light-wash 620ms ease-out both;
58
+ }
59
+ @media (prefers-reduced-motion: reduce) {
60
+ .session-info-popover,
61
+ .session-info-popover::after {
62
+ animation: none;
63
+ }
64
+ }
65
+ @media (max-width: 640px) {
66
+ .sidebar-overlay-backdrop.sidebar-mobile-pending {
67
+ opacity: 0 !important;
68
+ pointer-events: none !important;
69
+ }
70
+ .sidebar-container.sidebar-mobile-pending.sidebar-open {
71
+ transform: translateX(-100%);
72
+ box-shadow: none;
73
+ }
74
+ }
75
+ `}),(0,n.jsxs)("div",{style:{display:"flex",height:"100dvh",overflow:"hidden",background:"var(--bg)"},children:[(0,n.jsx)("div",{className:`sidebar-overlay-backdrop${A?"":" sidebar-mobile-pending"}`,onClick:()=>B(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!$,pointerEvents:$?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{className:`sidebar-container${$?" sidebar-open":" sidebar-closed"}${A?"":" sidebar-mobile-pending"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200},children:eZ}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,n.jsxs)("div",{ref:N,style:{display:"flex",alignItems:"center",flexShrink:0,borderBottom:"1px solid var(--border)",height:36,background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{onClick:em,title:$?"Hide sidebar":"Show sidebar","aria-label":$?"Hide sidebar":"Show sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},children:$?(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.jsx)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();x({x:t.left+t.width/2,y:t.top+t.height/2})},title:h?"Switch to light mode":"Switch to dark mode","aria-label":h?"Switch to light mode":"Switch to dark mode","aria-pressed":h,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},children:h?(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)("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:"16",height:"16",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"})})}),eV&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[(0,n.jsxs)("button",{onClick:eK,disabled:!f,title:f?"Export HTML":"Export is available after the session is saved","aria-label":"Export HTML",style:{display:"flex",alignItems:"center",gap:6,height:"100%",padding:"0 12px",background:"none",border:"none",borderTop:"2px solid transparent",borderRight:"1px solid var(--border)",color:f?"var(--text-muted)":"var(--text-dim)",cursor:f?"pointer":"not-allowed",opacity:f?1:.45,flexShrink:0,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>{f&&(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=f?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:18,height:18,borderRadius:5,background:"transparent",color:f?"var(--text-muted)":"var(--text-dim)",flexShrink:0},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.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:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}),!g&&(0,n.jsx)("span",{children:"Export"})]}),(0,n.jsx)(nm,{tree:O,activeLeafId:_,onLeafChange:Y,onSetLabel:J,inline:!0,compact:g,containerRef:N,open:"branches"===eu,onToggle:()=>eg("branches"),hasSession:!0}),(0,n.jsxs)("button",{ref:G,onClick:()=>eg("system"),title:"System prompt","aria-label":"System prompt","aria-pressed":"system"===eu,style:{display:"flex",alignItems:"center",gap:6,height:"100%",padding:"0 12px",background:"system"===eu?"var(--bg-selected)":"none",border:"none",borderTop:"system"===eu?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:"pointer",color:"system"===eu?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="system"===eu?"var(--text)":"var(--text-muted)"},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:{color:Z?"var(--accent)":"var(--text-dim)",flexShrink:0},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"})]}),!g&&(0,n.jsx)("span",{children:"System"})]})]}),eV&&(ee||ea)&&(()=>{let e=ee?.tokens,t=ee?.cost??0,r=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),o=t>0?t>=.01?`$${t.toFixed(2)}`:"<$0.01":null,i="var(--text-muted)",l=null;if(ea?.contextWindow){let e=ea.percent;null!==e&&e>90?i="#ef4444":null!==e&&e>70&&(i="rgba(234,179,8,0.95)"),l=null!==e?`${e.toFixed(0)}% / ${r(ea.contextWindow)}`:`? / ${r(ea.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)}`)),ea?.contextWindow){let e=ea.percent;s.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${ea.contextWindow.toLocaleString()} tokens`)}let a=s.join(" | ");return(0,n.jsxs)("button",{type:"button",onClick:()=>eg("session"),title:a||"Session info","aria-label":"Session info","aria-pressed":"session"===eu,style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:10,paddingLeft:12,paddingRight:ej?12:48,height:"100%",background:"session"===eu?"var(--bg-selected)":"none",border:"none",borderTop:"session"===eu?"2px solid var(--accent)":"2px solid transparent",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:"pointer",fontVariantNumeric:"tabular-nums",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="session"===eu?"var(--text)":"var(--text-muted)"},children:[g&&(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),!g&&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)]}),!g&&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)]}),!g&&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)]}),!g&&o&&(0,n.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text)",fontWeight:500},children:o}),l&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:i},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]})]})})(),eu&&eh&&(0,n.jsxs)("div",{style:{position:"fixed",top:eh.top,left:eh.left,width:eh.width,maxHeight:`calc(100dvh - ${eh.top}px)`,overflowY:"auto",zIndex:500},children:["system"===eu&&(0,n.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:Z?(0,n.jsx)("div",{style:{maxHeight:"min(600px, 75vh)",overflowY:"auto",padding:"12px 16px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:Z}):""===Z?(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"System prompt is empty (tools are disabled)"}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message to load the system prompt"})}),"session"===eu&&(0,n.jsx)("div",{className:"session-info-popover",style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",boxShadow:"0 10px 28px rgba(0,0,0,0.10)",padding:"12px 16px"},children:ee?(e=[...ee.sessionName?[{label:"Name",value:ee.sessionName,copyField:null}]:[],{label:"File",value:ee.sessionFile??"In-memory",copyField:"file"},{label:"ID",value:ee.sessionId,copyField:"id"}],t=[["User",ee.userMessages.toLocaleString()],["Assistant",ee.assistantMessages.toLocaleString()],["Tool Calls",ee.toolCalls.toLocaleString()],["Tool Results",ee.toolResults.toLocaleString()],["Total",ee.totalMessages.toLocaleString()]],r=[["Input",ee.tokens.input.toLocaleString()],["Output",ee.tokens.output.toLocaleString()],...ee.tokens.cacheRead>0?[["Cache Read",ee.tokens.cacheRead.toLocaleString()]]:[],...ee.tokens.cacheWrite>0?[["Cache Write",ee.tokens.cacheWrite.toLocaleString()]]:[],["Total",ee.tokens.total.toLocaleString()]],l=ea??ee.contextUsage,a=[...ee.cost>0?[["Cost",`$${ee.cost.toFixed(4)}`]]:[],...l?.contextWindow?[["Context",`${null!==l.percent?`${l.percent.toFixed(1)}%`:"?"} / ${(s=l.contextWindow)>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}k`:String(s)}`]]:[]],d=(e,t,r="left",o=!1)=>(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:e}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:o?"max-content max-content":"auto minmax(0, 1fr)",columnGap:o?14:12,rowGap:4,justifyContent:o?"start":void 0},children:t.map(([t,i])=>(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:t}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:o?"normal":"anywhere",textAlign:r,whiteSpace:"right"===r?"nowrap":"normal"},children:i})]},`${e}:${t}`))})]}),c=(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:"Session Info"}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:e.map(e=>{var t,r;let o;return(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:e.label}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"normal"},children:e.value}),(0,n.jsx)("div",{children:e.copyField?(t=e.copyField,r=e.value,o=eo===t,(0,n.jsx)("button",{type:"button",title:o?"Copied":`Copy ${"file"===t?"file path":"session ID"}`,onClick:()=>es(t,r),style:{alignSelf:"start",display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,marginTop:-2,color:o?"var(--accent)":"var(--text-dim)",background:"transparent",border:"1px solid var(--border)",borderRadius:4,cursor:"pointer",flex:"0 0 auto",transition:"color 0.12s, border-color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=o?"var(--accent)":"var(--text-dim)",e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="transparent"},children:o?(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})):null})]},`session-info:${e.label}`)})})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:g?"1fr":"minmax(360px, 1.7fr) minmax(140px, 0.55fr) minmax(190px, 0.75fr)",gap:g?16:24,fontSize:12,lineHeight:1.5,fontFamily:"var(--font-mono)"},children:[c,d("Messages",t),d("Tokens",[...r,...a],"right",!0)]})):(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message or run /session to load session info"})})]})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:eV?(0,n.jsx)(tZ,{session:f,newSessionCwd:eq,onAgentEnd:eP,onSessionCreated:eD,onSessionForked:eF,modelsRefreshKey:I,chatInputRef:F,onBranchDataChange:V,onSystemPromptChange:Q,onSessionStatsChange:en,onSessionStatsPanelOpen:ef,onContextUsageChange:ec,onOpenFile:e_},j):eY?eT?(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})]}),(0,n.jsxs)("div",{className:`right-panel-container${ej?" right-panel-open":" right-panel-closed"}`,style:{display:"flex",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)"},children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",height:36},children:(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(ro,{tabs:ev,activeTabId:eb??"",onSelectTab:ek,onCloseTab:eU})})}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:eJ?.filePath?(0,n.jsx)(rr,{filePath:eJ.filePath,cwd:eT??void 0,sourceSessionId:eJ.sourceSessionId}):(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)("button",{onClick:()=>ew(e=>!e),title:ej?"Hide file panel":"Show file panel","aria-label":ej?"Hide file panel":"Show file panel",style:{position:"fixed",top:0,right:0,zIndex:300,display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"var(--bg-panel)",border:"none",borderLeft:"1px solid var(--border)",borderBottom:"1px solid var(--border)",color:ej?"var(--text)":"var(--text-muted)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=ej?"var(--text)":"var(--text-muted)"},children:(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:"15",y1:"3",x2:"15",y2:"21"})]})}),T&&(0,n.jsx)(r1,{onClose:()=>{L(!1),z(e=>e+1)}}),R&&(eT??f?.cwd??v)&&(0,n.jsx)(r3,{cwd:eT??f?.cwd??v,onClose:()=>W(!1)}),M&&(eT??f?.cwd??v)&&(0,n.jsx)(nc,{cwd:eT??f?.cwd??v,sessionId:f?.id??null,onClose:()=>E(!1),onReloaded:()=>w(e=>e+1)})]})}},71675:(e,t,r)=>{Promise.resolve().then(r.bind(r,58978))}},e=>{e.O(0,[7330,4784,8441,3794,7358],()=>e(e.s=71675)),_N_E=e.O()}]);