agentstudio 0.2.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts.map +1 -1
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/{AgentsPage-DpXjvy0I.js → AgentsPage-Cl2yOPj5.js} +1 -1
- package/public/assets/{Button-u4yI-WsV.js → Button-DPVn3zDJ.js} +1 -1
- package/public/assets/{ChatPage-Boj_N_ec.js → ChatPage-BAslLt2l.js} +125 -125
- package/public/assets/{CommandsPage-DJyOtqIu.js → CommandsPage-DakxsAcv.js} +1 -1
- package/public/assets/{DashboardPage-CPyJ0iPo.js → DashboardPage-Dz5tihOs.js} +1 -1
- package/public/assets/{FileBrowser-CXd_LcTz.js → FileBrowser-BXtVLz8h.js} +1 -1
- package/public/assets/{GeneralSettingsPage-BIcZ0Tod.js → GeneralSettingsPage-CWWgquA9.js} +1 -1
- package/public/assets/{LandingPage-BlWek-wg.js → LandingPage-BDKkpXK0.js} +1 -1
- package/public/assets/{LoginPage-j9c0QS1W.js → LoginPage-1PbdWrXW.js} +1 -1
- package/public/assets/{McpAdminSettingsPage-Djm1tHK_.js → McpAdminSettingsPage-BlTO82W3.js} +1 -1
- package/public/assets/{McpPage-DjN_N6XO.js → McpPage-Bix7CnMS.js} +1 -1
- package/public/assets/{MemorySettingsPage-C06mG8J-.js → MemorySettingsPage-Dzq3vCns.js} +1 -1
- package/public/assets/{PluginsPage-C8H1LJqV.js → PluginsPage-oYSGDv3z.js} +1 -1
- package/public/assets/{ProjectSelector-l8LQCZCe.js → ProjectSelector-Bp1q7dra.js} +1 -1
- package/public/assets/ProjectsPage-BKpI8KE2.js +21 -0
- package/public/assets/{ScheduledTasksPage-C9bAZ-8o.js → ScheduledTasksPage-D2rYw_Qf.js} +1 -1
- package/public/assets/{SettingsLayout-Bv4IpkB5.js → SettingsLayout-CfmsuehF.js} +1 -1
- package/public/assets/{SkillsPage-DD-bktLO.js → SkillsPage-D01PYcoW.js} +1 -1
- package/public/assets/{SubagentsPage-BAXwEpQK.js → SubagentsPage-CDaYnbfn.js} +1 -1
- package/public/assets/{SystemInfoPage-41rDcUwB.js → SystemInfoPage-DAeYkq91.js} +1 -1
- package/public/assets/{TelemetrySettingsPage-CyXkNXJH.js → TelemetrySettingsPage-BPuPqJPR.js} +1 -1
- package/public/assets/{ToastTestPage-CtcmP941.js → ToastTestPage-DkZ9D943.js} +1 -1
- package/public/assets/{VersionSettingsPage-BLkrL0Ek.js → VersionSettingsPage-DHUbqInQ.js} +1 -1
- package/public/assets/{WebSocketTunnelPage-McDRE6Ff.js → WebSocketTunnelPage-BGeVdEp8.js} +1 -1
- package/public/assets/{_basePickBy-DDGafuFd.js → _basePickBy-BFNUdIR5.js} +1 -1
- package/public/assets/{_baseUniq-OZ7OoecG.js → _baseUniq-DP62Yq8R.js} +1 -1
- package/public/assets/{arc-C2QxosH7.js → arc-CkNwuwWZ.js} +1 -1
- package/public/assets/{architectureDiagram-VXUJARFQ-gBoRl0vw.js → architectureDiagram-VXUJARFQ-7Ky7pc6T.js} +1 -1
- package/public/assets/{blockDiagram-VD42YOAC-DDJh2Okf.js → blockDiagram-VD42YOAC-Ax8FYBYm.js} +1 -1
- package/public/assets/{c4Diagram-YG6GDRKO-C4b85nLT.js → c4Diagram-YG6GDRKO-CyNR39OO.js} +1 -1
- package/public/assets/channel-BKv1iINC.js +1 -0
- package/public/assets/{chunk-4BX2VUAB--YHjBv7U.js → chunk-4BX2VUAB-zM0Al_rU.js} +1 -1
- package/public/assets/{chunk-55IACEB6-B2-h5gVj.js → chunk-55IACEB6-CCDkr_yY.js} +1 -1
- package/public/assets/{chunk-B4BG7PRW-DRi5viyb.js → chunk-B4BG7PRW-yOb-P7Po.js} +1 -1
- package/public/assets/{chunk-DI55MBZ5-Xk-YhQRJ.js → chunk-DI55MBZ5-zGH8m4eb.js} +1 -1
- package/public/assets/{chunk-FMBD7UC4-DDcnlWsh.js → chunk-FMBD7UC4-DI1MjWfw.js} +1 -1
- package/public/assets/{chunk-QN33PNHL-OXq0iw2q.js → chunk-QN33PNHL-C_FDNT8n.js} +1 -1
- package/public/assets/{chunk-QZHKN3VN-D7P0oOa9.js → chunk-QZHKN3VN-V_K-gce9.js} +1 -1
- package/public/assets/{chunk-TZMSLE5B-Cts6I75U.js → chunk-TZMSLE5B-BnNBbkNq.js} +1 -1
- package/public/assets/{classDiagram-2ON5EDUG-BLM7y3rH.js → classDiagram-2ON5EDUG-DWylXt6j.js} +1 -1
- package/public/assets/{classDiagram-v2-WZHVMYZB-BLM7y3rH.js → classDiagram-v2-WZHVMYZB-DWylXt6j.js} +1 -1
- package/public/assets/clone-BnTQiQb4.js +1 -0
- package/public/assets/{cose-bilkent-S5V4N54A-6uP92_NU.js → cose-bilkent-S5V4N54A-DrNb0vKp.js} +1 -1
- package/public/assets/{dagre-6UL2VRFP-CK2VJLzv.js → dagre-6UL2VRFP-CtKFNLmb.js} +1 -1
- package/public/assets/{diagram-PSM6KHXK-C-ZaY5UR.js → diagram-PSM6KHXK-DpQfOKt-.js} +1 -1
- package/public/assets/{diagram-QEK2KX5R-KM9LoLux.js → diagram-QEK2KX5R-DscZmfZJ.js} +1 -1
- package/public/assets/{diagram-S2PKOQOG-C8uziTLV.js → diagram-S2PKOQOG-UbEZAQ1u.js} +1 -1
- package/public/assets/{erDiagram-Q2GNP2WA-DHFQ6rZ5.js → erDiagram-Q2GNP2WA-mmTcLBrY.js} +1 -1
- package/public/assets/{flowDiagram-NV44I4VS-CzNBOu8h.js → flowDiagram-NV44I4VS-BsIXhV1w.js} +1 -1
- package/public/assets/{ganttDiagram-LVOFAZNH-vqd0zpgi.js → ganttDiagram-LVOFAZNH-CaHkiTYy.js} +1 -1
- package/public/assets/{gitGraphDiagram-NY62KEGX-BOW5S00P.js → gitGraphDiagram-NY62KEGX-B-ctMH3l.js} +1 -1
- package/public/assets/{graph-BP_Rwsef.js → graph-CtuWuGCI.js} +1 -1
- package/public/assets/{index-h5dd40hU.js → index-D9bAK8SN.js} +4 -4
- package/public/assets/{infoDiagram-F6ZHWCRC-LVLvTvsq.js → infoDiagram-F6ZHWCRC-DMsG_8YD.js} +1 -1
- package/public/assets/{journeyDiagram-XKPGCS4Q-Cf_fvy7_.js → journeyDiagram-XKPGCS4Q-XnBAE0k9.js} +1 -1
- package/public/assets/{kanban-definition-3W4ZIXB7-u6UccFfM.js → kanban-definition-3W4ZIXB7-DY1J_CQA.js} +1 -1
- package/public/assets/{layout-sH_TKNrG.js → layout-BBAqRBns.js} +1 -1
- package/public/assets/{linear-BdE0kKFb.js → linear-DXGOqRyX.js} +1 -1
- package/public/assets/{mindmap-definition-VGOIOE7T-9d-rVW5A.js → mindmap-definition-VGOIOE7T-D8LYlQnr.js} +1 -1
- package/public/assets/{pieDiagram-ADFJNKIX-U_y5PbGf.js → pieDiagram-ADFJNKIX-DqZw-HeQ.js} +1 -1
- package/public/assets/{quadrantDiagram-AYHSOK5B-DGb0hrEb.js → quadrantDiagram-AYHSOK5B-CfjEkg6d.js} +1 -1
- package/public/assets/{requirementDiagram-UZGBJVZJ-DNTHnK1t.js → requirementDiagram-UZGBJVZJ-CEbDefgn.js} +1 -1
- package/public/assets/{sankeyDiagram-TZEHDZUN-5uBZF1V2.js → sankeyDiagram-TZEHDZUN-DOU4OJks.js} +1 -1
- package/public/assets/{sequenceDiagram-WL72ISMW-AeCHCuPt.js → sequenceDiagram-WL72ISMW-BmjWQ4oi.js} +1 -1
- package/public/assets/{stateDiagram-FKZM4ZOC-CXM0ycgk.js → stateDiagram-FKZM4ZOC-C7lI7uz2.js} +1 -1
- package/public/assets/{stateDiagram-v2-4FDKWEC3-FWopaxaM.js → stateDiagram-v2-4FDKWEC3-C8Eo5YFb.js} +1 -1
- package/public/assets/{table-CUyJSNAf.js → table-F592JIUY.js} +1 -1
- package/public/assets/{timeline-definition-IT6M3QCI-BXZLvFn7.js → timeline-definition-IT6M3QCI-BltidY3A.js} +1 -1
- package/public/assets/{treemap-KMMF4GRG-BcB7MUc4.js → treemap-KMMF4GRG-CXskbtZo.js} +1 -1
- package/public/assets/{xychartDiagram-PRI3JC2R-BsE7x9kD.js → xychartDiagram-PRI3JC2R-Bk3p1DGz.js} +1 -1
- package/public/index.html +1 -1
- package/routes/a2a.d.ts.map +1 -1
- package/routes/a2a.js +15 -4
- package/routes/a2a.js.map +1 -1
- package/routes/agents.d.ts.map +1 -1
- package/routes/agents.js +15 -3
- package/routes/agents.js.map +1 -1
- package/routes/network.d.ts +9 -0
- package/routes/network.d.ts.map +1 -0
- package/routes/network.js +60 -0
- package/routes/network.js.map +1 -0
- package/services/a2a/__tests__/a2aClientTool.test.js +174 -0
- package/services/a2a/__tests__/a2aClientTool.test.js.map +1 -1
- package/services/a2a/a2aClientTool.js +28 -7
- package/services/a2a/a2aClientTool.js.map +1 -1
- package/services/projectMetadataStorage.d.ts.map +1 -1
- package/services/projectMetadataStorage.js +2 -0
- package/services/projectMetadataStorage.js.map +1 -1
- package/services/sessionManager.d.ts +32 -2
- package/services/sessionManager.d.ts.map +1 -1
- package/services/sessionManager.js +88 -2
- package/services/sessionManager.js.map +1 -1
- package/services/slackAIService.d.ts.map +1 -1
- package/services/slackAIService.js +27 -6
- package/services/slackAIService.js.map +1 -1
- package/services/taskExecutor/taskWorker.js +4 -3
- package/services/taskExecutor/taskWorker.js.map +1 -1
- package/services/tunnelService.d.ts +15 -0
- package/services/tunnelService.d.ts.map +1 -1
- package/services/tunnelService.js +81 -0
- package/services/tunnelService.js.map +1 -1
- package/types/projects.d.ts +2 -0
- package/types/projects.d.ts.map +1 -1
- package/utils/claudeUtils.d.ts.map +1 -1
- package/utils/claudeUtils.js +2 -1
- package/utils/claudeUtils.js.map +1 -1
- package/utils/networkUtils.d.ts +25 -0
- package/utils/networkUtils.d.ts.map +1 -0
- package/utils/networkUtils.js +65 -0
- package/utils/networkUtils.js.map +1 -0
- package/utils/sessionUtils.d.ts +5 -2
- package/utils/sessionUtils.d.ts.map +1 -1
- package/utils/sessionUtils.js +34 -9
- package/utils/sessionUtils.js.map +1 -1
- package/public/assets/ProjectsPage-DVGpii1H.js +0 -21
- package/public/assets/channel-4mgiaMWd.js +0 -1
- package/public/assets/clone-BHGNnQ0D.js +0 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import{j as e}from"./data-structures-C0h9Oap1.js";import{r as o,W as Be}from"./monaco-editor-DHKm5-VF.js";import{a as P,A as E}from"./agents-DG431Wop.js";import{s as Z,a as I,b as We}from"./index-D9bAK8SN.js";import{f as ue}from"./dateFormat-CXa8VnEC.js";import{u as me}from"./tools-C0JOzoE_.js";import{a4 as He,aI as _e,t as ee,a2 as pe,r as Ce,y as te,M as Ye,k as ft,u as Le,aJ as Je,a5 as De,e as Nt,X as _,j as be,a3 as kt,T as wt,g as Re,v as xe,o as qe,D as Me,m as Ue,J as Ae,a7 as ye,A as Ie,ay as Ve,I as ce,aK as se,a8 as vt,E as Ct,aL as Fe,aM as Mt,aN as At,U as St,ad as Ge,z as Ke,_ as $t,f as Pt}from"./ui-components-CRCmgMKc.js";import{u as Et}from"./useAgents-Bp5Ry-Dk.js";import{F as Qe}from"./FileBrowser-BXtVLz8h.js";import{T as Xe,a as Ze,b as Se,c as Y,d as et,e as Q}from"./table-F592JIUY.js";import{f as Tt,g as It}from"./useCommands-B0s3JzZs.js";import{C as Ft}from"./CommandForm-C8RL-p7h.js";import{g as $e}from"./UnifiedToolSelector-CKjY_qjS.js";import{b as Kt,c as Dt,S as Ut}from"./SubagentForm-CSRBsxUE.js";import{u as Lt}from"./useProjects-DuCnMeYt.js";import{u as Rt}from"./useClaudeVersions-DYM2HCGW.js";import"./syntax-highlighting-CnREyncB.js";const zt=({projects:l,agents:M,onOpenProject:t,onMemoryManagement:r,onCommandManagement:p,onSubAgentManagement:u,onA2AManagement:w,onSettings:y,onDeleteProject:v,onAgentChanged:h,className:A=""})=>{const{t:g}=me("pages"),[c,j]=o.useState(null),F=async(d,m)=>{if(m!==d.defaultAgent)try{j(d.id);const S=await P(`${E}/projects/${encodeURIComponent(d.path)}/default-agent`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentId:m})});if(S.ok){const C=M.find(B=>B.id===m);C&&h&&h(d.id,C),Z("助手切换成功")}else{const C=await S.json();throw new Error(C.error||"切换助手失败")}}catch(S){console.error("Failed to change agent:",S),I("切换助手失败",S instanceof Error?S.message:"未知错误")}finally{j(null)}},U=(d,m=!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(d),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 ${m?"text-base":""}`,children:d.name}),e.jsx("button",{onClick:()=>t(d),className:"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors flex-shrink-0",title:g("projects.actions.open"),children:e.jsx(Ye,{className:"w-3 h-3"})})]}),d.description&&e.jsx("div",{className:`text-gray-500 dark:text-gray-400 truncate ${m?"text-sm mt-1":"text-sm max-w-xs"}`,children:d.description})]}),R=d=>{const m=M.filter(C=>C.enabled),S=c===d.id;return e.jsxs("div",{className:"relative inline-block",onClick:C=>C.stopPropagation(),children:[e.jsx("select",{value:d.defaultAgent,onChange:C=>F(d,C.target.value),disabled:S,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:m.map(C=>e.jsxs("option",{value:C.id,className:"bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100",children:[C.ui.icon," ",C.name]},C.id))}),e.jsx(ft,{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"})]})},K=d=>e.jsxs("div",{className:"flex items-center space-x-2 text-sm text-gray-500 dark:text-gray-400",children:[e.jsx(Le,{className:"w-4 h-4"}),e.jsx("span",{className:"truncate",title:d.path,children:d.path})]}),O=(d,m)=>e.jsxs("div",{className:"flex items-center space-x-1 text-sm text-gray-500 dark:text-gray-400",children:[m,e.jsx("span",{children:ue(d)})]}),x=d=>e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx("button",{onClick:()=>r(d),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:g("components:projectMemory.title"),children:e.jsx(He,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>p(d),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:g("components:projectCommands.title"),children:e.jsx(_e,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>u(d),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:g("components:projectSubAgents.title"),children:e.jsx(ee,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>w(d),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(pe,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>y(d),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(Ce,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>v(d),className:"p-1.5 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded-md transition-colors",title:g("projects.actions.delete"),children:e.jsx(te,{className:"w-3.5 h-3.5"})})]});return e.jsxs("div",{className:`space-y-4 ${A}`,children:[e.jsx("div",{className:"md:hidden space-y-4",children:l.map(d=>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(d),children:e.jsx("div",{className:"flex items-start space-x-3",children:U(d,!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:[g("projects.table.agent"),":"]}),e.jsx("div",{children:R(d)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[g("projects.table.lastActive"),":"]}),e.jsx("div",{className:"text-right",children:O(d.lastAccessed,e.jsx(Je,{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:[g("common:path"),":"]}),e.jsx("div",{className:"text-right text-xs truncate ml-2 max-w-[200px]",children:d.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:g("projects.table.actions")}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("button",{onClick:()=>r(d),className:"p-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:g("components:projectMemory.title"),children:e.jsx(He,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>p(d),className:"p-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:g("components:projectCommands.title"),children:e.jsx(_e,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>u(d),className:"p-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors",title:g("components:projectSubAgents.title"),children:e.jsx(ee,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>w(d),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(pe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>y(d),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(Ce,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>v(d),className:"p-2 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded-md transition-colors",title:g("projects.actions.delete"),children:e.jsx(te,{className:"w-4 h-4"})})]})]})})]},d.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:g("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:g("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:g("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:g("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:g("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:g("projects.table.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:l.map((d,m)=>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(d)})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap w-32",children:R(d)}),e.jsx("td",{className:"px-6 py-4 max-w-xs truncate",children:K(d)}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400 w-32",children:O(d.createdAt,e.jsx(De,{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:O(d.lastAccessed,e.jsx(Je,{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:x(d)})]},d.id+"-"+m))})]})})]})},Ot=({project:l,onClose:M})=>{const[t,r]=o.useState(""),[p,u]=o.useState(!0),[w,y]=o.useState(!1),[v,h]=o.useState(null);o.useEffect(()=>{(async()=>{try{u(!0),h(null);const c=await P(`${E}/projects/claude-md?path=${encodeURIComponent(l.path)}`);if(c.ok){const j=await c.json();r(j.content||"")}else if(c.status===404)r("");else throw new Error("加载 CLAUDE.md 文件失败")}catch(c){console.error("Failed to load CLAUDE.md:",c),h(c instanceof Error?c.message:"未知错误")}finally{u(!1)}})()},[l.id]);const A=async()=>{try{if(y(!0),h(null),!(await P(`${E}/projects/claude-md?path=${encodeURIComponent(l.path)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})})).ok)throw new Error("保存 CLAUDE.md 文件失败");const c=document.getElementById("save-button");if(c){const j=c.textContent;c.textContent="已保存",setTimeout(()=>{c.textContent==="已保存"&&(c.textContent=j)},2e3)}}catch(g){console.error("Failed to save CLAUDE.md:",g),h(g instanceof Error?g.message:"保存失败")}finally{y(!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(Nt,{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:l.name})]})]}),e.jsx("button",{onClick:M,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors",children:e.jsx(_,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex-1 flex flex-col p-6 overflow-hidden",children:p?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..."})]})}):v?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(be,{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:v})]})}):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:g=>r(g.target.value),placeholder:`# 项目记忆
|
|
2
|
+
|
|
3
|
+
此文件用于存储项目相关的上下文信息、开发指导和重要注意事项。
|
|
4
|
+
|
|
5
|
+
## 项目概述
|
|
6
|
+
描述项目的主要功能和目标...
|
|
7
|
+
|
|
8
|
+
## 开发规范
|
|
9
|
+
记录代码规范、架构决策等...
|
|
10
|
+
|
|
11
|
+
## 重要注意事项
|
|
12
|
+
记录需要特别注意的地方...`,className:"w-full h-full p-4 border-0 resize-none focus:outline-none font-mono text-sm dark:bg-gray-700 dark:text-white dark:placeholder-gray-400",style:{minHeight:"400px"}})})]})}),!p&&!v&&e.jsxs("div",{className:"flex justify-end space-x-3 p-6 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900",children:[e.jsx("button",{onClick:M,className:"px-4 py-2 text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors",children:"取消"}),e.jsxs("button",{id:"save-button",onClick:A,disabled:w,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 flex items-center space-x-2",children:[w?e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-white border-t-transparent"}):e.jsx(kt,{className:"w-4 h-4"}),e.jsx("span",{children:w?"保存中...":"保存"})]})]})]})})},Bt=({project:l,onClose:M})=>{const{t}=me("components"),{isMobile:r}=We(),[p,u]=o.useState(""),[w,y]=o.useState(!1),[v,h]=o.useState(null),[A,g]=o.useState(null),{data:c=[],isLoading:j,error:F,refetch:U}=Tt({projectId:l.id,search:p.trim()||void 0}),R=It(l.id),K=async x=>{try{await R.mutateAsync(x.id),g(null),U()}catch(d){console.error("Failed to delete command:",d)}},O=()=>{y(!1),h(null),U()};return j?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-6xl h-[80vh] 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:t("projectCommandsModal.loading")})]})})}):F?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-6xl h-[80vh] flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(be,{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:t("projectCommandsModal.error.title")}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-4",children:t("projectCommandsModal.error.message")}),e.jsxs("div",{className:"flex justify-center space-x-3",children:[e.jsx("button",{onClick:()=>U(),className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:t("projectCommandsModal.error.retry")}),e.jsx("button",{onClick:M,className:"px-4 py-2 text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors",children:t("projectCommandsModal.error.close")})]})]})})}):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 ${r?"max-w-full h-[95vh]":"max-w-6xl h-[80vh]"} flex flex-col`,children:[e.jsx("div",{className:`${r?"p-4":"p-6"} border-b border-gray-200 dark:border-gray-700`,children:e.jsxs("div",{className:`flex items-center ${r?"space-x-2":"space-x-3"}`,children:[e.jsx(wt,{className:`${r?"w-5 h-5":"w-6 h-6"} text-green-600`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h2",{className:`${r?"text-lg":"text-xl"} font-semibold text-gray-900 dark:text-white truncate`,children:t("projectCommandsModal.title")}),e.jsx("p",{className:`${r?"text-xs":"text-sm"} text-gray-600 dark:text-gray-400 truncate`,children:l.name})]}),e.jsx("button",{onClick:M,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors flex-shrink-0",children:e.jsx(_,{className:`${r?"w-4 h-4":"w-5 h-5"}`})})]})}),e.jsx("div",{className:`${r?"p-4":"p-6"} border-b border-gray-200 dark:border-gray-700`,children:e.jsxs("div",{className:`${r?"space-y-3":"flex items-center space-x-4"}`,children:[e.jsxs("div",{className:r?"":"flex-1 relative",children:[e.jsx(Re,{className:`absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 ${r?"w-4 h-4":"w-5 h-5"}`}),e.jsx("input",{type:"text",placeholder:t("projectCommandsModal.searchPlaceholder"),value:p,onChange:x=>u(x.target.value),className:`pl-10 pr-4 py-2 w-full 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 dark:placeholder-gray-400 ${r?"text-sm":""}`})]}),e.jsxs("button",{onClick:()=>{h(null),y(!0)},className:`${r?"w-full py-2.5 px-4 flex items-center justify-center space-x-2":"flex items-center space-x-2 px-4 py-2"} bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors whitespace-nowrap ${r?"text-sm":""}`,children:[e.jsx(xe,{className:"w-4 h-4"}),e.jsx("span",{children:t("projectCommandsModal.createButton")})]})]})}),e.jsx("div",{className:"flex-1 overflow-auto",children:c.length===0?e.jsxs("div",{className:`text-center ${r?"py-8":"py-16"}`,children:[e.jsx("div",{className:`${r?"text-4xl":"text-6xl"} mb-4`,children:"⚡"}),e.jsx("h3",{className:`${r?"text-lg":"text-xl"} font-medium text-gray-900 dark:text-white mb-2`,children:t(p?"projectCommandsModal.emptyState.noMatchTitle":"projectCommandsModal.emptyState.noCommandsTitle")}),e.jsx("p",{className:`text-gray-600 dark:text-gray-400 ${r?"mb-4":"mb-6"}`,children:t(p?"projectCommandsModal.emptyState.noMatchDescription":"projectCommandsModal.emptyState.noCommandsDescription")}),!p&&e.jsx("button",{onClick:()=>{h(null),y(!0)},className:`${r?"w-full py-3 px-4":"px-6 py-3"} bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors`,children:t("projectCommandsModal.createButton")})]}):e.jsx(e.Fragment,{children:r?e.jsx("div",{className:"p-4 space-y-4",children:c.map((x,d)=>e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[e.jsxs("div",{className:"flex items-start space-x-3 mb-3",children:[e.jsx("div",{className:"text-xl mr-3",children:"⚡"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-base font-medium text-gray-900 dark:text-white mb-1",children:[x.namespace?`/${x.namespace}:${x.name}`:`/${x.name}`,x.argumentHint&&e.jsx("code",{className:"ml-2 bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-300 px-1.5 py-0.5 rounded text-xs",children:x.argumentHint})]}),x.description&&e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:x.description})]})]}),e.jsxs("div",{className:"space-y-2 mb-4",children:[e.jsxs("div",{className:"flex items-center text-sm",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 mr-2",children:[t("projectCommandsModal.table.model"),":"]}),x.model?e.jsxs("div",{className:"flex items-center text-gray-900 dark:text-white",children:[e.jsx(qe,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-sm",children:x.model})]}):e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:t("projectCommandsModal.table.inheritSettings")})]}),e.jsxs("div",{className:"flex items-start text-sm",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 mr-2 mt-1",children:[t("projectCommandsModal.table.tools"),":"]}),x.allowedTools&&x.allowedTools.length>0?e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center space-x-1 text-gray-500 dark:text-gray-400 mb-1",children:[e.jsx(Me,{className:"w-3 h-3"}),e.jsx("span",{className:"text-xs",children:t("projectCommandsModal.table.toolsCount",{count:x.allowedTools.length})})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:x.allowedTools.map((m,S)=>e.jsx("code",{className:"bg-green-50 dark:bg-green-900/30 text-green-700 dark:text-green-400 px-1.5 py-0.5 rounded text-xs",children:$e(m)},S))})]}):e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:t("projectCommandsModal.table.inheritSettings")})]}),e.jsxs("div",{className:"flex items-center text-sm",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 mr-2",children:[t("projectCommandsModal.table.createdAt"),":"]}),e.jsxs("div",{className:"flex items-center text-gray-500 dark:text-gray-400",children:[e.jsx(Ue,{className:"w-4 h-4 mr-1"}),e.jsx("span",{children:ue(x.createdAt||x.updatedAt)})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end space-x-2 pt-3 border-t border-gray-200 dark:border-gray-700",children:[e.jsxs("button",{onClick:()=>{h(x),y(!0)},className:"inline-flex items-center px-3 py-2 text-sm font-medium text-blue-600 bg-blue-50 dark:bg-blue-900/50 rounded-md hover:bg-blue-100 dark:hover:bg-blue-900/70 transition-colors",children:[e.jsx(Ae,{className:"w-3 h-3 mr-1"}),t("projectCommandsModal.actions.edit")]}),e.jsx("button",{onClick:()=>g(x),className:"p-2 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded-lg transition-colors",title:t("projectCommandsModal.actions.deleteTooltip"),children:e.jsx(te,{className:"w-4 h-4"})})]})]},x.id+"-"+d))}):e.jsxs(Xe,{children:[e.jsx(Ze,{children:e.jsxs(Se,{children:[e.jsx(Y,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:t("projectCommandsModal.table.command")}),e.jsx(Y,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:t("projectCommandsModal.table.model")}),e.jsx(Y,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:t("projectCommandsModal.table.tools")}),e.jsx(Y,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:t("projectCommandsModal.table.createdAt")}),e.jsx(Y,{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:t("projectCommandsModal.table.actions")})]})}),e.jsx(et,{children:c.map((x,d)=>e.jsxs(Se,{className:"hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors",children:[e.jsx(Q,{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"text-xl mr-3",children:"⚡"}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:[x.namespace?`/${x.namespace}:${x.name}`:`/${x.name}`,x.argumentHint&&e.jsx("code",{className:"ml-2 bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200 px-1.5 py-0.5 rounded text-xs",children:x.argumentHint})]}),x.description&&e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 truncate max-w-xs",children:x.description})]})]})}),e.jsx(Q,{className:"px-6 py-4",children:x.model?e.jsxs("div",{className:"text-sm text-gray-900 dark:text-white",children:[e.jsx(qe,{className:"w-3 h-3 inline mr-1"}),x.model]}):e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:t("projectCommandsModal.table.inheritSettings")})}),e.jsx(Q,{className:"px-6 py-4",children:x.allowedTools&&x.allowedTools.length>0?e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-1 text-sm text-gray-500 dark:text-gray-400 mb-1",children:[e.jsx(Me,{className:"w-3 h-3"}),e.jsx("span",{children:t("projectCommandsModal.table.toolsCount",{count:x.allowedTools.length})})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:x.allowedTools.map((m,S)=>e.jsx("code",{className:"bg-green-50 dark:bg-green-900/30 text-green-700 dark:text-green-400 px-1.5 py-0.5 rounded text-xs",children:$e(m)},S))})]}):e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:t("projectCommandsModal.table.inheritSettings")})}),e.jsx(Q,{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400",children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(Ue,{className:"w-4 h-4"}),e.jsx("span",{children:ue(x.createdAt||x.updatedAt)})]})}),e.jsx(Q,{className:"px-6 py-4 whitespace-nowrap text-right text-sm font-medium",children:e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsxs("button",{onClick:()=>{h(x),y(!0)},className:"inline-flex items-center px-3 py-1.5 text-xs font-medium text-blue-600 bg-blue-50 rounded-md hover:bg-blue-100 transition-colors",title:t("projectCommandsModal.actions.editTooltip"),children:[e.jsx(Ae,{className:"w-3 h-3 mr-1"}),t("projectCommandsModal.actions.edit")]}),e.jsx("button",{onClick:()=>g(x),className:"p-2 text-red-600 hover:bg-red-50 rounded-lg transition-colors",title:t("projectCommandsModal.actions.deleteTooltip"),children:e.jsx(te,{className:"w-4 h-4"})})]})})]},x.id+"-"+d))})]})})}),w&&e.jsx(Ft,{command:v,projectId:l.id,onClose:()=>{y(!1),h(null)},onSuccess:O}),A&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[60] p-4",children:e.jsxs("div",{className:`bg-white dark:bg-gray-800 rounded-lg shadow-xl ${r?"w-full max-w-sm":"max-w-md w-full mx-4"} p-6`,children:[e.jsxs("div",{className:"flex items-center space-x-3 mb-4",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(be,{className:`${r?"h-5 w-5":"h-6 w-6"} text-red-600`})}),e.jsx("div",{className:"flex-1",children:e.jsx("h3",{className:`${r?"text-base":"text-lg"} font-medium text-gray-900 dark:text-white`,children:t("projectCommandsModal.deleteConfirm.title")})})]}),e.jsx("p",{className:`${r?"text-sm mb-4":"mb-6"} text-gray-600 dark:text-gray-400`,children:t("projectCommandsModal.deleteConfirm.message",{name:A.name})}),e.jsxs("div",{className:`${r?"grid grid-cols-2 gap-2":"flex justify-end space-x-3"}`,children:[e.jsx("button",{onClick:()=>g(null),className:`${r?"px-3 py-2.5 text-sm":"px-4 py-2"} text-gray-700 dark:text-gray-300 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 rounded-lg transition-colors`,children:t("projectCommandsModal.deleteConfirm.cancel")}),e.jsx("button",{onClick:()=>K(A),disabled:R.isPending,className:`${r?"px-3 py-2.5 text-sm":"px-4 py-2"} bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors disabled:opacity-50`,children:R.isPending?t("projectCommandsModal.deleteConfirm.deleting"):t("projectCommandsModal.deleteConfirm.confirm")})]})]})})]})})},Ht=({project:l,onClose:M})=>{const{t}=me("components"),{isMobile:r}=We(),[p,u]=o.useState(""),[w,y]=o.useState(!1),[v,h]=o.useState(null),[A,g]=o.useState(null),{data:c=[],isLoading:j,error:F,refetch:U}=Kt({projectId:l.id,search:p.trim()||void 0}),R=Dt(l.id),K=async m=>{try{await R.mutateAsync(m.id),g(null),U()}catch(S){console.error("Failed to delete subagent:",S)}},O=m=>{h(m),y(!0)},x=()=>{y(!1),h(null)},d=()=>{U(),y(!1),h(null)};return j?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsx("div",{className:`bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full ${r?"max-w-full h-[95vh]":"max-w-6xl h-[80vh]"} 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:t("projectSubAgentsModal.loading")})]})})}):F?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsx("div",{className:`bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full ${r?"max-w-full h-[95vh]":"max-w-6xl h-[80vh]"} flex items-center justify-center`,children:e.jsxs("div",{className:`text-center ${r?"px-6":""}`,children:[e.jsx(be,{className:`${r?"h-10 w-10":"h-12 w-12"} text-red-500 mx-auto mb-4`}),e.jsx("h3",{className:`${r?"text-base":"text-lg"} font-medium text-gray-900 dark:text-white mb-2`,children:t("projectSubAgentsModal.error.loadFailed")}),e.jsx("p",{className:`${r?"text-sm":""} text-gray-600 dark:text-gray-400 mb-4`,children:t("projectSubAgentsModal.error.loadFailedMessage")}),e.jsxs("div",{className:`${r?"grid grid-cols-2 gap-2":"flex justify-center space-x-3"}`,children:[e.jsx("button",{onClick:()=>U(),className:`${r?"px-3 py-2.5 text-sm":"px-4 py-2"} bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors`,children:t("projectSubAgentsModal.actions.retry")}),e.jsx("button",{onClick:M,className:`${r?"px-3 py-2.5 text-sm":"px-4 py-2"} text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors`,children:t("projectSubAgentsModal.actions.close")})]})]})})}):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 ${r?"max-w-full h-[95vh]":"max-w-6xl h-[80vh]"} flex flex-col`,children:[e.jsx("div",{className:`${r?"p-4":"p-6"} border-b border-gray-200 dark:border-gray-700`,children:e.jsxs("div",{className:`flex items-center ${r?"space-x-2":"space-x-3"}`,children:[e.jsx(ee,{className:`${r?"w-5 h-5":"w-6 h-6"} text-purple-600`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h2",{className:`${r?"text-lg":"text-xl"} font-semibold text-gray-900 dark:text-white truncate`,children:t("projectSubAgentsModal.title")}),e.jsx("p",{className:`${r?"text-xs":"text-sm"} text-gray-600 dark:text-gray-400 truncate`,children:l.name})]}),e.jsx("button",{onClick:M,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors flex-shrink-0",children:e.jsx(_,{className:`${r?"w-4 h-4":"w-5 h-5"}`})})]})}),e.jsx("div",{className:`${r?"p-4":"p-6"} border-b border-gray-200 dark:border-gray-700`,children:e.jsxs("div",{className:`${r?"space-y-3":"flex items-center space-x-4"}`,children:[e.jsxs("div",{className:r?"":"flex-1 relative",children:[e.jsx(Re,{className:`absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 ${r?"w-4 h-4":"w-5 h-5"}`}),e.jsx("input",{type:"text",placeholder:t("projectSubAgentsModal.searchPlaceholder"),value:p,onChange:m=>u(m.target.value),className:`pl-10 pr-4 py-2 w-full 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 dark:placeholder-gray-400 ${r?"text-sm":""}`})]}),e.jsxs("button",{onClick:()=>{h(null),y(!0)},className:`${r?"w-full py-2.5 px-4 flex items-center justify-center space-x-2":"flex items-center space-x-2 px-4 py-2"} bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors whitespace-nowrap ${r?"text-sm":""}`,children:[e.jsx(xe,{className:"w-4 h-4"}),e.jsx("span",{children:t("projectSubAgentsModal.actions.create")})]})]})}),e.jsx("div",{className:"flex-1 overflow-auto",children:c.length===0?e.jsxs("div",{className:`text-center ${r?"py-8":"py-16"}`,children:[e.jsx("div",{className:`${r?"text-4xl":"text-6xl"} mb-4`,children:"🤖"}),e.jsx("h3",{className:`${r?"text-lg":"text-xl"} font-medium text-gray-900 dark:text-white mb-2`,children:t(p?"projectSubAgentsModal.emptyState.noResults":"projectSubAgentsModal.emptyState.noSubagents")}),e.jsx("p",{className:`text-gray-600 dark:text-gray-400 ${r?"mb-4":"mb-6"}`,children:t(p?"projectSubAgentsModal.emptyState.tryAdjust":"projectSubAgentsModal.emptyState.description")}),!p&&e.jsx("button",{onClick:()=>{h(null),y(!0)},className:`${r?"w-full py-3 px-4":"px-6 py-3"} bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors`,children:t("projectSubAgentsModal.actions.create")})]}):e.jsx(e.Fragment,{children:r?e.jsx("div",{className:"p-4 space-y-4",children:c.map((m,S)=>e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[e.jsxs("div",{className:"flex items-start space-x-3 mb-3",children:[e.jsx("div",{className:"text-xl mr-3",children:"🤖"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-base font-medium text-gray-900 dark:text-white mb-1",children:m.name}),m.description&&e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:m.description})]})]}),e.jsxs("div",{className:"space-y-2 mb-4",children:[e.jsxs("div",{className:"flex items-start text-sm",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 mr-2 mt-1",children:[t("projectSubAgentsModal.table.tools"),":"]}),m.tools&&m.tools.length>0?e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center space-x-1 text-gray-500 dark:text-gray-400 mb-1",children:[e.jsx(Me,{className:"w-3 h-3"}),e.jsx("span",{className:"text-xs",children:t("projectSubAgentsModal.table.toolsCount",{count:m.tools.length})})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:m.tools.map((C,B)=>e.jsx("code",{className:"bg-green-50 dark:bg-green-900/30 text-green-700 dark:text-green-400 px-1.5 py-0.5 rounded text-xs",children:$e(C)},B))})]}):e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:t("projectSubAgentsModal.table.inheritSettings")})]}),e.jsxs("div",{className:"flex items-center text-sm",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400 mr-2",children:[t("projectSubAgentsModal.table.createdAt"),":"]}),e.jsxs("div",{className:"flex items-center text-gray-500 dark:text-gray-400",children:[e.jsx(De,{className:"w-4 h-4 mr-1"}),e.jsx("span",{children:ue(m.createdAt)})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end space-x-2 pt-3 border-t border-gray-200 dark:border-gray-700",children:[e.jsxs("button",{onClick:()=>O(m),className:"inline-flex items-center px-3 py-2 text-sm font-medium text-blue-600 bg-blue-50 dark:bg-blue-900/50 rounded-md hover:bg-blue-100 dark:hover:bg-blue-900/70 transition-colors",children:[e.jsx(Ae,{className:"w-3 h-3 mr-1"}),t("projectSubAgentsModal.actions.edit")]}),e.jsx("button",{onClick:()=>g(m),className:"p-2 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded-lg transition-colors",title:t("projectSubAgentsModal.actions.deleteTooltip"),children:e.jsx(te,{className:"w-4 h-4"})})]})]},m.id+"-"+S))}):e.jsxs(Xe,{children:[e.jsx(Ze,{children:e.jsxs(Se,{children:[e.jsx(Y,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:t("projectSubAgentsModal.table.subagent")}),e.jsx(Y,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:t("projectSubAgentsModal.table.tools")}),e.jsx(Y,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:t("projectSubAgentsModal.table.createdAt")}),e.jsx(Y,{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:t("projectSubAgentsModal.table.actions")})]})}),e.jsx(et,{children:c.map((m,S)=>e.jsxs(Se,{className:"hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors",children:[e.jsx(Q,{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"text-xl mr-3",children:"🤖"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:m.name}),m.description&&e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 truncate max-w-xs",children:m.description})]})]})}),e.jsx(Q,{className:"px-6 py-4",children:m.tools&&m.tools.length>0?e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-1 text-sm text-gray-500 dark:text-gray-400 mb-1",children:[e.jsx(Me,{className:"w-3 h-3"}),e.jsx("span",{children:t("projectSubAgentsModal.table.toolsCount",{count:m.tools.length})})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:m.tools.map((C,B)=>e.jsx("code",{className:"bg-green-50 dark:bg-green-900/30 text-green-700 dark:text-green-400 px-1.5 py-0.5 rounded text-xs",children:$e(C)},B))})]}):e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:t("projectSubAgentsModal.table.inheritSettings")})}),e.jsx(Q,{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400",children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(De,{className:"w-4 h-4"}),e.jsx("span",{children:ue(m.createdAt)})]})}),e.jsx(Q,{className:"px-6 py-4 whitespace-nowrap text-right text-sm font-medium",children:e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsxs("button",{onClick:()=>O(m),className:"inline-flex items-center px-3 py-1.5 text-xs font-medium text-blue-600 bg-blue-50 rounded-md hover:bg-blue-100 transition-colors",title:t("projectSubAgentsModal.actions.editTooltip"),children:[e.jsx(Ae,{className:"w-3 h-3 mr-1"}),t("projectSubAgentsModal.actions.edit")]}),e.jsx("button",{onClick:()=>g(m),className:"p-2 text-red-600 hover:bg-red-50 rounded-lg transition-colors",title:t("projectSubAgentsModal.actions.deleteTooltip"),children:e.jsx(te,{className:"w-4 h-4"})})]})})]},m.id+"-"+S))})]})})}),w&&e.jsx(Ut,{subagent:v,projectId:l.id,onClose:x,onSuccess:d}),A&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[60] p-4",children:e.jsxs("div",{className:`bg-white dark:bg-gray-800 rounded-lg shadow-xl ${r?"w-full max-w-sm":"max-w-md w-full mx-4"} p-6`,children:[e.jsxs("div",{className:"flex items-center space-x-3 mb-4",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(be,{className:`${r?"h-5 w-5":"h-6 w-6"} text-red-600`})}),e.jsx("div",{className:"flex-1",children:e.jsx("h3",{className:`${r?"text-base":"text-lg"} font-medium text-gray-900 dark:text-white`,children:t("projectSubAgentsModal.deleteConfirm.title")})})]}),e.jsx("p",{className:`${r?"text-sm mb-4":"mb-6"} text-gray-600 dark:text-gray-400`,children:t("projectSubAgentsModal.deleteConfirm.message",{name:A.name})}),e.jsxs("div",{className:`${r?"grid grid-cols-2 gap-2":"flex justify-end space-x-3"}`,children:[e.jsx("button",{onClick:()=>g(null),className:`${r?"px-3 py-2.5 text-sm":"px-4 py-2"} text-gray-700 dark:text-gray-300 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 rounded-lg transition-colors`,children:t("projectSubAgentsModal.actions.cancel")}),e.jsx("button",{onClick:()=>K(A),disabled:R.isPending,className:`${r?"px-3 py-2.5 text-sm":"px-4 py-2"} bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors disabled:opacity-50`,children:R.isPending?e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-white border-t-transparent"}):t("projectSubAgentsModal.actions.delete")})]})]})})]})})},_t=l=>{const[M,t]=o.useState({mapping:!0,card:!0,keys:!0,config:!0,tasks:!0}),[r,p]=o.useState(null),[u,w]=o.useState(null),[y,v]=o.useState([]),[h,A]=o.useState(null),[g,c]=o.useState([]),j=async()=>{try{t(s=>({...s,mapping:!0}));const i=await P(`${E}/a2a/mapping/${encodeURIComponent(l.path)}`);if(i.ok){const s=await i.json();return p(s),s}else return console.error("Failed to fetch agent mapping"),null}catch(i){return console.error("Error fetching agent mapping:",i),null}finally{t(i=>({...i,mapping:!1}))}},F=async()=>{try{t(s=>({...s,card:!0}));const i=await P(`${E}/a2a/agent-card/${encodeURIComponent(l.path)}`);if(i.ok){const s=await i.json();return w(s),s}else return console.error("Failed to fetch agent card"),null}catch(i){return console.error("Error fetching agent card:",i),null}finally{t(i=>({...i,card:!1}))}};o.useEffect(()=>{(async()=>{await j()?await F():w(null)})()},[l.path]),o.useEffect(()=>{(async()=>{try{t(b=>({...b,keys:!0}));const s=await P(`${E}/a2a/api-keys/${encodeURIComponent(l.path)}`);if(s.ok){const b=await s.json();v(b.apiKeys||[])}else console.error("Failed to fetch API keys")}catch(s){console.error("Error fetching API keys:",s)}finally{t(s=>({...s,keys:!1}))}})()},[l.id]),o.useEffect(()=>{(async()=>{try{t(b=>({...b,config:!0}));const s=await P(`${E}/a2a/config/${encodeURIComponent(l.path)}`);if(s.ok){const b=await s.json();A(b)}else s.status===404&&A({allowedAgents:[],taskTimeout:3e5,maxConcurrentTasks:5})}catch(s){console.error("Error fetching config:",s)}finally{t(s=>({...s,config:!1}))}})()},[l.id]),o.useEffect(()=>{(async()=>{try{if(t(b=>({...b,tasks:!0})),!r)return;const s=await P(`${E}/a2a/tasks/${encodeURIComponent(l.path)}`);if(s.ok){const b=await s.json();c(b.tasks||[])}}catch(s){console.error("Error fetching tasks:",s)}finally{t(s=>({...s,tasks:!1}))}})()},[r]);const U=async i=>{try{const s=await P(`${E}/a2a/api-keys/${encodeURIComponent(l.path)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({description:i})});if(s.ok){const b=await s.json();return v(D=>[b,...D]),Z("API密钥创建成功"),b}else{const b=await s.json();throw new Error(b.error||"创建失败")}}catch(s){return console.error("Failed to create API key:",s),I("创建API密钥失败",s instanceof Error?s.message:"未知错误"),null}},R=async i=>{try{const s=await P(`${E}/a2a/api-keys/${encodeURIComponent(l.path)}/${i}`,{method:"DELETE"});if(s.ok)return v(b=>b.filter(D=>D.id!==i)),Z("API密钥删除成功"),!0;{const b=await s.json();throw new Error(b.error||"删除失败")}}catch(s){return console.error("Failed to delete API key:",s),I("删除API密钥失败",s instanceof Error?s.message:"未知错误"),!1}},K=async i=>{try{const s=await P(`${E}/a2a/config/${encodeURIComponent(l.path)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(s.ok)return A(i),Z("A2A配置更新成功"),!0;{const b=await s.json();throw new Error(b.error||"更新失败")}}catch(s){return console.error("Failed to update config:",s),I("更新A2A配置失败",s instanceof Error?s.message:"未知错误"),!1}},O=async i=>{if(!h)return!1;const s={...h,allowedAgents:[...h.allowedAgents,i]};return await K(s)},x=async i=>{if(!h)return!1;const s={...h,allowedAgents:h.allowedAgents.filter((b,D)=>D!==i)};return await K(s)},d=async(i,s)=>{if(!h)return!1;const b={...h,allowedAgents:h.allowedAgents.map((D,J)=>J===i?s:D)};return await K(b)};return{loading:M,agentMapping:r,agentCard:u,apiKeys:y,config:h,tasks:g,fetchAgentMapping:j,fetchAgentCard:F,createApiKey:U,deleteApiKey:R,updateConfig:K,addExternalAgent:O,removeExternalAgent:x,updateExternalAgent:d,toggleExternalAgent:async i=>{if(!h)return!1;const s=h.allowedAgents[i];return await d(i,{...s,enabled:!s.enabled})},cancelTask:async i=>{if(!r)return!1;try{const s=await P(`${E}/a2a/tasks/${encodeURIComponent(l.path)}/${i}`,{method:"DELETE"});if(s.ok)return c(b=>b.map(D=>D.id===i?{...D,status:"canceled",completedAt:new Date().toISOString()}:D)),Z("任务已取消"),!0;{const b=await s.json();throw new Error(b.error||"取消失败")}}catch(s){return console.error("Failed to cancel task:",s),I("取消任务失败",s instanceof Error?s.message:"未知错误"),!1}},refreshTasks:async()=>{if(r)try{t(s=>({...s,tasks:!0}));const i=await P(`${E}/a2a/tasks/${encodeURIComponent(l.path)}`);if(i.ok){const s=await i.json();c(s.tasks||[])}}catch(i){console.error("Error refreshing tasks:",i)}finally{t(i=>({...i,tasks:!1}))}},copyToClipboard:async i=>{try{return await navigator.clipboard.writeText(i),Z("已复制到剪贴板"),!0}catch{return I("复制失败"),!1}},importProjects:async i=>{try{const s=await P(`${E}/a2a/import-projects/${encodeURIComponent(l.path)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectPaths:i})});if(s.ok){const b=await s.json(),D=await P(`${E}/a2a/config/${encodeURIComponent(l.path)}`);if(D.ok){const J=await D.json();A(J)}return b.totalSuccess>0&&Z(`成功导入 ${b.totalSuccess} 个项目`),b.totalFailed>0&&I(`${b.totalFailed} 个项目导入失败`),b}else{const b=await s.json();throw new Error(b.error||"导入失败")}}catch(s){return console.error("Failed to import projects:",s),I("导入项目失败",s instanceof Error?s.message:"未知错误"),null}},validateAgentUrl:i=>{try{const s=new URL(i);return["http:","https:"].includes(s.protocol)?{valid:!0}:{valid:!1,error:"URL必须使用HTTP或HTTPS协议"}}catch{return{valid:!1,error:"无效的URL格式"}}},formatDate:i=>new Date(i).toLocaleString("zh-CN")}},Jt=({project:l,onClose:M})=>{const{t}=me("components"),[r,p]=o.useState("overview"),{loading:u,agentMapping:w,agentCard:y,apiKeys:v,config:h,tasks:A,createApiKey:g,deleteApiKey:c,addExternalAgent:j,removeExternalAgent:F,updateExternalAgent:U,toggleExternalAgent:R,copyToClipboard:K,validateAgentUrl:O,formatDate:x,importProjects:d}=_t(l),{data:m}=Lt(),[S,C]=o.useState(!1),[B,H]=o.useState(!1),[je,G]=o.useState(!1),[i,s]=o.useState(new Set),[b,D]=o.useState(!1),[J,fe]=o.useState(null),[ne,le]=o.useState(""),[de,X]=o.useState(""),[Pe,Ne]=o.useState(!1),[ge,ke]=o.useState(""),[he,Ee]=o.useState(new Set),[n,f]=o.useState(null),[k,$]=o.useState(!1),[L,q]=o.useState(""),[V,we]=o.useState(!1),ve=Be.useCallback(async()=>{$(!0);try{const a=await P(`${E}/network-info`);if(!a.ok)throw new Error("Failed to load network info");const N=await a.json();f(N)}catch(a){console.error("Error loading network info:",a),I("获取网络信息失败")}finally{$(!1)}},[]);Be.useEffect(()=>{r==="im"&&!n&&!k&&ve()},[r,n,k,ve]);const tt=a=>{Ee(N=>{const T=new Set(N);return T.has(a)?T.delete(a):T.add(a),T})},at=a=>a?"•".repeat(Math.min(a.length,40)):"••••••••••••••••",[z,ae]=o.useState({name:"",url:"",apiKey:"",description:"",enabled:!0}),[W,ze]=o.useState({name:"",url:"",apiKey:""}),Oe=a=>a.trim()?a.length>100?(X(t("a2aManagement.validation.descriptionTooLong")),!1):(X(""),!0):(X(t("a2aManagement.validation.descriptionRequired")),!1),rt=()=>{const a={name:"",url:"",apiKey:""};let N=!0;if(z.name.trim()?z.name.length>50&&(a.name=t("a2aManagement.validation.agentNameTooLong"),N=!1):(a.name=t("a2aManagement.validation.agentNameRequired"),N=!1),!z.url.trim())a.url=t("a2aManagement.validation.urlRequired"),N=!1;else{const T=O(z.url);T.valid||(a.url=T.error||t("a2aManagement.validation.invalidUrl"),N=!1)}return z.apiKey.trim()||(a.apiKey=t("a2aManagement.validation.apiKeyRequired"),N=!1),ze(a),N},st=async()=>{if(!Oe(ne))return;const a=await g(ne);a&&a.key&&(le(""),C(!1),X(""),ke(a.key),Ne(!0))},nt=async a=>{confirm(t("a2aManagement.confirmations.deleteApiKey"))&&await c(a)},lt=async()=>{rt()&&(J!==null&&h?await U(J,z)&&(H(!1),oe()):await j(z)&&(H(!1),oe()))},dt=async a=>{confirm(t("a2aManagement.confirmations.deleteExternalAgent"))&&await F(a)},ot=a=>{if(!h)return;const N=h.allowedAgents[a];ae({name:N.name,url:N.url,apiKey:N.apiKey,description:N.description||"",enabled:N.enabled}),fe(a),H(!0)},oe=()=>{ae({name:"",url:"",apiKey:"",description:"",enabled:!0}),fe(null),ze({name:"",url:"",apiKey:""})},it=async()=>{if(i.size===0){I("请至少选择一个项目");return}D(!0);try{const a=Array.from(i);await d(a)&&(G(!1),s(new Set))}finally{D(!1)}},ct=a=>{s(N=>{const T=new Set(N);return T.has(a)?T.delete(a):T.add(a),T})},xt=()=>{if(!y||!v.length)return"";const a=v[0].key||"YOUR_API_KEY_HERE";return`curl -X POST "${`${y.url}/messages`}" \\
|
|
13
|
+
-H "Content-Type: application/json" \\
|
|
14
|
+
-H "Authorization: Bearer ${a}" \\
|
|
15
|
+
-d '{
|
|
16
|
+
"message": "你好,请帮我完成一个任务"
|
|
17
|
+
}'`},mt=async()=>{const a=xt();a?await K(a):I("请先创建至少一个 API 密钥")},gt=()=>e.jsx("div",{className:"border-b border-gray-200 dark:border-gray-700 px-6",children:e.jsx("nav",{className:"flex space-x-8",children:[{id:"overview",label:t("a2aManagement.tabs.overview"),icon:pe},{id:"keys",label:t("a2aManagement.tabs.apiKeys"),icon:ye},{id:"external",label:t("a2aManagement.tabs.external"),icon:ee},{id:"tasks",label:t("a2aManagement.tabs.tasks"),icon:Ie},{id:"im",label:t("a2aManagement.tabs.im"),icon:Ve}].map(({id:a,label:N,icon:T})=>e.jsxs("button",{onClick:()=>p(a),className:`flex items-center space-x-2 py-4 px-3 border-b-2 font-medium text-sm transition-colors ${r===a?"border-blue-500 text-blue-600 dark:text-blue-400":"border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"}`,children:[e.jsx(T,{className:"w-4 h-4"}),e.jsx("span",{children:N})]},a))})}),ht=()=>{const a=l.path.split("/").pop()||l.path,N=y?.context?.agentType||"claude code",T=`${a} (${N})`;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(ye,{className:"w-8 h-8 text-blue-500"}),e.jsxs("div",{className:"ml-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:t("a2aManagement.overview.apiKeys")}),e.jsx("p",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:v.length})]})]})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(ee,{className:"w-8 h-8 text-green-500"}),e.jsxs("div",{className:"ml-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:t("a2aManagement.overview.externalAgents")}),e.jsx("p",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:h?.allowedAgents?.length||0})]})]})}),e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Ie,{className:"w-8 h-8 text-purple-500"}),e.jsxs("div",{className:"ml-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:t("a2aManagement.overview.activeTasks")}),e.jsx("p",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:A.filter(ie=>ie.status==="running").length})]})]})})]}),y&&e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6",children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-4 flex items-center",children:[e.jsx(ee,{className:"w-5 h-5 mr-2"}),t("a2aManagement.overview.agentCard")]}),e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-1",children:T}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 text-sm",children:y.description})]}),e.jsx("span",{className:"px-2 py-1 text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200 rounded-full",children:y.version})]}),e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm text-blue-800 dark:text-blue-200 mb-1",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(pe,{className:"w-4 h-4 mr-2"}),"A2A Endpoint"]}),e.jsxs("button",{onClick:mt,className:"flex items-center space-x-1 px-2 py-1 text-xs bg-blue-600 hover:bg-blue-700 text-white rounded transition-colors",title:"复制 curl 命令",children:[e.jsx(ce,{className:"w-3 h-3"}),e.jsx("span",{children:"复制 curl"})]})]}),e.jsx("code",{className:"text-xs text-blue-700 dark:text-blue-300 font-mono break-all",children:y.url})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h5",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-3",children:t("a2aManagement.agentCard.context")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"A2A Agent ID:"}),e.jsxs("div",{className:"flex items-center space-x-2 flex-1 min-w-0",children:[e.jsx("code",{className:"text-gray-900 dark:text-white font-mono text-xs truncate",children:y.context?.a2aAgentId}),e.jsx("button",{onClick:()=>K(y.context?.a2aAgentId||""),className:"p-1 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 flex-shrink-0",title:t("a2aManagement.actions.copy"),children:e.jsx(ce,{className:"w-3 h-3"})})]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Project:"}),e.jsx("span",{className:"text-gray-900 dark:text-white",children:y.context?.projectName})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Type:"}),e.jsx("span",{className:"text-gray-900 dark:text-white",children:y.context?.agentType})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Category:"}),e.jsx("span",{className:"text-gray-900 dark:text-white",children:y.context?.agentCategory})]})]})]}),e.jsxs("div",{children:[e.jsxs("h5",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-3",children:[t("a2aManagement.agentCard.skills")," (",y.skills?.length||0,")"]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2 max-h-48 overflow-y-auto",children:y.skills?.map((ie,Te)=>e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-lg p-2 text-xs",children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white mb-1 truncate",children:ie.name}),e.jsx("div",{className:"text-gray-500 dark:text-gray-400 line-clamp-2",children:ie.description})]},Te))})]}),e.jsx("div",{className:"mt-4 pt-4 border-t border-gray-200 dark:border-gray-700",children:e.jsxs("div",{className:"flex items-center text-xs text-gray-500 dark:text-gray-400",children:[e.jsx(ye,{className:"w-3 h-3 mr-1"}),t("a2aManagement.agentCard.security"),": ",y.securitySchemes?.[0]?.type]})})]})]})},yt=()=>e.jsxs("div",{className:"space-y-6",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:t("a2aManagement.apiKeys.title")}),e.jsxs("button",{onClick:()=>C(!0),className:"flex items-center space-x-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:[e.jsx(xe,{className:"w-4 h-4"}),e.jsx("span",{children:t("a2aManagement.actions.createKey")})]})]}),u.keys?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(se,{className:"w-6 h-6 animate-spin text-blue-500"})}):v.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ye,{className:"w-12 h-12 text-gray-400 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:t("a2aManagement.apiKeys.noKeys")}),e.jsx("button",{onClick:()=>C(!0),className:"mt-4 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:t("a2aManagement.apiKeys.createFirstKey")})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200 dark:border-gray-700",children:[e.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-700 dark:text-gray-300",children:t("a2aManagement.apiKeys.description")}),e.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-700 dark:text-gray-300",children:t("a2aManagement.apiKeys.key")}),e.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-700 dark:text-gray-300",children:t("a2aManagement.apiKeys.createdAt")}),e.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-700 dark:text-gray-300",children:t("a2aManagement.apiKeys.lastUsed")}),e.jsx("th",{className:"text-right py-3 px-4 font-medium text-gray-700 dark:text-gray-300",children:t("a2aManagement.apiKeys.actions")})]})}),e.jsx("tbody",{children:v.map(a=>e.jsxs("tr",{className:"border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50 dark:hover:bg-gray-800/50",children:[e.jsx("td",{className:"py-3 px-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("span",{className:"text-gray-900 dark:text-white",children:a.description}),e.jsx("span",{className:"px-1.5 py-0.5 text-xs bg-green-100 dark:bg-green-900 text-green-800 dark:text-green-200 rounded-full",children:"Active"})]})}),e.jsx("td",{className:"py-3 px-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("code",{className:"text-xs text-gray-700 dark:text-gray-300 font-mono bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded max-w-xs overflow-hidden",children:he.has(a.id)&&a.key?a.key:at(a.key)}),a.key&&e.jsx("button",{onClick:()=>tt(a.id),className:"p-1 hover:bg-gray-200 dark:hover:bg-gray-700 rounded transition-colors",title:he.has(a.id)?t("a2aManagement.apiKeys.hideKey"):t("a2aManagement.apiKeys.showKey"),children:he.has(a.id)?e.jsx(vt,{className:"w-4 h-4 text-gray-500"}):e.jsx(Ct,{className:"w-4 h-4 text-gray-500"})}),e.jsx("button",{onClick:()=>a.key&&K(a.key),className:"p-1 hover:bg-gray-200 dark:hover:bg-gray-700 rounded transition-colors",title:t("a2aManagement.actions.copy"),children:e.jsx(ce,{className:"w-4 h-4 text-gray-500"})})]})}),e.jsx("td",{className:"py-3 px-4 text-gray-500 dark:text-gray-400",children:x(a.createdAt)}),e.jsx("td",{className:"py-3 px-4 text-gray-500 dark:text-gray-400",children:a.lastUsed?x(a.lastUsed):"-"}),e.jsx("td",{className:"py-3 px-4 text-right",children:e.jsx("button",{onClick:()=>nt(a.id),className:"p-1.5 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded-lg transition-colors",title:t("a2aManagement.actions.delete"),children:e.jsx(te,{className:"w-4 h-4"})})})]},a.id))})]})}),S&&e.jsx("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-md mx-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:t("a2aManagement.modals.createKey.title")}),e.jsx("button",{onClick:()=>{C(!1),le(""),X("")},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:"p-6",children:[e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[t("a2aManagement.modals.createKey.description")," *"]}),e.jsx("input",{type:"text",value:ne,onChange:a=>{le(a.target.value),Oe(a.target.value)},placeholder:t("a2aManagement.modals.createKey.descriptionPlaceholder"),className:`w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white ${de?"border-red-300 dark:border-red-600":"border-gray-300 dark:border-gray-600"}`,maxLength:100,autoFocus:!0}),de&&e.jsx("p",{className:"text-red-600 dark:text-red-400 text-sm mt-1",children:de}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:t("a2aManagement.modals.createKey.descriptionHelp")})]}),e.jsx("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-3 mb-4",children:e.jsxs("p",{className:"text-sm text-yellow-800 dark:text-yellow-200",children:[e.jsxs("strong",{children:[t("a2aManagement.modals.createKey.important"),":"]})," ",t("a2aManagement.modals.createKey.securityNote")]})}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{C(!1),le(""),X("")},className:"px-4 py-2 text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700",children:t("a2aManagement.actions.cancel")}),e.jsx("button",{onClick:st,disabled:!ne.trim()||!!de||u.keys,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:u.keys?e.jsxs("span",{className:"flex items-center",children:[e.jsx(se,{className:"w-4 h-4 animate-spin mr-2"}),t("a2aManagement.modals.createKey.creating")]}):t("a2aManagement.actions.createKey")})]})]})]})}),Pe&&e.jsx("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-lg mx-4",children:[e.jsx("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white flex items-center",children:[e.jsx(ye,{className:"w-5 h-5 mr-2 text-green-500"}),t("a2aManagement.modals.newKey.title","API密钥创建成功")]})}),e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:t("a2aManagement.modals.newKey.yourKey","您的 API 密钥")}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"p-3 bg-gray-50 dark:bg-gray-900 border border-gray-300 dark:border-gray-600 rounded-lg font-mono text-sm break-all",children:ge}),e.jsx("button",{onClick:()=>K(ge),className:"absolute top-2 right-2 p-2 bg-blue-600 hover:bg-blue-700 text-white rounded transition-colors",title:t("a2aManagement.actions.copy"),children:e.jsx(ce,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-3 mb-6",children:e.jsxs("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:[e.jsxs("strong",{children:[t("a2aManagement.modals.newKey.usage","使用方式"),":"]})," ",t("a2aManagement.modals.newKey.usageDetail","在请求头中添加 Authorization: Bearer YOUR_API_KEY")]})}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsxs("button",{onClick:()=>K(ge),className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 flex items-center space-x-2",children:[e.jsx(ce,{className:"w-4 h-4"}),e.jsx("span",{children:t("a2aManagement.actions.copyKey","复制密钥")})]}),e.jsx("button",{onClick:()=>{Ne(!1),ke("")},className:"px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700",children:t("a2aManagement.actions.close","关闭")})]})]})]})})]}),pt=()=>e.jsxs("div",{className:"space-y-6",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:t("a2aManagement.external.title")}),e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsxs("button",{onClick:()=>G(!0),className:"flex items-center space-x-2 px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700",children:[e.jsx(Fe,{className:"w-4 h-4"}),e.jsx("span",{children:t("a2aManagement.actions.importProjects")})]}),e.jsxs("button",{onClick:()=>{oe(),H(!0)},className:"flex items-center space-x-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:[e.jsx(xe,{className:"w-4 h-4"}),e.jsx("span",{children:t("a2aManagement.actions.addAgent")})]})]})]}),u.config?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(se,{className:"w-6 h-6 animate-spin text-blue-500"})}):!h||h.allowedAgents?.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ee,{className:"w-12 h-12 text-gray-400 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:t("a2aManagement.external.noAgents")}),e.jsx("button",{onClick:()=>{oe(),H(!0)},className:"mt-4 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:t("a2aManagement.external.addFirstAgent")})]}):e.jsx("div",{className:"space-y-4",children:h.allowedAgents?.map((a,N)=>e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center space-x-3 mb-2",children:[e.jsx("h4",{className:"text-medium font-medium text-gray-900 dark:text-white",children:a.name}),e.jsx("span",{className:`px-2 py-1 text-xs rounded-full ${a.enabled?"bg-green-100 dark:bg-green-900 text-green-800 dark:text-green-200":"bg-gray-100 dark:bg-gray-900 text-gray-800 dark:text-gray-200"}`,children:a.enabled?t("a2aManagement.external.enabled"):t("a2aManagement.external.disabled")})]}),a.description&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-2",children:a.description}),e.jsx("div",{className:"space-y-1 text-sm",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[t("a2aManagement.external.form.url"),":"]}),e.jsxs("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 dark:text-blue-400 hover:underline flex items-center",children:[a.url,e.jsx(Ye,{className:"w-3 h-3 ml-1"})]})]})})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("button",{onClick:()=>R(N),className:`p-2 rounded-lg transition-colors ${a.enabled?"text-green-600 hover:bg-green-50 dark:hover:bg-green-900/50":"text-gray-600 hover:bg-gray-100 dark:hover:bg-gray-700"}`,title:a.enabled?t("a2aManagement.actions.disable"):t("a2aManagement.actions.enable"),children:a.enabled?e.jsx(Mt,{className:"w-4 h-4"}):e.jsx(At,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ot(N),className:"p-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",title:t("a2aManagement.actions.edit"),children:e.jsx(Ce,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>dt(N),className:"p-2 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/50 rounded-lg transition-colors",title:t("a2aManagement.actions.delete"),children:e.jsx(te,{className:"w-4 h-4"})})]})]})},N))}),B&&e.jsx("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-md mx-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:t(J!==null?"a2aManagement.external.modal.editTitle":"a2aManagement.external.modal.addTitle")}),e.jsx("button",{onClick:()=>{H(!1),oe()},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:"p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[t("a2aManagement.external.form.name")," *"]}),e.jsx("input",{type:"text",value:z.name,onChange:a=>ae({...z,name:a.target.value}),placeholder:t("a2aManagement.external.form.namePlaceholder"),className:`w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white ${W.name?"border-red-300 dark:border-red-600":"border-gray-300 dark:border-gray-600"}`,maxLength:50}),W.name&&e.jsx("p",{className:"text-red-600 dark:text-red-400 text-sm mt-1",children:W.name})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[t("a2aManagement.external.form.url")," *"]}),e.jsx("input",{type:"url",value:z.url,onChange:a=>ae({...z,url:a.target.value}),placeholder:t("a2aManagement.external.form.urlPlaceholder"),className:`w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white ${W.url?"border-red-300 dark:border-red-600":"border-gray-300 dark:border-gray-600"}`}),W.url&&e.jsx("p",{className:"text-red-600 dark:text-red-400 text-sm mt-1",children:W.url}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:t("a2aManagement.external.form.urlHelp")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[t("a2aManagement.external.form.apiKey")," *"]}),e.jsx("input",{type:"password",value:z.apiKey,onChange:a=>ae({...z,apiKey:a.target.value}),placeholder:t("a2aManagement.external.form.apiKeyPlaceholder"),className:`w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:text-white ${W.apiKey?"border-red-300 dark:border-red-600":"border-gray-300 dark:border-gray-600"}`}),W.apiKey&&e.jsx("p",{className:"text-red-600 dark:text-red-400 text-sm mt-1",children:W.apiKey})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:t("a2aManagement.external.form.description")}),e.jsx("textarea",{value:z.description,onChange:a=>ae({...z,description:a.target.value}),placeholder:t("a2aManagement.external.form.descriptionPlaceholder"),rows:3,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",maxLength:200})]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",id:"agent-enabled",checked:z.enabled,onChange:a=>ae({...z,enabled:a.target.checked}),className:"w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}),e.jsx("label",{htmlFor:"agent-enabled",className:"ml-2 text-sm text-gray-700 dark:text-gray-300",children:t("a2aManagement.external.form.enableThisAgent")})]}),e.jsxs("div",{className:"flex justify-end space-x-3 pt-4",children:[e.jsx("button",{onClick:()=>{H(!1),oe()},className:"px-4 py-2 text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700",children:t("a2aManagement.actions.cancel")}),e.jsx("button",{onClick:lt,disabled:u.config,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:t(J!==null?"a2aManagement.external.modal.saveChanges":"a2aManagement.external.modal.addAgent")})]})]})]})}),je&&e.jsx("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-2xl mx-4 max-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("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white flex items-center",children:[e.jsx(Fe,{className:"w-5 h-5 mr-2"}),t("a2aManagement.external.importModal.title")]}),e.jsx("button",{onClick:()=>{G(!1),s(new Set)},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:"flex-1 overflow-y-auto p-6",children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-4",children:t("a2aManagement.external.importModal.description")}),!m||m.projects.length===0?e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:t("a2aManagement.external.importModal.noProjects")})}):e.jsx("div",{className:"space-y-2",children:m.projects.filter(a=>a.path!==l.path).map(a=>e.jsxs("label",{className:"flex items-center p-3 border border-gray-200 dark:border-gray-700 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:i.has(a.path),onChange:()=>ct(a.path),className:"w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}),e.jsxs("div",{className:"ml-3 flex-1",children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:a.name}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:a.path})]})]},a.path))})]}),e.jsxs("div",{className:"p-6 border-t border-gray-200 dark:border-gray-700",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:[t("a2aManagement.external.importModal.selected"),": ",i.size]})}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{G(!1),s(new Set)},className:"px-4 py-2 text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700",children:t("a2aManagement.actions.cancel")}),e.jsx("button",{onClick:it,disabled:i.size===0||b,className:"px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 disabled:opacity-50 disabled:cursor-not-allowed flex items-center space-x-2",children:b?e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"w-4 h-4 animate-spin"}),e.jsx("span",{children:t("a2aManagement.external.importModal.importing")})]}):e.jsxs(e.Fragment,{children:[e.jsx(Fe,{className:"w-4 h-4"}),e.jsx("span",{children:t("a2aManagement.external.importModal.import")})]})})]})]})]})})]}),ut=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:t("a2aManagement.tasks.title")}),w?u.tasks?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(se,{className:"w-6 h-6 animate-spin text-blue-500"})}):A.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ue,{className:"w-12 h-12 text-gray-400 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:t("a2aManagement.tasks.noTasks")})]}):e.jsx("div",{className:"space-y-4",children:A.map(a=>e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6",children:e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center space-x-3 mb-2",children:[e.jsx("h4",{className:"text-medium font-medium text-gray-900 dark:text-white",children:a.id}),e.jsx("span",{className:`px-2 py-1 text-xs rounded-full ${a.status==="completed"?"bg-green-100 dark:bg-green-900 text-green-800 dark:text-green-200":a.status==="running"?"bg-blue-100 dark:bg-blue-900 text-blue-800 dark:text-blue-200":a.status==="failed"?"bg-red-100 dark:bg-red-900 text-red-800 dark:text-red-200":"bg-gray-100 dark:bg-gray-900 text-gray-800 dark:text-gray-200"}`,children:a.status})]}),e.jsxs("div",{className:"space-y-1 text-sm text-gray-500 dark:text-gray-400",children:[e.jsxs("div",{children:[t("a2aManagement.tasks.createdAt"),": ",x(a.createdAt)]}),a.startedAt&&e.jsxs("div",{children:[t("a2aManagement.tasks.startedAt"),": ",x(a.startedAt)]}),a.completedAt&&e.jsxs("div",{children:[t("a2aManagement.tasks.completedAt"),": ",x(a.completedAt)]})]})]})})},a.id))}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Ie,{className:"w-12 h-12 text-gray-400 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:t("a2aManagement.tasks.needA2AEnabled")})]})]}),bt=async()=>{if(!y?.context?.a2aAgentId){I("无法获取 A2A Agent ID");return}we(!0);try{const a=v.find(re=>re.description==="企微调用");let N;if(a&&a.key)N=a.key;else{const re=await g("企微调用");if(!re||!re.key){I("创建 API 密钥失败");return}N=re.key}await ve();let T;if(n?.tunnel?.connected&&n.tunnel.url)T=n.tunnel.url;else if(n?.network?.bestLocalIP){const re=n.network.port||4936;T=`http://${n.network.bestLocalIP}:${re}`}else{I("无法确定访问地址,请先配置隧道服务");return}const ie=`${T}/a2a/${y.context.a2aAgentId}/messages`,Te=`/ap ${l.name} ${ie} --api-key ${N}`;q(Te)}catch(a){console.error("Error generating command:",a),I("生成命令失败")}finally{we(!1)}},jt=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(Ve,{className:"w-5 h-5"}),t("a2aManagement.im.title")]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:t("a2aManagement.im.description")})]}),e.jsxs("button",{onClick:ve,disabled:k,className:"flex items-center gap-2 px-3 py-2 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors disabled:opacity-50",children:[e.jsx(St,{className:`w-4 h-4 ${k?"animate-spin":""}`}),t("a2aManagement.im.refresh")]})]}),k?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(se,{className:"w-6 h-6 animate-spin text-blue-500"})}):n&&e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-white mb-4",children:t("a2aManagement.im.networkStatus")}),e.jsxs("div",{className:"mb-4 p-3 rounded-lg bg-gray-50 dark:bg-gray-900",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:t("a2aManagement.im.tunnelStatus")}),n.tunnel?.connected?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-600 dark:text-green-400",children:[e.jsx(Ge,{className:"w-3 h-3"}),t("a2aManagement.im.connected")]}):e.jsxs("span",{className:"flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400",children:[e.jsx(Ke,{className:"w-3 h-3"}),t("a2aManagement.im.notConnected")]})]}),n.tunnel?.connected&&n.tunnel.url&&e.jsx("div",{className:"text-xs text-gray-600 dark:text-gray-400 break-all",children:n.tunnel.url})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-gray-50 dark:bg-gray-900",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:t("a2aManagement.im.localNetwork")}),n.network?.bestLocalIP?e.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-600 dark:text-green-400",children:[e.jsx(Ge,{className:"w-3 h-3"}),t("a2aManagement.im.available")]}):e.jsxs("span",{className:"flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400",children:[e.jsx(Ke,{className:"w-3 h-3"}),t("a2aManagement.im.unavailable")]})]}),n.network?.bestLocalIP&&e.jsxs("div",{className:"text-xs text-gray-600 dark:text-gray-400",children:["http://",n.network.bestLocalIP,":",n.network.port||4936]})]}),!n.tunnel?.connected&&!n.network?.bestLocalIP&&e.jsx("div",{className:"mt-4 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ke,{className:"w-4 h-4 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5"}),e.jsx("div",{className:"text-sm text-yellow-800 dark:text-yellow-200",children:t("a2aManagement.im.noAccessWarning")})]})})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-white mb-4",children:t("a2aManagement.im.commandGenerator")}),e.jsxs("div",{className:"mb-4",children:[e.jsx("button",{onClick:bt,disabled:V||!y?.context?.a2aAgentId||k,className:"w-full px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:V?e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"w-4 h-4 animate-spin"}),t("a2aManagement.im.generating")]}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"w-4 h-4"}),t("a2aManagement.im.generateCommand")]})}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-2",children:t("a2aManagement.im.generateHint")})]}),L&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"p-3 bg-gray-50 dark:bg-gray-900 border border-gray-300 dark:border-gray-600 rounded-lg font-mono text-sm break-all",children:L}),e.jsx("button",{onClick:()=>K(L),className:"absolute top-2 right-2 p-2 bg-blue-600 hover:bg-blue-700 text-white rounded transition-colors",title:t("a2aManagement.actions.copy"),children:e.jsx(ce,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-3",children:e.jsxs("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:[e.jsxs("strong",{children:[t("a2aManagement.im.usage"),":"]})," ",t("a2aManagement.im.usageDetail")]})})]})]})]});return e.jsx("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 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",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white flex items-center",children:[e.jsx(pe,{className:"w-5 h-5 mr-2"}),t("a2aManagement.title")]}),e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:[t("a2aManagement.project"),": ",l.name]})]}),e.jsx("button",{onClick:M,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:"flex-1 overflow-hidden flex flex-col",children:[e.jsx("div",{className:"flex-shrink-0",children:gt()}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[r==="overview"&&ht(),r==="keys"&&yt(),r==="external"&&pt(),r==="tasks"&&ut(),r==="im"&&jt()]})]})]})})},qt=({isOpen:l,project:M,onClose:t,onSaved:r})=>{const{data:p}=Rt(),[u,w]=o.useState(""),[y,v]=o.useState(""),[h,A]=o.useState(!1);o.useEffect(()=>{M&&(w(M.defaultProviderId||""),v(M.defaultModel||""))},[M]);const g=o.useMemo(()=>p?.versions?u?p.versions.find(U=>U.id===u)?.models||[]:(p.versions.find(F=>F.id===p.defaultVersionId)||p.versions[0])?.models||[]:[],[p,u]);o.useEffect(()=>{g.length>0&&y&&(g.some(F=>F.id===y)||v(""))},[g,y]);const c=async()=>{if(M){A(!0);try{const j=await P(`${E}/projects/${encodeURIComponent(M.path)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultProviderId:u||"",defaultModel:y||""})});if(!j.ok){const F=await j.json();throw new Error(F.error||"保存失败")}Z("项目设置已保存"),r(),t()}catch(j){console.error("Failed to save project settings:",j),I(j instanceof Error?j.message:"保存项目设置失败")}finally{A(!1)}}};return!l||!M?null: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-xl shadow-2xl w-full max-w-lg mx-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-indigo-100 dark:bg-indigo-900/30 rounded-lg",children:e.jsx(Ce,{className:"w-5 h-5 text-indigo-600 dark:text-indigo-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:"项目设置"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:M.name})]})]}),e.jsx("button",{onClick:t,className:"p-2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700",children:e.jsx(_,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[e.jsx($t,{className:"w-4 h-4"}),"默认供应商"]}),e.jsxs("select",{value:u,onChange:j=>w(j.target.value),className:"w-full px-3 py-2 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-indigo-500 focus:border-transparent",children:[e.jsx("option",{value:"",children:"使用系统默认"}),p?.versions?.map(j=>e.jsxs("option",{value:j.id,children:[j.name," ",j.isDefault?"(系统默认)":""]},j.id))]}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"设置此项目使用的 API 密钥和环境配置"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[e.jsx(ee,{className:"w-4 h-4"}),"默认模型"]}),e.jsxs("select",{value:y,onChange:j=>v(j.target.value),className:"w-full px-3 py-2 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-indigo-500 focus:border-transparent",children:[e.jsx("option",{value:"",children:"使用供应商首选模型"}),g.map(j=>e.jsx("option",{value:j.id,children:j.name},j.id))]}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"设置此项目的默认 AI 模型(可在聊天时覆盖)"})]}),e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-700/50 rounded-lg",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"配置优先级"}),e.jsxs("ul",{className:"text-xs text-gray-500 dark:text-gray-400 space-y-1",children:[e.jsx("li",{children:"1. 聊天时手动选择(最高优先级)"}),e.jsx("li",{children:"2. 项目默认设置(此处配置)"}),e.jsx("li",{children:"3. 供应商首选模型"}),e.jsx("li",{children:"4. 系统默认配置"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 p-4 border-t border-gray-200 dark:border-gray-700",children:[e.jsx("button",{onClick:t,className:"px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:"取消"}),e.jsx("button",{onClick:c,disabled:h,className:"px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg transition-colors disabled:opacity-50",children:h?"保存中...":"保存设置"})]})]})})},Vt=({isOpen:l,onClose:M,onConfirm:t,agents:r})=>{const{t:p}=me("pages"),[u,w]=o.useState({name:"",agentId:"",directory:"~/claude-code-projects",description:""}),[y,v]=o.useState(!1);o.useEffect(()=>{l&&w({name:"",agentId:r.length>0?r[0].id:"",directory:"~/claude-code-projects",description:""})},[l,r]);const h=c=>{if(!c.startsWith("~/"))return c},A=c=>{c.preventDefault(),u.name&&u.agentId&&t(u)},g=r.find(c=>c.id===u.agentId);return l?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-md mx-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:p("projects.form.create")}),e.jsx("button",{onClick:M,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx(_,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:A,className:"p-6",children:[e.jsxs("div",{className:"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:p("projects.form.nameRequired")}),e.jsx("input",{type:"text",value:u.name,onChange:c=>w({...u,name:c.target.value}),placeholder:p("projects.form.namePlaceholder"),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",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:p("projects.form.agentType")}),e.jsx("select",{value:u.agentId,onChange:c=>w({...u,agentId:c.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",required:!0,children:r.filter(c=>c.enabled).map(c=>e.jsxs("option",{value:c.id,children:[c.ui.icon," ",c.name]},c.id))}),g&&e.jsx("div",{className:"mt-2 p-3 bg-gray-50 dark:bg-gray-700 rounded-lg",children:e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"text-2xl",children:g.ui.icon}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:g.name}),e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:g.description})]})]})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:p("projects.form.directory")}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("input",{type:"text",value:u.directory,onChange:c=>w({...u,directory:c.target.value}),className:"flex-1 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"}),e.jsx("button",{type:"button",onClick:()=>v(!0),className:"px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700",title:p("projects.form.directory"),children:e.jsx(Le,{className:"w-4 h-4 text-gray-600 dark:text-gray-400"})})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:p("projects.form.directoryNote")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:p("projects.form.description")}),e.jsx("textarea",{value:u.description,onChange:c=>w({...u,description:c.target.value}),placeholder:p("projects.form.descriptionPlaceholder"),rows:3,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"})]})]}),e.jsxs("div",{className:"flex justify-end space-x-3 mt-6",children:[e.jsx("button",{type:"button",onClick:M,className:"px-4 py-2 text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700",children:p("projects.form.cancel")}),e.jsx("button",{type:"submit",disabled:!u.name||!u.agentId,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:p("projects.createButton")})]})]})]}),y&&e.jsx(Qe,{title:p("projects.form.directory"),initialPath:h(u.directory),allowFiles:!1,allowDirectories:!0,allowNewDirectory:!0,onSelect:(c,j)=>{j&&(w({...u,directory:c}),v(!1))},onClose:()=>v(!1)})]}):null},xa=()=>{const{t:l}=me("pages"),{data:M}=Et(),[t,r]=o.useState([]),[p,u]=o.useState(!0),[w,y]=o.useState(""),[v,h]=o.useState(!1),[A,g]=o.useState(null),[c,j]=o.useState(null),[F,U]=o.useState(null),[R,K]=o.useState(null),[O,x]=o.useState(null),[d,m]=o.useState(null),[S,C]=o.useState(!1),[B,H]=o.useState(""),[je,G]=o.useState(!1),s=(M?.agents||[]).filter(n=>n.enabled),b=async()=>{try{u(!0);const n=await P(`${E}/projects`);if(n.ok){const f=await n.json();r(f.projects||[])}else console.error("Failed to fetch projects:",n.status),r([])}catch(n){console.error("Failed to fetch projects:",n),r([])}finally{u(!1)}};o.useEffect(()=>{b()},[]);const D=t.filter(n=>n.name.toLowerCase().includes(w.toLowerCase())||n.description?.toLowerCase().includes(w.toLowerCase())||n.defaultAgentName.toLowerCase().includes(w.toLowerCase())).sort((n,f)=>new Date(f.lastAccessed).getTime()-new Date(n.lastAccessed).getTime()),J=async n=>{try{const f=await P(`${E}/projects/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentId:n.agentId,projectName:n.name,parentDirectory:n.directory,description:n.description})});if(f.ok){const k=await f.json();r(q=>[k.project,...q]),h(!1);const $=new URLSearchParams;$.set("project",k.project.path);const L=`/chat/${n.agentId}?${$.toString()}`;window.open(L,"_blank")}else{const k=await f.json();throw new Error(k.error||l("projects.errors.createFailed"))}}catch(f){console.error("Failed to create project:",f),I(l("projects.errors.createFailed"),f instanceof Error?f.message:l("errors:common.unknownError"))}},fe=async n=>{if(n.agents.length>0&&!n.defaultAgent){m(n);return}const f=n.defaultAgent||"claude-code";console.log("Opening project:",n.name,"with agent:",f);const k=new URLSearchParams;k.set("project",n.path);const $=`/chat/${f}?${k.toString()}`;console.log("Generated URL:",$),window.open($,"_blank"),r(L=>L.map(q=>q.id===n.id?{...q,lastAccessed:new Date().toISOString()}:q))},ne=async n=>{if(window.confirm(`${l("projects.deleteConfirm")}
|
|
18
|
+
|
|
19
|
+
${l("projects.deleteNote")}`))try{const k=await P(`${E}/projects/by-id/${n.id}`,{method:"DELETE"});if(k.ok)r($=>$.filter(L=>L.id!==n.id));else{const $=await k.json();throw new Error($.error||l("projects.errors.deleteFailed"))}}catch(k){console.error("Failed to delete project:",k),I(l("projects.errors.deleteFailed"),k instanceof Error?k.message:l("errors:common.unknownError"))}},le=n=>{g(n)},de=n=>{j(n)},X=n=>{U(n)},Pe=n=>{K(n)},Ne=n=>{x(n)},ge=(n,f)=>{r(k=>k.map($=>$.id===n?{...$,defaultAgent:f.id,defaultAgentName:f.name,defaultAgentIcon:f.ui.icon,lastAccessed:new Date().toISOString()}:$))},ke=async n=>{if(d)try{const f=await P(`${E}/projects/${encodeURIComponent(d.path)}/select-agent`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentId:n})});if(f.ok){const k=await f.json();r(q=>q.map(V=>V.id===d.id?k.project:V)),m(null);const $=new URLSearchParams;$.set("project",k.project.path);const L=`/chat/${n}?${$.toString()}`;window.open(L,"_blank")}else{const k=await f.json();I(l("errors:agent.setFailed"),k.error||l("errors:common.unknownError"))}}catch(f){console.error("Failed to select agent:",f),I(l("errors:agent.setFailed"),f instanceof Error?f.message:l("errors:common.unknownError"))}},he=async()=>{if(B.trim())try{const n=await P(`${E}/files/browse?path=${encodeURIComponent(B)}`);if(!n.ok)throw new Error("目录不存在或无法访问");if(!(await n.json()).isDirectory)throw new Error("请选择一个目录");const k=s[0];if(!k)throw new Error("没有可用的代理");const $=await P(`${E}/projects/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentId:k.id,projectPath:B})});if($.ok){const L=await $.json();if(r(V=>[L.project,...V]),C(!1),H(""),window.confirm(`项目 "${L.project.name}" 导入成功!
|
|
20
|
+
|
|
21
|
+
是否立即打开该项目?`))if(s.length>1)m(L.project);else{const V=new URLSearchParams;V.set("project",L.project.path);const we=`/chat/${k.id}?${V.toString()}`;window.open(we,"_blank")}}else{const L=await $.json();throw new Error(L.error||"导入项目失败")}}catch(n){console.error("Failed to import project:",n),I("导入项目失败",n instanceof Error?n.message:"未知错误")}},Ee=(n,f)=>{f&&(H(n),G(!1))};return p?e.jsx("div",{className:"p-8 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:l("projects.loading")})]})}):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.jsx("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white",children:l("projects.title")}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:l("projects.subtitle")})]})}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(Re,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-5 h-5"}),e.jsx("input",{type:"text",placeholder:l("projects.searchPlaceholder"),value:w,onChange:n=>y(n.target.value),className:"pl-10 pr-4 py-3 w-full 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.jsxs("button",{onClick:()=>C(!0),className:"flex items-center space-x-2 px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 hover:shadow-md active:scale-95 transition-all whitespace-nowrap font-medium",children:[e.jsx(Pt,{className:"w-5 h-5"}),e.jsx("span",{children:"导入项目"})]}),e.jsxs("button",{onClick:()=>h(!0),className:"flex items-center space-x-2 px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors whitespace-nowrap",children:[e.jsx(xe,{className:"w-5 h-5"}),e.jsx("span",{children:l("projects.createButton")})]})]})]}),D.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("div",{className:"text-6xl mb-4",children:"📁"}),e.jsx("h3",{className:"text-xl font-medium text-gray-900 dark:text-white mb-2",children:l("projects.noProjects")}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:l("projects.selectType")}),!w&&e.jsx("button",{onClick:()=>h(!0),className:"px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:l("projects.createButton")})]}):e.jsx(zt,{projects:D,agents:s,onOpenProject:fe,onMemoryManagement:le,onCommandManagement:de,onSubAgentManagement:X,onA2AManagement:Pe,onSettings:Ne,onDeleteProject:ne,onAgentChanged:ge}),S&&e.jsx("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-md mx-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"导入项目"}),e.jsx("button",{onClick:()=>{C(!1),H("")},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:"p-6",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"项目目录路径"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("input",{type:"text",value:B,onChange:n=>H(n.target.value),placeholder:"请选择或输入项目目录路径",className:"flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-transparent dark:bg-gray-700 dark:text-white"}),e.jsx("button",{type:"button",onClick:()=>G(!0),className:"px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700",title:"选择目录",children:e.jsx(Le,{className:"w-4 h-4 text-gray-600 dark:text-gray-400"})})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:"选择要导入的现有项目目录"})]}),e.jsx("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-3 mb-4",children:e.jsxs("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:[e.jsx("strong",{children:"说明:"}),"导入的目录将被添加到项目中,并关联到第一个可用的代理。"]})}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{type:"button",onClick:()=>{C(!1),H("")},className:"px-4 py-2 text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700",children:"取消"}),e.jsx("button",{type:"button",onClick:he,disabled:!B.trim(),className:"px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 disabled:opacity-50 disabled:cursor-not-allowed",children:"导入项目"})]})]})]})}),e.jsx(Vt,{isOpen:v,onClose:()=>h(!1),onConfirm:J,agents:s}),A&&e.jsx(Ot,{project:A,onClose:()=>g(null)}),c&&e.jsx(Bt,{project:c,onClose:()=>j(null)}),F&&e.jsx(Ht,{project:F,onClose:()=>U(null)}),R&&e.jsx(Jt,{project:R,onClose:()=>K(null)}),e.jsx(qt,{isOpen:!!O,project:O,onClose:()=>x(null),onSaved:()=>b()}),d&&e.jsx("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-md mx-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:l("projects.selectType")}),e.jsx("button",{onClick:()=>m(null),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:"p-6",children:[e.jsx("div",{className:"mb-4",children:e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-4",children:l("projects.selectType")})}),e.jsx("div",{className:"space-y-3",children:s.map(n=>e.jsx("button",{onClick:()=>ke(n.id),className:"w-full p-4 text-left border border-gray-200 dark:border-gray-700 rounded-lg hover:border-blue-300 dark:hover:border-blue-600 hover:bg-blue-50 dark:hover:bg-blue-900/50 transition-colors",children:e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"text-2xl",children:n.ui.icon}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:n.name}),e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:n.description})]})]})},n.id))}),e.jsx("div",{className:"flex justify-end mt-6",children:e.jsx("button",{onClick:()=>m(null),className:"px-4 py-2 text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700",children:l("projects.form.cancel")})})]})]})}),je&&e.jsx(Qe,{title:"选择项目目录",allowFiles:!1,allowDirectories:!0,onSelect:Ee,onClose:()=>G(!1)})]})};export{xa as ProjectsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./data-structures-C0h9Oap1.js";import{r as i,W as ve}from"./monaco-editor-DHKm5-VF.js";import{T as ue,a as ge,b as Y,c as N,d as he,e as j}from"./table-CUyJSNAf.js";import{b as z,u as I,c as P,a as k,A as w}from"./agents-DG431Wop.js";import{u as Ne}from"./useAgents-Bp5Ry-Dk.js";import{u as Se}from"./useProjects-DuCnMeYt.js";import{u as Ce}from"./useClaudeVersions-DYM2HCGW.js";import{a as g,s as C}from"./index-h5dd40hU.js";import{m as O,t as Te,f as Ee,ax as ce,k as me,a5 as Ae,ay as ye,af as pe,a3 as Ie,az as $e,L as ae,l as qe,e as oe,n as be,C as fe,A as Me,r as Fe,v as xe,aA as Pe,aB as Re,U as De,aC as Ke,J as Oe,y as Qe,X as Le}from"./ui-components-CRCmgMKc.js";import"./syntax-highlighting-CnREyncB.js";import"./tools-C0JOzoE_.js";const d={all:["scheduled-tasks"],lists:()=>[...d.all,"list"],list:()=>[...d.lists()],details:()=>[...d.all,"detail"],detail:t=>[...d.details(),t],history:t=>[...d.all,"history",t],status:()=>[...d.all,"status"]},Ve=()=>z({queryKey:d.list(),queryFn:async()=>{const t=await k(`${w}/scheduled-tasks`);if(!t.ok)throw new Error("Failed to fetch scheduled tasks");return t.json()},refetchInterval:t=>t.state.data?.some(c=>c.lastRunStatus==="running")?3e3:!1}),He=(t,n=50)=>z({queryKey:d.history(t),queryFn:async()=>{const l=await k(`${w}/scheduled-tasks/${t}/history?limit=${n}`);if(!l.ok)throw new Error("Failed to fetch task execution history");return l.json()},enabled:!!t,refetchInterval:l=>l.state.data?.some($=>$.status==="running")?3e3:!1}),Be=()=>z({queryKey:d.status(),queryFn:async()=>{const t=await k(`${w}/scheduled-tasks/status`);if(!t.ok)throw new Error("Failed to fetch scheduler status");return t.json()},refetchInterval:3e4}),ze=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/scheduled-tasks`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to create scheduled task")}return l.json()},onSuccess:()=>{t.invalidateQueries({queryKey:d.lists()}),t.invalidateQueries({queryKey:d.status()})}})},Ue=()=>{const t=I();return P({mutationFn:async({taskId:n,data:l})=>{const c=await k(`${w}/scheduled-tasks/${n}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!c.ok){const p=await c.json().catch(()=>({}));throw new Error(p.error||"Failed to update scheduled task")}return c.json()},onSuccess:n=>{t.invalidateQueries({queryKey:d.lists()}),t.invalidateQueries({queryKey:d.detail(n.id)}),t.invalidateQueries({queryKey:d.status()})}})},_e=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/scheduled-tasks/${n}`,{method:"DELETE"});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to delete scheduled task")}},onSuccess:()=>{t.invalidateQueries({queryKey:d.lists()}),t.invalidateQueries({queryKey:d.status()})}})},Je=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/scheduled-tasks/${n}/toggle`,{method:"POST"});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to toggle scheduled task")}return l.json()},onSuccess:n=>{t.invalidateQueries({queryKey:d.lists()}),t.invalidateQueries({queryKey:d.detail(n.id)}),t.invalidateQueries({queryKey:d.status()})}})},je=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/scheduled-tasks/${n}/run`,{method:"POST"});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to run scheduled task")}return l.json()},onSuccess:(n,l)=>{t.invalidateQueries({queryKey:d.detail(l)}),t.invalidateQueries({queryKey:d.lists()}),t.invalidateQueries({queryKey:d.history(l)})}})},We=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/scheduled-tasks/executions/${n}/stop`,{method:"POST"});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to stop execution")}return l.json()},onSuccess:()=>{t.invalidateQueries({queryKey:d.all})}})},Xe=()=>z({queryKey:[...d.all,"running"],queryFn:async()=>{const t=await k(`${w}/scheduled-tasks/running`);if(!t.ok)throw new Error("Failed to fetch running executions");return t.json()},refetchInterval:3e3}),Ge=()=>{const t=I();return P({mutationFn:async()=>{const n=await k(`${w}/scheduled-tasks/scheduler/enable`,{method:"POST"});if(!n.ok){const l=await n.json().catch(()=>({}));throw new Error(l.error||"Failed to enable scheduler")}return n.json()},onSuccess:()=>{t.invalidateQueries({queryKey:d.status()})}})},Ye=()=>{const t=I();return P({mutationFn:async()=>{const n=await k(`${w}/scheduled-tasks/scheduler/disable`,{method:"POST"});if(!n.ok){const l=await n.json().catch(()=>({}));throw new Error(l.error||"Failed to disable scheduler")}return n.json()},onSuccess:()=>{t.invalidateQueries({queryKey:d.status()})}})},Z={all:["task-executor"],stats:()=>[...Z.all,"stats"],health:()=>[...Z.all,"health"]},Ze=()=>z({queryKey:Z.stats(),queryFn:async()=>{const t=await k(`${w}/task-executor/stats`);if(!t.ok)throw new Error("Failed to fetch task executor stats");return t.json()},refetchInterval:5e3}),et=()=>z({queryKey:[...Z.all,"config"],queryFn:async()=>{const t=await k(`${w}/task-executor/config`);if(!t.ok)throw new Error("Failed to fetch task executor config");return t.json()}}),tt=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/task-executor/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to update executor config")}return l.json()},onSuccess:()=>{t.invalidateQueries({queryKey:Z.all})}})},rt=[{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 * *"}],st=t=>{if(!t){const n=new Date;return n.setHours(n.getHours()+1),n.setMinutes(0),n.setSeconds(0),n.toISOString().slice(0,16)}return new Date(t).toISOString().slice(0,16)},at=t=>new Date(t).toISOString(),nt=({task:t,agents:n,onSave:l,onCancel:c})=>{const p=!!t,$=ze(),Q=Ue(),L=je(),{data:U}=Se(),R=U?.projects||[],{data:o}=Ce(),[v,_]=i.useState(t?.name||""),[S,J]=i.useState(t?.description||""),[b,q]=i.useState(t?.agentId||""),[f,V]=i.useState(t?.projectPath||""),[m,s]=i.useState(t?.schedule.type||"interval"),[x,u]=i.useState(t?.schedule.intervalMinutes||30),[h,H]=i.useState(t?.schedule.cronExpression||"*/30 * * * *"),[W,ee]=i.useState(st(t?.schedule.executeAt)),[M,ne]=i.useState(t?.triggerMessage||""),[E,le]=i.useState(t?.enabled??!0),[T,de]=i.useState(!!t?.modelOverride?.modelId),[A,te]=i.useState(t?.modelOverride?.versionId||""),[K,B]=i.useState(t?.modelOverride?.modelId||""),[X,re]=i.useState(!1),[G,r]=i.useState(!1),y=i.useMemo(()=>o?.versions?A?o.versions.find(ie=>ie.id===A)?.models||[]:(o.versions.find(D=>D.id===o.defaultVersionId)||o.versions[0])?.models||[]:[],[o,A]);i.useEffect(()=>{T&&o?.versions&&A&&(o.versions.some(D=>D.id===A)||(te(o.defaultVersionId||""),B("")))},[o,A,T]),i.useEffect(()=>{T&&y.length>0&&(y.some(D=>D.id===K)||B(y[0].id))},[y,K,T]),i.useEffect(()=>{!b&&n.length>0&&q(n[0].id)},[b,n]),i.useEffect(()=>{!f&&R.length>0&&V(R[0].path)},[f,R]);const F=()=>m==="interval"?{type:"interval",intervalMinutes:x}:m==="once"?{type:"once",executeAt:at(W)}:{type:"cron",cronExpression:h},se=()=>{if(!(!T||!K))return{versionId:A||void 0,modelId:K}},ke=async()=>{if(!v.trim()){g("请输入任务名称");return}if(!b){g("请选择 Agent");return}if(!f){g("请选择项目路径");return}if(!M.trim()){g("请输入触发消息");return}if(m==="interval"&&(!x||x<1)){g("间隔时间必须大于 0");return}if(m==="cron"&&!h.trim()){g("请输入 Cron 表达式");return}if(m==="once"){const a=new Date(W).getTime();if(isNaN(a)){g("请选择有效的执行时间");return}if(a<=Date.now()){g("执行时间必须在未来");return}}re(!0);try{if(p)await Q.mutateAsync({taskId:t.id,data:{name:v.trim(),description:S.trim()||void 0,agentId:b,projectPath:f,schedule:F(),triggerMessage:M.trim(),enabled:E,modelOverride:se()}}),C("任务已更新");else{const a={name:v.trim(),description:S.trim()||void 0,agentId:b,projectPath:f,schedule:F(),triggerMessage:M.trim(),enabled:E,modelOverride:se()};await $.mutateAsync(a),C("任务已创建")}l()}catch{g(p?"更新失败":"创建失败")}finally{re(!1)}},we=async()=>{if(!v.trim()){g("请输入任务名称");return}if(!b){g("请选择 Agent");return}if(!f){g("请选择项目路径");return}if(!M.trim()){g("请输入触发消息");return}r(!0);try{let a;if(p)await Q.mutateAsync({taskId:t.id,data:{name:v.trim(),description:S.trim()||void 0,agentId:b,projectPath:f,schedule:F(),triggerMessage:M.trim(),enabled:E,modelOverride:se()}}),a=t.id,C("任务已更新");else{const D={name:v.trim(),description:S.trim()||void 0,agentId:b,projectPath:f,schedule:F(),triggerMessage:M.trim(),enabled:E,modelOverride:se()};a=(await $.mutateAsync(D)).id,C("任务已创建")}await L.mutateAsync(a),C("任务已开始执行,请在执行历史中查看结果"),l()}catch{g("操作失败")}finally{r(!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:p?"编辑定时任务":"创建定时任务"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"配置 Agent 的自动执行计划"})]}),e.jsx("button",{onClick:c,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(O,{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:v,onChange:a=>_(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:S,onChange:a=>J(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(Te,{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:b,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:n.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(Ee,{className:"w-4 h-4"}),"项目路径 *"]}),e.jsx("select",{value:f,onChange:a=>V(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:()=>de(!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 默认的模型"}),o?.versions&&o.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:A,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:o.defaultVersionId?`默认 (${o.versions.find(a=>a.id===o.defaultVersionId)?.name})`:"默认"}),o.versions.filter(a=>a.id!==o.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"})})]})]}),y.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:y.map(a=>e.jsxs("button",{type:"button",onClick:()=>B(a.id),className:`flex items-center justify-between px-3 py-2 text-sm rounded-lg border transition-all ${K===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(O,{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:m==="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:m==="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:m==="once",onChange:()=>s("once"),className:"mr-2"}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300",children:"仅执行一次"})]})]}),m==="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:x,onChange:a=>u(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:["每隔 ",x," 分钟执行一次"]})]}),m==="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:h,onChange:a=>H(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:rt.map(a=>e.jsx("button",{type:"button",onClick:()=>H(a.value),className:`px-2 py-1 text-xs rounded-full border transition-colors ${h===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))})]}),m==="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(Ae,{className:"w-4 h-4"}),"执行时间"]}),e.jsx("input",{type:"datetime-local",value:W,onChange:a=>ee(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:M,onChange:a=>ne(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:()=>le(!E),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${E?"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 ${E?"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:c,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:X||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:X||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(Ie,{className:"w-4 h-4 mr-2"}),X?"保存中...":"保存"]})]})]})]})})]})})},lt=({taskId:t,taskName:n,agentId:l,projectPath:c,onBack:p})=>{const{data:$=[],isLoading:Q}=He(t),[L,U]=i.useState(new Set),R=s=>{U(x=>{const u=new Set(x);return u.has(s)?u.delete(s):u.add(s),u})},o=s=>s?new Date(s).toLocaleString("zh-CN"):"-",v=s=>new Date(s).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3}),_=s=>{if(!s.completedAt)return"-";const x=new Date(s.startedAt).getTime(),h=new Date(s.completedAt).getTime()-x;return h<1e3?`${h}ms`:h<6e4?`${(h/1e3).toFixed(1)}s`:`${Math.floor(h/6e4)}m ${Math.floor(h%6e4/1e3)}s`},S=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(O,{className:"w-5 h-5 text-gray-400"})}},J=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:"未知"})}},b=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"}},f=s=>{const x=s.agentId||l,u=s.projectPath||c;if(!x||!s.sessionId)return null;let h=`/chat/${encodeURIComponent(x)}?session=${encodeURIComponent(s.sessionId)}`;return u&&(h+=`&project=${encodeURIComponent(u)}`),h},V=(s,x)=>{x.stopPropagation();const u=f(s);u&&window.open(u,"_blank")},m=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((x,u)=>e.jsxs("div",{className:`flex items-start gap-2 px-3 py-1.5 rounded text-sm font-mono ${b(x.level)}`,children:[e.jsx("span",{className:"text-gray-400 dark:text-gray-500 shrink-0 w-24",children:v(x.timestamp)}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs shrink-0 ${q(x.type)}`,children:x.type}),e.jsx("span",{className:"flex-1 break-all whitespace-pre-wrap",children:x.message})]},u))});return e.jsxs("div",{className:"p-8",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("button",{onClick:p,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($e,{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:["任务:",n]})]})]}),Q?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"})}):$.length===0?e.jsxs("div",{className:"text-center py-12 bg-gray-50 dark:bg-gray-800 rounded-lg",children:[e.jsx(O,{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(N,{className:"w-[40px]"}),e.jsx(N,{className:"w-[80px]",children:"状态"}),e.jsx(N,{children:"开始时间"}),e.jsx(N,{children:"完成时间"}),e.jsx(N,{children:"耗时"}),e.jsx(N,{children:"结果摘要"}),e.jsx(N,{className:"w-[100px]",children:"操作"})]})}),e.jsx(he,{children:$.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(j,{className:"p-2",children:e.jsx("button",{className:"p-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded",children:L.has(s.id)?e.jsx(me,{className:"w-4 h-4 text-gray-500"}):e.jsx(qe,{className:"w-4 h-4 text-gray-500"})})}),e.jsx(j,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[S(s.status),J(s.status)]})}),e.jsx(j,{children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:o(s.startedAt)})}),e.jsx(j,{children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:o(s.completedAt)})}),e.jsx(j,{children:e.jsx("span",{className:"text-sm font-mono text-gray-600 dark:text-gray-400",children:_(s)})}),e.jsx(j,{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(j,{children:s.sessionId&&f(s)&&e.jsx("button",{onClick:x=>V(s,x),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"})})})]}),L.has(s.id)&&e.jsx(Y,{children:e.jsx(j,{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," 条)"]})]}),m(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))})]})})]})},bt=()=>{const t=I(),{data:n=[],isLoading:l}=Ve(),{data:c}=Ne(!0),{data:p}=Be(),$=_e(),Q=Je(),L=je(),U=We(),{data:R}=Xe(),o=Ge(),v=Ye(),[_,S]=i.useState(null),[J,b]=i.useState(!1),[q,f]=i.useState(null),[V,m]=i.useState(!1),[s,x]=i.useState(2),{data:u}=Ze(),{data:h}=et(),H=tt(),W=r=>R?.executions?.find(F=>F.taskId===r)?.executionId||null,ee=c?.agents||[],M=r=>ee.find(F=>F.id===r)?.name||r,ne=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")}`:"-"},E=r=>r?new Date(r).toLocaleString("zh-CN"):"-",le=async r=>{try{await Q.mutateAsync(r.id),C(r.enabled?"任务已暂停":"任务已启用")}catch{g("操作失败")}},T=async r=>{if(confirm(`确定要删除任务 "${r.name}" 吗?`))try{await $.mutateAsync(r.id),C("任务已删除")}catch{g("删除失败")}},de=async r=>{try{await L.mutateAsync(r.id),C("任务已开始执行"),t.invalidateQueries({queryKey:d.lists()})}catch{g("执行失败")}},A=async r=>{const y=W(r.id);if(!y){g("找不到正在运行的执行");return}try{await U.mutateAsync(y),C("任务已停止"),t.invalidateQueries({queryKey:d.lists()})}catch{g("停止失败")}},te=async()=>{if(p)try{p.enabled?(await v.mutateAsync(),C("调度器已禁用")):(await o.mutateAsync(),C("调度器已启用"))}catch{g("操作失败")}},K=r=>{S(r),b(!0)},B=()=>{S(null),b(!0)},X=()=>{S(null),b(!1),t.invalidateQueries({queryKey:d.lists()})},re=()=>{S(null),b(!1)},G=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(q){const r=n.find(y=>y.id===q);return e.jsx(lt,{taskId:q,taskName:r?.name||q,agentId:r?.agentId,projectPath:r?.projectPath,onBack:()=>f(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(O,{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:[p&&e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs("button",{onClick:te,disabled:o.isPending||v.isPending,className:`flex items-center gap-2 px-3 py-1.5 rounded-lg transition-colors ${p.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"} ${o.isPending||v.isPending?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,title:p.enabled?"点击禁用调度器":"点击启用调度器",children:[e.jsx(O,{className:`w-4 h-4 ${o.isPending||v.isPending?"animate-pulse":""}`}),e.jsx("span",{className:"font-medium",children:p.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(Me,{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:()=>{h&&x(h.maxConcurrent),m(!0)},className:"ml-2 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors",title:"执行器设置",children:e.jsx(Fe,{className:"w-4 h-4"})})]})]}),e.jsxs("button",{onClick:B,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"}),"新建任务"]})]})]}),l?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(O,{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:B,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(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"状态"}),e.jsx(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"任务名称"}),e.jsx(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Agent"}),e.jsx(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"调度规则"}),e.jsx(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"上次执行"}),e.jsx(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"下次执行"}),e.jsx(N,{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(j,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("button",{onClick:()=>le(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(Pe,{className:"w-5 h-5"})})}),e.jsx(j,{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(j,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:M(r.agentId)})}),e.jsx(j,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm font-mono text-gray-600 dark:text-gray-400",children:ne(r)})}),e.jsx(j,{className:"px-6 py-4",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[G(r),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:E(r.lastRunAt)})]})}),e.jsx(j,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:r.enabled?E(r.nextRunAt):"-"})}),e.jsx(j,{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:()=>A(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(Re,{className:"w-4 h-4"})}):e.jsx("button",{onClick:()=>de(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(De,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>f(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(Ke,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>K(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(Oe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>T(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(Qe,{className:"w-4 h-4"})})]})})]},r.id))})]})}),J&&e.jsx(nt,{task:_,agents:ee,onSave:X,onCancel:re}),V&&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:()=>m(!1),className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700",children:e.jsx(Le,{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:s,onChange:r=>x(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:"允许同时执行的最大任务数量"})]}),h&&e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:["当前配置: 并发 ",h.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:()=>m(!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 H.mutateAsync({maxConcurrent:s}),C(`并发数已更新为 ${s}`),m(!1)}catch(r){g(r instanceof Error?r.message:"更新失败")}},disabled:H.isPending,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:H.isPending?"保存中...":"保存"})]})]})})]})};export{bt as ScheduledTasksPage,bt as default};
|
|
1
|
+
import{j as e}from"./data-structures-C0h9Oap1.js";import{r as i,W as ve}from"./monaco-editor-DHKm5-VF.js";import{T as ue,a as ge,b as Y,c as N,d as he,e as j}from"./table-F592JIUY.js";import{b as z,u as I,c as P,a as k,A as w}from"./agents-DG431Wop.js";import{u as Ne}from"./useAgents-Bp5Ry-Dk.js";import{u as Se}from"./useProjects-DuCnMeYt.js";import{u as Ce}from"./useClaudeVersions-DYM2HCGW.js";import{a as g,s as C}from"./index-D9bAK8SN.js";import{m as O,t as Te,f as Ee,ax as ce,k as me,a5 as Ae,ay as ye,af as pe,a3 as Ie,az as $e,L as ae,l as qe,e as oe,n as be,C as fe,A as Me,r as Fe,v as xe,aA as Pe,aB as Re,U as De,aC as Ke,J as Oe,y as Qe,X as Le}from"./ui-components-CRCmgMKc.js";import"./syntax-highlighting-CnREyncB.js";import"./tools-C0JOzoE_.js";const d={all:["scheduled-tasks"],lists:()=>[...d.all,"list"],list:()=>[...d.lists()],details:()=>[...d.all,"detail"],detail:t=>[...d.details(),t],history:t=>[...d.all,"history",t],status:()=>[...d.all,"status"]},Ve=()=>z({queryKey:d.list(),queryFn:async()=>{const t=await k(`${w}/scheduled-tasks`);if(!t.ok)throw new Error("Failed to fetch scheduled tasks");return t.json()},refetchInterval:t=>t.state.data?.some(c=>c.lastRunStatus==="running")?3e3:!1}),He=(t,n=50)=>z({queryKey:d.history(t),queryFn:async()=>{const l=await k(`${w}/scheduled-tasks/${t}/history?limit=${n}`);if(!l.ok)throw new Error("Failed to fetch task execution history");return l.json()},enabled:!!t,refetchInterval:l=>l.state.data?.some($=>$.status==="running")?3e3:!1}),Be=()=>z({queryKey:d.status(),queryFn:async()=>{const t=await k(`${w}/scheduled-tasks/status`);if(!t.ok)throw new Error("Failed to fetch scheduler status");return t.json()},refetchInterval:3e4}),ze=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/scheduled-tasks`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to create scheduled task")}return l.json()},onSuccess:()=>{t.invalidateQueries({queryKey:d.lists()}),t.invalidateQueries({queryKey:d.status()})}})},Ue=()=>{const t=I();return P({mutationFn:async({taskId:n,data:l})=>{const c=await k(`${w}/scheduled-tasks/${n}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!c.ok){const p=await c.json().catch(()=>({}));throw new Error(p.error||"Failed to update scheduled task")}return c.json()},onSuccess:n=>{t.invalidateQueries({queryKey:d.lists()}),t.invalidateQueries({queryKey:d.detail(n.id)}),t.invalidateQueries({queryKey:d.status()})}})},_e=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/scheduled-tasks/${n}`,{method:"DELETE"});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to delete scheduled task")}},onSuccess:()=>{t.invalidateQueries({queryKey:d.lists()}),t.invalidateQueries({queryKey:d.status()})}})},Je=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/scheduled-tasks/${n}/toggle`,{method:"POST"});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to toggle scheduled task")}return l.json()},onSuccess:n=>{t.invalidateQueries({queryKey:d.lists()}),t.invalidateQueries({queryKey:d.detail(n.id)}),t.invalidateQueries({queryKey:d.status()})}})},je=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/scheduled-tasks/${n}/run`,{method:"POST"});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to run scheduled task")}return l.json()},onSuccess:(n,l)=>{t.invalidateQueries({queryKey:d.detail(l)}),t.invalidateQueries({queryKey:d.lists()}),t.invalidateQueries({queryKey:d.history(l)})}})},We=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/scheduled-tasks/executions/${n}/stop`,{method:"POST"});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to stop execution")}return l.json()},onSuccess:()=>{t.invalidateQueries({queryKey:d.all})}})},Xe=()=>z({queryKey:[...d.all,"running"],queryFn:async()=>{const t=await k(`${w}/scheduled-tasks/running`);if(!t.ok)throw new Error("Failed to fetch running executions");return t.json()},refetchInterval:3e3}),Ge=()=>{const t=I();return P({mutationFn:async()=>{const n=await k(`${w}/scheduled-tasks/scheduler/enable`,{method:"POST"});if(!n.ok){const l=await n.json().catch(()=>({}));throw new Error(l.error||"Failed to enable scheduler")}return n.json()},onSuccess:()=>{t.invalidateQueries({queryKey:d.status()})}})},Ye=()=>{const t=I();return P({mutationFn:async()=>{const n=await k(`${w}/scheduled-tasks/scheduler/disable`,{method:"POST"});if(!n.ok){const l=await n.json().catch(()=>({}));throw new Error(l.error||"Failed to disable scheduler")}return n.json()},onSuccess:()=>{t.invalidateQueries({queryKey:d.status()})}})},Z={all:["task-executor"],stats:()=>[...Z.all,"stats"],health:()=>[...Z.all,"health"]},Ze=()=>z({queryKey:Z.stats(),queryFn:async()=>{const t=await k(`${w}/task-executor/stats`);if(!t.ok)throw new Error("Failed to fetch task executor stats");return t.json()},refetchInterval:5e3}),et=()=>z({queryKey:[...Z.all,"config"],queryFn:async()=>{const t=await k(`${w}/task-executor/config`);if(!t.ok)throw new Error("Failed to fetch task executor config");return t.json()}}),tt=()=>{const t=I();return P({mutationFn:async n=>{const l=await k(`${w}/task-executor/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||"Failed to update executor config")}return l.json()},onSuccess:()=>{t.invalidateQueries({queryKey:Z.all})}})},rt=[{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 * *"}],st=t=>{if(!t){const n=new Date;return n.setHours(n.getHours()+1),n.setMinutes(0),n.setSeconds(0),n.toISOString().slice(0,16)}return new Date(t).toISOString().slice(0,16)},at=t=>new Date(t).toISOString(),nt=({task:t,agents:n,onSave:l,onCancel:c})=>{const p=!!t,$=ze(),Q=Ue(),L=je(),{data:U}=Se(),R=U?.projects||[],{data:o}=Ce(),[v,_]=i.useState(t?.name||""),[S,J]=i.useState(t?.description||""),[b,q]=i.useState(t?.agentId||""),[f,V]=i.useState(t?.projectPath||""),[m,s]=i.useState(t?.schedule.type||"interval"),[x,u]=i.useState(t?.schedule.intervalMinutes||30),[h,H]=i.useState(t?.schedule.cronExpression||"*/30 * * * *"),[W,ee]=i.useState(st(t?.schedule.executeAt)),[M,ne]=i.useState(t?.triggerMessage||""),[E,le]=i.useState(t?.enabled??!0),[T,de]=i.useState(!!t?.modelOverride?.modelId),[A,te]=i.useState(t?.modelOverride?.versionId||""),[K,B]=i.useState(t?.modelOverride?.modelId||""),[X,re]=i.useState(!1),[G,r]=i.useState(!1),y=i.useMemo(()=>o?.versions?A?o.versions.find(ie=>ie.id===A)?.models||[]:(o.versions.find(D=>D.id===o.defaultVersionId)||o.versions[0])?.models||[]:[],[o,A]);i.useEffect(()=>{T&&o?.versions&&A&&(o.versions.some(D=>D.id===A)||(te(o.defaultVersionId||""),B("")))},[o,A,T]),i.useEffect(()=>{T&&y.length>0&&(y.some(D=>D.id===K)||B(y[0].id))},[y,K,T]),i.useEffect(()=>{!b&&n.length>0&&q(n[0].id)},[b,n]),i.useEffect(()=>{!f&&R.length>0&&V(R[0].path)},[f,R]);const F=()=>m==="interval"?{type:"interval",intervalMinutes:x}:m==="once"?{type:"once",executeAt:at(W)}:{type:"cron",cronExpression:h},se=()=>{if(!(!T||!K))return{versionId:A||void 0,modelId:K}},ke=async()=>{if(!v.trim()){g("请输入任务名称");return}if(!b){g("请选择 Agent");return}if(!f){g("请选择项目路径");return}if(!M.trim()){g("请输入触发消息");return}if(m==="interval"&&(!x||x<1)){g("间隔时间必须大于 0");return}if(m==="cron"&&!h.trim()){g("请输入 Cron 表达式");return}if(m==="once"){const a=new Date(W).getTime();if(isNaN(a)){g("请选择有效的执行时间");return}if(a<=Date.now()){g("执行时间必须在未来");return}}re(!0);try{if(p)await Q.mutateAsync({taskId:t.id,data:{name:v.trim(),description:S.trim()||void 0,agentId:b,projectPath:f,schedule:F(),triggerMessage:M.trim(),enabled:E,modelOverride:se()}}),C("任务已更新");else{const a={name:v.trim(),description:S.trim()||void 0,agentId:b,projectPath:f,schedule:F(),triggerMessage:M.trim(),enabled:E,modelOverride:se()};await $.mutateAsync(a),C("任务已创建")}l()}catch{g(p?"更新失败":"创建失败")}finally{re(!1)}},we=async()=>{if(!v.trim()){g("请输入任务名称");return}if(!b){g("请选择 Agent");return}if(!f){g("请选择项目路径");return}if(!M.trim()){g("请输入触发消息");return}r(!0);try{let a;if(p)await Q.mutateAsync({taskId:t.id,data:{name:v.trim(),description:S.trim()||void 0,agentId:b,projectPath:f,schedule:F(),triggerMessage:M.trim(),enabled:E,modelOverride:se()}}),a=t.id,C("任务已更新");else{const D={name:v.trim(),description:S.trim()||void 0,agentId:b,projectPath:f,schedule:F(),triggerMessage:M.trim(),enabled:E,modelOverride:se()};a=(await $.mutateAsync(D)).id,C("任务已创建")}await L.mutateAsync(a),C("任务已开始执行,请在执行历史中查看结果"),l()}catch{g("操作失败")}finally{r(!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:p?"编辑定时任务":"创建定时任务"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"配置 Agent 的自动执行计划"})]}),e.jsx("button",{onClick:c,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(O,{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:v,onChange:a=>_(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:S,onChange:a=>J(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(Te,{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:b,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:n.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(Ee,{className:"w-4 h-4"}),"项目路径 *"]}),e.jsx("select",{value:f,onChange:a=>V(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:()=>de(!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 默认的模型"}),o?.versions&&o.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:A,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:o.defaultVersionId?`默认 (${o.versions.find(a=>a.id===o.defaultVersionId)?.name})`:"默认"}),o.versions.filter(a=>a.id!==o.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"})})]})]}),y.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:y.map(a=>e.jsxs("button",{type:"button",onClick:()=>B(a.id),className:`flex items-center justify-between px-3 py-2 text-sm rounded-lg border transition-all ${K===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(O,{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:m==="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:m==="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:m==="once",onChange:()=>s("once"),className:"mr-2"}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300",children:"仅执行一次"})]})]}),m==="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:x,onChange:a=>u(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:["每隔 ",x," 分钟执行一次"]})]}),m==="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:h,onChange:a=>H(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:rt.map(a=>e.jsx("button",{type:"button",onClick:()=>H(a.value),className:`px-2 py-1 text-xs rounded-full border transition-colors ${h===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))})]}),m==="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(Ae,{className:"w-4 h-4"}),"执行时间"]}),e.jsx("input",{type:"datetime-local",value:W,onChange:a=>ee(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:M,onChange:a=>ne(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:()=>le(!E),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${E?"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 ${E?"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:c,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:X||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:X||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(Ie,{className:"w-4 h-4 mr-2"}),X?"保存中...":"保存"]})]})]})]})})]})})},lt=({taskId:t,taskName:n,agentId:l,projectPath:c,onBack:p})=>{const{data:$=[],isLoading:Q}=He(t),[L,U]=i.useState(new Set),R=s=>{U(x=>{const u=new Set(x);return u.has(s)?u.delete(s):u.add(s),u})},o=s=>s?new Date(s).toLocaleString("zh-CN"):"-",v=s=>new Date(s).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3}),_=s=>{if(!s.completedAt)return"-";const x=new Date(s.startedAt).getTime(),h=new Date(s.completedAt).getTime()-x;return h<1e3?`${h}ms`:h<6e4?`${(h/1e3).toFixed(1)}s`:`${Math.floor(h/6e4)}m ${Math.floor(h%6e4/1e3)}s`},S=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(O,{className:"w-5 h-5 text-gray-400"})}},J=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:"未知"})}},b=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"}},f=s=>{const x=s.agentId||l,u=s.projectPath||c;if(!x||!s.sessionId)return null;let h=`/chat/${encodeURIComponent(x)}?session=${encodeURIComponent(s.sessionId)}`;return u&&(h+=`&project=${encodeURIComponent(u)}`),h},V=(s,x)=>{x.stopPropagation();const u=f(s);u&&window.open(u,"_blank")},m=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((x,u)=>e.jsxs("div",{className:`flex items-start gap-2 px-3 py-1.5 rounded text-sm font-mono ${b(x.level)}`,children:[e.jsx("span",{className:"text-gray-400 dark:text-gray-500 shrink-0 w-24",children:v(x.timestamp)}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs shrink-0 ${q(x.type)}`,children:x.type}),e.jsx("span",{className:"flex-1 break-all whitespace-pre-wrap",children:x.message})]},u))});return e.jsxs("div",{className:"p-8",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("button",{onClick:p,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($e,{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:["任务:",n]})]})]}),Q?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"})}):$.length===0?e.jsxs("div",{className:"text-center py-12 bg-gray-50 dark:bg-gray-800 rounded-lg",children:[e.jsx(O,{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(N,{className:"w-[40px]"}),e.jsx(N,{className:"w-[80px]",children:"状态"}),e.jsx(N,{children:"开始时间"}),e.jsx(N,{children:"完成时间"}),e.jsx(N,{children:"耗时"}),e.jsx(N,{children:"结果摘要"}),e.jsx(N,{className:"w-[100px]",children:"操作"})]})}),e.jsx(he,{children:$.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(j,{className:"p-2",children:e.jsx("button",{className:"p-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded",children:L.has(s.id)?e.jsx(me,{className:"w-4 h-4 text-gray-500"}):e.jsx(qe,{className:"w-4 h-4 text-gray-500"})})}),e.jsx(j,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[S(s.status),J(s.status)]})}),e.jsx(j,{children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:o(s.startedAt)})}),e.jsx(j,{children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:o(s.completedAt)})}),e.jsx(j,{children:e.jsx("span",{className:"text-sm font-mono text-gray-600 dark:text-gray-400",children:_(s)})}),e.jsx(j,{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(j,{children:s.sessionId&&f(s)&&e.jsx("button",{onClick:x=>V(s,x),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"})})})]}),L.has(s.id)&&e.jsx(Y,{children:e.jsx(j,{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," 条)"]})]}),m(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))})]})})]})},bt=()=>{const t=I(),{data:n=[],isLoading:l}=Ve(),{data:c}=Ne(!0),{data:p}=Be(),$=_e(),Q=Je(),L=je(),U=We(),{data:R}=Xe(),o=Ge(),v=Ye(),[_,S]=i.useState(null),[J,b]=i.useState(!1),[q,f]=i.useState(null),[V,m]=i.useState(!1),[s,x]=i.useState(2),{data:u}=Ze(),{data:h}=et(),H=tt(),W=r=>R?.executions?.find(F=>F.taskId===r)?.executionId||null,ee=c?.agents||[],M=r=>ee.find(F=>F.id===r)?.name||r,ne=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")}`:"-"},E=r=>r?new Date(r).toLocaleString("zh-CN"):"-",le=async r=>{try{await Q.mutateAsync(r.id),C(r.enabled?"任务已暂停":"任务已启用")}catch{g("操作失败")}},T=async r=>{if(confirm(`确定要删除任务 "${r.name}" 吗?`))try{await $.mutateAsync(r.id),C("任务已删除")}catch{g("删除失败")}},de=async r=>{try{await L.mutateAsync(r.id),C("任务已开始执行"),t.invalidateQueries({queryKey:d.lists()})}catch{g("执行失败")}},A=async r=>{const y=W(r.id);if(!y){g("找不到正在运行的执行");return}try{await U.mutateAsync(y),C("任务已停止"),t.invalidateQueries({queryKey:d.lists()})}catch{g("停止失败")}},te=async()=>{if(p)try{p.enabled?(await v.mutateAsync(),C("调度器已禁用")):(await o.mutateAsync(),C("调度器已启用"))}catch{g("操作失败")}},K=r=>{S(r),b(!0)},B=()=>{S(null),b(!0)},X=()=>{S(null),b(!1),t.invalidateQueries({queryKey:d.lists()})},re=()=>{S(null),b(!1)},G=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(q){const r=n.find(y=>y.id===q);return e.jsx(lt,{taskId:q,taskName:r?.name||q,agentId:r?.agentId,projectPath:r?.projectPath,onBack:()=>f(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(O,{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:[p&&e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs("button",{onClick:te,disabled:o.isPending||v.isPending,className:`flex items-center gap-2 px-3 py-1.5 rounded-lg transition-colors ${p.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"} ${o.isPending||v.isPending?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,title:p.enabled?"点击禁用调度器":"点击启用调度器",children:[e.jsx(O,{className:`w-4 h-4 ${o.isPending||v.isPending?"animate-pulse":""}`}),e.jsx("span",{className:"font-medium",children:p.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(Me,{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:()=>{h&&x(h.maxConcurrent),m(!0)},className:"ml-2 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors",title:"执行器设置",children:e.jsx(Fe,{className:"w-4 h-4"})})]})]}),e.jsxs("button",{onClick:B,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"}),"新建任务"]})]})]}),l?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(O,{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:B,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(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"状态"}),e.jsx(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"任务名称"}),e.jsx(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Agent"}),e.jsx(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"调度规则"}),e.jsx(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"上次执行"}),e.jsx(N,{className:"px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider",children:"下次执行"}),e.jsx(N,{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(j,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("button",{onClick:()=>le(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(Pe,{className:"w-5 h-5"})})}),e.jsx(j,{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(j,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:M(r.agentId)})}),e.jsx(j,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm font-mono text-gray-600 dark:text-gray-400",children:ne(r)})}),e.jsx(j,{className:"px-6 py-4",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[G(r),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:E(r.lastRunAt)})]})}),e.jsx(j,{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:r.enabled?E(r.nextRunAt):"-"})}),e.jsx(j,{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:()=>A(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(Re,{className:"w-4 h-4"})}):e.jsx("button",{onClick:()=>de(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(De,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>f(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(Ke,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>K(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(Oe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>T(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(Qe,{className:"w-4 h-4"})})]})})]},r.id))})]})}),J&&e.jsx(nt,{task:_,agents:ee,onSave:X,onCancel:re}),V&&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:()=>m(!1),className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700",children:e.jsx(Le,{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:s,onChange:r=>x(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:"允许同时执行的最大任务数量"})]}),h&&e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:["当前配置: 并发 ",h.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:()=>m(!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 H.mutateAsync({maxConcurrent:s}),C(`并发数已更新为 ${s}`),m(!1)}catch(r){g(r instanceof Error?r.message:"更新失败")}},disabled:H.isPending,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:H.isPending?"保存中...":"保存"})]})]})})]})};export{bt as ScheduledTasksPage,bt as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as t}from"./data-structures-C0h9Oap1.js";import{b as i,O as r}from"./index-
|
|
1
|
+
import{j as t}from"./data-structures-C0h9Oap1.js";import{b as i,O as r}from"./index-D9bAK8SN.js";import"./monaco-editor-DHKm5-VF.js";import"./syntax-highlighting-CnREyncB.js";import"./agents-DG431Wop.js";import"./tools-C0JOzoE_.js";import"./ui-components-CRCmgMKc.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};
|