@saluzi/saluzi-edu 0.5.12 → 0.5.13

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.
Files changed (160) hide show
  1. package/dist/cli.js +47 -47
  2. package/dist/rcs-web/assets/{AdminPanel-N24fbtDr.js → AdminPanel-DUladavo.js} +1 -1
  3. package/dist/rcs-web/assets/{ArtifactView-BDbNCtzr.js → ArtifactView-n0v6hnzo.js} +1 -1
  4. package/{packages/remote-control-server/web/dist/assets/ArtifactsGallery-BhxPaq_Y.js → dist/rcs-web/assets/ArtifactsGallery-ug-kp4qP.js} +5 -5
  5. package/{packages/remote-control-server/web/dist/assets/Claim-ClId-sat.js → dist/rcs-web/assets/Claim-CYVUcDxH.js} +1 -1
  6. package/dist/rcs-web/assets/Dashboard--x6EF7xP.js +6 -0
  7. package/dist/rcs-web/assets/Join-DDTbyo3-.js +1 -0
  8. package/dist/rcs-web/assets/Login-CR9Rx-mk.js +1 -0
  9. package/dist/rcs-web/assets/Register-BFzxxFmG.js +1 -0
  10. package/dist/rcs-web/assets/{SessionDetail-C-lPPdGL.js → SessionDetail-CsnvwQ0t.js} +9 -9
  11. package/dist/rcs-web/assets/{SessionVisibilityBadge-rHbdCbCs.js → SessionVisibilityBadge-IJ03myi1.js} +2 -2
  12. package/dist/rcs-web/assets/Setup-CDlsj-Tq.js +1 -0
  13. package/dist/rcs-web/assets/{ShareLanding-Bd--e_ru.js → ShareLanding-yU_oNRIA.js} +1 -1
  14. package/dist/rcs-web/assets/{TeamCreate-btnOXimS.js → TeamCreate-BZFPWa3R.js} +1 -1
  15. package/dist/rcs-web/assets/{TeamDetail-Bq7sfprF.js → TeamDetail-Bs8euLfd.js} +2 -2
  16. package/dist/rcs-web/assets/{TeamList-Ckc_5rPG.js → TeamList-Czzk-glq.js} +1 -1
  17. package/dist/rcs-web/assets/{TeamSettings-Dn8wW8D0.js → TeamSettings-CXTCaWDB.js} +1 -1
  18. package/dist/rcs-web/assets/{UserSearchInput-BRoxtwWw.js → UserSearchInput-CGtPgB9t.js} +1 -1
  19. package/dist/rcs-web/assets/{UserSettings-BsPA9Uww.js → UserSettings-CL5LzA-S.js} +1 -1
  20. package/dist/rcs-web/assets/{arc-WLkbBjJm.js → arc-DjW5P0be.js} +1 -1
  21. package/{packages/remote-control-server/web/dist/assets/architectureDiagram-3BPJPVTR-BJi4DwhI.js → dist/rcs-web/assets/architectureDiagram-3BPJPVTR-BusiH9yR.js} +1 -1
  22. package/{packages/remote-control-server/web/dist/assets/blockDiagram-GPEHLZMM-CmqVqUku.js → dist/rcs-web/assets/blockDiagram-GPEHLZMM-3edPnryX.js} +1 -1
  23. package/{packages/remote-control-server/web/dist/assets/c4Diagram-AAUBKEIU-z7aUi41b.js → dist/rcs-web/assets/c4Diagram-AAUBKEIU-ZLlCXozI.js} +1 -1
  24. package/dist/rcs-web/assets/channel-ZxgdY0DL.js +1 -0
  25. package/dist/rcs-web/assets/{chunk-2J33WTMH-DmlfMgi-.js → chunk-2J33WTMH-DGhWwfFz.js} +1 -1
  26. package/dist/rcs-web/assets/{chunk-4BX2VUAB-DvBN8rCU.js → chunk-4BX2VUAB-Cu1Rovtf.js} +1 -1
  27. package/dist/rcs-web/assets/{chunk-55IACEB6-DvXeBOx-.js → chunk-55IACEB6-DHElqmXB.js} +1 -1
  28. package/{packages/remote-control-server/web/dist/assets/chunk-727SXJPM-DiL1P1kA.js → dist/rcs-web/assets/chunk-727SXJPM-BqK0ih5x.js} +1 -1
  29. package/{packages/remote-control-server/web/dist/assets/chunk-AQP2D5EJ-CapDNDA2.js → dist/rcs-web/assets/chunk-AQP2D5EJ-BqbZo8Yj.js} +1 -1
  30. package/dist/rcs-web/assets/{chunk-FMBD7UC4-LbpvFjyd.js → chunk-FMBD7UC4-DPaHLrRQ.js} +1 -1
  31. package/dist/rcs-web/assets/{chunk-ND2GUHAM-CzgCleAV.js → chunk-ND2GUHAM-DLFqo9BD.js} +1 -1
  32. package/dist/rcs-web/assets/{chunk-QZHKN3VN-CLwirFtM.js → chunk-QZHKN3VN-BGxZPgfS.js} +1 -1
  33. package/dist/rcs-web/assets/classDiagram-4FO5ZUOK--ySrRR0W.js +1 -0
  34. package/dist/rcs-web/assets/classDiagram-v2-Q7XG4LA2--ySrRR0W.js +1 -0
  35. package/dist/rcs-web/assets/{code-block-IT6T5CEO-CPLRB_pE.js → code-block-IT6T5CEO-CSwLPJ0x.js} +1 -1
  36. package/dist/rcs-web/assets/{copy-ds55WfXQ.js → copy-BhKgO2-h.js} +1 -1
  37. package/dist/rcs-web/assets/{cose-bilkent-S5V4N54A-CJQmna96.js → cose-bilkent-S5V4N54A-CEbUVDno.js} +1 -1
  38. package/dist/rcs-web/assets/{dagre-BM42HDAG-DEhEovt8.js → dagre-BM42HDAG-BOpyYtmk.js} +1 -1
  39. package/dist/rcs-web/assets/{diagram-2AECGRRQ-4okwBc-D.js → diagram-2AECGRRQ-BloFuIVx.js} +1 -1
  40. package/dist/rcs-web/assets/{diagram-5GNKFQAL-H2-k4m--.js → diagram-5GNKFQAL-ODoXsyn6.js} +1 -1
  41. package/{packages/remote-control-server/web/dist/assets/diagram-KO2AKTUF-DDErYX7-.js → dist/rcs-web/assets/diagram-KO2AKTUF-CqvO6a9C.js} +1 -1
  42. package/dist/rcs-web/assets/{diagram-LMA3HP47-l4LQiTmZ.js → diagram-LMA3HP47-_GbpEoyV.js} +1 -1
  43. package/{packages/remote-control-server/web/dist/assets/diagram-OG6HWLK6-CpAEcjR4.js → dist/rcs-web/assets/diagram-OG6HWLK6-Es7g24jE.js} +1 -1
  44. package/dist/rcs-web/assets/{dialog-BUpbhUDV.js → dialog-BBq_xUNv.js} +1 -1
  45. package/{packages/remote-control-server/web/dist/assets/erDiagram-TEJ5UH35-CzSfImjG.js → dist/rcs-web/assets/erDiagram-TEJ5UH35-5RgvoMG8.js} +1 -1
  46. package/dist/rcs-web/assets/{flowDiagram-I6XJVG4X-Dr-LtHsL.js → flowDiagram-I6XJVG4X-CoaA57yK.js} +1 -1
  47. package/{packages/remote-control-server/web/dist/assets/ganttDiagram-6RSMTGT7-CXpEIO6H.js → dist/rcs-web/assets/ganttDiagram-6RSMTGT7-6j5ZIgMM.js} +1 -1
  48. package/{packages/remote-control-server/web/dist/assets/gitGraphDiagram-PVQCEYII-Doj2VKE1.js → dist/rcs-web/assets/gitGraphDiagram-PVQCEYII-COZ5Q_FL.js} +1 -1
  49. package/dist/rcs-web/assets/{infoDiagram-5YYISTIA-CFJYX2aM.js → infoDiagram-5YYISTIA-Bx0c_B3n.js} +1 -1
  50. package/dist/rcs-web/assets/{ishikawaDiagram-YF4QCWOH-F50-t8RF.js → ishikawaDiagram-YF4QCWOH-dHJBXkSa.js} +1 -1
  51. package/dist/rcs-web/assets/{journeyDiagram-JHISSGLW-Dl5ueEc9.js → journeyDiagram-JHISSGLW-Dcq9iFgM.js} +1 -1
  52. package/dist/rcs-web/assets/{kanban-definition-UN3LZRKU-seqONfO3.js → kanban-definition-UN3LZRKU-CZxcvp-B.js} +1 -1
  53. package/dist/rcs-web/assets/{linear-Dv62-Sa5.js → linear-Bv6UyZQa.js} +1 -1
  54. package/dist/rcs-web/assets/{main-Cv-18i1u.js → main-By9kIvu-.js} +19 -19
  55. package/dist/rcs-web/assets/main-C-SKezR2.css +1 -0
  56. package/{packages/remote-control-server/web/dist/assets/mermaid-VLURNSYL-HzkeBXwF.js → dist/rcs-web/assets/mermaid-VLURNSYL-DduLrURr.js} +4 -4
  57. package/dist/rcs-web/assets/{mermaid.core-LpWnkgo7.js → mermaid.core-Bxop4hX2.js} +5 -5
  58. package/{packages/remote-control-server/web/dist/assets/mindmap-definition-RKZ34NQL-6-cD5kGK.js → dist/rcs-web/assets/mindmap-definition-RKZ34NQL-OPyGyOpN.js} +1 -1
  59. package/dist/rcs-web/assets/{pieDiagram-4H26LBE5-C9zkUn5q.js → pieDiagram-4H26LBE5-B4uZJNDD.js} +1 -1
  60. package/dist/rcs-web/assets/{quadrantDiagram-W4KKPZXB-CpGzs4_X.js → quadrantDiagram-W4KKPZXB-DGDKsLDP.js} +1 -1
  61. package/dist/rcs-web/assets/{refresh-cw-BRGSdX3K.js → refresh-cw-NV7B8IJD.js} +1 -1
  62. package/dist/rcs-web/assets/{requirementDiagram-4Y6WPE33-DVgiogrq.js → requirementDiagram-4Y6WPE33-CgBcr3ay.js} +1 -1
  63. package/dist/rcs-web/assets/{sankeyDiagram-5OEKKPKP-BLFunPVU.js → sankeyDiagram-5OEKKPKP-CnIWx0dJ.js} +1 -1
  64. package/dist/rcs-web/assets/{sequenceDiagram-3UESZ5HK-C9K1xnOT.js → sequenceDiagram-3UESZ5HK-B8U7yJ7k.js} +1 -1
  65. package/dist/rcs-web/assets/{stateDiagram-AJRCARHV-vifFCjen.js → stateDiagram-AJRCARHV-eOqfxib6.js} +1 -1
  66. package/dist/rcs-web/assets/{stateDiagram-v2-BHNVJYJU-7gdiYOYv.js → stateDiagram-v2-BHNVJYJU-z6cYmgsI.js} +1 -1
  67. package/{packages/remote-control-server/web/dist/assets/timeline-definition-PNZ67QCA-DXNkBwBM.js → dist/rcs-web/assets/timeline-definition-PNZ67QCA-BLAtSeoe.js} +1 -1
  68. package/dist/rcs-web/assets/{vennDiagram-CIIHVFJN-DKQuds1M.js → vennDiagram-CIIHVFJN-x2K-Z8M5.js} +1 -1
  69. package/dist/rcs-web/assets/{wardleyDiagram-YWT4CUSO-DM8Y_x69.js → wardleyDiagram-YWT4CUSO-BZyV-nKl.js} +1 -1
  70. package/dist/rcs-web/assets/{xychartDiagram-2RQKCTM6-CZNSppIC.js → xychartDiagram-2RQKCTM6-BXBh8hUz.js} +1 -1
  71. package/dist/rcs-web/index.html +2 -2
  72. package/package.json +1 -1
  73. package/packages/remote-control-server/web/dist/assets/{AdminPanel-N24fbtDr.js → AdminPanel-DUladavo.js} +1 -1
  74. package/packages/remote-control-server/web/dist/assets/{ArtifactView-BDbNCtzr.js → ArtifactView-n0v6hnzo.js} +1 -1
  75. package/{dist/rcs-web/assets/ArtifactsGallery-BhxPaq_Y.js → packages/remote-control-server/web/dist/assets/ArtifactsGallery-ug-kp4qP.js} +5 -5
  76. package/{dist/rcs-web/assets/Claim-ClId-sat.js → packages/remote-control-server/web/dist/assets/Claim-CYVUcDxH.js} +1 -1
  77. package/packages/remote-control-server/web/dist/assets/Dashboard--x6EF7xP.js +6 -0
  78. package/packages/remote-control-server/web/dist/assets/Join-DDTbyo3-.js +1 -0
  79. package/packages/remote-control-server/web/dist/assets/Login-CR9Rx-mk.js +1 -0
  80. package/packages/remote-control-server/web/dist/assets/Register-BFzxxFmG.js +1 -0
  81. package/packages/remote-control-server/web/dist/assets/{SessionDetail-C-lPPdGL.js → SessionDetail-CsnvwQ0t.js} +9 -9
  82. package/packages/remote-control-server/web/dist/assets/{SessionVisibilityBadge-rHbdCbCs.js → SessionVisibilityBadge-IJ03myi1.js} +2 -2
  83. package/packages/remote-control-server/web/dist/assets/Setup-CDlsj-Tq.js +1 -0
  84. package/packages/remote-control-server/web/dist/assets/{ShareLanding-Bd--e_ru.js → ShareLanding-yU_oNRIA.js} +1 -1
  85. package/packages/remote-control-server/web/dist/assets/{TeamCreate-btnOXimS.js → TeamCreate-BZFPWa3R.js} +1 -1
  86. package/packages/remote-control-server/web/dist/assets/{TeamDetail-Bq7sfprF.js → TeamDetail-Bs8euLfd.js} +2 -2
  87. package/packages/remote-control-server/web/dist/assets/{TeamList-Ckc_5rPG.js → TeamList-Czzk-glq.js} +1 -1
  88. package/packages/remote-control-server/web/dist/assets/{TeamSettings-Dn8wW8D0.js → TeamSettings-CXTCaWDB.js} +1 -1
  89. package/packages/remote-control-server/web/dist/assets/{UserSearchInput-BRoxtwWw.js → UserSearchInput-CGtPgB9t.js} +1 -1
  90. package/packages/remote-control-server/web/dist/assets/{UserSettings-BsPA9Uww.js → UserSettings-CL5LzA-S.js} +1 -1
  91. package/packages/remote-control-server/web/dist/assets/{arc-WLkbBjJm.js → arc-DjW5P0be.js} +1 -1
  92. package/{dist/rcs-web/assets/architectureDiagram-3BPJPVTR-BJi4DwhI.js → packages/remote-control-server/web/dist/assets/architectureDiagram-3BPJPVTR-BusiH9yR.js} +1 -1
  93. package/{dist/rcs-web/assets/blockDiagram-GPEHLZMM-CmqVqUku.js → packages/remote-control-server/web/dist/assets/blockDiagram-GPEHLZMM-3edPnryX.js} +1 -1
  94. package/{dist/rcs-web/assets/c4Diagram-AAUBKEIU-z7aUi41b.js → packages/remote-control-server/web/dist/assets/c4Diagram-AAUBKEIU-ZLlCXozI.js} +1 -1
  95. package/packages/remote-control-server/web/dist/assets/channel-ZxgdY0DL.js +1 -0
  96. package/packages/remote-control-server/web/dist/assets/{chunk-2J33WTMH-DmlfMgi-.js → chunk-2J33WTMH-DGhWwfFz.js} +1 -1
  97. package/packages/remote-control-server/web/dist/assets/{chunk-4BX2VUAB-DvBN8rCU.js → chunk-4BX2VUAB-Cu1Rovtf.js} +1 -1
  98. package/packages/remote-control-server/web/dist/assets/{chunk-55IACEB6-DvXeBOx-.js → chunk-55IACEB6-DHElqmXB.js} +1 -1
  99. package/{dist/rcs-web/assets/chunk-727SXJPM-DiL1P1kA.js → packages/remote-control-server/web/dist/assets/chunk-727SXJPM-BqK0ih5x.js} +1 -1
  100. package/{dist/rcs-web/assets/chunk-AQP2D5EJ-CapDNDA2.js → packages/remote-control-server/web/dist/assets/chunk-AQP2D5EJ-BqbZo8Yj.js} +1 -1
  101. package/packages/remote-control-server/web/dist/assets/{chunk-FMBD7UC4-LbpvFjyd.js → chunk-FMBD7UC4-DPaHLrRQ.js} +1 -1
  102. package/packages/remote-control-server/web/dist/assets/{chunk-ND2GUHAM-CzgCleAV.js → chunk-ND2GUHAM-DLFqo9BD.js} +1 -1
  103. package/packages/remote-control-server/web/dist/assets/{chunk-QZHKN3VN-CLwirFtM.js → chunk-QZHKN3VN-BGxZPgfS.js} +1 -1
  104. package/packages/remote-control-server/web/dist/assets/classDiagram-4FO5ZUOK--ySrRR0W.js +1 -0
  105. package/packages/remote-control-server/web/dist/assets/classDiagram-v2-Q7XG4LA2--ySrRR0W.js +1 -0
  106. package/packages/remote-control-server/web/dist/assets/{code-block-IT6T5CEO-CPLRB_pE.js → code-block-IT6T5CEO-CSwLPJ0x.js} +1 -1
  107. package/packages/remote-control-server/web/dist/assets/{copy-ds55WfXQ.js → copy-BhKgO2-h.js} +1 -1
  108. package/packages/remote-control-server/web/dist/assets/{cose-bilkent-S5V4N54A-CJQmna96.js → cose-bilkent-S5V4N54A-CEbUVDno.js} +1 -1
  109. package/packages/remote-control-server/web/dist/assets/{dagre-BM42HDAG-DEhEovt8.js → dagre-BM42HDAG-BOpyYtmk.js} +1 -1
  110. package/packages/remote-control-server/web/dist/assets/{diagram-2AECGRRQ-4okwBc-D.js → diagram-2AECGRRQ-BloFuIVx.js} +1 -1
  111. package/packages/remote-control-server/web/dist/assets/{diagram-5GNKFQAL-H2-k4m--.js → diagram-5GNKFQAL-ODoXsyn6.js} +1 -1
  112. package/{dist/rcs-web/assets/diagram-KO2AKTUF-DDErYX7-.js → packages/remote-control-server/web/dist/assets/diagram-KO2AKTUF-CqvO6a9C.js} +1 -1
  113. package/packages/remote-control-server/web/dist/assets/{diagram-LMA3HP47-l4LQiTmZ.js → diagram-LMA3HP47-_GbpEoyV.js} +1 -1
  114. package/{dist/rcs-web/assets/diagram-OG6HWLK6-CpAEcjR4.js → packages/remote-control-server/web/dist/assets/diagram-OG6HWLK6-Es7g24jE.js} +1 -1
  115. package/packages/remote-control-server/web/dist/assets/{dialog-BUpbhUDV.js → dialog-BBq_xUNv.js} +1 -1
  116. package/{dist/rcs-web/assets/erDiagram-TEJ5UH35-CzSfImjG.js → packages/remote-control-server/web/dist/assets/erDiagram-TEJ5UH35-5RgvoMG8.js} +1 -1
  117. package/packages/remote-control-server/web/dist/assets/{flowDiagram-I6XJVG4X-Dr-LtHsL.js → flowDiagram-I6XJVG4X-CoaA57yK.js} +1 -1
  118. package/{dist/rcs-web/assets/ganttDiagram-6RSMTGT7-CXpEIO6H.js → packages/remote-control-server/web/dist/assets/ganttDiagram-6RSMTGT7-6j5ZIgMM.js} +1 -1
  119. package/{dist/rcs-web/assets/gitGraphDiagram-PVQCEYII-Doj2VKE1.js → packages/remote-control-server/web/dist/assets/gitGraphDiagram-PVQCEYII-COZ5Q_FL.js} +1 -1
  120. package/packages/remote-control-server/web/dist/assets/{infoDiagram-5YYISTIA-CFJYX2aM.js → infoDiagram-5YYISTIA-Bx0c_B3n.js} +1 -1
  121. package/packages/remote-control-server/web/dist/assets/{ishikawaDiagram-YF4QCWOH-F50-t8RF.js → ishikawaDiagram-YF4QCWOH-dHJBXkSa.js} +1 -1
  122. package/packages/remote-control-server/web/dist/assets/{journeyDiagram-JHISSGLW-Dl5ueEc9.js → journeyDiagram-JHISSGLW-Dcq9iFgM.js} +1 -1
  123. package/packages/remote-control-server/web/dist/assets/{kanban-definition-UN3LZRKU-seqONfO3.js → kanban-definition-UN3LZRKU-CZxcvp-B.js} +1 -1
  124. package/packages/remote-control-server/web/dist/assets/{linear-Dv62-Sa5.js → linear-Bv6UyZQa.js} +1 -1
  125. package/packages/remote-control-server/web/dist/assets/{main-Cv-18i1u.js → main-By9kIvu-.js} +19 -19
  126. package/packages/remote-control-server/web/dist/assets/main-C-SKezR2.css +1 -0
  127. package/{dist/rcs-web/assets/mermaid-VLURNSYL-HzkeBXwF.js → packages/remote-control-server/web/dist/assets/mermaid-VLURNSYL-DduLrURr.js} +4 -4
  128. package/packages/remote-control-server/web/dist/assets/{mermaid.core-LpWnkgo7.js → mermaid.core-Bxop4hX2.js} +5 -5
  129. package/{dist/rcs-web/assets/mindmap-definition-RKZ34NQL-6-cD5kGK.js → packages/remote-control-server/web/dist/assets/mindmap-definition-RKZ34NQL-OPyGyOpN.js} +1 -1
  130. package/packages/remote-control-server/web/dist/assets/{pieDiagram-4H26LBE5-C9zkUn5q.js → pieDiagram-4H26LBE5-B4uZJNDD.js} +1 -1
  131. package/packages/remote-control-server/web/dist/assets/{quadrantDiagram-W4KKPZXB-CpGzs4_X.js → quadrantDiagram-W4KKPZXB-DGDKsLDP.js} +1 -1
  132. package/packages/remote-control-server/web/dist/assets/{refresh-cw-BRGSdX3K.js → refresh-cw-NV7B8IJD.js} +1 -1
  133. package/packages/remote-control-server/web/dist/assets/{requirementDiagram-4Y6WPE33-DVgiogrq.js → requirementDiagram-4Y6WPE33-CgBcr3ay.js} +1 -1
  134. package/packages/remote-control-server/web/dist/assets/{sankeyDiagram-5OEKKPKP-BLFunPVU.js → sankeyDiagram-5OEKKPKP-CnIWx0dJ.js} +1 -1
  135. package/packages/remote-control-server/web/dist/assets/{sequenceDiagram-3UESZ5HK-C9K1xnOT.js → sequenceDiagram-3UESZ5HK-B8U7yJ7k.js} +1 -1
  136. package/packages/remote-control-server/web/dist/assets/{stateDiagram-AJRCARHV-vifFCjen.js → stateDiagram-AJRCARHV-eOqfxib6.js} +1 -1
  137. package/packages/remote-control-server/web/dist/assets/{stateDiagram-v2-BHNVJYJU-7gdiYOYv.js → stateDiagram-v2-BHNVJYJU-z6cYmgsI.js} +1 -1
  138. package/{dist/rcs-web/assets/timeline-definition-PNZ67QCA-DXNkBwBM.js → packages/remote-control-server/web/dist/assets/timeline-definition-PNZ67QCA-BLAtSeoe.js} +1 -1
  139. package/packages/remote-control-server/web/dist/assets/{vennDiagram-CIIHVFJN-DKQuds1M.js → vennDiagram-CIIHVFJN-x2K-Z8M5.js} +1 -1
  140. package/packages/remote-control-server/web/dist/assets/{wardleyDiagram-YWT4CUSO-DM8Y_x69.js → wardleyDiagram-YWT4CUSO-BZyV-nKl.js} +1 -1
  141. package/packages/remote-control-server/web/dist/assets/{xychartDiagram-2RQKCTM6-CZNSppIC.js → xychartDiagram-2RQKCTM6-BXBh8hUz.js} +1 -1
  142. package/packages/remote-control-server/web/dist/index.html +2 -2
  143. package/dist/rcs-web/assets/Dashboard-ppeF5vBM.js +0 -6
  144. package/dist/rcs-web/assets/Join-xPPDkVBy.js +0 -1
  145. package/dist/rcs-web/assets/Login-BKaBogPS.js +0 -1
  146. package/dist/rcs-web/assets/Register-BP0npVpc.js +0 -1
  147. package/dist/rcs-web/assets/Setup-CPfviAHa.js +0 -1
  148. package/dist/rcs-web/assets/channel-B6VWMPrR.js +0 -1
  149. package/dist/rcs-web/assets/classDiagram-4FO5ZUOK-C568lnYy.js +0 -1
  150. package/dist/rcs-web/assets/classDiagram-v2-Q7XG4LA2-C568lnYy.js +0 -1
  151. package/dist/rcs-web/assets/main-DBlZ5szI.css +0 -1
  152. package/packages/remote-control-server/web/dist/assets/Dashboard-ppeF5vBM.js +0 -6
  153. package/packages/remote-control-server/web/dist/assets/Join-xPPDkVBy.js +0 -1
  154. package/packages/remote-control-server/web/dist/assets/Login-BKaBogPS.js +0 -1
  155. package/packages/remote-control-server/web/dist/assets/Register-BP0npVpc.js +0 -1
  156. package/packages/remote-control-server/web/dist/assets/Setup-CPfviAHa.js +0 -1
  157. package/packages/remote-control-server/web/dist/assets/channel-B6VWMPrR.js +0 -1
  158. package/packages/remote-control-server/web/dist/assets/classDiagram-4FO5ZUOK-C568lnYy.js +0 -1
  159. package/packages/remote-control-server/web/dist/assets/classDiagram-v2-Q7XG4LA2-C568lnYy.js +0 -1
  160. package/packages/remote-control-server/web/dist/assets/main-DBlZ5szI.css +0 -1
