agentstudio 0.4.2 → 0.4.3

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 (280) hide show
  1. package/config/engineConfig.d.ts +15 -0
  2. package/config/engineConfig.d.ts.map +1 -1
  3. package/config/engineConfig.js +30 -0
  4. package/config/engineConfig.js.map +1 -1
  5. package/config/index.d.ts.map +1 -1
  6. package/config/index.js +14 -0
  7. package/config/index.js.map +1 -1
  8. package/config/paths.d.ts +5 -0
  9. package/config/paths.d.ts.map +1 -1
  10. package/config/paths.js +6 -1
  11. package/config/paths.js.map +1 -1
  12. package/engines/claude/__tests__/supportedModels.test.d.ts +6 -4
  13. package/engines/claude/__tests__/supportedModels.test.d.ts.map +1 -1
  14. package/engines/claude/__tests__/supportedModels.test.js +55 -13
  15. package/engines/claude/__tests__/supportedModels.test.js.map +1 -1
  16. package/engines/claude/aguiAdapter.d.ts.map +1 -1
  17. package/engines/claude/aguiAdapter.js +8 -0
  18. package/engines/claude/aguiAdapter.js.map +1 -1
  19. package/engines/claude/claudeEngine.d.ts +36 -3
  20. package/engines/claude/claudeEngine.d.ts.map +1 -1
  21. package/engines/claude/claudeEngine.js +132 -13
  22. package/engines/claude/claudeEngine.js.map +1 -1
  23. package/index.d.ts.map +1 -1
  24. package/index.js +29 -2
  25. package/index.js.map +1 -1
  26. package/middleware/callChain.d.ts +10 -0
  27. package/middleware/callChain.d.ts.map +1 -0
  28. package/middleware/callChain.js +24 -0
  29. package/middleware/callChain.js.map +1 -0
  30. package/middleware/requestId.d.ts +8 -0
  31. package/middleware/requestId.d.ts.map +1 -0
  32. package/middleware/requestId.js +18 -0
  33. package/middleware/requestId.js.map +1 -0
  34. package/package.json +1 -1
  35. package/prompts/gameDevSystemPrompt.d.ts +15 -0
  36. package/prompts/gameDevSystemPrompt.d.ts.map +1 -0
  37. package/prompts/gameDevSystemPrompt.js +37 -0
  38. package/prompts/gameDevSystemPrompt.js.map +1 -0
  39. package/prompts/vibeGamingPrompt.d.ts +13 -0
  40. package/prompts/vibeGamingPrompt.d.ts.map +1 -0
  41. package/prompts/vibeGamingPrompt.js +125 -0
  42. package/prompts/vibeGamingPrompt.js.map +1 -0
  43. package/public/assets/{AgentsPage-BsZdkqzM.js → AgentsPage-CHee5mUh.js} +1 -1
  44. package/public/assets/{Button-CMTSYiKV.js → Button-D5qiS7CR.js} +1 -1
  45. package/public/assets/ChatPage-B7-rn9mH.js +478 -0
  46. package/public/assets/{CommandForm-DwGvE9A_.js → CommandForm-CMfgHNm5.js} +1 -1
  47. package/public/assets/{CommandsPage-qDWzq8xp.js → CommandsPage-B4rjtVWk.js} +1 -1
  48. package/public/assets/{CursorConfigPage-DpUdJzRi.js → CursorConfigPage-DQ-3b3ti.js} +1 -1
  49. package/public/assets/{DashboardPage-BhqKOzob.js → DashboardPage-BowdW2Xj.js} +1 -1
  50. package/public/assets/{EngineGate-BjHJu955.js → EngineGate-DYNvEEbW.js} +1 -1
  51. package/public/assets/{FileBrowser-DboOOM_v.js → FileBrowser-DHyCacM6.js} +1 -1
  52. package/public/assets/{FileExplorer-x5R0Tcmk.js → FileExplorer-BprfeAH_.js} +1 -1
  53. package/public/assets/GeneralSettingsPage-C6hJ_zTw.js +1 -0
  54. package/public/assets/{HooksPage-DDGc0GGV.js → HooksPage-BwE2Zm3X.js} +1 -1
  55. package/public/assets/{LandingPage-CvY4n9Rh.js → LandingPage-DKvwbGX1.js} +1 -1
  56. package/public/assets/{LoginPage-C-PZfjYC.js → LoginPage-BpZhqRAN.js} +1 -1
  57. package/public/assets/{McpAdminSettingsPage-CIILVzB8.js → McpAdminSettingsPage-DuvsM5TX.js} +1 -1
  58. package/public/assets/{McpPage-B4nQUJag.js → McpPage-Hu8vyMhX.js} +1 -1
  59. package/public/assets/{MemorySettingsPage-eu6tsuUh.js → MemorySettingsPage-gIWSsrES.js} +1 -1
  60. package/public/assets/{ModelsPage-Bb5vSsuc.js → ModelsPage-Cosb3hHI.js} +1 -1
  61. package/public/assets/PluginsPage-CuNui9NV.js +12 -0
  62. package/public/assets/{ProjectSelector-CybrDbBY.js → ProjectSelector-CyBlHb2H.js} +1 -1
  63. package/public/assets/{ProjectsPage-DRl-0B4G.js → ProjectsPage-DYhCvH07.js} +1 -1
  64. package/public/assets/{RulesPage-DUt33RkX.js → RulesPage-C32P_Aqz.js} +1 -1
  65. package/public/assets/{ScheduledTasksPage-CTDYYRIN.js → ScheduledTasksPage-ixn5qoiD.js} +1 -1
  66. package/public/assets/SettingsLayout-C_7jR0Te.js +1 -0
  67. package/public/assets/{SkillsPage-Lzw8I9vR.js → SkillsPage-C-WS4N1Y.js} +1 -1
  68. package/public/assets/{SubagentForm-BzzeWg0W.js → SubagentForm-BbxljQUp.js} +1 -1
  69. package/public/assets/{SubagentsPage-bX2XWdJ0.js → SubagentsPage-D66TBaeN.js} +1 -1
  70. package/public/assets/{SystemInfoPage-nEIQbtwG.js → SystemInfoPage-DXVUncTe.js} +1 -1
  71. package/public/assets/{TelemetrySettingsPage-q167I4G9.js → TelemetrySettingsPage-Cp3vOu7X.js} +1 -1
  72. package/public/assets/{ToastTestPage-j224d3QR.js → ToastTestPage-03up9yZR.js} +1 -1
  73. package/public/assets/{ToolsList-CTsQr53G.js → ToolsList-BZFBEuvQ.js} +1 -1
  74. package/public/assets/UnifiedToolSelector-DJN7ASu1.js +1 -0
  75. package/public/assets/{VersionSettingsPage-BwpwiLyl.js → VersionSettingsPage-DppWaX--.js} +1 -1
  76. package/public/assets/{VoiceSettingsPage-d3l9AWBn.js → VoiceSettingsPage-BWJLeedX.js} +1 -1
  77. package/public/assets/{WebSocketTunnelPage-BqEUE7mr.js → WebSocketTunnelPage-BPeSTgEZ.js} +1 -1
  78. package/public/assets/{_basePickBy-DHabY031.js → _basePickBy-0UeYrifO.js} +1 -1
  79. package/public/assets/{_baseUniq-B1lmu3qr.js → _baseUniq-Q0NUbuSr.js} +1 -1
  80. package/public/assets/{agents-KlPdWQ8K.js → agents-DR9EZMs5.js} +1 -1
  81. package/public/assets/{arc-6sRLTBcr.js → arc-BV8erW1-.js} +1 -1
  82. package/public/assets/{architectureDiagram-VXUJARFQ-kwdTmjuB.js → architectureDiagram-VXUJARFQ-BIodTu6s.js} +1 -1
  83. package/public/assets/{blockDiagram-VD42YOAC-CYO9EYkJ.js → blockDiagram-VD42YOAC-4H3KjsGf.js} +1 -1
  84. package/public/assets/{c4Diagram-YG6GDRKO-gAp3--Ee.js → c4Diagram-YG6GDRKO-J2ovCYEr.js} +1 -1
  85. package/public/assets/channel-gveiJv4S.js +1 -0
  86. package/public/assets/{chunk-4BX2VUAB-DQVsL-J6.js → chunk-4BX2VUAB-D7Mc44O6.js} +1 -1
  87. package/public/assets/{chunk-55IACEB6-DVsfnY5X.js → chunk-55IACEB6-CMASo37Z.js} +1 -1
  88. package/public/assets/{chunk-B4BG7PRW-BNmOvuIn.js → chunk-B4BG7PRW-2T3W2IB6.js} +1 -1
  89. package/public/assets/{chunk-DI55MBZ5-BkucWe8Y.js → chunk-DI55MBZ5-FR9qswmO.js} +1 -1
  90. package/public/assets/{chunk-FMBD7UC4-BsvfEdnB.js → chunk-FMBD7UC4-Bz2LO9q3.js} +1 -1
  91. package/public/assets/{chunk-QN33PNHL-DSecsNtM.js → chunk-QN33PNHL-D7mfK9Pm.js} +1 -1
  92. package/public/assets/{chunk-QZHKN3VN-DhvrZSqy.js → chunk-QZHKN3VN-AkuNbqQU.js} +1 -1
  93. package/public/assets/{chunk-TZMSLE5B-BqQ674GC.js → chunk-TZMSLE5B-DtY3rhWy.js} +1 -1
  94. package/public/assets/classDiagram-2ON5EDUG-f-lJUj27.js +1 -0
  95. package/public/assets/classDiagram-v2-WZHVMYZB-f-lJUj27.js +1 -0
  96. package/public/assets/clone-D5-Tsf9e.js +1 -0
  97. package/public/assets/{cose-bilkent-S5V4N54A-D9ZC6LmB.js → cose-bilkent-S5V4N54A-BuEw-qDX.js} +1 -1
  98. package/public/assets/{dagre-6UL2VRFP-s7YD2ZcY.js → dagre-6UL2VRFP-D-NrLBGh.js} +1 -1
  99. package/public/assets/{diagram-PSM6KHXK-C7jhP5tx.js → diagram-PSM6KHXK-BFjWOHNz.js} +1 -1
  100. package/public/assets/{diagram-QEK2KX5R-B348GmS1.js → diagram-QEK2KX5R-C0YlDb8t.js} +1 -1
  101. package/public/assets/{diagram-S2PKOQOG-Cu-zjwc9.js → diagram-S2PKOQOG-BLKbR12g.js} +1 -1
  102. package/public/assets/{erDiagram-Q2GNP2WA-tM4HKBpy.js → erDiagram-Q2GNP2WA-Cov6xnUk.js} +1 -1
  103. package/public/assets/{flowDiagram-NV44I4VS-DjCIshpi.js → flowDiagram-NV44I4VS-DTMKSJI1.js} +1 -1
  104. package/public/assets/{ganttDiagram-LVOFAZNH-Q6plkI5G.js → ganttDiagram-LVOFAZNH-DR0bcfHY.js} +1 -1
  105. package/public/assets/{gitGraphDiagram-NY62KEGX-B3Uw90Yt.js → gitGraphDiagram-NY62KEGX-CvxYSabY.js} +1 -1
  106. package/public/assets/{graph-Bp0jlxBT.js → graph-BYXvelIL.js} +1 -1
  107. package/public/assets/{index-f67nhEoX.js → index-BIGPvi1D.js} +44 -44
  108. package/public/assets/infoDiagram-F6ZHWCRC-CL9g-UgS.js +2 -0
  109. package/public/assets/{journeyDiagram-XKPGCS4Q-CgQogtHU.js → journeyDiagram-XKPGCS4Q-Df8G0pW8.js} +1 -1
  110. package/public/assets/{kanban-definition-3W4ZIXB7-Cv7kVxyy.js → kanban-definition-3W4ZIXB7-DhoP7TG_.js} +1 -1
  111. package/public/assets/{layout-6bkH32V1.js → layout-CgO4Vp_y.js} +1 -1
  112. package/public/assets/{linear-DWoZ6Tbm.js → linear-CaY74pOB.js} +1 -1
  113. package/public/assets/{mindmap-definition-VGOIOE7T-D5wd9HsH.js → mindmap-definition-VGOIOE7T-CVK2y0WQ.js} +1 -1
  114. package/public/assets/{pieDiagram-ADFJNKIX-8vPxErLm.js → pieDiagram-ADFJNKIX-BQt_waQk.js} +1 -1
  115. package/public/assets/{quadrantDiagram-AYHSOK5B-Pn0NZ9k7.js → quadrantDiagram-AYHSOK5B-DvLFoDeH.js} +1 -1
  116. package/public/assets/{requirementDiagram-UZGBJVZJ-C7u8MiN1.js → requirementDiagram-UZGBJVZJ-C4lqjEUP.js} +1 -1
  117. package/public/assets/{sankeyDiagram-TZEHDZUN-C660O4mw.js → sankeyDiagram-TZEHDZUN-BKIDyl6M.js} +1 -1
  118. package/public/assets/{sequenceDiagram-WL72ISMW-pXBA2_3B.js → sequenceDiagram-WL72ISMW-BeyhJ61U.js} +1 -1
  119. package/public/assets/{stateDiagram-FKZM4ZOC-CxZMM1Lf.js → stateDiagram-FKZM4ZOC-CKyn6eKl.js} +1 -1
  120. package/public/assets/stateDiagram-v2-4FDKWEC3-DogBVcJE.js +1 -0
  121. package/public/assets/{table-Clz57edU.js → table-BgVewkB5.js} +1 -1
  122. package/public/assets/{timeline-definition-IT6M3QCI-Crg44TaP.js → timeline-definition-IT6M3QCI-Cm5SIAmT.js} +1 -1
  123. package/public/assets/tools-crrPnehB.js +1 -0
  124. package/public/assets/{treemap-KMMF4GRG-bFxwBWXw.js → treemap-KMMF4GRG-CUMeoVWM.js} +1 -1
  125. package/public/assets/{ui-components-DjgDPiqV.js → ui-components-D1pZO0y-.js} +1 -1
  126. package/public/assets/{useAgents-8KXN6U61.js → useAgents-M4lcWvy0.js} +1 -1
  127. package/public/assets/{useClaudeVersions-DicHLV6A.js → useClaudeVersions-CKT_fq1t.js} +1 -1
  128. package/public/assets/{useCommands-DbSH48ba.js → useCommands-vaoVPEDI.js} +1 -1
  129. package/public/assets/{useProjects-Bbh6hJMM.js → useProjects-D1ElB-WS.js} +1 -1
  130. package/public/assets/{useSessions-DOa4-xiB.js → useSessions-Dp1kUl43.js} +1 -1
  131. package/public/assets/{xychartDiagram-PRI3JC2R-DG3KmjD-.js → xychartDiagram-PRI3JC2R-Cy-SHDyX.js} +1 -1
  132. package/public/index.html +4 -4
  133. package/routes/a2a.d.ts.map +1 -1
  134. package/routes/a2a.js +27 -7
  135. package/routes/a2a.js.map +1 -1
  136. package/routes/agents.d.ts.map +1 -1
  137. package/routes/agents.js +234 -38
  138. package/routes/agents.js.map +1 -1
  139. package/routes/agui.d.ts.map +1 -1
  140. package/routes/agui.js +44 -1
  141. package/routes/agui.js.map +1 -1
  142. package/routes/gitVersions.d.ts.map +1 -1
  143. package/routes/gitVersions.js +80 -1
  144. package/routes/gitVersions.js.map +1 -1
  145. package/routes/marketplaceSkills.d.ts +18 -0
  146. package/routes/marketplaceSkills.d.ts.map +1 -0
  147. package/routes/marketplaceSkills.js +190 -0
  148. package/routes/marketplaceSkills.js.map +1 -0
  149. package/routes/plugins.d.ts.map +1 -1
  150. package/routes/plugins.js +48 -7
  151. package/routes/plugins.js.map +1 -1
  152. package/routes/projects.d.ts.map +1 -1
  153. package/routes/projects.js +34 -0
  154. package/routes/projects.js.map +1 -1
  155. package/schemas/a2a.d.ts +35 -4
  156. package/schemas/a2a.d.ts.map +1 -1
  157. package/schemas/a2a.js +9 -1
  158. package/schemas/a2a.js.map +1 -1
  159. package/services/__tests__/agentImporter.test.js +197 -0
  160. package/services/__tests__/agentImporter.test.js.map +1 -1
  161. package/services/__tests__/pluginInstaller.test.js +2 -1
  162. package/services/__tests__/pluginInstaller.test.js.map +1 -1
  163. package/services/agentImporter.d.ts +7 -0
  164. package/services/agentImporter.d.ts.map +1 -1
  165. package/services/agentImporter.js +57 -4
  166. package/services/agentImporter.js.map +1 -1
  167. package/services/builtinMarketplaceService.d.ts +56 -0
  168. package/services/builtinMarketplaceService.d.ts.map +1 -0
  169. package/services/builtinMarketplaceService.js +328 -0
  170. package/services/builtinMarketplaceService.js.map +1 -0
  171. package/services/claudeSession.d.ts.map +1 -1
  172. package/services/claudeSession.js +15 -4
  173. package/services/claudeSession.js.map +1 -1
  174. package/services/claudeVersionStorage.js +6 -6
  175. package/services/claudeVersionStorage.js.map +1 -1
  176. package/services/gitVersionService.d.ts +22 -0
  177. package/services/gitVersionService.d.ts.map +1 -1
  178. package/services/gitVersionService.js +117 -19
  179. package/services/gitVersionService.js.map +1 -1
  180. package/services/marketplaceSkillService.d.ts +129 -0
  181. package/services/marketplaceSkillService.d.ts.map +1 -0
  182. package/services/marketplaceSkillService.js +358 -0
  183. package/services/marketplaceSkillService.js.map +1 -0
  184. package/services/marketplaceUpdateService.d.ts.map +1 -1
  185. package/services/marketplaceUpdateService.js +29 -2
  186. package/services/marketplaceUpdateService.js.map +1 -1
  187. package/services/pluginCopyInstall.d.ts +60 -0
  188. package/services/pluginCopyInstall.d.ts.map +1 -0
  189. package/services/pluginCopyInstall.js +290 -0
  190. package/services/pluginCopyInstall.js.map +1 -0
  191. package/services/pluginInstallStrategy.d.ts +39 -0
  192. package/services/pluginInstallStrategy.d.ts.map +1 -0
  193. package/services/pluginInstallStrategy.js +50 -0
  194. package/services/pluginInstallStrategy.js.map +1 -0
  195. package/services/pluginInstaller.d.ts +10 -0
  196. package/services/pluginInstaller.d.ts.map +1 -1
  197. package/services/pluginInstaller.js +70 -20
  198. package/services/pluginInstaller.js.map +1 -1
  199. package/services/pluginParser.d.ts +17 -1
  200. package/services/pluginParser.d.ts.map +1 -1
  201. package/services/pluginParser.js +161 -84
  202. package/services/pluginParser.js.map +1 -1
  203. package/services/pluginPaths.d.ts +3 -3
  204. package/services/pluginPaths.d.ts.map +1 -1
  205. package/services/pluginPaths.js +33 -14
  206. package/services/pluginPaths.js.map +1 -1
  207. package/services/pluginScanner.js +2 -2
  208. package/services/pluginScanner.js.map +1 -1
  209. package/services/pluginSymlink.d.ts +10 -0
  210. package/services/pluginSymlink.d.ts.map +1 -1
  211. package/services/pluginSymlink.js +117 -1
  212. package/services/pluginSymlink.js.map +1 -1
  213. package/services/preSendGuard/__tests__/preSendGuard.test.d.ts +2 -0
  214. package/services/preSendGuard/__tests__/preSendGuard.test.d.ts.map +1 -0
  215. package/services/preSendGuard/__tests__/preSendGuard.test.js +102 -0
  216. package/services/preSendGuard/__tests__/preSendGuard.test.js.map +1 -0
  217. package/services/preSendGuard/configResolver.d.ts +8 -0
  218. package/services/preSendGuard/configResolver.d.ts.map +1 -0
  219. package/services/preSendGuard/configResolver.js +181 -0
  220. package/services/preSendGuard/configResolver.js.map +1 -0
  221. package/services/preSendGuard/index.d.ts +9 -0
  222. package/services/preSendGuard/index.d.ts.map +1 -0
  223. package/services/preSendGuard/index.js +165 -0
  224. package/services/preSendGuard/index.js.map +1 -0
  225. package/services/preSendGuard/providers/httpAuditProvider.d.ts +3 -0
  226. package/services/preSendGuard/providers/httpAuditProvider.d.ts.map +1 -0
  227. package/services/preSendGuard/providers/httpAuditProvider.js +98 -0
  228. package/services/preSendGuard/providers/httpAuditProvider.js.map +1 -0
  229. package/services/preSendGuard/providers/noopProvider.d.ts +3 -0
  230. package/services/preSendGuard/providers/noopProvider.d.ts.map +1 -0
  231. package/services/preSendGuard/providers/noopProvider.js +13 -0
  232. package/services/preSendGuard/providers/noopProvider.js.map +1 -0
  233. package/services/runFinishedHooks.d.ts +29 -0
  234. package/services/runFinishedHooks.d.ts.map +1 -0
  235. package/services/runFinishedHooks.js +57 -0
  236. package/services/runFinishedHooks.js.map +1 -0
  237. package/testing/index.d.ts +18 -0
  238. package/testing/index.d.ts.map +1 -0
  239. package/testing/index.js +25 -0
  240. package/testing/index.js.map +1 -0
  241. package/testing/mockSdkQuery.d.ts +49 -0
  242. package/testing/mockSdkQuery.d.ts.map +1 -0
  243. package/testing/mockSdkQuery.js +209 -0
  244. package/testing/mockSdkQuery.js.map +1 -0
  245. package/testing/scenarioLoader.d.ts +71 -0
  246. package/testing/scenarioLoader.d.ts.map +1 -0
  247. package/testing/scenarioLoader.js +224 -0
  248. package/testing/scenarioLoader.js.map +1 -0
  249. package/types/a2a.d.ts +5 -0
  250. package/types/a2a.d.ts.map +1 -1
  251. package/types/agents.d.ts +32 -0
  252. package/types/agents.d.ts.map +1 -1
  253. package/types/agents.js +1 -0
  254. package/types/agents.js.map +1 -1
  255. package/types/engine.d.ts +6 -0
  256. package/types/engine.d.ts.map +1 -1
  257. package/types/plugins.d.ts +12 -2
  258. package/types/plugins.d.ts.map +1 -1
  259. package/types/preSendGuard.d.ts +51 -0
  260. package/types/preSendGuard.d.ts.map +1 -0
  261. package/types/preSendGuard.js +3 -0
  262. package/types/preSendGuard.js.map +1 -0
  263. package/utils/__tests__/claudeUtils.test.js +89 -1
  264. package/utils/__tests__/claudeUtils.test.js.map +1 -1
  265. package/utils/claudeUtils.d.ts +1 -1
  266. package/utils/claudeUtils.d.ts.map +1 -1
  267. package/utils/claudeUtils.js +92 -37
  268. package/utils/claudeUtils.js.map +1 -1
  269. package/public/assets/ChatPage-D8buVhfb.js +0 -478
  270. package/public/assets/GeneralSettingsPage-DYdwai51.js +0 -1
  271. package/public/assets/PluginsPage-DD92Xk6X.js +0 -12
  272. package/public/assets/SettingsLayout-LGC-0pQl.js +0 -1
  273. package/public/assets/UnifiedToolSelector-BP6fuyzG.js +0 -1
  274. package/public/assets/channel-D9wyZF1L.js +0 -1
  275. package/public/assets/classDiagram-2ON5EDUG-DwEqkkEb.js +0 -1
  276. package/public/assets/classDiagram-v2-WZHVMYZB-DwEqkkEb.js +0 -1
  277. package/public/assets/clone-3wFPaI2j.js +0 -1
  278. package/public/assets/infoDiagram-F6ZHWCRC-HUfwv_JT.js +0 -2
  279. package/public/assets/stateDiagram-v2-4FDKWEC3-CmurzrWf.js +0 -1
  280. package/public/assets/tools-BZTR2NP1.js +0 -1
