@saluzi/saluzi-edu 0.7.4 → 0.7.5
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 +91 -59
- package/dist/rcs-schema.sql +42 -0
- package/dist/rcs-web/assets/{AdminPanel-B9YWaqlO.js → AdminPanel-QjFUzKR-.js} +1 -1
- package/dist/rcs-web/assets/{ArtifactView-B8lAeS5B.js → ArtifactView-DSrHrqoO.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/ArtifactsGallery-CNd9-Awp.js → dist/rcs-web/assets/ArtifactsGallery-LD7hnmXQ.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/Claim-Dq08pl4W.js → dist/rcs-web/assets/Claim-rralKUvn.js} +1 -1
- package/dist/rcs-web/assets/{Dashboard-JZcrtByh.js → Dashboard-BhXzF4TR.js} +2 -2
- package/dist/rcs-web/assets/{Join-DgvRnpyb.js → Join-DYKrYQka.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/Login-CZbz6Wms.js → dist/rcs-web/assets/Login-Blmtx4In.js} +1 -1
- package/dist/rcs-web/assets/MemoriesGallery-CWyitPTS.js +1 -0
- package/dist/rcs-web/assets/{Register-DD7uiwEj.js → Register-CnZOK0Wa.js} +1 -1
- package/dist/rcs-web/assets/{RegisterEmpty-BrBfeQXp.js → RegisterEmpty-RNN7njqd.js} +2 -2
- package/dist/rcs-web/assets/{SessionDetail-BbnQBjP1.js → SessionDetail-BeZeeaGH.js} +19 -19
- package/dist/rcs-web/assets/{SessionVisibilityBadge-kSo9esvT.js → SessionVisibilityBadge-D976F6JX.js} +2 -2
- package/dist/rcs-web/assets/{Setup-Ca30VUSF.js → Setup-BFW58zKK.js} +1 -1
- package/dist/rcs-web/assets/{ShareLanding-C_vlxFAM.js → ShareLanding-BTLCFUy8.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/TeamDetail-8T_kKUcX.js → dist/rcs-web/assets/TeamDetail-DwZoGkMp.js} +2 -2
- package/dist/rcs-web/assets/{TeamList-DRXGQCJi.js → TeamList-DehdjKJu.js} +1 -1
- package/dist/rcs-web/assets/{TeamSettings-Byhon5C1.js → TeamSettings-DsZDvdLi.js} +1 -1
- package/dist/rcs-web/assets/{UserSearchInput-wixyd_8w.js → UserSearchInput-B-phMzno.js} +2 -2
- package/dist/rcs-web/assets/{UserSettings-Ds2retFk.js → UserSettings-po8VpRyO.js} +1 -1
- package/dist/rcs-web/assets/{arc-CThS8KNL.js → arc-yo8UpUoc.js} +1 -1
- package/dist/rcs-web/assets/{architectureDiagram-3BPJPVTR-Bko99SuX.js → architectureDiagram-3BPJPVTR-CAzjNMmM.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/blockDiagram-GPEHLZMM-CqCAgp0i.js → dist/rcs-web/assets/blockDiagram-GPEHLZMM-DRvlErcg.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/c4Diagram-AAUBKEIU-C1pGDG-L.js → dist/rcs-web/assets/c4Diagram-AAUBKEIU-CtqgfHXS.js} +1 -1
- package/dist/rcs-web/assets/channel-ByZbiIGl.js +1 -0
- package/dist/rcs-web/assets/{chunk-2J33WTMH-Bz0kJwEY.js → chunk-2J33WTMH-BnLSiOZc.js} +1 -1
- package/dist/rcs-web/assets/{chunk-4BX2VUAB-DYnlidI7.js → chunk-4BX2VUAB-CneZL39T.js} +1 -1
- package/dist/rcs-web/assets/{chunk-55IACEB6-cMV4HRvm.js → chunk-55IACEB6-AZPro6N3.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/chunk-727SXJPM-Bgz9JRYO.js → dist/rcs-web/assets/chunk-727SXJPM-DtoifF_Q.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/chunk-AQP2D5EJ-DIFGJlEF.js → dist/rcs-web/assets/chunk-AQP2D5EJ-BsdfbS-v.js} +1 -1
- package/dist/rcs-web/assets/{chunk-FMBD7UC4-BUC7O7T0.js → chunk-FMBD7UC4-Ba_h1XJS.js} +1 -1
- package/dist/rcs-web/assets/{chunk-ND2GUHAM-kGqgVnBZ.js → chunk-ND2GUHAM-CtZuWp5S.js} +1 -1
- package/dist/rcs-web/assets/{chunk-QZHKN3VN-B01O0qXh.js → chunk-QZHKN3VN-DF-7EztA.js} +1 -1
- package/dist/rcs-web/assets/classDiagram-4FO5ZUOK-B7LKcjGg.js +1 -0
- package/dist/rcs-web/assets/classDiagram-v2-Q7XG4LA2-B7LKcjGg.js +1 -0
- package/dist/rcs-web/assets/{code-block-IT6T5CEO-CscK0pCh.js → code-block-IT6T5CEO-BB5vH41t.js} +1 -1
- package/dist/rcs-web/assets/{copy-CvmA5P_Q.js → copy-COu9cGeU.js} +1 -1
- package/dist/rcs-web/assets/{cose-bilkent-S5V4N54A-BsBsVccW.js → cose-bilkent-S5V4N54A-BvX9PMEk.js} +1 -1
- package/dist/rcs-web/assets/{dagre-BM42HDAG-Bn4B33S-.js → dagre-BM42HDAG-BsbASaLl.js} +1 -1
- package/dist/rcs-web/assets/{diagram-2AECGRRQ-DAuAIPR6.js → diagram-2AECGRRQ-zjhhcSia.js} +1 -1
- package/dist/rcs-web/assets/{diagram-5GNKFQAL-w3k2b4gC.js → diagram-5GNKFQAL-B0noeRZk.js} +1 -1
- package/dist/rcs-web/assets/{diagram-KO2AKTUF-CMLav2KT.js → diagram-KO2AKTUF-q4A3A-0G.js} +1 -1
- package/dist/rcs-web/assets/{diagram-LMA3HP47-D14sXWdh.js → diagram-LMA3HP47-Z8Q18cks.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/diagram-OG6HWLK6-BexFwBQa.js → dist/rcs-web/assets/diagram-OG6HWLK6-JYocDScA.js} +1 -1
- package/dist/rcs-web/assets/{dialog-B4hKrd7w.js → dialog-jGu3j2II.js} +1 -1
- package/dist/rcs-web/assets/{erDiagram-TEJ5UH35-BA8ANmoV.js → erDiagram-TEJ5UH35-E18rAGwe.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/flowDiagram-I6XJVG4X-dTQIvKsj.js → dist/rcs-web/assets/flowDiagram-I6XJVG4X-DBAHvZfJ.js} +1 -1
- package/dist/rcs-web/assets/{ganttDiagram-6RSMTGT7-8SDHYxXc.js → ganttDiagram-6RSMTGT7-1aqSO10M.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/gitGraphDiagram-PVQCEYII-Bu7LyvTG.js → dist/rcs-web/assets/gitGraphDiagram-PVQCEYII-uBw1naVm.js} +1 -1
- package/dist/rcs-web/assets/{infoDiagram-5YYISTIA-BuQuDvuX.js → infoDiagram-5YYISTIA-5ZFaePD-.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/ishikawaDiagram-YF4QCWOH-QjafGk8V.js → dist/rcs-web/assets/ishikawaDiagram-YF4QCWOH-DvjOCepo.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/journeyDiagram-JHISSGLW-_FOXjXDF.js → dist/rcs-web/assets/journeyDiagram-JHISSGLW-dnXupGdJ.js} +1 -1
- package/dist/rcs-web/assets/{kanban-definition-UN3LZRKU-CbqJqyY6.js → kanban-definition-UN3LZRKU-Co4PRiOE.js} +1 -1
- package/dist/rcs-web/assets/{linear-H6F41eb2.js → linear-B9BaViDA.js} +1 -1
- package/dist/rcs-web/assets/main-CP31AzxJ.css +1 -0
- package/dist/rcs-web/assets/{main-BopVSHhX.js → main-CqWvY7FG.js} +62 -62
- package/{packages/remote-control-server/web/dist/assets/mermaid-VLURNSYL-5FH_DIq9.js → dist/rcs-web/assets/mermaid-VLURNSYL-B-oU9mPp.js} +4 -4
- package/dist/rcs-web/assets/{mermaid.core-C004NitB.js → mermaid.core-DE67nE19.js} +5 -5
- package/dist/rcs-web/assets/{mindmap-definition-RKZ34NQL-utqEJ2a8.js → mindmap-definition-RKZ34NQL-BNYnuKJy.js} +1 -1
- package/dist/rcs-web/assets/{notifications-DOBs9HVf.js → notifications-BjTdDOj4.js} +1 -1
- package/dist/rcs-web/assets/{pieDiagram-4H26LBE5-OlbTwDZQ.js → pieDiagram-4H26LBE5-n1DnXCmk.js} +1 -1
- package/dist/rcs-web/assets/{quadrantDiagram-W4KKPZXB-BOe2DhrU.js → quadrantDiagram-W4KKPZXB-MTMv8wiE.js} +1 -1
- package/dist/rcs-web/assets/{refresh-cw-BSwpDl-7.js → refresh-cw-Ddd1BD9C.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/requirementDiagram-4Y6WPE33-s6V1yWUG.js → dist/rcs-web/assets/requirementDiagram-4Y6WPE33-6KBFW0WL.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/sankeyDiagram-5OEKKPKP-CdJD78Mx.js → dist/rcs-web/assets/sankeyDiagram-5OEKKPKP-CCvT5ejn.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/sequenceDiagram-3UESZ5HK-DvGV6Dhl.js → dist/rcs-web/assets/sequenceDiagram-3UESZ5HK-CiOW881y.js} +1 -1
- package/{packages/remote-control-server/web/dist/assets/stateDiagram-AJRCARHV-Bj-_Ulcn.js → dist/rcs-web/assets/stateDiagram-AJRCARHV-yeM7KZfg.js} +1 -1
- package/dist/rcs-web/assets/{stateDiagram-v2-BHNVJYJU-BLGWynk-.js → stateDiagram-v2-BHNVJYJU-CXddkakE.js} +1 -1
- package/dist/rcs-web/assets/{timeline-definition-PNZ67QCA-B6VAH6Ka.js → timeline-definition-PNZ67QCA-Dfgo8yRK.js} +1 -1
- package/dist/rcs-web/assets/{vennDiagram-CIIHVFJN-DUwaLI6R.js → vennDiagram-CIIHVFJN-CpW5v7I2.js} +1 -1
- package/dist/rcs-web/assets/{wardleyDiagram-YWT4CUSO-CBetJore.js → wardleyDiagram-YWT4CUSO-BsGpbaNe.js} +1 -1
- package/dist/rcs-web/assets/{workerType-BF4aY_R_.js → workerType-BURsA0u4.js} +1 -1
- package/dist/rcs-web/assets/{xychartDiagram-2RQKCTM6-BBnx6V66.js → xychartDiagram-2RQKCTM6-BZ9L5_e4.js} +1 -1
- package/dist/rcs-web/index.html +2 -2
- package/package.json +1 -1
- package/packages/remote-control-server/src/__tests__/memories.test.ts +654 -0
- package/packages/remote-control-server/src/db/rcs-schema.sql +42 -0
- package/packages/remote-control-server/src/registerRoutes.ts +6 -0
- package/packages/remote-control-server/src/routes/v1/memories.ts +132 -0
- package/packages/remote-control-server/src/routes/web/memories.ts +321 -0
- package/packages/remote-control-server/src/services/memories.ts +747 -0
- package/packages/remote-control-server/web/dist/assets/{AdminPanel-B9YWaqlO.js → AdminPanel-QjFUzKR-.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{ArtifactView-B8lAeS5B.js → ArtifactView-DSrHrqoO.js} +1 -1
- package/{dist/rcs-web/assets/ArtifactsGallery-CNd9-Awp.js → packages/remote-control-server/web/dist/assets/ArtifactsGallery-LD7hnmXQ.js} +1 -1
- package/{dist/rcs-web/assets/Claim-Dq08pl4W.js → packages/remote-control-server/web/dist/assets/Claim-rralKUvn.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{Dashboard-JZcrtByh.js → Dashboard-BhXzF4TR.js} +2 -2
- package/packages/remote-control-server/web/dist/assets/{Join-DgvRnpyb.js → Join-DYKrYQka.js} +1 -1
- package/{dist/rcs-web/assets/Login-CZbz6Wms.js → packages/remote-control-server/web/dist/assets/Login-Blmtx4In.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/MemoriesGallery-CWyitPTS.js +1 -0
- package/packages/remote-control-server/web/dist/assets/{Register-DD7uiwEj.js → Register-CnZOK0Wa.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{RegisterEmpty-BrBfeQXp.js → RegisterEmpty-RNN7njqd.js} +2 -2
- package/packages/remote-control-server/web/dist/assets/{SessionDetail-BbnQBjP1.js → SessionDetail-BeZeeaGH.js} +19 -19
- package/packages/remote-control-server/web/dist/assets/{SessionVisibilityBadge-kSo9esvT.js → SessionVisibilityBadge-D976F6JX.js} +2 -2
- package/packages/remote-control-server/web/dist/assets/{Setup-Ca30VUSF.js → Setup-BFW58zKK.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{ShareLanding-C_vlxFAM.js → ShareLanding-BTLCFUy8.js} +1 -1
- package/{dist/rcs-web/assets/TeamDetail-8T_kKUcX.js → packages/remote-control-server/web/dist/assets/TeamDetail-DwZoGkMp.js} +2 -2
- package/packages/remote-control-server/web/dist/assets/{TeamList-DRXGQCJi.js → TeamList-DehdjKJu.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{TeamSettings-Byhon5C1.js → TeamSettings-DsZDvdLi.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{UserSearchInput-wixyd_8w.js → UserSearchInput-B-phMzno.js} +2 -2
- package/packages/remote-control-server/web/dist/assets/{UserSettings-Ds2retFk.js → UserSettings-po8VpRyO.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{arc-CThS8KNL.js → arc-yo8UpUoc.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{architectureDiagram-3BPJPVTR-Bko99SuX.js → architectureDiagram-3BPJPVTR-CAzjNMmM.js} +1 -1
- package/{dist/rcs-web/assets/blockDiagram-GPEHLZMM-CqCAgp0i.js → packages/remote-control-server/web/dist/assets/blockDiagram-GPEHLZMM-DRvlErcg.js} +1 -1
- package/{dist/rcs-web/assets/c4Diagram-AAUBKEIU-C1pGDG-L.js → packages/remote-control-server/web/dist/assets/c4Diagram-AAUBKEIU-CtqgfHXS.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/channel-ByZbiIGl.js +1 -0
- package/packages/remote-control-server/web/dist/assets/{chunk-2J33WTMH-Bz0kJwEY.js → chunk-2J33WTMH-BnLSiOZc.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-4BX2VUAB-DYnlidI7.js → chunk-4BX2VUAB-CneZL39T.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-55IACEB6-cMV4HRvm.js → chunk-55IACEB6-AZPro6N3.js} +1 -1
- package/{dist/rcs-web/assets/chunk-727SXJPM-Bgz9JRYO.js → packages/remote-control-server/web/dist/assets/chunk-727SXJPM-DtoifF_Q.js} +1 -1
- package/{dist/rcs-web/assets/chunk-AQP2D5EJ-DIFGJlEF.js → packages/remote-control-server/web/dist/assets/chunk-AQP2D5EJ-BsdfbS-v.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-FMBD7UC4-BUC7O7T0.js → chunk-FMBD7UC4-Ba_h1XJS.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-ND2GUHAM-kGqgVnBZ.js → chunk-ND2GUHAM-CtZuWp5S.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{chunk-QZHKN3VN-B01O0qXh.js → chunk-QZHKN3VN-DF-7EztA.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/classDiagram-4FO5ZUOK-B7LKcjGg.js +1 -0
- package/packages/remote-control-server/web/dist/assets/classDiagram-v2-Q7XG4LA2-B7LKcjGg.js +1 -0
- package/packages/remote-control-server/web/dist/assets/{code-block-IT6T5CEO-CscK0pCh.js → code-block-IT6T5CEO-BB5vH41t.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{copy-CvmA5P_Q.js → copy-COu9cGeU.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{cose-bilkent-S5V4N54A-BsBsVccW.js → cose-bilkent-S5V4N54A-BvX9PMEk.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{dagre-BM42HDAG-Bn4B33S-.js → dagre-BM42HDAG-BsbASaLl.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{diagram-2AECGRRQ-DAuAIPR6.js → diagram-2AECGRRQ-zjhhcSia.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{diagram-5GNKFQAL-w3k2b4gC.js → diagram-5GNKFQAL-B0noeRZk.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{diagram-KO2AKTUF-CMLav2KT.js → diagram-KO2AKTUF-q4A3A-0G.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{diagram-LMA3HP47-D14sXWdh.js → diagram-LMA3HP47-Z8Q18cks.js} +1 -1
- package/{dist/rcs-web/assets/diagram-OG6HWLK6-BexFwBQa.js → packages/remote-control-server/web/dist/assets/diagram-OG6HWLK6-JYocDScA.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{dialog-B4hKrd7w.js → dialog-jGu3j2II.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{erDiagram-TEJ5UH35-BA8ANmoV.js → erDiagram-TEJ5UH35-E18rAGwe.js} +1 -1
- package/{dist/rcs-web/assets/flowDiagram-I6XJVG4X-dTQIvKsj.js → packages/remote-control-server/web/dist/assets/flowDiagram-I6XJVG4X-DBAHvZfJ.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{ganttDiagram-6RSMTGT7-8SDHYxXc.js → ganttDiagram-6RSMTGT7-1aqSO10M.js} +1 -1
- package/{dist/rcs-web/assets/gitGraphDiagram-PVQCEYII-Bu7LyvTG.js → packages/remote-control-server/web/dist/assets/gitGraphDiagram-PVQCEYII-uBw1naVm.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{infoDiagram-5YYISTIA-BuQuDvuX.js → infoDiagram-5YYISTIA-5ZFaePD-.js} +1 -1
- package/{dist/rcs-web/assets/ishikawaDiagram-YF4QCWOH-QjafGk8V.js → packages/remote-control-server/web/dist/assets/ishikawaDiagram-YF4QCWOH-DvjOCepo.js} +1 -1
- package/{dist/rcs-web/assets/journeyDiagram-JHISSGLW-_FOXjXDF.js → packages/remote-control-server/web/dist/assets/journeyDiagram-JHISSGLW-dnXupGdJ.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{kanban-definition-UN3LZRKU-CbqJqyY6.js → kanban-definition-UN3LZRKU-Co4PRiOE.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{linear-H6F41eb2.js → linear-B9BaViDA.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/main-CP31AzxJ.css +1 -0
- package/packages/remote-control-server/web/dist/assets/{main-BopVSHhX.js → main-CqWvY7FG.js} +62 -62
- package/{dist/rcs-web/assets/mermaid-VLURNSYL-5FH_DIq9.js → packages/remote-control-server/web/dist/assets/mermaid-VLURNSYL-B-oU9mPp.js} +4 -4
- package/packages/remote-control-server/web/dist/assets/{mermaid.core-C004NitB.js → mermaid.core-DE67nE19.js} +5 -5
- package/packages/remote-control-server/web/dist/assets/{mindmap-definition-RKZ34NQL-utqEJ2a8.js → mindmap-definition-RKZ34NQL-BNYnuKJy.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{notifications-DOBs9HVf.js → notifications-BjTdDOj4.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{pieDiagram-4H26LBE5-OlbTwDZQ.js → pieDiagram-4H26LBE5-n1DnXCmk.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{quadrantDiagram-W4KKPZXB-BOe2DhrU.js → quadrantDiagram-W4KKPZXB-MTMv8wiE.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{refresh-cw-BSwpDl-7.js → refresh-cw-Ddd1BD9C.js} +1 -1
- package/{dist/rcs-web/assets/requirementDiagram-4Y6WPE33-s6V1yWUG.js → packages/remote-control-server/web/dist/assets/requirementDiagram-4Y6WPE33-6KBFW0WL.js} +1 -1
- package/{dist/rcs-web/assets/sankeyDiagram-5OEKKPKP-CdJD78Mx.js → packages/remote-control-server/web/dist/assets/sankeyDiagram-5OEKKPKP-CCvT5ejn.js} +1 -1
- package/{dist/rcs-web/assets/sequenceDiagram-3UESZ5HK-DvGV6Dhl.js → packages/remote-control-server/web/dist/assets/sequenceDiagram-3UESZ5HK-CiOW881y.js} +1 -1
- package/{dist/rcs-web/assets/stateDiagram-AJRCARHV-Bj-_Ulcn.js → packages/remote-control-server/web/dist/assets/stateDiagram-AJRCARHV-yeM7KZfg.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{stateDiagram-v2-BHNVJYJU-BLGWynk-.js → stateDiagram-v2-BHNVJYJU-CXddkakE.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{timeline-definition-PNZ67QCA-B6VAH6Ka.js → timeline-definition-PNZ67QCA-Dfgo8yRK.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{vennDiagram-CIIHVFJN-DUwaLI6R.js → vennDiagram-CIIHVFJN-CpW5v7I2.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{wardleyDiagram-YWT4CUSO-CBetJore.js → wardleyDiagram-YWT4CUSO-BsGpbaNe.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{workerType-BF4aY_R_.js → workerType-BURsA0u4.js} +1 -1
- package/packages/remote-control-server/web/dist/assets/{xychartDiagram-2RQKCTM6-BBnx6V66.js → xychartDiagram-2RQKCTM6-BZ9L5_e4.js} +1 -1
- package/packages/remote-control-server/web/dist/index.html +2 -2
- package/dist/rcs-web/assets/channel-D6RbJTfV.js +0 -1
- package/dist/rcs-web/assets/classDiagram-4FO5ZUOK-BlCPk6aR.js +0 -1
- package/dist/rcs-web/assets/classDiagram-v2-Q7XG4LA2-BlCPk6aR.js +0 -1
- package/dist/rcs-web/assets/main-C0n90aVY.css +0 -1
- package/packages/remote-control-server/web/dist/assets/channel-D6RbJTfV.js +0 -1
- package/packages/remote-control-server/web/dist/assets/classDiagram-4FO5ZUOK-BlCPk6aR.js +0 -1
- package/packages/remote-control-server/web/dist/assets/classDiagram-v2-Q7XG4LA2-BlCPk6aR.js +0 -1
- package/packages/remote-control-server/web/dist/assets/main-C0n90aVY.css +0 -1
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
var
|
|
1
|
+
var nn=Object.defineProperty;var rn=(r,t,s)=>t in r?nn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[t]=s;var R=(r,t,s)=>rn(r,typeof t!="symbol"?t+"":t,s);import{j as e,e as l}from"./vendor-DE_-CLIE.js";import{av as Q,ac as an,aD as Dt,aC as qt,aJ as c,aF as on,aE as Ue,aK as K,aA as de,ao as ln,an as G,af as cn,al as dn,aO as un,aR as Z,T as mn,Q as xn,X as fn,L as Ce,H as pn,I as hn,i as Pt,az as ms,N as gn,aw as Fe,e as Te,S as dt,M as yn,y as bn,ax as V,at as ne,ay as jn,aL as wn,G as kn,D as vn,aM as Ot,ag as Nn,a1 as _n,ak as Sn,A as Cn,aB as Tn,aG as En,aH as Mn,Z as Ut,a0 as Rn,aN as An,b as In,a4 as Ft,ai as $n,K as xs,F as Dn,B as fs,d as qn,C as Pn,ab as Kt,l as On,a as Un,u as Le,w as Be,E as Fn,g as He,f as We,v as Qe,s as Kn}from"./main-CqWvY7FG.js";import{A as Ln,g as Lt}from"./workerType-BURsA0u4.js";import{D as xe,a as fe,c as pe,d as he,b as Bn}from"./dialog-jGu3j2II.js";import{R as Hn}from"./refresh-cw-Ddd1BD9C.js";import{A as Wn,U as Qn}from"./UserSearchInput-B-phMzno.js";import{C as zn}from"./copy-COu9cGeU.js";import{E as Vn,A as Gn}from"./ArtifactsGallery-LD7hnmXQ.js";import{S as Yn}from"./SessionVisibilityBadge-D976F6JX.js";import{MemoriesGallery as Jn}from"./MemoriesGallery-CWyitPTS.js";import{S as Xn,b as Zn}from"./notifications-BjTdDOj4.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 er=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],ps=Q("chevron-right",er);/**
|
|
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 tr=[["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"}]],hs=Q("cpu",tr);/**
|
|
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 sr=[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]],nr=Q("gauge",sr);/**
|
|
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 rr=[["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"}]],ar=Q("hash",rr);/**
|
|
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 or=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],ir=Q("info",or);/**
|
|
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 lr=[["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"}]],cr=Q("layers",lr);/**
|
|
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 dr=[["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"}]],gs=Q("message-circle-question-mark",dr);/**
|
|
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 ur=[["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"}]],mr=Q("message-square-text",ur);/**
|
|
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 xr=[["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"}]],fr=Q("play",xr);/**
|
|
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 pr=[["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"}]],ys=Q("plug",pr);/**
|
|
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 hr=[["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"}]],gr=Q("server-cog",hr);/**
|
|
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 yr=[["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"}]],bs=Q("settings-2",yr);/**
|
|
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 br=[["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"}]],jr=Q("share-2",br);/**
|
|
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 pr=[["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"}]],hr=Q("shield-check",pr);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,k,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:(k=t.usage)==null?void 0:k.total_tokens,toolUseCount:(C=t.usage)==null?void 0:C.tool_uses,durationMs:(_=t.usage)==null?void 0:_.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 gr(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 yr(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=yr(t.remote_capabilities??r.remote_capabilities);return s.length===0&&n.length===0&&!a?null:{commands:s,skills:n,capabilities:a}}class br{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 rn(),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 ce=new br;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 jr{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,"onTurnStart");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,"turnStartedAt",null);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,this.onTurnStart=n==null?void 0:n.onTurnStart}markClosed(){this.closed=!0}setTurnStartedAt(t){var s;this.turnStartedAt!==t&&(this.turnStartedAt=t,(s=this.onTurnStart)==null||s.call(this,t))}async init(){await this.loadHistory(),this.connectSSE()}async loadHistory(){var j,m,h,w,S,I,T;const{events:t}=await Zs(this.sessionId);if(!t||t.length===0)return;const s=new Set;for(const b of t){if(b.type!=="user"||b.direction==="inbound")continue;const E=(j=b.payload)==null?void 0:j.uuid;typeof E=="string"&&E&&s.add(E)}const n=[];let a=null;const d=()=>{a&&(n.push(a),a=null)};for(const b of t){const E=b.payload||{},$=E.uuid;if(typeof $=="string"&&$&&this.seenUuids.add($),b.type==="tool_use"){const R=E.tool_call_id;typeof R=="string"&&R&&this.seenToolCallIds.add(R)}if(b.type==="user"){if(b.direction==="inbound"){const v=E.uuid;if(typeof v!="string"||!v||s.has(v))continue}d();const R=at(E);R&&n.push({type:"user_message",id:b.id||`hist-user-${n.length}`,content:R})}else if(b.type==="assistant"){d();const R=at(E);if(It(R))continue;const v=Gt(E),O=[],L=E.message;if(L&&typeof L=="object"&&Array.isArray(L.content)){for(const Y of L.content)if(Y.type==="tool_use"){const ee=Y.id;ee&&this.seenToolCallIds.add(ee),O.push({type:"tool_call",toolCall:{id:ee||`hist-tool-${n.length}`,title:Y.name||"tool",status:"complete",rawInput:Y.input||{}}})}}if(R||v||O.length>0){a={type:"assistant_message",id:b.id||`hist-asst-${n.length}`,chunks:[...v?[{type:"thought",text:v}]:[],...R?[{type:"message",text:R}]:[]]},n.push(a);for(const Y of O)n.push(Y);a=null}}else if(b.type==="conversation_rewound"){const R=Jt(E);if(R){const v=n.findIndex(O=>$t(O)===R);v>=0&&(n.length=v)}}else if(b.type==="tool_use"){const R=E,v={type:"tool_call",toolCall:{id:R.tool_call_id||`hist-tool-${n.length}`,title:R.tool_name||"tool",status:"complete",rawInput:R.tool_input||{}}};n.push(v)}else if(b.type==="tool_result"){const R=E,v=Vt(n,R.tool_call_id||"");if(v>=0){const O=n[v];n[v]={type:"tool_call",toolCall:{...O.toolCall,rawOutput:{output:R.content||R.output||""}}}}}}d();let i=null;for(const b of t){if(b.type!=="task_state")continue;const E=b.payload||{};Array.isArray(E.tasks)&&(i=E.tasks)}if(i&&i.length>0){const b=Yt(i);b.length>0&&n.push({type:"plan",id:`plan-hist-${Date.now()}`,entries:b})}this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries(n);let u=null,f=null,p=null,g=null,y=0,k=0;for(const b of t){const E=b.payload||{};if(typeof b.createdAt=="number"&&(b.createdAt>k&&(k=b.createdAt),b.type==="user"&&g!=="user"&&b.createdAt>0&&(y=b.createdAt)),b.type==="user"?g="user":(b.type==="result"||b.type==="result_success"||b.type==="interrupt")&&(g="turn_end"),b.type==="system"&&(E.subtype==="init"||((m=E.raw)==null?void 0:m.subtype)==="init")&&(f=zt(E)),b.type==="models_state"){const $=E.raw,R=$&&typeof $=="object"?$.models_state:E.models_state;R&&Array.isArray(R.availableModels)&&typeof R.currentModelId=="string"&&(u=R)}else if(b.type==="result"||b.type==="result_success"){const $=E.usage,R=typeof E.total_cost_usd=="number"?E.total_cost_usd:null;($||R!==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:R})}}let C=!1,_=dt();for(const b of t){if(b.type!=="system")continue;const E=Wt(b.payload||{});E&&(_=Lt(_,E),C=!0)}C&&(this.subagentState=_,(h=this.onSubagentUpdate)==null||h.call(this,this.subagentState)),u&&((w=this.onModelsStateChange)==null||w.call(this,u)),f&&((S=this.onWorkerInfoChange)==null||S.call(this,f)),p&&((I=this.onUsageChange)==null||I.call(this,p)),this.turnEnded=g==="turn_end",this.userSinceTurnEnd=g==="user",this.setTurnStartedAt(!this.closed&&g==="user"&&y>0&&k>=y?Date.now()-(k-y):null),this.turnEnded&&!this.closed&&((T=this.onStatusChange)==null||T.call(this,"idle"))}connectSSE(){ce.connect(this.sessionId),this.unsub=ce.onEvent(t=>this.handleEvent(t)),this.unsubState=ce.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),ce.disconnect()}handleEvent(t){var a,d,i,u,f,p,g,y,k,C,_,j;const s=t.type,n=t.payload||{};switch(s){case"user":{if(this.applyEmbeddedToolResults(n),this.userSinceTurnEnd=!0,!this.closed&&this.turnStartedAt===null&&this.setTurnStartedAt(Date.now()),t.direction==="inbound"){const 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(I=>{const T=I[I.length-1];if((T==null?void 0:T.type)==="assistant_message"&&T.id.startsWith(ot))return[...I.slice(0,-1),{...T,id:`assistant-${Date.now()}`,chunks:[...w?[{type:"thought",text:w}]:[],{type:"message",text:h}]}];if((T==null?void 0:T.type)==="assistant_message"){const b=T.chunks[T.chunks.length-1];return(b==null?void 0:b.type)==="message"?[...I.slice(0,-1),{...T,chunks:[...T.chunks.slice(0,-1),{type:"message",text:b.text+h}]}]:[...I.slice(0,-1),{...T,chunks:[...T.chunks,{type:"message",text:h}]}]}if(h&&h.trim()||w){const b={type:"assistant_message",id:`assistant-${Date.now()}`,chunks:[...w?[{type:"thought",text:w}]:[],...h?[{type:"message",text:h}]:[]]};return[...I,b]}return I});const S=n.message;if(S&&typeof S=="object"&&Array.isArray(S.content)){const I=S.content.filter(T=>T.type==="tool_use");for(const T of I){const b=T.id||`call-${Date.now()}-${Math.random().toString(16).slice(2,8)}`;if(this.seenToolCallIds.has(b))continue;this.seenToolCallIds.add(b),this.pendingToolCallIds.add(b);const E={id:b,title:T.name||"tool",status:"running",rawInput:T.input||{}};this.setEntries($=>[...$,{type:"tool_call",toolCall:E}])}}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(S=>[...S,{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.setTurnStartedAt(null),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",S=m.input||m.tool_input||{},I=m.description||"",T=Array.isArray(m.permission_suggestions)?m.permission_suggestions:[];this.setEntries(b=>{const E=[...b].reverse().findIndex($=>$.type==="tool_call");if(E>=0){const $=b.length-1-E,R=b[$];if(R.toolCall.status==="running")return this.pendingPermissionToolIds.set(h,R.toolCall.id),b.map((v,O)=>O===$?{type:"tool_call",toolCall:{...R.toolCall,status:"waiting_for_confirmation",permissionRequest:{requestId:h,options:[]}}}:v)}return b}),(d=this.onPermissionRequest)==null||d.call(this,{requestId:h,toolName:w,toolInput:S,description:I,suggestions:T})}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(S=>$t(S)===m);return w===-1?h:h.slice(0,w)}));break}case"session_status":{if(en(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,S=Wt(n);S&&(this.subagentState=Lt(this.subagentState,S),(g=this.onSubagentUpdate)==null||g.call(this,this.subagentState));const I=typeof h.permissionMode=="string"?h.permissionMode:typeof n.permissionMode=="string"?n.permissionMode:null;if(I&&((y=this.onPermissionModeChange)==null||y.call(this,I)),w==="init"){const T=zt(n);T&&((k=this.onWorkerInfoChange)==null||k.call(this,T))}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){(C=this.onControlResponse)==null||C.call(this,{subtype:w,requestId:h,error:typeof m.error=="string"?m.error:void 0});const S=this.pendingControlRequests.get(h);S&&(this.pendingControlRequests.delete(h),S({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 S=h.text??h.thinking;if(typeof S!="string"||!S)break;this.appendStreamingDelta(w,S)}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.setTurnStartedAt(null),this.finalizePendingToolCalls(n.is_error?"canceled":"complete"),this.closed||(_=this.onStatusChange)==null||_.call(this,"idle");const m=n.usage,h=typeof n.total_cost_usd=="number"?n.total_cost_usd:null;if(m||h!==null){const b=((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:b,outputTokens:(m==null?void 0:m.output_tokens)??0,totalCostUsd:h})}const w=typeof n.subtype=="string"?n.subtype:"",S=n.raw&&typeof n.raw=="object"?n.raw:void 0,T=(typeof n.result=="string"?n.result:typeof(S==null?void 0:S.result)=="string"?S.result:"").trim();w.startsWith("error_")&&T&&this.setEntries(b=>[...b,{type:"command_output",id:`exit-error-${typeof n.uuid=="string"?n.uuid:Date.now()}`,commandName:"worker",inputText:"",title:c("adapter.workerCrashed"),outputText:T,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(I=>I.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?` (${wr(g.size)})`:""}`,k=g.textContent||c("attach.emptyFile");u.push({type:"text",text:`${y}
|
|
71
|
+
*/const wr=[["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"}]],kr=Q("shield-check",wr);function ut(){return{tasks:{}}}const Bt=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 Ht(r,t){var i,u,f,p,g,y,k,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+Bt}}}:{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:(k=t.usage)==null?void 0:k.total_tokens,toolUseCount:(C=t.usage)==null?void 0:C.tool_uses,durationMs:(_=t.usage)==null?void 0:_.duration_ms,evictAfter:a+Bt}}}}function js(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 Wt={in_process_teammate:0,local_bash:1,monitor_mcp:2,remote_agent:3,local_agent:4,dream:5},Qt=100;function vr(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=Wt[s]??Qt,d=Wt[n]??Qt;return a===d?s.localeCompare(n):a-d}).map(([s,n])=>({taskType:s,tasks:[...n].sort((a,d)=>a.startTime-d.startTime)}))}function zt(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 Nr(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 Vt(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 Gt(r){const t=r.raw&&typeof r.raw=="object"&&!Array.isArray(r.raw)?r.raw:r,s=Vt(t.slash_command_details??r.slash_command_details,t.slash_commands??r.slash_commands),n=Vt(t.skill_details??r.skill_details,t.skills??r.skills),a=Nr(t.remote_capabilities??r.remote_capabilities);return s.length===0&&n.length===0&&!a?null:{commands:s,skills:n,capabilities:a}}class _r{constructor(t){R(this,"listeners",new Set);R(this,"stateListeners",new Set);R(this,"eventSource",null);R(this,"sessionId",null);R(this,"_lastSeqNum",0);R(this,"lastFrameAt",0);R(this,"firstEventAfterOpen",!1);R(this,"watchdogTimer",null);R(this,"visibilityHandler",null);R(this,"reconnectTimer",null);R(this,"reconnectAttempts",0);R(this,"_state","idle");R(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 un(),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 le=new _r;function ot(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 Yt(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 it="streaming-";function Jt(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 Xt(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 Zt(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 Sr{constructor(t,s,n){R(this,"sessionId");R(this,"setEntries");R(this,"unsub",null);R(this,"unsubState",null);R(this,"onStatusChange");R(this,"onError");R(this,"onPermissionRequest");R(this,"onModelsStateChange");R(this,"onSubagentUpdate");R(this,"onControlResponse");R(this,"onPermissionModeChange");R(this,"onUsageChange");R(this,"onElicitationRequest");R(this,"onWorkerInfoChange");R(this,"onTurnStart");R(this,"subagentState",ut());R(this,"seenUuids",new Set);R(this,"seenToolCallIds",new Set);R(this,"pendingToolCallIds",new Set);R(this,"pendingPermissionToolIds",new Map);R(this,"postedUserUuids",new Set);R(this,"pendingControlRequests",new Map);R(this,"turnEnded",!1);R(this,"userSinceTurnEnd",!1);R(this,"turnStartedAt",null);R(this,"closed",!1);this.sessionId=t,this.setEntries=s,this.onStatusChange=n==null?void 0:n.onStatusChange,this.onError=n==null?void 0:n.onError,this.onPermissionRequest=n==null?void 0:n.onPermissionRequest,this.onModelsStateChange=n==null?void 0:n.onModelsStateChange,this.onSubagentUpdate=n==null?void 0:n.onSubagentUpdate,this.onControlResponse=n==null?void 0:n.onControlResponse,this.onPermissionModeChange=n==null?void 0:n.onPermissionModeChange,this.onUsageChange=n==null?void 0:n.onUsageChange,this.onElicitationRequest=n==null?void 0:n.onElicitationRequest,this.onWorkerInfoChange=n==null?void 0:n.onWorkerInfoChange,this.onTurnStart=n==null?void 0:n.onTurnStart}markClosed(){this.closed=!0}setTurnStartedAt(t){var s;this.turnStartedAt!==t&&(this.turnStartedAt=t,(s=this.onTurnStart)==null||s.call(this,t))}async init(){await this.loadHistory(),this.connectSSE()}async loadHistory(){var j,m,h,w,S,I,T;const{events:t}=await an(this.sessionId);if(!t||t.length===0)return;const s=new Set;for(const b of t){if(b.type!=="user"||b.direction==="inbound")continue;const E=(j=b.payload)==null?void 0:j.uuid;typeof E=="string"&&E&&s.add(E)}const n=[];let a=null;const d=()=>{a&&(n.push(a),a=null)};for(const b of t){const E=b.payload||{},$=E.uuid;if(typeof $=="string"&&$&&this.seenUuids.add($),b.type==="tool_use"){const A=E.tool_call_id;typeof A=="string"&&A&&this.seenToolCallIds.add(A)}if(b.type==="user"){if(b.direction==="inbound"){const v=E.uuid;if(typeof v!="string"||!v||s.has(v))continue}d();const A=ot(E);A&&n.push({type:"user_message",id:b.id||`hist-user-${n.length}`,content:A})}else if(b.type==="assistant"){d();const A=ot(E);if(Dt(A))continue;const v=Jt(E),O=[],L=E.message;if(L&&typeof L=="object"&&Array.isArray(L.content)){for(const Y of L.content)if(Y.type==="tool_use"){const ee=Y.id;ee&&this.seenToolCallIds.add(ee),O.push({type:"tool_call",toolCall:{id:ee||`hist-tool-${n.length}`,title:Y.name||"tool",status:"complete",rawInput:Y.input||{}}})}}if(A||v||O.length>0){a={type:"assistant_message",id:b.id||`hist-asst-${n.length}`,chunks:[...v?[{type:"thought",text:v}]:[],...A?[{type:"message",text:A}]:[]]},n.push(a);for(const Y of O)n.push(Y);a=null}}else if(b.type==="conversation_rewound"){const A=Zt(E);if(A){const v=n.findIndex(O=>qt(O)===A);v>=0&&(n.length=v)}}else if(b.type==="tool_use"){const A=E,v={type:"tool_call",toolCall:{id:A.tool_call_id||`hist-tool-${n.length}`,title:A.tool_name||"tool",status:"complete",rawInput:A.tool_input||{}}};n.push(v)}else if(b.type==="tool_result"){const A=E,v=Yt(n,A.tool_call_id||"");if(v>=0){const O=n[v];n[v]={type:"tool_call",toolCall:{...O.toolCall,rawOutput:{output:A.content||A.output||""}}}}}}d();let i=null;for(const b of t){if(b.type!=="task_state")continue;const E=b.payload||{};Array.isArray(E.tasks)&&(i=E.tasks)}if(i&&i.length>0){const b=Xt(i);b.length>0&&n.push({type:"plan",id:`plan-hist-${Date.now()}`,entries:b})}this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries(n);let u=null,f=null,p=null,g=null,y=0,k=0;for(const b of t){const E=b.payload||{};if(typeof b.createdAt=="number"&&(b.createdAt>k&&(k=b.createdAt),b.type==="user"&&g!=="user"&&b.createdAt>0&&(y=b.createdAt)),b.type==="user"?g="user":(b.type==="result"||b.type==="result_success"||b.type==="interrupt")&&(g="turn_end"),b.type==="system"&&(E.subtype==="init"||((m=E.raw)==null?void 0:m.subtype)==="init")&&(f=Gt(E)),b.type==="models_state"){const $=E.raw,A=$&&typeof $=="object"?$.models_state:E.models_state;A&&Array.isArray(A.availableModels)&&typeof A.currentModelId=="string"&&(u=A)}else if(b.type==="result"||b.type==="result_success"){const $=E.usage,A=typeof E.total_cost_usd=="number"?E.total_cost_usd:null;($||A!==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:A})}}let C=!1,_=ut();for(const b of t){if(b.type!=="system")continue;const E=zt(b.payload||{});E&&(_=Ht(_,E),C=!0)}C&&(this.subagentState=_,(h=this.onSubagentUpdate)==null||h.call(this,this.subagentState)),u&&((w=this.onModelsStateChange)==null||w.call(this,u)),f&&((S=this.onWorkerInfoChange)==null||S.call(this,f)),p&&((I=this.onUsageChange)==null||I.call(this,p)),this.turnEnded=g==="turn_end",this.userSinceTurnEnd=g==="user",this.setTurnStartedAt(!this.closed&&g==="user"&&y>0&&k>=y?Date.now()-(k-y):null),this.turnEnded&&!this.closed&&((T=this.onStatusChange)==null||T.call(this,"idle"))}connectSSE(){le.connect(this.sessionId),this.unsub=le.onEvent(t=>this.handleEvent(t)),this.unsubState=le.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),le.disconnect()}handleEvent(t){var a,d,i,u,f,p,g,y,k,C,_,j;const s=t.type,n=t.payload||{};switch(s){case"user":{if(this.applyEmbeddedToolResults(n),this.userSinceTurnEnd=!0,!this.closed&&this.turnStartedAt===null&&this.setTurnStartedAt(Date.now()),t.direction==="inbound"){const m=n.uuid;if(typeof m!="string"||!m||this.postedUserUuids.has(m)||this.seenUuids.has(m))break;this.seenUuids.add(m);const h=ot(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(Dt(h))break;const w=Jt(n);this.setEntries(I=>{const T=I[I.length-1];if((T==null?void 0:T.type)==="assistant_message"&&T.id.startsWith(it))return[...I.slice(0,-1),{...T,id:`assistant-${Date.now()}`,chunks:[...w?[{type:"thought",text:w}]:[],{type:"message",text:h}]}];if((T==null?void 0:T.type)==="assistant_message"){const b=T.chunks[T.chunks.length-1];return(b==null?void 0:b.type)==="message"?[...I.slice(0,-1),{...T,chunks:[...T.chunks.slice(0,-1),{type:"message",text:b.text+h}]}]:[...I.slice(0,-1),{...T,chunks:[...T.chunks,{type:"message",text:h}]}]}if(h&&h.trim()||w){const b={type:"assistant_message",id:`assistant-${Date.now()}`,chunks:[...w?[{type:"thought",text:w}]:[],...h?[{type:"message",text:h}]:[]]};return[...I,b]}return I});const S=n.message;if(S&&typeof S=="object"&&Array.isArray(S.content)){const I=S.content.filter(T=>T.type==="tool_use");for(const T of I){const b=T.id||`call-${Date.now()}-${Math.random().toString(16).slice(2,8)}`;if(this.seenToolCallIds.has(b))continue;this.seenToolCallIds.add(b),this.pendingToolCallIds.add(b);const E={id:b,title:T.name||"tool",status:"running",rawInput:T.input||{}};this.setEntries($=>[...$,{type:"tool_call",toolCall:E}])}}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(S=>[...S,{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.setTurnStartedAt(null),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",S=m.input||m.tool_input||{},I=m.description||"",T=Array.isArray(m.permission_suggestions)?m.permission_suggestions:[];this.setEntries(b=>{const E=[...b].reverse().findIndex($=>$.type==="tool_call");if(E>=0){const $=b.length-1-E,A=b[$];if(A.toolCall.status==="running")return this.pendingPermissionToolIds.set(h,A.toolCall.id),b.map((v,O)=>O===$?{type:"tool_call",toolCall:{...A.toolCall,status:"waiting_for_confirmation",permissionRequest:{requestId:h,options:[]}}}:v)}return b}),(d=this.onPermissionRequest)==null||d.call(this,{requestId:h,toolName:w,toolInput:S,description:I,suggestions:T})}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=Zt(n);m&&(this.pendingToolCallIds.clear(),this.pendingPermissionToolIds.clear(),this.setEntries(h=>{const w=h.findIndex(S=>qt(S)===m);return w===-1?h:h.slice(0,w)}));break}case"session_status":{if(on(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,S=zt(n);S&&(this.subagentState=Ht(this.subagentState,S),(g=this.onSubagentUpdate)==null||g.call(this,this.subagentState));const I=typeof h.permissionMode=="string"?h.permissionMode:typeof n.permissionMode=="string"?n.permissionMode:null;if(I&&((y=this.onPermissionModeChange)==null||y.call(this,I)),w==="init"){const T=Gt(n);T&&((k=this.onWorkerInfoChange)==null||k.call(this,T))}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){(C=this.onControlResponse)==null||C.call(this,{subtype:w,requestId:h,error:typeof m.error=="string"?m.error:void 0});const S=this.pendingControlRequests.get(h);S&&(this.pendingControlRequests.delete(h),S({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 S=h.text??h.thinking;if(typeof S!="string"||!S)break;this.appendStreamingDelta(w,S)}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.setTurnStartedAt(null),this.finalizePendingToolCalls(n.is_error?"canceled":"complete"),this.closed||(_=this.onStatusChange)==null||_.call(this,"idle");const m=n.usage,h=typeof n.total_cost_usd=="number"?n.total_cost_usd:null;if(m||h!==null){const b=((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:b,outputTokens:(m==null?void 0:m.output_tokens)??0,totalCostUsd:h})}const w=typeof n.subtype=="string"?n.subtype:"",S=n.raw&&typeof n.raw=="object"?n.raw:void 0,T=(typeof n.result=="string"?n.result:typeof(S==null?void 0:S.result)=="string"?S.result:"").trim();w.startsWith("error_")&&T&&this.setEntries(b=>[...b,{type:"command_output",id:`exit-error-${typeof n.uuid=="string"?n.uuid:Date.now()}`,commandName:"worker",inputText:"",title:c("adapter.workerCrashed"),outputText:T,variant:"error"}]);break}case"task_state":{const m=Array.isArray(n.tasks)?n.tasks:[];if(m.length===0)break;const h=Xt(m);if(h.length===0)break;this.setEntries(w=>[...w.filter(I=>I.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=Yt(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(it)){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:`${it}${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?` (${Cr(g.size)})`:""}`,k=g.textContent||c("attach.emptyFile");u.push({type:"text",text:`${y}
|
|
72
72
|
\`\`\`
|
|
73
73
|
${k}
|
|
74
74
|
\`\`\``})}else if(g.kind==="directory"){const y=g.files!=null?`${K("attach.directoryHeader",{name:g.name})} ${K("attach.fileCount",{n:g.files.length})}`:K("attach.directoryHeader",{name:g.name}),k=g.textContent||c("attach.emptyDirectory");u.push({type:"text",text:`${y}
|
|
75
|
-
${k}`})}}const f=u.length===1&&u[0].type==="text"?u[0].text||t:u.length>0?u:t;try{const g=le();this.postedUserUuids.add(g);const y=await tn(this.sessionId,{type:"user",uuid:g,content:t,message:{content:f}}),k=(p=y==null?void 0:y.event)==null?void 0:p.id;k&&this.setEntries(C=>C.map(_=>_.type==="user_message"&&_.id===i.id?{..._,id:k}:_))}catch(g){throw this.setEntries(y=>y.filter(k=>!(k.type==="user_message"&&k.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 sn(this.sessionId)}async setPermissionMode(t){const s=le();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=le(),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=le();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=le();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 nn(this.sessionId,t)}async endSession(t){await G(this.sessionId,{type:"control_request",request_id:le(),request:{subtype:"end_session",...t?{reason:t}:{}}})}}function wr(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 Z(),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(an,{}),e.jsx(on,{onSettingsClick:()=>{window.history.pushState(null,"","/settings"),window.dispatchEvent(new PopStateEvent("popstate"))}})]})})}const Xt="rcs:subagent-panel:collapsed";function kr(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 vr(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 Nr({status:r}){return r==="running"?e.jsx(Ce,{className:"h-3 w-3 animate-spin text-brand-text"}):r==="completed"?e.jsx(lr,{className:"h-3 w-3 text-status-success"}):r==="failed"||r==="stopped"?e.jsx(cn,{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=vr(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(Nr,{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:kr(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(ln,{className:"h-3.5 w-3.5"})})]})}function _r({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 k=!y;try{window.localStorage.setItem(Xt,k?"1":"0")}catch{}return k})},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(k=>k+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 Sr(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 Cr(r){return r?Date.now()-r<6e4:!1}function Tr({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)},[k,C]=l.useState(!1),_=async()=>{if(!(!f||k)&&window.confirm(c("task.endConfirm"))){C(!0);try{await f(),r()}catch{C(!1)}}},j=n.length,m=t.worker,h=t.work_item,w=t.environment;return e.jsx(me,{open:!0,onOpenChange:S=>{S||r()},children:e.jsxs(xe,{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(fe,{children:e.jsx(pe,{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(Pn,{className:"h-3.5 w-3.5"}),"Status"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(dn,{status:s||t.status||"unknown"}),e.jsx("span",{className:"text-xs text-text-muted",children:m&&(Cr(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:Sr(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(Ar,{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(Ce,{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(ur,{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:_,disabled:k,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:k?"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(un,{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(Zn,{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 Er={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"},Mr=new Set(["dream"]);function Ar({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(nr,{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?K("task.mixedCount",{running:i,recent:u}):i>0?K("task.runningCount",{count:i}):K("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:gr(d).map(f=>{const p=!Mr.has(f.taskType),g=Er[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 Rr={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"},Ir={connected:"mcp.status.connected",failed:"mcp.status.failed","needs-auth":"mcp.status.needsAuth",pending:"mcp.status.pending",disabled:"mcp.status.disabled"};function $r({onClose:r,fetchServers:t,onToggle:s,onReconnect:n}){Z();const[a,d]=l.useState(null),[i,u]=l.useState(null),[f,p]=l.useState(null),[g,y]=l.useState(null),k=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(()=>{k()},[k]);const C=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 k()}},_=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 k()}};return e.jsx(me,{open:!0,onOpenChange:j=>{j||r()},children:e.jsxs(xe,{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(fe,{children:e.jsxs(pe,{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(Ce,{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 ${Rr[j.status]}`,children:c(Ir[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&&` · ${K("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 _(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(Un,{className:`h-3.5 w-3.5 ${h?"animate-spin":""}`})}),e.jsx("button",{type:"button",role:"switch","aria-checked":!w,onClick:()=>void C(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 Dr(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 qr({onClose:r,fetchSettings:t,onApply:s}){Z();const[n,a]=l.useState(null),[d,i]=l.useState(null),[u,f]=l.useState(""),[p,g]=l.useState(null),[y,k]=l.useState(null),[C,_]=l.useState(null),[j,m]=l.useState(!1),h=l.useCallback(async()=>{g(null),k(null),_(null),m(!1);try{const v=await t();a(v),i(v?null:c("settings.loadFailed"))}catch(v){Fe("[SettingsDrawer] fetch failed",v),i(c("settings.loadFailed"))}},[t]);l.useEffect(()=>{h()},[h]);const w=l.useMemo(()=>n?Object.entries(n.effective).filter(([,v])=>v!==void 0).sort(([v],[O])=>v.localeCompare(O)):[],[n]),S=l.useMemo(()=>{const v=u.trim().toLowerCase();return v?w.filter(([O,L])=>`${O} ${Dr(L)}`.toLowerCase().includes(v)):w},[w,u]),I=v=>typeof v[1]=="boolean",T=l.useMemo(()=>S.filter(I),[S]),b=l.useMemo(()=>S.filter(v=>!I(v)),[S]),E=l.useMemo(()=>C===null?null:w.find(([v])=>v===C)??null,[w,C]),$=async()=>{if(E)try{await navigator.clipboard.writeText(Zt(E[1])),m(!0),window.setTimeout(()=>m(!1),1500)}catch(v){Fe("[SettingsDrawer] copy failed",v)}},R=async(v,O)=>{g(v),k(null);try{const L=await s({[v]:!O});L.ok||k(L.error||c("settings.writeFailed"))}finally{await h()}};return e.jsx(me,{open:!0,onOpenChange:v=>{v||r()},children:e.jsxs(xe,{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(fe,{children:e.jsxs(pe,{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(Ce,{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")})]}),E?e.jsxs("section",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>{_(null),m(!1)},className:"flex items-center gap-1.5 text-xs text-text-muted transition-colors hover:text-text-primary",children:[e.jsx(Fn,{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:E[0]}),e.jsx("pre",{className:"max-h-[60vh] overflow-y-auto whitespace-pre-wrap break-all rounded-md border border-border bg-surface-2 p-3 font-mono text-[10px] leading-relaxed text-text-secondary",children:Zt(E[1])}),e.jsxs("button",{type:"button",onClick:()=>void $(),className:"flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-text-secondary transition-colors hover:bg-surface-2 hover:text-text-primary",children:[j?e.jsx(Te,{className:"h-3.5 w-3.5 text-status-success"}):e.jsx(Ln,{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:v=>f(v.target.value),placeholder:c("settings.searchPlaceholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"})]}),S.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:c("settings.noMatch")}),T.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-[10px] font-medium uppercase tracking-wide text-text-muted",children:K("settings.togglable",{n:T.length})}),T.map(([v,O])=>{const L=p===v;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-border bg-surface-2 px-3 py-2",children:[e.jsx("div",{className:"truncate font-mono text-xs text-text-primary",children:v}),e.jsx("button",{type:"button",role:"switch","aria-checked":O,disabled:L,onClick:()=>void R(v,O),className:`relative h-5 w-9 flex-shrink-0 rounded-full transition-colors disabled:opacity-50 ${O?"bg-brand":"bg-surface-3"}`,title:O?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 ${O?"left-4.5":"left-0.5"}`})})]},v)})]}),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:K("settings.readOnly",{n:b.length})}),b.map(([v])=>e.jsxs("button",{type:"button",onClick:()=>_(v),className:"flex w-full items-center justify-between gap-3 rounded-md border border-border bg-surface-2 px-3 py-2 text-left transition-colors hover:bg-surface-3",title:c("settings.viewDetail"),children:[e.jsx("span",{className:"truncate font-mono text-xs text-text-primary",children:v}),e.jsx(ms,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"})]},v))]})]})]})]})]})})}function Pr({onClose:r,onAsk:t}){Z();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(k=>k.map(C=>C.id===g?{...C,answer:y??c("sideQuestion.noAnswer"),error:y===null}:C))}finally{u(!1)}};return e.jsx(me,{open:!0,onOpenChange:p=>{p||r()},children:e.jsxs(xe,{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(fe,{children:e.jsxs(pe,{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(mn,{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(Ce,{className:"h-4 w-4 animate-spin"}):e.jsx(xn,{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 Or({requestId:r,toolName:t,toolInput:s,description:n,suggestions:a,onApprove:d,onApproveAlways:i,onReject:u}){Z();const f=s&&typeof s=="object"&&!Array.isArray(s)?s:{},p=fn(pn(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":K("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(hn,{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((k,C)=>e.jsx(gn,{filePath:k.filePath,oldString:k.oldString,newString:k.newString,label:k.label},C))}):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:ne("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:ne("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(hr,{className:"h-3.5 w-3.5"}),c("permission.alwaysAllow")," ",qt(es(t,a),40)]}),e.jsx("button",{onClick:u,className:ne("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 Ur({questions:r,description:t,onSubmit:s,onSkip:n}){const[a,d]=l.useState({}),[i,u]=l.useState({}),[f,p]=l.useState(0),g=(_,j,m)=>{if(m){const h=a[_]||[],w=h.includes(j)?h.filter(S=>S!==j):[...h,j];d({...a,[_]:w})}else d({...a,[_]:j})},y=_=>{var m;const j=(m=i[_])==null?void 0:m.trim();j&&(d({...a,[_]:j}),u({...i,[_]:""}))},k=()=>{var j,m;const _={};for(const[h,w]of Object.entries(a)){const S=r[parseInt(h,10)];S&&(typeof w=="number"?_[h]=((m=(j=S.options)==null?void 0:j[w])==null?void 0:m.label)||String(w):Array.isArray(w)?_[h]=w.map(I=>{var T,b;return((b=(T=S.options)==null?void 0:T[I])==null?void 0:b.label)||String(I)}):_[h]=w)}s(_)};if(r.length<=1){const _=r[0]||{question:t,options:[],multiSelect:!1},j=_.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||_.question||"Question")}),e.jsxs("div",{className:"space-y-2",children:[(_.options||[]).map((m,h)=>{const w=j?(a[0]||[]).includes(h):a[0]===h;return e.jsxs("button",{onClick:()=>g(0,h,j),className:ne("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:k,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 C=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((_,j)=>e.jsx("button",{onClick:()=>p(j),className:ne("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:_.header||`Q${j+1}`},j))}),C&&e.jsx(Fr,{question:C,qIdx:f,answers:a,otherTexts:i,onSelect:g,onOtherTextChange:(_,j)=>u({...i,[_]: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:k,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 Fr({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:ne("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 Kr({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(Te,{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:Lr(r)}}),e.jsx("div",{className:"space-y-2",children:u?e.jsxs(e.Fragment,{children:[e.jsx(Se,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes"}),e.jsx(Se,{selected:n==="no",onClick:()=>a("no"),label:"No"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Se,{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(Se,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes, manually approve edits",desc:"Approve plan but confirm each edit"}),e.jsx(Se,{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 Se({selected:r,onClick:t,label:s,desc:n}){return e.jsxs("button",{onClick:t,className:ne("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:ne("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 Lr(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 Br({request:r,onSubmit:t}){Z();const s=Hr(r.requestedSchema),n=Wr(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(Bn,{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(or,{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 Hr(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 Wr(r){const t=r==null?void 0:r.required;return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function Qr(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 yn(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 bn(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 jn(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 zr({open:r,onClose:t,sessionId:s,sessionTitle:n}){Z();const{shares:a,isLoading:d,error:i,createShare:u,revokeShare:f}=Qr(s),[p,g]=l.useState("user"),[y,k]=l.useState(""),[C,_]=l.useState(""),[j,m]=l.useState("read"),[h,w]=l.useState(""),[S,I]=l.useState(!1),[T,b]=l.useState(null),[E,$]=l.useState(""),[R,v]=l.useState(!1),[O,L]=l.useState(!1);l.useEffect(()=>{r&&(g("user"),k(""),_(""),m("read"),w(""),I(!1),b(null),$(""),v(!1),L(!1))},[r]);const Y=async()=>{I(!0),$(""),b(null);try{const q={grantedTo:p==="user"?{userId:y.trim()}:{teamId:C.trim()},permission:j};h.trim()&&(q.expiresAt=h.trim());const he=await u(q);b(`${window.location.origin}/code/s/${he.shareToken}`)}catch(q){$(q instanceof Error?q.message:"Failed to create share")}finally{I(!1)}},ee=async q=>{try{await f(q)}catch{}},J=async()=>{if(!T)return;L(!1);try{if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(T),v(!0),setTimeout(()=>v(!1),2e3);return}}catch{}const q=document.createElement("textarea");q.value=T,q.style.position="fixed",q.style.opacity="0",document.body.appendChild(q),q.select();try{document.execCommand("copy"),v(!0),setTimeout(()=>v(!1),2e3)}catch{L(!0)}document.body.removeChild(q)};return e.jsx(me,{open:r,onOpenChange:q=>{q||t()},children:e.jsxs(xe,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(fe,{children:e.jsxs(pe,{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(Kn,{onSelect:k,placeholder:c("share.userIdPlaceholder"),actionLabel:c("share.selectUser")}):e.jsx("input",{type:"text",value:C,onChange:q=>_(q.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:q=>m(q.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:q=>w(q.target.value),className:"w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary focus:border-brand focus:outline-none"})]}),(E||i)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:E||i}),T&&e.jsxs("div",{className:"rounded-md bg-surface-2 px-3 py-2",children:[e.jsx("p",{className:"text-sm text-text-secondary mb-1",children: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:T}),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:R?c("share.copied"):c("share.copy")})]}),O&&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(q=>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:q.granted_to_user||q.granted_to_team||"Unknown"}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[q.permission==="write"?c("share.permissionWrite"):c("share.permissionRead"),q.expires_at?` · expires ${q.expires_at}`:""]})]}),e.jsx("button",{onClick:()=>ee(q.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")})]},q.id))})]})]}),e.jsxs(On,{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:Y,disabled:S||(p==="user"?!y.trim():!C.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:S?c("common.creating"):c("share.createShare")})]})]})})}function Vr(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 Gr(r){return r?new Date(r).toLocaleString():""}function Yr({open:r,onClose:t,adapter:s,onResume:n}){const a=Z(),[d,i]=l.useState([]),[u,f]=l.useState(!1),[p,g]=l.useState("");l.useEffect(()=>{if(!r)return;let k=!1;return f(!0),g(""),i([]),s.listResumableSessions().then(C=>{k||i(C)}).catch(C=>{k||g(C instanceof Error?C.message:String(C))}).finally(()=>{k||f(!1)}),()=>{k=!0}},[r,s]);const y=l.useMemo(()=>Vr(d),[d,a]);return e.jsx(me,{open:r,onOpenChange:k=>{k||t()},children:e.jsxs(xe,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(fe,{children:e.jsx(pe,{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(k=>e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-xs font-medium text-text-muted",children:k.label}),e.jsx("div",{className:"space-y-1",children:k.items.map(C=>e.jsxs("button",{type:"button",onClick:()=>n(C),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:C.title}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[Gr(C.modified),C.gitBranch?` · ${C.gitBranch}`:""]})]},C.sessionId))})]},k.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 Jr{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 Jr(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 Xr(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 Zr(r,t=js()){if(!t||!r)return null;try{const s=t.getItem(bs+r);return s?Xr(JSON.parse(s)):null}catch{return null}}function ea(r,t,s=js()){if(!(!s||!r))try{s.setItem(bs+r,JSON.stringify(t))}catch{}}function ta(r){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/acp/relay/${r}`}function sa(r){const t=ta(r),s=kn(),n=s?{proxyUrl:t,token:s}:{proxyUrl:t};return new wn(n)}const de=[{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 ue(r){return r<1e3?String(r):r<1e6?`${(r/1e3).toFixed(1)}k`:`${(r/1e6).toFixed(1)}M`}function na(r){const t=de.findIndex(s=>s.value===r);return de[(t+1+de.length)%de.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 ra(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 aa({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(qn,{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(Te,{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 oa({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(Jn,{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(Te,{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 ia=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 la({usage:r}){const t=Math.min(100,Math.max(0,r.percentage)),s=t>=80,n=(r.categories??[]).filter(u=>!u.isDeferred&&!ia.has(u.name)),a=(r.categories??[]).filter(u=>u.isDeferred),d=n.reduce((u,f)=>u+f.tokens,0),i=[`${K("session.context.tooltip",{used:ue(r.totalTokens),max:ue(r.rawMaxTokens)})}${r.model?` · ${r.model}`:""}`,...n.slice(0,8).map(u=>`${u.name}: ${ue(u.tokens)}`),...a.slice(0,3).map(u=>`${u.name}${c("session.context.deferredSuffix")}: ${ue(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 ca({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(Dn,{models:r,currentModelId:t,onSelect:f,showSearch:r.length>5})})]})}function da({mode:r,onModeChange:t,disabled:s}){const[n,a]=l.useState(!1),d=de.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($n,{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:de.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(Te,{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 Sa({sessionId:r,onBack:t}){var Rt;Z();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),[k,C]=l.useState(!1),[_,j]=l.useState(!1),[m,h]=l.useState(!1),[w,S]=l.useState(!1),[I,T]=l.useState(""),[b,E]=l.useState(0),$=l.useRef(null),[R,v]=l.useState({text:"",nonce:0}),[O,L]=l.useState(!1),[Y,ee]=l.useState(!1),[J,q]=l.useState(!1),[he,mt]=l.useState(0),[ws,ks]=l.useState(0),[ge,te]=l.useState([]),[X,ye]=l.useState(!1),[be,ie]=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(()=>Zr(r)),[Ve,Ge]=l.useState(!0),[je,Cs]=l.useState(null),[Ts,Es]=l.useState(null),[Me,pt]=l.useState(null),[Ae,Re]=l.useState([]),[Ms,Ye]=l.useState(!1),[Je,ht]=l.useState(""),Xe=l.useRef(null),[Ie,As]=l.useState(()=>localStorage.getItem(rs)||"default"),[gt,yt]=l.useState(null),we=l.useRef(null),[bt,jt]=l.useState(null),ke=l.useRef(null),re=l.useRef(null),wt=l.useRef(ge);wt.current=ge;const $e=l.useRef(null);$e.current||($e.current=new Qn(zn()));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 ae=l.useCallback(o=>{yt(o),we.current&&clearTimeout(we.current),we.current=setTimeout(()=>yt(null),5e3)},[]),se=l.useCallback(o=>{jt(o),ke.current&&clearTimeout(ke.current),ke.current=setTimeout(()=>jt(null),5e3)},[]),De=lt({value:Ie,apply:o=>{As(o);try{localStorage.setItem(rs,o)}catch{}},send:o=>{const x=re.current;return x?x.setPermissionMode(o):Promise.reject(new Error("adapter not ready"))},onError:(o,x)=>{console.error("[SessionDetail] set permission mode failed:",o),ae(x==="send"?K("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 M;const x=re.current;if(!x)return Promise.reject(new Error("adapter not ready"));const N=((M=Ke.find(D=>D.value===o))==null?void 0:M.tokens)??null;return x.setThinkingBudget(N)},onError:(o,x)=>{console.error("[SessionDetail] set thinking budget failed:",o),ae(x==="send"?K("session.thinking.failedRequest",{message:o}):o||c("session.thinking.failed"))}}),P=l.useMemo(()=>new jr(r,te,{onStatusChange:o=>{var x;d(o),ye(o==="running"||o==="requires_action"),(x=$e.current)==null||x.onStatus(o,kt.current)},onError:o=>{console.error("[RCSChatAdapter] error:",o)},onPermissionRequest:o=>{ie(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)},onTurnStart:o=>{Es(o)},onElicitationRequest:o=>{pt(o)}}),[r,ae]);l.useEffect(()=>(re.current=P,()=>{P.disconnect()}),[P]);const F=l.useMemo(()=>ra(W),[W]),vt=l.useRef(!1);l.useEffect(()=>{var N;if(!F.set_max_thinking_tokens||vt.current)return;const o=re.current;if(!o)return;const x=((N=Ke.find(M=>M.value===Ee))==null?void 0:N.tokens)??null;o.setThinkingBudget(x).then(()=>{vt.current=!0}).catch(M=>console.error("[SessionDetail] reconcile thinking budget failed:",M))},[F.set_max_thinking_tokens,Ee,W]);const Nt=F.stop_task?o=>{P.stopSubagent(o).then(x=>{x.ok||se(x.error||c("session.stopTask.failed"))})}:void 0,Rs=Z(),tt=l.useMemo(()=>vn((W==null?void 0:W.commands)??[],(W==null?void 0:W.skills)??[]),[W,Rs]),ve=l.useMemo(()=>Nn(ge,I),[ge,I]),Is=l.useCallback(o=>et.set(o),[et]),[_t,$s]=l.useState(()=>localStorage.getItem(ls)||"auto"),Ds=lt({value:_t,apply:o=>{$s(o);try{localStorage.setItem(ls,o)}catch{}},send:o=>{var M;const x=re.current;if(!x)return Promise.reject(new Error("adapter not ready"));const N=(M=ut.find(D=>D.value===o))==null?void 0:M.effort;return x.setEffort(N)},onError:(o,x)=>{console.error("[SessionDetail] set effort failed:",o),ae(x==="send"?K("session.effort.failedRequest",{message:o}):o||c("session.effort.failed"))}}),st=l.useCallback(()=>{var o;F.get_context_usage&&((o=re.current)==null||o.getContextUsage().then(x=>{x&&(ft(x),ea(r,x))}).catch(()=>{}).finally(()=>Ge(!1)))},[F,r]);l.useEffect(()=>{if(!F.get_context_usage)return;st();const o=setInterval(st,6e4);return()=>clearInterval(o)},[F,X,st]),l.useEffect(()=>{W&&!F.get_context_usage&&Ge(!1)},[W,F]),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(()=>ce.onEvent(x=>{x.type!=="artifact_created"&&x.type!=="artifact_updated"||(St.current&&ks(N=>N+1),mt(N=>N+1))}),[]);const[Ne,qs]=l.useState("idle");l.useEffect(()=>ce.onStateChange(x=>qs(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)&&P.markClosed(),ye(N.status==="running"||N.status==="requires_action")}catch(N){if(o)return;u(N instanceof Error?N.message:c("session.loadFailed"));return}try{await P.init()}catch(N){console.warn("Failed to init adapter:",N)}}return x(),()=>{o=!0}},[r,P]);const U=Ue(a),Ct=l.useRef(a);Ct.current=a,l.useEffect(()=>{if(U)return;let o=!1;const N=setInterval(async()=>{try{const M=await Ut(r);if(o||M.status===Ct.current)return;Ue(M.status)&&P.markClosed(),d(M.status),ye(M.status==="running"||M.status==="requires_action")}catch{}},6e4);return()=>{o=!0,clearInterval(N)}},[r,U,P]);const B=(s==null?void 0:s.access_level)==="read",Tt=Ss??(Ve&&!U&&!B?ns():null),nt=l.useCallback(()=>{te([]),ft(ns()),Pt(r).catch(o=>{console.warn("[SessionDetail] Failed to clear session history:",o)})},[r]),_e=l.useCallback(async(o,x)=>{const N=re.current;if(!N||U)return;if(o.sessionId===r){te(D=>[...D,{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 M=(D,H="default")=>te(oe=>[...oe,{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:D,variant:H}]);M(K("session.resume.restoring",{title:o.title??""}));try{await Pt(r),te([]);const D=await N.resumeSession(o.sessionId);M(D.title?K("session.resume.restoredWithTitle",{count:D.messageCount,title:D.title}):K("session.resume.restored",{count:D.messageCount}))}catch(D){M(K("session.resume.failed",{message:D instanceof Error?D.message:String(D)}),"error")}},[U,r]),Ps=l.useCallback(async()=>{if(s!=null&&s.environment_id)try{const o=await _n({environment_id:s.environment_id});window.location.href=`/code/${o.id}?resumeFrom=${r}`}catch(o){se(K("session.createFailedWithReason",{message:o instanceof Error?o.message:String(o)}))}},[s,r,se]),Os=l.useRef(new URLSearchParams(window.location.search).get("resumeFrom")),Et=l.useRef(!1);l.useEffect(()=>{const o=Os.current;!o||Et.current||!W||!F.resume||(Et.current=!0,window.history.replaceState({},"",window.location.pathname),_e({sessionId:o,title:o.slice(0,8),modified:0},null))},[W,F.resume,_e]);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||U)return;const M=/^\/resume(?:\s+(.*))?$/.exec(x);if(M){const H=(M[1]??"").trim();if(!F.resume){te(oe=>[...oe,{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 _e({sessionId:H,title:H,modified:0},x):h(!0);return}const D=await Sn(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(oe=>oe&&{...oe,currentModelId:H})},onNewSession:()=>{te([])}}).catch(()=>null);if(D){if(Fe("[SessionDetail] local command result",D),"clearEntries"in D&&D.clearEntries){nt();return}if("newSession"in D&&D.newSession){nt();return}if("userEntry"in D){te(H=>[...H,D.userEntry,D.cmdEntry]);return}}ye(!0);try{await P.sendMessage(x,o.images,o.attachments)}catch(H){if(console.error("Send failed:",H),H instanceof Cn&&H.type==="session_closed"){d("archived"),P.markClosed(),se(c("session.closedSendBlocked"));return}se(`${c("session.sendFailed")}${H instanceof Error?`: ${H.message}`:""}`)}},[P,U,r,z,tt,nt,se,_e,F]),Us=l.useCallback(o=>{if(X){Re(x=>[...x,o]);return}qe(o)},[X,qe]),rt=l.useRef(!1);l.useEffect(()=>{if(U){Re(x=>x.length>0?[]:x);return}if(X||Ae.length===0||rt.current)return;const o=Ae[0];o&&(rt.current=!0,Re(x=>x.slice(1)),qe(o).finally(()=>{rt.current=!1}))},[X,Ae,qe,U]);const Fs=l.useCallback((o,x)=>{if(X)return;const N=x==="edit"?c("session.rewind.confirmEdit"):c("session.rewind.confirm");window.confirm(`${N}
|
|
78
|
-
${c("session.rewind.confirmBody")}`)&&P.rewindToMessage(o.id).then(()=>{x==="edit"&&o.content&&v(M=>({text:o.content,nonce:M.nonce+1}))}).catch(M=>{console.error("[SessionDetail] rewind failed:",M),se(K("session.rewind.failed",{message:M instanceof Error?M.message:String(M)}))})},[X,se]),Ks=l.useCallback(o=>{const x=ve.orderedMatchIds;if(x.length===0)return;const N=(o%x.length+x.length)%x.length;E(N);const M=x[N],D=document.querySelector(`[data-entry-id="${CSS.escape(M)}"]`);D==null||D.scrollIntoView({block:"center",behavior:"smooth"})},[ve]),Mt=l.useCallback(async()=>{try{await P.interrupt()}catch(o){console.error("Interrupt failed:",o)}finally{ye(!1)}},[P]),Ls=l.useCallback(()=>{Ze(na(Ie))},[Ze,Ie]);l.useEffect(()=>()=>{we.current&&clearTimeout(we.current),ke.current&&clearTimeout(ke.current)},[]);const Bs=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]),Hs=l.useCallback(async o=>{try{await P.respondPermission(o,!0)}catch(x){console.error("Failed to approve:",x)}ie(x=>x.filter(N=>N.requestId!==o))},[P]),Ws=l.useCallback(async(o,x)=>{try{await P.respondPermission(o,!0,{updated_permissions:x})}catch(N){console.error("Failed to approve with rules:",N)}ie(N=>N.filter(M=>M.requestId!==o))},[P]),Qs=l.useCallback(async(o,x)=>{const N=Me;if(pt(null),!!N)try{await P.respondElicitation(N.requestId,o,x)}catch(M){console.error("Failed to submit elicitation:",M)}},[Me,P]),zs=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]),At=l.useCallback(async()=>{const o=Je.trim();if(Ye(!1),!(!s||!o||o===s.title))try{const x=await Tn(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]),Vs=l.useCallback(async o=>{try{await P.respondPermission(o,!1)}catch(x){console.error("Failed to reject:",x)}ie(x=>x.filter(N=>N.requestId!==o))},[P]),Gs=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(M){console.error("Failed to submit answers:",M)}ie(M=>M.filter(D=>D.requestId!==o))},[r]),Ys=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(M){console.error("Failed to submit plan response:",M)}ie(M=>M.filter(D=>D.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(ma,{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:Ms?e.jsx("input",{ref:Xe,value:Je,onChange:o=>ht(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),At()):o.key==="Escape"&&(o.preventDefault(),Ye(!1))},onBlur:()=>void At(),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&&!U?e.jsx("button",{type:"button",onClick:zs,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(Wn,{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:()=>q(!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(En,{className:"h-3.5 w-3.5"}),he>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:he>9?"9+":he})]}),F.side_question&&!U&&!B&&e.jsx("button",{onClick:()=>j(!_),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${_?"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;S(o),o?setTimeout(()=>{var x;return(x=$.current)==null?void 0:x.focus()},0):(T(""),E(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"})}),F.mcp_management&&!U&&!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"})}),F.remote_settings&&!U&&!B&&e.jsx("button",{onClick:()=>C(!k),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${k?"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:()=>ee(!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(fr,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>L(!O),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(tr,{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"),be.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:be.length})]})]})})}),O&&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":(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")})," ",ds(s.created_at)]})]})})}),(Ne==="reconnecting"||Ne==="failed")&&e.jsxs("div",{className:`flex items-center justify-center gap-2 px-4 py-1.5 text-xs font-medium ${Ne==="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 ${Ne==="failed"?"bg-status-error":"animate-pulse bg-status-warning"}`}),Ne==="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(Hn,{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:I,onChange:o=>{T(o.target.value),E(0)},onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),Ks(I&&o.shiftKey?b-1:b+1)):o.key==="Escape"&&(o.preventDefault(),S(!1),T(""))},placeholder:c("session.search.placeholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"}),I.trim()&&e.jsx("span",{className:"flex-shrink-0 font-mono text-[10px] text-text-muted",children:ve.orderedMatchIds.length===0?c("session.search.noResults"):`${b+1}/${ve.orderedMatchIds.length}`})]})}),e.jsx(Mn,{entries:ge,isLoading:X,turnStartedAt:Ts,emptyTitle:c("session.emptyTitle"),emptyDescription:c("session.emptyDescription"),searchMatchIds:I.trim()?ve.matchIds:void 0,onRewindEntry:F.rewind&&!U&&!B&&!X?(o,x)=>Fs(o,x):void 0}),e.jsx(_r,{state:xt,onStopTask:Nt}),be.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:be.map(o=>e.jsx(ua,{request:o,onApprove:()=>Hs(o.requestId),onApproveAlways:o.suggestions&&o.suggestions.length>0?()=>Ws(o.requestId,o.suggestions??[]):void 0,onReject:()=>Vs(o.requestId),onSubmitAnswers:Gs,onSubmitPlan:Ys},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(Br,{request:Me,onSubmit:Qs})})}),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(da,{mode:Ie,onModeChange:Ze,disabled:U||B}),e.jsx(ca,{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:U||B}),F.set_max_thinking_tokens&&e.jsx(aa,{budget:Ee,onBudgetChange:Is,disabled:U||B}),F.set_effort&&e.jsx(oa,{effort:_t,onEffortChange:o=>Ds.set(o),disabled:U||B})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[Tt&&e.jsx(la,{usage:Tt}),je&&e.jsxs("span",{className:"text-[10px] text-text-muted font-mono",title:c("session.usage.total"),children:[ue(je.inputTokens)," in / ",ue(je.outputTokens)," out",je.totalCostUsd!=null&&` · $${je.totalCostUsd.toFixed(2)}`]})]})]}),U&&(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 Ps(),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(An,{onSubmit:Us,isLoading:X,onInterrupt:Mt,onCycleMode:Ls,disabled:U||B,placeholder:U?c("session.closed"):B?c("session.readOnly"):c("session.inputPlaceholder"),supportsAttachments:!0,commands:tt,queueWhileLoading:!0,queuedCount:Ae.length,onDequeue:o=>Re(x=>x.filter((N,M)=>M!==o)),onSearchFiles:F.file_search?o=>P.searchFiles(o):void 0,historyKey:r,draftOverride:R}),g&&e.jsx($r,{onClose:()=>y(!1),fetchServers:()=>P.getMcpServers(),onToggle:(o,x)=>P.toggleMcpServer(o,x),onReconnect:o=>P.reconnectMcpServer(o)}),k&&e.jsx(qr,{onClose:()=>C(!1),fetchSettings:()=>P.getRemoteSettings(),onApply:o=>P.applyFlagSettings(o)}),_&&e.jsx(Pr,{onClose:()=>j(!1),onAsk:o=>P.askSideQuestion(o)}),f&&s&&e.jsx(Tr,{onClose:()=>p(!1),session:s,liveStatus:a,pendingPermissions:be,subagentState:xt,onStopTask:Nt,onInterrupt:Mt,onDelete:Bs,onEndSession:F.end_session&&!U&&!B?async()=>{await P.endSession("ended from web"),await Ot(s.id),window.location.href="/code/"}:void 0}),e.jsx(zr,{open:Y,onClose:()=>ee(!1),sessionId:s.id,sessionTitle:s.title||void 0}),e.jsx(Yr,{open:m,onClose:()=>h(!1),adapter:P,onResume:o=>{h(!1),_e(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 ua({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(Ur,{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(Kr,{requestId:r.requestId,planContent:p,description:f,onSubmit:(g,y)=>d(r.requestId,g,y)})}return e.jsx(Or,{requestId:r.requestId,toolName:i,toolInput:u,description:f,suggestions:r.suggestions,onApprove:t,onApproveAlways:s,onReject:n})}function ma({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=sa(t);return p.setConnectionStateHandler((g,y)=>{d(g),u(y||null)}),f.current=p,n(p),p.connect().catch(g=>{g instanceof Rn||(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(In,{client:s,agentId:t})})]})})}export{Sa as SessionDetail};
|
|
75
|
+
${k}`})}}const f=u.length===1&&u[0].type==="text"?u[0].text||t:u.length>0?u:t;try{const g=de();this.postedUserUuids.add(g);const y=await ln(this.sessionId,{type:"user",uuid:g,content:t,message:{content:f}}),k=(p=y==null?void 0:y.event)==null?void 0:p.id;k&&this.setEntries(C=>C.map(_=>_.type==="user_message"&&_.id===i.id?{..._,id:k}:_))}catch(g){throw this.setEntries(y=>y.filter(k=>!(k.type==="user_message"&&k.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 cn(this.sessionId)}async setPermissionMode(t){const s=de();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=de(),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=de();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=de();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 dn(this.sessionId,t)}async endSession(t){await G(this.sessionId,{type:"control_request",request_id:de(),request:{subtype:"end_session",...t?{reason:t}:{}}})}}function Cr(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 Z(),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(mn,{}),e.jsx(xn,{onSettingsClick:()=>{window.history.pushState(null,"","/settings"),window.dispatchEvent(new PopStateEvent("popstate"))}})]})})}const es="rcs:subagent-panel:collapsed";function Tr(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 Er(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 Mr({status:r}){return r==="running"?e.jsx(Ce,{className:"h-3 w-3 animate-spin text-brand-text"}):r==="completed"?e.jsx(fr,{className:"h-3 w-3 text-status-success"}):r==="failed"||r==="stopped"?e.jsx(pn,{className:"h-3 w-3 text-status-error"}):null}function ws({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=Er(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(Mr,{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:Tr(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(fn,{className:"h-3.5 w-3.5"})})]})}function Rr({state:r,onStopTask:t}){const[s,n]=l.useState(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(es)==="1"}catch{return!1}}),a=()=>{n(y=>{const k=!y;try{window.localStorage.setItem(es,k?"1":"0")}catch{}return k})},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(k=>k+1)},1e3);return()=>clearInterval(y)},[d,i]);const f=js(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(ps,{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(ws,{task:y,onStopTask:t},y.taskId))})]})})}function Ar(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 Ir(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)},[k,C]=l.useState(!1),_=async()=>{if(!(!f||k)&&window.confirm(c("task.endConfirm"))){C(!0);try{await f(),r()}catch{C(!1)}}},j=n.length,m=t.worker,h=t.work_item,w=t.environment;return e.jsx(xe,{open:!0,onOpenChange:S=>{S||r()},children:e.jsxs(fe,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-96 h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md overflow-y-auto",children:[e.jsx(pe,{children:e.jsx(he,{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(Ln,{className:"h-3.5 w-3.5"}),"Status"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(hn,{status:s||t.status||"unknown"}),e.jsx("span",{className:"text-xs text-text-muted",children:m&&(Ir(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(Pt,{className:"h-3 w-3"}),"Heartbeat"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:Ar(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(hs,{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(Pt,{className:"h-3 w-3"}),"Created"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:ms(t.created_at)})]})]})]}),e.jsx(Pr,{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(Ce,{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(gr,{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:_,disabled:k,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:k?"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(gn,{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(ar,{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 Dr={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"},qr=new Set(["dream"]);function Pr({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=js(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(cr,{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?K("task.mixedCount",{running:i,recent:u}):i>0?K("task.runningCount",{count:i}):K("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:vr(d).map(f=>{const p=!qr.has(f.taskType),g=Dr[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(ws,{task:y,onStopTask:t,fullText:!0},y.taskId))]},f.taskType)})})]})}const Or={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"},Ur={connected:"mcp.status.connected",failed:"mcp.status.failed","needs-auth":"mcp.status.needsAuth",pending:"mcp.status.pending",disabled:"mcp.status.disabled"};function Fr({onClose:r,fetchServers:t,onToggle:s,onReconnect:n}){Z();const[a,d]=l.useState(null),[i,u]=l.useState(null),[f,p]=l.useState(null),[g,y]=l.useState(null),k=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(()=>{k()},[k]);const C=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 k()}},_=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 k()}};return e.jsx(xe,{open:!0,onOpenChange:j=>{j||r()},children:e.jsxs(fe,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-96 h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md overflow-y-auto",children:[e.jsx(pe,{children:e.jsxs(he,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(ys,{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(Ce,{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 ${Or[j.status]}`,children:c(Ur[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&&` · ${K("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 _(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(Hn,{className:`h-3.5 w-3.5 ${h?"animate-spin":""}`})}),e.jsx("button",{type:"button",role:"switch","aria-checked":!w,onClick:()=>void C(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 Kr(r){if(r==null)return c("settings.unset");if(typeof r=="string")return r;try{return JSON.stringify(r)}catch{return String(r)}}function ts(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 Lr({onClose:r,fetchSettings:t,onApply:s}){Z();const[n,a]=l.useState(null),[d,i]=l.useState(null),[u,f]=l.useState(""),[p,g]=l.useState(null),[y,k]=l.useState(null),[C,_]=l.useState(null),[j,m]=l.useState(!1),h=l.useCallback(async()=>{g(null),k(null),_(null),m(!1);try{const v=await t();a(v),i(v?null:c("settings.loadFailed"))}catch(v){Fe("[SettingsDrawer] fetch failed",v),i(c("settings.loadFailed"))}},[t]);l.useEffect(()=>{h()},[h]);const w=l.useMemo(()=>n?Object.entries(n.effective).filter(([,v])=>v!==void 0).sort(([v],[O])=>v.localeCompare(O)):[],[n]),S=l.useMemo(()=>{const v=u.trim().toLowerCase();return v?w.filter(([O,L])=>`${O} ${Kr(L)}`.toLowerCase().includes(v)):w},[w,u]),I=v=>typeof v[1]=="boolean",T=l.useMemo(()=>S.filter(I),[S]),b=l.useMemo(()=>S.filter(v=>!I(v)),[S]),E=l.useMemo(()=>C===null?null:w.find(([v])=>v===C)??null,[w,C]),$=async()=>{if(E)try{await navigator.clipboard.writeText(ts(E[1])),m(!0),window.setTimeout(()=>m(!1),1500)}catch(v){Fe("[SettingsDrawer] copy failed",v)}},A=async(v,O)=>{g(v),k(null);try{const L=await s({[v]:!O});L.ok||k(L.error||c("settings.writeFailed"))}finally{await h()}};return e.jsx(xe,{open:!0,onOpenChange:v=>{v||r()},children:e.jsxs(fe,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-96 h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md overflow-y-auto",children:[e.jsx(pe,{children:e.jsxs(he,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(bs,{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(Ce,{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")})]}),E?e.jsxs("section",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>{_(null),m(!1)},className:"flex items-center gap-1.5 text-xs text-text-muted transition-colors hover:text-text-primary",children:[e.jsx(Wn,{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:E[0]}),e.jsx("pre",{className:"max-h-[60vh] overflow-y-auto whitespace-pre-wrap break-all rounded-md border border-border bg-surface-2 p-3 font-mono text-[10px] leading-relaxed text-text-secondary",children:ts(E[1])}),e.jsxs("button",{type:"button",onClick:()=>void $(),className:"flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs text-text-secondary transition-colors hover:bg-surface-2 hover:text-text-primary",children:[j?e.jsx(Te,{className:"h-3.5 w-3.5 text-status-success"}):e.jsx(zn,{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(dt,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{value:u,onChange:v=>f(v.target.value),placeholder:c("settings.searchPlaceholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"})]}),S.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:c("settings.noMatch")}),T.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-[10px] font-medium uppercase tracking-wide text-text-muted",children:K("settings.togglable",{n:T.length})}),T.map(([v,O])=>{const L=p===v;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-border bg-surface-2 px-3 py-2",children:[e.jsx("div",{className:"truncate font-mono text-xs text-text-primary",children:v}),e.jsx("button",{type:"button",role:"switch","aria-checked":O,disabled:L,onClick:()=>void A(v,O),className:`relative h-5 w-9 flex-shrink-0 rounded-full transition-colors disabled:opacity-50 ${O?"bg-brand":"bg-surface-3"}`,title:O?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 ${O?"left-4.5":"left-0.5"}`})})]},v)})]}),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:K("settings.readOnly",{n:b.length})}),b.map(([v])=>e.jsxs("button",{type:"button",onClick:()=>_(v),className:"flex w-full items-center justify-between gap-3 rounded-md border border-border bg-surface-2 px-3 py-2 text-left transition-colors hover:bg-surface-3",title:c("settings.viewDetail"),children:[e.jsx("span",{className:"truncate font-mono text-xs text-text-primary",children:v}),e.jsx(ps,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"})]},v))]})]})]})]})]})})}function Br({onClose:r,onAsk:t}){Z();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(k=>k.map(C=>C.id===g?{...C,answer:y??c("sideQuestion.noAnswer"),error:y===null}:C))}finally{u(!1)}};return e.jsx(xe,{open:!0,onOpenChange:p=>{p||r()},children:e.jsxs(fe,{showCloseButton:!1,className:"fixed inset-y-0 right-0 top-auto left-auto translate-x-0 translate-y-0 w-full sm:w-[26rem] h-full max-w-none max-h-none rounded-none border-l border-border bg-surface-1 p-4 sm:max-w-md flex flex-col",children:[e.jsx(pe,{children:e.jsxs(he,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(gs,{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(yn,{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(Ce,{className:"h-4 w-4 animate-spin"}):e.jsx(bn,{className:"h-4 w-4"})})]})]})})}const lt="focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface-1";function ss(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 Hr({requestId:r,toolName:t,toolInput:s,description:n,suggestions:a,onApprove:d,onApproveAlways:i,onReject:u}){Z();const f=s&&typeof s=="object"&&!Array.isArray(s)?s:{},p=jn(wn(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":K("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(kn,{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((k,C)=>e.jsx(vn,{filePath:k.filePath,oldString:k.oldString,newString:k.newString,label:k.label},C))}):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:Ot(g,500)})),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:d,className:ne("rounded-lg bg-approve px-4 py-2 text-sm font-medium font-display text-white hover:bg-approve-hover transition-colors",lt),children:c("permission.approve")}),y&&i&&e.jsxs("button",{onClick:i,className:ne("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",lt),title:c("permission.alwaysAllowHint").replace("{rule}",ss(t,a)),children:[e.jsx(kr,{className:"h-3.5 w-3.5"}),c("permission.alwaysAllow")," ",Ot(ss(t,a),40)]}),e.jsx("button",{onClick:u,className:ne("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",lt),children:c("permission.reject")})]})]})}function Wr({questions:r,description:t,onSubmit:s,onSkip:n}){const[a,d]=l.useState({}),[i,u]=l.useState({}),[f,p]=l.useState(0),g=(_,j,m)=>{if(m){const h=a[_]||[],w=h.includes(j)?h.filter(S=>S!==j):[...h,j];d({...a,[_]:w})}else d({...a,[_]:j})},y=_=>{var m;const j=(m=i[_])==null?void 0:m.trim();j&&(d({...a,[_]:j}),u({...i,[_]:""}))},k=()=>{var j,m;const _={};for(const[h,w]of Object.entries(a)){const S=r[parseInt(h,10)];S&&(typeof w=="number"?_[h]=((m=(j=S.options)==null?void 0:j[w])==null?void 0:m.label)||String(w):Array.isArray(w)?_[h]=w.map(I=>{var T,b;return((b=(T=S.options)==null?void 0:T[I])==null?void 0:b.label)||String(I)}):_[h]=w)}s(_)};if(r.length<=1){const _=r[0]||{question:t,options:[],multiSelect:!1},j=_.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||_.question||"Question")}),e.jsxs("div",{className:"space-y-2",children:[(_.options||[]).map((m,h)=>{const w=j?(a[0]||[]).includes(h):a[0]===h;return e.jsxs("button",{onClick:()=>g(0,h,j),className:ne("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:k,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 C=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((_,j)=>e.jsx("button",{onClick:()=>p(j),className:ne("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:_.header||`Q${j+1}`},j))}),C&&e.jsx(Qr,{question:C,qIdx:f,answers:a,otherTexts:i,onSelect:g,onOtherTextChange:(_,j)=>u({...i,[_]: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:k,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 Qr({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:ne("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 zr({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(Te,{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:Vr(r)}}),e.jsx("div",{className:"space-y-2",children:u?e.jsxs(e.Fragment,{children:[e.jsx(Se,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes"}),e.jsx(Se,{selected:n==="no",onClick:()=>a("no"),label:"No"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Se,{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(Se,{selected:n==="yes-default",onClick:()=>a("yes-default"),label:"Yes, manually approve edits",desc:"Approve plan but confirm each edit"}),e.jsx(Se,{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 Se({selected:r,onClick:t,label:s,desc:n}){return e.jsxs("button",{onClick:t,className:ne("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:ne("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 Vr(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 Gr({request:r,onSubmit:t}){Z();const s=Yr(r.requestedSchema),n=Jr(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(ns,{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(Vn,{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(ns,{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 ns({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(mr,{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 Yr(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 Jr(r){const t=r==null?void 0:r.required;return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function Xr(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 Nn(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 _n(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 Sn(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 Zr({open:r,onClose:t,sessionId:s,sessionTitle:n}){Z();const{shares:a,isLoading:d,error:i,createShare:u,revokeShare:f}=Xr(s),[p,g]=l.useState("user"),[y,k]=l.useState(""),[C,_]=l.useState(""),[j,m]=l.useState("read"),[h,w]=l.useState(""),[S,I]=l.useState(!1),[T,b]=l.useState(null),[E,$]=l.useState(""),[A,v]=l.useState(!1),[O,L]=l.useState(!1);l.useEffect(()=>{r&&(g("user"),k(""),_(""),m("read"),w(""),I(!1),b(null),$(""),v(!1),L(!1))},[r]);const Y=async()=>{I(!0),$(""),b(null);try{const q={grantedTo:p==="user"?{userId:y.trim()}:{teamId:C.trim()},permission:j};h.trim()&&(q.expiresAt=h.trim());const re=await u(q);b(`${window.location.origin}/code/s/${re.shareToken}`)}catch(q){$(q instanceof Error?q.message:"Failed to create share")}finally{I(!1)}},ee=async q=>{try{await f(q)}catch{}},J=async()=>{if(!T)return;L(!1);try{if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(T),v(!0),setTimeout(()=>v(!1),2e3);return}}catch{}const q=document.createElement("textarea");q.value=T,q.style.position="fixed",q.style.opacity="0",document.body.appendChild(q),q.select();try{document.execCommand("copy"),v(!0),setTimeout(()=>v(!1),2e3)}catch{L(!0)}document.body.removeChild(q)};return e.jsx(xe,{open:r,onOpenChange:q=>{q||t()},children:e.jsxs(fe,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(pe,{children:e.jsxs(he,{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(Qn,{onSelect:k,placeholder:c("share.userIdPlaceholder"),actionLabel:c("share.selectUser")}):e.jsx("input",{type:"text",value:C,onChange:q=>_(q.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:q=>m(q.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:q=>w(q.target.value),className:"w-full rounded-lg border border-border bg-surface-2 px-3 py-2 text-sm text-text-primary focus:border-brand focus:outline-none"})]}),(E||i)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:E||i}),T&&e.jsxs("div",{className:"rounded-md bg-surface-2 px-3 py-2",children:[e.jsx("p",{className:"text-sm text-text-secondary mb-1",children: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:T}),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:A?c("share.copied"):c("share.copy")})]}),O&&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(q=>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:q.granted_to_user||q.granted_to_team||"Unknown"}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[q.permission==="write"?c("share.permissionWrite"):c("share.permissionRead"),q.expires_at?` · expires ${q.expires_at}`:""]})]}),e.jsx("button",{onClick:()=>ee(q.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")})]},q.id))})]})]}),e.jsxs(Bn,{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:Y,disabled:S||(p==="user"?!y.trim():!C.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:S?c("common.creating"):c("share.createShare")})]})]})})}function ea(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 ta(r){return r?new Date(r).toLocaleString():""}function sa({open:r,onClose:t,adapter:s,onResume:n}){const a=Z(),[d,i]=l.useState([]),[u,f]=l.useState(!1),[p,g]=l.useState("");l.useEffect(()=>{if(!r)return;let k=!1;return f(!0),g(""),i([]),s.listResumableSessions().then(C=>{k||i(C)}).catch(C=>{k||g(C instanceof Error?C.message:String(C))}).finally(()=>{k||f(!1)}),()=>{k=!0}},[r,s]);const y=l.useMemo(()=>ea(d),[d,a]);return e.jsx(xe,{open:r,onOpenChange:k=>{k||t()},children:e.jsxs(fe,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(pe,{children:e.jsx(he,{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(k=>e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-xs font-medium text-text-muted",children:k.label}),e.jsx("div",{className:"space-y-1",children:k.items.map(C=>e.jsxs("button",{type:"button",onClick:()=>n(C),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:C.title}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[ta(C.modified),C.gitBranch?` · ${C.gitBranch}`:""]})]},C.sessionId))})]},k.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 na{constructor(t,s,n,a){R(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,rs(n),"send")})}catch(n){this.rollback(s,rs(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 rs(r){return r instanceof Error?r.message:String(r)}function ct(r){const t=l.useRef(r);t.current=r;const s=l.useRef(null);s.current||(s.current=new na(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 ks="rcs_context_usage_";function vs(){try{if(typeof localStorage<"u")return localStorage}catch{}return null}function as(){return{totalTokens:0,rawMaxTokens:0,percentage:0}}function ra(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 aa(r,t=vs()){if(!t||!r)return null;try{const s=t.getItem(ks+r);return s?ra(JSON.parse(s)):null}catch{return null}}function oa(r,t,s=vs()){if(!(!s||!r))try{s.setItem(ks+r,JSON.stringify(t))}catch{}}function ia(r){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/acp/relay/${r}`}function la(r){const t=ia(r),s=Tn(),n=s?{proxyUrl:t,token:s}:{proxyUrl:t};return new Cn(n)}const ue=[{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"}],os="rcs_permission_mode";function me(r){return r<1e3?String(r):r<1e6?`${(r/1e3).toFixed(1)}k`:`${(r/1e6).toFixed(1)}M`}function ca(r){const t=ue.findIndex(s=>s.value===r);return ue[(t+1+ue.length)%ue.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}],is="rcs_thinking_budget",mt=[{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"}],ls=r=>r.labelKey?c(r.labelKey):r.label,cs=r=>r.labelKey?c(r.labelKey):r.label,ds="rcs_effort";function da(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 ua({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(fs,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?cs(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(Te,{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:cs(i)}),e.jsx("div",{className:"text-xs text-text-muted",children:i.descKey?c(i.descKey):i.description})]})]},i.value))})]})}function ma({effort:r,onEffortChange:t,disabled:s}){const[n,a]=l.useState(!1),d=mt.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(nr,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:d?ls(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:mt.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(Te,{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:ls(i)}),e.jsx("div",{className:"text-xs text-text-muted",children:c(i.descKey)})]})]},i.value))})]})}const xa=new Set(["Free space","Autocompact buffer","Compact buffer"]),us=["bg-brand","bg-status-active","bg-status-success","bg-violet-500","bg-amber-500","bg-pink-500","bg-teal-500"];function fa({usage:r}){const t=Math.min(100,Math.max(0,r.percentage)),s=t>=80,n=(r.categories??[]).filter(u=>!u.isDeferred&&!xa.has(u.name)),a=(r.categories??[]).filter(u=>u.isDeferred),d=n.reduce((u,f)=>u+f.tokens,0),i=[`${K("session.context.tooltip",{used:me(r.totalTokens),max:me(r.rawMaxTokens)})}${r.model?` · ${r.model}`:""}`,...n.slice(0,8).map(u=>`${u.name}: ${me(u.tokens)}`),...a.slice(0,3).map(u=>`${u.name}${c("session.context.deferredSuffix")}: ${me(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":us[f%us.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 pa({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(hs,{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(Kn,{models:r,currentModelId:t,onSelect:f,showSearch:r.length>5})})]})}function ha({mode:r,onModeChange:t,disabled:s}){const[n,a]=l.useState(!1),d=ue.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(Fn,{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:ue.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(Te,{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 Ia({sessionId:r,onBack:t}){var $t;Z();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),[k,C]=l.useState(!1),[_,j]=l.useState(!1),[m,h]=l.useState(!1),[w,S]=l.useState(!1),[I,T]=l.useState(""),[b,E]=l.useState(0),$=l.useRef(null),[A,v]=l.useState({text:"",nonce:0}),[O,L]=l.useState(!1),[Y,ee]=l.useState(!1),[J,q]=l.useState(!1),[re,Ns]=l.useState(!1),[ze,xt]=l.useState(0),[_s,Ss]=l.useState(0),[ge,te]=l.useState([]),[X,ye]=l.useState(!1),[be,ce]=l.useState([]),[z,Ve]=l.useState(null),[ft,Cs]=l.useState(()=>ut()),[W,Ts]=l.useState(null),[Ee,Es]=l.useState(()=>localStorage.getItem(is)||"off"),[Ms,pt]=l.useState(()=>aa(r)),[Ge,Ye]=l.useState(!0),[je,Rs]=l.useState(null),[As,Is]=l.useState(null),[Me,ht]=l.useState(null),[Re,Ae]=l.useState([]),[$s,Je]=l.useState(!1),[Xe,gt]=l.useState(""),Ze=l.useRef(null),[Ie,Ds]=l.useState(()=>localStorage.getItem(os)||"default"),[yt,bt]=l.useState(null),we=l.useRef(null),[jt,wt]=l.useState(null),ke=l.useRef(null),ae=l.useRef(null),kt=l.useRef(ge);kt.current=ge;const $e=l.useRef(null);$e.current||($e.current=new Xn(Zn()));const vt=l.useRef(r);vt.current=(s==null?void 0:s.title)||r,l.useEffect(()=>{var o;(o=$e.current)==null||o.reset()},[r]);const oe=l.useCallback(o=>{bt(o),we.current&&clearTimeout(we.current),we.current=setTimeout(()=>bt(null),5e3)},[]),se=l.useCallback(o=>{wt(o),ke.current&&clearTimeout(ke.current),ke.current=setTimeout(()=>wt(null),5e3)},[]),De=ct({value:Ie,apply:o=>{Ds(o);try{localStorage.setItem(os,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),oe(x==="send"?K("session.mode.switchFailedRequest",{message:o}):o||c("session.mode.switchFailed"))}}),et=l.useCallback(o=>De.set(o),[De]),tt=ct({value:Ee,apply:o=>{Es(o);try{localStorage.setItem(is,o)}catch{}},send:o=>{var M;const x=ae.current;if(!x)return Promise.reject(new Error("adapter not ready"));const N=((M=Ke.find(D=>D.value===o))==null?void 0:M.tokens)??null;return x.setThinkingBudget(N)},onError:(o,x)=>{console.error("[SessionDetail] set thinking budget failed:",o),oe(x==="send"?K("session.thinking.failedRequest",{message:o}):o||c("session.thinking.failed"))}}),P=l.useMemo(()=>new Sr(r,te,{onStatusChange:o=>{var x;d(o),ye(o==="running"||o==="requires_action"),(x=$e.current)==null||x.onStatus(o,vt.current)},onError:o=>{console.error("[RCSChatAdapter] error:",o)},onPermissionRequest:o=>{ce(x=>x.some(N=>N.requestId===o.requestId)?x:[...x,o])},onModelsStateChange:o=>{Ve(o)},onSubagentUpdate:o=>{Cs(o)},onControlResponse:o=>{tt.handleControlResponse(o)||De.handleControlResponse(o)},onPermissionModeChange:o=>{De.sync(o)},onUsageChange:o=>{Rs(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=>{Ts(x=>JSON.stringify(x)===JSON.stringify(o)?x:o)},onTurnStart:o=>{Is(o)},onElicitationRequest:o=>{ht(o)}}),[r,oe]);l.useEffect(()=>(ae.current=P,()=>{P.disconnect()}),[P]);const F=l.useMemo(()=>da(W),[W]),Nt=l.useRef(!1);l.useEffect(()=>{var N;if(!F.set_max_thinking_tokens||Nt.current)return;const o=ae.current;if(!o)return;const x=((N=Ke.find(M=>M.value===Ee))==null?void 0:N.tokens)??null;o.setThinkingBudget(x).then(()=>{Nt.current=!0}).catch(M=>console.error("[SessionDetail] reconcile thinking budget failed:",M))},[F.set_max_thinking_tokens,Ee,W]);const _t=F.stop_task?o=>{P.stopSubagent(o).then(x=>{x.ok||se(x.error||c("session.stopTask.failed"))})}:void 0,qs=Z(),st=l.useMemo(()=>En((W==null?void 0:W.commands)??[],(W==null?void 0:W.skills)??[]),[W,qs]),ve=l.useMemo(()=>Mn(ge,I),[ge,I]),Ps=l.useCallback(o=>tt.set(o),[tt]),[St,Os]=l.useState(()=>localStorage.getItem(ds)||"auto"),Us=ct({value:St,apply:o=>{Os(o);try{localStorage.setItem(ds,o)}catch{}},send:o=>{var M;const x=ae.current;if(!x)return Promise.reject(new Error("adapter not ready"));const N=(M=mt.find(D=>D.value===o))==null?void 0:M.effort;return x.setEffort(N)},onError:(o,x)=>{console.error("[SessionDetail] set effort failed:",o),oe(x==="send"?K("session.effort.failedRequest",{message:o}):o||c("session.effort.failed"))}}),nt=l.useCallback(()=>{var o;F.get_context_usage&&((o=ae.current)==null||o.getContextUsage().then(x=>{x&&(pt(x),oa(r,x))}).catch(()=>{}).finally(()=>Ye(!1)))},[F,r]);l.useEffect(()=>{if(!F.get_context_usage)return;nt();const o=setInterval(nt,6e4);return()=>clearInterval(o)},[F,X,nt]),l.useEffect(()=>{W&&!F.get_context_usage&&Ye(!1)},[W,F]),l.useEffect(()=>{if(!Ge)return;const o=setTimeout(()=>Ye(!1),1e4);return()=>clearTimeout(o)},[Ge]);const Ct=l.useRef(J);Ct.current=J,l.useEffect(()=>le.onEvent(x=>{x.type!=="artifact_created"&&x.type!=="artifact_updated"||(Ct.current&&Ss(N=>N+1),xt(N=>N+1))}),[]);const[Fs,Ks]=l.useState(0),Tt=l.useRef(re);Tt.current=re,l.useEffect(()=>le.onEvent(x=>{x.type==="memory_synced"&&Tt.current&&Ks(N=>N+1)}),[]);const[Ne,Ls]=l.useState("idle");l.useEffect(()=>le.onStateChange(x=>Ls(x)),[]),l.useEffect(()=>{J&&xt(0)},[J]),l.useEffect(()=>{let o=!1;async function x(){u("");try{const N=await Kt(r);if(o)return;n(N),d(N.status),Ue(N.status)&&P.markClosed(),ye(N.status==="running"||N.status==="requires_action")}catch(N){if(o)return;u(N instanceof Error?N.message:c("session.loadFailed"));return}try{await P.init()}catch(N){console.warn("Failed to init adapter:",N)}}return x(),()=>{o=!0}},[r,P]);const U=Ue(a),Et=l.useRef(a);Et.current=a,l.useEffect(()=>{if(U)return;let o=!1;const N=setInterval(async()=>{try{const M=await Kt(r);if(o||M.status===Et.current)return;Ue(M.status)&&P.markClosed(),d(M.status),ye(M.status==="running"||M.status==="requires_action")}catch{}},6e4);return()=>{o=!0,clearInterval(N)}},[r,U,P]);const B=(s==null?void 0:s.access_level)==="read",Mt=Ms??(Ge&&!U&&!B?as():null),rt=l.useCallback(()=>{te([]),pt(as()),Ut(r).catch(o=>{console.warn("[SessionDetail] Failed to clear session history:",o)})},[r]),_e=l.useCallback(async(o,x)=>{const N=ae.current;if(!N||U)return;if(o.sessionId===r){te(D=>[...D,{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 M=(D,H="default")=>te(ie=>[...ie,{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:D,variant:H}]);M(K("session.resume.restoring",{title:o.title??""}));try{await Ut(r),te([]);const D=await N.resumeSession(o.sessionId);M(D.title?K("session.resume.restoredWithTitle",{count:D.messageCount,title:D.title}):K("session.resume.restored",{count:D.messageCount}))}catch(D){M(K("session.resume.failed",{message:D instanceof Error?D.message:String(D)}),"error")}},[U,r]),Bs=l.useCallback(async()=>{if(s!=null&&s.environment_id)try{const o=await Rn({environment_id:s.environment_id});window.location.href=`/code/${o.id}?resumeFrom=${r}`}catch(o){se(K("session.createFailedWithReason",{message:o instanceof Error?o.message:String(o)}))}},[s,r,se]),Hs=l.useRef(new URLSearchParams(window.location.search).get("resumeFrom")),Rt=l.useRef(!1);l.useEffect(()=>{const o=Hs.current;!o||Rt.current||!W||!F.resume||(Rt.current=!0,window.history.replaceState({},"",window.location.pathname),_e({sessionId:o,title:o.slice(0,8),modified:0},null))},[W,F.resume,_e]);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||U)return;const M=/^\/resume(?:\s+(.*))?$/.exec(x);if(M){const H=(M[1]??"").trim();if(!F.resume){te(ie=>[...ie,{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 _e({sessionId:H,title:H,modified:0},x):h(!0);return}const D=await An(x,{sessionId:r,availableCommands:st,availableModels:(z==null?void 0:z.availableModels)??[],currentModel:z?{modelId:z.currentModelId,name:z.currentModelId}:null,supportsImages:!0,entries:kt.current,setModel:async H=>{await G(r,{type:"control_request",request:{subtype:"set_model",model:H}}),Ve(ie=>ie&&{...ie,currentModelId:H})},onNewSession:()=>{te([])}}).catch(()=>null);if(D){if(Fe("[SessionDetail] local command result",D),"clearEntries"in D&&D.clearEntries){rt();return}if("newSession"in D&&D.newSession){rt();return}if("userEntry"in D){te(H=>[...H,D.userEntry,D.cmdEntry]);return}}ye(!0);try{await P.sendMessage(x,o.images,o.attachments)}catch(H){if(console.error("Send failed:",H),H instanceof In&&H.type==="session_closed"){d("archived"),P.markClosed(),se(c("session.closedSendBlocked"));return}se(`${c("session.sendFailed")}${H instanceof Error?`: ${H.message}`:""}`)}},[P,U,r,z,st,rt,se,_e,F]),Ws=l.useCallback(o=>{if(X){Ae(x=>[...x,o]);return}qe(o)},[X,qe]),at=l.useRef(!1);l.useEffect(()=>{if(U){Ae(x=>x.length>0?[]:x);return}if(X||Re.length===0||at.current)return;const o=Re[0];o&&(at.current=!0,Ae(x=>x.slice(1)),qe(o).finally(()=>{at.current=!1}))},[X,Re,qe,U]);const Qs=l.useCallback((o,x)=>{if(X)return;const N=x==="edit"?c("session.rewind.confirmEdit"):c("session.rewind.confirm");window.confirm(`${N}
|
|
78
|
+
${c("session.rewind.confirmBody")}`)&&P.rewindToMessage(o.id).then(()=>{x==="edit"&&o.content&&v(M=>({text:o.content,nonce:M.nonce+1}))}).catch(M=>{console.error("[SessionDetail] rewind failed:",M),se(K("session.rewind.failed",{message:M instanceof Error?M.message:String(M)}))})},[X,se]),zs=l.useCallback(o=>{const x=ve.orderedMatchIds;if(x.length===0)return;const N=(o%x.length+x.length)%x.length;E(N);const M=x[N],D=document.querySelector(`[data-entry-id="${CSS.escape(M)}"]`);D==null||D.scrollIntoView({block:"center",behavior:"smooth"})},[ve]),At=l.useCallback(async()=>{try{await P.interrupt()}catch(o){console.error("Interrupt failed:",o)}finally{ye(!1)}},[P]),Vs=l.useCallback(()=>{et(ca(Ie))},[et,Ie]);l.useEffect(()=>()=>{we.current&&clearTimeout(we.current),ke.current&&clearTimeout(ke.current)},[]);const Gs=l.useCallback(async()=>{if(s&&window.confirm(c("dashboard.confirmDelete").replace("{id}",s.title||s.id)))try{await Ft(s.id),window.location.href="/code/"}catch(o){alert(o instanceof Error?o.message:c("dashboard.deleteFailed"))}},[s]),Ys=l.useCallback(async o=>{try{await P.respondPermission(o,!0)}catch(x){console.error("Failed to approve:",x)}ce(x=>x.filter(N=>N.requestId!==o))},[P]),Js=l.useCallback(async(o,x)=>{try{await P.respondPermission(o,!0,{updated_permissions:x})}catch(N){console.error("Failed to approve with rules:",N)}ce(N=>N.filter(M=>M.requestId!==o))},[P]),Xs=l.useCallback(async(o,x)=>{const N=Me;if(ht(null),!!N)try{await P.respondElicitation(N.requestId,o,x)}catch(M){console.error("Failed to submit elicitation:",M)}},[Me,P]),Zs=l.useCallback(()=>{!s||B||(gt(s.title||""),Je(!0),setTimeout(()=>{var o,x;(o=Ze.current)==null||o.focus(),(x=Ze.current)==null||x.select()},0))},[s,B]),It=l.useCallback(async()=>{const o=Xe.trim();if(Je(!1),!(!s||!o||o===s.title))try{const x=await $n(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,Xe]),en=l.useCallback(async o=>{try{await P.respondPermission(o,!1)}catch(x){console.error("Failed to reject:",x)}ce(x=>x.filter(N=>N.requestId!==o))},[P]),tn=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(M){console.error("Failed to submit answers:",M)}ce(M=>M.filter(D=>D.requestId!==o))},[r]),sn=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(M){console.error("Failed to submit plan response:",M)}ce(M=>M.filter(D=>D.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(ya,{sessionId:r,agentId:s.environment_id})]}):e.jsx(xs,{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:$s?e.jsx("input",{ref:Ze,value:Xe,onChange:o=>gt(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),It()):o.key==="Escape"&&(o.preventDefault(),Je(!1))},onBlur:()=>void It(),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&&!U?e.jsx("button",{type:"button",onClick:Zs,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(Yn,{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=Lt(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:()=>q(!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(Dn,{className:"h-3.5 w-3.5"}),ze>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:ze>9?"9+":ze})]}),e.jsx("button",{onClick:()=>Ns(!re),className:`flex h-7 w-7 items-center justify-center rounded-md transition-colors ${re?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:c("memories.title"),children:e.jsx(fs,{className:"h-3.5 w-3.5"})}),F.side_question&&!U&&!B&&e.jsx("button",{onClick:()=>j(!_),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${_?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:c("session.sideQuestion.title"),children:e.jsx(gs,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>{const o=!w;S(o),o?setTimeout(()=>{var x;return(x=$.current)==null?void 0:x.focus()},0):(T(""),E(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(dt,{className:"h-3.5 w-3.5"})}),F.mcp_management&&!U&&!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(ys,{className:"h-3.5 w-3.5"})}),F.remote_settings&&!U&&!B&&e.jsx("button",{onClick:()=>C(!k),className:`hidden h-7 w-7 items-center justify-center rounded-md transition-colors sm:flex ${k?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:c("session.settings.title"),children:e.jsx(bs,{className:"h-3.5 w-3.5"})}),!B&&(s==null?void 0:s.access_level)!=="write"&&e.jsx("button",{onClick:()=>ee(!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(jr,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>L(!O),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(ir,{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"),be.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:be.length})]})]})})}),O&&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")})," ",Lt(s.source==="acp"?"acp":($t=s.environment)==null?void 0:$t.worker_type).fullLabel]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:c("session.metaCreated")})," ",ms(s.created_at)]})]})})}),(Ne==="reconnecting"||Ne==="failed")&&e.jsxs("div",{className:`flex items-center justify-center gap-2 px-4 py-1.5 text-xs font-medium ${Ne==="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 ${Ne==="failed"?"bg-status-error":"animate-pulse bg-status-warning"}`}),Ne==="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(Gn,{sessionId:r,embedded:!0,refreshTick:_s})})}),re&&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(Jn,{sessionId:r,embedded:!0,refreshTick:Fs})})}),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(dt,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{ref:$,value:I,onChange:o=>{T(o.target.value),E(0)},onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),zs(I&&o.shiftKey?b-1:b+1)):o.key==="Escape"&&(o.preventDefault(),S(!1),T(""))},placeholder:c("session.search.placeholder"),className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"}),I.trim()&&e.jsx("span",{className:"flex-shrink-0 font-mono text-[10px] text-text-muted",children:ve.orderedMatchIds.length===0?c("session.search.noResults"):`${b+1}/${ve.orderedMatchIds.length}`})]})}),e.jsx(qn,{entries:ge,isLoading:X,turnStartedAt:As,emptyTitle:c("session.emptyTitle"),emptyDescription:c("session.emptyDescription"),searchMatchIds:I.trim()?ve.matchIds:void 0,onRewindEntry:F.rewind&&!U&&!B&&!X?(o,x)=>Qs(o,x):void 0}),e.jsx(Rr,{state:ft,onStopTask:_t}),be.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:be.map(o=>e.jsx(ga,{request:o,onApprove:()=>Ys(o.requestId),onApproveAlways:o.suggestions&&o.suggestions.length>0?()=>Js(o.requestId,o.suggestions??[]):void 0,onReject:()=>en(o.requestId),onSubmitAnswers:tn,onSubmitPlan:sn},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(Gr,{request:Me,onSubmit:Xs})})}),jt&&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:jt})}),yt&&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:yt})}),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(ha,{mode:Ie,onModeChange:et,disabled:U||B}),e.jsx(pa,{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}}),Ve(x=>x&&{...x,currentModelId:o})},disabled:U||B}),F.set_max_thinking_tokens&&e.jsx(ua,{budget:Ee,onBudgetChange:Ps,disabled:U||B}),F.set_effort&&e.jsx(ma,{effort:St,onEffortChange:o=>Us.set(o),disabled:U||B})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[Mt&&e.jsx(fa,{usage:Mt}),je&&e.jsxs("span",{className:"text-[10px] text-text-muted font-mono",title:c("session.usage.total"),children:[me(je.inputTokens)," in / ",me(je.outputTokens)," out",je.totalCostUsd!=null&&` · $${je.totalCostUsd.toFixed(2)}`]})]})]}),U&&(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 Bs(),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(Pn,{onSubmit:Ws,isLoading:X,onInterrupt:At,onCycleMode:Vs,disabled:U||B,placeholder:U?c("session.closed"):B?c("session.readOnly"):c("session.inputPlaceholder"),supportsAttachments:!0,commands:st,queueWhileLoading:!0,queuedCount:Re.length,onDequeue:o=>Ae(x=>x.filter((N,M)=>M!==o)),onSearchFiles:F.file_search?o=>P.searchFiles(o):void 0,historyKey:r,draftOverride:A}),g&&e.jsx(Fr,{onClose:()=>y(!1),fetchServers:()=>P.getMcpServers(),onToggle:(o,x)=>P.toggleMcpServer(o,x),onReconnect:o=>P.reconnectMcpServer(o)}),k&&e.jsx(Lr,{onClose:()=>C(!1),fetchSettings:()=>P.getRemoteSettings(),onApply:o=>P.applyFlagSettings(o)}),_&&e.jsx(Br,{onClose:()=>j(!1),onAsk:o=>P.askSideQuestion(o)}),f&&s&&e.jsx($r,{onClose:()=>p(!1),session:s,liveStatus:a,pendingPermissions:be,subagentState:ft,onStopTask:_t,onInterrupt:At,onDelete:Gs,onEndSession:F.end_session&&!U&&!B?async()=>{await P.endSession("ended from web"),await Ft(s.id),window.location.href="/code/"}:void 0}),e.jsx(Zr,{open:Y,onClose:()=>ee(!1),sessionId:s.id,sessionTitle:s.title||void 0}),e.jsx(sa,{open:m,onClose:()=>h(!1),adapter:P,onResume:o=>{h(!1),_e(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 ga({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(Wr,{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(zr,{requestId:r.requestId,planContent:p,description:f,onSubmit:(g,y)=>d(r.requestId,g,y)})}return e.jsx(Hr,{requestId:r.requestId,toolName:i,toolInput:u,description:f,suggestions:r.suggestions,onApprove:t,onApproveAlways:s,onReject:n})}function ya({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=la(t);return p.setConnectionStateHandler((g,y)=>{d(g),u(y||null)}),f.current=p,n(p),p.connect().catch(g=>{g instanceof On||(u(g.message),d("error"))}),()=>{p.disconnect(),f.current=null,n(null),d("disconnected")}},[t]),e.jsx(xs,{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(Un,{client:s,agentId:t})})]})})}export{Ia as SessionDetail};
|