@saluzi/saluzi-edu 0.2.61 → 0.2.63

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 (147) hide show
  1. package/dist/cli.js +204 -116
  2. package/dist/parade/web/menu.html +71 -23
  3. package/dist/rcs-web/assets/{AdminPanel-Xlza8Stt.js → AdminPanel-CqP_94xa.js} +1 -1
  4. package/{packages/remote-control-server/web/dist/assets/Claim-BMWwu213.js → dist/rcs-web/assets/Claim-BvfARQ6Q.js} +1 -1
  5. package/{packages/remote-control-server/web/dist/assets/Dashboard-D5awDzM3.js → dist/rcs-web/assets/Dashboard-BDGi4XpN.js} +1 -1
  6. package/{packages/remote-control-server/web/dist/assets/Join-ok37ggfZ.js → dist/rcs-web/assets/Join-PPDYBhsJ.js} +1 -1
  7. package/dist/rcs-web/assets/{Login-5qo97rq-.js → Login-JprQIEpr.js} +1 -1
  8. package/dist/rcs-web/assets/{Register-D_UOG8ar.js → Register-cuGuAE83.js} +1 -1
  9. package/dist/rcs-web/assets/{SessionDetail-BbHrR4Qu.js → SessionDetail-D-xhkyLo.js} +5 -5
  10. package/dist/rcs-web/assets/{SessionVisibilityBadge-Dy4FwTzo.js → SessionVisibilityBadge-91WyR9K6.js} +1 -1
  11. package/dist/rcs-web/assets/{Setup-GnPeNyH9.js → Setup-Buwa9Y3M.js} +1 -1
  12. package/dist/rcs-web/assets/{ShareLanding-CUjQydLL.js → ShareLanding-DhwgJb6V.js} +1 -1
  13. package/dist/rcs-web/assets/{TeamCreate-Ck2fEoUW.js → TeamCreate-CaoinTSG.js} +1 -1
  14. package/dist/rcs-web/assets/{TeamDetail-De6EPND0.js → TeamDetail-D5ahen24.js} +1 -1
  15. package/dist/rcs-web/assets/{TeamList-C-0LJRxd.js → TeamList-qCuKKSH3.js} +1 -1
  16. package/dist/rcs-web/assets/{TeamSettings-BszOrXVW.js → TeamSettings-BaIwImrp.js} +1 -1
  17. package/dist/rcs-web/assets/{UserSearchInput-CyQWtLL-.js → UserSearchInput-BxcYR_HU.js} +1 -1
  18. package/dist/rcs-web/assets/{UserSettings-DgyYp-1y.js → UserSettings-zfGfcuWs.js} +1 -1
  19. package/dist/rcs-web/assets/{arc-BaOPt7k-.js → arc-DwAbF6eM.js} +1 -1
  20. package/dist/rcs-web/assets/{architectureDiagram-3BPJPVTR-SvIakXbT.js → architectureDiagram-3BPJPVTR-uMOwOwiN.js} +1 -1
  21. package/{packages/remote-control-server/web/dist/assets/blockDiagram-GPEHLZMM-CiDp9J7i.js → dist/rcs-web/assets/blockDiagram-GPEHLZMM-B5BqFTkP.js} +1 -1
  22. package/dist/rcs-web/assets/{c4Diagram-AAUBKEIU-D9wzA9ur.js → c4Diagram-AAUBKEIU-D6eienz2.js} +1 -1
  23. package/dist/rcs-web/assets/channel-CCfqpGSl.js +1 -0
  24. package/dist/rcs-web/assets/{chunk-2J33WTMH-qfYueRAP.js → chunk-2J33WTMH-DqVxv8yW.js} +1 -1
  25. package/dist/rcs-web/assets/{chunk-4BX2VUAB-D1V_UCiK.js → chunk-4BX2VUAB-X5o4x8om.js} +1 -1
  26. package/dist/rcs-web/assets/{chunk-55IACEB6-C67QiGmo.js → chunk-55IACEB6-D7G25_Y5.js} +1 -1
  27. package/{packages/remote-control-server/web/dist/assets/chunk-727SXJPM-D2Wln4TT.js → dist/rcs-web/assets/chunk-727SXJPM-CoXI1FIy.js} +1 -1
  28. package/dist/rcs-web/assets/{chunk-AQP2D5EJ-03h8hZhw.js → chunk-AQP2D5EJ-C73Crhqe.js} +1 -1
  29. package/dist/rcs-web/assets/{chunk-FMBD7UC4-7zas8pDp.js → chunk-FMBD7UC4-DVzxIsSE.js} +1 -1
  30. package/dist/rcs-web/assets/{chunk-ND2GUHAM-PUXucyY6.js → chunk-ND2GUHAM-C6_oEhLf.js} +1 -1
  31. package/dist/rcs-web/assets/{chunk-QZHKN3VN-M3U5l4yW.js → chunk-QZHKN3VN-COvH7k5r.js} +1 -1
  32. package/dist/rcs-web/assets/classDiagram-4FO5ZUOK-DzNdVs3v.js +1 -0
  33. package/dist/rcs-web/assets/classDiagram-v2-Q7XG4LA2-DzNdVs3v.js +1 -0
  34. package/dist/rcs-web/assets/{code-block-IT6T5CEO-BgUazuuS.js → code-block-IT6T5CEO-CE-2f_-K.js} +1 -1
  35. package/dist/rcs-web/assets/{copy-DjaSB1Rw.js → copy-9pzb1Po6.js} +1 -1
  36. package/dist/rcs-web/assets/{cose-bilkent-S5V4N54A-zPupX74N.js → cose-bilkent-S5V4N54A-B9sMDFRe.js} +1 -1
  37. package/dist/rcs-web/assets/{dagre-BM42HDAG-B_EJ050J.js → dagre-BM42HDAG-DB1jXylM.js} +1 -1
  38. package/dist/rcs-web/assets/{diagram-2AECGRRQ-dnnxPH7w.js → diagram-2AECGRRQ-MNuqSRmg.js} +1 -1
  39. package/dist/rcs-web/assets/{diagram-5GNKFQAL-CLEOqCLZ.js → diagram-5GNKFQAL-BZwhvaEY.js} +1 -1
  40. package/dist/rcs-web/assets/{diagram-KO2AKTUF-DKBGpiRW.js → diagram-KO2AKTUF-3Wp2PnI2.js} +1 -1
  41. package/dist/rcs-web/assets/{diagram-LMA3HP47-BAilhXiA.js → diagram-LMA3HP47-CTcV1SBj.js} +1 -1
  42. package/dist/rcs-web/assets/{diagram-OG6HWLK6-C3CdmOxC.js → diagram-OG6HWLK6-DzXhSQDC.js} +1 -1
  43. package/dist/rcs-web/assets/{erDiagram-TEJ5UH35-D1yv-3Jv.js → erDiagram-TEJ5UH35-CwSihkB8.js} +1 -1
  44. package/dist/rcs-web/assets/{flowDiagram-I6XJVG4X-DpW11XWj.js → flowDiagram-I6XJVG4X-BSuXctT4.js} +1 -1
  45. package/{packages/remote-control-server/web/dist/assets/ganttDiagram-6RSMTGT7-CWr8suZm.js → dist/rcs-web/assets/ganttDiagram-6RSMTGT7-B87oxjmY.js} +1 -1
  46. package/dist/rcs-web/assets/{gitGraphDiagram-PVQCEYII-BspxLSNV.js → gitGraphDiagram-PVQCEYII-BRrwOi3C.js} +1 -1
  47. package/dist/rcs-web/assets/{infoDiagram-5YYISTIA-Bow20s-Q.js → infoDiagram-5YYISTIA-B-8QXS0n.js} +1 -1
  48. package/dist/rcs-web/assets/{ishikawaDiagram-YF4QCWOH-BESvGYGI.js → ishikawaDiagram-YF4QCWOH-Bau9MU6C.js} +1 -1
  49. package/dist/rcs-web/assets/{journeyDiagram-JHISSGLW-DZ6gzC7H.js → journeyDiagram-JHISSGLW-D_tAp--R.js} +1 -1
  50. package/dist/rcs-web/assets/{kanban-definition-UN3LZRKU-DIQo2GiM.js → kanban-definition-UN3LZRKU---UIvjMZ.js} +1 -1
  51. package/dist/rcs-web/assets/{linear-CdXALiZ8.js → linear-CIDLjd5h.js} +1 -1
  52. package/dist/rcs-web/assets/{main-CwLwGVDc.js → main-N3GYCdLF.js} +3 -3
  53. package/dist/rcs-web/assets/{mermaid-VLURNSYL-C0ZKM74W.js → mermaid-VLURNSYL-Cu5A5sMk.js} +4 -4
  54. package/dist/rcs-web/assets/{mermaid.core-eEtoQhrQ.js → mermaid.core-CEJOtCGw.js} +5 -5
  55. package/dist/rcs-web/assets/{mindmap-definition-RKZ34NQL-CcW3H_cH.js → mindmap-definition-RKZ34NQL-ldyccyCP.js} +1 -1
  56. package/dist/rcs-web/assets/{pieDiagram-4H26LBE5-DpXUpJMl.js → pieDiagram-4H26LBE5-CmghofeF.js} +1 -1
  57. package/{packages/remote-control-server/web/dist/assets/quadrantDiagram-W4KKPZXB-DOwMRzzP.js → dist/rcs-web/assets/quadrantDiagram-W4KKPZXB-B-2N2UHr.js} +1 -1
  58. package/dist/rcs-web/assets/{requirementDiagram-4Y6WPE33-CBi_6NcW.js → requirementDiagram-4Y6WPE33-39jlO9Y8.js} +1 -1
  59. package/{packages/remote-control-server/web/dist/assets/sankeyDiagram-5OEKKPKP-CKbAoTHm.js → dist/rcs-web/assets/sankeyDiagram-5OEKKPKP-DdY7KNFB.js} +1 -1
  60. package/dist/rcs-web/assets/{sequenceDiagram-3UESZ5HK-a3rYCe-w.js → sequenceDiagram-3UESZ5HK-D2k5rX6x.js} +1 -1
  61. package/dist/rcs-web/assets/{stateDiagram-AJRCARHV-B6R_Dt84.js → stateDiagram-AJRCARHV-CP9N457o.js} +1 -1
  62. package/dist/rcs-web/assets/{stateDiagram-v2-BHNVJYJU-Cq935fvz.js → stateDiagram-v2-BHNVJYJU-CPhZYlL0.js} +1 -1
  63. package/{packages/remote-control-server/web/dist/assets/timeline-definition-PNZ67QCA-8DXPKq1k.js → dist/rcs-web/assets/timeline-definition-PNZ67QCA-DSEPBO8O.js} +1 -1
  64. package/dist/rcs-web/assets/{vennDiagram-CIIHVFJN-BfDEkku5.js → vennDiagram-CIIHVFJN-CkNMwCJ3.js} +1 -1
  65. package/dist/rcs-web/assets/{wardleyDiagram-YWT4CUSO-Dvp2XZVf.js → wardleyDiagram-YWT4CUSO-Cxd-F60s.js} +1 -1
  66. package/{packages/remote-control-server/web/dist/assets/xychartDiagram-2RQKCTM6-DiPjQLUx.js → dist/rcs-web/assets/xychartDiagram-2RQKCTM6-BLL105NN.js} +1 -1
  67. package/dist/rcs-web/index.html +1 -1
  68. package/package.json +1 -1
  69. package/packages/remote-control-server/src/__tests__/models-state-snapshot.test.ts +216 -0
  70. package/packages/remote-control-server/src/__tests__/turn-end-status.test.ts +217 -1
  71. package/packages/remote-control-server/src/routes/v2/worker-events.ts +12 -1
  72. package/packages/remote-control-server/src/routes/web/control.ts +11 -2
  73. package/packages/remote-control-server/src/routes/web/sessions.ts +33 -0
  74. package/packages/remote-control-server/src/services/transport.ts +12 -0
  75. package/packages/remote-control-server/src/transport/event-bus.ts +25 -0
  76. package/packages/remote-control-server/src/transport/ws-handler.ts +14 -1
  77. package/packages/remote-control-server/web/dist/assets/{AdminPanel-Xlza8Stt.js → AdminPanel-CqP_94xa.js} +1 -1
  78. package/{dist/rcs-web/assets/Claim-BMWwu213.js → packages/remote-control-server/web/dist/assets/Claim-BvfARQ6Q.js} +1 -1
  79. package/{dist/rcs-web/assets/Dashboard-D5awDzM3.js → packages/remote-control-server/web/dist/assets/Dashboard-BDGi4XpN.js} +1 -1
  80. package/{dist/rcs-web/assets/Join-ok37ggfZ.js → packages/remote-control-server/web/dist/assets/Join-PPDYBhsJ.js} +1 -1
  81. package/packages/remote-control-server/web/dist/assets/{Login-5qo97rq-.js → Login-JprQIEpr.js} +1 -1
  82. package/packages/remote-control-server/web/dist/assets/{Register-D_UOG8ar.js → Register-cuGuAE83.js} +1 -1
  83. package/packages/remote-control-server/web/dist/assets/{SessionDetail-BbHrR4Qu.js → SessionDetail-D-xhkyLo.js} +5 -5
  84. package/packages/remote-control-server/web/dist/assets/{SessionVisibilityBadge-Dy4FwTzo.js → SessionVisibilityBadge-91WyR9K6.js} +1 -1
  85. package/packages/remote-control-server/web/dist/assets/{Setup-GnPeNyH9.js → Setup-Buwa9Y3M.js} +1 -1
  86. package/packages/remote-control-server/web/dist/assets/{ShareLanding-CUjQydLL.js → ShareLanding-DhwgJb6V.js} +1 -1
  87. package/packages/remote-control-server/web/dist/assets/{TeamCreate-Ck2fEoUW.js → TeamCreate-CaoinTSG.js} +1 -1
  88. package/packages/remote-control-server/web/dist/assets/{TeamDetail-De6EPND0.js → TeamDetail-D5ahen24.js} +1 -1
  89. package/packages/remote-control-server/web/dist/assets/{TeamList-C-0LJRxd.js → TeamList-qCuKKSH3.js} +1 -1
  90. package/packages/remote-control-server/web/dist/assets/{TeamSettings-BszOrXVW.js → TeamSettings-BaIwImrp.js} +1 -1
  91. package/packages/remote-control-server/web/dist/assets/{UserSearchInput-CyQWtLL-.js → UserSearchInput-BxcYR_HU.js} +1 -1
  92. package/packages/remote-control-server/web/dist/assets/{UserSettings-DgyYp-1y.js → UserSettings-zfGfcuWs.js} +1 -1
  93. package/packages/remote-control-server/web/dist/assets/{arc-BaOPt7k-.js → arc-DwAbF6eM.js} +1 -1
  94. package/packages/remote-control-server/web/dist/assets/{architectureDiagram-3BPJPVTR-SvIakXbT.js → architectureDiagram-3BPJPVTR-uMOwOwiN.js} +1 -1
  95. package/{dist/rcs-web/assets/blockDiagram-GPEHLZMM-CiDp9J7i.js → packages/remote-control-server/web/dist/assets/blockDiagram-GPEHLZMM-B5BqFTkP.js} +1 -1
  96. package/packages/remote-control-server/web/dist/assets/{c4Diagram-AAUBKEIU-D9wzA9ur.js → c4Diagram-AAUBKEIU-D6eienz2.js} +1 -1
  97. package/packages/remote-control-server/web/dist/assets/channel-CCfqpGSl.js +1 -0
  98. package/packages/remote-control-server/web/dist/assets/{chunk-2J33WTMH-qfYueRAP.js → chunk-2J33WTMH-DqVxv8yW.js} +1 -1
  99. package/packages/remote-control-server/web/dist/assets/{chunk-4BX2VUAB-D1V_UCiK.js → chunk-4BX2VUAB-X5o4x8om.js} +1 -1
  100. package/packages/remote-control-server/web/dist/assets/{chunk-55IACEB6-C67QiGmo.js → chunk-55IACEB6-D7G25_Y5.js} +1 -1
  101. package/{dist/rcs-web/assets/chunk-727SXJPM-D2Wln4TT.js → packages/remote-control-server/web/dist/assets/chunk-727SXJPM-CoXI1FIy.js} +1 -1
  102. package/packages/remote-control-server/web/dist/assets/{chunk-AQP2D5EJ-03h8hZhw.js → chunk-AQP2D5EJ-C73Crhqe.js} +1 -1
  103. package/packages/remote-control-server/web/dist/assets/{chunk-FMBD7UC4-7zas8pDp.js → chunk-FMBD7UC4-DVzxIsSE.js} +1 -1
  104. package/packages/remote-control-server/web/dist/assets/{chunk-ND2GUHAM-PUXucyY6.js → chunk-ND2GUHAM-C6_oEhLf.js} +1 -1
  105. package/packages/remote-control-server/web/dist/assets/{chunk-QZHKN3VN-M3U5l4yW.js → chunk-QZHKN3VN-COvH7k5r.js} +1 -1
  106. package/packages/remote-control-server/web/dist/assets/classDiagram-4FO5ZUOK-DzNdVs3v.js +1 -0
  107. package/packages/remote-control-server/web/dist/assets/classDiagram-v2-Q7XG4LA2-DzNdVs3v.js +1 -0
  108. package/packages/remote-control-server/web/dist/assets/{code-block-IT6T5CEO-BgUazuuS.js → code-block-IT6T5CEO-CE-2f_-K.js} +1 -1
  109. package/packages/remote-control-server/web/dist/assets/{copy-DjaSB1Rw.js → copy-9pzb1Po6.js} +1 -1
  110. package/packages/remote-control-server/web/dist/assets/{cose-bilkent-S5V4N54A-zPupX74N.js → cose-bilkent-S5V4N54A-B9sMDFRe.js} +1 -1
  111. package/packages/remote-control-server/web/dist/assets/{dagre-BM42HDAG-B_EJ050J.js → dagre-BM42HDAG-DB1jXylM.js} +1 -1
  112. package/packages/remote-control-server/web/dist/assets/{diagram-2AECGRRQ-dnnxPH7w.js → diagram-2AECGRRQ-MNuqSRmg.js} +1 -1
  113. package/packages/remote-control-server/web/dist/assets/{diagram-5GNKFQAL-CLEOqCLZ.js → diagram-5GNKFQAL-BZwhvaEY.js} +1 -1
  114. package/packages/remote-control-server/web/dist/assets/{diagram-KO2AKTUF-DKBGpiRW.js → diagram-KO2AKTUF-3Wp2PnI2.js} +1 -1
  115. package/packages/remote-control-server/web/dist/assets/{diagram-LMA3HP47-BAilhXiA.js → diagram-LMA3HP47-CTcV1SBj.js} +1 -1
  116. package/packages/remote-control-server/web/dist/assets/{diagram-OG6HWLK6-C3CdmOxC.js → diagram-OG6HWLK6-DzXhSQDC.js} +1 -1
  117. package/packages/remote-control-server/web/dist/assets/{erDiagram-TEJ5UH35-D1yv-3Jv.js → erDiagram-TEJ5UH35-CwSihkB8.js} +1 -1
  118. package/packages/remote-control-server/web/dist/assets/{flowDiagram-I6XJVG4X-DpW11XWj.js → flowDiagram-I6XJVG4X-BSuXctT4.js} +1 -1
  119. package/{dist/rcs-web/assets/ganttDiagram-6RSMTGT7-CWr8suZm.js → packages/remote-control-server/web/dist/assets/ganttDiagram-6RSMTGT7-B87oxjmY.js} +1 -1
  120. package/packages/remote-control-server/web/dist/assets/{gitGraphDiagram-PVQCEYII-BspxLSNV.js → gitGraphDiagram-PVQCEYII-BRrwOi3C.js} +1 -1
  121. package/packages/remote-control-server/web/dist/assets/{infoDiagram-5YYISTIA-Bow20s-Q.js → infoDiagram-5YYISTIA-B-8QXS0n.js} +1 -1
  122. package/packages/remote-control-server/web/dist/assets/{ishikawaDiagram-YF4QCWOH-BESvGYGI.js → ishikawaDiagram-YF4QCWOH-Bau9MU6C.js} +1 -1
  123. package/packages/remote-control-server/web/dist/assets/{journeyDiagram-JHISSGLW-DZ6gzC7H.js → journeyDiagram-JHISSGLW-D_tAp--R.js} +1 -1
  124. package/packages/remote-control-server/web/dist/assets/{kanban-definition-UN3LZRKU-DIQo2GiM.js → kanban-definition-UN3LZRKU---UIvjMZ.js} +1 -1
  125. package/packages/remote-control-server/web/dist/assets/{linear-CdXALiZ8.js → linear-CIDLjd5h.js} +1 -1
  126. package/packages/remote-control-server/web/dist/assets/{main-CwLwGVDc.js → main-N3GYCdLF.js} +3 -3
  127. package/packages/remote-control-server/web/dist/assets/{mermaid-VLURNSYL-C0ZKM74W.js → mermaid-VLURNSYL-Cu5A5sMk.js} +4 -4
  128. package/packages/remote-control-server/web/dist/assets/{mermaid.core-eEtoQhrQ.js → mermaid.core-CEJOtCGw.js} +5 -5
  129. package/packages/remote-control-server/web/dist/assets/{mindmap-definition-RKZ34NQL-CcW3H_cH.js → mindmap-definition-RKZ34NQL-ldyccyCP.js} +1 -1
  130. package/packages/remote-control-server/web/dist/assets/{pieDiagram-4H26LBE5-DpXUpJMl.js → pieDiagram-4H26LBE5-CmghofeF.js} +1 -1
  131. package/{dist/rcs-web/assets/quadrantDiagram-W4KKPZXB-DOwMRzzP.js → packages/remote-control-server/web/dist/assets/quadrantDiagram-W4KKPZXB-B-2N2UHr.js} +1 -1
  132. package/packages/remote-control-server/web/dist/assets/{requirementDiagram-4Y6WPE33-CBi_6NcW.js → requirementDiagram-4Y6WPE33-39jlO9Y8.js} +1 -1
  133. package/{dist/rcs-web/assets/sankeyDiagram-5OEKKPKP-CKbAoTHm.js → packages/remote-control-server/web/dist/assets/sankeyDiagram-5OEKKPKP-DdY7KNFB.js} +1 -1
  134. package/packages/remote-control-server/web/dist/assets/{sequenceDiagram-3UESZ5HK-a3rYCe-w.js → sequenceDiagram-3UESZ5HK-D2k5rX6x.js} +1 -1
  135. package/packages/remote-control-server/web/dist/assets/{stateDiagram-AJRCARHV-B6R_Dt84.js → stateDiagram-AJRCARHV-CP9N457o.js} +1 -1
  136. package/packages/remote-control-server/web/dist/assets/{stateDiagram-v2-BHNVJYJU-Cq935fvz.js → stateDiagram-v2-BHNVJYJU-CPhZYlL0.js} +1 -1
  137. package/{dist/rcs-web/assets/timeline-definition-PNZ67QCA-8DXPKq1k.js → packages/remote-control-server/web/dist/assets/timeline-definition-PNZ67QCA-DSEPBO8O.js} +1 -1
  138. package/packages/remote-control-server/web/dist/assets/{vennDiagram-CIIHVFJN-BfDEkku5.js → vennDiagram-CIIHVFJN-CkNMwCJ3.js} +1 -1
  139. package/packages/remote-control-server/web/dist/assets/{wardleyDiagram-YWT4CUSO-Dvp2XZVf.js → wardleyDiagram-YWT4CUSO-Cxd-F60s.js} +1 -1
  140. package/{dist/rcs-web/assets/xychartDiagram-2RQKCTM6-DiPjQLUx.js → packages/remote-control-server/web/dist/assets/xychartDiagram-2RQKCTM6-BLL105NN.js} +1 -1
  141. package/packages/remote-control-server/web/dist/index.html +1 -1
  142. package/dist/rcs-web/assets/channel-CirgRB_G.js +0 -1
  143. package/dist/rcs-web/assets/classDiagram-4FO5ZUOK-Cq12UEz9.js +0 -1
  144. package/dist/rcs-web/assets/classDiagram-v2-Q7XG4LA2-Cq12UEz9.js +0 -1
  145. package/packages/remote-control-server/web/dist/assets/channel-CirgRB_G.js +0 -1
  146. package/packages/remote-control-server/web/dist/assets/classDiagram-4FO5ZUOK-Cq12UEz9.js +0 -1
  147. package/packages/remote-control-server/web/dist/assets/classDiagram-v2-Q7XG4LA2-Cq12UEz9.js +0 -1