@@ -1 +1 @@
1
- import{j as e}from"./data-structures-ChC1tqVg.js";import{r as m}from"./monaco-editor-BWfQfpij.js";import{u as H,a as F,A}from"./agents-KlPdWQ8K.js";import{a as J,b as M,c as V}from"./useAgents-8KXN6U61.js";import{F as S}from"./FileBrowser-DboOOM_v.js";import{c as Y,a as P}from"./index-f67nhEoX.js";import{u as I}from"./tools-BZTR2NP1.js";import{X as $,am as E,S as Z,u as ee}from"./ui-components-DjgDPiqV.js";const de=({agent:a,onProjectSelect:c,onClose:g})=>{const{t}=I("components"),n=Y(),[x,j]=m.useState(!1),[h,f]=m.useState(!1),[B,b]=m.useState(!1),[T,w]=m.useState(!1),[C,N]=m.useState(""),[q,k]=m.useState(!1),D=J(),z=M(),v=H(),{data:L,isLoading:Q}=V(a.id),u=L?.projects||[],R=async()=>{j(!0);try{const r=a.id.replace(/[-_]/g,"-"),s=new Date().toISOString().slice(0,16).replace(/[:T]/g,"-"),l=`${r}-project-${s}`,d=await D.mutateAsync({agentId:a.id,projectName:l});await v.invalidateQueries({queryKey:["agent-projects",a.id]}),c(d.project.path)}catch(r){console.error("Failed to create project:",r),P(t("projectSelector.createProjectFailed",{error:""}),r instanceof Error?r.message:t("projectSelector.unknownError"))}finally{j(!1)}},K=()=>{b(!0)},U=(r,s)=>{s&&(N(r),b(!1),k(!0))},W=async r=>{j(!0);try{const s=r,l=await D.mutateAsync({agentId:a.id,projectName:s,parentDirectory:C||void 0});await v.invalidateQueries({queryKey:["agent-projects",a.id]}),c(l.project.path)}catch(s){console.error("Failed to create project:",s),P(t("projectSelector.createProjectFailed",{error:""}),s instanceof Error?s.message:t("projectSelector.unknownError"))}finally{j(!1),k(!1),N("")}},_=()=>{f(!0)},O=async(r,s)=>{if(s){const l=r.replace(/\/$/,""),d=u.map(o=>o.path.replace(/\/$/,""));let i=d.includes(l);if(!i)try{const o=await F(`${A}/files/browse?path=${encodeURIComponent(r)}/.cc-sessions`);o.ok&&(await o.json()).items?.some(y=>y.isDirectory&&y.name===a.id)&&(i=!0)}catch{}if(console.log("Import path comparison:",{selectedPath:l,agentProjects:d,isExisting:i}),i)c(r),w(!1);else if(await n({title:t("projectSelector.importConfirmationTitle","导入项目"),message:t("projectSelector.importConfirmation",{agentName:a.name,path:r}),confirmText:t("projectSelector.import","导入"),cancelText:t("projectSelector.cancel","取消"),variant:"info"}))try{await z.mutateAsync({agentId:a.id,projectPath:r}),await v.invalidateQueries({queryKey:["agent-projects",a.id]}),c(r),w(!1)}catch(p){console.error("Failed to import project:",p),P(t("projectSelector.importProjectFailed",{error:""}),p instanceof Error?p.message:t("projectSelector.unknownError"))}}},X=async(r,s)=>{if(s){const l=r.replace(/\/$/,""),d=u.map(o=>o.path.replace(/\/$/,""));let i=d.includes(l);if(!i)try{const o=await F(`${A}/files/browse?path=${encodeURIComponent(r)}/.cc-sessions`);o.ok&&(await o.json()).items?.some(y=>y.isDirectory&&y.name===a.id)&&(i=!0)}catch{}console.log("Path comparison:",{selectedPath:l,agentProjects:d,isExisting:i}),(i||await n({title:t("projectSelector.importConfirmationTitle","导入项目"),message:t("projectSelector.importConfirmation",{agentName:a.name,path:r}),confirmText:t("projectSelector.import","导入"),cancelText:t("projectSelector.cancel","取消"),variant:"info"}))&&(c(r),f(!1))}};return e.jsxs("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:[e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg w-full max-w-6xl mx-4 max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"text-2xl",children:a.ui.icon}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:a.name}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:t("projectSelector.selectProjectDirectory")})]})]}),e.jsx("button",{onClick:g,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 flex-shrink-0",children:e.jsx($,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex flex-1 min-h-0 flex-col md:flex-row",children:[e.jsxs("div",{className:"w-full md:w-1/2 p-6 md:border-r border-gray-200 dark:border-gray-700",children:[e.jsx("h4",{className:"text-base font-medium text-gray-900 dark:text-white mb-4",children:t("projectSelector.projectActions")}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{onClick:R,disabled:x,className:"w-full flex items-center space-x-4 p-4 border border-primary/40 dark:border-primary/60 rounded-lg hover:bg-primary/5 dark:hover:bg-primary/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(E,{className:`w-6 h-6 ${x?"text-gray-400 dark:text-gray-500":"text-primary"}`})}),e.jsxs("div",{className:"text-left flex-1",children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:t(x?"projectSelector.creatingProject":"projectSelector.quickCreateProject")}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:t("projectSelector.quickCreateDescription")})]})]}),e.jsxs("button",{onClick:K,disabled:x,className:"w-full flex items-center space-x-4 p-4 border border-gray-200 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(E,{className:"w-6 h-6 text-gray-600 dark:text-gray-400"})}),e.jsxs("div",{className:"text-left flex-1",children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:t("projectSelector.customLocationCreate")}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:t("projectSelector.customLocationDescription")})]})]}),e.jsxs("button",{onClick:_,className:"w-full flex items-center space-x-4 p-4 border border-gray-200 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(Z,{className:"w-6 h-6 text-gray-600 dark:text-gray-400"})}),e.jsxs("div",{className:"text-left flex-1",children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:t("projectSelector.browseProject")}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:t("projectSelector.browseDescription")})]})]})]})]}),e.jsxs("div",{className:"w-full md:w-1/2 p-6 flex flex-col min-h-[300px] md:min-h-0",children:[e.jsx("h4",{className:"text-base font-medium text-gray-900 dark:text-white mb-4",children:t("projectSelector.recentProjects")}),Q?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"animate-spin w-8 h-8 border-4 border-gray-300 dark:border-gray-600 border-t-blue-600 dark:border-t-blue-500 rounded-full mx-auto mb-3"}),e.jsx("p",{className:"text-sm",children:t("projectSelector.loadingProjects")})]})}):u.length>0?e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("div",{className:"space-y-2 max-h-full overflow-y-auto",children:u.map((r,s)=>e.jsxs("button",{onClick:()=>c(r.path),className:"w-full flex items-center space-x-3 p-4 border border-gray-100 dark:border-gray-700 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-left",children:[e.jsx("div",{className:"w-5 h-5 flex-shrink-0 text-xl text-primary",children:r.defaultAgentIcon||"📁"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white truncate",children:r.name}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 truncate mt-1",children:r.path}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500 mt-1",children:t("projectSelector.lastAccessed",{date:new Date(r.lastAccessed).toLocaleString()})})]})]},r.id||s))})}):e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx(ee,{className:"w-16 h-16 text-gray-300 dark:text-gray-600 mx-auto mb-3"}),e.jsx("p",{className:"text-base font-medium",children:t("projectSelector.noRecentProjects")}),e.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500 mt-1",children:t("projectSelector.createProjectToStart")})]})})]})]}),e.jsx("div",{className:"flex justify-end p-6 border-t border-gray-200 dark:border-gray-700 flex-shrink-0",children:e.jsx("button",{onClick:g,className:"px-6 py-2 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200 transition-colors",children:t("projectSelector.cancel")})})]}),h&&e.jsx(S,{title:t("projectSelector.selectProjectDirectory"),allowFiles:!1,allowDirectories:!0,onSelect:X,onClose:()=>f(!1)}),B&&e.jsx(S,{title:t("projectSelector.selectParentDirectory"),allowFiles:!1,allowDirectories:!0,allowNewDirectory:!0,onSelect:U,onClose:()=>b(!1)}),T&&e.jsx(S,{title:t("projectSelector.importProject"),allowFiles:!1,allowDirectories:!0,onSelect:O,onClose:()=>w(!1)}),q&&e.jsx(te,{parentDirectory:C,onConfirm:W,onCancel:()=>{k(!1),N("")}})]})},te=({parentDirectory:a,onConfirm:c,onCancel:g})=>{const{t}=I("components"),[n,x]=m.useState(""),j=h=>{h.preventDefault(),n.trim()&&c(n.trim())};return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[60]",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg p-6 w-full max-w-md mx-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:t("projectSelector.dialog.createNewProject")}),e.jsx("button",{onClick:g,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx($,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-2",children:t("projectSelector.dialog.projectWillBeCreatedAt")}),e.jsx("div",{className:"p-2 bg-gray-100 dark:bg-gray-700 rounded text-sm font-mono text-gray-800 dark:text-gray-200 break-all",children:a})]}),e.jsxs("form",{onSubmit:j,children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"projectName",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:t("projectSelector.dialog.projectName")}),e.jsx("input",{id:"projectName",type:"text",value:n,onChange:h=>x(h.target.value),placeholder:t("projectSelector.dialog.projectNamePlaceholder"),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent",autoFocus:!0,required:!0})]}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{type:"button",onClick:g,className:"px-4 py-2 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200 transition-colors",children:t("projectSelector.dialog.cancel")}),e.jsx("button",{type:"submit",disabled:!n.trim(),className:"px-4 py-2 text-sm bg-blue-600 dark:bg-blue-500 text-white rounded-lg hover:bg-blue-700 dark:hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:t("projectSelector.dialog.createProject")})]})]})]})})};export{de as P};
1
+ import{j as e}from"./data-structures-ChC1tqVg.js";import{r as m}from"./monaco-editor-BWfQfpij.js";import{u as H,a as F,A}from"./agents-DR9EZMs5.js";import{a as J,b as M,c as V}from"./useAgents-M4lcWvy0.js";import{F as S}from"./FileBrowser-DHyCacM6.js";import{c as Y,a as P}from"./index-BIGPvi1D.js";import{u as I}from"./tools-crrPnehB.js";import{X as $,am as E,S as Z,u as ee}from"./ui-components-D1pZO0y-.js";const de=({agent:a,onProjectSelect:c,onClose:g})=>{const{t}=I("components"),n=Y(),[x,j]=m.useState(!1),[h,f]=m.useState(!1),[B,b]=m.useState(!1),[T,w]=m.useState(!1),[C,N]=m.useState(""),[q,k]=m.useState(!1),D=J(),z=M(),v=H(),{data:L,isLoading:Q}=V(a.id),u=L?.projects||[],R=async()=>{j(!0);try{const r=a.id.replace(/[-_]/g,"-"),s=new Date().toISOString().slice(0,16).replace(/[:T]/g,"-"),l=`${r}-project-${s}`,d=await D.mutateAsync({agentId:a.id,projectName:l});await v.invalidateQueries({queryKey:["agent-projects",a.id]}),c(d.project.path)}catch(r){console.error("Failed to create project:",r),P(t("projectSelector.createProjectFailed",{error:""}),r instanceof Error?r.message:t("projectSelector.unknownError"))}finally{j(!1)}},K=()=>{b(!0)},U=(r,s)=>{s&&(N(r),b(!1),k(!0))},W=async r=>{j(!0);try{const s=r,l=await D.mutateAsync({agentId:a.id,projectName:s,parentDirectory:C||void 0});await v.invalidateQueries({queryKey:["agent-projects",a.id]}),c(l.project.path)}catch(s){console.error("Failed to create project:",s),P(t("projectSelector.createProjectFailed",{error:""}),s instanceof Error?s.message:t("projectSelector.unknownError"))}finally{j(!1),k(!1),N("")}},_=()=>{f(!0)},O=async(r,s)=>{if(s){const l=r.replace(/\/$/,""),d=u.map(o=>o.path.replace(/\/$/,""));let i=d.includes(l);if(!i)try{const o=await F(`${A}/files/browse?path=${encodeURIComponent(r)}/.cc-sessions`);o.ok&&(await o.json()).items?.some(y=>y.isDirectory&&y.name===a.id)&&(i=!0)}catch{}if(console.log("Import path comparison:",{selectedPath:l,agentProjects:d,isExisting:i}),i)c(r),w(!1);else if(await n({title:t("projectSelector.importConfirmationTitle","导入项目"),message:t("projectSelector.importConfirmation",{agentName:a.name,path:r}),confirmText:t("projectSelector.import","导入"),cancelText:t("projectSelector.cancel","取消"),variant:"info"}))try{await z.mutateAsync({agentId:a.id,projectPath:r}),await v.invalidateQueries({queryKey:["agent-projects",a.id]}),c(r),w(!1)}catch(p){console.error("Failed to import project:",p),P(t("projectSelector.importProjectFailed",{error:""}),p instanceof Error?p.message:t("projectSelector.unknownError"))}}},X=async(r,s)=>{if(s){const l=r.replace(/\/$/,""),d=u.map(o=>o.path.replace(/\/$/,""));let i=d.includes(l);if(!i)try{const o=await F(`${A}/files/browse?path=${encodeURIComponent(r)}/.cc-sessions`);o.ok&&(await o.json()).items?.some(y=>y.isDirectory&&y.name===a.id)&&(i=!0)}catch{}console.log("Path comparison:",{selectedPath:l,agentProjects:d,isExisting:i}),(i||await n({title:t("projectSelector.importConfirmationTitle","导入项目"),message:t("projectSelector.importConfirmation",{agentName:a.name,path:r}),confirmText:t("projectSelector.import","导入"),cancelText:t("projectSelector.cancel","取消"),variant:"info"}))&&(c(r),f(!1))}};return e.jsxs("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:[e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg w-full max-w-6xl mx-4 max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"text-2xl",children:a.ui.icon}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:a.name}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:t("projectSelector.selectProjectDirectory")})]})]}),e.jsx("button",{onClick:g,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 flex-shrink-0",children:e.jsx($,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex flex-1 min-h-0 flex-col md:flex-row",children:[e.jsxs("div",{className:"w-full md:w-1/2 p-6 md:border-r border-gray-200 dark:border-gray-700",children:[e.jsx("h4",{className:"text-base font-medium text-gray-900 dark:text-white mb-4",children:t("projectSelector.projectActions")}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{onClick:R,disabled:x,className:"w-full flex items-center space-x-4 p-4 border border-primary/40 dark:border-primary/60 rounded-lg hover:bg-primary/5 dark:hover:bg-primary/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(E,{className:`w-6 h-6 ${x?"text-gray-400 dark:text-gray-500":"text-primary"}`})}),e.jsxs("div",{className:"text-left flex-1",children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:t(x?"projectSelector.creatingProject":"projectSelector.quickCreateProject")}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:t("projectSelector.quickCreateDescription")})]})]}),e.jsxs("button",{onClick:K,disabled:x,className:"w-full flex items-center space-x-4 p-4 border border-gray-200 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(E,{className:"w-6 h-6 text-gray-600 dark:text-gray-400"})}),e.jsxs("div",{className:"text-left flex-1",children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:t("projectSelector.customLocationCreate")}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:t("projectSelector.customLocationDescription")})]})]}),e.jsxs("button",{onClick:_,className:"w-full flex items-center space-x-4 p-4 border border-gray-200 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(Z,{className:"w-6 h-6 text-gray-600 dark:text-gray-400"})}),e.jsxs("div",{className:"text-left flex-1",children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:t("projectSelector.browseProject")}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:t("projectSelector.browseDescription")})]})]})]})]}),e.jsxs("div",{className:"w-full md:w-1/2 p-6 flex flex-col min-h-[300px] md:min-h-0",children:[e.jsx("h4",{className:"text-base font-medium text-gray-900 dark:text-white mb-4",children:t("projectSelector.recentProjects")}),Q?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"animate-spin w-8 h-8 border-4 border-gray-300 dark:border-gray-600 border-t-blue-600 dark:border-t-blue-500 rounded-full mx-auto mb-3"}),e.jsx("p",{className:"text-sm",children:t("projectSelector.loadingProjects")})]})}):u.length>0?e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("div",{className:"space-y-2 max-h-full overflow-y-auto",children:u.map((r,s)=>e.jsxs("button",{onClick:()=>c(r.path),className:"w-full flex items-center space-x-3 p-4 border border-gray-100 dark:border-gray-700 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-left",children:[e.jsx("div",{className:"w-5 h-5 flex-shrink-0 text-xl text-primary",children:r.defaultAgentIcon||"📁"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white truncate",children:r.name}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 truncate mt-1",children:r.path}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500 mt-1",children:t("projectSelector.lastAccessed",{date:new Date(r.lastAccessed).toLocaleString()})})]})]},r.id||s))})}):e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx(ee,{className:"w-16 h-16 text-gray-300 dark:text-gray-600 mx-auto mb-3"}),e.jsx("p",{className:"text-base font-medium",children:t("projectSelector.noRecentProjects")}),e.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500 mt-1",children:t("projectSelector.createProjectToStart")})]})})]})]}),e.jsx("div",{className:"flex justify-end p-6 border-t border-gray-200 dark:border-gray-700 flex-shrink-0",children:e.jsx("button",{onClick:g,className:"px-6 py-2 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200 transition-colors",children:t("projectSelector.cancel")})})]}),h&&e.jsx(S,{title:t("projectSelector.selectProjectDirectory"),allowFiles:!1,allowDirectories:!0,onSelect:X,onClose:()=>f(!1)}),B&&e.jsx(S,{title:t("projectSelector.selectParentDirectory"),allowFiles:!1,allowDirectories:!0,allowNewDirectory:!0,onSelect:U,onClose:()=>b(!1)}),T&&e.jsx(S,{title:t("projectSelector.importProject"),allowFiles:!1,allowDirectories:!0,onSelect:O,onClose:()=>w(!1)}),q&&e.jsx(te,{parentDirectory:C,onConfirm:W,onCancel:()=>{k(!1),N("")}})]})},te=({parentDirectory:a,onConfirm:c,onCancel:g})=>{const{t}=I("components"),[n,x]=m.useState(""),j=h=>{h.preventDefault(),n.trim()&&c(n.trim())};return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[60]",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg p-6 w-full max-w-md mx-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:t("projectSelector.dialog.createNewProject")}),e.jsx("button",{onClick:g,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx($,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-2",children:t("projectSelector.dialog.projectWillBeCreatedAt")}),e.jsx("div",{className:"p-2 bg-gray-100 dark:bg-gray-700 rounded text-sm font-mono text-gray-800 dark:text-gray-200 break-all",children:a})]}),e.jsxs("form",{onSubmit:j,children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"projectName",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:t("projectSelector.dialog.projectName")}),e.jsx("input",{id:"projectName",type:"text",value:n,onChange:h=>x(h.target.value),placeholder:t("projectSelector.dialog.projectNamePlaceholder"),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent",autoFocus:!0,required:!0})]}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{type:"button",onClick:g,className:"px-4 py-2 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200 transition-colors",children:t("projectSelector.dialog.cancel")}),e.jsx("button",{type:"submit",disabled:!n.trim(),className:"px-4 py-2 text-sm bg-blue-600 dark:bg-blue-500 text-white rounded-lg hover:bg-blue-700 dark:hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:t("projectSelector.dialog.createProject")})]})]})]})})};export{de as P};
@@ -1,4 +1,4 @@
1
- import{j as e}from"./data-structures-ChC1tqVg.js";import{r as o,W as Ge}from"./monaco-editor-BWfQfpij.js";import{a as $,A as T,b as at,u as qe,c as _e}from"./agents-KlPdWQ8K.js";import{s as Q,a as E,b as rt,c as st}from"./index-f67nhEoX.js";import{f as ve}from"./dateFormat-CXa8VnEC.js";import{u as be}from"./tools-BZTR2NP1.js";import{a5 as We,ak as Ye,t as re,a3 as we,aP as Ae,r as $e,y as Z,M as nt,k as $t,u as Be,aQ as Xe,a6 as Oe,d as Tt,X as J,j as Ce,a4 as lt,T as Pt,S as He,v as ue,o as Ze,D as ye,m as Te,J as Pe,a8 as ke,A as Le,R as et,I as he,aR as de,a9 as Et,E as It,aS as ze,aT as Ft,aU as Kt,V as Dt,ae as tt,z as pe,$ as Rt,aV as Ut,_ as dt,L as Ve,aq as Lt,e as zt}from"./ui-components-DjgDPiqV.js";import{u as Ot}from"./useAgents-8KXN6U61.js";import{F as ot}from"./FileBrowser-DboOOM_v.js";import{T as it,a as ct,b as Ee,c as Y,d as xt,e as X}from"./table-Clz57edU.js";import{f as Vt,g as qt}from"./useCommands-DbSH48ba.js";import{C as _t}from"./CommandForm-DwGvE9A_.js";import{g as Ie}from"./UnifiedToolSelector-BP6fuyzG.js";import{b as Bt,c as Ht,S as Jt}from"./SubagentForm-BzzeWg0W.js";import{u as Qt}from"./useProjects-Bbh6hJMM.js";import{u as Gt}from"./useClaudeVersions-DicHLV6A.js";import"./syntax-highlighting-DGbNjS3S.js";const Wt=({projects:a,agents:g,onOpenProject:t,onMemoryManagement:s,onCommandManagement:c,onSubAgentManagement:j,onA2AManagement:k,onVersionManagement:N,onSettings:p,onDeleteProject:h,onAgentChanged:f,className:w=""})=>{const{t:d}=be("pages"),[y,S]=o.useState(null),I=async(l,u)=>{if(u!==l.defaultAgent)try{S(l.id);const A=await $(`${T}/projects/${encodeURIComponent(l.path)}/default-agent`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentId:u})});if(A.ok){const v=g.find(oe=>oe.id===u);v&&f&&f(l.id,v),Q("助手切换成功")}else{const v=await A.json();throw new Error(v.error||"切换助手失败")}}catch(A){console.error("Failed to change agent:",A),E("切换助手失败",A instanceof Error?A.message:"未知错误")}finally{S(null)}},U=(l,u=!1)=>e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("button",{onClick:()=>t(l),className:`text-sm font-medium text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300 hover:underline cursor-pointer text-left truncate ${u?"text-base":""}`,children:l.name}),e.jsx("button",{onClick:()=>t(l),className:"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors flex-shrink-0",title:d("projects.actions.open"),children:e.jsx(nt,{className:"w-3 h-3"})})]}),l.description&&e.jsx("div",{className:`text-gray-500 dark:text-gray-400 truncate ${u?"text-sm mt-1":"text-sm max-w-xs"}`,children:l.description})]}),K=l=>{const u=g.filter(v=>v.enabled),A=y===l.id;return e.jsxs("div",{className:"relative inline-block",onClick:v=>v.stopPropagation(),children:[e.jsx("select",{value:l.defaultAgent,onChange:v=>I(l,v.target.value),disabled:A,className:"appearance-none bg-white dark:bg-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 rounded-md px-3 py-1.5 pr-8 text-xs font-medium cursor-pointer border border-gray-200 dark:border-gray-600 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed",title:"切换助手",children:u.map(v=>e.jsxs("option",{value:v.id,className:"bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100",children:[v.ui.icon," ",v.name]},v.id))}),e.jsx($t,{className:"absolute right-2 top-1/2 transform -translate-y-1/2 w-3 h-3 text-gray-400 dark:text-gray-300 pointer-events-none"})]})},L=l=>e.jsxs("div",{className:"flex items-center space-x-2 text-sm text-gray-500 dark:text-gray-400",children:[e.jsx(Be,{className:"w-4 h-4"}),e.jsx("span",{className:"truncate",title:l.path,children:l.path})]}),q=(l,u)=>e.jsxs("div",{className:"flex items-center space-x-1 text-sm text-gray-500 dark:text-gray-400",children:[u,e.jsx("span",{children:ve(l)})]}),m=l=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx("button",{onClick:()=>s(l),className:"p-1.5 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectMemory.title"),children:e.jsx(We,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>c(l),className:"p-1.5 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectCommands.title"),children:e.jsx(Ye,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>j(l),className:"p-1.5 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectSubAgents.title"),children:e.jsx(re,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>k(l),className:"p-1.5 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/50 rounded-md transition-colors",title:"A2A Protocol 管理",children:e.jsx(we,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>N(l),className:"p-1.5 text-purple-600 dark:text-purple-400 hover:bg-purple-50 dark:hover:bg-purple-900/50 rounded-md transition-colors",title:"版本管理",children:e.jsx(Ae,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>p(l),className:"p-1.5 text-indigo-600 dark:text-indigo-400 hover:bg-indigo-50 dark:hover:bg-indigo-900/50 rounded-md transition-colors",title:"项目设置",children:e.jsx($e,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>h(l),className:"p-1.5 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded-md transition-colors",title:d("projects.actions.delete"),children:e.jsx(Z,{className:"w-3.5 h-3.5"})})]});return e.jsxs("div",{className:`space-y-4 ${w}`,children:[e.jsx("div",{className:"md:hidden space-y-4",children:a.map(l=>e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 hover:shadow-md transition-shadow",children:[e.jsx("div",{className:"p-4 cursor-pointer",onClick:()=>t(l),children:e.jsx("div",{className:"flex items-start space-x-3",children:U(l,!0)})}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 text-sm mb-3 px-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[d("projects.table.agent"),":"]}),e.jsx("div",{children:K(l)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[d("projects.table.lastActive"),":"]}),e.jsx("div",{className:"text-right",children:q(l.lastAccessed,e.jsx(Xe,{className:"w-4 h-4"}))})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[d("common:path"),":"]}),e.jsx("div",{className:"text-right text-xs truncate ml-2 max-w-[200px]",children:l.path})]})]}),e.jsx("div",{className:"border-t border-gray-200 dark:border-gray-700 p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:d("projects.table.actions")}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("button",{onClick:()=>s(l),className:"p-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectMemory.title"),children:e.jsx(We,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>c(l),className:"p-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectCommands.title"),children:e.jsx(Ye,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>j(l),className:"p-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectSubAgents.title"),children:e.jsx(re,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>k(l),className:"p-2 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/50 rounded-md transition-colors",title:"A2A Protocol 管理",children:e.jsx(we,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>N(l),className:"p-2 text-purple-600 dark:text-purple-400 hover:bg-purple-50 dark:hover:bg-purple-900/50 rounded-md transition-colors",title:"版本管理",children:e.jsx(Ae,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>p(l),className:"p-2 text-indigo-600 dark:text-indigo-400 hover:bg-indigo-50 dark:hover:bg-indigo-900/50 rounded-md transition-colors",title:"项目设置",children:e.jsx($e,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>h(l),className:"p-2 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded-md transition-colors",title:d("projects.actions.delete"),children:e.jsx(Z,{className:"w-4 h-4"})})]})]})})]},l.id))}),e.jsx("div",{className:"hidden md:block bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-x-auto",children:e.jsxs("table",{className:"min-w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200 dark:border-gray-700",children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider sticky left-0 bg-white dark:bg-gray-800 z-10 w-64",children:d("projects.table.project")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider w-32",children:d("projects.table.agent")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:d("common:path")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider w-32",children:d("common:createdAt")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider w-32",children:d("projects.table.lastActive")}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider sticky right-0 bg-white dark:bg-gray-800 z-10 w-32",children:d("projects.table.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:a.map((l,u)=>e.jsxs("tr",{className:"group hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors",children:[e.jsx("td",{className:"px-6 py-4 sticky left-0 bg-white dark:bg-gray-800 group-hover:bg-gray-50 dark:group-hover:bg-gray-700/50 z-10 w-64 max-w-[256px]",children:e.jsx("div",{className:"truncate",children:U(l)})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap w-32",children:K(l)}),e.jsx("td",{className:"px-6 py-4 max-w-xs truncate",children:L(l)}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400 w-32",children:q(l.createdAt,e.jsx(Oe,{className:"w-4 h-4"}))}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400 w-32",children:q(l.lastAccessed,e.jsx(Xe,{className:"w-4 h-4"}))}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-right text-sm font-medium sticky right-0 bg-white dark:bg-gray-800 group-hover:bg-gray-50 dark:group-hover:bg-gray-700/50 z-10 w-32",children:m(l)})]},l.id+"-"+u))})]})})]})},Yt=({project:a,onClose:g})=>{const[t,s]=o.useState(""),[c,j]=o.useState(!0),[k,N]=o.useState(!1),[p,h]=o.useState(!1),[f,w]=o.useState(null);o.useEffect(()=>{(async()=>{try{j(!0),w(null);const S=await $(`${T}/projects/claude-md?path=${encodeURIComponent(a.path)}`);if(S.ok){const I=await S.json();s(I.content||"")}else if(S.status===404)s("");else throw new Error("加载 CLAUDE.md 文件失败")}catch(S){console.error("Failed to load CLAUDE.md:",S),w(S instanceof Error?S.message:"未知错误")}finally{j(!1)}})()},[a.id]);const d=async()=>{try{if(N(!0),w(null),h(!1),!(await $(`${T}/projects/claude-md?path=${encodeURIComponent(a.path)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})})).ok)throw new Error("保存 CLAUDE.md 文件失败");h(!0),setTimeout(()=>{h(!1)},2e3)}catch(y){console.error("Failed to save CLAUDE.md:",y),w(y instanceof Error?y.message:"保存失败")}finally{N(!1)}};return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-4xl h-[80vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(Tt,{className:"w-6 h-6 text-blue-600"}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"项目记忆管理"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:a.name})]})]}),e.jsx("button",{onClick:g,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors",children:e.jsx(J,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex-1 flex flex-col p-6 overflow-hidden",children:c?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"}),e.jsx("div",{className:"text-gray-600 dark:text-gray-400",children:"正在加载 CLAUDE.md..."})]})}):f?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Ce,{className:"h-12 w-12 text-red-500 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:"加载失败"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:f})]})}):e.jsxs("div",{className:"flex-1 flex flex-col space-y-4",children:[e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:"编辑项目的记忆文件 (CLAUDE.md),用于存储项目相关的上下文信息和指导。"}),e.jsx("div",{className:"flex-1 border border-gray-300 dark:border-gray-600 rounded-lg overflow-hidden",children:e.jsx("textarea",{value:t,onChange:y=>s(y.target.value),placeholder:`# 项目记忆
1
+ import{j as e}from"./data-structures-ChC1tqVg.js";import{r as o,W as Ge}from"./monaco-editor-BWfQfpij.js";import{a as $,A as T,b as at,u as qe,c as _e}from"./agents-DR9EZMs5.js";import{s as Q,a as E,b as rt,c as st}from"./index-BIGPvi1D.js";import{f as ve}from"./dateFormat-CXa8VnEC.js";import{u as be}from"./tools-crrPnehB.js";import{a5 as We,ak as Ye,t as re,a3 as we,aP as Ae,r as $e,y as Z,N as nt,k as $t,u as Be,aQ as Xe,a6 as Oe,d as Tt,X as J,j as Ce,a4 as lt,T as Pt,S as He,v as ue,o as Ze,D as ye,m as Te,J as Pe,a8 as ke,A as Le,R as et,I as he,aR as de,a9 as Et,E as It,aS as ze,aT as Ft,aU as Kt,V as Dt,ae as tt,z as pe,$ as Rt,aV as Ut,_ as dt,L as Ve,aq as Lt,e as zt}from"./ui-components-D1pZO0y-.js";import{u as Ot}from"./useAgents-M4lcWvy0.js";import{F as ot}from"./FileBrowser-DHyCacM6.js";import{T as it,a as ct,b as Ee,c as Y,d as xt,e as X}from"./table-BgVewkB5.js";import{f as Vt,g as qt}from"./useCommands-vaoVPEDI.js";import{C as _t}from"./CommandForm-CMfgHNm5.js";import{g as Ie}from"./UnifiedToolSelector-DJN7ASu1.js";import{b as Bt,c as Ht,S as Jt}from"./SubagentForm-BbxljQUp.js";import{u as Qt}from"./useProjects-D1ElB-WS.js";import{u as Gt}from"./useClaudeVersions-CKT_fq1t.js";import"./syntax-highlighting-DGbNjS3S.js";const Wt=({projects:a,agents:g,onOpenProject:t,onMemoryManagement:s,onCommandManagement:c,onSubAgentManagement:j,onA2AManagement:k,onVersionManagement:N,onSettings:p,onDeleteProject:h,onAgentChanged:f,className:w=""})=>{const{t:d}=be("pages"),[y,S]=o.useState(null),I=async(l,u)=>{if(u!==l.defaultAgent)try{S(l.id);const A=await $(`${T}/projects/${encodeURIComponent(l.path)}/default-agent`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentId:u})});if(A.ok){const v=g.find(oe=>oe.id===u);v&&f&&f(l.id,v),Q("助手切换成功")}else{const v=await A.json();throw new Error(v.error||"切换助手失败")}}catch(A){console.error("Failed to change agent:",A),E("切换助手失败",A instanceof Error?A.message:"未知错误")}finally{S(null)}},U=(l,u=!1)=>e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("button",{onClick:()=>t(l),className:`text-sm font-medium text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300 hover:underline cursor-pointer text-left truncate ${u?"text-base":""}`,children:l.name}),e.jsx("button",{onClick:()=>t(l),className:"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors flex-shrink-0",title:d("projects.actions.open"),children:e.jsx(nt,{className:"w-3 h-3"})})]}),l.description&&e.jsx("div",{className:`text-gray-500 dark:text-gray-400 truncate ${u?"text-sm mt-1":"text-sm max-w-xs"}`,children:l.description})]}),K=l=>{const u=g.filter(v=>v.enabled),A=y===l.id;return e.jsxs("div",{className:"relative inline-block",onClick:v=>v.stopPropagation(),children:[e.jsx("select",{value:l.defaultAgent,onChange:v=>I(l,v.target.value),disabled:A,className:"appearance-none bg-white dark:bg-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 rounded-md px-3 py-1.5 pr-8 text-xs font-medium cursor-pointer border border-gray-200 dark:border-gray-600 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed",title:"切换助手",children:u.map(v=>e.jsxs("option",{value:v.id,className:"bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100",children:[v.ui.icon," ",v.name]},v.id))}),e.jsx($t,{className:"absolute right-2 top-1/2 transform -translate-y-1/2 w-3 h-3 text-gray-400 dark:text-gray-300 pointer-events-none"})]})},L=l=>e.jsxs("div",{className:"flex items-center space-x-2 text-sm text-gray-500 dark:text-gray-400",children:[e.jsx(Be,{className:"w-4 h-4"}),e.jsx("span",{className:"truncate",title:l.path,children:l.path})]}),q=(l,u)=>e.jsxs("div",{className:"flex items-center space-x-1 text-sm text-gray-500 dark:text-gray-400",children:[u,e.jsx("span",{children:ve(l)})]}),m=l=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx("button",{onClick:()=>s(l),className:"p-1.5 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectMemory.title"),children:e.jsx(We,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>c(l),className:"p-1.5 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectCommands.title"),children:e.jsx(Ye,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>j(l),className:"p-1.5 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectSubAgents.title"),children:e.jsx(re,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>k(l),className:"p-1.5 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/50 rounded-md transition-colors",title:"A2A Protocol 管理",children:e.jsx(we,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>N(l),className:"p-1.5 text-purple-600 dark:text-purple-400 hover:bg-purple-50 dark:hover:bg-purple-900/50 rounded-md transition-colors",title:"版本管理",children:e.jsx(Ae,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>p(l),className:"p-1.5 text-indigo-600 dark:text-indigo-400 hover:bg-indigo-50 dark:hover:bg-indigo-900/50 rounded-md transition-colors",title:"项目设置",children:e.jsx($e,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>h(l),className:"p-1.5 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded-md transition-colors",title:d("projects.actions.delete"),children:e.jsx(Z,{className:"w-3.5 h-3.5"})})]});return e.jsxs("div",{className:`space-y-4 ${w}`,children:[e.jsx("div",{className:"md:hidden space-y-4",children:a.map(l=>e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 hover:shadow-md transition-shadow",children:[e.jsx("div",{className:"p-4 cursor-pointer",onClick:()=>t(l),children:e.jsx("div",{className:"flex items-start space-x-3",children:U(l,!0)})}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 text-sm mb-3 px-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[d("projects.table.agent"),":"]}),e.jsx("div",{children:K(l)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[d("projects.table.lastActive"),":"]}),e.jsx("div",{className:"text-right",children:q(l.lastAccessed,e.jsx(Xe,{className:"w-4 h-4"}))})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[d("common:path"),":"]}),e.jsx("div",{className:"text-right text-xs truncate ml-2 max-w-[200px]",children:l.path})]})]}),e.jsx("div",{className:"border-t border-gray-200 dark:border-gray-700 p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:d("projects.table.actions")}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("button",{onClick:()=>s(l),className:"p-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectMemory.title"),children:e.jsx(We,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>c(l),className:"p-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectCommands.title"),children:e.jsx(Ye,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>j(l),className:"p-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:d("components:projectSubAgents.title"),children:e.jsx(re,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>k(l),className:"p-2 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/50 rounded-md transition-colors",title:"A2A Protocol 管理",children:e.jsx(we,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>N(l),className:"p-2 text-purple-600 dark:text-purple-400 hover:bg-purple-50 dark:hover:bg-purple-900/50 rounded-md transition-colors",title:"版本管理",children:e.jsx(Ae,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>p(l),className:"p-2 text-indigo-600 dark:text-indigo-400 hover:bg-indigo-50 dark:hover:bg-indigo-900/50 rounded-md transition-colors",title:"项目设置",children:e.jsx($e,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>h(l),className:"p-2 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded-md transition-colors",title:d("projects.actions.delete"),children:e.jsx(Z,{className:"w-4 h-4"})})]})]})})]},l.id))}),e.jsx("div",{className:"hidden md:block bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-x-auto",children:e.jsxs("table",{className:"min-w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200 dark:border-gray-700",children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider sticky left-0 bg-white dark:bg-gray-800 z-10 w-64",children:d("projects.table.project")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider w-32",children:d("projects.table.agent")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:d("common:path")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider w-32",children:d("common:createdAt")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider w-32",children:d("projects.table.lastActive")}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider sticky right-0 bg-white dark:bg-gray-800 z-10 w-32",children:d("projects.table.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:a.map((l,u)=>e.jsxs("tr",{className:"group hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors",children:[e.jsx("td",{className:"px-6 py-4 sticky left-0 bg-white dark:bg-gray-800 group-hover:bg-gray-50 dark:group-hover:bg-gray-700/50 z-10 w-64 max-w-[256px]",children:e.jsx("div",{className:"truncate",children:U(l)})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap w-32",children:K(l)}),e.jsx("td",{className:"px-6 py-4 max-w-xs truncate",children:L(l)}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400 w-32",children:q(l.createdAt,e.jsx(Oe,{className:"w-4 h-4"}))}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400 w-32",children:q(l.lastAccessed,e.jsx(Xe,{className:"w-4 h-4"}))}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-right text-sm font-medium sticky right-0 bg-white dark:bg-gray-800 group-hover:bg-gray-50 dark:group-hover:bg-gray-700/50 z-10 w-32",children:m(l)})]},l.id+"-"+u))})]})})]})},Yt=({project:a,onClose:g})=>{const[t,s]=o.useState(""),[c,j]=o.useState(!0),[k,N]=o.useState(!1),[p,h]=o.useState(!1),[f,w]=o.useState(null);o.useEffect(()=>{(async()=>{try{j(!0),w(null);const S=await $(`${T}/projects/claude-md?path=${encodeURIComponent(a.path)}`);if(S.ok){const I=await S.json();s(I.content||"")}else if(S.status===404)s("");else throw new Error("加载 CLAUDE.md 文件失败")}catch(S){console.error("Failed to load CLAUDE.md:",S),w(S instanceof Error?S.message:"未知错误")}finally{j(!1)}})()},[a.id]);const d=async()=>{try{if(N(!0),w(null),h(!1),!(await $(`${T}/projects/claude-md?path=${encodeURIComponent(a.path)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})})).ok)throw new Error("保存 CLAUDE.md 文件失败");h(!0),setTimeout(()=>{h(!1)},2e3)}catch(y){console.error("Failed to save CLAUDE.md:",y),w(y instanceof Error?y.message:"保存失败")}finally{N(!1)}};return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-4xl h-[80vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(Tt,{className:"w-6 h-6 text-blue-600"}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"项目记忆管理"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:a.name})]})]}),e.jsx("button",{onClick:g,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors",children:e.jsx(J,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex-1 flex flex-col p-6 overflow-hidden",children:c?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"}),e.jsx("div",{className:"text-gray-600 dark:text-gray-400",children:"正在加载 CLAUDE.md..."})]})}):f?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Ce,{className:"h-12 w-12 text-red-500 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:"加载失败"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:f})]})}):e.jsxs("div",{className:"flex-1 flex flex-col space-y-4",children:[e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:"编辑项目的记忆文件 (CLAUDE.md),用于存储项目相关的上下文信息和指导。"}),e.jsx("div",{className:"flex-1 border border-gray-300 dark:border-gray-600 rounded-lg overflow-hidden",children:e.jsx("textarea",{value:t,onChange:y=>s(y.target.value),placeholder:`# 项目记忆
2
2
 
3
3
  此文件用于存储项目相关的上下文信息、开发指导和重要注意事项。
4
4
 
@@ -1 +1 @@
1
- import{j as e}from"./data-structures-ChC1tqVg.js";import{r as c}from"./monaco-editor-BWfQfpij.js";import{u as K,b as U,c as R,a as h,A as b}from"./agents-KlPdWQ8K.js";import{T as z,a as B,b as A,c as u,d as J,e as m}from"./table-Clz57edU.js";import{e as V}from"./index-f67nhEoX.js";import{V as G,j as H,v as _,E as T,S as W,aj as P,G as X,e as Y,C as Z,J as ee,y as re}from"./ui-components-DjgDPiqV.js";import"./syntax-highlighting-DGbNjS3S.js";import"./tools-BZTR2NP1.js";async function te(){const n=await h(`${b}/rules`);if(!n.ok)throw new Error("Failed to fetch rules");return n.json()}async function $(n){const s=await h(`${b}/rules/${encodeURIComponent(n)}`);if(!s.ok)throw new Error("Failed to fetch rule");return s.json()}async function ae(n){const s=await h(`${b}/rules`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!s.ok){const l=await s.json();throw new Error(l.error||"Failed to create rule")}return s.json()}async function se(n,s){const l=await h(`${b}/rules/${encodeURIComponent(n)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!l.ok){const p=await l.json();throw new Error(p.error||"Failed to update rule")}return l.json()}async function le(n){const s=await h(`${b}/rules/${encodeURIComponent(n)}`,{method:"DELETE"});if(!s.ok){const l=await s.json();throw new Error(l.error||"Failed to delete rule")}}const me=()=>{const{engineType:n}=V(),s=K(),[l,p]=c.useState(""),[q,i]=c.useState(!1),[y,x]=c.useState(null),[o,F]=c.useState(null),[f,j]=c.useState(null),[t,d]=c.useState({name:"",scope:"global",content:"",description:"",globs:"",alwaysApply:!1}),{data:S,isLoading:D,error:w,refetch:L}=U({queryKey:["rules"],queryFn:te}),O=S?.rules||[],k=S?.readOnly||!1,N=R({mutationFn:ae,onSuccess:()=>{s.invalidateQueries({queryKey:["rules"]}),i(!1),g()}}),v=R({mutationFn:({id:r,data:a})=>se(r,a),onSuccess:()=>{s.invalidateQueries({queryKey:["rules"]}),i(!1),x(null),g()}}),C=R({mutationFn:le,onSuccess:()=>{s.invalidateQueries({queryKey:["rules"]}),j(null)}}),g=()=>{d({name:"",scope:"global",content:"",description:"",globs:"",alwaysApply:!1})},M=async r=>{try{const{rule:a}=await $(r.id);F(a)}catch(a){console.error("Failed to fetch rule:",a)}},Q=async r=>{try{const{rule:a}=await $(r.id);x(a),d({name:a.name,scope:a.scope,content:a.content,description:a.frontmatter.description||"",globs:a.frontmatter.globs||"",alwaysApply:a.frontmatter.alwaysApply||!1}),i(!0)}catch(a){console.error("Failed to fetch rule:",a)}},I=r=>{r.preventDefault();const a={};t.description&&(a.description=t.description),t.globs&&(a.globs=t.globs),t.alwaysApply&&(a.alwaysApply=t.alwaysApply),y?v.mutate({id:y.id,data:{content:t.content,frontmatter:a}}):N.mutate({name:t.name,scope:t.scope,content:t.content,frontmatter:a})},E=O.filter(r=>r.name.toLowerCase().includes(l.toLowerCase())||r.description?.toLowerCase().includes(l.toLowerCase()));return D?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx(G,{className:"w-8 h-8 animate-spin text-blue-500"})}):w?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-red-700 dark:text-red-400",children:[e.jsx(H,{className:"w-5 h-5"}),e.jsxs("span",{children:["加载失败: ",w instanceof Error?w.message:"未知错误"]})]}),e.jsx("button",{onClick:()=>L(),className:"mt-2 text-sm text-red-600 hover:text-red-700 dark:text-red-400",children:"重试"})]})}):e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Rules"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:n==="cursor-cli"?"管理 Cursor 规则 (~/.cursor/rules/*.mdc)":"管理 Claude Code 规则 (~/.claude/rules/*.md)"})]}),e.jsx("div",{className:"flex items-center gap-3",children:k?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg text-yellow-700 dark:text-yellow-400 text-sm",children:[e.jsx(T,{className:"w-4 h-4"}),e.jsxs("span",{children:["只读模式 (",n==="cursor-cli"?"Cursor":"Claude",")"]})]}):e.jsxs("button",{onClick:()=>{x(null),g(),i(!0)},className:"flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[e.jsx(_,{className:"w-4 h-4"}),e.jsx("span",{children:"添加规则"})]})})]}),e.jsxs("div",{className:"relative",children:[e.jsx(W,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"搜索规则...",value:l,onChange:r=>p(r.target.value),className:"w-full pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white"})]})]}),E.length===0?e.jsxs("div",{className:"text-center py-12 bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700",children:[e.jsx(P,{className:"w-12 h-12 mx-auto text-gray-400 mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:l?"没有找到匹配的规则":"暂无规则"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400 mb-4",children:l?"尝试调整搜索条件":"创建第一个规则开始"}),!k&&!l&&e.jsx("button",{onClick:()=>{x(null),g(),i(!0)},className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:"添加规则"})]}):e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden",children:e.jsxs(z,{children:[e.jsx(B,{children:e.jsxs(A,{children:[e.jsx(u,{children:"名称"}),e.jsx(u,{children:"范围"}),e.jsx(u,{children:"描述"}),e.jsx(u,{children:"匹配模式"}),e.jsx(u,{className:"text-right",children:"操作"})]})}),e.jsx(J,{children:E.map(r=>e.jsxs(A,{children:[e.jsx(m,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"w-4 h-4 text-blue-500"}),r.name]})}),e.jsx(m,{children:e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs ${r.scope==="global"?"bg-purple-100 text-purple-700 dark:bg-purple-900/50 dark:text-purple-300":"bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-300"}`,children:[r.scope==="global"?e.jsx(X,{className:"w-3 h-3"}):e.jsx(Y,{className:"w-3 h-3"}),r.scope==="global"?"全局":"项目"]})}),e.jsx(m,{className:"text-gray-500 dark:text-gray-400 max-w-xs truncate",children:r.description||"-"}),e.jsxs(m,{className:"text-gray-500 dark:text-gray-400 text-sm",children:[r.globs||r.paths?.join(", ")||"-",r.alwaysApply&&e.jsxs("span",{className:"ml-2 inline-flex items-center gap-1 text-green-600",children:[e.jsx(Z,{className:"w-3 h-3"}),"始终应用"]})]}),e.jsx(m,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>M(r),className:"p-1 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded transition-colors",title:"查看",children:e.jsx(T,{className:"w-4 h-4"})}),!k&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>Q(r),className:"p-1 text-blue-600 hover:bg-blue-50 dark:hover:bg-blue-900/50 rounded transition-colors",title:"编辑",children:e.jsx(ee,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>j(r),className:"p-1 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded transition-colors",title:"删除",children:e.jsx(re,{className:"w-4 h-4"})})]})]})})]},r.id))})]})}),q&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsx("div",{className:"p-6 border-b border-gray-200 dark:border-gray-700",children:e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white",children:y?"编辑规则":"创建规则"})}),e.jsxs("form",{onSubmit:I,className:"p-6 space-y-4",children:[!y&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"规则名称"}),e.jsx("input",{type:"text",value:t.name,onChange:r=>d({...t,name:r.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white",placeholder:"my-rule",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"范围"}),e.jsxs("select",{value:t.scope,onChange:r=>d({...t,scope:r.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white",children:[e.jsx("option",{value:"global",children:"全局"}),e.jsx("option",{value:"project",children:"项目"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"描述"}),e.jsx("input",{type:"text",value:t.description,onChange:r=>d({...t,description:r.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white",placeholder:"规则描述"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"匹配模式 (globs)"}),e.jsx("input",{type:"text",value:t.globs,onChange:r=>d({...t,globs:r.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white",placeholder:"**/*.ts, src/**/*.tsx"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"alwaysApply",checked:t.alwaysApply,onChange:r=>d({...t,alwaysApply:r.target.checked}),className:"w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}),e.jsx("label",{htmlFor:"alwaysApply",className:"text-sm text-gray-700 dark:text-gray-300",children:"始终应用此规则"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"规则内容"}),e.jsx("textarea",{value:t.content,onChange:r=>d({...t,content:r.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white font-mono text-sm",rows:12,placeholder:"# 规则内容 (Markdown)",required:!0})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx("button",{type:"button",onClick:()=>{i(!1),x(null),g()},className:"px-4 py-2 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors",children:"取消"}),e.jsx("button",{type:"submit",disabled:N.isPending||v.isPending,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50",children:N.isPending||v.isPending?"保存中...":"保存"})]})]})]})}),o&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"p-6 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white",children:o.name}),e.jsx("span",{className:`px-2 py-1 rounded-full text-xs ${o.scope==="global"?"bg-purple-100 text-purple-700 dark:bg-purple-900/50 dark:text-purple-300":"bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-300"}`,children:o.scope==="global"?"全局":"项目"})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[o.frontmatter.description&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-500 dark:text-gray-400 mb-1",children:"描述"}),e.jsx("p",{className:"text-gray-900 dark:text-white",children:o.frontmatter.description})]}),o.frontmatter.globs&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-500 dark:text-gray-400 mb-1",children:"匹配模式"}),e.jsx("code",{className:"text-sm bg-gray-100 dark:bg-gray-700 px-2 py-1 rounded",children:o.frontmatter.globs})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-500 dark:text-gray-400 mb-1",children:"内容"}),e.jsx("pre",{className:"bg-gray-50 dark:bg-gray-900 p-4 rounded-lg overflow-x-auto text-sm text-gray-800 dark:text-gray-200",children:o.content})]}),e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:["路径: ",o.path]})]}),e.jsx("div",{className:"p-6 border-t border-gray-200 dark:border-gray-700 flex justify-end",children:e.jsx("button",{onClick:()=>F(null),className:"px-4 py-2 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors",children:"关闭"})})]})}),f&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md p-6",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white mb-4",children:"确认删除"}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:['确定要删除规则 "',f.name,'" 吗?此操作无法撤销。']}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>j(null),className:"px-4 py-2 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors",children:"取消"}),e.jsx("button",{onClick:()=>C.mutate(f.id),disabled:C.isPending,className:"px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors disabled:opacity-50",children:C.isPending?"删除中...":"删除"})]})]})})]})};export{me as RulesPage};
1
+ import{j as e}from"./data-structures-ChC1tqVg.js";import{r as c}from"./monaco-editor-BWfQfpij.js";import{u as K,b as U,c as R,a as h,A as b}from"./agents-DR9EZMs5.js";import{T as z,a as B,b as A,c as u,d as J,e as m}from"./table-BgVewkB5.js";import{e as V}from"./index-BIGPvi1D.js";import{V as G,j as H,v as _,E as T,S as W,aj as P,G as X,e as Y,C as Z,J as ee,y as re}from"./ui-components-D1pZO0y-.js";import"./syntax-highlighting-DGbNjS3S.js";import"./tools-crrPnehB.js";async function te(){const n=await h(`${b}/rules`);if(!n.ok)throw new Error("Failed to fetch rules");return n.json()}async function $(n){const s=await h(`${b}/rules/${encodeURIComponent(n)}`);if(!s.ok)throw new Error("Failed to fetch rule");return s.json()}async function ae(n){const s=await h(`${b}/rules`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!s.ok){const l=await s.json();throw new Error(l.error||"Failed to create rule")}return s.json()}async function se(n,s){const l=await h(`${b}/rules/${encodeURIComponent(n)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!l.ok){const p=await l.json();throw new Error(p.error||"Failed to update rule")}return l.json()}async function le(n){const s=await h(`${b}/rules/${encodeURIComponent(n)}`,{method:"DELETE"});if(!s.ok){const l=await s.json();throw new Error(l.error||"Failed to delete rule")}}const me=()=>{const{engineType:n}=V(),s=K(),[l,p]=c.useState(""),[q,i]=c.useState(!1),[y,x]=c.useState(null),[o,F]=c.useState(null),[f,j]=c.useState(null),[t,d]=c.useState({name:"",scope:"global",content:"",description:"",globs:"",alwaysApply:!1}),{data:S,isLoading:D,error:w,refetch:L}=U({queryKey:["rules"],queryFn:te}),O=S?.rules||[],k=S?.readOnly||!1,N=R({mutationFn:ae,onSuccess:()=>{s.invalidateQueries({queryKey:["rules"]}),i(!1),g()}}),v=R({mutationFn:({id:r,data:a})=>se(r,a),onSuccess:()=>{s.invalidateQueries({queryKey:["rules"]}),i(!1),x(null),g()}}),C=R({mutationFn:le,onSuccess:()=>{s.invalidateQueries({queryKey:["rules"]}),j(null)}}),g=()=>{d({name:"",scope:"global",content:"",description:"",globs:"",alwaysApply:!1})},M=async r=>{try{const{rule:a}=await $(r.id);F(a)}catch(a){console.error("Failed to fetch rule:",a)}},Q=async r=>{try{const{rule:a}=await $(r.id);x(a),d({name:a.name,scope:a.scope,content:a.content,description:a.frontmatter.description||"",globs:a.frontmatter.globs||"",alwaysApply:a.frontmatter.alwaysApply||!1}),i(!0)}catch(a){console.error("Failed to fetch rule:",a)}},I=r=>{r.preventDefault();const a={};t.description&&(a.description=t.description),t.globs&&(a.globs=t.globs),t.alwaysApply&&(a.alwaysApply=t.alwaysApply),y?v.mutate({id:y.id,data:{content:t.content,frontmatter:a}}):N.mutate({name:t.name,scope:t.scope,content:t.content,frontmatter:a})},E=O.filter(r=>r.name.toLowerCase().includes(l.toLowerCase())||r.description?.toLowerCase().includes(l.toLowerCase()));return D?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx(G,{className:"w-8 h-8 animate-spin text-blue-500"})}):w?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-red-700 dark:text-red-400",children:[e.jsx(H,{className:"w-5 h-5"}),e.jsxs("span",{children:["加载失败: ",w instanceof Error?w.message:"未知错误"]})]}),e.jsx("button",{onClick:()=>L(),className:"mt-2 text-sm text-red-600 hover:text-red-700 dark:text-red-400",children:"重试"})]})}):e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Rules"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:n==="cursor-cli"?"管理 Cursor 规则 (~/.cursor/rules/*.mdc)":"管理 Claude Code 规则 (~/.claude/rules/*.md)"})]}),e.jsx("div",{className:"flex items-center gap-3",children:k?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg text-yellow-700 dark:text-yellow-400 text-sm",children:[e.jsx(T,{className:"w-4 h-4"}),e.jsxs("span",{children:["只读模式 (",n==="cursor-cli"?"Cursor":"Claude",")"]})]}):e.jsxs("button",{onClick:()=>{x(null),g(),i(!0)},className:"flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[e.jsx(_,{className:"w-4 h-4"}),e.jsx("span",{children:"添加规则"})]})})]}),e.jsxs("div",{className:"relative",children:[e.jsx(W,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"搜索规则...",value:l,onChange:r=>p(r.target.value),className:"w-full pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white"})]})]}),E.length===0?e.jsxs("div",{className:"text-center py-12 bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700",children:[e.jsx(P,{className:"w-12 h-12 mx-auto text-gray-400 mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:l?"没有找到匹配的规则":"暂无规则"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400 mb-4",children:l?"尝试调整搜索条件":"创建第一个规则开始"}),!k&&!l&&e.jsx("button",{onClick:()=>{x(null),g(),i(!0)},className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:"添加规则"})]}):e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden",children:e.jsxs(z,{children:[e.jsx(B,{children:e.jsxs(A,{children:[e.jsx(u,{children:"名称"}),e.jsx(u,{children:"范围"}),e.jsx(u,{children:"描述"}),e.jsx(u,{children:"匹配模式"}),e.jsx(u,{className:"text-right",children:"操作"})]})}),e.jsx(J,{children:E.map(r=>e.jsxs(A,{children:[e.jsx(m,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"w-4 h-4 text-blue-500"}),r.name]})}),e.jsx(m,{children:e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs ${r.scope==="global"?"bg-purple-100 text-purple-700 dark:bg-purple-900/50 dark:text-purple-300":"bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-300"}`,children:[r.scope==="global"?e.jsx(X,{className:"w-3 h-3"}):e.jsx(Y,{className:"w-3 h-3"}),r.scope==="global"?"全局":"项目"]})}),e.jsx(m,{className:"text-gray-500 dark:text-gray-400 max-w-xs truncate",children:r.description||"-"}),e.jsxs(m,{className:"text-gray-500 dark:text-gray-400 text-sm",children:[r.globs||r.paths?.join(", ")||"-",r.alwaysApply&&e.jsxs("span",{className:"ml-2 inline-flex items-center gap-1 text-green-600",children:[e.jsx(Z,{className:"w-3 h-3"}),"始终应用"]})]}),e.jsx(m,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>M(r),className:"p-1 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded transition-colors",title:"查看",children:e.jsx(T,{className:"w-4 h-4"})}),!k&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>Q(r),className:"p-1 text-blue-600 hover:bg-blue-50 dark:hover:bg-blue-900/50 rounded transition-colors",title:"编辑",children:e.jsx(ee,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>j(r),className:"p-1 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded transition-colors",title:"删除",children:e.jsx(re,{className:"w-4 h-4"})})]})]})})]},r.id))})]})}),q&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsx("div",{className:"p-6 border-b border-gray-200 dark:border-gray-700",children:e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white",children:y?"编辑规则":"创建规则"})}),e.jsxs("form",{onSubmit:I,className:"p-6 space-y-4",children:[!y&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"规则名称"}),e.jsx("input",{type:"text",value:t.name,onChange:r=>d({...t,name:r.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white",placeholder:"my-rule",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"范围"}),e.jsxs("select",{value:t.scope,onChange:r=>d({...t,scope:r.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white",children:[e.jsx("option",{value:"global",children:"全局"}),e.jsx("option",{value:"project",children:"项目"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"描述"}),e.jsx("input",{type:"text",value:t.description,onChange:r=>d({...t,description:r.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white",placeholder:"规则描述"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"匹配模式 (globs)"}),e.jsx("input",{type:"text",value:t.globs,onChange:r=>d({...t,globs:r.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white",placeholder:"**/*.ts, src/**/*.tsx"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"alwaysApply",checked:t.alwaysApply,onChange:r=>d({...t,alwaysApply:r.target.checked}),className:"w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}),e.jsx("label",{htmlFor:"alwaysApply",className:"text-sm text-gray-700 dark:text-gray-300",children:"始终应用此规则"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"规则内容"}),e.jsx("textarea",{value:t.content,onChange:r=>d({...t,content:r.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white font-mono text-sm",rows:12,placeholder:"# 规则内容 (Markdown)",required:!0})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx("button",{type:"button",onClick:()=>{i(!1),x(null),g()},className:"px-4 py-2 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors",children:"取消"}),e.jsx("button",{type:"submit",disabled:N.isPending||v.isPending,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50",children:N.isPending||v.isPending?"保存中...":"保存"})]})]})]})}),o&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"p-6 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white",children:o.name}),e.jsx("span",{className:`px-2 py-1 rounded-full text-xs ${o.scope==="global"?"bg-purple-100 text-purple-700 dark:bg-purple-900/50 dark:text-purple-300":"bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-300"}`,children:o.scope==="global"?"全局":"项目"})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[o.frontmatter.description&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-500 dark:text-gray-400 mb-1",children:"描述"}),e.jsx("p",{className:"text-gray-900 dark:text-white",children:o.frontmatter.description})]}),o.frontmatter.globs&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-500 dark:text-gray-400 mb-1",children:"匹配模式"}),e.jsx("code",{className:"text-sm bg-gray-100 dark:bg-gray-700 px-2 py-1 rounded",children:o.frontmatter.globs})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-500 dark:text-gray-400 mb-1",children:"内容"}),e.jsx("pre",{className:"bg-gray-50 dark:bg-gray-900 p-4 rounded-lg overflow-x-auto text-sm text-gray-800 dark:text-gray-200",children:o.content})]}),e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:["路径: ",o.path]})]}),e.jsx("div",{className:"p-6 border-t border-gray-200 dark:border-gray-700 flex justify-end",children:e.jsx("button",{onClick:()=>F(null),className:"px-4 py-2 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors",children:"关闭"})})]})}),f&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md p-6",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white mb-4",children:"确认删除"}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:['确定要删除规则 "',f.name,'" 吗?此操作无法撤销。']}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>j(null),className:"px-4 py-2 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors",children:"取消"}),e.jsx("button",{onClick:()=>C.mutate(f.id),disabled:C.isPending,className:"px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors disabled:opacity-50",children:C.isPending?"删除中...":"删除"})]})]})})]})};export{me as RulesPage};
@@ -1 +1 @@
1
- import{j as e}from"./data-structures-ChC1tqVg.js";import{r as c,W as ve}from"./monaco-editor-BWfQfpij.js";import{T as ue,a as ge,b as Y,c as v,d as he,e as b}from"./table-Clz57edU.js";import{b as J,u as $,c as P,a as f,A as j}from"./agents-KlPdWQ8K.js";import{u as Ne}from"./useAgents-8KXN6U61.js";import{u as Se}from"./useProjects-Bbh6hJMM.js";import{u as Ce}from"./useClaudeVersions-DicHLV6A.js";import{a as g,s as S,c as Te}from"./index-f67nhEoX.js";import{m as B,t as Ee,e as Ie,an as ce,k as me,a6 as $e,R as ye,ag as pe,a4 as Ae,aF as qe,L as ae,l as Me,d as oe,n as be,C as fe,A as Fe,r as Pe,v as xe,aG as Re,aH as De,V as Ke,aI as Oe,J as Qe,y as Le,X as Ve}from"./ui-components-DjgDPiqV.js";import"./syntax-highlighting-DGbNjS3S.js";import"./tools-BZTR2NP1.js";const i={all:["scheduled-tasks"],lists:()=>[...i.all,"list"],list:()=>[...i.lists()],details:()=>[...i.all,"detail"],detail:t=>[...i.details(),t],history:t=>[...i.all,"history",t],status:()=>[...i.all,"status"]},He=()=>J({queryKey:i.list(),queryFn:async()=>{const t=await f(`${j}/scheduled-tasks`);if(!t.ok)throw new Error("Failed to fetch scheduled tasks");return t.json()},refetchInterval:t=>t.state.data?.some(o=>o.lastRunStatus==="running")?3e3:!1}),Be=(t,l=50)=>J({queryKey:i.history(t),queryFn:async()=>{const n=await f(`${j}/scheduled-tasks/${t}/history?limit=${l}`);if(!n.ok)throw new Error("Failed to fetch task execution history");return n.json()},enabled:!!t,refetchInterval:n=>n.state.data?.some(k=>k.status==="running")?3e3:!1}),ze=()=>J({queryKey:i.status(),queryFn:async()=>{const t=await f(`${j}/scheduled-tasks/status`);if(!t.ok)throw new Error("Failed to fetch scheduler status");return t.json()},refetchInterval:3e4}),Ue=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/scheduled-tasks`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to create scheduled task")}return n.json()},onSuccess:()=>{t.invalidateQueries({queryKey:i.lists()}),t.invalidateQueries({queryKey:i.status()})}})},_e=()=>{const t=$();return P({mutationFn:async({taskId:l,data:n})=>{const o=await f(`${j}/scheduled-tasks/${l}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!o.ok){const C=await o.json().catch(()=>({}));throw new Error(C.error||"Failed to update scheduled task")}return o.json()},onSuccess:l=>{t.invalidateQueries({queryKey:i.lists()}),t.invalidateQueries({queryKey:i.detail(l.id)}),t.invalidateQueries({queryKey:i.status()})}})},Je=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/scheduled-tasks/${l}`,{method:"DELETE"});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to delete scheduled task")}},onSuccess:()=>{t.invalidateQueries({queryKey:i.lists()}),t.invalidateQueries({queryKey:i.status()})}})},We=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/scheduled-tasks/${l}/toggle`,{method:"POST"});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to toggle scheduled task")}return n.json()},onSuccess:l=>{t.invalidateQueries({queryKey:i.lists()}),t.invalidateQueries({queryKey:i.detail(l.id)}),t.invalidateQueries({queryKey:i.status()})}})},je=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/scheduled-tasks/${l}/run`,{method:"POST"});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to run scheduled task")}return n.json()},onSuccess:(l,n)=>{t.invalidateQueries({queryKey:i.detail(n)}),t.invalidateQueries({queryKey:i.lists()}),t.invalidateQueries({queryKey:i.history(n)})}})},Xe=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/scheduled-tasks/executions/${l}/stop`,{method:"POST"});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to stop execution")}return n.json()},onSuccess:()=>{t.invalidateQueries({queryKey:i.all})}})},Ge=()=>J({queryKey:[...i.all,"running"],queryFn:async()=>{const t=await f(`${j}/scheduled-tasks/running`);if(!t.ok)throw new Error("Failed to fetch running executions");return t.json()},refetchInterval:3e3}),Ye=()=>{const t=$();return P({mutationFn:async()=>{const l=await f(`${j}/scheduled-tasks/scheduler/enable`,{method:"POST"});if(!l.ok){const n=await l.json().catch(()=>({}));throw new Error(n.error||"Failed to enable scheduler")}return l.json()},onSuccess:()=>{t.invalidateQueries({queryKey:i.status()})}})},Ze=()=>{const t=$();return P({mutationFn:async()=>{const l=await f(`${j}/scheduled-tasks/scheduler/disable`,{method:"POST"});if(!l.ok){const n=await l.json().catch(()=>({}));throw new Error(n.error||"Failed to disable scheduler")}return l.json()},onSuccess:()=>{t.invalidateQueries({queryKey:i.status()})}})},Z={all:["task-executor"],stats:()=>[...Z.all,"stats"],health:()=>[...Z.all,"health"]},et=()=>J({queryKey:Z.stats(),queryFn:async()=>{const t=await f(`${j}/task-executor/stats`);if(!t.ok)throw new Error("Failed to fetch task executor stats");return t.json()},refetchInterval:5e3}),tt=()=>J({queryKey:[...Z.all,"config"],queryFn:async()=>{const t=await f(`${j}/task-executor/config`);if(!t.ok)throw new Error("Failed to fetch task executor config");return t.json()}}),rt=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/task-executor/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to update executor config")}return n.json()},onSuccess:()=>{t.invalidateQueries({queryKey:Z.all})}})},st=[{label:"每 5 分钟",value:"*/5 * * * *"},{label:"每 15 分钟",value:"*/15 * * * *"},{label:"每 30 分钟",value:"*/30 * * * *"},{label:"每小时",value:"0 * * * *"},{label:"每天 9:00",value:"0 9 * * *"},{label:"每天 18:00",value:"0 18 * * *"},{label:"每周一 9:00",value:"0 9 * * 1"},{label:"每月 1 日 9:00",value:"0 9 1 * *"}],at=t=>{if(!t){const l=new Date;return l.setHours(l.getHours()+1),l.setMinutes(0),l.setSeconds(0),l.toISOString().slice(0,16)}return new Date(t).toISOString().slice(0,16)},nt=t=>new Date(t).toISOString(),lt=({task:t,agents:l,onSave:n,onCancel:o})=>{const C=!!t,k=Ue(),z=_e(),U=je(),{data:W}=Se(),R=W?.projects||[],{data:x}=Ce(),[w,D]=c.useState(t?.name||""),[A,K]=c.useState(t?.description||""),[N,q]=c.useState(t?.agentId||""),[m,Q]=c.useState(t?.projectPath||""),[p,s]=c.useState(t?.schedule.type||"interval"),[d,h]=c.useState(t?.schedule.intervalMinutes||30),[u,L]=c.useState(t?.schedule.cronExpression||"*/30 * * * *"),[V,ne]=c.useState(at(t?.schedule.executeAt)),[E,le]=c.useState(t?.triggerMessage||""),[M,ee]=c.useState(t?.enabled??!0),[T,ie]=c.useState(!!t?.modelOverride?.modelId),[I,te]=c.useState(t?.modelOverride?.versionId||""),[H,X]=c.useState(t?.modelOverride?.modelId||""),[_,re]=c.useState(!1),[G,se]=c.useState(!1),r=c.useMemo(()=>x?.versions?I?x.versions.find(de=>de.id===I)?.models||[]:(x.versions.find(O=>O.id===x.defaultVersionId)||x.versions[0])?.models||[]:[],[x,I]);c.useEffect(()=>{T&&x?.versions&&I&&(x.versions.some(O=>O.id===I)||(te(x.defaultVersionId||""),X("")))},[x,I,T]),c.useEffect(()=>{T&&r.length>0&&(r.some(O=>O.id===H)||X(r[0].id))},[r,H,T]),c.useEffect(()=>{!N&&l.length>0&&q(l[0].id)},[N,l]),c.useEffect(()=>{!m&&R.length>0&&Q(R[0].path)},[m,R]);const y=()=>p==="interval"?{type:"interval",intervalMinutes:d}:p==="once"?{type:"once",executeAt:nt(V)}:{type:"cron",cronExpression:u},F=()=>{if(!(!T||!H))return{versionId:I||void 0,modelId:H}},ke=async()=>{if(!w.trim()){g("请输入任务名称");return}if(!N){g("请选择 Agent");return}if(!m){g("请选择项目路径");return}if(!E.trim()){g("请输入触发消息");return}if(p==="interval"&&(!d||d<1)){g("间隔时间必须大于 0");return}if(p==="cron"&&!u.trim()){g("请输入 Cron 表达式");return}if(p==="once"){const a=new Date(V).getTime();if(isNaN(a)){g("请选择有效的执行时间");return}if(a<=Date.now()){g("执行时间必须在未来");return}}re(!0);try{if(C)await z.mutateAsync({taskId:t.id,data:{name:w.trim(),description:A.trim()||void 0,agentId:N,projectPath:m,schedule:y(),triggerMessage:E.trim(),enabled:M,modelOverride:F()}}),S("任务已更新");else{const a={name:w.trim(),description:A.trim()||void 0,agentId:N,projectPath:m,schedule:y(),triggerMessage:E.trim(),enabled:M,modelOverride:F()};await k.mutateAsync(a),S("任务已创建")}n()}catch{g(C?"更新失败":"创建失败")}finally{re(!1)}},we=async()=>{if(!w.trim()){g("请输入任务名称");return}if(!N){g("请选择 Agent");return}if(!m){g("请选择项目路径");return}if(!E.trim()){g("请输入触发消息");return}se(!0);try{let a;if(C)await z.mutateAsync({taskId:t.id,data:{name:w.trim(),description:A.trim()||void 0,agentId:N,projectPath:m,schedule:y(),triggerMessage:E.trim(),enabled:M,modelOverride:F()}}),a=t.id,S("任务已更新");else{const O={name:w.trim(),description:A.trim()||void 0,agentId:N,projectPath:m,schedule:y(),triggerMessage:E.trim(),enabled:M,modelOverride:F()};a=(await k.mutateAsync(O)).id,S("任务已创建")}await U.mutateAsync(a),S("任务已开始执行,请在执行历史中查看结果"),n()}catch{g("操作失败")}finally{se(!1)}};return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-5xl max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:C?"编辑定时任务":"创建定时任务"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"配置 Agent 的自动执行计划"})]}),e.jsx("button",{onClick:o,className:"p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(B,{className:"w-5 h-5"}),"基本信息"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"任务名称 *"}),e.jsx("input",{type:"text",value:w,onChange:a=>D(a.target.value),placeholder:"例如:每日代码检查",className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"描述"}),e.jsx("input",{type:"text",value:A,onChange:a=>K(a.target.value),placeholder:"可选的任务描述",className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(Ee,{className:"w-5 h-5"}),"执行配置"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"执行 Agent *"}),e.jsx("select",{value:N,onChange:a=>q(a.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:l.map(a=>e.jsxs("option",{value:a.id,children:[a.ui?.icon||"🤖"," ",a.name]},a.id))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1 flex items-center gap-2",children:[e.jsx(Ie,{className:"w-4 h-4"}),"项目路径 *"]}),e.jsx("select",{value:m,onChange:a=>Q(a.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:R.map(a=>e.jsx("option",{value:a.path,children:a.name||a.path},a.path))}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"Agent 将在此项目目录下执行"})]}),e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"覆盖模型配置"})]}),e.jsx("button",{type:"button",onClick:()=>ie(!T),className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${T?"bg-blue-600":"bg-gray-300 dark:bg-gray-600"}`,children:e.jsx("span",{className:`inline-block h-3 w-3 transform rounded-full bg-white transition-transform ${T?"translate-x-5":"translate-x-1"}`})})]}),T&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-2",children:"可以为定时任务指定不同于 Agent 默认的模型"}),x?.versions&&x.versions.length>1&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-gray-500 dark:text-gray-400 mb-1",children:"供应商"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:I,onChange:a=>te(a.target.value),className:"w-full appearance-none px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:[e.jsx("option",{value:"",children:x.defaultVersionId?`默认 (${x.versions.find(a=>a.id===x.defaultVersionId)?.name})`:"默认"}),x.versions.filter(a=>a.id!==x.defaultVersionId).map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]}),e.jsx("div",{className:"absolute inset-y-0 right-0 flex items-center px-2 pointer-events-none text-gray-500",children:e.jsx(me,{className:"w-4 h-4"})})]})]}),r.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-gray-500 dark:text-gray-400 mb-1",children:"模型"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:r.map(a=>e.jsxs("button",{type:"button",onClick:()=>X(a.id),className:`flex items-center justify-between px-3 py-2 text-sm rounded-lg border transition-all ${H===a.id?"border-purple-500 bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300 shadow-sm":"border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600 text-gray-700 dark:text-gray-300"}`,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ce,{className:"w-4 h-4 opacity-70"}),e.jsx("span",{className:"font-medium",children:a.name})]}),a.isVision&&e.jsx("span",{className:"text-xs bg-gray-100 dark:bg-gray-700 px-1.5 py-0.5 rounded text-gray-500",children:"Vision"})]},a.id))})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(B,{className:"w-5 h-5"}),"调度规则"]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsxs("label",{className:"flex items-center",children:[e.jsx("input",{type:"radio",name:"scheduleType",value:"interval",checked:p==="interval",onChange:()=>s("interval"),className:"mr-2"}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300",children:"间隔执行"})]}),e.jsxs("label",{className:"flex items-center",children:[e.jsx("input",{type:"radio",name:"scheduleType",value:"cron",checked:p==="cron",onChange:()=>s("cron"),className:"mr-2"}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300",children:"Cron 表达式"})]}),e.jsxs("label",{className:"flex items-center",children:[e.jsx("input",{type:"radio",name:"scheduleType",value:"once",checked:p==="once",onChange:()=>s("once"),className:"mr-2"}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300",children:"仅执行一次"})]})]}),p==="interval"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"间隔时间(分钟)"}),e.jsx("input",{type:"number",min:1,max:10080,value:d,onChange:a=>h(parseInt(a.target.value)||30),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),e.jsxs("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:["每隔 ",d," 分钟执行一次"]})]}),p==="cron"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Cron 表达式"}),e.jsx("input",{type:"text",value:u,onChange:a=>L(a.target.value),placeholder:"*/30 * * * *",className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white font-mono focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:st.map(a=>e.jsx("button",{type:"button",onClick:()=>L(a.value),className:`px-2 py-1 text-xs rounded-full border transition-colors ${u===a.value?"bg-blue-100 border-blue-300 text-blue-700 dark:bg-blue-900 dark:border-blue-700 dark:text-blue-300":"bg-gray-50 border-gray-200 text-gray-600 hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700"}`,children:a.label},a.value))})]}),p==="once"&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1 flex items-center gap-2",children:[e.jsx($e,{className:"w-4 h-4"}),"执行时间"]}),e.jsx("input",{type:"datetime-local",value:V,onChange:a=>ne(a.target.value),min:new Date().toISOString().slice(0,16),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"任务将在指定时间执行一次后自动禁用"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(ye,{className:"w-5 h-5"}),"触发消息"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"发送给 Agent 的消息 *"}),e.jsx("textarea",{value:E,onChange:a=>le(a.target.value),placeholder:"请检查代码质量并生成报告...",rows:5,className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-y"}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"定时触发时,这条消息会发送给选定的 Agent"})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-4 border-t border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"启用任务"}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"创建后立即开始调度"})]}),e.jsx("button",{type:"button",onClick:()=>ee(!M),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${M?"bg-blue-600":"bg-gray-300 dark:bg-gray-600"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${M?"translate-x-6":"translate-x-1"}`})})]}),e.jsxs("div",{className:"flex justify-between pt-4 border-t border-gray-200 dark:border-gray-700",children:[e.jsx("button",{onClick:o,className:"px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg transition-colors",children:"取消"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("button",{onClick:we,disabled:_||G,className:"inline-flex items-center px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors disabled:opacity-50",title:"保存任务并立即执行一次",children:[e.jsx(pe,{className:"w-4 h-4 mr-2"}),G?"执行中...":"保存并执行"]}),e.jsxs("button",{onClick:ke,disabled:_||G,className:"inline-flex items-center px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50",children:[e.jsx(Ae,{className:"w-4 h-4 mr-2"}),_?"保存中...":"保存"]})]})]})]})})]})})},it=({taskId:t,taskName:l,agentId:n,projectPath:o,onBack:C})=>{const{data:k=[],isLoading:z}=Be(t),[U,W]=c.useState(new Set),R=s=>{W(d=>{const h=new Set(d);return h.has(s)?h.delete(s):h.add(s),h})},x=s=>s?new Date(s).toLocaleString("zh-CN"):"-",w=s=>new Date(s).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3}),D=s=>{if(!s.completedAt)return"-";const d=new Date(s.startedAt).getTime(),u=new Date(s.completedAt).getTime()-d;return u<1e3?`${u}ms`:u<6e4?`${(u/1e3).toFixed(1)}s`:`${Math.floor(u/6e4)}m ${Math.floor(u%6e4/1e3)}s`},A=s=>{switch(s){case"running":return e.jsx(ae,{className:"w-5 h-5 text-blue-500 animate-spin"});case"success":return e.jsx(fe,{className:"w-5 h-5 text-green-500"});case"error":return e.jsx(be,{className:"w-5 h-5 text-red-500"});default:return e.jsx(B,{className:"w-5 h-5 text-gray-400"})}},K=s=>{switch(s){case"running":return e.jsx("span",{className:"text-blue-600 dark:text-blue-400",children:"运行中"});case"success":return e.jsx("span",{className:"text-green-600 dark:text-green-400",children:"成功"});case"error":return e.jsx("span",{className:"text-red-600 dark:text-red-400",children:"失败"});default:return e.jsx("span",{className:"text-gray-500",children:"未知"})}},N=s=>{switch(s){case"error":return"text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-900/20";case"warn":return"text-yellow-600 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-900/20";case"info":return"text-blue-600 dark:text-blue-400";case"debug":return"text-gray-500 dark:text-gray-400";default:return"text-gray-600 dark:text-gray-400"}},q=s=>{switch(s){case"system":return"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400";case"assistant":return"bg-blue-100 text-blue-600 dark:bg-blue-900 dark:text-blue-400";case"tool_use":return"bg-purple-100 text-purple-600 dark:bg-purple-900 dark:text-purple-400";case"result":return"bg-green-100 text-green-600 dark:bg-green-900 dark:text-green-400";case"error":return"bg-red-100 text-red-600 dark:bg-red-900 dark:text-red-400";default:return"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400"}},m=s=>{const d=s.agentId||n,h=s.projectPath||o;if(!d||!s.sessionId)return null;let u=`/chat/${encodeURIComponent(d)}?session=${encodeURIComponent(s.sessionId)}`;return h&&(u+=`&project=${encodeURIComponent(h)}`),u},Q=(s,d)=>{d.stopPropagation();const h=m(s);h&&window.open(h,"_blank")},p=s=>!s||s.length===0?e.jsx("div",{className:"text-center py-4 text-gray-500 dark:text-gray-400",children:"暂无执行日志"}):e.jsx("div",{className:"space-y-1 max-h-96 overflow-y-auto",children:s.map((d,h)=>e.jsxs("div",{className:`flex items-start gap-2 px-3 py-1.5 rounded text-sm font-mono ${N(d.level)}`,children:[e.jsx("span",{className:"text-gray-400 dark:text-gray-500 shrink-0 w-24",children:w(d.timestamp)}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs shrink-0 ${q(d.type)}`,children:d.type}),e.jsx("span",{className:"flex-1 break-all whitespace-pre-wrap",children:d.message})]},h))});return e.jsxs("div",{className:"p-8",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("button",{onClick:C,className:"p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg transition-colors",children:e.jsx(qe,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"执行历史"}),e.jsxs("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:["任务:",l]})]})]}),z?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ae,{className:"w-8 h-8 animate-spin text-gray-400"})}):k.length===0?e.jsxs("div",{className:"text-center py-12 bg-gray-50 dark:bg-gray-800 rounded-lg",children:[e.jsx(B,{className:"w-12 h-12 mx-auto text-gray-400 mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:"暂无执行记录"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:"任务尚未执行过"})]}):e.jsx("div",{className:"bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden",children:e.jsxs(ue,{children:[e.jsx(ge,{children:e.jsxs(Y,{children:[e.jsx(v,{className:"w-[40px]"}),e.jsx(v,{className:"w-[80px]",children:"状态"}),e.jsx(v,{children:"开始时间"}),e.jsx(v,{children:"完成时间"}),e.jsx(v,{children:"耗时"}),e.jsx(v,{children:"结果摘要"}),e.jsx(v,{className:"w-[100px]",children:"操作"})]})}),e.jsx(he,{children:k.map(s=>e.jsxs(ve.Fragment,{children:[e.jsxs(Y,{className:"cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800",onClick:()=>R(s.id),children:[e.jsx(b,{className:"p-2",children:e.jsx("button",{className:"p-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded",children:U.has(s.id)?e.jsx(me,{className:"w-4 h-4 text-gray-500"}):e.jsx(Me,{className:"w-4 h-4 text-gray-500"})})}),e.jsx(b,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[A(s.status),K(s.status)]})}),e.jsx(b,{children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:x(s.startedAt)})}),e.jsx(b,{children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:x(s.completedAt)})}),e.jsx(b,{children:e.jsx("span",{className:"text-sm font-mono text-gray-600 dark:text-gray-400",children:D(s)})}),e.jsx(b,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[s.logs&&s.logs.length>0&&e.jsx("span",{title:"有详细日志",children:e.jsx(oe,{className:"w-4 h-4 text-gray-400 shrink-0"})}),s.error?e.jsx("div",{className:"text-sm text-red-600 dark:text-red-400 max-w-md truncate",children:s.error}):s.responseSummary?e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400 max-w-md truncate",children:s.responseSummary}):e.jsx("span",{className:"text-sm text-gray-400",children:"-"})]})}),e.jsx(b,{children:s.sessionId&&m(s)&&e.jsx("button",{onClick:d=>Q(s,d),className:"inline-flex items-center justify-center p-2 text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 hover:bg-blue-50 dark:hover:bg-blue-900/20 rounded transition-colors",title:"在新窗口继续会话",children:e.jsx(ye,{className:"w-4 h-4"})})})]}),U.has(s.id)&&e.jsx(Y,{children:e.jsx(b,{colSpan:7,className:"bg-gray-50 dark:bg-gray-800/50 p-4",children:e.jsxs("div",{className:"space-y-3",children:[s.errorStack&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3",children:[e.jsx("h4",{className:"text-sm font-medium text-red-700 dark:text-red-400 mb-2",children:"错误堆栈"}),e.jsx("pre",{className:"text-xs text-red-600 dark:text-red-400 whitespace-pre-wrap overflow-x-auto",children:s.errorStack})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg p-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-2 flex items-center gap-2",children:[e.jsx(oe,{className:"w-4 h-4"}),"执行日志",s.logs&&e.jsxs("span",{className:"text-xs text-gray-400",children:["(",s.logs.length," 条)"]})]}),p(s.logs)]}),s.sessionId&&e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Session ID: ",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded",children:s.sessionId})]})]})})})]},s.id))})]})})]})},ft=()=>{const t=$(),l=Te(),{data:n=[],isLoading:o}=He(),{data:C}=Ne(!0),{data:k}=ze(),z=Je(),U=We(),W=je(),R=Xe(),{data:x}=Ge(),w=Ye(),D=Ze(),[A,K]=c.useState(null),[N,q]=c.useState(!1),[m,Q]=c.useState(null),[p,s]=c.useState(!1),[d,h]=c.useState(2),{data:u}=et(),{data:L}=tt(),V=rt(),ne=r=>x?.executions?.find(F=>F.taskId===r)?.executionId||null,E=C?.agents||[],le=r=>E.find(F=>F.id===r)?.name||r,M=r=>{if(r.schedule.type==="interval"&&r.schedule.intervalMinutes){const y=r.schedule.intervalMinutes;return y<60?`每 ${y} 分钟`:`每 ${Math.floor(y/60)} 小时`}return r.schedule.type==="cron"&&r.schedule.cronExpression?r.schedule.cronExpression:r.schedule.type==="once"&&r.schedule.executeAt?`一次性 @ ${new Date(r.schedule.executeAt).toLocaleString("zh-CN")}`:"-"},ee=r=>r?new Date(r).toLocaleString("zh-CN"):"-",T=async r=>{try{await U.mutateAsync(r.id),S(r.enabled?"任务已暂停":"任务已启用")}catch{g("操作失败")}},ie=async r=>{if(await l({title:"删除确认",message:`确定要删除任务 "${r.name}" 吗?`,confirmText:"删除",cancelText:"取消",variant:"danger"}))try{await z.mutateAsync(r.id),S("任务已删除")}catch{g("删除失败")}},I=async r=>{try{await W.mutateAsync(r.id),S("任务已开始执行"),t.invalidateQueries({queryKey:i.lists()})}catch{g("执行失败")}},te=async r=>{const y=ne(r.id);if(!y){g("找不到正在运行的执行");return}try{await R.mutateAsync(y),S("任务已停止"),t.invalidateQueries({queryKey:i.lists()})}catch{g("停止失败")}},H=async()=>{if(k)try{k.enabled?(await D.mutateAsync(),S("调度器已禁用")):(await w.mutateAsync(),S("调度器已启用"))}catch{g("操作失败")}},X=r=>{K(r),q(!0)},_=()=>{K(null),q(!0)},re=()=>{K(null),q(!1),t.invalidateQueries({queryKey:i.lists()})},G=()=>{K(null),q(!1)},se=r=>r.lastRunStatus==="running"?e.jsxs("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",children:[e.jsx(ae,{className:"w-3 h-3 mr-1 animate-spin"}),"运行中"]}):r.lastRunStatus==="success"?e.jsxs("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200",children:[e.jsx(fe,{className:"w-3 h-3 mr-1"}),"成功"]}):r.lastRunStatus==="error"?e.jsxs("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200",children:[e.jsx(be,{className:"w-3 h-3 mr-1"}),"失败"]}):e.jsx("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",children:"未执行"});if(m){const r=n.find(y=>y.id===m);return e.jsx(it,{taskId:m,taskName:r?.name||m,agentId:r?.agentId,projectPath:r?.projectPath,onBack:()=>Q(null)})}return e.jsxs("div",{className:"p-8",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(B,{className:"w-8 h-8"}),"定时任务"]}),e.jsx("p",{className:"mt-2 text-gray-600 dark:text-gray-400",children:"配置 Agent 的自动执行计划"})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[k&&e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs("button",{onClick:H,disabled:w.isPending||D.isPending,className:`flex items-center gap-2 px-3 py-1.5 rounded-lg transition-colors ${k.enabled?"bg-green-50 dark:bg-green-900/20 text-green-700 dark:text-green-300 hover:bg-green-100 dark:hover:bg-green-900/30":"bg-orange-50 dark:bg-orange-900/20 text-orange-700 dark:text-orange-300 hover:bg-orange-100 dark:hover:bg-orange-900/30"} ${w.isPending||D.isPending?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,title:k.enabled?"点击禁用调度器":"点击启用调度器",children:[e.jsx(B,{className:`w-4 h-4 ${w.isPending||D.isPending?"animate-pulse":""}`}),e.jsx("span",{className:"font-medium",children:k.enabled?"调度器已启用":"调度器已禁用"})]}),u&&e.jsxs("div",{className:"flex items-center gap-3 text-gray-500 dark:text-gray-400",children:[e.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"|"}),e.jsxs("span",{className:`flex items-center gap-1 ${u.runningTasks>0?"text-blue-600 dark:text-blue-400":""}`,children:[e.jsx(Fe,{className:`w-4 h-4 ${u.runningTasks>0?"animate-pulse":""}`}),"运行: ",u.runningTasks]}),e.jsxs("span",{className:"text-yellow-600 dark:text-yellow-400",children:["队列: ",u.queuedTasks]}),e.jsxs("span",{className:"text-green-600 dark:text-green-400",children:["完成: ",u.completedTasks]}),e.jsxs("span",{className:"text-red-600 dark:text-red-400",children:["失败: ",u.failedTasks]}),e.jsx("button",{onClick:()=>{L&&h(L.maxConcurrent),s(!0)},className:"ml-2 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors",title:"执行器设置",children:e.jsx(Pe,{className:"w-4 h-4"})})]})]}),e.jsxs("button",{onClick:_,className:"inline-flex items-center px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[e.jsx(xe,{className:"w-5 h-5 mr-2"}),"新建任务"]})]})]}),o?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ae,{className:"w-8 h-8 animate-spin text-gray-400"})}):n.length===0?e.jsxs("div",{className:"text-center py-16 bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700",children:[e.jsx(B,{className:"w-16 h-16 mx-auto text-gray-400 mb-4"}),e.jsx("h3",{className:"text-xl font-medium text-gray-900 dark:text-white mb-2",children:"暂无定时任务"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:"创建定时任务来让 Agent 自动执行工作"}),e.jsxs("button",{onClick:_,className:"inline-flex items-center px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[e.jsx(xe,{className:"w-5 h-5 mr-2"}),"创建第一个任务"]})]}):e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden",children:e.jsxs(ue,{children:[e.jsx(ge,{children:e.jsxs(Y,{children:[e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"状态"}),e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"任务名称"}),e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Agent"}),e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"调度规则"}),e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"上次执行"}),e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"下次执行"}),e.jsx(v,{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:"操作"})]})}),e.jsx(he,{children:n.map(r=>e.jsxs(Y,{className:"hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors",children:[e.jsx(b,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("button",{onClick:()=>T(r),className:`p-1 rounded-full transition-colors ${r.enabled?"text-green-600 hover:bg-green-100 dark:hover:bg-green-900":"text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800"}`,title:r.enabled?"点击暂停":"点击启用",children:r.enabled?e.jsx(pe,{className:"w-5 h-5 fill-current"}):e.jsx(Re,{className:"w-5 h-5"})})}),e.jsx(b,{className:"px-6 py-4",children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:r.name}),r.description&&e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 truncate max-w-[200px]",children:r.description})]})}),e.jsx(b,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:le(r.agentId)})}),e.jsx(b,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm font-mono text-gray-600 dark:text-gray-400",children:M(r)})}),e.jsx(b,{className:"px-6 py-4",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[se(r),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:ee(r.lastRunAt)})]})}),e.jsx(b,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:r.enabled?ee(r.nextRunAt):"-"})}),e.jsx(b,{className:"px-6 py-4 whitespace-nowrap text-right text-sm font-medium",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[r.lastRunStatus==="running"?e.jsx("button",{onClick:()=>te(r),className:"p-2 text-red-500 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900 rounded-lg transition-colors",title:"停止执行",children:e.jsx(De,{className:"w-4 h-4"})}):e.jsx("button",{onClick:()=>I(r),className:"p-2 text-gray-500 hover:text-blue-600 hover:bg-blue-50 dark:hover:bg-blue-900 rounded-lg transition-colors",title:"立即执行",children:e.jsx(Ke,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>Q(r.id),className:"p-2 text-gray-500 hover:text-purple-600 hover:bg-purple-50 dark:hover:bg-purple-900 rounded-lg transition-colors",title:"执行历史",children:e.jsx(Oe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>X(r),className:"p-2 text-gray-500 hover:text-green-600 hover:bg-green-50 dark:hover:bg-green-900 rounded-lg transition-colors",title:"编辑",children:e.jsx(Qe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ie(r),className:"p-2 text-gray-500 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900 rounded-lg transition-colors",title:"删除",children:e.jsx(Le,{className:"w-4 h-4"})})]})})]},r.id))})]})}),N&&e.jsx(lt,{task:A,agents:E,onSave:re,onCancel:G}),p&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md mx-4",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200 dark:border-gray-700",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"执行器设置"}),e.jsx("button",{onClick:()=>s(!1),className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700",children:e.jsx(Ve,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"px-6 py-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"最大并发数 (1-10)"}),e.jsx("input",{type:"number",min:1,max:10,value:d,onChange:r=>h(Math.min(10,Math.max(1,parseInt(r.target.value)||1))),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"允许同时执行的最大任务数量"})]}),L&&e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:["当前配置: 并发 ",L.maxConcurrent]})]}),e.jsxs("div",{className:"flex justify-end gap-3 px-6 py-4 border-t border-gray-200 dark:border-gray-700",children:[e.jsx("button",{onClick:()=>s(!1),className:"px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg",children:"取消"}),e.jsx("button",{onClick:async()=>{try{await V.mutateAsync({maxConcurrent:d}),S(`并发数已更新为 ${d}`),s(!1)}catch(r){g(r instanceof Error?r.message:"更新失败")}},disabled:V.isPending,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:V.isPending?"保存中...":"保存"})]})]})})]})};export{ft as ScheduledTasksPage,ft as default};
1
+ import{j as e}from"./data-structures-ChC1tqVg.js";import{r as c,W as ve}from"./monaco-editor-BWfQfpij.js";import{T as ue,a as ge,b as Y,c as v,d as he,e as b}from"./table-BgVewkB5.js";import{b as J,u as $,c as P,a as f,A as j}from"./agents-DR9EZMs5.js";import{u as Ne}from"./useAgents-M4lcWvy0.js";import{u as Se}from"./useProjects-D1ElB-WS.js";import{u as Ce}from"./useClaudeVersions-CKT_fq1t.js";import{a as g,s as S,c as Te}from"./index-BIGPvi1D.js";import{m as B,t as Ee,e as Ie,an as ce,k as me,a6 as $e,R as ye,ag as pe,a4 as Ae,aF as qe,L as ae,l as Me,d as oe,n as be,C as fe,A as Fe,r as Pe,v as xe,aG as Re,aH as De,V as Ke,aI as Oe,J as Qe,y as Le,X as Ve}from"./ui-components-D1pZO0y-.js";import"./syntax-highlighting-DGbNjS3S.js";import"./tools-crrPnehB.js";const i={all:["scheduled-tasks"],lists:()=>[...i.all,"list"],list:()=>[...i.lists()],details:()=>[...i.all,"detail"],detail:t=>[...i.details(),t],history:t=>[...i.all,"history",t],status:()=>[...i.all,"status"]},He=()=>J({queryKey:i.list(),queryFn:async()=>{const t=await f(`${j}/scheduled-tasks`);if(!t.ok)throw new Error("Failed to fetch scheduled tasks");return t.json()},refetchInterval:t=>t.state.data?.some(o=>o.lastRunStatus==="running")?3e3:!1}),Be=(t,l=50)=>J({queryKey:i.history(t),queryFn:async()=>{const n=await f(`${j}/scheduled-tasks/${t}/history?limit=${l}`);if(!n.ok)throw new Error("Failed to fetch task execution history");return n.json()},enabled:!!t,refetchInterval:n=>n.state.data?.some(k=>k.status==="running")?3e3:!1}),ze=()=>J({queryKey:i.status(),queryFn:async()=>{const t=await f(`${j}/scheduled-tasks/status`);if(!t.ok)throw new Error("Failed to fetch scheduler status");return t.json()},refetchInterval:3e4}),Ue=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/scheduled-tasks`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to create scheduled task")}return n.json()},onSuccess:()=>{t.invalidateQueries({queryKey:i.lists()}),t.invalidateQueries({queryKey:i.status()})}})},_e=()=>{const t=$();return P({mutationFn:async({taskId:l,data:n})=>{const o=await f(`${j}/scheduled-tasks/${l}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!o.ok){const C=await o.json().catch(()=>({}));throw new Error(C.error||"Failed to update scheduled task")}return o.json()},onSuccess:l=>{t.invalidateQueries({queryKey:i.lists()}),t.invalidateQueries({queryKey:i.detail(l.id)}),t.invalidateQueries({queryKey:i.status()})}})},Je=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/scheduled-tasks/${l}`,{method:"DELETE"});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to delete scheduled task")}},onSuccess:()=>{t.invalidateQueries({queryKey:i.lists()}),t.invalidateQueries({queryKey:i.status()})}})},We=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/scheduled-tasks/${l}/toggle`,{method:"POST"});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to toggle scheduled task")}return n.json()},onSuccess:l=>{t.invalidateQueries({queryKey:i.lists()}),t.invalidateQueries({queryKey:i.detail(l.id)}),t.invalidateQueries({queryKey:i.status()})}})},je=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/scheduled-tasks/${l}/run`,{method:"POST"});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to run scheduled task")}return n.json()},onSuccess:(l,n)=>{t.invalidateQueries({queryKey:i.detail(n)}),t.invalidateQueries({queryKey:i.lists()}),t.invalidateQueries({queryKey:i.history(n)})}})},Xe=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/scheduled-tasks/executions/${l}/stop`,{method:"POST"});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to stop execution")}return n.json()},onSuccess:()=>{t.invalidateQueries({queryKey:i.all})}})},Ge=()=>J({queryKey:[...i.all,"running"],queryFn:async()=>{const t=await f(`${j}/scheduled-tasks/running`);if(!t.ok)throw new Error("Failed to fetch running executions");return t.json()},refetchInterval:3e3}),Ye=()=>{const t=$();return P({mutationFn:async()=>{const l=await f(`${j}/scheduled-tasks/scheduler/enable`,{method:"POST"});if(!l.ok){const n=await l.json().catch(()=>({}));throw new Error(n.error||"Failed to enable scheduler")}return l.json()},onSuccess:()=>{t.invalidateQueries({queryKey:i.status()})}})},Ze=()=>{const t=$();return P({mutationFn:async()=>{const l=await f(`${j}/scheduled-tasks/scheduler/disable`,{method:"POST"});if(!l.ok){const n=await l.json().catch(()=>({}));throw new Error(n.error||"Failed to disable scheduler")}return l.json()},onSuccess:()=>{t.invalidateQueries({queryKey:i.status()})}})},Z={all:["task-executor"],stats:()=>[...Z.all,"stats"],health:()=>[...Z.all,"health"]},et=()=>J({queryKey:Z.stats(),queryFn:async()=>{const t=await f(`${j}/task-executor/stats`);if(!t.ok)throw new Error("Failed to fetch task executor stats");return t.json()},refetchInterval:5e3}),tt=()=>J({queryKey:[...Z.all,"config"],queryFn:async()=>{const t=await f(`${j}/task-executor/config`);if(!t.ok)throw new Error("Failed to fetch task executor config");return t.json()}}),rt=()=>{const t=$();return P({mutationFn:async l=>{const n=await f(`${j}/task-executor/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||"Failed to update executor config")}return n.json()},onSuccess:()=>{t.invalidateQueries({queryKey:Z.all})}})},st=[{label:"每 5 分钟",value:"*/5 * * * *"},{label:"每 15 分钟",value:"*/15 * * * *"},{label:"每 30 分钟",value:"*/30 * * * *"},{label:"每小时",value:"0 * * * *"},{label:"每天 9:00",value:"0 9 * * *"},{label:"每天 18:00",value:"0 18 * * *"},{label:"每周一 9:00",value:"0 9 * * 1"},{label:"每月 1 日 9:00",value:"0 9 1 * *"}],at=t=>{if(!t){const l=new Date;return l.setHours(l.getHours()+1),l.setMinutes(0),l.setSeconds(0),l.toISOString().slice(0,16)}return new Date(t).toISOString().slice(0,16)},nt=t=>new Date(t).toISOString(),lt=({task:t,agents:l,onSave:n,onCancel:o})=>{const C=!!t,k=Ue(),z=_e(),U=je(),{data:W}=Se(),R=W?.projects||[],{data:x}=Ce(),[w,D]=c.useState(t?.name||""),[A,K]=c.useState(t?.description||""),[N,q]=c.useState(t?.agentId||""),[m,Q]=c.useState(t?.projectPath||""),[p,s]=c.useState(t?.schedule.type||"interval"),[d,h]=c.useState(t?.schedule.intervalMinutes||30),[u,L]=c.useState(t?.schedule.cronExpression||"*/30 * * * *"),[V,ne]=c.useState(at(t?.schedule.executeAt)),[E,le]=c.useState(t?.triggerMessage||""),[M,ee]=c.useState(t?.enabled??!0),[T,ie]=c.useState(!!t?.modelOverride?.modelId),[I,te]=c.useState(t?.modelOverride?.versionId||""),[H,X]=c.useState(t?.modelOverride?.modelId||""),[_,re]=c.useState(!1),[G,se]=c.useState(!1),r=c.useMemo(()=>x?.versions?I?x.versions.find(de=>de.id===I)?.models||[]:(x.versions.find(O=>O.id===x.defaultVersionId)||x.versions[0])?.models||[]:[],[x,I]);c.useEffect(()=>{T&&x?.versions&&I&&(x.versions.some(O=>O.id===I)||(te(x.defaultVersionId||""),X("")))},[x,I,T]),c.useEffect(()=>{T&&r.length>0&&(r.some(O=>O.id===H)||X(r[0].id))},[r,H,T]),c.useEffect(()=>{!N&&l.length>0&&q(l[0].id)},[N,l]),c.useEffect(()=>{!m&&R.length>0&&Q(R[0].path)},[m,R]);const y=()=>p==="interval"?{type:"interval",intervalMinutes:d}:p==="once"?{type:"once",executeAt:nt(V)}:{type:"cron",cronExpression:u},F=()=>{if(!(!T||!H))return{versionId:I||void 0,modelId:H}},ke=async()=>{if(!w.trim()){g("请输入任务名称");return}if(!N){g("请选择 Agent");return}if(!m){g("请选择项目路径");return}if(!E.trim()){g("请输入触发消息");return}if(p==="interval"&&(!d||d<1)){g("间隔时间必须大于 0");return}if(p==="cron"&&!u.trim()){g("请输入 Cron 表达式");return}if(p==="once"){const a=new Date(V).getTime();if(isNaN(a)){g("请选择有效的执行时间");return}if(a<=Date.now()){g("执行时间必须在未来");return}}re(!0);try{if(C)await z.mutateAsync({taskId:t.id,data:{name:w.trim(),description:A.trim()||void 0,agentId:N,projectPath:m,schedule:y(),triggerMessage:E.trim(),enabled:M,modelOverride:F()}}),S("任务已更新");else{const a={name:w.trim(),description:A.trim()||void 0,agentId:N,projectPath:m,schedule:y(),triggerMessage:E.trim(),enabled:M,modelOverride:F()};await k.mutateAsync(a),S("任务已创建")}n()}catch{g(C?"更新失败":"创建失败")}finally{re(!1)}},we=async()=>{if(!w.trim()){g("请输入任务名称");return}if(!N){g("请选择 Agent");return}if(!m){g("请选择项目路径");return}if(!E.trim()){g("请输入触发消息");return}se(!0);try{let a;if(C)await z.mutateAsync({taskId:t.id,data:{name:w.trim(),description:A.trim()||void 0,agentId:N,projectPath:m,schedule:y(),triggerMessage:E.trim(),enabled:M,modelOverride:F()}}),a=t.id,S("任务已更新");else{const O={name:w.trim(),description:A.trim()||void 0,agentId:N,projectPath:m,schedule:y(),triggerMessage:E.trim(),enabled:M,modelOverride:F()};a=(await k.mutateAsync(O)).id,S("任务已创建")}await U.mutateAsync(a),S("任务已开始执行,请在执行历史中查看结果"),n()}catch{g("操作失败")}finally{se(!1)}};return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-5xl max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:C?"编辑定时任务":"创建定时任务"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"配置 Agent 的自动执行计划"})]}),e.jsx("button",{onClick:o,className:"p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(B,{className:"w-5 h-5"}),"基本信息"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"任务名称 *"}),e.jsx("input",{type:"text",value:w,onChange:a=>D(a.target.value),placeholder:"例如:每日代码检查",className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"描述"}),e.jsx("input",{type:"text",value:A,onChange:a=>K(a.target.value),placeholder:"可选的任务描述",className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(Ee,{className:"w-5 h-5"}),"执行配置"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"执行 Agent *"}),e.jsx("select",{value:N,onChange:a=>q(a.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:l.map(a=>e.jsxs("option",{value:a.id,children:[a.ui?.icon||"🤖"," ",a.name]},a.id))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1 flex items-center gap-2",children:[e.jsx(Ie,{className:"w-4 h-4"}),"项目路径 *"]}),e.jsx("select",{value:m,onChange:a=>Q(a.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:R.map(a=>e.jsx("option",{value:a.path,children:a.name||a.path},a.path))}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"Agent 将在此项目目录下执行"})]}),e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"覆盖模型配置"})]}),e.jsx("button",{type:"button",onClick:()=>ie(!T),className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${T?"bg-blue-600":"bg-gray-300 dark:bg-gray-600"}`,children:e.jsx("span",{className:`inline-block h-3 w-3 transform rounded-full bg-white transition-transform ${T?"translate-x-5":"translate-x-1"}`})})]}),T&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-2",children:"可以为定时任务指定不同于 Agent 默认的模型"}),x?.versions&&x.versions.length>1&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-gray-500 dark:text-gray-400 mb-1",children:"供应商"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:I,onChange:a=>te(a.target.value),className:"w-full appearance-none px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:[e.jsx("option",{value:"",children:x.defaultVersionId?`默认 (${x.versions.find(a=>a.id===x.defaultVersionId)?.name})`:"默认"}),x.versions.filter(a=>a.id!==x.defaultVersionId).map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]}),e.jsx("div",{className:"absolute inset-y-0 right-0 flex items-center px-2 pointer-events-none text-gray-500",children:e.jsx(me,{className:"w-4 h-4"})})]})]}),r.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-gray-500 dark:text-gray-400 mb-1",children:"模型"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:r.map(a=>e.jsxs("button",{type:"button",onClick:()=>X(a.id),className:`flex items-center justify-between px-3 py-2 text-sm rounded-lg border transition-all ${H===a.id?"border-purple-500 bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300 shadow-sm":"border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600 text-gray-700 dark:text-gray-300"}`,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ce,{className:"w-4 h-4 opacity-70"}),e.jsx("span",{className:"font-medium",children:a.name})]}),a.isVision&&e.jsx("span",{className:"text-xs bg-gray-100 dark:bg-gray-700 px-1.5 py-0.5 rounded text-gray-500",children:"Vision"})]},a.id))})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(B,{className:"w-5 h-5"}),"调度规则"]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsxs("label",{className:"flex items-center",children:[e.jsx("input",{type:"radio",name:"scheduleType",value:"interval",checked:p==="interval",onChange:()=>s("interval"),className:"mr-2"}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300",children:"间隔执行"})]}),e.jsxs("label",{className:"flex items-center",children:[e.jsx("input",{type:"radio",name:"scheduleType",value:"cron",checked:p==="cron",onChange:()=>s("cron"),className:"mr-2"}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300",children:"Cron 表达式"})]}),e.jsxs("label",{className:"flex items-center",children:[e.jsx("input",{type:"radio",name:"scheduleType",value:"once",checked:p==="once",onChange:()=>s("once"),className:"mr-2"}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300",children:"仅执行一次"})]})]}),p==="interval"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"间隔时间(分钟)"}),e.jsx("input",{type:"number",min:1,max:10080,value:d,onChange:a=>h(parseInt(a.target.value)||30),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),e.jsxs("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:["每隔 ",d," 分钟执行一次"]})]}),p==="cron"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Cron 表达式"}),e.jsx("input",{type:"text",value:u,onChange:a=>L(a.target.value),placeholder:"*/30 * * * *",className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white font-mono focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:st.map(a=>e.jsx("button",{type:"button",onClick:()=>L(a.value),className:`px-2 py-1 text-xs rounded-full border transition-colors ${u===a.value?"bg-blue-100 border-blue-300 text-blue-700 dark:bg-blue-900 dark:border-blue-700 dark:text-blue-300":"bg-gray-50 border-gray-200 text-gray-600 hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700"}`,children:a.label},a.value))})]}),p==="once"&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1 flex items-center gap-2",children:[e.jsx($e,{className:"w-4 h-4"}),"执行时间"]}),e.jsx("input",{type:"datetime-local",value:V,onChange:a=>ne(a.target.value),min:new Date().toISOString().slice(0,16),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"任务将在指定时间执行一次后自动禁用"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(ye,{className:"w-5 h-5"}),"触发消息"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"发送给 Agent 的消息 *"}),e.jsx("textarea",{value:E,onChange:a=>le(a.target.value),placeholder:"请检查代码质量并生成报告...",rows:5,className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-y"}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"定时触发时,这条消息会发送给选定的 Agent"})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-4 border-t border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"启用任务"}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"创建后立即开始调度"})]}),e.jsx("button",{type:"button",onClick:()=>ee(!M),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${M?"bg-blue-600":"bg-gray-300 dark:bg-gray-600"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${M?"translate-x-6":"translate-x-1"}`})})]}),e.jsxs("div",{className:"flex justify-between pt-4 border-t border-gray-200 dark:border-gray-700",children:[e.jsx("button",{onClick:o,className:"px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg transition-colors",children:"取消"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("button",{onClick:we,disabled:_||G,className:"inline-flex items-center px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors disabled:opacity-50",title:"保存任务并立即执行一次",children:[e.jsx(pe,{className:"w-4 h-4 mr-2"}),G?"执行中...":"保存并执行"]}),e.jsxs("button",{onClick:ke,disabled:_||G,className:"inline-flex items-center px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50",children:[e.jsx(Ae,{className:"w-4 h-4 mr-2"}),_?"保存中...":"保存"]})]})]})]})})]})})},it=({taskId:t,taskName:l,agentId:n,projectPath:o,onBack:C})=>{const{data:k=[],isLoading:z}=Be(t),[U,W]=c.useState(new Set),R=s=>{W(d=>{const h=new Set(d);return h.has(s)?h.delete(s):h.add(s),h})},x=s=>s?new Date(s).toLocaleString("zh-CN"):"-",w=s=>new Date(s).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3}),D=s=>{if(!s.completedAt)return"-";const d=new Date(s.startedAt).getTime(),u=new Date(s.completedAt).getTime()-d;return u<1e3?`${u}ms`:u<6e4?`${(u/1e3).toFixed(1)}s`:`${Math.floor(u/6e4)}m ${Math.floor(u%6e4/1e3)}s`},A=s=>{switch(s){case"running":return e.jsx(ae,{className:"w-5 h-5 text-blue-500 animate-spin"});case"success":return e.jsx(fe,{className:"w-5 h-5 text-green-500"});case"error":return e.jsx(be,{className:"w-5 h-5 text-red-500"});default:return e.jsx(B,{className:"w-5 h-5 text-gray-400"})}},K=s=>{switch(s){case"running":return e.jsx("span",{className:"text-blue-600 dark:text-blue-400",children:"运行中"});case"success":return e.jsx("span",{className:"text-green-600 dark:text-green-400",children:"成功"});case"error":return e.jsx("span",{className:"text-red-600 dark:text-red-400",children:"失败"});default:return e.jsx("span",{className:"text-gray-500",children:"未知"})}},N=s=>{switch(s){case"error":return"text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-900/20";case"warn":return"text-yellow-600 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-900/20";case"info":return"text-blue-600 dark:text-blue-400";case"debug":return"text-gray-500 dark:text-gray-400";default:return"text-gray-600 dark:text-gray-400"}},q=s=>{switch(s){case"system":return"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400";case"assistant":return"bg-blue-100 text-blue-600 dark:bg-blue-900 dark:text-blue-400";case"tool_use":return"bg-purple-100 text-purple-600 dark:bg-purple-900 dark:text-purple-400";case"result":return"bg-green-100 text-green-600 dark:bg-green-900 dark:text-green-400";case"error":return"bg-red-100 text-red-600 dark:bg-red-900 dark:text-red-400";default:return"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400"}},m=s=>{const d=s.agentId||n,h=s.projectPath||o;if(!d||!s.sessionId)return null;let u=`/chat/${encodeURIComponent(d)}?session=${encodeURIComponent(s.sessionId)}`;return h&&(u+=`&project=${encodeURIComponent(h)}`),u},Q=(s,d)=>{d.stopPropagation();const h=m(s);h&&window.open(h,"_blank")},p=s=>!s||s.length===0?e.jsx("div",{className:"text-center py-4 text-gray-500 dark:text-gray-400",children:"暂无执行日志"}):e.jsx("div",{className:"space-y-1 max-h-96 overflow-y-auto",children:s.map((d,h)=>e.jsxs("div",{className:`flex items-start gap-2 px-3 py-1.5 rounded text-sm font-mono ${N(d.level)}`,children:[e.jsx("span",{className:"text-gray-400 dark:text-gray-500 shrink-0 w-24",children:w(d.timestamp)}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs shrink-0 ${q(d.type)}`,children:d.type}),e.jsx("span",{className:"flex-1 break-all whitespace-pre-wrap",children:d.message})]},h))});return e.jsxs("div",{className:"p-8",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("button",{onClick:C,className:"p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg transition-colors",children:e.jsx(qe,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"执行历史"}),e.jsxs("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:["任务:",l]})]})]}),z?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ae,{className:"w-8 h-8 animate-spin text-gray-400"})}):k.length===0?e.jsxs("div",{className:"text-center py-12 bg-gray-50 dark:bg-gray-800 rounded-lg",children:[e.jsx(B,{className:"w-12 h-12 mx-auto text-gray-400 mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:"暂无执行记录"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:"任务尚未执行过"})]}):e.jsx("div",{className:"bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden",children:e.jsxs(ue,{children:[e.jsx(ge,{children:e.jsxs(Y,{children:[e.jsx(v,{className:"w-[40px]"}),e.jsx(v,{className:"w-[80px]",children:"状态"}),e.jsx(v,{children:"开始时间"}),e.jsx(v,{children:"完成时间"}),e.jsx(v,{children:"耗时"}),e.jsx(v,{children:"结果摘要"}),e.jsx(v,{className:"w-[100px]",children:"操作"})]})}),e.jsx(he,{children:k.map(s=>e.jsxs(ve.Fragment,{children:[e.jsxs(Y,{className:"cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800",onClick:()=>R(s.id),children:[e.jsx(b,{className:"p-2",children:e.jsx("button",{className:"p-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded",children:U.has(s.id)?e.jsx(me,{className:"w-4 h-4 text-gray-500"}):e.jsx(Me,{className:"w-4 h-4 text-gray-500"})})}),e.jsx(b,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[A(s.status),K(s.status)]})}),e.jsx(b,{children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:x(s.startedAt)})}),e.jsx(b,{children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:x(s.completedAt)})}),e.jsx(b,{children:e.jsx("span",{className:"text-sm font-mono text-gray-600 dark:text-gray-400",children:D(s)})}),e.jsx(b,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[s.logs&&s.logs.length>0&&e.jsx("span",{title:"有详细日志",children:e.jsx(oe,{className:"w-4 h-4 text-gray-400 shrink-0"})}),s.error?e.jsx("div",{className:"text-sm text-red-600 dark:text-red-400 max-w-md truncate",children:s.error}):s.responseSummary?e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400 max-w-md truncate",children:s.responseSummary}):e.jsx("span",{className:"text-sm text-gray-400",children:"-"})]})}),e.jsx(b,{children:s.sessionId&&m(s)&&e.jsx("button",{onClick:d=>Q(s,d),className:"inline-flex items-center justify-center p-2 text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 hover:bg-blue-50 dark:hover:bg-blue-900/20 rounded transition-colors",title:"在新窗口继续会话",children:e.jsx(ye,{className:"w-4 h-4"})})})]}),U.has(s.id)&&e.jsx(Y,{children:e.jsx(b,{colSpan:7,className:"bg-gray-50 dark:bg-gray-800/50 p-4",children:e.jsxs("div",{className:"space-y-3",children:[s.errorStack&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3",children:[e.jsx("h4",{className:"text-sm font-medium text-red-700 dark:text-red-400 mb-2",children:"错误堆栈"}),e.jsx("pre",{className:"text-xs text-red-600 dark:text-red-400 whitespace-pre-wrap overflow-x-auto",children:s.errorStack})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg p-3",children:[e.jsxs("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-2 flex items-center gap-2",children:[e.jsx(oe,{className:"w-4 h-4"}),"执行日志",s.logs&&e.jsxs("span",{className:"text-xs text-gray-400",children:["(",s.logs.length," 条)"]})]}),p(s.logs)]}),s.sessionId&&e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Session ID: ",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded",children:s.sessionId})]})]})})})]},s.id))})]})})]})},ft=()=>{const t=$(),l=Te(),{data:n=[],isLoading:o}=He(),{data:C}=Ne(!0),{data:k}=ze(),z=Je(),U=We(),W=je(),R=Xe(),{data:x}=Ge(),w=Ye(),D=Ze(),[A,K]=c.useState(null),[N,q]=c.useState(!1),[m,Q]=c.useState(null),[p,s]=c.useState(!1),[d,h]=c.useState(2),{data:u}=et(),{data:L}=tt(),V=rt(),ne=r=>x?.executions?.find(F=>F.taskId===r)?.executionId||null,E=C?.agents||[],le=r=>E.find(F=>F.id===r)?.name||r,M=r=>{if(r.schedule.type==="interval"&&r.schedule.intervalMinutes){const y=r.schedule.intervalMinutes;return y<60?`每 ${y} 分钟`:`每 ${Math.floor(y/60)} 小时`}return r.schedule.type==="cron"&&r.schedule.cronExpression?r.schedule.cronExpression:r.schedule.type==="once"&&r.schedule.executeAt?`一次性 @ ${new Date(r.schedule.executeAt).toLocaleString("zh-CN")}`:"-"},ee=r=>r?new Date(r).toLocaleString("zh-CN"):"-",T=async r=>{try{await U.mutateAsync(r.id),S(r.enabled?"任务已暂停":"任务已启用")}catch{g("操作失败")}},ie=async r=>{if(await l({title:"删除确认",message:`确定要删除任务 "${r.name}" 吗?`,confirmText:"删除",cancelText:"取消",variant:"danger"}))try{await z.mutateAsync(r.id),S("任务已删除")}catch{g("删除失败")}},I=async r=>{try{await W.mutateAsync(r.id),S("任务已开始执行"),t.invalidateQueries({queryKey:i.lists()})}catch{g("执行失败")}},te=async r=>{const y=ne(r.id);if(!y){g("找不到正在运行的执行");return}try{await R.mutateAsync(y),S("任务已停止"),t.invalidateQueries({queryKey:i.lists()})}catch{g("停止失败")}},H=async()=>{if(k)try{k.enabled?(await D.mutateAsync(),S("调度器已禁用")):(await w.mutateAsync(),S("调度器已启用"))}catch{g("操作失败")}},X=r=>{K(r),q(!0)},_=()=>{K(null),q(!0)},re=()=>{K(null),q(!1),t.invalidateQueries({queryKey:i.lists()})},G=()=>{K(null),q(!1)},se=r=>r.lastRunStatus==="running"?e.jsxs("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",children:[e.jsx(ae,{className:"w-3 h-3 mr-1 animate-spin"}),"运行中"]}):r.lastRunStatus==="success"?e.jsxs("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200",children:[e.jsx(fe,{className:"w-3 h-3 mr-1"}),"成功"]}):r.lastRunStatus==="error"?e.jsxs("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200",children:[e.jsx(be,{className:"w-3 h-3 mr-1"}),"失败"]}):e.jsx("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400",children:"未执行"});if(m){const r=n.find(y=>y.id===m);return e.jsx(it,{taskId:m,taskName:r?.name||m,agentId:r?.agentId,projectPath:r?.projectPath,onBack:()=>Q(null)})}return e.jsxs("div",{className:"p-8",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(B,{className:"w-8 h-8"}),"定时任务"]}),e.jsx("p",{className:"mt-2 text-gray-600 dark:text-gray-400",children:"配置 Agent 的自动执行计划"})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[k&&e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs("button",{onClick:H,disabled:w.isPending||D.isPending,className:`flex items-center gap-2 px-3 py-1.5 rounded-lg transition-colors ${k.enabled?"bg-green-50 dark:bg-green-900/20 text-green-700 dark:text-green-300 hover:bg-green-100 dark:hover:bg-green-900/30":"bg-orange-50 dark:bg-orange-900/20 text-orange-700 dark:text-orange-300 hover:bg-orange-100 dark:hover:bg-orange-900/30"} ${w.isPending||D.isPending?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,title:k.enabled?"点击禁用调度器":"点击启用调度器",children:[e.jsx(B,{className:`w-4 h-4 ${w.isPending||D.isPending?"animate-pulse":""}`}),e.jsx("span",{className:"font-medium",children:k.enabled?"调度器已启用":"调度器已禁用"})]}),u&&e.jsxs("div",{className:"flex items-center gap-3 text-gray-500 dark:text-gray-400",children:[e.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"|"}),e.jsxs("span",{className:`flex items-center gap-1 ${u.runningTasks>0?"text-blue-600 dark:text-blue-400":""}`,children:[e.jsx(Fe,{className:`w-4 h-4 ${u.runningTasks>0?"animate-pulse":""}`}),"运行: ",u.runningTasks]}),e.jsxs("span",{className:"text-yellow-600 dark:text-yellow-400",children:["队列: ",u.queuedTasks]}),e.jsxs("span",{className:"text-green-600 dark:text-green-400",children:["完成: ",u.completedTasks]}),e.jsxs("span",{className:"text-red-600 dark:text-red-400",children:["失败: ",u.failedTasks]}),e.jsx("button",{onClick:()=>{L&&h(L.maxConcurrent),s(!0)},className:"ml-2 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors",title:"执行器设置",children:e.jsx(Pe,{className:"w-4 h-4"})})]})]}),e.jsxs("button",{onClick:_,className:"inline-flex items-center px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[e.jsx(xe,{className:"w-5 h-5 mr-2"}),"新建任务"]})]})]}),o?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ae,{className:"w-8 h-8 animate-spin text-gray-400"})}):n.length===0?e.jsxs("div",{className:"text-center py-16 bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700",children:[e.jsx(B,{className:"w-16 h-16 mx-auto text-gray-400 mb-4"}),e.jsx("h3",{className:"text-xl font-medium text-gray-900 dark:text-white mb-2",children:"暂无定时任务"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:"创建定时任务来让 Agent 自动执行工作"}),e.jsxs("button",{onClick:_,className:"inline-flex items-center px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[e.jsx(xe,{className:"w-5 h-5 mr-2"}),"创建第一个任务"]})]}):e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden",children:e.jsxs(ue,{children:[e.jsx(ge,{children:e.jsxs(Y,{children:[e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"状态"}),e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"任务名称"}),e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Agent"}),e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"调度规则"}),e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"上次执行"}),e.jsx(v,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"下次执行"}),e.jsx(v,{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:"操作"})]})}),e.jsx(he,{children:n.map(r=>e.jsxs(Y,{className:"hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors",children:[e.jsx(b,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("button",{onClick:()=>T(r),className:`p-1 rounded-full transition-colors ${r.enabled?"text-green-600 hover:bg-green-100 dark:hover:bg-green-900":"text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800"}`,title:r.enabled?"点击暂停":"点击启用",children:r.enabled?e.jsx(pe,{className:"w-5 h-5 fill-current"}):e.jsx(Re,{className:"w-5 h-5"})})}),e.jsx(b,{className:"px-6 py-4",children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:r.name}),r.description&&e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 truncate max-w-[200px]",children:r.description})]})}),e.jsx(b,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:le(r.agentId)})}),e.jsx(b,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm font-mono text-gray-600 dark:text-gray-400",children:M(r)})}),e.jsx(b,{className:"px-6 py-4",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[se(r),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:ee(r.lastRunAt)})]})}),e.jsx(b,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:r.enabled?ee(r.nextRunAt):"-"})}),e.jsx(b,{className:"px-6 py-4 whitespace-nowrap text-right text-sm font-medium",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[r.lastRunStatus==="running"?e.jsx("button",{onClick:()=>te(r),className:"p-2 text-red-500 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900 rounded-lg transition-colors",title:"停止执行",children:e.jsx(De,{className:"w-4 h-4"})}):e.jsx("button",{onClick:()=>I(r),className:"p-2 text-gray-500 hover:text-blue-600 hover:bg-blue-50 dark:hover:bg-blue-900 rounded-lg transition-colors",title:"立即执行",children:e.jsx(Ke,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>Q(r.id),className:"p-2 text-gray-500 hover:text-purple-600 hover:bg-purple-50 dark:hover:bg-purple-900 rounded-lg transition-colors",title:"执行历史",children:e.jsx(Oe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>X(r),className:"p-2 text-gray-500 hover:text-green-600 hover:bg-green-50 dark:hover:bg-green-900 rounded-lg transition-colors",title:"编辑",children:e.jsx(Qe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ie(r),className:"p-2 text-gray-500 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900 rounded-lg transition-colors",title:"删除",children:e.jsx(Le,{className:"w-4 h-4"})})]})})]},r.id))})]})}),N&&e.jsx(lt,{task:A,agents:E,onSave:re,onCancel:G}),p&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md mx-4",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200 dark:border-gray-700",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"执行器设置"}),e.jsx("button",{onClick:()=>s(!1),className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700",children:e.jsx(Ve,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"px-6 py-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"最大并发数 (1-10)"}),e.jsx("input",{type:"number",min:1,max:10,value:d,onChange:r=>h(Math.min(10,Math.max(1,parseInt(r.target.value)||1))),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"允许同时执行的最大任务数量"})]}),L&&e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:["当前配置: 并发 ",L.maxConcurrent]})]}),e.jsxs("div",{className:"flex justify-end gap-3 px-6 py-4 border-t border-gray-200 dark:border-gray-700",children:[e.jsx("button",{onClick:()=>s(!1),className:"px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg",children:"取消"}),e.jsx("button",{onClick:async()=>{try{await V.mutateAsync({maxConcurrent:d}),S(`并发数已更新为 ${d}`),s(!1)}catch(r){g(r instanceof Error?r.message:"更新失败")}},disabled:V.isPending,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:V.isPending?"保存中...":"保存"})]})]})})]})};export{ft as ScheduledTasksPage,ft as default};
@@ -0,0 +1 @@
1
+ import{j as t}from"./data-structures-ChC1tqVg.js";import{b as i,O as r}from"./index-BIGPvi1D.js";import"./monaco-editor-BWfQfpij.js";import"./syntax-highlighting-DGbNjS3S.js";import"./agents-DR9EZMs5.js";import"./tools-crrPnehB.js";import"./ui-components-D1pZO0y-.js";const l=()=>{const{isMobile:o}=i();return t.jsx("div",{className:o?"p-4":"p-8",children:t.jsx("div",{children:t.jsx(r,{})})})};export{l as SettingsLayout};
@@ -1,4 +1,4 @@
1
- import{j as e}from"./data-structures-ChC1tqVg.js";import{r as x}from"./monaco-editor-BWfQfpij.js";import{T as be,a as fe,b as te,c as Q,d as ye,e as z}from"./table-Clz57edU.js";import{g as ke,a as f,b as re,u as Z,c as X,A as J}from"./agents-KlPdWQ8K.js";import{U as we}from"./UnifiedToolSelector-BP6fuyzG.js";import{u as Y}from"./tools-BZTR2NP1.js";import{r as je,d as ve,aN as Ne,X as V,v as le,S as Se,E as se,e as Te,J as Ce,y as Fe}from"./ui-components-DjgDPiqV.js";import{B as H}from"./Button-CMTSYiKV.js";import{F as $e}from"./FileExplorer-x5R0Tcmk.js";import{T as Ee}from"./ToolsList-CTsQr53G.js";import{e as De,c as Le,a as Me}from"./index-f67nhEoX.js";import"./syntax-highlighting-DGbNjS3S.js";class Pe{baseURL=`${ke()}/skills`;async getAllSkills(l){const a=new URLSearchParams;l?.scope&&a.append("scope",l.scope),l?.includeDisabled&&a.append("includeDisabled","true");const r=await f(`${this.baseURL}?${a.toString()}`);if(!r.ok)throw new Error(`Failed to fetch skills: ${r.statusText}`);const n=await r.json();return this.transformToSkillListItems(n.skills)}async getSkill(l,a){const r=a?`?scope=${a}`:"",n=await f(`${this.baseURL}/${l}${r}`);if(n.status===404)return null;if(!n.ok)throw new Error(`Failed to fetch skill: ${n.statusText}`);return(await n.json()).skill}async createSkill(l){const a=await f(`${this.baseURL}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!a.ok){const n=await a.json();throw new Error(n.error||"Failed to create skill")}return(await a.json()).skill}async updateSkill(l,a){const r=await f(`${this.baseURL}/${l}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!r.ok){const c=await r.json();throw new Error(c.error||"Failed to update skill")}return(await r.json()).skill}async deleteSkill(l,a){const r=a?`?scope=${a}`:"",n=await f(`${this.baseURL}/${l}${r}`,{method:"DELETE"});if(n.status===404)return!1;if(!n.ok)throw new Error(`Failed to delete skill: ${n.statusText}`);return!0}async getSkillDirectoryInfo(l){const a=await f(`${this.baseURL}/${l}/directory`);if(a.status===404)return null;if(!a.ok)throw new Error(`Failed to fetch skill directory info: ${a.statusText}`);return(await a.json()).directoryInfo}async validateSkillManifest(l){const a=await f(`${this.baseURL}/validate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:l})});if(!a.ok)throw new Error(`Failed to validate skill manifest: ${a.statusText}`);return await a.json()}async getSkillFile(l,a){const r=await f(`${this.baseURL}/${l}/files/${a}`);if(!r.ok)throw new Error(`Failed to fetch skill file: ${r.statusText}`);return(await r.json()).content}async updateSkillFile(l,a,r){const n=await f(`${this.baseURL}/${l}/files/${a}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:r})});if(!n.ok)throw new Error(`Failed to update skill file: ${n.statusText}`)}transformToSkillListItems(l){return l.map(a=>({id:a.id,name:a.name,description:a.description,scope:a.scope,projectName:a.scope==="project"?"Current Project":void 0,source:a.source,enabled:a.enabled,createdAt:a.createdAt,updatedAt:a.updatedAt,allowedTools:a.allowedTools,toolCount:a.allowedTools?.length||0,usageCount:0,lastUsed:void 0}))}}const P=new Pe,y={all:["skills"],lists:()=>[...y.all,"list"],list:t=>[...y.lists(),t],details:()=>[...y.all,"detail"],detail:t=>[...y.details(),t],directory:t=>[...y.all,"directory",t]},Ae=t=>re({queryKey:y.list(t||{}),queryFn:()=>P.getAllSkills(t),staleTime:300*1e3}),Ie=(t,l)=>re({queryKey:y.detail(t),queryFn:()=>P.getSkill(t,l),enabled:!!t,staleTime:300*1e3}),Re=()=>{const t=Z();return X({mutationFn:l=>P.createSkill(l),onSuccess:l=>{t.invalidateQueries({queryKey:y.lists()}),t.setQueryData(y.detail(l.id),l)},onError:l=>{console.error("Failed to create skill:",l)}})},Ue=()=>{const t=Z();return X({mutationFn:({skillId:l,updates:a})=>P.updateSkill(l,a),onSuccess:l=>{t.setQueryData(y.detail(l.id),l),t.invalidateQueries({queryKey:y.lists()})},onError:l=>{console.error("Failed to update skill:",l)}})},Be=()=>{const t=Z();return X({mutationFn:({skillId:l,scope:a})=>P.deleteSkill(l,a),onSuccess:(l,{skillId:a})=>{t.removeQueries({queryKey:y.detail(a)}),t.invalidateQueries({queryKey:y.lists()})},onError:l=>{console.error("Failed to delete skill:",l)}})},Ke=()=>X({mutationFn:t=>P.validateSkillManifest(t),onError:t=>{console.error("Failed to validate skill manifest:",t)}}),We=({onClose:t,onSuccess:l,editSkill:a})=>{const{t:r}=Y(["skills","common"]),n=!!a,[c,p]=x.useState("basic"),[o,m]=x.useState({name:"",description:"",allowedTools:[],content:"",additionalFiles:[]}),[h,k]=x.useState([]),[v,F]=x.useState(""),[D,L]=x.useState(!1),[N,T]=x.useState([]),[g,w]=x.useState([]),[$,A]=x.useState(!1),I=Re(),R=Ue(),M=Ke(),B=Ie(a?.id||"",a?.scope||"user"),S=n?B.data:null,G=n?B.isLoading:!1,[K,U]=x.useState(0),[W,E]=x.useState(0),[d,C]=x.useState(!1);x.useEffect(()=>{if(!d){const s=[...N];$&&s.push(...g),m(i=>({...i,allowedTools:s})),U(Date.now())}},[N,g,$,d]),x.useEffect(()=>{!d&&(o.name||o.description)&&U(Date.now())},[o.name,o.description,d]),x.useEffect(()=>{!d&&o.content&&E(Date.now())},[o.content,d]),x.useEffect(()=>{if(n&&S){m({name:S.name,description:S.description,allowedTools:S.allowedTools||[],content:"",additionalFiles:(S.files||[]).filter(u=>!u.path.endsWith("SKILL.md")).map(u=>({id:Math.random().toString(36).substr(2,9),name:u.name,path:u.path,type:u.type,content:""}))});const s=S.allowedTools||[],i=s.filter(u=>!u.startsWith("mcp__")),b=s.filter(u=>u.startsWith("mcp__"));T(i),w(b),A(b.length>0),(async()=>{try{const u=await fetch(`/api/skills/${a.id}/files/SKILL.md`);if(u.ok){const ge=await u.json();m(pe=>({...pe,content:ge.content})),E(Date.now())}}catch(u){console.error("Failed to load skill manifest:",u)}})()}},[n,S,a]),x.useEffect(()=>{if(o.content){const i=setTimeout(async()=>{try{const b=await M.mutateAsync(o.content);k(b.errors.map(j=>j.message)||[])}catch{k(["Validation failed"])}},500);return()=>clearTimeout(i)}},[o.content,M]);const q=async()=>{try{if(n){const s={name:o.name,description:o.description,allowedTools:o.allowedTools,content:o.content,additionalFiles:o.additionalFiles.map(i=>({name:i.name,path:i.path,type:i.type,content:i.content}))};await R.mutateAsync({skillId:a.id,updates:s})}else{const s={name:o.name,description:o.description,scope:"user",allowedTools:o.allowedTools,content:o.content,additionalFiles:o.additionalFiles.map(i=>({name:i.name,path:i.path,type:i.type,content:i.content}))};await I.mutateAsync(s)}l()}catch(s){console.error(n?"Failed to update skill:":"Failed to create skill:",s),alert(r(n?"errors.updateFailed":"errors.createFailed"))}},O=()=>{const s={id:Math.random().toString(36).substr(2,9),name:"New File",path:"new-file.md",type:"markdown",content:""};m(i=>({...i,additionalFiles:[...i.additionalFiles,s]}))},oe=s=>{m(i=>({...i,additionalFiles:i.additionalFiles.filter(b=>b.id!==s)}))},_=(s,i)=>{m(b=>({...b,additionalFiles:b.additionalFiles.map(j=>j.id===s?{...j,...i}:j)}))},ne=o.name.trim()!==""&&!v&&o.description.trim()!==""&&o.content.trim()!==""&&h.length===0,ie=()=>{switch(c){case"basic":return o.name.trim()!==""&&!v&&o.description.trim()!=="";case"manifest":return o.content.trim()!==""&&h.length===0;case"files":return!0;default:return!1}},ee=()=>{if(!d){if(C(!0),K>W){if(o.name&&o.description){const s=ae(o.name,o.description,o.allowedTools);m(i=>({...i,content:s})),E(Date.now())}}else if(W>K){const s=qe(o.content);if(s&&(s.name&&s.name!==o.name||s.description&&s.description!==o.description||s.allowedTools&&JSON.stringify(s.allowedTools)!==JSON.stringify(o.allowedTools))){m(u=>({...u,name:s.name||u.name,description:s.description||u.description,allowedTools:s.allowedTools||u.allowedTools}));const b=(s.allowedTools||[]).filter(u=>!u.startsWith("mcp__")),j=(s.allowedTools||[]).filter(u=>u.startsWith("mcp__"));T(b),w(j),A(j.length>0),U(Date.now())}}else if(!o.content&&o.name&&o.description){const s=ae(o.name,o.description,o.allowedTools);m(i=>({...i,content:s})),E(Date.now())}setTimeout(()=>C(!1),100)}},de=()=>{ee(),c==="basic"?p("manifest"):c==="manifest"&&p("files")},ce=s=>{ee(),p(s)},xe=[{id:"basic",label:r("create.tabs.basic"),icon:je},{id:"manifest",label:r("create.tabs.manifest"),icon:ve},{id:"files",label:r("create.tabs.files"),icon:Ne}],ue=s=>s?s.length>64?"技能名称不能超过64个字符":/^[a-z0-9-]+$/.test(s)?s.startsWith("-")||s.endsWith("-")?"不能以连字符开始或结束":s.includes("--")?"不能包含连续的连字符":"":"只能使用小写字母、数字和连字符":"",me=s=>{m(i=>({...i,name:s})),F(ue(s))},he=s=>{s.key==="Escape"&&t()};return n&&G?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsx("div",{className:"bg-white rounded-lg p-6 w-full max-w-md",children:e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})})})}):e.jsxs("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",onKeyDown:he,children:[e.jsxs("div",{className:"bg-white rounded-lg w-full max-w-3xl max-h-[90vh] overflow-hidden flex flex-col dark:bg-gray-800 dark:text-white",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:n?`编辑技能 - ${a?.name}`:r("create.title")}),e.jsx("p",{className:"text-sm text-gray-600 mt-1 dark:text-gray-300",children:n?"修改现有技能的配置和功能":r("create.subtitle")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[c!=="files"?e.jsx("button",{onClick:de,disabled:!ie(),className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors dark:bg-blue-500 dark:hover:bg-blue-600",children:r("common:actions.next")}):e.jsx("button",{onClick:q,disabled:!ne||I.isPending||R.isPending,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors dark:bg-blue-500 dark:hover:bg-blue-600",children:I.isPending||R.isPending?r("common:status.saving"):r(n?"common:actions.save":"common:actions.create")}),e.jsx("button",{onClick:t,className:"p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100 rounded-lg transition-colors dark:text-gray-400 dark:hover:text-gray-200 dark:hover:bg-gray-700",children:e.jsx(V,{className:"w-5 h-5"})})]})]}),e.jsx("div",{className:"flex border-b border-gray-200 dark:border-gray-700",children:xe.map(s=>{const i=s.icon,b=c===s.id,j=s.id==="basic"&&o.name.trim()!==""&&o.description.trim()!==""||s.id==="manifest"&&o.content.trim()!==""&&h.length===0||s.id==="files";return e.jsxs("button",{onClick:()=>ce(s.id),className:`flex items-center gap-2 px-6 py-3 font-medium text-sm transition-colors ${b?"text-blue-600 border-b-2 border-blue-600 dark:text-blue-400 dark:border-blue-400":"text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"}`,children:[e.jsx(i,{className:"w-4 h-4"}),s.label,j&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500"})]},s.id)})}),e.jsxs("div",{className:"flex-1 overflow-auto p-6",children:[c==="basic"&&e.jsxs("div",{className:"space-y-6 max-w-2xl",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2 dark:text-gray-300",children:"技能名称 (Slug)"}),e.jsx("input",{type:"text",value:o.name,onChange:s=>me(s.target.value),disabled:n,className:`w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400 dark:focus:ring-blue-400 dark:focus:border-blue-400 font-mono ${n?"bg-gray-100 text-gray-500 cursor-not-allowed dark:bg-gray-600 dark:text-gray-400":v?"border-red-500 focus:ring-red-500 focus:border-red-500":"border-gray-300"}`,placeholder:"my-awesome-skill"}),v?e.jsx("p",{className:"text-xs text-red-500 mt-1 dark:text-red-400",children:v}):e.jsx("p",{className:"text-xs text-gray-500 mt-1 dark:text-gray-400",children:n?"技能名称在编辑模式下不能修改":"只能使用小写字母、数字和连字符,最多64个字符"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2 dark:text-gray-300",children:r("create.basic.description")}),e.jsx("textarea",{value:o.description,onChange:s=>{m(i=>({...i,description:s.target.value}))},rows:3,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none resize-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400 dark:focus:ring-blue-400 dark:focus:border-blue-400",placeholder:r("create.basic.descriptionPlaceholder")}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 dark:text-gray-400",children:r("create.basic.descriptionHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2 dark:text-gray-300",children:r("create.basic.allowedTools")}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("button",{type:"button",onClick:()=>L(!D),className:"px-3 py-2 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 rounded-lg transition-colors text-sm",children:r("create.basic.selectTools")}),(N.length>0||g.length>0)&&e.jsxs("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:["常规工具 ",N.length," 个",g.length>0&&`, MCP工具 ${g.length} 个`]})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 dark:text-gray-400",children:r("create.basic.allowedToolsHint")})]})]}),c==="manifest"&&e.jsx("div",{className:"space-y-6 max-w-2xl",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2 dark:text-gray-300",children:r("create.content.skillManifest")}),e.jsx("textarea",{value:o.content,onChange:s=>m(i=>({...i,content:s.target.value})),rows:15,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none font-mono text-sm resize-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-400 dark:focus:border-blue-400"}),h.length>0&&e.jsxs("div",{className:"mt-2 p-3 bg-red-50 border border-red-200 rounded-lg dark:bg-red-900/20 dark:border-red-800",children:[e.jsxs("h4",{className:"text-sm font-medium text-red-800 mb-1 dark:text-red-400",children:[r("editor.errors.validationErrors"),":"]}),e.jsx("ul",{className:"text-sm text-red-700 space-y-1 dark:text-red-300",children:h.map((s,i)=>e.jsxs("li",{children:["• ",s]},i))})]})]})}),c==="files"&&e.jsxs("div",{className:"space-y-6 max-w-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:r("create.content.additionalFiles")}),e.jsxs("button",{onClick:O,className:"flex items-center gap-2 px-3 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors dark:bg-green-500 dark:hover:bg-green-600",children:[e.jsx(le,{className:"w-4 h-4"}),r("create.content.addFile")]})]}),o.additionalFiles.length===0?e.jsxs("div",{className:"text-center py-8 border-2 border-dashed border-gray-300 rounded-lg",children:[e.jsx("p",{className:"text-gray-600 dark:text-gray-300",children:r("create.content.noFiles")}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 dark:text-gray-400",children:r("create.content.noFilesHint")})]}):e.jsx("div",{className:"space-y-4",children:o.additionalFiles.map(s=>e.jsxs("div",{className:"border border-gray-200 rounded-lg p-4 dark:border-gray-700",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx("input",{type:"text",value:s.name,onChange:i=>_(s.id,{name:i.target.value}),className:"flex-1 px-2 py-1 border border-gray-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-400 dark:focus:border-blue-400",placeholder:r("create.content.fileName")}),e.jsx("input",{type:"text",value:s.path,onChange:i=>_(s.id,{path:i.target.value}),className:"flex-1 px-2 py-1 border border-gray-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none font-mono text-sm dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-400 dark:focus:border-blue-400",placeholder:r("create.content.filePath")}),e.jsxs("select",{value:s.type,onChange:i=>_(s.id,{type:i.target.value}),className:"px-2 py-1 border border-gray-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-400 dark:focus:border-blue-400",children:[e.jsx("option",{value:"markdown",children:r("create.content.fileType.markdown")}),e.jsx("option",{value:"text",children:r("create.content.fileType.text")}),e.jsx("option",{value:"script",children:r("create.content.fileType.script")}),e.jsx("option",{value:"template",children:r("create.content.fileType.template")}),e.jsx("option",{value:"other",children:r("create.content.fileType.other")})]})]}),e.jsx("button",{onClick:()=>oe(s.id),className:"p-1 text-red-500 hover:text-red-700 hover:bg-red-50 rounded transition-colors dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20",children:e.jsx(V,{className:"w-4 h-4"})})]}),e.jsx("textarea",{value:s.content,onChange:i=>_(s.id,{content:i.target.value}),rows:6,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none font-mono text-sm resize-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400 dark:focus:ring-blue-400 dark:focus:border-blue-400",placeholder:r("create.content.fileContent")})]},s.id))})]})]})]}),e.jsx(we,{isOpen:D,onClose:()=>L(!1),selectedRegularTools:N,onRegularToolsChange:T,selectedMcpTools:g,onMcpToolsChange:w,mcpToolsEnabled:$,onMcpEnabledChange:A})]})};function qe(t){try{const l=t.match(/^---\s*\n(.*?)\n---/s);if(!l)return null;const r=l[1].split(`
1
+ import{j as e}from"./data-structures-ChC1tqVg.js";import{r as x}from"./monaco-editor-BWfQfpij.js";import{T as be,a as fe,b as te,c as Q,d as ye,e as z}from"./table-BgVewkB5.js";import{g as ke,a as f,b as re,u as Z,c as X,A as J}from"./agents-DR9EZMs5.js";import{U as we}from"./UnifiedToolSelector-DJN7ASu1.js";import{u as Y}from"./tools-crrPnehB.js";import{r as je,d as ve,aN as Ne,X as V,v as le,S as Se,E as se,e as Te,J as Ce,y as Fe}from"./ui-components-D1pZO0y-.js";import{B as H}from"./Button-D5qiS7CR.js";import{F as $e}from"./FileExplorer-BprfeAH_.js";import{T as Ee}from"./ToolsList-BZFBEuvQ.js";import{e as De,c as Le,a as Me}from"./index-BIGPvi1D.js";import"./syntax-highlighting-DGbNjS3S.js";class Pe{baseURL=`${ke()}/skills`;async getAllSkills(l){const a=new URLSearchParams;l?.scope&&a.append("scope",l.scope),l?.includeDisabled&&a.append("includeDisabled","true");const r=await f(`${this.baseURL}?${a.toString()}`);if(!r.ok)throw new Error(`Failed to fetch skills: ${r.statusText}`);const n=await r.json();return this.transformToSkillListItems(n.skills)}async getSkill(l,a){const r=a?`?scope=${a}`:"",n=await f(`${this.baseURL}/${l}${r}`);if(n.status===404)return null;if(!n.ok)throw new Error(`Failed to fetch skill: ${n.statusText}`);return(await n.json()).skill}async createSkill(l){const a=await f(`${this.baseURL}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!a.ok){const n=await a.json();throw new Error(n.error||"Failed to create skill")}return(await a.json()).skill}async updateSkill(l,a){const r=await f(`${this.baseURL}/${l}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!r.ok){const c=await r.json();throw new Error(c.error||"Failed to update skill")}return(await r.json()).skill}async deleteSkill(l,a){const r=a?`?scope=${a}`:"",n=await f(`${this.baseURL}/${l}${r}`,{method:"DELETE"});if(n.status===404)return!1;if(!n.ok)throw new Error(`Failed to delete skill: ${n.statusText}`);return!0}async getSkillDirectoryInfo(l){const a=await f(`${this.baseURL}/${l}/directory`);if(a.status===404)return null;if(!a.ok)throw new Error(`Failed to fetch skill directory info: ${a.statusText}`);return(await a.json()).directoryInfo}async validateSkillManifest(l){const a=await f(`${this.baseURL}/validate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:l})});if(!a.ok)throw new Error(`Failed to validate skill manifest: ${a.statusText}`);return await a.json()}async getSkillFile(l,a){const r=await f(`${this.baseURL}/${l}/files/${a}`);if(!r.ok)throw new Error(`Failed to fetch skill file: ${r.statusText}`);return(await r.json()).content}async updateSkillFile(l,a,r){const n=await f(`${this.baseURL}/${l}/files/${a}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:r})});if(!n.ok)throw new Error(`Failed to update skill file: ${n.statusText}`)}transformToSkillListItems(l){return l.map(a=>({id:a.id,name:a.name,description:a.description,scope:a.scope,projectName:a.scope==="project"?"Current Project":void 0,source:a.source,enabled:a.enabled,createdAt:a.createdAt,updatedAt:a.updatedAt,allowedTools:a.allowedTools,toolCount:a.allowedTools?.length||0,usageCount:0,lastUsed:void 0}))}}const P=new Pe,y={all:["skills"],lists:()=>[...y.all,"list"],list:t=>[...y.lists(),t],details:()=>[...y.all,"detail"],detail:t=>[...y.details(),t],directory:t=>[...y.all,"directory",t]},Ae=t=>re({queryKey:y.list(t||{}),queryFn:()=>P.getAllSkills(t),staleTime:300*1e3}),Ie=(t,l)=>re({queryKey:y.detail(t),queryFn:()=>P.getSkill(t,l),enabled:!!t,staleTime:300*1e3}),Re=()=>{const t=Z();return X({mutationFn:l=>P.createSkill(l),onSuccess:l=>{t.invalidateQueries({queryKey:y.lists()}),t.setQueryData(y.detail(l.id),l)},onError:l=>{console.error("Failed to create skill:",l)}})},Ue=()=>{const t=Z();return X({mutationFn:({skillId:l,updates:a})=>P.updateSkill(l,a),onSuccess:l=>{t.setQueryData(y.detail(l.id),l),t.invalidateQueries({queryKey:y.lists()})},onError:l=>{console.error("Failed to update skill:",l)}})},Be=()=>{const t=Z();return X({mutationFn:({skillId:l,scope:a})=>P.deleteSkill(l,a),onSuccess:(l,{skillId:a})=>{t.removeQueries({queryKey:y.detail(a)}),t.invalidateQueries({queryKey:y.lists()})},onError:l=>{console.error("Failed to delete skill:",l)}})},Ke=()=>X({mutationFn:t=>P.validateSkillManifest(t),onError:t=>{console.error("Failed to validate skill manifest:",t)}}),We=({onClose:t,onSuccess:l,editSkill:a})=>{const{t:r}=Y(["skills","common"]),n=!!a,[c,p]=x.useState("basic"),[o,m]=x.useState({name:"",description:"",allowedTools:[],content:"",additionalFiles:[]}),[h,k]=x.useState([]),[v,F]=x.useState(""),[D,L]=x.useState(!1),[N,T]=x.useState([]),[g,w]=x.useState([]),[$,A]=x.useState(!1),I=Re(),R=Ue(),M=Ke(),B=Ie(a?.id||"",a?.scope||"user"),S=n?B.data:null,G=n?B.isLoading:!1,[K,U]=x.useState(0),[W,E]=x.useState(0),[d,C]=x.useState(!1);x.useEffect(()=>{if(!d){const s=[...N];$&&s.push(...g),m(i=>({...i,allowedTools:s})),U(Date.now())}},[N,g,$,d]),x.useEffect(()=>{!d&&(o.name||o.description)&&U(Date.now())},[o.name,o.description,d]),x.useEffect(()=>{!d&&o.content&&E(Date.now())},[o.content,d]),x.useEffect(()=>{if(n&&S){m({name:S.name,description:S.description,allowedTools:S.allowedTools||[],content:"",additionalFiles:(S.files||[]).filter(u=>!u.path.endsWith("SKILL.md")).map(u=>({id:Math.random().toString(36).substr(2,9),name:u.name,path:u.path,type:u.type,content:""}))});const s=S.allowedTools||[],i=s.filter(u=>!u.startsWith("mcp__")),b=s.filter(u=>u.startsWith("mcp__"));T(i),w(b),A(b.length>0),(async()=>{try{const u=await fetch(`/api/skills/${a.id}/files/SKILL.md`);if(u.ok){const ge=await u.json();m(pe=>({...pe,content:ge.content})),E(Date.now())}}catch(u){console.error("Failed to load skill manifest:",u)}})()}},[n,S,a]),x.useEffect(()=>{if(o.content){const i=setTimeout(async()=>{try{const b=await M.mutateAsync(o.content);k(b.errors.map(j=>j.message)||[])}catch{k(["Validation failed"])}},500);return()=>clearTimeout(i)}},[o.content,M]);const q=async()=>{try{if(n){const s={name:o.name,description:o.description,allowedTools:o.allowedTools,content:o.content,additionalFiles:o.additionalFiles.map(i=>({name:i.name,path:i.path,type:i.type,content:i.content}))};await R.mutateAsync({skillId:a.id,updates:s})}else{const s={name:o.name,description:o.description,scope:"user",allowedTools:o.allowedTools,content:o.content,additionalFiles:o.additionalFiles.map(i=>({name:i.name,path:i.path,type:i.type,content:i.content}))};await I.mutateAsync(s)}l()}catch(s){console.error(n?"Failed to update skill:":"Failed to create skill:",s),alert(r(n?"errors.updateFailed":"errors.createFailed"))}},O=()=>{const s={id:Math.random().toString(36).substr(2,9),name:"New File",path:"new-file.md",type:"markdown",content:""};m(i=>({...i,additionalFiles:[...i.additionalFiles,s]}))},oe=s=>{m(i=>({...i,additionalFiles:i.additionalFiles.filter(b=>b.id!==s)}))},_=(s,i)=>{m(b=>({...b,additionalFiles:b.additionalFiles.map(j=>j.id===s?{...j,...i}:j)}))},ne=o.name.trim()!==""&&!v&&o.description.trim()!==""&&o.content.trim()!==""&&h.length===0,ie=()=>{switch(c){case"basic":return o.name.trim()!==""&&!v&&o.description.trim()!=="";case"manifest":return o.content.trim()!==""&&h.length===0;case"files":return!0;default:return!1}},ee=()=>{if(!d){if(C(!0),K>W){if(o.name&&o.description){const s=ae(o.name,o.description,o.allowedTools);m(i=>({...i,content:s})),E(Date.now())}}else if(W>K){const s=qe(o.content);if(s&&(s.name&&s.name!==o.name||s.description&&s.description!==o.description||s.allowedTools&&JSON.stringify(s.allowedTools)!==JSON.stringify(o.allowedTools))){m(u=>({...u,name:s.name||u.name,description:s.description||u.description,allowedTools:s.allowedTools||u.allowedTools}));const b=(s.allowedTools||[]).filter(u=>!u.startsWith("mcp__")),j=(s.allowedTools||[]).filter(u=>u.startsWith("mcp__"));T(b),w(j),A(j.length>0),U(Date.now())}}else if(!o.content&&o.name&&o.description){const s=ae(o.name,o.description,o.allowedTools);m(i=>({...i,content:s})),E(Date.now())}setTimeout(()=>C(!1),100)}},de=()=>{ee(),c==="basic"?p("manifest"):c==="manifest"&&p("files")},ce=s=>{ee(),p(s)},xe=[{id:"basic",label:r("create.tabs.basic"),icon:je},{id:"manifest",label:r("create.tabs.manifest"),icon:ve},{id:"files",label:r("create.tabs.files"),icon:Ne}],ue=s=>s?s.length>64?"技能名称不能超过64个字符":/^[a-z0-9-]+$/.test(s)?s.startsWith("-")||s.endsWith("-")?"不能以连字符开始或结束":s.includes("--")?"不能包含连续的连字符":"":"只能使用小写字母、数字和连字符":"",me=s=>{m(i=>({...i,name:s})),F(ue(s))},he=s=>{s.key==="Escape"&&t()};return n&&G?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsx("div",{className:"bg-white rounded-lg p-6 w-full max-w-md",children:e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})})})}):e.jsxs("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",onKeyDown:he,children:[e.jsxs("div",{className:"bg-white rounded-lg w-full max-w-3xl max-h-[90vh] overflow-hidden flex flex-col dark:bg-gray-800 dark:text-white",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:n?`编辑技能 - ${a?.name}`:r("create.title")}),e.jsx("p",{className:"text-sm text-gray-600 mt-1 dark:text-gray-300",children:n?"修改现有技能的配置和功能":r("create.subtitle")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[c!=="files"?e.jsx("button",{onClick:de,disabled:!ie(),className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors dark:bg-blue-500 dark:hover:bg-blue-600",children:r("common:actions.next")}):e.jsx("button",{onClick:q,disabled:!ne||I.isPending||R.isPending,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors dark:bg-blue-500 dark:hover:bg-blue-600",children:I.isPending||R.isPending?r("common:status.saving"):r(n?"common:actions.save":"common:actions.create")}),e.jsx("button",{onClick:t,className:"p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100 rounded-lg transition-colors dark:text-gray-400 dark:hover:text-gray-200 dark:hover:bg-gray-700",children:e.jsx(V,{className:"w-5 h-5"})})]})]}),e.jsx("div",{className:"flex border-b border-gray-200 dark:border-gray-700",children:xe.map(s=>{const i=s.icon,b=c===s.id,j=s.id==="basic"&&o.name.trim()!==""&&o.description.trim()!==""||s.id==="manifest"&&o.content.trim()!==""&&h.length===0||s.id==="files";return e.jsxs("button",{onClick:()=>ce(s.id),className:`flex items-center gap-2 px-6 py-3 font-medium text-sm transition-colors ${b?"text-blue-600 border-b-2 border-blue-600 dark:text-blue-400 dark:border-blue-400":"text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"}`,children:[e.jsx(i,{className:"w-4 h-4"}),s.label,j&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500"})]},s.id)})}),e.jsxs("div",{className:"flex-1 overflow-auto p-6",children:[c==="basic"&&e.jsxs("div",{className:"space-y-6 max-w-2xl",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2 dark:text-gray-300",children:"技能名称 (Slug)"}),e.jsx("input",{type:"text",value:o.name,onChange:s=>me(s.target.value),disabled:n,className:`w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400 dark:focus:ring-blue-400 dark:focus:border-blue-400 font-mono ${n?"bg-gray-100 text-gray-500 cursor-not-allowed dark:bg-gray-600 dark:text-gray-400":v?"border-red-500 focus:ring-red-500 focus:border-red-500":"border-gray-300"}`,placeholder:"my-awesome-skill"}),v?e.jsx("p",{className:"text-xs text-red-500 mt-1 dark:text-red-400",children:v}):e.jsx("p",{className:"text-xs text-gray-500 mt-1 dark:text-gray-400",children:n?"技能名称在编辑模式下不能修改":"只能使用小写字母、数字和连字符,最多64个字符"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2 dark:text-gray-300",children:r("create.basic.description")}),e.jsx("textarea",{value:o.description,onChange:s=>{m(i=>({...i,description:s.target.value}))},rows:3,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none resize-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400 dark:focus:ring-blue-400 dark:focus:border-blue-400",placeholder:r("create.basic.descriptionPlaceholder")}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 dark:text-gray-400",children:r("create.basic.descriptionHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2 dark:text-gray-300",children:r("create.basic.allowedTools")}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("button",{type:"button",onClick:()=>L(!D),className:"px-3 py-2 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 rounded-lg transition-colors text-sm",children:r("create.basic.selectTools")}),(N.length>0||g.length>0)&&e.jsxs("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:["常规工具 ",N.length," 个",g.length>0&&`, MCP工具 ${g.length} 个`]})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 dark:text-gray-400",children:r("create.basic.allowedToolsHint")})]})]}),c==="manifest"&&e.jsx("div",{className:"space-y-6 max-w-2xl",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2 dark:text-gray-300",children:r("create.content.skillManifest")}),e.jsx("textarea",{value:o.content,onChange:s=>m(i=>({...i,content:s.target.value})),rows:15,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none font-mono text-sm resize-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-400 dark:focus:border-blue-400"}),h.length>0&&e.jsxs("div",{className:"mt-2 p-3 bg-red-50 border border-red-200 rounded-lg dark:bg-red-900/20 dark:border-red-800",children:[e.jsxs("h4",{className:"text-sm font-medium text-red-800 mb-1 dark:text-red-400",children:[r("editor.errors.validationErrors"),":"]}),e.jsx("ul",{className:"text-sm text-red-700 space-y-1 dark:text-red-300",children:h.map((s,i)=>e.jsxs("li",{children:["• ",s]},i))})]})]})}),c==="files"&&e.jsxs("div",{className:"space-y-6 max-w-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:r("create.content.additionalFiles")}),e.jsxs("button",{onClick:O,className:"flex items-center gap-2 px-3 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors dark:bg-green-500 dark:hover:bg-green-600",children:[e.jsx(le,{className:"w-4 h-4"}),r("create.content.addFile")]})]}),o.additionalFiles.length===0?e.jsxs("div",{className:"text-center py-8 border-2 border-dashed border-gray-300 rounded-lg",children:[e.jsx("p",{className:"text-gray-600 dark:text-gray-300",children:r("create.content.noFiles")}),e.jsx("p",{className:"text-sm text-gray-500 mt-1 dark:text-gray-400",children:r("create.content.noFilesHint")})]}):e.jsx("div",{className:"space-y-4",children:o.additionalFiles.map(s=>e.jsxs("div",{className:"border border-gray-200 rounded-lg p-4 dark:border-gray-700",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx("input",{type:"text",value:s.name,onChange:i=>_(s.id,{name:i.target.value}),className:"flex-1 px-2 py-1 border border-gray-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-400 dark:focus:border-blue-400",placeholder:r("create.content.fileName")}),e.jsx("input",{type:"text",value:s.path,onChange:i=>_(s.id,{path:i.target.value}),className:"flex-1 px-2 py-1 border border-gray-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none font-mono text-sm dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-400 dark:focus:border-blue-400",placeholder:r("create.content.filePath")}),e.jsxs("select",{value:s.type,onChange:i=>_(s.id,{type:i.target.value}),className:"px-2 py-1 border border-gray-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-400 dark:focus:border-blue-400",children:[e.jsx("option",{value:"markdown",children:r("create.content.fileType.markdown")}),e.jsx("option",{value:"text",children:r("create.content.fileType.text")}),e.jsx("option",{value:"script",children:r("create.content.fileType.script")}),e.jsx("option",{value:"template",children:r("create.content.fileType.template")}),e.jsx("option",{value:"other",children:r("create.content.fileType.other")})]})]}),e.jsx("button",{onClick:()=>oe(s.id),className:"p-1 text-red-500 hover:text-red-700 hover:bg-red-50 rounded transition-colors dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20",children:e.jsx(V,{className:"w-4 h-4"})})]}),e.jsx("textarea",{value:s.content,onChange:i=>_(s.id,{content:i.target.value}),rows:6,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none font-mono text-sm resize-none dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400 dark:focus:ring-blue-400 dark:focus:border-blue-400",placeholder:r("create.content.fileContent")})]},s.id))})]})]})]}),e.jsx(we,{isOpen:D,onClose:()=>L(!1),selectedRegularTools:N,onRegularToolsChange:T,selectedMcpTools:g,onMcpToolsChange:w,mcpToolsEnabled:$,onMcpEnabledChange:A})]})};function qe(t){try{const l=t.match(/^---\s*\n(.*?)\n---/s);if(!l)return null;const r=l[1].split(`
2
2
  `),n={};for(const c of r){const p=c.trim();if(p.startsWith("name:"))n.name=p.replace("name:","").trim();else if(p.startsWith("description:"))n.description=p.replace("description:","").trim();else if(p.startsWith("allowed-tools:")){const o=p.replace("allowed-tools:","").trim();if(o.startsWith("[")&&o.endsWith("]")){const m=o.slice(1,-1).split(",").map(h=>h.trim().replace(/^"(.*)"$/,"$1")).filter(h=>h.length>0);n.allowedTools=m}}}return n}catch(l){return console.error("Failed to parse skill content:",l),null}}function ae(t,l,a){const r=a.length>0?`
3
3
  allowed-tools: [${a.map(c=>`"${c}"`).join(", ")}]`:"",n=t.split("-").map(c=>c.charAt(0).toUpperCase()+c.slice(1)).join(" ");return`---
4
4
  name: ${t}