@saluzi/saluzi-edu 0.7.13 → 0.7.14
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/cli.js +42 -42
- package/dist/rcs-web/assets/{AdminPanel-DugQ1zJs.js → AdminPanel-D2BlOKin.js} +1 -1
- package/dist/rcs-web/assets/{ArtifactView-rXn5UHd0.js → ArtifactView-CdmY8dgX.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/ArtifactsGallery-DYZ5MTsU.js → dist/rcs-web/assets/ArtifactsGallery-CgNRmnHR.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/Claim-55pIPPu9.js → dist/rcs-web/assets/Claim-5XUBbu1N.js} +1 -1
- package/dist/rcs-web/assets/{Dashboard-CC-Am4QG.js → Dashboard-xYGSv6Lw.js} +1 -1
- package/dist/rcs-web/assets/{Join-Bv_quRru.js → Join-DWpwHKrN.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/Login-CQvhBtmI.js → dist/rcs-web/assets/Login-BECgsaNA.js} +1 -1
- package/dist/rcs-web/assets/{MemoriesGallery-DmhB-a-r.js → MemoriesGallery-CiOmM1Od.js} +1 -1
- package/dist/rcs-web/assets/{Register-CWCr9uhR.js → Register-CZk-qnY0.js} +1 -1
- package/dist/rcs-web/assets/{RegisterEmpty-BxED5Dy8.js → RegisterEmpty-Ch_-rZ4Q.js} +1 -1
- package/dist/rcs-web/assets/{SessionDetail-BtVDoMg8.js → SessionDetail-BvfRSk-I.js} +7 -7
- package/dist/rcs-web/assets/{SessionVisibilityBadge-mclra9a1.js → SessionVisibilityBadge-DgqWVacE.js} +1 -1
- package/dist/rcs-web/assets/{Setup-BOa1QZgo.js → Setup-wM-Ui88_.js} +1 -1
- package/dist/rcs-web/assets/{ShareLanding-DUksxKDO.js → ShareLanding-CFhEbfTb.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/TeamDetail-N4R7QgkK.js → dist/rcs-web/assets/TeamDetail-DGplkbKB.js} +1 -1
- package/dist/rcs-web/assets/{TeamList-Dkroa-DR.js → TeamList-DCkEwOSN.js} +1 -1
- package/dist/rcs-web/assets/{TeamSettings-sH6k3cBB.js → TeamSettings--GVPCr2u.js} +1 -1
- package/dist/rcs-web/assets/{UserSearchInput-B8gKPGEK.js → UserSearchInput-BL-q5UjI.js} +1 -1
- package/dist/rcs-web/assets/{UserSettings-Cnr-Z5oi.js → UserSettings-Dzu7_2NW.js} +1 -1
- package/dist/rcs-web/assets/{arc-BaScP50H.js → arc-CweLs86f.js} +1 -1
- package/dist/rcs-web/assets/{architectureDiagram-3BPJPVTR-LpUmudjN.js → architectureDiagram-3BPJPVTR-CBnaew3X.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/blockDiagram-GPEHLZMM-BahEW4lQ.js → dist/rcs-web/assets/blockDiagram-GPEHLZMM-B10LIxoE.js} +1 -1
- package/dist/rcs-web/assets/{c4Diagram-AAUBKEIU-NNZbDHKK.js → c4Diagram-AAUBKEIU-D2FPFw7D.js} +1 -1
- package/dist/rcs-web/assets/channel-xCO2xzDo.js +1 -0
- package/dist/rcs-web/assets/{chunk-2J33WTMH-69YYeEie.js → chunk-2J33WTMH-DuAZ1hhX.js} +1 -1
- package/dist/rcs-web/assets/{chunk-4BX2VUAB-CoMWvtbi.js → chunk-4BX2VUAB-2hDcfMbF.js} +1 -1
- package/dist/rcs-web/assets/{chunk-55IACEB6-BhdS00Z_.js → chunk-55IACEB6-yptbXrVo.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/chunk-727SXJPM-B-X0tTCc.js → dist/rcs-web/assets/chunk-727SXJPM-CqZXI5V6.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/chunk-AQP2D5EJ-uNpZ8YVO.js → dist/rcs-web/assets/chunk-AQP2D5EJ-jQSgh8tv.js} +1 -1
- package/dist/rcs-web/assets/{chunk-FMBD7UC4-INF2n4DE.js → chunk-FMBD7UC4-CXmKLoz9.js} +1 -1
- package/dist/rcs-web/assets/{chunk-ND2GUHAM-CGoZKqoJ.js → chunk-ND2GUHAM-DcwJgQ1I.js} +1 -1
- package/dist/rcs-web/assets/{chunk-QZHKN3VN-B0_Eodir.js → chunk-QZHKN3VN-D5Egk7l_.js} +1 -1
- package/dist/rcs-web/assets/classDiagram-4FO5ZUOK-Bw1hKsvW.js +1 -0
- package/dist/rcs-web/assets/classDiagram-v2-Q7XG4LA2-Bw1hKsvW.js +1 -0
- package/dist/rcs-web/assets/{code-block-IT6T5CEO-Dqe2MgFE.js → code-block-IT6T5CEO-DlEre8T_.js} +1 -1
- package/dist/rcs-web/assets/{copy-BM16nNhl.js → copy-CLvdPjzw.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/cose-bilkent-S5V4N54A-CnkedUmD.js → dist/rcs-web/assets/cose-bilkent-S5V4N54A-ChTQbRce.js} +1 -1
- package/dist/rcs-web/assets/{dagre-BM42HDAG-C3C2M9Dc.js → dagre-BM42HDAG-C-YbVNb3.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/diagram-2AECGRRQ-ESFaqWFA.js → dist/rcs-web/assets/diagram-2AECGRRQ-DLCij6AY.js} +1 -1
- package/dist/rcs-web/assets/{diagram-5GNKFQAL-18y3Di-Z.js → diagram-5GNKFQAL-BwKzkGdR.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/diagram-KO2AKTUF-HRfgxVLi.js → dist/rcs-web/assets/diagram-KO2AKTUF-BlG8s5sr.js} +1 -1
- package/dist/rcs-web/assets/{diagram-LMA3HP47-BGXS1MbV.js → diagram-LMA3HP47-C_d-MmaZ.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/diagram-OG6HWLK6-mTYLV8qh.js → dist/rcs-web/assets/diagram-OG6HWLK6-DpNm_iwR.js} +1 -1
- package/dist/rcs-web/assets/{dialog-BY4fOXc_.js → dialog-NQ-AVx58.js} +1 -1
- package/dist/rcs-web/assets/{erDiagram-TEJ5UH35-DS5hbsJs.js → erDiagram-TEJ5UH35-BMKjCngx.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/flowDiagram-I6XJVG4X-CZdy8yJc.js → dist/rcs-web/assets/flowDiagram-I6XJVG4X-A17iEmxC.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/ganttDiagram-6RSMTGT7-DSBnE024.js → dist/rcs-web/assets/ganttDiagram-6RSMTGT7-B5OlRo5d.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/gitGraphDiagram-PVQCEYII-SPF9bGwd.js → dist/rcs-web/assets/gitGraphDiagram-PVQCEYII-CB2mZRLs.js} +1 -1
- package/dist/rcs-web/assets/{infoDiagram-5YYISTIA-BHH_W4WL.js → infoDiagram-5YYISTIA-CfXW8MRE.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/ishikawaDiagram-YF4QCWOH-Dk_V2DBo.js → dist/rcs-web/assets/ishikawaDiagram-YF4QCWOH-BhjcnpdC.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/journeyDiagram-JHISSGLW-D9V0wEAf.js → dist/rcs-web/assets/journeyDiagram-JHISSGLW-CApDn6x-.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/kanban-definition-UN3LZRKU-CsqaKKO9.js → dist/rcs-web/assets/kanban-definition-UN3LZRKU-Chx7pPDw.js} +1 -1
- package/dist/rcs-web/assets/{linear-B41O4W2v.js → linear-B-1to2hH.js} +1 -1
- package/dist/rcs-web/assets/{main-BEcUh0F7.js → main-BS9Lw_5N.js} +4 -4
- package/dist/rcs-web/assets/main-CK63KDX7.css +1 -0
- package/{packages/remote-control-server/web/dist/assets/mermaid-VLURNSYL-C1VVhmLq.js → dist/rcs-web/assets/mermaid-VLURNSYL-vwkADU0l.js} +4 -4
- package/dist/rcs-web/assets/{mermaid.core-DQfCv5Cg.js → mermaid.core-B7Vlk3kK.js} +5 -5
- package/dist/rcs-web/assets/{mindmap-definition-RKZ34NQL-BD1xoQCh.js → mindmap-definition-RKZ34NQL-8NONPI2a.js} +1 -1
- package/dist/rcs-web/assets/{notifications-BPvB-uGE.js → notifications-DhCswD0D.js} +1 -1
- package/dist/rcs-web/assets/{pieDiagram-4H26LBE5-C9VTG-uO.js → pieDiagram-4H26LBE5-Bfmy32wf.js} +1 -1
- package/dist/rcs-web/assets/{quadrantDiagram-W4KKPZXB-CcdAz31R.js → quadrantDiagram-W4KKPZXB-Du5i8g4M.js} +1 -1
- package/dist/rcs-web/assets/{refresh-cw-D-EyhwSL.js → refresh-cw-BRyy1vY7.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/requirementDiagram-4Y6WPE33-56ONxGl0.js → dist/rcs-web/assets/requirementDiagram-4Y6WPE33-Ciny9AX3.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/sankeyDiagram-5OEKKPKP-ECkEyAfb.js → dist/rcs-web/assets/sankeyDiagram-5OEKKPKP-sLE95Cwh.js} +1 -1
- package/dist/rcs-web/assets/{sequenceDiagram-3UESZ5HK-C_31JcIA.js → sequenceDiagram-3UESZ5HK-CQZ9uU8-.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/stateDiagram-AJRCARHV-BCCWavRG.js → dist/rcs-web/assets/stateDiagram-AJRCARHV-uc20eqzV.js} +1 -1
- package/dist/rcs-web/assets/{stateDiagram-v2-BHNVJYJU-CErSQlCd.js → stateDiagram-v2-BHNVJYJU-hihiN4tK.js} +1 -1
- package/dist/rcs-web/assets/{timeline-definition-PNZ67QCA-Bq1dpAT8.js → timeline-definition-PNZ67QCA-lae7py1I.js} +1 -1
- package/dist/rcs-web/assets/{vennDiagram-CIIHVFJN-C0gZpyFU.js → vennDiagram-CIIHVFJN-BWfzq5yI.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/wardleyDiagram-YWT4CUSO-qPrWLnjV.js → dist/rcs-web/assets/wardleyDiagram-YWT4CUSO-BpaZ1YMv.js} +1 -1
- package/dist/rcs-web/assets/{workerType-CWB4ZW61.js → workerType-Csz9RRnt.js} +1 -1
- package/dist/rcs-web/assets/{xychartDiagram-2RQKCTM6-p83OQUAm.js → xychartDiagram-2RQKCTM6-BzVPD5x9.js} +1 -1
- package/dist/rcs-web/index.html +3 -3
- package/package.json +1 -1
- package/packages/remote-control-server/web/dist/assets/{AdminPanel-DugQ1zJs.js → AdminPanel-D2BlOKin.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{ArtifactView-rXn5UHd0.js → ArtifactView-CdmY8dgX.js} +1 -1
- package/{dist/rcs-web/assets/ArtifactsGallery-DYZ5MTsU.js → packages/remote-control-server/web/dist/assets/ArtifactsGallery-CgNRmnHR.js} +1 -1
- package/{dist/rcs-web/assets/Claim-55pIPPu9.js → packages/remote-control-server/web/dist/assets/Claim-5XUBbu1N.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{Dashboard-CC-Am4QG.js → Dashboard-xYGSv6Lw.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{Join-Bv_quRru.js → Join-DWpwHKrN.js} +1 -1
- package/{dist/rcs-web/assets/Login-CQvhBtmI.js → packages/remote-control-server/web/dist/assets/Login-BECgsaNA.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{MemoriesGallery-DmhB-a-r.js → MemoriesGallery-CiOmM1Od.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{Register-CWCr9uhR.js → Register-CZk-qnY0.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{RegisterEmpty-BxED5Dy8.js → RegisterEmpty-Ch_-rZ4Q.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{SessionDetail-BtVDoMg8.js → SessionDetail-BvfRSk-I.js} +7 -7
- package/packages/remote-control-server/web/dist/assets/{SessionVisibilityBadge-mclra9a1.js → SessionVisibilityBadge-DgqWVacE.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{Setup-BOa1QZgo.js → Setup-wM-Ui88_.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{ShareLanding-DUksxKDO.js → ShareLanding-CFhEbfTb.js} +1 -1
- package/{dist/rcs-web/assets/TeamDetail-N4R7QgkK.js → packages/remote-control-server/web/dist/assets/TeamDetail-DGplkbKB.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{TeamList-Dkroa-DR.js → TeamList-DCkEwOSN.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{TeamSettings-sH6k3cBB.js → TeamSettings--GVPCr2u.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{UserSearchInput-B8gKPGEK.js → UserSearchInput-BL-q5UjI.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{UserSettings-Cnr-Z5oi.js → UserSettings-Dzu7_2NW.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{arc-BaScP50H.js → arc-CweLs86f.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{architectureDiagram-3BPJPVTR-LpUmudjN.js → architectureDiagram-3BPJPVTR-CBnaew3X.js} +1 -1
- package/{dist/rcs-web/assets/blockDiagram-GPEHLZMM-BahEW4lQ.js → packages/remote-control-server/web/dist/assets/blockDiagram-GPEHLZMM-B10LIxoE.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{c4Diagram-AAUBKEIU-NNZbDHKK.js → c4Diagram-AAUBKEIU-D2FPFw7D.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/channel-xCO2xzDo.js +1 -0
- package/packages/remote-control-server/web/dist/assets/{chunk-2J33WTMH-69YYeEie.js → chunk-2J33WTMH-DuAZ1hhX.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-4BX2VUAB-CoMWvtbi.js → chunk-4BX2VUAB-2hDcfMbF.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-55IACEB6-BhdS00Z_.js → chunk-55IACEB6-yptbXrVo.js} +1 -1
- package/{dist/rcs-web/assets/chunk-727SXJPM-B-X0tTCc.js → packages/remote-control-server/web/dist/assets/chunk-727SXJPM-CqZXI5V6.js} +1 -1
- package/{dist/rcs-web/assets/chunk-AQP2D5EJ-uNpZ8YVO.js → packages/remote-control-server/web/dist/assets/chunk-AQP2D5EJ-jQSgh8tv.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-FMBD7UC4-INF2n4DE.js → chunk-FMBD7UC4-CXmKLoz9.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-ND2GUHAM-CGoZKqoJ.js → chunk-ND2GUHAM-DcwJgQ1I.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-QZHKN3VN-B0_Eodir.js → chunk-QZHKN3VN-D5Egk7l_.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/classDiagram-4FO5ZUOK-Bw1hKsvW.js +1 -0
- package/packages/remote-control-server/web/dist/assets/classDiagram-v2-Q7XG4LA2-Bw1hKsvW.js +1 -0
- package/packages/remote-control-server/web/dist/assets/{code-block-IT6T5CEO-Dqe2MgFE.js → code-block-IT6T5CEO-DlEre8T_.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{copy-BM16nNhl.js → copy-CLvdPjzw.js} +1 -1
- package/{dist/rcs-web/assets/cose-bilkent-S5V4N54A-CnkedUmD.js → packages/remote-control-server/web/dist/assets/cose-bilkent-S5V4N54A-ChTQbRce.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{dagre-BM42HDAG-C3C2M9Dc.js → dagre-BM42HDAG-C-YbVNb3.js} +1 -1
- package/{dist/rcs-web/assets/diagram-2AECGRRQ-ESFaqWFA.js → packages/remote-control-server/web/dist/assets/diagram-2AECGRRQ-DLCij6AY.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{diagram-5GNKFQAL-18y3Di-Z.js → diagram-5GNKFQAL-BwKzkGdR.js} +1 -1
- package/{dist/rcs-web/assets/diagram-KO2AKTUF-HRfgxVLi.js → packages/remote-control-server/web/dist/assets/diagram-KO2AKTUF-BlG8s5sr.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{diagram-LMA3HP47-BGXS1MbV.js → diagram-LMA3HP47-C_d-MmaZ.js} +1 -1
- package/{dist/rcs-web/assets/diagram-OG6HWLK6-mTYLV8qh.js → packages/remote-control-server/web/dist/assets/diagram-OG6HWLK6-DpNm_iwR.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{dialog-BY4fOXc_.js → dialog-NQ-AVx58.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{erDiagram-TEJ5UH35-DS5hbsJs.js → erDiagram-TEJ5UH35-BMKjCngx.js} +1 -1
- package/{dist/rcs-web/assets/flowDiagram-I6XJVG4X-CZdy8yJc.js → packages/remote-control-server/web/dist/assets/flowDiagram-I6XJVG4X-A17iEmxC.js} +1 -1
- package/{dist/rcs-web/assets/ganttDiagram-6RSMTGT7-DSBnE024.js → packages/remote-control-server/web/dist/assets/ganttDiagram-6RSMTGT7-B5OlRo5d.js} +1 -1
- package/{dist/rcs-web/assets/gitGraphDiagram-PVQCEYII-SPF9bGwd.js → packages/remote-control-server/web/dist/assets/gitGraphDiagram-PVQCEYII-CB2mZRLs.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{infoDiagram-5YYISTIA-BHH_W4WL.js → infoDiagram-5YYISTIA-CfXW8MRE.js} +1 -1
- package/{dist/rcs-web/assets/ishikawaDiagram-YF4QCWOH-Dk_V2DBo.js → packages/remote-control-server/web/dist/assets/ishikawaDiagram-YF4QCWOH-BhjcnpdC.js} +1 -1
- package/{dist/rcs-web/assets/journeyDiagram-JHISSGLW-D9V0wEAf.js → packages/remote-control-server/web/dist/assets/journeyDiagram-JHISSGLW-CApDn6x-.js} +1 -1
- package/{dist/rcs-web/assets/kanban-definition-UN3LZRKU-CsqaKKO9.js → packages/remote-control-server/web/dist/assets/kanban-definition-UN3LZRKU-Chx7pPDw.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{linear-B41O4W2v.js → linear-B-1to2hH.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{main-BEcUh0F7.js → main-BS9Lw_5N.js} +4 -4
- package/packages/remote-control-server/web/dist/assets/main-CK63KDX7.css +1 -0
- package/{dist/rcs-web/assets/mermaid-VLURNSYL-C1VVhmLq.js → packages/remote-control-server/web/dist/assets/mermaid-VLURNSYL-vwkADU0l.js} +4 -4
- package/packages/remote-control-server/web/dist/assets/{mermaid.core-DQfCv5Cg.js → mermaid.core-B7Vlk3kK.js} +5 -5
- package/packages/remote-control-server/web/dist/assets/{mindmap-definition-RKZ34NQL-BD1xoQCh.js → mindmap-definition-RKZ34NQL-8NONPI2a.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{notifications-BPvB-uGE.js → notifications-DhCswD0D.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{pieDiagram-4H26LBE5-C9VTG-uO.js → pieDiagram-4H26LBE5-Bfmy32wf.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{quadrantDiagram-W4KKPZXB-CcdAz31R.js → quadrantDiagram-W4KKPZXB-Du5i8g4M.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{refresh-cw-D-EyhwSL.js → refresh-cw-BRyy1vY7.js} +1 -1
- package/{dist/rcs-web/assets/requirementDiagram-4Y6WPE33-56ONxGl0.js → packages/remote-control-server/web/dist/assets/requirementDiagram-4Y6WPE33-Ciny9AX3.js} +1 -1
- package/{dist/rcs-web/assets/sankeyDiagram-5OEKKPKP-ECkEyAfb.js → packages/remote-control-server/web/dist/assets/sankeyDiagram-5OEKKPKP-sLE95Cwh.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{sequenceDiagram-3UESZ5HK-C_31JcIA.js → sequenceDiagram-3UESZ5HK-CQZ9uU8-.js} +1 -1
- package/{dist/rcs-web/assets/stateDiagram-AJRCARHV-BCCWavRG.js → packages/remote-control-server/web/dist/assets/stateDiagram-AJRCARHV-uc20eqzV.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{stateDiagram-v2-BHNVJYJU-CErSQlCd.js → stateDiagram-v2-BHNVJYJU-hihiN4tK.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{timeline-definition-PNZ67QCA-Bq1dpAT8.js → timeline-definition-PNZ67QCA-lae7py1I.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{vennDiagram-CIIHVFJN-C0gZpyFU.js → vennDiagram-CIIHVFJN-BWfzq5yI.js} +1 -1
- package/{dist/rcs-web/assets/wardleyDiagram-YWT4CUSO-qPrWLnjV.js → packages/remote-control-server/web/dist/assets/wardleyDiagram-YWT4CUSO-BpaZ1YMv.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{workerType-CWB4ZW61.js → workerType-Csz9RRnt.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{xychartDiagram-2RQKCTM6-p83OQUAm.js → xychartDiagram-2RQKCTM6-BzVPD5x9.js} +1 -1
- package/packages/remote-control-server/web/dist/index.html +3 -3
- package/dist/rcs-web/assets/channel-S5Y2JIsm.js +0 -1
- package/dist/rcs-web/assets/classDiagram-4FO5ZUOK-BftkaBF6.js +0 -1
- package/dist/rcs-web/assets/classDiagram-v2-Q7XG4LA2-BftkaBF6.js +0 -1
- package/dist/rcs-web/assets/main-B7U6M5cC.css +0 -1
- package/packages/remote-control-server/web/dist/assets/channel-S5Y2JIsm.js +0 -1
- package/packages/remote-control-server/web/dist/assets/classDiagram-4FO5ZUOK-BftkaBF6.js +0 -1
- package/packages/remote-control-server/web/dist/assets/classDiagram-v2-Q7XG4LA2-BftkaBF6.js +0 -1
- package/packages/remote-control-server/web/dist/assets/main-B7U6M5cC.css +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var En=Object.defineProperty;var Mn=(r,t,s)=>t in r?En(r,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[t]=s;var q=(r,t,s)=>Mn(r,typeof t!="symbol"?t+"":t,s);import{j as e,e as l}from"./vendor-DE_-CLIE.js";import{aF as J,ai as Rn,aN as ls,aM as cs,aT as i,aP as An,aO as
|
|
1
|
+
var En=Object.defineProperty;var Mn=(r,t,s)=>t in r?En(r,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[t]=s;var q=(r,t,s)=>Mn(r,typeof t!="symbol"?t+"":t,s);import{j as e,e as l}from"./vendor-DE_-CLIE.js";import{aF as J,ai as Rn,aN as ls,aM as cs,aT as i,aP as An,aO as pt,aU as H,aK as ve,ax as $n,aw as ee,al as In,at as Dn,aY as qn,a$ as ae,T as Pn,Q as On,X as Hs,L as Ge,H as Fn,I as Un,i as ds,aJ as Ws,N as Qs,aG as ft,e as qe,S as ht,M as Kn,y as Ln,aH as te,aD as he,aI as Bn,aV as Hn,G as Wn,D as Qn,aW as us,am as Vn,a2 as Yn,as as zn,ae as Vs,ad as Gn,ab as Jn,au as Xn,ap as Zn,P as ms,t as er,B as qt,V as tr,ac as xs,$ as sr,an as nr,a4 as rr,aB as ar,A as or,aL as ir,aQ as lr,aR as cr,Z as ps,a1 as dr,aX as ur,b as mr,a6 as fs,aq as xr,K as Ys,F as pr,d as fr,C as hr,ah as hs,l as yr,a as gr,u as Je,w as Xe,E as br,g as Ze,f as et,v as tt,s as jr}from"./main-BS9Lw_5N.js";import{A as wr,g as ys}from"./workerType-Csz9RRnt.js";import{D as ke,a as Ne,c as Pe,d as Se,b as vr}from"./dialog-NQ-AVx58.js";import{R as kr}from"./refresh-cw-BRyy1vY7.js";import{A as Nr,U as Sr}from"./UserSearchInput-BL-q5UjI.js";import{C as _r}from"./copy-CLvdPjzw.js";import{E as Cr,S as Tr,A as Er}from"./ArtifactsGallery-CgNRmnHR.js";import{S as Mr}from"./SessionVisibilityBadge-DgqWVacE.js";import{MemoriesGallery as Rr}from"./MemoriesGallery-CiOmM1Od.js";import{S as Ar,b as $r}from"./notifications-DhCswD0D.js";import"./preload-helper-BiaRt2Oj.js";import"./motion-BILbV7YQ.js";/**
|
|
2
2
|
* @license lucide-react v0.555.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const
|
|
6
|
+
*/const Ir=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],zs=J("chevron-right",Ir);/**
|
|
7
7
|
* @license lucide-react v0.555.0 - ISC
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
@@ -73,11 +73,11 @@ var En=Object.defineProperty;var Mn=(r,t,s)=>t in r?En(r,t,{enumerable:!0,config
|
|
|
73
73
|
*
|
|
74
74
|
* This source code is licensed under the ISC license.
|
|
75
75
|
* See the LICENSE file in the root directory of this source tree.
|
|
76
|
-
*/const na=[["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:"m9 12 2 2 4-4",key:"dzmm74"}]],ra=J("shield-check",na);function It(){return{tasks:{}}}const bs=3e4;function mt(r){const t=r.trim();if(!t)return"agent";const s=t.split(/\s+/).slice(0,2).join(" ");return s.length>40?s.slice(0,40)+"…":s}function js(r,t){var c,u,p,h,g,b,S,M,C,j,x,y;const s=t.subtype;if(s!=="task_started"&&s!=="task_progress"&&s!=="task_notification")return r;const n=t.task_id;if(!n)return r;const a=Date.now(),d=r.tasks[n];if(s==="task_started"){if(d)return{tasks:{...r.tasks,[n]:{...d,description:t.description??d.description,name:mt(t.description??d.description),taskType:t.task_type??d.taskType,workflowName:t.workflow_name??d.workflowName,prompt:t.prompt??d.prompt,toolUseId:t.tool_use_id??d.toolUseId,status:"running",startTime:a,evictAfter:void 0}}};const k=t.description??"";return{tasks:{...r.tasks,[n]:{taskId:n,name:mt(k),description:k,taskType:t.task_type,workflowName:t.workflow_name,prompt:t.prompt,toolUseId:t.tool_use_id,status:"running",startTime:a}}}}if(s==="task_progress"){if(!d){const k=t.description??"";return{tasks:{...r.tasks,[n]:{taskId:n,name:mt(k),description:k,toolUseId:t.tool_use_id,status:"running",startTime:a,tokenCount:(c=t.usage)==null?void 0:c.total_tokens,toolUseCount:(u=t.usage)==null?void 0:u.tool_uses,durationMs:(p=t.usage)==null?void 0:p.duration_ms,lastToolName:t.last_tool_name,summary:t.summary}}}}return{tasks:{...r.tasks,[n]:{...d,description:t.description??d.description,tokenCount:((h=t.usage)==null?void 0:h.total_tokens)??d.tokenCount,toolUseCount:((g=t.usage)==null?void 0:g.tool_uses)??d.toolUseCount,durationMs:((b=t.usage)==null?void 0:b.duration_ms)??d.durationMs,lastToolName:t.last_tool_name??d.lastToolName,summary:t.summary??d.summary}}}}return d?{tasks:{...r.tasks,[n]:{...d,status:t.status??"completed",endTime:a,finalSummary:t.summary??d.finalSummary,outputFile:t.output_file??d.outputFile,tokenCount:((j=t.usage)==null?void 0:j.total_tokens)??d.tokenCount,toolUseCount:((x=t.usage)==null?void 0:x.tool_uses)??d.toolUseCount,durationMs:((y=t.usage)==null?void 0:y.duration_ms)??d.durationMs,evictAfter:a+bs}}}:{tasks:{...r.tasks,[n]:{taskId:n,name:mt(t.summary??""),description:t.summary??"",status:t.status??"completed",startTime:a,endTime:a,finalSummary:t.summary,outputFile:t.output_file,tokenCount:(S=t.usage)==null?void 0:S.total_tokens,toolUseCount:(M=t.usage)==null?void 0:M.tool_uses,durationMs:(C=t.usage)==null?void 0:C.duration_ms,evictAfter:a+bs}}}}function en(r,t=Date.now()){return Object.values(r.tasks).filter(s=>s.evictAfter===void 0||s.evictAfter>t).sort((s,n)=>s.startTime-n.startTime)}const ws={in_process_teammate:0,local_bash:1,monitor_mcp:2,remote_agent:3,local_agent:4,dream:5},vs=100;function aa(r){const t=new Map;for(const s of r){const n=s.taskType??"",a=t.get(n);a?a.push(s):t.set(n,[s])}return[...t.entries()].sort(([s],[n])=>{const a=ws[s]??vs,d=ws[n]??vs;return a===d?s.localeCompare(n):a-d}).map(([s,n])=>({taskType:s,tasks:[...n].sort((a,d)=>a.startTime-d.startTime)}))}function ks(r){const t=r.raw,s=t&&typeof t=="object"?t:r,n=typeof s.subtype=="string"?s.subtype:void 0;return n!=="task_started"&&n!=="task_progress"&&n!=="task_notification"?null:{subtype:n,task_id:typeof s.task_id=="string"?s.task_id:void 0,tool_use_id:typeof s.tool_use_id=="string"?s.tool_use_id:void 0,description:typeof s.description=="string"?s.description:void 0,task_type:typeof s.task_type=="string"?s.task_type:void 0,workflow_name:typeof s.workflow_name=="string"?s.workflow_name:void 0,prompt:typeof s.prompt=="string"?s.prompt:void 0,usage:s.usage&&typeof s.usage=="object"?s.usage:void 0,last_tool_name:typeof s.last_tool_name=="string"?s.last_tool_name:void 0,summary:typeof s.summary=="string"?s.summary:void 0,status:s.status==="completed"||s.status==="failed"||s.status==="stopped"?s.status:void 0,output_file:typeof s.output_file=="string"?s.output_file:void 0}}function oa(r){if(!r||typeof r!="object"||Array.isArray(r))return null;const t=r,s={file_search:t.file_search===!0,clear:t.clear===!0,set_max_thinking_tokens:t.set_max_thinking_tokens===!0,get_context_usage:t.get_context_usage===!0,stop_task:t.stop_task===!0,set_model:t.set_model===!0,set_permission_mode:t.set_permission_mode===!0,interrupt:t.interrupt===!0,end_session:t.end_session===!0,mcp_management:t.mcp_management===!0,remote_settings:t.remote_settings===!0,rewind:t.rewind===!0,resume:t.resume===!0,set_effort:t.set_effort===!0,set_token_mode:t.set_token_mode===!0,side_question:t.side_question===!0};return Object.values(s).some(Boolean)?s:null}function Ns(r,t){const s=[];if(Array.isArray(r)){for(const n of r){if(!n||typeof n!="object")continue;const a=n;if(typeof a.name!="string"||!a.name)continue;const d=a.type==="prompt"||a.type==="local"||a.type==="local-jsx"?a.type:void 0;s.push({name:a.name,...typeof a.description=="string"&&a.description?{description:a.description}:{},...typeof a.argumentHint=="string"&&a.argumentHint?{argumentHint:a.argumentHint}:{},...d?{type:d}:{}})}if(s.length>0)return s}if(Array.isArray(t))for(const n of t)typeof n=="string"&&n&&s.push({name:n});return s}function Ss(r){const t=r.raw&&typeof r.raw=="object"&&!Array.isArray(r.raw)?r.raw:r,s=Ns(t.slash_command_details??r.slash_command_details,t.slash_commands??r.slash_commands),n=Ns(t.skill_details??r.skill_details,t.skills??r.skills),a=oa(t.remote_capabilities??r.remote_capabilities);return s.length===0&&n.length===0&&!a?null:{commands:s,skills:n,capabilities:a}}class ia{constructor(t){q(this,"listeners",new Set);q(this,"stateListeners",new Set);q(this,"eventSource",null);q(this,"sessionId",null);q(this,"_lastSeqNum",0);q(this,"lastFrameAt",0);q(this,"firstEventAfterOpen",!1);q(this,"watchdogTimer",null);q(this,"visibilityHandler",null);q(this,"reconnectTimer",null);q(this,"reconnectAttempts",0);q(this,"_state","idle");q(this,"opts");this.opts={stallThresholdMs:45e3,watchdogTickMs:5e3,reconnectBaseDelayMs:1e3,reconnectMaxDelayMs:15e3,maxReconnectAttempts:6,...t}}get state(){return this._state}onEvent(t){return this.listeners.add(t),()=>this.listeners.delete(t)}onStateChange(t){return this.stateListeners.add(t),()=>this.stateListeners.delete(t)}connect(t){this.stopReconnectTimer(),this.reconnectAttempts=0,this.sessionId=t,this.openStream()}openStream(){if(this.closeStream(),!this.sessionId)return;this.setState("connecting");const t=this._lastSeqNum>0?`/web/sessions/${this.sessionId}/events?fromSeqNum=${this._lastSeqNum}`:`/web/sessions/${this.sessionId}/events`,s=new EventSource(t,{withCredentials:!0});this.eventSource=s,this.lastFrameAt=Date.now(),this.firstEventAfterOpen=!0,s.addEventListener("open",()=>{this.lastFrameAt=Date.now(),this.reconnectAttempts=0,this.firstEventAfterOpen=!0,this.setState("open")}),s.addEventListener("ping",()=>{this.lastFrameAt=Date.now()}),s.addEventListener("message",n=>{this.lastFrameAt=Date.now();try{const a=JSON.parse(n.data);if(this.firstEventAfterOpen&&(this.firstEventAfterOpen=!1,typeof a.seqNum=="number"&&a.seqNum<this._lastSeqNum&&(this._lastSeqNum=a.seqNum-1,this.notifyResync())),a.seqNum!==void 0&&a.seqNum<=this._lastSeqNum)return;a.seqNum!==void 0&&(this._lastSeqNum=a.seqNum);for(const d of this.listeners)d(a)}catch{}}),s.addEventListener("error",()=>{s.readyState===EventSource.CLOSED&&this.scheduleReconnect()}),this.startWatchdog()}disconnect(){this.sessionId=null,this.stopReconnectTimer(),this.closeStream(),this._lastSeqNum=0,this.reconnectAttempts=0,this.setState("idle")}closeStream(){this.stopWatchdog(),this.eventSource&&(this.eventSource.close(),this.eventSource=null)}startWatchdog(){this.stopWatchdog(),this.watchdogTimer=setInterval(()=>{this.probeStall()},this.opts.watchdogTickMs),typeof document<"u"&&(this.visibilityHandler=()=>{document.visibilityState==="visible"&&this.probeStall()},document.addEventListener("visibilitychange",this.visibilityHandler))}probeStall(){const t=this.eventSource;!t||t.readyState!==EventSource.OPEN||Date.now()-this.lastFrameAt<=this.opts.stallThresholdMs||this.scheduleReconnect()}stopWatchdog(){this.watchdogTimer&&(clearInterval(this.watchdogTimer),this.watchdogTimer=null),this.visibilityHandler&&(typeof document<"u"&&document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null)}stopReconnectTimer(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}scheduleReconnect(){if(this.reconnectTimer||!this.sessionId)return;if(this.closeStream(),this.reconnectAttempts++,this.reconnectAttempts>this.opts.maxReconnectAttempts){this.setState("failed");return}this.setState("reconnecting");const t=Math.min(this.opts.reconnectBaseDelayMs*2**(this.reconnectAttempts-1),this.opts.reconnectMaxDelayMs),s=Math.max(0,t+t*.25*(2*Math.random()-1));this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnect()},s)}async reconnect(){this.sessionId&&(await qn(),this.sessionId&&this.openStream())}setState(t){if(this._state!==t){this._state=t;for(const s of this.stateListeners)s(t,{})}}notifyResync(){for(const t of this.stateListeners)t(this._state,{resync:!0})}}const fe=new ia;function Mt(r){if(typeof r.content=="string")return r.content;if(r.message&&typeof r.message=="object"){const t=r.message;if(typeof t.content=="string")return t.content;if(Array.isArray(t.content))return t.content.filter(s=>s.type==="text"&&typeof s.text=="string").map(s=>s.text).join("")}return""}function _s(r,t){for(let s=r.length-1;s>=0;s--){const n=r[s];if(n&&n.type==="tool_call"&&n.toolCall.id===t)return s}return-1}const Rt="streaming-";function Cs(r){const t=r.message;if(!t||typeof t!="object"||!Array.isArray(t.content))return"";const s=[];for(const n of t.content)if((n==null?void 0:n.type)==="thinking"){const a=typeof n.thinking=="string"&&n.thinking||typeof n.text=="string"&&n.text||"";a&&s.push(a)}return s.join("")}function Ts(r){return r.filter(t=>typeof t.subject=="string"&&t.subject).map(t=>({content:t.subject,priority:"medium",status:t.status==="completed"?"completed":t.status==="in_progress"?"in_progress":"pending"}))}function Es(r){if(!r||typeof r!="object")return"";const t=r;if(typeof t.target_event_id=="string"&&t.target_event_id)return t.target_event_id;const s=t.raw;if(s&&typeof s=="object"&&!Array.isArray(s)){const n=s.target_event_id;if(typeof n=="string"&&n)return n}return""}class la{constructor(t,s,n){q(this,"sessionId");q(this,"setEntries");q(this,"unsub",null);q(this,"unsubState",null);q(this,"onStatusChange");q(this,"onError");q(this,"onPermissionRequest");q(this,"onModelsStateChange");q(this,"onSubagentUpdate");q(this,"onControlResponse");q(this,"onPermissionModeChange");q(this,"onUsageChange");q(this,"onElicitationRequest");q(this,"onWorkerInfoChange");q(this,"onTurnStart");q(this,"subagentState",It());q(this,"seenUuids",new Set);q(this,"seenToolCallIds",new Set);q(this,"pendingToolCallIds",new Set);q(this,"pendingPermissionToolIds",new Map);q(this,"postedUserUuids",new Set);q(this,"pendingControlRequests",new Map);q(this,"turnEnded",!1);q(this,"userSinceTurnEnd",!1);q(this,"turnStartedAt",null);q(this,"closed",!1);this.sessionId=t,this.setEntries=s,this.onStatusChange=n==null?void 0:n.onStatusChange,this.onError=n==null?void 0:n.onError,this.onPermissionRequest=n==null?void 0:n.onPermissionRequest,this.onModelsStateChange=n==null?void 0:n.onModelsStateChange,this.onSubagentUpdate=n==null?void 0:n.onSubagentUpdate,this.onControlResponse=n==null?void 0:n.onControlResponse,this.onPermissionModeChange=n==null?void 0:n.onPermissionModeChange,this.onUsageChange=n==null?void 0:n.onUsageChange,this.onElicitationRequest=n==null?void 0:n.onElicitationRequest,this.onWorkerInfoChange=n==null?void 0:n.onWorkerInfoChange,this.onTurnStart=n==null?void 0:n.onTurnStart}markClosed(){this.closed=!0}setTurnStartedAt(t){var s;this.turnStartedAt!==t&&(this.turnStartedAt=t,(s=this.onTurnStart)==null||s.call(this,t))}async init(){await this.loadHistory(),this.connectSSE()}async loadHistory(){var j,x,y,k,_,A,T;const{events:t}=await Rn(this.sessionId);if(!t||t.length===0)return;const s=new Set;for(const w of t){if(w.type!=="user"||w.direction==="inbound")continue;const E=(j=w.payload)==null?void 0:j.uuid;typeof E=="string"&&E&&s.add(E)}const n=[];let a=null;const d=()=>{a&&(n.push(a),a=null)};for(const w of t){const E=w.payload||{},I=E.uuid;if(typeof I=="string"&&I&&this.seenUuids.add(I),w.type==="tool_use"){const $=E.tool_call_id;typeof $=="string"&&$&&this.seenToolCallIds.add($)}if(w.type==="user"){if(w.direction==="inbound"){const v=E.uuid;if(typeof v!="string"||!v||s.has(v))continue}d();const $=Mt(E);$&&n.push({type:"user_message",id:w.id||`hist-user-${n.length}`,content:$})}else if(w.type==="assistant"){d();const $=Mt(E);if(ls($))continue;const v=Cs(E),F=[],P=E.message;if(P&&typeof P=="object"&&Array.isArray(P.content)){for(const G of P.content)if(G.type==="tool_use"){const X=G.id;X&&this.seenToolCallIds.add(X),F.push({type:"tool_call",toolCall:{id:X||`hist-tool-${n.length}`,title:G.name||"tool",status:"complete",rawInput:G.input||{}}})}}if($||v||F.length>0){a={type:"assistant_message",id:w.id||`hist-asst-${n.length}`,chunks:[...v?[{type:"thought",text:v}]:[],...$?[{type:"message",text:$}]:[]]},n.push(a);for(const G of F)n.push(G);a=null}}else if(w.type==="conversation_rewound"){const $=Es(E);if($){const v=n.findIndex(F=>cs(F)===$);v>=0&&(n.length=v)}}else if(w.type==="tool_use"){const $=E,v={type:"tool_call",toolCall:{id:$.tool_call_id||`hist-tool-${n.length}`,title:$.tool_name||"tool",status:"complete",rawInput:$.tool_input||{}}};n.push(v)}else if(w.type==="tool_result"){const $=E,v=_s(n,$.tool_call_id||"");if(v>=0){const F=n[v];n[v]={type:"tool_call",toolCall:{...F.toolCall,rawOutput:{output:$.content||$.output||""}}}}}}d();let c=null;for(const w of t){if(w.type!=="task_state")continue;const E=w.payload||{};Array.isArray(E.tasks)&&(c=E.tasks)}if(c&&c.length>0){const w=Ts(c);w.length>0&&n.push({type:"plan",id:`plan-hist-${Date.now()}`,entries:w})}this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries(n);let u=null,p=null,h=null,g=null,b=0,S=0;for(const w of t){const E=w.payload||{};if(typeof w.createdAt=="number"&&(w.createdAt>S&&(S=w.createdAt),w.type==="user"&&g!=="user"&&w.createdAt>0&&(b=w.createdAt)),w.type==="user"?g="user":(w.type==="result"||w.type==="result_success"||w.type==="interrupt")&&(g="turn_end"),w.type==="system"&&(E.subtype==="init"||((x=E.raw)==null?void 0:x.subtype)==="init")&&(p=Ss(E)),w.type==="models_state"){const I=E.raw,$=I&&typeof I=="object"?I.models_state:E.models_state;$&&Array.isArray($.availableModels)&&typeof $.currentModelId=="string"&&(u=$)}else if(w.type==="result"||w.type==="result_success"){const I=E.usage,$=typeof E.total_cost_usd=="number"?E.total_cost_usd:null;(I||$!==null)&&(h={inputTokens:((I==null?void 0:I.input_tokens)??0)+((I==null?void 0:I.cache_read_input_tokens)??0)+((I==null?void 0:I.cache_creation_input_tokens)??0),outputTokens:(I==null?void 0:I.output_tokens)??0,totalCostUsd:$})}}let M=!1,C=It();for(const w of t){if(w.type!=="system")continue;const E=ks(w.payload||{});E&&(C=js(C,E),M=!0)}M&&(this.subagentState=C,(y=this.onSubagentUpdate)==null||y.call(this,this.subagentState)),u&&((k=this.onModelsStateChange)==null||k.call(this,u)),p&&((_=this.onWorkerInfoChange)==null||_.call(this,p)),h&&((A=this.onUsageChange)==null||A.call(this,h)),this.turnEnded=g==="turn_end",this.userSinceTurnEnd=g==="user",this.setTurnStartedAt(!this.closed&&g==="user"&&b>0&&S>=b?Date.now()-(S-b):null),this.turnEnded&&!this.closed&&((T=this.onStatusChange)==null||T.call(this,"idle"))}connectSSE(){fe.connect(this.sessionId),this.unsub=fe.onEvent(t=>this.handleEvent(t)),this.unsubState=fe.onStateChange((t,s)=>{s.resync&&!this.closed&&this.loadHistory().catch(()=>{})})}disconnect(){this.unsub&&(this.unsub(),this.unsub=null),this.unsubState&&(this.unsubState(),this.unsubState=null),fe.disconnect()}handleEvent(t){var a,d,c,u,p,h,g,b,S,M,C,j;const s=t.type,n=t.payload||{};switch(s){case"user":{if(this.applyEmbeddedToolResults(n),this.userSinceTurnEnd=!0,!this.closed&&this.turnStartedAt===null&&this.setTurnStartedAt(Date.now()),t.direction==="inbound"){const x=n.uuid;if(typeof x!="string"||!x||this.postedUserUuids.has(x)||this.seenUuids.has(x))break;this.seenUuids.add(x);const y=Mt(n);y&&this.setEntries(k=>[...k,{type:"user_message",id:t.id||`user-${Date.now()}`,content:y}])}break}case"assistant":{const x=n.uuid;if(typeof x=="string"&&x){if(this.seenUuids.has(x))break;this.seenUuids.add(x)}const y=typeof n.content=="string"?n.content:"";if(ls(y))break;const k=Cs(n);this.setEntries(A=>{const T=A[A.length-1];if((T==null?void 0:T.type)==="assistant_message"&&T.id.startsWith(Rt))return[...A.slice(0,-1),{...T,id:`assistant-${Date.now()}`,chunks:[...k?[{type:"thought",text:k}]:[],{type:"message",text:y}]}];if((T==null?void 0:T.type)==="assistant_message"){const w=T.chunks[T.chunks.length-1];return(w==null?void 0:w.type)==="message"?[...A.slice(0,-1),{...T,chunks:[...T.chunks.slice(0,-1),{type:"message",text:w.text+y}]}]:[...A.slice(0,-1),{...T,chunks:[...T.chunks,{type:"message",text:y}]}]}if(y&&y.trim()||k){const w={type:"assistant_message",id:`assistant-${Date.now()}`,chunks:[...k?[{type:"thought",text:k}]:[],...y?[{type:"message",text:y}]:[]]};return[...A,w]}return A});const _=n.message;if(_&&typeof _=="object"&&Array.isArray(_.content)){const A=_.content.filter(T=>T.type==="tool_use");for(const T of A){const w=T.id||`call-${Date.now()}-${Math.random().toString(16).slice(2,8)}`;if(this.seenToolCallIds.has(w))continue;this.seenToolCallIds.add(w),this.pendingToolCallIds.add(w);const E={id:w,title:T.name||"tool",status:"running",rawInput:T.input||{}};this.setEntries(I=>[...I,{type:"tool_call",toolCall:E}])}}break}case"tool_use":{const x=n,y=x.tool_call_id||`call-${Date.now()}`;if(this.seenToolCallIds.has(y))break;this.seenToolCallIds.add(y),this.pendingToolCallIds.add(y);const k={id:y,title:x.tool_name||"tool",status:"running",rawInput:x.tool_input||{}};this.setEntries(_=>[..._,{type:"tool_call",toolCall:k}]);break}case"tool_result":{const x=n;this.applyToolResult(x.tool_call_id||"",x.content??x.output);break}case"interrupt":{this.finalizePendingToolCalls("canceled"),this.turnEnded=!0,this.userSinceTurnEnd=!1,this.setTurnStartedAt(null),this.closed||(a=this.onStatusChange)==null||a.call(this,"idle");break}case"control_request":case"permission_request":{const x=n.request;if(x&&x.subtype==="can_use_tool"){const y=n.request_id||"",k=x.tool_name||"unknown",_=x.input||x.tool_input||{},A=x.description||"",T=Array.isArray(x.permission_suggestions)?x.permission_suggestions:[];this.setEntries(w=>{const E=[...w].reverse().findIndex(I=>I.type==="tool_call");if(E>=0){const I=w.length-1-E,$=w[I];if($.toolCall.status==="running")return this.pendingPermissionToolIds.set(y,$.toolCall.id),w.map((v,F)=>F===I?{type:"tool_call",toolCall:{...$.toolCall,status:"waiting_for_confirmation",permissionRequest:{requestId:y,options:[]}}}:v)}return w}),(d=this.onPermissionRequest)==null||d.call(this,{requestId:y,toolName:k,toolInput:_,description:A,suggestions:T})}else x&&x.subtype==="elicitation"&&((c=this.onElicitationRequest)==null||c.call(this,{requestId:n.request_id||"",serverName:x.mcp_server_name||"",message:x.message||"",mode:x.mode==="url"?"url":"form",url:typeof x.url=="string"?x.url:void 0,requestedSchema:x.requested_schema||void 0}));break}case"conversation_rewound":{const x=Es(n);x&&(this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries(y=>{const k=y.findIndex(_=>cs(_)===x);return k===-1?y:y.slice(0,k)}));break}case"session_status":{if(An(n)){this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries([]);break}if(typeof n.status=="string"){if(ft(n.status))this.closed=!0,this.finalizePendingToolCalls("canceled");else if(this.closed)break;if(n.status==="running"&&this.turnEnded&&!this.userSinceTurnEnd)break;(u=this.onStatusChange)==null||u.call(this,n.status)}break}case"error":{const x=String(n.message||n.content||"Unknown error");(p=this.onError)==null||p.call(this,x);break}case"models_state":{const x=n.raw,y=typeof x=="object"&&x!==null?x.models_state:n.models_state;y&&Array.isArray(y.availableModels)&&typeof y.currentModelId=="string"&&((h=this.onModelsStateChange)==null||h.call(this,y));break}case"system":{const x=n.raw,y=x&&typeof x=="object"?x:n,k=typeof y.subtype=="string"?y.subtype:void 0,_=ks(n);_&&(this.subagentState=js(this.subagentState,_),(g=this.onSubagentUpdate)==null||g.call(this,this.subagentState));const A=typeof y.permissionMode=="string"?y.permissionMode:typeof n.permissionMode=="string"?n.permissionMode:null;if(A&&((b=this.onPermissionModeChange)==null||b.call(this,A)),k==="init"){const T=Ss(n);T&&((S=this.onWorkerInfoChange)==null||S.call(this,T))}break}case"control_response":{const x=n.response;if(x&&typeof x=="object"){const y=typeof x.request_id=="string"?x.request_id:"",k=typeof x.subtype=="string"?x.subtype:"";if(y){(M=this.onControlResponse)==null||M.call(this,{subtype:k,requestId:y,error:typeof x.error=="string"?x.error:void 0});const _=this.pendingControlRequests.get(y);_&&(this.pendingControlRequests.delete(y),_({data:k==="success"&&x.response&&typeof x.response=="object"?x.response:null,...k==="error"&&typeof x.error=="string"?{error:x.error}:{}}))}}break}case"stream_event":{const x=n.event;if(!x||typeof x.type!="string")break;if(x.type==="content_block_delta"){const y=x.delta;if(!y||typeof y.type!="string")break;const k=y.type==="text_delta"?"message":y.type==="thinking_delta"?"thought":null;if(!k)break;const _=y.text??y.thinking;if(typeof _!="string"||!_)break;this.appendStreamingDelta(k,_)}break}case"partial_assistant":{const x=typeof n.content=="string"?n.content:"";x&&this.appendStreamingDelta("message",x);break}case"result":case"result_success":{this.turnEnded=!0,this.userSinceTurnEnd=!1,this.setTurnStartedAt(null),this.finalizePendingToolCalls(n.is_error?"canceled":"complete"),this.closed||(C=this.onStatusChange)==null||C.call(this,"idle");const x=n.usage,y=typeof n.total_cost_usd=="number"?n.total_cost_usd:null;if(x||y!==null){const w=((x==null?void 0:x.input_tokens)??0)+((x==null?void 0:x.cache_read_input_tokens)??0)+((x==null?void 0:x.cache_creation_input_tokens)??0);(j=this.onUsageChange)==null||j.call(this,{inputTokens:w,outputTokens:(x==null?void 0:x.output_tokens)??0,totalCostUsd:y})}const k=typeof n.subtype=="string"?n.subtype:"",_=n.raw&&typeof n.raw=="object"?n.raw:void 0,T=(typeof n.result=="string"?n.result:typeof(_==null?void 0:_.result)=="string"?_.result:"").trim();k.startsWith("error_")&&T&&this.setEntries(w=>[...w,{type:"command_output",id:`exit-error-${typeof n.uuid=="string"?n.uuid:Date.now()}`,commandName:"worker",inputText:"",title:i("adapter.workerCrashed"),outputText:T,variant:"error"}]);break}case"task_state":{const x=Array.isArray(n.tasks)?n.tasks:[];if(x.length===0)break;const y=Ts(x);if(y.length===0)break;this.setEntries(k=>[...k.filter(A=>A.type!=="plan"),{type:"plan",id:`plan-${n.task_list_id||Date.now()}`,entries:y}]);break}}}applyEmbeddedToolResults(t){const s=t.message;if(!(!s||typeof s!="object"||!Array.isArray(s.content)))for(const n of s.content)!n||n.type!=="tool_result"||this.applyToolResult(n.tool_use_id||"",n.content??n.output)}applyToolResult(t,s){t&&(this.pendingToolCallIds.delete(t),this.setEntries(n=>{const a=_s(n,t);if(a<0)return n;const d=n[a];return d.toolCall.status!=="running"&&d.toolCall.status!=="waiting_for_confirmation"?n:n.map((c,u)=>u===a?{type:"tool_call",toolCall:{...d.toolCall,status:"complete",permissionRequest:void 0,rawOutput:{output:s||""}}}:c)}))}finalizePendingToolCalls(t){if(this.pendingToolCallIds.size===0)return;const s=this.pendingToolCallIds;this.pendingToolCallIds=new Set,this.setEntries(n=>n.map(a=>a.type!=="tool_call"||!s.has(a.toolCall.id)?a:{type:"tool_call",toolCall:{...a.toolCall,status:t,permissionRequest:void 0}}))}appendStreamingDelta(t,s){this.setEntries(n=>{const a=n[n.length-1];if((a==null?void 0:a.type)==="assistant_message"&&a.id.startsWith(Rt)){const c=a.chunks[a.chunks.length-1];return(c==null?void 0:c.type)===t?[...n.slice(0,-1),{...a,chunks:[...a.chunks.slice(0,-1),{type:t,text:c.text+s}]}]:[...n.slice(0,-1),{...a,chunks:[...a.chunks,{type:t,text:s}]}]}const d={type:"assistant_message",id:`${Rt}${Date.now()}`,chunks:[{type:t,text:s}]};return[...n,d]})}async sendMessage(t,s,n){var h;const a=s&&s.length>0,d=n&&n.length>0;if(!t.trim()&&!a&&!d)return;const c={type:"user_message",id:`user-${Date.now()}`,content:t,images:a?s:void 0,attachments:d?n:void 0};this.setEntries(g=>[...g,c]);const u=[];if(t&&u.push({type:"text",text:t}),a)for(const g of s)u.push({type:"image",source:{type:"base64",media_type:g.mimeType,data:g.data}});if(d){for(const g of n)if(g.kind==="text"||g.kind==="table"){const b=`📎 ${g.name}${g.size!=null?` (${ca(g.size)})`:""}`,S=g.textContent||i("attach.emptyFile");u.push({type:"text",text:`${b}
|
|
76
|
+
*/const na=[["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:"m9 12 2 2 4-4",key:"dzmm74"}]],ra=J("shield-check",na);function It(){return{tasks:{}}}const gs=3e4;function ut(r){const t=r.trim();if(!t)return"agent";const s=t.split(/\s+/).slice(0,2).join(" ");return s.length>40?s.slice(0,40)+"…":s}function bs(r,t){var c,u,p,h,g,b,S,M,C,j,x,y;const s=t.subtype;if(s!=="task_started"&&s!=="task_progress"&&s!=="task_notification")return r;const n=t.task_id;if(!n)return r;const a=Date.now(),d=r.tasks[n];if(s==="task_started"){if(d)return{tasks:{...r.tasks,[n]:{...d,description:t.description??d.description,name:ut(t.description??d.description),taskType:t.task_type??d.taskType,workflowName:t.workflow_name??d.workflowName,prompt:t.prompt??d.prompt,toolUseId:t.tool_use_id??d.toolUseId,status:"running",startTime:a,evictAfter:void 0}}};const k=t.description??"";return{tasks:{...r.tasks,[n]:{taskId:n,name:ut(k),description:k,taskType:t.task_type,workflowName:t.workflow_name,prompt:t.prompt,toolUseId:t.tool_use_id,status:"running",startTime:a}}}}if(s==="task_progress"){if(!d){const k=t.description??"";return{tasks:{...r.tasks,[n]:{taskId:n,name:ut(k),description:k,toolUseId:t.tool_use_id,status:"running",startTime:a,tokenCount:(c=t.usage)==null?void 0:c.total_tokens,toolUseCount:(u=t.usage)==null?void 0:u.tool_uses,durationMs:(p=t.usage)==null?void 0:p.duration_ms,lastToolName:t.last_tool_name,summary:t.summary}}}}return{tasks:{...r.tasks,[n]:{...d,description:t.description??d.description,tokenCount:((h=t.usage)==null?void 0:h.total_tokens)??d.tokenCount,toolUseCount:((g=t.usage)==null?void 0:g.tool_uses)??d.toolUseCount,durationMs:((b=t.usage)==null?void 0:b.duration_ms)??d.durationMs,lastToolName:t.last_tool_name??d.lastToolName,summary:t.summary??d.summary}}}}return d?{tasks:{...r.tasks,[n]:{...d,status:t.status??"completed",endTime:a,finalSummary:t.summary??d.finalSummary,outputFile:t.output_file??d.outputFile,tokenCount:((j=t.usage)==null?void 0:j.total_tokens)??d.tokenCount,toolUseCount:((x=t.usage)==null?void 0:x.tool_uses)??d.toolUseCount,durationMs:((y=t.usage)==null?void 0:y.duration_ms)??d.durationMs,evictAfter:a+gs}}}:{tasks:{...r.tasks,[n]:{taskId:n,name:ut(t.summary??""),description:t.summary??"",status:t.status??"completed",startTime:a,endTime:a,finalSummary:t.summary,outputFile:t.output_file,tokenCount:(S=t.usage)==null?void 0:S.total_tokens,toolUseCount:(M=t.usage)==null?void 0:M.tool_uses,durationMs:(C=t.usage)==null?void 0:C.duration_ms,evictAfter:a+gs}}}}function en(r,t=Date.now()){return Object.values(r.tasks).filter(s=>s.evictAfter===void 0||s.evictAfter>t).sort((s,n)=>s.startTime-n.startTime)}const js={in_process_teammate:0,local_bash:1,monitor_mcp:2,remote_agent:3,local_agent:4,dream:5},ws=100;function aa(r){const t=new Map;for(const s of r){const n=s.taskType??"",a=t.get(n);a?a.push(s):t.set(n,[s])}return[...t.entries()].sort(([s],[n])=>{const a=js[s]??ws,d=js[n]??ws;return a===d?s.localeCompare(n):a-d}).map(([s,n])=>({taskType:s,tasks:[...n].sort((a,d)=>a.startTime-d.startTime)}))}function vs(r){const t=r.raw,s=t&&typeof t=="object"?t:r,n=typeof s.subtype=="string"?s.subtype:void 0;return n!=="task_started"&&n!=="task_progress"&&n!=="task_notification"?null:{subtype:n,task_id:typeof s.task_id=="string"?s.task_id:void 0,tool_use_id:typeof s.tool_use_id=="string"?s.tool_use_id:void 0,description:typeof s.description=="string"?s.description:void 0,task_type:typeof s.task_type=="string"?s.task_type:void 0,workflow_name:typeof s.workflow_name=="string"?s.workflow_name:void 0,prompt:typeof s.prompt=="string"?s.prompt:void 0,usage:s.usage&&typeof s.usage=="object"?s.usage:void 0,last_tool_name:typeof s.last_tool_name=="string"?s.last_tool_name:void 0,summary:typeof s.summary=="string"?s.summary:void 0,status:s.status==="completed"||s.status==="failed"||s.status==="stopped"?s.status:void 0,output_file:typeof s.output_file=="string"?s.output_file:void 0}}function oa(r){if(!r||typeof r!="object"||Array.isArray(r))return null;const t=r,s={file_search:t.file_search===!0,clear:t.clear===!0,set_max_thinking_tokens:t.set_max_thinking_tokens===!0,get_context_usage:t.get_context_usage===!0,stop_task:t.stop_task===!0,set_model:t.set_model===!0,set_permission_mode:t.set_permission_mode===!0,interrupt:t.interrupt===!0,end_session:t.end_session===!0,mcp_management:t.mcp_management===!0,remote_settings:t.remote_settings===!0,rewind:t.rewind===!0,resume:t.resume===!0,set_effort:t.set_effort===!0,set_token_mode:t.set_token_mode===!0,side_question:t.side_question===!0};return Object.values(s).some(Boolean)?s:null}function ks(r,t){const s=[];if(Array.isArray(r)){for(const n of r){if(!n||typeof n!="object")continue;const a=n;if(typeof a.name!="string"||!a.name)continue;const d=a.type==="prompt"||a.type==="local"||a.type==="local-jsx"?a.type:void 0;s.push({name:a.name,...typeof a.description=="string"&&a.description?{description:a.description}:{},...typeof a.argumentHint=="string"&&a.argumentHint?{argumentHint:a.argumentHint}:{},...d?{type:d}:{}})}if(s.length>0)return s}if(Array.isArray(t))for(const n of t)typeof n=="string"&&n&&s.push({name:n});return s}function Ns(r){const t=r.raw&&typeof r.raw=="object"&&!Array.isArray(r.raw)?r.raw:r,s=ks(t.slash_command_details??r.slash_command_details,t.slash_commands??r.slash_commands),n=ks(t.skill_details??r.skill_details,t.skills??r.skills),a=oa(t.remote_capabilities??r.remote_capabilities);return s.length===0&&n.length===0&&!a?null:{commands:s,skills:n,capabilities:a}}class ia{constructor(t){q(this,"listeners",new Set);q(this,"stateListeners",new Set);q(this,"eventSource",null);q(this,"sessionId",null);q(this,"_lastSeqNum",0);q(this,"lastFrameAt",0);q(this,"firstEventAfterOpen",!1);q(this,"watchdogTimer",null);q(this,"visibilityHandler",null);q(this,"reconnectTimer",null);q(this,"reconnectAttempts",0);q(this,"_state","idle");q(this,"opts");this.opts={stallThresholdMs:45e3,watchdogTickMs:5e3,reconnectBaseDelayMs:1e3,reconnectMaxDelayMs:15e3,maxReconnectAttempts:6,...t}}get state(){return this._state}onEvent(t){return this.listeners.add(t),()=>this.listeners.delete(t)}onStateChange(t){return this.stateListeners.add(t),()=>this.stateListeners.delete(t)}connect(t){this.stopReconnectTimer(),this.reconnectAttempts=0,this.sessionId=t,this.openStream()}openStream(){if(this.closeStream(),!this.sessionId)return;this.setState("connecting");const t=this._lastSeqNum>0?`/web/sessions/${this.sessionId}/events?fromSeqNum=${this._lastSeqNum}`:`/web/sessions/${this.sessionId}/events`,s=new EventSource(t,{withCredentials:!0});this.eventSource=s,this.lastFrameAt=Date.now(),this.firstEventAfterOpen=!0,s.addEventListener("open",()=>{this.lastFrameAt=Date.now(),this.reconnectAttempts=0,this.firstEventAfterOpen=!0,this.setState("open")}),s.addEventListener("ping",()=>{this.lastFrameAt=Date.now()}),s.addEventListener("message",n=>{this.lastFrameAt=Date.now();try{const a=JSON.parse(n.data);if(this.firstEventAfterOpen&&(this.firstEventAfterOpen=!1,typeof a.seqNum=="number"&&a.seqNum<this._lastSeqNum&&(this._lastSeqNum=a.seqNum-1,this.notifyResync())),a.seqNum!==void 0&&a.seqNum<=this._lastSeqNum)return;a.seqNum!==void 0&&(this._lastSeqNum=a.seqNum);for(const d of this.listeners)d(a)}catch{}}),s.addEventListener("error",()=>{s.readyState===EventSource.CLOSED&&this.scheduleReconnect()}),this.startWatchdog()}disconnect(){this.sessionId=null,this.stopReconnectTimer(),this.closeStream(),this._lastSeqNum=0,this.reconnectAttempts=0,this.setState("idle")}closeStream(){this.stopWatchdog(),this.eventSource&&(this.eventSource.close(),this.eventSource=null)}startWatchdog(){this.stopWatchdog(),this.watchdogTimer=setInterval(()=>{this.probeStall()},this.opts.watchdogTickMs),typeof document<"u"&&(this.visibilityHandler=()=>{document.visibilityState==="visible"&&this.probeStall()},document.addEventListener("visibilitychange",this.visibilityHandler))}probeStall(){const t=this.eventSource;!t||t.readyState!==EventSource.OPEN||Date.now()-this.lastFrameAt<=this.opts.stallThresholdMs||this.scheduleReconnect()}stopWatchdog(){this.watchdogTimer&&(clearInterval(this.watchdogTimer),this.watchdogTimer=null),this.visibilityHandler&&(typeof document<"u"&&document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null)}stopReconnectTimer(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}scheduleReconnect(){if(this.reconnectTimer||!this.sessionId)return;if(this.closeStream(),this.reconnectAttempts++,this.reconnectAttempts>this.opts.maxReconnectAttempts){this.setState("failed");return}this.setState("reconnecting");const t=Math.min(this.opts.reconnectBaseDelayMs*2**(this.reconnectAttempts-1),this.opts.reconnectMaxDelayMs),s=Math.max(0,t+t*.25*(2*Math.random()-1));this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnect()},s)}async reconnect(){this.sessionId&&(await qn(),this.sessionId&&this.openStream())}setState(t){if(this._state!==t){this._state=t;for(const s of this.stateListeners)s(t,{})}}notifyResync(){for(const t of this.stateListeners)t(this._state,{resync:!0})}}const fe=new ia;function Rt(r){if(typeof r.content=="string")return r.content;if(r.message&&typeof r.message=="object"){const t=r.message;if(typeof t.content=="string")return t.content;if(Array.isArray(t.content))return t.content.filter(s=>s.type==="text"&&typeof s.text=="string").map(s=>s.text).join("")}return""}function Ss(r,t){for(let s=r.length-1;s>=0;s--){const n=r[s];if(n&&n.type==="tool_call"&&n.toolCall.id===t)return s}return-1}const At="streaming-";function _s(r){const t=r.message;if(!t||typeof t!="object"||!Array.isArray(t.content))return"";const s=[];for(const n of t.content)if((n==null?void 0:n.type)==="thinking"){const a=typeof n.thinking=="string"&&n.thinking||typeof n.text=="string"&&n.text||"";a&&s.push(a)}return s.join("")}function Cs(r){return r.filter(t=>typeof t.subject=="string"&&t.subject).map(t=>({content:t.subject,priority:"medium",status:t.status==="completed"?"completed":t.status==="in_progress"?"in_progress":"pending"}))}function Ts(r){if(!r||typeof r!="object")return"";const t=r;if(typeof t.target_event_id=="string"&&t.target_event_id)return t.target_event_id;const s=t.raw;if(s&&typeof s=="object"&&!Array.isArray(s)){const n=s.target_event_id;if(typeof n=="string"&&n)return n}return""}class la{constructor(t,s,n){q(this,"sessionId");q(this,"setEntries");q(this,"unsub",null);q(this,"unsubState",null);q(this,"onStatusChange");q(this,"onError");q(this,"onPermissionRequest");q(this,"onModelsStateChange");q(this,"onSubagentUpdate");q(this,"onControlResponse");q(this,"onPermissionModeChange");q(this,"onUsageChange");q(this,"onElicitationRequest");q(this,"onWorkerInfoChange");q(this,"onTurnStart");q(this,"subagentState",It());q(this,"seenUuids",new Set);q(this,"seenToolCallIds",new Set);q(this,"pendingToolCallIds",new Set);q(this,"pendingPermissionToolIds",new Map);q(this,"postedUserUuids",new Set);q(this,"pendingControlRequests",new Map);q(this,"turnEnded",!1);q(this,"userSinceTurnEnd",!1);q(this,"turnStartedAt",null);q(this,"closed",!1);this.sessionId=t,this.setEntries=s,this.onStatusChange=n==null?void 0:n.onStatusChange,this.onError=n==null?void 0:n.onError,this.onPermissionRequest=n==null?void 0:n.onPermissionRequest,this.onModelsStateChange=n==null?void 0:n.onModelsStateChange,this.onSubagentUpdate=n==null?void 0:n.onSubagentUpdate,this.onControlResponse=n==null?void 0:n.onControlResponse,this.onPermissionModeChange=n==null?void 0:n.onPermissionModeChange,this.onUsageChange=n==null?void 0:n.onUsageChange,this.onElicitationRequest=n==null?void 0:n.onElicitationRequest,this.onWorkerInfoChange=n==null?void 0:n.onWorkerInfoChange,this.onTurnStart=n==null?void 0:n.onTurnStart}markClosed(){this.closed=!0}setTurnStartedAt(t){var s;this.turnStartedAt!==t&&(this.turnStartedAt=t,(s=this.onTurnStart)==null||s.call(this,t))}async init(){await this.loadHistory(),this.connectSSE()}async loadHistory(){var j,x,y,k,_,A,T;const{events:t}=await Rn(this.sessionId);if(!t||t.length===0)return;const s=new Set;for(const w of t){if(w.type!=="user"||w.direction==="inbound")continue;const E=(j=w.payload)==null?void 0:j.uuid;typeof E=="string"&&E&&s.add(E)}const n=[];let a=null;const d=()=>{a&&(n.push(a),a=null)};for(const w of t){const E=w.payload||{},$=E.uuid;if(typeof $=="string"&&$&&this.seenUuids.add($),w.type==="tool_use"){const I=E.tool_call_id;typeof I=="string"&&I&&this.seenToolCallIds.add(I)}if(w.type==="user"){if(w.direction==="inbound"){const v=E.uuid;if(typeof v!="string"||!v||s.has(v))continue}d();const I=Rt(E);I&&n.push({type:"user_message",id:w.id||`hist-user-${n.length}`,content:I})}else if(w.type==="assistant"){d();const I=Rt(E);if(ls(I))continue;const v=_s(E),F=[],P=E.message;if(P&&typeof P=="object"&&Array.isArray(P.content)){for(const G of P.content)if(G.type==="tool_use"){const X=G.id;X&&this.seenToolCallIds.add(X),F.push({type:"tool_call",toolCall:{id:X||`hist-tool-${n.length}`,title:G.name||"tool",status:"complete",rawInput:G.input||{}}})}}if(I||v||F.length>0){a={type:"assistant_message",id:w.id||`hist-asst-${n.length}`,chunks:[...v?[{type:"thought",text:v}]:[],...I?[{type:"message",text:I}]:[]]},n.push(a);for(const G of F)n.push(G);a=null}}else if(w.type==="conversation_rewound"){const I=Ts(E);if(I){const v=n.findIndex(F=>cs(F)===I);v>=0&&(n.length=v)}}else if(w.type==="tool_use"){const I=E,v={type:"tool_call",toolCall:{id:I.tool_call_id||`hist-tool-${n.length}`,title:I.tool_name||"tool",status:"complete",rawInput:I.tool_input||{}}};n.push(v)}else if(w.type==="tool_result"){const I=E,v=Ss(n,I.tool_call_id||"");if(v>=0){const F=n[v];n[v]={type:"tool_call",toolCall:{...F.toolCall,rawOutput:{output:I.content||I.output||""}}}}}}d();let c=null;for(const w of t){if(w.type!=="task_state")continue;const E=w.payload||{};Array.isArray(E.tasks)&&(c=E.tasks)}if(c&&c.length>0){const w=Cs(c);w.length>0&&n.push({type:"plan",id:`plan-hist-${Date.now()}`,entries:w})}this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries(n);let u=null,p=null,h=null,g=null,b=0,S=0;for(const w of t){const E=w.payload||{};if(typeof w.createdAt=="number"&&(w.createdAt>S&&(S=w.createdAt),w.type==="user"&&g!=="user"&&w.createdAt>0&&(b=w.createdAt)),w.type==="user"?g="user":(w.type==="result"||w.type==="result_success"||w.type==="interrupt")&&(g="turn_end"),w.type==="system"&&(E.subtype==="init"||((x=E.raw)==null?void 0:x.subtype)==="init")&&(p=Ns(E)),w.type==="models_state"){const $=E.raw,I=$&&typeof $=="object"?$.models_state:E.models_state;I&&Array.isArray(I.availableModels)&&typeof I.currentModelId=="string"&&(u=I)}else if(w.type==="result"||w.type==="result_success"){const $=E.usage,I=typeof E.total_cost_usd=="number"?E.total_cost_usd:null;($||I!==null)&&(h={inputTokens:(($==null?void 0:$.input_tokens)??0)+(($==null?void 0:$.cache_read_input_tokens)??0)+(($==null?void 0:$.cache_creation_input_tokens)??0),outputTokens:($==null?void 0:$.output_tokens)??0,totalCostUsd:I})}}let M=!1,C=It();for(const w of t){if(w.type!=="system")continue;const E=vs(w.payload||{});E&&(C=bs(C,E),M=!0)}M&&(this.subagentState=C,(y=this.onSubagentUpdate)==null||y.call(this,this.subagentState)),u&&((k=this.onModelsStateChange)==null||k.call(this,u)),p&&((_=this.onWorkerInfoChange)==null||_.call(this,p)),h&&((A=this.onUsageChange)==null||A.call(this,h)),this.turnEnded=g==="turn_end",this.userSinceTurnEnd=g==="user",this.setTurnStartedAt(!this.closed&&g==="user"&&b>0&&S>=b?Date.now()-(S-b):null),this.turnEnded&&!this.closed&&((T=this.onStatusChange)==null||T.call(this,"idle"))}connectSSE(){fe.connect(this.sessionId),this.unsub=fe.onEvent(t=>this.handleEvent(t)),this.unsubState=fe.onStateChange((t,s)=>{s.resync&&!this.closed&&this.loadHistory().catch(()=>{})})}disconnect(){this.unsub&&(this.unsub(),this.unsub=null),this.unsubState&&(this.unsubState(),this.unsubState=null),fe.disconnect()}handleEvent(t){var a,d,c,u,p,h,g,b,S,M,C,j;const s=t.type,n=t.payload||{};switch(s){case"user":{if(this.applyEmbeddedToolResults(n),this.userSinceTurnEnd=!0,!this.closed&&this.turnStartedAt===null&&this.setTurnStartedAt(Date.now()),t.direction==="inbound"){const x=n.uuid;if(typeof x!="string"||!x||this.postedUserUuids.has(x)||this.seenUuids.has(x))break;this.seenUuids.add(x);const y=Rt(n);y&&this.setEntries(k=>[...k,{type:"user_message",id:t.id||`user-${Date.now()}`,content:y}])}break}case"assistant":{const x=n.uuid;if(typeof x=="string"&&x){if(this.seenUuids.has(x))break;this.seenUuids.add(x)}const y=typeof n.content=="string"?n.content:"";if(ls(y))break;const k=_s(n);this.setEntries(A=>{const T=A[A.length-1];if((T==null?void 0:T.type)==="assistant_message"&&T.id.startsWith(At))return[...A.slice(0,-1),{...T,id:`assistant-${Date.now()}`,chunks:[...k?[{type:"thought",text:k}]:[],{type:"message",text:y}]}];if((T==null?void 0:T.type)==="assistant_message"){const w=T.chunks[T.chunks.length-1];return(w==null?void 0:w.type)==="message"?[...A.slice(0,-1),{...T,chunks:[...T.chunks.slice(0,-1),{type:"message",text:w.text+y}]}]:[...A.slice(0,-1),{...T,chunks:[...T.chunks,{type:"message",text:y}]}]}if(y&&y.trim()||k){const w={type:"assistant_message",id:`assistant-${Date.now()}`,chunks:[...k?[{type:"thought",text:k}]:[],...y?[{type:"message",text:y}]:[]]};return[...A,w]}return A});const _=n.message;if(_&&typeof _=="object"&&Array.isArray(_.content)){const A=_.content.filter(T=>T.type==="tool_use");for(const T of A){const w=T.id||`call-${Date.now()}-${Math.random().toString(16).slice(2,8)}`;if(this.seenToolCallIds.has(w))continue;this.seenToolCallIds.add(w),this.pendingToolCallIds.add(w);const E={id:w,title:T.name||"tool",status:"running",rawInput:T.input||{}};this.setEntries($=>[...$,{type:"tool_call",toolCall:E}])}}break}case"tool_use":{const x=n,y=x.tool_call_id||`call-${Date.now()}`;if(this.seenToolCallIds.has(y))break;this.seenToolCallIds.add(y),this.pendingToolCallIds.add(y);const k={id:y,title:x.tool_name||"tool",status:"running",rawInput:x.tool_input||{}};this.setEntries(_=>[..._,{type:"tool_call",toolCall:k}]);break}case"tool_result":{const x=n;this.applyToolResult(x.tool_call_id||"",x.content??x.output);break}case"interrupt":{this.finalizePendingToolCalls("canceled"),this.turnEnded=!0,this.userSinceTurnEnd=!1,this.setTurnStartedAt(null),this.closed||(a=this.onStatusChange)==null||a.call(this,"idle");break}case"control_request":case"permission_request":{const x=n.request;if(x&&x.subtype==="can_use_tool"){const y=n.request_id||"",k=x.tool_name||"unknown",_=x.input||x.tool_input||{},A=x.description||"",T=Array.isArray(x.permission_suggestions)?x.permission_suggestions:[];this.setEntries(w=>{const E=[...w].reverse().findIndex($=>$.type==="tool_call");if(E>=0){const $=w.length-1-E,I=w[$];if(I.toolCall.status==="running")return this.pendingPermissionToolIds.set(y,I.toolCall.id),w.map((v,F)=>F===$?{type:"tool_call",toolCall:{...I.toolCall,status:"waiting_for_confirmation",permissionRequest:{requestId:y,options:[]}}}:v)}return w}),(d=this.onPermissionRequest)==null||d.call(this,{requestId:y,toolName:k,toolInput:_,description:A,suggestions:T})}else x&&x.subtype==="elicitation"&&((c=this.onElicitationRequest)==null||c.call(this,{requestId:n.request_id||"",serverName:x.mcp_server_name||"",message:x.message||"",mode:x.mode==="url"?"url":"form",url:typeof x.url=="string"?x.url:void 0,requestedSchema:x.requested_schema||void 0}));break}case"conversation_rewound":{const x=Ts(n);x&&(this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries(y=>{const k=y.findIndex(_=>cs(_)===x);return k===-1?y:y.slice(0,k)}));break}case"session_status":{if(An(n)){this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries([]);break}if(typeof n.status=="string"){if(pt(n.status))this.closed=!0,this.finalizePendingToolCalls("canceled");else if(this.closed)break;if(n.status==="running"&&this.turnEnded&&!this.userSinceTurnEnd)break;(u=this.onStatusChange)==null||u.call(this,n.status)}break}case"error":{const x=String(n.message||n.content||"Unknown error");(p=this.onError)==null||p.call(this,x);break}case"models_state":{const x=n.raw,y=typeof x=="object"&&x!==null?x.models_state:n.models_state;y&&Array.isArray(y.availableModels)&&typeof y.currentModelId=="string"&&((h=this.onModelsStateChange)==null||h.call(this,y));break}case"system":{const x=n.raw,y=x&&typeof x=="object"?x:n,k=typeof y.subtype=="string"?y.subtype:void 0,_=vs(n);_&&(this.subagentState=bs(this.subagentState,_),(g=this.onSubagentUpdate)==null||g.call(this,this.subagentState));const A=typeof y.permissionMode=="string"?y.permissionMode:typeof n.permissionMode=="string"?n.permissionMode:null;if(A&&((b=this.onPermissionModeChange)==null||b.call(this,A)),k==="init"){const T=Ns(n);T&&((S=this.onWorkerInfoChange)==null||S.call(this,T))}break}case"control_response":{const x=n.response;if(x&&typeof x=="object"){const y=typeof x.request_id=="string"?x.request_id:"",k=typeof x.subtype=="string"?x.subtype:"";if(y){(M=this.onControlResponse)==null||M.call(this,{subtype:k,requestId:y,error:typeof x.error=="string"?x.error:void 0});const _=this.pendingControlRequests.get(y);_&&(this.pendingControlRequests.delete(y),_({data:k==="success"&&x.response&&typeof x.response=="object"?x.response:null,...k==="error"&&typeof x.error=="string"?{error:x.error}:{}}))}}break}case"stream_event":{const x=n.event;if(!x||typeof x.type!="string")break;if(x.type==="content_block_delta"){const y=x.delta;if(!y||typeof y.type!="string")break;const k=y.type==="text_delta"?"message":y.type==="thinking_delta"?"thought":null;if(!k)break;const _=y.text??y.thinking;if(typeof _!="string"||!_)break;this.appendStreamingDelta(k,_)}break}case"partial_assistant":{const x=typeof n.content=="string"?n.content:"";x&&this.appendStreamingDelta("message",x);break}case"result":case"result_success":{this.turnEnded=!0,this.userSinceTurnEnd=!1,this.setTurnStartedAt(null),this.finalizePendingToolCalls(n.is_error?"canceled":"complete"),this.closed||(C=this.onStatusChange)==null||C.call(this,"idle");const x=n.usage,y=typeof n.total_cost_usd=="number"?n.total_cost_usd:null;if(x||y!==null){const w=((x==null?void 0:x.input_tokens)??0)+((x==null?void 0:x.cache_read_input_tokens)??0)+((x==null?void 0:x.cache_creation_input_tokens)??0);(j=this.onUsageChange)==null||j.call(this,{inputTokens:w,outputTokens:(x==null?void 0:x.output_tokens)??0,totalCostUsd:y})}const k=typeof n.subtype=="string"?n.subtype:"",_=n.raw&&typeof n.raw=="object"?n.raw:void 0,T=(typeof n.result=="string"?n.result:typeof(_==null?void 0:_.result)=="string"?_.result:"").trim();k.startsWith("error_")&&T&&this.setEntries(w=>[...w,{type:"command_output",id:`exit-error-${typeof n.uuid=="string"?n.uuid:Date.now()}`,commandName:"worker",inputText:"",title:i("adapter.workerCrashed"),outputText:T,variant:"error"}]);break}case"task_state":{const x=Array.isArray(n.tasks)?n.tasks:[];if(x.length===0)break;const y=Cs(x);if(y.length===0)break;this.setEntries(k=>[...k.filter(A=>A.type!=="plan"),{type:"plan",id:`plan-${n.task_list_id||Date.now()}`,entries:y}]);break}}}applyEmbeddedToolResults(t){const s=t.message;if(!(!s||typeof s!="object"||!Array.isArray(s.content)))for(const n of s.content)!n||n.type!=="tool_result"||this.applyToolResult(n.tool_use_id||"",n.content??n.output)}applyToolResult(t,s){t&&(this.pendingToolCallIds.delete(t),this.setEntries(n=>{const a=Ss(n,t);if(a<0)return n;const d=n[a];return d.toolCall.status!=="running"&&d.toolCall.status!=="waiting_for_confirmation"?n:n.map((c,u)=>u===a?{type:"tool_call",toolCall:{...d.toolCall,status:"complete",permissionRequest:void 0,rawOutput:{output:s||""}}}:c)}))}finalizePendingToolCalls(t){if(this.pendingToolCallIds.size===0)return;const s=this.pendingToolCallIds;this.pendingToolCallIds=new Set,this.setEntries(n=>n.map(a=>a.type!=="tool_call"||!s.has(a.toolCall.id)?a:{type:"tool_call",toolCall:{...a.toolCall,status:t,permissionRequest:void 0}}))}appendStreamingDelta(t,s){this.setEntries(n=>{const a=n[n.length-1];if((a==null?void 0:a.type)==="assistant_message"&&a.id.startsWith(At)){const c=a.chunks[a.chunks.length-1];return(c==null?void 0:c.type)===t?[...n.slice(0,-1),{...a,chunks:[...a.chunks.slice(0,-1),{type:t,text:c.text+s}]}]:[...n.slice(0,-1),{...a,chunks:[...a.chunks,{type:t,text:s}]}]}const d={type:"assistant_message",id:`${At}${Date.now()}`,chunks:[{type:t,text:s}]};return[...n,d]})}async sendMessage(t,s,n){var h;const a=s&&s.length>0,d=n&&n.length>0;if(!t.trim()&&!a&&!d)return;const c={type:"user_message",id:`user-${Date.now()}`,content:t,images:a?s:void 0,attachments:d?n:void 0};this.setEntries(g=>[...g,c]);const u=[];if(t&&u.push({type:"text",text:t}),a)for(const g of s)u.push({type:"image",source:{type:"base64",media_type:g.mimeType,data:g.data}});if(d){for(const g of n)if(g.kind==="text"||g.kind==="table"){const b=`📎 ${g.name}${g.size!=null?` (${ca(g.size)})`:""}`,S=g.textContent||i("attach.emptyFile");u.push({type:"text",text:`${b}
|
|
77
77
|
\`\`\`
|
|
78
78
|
${S}
|
|
79
79
|
\`\`\``})}else if(g.kind==="directory"){const b=g.files!=null?`${H("attach.directoryHeader",{name:g.name})} ${H("attach.fileCount",{n:g.files.length})}`:H("attach.directoryHeader",{name:g.name}),S=g.textContent||i("attach.emptyDirectory");u.push({type:"text",text:`${b}
|
|
80
|
-
${S}`})}}const p=u.length===1&&u[0].type==="text"?u[0].text||t:u.length>0?u:t;try{const g=ve();this.postedUserUuids.add(g);const b=await In(this.sessionId,{type:"user",uuid:g,content:t,message:{content:p}}),S=(h=b==null?void 0:b.event)==null?void 0:h.id;S&&this.setEntries(M=>M.map(C=>C.type==="user_message"&&C.id===c.id?{...C,id:S}:C))}catch(g){throw this.setEntries(b=>b.filter(S=>!(S.type==="user_message"&&S.id===c.id))),g}}async respondPermission(t,s,n){await ee(this.sessionId,{type:"permission_response",approved:s,request_id:t,...n});const a=this.pendingPermissionToolIds.get(t);this.pendingPermissionToolIds.delete(t),a&&!s&&this.pendingToolCallIds.delete(a),this.setEntries(d=>d.map(c=>{var u;return c.type!=="tool_call"||((u=c.toolCall.permissionRequest)==null?void 0:u.requestId)!==t?c:{type:"tool_call",toolCall:{...c.toolCall,status:s?"running":"rejected",permissionRequest:void 0}}}))}async interrupt(){this.finalizePendingToolCalls("canceled"),await $n(this.sessionId)}async setPermissionMode(t){const s=ve();return await ee(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_permission_mode",mode:t}}),s}async controlRoundTrip(t,s=8e3){const n=ve(),a=new Promise(c=>{this.pendingControlRequests.set(n,c)}),d=setTimeout(()=>{const c=this.pendingControlRequests.get(n);c&&(this.pendingControlRequests.delete(n),c({data:null,error:"timeout"}))},s);try{return await ee(this.sessionId,{type:"control_request",request_id:n,request:t}),await a}catch(c){throw this.pendingControlRequests.delete(n),c}finally{clearTimeout(d)}}async searchFiles(t,s=20){const n=await this.controlRoundTrip({subtype:"file_search",query:t,limit:s});try{if(!n.data||!Array.isArray(n.data.suggestions))return[];const a=[];for(const d of n.data.suggestions)d&&typeof d=="object"&&typeof d.path=="string"&&a.push(d.path);return a}catch{return[]}}async respondElicitation(t,s,n){await ee(this.sessionId,{type:"permission_response",approved:s==="accept",request_id:t,response:{subtype:"success",request_id:t,response:{action:s,...n?{content:n}:{}}}})}async askSideQuestion(t){const s=await this.controlRoundTrip({subtype:"side_question",question:t},12e4);if(s.error||!s.data)return null;const n=s.data.response;return typeof n=="string"?n:null}async listResumableSessions(){const t=await this.controlRoundTrip({subtype:"list_sessions"});if(!t.data||!Array.isArray(t.data.sessions))throw new Error(t.error??"list_sessions failed");const s=[];for(const n of t.data.sessions){if(!n||typeof n!="object")continue;const a=n;typeof a.session_id!="string"||!a.session_id||s.push({sessionId:a.session_id,title:typeof a.title=="string"&&a.title?a.title:a.session_id.slice(0,8),modified:typeof a.modified=="number"?a.modified:0,...typeof a.created_at=="number"?{createdAt:a.created_at}:{},...typeof a.git_branch=="string"&&a.git_branch?{gitBranch:a.git_branch}:{}})}return s}async resumeSession(t){const s=await this.controlRoundTrip({subtype:"resume_session",session_id:t},3e4);if(!s.data)throw new Error(s.error??"resume_session failed");return{title:typeof s.data.title=="string"?s.data.title:null,messageCount:typeof s.data.message_count=="number"?s.data.message_count:0}}async setEffort(t){const s=ve();return await ee(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_effort",...t?{effort:t}:{effort:null}}}),s}async setTokenMode(t){const s=ve();return await ee(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_token_mode",mode:t}}),s}async setThinkingBudget(t){const s=ve();return await ee(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_max_thinking_tokens",max_thinking_tokens:t}}),s}async getContextUsage(){const t=await this.controlRoundTrip({subtype:"get_context_usage"});try{if(!t.data)return null;const s=t.data.totalTokens,n=t.data.rawMaxTokens,a=t.data.percentage;if(typeof s!="number"||typeof n!="number")return null;const d=t.data.categories,c=Array.isArray(d)?d.filter(u=>!!u&&typeof u=="object"&&typeof u.name=="string").map(u=>({name:u.name,tokens:typeof u.tokens=="number"?u.tokens:0,...u.isDeferred===!0?{isDeferred:!0}:{}})):void 0;return{totalTokens:s,rawMaxTokens:n,percentage:typeof a=="number"?a:0,...typeof t.data.model=="string"&&t.data.model?{model:t.data.model}:{},...c&&c.length>0?{categories:c}:{}}}catch{return null}}async stopSubagent(t){const s=await this.controlRoundTrip({subtype:"stop_task",task_id:t});try{return s.error?{ok:!1,error:s.error==="timeout"?i("adapter.stopTimeout"):s.error}:{ok:!0}}catch{return{ok:!1,error:i("adapter.stopFailed")}}}async getMcpServers(){var a;const s=(a=(await this.controlRoundTrip({subtype:"mcp_status"})).data)==null?void 0:a.mcpServers;if(!Array.isArray(s))return[];const n=[];for(const d of s){if(!d||typeof d!="object")continue;const c=d;if(typeof c.name!="string"||!c.name)continue;const u=c.status;if(u!=="connected"&&u!=="failed"&&u!=="needs-auth"&&u!=="pending"&&u!=="disabled")continue;const p=c.serverInfo,h=c.config;n.push({name:c.name,status:u,...p&&typeof p.name=="string"&&typeof p.version=="string"?{serverInfo:{name:p.name,version:p.version}}:{},...typeof c.error=="string"&&c.error?{error:c.error}:{},...typeof(h==null?void 0:h.url)=="string"&&h.url?{url:h.url}:{},...Array.isArray(c.tools)?{toolCount:c.tools.length}:{}})}return n}async toggleMcpServer(t,s){const n=await this.controlRoundTrip({subtype:"mcp_toggle",serverName:t,enabled:s},15e3);return n.error?{ok:!1,error:n.error==="timeout"?i("adapter.requestTimeout"):n.error}:{ok:!0}}async reconnectMcpServer(t){const s=await this.controlRoundTrip({subtype:"mcp_reconnect",serverName:t},2e4);return s.error?{ok:!1,error:s.error==="timeout"?i("adapter.requestTimeout"):s.error}:{ok:!0}}async getRemoteSettings(){const s=(await this.controlRoundTrip({subtype:"get_settings"})).data;if(!s)return null;const n=s.applied,a=s.effective&&typeof s.effective=="object"&&!Array.isArray(s.effective)?s.effective:{},d=s.sources,c=[];if(Array.isArray(d))for(const u of d){if(!u||typeof u!="object")continue;const p=u;typeof p.source=="string"&&c.push({source:p.source,settings:p.settings&&typeof p.settings=="object"&&!Array.isArray(p.settings)?p.settings:{}})}return{applied:{model:typeof(n==null?void 0:n.model)=="string"?n.model:null,effort:typeof(n==null?void 0:n.effort)=="string"?n.effort:null,tokenMode:typeof(n==null?void 0:n.tokenMode)=="string"?n.tokenMode:null},effective:a,sources:c}}async applyFlagSettings(t){const s=await this.controlRoundTrip({subtype:"apply_flag_settings",settings:t},15e3);return s.error?{ok:!1,error:s.error==="timeout"?i("adapter.requestTimeout"):s.error}:{ok:!0}}async rewindToMessage(t){await Dn(this.sessionId,t)}async endSession(t){await ee(this.sessionId,{type:"control_request",request_id:ve(),request:{subtype:"end_session",...t?{reason:t}:{}}})}}function ca(r){return r<1024?`${r} B`:r<1024*1024?`${(r/1024).toFixed(1)} KB`:`${(r/(1024*1024)).toFixed(1)} MB`}function xt({onBack:r,title:t,meta:s,actions:n}){return ae(),e.jsx("div",{className:"flex-shrink-0 border-b border-nav-rule bg-surface-1/80 backdrop-blur-md",children:e.jsxs("div",{className:"mx-auto flex h-12 w-full page-measure items-center gap-2 px-4 sm:px-8",children:[e.jsx("button",{type:"button",onClick:r,"aria-label":i("nav.dashboard"),title:i("nav.dashboard"),className:"-mx-2 flex-shrink-0 rounded-md px-2 py-1 text-xs text-text-muted transition hover:-translate-x-0.5 hover:bg-surface-2 hover:text-text-primary",children:i("nav.dashboard")}),e.jsx("span",{className:"mx-1 h-4 w-px flex-shrink-0 bg-border","aria-hidden":"true"}),e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[t,s&&e.jsx("div",{className:"flex flex-shrink-0 items-center gap-2",children:s})]}),n&&e.jsx("div",{className:"flex flex-shrink-0 items-center gap-0.5",children:n}),e.jsx("span",{className:"mx-1 h-4 w-px flex-shrink-0 bg-border","aria-hidden":"true"}),e.jsx(Pn,{}),e.jsx(On,{onSettingsClick:()=>{window.history.pushState(null,"","/settings"),window.dispatchEvent(new PopStateEvent("popstate"))}})]})})}const Ms="rcs:subagent-panel:collapsed";function da(r){if(r<1e3)return"0s";const t=Math.floor(r/1e3);if(t<60)return`${t}s`;const s=Math.floor(t/60),n=t%60;if(s<60)return n?`${s}m${n}s`:`${s}m`;const a=Math.floor(s/60),d=s%60;return d?`${a}h${d}m`:`${a}h`}function ua(r){return r===void 0||r<=0?"":r<1e3?`${r}`:r<1e6?`${(r/1e3).toFixed(r<1e4?1:0)}k`:`${(r/1e6).toFixed(1)}M`}function ma({status:r}){return r==="running"?e.jsx(Ge,{className:"h-3 w-3 animate-spin text-brand-text"}):r==="completed"?e.jsx(Gr,{className:"h-3 w-3 text-status-success"}):r==="failed"||r==="stopped"?e.jsx(Un,{className:"h-3 w-3 text-status-error"}):null}function tn({task:r,onStopTask:t,fullText:s}){const n=r.status==="running",a=n?r.durationMs??Date.now()-r.startTime:(r.endTime??Date.now())-r.startTime,d=ua(r.tokenCount),c=r.toolUseCount!==void 0&&r.toolUseCount>0?`${r.toolUseCount} tool${r.toolUseCount>1?"s":""}`:"",u=r.summary||r.description||"(no description)";return e.jsxs("div",{className:"group/task flex items-start gap-2 rounded-md bg-surface-2 px-2.5 py-1.5 text-xs",children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0",children:e.jsx(ma,{status:r.status})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"truncate font-medium text-text-primary",children:r.name}),e.jsx("span",{className:"flex-shrink-0 font-mono text-text-muted",children:da(a)})]}),e.jsx("div",{className:`mt-0.5 text-text-secondary ${s?"line-clamp-2 break-words":"truncate"}`,children:u}),(d||c||r.lastToolName)&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-x-2 overflow-hidden whitespace-nowrap font-mono text-[10px] text-text-muted",children:[d&&e.jsxs("span",{className:"flex-shrink-0",children:["↕ ",d," tok"]}),c&&e.jsxs("span",{className:"flex-shrink-0",children:["· ",c]}),r.lastToolName&&e.jsxs("span",{className:"min-w-0 truncate",children:["· last: ",r.lastToolName]})]}),!n&&r.finalSummary&&e.jsx("div",{className:"mt-1 line-clamp-2 rounded bg-status-success/10 px-1.5 py-0.5 text-[10px] text-status-success",children:r.finalSummary})]}),n&&t&&e.jsx("button",{type:"button",onClick:()=>t(r.taskId),title:i("subagent.stop"),className:"mt-0.5 flex-shrink-0 rounded p-0.5 text-text-muted opacity-0 transition-opacity hover:bg-status-error/10 hover:text-status-error focus:opacity-100 group-hover/task:opacity-100",children:e.jsx(Fn,{className:"h-3.5 w-3.5"})})]})}function xa({state:r,onStopTask:t}){const[s,n]=l.useState(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Ms)==="1"}catch{return!1}}),a=()=>{n(b=>{const S=!b;try{window.localStorage.setItem(Ms,S?"1":"0")}catch{}return S})},d=Object.values(r.tasks).some(b=>b.status==="running"),c=Object.values(r.tasks).some(b=>b.status!=="running"&&b.evictAfter!==void 0),[,u]=l.useState(0);l.useEffect(()=>{if(!d&&!c)return;const b=setInterval(()=>{u(S=>S+1)},1e3);return()=>clearInterval(b)},[d,c]);const p=en(r);if(p.length===0)return null;const h=p.filter(b=>b.status==="running").length,g=h>0?`${h} running`:`${p.length} recent`;return e.jsx("section",{"aria-label":"Subagents",className:"border-t border-border bg-surface-1 px-4 py-2",children:e.jsxs("div",{className:"mx-auto max-w-3xl space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:a,"aria-expanded":!s,"aria-controls":"subagent-list",className:"flex w-full items-center justify-between text-[10px] font-medium uppercase tracking-wide text-text-muted hover:text-text-secondary transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(zs,{className:`h-3 w-3 transition-transform ${s?"":"rotate-90"}`}),e.jsx("span",{children:"Subagents"})]}),e.jsx("span",{children:g})]}),!s&&e.jsx("div",{id:"subagent-list",className:"space-y-1.5",children:p.map(b=>e.jsx(tn,{task:b,onStopTask:t},b.taskId))})]})})}function pa(r){if(!r)return"never";const t=Math.max(0,Date.now()-r);return t<5e3?"just now":t<6e4?`${Math.floor(t/1e3)}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:`${Math.floor(t/36e5)}h ago`}function fa(r){return r?Date.now()-r<6e4:!1}function ha({onClose:r,session:t,liveStatus:s,pendingPermissions:n,onInterrupt:a,onDelete:d,subagentState:c,onStopTask:u,onEndSession:p}){const[h,g]=l.useState(!1),b=async()=>{await navigator.clipboard.writeText(t.id),g(!0),setTimeout(()=>g(!1),1500)},[S,M]=l.useState(!1),C=async()=>{if(!(!p||S)&&window.confirm(i("task.endConfirm"))){M(!0);try{await p(),r()}catch{M(!1)}}},j=n.length,x=t.worker,y=t.work_item,k=t.environment;return e.jsx(De,{open:!0,onOpenChange:_=>{_||r()},children:e.jsxs(qe,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-96 h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md overflow-y-auto",children:[e.jsx(Pe,{children:e.jsx(Oe,{className:"font-display font-semibold text-text-primary",children:"Session Ops"})}),e.jsxs("div",{className:"mt-3 space-y-5 text-sm",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-text-muted",children:[e.jsx(wr,{className:"h-3.5 w-3.5"}),"Status"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Kn,{status:s||t.status||"unknown"}),e.jsx("span",{className:"text-xs text-text-muted",children:x&&(fa(x.last_heartbeat_at)?"· worker online":"· worker offline")})]}),e.jsxs("dl",{className:"space-y-1 text-xs text-text-muted",children:[x&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(ds,{className:"h-3 w-3"}),"Heartbeat"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:pa(x.last_heartbeat_at)})]}),k&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(Gs,{className:"h-3 w-3"}),"Environment"]}),e.jsx("dd",{className:"truncate text-text-secondary",children:k.machine_name||k.id})]}),t.created_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(ds,{className:"h-3 w-3"}),"Created"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:Ws(t.created_at)})]})]})]}),e.jsx(ba,{state:c,onStopTask:u}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-text-muted",children:[e.jsx(Ge,{className:"h-3.5 w-3.5"}),"Pending Actions"]}),j>0?e.jsxs("div",{className:"rounded-md bg-status-warning/10 px-3 py-2 text-xs text-status-warning",children:[j," permission request",j>1?"s":""," awaiting your approval"]}):e.jsx("p",{className:"text-xs text-text-muted",children:"No pending actions"})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-text-muted",children:[e.jsx(Zr,{className:"h-3.5 w-3.5"}),"Quick Actions"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:a,className:"flex-1 rounded-md border border-border px-3 py-1.5 text-xs text-text-secondary hover:bg-surface-2 transition-colors",children:"Interrupt"}),p&&e.jsx("button",{onClick:C,disabled:S,className:"flex-1 rounded-md border border-status-error/30 px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:i("task.endHint"),children:S?"Ending…":"End session"}),e.jsxs("button",{onClick:d,className:"flex-1 rounded-md border border-status-error/30 px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 transition-colors",children:[e.jsx(Qs,{className:"mr-1 inline h-3 w-3"}),"Delete"]})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-text-muted",children:[e.jsx(Kr,{className:"h-3.5 w-3.5"}),"Session Info"]}),e.jsxs("dl",{className:"space-y-1 text-xs text-text-muted",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("dt",{children:"Session ID"}),e.jsxs("dd",{className:"flex items-center gap-1 min-w-0",children:[e.jsx("code",{className:"break-all font-mono text-text-secondary text-right",children:t.id}),e.jsx("button",{onClick:b,className:"text-text-muted hover:text-text-primary transition-colors flex-shrink-0",title:"Copy session id",children:h?"✓":"⧉"})]})]}),y&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Spawn mode"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:y.spawn_mode??"default"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Work state"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:y.state})]})]}),t.source&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Source"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:t.source})]}),k&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Worker type"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:k.worker_type})]})]})]})]})]})})}const ya={in_process_teammate:"task.type.teammates",local_bash:"task.type.shells",monitor_mcp:"task.type.monitors",remote_agent:"task.type.remoteAgents",local_agent:"task.type.localAgents"},ga=new Set(["dream"]);function ba({state:r,onStopTask:t}){const s=Object.values(r.tasks).some(p=>p.status==="running"),n=Object.values(r.tasks).some(p=>p.status!=="running"&&p.evictAfter!==void 0),[,a]=l.useState(0);l.useEffect(()=>{if(!s&&!n)return;const p=setInterval(()=>{a(h=>h+1)},1e3);return()=>clearInterval(p)},[s,n]);const d=en(r),c=d.filter(p=>p.status==="running").length,u=d.length-c;return e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-text-muted",children:[e.jsx(Wr,{className:"h-3.5 w-3.5"}),i("task.backgroundTasks")]}),d.length>0&&e.jsx("span",{className:"font-mono text-[10px] text-text-muted",children:c>0&&u>0?H("task.mixedCount",{running:c,recent:u}):c>0?H("task.runningCount",{count:c}):H("task.recentCount",{count:d.length})})]}),d.length===0?e.jsx("p",{className:"text-xs text-text-muted",children:i("task.noBackgroundTasks")}):e.jsx("div",{className:"max-h-[38vh] space-y-2 overflow-y-auto overscroll-contain pr-1",children:aa(d).map(p=>{const h=!ga.has(p.taskType),g=ya[p.taskType]??"task.type.tasks";return e.jsxs("div",{className:"space-y-1",children:[h&&e.jsxs("div",{className:"pl-1 text-[10px] font-medium uppercase tracking-wide text-text-muted/80",children:[i(g)," (",p.tasks.length,")"]}),p.tasks.map(b=>e.jsx(tn,{task:b,onStopTask:t,fullText:!0},b.taskId))]},p.taskType)})})]})}const ja={connected:"bg-status-success/15 text-status-success",failed:"bg-status-error/15 text-status-error","needs-auth":"bg-status-warning/15 text-status-warning",pending:"bg-status-active/15 text-status-active",disabled:"bg-surface-3 text-text-muted"},wa={connected:"mcp.status.connected",failed:"mcp.status.failed","needs-auth":"mcp.status.needsAuth",pending:"mcp.status.pending",disabled:"mcp.status.disabled"};function va({onClose:r,fetchServers:t,onToggle:s,onReconnect:n}){ae();const[a,d]=l.useState(null),[c,u]=l.useState(null),[p,h]=l.useState(null),[g,b]=l.useState(null),S=l.useCallback(async()=>{h(null),b(null);try{const j=await t();d(j),u(null)}catch(j){ht("[McpPanel] fetch failed",j),u(i("mcp.loadFailed"))}},[t]);l.useEffect(()=>{S()},[S]);const M=async j=>{const x=j.status==="disabled";h(`toggle:${j.name}`),b(null);try{const y=await s(j.name,x);y.ok||b(y.error||i("mcp.toggleFailed"))}finally{await S()}},C=async j=>{h(`reconnect:${j.name}`),b(null);try{const x=await n(j.name);x.ok||b(x.error||i("mcp.reconnectFailed"))}finally{await S()}};return e.jsx(De,{open:!0,onOpenChange:j=>{j||r()},children:e.jsxs(qe,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-96 h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md overflow-y-auto",children:[e.jsx(Pe,{children:e.jsxs(Oe,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(Xs,{className:"h-4 w-4"}),i("session.mcp.title")]})}),e.jsxs("div",{className:"mt-3 space-y-3 text-sm",children:[g&&e.jsx("div",{className:"rounded-md bg-status-error/10 px-3 py-2 text-xs text-status-error",children:g}),a===null&&!c&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(Ge,{className:"h-3.5 w-3.5 animate-spin"}),i("mcp.loading")]}),c&&e.jsx("p",{className:"text-xs text-status-error",children:c}),a!==null&&a.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:i("mcp.empty")}),a==null?void 0:a.map(j=>{const x=p===`toggle:${j.name}`,y=p===`reconnect:${j.name}`,k=j.status==="disabled";return e.jsx("div",{className:"rounded-lg border border-border bg-surface-2 px-3 py-2.5",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-2",children:[e.jsx("span",{className:"truncate text-sm font-medium text-text-primary",children:j.name}),e.jsx("span",{className:`flex-shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium ${ja[j.status]}`,children:i(wa[j.status])})]}),e.jsxs("div",{className:"mt-0.5 truncate text-xs text-text-muted",children:[j.serverInfo?`${j.serverInfo.name} v${j.serverInfo.version}`:j.url||"stdio",j.toolCount!==void 0&&` · ${H("mcp.toolCount",{n:j.toolCount})}`]}),j.error&&e.jsx("div",{className:"mt-1 truncate text-xs text-status-error",title:j.error,children:j.error})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>void C(j),disabled:y||k,className:"rounded-md p-1.5 text-text-muted hover:bg-surface-3 hover:text-text-primary transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:i("mcp.reconnect"),children:e.jsx(kr,{className:`h-3.5 w-3.5 ${y?"animate-spin":""}`})}),e.jsx("button",{type:"button",role:"switch","aria-checked":!k,onClick:()=>void M(j),disabled:x,className:`relative h-5 w-9 rounded-full transition-colors disabled:opacity-50 ${k?"bg-surface-3":"bg-brand"}`,title:k?i("mcp.enable"):i("mcp.disable"),children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${k?"left-0.5":"left-4.5"}`})})]})]})},j.name)})]})]})})}const sn=[{key:"autoMemoryEnabled",labelKey:"settings.autoMemory",defaultValue:!0},{key:"teamMemoryEnabled",labelKey:"settings.teamMemory",defaultValue:!1}],ka=new Set(sn.map(r=>r.key));function Na(r){if(r==null)return i("settings.unset");if(typeof r=="string")return r;try{return JSON.stringify(r)}catch{return String(r)}}function Rs(r){if(r==null)return i("settings.unset");if(typeof r=="object")try{return JSON.stringify(r,null,2)}catch{return String(r)}return String(r)}function Sa({onClose:r,fetchSettings:t,onApply:s}){ae();const[n,a]=l.useState(null),[d,c]=l.useState(null),[u,p]=l.useState(""),[h,g]=l.useState(null),[b,S]=l.useState(null),[M,C]=l.useState(null),[j,x]=l.useState(!1),y=l.useCallback(async()=>{g(null),S(null),C(null),x(!1);try{const v=await t();a(v),c(v?null:i("settings.loadFailed"))}catch(v){ht("[SettingsDrawer] fetch failed",v),c(i("settings.loadFailed"))}},[t]);l.useEffect(()=>{y()},[y]);const k=l.useMemo(()=>n?Object.entries(n.effective).filter(([,v])=>v!==void 0).filter(([v])=>!v.startsWith("memoryV2")).sort(([v],[F])=>v.localeCompare(F)):[],[n]),_=l.useMemo(()=>{const v=u.trim().toLowerCase();return v?k.filter(([F,P])=>`${F} ${Na(P)}`.toLowerCase().includes(v)):k},[k,u]),A=v=>typeof v[1]=="boolean",T=l.useMemo(()=>_.filter(A).filter(([v])=>!ka.has(v)),[_]),w=l.useMemo(()=>_.filter(v=>!A(v)),[_]),E=l.useMemo(()=>M===null?null:k.find(([v])=>v===M)??null,[k,M]),I=async()=>{if(E)try{await navigator.clipboard.writeText(Rs(E[1])),x(!0),window.setTimeout(()=>x(!1),1500)}catch(v){ht("[SettingsDrawer] copy failed",v)}},$=async(v,F)=>{g(v),S(null);try{const P=await s({[v]:!F});P.ok||S(P.error||i("settings.writeFailed"))}finally{await y()}};return e.jsx(De,{open:!0,onOpenChange:v=>{v||r()},children:e.jsxs(qe,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-96 h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md overflow-y-auto",children:[e.jsx(Pe,{children:e.jsxs(Oe,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(Zs,{className:"h-4 w-4"}),i("session.settings.title")]})}),e.jsxs("div",{className:"mt-3 space-y-4 text-sm",children:[b&&e.jsx("div",{className:"rounded-md bg-status-error/10 px-3 py-2 text-xs text-status-error",children:b}),n===null&&!d&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(Ge,{className:"h-3.5 w-3.5 animate-spin"}),i("settings.loading")]}),d&&e.jsx("p",{className:"text-xs text-status-error",children:d}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"rounded-lg border border-border bg-surface-2 px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-text-muted",children:i("settings.model")}),e.jsx("code",{className:"font-mono text-text-secondary",children:n.applied.model||i("settings.defaultModel")})]}),n.applied.effort&&e.jsxs("div",{className:"mt-1 flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-text-muted",children:"Effort"}),e.jsx("code",{className:"font-mono text-text-secondary",children:n.applied.effort})]}),e.jsx("p",{className:"mt-2 text-[10px] leading-relaxed text-text-muted",children:i("settings.hint")})]}),E?e.jsxs("section",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>{C(null),x(!1)},className:"flex items-center gap-1.5 text-xs text-text-muted transition-colors hover:text-text-primary",children:[e.jsx(Nr,{className:"h-3.5 w-3.5"}),i("settings.back")]}),e.jsx("div",{className:"break-all font-mono text-xs font-medium text-text-primary",children:E[0]}),e.jsx("pre",{className:"max-h-[60vh] overflow-y-auto whitespace-pre-wrap break-all rounded-md border border-border bg-surface-2 p-3 font-mono text-[10px] leading-relaxed text-text-secondary",children:Rs(E[1])}),e.jsxs("button",{type:"button",onClick:()=>void I(),className:"flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-text-secondary transition-colors hover:bg-surface-2 hover:text-text-primary",children:[j?e.jsx($e,{className:"h-3.5 w-3.5 text-status-success"}):e.jsx(_r,{className:"h-3.5 w-3.5"}),j?i("settings.copied"):i("settings.copyValue")]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-surface-2 px-2.5 py-1.5",children:[e.jsx(yt,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{value:u,onChange:v=>p(v.target.value),placeholder:i("settings.searchPlaceholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"})]}),_.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:i("settings.noMatch")}),e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-[10px] font-medium uppercase tracking-wide text-text-muted",children:i("settings.memorySection")}),sn.map(v=>{const F=n.effective[v.key],P=typeof F=="boolean"?F:v.defaultValue,G=h===v.key;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-border bg-surface-2 px-3 py-2",children:[e.jsx("div",{className:"truncate text-xs text-text-primary",children:i(v.labelKey)}),e.jsx("button",{type:"button",role:"switch","aria-checked":P,disabled:G,onClick:()=>void $(v.key,P),className:`relative h-5 w-9 flex-shrink-0 rounded-full transition-colors disabled:opacity-50 ${P?"bg-brand":"bg-surface-3"}`,title:P?i("settings.turnOff"):i("settings.turnOn"),children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${P?"left-4.5":"left-0.5"}`})})]},v.key)}),e.jsx("p",{className:"text-[10px] leading-relaxed text-text-muted",children:i("settings.memoryHint")})]}),T.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-[10px] font-medium uppercase tracking-wide text-text-muted",children:H("settings.togglable",{n:T.length})}),T.map(([v,F])=>{const P=h===v;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-border bg-surface-2 px-3 py-2",children:[e.jsx("div",{className:"truncate font-mono text-xs text-text-primary",children:v}),e.jsx("button",{type:"button",role:"switch","aria-checked":F,disabled:P,onClick:()=>void $(v,F),className:`relative h-5 w-9 flex-shrink-0 rounded-full transition-colors disabled:opacity-50 ${F?"bg-brand":"bg-surface-3"}`,title:F?i("settings.turnOff"):i("settings.turnOn"),children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${F?"left-4.5":"left-0.5"}`})})]},v)})]}),w.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-[10px] font-medium uppercase tracking-wide text-text-muted",children:H("settings.readOnly",{n:w.length})}),w.map(([v])=>e.jsxs("button",{type:"button",onClick:()=>C(v),className:"flex w-full items-center justify-between gap-3 rounded-md border border-border bg-surface-2 px-3 py-2 text-left transition-colors hover:bg-surface-3",title:i("settings.viewDetail"),children:[e.jsx("span",{className:"truncate font-mono text-xs text-text-primary",children:v}),e.jsx(zs,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"})]},v))]})]})]})]})]})})}function _a({onClose:r,onAsk:t}){ae();const[s,n]=l.useState([]),[a,d]=l.useState(""),[c,u]=l.useState(!1),p=async()=>{const h=a.trim();if(!h||c)return;const g=Date.now();n(b=>[...b,{id:g,question:h,answer:null}]),d(""),u(!0);try{const b=await t(h);n(S=>S.map(M=>M.id===g?{...M,answer:b??i("sideQuestion.noAnswer"),error:b===null}:M))}finally{u(!1)}};return e.jsx(De,{open:!0,onOpenChange:h=>{h||r()},children:e.jsxs(qe,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-[26rem] h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md flex flex-col",children:[e.jsx(Pe,{children:e.jsxs(Oe,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(Js,{className:"h-4 w-4"}),i("sideQuestion.title")]})}),e.jsx("p",{className:"mt-1 text-[10px] leading-relaxed text-text-muted",children:i("sideQuestion.desc")}),e.jsxs("div",{className:"mt-3 flex-1 space-y-4 overflow-y-auto",children:[s.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:i("sideQuestion.empty")}),s.map(h=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx("div",{className:"max-w-[85%] rounded-2xl rounded-br-md border border-user-bubble-border bg-user-bubble px-4 py-2 text-sm text-text-primary",children:h.question})}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-brand/8 flex items-center justify-center flex-shrink-0 overflow-hidden",children:e.jsx("img",{src:"/code/pony.svg",alt:"Saluzi",width:24,height:24,className:"object-contain",draggable:!1})}),e.jsx("div",{className:"min-w-0 flex-1 pt-1 text-sm text-text-primary",children:h.answer===null?e.jsxs("span",{className:"chat-typing-indicator inline-flex items-center gap-1","aria-hidden":"true",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):e.jsx("div",{className:h.error?"text-status-error":"",children:e.jsx(Ln,{children:h.answer})})})]})]},h.id))]}),e.jsxs("div",{className:"mt-3 flex items-end gap-2",children:[e.jsx("textarea",{value:a,onChange:h=>d(h.target.value),onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey&&!h.nativeEvent.isComposing&&(h.preventDefault(),p())},rows:Math.min(4,Math.max(1,a.split(`
|
|
81
|
-
`).length)),placeholder:i("sideQuestion.placeholder"),disabled:c,className:"flex-1 resize-none rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary placeholder:text-text-muted focus:border-accent focus:outline-none disabled:opacity-50"}),e.jsx("button",{type:"button",onClick:()=>void p(),disabled:c||!a.trim(),className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg bg-brand text-white transition-colors hover:bg-brand-light disabled:opacity-40 disabled:cursor-not-allowed",title:i("sideQuestion.send"),children:c?e.jsx(Ge,{className:"h-4 w-4 animate-spin"}):e.jsx(Bn,{className:"h-4 w-4"})})]})]})})}const At="focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface-1";function As(r,t){var a;const s=(a=t==null?void 0:t.find(d=>d.type==="addRules"||d.type==="replaceRules"))==null?void 0:a.rules,n=s==null?void 0:s[0];return n!=null&&n.ruleContent?`${n.toolName}(${n.ruleContent})`:n!=null&&n.toolName?n.toolName:r}function Ca({requestId:r,toolName:t,toolInput:s,description:n,suggestions:a,onApprove:d,onApproveAlways:c,onReject:u}){ae();const p=s&&typeof s=="object"&&!Array.isArray(s)?s:{},h=Hn(Wn(t),p,{writeUnknownLabel:i("permission.writeUnknown")}),g=typeof s=="string"?s:JSON.stringify(s,null,2),b=Array.isArray(a)&&a.length>0;return e.jsxs("div",{role:"group","aria-label":H("permission.requestAria",{tool:t}),className:"rounded-xl border border-approve/30 bg-surface-1 p-4",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("span",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-approve/15 text-approve-text",children:e.jsx(Qn,{className:"h-3 w-3"})}),e.jsx("span",{className:"text-sm font-semibold font-display text-approve-text",children:i("permission.title")})]}),n&&e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:te(n)}),e.jsx("div",{className:"mb-2 font-mono text-xs font-bold text-text-primary",children:te(t)}),t!=="AskUserQuestion"&&(h?e.jsx("div",{className:"mb-3 space-y-2",children:h.map((S,M)=>e.jsx(Vn,{filePath:S.filePath,oldString:S.oldString,newString:S.newString,label:S.label},M))}):e.jsx("pre",{className:"mb-3 max-h-40 overflow-auto rounded-lg bg-surface-1 p-2 text-xs text-text-secondary font-mono",children:us(g,500)})),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:d,className:he("rounded-lg bg-approve px-4 py-2 text-sm font-medium font-display text-white hover:bg-approve-hover transition-colors",At),children:i("permission.approve")}),b&&c&&e.jsxs("button",{onClick:c,className:he("flex items-center gap-1.5 rounded-lg border border-approve/40 bg-approve/10 px-4 py-2 text-sm font-medium font-display text-approve-text hover:bg-approve/20 transition-colors",At),title:i("permission.alwaysAllowHint").replace("{rule}",As(t,a)),children:[e.jsx(ra,{className:"h-3.5 w-3.5"}),i("permission.alwaysAllow")," ",us(As(t,a),40)]}),e.jsx("button",{onClick:u,className:he("rounded-lg border border-status-error/40 px-4 py-2 text-sm font-medium font-display text-status-error hover:bg-status-error/10 transition-colors",At),children:i("permission.reject")})]})]})}function Ta({questions:r,description:t,onSubmit:s,onSkip:n}){const[a,d]=l.useState({}),[c,u]=l.useState({}),[p,h]=l.useState(0),g=(C,j,x)=>{if(x){const y=a[C]||[],k=y.includes(j)?y.filter(_=>_!==j):[...y,j];d({...a,[C]:k})}else d({...a,[C]:j})},b=C=>{var x;const j=(x=c[C])==null?void 0:x.trim();j&&(d({...a,[C]:j}),u({...c,[C]:""}))},S=()=>{var j,x;const C={};for(const[y,k]of Object.entries(a)){const _=r[parseInt(y,10)];_&&(typeof k=="number"?C[y]=((x=(j=_.options)==null?void 0:j[k])==null?void 0:x.label)||String(k):Array.isArray(k)?C[y]=k.map(A=>{var T,w;return((w=(T=_.options)==null?void 0:T[A])==null?void 0:w.label)||String(A)}):C[y]=k)}s(C)};if(r.length<=1){const C=r[0]||{question:t,options:[],multiSelect:!1},j=C.multiSelect||!1;return e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx("div",{className:"mb-3 text-sm font-semibold font-display text-text-primary",children:te(t||C.question||"Question")}),e.jsxs("div",{className:"space-y-2",children:[(C.options||[]).map((x,y)=>{const k=j?(a[0]||[]).includes(y):a[0]===y;return e.jsxs("button",{onClick:()=>g(0,y,j),className:he("w-full rounded-lg border px-4 py-2.5 text-left text-sm font-display transition-colors",k?"border-brand bg-brand/10 text-text-primary":"border-border bg-surface-2 text-text-secondary hover:border-border-light"),children:[e.jsx("div",{className:"font-medium font-display",children:te(x.label)}),x.description&&e.jsx("div",{className:"mt-0.5 text-xs font-sans text-text-muted",children:te(x.description)})]},y)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:c[0]||"",onChange:x=>u({...c,0:x.target.value}),placeholder:"Other...",className:"flex-1 rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm font-display text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none",onKeyDown:x=>x.key==="Enter"&&b(0)}),e.jsx("button",{onClick:()=>b(0),className:"rounded-lg border border-border px-3 py-2 text-sm font-display text-text-secondary hover:bg-surface-2 transition-colors",children:"Send"})]})]}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx("button",{onClick:S,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium font-display text-white hover:bg-brand-light transition-colors",children:"Submit"}),e.jsx("button",{onClick:n,className:"rounded-lg border border-border px-4 py-2 text-sm font-display text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})}const M=r[p];return e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx("div",{className:"mb-3 text-sm font-semibold font-display text-text-primary",children:te(t||"Questions")}),e.jsx("div",{className:"mb-3 flex gap-1 overflow-x-auto",children:r.map((C,j)=>e.jsx("button",{onClick:()=>h(j),className:he("rounded-md px-3 py-1.5 text-xs font-display whitespace-nowrap transition-colors",p===j?"bg-brand/20 text-brand-text":"text-text-muted hover:bg-surface-2"),children:C.header||`Q${j+1}`},j))}),M&&e.jsx(Ea,{question:M,qIdx:p,answers:a,otherTexts:c,onSelect:g,onOtherTextChange:(C,j)=>u({...c,[C]:j}),onOtherSubmit:b}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-display text-text-muted",children:[p+1," / ",r.length]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:S,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium font-display text-white hover:bg-brand-light transition-colors",children:"Submit All"}),e.jsx("button",{onClick:n,className:"rounded-lg border border-border px-4 py-2 text-sm font-display text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})]})}function Ea({question:r,qIdx:t,answers:s,otherTexts:n,onSelect:a,onOtherTextChange:d,onOtherSubmit:c}){const u=r.multiSelect||!1;return e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:te(r.question)}),e.jsxs("div",{className:"space-y-2",children:[(r.options||[]).map((p,h)=>{const g=u?(s[t]||[]).includes(h):s[t]===h;return e.jsxs("button",{onClick:()=>a(t,h,u),className:he("w-full rounded-lg border px-4 py-2.5 text-left text-sm font-display transition-colors",g?"border-brand bg-brand/10 text-text-primary":"border-border bg-surface-2 text-text-secondary hover:border-border-light"),children:[e.jsx("div",{className:"font-medium font-display",children:te(p.label)}),p.description&&e.jsx("div",{className:"mt-0.5 text-xs font-sans text-text-muted",children:te(p.description)})]},h)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n[t]||"",onChange:p=>d(t,p.target.value),placeholder:"Other...",className:"flex-1 rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm font-display text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none",onKeyDown:p=>p.key==="Enter"&&c(t)}),e.jsx("button",{onClick:()=>c(t),className:"rounded-lg border border-border px-3 py-2 text-sm font-display text-text-secondary hover:bg-surface-2 transition-colors",children:"Send"})]})]})]})}function Ma({planContent:r,description:t,onSubmit:s}){const[n,a]=l.useState(null),[d,c]=l.useState(""),u=!r||!r.trim(),p=()=>{n&&s(n,n==="no"?d:void 0)};return e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx("span",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-brand/15 text-brand-text",children:e.jsx($e,{className:"h-3 w-3",strokeWidth:2.5})}),e.jsx("span",{className:"text-sm font-semibold font-display text-text-primary",children:u?"Exit plan mode?":"Ready to code?"})]}),!u&&e.jsx("div",{className:"mb-4 max-h-64 overflow-auto rounded-lg bg-tool-card p-4 text-sm text-text-secondary",dangerouslySetInnerHTML:{__html:Ra(r)}}),e.jsx("div",{className:"space-y-2",children:u?e.jsxs(e.Fragment,{children:[e.jsx(ze,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes"}),e.jsx(ze,{selected:n==="no",onClick:()=>a("no"),label:"No"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ze,{selected:n==="yes-accept-edits",onClick:()=>a("yes-accept-edits"),label:"Yes, auto-accept edits",desc:"Approve plan and auto-accept file edits"}),e.jsx(ze,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes, manually approve edits",desc:"Approve plan but confirm each edit"}),e.jsx(ze,{selected:n==="no",onClick:()=>a("no"),label:"No, keep planning",desc:"Provide feedback to refine the plan"})]})}),n==="no"&&e.jsx("textarea",{value:d,onChange:h=>c(h.target.value),placeholder:"Tell Saluzi what to change...",className:"mt-3 w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm font-display text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none",rows:3}),e.jsx("div",{className:"mt-4",children:e.jsx("button",{onClick:p,disabled:!n,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium font-display text-white hover:bg-brand-light disabled:opacity-50 transition-colors",children:"Submit"})})]})}function ze({selected:r,onClick:t,label:s,desc:n}){return e.jsxs("button",{onClick:t,className:he("w-full rounded-lg border px-4 py-2.5 text-left text-sm font-display transition-colors",r?"border-brand bg-brand/10 text-text-primary":"border-border bg-surface-2 text-text-secondary hover:border-border-light"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:he("flex h-4 w-4 items-center justify-center rounded-full border text-[10px] transition-colors",r?"border-brand bg-brand text-white":"border-border"),children:r&&"✓"}),e.jsx("span",{className:"font-medium font-display",children:s})]}),n&&e.jsx("div",{className:"mt-0.5 pl-6 text-xs font-sans text-text-muted",children:n})]})}function Ra(r){let t=te(r);return t=t.replace(/```(\w*)\n?([\s\S]*?)```/g,(s,n,a)=>`<pre class="my-2 overflow-x-auto rounded-lg bg-tool-card p-3 font-mono text-xs">${a.trim()}</pre>`),t=t.replace(/`([^`]+)`/g,'<code class="rounded bg-tool-card px-1.5 py-0.5 font-mono text-xs">$1</code>'),t=t.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),t}function Aa({request:r,onSubmit:t}){ae();const s=Ia(r.requestedSchema),n=$a(r.requestedSchema),[a,d]=l.useState({}),c=s.length===0||n.every(u=>(a[u]??"").trim()!=="");return r.mode==="url"&&r.url?e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx(Is,{serverName:r.serverName,message:r.message}),e.jsxs("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",className:"mt-2 flex w-full items-center justify-between rounded-lg border border-border bg-surface-2 px-4 py-2.5 text-sm text-brand-text hover:bg-brand/10 transition-colors",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:r.url}),e.jsx(Cr,{className:"ml-2 h-4 w-4 flex-shrink-0"})]}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx("button",{onClick:()=>t("accept"),className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light transition-colors",children:i("elicitation.done")}),e.jsx("button",{onClick:()=>t("cancel"),className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:i("common.cancel")})]})]}):e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx(Is,{serverName:r.serverName,message:r.message}),s.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:s.map(({name:u,prop:p})=>e.jsxs("label",{className:"block",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs font-medium text-text-primary",children:u}),n.includes(u)&&e.jsx("span",{className:"text-[10px] font-medium text-warning-text",children:i("elicitation.required")})]}),p.description&&e.jsx("div",{className:"mb-1 text-xs text-text-muted",children:te(p.description)}),e.jsx("input",{type:p.type==="number"?"number":"text",value:a[u]??"",onChange:h=>d(g=>({...g,[u]:h.target.value})),className:"w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none"})]},u))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{const u={};for(const{name:p,prop:h}of s){const g=(a[p]??"").trim();g&&(u[p]=h.type==="number"?Number(g):g)}t("accept",u)},disabled:!c,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light disabled:opacity-50 transition-colors",children:i("elicitation.submit")}),e.jsx("button",{onClick:()=>t("decline"),className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:i("elicitation.decline")})]})]})}function Is({serverName:r,message:t}){return e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx("span",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-brand/15 text-brand-text",children:e.jsx(Yr,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-sm font-semibold text-text-primary",children:[i("elicitation.title")," ",e.jsx("span",{className:"font-mono text-xs text-text-muted",children:te(r)})]})]}),t&&e.jsx("div",{className:"text-sm text-text-secondary",children:te(t)})]})}function Ia(r){const t=r==null?void 0:r.properties;return!t||typeof t!="object"?[]:Object.entries(t).filter(([,s])=>s&&typeof s=="object").map(([s,n])=>({name:s,prop:n}))}function $a(r){const t=r==null?void 0:r.required;return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function Da(r){const[t,s]=l.useState([]),[n,a]=l.useState(!0),[d,c]=l.useState(null),u=l.useCallback(async()=>{a(!0),c(null);try{const g=await Yn(r);s(g)}catch(g){c(g instanceof Error?g.message:"Failed to load shares")}finally{a(!1)}},[r]);l.useEffect(()=>{u()},[u]);const p=l.useCallback(async g=>{c(null);try{const b=await zn(r,g);return await u(),b}catch(b){throw c(b instanceof Error?b.message:"Failed to create share"),b}},[r,u]),h=l.useCallback(async g=>{c(null);try{await Gn(r,g),await u()}catch(b){throw c(b instanceof Error?b.message:"Failed to revoke share"),b}},[r,u]);return{shares:t,isLoading:n,error:d,createShare:p,revokeShare:h,refresh:u}}function qa({open:r,onClose:t,sessionId:s,sessionTitle:n}){ae();const{shares:a,isLoading:d,error:c,createShare:u,revokeShare:p}=Da(s),[h,g]=l.useState("user"),[b,S]=l.useState(""),[M,C]=l.useState(""),[j,x]=l.useState("read"),[y,k]=l.useState(""),[_,A]=l.useState(!1),[T,w]=l.useState(null),[E,I]=l.useState(""),[$,v]=l.useState(!1),[F,P]=l.useState(!1);l.useEffect(()=>{r&&(g("user"),S(""),C(""),x("read"),k(""),A(!1),w(null),I(""),v(!1),P(!1))},[r]);const G=async()=>{A(!0),I(""),w(null);try{const O={grantedTo:h==="user"?{userId:b.trim()}:{teamId:M.trim()},permission:j};y.trim()&&(O.expiresAt=y.trim());const ne=await u(O);w(`${window.location.origin}/code/s/${ne.shareToken}`)}catch(O){I(O instanceof Error?O.message:"Failed to create share")}finally{A(!1)}},X=async O=>{try{await p(O)}catch{}},se=async()=>{if(!T)return;P(!1);try{if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(T),v(!0),setTimeout(()=>v(!1),2e3);return}}catch{}const O=document.createElement("textarea");O.value=T,O.style.position="fixed",O.style.opacity="0",document.body.appendChild(O),O.select();try{document.execCommand("copy"),v(!0),setTimeout(()=>v(!1),2e3)}catch{P(!0)}document.body.removeChild(O)};return e.jsx(De,{open:r,onOpenChange:O=>{O||t()},children:e.jsxs(qe,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(Pe,{children:e.jsxs(Oe,{className:"font-display text-lg font-semibold text-text-primary",children:[i("share.title"),n?`: ${n}`:""]})}),e.jsxs("div",{className:"space-y-4 min-w-0",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:i("share.grantTo")}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("button",{onClick:()=>g("user"),className:`rounded-md px-3 py-1 text-sm transition-colors ${h==="user"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:i("share.user")}),e.jsx("button",{onClick:()=>g("team"),className:`rounded-md px-3 py-1 text-sm transition-colors ${h==="team"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:i("share.team")})]}),h==="user"?e.jsx(Sr,{onSelect:S,placeholder:i("share.userIdPlaceholder"),actionLabel:i("share.selectUser")}):e.jsx("input",{type:"text",value:M,onChange:O=>C(O.target.value),placeholder:i("share.teamIdPlaceholder"),className:"w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none"}),h==="user"&&b&&e.jsxs("p",{className:"mt-1 text-xs text-text-muted",children:[i("share.selectedUser"),": ",e.jsx("span",{className:"font-mono",children:b})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:i("share.permission")}),e.jsxs("select",{value:j,onChange:O=>x(O.target.value),className:"w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary focus:border-brand focus:outline-none",children:[e.jsx("option",{value:"read",children:i("share.permissionRead")}),e.jsx("option",{value:"write",children:i("share.permissionWrite")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:i("share.expiresAt")}),e.jsx("input",{type:"datetime-local",value:y,onChange:O=>k(O.target.value),className:"w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary focus:border-brand focus:outline-none"})]}),(E||c)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:E||c}),T&&e.jsxs("div",{className:"rounded-md bg-surface-2 px-3 py-2",children:[e.jsx("p",{className:"text-sm text-text-secondary mb-1",children:i("share.linkCreated")}),e.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[e.jsx("code",{className:"min-w-0 flex-1 break-all text-xs text-text-primary",children:T}),e.jsx("button",{onClick:se,className:"shrink-0 rounded-md bg-brand px-2 py-1 text-xs text-white hover:bg-brand-light transition-colors",children:$?i("share.copied"):i("share.copy")})]}),F&&e.jsx("p",{className:"mt-1 text-xs text-status-error",children:i("share.copyFailed")})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"mb-2 text-sm font-medium text-text-secondary",children:i("share.existingShares")}),d?e.jsx("p",{className:"text-sm text-text-muted",children:i("share.loading")}):a.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:i("share.none")}):e.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto",children:a.map(O=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md bg-surface-2 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm text-text-primary",children:O.granted_to_user||O.granted_to_team||"Unknown"}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[O.permission==="write"?i("share.permissionWrite"):i("share.permissionRead"),O.expires_at?` · expires ${O.expires_at}`:""]})]}),e.jsx("button",{onClick:()=>X(O.id),className:"shrink-0 rounded-md px-2 py-1 text-xs text-status-error hover:bg-surface-3 transition-colors",children:i("share.revoke")})]},O.id))})]})]}),e.jsxs(vr,{children:[e.jsx("button",{onClick:t,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:i("common.close")}),e.jsx("button",{onClick:G,disabled:_||(h==="user"?!b.trim():!M.trim()),className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light disabled:opacity-50 transition-colors",children:_?i("common.creating"):i("share.createShare")})]})]})})}function Pa(r){const t=new Date,s=new Date(t.getTime()-1440*60*1e3),n=(c,u)=>c.getFullYear()===u.getFullYear()&&c.getMonth()===u.getMonth()&&c.getDate()===u.getDate(),a={today:[],yesterday:[],earlier:[]};for(const c of r){const u=new Date(c.modified||0);n(u,t)?a.today.push(c):n(u,s)?a.yesterday.push(c):a.earlier.push(c)}return[["today",i("resume.today")],["yesterday",i("resume.yesterday")],["earlier",i("resume.earlier")]].map(([c,u])=>({label:u,items:a[c]})).filter(c=>c.items.length>0)}function Oa(r){return r?new Date(r).toLocaleString():""}function Fa({open:r,onClose:t,adapter:s,onResume:n}){const a=ae(),[d,c]=l.useState([]),[u,p]=l.useState(!1),[h,g]=l.useState("");l.useEffect(()=>{if(!r)return;let S=!1;return p(!0),g(""),c([]),s.listResumableSessions().then(M=>{S||c(M)}).catch(M=>{S||g(M instanceof Error?M.message:String(M))}).finally(()=>{S||p(!1)}),()=>{S=!0}},[r,s]);const b=l.useMemo(()=>Pa(d),[d,a]);return e.jsx(De,{open:r,onOpenChange:S=>{S||t()},children:e.jsxs(qe,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(Pe,{children:e.jsx(Oe,{className:"font-display text-lg font-semibold text-text-primary",children:i("session.resume.title")})}),e.jsxs("div",{className:"max-h-96 min-w-0 space-y-4 overflow-y-auto",children:[u&&e.jsx("p",{className:"py-6 text-center text-sm text-text-muted",children:i("resume.loading")}),!u&&h&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:h}),!u&&!h&&d.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-text-muted",children:i("resume.empty")}),!u&&!h&&b.map(S=>e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-xs font-medium text-text-muted",children:S.label}),e.jsx("div",{className:"space-y-1",children:S.items.map(M=>e.jsxs("button",{type:"button",onClick:()=>n(M),className:"w-full rounded-md px-3 py-2 text-left transition-colors hover:bg-surface-3",children:[e.jsx("p",{className:"truncate text-sm text-text-primary",children:M.title}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[Oa(M.modified),M.gitBranch?` · ${M.gitBranch}`:""]})]},M.sessionId))})]},S.label))]}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx("button",{type:"button",onClick:t,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary transition-colors hover:bg-surface-2",children:i("common.cancel")})})]})})}const $s=["working","episodic","semantic","procedural"],Ua=["user","feedback","project","reference"];function Ka(r){switch(r){case"user":return"bg-accent/15 text-accent";case"feedback":return"bg-status-warning/15 text-status-warning";case"project":return"bg-status-active/15 text-status-active";default:return"bg-surface-3 text-text-muted"}}function La(r){try{return new Date(r).toLocaleDateString()}catch{return"—"}}function Ba({refreshTick:r,recall:t,dreaming:s,onDreamTrigger:n}){ae();const[a,d]=l.useState(null),[c,u]=l.useState("memories"),[p,h]=l.useState("personal"),[g,b]=l.useState([]),[S,M]=l.useState(!1),[C,j]=l.useState(""),[x,y]=l.useState(null),[k,_]=l.useState({}),[A,T]=l.useState(null),[w,E]=l.useState(""),[I,$]=l.useState(""),[v,F]=l.useState(null),[P,G]=l.useState(null),[X,se]=l.useState(""),[O,ne]=l.useState(null),[ke,Ne]=l.useState(!1),ue=l.useRef(null);l.useEffect(()=>{Vs().then(d).catch(()=>d(null))},[]);const Se=l.useCallback(async()=>{M(!0),j("");try{b(await Jn(p))}catch{j(i("memorySidebar.loadFailed"))}finally{M(!1)}},[p]);l.useEffect(()=>{(a==null?void 0:a.mode)==="memdir"&&Se()},[a==null?void 0:a.mode,Se,r]),l.useEffect(()=>{c!=="governance"||(a==null?void 0:a.mode)!=="memdir"||Xn().then(G).catch(()=>G(null))},[c,a==null?void 0:a.mode,r]),l.useEffect(()=>{ue.current&&clearTimeout(ue.current);const f=I.trim();if(!f){F(null);return}return ue.current=setTimeout(()=>{Zn(f).then(F).catch(()=>F([]))},300),()=>{ue.current&&clearTimeout(ue.current)}},[I]);const _e=async f=>{if(x===f){y(null);return}if(y(f),!k[f])try{const{content:K}=await xs(f);_(Z=>({...Z,[f]:K}))}catch{_(K=>({...K,[f]:i("memorySidebar.loadFailed")}))}},oe=f=>x===f?e.jsx("pre",{className:"mt-1 max-h-48 overflow-y-auto whitespace-pre-wrap rounded bg-surface-3 p-2 text-[10px] leading-relaxed text-text-secondary",children:k[f]??"…"}):null,ie=async f=>{if(k[f])E(k[f]);else try{const{content:K}=await xs(f);_(Z=>({...Z,[f]:K})),E(K)}catch{E("")}T(f)},W=async()=>{if(A)try{await or(A,w),_(f=>({...f,[A]:w})),T(null)}catch{j(i("memorySidebar.updateFailed"))}},ye=async f=>{try{await ar(f),b(K=>K.filter(Z=>Z.path!==f)),y(K=>K===f?null:K)}catch{j(i("memorySidebar.deleteFailed"))}},ge=async f=>{try{await rr(f),await Se()}catch(K){j(K instanceof Error?K.message:i("memorySidebar.promoteFailed"))}},[re,Q]=l.useState(!1),[be,Fe]=l.useState(""),[st,z]=l.useState(""),[nt,je]=l.useState("project"),[Ue,rt]=l.useState(""),[Ke,Ce]=l.useState(!1),Le=()=>{Q(!0),Fe(""),z(""),je("project"),rt("")},me=be.trim().length>0&&Ue.trim().length>0&&!Ke,bt=async()=>{if(me){Ce(!0),j("");try{await nr({scope:p,name:be.trim(),description:st.trim()||void 0,type:nt,content:Ue}),Q(!1),await Se()}catch(f){j(f instanceof Error?f.message:i("memorySidebar.createFailed"))}finally{Ce(!1)}}},at=()=>{n==null||n()},ot=l.useCallback(async()=>{const f=X.trim();if(!(!f||ke)){Ne(!0),ne(null);try{ne(await er(f,5))}catch{ne([])}finally{Ne(!1)}}},[X,ke]),le=(a==null?void 0:a.teamEnabled)===!0,Te=a==null?void 0:a.automation,Ee=le&&c==="memories"&&!I;return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center gap-1 border-b border-border px-2 py-1.5",children:[e.jsx("button",{type:"button",onClick:()=>u("memories"),className:`rounded-md px-2 py-1 text-xs font-medium ${c==="memories"?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2"}`,children:i("memorySidebar.memoriesTab")}),e.jsx("button",{type:"button",onClick:()=>u("governance"),className:`rounded-md px-2 py-1 text-xs font-medium ${c==="governance"?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2"}`,children:i("memorySidebar.governanceTab")}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[(a==null?void 0:a.mode)==="memdir"&&c==="memories"&&!I&&e.jsx("button",{type:"button",onClick:re?()=>Q(!1):Le,disabled:p==="team"&&!le,className:"rounded p-1 text-text-secondary hover:bg-surface-2 hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-50",title:i("memorySidebar.new"),children:re?e.jsx(ms,{className:"h-3 w-3"}):e.jsx(tr,{className:"h-3 w-3"})}),e.jsx(yt,{className:"h-3 w-3 text-text-muted"}),e.jsx("input",{value:I,onChange:f=>$(f.target.value),placeholder:i("memorySidebar.searchPlaceholder"),title:i("memorySidebar.searchHint"),className:"w-28 bg-transparent text-xs text-text-primary placeholder:text-text-muted focus:outline-none"})]})]}),C&&e.jsx("p",{className:"px-3 py-1 text-xs text-status-error",children:C}),Te&&Te.mode!=="normal"&&e.jsx("div",{className:"border-b border-status-warning/30 bg-status-warning/10 px-3 py-1.5 text-xs text-status-warning",children:Te.mode==="sa"?i("memorySidebar.saModeBanner"):i("memorySidebar.poorModeBanner")}),v!==null&&e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:v.length===0?e.jsx("p",{className:"py-8 text-center text-xs text-text-muted",children:i("memorySidebar.noResults")}):e.jsx("ul",{className:"space-y-1",children:v.map(f=>e.jsxs("li",{children:[e.jsxs("button",{type:"button",onClick:()=>void _e(f.path),className:"w-full rounded-md px-2 py-1.5 text-left hover:bg-surface-2",children:[e.jsx("span",{className:"block truncate text-xs font-medium text-text-primary",children:f.name}),e.jsx("ul",{className:"mt-0.5 space-y-0.5",children:f.matches.map((K,Z)=>e.jsxs("li",{className:"flex gap-1.5 text-[10px] leading-relaxed",children:[e.jsx("span",{className:"flex-shrink-0 font-mono text-text-muted",children:K.line===0?"file":`L${K.line}`}),e.jsx("span",{className:"truncate text-text-secondary",children:K.text})]},Z))})]}),oe(f.path)]},f.path))})}),v===null&&c==="memories"&&e.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[t&&t.hits.length>0&&e.jsxs("div",{className:"mb-2 rounded-md border border-brand/30 bg-brand/5 p-2",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-brand-text",children:i("memorySidebar.recallTitle")}),e.jsxs("p",{className:"mb-1 truncate text-[10px] text-text-muted",title:t.query,children:[i("memorySidebar.recallQuery"),": ",t.query]}),e.jsx("ul",{className:"space-y-0.5",children:t.hits.slice(0,5).map(f=>e.jsxs("li",{children:[e.jsxs("button",{type:"button",onClick:()=>void _e(f.path),className:"flex w-full items-center justify-between gap-2 rounded px-1 py-0.5 text-left text-xs hover:bg-surface-2",title:f.path,children:[e.jsx("span",{className:"truncate text-text-secondary",children:f.path.replace(/^team\//,"").replace(/\.md$/,"")}),f.score!==void 0&&e.jsxs("span",{className:"flex-shrink-0 text-[10px] text-text-muted",children:[(f.score*100).toFixed(0),"%"]})]}),oe(f.path)]},f.path))})]}),Ee&&e.jsx("div",{className:"mb-2 flex rounded-md bg-surface-2 p-0.5 text-xs",children:["personal","team"].map(f=>e.jsx("button",{type:"button",onClick:()=>h(f),className:`flex-1 rounded px-2 py-1 ${p===f?"bg-brand-light text-white":"text-text-muted"}`,children:f==="personal"?i("memorySidebar.personal"):i("memorySidebar.team")},f))}),p==="team"&&le&&!re&&e.jsx("p",{className:"mb-2 px-1 text-[10px] leading-relaxed text-text-muted",children:i("memorySidebar.teamHint")}),re&&e.jsxs("div",{className:"mb-2 space-y-1.5 rounded-md border border-border bg-surface-2 p-2",children:[e.jsx("input",{value:be,onChange:f=>Fe(f.target.value),placeholder:i("memorySidebar.create.namePlaceholder"),className:"w-full rounded bg-surface-3 px-2 py-1 text-xs text-text-primary placeholder:text-text-muted focus:outline-none focus:ring-1 focus:ring-brand/40"}),e.jsx("input",{value:st,onChange:f=>z(f.target.value),placeholder:i("memorySidebar.create.descriptionPlaceholder"),className:"w-full rounded bg-surface-3 px-2 py-1 text-xs text-text-primary placeholder:text-text-muted focus:outline-none focus:ring-1 focus:ring-brand/40"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("select",{value:nt,onChange:f=>je(f.target.value),className:"flex-shrink-0 rounded bg-surface-3 px-1.5 py-1 text-xs text-text-primary focus:outline-none",children:Ua.map(f=>e.jsx("option",{value:f,children:f},f))}),e.jsx("span",{className:"truncate text-[10px] text-text-muted",children:p==="team"?i("memorySidebar.team"):i("memorySidebar.personal")})]}),e.jsx("textarea",{value:Ue,onChange:f=>rt(f.target.value),placeholder:i("memorySidebar.create.contentPlaceholder"),rows:6,className:"w-full rounded bg-surface-3 p-2 text-[10px] leading-relaxed text-text-primary placeholder:text-text-muted focus:outline-none focus:ring-1 focus:ring-brand/40"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{type:"button",onClick:()=>void bt(),disabled:!me,className:"rounded bg-accent px-2 py-0.5 text-[10px] font-medium text-white hover:bg-accent/90 disabled:cursor-not-allowed disabled:opacity-50",children:Ke?"…":i("memorySidebar.new")}),e.jsx("button",{type:"button",onClick:()=>Q(!1),className:"rounded px-2 py-0.5 text-[10px] text-text-muted hover:bg-surface-3",children:i("memorySidebar.cancel")})]})]}),S?e.jsx("div",{className:"space-y-2",children:[0,1,2].map(f=>e.jsx("div",{className:"h-12 animate-pulse rounded-md bg-surface-2"},f))}):g.length===0?e.jsxs("div",{className:"py-10 text-center",children:[e.jsx(Dt,{className:"mx-auto h-6 w-6 text-text-muted/40"}),e.jsx("p",{className:"mt-2 text-xs text-text-muted",children:i("memorySidebar.empty")})]}):e.jsx("ul",{className:"space-y-1",children:g.map(f=>e.jsxs("li",{className:"group rounded-md hover:bg-surface-2",children:[e.jsxs("button",{type:"button",onClick:()=>void _e(f.path),className:"w-full px-2 py-1.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-xs font-medium text-text-primary",children:f.name}),f.type&&e.jsx("span",{className:`flex-shrink-0 rounded-full px-1.5 py-0.5 text-[9px] font-medium ${Ka(f.type)}`,children:f.type}),e.jsx("span",{className:"ml-auto flex-shrink-0 text-[9px] text-text-muted",children:La(f.mtimeMs)})]}),f.description&&e.jsx("p",{className:"mt-0.5 truncate text-[10px] text-text-muted",children:f.description})]}),e.jsxs("div",{className:"flex items-center gap-0.5 px-2 pb-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx("button",{type:"button",onClick:()=>void ie(f.path),className:"rounded p-1 text-text-secondary hover:bg-surface-3 hover:text-text-primary",title:i("memorySidebar.edit"),children:e.jsx(ms,{className:"h-3 w-3"})}),f.scope==="personal"&&le&&e.jsx("button",{type:"button",onClick:()=>void ge(f.path),className:"rounded p-1 text-text-secondary hover:bg-surface-3 hover:text-text-primary",title:i("memorySidebar.promote"),children:e.jsx(sr,{className:"h-3 w-3"})}),e.jsx("button",{type:"button",onClick:()=>void ye(f.path),className:"ml-auto rounded p-1 text-text-secondary hover:bg-status-error/10 hover:text-status-error",title:i("memorySidebar.delete"),children:e.jsx(Qs,{className:"h-3 w-3"})})]}),x===f.path&&A!==f.path&&e.jsx("pre",{className:"mx-2 mb-2 max-h-48 overflow-y-auto whitespace-pre-wrap rounded bg-surface-3 p-2 text-[10px] leading-relaxed text-text-secondary",children:k[f.path]??"…"}),x===f.path&&A===f.path&&e.jsxs("div",{className:"mx-2 mb-2",children:[e.jsx("textarea",{value:w,onChange:K=>E(K.target.value),rows:8,className:"w-full rounded bg-surface-3 p-2 text-[10px] leading-relaxed text-text-primary focus:outline-none focus:ring-1 focus:ring-brand/40"}),e.jsxs("div",{className:"mt-1 flex gap-1",children:[e.jsx("button",{type:"button",onClick:()=>void W(),className:"rounded bg-accent px-2 py-0.5 text-[10px] font-medium text-white hover:bg-accent/90",children:i("memorySidebar.save")}),e.jsx("button",{type:"button",onClick:()=>T(null),className:"rounded px-2 py-0.5 text-[10px] text-text-muted hover:bg-surface-2",children:i("memorySidebar.cancel")})]})]})]},f.path))})]}),v===null&&c==="governance"&&e.jsx("div",{className:"flex-1 overflow-y-auto p-3 text-xs",children:P?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("button",{type:"button",disabled:s||!P.automation.autoDream,onClick:at,className:"inline-flex w-full items-center justify-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-accent/90 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(Tr,{className:"h-3.5 w-3.5"}),s?i("memorySidebar.dreaming"):i("memorySidebar.dream")]}),!P.automation.autoDream&&e.jsx("p",{className:"mt-1 text-center text-[10px] text-text-muted",children:i("memorySidebar.dreamDisabled")})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-text-muted",children:i("memorySidebar.recallTest.title")}),e.jsx("p",{className:"mb-1.5 text-[10px] leading-relaxed text-text-muted",children:i("memorySidebar.recallTest.hint")}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("input",{value:X,onChange:f=>se(f.target.value),onKeyDown:f=>{f.key==="Enter"&&!f.nativeEvent.isComposing&&ot()},placeholder:i("memorySidebar.recallTest.placeholder"),className:"min-w-0 flex-1 rounded-md bg-surface-2 px-2 py-1 text-xs text-text-primary placeholder:text-text-muted focus:outline-none focus:ring-1 focus:ring-brand/40"}),e.jsx("button",{type:"button",onClick:()=>void ot(),disabled:ke||!X.trim(),className:"flex-shrink-0 rounded-md bg-accent px-2.5 py-1 text-xs font-medium text-white hover:bg-accent/90 disabled:cursor-not-allowed disabled:opacity-50",children:ke?i("memorySidebar.recallTest.running"):i("memorySidebar.recallTest.run")})]}),O!==null&&e.jsx("ul",{className:"mt-1.5 space-y-0.5 rounded-md bg-surface-2 p-2",children:O.length===0?e.jsx("li",{className:"text-[10px] text-text-muted",children:i("memorySidebar.recallTest.noResults")}):O.map(f=>e.jsxs("li",{children:[e.jsxs("button",{type:"button",onClick:()=>void _e(f.path),className:"flex w-full items-center justify-between gap-2 rounded px-1 py-0.5 text-left text-xs hover:bg-surface-3",title:f.path,children:[e.jsx("span",{className:"truncate text-text-secondary",children:f.path.replace(/^team\//,"").replace(/\.md$/,"")}),e.jsxs("span",{className:"flex-shrink-0 text-[10px] text-text-muted",children:[(f.score*100).toFixed(0),"%",f.confidence!==void 0?` · conf ${f.confidence.toFixed(2)}`:""]})]}),oe(f.path)]},f.path))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-wide text-text-muted",children:i("memorySidebar.layers")}),e.jsx("ul",{className:"space-y-1",children:$s.map(f=>{const K=P.layers[f],Z=Math.max(...$s.map(Be=>P.layers[Be]),1);return e.jsxs("li",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-16 flex-shrink-0 text-text-secondary",children:f}),e.jsx("div",{className:"h-1.5 flex-1 overflow-hidden rounded-full bg-surface-2",children:e.jsx("div",{className:"h-full rounded-full bg-brand",style:{width:`${K/Z*100}%`}})}),e.jsx("span",{className:"w-6 text-right text-text-muted",children:K})]},f)})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-wide text-text-muted",children:i("memorySidebar.health")}),e.jsxs("div",{className:"rounded-md bg-surface-2 p-2 text-[10px] text-text-secondary",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:i("memorySidebar.total")}),e.jsx("span",{children:P.health.totalMemories})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:i("memorySidebar.capacity")}),e.jsxs("span",{className:P.health.capacity.tier==="critical"?"text-status-error":P.health.capacity.tier==="warning"?"text-status-warning":"text-status-active",children:[P.health.capacity.utilizationPct.toFixed(0),"% · ",P.health.capacity.tier]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:i("memorySidebar.avgConfidence")}),e.jsx("span",{children:P.health.avgConfidence.toFixed(2)})]})]})]}),P.alerts.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-wide text-text-muted",children:[i("memorySidebar.alerts")," (",P.alerts.length,")"]}),e.jsx("ul",{className:"space-y-1 rounded-md bg-status-warning/5 p-2",children:P.alerts.slice(-8).reverse().map((f,K)=>e.jsx("li",{className:"text-[10px] leading-relaxed text-text-secondary",children:f},K))})]}),P.conflicts&&e.jsxs("div",{children:[e.jsx("p",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-wide text-status-warning",children:i("memorySidebar.conflicts")}),e.jsx("pre",{className:"max-h-40 overflow-y-auto whitespace-pre-wrap rounded-md bg-surface-2 p-2 text-[10px] leading-relaxed text-text-secondary",children:P.conflicts})]})]}):e.jsx("p",{className:"py-10 text-center text-text-muted",children:i("memorySidebar.loadFailed")})})]})}class Ha{constructor(t,s,n,a){q(this,"pending",null);this.current=t,this.apply=s,this.send=n,this.onError=a}set(t){if(t===this.current)return;const s=this.current;this.current=t,this.pending={requestId:null,previous:s},this.apply(t);try{Promise.resolve(this.send(t)).then(n=>{this.pending&&(this.pending.requestId=n)}).catch(n=>{this.rollback(s,Ds(n),"send")})}catch(n){this.rollback(s,Ds(n),"send")}}handleControlResponse(t){const s=this.pending;if(!s||s.requestId!==t.requestId)return!1;const{previous:n}=s;return this.pending=null,t.subtype==="error"&&this.rollback(n,t.error??"","response"),!0}sync(t){t!==this.current&&(this.current=t,this.apply(t),this.pending=null)}adoptExternal(t){this.pending||t!==this.current&&(this.current=t)}getCurrent(){return this.current}rollback(t,s,n){var a;this.pending=null,this.current=t,this.apply(t),s&&((a=this.onError)==null||a.call(this,s,n))}}function Ds(r){return r instanceof Error?r.message:String(r)}function pt(r){const t=l.useRef(r);t.current=r;const s=l.useRef(null);s.current||(s.current=new Ha(r.value,a=>t.current.apply(a),a=>t.current.send(a),(a,d)=>{var c,u;return(u=(c=t.current).onError)==null?void 0:u.call(c,a,d)}));const n=s.current;return l.useEffect(()=>{n.adoptExternal(r.value)}),l.useMemo(()=>({set:a=>n.set(a),handleControlResponse:a=>n.handleControlResponse(a),sync:a=>n.sync(a)}),[n])}const nn="rcs_context_usage_";function rn(){try{if(typeof localStorage<"u")return localStorage}catch{}return null}function qs(){return{totalTokens:0,rawMaxTokens:0,percentage:0}}function Wa(r){if(!r||typeof r!="object"||Array.isArray(r))return null;const t=r,{totalTokens:s,rawMaxTokens:n,percentage:a}=t;if(typeof s!="number"||typeof n!="number"||typeof a!="number")return null;const d=t.categories,c=Array.isArray(d)?d.filter(u=>!!u&&typeof u=="object"&&typeof u.name=="string").map(u=>({name:u.name,tokens:typeof u.tokens=="number"?u.tokens:0,...u.isDeferred===!0?{isDeferred:!0}:{}})):void 0;return{totalTokens:s,rawMaxTokens:n,percentage:a,...typeof t.model=="string"&&t.model?{model:t.model}:{},...c&&c.length>0?{categories:c}:{}}}function Qa(r,t=rn()){if(!t||!r)return null;try{const s=t.getItem(nn+r);return s?Wa(JSON.parse(s)):null}catch{return null}}function Va(r,t,s=rn()){if(!(!s||!r))try{s.setItem(nn+r,JSON.stringify(t))}catch{}}function Ya(r){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/acp/relay/${r}`}function za(r){const t=Ya(r),s=lr(),n=s?{proxyUrl:t,token:s}:{proxyUrl:t};return new ir(n)}const Ae=[{value:"default",labelKey:"session.mode.default",descKey:"session.mode.defaultDesc"},{value:"acceptEdits",labelKey:"session.mode.acceptEdits",descKey:"session.mode.acceptEditsDesc"},{value:"plan",labelKey:"session.mode.plan",descKey:"session.mode.planDesc"},{value:"bypassPermissions",labelKey:"session.mode.bypass",descKey:"session.mode.bypassDesc"}],Ps="rcs_permission_mode";function Ie(r){return r<1e3?String(r):r<1e6?`${(r/1e3).toFixed(1)}k`:`${(r/1e6).toFixed(1)}M`}function Ga(r){const t=Ae.findIndex(s=>s.value===r);return Ae[(t+1+Ae.length)%Ae.length].value}const gt=[{value:"off",labelKey:"session.thinking.off",descKey:"session.thinking.offDesc",label:void 0,description:void 0,tokens:0},{value:"on",labelKey:"session.thinking.on",descKey:"session.thinking.onDesc",label:void 0,description:void 0,tokens:null},{value:"8192",labelKey:void 0,descKey:void 0,label:"8k",description:"8192 tokens",tokens:8192},{value:"16384",labelKey:void 0,descKey:void 0,label:"16k",description:"16384 tokens",tokens:16384},{value:"32768",labelKey:void 0,descKey:void 0,label:"32k",description:"32768 tokens",tokens:32768}],Os="rcs_thinking_budget",$t=[{value:"auto",effort:void 0,labelKey:"session.effort.auto",descKey:"session.effort.autoDesc",label:void 0},{value:"low",effort:"low",labelKey:void 0,descKey:"session.effort.lowDesc",label:"low"},{value:"medium",effort:"medium",labelKey:void 0,descKey:"session.effort.mediumDesc",label:"medium"},{value:"high",effort:"high",labelKey:void 0,descKey:"session.effort.highDesc",label:"high"},{value:"xhigh",effort:"xhigh",labelKey:void 0,descKey:"session.effort.xhighDesc",label:"xhigh"},{value:"max",effort:"max",labelKey:void 0,descKey:"session.effort.maxDesc",label:"max"}],Fs=r=>r.labelKey?i(r.labelKey):r.label,Us=r=>r.labelKey?i(r.labelKey):r.label,Ks="rcs_effort",Ls=[{value:"normal",descKey:"session.tokenMode.normalDesc"},{value:"poor",descKey:"session.tokenMode.poorDesc"},{value:"sa",descKey:"session.tokenMode.saDesc"}],Bs="rcs_token_mode";function Ja(r){return r!=null&&r.capabilities?r.capabilities:r?{file_search:!0,clear:!0,set_max_thinking_tokens:!0,get_context_usage:!0,stop_task:!0,set_model:!0,set_permission_mode:!0,interrupt:!0,end_session:!0,mcp_management:!0,remote_settings:!0,rewind:!0,resume:!0,set_effort:!0,set_token_mode:!1,side_question:!0}:{file_search:!1,clear:!0,set_max_thinking_tokens:!0,get_context_usage:!1,stop_task:!1,set_model:!0,set_permission_mode:!0,interrupt:!0,end_session:!1,mcp_management:!1,remote_settings:!1,rewind:!1,resume:!1,set_effort:!1,set_token_mode:!1,side_question:!1}}function Xa({budget:r,onBudgetChange:t,disabled:s}){const[n,a]=l.useState(!1),d=gt.find(c=>c.value===r);return e.jsxs(Je,{open:n,onOpenChange:a,children:[e.jsx(Xe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:s,className:"flex items-center gap-1.5 rounded-lg px-2 h-7 text-xs text-text-muted hover:text-text-primary hover:bg-surface-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed font-display",title:i("session.thinking.title"),children:[e.jsx(Dt,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?Us(d):i("session.thinking.fallback")}),n?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(et,{className:"h-3 w-3"})]})}),e.jsx(tt,{className:"w-64 p-1",align:"start",children:gt.map(c=>e.jsxs("button",{type:"button",onClick:()=>{t(c.value,c.tokens),a(!1)},className:"flex w-full items-start gap-2 rounded-md px-2.5 py-2 text-left hover:bg-surface-2 transition-colors",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 flex-shrink-0 items-center justify-center",children:r===c.value&&e.jsx($e,{className:"h-3.5 w-3.5 text-brand-text"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:Us(c)}),e.jsx("div",{className:"text-xs text-text-muted",children:c.descKey?i(c.descKey):c.description})]})]},c.value))})]})}function Za({effort:r,onEffortChange:t,disabled:s}){const[n,a]=l.useState(!1),d=$t.find(c=>c.value===r);return e.jsxs(Je,{open:n,onOpenChange:a,children:[e.jsx(Xe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:s,className:"flex items-center gap-1.5 rounded-lg px-2 h-7 text-xs text-text-muted hover:text-text-primary hover:bg-surface-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed font-display",title:i("session.effort.title"),children:[e.jsx(Fr,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?Fs(d):i("session.effort.fallback")}),n?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(et,{className:"h-3 w-3"})]})}),e.jsx(tt,{className:"w-64 p-1",align:"start",children:$t.map(c=>e.jsxs("button",{type:"button",onClick:()=>{t(c.value),a(!1)},className:"flex w-full items-start gap-2 rounded-md px-2.5 py-2 text-left hover:bg-surface-2 transition-colors",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 flex-shrink-0 items-center justify-center",children:r===c.value&&e.jsx($e,{className:"h-3.5 w-3.5 text-brand-text"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:Fs(c)}),e.jsx("div",{className:"text-xs text-text-muted",children:i(c.descKey)})]})]},c.value))})]})}function eo({mode:r,onModeChange:t,disabled:s}){const[n,a]=l.useState(!1),d=Ls.find(c=>c.value===r);return e.jsxs(Je,{open:n,onOpenChange:a,children:[e.jsx(Xe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:s,className:"flex items-center gap-1.5 rounded-lg px-2 h-7 text-xs text-text-muted hover:text-text-primary hover:bg-surface-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed font-display",title:i("session.tokenMode.title"),children:[e.jsx(qr,{className:"h-3 w-3"}),e.jsx("span",{className:`max-w-24 truncate ${r!=="normal"?"font-medium text-brand-text":""}`,children:d?i(`session.tokenMode.${d.value}`):i("session.tokenMode.fallback")}),n?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(et,{className:"h-3 w-3"})]})}),e.jsx(tt,{className:"w-64 p-1",align:"start",children:Ls.map(c=>e.jsxs("button",{type:"button",onClick:()=>{t(c.value),a(!1)},className:"flex w-full items-start gap-2 rounded-md px-2.5 py-2 text-left hover:bg-surface-2 transition-colors",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 flex-shrink-0 items-center justify-center",children:r===c.value&&e.jsx($e,{className:"h-3.5 w-3.5 text-brand-text"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:i(`session.tokenMode.${c.value}`)}),e.jsx("div",{className:"text-xs text-text-muted",children:i(c.descKey)})]})]},c.value))})]})}const to=new Set(["Free space","Autocompact buffer","Compact buffer"]),Hs=["bg-brand","bg-status-active","bg-status-success","bg-violet-500","bg-amber-500","bg-pink-500","bg-teal-500"];function so({usage:r}){const t=Math.min(100,Math.max(0,r.percentage)),s=t>=80,n=(r.categories??[]).filter(u=>!u.isDeferred&&!to.has(u.name)),a=(r.categories??[]).filter(u=>u.isDeferred),d=n.reduce((u,p)=>u+p.tokens,0),c=[`${H("session.context.tooltip",{used:Ie(r.totalTokens),max:Ie(r.rawMaxTokens)})}${r.model?` · ${r.model}`:""}`,...n.slice(0,8).map(u=>`${u.name}: ${Ie(u.tokens)}`),...a.slice(0,3).map(u=>`${u.name}${i("session.context.deferredSuffix")}: ${Ie(u.tokens)}`)];return e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-text-muted font-mono",title:c.join(`
|
|
82
|
-
`),children:[e.jsx("span",{className:"relative flex h-1.5 w-16 overflow-hidden rounded-full bg-surface-3",children:n.length>0?n.map((u,p)=>e.jsx("span",{className:s&&p===0?"bg-status-warning":Hs[p%Hs.length],style:{width:`${Math.min(100,Math.max(0,d>0?u.tokens/d*t:0))}%`}},u.name)):e.jsx("span",{className:`absolute inset-y-0 left-0 rounded-full transition-all ${s?"bg-status-warning":"bg-brand/70"}`,style:{width:`${t}%`}})}),e.jsxs("span",{children:[t,"%"]})]})}function no({models:r,currentModelId:t,onSelect:s,disabled:n}){const[a,d]=l.useState(!1),c=r.find(h=>h.modelId===t)??null,u=r.length>0,p=async h=>{s(h.modelId),d(!1)};return e.jsxs(Je,{open:a,onOpenChange:u?d:void 0,children:[e.jsx(Xe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:n||!u,className:"flex items-center gap-1.5 rounded-lg px-2 h-7 text-xs text-text-muted hover:text-text-primary hover:bg-surface-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed font-display",title:i("session.model.title"),children:[e.jsx(Gs,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-32 truncate",children:(c==null?void 0:c.name)??t??i("session.model.title")}),a?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(et,{className:"h-3 w-3"})]})}),e.jsx(tt,{className:"w-72 p-0",align:"start",children:e.jsx(jr,{models:r,currentModelId:t,onSelect:p,showSearch:r.length>5})})]})}function ro({mode:r,onModeChange:t,disabled:s}){const[n,a]=l.useState(!1),d=Ae.find(c=>c.value===r);return e.jsxs(Je,{open:n,onOpenChange:a,children:[e.jsx(Xe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:s,className:"flex items-center gap-1.5 rounded-lg px-2 h-7 text-xs text-text-muted hover:text-text-primary hover:bg-surface-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed font-display",title:i("session.mode.title"),children:[e.jsx(br,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?i(d.labelKey):r}),n?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(et,{className:"h-3 w-3"})]})}),e.jsx(tt,{className:"w-64 p-1",align:"start",children:Ae.map(c=>e.jsxs("button",{type:"button",onClick:()=>{t(c.value),a(!1)},className:"flex w-full items-start gap-2 rounded-md px-2.5 py-2 text-left hover:bg-surface-2 transition-colors",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 flex-shrink-0 items-center justify-center",children:r===c.value&&e.jsx($e,{className:"h-3.5 w-3.5 text-brand-text"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:i(c.labelKey)}),e.jsx("div",{className:"text-xs text-text-muted",children:i(c.descKey)})]})]},c.value))})]})}function vo({sessionId:r,onBack:t}){var is;ae();const[s,n]=l.useState(null),[a,d]=l.useState(null),[c,u]=l.useState(""),[p,h]=l.useState(!1),[g,b]=l.useState(!1),[S,M]=l.useState(!1),[C,j]=l.useState(!1),[x,y]=l.useState(!1),[k,_]=l.useState(!1),[A,T]=l.useState(""),[w,E]=l.useState(0),I=l.useRef(null),[$,v]=l.useState({text:"",nonce:0}),[F,P]=l.useState(!1),[G,X]=l.useState(!1),[se,O]=l.useState(!1),[ne,ke]=l.useState(!1),[Ne,ue]=l.useState(0),[Se,_e]=l.useState(0),[oe,ie]=l.useState([]),[W,ye]=l.useState(!1),[ge,re]=l.useState([]),[Q,be]=l.useState(null),[Fe,st]=l.useState(()=>It()),[z,nt]=l.useState(null),[je,Ue]=l.useState(()=>localStorage.getItem(Os)||"off"),[rt,Ke]=l.useState(()=>Qa(r)),[Ce,Le]=l.useState(!0),[me,bt]=l.useState(null),[at,ot]=l.useState(null),[le,Te]=l.useState(null),[Ee,f]=l.useState([]),[K,Z]=l.useState(!1),[Be,qt]=l.useState(""),jt=l.useRef(null),[it,an]=l.useState(()=>localStorage.getItem(Ps)||"default"),[Pt,Ot]=l.useState(null),He=l.useRef(null),[Ft,Ut]=l.useState(null),We=l.useRef(null),ce=l.useRef(null),Kt=l.useRef(oe);Kt.current=oe;const lt=l.useRef(null);lt.current||(lt.current=new Ar(Ir()));const Lt=l.useRef(r);Lt.current=(s==null?void 0:s.title)||r,l.useEffect(()=>{var o;(o=lt.current)==null||o.reset()},[r]);const de=l.useCallback(o=>{Ot(o),He.current&&clearTimeout(He.current),He.current=setTimeout(()=>Ot(null),5e3)},[]),xe=l.useCallback(o=>{Ut(o),We.current&&clearTimeout(We.current),We.current=setTimeout(()=>Ut(null),5e3)},[]),ct=pt({value:it,apply:o=>{an(o);try{localStorage.setItem(Ps,o)}catch{}},send:o=>{const m=ce.current;return m?m.setPermissionMode(o):Promise.reject(new Error("adapter not ready"))},onError:(o,m)=>{console.error("[SessionDetail] set permission mode failed:",o),de(m==="send"?H("session.mode.switchFailedRequest",{message:o}):o||i("session.mode.switchFailed"))}}),wt=l.useCallback(o=>ct.set(o),[ct]),[Bt,on]=l.useState(()=>localStorage.getItem(Bs)||"normal"),dt=pt({value:Bt,apply:o=>{on(o);try{localStorage.setItem(Bs,o)}catch{}},send:o=>{const m=ce.current;return m?m.setTokenMode(o):Promise.reject(new Error("adapter not ready"))},onError:(o,m)=>{console.error("[SessionDetail] set token mode failed:",o),de(m==="send"?H("session.tokenMode.failedRequest",{message:o}):o||i("session.tokenMode.failed"))}}),vt=pt({value:je,apply:o=>{Ue(o);try{localStorage.setItem(Os,o)}catch{}},send:o=>{var R;const m=ce.current;if(!m)return Promise.reject(new Error("adapter not ready"));const N=((R=gt.find(D=>D.value===o))==null?void 0:R.tokens)??null;return m.setThinkingBudget(N)},onError:(o,m)=>{console.error("[SessionDetail] set thinking budget failed:",o),de(m==="send"?H("session.thinking.failedRequest",{message:o}):o||i("session.thinking.failed"))}}),U=l.useMemo(()=>new la(r,ie,{onStatusChange:o=>{var m;d(o),ye(o==="running"||o==="requires_action"),(m=lt.current)==null||m.onStatus(o,Lt.current)},onError:o=>{console.error("[RCSChatAdapter] error:",o)},onPermissionRequest:o=>{re(m=>m.some(N=>N.requestId===o.requestId)?m:[...m,o])},onModelsStateChange:o=>{be(o)},onSubagentUpdate:o=>{st(o)},onControlResponse:o=>{vt.handleControlResponse(o)||dt.handleControlResponse(o)||Yt.handleControlResponse(o)||ct.handleControlResponse(o)},onPermissionModeChange:o=>{ct.sync(o)},onUsageChange:o=>{bt(m=>({inputTokens:Math.max((m==null?void 0:m.inputTokens)??0,o.inputTokens),outputTokens:Math.max((m==null?void 0:m.outputTokens)??0,o.outputTokens),totalCostUsd:o.totalCostUsd??(m==null?void 0:m.totalCostUsd)??null}))},onWorkerInfoChange:o=>{nt(m=>JSON.stringify(m)===JSON.stringify(o)?m:o)},onTurnStart:o=>{ot(o)},onElicitationRequest:o=>{Te(o)}}),[r,de]);l.useEffect(()=>(ce.current=U,()=>{U.disconnect()}),[U]);const L=l.useMemo(()=>Ja(z),[z]),Ht=l.useRef(!1);l.useEffect(()=>{var N;if(!L.set_max_thinking_tokens||Ht.current)return;const o=ce.current;if(!o)return;const m=((N=gt.find(R=>R.value===je))==null?void 0:N.tokens)??null;o.setThinkingBudget(m).then(()=>{Ht.current=!0}).catch(R=>console.error("[SessionDetail] reconcile thinking budget failed:",R))},[L.set_max_thinking_tokens,je,z]);const Wt=L.stop_task?o=>{U.stopSubagent(o).then(m=>{m.ok||xe(m.error||i("session.stopTask.failed"))})}:void 0,Qt=l.useRef(!1);l.useEffect(()=>{if(!L.set_token_mode||Qt.current)return;const o=ce.current;o&&(Qt.current=!0,o.getRemoteSettings().then(m=>{const N=m==null?void 0:m.applied.tokenMode;(N==="normal"||N==="poor"||N==="sa")&&dt.sync(N)}).catch(m=>console.error("[SessionDetail] reconcile token mode failed:",m)))},[L.set_token_mode,dt]);const ln=ae(),kt=l.useMemo(()=>cr((z==null?void 0:z.commands)??[],(z==null?void 0:z.skills)??[]),[z,ln]),Me=l.useMemo(()=>dr(oe,A),[oe,A]),cn=l.useCallback(o=>vt.set(o),[vt]),[Vt,dn]=l.useState(()=>localStorage.getItem(Ks)||"auto"),Yt=pt({value:Vt,apply:o=>{dn(o);try{localStorage.setItem(Ks,o)}catch{}},send:o=>{var R;const m=ce.current;if(!m)return Promise.reject(new Error("adapter not ready"));const N=(R=$t.find(D=>D.value===o))==null?void 0:R.effort;return m.setEffort(N)},onError:(o,m)=>{console.error("[SessionDetail] set effort failed:",o),de(m==="send"?H("session.effort.failedRequest",{message:o}):o||i("session.effort.failed"))}}),Nt=l.useCallback(()=>{var o;L.get_context_usage&&((o=ce.current)==null||o.getContextUsage().then(m=>{m&&(Ke(m),Va(r,m))}).catch(()=>{}).finally(()=>Le(!1)))},[L,r]);l.useEffect(()=>{if(!L.get_context_usage)return;Nt();const o=setInterval(Nt,6e4);return()=>clearInterval(o)},[L,W,Nt]),l.useEffect(()=>{z&&!L.get_context_usage&&Le(!1)},[z,L]),l.useEffect(()=>{if(!Ce)return;const o=setTimeout(()=>Le(!1),1e4);return()=>clearTimeout(o)},[Ce]);const zt=l.useRef(se);zt.current=se,l.useEffect(()=>fe.onEvent(m=>{m.type!=="artifact_created"&&m.type!=="artifact_updated"||(zt.current&&_e(N=>N+1),ue(N=>N+1))}),[]);const[Gt,ut]=l.useState(0),Jt=l.useRef(ne);Jt.current=ne;const[Qe,Xt]=l.useState(null),[pe,un]=l.useState(!1),[St,Zt]=l.useState(0),[mn,xn]=l.useState(void 0),_t=l.useRef(pe);_t.current=pe,l.useEffect(()=>fe.onEvent(m=>{m.type==="memory_synced"&&Jt.current&&ut(N=>N+1)}),[]),l.useEffect(()=>{Vs().then(o=>Xt(o.mode)).catch(()=>Xt("sqlite"))},[]),l.useEffect(()=>fe.onEvent(m=>{var N,R;if(m.type==="memory_changed")_t.current?ut(D=>D+1):Zt(D=>D+1);else if(m.type==="memory_recall"){const D=Array.isArray((N=m.payload)==null?void 0:N.hits)?m.payload.hits:void 0;D&&xn({query:typeof((R=m.payload)==null?void 0:R.query)=="string"?m.payload.query:"",hits:D}),_t.current&&ut(Y=>Y+1)}}),[]),l.useEffect(()=>{pe&&Zt(0)},[pe]);const[Ve,pn]=l.useState("idle");l.useEffect(()=>fe.onStateChange(m=>pn(m)),[]),l.useEffect(()=>{se&&ue(0)},[se]),l.useEffect(()=>{let o=!1;async function m(){u("");try{const N=await ys(r);if(o)return;n(N),d(N.status),ft(N.status)&&U.markClosed(),ye(N.status==="running"||N.status==="requires_action")}catch(N){if(o)return;u(N instanceof Error?N.message:i("session.loadFailed"));return}try{await U.init()}catch(N){console.warn("Failed to init adapter:",N)}}return m(),()=>{o=!0}},[r,U]);const B=ft(a),es=l.useRef(a);es.current=a,l.useEffect(()=>{if(B)return;let o=!1;const N=setInterval(async()=>{try{const R=await ys(r);if(o||R.status===es.current)return;ft(R.status)&&U.markClosed(),d(R.status),ye(R.status==="running"||R.status==="requires_action")}catch{}},6e4);return()=>{o=!0,clearInterval(N)}},[r,B,U]);const V=(s==null?void 0:s.access_level)==="read",ts=rt??(Ce&&!B&&!V?qs():null),Ct=l.useCallback(()=>{ie([]),Ke(qs()),ps(r).catch(o=>{console.warn("[SessionDetail] Failed to clear session history:",o)})},[r]),Ye=l.useCallback(async(o,m)=>{const N=ce.current;if(!N||B)return;if(o.sessionId===r){ie(D=>[...D,{type:"command_output",id:`cmd-resume-${Date.now()}`,commandName:"resume",inputText:m??"/resume",title:"Resume",subtitle:i("session.resume.title"),outputText:i("session.resume.currentBlocked"),variant:"error"}]);return}const R=(D,Y="default")=>ie(we=>[...we,{type:"command_output",id:`cmd-resume-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,commandName:"resume",inputText:m??`/resume ${o.sessionId.slice(0,8)}`,title:"Resume",subtitle:i("session.resume.title"),outputText:D,variant:Y}]);R(H("session.resume.restoring",{title:o.title??""}));try{await ps(r),ie([]);const D=await N.resumeSession(o.sessionId);R(D.title?H("session.resume.restoredWithTitle",{count:D.messageCount,title:D.title}):H("session.resume.restored",{count:D.messageCount}))}catch(D){R(H("session.resume.failed",{message:D instanceof Error?D.message:String(D)}),"error")}},[B,r]),fn=l.useCallback(async()=>{if(s!=null&&s.environment_id)try{const o=await ur({environment_id:s.environment_id});window.location.href=`/code/${o.id}?resumeFrom=${r}`}catch(o){xe(H("session.createFailedWithReason",{message:o instanceof Error?o.message:String(o)}))}},[s,r,xe]),hn=l.useRef(new URLSearchParams(window.location.search).get("resumeFrom")),ss=l.useRef(!1);l.useEffect(()=>{const o=hn.current;!o||ss.current||!z||!L.resume||(ss.current=!0,window.history.replaceState({},"",window.location.pathname),Ye({sessionId:o,title:o.slice(0,8),modified:0},null))},[z,L.resume,Ye]);const Re=l.useCallback(async o=>{const m=o.text.trim(),N=o.images&&o.images.length>0||o.attachments&&o.attachments.length>0;if(!m&&!N||B)return;const R=/^\/resume(?:\s+(.*))?$/.exec(m);if(R){const Y=(R[1]??"").trim();if(!L.resume){ie(we=>[...we,{type:"user_message",id:`user-${Date.now()}`,content:m},{type:"command_output",id:`cmd-${Date.now()}`,commandName:"resume",inputText:m,title:"Resume",subtitle:i("session.resume.title"),outputText:i("session.resume.unsupported"),variant:"error"}]);return}Y?await Ye({sessionId:Y,title:Y,modified:0},m):y(!0);return}const D=await mr(m,{sessionId:r,availableCommands:kt,availableModels:(Q==null?void 0:Q.availableModels)??[],currentModel:Q?{modelId:Q.currentModelId,name:Q.currentModelId}:null,supportsImages:!0,entries:Kt.current,setModel:async Y=>{await ee(r,{type:"control_request",request:{subtype:"set_model",model:Y}}),be(we=>we&&{...we,currentModelId:Y})},onNewSession:()=>{ie([])}}).catch(()=>null);if(D){if(ht("[SessionDetail] local command result",D),"clearEntries"in D&&D.clearEntries){Ct();return}if("newSession"in D&&D.newSession){Ct();return}if("userEntry"in D){ie(Y=>[...Y,D.userEntry,D.cmdEntry]);return}}ye(!0);try{await U.sendMessage(m,o.images,o.attachments)}catch(Y){if(console.error("Send failed:",Y),Y instanceof xr&&Y.type==="session_closed"){d("archived"),U.markClosed(),xe(i("session.closedSendBlocked"));return}xe(`${i("session.sendFailed")}${Y instanceof Error?`: ${Y.message}`:""}`)}},[U,B,r,Q,kt,Ct,xe,Ye,L]),yn=l.useCallback(o=>{if(W){f(m=>[...m,o]);return}Re(o)},[W,Re]),[Tt,ns]=l.useState(!1),gn=l.useCallback(()=>{W||(ns(!0),Re({text:"/dream"}))},[W,Re]);l.useEffect(()=>{!W&&Tt&&(ns(!1),ut(o=>o+1))},[W,Tt]);const Et=l.useRef(!1);l.useEffect(()=>{if(B){f(m=>m.length>0?[]:m);return}if(W||Ee.length===0||Et.current)return;const o=Ee[0];o&&(Et.current=!0,f(m=>m.slice(1)),Re(o).finally(()=>{Et.current=!1}))},[W,Ee,Re,B]);const rs=l.useCallback((o,m)=>{if(W)return;const N=m==="edit"?i("session.rewind.confirmEdit"):i("session.rewind.confirm");window.confirm(`${N}
|
|
83
|
-
${i("session.rewind.confirmBody")}`)&&U.rewindToMessage(o.id).then(()=>{m==="edit"&&o.content&&v(R=>({text:o.content,nonce:R.nonce+1}))}).catch(R=>{console.error("[SessionDetail] rewind failed:",R),xe(H("session.rewind.failed",{message:R instanceof Error?R.message:String(R)}))})},[W,xe]),bn=l.useCallback(o=>{const m=Me.orderedMatchIds;if(m.length===0)return;const N=(o%m.length+m.length)%m.length;E(N);const R=m[N],D=document.querySelector(`[data-entry-id="${CSS.escape(R)}"]`);D==null||D.scrollIntoView({block:"center",behavior:"smooth"})},[Me]),as=l.useCallback(async()=>{try{await U.interrupt()}catch(o){console.error("Interrupt failed:",o)}finally{ye(!1)}},[U]),jn=l.useCallback(()=>{wt(Ga(it))},[wt,it]);l.useEffect(()=>()=>{He.current&&clearTimeout(He.current),We.current&&clearTimeout(We.current)},[]);const wn=l.useCallback(async()=>{if(s&&window.confirm(i("dashboard.confirmDelete").replace("{id}",s.title||s.id)))try{await fs(s.id),window.location.href="/code/"}catch(o){alert(o instanceof Error?o.message:i("dashboard.deleteFailed"))}},[s]),vn=l.useCallback(async o=>{try{await U.respondPermission(o,!0)}catch(m){console.error("Failed to approve:",m)}re(m=>m.filter(N=>N.requestId!==o))},[U]),kn=l.useCallback(async(o,m)=>{try{await U.respondPermission(o,!0,{updated_permissions:m})}catch(N){console.error("Failed to approve with rules:",N)}re(N=>N.filter(R=>R.requestId!==o))},[U]),Nn=l.useCallback(async(o,m)=>{const N=le;if(Te(null),!!N)try{await U.respondElicitation(N.requestId,o,m)}catch(R){console.error("Failed to submit elicitation:",R)}},[le,U]),Sn=l.useCallback(()=>{!s||V||(qt(s.title||""),Z(!0),setTimeout(()=>{var o,m;(o=jt.current)==null||o.focus(),(m=jt.current)==null||m.select()},0))},[s,V]),os=l.useCallback(async()=>{const o=Be.trim();if(Z(!1),!(!s||!o||o===s.title))try{const m=await pr(s.id,o);n(N=>N&&{...N,title:m.title??o})}catch(m){console.error("Rename failed:",m),alert(m instanceof Error?m.message:i("session.rename.failed"))}},[s,Be]),_n=l.useCallback(async o=>{try{await U.respondPermission(o,!1)}catch(m){console.error("Failed to reject:",m)}re(m=>m.filter(N=>N.requestId!==o))},[U]),Cn=l.useCallback(async(o,m,N)=>{try{await ee(r,{type:"permission_response",approved:!0,request_id:o,updated_input:{questions:N,answers:m}})}catch(R){console.error("Failed to submit answers:",R)}re(R=>R.filter(D=>D.requestId!==o))},[r]),Tn=l.useCallback(async(o,m,N)=>{try{m==="no"?await ee(r,{type:"permission_response",approved:!1,request_id:o,...N?{message:N}:{}}):await ee(r,{type:"permission_response",approved:!0,request_id:o,updated_permissions:[{type:"setMode",mode:{"yes-accept-edits":"acceptEdits","yes-default":"default"}[m]||"default",destination:"session"}]})}catch(R){console.error("Failed to submit plan response:",R)}re(R=>R.filter(D=>D.requestId!==o))},[r]);return c?e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(xt,{onBack:t,title:e.jsx("span",{className:"text-xs font-medium text-text-muted",children:i("session.loadFailed")})}),e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-status-error",children:c}),e.jsx("a",{href:"/code/",className:"mt-4 inline-block text-brand-text hover:underline",children:i("session.backToDashboard")})]})})]}):s?s.source==="acp"&&s.environment_id?e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx("h1",{className:"sr-only",children:s.title||s.id}),e.jsx(xt,{onBack:t,title:e.jsx("span",{className:"truncate text-xs font-semibold text-text-primary",children:s.title||s.id}),meta:e.jsx("span",{className:"rounded-full bg-brand/15 px-2 py-0.5 text-[10px] font-medium text-brand-text",children:"ACP"})}),e.jsx(oo,{sessionId:r,agentId:s.environment_id})]}):e.jsx(Ys,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx("h1",{className:"sr-only",children:s.title||s.id}),e.jsx(xt,{onBack:t,title:K?e.jsx("input",{ref:jt,value:Be,onChange:o=>qt(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),os()):o.key==="Escape"&&(o.preventDefault(),Z(!1))},onBlur:()=>void os(),maxLength:200,className:"w-full max-w-xs rounded-md border border-brand/50 bg-surface-2 px-2 py-0.5 text-xs font-semibold text-text-primary focus:outline-none focus:ring-2 focus:ring-brand/30"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex min-w-0 items-center gap-2 text-xs font-semibold text-text-primary",children:!V&&!B?e.jsx("button",{type:"button",onClick:Sn,title:i("session.rename.title"),className:"truncate text-left transition-colors hover:text-text-secondary",children:s.title||s.id}):e.jsx("span",{className:"truncate",children:s.title||s.id})}),s.visibility&&e.jsx(Mr,{visibility:s.visibility||"private",className:"hidden flex-shrink-0 text-[10px] sm:inline-flex"})]}),meta:e.jsx(e.Fragment,{children:(()=>{var N;const o=s.source==="acp"?"acp":(N=s.environment)==null?void 0:N.worker_type,m=gs(o);return e.jsx("span",{className:`hidden items-center rounded-full px-2 py-0.5 text-[10px] font-medium sm:inline-flex ${m.colorClass}`,children:m.fullLabel})})()}),actions:e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsxs("button",{onClick:()=>O(!se),className:`relative flex h-7 w-7 items-center justify-center rounded-md transition-colors ${se?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("artifacts.title"),children:[e.jsx(fr,{className:"h-3.5 w-3.5"}),Ne>0&&!se&&e.jsx("span",{className:"absolute -right-0.5 -top-0.5 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-brand px-0.5 text-[10px] font-bold text-white",children:Ne>9?"9+":Ne})]}),e.jsxs("button",{onClick:()=>{Qe==="memdir"?un(!pe):ke(!ne)},className:`relative flex h-7 w-7 items-center justify-center rounded-md transition-colors ${Qe==="memdir"?pe?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary":ne?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("memories.title"),children:[e.jsx(Dt,{className:"h-3.5 w-3.5"}),Qe==="memdir"&&St>0&&!pe&&e.jsx("span",{className:"absolute -right-0.5 -top-0.5 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-brand px-0.5 text-[10px] font-bold text-white",children:St>9?"9+":St})]}),L.side_question&&!B&&!V&&e.jsx("button",{onClick:()=>j(!C),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${C?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("session.sideQuestion.title"),children:e.jsx(Js,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>{const o=!k;_(o),o?setTimeout(()=>{var m;return(m=I.current)==null?void 0:m.focus()},0):(T(""),E(0))},className:`flex h-7 w-7 items-center justify-center rounded-md transition-colors ${k?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("session.search.title"),children:e.jsx(yt,{className:"h-3.5 w-3.5"})}),L.mcp_management&&!B&&!V&&e.jsx("button",{onClick:()=>b(!g),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${g?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("session.mcp.title"),children:e.jsx(Xs,{className:"h-3.5 w-3.5"})}),L.remote_settings&&!B&&!V&&e.jsx("button",{onClick:()=>M(!S),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${S?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("session.settings.title"),children:e.jsx(Zs,{className:"h-3.5 w-3.5"})}),!V&&(s==null?void 0:s.access_level)!=="write"&&e.jsx("button",{onClick:()=>X(!0),className:"flex h-7 w-7 items-center justify-center rounded-md text-text-muted hover:bg-surface-2 hover:text-text-secondary transition-colors",title:i("session.share"),children:e.jsx(sa,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>P(!F),className:"hidden h-7 w-7 items-center justify-center rounded-md text-text-muted hover:bg-surface-2 hover:text-text-secondary transition-colors sm:flex",title:i("session.info"),children:e.jsx(Br,{className:"h-3.5 w-3.5"})}),e.jsxs("button",{onClick:()=>h(!p),className:"ml-0.5 flex items-center gap-1 rounded-md px-2 py-1 text-xs font-semibold text-text-primary hover:bg-brand-light hover:text-white transition-colors",children:[i("session.tasks"),ge.length>0&&e.jsx("span",{className:"rounded-full bg-status-warning/15 px-1.5 py-0.5 text-[10px] font-medium text-status-warning",children:ge.length})]})]})})}),F&&e.jsx("div",{className:"flex-shrink-0 border-b bg-surface-1 py-2",children:e.jsx("div",{className:"mx-auto page-measure px-4 sm:px-8",children:e.jsxs("div",{className:"rounded-md bg-surface-2 px-3 py-2 text-xs text-text-muted space-y-1 font-mono",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:i("session.metaSession")})," ",s.id]}),s.environment_id&&e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:i("session.metaEnvironment")})," ",s.environment_id]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:i("session.metaStatus")})," ",a]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:i("session.metaWorker")})," ",gs(s.source==="acp"?"acp":(is=s.environment)==null?void 0:is.worker_type).fullLabel]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:i("session.metaCreated")})," ",Ws(s.created_at)]})]})})}),(Ve==="reconnecting"||Ve==="failed")&&e.jsxs("div",{className:`flex items-center justify-center gap-2 px-4 py-1.5 text-xs font-medium ${Ve==="failed"?"bg-status-error/10 text-status-error":"bg-status-warning/10 text-status-warning"}`,children:[e.jsx("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${Ve==="failed"?"bg-status-error":"animate-pulse bg-status-warning"}`}),Ve==="failed"?i("session.sseFailed"):i("session.sseReconnecting")]}),se&&e.jsx("div",{className:"border-b bg-surface-1 py-4",children:e.jsx("div",{className:"mx-auto page-measure px-4 sm:px-8",children:e.jsx(Er,{sessionId:r,embedded:!0,refreshTick:Se})})}),ne&&Qe!=="memdir"&&e.jsx("div",{className:"border-b bg-surface-1 py-4",children:e.jsx("div",{className:"mx-auto page-measure px-4 sm:px-8",children:e.jsx(Rr,{sessionId:r,embedded:!0,refreshTick:Gt})})}),k&&e.jsx("div",{className:"border-b bg-surface-1 py-2",children:e.jsxs("div",{className:"mx-auto flex page-measure px-4 sm:px-8 items-center gap-2",children:[e.jsx(yt,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{ref:I,value:A,onChange:o=>{T(o.target.value),E(0)},onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),bn(A&&o.shiftKey?w-1:w+1)):o.key==="Escape"&&(o.preventDefault(),_(!1),T(""))},placeholder:i("session.search.placeholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"}),A.trim()&&e.jsx("span",{className:"flex-shrink-0 font-mono text-[10px] text-text-muted",children:Me.orderedMatchIds.length===0?i("session.search.noResults"):`${w+1}/${Me.orderedMatchIds.length}`})]})}),Qe==="memdir"?e.jsxs("div",{className:"flex min-h-0 flex-1",children:[pe&&e.jsx("aside",{className:"w-72 flex-shrink-0 overflow-y-auto border-r border-border bg-surface-1","data-testid":"memory-sidebar",children:e.jsx(Ba,{refreshTick:Gt,recall:mn,dreaming:W&&Tt,onDreamTrigger:gn})}),e.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:e.jsx(hs,{entries:oe,isLoading:W,turnStartedAt:at,emptyTitle:i("session.emptyTitle"),emptyDescription:i("session.emptyDescription"),searchMatchIds:A.trim()?Me.matchIds:void 0,onRewindEntry:L.rewind&&!B&&!V&&!W?(o,m)=>rs(o,m):void 0})})]}):e.jsx(hs,{entries:oe,isLoading:W,turnStartedAt:at,emptyTitle:i("session.emptyTitle"),emptyDescription:i("session.emptyDescription"),searchMatchIds:A.trim()?Me.matchIds:void 0,onRewindEntry:L.rewind&&!B&&!V&&!W?(o,m)=>rs(o,m):void 0}),e.jsx(xa,{state:Fe,onStopTask:Wt}),ge.length>0&&e.jsx("div",{className:"border-t bg-surface-1 py-3",children:e.jsx("div",{className:"mx-auto page-measure px-4 sm:px-8 space-y-3",children:ge.map(o=>e.jsx(ao,{request:o,onApprove:()=>vn(o.requestId),onApproveAlways:o.suggestions&&o.suggestions.length>0?()=>kn(o.requestId,o.suggestions??[]):void 0,onReject:()=>_n(o.requestId),onSubmitAnswers:Cn,onSubmitPlan:Tn},o.requestId))})}),le&&e.jsx("div",{className:"border-t bg-surface-1 py-3",children:e.jsx("div",{className:"mx-auto page-measure px-4 sm:px-8",children:e.jsx(Aa,{request:le,onSubmit:Nn})})}),Ft&&e.jsx("div",{className:"mx-auto page-measure w-full px-4 sm:px-8 pb-1",children:e.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 px-3 py-1.5 text-xs text-red-700 dark:text-red-300",children:Ft})}),Pt&&e.jsx("div",{className:"mx-auto page-measure w-full px-4 sm:px-8 pb-1",children:e.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 px-3 py-1.5 text-xs text-red-700 dark:text-red-300",children:Pt})}),e.jsxs("div",{className:"page-measure mx-auto w-full px-4 sm:px-8 pb-1 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ro,{mode:it,onModeChange:wt,disabled:B||V}),e.jsx(no,{models:(Q==null?void 0:Q.availableModels)??[],currentModelId:(Q==null?void 0:Q.currentModelId)??null,onSelect:o=>{ee(r,{type:"control_request",request:{subtype:"set_model",model:o}}),be(m=>m&&{...m,currentModelId:o})},disabled:B||V}),L.set_max_thinking_tokens&&e.jsx(Xa,{budget:je,onBudgetChange:cn,disabled:B||V}),L.set_effort&&e.jsx(Za,{effort:Vt,onEffortChange:o=>Yt.set(o),disabled:B||V}),L.set_token_mode&&e.jsx(eo,{mode:Bt,onModeChange:o=>dt.set(o),disabled:B||V})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[ts&&e.jsx(so,{usage:ts}),me&&e.jsxs("span",{className:"text-[10px] text-text-muted font-mono",title:i("session.usage.total"),children:[Ie(me.inputTokens)," in / ",Ie(me.outputTokens)," out",me.totalCostUsd!=null&&` · $${me.totalCostUsd.toFixed(2)}`]})]})]}),B&&(s==null?void 0:s.environment_id)&&e.jsx("div",{className:"mx-auto w-full page-measure px-4 pb-2 sm:px-8",children:e.jsx("button",{type:"button",onClick:()=>void fn(),className:"w-full rounded-lg border border-border bg-surface-1 px-4 py-2.5 text-sm text-text-secondary transition-colors hover:bg-surface-2 hover:text-text-primary",children:i("session.resumeInNew")})}),e.jsx(hr,{onSubmit:yn,isLoading:W,onInterrupt:as,onCycleMode:jn,disabled:B||V,placeholder:B?i("session.closed"):V?i("session.readOnly"):i("session.inputPlaceholder"),supportsAttachments:!0,commands:kt,queueWhileLoading:!0,queuedCount:Ee.length,onDequeue:o=>f(m=>m.filter((N,R)=>R!==o)),onSearchFiles:L.file_search?o=>U.searchFiles(o):void 0,historyKey:r,draftOverride:$}),g&&e.jsx(va,{onClose:()=>b(!1),fetchServers:()=>U.getMcpServers(),onToggle:(o,m)=>U.toggleMcpServer(o,m),onReconnect:o=>U.reconnectMcpServer(o)}),S&&e.jsx(Sa,{onClose:()=>M(!1),fetchSettings:()=>U.getRemoteSettings(),onApply:o=>U.applyFlagSettings(o)}),C&&e.jsx(_a,{onClose:()=>j(!1),onAsk:o=>U.askSideQuestion(o)}),p&&s&&e.jsx(ha,{onClose:()=>h(!1),session:s,liveStatus:a,pendingPermissions:ge,subagentState:Fe,onStopTask:Wt,onInterrupt:as,onDelete:wn,onEndSession:L.end_session&&!B&&!V?async()=>{await U.endSession("ended from web"),await fs(s.id),window.location.href="/code/"}:void 0}),e.jsx(qa,{open:G,onClose:()=>X(!1),sessionId:s.id,sessionTitle:s.title||void 0}),e.jsx(Fa,{open:x,onClose:()=>y(!1),adapter:U,onResume:o=>{y(!1),Ye(o,null)}})]})}):e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(xt,{onBack:t,title:e.jsx("span",{className:"h-3.5 w-40 animate-pulse rounded bg-surface-2"})}),e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx("div",{className:"text-text-muted",children:i("session.loading")})})]})}function ao({request:r,onApprove:t,onApproveAlways:s,onReject:n,onSubmitAnswers:a,onSubmitPlan:d}){const c=r.toolName,u=r.toolInput,p=r.description||"";if(c==="AskUserQuestion"){const h=u.questions||[];return e.jsx(Ta,{requestId:r.requestId,questions:h,description:p,onSubmit:g=>a(r.requestId,g,h),onSkip:n})}if(c==="ExitPlanMode"){const h=u.plan||"";return e.jsx(Ma,{requestId:r.requestId,planContent:h,description:p,onSubmit:(g,b)=>d(r.requestId,g,b)})}return e.jsx(Ca,{requestId:r.requestId,toolName:c,toolInput:u,description:p,suggestions:r.suggestions,onApprove:t,onApproveAlways:s,onReject:n})}function oo({sessionId:r,agentId:t}){const[s,n]=l.useState(null),[a,d]=l.useState("disconnected"),[c,u]=l.useState(null),p=l.useRef(null);return l.useEffect(()=>{const h=za(t);return h.setConnectionStateHandler((g,b)=>{d(g),u(b||null)}),p.current=h,n(h),h.connect().catch(g=>{g instanceof yr||(u(g.message),d("error"))}),()=>{h.disconnect(),p.current=null,n(null),d("disconnected")}},[t]),e.jsx(Ys,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[c&&a==="error"&&e.jsx("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm border-b",children:c}),a==="connecting"&&e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin h-8 w-8 border-2 border-brand border-t-transparent rounded-full mx-auto mb-3"}),e.jsx("p",{className:"text-text-muted text-sm",children:i("session.connectingAgent")})]})}),a==="error"&&!s&&e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"font-medium mb-1",children:i("session.connectionFailed")}),e.jsx("p",{className:"text-text-muted text-sm",children:c})]})}),s&&a==="connected"&&e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(gr,{client:s,agentId:t})})]})})}export{vo as SessionDetail};
|
|
80
|
+
${S}`})}}const p=u.length===1&&u[0].type==="text"?u[0].text||t:u.length>0?u:t;try{const g=ve();this.postedUserUuids.add(g);const b=await $n(this.sessionId,{type:"user",uuid:g,content:t,message:{content:p}}),S=(h=b==null?void 0:b.event)==null?void 0:h.id;S&&this.setEntries(M=>M.map(C=>C.type==="user_message"&&C.id===c.id?{...C,id:S}:C))}catch(g){throw this.setEntries(b=>b.filter(S=>!(S.type==="user_message"&&S.id===c.id))),g}}async respondPermission(t,s,n){await ee(this.sessionId,{type:"permission_response",approved:s,request_id:t,...n});const a=this.pendingPermissionToolIds.get(t);this.pendingPermissionToolIds.delete(t),a&&!s&&this.pendingToolCallIds.delete(a),this.setEntries(d=>d.map(c=>{var u;return c.type!=="tool_call"||((u=c.toolCall.permissionRequest)==null?void 0:u.requestId)!==t?c:{type:"tool_call",toolCall:{...c.toolCall,status:s?"running":"rejected",permissionRequest:void 0}}}))}async interrupt(){this.finalizePendingToolCalls("canceled"),await In(this.sessionId)}async setPermissionMode(t){const s=ve();return await ee(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_permission_mode",mode:t}}),s}async controlRoundTrip(t,s=8e3){const n=ve(),a=new Promise(c=>{this.pendingControlRequests.set(n,c)}),d=setTimeout(()=>{const c=this.pendingControlRequests.get(n);c&&(this.pendingControlRequests.delete(n),c({data:null,error:"timeout"}))},s);try{return await ee(this.sessionId,{type:"control_request",request_id:n,request:t}),await a}catch(c){throw this.pendingControlRequests.delete(n),c}finally{clearTimeout(d)}}async searchFiles(t,s=20){const n=await this.controlRoundTrip({subtype:"file_search",query:t,limit:s});try{if(!n.data||!Array.isArray(n.data.suggestions))return[];const a=[];for(const d of n.data.suggestions)d&&typeof d=="object"&&typeof d.path=="string"&&a.push(d.path);return a}catch{return[]}}async respondElicitation(t,s,n){await ee(this.sessionId,{type:"permission_response",approved:s==="accept",request_id:t,response:{subtype:"success",request_id:t,response:{action:s,...n?{content:n}:{}}}})}async askSideQuestion(t){const s=await this.controlRoundTrip({subtype:"side_question",question:t},12e4);if(s.error||!s.data)return null;const n=s.data.response;return typeof n=="string"?n:null}async listResumableSessions(){const t=await this.controlRoundTrip({subtype:"list_sessions"});if(!t.data||!Array.isArray(t.data.sessions))throw new Error(t.error??"list_sessions failed");const s=[];for(const n of t.data.sessions){if(!n||typeof n!="object")continue;const a=n;typeof a.session_id!="string"||!a.session_id||s.push({sessionId:a.session_id,title:typeof a.title=="string"&&a.title?a.title:a.session_id.slice(0,8),modified:typeof a.modified=="number"?a.modified:0,...typeof a.created_at=="number"?{createdAt:a.created_at}:{},...typeof a.git_branch=="string"&&a.git_branch?{gitBranch:a.git_branch}:{}})}return s}async resumeSession(t){const s=await this.controlRoundTrip({subtype:"resume_session",session_id:t},3e4);if(!s.data)throw new Error(s.error??"resume_session failed");return{title:typeof s.data.title=="string"?s.data.title:null,messageCount:typeof s.data.message_count=="number"?s.data.message_count:0}}async setEffort(t){const s=ve();return await ee(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_effort",...t?{effort:t}:{effort:null}}}),s}async setTokenMode(t){const s=ve();return await ee(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_token_mode",mode:t}}),s}async setThinkingBudget(t){const s=ve();return await ee(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_max_thinking_tokens",max_thinking_tokens:t}}),s}async getContextUsage(){const t=await this.controlRoundTrip({subtype:"get_context_usage"});try{if(!t.data)return null;const s=t.data.totalTokens,n=t.data.rawMaxTokens,a=t.data.percentage;if(typeof s!="number"||typeof n!="number")return null;const d=t.data.categories,c=Array.isArray(d)?d.filter(u=>!!u&&typeof u=="object"&&typeof u.name=="string").map(u=>({name:u.name,tokens:typeof u.tokens=="number"?u.tokens:0,...u.isDeferred===!0?{isDeferred:!0}:{}})):void 0;return{totalTokens:s,rawMaxTokens:n,percentage:typeof a=="number"?a:0,...typeof t.data.model=="string"&&t.data.model?{model:t.data.model}:{},...c&&c.length>0?{categories:c}:{}}}catch{return null}}async stopSubagent(t){const s=await this.controlRoundTrip({subtype:"stop_task",task_id:t});try{return s.error?{ok:!1,error:s.error==="timeout"?i("adapter.stopTimeout"):s.error}:{ok:!0}}catch{return{ok:!1,error:i("adapter.stopFailed")}}}async getMcpServers(){var a;const s=(a=(await this.controlRoundTrip({subtype:"mcp_status"})).data)==null?void 0:a.mcpServers;if(!Array.isArray(s))return[];const n=[];for(const d of s){if(!d||typeof d!="object")continue;const c=d;if(typeof c.name!="string"||!c.name)continue;const u=c.status;if(u!=="connected"&&u!=="failed"&&u!=="needs-auth"&&u!=="pending"&&u!=="disabled")continue;const p=c.serverInfo,h=c.config;n.push({name:c.name,status:u,...p&&typeof p.name=="string"&&typeof p.version=="string"?{serverInfo:{name:p.name,version:p.version}}:{},...typeof c.error=="string"&&c.error?{error:c.error}:{},...typeof(h==null?void 0:h.url)=="string"&&h.url?{url:h.url}:{},...Array.isArray(c.tools)?{toolCount:c.tools.length}:{}})}return n}async toggleMcpServer(t,s){const n=await this.controlRoundTrip({subtype:"mcp_toggle",serverName:t,enabled:s},15e3);return n.error?{ok:!1,error:n.error==="timeout"?i("adapter.requestTimeout"):n.error}:{ok:!0}}async reconnectMcpServer(t){const s=await this.controlRoundTrip({subtype:"mcp_reconnect",serverName:t},2e4);return s.error?{ok:!1,error:s.error==="timeout"?i("adapter.requestTimeout"):s.error}:{ok:!0}}async getRemoteSettings(){const s=(await this.controlRoundTrip({subtype:"get_settings"})).data;if(!s)return null;const n=s.applied,a=s.effective&&typeof s.effective=="object"&&!Array.isArray(s.effective)?s.effective:{},d=s.sources,c=[];if(Array.isArray(d))for(const u of d){if(!u||typeof u!="object")continue;const p=u;typeof p.source=="string"&&c.push({source:p.source,settings:p.settings&&typeof p.settings=="object"&&!Array.isArray(p.settings)?p.settings:{}})}return{applied:{model:typeof(n==null?void 0:n.model)=="string"?n.model:null,effort:typeof(n==null?void 0:n.effort)=="string"?n.effort:null,tokenMode:typeof(n==null?void 0:n.tokenMode)=="string"?n.tokenMode:null},effective:a,sources:c}}async applyFlagSettings(t){const s=await this.controlRoundTrip({subtype:"apply_flag_settings",settings:t},15e3);return s.error?{ok:!1,error:s.error==="timeout"?i("adapter.requestTimeout"):s.error}:{ok:!0}}async rewindToMessage(t){await Dn(this.sessionId,t)}async endSession(t){await ee(this.sessionId,{type:"control_request",request_id:ve(),request:{subtype:"end_session",...t?{reason:t}:{}}})}}function ca(r){return r<1024?`${r} B`:r<1024*1024?`${(r/1024).toFixed(1)} KB`:`${(r/(1024*1024)).toFixed(1)} MB`}function mt({onBack:r,title:t,meta:s,actions:n}){return ae(),e.jsx("div",{className:"flex-shrink-0 border-b border-nav-rule bg-surface-1/80 backdrop-blur-md",children:e.jsxs("div",{className:"mx-auto flex h-12 w-full page-measure items-center gap-2 px-4 sm:px-8",children:[e.jsx("button",{type:"button",onClick:r,"aria-label":i("nav.dashboard"),title:i("nav.dashboard"),className:"-mx-2 flex-shrink-0 rounded-md px-2 py-1 text-xs text-text-muted transition hover:-translate-x-0.5 hover:bg-surface-2 hover:text-text-primary",children:i("nav.dashboard")}),e.jsx("span",{className:"mx-1 h-4 w-px flex-shrink-0 bg-border","aria-hidden":"true"}),e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[t,s&&e.jsx("div",{className:"flex flex-shrink-0 items-center gap-2",children:s})]}),n&&e.jsx("div",{className:"flex flex-shrink-0 items-center gap-0.5",children:n}),e.jsx("span",{className:"mx-1 h-4 w-px flex-shrink-0 bg-border","aria-hidden":"true"}),e.jsx(Pn,{}),e.jsx(On,{onSettingsClick:()=>{window.history.pushState(null,"","/settings"),window.dispatchEvent(new PopStateEvent("popstate"))}})]})})}const Es="rcs:subagent-panel:collapsed";function da(r){if(r<1e3)return"0s";const t=Math.floor(r/1e3);if(t<60)return`${t}s`;const s=Math.floor(t/60),n=t%60;if(s<60)return n?`${s}m${n}s`:`${s}m`;const a=Math.floor(s/60),d=s%60;return d?`${a}h${d}m`:`${a}h`}function ua(r){return r===void 0||r<=0?"":r<1e3?`${r}`:r<1e6?`${(r/1e3).toFixed(r<1e4?1:0)}k`:`${(r/1e6).toFixed(1)}M`}function ma({status:r}){return r==="running"?e.jsx(Ge,{className:"h-3 w-3 animate-spin text-brand-text"}):r==="completed"?e.jsx(Gr,{className:"h-3 w-3 text-status-success"}):r==="failed"||r==="stopped"?e.jsx(Fn,{className:"h-3 w-3 text-status-error"}):null}function tn({task:r,onStopTask:t,fullText:s}){const n=r.status==="running",a=n?r.durationMs??Date.now()-r.startTime:(r.endTime??Date.now())-r.startTime,d=ua(r.tokenCount),c=r.toolUseCount!==void 0&&r.toolUseCount>0?`${r.toolUseCount} tool${r.toolUseCount>1?"s":""}`:"",u=r.summary||r.description||"(no description)";return e.jsxs("div",{className:"group/task flex items-start gap-2 rounded-md bg-surface-2 px-2.5 py-1.5 text-xs",children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0",children:e.jsx(ma,{status:r.status})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"truncate font-medium text-text-primary",children:r.name}),e.jsx("span",{className:"flex-shrink-0 font-mono text-text-muted",children:da(a)})]}),e.jsx("div",{className:`mt-0.5 text-text-secondary ${s?"line-clamp-2 break-words":"truncate"}`,children:u}),(d||c||r.lastToolName)&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-x-2 overflow-hidden whitespace-nowrap font-mono text-[10px] text-text-muted",children:[d&&e.jsxs("span",{className:"flex-shrink-0",children:["↕ ",d," tok"]}),c&&e.jsxs("span",{className:"flex-shrink-0",children:["· ",c]}),r.lastToolName&&e.jsxs("span",{className:"min-w-0 truncate",children:["· last: ",r.lastToolName]})]}),!n&&r.finalSummary&&e.jsx("div",{className:"mt-1 line-clamp-2 rounded bg-status-success/10 px-1.5 py-0.5 text-[10px] text-status-success",children:r.finalSummary})]}),n&&t&&e.jsx("button",{type:"button",onClick:()=>t(r.taskId),title:i("subagent.stop"),className:"mt-0.5 flex-shrink-0 rounded p-0.5 text-text-muted opacity-0 transition-opacity hover:bg-status-error/10 hover:text-status-error focus:opacity-100 group-hover/task:opacity-100",children:e.jsx(Hs,{className:"h-3.5 w-3.5"})})]})}function xa({state:r,onStopTask:t}){const[s,n]=l.useState(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Es)==="1"}catch{return!1}}),a=()=>{n(b=>{const S=!b;try{window.localStorage.setItem(Es,S?"1":"0")}catch{}return S})},d=Object.values(r.tasks).some(b=>b.status==="running"),c=Object.values(r.tasks).some(b=>b.status!=="running"&&b.evictAfter!==void 0),[,u]=l.useState(0);l.useEffect(()=>{if(!d&&!c)return;const b=setInterval(()=>{u(S=>S+1)},1e3);return()=>clearInterval(b)},[d,c]);const p=en(r);if(p.length===0)return null;const h=p.filter(b=>b.status==="running").length,g=h>0?`${h} running`:`${p.length} recent`;return e.jsx("section",{"aria-label":"Subagents",className:"border-t border-border bg-surface-1 px-4 py-2",children:e.jsxs("div",{className:"mx-auto max-w-3xl space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:a,"aria-expanded":!s,"aria-controls":"subagent-list",className:"flex w-full items-center justify-between text-[10px] font-medium uppercase tracking-wide text-text-muted hover:text-text-secondary transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(zs,{className:`h-3 w-3 transition-transform ${s?"":"rotate-90"}`}),e.jsx("span",{children:"Subagents"})]}),e.jsx("span",{children:g})]}),!s&&e.jsx("div",{id:"subagent-list",className:"space-y-1.5",children:p.map(b=>e.jsx(tn,{task:b,onStopTask:t},b.taskId))})]})})}function pa(r){if(!r)return"never";const t=Math.max(0,Date.now()-r);return t<5e3?"just now":t<6e4?`${Math.floor(t/1e3)}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:`${Math.floor(t/36e5)}h ago`}function fa(r){return r?Date.now()-r<6e4:!1}function ha({onClose:r,session:t,liveStatus:s,pendingPermissions:n,onInterrupt:a,onDelete:d,subagentState:c,onStopTask:u,onEndSession:p}){const[h,g]=l.useState(!1),b=async()=>{await navigator.clipboard.writeText(t.id),g(!0),setTimeout(()=>g(!1),1500)},[S,M]=l.useState(!1),C=async()=>{if(!(!p||S)&&window.confirm(i("task.endConfirm"))){M(!0);try{await p(),r()}catch{M(!1)}}},j=n.length,x=t.worker,y=t.work_item,k=t.environment;return e.jsx(ke,{open:!0,onOpenChange:_=>{_||r()},children:e.jsxs(Ne,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-96 h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md overflow-y-auto",children:[e.jsx(Pe,{children:e.jsx(Se,{className:"font-display font-semibold text-text-primary",children:"Session Ops"})}),e.jsxs("div",{className:"mt-3 space-y-5 text-sm",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-text-muted",children:[e.jsx(wr,{className:"h-3.5 w-3.5"}),"Status"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Un,{status:s||t.status||"unknown"}),e.jsx("span",{className:"text-xs text-text-muted",children:x&&(fa(x.last_heartbeat_at)?"· worker online":"· worker offline")})]}),e.jsxs("dl",{className:"space-y-1 text-xs text-text-muted",children:[x&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(ds,{className:"h-3 w-3"}),"Heartbeat"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:pa(x.last_heartbeat_at)})]}),k&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(Gs,{className:"h-3 w-3"}),"Environment"]}),e.jsx("dd",{className:"truncate text-text-secondary",children:k.machine_name||k.id})]}),t.created_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(ds,{className:"h-3 w-3"}),"Created"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:Ws(t.created_at)})]})]})]}),e.jsx(ba,{state:c,onStopTask:u}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-text-muted",children:[e.jsx(Ge,{className:"h-3.5 w-3.5"}),"Pending Actions"]}),j>0?e.jsxs("div",{className:"rounded-md bg-status-warning/10 px-3 py-2 text-xs text-status-warning",children:[j," permission request",j>1?"s":""," awaiting your approval"]}):e.jsx("p",{className:"text-xs text-text-muted",children:"No pending actions"})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-text-muted",children:[e.jsx(Zr,{className:"h-3.5 w-3.5"}),"Quick Actions"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:a,className:"flex-1 rounded-md border border-border px-3 py-1.5 text-xs text-text-secondary hover:bg-surface-2 transition-colors",children:"Interrupt"}),p&&e.jsx("button",{onClick:C,disabled:S,className:"flex-1 rounded-md border border-status-error/30 px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:i("task.endHint"),children:S?"Ending…":"End session"}),e.jsxs("button",{onClick:d,className:"flex-1 rounded-md border border-status-error/30 px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 transition-colors",children:[e.jsx(Qs,{className:"mr-1 inline h-3 w-3"}),"Delete"]})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-text-muted",children:[e.jsx(Kr,{className:"h-3.5 w-3.5"}),"Session Info"]}),e.jsxs("dl",{className:"space-y-1 text-xs text-text-muted",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("dt",{children:"Session ID"}),e.jsxs("dd",{className:"flex items-center gap-1 min-w-0",children:[e.jsx("code",{className:"break-all font-mono text-text-secondary text-right",children:t.id}),e.jsx("button",{onClick:b,className:"text-text-muted hover:text-text-primary transition-colors flex-shrink-0",title:"Copy session id",children:h?"✓":"⧉"})]})]}),y&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Spawn mode"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:y.spawn_mode??"default"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Work state"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:y.state})]})]}),t.source&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Source"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:t.source})]}),k&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Worker type"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:k.worker_type})]})]})]})]})]})})}const ya={in_process_teammate:"task.type.teammates",local_bash:"task.type.shells",monitor_mcp:"task.type.monitors",remote_agent:"task.type.remoteAgents",local_agent:"task.type.localAgents"},ga=new Set(["dream"]);function ba({state:r,onStopTask:t}){const s=Object.values(r.tasks).some(p=>p.status==="running"),n=Object.values(r.tasks).some(p=>p.status!=="running"&&p.evictAfter!==void 0),[,a]=l.useState(0);l.useEffect(()=>{if(!s&&!n)return;const p=setInterval(()=>{a(h=>h+1)},1e3);return()=>clearInterval(p)},[s,n]);const d=en(r),c=d.filter(p=>p.status==="running").length,u=d.length-c;return e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium uppercase tracking-wide text-text-muted",children:[e.jsx(Wr,{className:"h-3.5 w-3.5"}),i("task.backgroundTasks")]}),d.length>0&&e.jsx("span",{className:"font-mono text-[10px] text-text-muted",children:c>0&&u>0?H("task.mixedCount",{running:c,recent:u}):c>0?H("task.runningCount",{count:c}):H("task.recentCount",{count:d.length})})]}),d.length===0?e.jsx("p",{className:"text-xs text-text-muted",children:i("task.noBackgroundTasks")}):e.jsx("div",{className:"max-h-[38vh] space-y-2 overflow-y-auto overscroll-contain pr-1",children:aa(d).map(p=>{const h=!ga.has(p.taskType),g=ya[p.taskType]??"task.type.tasks";return e.jsxs("div",{className:"space-y-1",children:[h&&e.jsxs("div",{className:"pl-1 text-[10px] font-medium uppercase tracking-wide text-text-muted/80",children:[i(g)," (",p.tasks.length,")"]}),p.tasks.map(b=>e.jsx(tn,{task:b,onStopTask:t,fullText:!0},b.taskId))]},p.taskType)})})]})}const ja={connected:"bg-status-success/15 text-status-success",failed:"bg-status-error/15 text-status-error","needs-auth":"bg-status-warning/15 text-status-warning",pending:"bg-status-active/15 text-status-active",disabled:"bg-surface-3 text-text-muted"},wa={connected:"mcp.status.connected",failed:"mcp.status.failed","needs-auth":"mcp.status.needsAuth",pending:"mcp.status.pending",disabled:"mcp.status.disabled"};function va({onClose:r,fetchServers:t,onToggle:s,onReconnect:n}){ae();const[a,d]=l.useState(null),[c,u]=l.useState(null),[p,h]=l.useState(null),[g,b]=l.useState(null),S=l.useCallback(async()=>{h(null),b(null);try{const j=await t();d(j),u(null)}catch(j){ft("[McpPanel] fetch failed",j),u(i("mcp.loadFailed"))}},[t]);l.useEffect(()=>{S()},[S]);const M=async j=>{const x=j.status==="disabled";h(`toggle:${j.name}`),b(null);try{const y=await s(j.name,x);y.ok||b(y.error||i("mcp.toggleFailed"))}finally{await S()}},C=async j=>{h(`reconnect:${j.name}`),b(null);try{const x=await n(j.name);x.ok||b(x.error||i("mcp.reconnectFailed"))}finally{await S()}};return e.jsx(ke,{open:!0,onOpenChange:j=>{j||r()},children:e.jsxs(Ne,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-96 h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md overflow-y-auto",children:[e.jsx(Pe,{children:e.jsxs(Se,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(Xs,{className:"h-4 w-4"}),i("session.mcp.title")]})}),e.jsxs("div",{className:"mt-3 space-y-3 text-sm",children:[g&&e.jsx("div",{className:"rounded-md bg-status-error/10 px-3 py-2 text-xs text-status-error",children:g}),a===null&&!c&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(Ge,{className:"h-3.5 w-3.5 animate-spin"}),i("mcp.loading")]}),c&&e.jsx("p",{className:"text-xs text-status-error",children:c}),a!==null&&a.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:i("mcp.empty")}),a==null?void 0:a.map(j=>{const x=p===`toggle:${j.name}`,y=p===`reconnect:${j.name}`,k=j.status==="disabled";return e.jsx("div",{className:"rounded-lg border border-border bg-surface-2 px-3 py-2.5",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-2",children:[e.jsx("span",{className:"truncate text-sm font-medium text-text-primary",children:j.name}),e.jsx("span",{className:`flex-shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium ${ja[j.status]}`,children:i(wa[j.status])})]}),e.jsxs("div",{className:"mt-0.5 truncate text-xs text-text-muted",children:[j.serverInfo?`${j.serverInfo.name} v${j.serverInfo.version}`:j.url||"stdio",j.toolCount!==void 0&&` · ${H("mcp.toolCount",{n:j.toolCount})}`]}),j.error&&e.jsx("div",{className:"mt-1 truncate text-xs text-status-error",title:j.error,children:j.error})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>void C(j),disabled:y||k,className:"rounded-md p-1.5 text-text-muted hover:bg-surface-3 hover:text-text-primary transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:i("mcp.reconnect"),children:e.jsx(kr,{className:`h-3.5 w-3.5 ${y?"animate-spin":""}`})}),e.jsx("button",{type:"button",role:"switch","aria-checked":!k,onClick:()=>void M(j),disabled:x,className:`relative h-5 w-9 rounded-full transition-colors disabled:opacity-50 ${k?"bg-surface-3":"bg-brand"}`,title:k?i("mcp.enable"):i("mcp.disable"),children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${k?"left-0.5":"left-4.5"}`})})]})]})},j.name)})]})]})})}const sn=[{key:"autoMemoryEnabled",labelKey:"settings.autoMemory",defaultValue:!0},{key:"teamMemoryEnabled",labelKey:"settings.teamMemory",defaultValue:!1}],ka=new Set(sn.map(r=>r.key));function Na(r){if(r==null)return i("settings.unset");if(typeof r=="string")return r;try{return JSON.stringify(r)}catch{return String(r)}}function Ms(r){if(r==null)return i("settings.unset");if(typeof r=="object")try{return JSON.stringify(r,null,2)}catch{return String(r)}return String(r)}function Sa({onClose:r,fetchSettings:t,onApply:s}){ae();const[n,a]=l.useState(null),[d,c]=l.useState(null),[u,p]=l.useState(""),[h,g]=l.useState(null),[b,S]=l.useState(null),[M,C]=l.useState(null),[j,x]=l.useState(!1),y=l.useCallback(async()=>{g(null),S(null),C(null),x(!1);try{const v=await t();a(v),c(v?null:i("settings.loadFailed"))}catch(v){ft("[SettingsDrawer] fetch failed",v),c(i("settings.loadFailed"))}},[t]);l.useEffect(()=>{y()},[y]);const k=l.useMemo(()=>n?Object.entries(n.effective).filter(([,v])=>v!==void 0).filter(([v])=>!v.startsWith("memoryV2")).sort(([v],[F])=>v.localeCompare(F)):[],[n]),_=l.useMemo(()=>{const v=u.trim().toLowerCase();return v?k.filter(([F,P])=>`${F} ${Na(P)}`.toLowerCase().includes(v)):k},[k,u]),A=v=>typeof v[1]=="boolean",T=l.useMemo(()=>_.filter(A).filter(([v])=>!ka.has(v)),[_]),w=l.useMemo(()=>_.filter(v=>!A(v)),[_]),E=l.useMemo(()=>M===null?null:k.find(([v])=>v===M)??null,[k,M]),$=async()=>{if(E)try{await navigator.clipboard.writeText(Ms(E[1])),x(!0),window.setTimeout(()=>x(!1),1500)}catch(v){ft("[SettingsDrawer] copy failed",v)}},I=async(v,F)=>{g(v),S(null);try{const P=await s({[v]:!F});P.ok||S(P.error||i("settings.writeFailed"))}finally{await y()}};return e.jsx(ke,{open:!0,onOpenChange:v=>{v||r()},children:e.jsxs(Ne,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-96 h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md overflow-y-auto",children:[e.jsx(Pe,{children:e.jsxs(Se,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(Zs,{className:"h-4 w-4"}),i("session.settings.title")]})}),e.jsxs("div",{className:"mt-3 space-y-4 text-sm",children:[b&&e.jsx("div",{className:"rounded-md bg-status-error/10 px-3 py-2 text-xs text-status-error",children:b}),n===null&&!d&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(Ge,{className:"h-3.5 w-3.5 animate-spin"}),i("settings.loading")]}),d&&e.jsx("p",{className:"text-xs text-status-error",children:d}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"rounded-lg border border-border bg-surface-2 px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-text-muted",children:i("settings.model")}),e.jsx("code",{className:"font-mono text-text-secondary",children:n.applied.model||i("settings.defaultModel")})]}),n.applied.effort&&e.jsxs("div",{className:"mt-1 flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-text-muted",children:"Effort"}),e.jsx("code",{className:"font-mono text-text-secondary",children:n.applied.effort})]}),e.jsx("p",{className:"mt-2 text-[10px] leading-relaxed text-text-muted",children:i("settings.hint")})]}),E?e.jsxs("section",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>{C(null),x(!1)},className:"flex items-center gap-1.5 text-xs text-text-muted transition-colors hover:text-text-primary",children:[e.jsx(Nr,{className:"h-3.5 w-3.5"}),i("settings.back")]}),e.jsx("div",{className:"break-all font-mono text-xs font-medium text-text-primary",children:E[0]}),e.jsx("pre",{className:"max-h-[60vh] overflow-y-auto whitespace-pre-wrap break-all rounded-md border border-border bg-surface-2 p-3 font-mono text-[10px] leading-relaxed text-text-secondary",children:Ms(E[1])}),e.jsxs("button",{type:"button",onClick:()=>void $(),className:"flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-text-secondary transition-colors hover:bg-surface-2 hover:text-text-primary",children:[j?e.jsx(qe,{className:"h-3.5 w-3.5 text-status-success"}):e.jsx(_r,{className:"h-3.5 w-3.5"}),j?i("settings.copied"):i("settings.copyValue")]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-surface-2 px-2.5 py-1.5",children:[e.jsx(ht,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{value:u,onChange:v=>p(v.target.value),placeholder:i("settings.searchPlaceholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"})]}),_.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:i("settings.noMatch")}),e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-[10px] font-medium uppercase tracking-wide text-text-muted",children:i("settings.memorySection")}),sn.map(v=>{const F=n.effective[v.key],P=typeof F=="boolean"?F:v.defaultValue,G=h===v.key;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-border bg-surface-2 px-3 py-2",children:[e.jsx("div",{className:"truncate text-xs text-text-primary",children:i(v.labelKey)}),e.jsx("button",{type:"button",role:"switch","aria-checked":P,disabled:G,onClick:()=>void I(v.key,P),className:`relative h-5 w-9 flex-shrink-0 rounded-full transition-colors disabled:opacity-50 ${P?"bg-brand":"bg-surface-3"}`,title:P?i("settings.turnOff"):i("settings.turnOn"),children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${P?"left-4.5":"left-0.5"}`})})]},v.key)}),e.jsx("p",{className:"text-[10px] leading-relaxed text-text-muted",children:i("settings.memoryHint")})]}),T.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-[10px] font-medium uppercase tracking-wide text-text-muted",children:H("settings.togglable",{n:T.length})}),T.map(([v,F])=>{const P=h===v;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-border bg-surface-2 px-3 py-2",children:[e.jsx("div",{className:"truncate font-mono text-xs text-text-primary",children:v}),e.jsx("button",{type:"button",role:"switch","aria-checked":F,disabled:P,onClick:()=>void I(v,F),className:`relative h-5 w-9 flex-shrink-0 rounded-full transition-colors disabled:opacity-50 ${F?"bg-brand":"bg-surface-3"}`,title:F?i("settings.turnOff"):i("settings.turnOn"),children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${F?"left-4.5":"left-0.5"}`})})]},v)})]}),w.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-[10px] font-medium uppercase tracking-wide text-text-muted",children:H("settings.readOnly",{n:w.length})}),w.map(([v])=>e.jsxs("button",{type:"button",onClick:()=>C(v),className:"flex w-full items-center justify-between gap-3 rounded-md border border-border bg-surface-2 px-3 py-2 text-left transition-colors hover:bg-surface-3",title:i("settings.viewDetail"),children:[e.jsx("span",{className:"truncate font-mono text-xs text-text-primary",children:v}),e.jsx(zs,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"})]},v))]})]})]})]})]})})}function _a({onClose:r,onAsk:t}){ae();const[s,n]=l.useState([]),[a,d]=l.useState(""),[c,u]=l.useState(!1),p=async()=>{const h=a.trim();if(!h||c)return;const g=Date.now();n(b=>[...b,{id:g,question:h,answer:null}]),d(""),u(!0);try{const b=await t(h);n(S=>S.map(M=>M.id===g?{...M,answer:b??i("sideQuestion.noAnswer"),error:b===null}:M))}finally{u(!1)}};return e.jsx(ke,{open:!0,onOpenChange:h=>{h||r()},children:e.jsxs(Ne,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-[26rem] h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md flex flex-col",children:[e.jsx(Pe,{children:e.jsxs(Se,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(Js,{className:"h-4 w-4"}),i("sideQuestion.title")]})}),e.jsx("p",{className:"mt-1 text-[10px] leading-relaxed text-text-muted",children:i("sideQuestion.desc")}),e.jsxs("div",{className:"mt-3 flex-1 space-y-4 overflow-y-auto",children:[s.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:i("sideQuestion.empty")}),s.map(h=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx("div",{className:"max-w-[85%] rounded-2xl rounded-br-md border border-user-bubble-border bg-user-bubble px-4 py-2 text-sm text-text-primary",children:h.question})}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-brand/8 flex items-center justify-center flex-shrink-0 overflow-hidden",children:e.jsx("img",{src:"/code/pony.svg",alt:"Saluzi",width:24,height:24,className:"object-contain",draggable:!1})}),e.jsx("div",{className:"min-w-0 flex-1 pt-1 text-sm text-text-primary",children:h.answer===null?e.jsxs("span",{className:"chat-typing-indicator inline-flex items-center gap-1","aria-hidden":"true",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):e.jsx("div",{className:h.error?"text-status-error":"",children:e.jsx(Kn,{children:h.answer})})})]})]},h.id))]}),e.jsxs("div",{className:"mt-3 flex items-end gap-2",children:[e.jsx("textarea",{value:a,onChange:h=>d(h.target.value),onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey&&!h.nativeEvent.isComposing&&(h.preventDefault(),p())},rows:Math.min(4,Math.max(1,a.split(`
|
|
81
|
+
`).length)),placeholder:i("sideQuestion.placeholder"),disabled:c,className:"flex-1 resize-none rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary placeholder:text-text-muted focus:border-accent focus:outline-none disabled:opacity-50"}),e.jsx("button",{type:"button",onClick:()=>void p(),disabled:c||!a.trim(),className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg bg-brand text-white transition-colors hover:bg-brand-light disabled:opacity-40 disabled:cursor-not-allowed",title:i("sideQuestion.send"),children:c?e.jsx(Ge,{className:"h-4 w-4 animate-spin"}):e.jsx(Ln,{className:"h-4 w-4"})})]})]})})}const $t="focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface-1";function Rs(r,t){var a;const s=(a=t==null?void 0:t.find(d=>d.type==="addRules"||d.type==="replaceRules"))==null?void 0:a.rules,n=s==null?void 0:s[0];return n!=null&&n.ruleContent?`${n.toolName}(${n.ruleContent})`:n!=null&&n.toolName?n.toolName:r}function Ca({requestId:r,toolName:t,toolInput:s,description:n,suggestions:a,onApprove:d,onApproveAlways:c,onReject:u}){ae();const p=s&&typeof s=="object"&&!Array.isArray(s)?s:{},h=Bn(Hn(t),p,{writeUnknownLabel:i("permission.writeUnknown")}),g=typeof s=="string"?s:JSON.stringify(s,null,2),b=Array.isArray(a)&&a.length>0;return e.jsxs("div",{role:"group","aria-label":H("permission.requestAria",{tool:t}),className:"rounded-xl border border-approve/30 bg-surface-1 p-4",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("span",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-approve/15 text-approve-text",children:e.jsx(Wn,{className:"h-3 w-3"})}),e.jsx("span",{className:"text-sm font-semibold font-display text-approve-text",children:i("permission.title")})]}),n&&e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:te(n)}),e.jsx("div",{className:"mb-2 font-mono text-xs font-bold text-text-primary",children:te(t)}),t!=="AskUserQuestion"&&(h?e.jsx("div",{className:"mb-3 space-y-2",children:h.map((S,M)=>e.jsx(Qn,{filePath:S.filePath,oldString:S.oldString,newString:S.newString,label:S.label},M))}):e.jsx("pre",{className:"mb-3 max-h-40 overflow-auto rounded-lg bg-surface-1 p-2 text-xs text-text-secondary font-mono",children:us(g,500)})),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:d,className:he("rounded-lg bg-approve px-4 py-2 text-sm font-medium font-display text-white hover:bg-approve-hover transition-colors",$t),children:i("permission.approve")}),b&&c&&e.jsxs("button",{onClick:c,className:he("flex items-center gap-1.5 rounded-lg border border-approve/40 bg-approve/10 px-4 py-2 text-sm font-medium font-display text-approve-text hover:bg-approve/20 transition-colors",$t),title:i("permission.alwaysAllowHint").replace("{rule}",Rs(t,a)),children:[e.jsx(ra,{className:"h-3.5 w-3.5"}),i("permission.alwaysAllow")," ",us(Rs(t,a),40)]}),e.jsx("button",{onClick:u,className:he("rounded-lg border border-status-error/40 px-4 py-2 text-sm font-medium font-display text-status-error hover:bg-status-error/10 transition-colors",$t),children:i("permission.reject")})]})]})}function Ta({questions:r,description:t,onSubmit:s,onSkip:n}){const[a,d]=l.useState({}),[c,u]=l.useState({}),[p,h]=l.useState(0),g=(C,j,x)=>{if(x){const y=a[C]||[],k=y.includes(j)?y.filter(_=>_!==j):[...y,j];d({...a,[C]:k})}else d({...a,[C]:j})},b=C=>{var x;const j=(x=c[C])==null?void 0:x.trim();j&&(d({...a,[C]:j}),u({...c,[C]:""}))},S=()=>{var j,x;const C={};for(const[y,k]of Object.entries(a)){const _=r[parseInt(y,10)];_&&(typeof k=="number"?C[y]=((x=(j=_.options)==null?void 0:j[k])==null?void 0:x.label)||String(k):Array.isArray(k)?C[y]=k.map(A=>{var T,w;return((w=(T=_.options)==null?void 0:T[A])==null?void 0:w.label)||String(A)}):C[y]=k)}s(C)};if(r.length<=1){const C=r[0]||{question:t,options:[],multiSelect:!1},j=C.multiSelect||!1;return e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx("div",{className:"mb-3 text-sm font-semibold font-display text-text-primary",children:te(t||C.question||"Question")}),e.jsxs("div",{className:"space-y-2",children:[(C.options||[]).map((x,y)=>{const k=j?(a[0]||[]).includes(y):a[0]===y;return e.jsxs("button",{onClick:()=>g(0,y,j),className:he("w-full rounded-lg border px-4 py-2.5 text-left text-sm font-display transition-colors",k?"border-brand bg-brand/10 text-text-primary":"border-border bg-surface-2 text-text-secondary hover:border-border-light"),children:[e.jsx("div",{className:"font-medium font-display",children:te(x.label)}),x.description&&e.jsx("div",{className:"mt-0.5 text-xs font-sans text-text-muted",children:te(x.description)})]},y)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:c[0]||"",onChange:x=>u({...c,0:x.target.value}),placeholder:"Other...",className:"flex-1 rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm font-display text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none",onKeyDown:x=>x.key==="Enter"&&b(0)}),e.jsx("button",{onClick:()=>b(0),className:"rounded-lg border border-border px-3 py-2 text-sm font-display text-text-secondary hover:bg-surface-2 transition-colors",children:"Send"})]})]}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx("button",{onClick:S,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium font-display text-white hover:bg-brand-light transition-colors",children:"Submit"}),e.jsx("button",{onClick:n,className:"rounded-lg border border-border px-4 py-2 text-sm font-display text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})}const M=r[p];return e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx("div",{className:"mb-3 text-sm font-semibold font-display text-text-primary",children:te(t||"Questions")}),e.jsx("div",{className:"mb-3 flex gap-1 overflow-x-auto",children:r.map((C,j)=>e.jsx("button",{onClick:()=>h(j),className:he("rounded-md px-3 py-1.5 text-xs font-display whitespace-nowrap transition-colors",p===j?"bg-brand/20 text-brand-text":"text-text-muted hover:bg-surface-2"),children:C.header||`Q${j+1}`},j))}),M&&e.jsx(Ea,{question:M,qIdx:p,answers:a,otherTexts:c,onSelect:g,onOtherTextChange:(C,j)=>u({...c,[C]:j}),onOtherSubmit:b}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-display text-text-muted",children:[p+1," / ",r.length]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:S,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium font-display text-white hover:bg-brand-light transition-colors",children:"Submit All"}),e.jsx("button",{onClick:n,className:"rounded-lg border border-border px-4 py-2 text-sm font-display text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})]})}function Ea({question:r,qIdx:t,answers:s,otherTexts:n,onSelect:a,onOtherTextChange:d,onOtherSubmit:c}){const u=r.multiSelect||!1;return e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:te(r.question)}),e.jsxs("div",{className:"space-y-2",children:[(r.options||[]).map((p,h)=>{const g=u?(s[t]||[]).includes(h):s[t]===h;return e.jsxs("button",{onClick:()=>a(t,h,u),className:he("w-full rounded-lg border px-4 py-2.5 text-left text-sm font-display transition-colors",g?"border-brand bg-brand/10 text-text-primary":"border-border bg-surface-2 text-text-secondary hover:border-border-light"),children:[e.jsx("div",{className:"font-medium font-display",children:te(p.label)}),p.description&&e.jsx("div",{className:"mt-0.5 text-xs font-sans text-text-muted",children:te(p.description)})]},h)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n[t]||"",onChange:p=>d(t,p.target.value),placeholder:"Other...",className:"flex-1 rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm font-display text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none",onKeyDown:p=>p.key==="Enter"&&c(t)}),e.jsx("button",{onClick:()=>c(t),className:"rounded-lg border border-border px-3 py-2 text-sm font-display text-text-secondary hover:bg-surface-2 transition-colors",children:"Send"})]})]})]})}function Ma({planContent:r,description:t,onSubmit:s}){const[n,a]=l.useState(null),[d,c]=l.useState(""),u=!r||!r.trim(),p=()=>{n&&s(n,n==="no"?d:void 0)};return e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx("span",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-brand/15 text-brand-text",children:e.jsx(qe,{className:"h-3 w-3",strokeWidth:2.5})}),e.jsx("span",{className:"text-sm font-semibold font-display text-text-primary",children:u?"Exit plan mode?":"Ready to code?"})]}),!u&&e.jsx("div",{className:"mb-4 max-h-64 overflow-auto rounded-lg bg-tool-card p-4 text-sm text-text-secondary",dangerouslySetInnerHTML:{__html:Ra(r)}}),e.jsx("div",{className:"space-y-2",children:u?e.jsxs(e.Fragment,{children:[e.jsx(ze,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes"}),e.jsx(ze,{selected:n==="no",onClick:()=>a("no"),label:"No"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ze,{selected:n==="yes-accept-edits",onClick:()=>a("yes-accept-edits"),label:"Yes, auto-accept edits",desc:"Approve plan and auto-accept file edits"}),e.jsx(ze,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes, manually approve edits",desc:"Approve plan but confirm each edit"}),e.jsx(ze,{selected:n==="no",onClick:()=>a("no"),label:"No, keep planning",desc:"Provide feedback to refine the plan"})]})}),n==="no"&&e.jsx("textarea",{value:d,onChange:h=>c(h.target.value),placeholder:"Tell Saluzi what to change...",className:"mt-3 w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm font-display text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none",rows:3}),e.jsx("div",{className:"mt-4",children:e.jsx("button",{onClick:p,disabled:!n,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium font-display text-white hover:bg-brand-light disabled:opacity-50 transition-colors",children:"Submit"})})]})}function ze({selected:r,onClick:t,label:s,desc:n}){return e.jsxs("button",{onClick:t,className:he("w-full rounded-lg border px-4 py-2.5 text-left text-sm font-display transition-colors",r?"border-brand bg-brand/10 text-text-primary":"border-border bg-surface-2 text-text-secondary hover:border-border-light"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:he("flex h-4 w-4 items-center justify-center rounded-full border text-[10px] transition-colors",r?"border-brand bg-brand text-white":"border-border"),children:r&&"✓"}),e.jsx("span",{className:"font-medium font-display",children:s})]}),n&&e.jsx("div",{className:"mt-0.5 pl-6 text-xs font-sans text-text-muted",children:n})]})}function Ra(r){let t=te(r);return t=t.replace(/```(\w*)\n?([\s\S]*?)```/g,(s,n,a)=>`<pre class="my-2 overflow-x-auto rounded-lg bg-tool-card p-3 font-mono text-xs">${a.trim()}</pre>`),t=t.replace(/`([^`]+)`/g,'<code class="rounded bg-tool-card px-1.5 py-0.5 font-mono text-xs">$1</code>'),t=t.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),t}function Aa({request:r,onSubmit:t}){ae();const s=$a(r.requestedSchema),n=Ia(r.requestedSchema),[a,d]=l.useState({}),c=s.length===0||n.every(u=>(a[u]??"").trim()!=="");return r.mode==="url"&&r.url?e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx(As,{serverName:r.serverName,message:r.message}),e.jsxs("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",className:"mt-2 flex w-full items-center justify-between rounded-lg border border-border bg-surface-2 px-4 py-2.5 text-sm text-brand-text hover:bg-brand/10 transition-colors",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:r.url}),e.jsx(Cr,{className:"ml-2 h-4 w-4 flex-shrink-0"})]}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx("button",{onClick:()=>t("accept"),className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light transition-colors",children:i("elicitation.done")}),e.jsx("button",{onClick:()=>t("cancel"),className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:i("common.cancel")})]})]}):e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx(As,{serverName:r.serverName,message:r.message}),s.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:s.map(({name:u,prop:p})=>e.jsxs("label",{className:"block",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs font-medium text-text-primary",children:u}),n.includes(u)&&e.jsx("span",{className:"text-[10px] font-medium text-warning-text",children:i("elicitation.required")})]}),p.description&&e.jsx("div",{className:"mb-1 text-xs text-text-muted",children:te(p.description)}),e.jsx("input",{type:p.type==="number"?"number":"text",value:a[u]??"",onChange:h=>d(g=>({...g,[u]:h.target.value})),className:"w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none"})]},u))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{const u={};for(const{name:p,prop:h}of s){const g=(a[p]??"").trim();g&&(u[p]=h.type==="number"?Number(g):g)}t("accept",u)},disabled:!c,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light disabled:opacity-50 transition-colors",children:i("elicitation.submit")}),e.jsx("button",{onClick:()=>t("decline"),className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:i("elicitation.decline")})]})]})}function As({serverName:r,message:t}){return e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx("span",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-brand/15 text-brand-text",children:e.jsx(Yr,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-sm font-semibold text-text-primary",children:[i("elicitation.title")," ",e.jsx("span",{className:"font-mono text-xs text-text-muted",children:te(r)})]})]}),t&&e.jsx("div",{className:"text-sm text-text-secondary",children:te(t)})]})}function $a(r){const t=r==null?void 0:r.properties;return!t||typeof t!="object"?[]:Object.entries(t).filter(([,s])=>s&&typeof s=="object").map(([s,n])=>({name:s,prop:n}))}function Ia(r){const t=r==null?void 0:r.required;return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function Da(r){const[t,s]=l.useState([]),[n,a]=l.useState(!0),[d,c]=l.useState(null),u=l.useCallback(async()=>{a(!0),c(null);try{const g=await Vn(r);s(g)}catch(g){c(g instanceof Error?g.message:"Failed to load shares")}finally{a(!1)}},[r]);l.useEffect(()=>{u()},[u]);const p=l.useCallback(async g=>{c(null);try{const b=await Yn(r,g);return await u(),b}catch(b){throw c(b instanceof Error?b.message:"Failed to create share"),b}},[r,u]),h=l.useCallback(async g=>{c(null);try{await zn(r,g),await u()}catch(b){throw c(b instanceof Error?b.message:"Failed to revoke share"),b}},[r,u]);return{shares:t,isLoading:n,error:d,createShare:p,revokeShare:h,refresh:u}}function qa({open:r,onClose:t,sessionId:s,sessionTitle:n}){ae();const{shares:a,isLoading:d,error:c,createShare:u,revokeShare:p}=Da(s),[h,g]=l.useState("user"),[b,S]=l.useState(""),[M,C]=l.useState(""),[j,x]=l.useState("read"),[y,k]=l.useState(""),[_,A]=l.useState(!1),[T,w]=l.useState(null),[E,$]=l.useState(""),[I,v]=l.useState(!1),[F,P]=l.useState(!1);l.useEffect(()=>{r&&(g("user"),S(""),C(""),x("read"),k(""),A(!1),w(null),$(""),v(!1),P(!1))},[r]);const G=async()=>{A(!0),$(""),w(null);try{const O={grantedTo:h==="user"?{userId:b.trim()}:{teamId:M.trim()},permission:j};y.trim()&&(O.expiresAt=y.trim());const ne=await u(O);w(`${window.location.origin}/code/s/${ne.shareToken}`)}catch(O){$(O instanceof Error?O.message:"Failed to create share")}finally{A(!1)}},X=async O=>{try{await p(O)}catch{}},se=async()=>{if(!T)return;P(!1);try{if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(T),v(!0),setTimeout(()=>v(!1),2e3);return}}catch{}const O=document.createElement("textarea");O.value=T,O.style.position="fixed",O.style.opacity="0",document.body.appendChild(O),O.select();try{document.execCommand("copy"),v(!0),setTimeout(()=>v(!1),2e3)}catch{P(!0)}document.body.removeChild(O)};return e.jsx(ke,{open:r,onOpenChange:O=>{O||t()},children:e.jsxs(Ne,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(Pe,{children:e.jsxs(Se,{className:"font-display text-lg font-semibold text-text-primary",children:[i("share.title"),n?`: ${n}`:""]})}),e.jsxs("div",{className:"space-y-4 min-w-0",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:i("share.grantTo")}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("button",{onClick:()=>g("user"),className:`rounded-md px-3 py-1 text-sm transition-colors ${h==="user"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:i("share.user")}),e.jsx("button",{onClick:()=>g("team"),className:`rounded-md px-3 py-1 text-sm transition-colors ${h==="team"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:i("share.team")})]}),h==="user"?e.jsx(Sr,{onSelect:S,placeholder:i("share.userIdPlaceholder"),actionLabel:i("share.selectUser")}):e.jsx("input",{type:"text",value:M,onChange:O=>C(O.target.value),placeholder:i("share.teamIdPlaceholder"),className:"w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary placeholder:text-text-muted focus:border-brand focus:outline-none"}),h==="user"&&b&&e.jsxs("p",{className:"mt-1 text-xs text-text-muted",children:[i("share.selectedUser"),": ",e.jsx("span",{className:"font-mono",children:b})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:i("share.permission")}),e.jsxs("select",{value:j,onChange:O=>x(O.target.value),className:"w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary focus:border-brand focus:outline-none",children:[e.jsx("option",{value:"read",children:i("share.permissionRead")}),e.jsx("option",{value:"write",children:i("share.permissionWrite")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:i("share.expiresAt")}),e.jsx("input",{type:"datetime-local",value:y,onChange:O=>k(O.target.value),className:"w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary focus:border-brand focus:outline-none"})]}),(E||c)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:E||c}),T&&e.jsxs("div",{className:"rounded-md bg-surface-2 px-3 py-2",children:[e.jsx("p",{className:"text-sm text-text-secondary mb-1",children:i("share.linkCreated")}),e.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[e.jsx("code",{className:"min-w-0 flex-1 break-all text-xs text-text-primary",children:T}),e.jsx("button",{onClick:se,className:"shrink-0 rounded-md bg-brand px-2 py-1 text-xs text-white hover:bg-brand-light transition-colors",children:I?i("share.copied"):i("share.copy")})]}),F&&e.jsx("p",{className:"mt-1 text-xs text-status-error",children:i("share.copyFailed")})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"mb-2 text-sm font-medium text-text-secondary",children:i("share.existingShares")}),d?e.jsx("p",{className:"text-sm text-text-muted",children:i("share.loading")}):a.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:i("share.none")}):e.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto",children:a.map(O=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md bg-surface-2 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm text-text-primary",children:O.granted_to_user||O.granted_to_team||"Unknown"}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[O.permission==="write"?i("share.permissionWrite"):i("share.permissionRead"),O.expires_at?` · expires ${O.expires_at}`:""]})]}),e.jsx("button",{onClick:()=>X(O.id),className:"shrink-0 rounded-md px-2 py-1 text-xs text-status-error hover:bg-surface-3 transition-colors",children:i("share.revoke")})]},O.id))})]})]}),e.jsxs(vr,{children:[e.jsx("button",{onClick:t,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:i("common.close")}),e.jsx("button",{onClick:G,disabled:_||(h==="user"?!b.trim():!M.trim()),className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light disabled:opacity-50 transition-colors",children:_?i("common.creating"):i("share.createShare")})]})]})})}function Pa(r){const t=new Date,s=new Date(t.getTime()-1440*60*1e3),n=(c,u)=>c.getFullYear()===u.getFullYear()&&c.getMonth()===u.getMonth()&&c.getDate()===u.getDate(),a={today:[],yesterday:[],earlier:[]};for(const c of r){const u=new Date(c.modified||0);n(u,t)?a.today.push(c):n(u,s)?a.yesterday.push(c):a.earlier.push(c)}return[["today",i("resume.today")],["yesterday",i("resume.yesterday")],["earlier",i("resume.earlier")]].map(([c,u])=>({label:u,items:a[c]})).filter(c=>c.items.length>0)}function Oa(r){return r?new Date(r).toLocaleString():""}function Fa({open:r,onClose:t,adapter:s,onResume:n}){const a=ae(),[d,c]=l.useState([]),[u,p]=l.useState(!1),[h,g]=l.useState("");l.useEffect(()=>{if(!r)return;let S=!1;return p(!0),g(""),c([]),s.listResumableSessions().then(M=>{S||c(M)}).catch(M=>{S||g(M instanceof Error?M.message:String(M))}).finally(()=>{S||p(!1)}),()=>{S=!0}},[r,s]);const b=l.useMemo(()=>Pa(d),[d,a]);return e.jsx(ke,{open:r,onOpenChange:S=>{S||t()},children:e.jsxs(Ne,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(Pe,{children:e.jsx(Se,{className:"font-display text-lg font-semibold text-text-primary",children:i("session.resume.title")})}),e.jsxs("div",{className:"max-h-96 min-w-0 space-y-4 overflow-y-auto",children:[u&&e.jsx("p",{className:"py-6 text-center text-sm text-text-muted",children:i("resume.loading")}),!u&&h&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:h}),!u&&!h&&d.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-text-muted",children:i("resume.empty")}),!u&&!h&&b.map(S=>e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-xs font-medium text-text-muted",children:S.label}),e.jsx("div",{className:"space-y-1",children:S.items.map(M=>e.jsxs("button",{type:"button",onClick:()=>n(M),className:"w-full rounded-md px-3 py-2 text-left transition-colors hover:bg-surface-3",children:[e.jsx("p",{className:"truncate text-sm text-text-primary",children:M.title}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[Oa(M.modified),M.gitBranch?` · ${M.gitBranch}`:""]})]},M.sessionId))})]},S.label))]}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx("button",{type:"button",onClick:t,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary transition-colors hover:bg-surface-2",children:i("common.cancel")})})]})})}const $s=["working","episodic","semantic","procedural"],Ua=["user","feedback","project","reference"];function Ka(r){switch(r){case"user":return"bg-accent/15 text-accent";case"feedback":return"bg-status-warning/15 text-status-warning";case"project":return"bg-status-active/15 text-status-active";default:return"bg-surface-3 text-text-muted"}}function La(r){try{return new Date(r).toLocaleDateString()}catch{return"—"}}function Ba({refreshTick:r,recall:t,dreaming:s,onDreamTrigger:n}){ae();const[a,d]=l.useState(null),[c,u]=l.useState("memories"),[p,h]=l.useState("personal"),[g,b]=l.useState([]),[S,M]=l.useState(!1),[C,j]=l.useState(""),[x,y]=l.useState(null),[k,_]=l.useState({}),[A,T]=l.useState(null),[w,E]=l.useState(""),[$,I]=l.useState(""),[v,F]=l.useState(null),[P,G]=l.useState(null),[X,se]=l.useState(""),[O,ne]=l.useState(null),[_e,Ce]=l.useState(!1),ue=l.useRef(null);l.useEffect(()=>{Vs().then(d).catch(()=>d(null))},[]);const Te=l.useCallback(async()=>{M(!0),j("");try{b(await Gn(p))}catch{j(i("memorySidebar.loadFailed"))}finally{M(!1)}},[p]);l.useEffect(()=>{(a==null?void 0:a.mode)==="memdir"&&Te()},[a==null?void 0:a.mode,Te,r]),l.useEffect(()=>{c!=="governance"||(a==null?void 0:a.mode)!=="memdir"||Jn().then(G).catch(()=>G(null))},[c,a==null?void 0:a.mode,r]),l.useEffect(()=>{ue.current&&clearTimeout(ue.current);const f=$.trim();if(!f){F(null);return}return ue.current=setTimeout(()=>{Xn(f).then(F).catch(()=>F([]))},300),()=>{ue.current&&clearTimeout(ue.current)}},[$]);const Ee=async f=>{if(x===f){y(null);return}if(y(f),!k[f])try{const{content:K}=await xs(f);_(Z=>({...Z,[f]:K}))}catch{_(K=>({...K,[f]:i("memorySidebar.loadFailed")}))}},ie=f=>x===f?e.jsx("pre",{className:"mt-1 max-h-48 overflow-y-auto whitespace-pre-wrap rounded bg-surface-3 p-2 text-[10px] leading-relaxed text-text-secondary",children:k[f]??"…"}):null,oe=async f=>{if(k[f])E(k[f]);else try{const{content:K}=await xs(f);_(Z=>({...Z,[f]:K})),E(K)}catch{E("")}T(f)},V=async()=>{if(A)try{await ar(A,w),_(f=>({...f,[A]:w})),T(null)}catch{j(i("memorySidebar.updateFailed"))}},ye=async f=>{try{await rr(f),b(K=>K.filter(Z=>Z.path!==f)),y(K=>K===f?null:K)}catch{j(i("memorySidebar.deleteFailed"))}},ge=async f=>{try{await nr(f),await Te()}catch(K){j(K instanceof Error?K.message:i("memorySidebar.promoteFailed"))}},[re,W]=l.useState(!1),[be,Oe]=l.useState(""),[st,Y]=l.useState(""),[nt,je]=l.useState("project"),[Fe,rt]=l.useState(""),[Ue,Me]=l.useState(!1),Ke=()=>{W(!0),Oe(""),Y(""),je("project"),rt("")},me=be.trim().length>0&&Fe.trim().length>0&&!Ue,gt=async()=>{if(me){Me(!0),j("");try{await sr({scope:p,name:be.trim(),description:st.trim()||void 0,type:nt,content:Fe}),W(!1),await Te()}catch(f){j(f instanceof Error?f.message:i("memorySidebar.createFailed"))}finally{Me(!1)}}},bt=()=>{n==null||n()},at=l.useCallback(async()=>{const f=X.trim();if(!(!f||_e)){Ce(!0),ne(null);try{ne(await Zn(f,5))}catch{ne([])}finally{Ce(!1)}}},[X,_e]),le=(a==null?void 0:a.teamEnabled)===!0,Re=a==null?void 0:a.automation,Ae=le&&c==="memories"&&!$;return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center gap-1 border-b border-border px-2 py-1.5",children:[e.jsx("button",{type:"button",onClick:()=>u("memories"),className:`rounded-md px-2 py-1 text-xs font-medium ${c==="memories"?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2"}`,children:i("memorySidebar.memoriesTab")}),e.jsx("button",{type:"button",onClick:()=>u("governance"),className:`rounded-md px-2 py-1 text-xs font-medium ${c==="governance"?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2"}`,children:i("memorySidebar.governanceTab")}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[(a==null?void 0:a.mode)==="memdir"&&c==="memories"&&!$&&e.jsx("button",{type:"button",onClick:re?()=>W(!1):Ke,disabled:p==="team"&&!le,className:"rounded p-1 text-text-secondary hover:bg-surface-2 hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-50",title:i("memorySidebar.new"),children:re?e.jsx(ms,{className:"h-3 w-3"}):e.jsx(er,{className:"h-3 w-3"})}),e.jsx(ht,{className:"h-3 w-3 text-text-muted"}),e.jsx("input",{value:$,onChange:f=>I(f.target.value),placeholder:i("memorySidebar.searchPlaceholder"),title:i("memorySidebar.searchHint"),className:"w-28 bg-transparent text-xs text-text-primary placeholder:text-text-muted focus:outline-none"})]})]}),C&&e.jsx("p",{className:"px-3 py-1 text-xs text-status-error",children:C}),Re&&Re.mode!=="normal"&&e.jsx("div",{className:"border-b border-status-warning/30 bg-status-warning/10 px-3 py-1.5 text-xs text-status-warning",children:Re.mode==="sa"?i("memorySidebar.saModeBanner"):i("memorySidebar.poorModeBanner")}),v!==null&&e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:v.length===0?e.jsx("p",{className:"py-8 text-center text-xs text-text-muted",children:i("memorySidebar.noResults")}):e.jsx("ul",{className:"space-y-1",children:v.map(f=>e.jsxs("li",{children:[e.jsxs("button",{type:"button",onClick:()=>void Ee(f.path),className:"w-full rounded-md px-2 py-1.5 text-left hover:bg-surface-2",children:[e.jsx("span",{className:"block truncate text-xs font-medium text-text-primary",children:f.name}),e.jsx("ul",{className:"mt-0.5 space-y-0.5",children:f.matches.map((K,Z)=>e.jsxs("li",{className:"flex gap-1.5 text-[10px] leading-relaxed",children:[e.jsx("span",{className:"flex-shrink-0 font-mono text-text-muted",children:K.line===0?"file":`L${K.line}`}),e.jsx("span",{className:"truncate text-text-secondary",children:K.text})]},Z))})]}),ie(f.path)]},f.path))})}),v===null&&c==="memories"&&e.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[t&&t.hits.length>0&&e.jsxs("div",{className:"mb-2 rounded-md border border-brand/30 bg-brand/5 p-2",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-brand-text",children:i("memorySidebar.recallTitle")}),e.jsxs("p",{className:"mb-1 truncate text-[10px] text-text-muted",title:t.query,children:[i("memorySidebar.recallQuery"),": ",t.query]}),e.jsx("ul",{className:"space-y-0.5",children:t.hits.slice(0,5).map(f=>e.jsxs("li",{children:[e.jsxs("button",{type:"button",onClick:()=>void Ee(f.path),className:"flex w-full items-center justify-between gap-2 rounded px-1 py-0.5 text-left text-xs hover:bg-surface-2",title:f.path,children:[e.jsx("span",{className:"truncate text-text-secondary",children:f.path.replace(/^team\//,"").replace(/\.md$/,"")}),f.score!==void 0&&e.jsxs("span",{className:"flex-shrink-0 text-[10px] text-text-muted",children:[(f.score*100).toFixed(0),"%"]})]}),ie(f.path)]},f.path))})]}),Ae&&e.jsx("div",{className:"mb-2 flex rounded-md bg-surface-2 p-0.5 text-xs",children:["personal","team"].map(f=>e.jsx("button",{type:"button",onClick:()=>h(f),className:`flex-1 rounded px-2 py-1 ${p===f?"bg-brand-light text-white":"text-text-muted"}`,children:f==="personal"?i("memorySidebar.personal"):i("memorySidebar.team")},f))}),p==="team"&&le&&!re&&e.jsx("p",{className:"mb-2 px-1 text-[10px] leading-relaxed text-text-muted",children:i("memorySidebar.teamHint")}),re&&e.jsxs("div",{className:"mb-2 space-y-1.5 rounded-md border border-border bg-surface-2 p-2",children:[e.jsx("input",{value:be,onChange:f=>Oe(f.target.value),placeholder:i("memorySidebar.create.namePlaceholder"),className:"w-full rounded bg-surface-3 px-2 py-1 text-xs text-text-primary placeholder:text-text-muted focus:outline-none focus:ring-1 focus:ring-brand/40"}),e.jsx("input",{value:st,onChange:f=>Y(f.target.value),placeholder:i("memorySidebar.create.descriptionPlaceholder"),className:"w-full rounded bg-surface-3 px-2 py-1 text-xs text-text-primary placeholder:text-text-muted focus:outline-none focus:ring-1 focus:ring-brand/40"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("select",{value:nt,onChange:f=>je(f.target.value),className:"flex-shrink-0 rounded bg-surface-3 px-1.5 py-1 text-xs text-text-primary focus:outline-none",children:Ua.map(f=>e.jsx("option",{value:f,children:f},f))}),e.jsx("span",{className:"truncate text-[10px] text-text-muted",children:p==="team"?i("memorySidebar.team"):i("memorySidebar.personal")})]}),e.jsx("textarea",{value:Fe,onChange:f=>rt(f.target.value),placeholder:i("memorySidebar.create.contentPlaceholder"),rows:6,className:"w-full rounded bg-surface-3 p-2 text-[10px] leading-relaxed text-text-primary placeholder:text-text-muted focus:outline-none focus:ring-1 focus:ring-brand/40"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{type:"button",onClick:()=>void gt(),disabled:!me,className:"rounded bg-accent px-2 py-0.5 text-[10px] font-medium text-white hover:bg-accent/90 disabled:cursor-not-allowed disabled:opacity-50",children:Ue?"…":i("memorySidebar.new")}),e.jsx("button",{type:"button",onClick:()=>W(!1),className:"rounded px-2 py-0.5 text-[10px] text-text-muted hover:bg-surface-3",children:i("memorySidebar.cancel")})]})]}),S?e.jsx("div",{className:"space-y-2",children:[0,1,2].map(f=>e.jsx("div",{className:"h-12 animate-pulse rounded-md bg-surface-2"},f))}):g.length===0?e.jsxs("div",{className:"py-10 text-center",children:[e.jsx(qt,{className:"mx-auto h-6 w-6 text-text-muted/40"}),e.jsx("p",{className:"mt-2 text-xs text-text-muted",children:i("memorySidebar.empty")})]}):e.jsx("ul",{className:"space-y-1",children:g.map(f=>e.jsxs("li",{className:"group rounded-md hover:bg-surface-2",children:[e.jsxs("button",{type:"button",onClick:()=>void Ee(f.path),className:"w-full px-2 py-1.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-xs font-medium text-text-primary",children:f.name}),f.type&&e.jsx("span",{className:`flex-shrink-0 rounded-full px-1.5 py-0.5 text-[9px] font-medium ${Ka(f.type)}`,children:f.type}),e.jsx("span",{className:"ml-auto flex-shrink-0 text-[9px] text-text-muted",children:La(f.mtimeMs)})]}),f.description&&e.jsx("p",{className:"mt-0.5 truncate text-[10px] text-text-muted",children:f.description})]}),e.jsxs("div",{className:"flex items-center gap-0.5 px-2 pb-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx("button",{type:"button",onClick:()=>void oe(f.path),className:"rounded p-1 text-text-secondary hover:bg-surface-3 hover:text-text-primary",title:i("memorySidebar.edit"),children:e.jsx(ms,{className:"h-3 w-3"})}),f.scope==="personal"&&le&&e.jsx("button",{type:"button",onClick:()=>void ge(f.path),className:"rounded p-1 text-text-secondary hover:bg-surface-3 hover:text-text-primary",title:i("memorySidebar.promote"),children:e.jsx(tr,{className:"h-3 w-3"})}),e.jsx("button",{type:"button",onClick:()=>void ye(f.path),className:"ml-auto rounded p-1 text-text-secondary hover:bg-status-error/10 hover:text-status-error",title:i("memorySidebar.delete"),children:e.jsx(Qs,{className:"h-3 w-3"})})]}),x===f.path&&A!==f.path&&e.jsx("pre",{className:"mx-2 mb-2 max-h-48 overflow-y-auto whitespace-pre-wrap rounded bg-surface-3 p-2 text-[10px] leading-relaxed text-text-secondary",children:k[f.path]??"…"}),x===f.path&&A===f.path&&e.jsxs("div",{className:"mx-2 mb-2",children:[e.jsx("textarea",{value:w,onChange:K=>E(K.target.value),rows:8,className:"w-full rounded bg-surface-3 p-2 text-[10px] leading-relaxed text-text-primary focus:outline-none focus:ring-1 focus:ring-brand/40"}),e.jsxs("div",{className:"mt-1 flex gap-1",children:[e.jsx("button",{type:"button",onClick:()=>void V(),className:"rounded bg-accent px-2 py-0.5 text-[10px] font-medium text-white hover:bg-accent/90",children:i("memorySidebar.save")}),e.jsx("button",{type:"button",onClick:()=>T(null),className:"rounded px-2 py-0.5 text-[10px] text-text-muted hover:bg-surface-2",children:i("memorySidebar.cancel")})]})]})]},f.path))})]}),v===null&&c==="governance"&&e.jsx("div",{className:"flex-1 overflow-y-auto p-3 text-xs",children:P?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("button",{type:"button",disabled:s||!P.automation.autoDream,onClick:bt,className:"inline-flex w-full items-center justify-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-accent/90 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(Tr,{className:"h-3.5 w-3.5"}),s?i("memorySidebar.dreaming"):i("memorySidebar.dream")]}),!P.automation.autoDream&&e.jsx("p",{className:"mt-1 text-center text-[10px] text-text-muted",children:i("memorySidebar.dreamDisabled")})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-text-muted",children:i("memorySidebar.recallTest.title")}),e.jsx("p",{className:"mb-1.5 text-[10px] leading-relaxed text-text-muted",children:i("memorySidebar.recallTest.hint")}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("input",{value:X,onChange:f=>se(f.target.value),onKeyDown:f=>{f.key==="Enter"&&!f.nativeEvent.isComposing&&at()},placeholder:i("memorySidebar.recallTest.placeholder"),className:"min-w-0 flex-1 rounded-md bg-surface-2 px-2 py-1 text-xs text-text-primary placeholder:text-text-muted focus:outline-none focus:ring-1 focus:ring-brand/40"}),e.jsx("button",{type:"button",onClick:()=>void at(),disabled:_e||!X.trim(),className:"flex-shrink-0 rounded-md bg-accent px-2.5 py-1 text-xs font-medium text-white hover:bg-accent/90 disabled:cursor-not-allowed disabled:opacity-50",children:_e?i("memorySidebar.recallTest.running"):i("memorySidebar.recallTest.run")})]}),O!==null&&e.jsx("ul",{className:"mt-1.5 space-y-0.5 rounded-md bg-surface-2 p-2",children:O.length===0?e.jsx("li",{className:"text-[10px] text-text-muted",children:i("memorySidebar.recallTest.noResults")}):O.map(f=>e.jsxs("li",{children:[e.jsxs("button",{type:"button",onClick:()=>void Ee(f.path),className:"flex w-full items-center justify-between gap-2 rounded px-1 py-0.5 text-left text-xs hover:bg-surface-3",title:f.path,children:[e.jsx("span",{className:"truncate text-text-secondary",children:f.path.replace(/^team\//,"").replace(/\.md$/,"")}),e.jsxs("span",{className:"flex-shrink-0 text-[10px] text-text-muted",children:[(f.score*100).toFixed(0),"%",f.confidence!==void 0?` · conf ${f.confidence.toFixed(2)}`:""]})]}),ie(f.path)]},f.path))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-wide text-text-muted",children:i("memorySidebar.layers")}),e.jsx("ul",{className:"space-y-1",children:$s.map(f=>{const K=P.layers[f],Z=Math.max(...$s.map(Le=>P.layers[Le]),1);return e.jsxs("li",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-16 flex-shrink-0 text-text-secondary",children:f}),e.jsx("div",{className:"h-1.5 flex-1 overflow-hidden rounded-full bg-surface-2",children:e.jsx("div",{className:"h-full rounded-full bg-brand",style:{width:`${K/Z*100}%`}})}),e.jsx("span",{className:"w-6 text-right text-text-muted",children:K})]},f)})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-wide text-text-muted",children:i("memorySidebar.health")}),e.jsxs("div",{className:"rounded-md bg-surface-2 p-2 text-[10px] text-text-secondary",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:i("memorySidebar.total")}),e.jsx("span",{children:P.health.totalMemories})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:i("memorySidebar.capacity")}),e.jsxs("span",{className:P.health.capacity.tier==="critical"?"text-status-error":P.health.capacity.tier==="warning"?"text-status-warning":"text-status-active",children:[P.health.capacity.utilizationPct.toFixed(0),"% · ",P.health.capacity.tier]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:i("memorySidebar.avgConfidence")}),e.jsx("span",{children:P.health.avgConfidence.toFixed(2)})]})]})]}),P.alerts.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-wide text-text-muted",children:[i("memorySidebar.alerts")," (",P.alerts.length,")"]}),e.jsx("ul",{className:"space-y-1 rounded-md bg-status-warning/5 p-2",children:P.alerts.slice(-8).reverse().map((f,K)=>e.jsx("li",{className:"text-[10px] leading-relaxed text-text-secondary",children:f},K))})]}),P.conflicts&&e.jsxs("div",{children:[e.jsx("p",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-wide text-status-warning",children:i("memorySidebar.conflicts")}),e.jsx("pre",{className:"max-h-40 overflow-y-auto whitespace-pre-wrap rounded-md bg-surface-2 p-2 text-[10px] leading-relaxed text-text-secondary",children:P.conflicts})]})]}):e.jsx("p",{className:"py-10 text-center text-text-muted",children:i("memorySidebar.loadFailed")})})]})}class Ha{constructor(t,s,n,a){q(this,"pending",null);this.current=t,this.apply=s,this.send=n,this.onError=a}set(t){if(t===this.current)return;const s=this.current;this.current=t,this.pending={requestId:null,previous:s},this.apply(t);try{Promise.resolve(this.send(t)).then(n=>{this.pending&&(this.pending.requestId=n)}).catch(n=>{this.rollback(s,Is(n),"send")})}catch(n){this.rollback(s,Is(n),"send")}}handleControlResponse(t){const s=this.pending;if(!s||s.requestId!==t.requestId)return!1;const{previous:n}=s;return this.pending=null,t.subtype==="error"&&this.rollback(n,t.error??"","response"),!0}sync(t){t!==this.current&&(this.current=t,this.apply(t),this.pending=null)}adoptExternal(t){this.pending||t!==this.current&&(this.current=t)}getCurrent(){return this.current}rollback(t,s,n){var a;this.pending=null,this.current=t,this.apply(t),s&&((a=this.onError)==null||a.call(this,s,n))}}function Is(r){return r instanceof Error?r.message:String(r)}function xt(r){const t=l.useRef(r);t.current=r;const s=l.useRef(null);s.current||(s.current=new Ha(r.value,a=>t.current.apply(a),a=>t.current.send(a),(a,d)=>{var c,u;return(u=(c=t.current).onError)==null?void 0:u.call(c,a,d)}));const n=s.current;return l.useEffect(()=>{n.adoptExternal(r.value)}),l.useMemo(()=>({set:a=>n.set(a),handleControlResponse:a=>n.handleControlResponse(a),sync:a=>n.sync(a)}),[n])}const nn="rcs_context_usage_";function rn(){try{if(typeof localStorage<"u")return localStorage}catch{}return null}function Ds(){return{totalTokens:0,rawMaxTokens:0,percentage:0}}function Wa(r){if(!r||typeof r!="object"||Array.isArray(r))return null;const t=r,{totalTokens:s,rawMaxTokens:n,percentage:a}=t;if(typeof s!="number"||typeof n!="number"||typeof a!="number")return null;const d=t.categories,c=Array.isArray(d)?d.filter(u=>!!u&&typeof u=="object"&&typeof u.name=="string").map(u=>({name:u.name,tokens:typeof u.tokens=="number"?u.tokens:0,...u.isDeferred===!0?{isDeferred:!0}:{}})):void 0;return{totalTokens:s,rawMaxTokens:n,percentage:a,...typeof t.model=="string"&&t.model?{model:t.model}:{},...c&&c.length>0?{categories:c}:{}}}function Qa(r,t=rn()){if(!t||!r)return null;try{const s=t.getItem(nn+r);return s?Wa(JSON.parse(s)):null}catch{return null}}function Va(r,t,s=rn()){if(!(!s||!r))try{s.setItem(nn+r,JSON.stringify(t))}catch{}}function Ya(r){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/acp/relay/${r}`}function za(r){const t=Ya(r),s=ir(),n=s?{proxyUrl:t,token:s}:{proxyUrl:t};return new or(n)}const Ie=[{value:"default",labelKey:"session.mode.default",descKey:"session.mode.defaultDesc"},{value:"acceptEdits",labelKey:"session.mode.acceptEdits",descKey:"session.mode.acceptEditsDesc"},{value:"plan",labelKey:"session.mode.plan",descKey:"session.mode.planDesc"},{value:"bypassPermissions",labelKey:"session.mode.bypass",descKey:"session.mode.bypassDesc"}],qs="rcs_permission_mode";function De(r){return r<1e3?String(r):r<1e6?`${(r/1e3).toFixed(1)}k`:`${(r/1e6).toFixed(1)}M`}function Ga(r){const t=Ie.findIndex(s=>s.value===r);return Ie[(t+1+Ie.length)%Ie.length].value}const yt=[{value:"off",labelKey:"session.thinking.off",descKey:"session.thinking.offDesc",label:void 0,description:void 0,tokens:0},{value:"on",labelKey:"session.thinking.on",descKey:"session.thinking.onDesc",label:void 0,description:void 0,tokens:null},{value:"8192",labelKey:void 0,descKey:void 0,label:"8k",description:"8192 tokens",tokens:8192},{value:"16384",labelKey:void 0,descKey:void 0,label:"16k",description:"16384 tokens",tokens:16384},{value:"32768",labelKey:void 0,descKey:void 0,label:"32k",description:"32768 tokens",tokens:32768}],Ps="rcs_thinking_budget",Dt=[{value:"auto",effort:void 0,labelKey:"session.effort.auto",descKey:"session.effort.autoDesc",label:void 0},{value:"low",effort:"low",labelKey:void 0,descKey:"session.effort.lowDesc",label:"low"},{value:"medium",effort:"medium",labelKey:void 0,descKey:"session.effort.mediumDesc",label:"medium"},{value:"high",effort:"high",labelKey:void 0,descKey:"session.effort.highDesc",label:"high"},{value:"xhigh",effort:"xhigh",labelKey:void 0,descKey:"session.effort.xhighDesc",label:"xhigh"},{value:"max",effort:"max",labelKey:void 0,descKey:"session.effort.maxDesc",label:"max"}],Os=r=>r.labelKey?i(r.labelKey):r.label,Fs=r=>r.labelKey?i(r.labelKey):r.label,Us="rcs_effort",Ks=[{value:"normal",descKey:"session.tokenMode.normalDesc"},{value:"poor",descKey:"session.tokenMode.poorDesc"},{value:"sa",descKey:"session.tokenMode.saDesc"}],Ls="rcs_token_mode";function Ja(r){return r!=null&&r.capabilities?r.capabilities:r?{file_search:!0,clear:!0,set_max_thinking_tokens:!0,get_context_usage:!0,stop_task:!0,set_model:!0,set_permission_mode:!0,interrupt:!0,end_session:!0,mcp_management:!0,remote_settings:!0,rewind:!0,resume:!0,set_effort:!0,set_token_mode:!1,side_question:!0}:{file_search:!1,clear:!0,set_max_thinking_tokens:!0,get_context_usage:!1,stop_task:!1,set_model:!0,set_permission_mode:!0,interrupt:!0,end_session:!1,mcp_management:!1,remote_settings:!1,rewind:!1,resume:!1,set_effort:!1,set_token_mode:!1,side_question:!1}}function Xa({budget:r,onBudgetChange:t,disabled:s}){const[n,a]=l.useState(!1),d=yt.find(c=>c.value===r);return e.jsxs(Je,{open:n,onOpenChange:a,children:[e.jsx(Xe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:s,className:"flex items-center gap-1.5 rounded-lg px-2 h-7 text-xs text-text-muted hover:text-text-primary hover:bg-surface-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed font-display",title:i("session.thinking.title"),children:[e.jsx(qt,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?Fs(d):i("session.thinking.fallback")}),n?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(et,{className:"h-3 w-3"})]})}),e.jsx(tt,{className:"w-64 p-1",align:"start",children:yt.map(c=>e.jsxs("button",{type:"button",onClick:()=>{t(c.value,c.tokens),a(!1)},className:"flex w-full items-start gap-2 rounded-md px-2.5 py-2 text-left hover:bg-surface-2 transition-colors",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 flex-shrink-0 items-center justify-center",children:r===c.value&&e.jsx(qe,{className:"h-3.5 w-3.5 text-brand-text"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:Fs(c)}),e.jsx("div",{className:"text-xs text-text-muted",children:c.descKey?i(c.descKey):c.description})]})]},c.value))})]})}function Za({effort:r,onEffortChange:t,disabled:s}){const[n,a]=l.useState(!1),d=Dt.find(c=>c.value===r);return e.jsxs(Je,{open:n,onOpenChange:a,children:[e.jsx(Xe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:s,className:"flex items-center gap-1.5 rounded-lg px-2 h-7 text-xs text-text-muted hover:text-text-primary hover:bg-surface-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed font-display",title:i("session.effort.title"),children:[e.jsx(Fr,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?Os(d):i("session.effort.fallback")}),n?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(et,{className:"h-3 w-3"})]})}),e.jsx(tt,{className:"w-64 p-1",align:"start",children:Dt.map(c=>e.jsxs("button",{type:"button",onClick:()=>{t(c.value),a(!1)},className:"flex w-full items-start gap-2 rounded-md px-2.5 py-2 text-left hover:bg-surface-2 transition-colors",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 flex-shrink-0 items-center justify-center",children:r===c.value&&e.jsx(qe,{className:"h-3.5 w-3.5 text-brand-text"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:Os(c)}),e.jsx("div",{className:"text-xs text-text-muted",children:i(c.descKey)})]})]},c.value))})]})}function eo({mode:r,onModeChange:t,disabled:s}){const[n,a]=l.useState(!1),d=Ks.find(c=>c.value===r);return e.jsxs(Je,{open:n,onOpenChange:a,children:[e.jsx(Xe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:s,className:"flex items-center gap-1.5 rounded-lg px-2 h-7 text-xs text-text-muted hover:text-text-primary hover:bg-surface-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed font-display",title:i("session.tokenMode.title"),children:[e.jsx(qr,{className:"h-3 w-3"}),e.jsx("span",{className:`max-w-24 truncate ${r!=="normal"?"font-medium text-brand-text":""}`,children:d?i(`session.tokenMode.${d.value}`):i("session.tokenMode.fallback")}),n?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(et,{className:"h-3 w-3"})]})}),e.jsx(tt,{className:"w-64 p-1",align:"start",children:Ks.map(c=>e.jsxs("button",{type:"button",onClick:()=>{t(c.value),a(!1)},className:"flex w-full items-start gap-2 rounded-md px-2.5 py-2 text-left hover:bg-surface-2 transition-colors",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 flex-shrink-0 items-center justify-center",children:r===c.value&&e.jsx(qe,{className:"h-3.5 w-3.5 text-brand-text"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:i(`session.tokenMode.${c.value}`)}),e.jsx("div",{className:"text-xs text-text-muted",children:i(c.descKey)})]})]},c.value))})]})}const to=new Set(["Free space","Autocompact buffer","Compact buffer"]),Bs=["bg-brand","bg-status-active","bg-status-success","bg-violet-500","bg-amber-500","bg-pink-500","bg-teal-500"];function so({usage:r}){const t=Math.min(100,Math.max(0,r.percentage)),s=t>=80,n=(r.categories??[]).filter(u=>!u.isDeferred&&!to.has(u.name)),a=(r.categories??[]).filter(u=>u.isDeferred),d=n.reduce((u,p)=>u+p.tokens,0),c=[`${H("session.context.tooltip",{used:De(r.totalTokens),max:De(r.rawMaxTokens)})}${r.model?` · ${r.model}`:""}`,...n.slice(0,8).map(u=>`${u.name}: ${De(u.tokens)}`),...a.slice(0,3).map(u=>`${u.name}${i("session.context.deferredSuffix")}: ${De(u.tokens)}`)];return e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-text-muted font-mono",title:c.join(`
|
|
82
|
+
`),children:[e.jsx("span",{className:"relative flex h-1.5 w-16 overflow-hidden rounded-full bg-surface-3",children:n.length>0?n.map((u,p)=>e.jsx("span",{className:s&&p===0?"bg-status-warning":Bs[p%Bs.length],style:{width:`${Math.min(100,Math.max(0,d>0?u.tokens/d*t:0))}%`}},u.name)):e.jsx("span",{className:`absolute inset-y-0 left-0 rounded-full transition-all ${s?"bg-status-warning":"bg-brand/70"}`,style:{width:`${t}%`}})}),e.jsxs("span",{children:[t,"%"]})]})}function no({models:r,currentModelId:t,onSelect:s,disabled:n}){const[a,d]=l.useState(!1),c=r.find(h=>h.modelId===t)??null,u=r.length>0,p=async h=>{s(h.modelId),d(!1)};return e.jsxs(Je,{open:a,onOpenChange:u?d:void 0,children:[e.jsx(Xe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:n||!u,className:"flex items-center gap-1.5 rounded-lg px-2 h-7 text-xs text-text-muted hover:text-text-primary hover:bg-surface-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed font-display",title:i("session.model.title"),children:[e.jsx(Gs,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-32 truncate",children:(c==null?void 0:c.name)??t??i("session.model.title")}),a?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(et,{className:"h-3 w-3"})]})}),e.jsx(tt,{className:"w-72 p-0",align:"start",children:e.jsx(jr,{models:r,currentModelId:t,onSelect:p,showSearch:r.length>5})})]})}function ro({mode:r,onModeChange:t,disabled:s}){const[n,a]=l.useState(!1),d=Ie.find(c=>c.value===r);return e.jsxs(Je,{open:n,onOpenChange:a,children:[e.jsx(Xe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:s,className:"flex items-center gap-1.5 rounded-lg px-2 h-7 text-xs text-text-muted hover:text-text-primary hover:bg-surface-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed font-display",title:i("session.mode.title"),children:[e.jsx(br,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?i(d.labelKey):r}),n?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(et,{className:"h-3 w-3"})]})}),e.jsx(tt,{className:"w-64 p-1",align:"start",children:Ie.map(c=>e.jsxs("button",{type:"button",onClick:()=>{t(c.value),a(!1)},className:"flex w-full items-start gap-2 rounded-md px-2.5 py-2 text-left hover:bg-surface-2 transition-colors",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 flex-shrink-0 items-center justify-center",children:r===c.value&&e.jsx(qe,{className:"h-3.5 w-3.5 text-brand-text"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:i(c.labelKey)}),e.jsx("div",{className:"text-xs text-text-muted",children:i(c.descKey)})]})]},c.value))})]})}function vo({sessionId:r,onBack:t}){var is;ae();const[s,n]=l.useState(null),[a,d]=l.useState(null),[c,u]=l.useState(""),[p,h]=l.useState(!1),[g,b]=l.useState(!1),[S,M]=l.useState(!1),[C,j]=l.useState(!1),[x,y]=l.useState(!1),[k,_]=l.useState(!1),[A,T]=l.useState(""),[w,E]=l.useState(0),$=l.useRef(null),[I,v]=l.useState({text:"",nonce:0}),[F,P]=l.useState(!1),[G,X]=l.useState(!1),[se,O]=l.useState(!1),[ne,_e]=l.useState(!1),[Ce,ue]=l.useState(0),[Te,Ee]=l.useState(0),[ie,oe]=l.useState([]),[V,ye]=l.useState(!1),[ge,re]=l.useState([]),[W,be]=l.useState(null),[Oe,st]=l.useState(()=>It()),[Y,nt]=l.useState(null),[je,Fe]=l.useState(()=>localStorage.getItem(Ps)||"off"),[rt,Ue]=l.useState(()=>Qa(r)),[Me,Ke]=l.useState(!0),[me,gt]=l.useState(null),[bt,at]=l.useState(null),[le,Re]=l.useState(null),[Ae,f]=l.useState([]),[K,Z]=l.useState(!1),[Le,Pt]=l.useState(""),jt=l.useRef(null),[ot,an]=l.useState(()=>localStorage.getItem(qs)||"default"),[Ot,Ft]=l.useState(null),Be=l.useRef(null),[Ut,Kt]=l.useState(null),He=l.useRef(null),ce=l.useRef(null),Lt=l.useRef(ie);Lt.current=ie;const it=l.useRef(null);it.current||(it.current=new Ar($r()));const Bt=l.useRef(r);Bt.current=(s==null?void 0:s.title)||r,l.useEffect(()=>{var o;(o=it.current)==null||o.reset()},[r]);const de=l.useCallback(o=>{Ft(o),Be.current&&clearTimeout(Be.current),Be.current=setTimeout(()=>Ft(null),5e3)},[]),xe=l.useCallback(o=>{Kt(o),He.current&&clearTimeout(He.current),He.current=setTimeout(()=>Kt(null),5e3)},[]),lt=xt({value:ot,apply:o=>{an(o);try{localStorage.setItem(qs,o)}catch{}},send:o=>{const m=ce.current;return m?m.setPermissionMode(o):Promise.reject(new Error("adapter not ready"))},onError:(o,m)=>{console.error("[SessionDetail] set permission mode failed:",o),de(m==="send"?H("session.mode.switchFailedRequest",{message:o}):o||i("session.mode.switchFailed"))}}),wt=l.useCallback(o=>lt.set(o),[lt]),[Ht,on]=l.useState(()=>localStorage.getItem(Ls)||"normal"),ct=xt({value:Ht,apply:o=>{on(o);try{localStorage.setItem(Ls,o)}catch{}},send:o=>{const m=ce.current;return m?m.setTokenMode(o):Promise.reject(new Error("adapter not ready"))},onError:(o,m)=>{console.error("[SessionDetail] set token mode failed:",o),de(m==="send"?H("session.tokenMode.failedRequest",{message:o}):o||i("session.tokenMode.failed"))}}),vt=xt({value:je,apply:o=>{Fe(o);try{localStorage.setItem(Ps,o)}catch{}},send:o=>{var R;const m=ce.current;if(!m)return Promise.reject(new Error("adapter not ready"));const N=((R=yt.find(D=>D.value===o))==null?void 0:R.tokens)??null;return m.setThinkingBudget(N)},onError:(o,m)=>{console.error("[SessionDetail] set thinking budget failed:",o),de(m==="send"?H("session.thinking.failedRequest",{message:o}):o||i("session.thinking.failed"))}}),U=l.useMemo(()=>new la(r,oe,{onStatusChange:o=>{var m;d(o),ye(o==="running"||o==="requires_action"),(m=it.current)==null||m.onStatus(o,Bt.current)},onError:o=>{console.error("[RCSChatAdapter] error:",o)},onPermissionRequest:o=>{re(m=>m.some(N=>N.requestId===o.requestId)?m:[...m,o])},onModelsStateChange:o=>{be(o)},onSubagentUpdate:o=>{st(o)},onControlResponse:o=>{vt.handleControlResponse(o)||ct.handleControlResponse(o)||zt.handleControlResponse(o)||lt.handleControlResponse(o)},onPermissionModeChange:o=>{lt.sync(o)},onUsageChange:o=>{gt(m=>({inputTokens:Math.max((m==null?void 0:m.inputTokens)??0,o.inputTokens),outputTokens:Math.max((m==null?void 0:m.outputTokens)??0,o.outputTokens),totalCostUsd:o.totalCostUsd??(m==null?void 0:m.totalCostUsd)??null}))},onWorkerInfoChange:o=>{nt(m=>JSON.stringify(m)===JSON.stringify(o)?m:o)},onTurnStart:o=>{at(o)},onElicitationRequest:o=>{Re(o)}}),[r,de]);l.useEffect(()=>(ce.current=U,()=>{U.disconnect()}),[U]);const L=l.useMemo(()=>Ja(Y),[Y]),Wt=l.useRef(!1);l.useEffect(()=>{var N;if(!L.set_max_thinking_tokens||Wt.current)return;const o=ce.current;if(!o)return;const m=((N=yt.find(R=>R.value===je))==null?void 0:N.tokens)??null;o.setThinkingBudget(m).then(()=>{Wt.current=!0}).catch(R=>console.error("[SessionDetail] reconcile thinking budget failed:",R))},[L.set_max_thinking_tokens,je,Y]);const Qt=L.stop_task?o=>{U.stopSubagent(o).then(m=>{m.ok||xe(m.error||i("session.stopTask.failed"))})}:void 0,Vt=l.useRef(!1);l.useEffect(()=>{if(!L.set_token_mode||Vt.current)return;const o=ce.current;o&&(Vt.current=!0,o.getRemoteSettings().then(m=>{const N=m==null?void 0:m.applied.tokenMode;(N==="normal"||N==="poor"||N==="sa")&&ct.sync(N)}).catch(m=>console.error("[SessionDetail] reconcile token mode failed:",m)))},[L.set_token_mode,ct]);const ln=ae(),kt=l.useMemo(()=>lr((Y==null?void 0:Y.commands)??[],(Y==null?void 0:Y.skills)??[]),[Y,ln]),We=l.useMemo(()=>cr(ie,A),[ie,A]),cn=l.useCallback(o=>vt.set(o),[vt]),[Yt,dn]=l.useState(()=>localStorage.getItem(Us)||"auto"),zt=xt({value:Yt,apply:o=>{dn(o);try{localStorage.setItem(Us,o)}catch{}},send:o=>{var R;const m=ce.current;if(!m)return Promise.reject(new Error("adapter not ready"));const N=(R=Dt.find(D=>D.value===o))==null?void 0:R.effort;return m.setEffort(N)},onError:(o,m)=>{console.error("[SessionDetail] set effort failed:",o),de(m==="send"?H("session.effort.failedRequest",{message:o}):o||i("session.effort.failed"))}}),Nt=l.useCallback(()=>{var o;L.get_context_usage&&((o=ce.current)==null||o.getContextUsage().then(m=>{m&&(Ue(m),Va(r,m))}).catch(()=>{}).finally(()=>Ke(!1)))},[L,r]);l.useEffect(()=>{if(!L.get_context_usage)return;Nt();const o=setInterval(Nt,6e4);return()=>clearInterval(o)},[L,V,Nt]),l.useEffect(()=>{Y&&!L.get_context_usage&&Ke(!1)},[Y,L]),l.useEffect(()=>{if(!Me)return;const o=setTimeout(()=>Ke(!1),1e4);return()=>clearTimeout(o)},[Me]);const Gt=l.useRef(se);Gt.current=se,l.useEffect(()=>fe.onEvent(m=>{m.type!=="artifact_created"&&m.type!=="artifact_updated"||(Gt.current&&Ee(N=>N+1),ue(N=>N+1))}),[]);const[Jt,dt]=l.useState(0),Xt=l.useRef(ne);Xt.current=ne;const[Qe,Zt]=l.useState(null),[pe,St]=l.useState(!1),[_t,es]=l.useState(0),[un,mn]=l.useState(void 0),Ct=l.useRef(pe);Ct.current=pe,l.useEffect(()=>fe.onEvent(m=>{m.type==="memory_synced"&&Xt.current&&dt(N=>N+1)}),[]),l.useEffect(()=>{Vs().then(o=>Zt(o.mode)).catch(()=>Zt("sqlite"))},[]),l.useEffect(()=>fe.onEvent(m=>{var N,R;if(m.type==="memory_changed")Ct.current?dt(D=>D+1):es(D=>D+1);else if(m.type==="memory_recall"){const D=Array.isArray((N=m.payload)==null?void 0:N.hits)?m.payload.hits:void 0;D&&mn({query:typeof((R=m.payload)==null?void 0:R.query)=="string"?m.payload.query:"",hits:D}),Ct.current&&dt(Q=>Q+1)}}),[]),l.useEffect(()=>{pe&&es(0)},[pe]);const[Ve,xn]=l.useState("idle");l.useEffect(()=>fe.onStateChange(m=>xn(m)),[]),l.useEffect(()=>{se&&ue(0)},[se]),l.useEffect(()=>{let o=!1;async function m(){u("");try{const N=await hs(r);if(o)return;n(N),d(N.status),pt(N.status)&&U.markClosed(),ye(N.status==="running"||N.status==="requires_action")}catch(N){if(o)return;u(N instanceof Error?N.message:i("session.loadFailed"));return}try{await U.init()}catch(N){console.warn("Failed to init adapter:",N)}}return m(),()=>{o=!0}},[r,U]);const B=pt(a),ts=l.useRef(a);ts.current=a,l.useEffect(()=>{if(B)return;let o=!1;const N=setInterval(async()=>{try{const R=await hs(r);if(o||R.status===ts.current)return;pt(R.status)&&U.markClosed(),d(R.status),ye(R.status==="running"||R.status==="requires_action")}catch{}},6e4);return()=>{o=!0,clearInterval(N)}},[r,B,U]);const z=(s==null?void 0:s.access_level)==="read",ss=rt??(Me&&!B&&!z?Ds():null),Tt=l.useCallback(()=>{oe([]),Ue(Ds()),ps(r).catch(o=>{console.warn("[SessionDetail] Failed to clear session history:",o)})},[r]),Ye=l.useCallback(async(o,m)=>{const N=ce.current;if(!N||B)return;if(o.sessionId===r){oe(D=>[...D,{type:"command_output",id:`cmd-resume-${Date.now()}`,commandName:"resume",inputText:m??"/resume",title:"Resume",subtitle:i("session.resume.title"),outputText:i("session.resume.currentBlocked"),variant:"error"}]);return}const R=(D,Q="default")=>oe(we=>[...we,{type:"command_output",id:`cmd-resume-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,commandName:"resume",inputText:m??`/resume ${o.sessionId.slice(0,8)}`,title:"Resume",subtitle:i("session.resume.title"),outputText:D,variant:Q}]);R(H("session.resume.restoring",{title:o.title??""}));try{await ps(r),oe([]);const D=await N.resumeSession(o.sessionId);R(D.title?H("session.resume.restoredWithTitle",{count:D.messageCount,title:D.title}):H("session.resume.restored",{count:D.messageCount}))}catch(D){R(H("session.resume.failed",{message:D instanceof Error?D.message:String(D)}),"error")}},[B,r]),pn=l.useCallback(async()=>{if(s!=null&&s.environment_id)try{const o=await dr({environment_id:s.environment_id});window.location.href=`/code/${o.id}?resumeFrom=${r}`}catch(o){xe(H("session.createFailedWithReason",{message:o instanceof Error?o.message:String(o)}))}},[s,r,xe]),fn=l.useRef(new URLSearchParams(window.location.search).get("resumeFrom")),ns=l.useRef(!1);l.useEffect(()=>{const o=fn.current;!o||ns.current||!Y||!L.resume||(ns.current=!0,window.history.replaceState({},"",window.location.pathname),Ye({sessionId:o,title:o.slice(0,8),modified:0},null))},[Y,L.resume,Ye]);const $e=l.useCallback(async o=>{const m=o.text.trim(),N=o.images&&o.images.length>0||o.attachments&&o.attachments.length>0;if(!m&&!N||B)return;const R=/^\/resume(?:\s+(.*))?$/.exec(m);if(R){const Q=(R[1]??"").trim();if(!L.resume){oe(we=>[...we,{type:"user_message",id:`user-${Date.now()}`,content:m},{type:"command_output",id:`cmd-${Date.now()}`,commandName:"resume",inputText:m,title:"Resume",subtitle:i("session.resume.title"),outputText:i("session.resume.unsupported"),variant:"error"}]);return}Q?await Ye({sessionId:Q,title:Q,modified:0},m):y(!0);return}const D=await ur(m,{sessionId:r,availableCommands:kt,availableModels:(W==null?void 0:W.availableModels)??[],currentModel:W?{modelId:W.currentModelId,name:W.currentModelId}:null,supportsImages:!0,entries:Lt.current,setModel:async Q=>{await ee(r,{type:"control_request",request:{subtype:"set_model",model:Q}}),be(we=>we&&{...we,currentModelId:Q})},onNewSession:()=>{oe([])}}).catch(()=>null);if(D){if(ft("[SessionDetail] local command result",D),"clearEntries"in D&&D.clearEntries){Tt();return}if("newSession"in D&&D.newSession){Tt();return}if("userEntry"in D){oe(Q=>[...Q,D.userEntry,D.cmdEntry]);return}}ye(!0);try{await U.sendMessage(m,o.images,o.attachments)}catch(Q){if(console.error("Send failed:",Q),Q instanceof mr&&Q.type==="session_closed"){d("archived"),U.markClosed(),xe(i("session.closedSendBlocked"));return}xe(`${i("session.sendFailed")}${Q instanceof Error?`: ${Q.message}`:""}`)}},[U,B,r,W,kt,Tt,xe,Ye,L]),hn=l.useCallback(o=>{if(V){f(m=>[...m,o]);return}$e(o)},[V,$e]),[Et,rs]=l.useState(!1),yn=l.useCallback(()=>{V||(rs(!0),$e({text:"/dream"}))},[V,$e]);l.useEffect(()=>{!V&&Et&&(rs(!1),dt(o=>o+1))},[V,Et]);const Mt=l.useRef(!1);l.useEffect(()=>{if(B){f(m=>m.length>0?[]:m);return}if(V||Ae.length===0||Mt.current)return;const o=Ae[0];o&&(Mt.current=!0,f(m=>m.slice(1)),$e(o).finally(()=>{Mt.current=!1}))},[V,Ae,$e,B]);const gn=l.useCallback((o,m)=>{if(V)return;const N=m==="edit"?i("session.rewind.confirmEdit"):i("session.rewind.confirm");window.confirm(`${N}
|
|
83
|
+
${i("session.rewind.confirmBody")}`)&&U.rewindToMessage(o.id).then(()=>{m==="edit"&&o.content&&v(R=>({text:o.content,nonce:R.nonce+1}))}).catch(R=>{console.error("[SessionDetail] rewind failed:",R),xe(H("session.rewind.failed",{message:R instanceof Error?R.message:String(R)}))})},[V,xe]),bn=l.useCallback(o=>{const m=We.orderedMatchIds;if(m.length===0)return;const N=(o%m.length+m.length)%m.length;E(N);const R=m[N],D=document.querySelector(`[data-entry-id="${CSS.escape(R)}"]`);D==null||D.scrollIntoView({block:"center",behavior:"smooth"})},[We]),as=l.useCallback(async()=>{try{await U.interrupt()}catch(o){console.error("Interrupt failed:",o)}finally{ye(!1)}},[U]),jn=l.useCallback(()=>{wt(Ga(ot))},[wt,ot]);l.useEffect(()=>()=>{Be.current&&clearTimeout(Be.current),He.current&&clearTimeout(He.current)},[]);const wn=l.useCallback(async()=>{if(s&&window.confirm(i("dashboard.confirmDelete").replace("{id}",s.title||s.id)))try{await fs(s.id),window.location.href="/code/"}catch(o){alert(o instanceof Error?o.message:i("dashboard.deleteFailed"))}},[s]),vn=l.useCallback(async o=>{try{await U.respondPermission(o,!0)}catch(m){console.error("Failed to approve:",m)}re(m=>m.filter(N=>N.requestId!==o))},[U]),kn=l.useCallback(async(o,m)=>{try{await U.respondPermission(o,!0,{updated_permissions:m})}catch(N){console.error("Failed to approve with rules:",N)}re(N=>N.filter(R=>R.requestId!==o))},[U]),Nn=l.useCallback(async(o,m)=>{const N=le;if(Re(null),!!N)try{await U.respondElicitation(N.requestId,o,m)}catch(R){console.error("Failed to submit elicitation:",R)}},[le,U]),Sn=l.useCallback(()=>{!s||z||(Pt(s.title||""),Z(!0),setTimeout(()=>{var o,m;(o=jt.current)==null||o.focus(),(m=jt.current)==null||m.select()},0))},[s,z]),os=l.useCallback(async()=>{const o=Le.trim();if(Z(!1),!(!s||!o||o===s.title))try{const m=await xr(s.id,o);n(N=>N&&{...N,title:m.title??o})}catch(m){console.error("Rename failed:",m),alert(m instanceof Error?m.message:i("session.rename.failed"))}},[s,Le]),_n=l.useCallback(async o=>{try{await U.respondPermission(o,!1)}catch(m){console.error("Failed to reject:",m)}re(m=>m.filter(N=>N.requestId!==o))},[U]),Cn=l.useCallback(async(o,m,N)=>{try{await ee(r,{type:"permission_response",approved:!0,request_id:o,updated_input:{questions:N,answers:m}})}catch(R){console.error("Failed to submit answers:",R)}re(R=>R.filter(D=>D.requestId!==o))},[r]),Tn=l.useCallback(async(o,m,N)=>{try{m==="no"?await ee(r,{type:"permission_response",approved:!1,request_id:o,...N?{message:N}:{}}):await ee(r,{type:"permission_response",approved:!0,request_id:o,updated_permissions:[{type:"setMode",mode:{"yes-accept-edits":"acceptEdits","yes-default":"default"}[m]||"default",destination:"session"}]})}catch(R){console.error("Failed to submit plan response:",R)}re(R=>R.filter(D=>D.requestId!==o))},[r]);return c?e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(mt,{onBack:t,title:e.jsx("span",{className:"text-xs font-medium text-text-muted",children:i("session.loadFailed")})}),e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-status-error",children:c}),e.jsx("a",{href:"/code/",className:"mt-4 inline-block text-brand-text hover:underline",children:i("session.backToDashboard")})]})})]}):s?s.source==="acp"&&s.environment_id?e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx("h1",{className:"sr-only",children:s.title||s.id}),e.jsx(mt,{onBack:t,title:e.jsx("span",{className:"truncate text-xs font-semibold text-text-primary",children:s.title||s.id}),meta:e.jsx("span",{className:"rounded-full bg-brand/15 px-2 py-0.5 text-[10px] font-medium text-brand-text",children:"ACP"})}),e.jsx(oo,{sessionId:r,agentId:s.environment_id})]}):e.jsx(Ys,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx("h1",{className:"sr-only",children:s.title||s.id}),e.jsx(mt,{onBack:t,title:K?e.jsx("input",{ref:jt,value:Le,onChange:o=>Pt(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),os()):o.key==="Escape"&&(o.preventDefault(),Z(!1))},onBlur:()=>void os(),maxLength:200,className:"w-full max-w-xs rounded-md border border-brand/50 bg-surface-2 px-2 py-0.5 text-xs font-semibold text-text-primary focus:outline-none focus:ring-2 focus:ring-brand/30"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex min-w-0 items-center gap-2 text-xs font-semibold text-text-primary",children:!z&&!B?e.jsx("button",{type:"button",onClick:Sn,title:i("session.rename.title"),className:"truncate text-left transition-colors hover:text-text-secondary",children:s.title||s.id}):e.jsx("span",{className:"truncate",children:s.title||s.id})}),s.visibility&&e.jsx(Mr,{visibility:s.visibility||"private",className:"hidden flex-shrink-0 text-[10px] sm:inline-flex"})]}),meta:e.jsx(e.Fragment,{children:(()=>{var N;const o=s.source==="acp"?"acp":(N=s.environment)==null?void 0:N.worker_type,m=ys(o);return e.jsx("span",{className:`hidden items-center rounded-full px-2 py-0.5 text-[10px] font-medium sm:inline-flex ${m.colorClass}`,children:m.fullLabel})})()}),actions:e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsxs("button",{onClick:()=>O(!se),className:`relative flex h-7 w-7 items-center justify-center rounded-md transition-colors ${se?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("artifacts.title"),children:[e.jsx(pr,{className:"h-3.5 w-3.5"}),Ce>0&&!se&&e.jsx("span",{className:"absolute -right-0.5 -top-0.5 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-brand px-0.5 text-[10px] font-bold text-white",children:Ce>9?"9+":Ce})]}),e.jsxs("button",{onClick:()=>{Qe==="memdir"?St(!pe):_e(!ne)},className:`relative flex h-7 w-7 items-center justify-center rounded-md transition-colors ${Qe==="memdir"?pe?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary":ne?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("memories.title"),children:[e.jsx(qt,{className:"h-3.5 w-3.5"}),Qe==="memdir"&&_t>0&&!pe&&e.jsx("span",{className:"absolute -right-0.5 -top-0.5 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-brand px-0.5 text-[10px] font-bold text-white",children:_t>9?"9+":_t})]}),L.side_question&&!B&&!z&&e.jsx("button",{onClick:()=>j(!C),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${C?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("session.sideQuestion.title"),children:e.jsx(Js,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>{const o=!k;_(o),o?setTimeout(()=>{var m;return(m=$.current)==null?void 0:m.focus()},0):(T(""),E(0))},className:`flex h-7 w-7 items-center justify-center rounded-md transition-colors ${k?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("session.search.title"),children:e.jsx(ht,{className:"h-3.5 w-3.5"})}),L.mcp_management&&!B&&!z&&e.jsx("button",{onClick:()=>b(!g),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${g?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("session.mcp.title"),children:e.jsx(Xs,{className:"h-3.5 w-3.5"})}),L.remote_settings&&!B&&!z&&e.jsx("button",{onClick:()=>M(!S),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${S?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:i("session.settings.title"),children:e.jsx(Zs,{className:"h-3.5 w-3.5"})}),!z&&(s==null?void 0:s.access_level)!=="write"&&e.jsx("button",{onClick:()=>X(!0),className:"flex h-7 w-7 items-center justify-center rounded-md text-text-muted hover:bg-surface-2 hover:text-text-secondary transition-colors",title:i("session.share"),children:e.jsx(sa,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>P(!F),className:"hidden h-7 w-7 items-center justify-center rounded-md text-text-muted hover:bg-surface-2 hover:text-text-secondary transition-colors sm:flex",title:i("session.info"),children:e.jsx(Br,{className:"h-3.5 w-3.5"})}),e.jsxs("button",{onClick:()=>h(!p),className:"ml-0.5 flex items-center gap-1 rounded-md px-2 py-1 text-xs font-semibold text-text-primary hover:bg-brand-light hover:text-white transition-colors",children:[i("session.tasks"),ge.length>0&&e.jsx("span",{className:"rounded-full bg-status-warning/15 px-1.5 py-0.5 text-[10px] font-medium text-status-warning",children:ge.length})]})]})})}),F&&e.jsx("div",{className:"flex-shrink-0 border-b bg-surface-1 py-2",children:e.jsx("div",{className:"mx-auto page-measure px-4 sm:px-8",children:e.jsxs("div",{className:"rounded-md bg-surface-2 px-3 py-2 text-xs text-text-muted space-y-1 font-mono [overflow-wrap:anywhere]",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:i("session.metaSession")})," ",s.id]}),s.environment_id&&e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:i("session.metaEnvironment")})," ",s.environment_id]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:i("session.metaStatus")})," ",a]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:i("session.metaWorker")})," ",ys(s.source==="acp"?"acp":(is=s.environment)==null?void 0:is.worker_type).fullLabel]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:i("session.metaCreated")})," ",Ws(s.created_at)]})]})})}),(Ve==="reconnecting"||Ve==="failed")&&e.jsxs("div",{className:`flex items-center justify-center gap-2 px-4 py-1.5 text-xs font-medium ${Ve==="failed"?"bg-status-error/10 text-status-error":"bg-status-warning/10 text-status-warning"}`,children:[e.jsx("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${Ve==="failed"?"bg-status-error":"animate-pulse bg-status-warning"}`}),Ve==="failed"?i("session.sseFailed"):i("session.sseReconnecting")]}),se&&e.jsx("div",{className:"border-b bg-surface-1 py-4",children:e.jsx("div",{className:"mx-auto page-measure px-4 sm:px-8",children:e.jsx(Er,{sessionId:r,embedded:!0,refreshTick:Te})})}),ne&&Qe!=="memdir"&&e.jsx("div",{className:"border-b bg-surface-1 py-4",children:e.jsx("div",{className:"mx-auto page-measure px-4 sm:px-8",children:e.jsx(Rr,{sessionId:r,embedded:!0,refreshTick:Jt})})}),k&&e.jsx("div",{className:"border-b bg-surface-1 py-2",children:e.jsxs("div",{className:"mx-auto flex page-measure px-4 sm:px-8 items-center gap-2",children:[e.jsx(ht,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{ref:$,value:A,onChange:o=>{T(o.target.value),E(0)},onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),bn(A&&o.shiftKey?w-1:w+1)):o.key==="Escape"&&(o.preventDefault(),_(!1),T(""))},placeholder:i("session.search.placeholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"}),A.trim()&&e.jsx("span",{className:"flex-shrink-0 font-mono text-[10px] text-text-muted",children:We.orderedMatchIds.length===0?i("session.search.noResults"):`${w+1}/${We.orderedMatchIds.length}`})]})}),e.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:e.jsx(fr,{entries:ie,isLoading:V,turnStartedAt:bt,emptyTitle:i("session.emptyTitle"),emptyDescription:i("session.emptyDescription"),searchMatchIds:A.trim()?We.matchIds:void 0,onRewindEntry:L.rewind&&!B&&!z&&!V?(o,m)=>gn(o,m):void 0})}),Qe==="memdir"&&e.jsx(ke,{open:pe,onOpenChange:St,children:e.jsxs(Ne,{showCloseButton:!1,"data-testid":"memory-sidebar",className:"fixed inset-y-0 left-0 top-auto right-auto translate-x-0 translate-y-0 flex h-full w-full flex-col overflow-hidden rounded-none border-r border-border bg-surface-1 p-0 max-w-none max-h-none sm:w-96 sm:max-w-md",children:[e.jsx(Se,{className:"sr-only",children:i("memorySidebar.title")}),e.jsx("div",{className:"flex flex-shrink-0 items-center justify-end px-2 pt-2 sm:hidden",children:e.jsx("button",{type:"button",onClick:()=>St(!1),className:"flex h-8 w-8 items-center justify-center rounded-md text-text-muted hover:bg-surface-2 hover:text-text-primary","aria-label":i("common.close"),title:i("common.close"),children:e.jsx(Hs,{className:"h-4 w-4"})})}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:e.jsx(Ba,{refreshTick:Jt,recall:un,dreaming:V&&Et,onDreamTrigger:yn})})]})}),e.jsx(xa,{state:Oe,onStopTask:Qt}),ge.length>0&&e.jsx("div",{className:"border-t bg-surface-1 py-3",children:e.jsx("div",{className:"mx-auto page-measure px-4 sm:px-8 space-y-3",children:ge.map(o=>e.jsx(ao,{request:o,onApprove:()=>vn(o.requestId),onApproveAlways:o.suggestions&&o.suggestions.length>0?()=>kn(o.requestId,o.suggestions??[]):void 0,onReject:()=>_n(o.requestId),onSubmitAnswers:Cn,onSubmitPlan:Tn},o.requestId))})}),le&&e.jsx("div",{className:"border-t bg-surface-1 py-3",children:e.jsx("div",{className:"mx-auto page-measure px-4 sm:px-8",children:e.jsx(Aa,{request:le,onSubmit:Nn})})}),Ut&&e.jsx("div",{className:"mx-auto page-measure w-full px-4 sm:px-8 pb-1",children:e.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 px-3 py-1.5 text-xs text-red-700 dark:text-red-300",children:Ut})}),Ot&&e.jsx("div",{className:"mx-auto page-measure w-full px-4 sm:px-8 pb-1",children:e.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 px-3 py-1.5 text-xs text-red-700 dark:text-red-300",children:Ot})}),e.jsxs("div",{className:"page-measure mx-auto w-full px-4 sm:px-8 pb-1 flex flex-wrap items-center justify-between gap-x-1 gap-y-1.5",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1",children:[e.jsx(ro,{mode:ot,onModeChange:wt,disabled:B||z}),e.jsx(no,{models:(W==null?void 0:W.availableModels)??[],currentModelId:(W==null?void 0:W.currentModelId)??null,onSelect:o=>{ee(r,{type:"control_request",request:{subtype:"set_model",model:o}}),be(m=>m&&{...m,currentModelId:o})},disabled:B||z}),L.set_max_thinking_tokens&&e.jsx(Xa,{budget:je,onBudgetChange:cn,disabled:B||z}),L.set_effort&&e.jsx(Za,{effort:Yt,onEffortChange:o=>zt.set(o),disabled:B||z}),L.set_token_mode&&e.jsx(eo,{mode:Ht,onModeChange:o=>ct.set(o),disabled:B||z})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-3",children:[ss&&e.jsx(so,{usage:ss}),me&&e.jsxs("span",{className:"hidden text-[10px] text-text-muted font-mono sm:inline",title:i("session.usage.total"),children:[De(me.inputTokens)," in / ",De(me.outputTokens)," out",me.totalCostUsd!=null&&` · $${me.totalCostUsd.toFixed(2)}`]})]})]}),B&&(s==null?void 0:s.environment_id)&&e.jsx("div",{className:"mx-auto w-full page-measure px-4 pb-2 sm:px-8",children:e.jsx("button",{type:"button",onClick:()=>void pn(),className:"w-full rounded-lg border border-border bg-surface-1 px-4 py-2.5 text-sm text-text-secondary transition-colors hover:bg-surface-2 hover:text-text-primary",children:i("session.resumeInNew")})}),e.jsx(hr,{onSubmit:hn,isLoading:V,onInterrupt:as,onCycleMode:jn,disabled:B||z,placeholder:B?i("session.closed"):z?i("session.readOnly"):i("session.inputPlaceholder"),supportsAttachments:!0,commands:kt,queueWhileLoading:!0,queuedCount:Ae.length,onDequeue:o=>f(m=>m.filter((N,R)=>R!==o)),onSearchFiles:L.file_search?o=>U.searchFiles(o):void 0,historyKey:r,draftOverride:I}),g&&e.jsx(va,{onClose:()=>b(!1),fetchServers:()=>U.getMcpServers(),onToggle:(o,m)=>U.toggleMcpServer(o,m),onReconnect:o=>U.reconnectMcpServer(o)}),S&&e.jsx(Sa,{onClose:()=>M(!1),fetchSettings:()=>U.getRemoteSettings(),onApply:o=>U.applyFlagSettings(o)}),C&&e.jsx(_a,{onClose:()=>j(!1),onAsk:o=>U.askSideQuestion(o)}),p&&s&&e.jsx(ha,{onClose:()=>h(!1),session:s,liveStatus:a,pendingPermissions:ge,subagentState:Oe,onStopTask:Qt,onInterrupt:as,onDelete:wn,onEndSession:L.end_session&&!B&&!z?async()=>{await U.endSession("ended from web"),await fs(s.id),window.location.href="/code/"}:void 0}),e.jsx(qa,{open:G,onClose:()=>X(!1),sessionId:s.id,sessionTitle:s.title||void 0}),e.jsx(Fa,{open:x,onClose:()=>y(!1),adapter:U,onResume:o=>{y(!1),Ye(o,null)}})]})}):e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(mt,{onBack:t,title:e.jsx("span",{className:"h-3.5 w-40 animate-pulse rounded bg-surface-2"})}),e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx("div",{className:"text-text-muted",children:i("session.loading")})})]})}function ao({request:r,onApprove:t,onApproveAlways:s,onReject:n,onSubmitAnswers:a,onSubmitPlan:d}){const c=r.toolName,u=r.toolInput,p=r.description||"";if(c==="AskUserQuestion"){const h=u.questions||[];return e.jsx(Ta,{requestId:r.requestId,questions:h,description:p,onSubmit:g=>a(r.requestId,g,h),onSkip:n})}if(c==="ExitPlanMode"){const h=u.plan||"";return e.jsx(Ma,{requestId:r.requestId,planContent:h,description:p,onSubmit:(g,b)=>d(r.requestId,g,b)})}return e.jsx(Ca,{requestId:r.requestId,toolName:c,toolInput:u,description:p,suggestions:r.suggestions,onApprove:t,onApproveAlways:s,onReject:n})}function oo({sessionId:r,agentId:t}){const[s,n]=l.useState(null),[a,d]=l.useState("disconnected"),[c,u]=l.useState(null),p=l.useRef(null);return l.useEffect(()=>{const h=za(t);return h.setConnectionStateHandler((g,b)=>{d(g),u(b||null)}),p.current=h,n(h),h.connect().catch(g=>{g instanceof yr||(u(g.message),d("error"))}),()=>{h.disconnect(),p.current=null,n(null),d("disconnected")}},[t]),e.jsx(Ys,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[c&&a==="error"&&e.jsx("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm border-b",children:c}),a==="connecting"&&e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin h-8 w-8 border-2 border-brand border-t-transparent rounded-full mx-auto mb-3"}),e.jsx("p",{className:"text-text-muted text-sm",children:i("session.connectingAgent")})]})}),a==="error"&&!s&&e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"font-medium mb-1",children:i("session.connectionFailed")}),e.jsx("p",{className:"text-text-muted text-sm",children:c})]})}),s&&a==="connected"&&e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(gr,{client:s,agentId:t})})]})})}export{vo as SessionDetail};
|