@saluzi/saluzi-edu 0.6.0 → 0.6.1
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 +62 -62
- package/dist/rcs-web/assets/{AdminPanel-D0fVkpU2.js → AdminPanel-YIhNS5Qr.js} +1 -1
- package/dist/rcs-web/assets/{ArtifactView-DG0-kZ2G.js → ArtifactView-wAwsEOXp.js} +1 -1
- package/dist/rcs-web/assets/{ArtifactsGallery-CcobkOm1.js → ArtifactsGallery-DIp4aSOX.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/Claim-CltNvmRS.js → dist/rcs-web/assets/Claim-DJ4tizsL.js} +1 -1
- package/dist/rcs-web/assets/{Dashboard-CEzuQ0N4.js → Dashboard-BLV5zTyh.js} +1 -1
- package/dist/rcs-web/assets/{Join-DX0LzcPE.js → Join-B91AXtrD.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/Login-BVKB4X_Z.js → dist/rcs-web/assets/Login-CWFOyYxU.js} +1 -1
- package/dist/rcs-web/assets/{Register-D-BrLVl3.js → Register-BaQgCZnM.js} +1 -1
- package/dist/rcs-web/assets/{RegisterEmpty-DdDXaiEn.js → RegisterEmpty-VAnkkhxE.js} +1 -1
- package/dist/rcs-web/assets/{SessionDetail-BkKSNMD8.js → SessionDetail-CvkeGPev.js} +20 -20
- package/dist/rcs-web/assets/{SessionVisibilityBadge-Ch3s2iFY.js → SessionVisibilityBadge-SoKp2ads.js} +1 -1
- package/dist/rcs-web/assets/{Setup-CyGhRI5L.js → Setup-CuKeura-.js} +1 -1
- package/dist/rcs-web/assets/{ShareLanding-xKcBqmJb.js → ShareLanding-CcFoMs-8.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/TeamDetail-C3Ne25hE.js → dist/rcs-web/assets/TeamDetail-Cwer75cF.js} +1 -1
- package/dist/rcs-web/assets/{TeamList-C5Zyrj2-.js → TeamList-zWC3UYCg.js} +1 -1
- package/dist/rcs-web/assets/{TeamSettings-BsT93PQO.js → TeamSettings-C8PMmj1J.js} +1 -1
- package/dist/rcs-web/assets/{UserSearchInput-BFpwaVmp.js → UserSearchInput-OP0ex0JY.js} +1 -1
- package/dist/rcs-web/assets/{UserSettings-cIzS243Z.js → UserSettings-Bk0df0IW.js} +1 -1
- package/dist/rcs-web/assets/{arc-CiWQl09E.js → arc-LA1YluYC.js} +1 -1
- package/dist/rcs-web/assets/{architectureDiagram-3BPJPVTR-DL5Id6fa.js → architectureDiagram-3BPJPVTR-BX0GtZq3.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/blockDiagram-GPEHLZMM-DF-nk9Fe.js → dist/rcs-web/assets/blockDiagram-GPEHLZMM-DOEtgiur.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/c4Diagram-AAUBKEIU-l_Pl6m2J.js → dist/rcs-web/assets/c4Diagram-AAUBKEIU-B4yXmB4r.js} +1 -1
- package/dist/rcs-web/assets/channel-BSkZH-Bh.js +1 -0
- package/dist/rcs-web/assets/{chunk-2J33WTMH-Dr5xQSXu.js → chunk-2J33WTMH-BTtQR0Cy.js} +1 -1
- package/dist/rcs-web/assets/{chunk-4BX2VUAB-DAPTU1FG.js → chunk-4BX2VUAB-1HwNFe2a.js} +1 -1
- package/dist/rcs-web/assets/{chunk-55IACEB6-BgaGrvZR.js → chunk-55IACEB6-BZNQqhIb.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/chunk-727SXJPM-D6dnSxU3.js → dist/rcs-web/assets/chunk-727SXJPM-CYhzt0io.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/chunk-AQP2D5EJ-BVCad_JN.js → dist/rcs-web/assets/chunk-AQP2D5EJ-DHrz4pCx.js} +1 -1
- package/dist/rcs-web/assets/{chunk-FMBD7UC4-BNLx608W.js → chunk-FMBD7UC4-CaPwOz97.js} +1 -1
- package/dist/rcs-web/assets/{chunk-ND2GUHAM-BAHk1eiL.js → chunk-ND2GUHAM-DA0ZkEzn.js} +1 -1
- package/dist/rcs-web/assets/{chunk-QZHKN3VN-CX_4LT0M.js → chunk-QZHKN3VN-DSfuz56H.js} +1 -1
- package/dist/rcs-web/assets/classDiagram-4FO5ZUOK-DPk5suy5.js +1 -0
- package/dist/rcs-web/assets/classDiagram-v2-Q7XG4LA2-DPk5suy5.js +1 -0
- package/dist/rcs-web/assets/{code-block-IT6T5CEO-BoFB9z5v.js → code-block-IT6T5CEO-BNvuvbAY.js} +1 -1
- package/dist/rcs-web/assets/{copy-EPASKX-X.js → copy-D89XvJAZ.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/cose-bilkent-S5V4N54A-CMpuIlrx.js → dist/rcs-web/assets/cose-bilkent-S5V4N54A-BBBWys5l.js} +1 -1
- package/dist/rcs-web/assets/{dagre-BM42HDAG-Dg4Q9j21.js → dagre-BM42HDAG-BQXT7HJf.js} +1 -1
- package/dist/rcs-web/assets/{diagram-2AECGRRQ-YGGSegJh.js → diagram-2AECGRRQ-BWcc0ls-.js} +1 -1
- package/dist/rcs-web/assets/{diagram-5GNKFQAL-Rg7tQ7zl.js → diagram-5GNKFQAL-CraFf5c1.js} +1 -1
- package/dist/rcs-web/assets/{diagram-KO2AKTUF-FwQUsRJf.js → diagram-KO2AKTUF-ibhCBjd8.js} +1 -1
- package/dist/rcs-web/assets/{diagram-LMA3HP47-DDzZwu_E.js → diagram-LMA3HP47-CbTdpjvm.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/diagram-OG6HWLK6-D6Pxp9XO.js → dist/rcs-web/assets/diagram-OG6HWLK6-CNP77FZu.js} +1 -1
- package/dist/rcs-web/assets/{dialog-Ort95zkZ.js → dialog-CAsYgtpg.js} +1 -1
- package/dist/rcs-web/assets/{erDiagram-TEJ5UH35-BSDAq23h.js → erDiagram-TEJ5UH35-CrXP8g6S.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/flowDiagram-I6XJVG4X-CzWT0vwA.js → dist/rcs-web/assets/flowDiagram-I6XJVG4X-CNjng8UY.js} +1 -1
- package/dist/rcs-web/assets/{ganttDiagram-6RSMTGT7-DPNJQ_Co.js → ganttDiagram-6RSMTGT7-CDNjDeCq.js} +1 -1
- package/dist/rcs-web/assets/{gitGraphDiagram-PVQCEYII-vHpFxzAD.js → gitGraphDiagram-PVQCEYII-CASecY9v.js} +1 -1
- package/dist/rcs-web/assets/{infoDiagram-5YYISTIA-Bk_F8hwq.js → infoDiagram-5YYISTIA-Cs3XWzD-.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/ishikawaDiagram-YF4QCWOH-CBYfpD17.js → dist/rcs-web/assets/ishikawaDiagram-YF4QCWOH-kAO88EzG.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/journeyDiagram-JHISSGLW-BxoYxLNN.js → dist/rcs-web/assets/journeyDiagram-JHISSGLW-BCX4o3Cd.js} +1 -1
- package/dist/rcs-web/assets/{kanban-definition-UN3LZRKU-B5pCpO1z.js → kanban-definition-UN3LZRKU-CDC9KVRS.js} +1 -1
- package/dist/rcs-web/assets/{linear-BpcrEfNA.js → linear-CUrURi3P.js} +1 -1
- package/dist/rcs-web/assets/{main-BC4mcO_f.js → main-7jP_dqcT.js} +3 -3
- package/{packages/remote-control-server/web/dist/assets/mermaid-VLURNSYL-DWwqH0oB.js → dist/rcs-web/assets/mermaid-VLURNSYL-D7suvi1K.js} +4 -4
- package/dist/rcs-web/assets/{mermaid.core-CPGFiRhL.js → mermaid.core-BTm2FoGO.js} +5 -5
- package/dist/rcs-web/assets/{mindmap-definition-RKZ34NQL-DBF7JLl0.js → mindmap-definition-RKZ34NQL-BptbcT1w.js} +1 -1
- package/dist/rcs-web/assets/{notifications-C7DetfWu.js → notifications-CJOZ8afS.js} +1 -1
- package/dist/rcs-web/assets/{pieDiagram-4H26LBE5-CbUgqUZY.js → pieDiagram-4H26LBE5-DWptAgm8.js} +1 -1
- package/dist/rcs-web/assets/{quadrantDiagram-W4KKPZXB-BUF-YWIU.js → quadrantDiagram-W4KKPZXB-BMXRPRcs.js} +1 -1
- package/dist/rcs-web/assets/{refresh-cw-DBXI7gD3.js → refresh-cw-BdnkJGAc.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/requirementDiagram-4Y6WPE33-B8fyHxTP.js → dist/rcs-web/assets/requirementDiagram-4Y6WPE33-T0k9vm-H.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/sankeyDiagram-5OEKKPKP-DAZKpwBw.js → dist/rcs-web/assets/sankeyDiagram-5OEKKPKP-CTMqVl1K.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/sequenceDiagram-3UESZ5HK-DamEgVx-.js → dist/rcs-web/assets/sequenceDiagram-3UESZ5HK-DOpiyGKl.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/stateDiagram-AJRCARHV-DU-QvteV.js → dist/rcs-web/assets/stateDiagram-AJRCARHV-CHE-ZSds.js} +1 -1
- package/dist/rcs-web/assets/{stateDiagram-v2-BHNVJYJU-C5QVbdY9.js → stateDiagram-v2-BHNVJYJU-Wtd7hWcf.js} +1 -1
- package/dist/rcs-web/assets/{timeline-definition-PNZ67QCA-Df0hGAH6.js → timeline-definition-PNZ67QCA-v6PYD_S4.js} +1 -1
- package/dist/rcs-web/assets/{vennDiagram-CIIHVFJN-DbX36wdR.js → vennDiagram-CIIHVFJN-eZ0ybaJe.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/wardleyDiagram-YWT4CUSO-rjVkCTKo.js → dist/rcs-web/assets/wardleyDiagram-YWT4CUSO-C1Eujzxf.js} +1 -1
- package/dist/rcs-web/assets/{workerType-gCLCeJDi.js → workerType-D9tOpHFH.js} +1 -1
- package/dist/rcs-web/assets/{xychartDiagram-2RQKCTM6-CHjulBZn.js → xychartDiagram-2RQKCTM6-DE480xjy.js} +1 -1
- package/dist/rcs-web/index.html +1 -1
- package/package.json +1 -1
- package/packages/remote-control-server/src/services/session-titles.ts +4 -2
- package/packages/remote-control-server/src/transport/ws-handler.ts +3 -2
- package/packages/remote-control-server/web/dist/assets/{AdminPanel-D0fVkpU2.js → AdminPanel-YIhNS5Qr.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{ArtifactView-DG0-kZ2G.js → ArtifactView-wAwsEOXp.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{ArtifactsGallery-CcobkOm1.js → ArtifactsGallery-DIp4aSOX.js} +1 -1
- package/{dist/rcs-web/assets/Claim-CltNvmRS.js → packages/remote-control-server/web/dist/assets/Claim-DJ4tizsL.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{Dashboard-CEzuQ0N4.js → Dashboard-BLV5zTyh.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{Join-DX0LzcPE.js → Join-B91AXtrD.js} +1 -1
- package/{dist/rcs-web/assets/Login-BVKB4X_Z.js → packages/remote-control-server/web/dist/assets/Login-CWFOyYxU.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{Register-D-BrLVl3.js → Register-BaQgCZnM.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{RegisterEmpty-DdDXaiEn.js → RegisterEmpty-VAnkkhxE.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{SessionDetail-BkKSNMD8.js → SessionDetail-CvkeGPev.js} +20 -20
- package/packages/remote-control-server/web/dist/assets/{SessionVisibilityBadge-Ch3s2iFY.js → SessionVisibilityBadge-SoKp2ads.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{Setup-CyGhRI5L.js → Setup-CuKeura-.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{ShareLanding-xKcBqmJb.js → ShareLanding-CcFoMs-8.js} +1 -1
- package/{dist/rcs-web/assets/TeamDetail-C3Ne25hE.js → packages/remote-control-server/web/dist/assets/TeamDetail-Cwer75cF.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{TeamList-C5Zyrj2-.js → TeamList-zWC3UYCg.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{TeamSettings-BsT93PQO.js → TeamSettings-C8PMmj1J.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{UserSearchInput-BFpwaVmp.js → UserSearchInput-OP0ex0JY.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{UserSettings-cIzS243Z.js → UserSettings-Bk0df0IW.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{arc-CiWQl09E.js → arc-LA1YluYC.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{architectureDiagram-3BPJPVTR-DL5Id6fa.js → architectureDiagram-3BPJPVTR-BX0GtZq3.js} +1 -1
- package/{dist/rcs-web/assets/blockDiagram-GPEHLZMM-DF-nk9Fe.js → packages/remote-control-server/web/dist/assets/blockDiagram-GPEHLZMM-DOEtgiur.js} +1 -1
- package/{dist/rcs-web/assets/c4Diagram-AAUBKEIU-l_Pl6m2J.js → packages/remote-control-server/web/dist/assets/c4Diagram-AAUBKEIU-B4yXmB4r.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/channel-BSkZH-Bh.js +1 -0
- package/packages/remote-control-server/web/dist/assets/{chunk-2J33WTMH-Dr5xQSXu.js → chunk-2J33WTMH-BTtQR0Cy.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-4BX2VUAB-DAPTU1FG.js → chunk-4BX2VUAB-1HwNFe2a.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-55IACEB6-BgaGrvZR.js → chunk-55IACEB6-BZNQqhIb.js} +1 -1
- package/{dist/rcs-web/assets/chunk-727SXJPM-D6dnSxU3.js → packages/remote-control-server/web/dist/assets/chunk-727SXJPM-CYhzt0io.js} +1 -1
- package/{dist/rcs-web/assets/chunk-AQP2D5EJ-BVCad_JN.js → packages/remote-control-server/web/dist/assets/chunk-AQP2D5EJ-DHrz4pCx.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-FMBD7UC4-BNLx608W.js → chunk-FMBD7UC4-CaPwOz97.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-ND2GUHAM-BAHk1eiL.js → chunk-ND2GUHAM-DA0ZkEzn.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-QZHKN3VN-CX_4LT0M.js → chunk-QZHKN3VN-DSfuz56H.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/classDiagram-4FO5ZUOK-DPk5suy5.js +1 -0
- package/packages/remote-control-server/web/dist/assets/classDiagram-v2-Q7XG4LA2-DPk5suy5.js +1 -0
- package/packages/remote-control-server/web/dist/assets/{code-block-IT6T5CEO-BoFB9z5v.js → code-block-IT6T5CEO-BNvuvbAY.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{copy-EPASKX-X.js → copy-D89XvJAZ.js} +1 -1
- package/{dist/rcs-web/assets/cose-bilkent-S5V4N54A-CMpuIlrx.js → packages/remote-control-server/web/dist/assets/cose-bilkent-S5V4N54A-BBBWys5l.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{dagre-BM42HDAG-Dg4Q9j21.js → dagre-BM42HDAG-BQXT7HJf.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{diagram-2AECGRRQ-YGGSegJh.js → diagram-2AECGRRQ-BWcc0ls-.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{diagram-5GNKFQAL-Rg7tQ7zl.js → diagram-5GNKFQAL-CraFf5c1.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{diagram-KO2AKTUF-FwQUsRJf.js → diagram-KO2AKTUF-ibhCBjd8.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{diagram-LMA3HP47-DDzZwu_E.js → diagram-LMA3HP47-CbTdpjvm.js} +1 -1
- package/{dist/rcs-web/assets/diagram-OG6HWLK6-D6Pxp9XO.js → packages/remote-control-server/web/dist/assets/diagram-OG6HWLK6-CNP77FZu.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{dialog-Ort95zkZ.js → dialog-CAsYgtpg.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{erDiagram-TEJ5UH35-BSDAq23h.js → erDiagram-TEJ5UH35-CrXP8g6S.js} +1 -1
- package/{dist/rcs-web/assets/flowDiagram-I6XJVG4X-CzWT0vwA.js → packages/remote-control-server/web/dist/assets/flowDiagram-I6XJVG4X-CNjng8UY.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{ganttDiagram-6RSMTGT7-DPNJQ_Co.js → ganttDiagram-6RSMTGT7-CDNjDeCq.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{gitGraphDiagram-PVQCEYII-vHpFxzAD.js → gitGraphDiagram-PVQCEYII-CASecY9v.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{infoDiagram-5YYISTIA-Bk_F8hwq.js → infoDiagram-5YYISTIA-Cs3XWzD-.js} +1 -1
- package/{dist/rcs-web/assets/ishikawaDiagram-YF4QCWOH-CBYfpD17.js → packages/remote-control-server/web/dist/assets/ishikawaDiagram-YF4QCWOH-kAO88EzG.js} +1 -1
- package/{dist/rcs-web/assets/journeyDiagram-JHISSGLW-BxoYxLNN.js → packages/remote-control-server/web/dist/assets/journeyDiagram-JHISSGLW-BCX4o3Cd.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{kanban-definition-UN3LZRKU-B5pCpO1z.js → kanban-definition-UN3LZRKU-CDC9KVRS.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{linear-BpcrEfNA.js → linear-CUrURi3P.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{main-BC4mcO_f.js → main-7jP_dqcT.js} +3 -3
- package/{dist/rcs-web/assets/mermaid-VLURNSYL-DWwqH0oB.js → packages/remote-control-server/web/dist/assets/mermaid-VLURNSYL-D7suvi1K.js} +4 -4
- package/packages/remote-control-server/web/dist/assets/{mermaid.core-CPGFiRhL.js → mermaid.core-BTm2FoGO.js} +5 -5
- package/packages/remote-control-server/web/dist/assets/{mindmap-definition-RKZ34NQL-DBF7JLl0.js → mindmap-definition-RKZ34NQL-BptbcT1w.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{notifications-C7DetfWu.js → notifications-CJOZ8afS.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{pieDiagram-4H26LBE5-CbUgqUZY.js → pieDiagram-4H26LBE5-DWptAgm8.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{quadrantDiagram-W4KKPZXB-BUF-YWIU.js → quadrantDiagram-W4KKPZXB-BMXRPRcs.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{refresh-cw-DBXI7gD3.js → refresh-cw-BdnkJGAc.js} +1 -1
- package/{dist/rcs-web/assets/requirementDiagram-4Y6WPE33-B8fyHxTP.js → packages/remote-control-server/web/dist/assets/requirementDiagram-4Y6WPE33-T0k9vm-H.js} +1 -1
- package/{dist/rcs-web/assets/sankeyDiagram-5OEKKPKP-DAZKpwBw.js → packages/remote-control-server/web/dist/assets/sankeyDiagram-5OEKKPKP-CTMqVl1K.js} +1 -1
- package/{dist/rcs-web/assets/sequenceDiagram-3UESZ5HK-DamEgVx-.js → packages/remote-control-server/web/dist/assets/sequenceDiagram-3UESZ5HK-DOpiyGKl.js} +1 -1
- package/{dist/rcs-web/assets/stateDiagram-AJRCARHV-DU-QvteV.js → packages/remote-control-server/web/dist/assets/stateDiagram-AJRCARHV-CHE-ZSds.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{stateDiagram-v2-BHNVJYJU-C5QVbdY9.js → stateDiagram-v2-BHNVJYJU-Wtd7hWcf.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{timeline-definition-PNZ67QCA-Df0hGAH6.js → timeline-definition-PNZ67QCA-v6PYD_S4.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{vennDiagram-CIIHVFJN-DbX36wdR.js → vennDiagram-CIIHVFJN-eZ0ybaJe.js} +1 -1
- package/{dist/rcs-web/assets/wardleyDiagram-YWT4CUSO-rjVkCTKo.js → packages/remote-control-server/web/dist/assets/wardleyDiagram-YWT4CUSO-C1Eujzxf.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{workerType-gCLCeJDi.js → workerType-D9tOpHFH.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{xychartDiagram-2RQKCTM6-CHjulBZn.js → xychartDiagram-2RQKCTM6-DE480xjy.js} +1 -1
- package/packages/remote-control-server/web/dist/index.html +1 -1
- package/dist/rcs-web/assets/channel-CBq46cRr.js +0 -1
- package/dist/rcs-web/assets/classDiagram-4FO5ZUOK-CYdZp3iH.js +0 -1
- package/dist/rcs-web/assets/classDiagram-v2-Q7XG4LA2-CYdZp3iH.js +0 -1
- package/packages/remote-control-server/web/dist/assets/channel-CBq46cRr.js +0 -1
- package/packages/remote-control-server/web/dist/assets/classDiagram-4FO5ZUOK-CYdZp3iH.js +0 -1
- package/packages/remote-control-server/web/dist/assets/classDiagram-v2-Q7XG4LA2-CYdZp3iH.js +0 -1
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Gs=Object.defineProperty;var Ys=(r,t,s)=>t in r?Gs(r,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[t]=s;var A=(r,t,s)=>Ys(r,typeof t!="symbol"?t+"":t,s);import{j as e,e as l}from"./vendor-DE_-CLIE.js";import{ap as Q,a8 as Js,ax as It,aw as $t,aD as c,az as Xs,ay as Ue,aE as F,au as oe,aj as Zs,ai as G,ab as en,ag as tn,aI as sn,aL as X,T as nn,Q as rn,X as an,L as _e,H as on,I as ln,i as Dt,at as ds,N as cn,aq as Fe,e as Se,S as ct,M as dn,y as un,ar as V,an as te,as as mn,aF as xn,G as fn,D as pn,aG as qt,ac as hn,a0 as gn,af as yn,A as bn,av as jn,aA as wn,aB as kn,Z as Pt,$ as vn,aH as Nn,b as _n,a2 as Ot,ad as Sn,K as us,F as Cn,d as Tn,C as En,a7 as Ut,l as Mn,a as Rn,u as Le,w as Be,E as An,g as He,f as We,v as Qe,s as In,B as $n}from"./main-7jP_dqcT.js";import{A as Dn,g as Ft}from"./workerType-D9tOpHFH.js";import{D as de,a as ue,c as me,d as xe,b as qn}from"./dialog-CAsYgtpg.js";import{R as Pn}from"./refresh-cw-BdnkJGAc.js";import{A as On,U as Un}from"./UserSearchInput-OP0ex0JY.js";import{C as Fn}from"./copy-D89XvJAZ.js";import{E as Kn,A as Ln}from"./ArtifactsGallery-DIp4aSOX.js";import{S as Bn}from"./SessionVisibilityBadge-SoKp2ads.js";import{S as Hn,b as Wn}from"./notifications-CJOZ8afS.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 Qn=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],ms=Q("chevron-right",Qn);/**
|
|
7
7
|
* @license lucide-react v0.555.0 - ISC
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const
|
|
11
|
+
*/const zn=[["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M17 20v2",key:"1rnc9c"}],["path",{d:"M17 2v2",key:"11trls"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M2 17h2",key:"7oei6x"}],["path",{d:"M2 7h2",key:"asdhe0"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"M20 17h2",key:"1fpfkl"}],["path",{d:"M20 7h2",key:"1o8tra"}],["path",{d:"M7 20v2",key:"4gnj0m"}],["path",{d:"M7 2v2",key:"1i4yhu"}],["rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",key:"1vbyd7"}],["rect",{x:"8",y:"8",width:"8",height:"8",rx:"1",key:"z9xiuo"}]],xs=Q("cpu",zn);/**
|
|
12
12
|
* @license lucide-react v0.555.0 - ISC
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const
|
|
16
|
+
*/const Vn=[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]],Gn=Q("gauge",Vn);/**
|
|
17
17
|
* @license lucide-react v0.555.0 - ISC
|
|
18
18
|
*
|
|
19
19
|
* This source code is licensed under the ISC license.
|
|
20
20
|
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const
|
|
21
|
+
*/const Yn=[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]],Jn=Q("hash",Yn);/**
|
|
22
22
|
* @license lucide-react v0.555.0 - ISC
|
|
23
23
|
*
|
|
24
24
|
* This source code is licensed under the ISC license.
|
|
25
25
|
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const
|
|
26
|
+
*/const Xn=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],Zn=Q("info",Xn);/**
|
|
27
27
|
* @license lucide-react v0.555.0 - ISC
|
|
28
28
|
*
|
|
29
29
|
* This source code is licensed under the ISC license.
|
|
30
30
|
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
-
*/const
|
|
31
|
+
*/const er=[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",key:"zw3jo"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",key:"1wduqc"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",key:"kqbvx6"}]],tr=Q("layers",er);/**
|
|
32
32
|
* @license lucide-react v0.555.0 - ISC
|
|
33
33
|
*
|
|
34
34
|
* This source code is licensed under the ISC license.
|
|
35
35
|
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
-
*/const
|
|
36
|
+
*/const sr=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],fs=Q("message-circle-question-mark",sr);/**
|
|
37
37
|
* @license lucide-react v0.555.0 - ISC
|
|
38
38
|
*
|
|
39
39
|
* This source code is licensed under the ISC license.
|
|
40
40
|
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
-
*/const
|
|
41
|
+
*/const nr=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M7 11h10",key:"1twpyw"}],["path",{d:"M7 15h6",key:"d9of3u"}],["path",{d:"M7 7h8",key:"af5zfr"}]],rr=Q("message-square-text",nr);/**
|
|
42
42
|
* @license lucide-react v0.555.0 - ISC
|
|
43
43
|
*
|
|
44
44
|
* This source code is licensed under the ISC license.
|
|
45
45
|
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
-
*/const
|
|
46
|
+
*/const ar=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],or=Q("play",ar);/**
|
|
47
47
|
* @license lucide-react v0.555.0 - ISC
|
|
48
48
|
*
|
|
49
49
|
* This source code is licensed under the ISC license.
|
|
50
50
|
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
-
*/const
|
|
51
|
+
*/const ir=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]],ps=Q("plug",ir);/**
|
|
52
52
|
* @license lucide-react v0.555.0 - ISC
|
|
53
53
|
*
|
|
54
54
|
* This source code is licensed under the ISC license.
|
|
55
55
|
* See the LICENSE file in the root directory of this source tree.
|
|
56
|
-
*/const
|
|
56
|
+
*/const lr=[["path",{d:"m10.852 14.772-.383.923",key:"11vil6"}],["path",{d:"M13.148 14.772a3 3 0 1 0-2.296-5.544l-.383-.923",key:"1v3clb"}],["path",{d:"m13.148 9.228.383-.923",key:"t2zzyc"}],["path",{d:"m13.53 15.696-.382-.924a3 3 0 1 1-2.296-5.544",key:"1bxfiv"}],["path",{d:"m14.772 10.852.923-.383",key:"k9m8cz"}],["path",{d:"m14.772 13.148.923.383",key:"1xvhww"}],["path",{d:"M4.5 10H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-.5",key:"tn8das"}],["path",{d:"M4.5 14H4a2 2 0 0 0-2 2v4a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2h-.5",key:"1g2pve"}],["path",{d:"M6 18h.01",key:"uhywen"}],["path",{d:"M6 6h.01",key:"1utrut"}],["path",{d:"m9.228 10.852-.923-.383",key:"1wtb30"}],["path",{d:"m9.228 13.148-.923.383",key:"1a830x"}]],cr=Q("server-cog",lr);/**
|
|
57
57
|
* @license lucide-react v0.555.0 - ISC
|
|
58
58
|
*
|
|
59
59
|
* This source code is licensed under the ISC license.
|
|
60
60
|
* See the LICENSE file in the root directory of this source tree.
|
|
61
|
-
*/const
|
|
61
|
+
*/const dr=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],hs=Q("settings-2",dr);/**
|
|
62
62
|
* @license lucide-react v0.555.0 - ISC
|
|
63
63
|
*
|
|
64
64
|
* This source code is licensed under the ISC license.
|
|
65
65
|
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
-
*/const
|
|
66
|
+
*/const ur=[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]],mr=Q("share-2",ur);/**
|
|
67
67
|
* @license lucide-react v0.555.0 - ISC
|
|
68
68
|
*
|
|
69
69
|
* This source code is licensed under the ISC license.
|
|
70
70
|
* See the LICENSE file in the root directory of this source tree.
|
|
71
|
-
*/const ur=[["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"}]],mr=H("shield-check",ur);function lt(){return{tasks:{}}}const Ft=3e4;function qe(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 Kt(r,t){var i,u,f,p,g,y,v,E,C,b,m,h;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:qe(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 w=t.description??"";return{tasks:{...r.tasks,[n]:{taskId:n,name:qe(w),description:w,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 w=t.description??"";return{tasks:{...r.tasks,[n]:{taskId:n,name:qe(w),description:w,toolUseId:t.tool_use_id,status:"running",startTime:a,tokenCount:(i=t.usage)==null?void 0:i.total_tokens,toolUseCount:(u=t.usage)==null?void 0:u.tool_uses,durationMs:(f=t.usage)==null?void 0:f.duration_ms,lastToolName:t.last_tool_name,summary:t.summary}}}}return{tasks:{...r.tasks,[n]:{...d,description:t.description??d.description,tokenCount:((p=t.usage)==null?void 0:p.total_tokens)??d.tokenCount,toolUseCount:((g=t.usage)==null?void 0:g.tool_uses)??d.toolUseCount,durationMs:((y=t.usage)==null?void 0:y.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:((b=t.usage)==null?void 0:b.total_tokens)??d.tokenCount,toolUseCount:((m=t.usage)==null?void 0:m.tool_uses)??d.toolUseCount,durationMs:((h=t.usage)==null?void 0:h.duration_ms)??d.durationMs,evictAfter:a+Ft}}}:{tasks:{...r.tasks,[n]:{taskId:n,name:qe(t.summary??""),description:t.summary??"",status:t.status??"completed",startTime:a,endTime:a,finalSummary:t.summary,outputFile:t.output_file,tokenCount:(v=t.usage)==null?void 0:v.total_tokens,toolUseCount:(E=t.usage)==null?void 0:E.tool_uses,durationMs:(C=t.usage)==null?void 0:C.duration_ms,evictAfter:a+Ft}}}}function ps(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 Lt={in_process_teammate:0,local_bash:1,monitor_mcp:2,remote_agent:3,local_agent:4,dream:5},Bt=100;function xr(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=Lt[s]??Bt,d=Lt[n]??Bt;return a===d?s.localeCompare(n):a-d}).map(([s,n])=>({taskType:s,tasks:[...n].sort((a,d)=>a.startTime-d.startTime)}))}function Ht(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 fr(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,side_question:t.side_question===!0};return Object.values(s).some(Boolean)?s:null}function Wt(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 Qt(r){const t=r.raw&&typeof r.raw=="object"&&!Array.isArray(r.raw)?r.raw:r,s=Wt(t.slash_command_details??r.slash_command_details,t.slash_commands??r.slash_commands),n=Wt(t.skill_details??r.skill_details,t.skills??r.skills),a=fr(t.remote_capabilities??r.remote_capabilities);return s.length===0&&n.length===0&&!a?null:{commands:s,skills:n,capabilities:a}}class pr{constructor(t){A(this,"listeners",new Set);A(this,"stateListeners",new Set);A(this,"eventSource",null);A(this,"sessionId",null);A(this,"_lastSeqNum",0);A(this,"lastFrameAt",0);A(this,"firstEventAfterOpen",!1);A(this,"watchdogTimer",null);A(this,"visibilityHandler",null);A(this,"reconnectTimer",null);A(this,"reconnectAttempts",0);A(this,"_state","idle");A(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 en(),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 ie=new pr;function nt(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 zt(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 hr(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 Vt(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 Gt(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 gr{constructor(t,s,n){A(this,"sessionId");A(this,"setEntries");A(this,"unsub",null);A(this,"unsubState",null);A(this,"onStatusChange");A(this,"onError");A(this,"onPermissionRequest");A(this,"onModelsStateChange");A(this,"onSubagentUpdate");A(this,"onControlResponse");A(this,"onPermissionModeChange");A(this,"onUsageChange");A(this,"onElicitationRequest");A(this,"onWorkerInfoChange");A(this,"subagentState",lt());A(this,"seenUuids",new Set);A(this,"seenToolCallIds",new Set);A(this,"pendingToolCallIds",new Set);A(this,"pendingPermissionToolIds",new Map);A(this,"postedUserUuids",new Set);A(this,"pendingControlRequests",new Map);A(this,"turnEnded",!1);A(this,"userSinceTurnEnd",!1);A(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}markClosed(){this.closed=!0}async init(){await this.loadHistory(),this.connectSSE()}async loadHistory(){var E,C,b,m,h,w,T;const{events:t}=await Gs(this.sessionId);if(!t||t.length===0)return;const s=new Set;for(const k of t){if(k.type!=="user"||k.direction==="inbound")continue;const j=(E=k.payload)==null?void 0:E.uuid;typeof j=="string"&&j&&s.add(j)}const n=[];let a=null;const d=()=>{a&&(n.push(a),a=null)};for(const k of t){const j=k.payload||{},N=j.uuid;if(typeof N=="string"&&N&&this.seenUuids.add(N),k.type==="tool_use"){const M=j.tool_call_id;typeof M=="string"&&M&&this.seenToolCallIds.add(M)}if(k.type==="user"){if(k.direction==="inbound"){const $=j.uuid;if(typeof $!="string"||!$||s.has($))continue}d();const M=nt(j);M&&n.push({type:"user_message",id:k.id||`hist-user-${n.length}`,content:M})}else if(k.type==="assistant"){d();const M=nt(j);if(At(M))continue;const $=[],K=j.message;if(K&&typeof K=="object"&&Array.isArray(K.content)){for(const S of K.content)if(S.type==="tool_use"){const P=S.id;P&&this.seenToolCallIds.add(P),$.push({type:"tool_call",toolCall:{id:P||`hist-tool-${n.length}`,title:S.name||"tool",status:"complete",rawInput:S.input||{}}})}}if(M||$.length>0){a={type:"assistant_message",id:k.id||`hist-asst-${n.length}`,chunks:M?[{type:"message",text:M}]:[]},n.push(a);for(const S of $)n.push(S);a=null}}else if(k.type==="conversation_rewound"){const M=Gt(j);if(M){const $=n.findIndex(K=>It(K)===M);$>=0&&(n.length=$)}}else if(k.type==="tool_use"){const M=j,$={type:"tool_call",toolCall:{id:M.tool_call_id||`hist-tool-${n.length}`,title:M.tool_name||"tool",status:"complete",rawInput:M.tool_input||{}}};n.push($)}else if(k.type==="tool_result"){const M=j,$=zt(n,M.tool_call_id||"");if($>=0){const K=n[$];n[$]={type:"tool_call",toolCall:{...K.toolCall,rawOutput:{output:M.content||M.output||""}}}}}}d();let i=null;for(const k of t){if(k.type!=="task_state")continue;const j=k.payload||{};Array.isArray(j.tasks)&&(i=j.tasks)}if(i&&i.length>0){const k=Vt(i);k.length>0&&n.push({type:"plan",id:`plan-hist-${Date.now()}`,entries:k})}this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries(n);let u=null,f=null,p=null,g=null;for(const k of t){const j=k.payload||{};if(k.type==="user"?g="user":(k.type==="result"||k.type==="result_success"||k.type==="interrupt")&&(g="turn_end"),k.type==="system"&&(j.subtype==="init"||((C=j.raw)==null?void 0:C.subtype)==="init")&&(f=Qt(j)),k.type==="models_state"){const N=j.raw,M=N&&typeof N=="object"?N.models_state:j.models_state;M&&Array.isArray(M.availableModels)&&typeof M.currentModelId=="string"&&(u=M)}else if(k.type==="result"||k.type==="result_success"){const N=j.usage,M=typeof j.total_cost_usd=="number"?j.total_cost_usd:null;(N||M!==null)&&(p={inputTokens:((N==null?void 0:N.input_tokens)??0)+((N==null?void 0:N.cache_read_input_tokens)??0)+((N==null?void 0:N.cache_creation_input_tokens)??0),outputTokens:(N==null?void 0:N.output_tokens)??0,totalCostUsd:M})}}let y=!1,v=lt();for(const k of t){if(k.type!=="system")continue;const j=Ht(k.payload||{});j&&(v=Kt(v,j),y=!0)}y&&(this.subagentState=v,(b=this.onSubagentUpdate)==null||b.call(this,this.subagentState)),u&&((m=this.onModelsStateChange)==null||m.call(this,u)),f&&((h=this.onWorkerInfoChange)==null||h.call(this,f)),p&&((w=this.onUsageChange)==null||w.call(this,p)),this.turnEnded=g==="turn_end",this.userSinceTurnEnd=g==="user",this.turnEnded&&!this.closed&&((T=this.onStatusChange)==null||T.call(this,"idle"))}connectSSE(){ie.connect(this.sessionId),this.unsub=ie.onEvent(t=>this.handleEvent(t)),this.unsubState=ie.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),ie.disconnect()}handleEvent(t){var a,d,i,u,f,p,g,y,v,E,C,b;const s=t.type,n=t.payload||{};switch(s){case"user":{if(this.applyEmbeddedToolResults(n),this.userSinceTurnEnd=!0,t.direction==="inbound"){const m=n.uuid;if(typeof m!="string"||!m||this.postedUserUuids.has(m)||this.seenUuids.has(m))break;this.seenUuids.add(m);const h=nt(n);h&&this.setEntries(w=>[...w,{type:"user_message",id:t.id||`user-${Date.now()}`,content:h}])}break}case"assistant":{const m=n.uuid;if(typeof m=="string"&&m){if(this.seenUuids.has(m))break;this.seenUuids.add(m)}const h=typeof n.content=="string"?n.content:"";if(At(h))break;const w=hr(n);this.setEntries(k=>{const j=k[k.length-1];if((j==null?void 0:j.type)==="assistant_message"&&j.id.startsWith(rt))return[...k.slice(0,-1),{...j,id:`assistant-${Date.now()}`,chunks:[...w?[{type:"thought",text:w}]:[],{type:"message",text:h}]}];if((j==null?void 0:j.type)==="assistant_message"){const N=j.chunks[j.chunks.length-1];return(N==null?void 0:N.type)==="message"?[...k.slice(0,-1),{...j,chunks:[...j.chunks.slice(0,-1),{type:"message",text:N.text+h}]}]:[...k.slice(0,-1),{...j,chunks:[...j.chunks,{type:"message",text:h}]}]}if(h&&h.trim()||w){const N={type:"assistant_message",id:`assistant-${Date.now()}`,chunks:[...w?[{type:"thought",text:w}]:[],...h?[{type:"message",text:h}]:[]]};return[...k,N]}return k});const T=n.message;if(T&&typeof T=="object"&&Array.isArray(T.content)){const k=T.content.filter(j=>j.type==="tool_use");for(const j of k){const N=j.id||`call-${Date.now()}-${Math.random().toString(16).slice(2,8)}`;if(this.seenToolCallIds.has(N))continue;this.seenToolCallIds.add(N),this.pendingToolCallIds.add(N);const M={id:N,title:j.name||"tool",status:"running",rawInput:j.input||{}};this.setEntries($=>[...$,{type:"tool_call",toolCall:M}])}}break}case"tool_use":{const m=n,h=m.tool_call_id||`call-${Date.now()}`;if(this.seenToolCallIds.has(h))break;this.seenToolCallIds.add(h),this.pendingToolCallIds.add(h);const w={id:h,title:m.tool_name||"tool",status:"running",rawInput:m.tool_input||{}};this.setEntries(T=>[...T,{type:"tool_call",toolCall:w}]);break}case"tool_result":{const m=n;this.applyToolResult(m.tool_call_id||"",m.content??m.output);break}case"interrupt":{this.finalizePendingToolCalls("canceled"),this.turnEnded=!0,this.userSinceTurnEnd=!1,this.closed||(a=this.onStatusChange)==null||a.call(this,"idle");break}case"control_request":case"permission_request":{const m=n.request;if(m&&m.subtype==="can_use_tool"){const h=n.request_id||"",w=m.tool_name||"unknown",T=m.input||m.tool_input||{},k=m.description||"",j=Array.isArray(m.permission_suggestions)?m.permission_suggestions:[];this.setEntries(N=>{const M=[...N].reverse().findIndex($=>$.type==="tool_call");if(M>=0){const $=N.length-1-M,K=N[$];if(K.toolCall.status==="running")return this.pendingPermissionToolIds.set(h,K.toolCall.id),N.map((S,P)=>P===$?{type:"tool_call",toolCall:{...K.toolCall,status:"waiting_for_confirmation",permissionRequest:{requestId:h,options:[]}}}:S)}return N}),(d=this.onPermissionRequest)==null||d.call(this,{requestId:h,toolName:w,toolInput:T,description:k,suggestions:j})}else m&&m.subtype==="elicitation"&&((i=this.onElicitationRequest)==null||i.call(this,{requestId:n.request_id||"",serverName:m.mcp_server_name||"",message:m.message||"",mode:m.mode==="url"?"url":"form",url:typeof m.url=="string"?m.url:void 0,requestedSchema:m.requested_schema||void 0}));break}case"conversation_rewound":{const m=Gt(n);m&&(this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries(h=>{const w=h.findIndex(T=>It(T)===m);return w===-1?h:h.slice(0,w)}));break}case"session_status":{if(Ys(n)){this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries([]);break}if(typeof n.status=="string"){if(Oe(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 m=String(n.message||n.content||"Unknown error");(f=this.onError)==null||f.call(this,m);break}case"models_state":{const m=n.raw,h=typeof m=="object"&&m!==null?m.models_state:n.models_state;h&&Array.isArray(h.availableModels)&&typeof h.currentModelId=="string"&&((p=this.onModelsStateChange)==null||p.call(this,h));break}case"system":{const m=n.raw,h=m&&typeof m=="object"?m:n,w=typeof h.subtype=="string"?h.subtype:void 0,T=Ht(n);T&&(this.subagentState=Kt(this.subagentState,T),(g=this.onSubagentUpdate)==null||g.call(this,this.subagentState));const k=typeof h.permissionMode=="string"?h.permissionMode:typeof n.permissionMode=="string"?n.permissionMode:null;if(k&&((y=this.onPermissionModeChange)==null||y.call(this,k)),w==="init"){const j=Qt(n);j&&((v=this.onWorkerInfoChange)==null||v.call(this,j))}break}case"control_response":{const m=n.response;if(m&&typeof m=="object"){const h=typeof m.request_id=="string"?m.request_id:"",w=typeof m.subtype=="string"?m.subtype:"";if(h){(E=this.onControlResponse)==null||E.call(this,{subtype:w,requestId:h,error:typeof m.error=="string"?m.error:void 0});const T=this.pendingControlRequests.get(h);T&&(this.pendingControlRequests.delete(h),T({data:w==="success"&&m.response&&typeof m.response=="object"?m.response:null,...w==="error"&&typeof m.error=="string"?{error:m.error}:{}}))}}break}case"stream_event":{const m=n.event;if(!m||typeof m.type!="string")break;if(m.type==="content_block_delta"){const h=m.delta;if(!h||typeof h.type!="string")break;const w=h.type==="text_delta"?"message":h.type==="thinking_delta"?"thought":null;if(!w)break;const T=h.text??h.thinking;if(typeof T!="string"||!T)break;this.appendStreamingDelta(w,T)}break}case"partial_assistant":{const m=typeof n.content=="string"?n.content:"";m&&this.appendStreamingDelta("message",m);break}case"result":case"result_success":{this.turnEnded=!0,this.userSinceTurnEnd=!1,this.finalizePendingToolCalls(n.is_error?"canceled":"complete"),this.closed||(C=this.onStatusChange)==null||C.call(this,"idle");const m=n.usage,h=typeof n.total_cost_usd=="number"?n.total_cost_usd:null;if(m||h!==null){const N=((m==null?void 0:m.input_tokens)??0)+((m==null?void 0:m.cache_read_input_tokens)??0)+((m==null?void 0:m.cache_creation_input_tokens)??0);(b=this.onUsageChange)==null||b.call(this,{inputTokens:N,outputTokens:(m==null?void 0:m.output_tokens)??0,totalCostUsd:h})}const w=typeof n.subtype=="string"?n.subtype:"",T=n.raw&&typeof n.raw=="object"?n.raw:void 0,j=(typeof n.result=="string"?n.result:typeof(T==null?void 0:T.result)=="string"?T.result:"").trim();w.startsWith("error_")&&j&&this.setEntries(N=>[...N,{type:"command_output",id:`exit-error-${typeof n.uuid=="string"?n.uuid:Date.now()}`,commandName:"worker",inputText:"",title:c("adapter.workerCrashed"),outputText:j,variant:"error"}]);break}case"task_state":{const m=Array.isArray(n.tasks)?n.tasks:[];if(m.length===0)break;const h=Vt(m);if(h.length===0)break;this.setEntries(w=>[...w.filter(k=>k.type!=="plan"),{type:"plan",id:`plan-${n.task_list_id||Date.now()}`,entries:h}]);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=zt(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((i,u)=>u===a?{type:"tool_call",toolCall:{...d.toolCall,status:"complete",permissionRequest:void 0,rawOutput:{output:s||""}}}:i)}))}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 i=a.chunks[a.chunks.length-1];return(i==null?void 0:i.type)===t?[...n.slice(0,-1),{...a,chunks:[...a.chunks.slice(0,-1),{type:t,text:i.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 p;const a=s&&s.length>0,d=n&&n.length>0;if(!t.trim()&&!a&&!d)return;const i={type:"user_message",id:`user-${Date.now()}`,content:t,images:a?s:void 0,attachments:d?n:void 0};this.setEntries(g=>[...g,i]);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 y=`📎 ${g.name}${g.size!=null?` (${yr(g.size)})`:""}`,v=g.textContent||c("attach.emptyFile");u.push({type:"text",text:`${y}
|
|
71
|
+
*/const xr=[["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"}]],fr=Q("shield-check",xr);function dt(){return{tasks:{}}}const Kt=3e4;function Pe(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 Lt(r,t){var i,u,f,p,g,y,v,E,C,j,m,h;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:Pe(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 w=t.description??"";return{tasks:{...r.tasks,[n]:{taskId:n,name:Pe(w),description:w,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 w=t.description??"";return{tasks:{...r.tasks,[n]:{taskId:n,name:Pe(w),description:w,toolUseId:t.tool_use_id,status:"running",startTime:a,tokenCount:(i=t.usage)==null?void 0:i.total_tokens,toolUseCount:(u=t.usage)==null?void 0:u.tool_uses,durationMs:(f=t.usage)==null?void 0:f.duration_ms,lastToolName:t.last_tool_name,summary:t.summary}}}}return{tasks:{...r.tasks,[n]:{...d,description:t.description??d.description,tokenCount:((p=t.usage)==null?void 0:p.total_tokens)??d.tokenCount,toolUseCount:((g=t.usage)==null?void 0:g.tool_uses)??d.toolUseCount,durationMs:((y=t.usage)==null?void 0:y.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:((m=t.usage)==null?void 0:m.tool_uses)??d.toolUseCount,durationMs:((h=t.usage)==null?void 0:h.duration_ms)??d.durationMs,evictAfter:a+Kt}}}:{tasks:{...r.tasks,[n]:{taskId:n,name:Pe(t.summary??""),description:t.summary??"",status:t.status??"completed",startTime:a,endTime:a,finalSummary:t.summary,outputFile:t.output_file,tokenCount:(v=t.usage)==null?void 0:v.total_tokens,toolUseCount:(E=t.usage)==null?void 0:E.tool_uses,durationMs:(C=t.usage)==null?void 0:C.duration_ms,evictAfter:a+Kt}}}}function gs(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 Bt={in_process_teammate:0,local_bash:1,monitor_mcp:2,remote_agent:3,local_agent:4,dream:5},Ht=100;function pr(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=Bt[s]??Ht,d=Bt[n]??Ht;return a===d?s.localeCompare(n):a-d}).map(([s,n])=>({taskType:s,tasks:[...n].sort((a,d)=>a.startTime-d.startTime)}))}function Wt(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 hr(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,side_question:t.side_question===!0};return Object.values(s).some(Boolean)?s:null}function Qt(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 zt(r){const t=r.raw&&typeof r.raw=="object"&&!Array.isArray(r.raw)?r.raw:r,s=Qt(t.slash_command_details??r.slash_command_details,t.slash_commands??r.slash_commands),n=Qt(t.skill_details??r.skill_details,t.skills??r.skills),a=hr(t.remote_capabilities??r.remote_capabilities);return s.length===0&&n.length===0&&!a?null:{commands:s,skills:n,capabilities:a}}class gr{constructor(t){A(this,"listeners",new Set);A(this,"stateListeners",new Set);A(this,"eventSource",null);A(this,"sessionId",null);A(this,"_lastSeqNum",0);A(this,"lastFrameAt",0);A(this,"firstEventAfterOpen",!1);A(this,"watchdogTimer",null);A(this,"visibilityHandler",null);A(this,"reconnectTimer",null);A(this,"reconnectAttempts",0);A(this,"_state","idle");A(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 sn(),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 ie=new gr;function at(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 Vt(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 ot="streaming-";function Gt(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 Yt(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 Jt(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 yr{constructor(t,s,n){A(this,"sessionId");A(this,"setEntries");A(this,"unsub",null);A(this,"unsubState",null);A(this,"onStatusChange");A(this,"onError");A(this,"onPermissionRequest");A(this,"onModelsStateChange");A(this,"onSubagentUpdate");A(this,"onControlResponse");A(this,"onPermissionModeChange");A(this,"onUsageChange");A(this,"onElicitationRequest");A(this,"onWorkerInfoChange");A(this,"subagentState",dt());A(this,"seenUuids",new Set);A(this,"seenToolCallIds",new Set);A(this,"pendingToolCallIds",new Set);A(this,"pendingPermissionToolIds",new Map);A(this,"postedUserUuids",new Set);A(this,"pendingControlRequests",new Map);A(this,"turnEnded",!1);A(this,"userSinceTurnEnd",!1);A(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}markClosed(){this.closed=!0}async init(){await this.loadHistory(),this.connectSSE()}async loadHistory(){var E,C,j,m,h,w,T;const{events:t}=await Js(this.sessionId);if(!t||t.length===0)return;const s=new Set;for(const k of t){if(k.type!=="user"||k.direction==="inbound")continue;const b=(E=k.payload)==null?void 0:E.uuid;typeof b=="string"&&b&&s.add(b)}const n=[];let a=null;const d=()=>{a&&(n.push(a),a=null)};for(const k of t){const b=k.payload||{},_=b.uuid;if(typeof _=="string"&&_&&this.seenUuids.add(_),k.type==="tool_use"){const M=b.tool_call_id;typeof M=="string"&&M&&this.seenToolCallIds.add(M)}if(k.type==="user"){if(k.direction==="inbound"){const $=b.uuid;if(typeof $!="string"||!$||s.has($))continue}d();const M=at(b);M&&n.push({type:"user_message",id:k.id||`hist-user-${n.length}`,content:M})}else if(k.type==="assistant"){d();const M=at(b);if(It(M))continue;const $=Gt(b),K=[],S=b.message;if(S&&typeof S=="object"&&Array.isArray(S.content)){for(const P of S.content)if(P.type==="tool_use"){const L=P.id;L&&this.seenToolCallIds.add(L),K.push({type:"tool_call",toolCall:{id:L||`hist-tool-${n.length}`,title:P.name||"tool",status:"complete",rawInput:P.input||{}}})}}if(M||$||K.length>0){a={type:"assistant_message",id:k.id||`hist-asst-${n.length}`,chunks:[...$?[{type:"thought",text:$}]:[],...M?[{type:"message",text:M}]:[]]},n.push(a);for(const P of K)n.push(P);a=null}}else if(k.type==="conversation_rewound"){const M=Jt(b);if(M){const $=n.findIndex(K=>$t(K)===M);$>=0&&(n.length=$)}}else if(k.type==="tool_use"){const M=b,$={type:"tool_call",toolCall:{id:M.tool_call_id||`hist-tool-${n.length}`,title:M.tool_name||"tool",status:"complete",rawInput:M.tool_input||{}}};n.push($)}else if(k.type==="tool_result"){const M=b,$=Vt(n,M.tool_call_id||"");if($>=0){const K=n[$];n[$]={type:"tool_call",toolCall:{...K.toolCall,rawOutput:{output:M.content||M.output||""}}}}}}d();let i=null;for(const k of t){if(k.type!=="task_state")continue;const b=k.payload||{};Array.isArray(b.tasks)&&(i=b.tasks)}if(i&&i.length>0){const k=Yt(i);k.length>0&&n.push({type:"plan",id:`plan-hist-${Date.now()}`,entries:k})}this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries(n);let u=null,f=null,p=null,g=null;for(const k of t){const b=k.payload||{};if(k.type==="user"?g="user":(k.type==="result"||k.type==="result_success"||k.type==="interrupt")&&(g="turn_end"),k.type==="system"&&(b.subtype==="init"||((C=b.raw)==null?void 0:C.subtype)==="init")&&(f=zt(b)),k.type==="models_state"){const _=b.raw,M=_&&typeof _=="object"?_.models_state:b.models_state;M&&Array.isArray(M.availableModels)&&typeof M.currentModelId=="string"&&(u=M)}else if(k.type==="result"||k.type==="result_success"){const _=b.usage,M=typeof b.total_cost_usd=="number"?b.total_cost_usd:null;(_||M!==null)&&(p={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:M})}}let y=!1,v=dt();for(const k of t){if(k.type!=="system")continue;const b=Wt(k.payload||{});b&&(v=Lt(v,b),y=!0)}y&&(this.subagentState=v,(j=this.onSubagentUpdate)==null||j.call(this,this.subagentState)),u&&((m=this.onModelsStateChange)==null||m.call(this,u)),f&&((h=this.onWorkerInfoChange)==null||h.call(this,f)),p&&((w=this.onUsageChange)==null||w.call(this,p)),this.turnEnded=g==="turn_end",this.userSinceTurnEnd=g==="user",this.turnEnded&&!this.closed&&((T=this.onStatusChange)==null||T.call(this,"idle"))}connectSSE(){ie.connect(this.sessionId),this.unsub=ie.onEvent(t=>this.handleEvent(t)),this.unsubState=ie.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),ie.disconnect()}handleEvent(t){var a,d,i,u,f,p,g,y,v,E,C,j;const s=t.type,n=t.payload||{};switch(s){case"user":{if(this.applyEmbeddedToolResults(n),this.userSinceTurnEnd=!0,t.direction==="inbound"){const m=n.uuid;if(typeof m!="string"||!m||this.postedUserUuids.has(m)||this.seenUuids.has(m))break;this.seenUuids.add(m);const h=at(n);h&&this.setEntries(w=>[...w,{type:"user_message",id:t.id||`user-${Date.now()}`,content:h}])}break}case"assistant":{const m=n.uuid;if(typeof m=="string"&&m){if(this.seenUuids.has(m))break;this.seenUuids.add(m)}const h=typeof n.content=="string"?n.content:"";if(It(h))break;const w=Gt(n);this.setEntries(k=>{const b=k[k.length-1];if((b==null?void 0:b.type)==="assistant_message"&&b.id.startsWith(ot))return[...k.slice(0,-1),{...b,id:`assistant-${Date.now()}`,chunks:[...w?[{type:"thought",text:w}]:[],{type:"message",text:h}]}];if((b==null?void 0:b.type)==="assistant_message"){const _=b.chunks[b.chunks.length-1];return(_==null?void 0:_.type)==="message"?[...k.slice(0,-1),{...b,chunks:[...b.chunks.slice(0,-1),{type:"message",text:_.text+h}]}]:[...k.slice(0,-1),{...b,chunks:[...b.chunks,{type:"message",text:h}]}]}if(h&&h.trim()||w){const _={type:"assistant_message",id:`assistant-${Date.now()}`,chunks:[...w?[{type:"thought",text:w}]:[],...h?[{type:"message",text:h}]:[]]};return[...k,_]}return k});const T=n.message;if(T&&typeof T=="object"&&Array.isArray(T.content)){const k=T.content.filter(b=>b.type==="tool_use");for(const b of k){const _=b.id||`call-${Date.now()}-${Math.random().toString(16).slice(2,8)}`;if(this.seenToolCallIds.has(_))continue;this.seenToolCallIds.add(_),this.pendingToolCallIds.add(_);const M={id:_,title:b.name||"tool",status:"running",rawInput:b.input||{}};this.setEntries($=>[...$,{type:"tool_call",toolCall:M}])}}break}case"tool_use":{const m=n,h=m.tool_call_id||`call-${Date.now()}`;if(this.seenToolCallIds.has(h))break;this.seenToolCallIds.add(h),this.pendingToolCallIds.add(h);const w={id:h,title:m.tool_name||"tool",status:"running",rawInput:m.tool_input||{}};this.setEntries(T=>[...T,{type:"tool_call",toolCall:w}]);break}case"tool_result":{const m=n;this.applyToolResult(m.tool_call_id||"",m.content??m.output);break}case"interrupt":{this.finalizePendingToolCalls("canceled"),this.turnEnded=!0,this.userSinceTurnEnd=!1,this.closed||(a=this.onStatusChange)==null||a.call(this,"idle");break}case"control_request":case"permission_request":{const m=n.request;if(m&&m.subtype==="can_use_tool"){const h=n.request_id||"",w=m.tool_name||"unknown",T=m.input||m.tool_input||{},k=m.description||"",b=Array.isArray(m.permission_suggestions)?m.permission_suggestions:[];this.setEntries(_=>{const M=[..._].reverse().findIndex($=>$.type==="tool_call");if(M>=0){const $=_.length-1-M,K=_[$];if(K.toolCall.status==="running")return this.pendingPermissionToolIds.set(h,K.toolCall.id),_.map((S,P)=>P===$?{type:"tool_call",toolCall:{...K.toolCall,status:"waiting_for_confirmation",permissionRequest:{requestId:h,options:[]}}}:S)}return _}),(d=this.onPermissionRequest)==null||d.call(this,{requestId:h,toolName:w,toolInput:T,description:k,suggestions:b})}else m&&m.subtype==="elicitation"&&((i=this.onElicitationRequest)==null||i.call(this,{requestId:n.request_id||"",serverName:m.mcp_server_name||"",message:m.message||"",mode:m.mode==="url"?"url":"form",url:typeof m.url=="string"?m.url:void 0,requestedSchema:m.requested_schema||void 0}));break}case"conversation_rewound":{const m=Jt(n);m&&(this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries(h=>{const w=h.findIndex(T=>$t(T)===m);return w===-1?h:h.slice(0,w)}));break}case"session_status":{if(Xs(n)){this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries([]);break}if(typeof n.status=="string"){if(Ue(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 m=String(n.message||n.content||"Unknown error");(f=this.onError)==null||f.call(this,m);break}case"models_state":{const m=n.raw,h=typeof m=="object"&&m!==null?m.models_state:n.models_state;h&&Array.isArray(h.availableModels)&&typeof h.currentModelId=="string"&&((p=this.onModelsStateChange)==null||p.call(this,h));break}case"system":{const m=n.raw,h=m&&typeof m=="object"?m:n,w=typeof h.subtype=="string"?h.subtype:void 0,T=Wt(n);T&&(this.subagentState=Lt(this.subagentState,T),(g=this.onSubagentUpdate)==null||g.call(this,this.subagentState));const k=typeof h.permissionMode=="string"?h.permissionMode:typeof n.permissionMode=="string"?n.permissionMode:null;if(k&&((y=this.onPermissionModeChange)==null||y.call(this,k)),w==="init"){const b=zt(n);b&&((v=this.onWorkerInfoChange)==null||v.call(this,b))}break}case"control_response":{const m=n.response;if(m&&typeof m=="object"){const h=typeof m.request_id=="string"?m.request_id:"",w=typeof m.subtype=="string"?m.subtype:"";if(h){(E=this.onControlResponse)==null||E.call(this,{subtype:w,requestId:h,error:typeof m.error=="string"?m.error:void 0});const T=this.pendingControlRequests.get(h);T&&(this.pendingControlRequests.delete(h),T({data:w==="success"&&m.response&&typeof m.response=="object"?m.response:null,...w==="error"&&typeof m.error=="string"?{error:m.error}:{}}))}}break}case"stream_event":{const m=n.event;if(!m||typeof m.type!="string")break;if(m.type==="content_block_delta"){const h=m.delta;if(!h||typeof h.type!="string")break;const w=h.type==="text_delta"?"message":h.type==="thinking_delta"?"thought":null;if(!w)break;const T=h.text??h.thinking;if(typeof T!="string"||!T)break;this.appendStreamingDelta(w,T)}break}case"partial_assistant":{const m=typeof n.content=="string"?n.content:"";m&&this.appendStreamingDelta("message",m);break}case"result":case"result_success":{this.turnEnded=!0,this.userSinceTurnEnd=!1,this.finalizePendingToolCalls(n.is_error?"canceled":"complete"),this.closed||(C=this.onStatusChange)==null||C.call(this,"idle");const m=n.usage,h=typeof n.total_cost_usd=="number"?n.total_cost_usd:null;if(m||h!==null){const _=((m==null?void 0:m.input_tokens)??0)+((m==null?void 0:m.cache_read_input_tokens)??0)+((m==null?void 0:m.cache_creation_input_tokens)??0);(j=this.onUsageChange)==null||j.call(this,{inputTokens:_,outputTokens:(m==null?void 0:m.output_tokens)??0,totalCostUsd:h})}const w=typeof n.subtype=="string"?n.subtype:"",T=n.raw&&typeof n.raw=="object"?n.raw:void 0,b=(typeof n.result=="string"?n.result:typeof(T==null?void 0:T.result)=="string"?T.result:"").trim();w.startsWith("error_")&&b&&this.setEntries(_=>[..._,{type:"command_output",id:`exit-error-${typeof n.uuid=="string"?n.uuid:Date.now()}`,commandName:"worker",inputText:"",title:c("adapter.workerCrashed"),outputText:b,variant:"error"}]);break}case"task_state":{const m=Array.isArray(n.tasks)?n.tasks:[];if(m.length===0)break;const h=Yt(m);if(h.length===0)break;this.setEntries(w=>[...w.filter(k=>k.type!=="plan"),{type:"plan",id:`plan-${n.task_list_id||Date.now()}`,entries:h}]);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=Vt(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((i,u)=>u===a?{type:"tool_call",toolCall:{...d.toolCall,status:"complete",permissionRequest:void 0,rawOutput:{output:s||""}}}:i)}))}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(ot)){const i=a.chunks[a.chunks.length-1];return(i==null?void 0:i.type)===t?[...n.slice(0,-1),{...a,chunks:[...a.chunks.slice(0,-1),{type:t,text:i.text+s}]}]:[...n.slice(0,-1),{...a,chunks:[...a.chunks,{type:t,text:s}]}]}const d={type:"assistant_message",id:`${ot}${Date.now()}`,chunks:[{type:t,text:s}]};return[...n,d]})}async sendMessage(t,s,n){var p;const a=s&&s.length>0,d=n&&n.length>0;if(!t.trim()&&!a&&!d)return;const i={type:"user_message",id:`user-${Date.now()}`,content:t,images:a?s:void 0,attachments:d?n:void 0};this.setEntries(g=>[...g,i]);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 y=`📎 ${g.name}${g.size!=null?` (${br(g.size)})`:""}`,v=g.textContent||c("attach.emptyFile");u.push({type:"text",text:`${y}
|
|
72
72
|
\`\`\`
|
|
73
73
|
${v}
|
|
74
|
-
\`\`\``})}else if(g.kind==="directory"){const y=g.files!=null?`${
|
|
75
|
-
${v}`})}}const f=u.length===1&&u[0].type==="text"?u[0].text||t:u.length>0?u:t;try{const g=oe();this.postedUserUuids.add(g);const y=await Js(this.sessionId,{type:"user",uuid:g,content:t,message:{content:f}}),v=(p=y==null?void 0:y.event)==null?void 0:p.id;v&&this.setEntries(E=>E.map(C=>C.type==="user_message"&&C.id===i.id?{...C,id:v}:C))}catch(g){throw this.setEntries(y=>y.filter(v=>!(v.type==="user_message"&&v.id===i.id))),g}}async respondPermission(t,s,n){await G(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(i=>{var u;return i.type!=="tool_call"||((u=i.toolCall.permissionRequest)==null?void 0:u.requestId)!==t?i:{type:"tool_call",toolCall:{...i.toolCall,status:s?"running":"rejected",permissionRequest:void 0}}}))}async interrupt(){this.finalizePendingToolCalls("canceled"),await Xs(this.sessionId)}async setPermissionMode(t){const s=oe();return await G(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_permission_mode",mode:t}}),s}async controlRoundTrip(t,s=8e3){const n=oe(),a=new Promise(i=>{this.pendingControlRequests.set(n,i)}),d=setTimeout(()=>{const i=this.pendingControlRequests.get(n);i&&(this.pendingControlRequests.delete(n),i({data:null,error:"timeout"}))},s);try{return await G(this.sessionId,{type:"control_request",request_id:n,request:t}),await a}catch(i){throw this.pendingControlRequests.delete(n),i}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 G(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=oe();return await G(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_effort",...t?{effort:t}:{effort:null}}}),s}async setThinkingBudget(t){const s=oe();return await G(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,i=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}:{},...i&&i.length>0?{categories:i}:{}}}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"?c("adapter.stopTimeout"):s.error}:{ok:!0}}catch{return{ok:!1,error:c("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 i=d;if(typeof i.name!="string"||!i.name)continue;const u=i.status;if(u!=="connected"&&u!=="failed"&&u!=="needs-auth"&&u!=="pending"&&u!=="disabled")continue;const f=i.serverInfo,p=i.config;n.push({name:i.name,status:u,...f&&typeof f.name=="string"&&typeof f.version=="string"?{serverInfo:{name:f.name,version:f.version}}:{},...typeof i.error=="string"&&i.error?{error:i.error}:{},...typeof(p==null?void 0:p.url)=="string"&&p.url?{url:p.url}:{},...Array.isArray(i.tools)?{toolCount:i.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"?c("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"?c("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,i=[];if(Array.isArray(d))for(const u of d){if(!u||typeof u!="object")continue;const f=u;typeof f.source=="string"&&i.push({source:f.source,settings:f.settings&&typeof f.settings=="object"&&!Array.isArray(f.settings)?f.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},effective:a,sources:i}}async applyFlagSettings(t){const s=await this.controlRoundTrip({subtype:"apply_flag_settings",settings:t},15e3);return s.error?{ok:!1,error:s.error==="timeout"?c("adapter.requestTimeout"):s.error}:{ok:!0}}async rewindToMessage(t){await Zs(this.sessionId,t)}async endSession(t){await G(this.sessionId,{type:"control_request",request_id:oe(),request:{subtype:"end_session",...t?{reason:t}:{}}})}}function yr(r){return r<1024?`${r} B`:r<1024*1024?`${(r/1024).toFixed(1)} KB`:`${(r/(1024*1024)).toFixed(1)} MB`}function Pe({onBack:r,title:t,meta:s,actions:n}){return X(),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":c("nav.dashboard"),title:c("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:c("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(tn,{}),e.jsx(sn,{onSettingsClick:()=>{window.history.pushState(null,"","/settings"),window.dispatchEvent(new PopStateEvent("popstate"))}})]})})}const Yt="rcs:subagent-panel:collapsed";function br(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 jr(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 wr({status:r}){return r==="running"?e.jsx(_e,{className:"h-3 w-3 animate-spin text-brand-text"}):r==="completed"?e.jsx(rr,{className:"h-3 w-3 text-status-success"}):r==="failed"||r==="stopped"?e.jsx(rn,{className:"h-3 w-3 text-status-error"}):null}function hs({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=jr(r.tokenCount),i=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(wr,{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:br(a)})]}),e.jsx("div",{className:`mt-0.5 text-text-secondary ${s?"line-clamp-2 break-words":"truncate"}`,children:u}),(d||i||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"]}),i&&e.jsxs("span",{className:"flex-shrink-0",children:["· ",i]}),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:c("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(nn,{className:"h-3.5 w-3.5"})})]})}function kr({state:r,onStopTask:t}){const[s,n]=l.useState(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Yt)==="1"}catch{return!1}}),a=()=>{n(y=>{const v=!y;try{window.localStorage.setItem(Yt,v?"1":"0")}catch{}return v})},d=Object.values(r.tasks).some(y=>y.status==="running"),i=Object.values(r.tasks).some(y=>y.status!=="running"&&y.evictAfter!==void 0),[,u]=l.useState(0);l.useEffect(()=>{if(!d&&!i)return;const y=setInterval(()=>{u(v=>v+1)},1e3);return()=>clearInterval(y)},[d,i]);const f=ps(r);if(f.length===0)return null;const p=f.filter(y=>y.status==="running").length,g=p>0?`${p} running`:`${f.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(ds,{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:f.map(y=>e.jsx(hs,{task:y,onStopTask:t},y.taskId))})]})})}function vr(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 Nr(r){return r?Date.now()-r<6e4:!1}function _r({onClose:r,session:t,liveStatus:s,pendingPermissions:n,onInterrupt:a,onDelete:d,subagentState:i,onStopTask:u,onEndSession:f}){const[p,g]=l.useState(!1),y=async()=>{await navigator.clipboard.writeText(t.id),g(!0),setTimeout(()=>g(!1),1500)},[v,E]=l.useState(!1),C=async()=>{if(!(!f||v)&&window.confirm(c("task.endConfirm"))){E(!0);try{await f(),r()}catch{E(!1)}}},b=n.length,m=t.worker,h=t.work_item,w=t.environment;return e.jsx(de,{open:!0,onOpenChange:T=>{T||r()},children:e.jsxs(ue,{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(me,{children:e.jsx(xe,{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(In,{className:"h-3.5 w-3.5"}),"Status"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(an,{status:s||t.status||"unknown"}),e.jsx("span",{className:"text-xs text-text-muted",children:m&&(Nr(m.last_heartbeat_at)?"· worker online":"· worker offline")})]}),e.jsxs("dl",{className:"space-y-1 text-xs text-text-muted",children:[m&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx($t,{className:"h-3 w-3"}),"Heartbeat"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:vr(m.last_heartbeat_at)})]}),w&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(us,{className:"h-3 w-3"}),"Environment"]}),e.jsx("dd",{className:"truncate text-text-secondary",children:w.machine_name||w.id})]}),t.created_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx($t,{className:"h-3 w-3"}),"Created"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:ls(t.created_at)})]})]})]}),e.jsx(Tr,{state:i,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(_e,{className:"h-3.5 w-3.5"}),"Pending Actions"]}),b>0?e.jsxs("div",{className:"rounded-md bg-status-warning/10 px-3 py-2 text-xs text-status-warning",children:[b," permission request",b>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(ir,{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"}),f&&e.jsx("button",{onClick:C,disabled:v,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:c("task.endHint"),children:v?"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(on,{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(Gn,{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:y,className:"text-text-muted hover:text-text-primary transition-colors flex-shrink-0",title:"Copy session id",children:p?"✓":"⧉"})]})]}),h&&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:h.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:h.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})]}),w&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Worker type"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:w.worker_type})]})]})]})]})]})})}const Sr={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"},Cr=new Set(["dream"]);function Tr({state:r,onStopTask:t}){const s=Object.values(r.tasks).some(f=>f.status==="running"),n=Object.values(r.tasks).some(f=>f.status!=="running"&&f.evictAfter!==void 0),[,a]=l.useState(0);l.useEffect(()=>{if(!s&&!n)return;const f=setInterval(()=>{a(p=>p+1)},1e3);return()=>clearInterval(f)},[s,n]);const d=ps(r),i=d.filter(f=>f.status==="running").length,u=d.length-i;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(Zn,{className:"h-3.5 w-3.5"}),c("task.backgroundTasks")]}),d.length>0&&e.jsx("span",{className:"font-mono text-[10px] text-text-muted",children:i>0&&u>0?U("task.mixedCount",{running:i,recent:u}):i>0?U("task.runningCount",{count:i}):U("task.recentCount",{count:d.length})})]}),d.length===0?e.jsx("p",{className:"text-xs text-text-muted",children:c("task.noBackgroundTasks")}):e.jsx("div",{className:"max-h-[38vh] space-y-2 overflow-y-auto overscroll-contain pr-1",children:xr(d).map(f=>{const p=!Cr.has(f.taskType),g=Sr[f.taskType]??"task.type.tasks";return e.jsxs("div",{className:"space-y-1",children:[p&&e.jsxs("div",{className:"pl-1 text-[10px] font-medium uppercase tracking-wide text-text-muted/80",children:[c(g)," (",f.tasks.length,")"]}),f.tasks.map(y=>e.jsx(hs,{task:y,onStopTask:t,fullText:!0},y.taskId))]},f.taskType)})})]})}const Er={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"},Mr={connected:"mcp.status.connected",failed:"mcp.status.failed","needs-auth":"mcp.status.needsAuth",pending:"mcp.status.pending",disabled:"mcp.status.disabled"};function Rr({onClose:r,fetchServers:t,onToggle:s,onReconnect:n}){X();const[a,d]=l.useState(null),[i,u]=l.useState(null),[f,p]=l.useState(null),[g,y]=l.useState(null),v=l.useCallback(async()=>{p(null),y(null);try{const b=await t();d(b),u(null)}catch(b){Ue("[McpPanel] fetch failed",b),u(c("mcp.loadFailed"))}},[t]);l.useEffect(()=>{v()},[v]);const E=async b=>{const m=b.status==="disabled";p(`toggle:${b.name}`),y(null);try{const h=await s(b.name,m);h.ok||y(h.error||c("mcp.toggleFailed"))}finally{await v()}},C=async b=>{p(`reconnect:${b.name}`),y(null);try{const m=await n(b.name);m.ok||y(m.error||c("mcp.reconnectFailed"))}finally{await v()}};return e.jsx(de,{open:!0,onOpenChange:b=>{b||r()},children:e.jsxs(ue,{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(me,{children:e.jsxs(xe,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(xs,{className:"h-4 w-4"}),c("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&&!i&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(_e,{className:"h-3.5 w-3.5 animate-spin"}),c("mcp.loading")]}),i&&e.jsx("p",{className:"text-xs text-status-error",children:i}),a!==null&&a.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:c("mcp.empty")}),a==null?void 0:a.map(b=>{const m=f===`toggle:${b.name}`,h=f===`reconnect:${b.name}`,w=b.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:b.name}),e.jsx("span",{className:`flex-shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium ${Er[b.status]}`,children:c(Mr[b.status])})]}),e.jsxs("div",{className:"mt-0.5 truncate text-xs text-text-muted",children:[b.serverInfo?`${b.serverInfo.name} v${b.serverInfo.version}`:b.url||"stdio",b.toolCount!==void 0&&` · ${U("mcp.toolCount",{n:b.toolCount})}`]}),b.error&&e.jsx("div",{className:"mt-1 truncate text-xs text-status-error",title:b.error,children:b.error})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>void C(b),disabled:h||w,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:c("mcp.reconnect"),children:e.jsx(Dn,{className:`h-3.5 w-3.5 ${h?"animate-spin":""}`})}),e.jsx("button",{type:"button",role:"switch","aria-checked":!w,onClick:()=>void E(b),disabled:m,className:`relative h-5 w-9 rounded-full transition-colors disabled:opacity-50 ${w?"bg-surface-3":"bg-brand"}`,title:w?c("mcp.enable"):c("mcp.disable"),children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${w?"left-0.5":"left-4.5"}`})})]})]})},b.name)})]})]})})}function Ar(r){if(r==null)return c("settings.unset");if(typeof r=="string")return r;try{return JSON.stringify(r)}catch{return String(r)}}function Jt(r){if(r==null)return c("settings.unset");if(typeof r=="object")try{return JSON.stringify(r,null,2)}catch{return String(r)}return String(r)}function Ir({onClose:r,fetchSettings:t,onApply:s}){X();const[n,a]=l.useState(null),[d,i]=l.useState(null),[u,f]=l.useState(""),[p,g]=l.useState(null),[y,v]=l.useState(null),[E,C]=l.useState(null),[b,m]=l.useState(!1),h=l.useCallback(async()=>{g(null),v(null),C(null),m(!1);try{const S=await t();a(S),i(S?null:c("settings.loadFailed"))}catch(S){Ue("[SettingsDrawer] fetch failed",S),i(c("settings.loadFailed"))}},[t]);l.useEffect(()=>{h()},[h]);const w=l.useMemo(()=>n?Object.entries(n.effective).filter(([,S])=>S!==void 0).sort(([S],[P])=>S.localeCompare(P)):[],[n]),T=l.useMemo(()=>{const S=u.trim().toLowerCase();return S?w.filter(([P,V])=>`${P} ${Ar(V)}`.toLowerCase().includes(S)):w},[w,u]),k=S=>typeof S[1]=="boolean",j=l.useMemo(()=>T.filter(k),[T]),N=l.useMemo(()=>T.filter(S=>!k(S)),[T]),M=l.useMemo(()=>E===null?null:w.find(([S])=>S===E)??null,[w,E]),$=async()=>{if(M)try{await navigator.clipboard.writeText(Jt(M[1])),m(!0),window.setTimeout(()=>m(!1),1500)}catch(S){Ue("[SettingsDrawer] copy failed",S)}},K=async(S,P)=>{g(S),v(null);try{const V=await s({[S]:!P});V.ok||v(V.error||c("settings.writeFailed"))}finally{await h()}};return e.jsx(de,{open:!0,onOpenChange:S=>{S||r()},children:e.jsxs(ue,{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(me,{children:e.jsxs(xe,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(fs,{className:"h-4 w-4"}),c("session.settings.title")]})}),e.jsxs("div",{className:"mt-3 space-y-4 text-sm",children:[y&&e.jsx("div",{className:"rounded-md bg-status-error/10 px-3 py-2 text-xs text-status-error",children:y}),n===null&&!d&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(_e,{className:"h-3.5 w-3.5 animate-spin"}),c("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:c("settings.model")}),e.jsx("code",{className:"font-mono text-text-secondary",children:n.applied.model||c("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:c("settings.hint")})]}),M?e.jsxs("section",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>{C(null),m(!1)},className:"flex items-center gap-1.5 text-xs text-text-muted transition-colors hover:text-text-primary",children:[e.jsx(qn,{className:"h-3.5 w-3.5"}),c("settings.back")]}),e.jsx("div",{className:"break-all font-mono text-xs font-medium text-text-primary",children:M[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:Jt(M[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:[b?e.jsx(Se,{className:"h-3.5 w-3.5 text-status-success"}):e.jsx(On,{className:"h-3.5 w-3.5"}),b?c("settings.copied"):c("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(it,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{value:u,onChange:S=>f(S.target.value),placeholder:c("settings.searchPlaceholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"})]}),T.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:c("settings.noMatch")}),j.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:U("settings.togglable",{n:j.length})}),j.map(([S,P])=>{const V=p===S;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:S}),e.jsx("button",{type:"button",role:"switch","aria-checked":P,disabled:V,onClick:()=>void K(S,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?c("settings.turnOff"):c("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"}`})})]},S)})]}),N.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:U("settings.readOnly",{n:N.length})}),N.map(([S])=>e.jsxs("button",{type:"button",onClick:()=>C(S),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:c("settings.viewDetail"),children:[e.jsx("span",{className:"truncate font-mono text-xs text-text-primary",children:S}),e.jsx(ds,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"})]},S))]})]})]})]})]})})}function $r({onClose:r,onAsk:t}){X();const[s,n]=l.useState([]),[a,d]=l.useState(""),[i,u]=l.useState(!1),f=async()=>{const p=a.trim();if(!p||i)return;const g=Date.now();n(y=>[...y,{id:g,question:p,answer:null}]),d(""),u(!0);try{const y=await t(p);n(v=>v.map(E=>E.id===g?{...E,answer:y??c("sideQuestion.noAnswer"),error:y===null}:E))}finally{u(!1)}};return e.jsx(de,{open:!0,onOpenChange:p=>{p||r()},children:e.jsxs(ue,{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(me,{children:e.jsxs(xe,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(ms,{className:"h-4 w-4"}),c("sideQuestion.title")]})}),e.jsx("p",{className:"mt-1 text-[10px] leading-relaxed text-text-muted",children:c("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:c("sideQuestion.empty")}),s.map(p=>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:p.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:p.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:p.error?"text-status-error":"",children:e.jsx(ln,{children:p.answer})})})]})]},p.id))]}),e.jsxs("div",{className:"mt-3 flex items-end gap-2",children:[e.jsx("textarea",{value:a,onChange:p=>d(p.target.value),onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&!p.nativeEvent.isComposing&&(p.preventDefault(),f())},rows:Math.min(4,Math.max(1,a.split(`
|
|
76
|
-
`).length)),placeholder:c("sideQuestion.placeholder"),disabled:i,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 f(),disabled:i||!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:c("sideQuestion.send"),children:i?e.jsx(_e,{className:"h-4 w-4 animate-spin"}):e.jsx(cn,{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 Xt(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 Dr({requestId:r,toolName:t,toolInput:s,description:n,suggestions:a,onApprove:d,onApproveAlways:i,onReject:u}){X();const f=s&&typeof s=="object"&&!Array.isArray(s)?s:{},p=dn(un(t),f,{writeUnknownLabel:c("permission.writeUnknown")}),g=typeof s=="string"?s:JSON.stringify(s,null,2),y=Array.isArray(a)&&a.length>0;return e.jsxs("div",{role:"group","aria-label":U("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(mn,{className:"h-3 w-3"})}),e.jsx("span",{className:"text-sm font-semibold font-display text-approve-text",children:c("permission.title")})]}),n&&e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:z(n)}),e.jsx("div",{className:"mb-2 font-mono text-xs font-bold text-text-primary",children:z(t)}),t!=="AskUserQuestion"&&(p?e.jsx("div",{className:"mb-3 space-y-2",children:p.map((v,E)=>e.jsx(xn,{filePath:v.filePath,oldString:v.oldString,newString:v.newString,label:v.label},E))}):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:Dt(g,500)})),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:d,className:te("rounded-lg bg-approve px-4 py-2 text-sm font-medium font-display text-white hover:bg-approve-hover transition-colors",at),children:c("permission.approve")}),y&&i&&e.jsxs("button",{onClick:i,className:te("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:c("permission.alwaysAllowHint").replace("{rule}",Xt(t,a)),children:[e.jsx(mr,{className:"h-3.5 w-3.5"}),c("permission.alwaysAllow")," ",Dt(Xt(t,a),40)]}),e.jsx("button",{onClick:u,className:te("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:c("permission.reject")})]})]})}function qr({questions:r,description:t,onSubmit:s,onSkip:n}){const[a,d]=l.useState({}),[i,u]=l.useState({}),[f,p]=l.useState(0),g=(C,b,m)=>{if(m){const h=a[C]||[],w=h.includes(b)?h.filter(T=>T!==b):[...h,b];d({...a,[C]:w})}else d({...a,[C]:b})},y=C=>{var m;const b=(m=i[C])==null?void 0:m.trim();b&&(d({...a,[C]:b}),u({...i,[C]:""}))},v=()=>{var b,m;const C={};for(const[h,w]of Object.entries(a)){const T=r[parseInt(h,10)];T&&(typeof w=="number"?C[h]=((m=(b=T.options)==null?void 0:b[w])==null?void 0:m.label)||String(w):Array.isArray(w)?C[h]=w.map(k=>{var j,N;return((N=(j=T.options)==null?void 0:j[k])==null?void 0:N.label)||String(k)}):C[h]=w)}s(C)};if(r.length<=1){const C=r[0]||{question:t,options:[],multiSelect:!1},b=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:z(t||C.question||"Question")}),e.jsxs("div",{className:"space-y-2",children:[(C.options||[]).map((m,h)=>{const w=b?(a[0]||[]).includes(h):a[0]===h;return e.jsxs("button",{onClick:()=>g(0,h,b),className:te("w-full rounded-lg border px-4 py-2.5 text-left text-sm font-display transition-colors",w?"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:z(m.label)}),m.description&&e.jsx("div",{className:"mt-0.5 text-xs font-sans text-text-muted",children:z(m.description)})]},h)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:i[0]||"",onChange:m=>u({...i,0:m.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:m=>m.key==="Enter"&&y(0)}),e.jsx("button",{onClick:()=>y(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:v,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 E=r[f];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:z(t||"Questions")}),e.jsx("div",{className:"mb-3 flex gap-1 overflow-x-auto",children:r.map((C,b)=>e.jsx("button",{onClick:()=>p(b),className:te("rounded-md px-3 py-1.5 text-xs font-display whitespace-nowrap transition-colors",f===b?"bg-brand/20 text-brand-text":"text-text-muted hover:bg-surface-2"),children:C.header||`Q${b+1}`},b))}),E&&e.jsx(Pr,{question:E,qIdx:f,answers:a,otherTexts:i,onSelect:g,onOtherTextChange:(C,b)=>u({...i,[C]:b}),onOtherSubmit:y}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-display text-text-muted",children:[f+1," / ",r.length]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:v,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 Pr({question:r,qIdx:t,answers:s,otherTexts:n,onSelect:a,onOtherTextChange:d,onOtherSubmit:i}){const u=r.multiSelect||!1;return e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:z(r.question)}),e.jsxs("div",{className:"space-y-2",children:[(r.options||[]).map((f,p)=>{const g=u?(s[t]||[]).includes(p):s[t]===p;return e.jsxs("button",{onClick:()=>a(t,p,u),className:te("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:z(f.label)}),f.description&&e.jsx("div",{className:"mt-0.5 text-xs font-sans text-text-muted",children:z(f.description)})]},p)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n[t]||"",onChange:f=>d(t,f.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:f=>f.key==="Enter"&&i(t)}),e.jsx("button",{onClick:()=>i(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 Or({planContent:r,description:t,onSubmit:s}){const[n,a]=l.useState(null),[d,i]=l.useState(""),u=!r||!r.trim(),f=()=>{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(Se,{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:Ur(r)}}),e.jsx("div",{className:"space-y-2",children:u?e.jsxs(e.Fragment,{children:[e.jsx(Ne,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes"}),e.jsx(Ne,{selected:n==="no",onClick:()=>a("no"),label:"No"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ne,{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(Ne,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes, manually approve edits",desc:"Approve plan but confirm each edit"}),e.jsx(Ne,{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:p=>i(p.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:f,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 Ne({selected:r,onClick:t,label:s,desc:n}){return e.jsxs("button",{onClick:t,className:te("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:te("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 Ur(r){let t=z(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 Fr({request:r,onSubmit:t}){X();const s=Kr(r.requestedSchema),n=Lr(r.requestedSchema),[a,d]=l.useState({}),i=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(Zt,{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(Un,{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:c("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:c("common.cancel")})]})]}):e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx(Zt,{serverName:r.serverName,message:r.message}),s.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:s.map(({name:u,prop:f})=>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:c("elicitation.required")})]}),f.description&&e.jsx("div",{className:"mb-1 text-xs text-text-muted",children:z(f.description)}),e.jsx("input",{type:f.type==="number"?"number":"text",value:a[u]??"",onChange:p=>d(g=>({...g,[u]:p.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:f,prop:p}of s){const g=(a[f]??"").trim();g&&(u[f]=p.type==="number"?Number(g):g)}t("accept",u)},disabled:!i,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:c("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:c("elicitation.decline")})]})]})}function Zt({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(sr,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-sm font-semibold text-text-primary",children:[c("elicitation.title")," ",e.jsx("span",{className:"font-mono text-xs text-text-muted",children:z(r)})]})]}),t&&e.jsx("div",{className:"text-sm text-text-secondary",children:z(t)})]})}function Kr(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 Lr(r){const t=r==null?void 0:r.required;return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function Br(r){const[t,s]=l.useState([]),[n,a]=l.useState(!0),[d,i]=l.useState(null),u=l.useCallback(async()=>{a(!0),i(null);try{const g=await fn(r);s(g)}catch(g){i(g instanceof Error?g.message:"Failed to load shares")}finally{a(!1)}},[r]);l.useEffect(()=>{u()},[u]);const f=l.useCallback(async g=>{i(null);try{const y=await pn(r,g);return await u(),y}catch(y){throw i(y instanceof Error?y.message:"Failed to create share"),y}},[r,u]),p=l.useCallback(async g=>{i(null);try{await hn(r,g),await u()}catch(y){throw i(y instanceof Error?y.message:"Failed to revoke share"),y}},[r,u]);return{shares:t,isLoading:n,error:d,createShare:f,revokeShare:p,refresh:u}}function Hr({open:r,onClose:t,sessionId:s,sessionTitle:n}){X();const{shares:a,isLoading:d,error:i,createShare:u,revokeShare:f}=Br(s),[p,g]=l.useState("user"),[y,v]=l.useState(""),[E,C]=l.useState(""),[b,m]=l.useState("read"),[h,w]=l.useState(""),[T,k]=l.useState(!1),[j,N]=l.useState(null),[M,$]=l.useState(""),[K,S]=l.useState(!1),[P,V]=l.useState(!1);l.useEffect(()=>{r&&(g("user"),v(""),C(""),m("read"),w(""),k(!1),N(null),$(""),S(!1),V(!1))},[r]);const Ce=async()=>{k(!0),$(""),N(null);try{const D={grantedTo:p==="user"?{userId:y.trim()}:{teamId:E.trim()},permission:b};h.trim()&&(D.expiresAt=h.trim());const fe=await u(D);N(`${window.location.origin}/code/s/${fe.shareToken}`)}catch(D){$(D instanceof Error?D.message:"Failed to create share")}finally{k(!1)}},Te=async D=>{try{await f(D)}catch{}},J=async()=>{if(!j)return;V(!1);try{if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(j),S(!0),setTimeout(()=>S(!1),2e3);return}}catch{}const D=document.createElement("textarea");D.value=j,D.style.position="fixed",D.style.opacity="0",document.body.appendChild(D),D.select();try{document.execCommand("copy"),S(!0),setTimeout(()=>S(!1),2e3)}catch{V(!0)}document.body.removeChild(D)};return e.jsx(de,{open:r,onOpenChange:D=>{D||t()},children:e.jsxs(ue,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(me,{children:e.jsxs(xe,{className:"font-display text-lg font-semibold text-text-primary",children:[c("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:c("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 ${p==="user"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:c("share.user")}),e.jsx("button",{onClick:()=>g("team"),className:`rounded-md px-3 py-1 text-sm transition-colors ${p==="team"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:c("share.team")})]}),p==="user"?e.jsx(Pn,{onSelect:v,placeholder:c("share.userIdPlaceholder"),actionLabel:c("share.selectUser")}):e.jsx("input",{type:"text",value:E,onChange:D=>C(D.target.value),placeholder:c("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"}),p==="user"&&y&&e.jsxs("p",{className:"mt-1 text-xs text-text-muted",children:[c("share.selectedUser"),": ",e.jsx("span",{className:"font-mono",children:y})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:c("share.permission")}),e.jsxs("select",{value:b,onChange:D=>m(D.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:c("share.permissionRead")}),e.jsx("option",{value:"write",children:c("share.permissionWrite")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:c("share.expiresAt")}),e.jsx("input",{type:"datetime-local",value:h,onChange:D=>w(D.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"})]}),(M||i)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:M||i}),j&&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:c("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:j}),e.jsx("button",{onClick:J,className:"shrink-0 rounded-md bg-brand px-2 py-1 text-xs text-white hover:bg-brand-light transition-colors",children:K?c("share.copied"):c("share.copy")})]}),P&&e.jsx("p",{className:"mt-1 text-xs text-status-error",children:c("share.copyFailed")})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"mb-2 text-sm font-medium text-text-secondary",children:c("share.existingShares")}),d?e.jsx("p",{className:"text-sm text-text-muted",children:c("share.loading")}):a.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:c("share.none")}):e.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto",children:a.map(D=>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:D.granted_to_user||D.granted_to_team||"Unknown"}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[D.permission==="write"?c("share.permissionWrite"):c("share.permissionRead"),D.expires_at?` · expires ${D.expires_at}`:""]})]}),e.jsx("button",{onClick:()=>Te(D.id),className:"shrink-0 rounded-md px-2 py-1 text-xs text-status-error hover:bg-surface-3 transition-colors",children:c("share.revoke")})]},D.id))})]})]}),e.jsxs($n,{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:c("common.close")}),e.jsx("button",{onClick:Ce,disabled:T||(p==="user"?!y.trim():!E.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:T?c("common.creating"):c("share.createShare")})]})]})})}function Wr(r){const t=new Date,s=new Date(t.getTime()-1440*60*1e3),n=(i,u)=>i.getFullYear()===u.getFullYear()&&i.getMonth()===u.getMonth()&&i.getDate()===u.getDate(),a={today:[],yesterday:[],earlier:[]};for(const i of r){const u=new Date(i.modified||0);n(u,t)?a.today.push(i):n(u,s)?a.yesterday.push(i):a.earlier.push(i)}return[["today",c("resume.today")],["yesterday",c("resume.yesterday")],["earlier",c("resume.earlier")]].map(([i,u])=>({label:u,items:a[i]})).filter(i=>i.items.length>0)}function Qr(r){return r?new Date(r).toLocaleString():""}function zr({open:r,onClose:t,adapter:s,onResume:n}){const a=X(),[d,i]=l.useState([]),[u,f]=l.useState(!1),[p,g]=l.useState("");l.useEffect(()=>{if(!r)return;let v=!1;return f(!0),g(""),i([]),s.listResumableSessions().then(E=>{v||i(E)}).catch(E=>{v||g(E instanceof Error?E.message:String(E))}).finally(()=>{v||f(!1)}),()=>{v=!0}},[r,s]);const y=l.useMemo(()=>Wr(d),[d,a]);return e.jsx(de,{open:r,onOpenChange:v=>{v||t()},children:e.jsxs(ue,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(me,{children:e.jsx(xe,{className:"font-display text-lg font-semibold text-text-primary",children:c("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:c("resume.loading")}),!u&&p&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:p}),!u&&!p&&d.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-text-muted",children:c("resume.empty")}),!u&&!p&&y.map(v=>e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-xs font-medium text-text-muted",children:v.label}),e.jsx("div",{className:"space-y-1",children:v.items.map(E=>e.jsxs("button",{type:"button",onClick:()=>n(E),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:E.title}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[Qr(E.modified),E.gitBranch?` · ${E.gitBranch}`:""]})]},E.sessionId))})]},v.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:c("common.cancel")})})]})})}class Vr{constructor(t,s,n,a){A(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,es(n),"send")})}catch(n){this.rollback(s,es(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 es(r){return r instanceof Error?r.message:String(r)}function ot(r){const t=l.useRef(r);t.current=r;const s=l.useRef(null);s.current||(s.current=new Vr(r.value,a=>t.current.apply(a),a=>t.current.send(a),(a,d)=>{var i,u;return(u=(i=t.current).onError)==null?void 0:u.call(i,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 gs="rcs_context_usage_";function ys(){try{if(typeof localStorage<"u")return localStorage}catch{}return null}function ts(){return{totalTokens:0,rawMaxTokens:0,percentage:0}}function Gr(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,i=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}:{},...i&&i.length>0?{categories:i}:{}}}function Yr(r,t=ys()){if(!t||!r)return null;try{const s=t.getItem(gs+r);return s?Gr(JSON.parse(s)):null}catch{return null}}function Jr(r,t,s=ys()){if(!(!s||!r))try{s.setItem(gs+r,JSON.stringify(t))}catch{}}function Xr(r){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/acp/relay/${r}`}function Zr(r){const t=Xr(r),s=yn(),n=s?{proxyUrl:t,token:s}:{proxyUrl:t};return new gn(n)}const le=[{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"}],ss="rcs_permission_mode";function ce(r){return r<1e3?String(r):r<1e6?`${(r/1e3).toFixed(1)}k`:`${(r/1e6).toFixed(1)}M`}function ea(r){const t=le.findIndex(s=>s.value===r);return le[(t+1+le.length)%le.length].value}const ct=[{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}],ns="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"}],rs=r=>r.labelKey?c(r.labelKey):r.label,as=r=>r.labelKey?c(r.labelKey):r.label,os="rcs_effort";function ta(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,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,side_question:!1}}function sa({budget:r,onBudgetChange:t,disabled:s}){const[n,a]=l.useState(!1),d=ct.find(i=>i.value===r);return e.jsxs(Fe,{open:n,onOpenChange:a,children:[e.jsx(Ke,{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:c("session.thinking.title"),children:[e.jsx(An,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?as(d):c("session.thinking.fallback")}),n?e.jsx(Le,{className:"h-3 w-3"}):e.jsx(Be,{className:"h-3 w-3"})]})}),e.jsx(He,{className:"w-64 p-1",align:"start",children:ct.map(i=>e.jsxs("button",{type:"button",onClick:()=>{t(i.value,i.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===i.value&&e.jsx(Se,{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:as(i)}),e.jsx("div",{className:"text-xs text-text-muted",children:i.descKey?c(i.descKey):i.description})]})]},i.value))})]})}function na({effort:r,onEffortChange:t,disabled:s}){const[n,a]=l.useState(!1),d=dt.find(i=>i.value===r);return e.jsxs(Fe,{open:n,onOpenChange:a,children:[e.jsx(Ke,{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:c("session.effort.title"),children:[e.jsx(zn,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?rs(d):c("session.effort.fallback")}),n?e.jsx(Le,{className:"h-3 w-3"}):e.jsx(Be,{className:"h-3 w-3"})]})}),e.jsx(He,{className:"w-64 p-1",align:"start",children:dt.map(i=>e.jsxs("button",{type:"button",onClick:()=>{t(i.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===i.value&&e.jsx(Se,{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:rs(i)}),e.jsx("div",{className:"text-xs text-text-muted",children:c(i.descKey)})]})]},i.value))})]})}const ra=new Set(["Free space","Autocompact buffer","Compact buffer"]),is=["bg-brand","bg-status-active","bg-status-success","bg-violet-500","bg-amber-500","bg-pink-500","bg-teal-500"];function aa({usage:r}){const t=Math.min(100,Math.max(0,r.percentage)),s=t>=80,n=(r.categories??[]).filter(u=>!u.isDeferred&&!ra.has(u.name)),a=(r.categories??[]).filter(u=>u.isDeferred),d=n.reduce((u,f)=>u+f.tokens,0),i=[`${U("session.context.tooltip",{used:ce(r.totalTokens),max:ce(r.rawMaxTokens)})}${r.model?` · ${r.model}`:""}`,...n.slice(0,8).map(u=>`${u.name}: ${ce(u.tokens)}`),...a.slice(0,3).map(u=>`${u.name}${c("session.context.deferredSuffix")}: ${ce(u.tokens)}`)];return e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-text-muted font-mono",title:i.join(`
|
|
77
|
-
`),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,f)=>e.jsx("span",{className:s&&f===0?"bg-status-warning":is[f%is.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 oa({models:r,currentModelId:t,onSelect:s,disabled:n}){const[a,d]=l.useState(!1),i=r.find(p=>p.modelId===t)??null,u=r.length>0,f=async p=>{s(p.modelId),d(!1)};return e.jsxs(Fe,{open:a,onOpenChange:u?d:void 0,children:[e.jsx(Ke,{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:c("session.model.title"),children:[e.jsx(us,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-32 truncate",children:(i==null?void 0:i.name)??t??c("session.model.title")}),a?e.jsx(Le,{className:"h-3 w-3"}):e.jsx(Be,{className:"h-3 w-3"})]})}),e.jsx(He,{className:"w-72 p-0",align:"start",children:e.jsx(Rn,{models:r,currentModelId:t,onSelect:f,showSearch:r.length>5})})]})}function ia({mode:r,onModeChange:t,disabled:s}){const[n,a]=l.useState(!1),d=le.find(i=>i.value===r);return e.jsxs(Fe,{open:n,onOpenChange:a,children:[e.jsx(Ke,{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:c("session.mode.title"),children:[e.jsx(Mn,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?c(d.labelKey):r}),n?e.jsx(Le,{className:"h-3 w-3"}):e.jsx(Be,{className:"h-3 w-3"})]})}),e.jsx(He,{className:"w-64 p-1",align:"start",children:le.map(i=>e.jsxs("button",{type:"button",onClick:()=>{t(i.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===i.value&&e.jsx(Se,{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:c(i.labelKey)}),e.jsx("div",{className:"text-xs text-text-muted",children:c(i.descKey)})]})]},i.value))})]})}function va({sessionId:r,onBack:t}){var Rt;X();const[s,n]=l.useState(null),[a,d]=l.useState(null),[i,u]=l.useState(""),[f,p]=l.useState(!1),[g,y]=l.useState(!1),[v,E]=l.useState(!1),[C,b]=l.useState(!1),[m,h]=l.useState(!1),[w,T]=l.useState(!1),[k,j]=l.useState(""),[N,M]=l.useState(0),$=l.useRef(null),[K,S]=l.useState({text:"",nonce:0}),[P,V]=l.useState(!1),[Ce,Te]=l.useState(!1),[J,D]=l.useState(!1),[fe,ut]=l.useState(0),[bs,js]=l.useState(0),[pe,Z]=l.useState([]),[Y,he]=l.useState(!1),[ge,re]=l.useState([]),[W,We]=l.useState(null),[mt,ws]=l.useState(()=>lt()),[Q,ks]=l.useState(null),[xt,vs]=l.useState(()=>localStorage.getItem(ns)||"off"),[Ns,ft]=l.useState(()=>Yr(r)),[Qe,ze]=l.useState(!0),[ye,_s]=l.useState(null),[Ee,pt]=l.useState(null),[Me,Re]=l.useState([]),[Ss,Ve]=l.useState(!1),[Ge,ht]=l.useState(""),Ye=l.useRef(null),[Ae,Cs]=l.useState(()=>localStorage.getItem(ss)||"default"),[gt,yt]=l.useState(null),be=l.useRef(null),[bt,jt]=l.useState(null),je=l.useRef(null),ae=l.useRef(null),wt=l.useRef(pe);wt.current=pe;const Ie=l.useRef(null);Ie.current||(Ie.current=new Ln(Bn()));const kt=l.useRef(r);kt.current=(s==null?void 0:s.title)||r,l.useEffect(()=>{var o;(o=Ie.current)==null||o.reset()},[r]);const se=l.useCallback(o=>{yt(o),be.current&&clearTimeout(be.current),be.current=setTimeout(()=>yt(null),5e3)},[]),ee=l.useCallback(o=>{jt(o),je.current&&clearTimeout(je.current),je.current=setTimeout(()=>jt(null),5e3)},[]),$e=ot({value:Ae,apply:o=>{Cs(o);try{localStorage.setItem(ss,o)}catch{}},send:o=>{const x=ae.current;return x?x.setPermissionMode(o):Promise.reject(new Error("adapter not ready"))},onError:(o,x)=>{console.error("[SessionDetail] set permission mode failed:",o),se(x==="send"?U("session.mode.switchFailedRequest",{message:o}):o||c("session.mode.switchFailed"))}}),Je=l.useCallback(o=>$e.set(o),[$e]),Xe=ot({value:xt,apply:o=>{vs(o);try{localStorage.setItem(ns,o)}catch{}},send:o=>{var R;const x=ae.current;if(!x)return Promise.reject(new Error("adapter not ready"));const _=((R=ct.find(I=>I.value===o))==null?void 0:R.tokens)??null;return x.setThinkingBudget(_)},onError:(o,x)=>{console.error("[SessionDetail] set thinking budget failed:",o),se(x==="send"?U("session.thinking.failedRequest",{message:o}):o||c("session.thinking.failed"))}}),q=l.useMemo(()=>new gr(r,Z,{onStatusChange:o=>{var x;d(o),he(o==="running"||o==="requires_action"),(x=Ie.current)==null||x.onStatus(o,kt.current)},onError:o=>{console.error("[RCSChatAdapter] error:",o)},onPermissionRequest:o=>{re(x=>x.some(_=>_.requestId===o.requestId)?x:[...x,o])},onModelsStateChange:o=>{We(o)},onSubagentUpdate:o=>{ws(o)},onControlResponse:o=>{Xe.handleControlResponse(o)||$e.handleControlResponse(o)},onPermissionModeChange:o=>{$e.sync(o)},onUsageChange:o=>{_s(x=>({inputTokens:Math.max((x==null?void 0:x.inputTokens)??0,o.inputTokens),outputTokens:Math.max((x==null?void 0:x.outputTokens)??0,o.outputTokens),totalCostUsd:o.totalCostUsd??(x==null?void 0:x.totalCostUsd)??null}))},onWorkerInfoChange:o=>{ks(x=>JSON.stringify(x)===JSON.stringify(o)?x:o)},onElicitationRequest:o=>{pt(o)}}),[r,se]);l.useEffect(()=>(ae.current=q,()=>{q.disconnect()}),[q]);const F=l.useMemo(()=>ta(Q),[Q]),vt=F.stop_task?o=>{q.stopSubagent(o).then(x=>{x.ok||ee(x.error||c("session.stopTask.failed"))})}:void 0,Ts=X(),Ze=l.useMemo(()=>bn((Q==null?void 0:Q.commands)??[],(Q==null?void 0:Q.skills)??[]),[Q,Ts]),we=l.useMemo(()=>jn(pe,k),[pe,k]),Es=l.useCallback(o=>Xe.set(o),[Xe]),[Nt,Ms]=l.useState(()=>localStorage.getItem(os)||"auto"),Rs=ot({value:Nt,apply:o=>{Ms(o);try{localStorage.setItem(os,o)}catch{}},send:o=>{var R;const x=ae.current;if(!x)return Promise.reject(new Error("adapter not ready"));const _=(R=dt.find(I=>I.value===o))==null?void 0:R.effort;return x.setEffort(_)},onError:(o,x)=>{console.error("[SessionDetail] set effort failed:",o),se(x==="send"?U("session.effort.failedRequest",{message:o}):o||c("session.effort.failed"))}}),et=l.useCallback(()=>{var o;F.get_context_usage&&((o=ae.current)==null||o.getContextUsage().then(x=>{x&&(ft(x),Jr(r,x))}).catch(()=>{}).finally(()=>ze(!1)))},[F,r]);l.useEffect(()=>{if(!F.get_context_usage)return;Y||et();const o=setInterval(et,6e4);return()=>clearInterval(o)},[F,Y,et]),l.useEffect(()=>{Q&&!F.get_context_usage&&ze(!1)},[Q,F]),l.useEffect(()=>{if(!Qe)return;const o=setTimeout(()=>ze(!1),1e4);return()=>clearTimeout(o)},[Qe]);const _t=l.useRef(J);_t.current=J,l.useEffect(()=>ie.onEvent(x=>{x.type!=="artifact_created"&&x.type!=="artifact_updated"||(_t.current&&js(_=>_+1),ut(_=>_+1))}),[]);const[ke,As]=l.useState("idle");l.useEffect(()=>ie.onStateChange(x=>As(x)),[]),l.useEffect(()=>{J&&ut(0)},[J]),l.useEffect(()=>{let o=!1;async function x(){u("");try{const _=await Ot(r);if(o)return;n(_),d(_.status),Oe(_.status)&&q.markClosed(),he(_.status==="running"||_.status==="requires_action")}catch(_){if(o)return;u(_ instanceof Error?_.message:c("session.loadFailed"));return}try{await q.init()}catch(_){console.warn("Failed to init adapter:",_)}}return x(),()=>{o=!0}},[r,q]);const O=Oe(a),St=l.useRef(a);St.current=a,l.useEffect(()=>{if(O)return;let o=!1;const _=setInterval(async()=>{try{const R=await Ot(r);if(o||R.status===St.current)return;Oe(R.status)&&q.markClosed(),d(R.status),he(R.status==="running"||R.status==="requires_action")}catch{}},6e4);return()=>{o=!0,clearInterval(_)}},[r,O,q]);const L=(s==null?void 0:s.access_level)==="read",Ct=Ns??(Qe&&!O&&!L?ts():null),tt=l.useCallback(()=>{Z([]),ft(ts()),qt(r).catch(o=>{console.warn("[SessionDetail] Failed to clear session history:",o)})},[r]),ve=l.useCallback(async(o,x)=>{const _=ae.current;if(!_||O)return;if(o.sessionId===r){Z(I=>[...I,{type:"command_output",id:`cmd-resume-${Date.now()}`,commandName:"resume",inputText:x??"/resume",title:"Resume",subtitle:c("session.resume.title"),outputText:c("session.resume.currentBlocked"),variant:"error"}]);return}const R=(I,B="default")=>Z(ne=>[...ne,{type:"command_output",id:`cmd-resume-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,commandName:"resume",inputText:x??`/resume ${o.sessionId.slice(0,8)}`,title:"Resume",subtitle:c("session.resume.title"),outputText:I,variant:B}]);R(U("session.resume.restoring",{title:o.title??""}));try{await qt(r),Z([]);const I=await _.resumeSession(o.sessionId);R(I.title?U("session.resume.restoredWithTitle",{count:I.messageCount,title:I.title}):U("session.resume.restored",{count:I.messageCount}))}catch(I){R(U("session.resume.failed",{message:I instanceof Error?I.message:String(I)}),"error")}},[O,r]),Is=l.useCallback(async()=>{if(s!=null&&s.environment_id)try{const o=await wn({environment_id:s.environment_id});window.location.href=`/code/${o.id}?resumeFrom=${r}`}catch(o){ee(U("session.createFailedWithReason",{message:o instanceof Error?o.message:String(o)}))}},[s,r,ee]),$s=l.useRef(new URLSearchParams(window.location.search).get("resumeFrom")),Tt=l.useRef(!1);l.useEffect(()=>{const o=$s.current;!o||Tt.current||!Q||!F.resume||(Tt.current=!0,window.history.replaceState({},"",window.location.pathname),ve({sessionId:o,title:o.slice(0,8),modified:0},null))},[Q,F.resume,ve]);const De=l.useCallback(async o=>{const x=o.text.trim(),_=o.images&&o.images.length>0||o.attachments&&o.attachments.length>0;if(!x&&!_||O)return;const R=/^\/resume(?:\s+(.*))?$/.exec(x);if(R){const B=(R[1]??"").trim();if(!F.resume){Z(ne=>[...ne,{type:"user_message",id:`user-${Date.now()}`,content:x},{type:"command_output",id:`cmd-${Date.now()}`,commandName:"resume",inputText:x,title:"Resume",subtitle:c("session.resume.title"),outputText:c("session.resume.unsupported"),variant:"error"}]);return}B?await ve({sessionId:B,title:B,modified:0},x):h(!0);return}const I=await kn(x,{sessionId:r,availableCommands:Ze,availableModels:(W==null?void 0:W.availableModels)??[],currentModel:W?{modelId:W.currentModelId,name:W.currentModelId}:null,supportsImages:!0,entries:wt.current,setModel:async B=>{await G(r,{type:"control_request",request:{subtype:"set_model",model:B}}),We(ne=>ne&&{...ne,currentModelId:B})},onNewSession:()=>{Z([])}}).catch(()=>null);if(I){if(Ue("[SessionDetail] local command result",I),"clearEntries"in I&&I.clearEntries){tt();return}if("newSession"in I&&I.newSession){tt();return}if("userEntry"in I){Z(B=>[...B,I.userEntry,I.cmdEntry]);return}}he(!0);try{await q.sendMessage(x,o.images,o.attachments)}catch(B){if(console.error("Send failed:",B),B instanceof vn&&B.type==="session_closed"){d("archived"),q.markClosed(),ee(c("session.closedSendBlocked"));return}ee(`${c("session.sendFailed")}${B instanceof Error?`: ${B.message}`:""}`)}},[q,O,r,W,Ze,tt,ee,ve,F]),Ds=l.useCallback(o=>{if(Y){Re(x=>[...x,o]);return}De(o)},[Y,De]),st=l.useRef(!1);l.useEffect(()=>{if(O){Re(x=>x.length>0?[]:x);return}if(Y||Me.length===0||st.current)return;const o=Me[0];o&&(st.current=!0,Re(x=>x.slice(1)),De(o).finally(()=>{st.current=!1}))},[Y,Me,De,O]);const qs=l.useCallback((o,x)=>{if(Y)return;const _=x==="edit"?c("session.rewind.confirmEdit"):c("session.rewind.confirm");window.confirm(`${_}
|
|
78
|
-
${c("session.rewind.confirmBody")}`)&&q.rewindToMessage(o.id).then(()=>{x==="edit"&&o.content&&S(R=>({text:o.content,nonce:R.nonce+1}))}).catch(R=>{console.error("[SessionDetail] rewind failed:",R),ee(U("session.rewind.failed",{message:R instanceof Error?R.message:String(R)}))})},[Y,ee]),Ps=l.useCallback(o=>{const x=we.orderedMatchIds;if(x.length===0)return;const _=(o%x.length+x.length)%x.length;M(_);const R=x[_],I=document.querySelector(`[data-entry-id="${CSS.escape(R)}"]`);I==null||I.scrollIntoView({block:"center",behavior:"smooth"})},[we]),Et=l.useCallback(async()=>{try{await q.interrupt()}catch(o){console.error("Interrupt failed:",o)}finally{he(!1)}},[q]),Os=l.useCallback(()=>{Je(ea(Ae))},[Je,Ae]);l.useEffect(()=>()=>{be.current&&clearTimeout(be.current),je.current&&clearTimeout(je.current)},[]);const Us=l.useCallback(async()=>{if(s&&window.confirm(c("dashboard.confirmDelete").replace("{id}",s.title||s.id)))try{await Pt(s.id),window.location.href="/code/"}catch(o){alert(o instanceof Error?o.message:c("dashboard.deleteFailed"))}},[s]),Fs=l.useCallback(async o=>{try{await q.respondPermission(o,!0)}catch(x){console.error("Failed to approve:",x)}re(x=>x.filter(_=>_.requestId!==o))},[q]),Ks=l.useCallback(async(o,x)=>{try{await q.respondPermission(o,!0,{updated_permissions:x})}catch(_){console.error("Failed to approve with rules:",_)}re(_=>_.filter(R=>R.requestId!==o))},[q]),Ls=l.useCallback(async(o,x)=>{const _=Ee;if(pt(null),!!_)try{await q.respondElicitation(_.requestId,o,x)}catch(R){console.error("Failed to submit elicitation:",R)}},[Ee,q]),Bs=l.useCallback(()=>{!s||L||(ht(s.title||""),Ve(!0),setTimeout(()=>{var o,x;(o=Ye.current)==null||o.focus(),(x=Ye.current)==null||x.select()},0))},[s,L]),Mt=l.useCallback(async()=>{const o=Ge.trim();if(Ve(!1),!(!s||!o||o===s.title))try{const x=await Nn(s.id,o);n(_=>_&&{..._,title:x.title??o})}catch(x){console.error("Rename failed:",x),alert(x instanceof Error?x.message:c("session.rename.failed"))}},[s,Ge]),Hs=l.useCallback(async o=>{try{await q.respondPermission(o,!1)}catch(x){console.error("Failed to reject:",x)}re(x=>x.filter(_=>_.requestId!==o))},[q]),Ws=l.useCallback(async(o,x,_)=>{try{await G(r,{type:"permission_response",approved:!0,request_id:o,updated_input:{questions:_,answers:x}})}catch(R){console.error("Failed to submit answers:",R)}re(R=>R.filter(I=>I.requestId!==o))},[r]),Qs=l.useCallback(async(o,x,_)=>{try{x==="no"?await G(r,{type:"permission_response",approved:!1,request_id:o,..._?{message:_}:{}}):await G(r,{type:"permission_response",approved:!0,request_id:o,updated_permissions:[{type:"setMode",mode:{"yes-accept-edits":"acceptEdits","yes-default":"default"}[x]||"default",destination:"session"}]})}catch(R){console.error("Failed to submit plan response:",R)}re(R=>R.filter(I=>I.requestId!==o))},[r]);return i?e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(Pe,{onBack:t,title:e.jsx("span",{className:"text-xs font-medium text-text-muted",children:c("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:i}),e.jsx("a",{href:"/code/",className:"mt-4 inline-block text-brand-text hover:underline",children:c("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(Pe,{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(ca,{sessionId:r,agentId:s.environment_id})]}):e.jsx(cs,{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(Pe,{onBack:t,title:Ss?e.jsx("input",{ref:Ye,value:Ge,onChange:o=>ht(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),Mt()):o.key==="Escape"&&(o.preventDefault(),Ve(!1))},onBlur:()=>void Mt(),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:!L&&!O?e.jsx("button",{type:"button",onClick:Bs,title:c("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(Kn,{visibility:s.visibility||"private",className:"hidden flex-shrink-0 text-[10px] sm:inline-flex"})]}),meta:e.jsx(e.Fragment,{children:(()=>{var _;const o=s.source==="acp"?"acp":(_=s.environment)==null?void 0:_.worker_type,x=Ut(o);return e.jsx("span",{className:`hidden items-center rounded-full px-2 py-0.5 text-[10px] font-medium sm:inline-flex ${x.colorClass}`,children:x.fullLabel})})()}),actions:e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsxs("button",{onClick:()=>D(!J),className:`relative flex h-7 w-7 items-center justify-center rounded-md transition-colors ${J?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:c("artifacts.title"),children:[e.jsx(_n,{className:"h-3.5 w-3.5"}),fe>0&&!J&&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:fe>9?"9+":fe})]}),F.side_question&&!O&&!L&&e.jsx("button",{onClick:()=>b(!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:c("session.sideQuestion.title"),children:e.jsx(ms,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>{const o=!w;T(o),o?setTimeout(()=>{var x;return(x=$.current)==null?void 0:x.focus()},0):(j(""),M(0))},className:`flex h-7 w-7 items-center justify-center rounded-md transition-colors ${w?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:c("session.search.title"),children:e.jsx(it,{className:"h-3.5 w-3.5"})}),F.mcp_management&&!O&&!L&&e.jsx("button",{onClick:()=>y(!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:c("session.mcp.title"),children:e.jsx(xs,{className:"h-3.5 w-3.5"})}),F.remote_settings&&!O&&!L&&e.jsx("button",{onClick:()=>E(!v),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${v?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:c("session.settings.title"),children:e.jsx(fs,{className:"h-3.5 w-3.5"})}),!L&&(s==null?void 0:s.access_level)!=="write"&&e.jsx("button",{onClick:()=>Te(!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:c("session.share"),children:e.jsx(dr,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>V(!P),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:c("session.info"),children:e.jsx(Jn,{className:"h-3.5 w-3.5"})}),e.jsxs("button",{onClick:()=>p(!f),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:[c("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})]})]})})}),P&&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:c("session.metaSession")})," ",s.id]}),s.environment_id&&e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:c("session.metaEnvironment")})," ",s.environment_id]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:c("session.metaStatus")})," ",a]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:c("session.metaWorker")})," ",Ut(s.source==="acp"?"acp":(Rt=s.environment)==null?void 0:Rt.worker_type).fullLabel]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:c("session.metaCreated")})," ",ls(s.created_at)]})]})})}),(ke==="reconnecting"||ke==="failed")&&e.jsxs("div",{className:`flex items-center justify-center gap-2 px-4 py-1.5 text-xs font-medium ${ke==="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 ${ke==="failed"?"bg-status-error":"animate-pulse bg-status-warning"}`}),ke==="failed"?c("session.sseFailed"):c("session.sseReconnecting")]}),J&&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(Fn,{sessionId:r,embedded:!0,refreshTick:bs})})}),w&&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(it,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{ref:$,value:k,onChange:o=>{j(o.target.value),M(0)},onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),Ps(k&&o.shiftKey?N-1:N+1)):o.key==="Escape"&&(o.preventDefault(),T(!1),j(""))},placeholder:c("session.search.placeholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"}),k.trim()&&e.jsx("span",{className:"flex-shrink-0 font-mono text-[10px] text-text-muted",children:we.orderedMatchIds.length===0?c("session.search.noResults"):`${N+1}/${we.orderedMatchIds.length}`})]})}),e.jsx(Sn,{entries:pe,isLoading:Y,emptyTitle:c("session.emptyTitle"),emptyDescription:c("session.emptyDescription"),searchMatchIds:k.trim()?we.matchIds:void 0,onRewindEntry:F.rewind&&!O&&!L&&!Y?(o,x)=>qs(o,x):void 0}),e.jsx(kr,{state:mt,onStopTask:vt}),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(la,{request:o,onApprove:()=>Fs(o.requestId),onApproveAlways:o.suggestions&&o.suggestions.length>0?()=>Ks(o.requestId,o.suggestions??[]):void 0,onReject:()=>Hs(o.requestId),onSubmitAnswers:Ws,onSubmitPlan:Qs},o.requestId))})}),Ee&&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(Fr,{request:Ee,onSubmit:Ls})})}),bt&&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:bt})}),gt&&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:gt})}),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(ia,{mode:Ae,onModeChange:Je,disabled:O||L}),e.jsx(oa,{models:(W==null?void 0:W.availableModels)??[],currentModelId:(W==null?void 0:W.currentModelId)??null,onSelect:o=>{G(r,{type:"control_request",request:{subtype:"set_model",model:o}}),We(x=>x&&{...x,currentModelId:o})},disabled:O||L}),F.set_max_thinking_tokens&&e.jsx(sa,{budget:xt,onBudgetChange:Es,disabled:O||L}),F.set_effort&&e.jsx(na,{effort:Nt,onEffortChange:o=>Rs.set(o),disabled:O||L})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[Ct&&e.jsx(aa,{usage:Ct}),ye&&e.jsxs("span",{className:"text-[10px] text-text-muted font-mono",title:c("session.usage.total"),children:[ce(ye.inputTokens)," in / ",ce(ye.outputTokens)," out",ye.totalCostUsd!=null&&` · $${ye.totalCostUsd.toFixed(2)}`]})]})]}),O&&(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 Is(),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:c("session.resumeInNew")})}),e.jsx(Cn,{onSubmit:Ds,isLoading:Y,onInterrupt:Et,onCycleMode:Os,disabled:O||L,placeholder:O?c("session.closed"):L?c("session.readOnly"):c("session.inputPlaceholder"),supportsAttachments:!0,commands:Ze,queueWhileLoading:!0,queuedCount:Me.length,onDequeue:o=>Re(x=>x.filter((_,R)=>R!==o)),onSearchFiles:F.file_search?o=>q.searchFiles(o):void 0,historyKey:r,draftOverride:K}),g&&e.jsx(Rr,{onClose:()=>y(!1),fetchServers:()=>q.getMcpServers(),onToggle:(o,x)=>q.toggleMcpServer(o,x),onReconnect:o=>q.reconnectMcpServer(o)}),v&&e.jsx(Ir,{onClose:()=>E(!1),fetchSettings:()=>q.getRemoteSettings(),onApply:o=>q.applyFlagSettings(o)}),C&&e.jsx($r,{onClose:()=>b(!1),onAsk:o=>q.askSideQuestion(o)}),f&&s&&e.jsx(_r,{onClose:()=>p(!1),session:s,liveStatus:a,pendingPermissions:ge,subagentState:mt,onStopTask:vt,onInterrupt:Et,onDelete:Us,onEndSession:F.end_session&&!O&&!L?async()=>{await q.endSession("ended from web"),await Pt(s.id),window.location.href="/code/"}:void 0}),e.jsx(Hr,{open:Ce,onClose:()=>Te(!1),sessionId:s.id,sessionTitle:s.title||void 0}),e.jsx(zr,{open:m,onClose:()=>h(!1),adapter:q,onResume:o=>{h(!1),ve(o,null)}})]})}):e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(Pe,{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:c("session.loading")})})]})}function la({request:r,onApprove:t,onApproveAlways:s,onReject:n,onSubmitAnswers:a,onSubmitPlan:d}){const i=r.toolName,u=r.toolInput,f=r.description||"";if(i==="AskUserQuestion"){const p=u.questions||[];return e.jsx(qr,{requestId:r.requestId,questions:p,description:f,onSubmit:g=>a(r.requestId,g,p),onSkip:n})}if(i==="ExitPlanMode"){const p=u.plan||"";return e.jsx(Or,{requestId:r.requestId,planContent:p,description:f,onSubmit:(g,y)=>d(r.requestId,g,y)})}return e.jsx(Dr,{requestId:r.requestId,toolName:i,toolInput:u,description:f,suggestions:r.suggestions,onApprove:t,onApproveAlways:s,onReject:n})}function ca({sessionId:r,agentId:t}){const[s,n]=l.useState(null),[a,d]=l.useState("disconnected"),[i,u]=l.useState(null),f=l.useRef(null);return l.useEffect(()=>{const p=Zr(t);return p.setConnectionStateHandler((g,y)=>{d(g),u(y||null)}),f.current=p,n(p),p.connect().catch(g=>{g instanceof Tn||(u(g.message),d("error"))}),()=>{p.disconnect(),f.current=null,n(null),d("disconnected")}},[t]),e.jsx(cs,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[i&&a==="error"&&e.jsx("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm border-b",children:i}),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:c("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:c("session.connectionFailed")}),e.jsx("p",{className:"text-text-muted text-sm",children:i})]})}),s&&a==="connected"&&e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(En,{client:s,agentId:t})})]})})}export{va as SessionDetail};
|
|
74
|
+
\`\`\``})}else if(g.kind==="directory"){const y=g.files!=null?`${F("attach.directoryHeader",{name:g.name})} ${F("attach.fileCount",{n:g.files.length})}`:F("attach.directoryHeader",{name:g.name}),v=g.textContent||c("attach.emptyDirectory");u.push({type:"text",text:`${y}
|
|
75
|
+
${v}`})}}const f=u.length===1&&u[0].type==="text"?u[0].text||t:u.length>0?u:t;try{const g=oe();this.postedUserUuids.add(g);const y=await Zs(this.sessionId,{type:"user",uuid:g,content:t,message:{content:f}}),v=(p=y==null?void 0:y.event)==null?void 0:p.id;v&&this.setEntries(E=>E.map(C=>C.type==="user_message"&&C.id===i.id?{...C,id:v}:C))}catch(g){throw this.setEntries(y=>y.filter(v=>!(v.type==="user_message"&&v.id===i.id))),g}}async respondPermission(t,s,n){await G(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(i=>{var u;return i.type!=="tool_call"||((u=i.toolCall.permissionRequest)==null?void 0:u.requestId)!==t?i:{type:"tool_call",toolCall:{...i.toolCall,status:s?"running":"rejected",permissionRequest:void 0}}}))}async interrupt(){this.finalizePendingToolCalls("canceled"),await en(this.sessionId)}async setPermissionMode(t){const s=oe();return await G(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_permission_mode",mode:t}}),s}async controlRoundTrip(t,s=8e3){const n=oe(),a=new Promise(i=>{this.pendingControlRequests.set(n,i)}),d=setTimeout(()=>{const i=this.pendingControlRequests.get(n);i&&(this.pendingControlRequests.delete(n),i({data:null,error:"timeout"}))},s);try{return await G(this.sessionId,{type:"control_request",request_id:n,request:t}),await a}catch(i){throw this.pendingControlRequests.delete(n),i}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 G(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=oe();return await G(this.sessionId,{type:"control_request",request_id:s,request:{subtype:"set_effort",...t?{effort:t}:{effort:null}}}),s}async setThinkingBudget(t){const s=oe();return await G(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,i=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}:{},...i&&i.length>0?{categories:i}:{}}}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"?c("adapter.stopTimeout"):s.error}:{ok:!0}}catch{return{ok:!1,error:c("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 i=d;if(typeof i.name!="string"||!i.name)continue;const u=i.status;if(u!=="connected"&&u!=="failed"&&u!=="needs-auth"&&u!=="pending"&&u!=="disabled")continue;const f=i.serverInfo,p=i.config;n.push({name:i.name,status:u,...f&&typeof f.name=="string"&&typeof f.version=="string"?{serverInfo:{name:f.name,version:f.version}}:{},...typeof i.error=="string"&&i.error?{error:i.error}:{},...typeof(p==null?void 0:p.url)=="string"&&p.url?{url:p.url}:{},...Array.isArray(i.tools)?{toolCount:i.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"?c("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"?c("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,i=[];if(Array.isArray(d))for(const u of d){if(!u||typeof u!="object")continue;const f=u;typeof f.source=="string"&&i.push({source:f.source,settings:f.settings&&typeof f.settings=="object"&&!Array.isArray(f.settings)?f.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},effective:a,sources:i}}async applyFlagSettings(t){const s=await this.controlRoundTrip({subtype:"apply_flag_settings",settings:t},15e3);return s.error?{ok:!1,error:s.error==="timeout"?c("adapter.requestTimeout"):s.error}:{ok:!0}}async rewindToMessage(t){await tn(this.sessionId,t)}async endSession(t){await G(this.sessionId,{type:"control_request",request_id:oe(),request:{subtype:"end_session",...t?{reason:t}:{}}})}}function br(r){return r<1024?`${r} B`:r<1024*1024?`${(r/1024).toFixed(1)} KB`:`${(r/(1024*1024)).toFixed(1)} MB`}function Oe({onBack:r,title:t,meta:s,actions:n}){return X(),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":c("nav.dashboard"),title:c("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:c("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(nn,{}),e.jsx(rn,{onSettingsClick:()=>{window.history.pushState(null,"","/settings"),window.dispatchEvent(new PopStateEvent("popstate"))}})]})})}const Xt="rcs:subagent-panel:collapsed";function jr(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 wr(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 kr({status:r}){return r==="running"?e.jsx(_e,{className:"h-3 w-3 animate-spin text-brand-text"}):r==="completed"?e.jsx(or,{className:"h-3 w-3 text-status-success"}):r==="failed"||r==="stopped"?e.jsx(on,{className:"h-3 w-3 text-status-error"}):null}function ys({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=wr(r.tokenCount),i=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(kr,{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:jr(a)})]}),e.jsx("div",{className:`mt-0.5 text-text-secondary ${s?"line-clamp-2 break-words":"truncate"}`,children:u}),(d||i||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"]}),i&&e.jsxs("span",{className:"flex-shrink-0",children:["· ",i]}),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:c("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(an,{className:"h-3.5 w-3.5"})})]})}function vr({state:r,onStopTask:t}){const[s,n]=l.useState(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Xt)==="1"}catch{return!1}}),a=()=>{n(y=>{const v=!y;try{window.localStorage.setItem(Xt,v?"1":"0")}catch{}return v})},d=Object.values(r.tasks).some(y=>y.status==="running"),i=Object.values(r.tasks).some(y=>y.status!=="running"&&y.evictAfter!==void 0),[,u]=l.useState(0);l.useEffect(()=>{if(!d&&!i)return;const y=setInterval(()=>{u(v=>v+1)},1e3);return()=>clearInterval(y)},[d,i]);const f=gs(r);if(f.length===0)return null;const p=f.filter(y=>y.status==="running").length,g=p>0?`${p} running`:`${f.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(ms,{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:f.map(y=>e.jsx(ys,{task:y,onStopTask:t},y.taskId))})]})})}function Nr(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 _r(r){return r?Date.now()-r<6e4:!1}function Sr({onClose:r,session:t,liveStatus:s,pendingPermissions:n,onInterrupt:a,onDelete:d,subagentState:i,onStopTask:u,onEndSession:f}){const[p,g]=l.useState(!1),y=async()=>{await navigator.clipboard.writeText(t.id),g(!0),setTimeout(()=>g(!1),1500)},[v,E]=l.useState(!1),C=async()=>{if(!(!f||v)&&window.confirm(c("task.endConfirm"))){E(!0);try{await f(),r()}catch{E(!1)}}},j=n.length,m=t.worker,h=t.work_item,w=t.environment;return e.jsx(de,{open:!0,onOpenChange:T=>{T||r()},children:e.jsxs(ue,{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(me,{children:e.jsx(xe,{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(Dn,{className:"h-3.5 w-3.5"}),"Status"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ln,{status:s||t.status||"unknown"}),e.jsx("span",{className:"text-xs text-text-muted",children:m&&(_r(m.last_heartbeat_at)?"· worker online":"· worker offline")})]}),e.jsxs("dl",{className:"space-y-1 text-xs text-text-muted",children:[m&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(Dt,{className:"h-3 w-3"}),"Heartbeat"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:Nr(m.last_heartbeat_at)})]}),w&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(xs,{className:"h-3 w-3"}),"Environment"]}),e.jsx("dd",{className:"truncate text-text-secondary",children:w.machine_name||w.id})]}),t.created_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(Dt,{className:"h-3 w-3"}),"Created"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:ds(t.created_at)})]})]})]}),e.jsx(Er,{state:i,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(_e,{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(cr,{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"}),f&&e.jsx("button",{onClick:C,disabled:v,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:c("task.endHint"),children:v?"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(cn,{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(Jn,{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:y,className:"text-text-muted hover:text-text-primary transition-colors flex-shrink-0",title:"Copy session id",children:p?"✓":"⧉"})]})]}),h&&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:h.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:h.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})]}),w&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Worker type"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:w.worker_type})]})]})]})]})]})})}const Cr={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"},Tr=new Set(["dream"]);function Er({state:r,onStopTask:t}){const s=Object.values(r.tasks).some(f=>f.status==="running"),n=Object.values(r.tasks).some(f=>f.status!=="running"&&f.evictAfter!==void 0),[,a]=l.useState(0);l.useEffect(()=>{if(!s&&!n)return;const f=setInterval(()=>{a(p=>p+1)},1e3);return()=>clearInterval(f)},[s,n]);const d=gs(r),i=d.filter(f=>f.status==="running").length,u=d.length-i;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(tr,{className:"h-3.5 w-3.5"}),c("task.backgroundTasks")]}),d.length>0&&e.jsx("span",{className:"font-mono text-[10px] text-text-muted",children:i>0&&u>0?F("task.mixedCount",{running:i,recent:u}):i>0?F("task.runningCount",{count:i}):F("task.recentCount",{count:d.length})})]}),d.length===0?e.jsx("p",{className:"text-xs text-text-muted",children:c("task.noBackgroundTasks")}):e.jsx("div",{className:"max-h-[38vh] space-y-2 overflow-y-auto overscroll-contain pr-1",children:pr(d).map(f=>{const p=!Tr.has(f.taskType),g=Cr[f.taskType]??"task.type.tasks";return e.jsxs("div",{className:"space-y-1",children:[p&&e.jsxs("div",{className:"pl-1 text-[10px] font-medium uppercase tracking-wide text-text-muted/80",children:[c(g)," (",f.tasks.length,")"]}),f.tasks.map(y=>e.jsx(ys,{task:y,onStopTask:t,fullText:!0},y.taskId))]},f.taskType)})})]})}const Mr={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"},Rr={connected:"mcp.status.connected",failed:"mcp.status.failed","needs-auth":"mcp.status.needsAuth",pending:"mcp.status.pending",disabled:"mcp.status.disabled"};function Ar({onClose:r,fetchServers:t,onToggle:s,onReconnect:n}){X();const[a,d]=l.useState(null),[i,u]=l.useState(null),[f,p]=l.useState(null),[g,y]=l.useState(null),v=l.useCallback(async()=>{p(null),y(null);try{const j=await t();d(j),u(null)}catch(j){Fe("[McpPanel] fetch failed",j),u(c("mcp.loadFailed"))}},[t]);l.useEffect(()=>{v()},[v]);const E=async j=>{const m=j.status==="disabled";p(`toggle:${j.name}`),y(null);try{const h=await s(j.name,m);h.ok||y(h.error||c("mcp.toggleFailed"))}finally{await v()}},C=async j=>{p(`reconnect:${j.name}`),y(null);try{const m=await n(j.name);m.ok||y(m.error||c("mcp.reconnectFailed"))}finally{await v()}};return e.jsx(de,{open:!0,onOpenChange:j=>{j||r()},children:e.jsxs(ue,{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(me,{children:e.jsxs(xe,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(ps,{className:"h-4 w-4"}),c("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&&!i&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(_e,{className:"h-3.5 w-3.5 animate-spin"}),c("mcp.loading")]}),i&&e.jsx("p",{className:"text-xs text-status-error",children:i}),a!==null&&a.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:c("mcp.empty")}),a==null?void 0:a.map(j=>{const m=f===`toggle:${j.name}`,h=f===`reconnect:${j.name}`,w=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 ${Mr[j.status]}`,children:c(Rr[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&&` · ${F("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:h||w,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:c("mcp.reconnect"),children:e.jsx(Pn,{className:`h-3.5 w-3.5 ${h?"animate-spin":""}`})}),e.jsx("button",{type:"button",role:"switch","aria-checked":!w,onClick:()=>void E(j),disabled:m,className:`relative h-5 w-9 rounded-full transition-colors disabled:opacity-50 ${w?"bg-surface-3":"bg-brand"}`,title:w?c("mcp.enable"):c("mcp.disable"),children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${w?"left-0.5":"left-4.5"}`})})]})]})},j.name)})]})]})})}function Ir(r){if(r==null)return c("settings.unset");if(typeof r=="string")return r;try{return JSON.stringify(r)}catch{return String(r)}}function Zt(r){if(r==null)return c("settings.unset");if(typeof r=="object")try{return JSON.stringify(r,null,2)}catch{return String(r)}return String(r)}function $r({onClose:r,fetchSettings:t,onApply:s}){X();const[n,a]=l.useState(null),[d,i]=l.useState(null),[u,f]=l.useState(""),[p,g]=l.useState(null),[y,v]=l.useState(null),[E,C]=l.useState(null),[j,m]=l.useState(!1),h=l.useCallback(async()=>{g(null),v(null),C(null),m(!1);try{const S=await t();a(S),i(S?null:c("settings.loadFailed"))}catch(S){Fe("[SettingsDrawer] fetch failed",S),i(c("settings.loadFailed"))}},[t]);l.useEffect(()=>{h()},[h]);const w=l.useMemo(()=>n?Object.entries(n.effective).filter(([,S])=>S!==void 0).sort(([S],[P])=>S.localeCompare(P)):[],[n]),T=l.useMemo(()=>{const S=u.trim().toLowerCase();return S?w.filter(([P,L])=>`${P} ${Ir(L)}`.toLowerCase().includes(S)):w},[w,u]),k=S=>typeof S[1]=="boolean",b=l.useMemo(()=>T.filter(k),[T]),_=l.useMemo(()=>T.filter(S=>!k(S)),[T]),M=l.useMemo(()=>E===null?null:w.find(([S])=>S===E)??null,[w,E]),$=async()=>{if(M)try{await navigator.clipboard.writeText(Zt(M[1])),m(!0),window.setTimeout(()=>m(!1),1500)}catch(S){Fe("[SettingsDrawer] copy failed",S)}},K=async(S,P)=>{g(S),v(null);try{const L=await s({[S]:!P});L.ok||v(L.error||c("settings.writeFailed"))}finally{await h()}};return e.jsx(de,{open:!0,onOpenChange:S=>{S||r()},children:e.jsxs(ue,{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(me,{children:e.jsxs(xe,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(hs,{className:"h-4 w-4"}),c("session.settings.title")]})}),e.jsxs("div",{className:"mt-3 space-y-4 text-sm",children:[y&&e.jsx("div",{className:"rounded-md bg-status-error/10 px-3 py-2 text-xs text-status-error",children:y}),n===null&&!d&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(_e,{className:"h-3.5 w-3.5 animate-spin"}),c("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:c("settings.model")}),e.jsx("code",{className:"font-mono text-text-secondary",children:n.applied.model||c("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:c("settings.hint")})]}),M?e.jsxs("section",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>{C(null),m(!1)},className:"flex items-center gap-1.5 text-xs text-text-muted transition-colors hover:text-text-primary",children:[e.jsx(On,{className:"h-3.5 w-3.5"}),c("settings.back")]}),e.jsx("div",{className:"break-all font-mono text-xs font-medium text-text-primary",children:M[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:Zt(M[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(Se,{className:"h-3.5 w-3.5 text-status-success"}):e.jsx(Fn,{className:"h-3.5 w-3.5"}),j?c("settings.copied"):c("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(ct,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{value:u,onChange:S=>f(S.target.value),placeholder:c("settings.searchPlaceholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"})]}),T.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:c("settings.noMatch")}),b.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:F("settings.togglable",{n:b.length})}),b.map(([S,P])=>{const L=p===S;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:S}),e.jsx("button",{type:"button",role:"switch","aria-checked":P,disabled:L,onClick:()=>void K(S,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?c("settings.turnOff"):c("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"}`})})]},S)})]}),_.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:F("settings.readOnly",{n:_.length})}),_.map(([S])=>e.jsxs("button",{type:"button",onClick:()=>C(S),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:c("settings.viewDetail"),children:[e.jsx("span",{className:"truncate font-mono text-xs text-text-primary",children:S}),e.jsx(ms,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"})]},S))]})]})]})]})]})})}function Dr({onClose:r,onAsk:t}){X();const[s,n]=l.useState([]),[a,d]=l.useState(""),[i,u]=l.useState(!1),f=async()=>{const p=a.trim();if(!p||i)return;const g=Date.now();n(y=>[...y,{id:g,question:p,answer:null}]),d(""),u(!0);try{const y=await t(p);n(v=>v.map(E=>E.id===g?{...E,answer:y??c("sideQuestion.noAnswer"),error:y===null}:E))}finally{u(!1)}};return e.jsx(de,{open:!0,onOpenChange:p=>{p||r()},children:e.jsxs(ue,{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(me,{children:e.jsxs(xe,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(fs,{className:"h-4 w-4"}),c("sideQuestion.title")]})}),e.jsx("p",{className:"mt-1 text-[10px] leading-relaxed text-text-muted",children:c("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:c("sideQuestion.empty")}),s.map(p=>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:p.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:p.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:p.error?"text-status-error":"",children:e.jsx(dn,{children:p.answer})})})]})]},p.id))]}),e.jsxs("div",{className:"mt-3 flex items-end gap-2",children:[e.jsx("textarea",{value:a,onChange:p=>d(p.target.value),onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&!p.nativeEvent.isComposing&&(p.preventDefault(),f())},rows:Math.min(4,Math.max(1,a.split(`
|
|
76
|
+
`).length)),placeholder:c("sideQuestion.placeholder"),disabled:i,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 f(),disabled:i||!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:c("sideQuestion.send"),children:i?e.jsx(_e,{className:"h-4 w-4 animate-spin"}):e.jsx(un,{className:"h-4 w-4"})})]})]})})}const it="focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface-1";function es(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 qr({requestId:r,toolName:t,toolInput:s,description:n,suggestions:a,onApprove:d,onApproveAlways:i,onReject:u}){X();const f=s&&typeof s=="object"&&!Array.isArray(s)?s:{},p=mn(xn(t),f,{writeUnknownLabel:c("permission.writeUnknown")}),g=typeof s=="string"?s:JSON.stringify(s,null,2),y=Array.isArray(a)&&a.length>0;return e.jsxs("div",{role:"group","aria-label":F("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(fn,{className:"h-3 w-3"})}),e.jsx("span",{className:"text-sm font-semibold font-display text-approve-text",children:c("permission.title")})]}),n&&e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:V(n)}),e.jsx("div",{className:"mb-2 font-mono text-xs font-bold text-text-primary",children:V(t)}),t!=="AskUserQuestion"&&(p?e.jsx("div",{className:"mb-3 space-y-2",children:p.map((v,E)=>e.jsx(pn,{filePath:v.filePath,oldString:v.oldString,newString:v.newString,label:v.label},E))}):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:qt(g,500)})),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:d,className:te("rounded-lg bg-approve px-4 py-2 text-sm font-medium font-display text-white hover:bg-approve-hover transition-colors",it),children:c("permission.approve")}),y&&i&&e.jsxs("button",{onClick:i,className:te("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",it),title:c("permission.alwaysAllowHint").replace("{rule}",es(t,a)),children:[e.jsx(fr,{className:"h-3.5 w-3.5"}),c("permission.alwaysAllow")," ",qt(es(t,a),40)]}),e.jsx("button",{onClick:u,className:te("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",it),children:c("permission.reject")})]})]})}function Pr({questions:r,description:t,onSubmit:s,onSkip:n}){const[a,d]=l.useState({}),[i,u]=l.useState({}),[f,p]=l.useState(0),g=(C,j,m)=>{if(m){const h=a[C]||[],w=h.includes(j)?h.filter(T=>T!==j):[...h,j];d({...a,[C]:w})}else d({...a,[C]:j})},y=C=>{var m;const j=(m=i[C])==null?void 0:m.trim();j&&(d({...a,[C]:j}),u({...i,[C]:""}))},v=()=>{var j,m;const C={};for(const[h,w]of Object.entries(a)){const T=r[parseInt(h,10)];T&&(typeof w=="number"?C[h]=((m=(j=T.options)==null?void 0:j[w])==null?void 0:m.label)||String(w):Array.isArray(w)?C[h]=w.map(k=>{var b,_;return((_=(b=T.options)==null?void 0:b[k])==null?void 0:_.label)||String(k)}):C[h]=w)}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:V(t||C.question||"Question")}),e.jsxs("div",{className:"space-y-2",children:[(C.options||[]).map((m,h)=>{const w=j?(a[0]||[]).includes(h):a[0]===h;return e.jsxs("button",{onClick:()=>g(0,h,j),className:te("w-full rounded-lg border px-4 py-2.5 text-left text-sm font-display transition-colors",w?"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:V(m.label)}),m.description&&e.jsx("div",{className:"mt-0.5 text-xs font-sans text-text-muted",children:V(m.description)})]},h)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:i[0]||"",onChange:m=>u({...i,0:m.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:m=>m.key==="Enter"&&y(0)}),e.jsx("button",{onClick:()=>y(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:v,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 E=r[f];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:V(t||"Questions")}),e.jsx("div",{className:"mb-3 flex gap-1 overflow-x-auto",children:r.map((C,j)=>e.jsx("button",{onClick:()=>p(j),className:te("rounded-md px-3 py-1.5 text-xs font-display whitespace-nowrap transition-colors",f===j?"bg-brand/20 text-brand-text":"text-text-muted hover:bg-surface-2"),children:C.header||`Q${j+1}`},j))}),E&&e.jsx(Or,{question:E,qIdx:f,answers:a,otherTexts:i,onSelect:g,onOtherTextChange:(C,j)=>u({...i,[C]:j}),onOtherSubmit:y}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-display text-text-muted",children:[f+1," / ",r.length]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:v,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 Or({question:r,qIdx:t,answers:s,otherTexts:n,onSelect:a,onOtherTextChange:d,onOtherSubmit:i}){const u=r.multiSelect||!1;return e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:V(r.question)}),e.jsxs("div",{className:"space-y-2",children:[(r.options||[]).map((f,p)=>{const g=u?(s[t]||[]).includes(p):s[t]===p;return e.jsxs("button",{onClick:()=>a(t,p,u),className:te("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:V(f.label)}),f.description&&e.jsx("div",{className:"mt-0.5 text-xs font-sans text-text-muted",children:V(f.description)})]},p)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n[t]||"",onChange:f=>d(t,f.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:f=>f.key==="Enter"&&i(t)}),e.jsx("button",{onClick:()=>i(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 Ur({planContent:r,description:t,onSubmit:s}){const[n,a]=l.useState(null),[d,i]=l.useState(""),u=!r||!r.trim(),f=()=>{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(Se,{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:Fr(r)}}),e.jsx("div",{className:"space-y-2",children:u?e.jsxs(e.Fragment,{children:[e.jsx(Ne,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes"}),e.jsx(Ne,{selected:n==="no",onClick:()=>a("no"),label:"No"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ne,{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(Ne,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes, manually approve edits",desc:"Approve plan but confirm each edit"}),e.jsx(Ne,{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:p=>i(p.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:f,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 Ne({selected:r,onClick:t,label:s,desc:n}){return e.jsxs("button",{onClick:t,className:te("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:te("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 Fr(r){let t=V(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 Kr({request:r,onSubmit:t}){X();const s=Lr(r.requestedSchema),n=Br(r.requestedSchema),[a,d]=l.useState({}),i=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(ts,{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(Kn,{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:c("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:c("common.cancel")})]})]}):e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx(ts,{serverName:r.serverName,message:r.message}),s.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:s.map(({name:u,prop:f})=>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:c("elicitation.required")})]}),f.description&&e.jsx("div",{className:"mb-1 text-xs text-text-muted",children:V(f.description)}),e.jsx("input",{type:f.type==="number"?"number":"text",value:a[u]??"",onChange:p=>d(g=>({...g,[u]:p.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:f,prop:p}of s){const g=(a[f]??"").trim();g&&(u[f]=p.type==="number"?Number(g):g)}t("accept",u)},disabled:!i,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:c("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:c("elicitation.decline")})]})]})}function ts({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(rr,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-sm font-semibold text-text-primary",children:[c("elicitation.title")," ",e.jsx("span",{className:"font-mono text-xs text-text-muted",children:V(r)})]})]}),t&&e.jsx("div",{className:"text-sm text-text-secondary",children:V(t)})]})}function Lr(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 Br(r){const t=r==null?void 0:r.required;return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function Hr(r){const[t,s]=l.useState([]),[n,a]=l.useState(!0),[d,i]=l.useState(null),u=l.useCallback(async()=>{a(!0),i(null);try{const g=await hn(r);s(g)}catch(g){i(g instanceof Error?g.message:"Failed to load shares")}finally{a(!1)}},[r]);l.useEffect(()=>{u()},[u]);const f=l.useCallback(async g=>{i(null);try{const y=await gn(r,g);return await u(),y}catch(y){throw i(y instanceof Error?y.message:"Failed to create share"),y}},[r,u]),p=l.useCallback(async g=>{i(null);try{await yn(r,g),await u()}catch(y){throw i(y instanceof Error?y.message:"Failed to revoke share"),y}},[r,u]);return{shares:t,isLoading:n,error:d,createShare:f,revokeShare:p,refresh:u}}function Wr({open:r,onClose:t,sessionId:s,sessionTitle:n}){X();const{shares:a,isLoading:d,error:i,createShare:u,revokeShare:f}=Hr(s),[p,g]=l.useState("user"),[y,v]=l.useState(""),[E,C]=l.useState(""),[j,m]=l.useState("read"),[h,w]=l.useState(""),[T,k]=l.useState(!1),[b,_]=l.useState(null),[M,$]=l.useState(""),[K,S]=l.useState(!1),[P,L]=l.useState(!1);l.useEffect(()=>{r&&(g("user"),v(""),C(""),m("read"),w(""),k(!1),_(null),$(""),S(!1),L(!1))},[r]);const Ce=async()=>{k(!0),$(""),_(null);try{const D={grantedTo:p==="user"?{userId:y.trim()}:{teamId:E.trim()},permission:j};h.trim()&&(D.expiresAt=h.trim());const fe=await u(D);_(`${window.location.origin}/code/s/${fe.shareToken}`)}catch(D){$(D instanceof Error?D.message:"Failed to create share")}finally{k(!1)}},Te=async D=>{try{await f(D)}catch{}},J=async()=>{if(!b)return;L(!1);try{if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(b),S(!0),setTimeout(()=>S(!1),2e3);return}}catch{}const D=document.createElement("textarea");D.value=b,D.style.position="fixed",D.style.opacity="0",document.body.appendChild(D),D.select();try{document.execCommand("copy"),S(!0),setTimeout(()=>S(!1),2e3)}catch{L(!0)}document.body.removeChild(D)};return e.jsx(de,{open:r,onOpenChange:D=>{D||t()},children:e.jsxs(ue,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(me,{children:e.jsxs(xe,{className:"font-display text-lg font-semibold text-text-primary",children:[c("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:c("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 ${p==="user"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:c("share.user")}),e.jsx("button",{onClick:()=>g("team"),className:`rounded-md px-3 py-1 text-sm transition-colors ${p==="team"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:c("share.team")})]}),p==="user"?e.jsx(Un,{onSelect:v,placeholder:c("share.userIdPlaceholder"),actionLabel:c("share.selectUser")}):e.jsx("input",{type:"text",value:E,onChange:D=>C(D.target.value),placeholder:c("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"}),p==="user"&&y&&e.jsxs("p",{className:"mt-1 text-xs text-text-muted",children:[c("share.selectedUser"),": ",e.jsx("span",{className:"font-mono",children:y})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:c("share.permission")}),e.jsxs("select",{value:j,onChange:D=>m(D.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:c("share.permissionRead")}),e.jsx("option",{value:"write",children:c("share.permissionWrite")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:c("share.expiresAt")}),e.jsx("input",{type:"datetime-local",value:h,onChange:D=>w(D.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"})]}),(M||i)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:M||i}),b&&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:c("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:b}),e.jsx("button",{onClick:J,className:"shrink-0 rounded-md bg-brand px-2 py-1 text-xs text-white hover:bg-brand-light transition-colors",children:K?c("share.copied"):c("share.copy")})]}),P&&e.jsx("p",{className:"mt-1 text-xs text-status-error",children:c("share.copyFailed")})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"mb-2 text-sm font-medium text-text-secondary",children:c("share.existingShares")}),d?e.jsx("p",{className:"text-sm text-text-muted",children:c("share.loading")}):a.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:c("share.none")}):e.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto",children:a.map(D=>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:D.granted_to_user||D.granted_to_team||"Unknown"}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[D.permission==="write"?c("share.permissionWrite"):c("share.permissionRead"),D.expires_at?` · expires ${D.expires_at}`:""]})]}),e.jsx("button",{onClick:()=>Te(D.id),className:"shrink-0 rounded-md px-2 py-1 text-xs text-status-error hover:bg-surface-3 transition-colors",children:c("share.revoke")})]},D.id))})]})]}),e.jsxs(qn,{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:c("common.close")}),e.jsx("button",{onClick:Ce,disabled:T||(p==="user"?!y.trim():!E.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:T?c("common.creating"):c("share.createShare")})]})]})})}function Qr(r){const t=new Date,s=new Date(t.getTime()-1440*60*1e3),n=(i,u)=>i.getFullYear()===u.getFullYear()&&i.getMonth()===u.getMonth()&&i.getDate()===u.getDate(),a={today:[],yesterday:[],earlier:[]};for(const i of r){const u=new Date(i.modified||0);n(u,t)?a.today.push(i):n(u,s)?a.yesterday.push(i):a.earlier.push(i)}return[["today",c("resume.today")],["yesterday",c("resume.yesterday")],["earlier",c("resume.earlier")]].map(([i,u])=>({label:u,items:a[i]})).filter(i=>i.items.length>0)}function zr(r){return r?new Date(r).toLocaleString():""}function Vr({open:r,onClose:t,adapter:s,onResume:n}){const a=X(),[d,i]=l.useState([]),[u,f]=l.useState(!1),[p,g]=l.useState("");l.useEffect(()=>{if(!r)return;let v=!1;return f(!0),g(""),i([]),s.listResumableSessions().then(E=>{v||i(E)}).catch(E=>{v||g(E instanceof Error?E.message:String(E))}).finally(()=>{v||f(!1)}),()=>{v=!0}},[r,s]);const y=l.useMemo(()=>Qr(d),[d,a]);return e.jsx(de,{open:r,onOpenChange:v=>{v||t()},children:e.jsxs(ue,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(me,{children:e.jsx(xe,{className:"font-display text-lg font-semibold text-text-primary",children:c("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:c("resume.loading")}),!u&&p&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:p}),!u&&!p&&d.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-text-muted",children:c("resume.empty")}),!u&&!p&&y.map(v=>e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-xs font-medium text-text-muted",children:v.label}),e.jsx("div",{className:"space-y-1",children:v.items.map(E=>e.jsxs("button",{type:"button",onClick:()=>n(E),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:E.title}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[zr(E.modified),E.gitBranch?` · ${E.gitBranch}`:""]})]},E.sessionId))})]},v.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:c("common.cancel")})})]})})}class Gr{constructor(t,s,n,a){A(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,ss(n),"send")})}catch(n){this.rollback(s,ss(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 ss(r){return r instanceof Error?r.message:String(r)}function lt(r){const t=l.useRef(r);t.current=r;const s=l.useRef(null);s.current||(s.current=new Gr(r.value,a=>t.current.apply(a),a=>t.current.send(a),(a,d)=>{var i,u;return(u=(i=t.current).onError)==null?void 0:u.call(i,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 bs="rcs_context_usage_";function js(){try{if(typeof localStorage<"u")return localStorage}catch{}return null}function ns(){return{totalTokens:0,rawMaxTokens:0,percentage:0}}function Yr(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,i=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}:{},...i&&i.length>0?{categories:i}:{}}}function Jr(r,t=js()){if(!t||!r)return null;try{const s=t.getItem(bs+r);return s?Yr(JSON.parse(s)):null}catch{return null}}function Xr(r,t,s=js()){if(!(!s||!r))try{s.setItem(bs+r,JSON.stringify(t))}catch{}}function Zr(r){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/acp/relay/${r}`}function ea(r){const t=Zr(r),s=jn(),n=s?{proxyUrl:t,token:s}:{proxyUrl:t};return new bn(n)}const le=[{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"}],rs="rcs_permission_mode";function ce(r){return r<1e3?String(r):r<1e6?`${(r/1e3).toFixed(1)}k`:`${(r/1e6).toFixed(1)}M`}function ta(r){const t=le.findIndex(s=>s.value===r);return le[(t+1+le.length)%le.length].value}const Ke=[{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}],as="rcs_thinking_budget",ut=[{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?c(r.labelKey):r.label,is=r=>r.labelKey?c(r.labelKey):r.label,ls="rcs_effort";function sa(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,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,side_question:!1}}function na({budget:r,onBudgetChange:t,disabled:s}){const[n,a]=l.useState(!1),d=Ke.find(i=>i.value===r);return e.jsxs(Le,{open:n,onOpenChange:a,children:[e.jsx(Be,{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:c("session.thinking.title"),children:[e.jsx($n,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?is(d):c("session.thinking.fallback")}),n?e.jsx(He,{className:"h-3 w-3"}):e.jsx(We,{className:"h-3 w-3"})]})}),e.jsx(Qe,{className:"w-64 p-1",align:"start",children:Ke.map(i=>e.jsxs("button",{type:"button",onClick:()=>{t(i.value,i.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===i.value&&e.jsx(Se,{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:is(i)}),e.jsx("div",{className:"text-xs text-text-muted",children:i.descKey?c(i.descKey):i.description})]})]},i.value))})]})}function ra({effort:r,onEffortChange:t,disabled:s}){const[n,a]=l.useState(!1),d=ut.find(i=>i.value===r);return e.jsxs(Le,{open:n,onOpenChange:a,children:[e.jsx(Be,{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:c("session.effort.title"),children:[e.jsx(Gn,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?os(d):c("session.effort.fallback")}),n?e.jsx(He,{className:"h-3 w-3"}):e.jsx(We,{className:"h-3 w-3"})]})}),e.jsx(Qe,{className:"w-64 p-1",align:"start",children:ut.map(i=>e.jsxs("button",{type:"button",onClick:()=>{t(i.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===i.value&&e.jsx(Se,{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(i)}),e.jsx("div",{className:"text-xs text-text-muted",children:c(i.descKey)})]})]},i.value))})]})}const aa=new Set(["Free space","Autocompact buffer","Compact buffer"]),cs=["bg-brand","bg-status-active","bg-status-success","bg-violet-500","bg-amber-500","bg-pink-500","bg-teal-500"];function oa({usage:r}){const t=Math.min(100,Math.max(0,r.percentage)),s=t>=80,n=(r.categories??[]).filter(u=>!u.isDeferred&&!aa.has(u.name)),a=(r.categories??[]).filter(u=>u.isDeferred),d=n.reduce((u,f)=>u+f.tokens,0),i=[`${F("session.context.tooltip",{used:ce(r.totalTokens),max:ce(r.rawMaxTokens)})}${r.model?` · ${r.model}`:""}`,...n.slice(0,8).map(u=>`${u.name}: ${ce(u.tokens)}`),...a.slice(0,3).map(u=>`${u.name}${c("session.context.deferredSuffix")}: ${ce(u.tokens)}`)];return e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-text-muted font-mono",title:i.join(`
|
|
77
|
+
`),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,f)=>e.jsx("span",{className:s&&f===0?"bg-status-warning":cs[f%cs.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 ia({models:r,currentModelId:t,onSelect:s,disabled:n}){const[a,d]=l.useState(!1),i=r.find(p=>p.modelId===t)??null,u=r.length>0,f=async p=>{s(p.modelId),d(!1)};return e.jsxs(Le,{open:a,onOpenChange:u?d:void 0,children:[e.jsx(Be,{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:c("session.model.title"),children:[e.jsx(xs,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-32 truncate",children:(i==null?void 0:i.name)??t??c("session.model.title")}),a?e.jsx(He,{className:"h-3 w-3"}):e.jsx(We,{className:"h-3 w-3"})]})}),e.jsx(Qe,{className:"w-72 p-0",align:"start",children:e.jsx(In,{models:r,currentModelId:t,onSelect:f,showSearch:r.length>5})})]})}function la({mode:r,onModeChange:t,disabled:s}){const[n,a]=l.useState(!1),d=le.find(i=>i.value===r);return e.jsxs(Le,{open:n,onOpenChange:a,children:[e.jsx(Be,{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:c("session.mode.title"),children:[e.jsx(An,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?c(d.labelKey):r}),n?e.jsx(He,{className:"h-3 w-3"}):e.jsx(We,{className:"h-3 w-3"})]})}),e.jsx(Qe,{className:"w-64 p-1",align:"start",children:le.map(i=>e.jsxs("button",{type:"button",onClick:()=>{t(i.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===i.value&&e.jsx(Se,{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:c(i.labelKey)}),e.jsx("div",{className:"text-xs text-text-muted",children:c(i.descKey)})]})]},i.value))})]})}function Na({sessionId:r,onBack:t}){var At;X();const[s,n]=l.useState(null),[a,d]=l.useState(null),[i,u]=l.useState(""),[f,p]=l.useState(!1),[g,y]=l.useState(!1),[v,E]=l.useState(!1),[C,j]=l.useState(!1),[m,h]=l.useState(!1),[w,T]=l.useState(!1),[k,b]=l.useState(""),[_,M]=l.useState(0),$=l.useRef(null),[K,S]=l.useState({text:"",nonce:0}),[P,L]=l.useState(!1),[Ce,Te]=l.useState(!1),[J,D]=l.useState(!1),[fe,mt]=l.useState(0),[ws,ks]=l.useState(0),[pe,Z]=l.useState([]),[Y,he]=l.useState(!1),[ge,ae]=l.useState([]),[z,ze]=l.useState(null),[xt,vs]=l.useState(()=>dt()),[W,Ns]=l.useState(null),[Ee,_s]=l.useState(()=>localStorage.getItem(as)||"off"),[Ss,ft]=l.useState(()=>Jr(r)),[Ve,Ge]=l.useState(!0),[ye,Cs]=l.useState(null),[Me,pt]=l.useState(null),[Re,Ae]=l.useState([]),[Ts,Ye]=l.useState(!1),[Je,ht]=l.useState(""),Xe=l.useRef(null),[Ie,Es]=l.useState(()=>localStorage.getItem(rs)||"default"),[gt,yt]=l.useState(null),be=l.useRef(null),[bt,jt]=l.useState(null),je=l.useRef(null),se=l.useRef(null),wt=l.useRef(pe);wt.current=pe;const $e=l.useRef(null);$e.current||($e.current=new Hn(Wn()));const kt=l.useRef(r);kt.current=(s==null?void 0:s.title)||r,l.useEffect(()=>{var o;(o=$e.current)==null||o.reset()},[r]);const ne=l.useCallback(o=>{yt(o),be.current&&clearTimeout(be.current),be.current=setTimeout(()=>yt(null),5e3)},[]),ee=l.useCallback(o=>{jt(o),je.current&&clearTimeout(je.current),je.current=setTimeout(()=>jt(null),5e3)},[]),De=lt({value:Ie,apply:o=>{Es(o);try{localStorage.setItem(rs,o)}catch{}},send:o=>{const x=se.current;return x?x.setPermissionMode(o):Promise.reject(new Error("adapter not ready"))},onError:(o,x)=>{console.error("[SessionDetail] set permission mode failed:",o),ne(x==="send"?F("session.mode.switchFailedRequest",{message:o}):o||c("session.mode.switchFailed"))}}),Ze=l.useCallback(o=>De.set(o),[De]),et=lt({value:Ee,apply:o=>{_s(o);try{localStorage.setItem(as,o)}catch{}},send:o=>{var R;const x=se.current;if(!x)return Promise.reject(new Error("adapter not ready"));const N=((R=Ke.find(I=>I.value===o))==null?void 0:R.tokens)??null;return x.setThinkingBudget(N)},onError:(o,x)=>{console.error("[SessionDetail] set thinking budget failed:",o),ne(x==="send"?F("session.thinking.failedRequest",{message:o}):o||c("session.thinking.failed"))}}),q=l.useMemo(()=>new yr(r,Z,{onStatusChange:o=>{var x;d(o),he(o==="running"||o==="requires_action"),(x=$e.current)==null||x.onStatus(o,kt.current)},onError:o=>{console.error("[RCSChatAdapter] error:",o)},onPermissionRequest:o=>{ae(x=>x.some(N=>N.requestId===o.requestId)?x:[...x,o])},onModelsStateChange:o=>{ze(o)},onSubagentUpdate:o=>{vs(o)},onControlResponse:o=>{et.handleControlResponse(o)||De.handleControlResponse(o)},onPermissionModeChange:o=>{De.sync(o)},onUsageChange:o=>{Cs(x=>({inputTokens:Math.max((x==null?void 0:x.inputTokens)??0,o.inputTokens),outputTokens:Math.max((x==null?void 0:x.outputTokens)??0,o.outputTokens),totalCostUsd:o.totalCostUsd??(x==null?void 0:x.totalCostUsd)??null}))},onWorkerInfoChange:o=>{Ns(x=>JSON.stringify(x)===JSON.stringify(o)?x:o)},onElicitationRequest:o=>{pt(o)}}),[r,ne]);l.useEffect(()=>(se.current=q,()=>{q.disconnect()}),[q]);const U=l.useMemo(()=>sa(W),[W]),vt=l.useRef(!1);l.useEffect(()=>{var N;if(!U.set_max_thinking_tokens||vt.current)return;const o=se.current;if(!o)return;const x=((N=Ke.find(R=>R.value===Ee))==null?void 0:N.tokens)??null;o.setThinkingBudget(x).then(()=>{vt.current=!0}).catch(R=>console.error("[SessionDetail] reconcile thinking budget failed:",R))},[U.set_max_thinking_tokens,Ee,W]);const Nt=U.stop_task?o=>{q.stopSubagent(o).then(x=>{x.ok||ee(x.error||c("session.stopTask.failed"))})}:void 0,Ms=X(),tt=l.useMemo(()=>wn((W==null?void 0:W.commands)??[],(W==null?void 0:W.skills)??[]),[W,Ms]),we=l.useMemo(()=>kn(pe,k),[pe,k]),Rs=l.useCallback(o=>et.set(o),[et]),[_t,As]=l.useState(()=>localStorage.getItem(ls)||"auto"),Is=lt({value:_t,apply:o=>{As(o);try{localStorage.setItem(ls,o)}catch{}},send:o=>{var R;const x=se.current;if(!x)return Promise.reject(new Error("adapter not ready"));const N=(R=ut.find(I=>I.value===o))==null?void 0:R.effort;return x.setEffort(N)},onError:(o,x)=>{console.error("[SessionDetail] set effort failed:",o),ne(x==="send"?F("session.effort.failedRequest",{message:o}):o||c("session.effort.failed"))}}),st=l.useCallback(()=>{var o;U.get_context_usage&&((o=se.current)==null||o.getContextUsage().then(x=>{x&&(ft(x),Xr(r,x))}).catch(()=>{}).finally(()=>Ge(!1)))},[U,r]);l.useEffect(()=>{if(!U.get_context_usage)return;Y||st();const o=setInterval(st,6e4);return()=>clearInterval(o)},[U,Y,st]),l.useEffect(()=>{W&&!U.get_context_usage&&Ge(!1)},[W,U]),l.useEffect(()=>{if(!Ve)return;const o=setTimeout(()=>Ge(!1),1e4);return()=>clearTimeout(o)},[Ve]);const St=l.useRef(J);St.current=J,l.useEffect(()=>ie.onEvent(x=>{x.type!=="artifact_created"&&x.type!=="artifact_updated"||(St.current&&ks(N=>N+1),mt(N=>N+1))}),[]);const[ke,$s]=l.useState("idle");l.useEffect(()=>ie.onStateChange(x=>$s(x)),[]),l.useEffect(()=>{J&&mt(0)},[J]),l.useEffect(()=>{let o=!1;async function x(){u("");try{const N=await Ut(r);if(o)return;n(N),d(N.status),Ue(N.status)&&q.markClosed(),he(N.status==="running"||N.status==="requires_action")}catch(N){if(o)return;u(N instanceof Error?N.message:c("session.loadFailed"));return}try{await q.init()}catch(N){console.warn("Failed to init adapter:",N)}}return x(),()=>{o=!0}},[r,q]);const O=Ue(a),Ct=l.useRef(a);Ct.current=a,l.useEffect(()=>{if(O)return;let o=!1;const N=setInterval(async()=>{try{const R=await Ut(r);if(o||R.status===Ct.current)return;Ue(R.status)&&q.markClosed(),d(R.status),he(R.status==="running"||R.status==="requires_action")}catch{}},6e4);return()=>{o=!0,clearInterval(N)}},[r,O,q]);const B=(s==null?void 0:s.access_level)==="read",Tt=Ss??(Ve&&!O&&!B?ns():null),nt=l.useCallback(()=>{Z([]),ft(ns()),Pt(r).catch(o=>{console.warn("[SessionDetail] Failed to clear session history:",o)})},[r]),ve=l.useCallback(async(o,x)=>{const N=se.current;if(!N||O)return;if(o.sessionId===r){Z(I=>[...I,{type:"command_output",id:`cmd-resume-${Date.now()}`,commandName:"resume",inputText:x??"/resume",title:"Resume",subtitle:c("session.resume.title"),outputText:c("session.resume.currentBlocked"),variant:"error"}]);return}const R=(I,H="default")=>Z(re=>[...re,{type:"command_output",id:`cmd-resume-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,commandName:"resume",inputText:x??`/resume ${o.sessionId.slice(0,8)}`,title:"Resume",subtitle:c("session.resume.title"),outputText:I,variant:H}]);R(F("session.resume.restoring",{title:o.title??""}));try{await Pt(r),Z([]);const I=await N.resumeSession(o.sessionId);R(I.title?F("session.resume.restoredWithTitle",{count:I.messageCount,title:I.title}):F("session.resume.restored",{count:I.messageCount}))}catch(I){R(F("session.resume.failed",{message:I instanceof Error?I.message:String(I)}),"error")}},[O,r]),Ds=l.useCallback(async()=>{if(s!=null&&s.environment_id)try{const o=await vn({environment_id:s.environment_id});window.location.href=`/code/${o.id}?resumeFrom=${r}`}catch(o){ee(F("session.createFailedWithReason",{message:o instanceof Error?o.message:String(o)}))}},[s,r,ee]),qs=l.useRef(new URLSearchParams(window.location.search).get("resumeFrom")),Et=l.useRef(!1);l.useEffect(()=>{const o=qs.current;!o||Et.current||!W||!U.resume||(Et.current=!0,window.history.replaceState({},"",window.location.pathname),ve({sessionId:o,title:o.slice(0,8),modified:0},null))},[W,U.resume,ve]);const qe=l.useCallback(async o=>{const x=o.text.trim(),N=o.images&&o.images.length>0||o.attachments&&o.attachments.length>0;if(!x&&!N||O)return;const R=/^\/resume(?:\s+(.*))?$/.exec(x);if(R){const H=(R[1]??"").trim();if(!U.resume){Z(re=>[...re,{type:"user_message",id:`user-${Date.now()}`,content:x},{type:"command_output",id:`cmd-${Date.now()}`,commandName:"resume",inputText:x,title:"Resume",subtitle:c("session.resume.title"),outputText:c("session.resume.unsupported"),variant:"error"}]);return}H?await ve({sessionId:H,title:H,modified:0},x):h(!0);return}const I=await Nn(x,{sessionId:r,availableCommands:tt,availableModels:(z==null?void 0:z.availableModels)??[],currentModel:z?{modelId:z.currentModelId,name:z.currentModelId}:null,supportsImages:!0,entries:wt.current,setModel:async H=>{await G(r,{type:"control_request",request:{subtype:"set_model",model:H}}),ze(re=>re&&{...re,currentModelId:H})},onNewSession:()=>{Z([])}}).catch(()=>null);if(I){if(Fe("[SessionDetail] local command result",I),"clearEntries"in I&&I.clearEntries){nt();return}if("newSession"in I&&I.newSession){nt();return}if("userEntry"in I){Z(H=>[...H,I.userEntry,I.cmdEntry]);return}}he(!0);try{await q.sendMessage(x,o.images,o.attachments)}catch(H){if(console.error("Send failed:",H),H instanceof _n&&H.type==="session_closed"){d("archived"),q.markClosed(),ee(c("session.closedSendBlocked"));return}ee(`${c("session.sendFailed")}${H instanceof Error?`: ${H.message}`:""}`)}},[q,O,r,z,tt,nt,ee,ve,U]),Ps=l.useCallback(o=>{if(Y){Ae(x=>[...x,o]);return}qe(o)},[Y,qe]),rt=l.useRef(!1);l.useEffect(()=>{if(O){Ae(x=>x.length>0?[]:x);return}if(Y||Re.length===0||rt.current)return;const o=Re[0];o&&(rt.current=!0,Ae(x=>x.slice(1)),qe(o).finally(()=>{rt.current=!1}))},[Y,Re,qe,O]);const Os=l.useCallback((o,x)=>{if(Y)return;const N=x==="edit"?c("session.rewind.confirmEdit"):c("session.rewind.confirm");window.confirm(`${N}
|
|
78
|
+
${c("session.rewind.confirmBody")}`)&&q.rewindToMessage(o.id).then(()=>{x==="edit"&&o.content&&S(R=>({text:o.content,nonce:R.nonce+1}))}).catch(R=>{console.error("[SessionDetail] rewind failed:",R),ee(F("session.rewind.failed",{message:R instanceof Error?R.message:String(R)}))})},[Y,ee]),Us=l.useCallback(o=>{const x=we.orderedMatchIds;if(x.length===0)return;const N=(o%x.length+x.length)%x.length;M(N);const R=x[N],I=document.querySelector(`[data-entry-id="${CSS.escape(R)}"]`);I==null||I.scrollIntoView({block:"center",behavior:"smooth"})},[we]),Mt=l.useCallback(async()=>{try{await q.interrupt()}catch(o){console.error("Interrupt failed:",o)}finally{he(!1)}},[q]),Fs=l.useCallback(()=>{Ze(ta(Ie))},[Ze,Ie]);l.useEffect(()=>()=>{be.current&&clearTimeout(be.current),je.current&&clearTimeout(je.current)},[]);const Ks=l.useCallback(async()=>{if(s&&window.confirm(c("dashboard.confirmDelete").replace("{id}",s.title||s.id)))try{await Ot(s.id),window.location.href="/code/"}catch(o){alert(o instanceof Error?o.message:c("dashboard.deleteFailed"))}},[s]),Ls=l.useCallback(async o=>{try{await q.respondPermission(o,!0)}catch(x){console.error("Failed to approve:",x)}ae(x=>x.filter(N=>N.requestId!==o))},[q]),Bs=l.useCallback(async(o,x)=>{try{await q.respondPermission(o,!0,{updated_permissions:x})}catch(N){console.error("Failed to approve with rules:",N)}ae(N=>N.filter(R=>R.requestId!==o))},[q]),Hs=l.useCallback(async(o,x)=>{const N=Me;if(pt(null),!!N)try{await q.respondElicitation(N.requestId,o,x)}catch(R){console.error("Failed to submit elicitation:",R)}},[Me,q]),Ws=l.useCallback(()=>{!s||B||(ht(s.title||""),Ye(!0),setTimeout(()=>{var o,x;(o=Xe.current)==null||o.focus(),(x=Xe.current)==null||x.select()},0))},[s,B]),Rt=l.useCallback(async()=>{const o=Je.trim();if(Ye(!1),!(!s||!o||o===s.title))try{const x=await Sn(s.id,o);n(N=>N&&{...N,title:x.title??o})}catch(x){console.error("Rename failed:",x),alert(x instanceof Error?x.message:c("session.rename.failed"))}},[s,Je]),Qs=l.useCallback(async o=>{try{await q.respondPermission(o,!1)}catch(x){console.error("Failed to reject:",x)}ae(x=>x.filter(N=>N.requestId!==o))},[q]),zs=l.useCallback(async(o,x,N)=>{try{await G(r,{type:"permission_response",approved:!0,request_id:o,updated_input:{questions:N,answers:x}})}catch(R){console.error("Failed to submit answers:",R)}ae(R=>R.filter(I=>I.requestId!==o))},[r]),Vs=l.useCallback(async(o,x,N)=>{try{x==="no"?await G(r,{type:"permission_response",approved:!1,request_id:o,...N?{message:N}:{}}):await G(r,{type:"permission_response",approved:!0,request_id:o,updated_permissions:[{type:"setMode",mode:{"yes-accept-edits":"acceptEdits","yes-default":"default"}[x]||"default",destination:"session"}]})}catch(R){console.error("Failed to submit plan response:",R)}ae(R=>R.filter(I=>I.requestId!==o))},[r]);return i?e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(Oe,{onBack:t,title:e.jsx("span",{className:"text-xs font-medium text-text-muted",children:c("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:i}),e.jsx("a",{href:"/code/",className:"mt-4 inline-block text-brand-text hover:underline",children:c("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(Oe,{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(da,{sessionId:r,agentId:s.environment_id})]}):e.jsx(us,{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(Oe,{onBack:t,title:Ts?e.jsx("input",{ref:Xe,value:Je,onChange:o=>ht(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),Rt()):o.key==="Escape"&&(o.preventDefault(),Ye(!1))},onBlur:()=>void Rt(),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:!B&&!O?e.jsx("button",{type:"button",onClick:Ws,title:c("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(Bn,{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,x=Ft(o);return e.jsx("span",{className:`hidden items-center rounded-full px-2 py-0.5 text-[10px] font-medium sm:inline-flex ${x.colorClass}`,children:x.fullLabel})})()}),actions:e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsxs("button",{onClick:()=>D(!J),className:`relative flex h-7 w-7 items-center justify-center rounded-md transition-colors ${J?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:c("artifacts.title"),children:[e.jsx(Cn,{className:"h-3.5 w-3.5"}),fe>0&&!J&&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:fe>9?"9+":fe})]}),U.side_question&&!O&&!B&&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:c("session.sideQuestion.title"),children:e.jsx(fs,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>{const o=!w;T(o),o?setTimeout(()=>{var x;return(x=$.current)==null?void 0:x.focus()},0):(b(""),M(0))},className:`flex h-7 w-7 items-center justify-center rounded-md transition-colors ${w?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:c("session.search.title"),children:e.jsx(ct,{className:"h-3.5 w-3.5"})}),U.mcp_management&&!O&&!B&&e.jsx("button",{onClick:()=>y(!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:c("session.mcp.title"),children:e.jsx(ps,{className:"h-3.5 w-3.5"})}),U.remote_settings&&!O&&!B&&e.jsx("button",{onClick:()=>E(!v),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${v?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:c("session.settings.title"),children:e.jsx(hs,{className:"h-3.5 w-3.5"})}),!B&&(s==null?void 0:s.access_level)!=="write"&&e.jsx("button",{onClick:()=>Te(!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:c("session.share"),children:e.jsx(mr,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>L(!P),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:c("session.info"),children:e.jsx(Zn,{className:"h-3.5 w-3.5"})}),e.jsxs("button",{onClick:()=>p(!f),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:[c("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})]})]})})}),P&&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:c("session.metaSession")})," ",s.id]}),s.environment_id&&e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:c("session.metaEnvironment")})," ",s.environment_id]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:c("session.metaStatus")})," ",a]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:c("session.metaWorker")})," ",Ft(s.source==="acp"?"acp":(At=s.environment)==null?void 0:At.worker_type).fullLabel]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:c("session.metaCreated")})," ",ds(s.created_at)]})]})})}),(ke==="reconnecting"||ke==="failed")&&e.jsxs("div",{className:`flex items-center justify-center gap-2 px-4 py-1.5 text-xs font-medium ${ke==="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 ${ke==="failed"?"bg-status-error":"animate-pulse bg-status-warning"}`}),ke==="failed"?c("session.sseFailed"):c("session.sseReconnecting")]}),J&&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(Ln,{sessionId:r,embedded:!0,refreshTick:ws})})}),w&&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(ct,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{ref:$,value:k,onChange:o=>{b(o.target.value),M(0)},onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),Us(k&&o.shiftKey?_-1:_+1)):o.key==="Escape"&&(o.preventDefault(),T(!1),b(""))},placeholder:c("session.search.placeholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"}),k.trim()&&e.jsx("span",{className:"flex-shrink-0 font-mono text-[10px] text-text-muted",children:we.orderedMatchIds.length===0?c("session.search.noResults"):`${_+1}/${we.orderedMatchIds.length}`})]})}),e.jsx(Tn,{entries:pe,isLoading:Y,emptyTitle:c("session.emptyTitle"),emptyDescription:c("session.emptyDescription"),searchMatchIds:k.trim()?we.matchIds:void 0,onRewindEntry:U.rewind&&!O&&!B&&!Y?(o,x)=>Os(o,x):void 0}),e.jsx(vr,{state:xt,onStopTask:Nt}),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(ca,{request:o,onApprove:()=>Ls(o.requestId),onApproveAlways:o.suggestions&&o.suggestions.length>0?()=>Bs(o.requestId,o.suggestions??[]):void 0,onReject:()=>Qs(o.requestId),onSubmitAnswers:zs,onSubmitPlan:Vs},o.requestId))})}),Me&&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(Kr,{request:Me,onSubmit:Hs})})}),bt&&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:bt})}),gt&&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:gt})}),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(la,{mode:Ie,onModeChange:Ze,disabled:O||B}),e.jsx(ia,{models:(z==null?void 0:z.availableModels)??[],currentModelId:(z==null?void 0:z.currentModelId)??null,onSelect:o=>{G(r,{type:"control_request",request:{subtype:"set_model",model:o}}),ze(x=>x&&{...x,currentModelId:o})},disabled:O||B}),U.set_max_thinking_tokens&&e.jsx(na,{budget:Ee,onBudgetChange:Rs,disabled:O||B}),U.set_effort&&e.jsx(ra,{effort:_t,onEffortChange:o=>Is.set(o),disabled:O||B})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[Tt&&e.jsx(oa,{usage:Tt}),ye&&e.jsxs("span",{className:"text-[10px] text-text-muted font-mono",title:c("session.usage.total"),children:[ce(ye.inputTokens)," in / ",ce(ye.outputTokens)," out",ye.totalCostUsd!=null&&` · $${ye.totalCostUsd.toFixed(2)}`]})]})]}),O&&(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 Ds(),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:c("session.resumeInNew")})}),e.jsx(En,{onSubmit:Ps,isLoading:Y,onInterrupt:Mt,onCycleMode:Fs,disabled:O||B,placeholder:O?c("session.closed"):B?c("session.readOnly"):c("session.inputPlaceholder"),supportsAttachments:!0,commands:tt,queueWhileLoading:!0,queuedCount:Re.length,onDequeue:o=>Ae(x=>x.filter((N,R)=>R!==o)),onSearchFiles:U.file_search?o=>q.searchFiles(o):void 0,historyKey:r,draftOverride:K}),g&&e.jsx(Ar,{onClose:()=>y(!1),fetchServers:()=>q.getMcpServers(),onToggle:(o,x)=>q.toggleMcpServer(o,x),onReconnect:o=>q.reconnectMcpServer(o)}),v&&e.jsx($r,{onClose:()=>E(!1),fetchSettings:()=>q.getRemoteSettings(),onApply:o=>q.applyFlagSettings(o)}),C&&e.jsx(Dr,{onClose:()=>j(!1),onAsk:o=>q.askSideQuestion(o)}),f&&s&&e.jsx(Sr,{onClose:()=>p(!1),session:s,liveStatus:a,pendingPermissions:ge,subagentState:xt,onStopTask:Nt,onInterrupt:Mt,onDelete:Ks,onEndSession:U.end_session&&!O&&!B?async()=>{await q.endSession("ended from web"),await Ot(s.id),window.location.href="/code/"}:void 0}),e.jsx(Wr,{open:Ce,onClose:()=>Te(!1),sessionId:s.id,sessionTitle:s.title||void 0}),e.jsx(Vr,{open:m,onClose:()=>h(!1),adapter:q,onResume:o=>{h(!1),ve(o,null)}})]})}):e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(Oe,{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:c("session.loading")})})]})}function ca({request:r,onApprove:t,onApproveAlways:s,onReject:n,onSubmitAnswers:a,onSubmitPlan:d}){const i=r.toolName,u=r.toolInput,f=r.description||"";if(i==="AskUserQuestion"){const p=u.questions||[];return e.jsx(Pr,{requestId:r.requestId,questions:p,description:f,onSubmit:g=>a(r.requestId,g,p),onSkip:n})}if(i==="ExitPlanMode"){const p=u.plan||"";return e.jsx(Ur,{requestId:r.requestId,planContent:p,description:f,onSubmit:(g,y)=>d(r.requestId,g,y)})}return e.jsx(qr,{requestId:r.requestId,toolName:i,toolInput:u,description:f,suggestions:r.suggestions,onApprove:t,onApproveAlways:s,onReject:n})}function da({sessionId:r,agentId:t}){const[s,n]=l.useState(null),[a,d]=l.useState("disconnected"),[i,u]=l.useState(null),f=l.useRef(null);return l.useEffect(()=>{const p=ea(t);return p.setConnectionStateHandler((g,y)=>{d(g),u(y||null)}),f.current=p,n(p),p.connect().catch(g=>{g instanceof Mn||(u(g.message),d("error"))}),()=>{p.disconnect(),f.current=null,n(null),d("disconnected")}},[t]),e.jsx(us,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[i&&a==="error"&&e.jsx("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm border-b",children:i}),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:c("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:c("session.connectionFailed")}),e.jsx("p",{className:"text-text-muted text-sm",children:i})]})}),s&&a==="connected"&&e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Rn,{client:s,agentId:t})})]})})}export{Na as SessionDetail};
|