@@ -1,4 +1,4 @@
1
- var Is=Object.defineProperty;var qs=(r,t,n)=>t in r?Is(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n;var T=(r,t,n)=>qs(r,typeof t!="symbol"?t+"":t,n);import{e as l,j as e}from"./vendor-DE_-CLIE.js";import{ai as L,a1 as Ds,aq as St,ap as Ct,as as Ps,ar as De,am as ne,ac as Us,ab as Q,a4 as Os,a9 as Fs,az as Ls,z as Gt,g as Et,al as Yt,L as ve,G as Bs,aj as Pe,d as Ne,S as rt,M as Hs,v as Ws,X as zs,y as Ks,ak as z,ag as ke,ax as Tt,a5 as Qs,Q as Vs,a8 as Gs,aC as Jt,aw as S,A as Ys,an as Js,at as Xs,au as Zs,J as Mt,N as en,ay as tn,b as sn,W as Rt,a6 as nn,E as Xt,P as rn,F as an,c as on,C as ln,a0 as At,D as cn,a as dn,r as Ue,t as Oe,x as un,f as Fe,e as Le,s as Be,p as mn,B as xn}from"./main-Cv-18i1u.js";import{g as fn}from"./workerType-Bd-zteMi.js";import{D as ie,a as le,c as ce,d as de,b as pn}from"./dialog-BUpbhUDV.js";import{R as hn}from"./refresh-cw-BRGSdX3K.js";import{C as gn}from"./copy-ds55WfXQ.js";import{E as yn,A as bn}from"./ArtifactsGallery-BhxPaq_Y.js";import{S as wn}from"./SessionVisibilityBadge-rHbdCbCs.js";import{U as jn}from"./UserSearchInput-BRoxtwWw.js";import{S as kn,b as vn}from"./notifications-D9_SRqI0.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";/**
1
+ var Is=Object.defineProperty;var Ds=(r,t,n)=>t in r?Is(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n;var T=(r,t,n)=>Ds(r,typeof t!="symbol"?t+"":t,n);import{e as l,j as e}from"./vendor-DE_-CLIE.js";import{aj as L,a2 as qs,ar as St,aq as Ct,at as Ps,as as qe,an as ne,ad as Us,ac as V,a5 as Os,aa as Fs,aA as Ls,E as Gt,g as Et,am as Yt,L as ve,H as Bs,ak as Pe,d as Ne,S as rt,M as Hs,v as Ws,X as zs,z as Ks,al as z,ah as ke,ay as Tt,a6 as Vs,V as Qs,a9 as Gs,aD as Jt,ax as S,A as Ys,ao as Js,au as Xs,av as Zs,K as Mt,Q as en,az as tn,b as sn,Y as Rt,a7 as nn,G as Xt,P as rn,F as an,c as on,C as ln,a1 as At,D as cn,a as dn,r as Ue,t as Oe,x as un,f as Fe,e as Le,s as Be,p as mn,B as xn}from"./main-By9kIvu-.js";import{g as fn}from"./workerType-Bd-zteMi.js";import{D as ie,a as le,c as ce,d as de,b as pn}from"./dialog-BBq_xUNv.js";import{R as hn}from"./refresh-cw-NV7B8IJD.js";import{C as gn}from"./copy-BhKgO2-h.js";import{E as yn,A as bn}from"./ArtifactsGallery-ug-kp4qP.js";import{S as wn}from"./SessionVisibilityBadge-IJ03myi1.js";import{U as jn}from"./UserSearchInput-CGtPgB9t.js";import{S as kn,b as vn}from"./notifications-D9_SRqI0.js";import"./shiki-mEP5vQQu.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.
@@ -33,12 +33,12 @@ var Is=Object.defineProperty;var qs=(r,t,n)=>t in r?Is(r,t,{enumerable:!0,config
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 In=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],qn=L("info",In);/**
36
+ */const In=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],Dn=L("info",In);/**
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 Dn=[["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"}]],ts=L("message-circle-question-mark",Dn);/**
41
+ */const qn=[["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"}]],ts=L("message-circle-question-mark",qn);/**
42
42
  * @license lucide-react v0.555.0 - ISC
43
43
  *
44
44
  * This source code is licensed under the ISC license.
@@ -73,16 +73,16 @@ var Is=Object.defineProperty;var qs=(r,t,n)=>t in r?Is(r,t,{enumerable:!0,config
73
73
  *
74
74
  * This source code is licensed under the ISC license.
75
75
  * See the LICENSE file in the root directory of this source tree.
76
- */const Qn=[["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"}]],Vn=L("shield-check",Qn);/**
76
+ */const Vn=[["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"}]],Qn=L("shield-check",Vn);/**
77
77
  * @license lucide-react v0.555.0 - ISC
78
78
  *
79
79
  * This source code is licensed under the ISC license.
80
80
  * See the LICENSE file in the root directory of this source tree.
81
- */const Gn=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],Yn=L("triangle-alert",Gn);function rs(){return{tasks:{}}}const $t=3e4;function qe(r){const t=r.trim();if(!t)return"agent";const n=t.split(/\s+/).slice(0,2).join(" ");return n.length>40?n.slice(0,40)+"…":n}function Jn(r,t){var i,m,y,f,h,w,v,M,u,c,b,p;const n=t.subtype;if(n!=="task_started"&&n!=="task_progress"&&n!=="task_notification")return r;const s=t.task_id;if(!s)return r;const a=Date.now(),d=r.tasks[s];if(n==="task_started"){if(d)return{tasks:{...r.tasks,[s]:{...d,description:t.description??d.description,name:qe(t.description??d.description),taskType:t.task_type??d.taskType,workflowName:t.workflow_name??d.workflowName,prompt:t.prompt??d.prompt,toolUseId:t.tool_use_id??d.toolUseId,status:"running",startTime:a,evictAfter:void 0}}};const g=t.description??"";return{tasks:{...r.tasks,[s]:{taskId:s,name:qe(g),description:g,taskType:t.task_type,workflowName:t.workflow_name,prompt:t.prompt,toolUseId:t.tool_use_id,status:"running",startTime:a}}}}if(n==="task_progress"){if(!d){const g=t.description??"";return{tasks:{...r.tasks,[s]:{taskId:s,name:qe(g),description:g,toolUseId:t.tool_use_id,status:"running",startTime:a,tokenCount:(i=t.usage)==null?void 0:i.total_tokens,toolUseCount:(m=t.usage)==null?void 0:m.tool_uses,durationMs:(y=t.usage)==null?void 0:y.duration_ms,lastToolName:t.last_tool_name,summary:t.summary}}}}return{tasks:{...r.tasks,[s]:{...d,description:t.description??d.description,tokenCount:((f=t.usage)==null?void 0:f.total_tokens)??d.tokenCount,toolUseCount:((h=t.usage)==null?void 0:h.tool_uses)??d.toolUseCount,durationMs:((w=t.usage)==null?void 0:w.duration_ms)??d.durationMs,lastToolName:t.last_tool_name??d.lastToolName,summary:t.summary??d.summary}}}}return d?{tasks:{...r.tasks,[s]:{...d,status:t.status??"completed",endTime:a,finalSummary:t.summary??d.finalSummary,outputFile:t.output_file??d.outputFile,tokenCount:((c=t.usage)==null?void 0:c.total_tokens)??d.tokenCount,toolUseCount:((b=t.usage)==null?void 0:b.tool_uses)??d.toolUseCount,durationMs:((p=t.usage)==null?void 0:p.duration_ms)??d.durationMs,evictAfter:a+$t}}}:{tasks:{...r.tasks,[s]:{taskId:s,name:qe(t.summary??""),description:t.summary??"",status:t.status??"completed",startTime:a,endTime:a,finalSummary:t.summary,outputFile:t.output_file,tokenCount:(v=t.usage)==null?void 0:v.total_tokens,toolUseCount:(M=t.usage)==null?void 0:M.tool_uses,durationMs:(u=t.usage)==null?void 0:u.duration_ms,evictAfter:a+$t}}}}function Xn(r,t=Date.now()){return Object.values(r.tasks).filter(n=>n.evictAfter===void 0||n.evictAfter>t).sort((n,s)=>n.startTime-s.startTime)}function Zn(r){if(!r||typeof r!="object"||Array.isArray(r))return null;const t=r,n={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(n).some(Boolean)?n:null}function It(r,t){const n=[];if(Array.isArray(r)){for(const s of r){if(!s||typeof s!="object")continue;const a=s;if(typeof a.name!="string"||!a.name)continue;const d=a.type==="prompt"||a.type==="local"||a.type==="local-jsx"?a.type:void 0;n.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(n.length>0)return n}if(Array.isArray(t))for(const s of t)typeof s=="string"&&s&&n.push({name:s});return n}function qt(r){const t=r.raw&&typeof r.raw=="object"&&!Array.isArray(r.raw)?r.raw:r,n=It(t.slash_command_details??r.slash_command_details,t.slash_commands??r.slash_commands),s=It(t.skill_details??r.skill_details,t.skills??r.skills),a=Zn(t.remote_capabilities??r.remote_capabilities);return n.length===0&&s.length===0&&!a?null:{commands:n,skills:s,capabilities:a}}class er{constructor(t){T(this,"listeners",new Set);T(this,"stateListeners",new Set);T(this,"eventSource",null);T(this,"sessionId",null);T(this,"_lastSeqNum",0);T(this,"lastFrameAt",0);T(this,"firstEventAfterOpen",!1);T(this,"watchdogTimer",null);T(this,"visibilityHandler",null);T(this,"reconnectTimer",null);T(this,"reconnectAttempts",0);T(this,"_state","idle");T(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`,n=new EventSource(t,{withCredentials:!0});this.eventSource=n,this.lastFrameAt=Date.now(),this.firstEventAfterOpen=!0,n.addEventListener("open",()=>{this.lastFrameAt=Date.now(),this.reconnectAttempts=0,this.firstEventAfterOpen=!0,this.setState("open")}),n.addEventListener("ping",()=>{this.lastFrameAt=Date.now()}),n.addEventListener("message",s=>{this.lastFrameAt=Date.now();try{const a=JSON.parse(s.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{}}),n.addEventListener("error",()=>{n.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),n=Math.max(0,t+t*.25*(2*Math.random()-1));this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnect()},n)}async reconnect(){this.sessionId&&(await Ls(),this.sessionId&&this.openStream())}setState(t){if(this._state!==t){this._state=t;for(const n of this.stateListeners)n(t,{})}}notifyResync(){for(const t of this.stateListeners)t(this._state,{resync:!0})}}const re=new er;function tt(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(n=>n.type==="text"&&typeof n.text=="string").map(n=>n.text).join("")}return""}function Dt(r,t){for(let n=r.length-1;n>=0;n--){const s=r[n];if(s&&s.type==="tool_call"&&s.toolCall.id===t)return n}return-1}const st="streaming-";function tr(r){const t=r.message;if(!t||typeof t!="object"||!Array.isArray(t.content))return"";const n=[];for(const s of t.content)if((s==null?void 0:s.type)==="thinking"){const a=typeof s.thinking=="string"&&s.thinking||typeof s.text=="string"&&s.text||"";a&&n.push(a)}return n.join("")}function Pt(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 Ut(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 n=t.raw;if(n&&typeof n=="object"&&!Array.isArray(n)){const s=n.target_event_id;if(typeof s=="string"&&s)return s}return""}class sr{constructor(t,n,s){T(this,"sessionId");T(this,"setEntries");T(this,"unsub",null);T(this,"unsubState",null);T(this,"onStatusChange");T(this,"onError");T(this,"onPermissionRequest");T(this,"onModelsStateChange");T(this,"onSubagentUpdate");T(this,"onControlResponse");T(this,"onPermissionModeChange");T(this,"onUsageChange");T(this,"onElicitationRequest");T(this,"onWorkerInfoChange");T(this,"subagentState",rs());T(this,"seenUuids",new Set);T(this,"seenToolCallIds",new Set);T(this,"postedUserUuids",new Set);T(this,"pendingControlRequests",new Map);T(this,"turnEnded",!1);T(this,"userSinceTurnEnd",!1);T(this,"closed",!1);this.sessionId=t,this.setEntries=n,this.onStatusChange=s==null?void 0:s.onStatusChange,this.onError=s==null?void 0:s.onError,this.onPermissionRequest=s==null?void 0:s.onPermissionRequest,this.onModelsStateChange=s==null?void 0:s.onModelsStateChange,this.onSubagentUpdate=s==null?void 0:s.onSubagentUpdate,this.onControlResponse=s==null?void 0:s.onControlResponse,this.onPermissionModeChange=s==null?void 0:s.onPermissionModeChange,this.onUsageChange=s==null?void 0:s.onUsageChange,this.onElicitationRequest=s==null?void 0:s.onElicitationRequest,this.onWorkerInfoChange=s==null?void 0:s.onWorkerInfoChange}markClosed(){this.closed=!0}async init(){await this.loadHistory(),this.connectSSE()}async loadHistory(){var w,v,M,u,c,b;const{events:t}=await Ds(this.sessionId);if(!t||t.length===0)return;const n=new Set;for(const p of t){if(p.type!=="user"||p.direction==="inbound")continue;const g=(w=p.payload)==null?void 0:w.uuid;typeof g=="string"&&g&&n.add(g)}const s=[];let a=null;const d=()=>{a&&(s.push(a),a=null)};for(const p of t){const g=p.payload||{},k=g.uuid;if(typeof k=="string"&&k&&this.seenUuids.add(k),p.type==="tool_use"){const j=g.tool_call_id;typeof j=="string"&&j&&this.seenToolCallIds.add(j)}if(p.type==="user"){if(p.direction==="inbound"){const E=g.uuid;if(typeof E!="string"||!E||n.has(E))continue}d();const j=tt(g);j&&s.push({type:"user_message",id:p.id||`hist-user-${s.length}`,content:j})}else if(p.type==="assistant"){d();const j=tt(g);if(St(j))continue;const E=[],I=g.message;if(I&&typeof I=="object"&&Array.isArray(I.content)){for(const q of I.content)if(q.type==="tool_use"){const B=q.id;B&&this.seenToolCallIds.add(B),E.push({type:"tool_call",toolCall:{id:B||`hist-tool-${s.length}`,title:q.name||"tool",status:"complete",rawInput:q.input||{}}})}}if(j||E.length>0){a={type:"assistant_message",id:p.id||`hist-asst-${s.length}`,chunks:j?[{type:"message",text:j}]:[]},s.push(a);for(const q of E)s.push(q);a=null}}else if(p.type==="conversation_rewound"){const j=Ut(g);if(j){const E=s.findIndex(I=>Ct(I)===j);E>=0&&(s.length=E)}}else if(p.type==="tool_use"){const j=g,E={type:"tool_call",toolCall:{id:j.tool_call_id||`hist-tool-${s.length}`,title:j.tool_name||"tool",status:"complete",rawInput:j.tool_input||{}}};s.push(E)}else if(p.type==="tool_result"){const j=g,E=Dt(s,j.tool_call_id||"");if(E>=0){const I=s[E];s[E]={type:"tool_call",toolCall:{...I.toolCall,rawOutput:{output:j.content||j.output||""}}}}}}d();let i=null;for(const p of t){if(p.type!=="task_state")continue;const g=p.payload||{};Array.isArray(g.tasks)&&(i=g.tasks)}if(i&&i.length>0){const p=Pt(i);p.length>0&&s.push({type:"plan",id:`plan-hist-${Date.now()}`,entries:p})}this.setEntries(s);let m=null,y=null,f=null,h=null;for(const p of t){const g=p.payload||{};if(p.type==="user"?h="user":(p.type==="result"||p.type==="result_success"||p.type==="interrupt")&&(h="turn_end"),p.type==="system"&&(g.subtype==="init"||((v=g.raw)==null?void 0:v.subtype)==="init")&&(y=qt(g)),p.type==="models_state"){const k=g.raw,j=k&&typeof k=="object"?k.models_state:g.models_state;j&&Array.isArray(j.availableModels)&&typeof j.currentModelId=="string"&&(m=j)}else if(p.type==="result"||p.type==="result_success"){const k=g.usage,j=typeof g.total_cost_usd=="number"?g.total_cost_usd:null;(k||j!==null)&&(f={inputTokens:((k==null?void 0:k.input_tokens)??0)+((k==null?void 0:k.cache_read_input_tokens)??0)+((k==null?void 0:k.cache_creation_input_tokens)??0),outputTokens:(k==null?void 0:k.output_tokens)??0,totalCostUsd:j})}}m&&((M=this.onModelsStateChange)==null||M.call(this,m)),y&&((u=this.onWorkerInfoChange)==null||u.call(this,y)),f&&((c=this.onUsageChange)==null||c.call(this,f)),this.turnEnded=h==="turn_end",this.userSinceTurnEnd=h==="user",this.turnEnded&&!this.closed&&((b=this.onStatusChange)==null||b.call(this,"idle"))}connectSSE(){re.connect(this.sessionId),this.unsub=re.onEvent(t=>this.handleEvent(t)),this.unsubState=re.onStateChange((t,n)=>{n.resync&&!this.closed&&this.loadHistory().catch(()=>{})})}disconnect(){this.unsub&&(this.unsub(),this.unsub=null),this.unsubState&&(this.unsubState(),this.unsubState=null),re.disconnect()}handleEvent(t){var a,d,i,m,y,f,h,w,v,M;const n=t.type,s=t.payload||{};switch(n){case"user":{if(this.userSinceTurnEnd=!0,t.direction==="inbound"){const u=s.uuid;if(typeof u!="string"||!u||this.postedUserUuids.has(u)||this.seenUuids.has(u))break;this.seenUuids.add(u);const c=tt(s);c&&this.setEntries(b=>[...b,{type:"user_message",id:t.id||`user-${Date.now()}`,content:c}])}break}case"assistant":{const u=s.uuid;if(typeof u=="string"&&u){if(this.seenUuids.has(u))break;this.seenUuids.add(u)}const c=typeof s.content=="string"?s.content:"";if(St(c))break;const b=tr(s);this.setEntries(g=>{const k=g[g.length-1];if((k==null?void 0:k.type)==="assistant_message"&&k.id.startsWith(st))return[...g.slice(0,-1),{...k,id:`assistant-${Date.now()}`,chunks:[...b?[{type:"thought",text:b}]:[],{type:"message",text:c}]}];if((k==null?void 0:k.type)==="assistant_message"){const j=k.chunks[k.chunks.length-1];return(j==null?void 0:j.type)==="message"?[...g.slice(0,-1),{...k,chunks:[...k.chunks.slice(0,-1),{type:"message",text:j.text+c}]}]:[...g.slice(0,-1),{...k,chunks:[...k.chunks,{type:"message",text:c}]}]}if(c&&c.trim()||b){const j={type:"assistant_message",id:`assistant-${Date.now()}`,chunks:[...b?[{type:"thought",text:b}]:[],...c?[{type:"message",text:c}]:[]]};return[...g,j]}return g});const p=s.message;if(p&&typeof p=="object"&&Array.isArray(p.content)){const g=p.content.filter(k=>k.type==="tool_use");for(const k of g){const j=k.id||`call-${Date.now()}-${Math.random().toString(16).slice(2,8)}`;if(this.seenToolCallIds.has(j))continue;this.seenToolCallIds.add(j);const E={id:j,title:k.name||"tool",status:"running",rawInput:k.input||{}};this.setEntries(I=>[...I,{type:"tool_call",toolCall:E}])}}break}case"tool_use":{const u=s,c=u.tool_call_id||`call-${Date.now()}`;if(this.seenToolCallIds.has(c))break;this.seenToolCallIds.add(c);const b={id:c,title:u.tool_name||"tool",status:"running",rawInput:u.tool_input||{}};this.setEntries(p=>[...p,{type:"tool_call",toolCall:b}]);break}case"tool_result":{const u=s,c=u.tool_call_id||"";this.setEntries(b=>{const p=Dt(b,c);if(p<0)return b;const g=b[p];return b.map((k,j)=>j===p?{type:"tool_call",toolCall:{...g.toolCall,status:"complete",rawOutput:{output:u.content||u.output||""}}}:k)});break}case"control_request":case"permission_request":{const u=s.request;if(u&&u.subtype==="can_use_tool"){const c=s.request_id||"",b=u.tool_name||"unknown",p=u.input||u.tool_input||{},g=u.description||"",k=Array.isArray(u.permission_suggestions)?u.permission_suggestions:[];this.setEntries(j=>{const E=[...j].reverse().findIndex(I=>I.type==="tool_call");if(E>=0){const I=j.length-1-E,q=j[I];if(q.toolCall.status==="running")return j.map((B,X)=>X===I?{type:"tool_call",toolCall:{...q.toolCall,status:"waiting_for_confirmation",permissionRequest:{requestId:c,options:[]}}}:B)}return j}),(a=this.onPermissionRequest)==null||a.call(this,{requestId:c,toolName:b,toolInput:p,description:g,suggestions:k})}else u&&u.subtype==="elicitation"&&((d=this.onElicitationRequest)==null||d.call(this,{requestId:s.request_id||"",serverName:u.mcp_server_name||"",message:u.message||"",mode:u.mode==="url"?"url":"form",url:typeof u.url=="string"?u.url:void 0,requestedSchema:u.requested_schema||void 0}));break}case"conversation_rewound":{const u=Ut(s);u&&this.setEntries(c=>{const b=c.findIndex(p=>Ct(p)===u);return b===-1?c:c.slice(0,b)});break}case"session_status":{if(Ps(s)){this.setEntries([]);break}if(typeof s.status=="string"){if(De(s.status))this.closed=!0;else if(this.closed)break;if(s.status==="running"&&this.turnEnded&&!this.userSinceTurnEnd)break;(i=this.onStatusChange)==null||i.call(this,s.status)}break}case"error":{const u=String(s.message||s.content||"Unknown error");(m=this.onError)==null||m.call(this,u);break}case"models_state":{const u=s.raw,c=typeof u=="object"&&u!==null?u.models_state:s.models_state;c&&Array.isArray(c.availableModels)&&typeof c.currentModelId=="string"&&((y=this.onModelsStateChange)==null||y.call(this,c));break}case"system":{const u=s.raw,c=u&&typeof u=="object"?u:s,b=typeof c.subtype=="string"?c.subtype:void 0;if(b==="task_started"||b==="task_progress"||b==="task_notification"){const g={subtype:b,task_id:typeof c.task_id=="string"?c.task_id:void 0,tool_use_id:typeof c.tool_use_id=="string"?c.tool_use_id:void 0,description:typeof c.description=="string"?c.description:void 0,task_type:typeof c.task_type=="string"?c.task_type:void 0,workflow_name:typeof c.workflow_name=="string"?c.workflow_name:void 0,prompt:typeof c.prompt=="string"?c.prompt:void 0,usage:c.usage&&typeof c.usage=="object"?c.usage:void 0,last_tool_name:typeof c.last_tool_name=="string"?c.last_tool_name:void 0,summary:typeof c.summary=="string"?c.summary:void 0,status:c.status==="completed"||c.status==="failed"||c.status==="stopped"?c.status:void 0,output_file:typeof c.output_file=="string"?c.output_file:void 0};this.subagentState=Jn(this.subagentState,g)}const p=typeof c.permissionMode=="string"?c.permissionMode:typeof s.permissionMode=="string"?s.permissionMode:null;if(p&&((f=this.onPermissionModeChange)==null||f.call(this,p)),b==="init"){const g=qt(s);g&&((h=this.onWorkerInfoChange)==null||h.call(this,g))}break}case"control_response":{const u=s.response;if(u&&typeof u=="object"){const c=typeof u.request_id=="string"?u.request_id:"",b=typeof u.subtype=="string"?u.subtype:"";if(c){(w=this.onControlResponse)==null||w.call(this,{subtype:b,requestId:c,error:typeof u.error=="string"?u.error:void 0});const p=this.pendingControlRequests.get(c);p&&(this.pendingControlRequests.delete(c),p({data:b==="success"&&u.response&&typeof u.response=="object"?u.response:null,...b==="error"&&typeof u.error=="string"?{error:u.error}:{}}))}}break}case"stream_event":{const u=s.event;if(!u||typeof u.type!="string")break;if(u.type==="content_block_delta"){const c=u.delta;if(!c||typeof c.type!="string")break;const b=c.type==="text_delta"?"message":c.type==="thinking_delta"?"thought":null;if(!b)break;const p=c.text??c.thinking;if(typeof p!="string"||!p)break;this.appendStreamingDelta(b,p)}break}case"partial_assistant":{const u=typeof s.content=="string"?s.content:"";u&&this.appendStreamingDelta("message",u);break}case"result":case"result_success":{this.turnEnded=!0,this.userSinceTurnEnd=!1,this.closed||(v=this.onStatusChange)==null||v.call(this,"idle");const u=s.usage,c=typeof s.total_cost_usd=="number"?s.total_cost_usd:null;if(u||c!==null){const j=((u==null?void 0:u.input_tokens)??0)+((u==null?void 0:u.cache_read_input_tokens)??0)+((u==null?void 0:u.cache_creation_input_tokens)??0);(M=this.onUsageChange)==null||M.call(this,{inputTokens:j,outputTokens:(u==null?void 0:u.output_tokens)??0,totalCostUsd:c})}const b=typeof s.subtype=="string"?s.subtype:"",p=s.raw&&typeof s.raw=="object"?s.raw:void 0,k=(typeof s.result=="string"?s.result:typeof(p==null?void 0:p.result)=="string"?p.result:"").trim();b.startsWith("error_")&&k&&this.setEntries(j=>[...j,{type:"command_output",id:`exit-error-${typeof s.uuid=="string"?s.uuid:Date.now()}`,commandName:"worker",inputText:"",title:"Worker 进程异常退出",outputText:k,variant:"error"}]);break}case"task_state":{const u=Array.isArray(s.tasks)?s.tasks:[];if(u.length===0)break;const c=Pt(u);if(c.length===0)break;this.setEntries(b=>[...b.filter(g=>g.type!=="plan"),{type:"plan",id:`plan-${s.task_list_id||Date.now()}`,entries:c}]);break}}}appendStreamingDelta(t,n){this.setEntries(s=>{const a=s[s.length-1];if((a==null?void 0:a.type)==="assistant_message"&&a.id.startsWith(st)){const i=a.chunks[a.chunks.length-1];return(i==null?void 0:i.type)===t?[...s.slice(0,-1),{...a,chunks:[...a.chunks.slice(0,-1),{type:t,text:i.text+n}]}]:[...s.slice(0,-1),{...a,chunks:[...a.chunks,{type:t,text:n}]}]}const d={type:"assistant_message",id:`${st}${Date.now()}`,chunks:[{type:t,text:n}]};return[...s,d]})}async sendMessage(t,n,s){var f;const a=n&&n.length>0,d=s&&s.length>0;if(!t.trim()&&!a&&!d)return;const i={type:"user_message",id:`user-${Date.now()}`,content:t,images:a?n:void 0,attachments:d?s:void 0};this.setEntries(h=>[...h,i]);const m=[];if(t&&m.push({type:"text",text:t}),a)for(const h of n)m.push({type:"image",source:{type:"base64",media_type:h.mimeType,data:h.data}});if(d){for(const h of s)if(h.kind==="text"||h.kind==="table"){const w=`📎 ${h.name}${h.size!=null?` (${nr(h.size)})`:""}`,v=h.textContent||"(空文件)";m.push({type:"text",text:`${w}
81
+ */const Gn=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],Yn=L("triangle-alert",Gn);function rs(){return{tasks:{}}}const $t=3e4;function De(r){const t=r.trim();if(!t)return"agent";const n=t.split(/\s+/).slice(0,2).join(" ");return n.length>40?n.slice(0,40)+"…":n}function Jn(r,t){var i,m,y,f,h,w,v,M,u,c,b,p;const n=t.subtype;if(n!=="task_started"&&n!=="task_progress"&&n!=="task_notification")return r;const s=t.task_id;if(!s)return r;const a=Date.now(),d=r.tasks[s];if(n==="task_started"){if(d)return{tasks:{...r.tasks,[s]:{...d,description:t.description??d.description,name:De(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 g=t.description??"";return{tasks:{...r.tasks,[s]:{taskId:s,name:De(g),description:g,taskType:t.task_type,workflowName:t.workflow_name,prompt:t.prompt,toolUseId:t.tool_use_id,status:"running",startTime:a}}}}if(n==="task_progress"){if(!d){const g=t.description??"";return{tasks:{...r.tasks,[s]:{taskId:s,name:De(g),description:g,toolUseId:t.tool_use_id,status:"running",startTime:a,tokenCount:(i=t.usage)==null?void 0:i.total_tokens,toolUseCount:(m=t.usage)==null?void 0:m.tool_uses,durationMs:(y=t.usage)==null?void 0:y.duration_ms,lastToolName:t.last_tool_name,summary:t.summary}}}}return{tasks:{...r.tasks,[s]:{...d,description:t.description??d.description,tokenCount:((f=t.usage)==null?void 0:f.total_tokens)??d.tokenCount,toolUseCount:((h=t.usage)==null?void 0:h.tool_uses)??d.toolUseCount,durationMs:((w=t.usage)==null?void 0:w.duration_ms)??d.durationMs,lastToolName:t.last_tool_name??d.lastToolName,summary:t.summary??d.summary}}}}return d?{tasks:{...r.tasks,[s]:{...d,status:t.status??"completed",endTime:a,finalSummary:t.summary??d.finalSummary,outputFile:t.output_file??d.outputFile,tokenCount:((c=t.usage)==null?void 0:c.total_tokens)??d.tokenCount,toolUseCount:((b=t.usage)==null?void 0:b.tool_uses)??d.toolUseCount,durationMs:((p=t.usage)==null?void 0:p.duration_ms)??d.durationMs,evictAfter:a+$t}}}:{tasks:{...r.tasks,[s]:{taskId:s,name:De(t.summary??""),description:t.summary??"",status:t.status??"completed",startTime:a,endTime:a,finalSummary:t.summary,outputFile:t.output_file,tokenCount:(v=t.usage)==null?void 0:v.total_tokens,toolUseCount:(M=t.usage)==null?void 0:M.tool_uses,durationMs:(u=t.usage)==null?void 0:u.duration_ms,evictAfter:a+$t}}}}function Xn(r,t=Date.now()){return Object.values(r.tasks).filter(n=>n.evictAfter===void 0||n.evictAfter>t).sort((n,s)=>n.startTime-s.startTime)}function Zn(r){if(!r||typeof r!="object"||Array.isArray(r))return null;const t=r,n={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(n).some(Boolean)?n:null}function It(r,t){const n=[];if(Array.isArray(r)){for(const s of r){if(!s||typeof s!="object")continue;const a=s;if(typeof a.name!="string"||!a.name)continue;const d=a.type==="prompt"||a.type==="local"||a.type==="local-jsx"?a.type:void 0;n.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(n.length>0)return n}if(Array.isArray(t))for(const s of t)typeof s=="string"&&s&&n.push({name:s});return n}function Dt(r){const t=r.raw&&typeof r.raw=="object"&&!Array.isArray(r.raw)?r.raw:r,n=It(t.slash_command_details??r.slash_command_details,t.slash_commands??r.slash_commands),s=It(t.skill_details??r.skill_details,t.skills??r.skills),a=Zn(t.remote_capabilities??r.remote_capabilities);return n.length===0&&s.length===0&&!a?null:{commands:n,skills:s,capabilities:a}}class er{constructor(t){T(this,"listeners",new Set);T(this,"stateListeners",new Set);T(this,"eventSource",null);T(this,"sessionId",null);T(this,"_lastSeqNum",0);T(this,"lastFrameAt",0);T(this,"firstEventAfterOpen",!1);T(this,"watchdogTimer",null);T(this,"visibilityHandler",null);T(this,"reconnectTimer",null);T(this,"reconnectAttempts",0);T(this,"_state","idle");T(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`,n=new EventSource(t,{withCredentials:!0});this.eventSource=n,this.lastFrameAt=Date.now(),this.firstEventAfterOpen=!0,n.addEventListener("open",()=>{this.lastFrameAt=Date.now(),this.reconnectAttempts=0,this.firstEventAfterOpen=!0,this.setState("open")}),n.addEventListener("ping",()=>{this.lastFrameAt=Date.now()}),n.addEventListener("message",s=>{this.lastFrameAt=Date.now();try{const a=JSON.parse(s.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{}}),n.addEventListener("error",()=>{n.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),n=Math.max(0,t+t*.25*(2*Math.random()-1));this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnect()},n)}async reconnect(){this.sessionId&&(await Ls(),this.sessionId&&this.openStream())}setState(t){if(this._state!==t){this._state=t;for(const n of this.stateListeners)n(t,{})}}notifyResync(){for(const t of this.stateListeners)t(this._state,{resync:!0})}}const re=new er;function tt(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(n=>n.type==="text"&&typeof n.text=="string").map(n=>n.text).join("")}return""}function qt(r,t){for(let n=r.length-1;n>=0;n--){const s=r[n];if(s&&s.type==="tool_call"&&s.toolCall.id===t)return n}return-1}const st="streaming-";function tr(r){const t=r.message;if(!t||typeof t!="object"||!Array.isArray(t.content))return"";const n=[];for(const s of t.content)if((s==null?void 0:s.type)==="thinking"){const a=typeof s.thinking=="string"&&s.thinking||typeof s.text=="string"&&s.text||"";a&&n.push(a)}return n.join("")}function Pt(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 Ut(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 n=t.raw;if(n&&typeof n=="object"&&!Array.isArray(n)){const s=n.target_event_id;if(typeof s=="string"&&s)return s}return""}class sr{constructor(t,n,s){T(this,"sessionId");T(this,"setEntries");T(this,"unsub",null);T(this,"unsubState",null);T(this,"onStatusChange");T(this,"onError");T(this,"onPermissionRequest");T(this,"onModelsStateChange");T(this,"onSubagentUpdate");T(this,"onControlResponse");T(this,"onPermissionModeChange");T(this,"onUsageChange");T(this,"onElicitationRequest");T(this,"onWorkerInfoChange");T(this,"subagentState",rs());T(this,"seenUuids",new Set);T(this,"seenToolCallIds",new Set);T(this,"postedUserUuids",new Set);T(this,"pendingControlRequests",new Map);T(this,"turnEnded",!1);T(this,"userSinceTurnEnd",!1);T(this,"closed",!1);this.sessionId=t,this.setEntries=n,this.onStatusChange=s==null?void 0:s.onStatusChange,this.onError=s==null?void 0:s.onError,this.onPermissionRequest=s==null?void 0:s.onPermissionRequest,this.onModelsStateChange=s==null?void 0:s.onModelsStateChange,this.onSubagentUpdate=s==null?void 0:s.onSubagentUpdate,this.onControlResponse=s==null?void 0:s.onControlResponse,this.onPermissionModeChange=s==null?void 0:s.onPermissionModeChange,this.onUsageChange=s==null?void 0:s.onUsageChange,this.onElicitationRequest=s==null?void 0:s.onElicitationRequest,this.onWorkerInfoChange=s==null?void 0:s.onWorkerInfoChange}markClosed(){this.closed=!0}async init(){await this.loadHistory(),this.connectSSE()}async loadHistory(){var w,v,M,u,c,b;const{events:t}=await qs(this.sessionId);if(!t||t.length===0)return;const n=new Set;for(const p of t){if(p.type!=="user"||p.direction==="inbound")continue;const g=(w=p.payload)==null?void 0:w.uuid;typeof g=="string"&&g&&n.add(g)}const s=[];let a=null;const d=()=>{a&&(s.push(a),a=null)};for(const p of t){const g=p.payload||{},k=g.uuid;if(typeof k=="string"&&k&&this.seenUuids.add(k),p.type==="tool_use"){const j=g.tool_call_id;typeof j=="string"&&j&&this.seenToolCallIds.add(j)}if(p.type==="user"){if(p.direction==="inbound"){const E=g.uuid;if(typeof E!="string"||!E||n.has(E))continue}d();const j=tt(g);j&&s.push({type:"user_message",id:p.id||`hist-user-${s.length}`,content:j})}else if(p.type==="assistant"){d();const j=tt(g);if(St(j))continue;const E=[],I=g.message;if(I&&typeof I=="object"&&Array.isArray(I.content)){for(const D of I.content)if(D.type==="tool_use"){const B=D.id;B&&this.seenToolCallIds.add(B),E.push({type:"tool_call",toolCall:{id:B||`hist-tool-${s.length}`,title:D.name||"tool",status:"complete",rawInput:D.input||{}}})}}if(j||E.length>0){a={type:"assistant_message",id:p.id||`hist-asst-${s.length}`,chunks:j?[{type:"message",text:j}]:[]},s.push(a);for(const D of E)s.push(D);a=null}}else if(p.type==="conversation_rewound"){const j=Ut(g);if(j){const E=s.findIndex(I=>Ct(I)===j);E>=0&&(s.length=E)}}else if(p.type==="tool_use"){const j=g,E={type:"tool_call",toolCall:{id:j.tool_call_id||`hist-tool-${s.length}`,title:j.tool_name||"tool",status:"complete",rawInput:j.tool_input||{}}};s.push(E)}else if(p.type==="tool_result"){const j=g,E=qt(s,j.tool_call_id||"");if(E>=0){const I=s[E];s[E]={type:"tool_call",toolCall:{...I.toolCall,rawOutput:{output:j.content||j.output||""}}}}}}d();let i=null;for(const p of t){if(p.type!=="task_state")continue;const g=p.payload||{};Array.isArray(g.tasks)&&(i=g.tasks)}if(i&&i.length>0){const p=Pt(i);p.length>0&&s.push({type:"plan",id:`plan-hist-${Date.now()}`,entries:p})}this.setEntries(s);let m=null,y=null,f=null,h=null;for(const p of t){const g=p.payload||{};if(p.type==="user"?h="user":(p.type==="result"||p.type==="result_success"||p.type==="interrupt")&&(h="turn_end"),p.type==="system"&&(g.subtype==="init"||((v=g.raw)==null?void 0:v.subtype)==="init")&&(y=Dt(g)),p.type==="models_state"){const k=g.raw,j=k&&typeof k=="object"?k.models_state:g.models_state;j&&Array.isArray(j.availableModels)&&typeof j.currentModelId=="string"&&(m=j)}else if(p.type==="result"||p.type==="result_success"){const k=g.usage,j=typeof g.total_cost_usd=="number"?g.total_cost_usd:null;(k||j!==null)&&(f={inputTokens:((k==null?void 0:k.input_tokens)??0)+((k==null?void 0:k.cache_read_input_tokens)??0)+((k==null?void 0:k.cache_creation_input_tokens)??0),outputTokens:(k==null?void 0:k.output_tokens)??0,totalCostUsd:j})}}m&&((M=this.onModelsStateChange)==null||M.call(this,m)),y&&((u=this.onWorkerInfoChange)==null||u.call(this,y)),f&&((c=this.onUsageChange)==null||c.call(this,f)),this.turnEnded=h==="turn_end",this.userSinceTurnEnd=h==="user",this.turnEnded&&!this.closed&&((b=this.onStatusChange)==null||b.call(this,"idle"))}connectSSE(){re.connect(this.sessionId),this.unsub=re.onEvent(t=>this.handleEvent(t)),this.unsubState=re.onStateChange((t,n)=>{n.resync&&!this.closed&&this.loadHistory().catch(()=>{})})}disconnect(){this.unsub&&(this.unsub(),this.unsub=null),this.unsubState&&(this.unsubState(),this.unsubState=null),re.disconnect()}handleEvent(t){var a,d,i,m,y,f,h,w,v,M;const n=t.type,s=t.payload||{};switch(n){case"user":{if(this.userSinceTurnEnd=!0,t.direction==="inbound"){const u=s.uuid;if(typeof u!="string"||!u||this.postedUserUuids.has(u)||this.seenUuids.has(u))break;this.seenUuids.add(u);const c=tt(s);c&&this.setEntries(b=>[...b,{type:"user_message",id:t.id||`user-${Date.now()}`,content:c}])}break}case"assistant":{const u=s.uuid;if(typeof u=="string"&&u){if(this.seenUuids.has(u))break;this.seenUuids.add(u)}const c=typeof s.content=="string"?s.content:"";if(St(c))break;const b=tr(s);this.setEntries(g=>{const k=g[g.length-1];if((k==null?void 0:k.type)==="assistant_message"&&k.id.startsWith(st))return[...g.slice(0,-1),{...k,id:`assistant-${Date.now()}`,chunks:[...b?[{type:"thought",text:b}]:[],{type:"message",text:c}]}];if((k==null?void 0:k.type)==="assistant_message"){const j=k.chunks[k.chunks.length-1];return(j==null?void 0:j.type)==="message"?[...g.slice(0,-1),{...k,chunks:[...k.chunks.slice(0,-1),{type:"message",text:j.text+c}]}]:[...g.slice(0,-1),{...k,chunks:[...k.chunks,{type:"message",text:c}]}]}if(c&&c.trim()||b){const j={type:"assistant_message",id:`assistant-${Date.now()}`,chunks:[...b?[{type:"thought",text:b}]:[],...c?[{type:"message",text:c}]:[]]};return[...g,j]}return g});const p=s.message;if(p&&typeof p=="object"&&Array.isArray(p.content)){const g=p.content.filter(k=>k.type==="tool_use");for(const k of g){const j=k.id||`call-${Date.now()}-${Math.random().toString(16).slice(2,8)}`;if(this.seenToolCallIds.has(j))continue;this.seenToolCallIds.add(j);const E={id:j,title:k.name||"tool",status:"running",rawInput:k.input||{}};this.setEntries(I=>[...I,{type:"tool_call",toolCall:E}])}}break}case"tool_use":{const u=s,c=u.tool_call_id||`call-${Date.now()}`;if(this.seenToolCallIds.has(c))break;this.seenToolCallIds.add(c);const b={id:c,title:u.tool_name||"tool",status:"running",rawInput:u.tool_input||{}};this.setEntries(p=>[...p,{type:"tool_call",toolCall:b}]);break}case"tool_result":{const u=s,c=u.tool_call_id||"";this.setEntries(b=>{const p=qt(b,c);if(p<0)return b;const g=b[p];return b.map((k,j)=>j===p?{type:"tool_call",toolCall:{...g.toolCall,status:"complete",rawOutput:{output:u.content||u.output||""}}}:k)});break}case"control_request":case"permission_request":{const u=s.request;if(u&&u.subtype==="can_use_tool"){const c=s.request_id||"",b=u.tool_name||"unknown",p=u.input||u.tool_input||{},g=u.description||"",k=Array.isArray(u.permission_suggestions)?u.permission_suggestions:[];this.setEntries(j=>{const E=[...j].reverse().findIndex(I=>I.type==="tool_call");if(E>=0){const I=j.length-1-E,D=j[I];if(D.toolCall.status==="running")return j.map((B,X)=>X===I?{type:"tool_call",toolCall:{...D.toolCall,status:"waiting_for_confirmation",permissionRequest:{requestId:c,options:[]}}}:B)}return j}),(a=this.onPermissionRequest)==null||a.call(this,{requestId:c,toolName:b,toolInput:p,description:g,suggestions:k})}else u&&u.subtype==="elicitation"&&((d=this.onElicitationRequest)==null||d.call(this,{requestId:s.request_id||"",serverName:u.mcp_server_name||"",message:u.message||"",mode:u.mode==="url"?"url":"form",url:typeof u.url=="string"?u.url:void 0,requestedSchema:u.requested_schema||void 0}));break}case"conversation_rewound":{const u=Ut(s);u&&this.setEntries(c=>{const b=c.findIndex(p=>Ct(p)===u);return b===-1?c:c.slice(0,b)});break}case"session_status":{if(Ps(s)){this.setEntries([]);break}if(typeof s.status=="string"){if(qe(s.status))this.closed=!0;else if(this.closed)break;if(s.status==="running"&&this.turnEnded&&!this.userSinceTurnEnd)break;(i=this.onStatusChange)==null||i.call(this,s.status)}break}case"error":{const u=String(s.message||s.content||"Unknown error");(m=this.onError)==null||m.call(this,u);break}case"models_state":{const u=s.raw,c=typeof u=="object"&&u!==null?u.models_state:s.models_state;c&&Array.isArray(c.availableModels)&&typeof c.currentModelId=="string"&&((y=this.onModelsStateChange)==null||y.call(this,c));break}case"system":{const u=s.raw,c=u&&typeof u=="object"?u:s,b=typeof c.subtype=="string"?c.subtype:void 0;if(b==="task_started"||b==="task_progress"||b==="task_notification"){const g={subtype:b,task_id:typeof c.task_id=="string"?c.task_id:void 0,tool_use_id:typeof c.tool_use_id=="string"?c.tool_use_id:void 0,description:typeof c.description=="string"?c.description:void 0,task_type:typeof c.task_type=="string"?c.task_type:void 0,workflow_name:typeof c.workflow_name=="string"?c.workflow_name:void 0,prompt:typeof c.prompt=="string"?c.prompt:void 0,usage:c.usage&&typeof c.usage=="object"?c.usage:void 0,last_tool_name:typeof c.last_tool_name=="string"?c.last_tool_name:void 0,summary:typeof c.summary=="string"?c.summary:void 0,status:c.status==="completed"||c.status==="failed"||c.status==="stopped"?c.status:void 0,output_file:typeof c.output_file=="string"?c.output_file:void 0};this.subagentState=Jn(this.subagentState,g)}const p=typeof c.permissionMode=="string"?c.permissionMode:typeof s.permissionMode=="string"?s.permissionMode:null;if(p&&((f=this.onPermissionModeChange)==null||f.call(this,p)),b==="init"){const g=Dt(s);g&&((h=this.onWorkerInfoChange)==null||h.call(this,g))}break}case"control_response":{const u=s.response;if(u&&typeof u=="object"){const c=typeof u.request_id=="string"?u.request_id:"",b=typeof u.subtype=="string"?u.subtype:"";if(c){(w=this.onControlResponse)==null||w.call(this,{subtype:b,requestId:c,error:typeof u.error=="string"?u.error:void 0});const p=this.pendingControlRequests.get(c);p&&(this.pendingControlRequests.delete(c),p({data:b==="success"&&u.response&&typeof u.response=="object"?u.response:null,...b==="error"&&typeof u.error=="string"?{error:u.error}:{}}))}}break}case"stream_event":{const u=s.event;if(!u||typeof u.type!="string")break;if(u.type==="content_block_delta"){const c=u.delta;if(!c||typeof c.type!="string")break;const b=c.type==="text_delta"?"message":c.type==="thinking_delta"?"thought":null;if(!b)break;const p=c.text??c.thinking;if(typeof p!="string"||!p)break;this.appendStreamingDelta(b,p)}break}case"partial_assistant":{const u=typeof s.content=="string"?s.content:"";u&&this.appendStreamingDelta("message",u);break}case"result":case"result_success":{this.turnEnded=!0,this.userSinceTurnEnd=!1,this.closed||(v=this.onStatusChange)==null||v.call(this,"idle");const u=s.usage,c=typeof s.total_cost_usd=="number"?s.total_cost_usd:null;if(u||c!==null){const j=((u==null?void 0:u.input_tokens)??0)+((u==null?void 0:u.cache_read_input_tokens)??0)+((u==null?void 0:u.cache_creation_input_tokens)??0);(M=this.onUsageChange)==null||M.call(this,{inputTokens:j,outputTokens:(u==null?void 0:u.output_tokens)??0,totalCostUsd:c})}const b=typeof s.subtype=="string"?s.subtype:"",p=s.raw&&typeof s.raw=="object"?s.raw:void 0,k=(typeof s.result=="string"?s.result:typeof(p==null?void 0:p.result)=="string"?p.result:"").trim();b.startsWith("error_")&&k&&this.setEntries(j=>[...j,{type:"command_output",id:`exit-error-${typeof s.uuid=="string"?s.uuid:Date.now()}`,commandName:"worker",inputText:"",title:"Worker 进程异常退出",outputText:k,variant:"error"}]);break}case"task_state":{const u=Array.isArray(s.tasks)?s.tasks:[];if(u.length===0)break;const c=Pt(u);if(c.length===0)break;this.setEntries(b=>[...b.filter(g=>g.type!=="plan"),{type:"plan",id:`plan-${s.task_list_id||Date.now()}`,entries:c}]);break}}}appendStreamingDelta(t,n){this.setEntries(s=>{const a=s[s.length-1];if((a==null?void 0:a.type)==="assistant_message"&&a.id.startsWith(st)){const i=a.chunks[a.chunks.length-1];return(i==null?void 0:i.type)===t?[...s.slice(0,-1),{...a,chunks:[...a.chunks.slice(0,-1),{type:t,text:i.text+n}]}]:[...s.slice(0,-1),{...a,chunks:[...a.chunks,{type:t,text:n}]}]}const d={type:"assistant_message",id:`${st}${Date.now()}`,chunks:[{type:t,text:n}]};return[...s,d]})}async sendMessage(t,n,s){var f;const a=n&&n.length>0,d=s&&s.length>0;if(!t.trim()&&!a&&!d)return;const i={type:"user_message",id:`user-${Date.now()}`,content:t,images:a?n:void 0,attachments:d?s:void 0};this.setEntries(h=>[...h,i]);const m=[];if(t&&m.push({type:"text",text:t}),a)for(const h of n)m.push({type:"image",source:{type:"base64",media_type:h.mimeType,data:h.data}});if(d){for(const h of s)if(h.kind==="text"||h.kind==="table"){const w=`📎 ${h.name}${h.size!=null?` (${nr(h.size)})`:""}`,v=h.textContent||"(空文件)";m.push({type:"text",text:`${w}
82
82
  \`\`\`
83
83
  ${v}
84
84
  \`\`\``})}else if(h.kind==="directory"){const w=`📁 目录: ${h.name}${h.files!=null?` (${h.files.length} 个文件)`:""}`,v=h.textContent||"(空目录)";m.push({type:"text",text:`${w}
85
- ${v}`})}}const y=m.length===1&&m[0].type==="text"?m[0].text||t:m.length>0?m:t;try{const h=ne();this.postedUserUuids.add(h);const w=await Us(this.sessionId,{type:"user",uuid:h,content:t,message:{content:y}}),v=(f=w==null?void 0:w.event)==null?void 0:f.id;v&&this.setEntries(M=>M.map(u=>u.type==="user_message"&&u.id===i.id?{...u,id:v}:u))}catch(h){throw this.setEntries(w=>w.filter(v=>!(v.type==="user_message"&&v.id===i.id))),h}}async respondPermission(t,n,s){await Q(this.sessionId,{type:"permission_response",approved:n,request_id:t,...s}),this.setEntries(a=>a.map(d=>{var i;return d.type!=="tool_call"||((i=d.toolCall.permissionRequest)==null?void 0:i.requestId)!==t?d:{type:"tool_call",toolCall:{...d.toolCall,status:n?"running":"rejected",permissionRequest:void 0}}}))}async interrupt(){this.setEntries(t=>t.map(n=>n.type!=="tool_call"||n.toolCall.status!=="running"&&n.toolCall.status!=="waiting_for_confirmation"?n:{type:"tool_call",toolCall:{...n.toolCall,status:"canceled",permissionRequest:void 0}})),await Os(this.sessionId)}async setPermissionMode(t){const n=ne();return await Q(this.sessionId,{type:"control_request",request_id:n,request:{subtype:"set_permission_mode",mode:t}}),n}async controlRoundTrip(t,n=8e3){const s=ne(),a=new Promise(i=>{this.pendingControlRequests.set(s,i)}),d=setTimeout(()=>{const i=this.pendingControlRequests.get(s);i&&(this.pendingControlRequests.delete(s),i({data:null,error:"timeout"}))},n);try{return await Q(this.sessionId,{type:"control_request",request_id:s,request:t}),await a}catch(i){throw this.pendingControlRequests.delete(s),i}finally{clearTimeout(d)}}async searchFiles(t,n=20){const s=await this.controlRoundTrip({subtype:"file_search",query:t,limit:n});try{if(!s.data||!Array.isArray(s.data.suggestions))return[];const a=[];for(const d of s.data.suggestions)d&&typeof d=="object"&&typeof d.path=="string"&&a.push(d.path);return a}catch{return[]}}async respondElicitation(t,n,s){await Q(this.sessionId,{type:"permission_response",approved:n==="accept",request_id:t,response:{subtype:"success",request_id:t,response:{action:n,...s?{content:s}:{}}}})}async askSideQuestion(t){const n=await this.controlRoundTrip({subtype:"side_question",question:t},12e4);if(n.error||!n.data)return null;const s=n.data.response;return typeof s=="string"?s: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 n=[];for(const s of t.data.sessions){if(!s||typeof s!="object")continue;const a=s;typeof a.session_id!="string"||!a.session_id||n.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 n}async resumeSession(t){const n=await this.controlRoundTrip({subtype:"resume_session",session_id:t},3e4);if(!n.data)throw new Error(n.error??"resume_session failed");return{title:typeof n.data.title=="string"?n.data.title:null,messageCount:typeof n.data.message_count=="number"?n.data.message_count:0}}async setEffort(t){const n=ne();return await Q(this.sessionId,{type:"control_request",request_id:n,request:{subtype:"set_effort",...t?{effort:t}:{effort:null}}}),n}async setThinkingBudget(t){const n=ne();return await Q(this.sessionId,{type:"control_request",request_id:n,request:{subtype:"set_max_thinking_tokens",max_thinking_tokens:t}}),n}async getContextUsage(){const t=await this.controlRoundTrip({subtype:"get_context_usage"});try{if(!t.data)return null;const n=t.data.totalTokens,s=t.data.rawMaxTokens,a=t.data.percentage;if(typeof n!="number"||typeof s!="number")return null;const d=t.data.categories,i=Array.isArray(d)?d.filter(m=>!!m&&typeof m=="object"&&typeof m.name=="string").map(m=>({name:m.name,tokens:typeof m.tokens=="number"?m.tokens:0,...m.isDeferred===!0?{isDeferred:!0}:{}})):void 0;return{totalTokens:n,rawMaxTokens:s,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 n=await this.controlRoundTrip({subtype:"stop_task",task_id:t});try{return n.error?{ok:!1,error:n.error==="timeout"?"停止请求超时":n.error}:{ok:!0}}catch{return{ok:!1,error:"停止请求失败"}}}async getMcpServers(){var a;const n=(a=(await this.controlRoundTrip({subtype:"mcp_status"})).data)==null?void 0:a.mcpServers;if(!Array.isArray(n))return[];const s=[];for(const d of n){if(!d||typeof d!="object")continue;const i=d;if(typeof i.name!="string"||!i.name)continue;const m=i.status;if(m!=="connected"&&m!=="failed"&&m!=="needs-auth"&&m!=="pending"&&m!=="disabled")continue;const y=i.serverInfo,f=i.config;s.push({name:i.name,status:m,...y&&typeof y.name=="string"&&typeof y.version=="string"?{serverInfo:{name:y.name,version:y.version}}:{},...typeof i.error=="string"&&i.error?{error:i.error}:{},...typeof(f==null?void 0:f.url)=="string"&&f.url?{url:f.url}:{},...Array.isArray(i.tools)?{toolCount:i.tools.length}:{}})}return s}async toggleMcpServer(t,n){const s=await this.controlRoundTrip({subtype:"mcp_toggle",serverName:t,enabled:n},15e3);return s.error?{ok:!1,error:s.error==="timeout"?"请求超时":s.error}:{ok:!0}}async reconnectMcpServer(t){const n=await this.controlRoundTrip({subtype:"mcp_reconnect",serverName:t},2e4);return n.error?{ok:!1,error:n.error==="timeout"?"请求超时":n.error}:{ok:!0}}async getRemoteSettings(){const n=(await this.controlRoundTrip({subtype:"get_settings"})).data;if(!n)return null;const s=n.applied,a=n.effective&&typeof n.effective=="object"&&!Array.isArray(n.effective)?n.effective:{},d=n.sources,i=[];if(Array.isArray(d))for(const m of d){if(!m||typeof m!="object")continue;const y=m;typeof y.source=="string"&&i.push({source:y.source,settings:y.settings&&typeof y.settings=="object"&&!Array.isArray(y.settings)?y.settings:{}})}return{applied:{model:typeof(s==null?void 0:s.model)=="string"?s.model:null,effort:typeof(s==null?void 0:s.effort)=="string"?s.effort:null},effective:a,sources:i}}async applyFlagSettings(t){const n=await this.controlRoundTrip({subtype:"apply_flag_settings",settings:t},15e3);return n.error?{ok:!1,error:n.error==="timeout"?"请求超时":n.error}:{ok:!0}}async rewindToMessage(t){await Fs(this.sessionId,t)}async endSession(t){await Q(this.sessionId,{type:"control_request",request_id:ne(),request:{subtype:"end_session",...t?{reason:t}:{}}})}}function nr(r){return r<1024?`${r} B`:r<1024*1024?`${(r/1024).toFixed(1)} KB`:`${(r/(1024*1024)).toFixed(1)} MB`}function rr(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 ar(r){return r?Date.now()-r<6e4:!1}function or({onClose:r,session:t,liveStatus:n,pendingPermissions:s,onInterrupt:a,onDelete:d,onEndSession:i}){const[m,y]=l.useState(!1),f=async()=>{await navigator.clipboard.writeText(t.id),y(!0),setTimeout(()=>y(!1),1500)},[h,w]=l.useState(!1),v=async()=>{if(!(!i||h)&&window.confirm("结束 worker 会话?正在进行的回合将被中止,会话随后归档。")){w(!0);try{await i(),r()}catch{w(!1)}}},M=s.length,u=t.worker,c=t.work_item,b=t.environment;return e.jsx(ie,{open:!0,onOpenChange:p=>{p||r()},children:e.jsxs(le,{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(ce,{children:e.jsx(de,{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(_n,{className:"h-3.5 w-3.5"}),"Status"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gt,{status:n||t.status||"unknown"}),e.jsx("span",{className:"text-xs text-text-muted",children:u&&(ar(u.last_heartbeat_at)?"· worker online":"· worker offline")})]}),e.jsxs("dl",{className:"space-y-1 text-xs text-text-muted",children:[u&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(Et,{className:"h-3 w-3"}),"Heartbeat"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:rr(u.last_heartbeat_at)})]}),b&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(es,{className:"h-3 w-3"}),"Environment"]}),e.jsx("dd",{className:"truncate text-text-secondary",children:b.machine_name||b.id})]}),t.created_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(Et,{className:"h-3 w-3"}),"Created"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:Yt(t.created_at)})]})]})]}),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(ve,{className:"h-3.5 w-3.5"}),"Pending Actions"]}),M>0?e.jsxs("div",{className:"rounded-md bg-status-warning/10 px-3 py-2 text-xs text-status-warning",children:[M," permission request",M>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(Hn,{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"}),i&&e.jsx("button",{onClick:v,disabled:h,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:"通知 worker 中止在途回合并退出,随后归档会话",children:h?"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(Bs,{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($n,{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:f,className:"text-text-muted hover:text-text-primary transition-colors flex-shrink-0",title:"Copy session id",children:m?"✓":"⧉"})]})]}),c&&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:c.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:c.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})]}),b&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Worker type"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:b.worker_type})]})]})]})]})]})})}const ir={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"},lr={connected:"已连接",failed:"失败","needs-auth":"待认证",pending:"连接中",disabled:"已禁用"};function cr({onClose:r,fetchServers:t,onToggle:n,onReconnect:s}){const[a,d]=l.useState(null),[i,m]=l.useState(null),[y,f]=l.useState(null),[h,w]=l.useState(null),v=l.useCallback(async()=>{f(null),w(null);try{const c=await t();d(c),m(null)}catch(c){Pe("[McpPanel] fetch failed",c),m("获取 MCP 状态失败 — worker 可能不支持")}},[t]);l.useEffect(()=>{v()},[v]);const M=async c=>{const b=c.status==="disabled";f(`toggle:${c.name}`),w(null);try{const p=await n(c.name,b);p.ok||w(p.error||"切换失败")}finally{await v()}},u=async c=>{f(`reconnect:${c.name}`),w(null);try{const b=await s(c.name);b.ok||w(b.error||"重连失败")}finally{await v()}};return e.jsx(ie,{open:!0,onOpenChange:c=>{c||r()},children:e.jsxs(le,{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(ce,{children:e.jsxs(de,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(ss,{className:"h-4 w-4"}),"MCP 服务器"]})}),e.jsxs("div",{className:"mt-3 space-y-3 text-sm",children:[h&&e.jsx("div",{className:"rounded-md bg-status-error/10 px-3 py-2 text-xs text-status-error",children:h}),a===null&&!i&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(ve,{className:"h-3.5 w-3.5 animate-spin"}),"加载 MCP 状态…"]}),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:"没有配置 MCP 服务器"}),a==null?void 0:a.map(c=>{const b=y===`toggle:${c.name}`,p=y===`reconnect:${c.name}`,g=c.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:c.name}),e.jsx("span",{className:`flex-shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium ${ir[c.status]}`,children:lr[c.status]})]}),e.jsxs("div",{className:"mt-0.5 truncate text-xs text-text-muted",children:[c.serverInfo?`${c.serverInfo.name} v${c.serverInfo.version}`:c.url||"stdio",c.toolCount!==void 0&&` · ${c.toolCount} 工具`]}),c.error&&e.jsx("div",{className:"mt-1 truncate text-xs text-status-error",title:c.error,children:c.error})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>void u(c),disabled:p||g,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:"重连",children:e.jsx(hn,{className:`h-3.5 w-3.5 ${p?"animate-spin":""}`})}),e.jsx("button",{type:"button",role:"switch","aria-checked":!g,onClick:()=>void M(c),disabled:b,className:`relative h-5 w-9 rounded-full transition-colors disabled:opacity-50 ${g?"bg-surface-3":"bg-brand"}`,title:g?"启用":"禁用",children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${g?"left-0.5":"left-4.5"}`})})]})]})},c.name)})]})]})})}function dr(r){if(r==null)return"(未设置)";if(typeof r=="string")return r;try{return JSON.stringify(r)}catch{return String(r)}}function Ot(r){if(r==null)return"(未设置)";if(typeof r=="object")try{return JSON.stringify(r,null,2)}catch{return String(r)}return String(r)}function ur({onClose:r,fetchSettings:t,onApply:n}){const[s,a]=l.useState(null),[d,i]=l.useState(null),[m,y]=l.useState(""),[f,h]=l.useState(null),[w,v]=l.useState(null),[M,u]=l.useState(null),[c,b]=l.useState(!1),p=l.useCallback(async()=>{h(null),v(null),u(null),b(!1);try{const C=await t();a(C),i(C?null:"获取设置失败 — worker 可能不支持")}catch(C){Pe("[SettingsDrawer] fetch failed",C),i("获取设置失败 — worker 可能不支持")}},[t]);l.useEffect(()=>{p()},[p]);const g=l.useMemo(()=>s?Object.entries(s.effective).filter(([,C])=>C!==void 0).sort(([C],[U])=>C.localeCompare(U)):[],[s]),k=l.useMemo(()=>{const C=m.trim().toLowerCase();return C?g.filter(([U,K])=>`${U} ${dr(K)}`.toLowerCase().includes(C)):g},[g,m]),j=C=>typeof C[1]=="boolean",E=l.useMemo(()=>k.filter(j),[k]),I=l.useMemo(()=>k.filter(C=>!j(C)),[k]),q=l.useMemo(()=>M===null?null:g.find(([C])=>C===M)??null,[g,M]),B=async()=>{if(q)try{await navigator.clipboard.writeText(Ot(q[1])),b(!0),window.setTimeout(()=>b(!1),1500)}catch(C){Pe("[SettingsDrawer] copy failed",C)}},X=async(C,U)=>{h(C),v(null);try{const K=await n({[C]:!U});K.ok||v(K.error||"写入失败")}finally{await p()}};return e.jsx(ie,{open:!0,onOpenChange:C=>{C||r()},children:e.jsxs(le,{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(ce,{children:e.jsxs(de,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(ns,{className:"h-4 w-4"}),"会话设置"]})}),e.jsxs("div",{className:"mt-3 space-y-4 text-sm",children:[w&&e.jsx("div",{className:"rounded-md bg-status-error/10 px-3 py-2 text-xs text-status-error",children:w}),s===null&&!d&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(ve,{className:"h-3.5 w-3.5 animate-spin"}),"加载设置…"]}),d&&e.jsx("p",{className:"text-xs text-status-error",children:d}),s&&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:"模型"}),e.jsx("code",{className:"font-mono text-text-secondary",children:s.applied.model||"(默认)"})]}),s.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:s.applied.effort})]}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-text-muted",children:"布尔开关写入会话级 flag 层(apply_flag_settings);只读项点击查看详情。"})]}),q?e.jsxs("section",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>{u(null),b(!1)},className:"flex items-center gap-1.5 text-xs text-text-muted transition-colors hover:text-text-primary",children:[e.jsx(Cn,{className:"h-3.5 w-3.5"}),"返回设置列表"]}),e.jsx("div",{className:"break-all font-mono text-xs font-medium text-text-primary",children:q[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-[11px] leading-relaxed text-text-secondary",children:Ot(q[1])}),e.jsxs("button",{type:"button",onClick:()=>void B(),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:[c?e.jsx(Ne,{className:"h-3.5 w-3.5 text-status-success"}):e.jsx(gn,{className:"h-3.5 w-3.5"}),c?"已复制":"复制值"]})]}):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(rt,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{value:m,onChange:C=>y(C.target.value),placeholder:"搜索设置项…",className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"})]}),k.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:"没有匹配的设置项"}),E.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("h3",{className:"text-[11px] font-medium uppercase tracking-wide text-text-muted",children:["可设置(",E.length,")"]}),E.map(([C,U])=>{const K=f===C;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:C}),e.jsx("button",{type:"button",role:"switch","aria-checked":U,disabled:K,onClick:()=>void X(C,U),className:`relative h-5 w-9 flex-shrink-0 rounded-full transition-colors disabled:opacity-50 ${U?"bg-brand":"bg-surface-3"}`,title:U?"关闭(写入 false)":"开启(写入 true)",children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${U?"left-4.5":"left-0.5"}`})})]},C)})]}),I.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("h3",{className:"text-[11px] font-medium uppercase tracking-wide text-text-muted",children:["只读(",I.length,")"]}),I.map(([C])=>e.jsxs("button",{type:"button",onClick:()=>u(C),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:"查看详情",children:[e.jsx("span",{className:"truncate font-mono text-xs text-text-primary",children:C}),e.jsx(Zt,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"})]},C))]})]})]})]})]})})}function mr({onClose:r,onAsk:t}){const[n,s]=l.useState([]),[a,d]=l.useState(""),[i,m]=l.useState(!1),y=async()=>{const f=a.trim();if(!f||i)return;const h=Date.now();s(w=>[...w,{id:h,question:f,answer:null}]),d(""),m(!0);try{const w=await t(f);s(v=>v.map(M=>M.id===h?{...M,answer:w??"没有获得回答(超时或 worker 不支持)",error:w===null}:M))}finally{m(!1)}};return e.jsx(ie,{open:!0,onOpenChange:f=>{f||r()},children:e.jsxs(le,{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(ce,{children:e.jsxs(de,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(ts,{className:"h-4 w-4"}),"旁路提问"]})}),e.jsx("p",{className:"mt-1 text-[11px] leading-relaxed text-text-muted",children:"针对当前会话上下文提问,不进入主对话、不消耗会话历史 — 适合「这个会话干了什么」式的快速核对。"}),e.jsxs("div",{className:"mt-3 flex-1 space-y-4 overflow-y-auto",children:[n.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:"还没有提问。在下方输入你的问题。"}),n.map(f=>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:f.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:f.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:f.error?"text-status-error":"",children:e.jsx(Hs,{children:f.answer})})})]})]},f.id))]}),e.jsxs("div",{className:"mt-3 flex items-end gap-2",children:[e.jsx("textarea",{value:a,onChange:f=>d(f.target.value),onKeyDown:f=>{f.key==="Enter"&&!f.shiftKey&&!f.nativeEvent.isComposing&&(f.preventDefault(),y())},rows:Math.min(4,Math.max(1,a.split(`
86
- `).length)),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 y(),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:"提问(Enter)",children:i?e.jsx(ve,{className:"h-4 w-4 animate-spin"}):e.jsx(Ws,{className:"h-4 w-4"})})]})]})})}const Ft="rcs:subagent-panel:collapsed";function xr(r){if(r<1e3)return"0s";const t=Math.floor(r/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60),s=t%60;if(n<60)return s?`${n}m${s}s`:`${n}m`;const a=Math.floor(n/60),d=n%60;return d?`${a}h${d}m`:`${a}h`}function fr(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 pr({status:r}){return r==="running"?e.jsx(ve,{className:"h-3 w-3 animate-spin text-brand"}):r==="completed"?e.jsx(Fn,{className:"h-3 w-3 text-status-success"}):r==="failed"||r==="stopped"?e.jsx(Ks,{className:"h-3 w-3 text-status-error"}):null}function hr({task:r,onStopTask:t}){const n=r.status==="running",s=n?r.durationMs??Date.now()-r.startTime:(r.endTime??Date.now())-r.startTime,a=fr(r.tokenCount),d=r.toolUseCount!==void 0&&r.toolUseCount>0?`${r.toolUseCount} tool${r.toolUseCount>1?"s":""}`:"",i=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(pr,{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:xr(s)})]}),e.jsx("div",{className:"mt-0.5 truncate text-text-secondary",children:i}),(a||d||r.lastToolName)&&e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 font-mono text-[10px] text-text-muted",children:[a&&e.jsxs("span",{children:["↕ ",a," tok"]}),d&&e.jsxs("span",{children:["· ",d]}),r.lastToolName&&e.jsxs("span",{className:"truncate",children:["· last: ",r.lastToolName]})]}),!n&&r.finalSummary&&e.jsx("div",{className:"mt-1 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:"停止此任务",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(zs,{className:"h-3.5 w-3.5"})})]})}function gr({state:r,onStopTask:t}){const[n,s]=l.useState(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Ft)==="1"}catch{return!1}}),a=()=>{s(f=>{const h=!f;try{window.localStorage.setItem(Ft,h?"1":"0")}catch{}return h})},[,d]=l.useState(0);l.useEffect(()=>{const f=Object.values(r.tasks).some(v=>v.status==="running"),h=Object.values(r.tasks).some(v=>v.status!=="running"&&v.evictAfter!==void 0);if(!f&&!h)return;const w=setInterval(()=>{d(v=>v+1)},1e3);return()=>clearInterval(w)},[r]);const i=Xn(r);if(i.length===0)return null;const m=i.filter(f=>f.status==="running").length,y=m>0?`${m} running`:`${i.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":!n,"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(Zt,{className:`h-3 w-3 transition-transform ${n?"":"rotate-90"}`}),e.jsx("span",{children:"Subagents"})]}),e.jsx("span",{children:y})]}),!n&&e.jsx("div",{id:"subagent-list",className:"space-y-1.5",children:i.map(f=>e.jsx(hr,{task:f,onStopTask:t},f.taskId))})]})})}function Lt(r,t){var a;const n=(a=t==null?void 0:t.find(d=>d.type==="addRules"||d.type==="replaceRules"))==null?void 0:a.rules,s=n==null?void 0:n[0];return s!=null&&s.ruleContent?`${s.toolName}(${s.ruleContent})`:s!=null&&s.toolName?s.toolName:r}function yr({requestId:r,toolName:t,toolInput:n,description:s,suggestions:a,onApprove:d,onApproveAlways:i,onReject:m}){const y=typeof n=="string"?n:JSON.stringify(n,null,2),f=Array.isArray(a)&&a.length>0;return e.jsxs("div",{className:"rounded-xl border border-warning-border/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-warning-border/15 text-warning-text",children:e.jsx(Yn,{className:"h-3 w-3"})}),e.jsx("span",{className:"text-sm font-semibold text-warning-text",children:"Permission Request"})]}),s&&e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:z(s)}),e.jsx("div",{className:"mb-2 font-mono text-xs font-bold text-text-primary",children:z(t)}),t!=="AskUserQuestion"&&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:Tt(y,500)}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:d,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light transition-colors",children:"Approve"}),f&&i&&e.jsxs("button",{onClick:i,className:"flex items-center gap-1.5 rounded-lg border border-brand/40 bg-brand/10 px-4 py-2 text-sm font-medium text-brand hover:bg-brand/20 transition-colors",title:`允许并记住规则:${Lt(t,a)}`,children:[e.jsx(Vn,{className:"h-3.5 w-3.5"}),"Always allow ",Tt(Lt(t,a),40)]}),e.jsx("button",{onClick:m,className:"rounded-lg bg-status-error/20 px-4 py-2 text-sm font-medium text-status-error hover:bg-status-error/30 transition-colors",children:"Reject"})]})]})}function br({questions:r,description:t,onSubmit:n,onSkip:s}){const[a,d]=l.useState({}),[i,m]=l.useState({}),[y,f]=l.useState(0),h=(u,c,b)=>{if(b){const p=a[u]||[],g=p.includes(c)?p.filter(k=>k!==c):[...p,c];d({...a,[u]:g})}else d({...a,[u]:c})},w=u=>{var b;const c=(b=i[u])==null?void 0:b.trim();c&&(d({...a,[u]:c}),m({...i,[u]:""}))},v=()=>{var c,b;const u={};for(const[p,g]of Object.entries(a)){const k=r[parseInt(p,10)];k&&(typeof g=="number"?u[p]=((b=(c=k.options)==null?void 0:c[g])==null?void 0:b.label)||String(g):Array.isArray(g)?u[p]=g.map(j=>{var E,I;return((I=(E=k.options)==null?void 0:E[j])==null?void 0:I.label)||String(j)}):u[p]=g)}n(u)};if(r.length<=1){const u=r[0]||{question:t,options:[],multiSelect:!1},c=u.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 text-text-primary",children:z(t||u.question||"Question")}),e.jsxs("div",{className:"space-y-2",children:[(u.options||[]).map((b,p)=>{const g=c?(a[0]||[]).includes(p):a[0]===p;return e.jsxs("button",{onClick:()=>h(0,p,c),className:ke("w-full rounded-lg border px-4 py-2.5 text-left text-sm 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",children:z(b.label)}),b.description&&e.jsx("div",{className:"mt-0.5 text-xs text-text-muted",children:z(b.description)})]},p)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:i[0]||"",onChange:b=>m({...i,0:b.target.value}),placeholder:"Other...",className:"flex-1 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",onKeyDown:b=>b.key==="Enter"&&w(0)}),e.jsx("button",{onClick:()=>w(0),className:"rounded-lg border border-border px-3 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Send"})]})]}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx("button",{onClick:v,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light transition-colors",children:"Submit"}),e.jsx("button",{onClick:s,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})}const M=r[y];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 text-text-primary",children:z(t||"Questions")}),e.jsx("div",{className:"mb-3 flex gap-1 overflow-x-auto",children:r.map((u,c)=>e.jsx("button",{onClick:()=>f(c),className:ke("rounded-md px-3 py-1.5 text-xs whitespace-nowrap transition-colors",y===c?"bg-brand/20 text-brand":"text-text-muted hover:bg-surface-2"),children:u.header||`Q${c+1}`},c))}),M&&e.jsx(wr,{question:M,qIdx:y,answers:a,otherTexts:i,onSelect:h,onOtherTextChange:(u,c)=>m({...i,[u]:c}),onOtherSubmit:w}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-text-muted",children:[y+1," / ",r.length]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:v,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light transition-colors",children:"Submit All"}),e.jsx("button",{onClick:s,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})]})}function wr({question:r,qIdx:t,answers:n,otherTexts:s,onSelect:a,onOtherTextChange:d,onOtherSubmit:i}){const m=r.multiSelect||!1;return e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:z(r.question)}),e.jsxs("div",{className:"space-y-2",children:[(r.options||[]).map((y,f)=>{const h=m?(n[t]||[]).includes(f):n[t]===f;return e.jsxs("button",{onClick:()=>a(t,f,m),className:ke("w-full rounded-lg border px-4 py-2.5 text-left text-sm transition-colors",h?"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",children:z(y.label)}),y.description&&e.jsx("div",{className:"mt-0.5 text-xs text-text-muted",children:z(y.description)})]},f)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:s[t]||"",onChange:y=>d(t,y.target.value),placeholder:"Other...",className:"flex-1 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",onKeyDown:y=>y.key==="Enter"&&i(t)}),e.jsx("button",{onClick:()=>i(t),className:"rounded-lg border border-border px-3 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Send"})]})]})]})}function jr({planContent:r,description:t,onSubmit:n}){const[s,a]=l.useState(null),[d,i]=l.useState(""),m=!r||!r.trim(),y=()=>{s&&n(s,s==="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",children:e.jsx(Ne,{className:"h-3 w-3",strokeWidth:2.5})}),e.jsx("span",{className:"text-sm font-semibold text-text-primary",children:m?"Exit plan mode?":"Ready to code?"})]}),!m&&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:kr(r)}}),e.jsx("div",{className:"space-y-2",children:m?e.jsxs(e.Fragment,{children:[e.jsx(je,{selected:s==="yes-default",onClick:()=>a("yes-default"),label:"Yes"}),e.jsx(je,{selected:s==="no",onClick:()=>a("no"),label:"No"})]}):e.jsxs(e.Fragment,{children:[e.jsx(je,{selected:s==="yes-accept-edits",onClick:()=>a("yes-accept-edits"),label:"Yes, auto-accept edits",desc:"Approve plan and auto-accept file edits"}),e.jsx(je,{selected:s==="yes-default",onClick:()=>a("yes-default"),label:"Yes, manually approve edits",desc:"Approve plan but confirm each edit"}),e.jsx(je,{selected:s==="no",onClick:()=>a("no"),label:"No, keep planning",desc:"Provide feedback to refine the plan"})]})}),s==="no"&&e.jsx("textarea",{value:d,onChange:f=>i(f.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 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:y,disabled:!s,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:"Submit"})})]})}function je({selected:r,onClick:t,label:n,desc:s}){return e.jsxs("button",{onClick:t,className:ke("w-full rounded-lg border px-4 py-2.5 text-left text-sm 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:ke("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",children:n})]}),s&&e.jsx("div",{className:"mt-0.5 pl-6 text-xs text-text-muted",children:s})]})}function kr(r){let t=z(r);return t=t.replace(/```(\w*)\n?([\s\S]*?)```/g,(n,s,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 vr({request:r,onSubmit:t}){const n=Nr(r.requestedSchema),s=_r(r.requestedSchema),[a,d]=l.useState({}),i=n.length===0||s.every(m=>(a[m]??"").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(Bt,{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 hover:bg-brand/10 transition-colors",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:r.url}),e.jsx(yn,{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:"完成"}),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:"取消"})]})]}):e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx(Bt,{serverName:r.serverName,message:r.message}),n.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:n.map(({name:m,prop:y})=>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:m}),s.includes(m)&&e.jsx("span",{className:"text-[10px] font-medium text-warning-text",children:"必填"})]}),y.description&&e.jsx("div",{className:"mb-1 text-xs text-text-muted",children:z(y.description)}),e.jsx("input",{type:y.type==="number"?"number":"text",value:a[m]??"",onChange:f=>d(h=>({...h,[m]:f.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"})]},m))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{const m={};for(const{name:y,prop:f}of n){const h=(a[y]??"").trim();h&&(m[y]=f.type==="number"?Number(h):h)}t("accept",m)},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:"提交"}),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:"拒绝"})]})]})}function Bt({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",children:e.jsx(Un,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-sm font-semibold text-text-primary",children:["MCP 请求输入 ",e.jsx("span",{className:"font-mono text-xs text-text-muted",children:z(r)})]})]}),t&&e.jsx("div",{className:"text-sm text-text-secondary",children:z(t)})]})}function Nr(r){const t=r==null?void 0:r.properties;return!t||typeof t!="object"?[]:Object.entries(t).filter(([,n])=>n&&typeof n=="object").map(([n,s])=>({name:n,prop:s}))}function _r(r){const t=r==null?void 0:r.required;return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}function Sr(r){const[t,n]=l.useState([]),[s,a]=l.useState(!0),[d,i]=l.useState(null),m=l.useCallback(async()=>{a(!0),i(null);try{const h=await Qs(r);n(h)}catch(h){i(h instanceof Error?h.message:"Failed to load shares")}finally{a(!1)}},[r]);l.useEffect(()=>{m()},[m]);const y=l.useCallback(async h=>{i(null);try{const w=await Vs(r,h);return await m(),w}catch(w){throw i(w instanceof Error?w.message:"Failed to create share"),w}},[r,m]),f=l.useCallback(async h=>{i(null);try{await Gs(r,h),await m()}catch(w){throw i(w instanceof Error?w.message:"Failed to revoke share"),w}},[r,m]);return{shares:t,isLoading:s,error:d,createShare:y,revokeShare:f,refresh:m}}function Cr({open:r,onClose:t,sessionId:n,sessionTitle:s}){Jt();const{shares:a,isLoading:d,error:i,createShare:m,revokeShare:y}=Sr(n),[f,h]=l.useState("user"),[w,v]=l.useState(""),[M,u]=l.useState(""),[c,b]=l.useState("read"),[p,g]=l.useState(""),[k,j]=l.useState(!1),[E,I]=l.useState(null),[q,B]=l.useState(""),[X,C]=l.useState(!1),[U,K]=l.useState(!1);l.useEffect(()=>{r&&(h("user"),v(""),u(""),b("read"),g(""),j(!1),I(null),B(""),C(!1),K(!1))},[r]);const _e=async()=>{j(!0),B(""),I(null);try{const A={grantedTo:f==="user"?{userId:w.trim()}:{teamId:M.trim()},permission:c};p.trim()&&(A.expiresAt=p.trim());const ue=await m(A);I(`${window.location.origin}/code/s/${ue.shareToken}`)}catch(A){B(A instanceof Error?A.message:"Failed to create share")}finally{j(!1)}},Se=async A=>{try{await y(A)}catch{}},G=async()=>{if(!E)return;K(!1);try{if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(E),C(!0),setTimeout(()=>C(!1),2e3);return}}catch{}const A=document.createElement("textarea");A.value=E,A.style.position="fixed",A.style.opacity="0",document.body.appendChild(A),A.select();try{document.execCommand("copy"),C(!0),setTimeout(()=>C(!1),2e3)}catch{K(!0)}document.body.removeChild(A)};return e.jsx(ie,{open:r,onOpenChange:A=>{A||t()},children:e.jsxs(le,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(ce,{children:e.jsxs(de,{className:"font-display text-lg font-semibold text-text-primary",children:[S("share.title"),s?`: ${s}`:""]})}),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:S("share.grantTo")}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("button",{onClick:()=>h("user"),className:`rounded-md px-3 py-1 text-sm transition-colors ${f==="user"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:S("share.user")}),e.jsx("button",{onClick:()=>h("team"),className:`rounded-md px-3 py-1 text-sm transition-colors ${f==="team"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:S("share.team")})]}),f==="user"?e.jsx(jn,{onSelect:v,placeholder:S("share.userIdPlaceholder"),actionLabel:S("share.selectUser")}):e.jsx("input",{type:"text",value:M,onChange:A=>u(A.target.value),placeholder:S("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"}),f==="user"&&w&&e.jsxs("p",{className:"mt-1 text-xs text-text-muted",children:[S("share.selectedUser"),": ",e.jsx("span",{className:"font-mono",children:w})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:S("share.permission")}),e.jsxs("select",{value:c,onChange:A=>b(A.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:S("share.permissionRead")}),e.jsx("option",{value:"write",children:S("share.permissionWrite")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:S("share.expiresAt")}),e.jsx("input",{type:"datetime-local",value:p,onChange:A=>g(A.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"})]}),(q||i)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:q||i}),E&&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:S("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:E}),e.jsx("button",{onClick:G,className:"shrink-0 rounded-md bg-brand px-2 py-1 text-xs text-white hover:bg-brand-light transition-colors",children:X?S("share.copied"):S("share.copy")})]}),U&&e.jsx("p",{className:"mt-1 text-xs text-status-error",children:S("share.copyFailed")})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"mb-2 text-sm font-medium text-text-secondary",children:S("share.existingShares")}),d?e.jsx("p",{className:"text-sm text-text-muted",children:S("share.loading")}):a.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:S("share.none")}):e.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto",children:a.map(A=>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:A.granted_to_user||A.granted_to_team||"Unknown"}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[A.permission==="write"?S("share.permissionWrite"):S("share.permissionRead"),A.expires_at?` · expires ${A.expires_at}`:""]})]}),e.jsx("button",{onClick:()=>Se(A.id),className:"shrink-0 rounded-md px-2 py-1 text-xs text-status-error hover:bg-surface-3 transition-colors",children:S("share.revoke")})]},A.id))})]})]}),e.jsxs(pn,{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:S("common.close")}),e.jsx("button",{onClick:_e,disabled:k||(f==="user"?!w.trim():!M.trim()),className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light disabled:opacity-50 transition-colors",children:k?S("common.creating"):S("share.createShare")})]})]})})}function Er(r){const t=new Date,n=new Date(t.getTime()-1440*60*1e3),s=(i,m)=>i.getFullYear()===m.getFullYear()&&i.getMonth()===m.getMonth()&&i.getDate()===m.getDate(),a={today:[],yesterday:[],earlier:[]};for(const i of r){const m=new Date(i.modified||0);s(m,t)?a.today.push(i):s(m,n)?a.yesterday.push(i):a.earlier.push(i)}return[["today","今天"],["yesterday","昨天"],["earlier","更早"]].map(([i,m])=>({label:m,items:a[i]})).filter(i=>i.items.length>0)}function Tr(r){return r?new Date(r).toLocaleString():""}function Mr({open:r,onClose:t,adapter:n,onResume:s}){const[a,d]=l.useState([]),[i,m]=l.useState(!1),[y,f]=l.useState("");l.useEffect(()=>{if(!r)return;let w=!1;return m(!0),f(""),d([]),n.listResumableSessions().then(v=>{w||d(v)}).catch(v=>{w||f(v instanceof Error?v.message:String(v))}).finally(()=>{w||m(!1)}),()=>{w=!0}},[r,n]);const h=l.useMemo(()=>Er(a),[a]);return e.jsx(ie,{open:r,onOpenChange:w=>{w||t()},children:e.jsxs(le,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(ce,{children:e.jsx(de,{className:"font-display text-lg font-semibold text-text-primary",children:"恢复历史对话"})}),e.jsxs("div",{className:"max-h-96 min-w-0 space-y-4 overflow-y-auto",children:[i&&e.jsx("p",{className:"py-6 text-center text-sm text-text-muted",children:"正在加载本地会话列表…"}),!i&&y&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:y}),!i&&!y&&a.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-text-muted",children:"没有可恢复的历史对话"}),!i&&!y&&h.map(w=>e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-xs font-medium text-text-muted",children:w.label}),e.jsx("div",{className:"space-y-1",children:w.items.map(v=>e.jsxs("button",{type:"button",onClick:()=>s(v),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:v.title}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[Tr(v.modified),v.gitBranch?` · ${v.gitBranch}`:""]})]},v.sessionId))})]},w.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:"取消"})})]})})}class Rr{constructor(t,n,s,a){T(this,"pending",null);this.current=t,this.apply=n,this.send=s,this.onError=a}set(t){if(t===this.current)return;const n=this.current;this.current=t,this.pending={requestId:null,previous:n},this.apply(t);try{Promise.resolve(this.send(t)).then(s=>{this.pending&&(this.pending.requestId=s)}).catch(s=>{this.rollback(n,Ht(s),"send")})}catch(s){this.rollback(n,Ht(s),"send")}}handleControlResponse(t){const n=this.pending;if(!n||n.requestId!==t.requestId)return!1;const{previous:s}=n;return this.pending=null,t.subtype==="error"&&this.rollback(s,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,n,s){var a;this.pending=null,this.current=t,this.apply(t),n&&((a=this.onError)==null||a.call(this,n,s))}}function Ht(r){return r instanceof Error?r.message:String(r)}function nt(r){const t=l.useRef(r);t.current=r;const n=l.useRef(null);n.current||(n.current=new Rr(r.value,a=>t.current.apply(a),a=>t.current.send(a),(a,d)=>{var i,m;return(m=(i=t.current).onError)==null?void 0:m.call(i,a,d)}));const s=n.current;return l.useEffect(()=>{s.adoptExternal(r.value)}),l.useMemo(()=>({set:a=>s.set(a),handleControlResponse:a=>s.handleControlResponse(a),sync:a=>s.sync(a)}),[s])}const as="rcs_context_usage_";function os(){try{if(typeof localStorage<"u")return localStorage}catch{}return null}function Wt(){return{totalTokens:0,rawMaxTokens:0,percentage:0}}function Ar(r){if(!r||typeof r!="object"||Array.isArray(r))return null;const t=r,{totalTokens:n,rawMaxTokens:s,percentage:a}=t;if(typeof n!="number"||typeof s!="number"||typeof a!="number")return null;const d=t.categories,i=Array.isArray(d)?d.filter(m=>!!m&&typeof m=="object"&&typeof m.name=="string").map(m=>({name:m.name,tokens:typeof m.tokens=="number"?m.tokens:0,...m.isDeferred===!0?{isDeferred:!0}:{}})):void 0;return{totalTokens:n,rawMaxTokens:s,percentage:a,...typeof t.model=="string"&&t.model?{model:t.model}:{},...i&&i.length>0?{categories:i}:{}}}function $r(r,t=os()){if(!t||!r)return null;try{const n=t.getItem(as+r);return n?Ar(JSON.parse(n)):null}catch{return null}}function Ir(r,t,n=os()){if(!(!n||!r))try{n.setItem(as+r,JSON.stringify(t))}catch{}}function qr(r){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/acp/relay/${r}`}function Dr(r){const t=qr(r),n=Js(),s=n?{proxyUrl:t,token:n}:{proxyUrl:t};return new Ys(s)}const ae=[{value:"default",label:"默认",description:"手动审批权限请求"},{value:"acceptEdits",label:"自动接受编辑",description:"自动允许文件编辑操作"},{value:"plan",label:"规划模式",description:"仅规划,不执行工具"},{value:"bypassPermissions",label:"跳过权限",description:"跳过所有权限检查"}],zt="rcs_permission_mode";function oe(r){return r<1e3?String(r):r<1e6?`${(r/1e3).toFixed(1)}k`:`${(r/1e6).toFixed(1)}M`}function Pr(r){const t=ae.findIndex(n=>n.value===r);return ae[(t+1+ae.length)%ae.length].value}const at=[{value:"off",label:"关闭思考",tokens:null,description:"不使用扩展思考"},{value:"on",label:"默认思考",tokens:0,description:"开启,使用默认预算"},{value:"8192",label:"8k",tokens:8192,description:"8192 tokens"},{value:"16384",label:"16k",tokens:16384,description:"16384 tokens"},{value:"32768",label:"32k",tokens:32768,description:"32768 tokens"}],Kt="rcs_thinking_budget",ot=[{value:"auto",effort:void 0,label:"自动",description:"使用模型默认 effort"},{value:"low",effort:"low",label:"low",description:"低推理力度"},{value:"medium",effort:"medium",label:"medium",description:"中推理力度"},{value:"high",effort:"high",label:"high",description:"高推理力度"},{value:"xhigh",effort:"xhigh",label:"xhigh",description:"超高推理力度"},{value:"max",effort:"max",label:"max",description:"最大推理力度"}],Qt="rcs_effort";function Ur(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 Or({budget:r,onBudgetChange:t,disabled:n}){const[s,a]=l.useState(!1),d=at.find(i=>i.value===r);return e.jsxs(Ue,{open:s,onOpenChange:a,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:n,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:"思考预算",children:[e.jsx(xn,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:(d==null?void 0:d.label)??"思考"}),s?e.jsx(Fe,{className:"h-3 w-3"}):e.jsx(Le,{className:"h-3 w-3"})]})}),e.jsx(Be,{className:"w-64 p-1",align:"start",children:at.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(Ne,{className:"h-3.5 w-3.5 text-brand"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:i.label}),e.jsx("div",{className:"text-xs text-text-muted",children:i.description})]})]},i.value))})]})}function Fr({effort:r,onEffortChange:t,disabled:n}){const[s,a]=l.useState(!1),d=ot.find(i=>i.value===r);return e.jsxs(Ue,{open:s,onOpenChange:a,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:n,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:"Effort 档位",children:[e.jsx(Rn,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:(d==null?void 0:d.label)??"自动"}),s?e.jsx(Fe,{className:"h-3 w-3"}):e.jsx(Le,{className:"h-3 w-3"})]})}),e.jsx(Be,{className:"w-64 p-1",align:"start",children:ot.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(Ne,{className:"h-3.5 w-3.5 text-brand"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:i.label}),e.jsx("div",{className:"text-xs text-text-muted",children:i.description})]})]},i.value))})]})}const Vt=["bg-brand","bg-status-active","bg-status-success","bg-violet-500","bg-amber-500","bg-pink-500","bg-teal-500"];function Lr({usage:r}){const t=Math.min(100,Math.max(0,r.percentage)),n=t>=80,s=(r.categories??[]).filter(i=>!i.isDeferred),a=(r.categories??[]).filter(i=>i.isDeferred),d=[`上下文用量:${oe(r.totalTokens)} / ${oe(r.rawMaxTokens)} tokens${r.model?` · ${r.model}`:""}`,...s.slice(0,8).map(i=>`${i.name}: ${oe(i.tokens)}`),...a.slice(0,3).map(i=>`${i.name}(延迟加载): ${oe(i.tokens)}`)];return e.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-text-muted font-mono",title:d.join(`
87
- `),children:[e.jsx("span",{className:"relative flex h-1.5 w-16 overflow-hidden rounded-full bg-surface-3",children:s.length>0?s.map((i,m)=>e.jsx("span",{className:n&&m===0?"bg-status-warning":Vt[m%Vt.length],style:{width:`${Math.min(100,Math.max(0,i.tokens/r.rawMaxTokens*100))}%`}},i.name)):e.jsx("span",{className:`absolute inset-y-0 left-0 rounded-full transition-all ${n?"bg-status-warning":"bg-brand/70"}`,style:{width:`${t}%`}})}),e.jsxs("span",{children:[t,"%"]})]})}function Br({models:r,currentModelId:t,onSelect:n,disabled:s}){const[a,d]=l.useState(!1),i=r.find(f=>f.modelId===t)??null,m=r.length>0,y=async f=>{n(f.modelId),d(!1)};return e.jsxs(Ue,{open:a,onOpenChange:m?d:void 0,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:s||!m,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:"选择模型",children:[e.jsx(es,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-32 truncate",children:(i==null?void 0:i.name)??t??"选择模型"}),a?e.jsx(Fe,{className:"h-3 w-3"}):e.jsx(Le,{className:"h-3 w-3"})]})}),e.jsx(Be,{className:"w-72 p-0",align:"start",children:e.jsx(mn,{models:r,currentModelId:t,onSelect:y,showSearch:r.length>5})})]})}function Hr({mode:r,onModeChange:t,disabled:n}){const[s,a]=l.useState(!1),d=ae.find(i=>i.value===r);return e.jsxs(Ue,{open:s,onOpenChange:a,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:n,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:"权限模式(Shift+Tab 循环)",children:[e.jsx(un,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:(d==null?void 0:d.label)??r}),s?e.jsx(Fe,{className:"h-3 w-3"}):e.jsx(Le,{className:"h-3 w-3"})]})}),e.jsx(Be,{className:"w-64 p-1",align:"start",children:ae.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(Ne,{className:"h-3.5 w-3.5 text-brand"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:i.label}),e.jsx("div",{className:"text-xs text-text-muted",children:i.description})]})]},i.value))})]})}function aa({sessionId:r,onSessionLoaded:t}){Jt();const[n,s]=l.useState(null),[a,d]=l.useState(null),[i,m]=l.useState(""),[y,f]=l.useState(!1),[h,w]=l.useState(!1),[v,M]=l.useState(!1),[u,c]=l.useState(!1),[b,p]=l.useState(!1),[g,k]=l.useState(!1),[j,E]=l.useState(""),[I,q]=l.useState(0),B=l.useRef(null),[X,C]=l.useState({text:"",nonce:0}),[U,K]=l.useState(!1),[_e,Se]=l.useState(!1),[G,A]=l.useState(!1),[ue,it]=l.useState(0),[is,ls]=l.useState(0),[me,Y]=l.useState([]),[V,xe]=l.useState(!1),[fe,te]=l.useState([]),[H,He]=l.useState(null),[cs,ds]=l.useState(()=>rs()),[W,us]=l.useState(null),[lt,ms]=l.useState(()=>localStorage.getItem(Kt)||"off"),[xs,ct]=l.useState(()=>$r(r)),[We,ze]=l.useState(!0),[pe,fs]=l.useState(null),[Ce,dt]=l.useState(null),[Ee,Te]=l.useState([]),[ut,Ke]=l.useState(!1),[Qe,mt]=l.useState(""),Ve=l.useRef(null),[Me,ps]=l.useState(()=>localStorage.getItem(zt)||"default"),[xt,ft]=l.useState(null),he=l.useRef(null),[pt,ht]=l.useState(null),ge=l.useRef(null),se=l.useRef(null),gt=l.useRef(me);gt.current=me;const Re=l.useRef(t);Re.current=t;const Ae=l.useRef(null);Ae.current||(Ae.current=new kn(vn()));const yt=l.useRef(r);yt.current=(n==null?void 0:n.title)||r,l.useEffect(()=>{var o;(o=Ae.current)==null||o.reset()},[r]);const Z=l.useCallback(o=>{ft(o),he.current&&clearTimeout(he.current),he.current=setTimeout(()=>ft(null),5e3)},[]),J=l.useCallback(o=>{ht(o),ge.current&&clearTimeout(ge.current),ge.current=setTimeout(()=>ht(null),5e3)},[]),$e=nt({value:Me,apply:o=>{ps(o);try{localStorage.setItem(zt,o)}catch{}},send:o=>{const x=se.current;return x?x.setPermissionMode(o):Promise.reject(new Error("adapter not ready"))},onError:(o,x)=>{console.error("[SessionDetail] set permission mode failed:",o),Z(x==="send"?`模式切换请求发送失败: ${o}`:o||"模式切换失败")}}),Ge=l.useCallback(o=>$e.set(o),[$e]),Ye=nt({value:lt,apply:o=>{ms(o);try{localStorage.setItem(Kt,o)}catch{}},send:o=>{var N;const x=se.current;if(!x)return Promise.reject(new Error("adapter not ready"));const _=((N=at.find(R=>R.value===o))==null?void 0:N.tokens)??null;return x.setThinkingBudget(_)},onError:(o,x)=>{console.error("[SessionDetail] set thinking budget failed:",o),Z(x==="send"?`思考预算请求发送失败: ${o}`:o||"思考预算切换失败")}}),$=l.useMemo(()=>new sr(r,Y,{onStatusChange:o=>{var x;d(o),xe(o==="running"||o==="requires_action"),(x=Ae.current)==null||x.onStatus(o,yt.current)},onError:o=>{console.error("[RCSChatAdapter] error:",o)},onPermissionRequest:o=>{te(x=>x.some(_=>_.requestId===o.requestId)?x:[...x,o])},onModelsStateChange:o=>{He(o)},onSubagentUpdate:o=>{ds(o)},onControlResponse:o=>{Ye.handleControlResponse(o)||$e.handleControlResponse(o)},onPermissionModeChange:o=>{$e.sync(o)},onUsageChange:o=>{fs(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=>{us(x=>JSON.stringify(x)===JSON.stringify(o)?x:o)},onElicitationRequest:o=>{dt(o)}}),[r,Z]);l.useEffect(()=>(se.current=$,()=>{$.disconnect()}),[$]);const P=l.useMemo(()=>Ur(W),[W]),Je=l.useMemo(()=>Xs((W==null?void 0:W.commands)??[],(W==null?void 0:W.skills)??[]),[W]),ye=l.useMemo(()=>Zs(me,j),[me,j]),hs=l.useCallback(o=>Ye.set(o),[Ye]),[bt,gs]=l.useState(()=>localStorage.getItem(Qt)||"auto"),ys=nt({value:bt,apply:o=>{gs(o);try{localStorage.setItem(Qt,o)}catch{}},send:o=>{var N;const x=se.current;if(!x)return Promise.reject(new Error("adapter not ready"));const _=(N=ot.find(R=>R.value===o))==null?void 0:N.effort;return x.setEffort(_)},onError:(o,x)=>{console.error("[SessionDetail] set effort failed:",o),Z(x==="send"?`Effort 切换请求发送失败: ${o}`:o||"Effort 切换失败")}}),Xe=l.useCallback(()=>{var o;P.get_context_usage&&((o=se.current)==null||o.getContextUsage().then(x=>{x&&(ct(x),Ir(r,x))}).catch(()=>{}).finally(()=>ze(!1)))},[P,r]);l.useEffect(()=>{if(!P.get_context_usage)return;V||Xe();const o=setInterval(Xe,6e4);return()=>clearInterval(o)},[P,V,Xe]),l.useEffect(()=>{W&&!P.get_context_usage&&ze(!1)},[W,P]),l.useEffect(()=>{if(!We)return;const o=setTimeout(()=>ze(!1),1e4);return()=>clearTimeout(o)},[We]);const wt=l.useRef(G);wt.current=G,l.useEffect(()=>re.onEvent(x=>{x.type!=="artifact_created"&&x.type!=="artifact_updated"||(wt.current&&ls(_=>_+1),it(_=>_+1))}),[]);const[be,bs]=l.useState("idle");l.useEffect(()=>re.onStateChange(x=>bs(x)),[]),l.useEffect(()=>{G&&it(0)},[G]),l.useEffect(()=>{let o=!1;async function x(){var _;m("");try{const N=await At(r);if(o)return;s(N),d(N.status),De(N.status)&&$.markClosed(),xe(N.status==="running"||N.status==="requires_action"),(_=Re.current)==null||_.call(Re,N)}catch(N){if(o)return;m(N instanceof Error?N.message:S("session.loadFailed"));return}try{await $.init()}catch(N){console.warn("Failed to init adapter:",N)}}return x(),()=>{o=!0}},[r,$]);const D=De(a),jt=l.useRef(a);jt.current=a,l.useEffect(()=>{if(D)return;let o=!1;const _=setInterval(async()=>{try{const N=await At(r);if(o||N.status===jt.current)return;De(N.status)&&$.markClosed(),d(N.status),xe(N.status==="running"||N.status==="requires_action")}catch{}},6e4);return()=>{o=!0,clearInterval(_)}},[r,D,$]);const O=(n==null?void 0:n.access_level)==="read",kt=xs??(We&&!D&&!O?Wt():null),Ze=l.useCallback(()=>{Y([]),ct(Wt()),Mt(r).catch(o=>{console.warn("[SessionDetail] Failed to clear session history:",o)})},[r]),we=l.useCallback(async(o,x)=>{const _=se.current;if(!_||D)return;if(o.sessionId===r){Y(R=>[...R,{type:"command_output",id:`cmd-resume-${Date.now()}`,commandName:"resume",inputText:x??"/resume",title:"Resume",subtitle:"恢复历史对话",outputText:"不能恢复当前会话自身",variant:"error"}]);return}const N=(R,F="default")=>Y(ee=>[...ee,{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:"恢复历史对话",outputText:R,variant:F}]);N(`正在恢复「${o.title}」…`);try{await Mt(r),Y([]);const R=await _.resumeSession(o.sessionId);N(`已恢复 ${R.messageCount} 条消息${R.title?`:${R.title}`:""}`)}catch(R){N(`恢复失败:${R instanceof Error?R.message:String(R)}`,"error")}},[D,r]),ws=l.useCallback(async()=>{if(n!=null&&n.environment_id)try{const o=await en({environment_id:n.environment_id});window.location.href=`/code/${o.id}?resumeFrom=${r}`}catch(o){J(`创建会话失败:${o instanceof Error?o.message:String(o)}`)}},[n,r,J]),js=l.useRef(new URLSearchParams(window.location.search).get("resumeFrom")),vt=l.useRef(!1);l.useEffect(()=>{const o=js.current;!o||vt.current||!W||!P.resume||(vt.current=!0,window.history.replaceState({},"",window.location.pathname),we({sessionId:o,title:o.slice(0,8),modified:0},null))},[W,P.resume,we]);const Ie=l.useCallback(async o=>{const x=o.text.trim(),_=o.images&&o.images.length>0||o.attachments&&o.attachments.length>0;if(!x&&!_||D)return;const N=/^\/resume(?:\s+(.*))?$/.exec(x);if(N){const F=(N[1]??"").trim();if(!P.resume){Y(ee=>[...ee,{type:"user_message",id:`user-${Date.now()}`,content:x},{type:"command_output",id:`cmd-${Date.now()}`,commandName:"resume",inputText:x,title:"Resume",subtitle:"恢复历史对话",outputText:"当前 worker 不支持 /resume(需要 spawn 模式 worker:slz rc)",variant:"error"}]);return}F?await we({sessionId:F,title:F,modified:0},x):p(!0);return}const R=await tn(x,{sessionId:r,availableCommands:Je,availableModels:(H==null?void 0:H.availableModels)??[],currentModel:H?{modelId:H.currentModelId,name:H.currentModelId}:null,supportsImages:!0,entries:gt.current,setModel:async F=>{await Q(r,{type:"control_request",request:{subtype:"set_model",model:F}}),He(ee=>ee&&{...ee,currentModelId:F})},onNewSession:()=>{Y([])}}).catch(()=>null);if(R){if(Pe("[SessionDetail] local command result",R),"clearEntries"in R&&R.clearEntries){Ze();return}if("newSession"in R&&R.newSession){Ze();return}if("userEntry"in R){Y(F=>[...F,R.userEntry,R.cmdEntry]);return}}xe(!0);try{await $.sendMessage(x,o.images,o.attachments)}catch(F){if(console.error("Send failed:",F),F instanceof sn&&F.type==="session_closed"){d("archived"),$.markClosed(),J(S("session.closedSendBlocked"));return}J(`${S("session.sendFailed")}${F instanceof Error?`: ${F.message}`:""}`)}},[$,D,r,H,Je,Ze,J,we,P]),ks=l.useCallback(o=>{if(V){Te(x=>[...x,o]);return}Ie(o)},[V,Ie]),et=l.useRef(!1);l.useEffect(()=>{if(D){Te(x=>x.length>0?[]:x);return}if(V||Ee.length===0||et.current)return;const o=Ee[0];o&&(et.current=!0,Te(x=>x.slice(1)),Ie(o).finally(()=>{et.current=!1}))},[V,Ee,Ie,D]);const vs=l.useCallback((o,x)=>{if(V)return;const _=x==="edit"?"回退到这条消息并编辑?":"回退到这条消息?";window.confirm(`${_}
88
- 之后的对话将移除,已修改的文件将恢复到当时的状态(若有快照)。`)&&$.rewindToMessage(o.id).then(()=>{x==="edit"&&o.content&&C(N=>({text:o.content,nonce:N.nonce+1}))}).catch(N=>{console.error("[SessionDetail] rewind failed:",N),J(`回退失败: ${N instanceof Error?N.message:String(N)}`)})},[V,J]),Ns=l.useCallback(o=>{const x=ye.orderedMatchIds;if(x.length===0)return;const _=(o%x.length+x.length)%x.length;q(_);const N=x[_],R=document.querySelector(`[data-entry-id="${CSS.escape(N)}"]`);R==null||R.scrollIntoView({block:"center",behavior:"smooth"})},[ye]),Nt=l.useCallback(async()=>{try{await $.interrupt()}catch(o){console.error("Interrupt failed:",o)}finally{xe(!1)}},[$]),_s=l.useCallback(()=>{Ge(Pr(Me))},[Ge,Me]);l.useEffect(()=>()=>{he.current&&clearTimeout(he.current),ge.current&&clearTimeout(ge.current)},[]);const Ss=l.useCallback(async()=>{if(n&&window.confirm(S("dashboard.confirmDelete").replace("{id}",n.title||n.id)))try{await Rt(n.id),window.location.href="/code/"}catch(o){alert(o instanceof Error?o.message:S("dashboard.deleteFailed"))}},[n]),Cs=l.useCallback(async o=>{try{await $.respondPermission(o,!0)}catch(x){console.error("Failed to approve:",x)}te(x=>x.filter(_=>_.requestId!==o))},[$]),Es=l.useCallback(async(o,x)=>{try{await $.respondPermission(o,!0,{updated_permissions:x})}catch(_){console.error("Failed to approve with rules:",_)}te(_=>_.filter(N=>N.requestId!==o))},[$]),Ts=l.useCallback(async(o,x)=>{const _=Ce;if(dt(null),!!_)try{await $.respondElicitation(_.requestId,o,x)}catch(N){console.error("Failed to submit elicitation:",N)}},[Ce,$]),Ms=l.useCallback(()=>{!n||O||(mt(n.title||""),Ke(!0),setTimeout(()=>{var o,x;(o=Ve.current)==null||o.focus(),(x=Ve.current)==null||x.select()},0))},[n,O]),_t=l.useCallback(async()=>{const o=Qe.trim();if(Ke(!1),!(!n||!o||o===n.title))try{const x=await nn(n.id,o);s(_=>_&&{..._,title:x.title??o})}catch(x){console.error("Rename failed:",x),alert(x instanceof Error?x.message:"重命名失败")}},[n,Qe]),Rs=l.useCallback(async o=>{try{await $.respondPermission(o,!1)}catch(x){console.error("Failed to reject:",x)}te(x=>x.filter(_=>_.requestId!==o))},[$]),As=l.useCallback(async(o,x,_)=>{try{await Q(r,{type:"permission_response",approved:!0,request_id:o,updated_input:{questions:_,answers:x}})}catch(N){console.error("Failed to submit answers:",N)}te(N=>N.filter(R=>R.requestId!==o))},[r]),$s=l.useCallback(async(o,x,_)=>{try{x==="no"?await Q(r,{type:"permission_response",approved:!1,request_id:o,..._?{message:_}:{}}):await Q(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(N){console.error("Failed to submit plan response:",N)}te(N=>N.filter(R=>R.requestId!==o))},[r]);return i?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 hover:underline",children:S("session.backToDashboard")})]})}):n?n.source==="acp"&&n.environment_id?e.jsx(zr,{sessionId:r,agentId:n.environment_id}):e.jsx(Xt,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx("h1",{className:"sr-only",children:n.title||n.id}),e.jsx("div",{className:"border-b bg-surface-1 px-4 py-3",children:e.jsxs("div",{className:"mx-auto max-w-5xl",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[ut?e.jsx("input",{ref:Ve,value:Qe,onChange:o=>mt(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),_t()):o.key==="Escape"&&(o.preventDefault(),Ke(!1))},onBlur:()=>void _t(),maxLength:200,className:"w-full max-w-md rounded-lg border border-brand/50 bg-surface-2 px-2.5 py-1 font-display text-lg font-semibold text-text-primary focus:outline-none focus:ring-2 focus:ring-brand/30"}):e.jsxs("h2",{className:"group/title flex min-w-0 items-center gap-1.5 font-display text-lg font-semibold text-text-primary",children:[e.jsx("span",{className:"truncate",children:n.title||n.id}),!O&&!D&&e.jsx("button",{type:"button",onClick:Ms,className:"flex-shrink-0 rounded p-0.5 text-text-muted opacity-0 transition-opacity hover:text-text-primary group-hover/title:opacity-100",title:"重命名会话",children:e.jsx(rn,{className:"h-3.5 w-3.5"})})]}),n.visibility&&!ut&&e.jsx(wn,{visibility:n.visibility||"private"})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:[(()=>{var _;const o=n.source==="acp"?"acp":(_=n.environment)==null?void 0:_.worker_type,x=fn(o);return e.jsx("span",{className:`rounded-full px-2 py-0.5 text-xs font-medium ${x.colorClass}`,children:x.fullLabel})})(),a&&e.jsx(Gt,{status:a}),e.jsx("span",{className:"text-xs text-text-muted",children:Yt(n.created_at)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>A(!G),className:`relative flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors ${G?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:S("artifacts.title"),children:[e.jsx(an,{className:"h-3.5 w-3.5"}),ue>0&&!G&&e.jsx("span",{className:"absolute -right-1.5 -top-1.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-status-active px-1 text-[10px] font-bold text-white",children:ue>9?"9+":ue})]}),P.side_question&&!D&&!O&&e.jsx("button",{onClick:()=>c(!u),className:`flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors ${u?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:"旁路提问 — 针对会话上下文提问,不进入主对话",children:e.jsx(ts,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>{const o=!g;k(o),o?setTimeout(()=>{var x;return(x=B.current)==null?void 0:x.focus()},0):(E(""),q(0))},className:`flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors ${g?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:"搜索会话内容",children:e.jsx(rt,{className:"h-3.5 w-3.5"})}),P.mcp_management&&!D&&!O&&e.jsx("button",{onClick:()=>w(!h),className:`flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors ${h?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:"MCP 服务器",children:e.jsx(ss,{className:"h-3.5 w-3.5"})}),P.remote_settings&&!D&&!O&&e.jsx("button",{onClick:()=>M(!v),className:`flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors ${v?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:"会话设置",children:e.jsx(ns,{className:"h-3.5 w-3.5"})}),!O&&(n==null?void 0:n.access_level)!=="write"&&e.jsx("button",{onClick:()=>Se(!0),className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs text-text-muted hover:bg-surface-2 hover:text-text-secondary transition-colors",title:S("session.share"),children:e.jsx(Kn,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>K(!U),className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs text-text-muted hover:bg-surface-2 hover:text-text-secondary transition-colors",title:S("session.info"),children:e.jsx(qn,{className:"h-3.5 w-3.5"})}),e.jsxs("button",{onClick:()=>f(!y),className:"flex items-center gap-1 rounded-md px-3 py-1.5 text-sm text-text-primary font-bold hover:bg-brand-light hover:text-white transition-colors",children:[S("session.tasks"),fe.length>0&&e.jsx("span",{className:"ml-1 rounded-full bg-status-warning px-1.5 py-0.5 text-[10px] font-medium text-white",children:fe.length})]})]})]}),U&&e.jsxs("div",{className:"mt-2 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:S("session.metaSession")})," ",n.id]}),n.environment_id&&e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:S("session.metaEnvironment")})," ",n.environment_id]})]})]})}),(be==="reconnecting"||be==="failed")&&e.jsxs("div",{className:`flex items-center justify-center gap-2 px-4 py-1.5 text-xs font-medium ${be==="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 ${be==="failed"?"bg-status-error":"animate-pulse bg-status-warning"}`}),be==="failed"?S("session.sseFailed"):S("session.sseReconnecting")]}),G&&e.jsx("div",{className:"border-b bg-surface-1 px-4 py-4",children:e.jsx("div",{className:"mx-auto max-w-3xl",children:e.jsx(bn,{sessionId:r,embedded:!0,refreshTick:is})})}),g&&e.jsx("div",{className:"border-b bg-surface-1 px-4 py-2",children:e.jsxs("div",{className:"mx-auto flex max-w-3xl items-center gap-2",children:[e.jsx(rt,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{ref:B,value:j,onChange:o=>{E(o.target.value),q(0)},onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),Ns(j&&o.shiftKey?I-1:I+1)):o.key==="Escape"&&(o.preventDefault(),k(!1),E(""))},placeholder:"搜索会话内容…",className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"}),j.trim()&&e.jsx("span",{className:"flex-shrink-0 font-mono text-[11px] text-text-muted",children:ye.orderedMatchIds.length===0?"无结果":`${I+1}/${ye.orderedMatchIds.length}`})]})}),e.jsx(on,{entries:me,isLoading:V,emptyTitle:S("session.emptyTitle"),emptyDescription:S("session.emptyDescription"),searchMatchIds:j.trim()?ye.matchIds:void 0,onRewindEntry:P.rewind&&!D&&!O&&!V?(o,x)=>vs(o,x):void 0}),e.jsx(gr,{state:cs,onStopTask:P.stop_task?o=>{$.stopSubagent(o).then(x=>{x.ok||J(x.error||"停止任务失败")})}:void 0}),fe.length>0&&e.jsx("div",{className:"border-t bg-surface-1 px-4 py-3",children:e.jsx("div",{className:"mx-auto max-w-3xl space-y-3",children:fe.map(o=>e.jsx(Wr,{request:o,onApprove:()=>Cs(o.requestId),onApproveAlways:o.suggestions&&o.suggestions.length>0?()=>Es(o.requestId,o.suggestions??[]):void 0,onReject:()=>Rs(o.requestId),onSubmitAnswers:As,onSubmitPlan:$s},o.requestId))})}),Ce&&e.jsx("div",{className:"border-t bg-surface-1 px-4 py-3",children:e.jsx("div",{className:"mx-auto max-w-3xl",children:e.jsx(vr,{request:Ce,onSubmit:Ts})})}),pt&&e.jsx("div",{className:"mx-auto max-w-3xl w-full px-4 sm:px-8 pb-1",children:e.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 px-3 py-1.5 text-xs text-red-700 dark:text-red-300",children:pt})}),xt&&e.jsx("div",{className:"mx-auto max-w-3xl 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:xt})}),e.jsxs("div",{className:"max-w-3xl 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(Hr,{mode:Me,onModeChange:Ge,disabled:D||O}),e.jsx(Br,{models:(H==null?void 0:H.availableModels)??[],currentModelId:(H==null?void 0:H.currentModelId)??null,onSelect:o=>{Q(r,{type:"control_request",request:{subtype:"set_model",model:o}}),He(x=>x&&{...x,currentModelId:o})},disabled:D||O}),P.set_max_thinking_tokens&&e.jsx(Or,{budget:lt,onBudgetChange:hs,disabled:D||O}),P.set_effort&&e.jsx(Fr,{effort:bt,onEffortChange:o=>ys.set(o),disabled:D||O})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[kt&&e.jsx(Lr,{usage:kt}),pe&&e.jsxs("span",{className:"text-[11px] text-text-muted font-mono",title:"会话累计用量(input 含缓存读写)",children:[oe(pe.inputTokens)," in / ",oe(pe.outputTokens)," out",pe.totalCostUsd!=null&&` · $${pe.totalCostUsd.toFixed(2)}`]})]})]}),D&&(n==null?void 0:n.environment_id)&&e.jsx("div",{className:"mx-auto w-full max-w-3xl px-4 pb-2 sm:px-8",children:e.jsx("button",{type:"button",onClick:()=>void ws(),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:"在新会话中继续此对话(/resume)"})}),e.jsx(ln,{onSubmit:ks,isLoading:V,onInterrupt:Nt,onCycleMode:_s,disabled:D||O,placeholder:D?S("session.closed"):O?S("session.readOnly"):S("session.inputPlaceholder"),supportsAttachments:!0,commands:Je,queueWhileLoading:!0,queuedCount:Ee.length,onDequeue:o=>Te(x=>x.filter((_,N)=>N!==o)),onSearchFiles:P.file_search?o=>$.searchFiles(o):void 0,historyKey:r,draftOverride:X}),h&&e.jsx(cr,{onClose:()=>w(!1),fetchServers:()=>$.getMcpServers(),onToggle:(o,x)=>$.toggleMcpServer(o,x),onReconnect:o=>$.reconnectMcpServer(o)}),v&&e.jsx(ur,{onClose:()=>M(!1),fetchSettings:()=>$.getRemoteSettings(),onApply:o=>$.applyFlagSettings(o)}),u&&e.jsx(mr,{onClose:()=>c(!1),onAsk:o=>$.askSideQuestion(o)}),y&&n&&e.jsx(or,{onClose:()=>f(!1),session:n,liveStatus:a,pendingPermissions:fe,onInterrupt:Nt,onDelete:Ss,onEndSession:P.end_session&&!D&&!O?async()=>{await $.endSession("ended from web"),await Rt(n.id),window.location.href="/code/"}:void 0}),e.jsx(Cr,{open:_e,onClose:()=>Se(!1),sessionId:n.id,sessionTitle:n.title||void 0}),e.jsx(Mr,{open:b,onClose:()=>p(!1),adapter:$,onResume:o=>{p(!1),we(o,null)}})]})}):e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx("div",{className:"text-text-muted",children:S("session.loading")})})}function Wr({request:r,onApprove:t,onApproveAlways:n,onReject:s,onSubmitAnswers:a,onSubmitPlan:d}){const i=r.toolName,m=r.toolInput,y=r.description||"";if(i==="AskUserQuestion"){const f=m.questions||[];return e.jsx(br,{requestId:r.requestId,questions:f,description:y,onSubmit:h=>a(r.requestId,h,f),onSkip:s})}if(i==="ExitPlanMode"){const f=m.plan||"";return e.jsx(jr,{requestId:r.requestId,planContent:f,description:y,onSubmit:(h,w)=>d(r.requestId,h,w)})}return e.jsx(yr,{requestId:r.requestId,toolName:i,toolInput:m,description:y,suggestions:r.suggestions,onApprove:t,onApproveAlways:n,onReject:s})}function zr({sessionId:r,agentId:t}){const[n,s]=l.useState(null),[a,d]=l.useState("disconnected"),[i,m]=l.useState(null),y=l.useRef(null);return l.useEffect(()=>{const f=Dr(t);return f.setConnectionStateHandler((h,w)=>{d(h),m(w||null)}),y.current=f,s(f),f.connect().catch(h=>{h instanceof cn||(m(h.message),d("error"))}),()=>{f.disconnect(),y.current=null,s(null),d("disconnected")}},[t]),e.jsx(Xt,{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:S("session.connectingAgent")})]})}),a==="error"&&!n&&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:S("session.connectionFailed")}),e.jsx("p",{className:"text-text-muted text-sm",children:i})]})}),n&&a==="connected"&&e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(dn,{client:n,agentId:t})})]})})}export{aa as SessionDetail};
85
+ ${v}`})}}const y=m.length===1&&m[0].type==="text"?m[0].text||t:m.length>0?m:t;try{const h=ne();this.postedUserUuids.add(h);const w=await Us(this.sessionId,{type:"user",uuid:h,content:t,message:{content:y}}),v=(f=w==null?void 0:w.event)==null?void 0:f.id;v&&this.setEntries(M=>M.map(u=>u.type==="user_message"&&u.id===i.id?{...u,id:v}:u))}catch(h){throw this.setEntries(w=>w.filter(v=>!(v.type==="user_message"&&v.id===i.id))),h}}async respondPermission(t,n,s){await V(this.sessionId,{type:"permission_response",approved:n,request_id:t,...s}),this.setEntries(a=>a.map(d=>{var i;return d.type!=="tool_call"||((i=d.toolCall.permissionRequest)==null?void 0:i.requestId)!==t?d:{type:"tool_call",toolCall:{...d.toolCall,status:n?"running":"rejected",permissionRequest:void 0}}}))}async interrupt(){this.setEntries(t=>t.map(n=>n.type!=="tool_call"||n.toolCall.status!=="running"&&n.toolCall.status!=="waiting_for_confirmation"?n:{type:"tool_call",toolCall:{...n.toolCall,status:"canceled",permissionRequest:void 0}})),await Os(this.sessionId)}async setPermissionMode(t){const n=ne();return await V(this.sessionId,{type:"control_request",request_id:n,request:{subtype:"set_permission_mode",mode:t}}),n}async controlRoundTrip(t,n=8e3){const s=ne(),a=new Promise(i=>{this.pendingControlRequests.set(s,i)}),d=setTimeout(()=>{const i=this.pendingControlRequests.get(s);i&&(this.pendingControlRequests.delete(s),i({data:null,error:"timeout"}))},n);try{return await V(this.sessionId,{type:"control_request",request_id:s,request:t}),await a}catch(i){throw this.pendingControlRequests.delete(s),i}finally{clearTimeout(d)}}async searchFiles(t,n=20){const s=await this.controlRoundTrip({subtype:"file_search",query:t,limit:n});try{if(!s.data||!Array.isArray(s.data.suggestions))return[];const a=[];for(const d of s.data.suggestions)d&&typeof d=="object"&&typeof d.path=="string"&&a.push(d.path);return a}catch{return[]}}async respondElicitation(t,n,s){await V(this.sessionId,{type:"permission_response",approved:n==="accept",request_id:t,response:{subtype:"success",request_id:t,response:{action:n,...s?{content:s}:{}}}})}async askSideQuestion(t){const n=await this.controlRoundTrip({subtype:"side_question",question:t},12e4);if(n.error||!n.data)return null;const s=n.data.response;return typeof s=="string"?s: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 n=[];for(const s of t.data.sessions){if(!s||typeof s!="object")continue;const a=s;typeof a.session_id!="string"||!a.session_id||n.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 n}async resumeSession(t){const n=await this.controlRoundTrip({subtype:"resume_session",session_id:t},3e4);if(!n.data)throw new Error(n.error??"resume_session failed");return{title:typeof n.data.title=="string"?n.data.title:null,messageCount:typeof n.data.message_count=="number"?n.data.message_count:0}}async setEffort(t){const n=ne();return await V(this.sessionId,{type:"control_request",request_id:n,request:{subtype:"set_effort",...t?{effort:t}:{effort:null}}}),n}async setThinkingBudget(t){const n=ne();return await V(this.sessionId,{type:"control_request",request_id:n,request:{subtype:"set_max_thinking_tokens",max_thinking_tokens:t}}),n}async getContextUsage(){const t=await this.controlRoundTrip({subtype:"get_context_usage"});try{if(!t.data)return null;const n=t.data.totalTokens,s=t.data.rawMaxTokens,a=t.data.percentage;if(typeof n!="number"||typeof s!="number")return null;const d=t.data.categories,i=Array.isArray(d)?d.filter(m=>!!m&&typeof m=="object"&&typeof m.name=="string").map(m=>({name:m.name,tokens:typeof m.tokens=="number"?m.tokens:0,...m.isDeferred===!0?{isDeferred:!0}:{}})):void 0;return{totalTokens:n,rawMaxTokens:s,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 n=await this.controlRoundTrip({subtype:"stop_task",task_id:t});try{return n.error?{ok:!1,error:n.error==="timeout"?"停止请求超时":n.error}:{ok:!0}}catch{return{ok:!1,error:"停止请求失败"}}}async getMcpServers(){var a;const n=(a=(await this.controlRoundTrip({subtype:"mcp_status"})).data)==null?void 0:a.mcpServers;if(!Array.isArray(n))return[];const s=[];for(const d of n){if(!d||typeof d!="object")continue;const i=d;if(typeof i.name!="string"||!i.name)continue;const m=i.status;if(m!=="connected"&&m!=="failed"&&m!=="needs-auth"&&m!=="pending"&&m!=="disabled")continue;const y=i.serverInfo,f=i.config;s.push({name:i.name,status:m,...y&&typeof y.name=="string"&&typeof y.version=="string"?{serverInfo:{name:y.name,version:y.version}}:{},...typeof i.error=="string"&&i.error?{error:i.error}:{},...typeof(f==null?void 0:f.url)=="string"&&f.url?{url:f.url}:{},...Array.isArray(i.tools)?{toolCount:i.tools.length}:{}})}return s}async toggleMcpServer(t,n){const s=await this.controlRoundTrip({subtype:"mcp_toggle",serverName:t,enabled:n},15e3);return s.error?{ok:!1,error:s.error==="timeout"?"请求超时":s.error}:{ok:!0}}async reconnectMcpServer(t){const n=await this.controlRoundTrip({subtype:"mcp_reconnect",serverName:t},2e4);return n.error?{ok:!1,error:n.error==="timeout"?"请求超时":n.error}:{ok:!0}}async getRemoteSettings(){const n=(await this.controlRoundTrip({subtype:"get_settings"})).data;if(!n)return null;const s=n.applied,a=n.effective&&typeof n.effective=="object"&&!Array.isArray(n.effective)?n.effective:{},d=n.sources,i=[];if(Array.isArray(d))for(const m of d){if(!m||typeof m!="object")continue;const y=m;typeof y.source=="string"&&i.push({source:y.source,settings:y.settings&&typeof y.settings=="object"&&!Array.isArray(y.settings)?y.settings:{}})}return{applied:{model:typeof(s==null?void 0:s.model)=="string"?s.model:null,effort:typeof(s==null?void 0:s.effort)=="string"?s.effort:null},effective:a,sources:i}}async applyFlagSettings(t){const n=await this.controlRoundTrip({subtype:"apply_flag_settings",settings:t},15e3);return n.error?{ok:!1,error:n.error==="timeout"?"请求超时":n.error}:{ok:!0}}async rewindToMessage(t){await Fs(this.sessionId,t)}async endSession(t){await V(this.sessionId,{type:"control_request",request_id:ne(),request:{subtype:"end_session",...t?{reason:t}:{}}})}}function nr(r){return r<1024?`${r} B`:r<1024*1024?`${(r/1024).toFixed(1)} KB`:`${(r/(1024*1024)).toFixed(1)} MB`}function rr(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 ar(r){return r?Date.now()-r<6e4:!1}function or({onClose:r,session:t,liveStatus:n,pendingPermissions:s,onInterrupt:a,onDelete:d,onEndSession:i}){const[m,y]=l.useState(!1),f=async()=>{await navigator.clipboard.writeText(t.id),y(!0),setTimeout(()=>y(!1),1500)},[h,w]=l.useState(!1),v=async()=>{if(!(!i||h)&&window.confirm("结束 worker 会话?正在进行的回合将被中止,会话随后归档。")){w(!0);try{await i(),r()}catch{w(!1)}}},M=s.length,u=t.worker,c=t.work_item,b=t.environment;return e.jsx(ie,{open:!0,onOpenChange:p=>{p||r()},children:e.jsxs(le,{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(ce,{children:e.jsx(de,{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(_n,{className:"h-3.5 w-3.5"}),"Status"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gt,{status:n||t.status||"unknown"}),e.jsx("span",{className:"text-xs text-text-muted",children:u&&(ar(u.last_heartbeat_at)?"· worker online":"· worker offline")})]}),e.jsxs("dl",{className:"space-y-1 text-xs text-text-muted",children:[u&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(Et,{className:"h-3 w-3"}),"Heartbeat"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:rr(u.last_heartbeat_at)})]}),b&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(es,{className:"h-3 w-3"}),"Environment"]}),e.jsx("dd",{className:"truncate text-text-secondary",children:b.machine_name||b.id})]}),t.created_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(Et,{className:"h-3 w-3"}),"Created"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:Yt(t.created_at)})]})]})]}),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(ve,{className:"h-3.5 w-3.5"}),"Pending Actions"]}),M>0?e.jsxs("div",{className:"rounded-md bg-status-warning/10 px-3 py-2 text-xs text-status-warning",children:[M," permission request",M>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(Hn,{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"}),i&&e.jsx("button",{onClick:v,disabled:h,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:"通知 worker 中止在途回合并退出,随后归档会话",children:h?"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(Bs,{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($n,{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:f,className:"text-text-muted hover:text-text-primary transition-colors flex-shrink-0",title:"Copy session id",children:m?"✓":"⧉"})]})]}),c&&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:c.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:c.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})]}),b&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Worker type"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:b.worker_type})]})]})]})]})]})})}const ir={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"},lr={connected:"已连接",failed:"失败","needs-auth":"待认证",pending:"连接中",disabled:"已禁用"};function cr({onClose:r,fetchServers:t,onToggle:n,onReconnect:s}){const[a,d]=l.useState(null),[i,m]=l.useState(null),[y,f]=l.useState(null),[h,w]=l.useState(null),v=l.useCallback(async()=>{f(null),w(null);try{const c=await t();d(c),m(null)}catch(c){Pe("[McpPanel] fetch failed",c),m("获取 MCP 状态失败 — worker 可能不支持")}},[t]);l.useEffect(()=>{v()},[v]);const M=async c=>{const b=c.status==="disabled";f(`toggle:${c.name}`),w(null);try{const p=await n(c.name,b);p.ok||w(p.error||"切换失败")}finally{await v()}},u=async c=>{f(`reconnect:${c.name}`),w(null);try{const b=await s(c.name);b.ok||w(b.error||"重连失败")}finally{await v()}};return e.jsx(ie,{open:!0,onOpenChange:c=>{c||r()},children:e.jsxs(le,{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(ce,{children:e.jsxs(de,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(ss,{className:"h-4 w-4"}),"MCP 服务器"]})}),e.jsxs("div",{className:"mt-3 space-y-3 text-sm",children:[h&&e.jsx("div",{className:"rounded-md bg-status-error/10 px-3 py-2 text-xs text-status-error",children:h}),a===null&&!i&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(ve,{className:"h-3.5 w-3.5 animate-spin"}),"加载 MCP 状态…"]}),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:"没有配置 MCP 服务器"}),a==null?void 0:a.map(c=>{const b=y===`toggle:${c.name}`,p=y===`reconnect:${c.name}`,g=c.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:c.name}),e.jsx("span",{className:`flex-shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium ${ir[c.status]}`,children:lr[c.status]})]}),e.jsxs("div",{className:"mt-0.5 truncate text-xs text-text-muted",children:[c.serverInfo?`${c.serverInfo.name} v${c.serverInfo.version}`:c.url||"stdio",c.toolCount!==void 0&&` · ${c.toolCount} 工具`]}),c.error&&e.jsx("div",{className:"mt-1 truncate text-xs text-status-error",title:c.error,children:c.error})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>void u(c),disabled:p||g,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:"重连",children:e.jsx(hn,{className:`h-3.5 w-3.5 ${p?"animate-spin":""}`})}),e.jsx("button",{type:"button",role:"switch","aria-checked":!g,onClick:()=>void M(c),disabled:b,className:`relative h-5 w-9 rounded-full transition-colors disabled:opacity-50 ${g?"bg-surface-3":"bg-brand"}`,title:g?"启用":"禁用",children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${g?"left-0.5":"left-4.5"}`})})]})]})},c.name)})]})]})})}function dr(r){if(r==null)return"(未设置)";if(typeof r=="string")return r;try{return JSON.stringify(r)}catch{return String(r)}}function Ot(r){if(r==null)return"(未设置)";if(typeof r=="object")try{return JSON.stringify(r,null,2)}catch{return String(r)}return String(r)}function ur({onClose:r,fetchSettings:t,onApply:n}){const[s,a]=l.useState(null),[d,i]=l.useState(null),[m,y]=l.useState(""),[f,h]=l.useState(null),[w,v]=l.useState(null),[M,u]=l.useState(null),[c,b]=l.useState(!1),p=l.useCallback(async()=>{h(null),v(null),u(null),b(!1);try{const C=await t();a(C),i(C?null:"获取设置失败 — worker 可能不支持")}catch(C){Pe("[SettingsDrawer] fetch failed",C),i("获取设置失败 — worker 可能不支持")}},[t]);l.useEffect(()=>{p()},[p]);const g=l.useMemo(()=>s?Object.entries(s.effective).filter(([,C])=>C!==void 0).sort(([C],[U])=>C.localeCompare(U)):[],[s]),k=l.useMemo(()=>{const C=m.trim().toLowerCase();return C?g.filter(([U,K])=>`${U} ${dr(K)}`.toLowerCase().includes(C)):g},[g,m]),j=C=>typeof C[1]=="boolean",E=l.useMemo(()=>k.filter(j),[k]),I=l.useMemo(()=>k.filter(C=>!j(C)),[k]),D=l.useMemo(()=>M===null?null:g.find(([C])=>C===M)??null,[g,M]),B=async()=>{if(D)try{await navigator.clipboard.writeText(Ot(D[1])),b(!0),window.setTimeout(()=>b(!1),1500)}catch(C){Pe("[SettingsDrawer] copy failed",C)}},X=async(C,U)=>{h(C),v(null);try{const K=await n({[C]:!U});K.ok||v(K.error||"写入失败")}finally{await p()}};return e.jsx(ie,{open:!0,onOpenChange:C=>{C||r()},children:e.jsxs(le,{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(ce,{children:e.jsxs(de,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(ns,{className:"h-4 w-4"}),"会话设置"]})}),e.jsxs("div",{className:"mt-3 space-y-4 text-sm",children:[w&&e.jsx("div",{className:"rounded-md bg-status-error/10 px-3 py-2 text-xs text-status-error",children:w}),s===null&&!d&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-muted",children:[e.jsx(ve,{className:"h-3.5 w-3.5 animate-spin"}),"加载设置…"]}),d&&e.jsx("p",{className:"text-xs text-status-error",children:d}),s&&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:"模型"}),e.jsx("code",{className:"font-mono text-text-secondary",children:s.applied.model||"(默认)"})]}),s.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:s.applied.effort})]}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-text-muted",children:"布尔开关写入会话级 flag 层(apply_flag_settings);只读项点击查看详情。"})]}),D?e.jsxs("section",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>{u(null),b(!1)},className:"flex items-center gap-1.5 text-xs text-text-muted transition-colors hover:text-text-primary",children:[e.jsx(Cn,{className:"h-3.5 w-3.5"}),"返回设置列表"]}),e.jsx("div",{className:"break-all font-mono text-xs font-medium text-text-primary",children:D[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-[11px] leading-relaxed text-text-secondary",children:Ot(D[1])}),e.jsxs("button",{type:"button",onClick:()=>void B(),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:[c?e.jsx(Ne,{className:"h-3.5 w-3.5 text-status-success"}):e.jsx(gn,{className:"h-3.5 w-3.5"}),c?"已复制":"复制值"]})]}):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(rt,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{value:m,onChange:C=>y(C.target.value),placeholder:"搜索设置项…",className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"})]}),k.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:"没有匹配的设置项"}),E.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("h3",{className:"text-[11px] font-medium uppercase tracking-wide text-text-muted",children:["可设置(",E.length,")"]}),E.map(([C,U])=>{const K=f===C;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:C}),e.jsx("button",{type:"button",role:"switch","aria-checked":U,disabled:K,onClick:()=>void X(C,U),className:`relative h-5 w-9 flex-shrink-0 rounded-full transition-colors disabled:opacity-50 ${U?"bg-brand":"bg-surface-3"}`,title:U?"关闭(写入 false)":"开启(写入 true)",children:e.jsx("span",{className:`absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all ${U?"left-4.5":"left-0.5"}`})})]},C)})]}),I.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("h3",{className:"text-[11px] font-medium uppercase tracking-wide text-text-muted",children:["只读(",I.length,")"]}),I.map(([C])=>e.jsxs("button",{type:"button",onClick:()=>u(C),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:"查看详情",children:[e.jsx("span",{className:"truncate font-mono text-xs text-text-primary",children:C}),e.jsx(Zt,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"})]},C))]})]})]})]})]})})}function mr({onClose:r,onAsk:t}){const[n,s]=l.useState([]),[a,d]=l.useState(""),[i,m]=l.useState(!1),y=async()=>{const f=a.trim();if(!f||i)return;const h=Date.now();s(w=>[...w,{id:h,question:f,answer:null}]),d(""),m(!0);try{const w=await t(f);s(v=>v.map(M=>M.id===h?{...M,answer:w??"没有获得回答(超时或 worker 不支持)",error:w===null}:M))}finally{m(!1)}};return e.jsx(ie,{open:!0,onOpenChange:f=>{f||r()},children:e.jsxs(le,{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(ce,{children:e.jsxs(de,{className:"flex items-center gap-2 font-display font-semibold text-text-primary",children:[e.jsx(ts,{className:"h-4 w-4"}),"旁路提问"]})}),e.jsx("p",{className:"mt-1 text-[11px] leading-relaxed text-text-muted",children:"针对当前会话上下文提问,不进入主对话、不消耗会话历史 — 适合「这个会话干了什么」式的快速核对。"}),e.jsxs("div",{className:"mt-3 flex-1 space-y-4 overflow-y-auto",children:[n.length===0&&e.jsx("p",{className:"text-xs text-text-muted",children:"还没有提问。在下方输入你的问题。"}),n.map(f=>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:f.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:f.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:f.error?"text-status-error":"",children:e.jsx(Hs,{children:f.answer})})})]})]},f.id))]}),e.jsxs("div",{className:"mt-3 flex items-end gap-2",children:[e.jsx("textarea",{value:a,onChange:f=>d(f.target.value),onKeyDown:f=>{f.key==="Enter"&&!f.shiftKey&&!f.nativeEvent.isComposing&&(f.preventDefault(),y())},rows:Math.min(4,Math.max(1,a.split(`
86
+ `).length)),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 y(),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:"提问(Enter)",children:i?e.jsx(ve,{className:"h-4 w-4 animate-spin"}):e.jsx(Ws,{className:"h-4 w-4"})})]})]})})}const Ft="rcs:subagent-panel:collapsed";function xr(r){if(r<1e3)return"0s";const t=Math.floor(r/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60),s=t%60;if(n<60)return s?`${n}m${s}s`:`${n}m`;const a=Math.floor(n/60),d=n%60;return d?`${a}h${d}m`:`${a}h`}function fr(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 pr({status:r}){return r==="running"?e.jsx(ve,{className:"h-3 w-3 animate-spin text-brand"}):r==="completed"?e.jsx(Fn,{className:"h-3 w-3 text-status-success"}):r==="failed"||r==="stopped"?e.jsx(Ks,{className:"h-3 w-3 text-status-error"}):null}function hr({task:r,onStopTask:t}){const n=r.status==="running",s=n?r.durationMs??Date.now()-r.startTime:(r.endTime??Date.now())-r.startTime,a=fr(r.tokenCount),d=r.toolUseCount!==void 0&&r.toolUseCount>0?`${r.toolUseCount} tool${r.toolUseCount>1?"s":""}`:"",i=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(pr,{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:xr(s)})]}),e.jsx("div",{className:"mt-0.5 truncate text-text-secondary",children:i}),(a||d||r.lastToolName)&&e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 font-mono text-[10px] text-text-muted",children:[a&&e.jsxs("span",{children:["↕ ",a," tok"]}),d&&e.jsxs("span",{children:["· ",d]}),r.lastToolName&&e.jsxs("span",{className:"truncate",children:["· last: ",r.lastToolName]})]}),!n&&r.finalSummary&&e.jsx("div",{className:"mt-1 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:"停止此任务",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(zs,{className:"h-3.5 w-3.5"})})]})}function gr({state:r,onStopTask:t}){const[n,s]=l.useState(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Ft)==="1"}catch{return!1}}),a=()=>{s(f=>{const h=!f;try{window.localStorage.setItem(Ft,h?"1":"0")}catch{}return h})},[,d]=l.useState(0);l.useEffect(()=>{const f=Object.values(r.tasks).some(v=>v.status==="running"),h=Object.values(r.tasks).some(v=>v.status!=="running"&&v.evictAfter!==void 0);if(!f&&!h)return;const w=setInterval(()=>{d(v=>v+1)},1e3);return()=>clearInterval(w)},[r]);const i=Xn(r);if(i.length===0)return null;const m=i.filter(f=>f.status==="running").length,y=m>0?`${m} running`:`${i.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":!n,"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(Zt,{className:`h-3 w-3 transition-transform ${n?"":"rotate-90"}`}),e.jsx("span",{children:"Subagents"})]}),e.jsx("span",{children:y})]}),!n&&e.jsx("div",{id:"subagent-list",className:"space-y-1.5",children:i.map(f=>e.jsx(hr,{task:f,onStopTask:t},f.taskId))})]})})}function Lt(r,t){var a;const n=(a=t==null?void 0:t.find(d=>d.type==="addRules"||d.type==="replaceRules"))==null?void 0:a.rules,s=n==null?void 0:n[0];return s!=null&&s.ruleContent?`${s.toolName}(${s.ruleContent})`:s!=null&&s.toolName?s.toolName:r}function yr({requestId:r,toolName:t,toolInput:n,description:s,suggestions:a,onApprove:d,onApproveAlways:i,onReject:m}){const y=typeof n=="string"?n:JSON.stringify(n,null,2),f=Array.isArray(a)&&a.length>0;return e.jsxs("div",{className:"rounded-xl border border-warning-border/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-warning-border/15 text-warning-text",children:e.jsx(Yn,{className:"h-3 w-3"})}),e.jsx("span",{className:"text-sm font-semibold text-warning-text",children:"Permission Request"})]}),s&&e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:z(s)}),e.jsx("div",{className:"mb-2 font-mono text-xs font-bold text-text-primary",children:z(t)}),t!=="AskUserQuestion"&&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:Tt(y,500)}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:d,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light transition-colors",children:"Approve"}),f&&i&&e.jsxs("button",{onClick:i,className:"flex items-center gap-1.5 rounded-lg border border-brand/40 bg-brand/10 px-4 py-2 text-sm font-medium text-brand hover:bg-brand/20 transition-colors",title:`允许并记住规则:${Lt(t,a)}`,children:[e.jsx(Qn,{className:"h-3.5 w-3.5"}),"Always allow ",Tt(Lt(t,a),40)]}),e.jsx("button",{onClick:m,className:"rounded-lg bg-status-error/20 px-4 py-2 text-sm font-medium text-status-error hover:bg-status-error/30 transition-colors",children:"Reject"})]})]})}function br({questions:r,description:t,onSubmit:n,onSkip:s}){const[a,d]=l.useState({}),[i,m]=l.useState({}),[y,f]=l.useState(0),h=(u,c,b)=>{if(b){const p=a[u]||[],g=p.includes(c)?p.filter(k=>k!==c):[...p,c];d({...a,[u]:g})}else d({...a,[u]:c})},w=u=>{var b;const c=(b=i[u])==null?void 0:b.trim();c&&(d({...a,[u]:c}),m({...i,[u]:""}))},v=()=>{var c,b;const u={};for(const[p,g]of Object.entries(a)){const k=r[parseInt(p,10)];k&&(typeof g=="number"?u[p]=((b=(c=k.options)==null?void 0:c[g])==null?void 0:b.label)||String(g):Array.isArray(g)?u[p]=g.map(j=>{var E,I;return((I=(E=k.options)==null?void 0:E[j])==null?void 0:I.label)||String(j)}):u[p]=g)}n(u)};if(r.length<=1){const u=r[0]||{question:t,options:[],multiSelect:!1},c=u.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 text-text-primary",children:z(t||u.question||"Question")}),e.jsxs("div",{className:"space-y-2",children:[(u.options||[]).map((b,p)=>{const g=c?(a[0]||[]).includes(p):a[0]===p;return e.jsxs("button",{onClick:()=>h(0,p,c),className:ke("w-full rounded-lg border px-4 py-2.5 text-left text-sm 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",children:z(b.label)}),b.description&&e.jsx("div",{className:"mt-0.5 text-xs text-text-muted",children:z(b.description)})]},p)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:i[0]||"",onChange:b=>m({...i,0:b.target.value}),placeholder:"Other...",className:"flex-1 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",onKeyDown:b=>b.key==="Enter"&&w(0)}),e.jsx("button",{onClick:()=>w(0),className:"rounded-lg border border-border px-3 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Send"})]})]}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx("button",{onClick:v,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light transition-colors",children:"Submit"}),e.jsx("button",{onClick:s,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})}const M=r[y];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 text-text-primary",children:z(t||"Questions")}),e.jsx("div",{className:"mb-3 flex gap-1 overflow-x-auto",children:r.map((u,c)=>e.jsx("button",{onClick:()=>f(c),className:ke("rounded-md px-3 py-1.5 text-xs whitespace-nowrap transition-colors",y===c?"bg-brand/20 text-brand":"text-text-muted hover:bg-surface-2"),children:u.header||`Q${c+1}`},c))}),M&&e.jsx(wr,{question:M,qIdx:y,answers:a,otherTexts:i,onSelect:h,onOtherTextChange:(u,c)=>m({...i,[u]:c}),onOtherSubmit:w}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-text-muted",children:[y+1," / ",r.length]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:v,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light transition-colors",children:"Submit All"}),e.jsx("button",{onClick:s,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})]})}function wr({question:r,qIdx:t,answers:n,otherTexts:s,onSelect:a,onOtherTextChange:d,onOtherSubmit:i}){const m=r.multiSelect||!1;return e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:z(r.question)}),e.jsxs("div",{className:"space-y-2",children:[(r.options||[]).map((y,f)=>{const h=m?(n[t]||[]).includes(f):n[t]===f;return e.jsxs("button",{onClick:()=>a(t,f,m),className:ke("w-full rounded-lg border px-4 py-2.5 text-left text-sm transition-colors",h?"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",children:z(y.label)}),y.description&&e.jsx("div",{className:"mt-0.5 text-xs text-text-muted",children:z(y.description)})]},f)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:s[t]||"",onChange:y=>d(t,y.target.value),placeholder:"Other...",className:"flex-1 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",onKeyDown:y=>y.key==="Enter"&&i(t)}),e.jsx("button",{onClick:()=>i(t),className:"rounded-lg border border-border px-3 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Send"})]})]})]})}function jr({planContent:r,description:t,onSubmit:n}){const[s,a]=l.useState(null),[d,i]=l.useState(""),m=!r||!r.trim(),y=()=>{s&&n(s,s==="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",children:e.jsx(Ne,{className:"h-3 w-3",strokeWidth:2.5})}),e.jsx("span",{className:"text-sm font-semibold text-text-primary",children:m?"Exit plan mode?":"Ready to code?"})]}),!m&&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:kr(r)}}),e.jsx("div",{className:"space-y-2",children:m?e.jsxs(e.Fragment,{children:[e.jsx(je,{selected:s==="yes-default",onClick:()=>a("yes-default"),label:"Yes"}),e.jsx(je,{selected:s==="no",onClick:()=>a("no"),label:"No"})]}):e.jsxs(e.Fragment,{children:[e.jsx(je,{selected:s==="yes-accept-edits",onClick:()=>a("yes-accept-edits"),label:"Yes, auto-accept edits",desc:"Approve plan and auto-accept file edits"}),e.jsx(je,{selected:s==="yes-default",onClick:()=>a("yes-default"),label:"Yes, manually approve edits",desc:"Approve plan but confirm each edit"}),e.jsx(je,{selected:s==="no",onClick:()=>a("no"),label:"No, keep planning",desc:"Provide feedback to refine the plan"})]})}),s==="no"&&e.jsx("textarea",{value:d,onChange:f=>i(f.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 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:y,disabled:!s,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:"Submit"})})]})}function je({selected:r,onClick:t,label:n,desc:s}){return e.jsxs("button",{onClick:t,className:ke("w-full rounded-lg border px-4 py-2.5 text-left text-sm 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:ke("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",children:n})]}),s&&e.jsx("div",{className:"mt-0.5 pl-6 text-xs text-text-muted",children:s})]})}function kr(r){let t=z(r);return t=t.replace(/```(\w*)\n?([\s\S]*?)```/g,(n,s,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 vr({request:r,onSubmit:t}){const n=Nr(r.requestedSchema),s=_r(r.requestedSchema),[a,d]=l.useState({}),i=n.length===0||s.every(m=>(a[m]??"").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(Bt,{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 hover:bg-brand/10 transition-colors",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:r.url}),e.jsx(yn,{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:"完成"}),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:"取消"})]})]}):e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx(Bt,{serverName:r.serverName,message:r.message}),n.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:n.map(({name:m,prop:y})=>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:m}),s.includes(m)&&e.jsx("span",{className:"text-[10px] font-medium text-warning-text",children:"必填"})]}),y.description&&e.jsx("div",{className:"mb-1 text-xs text-text-muted",children:z(y.description)}),e.jsx("input",{type:y.type==="number"?"number":"text",value:a[m]??"",onChange:f=>d(h=>({...h,[m]:f.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"})]},m))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{const m={};for(const{name:y,prop:f}of n){const h=(a[y]??"").trim();h&&(m[y]=f.type==="number"?Number(h):h)}t("accept",m)},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:"提交"}),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:"拒绝"})]})]})}function Bt({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",children:e.jsx(Un,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-sm font-semibold text-text-primary",children:["MCP 请求输入 ",e.jsx("span",{className:"font-mono text-xs text-text-muted",children:z(r)})]})]}),t&&e.jsx("div",{className:"text-sm text-text-secondary",children:z(t)})]})}function Nr(r){const t=r==null?void 0:r.properties;return!t||typeof t!="object"?[]:Object.entries(t).filter(([,n])=>n&&typeof n=="object").map(([n,s])=>({name:n,prop:s}))}function _r(r){const t=r==null?void 0:r.required;return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}function Sr(r){const[t,n]=l.useState([]),[s,a]=l.useState(!0),[d,i]=l.useState(null),m=l.useCallback(async()=>{a(!0),i(null);try{const h=await Vs(r);n(h)}catch(h){i(h instanceof Error?h.message:"Failed to load shares")}finally{a(!1)}},[r]);l.useEffect(()=>{m()},[m]);const y=l.useCallback(async h=>{i(null);try{const w=await Qs(r,h);return await m(),w}catch(w){throw i(w instanceof Error?w.message:"Failed to create share"),w}},[r,m]),f=l.useCallback(async h=>{i(null);try{await Gs(r,h),await m()}catch(w){throw i(w instanceof Error?w.message:"Failed to revoke share"),w}},[r,m]);return{shares:t,isLoading:s,error:d,createShare:y,revokeShare:f,refresh:m}}function Cr({open:r,onClose:t,sessionId:n,sessionTitle:s}){Jt();const{shares:a,isLoading:d,error:i,createShare:m,revokeShare:y}=Sr(n),[f,h]=l.useState("user"),[w,v]=l.useState(""),[M,u]=l.useState(""),[c,b]=l.useState("read"),[p,g]=l.useState(""),[k,j]=l.useState(!1),[E,I]=l.useState(null),[D,B]=l.useState(""),[X,C]=l.useState(!1),[U,K]=l.useState(!1);l.useEffect(()=>{r&&(h("user"),v(""),u(""),b("read"),g(""),j(!1),I(null),B(""),C(!1),K(!1))},[r]);const _e=async()=>{j(!0),B(""),I(null);try{const A={grantedTo:f==="user"?{userId:w.trim()}:{teamId:M.trim()},permission:c};p.trim()&&(A.expiresAt=p.trim());const ue=await m(A);I(`${window.location.origin}/code/s/${ue.shareToken}`)}catch(A){B(A instanceof Error?A.message:"Failed to create share")}finally{j(!1)}},Se=async A=>{try{await y(A)}catch{}},G=async()=>{if(!E)return;K(!1);try{if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(E),C(!0),setTimeout(()=>C(!1),2e3);return}}catch{}const A=document.createElement("textarea");A.value=E,A.style.position="fixed",A.style.opacity="0",document.body.appendChild(A),A.select();try{document.execCommand("copy"),C(!0),setTimeout(()=>C(!1),2e3)}catch{K(!0)}document.body.removeChild(A)};return e.jsx(ie,{open:r,onOpenChange:A=>{A||t()},children:e.jsxs(le,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(ce,{children:e.jsxs(de,{className:"font-display text-lg font-semibold text-text-primary",children:[S("share.title"),s?`: ${s}`:""]})}),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:S("share.grantTo")}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("button",{onClick:()=>h("user"),className:`rounded-md px-3 py-1 text-sm transition-colors ${f==="user"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:S("share.user")}),e.jsx("button",{onClick:()=>h("team"),className:`rounded-md px-3 py-1 text-sm transition-colors ${f==="team"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:S("share.team")})]}),f==="user"?e.jsx(jn,{onSelect:v,placeholder:S("share.userIdPlaceholder"),actionLabel:S("share.selectUser")}):e.jsx("input",{type:"text",value:M,onChange:A=>u(A.target.value),placeholder:S("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"}),f==="user"&&w&&e.jsxs("p",{className:"mt-1 text-xs text-text-muted",children:[S("share.selectedUser"),": ",e.jsx("span",{className:"font-mono",children:w})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:S("share.permission")}),e.jsxs("select",{value:c,onChange:A=>b(A.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:S("share.permissionRead")}),e.jsx("option",{value:"write",children:S("share.permissionWrite")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:S("share.expiresAt")}),e.jsx("input",{type:"datetime-local",value:p,onChange:A=>g(A.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"})]}),(D||i)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:D||i}),E&&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:S("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:E}),e.jsx("button",{onClick:G,className:"shrink-0 rounded-md bg-brand px-2 py-1 text-xs text-white hover:bg-brand-light transition-colors",children:X?S("share.copied"):S("share.copy")})]}),U&&e.jsx("p",{className:"mt-1 text-xs text-status-error",children:S("share.copyFailed")})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"mb-2 text-sm font-medium text-text-secondary",children:S("share.existingShares")}),d?e.jsx("p",{className:"text-sm text-text-muted",children:S("share.loading")}):a.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:S("share.none")}):e.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto",children:a.map(A=>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:A.granted_to_user||A.granted_to_team||"Unknown"}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[A.permission==="write"?S("share.permissionWrite"):S("share.permissionRead"),A.expires_at?` · expires ${A.expires_at}`:""]})]}),e.jsx("button",{onClick:()=>Se(A.id),className:"shrink-0 rounded-md px-2 py-1 text-xs text-status-error hover:bg-surface-3 transition-colors",children:S("share.revoke")})]},A.id))})]})]}),e.jsxs(pn,{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:S("common.close")}),e.jsx("button",{onClick:_e,disabled:k||(f==="user"?!w.trim():!M.trim()),className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light disabled:opacity-50 transition-colors",children:k?S("common.creating"):S("share.createShare")})]})]})})}function Er(r){const t=new Date,n=new Date(t.getTime()-1440*60*1e3),s=(i,m)=>i.getFullYear()===m.getFullYear()&&i.getMonth()===m.getMonth()&&i.getDate()===m.getDate(),a={today:[],yesterday:[],earlier:[]};for(const i of r){const m=new Date(i.modified||0);s(m,t)?a.today.push(i):s(m,n)?a.yesterday.push(i):a.earlier.push(i)}return[["today","今天"],["yesterday","昨天"],["earlier","更早"]].map(([i,m])=>({label:m,items:a[i]})).filter(i=>i.items.length>0)}function Tr(r){return r?new Date(r).toLocaleString():""}function Mr({open:r,onClose:t,adapter:n,onResume:s}){const[a,d]=l.useState([]),[i,m]=l.useState(!1),[y,f]=l.useState("");l.useEffect(()=>{if(!r)return;let w=!1;return m(!0),f(""),d([]),n.listResumableSessions().then(v=>{w||d(v)}).catch(v=>{w||f(v instanceof Error?v.message:String(v))}).finally(()=>{w||m(!1)}),()=>{w=!0}},[r,n]);const h=l.useMemo(()=>Er(a),[a]);return e.jsx(ie,{open:r,onOpenChange:w=>{w||t()},children:e.jsxs(le,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(ce,{children:e.jsx(de,{className:"font-display text-lg font-semibold text-text-primary",children:"恢复历史对话"})}),e.jsxs("div",{className:"max-h-96 min-w-0 space-y-4 overflow-y-auto",children:[i&&e.jsx("p",{className:"py-6 text-center text-sm text-text-muted",children:"正在加载本地会话列表…"}),!i&&y&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:y}),!i&&!y&&a.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-text-muted",children:"没有可恢复的历史对话"}),!i&&!y&&h.map(w=>e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-xs font-medium text-text-muted",children:w.label}),e.jsx("div",{className:"space-y-1",children:w.items.map(v=>e.jsxs("button",{type:"button",onClick:()=>s(v),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:v.title}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[Tr(v.modified),v.gitBranch?` · ${v.gitBranch}`:""]})]},v.sessionId))})]},w.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:"取消"})})]})})}class Rr{constructor(t,n,s,a){T(this,"pending",null);this.current=t,this.apply=n,this.send=s,this.onError=a}set(t){if(t===this.current)return;const n=this.current;this.current=t,this.pending={requestId:null,previous:n},this.apply(t);try{Promise.resolve(this.send(t)).then(s=>{this.pending&&(this.pending.requestId=s)}).catch(s=>{this.rollback(n,Ht(s),"send")})}catch(s){this.rollback(n,Ht(s),"send")}}handleControlResponse(t){const n=this.pending;if(!n||n.requestId!==t.requestId)return!1;const{previous:s}=n;return this.pending=null,t.subtype==="error"&&this.rollback(s,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,n,s){var a;this.pending=null,this.current=t,this.apply(t),n&&((a=this.onError)==null||a.call(this,n,s))}}function Ht(r){return r instanceof Error?r.message:String(r)}function nt(r){const t=l.useRef(r);t.current=r;const n=l.useRef(null);n.current||(n.current=new Rr(r.value,a=>t.current.apply(a),a=>t.current.send(a),(a,d)=>{var i,m;return(m=(i=t.current).onError)==null?void 0:m.call(i,a,d)}));const s=n.current;return l.useEffect(()=>{s.adoptExternal(r.value)}),l.useMemo(()=>({set:a=>s.set(a),handleControlResponse:a=>s.handleControlResponse(a),sync:a=>s.sync(a)}),[s])}const as="rcs_context_usage_";function os(){try{if(typeof localStorage<"u")return localStorage}catch{}return null}function Wt(){return{totalTokens:0,rawMaxTokens:0,percentage:0}}function Ar(r){if(!r||typeof r!="object"||Array.isArray(r))return null;const t=r,{totalTokens:n,rawMaxTokens:s,percentage:a}=t;if(typeof n!="number"||typeof s!="number"||typeof a!="number")return null;const d=t.categories,i=Array.isArray(d)?d.filter(m=>!!m&&typeof m=="object"&&typeof m.name=="string").map(m=>({name:m.name,tokens:typeof m.tokens=="number"?m.tokens:0,...m.isDeferred===!0?{isDeferred:!0}:{}})):void 0;return{totalTokens:n,rawMaxTokens:s,percentage:a,...typeof t.model=="string"&&t.model?{model:t.model}:{},...i&&i.length>0?{categories:i}:{}}}function $r(r,t=os()){if(!t||!r)return null;try{const n=t.getItem(as+r);return n?Ar(JSON.parse(n)):null}catch{return null}}function Ir(r,t,n=os()){if(!(!n||!r))try{n.setItem(as+r,JSON.stringify(t))}catch{}}function Dr(r){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/acp/relay/${r}`}function qr(r){const t=Dr(r),n=Js(),s=n?{proxyUrl:t,token:n}:{proxyUrl:t};return new Ys(s)}const ae=[{value:"default",label:"默认",description:"手动审批权限请求"},{value:"acceptEdits",label:"自动接受编辑",description:"自动允许文件编辑操作"},{value:"plan",label:"规划模式",description:"仅规划,不执行工具"},{value:"bypassPermissions",label:"跳过权限",description:"跳过所有权限检查"}],zt="rcs_permission_mode";function oe(r){return r<1e3?String(r):r<1e6?`${(r/1e3).toFixed(1)}k`:`${(r/1e6).toFixed(1)}M`}function Pr(r){const t=ae.findIndex(n=>n.value===r);return ae[(t+1+ae.length)%ae.length].value}const at=[{value:"off",label:"关闭思考",tokens:null,description:"不使用扩展思考"},{value:"on",label:"默认思考",tokens:0,description:"开启,使用默认预算"},{value:"8192",label:"8k",tokens:8192,description:"8192 tokens"},{value:"16384",label:"16k",tokens:16384,description:"16384 tokens"},{value:"32768",label:"32k",tokens:32768,description:"32768 tokens"}],Kt="rcs_thinking_budget",ot=[{value:"auto",effort:void 0,label:"自动",description:"使用模型默认 effort"},{value:"low",effort:"low",label:"low",description:"低推理力度"},{value:"medium",effort:"medium",label:"medium",description:"中推理力度"},{value:"high",effort:"high",label:"high",description:"高推理力度"},{value:"xhigh",effort:"xhigh",label:"xhigh",description:"超高推理力度"},{value:"max",effort:"max",label:"max",description:"最大推理力度"}],Vt="rcs_effort";function Ur(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 Or({budget:r,onBudgetChange:t,disabled:n}){const[s,a]=l.useState(!1),d=at.find(i=>i.value===r);return e.jsxs(Ue,{open:s,onOpenChange:a,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:n,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:"思考预算",children:[e.jsx(xn,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:(d==null?void 0:d.label)??"思考"}),s?e.jsx(Fe,{className:"h-3 w-3"}):e.jsx(Le,{className:"h-3 w-3"})]})}),e.jsx(Be,{className:"w-64 p-1",align:"start",children:at.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(Ne,{className:"h-3.5 w-3.5 text-brand"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:i.label}),e.jsx("div",{className:"text-xs text-text-muted",children:i.description})]})]},i.value))})]})}function Fr({effort:r,onEffortChange:t,disabled:n}){const[s,a]=l.useState(!1),d=ot.find(i=>i.value===r);return e.jsxs(Ue,{open:s,onOpenChange:a,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:n,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:"Effort 档位",children:[e.jsx(Rn,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:(d==null?void 0:d.label)??"自动"}),s?e.jsx(Fe,{className:"h-3 w-3"}):e.jsx(Le,{className:"h-3 w-3"})]})}),e.jsx(Be,{className:"w-64 p-1",align:"start",children:ot.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(Ne,{className:"h-3.5 w-3.5 text-brand"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:i.label}),e.jsx("div",{className:"text-xs text-text-muted",children:i.description})]})]},i.value))})]})}const Qt=["bg-brand","bg-status-active","bg-status-success","bg-violet-500","bg-amber-500","bg-pink-500","bg-teal-500"];function Lr({usage:r}){const t=Math.min(100,Math.max(0,r.percentage)),n=t>=80,s=(r.categories??[]).filter(i=>!i.isDeferred),a=(r.categories??[]).filter(i=>i.isDeferred),d=[`上下文用量:${oe(r.totalTokens)} / ${oe(r.rawMaxTokens)} tokens${r.model?` · ${r.model}`:""}`,...s.slice(0,8).map(i=>`${i.name}: ${oe(i.tokens)}`),...a.slice(0,3).map(i=>`${i.name}(延迟加载): ${oe(i.tokens)}`)];return e.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-text-muted font-mono",title:d.join(`
87
+ `),children:[e.jsx("span",{className:"relative flex h-1.5 w-16 overflow-hidden rounded-full bg-surface-3",children:s.length>0?s.map((i,m)=>e.jsx("span",{className:n&&m===0?"bg-status-warning":Qt[m%Qt.length],style:{width:`${Math.min(100,Math.max(0,i.tokens/r.rawMaxTokens*100))}%`}},i.name)):e.jsx("span",{className:`absolute inset-y-0 left-0 rounded-full transition-all ${n?"bg-status-warning":"bg-brand/70"}`,style:{width:`${t}%`}})}),e.jsxs("span",{children:[t,"%"]})]})}function Br({models:r,currentModelId:t,onSelect:n,disabled:s}){const[a,d]=l.useState(!1),i=r.find(f=>f.modelId===t)??null,m=r.length>0,y=async f=>{n(f.modelId),d(!1)};return e.jsxs(Ue,{open:a,onOpenChange:m?d:void 0,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:s||!m,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:"选择模型",children:[e.jsx(es,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-32 truncate",children:(i==null?void 0:i.name)??t??"选择模型"}),a?e.jsx(Fe,{className:"h-3 w-3"}):e.jsx(Le,{className:"h-3 w-3"})]})}),e.jsx(Be,{className:"w-72 p-0",align:"start",children:e.jsx(mn,{models:r,currentModelId:t,onSelect:y,showSearch:r.length>5})})]})}function Hr({mode:r,onModeChange:t,disabled:n}){const[s,a]=l.useState(!1),d=ae.find(i=>i.value===r);return e.jsxs(Ue,{open:s,onOpenChange:a,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:n,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:"权限模式(Shift+Tab 循环)",children:[e.jsx(un,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:(d==null?void 0:d.label)??r}),s?e.jsx(Fe,{className:"h-3 w-3"}):e.jsx(Le,{className:"h-3 w-3"})]})}),e.jsx(Be,{className:"w-64 p-1",align:"start",children:ae.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(Ne,{className:"h-3.5 w-3.5 text-brand"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-text-primary",children:i.label}),e.jsx("div",{className:"text-xs text-text-muted",children:i.description})]})]},i.value))})]})}function aa({sessionId:r,onSessionLoaded:t}){Jt();const[n,s]=l.useState(null),[a,d]=l.useState(null),[i,m]=l.useState(""),[y,f]=l.useState(!1),[h,w]=l.useState(!1),[v,M]=l.useState(!1),[u,c]=l.useState(!1),[b,p]=l.useState(!1),[g,k]=l.useState(!1),[j,E]=l.useState(""),[I,D]=l.useState(0),B=l.useRef(null),[X,C]=l.useState({text:"",nonce:0}),[U,K]=l.useState(!1),[_e,Se]=l.useState(!1),[G,A]=l.useState(!1),[ue,it]=l.useState(0),[is,ls]=l.useState(0),[me,Y]=l.useState([]),[Q,xe]=l.useState(!1),[fe,te]=l.useState([]),[H,He]=l.useState(null),[cs,ds]=l.useState(()=>rs()),[W,us]=l.useState(null),[lt,ms]=l.useState(()=>localStorage.getItem(Kt)||"off"),[xs,ct]=l.useState(()=>$r(r)),[We,ze]=l.useState(!0),[pe,fs]=l.useState(null),[Ce,dt]=l.useState(null),[Ee,Te]=l.useState([]),[ut,Ke]=l.useState(!1),[Ve,mt]=l.useState(""),Qe=l.useRef(null),[Me,ps]=l.useState(()=>localStorage.getItem(zt)||"default"),[xt,ft]=l.useState(null),he=l.useRef(null),[pt,ht]=l.useState(null),ge=l.useRef(null),se=l.useRef(null),gt=l.useRef(me);gt.current=me;const Re=l.useRef(t);Re.current=t;const Ae=l.useRef(null);Ae.current||(Ae.current=new kn(vn()));const yt=l.useRef(r);yt.current=(n==null?void 0:n.title)||r,l.useEffect(()=>{var o;(o=Ae.current)==null||o.reset()},[r]);const Z=l.useCallback(o=>{ft(o),he.current&&clearTimeout(he.current),he.current=setTimeout(()=>ft(null),5e3)},[]),J=l.useCallback(o=>{ht(o),ge.current&&clearTimeout(ge.current),ge.current=setTimeout(()=>ht(null),5e3)},[]),$e=nt({value:Me,apply:o=>{ps(o);try{localStorage.setItem(zt,o)}catch{}},send:o=>{const x=se.current;return x?x.setPermissionMode(o):Promise.reject(new Error("adapter not ready"))},onError:(o,x)=>{console.error("[SessionDetail] set permission mode failed:",o),Z(x==="send"?`模式切换请求发送失败: ${o}`:o||"模式切换失败")}}),Ge=l.useCallback(o=>$e.set(o),[$e]),Ye=nt({value:lt,apply:o=>{ms(o);try{localStorage.setItem(Kt,o)}catch{}},send:o=>{var N;const x=se.current;if(!x)return Promise.reject(new Error("adapter not ready"));const _=((N=at.find(R=>R.value===o))==null?void 0:N.tokens)??null;return x.setThinkingBudget(_)},onError:(o,x)=>{console.error("[SessionDetail] set thinking budget failed:",o),Z(x==="send"?`思考预算请求发送失败: ${o}`:o||"思考预算切换失败")}}),$=l.useMemo(()=>new sr(r,Y,{onStatusChange:o=>{var x;d(o),xe(o==="running"||o==="requires_action"),(x=Ae.current)==null||x.onStatus(o,yt.current)},onError:o=>{console.error("[RCSChatAdapter] error:",o)},onPermissionRequest:o=>{te(x=>x.some(_=>_.requestId===o.requestId)?x:[...x,o])},onModelsStateChange:o=>{He(o)},onSubagentUpdate:o=>{ds(o)},onControlResponse:o=>{Ye.handleControlResponse(o)||$e.handleControlResponse(o)},onPermissionModeChange:o=>{$e.sync(o)},onUsageChange:o=>{fs(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=>{us(x=>JSON.stringify(x)===JSON.stringify(o)?x:o)},onElicitationRequest:o=>{dt(o)}}),[r,Z]);l.useEffect(()=>(se.current=$,()=>{$.disconnect()}),[$]);const P=l.useMemo(()=>Ur(W),[W]),Je=l.useMemo(()=>Xs((W==null?void 0:W.commands)??[],(W==null?void 0:W.skills)??[]),[W]),ye=l.useMemo(()=>Zs(me,j),[me,j]),hs=l.useCallback(o=>Ye.set(o),[Ye]),[bt,gs]=l.useState(()=>localStorage.getItem(Vt)||"auto"),ys=nt({value:bt,apply:o=>{gs(o);try{localStorage.setItem(Vt,o)}catch{}},send:o=>{var N;const x=se.current;if(!x)return Promise.reject(new Error("adapter not ready"));const _=(N=ot.find(R=>R.value===o))==null?void 0:N.effort;return x.setEffort(_)},onError:(o,x)=>{console.error("[SessionDetail] set effort failed:",o),Z(x==="send"?`Effort 切换请求发送失败: ${o}`:o||"Effort 切换失败")}}),Xe=l.useCallback(()=>{var o;P.get_context_usage&&((o=se.current)==null||o.getContextUsage().then(x=>{x&&(ct(x),Ir(r,x))}).catch(()=>{}).finally(()=>ze(!1)))},[P,r]);l.useEffect(()=>{if(!P.get_context_usage)return;Q||Xe();const o=setInterval(Xe,6e4);return()=>clearInterval(o)},[P,Q,Xe]),l.useEffect(()=>{W&&!P.get_context_usage&&ze(!1)},[W,P]),l.useEffect(()=>{if(!We)return;const o=setTimeout(()=>ze(!1),1e4);return()=>clearTimeout(o)},[We]);const wt=l.useRef(G);wt.current=G,l.useEffect(()=>re.onEvent(x=>{x.type!=="artifact_created"&&x.type!=="artifact_updated"||(wt.current&&ls(_=>_+1),it(_=>_+1))}),[]);const[be,bs]=l.useState("idle");l.useEffect(()=>re.onStateChange(x=>bs(x)),[]),l.useEffect(()=>{G&&it(0)},[G]),l.useEffect(()=>{let o=!1;async function x(){var _;m("");try{const N=await At(r);if(o)return;s(N),d(N.status),qe(N.status)&&$.markClosed(),xe(N.status==="running"||N.status==="requires_action"),(_=Re.current)==null||_.call(Re,N)}catch(N){if(o)return;m(N instanceof Error?N.message:S("session.loadFailed"));return}try{await $.init()}catch(N){console.warn("Failed to init adapter:",N)}}return x(),()=>{o=!0}},[r,$]);const q=qe(a),jt=l.useRef(a);jt.current=a,l.useEffect(()=>{if(q)return;let o=!1;const _=setInterval(async()=>{try{const N=await At(r);if(o||N.status===jt.current)return;qe(N.status)&&$.markClosed(),d(N.status),xe(N.status==="running"||N.status==="requires_action")}catch{}},6e4);return()=>{o=!0,clearInterval(_)}},[r,q,$]);const O=(n==null?void 0:n.access_level)==="read",kt=xs??(We&&!q&&!O?Wt():null),Ze=l.useCallback(()=>{Y([]),ct(Wt()),Mt(r).catch(o=>{console.warn("[SessionDetail] Failed to clear session history:",o)})},[r]),we=l.useCallback(async(o,x)=>{const _=se.current;if(!_||q)return;if(o.sessionId===r){Y(R=>[...R,{type:"command_output",id:`cmd-resume-${Date.now()}`,commandName:"resume",inputText:x??"/resume",title:"Resume",subtitle:"恢复历史对话",outputText:"不能恢复当前会话自身",variant:"error"}]);return}const N=(R,F="default")=>Y(ee=>[...ee,{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:"恢复历史对话",outputText:R,variant:F}]);N(`正在恢复「${o.title}」…`);try{await Mt(r),Y([]);const R=await _.resumeSession(o.sessionId);N(`已恢复 ${R.messageCount} 条消息${R.title?`:${R.title}`:""}`)}catch(R){N(`恢复失败:${R instanceof Error?R.message:String(R)}`,"error")}},[q,r]),ws=l.useCallback(async()=>{if(n!=null&&n.environment_id)try{const o=await en({environment_id:n.environment_id});window.location.href=`/code/${o.id}?resumeFrom=${r}`}catch(o){J(`创建会话失败:${o instanceof Error?o.message:String(o)}`)}},[n,r,J]),js=l.useRef(new URLSearchParams(window.location.search).get("resumeFrom")),vt=l.useRef(!1);l.useEffect(()=>{const o=js.current;!o||vt.current||!W||!P.resume||(vt.current=!0,window.history.replaceState({},"",window.location.pathname),we({sessionId:o,title:o.slice(0,8),modified:0},null))},[W,P.resume,we]);const Ie=l.useCallback(async o=>{const x=o.text.trim(),_=o.images&&o.images.length>0||o.attachments&&o.attachments.length>0;if(!x&&!_||q)return;const N=/^\/resume(?:\s+(.*))?$/.exec(x);if(N){const F=(N[1]??"").trim();if(!P.resume){Y(ee=>[...ee,{type:"user_message",id:`user-${Date.now()}`,content:x},{type:"command_output",id:`cmd-${Date.now()}`,commandName:"resume",inputText:x,title:"Resume",subtitle:"恢复历史对话",outputText:"当前 worker 不支持 /resume(需要 spawn 模式 worker:slz rc)",variant:"error"}]);return}F?await we({sessionId:F,title:F,modified:0},x):p(!0);return}const R=await tn(x,{sessionId:r,availableCommands:Je,availableModels:(H==null?void 0:H.availableModels)??[],currentModel:H?{modelId:H.currentModelId,name:H.currentModelId}:null,supportsImages:!0,entries:gt.current,setModel:async F=>{await V(r,{type:"control_request",request:{subtype:"set_model",model:F}}),He(ee=>ee&&{...ee,currentModelId:F})},onNewSession:()=>{Y([])}}).catch(()=>null);if(R){if(Pe("[SessionDetail] local command result",R),"clearEntries"in R&&R.clearEntries){Ze();return}if("newSession"in R&&R.newSession){Ze();return}if("userEntry"in R){Y(F=>[...F,R.userEntry,R.cmdEntry]);return}}xe(!0);try{await $.sendMessage(x,o.images,o.attachments)}catch(F){if(console.error("Send failed:",F),F instanceof sn&&F.type==="session_closed"){d("archived"),$.markClosed(),J(S("session.closedSendBlocked"));return}J(`${S("session.sendFailed")}${F instanceof Error?`: ${F.message}`:""}`)}},[$,q,r,H,Je,Ze,J,we,P]),ks=l.useCallback(o=>{if(Q){Te(x=>[...x,o]);return}Ie(o)},[Q,Ie]),et=l.useRef(!1);l.useEffect(()=>{if(q){Te(x=>x.length>0?[]:x);return}if(Q||Ee.length===0||et.current)return;const o=Ee[0];o&&(et.current=!0,Te(x=>x.slice(1)),Ie(o).finally(()=>{et.current=!1}))},[Q,Ee,Ie,q]);const vs=l.useCallback((o,x)=>{if(Q)return;const _=x==="edit"?"回退到这条消息并编辑?":"回退到这条消息?";window.confirm(`${_}
88
+ 之后的对话将移除,已修改的文件将恢复到当时的状态(若有快照)。`)&&$.rewindToMessage(o.id).then(()=>{x==="edit"&&o.content&&C(N=>({text:o.content,nonce:N.nonce+1}))}).catch(N=>{console.error("[SessionDetail] rewind failed:",N),J(`回退失败: ${N instanceof Error?N.message:String(N)}`)})},[Q,J]),Ns=l.useCallback(o=>{const x=ye.orderedMatchIds;if(x.length===0)return;const _=(o%x.length+x.length)%x.length;D(_);const N=x[_],R=document.querySelector(`[data-entry-id="${CSS.escape(N)}"]`);R==null||R.scrollIntoView({block:"center",behavior:"smooth"})},[ye]),Nt=l.useCallback(async()=>{try{await $.interrupt()}catch(o){console.error("Interrupt failed:",o)}finally{xe(!1)}},[$]),_s=l.useCallback(()=>{Ge(Pr(Me))},[Ge,Me]);l.useEffect(()=>()=>{he.current&&clearTimeout(he.current),ge.current&&clearTimeout(ge.current)},[]);const Ss=l.useCallback(async()=>{if(n&&window.confirm(S("dashboard.confirmDelete").replace("{id}",n.title||n.id)))try{await Rt(n.id),window.location.href="/code/"}catch(o){alert(o instanceof Error?o.message:S("dashboard.deleteFailed"))}},[n]),Cs=l.useCallback(async o=>{try{await $.respondPermission(o,!0)}catch(x){console.error("Failed to approve:",x)}te(x=>x.filter(_=>_.requestId!==o))},[$]),Es=l.useCallback(async(o,x)=>{try{await $.respondPermission(o,!0,{updated_permissions:x})}catch(_){console.error("Failed to approve with rules:",_)}te(_=>_.filter(N=>N.requestId!==o))},[$]),Ts=l.useCallback(async(o,x)=>{const _=Ce;if(dt(null),!!_)try{await $.respondElicitation(_.requestId,o,x)}catch(N){console.error("Failed to submit elicitation:",N)}},[Ce,$]),Ms=l.useCallback(()=>{!n||O||(mt(n.title||""),Ke(!0),setTimeout(()=>{var o,x;(o=Qe.current)==null||o.focus(),(x=Qe.current)==null||x.select()},0))},[n,O]),_t=l.useCallback(async()=>{const o=Ve.trim();if(Ke(!1),!(!n||!o||o===n.title))try{const x=await nn(n.id,o);s(_=>_&&{..._,title:x.title??o})}catch(x){console.error("Rename failed:",x),alert(x instanceof Error?x.message:"重命名失败")}},[n,Ve]),Rs=l.useCallback(async o=>{try{await $.respondPermission(o,!1)}catch(x){console.error("Failed to reject:",x)}te(x=>x.filter(_=>_.requestId!==o))},[$]),As=l.useCallback(async(o,x,_)=>{try{await V(r,{type:"permission_response",approved:!0,request_id:o,updated_input:{questions:_,answers:x}})}catch(N){console.error("Failed to submit answers:",N)}te(N=>N.filter(R=>R.requestId!==o))},[r]),$s=l.useCallback(async(o,x,_)=>{try{x==="no"?await V(r,{type:"permission_response",approved:!1,request_id:o,..._?{message:_}:{}}):await V(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(N){console.error("Failed to submit plan response:",N)}te(N=>N.filter(R=>R.requestId!==o))},[r]);return i?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 hover:underline",children:S("session.backToDashboard")})]})}):n?n.source==="acp"&&n.environment_id?e.jsx(zr,{sessionId:r,agentId:n.environment_id}):e.jsx(Xt,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx("h1",{className:"sr-only",children:n.title||n.id}),e.jsx("div",{className:"border-b bg-surface-1 px-4 py-3",children:e.jsxs("div",{className:"mx-auto max-w-5xl",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[ut?e.jsx("input",{ref:Qe,value:Ve,onChange:o=>mt(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),_t()):o.key==="Escape"&&(o.preventDefault(),Ke(!1))},onBlur:()=>void _t(),maxLength:200,className:"w-full max-w-md rounded-lg border border-brand/50 bg-surface-2 px-2.5 py-1 font-display text-lg font-semibold text-text-primary focus:outline-none focus:ring-2 focus:ring-brand/30"}):e.jsxs("h2",{className:"group/title flex min-w-0 items-center gap-1.5 font-display text-lg font-semibold text-text-primary",children:[e.jsx("span",{className:"truncate",children:n.title||n.id}),!O&&!q&&e.jsx("button",{type:"button",onClick:Ms,className:"flex-shrink-0 rounded p-0.5 text-text-muted opacity-0 transition-opacity hover:text-text-primary group-hover/title:opacity-100",title:"重命名会话",children:e.jsx(rn,{className:"h-3.5 w-3.5"})})]}),n.visibility&&!ut&&e.jsx(wn,{visibility:n.visibility||"private"})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:[(()=>{var _;const o=n.source==="acp"?"acp":(_=n.environment)==null?void 0:_.worker_type,x=fn(o);return e.jsx("span",{className:`rounded-full px-2 py-0.5 text-xs font-medium ${x.colorClass}`,children:x.fullLabel})})(),a&&e.jsx(Gt,{status:a}),e.jsx("span",{className:"text-xs text-text-muted",children:Yt(n.created_at)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>A(!G),className:`relative flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors ${G?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:S("artifacts.title"),children:[e.jsx(an,{className:"h-3.5 w-3.5"}),ue>0&&!G&&e.jsx("span",{className:"absolute -right-1.5 -top-1.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-status-active px-1 text-[10px] font-bold text-white",children:ue>9?"9+":ue})]}),P.side_question&&!q&&!O&&e.jsx("button",{onClick:()=>c(!u),className:`flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors ${u?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:"旁路提问 — 针对会话上下文提问,不进入主对话",children:e.jsx(ts,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>{const o=!g;k(o),o?setTimeout(()=>{var x;return(x=B.current)==null?void 0:x.focus()},0):(E(""),D(0))},className:`flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors ${g?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:"搜索会话内容",children:e.jsx(rt,{className:"h-3.5 w-3.5"})}),P.mcp_management&&!q&&!O&&e.jsx("button",{onClick:()=>w(!h),className:`flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors ${h?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:"MCP 服务器",children:e.jsx(ss,{className:"h-3.5 w-3.5"})}),P.remote_settings&&!q&&!O&&e.jsx("button",{onClick:()=>M(!v),className:`flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors ${v?"bg-brand-light text-white":"text-text-muted hover:bg-surface-2 hover:text-text-secondary"}`,title:"会话设置",children:e.jsx(ns,{className:"h-3.5 w-3.5"})}),!O&&(n==null?void 0:n.access_level)!=="write"&&e.jsx("button",{onClick:()=>Se(!0),className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs text-text-muted hover:bg-surface-2 hover:text-text-secondary transition-colors",title:S("session.share"),children:e.jsx(Kn,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>K(!U),className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs text-text-muted hover:bg-surface-2 hover:text-text-secondary transition-colors",title:S("session.info"),children:e.jsx(Dn,{className:"h-3.5 w-3.5"})}),e.jsxs("button",{onClick:()=>f(!y),className:"flex items-center gap-1 rounded-md px-3 py-1.5 text-sm text-text-primary font-bold hover:bg-brand-light hover:text-white transition-colors",children:[S("session.tasks"),fe.length>0&&e.jsx("span",{className:"ml-1 rounded-full bg-status-warning px-1.5 py-0.5 text-[10px] font-medium text-white",children:fe.length})]})]})]}),U&&e.jsxs("div",{className:"mt-2 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:S("session.metaSession")})," ",n.id]}),n.environment_id&&e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:S("session.metaEnvironment")})," ",n.environment_id]})]})]})}),(be==="reconnecting"||be==="failed")&&e.jsxs("div",{className:`flex items-center justify-center gap-2 px-4 py-1.5 text-xs font-medium ${be==="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 ${be==="failed"?"bg-status-error":"animate-pulse bg-status-warning"}`}),be==="failed"?S("session.sseFailed"):S("session.sseReconnecting")]}),G&&e.jsx("div",{className:"border-b bg-surface-1 px-4 py-4",children:e.jsx("div",{className:"mx-auto max-w-3xl",children:e.jsx(bn,{sessionId:r,embedded:!0,refreshTick:is})})}),g&&e.jsx("div",{className:"border-b bg-surface-1 px-4 py-2",children:e.jsxs("div",{className:"mx-auto flex max-w-3xl items-center gap-2",children:[e.jsx(rt,{className:"h-3.5 w-3.5 flex-shrink-0 text-text-muted"}),e.jsx("input",{ref:B,value:j,onChange:o=>{E(o.target.value),D(0)},onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),Ns(j&&o.shiftKey?I-1:I+1)):o.key==="Escape"&&(o.preventDefault(),k(!1),E(""))},placeholder:"搜索会话内容…",className:"w-full bg-transparent text-sm text-text-primary placeholder:text-text-muted focus:outline-none"}),j.trim()&&e.jsx("span",{className:"flex-shrink-0 font-mono text-[11px] text-text-muted",children:ye.orderedMatchIds.length===0?"无结果":`${I+1}/${ye.orderedMatchIds.length}`})]})}),e.jsx(on,{entries:me,isLoading:Q,emptyTitle:S("session.emptyTitle"),emptyDescription:S("session.emptyDescription"),searchMatchIds:j.trim()?ye.matchIds:void 0,onRewindEntry:P.rewind&&!q&&!O&&!Q?(o,x)=>vs(o,x):void 0}),e.jsx(gr,{state:cs,onStopTask:P.stop_task?o=>{$.stopSubagent(o).then(x=>{x.ok||J(x.error||"停止任务失败")})}:void 0}),fe.length>0&&e.jsx("div",{className:"border-t bg-surface-1 px-4 py-3",children:e.jsx("div",{className:"mx-auto max-w-3xl space-y-3",children:fe.map(o=>e.jsx(Wr,{request:o,onApprove:()=>Cs(o.requestId),onApproveAlways:o.suggestions&&o.suggestions.length>0?()=>Es(o.requestId,o.suggestions??[]):void 0,onReject:()=>Rs(o.requestId),onSubmitAnswers:As,onSubmitPlan:$s},o.requestId))})}),Ce&&e.jsx("div",{className:"border-t bg-surface-1 px-4 py-3",children:e.jsx("div",{className:"mx-auto max-w-3xl",children:e.jsx(vr,{request:Ce,onSubmit:Ts})})}),pt&&e.jsx("div",{className:"mx-auto max-w-3xl w-full px-4 sm:px-8 pb-1",children:e.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 px-3 py-1.5 text-xs text-red-700 dark:text-red-300",children:pt})}),xt&&e.jsx("div",{className:"mx-auto max-w-3xl 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:xt})}),e.jsxs("div",{className:"max-w-3xl 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(Hr,{mode:Me,onModeChange:Ge,disabled:q||O}),e.jsx(Br,{models:(H==null?void 0:H.availableModels)??[],currentModelId:(H==null?void 0:H.currentModelId)??null,onSelect:o=>{V(r,{type:"control_request",request:{subtype:"set_model",model:o}}),He(x=>x&&{...x,currentModelId:o})},disabled:q||O}),P.set_max_thinking_tokens&&e.jsx(Or,{budget:lt,onBudgetChange:hs,disabled:q||O}),P.set_effort&&e.jsx(Fr,{effort:bt,onEffortChange:o=>ys.set(o),disabled:q||O})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[kt&&e.jsx(Lr,{usage:kt}),pe&&e.jsxs("span",{className:"text-[11px] text-text-muted font-mono",title:"会话累计用量(input 含缓存读写)",children:[oe(pe.inputTokens)," in / ",oe(pe.outputTokens)," out",pe.totalCostUsd!=null&&` · $${pe.totalCostUsd.toFixed(2)}`]})]})]}),q&&(n==null?void 0:n.environment_id)&&e.jsx("div",{className:"mx-auto w-full max-w-3xl px-4 pb-2 sm:px-8",children:e.jsx("button",{type:"button",onClick:()=>void ws(),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:"在新会话中继续此对话(/resume)"})}),e.jsx(ln,{onSubmit:ks,isLoading:Q,onInterrupt:Nt,onCycleMode:_s,disabled:q||O,placeholder:q?S("session.closed"):O?S("session.readOnly"):S("session.inputPlaceholder"),supportsAttachments:!0,commands:Je,queueWhileLoading:!0,queuedCount:Ee.length,onDequeue:o=>Te(x=>x.filter((_,N)=>N!==o)),onSearchFiles:P.file_search?o=>$.searchFiles(o):void 0,historyKey:r,draftOverride:X}),h&&e.jsx(cr,{onClose:()=>w(!1),fetchServers:()=>$.getMcpServers(),onToggle:(o,x)=>$.toggleMcpServer(o,x),onReconnect:o=>$.reconnectMcpServer(o)}),v&&e.jsx(ur,{onClose:()=>M(!1),fetchSettings:()=>$.getRemoteSettings(),onApply:o=>$.applyFlagSettings(o)}),u&&e.jsx(mr,{onClose:()=>c(!1),onAsk:o=>$.askSideQuestion(o)}),y&&n&&e.jsx(or,{onClose:()=>f(!1),session:n,liveStatus:a,pendingPermissions:fe,onInterrupt:Nt,onDelete:Ss,onEndSession:P.end_session&&!q&&!O?async()=>{await $.endSession("ended from web"),await Rt(n.id),window.location.href="/code/"}:void 0}),e.jsx(Cr,{open:_e,onClose:()=>Se(!1),sessionId:n.id,sessionTitle:n.title||void 0}),e.jsx(Mr,{open:b,onClose:()=>p(!1),adapter:$,onResume:o=>{p(!1),we(o,null)}})]})}):e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx("div",{className:"text-text-muted",children:S("session.loading")})})}function Wr({request:r,onApprove:t,onApproveAlways:n,onReject:s,onSubmitAnswers:a,onSubmitPlan:d}){const i=r.toolName,m=r.toolInput,y=r.description||"";if(i==="AskUserQuestion"){const f=m.questions||[];return e.jsx(br,{requestId:r.requestId,questions:f,description:y,onSubmit:h=>a(r.requestId,h,f),onSkip:s})}if(i==="ExitPlanMode"){const f=m.plan||"";return e.jsx(jr,{requestId:r.requestId,planContent:f,description:y,onSubmit:(h,w)=>d(r.requestId,h,w)})}return e.jsx(yr,{requestId:r.requestId,toolName:i,toolInput:m,description:y,suggestions:r.suggestions,onApprove:t,onApproveAlways:n,onReject:s})}function zr({sessionId:r,agentId:t}){const[n,s]=l.useState(null),[a,d]=l.useState("disconnected"),[i,m]=l.useState(null),y=l.useRef(null);return l.useEffect(()=>{const f=qr(t);return f.setConnectionStateHandler((h,w)=>{d(h),m(w||null)}),y.current=f,s(f),f.connect().catch(h=>{h instanceof cn||(m(h.message),d("error"))}),()=>{f.disconnect(),y.current=null,s(null),d("disconnected")}},[t]),e.jsx(Xt,{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:S("session.connectingAgent")})]})}),a==="error"&&!n&&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:S("session.connectionFailed")}),e.jsx("p",{className:"text-text-muted text-sm",children:i})]})}),n&&a==="connected"&&e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(dn,{client:n,agentId:t})})]})})}export{aa as SessionDetail};