lookatstudy-mobile 0.33.0 → 0.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/package.json +1 -1
  2. package/server.cjs +6 -6
  3. package/web/assets/{CanvasStage-CaFu-HaO.js → CanvasStage-Bt_fNO8t.js} +1 -1
  4. package/web/assets/{CommandPalette-BPSWW32h.js → CommandPalette-DWmgv52l.js} +1 -1
  5. package/web/assets/{CourseSearchPanel-CfyFDrU0.js → CourseSearchPanel-vB2mN_3Y.js} +1 -1
  6. package/web/assets/{ExamView-DpO-T-FU.js → ExamView-DjcpWfqz.js} +1 -1
  7. package/web/assets/{ReviewPanel-BWsENArl.js → ReviewPanel-BIdGi9F2.js} +1 -1
  8. package/web/assets/{SettingsView-Dlb3-wms.js → SettingsView-BeMHHZCd.js} +2 -2
  9. package/web/assets/{VoicePanel-D-9fJp6L.js → VoicePanel-CKzA8jtV.js} +1 -1
  10. package/web/assets/{abnfDiagram-VCTEODGH-ODA7YWAP-CONl7hDv.js → abnfDiagram-VCTEODGH-ODA7YWAP-D0MMepkX.js} +1 -1
  11. package/web/assets/{abnfDiagram-VCTEODGH-zkSafbw8.js → abnfDiagram-VCTEODGH-dGcioyTT.js} +1 -1
  12. package/web/assets/{architectureDiagram-5GKGNRK7-C4PU3XN7-DMWuKYkU.js → architectureDiagram-5GKGNRK7-C4PU3XN7-C6PC7E-G.js} +1 -1
  13. package/web/assets/{architectureDiagram-5GKGNRK7-BTcz7RyQ.js → architectureDiagram-5GKGNRK7-CXRelZVJ.js} +1 -1
  14. package/web/assets/{arrow-right-COMYZ1fA.js → arrow-right-Do7NbfY9.js} +1 -1
  15. package/web/assets/{blockDiagram-I7D4REHJ-B63IaFUV.js → blockDiagram-I7D4REHJ-Dd_p7o-g.js} +1 -1
  16. package/web/assets/{blockDiagram-NRAW4CY4-UMJ6PMQQ-CIAE11Pm.js → blockDiagram-NRAW4CY4-UMJ6PMQQ-1W9B_JQA.js} +1 -1
  17. package/web/assets/{c4Diagram-7LVT6UL2-BwajFuZF.js → c4Diagram-7LVT6UL2-D6GGkJgl.js} +1 -1
  18. package/web/assets/{c4Diagram-UCG6FXSJ-75X3U2P3-CQ2Qp_c1.js → c4Diagram-UCG6FXSJ-75X3U2P3-D6kIkgIO.js} +1 -1
  19. package/web/assets/channel-Bmdemkmz.js +1 -0
  20. package/web/assets/{chunk-2Q5K7J3B-hrIKE0Kh.js → chunk-2Q5K7J3B-1wsMqe35.js} +1 -1
  21. package/web/assets/{chunk-5VM5RSS4-nWuT_8NP.js → chunk-5VM5RSS4-DfuR9l9V.js} +1 -1
  22. package/web/assets/{chunk-7XDTSPCN-DaOQXXh6.js → chunk-7XDTSPCN-BZY0pKX-.js} +1 -1
  23. package/web/assets/{chunk-CTNIYPP6-B2__YmBS.js → chunk-CTNIYPP6-CNvvOY5j.js} +1 -1
  24. package/web/assets/{chunk-CXNFBKHE-CmQMLQWw.js → chunk-CXNFBKHE-Dm1pquWx.js} +1 -1
  25. package/web/assets/{chunk-F27PBJKO-zHBM_1uo.js → chunk-F27PBJKO-CHRFnx11.js} +1 -1
  26. package/web/assets/{chunk-IMKFNOWR-DTwQZApD.js → chunk-IMKFNOWR-uiypXoEe.js} +1 -1
  27. package/web/assets/{chunk-ISA7TJRJ-C_jhI1TS.js → chunk-ISA7TJRJ-BQ2gIr75.js} +1 -1
  28. package/web/assets/{chunk-JWPE2WC7-Dx6T5lv2.js → chunk-JWPE2WC7-BgST7e0p.js} +1 -1
  29. package/web/assets/{chunk-LV3HUYFY--L9ggqz-.js → chunk-LV3HUYFY-BnzTfd10.js} +1 -1
  30. package/web/assets/{chunk-M3IUQBOH-OFj5uQc-.js → chunk-M3IUQBOH-CviSmNDD.js} +1 -1
  31. package/web/assets/{chunk-NDIOYS4C-BaCZBdfD.js → chunk-NDIOYS4C-C4wQSziF.js} +1 -1
  32. package/web/assets/{chunk-POPQ4Y6H-CpiIve5m.js → chunk-POPQ4Y6H-LX5w0GJ3.js} +1 -1
  33. package/web/assets/{chunk-RE4WF27V-DMiY8mvU.js → chunk-RE4WF27V-BAhk1SH_.js} +1 -1
  34. package/web/assets/{chunk-SVP7TREG-BgA7U0O5.js → chunk-SVP7TREG-7Sg7sU_j.js} +1 -1
  35. package/web/assets/{chunk-TICWLB2K-BhfM6aa6.js → chunk-TICWLB2K-CP9bBlVg.js} +1 -1
  36. package/web/assets/{chunk-VII2H2IX-D97vmfRp.js → chunk-VII2H2IX-DZd3RSio.js} +1 -1
  37. package/web/assets/{chunk-X5GNSKZ3-Duc5cfce.js → chunk-X5GNSKZ3-BhOZRnO2.js} +1 -1
  38. package/web/assets/{chunk-XCWWM2C3-cz_1pt_w.js → chunk-XCWWM2C3-RUaVDOLz.js} +1 -1
  39. package/web/assets/{chunk-XXDRQBXY-dbgIls1a.js → chunk-XXDRQBXY-BMOoMY4C.js} +1 -1
  40. package/web/assets/classDiagram-DTDB5LWJ-LWRDKZ5K-BA0DiW1S.js +1 -0
  41. package/web/assets/classDiagram-ZZMXUADV-Y4CKpvNU.js +1 -0
  42. package/web/assets/classDiagram-v2-JRS7N3AN-2BZHGRP2-BA0DiW1S.js +1 -0
  43. package/web/assets/classDiagram-v2-VYDZK3BY-Y4CKpvNU.js +1 -0
  44. package/web/assets/{core-B40QXYe5.js → core-Bljob3yk.js} +1 -1
  45. package/web/assets/{cose-bilkent-JH36ORCC-Ce0oIg81.js → cose-bilkent-JH36ORCC-DLbA0yhO.js} +1 -1
  46. package/web/assets/{cose-bilkent-JH36ORCC-OB24KH3T-CN3uo8CD.js → cose-bilkent-JH36ORCC-OB24KH3T-ebHFtabj.js} +1 -1
  47. package/web/assets/{cynefin-OW5HDTMX-D283bZaS.js → cynefin-OW5HDTMX-CnnFvhFO.js} +1 -1
  48. package/web/assets/{cynefin-OW5HDTMX-GVF3BKWE-blsoPqhC.js → cynefin-OW5HDTMX-GVF3BKWE-DyJbbdgM.js} +1 -1
  49. package/web/assets/{cynefinDiagram-5FMLGOSQ-Dk3rgOe4.js → cynefinDiagram-5FMLGOSQ-DCwI1QTM.js} +1 -1
  50. package/web/assets/{cynefinDiagram-5FMLGOSQ-H3WIRU3N-DnTy2Qp1.js → cynefinDiagram-5FMLGOSQ-H3WIRU3N-jNzWfP6P.js} +1 -1
  51. package/web/assets/{dagre-3AP2YEHR-DCERTXHT-YyKk2Eje.js → dagre-3AP2YEHR-DCERTXHT-DeiOeAFM.js} +1 -1
  52. package/web/assets/{dagre-GXQ25YYZ-C4wVVN3x.js → dagre-GXQ25YYZ-CDCQs5B2.js} +1 -1
  53. package/web/assets/{diagram-S7CK7UJ4-Bl_tuPkt.js → diagram-S7CK7UJ4-DgZUpvXD.js} +1 -1
  54. package/web/assets/{diagram-S7CK7UJ4-MULGZGEL-RsN96cLG.js → diagram-S7CK7UJ4-MULGZGEL-BPzWf7Pz.js} +1 -1
  55. package/web/assets/{diagram-UQ7AKVKN-CDq4dP0x.js → diagram-UQ7AKVKN-CZTprTGR.js} +1 -1
  56. package/web/assets/{diagram-UQ7AKVKN-YQBY353J-CnONTOO_.js → diagram-UQ7AKVKN-YQBY353J-D8p7jpg9.js} +1 -1
  57. package/web/assets/{diagram-VSXAHHWV-KXVyLIQF.js → diagram-VSXAHHWV-D3J7k7wm.js} +1 -1
  58. package/web/assets/{diagram-VSXAHHWV-WLNH2ELY-BiT9bonG.js → diagram-VSXAHHWV-WLNH2ELY-DY4p4Mm9.js} +1 -1
  59. package/web/assets/{diagram-VX7I27RA-w44lGlag.js → diagram-VX7I27RA-CGlO-Ekr.js} +1 -1
  60. package/web/assets/{diagram-VX7I27RA-XW6YQV5G-CM2-RHcs.js → diagram-VX7I27RA-XW6YQV5G-Ctmdqbly.js} +1 -1
  61. package/web/assets/{diagram-Z3DM3KII-HG7RF65D-NDekrIV6.js → diagram-Z3DM3KII-HG7RF65D-qfRqaf6R.js} +1 -1
  62. package/web/assets/{diagram-Z3DM3KII-Dk9pGU7a.js → diagram-Z3DM3KII-m9lJCZC1.js} +1 -1
  63. package/web/assets/{ebnfDiagram-PWID7BFC-OKY4VHYD-D3U0p9Dw.js → ebnfDiagram-PWID7BFC-OKY4VHYD-D89NZRDy.js} +1 -1
  64. package/web/assets/{ebnfDiagram-PWID7BFC-QL78PgDI.js → ebnfDiagram-PWID7BFC-c9DvObbP.js} +1 -1
  65. package/web/assets/{erDiagram-RLTQ6QDP-BsC71zHF.js → erDiagram-RLTQ6QDP-CYWGD0br.js} +1 -1
  66. package/web/assets/{erDiagram-SSCWMZ5O-PIPKOIK7-CEQ1fj11.js → erDiagram-SSCWMZ5O-PIPKOIK7-BrchUk-n.js} +1 -1
  67. package/web/assets/{flowDiagram-A5DVABFB-2Z4AVO5R-CeEDePYs.js → flowDiagram-A5DVABFB-2Z4AVO5R-B0Rwk_R1.js} +1 -1
  68. package/web/assets/{flowDiagram-HODETNUW-j9xJY7Cn.js → flowDiagram-HODETNUW-BJ3ZVwcY.js} +1 -1
  69. package/web/assets/{ganttDiagram-EL5Y4UJY-uJxSumZ8.js → ganttDiagram-EL5Y4UJY-B_MNJ8fZ.js} +1 -1
  70. package/web/assets/{ganttDiagram-EL5Y4UJY-JZNG7GOG-BP55ilH-.js → ganttDiagram-EL5Y4UJY-JZNG7GOG-DkxJ0Cn0.js} +1 -1
  71. package/web/assets/{gitGraphDiagram-WWUBYQGX-DVI1ESQd.js → gitGraphDiagram-WWUBYQGX-CSy5TQmE.js} +1 -1
  72. package/web/assets/{gitGraphDiagram-WWUBYQGX-DMWMLL3G-CNDUB39t.js → gitGraphDiagram-WWUBYQGX-DMWMLL3G-D_BHv1fj.js} +1 -1
  73. package/web/assets/{index-DrY2EFcb.js → index-BPS_Agzl.js} +1 -1
  74. package/web/assets/{index-BCpaGgFy.js → index-DiOyjst0.js} +1 -1
  75. package/web/assets/{index-_UR-NqZ3.js → index-HjyNOGR-.js} +3 -3
  76. package/web/assets/{infoDiagram-27XIBGKW-CkW-sNO8.js → infoDiagram-27XIBGKW-Dg4zHSFK.js} +1 -1
  77. package/web/assets/{infoDiagram-RXCK75RN-HANS5KVC-dTP_Odo6.js → infoDiagram-RXCK75RN-HANS5KVC-BnDIUO0e.js} +1 -1
  78. package/web/assets/{ishikawaDiagram-5VMMS53U-7GCIT7WU-CpugNdNM.js → ishikawaDiagram-5VMMS53U-7GCIT7WU-CvpASJo8.js} +1 -1
  79. package/web/assets/{ishikawaDiagram-5VMMS53U-Q4eOk7i4.js → ishikawaDiagram-5VMMS53U-zVzbXgbw.js} +1 -1
  80. package/web/assets/{journeyDiagram-3NMN7TZE-Dxj1sa_P.js → journeyDiagram-3NMN7TZE-Dnac9OWj.js} +1 -1
  81. package/web/assets/{journeyDiagram-EYS64GPL-OAPELBT7-DTtloFWb.js → journeyDiagram-EYS64GPL-OAPELBT7-JFMRWh-l.js} +1 -1
  82. package/web/assets/{kanban-definition-3QL26DDD-I7RKWQQY-DNUfp8js.js → kanban-definition-3QL26DDD-I7RKWQQY-DI4eShiu.js} +1 -1
  83. package/web/assets/{kanban-definition-UXKFOSKX-lN88B3xx.js → kanban-definition-UXKFOSKX-BGCJV8zY.js} +1 -1
  84. package/web/assets/{katex-N6JRN4PM-lNEBPo7H.js → katex-N6JRN4PM-CUVnEhz9.js} +1 -1
  85. package/web/assets/{layout-DbydpuQY.js → layout-BUaUYSLh.js} +1 -1
  86. package/web/assets/{main-DGGbnUfo.js → main-fDEgiN-S.js} +6 -6
  87. package/web/assets/{mermaid-layout-elk.core-DiLPr9HM.js → mermaid-layout-elk.core-BWBQ_Al5.js} +2 -2
  88. package/web/assets/{mermaid.core-D7fD1FwK.js → mermaid.core-BMxGmpq2.js} +5 -5
  89. package/web/assets/{mindmap-definition-FBJOCRG2-KIYZG64Y-BOFqPKDa.js → mindmap-definition-FBJOCRG2-KIYZG64Y-CjgpFZ4r.js} +1 -1
  90. package/web/assets/{mindmap-definition-YA3MSWOX-CATiDuGI.js → mindmap-definition-YA3MSWOX-DsaPJhNK.js} +1 -1
  91. package/web/assets/{pegDiagram-XKGWAZYB-Bp1tCSY-.js → pegDiagram-XKGWAZYB-DOx0zpGS.js} +1 -1
  92. package/web/assets/{pegDiagram-XKGWAZYB-OIP57N6J-DlQB65ue.js → pegDiagram-XKGWAZYB-OIP57N6J-DjMX89Yt.js} +1 -1
  93. package/web/assets/{pieDiagram-E7YTZNPT-2UOTW327-C_8F2EM1.js → pieDiagram-E7YTZNPT-2UOTW327-lDdClvNY.js} +1 -1
  94. package/web/assets/{pieDiagram-E7YTZNPT-CrDGrlAd.js → pieDiagram-E7YTZNPT-D6Fit7on.js} +1 -1
  95. package/web/assets/{quadrantDiagram-AXDQQJYC-Dr7W78wK.js → quadrantDiagram-AXDQQJYC-1jui_ce_.js} +1 -1
  96. package/web/assets/{quadrantDiagram-AXDQQJYC-SN3ASJJK-C39aRWD3.js → quadrantDiagram-AXDQQJYC-SN3ASJJK-BTbJgylU.js} +1 -1
  97. package/web/assets/{railroadDiagram-O6MQD6OU-34742W6X-CjrAplDr.js → railroadDiagram-O6MQD6OU-34742W6X-BC0RubPt.js} +1 -1
  98. package/web/assets/{railroadDiagram-O6MQD6OU-CXiZMLyn.js → railroadDiagram-O6MQD6OU-BAC-UzUT.js} +1 -1
  99. package/web/assets/{render-O7CIS3YK-CZ3IDVwW.js → render-O7CIS3YK-ilIoaxFJ.js} +7 -7
  100. package/web/assets/{requirementDiagram-BXWQKSXE-C2qycPSr.js → requirementDiagram-BXWQKSXE-9E1HLwpG.js} +1 -1
  101. package/web/assets/{requirementDiagram-EFPCY7ZU-NGAFFSMB-DHlqxJGG.js → requirementDiagram-EFPCY7ZU-NGAFFSMB-KHWBp4rz.js} +1 -1
  102. package/web/assets/{rotate-ccw-Cca2hxMT.js → rotate-ccw-QIElN2Wl.js} +1 -1
  103. package/web/assets/{sankeyDiagram-P5KCCOFB-3D3M4XPB-AsThg1OY.js → sankeyDiagram-P5KCCOFB-3D3M4XPB-C-izOJ7-.js} +1 -1
  104. package/web/assets/{sankeyDiagram-P5KCCOFB-vMRJfraP.js → sankeyDiagram-P5KCCOFB-Cdc1ghNL.js} +1 -1
  105. package/web/assets/{sequenceDiagram-WJ2MYXX4-DXz4qAcJ.js → sequenceDiagram-WJ2MYXX4-DRxvXwCF.js} +1 -1
  106. package/web/assets/{sequenceDiagram-WJ2MYXX4-Q2IOPB4R-O-Lrk2oI.js → sequenceDiagram-WJ2MYXX4-Q2IOPB4R-D1pUF6jo.js} +1 -1
  107. package/web/assets/{sizeCapture-INFHLROL-DoMzpXxN.js → sizeCapture-INFHLROL-DpTeYER6.js} +1 -1
  108. package/web/assets/{sizeCapture-X5ZJPWSS-PSGVOMYM-CGWX8Jny.js → sizeCapture-X5ZJPWSS-PSGVOMYM-9nTpQ1b_.js} +1 -1
  109. package/web/assets/{stateDiagram-D77RDMKH-aoa5ZmSB.js → stateDiagram-D77RDMKH-C96itYlp.js} +1 -1
  110. package/web/assets/{stateDiagram-HBIQ2CUA-4M2S6MAN-BsvWo7X8.js → stateDiagram-HBIQ2CUA-4M2S6MAN-DVcS5z07.js} +1 -1
  111. package/web/assets/stateDiagram-v2-4QOOHH4V-LBBLA2WV-C8CVqjZH.js +1 -0
  112. package/web/assets/stateDiagram-v2-MP3YSRHH-Ddg-z14V.js +1 -0
  113. package/web/assets/{swimlanes-42K2YHIH-Dz4OR5iQ.js → swimlanes-42K2YHIH-4suR9Oix.js} +1 -1
  114. package/web/assets/{swimlanes-XN3QIQJK-N6N2CCQ6-DVIJq7Pa.js → swimlanes-XN3QIQJK-N6N2CCQ6-DcuiDmSl.js} +1 -1
  115. package/web/assets/swimlanesDiagram-VK2B7HYN-E6N4H5SY-BDSwlxp9.js +8 -0
  116. package/web/assets/swimlanesDiagram-VR7AAH4N-Cj4AmHeX.js +8 -0
  117. package/web/assets/{timeline-definition-24CTP7MA-VTB2LyFw.js → timeline-definition-24CTP7MA-CcO-uk61.js} +1 -1
  118. package/web/assets/{timeline-definition-24CTP7MA-KN7RSRVM-U2gzdSo-.js → timeline-definition-24CTP7MA-KN7RSRVM-rA7akmuP.js} +1 -1
  119. package/web/assets/{vennDiagram-4TSXK5OY-AKJ7LXAN-DtdtRly6.js → vennDiagram-4TSXK5OY-AKJ7LXAN-Hpw8RJob.js} +1 -1
  120. package/web/assets/{vennDiagram-4TSXK5OY-BC1R0pU_.js → vennDiagram-4TSXK5OY-L93ffUGG.js} +1 -1
  121. package/web/assets/{wardleyDiagram-VM6X3IG4-3B6A3BN5-BgacOfmW.js → wardleyDiagram-VM6X3IG4-3B6A3BN5-Dij0NzOp.js} +1 -1
  122. package/web/assets/{wardleyDiagram-VM6X3IG4-DmMxrWiy.js → wardleyDiagram-VM6X3IG4-D4jAxgQi.js} +1 -1
  123. package/web/assets/{xychartDiagram-S5SC5T6Z-B3ColLAu.js → xychartDiagram-S5SC5T6Z-BeOHWeZb.js} +1 -1
  124. package/web/assets/{xychartDiagram-S5SC5T6Z-OBDNV6WG-DEomTVra.js → xychartDiagram-S5SC5T6Z-OBDNV6WG-NM-894O4.js} +1 -1
  125. package/web/index.html +1 -1
  126. package/web/assets/channel-Daa-iwE6.js +0 -1
  127. package/web/assets/classDiagram-DTDB5LWJ-LWRDKZ5K-B0cf41QA.js +0 -1
  128. package/web/assets/classDiagram-ZZMXUADV-BCEbKtzF.js +0 -1
  129. package/web/assets/classDiagram-v2-JRS7N3AN-2BZHGRP2-B0cf41QA.js +0 -1
  130. package/web/assets/classDiagram-v2-VYDZK3BY-BCEbKtzF.js +0 -1
  131. package/web/assets/stateDiagram-v2-4QOOHH4V-LBBLA2WV-BSX-RFNn.js +0 -1
  132. package/web/assets/stateDiagram-v2-MP3YSRHH-DiN5JuuU.js +0 -1
  133. package/web/assets/swimlanesDiagram-VK2B7HYN-E6N4H5SY-fcmr0ac0.js +0 -8
  134. package/web/assets/swimlanesDiagram-VR7AAH4N-C_q81JGw.js +0 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lookatstudy-mobile",
