agent-tower 0.7.1 → 0.7.2-beta.4
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/dist/executors/base.executor.d.ts.map +1 -1
- package/dist/executors/base.executor.js +6 -3
- package/dist/executors/base.executor.js.map +1 -1
- package/dist/routes/__tests__/workspaces.test.js +244 -0
- package/dist/routes/__tests__/workspaces.test.js.map +1 -1
- package/dist/routes/workspaces.d.ts.map +1 -1
- package/dist/routes/workspaces.js +11 -0
- package/dist/routes/workspaces.js.map +1 -1
- package/dist/runtime/__tests__/cli-driver-lifecycle.test.js +37 -0
- package/dist/runtime/__tests__/cli-driver-lifecycle.test.js.map +1 -1
- package/dist/runtime/__tests__/runtime-coordinator.test.js +13 -0
- package/dist/runtime/__tests__/runtime-coordinator.test.js.map +1 -1
- package/dist/runtime/cli-driver.js +17 -3
- package/dist/runtime/cli-driver.js.map +1 -1
- package/dist/runtime/contracts.d.ts +9 -2
- package/dist/runtime/contracts.d.ts.map +1 -1
- package/dist/runtime/runtime-coordinator.d.ts +2 -0
- package/dist/runtime/runtime-coordinator.d.ts.map +1 -1
- package/dist/runtime/runtime-coordinator.js +10 -0
- package/dist/runtime/runtime-coordinator.js.map +1 -1
- package/dist/services/__tests__/session-manager.lifecycle.test.js +67 -0
- package/dist/services/__tests__/session-manager.lifecycle.test.js.map +1 -1
- package/dist/services/__tests__/session-manager.team-run.test.js +41 -46
- package/dist/services/__tests__/session-manager.team-run.test.js.map +1 -1
- package/dist/services/__tests__/team-reconciler.service.test.js +30 -0
- package/dist/services/__tests__/team-reconciler.service.test.js.map +1 -1
- package/dist/services/project.service.d.ts.map +1 -1
- package/dist/services/project.service.js +30 -4
- package/dist/services/project.service.js.map +1 -1
- package/dist/services/session-manager.d.ts +1 -0
- package/dist/services/session-manager.d.ts.map +1 -1
- package/dist/services/session-manager.js +38 -3
- package/dist/services/session-manager.js.map +1 -1
- package/dist/services/session-runtime-cleanup-gate.d.ts +1 -0
- package/dist/services/session-runtime-cleanup-gate.d.ts.map +1 -1
- package/dist/services/session-runtime-cleanup-gate.js +5 -3
- package/dist/services/session-runtime-cleanup-gate.js.map +1 -1
- package/dist/services/team-reconciler.service.d.ts +1 -0
- package/dist/services/team-reconciler.service.d.ts.map +1 -1
- package/dist/services/team-reconciler.service.js +1 -0
- package/dist/services/team-reconciler.service.js.map +1 -1
- package/dist/services/workspace.service.d.ts +7 -1
- package/dist/services/workspace.service.d.ts.map +1 -1
- package/dist/services/workspace.service.js +111 -9
- package/dist/services/workspace.service.js.map +1 -1
- package/dist/utils/__tests__/spawned-process-identity.test.d.ts +2 -0
- package/dist/utils/__tests__/spawned-process-identity.test.d.ts.map +1 -0
- package/dist/utils/__tests__/spawned-process-identity.test.js +31 -0
- package/dist/utils/__tests__/spawned-process-identity.test.js.map +1 -0
- package/dist/utils/spawned-process-identity.d.ts +1 -1
- package/dist/utils/spawned-process-identity.d.ts.map +1 -1
- package/dist/utils/spawned-process-identity.js +11 -3
- package/dist/utils/spawned-process-identity.js.map +1 -1
- package/dist/web/assets/AgentDemoPage-Svq9Baa7.js +1 -0
- package/dist/web/assets/{AgentEnvironmentSettingsPage-b0XzUzna.js → AgentEnvironmentSettingsPage-DQjnDr-h.js} +1 -1
- package/dist/web/assets/AgentLogo-I2etsqym.js +1 -0
- package/dist/web/assets/BranchSelect-Eb5UGWWX.js +1 -0
- package/dist/web/assets/BrandLogo-BjC1hcgv.js +1 -0
- package/dist/web/assets/{ConversationPage-DQRA8WuD.js → ConversationPage-jEYUuSPT.js} +2 -2
- package/dist/web/assets/CreateTaskInput-B_cRDkVq.js +1 -0
- package/dist/web/assets/{DemoPage-DaDC_MIJ.js → DemoPage-BkkueMuL.js} +1 -1
- package/dist/web/assets/DesignSystemPage-oM16R2Ta.js +16 -0
- package/dist/web/assets/{ExecutionPermissionSelector-DglILGVC.js → ExecutionPermissionSelector-BX5Xx8ta.js} +1 -1
- package/dist/web/assets/{GeneralSettingsPage-BKRf-usO.js → GeneralSettingsPage-B0jFlgDl.js} +1 -1
- package/dist/web/assets/{LoadingPreviewPage-BHAQCQDA.js → LoadingPreviewPage-BxjpxLLP.js} +1 -1
- package/dist/web/assets/McpSettingsPage-BErvd619.js +1 -0
- package/dist/web/assets/{MemberAvatar-DUXHTIXf.js → MemberAvatar-TVtoxQe8.js} +1 -1
- package/dist/web/assets/NotificationSettingsPage-BETMBdj1.js +1 -0
- package/dist/web/assets/{ProfileSettingsPage-DwziCseV.js → ProfileSettingsPage-C03ZAft-.js} +1 -1
- package/dist/web/assets/ProjectKanbanPage-DsPxwoVf.js +86 -0
- package/dist/web/assets/ProjectSettingsPage-BwNM6VWs.js +2 -0
- package/dist/web/assets/{ProviderSettingsPage-CC3zkdf6.js → ProviderSettingsPage-CeNQPd74.js} +3 -3
- package/dist/web/assets/{SettingsMasterDetail-D5lNH2f6.js → SettingsMasterDetail-B_SI2h_k.js} +1 -1
- package/dist/web/assets/TeamSettingsPage-BfgtMl_n.js +1 -0
- package/dist/web/assets/agent-meta-DOylIs2N.js +1 -0
- package/dist/web/assets/arc-BlZww3MO.js +1 -0
- package/dist/web/assets/{architectureDiagram-3BPJPVTR-C_p9_AH2.js → architectureDiagram-3BPJPVTR-DWO_DRgk.js} +1 -1
- package/dist/web/assets/at-sign-BFf8Sz8T.js +1 -0
- package/dist/web/assets/{blockDiagram-GPEHLZMM-CKsR1Tax.js → blockDiagram-GPEHLZMM-CJPYhE52.js} +1 -1
- package/dist/web/assets/{c4Diagram-AAUBKEIU-BBUKt2FW.js → c4Diagram-AAUBKEIU-Cx5IvcjB.js} +1 -1
- package/dist/web/assets/channel-D9sA6Wxp.js +1 -0
- package/dist/web/assets/check-Cm7Vstpm.js +1 -0
- package/dist/web/assets/chevron-down-C6Ta4vyM.js +1 -0
- package/dist/web/assets/chevron-up-BwJT7iif.js +1 -0
- package/dist/web/assets/{chunk-2J33WTMH-BcGNhDoU.js → chunk-2J33WTMH-D9cBNYgd.js} +1 -1
- package/dist/web/assets/{chunk-4BX2VUAB-9dL7TVjW.js → chunk-4BX2VUAB-BY8TNt6E.js} +1 -1
- package/dist/web/assets/{chunk-55IACEB6-CzJzh0tH.js → chunk-55IACEB6-pT-HP-28.js} +1 -1
- package/dist/web/assets/{chunk-727SXJPM-Bp5EOgoG.js → chunk-727SXJPM-hy95xDLb.js} +1 -1
- package/dist/web/assets/{chunk-AQP2D5EJ-BaLnh9ac.js → chunk-AQP2D5EJ-DlUN-icr.js} +1 -1
- package/dist/web/assets/{chunk-FMBD7UC4-BcbzC8r4.js → chunk-FMBD7UC4-Dg2iMKZR.js} +1 -1
- package/dist/web/assets/{chunk-ND2GUHAM-DkT5Stbd.js → chunk-ND2GUHAM-DMzFIsJ-.js} +1 -1
- package/dist/web/assets/{chunk-QZHKN3VN-DszScpAV.js → chunk-QZHKN3VN-C6CgmKuM.js} +1 -1
- package/dist/web/assets/{circle-alert-ChWS5BPS.js → circle-alert-Dm2Pl-rU.js} +1 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-2e2YVo9r.js +1 -0
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-2e2YVo9r.js +1 -0
- package/dist/web/assets/code-block-OCS4YCEC-DizntuP_.js +2 -0
- package/dist/web/assets/{confirm-dialog-0vHzUzvI.js → confirm-dialog-DRpyE_qU.js} +1 -1
- package/dist/web/assets/copy-r0aUdsl8.js +1 -0
- package/dist/web/assets/{cose-bilkent-S5V4N54A-DueZsNr5.js → cose-bilkent-S5V4N54A-D-fvmvw-.js} +1 -1
- package/dist/web/assets/cssMode-DVorIr82.js +1 -0
- package/dist/web/assets/{dagre-BM42HDAG-BkQGrA8s.js → dagre-BM42HDAG-H0bYI1f3.js} +1 -1
- package/dist/web/assets/{diagram-2AECGRRQ-D4qtEjjj.js → diagram-2AECGRRQ-DI568fLp.js} +1 -1
- package/dist/web/assets/{diagram-5GNKFQAL-ZuFk-7GO.js → diagram-5GNKFQAL-BLcaBzw2.js} +1 -1
- package/dist/web/assets/{diagram-KO2AKTUF-kwBr5lw0.js → diagram-KO2AKTUF-aL1cvl23.js} +1 -1
- package/dist/web/assets/{diagram-LMA3HP47-m88-mNyr.js → diagram-LMA3HP47-DbOutAfH.js} +1 -1
- package/dist/web/assets/{diagram-OG6HWLK6-B9gV1dxA.js → diagram-OG6HWLK6-D_cWftAX.js} +1 -1
- package/dist/web/assets/{erDiagram-TEJ5UH35-De_DsoOX.js → erDiagram-TEJ5UH35-DRe5V8Dx.js} +1 -1
- package/dist/web/assets/{flowDiagram-I6XJVG4X-9VwLS0b3.js → flowDiagram-I6XJVG4X-B5-vg_Nh.js} +1 -1
- package/dist/web/assets/{freemarker2-CLp1Yffb.js → freemarker2-CXlYb2yX.js} +3 -3
- package/dist/web/assets/{ganttDiagram-6RSMTGT7-DoOyYr5i.js → ganttDiagram-6RSMTGT7-B3iBFICN.js} +1 -1
- package/dist/web/assets/{gitGraphDiagram-PVQCEYII-CMGuTxMz.js → gitGraphDiagram-PVQCEYII-CZ9zsKVw.js} +1 -1
- package/dist/web/assets/globe-JXfw4MCF.js +1 -0
- package/dist/web/assets/handlebars-BL0prPVZ.js +1 -0
- package/dist/web/assets/html-DJWeRkWe.js +1 -0
- package/dist/web/assets/htmlMode-D_fekqg9.js +1 -0
- package/dist/web/assets/{index-DI7lHrAR.js → index-CWEbo6pZ.js} +5 -5
- package/dist/web/assets/index-CWbMMO6g.js +122 -0
- package/dist/web/assets/index-uXglTJ2_.css +1 -0
- package/dist/web/assets/{infoDiagram-5YYISTIA-gUCDmQX7.js → infoDiagram-5YYISTIA-DQU_sN8x.js} +1 -1
- package/dist/web/assets/{ishikawaDiagram-YF4QCWOH-CmfFhhIz.js → ishikawaDiagram-YF4QCWOH-BVGrNzJa.js} +1 -1
- package/dist/web/assets/javascript-CDfuzdfe.js +1 -0
- package/dist/web/assets/{journeyDiagram-JHISSGLW-BvV5GoR_.js → journeyDiagram-JHISSGLW-DU4Md1Tq.js} +1 -1
- package/dist/web/assets/{jsonMode-BbjYNQ7Q.js → jsonMode-BMSvHUHa.js} +4 -4
- package/dist/web/assets/{kanban-definition-UN3LZRKU-BpTm0MC-.js → kanban-definition-UN3LZRKU-DDPgCucq.js} +1 -1
- package/dist/web/assets/key-round-BHVp7u3Z.js +1 -0
- package/dist/web/assets/{layers-DslPQJ3T.js → layers-2tjjhM75.js} +1 -1
- package/dist/web/assets/{linear-BJ_g8wqu.js → linear-D8yLBTVY.js} +1 -1
- package/dist/web/assets/link-CnunXc7X.js +1 -0
- package/dist/web/assets/liquid-DHrNpv6c.js +1 -0
- package/dist/web/assets/{lspLanguageFeatures-PSX0tqnR.js → lspLanguageFeatures-BiYvrSP0.js} +1 -1
- package/dist/web/assets/mdx-CIEpgUOV.js +1 -0
- package/dist/web/assets/mermaid-NOHMQCX5-9-DTTfp6.js +124 -0
- package/dist/web/assets/{message-square-C-22K3oa.js → message-square-QM0c6Dcv.js} +1 -1
- package/dist/web/assets/{mindmap-definition-RKZ34NQL-DS5GLydx.js → mindmap-definition-RKZ34NQL-CCAuuWFZ.js} +1 -1
- package/dist/web/assets/{modal-CFVLBZ5p.js → modal-BRoNvfhw.js} +1 -1
- package/dist/web/assets/{monaco-CkaUvvB4.js → monaco-CrBn9oMJ.js} +3 -3
- package/dist/web/assets/paperclip-CC7nHUQ7.js +1 -0
- package/dist/web/assets/pencil-DIY0Hu5t.js +1 -0
- package/dist/web/assets/{pieDiagram-4H26LBE5-C1PJJGsh.js → pieDiagram-4H26LBE5-CXy_N5QX.js} +2 -2
- package/dist/web/assets/play-CIZVXiwM.js +1 -0
- package/dist/web/assets/python-BIs0pClJ.js +1 -0
- package/dist/web/assets/{quadrantDiagram-W4KKPZXB-CzDfs-TQ.js → quadrantDiagram-W4KKPZXB-Dt44QsS8.js} +1 -1
- package/dist/web/assets/razor-JCx8NEwU.js +1 -0
- package/dist/web/assets/{requirementDiagram-4Y6WPE33-qHbU7oZa.js → requirementDiagram-4Y6WPE33-BL8D7Np0.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-5OEKKPKP-BfRgrEeN.js → sankeyDiagram-5OEKKPKP-I5nefO3A.js} +1 -1
- package/dist/web/assets/{select-CL78HCY0.js → select-BmjoUfrV.js} +1 -1
- package/dist/web/assets/{sequenceDiagram-3UESZ5HK-CGTNzKk3.js → sequenceDiagram-3UESZ5HK-lbPrhX8g.js} +1 -1
- package/dist/web/assets/server-BNBdQGor.js +1 -0
- package/dist/web/assets/stateDiagram-AJRCARHV-Bw3qtv2M.js +1 -0
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-Xbc4HxDQ.js +1 -0
- package/dist/web/assets/{switch-DmQ0Brgd.js → switch-CEUHI4gI.js} +1 -1
- package/dist/web/assets/task-kalEmHDc.js +42 -0
- package/dist/web/assets/task-priority-wLXAgVZZ.js +1 -0
- package/dist/web/assets/{textarea-DOte4pMQ.js → textarea-CD82lB0Z.js} +1 -1
- package/dist/web/assets/{timeline-definition-PNZ67QCA-BBhCKsly.js → timeline-definition-PNZ67QCA-Cfg_kgoa.js} +1 -1
- package/dist/web/assets/{trash-2-BSAHXKfW.js → trash-2-BF_3L-qk.js} +1 -1
- package/dist/web/assets/{tsMode-B6rHoWny.js → tsMode-DAHSkTAr.js} +2 -2
- package/dist/web/assets/typescript-CptiLWGr.js +1 -0
- package/dist/web/assets/{upload-e87qV_RH.js → upload-B2AMXrU-.js} +1 -1
- package/dist/web/assets/{use-profiles-Cv2zBJOC.js → use-profiles-CQ-jIuiI.js} +1 -1
- package/dist/web/assets/use-projects-BYUZwQ-q.js +1 -0
- package/dist/web/assets/{use-providers-CnpIgITQ.js → use-providers-DdV9gbj1.js} +1 -1
- package/dist/web/assets/useNormalizedLogs-DdFsf-Z1.js +1 -0
- package/dist/web/assets/{vennDiagram-CIIHVFJN-DrDrt_Jg.js → vennDiagram-CIIHVFJN-CdEP03CK.js} +1 -1
- package/dist/web/assets/{wardley-L42UT6IY-CMYQm14y.js → wardley-L42UT6IY-q_Enplrs.js} +1 -1
- package/dist/web/assets/{wardleyDiagram-YWT4CUSO-COLA9A80.js → wardleyDiagram-YWT4CUSO-DlL6fsid.js} +1 -1
- package/dist/web/assets/xml-DbPqkgZW.js +1 -0
- package/dist/web/assets/{xychartDiagram-2RQKCTM6-BDegkKoT.js → xychartDiagram-2RQKCTM6-B2OGqVKA.js} +1 -1
- package/dist/web/assets/yaml-Deyq6Z5-.js +1 -0
- package/dist/web/index.html +2 -2
- package/node_modules/@agent-tower/shared/dist/socket/events.d.ts +2 -2
- package/node_modules/@agent-tower/shared/dist/socket/events.d.ts.map +1 -1
- package/node_modules/@agent-tower/shared/dist/types.d.ts +19 -2
- package/node_modules/@agent-tower/shared/dist/types.d.ts.map +1 -1
- package/node_modules/@agent-tower/shared/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/web/assets/AgentDemoPage-Gr8q6VxC.js +0 -1
- package/dist/web/assets/AgentLogo-q8Chady2.js +0 -1
- package/dist/web/assets/CreateTaskInput-Dr6Lvllw.js +0 -1
- package/dist/web/assets/Icons-7lThaqQv.js +0 -1
- package/dist/web/assets/McpSettingsPage-CVOEPwCv.js +0 -1
- package/dist/web/assets/NotificationSettingsPage-DBe1YCNN.js +0 -1
- package/dist/web/assets/ProjectKanbanPage-Dcz8KXWU.js +0 -86
- package/dist/web/assets/ProjectSettingsPage-hzSrj79M.js +0 -2
- package/dist/web/assets/TeamSettingsPage-Cdbvh2ne.js +0 -1
- package/dist/web/assets/arc-d2D24uRQ.js +0 -1
- package/dist/web/assets/channel-D0hF47LU.js +0 -1
- package/dist/web/assets/check-BqhuHtHP.js +0 -1
- package/dist/web/assets/chevron-down-Bw_76CB_.js +0 -1
- package/dist/web/assets/chevron-right-DbcFf_Dw.js +0 -1
- package/dist/web/assets/chevron-up-x1n3MhC-.js +0 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-ulXJsBKw.js +0 -1
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-ulXJsBKw.js +0 -1
- package/dist/web/assets/code-block-OCS4YCEC-G8tEtSdL.js +0 -2
- package/dist/web/assets/cssMode-Dqx3XDOC.js +0 -1
- package/dist/web/assets/folder-picker-B0khMt7A.js +0 -1
- package/dist/web/assets/handlebars-CmLfR6Uy.js +0 -1
- package/dist/web/assets/html-D34UDOLc.js +0 -1
- package/dist/web/assets/htmlMode-qjrvkZFJ.js +0 -1
- package/dist/web/assets/index-DrzmyANC.js +0 -122
- package/dist/web/assets/index-MMCbS8_L.css +0 -1
- package/dist/web/assets/javascript-D5tp0LcO.js +0 -1
- package/dist/web/assets/liquid-DBu3_6XS.js +0 -1
- package/dist/web/assets/mdx-Bb4nrA8s.js +0 -1
- package/dist/web/assets/mermaid-NOHMQCX5-B44shuzc.js +0 -124
- package/dist/web/assets/pencil-DB3VPszm.js +0 -1
- package/dist/web/assets/python-BfodDYt4.js +0 -1
- package/dist/web/assets/razor-DdED1MBH.js +0 -1
- package/dist/web/assets/server-Cd7APx6v.js +0 -1
- package/dist/web/assets/stateDiagram-AJRCARHV-BY1LJ4b7.js +0 -1
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-BV_JKRZC.js +0 -1
- package/dist/web/assets/typescript-C2A3q8UY.js +0 -1
- package/dist/web/assets/use-projects-C8WDJXdj.js +0 -1
- package/dist/web/assets/useNormalizedLogs-AbIXa8s-.js +0 -1
- package/dist/web/assets/xml-D4xDxfjR.js +0 -1
- package/dist/web/assets/yaml-yJExA7tq.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{c as ze,u as de,r,j as e,a1 as Oe,l as j,m as ke,o as X,n as ce,q as f,p as _,a2 as Ke,a3 as Qe,a4 as Fe,_ as Ue,$ as je,a5 as Be,a6 as _e,s as $e,a7 as le}from"./index-CWbMMO6g.js";import{g as Ve,a as Ge}from"./ExecutionPermissionSelector-BX5Xx8ta.js";import{S as A}from"./agent-meta-DOylIs2N.js";import{u as He,a as We,A as Je}from"./mermaid-NOHMQCX5-9-DTTfp6.js";import{u as Ye,a as Xe,L as Ze,T as et}from"./useNormalizedLogs-DdFsf-Z1.js";import{u as tt,a as st,b as nt,R as rt,P as at,T as ot,C as it}from"./CreateTaskInput-B_cRDkVq.js";import{A as lt,a as dt,S as Se}from"./task-priority-wLXAgVZZ.js";import{P as ct}from"./paperclip-CC7nHUQ7.js";import{B as ut,S as mt}from"./BrandLogo-BjC1hcgv.js";import{u as ft}from"./use-providers-DdV9gbj1.js";import{M as pe}from"./message-square-QM0c6Dcv.js";import{T as xt}from"./trash-2-BF_3L-qk.js";import"./chevron-down-C6Ta4vyM.js";import"./check-Cm7Vstpm.js";import"./AgentLogo-I2etsqym.js";import"./use-projects-BYUZwQ-q.js";import"./MemberAvatar-TVtoxQe8.js";const ht=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["path",{d:"M14 4h7",key:"3xa0d5"}],["path",{d:"M14 9h7",key:"1icrd9"}],["path",{d:"M14 15h7",key:"1mj8o2"}],["path",{d:"M14 20h7",key:"11slyb"}]],pt=ze("layout-list",ht);function gt({sessionId:t,sessionStatus:n,sessionStartedAt:i,sessionEndedAt:x,agentType:w,runtimeType:p,providerId:u,providers:b,initialTokenUsage:v,onProviderChange:C,onSend:k,onStop:D,onExit:O,isSending:S=!1,isStopping:o=!1,canStop:m,className:ue}){const{t:g}=de(),[I,K]=r.useState(""),[L,Q]=r.useState(u??""),N=Ve(b,L||u),[Z,$]=r.useState(!1),[ee,F]=r.useState(null),V=r.useRef(null),te=r.useRef(null),G=r.useRef(null),P=r.useRef(!1),{scrollRef:H,contentRef:l,isAtBottom:W,scrollToBottom:M,stopScroll:se}=tt({initial:"instant",resize:"smooth"}),{isConnected:R,isLoadingSnapshot:me,isOutputActive:E,lastExitAt:ne,logs:J,entries:re,attach:U}=Ye({sessionId:t,sessionStatus:n,sessionStartedAt:i,sessionEndedAt:x,onExit:O}),{todos:Y}=Xe(re),fe=st(J,v),{files:ae,addFiles:T,removeFile:xe,clear:oe,buildMarkdownLinks:ie,getDoneAttachments:s,hasFiles:a,isUploading:d}=He(),{isActive:h,isCancelling:q}=nt(t,n),he=m??h;r.useEffect(()=>{Q(u??"")},[u]),r.useEffect(()=>{t&&R&&U()},[t,R,U]);const De=r.useCallback(c=>{Q(c),C?.(c)},[C]),ve=r.useCallback(()=>{V.current&&(V.current.style.height="60px")},[]),Ee=r.useCallback(c=>{K(c.target.value);const y=c.target;y.style.height="auto",y.style.height=`${Math.max(60,Math.min(y.scrollHeight,300))}px`},[]),be=r.useCallback(async()=>{if(!I.trim()&&!a||P.current||S||o||q||d||N)return;P.current=!0;const c=ie(),y=s().map(z=>z.id),B=[I.trim(),c].filter(Boolean).join(`
|
|
2
2
|
|
|
3
|
-
`);K(""),oe(),ve(),F(null);try{await k({message:B,providerId:L||void 0,attachmentIds:y}),await U(),requestAnimationFrame(()=>M("smooth"))}catch(z){F(z instanceof Error?z.message:g("Send failed. Please try again.")),K(B)}finally{P.current=!1}},[I,a,S,o,q,d,ie,s,oe,ve,k,L,N,U,M,g]),Te=r.useCallback(async()=>{!he||o||q||await D()},[he,o,q,D]),Le=r.useCallback(c=>{const y=c.target.files;y&&y.length>0&&T(Array.from(y)),c.target.value=""},[T]),Pe=r.useCallback(c=>{const y=c.clipboardData.items,B=[];for(const z of y)if(z.kind==="file"){const ye=z.getAsFile();ye&&B.push(ye)}B.length>0&&(c.preventDefault(),T(B))},[T]),Me=r.useCallback(c=>{c.preventDefault(),$(!0)},[]),Re=r.useCallback(c=>{c.preventDefault(),$(!1)},[]),qe=r.useCallback(c=>{c.preventDefault(),$(!1);const y=c.dataTransfer.files;y.length>0&&T(Array.from(y))},[T]);return e.jsxs("div",{className:j("relative flex min-h-0 flex-1 flex-col bg-background",ue),children:[e.jsxs("div",{className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:G,className:"h-full overflow-y-auto scrollbar-app-thin px-6 pb-4 pt-6",children:e.jsx("div",{ref:l,className:"mx-auto w-full min-w-0 max-w-4xl",children:me?e.jsxs("div",{className:"flex items-center justify-center gap-3 py-12 text-muted-foreground/70",children:[e.jsxs("svg",{className:"h-5 w-5 animate-spin",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),e.jsx("span",{className:"text-sm",children:g("Loading logs...")})]}):J.length===0?e.jsx("div",{className:"py-8 text-center text-muted-foreground/70",children:g(h?"Waiting for agent output...":"No logs recorded for this session.")}):e.jsx(Xe,{children:e.jsx(He,{logs:J,downloadSessionId:t,isOutputActive:E,lastExitAt:ne,onUserToggleDetails:se,scrollElementRef:G})})})}),!H&&e.jsxs("button",{type:"button",onClick:()=>M(),className:"absolute bottom-3 left-1/2 z-10 flex -translate-x-1/2 items-center gap-1.5 rounded-full border border-border bg-background/90 px-3 py-1.5 text-xs text-muted-foreground shadow-md backdrop-blur-sm transition-all hover:bg-background hover:text-foreground","aria-label":g("Scroll to bottom"),children:[e.jsx(at,{size:14}),e.jsx("span",{children:g("Back to bottom")})]})]}),Y.length>0&&e.jsx("div",{className:"shrink-0 border-t border-border/60 bg-background px-6 pb-1 pt-2",children:e.jsx("div",{className:"mx-auto max-w-4xl",children:e.jsx(et,{todos:Y})})}),e.jsx("div",{className:"z-10 w-full shrink-0 border-t border-transparent bg-background p-6 pb-6 pt-2",onDragOver:Me,onDragLeave:Re,onDrop:qe,children:e.jsxs("div",{className:"mx-auto max-w-4xl",children:[e.jsx(ot,{sessionId:t}),ee?e.jsx("div",{className:"mb-2 text-sm text-destructive",children:ee}):null,e.jsxs("div",{ref:W,className:j("relative rounded-xl border bg-background transition-colors duration-200 hover:border-ring/40 focus-within:border-ring/60",X?"border-info bg-info/5":"border-border"),children:[e.jsx(Je,{files:ae,onRemove:xe}),e.jsx("textarea",{ref:V,value:I,onChange:Ee,onPaste:Pe,onKeyDown:c=>{c.key==="Enter"&&!c.shiftKey&&!c.repeat&&!c.nativeEvent.isComposing&&c.nativeEvent.keyCode!==229&&(c.preventDefault(),be())},rows:1,placeholder:g(X?"Drop files here...":t&&!h?"Continue conversation...":"Message Agent..."),className:"w-full resize-none border-none bg-transparent px-4 pb-2 pt-4 text-sm leading-relaxed text-foreground placeholder-muted-foreground/70 focus:outline-none",style:{minHeight:"60px",maxHeight:"300px"}}),e.jsx("input",{ref:te,type:"file",multiple:!0,className:"hidden",onChange:Le}),e.jsxs("div",{className:"flex items-center justify-between px-2 pb-2 pt-1",children:[e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("button",{type:"button",onClick:()=>te.current?.click(),disabled:d,className:"rounded-lg p-2 text-muted-foreground/70 transition-colors hover:bg-muted hover:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",title:g("Upload file"),children:e.jsx(tt,{size:18})})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(it,{providers:b,currentProviderId:L,agentType:w,runtimeType:p,onSelect:De}),e.jsx(lt,{usage:fe}),he&&h&&!I.trim()&&!a?e.jsx("button",{type:"button",onClick:Te,disabled:o||q,className:"rounded-lg bg-destructive p-2 text-white transition-all duration-200 hover:bg-destructive/90 disabled:opacity-50",title:g("Stop"),children:e.jsx(Oe,{size:14})}):e.jsx("button",{type:"button",onClick:be,disabled:!I.trim()&&!a||d||S||o||q||!!N,className:j("rounded-lg p-2 transition-all duration-200",(I.trim()||a)&&!d&&!S&&!o&&!q&&!N?"bg-primary text-primary-foreground hover:bg-primary/90":"cursor-not-allowed bg-transparent text-muted-foreground/50"),title:g("Send"),children:e.jsx(dt,{size:18})})]})]})]})]})})]})}function vt(t=50){return ke({queryKey:f.conversations.list({limit:t}),queryFn:()=>_.get("/conversations",{params:{limit:String(t)}})})}function bt(t){return ke({queryKey:f.conversations.detail(t??""),queryFn:()=>_.get(`/conversations/${t}`),enabled:!!t})}function yt(){const t=Z();return ce({mutationFn:n=>_.post("/conversations",n),onSuccess:n=>{t.setQueryData(f.conversations.detail(n.id),n),t.invalidateQueries({queryKey:f.conversations.all}),t.invalidateQueries({queryKey:f.sessions.detail(n.sessionId)})}})}function jt(){const t=Z();return ce({mutationFn:({id:n,...i})=>_.post(`/conversations/${n}/message`,i),onSuccess:n=>{t.setQueryData(f.conversations.detail(n.id),n),t.invalidateQueries({queryKey:f.conversations.all}),t.invalidateQueries({queryKey:f.sessions.detail(n.sessionId)})}})}function Nt(){const t=Z();return ce({mutationFn:n=>_.post(`/conversations/${n}/stop`),onSuccess:n=>{t.setQueryData(f.conversations.detail(n.id),n),t.invalidateQueries({queryKey:f.conversations.all}),t.invalidateQueries({queryKey:f.sessions.detail(n.sessionId)})},onSettled:(n,i,x)=>{const w=t.getQueryData(f.conversations.detail(x)),p=n?.sessionId??w?.sessionId;t.invalidateQueries({queryKey:f.conversations.detail(x)}),p&&(t.invalidateQueries({queryKey:f.sessions.detail(p)}),t.invalidateQueries({queryKey:f.sessions.runtime(p)}))}})}function wt(){const t=Z();return ce({mutationFn:n=>_.delete(`/conversations/${n}`),onSuccess:(n,i)=>{t.removeQueries({queryKey:f.conversations.detail(i)}),t.invalidateQueries({queryKey:f.conversations.all})}})}const Ct=3e4,Ie="agent-tower:conversation-read-times";function kt(){try{const t=window.localStorage.getItem(Ie);if(!t)return{};const n=JSON.parse(t);return!n||typeof n!="object"||Array.isArray(n)?{}:Object.fromEntries(Object.entries(n).map(([i,x])=>[i,typeof x=="number"?x:Number(x)]).filter(i=>Number.isFinite(i[1])))}catch{return{}}}function Ne(t){try{window.localStorage.setItem(Ie,JSON.stringify(t))}catch{}}function we(t){const n=t.lastActiveAt??t.updatedAt??t.createdAt;if(!n)return 0;const i=new Date(n).getTime();return Number.isFinite(i)?i:0}function St(t=Ct){const[,n]=r.useState(0);r.useEffect(()=>{const i=setInterval(()=>n(x=>x+1),t);return()=>clearInterval(i)},[t])}function ge(t){return t===A.RUNNING||t===A.PENDING}function Ae(t){if(!t)return"";const n=new Date(t);if(Number.isNaN(n.getTime()))return"";const i=Math.max(0,Math.floor((Date.now()-n.getTime())/1e3));return i<60?le("{count}s ago",{count:i}):i<3600?le("{count}m ago",{count:Math.floor(i/60)}):i<86400?le("{count}h ago",{count:Math.floor(i/3600)}):le("{count}d ago",{count:Math.floor(i/86400)})}function It(t,n){switch(t){case A.RUNNING:return n("Running");case A.PENDING:return n("Starting");case A.COMPLETED:return n("Completed");case A.FAILED:return n("Failed");case A.CANCELLED:return n("Stopped");default:return t}}function Ce({className:t,pulseClassName:n}){return e.jsxs("span",{className:"relative inline-flex h-2 w-2",children:[e.jsx("span",{className:j("absolute inline-flex h-full w-full animate-ping rounded-full",n)}),e.jsx("span",{className:j("relative inline-flex h-2 w-2 rounded-full",t)})]})}function At({status:t,unread:n}){return ge(t)?e.jsx(Ce,{className:"bg-success",pulseClassName:"bg-success/70"}):n?e.jsx(Ce,{className:"bg-warning",pulseClassName:"bg-warning/70"}):null}function Dt({conversation:t,selected:n,onSelect:i,onDelete:x,disabled:w,unread:p}){const{t:u}=de(),b=Ae(t.lastActiveAt??t.createdAt),v=ge(t.status)||p;return e.jsxs("div",{className:j("group ml-4 mr-2 flex items-center rounded-md transition-colors",n?"bg-accent":"hover:bg-accent/50"),children:[e.jsxs("button",{type:"button",onClick:i,title:t.title,className:"flex min-w-0 flex-1 animate-task-enter items-center gap-2.5 rounded-md px-2 py-2 text-left text-sm",children:[e.jsx("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:e.jsx(pe,{size:14,className:"text-muted-foreground"})}),e.jsx("span",{className:j("min-w-0 flex-1 truncate",n?"font-medium text-foreground":"text-foreground/90"),children:t.title}),v?e.jsx("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:e.jsx(At,{status:t.status,unread:p})}):e.jsx("span",{className:"flex w-14 shrink-0 items-center justify-end text-[11px] tabular-nums text-muted-foreground/50",children:e.jsx("span",{className:"truncate group-hover:hidden",children:b})})]}),e.jsx("button",{type:"button",onClick:C=>{C.stopPropagation(),x()},disabled:w,className:"mr-1 hidden shrink-0 rounded-md p-1.5 text-muted-foreground hover:bg-background hover:text-destructive disabled:opacity-50 group-hover:flex",title:u("Delete"),children:e.jsx(xt,{size:14})})]})}function Et({isOpen:t,conversations:n,onClose:i,onSelectConversation:x}){const{t:w}=de(),[p,u]=r.useState(""),[b,v]=r.useState(0),C=r.useRef(null);r.useEffect(()=>{t&&(u(""),v(0))},[t]);const k=r.useMemo(()=>{const o=p.trim().toLowerCase();return o?n.filter(m=>m.title.toLowerCase().includes(o)).slice(0,50):n.slice(0,12)},[n,p]);r.useEffect(()=>{v(0)},[p]),r.useEffect(()=>{C.current?.children[b]?.scrollIntoView({block:"nearest"})},[b]);const D=r.useCallback(o=>{x(o),i()},[i,x]),O=r.useCallback(o=>{if(o.key==="Escape"){o.preventDefault(),i();return}if(o.key==="ArrowDown"){o.preventDefault(),v(m=>Math.min(m+1,k.length-1));return}if(o.key==="ArrowUp"){o.preventDefault(),v(m=>Math.max(m-1,0));return}if(o.key==="Enter"&&!o.nativeEvent.isComposing){o.preventDefault();const m=k[b];m&&D(m)}},[b,D,i,k]);if(!t)return null;const S=p.trim().length>0;return e.jsxs("div",{className:"fixed inset-0 z-90",role:"dialog","aria-modal":"true",children:[e.jsx("div",{className:"absolute inset-0 bg-black/20",onClick:i}),e.jsxs("div",{className:"absolute left-1/2 top-[18vh] w-[min(560px,calc(100vw-2rem))] -translate-x-1/2 overflow-hidden rounded-xl border border-border bg-popover shadow-lg animate-in fade-in zoom-in-95 duration-100",children:[e.jsxs("div",{className:"flex items-center gap-2.5 border-b border-border/60 px-4",children:[e.jsx(Se,{size:15,className:"shrink-0 text-muted-foreground/70"}),e.jsx("input",{value:p,onChange:o=>u(o.target.value),onKeyDown:O,placeholder:w("Search conversations..."),"aria-label":w("Search conversations..."),autoFocus:!0,className:"flex-1 border-none bg-transparent py-3 text-sm text-foreground placeholder-muted-foreground/60 focus:outline-none"})]}),k.length>0?e.jsxs(e.Fragment,{children:[S?null:e.jsx("div",{className:"px-4 pb-1 pt-2.5 text-[11px] font-medium text-muted-foreground/70",children:w("Recent conversations")}),e.jsx("div",{ref:C,className:"max-h-[46vh] overflow-y-auto pb-1.5 pt-0.5 scrollbar-app-thin",children:k.map((o,m)=>e.jsxs("button",{type:"button",onClick:()=>D(o),onMouseEnter:()=>v(m),className:j("flex w-full items-center gap-2.5 px-4 py-2 text-left transition-colors",m===b&&"bg-accent"),children:[e.jsx(pe,{size:14,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-foreground/90",title:o.title,children:o.title}),e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground/60",children:Ae(o.lastActiveAt??o.createdAt)})]},o.id))})]}):e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground/70",children:w("No matching conversations")})]})]})}function $t(){const{t}=de();St();const n=Ke(),{usesIntegratedTitlebar:i,desktopPlatform:x,hasMacTrafficLights:w}=Qe(),p=i&&x==="win32",{conversationId:u}=Fe(),b=Z(),[v,C]=r.useState(""),[k,D]=r.useState("idle"),[O,S]=r.useState(null),[o,m]=r.useState(!1),[ue,g]=r.useState(!1),[I,K]=r.useState(kt),[L,Q]=r.useState(()=>new Set),{data:N=[],isLoading:X}=vt(),{data:$,isLoading:ee}=bt(u),{data:F=[],isLoading:V}=ft(),te=yt(),W=jt(),P=Nt(),G=wt(),l=$??N.find(s=>s.id===u)??null,H=r.useMemo(()=>F.map(s=>{const a=We(s);return{id:s.provider.id,name:s.provider.name,agentType:s.provider.agentType,available:!a,permissionMode:s.provider.executionPermission,reason:a}}),[F]),M=!!u,se=M||o,R=r.useCallback(s=>{b.invalidateQueries({queryKey:f.conversations.all}),s&&b.invalidateQueries({queryKey:f.conversations.detail(s)})},[b]),me=r.useCallback(()=>{R(u)},[u,R]),E=r.useCallback(s=>{if(Q(d=>{if(!d.has(s.id))return d;const h=new Set(d);return h.delete(s.id),h}),s.status!==A.COMPLETED)return;const a=Math.max(Date.now(),we(s));K(d=>{if(d[s.id]&&d[s.id]>=a)return d;const h={...d,[s.id]:a};return Ne(h),h})},[]),ne=r.useCallback(s=>{Q(a=>{if(a.has(s))return a;const d=new Set(a);return d.add(s),d})},[]),J=r.useCallback(s=>{Q(a=>{if(!a.has(s))return a;const d=new Set(a);return d.delete(s),d}),K(a=>{if(!(s in a))return a;const d={...a};return delete d[s],Ne(d),d})},[]),re=r.useMemo(()=>{const s=new Map;for(const a of N)s.set(a.sessionId,a);return l&&s.set(l.sessionId,l),s},[l,N]),U=r.useCallback(s=>s.status!==A.COMPLETED?!1:L.has(s.id)?!0:we(s)>(I[s.id]??0),[I,L]);r.useEffect(()=>{l||v||C(H.find(s=>s.available)?.id??"")},[l,v,H]),r.useEffect(()=>{l?.providerId&&C(l.providerId)},[l?.providerId]),r.useEffect(()=>{u&&m(!1)},[u]),r.useEffect(()=>{l&&E(l)},[l,E]),r.useEffect(()=>{const s=Ue.connect(),a=d=>{const h=re.get(d.sessionId);if(h){if(R(h.id),d.status!==A.COMPLETED){E(h);return}if(h.id===u){E(h);return}ne(h.id)}};return s.on(je.SESSION_COMPLETED,a),()=>{s.off(je.SESSION_COMPLETED,a)}},[u,re,R,E,ne]);const Y=()=>{S(null),m(!0),n("/conversations")},fe=()=>{m(!1),n("/conversations")},ae=r.useCallback(s=>{E(s),m(!1),n(`/conversations/${s.id}`)},[E,n]),T=async s=>{if(!(!s.providerId||!s.title.trim()||k!=="idle")){D("starting-session"),S(null);try{const a=await te.mutateAsync({prompt:s.title.trim(),providerId:s.providerId,attachmentIds:s.attachmentIds});C(s.providerId),m(!1),n(`/conversations/${a.id}`)}catch(a){S(a instanceof Error?a.message:t("Failed to start. Please try again."))}finally{D("idle")}}},xe=async s=>{!l||!s.message.trim()||W.isPending||await W.mutateAsync({id:l.id,message:s.message,providerId:s.providerId||v||void 0,attachmentIds:s.attachmentIds})},oe=async()=>{!l||P.isPending||await P.mutateAsync(l.id)},ie=async s=>{window.confirm(t("Delete this conversation?"))&&(await G.mutateAsync(s),J(s),u===s&&(m(!1),n("/conversations")))};return e.jsxs("div",{className:"flex h-dvh flex-col overflow-hidden bg-sidebar text-sm text-foreground",children:[e.jsxs("header",{className:j("flex h-12 shrink-0 items-center justify-between bg-sidebar px-4",i&&"app-region-drag",p&&"pr-[150px]"),children:[e.jsxs("div",{className:j("flex min-w-0 items-center gap-2",w&&"pl-[72px]"),children:[e.jsx(ct,{}),e.jsx("span",{className:"mx-1.5 select-none text-muted-foreground/40",children:"/"}),e.jsx("span",{className:"truncate text-sm font-medium text-foreground/90",children:t("Conversation")})]}),e.jsx("button",{type:"button",onClick:()=>_e.getState().openSettings(),className:j("rounded-md p-1.5 text-muted-foreground/70 transition-colors hover:bg-accent hover:text-foreground",i&&"app-region-no-drag"),title:t("Settings"),children:e.jsx(Be,{size:16})})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[e.jsxs("aside",{className:j("h-full w-full shrink-0 flex-col bg-sidebar md:flex md:w-[320px]",se?"hidden md:flex":"flex"),children:[e.jsxs("div",{className:"shrink-0 px-2 pb-1 pt-2",children:[e.jsxs("button",{type:"button",onClick:Y,className:j("flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm transition-colors",o?"bg-accent text-foreground":"text-foreground/80 hover:bg-accent/50"),title:t("New Conversation"),children:[e.jsx(ut,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("New Conversation")})]}),e.jsxs("button",{type:"button",onClick:()=>n("/"),className:"flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm text-foreground/80 transition-colors hover:bg-accent/50",title:t("Tasks"),children:[e.jsx(pt,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("Tasks")})]}),e.jsxs("button",{type:"button",onClick:()=>g(!0),className:"flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm text-foreground/80 transition-colors hover:bg-accent/50",title:t("Search"),children:[e.jsx(Se,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("Search")})]})]}),e.jsx("div",{className:"relative min-h-0 flex-1 overflow-y-auto scrollbar-app-thin pb-4 pt-3",children:X?e.jsx("div",{className:"px-4 py-4 text-sm text-muted-foreground",children:t("Loading...")}):N.length===0?e.jsxs("div",{className:"flex h-full select-none flex-col items-center justify-center px-6 text-center",children:[e.jsx(pe,{size:36,className:"mb-3 text-muted-foreground/40",strokeWidth:1.5}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:t("No conversations")}),e.jsx("button",{type:"button",onClick:Y,className:"rounded-md bg-brand px-3.5 py-1.5 text-xs font-medium text-brand-foreground transition-colors hover:bg-brand/90",children:t("New Conversation")})]}):e.jsxs("div",{className:"mb-2",children:[e.jsxs("div",{className:"flex w-full items-center gap-1.5 px-4 py-1.5 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"flex-1 text-left",children:t("History")}),e.jsx("span",{className:"text-[11px] font-normal tabular-nums text-muted-foreground/50",children:N.length})]}),e.jsx("div",{className:"mt-0.5 flex min-h-[40px] flex-col rounded-md",children:N.map(s=>e.jsx(Dt,{conversation:s,selected:s.id===u,disabled:G.isPending,unread:s.id!==u&&U(s),onSelect:()=>ae(s),onDelete:()=>ie(s.id)},s.id))})]})}),e.jsx("div",{className:"flex items-center justify-between border-t border-border/60 px-4 py-3 text-xs text-muted-foreground/70",children:e.jsxs("span",{children:[t("Conversations")," · ",N.length]})})]}),e.jsxs("main",{className:j("min-w-0 flex-1 flex-col bg-background md:mb-2 md:mr-2 md:overflow-hidden md:rounded-xl md:border md:border-border/50",se?"flex":"hidden md:flex"),children:[e.jsx("header",{className:"flex h-12 shrink-0 items-center justify-between border-b border-border/60 px-4 md:px-5",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[M||o?e.jsx("button",{type:"button",className:"rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground md:hidden",onClick:fe,title:t("Back"),children:e.jsx($e,{size:17})}):null,e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-semibold",children:l?.title??t("New Conversation")}),l?e.jsxs("div",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[It(l.status,t),l.directoryName?` · ${l.directoryName}`:""]}):null]})]})}),!l&&M?e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center px-4 text-sm text-muted-foreground",children:t(ee?"Loading...":"Conversation not found")}):l?e.jsx(gt,{sessionId:l.sessionId,sessionStatus:l.status,sessionStartedAt:l.createdAt,sessionEndedAt:ge(l.status)?null:l.lastActiveAt??l.updatedAt,agentType:l.agentType,runtimeType:l.runtimeType,providerId:v||l.providerId,providers:F,initialTokenUsage:l.tokenUsage,onProviderChange:C,onSend:xe,onStop:oe,onExit:me,isSending:W.isPending,isStopping:P.isPending}):e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 pb-[10vh] md:px-8",children:e.jsxs("div",{className:"w-full max-w-2xl animate-[fadeInUp_0.5s_cubic-bezier(0.16,1,0.3,1)]",children:[e.jsx("h1",{className:"mb-8 max-w-full break-words text-center text-3xl leading-tight tracking-tight text-foreground",children:t("需要我帮你做点什么?")}),e.jsx(mt,{variant:"conversation",projects:[],providers:H,isProvidersLoading:V,defaultProviderId:v,createStep:k,placeholder:"Ask a question...",submitLabel:"Start",pendingLabel:"Starting...",submitTitle:"Start",onSubmit:async({title:s,providerId:a,attachmentIds:d})=>{await T({title:s,providerId:a,attachmentIds:d})}}),O?e.jsx("div",{className:"mt-3 rounded-lg border border-destructive/15 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:O}):null]})})]})]}),e.jsx(Et,{isOpen:ue,conversations:N,onClose:()=>g(!1),onSelectConversation:ae})]})}export{$t as ConversationPage};
|
|
3
|
+
`);K(""),oe(),ve(),F(null);try{await k({message:B,providerId:L||void 0,attachmentIds:y}),await U(),requestAnimationFrame(()=>M("smooth"))}catch(z){F(z instanceof Error?z.message:g("Send failed. Please try again.")),K(B)}finally{P.current=!1}},[I,a,S,o,q,d,ie,s,oe,ve,k,L,N,U,M,g]),Te=r.useCallback(async()=>{!he||o||q||await D()},[he,o,q,D]),Le=r.useCallback(c=>{const y=c.target.files;y&&y.length>0&&T(Array.from(y)),c.target.value=""},[T]),Pe=r.useCallback(c=>{const y=c.clipboardData.items,B=[];for(const z of y)if(z.kind==="file"){const ye=z.getAsFile();ye&&B.push(ye)}B.length>0&&(c.preventDefault(),T(B))},[T]),Me=r.useCallback(c=>{c.preventDefault(),$(!0)},[]),Re=r.useCallback(c=>{c.preventDefault(),$(!1)},[]),qe=r.useCallback(c=>{c.preventDefault(),$(!1);const y=c.dataTransfer.files;y.length>0&&T(Array.from(y))},[T]);return e.jsxs("div",{className:j("relative flex min-h-0 flex-1 flex-col bg-background",ue),children:[e.jsxs("div",{className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:H,className:"h-full overflow-y-auto scrollbar-app-thin px-6 pb-4 pt-6",children:e.jsx("div",{ref:l,className:"mx-auto w-full min-w-0 max-w-4xl",children:me?e.jsxs("div",{className:"flex items-center justify-center gap-3 py-12 text-muted-foreground/70",children:[e.jsxs("svg",{className:"h-5 w-5 animate-spin",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),e.jsx("span",{className:"text-sm",children:g("Loading logs...")})]}):J.length===0?e.jsx("div",{className:"py-8 text-center text-muted-foreground/70",children:g(h?"Waiting for agent output...":"No logs recorded for this session.")}):e.jsx(Ze,{children:e.jsx(We,{logs:J,downloadSessionId:t,isOutputActive:E,lastExitAt:ne,onUserToggleDetails:se,scrollElementRef:H})})})}),!W&&e.jsxs("button",{type:"button",onClick:()=>M(),className:"absolute bottom-3 left-1/2 z-10 flex -translate-x-1/2 items-center gap-1.5 rounded-full border border-border bg-background/90 px-3 py-1.5 text-xs text-muted-foreground shadow-md backdrop-blur-sm transition-all hover:bg-background hover:text-foreground","aria-label":g("Scroll to bottom"),children:[e.jsx(lt,{size:14}),e.jsx("span",{children:g("Back to bottom")})]})]}),Y.length>0&&e.jsx("div",{className:"shrink-0 border-t border-border/60 bg-background px-6 pb-1 pt-2",children:e.jsx("div",{className:"mx-auto max-w-4xl",children:e.jsx(et,{todos:Y})})}),e.jsx("div",{className:"z-10 w-full shrink-0 border-t border-transparent bg-background p-6 pb-6 pt-2",onDragOver:Me,onDragLeave:Re,onDrop:qe,children:e.jsxs("div",{className:"mx-auto max-w-4xl",children:[e.jsx(rt,{sessionId:t}),ee?e.jsx("div",{className:"mb-2 text-sm text-destructive",children:ee}):null,e.jsxs("div",{ref:G,className:j("relative rounded-xl border bg-background transition-colors duration-200 hover:border-ring/40 focus-within:border-ring/60",Z?"border-info bg-info/5":"border-border"),children:[e.jsx(Je,{files:ae,onRemove:xe}),e.jsx("textarea",{ref:V,value:I,onChange:Ee,onPaste:Pe,onKeyDown:c=>{c.key==="Enter"&&!c.shiftKey&&!c.repeat&&!c.nativeEvent.isComposing&&c.nativeEvent.keyCode!==229&&(c.preventDefault(),be())},rows:1,placeholder:g(Z?"Drop files here...":t&&!h?"Continue conversation...":"Message Agent..."),className:"w-full resize-none border-none bg-transparent px-4 pb-2 pt-4 text-sm leading-relaxed text-foreground placeholder-muted-foreground/70 focus:outline-none",style:{minHeight:"60px",maxHeight:"300px"}}),e.jsx("input",{ref:te,type:"file",multiple:!0,className:"hidden",onChange:Le}),e.jsxs("div",{className:"flex items-center justify-between px-2 pb-2 pt-1",children:[e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("button",{type:"button",onClick:()=>te.current?.click(),disabled:d,className:"rounded-lg p-2 text-muted-foreground/70 transition-colors hover:bg-muted hover:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",title:g("Upload file"),children:e.jsx(ct,{size:18})})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(at,{providers:b,currentProviderId:L,agentType:w,runtimeType:p,onSelect:De}),e.jsx(ot,{usage:fe}),he&&h&&!I.trim()&&!a?e.jsx("button",{type:"button",onClick:Te,disabled:o||q,className:"rounded-lg bg-destructive p-2 text-white transition-all duration-200 hover:bg-destructive/90 disabled:opacity-50",title:g("Stop"),children:e.jsx(Oe,{size:14})}):e.jsx("button",{type:"button",onClick:be,disabled:!I.trim()&&!a||d||S||o||q||!!N,className:j("rounded-lg p-2 transition-all duration-200",(I.trim()||a)&&!d&&!S&&!o&&!q&&!N?"bg-primary text-primary-foreground hover:bg-primary/90":"cursor-not-allowed bg-transparent text-muted-foreground/50"),title:g("Send"),children:e.jsx(dt,{size:18})})]})]})]})]})})]})}function vt(t=50){return ke({queryKey:f.conversations.list({limit:t}),queryFn:()=>_.get("/conversations",{params:{limit:String(t)}})})}function bt(t){return ke({queryKey:f.conversations.detail(t??""),queryFn:()=>_.get(`/conversations/${t}`),enabled:!!t})}function yt(){const t=X();return ce({mutationFn:n=>_.post("/conversations",n),onSuccess:n=>{t.setQueryData(f.conversations.detail(n.id),n),t.invalidateQueries({queryKey:f.conversations.all}),t.invalidateQueries({queryKey:f.sessions.detail(n.sessionId)})}})}function jt(){const t=X();return ce({mutationFn:({id:n,...i})=>_.post(`/conversations/${n}/message`,i),onSuccess:n=>{t.setQueryData(f.conversations.detail(n.id),n),t.invalidateQueries({queryKey:f.conversations.all}),t.invalidateQueries({queryKey:f.sessions.detail(n.sessionId)})}})}function Nt(){const t=X();return ce({mutationFn:n=>_.post(`/conversations/${n}/stop`),onSuccess:n=>{t.setQueryData(f.conversations.detail(n.id),n),t.invalidateQueries({queryKey:f.conversations.all}),t.invalidateQueries({queryKey:f.sessions.detail(n.sessionId)})},onSettled:(n,i,x)=>{const w=t.getQueryData(f.conversations.detail(x)),p=n?.sessionId??w?.sessionId;t.invalidateQueries({queryKey:f.conversations.detail(x)}),p&&(t.invalidateQueries({queryKey:f.sessions.detail(p)}),t.invalidateQueries({queryKey:f.sessions.runtime(p)}))}})}function wt(){const t=X();return ce({mutationFn:n=>_.delete(`/conversations/${n}`),onSuccess:(n,i)=>{t.removeQueries({queryKey:f.conversations.detail(i)}),t.invalidateQueries({queryKey:f.conversations.all})}})}const Ct=3e4,Ie="agent-tower:conversation-read-times";function kt(){try{const t=window.localStorage.getItem(Ie);if(!t)return{};const n=JSON.parse(t);return!n||typeof n!="object"||Array.isArray(n)?{}:Object.fromEntries(Object.entries(n).map(([i,x])=>[i,typeof x=="number"?x:Number(x)]).filter(i=>Number.isFinite(i[1])))}catch{return{}}}function Ne(t){try{window.localStorage.setItem(Ie,JSON.stringify(t))}catch{}}function we(t){const n=t.lastActiveAt??t.updatedAt??t.createdAt;if(!n)return 0;const i=new Date(n).getTime();return Number.isFinite(i)?i:0}function St(t=Ct){const[,n]=r.useState(0);r.useEffect(()=>{const i=setInterval(()=>n(x=>x+1),t);return()=>clearInterval(i)},[t])}function ge(t){return t===A.RUNNING||t===A.PENDING}function Ae(t){if(!t)return"";const n=new Date(t);if(Number.isNaN(n.getTime()))return"";const i=Math.max(0,Math.floor((Date.now()-n.getTime())/1e3));return i<60?le("{count}s ago",{count:i}):i<3600?le("{count}m ago",{count:Math.floor(i/60)}):i<86400?le("{count}h ago",{count:Math.floor(i/3600)}):le("{count}d ago",{count:Math.floor(i/86400)})}function It(t,n){switch(t){case A.RUNNING:return n("Running");case A.PENDING:return n("Starting");case A.COMPLETED:return n("Completed");case A.FAILED:return n("Failed");case A.CANCELLED:return n("Stopped");default:return t}}function Ce({className:t,pulseClassName:n}){return e.jsxs("span",{className:"relative inline-flex h-2 w-2",children:[e.jsx("span",{className:j("absolute inline-flex h-full w-full animate-ping rounded-full",n)}),e.jsx("span",{className:j("relative inline-flex h-2 w-2 rounded-full",t)})]})}function At({status:t,unread:n}){return ge(t)?e.jsx(Ce,{className:"bg-success",pulseClassName:"bg-success/70"}):n?e.jsx(Ce,{className:"bg-warning",pulseClassName:"bg-warning/70"}):null}function Dt({conversation:t,selected:n,onSelect:i,onDelete:x,disabled:w,unread:p}){const{t:u}=de(),b=Ae(t.lastActiveAt??t.createdAt),v=ge(t.status)||p;return e.jsxs("div",{className:j("group ml-4 mr-2 flex items-center rounded-md transition-colors",n?"bg-accent":"hover:bg-accent/50"),children:[e.jsxs("button",{type:"button",onClick:i,title:t.title,className:"flex min-w-0 flex-1 animate-task-enter items-center gap-2.5 rounded-md px-2 py-2 text-left text-sm",children:[e.jsx("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:e.jsx(pe,{size:14,className:"text-muted-foreground"})}),e.jsx("span",{className:j("min-w-0 flex-1 truncate",n?"font-medium text-foreground":"text-foreground/90"),children:t.title}),v?e.jsx("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:e.jsx(At,{status:t.status,unread:p})}):e.jsx("span",{className:"flex w-14 shrink-0 items-center justify-end text-[11px] tabular-nums text-muted-foreground/50",children:e.jsx("span",{className:"truncate group-hover:hidden",children:b})})]}),e.jsx("button",{type:"button",onClick:C=>{C.stopPropagation(),x()},disabled:w,className:"mr-1 hidden shrink-0 rounded-md p-1.5 text-muted-foreground hover:bg-background hover:text-destructive disabled:opacity-50 group-hover:flex",title:u("Delete"),children:e.jsx(xt,{size:14})})]})}function Et({isOpen:t,conversations:n,onClose:i,onSelectConversation:x}){const{t:w}=de(),[p,u]=r.useState(""),[b,v]=r.useState(0),C=r.useRef(null);r.useEffect(()=>{t&&(u(""),v(0))},[t]);const k=r.useMemo(()=>{const o=p.trim().toLowerCase();return o?n.filter(m=>m.title.toLowerCase().includes(o)).slice(0,50):n.slice(0,12)},[n,p]);r.useEffect(()=>{v(0)},[p]),r.useEffect(()=>{C.current?.children[b]?.scrollIntoView({block:"nearest"})},[b]);const D=r.useCallback(o=>{x(o),i()},[i,x]),O=r.useCallback(o=>{if(o.key==="Escape"){o.preventDefault(),i();return}if(o.key==="ArrowDown"){o.preventDefault(),v(m=>Math.min(m+1,k.length-1));return}if(o.key==="ArrowUp"){o.preventDefault(),v(m=>Math.max(m-1,0));return}if(o.key==="Enter"&&!o.nativeEvent.isComposing){o.preventDefault();const m=k[b];m&&D(m)}},[b,D,i,k]);if(!t)return null;const S=p.trim().length>0;return e.jsxs("div",{className:"fixed inset-0 z-90",role:"dialog","aria-modal":"true",children:[e.jsx("div",{className:"absolute inset-0 bg-black/20",onClick:i}),e.jsxs("div",{className:"absolute left-1/2 top-[18vh] w-[min(560px,calc(100vw-2rem))] -translate-x-1/2 overflow-hidden rounded-xl border border-border bg-popover shadow-lg animate-in fade-in zoom-in-95 duration-100",children:[e.jsxs("div",{className:"flex items-center gap-2.5 border-b border-border/60 px-4",children:[e.jsx(Se,{size:15,className:"shrink-0 text-muted-foreground/70"}),e.jsx("input",{value:p,onChange:o=>u(o.target.value),onKeyDown:O,placeholder:w("Search conversations..."),"aria-label":w("Search conversations..."),autoFocus:!0,className:"flex-1 border-none bg-transparent py-3 text-sm text-foreground placeholder-muted-foreground/60 focus:outline-none"})]}),k.length>0?e.jsxs(e.Fragment,{children:[S?null:e.jsx("div",{className:"px-4 pb-1 pt-2.5 text-[11px] font-medium text-muted-foreground/70",children:w("Recent conversations")}),e.jsx("div",{ref:C,className:"max-h-[46vh] overflow-y-auto pb-1.5 pt-0.5 scrollbar-app-thin",children:k.map((o,m)=>e.jsxs("button",{type:"button",onClick:()=>D(o),onMouseEnter:()=>v(m),className:j("flex w-full items-center gap-2.5 px-4 py-2 text-left transition-colors",m===b&&"bg-accent"),children:[e.jsx(pe,{size:14,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-foreground/90",title:o.title,children:o.title}),e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground/60",children:Ae(o.lastActiveAt??o.createdAt)})]},o.id))})]}):e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground/70",children:w("No matching conversations")})]})]})}function Ht(){const{t}=de();St();const n=Ke(),{usesIntegratedTitlebar:i,desktopPlatform:x,hasMacTrafficLights:w}=Qe(),p=i&&x==="win32",{conversationId:u}=Fe(),b=X(),[v,C]=r.useState(""),[k,D]=r.useState("idle"),[O,S]=r.useState(null),[o,m]=r.useState(!1),[ue,g]=r.useState(!1),[I,K]=r.useState(kt),[L,Q]=r.useState(()=>new Set),{data:N=[],isLoading:Z}=vt(),{data:$,isLoading:ee}=bt(u),{data:F=[],isLoading:V}=ft(),te=yt(),G=jt(),P=Nt(),H=wt(),l=$??N.find(s=>s.id===u)??null,W=r.useMemo(()=>F.map(s=>{const a=Ge(s);return{id:s.provider.id,name:s.provider.name,agentType:s.provider.agentType,available:!a,permissionMode:s.provider.executionPermission,reason:a}}),[F]),M=!!u,se=M||o,R=r.useCallback(s=>{b.invalidateQueries({queryKey:f.conversations.all}),s&&b.invalidateQueries({queryKey:f.conversations.detail(s)})},[b]),me=r.useCallback(()=>{R(u)},[u,R]),E=r.useCallback(s=>{if(Q(d=>{if(!d.has(s.id))return d;const h=new Set(d);return h.delete(s.id),h}),s.status!==A.COMPLETED)return;const a=Math.max(Date.now(),we(s));K(d=>{if(d[s.id]&&d[s.id]>=a)return d;const h={...d,[s.id]:a};return Ne(h),h})},[]),ne=r.useCallback(s=>{Q(a=>{if(a.has(s))return a;const d=new Set(a);return d.add(s),d})},[]),J=r.useCallback(s=>{Q(a=>{if(!a.has(s))return a;const d=new Set(a);return d.delete(s),d}),K(a=>{if(!(s in a))return a;const d={...a};return delete d[s],Ne(d),d})},[]),re=r.useMemo(()=>{const s=new Map;for(const a of N)s.set(a.sessionId,a);return l&&s.set(l.sessionId,l),s},[l,N]),U=r.useCallback(s=>s.status!==A.COMPLETED?!1:L.has(s.id)?!0:we(s)>(I[s.id]??0),[I,L]);r.useEffect(()=>{l||v||C(W.find(s=>s.available)?.id??"")},[l,v,W]),r.useEffect(()=>{l?.providerId&&C(l.providerId)},[l?.providerId]),r.useEffect(()=>{u&&m(!1)},[u]),r.useEffect(()=>{l&&E(l)},[l,E]),r.useEffect(()=>{const s=Ue.connect(),a=d=>{const h=re.get(d.sessionId);if(h){if(R(h.id),d.status!==A.COMPLETED){E(h);return}if(h.id===u){E(h);return}ne(h.id)}};return s.on(je.SESSION_COMPLETED,a),()=>{s.off(je.SESSION_COMPLETED,a)}},[u,re,R,E,ne]);const Y=()=>{S(null),m(!0),n("/conversations")},fe=()=>{m(!1),n("/conversations")},ae=r.useCallback(s=>{E(s),m(!1),n(`/conversations/${s.id}`)},[E,n]),T=async s=>{if(!(!s.providerId||!s.title.trim()||k!=="idle")){D("starting-session"),S(null);try{const a=await te.mutateAsync({prompt:s.title.trim(),providerId:s.providerId,attachmentIds:s.attachmentIds});C(s.providerId),m(!1),n(`/conversations/${a.id}`)}catch(a){S(a instanceof Error?a.message:t("Failed to start. Please try again."))}finally{D("idle")}}},xe=async s=>{!l||!s.message.trim()||G.isPending||await G.mutateAsync({id:l.id,message:s.message,providerId:s.providerId||v||void 0,attachmentIds:s.attachmentIds})},oe=async()=>{!l||P.isPending||await P.mutateAsync(l.id)},ie=async s=>{window.confirm(t("Delete this conversation?"))&&(await H.mutateAsync(s),J(s),u===s&&(m(!1),n("/conversations")))};return e.jsxs("div",{className:"flex h-dvh flex-col overflow-hidden bg-sidebar text-sm text-foreground",children:[e.jsxs("header",{className:j("flex h-12 shrink-0 items-center justify-between bg-sidebar px-4",i&&"app-region-drag",p&&"pr-[150px]"),children:[e.jsxs("div",{className:j("flex min-w-0 items-center gap-2",w&&"pl-[72px]"),children:[e.jsx(ut,{}),e.jsx("span",{className:"mx-1.5 select-none text-muted-foreground/40",children:"/"}),e.jsx("span",{className:"truncate text-sm font-medium text-foreground/90",children:t("Conversation")})]}),e.jsx("button",{type:"button",onClick:()=>_e.getState().openSettings(),className:j("rounded-md p-1.5 text-muted-foreground/70 transition-colors hover:bg-accent hover:text-foreground",i&&"app-region-no-drag"),title:t("Settings"),children:e.jsx(Be,{size:16})})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[e.jsxs("aside",{className:j("h-full w-full shrink-0 flex-col bg-sidebar md:flex md:w-[320px]",se?"hidden md:flex":"flex"),children:[e.jsxs("div",{className:"shrink-0 px-2 pb-1 pt-2",children:[e.jsxs("button",{type:"button",onClick:Y,className:j("flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm transition-colors",o?"bg-accent text-foreground":"text-foreground/80 hover:bg-accent/50"),title:t("New Conversation"),children:[e.jsx(mt,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("New Conversation")})]}),e.jsxs("button",{type:"button",onClick:()=>n("/"),className:"flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm text-foreground/80 transition-colors hover:bg-accent/50",title:t("Tasks"),children:[e.jsx(pt,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("Tasks")})]}),e.jsxs("button",{type:"button",onClick:()=>g(!0),className:"flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm text-foreground/80 transition-colors hover:bg-accent/50",title:t("Search"),children:[e.jsx(Se,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("Search")})]})]}),e.jsx("div",{className:"relative min-h-0 flex-1 overflow-y-auto scrollbar-app-thin pb-4 pt-3",children:Z?e.jsx("div",{className:"px-4 py-4 text-sm text-muted-foreground",children:t("Loading...")}):N.length===0?e.jsxs("div",{className:"flex h-full select-none flex-col items-center justify-center px-6 text-center",children:[e.jsx(pe,{size:36,className:"mb-3 text-muted-foreground/40",strokeWidth:1.5}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:t("No conversations")}),e.jsx("button",{type:"button",onClick:Y,className:"rounded-md bg-brand px-3.5 py-1.5 text-xs font-medium text-brand-foreground transition-colors hover:bg-brand/90",children:t("New Conversation")})]}):e.jsxs("div",{className:"mb-2",children:[e.jsxs("div",{className:"flex w-full items-center gap-1.5 px-4 py-1.5 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"flex-1 text-left",children:t("History")}),e.jsx("span",{className:"text-[11px] font-normal tabular-nums text-muted-foreground/50",children:N.length})]}),e.jsx("div",{className:"mt-0.5 flex min-h-[40px] flex-col rounded-md",children:N.map(s=>e.jsx(Dt,{conversation:s,selected:s.id===u,disabled:H.isPending,unread:s.id!==u&&U(s),onSelect:()=>ae(s),onDelete:()=>ie(s.id)},s.id))})]})}),e.jsx("div",{className:"flex items-center justify-between border-t border-border/60 px-4 py-3 text-xs text-muted-foreground/70",children:e.jsxs("span",{children:[t("Conversations")," · ",N.length]})})]}),e.jsxs("main",{className:j("min-w-0 flex-1 flex-col bg-background md:mb-2 md:mr-2 md:overflow-hidden md:rounded-xl md:border md:border-border/50",se?"flex":"hidden md:flex"),children:[e.jsx("header",{className:"flex h-12 shrink-0 items-center justify-between border-b border-border/60 px-4 md:px-5",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[M||o?e.jsx("button",{type:"button",className:"rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground md:hidden",onClick:fe,title:t("Back"),children:e.jsx($e,{size:17})}):null,e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-semibold",children:l?.title??t("New Conversation")}),l?e.jsxs("div",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[It(l.status,t),l.directoryName?` · ${l.directoryName}`:""]}):null]})]})}),!l&&M?e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center px-4 text-sm text-muted-foreground",children:t(ee?"Loading...":"Conversation not found")}):l?e.jsx(gt,{sessionId:l.sessionId,sessionStatus:l.status,sessionStartedAt:l.createdAt,sessionEndedAt:ge(l.status)?null:l.lastActiveAt??l.updatedAt,agentType:l.agentType,runtimeType:l.runtimeType,providerId:v||l.providerId,providers:F,initialTokenUsage:l.tokenUsage,onProviderChange:C,onSend:xe,onStop:oe,onExit:me,isSending:G.isPending,isStopping:P.isPending}):e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 pb-[10vh] md:px-8",children:e.jsxs("div",{className:"w-full max-w-2xl animate-[fadeInUp_0.5s_cubic-bezier(0.16,1,0.3,1)]",children:[e.jsx("h1",{className:"mb-8 max-w-full break-words text-center text-3xl leading-tight tracking-tight text-foreground",children:t("需要我帮你做点什么?")}),e.jsx(it,{variant:"conversation",projects:[],providers:W,isProvidersLoading:V,defaultProviderId:v,createStep:k,placeholder:"Ask a question...",submitLabel:"Start",pendingLabel:"Starting...",submitTitle:"Start",onSubmit:async({title:s,providerId:a,attachmentIds:d})=>{await T({title:s,providerId:a,attachmentIds:d})}}),O?e.jsx("div",{className:"mt-3 rounded-lg border border-destructive/15 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:O}):null]})})]})]}),e.jsx(Et,{isOpen:ue,conversations:N,onClose:()=>g(!1),onSelectConversation:ae})]})}export{Ht as ConversationPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as de,o as ve,n as ke,q as D,p as me,t as kt,a7 as Ct,m as ot,r as a,_ as St,$ as ie,u as ue,j as e,V as be,l as w,ai as Xe,a3 as Tt,E as Et,F as Mt,a8 as Ze,X as It,D as Rt,aj as At,ak as Lt}from"./index-CWbMMO6g.js";import{S as Je,R as ce,A as Ne,W as O,T as et}from"./agent-meta-DOylIs2N.js";import{T as Pe,u as Ot,A as Pt}from"./mermaid-NOHMQCX5-9-DTTfp6.js";import{G as _t,M as Dt}from"./BrandLogo-BjC1hcgv.js";import{g as zt,a as $t,l as _e}from"./ExecutionPermissionSelector-BX5Xx8ta.js";import{A as ge}from"./AgentLogo-I2etsqym.js";import{C as le}from"./chevron-down-C6Ta4vyM.js";import{C as ee}from"./check-Cm7Vstpm.js";import{d as Ft}from"./use-projects-BYUZwQ-q.js";import{M as tt}from"./MemberAvatar-TVtoxQe8.js";import{u as qt}from"./use-providers-DdV9gbj1.js";import{P as Gt}from"./trash-2-BF_3L-qk.js";import{g as at,T as Ut,a as Wt,F as Bt,G as Kt}from"./task-priority-wLXAgVZZ.js";import{P as Ht}from"./paperclip-CC7nHUQ7.js";const Qt=[["path",{d:"m7 6 5 5 5-5",key:"1lc07p"}],["path",{d:"m7 13 5 5 5-5",key:"1d48rs"}]],Vt=de("chevrons-down",Qt);const Yt=[["path",{d:"m17 11-5-5-5 5",key:"e8nh98"}],["path",{d:"m17 18-5-5-5 5",key:"2avn1x"}]],Xt=de("chevrons-up",Yt);const Zt=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]],Jt=de("shield-alert",Zt);const es=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],ts=de("shield",es);const ss=[["path",{d:"M2 20h.01",key:"4haj6o"}],["path",{d:"M7 20v-4",key:"j294jx"}],["path",{d:"M12 20v-8",key:"i3yub9"}],["path",{d:"M17 20V8",key:"1tkaf5"}]],ns=de("signal-high",ss);const rs=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],os=de("zap",rs);function it(t){const s=ve(),r=ot({queryKey:D.sessions.runtime(t),queryFn:()=>me.get(`/sessions/${t}/runtime`),enabled:!!t});return a.useEffect(()=>{if(!t)return;const o=St.connect(),c=g=>{g.sessionId===t&&s.invalidateQueries({queryKey:D.sessions.runtime(t)})},l=g=>{g.sessionId===t&&s.setQueryData(D.sessions.runtime(t),g.state)},f=()=>{s.invalidateQueries({queryKey:D.sessions.runtime(t)})};return o.on(ie.SESSION_PERMISSION_REQUESTED,c),o.on(ie.SESSION_PERMISSION_INVALIDATED,c),o.on(ie.SESSION_RUNTIME_STATE_CHANGED,l),o.on("connect",f),()=>{o.off(ie.SESSION_PERMISSION_REQUESTED,c),o.off(ie.SESSION_PERMISSION_INVALIDATED,c),o.off(ie.SESSION_RUNTIME_STATE_CHANGED,l),o.off("connect",f)}},[t,s]),r}function as(t){return t==="RUNNING"||t==="AWAITING_PERMISSION"||t==="CANCELLING"}function is(t){return t===Je.RUNNING||t===Je.PENDING}function Xs(t,s){const{data:r}=it(t);return{runtimeState:r,isActive:is(s)||as(r?.turnState),isCancelling:r?.turnState==="CANCELLING"}}function cs(){const t=ve();return ke({mutationFn:({sessionId:s,requestId:r,optionId:o})=>me.post(`/sessions/${s}/permissions/${r}/resolve`,{optionId:o}),onSettled:(s,r,o)=>{t.invalidateQueries({queryKey:D.sessions.runtime(o.sessionId)})}})}function Zs(){const t=ve();return ke({mutationFn:s=>me.post(`/sessions/${s}/start`),onSuccess:(s,r)=>{t.invalidateQueries({queryKey:D.sessions.detail(r)}),t.invalidateQueries({queryKey:D.tasks.all})}})}const ls=45e3;function Js(){const t=ve();return ke({mutationFn:async s=>{try{return await me.post(`/sessions/${s}/stop`,void 0,{signal:AbortSignal.timeout(ls)})}catch(r){throw r instanceof DOMException&&r.name==="TimeoutError"?new Error("Stop request timed out before the server answered. The session may still be stopping; refresh the status and retry."):r}},onError:s=>{kt.error(Ct("Failed to stop session. Refreshing status; check it and try again."),{description:s instanceof Error?s.message:void 0})},onSettled:(s,r,o)=>{t.setQueryData(D.sessions.runtime(o),c=>c?.turnState==="CANCELLING"?{...c,turnState:"IDLE"}:c),Promise.allSettled([t.invalidateQueries({queryKey:D.sessions.detail(o)}),t.invalidateQueries({queryKey:D.sessions.runtime(o)}),t.invalidateQueries({queryKey:D.workspaces.all}),t.invalidateQueries({queryKey:D.tasks.all})])}})}function en(){const t=ve();return ke({mutationFn:({id:s,message:r,providerId:o})=>me.post(`/sessions/${s}/message`,{message:r,providerId:o}),onSuccess:()=>{t.invalidateQueries({queryKey:D.workspaces.all}),t.invalidateQueries({queryKey:D.tasks.all})}})}function tn({sessionId:t,compact:s=!1}){const{t:r}=ue(),{data:o}=it(t),c=cs(),l=o?.pendingPermissions[0],f=l?.requestId,g=c.reset;return a.useEffect(()=>{g()},[f,g]),l?e.jsx("div",{className:w("mb-2 border-l-2 border-warning bg-warning/5 px-3 py-2.5",s&&"px-2.5 py-2"),children:e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(Jt,{className:"mt-0.5 h-4 w-4 shrink-0 text-warning","aria-hidden":"true"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:r("Permission required")}),e.jsx("div",{className:"mt-0.5 break-words text-xs text-muted-foreground",children:l.toolSummary||l.toolName||r("The agent needs approval to continue.")}),l.actionDetails?e.jsx("pre",{className:"mt-2 max-h-48 overflow-auto whitespace-pre-wrap break-all text-xs",children:l.actionDetails}):null,e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:l.options.map(p=>e.jsxs("button",{type:"button",disabled:c.isPending,onClick:()=>c.mutate({sessionId:t,requestId:l.requestId,optionId:p.optionId}),className:w("inline-flex min-h-8 items-center gap-1.5 border px-3 text-xs font-medium transition-colors disabled:opacity-50",p.kind.startsWith("reject")?"border-destructive/30 text-destructive hover:bg-destructive/10":"border-border bg-background text-foreground hover:bg-muted"),children:[c.isPending&&c.variables?.requestId===l.requestId&&c.variables.optionId===p.optionId?e.jsx(be,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":"true"}):null,r(p.name)]},p.optionId))}),c.error?e.jsx("div",{className:"mt-1.5 text-xs text-destructive",role:"alert",children:c.error.message}):null]})]})}):null}function we(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString()}function ds(t){return t>=.9?"text-red-500":t>=.7?"text-amber-500":"text-neutral-400"}function sn({usage:t,tooltipSide:s="top"}){const{t:r}=ue();if(!t)return null;const o=t.modelContextWindow,c=o?t.totalTokens/o:0,l=o?Math.min(Math.round(c*100),100):null,f=o?ds(c):"text-neutral-400",g=o?e.jsx("span",{children:r("上下文: {used} / {max} tokens",{used:we(t.totalTokens),max:we(o)})}):e.jsx("span",{children:r("已使用: {used} tokens",{used:we(t.totalTokens)})});return e.jsx(Pe,{content:g,side:s,children:e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-xs rounded-lg hover:bg-neutral-100 transition-colors cursor-default select-none",children:[e.jsx(_t,{size:14,className:f}),e.jsxs("span",{className:`tabular-nums ${f}`,children:[we(t.totalTokens),l!==null&&e.jsxs("span",{className:"text-neutral-300 ml-0.5",children:["/ ",l,"%"]})]})]})})}const ms={damping:.7,stiffness:.05,mass:1.25},us=70,ps=1e3/60,fs=350;let Ce=!1;globalThis.document?.addEventListener("mousedown",()=>{Ce=!0});globalThis.document?.addEventListener("mouseup",()=>{Ce=!1});globalThis.document?.addEventListener("click",()=>{Ce=!1});const nn=(t={})=>{const[s,r]=a.useState(!1),[o,c]=a.useState(t.initial!==!1),[l,f]=a.useState(!1),g=a.useRef(null);g.current=t;const p=a.useCallback(()=>{if(!Ce)return!1;const h=window.getSelection();if(!h||!h.rangeCount)return!1;const v=h.getRangeAt(0);return v.commonAncestorContainer.contains(x.current)||x.current?.contains(v.commonAncestorContainer)},[]),b=a.useCallback(h=>{n.isAtBottom=h,c(h)},[]),N=a.useCallback(h=>{n.escapedFromLock=h,r(h)},[]),n=a.useMemo(()=>{let h;return{escapedFromLock:s,isAtBottom:o,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return x.current?.scrollTop??0},set scrollTop(v){x.current&&(x.current.scrollTop=v,n.ignoreScrollToTop=x.current.scrollTop)},get targetScrollTop(){return!x.current||!R.current?0:x.current.scrollHeight-1-x.current.clientHeight},get calculatedTargetScrollTop(){if(!x.current||!R.current)return 0;const{targetScrollTop:v}=this;if(!t.targetScrollTop)return v;if(h?.targetScrollTop===v)return h.calculatedScrollTop;const y=Math.max(Math.min(t.targetScrollTop(v,{scrollElement:x.current,contentElement:R.current}),v),0);return h={targetScrollTop:v,calculatedScrollTop:y},requestAnimationFrame(()=>{h=void 0}),y},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=us}}},[]),k=a.useCallback((h={})=>{typeof h=="string"&&(h={animation:h}),h.preserveScrollPosition||b(!0);const v=Date.now()+(Number(h.wait)||0),y=Oe(g.current,h.animation),{ignoreEscapes:I=!1}=h;let S,z=n.calculatedTargetScrollTop;h.duration instanceof Promise?h.duration.finally(()=>{S=Date.now()}):S=v+(h.duration??0);const T=async()=>{const q=new Promise(requestAnimationFrame).then(()=>{if(!n.isAtBottom)return n.animation=void 0,!1;const{scrollTop:$}=n,W=performance.now(),te=(W-(n.lastTick??W))/ps;if(n.animation||(n.animation={behavior:y,promise:q,ignoreEscapes:I}),n.animation.behavior===y&&(n.lastTick=W),p()||v>Date.now())return T();if($<Math.min(z,n.calculatedTargetScrollTop)){if(n.animation?.behavior===y){if(y==="instant")return n.scrollTop=n.calculatedTargetScrollTop,T();n.velocity=(y.damping*n.velocity+y.stiffness*n.scrollDifference)/y.mass,n.accumulated+=n.velocity*te,n.scrollTop+=n.accumulated,n.scrollTop!==$&&(n.accumulated=0)}return T()}return S>Date.now()?(z=n.calculatedTargetScrollTop,T()):(n.animation=void 0,n.scrollTop<n.calculatedTargetScrollTop?k({animation:Oe(g.current,g.current.resize),ignoreEscapes:I,duration:Math.max(0,S-Date.now())||void 0}):n.isAtBottom)});return q.then($=>(requestAnimationFrame(()=>{n.animation||(n.lastTick=void 0,n.velocity=0)}),$))};return h.wait!==!0&&(n.animation=void 0),n.animation?.behavior===y?n.animation.promise:T()},[b,p,n]),d=a.useCallback(()=>{N(!0),b(!1)},[N,b]),u=a.useCallback(({target:h})=>{if(h!==x.current)return;const{scrollTop:v,ignoreScrollToTop:y}=n;let{lastScrollTop:I=v}=n;n.lastScrollTop=v,n.ignoreScrollToTop=void 0,y&&y>v&&(I=y),f(n.isNearBottom),setTimeout(()=>{if(n.resizeDifference||v===y)return;if(p()){N(!0),b(!1);return}const S=v>I,z=v<I;if(n.animation?.ignoreEscapes){n.scrollTop=I;return}z&&(N(!0),b(!1)),S&&N(!1),!n.escapedFromLock&&n.isNearBottom&&b(!0)},1)},[N,b,p,n]),C=a.useCallback(({target:h,deltaY:v})=>{let y=h;for(;!["scroll","auto"].includes(getComputedStyle(y).overflow);){if(!y.parentElement)return;y=y.parentElement}y===x.current&&v<0&&x.current.scrollHeight>x.current.clientHeight&&!n.animation?.ignoreEscapes&&(N(!0),b(!1))},[N,b,n]),x=st(h=>{x.current?.removeEventListener("scroll",u),x.current?.removeEventListener("wheel",C),h?.addEventListener("scroll",u,{passive:!0}),h?.addEventListener("wheel",C,{passive:!0})},[]),R=st(h=>{if(n.resizeObserver?.disconnect(),!h)return;let v;n.resizeObserver=new ResizeObserver(([y])=>{const{height:I}=y.contentRect,S=I-(v??I);if(n.resizeDifference=S,n.scrollTop>n.targetScrollTop&&(n.scrollTop=n.targetScrollTop),f(n.isNearBottom),S>=0){const z=Oe(g.current,v?g.current.resize:g.current.initial);k({animation:z,wait:!0,preserveScrollPosition:!0,duration:z==="instant"?void 0:fs})}else n.isNearBottom&&(N(!1),b(!0));v=I,requestAnimationFrame(()=>{setTimeout(()=>{n.resizeDifference===S&&(n.resizeDifference=0)},1)})}),n.resizeObserver?.observe(h)},[]);return{contentRef:R,scrollRef:x,scrollToBottom:k,stopScroll:d,isAtBottom:o||l,isNearBottom:l,escapedFromLock:s,state:n}};function st(t,s){const r=a.useCallback(o=>(r.current=o,t(o)),s);return r}const Le=new Map;function Oe(...t){const s={...ms};let r=!1;for(const c of t){if(c==="instant"){r=!0;continue}typeof c=="object"&&(r=!1,s.damping=c.damping??s.damping,s.stiffness=c.stiffness??s.stiffness,s.mass=c.mass??s.mass)}const o=JSON.stringify(s);return Le.has(o)||Le.set(o,Object.freeze(s)),r?"instant":Le.get(o)}function rn({providers:t,currentProviderId:s,agentType:r,runtimeType:o,onSelect:c}){const{t:l}=ue(),[f,g]=a.useState(!1),p=a.useRef(null),b=o===ce.ACP?ce.ACP:ce.CLI,N=t.filter(u=>String(u.provider.agentType)===r&&(u.provider.runtimeType===ce.ACP?ce.ACP:ce.CLI)===b),n=t.find(u=>u.provider.id===s),k=zt(t,s),d=k?e.jsx("span",{role:"alert",className:"block break-words text-[11px] leading-snug text-destructive",children:l(k)}):null;return a.useEffect(()=>{function u(C){p.current&&!p.current.contains(C.target)&&g(!1)}if(f)return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[f]),N.length===0||N.length===1&&N[0].provider.id===s?e.jsxs("div",{className:"min-w-[112px] max-w-[min(46vw,240px)] px-2 py-1.5 text-xs text-neutral-400 select-none cursor-default",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ge,{agentType:n?.provider.agentType??r,className:"size-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:n?.provider.name?Xe(n.provider.name,12):r})]}),d]}):e.jsxs("div",{className:"relative min-w-[112px] max-w-[min(46vw,240px)]",ref:p,children:[e.jsxs("button",{type:"button",onClick:()=>g(!f),className:"flex max-w-full items-center gap-1 text-xs px-2 py-1.5 rounded-lg transition-colors cursor-pointer hover:bg-neutral-100 text-neutral-400 hover:text-neutral-600",title:`Provider: ${n?.provider.name??r} (click to change)`,children:[e.jsx(ge,{agentType:n?.provider.agentType??r,className:"size-3.5"}),e.jsx("span",{className:"min-w-0 truncate",children:n?.provider.name?Xe(n.provider.name,12):r}),e.jsx(le,{size:12,className:`shrink-0 transition-transform ${f?"rotate-180":""}`})]}),d?e.jsx("div",{className:"px-2",children:d}):null,f&&e.jsxs("div",{className:"absolute bottom-full right-0 z-50 mb-1 max-h-[min(60vh,320px)] min-w-[160px] max-w-[min(80vw,320px)] overflow-y-auto rounded-lg border border-neutral-200 bg-white py-1 shadow-lg",children:[e.jsx("div",{className:"px-2 py-1 text-xs text-neutral-400 border-b border-neutral-100",children:l("切换渠道")}),N.map(u=>{const C=$t(u),x=u.provider.executionPermission?l("Required permission: {mode}",{mode:l(_e[u.provider.executionPermission])}):void 0;return e.jsx("div",{tabIndex:C?0:void 0,role:C?"group":void 0,"aria-label":C?[u.provider.name,x,l(C)].filter(Boolean).join(": "):void 0,className:"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",children:e.jsxs("button",{type:"button",disabled:!!C,onClick:()=>{c(u.provider.id),g(!1)},className:`disabled:cursor-not-allowed w-full flex items-center justify-between px-3 py-2 text-sm text-left hover:bg-neutral-50 transition-colors ${u.provider.id===s?"bg-blue-50 text-blue-600":"text-neutral-700"}`,children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(ge,{agentType:u.provider.agentType,className:"size-4"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate max-w-[200px]",children:u.provider.name}),u.provider.executionPermission?e.jsx("span",{className:"block text-xs",children:l(_e[u.provider.executionPermission])}):null,C?e.jsx("span",{className:"block max-w-[240px] break-words text-xs",children:l(C)}):null]}),u.provider.isDefault&&e.jsx("span",{className:"text-xs text-neutral-400",children:l("(默认)")})]}),u.provider.id===s&&e.jsx(ee,{size:14,className:"shrink-0"})]})},u.provider.id)})]})]})}function on(t,s){return a.useMemo(()=>{for(let r=t.length-1;r>=0;r--){const o=t[r];if(o.tokenUsage&&typeof o.tokenUsage.totalTokens=="number"&&o.tokenUsage.totalTokens>0)return{totalTokens:o.tokenUsage.totalTokens,modelContextWindow:o.tokenUsage.modelContextWindow}}return s??null},[t,s])}function nt({iconName:t,className:s}){switch(t){case"chevrons-up":return e.jsx(Xt,{className:s,"aria-hidden":"true"});case"signal-high":return e.jsx(ns,{className:s,"aria-hidden":"true"});case"chevrons-down":return e.jsx(Vt,{className:s,"aria-hidden":"true"});default:return e.jsx(Dt,{className:s,"aria-hidden":"true"})}}function an({priority:t,className:s}){const r=at(t);return e.jsx("span",{className:w("inline-flex shrink-0 items-center rounded px-1.5 py-0.5 text-[10px] font-semibold leading-none",r.className,s),title:`${r.code} · ${r.label}`,children:r.code})}function xs({value:t,onChange:s,disabled:r=!1,compact:o=!1}){const{t:c}=ue(),[l,f]=a.useState(!1),g=a.useRef(null),p=at(t);return a.useEffect(()=>{if(!l)return;const b=N=>{g.current&&!g.current.contains(N.target)&&f(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[l]),e.jsxs("div",{className:"relative",ref:g,children:[e.jsxs("button",{type:"button",disabled:r||!s,onClick:()=>f(b=>!b),"aria-haspopup":"listbox","aria-expanded":l,"aria-label":c("Task priority"),className:w("inline-flex items-center gap-1.5 rounded-md text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 disabled:cursor-not-allowed disabled:opacity-50",o?"px-1.5 py-1":"px-2 py-1.5",p.className),children:[e.jsx(nt,{iconName:p.iconName,className:"size-3.5"}),e.jsx("span",{children:c(p.label)}),s?e.jsx(le,{className:w("size-3 transition-transform",l&&"rotate-180"),"aria-hidden":"true"}):null]}),l&&e.jsx("div",{className:"absolute right-0 top-full z-50 mt-1.5 w-36 rounded-lg border border-border bg-popover p-1 shadow-lg",role:"listbox","aria-label":c("Task priority"),children:Ut.map(b=>{const N=b.value===p.value;return e.jsxs("button",{type:"button",role:"option","aria-selected":N,onClick:()=>{s?.(b.value),f(!1)},className:"flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-xs text-foreground/80 transition-colors hover:bg-accent",children:[e.jsx("span",{className:w("inline-flex size-5 items-center justify-center rounded",b.className),children:e.jsx(nt,{iconName:b.iconName,className:"size-3.5"})}),e.jsxs("span",{className:"flex-1",children:[b.code," · ",c(b.label)]}),N?e.jsx(ee,{className:"size-3.5 text-foreground","aria-hidden":"true"}):null]},b.value)})})]})}function rt(t,s,r,o){if(r.filter(f=>f===o).length<=1)return t;const l=r.slice(0,s+1).filter(f=>f===o).length;return`${t} #${l}`}function hs(t){return Object.values(t).filter(Boolean).length}function gs({mode:t,setMode:s,selectedTemplateId:r,setSelectedTemplateId:o,selectedMemberPresetIds:c,setSelectedMemberPresetIds:l,disabled:f=!1,compact:g=!1}){const{t:p}=ue(),{preserveDesktopSearch:b}=Tt(),[N,n]=a.useState(!1),{data:k}=qt(),{data:d,isError:u,isFetching:C,isLoading:x,refetch:R}=Et(),{data:h,isError:v,isFetching:y,isLoading:I,refetch:S}=Mt(),z=a.useMemo(()=>new Map((k??[]).map(({provider:m,availability:j})=>[m.id,m.name+(j.type==="NOT_FOUND"?p(" (不可用)"):"")])),[k,p]),T=a.useMemo(()=>new Map((d??[]).map(m=>[m.id,m])),[d]),q=a.useMemo(()=>new Map((h??[]).map(m=>[m.id,m])),[h]),$=a.useMemo(()=>c.map(m=>T.get(m)).filter(m=>!!m),[T,c]);a.useEffect(()=>{d!==void 0&&l(m=>{const j=m.filter(P=>T.has(P));return j.length===m.length&&j.every((P,U)=>P===m[U])?m:j})},[d,T,l]),a.useEffect(()=>{h!==void 0&&o(m=>!m||q.has(m)?m:null)},[o,q,h]);const W=m=>{f||o(j=>j===m?null:m)},te=m=>{f||l(j=>[...j,m])},Q=m=>{f||l(j=>j.filter((P,U)=>U!==m))},se=e.jsxs("section",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:p("团队模板")}),v?e.jsxs("div",{className:"rounded-lg bg-destructive/10 px-3 py-2.5 text-xs text-destructive",children:[e.jsx("span",{children:p("团队模板加载失败")}),e.jsx("button",{type:"button",onClick:()=>{S()},disabled:f||y,className:"ml-2 underline hover:no-underline",children:p("重试")})]}):I?e.jsxs("div",{className:"flex items-center gap-2 py-3 text-xs text-muted-foreground",children:[e.jsx(be,{size:12,className:"animate-spin"}),p("加载中...")]}):(h??[]).length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border bg-background px-3 py-3 text-xs text-muted-foreground",children:[p("当前没有团队模板"),e.jsx(Ze,{to:b("/settings/team"),className:"ml-1.5 text-info hover:underline",children:p("去创建")})]}):e.jsx("div",{className:w("space-y-1.5",g&&"sm:grid sm:grid-cols-2 sm:gap-1.5 sm:space-y-0"),children:(h??[]).map(m=>{const j=m.id===r,P=m.members?.length??0,U=m.members?.map(Y=>Y.memberPresetId)??[],V=m.members?.slice(0,3).map((Y,oe)=>rt(Y.memberPreset?.name??Y.memberPresetId,oe,U,Y.memberPresetId)).join(", ");return e.jsx("button",{type:"button",onClick:()=>W(m.id),disabled:f,className:w("w-full rounded-lg px-3 py-2 text-left border transition-all disabled:cursor-not-allowed disabled:opacity-60",j?"bg-background border-foreground/20 shadow-sm":"bg-background border-border/60 hover:border-border hover:bg-accent"),children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:w("text-xs truncate",j?"font-medium text-foreground":"text-foreground"),children:m.name}),e.jsxs("span",{className:"text-[10px] text-muted-foreground shrink-0",children:[P,p("人")]})]}),V&&e.jsx("div",{className:"mt-0.5 text-[10px] text-muted-foreground truncate",children:V})]}),j&&e.jsx(ee,{size:13,className:"shrink-0 text-foreground"})]})},m.id)})})]}),B=$.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:$.map((m,j)=>{const P=rt(m.name,j,c,m.id);return e.jsxs("div",{className:"inline-flex items-center gap-1 pl-1 pr-0.5 py-0.5 rounded-md border border-border/60 bg-background text-[10px] text-foreground",children:[e.jsx(tt,{name:m.name,avatar:m.avatar,className:"h-3.5 w-3.5 text-[7px]"}),e.jsx("span",{className:"max-w-[80px] truncate",children:P}),e.jsx("button",{type:"button",onClick:()=>Q(j),disabled:f,className:"p-0.5 text-muted-foreground hover:text-destructive disabled:opacity-30 rounded transition-colors",children:e.jsx(It,{size:9})})]},`${m.id}-${j}`)})}),re=u?e.jsxs("div",{className:"rounded-lg bg-destructive/10 px-3 py-2.5 text-xs text-destructive",children:[e.jsx("span",{children:p("成员预设加载失败")}),e.jsx("button",{type:"button",onClick:()=>{R()},disabled:f||C,className:"ml-2 underline hover:no-underline",children:p("重试")})]}):x?e.jsxs("div",{className:"flex items-center gap-2 py-3 text-xs text-muted-foreground",children:[e.jsx(be,{size:12,className:"animate-spin"}),p("加载中...")]}):(d??[]).length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border bg-background px-3 py-3 text-xs text-muted-foreground",children:[p("当前没有成员预设"),e.jsx(Ze,{to:b("/settings/team"),className:"ml-1.5 text-info hover:underline",children:p("去创建")})]}):e.jsx("div",{className:"space-y-1 max-h-[180px] overflow-y-auto pr-1",children:(d??[]).map(m=>{const j=c.filter(V=>V===m.id).length,P=z.get(m.providerId)??m.providerId,U=hs(m.capabilities);return e.jsxs("button",{type:"button",onClick:()=>te(m.id),disabled:f,className:w("flex items-center gap-2 w-full px-2 py-1.5 rounded-lg text-left border border-transparent transition-all",f&&"cursor-not-allowed opacity-60","bg-background hover:bg-accent hover:border-border/60"),children:[e.jsx(tt,{name:m.name,avatar:m.avatar,className:"h-6 w-6 text-[9px] shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs text-foreground truncate",children:m.name}),e.jsxs("div",{className:"text-[10px] text-muted-foreground truncate",children:[P," · ",U,"/10"]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[j>0&&e.jsxs("span",{className:"text-[10px] text-foreground font-semibold",children:["×",j]}),e.jsx(Gt,{size:12,className:"text-muted-foreground"})]})]},m.id)})}),K=$.length>0&&e.jsx("span",{className:"inline-flex items-center justify-center min-w-[16px] h-4 rounded-full bg-primary text-[10px] font-semibold text-primary-foreground px-1.5",children:$.length}),pe=e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[11px] font-medium text-muted-foreground shrink-0",children:p("执行模式")}),e.jsxs("div",{className:"inline-flex items-center h-7 rounded-md border border-border/70 bg-background p-0.5",children:[e.jsxs("button",{type:"button",onClick:()=>!f&&s("AUTO"),disabled:f,className:w("flex items-center gap-1.5 rounded h-full px-2.5 text-xs transition-all disabled:cursor-not-allowed disabled:opacity-50",t==="AUTO"?"bg-primary text-primary-foreground font-medium shadow-sm":"text-muted-foreground hover:text-foreground"),children:[e.jsx(os,{size:11}),p("自动模式")]}),e.jsxs("button",{type:"button",onClick:()=>!f&&s("CONFIRM"),disabled:f,className:w("flex items-center gap-1.5 rounded h-full px-2.5 text-xs transition-all disabled:cursor-not-allowed disabled:opacity-50",t==="CONFIRM"?"bg-primary text-primary-foreground font-medium shadow-sm":"text-muted-foreground hover:text-foreground"),children:[e.jsx(ts,{size:11}),p("确认模式")]})]})]});return g?e.jsxs("div",{className:"space-y-3",children:[pe,se,e.jsxs("div",{className:"border-t border-border/50 pt-2.5",children:[e.jsxs("button",{type:"button",onClick:()=>!f&&n(m=>!m),disabled:f,"aria-expanded":N,className:"flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground hover:text-foreground transition-colors disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(le,{size:12,className:w("transition-transform",N?"":"-rotate-90")}),p("追加独立成员"),K]}),N&&e.jsxs("div",{className:"mt-2",children:[B,re]})]})]}):e.jsxs("div",{className:"space-y-3.5",children:[pe,e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[se,e.jsxs("section",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:p("追加成员")}),K]}),B,re]})]})]})}function bs({commands:t,selectedIndex:s,query:r,hasCatalog:o,title:c="Slash Commands",queryPrefix:l="/",emptyCatalogMessage:f="No slash commands catalog for this agent yet.",emptyQueryMessage:g,insertionHint:p="Enter / Tab to insert",compact:b=!1,onSelect:N}){const n=b?"px-1.5 pb-1.5":"px-2 pb-2",k=b?"px-2 py-1.5":"px-2.5 py-2",d=b?"max-h-36":"max-h-48";return e.jsxs("div",{className:b?"pt-1.5":"pt-2",children:[e.jsxs("div",{className:`mb-1 flex items-center justify-between ${b?"px-2 pt-0.5":"px-3 pt-1"}`,children:[e.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-neutral-400",children:c}),e.jsx("span",{className:"text-[10px] text-neutral-400",children:p})]}),t.length===0?e.jsx("div",{className:`${b?"px-2 pb-2 pt-1.5 text-[11px]":"px-3 pb-3 pt-2 text-xs"} text-neutral-400`,children:o?g??`No matches for ${l}${r}`:f}):e.jsx("div",{className:`${n} ${d} overflow-y-auto`,children:t.map((u,C)=>e.jsxs("button",{type:"button",onMouseDown:x=>x.preventDefault(),onClick:()=>N(u),className:`w-full rounded-lg border text-left transition-colors ${C===s?"border-neutral-300 bg-neutral-50":"border-transparent hover:border-neutral-200 hover:bg-neutral-50/80"} ${k}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-mono text-[13px] text-neutral-900",children:u.command}),u.kind&&u.kind!=="builtin"?e.jsx("span",{className:"rounded-full border border-neutral-200 px-1.5 py-0.5 text-[9px] uppercase tracking-[0.12em] text-neutral-500",children:u.scope?`${u.scope} ${u.kind}`:u.kind}):null]}),e.jsx("div",{className:`${b?"mt-0.5 text-[11px]":"mt-1 text-xs"} text-neutral-500`,children:u.description})]},u.command))})]})}const J=12,je=8;function vs({open:t,anchorRef:s,commands:r,selectedIndex:o,query:c,hasCatalog:l,title:f,queryPrefix:g,emptyCatalogMessage:p,emptyQueryMessage:b,insertionHint:N,compact:n=!1,onSelect:k}){const d=a.useRef(null),[u,C]=a.useState(null);return a.useLayoutEffect(()=>{if(!t){C(null);return}const x=s.current;if(!x)return;let R=0;const h=()=>{const I=s.current;if(!I)return;const S=I.getBoundingClientRect(),z=window.innerWidth,T=window.innerHeight,q=n?260:320,$=n?z-J*2:560,W=Math.min(Math.max(S.width,q),Math.max(q,$)),te=Math.min(Math.max(J,S.left),Math.max(J,z-J-W)),Q=T-S.bottom-je-J,se=S.top-je-J,B=d.current?.offsetHeight??(n?220:280),re=n?240:320,K=Q<180&&se>Q,m=Math.max(120,Math.min(re,K?se:Q)),j=K?Math.max(J,S.top-je-Math.min(B,m)):Math.min(T-J-Math.min(B,m),S.bottom+je);C({top:j,left:te,width:W,maxHeight:m})},v=()=>{cancelAnimationFrame(R),R=requestAnimationFrame(h)};v();const y=new ResizeObserver(v);return y.observe(x),d.current&&y.observe(d.current),window.addEventListener("resize",v),window.addEventListener("scroll",v,!0),window.visualViewport?.addEventListener("resize",v),window.visualViewport?.addEventListener("scroll",v),()=>{cancelAnimationFrame(R),y.disconnect(),window.removeEventListener("resize",v),window.removeEventListener("scroll",v,!0),window.visualViewport?.removeEventListener("resize",v),window.visualViewport?.removeEventListener("scroll",v)}},[s,r.length,n,t,c,o]),!t||!u||typeof document>"u"?null:Rt.createPortal(e.jsx("div",{className:"pointer-events-none fixed inset-0 z-[120]",children:e.jsx("div",{ref:d,className:"pointer-events-auto fixed overflow-hidden rounded-xl border border-neutral-200 bg-white shadow-lg shadow-neutral-200/70",style:{top:u.top,left:u.left,width:u.width,maxHeight:u.maxHeight},children:e.jsx(bs,{commands:r,selectedIndex:o,query:c,hasCatalog:l,title:f,queryPrefix:g,emptyCatalogMessage:p,emptyQueryMessage:b,insertionHint:N,compact:n,onSelect:k})})}),document.body)}function ys({agentType:t,workingDir:s}){return ot({queryKey:D.system.slashCommandCatalog(t,s),queryFn:async()=>(await me.get("/system/slash-command-catalog",{params:{agentType:String(t),...s?{workingDir:s}:{}}})).commands,enabled:!!t,staleTime:3e4})}function Ns(t,s){const r=new Set,o=[];for(const c of[...t,...s]){const l=c.command.trim().toLowerCase();!l||r.has(l)||(r.add(l),o.push(c.kind?c:{...c,kind:"builtin"}))}return o}function Se(t){return t.trim().toLowerCase().replace(/^[/$]/,"")}function ws(t){return Se(t.command)}function js(t,s){if(!s)return 1e3;const r=ws(t),o=t.aliases?.map(Se)??[],c=[r,...o];let l=0;for(const g of c)g===s?l=Math.max(l,500):g.startsWith(s)?l=Math.max(l,400-(g.length-s.length)):g.includes(s)&&(l=Math.max(l,250-g.indexOf(s)));return l>0?l:`${r} ${o.join(" ")} ${t.description}`.toLowerCase().includes(s)?100:0}function cn(t){const s=/(^|[\s])\$([^\s]*)$/.exec(t);if(!s||s.index===void 0)return null;const r=s.index+s[1].length;return{query:Se(s[2]),replaceStart:r}}function ks(t,s){const r=Se(s);return r?t.map((o,c)=>({command:o,index:c,score:js(o,r)})).filter(o=>o.score>0).sort((o,c)=>c.score-o.score||o.index-c.index||o.command.command.localeCompare(c.command.command)).map(o=>o.command):t.slice()}const Cs=[{command:"/permissions",description:"Manage what Codex can do without approval"},{command:"/sandbox-add-read-dir",description:"Grant read access to another directory"},{command:"/agent",description:"Switch between built-in agent personas"},{command:"/apps",description:"Manage connected apps"},{command:"/clear",description:"Start a fresh conversation"},{command:"/compact",description:"Replace chat context with a summary"},{command:"/copy",description:"Copy the last assistant message to your clipboard"},{command:"/diff",description:"Show the current git diff"},{command:"/experimental",description:"Toggle experimental features"},{command:"/feedback",description:"Share feedback on Codex CLI"},{command:"/init",description:"Create or update AGENTS.md for the repo"},{command:"/logout",description:"Sign out of Codex"},{command:"/mcp",description:"Manage MCP servers"},{command:"/mention",description:"Add files or directories to the conversation context"},{command:"/model",description:"Change the active model"},{command:"/fast",description:"Toggle low reasoning mode"},{command:"/plan",description:"Toggle plan mode for code changes"},{command:"/personality",description:"Select how Codex communicates"},{command:"/ps",description:"List running background tasks"},{command:"/fork",description:"Fork the current conversation state"},{command:"/resume",description:"Resume a previous conversation"},{command:"/new",description:"Open a conversation picker to start or resume"},{command:"/quit",description:"Exit Codex CLI",aliases:["exit"]},{command:"/review",description:"Run a code review"},{command:"/status",description:"Show session and configuration status"},{command:"/debug-config",description:"Inspect the effective configuration"},{command:"/statusline",description:"Configure the custom status line"},{command:"/skills",description:"Browse available skills and insert a $skill mention"}],Ss=[{command:"/clear",description:"Clear the conversation history"},{command:"/compact",description:"Compact the conversation context",aliases:["compact focus"]},{command:"/config",description:"Open the configuration panel"},{command:"/cost",description:"Show token usage and cost"},{command:"/doctor",description:"Check Claude Code installation health"},{command:"/help",description:"Show help and available commands"},{command:"/init",description:"Initialize project instructions"},{command:"/login",description:"Sign in to Claude Code"},{command:"/logout",description:"Sign out of Claude Code"},{command:"/mcp",description:"Manage MCP servers"},{command:"/memory",description:"Edit project memory files"},{command:"/model",description:"Change the active model"},{command:"/permissions",description:"Review or update tool permissions"},{command:"/pr_comments",description:"Read pull request review comments"},{command:"/review",description:"Run a code review"},{command:"/status",description:"Show account and system status"},{command:"/terminal-setup",description:"Configure terminal newline shortcuts"},{command:"/vim",description:"Toggle vim mode"}],Ts=[{command:"/bug",description:"File an issue about Gemini CLI"},{command:"/chat",description:"Manage chat checkpoints and exports"},{command:"/clear",description:"Clear the terminal display"},{command:"/compress",description:"Replace chat context with a summary"},{command:"/copy",description:"Copy the last Gemini CLI output"},{command:"/directory",description:"Manage additional workspace directories",aliases:["dir"]},{command:"/editor",description:"Choose the preferred editor"},{command:"/extensions",description:"List active Gemini CLI extensions"},{command:"/help",description:"Show help and command usage",aliases:["?"]},{command:"/mcp",description:"Show MCP servers and tools"},{command:"/memory",description:"Manage loaded GEMINI.md memory"},{command:"/restore",description:"Restore files from a tool checkpoint"},{command:"/settings",description:"Open the Gemini CLI settings editor"},{command:"/stats",description:"Show session statistics and token usage"},{command:"/theme",description:"Change the Gemini CLI theme"},{command:"/auth",description:"Change the authentication method"},{command:"/about",description:"Show version information"},{command:"/tools",description:"List currently available tools"},{command:"/privacy",description:"Review privacy and data collection settings"},{command:"/quit",description:"Exit Gemini CLI",aliases:["exit"]},{command:"/vim",description:"Toggle vim mode"},{command:"/init",description:"Generate a tailored GEMINI.md file"}],Es=[{command:"/model",description:"Change the active model"},{command:"/plan",description:"Create or reopen a plan"},{command:"/ask",description:"Toggle ask mode (read-only Q&A)"},{command:"/debug",description:"Toggle debug mode"},{command:"/clear",description:"Start a new chat session",aliases:["new","new-chat","newchat"]},{command:"/compress",description:"Summarize the conversation to reduce context"},{command:"/vim",description:"Toggle vim mode"},{command:"/shell",description:"Enter shell mode"},{command:"/about",description:"Show CLI, system, and account information"},{command:"/setup-terminal",description:"Configure terminal newline shortcuts"},{command:"/feedback",description:"Share feedback with the Cursor team"},{command:"/open",description:"Open the repository git root in Cursor"},{command:"/cursor",description:"Alias for /open",aliases:["open"]},{command:"/resume-chat",description:"Resume a previous chat by folder name",aliases:["resume"]},{command:"/copy-request-id",description:"Copy the last request ID"},{command:"/copy-conversation-id",description:"Copy the current conversation ID"},{command:"/logout",description:"Sign out from Cursor"},{command:"/quit",description:"Exit Cursor Agent",aliases:["exit"]},{command:"/mcp",description:"Manage MCP servers"}],Ms={[Ne.CODEX]:Cs,[Ne.CLAUDE_CODE]:Ss,[Ne.GEMINI_CLI]:Ts,[Ne.CURSOR_AGENT]:Es};function ct(t){return t.trim().toLowerCase().replace(/^\//,"")}function Is(t){return t?(Ms[t]??[]).map(s=>({...s,kind:s.kind??"builtin"})):[]}function Rs(t){const s=t.match(/^\s*\/([^\s]*)$/);return s?ct(s[1]):null}function As(t,s){return ks(t,ct(s))}function Ls(t){const s=t.key==="Enter"&&!t.shiftKey&&!t.repeat&&!t.nativeEvent.isComposing&&t.nativeEvent.keyCode!==229,r=t.key==="Tab"&&!t.shiftKey;return s||r}function Os({agentType:t,workingDir:s,input:r,setInput:o,textareaRef:c,minHeight:l,maxHeight:f}){const[g,p]=a.useState(0),{data:b=[]}=ys({agentType:t,workingDir:s}),N=a.useMemo(()=>Ns(Is(t),b),[t,b]),n=a.useMemo(()=>Rs(r),[r]),k=a.useMemo(()=>n===null?[]:As(N,n),[N,n]),d=a.useCallback(()=>{const x=c.current;x&&(x.style.height="auto",x.style.height=`${Math.max(l,Math.min(x.scrollHeight,f))}px`)},[f,l,c]);a.useEffect(()=>{p(0)},[t,n]),a.useEffect(()=>{g<k.length||p(0)},[k.length,g]);const u=a.useCallback(x=>{const h=`${r.match(/^(\s*)\/[^\s]*$/)?.[1]??""}${x.command} `;o(h),requestAnimationFrame(()=>{const v=c.current;v&&(d(),v.focus(),v.setSelectionRange(h.length,h.length))})},[r,d,o,c]),C=a.useCallback(x=>n===null||k.length===0?!1:x.key==="ArrowDown"?(x.preventDefault(),p(R=>(R+1)%k.length),!0):x.key==="ArrowUp"?(x.preventDefault(),p(R=>(R-1+k.length)%k.length),!0):Ls(x)?(x.preventDefault(),u(k[g]??k[0]),!0):!1,[u,k,n,g]);return{allCommands:N,query:n,filteredCommands:k,selectedIndex:g,setSelectedIndex:p,applyCommand:u,handleKeyDown:C}}const Ps={idle:"","creating-task":"Creating Task...","creating-teamrun":"Creating TeamRun...","creating-workspace":"Creating Workspace...","creating-session":"Creating Session...","starting-session":"Starting Agent..."};function ln({variant:t="task",projects:s,providers:r,isProvidersLoading:o,onSubmit:c,defaultProjectId:l="",defaultProviderId:f="",onProjectChange:g,createStep:p,placeholder:b,submitLabel:N,pendingLabel:n,submitTitle:k}){const{t:d}=ue(),[u,C]=a.useState(""),[x,R]=a.useState(l),[h,v]=a.useState(f),y=h||f,[I,S]=a.useState("SOLO"),[z,T]=a.useState(O.WORKTREE),[q,$]=a.useState(et.NORMAL),[W,te]=a.useState({}),[Q,se]=a.useState("AUTO"),[B,re]=a.useState(null),[K,pe]=a.useState([]),[m,j]=a.useState(!1),[P,U]=a.useState(!1),[V,Y]=a.useState(!1),[oe,ne]=a.useState(!1),Te=a.useRef(null),Ee=a.useRef(null),Me=a.useRef(null),De=a.useRef(null),ze=a.useRef(null),$e=a.useRef(null),{files:Fe,addFiles:ae,removeFile:lt,clear:qe,buildMarkdownLinks:Ge,getDoneAttachments:Ue,isUploading:ye}=Ot(),fe=Ft(),E=t==="conversation",M=t==="task"||t==="conversation",dt=N??d(E?"开始":"创建");a.useEffect(()=>{R(l),g?.(l)},[l,g]),a.useEffect(()=>{if(!P)return;const i=A=>{Te.current&&!Te.current.contains(A.target)&&U(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[P]),a.useEffect(()=>{if(!V)return;const i=A=>{Ee.current&&!Ee.current.contains(A.target)&&Y(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[V]),a.useEffect(()=>{if(!oe)return;const i=A=>{Me.current&&!Me.current.contains(A.target)&&ne(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[oe]);const G=a.useMemo(()=>s.find(i=>i.id===x),[s,x]),H=a.useMemo(()=>r.find(i=>i.id===y),[r,y]),Ie=x?W[x]:void 0,mt=(Ie?.isGitRepo??G?.isGitRepo)!==!1,ut=(Ie?.worktreeReady??G?.worktreeReady)!==!1,F=!E&&!(mt&&ut),_=F?"SOLO":I,X=F?O.MAIN_DIRECTORY:z,pt=X===O.MAIN_DIRECTORY?d("本地模式"):d("工作树模式"),We=d("工作树隔离改动,支持 TeamRun、Merge、Rebase 和冲突解决。"),ft=d("本地模式会直接修改项目主目录,不会自动提交,也不能使用 Merge、Rebase 或冲突解决。"),xt=Ie?.reason??G?.reason,Be=d(xt==="NO_HEAD"?"已检测到 Git,但需要先提交一次才能使用工作树模式。":"初始化 Git 后可使用工作树模式。"),Ke=E||_==="SOLO"?H?.agentType:null,Z=Os({agentType:Ke,workingDir:E?void 0:G?.repoPath,input:u,setInput:C,textareaRef:ze,minHeight:76,maxHeight:220}),L=p!=="idle",He=!!B||K.length>0,xe=!L&&!ye&&u.trim().length>0&&(E?H?.available===!0:!!x&&(_==="SOLO"?H?.available===!0:He));a.useEffect(()=>{F&&(S("SOLO"),T(O.MAIN_DIRECTORY),j(!1),ne(!1))},[F]),a.useEffect(()=>{F||E||T(O.WORKTREE)},[E,F,G?.id]);const ht=a.useCallback(async()=>{if(!G||fe.isPending)return;const i=await fe.mutateAsync({id:G.id});te(A=>({...A,[G.id]:i})),i.worktreeReady&&(S("SOLO"),T(O.WORKTREE),ne(!1))},[fe,G]),Re=a.useCallback(async()=>{if(!xe)return;const i=M?Ge():"",A=M?Ue().map(he=>he.id):[];try{await c({title:u.trim(),description:"",projectId:E?"":x,providerId:y,mode:E?"SOLO":_,workspaceMode:!E&&_==="SOLO"?X:O.WORKTREE,teamRunMode:E?"AUTO":Q,teamTemplateId:E||F?null:B,memberPresetIds:E||F?[]:K,attachmentLinks:i,attachmentIds:A,priority:q}),C(""),$(et.NORMAL),M&&qe()}catch{}},[xe,M,Ge,Ue,c,u,E,x,y,_,X,Q,F,B,K,qe,q]),gt=a.useCallback(i=>{Z.handleKeyDown(i)||i.key==="Enter"&&!i.shiftKey&&!i.nativeEvent.isComposing&&i.nativeEvent.keyCode!==229&&(i.preventDefault(),Re())},[Re,Z]),bt=a.useCallback(i=>{const A=i.target.files;A&&A.length>0&&ae(Array.from(A)),i.target.value=""},[ae]),vt=a.useCallback(i=>{R(i),g?.(i),U(!1)},[g]),yt=a.useCallback(i=>{if(!M)return;const A=i.clipboardData.items,he=[];for(const Ve of A)if(Ve.kind==="file"){const Ye=Ve.getAsFile();Ye&&he.push(Ye)}he.length>0&&(i.preventDefault(),ae(he))},[ae,M]),[Qe,Ae]=a.useState(!1),Nt=a.useCallback(i=>{M&&(i.preventDefault(),Ae(!0))},[M]),wt=a.useCallback(i=>{M&&(i.preventDefault(),Ae(!1))},[M]),jt=a.useCallback(i=>{if(!M)return;i.preventDefault(),Ae(!1);const A=i.dataTransfer.files;A.length>0&&ae(Array.from(A))},[ae,M]);return e.jsxs("div",{className:"w-full",children:[e.jsxs("div",{ref:De,className:w("relative bg-background rounded-xl border transition-colors duration-200","shadow-[0_1px_2px_rgba(0,0,0,0.05)]","hover:border-ring/40 focus-within:border-ring/60",Qe?"border-info bg-info/5":"border-border",L&&"opacity-80"),onDragOver:M?Nt:void 0,onDragLeave:M?wt:void 0,onDrop:M?jt:void 0,children:[M&&Fe.length>0&&e.jsx("div",{className:"px-4 pt-3",children:e.jsx(Pt,{files:Fe,onRemove:lt})}),e.jsx("textarea",{ref:ze,value:u,onChange:i=>C(i.target.value),onKeyDown:gt,onPaste:M?yt:void 0,placeholder:d(b||"Describe your task..."),disabled:L,autoFocus:!0,rows:1,className:"w-full px-4 pt-4 pb-2 bg-transparent border-none focus:outline-none resize-none text-[15px] text-foreground placeholder:text-muted-foreground/80 leading-relaxed",style:{minHeight:"76px",maxHeight:"220px",fieldSizing:"content"}}),M&&Qe&&e.jsx("div",{className:"px-4 pb-2",children:e.jsx("div",{className:"flex items-center justify-center py-3 border border-dashed border-info/40 rounded-lg text-xs font-medium text-info",children:d("Drop files here")})}),e.jsxs("div",{className:"flex items-center justify-between px-2 pb-2 pt-1",children:[e.jsx("div",{className:"flex items-center gap-1",children:M?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>$e.current?.click(),disabled:L||ye,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:d("Attach files"),children:e.jsx(Ht,{size:18})}),e.jsx("input",{ref:$e,type:"file",multiple:!0,onChange:bt,className:"hidden"})]}):null}),e.jsxs("div",{className:"flex items-center gap-2",children:[M&&ye&&e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(be,{size:14,className:"animate-spin"}),d("Uploading...")]}),L&&e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(be,{size:14,className:"animate-spin"}),d(n??Ps[p])]}),!E&&!L&&!ye&&_==="TEAM"&&!He&&u.trim().length>0&&e.jsx("span",{className:"text-[11px] text-warning",children:d("请选择团队模板或追加成员")}),xe&&e.jsxs("span",{className:"hidden sm:inline-flex items-center gap-1 text-[11px] text-muted-foreground/80 select-none",children:[e.jsx("kbd",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded border border-border bg-muted/60 text-[10px] font-medium text-muted-foreground leading-none",children:"⏎"}),dt]}),e.jsx("button",{type:"button",onClick:Re,disabled:!xe,className:w("flex items-center justify-center size-8 rounded-lg transition-all duration-200",xe?"bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm":"bg-muted text-muted-foreground/40 cursor-not-allowed"),title:d(k||"Create & Start"),children:e.jsx(Wt,{size:16,strokeWidth:2.5})})]})]})]}),e.jsx(vs,{open:!!Ke&&Z.query!==null,anchorRef:De,commands:Z.filteredCommands,selectedIndex:Z.selectedIndex,query:Z.query??"",hasCatalog:Z.allCommands.length>0,compact:!0,onSelect:Z.applyCommand}),e.jsxs("div",{className:"flex items-center flex-wrap gap-1.5 mt-2.5 px-0.5",children:[!E&&e.jsxs("div",{className:"relative",ref:Te,children:[e.jsxs("button",{type:"button",onClick:()=>{L||U(i=>!i)},disabled:L,className:w("flex items-center gap-1.5 px-2 h-7 rounded-md text-xs font-medium transition-colors","hover:bg-accent disabled:opacity-40 disabled:cursor-not-allowed",G?"text-foreground/80":"text-muted-foreground"),children:[e.jsx(Bt,{size:14,className:"shrink-0",style:{color:G?.color??"var(--muted-foreground)"}}),e.jsx("span",{className:"max-w-[120px] truncate",children:G?.name??d("Project")}),e.jsx(le,{size:12,className:w("text-muted-foreground transition-transform",P&&"rotate-180")})]}),P&&e.jsx("div",{className:"absolute top-full left-0 mt-1.5 w-56 bg-popover border border-border rounded-lg shadow-[0_4px_12px_rgba(0,0,0,0.06)] py-1 max-h-[240px] overflow-y-auto z-50",children:s.map(i=>e.jsxs("button",{type:"button",onClick:()=>vt(i.id),className:"flex items-center w-full px-3 py-2 text-xs text-left hover:bg-accent transition-colors",children:[e.jsx("span",{className:"size-2 rounded-full shrink-0 mr-2",style:{backgroundColor:i.color??"var(--muted-foreground)"}}),e.jsx("span",{className:w("truncate flex-1",i.id===x?"text-foreground font-medium":"text-muted-foreground"),children:i.name}),e.jsx(ee,{size:14,className:w("ml-2 shrink-0 text-foreground",i.id===x?"opacity-100":"opacity-0")})]},i.id))})]}),(E||_==="SOLO")&&e.jsxs("div",{className:"relative",ref:Ee,children:[e.jsxs("button",{type:"button",onClick:()=>{L||Y(i=>!i)},disabled:L,className:w("flex items-center gap-1.5 px-2 h-7 rounded-md text-xs font-medium transition-colors","hover:bg-accent disabled:opacity-40 disabled:cursor-not-allowed",H?"text-foreground/80":"text-muted-foreground"),children:[e.jsx(ge,{agentType:H?.agentType,className:"size-3.5"}),e.jsx("span",{className:"max-w-[120px] truncate",children:H?.name??d(o?"Loading...":"Agent")}),e.jsx(le,{size:12,className:w("text-muted-foreground transition-transform",V&&"rotate-180")})]}),V&&e.jsx("div",{className:"absolute top-full left-0 z-50 mt-1.5 max-h-[min(60vh,320px)] w-72 max-w-[calc(100vw-2rem)] overflow-y-auto rounded-lg border border-border bg-popover py-1 shadow-[0_4px_12px_rgba(0,0,0,0.06)] sm:w-80",children:r.map(i=>e.jsx("div",{tabIndex:i.available?void 0:0,role:i.available?void 0:"group","aria-label":i.available?void 0:`${i.name}: ${d(i.reason||"Agent executable is unavailable.")}`,className:"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",children:e.jsxs("button",{type:"button",disabled:!i.available,onClick:()=>{v(i.id),Y(!1)},className:w("flex w-full items-start px-3 py-2 text-left text-xs transition-colors hover:bg-accent",!i.available&&"cursor-not-allowed"),children:[e.jsx(ee,{size:14,className:w("mr-2 mt-0.5 shrink-0 text-foreground",i.id===y?"opacity-100":"opacity-0")}),e.jsx(ge,{agentType:i.agentType,className:"mr-2 mt-0.5 size-3.5 shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:w("block break-words",i.id===y?"font-medium text-foreground":"text-muted-foreground"),children:[i.name,i.available?"":d(" (unavailable)")]}),i.permissionMode?e.jsx("span",{className:"mt-0.5 block text-[11px] text-muted-foreground",children:d("Required permission: {mode}",{mode:d(_e[i.permissionMode])})}):null,i.reason?e.jsx("span",{className:"mt-0.5 block break-words text-[11px] leading-snug text-destructive",children:d(i.reason)}):null]})]})},i.id))})]}),!E&&_==="SOLO"&&e.jsxs("div",{className:"relative",ref:Me,children:[e.jsxs("button",{type:"button",onClick:()=>{L||ne(i=>!i)},disabled:L,className:w("flex items-center gap-1.5 px-2 h-7 rounded-md text-xs font-medium transition-colors","hover:bg-accent disabled:opacity-40 disabled:cursor-not-allowed text-foreground/80"),children:[e.jsx(Kt,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"max-w-[96px] truncate",children:pt}),e.jsx(le,{size:12,className:w("text-muted-foreground transition-transform",oe&&"rotate-180")})]}),oe&&e.jsxs("div",{className:"absolute top-full left-0 mt-1.5 w-72 max-w-[calc(100vw-2rem)] bg-popover border border-border rounded-lg shadow-[0_4px_12px_rgba(0,0,0,0.06)] py-1 z-50",children:[F?e.jsx(Pe,{side:"bottom",className:"block w-full",content:Be,children:e.jsxs("div",{tabIndex:0,"aria-label":Be,className:"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60",children:[e.jsxs("button",{type:"button",disabled:!0,className:"flex w-full cursor-not-allowed items-center px-3 py-2 text-left text-xs opacity-40 transition-colors",children:[e.jsx(ee,{size:14,className:"mr-2 mt-0.5 shrink-0 text-foreground opacity-0"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-muted-foreground",children:d("工作树模式")}),e.jsx("span",{className:"mt-0.5 block whitespace-normal text-[11px] leading-snug text-muted-foreground/80",children:We})]})]}),e.jsx("button",{type:"button",onClick:ht,disabled:fe.isPending,className:"flex w-full items-center px-3 py-2 text-left text-xs text-muted-foreground transition-colors hover:bg-accent disabled:cursor-not-allowed disabled:opacity-50",children:fe.isPending?d("检测中..."):d("重新检测 Git 状态")})]})}):e.jsxs("button",{type:"button",onClick:()=>{T(O.WORKTREE),ne(!1)},className:"flex w-full items-center px-3 py-2 text-left text-xs transition-colors hover:bg-accent",children:[e.jsx(ee,{size:14,className:w("mr-2 mt-0.5 shrink-0 text-foreground",X===O.WORKTREE?"opacity-100":"opacity-0")}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:w("block truncate",X===O.WORKTREE?"text-foreground font-medium":"text-muted-foreground"),children:d("工作树模式")}),e.jsx("span",{className:"mt-0.5 block whitespace-normal text-[11px] leading-snug text-muted-foreground/80",children:We})]})]}),e.jsxs("button",{type:"button",onClick:()=>{T(O.MAIN_DIRECTORY),ne(!1)},className:"flex items-start w-full px-3 py-2 text-xs text-left hover:bg-accent transition-colors",children:[e.jsx(ee,{size:14,className:w("mr-2 mt-0.5 shrink-0 text-foreground",X===O.MAIN_DIRECTORY?"opacity-100":"opacity-0")}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:w("block truncate",X===O.MAIN_DIRECTORY?"text-foreground font-medium":"text-muted-foreground"),children:d("本地模式")}),e.jsx("span",{className:"mt-0.5 block whitespace-normal text-[11px] leading-snug text-muted-foreground/80",children:ft})]})]})]})]}),!E&&e.jsx(xs,{value:q,compact:!0,disabled:L,onChange:$}),!E&&e.jsx(Pe,{side:"bottom",className:"ml-auto",content:F?d("Local projects only support local Solo tasks. Initialize Git to use worktrees and TeamRun."):X===O.MAIN_DIRECTORY?d("TeamRun 需要工作树模式。开启团队模式时会自动切换为工作树模式。"):d("启用 TeamRun 后可选择团队模板或成员。"),children:e.jsxs("button",{type:"button",role:"switch","aria-checked":_==="TEAM",onClick:()=>{L||F||(I==="TEAM"?(S("SOLO"),j(!1)):(S("TEAM"),ne(!1),T(O.WORKTREE),j(!0)))},disabled:L||F,className:w("flex items-center gap-2 h-7 pl-2 pr-2 rounded-md text-xs font-medium transition-colors","hover:bg-accent disabled:opacity-40 disabled:cursor-not-allowed","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",_==="TEAM"?"text-foreground/80":"text-muted-foreground"),"aria-label":d("启用团队模式"),children:[e.jsx(At,{size:14,className:_==="TEAM"?"text-foreground/80":"text-muted-foreground"}),e.jsx("span",{children:d("团队模式")}),(F||X===O.MAIN_DIRECTORY)&&_!=="TEAM"?e.jsx(Lt,{size:12,className:"text-muted-foreground/70","aria-hidden":"true"}):null,e.jsx("span",{className:w("relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors",_==="TEAM"?"bg-primary":"bg-border"),children:e.jsx("span",{className:w("inline-block size-3 rounded-full bg-background shadow-sm transition-transform",_==="TEAM"?"translate-x-3.5":"translate-x-0.5")})})]})})]}),H&&!H.available?e.jsx("p",{role:"alert",className:"mt-2 break-words px-2 text-xs leading-snug text-destructive",children:H.reason?d(H.reason):d("Agent executable is unavailable.")}):null,!E&&_==="TEAM"&&m&&e.jsx("div",{className:"mt-2.5 rounded-xl border border-border/60 bg-muted/40 p-3 animate-[fadeInUp_0.25s_cubic-bezier(0.16,1,0.3,1)]",children:e.jsx(gs,{mode:Q,setMode:se,selectedTemplateId:B,setSelectedTemplateId:re,selectedMemberPresetIds:K,setSelectedMemberPresetIds:pe,disabled:L,compact:!0})})]})}export{ln as C,rn as P,tn as R,vs as S,sn as T,os as Z,on as a,Xs as b,an as c,Zs as d,gs as e,en as f,cn as g,ks as h,Os as i,Js as j,xs as k,ts as l,nn as u};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as a,
|
|
1
|
+
import{r as a,_ as j,$ as E,a0 as T,j as s,l as M,u as P,p as I,B as O}from"./index-CWbMMO6g.js";function U(t){const{sessionId:c,onOutput:k,onExit:x,onError:b}=t,[p,g]=a.useState(()=>j.isConnected()),[r,d]=a.useState(!1),m=a.useRef({onOutput:k,onExit:x,onError:b});m.current={onOutput:k,onExit:x,onError:b},a.useEffect(()=>{const n=j.getSocket();g(n.connected);const u=()=>g(!0),v=()=>{g(!1),d(!1)},w=l=>{l.sessionId===c&&m.current.onOutput?.(l.data)},C=l=>{l.sessionId===c&&(d(!1),m.current.onExit?.(l.exitCode))},S=l=>{l.sessionId===c&&m.current.onError?.(l.message)};return n.on("connect",u),n.on("disconnect",v),n.on(E.SESSION_STDOUT,w),n.on(E.SESSION_EXIT,C),n.on(E.SESSION_ERROR,S),g(n.connected),()=>{n.off("connect",u),n.off("disconnect",v),n.off(E.SESSION_STDOUT,w),n.off(E.SESSION_EXIT,C),n.off(E.SESSION_ERROR,S),d(!1)}},[c]);const i=a.useCallback(()=>new Promise(n=>{if(!j.getSocket().connected){n(!1);return}d(!0),n(!0)}),[]),y=a.useCallback(()=>{d(!1)},[]),N=a.useCallback(n=>{j.getSocket().emit(T.INPUT,{sessionId:c,data:n})},[c]),h=a.useCallback((n,u)=>{j.getSocket().emit(T.RESIZE,{sessionId:c,cols:n,rows:u})},[c]);return{isConnected:p,isAttached:r,attach:i,detach:y,sendInput:N,resize:h}}function $({className:t,...c}){return s.jsx("div",{"data-slot":"card",className:M("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",t),...c})}function B(){const{t}=P(),[c,k]=a.useState([]),[x,b]=a.useState(""),[p,g]=a.useState(""),[r,d]=a.useState(null),[m,i]=a.useState([]),[y,N]=a.useState(!1),[h,n]=a.useState(""),u=a.useRef(null),v=a.useCallback(e=>{i(o=>{const f=o[o.length-1];return f&&f.role==="agent"?[...o.slice(0,-1),{...f,content:f.content+e}]:[...o,{role:"agent",content:e,timestamp:new Date}]})},[]),w=a.useCallback(e=>{i(o=>[...o,{role:"agent",content:`
|
|
2
2
|
[${t("Process exited with code {code}",{code:e})}]`,timestamp:new Date}]),d(null)},[t]),C=a.useCallback(e=>{i(o=>[...o,{role:"agent",content:`
|
|
3
3
|
[${t("Error: {message}",{message:e})}]`,timestamp:new Date}])},[t]),{isConnected:S,isAttached:l,attach:D}=U({sessionId:r||"",onOutput:v,onExit:w,onError:C});a.useEffect(()=>{I.get("/demo/agents").then(e=>{k(e.agents);const o=e.agents.find(f=>f.available);o&&b(o.type)})},[]),a.useEffect(()=>{u.current?.scrollIntoView({behavior:"smooth"})},[m]),a.useEffect(()=>{r&&S&&!l&&D()},[r,S,l,D]);const R=async()=>{if(!(!x||!p.trim())){N(!0),i([{role:"user",content:p,timestamp:new Date}]);try{const e=await I.post("/demo/start",{agentType:x,prompt:p.trim()});d(e.sessionId),g("")}catch(e){i(o=>[...o,{role:"agent",content:t("启动失败: {message}",{message:e instanceof Error?e.message:t("未知错误")}),timestamp:new Date}])}finally{N(!1)}}},A=async()=>{if(!r||!h.trim())return;const e=h.trim();i(o=>[...o,{role:"user",content:e,timestamp:new Date}]),n("");try{await I.post(`/demo/${r}/message`,{message:e})}catch(o){i(f=>[...f,{role:"agent",content:t("发送失败: {message}",{message:o instanceof Error?o.message:t("未知错误")}),timestamp:new Date}])}},_=async()=>{if(r)try{await I.post(`/demo/${r}/stop`),i(e=>[...e,{role:"agent",content:`
|
|
4
4
|
[${t("会话已停止")}]`,timestamp:new Date}]),d(null)}catch(e){console.error("Stop failed:",e)}};return s.jsxs("div",{className:"flex flex-col h-full max-w-4xl mx-auto p-4 gap-4",children:[s.jsx("h1",{className:"text-2xl font-bold",children:t("Agent 交互演示")}),!r&&s.jsxs($,{className:"p-4",children:[s.jsx("h2",{className:"text-lg font-semibold mb-3",children:t("选择 Agent")}),s.jsx("div",{className:"flex gap-2 flex-wrap mb-4",children:c.map(e=>s.jsxs(O,{variant:x===e.type?"default":"outline",disabled:!e.available,onClick:()=>b(e.type),children:[e.name,e.available&&e.version&&` (${e.version})`,!e.available&&t(" (不可用)")]},e.type))}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{type:"text",value:p,onChange:e=>g(e.target.value),onKeyDown:e=>e.key==="Enter"&&!e.nativeEvent.isComposing&&e.nativeEvent.keyCode!==229&&R(),placeholder:t("输入你的问题或任务..."),className:"flex-1 px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"}),s.jsx(O,{onClick:R,disabled:y||!x||!p.trim(),children:t(y?"启动中...":"开始")})]})]}),s.jsxs($,{className:"flex-1 p-4 overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex justify-between items-center mb-3",children:[s.jsx("h2",{className:"text-lg font-semibold",children:t("对话")}),r&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-sm text-gray-500",children:t(S?l?"已连接":"连接中...":"未连接")}),s.jsx(O,{variant:"outline",size:"sm",onClick:_,children:t("停止")})]})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto space-y-3",children:[m.length===0?s.jsx("div",{className:"text-gray-400 text-center py-8",children:t("选择 Agent 并输入问题开始对话")}):m.map((e,o)=>s.jsxs("div",{className:`p-3 rounded-lg ${e.role==="user"?"bg-blue-100 ml-8":"bg-gray-100 mr-8"}`,children:[s.jsx("div",{className:"text-xs text-gray-500 mb-1",children:e.role==="user"?t("你"):"Agent"}),s.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:e.content})]},o)),s.jsx("div",{ref:u})]}),r&&s.jsxs("div",{className:"flex gap-2 mt-3 pt-3 border-t",children:[s.jsx("input",{type:"text",value:h,onChange:e=>n(e.target.value),onKeyDown:e=>e.key==="Enter"&&!e.repeat&&!e.nativeEvent.isComposing&&e.nativeEvent.keyCode!==229&&A(),placeholder:t("发送后续消息..."),className:"flex-1 px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"}),s.jsx(O,{onClick:A,disabled:!h.trim(),children:t("发送")})]})]})]})}export{B as DemoPage};
|