@@ -14,14 +14,23 @@
14
14
  cursor, so the menu can extend beyond the parade window.
15
15
 
16
16
  Contract with the electron main script:
17
- - Window size: MENU_W x MENU_H design px (158x147) — the constants in
18
- paradeWindow.ts MUST match the locked layout below.
19
- - Query params: ?mode=<displayMode>&rot=<dynamic|static>&zoom=<dpiScale>
20
- zoom is applied identically to index.html (physical px compensation on
17
+ - Window: one PRE-WARMED frameless transparent popup, created hidden at
18
+ startup and REUSED for every right-click (hide/show, never recreated —
19
+ recreating a renderer process per open read as a laggy menu). Main
20
+ re-anchors it via setBounds at the OS cursor and sizes it
21
+ MENU_W x MENU_H design px x unitScale — the constants in paradeWindow.ts
22
+ MUST match the locked layout below.
23
+ - State: pushed per open over IPC parade-menu-state {mode, rot}; the page
24
+ applies it and acks via paradeMenu.ready(), then main shows the window
25
+ (no stale highlight). The ?mode/&rot/&zoom=<dpiScale> query params are
26
+ only the initial-load fallback / browser-debugging path. zoom is applied
27
+ identically to index.html (physical px compensation on
21
28
  --force-device-scale-factor=1 Win11; multiply window size by unitScale).
22
29
  - Selections: window.paradeMenu.action({type:'view', value}) or
23
30
  ({type:'rotation'}) → IPC parade-menu-action → relayed to the parade
24
31
  window renderer, which stays the single source of truth for mode state.
32
+ Escape dismisses via window.paradeMenu.dismiss() (hide, not close —
33
+ the window is reused).
25
34
  -->
26
35
  <style>
27
36
  :root {
@@ -124,35 +133,67 @@
124
133
  <div class="ctx-item" id="ctx-mode">Rotation: Dynamic</div>
125
134
  </div>
126
135
  <script>
127
- // Reflect the parade window's current state passed via query string.
128
- ;(function () {
129
- var q = new URLSearchParams(window.location.search)
130
-
131
- // DPI compensation — identical mechanism to index.html/cube.js: the main
132
- // process forces 1 CSS px = 1 physical px on Win11, then we CSS-zoom the
133
- // content by the OS DPI factor so physical size matches intent. Applied at
134
- // parse time; the window was sized as design px x unitScale by main.
135
- var zoom = parseFloat(q.get('zoom')) || 0
136
- if (zoom > 1) document.documentElement.style.zoom = String(zoom)
137
-
138
- // Mark the active display mode radio item.
139
- var mode = q.get('mode') || ''
136
+ // ---- State application ----
137
+ // The electron main process pre-warms this page and reuses its window for
138
+ // every right-click: each open pushes the parade window's current state via
139
+ // the parade-menu-state IPC; the query params below are only the initial
140
+ // fallback / browser-debugging path. applyState() must therefore REMOVE the
141
+ // previous open's active marks, not just add new ones.
142
+ function applyState(state) {
143
+ state = (state && typeof state === 'object') ? state : {}
144
+ var mode = String(state.mode || '')
140
145
  var views = document.querySelectorAll('.ctx-view')
141
146
  for (let i = 0; i < views.length; i++) {
142
147
  if (views[i].getAttribute('data-view') === mode) {
143
148
  views[i].classList.add('active')
149
+ } else {
150
+ views[i].classList.remove('active')
144
151
  }
145
152
  }
146
-
147
- // Rotation label.
148
- var rot = q.get('rot') === 'static' ? 'static' : 'dynamic'
153
+ var rot = state.rot === 'static' ? 'static' : 'dynamic'
149
154
  var modeEl = document.getElementById('ctx-mode')
150
155
  if (modeEl) {
151
156
  modeEl.textContent = 'Rotation: ' + (rot === 'dynamic' ? 'Dynamic' : 'Static')
152
157
  }
158
+ }
159
+
160
+ // The page itself is reused across opens, so the load-time #menu animation
161
+ // would only ever play once — replay it on every state push (i.e. every open).
162
+ function replayOpenAnimation() {
163
+ var menuEl = document.getElementById('menu')
164
+ if (!menuEl) return
165
+ menuEl.style.animation = 'none'
166
+ void menuEl.offsetWidth // force reflow so the animation restarts
167
+ menuEl.style.animation = ''
168
+ }
169
+
170
+ // Initial state via query string (fallback / browser debugging).
171
+ ;(function () {
172
+ var q = new URLSearchParams(window.location.search)
173
+
174
+ // DPI compensation — identical mechanism to index.html/cube.js: the main
175
+ // process forces 1 CSS px = 1 physical px on Win11, then we CSS-zoom the
176
+ // content by the OS DPI factor so physical size matches intent. Applied at
177
+ // parse time; the window was sized as design px x unitScale by main.
178
+ var zoom = parseFloat(q.get('zoom')) || 0
179
+ if (zoom > 1) document.documentElement.style.zoom = String(zoom)
180
+
181
+ applyState({ mode: q.get('mode') || '', rot: q.get('rot') || '' })
153
182
  })()
154
183
 
155
- // Report a selection to the electron main process, which closes the popup and
184
+ // Per-open state push: apply, replay the open animation, then ack so main
185
+ // shows the window with the highlight already up to date.
186
+ if (window.paradeMenu && typeof window.paradeMenu.onState === 'function') {
187
+ window.paradeMenu.onState(function (state) {
188
+ applyState(state)
189
+ replayOpenAnimation()
190
+ if (typeof window.paradeMenu.ready === 'function') {
191
+ window.paradeMenu.ready()
192
+ }
193
+ })
194
+ }
195
+
196
+ // Report a selection to the electron main process, which hides the popup and
156
197
  // relays the action to the parade window renderer.
157
198
  function reportAction(action) {
158
199
  if (window.paradeMenu && typeof window.paradeMenu.action === 'function') {
@@ -178,10 +219,17 @@ if (modeEl) {
178
219
  })
179
220
  }
180
221
 
181
- // Escape dismisses (native-menu parity).
222
+ // Escape dismisses (native-menu parity). The popup window is reused, so the
223
+ // page must NOT window.close() itself (that would destroy the prewarmed
224
+ // renderer) — it asks main to hide it instead. window.close() stays as the
225
+ // browser-debugging fallback where the bridge is missing.
182
226
  document.addEventListener('keydown', function (e) {
183
227
  if (e.key === 'Escape') {
184
- try { window.close() } catch (_) { /* ignore */ }
228
+ if (window.paradeMenu && typeof window.paradeMenu.dismiss === 'function') {
229
+ window.paradeMenu.dismiss()
230
+ } else {
231
+ try { window.close() } catch (_) { /* ignore */ }
232
+ }
185
233
  }
186
234
  })
187
235
 
@@ -1 +1 @@
1
- import{e as d,j as e}from"./vendor-DE_-CLIE.js";import{ak as c,al as o,J as m,af as s,a8 as l,x as u}from"./main-CwLwGVDc.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";function j(){c();const[a,i]=d.useState([]),{myTeams:r,isLoading:x}=o(),n=d.useCallback(async()=>{try{const t=await m();i(t||[])}catch(t){console.error("Admin: failed to load sessions",t)}},[]);return d.useEffect(()=>{n()},[n]),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs("div",{className:"mx-auto max-w-5xl px-4 py-8",children:[e.jsx("h1",{className:"mb-6 font-display text-2xl font-semibold text-text-primary",children:s("admin.title")}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"mb-4 font-display text-lg font-semibold text-text-primary",children:[s("admin.teams")," (",r.length,")"]}),x?e.jsx("div",{className:"rounded-xl border border-border bg-surface-1 p-4 text-center text-text-muted",children:s("common.loading")}):r.length===0?e.jsx("div",{className:"rounded-xl border border-border bg-surface-1 p-4 text-center text-text-muted",children:s("admin.noTeams")}):e.jsx("div",{className:"space-y-2",children:r.map(t=>e.jsxs("a",{href:`/teams/${t.slug}`,className:"flex items-center justify-between rounded-xl border border-border bg-surface-1 px-4 py-3 no-underline transition-colors hover:border-border-light hover:bg-surface-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"font-medium text-text-primary",children:t.name}),e.jsx("span",{className:"ml-2 text-xs text-text-muted",children:t.slug})]}),e.jsx("span",{className:"text-xs text-text-muted",children:l(new Date(t.created_at).getTime()/1e3)})]},t.id))})]}),e.jsxs("section",{children:[e.jsxs("h2",{className:"mb-4 font-display text-lg font-semibold text-text-primary",children:[s("admin.sessions")," (",a.length,")"]}),a.length===0?e.jsx("div",{className:"rounded-xl border border-border bg-surface-1 p-4 text-center text-text-muted",children:s("admin.noSessions")}):e.jsx("div",{className:"space-y-2",children:a.map(t=>e.jsxs("a",{href:`/code/${t.id}`,className:"flex items-center justify-between rounded-xl border border-border bg-surface-1 px-4 py-3 no-underline transition-colors hover:border-border-light hover:bg-surface-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-medium text-text-primary",children:t.title||t.id}),e.jsx("span",{className:"rounded-full bg-surface-2 px-2 py-0.5 text-xs text-text-muted",children:t.source||"unknown"})]}),e.jsx("div",{className:"truncate text-xs text-text-muted",children:t.id})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-3",children:[e.jsx(u,{status:t.status}),e.jsx("span",{className:"text-xs text-text-muted",children:l(t.updated_at||t.created_at)})]})]},t.id))})]})]})})}export{j as AdminPanel};
1
+ import{e as d,j as e}from"./vendor-DE_-CLIE.js";import{ak as c,al as o,J as m,af as s,a8 as l,x as u}from"./main-N3GYCdLF.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";function j(){c();const[a,i]=d.useState([]),{myTeams:r,isLoading:x}=o(),n=d.useCallback(async()=>{try{const t=await m();i(t||[])}catch(t){console.error("Admin: failed to load sessions",t)}},[]);return d.useEffect(()=>{n()},[n]),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs("div",{className:"mx-auto max-w-5xl px-4 py-8",children:[e.jsx("h1",{className:"mb-6 font-display text-2xl font-semibold text-text-primary",children:s("admin.title")}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"mb-4 font-display text-lg font-semibold text-text-primary",children:[s("admin.teams")," (",r.length,")"]}),x?e.jsx("div",{className:"rounded-xl border border-border bg-surface-1 p-4 text-center text-text-muted",children:s("common.loading")}):r.length===0?e.jsx("div",{className:"rounded-xl border border-border bg-surface-1 p-4 text-center text-text-muted",children:s("admin.noTeams")}):e.jsx("div",{className:"space-y-2",children:r.map(t=>e.jsxs("a",{href:`/teams/${t.slug}`,className:"flex items-center justify-between rounded-xl border border-border bg-surface-1 px-4 py-3 no-underline transition-colors hover:border-border-light hover:bg-surface-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"font-medium text-text-primary",children:t.name}),e.jsx("span",{className:"ml-2 text-xs text-text-muted",children:t.slug})]}),e.jsx("span",{className:"text-xs text-text-muted",children:l(new Date(t.created_at).getTime()/1e3)})]},t.id))})]}),e.jsxs("section",{children:[e.jsxs("h2",{className:"mb-4 font-display text-lg font-semibold text-text-primary",children:[s("admin.sessions")," (",a.length,")"]}),a.length===0?e.jsx("div",{className:"rounded-xl border border-border bg-surface-1 p-4 text-center text-text-muted",children:s("admin.noSessions")}):e.jsx("div",{className:"space-y-2",children:a.map(t=>e.jsxs("a",{href:`/code/${t.id}`,className:"flex items-center justify-between rounded-xl border border-border bg-surface-1 px-4 py-3 no-underline transition-colors hover:border-border-light hover:bg-surface-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-medium text-text-primary",children:t.title||t.id}),e.jsx("span",{className:"rounded-full bg-surface-2 px-2 py-0.5 text-xs text-text-muted",children:t.source||"unknown"})]}),e.jsx("div",{className:"truncate text-xs text-text-muted",children:t.id})]}),e.jsxs("div",{className:"ml-4 flex items-center gap-3",children:[e.jsx(u,{status:t.status}),e.jsx("span",{className:"text-xs text-text-muted",children:l(t.updated_at||t.created_at)})]})]},t.id))})]})]})})}export{j as AdminPanel};
@@ -1 +1 @@
1
- import{e as r,j as e}from"./vendor-DE_-CLIE.js";import{E as u,J as f}from"./main-CwLwGVDc.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";const v=2e3,N=3e4;function E(){const c=window.location.pathname.split("/"),i=c[c.length-1]||"",[s,n]=r.useState("idle"),[m,l]=r.useState(null),[a,d]=r.useState(null);return r.useEffect(()=>{if(!i||!i.startsWith("clm_")){l("Invalid claim token"),n("error");return}n("claiming"),u(i).then(t=>{d(t.environment_id),n("waiting")}).catch(t=>{l(t instanceof Error?t.message:"Claim failed"),n("error")})},[i]),r.useEffect(()=>{if(s!=="waiting"||!a)return;let t=!1;const x=Date.now(),o=setInterval(()=>{if(Date.now()-x>N){clearInterval(o),t||n("timeout");return}f().then(h=>{t||(h||[]).some(p=>p.environment_id===a)&&(clearInterval(o),window.location.href="/code/")}).catch(()=>{})},v);return()=>{t=!0,clearInterval(o)}},[s,a]),s==="claiming"?e.jsx("div",{className:"px-6 py-16 sm:px-10 sm:py-20",children:e.jsx("p",{className:"text-sm text-text-muted",children:"Claiming environment..."})}):s==="error"?e.jsxs("div",{className:"px-6 py-16 sm:px-10 sm:py-20",children:[e.jsx("p",{className:"text-sm text-destructive",children:m}),e.jsx("a",{href:"/code",className:"mt-4 inline-block text-accent hover:underline",children:"Back to dashboard"})]}):s==="waiting"||s==="timeout"?e.jsxs("div",{className:"px-6 py-16 sm:px-10 sm:py-20",children:[e.jsxs("header",{className:"mb-10",children:[e.jsx("h1",{className:"font-display text-2xl font-semibold tracking-tight text-text-primary",children:"Environment claimed"}),e.jsx("p",{className:"mt-2 text-sm text-text-muted",children:"You are now the owner of this environment."})]}),e.jsxs("div",{className:"space-y-4",children:[a&&e.jsx("p",{className:"font-mono text-xs text-text-muted",children:a}),s==="waiting"?e.jsxs("p",{className:"text-sm text-text-muted",children:["Waiting for the worker to create a session",e.jsx("span",{className:"animate-pulse",children:"…"})]}):e.jsx("p",{className:"text-sm text-text-muted",children:"The worker has not created a session yet — it may be offline or stopped. The session will appear on the dashboard once the worker connects."}),e.jsx("a",{href:"/code",className:"inline-block rounded-md bg-accent px-4 py-2 text-sm font-medium text-white hover:bg-accent/90 transition-colors",children:"Go to dashboard"})]})]}):e.jsx("div",{className:"px-6 py-16 sm:px-10 sm:py-20",children:e.jsx("p",{className:"text-sm text-text-muted",children:"Claiming environment..."})})}export{E as Claim};
1
+ import{e as r,j as e}from"./vendor-DE_-CLIE.js";import{E as u,J as f}from"./main-N3GYCdLF.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";const v=2e3,N=3e4;function E(){const c=window.location.pathname.split("/"),i=c[c.length-1]||"",[s,n]=r.useState("idle"),[m,l]=r.useState(null),[a,d]=r.useState(null);return r.useEffect(()=>{if(!i||!i.startsWith("clm_")){l("Invalid claim token"),n("error");return}n("claiming"),u(i).then(t=>{d(t.environment_id),n("waiting")}).catch(t=>{l(t instanceof Error?t.message:"Claim failed"),n("error")})},[i]),r.useEffect(()=>{if(s!=="waiting"||!a)return;let t=!1;const x=Date.now(),o=setInterval(()=>{if(Date.now()-x>N){clearInterval(o),t||n("timeout");return}f().then(h=>{t||(h||[]).some(p=>p.environment_id===a)&&(clearInterval(o),window.location.href="/code/")}).catch(()=>{})},v);return()=>{t=!0,clearInterval(o)}},[s,a]),s==="claiming"?e.jsx("div",{className:"px-6 py-16 sm:px-10 sm:py-20",children:e.jsx("p",{className:"text-sm text-text-muted",children:"Claiming environment..."})}):s==="error"?e.jsxs("div",{className:"px-6 py-16 sm:px-10 sm:py-20",children:[e.jsx("p",{className:"text-sm text-destructive",children:m}),e.jsx("a",{href:"/code",className:"mt-4 inline-block text-accent hover:underline",children:"Back to dashboard"})]}):s==="waiting"||s==="timeout"?e.jsxs("div",{className:"px-6 py-16 sm:px-10 sm:py-20",children:[e.jsxs("header",{className:"mb-10",children:[e.jsx("h1",{className:"font-display text-2xl font-semibold tracking-tight text-text-primary",children:"Environment claimed"}),e.jsx("p",{className:"mt-2 text-sm text-text-muted",children:"You are now the owner of this environment."})]}),e.jsxs("div",{className:"space-y-4",children:[a&&e.jsx("p",{className:"font-mono text-xs text-text-muted",children:a}),s==="waiting"?e.jsxs("p",{className:"text-sm text-text-muted",children:["Waiting for the worker to create a session",e.jsx("span",{className:"animate-pulse",children:"…"})]}):e.jsx("p",{className:"text-sm text-text-muted",children:"The worker has not created a session yet — it may be offline or stopped. The session will appear on the dashboard once the worker connects."}),e.jsx("a",{href:"/code",className:"inline-block rounded-md bg-accent px-4 py-2 text-sm font-medium text-white hover:bg-accent/90 transition-colors",children:"Go to dashboard"})]})]}):e.jsx("div",{className:"px-6 py-16 sm:px-10 sm:py-20",children:e.jsx("p",{className:"text-sm text-text-muted",children:"Claiming environment..."})})}export{E as Claim};
@@ -1,4 +1,4 @@
1
- import{j as e,e as o}from"./vendor-DE_-CLIE.js";import{a5 as O,a4 as _,al as E,aj as T,x as F,ak as L,af as a,a8 as A,q as $,s as W,e as H,r as V,d as P,ab as q,G,J,K,I as R}from"./main-CwLwGVDc.js";import{g as D}from"./workerType-Bd-zteMi.js";import{S as U,D as Z,a as z,c as Q,d as X,b as Y}from"./SessionVisibilityBadge-Dy4FwTzo.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";/**
1
+ import{j as e,e as o}from"./vendor-DE_-CLIE.js";import{a5 as O,a4 as _,al as E,aj as T,x as F,ak as L,af as a,a8 as A,q as $,s as W,e as H,r as V,d as P,ab as q,G,J,K,I as R}from"./main-N3GYCdLF.js";import{g as D}from"./workerType-Bd-zteMi.js";import{S as U,D as Z,a as z,c as Q,d as X,b as Y}from"./SessionVisibilityBadge-91WyR9K6.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.
@@ -1 +1 @@
1
- import{e as r,j as e}from"./vendor-DE_-CLIE.js";import{aj as v,af as t}from"./main-CwLwGVDc.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";function E({onSuccess:b,onInvalidInvite:l}){const{join:f}=v(),[u,h]=r.useState(""),[d,j]=r.useState(""),[o,w]=r.useState(""),[c,g]=r.useState(""),[m,n]=r.useState(""),[x,p]=r.useState(!1);r.useEffect(()=>{const a=new URLSearchParams(window.location.search).get("invite");a?h(a):l()},[l]);const y=async s=>{if(s.preventDefault(),n(""),o.length<8){n(t("auth.setup.passwordTooShort"));return}if(o!==c){n(t("auth.setup.passwordMismatch"));return}p(!0);try{await f(u,d,o),b()}catch(a){const i=a instanceof Error?a.message:"Join failed";if(i.includes("Invalid invitation")||i.includes("expired")||i.includes("already used")){l();return}n(i)}finally{p(!1)}};return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-surface-0 px-4",children:e.jsxs("div",{className:"w-full max-w-sm space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"font-display text-2xl font-semibold text-text-primary",children:t("auth.join.title")}),e.jsx("p",{className:"mt-2 text-sm text-text-muted",children:t("auth.join.welcome")}),e.jsx("p",{className:"mt-1 text-sm text-text-muted",children:t("auth.join.description")})]}),e.jsxs("form",{onSubmit:y,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.join.username")}),e.jsx("input",{type:"text",value:d,onChange:s=>j(s.target.value),required:!0,autoComplete:"username",autoFocus:!0,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"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.join.password")}),e.jsx("input",{type:"password",value:o,onChange:s=>w(s.target.value),required:!0,autoComplete:"new-password",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"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.join.confirmPassword")}),e.jsx("input",{type:"password",value:c,onChange:s=>g(s.target.value),required:!0,autoComplete:"new-password",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.jsx("p",{className:"text-sm text-status-error",children:m}),e.jsx("button",{type:"submit",disabled:x||!u,className:"w-full rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-light disabled:cursor-not-allowed disabled:opacity-50",children:x?t("common.loading"):t("auth.join.submit")})]})]})})}export{E as Join};
1
+ import{e as r,j as e}from"./vendor-DE_-CLIE.js";import{aj as v,af as t}from"./main-N3GYCdLF.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";function E({onSuccess:b,onInvalidInvite:l}){const{join:f}=v(),[u,h]=r.useState(""),[d,j]=r.useState(""),[o,w]=r.useState(""),[c,g]=r.useState(""),[m,n]=r.useState(""),[x,p]=r.useState(!1);r.useEffect(()=>{const a=new URLSearchParams(window.location.search).get("invite");a?h(a):l()},[l]);const y=async s=>{if(s.preventDefault(),n(""),o.length<8){n(t("auth.setup.passwordTooShort"));return}if(o!==c){n(t("auth.setup.passwordMismatch"));return}p(!0);try{await f(u,d,o),b()}catch(a){const i=a instanceof Error?a.message:"Join failed";if(i.includes("Invalid invitation")||i.includes("expired")||i.includes("already used")){l();return}n(i)}finally{p(!1)}};return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-surface-0 px-4",children:e.jsxs("div",{className:"w-full max-w-sm space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"font-display text-2xl font-semibold text-text-primary",children:t("auth.join.title")}),e.jsx("p",{className:"mt-2 text-sm text-text-muted",children:t("auth.join.welcome")}),e.jsx("p",{className:"mt-1 text-sm text-text-muted",children:t("auth.join.description")})]}),e.jsxs("form",{onSubmit:y,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.join.username")}),e.jsx("input",{type:"text",value:d,onChange:s=>j(s.target.value),required:!0,autoComplete:"username",autoFocus:!0,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"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.join.password")}),e.jsx("input",{type:"password",value:o,onChange:s=>w(s.target.value),required:!0,autoComplete:"new-password",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"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.join.confirmPassword")}),e.jsx("input",{type:"password",value:c,onChange:s=>g(s.target.value),required:!0,autoComplete:"new-password",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.jsx("p",{className:"text-sm text-status-error",children:m}),e.jsx("button",{type:"submit",disabled:x||!u,className:"w-full rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-light disabled:cursor-not-allowed disabled:opacity-50",children:x?t("common.loading"):t("auth.join.submit")})]})]})})}export{E as Join};
@@ -1 +1 @@
1
- import{e as r,j as e}from"./vendor-DE_-CLIE.js";import{aj as f,af as t}from"./main-CwLwGVDc.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";function N({onSuccess:d,onNavigateRegister:c}){const{login:m,registrationAllowed:x}=f(),[a,p]=r.useState(""),[o,b]=r.useState(""),[l,n]=r.useState(""),[i,u]=r.useState(!1),h=async s=>{s.preventDefault(),n(""),u(!0);try{await m(a,o),d()}catch{n(t("auth.login.failed"))}finally{u(!1)}};return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-surface-0 px-4",children:e.jsxs("div",{className:"w-full max-w-sm space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"font-display text-2xl font-semibold text-text-primary",children:t("auth.login.title")}),e.jsx("p",{className:"mt-2 text-sm text-text-muted",children:t("auth.login.description")})]}),e.jsxs("form",{onSubmit:h,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.login.username")}),e.jsx("input",{type:"text",value:a,onChange:s=>p(s.target.value),required:!0,autoComplete:"username",autoFocus:!0,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"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.login.password")}),e.jsx("input",{type:"password",value:o,onChange:s=>b(s.target.value),required:!0,autoComplete:"current-password",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"})]}),l&&e.jsx("p",{className:"text-sm text-status-error",children:l}),e.jsx("button",{type:"submit",disabled:i,className:"w-full rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-light disabled:cursor-not-allowed disabled:opacity-50",children:i?t("common.loading"):t("auth.login.submit")})]}),x&&e.jsx("button",{type:"button",onClick:c,className:"w-full text-center text-sm text-text-muted hover:text-text-primary transition-colors",children:t("auth.login.register")})]})})}export{N as Login};
1
+ import{e as r,j as e}from"./vendor-DE_-CLIE.js";import{aj as f,af as t}from"./main-N3GYCdLF.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";function N({onSuccess:d,onNavigateRegister:c}){const{login:m,registrationAllowed:x}=f(),[a,p]=r.useState(""),[o,b]=r.useState(""),[l,n]=r.useState(""),[i,u]=r.useState(!1),h=async s=>{s.preventDefault(),n(""),u(!0);try{await m(a,o),d()}catch{n(t("auth.login.failed"))}finally{u(!1)}};return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-surface-0 px-4",children:e.jsxs("div",{className:"w-full max-w-sm space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"font-display text-2xl font-semibold text-text-primary",children:t("auth.login.title")}),e.jsx("p",{className:"mt-2 text-sm text-text-muted",children:t("auth.login.description")})]}),e.jsxs("form",{onSubmit:h,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.login.username")}),e.jsx("input",{type:"text",value:a,onChange:s=>p(s.target.value),required:!0,autoComplete:"username",autoFocus:!0,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"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.login.password")}),e.jsx("input",{type:"password",value:o,onChange:s=>b(s.target.value),required:!0,autoComplete:"current-password",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"})]}),l&&e.jsx("p",{className:"text-sm text-status-error",children:l}),e.jsx("button",{type:"submit",disabled:i,className:"w-full rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-light disabled:cursor-not-allowed disabled:opacity-50",children:i?t("common.loading"):t("auth.login.submit")})]}),x&&e.jsx("button",{type:"button",onClick:c,className:"w-full text-center text-sm text-text-muted hover:text-text-primary transition-colors",children:t("auth.login.register")})]})})}export{N as Login};
@@ -1 +1 @@
1
- import{e as r,j as e}from"./vendor-DE_-CLIE.js";import{aj as y,af as t}from"./main-CwLwGVDc.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";function S({onSuccess:m,onBack:x}){const{register:p}=y(),[n,b]=r.useState(""),[a,h]=r.useState(""),[l,f]=r.useState(""),[i,o]=r.useState(""),[u,d]=r.useState(!1),g=async s=>{if(s.preventDefault(),o(""),a.length<8){o(t("auth.setup.passwordTooShort"));return}if(a!==l){o(t("auth.setup.passwordMismatch"));return}d(!0);try{await p(n,a),m()}catch(c){o(c instanceof Error?c.message:t("auth.register.failed"))}finally{d(!1)}};return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-surface-0 px-4",children:e.jsxs("div",{className:"w-full max-w-sm space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"font-display text-2xl font-semibold text-text-primary",children:t("auth.register.title")}),e.jsx("p",{className:"mt-2 text-sm text-text-muted",children:t("auth.register.description")})]}),e.jsxs("form",{onSubmit:g,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.login.username")}),e.jsx("input",{type:"text",value:n,onChange:s=>b(s.target.value),required:!0,autoComplete:"username",autoFocus:!0,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"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.login.password")}),e.jsx("input",{type:"password",value:a,onChange:s=>h(s.target.value),required:!0,autoComplete:"new-password",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"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.join.confirmPassword")}),e.jsx("input",{type:"password",value:l,onChange:s=>f(s.target.value),required:!0,autoComplete:"new-password",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"})]}),i&&e.jsx("p",{className:"text-sm text-status-error",children:i}),e.jsx("button",{type:"submit",disabled:u,className:"w-full rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-light disabled:cursor-not-allowed disabled:opacity-50",children:u?t("common.loading"):t("auth.register.submit")})]}),e.jsx("button",{type:"button",onClick:x,className:"w-full text-center text-sm text-text-muted hover:text-text-primary transition-colors",children:t("auth.register.backToLogin")})]})})}export{S as Register};
1
+ import{e as r,j as e}from"./vendor-DE_-CLIE.js";import{aj as y,af as t}from"./main-N3GYCdLF.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";function S({onSuccess:m,onBack:x}){const{register:p}=y(),[n,b]=r.useState(""),[a,h]=r.useState(""),[l,f]=r.useState(""),[i,o]=r.useState(""),[u,d]=r.useState(!1),g=async s=>{if(s.preventDefault(),o(""),a.length<8){o(t("auth.setup.passwordTooShort"));return}if(a!==l){o(t("auth.setup.passwordMismatch"));return}d(!0);try{await p(n,a),m()}catch(c){o(c instanceof Error?c.message:t("auth.register.failed"))}finally{d(!1)}};return e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-surface-0 px-4",children:e.jsxs("div",{className:"w-full max-w-sm space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"font-display text-2xl font-semibold text-text-primary",children:t("auth.register.title")}),e.jsx("p",{className:"mt-2 text-sm text-text-muted",children:t("auth.register.description")})]}),e.jsxs("form",{onSubmit:g,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.login.username")}),e.jsx("input",{type:"text",value:n,onChange:s=>b(s.target.value),required:!0,autoComplete:"username",autoFocus:!0,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"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.login.password")}),e.jsx("input",{type:"password",value:a,onChange:s=>h(s.target.value),required:!0,autoComplete:"new-password",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"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-text-secondary",children:t("auth.join.confirmPassword")}),e.jsx("input",{type:"password",value:l,onChange:s=>f(s.target.value),required:!0,autoComplete:"new-password",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"})]}),i&&e.jsx("p",{className:"text-sm text-status-error",children:i}),e.jsx("button",{type:"submit",disabled:u,className:"w-full rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-light disabled:cursor-not-allowed disabled:opacity-50",children:u?t("common.loading"):t("auth.register.submit")})]}),e.jsx("button",{type:"button",onClick:x,className:"w-full text-center text-sm text-text-muted hover:text-text-primary transition-colors",children:t("auth.register.backToLogin")})]})})}export{S as Register};
@@ -1,4 +1,4 @@
1
- var ot=Object.defineProperty;var it=(s,t,r)=>t in s?ot(s,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[t]=r;var E=(s,t,r)=>it(s,typeof t!="symbol"?t+"":t,r);import{e as u,j as e}from"./vendor-DE_-CLIE.js";import{a5 as $,Q as lt,ad as ct,a0 as dt,a9 as xe,$ as F,V as ut,x as Ie,g as we,a8 as $e,L as qe,z as mt,w as xt,a7 as I,a4 as G,d as Pe,ag as Ne,W as pt,H as ht,_ as ft,ak as De,af as N,A as yt,aa as gt,F as bt,ah as jt,a6 as kt,I as wt,Y as Nt,y as Ue,P as vt,c as _t,C as St,R as ve,N as Ct,ac as Mt,D as Et,a as Tt,q as Fe,s as Oe,v as Rt,f as Le,e as He,r as ze,M as At}from"./main-CwLwGVDc.js";import{g as It}from"./workerType-Bd-zteMi.js";import{D as Ve,a as Be,c as We,d as Qe,b as $t,S as qt}from"./SessionVisibilityBadge-Dy4FwTzo.js";import{U as Pt}from"./UserSearchInput-CyQWtLL-.js";import"./shiki-mEP5vQQu.js";import"./motion-BILbV7YQ.js";/**
1
+ var ot=Object.defineProperty;var it=(s,t,r)=>t in s?ot(s,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[t]=r;var E=(s,t,r)=>it(s,typeof t!="symbol"?t+"":t,r);import{e as u,j as e}from"./vendor-DE_-CLIE.js";import{a5 as $,Q as lt,ad as ct,a0 as dt,a9 as xe,$ as F,V as ut,x as Ie,g as we,a8 as $e,L as qe,z as mt,w as xt,a7 as I,a4 as G,d as Pe,ag as Ne,W as pt,H as ht,_ as ft,ak as De,af as v,A as yt,aa as gt,F as bt,ah as jt,a6 as kt,I as wt,Y as Nt,y as Ue,P as vt,c as _t,C as St,R as ve,N as Ct,ac as Mt,D as Et,a as Tt,q as Fe,s as Oe,v as Rt,f as Le,e as He,r as ze,M as At}from"./main-N3GYCdLF.js";import{g as It}from"./workerType-Bd-zteMi.js";import{D as Ve,a as Be,c as We,d as Qe,b as $t,S as qt}from"./SessionVisibilityBadge-91WyR9K6.js";import{U as Pt}from"./UserSearchInput-BxcYR_HU.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.
@@ -58,8 +58,8 @@ var ot=Object.defineProperty;var it=(s,t,r)=>t in s?ot(s,t,{enumerable:!0,config
58
58
  *
59
59
  * This source code is licensed under the ISC license.
60
60
  * See the LICENSE file in the root directory of this source tree.
61
- */const rs=[["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"}]],as=$("triangle-alert",rs);function Ke(){return{tasks:{}}}const _e=3e4;function ae(s){const t=s.trim();if(!t)return"agent";const r=t.split(/\s+/).slice(0,2).join(" ");return r.length>40?r.slice(0,40)+"…":r}function os(s,t){var d,x,f,m,p,g,v,j,a,i,y,b;const r=t.subtype;if(r!=="task_started"&&r!=="task_progress"&&r!=="task_notification")return s;const n=t.task_id;if(!n)return s;const l=Date.now(),c=s.tasks[n];if(r==="task_started"){if(c)return{tasks:{...s.tasks,[n]:{...c,description:t.description??c.description,name:ae(t.description??c.description),taskType:t.task_type??c.taskType,workflowName:t.workflow_name??c.workflowName,prompt:t.prompt??c.prompt,toolUseId:t.tool_use_id??c.toolUseId,status:"running",startTime:l,evictAfter:void 0}}};const k=t.description??"";return{tasks:{...s.tasks,[n]:{taskId:n,name:ae(k),description:k,taskType:t.task_type,workflowName:t.workflow_name,prompt:t.prompt,toolUseId:t.tool_use_id,status:"running",startTime:l}}}}if(r==="task_progress"){if(!c){const k=t.description??"";return{tasks:{...s.tasks,[n]:{taskId:n,name:ae(k),description:k,toolUseId:t.tool_use_id,status:"running",startTime:l,tokenCount:(d=t.usage)==null?void 0:d.total_tokens,toolUseCount:(x=t.usage)==null?void 0:x.tool_uses,durationMs:(f=t.usage)==null?void 0:f.duration_ms,lastToolName:t.last_tool_name,summary:t.summary}}}}return{tasks:{...s.tasks,[n]:{...c,description:t.description??c.description,tokenCount:((m=t.usage)==null?void 0:m.total_tokens)??c.tokenCount,toolUseCount:((p=t.usage)==null?void 0:p.tool_uses)??c.toolUseCount,durationMs:((g=t.usage)==null?void 0:g.duration_ms)??c.durationMs,lastToolName:t.last_tool_name??c.lastToolName,summary:t.summary??c.summary}}}}return c?{tasks:{...s.tasks,[n]:{...c,status:t.status??"completed",endTime:l,finalSummary:t.summary??c.finalSummary,outputFile:t.output_file??c.outputFile,tokenCount:((i=t.usage)==null?void 0:i.total_tokens)??c.tokenCount,toolUseCount:((y=t.usage)==null?void 0:y.tool_uses)??c.toolUseCount,durationMs:((b=t.usage)==null?void 0:b.duration_ms)??c.durationMs,evictAfter:l+_e}}}:{tasks:{...s.tasks,[n]:{taskId:n,name:ae(t.summary??""),description:t.summary??"",status:t.status??"completed",startTime:l,endTime:l,finalSummary:t.summary,outputFile:t.output_file,tokenCount:(v=t.usage)==null?void 0:v.total_tokens,toolUseCount:(j=t.usage)==null?void 0:j.tool_uses,durationMs:(a=t.usage)==null?void 0:a.duration_ms,evictAfter:l+_e}}}}function is(s,t=Date.now()){return Object.values(s.tasks).filter(r=>r.evictAfter===void 0||r.evictAfter>t).sort((r,n)=>r.startTime-n.startTime)}class ls{constructor(){E(this,"listeners",new Set);E(this,"eventSource",null);E(this,"_lastSeqNum",0)}onEvent(t){return this.listeners.add(t),()=>this.listeners.delete(t)}connect(t){this.disconnect();const r=`/web/sessions/${t}/events`,n=new EventSource(r,{withCredentials:!0});this.eventSource=n,n.addEventListener("message",l=>{try{const c=JSON.parse(l.data);if(c.seqNum!==void 0&&c.seqNum<=this._lastSeqNum)return;c.seqNum!==void 0&&(this._lastSeqNum=c.seqNum);for(const d of this.listeners)d(c)}catch{}})}disconnect(){this.eventSource&&(this.eventSource.close(),this.eventSource=null),this._lastSeqNum=0}}const pe=new ls;function Se(s){if(typeof s.content=="string")return s.content;if(s.message&&typeof s.message=="object"){const t=s.message;if(typeof t.content=="string")return t.content;if(Array.isArray(t.content))return t.content.filter(r=>r.type==="text"&&typeof r.text=="string").map(r=>r.text).join("")}return""}function Ce(s,t){for(let r=s.length-1;r>=0;r--){const n=s[r];if(n&&n.type==="tool_call"&&n.toolCall.id===t)return r}return-1}const he="streaming-";function cs(s){const t=s.message;if(!t||typeof t!="object"||!Array.isArray(t.content))return"";const r=[];for(const n of t.content)if((n==null?void 0:n.type)==="thinking"){const l=typeof n.thinking=="string"&&n.thinking||typeof n.text=="string"&&n.text||"";l&&r.push(l)}return r.join("")}function Me(s){return s.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"}))}class ds{constructor(t,r,n){E(this,"sessionId");E(this,"setEntries");E(this,"unsub",null);E(this,"onStatusChange");E(this,"onError");E(this,"onPermissionRequest");E(this,"onModelsStateChange");E(this,"onSubagentUpdate");E(this,"onControlResponse");E(this,"onPermissionModeChange");E(this,"onUsageChange");E(this,"onElicitationRequest");E(this,"subagentState",Ke());E(this,"seenUuids",new Set);E(this,"seenToolCallIds",new Set);E(this,"pendingControlRequests",new Map);this.sessionId=t,this.setEntries=r,this.onStatusChange=n==null?void 0:n.onStatusChange,this.onError=n==null?void 0:n.onError,this.onPermissionRequest=n==null?void 0:n.onPermissionRequest,this.onModelsStateChange=n==null?void 0:n.onModelsStateChange,this.onSubagentUpdate=n==null?void 0:n.onSubagentUpdate,this.onControlResponse=n==null?void 0:n.onControlResponse,this.onPermissionModeChange=n==null?void 0:n.onPermissionModeChange,this.onUsageChange=n==null?void 0:n.onUsageChange,this.onElicitationRequest=n==null?void 0:n.onElicitationRequest}async init(){await this.loadHistory(),this.connectSSE()}async loadHistory(){var f,m;const{events:t}=await lt(this.sessionId);if(!t||t.length===0)return;const r=[];let n=null;const l=()=>{n&&(r.push(n),n=null)};for(const p of t){const g=p.payload||{},v=g.uuid;if(typeof v=="string"&&v&&this.seenUuids.add(v),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")continue;l();const j=Se(g);j&&r.push({type:"user_message",id:p.id||`hist-user-${r.length}`,content:j})}else if(p.type==="assistant"){l();const j=Se(g),a=[],i=g.message;if(i&&typeof i=="object"&&Array.isArray(i.content)){for(const y of i.content)if(y.type==="tool_use"){const b=y.id;b&&this.seenToolCallIds.add(b),a.push({type:"tool_call",toolCall:{id:b||`hist-tool-${r.length}`,title:y.name||"tool",status:"complete",rawInput:y.input||{}}})}}if(j||a.length>0){n={type:"assistant_message",id:p.id||`hist-asst-${r.length}`,chunks:j?[{type:"message",text:j}]:[]},r.push(n);for(const y of a)r.push(y);n=null}}else if(p.type==="tool_use"){const j=g,a={type:"tool_call",toolCall:{id:j.tool_call_id||`hist-tool-${r.length}`,title:j.tool_name||"tool",status:"complete",rawInput:j.tool_input||{}}};r.push(a)}else if(p.type==="tool_result"){const j=g,a=Ce(r,j.tool_call_id||"");if(a>=0){const i=r[a];r[a]={type:"tool_call",toolCall:{...i.toolCall,rawOutput:{output:j.content||j.output||""}}}}}}l();let c=null;for(const p of t){if(p.type!=="task_state")continue;const g=p.payload||{};Array.isArray(g.tasks)&&(c=g.tasks)}if(c&&c.length>0){const p=Me(c);p.length>0&&r.push({type:"plan",id:`plan-hist-${Date.now()}`,entries:p})}this.setEntries(r);let d=null,x=null;for(const p of t){const g=p.payload||{};if(p.type==="models_state"){const v=g.raw,j=v&&typeof v=="object"?v.models_state:g.models_state;j&&Array.isArray(j.availableModels)&&typeof j.currentModelId=="string"&&(d=j)}else if(p.type==="result"||p.type==="result_success"){const v=g.usage,j=typeof g.total_cost_usd=="number"?g.total_cost_usd:null;(v||j!==null)&&(x={inputTokens:((v==null?void 0:v.input_tokens)??0)+((v==null?void 0:v.cache_read_input_tokens)??0)+((v==null?void 0:v.cache_creation_input_tokens)??0),outputTokens:(v==null?void 0:v.output_tokens)??0,totalCostUsd:j})}}d&&((f=this.onModelsStateChange)==null||f.call(this,d)),x&&((m=this.onUsageChange)==null||m.call(this,x))}connectSSE(){pe.connect(this.sessionId),this.unsub=pe.onEvent(t=>this.handleEvent(t))}disconnect(){this.unsub&&(this.unsub(),this.unsub=null),pe.disconnect()}handleEvent(t){var c,d,x,f,m,p,g,v,j;const r=t.type,n=t.payload||{},l=JSON.stringify(t);if(!/Remote Control connecting/i.test(l))switch(r){case"assistant":{const a=n.uuid;if(typeof a=="string"&&a){if(this.seenUuids.has(a))break;this.seenUuids.add(a)}const i=typeof n.content=="string"?n.content:"",y=cs(n);this.setEntries(k=>{const _=k[k.length-1];if((_==null?void 0:_.type)==="assistant_message"&&_.id.startsWith(he))return[...k.slice(0,-1),{..._,id:`assistant-${Date.now()}`,chunks:[...y?[{type:"thought",text:y}]:[],{type:"message",text:i}]}];if((_==null?void 0:_.type)==="assistant_message"){const S=_.chunks[_.chunks.length-1];return(S==null?void 0:S.type)==="message"?[...k.slice(0,-1),{..._,chunks:[..._.chunks.slice(0,-1),{type:"message",text:S.text+i}]}]:[...k.slice(0,-1),{..._,chunks:[..._.chunks,{type:"message",text:i}]}]}if(i&&i.trim()||y){const S={type:"assistant_message",id:`assistant-${Date.now()}`,chunks:[...y?[{type:"thought",text:y}]:[],...i?[{type:"message",text:i}]:[]]};return[...k,S]}return k});const b=n.message;if(b&&typeof b=="object"&&Array.isArray(b.content)){const k=b.content.filter(_=>_.type==="tool_use");for(const _ of k){const S=_.id||`call-${Date.now()}-${Math.random().toString(16).slice(2,8)}`;if(this.seenToolCallIds.has(S))continue;this.seenToolCallIds.add(S);const R={id:S,title:_.name||"tool",status:"running",rawInput:_.input||{}};this.setEntries(A=>[...A,{type:"tool_call",toolCall:R}])}}break}case"tool_use":{const a=n,i=a.tool_call_id||`call-${Date.now()}`;if(this.seenToolCallIds.has(i))break;this.seenToolCallIds.add(i);const y={id:i,title:a.tool_name||"tool",status:"running",rawInput:a.tool_input||{}};this.setEntries(b=>[...b,{type:"tool_call",toolCall:y}]);break}case"tool_result":{const a=n,i=a.tool_call_id||"";this.setEntries(y=>{const b=Ce(y,i);if(b<0)return y;const k=y[b];return y.map((_,S)=>S===b?{type:"tool_call",toolCall:{...k.toolCall,status:"complete",rawOutput:{output:a.content||a.output||""}}}:_)});break}case"control_request":case"permission_request":{const a=n.request;if(a&&a.subtype==="can_use_tool"){const i=n.request_id||"",y=a.tool_name||"unknown",b=a.input||a.tool_input||{},k=a.description||"",_=Array.isArray(a.permission_suggestions)?a.permission_suggestions:[];this.setEntries(S=>{const R=[...S].reverse().findIndex(A=>A.type==="tool_call");if(R>=0){const A=S.length-1-R,H=S[A];if(H.toolCall.status==="running")return S.map((q,B)=>B===A?{type:"tool_call",toolCall:{...H.toolCall,status:"waiting_for_confirmation",permissionRequest:{requestId:i,options:[]}}}:q)}return S}),(c=this.onPermissionRequest)==null||c.call(this,{requestId:i,toolName:y,toolInput:b,description:k,suggestions:_})}else a&&a.subtype==="elicitation"&&((d=this.onElicitationRequest)==null||d.call(this,{requestId:n.request_id||"",serverName:a.mcp_server_name||"",message:a.message||"",mode:a.mode==="url"?"url":"form",url:typeof a.url=="string"?a.url:void 0,requestedSchema:a.requested_schema||void 0}));break}case"session_status":{if(ct(n)){this.setEntries([]);break}typeof n.status=="string"&&((x=this.onStatusChange)==null||x.call(this,n.status));break}case"error":{const a=String(n.message||n.content||"Unknown error");(f=this.onError)==null||f.call(this,a);break}case"models_state":{const a=n.raw,i=typeof a=="object"&&a!==null?a.models_state:n.models_state;i&&Array.isArray(i.availableModels)&&typeof i.currentModelId=="string"&&((m=this.onModelsStateChange)==null||m.call(this,i));break}case"system":{const a=n.raw,i=a&&typeof a=="object"?a:n,y=typeof i.subtype=="string"?i.subtype:void 0;if(y==="task_started"||y==="task_progress"||y==="task_notification"){const k={subtype:y,task_id:typeof i.task_id=="string"?i.task_id:void 0,tool_use_id:typeof i.tool_use_id=="string"?i.tool_use_id:void 0,description:typeof i.description=="string"?i.description:void 0,task_type:typeof i.task_type=="string"?i.task_type:void 0,workflow_name:typeof i.workflow_name=="string"?i.workflow_name:void 0,prompt:typeof i.prompt=="string"?i.prompt:void 0,usage:i.usage&&typeof i.usage=="object"?i.usage:void 0,last_tool_name:typeof i.last_tool_name=="string"?i.last_tool_name:void 0,summary:typeof i.summary=="string"?i.summary:void 0,status:i.status==="completed"||i.status==="failed"||i.status==="stopped"?i.status:void 0,output_file:typeof i.output_file=="string"?i.output_file:void 0};this.subagentState=os(this.subagentState,k)}const b=typeof i.permissionMode=="string"?i.permissionMode:typeof n.permissionMode=="string"?n.permissionMode:null;b&&((p=this.onPermissionModeChange)==null||p.call(this,b));break}case"control_response":{const a=n.response;if(a&&typeof a=="object"){const i=typeof a.request_id=="string"?a.request_id:"",y=typeof a.subtype=="string"?a.subtype:"";if(i){(g=this.onControlResponse)==null||g.call(this,{subtype:y,requestId:i,error:typeof a.error=="string"?a.error:void 0});const b=this.pendingControlRequests.get(i);b&&(this.pendingControlRequests.delete(i),b(y==="success"&&a.response&&typeof a.response=="object"?a.response:null))}}break}case"stream_event":{const a=n.event;if(!a||typeof a.type!="string")break;if(a.type==="content_block_delta"){const i=a.delta;if(!i||typeof i.type!="string")break;const y=i.type==="text_delta"?"message":i.type==="thinking_delta"?"thought":null;if(!y)break;const b=i.text??i.thinking;if(typeof b!="string"||!b)break;this.appendStreamingDelta(y,b)}break}case"partial_assistant":{const a=typeof n.content=="string"?n.content:"";a&&this.appendStreamingDelta("message",a);break}case"result":case"result_success":{(v=this.onStatusChange)==null||v.call(this,"idle");const a=n.usage,i=typeof n.total_cost_usd=="number"?n.total_cost_usd:null;if(a||i!==null){const y=((a==null?void 0:a.input_tokens)??0)+((a==null?void 0:a.cache_read_input_tokens)??0)+((a==null?void 0:a.cache_creation_input_tokens)??0);(j=this.onUsageChange)==null||j.call(this,{inputTokens:y,outputTokens:(a==null?void 0:a.output_tokens)??0,totalCostUsd:i})}break}case"task_state":{const a=Array.isArray(n.tasks)?n.tasks:[];if(a.length===0)break;const i=Me(a);if(i.length===0)break;this.setEntries(y=>[...y.filter(k=>k.type!=="plan"),{type:"plan",id:`plan-${n.task_list_id||Date.now()}`,entries:i}]);break}}}appendStreamingDelta(t,r){this.setEntries(n=>{const l=n[n.length-1];if((l==null?void 0:l.type)==="assistant_message"&&l.id.startsWith(he)){const d=l.chunks[l.chunks.length-1];return(d==null?void 0:d.type)===t?[...n.slice(0,-1),{...l,chunks:[...l.chunks.slice(0,-1),{type:t,text:d.text+r}]}]:[...n.slice(0,-1),{...l,chunks:[...l.chunks,{type:t,text:r}]}]}const c={type:"assistant_message",id:`${he}${Date.now()}`,chunks:[{type:t,text:r}]};return[...n,c]})}async sendMessage(t,r,n){const l=r&&r.length>0,c=n&&n.length>0;if(!t.trim()&&!l&&!c)return;const d={type:"user_message",id:`user-${Date.now()}`,content:t,images:l?r:void 0,attachments:c?n:void 0};this.setEntries(m=>[...m,d]);const x=[];if(t&&x.push({type:"text",text:t}),l)for(const m of r)x.push({type:"image",source:{type:"base64",media_type:m.mimeType,data:m.data}});if(c){for(const m of n)if(m.kind==="text"||m.kind==="table"){const p=`📎 ${m.name}${m.size!=null?` (${us(m.size)})`:""}`,g=m.textContent||"(空文件)";x.push({type:"text",text:`${p}
61
+ */const rs=[["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"}]],as=$("triangle-alert",rs);function Ke(){return{tasks:{}}}const _e=3e4;function ae(s){const t=s.trim();if(!t)return"agent";const r=t.split(/\s+/).slice(0,2).join(" ");return r.length>40?r.slice(0,40)+"…":r}function os(s,t){var d,x,p,m,g,j,k,S,a,o,h,y;const r=t.subtype;if(r!=="task_started"&&r!=="task_progress"&&r!=="task_notification")return s;const n=t.task_id;if(!n)return s;const l=Date.now(),c=s.tasks[n];if(r==="task_started"){if(c)return{tasks:{...s.tasks,[n]:{...c,description:t.description??c.description,name:ae(t.description??c.description),taskType:t.task_type??c.taskType,workflowName:t.workflow_name??c.workflowName,prompt:t.prompt??c.prompt,toolUseId:t.tool_use_id??c.toolUseId,status:"running",startTime:l,evictAfter:void 0}}};const b=t.description??"";return{tasks:{...s.tasks,[n]:{taskId:n,name:ae(b),description:b,taskType:t.task_type,workflowName:t.workflow_name,prompt:t.prompt,toolUseId:t.tool_use_id,status:"running",startTime:l}}}}if(r==="task_progress"){if(!c){const b=t.description??"";return{tasks:{...s.tasks,[n]:{taskId:n,name:ae(b),description:b,toolUseId:t.tool_use_id,status:"running",startTime:l,tokenCount:(d=t.usage)==null?void 0:d.total_tokens,toolUseCount:(x=t.usage)==null?void 0:x.tool_uses,durationMs:(p=t.usage)==null?void 0:p.duration_ms,lastToolName:t.last_tool_name,summary:t.summary}}}}return{tasks:{...s.tasks,[n]:{...c,description:t.description??c.description,tokenCount:((m=t.usage)==null?void 0:m.total_tokens)??c.tokenCount,toolUseCount:((g=t.usage)==null?void 0:g.tool_uses)??c.toolUseCount,durationMs:((j=t.usage)==null?void 0:j.duration_ms)??c.durationMs,lastToolName:t.last_tool_name??c.lastToolName,summary:t.summary??c.summary}}}}return c?{tasks:{...s.tasks,[n]:{...c,status:t.status??"completed",endTime:l,finalSummary:t.summary??c.finalSummary,outputFile:t.output_file??c.outputFile,tokenCount:((o=t.usage)==null?void 0:o.total_tokens)??c.tokenCount,toolUseCount:((h=t.usage)==null?void 0:h.tool_uses)??c.toolUseCount,durationMs:((y=t.usage)==null?void 0:y.duration_ms)??c.durationMs,evictAfter:l+_e}}}:{tasks:{...s.tasks,[n]:{taskId:n,name:ae(t.summary??""),description:t.summary??"",status:t.status??"completed",startTime:l,endTime:l,finalSummary:t.summary,outputFile:t.output_file,tokenCount:(k=t.usage)==null?void 0:k.total_tokens,toolUseCount:(S=t.usage)==null?void 0:S.tool_uses,durationMs:(a=t.usage)==null?void 0:a.duration_ms,evictAfter:l+_e}}}}function is(s,t=Date.now()){return Object.values(s.tasks).filter(r=>r.evictAfter===void 0||r.evictAfter>t).sort((r,n)=>r.startTime-n.startTime)}class ls{constructor(){E(this,"listeners",new Set);E(this,"eventSource",null);E(this,"_lastSeqNum",0)}onEvent(t){return this.listeners.add(t),()=>this.listeners.delete(t)}connect(t){this.disconnect();const r=`/web/sessions/${t}/events`,n=new EventSource(r,{withCredentials:!0});this.eventSource=n,n.addEventListener("message",l=>{try{const c=JSON.parse(l.data);if(c.seqNum!==void 0&&c.seqNum<=this._lastSeqNum)return;c.seqNum!==void 0&&(this._lastSeqNum=c.seqNum);for(const d of this.listeners)d(c)}catch{}})}disconnect(){this.eventSource&&(this.eventSource.close(),this.eventSource=null),this._lastSeqNum=0}}const pe=new ls;function Se(s){if(typeof s.content=="string")return s.content;if(s.message&&typeof s.message=="object"){const t=s.message;if(typeof t.content=="string")return t.content;if(Array.isArray(t.content))return t.content.filter(r=>r.type==="text"&&typeof r.text=="string").map(r=>r.text).join("")}return""}function Ce(s,t){for(let r=s.length-1;r>=0;r--){const n=s[r];if(n&&n.type==="tool_call"&&n.toolCall.id===t)return r}return-1}const he="streaming-";function cs(s){const t=s.message;if(!t||typeof t!="object"||!Array.isArray(t.content))return"";const r=[];for(const n of t.content)if((n==null?void 0:n.type)==="thinking"){const l=typeof n.thinking=="string"&&n.thinking||typeof n.text=="string"&&n.text||"";l&&r.push(l)}return r.join("")}function Me(s){return s.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"}))}class ds{constructor(t,r,n){E(this,"sessionId");E(this,"setEntries");E(this,"unsub",null);E(this,"onStatusChange");E(this,"onError");E(this,"onPermissionRequest");E(this,"onModelsStateChange");E(this,"onSubagentUpdate");E(this,"onControlResponse");E(this,"onPermissionModeChange");E(this,"onUsageChange");E(this,"onElicitationRequest");E(this,"subagentState",Ke());E(this,"seenUuids",new Set);E(this,"seenToolCallIds",new Set);E(this,"pendingControlRequests",new Map);E(this,"turnEnded",!1);E(this,"userSinceTurnEnd",!1);this.sessionId=t,this.setEntries=r,this.onStatusChange=n==null?void 0:n.onStatusChange,this.onError=n==null?void 0:n.onError,this.onPermissionRequest=n==null?void 0:n.onPermissionRequest,this.onModelsStateChange=n==null?void 0:n.onModelsStateChange,this.onSubagentUpdate=n==null?void 0:n.onSubagentUpdate,this.onControlResponse=n==null?void 0:n.onControlResponse,this.onPermissionModeChange=n==null?void 0:n.onPermissionModeChange,this.onUsageChange=n==null?void 0:n.onUsageChange,this.onElicitationRequest=n==null?void 0:n.onElicitationRequest}async init(){await this.loadHistory(),this.connectSSE()}async loadHistory(){var m,g,j;const{events:t}=await lt(this.sessionId);if(!t||t.length===0)return;const r=[];let n=null;const l=()=>{n&&(r.push(n),n=null)};for(const k of t){const S=k.payload||{},a=S.uuid;if(typeof a=="string"&&a&&this.seenUuids.add(a),k.type==="tool_use"){const o=S.tool_call_id;typeof o=="string"&&o&&this.seenToolCallIds.add(o)}if(k.type==="user"){if(k.direction==="inbound")continue;l();const o=Se(S);o&&r.push({type:"user_message",id:k.id||`hist-user-${r.length}`,content:o})}else if(k.type==="assistant"){l();const o=Se(S),h=[],y=S.message;if(y&&typeof y=="object"&&Array.isArray(y.content)){for(const b of y.content)if(b.type==="tool_use"){const w=b.id;w&&this.seenToolCallIds.add(w),h.push({type:"tool_call",toolCall:{id:w||`hist-tool-${r.length}`,title:b.name||"tool",status:"complete",rawInput:b.input||{}}})}}if(o||h.length>0){n={type:"assistant_message",id:k.id||`hist-asst-${r.length}`,chunks:o?[{type:"message",text:o}]:[]},r.push(n);for(const b of h)r.push(b);n=null}}else if(k.type==="tool_use"){const o=S,h={type:"tool_call",toolCall:{id:o.tool_call_id||`hist-tool-${r.length}`,title:o.tool_name||"tool",status:"complete",rawInput:o.tool_input||{}}};r.push(h)}else if(k.type==="tool_result"){const o=S,h=Ce(r,o.tool_call_id||"");if(h>=0){const y=r[h];r[h]={type:"tool_call",toolCall:{...y.toolCall,rawOutput:{output:o.content||o.output||""}}}}}}l();let c=null;for(const k of t){if(k.type!=="task_state")continue;const S=k.payload||{};Array.isArray(S.tasks)&&(c=S.tasks)}if(c&&c.length>0){const k=Me(c);k.length>0&&r.push({type:"plan",id:`plan-hist-${Date.now()}`,entries:k})}this.setEntries(r);let d=null,x=null,p=null;for(const k of t){const S=k.payload||{};if(k.type==="user"?p="user":(k.type==="result"||k.type==="result_success"||k.type==="interrupt")&&(p="turn_end"),k.type==="models_state"){const a=S.raw,o=a&&typeof a=="object"?a.models_state:S.models_state;o&&Array.isArray(o.availableModels)&&typeof o.currentModelId=="string"&&(d=o)}else if(k.type==="result"||k.type==="result_success"){const a=S.usage,o=typeof S.total_cost_usd=="number"?S.total_cost_usd:null;(a||o!==null)&&(x={inputTokens:((a==null?void 0:a.input_tokens)??0)+((a==null?void 0:a.cache_read_input_tokens)??0)+((a==null?void 0:a.cache_creation_input_tokens)??0),outputTokens:(a==null?void 0:a.output_tokens)??0,totalCostUsd:o})}}d&&((m=this.onModelsStateChange)==null||m.call(this,d)),x&&((g=this.onUsageChange)==null||g.call(this,x)),this.turnEnded=p==="turn_end",this.userSinceTurnEnd=p==="user",this.turnEnded&&((j=this.onStatusChange)==null||j.call(this,"idle"))}connectSSE(){pe.connect(this.sessionId),this.unsub=pe.onEvent(t=>this.handleEvent(t))}disconnect(){this.unsub&&(this.unsub(),this.unsub=null),pe.disconnect()}handleEvent(t){var c,d,x,p,m,g,j,k,S;const r=t.type,n=t.payload||{},l=JSON.stringify(t);if(!/Remote Control connecting/i.test(l))switch(r){case"user":{this.userSinceTurnEnd=!0;break}case"assistant":{const a=n.uuid;if(typeof a=="string"&&a){if(this.seenUuids.has(a))break;this.seenUuids.add(a)}const o=typeof n.content=="string"?n.content:"",h=cs(n);this.setEntries(b=>{const w=b[b.length-1];if((w==null?void 0:w.type)==="assistant_message"&&w.id.startsWith(he))return[...b.slice(0,-1),{...w,id:`assistant-${Date.now()}`,chunks:[...h?[{type:"thought",text:h}]:[],{type:"message",text:o}]}];if((w==null?void 0:w.type)==="assistant_message"){const _=w.chunks[w.chunks.length-1];return(_==null?void 0:_.type)==="message"?[...b.slice(0,-1),{...w,chunks:[...w.chunks.slice(0,-1),{type:"message",text:_.text+o}]}]:[...b.slice(0,-1),{...w,chunks:[...w.chunks,{type:"message",text:o}]}]}if(o&&o.trim()||h){const _={type:"assistant_message",id:`assistant-${Date.now()}`,chunks:[...h?[{type:"thought",text:h}]:[],...o?[{type:"message",text:o}]:[]]};return[...b,_]}return b});const y=n.message;if(y&&typeof y=="object"&&Array.isArray(y.content)){const b=y.content.filter(w=>w.type==="tool_use");for(const w of b){const _=w.id||`call-${Date.now()}-${Math.random().toString(16).slice(2,8)}`;if(this.seenToolCallIds.has(_))continue;this.seenToolCallIds.add(_);const R={id:_,title:w.name||"tool",status:"running",rawInput:w.input||{}};this.setEntries(A=>[...A,{type:"tool_call",toolCall:R}])}}break}case"tool_use":{const a=n,o=a.tool_call_id||`call-${Date.now()}`;if(this.seenToolCallIds.has(o))break;this.seenToolCallIds.add(o);const h={id:o,title:a.tool_name||"tool",status:"running",rawInput:a.tool_input||{}};this.setEntries(y=>[...y,{type:"tool_call",toolCall:h}]);break}case"tool_result":{const a=n,o=a.tool_call_id||"";this.setEntries(h=>{const y=Ce(h,o);if(y<0)return h;const b=h[y];return h.map((w,_)=>_===y?{type:"tool_call",toolCall:{...b.toolCall,status:"complete",rawOutput:{output:a.content||a.output||""}}}:w)});break}case"control_request":case"permission_request":{const a=n.request;if(a&&a.subtype==="can_use_tool"){const o=n.request_id||"",h=a.tool_name||"unknown",y=a.input||a.tool_input||{},b=a.description||"",w=Array.isArray(a.permission_suggestions)?a.permission_suggestions:[];this.setEntries(_=>{const R=[..._].reverse().findIndex(A=>A.type==="tool_call");if(R>=0){const A=_.length-1-R,H=_[A];if(H.toolCall.status==="running")return _.map((q,B)=>B===A?{type:"tool_call",toolCall:{...H.toolCall,status:"waiting_for_confirmation",permissionRequest:{requestId:o,options:[]}}}:q)}return _}),(c=this.onPermissionRequest)==null||c.call(this,{requestId:o,toolName:h,toolInput:y,description:b,suggestions:w})}else a&&a.subtype==="elicitation"&&((d=this.onElicitationRequest)==null||d.call(this,{requestId:n.request_id||"",serverName:a.mcp_server_name||"",message:a.message||"",mode:a.mode==="url"?"url":"form",url:typeof a.url=="string"?a.url:void 0,requestedSchema:a.requested_schema||void 0}));break}case"session_status":{if(ct(n)){this.setEntries([]);break}if(typeof n.status=="string"){if(n.status==="running"&&this.turnEnded&&!this.userSinceTurnEnd)break;(x=this.onStatusChange)==null||x.call(this,n.status)}break}case"error":{const a=String(n.message||n.content||"Unknown error");(p=this.onError)==null||p.call(this,a);break}case"models_state":{const a=n.raw,o=typeof a=="object"&&a!==null?a.models_state:n.models_state;o&&Array.isArray(o.availableModels)&&typeof o.currentModelId=="string"&&((m=this.onModelsStateChange)==null||m.call(this,o));break}case"system":{const a=n.raw,o=a&&typeof a=="object"?a:n,h=typeof o.subtype=="string"?o.subtype:void 0;if(h==="task_started"||h==="task_progress"||h==="task_notification"){const b={subtype:h,task_id:typeof o.task_id=="string"?o.task_id:void 0,tool_use_id:typeof o.tool_use_id=="string"?o.tool_use_id:void 0,description:typeof o.description=="string"?o.description:void 0,task_type:typeof o.task_type=="string"?o.task_type:void 0,workflow_name:typeof o.workflow_name=="string"?o.workflow_name:void 0,prompt:typeof o.prompt=="string"?o.prompt:void 0,usage:o.usage&&typeof o.usage=="object"?o.usage:void 0,last_tool_name:typeof o.last_tool_name=="string"?o.last_tool_name:void 0,summary:typeof o.summary=="string"?o.summary:void 0,status:o.status==="completed"||o.status==="failed"||o.status==="stopped"?o.status:void 0,output_file:typeof o.output_file=="string"?o.output_file:void 0};this.subagentState=os(this.subagentState,b)}const y=typeof o.permissionMode=="string"?o.permissionMode:typeof n.permissionMode=="string"?n.permissionMode:null;y&&((g=this.onPermissionModeChange)==null||g.call(this,y));break}case"control_response":{const a=n.response;if(a&&typeof a=="object"){const o=typeof a.request_id=="string"?a.request_id:"",h=typeof a.subtype=="string"?a.subtype:"";if(o){(j=this.onControlResponse)==null||j.call(this,{subtype:h,requestId:o,error:typeof a.error=="string"?a.error:void 0});const y=this.pendingControlRequests.get(o);y&&(this.pendingControlRequests.delete(o),y(h==="success"&&a.response&&typeof a.response=="object"?a.response:null))}}break}case"stream_event":{const a=n.event;if(!a||typeof a.type!="string")break;if(a.type==="content_block_delta"){const o=a.delta;if(!o||typeof o.type!="string")break;const h=o.type==="text_delta"?"message":o.type==="thinking_delta"?"thought":null;if(!h)break;const y=o.text??o.thinking;if(typeof y!="string"||!y)break;this.appendStreamingDelta(h,y)}break}case"partial_assistant":{const a=typeof n.content=="string"?n.content:"";a&&this.appendStreamingDelta("message",a);break}case"result":case"result_success":{this.turnEnded=!0,this.userSinceTurnEnd=!1,(k=this.onStatusChange)==null||k.call(this,"idle");const a=n.usage,o=typeof n.total_cost_usd=="number"?n.total_cost_usd:null;if(a||o!==null){const h=((a==null?void 0:a.input_tokens)??0)+((a==null?void 0:a.cache_read_input_tokens)??0)+((a==null?void 0:a.cache_creation_input_tokens)??0);(S=this.onUsageChange)==null||S.call(this,{inputTokens:h,outputTokens:(a==null?void 0:a.output_tokens)??0,totalCostUsd:o})}break}case"task_state":{const a=Array.isArray(n.tasks)?n.tasks:[];if(a.length===0)break;const o=Me(a);if(o.length===0)break;this.setEntries(h=>[...h.filter(b=>b.type!=="plan"),{type:"plan",id:`plan-${n.task_list_id||Date.now()}`,entries:o}]);break}}}appendStreamingDelta(t,r){this.setEntries(n=>{const l=n[n.length-1];if((l==null?void 0:l.type)==="assistant_message"&&l.id.startsWith(he)){const d=l.chunks[l.chunks.length-1];return(d==null?void 0:d.type)===t?[...n.slice(0,-1),{...l,chunks:[...l.chunks.slice(0,-1),{type:t,text:d.text+r}]}]:[...n.slice(0,-1),{...l,chunks:[...l.chunks,{type:t,text:r}]}]}const c={type:"assistant_message",id:`${he}${Date.now()}`,chunks:[{type:t,text:r}]};return[...n,c]})}async sendMessage(t,r,n){const l=r&&r.length>0,c=n&&n.length>0;if(!t.trim()&&!l&&!c)return;const d={type:"user_message",id:`user-${Date.now()}`,content:t,images:l?r:void 0,attachments:c?n:void 0};this.setEntries(m=>[...m,d]);const x=[];if(t&&x.push({type:"text",text:t}),l)for(const m of r)x.push({type:"image",source:{type:"base64",media_type:m.mimeType,data:m.data}});if(c){for(const m of n)if(m.kind==="text"||m.kind==="table"){const g=`📎 ${m.name}${m.size!=null?` (${us(m.size)})`:""}`,j=m.textContent||"(空文件)";x.push({type:"text",text:`${g}
62
62
  \`\`\`
63
- ${g}
64
- \`\`\``})}else if(m.kind==="directory"){const p=`📁 目录: ${m.name}${m.files!=null?` (${m.files.length} 个文件)`:""}`,g=m.textContent||"(空目录)";x.push({type:"text",text:`${p}
65
- ${g}`})}}const f=x.length===1&&x[0].type==="text"?x[0].text||t:x.length>0?x:t;await dt(this.sessionId,{type:"user",uuid:xe(),content:t,message:{content:f}})}async respondPermission(t,r,n){await F(this.sessionId,{type:"permission_response",approved:r,request_id:t,...n}),this.setEntries(l=>l.map(c=>{var d;return c.type!=="tool_call"||((d=c.toolCall.permissionRequest)==null?void 0:d.requestId)!==t?c:{type:"tool_call",toolCall:{...c.toolCall,status:r?"running":"rejected",permissionRequest:void 0}}}))}async interrupt(){this.setEntries(t=>t.map(r=>r.type!=="tool_call"||r.toolCall.status!=="running"&&r.toolCall.status!=="waiting_for_confirmation"?r:{type:"tool_call",toolCall:{...r.toolCall,status:"canceled",permissionRequest:void 0}})),await ut(this.sessionId)}async setPermissionMode(t){const r=xe();return await F(this.sessionId,{type:"control_request",request_id:r,request:{subtype:"set_permission_mode",mode:t}}),r}async searchFiles(t,r=20){const n=xe(),l=new Promise(d=>{this.pendingControlRequests.set(n,d)});await F(this.sessionId,{type:"control_request",request_id:n,request:{subtype:"file_search",query:t,limit:r}});const c=setTimeout(()=>{const d=this.pendingControlRequests.get(n);d&&(this.pendingControlRequests.delete(n),d(null))},8e3);try{const d=await l;if(!d||!Array.isArray(d.suggestions))return[];const x=[];for(const f of d.suggestions)f&&typeof f=="object"&&typeof f.path=="string"&&x.push(f.path);return x}finally{clearTimeout(c)}}async respondElicitation(t,r,n){await F(this.sessionId,{type:"permission_response",approved:r==="accept",request_id:t,response:{subtype:"success",request_id:t,response:{action:r,...n?{content:n}:{}}}})}}function us(s){return s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`}function ms(s){if(!s)return"never";const t=Math.max(0,Date.now()-s);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 xs(s){return s?Date.now()-s<6e4:!1}function ps({onClose:s,session:t,liveStatus:r,pendingPermissions:n,onInterrupt:l,onDelete:c}){const[d,x]=u.useState(!1),f=async()=>{await navigator.clipboard.writeText(t.id),x(!0),setTimeout(()=>x(!1),1500)},m=n.length,p=t.worker,g=t.work_item,v=t.environment;return e.jsx(Ve,{open:!0,onOpenChange:j=>{j||s()},children:e.jsxs(Be,{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(We,{children:e.jsx(Qe,{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(Ut,{className:"h-3.5 w-3.5"}),"Status"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ie,{status:r||t.status||"unknown"}),e.jsx("span",{className:"text-xs text-text-muted",children:p&&(xs(p.last_heartbeat_at)?"· worker online":"· worker offline")})]}),e.jsxs("dl",{className:"space-y-1 text-xs text-text-muted",children:[p&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"h-3 w-3"}),"Heartbeat"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:ms(p.last_heartbeat_at)})]}),v&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(Ye,{className:"h-3 w-3"}),"Environment"]}),e.jsx("dd",{className:"truncate text-text-secondary",children:v.machine_name||v.id})]}),t.created_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"h-3 w-3"}),"Created"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:$e(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(qe,{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(Zt,{className:"h-3.5 w-3.5"}),"Quick Actions"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:l,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"}),e.jsxs("button",{onClick:c,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(mt,{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(Bt,{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:d?"✓":"⧉"})]})]}),g&&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:g.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:g.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})]}),v&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Worker type"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:v.worker_type})]})]})]})]})]})})}const Ee="rcs:subagent-panel:collapsed";function hs(s){if(s<1e3)return"0s";const t=Math.floor(s/1e3);if(t<60)return`${t}s`;const r=Math.floor(t/60),n=t%60;if(r<60)return n?`${r}m${n}s`:`${r}m`;const l=Math.floor(r/60),c=r%60;return c?`${l}h${c}m`:`${l}h`}function fs(s){return s===void 0||s<=0?"":s<1e3?`${s}`:s<1e6?`${(s/1e3).toFixed(s<1e4?1:0)}k`:`${(s/1e6).toFixed(1)}M`}function ys({status:s}){return s==="running"?e.jsx(qe,{className:"h-3 w-3 animate-spin text-brand"}):s==="completed"?e.jsx(Jt,{className:"h-3 w-3 text-status-success"}):s==="failed"||s==="stopped"?e.jsx(xt,{className:"h-3 w-3 text-status-error"}):null}function gs({task:s}){const t=s.status==="running",r=t?s.durationMs??Date.now()-s.startTime:(s.endTime??Date.now())-s.startTime,n=fs(s.tokenCount),l=s.toolUseCount!==void 0&&s.toolUseCount>0?`${s.toolUseCount} tool${s.toolUseCount>1?"s":""}`:"",c=s.summary||s.description||"(no description)";return e.jsxs("div",{className:"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(ys,{status:s.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:s.name}),e.jsx("span",{className:"flex-shrink-0 font-mono text-text-muted",children:hs(r)})]}),e.jsx("div",{className:"mt-0.5 truncate text-text-secondary",children:c}),(n||l||s.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:[n&&e.jsxs("span",{children:["↕ ",n," tok"]}),l&&e.jsxs("span",{children:["· ",l]}),s.lastToolName&&e.jsxs("span",{className:"truncate",children:["· last: ",s.lastToolName]})]}),!t&&s.finalSummary&&e.jsx("div",{className:"mt-1 rounded bg-status-success/10 px-1.5 py-0.5 text-[10px] text-status-success",children:s.finalSummary})]})]})}function bs({state:s}){const[t,r]=u.useState(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Ee)==="1"}catch{return!1}}),n=()=>{r(f=>{const m=!f;try{window.localStorage.setItem(Ee,m?"1":"0")}catch{}return m})},[,l]=u.useState(0);u.useEffect(()=>{const f=Object.values(s.tasks).some(g=>g.status==="running"),m=Object.values(s.tasks).some(g=>g.status!=="running"&&g.evictAfter!==void 0);if(!f&&!m)return;const p=setInterval(()=>{l(g=>g+1)},1e3);return()=>clearInterval(p)},[s]);const c=is(s);if(c.length===0)return null;const d=c.filter(f=>f.status==="running").length,x=d>0?`${d} running`:`${c.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:n,"aria-expanded":!t,"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(Ot,{className:`h-3 w-3 transition-transform ${t?"":"rotate-90"}`}),e.jsx("span",{children:"Subagents"})]}),e.jsx("span",{children:x})]}),!t&&e.jsx("div",{id:"subagent-list",className:"space-y-1.5",children:c.map(f=>e.jsx(gs,{task:f},f.taskId))})]})})}function Te(s,t){var l;const r=(l=t==null?void 0:t.find(c=>c.type==="addRules"||c.type==="replaceRules"))==null?void 0:l.rules,n=r==null?void 0:r[0];return n!=null&&n.ruleContent?`${n.toolName}(${n.ruleContent})`:n!=null&&n.toolName?n.toolName:s}function js({requestId:s,toolName:t,toolInput:r,description:n,suggestions:l,onApprove:c,onApproveAlways:d,onReject:x}){const f=typeof r=="string"?r:JSON.stringify(r,null,2),m=Array.isArray(l)&&l.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(as,{className:"h-3 w-3"})}),e.jsx("span",{className:"text-sm font-semibold text-warning-text",children:"Permission Request"})]}),n&&e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:I(n)}),e.jsx("div",{className:"mb-2 font-mono text-xs font-bold text-text-primary",children:I(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:Ne(f,500)}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:c,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light transition-colors",children:"Approve"}),m&&d&&e.jsxs("button",{onClick:d,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:`允许并记住规则:${Te(t,l)}`,children:[e.jsx(ns,{className:"h-3.5 w-3.5"}),"Always allow ",Ne(Te(t,l),40)]}),e.jsx("button",{onClick:x,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 ks({questions:s,description:t,onSubmit:r,onSkip:n}){const[l,c]=u.useState({}),[d,x]=u.useState({}),[f,m]=u.useState(0),p=(a,i,y)=>{if(y){const b=l[a]||[],k=b.includes(i)?b.filter(_=>_!==i):[...b,i];c({...l,[a]:k})}else c({...l,[a]:i})},g=a=>{var y;const i=(y=d[a])==null?void 0:y.trim();i&&(c({...l,[a]:i}),x({...d,[a]:""}))},v=()=>{var i,y;const a={};for(const[b,k]of Object.entries(l)){const _=s[parseInt(b,10)];_&&(typeof k=="number"?a[b]=((y=(i=_.options)==null?void 0:i[k])==null?void 0:y.label)||String(k):Array.isArray(k)?a[b]=k.map(S=>{var R,A;return((A=(R=_.options)==null?void 0:R[S])==null?void 0:A.label)||String(S)}):a[b]=k)}r(a)};if(s.length<=1){const a=s[0]||{question:t,options:[],multiSelect:!1},i=a.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:I(t||a.question||"Question")}),e.jsxs("div",{className:"space-y-2",children:[(a.options||[]).map((y,b)=>{const k=i?(l[0]||[]).includes(b):l[0]===b;return e.jsxs("button",{onClick:()=>p(0,b,i),className:G("w-full rounded-lg border px-4 py-2.5 text-left text-sm transition-colors",k?"border-brand bg-brand/10 text-text-primary":"border-border bg-surface-2 text-text-secondary hover:border-border-light"),children:[e.jsx("div",{className:"font-medium",children:I(y.label)}),y.description&&e.jsx("div",{className:"mt-0.5 text-xs text-text-muted",children:I(y.description)})]},b)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:d[0]||"",onChange:y=>x({...d,0: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"&&g(0)}),e.jsx("button",{onClick:()=>g(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:n,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})}const j=s[f];return e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx("div",{className:"mb-3 text-sm font-semibold text-text-primary",children:I(t||"Questions")}),e.jsx("div",{className:"mb-3 flex gap-1 overflow-x-auto",children:s.map((a,i)=>e.jsx("button",{onClick:()=>m(i),className:G("rounded-md px-3 py-1.5 text-xs whitespace-nowrap transition-colors",f===i?"bg-brand/20 text-brand":"text-text-muted hover:bg-surface-2"),children:a.header||`Q${i+1}`},i))}),j&&e.jsx(ws,{question:j,qIdx:f,answers:l,otherTexts:d,onSelect:p,onOtherTextChange:(a,i)=>x({...d,[a]:i}),onOtherSubmit:g}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-text-muted",children:[f+1," / ",s.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:n,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})]})}function ws({question:s,qIdx:t,answers:r,otherTexts:n,onSelect:l,onOtherTextChange:c,onOtherSubmit:d}){const x=s.multiSelect||!1;return e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:I(s.question)}),e.jsxs("div",{className:"space-y-2",children:[(s.options||[]).map((f,m)=>{const p=x?(r[t]||[]).includes(m):r[t]===m;return e.jsxs("button",{onClick:()=>l(t,m,x),className:G("w-full rounded-lg border px-4 py-2.5 text-left text-sm transition-colors",p?"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:I(f.label)}),f.description&&e.jsx("div",{className:"mt-0.5 text-xs text-text-muted",children:I(f.description)})]},m)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n[t]||"",onChange:f=>c(t,f.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:f=>f.key==="Enter"&&d(t)}),e.jsx("button",{onClick:()=>d(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 Ns({planContent:s,description:t,onSubmit:r}){const[n,l]=u.useState(null),[c,d]=u.useState(""),x=!s||!s.trim(),f=()=>{n&&r(n,n==="no"?c: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(Pe,{className:"h-3 w-3",strokeWidth:2.5})}),e.jsx("span",{className:"text-sm font-semibold text-text-primary",children:x?"Exit plan mode?":"Ready to code?"})]}),!x&&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:vs(s)}}),e.jsx("div",{className:"space-y-2",children:x?e.jsxs(e.Fragment,{children:[e.jsx(K,{selected:n==="yes-default",onClick:()=>l("yes-default"),label:"Yes"}),e.jsx(K,{selected:n==="no",onClick:()=>l("no"),label:"No"})]}):e.jsxs(e.Fragment,{children:[e.jsx(K,{selected:n==="yes-accept-edits",onClick:()=>l("yes-accept-edits"),label:"Yes, auto-accept edits",desc:"Approve plan and auto-accept file edits"}),e.jsx(K,{selected:n==="yes-default",onClick:()=>l("yes-default"),label:"Yes, manually approve edits",desc:"Approve plan but confirm each edit"}),e.jsx(K,{selected:n==="no",onClick:()=>l("no"),label:"No, keep planning",desc:"Provide feedback to refine the plan"})]})}),n==="no"&&e.jsx("textarea",{value:c,onChange:m=>d(m.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:f,disabled:!n,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 K({selected:s,onClick:t,label:r,desc:n}){return e.jsxs("button",{onClick:t,className:G("w-full rounded-lg border px-4 py-2.5 text-left text-sm transition-colors",s?"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:G("flex h-4 w-4 items-center justify-center rounded-full border text-[10px] transition-colors",s?"border-brand bg-brand text-white":"border-border"),children:s&&"✓"}),e.jsx("span",{className:"font-medium",children:r})]}),n&&e.jsx("div",{className:"mt-0.5 pl-6 text-xs text-text-muted",children:n})]})}function vs(s){let t=I(s);return t=t.replace(/```(\w*)\n?([\s\S]*?)```/g,(r,n,l)=>`<pre class="my-2 overflow-x-auto rounded-lg bg-tool-card p-3 font-mono text-xs">${l.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 _s({request:s,onSubmit:t}){const r=Ss(s.requestedSchema),n=Cs(s.requestedSchema),[l,c]=u.useState({}),d=r.length===0||n.every(x=>(l[x]??"").trim()!=="");return s.mode==="url"&&s.url?e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx(Re,{serverName:s.serverName,message:s.message}),e.jsxs("a",{href:s.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:s.url}),e.jsx(zt,{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(Re,{serverName:s.serverName,message:s.message}),r.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:r.map(({name:x,prop:f})=>e.jsxs("label",{className:"block",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs font-medium text-text-primary",children:x}),n.includes(x)&&e.jsx("span",{className:"text-[10px] font-medium text-warning-text",children:"必填"})]}),f.description&&e.jsx("div",{className:"mb-1 text-xs text-text-muted",children:I(f.description)}),e.jsx("input",{type:f.type==="number"?"number":"text",value:l[x]??"",onChange:m=>c(p=>({...p,[x]:m.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"})]},x))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{const x={};for(const{name:f,prop:m}of r){const p=(l[f]??"").trim();p&&(x[f]=m.type==="number"?Number(p):p)}t("accept",x)},disabled:!d,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 Re({serverName:s,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(Kt,{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:I(s)})]})]}),t&&e.jsx("div",{className:"text-sm text-text-secondary",children:I(t)})]})}function Ss(s){const t=s==null?void 0:s.properties;return!t||typeof t!="object"?[]:Object.entries(t).filter(([,r])=>r&&typeof r=="object").map(([r,n])=>({name:r,prop:n}))}function Cs(s){const t=s==null?void 0:s.required;return Array.isArray(t)?t.filter(r=>typeof r=="string"):[]}function Ms(s){const[t,r]=u.useState([]),[n,l]=u.useState(!0),[c,d]=u.useState(null),x=u.useCallback(async()=>{l(!0),d(null);try{const p=await pt(s);r(p)}catch(p){d(p instanceof Error?p.message:"Failed to load shares")}finally{l(!1)}},[s]);u.useEffect(()=>{x()},[x]);const f=u.useCallback(async p=>{d(null);try{const g=await ht(s,p);return await x(),g}catch(g){throw d(g instanceof Error?g.message:"Failed to create share"),g}},[s,x]),m=u.useCallback(async p=>{d(null);try{await ft(s,p),await x()}catch(g){throw d(g instanceof Error?g.message:"Failed to revoke share"),g}},[s,x]);return{shares:t,isLoading:n,error:c,createShare:f,revokeShare:m,refresh:x}}function Es({open:s,onClose:t,sessionId:r,sessionTitle:n}){De();const{shares:l,isLoading:c,error:d,createShare:x,revokeShare:f}=Ms(r),[m,p]=u.useState("user"),[g,v]=u.useState(""),[j,a]=u.useState(""),[i,y]=u.useState("read"),[b,k]=u.useState(""),[_,S]=u.useState(!1),[R,A]=u.useState(null),[H,q]=u.useState(""),[B,P]=u.useState(!1),[J,O]=u.useState(!1);u.useEffect(()=>{s&&(p("user"),v(""),a(""),y("read"),k(""),S(!1),A(null),q(""),P(!1),O(!1))},[s]);const W=async()=>{S(!0),q(""),A(null);try{const C={grantedTo:m==="user"?{userId:g.trim()}:{teamId:j.trim()},permission:i};b.trim()&&(C.expiresAt=b.trim());const Z=await x(C);A(`${window.location.origin}/code/s/${Z.shareToken}`)}catch(C){q(C instanceof Error?C.message:"Failed to create share")}finally{S(!1)}},X=async C=>{try{await f(C)}catch{}},Q=async()=>{if(!R)return;O(!1);try{if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(R),P(!0),setTimeout(()=>P(!1),2e3);return}}catch{}const C=document.createElement("textarea");C.value=R,C.style.position="fixed",C.style.opacity="0",document.body.appendChild(C),C.select();try{document.execCommand("copy"),P(!0),setTimeout(()=>P(!1),2e3)}catch{O(!0)}document.body.removeChild(C)};return e.jsx(Ve,{open:s,onOpenChange:C=>{C||t()},children:e.jsxs(Be,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(We,{children:e.jsxs(Qe,{className:"font-display text-lg font-semibold text-text-primary",children:[N("share.title"),n?`: ${n}`:""]})}),e.jsxs("div",{className:"space-y-4 min-w-0",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:N("share.grantTo")}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("button",{onClick:()=>p("user"),className:`rounded-md px-3 py-1 text-sm transition-colors ${m==="user"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:N("share.user")}),e.jsx("button",{onClick:()=>p("team"),className:`rounded-md px-3 py-1 text-sm transition-colors ${m==="team"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:N("share.team")})]}),m==="user"?e.jsx(Pt,{onSelect:v,placeholder:N("share.userIdPlaceholder"),actionLabel:N("share.selectUser")}):e.jsx("input",{type:"text",value:j,onChange:C=>a(C.target.value),placeholder:N("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"}),m==="user"&&g&&e.jsxs("p",{className:"mt-1 text-xs text-text-muted",children:[N("share.selectedUser"),": ",e.jsx("span",{className:"font-mono",children:g})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:N("share.permission")}),e.jsxs("select",{value:i,onChange:C=>y(C.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:N("share.permissionRead")}),e.jsx("option",{value:"write",children:N("share.permissionWrite")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:N("share.expiresAt")}),e.jsx("input",{type:"datetime-local",value:b,onChange:C=>k(C.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"})]}),(H||d)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:H||d}),R&&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:N("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:R}),e.jsx("button",{onClick:Q,className:"shrink-0 rounded-md bg-brand px-2 py-1 text-xs text-white hover:bg-brand-light transition-colors",children:B?N("share.copied"):N("share.copy")})]}),J&&e.jsx("p",{className:"mt-1 text-xs text-status-error",children:N("share.copyFailed")})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"mb-2 text-sm font-medium text-text-secondary",children:N("share.existingShares")}),c?e.jsx("p",{className:"text-sm text-text-muted",children:N("share.loading")}):l.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:N("share.none")}):e.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto",children:l.map(C=>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:C.granted_to_user||C.granted_to_team||"Unknown"}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[C.permission==="write"?N("share.permissionWrite"):N("share.permissionRead"),C.expires_at?` · expires ${C.expires_at}`:""]})]}),e.jsx("button",{onClick:()=>X(C.id),className:"shrink-0 rounded-md px-2 py-1 text-xs text-status-error hover:bg-surface-3 transition-colors",children:N("share.revoke")})]},C.id))})]})]}),e.jsxs($t,{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:N("common.close")}),e.jsx("button",{onClick:W,disabled:_||(m==="user"?!g.trim():!j.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:_?N("common.creating"):N("share.createShare")})]})]})})}function Ts(s){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/acp/relay/${s}`}function Rs(s){const t=Ts(s),r=gt(),n=r?{proxyUrl:t,token:r}:{proxyUrl:t};return new yt(n)}const V=[{value:"default",label:"默认",description:"手动审批权限请求"},{value:"acceptEdits",label:"自动接受编辑",description:"自动允许文件编辑操作"},{value:"plan",label:"规划模式",description:"仅规划,不执行工具"},{value:"bypassPermissions",label:"跳过权限",description:"跳过所有权限检查"}],oe="rcs_permission_mode";function Ae(s){return s<1e3?String(s):s<1e6?`${(s/1e3).toFixed(1)}k`:`${(s/1e6).toFixed(1)}M`}function As(s){const t=V.findIndex(r=>r.value===s);return V[(t+1+V.length)%V.length].value}function Is({models:s,currentModelId:t,onSelect:r,disabled:n}){const[l,c]=u.useState(!1),d=s.find(m=>m.modelId===t)??null,x=s.length>0,f=async m=>{r(m.modelId),c(!1)};return e.jsxs(Fe,{open:l,onOpenChange:x?c:void 0,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:n||!x,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(Ye,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-32 truncate",children:(d==null?void 0:d.name)??t??"选择模型"}),l?e.jsx(Le,{className:"h-3 w-3"}):e.jsx(He,{className:"h-3 w-3"})]})}),e.jsx(ze,{className:"w-72 p-0",align:"start",children:e.jsx(At,{models:s,currentModelId:t,onSelect:f,showSearch:s.length>5})})]})}function $s({mode:s,onModeChange:t,disabled:r}){const[n,l]=u.useState(!1),c=V.find(d=>d.value===s);return e.jsxs(Fe,{open:n,onOpenChange:l,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:r,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(Rt,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:(c==null?void 0:c.label)??s}),n?e.jsx(Le,{className:"h-3 w-3"}):e.jsx(He,{className:"h-3 w-3"})]})}),e.jsx(ze,{className:"w-64 p-1",align:"start",children:V.map(d=>e.jsxs("button",{type:"button",onClick:()=>{t(d.value),l(!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:s===d.value&&e.jsx(Pe,{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:d.label}),e.jsx("div",{className:"text-xs text-text-muted",children:d.description})]})]},d.value))})]})}function Bs({sessionId:s,onSessionLoaded:t}){De();const[r,n]=u.useState(null),[l,c]=u.useState(null),[d,x]=u.useState(""),[f,m]=u.useState(!1),[p,g]=u.useState(!1),[v,j]=u.useState(!1),[a,i]=u.useState([]),[y,b]=u.useState(!1),[k,_]=u.useState([]),[S,R]=u.useState(null),[A,H]=u.useState(()=>Ke()),[q,B]=u.useState(null),[P,J]=u.useState(null),[O,W]=u.useState([]),[X,Q]=u.useState(!1),[C,Z]=u.useState(""),ie=u.useRef(null),[le,ee]=u.useState(()=>localStorage.getItem(oe)||"default"),[fe,ye]=u.useState(null),Y=u.useRef(null),U=u.useRef(le);U.current=le;const te=u.useRef(null),ge=u.useRef(null),be=u.useRef(a);be.current=a;const se=u.useRef(t);se.current=t;const ne=u.useCallback(o=>{ye(o),Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>ye(null),5e3)},[]),ce=u.useCallback(o=>{var M;if(o===U.current)return;const h=U.current;U.current=o,ee(o);try{localStorage.setItem(oe,o)}catch{}(M=ge.current)==null||M.setPermissionMode(o).then(w=>{te.current={requestId:w,previous:h}}).catch(w=>{console.error("[SessionDetail] set permission mode failed:",w),ne(`模式切换请求发送失败: ${w instanceof Error?w.message:String(w)}`),U.current=h,ee(h)})},[ne]),T=u.useMemo(()=>new ds(s,i,{onStatusChange:o=>{c(o),b(o==="running"||o==="requires_action")},onError:o=>{console.error("[RCSChatAdapter] error:",o)},onPermissionRequest:o=>{_(h=>h.some(M=>M.requestId===o.requestId)?h:[...h,o])},onModelsStateChange:o=>{R(o)},onSubagentUpdate:o=>{H(o)},onControlResponse:o=>{const h=te.current;if(!(!h||h.requestId!==o.requestId)&&(te.current=null,o.subtype==="error")){U.current=h.previous,ee(h.previous);try{localStorage.setItem(oe,h.previous)}catch{}ne(o.error||"模式切换失败")}},onPermissionModeChange:o=>{if(o!==U.current){U.current=o,ee(o);try{localStorage.setItem(oe,o)}catch{}te.current=null}},onUsageChange:o=>{B(h=>({inputTokens:Math.max((h==null?void 0:h.inputTokens)??0,o.inputTokens),outputTokens:Math.max((h==null?void 0:h.outputTokens)??0,o.outputTokens),totalCostUsd:o.totalCostUsd??(h==null?void 0:h.totalCostUsd)??null}))},onElicitationRequest:o=>{J(o)}}),[s,ne]);u.useEffect(()=>(ge.current=T,()=>{T.disconnect()}),[T]),u.useEffect(()=>{let o=!1;async function h(){var M;x("");try{const w=await Ct(s);if(o)return;n(w),c(w.status),b(w.status==="running"||w.status==="requires_action"),(M=se.current)==null||M.call(se,w)}catch(w){if(o)return;x(w instanceof Error?w.message:N("session.loadFailed"));return}try{await T.init()}catch(w){console.warn("Failed to init adapter:",w)}}return h(),()=>{o=!0}},[s,T]);const z=Mt(l),L=(r==null?void 0:r.access_level)==="read",de=u.useCallback(()=>{i([]),bt(s).catch(o=>{console.warn("[SessionDetail] Failed to clear session history:",o)})},[s]),re=u.useCallback(async o=>{const h=o.text.trim(),M=o.images&&o.images.length>0||o.attachments&&o.attachments.length>0;if(!h&&!M||z)return;const w=await jt(h,{sessionId:s,availableCommands:ve,availableModels:(S==null?void 0:S.availableModels)??[],currentModel:S?{modelId:S.currentModelId,name:S.currentModelId}:null,supportsImages:!0,entries:be.current,setModel:async D=>{await F(s,{type:"control_request",request:{subtype:"set_model",model:D}}),R(me=>me&&{...me,currentModelId:D})},onNewSession:()=>{i([])}}).catch(()=>null);if(w){if(kt("[SessionDetail] local command result",w),"clearEntries"in w&&w.clearEntries){de();return}if("newSession"in w&&w.newSession){de();return}if("userEntry"in w){i(D=>[...D,w.userEntry,w.cmdEntry]);return}}b(!0);try{await T.sendMessage(h,o.images,o.attachments)}catch(D){console.error("Send failed:",D)}},[T,z,s,S,de]),Ge=u.useCallback(o=>{if(y){W(h=>[...h,o]);return}re(o)},[y,re]),ue=u.useRef(!1);u.useEffect(()=>{if(y||O.length===0||ue.current)return;const o=O[0];o&&(ue.current=!0,W(h=>h.slice(1)),re(o).finally(()=>{ue.current=!1}))},[y,O,re]);const je=u.useCallback(async()=>{try{await T.interrupt()}catch(o){console.error("Interrupt failed:",o)}finally{b(!1)}},[T]),Je=u.useCallback(()=>{ce(As(U.current))},[ce]);u.useEffect(()=>()=>{Y.current&&clearTimeout(Y.current)},[]);const Xe=u.useCallback(async()=>{if(r&&window.confirm(N("dashboard.confirmDelete").replace("{id}",r.title||r.id)))try{await wt(r.id),window.location.href="/code/"}catch(o){alert(o instanceof Error?o.message:N("dashboard.deleteFailed"))}},[r]),Ze=u.useCallback(async o=>{try{await T.respondPermission(o,!0)}catch(h){console.error("Failed to approve:",h)}_(h=>h.filter(M=>M.requestId!==o))},[T]),et=u.useCallback(async(o,h)=>{try{await T.respondPermission(o,!0,{updated_permissions:h})}catch(M){console.error("Failed to approve with rules:",M)}_(M=>M.filter(w=>w.requestId!==o))},[T]),tt=u.useCallback(async(o,h)=>{const M=P;if(J(null),!!M)try{await T.respondElicitation(M.requestId,o,h)}catch(w){console.error("Failed to submit elicitation:",w)}},[P,T]),st=u.useCallback(()=>{!r||L||(Z(r.title||""),Q(!0),setTimeout(()=>{var o,h;(o=ie.current)==null||o.focus(),(h=ie.current)==null||h.select()},0))},[r,L]),ke=u.useCallback(async()=>{const o=C.trim();if(Q(!1),!(!r||!o||o===r.title))try{const h=await Nt(r.id,o);n(M=>M&&{...M,title:h.title??o})}catch(h){console.error("Rename failed:",h),alert(h instanceof Error?h.message:"重命名失败")}},[r,C]),nt=u.useCallback(async o=>{try{await T.respondPermission(o,!1)}catch(h){console.error("Failed to reject:",h)}_(h=>h.filter(M=>M.requestId!==o))},[T]),rt=u.useCallback(async(o,h,M)=>{try{await F(s,{type:"permission_response",approved:!0,request_id:o,updated_input:{questions:M,answers:h}})}catch(w){console.error("Failed to submit answers:",w)}_(w=>w.filter(D=>D.requestId!==o))},[s]),at=u.useCallback(async(o,h,M)=>{try{h==="no"?await F(s,{type:"permission_response",approved:!1,request_id:o,...M?{message:M}:{}}):await F(s,{type:"permission_response",approved:!0,request_id:o,updated_permissions:[{type:"setMode",mode:{"yes-accept-edits":"acceptEdits","yes-default":"default"}[h]||"default",destination:"session"}]})}catch(w){console.error("Failed to submit plan response:",w)}_(w=>w.filter(D=>D.requestId!==o))},[s]);return d?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:d}),e.jsx("a",{href:"/code/",className:"mt-4 inline-block text-brand hover:underline",children:N("session.backToDashboard")})]})}):r?r.source==="acp"&&r.environment_id?e.jsx(Ps,{sessionId:s,agentId:r.environment_id}):e.jsx(Ue,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx("h1",{className:"sr-only",children:r.title||r.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:[X?e.jsx("input",{ref:ie,value:C,onChange:o=>Z(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.nativeEvent.isComposing?(o.preventDefault(),ke()):o.key==="Escape"&&(o.preventDefault(),Q(!1))},onBlur:()=>void ke(),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:r.title||r.id}),!L&&!z&&e.jsx("button",{type:"button",onClick:st,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(vt,{className:"h-3.5 w-3.5"})})]}),r.visibility&&!X&&e.jsx(qt,{visibility:r.visibility||"private"})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:[(()=>{var M;const o=r.source==="acp"?"acp":(M=r.environment)==null?void 0:M.worker_type,h=It(o);return e.jsx("span",{className:`rounded-full px-2 py-0.5 text-xs font-medium ${h.colorClass}`,children:h.fullLabel})})(),l&&e.jsx(Ie,{status:l}),e.jsx("span",{className:"text-xs text-text-muted",children:$e(r.created_at)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!L&&(r==null?void 0:r.access_level)!=="write"&&e.jsx("button",{onClick:()=>j(!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:N("session.share"),children:e.jsx(ts,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>g(!p),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:N("session.info"),children:e.jsx(Qt,{className:"h-3.5 w-3.5"})}),e.jsxs("button",{onClick:()=>m(!f),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:[N("session.tasks"),k.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:k.length})]})]})]}),p&&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:N("session.metaSession")})," ",r.id]}),r.environment_id&&e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:N("session.metaEnvironment")})," ",r.environment_id]})]})]})}),e.jsx(_t,{entries:a,isLoading:y,emptyTitle:N("session.emptyTitle"),emptyDescription:N("session.emptyDescription")}),e.jsx(bs,{state:A}),k.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:k.map(o=>e.jsx(qs,{request:o,onApprove:()=>Ze(o.requestId),onApproveAlways:o.suggestions&&o.suggestions.length>0?()=>et(o.requestId,o.suggestions??[]):void 0,onReject:()=>nt(o.requestId),onSubmitAnswers:rt,onSubmitPlan:at},o.requestId))})}),P&&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(_s,{request:P,onSubmit:tt})})}),fe&&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:fe})}),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($s,{mode:le,onModeChange:ce,disabled:z||L}),e.jsx(Is,{models:(S==null?void 0:S.availableModels)??[],currentModelId:(S==null?void 0:S.currentModelId)??null,onSelect:o=>{F(s,{type:"control_request",request:{subtype:"set_model",model:o}}),R(h=>h&&{...h,currentModelId:o})},disabled:z||L})]}),q&&e.jsxs("span",{className:"text-[11px] text-text-muted font-mono",title:"会话累计用量(input 含缓存读写)",children:[Ae(q.inputTokens)," in / ",Ae(q.outputTokens)," out",q.totalCostUsd!=null&&` · $${q.totalCostUsd.toFixed(2)}`]})]}),e.jsx(St,{onSubmit:Ge,isLoading:y,onInterrupt:je,onCycleMode:Je,disabled:z||L,placeholder:z?N("session.closed"):L?N("session.readOnly"):N("session.inputPlaceholder"),supportsAttachments:!0,commands:ve,queueWhileLoading:!0,queuedCount:O.length,onDequeue:o=>W(h=>h.filter((M,w)=>w!==o)),onSearchFiles:o=>T.searchFiles(o)}),f&&r&&e.jsx(ps,{onClose:()=>m(!1),session:r,liveStatus:l,pendingPermissions:k,onInterrupt:je,onDelete:Xe}),e.jsx(Es,{open:v,onClose:()=>j(!1),sessionId:r.id,sessionTitle:r.title||void 0})]})}):e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx("div",{className:"text-text-muted",children:N("session.loading")})})}function qs({request:s,onApprove:t,onApproveAlways:r,onReject:n,onSubmitAnswers:l,onSubmitPlan:c}){const d=s.toolName,x=s.toolInput,f=s.description||"";if(d==="AskUserQuestion"){const m=x.questions||[];return e.jsx(ks,{requestId:s.requestId,questions:m,description:f,onSubmit:p=>l(s.requestId,p,m),onSkip:n})}if(d==="ExitPlanMode"){const m=x.plan||"";return e.jsx(Ns,{requestId:s.requestId,planContent:m,description:f,onSubmit:(p,g)=>c(s.requestId,p,g)})}return e.jsx(js,{requestId:s.requestId,toolName:d,toolInput:x,description:f,suggestions:s.suggestions,onApprove:t,onApproveAlways:r,onReject:n})}function Ps({sessionId:s,agentId:t}){const[r,n]=u.useState(null),[l,c]=u.useState("disconnected"),[d,x]=u.useState(null),f=u.useRef(null);return u.useEffect(()=>{const m=Rs(t);return m.setConnectionStateHandler((p,g)=>{c(p),x(g||null)}),f.current=m,n(m),m.connect().catch(p=>{p instanceof Et||(x(p.message),c("error"))}),()=>{m.disconnect(),f.current=null,n(null),c("disconnected")}},[t]),e.jsx(Ue,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[d&&l==="error"&&e.jsx("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm border-b",children:d}),l==="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:N("session.connectingAgent")})]})}),l==="error"&&!r&&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:N("session.connectionFailed")}),e.jsx("p",{className:"text-text-muted text-sm",children:d})]})}),r&&l==="connected"&&e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Tt,{client:r,agentId:t})})]})})}export{Bs as SessionDetail};
63
+ ${j}
64
+ \`\`\``})}else if(m.kind==="directory"){const g=`📁 目录: ${m.name}${m.files!=null?` (${m.files.length} 个文件)`:""}`,j=m.textContent||"(空目录)";x.push({type:"text",text:`${g}
65
+ ${j}`})}}const p=x.length===1&&x[0].type==="text"?x[0].text||t:x.length>0?x:t;await dt(this.sessionId,{type:"user",uuid:xe(),content:t,message:{content:p}})}async respondPermission(t,r,n){await F(this.sessionId,{type:"permission_response",approved:r,request_id:t,...n}),this.setEntries(l=>l.map(c=>{var d;return c.type!=="tool_call"||((d=c.toolCall.permissionRequest)==null?void 0:d.requestId)!==t?c:{type:"tool_call",toolCall:{...c.toolCall,status:r?"running":"rejected",permissionRequest:void 0}}}))}async interrupt(){this.setEntries(t=>t.map(r=>r.type!=="tool_call"||r.toolCall.status!=="running"&&r.toolCall.status!=="waiting_for_confirmation"?r:{type:"tool_call",toolCall:{...r.toolCall,status:"canceled",permissionRequest:void 0}})),await ut(this.sessionId)}async setPermissionMode(t){const r=xe();return await F(this.sessionId,{type:"control_request",request_id:r,request:{subtype:"set_permission_mode",mode:t}}),r}async searchFiles(t,r=20){const n=xe(),l=new Promise(d=>{this.pendingControlRequests.set(n,d)});await F(this.sessionId,{type:"control_request",request_id:n,request:{subtype:"file_search",query:t,limit:r}});const c=setTimeout(()=>{const d=this.pendingControlRequests.get(n);d&&(this.pendingControlRequests.delete(n),d(null))},8e3);try{const d=await l;if(!d||!Array.isArray(d.suggestions))return[];const x=[];for(const p of d.suggestions)p&&typeof p=="object"&&typeof p.path=="string"&&x.push(p.path);return x}finally{clearTimeout(c)}}async respondElicitation(t,r,n){await F(this.sessionId,{type:"permission_response",approved:r==="accept",request_id:t,response:{subtype:"success",request_id:t,response:{action:r,...n?{content:n}:{}}}})}}function us(s){return s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`}function ms(s){if(!s)return"never";const t=Math.max(0,Date.now()-s);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 xs(s){return s?Date.now()-s<6e4:!1}function ps({onClose:s,session:t,liveStatus:r,pendingPermissions:n,onInterrupt:l,onDelete:c}){const[d,x]=u.useState(!1),p=async()=>{await navigator.clipboard.writeText(t.id),x(!0),setTimeout(()=>x(!1),1500)},m=n.length,g=t.worker,j=t.work_item,k=t.environment;return e.jsx(Ve,{open:!0,onOpenChange:S=>{S||s()},children:e.jsxs(Be,{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(We,{children:e.jsx(Qe,{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(Ut,{className:"h-3.5 w-3.5"}),"Status"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ie,{status:r||t.status||"unknown"}),e.jsx("span",{className:"text-xs text-text-muted",children:g&&(xs(g.last_heartbeat_at)?"· worker online":"· worker offline")})]}),e.jsxs("dl",{className:"space-y-1 text-xs text-text-muted",children:[g&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"h-3 w-3"}),"Heartbeat"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:ms(g.last_heartbeat_at)})]}),k&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(Ye,{className:"h-3 w-3"}),"Environment"]}),e.jsx("dd",{className:"truncate text-text-secondary",children:k.machine_name||k.id})]}),t.created_at&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"h-3 w-3"}),"Created"]}),e.jsx("dd",{className:"font-mono text-text-secondary",children:$e(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(qe,{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(Zt,{className:"h-3.5 w-3.5"}),"Quick Actions"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:l,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"}),e.jsxs("button",{onClick:c,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(mt,{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(Bt,{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:p,className:"text-text-muted hover:text-text-primary transition-colors flex-shrink-0",title:"Copy session id",children:d?"✓":"⧉"})]})]}),j&&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:j.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:j.state})]})]}),t.source&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Source"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:t.source})]}),k&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{children:"Worker type"}),e.jsx("dd",{className:"font-mono text-text-secondary",children:k.worker_type})]})]})]})]})]})})}const Ee="rcs:subagent-panel:collapsed";function hs(s){if(s<1e3)return"0s";const t=Math.floor(s/1e3);if(t<60)return`${t}s`;const r=Math.floor(t/60),n=t%60;if(r<60)return n?`${r}m${n}s`:`${r}m`;const l=Math.floor(r/60),c=r%60;return c?`${l}h${c}m`:`${l}h`}function fs(s){return s===void 0||s<=0?"":s<1e3?`${s}`:s<1e6?`${(s/1e3).toFixed(s<1e4?1:0)}k`:`${(s/1e6).toFixed(1)}M`}function ys({status:s}){return s==="running"?e.jsx(qe,{className:"h-3 w-3 animate-spin text-brand"}):s==="completed"?e.jsx(Jt,{className:"h-3 w-3 text-status-success"}):s==="failed"||s==="stopped"?e.jsx(xt,{className:"h-3 w-3 text-status-error"}):null}function gs({task:s}){const t=s.status==="running",r=t?s.durationMs??Date.now()-s.startTime:(s.endTime??Date.now())-s.startTime,n=fs(s.tokenCount),l=s.toolUseCount!==void 0&&s.toolUseCount>0?`${s.toolUseCount} tool${s.toolUseCount>1?"s":""}`:"",c=s.summary||s.description||"(no description)";return e.jsxs("div",{className:"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(ys,{status:s.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:s.name}),e.jsx("span",{className:"flex-shrink-0 font-mono text-text-muted",children:hs(r)})]}),e.jsx("div",{className:"mt-0.5 truncate text-text-secondary",children:c}),(n||l||s.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:[n&&e.jsxs("span",{children:["↕ ",n," tok"]}),l&&e.jsxs("span",{children:["· ",l]}),s.lastToolName&&e.jsxs("span",{className:"truncate",children:["· last: ",s.lastToolName]})]}),!t&&s.finalSummary&&e.jsx("div",{className:"mt-1 rounded bg-status-success/10 px-1.5 py-0.5 text-[10px] text-status-success",children:s.finalSummary})]})]})}function bs({state:s}){const[t,r]=u.useState(()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Ee)==="1"}catch{return!1}}),n=()=>{r(p=>{const m=!p;try{window.localStorage.setItem(Ee,m?"1":"0")}catch{}return m})},[,l]=u.useState(0);u.useEffect(()=>{const p=Object.values(s.tasks).some(j=>j.status==="running"),m=Object.values(s.tasks).some(j=>j.status!=="running"&&j.evictAfter!==void 0);if(!p&&!m)return;const g=setInterval(()=>{l(j=>j+1)},1e3);return()=>clearInterval(g)},[s]);const c=is(s);if(c.length===0)return null;const d=c.filter(p=>p.status==="running").length,x=d>0?`${d} running`:`${c.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:n,"aria-expanded":!t,"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(Ot,{className:`h-3 w-3 transition-transform ${t?"":"rotate-90"}`}),e.jsx("span",{children:"Subagents"})]}),e.jsx("span",{children:x})]}),!t&&e.jsx("div",{id:"subagent-list",className:"space-y-1.5",children:c.map(p=>e.jsx(gs,{task:p},p.taskId))})]})})}function Te(s,t){var l;const r=(l=t==null?void 0:t.find(c=>c.type==="addRules"||c.type==="replaceRules"))==null?void 0:l.rules,n=r==null?void 0:r[0];return n!=null&&n.ruleContent?`${n.toolName}(${n.ruleContent})`:n!=null&&n.toolName?n.toolName:s}function js({requestId:s,toolName:t,toolInput:r,description:n,suggestions:l,onApprove:c,onApproveAlways:d,onReject:x}){const p=typeof r=="string"?r:JSON.stringify(r,null,2),m=Array.isArray(l)&&l.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(as,{className:"h-3 w-3"})}),e.jsx("span",{className:"text-sm font-semibold text-warning-text",children:"Permission Request"})]}),n&&e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:I(n)}),e.jsx("div",{className:"mb-2 font-mono text-xs font-bold text-text-primary",children:I(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:Ne(p,500)}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:c,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light transition-colors",children:"Approve"}),m&&d&&e.jsxs("button",{onClick:d,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:`允许并记住规则:${Te(t,l)}`,children:[e.jsx(ns,{className:"h-3.5 w-3.5"}),"Always allow ",Ne(Te(t,l),40)]}),e.jsx("button",{onClick:x,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 ks({questions:s,description:t,onSubmit:r,onSkip:n}){const[l,c]=u.useState({}),[d,x]=u.useState({}),[p,m]=u.useState(0),g=(a,o,h)=>{if(h){const y=l[a]||[],b=y.includes(o)?y.filter(w=>w!==o):[...y,o];c({...l,[a]:b})}else c({...l,[a]:o})},j=a=>{var h;const o=(h=d[a])==null?void 0:h.trim();o&&(c({...l,[a]:o}),x({...d,[a]:""}))},k=()=>{var o,h;const a={};for(const[y,b]of Object.entries(l)){const w=s[parseInt(y,10)];w&&(typeof b=="number"?a[y]=((h=(o=w.options)==null?void 0:o[b])==null?void 0:h.label)||String(b):Array.isArray(b)?a[y]=b.map(_=>{var R,A;return((A=(R=w.options)==null?void 0:R[_])==null?void 0:A.label)||String(_)}):a[y]=b)}r(a)};if(s.length<=1){const a=s[0]||{question:t,options:[],multiSelect:!1},o=a.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:I(t||a.question||"Question")}),e.jsxs("div",{className:"space-y-2",children:[(a.options||[]).map((h,y)=>{const b=o?(l[0]||[]).includes(y):l[0]===y;return e.jsxs("button",{onClick:()=>g(0,y,o),className:G("w-full rounded-lg border px-4 py-2.5 text-left text-sm transition-colors",b?"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:I(h.label)}),h.description&&e.jsx("div",{className:"mt-0.5 text-xs text-text-muted",children:I(h.description)})]},y)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:d[0]||"",onChange:h=>x({...d,0:h.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:h=>h.key==="Enter"&&j(0)}),e.jsx("button",{onClick:()=>j(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:k,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:n,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})}const S=s[p];return e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx("div",{className:"mb-3 text-sm font-semibold text-text-primary",children:I(t||"Questions")}),e.jsx("div",{className:"mb-3 flex gap-1 overflow-x-auto",children:s.map((a,o)=>e.jsx("button",{onClick:()=>m(o),className:G("rounded-md px-3 py-1.5 text-xs whitespace-nowrap transition-colors",p===o?"bg-brand/20 text-brand":"text-text-muted hover:bg-surface-2"),children:a.header||`Q${o+1}`},o))}),S&&e.jsx(ws,{question:S,qIdx:p,answers:l,otherTexts:d,onSelect:g,onOtherTextChange:(a,o)=>x({...d,[a]:o}),onOtherSubmit:j}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-text-muted",children:[p+1," / ",s.length]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:k,className:"rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white hover:bg-brand-light transition-colors",children:"Submit All"}),e.jsx("button",{onClick:n,className:"rounded-lg border border-border px-4 py-2 text-sm text-text-secondary hover:bg-surface-2 transition-colors",children:"Skip"})]})]})]})}function ws({question:s,qIdx:t,answers:r,otherTexts:n,onSelect:l,onOtherTextChange:c,onOtherSubmit:d}){const x=s.multiSelect||!1;return e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-sm text-text-secondary",children:I(s.question)}),e.jsxs("div",{className:"space-y-2",children:[(s.options||[]).map((p,m)=>{const g=x?(r[t]||[]).includes(m):r[t]===m;return e.jsxs("button",{onClick:()=>l(t,m,x),className:G("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:I(p.label)}),p.description&&e.jsx("div",{className:"mt-0.5 text-xs text-text-muted",children:I(p.description)})]},m)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n[t]||"",onChange:p=>c(t,p.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:p=>p.key==="Enter"&&d(t)}),e.jsx("button",{onClick:()=>d(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 Ns({planContent:s,description:t,onSubmit:r}){const[n,l]=u.useState(null),[c,d]=u.useState(""),x=!s||!s.trim(),p=()=>{n&&r(n,n==="no"?c: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(Pe,{className:"h-3 w-3",strokeWidth:2.5})}),e.jsx("span",{className:"text-sm font-semibold text-text-primary",children:x?"Exit plan mode?":"Ready to code?"})]}),!x&&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:vs(s)}}),e.jsx("div",{className:"space-y-2",children:x?e.jsxs(e.Fragment,{children:[e.jsx(K,{selected:n==="yes-default",onClick:()=>l("yes-default"),label:"Yes"}),e.jsx(K,{selected:n==="no",onClick:()=>l("no"),label:"No"})]}):e.jsxs(e.Fragment,{children:[e.jsx(K,{selected:n==="yes-accept-edits",onClick:()=>l("yes-accept-edits"),label:"Yes, auto-accept edits",desc:"Approve plan and auto-accept file edits"}),e.jsx(K,{selected:n==="yes-default",onClick:()=>l("yes-default"),label:"Yes, manually approve edits",desc:"Approve plan but confirm each edit"}),e.jsx(K,{selected:n==="no",onClick:()=>l("no"),label:"No, keep planning",desc:"Provide feedback to refine the plan"})]})}),n==="no"&&e.jsx("textarea",{value:c,onChange:m=>d(m.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:p,disabled:!n,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 K({selected:s,onClick:t,label:r,desc:n}){return e.jsxs("button",{onClick:t,className:G("w-full rounded-lg border px-4 py-2.5 text-left text-sm transition-colors",s?"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:G("flex h-4 w-4 items-center justify-center rounded-full border text-[10px] transition-colors",s?"border-brand bg-brand text-white":"border-border"),children:s&&"✓"}),e.jsx("span",{className:"font-medium",children:r})]}),n&&e.jsx("div",{className:"mt-0.5 pl-6 text-xs text-text-muted",children:n})]})}function vs(s){let t=I(s);return t=t.replace(/```(\w*)\n?([\s\S]*?)```/g,(r,n,l)=>`<pre class="my-2 overflow-x-auto rounded-lg bg-tool-card p-3 font-mono text-xs">${l.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 _s({request:s,onSubmit:t}){const r=Ss(s.requestedSchema),n=Cs(s.requestedSchema),[l,c]=u.useState({}),d=r.length===0||n.every(x=>(l[x]??"").trim()!=="");return s.mode==="url"&&s.url?e.jsxs("div",{className:"rounded-xl border border-brand/30 bg-surface-1 p-4",children:[e.jsx(Re,{serverName:s.serverName,message:s.message}),e.jsxs("a",{href:s.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:s.url}),e.jsx(zt,{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(Re,{serverName:s.serverName,message:s.message}),r.length>0&&e.jsx("div",{className:"mb-3 space-y-3",children:r.map(({name:x,prop:p})=>e.jsxs("label",{className:"block",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs font-medium text-text-primary",children:x}),n.includes(x)&&e.jsx("span",{className:"text-[10px] font-medium text-warning-text",children:"必填"})]}),p.description&&e.jsx("div",{className:"mb-1 text-xs text-text-muted",children:I(p.description)}),e.jsx("input",{type:p.type==="number"?"number":"text",value:l[x]??"",onChange:m=>c(g=>({...g,[x]:m.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"})]},x))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{const x={};for(const{name:p,prop:m}of r){const g=(l[p]??"").trim();g&&(x[p]=m.type==="number"?Number(g):g)}t("accept",x)},disabled:!d,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 Re({serverName:s,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(Kt,{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:I(s)})]})]}),t&&e.jsx("div",{className:"text-sm text-text-secondary",children:I(t)})]})}function Ss(s){const t=s==null?void 0:s.properties;return!t||typeof t!="object"?[]:Object.entries(t).filter(([,r])=>r&&typeof r=="object").map(([r,n])=>({name:r,prop:n}))}function Cs(s){const t=s==null?void 0:s.required;return Array.isArray(t)?t.filter(r=>typeof r=="string"):[]}function Ms(s){const[t,r]=u.useState([]),[n,l]=u.useState(!0),[c,d]=u.useState(null),x=u.useCallback(async()=>{l(!0),d(null);try{const g=await pt(s);r(g)}catch(g){d(g instanceof Error?g.message:"Failed to load shares")}finally{l(!1)}},[s]);u.useEffect(()=>{x()},[x]);const p=u.useCallback(async g=>{d(null);try{const j=await ht(s,g);return await x(),j}catch(j){throw d(j instanceof Error?j.message:"Failed to create share"),j}},[s,x]),m=u.useCallback(async g=>{d(null);try{await ft(s,g),await x()}catch(j){throw d(j instanceof Error?j.message:"Failed to revoke share"),j}},[s,x]);return{shares:t,isLoading:n,error:c,createShare:p,revokeShare:m,refresh:x}}function Es({open:s,onClose:t,sessionId:r,sessionTitle:n}){De();const{shares:l,isLoading:c,error:d,createShare:x,revokeShare:p}=Ms(r),[m,g]=u.useState("user"),[j,k]=u.useState(""),[S,a]=u.useState(""),[o,h]=u.useState("read"),[y,b]=u.useState(""),[w,_]=u.useState(!1),[R,A]=u.useState(null),[H,q]=u.useState(""),[B,P]=u.useState(!1),[J,O]=u.useState(!1);u.useEffect(()=>{s&&(g("user"),k(""),a(""),h("read"),b(""),_(!1),A(null),q(""),P(!1),O(!1))},[s]);const W=async()=>{_(!0),q(""),A(null);try{const C={grantedTo:m==="user"?{userId:j.trim()}:{teamId:S.trim()},permission:o};y.trim()&&(C.expiresAt=y.trim());const Z=await x(C);A(`${window.location.origin}/code/s/${Z.shareToken}`)}catch(C){q(C instanceof Error?C.message:"Failed to create share")}finally{_(!1)}},X=async C=>{try{await p(C)}catch{}},Q=async()=>{if(!R)return;O(!1);try{if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(R),P(!0),setTimeout(()=>P(!1),2e3);return}}catch{}const C=document.createElement("textarea");C.value=R,C.style.position="fixed",C.style.opacity="0",document.body.appendChild(C),C.select();try{document.execCommand("copy"),P(!0),setTimeout(()=>P(!1),2e3)}catch{O(!0)}document.body.removeChild(C)};return e.jsx(Ve,{open:s,onOpenChange:C=>{C||t()},children:e.jsxs(Be,{className:"max-w-lg rounded-2xl border-border bg-surface-1 p-6 shadow-2xl",children:[e.jsx(We,{children:e.jsxs(Qe,{className:"font-display text-lg font-semibold text-text-primary",children:[v("share.title"),n?`: ${n}`:""]})}),e.jsxs("div",{className:"space-y-4 min-w-0",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:v("share.grantTo")}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("button",{onClick:()=>g("user"),className:`rounded-md px-3 py-1 text-sm transition-colors ${m==="user"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:v("share.user")}),e.jsx("button",{onClick:()=>g("team"),className:`rounded-md px-3 py-1 text-sm transition-colors ${m==="team"?"bg-brand text-white":"bg-surface-2 text-text-secondary hover:bg-surface-3"}`,children:v("share.team")})]}),m==="user"?e.jsx(Pt,{onSelect:k,placeholder:v("share.userIdPlaceholder"),actionLabel:v("share.selectUser")}):e.jsx("input",{type:"text",value:S,onChange:C=>a(C.target.value),placeholder:v("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"}),m==="user"&&j&&e.jsxs("p",{className:"mt-1 text-xs text-text-muted",children:[v("share.selectedUser"),": ",e.jsx("span",{className:"font-mono",children:j})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:v("share.permission")}),e.jsxs("select",{value:o,onChange:C=>h(C.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:v("share.permissionRead")}),e.jsx("option",{value:"write",children:v("share.permissionWrite")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm text-text-secondary",children:v("share.expiresAt")}),e.jsx("input",{type:"datetime-local",value:y,onChange:C=>b(C.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"})]}),(H||d)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-status-error",children:H||d}),R&&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:v("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:R}),e.jsx("button",{onClick:Q,className:"shrink-0 rounded-md bg-brand px-2 py-1 text-xs text-white hover:bg-brand-light transition-colors",children:B?v("share.copied"):v("share.copy")})]}),J&&e.jsx("p",{className:"mt-1 text-xs text-status-error",children:v("share.copyFailed")})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"mb-2 text-sm font-medium text-text-secondary",children:v("share.existingShares")}),c?e.jsx("p",{className:"text-sm text-text-muted",children:v("share.loading")}):l.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:v("share.none")}):e.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto",children:l.map(C=>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:C.granted_to_user||C.granted_to_team||"Unknown"}),e.jsxs("p",{className:"truncate text-xs text-text-muted",children:[C.permission==="write"?v("share.permissionWrite"):v("share.permissionRead"),C.expires_at?` · expires ${C.expires_at}`:""]})]}),e.jsx("button",{onClick:()=>X(C.id),className:"shrink-0 rounded-md px-2 py-1 text-xs text-status-error hover:bg-surface-3 transition-colors",children:v("share.revoke")})]},C.id))})]})]}),e.jsxs($t,{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:v("common.close")}),e.jsx("button",{onClick:W,disabled:w||(m==="user"?!j.trim():!S.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:w?v("common.creating"):v("share.createShare")})]})]})})}function Ts(s){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/acp/relay/${s}`}function Rs(s){const t=Ts(s),r=gt(),n=r?{proxyUrl:t,token:r}:{proxyUrl:t};return new yt(n)}const V=[{value:"default",label:"默认",description:"手动审批权限请求"},{value:"acceptEdits",label:"自动接受编辑",description:"自动允许文件编辑操作"},{value:"plan",label:"规划模式",description:"仅规划,不执行工具"},{value:"bypassPermissions",label:"跳过权限",description:"跳过所有权限检查"}],oe="rcs_permission_mode";function Ae(s){return s<1e3?String(s):s<1e6?`${(s/1e3).toFixed(1)}k`:`${(s/1e6).toFixed(1)}M`}function As(s){const t=V.findIndex(r=>r.value===s);return V[(t+1+V.length)%V.length].value}function Is({models:s,currentModelId:t,onSelect:r,disabled:n}){const[l,c]=u.useState(!1),d=s.find(m=>m.modelId===t)??null,x=s.length>0,p=async m=>{r(m.modelId),c(!1)};return e.jsxs(Fe,{open:l,onOpenChange:x?c:void 0,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:n||!x,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(Ye,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-32 truncate",children:(d==null?void 0:d.name)??t??"选择模型"}),l?e.jsx(Le,{className:"h-3 w-3"}):e.jsx(He,{className:"h-3 w-3"})]})}),e.jsx(ze,{className:"w-72 p-0",align:"start",children:e.jsx(At,{models:s,currentModelId:t,onSelect:p,showSearch:s.length>5})})]})}function $s({mode:s,onModeChange:t,disabled:r}){const[n,l]=u.useState(!1),c=V.find(d=>d.value===s);return e.jsxs(Fe,{open:n,onOpenChange:l,children:[e.jsx(Oe,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:r,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(Rt,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-24 truncate",children:(c==null?void 0:c.label)??s}),n?e.jsx(Le,{className:"h-3 w-3"}):e.jsx(He,{className:"h-3 w-3"})]})}),e.jsx(ze,{className:"w-64 p-1",align:"start",children:V.map(d=>e.jsxs("button",{type:"button",onClick:()=>{t(d.value),l(!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:s===d.value&&e.jsx(Pe,{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:d.label}),e.jsx("div",{className:"text-xs text-text-muted",children:d.description})]})]},d.value))})]})}function Bs({sessionId:s,onSessionLoaded:t}){De();const[r,n]=u.useState(null),[l,c]=u.useState(null),[d,x]=u.useState(""),[p,m]=u.useState(!1),[g,j]=u.useState(!1),[k,S]=u.useState(!1),[a,o]=u.useState([]),[h,y]=u.useState(!1),[b,w]=u.useState([]),[_,R]=u.useState(null),[A,H]=u.useState(()=>Ke()),[q,B]=u.useState(null),[P,J]=u.useState(null),[O,W]=u.useState([]),[X,Q]=u.useState(!1),[C,Z]=u.useState(""),ie=u.useRef(null),[le,ee]=u.useState(()=>localStorage.getItem(oe)||"default"),[fe,ye]=u.useState(null),Y=u.useRef(null),U=u.useRef(le);U.current=le;const te=u.useRef(null),ge=u.useRef(null),be=u.useRef(a);be.current=a;const se=u.useRef(t);se.current=t;const ne=u.useCallback(i=>{ye(i),Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>ye(null),5e3)},[]),ce=u.useCallback(i=>{var M;if(i===U.current)return;const f=U.current;U.current=i,ee(i);try{localStorage.setItem(oe,i)}catch{}(M=ge.current)==null||M.setPermissionMode(i).then(N=>{te.current={requestId:N,previous:f}}).catch(N=>{console.error("[SessionDetail] set permission mode failed:",N),ne(`模式切换请求发送失败: ${N instanceof Error?N.message:String(N)}`),U.current=f,ee(f)})},[ne]),T=u.useMemo(()=>new ds(s,o,{onStatusChange:i=>{c(i),y(i==="running"||i==="requires_action")},onError:i=>{console.error("[RCSChatAdapter] error:",i)},onPermissionRequest:i=>{w(f=>f.some(M=>M.requestId===i.requestId)?f:[...f,i])},onModelsStateChange:i=>{R(i)},onSubagentUpdate:i=>{H(i)},onControlResponse:i=>{const f=te.current;if(!(!f||f.requestId!==i.requestId)&&(te.current=null,i.subtype==="error")){U.current=f.previous,ee(f.previous);try{localStorage.setItem(oe,f.previous)}catch{}ne(i.error||"模式切换失败")}},onPermissionModeChange:i=>{if(i!==U.current){U.current=i,ee(i);try{localStorage.setItem(oe,i)}catch{}te.current=null}},onUsageChange:i=>{B(f=>({inputTokens:Math.max((f==null?void 0:f.inputTokens)??0,i.inputTokens),outputTokens:Math.max((f==null?void 0:f.outputTokens)??0,i.outputTokens),totalCostUsd:i.totalCostUsd??(f==null?void 0:f.totalCostUsd)??null}))},onElicitationRequest:i=>{J(i)}}),[s,ne]);u.useEffect(()=>(ge.current=T,()=>{T.disconnect()}),[T]),u.useEffect(()=>{let i=!1;async function f(){var M;x("");try{const N=await Ct(s);if(i)return;n(N),c(N.status),y(N.status==="running"||N.status==="requires_action"),(M=se.current)==null||M.call(se,N)}catch(N){if(i)return;x(N instanceof Error?N.message:v("session.loadFailed"));return}try{await T.init()}catch(N){console.warn("Failed to init adapter:",N)}}return f(),()=>{i=!0}},[s,T]);const z=Mt(l),L=(r==null?void 0:r.access_level)==="read",de=u.useCallback(()=>{o([]),bt(s).catch(i=>{console.warn("[SessionDetail] Failed to clear session history:",i)})},[s]),re=u.useCallback(async i=>{const f=i.text.trim(),M=i.images&&i.images.length>0||i.attachments&&i.attachments.length>0;if(!f&&!M||z)return;const N=await jt(f,{sessionId:s,availableCommands:ve,availableModels:(_==null?void 0:_.availableModels)??[],currentModel:_?{modelId:_.currentModelId,name:_.currentModelId}:null,supportsImages:!0,entries:be.current,setModel:async D=>{await F(s,{type:"control_request",request:{subtype:"set_model",model:D}}),R(me=>me&&{...me,currentModelId:D})},onNewSession:()=>{o([])}}).catch(()=>null);if(N){if(kt("[SessionDetail] local command result",N),"clearEntries"in N&&N.clearEntries){de();return}if("newSession"in N&&N.newSession){de();return}if("userEntry"in N){o(D=>[...D,N.userEntry,N.cmdEntry]);return}}y(!0);try{await T.sendMessage(f,i.images,i.attachments)}catch(D){console.error("Send failed:",D)}},[T,z,s,_,de]),Ge=u.useCallback(i=>{if(h){W(f=>[...f,i]);return}re(i)},[h,re]),ue=u.useRef(!1);u.useEffect(()=>{if(h||O.length===0||ue.current)return;const i=O[0];i&&(ue.current=!0,W(f=>f.slice(1)),re(i).finally(()=>{ue.current=!1}))},[h,O,re]);const je=u.useCallback(async()=>{try{await T.interrupt()}catch(i){console.error("Interrupt failed:",i)}finally{y(!1)}},[T]),Je=u.useCallback(()=>{ce(As(U.current))},[ce]);u.useEffect(()=>()=>{Y.current&&clearTimeout(Y.current)},[]);const Xe=u.useCallback(async()=>{if(r&&window.confirm(v("dashboard.confirmDelete").replace("{id}",r.title||r.id)))try{await wt(r.id),window.location.href="/code/"}catch(i){alert(i instanceof Error?i.message:v("dashboard.deleteFailed"))}},[r]),Ze=u.useCallback(async i=>{try{await T.respondPermission(i,!0)}catch(f){console.error("Failed to approve:",f)}w(f=>f.filter(M=>M.requestId!==i))},[T]),et=u.useCallback(async(i,f)=>{try{await T.respondPermission(i,!0,{updated_permissions:f})}catch(M){console.error("Failed to approve with rules:",M)}w(M=>M.filter(N=>N.requestId!==i))},[T]),tt=u.useCallback(async(i,f)=>{const M=P;if(J(null),!!M)try{await T.respondElicitation(M.requestId,i,f)}catch(N){console.error("Failed to submit elicitation:",N)}},[P,T]),st=u.useCallback(()=>{!r||L||(Z(r.title||""),Q(!0),setTimeout(()=>{var i,f;(i=ie.current)==null||i.focus(),(f=ie.current)==null||f.select()},0))},[r,L]),ke=u.useCallback(async()=>{const i=C.trim();if(Q(!1),!(!r||!i||i===r.title))try{const f=await Nt(r.id,i);n(M=>M&&{...M,title:f.title??i})}catch(f){console.error("Rename failed:",f),alert(f instanceof Error?f.message:"重命名失败")}},[r,C]),nt=u.useCallback(async i=>{try{await T.respondPermission(i,!1)}catch(f){console.error("Failed to reject:",f)}w(f=>f.filter(M=>M.requestId!==i))},[T]),rt=u.useCallback(async(i,f,M)=>{try{await F(s,{type:"permission_response",approved:!0,request_id:i,updated_input:{questions:M,answers:f}})}catch(N){console.error("Failed to submit answers:",N)}w(N=>N.filter(D=>D.requestId!==i))},[s]),at=u.useCallback(async(i,f,M)=>{try{f==="no"?await F(s,{type:"permission_response",approved:!1,request_id:i,...M?{message:M}:{}}):await F(s,{type:"permission_response",approved:!0,request_id:i,updated_permissions:[{type:"setMode",mode:{"yes-accept-edits":"acceptEdits","yes-default":"default"}[f]||"default",destination:"session"}]})}catch(N){console.error("Failed to submit plan response:",N)}w(N=>N.filter(D=>D.requestId!==i))},[s]);return d?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:d}),e.jsx("a",{href:"/code/",className:"mt-4 inline-block text-brand hover:underline",children:v("session.backToDashboard")})]})}):r?r.source==="acp"&&r.environment_id?e.jsx(Ps,{sessionId:s,agentId:r.environment_id}):e.jsx(Ue,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx("h1",{className:"sr-only",children:r.title||r.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:[X?e.jsx("input",{ref:ie,value:C,onChange:i=>Z(i.target.value),onKeyDown:i=>{i.key==="Enter"&&!i.nativeEvent.isComposing?(i.preventDefault(),ke()):i.key==="Escape"&&(i.preventDefault(),Q(!1))},onBlur:()=>void ke(),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:r.title||r.id}),!L&&!z&&e.jsx("button",{type:"button",onClick:st,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(vt,{className:"h-3.5 w-3.5"})})]}),r.visibility&&!X&&e.jsx(qt,{visibility:r.visibility||"private"})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:[(()=>{var M;const i=r.source==="acp"?"acp":(M=r.environment)==null?void 0:M.worker_type,f=It(i);return e.jsx("span",{className:`rounded-full px-2 py-0.5 text-xs font-medium ${f.colorClass}`,children:f.fullLabel})})(),l&&e.jsx(Ie,{status:l}),e.jsx("span",{className:"text-xs text-text-muted",children:$e(r.created_at)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!L&&(r==null?void 0:r.access_level)!=="write"&&e.jsx("button",{onClick:()=>S(!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:v("session.share"),children:e.jsx(ts,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>j(!g),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:v("session.info"),children:e.jsx(Qt,{className:"h-3.5 w-3.5"})}),e.jsxs("button",{onClick:()=>m(!p),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:[v("session.tasks"),b.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:b.length})]})]})]}),g&&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:v("session.metaSession")})," ",r.id]}),r.environment_id&&e.jsxs("div",{children:[e.jsx("span",{className:"text-text-primary font-bold font-sans",children:v("session.metaEnvironment")})," ",r.environment_id]})]})]})}),e.jsx(_t,{entries:a,isLoading:h,emptyTitle:v("session.emptyTitle"),emptyDescription:v("session.emptyDescription")}),e.jsx(bs,{state:A}),b.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:b.map(i=>e.jsx(qs,{request:i,onApprove:()=>Ze(i.requestId),onApproveAlways:i.suggestions&&i.suggestions.length>0?()=>et(i.requestId,i.suggestions??[]):void 0,onReject:()=>nt(i.requestId),onSubmitAnswers:rt,onSubmitPlan:at},i.requestId))})}),P&&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(_s,{request:P,onSubmit:tt})})}),fe&&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:fe})}),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($s,{mode:le,onModeChange:ce,disabled:z||L}),e.jsx(Is,{models:(_==null?void 0:_.availableModels)??[],currentModelId:(_==null?void 0:_.currentModelId)??null,onSelect:i=>{F(s,{type:"control_request",request:{subtype:"set_model",model:i}}),R(f=>f&&{...f,currentModelId:i})},disabled:z||L})]}),q&&e.jsxs("span",{className:"text-[11px] text-text-muted font-mono",title:"会话累计用量(input 含缓存读写)",children:[Ae(q.inputTokens)," in / ",Ae(q.outputTokens)," out",q.totalCostUsd!=null&&` · $${q.totalCostUsd.toFixed(2)}`]})]}),e.jsx(St,{onSubmit:Ge,isLoading:h,onInterrupt:je,onCycleMode:Je,disabled:z||L,placeholder:z?v("session.closed"):L?v("session.readOnly"):v("session.inputPlaceholder"),supportsAttachments:!0,commands:ve,queueWhileLoading:!0,queuedCount:O.length,onDequeue:i=>W(f=>f.filter((M,N)=>N!==i)),onSearchFiles:i=>T.searchFiles(i)}),p&&r&&e.jsx(ps,{onClose:()=>m(!1),session:r,liveStatus:l,pendingPermissions:b,onInterrupt:je,onDelete:Xe}),e.jsx(Es,{open:k,onClose:()=>S(!1),sessionId:r.id,sessionTitle:r.title||void 0})]})}):e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx("div",{className:"text-text-muted",children:v("session.loading")})})}function qs({request:s,onApprove:t,onApproveAlways:r,onReject:n,onSubmitAnswers:l,onSubmitPlan:c}){const d=s.toolName,x=s.toolInput,p=s.description||"";if(d==="AskUserQuestion"){const m=x.questions||[];return e.jsx(ks,{requestId:s.requestId,questions:m,description:p,onSubmit:g=>l(s.requestId,g,m),onSkip:n})}if(d==="ExitPlanMode"){const m=x.plan||"";return e.jsx(Ns,{requestId:s.requestId,planContent:m,description:p,onSubmit:(g,j)=>c(s.requestId,g,j)})}return e.jsx(js,{requestId:s.requestId,toolName:d,toolInput:x,description:p,suggestions:s.suggestions,onApprove:t,onApproveAlways:r,onReject:n})}function Ps({sessionId:s,agentId:t}){const[r,n]=u.useState(null),[l,c]=u.useState("disconnected"),[d,x]=u.useState(null),p=u.useRef(null);return u.useEffect(()=>{const m=Rs(t);return m.setConnectionStateHandler((g,j)=>{c(g),x(j||null)}),p.current=m,n(m),m.connect().catch(g=>{g instanceof Et||(x(g.message),c("error"))}),()=>{m.disconnect(),p.current=null,n(null),c("disconnected")}},[t]),e.jsx(Ue,{children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[d&&l==="error"&&e.jsx("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm border-b",children:d}),l==="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:v("session.connectingAgent")})]})}),l==="error"&&!r&&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:v("session.connectionFailed")}),e.jsx("p",{className:"text-text-muted text-sm",children:d})]})}),r&&l==="connected"&&e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Tt,{client:r,agentId:t})})]})})}export{Bs as SessionDetail};