3
- "version": "0.33.0",
3
+ "version": "0.33.1",
4
4
  "description": "LookatStudy Termux portable bundle (server.cjs + web frontend)",
5
5
  "repository": {
6
6
  "type": "git",
package/server.cjs CHANGED
@@ -560146,7 +560146,7 @@ async function cutCompanionFigure(deps, input) {
560146
560146
  let visionError;
560147
560147
  if (fm && !deps.skipVision) {
560148
560148
  let usedVision = "";
560149
- const locateAt = async (dataUrl, maxOutputTokens) => {
560149
+ const locateAt = async (imageBytes, maxOutputTokens) => {
560150
560150
  const llm = resolveVisionLlm(deps.db);
560151
560151
  usedVision = `${llm.provider.label}/${llm.model}`;
560152
560152
  const built = buildImportModel(llm);
@@ -560157,14 +560157,14 @@ async function cutCompanionFigure(deps, input) {
560157
560157
  role: "user",
560158
560158
  content: [
560159
560159
  { type: "text", text: locatePrompt(W, H) },
560160
- { type: "image", image: dataUrl }
560160
+ { type: "image", image: imageBytes }
560161
560161
  ]
560162
560162
  }
560163
560163
  ],
560164
560164
  { maxOutputTokens, ...built.providerOptions ? { providerOptions: built.providerOptions } : {} }
560165
560165
  );
560166
560166
  };
560167
- const locate = deps.locate ?? ((dataUrl) => locateAt(dataUrl, LOCATE_MAX_TOKENS));
560167
+ const locate = deps.locate ?? ((bytes) => locateAt(bytes, LOCATE_MAX_TOKENS));
560168
560168
  try {
560169
560169
  let preview = composeKeyedPreview(rgba, fm);
560170
560170
  const longest = Math.max(preview.width, preview.height);
@@ -560173,11 +560173,11 @@ async function cutCompanionFigure(deps, input) {
560173
560173
  preview = resizeBox(preview, Math.max(1, Math.round(preview.width * k)), Math.max(1, Math.round(preview.height * k)));
560174
560174
  }
560175
560175
  const previewPng = await rgbaToPng(preview);
560176
- const dataUrl = `data:image/png;base64,${Buffer.from(previewPng).toString("base64")}`;
560177
- let rawReply = await locate(dataUrl);
560176
+ const imageBytes = new Uint8Array(previewPng);
560177
+ let rawReply = await locate(imageBytes);
560178
560178
  cuts = parseCutsJson(rawReply, W, H);
560179
560179
  if (!cuts && !deps.locate && rawReply.trim() === "") {
560180
- rawReply = await locateAt(dataUrl, LOCATE_RETRY_TOKENS);
560180
+ rawReply = await locateAt(imageBytes, LOCATE_RETRY_TOKENS);
560181
560181
  cuts = parseCutsJson(rawReply, W, H);
560182
560182
  }
560183
560183
  if (!cuts) {
@@ -1,4 +1,4 @@
1
- import{r,j as h}from"./index-3R9G44mo.js";import{c as T,u as L,P as D}from"./main-DGGbnUfo.js";/**
1
+ import{r,j as h}from"./index-3R9G44mo.js";import{c as T,u as L,P as D}from"./main-fDEgiN-S.js";/**
2
2
  * @license lucide-react v0.468.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{r as s,j as t}from"./index-3R9G44mo.js";import{c as y,u as v,b as k,L as j,F as N,M as w,G as C,T as M,d as _}from"./main-DGGbnUfo.js";/**
1
+ import{r as s,j as t}from"./index-3R9G44mo.js";import{c as y,u as v,b as k,L as j,F as N,M as w,G as C,T as M,d as _}from"./main-fDEgiN-S.js";/**
2
2
  * @license lucide-react v0.468.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{r as u,j as t}from"./index-3R9G44mo.js";import{c as C,U as I,u as y,a as L,d as S,X as N,B as M,T as E,C as R}from"./main-DGGbnUfo.js";/**
1
+ import{r as u,j as t}from"./index-3R9G44mo.js";import{c as C,U as I,u as y,a as L,d as S,X as N,B as M,T as E,C as R}from"./main-fDEgiN-S.js";/**
2
2
  * @license lucide-react v0.468.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{r as o,h as U,j as e,c as ie}from"./index-3R9G44mo.js";import{c as te,u as ce,a as j,g as de,T as z,h as Y,L as V,i as oe,X as xe}from"./main-DGGbnUfo.js";import{R as G}from"./rotate-ccw-Cca2hxMT.js";import{A as q}from"./arrow-right-COMYZ1fA.js";/**
1
+ import{r as o,h as U,j as e,c as ie}from"./index-3R9G44mo.js";import{c as te,u as ce,a as j,g as de,T as z,h as Y,L as V,i as oe,X as xe}from"./main-fDEgiN-S.js";import{R as G}from"./rotate-ccw-QIElN2Wl.js";import{A as q}from"./arrow-right-Do7NbfY9.js";/**
2
2
  * @license lucide-react v0.468.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{r as a,j as e,c as S}from"./index-3R9G44mo.js";import{u as j,a as N,S as M}from"./main-DGGbnUfo.js";function A({tree:c,onReviewNode:d,progressMap:o}){const s=j(),[l,f]=a.useState([]),[b,h]=a.useState(!0),[n,x]=a.useState(null);a.useEffect(()=>{N.getAllSrsItems().then(t=>f(t)).catch(()=>f([])).finally(()=>h(!1))},[]);const p=a.useMemo(()=>new Map(c.map(t=>[t.id,t])),[c]),g=a.useMemo(()=>new Set(l.filter(t=>t.overdue).map(t=>t.nodeId)),[l]),i=a.useMemo(()=>{const t=c.filter(u=>{var y;const m=(y=o[u.id])==null?void 0:y.status;return u.type==="lesson"&&(m==="in_progress"||m==="mastered")}),r=new Map;for(const u of t){const m=u.parentId??"(root)";r.has(m)||r.set(m,[]),r.get(m).push(u)}return r},[c,o]),w=a.useMemo(()=>Array.from(i.values()).flat().filter(t=>g.has(t.id)).length,[i,g]),v=a.useMemo(()=>Array.from(i.values()).flat(),[i]);if(a.useEffect(()=>{if(i.size>0&&(!n||!i.has(n))){const t=i.keys().next().value;t&&x(t)}},[i,n]),b)return e.jsxs("div",{className:"text-center py-12 text-body text-ink-muted flex items-center justify-center gap-2",children:[e.jsx("span",{className:"typing-dot w-1.5 h-1.5 bg-brand rounded-full inline-block"}),s("review.loading")]});if(v.length===0)return e.jsxs("div",{className:"text-center py-16","data-testid":"review-empty",children:[e.jsx("div",{className:"text-4xl mb-3 opacity-30",children:"📖"}),e.jsx("div",{className:"text-body text-ink-muted",children:s("review.empty.title")}),e.jsx("div",{className:"text-label text-ink-faint mt-1",children:s("review.empty.desc")})]});const k=t=>{var r;return((r=p.get(t))==null?void 0:r.title)??t};return e.jsxs("div",{className:"p-5 max-w-2xl mx-auto","data-testid":"review-panel",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-title font-extrabold text-ink-strong",children:s("review.title")}),w>0&&e.jsxs("span",{className:"text-label font-bold text-review","data-testid":"review-due-count",children:[w," ",s("review.due.count")]})]}),e.jsxs("button",{onClick:()=>{const t=v[Math.floor(Math.random()*v.length)];t&&d(t.id)},"data-testid":"review-interleave",className:"btn-3d-neutral w-full py-2.5 text-body mb-5 flex items-center justify-center gap-1.5",children:[e.jsx(M,{className:"w-4 h-4"}),s("review.interleave")]}),e.jsx("div",{className:"text-label font-bold text-ink-muted mb-2",children:s("review.selectSection")}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",children:Array.from(i.entries()).map(([t,r])=>e.jsxs("button",{onClick:()=>x(t),className:`px-2.5 py-1 rounded-full text-label font-bold transition-colors ${n===t?"bg-brand/15 text-brand ring-1 ring-brand/30":"bg-surface-3 text-ink-muted hover:text-ink-strong"}`,children:[k(t),e.jsxs("span",{className:"ml-1 opacity-60",children:["(",r.length,")"]})]},t))}),n&&i.has(n)&&e.jsx("div",{className:"space-y-1.5","data-testid":"review-lesson-list",children:i.get(n).map(t=>{const r=g.has(t.id);return e.jsxs("div",{className:`flex items-center justify-between gap-2 p-2.5 rounded-lg transition-colors ${r?"bg-review/8 ring-1 ring-review/20":"bg-surface-3 hover:bg-surface-3/80"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 truncate flex-1",children:[r&&e.jsx("span",{className:"shrink-0 w-1.5 h-1.5 rounded-full bg-review"}),e.jsx("span",{className:"text-body text-ink-strong truncate",children:t.title})]}),e.jsx("button",{onClick:()=>d(t.id),"data-testid":`review-lesson-${t.id.slice(0,8)}`,className:"shrink-0 px-3 py-1 rounded-lg bg-brand/15 text-brand text-label font-bold hover:bg-brand/25 transition-colors",children:s("review.reviewLesson")})]},t.id)})})]})}function E({nodeId:c,onRated:d}){const o=a.useRef(null),s=j(),[l,f]=a.useState(!1),[b,h]=a.useState(!1),n=async x=>{if(!(l||b)){f(!0);try{await N.recordReview(c,x),h(!0),d==null||d(),S(x>=4?"correct":"wrong",{origin:x>=4&&o.current?(()=>{const p=o.current.getBoundingClientRect();return{x:p.right-48,y:p.top+24}})():void 0})}catch{}finally{f(!1)}}};return b?e.jsx("div",{className:"text-center text-body text-brand py-2","data-testid":"self-rated",children:s("review.selfrated")}):e.jsxs("div",{ref:o,className:"border-t border-[var(--border-faint)] pt-3 mt-3","data-testid":"self-rating",children:[e.jsx("div",{className:"text-caption font-bold text-ink-muted uppercase tracking-wider mb-2 text-center",children:s("review.selfrate.title")}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("button",{onClick:()=>n(1),disabled:l,"data-testid":"rate-again",className:"py-2 rounded-lg border border-warning/40 text-warning hover:bg-warning/10 transition-colors disabled:opacity-40 flex flex-col items-center gap-0.5",children:[e.jsx("span",{className:"text-body font-bold",children:s("review.selfrate.again")}),e.jsx("span",{className:"text-caption opacity-70",children:s("review.selfrate.again.hint")})]}),e.jsxs("button",{onClick:()=>n(4),disabled:l,"data-testid":"rate-remembered",className:"py-2 rounded-lg border border-accent/40 text-accent hover:bg-accent/10 transition-colors disabled:opacity-40 flex flex-col items-center gap-0.5",children:[e.jsx("span",{className:"text-body font-bold",children:s("review.selfrate.remembered")}),e.jsx("span",{className:"text-caption opacity-70",children:s("review.selfrate.remembered.hint")})]}),e.jsxs("button",{onClick:()=>n(5),disabled:l,"data-testid":"rate-mastered",className:"py-2 rounded-lg border border-brand/40 text-brand hover:bg-brand/10 transition-colors disabled:opacity-40 flex flex-col items-center gap-0.5",children:[e.jsx("span",{className:"text-body font-bold",children:s("review.selfrate.mastered")}),e.jsx("span",{className:"text-caption opacity-70",children:s("review.selfrate.mastered.hint")})]})]})]})}export{A as ReviewPanel,E as SelfRatingCard};
1
+ import{r as a,j as e,c as S}from"./index-3R9G44mo.js";import{u as j,a as N,S as M}from"./main-fDEgiN-S.js";function A({tree:c,onReviewNode:d,progressMap:o}){const s=j(),[l,f]=a.useState([]),[b,h]=a.useState(!0),[n,x]=a.useState(null);a.useEffect(()=>{N.getAllSrsItems().then(t=>f(t)).catch(()=>f([])).finally(()=>h(!1))},[]);const p=a.useMemo(()=>new Map(c.map(t=>[t.id,t])),[c]),g=a.useMemo(()=>new Set(l.filter(t=>t.overdue).map(t=>t.nodeId)),[l]),i=a.useMemo(()=>{const t=c.filter(u=>{var y;const m=(y=o[u.id])==null?void 0:y.status;return u.type==="lesson"&&(m==="in_progress"||m==="mastered")}),r=new Map;for(const u of t){const m=u.parentId??"(root)";r.has(m)||r.set(m,[]),r.get(m).push(u)}return r},[c,o]),w=a.useMemo(()=>Array.from(i.values()).flat().filter(t=>g.has(t.id)).length,[i,g]),v=a.useMemo(()=>Array.from(i.values()).flat(),[i]);if(a.useEffect(()=>{if(i.size>0&&(!n||!i.has(n))){const t=i.keys().next().value;t&&x(t)}},[i,n]),b)return e.jsxs("div",{className:"text-center py-12 text-body text-ink-muted flex items-center justify-center gap-2",children:[e.jsx("span",{className:"typing-dot w-1.5 h-1.5 bg-brand rounded-full inline-block"}),s("review.loading")]});if(v.length===0)return e.jsxs("div",{className:"text-center py-16","data-testid":"review-empty",children:[e.jsx("div",{className:"text-4xl mb-3 opacity-30",children:"📖"}),e.jsx("div",{className:"text-body text-ink-muted",children:s("review.empty.title")}),e.jsx("div",{className:"text-label text-ink-faint mt-1",children:s("review.empty.desc")})]});const k=t=>{var r;return((r=p.get(t))==null?void 0:r.title)??t};return e.jsxs("div",{className:"p-5 max-w-2xl mx-auto","data-testid":"review-panel",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-title font-extrabold text-ink-strong",children:s("review.title")}),w>0&&e.jsxs("span",{className:"text-label font-bold text-review","data-testid":"review-due-count",children:[w," ",s("review.due.count")]})]}),e.jsxs("button",{onClick:()=>{const t=v[Math.floor(Math.random()*v.length)];t&&d(t.id)},"data-testid":"review-interleave",className:"btn-3d-neutral w-full py-2.5 text-body mb-5 flex items-center justify-center gap-1.5",children:[e.jsx(M,{className:"w-4 h-4"}),s("review.interleave")]}),e.jsx("div",{className:"text-label font-bold text-ink-muted mb-2",children:s("review.selectSection")}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",children:Array.from(i.entries()).map(([t,r])=>e.jsxs("button",{onClick:()=>x(t),className:`px-2.5 py-1 rounded-full text-label font-bold transition-colors ${n===t?"bg-brand/15 text-brand ring-1 ring-brand/30":"bg-surface-3 text-ink-muted hover:text-ink-strong"}`,children:[k(t),e.jsxs("span",{className:"ml-1 opacity-60",children:["(",r.length,")"]})]},t))}),n&&i.has(n)&&e.jsx("div",{className:"space-y-1.5","data-testid":"review-lesson-list",children:i.get(n).map(t=>{const r=g.has(t.id);return e.jsxs("div",{className:`flex items-center justify-between gap-2 p-2.5 rounded-lg transition-colors ${r?"bg-review/8 ring-1 ring-review/20":"bg-surface-3 hover:bg-surface-3/80"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 truncate flex-1",children:[r&&e.jsx("span",{className:"shrink-0 w-1.5 h-1.5 rounded-full bg-review"}),e.jsx("span",{className:"text-body text-ink-strong truncate",children:t.title})]}),e.jsx("button",{onClick:()=>d(t.id),"data-testid":`review-lesson-${t.id.slice(0,8)}`,className:"shrink-0 px-3 py-1 rounded-lg bg-brand/15 text-brand text-label font-bold hover:bg-brand/25 transition-colors",children:s("review.reviewLesson")})]},t.id)})})]})}function E({nodeId:c,onRated:d}){const o=a.useRef(null),s=j(),[l,f]=a.useState(!1),[b,h]=a.useState(!1),n=async x=>{if(!(l||b)){f(!0);try{await N.recordReview(c,x),h(!0),d==null||d(),S(x>=4?"correct":"wrong",{origin:x>=4&&o.current?(()=>{const p=o.current.getBoundingClientRect();return{x:p.right-48,y:p.top+24}})():void 0})}catch{}finally{f(!1)}}};return b?e.jsx("div",{className:"text-center text-body text-brand py-2","data-testid":"self-rated",children:s("review.selfrated")}):e.jsxs("div",{ref:o,className:"border-t border-[var(--border-faint)] pt-3 mt-3","data-testid":"self-rating",children:[e.jsx("div",{className:"text-caption font-bold text-ink-muted uppercase tracking-wider mb-2 text-center",children:s("review.selfrate.title")}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("button",{onClick:()=>n(1),disabled:l,"data-testid":"rate-again",className:"py-2 rounded-lg border border-warning/40 text-warning hover:bg-warning/10 transition-colors disabled:opacity-40 flex flex-col items-center gap-0.5",children:[e.jsx("span",{className:"text-body font-bold",children:s("review.selfrate.again")}),e.jsx("span",{className:"text-caption opacity-70",children:s("review.selfrate.again.hint")})]}),e.jsxs("button",{onClick:()=>n(4),disabled:l,"data-testid":"rate-remembered",className:"py-2 rounded-lg border border-accent/40 text-accent hover:bg-accent/10 transition-colors disabled:opacity-40 flex flex-col items-center gap-0.5",children:[e.jsx("span",{className:"text-body font-bold",children:s("review.selfrate.remembered")}),e.jsx("span",{className:"text-caption opacity-70",children:s("review.selfrate.remembered.hint")})]}),e.jsxs("button",{onClick:()=>n(5),disabled:l,"data-testid":"rate-mastered",className:"py-2 rounded-lg border border-brand/40 text-brand hover:bg-brand/10 transition-colors disabled:opacity-40 flex flex-col items-center gap-0.5",children:[e.jsx("span",{className:"text-body font-bold",children:s("review.selfrate.mastered")}),e.jsx("span",{className:"text-caption opacity-70",children:s("review.selfrate.mastered.hint")})]})]})]})}export{A as ReviewPanel,E as SelfRatingCard};
@@ -1,10 +1,10 @@
1
- import{r as n,j as e,V as De,k as $e,l as Ee,s as nt,m as it,C as lt,M as ot}from"./index-3R9G44mo.js";import{c as rt,u as ne,b as ct,r as dt,X as Te,f as mt,k as oe,n as pe,a as o,W as ze,P as Ue,p as Ke,s as ut,i as xt,g as Pe,q as ht,t as pt,v as gt}from"./main-DGGbnUfo.js";/**
1
+ import{r as n,j as e,V as De,k as $e,l as Ee,s as nt,m as it,C as lt,M as ot}from"./index-3R9G44mo.js";import{c as rt,u as ne,b as ct,r as dt,X as Te,f as mt,k as oe,n as pe,a as o,W as ze,P as Ue,p as Ke,s as ut,i as xt,g as Pe,q as ht,t as pt,v as gt}from"./main-fDEgiN-S.js";/**
2
2
  * @license lucide-react v0.468.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
6
  */const ft=rt("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]),bt={vision:"companion.custom.routeVision",geometric:"companion.custom.routeGeometric",l1:"companion.custom.routeL1"};function vt(t){let u="";for(let h=0;h<t.length;h+=32768)u+=String.fromCharCode(...t.subarray(h,h+32768));return btoa(u)}async function jt(t){try{return await navigator.clipboard.writeText(t),!0}catch{}const u=document.createElement("textarea");u.value=t,u.style.position="fixed",u.style.opacity="0",document.body.appendChild(u),u.focus(),u.select();let r=!1;try{r=document.execCommand("copy")}catch{r=!1}return u.remove(),r}function wt({onClose:t,onSaved:u}){const r=ne(),[h,v]=n.useState(!1),[l,c]=n.useState(!1),[p,x]=n.useState(0),[f,y]=n.useState(null),[g,T]=n.useState(null),[S,W]=n.useState(""),[C,M]=n.useState(""),[_,L]=n.useState("ember"),R=n.useRef(null),A=n.useRef(null);ct(A,!0),n.useEffect(()=>{if(!l)return;x(0);const d=Date.now(),w=window.setInterval(()=>x(Math.floor((Date.now()-d)/1e3)),500);return()=>window.clearInterval(w)},[l]);const D=async()=>{const d=await jt(r("companion.wizard.prompt"));v(d),d?setTimeout(()=>v(!1),2400):T(r("companion.wizard.copyFail"))},U=async d=>{if(d){c(!0),T(null),y(null),W(d.name.replace(/\.png$/i,""));try{const w=vt(new Uint8Array(await d.arrayBuffer())),k=await window.api.companionPackCutFromImage({pngBase64:w});y(k),k.visionError?T(`${r("companion.custom.visionFallback")} · ${k.visionError}`):T(`${r("companion.custom.cutDone")} · ${r(bt[k.route]??"companion.custom.routeL1")}`)}catch(w){T(`${r("companion.custom.fail")}: ${String(w)}`)}finally{c(!1)}}},z=async()=>{if(f){c(!0);try{await window.api.companionPackApplyPack({name:C.trim()||S||"My Bot",manifest:{...f.manifest,vehicle:_},parts:f.parts.map(d=>({name:d.name,pngBase64:d.pngBase64}))}),await Ee(),await window.api.setSetting("companion_form","custom"),window.dispatchEvent(new Event("companion-config-changed")),u()}catch(d){T(`${r("companion.custom.fail")}: ${String(d)}`)}finally{c(!1)}}};return dt.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4","data-noswipe":"",role:"dialog","aria-modal":"true","aria-label":r("companion.wizard.title"),onClick:t,children:e.jsxs("div",{ref:A,onClick:d=>d.stopPropagation(),className:"w-full max-w-xl max-h-[86vh] overflow-y-auto rounded-2xl bg-surface-1 shadow-pop p-4","data-testid":"companion-wizard",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-body font-bold text-ink-strong",children:r("companion.wizard.title")}),e.jsx("button",{onClick:t,"aria-label":r("action.close"),className:"text-ink-muted hover:text-ink-strong w-8 h-8 flex items-center justify-center rounded-lg hover:bg-surface-2",children:e.jsx(Te,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"rounded-xl border border-[var(--border-faint)] p-3 mb-2",children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1",children:r("companion.wizard.s1")}),e.jsx("p",{className:"text-caption text-ink-muted leading-relaxed",children:r("companion.wizard.s1body")})]}),e.jsxs("div",{className:"rounded-xl border border-[var(--border-faint)] p-3 mb-2",children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1",children:r("companion.wizard.s2")}),e.jsx("p",{className:"text-caption text-ink-muted leading-relaxed mb-2",children:r("companion.wizard.s2body")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx("a",{href:"https://www.doubao.com/chat/",target:"_blank",rel:"noreferrer",className:"rounded-lg border border-[var(--border-faint)] px-3 py-1.5 text-label hover:bg-surface-2",children:r("companion.wizard.s2doubao")}),e.jsx("a",{href:"https://jimeng.jianying.com/",target:"_blank",rel:"noreferrer",className:"rounded-lg border border-[var(--border-faint)] px-3 py-1.5 text-label hover:bg-surface-2",children:r("companion.wizard.s2jimeng")}),e.jsx("a",{href:"https://chatgpt.com/",target:"_blank",rel:"noreferrer",className:"rounded-lg border border-[var(--border-faint)] px-3 py-1.5 text-label hover:bg-surface-2",children:r("companion.wizard.s2chatgpt")}),e.jsx("button",{type:"button",onClick:()=>void D(),"data-testid":"companion-wizard-copy",className:"rounded-lg bg-accent px-3 py-1.5 text-label text-white hover:opacity-90",children:r(h?"companion.wizard.copied":"companion.wizard.copy")})]}),e.jsx("textarea",{readOnly:!0,value:r("companion.wizard.prompt"),rows:6,className:"w-full rounded-lg bg-surface-2 border border-[var(--border-faint)] p-2 text-caption text-ink-muted font-mono resize-y select-all",onFocus:d=>d.currentTarget.select()})]}),e.jsxs("div",{className:"rounded-xl border border-[var(--border-faint)] p-3",children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1",children:r("companion.wizard.s3")}),e.jsxs("div",{className:"mb-2",children:[e.jsx("div",{className:"text-caption text-ink-muted mb-1",children:r("companion.wizard.vehicle")}),e.jsx("div",{className:"flex flex-wrap gap-1.5",role:"radiogroup","aria-label":r("companion.wizard.vehicle"),children:De.map(d=>{const w=_===d;return e.jsxs("button",{type:"button",role:"radio","aria-checked":w,"data-testid":`companion-wizard-veh-${d}`,onClick:()=>L(d),className:`flex items-center gap-1.5 rounded-lg border px-2.5 py-1 text-label motion-safe:transition-colors
7
- ${w?"border-[var(--accent)] bg-surface-2 text-ink-strong font-medium":"border-[var(--border-faint)] hover:bg-surface-2 text-ink-muted"}`,children:[e.jsx("span",{"aria-hidden":"true",className:"w-3 h-3 rounded-full border border-black/20",style:{background:$e[d].dot}}),r(`companion.form.${d}.name`)]},d)})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx("input",{ref:R,type:"file",accept:"image/png",className:"hidden","data-testid":"companion-custom-file",onChange:d=>{var w;return void U((w=d.target.files)==null?void 0:w[0])}}),e.jsx("button",{type:"button",disabled:l,onClick:()=>{var d;return(d=R.current)==null?void 0:d.click()},"data-testid":"companion-wizard-pick",className:"rounded-lg border border-[var(--border-faint)] px-3 py-1.5 text-label hover:bg-surface-2 disabled:opacity-50",children:r("companion.wizard.pick")}),l&&e.jsxs("span",{className:"flex items-center gap-1.5 text-label text-ink-muted","data-testid":"companion-custom-busy",children:[e.jsx(mt,{size:14,className:"animate-spin"}),r(f?"companion.custom.applying":"companion.custom.locating"),e.jsxs("span",{className:"tabular-nums",children:[p,"s"]})]}),g&&e.jsx("span",{className:"text-caption text-ink-muted","data-testid":"companion-custom-msg",children:g})]}),f&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-testid":"companion-custom-preview",children:[f.parts.map(d=>e.jsx("img",{src:`data:image/png;base64,${d.pngBase64}`,alt:d.name,title:d.name,className:"h-14 w-14 object-contain rounded-lg bg-surface-2"},d.name)),e.jsx("input",{value:C,onChange:d=>M(d.target.value),placeholder:r("companion.wizard.namePh"),"data-testid":"companion-wizard-name",className:"rounded-lg border border-[var(--border-faint)] bg-surface-0 px-2.5 py-1.5 text-label text-ink-strong placeholder:text-ink-muted w-36"}),e.jsx("button",{type:"button",disabled:l,onClick:()=>void z(),"data-testid":"companion-custom-apply",className:"rounded-lg bg-brand px-3 py-1.5 text-label text-white hover:opacity-90 disabled:opacity-50",children:r("companion.wizard.save")})]})]})]})}),document.body)}const he="bg-ink/[0.04] text-ink-strong text-label rounded-lg border border-transparent focus:border-accent focus:bg-ink/[0.06] transition-colors placeholder:text-ink-faint";function ye({kind:t,showProtocol:u=!0,testPrefix:r="custom",titleKey:h="settings.custom.form_title",modelPhKey:v="settings.custom.model_ph",testOverride:l,onSaved:c,onCancel:p}){const x=ne(),[f,y]=n.useState(""),[g,T]=n.useState("openai-compatible"),[S,W]=n.useState(""),[C,M]=n.useState(""),[_,L]=n.useState(""),[R,A]=n.useState(!1),[D,U]=n.useState(!1),[z,d]=n.useState(null),w=async()=>{if(!(!S.trim()||!_.trim()||D)){U(!0),d(null);try{const i=l?await l({baseUrl:S.trim(),apiKey:C.trim(),model:_.trim()}):await o.testCustomProvider({label:f||x("settings.custom.test_label"),protocol:g,baseUrl:S.trim(),apiKey:C.trim()||void 0,defaultModel:_.trim()});d({ok:i.ok,detail:i.detail})}catch(i){d({ok:!1,detail:i instanceof Error?i.message:String(i)})}finally{U(!1)}}},k=async()=>{if(!(!f.trim()||!S.trim()||!_.trim()))try{const i=await o.createCustomProvider({label:f.trim(),kind:t,protocol:u?g:"openai-compatible",baseUrl:S.trim(),apiKey:C.trim()||void 0,defaultModel:_.trim(),vision:t==="llm"?R:void 0});c(i)}catch{}};return e.jsxs("div",{className:"space-y-2.5","data-testid":`${r}-provider-form`,children:[e.jsx("div",{className:"text-label font-bold text-ink-strong",children:x(h)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:f,onChange:i=>y(i.target.value),placeholder:x("settings.custom.label_ph"),"data-testid":`${r}-label`,className:`${he} min-w-0 flex-1 px-2.5 py-1.5`}),u&&e.jsxs("select",{value:g,onChange:i=>T(i.target.value),"data-testid":`${r}-protocol`,className:`${he} px-2 py-1.5`,children:[e.jsx("option",{value:"openai-compatible",children:x("settings.proto.openai")}),e.jsx("option",{value:"anthropic",children:"Anthropic"}),e.jsx("option",{value:"google",children:"Google"})]})]}),e.jsx("input",{type:"text",value:S,onChange:i=>W(i.target.value),placeholder:x("settings.custom.baseurl_ph"),"data-testid":`${r}-baseurl`,className:`${he} w-full px-2.5 py-1.5 font-mono`}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:_,onChange:i=>L(i.target.value),placeholder:x(v),"data-testid":`${r}-model`,className:`${he} min-w-0 flex-1 px-2.5 py-1.5 font-mono`}),e.jsx("input",{type:"password",value:C,onChange:i=>M(i.target.value),placeholder:x("settings.custom.apikey_ph"),"data-testid":`${r}-apikey`,className:`${he} min-w-0 flex-1 px-2.5 py-1.5`})]}),t==="llm"&&e.jsxs("label",{className:"inline-flex items-center gap-2 text-label cursor-pointer select-none","data-testid":`${r}-vision`,children:[e.jsx("input",{type:"checkbox",checked:R,onChange:i=>A(i.target.checked),className:"w-4 h-4 rounded accent-brand"}),e.jsx("span",{className:"text-ink-strong",children:x("settings.custom.vision")}),e.jsx("span",{className:"text-ink-faint",children:x("settings.custom.visionHint")})]}),z&&e.jsxs("div",{className:`text-label rounded p-2 inline-flex items-start gap-1.5 ${z.ok?"bg-brand/10 text-brand":"bg-warning/10 text-warning"}`,children:[z.ok?e.jsx(oe,{className:"w-4 h-4 mt-px shrink-0","aria-hidden":"true"}):e.jsx(pe,{className:"w-4 h-4 mt-px shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"break-words",children:z.detail})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>void w(),disabled:!S.trim()||!_.trim()||D,"data-testid":`${r}-test`,className:"btn-3d-neutral px-3 py-1.5 text-label disabled:opacity-40",children:x(D?"settings.testing":"settings.test")}),e.jsx("button",{onClick:()=>void k(),disabled:!f.trim()||!S.trim()||!_.trim(),"data-testid":`${r}-save`,className:"btn-3d-brand px-3 py-1.5 text-label disabled:opacity-40",children:x("settings.custom.save")}),p&&e.jsx("button",{onClick:p,className:"text-label text-ink-muted hover:text-ink-strong px-3 py-1.5 transition-colors",children:x("action.cancel")})]})]})}const Ie="lookatstudy-theme",We="auto",Be="(prefers-color-scheme: dark)";function Ce(){return typeof window>"u"||window.matchMedia(Be).matches?"dark":"light"}function kt(){if(typeof localStorage>"u")return We;const t=localStorage.getItem(Ie);return t==="auto"||t==="light"||t==="dark"?t:We}function _e(t){const u=document.documentElement;u.classList.remove("dark","light"),u.classList.add(t),window.dispatchEvent(new CustomEvent("theme-changed",{detail:{resolved:t}}))}function Nt(){const[t,u]=n.useState(()=>kt()),[r,h]=n.useState(()=>t==="auto"?Ce():t),v=n.useCallback(l=>{u(l),localStorage.setItem(Ie,l);const c=l==="auto"?Ce():l;h(c),_e(c)},[]);return n.useEffect(()=>{if(t!=="auto")return;const l=window.matchMedia(Be),c=p=>{const x=p.matches?"dark":"light";h(x),_e(x)};return l.addEventListener("change",c),()=>l.removeEventListener("change",c)},[t]),n.useEffect(()=>{const l=t==="auto"?Ce():t;h(l),_e(l)},[t]),{mode:t,resolved:r,setMode:v}}const yt="0.33.0",St={version:yt};function Ne(){window.dispatchEvent(new Event(gt))}const J="bg-surface-1 text-ink text-body rounded-lg border border-[var(--border)] focus:border-brand focus:outline-none transition-colors placeholder:text-ink-faint",H="bg-surface-3 text-ink-muted hover:bg-surface-3 hover:bg-surface-3 hover:text-ink-strong",q="bg-brand text-white shadow-sm";function N(t){return t?"px-4 py-3.5 border-t border-[var(--border-faint)]":"px-4 py-3.5"}function At(){const t=ne(),[u,r]=n.useState([]),[h,v]=n.useState([]),[l,c]=n.useState("glm"),[p,x]=n.useState(""),[f,y]=n.useState(""),[g,T]=n.useState(null),[S,W]=n.useState(!1),[C,M]=n.useState(null),[_,L]=n.useState(!1),[R,A]=n.useState(!1),[D,U]=n.useState([]),[z,d]=n.useState(!1),[w,k]=n.useState(null),[i,E]=n.useState(null),[$,I]=n.useState(""),[m,X]=n.useState(!1),Z=Nt(),ce=async a=>{if(V)try{await o.updateCustomProvider(V.id,{vision:a}),await O()}catch{}},de=async()=>{d(!0),k(null);try{const a=await o.discoverModels();a.ok&&a.models?U(a.models):k(a.error||t("settings.discover_failed"))}catch(a){k(a instanceof Error?a.message:String(a))}finally{d(!1)}},O=n.useCallback(async()=>{try{const[a,j,K,se]=await Promise.all([o.getProviderPresets(),o.listCustomProviders(),o.getSetting("active_provider"),o.getSetting("active_model")]);r(a),v(j);const B=K??"glm";if(c(B),B.startsWith("custom-")){const P=j.find(F=>F.id===B);T(P!=null&&P.hasApiKey?t("settings.key.configured"):null)}else{const P=a.find(F=>F.id===B);if(P){const F=await o.getSetting(P.apiKeySetting);T(F?`${F.slice(0,4)}…${F.slice(-4)}`:null)}}if(B.startsWith("custom-")){const P=j.find(F=>F.id===B);x(se??(P==null?void 0:P.defaultModel)??"")}else{const P=a.find(F=>F.id===B);x(se??(P==null?void 0:P.defaultModel)??"")}}catch(a){console.error("[SettingsView] load() failed:",a)}},[t]);n.useEffect(()=>{O()},[O]);const ue=async a=>{c(a),M(null),y("");const j=u.find(K=>K.id===a);if(j){const K=await o.getSetting(j.apiKeySetting);T(K?`${K.slice(0,4)}…${K.slice(-4)}`:null),x(p||j.defaultModel)}},ge=async()=>{L(!1);try{if(await o.setSetting("active_provider",l),await o.setSetting("active_model",p),f.trim()){const a=u.find(j=>j.id===l);a&&(await o.setSetting(a.apiKeySetting,f.trim()),T(`${f.trim().slice(0,4)}…${f.trim().slice(-4)}`),y(""))}L(!0),setTimeout(()=>L(!1),2e3),window.dispatchEvent(new Event("llm-config-changed"))}catch{}},Y=async()=>{W(!0),M(null);try{const a=await o.testLlmConnection();M(a)}catch(a){M({ok:!1,detail:a instanceof Error?a.message:String(a),errorKind:"unknown"})}finally{W(!1)}},fe=async a=>{await o.setSetting("active_provider",a.id),await o.setSetting("active_model",a.defaultModel),c(a.id),x(a.defaultModel),A(!1),await O(),window.dispatchEvent(new Event("llm-config-changed"))},ie=async a=>{try{await o.deleteCustomProvider(a),l===a&&(await o.setSetting("active_provider","glm"),c("glm")),await O()}catch{}},V=l.startsWith("custom-")?h.find(a=>a.id===l):null;n.useEffect(()=>{if(!V)return;const a=V.models.find(j=>j.id===p);I(a!=null&&a.contextWindow?String(a.contextWindow):"")},[V,p]);const be=async()=>{var B,P;if(!V)return;const a=$.trim().replace(/[,\s_]/g,""),j=/^(\d+)([km]?)$/i.exec(a);if(a!==""&&!j)return;const K=((B=j==null?void 0:j[2])==null?void 0:B.toLowerCase())==="k"?1e3:((P=j==null?void 0:j[2])==null?void 0:P.toLowerCase())==="m"?1e6:1,se=a===""||!j?null:Math.max(1,Math.round(parseInt(j[1],10)*K));X(!0);try{const F=V.models.map(Q=>Q.id===p?{...Q,contextWindow:se}:Q);await o.updateCustomProvider(V.id,{models:F}),await O(),window.dispatchEvent(new Event("llm-config-changed"))}catch{}finally{X(!1)}},te=l.startsWith("custom-")?null:u.find(a=>a.id===l);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-5 pt-5 space-y-6",children:[e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.ai")}),e.jsxs("div",{className:"surface-card overflow-hidden",children:[e.jsxs("div",{className:N(!1),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-2",children:t("settings.row.provider")}),e.jsxs("div",{className:"flex flex-wrap gap-1.5","data-testid":"provider-grid",children:[u.map(a=>e.jsx("button",{onClick:()=>ue(a.id),"data-testid":`provider-card-${a.id}`,"aria-pressed":l===a.id,className:`px-3 py-1.5 rounded-lg text-label font-medium whitespace-nowrap transition-colors ${l===a.id?q:H}`,children:a.label},a.id)),h.filter(a=>a.kind==="llm").map(a=>e.jsxs("button",{onClick:()=>ue(a.id),"data-testid":`provider-card-${a.id}`,"aria-pressed":l===a.id,className:`px-3 py-1.5 rounded-lg text-label font-medium whitespace-nowrap transition-colors inline-flex items-center gap-1 ${l===a.id?q:H}`,children:[e.jsx(ze,{className:"w-3.5 h-3.5","aria-hidden":"true"}),a.label]},a.id)),e.jsxs("button",{onClick:()=>A(a=>!a),"data-testid":"add-custom-provider",className:"px-3 py-1.5 rounded-lg text-label whitespace-nowrap inline-flex items-center gap-1 border border-dashed border-[var(--border)] text-ink-muted hover:border-ink-muted hover:text-ink-strong transition-colors",children:[e.jsx(Ue,{className:"w-3.5 h-3.5","aria-hidden":"true"}),t("settings.add_custom")]})]})]}),R&&e.jsx("div",{className:"px-4 py-3.5 bg-surface-1 border-t border-[var(--border-faint)]",children:e.jsx(ye,{kind:"llm",testPrefix:"custom",onSaved:a=>void fe(a),onCancel:()=>A(!1)})}),h.length>0&&l.startsWith("custom-")&&e.jsx("div",{className:N(!0),children:e.jsx("button",{onClick:a=>{const j=a.currentTarget.getBoundingClientRect(),K=h.find(se=>se.id===l);K&&E({id:K.id,label:K.label,rect:j})},className:"text-label text-warning hover:underline",children:t("settings.delete_custom")})}),te&&e.jsxs(e.Fragment,{children:[te.baseUrl&&e.jsxs("div",{className:N(!0),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1.5",children:"Base URL"}),e.jsx("code",{className:"text-label text-ink-faint font-mono break-all",children:te.baseUrl})]}),e.jsxs("div",{className:N(!0),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-label font-medium text-ink-strong shrink-0 w-14",children:t("settings.model")}),e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[e.jsxs("select",{value:p,onChange:a=>x(a.target.value),"data-testid":"model-select",className:`${J} flex-1 px-2.5 py-1.5`,children:[te.models.map(a=>e.jsx("option",{value:a.id,children:a.id},a.id)),l==="openrouter"&&D.map(a=>e.jsx("option",{value:a.id,children:a.id},a.id))]}),l==="openrouter"&&e.jsxs("button",{onClick:de,disabled:z,"data-testid":"discover-models-btn",className:"text-label text-accent hover:underline disabled:opacity-40 whitespace-nowrap inline-flex items-center gap-1",children:[e.jsx(ft,{className:`w-3.5 h-3.5 ${z?"animate-spin":""}`,"aria-hidden":"true"}),t(z?"settings.discovering":"settings.refresh")]})]})]}),w&&e.jsx("div",{className:"text-label text-warning mt-1.5 ml-[68px]",children:w})]}),e.jsx("div",{className:N(!0),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-label font-medium text-ink-strong shrink-0 w-14",children:t("settings.apikey")}),e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[g&&e.jsxs("span",{className:"text-label text-brand shrink-0 inline-flex items-center gap-1",children:[e.jsx(oe,{className:"w-3.5 h-3.5","aria-hidden":"true"}),g]}),e.jsx("input",{type:"password",value:f,onChange:a=>y(a.target.value),placeholder:t(g?"settings.key.overwrite_ph":"settings.key.paste_ph"),"data-testid":"settings-key-input",className:`${J} flex-1 px-2.5 py-1.5`}),e.jsx("a",{href:te.keyUrl,target:"_blank",rel:"noopener noreferrer",className:"text-label text-brand hover:underline whitespace-nowrap",children:t("settings.key.get")})]})]})}),e.jsx("div",{className:N(!0),children:e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 min-w-0",children:[e.jsx("button",{onClick:Y,disabled:S,"data-testid":"test-connection-btn",className:"btn-3d-neutral px-3 py-1.5 text-label disabled:opacity-40",children:t(S?"settings.testing":"settings.test")}),C&&e.jsxs("span",{className:`text-label inline-flex items-center gap-1 min-w-0 break-words ${C.ok?"text-brand":"text-warning"}`,children:[C.ok?e.jsx(oe,{className:"w-4 h-4 shrink-0","aria-hidden":"true"}):e.jsx(pe,{className:"w-4 h-4 shrink-0","aria-hidden":"true"}),C.detail]})]})})]}),V&&!te&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:N(!0),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1.5",children:"Base URL"}),e.jsx("code",{className:"text-label text-ink-faint font-mono break-all",children:V.baseUrl})]}),e.jsx("div",{className:N(!0),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-label font-medium text-ink-strong shrink-0 w-14",children:t("settings.model")}),V.models.length>1?e.jsx("select",{value:p,onChange:a=>x(a.target.value),"data-testid":"model-select-custom",className:`${J} flex-1 px-2.5 py-1.5`,children:V.models.map(a=>e.jsx("option",{value:a.id,children:a.id},a.id))}):e.jsx("input",{type:"text",value:p,onChange:a=>x(a.target.value),placeholder:t("settings.custom.model_ph"),"data-testid":"model-input-custom",className:`${J} flex-1 px-2.5 py-1.5 font-mono`})]})}),e.jsxs("div",{className:N(!0),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1.5",children:t("settings.custom.windowLabel")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",inputMode:"numeric",value:$,onChange:a=>I(a.target.value),placeholder:t("settings.custom.windowPh"),"data-testid":"context-window-input",className:`${J} flex-1 px-2.5 py-1.5 font-mono tabular-nums`}),e.jsx("button",{onClick:be,disabled:m,"data-testid":"context-window-save",className:"btn-3d-neutral px-3 py-1.5 text-label shrink-0 disabled:opacity-40",children:t("settings.custom.save")})]}),e.jsx("div",{className:"text-caption text-ink-faint mt-1",children:t("settings.custom.windowHint")})]}),e.jsx("div",{className:N(!0),children:e.jsxs("label",{className:"inline-flex items-center gap-2 text-label cursor-pointer select-none","data-testid":"custom-vision-toggle",children:[e.jsx("input",{type:"checkbox",checked:V.vision,onChange:a=>void ce(a.target.checked),className:"w-4 h-4 rounded accent-brand"}),e.jsx("span",{className:"text-ink-strong",children:t("settings.custom.vision")}),e.jsx("span",{className:"text-ink-faint",children:t("settings.custom.visionHint")})]})}),e.jsx("div",{className:N(!0),children:e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 min-w-0",children:[e.jsx("button",{onClick:Y,disabled:S,"data-testid":"test-connection-btn",className:"btn-3d-neutral px-3 py-1.5 text-label disabled:opacity-40",children:t(S?"settings.testing":"settings.test")}),C&&e.jsxs("span",{className:`text-label inline-flex items-center gap-1 min-w-0 break-words ${C.ok?"text-brand":"text-warning"}`,children:[C.ok?e.jsx(oe,{className:"w-4 h-4 shrink-0","aria-hidden":"true"}):e.jsx(pe,{className:"w-4 h-4 shrink-0","aria-hidden":"true"}),C.detail]})]})})]})]})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.vision")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsx(_t,{activeProvider:l,activeModel:p,presets:u,customProviders:h,onProvidersChanged:()=>void O()})})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.speech")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsx(Pt,{})})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.memory")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsx($t,{})})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.companion")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsx(Et,{})})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.appearance")}),e.jsxs("div",{className:"surface-card overflow-hidden",children:[e.jsxs("div",{className:N(!1),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-2",children:t("settings.row.theme")}),e.jsx("div",{className:"flex gap-2",children:[{mode:"auto",label:t("settings.theme.auto")},{mode:"light",label:t("settings.theme.light")},{mode:"dark",label:t("settings.theme.dark")}].map(({mode:a,label:j})=>e.jsx("button",{onClick:()=>Z.setMode(a),"data-testid":`theme-${a}`,"aria-pressed":Z.mode===a,className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${Z.mode===a?q:H}`,children:j},a))}),e.jsx("p",{className:"text-label text-ink-muted mt-2",children:Z.mode==="auto"?t("settings.theme.following",{mode:t(`settings.theme.${Z.resolved}`)}):null})]}),e.jsxs("div",{className:N(!0),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-2",children:t("settings.row.interface_lang")}),e.jsx("div",{className:"flex gap-2",children:["zh-CN","en"].map(a=>e.jsx("button",{onClick:()=>ut(a),"data-testid":`lang-${a}`,"aria-pressed":Ke()===a,className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${Ke()===a?q:H}`,children:a==="zh-CN"?"中文":"English"},a))})]}),e.jsxs("div",{className:N(!0),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-2",children:t("settings.row.import_lang")}),e.jsx(Ct,{})]})]})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.data")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsx(Mt,{})})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.about")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsxs("div",{className:N(!1),children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("div",{className:"text-label font-medium text-ink-strong",children:t("settings.row.version")}),e.jsxs("a",{href:"https://github.com/Kaiji-Z/LookatStudy/releases",target:"_blank",rel:"noopener noreferrer",className:"text-label font-mono text-brand hover:underline","data-testid":"settings-version",children:["v",St.version]})]}),e.jsx("p",{className:"text-label text-ink-muted mt-2",children:t("settings.version.hint")})]})})]})]}),e.jsxs("div",{className:"sticky bottom-0 px-5 py-3 bg-surface-0 border-t border-[var(--border)] flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-label text-ink-muted",children:t("settings.footer.hint")}),e.jsxs("button",{onClick:ge,"data-testid":"settings-save",className:"btn-3d-brand px-5 py-2 text-body inline-flex items-center gap-1.5",children:[_&&e.jsx(xt,{className:"w-4 h-4","aria-hidden":"true"}),t(_?"settings.saved_text":"settings.footer.save")]})]}),i&&e.jsx(Pe,{anchorRect:i.rect,message:t("settings.delete_custom_confirm",{name:i.label}),danger:!0,confirmLabel:t("action.delete"),testid:"custom-provider-delete-confirm",onConfirm:()=>{ie(i.id),E(null)},onCancel:()=>E(null)})]})}function Ct(){const[t,u]=n.useState("en"),[r,h]=n.useState(!1);n.useEffect(()=>{o.getSetting("pref_lang").then(c=>{c&&u(c),h(!0)})},[]);const v=async c=>{u(c),await o.setSetting("pref_lang",c)},l=[{code:"en",label:"English"},{code:"zh-CN",label:"简体中文"},{code:"zh-TW",label:"繁體中文"}];return r?e.jsx("div",{className:"flex gap-2","data-testid":"pref-lang-options",children:l.map(c=>e.jsx("button",{onClick:()=>v(c.code),"data-testid":`pref-lang-${c.code}`,"aria-pressed":t===c.code,className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${t===c.code?q:H}`,children:c.label},c.code))}):null}function _t({activeProvider:t,activeModel:u,presets:r,customProviders:h,onProvidersChanged:v}){const l=ne(),[c,p]=n.useState(!1),[x,f]=n.useState(!1),[y,g]=n.useState(""),[T,S]=n.useState(!1),[W,C]=n.useState(!1),[M,_]=n.useState(null),[L,R]=n.useState(!1);n.useEffect(()=>{Promise.all([o.getSetting("flag_multimodal_import"),o.getSetting("vision_provider_override"),o.getSetting("vision_model_override"),o.getSetting("flag_math_vision")]).then(([m,X,Z])=>{p(m==="true"),g(X??""),R(Z==="true"),f(!0)})},[]);const A=async()=>{const m=!c;p(m),await o.setSetting("flag_multimodal_import",String(m))},D=async()=>{const m=!L;R(m),await o.setSetting("flag_math_vision",String(m))},U=async m=>{await o.setSetting("vision_provider_override",m.id),await o.setSetting("vision_model_override",m.defaultModel),g(m.id),S(!1)},z=async()=>{await o.setSetting("vision_provider_override",""),await o.setSetting("vision_model_override",""),g(""),S(!1)},[d,w]=n.useState(null),k=async m=>{try{y===m&&(await o.setSetting("vision_provider_override",""),await o.setSetting("vision_model_override",""),g("")),await o.deleteCustomProvider(m)}catch{}finally{v==null||v()}},i=async()=>{if(!W){C(!0),_(null);try{const m=await o.testLlmConnection({vision:!0});_({ok:m.ok,detail:m.detail})}catch(m){_({ok:!1,detail:m instanceof Error?m.message:String(m)})}finally{C(!1)}}},E=h.filter(m=>m.kind==="vision"),$=y.startsWith("custom-")?h.find(m=>m.id===y):null,I=y&&!y.startsWith("custom-")?r.find(m=>m.id===y):null;return x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-4 py-3.5 flex items-center gap-3",children:[e.jsx(re,{checked:c,onChange:A,label:l("settings.multimodal.toggle"),testid:"multimodal-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-body font-medium text-ink-strong",children:l("settings.multimodal.toggle")}),e.jsx("div",{className:"text-label text-ink-muted",children:l("settings.multimodal.toggle.desc")})]})]}),e.jsxs("div",{className:"px-4 py-3.5 border-t border-[var(--border-faint)] space-y-3",children:[e.jsxs("div",{className:"text-label text-ink-muted bg-ink/5 rounded-lg p-3",children:[e.jsx("div",{className:"font-medium mb-1",children:l("settings.multimodal.current_model",{model:u||l("settings.multimodal.not_selected")})}),e.jsx("div",{children:t.startsWith("custom-")?l("settings.multimodal.hint_custom"):l("settings.multimodal.hint_preset")})]}),e.jsxs("div",{className:"bg-ink/5 rounded-lg p-3",children:[e.jsx("div",{className:"text-label font-medium text-ink-muted mb-2",children:l("settings.multimodal.override_title")}),e.jsx("div",{className:"text-caption text-ink-muted mb-2",children:l("settings.multimodal.override_bridge_hint")}),e.jsxs("div",{className:"space-y-3 mt-1",children:[$&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-label",children:[e.jsx(ze,{className:"w-3.5 h-3.5 text-ink-faint shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"font-medium text-ink-strong",children:$.label}),e.jsx("code",{className:"text-ink-faint font-mono break-all",children:$.defaultModel}),e.jsx("span",{className:"text-ink-faint break-all min-w-0",children:$.baseUrl})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{onClick:()=>void i(),disabled:W,"data-testid":"vision-override-test",className:"btn-3d-neutral px-4 py-1.5 text-label disabled:opacity-50",children:l(W?"settings.testing":"settings.multimodal.test_override")}),e.jsx("button",{onClick:()=>S(m=>!m),className:"text-label text-accent hover:underline",children:l("settings.multimodal.replace_custom")}),e.jsx("button",{onClick:()=>void z(),className:"text-label text-ink-muted hover:text-ink-strong",children:l("settings.multimodal.stop_override")}),e.jsx("button",{onClick:m=>{m.stopPropagation(),w({id:$.id,label:$.label,rect:m.currentTarget.getBoundingClientRect()})},"data-testid":`vision-delete-${$.id}`,className:"text-label text-ink-muted hover:text-warning",children:l("action.delete")}),M&&e.jsxs("span",{className:`text-label inline-flex items-center gap-1 ${M.ok?"text-brand":"text-warning"}`,children:[M.ok?e.jsx(oe,{className:"w-4 h-4","aria-hidden":"true"}):e.jsx(pe,{className:"w-4 h-4","aria-hidden":"true"}),M.detail]})]})]}),I&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-label",children:[e.jsx("span",{className:"text-ink-muted",children:l("settings.multimodal.legacy_preset",{label:I.label})}),e.jsx("button",{onClick:()=>void z(),className:"text-label text-ink-muted hover:text-ink-strong underline",children:l("settings.multimodal.stop_override")})]}),!$&&!I&&e.jsxs(e.Fragment,{children:[E.map(m=>e.jsxs("span",{className:"relative block",children:[e.jsxs("button",{onClick:()=>void U(m),className:"w-full text-left px-3 py-2 rounded-lg bg-surface-1 hover:bg-surface-3 transition-colors","data-testid":`vision-pick-${m.id}`,children:[e.jsx("span",{className:"text-label font-medium text-ink-strong",children:m.label}),e.jsx("span",{className:"text-label text-ink-faint font-mono break-all ml-2",children:m.defaultModel})]}),e.jsx("button",{type:"button","aria-label":l("action.delete"),"data-tooltip":l("action.delete"),"data-testid":`vision-delete-${m.id}`,onClick:X=>{X.stopPropagation(),w({id:m.id,label:m.label,rect:X.currentTarget.getBoundingClientRect()})},className:"absolute top-1.5 right-1.5 w-6 h-6 rounded-full text-ink-muted hover:text-warning flex items-center justify-center hover:bg-surface-2",children:e.jsx(Te,{className:"w-3.5 h-3.5"})})]},m.id)),(T||E.length===0)&&e.jsx(ye,{kind:"vision",testPrefix:"vision-custom",titleKey:"settings.custom.form_title_vision",modelPhKey:"settings.custom.model_ph_vision",onSaved:m=>void U(m),onCancel:()=>S(!1)}),E.length>0&&e.jsx("button",{onClick:()=>S(m=>!m),className:"text-label text-accent hover:underline",children:l(T?"action.cancel":"settings.custom.new")})]})]})]}),e.jsxs("div",{className:"bg-ink/5 rounded-lg p-3 flex items-center gap-3",children:[e.jsx(re,{checked:L,onChange:D,label:l("settings.mathvision.toggle"),testid:"math-vision-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-label font-medium text-ink-strong",children:l("settings.mathvision.toggle")}),e.jsx("div",{className:"text-caption text-ink-muted",children:l("settings.mathvision.desc")})]})]})]}),d&&e.jsx(Pe,{anchorRect:d.rect,message:l("settings.delete_custom_confirm",{name:d.label}),danger:!0,confirmLabel:l("action.delete"),testid:"vision-provider-delete-confirm",onConfirm:()=>{k(d.id),w(null)},onCancel:()=>w(null)})]}):null}function $t(){const t=ne(),[u,r]=n.useState(!1),[h,v]=n.useState(!1);n.useEffect(()=>{o.getSetting("flag_memory_system").then(c=>{r(c==="true"),v(!0)})},[]);const l=async()=>{const c=!u;r(c),await o.setSetting("flag_memory_system",String(c))};return h?e.jsxs("div",{className:"px-4 py-3.5 flex items-center gap-3",children:[e.jsx(re,{checked:u,onChange:l,label:t("settings.memory.toggle"),testid:"memory-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-body font-medium text-ink-strong",children:t("settings.memory.toggle")}),e.jsx("div",{className:"text-label text-ink-muted",children:t("settings.memory.toggle.desc")})]})]}):null}function Et(){const t=ne(),[u,r]=n.useState(!0),[h,v]=n.useState(!1),l=n.useSyncExternalStore(nt,it),[c,p]=n.useState(!0),[x,f]=n.useState(!1),y=typeof window<"u"&&!!window.__lookatstudyWeb;n.useEffect(()=>{o.getSetting("companion_enabled").then(i=>{r(i!=="false"&&i!=="0"),v(!0)}),o.getSetting("companion_sfx").then(i=>{p(i!=="false"&&i!=="0")}),o.getSetting("companion_pet_mode").then(i=>{f(i==="1")})},[]);const g=async()=>{const i=!u;r(i),await o.setSetting("companion_enabled",String(i)),window.dispatchEvent(new Event("companion-config-changed"))},T=async()=>{const i=!c;p(i),await o.setSetting("companion_sfx",String(i)),window.dispatchEvent(new Event("companion-config-changed"))},S=async()=>{const i=!x;f(i),await o.setSetting("companion_pet_mode",i?"1":"0"),window.dispatchEvent(new Event("companion-config-changed"))},W=async i=>{i!==l.form&&(await o.setSetting("companion_form",i),window.dispatchEvent(new Event("companion-config-changed")))},[C,M]=n.useState([]),[_,L]=n.useState(!1),[R,A]=n.useState(null),[D,U]=n.useState(null),z=n.useCallback(async()=>{try{M((await window.api.companionPackList()).packs)}catch{}},[]);n.useEffect(()=>{z();const i=()=>void z();return window.addEventListener("companion-config-changed",i),()=>window.removeEventListener("companion-config-changed",i)},[z]);const d=async i=>{await window.api.companionPackActivate({id:i}),l.form!=="custom"&&await o.setSetting("companion_form","custom"),await Ee(),window.dispatchEvent(new Event("companion-config-changed"))},w=async i=>{(await window.api.companionPackDelete({id:i})).formReset&&window.dispatchEvent(new Event("companion-config-changed")),A(null),U(null),z()},k=async(i,E)=>{var $;await window.api.companionPackSetVehicle({id:i,vehicle:E}),await z(),($=C.find(I=>I.id===i))!=null&&$.active&&(await Ee(),window.dispatchEvent(new Event("companion-config-changed")))};return h?e.jsxs("div",{className:"px-4 py-3.5 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(re,{checked:u,onChange:g,label:t("settings.companion.toggle"),testid:"companion-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-body font-medium text-ink-strong",children:t("settings.companion.toggle")}),e.jsx("div",{className:"text-label text-ink-muted",children:t("settings.companion.toggle.desc")})]})]}),u&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(re,{checked:c,onChange:T,label:t("settings.companion.sfx"),testid:"companion-sfx-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-body font-medium text-ink-strong",children:t("settings.companion.sfx")}),e.jsx("div",{className:"text-label text-ink-muted",children:t("settings.companion.sfx.desc")})]})]}),!y&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(re,{checked:x,onChange:S,label:t("settings.companion.pet"),testid:"companion-pet-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-body font-medium text-ink-strong",children:t("settings.companion.pet")}),e.jsx("div",{className:"text-label text-ink-muted",children:t("settings.companion.pet.desc")})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-label text-ink-muted mb-2",children:t("settings.companion.form")}),e.jsxs("div",{className:"flex flex-wrap gap-2",role:"radiogroup","aria-label":t("settings.companion.form"),children:[lt.filter(i=>i!=="custom").map(i=>{const E=l.form===i;return e.jsxs("button",{type:"button",role:"radio","aria-checked":E,"data-testid":`companion-form-${i}`,onClick:()=>{W(i)},className:`flex flex-col items-center gap-0.5 rounded-xl p-1.5 border motion-safe:transition-colors
7
+ ${w?"border-[var(--accent)] bg-surface-2 text-ink-strong font-medium":"border-[var(--border-faint)] hover:bg-surface-2 text-ink-muted"}`,children:[e.jsx("span",{"aria-hidden":"true",className:"w-3 h-3 rounded-full border border-black/20",style:{background:$e[d].dot}}),r(`companion.form.${d}.name`)]},d)})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx("input",{ref:R,type:"file",accept:"image/png",className:"hidden","data-testid":"companion-custom-file",onChange:d=>{var w;return void U((w=d.target.files)==null?void 0:w[0])}}),e.jsx("button",{type:"button",disabled:l,onClick:()=>{var d;return(d=R.current)==null?void 0:d.click()},"data-testid":"companion-wizard-pick",className:"rounded-lg border border-[var(--border-faint)] px-3 py-1.5 text-label hover:bg-surface-2 disabled:opacity-50",children:r("companion.wizard.pick")}),l&&e.jsxs("span",{className:"flex items-center gap-1.5 text-label text-ink-muted","data-testid":"companion-custom-busy",children:[e.jsx(mt,{size:14,className:"animate-spin"}),r(f?"companion.custom.applying":"companion.custom.locating"),e.jsxs("span",{className:"tabular-nums",children:[p,"s"]})]}),g&&e.jsx("span",{className:"text-caption text-ink-muted","data-testid":"companion-custom-msg",children:g})]}),f&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-testid":"companion-custom-preview",children:[f.parts.map(d=>e.jsx("img",{src:`data:image/png;base64,${d.pngBase64}`,alt:d.name,title:d.name,className:"h-14 w-14 object-contain rounded-lg bg-surface-2"},d.name)),e.jsx("input",{value:C,onChange:d=>M(d.target.value),placeholder:r("companion.wizard.namePh"),"data-testid":"companion-wizard-name",className:"rounded-lg border border-[var(--border-faint)] bg-surface-0 px-2.5 py-1.5 text-label text-ink-strong placeholder:text-ink-muted w-36"}),e.jsx("button",{type:"button",disabled:l,onClick:()=>void z(),"data-testid":"companion-custom-apply",className:"rounded-lg bg-brand px-3 py-1.5 text-label text-white hover:opacity-90 disabled:opacity-50",children:r("companion.wizard.save")})]})]})]})}),document.body)}const he="bg-ink/[0.04] text-ink-strong text-label rounded-lg border border-transparent focus:border-accent focus:bg-ink/[0.06] transition-colors placeholder:text-ink-faint";function ye({kind:t,showProtocol:u=!0,testPrefix:r="custom",titleKey:h="settings.custom.form_title",modelPhKey:v="settings.custom.model_ph",testOverride:l,onSaved:c,onCancel:p}){const x=ne(),[f,y]=n.useState(""),[g,T]=n.useState("openai-compatible"),[S,W]=n.useState(""),[C,M]=n.useState(""),[_,L]=n.useState(""),[R,A]=n.useState(!1),[D,U]=n.useState(!1),[z,d]=n.useState(null),w=async()=>{if(!(!S.trim()||!_.trim()||D)){U(!0),d(null);try{const i=l?await l({baseUrl:S.trim(),apiKey:C.trim(),model:_.trim()}):await o.testCustomProvider({label:f||x("settings.custom.test_label"),protocol:g,baseUrl:S.trim(),apiKey:C.trim()||void 0,defaultModel:_.trim()});d({ok:i.ok,detail:i.detail})}catch(i){d({ok:!1,detail:i instanceof Error?i.message:String(i)})}finally{U(!1)}}},k=async()=>{if(!(!f.trim()||!S.trim()||!_.trim()))try{const i=await o.createCustomProvider({label:f.trim(),kind:t,protocol:u?g:"openai-compatible",baseUrl:S.trim(),apiKey:C.trim()||void 0,defaultModel:_.trim(),vision:t==="llm"?R:void 0});c(i)}catch{}};return e.jsxs("div",{className:"space-y-2.5","data-testid":`${r}-provider-form`,children:[e.jsx("div",{className:"text-label font-bold text-ink-strong",children:x(h)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:f,onChange:i=>y(i.target.value),placeholder:x("settings.custom.label_ph"),"data-testid":`${r}-label`,className:`${he} min-w-0 flex-1 px-2.5 py-1.5`}),u&&e.jsxs("select",{value:g,onChange:i=>T(i.target.value),"data-testid":`${r}-protocol`,className:`${he} px-2 py-1.5`,children:[e.jsx("option",{value:"openai-compatible",children:x("settings.proto.openai")}),e.jsx("option",{value:"anthropic",children:"Anthropic"}),e.jsx("option",{value:"google",children:"Google"})]})]}),e.jsx("input",{type:"text",value:S,onChange:i=>W(i.target.value),placeholder:x("settings.custom.baseurl_ph"),"data-testid":`${r}-baseurl`,className:`${he} w-full px-2.5 py-1.5 font-mono`}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:_,onChange:i=>L(i.target.value),placeholder:x(v),"data-testid":`${r}-model`,className:`${he} min-w-0 flex-1 px-2.5 py-1.5 font-mono`}),e.jsx("input",{type:"password",value:C,onChange:i=>M(i.target.value),placeholder:x("settings.custom.apikey_ph"),"data-testid":`${r}-apikey`,className:`${he} min-w-0 flex-1 px-2.5 py-1.5`})]}),t==="llm"&&e.jsxs("label",{className:"inline-flex items-center gap-2 text-label cursor-pointer select-none","data-testid":`${r}-vision`,children:[e.jsx("input",{type:"checkbox",checked:R,onChange:i=>A(i.target.checked),className:"w-4 h-4 rounded accent-brand"}),e.jsx("span",{className:"text-ink-strong",children:x("settings.custom.vision")}),e.jsx("span",{className:"text-ink-faint",children:x("settings.custom.visionHint")})]}),z&&e.jsxs("div",{className:`text-label rounded p-2 inline-flex items-start gap-1.5 ${z.ok?"bg-brand/10 text-brand":"bg-warning/10 text-warning"}`,children:[z.ok?e.jsx(oe,{className:"w-4 h-4 mt-px shrink-0","aria-hidden":"true"}):e.jsx(pe,{className:"w-4 h-4 mt-px shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"break-words",children:z.detail})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>void w(),disabled:!S.trim()||!_.trim()||D,"data-testid":`${r}-test`,className:"btn-3d-neutral px-3 py-1.5 text-label disabled:opacity-40",children:x(D?"settings.testing":"settings.test")}),e.jsx("button",{onClick:()=>void k(),disabled:!f.trim()||!S.trim()||!_.trim(),"data-testid":`${r}-save`,className:"btn-3d-brand px-3 py-1.5 text-label disabled:opacity-40",children:x("settings.custom.save")}),p&&e.jsx("button",{onClick:p,className:"text-label text-ink-muted hover:text-ink-strong px-3 py-1.5 transition-colors",children:x("action.cancel")})]})]})}const Ie="lookatstudy-theme",We="auto",Be="(prefers-color-scheme: dark)";function Ce(){return typeof window>"u"||window.matchMedia(Be).matches?"dark":"light"}function kt(){if(typeof localStorage>"u")return We;const t=localStorage.getItem(Ie);return t==="auto"||t==="light"||t==="dark"?t:We}function _e(t){const u=document.documentElement;u.classList.remove("dark","light"),u.classList.add(t),window.dispatchEvent(new CustomEvent("theme-changed",{detail:{resolved:t}}))}function Nt(){const[t,u]=n.useState(()=>kt()),[r,h]=n.useState(()=>t==="auto"?Ce():t),v=n.useCallback(l=>{u(l),localStorage.setItem(Ie,l);const c=l==="auto"?Ce():l;h(c),_e(c)},[]);return n.useEffect(()=>{if(t!=="auto")return;const l=window.matchMedia(Be),c=p=>{const x=p.matches?"dark":"light";h(x),_e(x)};return l.addEventListener("change",c),()=>l.removeEventListener("change",c)},[t]),n.useEffect(()=>{const l=t==="auto"?Ce():t;h(l),_e(l)},[t]),{mode:t,resolved:r,setMode:v}}const yt="0.33.1",St={version:yt};function Ne(){window.dispatchEvent(new Event(gt))}const J="bg-surface-1 text-ink text-body rounded-lg border border-[var(--border)] focus:border-brand focus:outline-none transition-colors placeholder:text-ink-faint",H="bg-surface-3 text-ink-muted hover:bg-surface-3 hover:bg-surface-3 hover:text-ink-strong",q="bg-brand text-white shadow-sm";function N(t){return t?"px-4 py-3.5 border-t border-[var(--border-faint)]":"px-4 py-3.5"}function At(){const t=ne(),[u,r]=n.useState([]),[h,v]=n.useState([]),[l,c]=n.useState("glm"),[p,x]=n.useState(""),[f,y]=n.useState(""),[g,T]=n.useState(null),[S,W]=n.useState(!1),[C,M]=n.useState(null),[_,L]=n.useState(!1),[R,A]=n.useState(!1),[D,U]=n.useState([]),[z,d]=n.useState(!1),[w,k]=n.useState(null),[i,E]=n.useState(null),[$,I]=n.useState(""),[m,X]=n.useState(!1),Z=Nt(),ce=async a=>{if(V)try{await o.updateCustomProvider(V.id,{vision:a}),await O()}catch{}},de=async()=>{d(!0),k(null);try{const a=await o.discoverModels();a.ok&&a.models?U(a.models):k(a.error||t("settings.discover_failed"))}catch(a){k(a instanceof Error?a.message:String(a))}finally{d(!1)}},O=n.useCallback(async()=>{try{const[a,j,K,se]=await Promise.all([o.getProviderPresets(),o.listCustomProviders(),o.getSetting("active_provider"),o.getSetting("active_model")]);r(a),v(j);const B=K??"glm";if(c(B),B.startsWith("custom-")){const P=j.find(F=>F.id===B);T(P!=null&&P.hasApiKey?t("settings.key.configured"):null)}else{const P=a.find(F=>F.id===B);if(P){const F=await o.getSetting(P.apiKeySetting);T(F?`${F.slice(0,4)}…${F.slice(-4)}`:null)}}if(B.startsWith("custom-")){const P=j.find(F=>F.id===B);x(se??(P==null?void 0:P.defaultModel)??"")}else{const P=a.find(F=>F.id===B);x(se??(P==null?void 0:P.defaultModel)??"")}}catch(a){console.error("[SettingsView] load() failed:",a)}},[t]);n.useEffect(()=>{O()},[O]);const ue=async a=>{c(a),M(null),y("");const j=u.find(K=>K.id===a);if(j){const K=await o.getSetting(j.apiKeySetting);T(K?`${K.slice(0,4)}…${K.slice(-4)}`:null),x(p||j.defaultModel)}},ge=async()=>{L(!1);try{if(await o.setSetting("active_provider",l),await o.setSetting("active_model",p),f.trim()){const a=u.find(j=>j.id===l);a&&(await o.setSetting(a.apiKeySetting,f.trim()),T(`${f.trim().slice(0,4)}…${f.trim().slice(-4)}`),y(""))}L(!0),setTimeout(()=>L(!1),2e3),window.dispatchEvent(new Event("llm-config-changed"))}catch{}},Y=async()=>{W(!0),M(null);try{const a=await o.testLlmConnection();M(a)}catch(a){M({ok:!1,detail:a instanceof Error?a.message:String(a),errorKind:"unknown"})}finally{W(!1)}},fe=async a=>{await o.setSetting("active_provider",a.id),await o.setSetting("active_model",a.defaultModel),c(a.id),x(a.defaultModel),A(!1),await O(),window.dispatchEvent(new Event("llm-config-changed"))},ie=async a=>{try{await o.deleteCustomProvider(a),l===a&&(await o.setSetting("active_provider","glm"),c("glm")),await O()}catch{}},V=l.startsWith("custom-")?h.find(a=>a.id===l):null;n.useEffect(()=>{if(!V)return;const a=V.models.find(j=>j.id===p);I(a!=null&&a.contextWindow?String(a.contextWindow):"")},[V,p]);const be=async()=>{var B,P;if(!V)return;const a=$.trim().replace(/[,\s_]/g,""),j=/^(\d+)([km]?)$/i.exec(a);if(a!==""&&!j)return;const K=((B=j==null?void 0:j[2])==null?void 0:B.toLowerCase())==="k"?1e3:((P=j==null?void 0:j[2])==null?void 0:P.toLowerCase())==="m"?1e6:1,se=a===""||!j?null:Math.max(1,Math.round(parseInt(j[1],10)*K));X(!0);try{const F=V.models.map(Q=>Q.id===p?{...Q,contextWindow:se}:Q);await o.updateCustomProvider(V.id,{models:F}),await O(),window.dispatchEvent(new Event("llm-config-changed"))}catch{}finally{X(!1)}},te=l.startsWith("custom-")?null:u.find(a=>a.id===l);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-5 pt-5 space-y-6",children:[e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.ai")}),e.jsxs("div",{className:"surface-card overflow-hidden",children:[e.jsxs("div",{className:N(!1),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-2",children:t("settings.row.provider")}),e.jsxs("div",{className:"flex flex-wrap gap-1.5","data-testid":"provider-grid",children:[u.map(a=>e.jsx("button",{onClick:()=>ue(a.id),"data-testid":`provider-card-${a.id}`,"aria-pressed":l===a.id,className:`px-3 py-1.5 rounded-lg text-label font-medium whitespace-nowrap transition-colors ${l===a.id?q:H}`,children:a.label},a.id)),h.filter(a=>a.kind==="llm").map(a=>e.jsxs("button",{onClick:()=>ue(a.id),"data-testid":`provider-card-${a.id}`,"aria-pressed":l===a.id,className:`px-3 py-1.5 rounded-lg text-label font-medium whitespace-nowrap transition-colors inline-flex items-center gap-1 ${l===a.id?q:H}`,children:[e.jsx(ze,{className:"w-3.5 h-3.5","aria-hidden":"true"}),a.label]},a.id)),e.jsxs("button",{onClick:()=>A(a=>!a),"data-testid":"add-custom-provider",className:"px-3 py-1.5 rounded-lg text-label whitespace-nowrap inline-flex items-center gap-1 border border-dashed border-[var(--border)] text-ink-muted hover:border-ink-muted hover:text-ink-strong transition-colors",children:[e.jsx(Ue,{className:"w-3.5 h-3.5","aria-hidden":"true"}),t("settings.add_custom")]})]})]}),R&&e.jsx("div",{className:"px-4 py-3.5 bg-surface-1 border-t border-[var(--border-faint)]",children:e.jsx(ye,{kind:"llm",testPrefix:"custom",onSaved:a=>void fe(a),onCancel:()=>A(!1)})}),h.length>0&&l.startsWith("custom-")&&e.jsx("div",{className:N(!0),children:e.jsx("button",{onClick:a=>{const j=a.currentTarget.getBoundingClientRect(),K=h.find(se=>se.id===l);K&&E({id:K.id,label:K.label,rect:j})},className:"text-label text-warning hover:underline",children:t("settings.delete_custom")})}),te&&e.jsxs(e.Fragment,{children:[te.baseUrl&&e.jsxs("div",{className:N(!0),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1.5",children:"Base URL"}),e.jsx("code",{className:"text-label text-ink-faint font-mono break-all",children:te.baseUrl})]}),e.jsxs("div",{className:N(!0),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-label font-medium text-ink-strong shrink-0 w-14",children:t("settings.model")}),e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[e.jsxs("select",{value:p,onChange:a=>x(a.target.value),"data-testid":"model-select",className:`${J} flex-1 px-2.5 py-1.5`,children:[te.models.map(a=>e.jsx("option",{value:a.id,children:a.id},a.id)),l==="openrouter"&&D.map(a=>e.jsx("option",{value:a.id,children:a.id},a.id))]}),l==="openrouter"&&e.jsxs("button",{onClick:de,disabled:z,"data-testid":"discover-models-btn",className:"text-label text-accent hover:underline disabled:opacity-40 whitespace-nowrap inline-flex items-center gap-1",children:[e.jsx(ft,{className:`w-3.5 h-3.5 ${z?"animate-spin":""}`,"aria-hidden":"true"}),t(z?"settings.discovering":"settings.refresh")]})]})]}),w&&e.jsx("div",{className:"text-label text-warning mt-1.5 ml-[68px]",children:w})]}),e.jsx("div",{className:N(!0),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-label font-medium text-ink-strong shrink-0 w-14",children:t("settings.apikey")}),e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[g&&e.jsxs("span",{className:"text-label text-brand shrink-0 inline-flex items-center gap-1",children:[e.jsx(oe,{className:"w-3.5 h-3.5","aria-hidden":"true"}),g]}),e.jsx("input",{type:"password",value:f,onChange:a=>y(a.target.value),placeholder:t(g?"settings.key.overwrite_ph":"settings.key.paste_ph"),"data-testid":"settings-key-input",className:`${J} flex-1 px-2.5 py-1.5`}),e.jsx("a",{href:te.keyUrl,target:"_blank",rel:"noopener noreferrer",className:"text-label text-brand hover:underline whitespace-nowrap",children:t("settings.key.get")})]})]})}),e.jsx("div",{className:N(!0),children:e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 min-w-0",children:[e.jsx("button",{onClick:Y,disabled:S,"data-testid":"test-connection-btn",className:"btn-3d-neutral px-3 py-1.5 text-label disabled:opacity-40",children:t(S?"settings.testing":"settings.test")}),C&&e.jsxs("span",{className:`text-label inline-flex items-center gap-1 min-w-0 break-words ${C.ok?"text-brand":"text-warning"}`,children:[C.ok?e.jsx(oe,{className:"w-4 h-4 shrink-0","aria-hidden":"true"}):e.jsx(pe,{className:"w-4 h-4 shrink-0","aria-hidden":"true"}),C.detail]})]})})]}),V&&!te&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:N(!0),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1.5",children:"Base URL"}),e.jsx("code",{className:"text-label text-ink-faint font-mono break-all",children:V.baseUrl})]}),e.jsx("div",{className:N(!0),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-label font-medium text-ink-strong shrink-0 w-14",children:t("settings.model")}),V.models.length>1?e.jsx("select",{value:p,onChange:a=>x(a.target.value),"data-testid":"model-select-custom",className:`${J} flex-1 px-2.5 py-1.5`,children:V.models.map(a=>e.jsx("option",{value:a.id,children:a.id},a.id))}):e.jsx("input",{type:"text",value:p,onChange:a=>x(a.target.value),placeholder:t("settings.custom.model_ph"),"data-testid":"model-input-custom",className:`${J} flex-1 px-2.5 py-1.5 font-mono`})]})}),e.jsxs("div",{className:N(!0),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1.5",children:t("settings.custom.windowLabel")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",inputMode:"numeric",value:$,onChange:a=>I(a.target.value),placeholder:t("settings.custom.windowPh"),"data-testid":"context-window-input",className:`${J} flex-1 px-2.5 py-1.5 font-mono tabular-nums`}),e.jsx("button",{onClick:be,disabled:m,"data-testid":"context-window-save",className:"btn-3d-neutral px-3 py-1.5 text-label shrink-0 disabled:opacity-40",children:t("settings.custom.save")})]}),e.jsx("div",{className:"text-caption text-ink-faint mt-1",children:t("settings.custom.windowHint")})]}),e.jsx("div",{className:N(!0),children:e.jsxs("label",{className:"inline-flex items-center gap-2 text-label cursor-pointer select-none","data-testid":"custom-vision-toggle",children:[e.jsx("input",{type:"checkbox",checked:V.vision,onChange:a=>void ce(a.target.checked),className:"w-4 h-4 rounded accent-brand"}),e.jsx("span",{className:"text-ink-strong",children:t("settings.custom.vision")}),e.jsx("span",{className:"text-ink-faint",children:t("settings.custom.visionHint")})]})}),e.jsx("div",{className:N(!0),children:e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 min-w-0",children:[e.jsx("button",{onClick:Y,disabled:S,"data-testid":"test-connection-btn",className:"btn-3d-neutral px-3 py-1.5 text-label disabled:opacity-40",children:t(S?"settings.testing":"settings.test")}),C&&e.jsxs("span",{className:`text-label inline-flex items-center gap-1 min-w-0 break-words ${C.ok?"text-brand":"text-warning"}`,children:[C.ok?e.jsx(oe,{className:"w-4 h-4 shrink-0","aria-hidden":"true"}):e.jsx(pe,{className:"w-4 h-4 shrink-0","aria-hidden":"true"}),C.detail]})]})})]})]})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.vision")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsx(_t,{activeProvider:l,activeModel:p,presets:u,customProviders:h,onProvidersChanged:()=>void O()})})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.speech")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsx(Pt,{})})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.memory")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsx($t,{})})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.companion")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsx(Et,{})})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.appearance")}),e.jsxs("div",{className:"surface-card overflow-hidden",children:[e.jsxs("div",{className:N(!1),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-2",children:t("settings.row.theme")}),e.jsx("div",{className:"flex gap-2",children:[{mode:"auto",label:t("settings.theme.auto")},{mode:"light",label:t("settings.theme.light")},{mode:"dark",label:t("settings.theme.dark")}].map(({mode:a,label:j})=>e.jsx("button",{onClick:()=>Z.setMode(a),"data-testid":`theme-${a}`,"aria-pressed":Z.mode===a,className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${Z.mode===a?q:H}`,children:j},a))}),e.jsx("p",{className:"text-label text-ink-muted mt-2",children:Z.mode==="auto"?t("settings.theme.following",{mode:t(`settings.theme.${Z.resolved}`)}):null})]}),e.jsxs("div",{className:N(!0),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-2",children:t("settings.row.interface_lang")}),e.jsx("div",{className:"flex gap-2",children:["zh-CN","en"].map(a=>e.jsx("button",{onClick:()=>ut(a),"data-testid":`lang-${a}`,"aria-pressed":Ke()===a,className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${Ke()===a?q:H}`,children:a==="zh-CN"?"中文":"English"},a))})]}),e.jsxs("div",{className:N(!0),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-2",children:t("settings.row.import_lang")}),e.jsx(Ct,{})]})]})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.data")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsx(Mt,{})})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-label font-bold text-ink-muted mb-2 px-1",children:t("settings.group.about")}),e.jsx("div",{className:"surface-card overflow-hidden",children:e.jsxs("div",{className:N(!1),children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("div",{className:"text-label font-medium text-ink-strong",children:t("settings.row.version")}),e.jsxs("a",{href:"https://github.com/Kaiji-Z/LookatStudy/releases",target:"_blank",rel:"noopener noreferrer",className:"text-label font-mono text-brand hover:underline","data-testid":"settings-version",children:["v",St.version]})]}),e.jsx("p",{className:"text-label text-ink-muted mt-2",children:t("settings.version.hint")})]})})]})]}),e.jsxs("div",{className:"sticky bottom-0 px-5 py-3 bg-surface-0 border-t border-[var(--border)] flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-label text-ink-muted",children:t("settings.footer.hint")}),e.jsxs("button",{onClick:ge,"data-testid":"settings-save",className:"btn-3d-brand px-5 py-2 text-body inline-flex items-center gap-1.5",children:[_&&e.jsx(xt,{className:"w-4 h-4","aria-hidden":"true"}),t(_?"settings.saved_text":"settings.footer.save")]})]}),i&&e.jsx(Pe,{anchorRect:i.rect,message:t("settings.delete_custom_confirm",{name:i.label}),danger:!0,confirmLabel:t("action.delete"),testid:"custom-provider-delete-confirm",onConfirm:()=>{ie(i.id),E(null)},onCancel:()=>E(null)})]})}function Ct(){const[t,u]=n.useState("en"),[r,h]=n.useState(!1);n.useEffect(()=>{o.getSetting("pref_lang").then(c=>{c&&u(c),h(!0)})},[]);const v=async c=>{u(c),await o.setSetting("pref_lang",c)},l=[{code:"en",label:"English"},{code:"zh-CN",label:"简体中文"},{code:"zh-TW",label:"繁體中文"}];return r?e.jsx("div",{className:"flex gap-2","data-testid":"pref-lang-options",children:l.map(c=>e.jsx("button",{onClick:()=>v(c.code),"data-testid":`pref-lang-${c.code}`,"aria-pressed":t===c.code,className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${t===c.code?q:H}`,children:c.label},c.code))}):null}function _t({activeProvider:t,activeModel:u,presets:r,customProviders:h,onProvidersChanged:v}){const l=ne(),[c,p]=n.useState(!1),[x,f]=n.useState(!1),[y,g]=n.useState(""),[T,S]=n.useState(!1),[W,C]=n.useState(!1),[M,_]=n.useState(null),[L,R]=n.useState(!1);n.useEffect(()=>{Promise.all([o.getSetting("flag_multimodal_import"),o.getSetting("vision_provider_override"),o.getSetting("vision_model_override"),o.getSetting("flag_math_vision")]).then(([m,X,Z])=>{p(m==="true"),g(X??""),R(Z==="true"),f(!0)})},[]);const A=async()=>{const m=!c;p(m),await o.setSetting("flag_multimodal_import",String(m))},D=async()=>{const m=!L;R(m),await o.setSetting("flag_math_vision",String(m))},U=async m=>{await o.setSetting("vision_provider_override",m.id),await o.setSetting("vision_model_override",m.defaultModel),g(m.id),S(!1)},z=async()=>{await o.setSetting("vision_provider_override",""),await o.setSetting("vision_model_override",""),g(""),S(!1)},[d,w]=n.useState(null),k=async m=>{try{y===m&&(await o.setSetting("vision_provider_override",""),await o.setSetting("vision_model_override",""),g("")),await o.deleteCustomProvider(m)}catch{}finally{v==null||v()}},i=async()=>{if(!W){C(!0),_(null);try{const m=await o.testLlmConnection({vision:!0});_({ok:m.ok,detail:m.detail})}catch(m){_({ok:!1,detail:m instanceof Error?m.message:String(m)})}finally{C(!1)}}},E=h.filter(m=>m.kind==="vision"),$=y.startsWith("custom-")?h.find(m=>m.id===y):null,I=y&&!y.startsWith("custom-")?r.find(m=>m.id===y):null;return x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-4 py-3.5 flex items-center gap-3",children:[e.jsx(re,{checked:c,onChange:A,label:l("settings.multimodal.toggle"),testid:"multimodal-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-body font-medium text-ink-strong",children:l("settings.multimodal.toggle")}),e.jsx("div",{className:"text-label text-ink-muted",children:l("settings.multimodal.toggle.desc")})]})]}),e.jsxs("div",{className:"px-4 py-3.5 border-t border-[var(--border-faint)] space-y-3",children:[e.jsxs("div",{className:"text-label text-ink-muted bg-ink/5 rounded-lg p-3",children:[e.jsx("div",{className:"font-medium mb-1",children:l("settings.multimodal.current_model",{model:u||l("settings.multimodal.not_selected")})}),e.jsx("div",{children:t.startsWith("custom-")?l("settings.multimodal.hint_custom"):l("settings.multimodal.hint_preset")})]}),e.jsxs("div",{className:"bg-ink/5 rounded-lg p-3",children:[e.jsx("div",{className:"text-label font-medium text-ink-muted mb-2",children:l("settings.multimodal.override_title")}),e.jsx("div",{className:"text-caption text-ink-muted mb-2",children:l("settings.multimodal.override_bridge_hint")}),e.jsxs("div",{className:"space-y-3 mt-1",children:[$&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-label",children:[e.jsx(ze,{className:"w-3.5 h-3.5 text-ink-faint shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"font-medium text-ink-strong",children:$.label}),e.jsx("code",{className:"text-ink-faint font-mono break-all",children:$.defaultModel}),e.jsx("span",{className:"text-ink-faint break-all min-w-0",children:$.baseUrl})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{onClick:()=>void i(),disabled:W,"data-testid":"vision-override-test",className:"btn-3d-neutral px-4 py-1.5 text-label disabled:opacity-50",children:l(W?"settings.testing":"settings.multimodal.test_override")}),e.jsx("button",{onClick:()=>S(m=>!m),className:"text-label text-accent hover:underline",children:l("settings.multimodal.replace_custom")}),e.jsx("button",{onClick:()=>void z(),className:"text-label text-ink-muted hover:text-ink-strong",children:l("settings.multimodal.stop_override")}),e.jsx("button",{onClick:m=>{m.stopPropagation(),w({id:$.id,label:$.label,rect:m.currentTarget.getBoundingClientRect()})},"data-testid":`vision-delete-${$.id}`,className:"text-label text-ink-muted hover:text-warning",children:l("action.delete")}),M&&e.jsxs("span",{className:`text-label inline-flex items-center gap-1 ${M.ok?"text-brand":"text-warning"}`,children:[M.ok?e.jsx(oe,{className:"w-4 h-4","aria-hidden":"true"}):e.jsx(pe,{className:"w-4 h-4","aria-hidden":"true"}),M.detail]})]})]}),I&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-label",children:[e.jsx("span",{className:"text-ink-muted",children:l("settings.multimodal.legacy_preset",{label:I.label})}),e.jsx("button",{onClick:()=>void z(),className:"text-label text-ink-muted hover:text-ink-strong underline",children:l("settings.multimodal.stop_override")})]}),!$&&!I&&e.jsxs(e.Fragment,{children:[E.map(m=>e.jsxs("span",{className:"relative block",children:[e.jsxs("button",{onClick:()=>void U(m),className:"w-full text-left px-3 py-2 rounded-lg bg-surface-1 hover:bg-surface-3 transition-colors","data-testid":`vision-pick-${m.id}`,children:[e.jsx("span",{className:"text-label font-medium text-ink-strong",children:m.label}),e.jsx("span",{className:"text-label text-ink-faint font-mono break-all ml-2",children:m.defaultModel})]}),e.jsx("button",{type:"button","aria-label":l("action.delete"),"data-tooltip":l("action.delete"),"data-testid":`vision-delete-${m.id}`,onClick:X=>{X.stopPropagation(),w({id:m.id,label:m.label,rect:X.currentTarget.getBoundingClientRect()})},className:"absolute top-1.5 right-1.5 w-6 h-6 rounded-full text-ink-muted hover:text-warning flex items-center justify-center hover:bg-surface-2",children:e.jsx(Te,{className:"w-3.5 h-3.5"})})]},m.id)),(T||E.length===0)&&e.jsx(ye,{kind:"vision",testPrefix:"vision-custom",titleKey:"settings.custom.form_title_vision",modelPhKey:"settings.custom.model_ph_vision",onSaved:m=>void U(m),onCancel:()=>S(!1)}),E.length>0&&e.jsx("button",{onClick:()=>S(m=>!m),className:"text-label text-accent hover:underline",children:l(T?"action.cancel":"settings.custom.new")})]})]})]}),e.jsxs("div",{className:"bg-ink/5 rounded-lg p-3 flex items-center gap-3",children:[e.jsx(re,{checked:L,onChange:D,label:l("settings.mathvision.toggle"),testid:"math-vision-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-label font-medium text-ink-strong",children:l("settings.mathvision.toggle")}),e.jsx("div",{className:"text-caption text-ink-muted",children:l("settings.mathvision.desc")})]})]})]}),d&&e.jsx(Pe,{anchorRect:d.rect,message:l("settings.delete_custom_confirm",{name:d.label}),danger:!0,confirmLabel:l("action.delete"),testid:"vision-provider-delete-confirm",onConfirm:()=>{k(d.id),w(null)},onCancel:()=>w(null)})]}):null}function $t(){const t=ne(),[u,r]=n.useState(!1),[h,v]=n.useState(!1);n.useEffect(()=>{o.getSetting("flag_memory_system").then(c=>{r(c==="true"),v(!0)})},[]);const l=async()=>{const c=!u;r(c),await o.setSetting("flag_memory_system",String(c))};return h?e.jsxs("div",{className:"px-4 py-3.5 flex items-center gap-3",children:[e.jsx(re,{checked:u,onChange:l,label:t("settings.memory.toggle"),testid:"memory-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-body font-medium text-ink-strong",children:t("settings.memory.toggle")}),e.jsx("div",{className:"text-label text-ink-muted",children:t("settings.memory.toggle.desc")})]})]}):null}function Et(){const t=ne(),[u,r]=n.useState(!0),[h,v]=n.useState(!1),l=n.useSyncExternalStore(nt,it),[c,p]=n.useState(!0),[x,f]=n.useState(!1),y=typeof window<"u"&&!!window.__lookatstudyWeb;n.useEffect(()=>{o.getSetting("companion_enabled").then(i=>{r(i!=="false"&&i!=="0"),v(!0)}),o.getSetting("companion_sfx").then(i=>{p(i!=="false"&&i!=="0")}),o.getSetting("companion_pet_mode").then(i=>{f(i==="1")})},[]);const g=async()=>{const i=!u;r(i),await o.setSetting("companion_enabled",String(i)),window.dispatchEvent(new Event("companion-config-changed"))},T=async()=>{const i=!c;p(i),await o.setSetting("companion_sfx",String(i)),window.dispatchEvent(new Event("companion-config-changed"))},S=async()=>{const i=!x;f(i),await o.setSetting("companion_pet_mode",i?"1":"0"),window.dispatchEvent(new Event("companion-config-changed"))},W=async i=>{i!==l.form&&(await o.setSetting("companion_form",i),window.dispatchEvent(new Event("companion-config-changed")))},[C,M]=n.useState([]),[_,L]=n.useState(!1),[R,A]=n.useState(null),[D,U]=n.useState(null),z=n.useCallback(async()=>{try{M((await window.api.companionPackList()).packs)}catch{}},[]);n.useEffect(()=>{z();const i=()=>void z();return window.addEventListener("companion-config-changed",i),()=>window.removeEventListener("companion-config-changed",i)},[z]);const d=async i=>{await window.api.companionPackActivate({id:i}),l.form!=="custom"&&await o.setSetting("companion_form","custom"),await Ee(),window.dispatchEvent(new Event("companion-config-changed"))},w=async i=>{(await window.api.companionPackDelete({id:i})).formReset&&window.dispatchEvent(new Event("companion-config-changed")),A(null),U(null),z()},k=async(i,E)=>{var $;await window.api.companionPackSetVehicle({id:i,vehicle:E}),await z(),($=C.find(I=>I.id===i))!=null&&$.active&&(await Ee(),window.dispatchEvent(new Event("companion-config-changed")))};return h?e.jsxs("div",{className:"px-4 py-3.5 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(re,{checked:u,onChange:g,label:t("settings.companion.toggle"),testid:"companion-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-body font-medium text-ink-strong",children:t("settings.companion.toggle")}),e.jsx("div",{className:"text-label text-ink-muted",children:t("settings.companion.toggle.desc")})]})]}),u&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(re,{checked:c,onChange:T,label:t("settings.companion.sfx"),testid:"companion-sfx-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-body font-medium text-ink-strong",children:t("settings.companion.sfx")}),e.jsx("div",{className:"text-label text-ink-muted",children:t("settings.companion.sfx.desc")})]})]}),!y&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(re,{checked:x,onChange:S,label:t("settings.companion.pet"),testid:"companion-pet-toggle"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-body font-medium text-ink-strong",children:t("settings.companion.pet")}),e.jsx("div",{className:"text-label text-ink-muted",children:t("settings.companion.pet.desc")})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-label text-ink-muted mb-2",children:t("settings.companion.form")}),e.jsxs("div",{className:"flex flex-wrap gap-2",role:"radiogroup","aria-label":t("settings.companion.form"),children:[lt.filter(i=>i!=="custom").map(i=>{const E=l.form===i;return e.jsxs("button",{type:"button",role:"radio","aria-checked":E,"data-testid":`companion-form-${i}`,onClick:()=>{W(i)},className:`flex flex-col items-center gap-0.5 rounded-xl p-1.5 border motion-safe:transition-colors
8
8
  ${E?"border-[var(--accent)] bg-surface-2 shadow-card":"border-[var(--border-faint)] hover:bg-surface-2"}`,title:t(`companion.form.${i}.desc`),children:[e.jsx(ot,{form:i,expression:"happy",pose:"float",size:64}),e.jsx("span",{className:`text-label ${E?"text-ink-strong font-medium":"text-ink-muted"}`,children:t(`companion.form.${i}.name`)})]},i)}),C.map(i=>{const E=l.form==="custom"&&i.active;return e.jsxs("span",{className:"relative inline-block",children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":E,"data-testid":`companion-form-pack-${i.id}`,onClick:()=>{d(i.id)},title:i.name,className:`flex flex-col items-center gap-0.5 rounded-xl p-1.5 border motion-safe:transition-colors
9
9
  ${E?"border-[var(--accent)] bg-surface-2 shadow-card":"border-[var(--border-faint)] hover:bg-surface-2"}`,children:[i.thumb?e.jsx("img",{src:i.thumb,alt:"",className:"h-14 w-14 object-contain"}):e.jsx("span",{className:"h-14 w-14 flex items-center justify-center",children:e.jsx("span",{className:"h-9 w-9 rounded-full bg-[#c8a06e]"})}),e.jsx("span",{className:`text-label max-w-20 truncate ${E?"text-ink-strong font-medium":"text-ink-muted"}`,children:i.name})]}),e.jsx("button",{type:"button","aria-label":t("companion.bots.veh"),"data-tooltip":t("companion.bots.veh"),"data-testid":`companion-pack-veh-${i.id}`,onClick:$=>{$.stopPropagation(),U(I=>I===i.id?null:i.id)},className:"absolute -top-1.5 -left-1.5 w-5 h-5 rounded-full border border-black/25 shadow-card hover:scale-110 motion-safe:transition-transform",style:{background:$e[i.vehicle??"silver"].dot}}),e.jsx("button",{type:"button","aria-label":t("companion.custom.delete"),"data-tooltip":t("companion.custom.delete"),onClick:$=>{$.stopPropagation(),A({id:i.id,rect:$.currentTarget.getBoundingClientRect()})},className:"absolute -top-1.5 -right-1.5 w-5 h-5 rounded-full bg-surface-1 border border-[var(--border-faint)] text-ink-muted hover:text-warning flex items-center justify-center",children:e.jsx(Te,{className:"w-3 h-3"})})]},i.id)}),e.jsxs("button",{type:"button",role:"radio","aria-checked":!1,"data-testid":"companion-form-add","aria-label":t("companion.bots.add"),onClick:()=>L(!0),className:"flex flex-col items-center gap-0.5 rounded-xl p-1.5 border border-dashed border-[var(--border-faint)] hover:bg-surface-2",children:[e.jsx("span",{className:"h-14 w-14 flex items-center justify-center text-ink-muted",children:e.jsx(Ue,{className:"w-6 h-6"})}),e.jsx("span",{className:"text-label text-ink-muted",children:t("companion.bots.add")})]})]}),D&&e.jsxs("div",{className:"mt-2 rounded-xl border border-[var(--border-faint)] bg-surface-0 p-2.5","data-testid":"companion-veh-picker",children:[e.jsx("div",{className:"text-caption text-ink-muted mb-1.5",children:t("companion.wizard.vehicle")}),e.jsx("div",{className:"flex flex-wrap gap-1.5",role:"radiogroup","aria-label":t("companion.wizard.vehicle"),children:["silver",...De].map(i=>{var $;const E=((($=C.find(I=>I.id===D))==null?void 0:$.vehicle)??"silver")===i;return e.jsxs("button",{type:"button",role:"radio","aria-checked":E,"data-testid":`companion-veh-pick-${i}`,onClick:()=>void k(D,i),className:`flex items-center gap-1.5 rounded-lg border px-2.5 py-1 text-label motion-safe:transition-colors
10
10
  ${E?"border-[var(--accent)] bg-surface-2 text-ink-strong font-medium":"border-[var(--border-faint)] hover:bg-surface-2 text-ink-muted"}`,children:[e.jsx("span",{"aria-hidden":"true",className:"w-3 h-3 rounded-full border border-black/20",style:{background:$e[i].dot}}),t(i==="silver"?"companion.veh.silver":`companion.form.${i}.name`)]},i)})})]}),R&&e.jsx(Pe,{anchorRect:R.rect,message:t("companion.bots.deleteConfirm"),danger:!0,testid:"companion-pack-delete-confirm",onConfirm:()=>void w(R.id),onCancel:()=>A(null)}),_&&e.jsx(wt,{onClose:()=>L(!1),onSaved:()=>{L(!1),z()}})]})]})]}):null}function re({checked:t,onChange:u,label:r,testid:h}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":r,onClick:u,"data-testid":h,className:`relative w-12 h-6 rounded-full transition-colors shrink-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand/60 focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--surface-2)] ${t?"bg-brand":"bg-ink/20 hover:bg-ink/25"}`,children:e.jsx("span",{className:`absolute left-0.5 top-1/2 -translate-y-1/2 w-5 h-5 rounded-full bg-white shadow transition-transform ${t?"translate-x-6":""}`})})}const Tt=[{id:"zh-CN-XiaoxiaoNeural",label:"zh-CN · 晓晓(女)"},{id:"zh-CN-XiaoyiNeural",label:"zh-CN · 晓伊(女)"},{id:"zh-CN-YunxiNeural",label:"zh-CN · 云希(男)"},{id:"zh-CN-YunyangNeural",label:"zh-CN · 云扬(男·新闻)"},{id:"zh-CN-liaoning-XiaobeiNeural",label:"zh-CN · 晓北(女·东北)"},{id:"zh-CN-shaanxi-XiaoniNeural",label:"zh-CN · 晓妮(女·陕西)"},{id:"en-US-AriaNeural",label:"en-US · Aria(女)"},{id:"en-US-GuyNeural",label:"en-US · Guy(男)"},{id:"en-US-JennyNeural",label:"en-US · Jenny(女)"}],zt=[{sid:"45",label:"zf_xiaobei(女)"},{sid:"46",label:"zf_xiaoni(女)"},{sid:"47",label:"zf_xiaoxiao(女)"},{sid:"48",label:"zf_xiaoyi(女·默认)"},{sid:"49",label:"zm_yunjian(男)"},{sid:"50",label:"zm_yunxi(男)"},{sid:"51",label:"zm_yunxia(男)"},{sid:"52",label:"zm_yunyang(男)"}];function Pt(){const t=ne(),[u,r]=n.useState([]),[h,v]=n.useState(null),[l,c]=n.useState(null),[p,x]=n.useState(null),[f,y]=n.useState(null),[g,T]=n.useState("edge"),[S,W]=n.useState("zh-CN-XiaoxiaoNeural"),[C,M]=n.useState("48"),[_,L]=n.useState("1.0"),[R,A]=n.useState(""),[D,U]=n.useState(""),[z,d]=n.useState([]),w=typeof window<"u"&&"speechSynthesis"in window,[k,i]=n.useState("local"),[E,$]=n.useState("asr-whisper-turbo"),[I,m]=n.useState(!0),[X,Z]=n.useState([]),[ce,de]=n.useState(!1),[O,ue]=n.useState(!1),[ge,Y]=n.useState(!1),[fe,ie]=n.useState(!1),[V,be]=n.useState(!1),[te,a]=n.useState(null),[j,K]=n.useState(!1),[se,B]=n.useState(null),[P,F]=n.useState(null),Q=n.useCallback(()=>{o.listCustomProviders().then(s=>Z(s.filter(b=>b.kind==="tts"||b.kind==="asr"))).catch(()=>{})},[]);n.useEffect(()=>{Promise.all([o.getSetting("tts_engine"),o.getSetting("tts_voice_edge"),o.getSetting("tts_sid_local"),o.getSetting("tts_speed"),o.getSetting("tts_custom_voice"),o.getSetting("tts_system_voice"),o.getSetting("asr_engine"),o.getSetting("asr_local_model"),o.getSetting("asr_auto_stop")]).then(([s,b,G,ee,ke,Fe,Ve,Se,at])=>{s&&T(s),b&&W(b),G&&M(G),ee&&L(ee),ke&&A(ke),Fe&&U(Fe),Ve&&i(Ve),(Se==="asr-whisper-turbo"||Se==="asr-whisper-small")&&$(Se),m(at!=="0")}),Q()},[Q]),n.useEffect(()=>{if(typeof window>"u"||!("speechSynthesis"in window))return;const s=()=>d(pt(window.speechSynthesis.getVoices()));return s(),window.speechSynthesis.addEventListener("voiceschanged",s),()=>window.speechSynthesis.removeEventListener("voiceschanged",s)},[]);const xe=n.useCallback(()=>{window.api.getSpeechModelStatus().then(s=>r(s)).catch(()=>{})},[]);n.useEffect(()=>(xe(),window.api.on("speech:modelProgress",b=>{x({id:b.id,pct:Math.floor(b.progress*100),label:b.currentFile?b.currentFile.split("/").pop()??"":""})})),[xe]);const Oe=s=>{c(null),v(s),x({id:s,pct:0,label:""}),window.api.ensureSpeechModel(s).then(()=>{v(null),x(null),xe()}).catch(b=>{v(null),x(null),c(b instanceof Error?b.message:String(b)),xe()})},Ge=s=>{v(s),y(null),window.api.deleteSpeechModel(s).then(xe).catch(b=>c(b instanceof Error?b.message:String(b))).finally(()=>v(null))},He=s=>t(s==="tts-kokoro"?"settings.speech.model.tts":s==="asr-whisper-turbo"?"settings.speech.model.asr_turbo":"settings.speech.model.asr_small"),qe=s=>t(s==="asr-whisper-turbo"?"settings.speech.model.turbo_short":"settings.speech.model.small_short"),Xe=s=>s.startsWith("asr-whisper")?t("settings.speech.license_mit"):t("settings.speech.license"),Me=s=>t(s==="ready"?"settings.speech.state.ready":s==="error"?"settings.speech.state.error":"settings.speech.state.absent"),Le=s=>{var b;return((b=u.find(G=>G.id===s))==null?void 0:b.state)??"absent"},me=s=>{T(s),a(null),o.setSetting("tts_engine",s),Ne()},Ye=s=>{U(s),o.setSetting("tts_system_voice",s),Ne()},ve=s=>{i(s),B(null),o.setSetting("asr_engine",s)},je=X.filter(s=>s.kind==="tts"),we=X.filter(s=>s.kind==="asr"),ae=g.startsWith("custom-")?je.find(s=>s.id===g)??null:null,le=k.startsWith("custom-")?we.find(s=>s.id===k)??null:null,Je=g==="azure",Ze=k==="groq",Qe=k==="azure",et=async()=>{if(!(!ae||V)){be(!0),a(null);try{a(await o.testCustomTts({providerId:ae.id}))}catch(s){a({ok:!1,detail:s instanceof Error?s.message:String(s)})}finally{be(!1)}}},tt=async()=>{if(!(!le||j)){K(!0),B(null);try{B(await o.testCustomAsr({providerId:le.id}))}catch(s){B({ok:!1,detail:s instanceof Error?s.message:String(s)})}finally{K(!1)}}},st=async(s,b)=>{F(null);try{await o.deleteCustomProvider(s),b==="tts"&&g===s&&me("edge"),b==="asr"&&k===s&&ve("local"),Q()}catch{}},Re=s=>{const b=u.find(ee=>ee.id===s),G=(b==null?void 0:b.state)??"absent";return e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-label font-medium text-ink-strong truncate",children:He(s)}),e.jsxs("div",{className:"text-caption text-ink-muted",children:[Me(G)," · ",Xe(s)]}),h===s&&(p==null?void 0:p.id)===s&&e.jsx("div",{className:"mt-1.5 h-1.5 rounded-full bg-ink/[0.08] overflow-hidden","data-testid":`speech-dl-bar-${s}`,children:e.jsx("div",{className:"h-full bg-brand transition-all",style:{width:`${p.pct}%`}})}),h===s&&(p==null?void 0:p.id)===s&&e.jsxs("div",{className:"text-caption text-ink-faint mt-0.5","data-testid":`speech-dl-pct-${s}`,children:[p.pct,"%",p.label?` · ${p.label}`:""]})]}),G==="ready"?f===s?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-caption text-warning",children:t("settings.speech.confirm_del")}),e.jsx("button",{onClick:()=>Ge(s),className:"text-label text-warning hover:underline","data-testid":`speech-del-confirm-${s}`,children:t("settings.speech.delete")}),e.jsx("button",{onClick:()=>y(null),className:"text-label text-ink-muted hover:text-ink-strong",children:t("action.cancel")})]}):e.jsx("button",{onClick:()=>y(s),disabled:h===s,className:"text-label text-ink-muted hover:text-warning disabled:opacity-40","data-testid":`speech-del-${s}`,children:t("settings.speech.delete")}):e.jsx("button",{onClick:()=>Oe(s),disabled:h!=null||G==="downloading",className:"btn-3d-brand px-3 py-1 text-label disabled:opacity-40","data-testid":`speech-dl-${s}`,children:t(h===s||G==="downloading"?"settings.speech.downloading":"settings.speech.download")})]},s)},Ae=(s,b,G,ee,ke)=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-label",children:[e.jsx(ze,{className:"w-3.5 h-3.5 text-ink-faint shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"font-medium text-ink-strong",children:s.label}),e.jsx("code",{className:"text-ink-faint font-mono break-all",children:s.defaultModel}),e.jsx("span",{className:"text-ink-faint break-all min-w-0",children:s.baseUrl}),s.hasApiKey&&e.jsxs("span",{className:"text-brand shrink-0 inline-flex items-center gap-0.5",children:[e.jsx(oe,{className:"w-3.5 h-3.5","aria-hidden":"true"}),t("settings.speech.key_saved")]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{onClick:()=>void ke(),disabled:G,className:"btn-3d-neutral px-3 py-1 text-label disabled:opacity-40","data-testid":`${b}-custom-test`,children:t(G?"settings.testing":"settings.test")}),P===s.id?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-caption text-warning",children:t("settings.speech.confirm_del_custom")}),e.jsx("button",{onClick:()=>void st(s.id,b),className:"text-label text-warning hover:underline","data-testid":`${b}-custom-del-confirm`,children:t("settings.speech.delete")}),e.jsx("button",{onClick:()=>F(null),className:"text-label text-ink-muted hover:text-ink-strong",children:t("action.cancel")})]}):e.jsx("button",{onClick:()=>F(s.id),className:"text-label text-ink-muted hover:text-warning","data-testid":`${b}-custom-del`,children:t("settings.speech.delete")}),ee&&e.jsxs("span",{className:`text-label inline-flex items-center gap-1 ${ee.ok?"text-brand":"text-warning"}`,children:[ee.ok?e.jsx(oe,{className:"w-4 h-4","aria-hidden":"true"}):e.jsx(pe,{className:"w-4 h-4","aria-hidden":"true"}),ee.detail]})]})]});return e.jsxs("div",{"data-testid":"settings-speech",children:[e.jsxs("div",{className:N(!1),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-2",children:t("settings.speech.tts_title")}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx("button",{onClick:()=>{me("edge"),de(!1),Y(!1)},"data-testid":"tts-engine-edge","aria-pressed":g==="edge",className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${g==="edge"?q:H}`,children:t("settings.speech.engine.edge")}),e.jsxs("button",{onClick:()=>{me("local"),de(!1),Y(!1)},"data-testid":"tts-engine-local","aria-pressed":g==="local",className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${g==="local"?q:H}`,children:[t("settings.speech.engine.local"),Le("tts-kokoro")!=="ready"?` · ${t("settings.speech.state.absent")}`:""]}),e.jsx("button",{onClick:()=>{me("system"),de(!1),Y(!1)},disabled:!w,"data-testid":"tts-engine-system","aria-pressed":g==="system",title:w?void 0:t("settings.speech.engine.system_unavailable"),className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${g==="system"?q:H} ${w?"":"opacity-40 cursor-not-allowed"}`,children:t("settings.speech.engine.system")}),e.jsx("button",{onClick:()=>{de(s=>!s),ce||Y(!1)},"data-testid":"tts-engine-custom","aria-pressed":g.startsWith("custom-")||ce,className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${g.startsWith("custom-")||ce?q:H}`,children:t("settings.speech.engine.custom")}),Je&&e.jsxs("button",{disabled:!0,"data-testid":"tts-engine-azure",className:"px-4 py-2 rounded-xl text-body font-bold opacity-50 cursor-not-allowed",children:["Azure · ",t("settings.speech.legacy")]})]}),g==="edge"&&e.jsx("p",{className:"text-label text-ink-muted mt-2",children:t("settings.speech.engine.edge_note")})]}),g==="edge"&&e.jsxs("div",{className:N(!1),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1.5",children:t("settings.speech.voice")}),e.jsx("select",{value:S,onChange:s=>{W(s.target.value),o.setSetting("tts_voice_edge",s.target.value)},"data-testid":"tts-voice-select",className:`${J} w-full min-w-0 px-2.5 py-1.5`,children:Tt.map(s=>e.jsx("option",{value:s.id,children:s.label},s.id))})]}),g==="local"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:N(!1),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1.5",children:t("settings.speech.voice")}),e.jsx("select",{value:C,onChange:s=>{M(s.target.value),o.setSetting("tts_sid_local",s.target.value)},"data-testid":"tts-sid-select",className:`${J} w-full min-w-0 px-2.5 py-1.5`,children:zt.map(s=>e.jsx("option",{value:s.sid,children:s.label},s.sid))})]}),e.jsx("div",{className:N(!1),children:Re("tts-kokoro")})]}),g==="system"&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:N(!1),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1.5",children:t("settings.speech.voice")}),e.jsxs("select",{value:D,onChange:s=>Ye(s.target.value),"data-testid":"tts-system-voice-select",className:`${J} w-full min-w-0 px-2.5 py-1.5`,children:[e.jsx("option",{value:"",children:t("settings.speech.voice_auto")}),z.map(s=>e.jsx("option",{value:s.name,children:ht(s)},s.voiceURI))]}),e.jsx("p",{className:"text-label text-ink-muted mt-2",children:t("settings.speech.engine.system_note")})]})}),ce&&e.jsx("div",{className:N(!1),children:e.jsxs("div",{className:"space-y-3",children:[ae&&Ae(ae,"tts",V,te,et),ae&&e.jsxs("div",{children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1.5",children:t("settings.speech.voice")}),e.jsx("input",{type:"text",value:R,onChange:s=>A(s.target.value),onBlur:()=>void o.setSetting("tts_custom_voice",R.trim()),placeholder:t("settings.speech.custom_voice_ph"),"data-testid":"tts-custom-voice",className:`${J} w-full min-w-0 px-2.5 py-1.5 font-mono`})]}),!ae&&je.map(s=>e.jsxs("button",{onClick:()=>me(s.id),className:"w-full text-left px-3 py-2 rounded-lg bg-surface-1 hover:bg-surface-3 transition-colors","data-testid":`tts-pick-${s.id}`,children:[e.jsx("span",{className:"text-label font-medium text-ink-strong",children:s.label}),e.jsx("span",{className:"text-label text-ink-faint font-mono break-all ml-2",children:s.defaultModel})]},s.id)),(ge||!ae&&je.length===0)&&e.jsx(ye,{kind:"tts",showProtocol:!1,testPrefix:"tts-custom",titleKey:"settings.custom.form_title_tts",modelPhKey:"settings.custom.model_ph_tts",testOverride:s=>o.testCustomTts({baseUrl:s.baseUrl,apiKey:s.apiKey||void 0,model:s.model}),onSaved:s=>{me(s.id),Y(!1),Q()},onCancel:()=>Y(!1)}),(ae||je.length>0)&&e.jsx("button",{onClick:()=>Y(s=>!s),className:"text-label text-accent hover:underline",children:t(ge?"action.cancel":"settings.custom.new")})]})}),e.jsx("div",{className:N(!0),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-label font-medium text-ink-strong shrink-0 w-14",children:t("settings.speech.speed")}),e.jsx("input",{type:"range",min:"0.5",max:"2",step:"0.05",value:_,onChange:s=>L(s.target.value),onPointerUp:()=>{o.setSetting("tts_speed",_),Ne()},onKeyUp:()=>{o.setSetting("tts_speed",_),Ne()},"data-testid":"tts-speed-range",className:"flex-1 min-w-0 accent-[var(--brand)]"}),e.jsxs("span",{className:"text-label text-ink-muted tabular-nums w-10 text-right","data-testid":"tts-speed-value",children:[Number(_).toFixed(2),"x"]})]})}),e.jsxs("div",{className:N(!0),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-2",children:t("settings.speech.asr_title")}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx("button",{onClick:()=>{ve("local"),ue(!1),ie(!1)},"data-testid":"asr-engine-local","aria-pressed":k==="local",className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${k==="local"?q:H}`,children:t("settings.speech.asr_engine.local")}),e.jsx("button",{onClick:()=>{ue(s=>!s),O||ie(!1)},"data-testid":"asr-engine-custom","aria-pressed":k.startsWith("custom-")||O,className:`px-4 py-2 rounded-xl text-body font-bold transition-all ${k.startsWith("custom-")||O?q:H}`,children:t("settings.speech.engine.custom")}),Ze&&e.jsxs("button",{disabled:!0,"data-testid":"asr-engine-groq",className:"px-4 py-2 rounded-xl text-body font-bold opacity-50 cursor-not-allowed",children:["Groq · ",t("settings.speech.legacy")]}),Qe&&e.jsxs("button",{disabled:!0,"data-testid":"asr-engine-azure",className:"px-4 py-2 rounded-xl text-body font-bold opacity-50 cursor-not-allowed",children:["Azure · ",t("settings.speech.legacy")]})]}),k==="local"?e.jsx("p",{className:"text-label text-ink-muted mt-2",children:t("settings.speech.asr_engine.local_note")}):k.startsWith("custom-")&&e.jsx("p",{className:"text-label text-ink-muted mt-2",children:t("settings.speech.asr_engine.custom_note")})]}),k==="local"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:N(!1),children:[e.jsx("div",{className:"text-label font-medium text-ink-strong mb-1.5",children:t("settings.model")}),e.jsx("select",{value:E,onChange:s=>{$(s.target.value),o.setSetting("asr_local_model",s.target.value)},"data-testid":"asr-model-select",className:`${J} w-full min-w-0 px-2.5 py-1.5`,children:["asr-whisper-turbo","asr-whisper-small"].map(s=>e.jsxs("option",{value:s,children:[qe(s)," · ",Me(Le(s))]},s))})]}),e.jsx("div",{className:N(!1),children:Re(E)})]}),O&&e.jsx("div",{className:N(!1),children:e.jsxs("div",{className:"space-y-3",children:[le&&Ae(le,"asr",j,se,tt),!le&&we.map(s=>e.jsxs("button",{onClick:()=>ve(s.id),className:"w-full text-left px-3 py-2 rounded-lg bg-surface-1 hover:bg-surface-3 transition-colors","data-testid":`asr-pick-${s.id}`,children:[e.jsx("span",{className:"text-label font-medium text-ink-strong",children:s.label}),e.jsx("span",{className:"text-label text-ink-faint font-mono break-all ml-2",children:s.defaultModel})]},s.id)),(fe||!le&&we.length===0)&&e.jsx(ye,{kind:"asr",showProtocol:!1,testPrefix:"asr-custom",titleKey:"settings.custom.form_title_asr",modelPhKey:"settings.custom.model_ph_asr",testOverride:s=>o.testCustomAsr({baseUrl:s.baseUrl,apiKey:s.apiKey||void 0,model:s.model}),onSaved:s=>{ve(s.id),ie(!1),Q()},onCancel:()=>ie(!1)}),(le||we.length>0)&&e.jsx("button",{onClick:()=>ie(s=>!s),className:"text-label text-accent hover:underline",children:t(fe?"action.cancel":"settings.custom.new")})]})}),e.jsxs("div",{className:N(!0),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(re,{checked:I,onChange:()=>{const s=!I;m(s),o.setSetting("asr_auto_stop",s?"1":"0")},label:t("settings.speech.asr_auto_stop"),testid:"asr-auto-stop-toggle"}),e.jsx("div",{className:"text-body font-medium text-ink-strong",children:t("settings.speech.asr_auto_stop")})]}),e.jsx("p",{className:"text-label text-ink-muted mt-2",children:t("settings.speech.asr_ux_note")})]}),l&&e.jsx("div",{className:"px-4 py-3 text-label text-warning break-all",role:"alert",children:l==="engine-unavailable"?t("chat.speech.engine_unavailable"):l})]})}function Mt(){const t=ne(),u=n.useRef(null),[r,h]=n.useState(null),[v,l]=n.useState(!1),[c,p]=n.useState(null);n.useEffect(()=>{o.dshImportDetect().then(h).catch(()=>h({found:!1,path:null,version:null}))},[]);const x=f=>{l(!0),p(null),f.then(p).catch(y=>p({ok:!1,error:String(y)})).finally(()=>l(!1))};return e.jsxs("div",{className:"p-4 space-y-3","data-testid":"settings-dsh-import",children:[e.jsx("div",{className:"text-label font-medium text-ink-strong",children:t("settings.dsh.title")}),e.jsx("p",{className:"text-label text-ink-muted leading-relaxed",children:t("settings.dsh.desc")}),r==null?null:r.found?e.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-testid":"settings-dsh-detected",children:[e.jsx("span",{className:"text-label text-ink-strong",children:t("settings.dsh.detectFound",{v:r.version??"?"})}),e.jsx("button",{onClick:()=>x(o.dshImportFromPath(r.path??"")),disabled:v,"data-testid":"settings-dsh-import-btn",className:"px-3 py-1.5 rounded-xl text-label font-bold btn-3d-brand disabled:opacity-50",children:t(v?"settings.dsh.importing":"settings.dsh.import")})]}):e.jsx("div",{className:"text-label text-ink-muted","data-testid":"settings-dsh-none",children:t("settings.dsh.detectNone")}),e.jsxs("div",{children:[e.jsx("input",{ref:u,type:"file",accept:".json,application/json",className:"hidden","data-testid":"settings-dsh-file-input",onChange:f=>{var g;const y=(g=f.target.files)==null?void 0:g[0];y&&(y.text().then(T=>x(o.dshImportFromText(T))),f.target.value="")}}),e.jsx("button",{onClick:()=>{var f;return(f=u.current)==null?void 0:f.click()},disabled:v,className:"px-3 py-1.5 rounded-xl text-label font-bold btn-3d-neutral disabled:opacity-50",children:t("settings.dsh.pickFile")})]}),v&&!c?e.jsx("div",{className:"text-label text-ink-muted",children:t("settings.dsh.importing")}):null,c!=null&&c.ok?e.jsxs("div",{className:"text-label text-brand leading-relaxed break-all",role:"status","data-testid":"settings-dsh-result",children:[t("settings.dsh.done",{courses:c.coursesCreated+c.coursesMapped+c.coursesRefreshed,nodes:c.nodes,progress:c.progressRows,srs:c.srsRows,xp:c.xpDelta}),c.skippedCourses.length>0?` · ${t("settings.dsh.skipped",{n:c.skippedCourses.length})}`:""]}):c?e.jsxs("div",{className:"text-label text-warning break-all",role:"alert","data-testid":"settings-dsh-error",children:[t("settings.dsh.failed"),": ",c.error??"unknown"]}):null]})}export{At as SettingsView};
@@ -1,4 +1,4 @@
1
- import{r as n,j as e}from"./index-3R9G44mo.js";import{c as f,u as h,e as b,f as g}from"./main-DGGbnUfo.js";import{R as j}from"./rotate-ccw-Cca2hxMT.js";/**
1
+ import{r as n,j as e}from"./index-3R9G44mo.js";import{c as f,u as h,e as b,f as g}from"./main-fDEgiN-S.js";import{R as j}from"./rotate-ccw-QIElN2Wl.js";/**
2
2
  * @license lucide-react v0.468.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{g as p,r as u,d as a}from"./chunk-XCWWM2C3-cz_1pt_w.js";import{p as f}from"./chunk-VII2H2IX-D97vmfRp.js";import{M as c,b as d}from"./cynefin-OW5HDTMX-GVF3BKWE-blsoPqhC.js";import{_ as n,l as o}from"./render-O7CIS3YK-CZ3IDVwW.js";import"./transform-Bd_a5eGM.js";import"./mermaid-layout-elk.core-DiLPr9HM.js";import"./main-DGGbnUfo.js";import"./index-3R9G44mo.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),m=t?parseInt(t,10):0,l=s?parseInt(s,10):1/0;return{min:m,max:l}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},D={parser:R,db:a,renderer:u,styles:p};export{D as diagram};
1
+ import{g as p,r as u,d as a}from"./chunk-XCWWM2C3-RUaVDOLz.js";import{p as f}from"./chunk-VII2H2IX-DZd3RSio.js";import{M as c,b as d}from"./cynefin-OW5HDTMX-GVF3BKWE-DyJbbdgM.js";import{_ as n,l as o}from"./render-O7CIS3YK-ilIoaxFJ.js";import"./transform-Bd_a5eGM.js";import"./mermaid-layout-elk.core-BWBQ_Al5.js";import"./main-fDEgiN-S.js";import"./index-3R9G44mo.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),m=t?parseInt(t,10):0,l=s?parseInt(s,10):1/0;return{min:m,max:l}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},D={parser:R,db:a,renderer:u,styles:p};export{D as diagram};
@@ -1 +1 @@
1
- import{g as p,r as u,d as a}from"./chunk-SVP7TREG-BgA7U0O5.js";import{p as f}from"./chunk-JWPE2WC7-Dx6T5lv2.js";import{_ as n,l as o}from"./mermaid.core-D7fD1FwK.js";import"./transform-Bd_a5eGM.js";import{M as c,b as d}from"./cynefin-OW5HDTMX-D283bZaS.js";import"./main-DGGbnUfo.js";import"./index-3R9G44mo.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},I={parser:R,db:a,renderer:u,styles:p};export{I as diagram};
1
+ import{g as p,r as u,d as a}from"./chunk-SVP7TREG-7Sg7sU_j.js";import{p as f}from"./chunk-JWPE2WC7-BgST7e0p.js";import{_ as n,l as o}from"./mermaid.core-BMxGmpq2.js";import"./transform-Bd_a5eGM.js";import{M as c,b as d}from"./cynefin-OW5HDTMX-CnnFvhFO.js";import"./main-fDEgiN-S.js";import"./index-3R9G44mo.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},I={parser:R,db:a,renderer:u,styles:p};export{I as diagram};