lantern-harness 0.1.44 → 0.2.2

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 (244) hide show
  1. package/CHANGELOG.md +224 -0
  2. package/README.md +25 -8
  3. package/builtin/session/lh-fs.mjs +93 -4
  4. package/builtin/session/lh-nav-groups.mjs +3 -0
  5. package/builtin/session/mcp-client.mjs +7 -3
  6. package/builtin/session/session-runs.mjs +5 -1
  7. package/builtin/session/skill-validation.mjs +72 -0
  8. package/builtin/session/space-skills.mjs +751 -0
  9. package/cli/data-root.mjs +21 -4
  10. package/cli/lantern.mjs +26 -1
  11. package/cli/mcp-server.mjs +2779 -0
  12. package/cli/server.mjs +8 -2
  13. package/config/app.defaults.json +4 -2
  14. package/dist/500.html +9 -6
  15. package/dist/_astro/Base.Du_-4L-4.css +1 -0
  16. package/dist/_astro/Base.astro_astro_type_script_index_0_lang.XUV2H6ea.js +2 -0
  17. package/dist/_astro/BusinessMapBoard.mRxl2G3D.js +5 -0
  18. package/dist/_astro/CaseExecBoard.Cqkxuf5c.js +1 -0
  19. package/dist/_astro/CaseExecutionBoard.CjX4CoKd.js +5 -0
  20. package/dist/_astro/CaseGenerateApp.acgnxl79.js +10 -0
  21. package/dist/_astro/CasesLibrary.zmzOQwdn.js +21 -0
  22. package/dist/_astro/ChatApp.Ben9LFra.js +1 -0
  23. package/dist/_astro/ChatApp.DBi6q7Qv.js +262 -0
  24. package/dist/_astro/{ConfirmDialog.DrrPf1MB.js → ConfirmDialog.DQFd6g2r.js} +1 -1
  25. package/dist/_astro/DashboardBoard.CAJVE2G4.js +5 -0
  26. package/dist/_astro/{DatePicker.Bkl71M49.js → DatePicker.BRO_CjVQ.js} +1 -1
  27. package/dist/_astro/DefectSubmitEntry.BzKXJ-zq.js +2 -0
  28. package/dist/_astro/DocsFileBrowser.apKMbGVf.js +1 -0
  29. package/dist/_astro/{DocsPager.Duf4I68E.js → DocsPager.DMN9-Tjg.js} +1 -1
  30. package/dist/_astro/{DrawerField.BH3p4Q4D.js → DrawerField.CLdvmHc6.js} +1 -1
  31. package/dist/_astro/KnowledgeLibrary.BcoMQeUd.js +1 -0
  32. package/dist/_astro/LifeKrTasksBoard.DJU0-QI-.js +1 -0
  33. package/dist/_astro/LifeKrTodosBoard.GK7KRAO3.js +1 -0
  34. package/dist/_astro/LifeObjectivesBoard.DuKa6Q3k.js +1 -0
  35. package/dist/_astro/LifePlanTypeSelect.Cm2lUmnH.js +1 -0
  36. package/dist/_astro/{LifeReviewsBoard.BPXeVpg1.js → LifeReviewsBoard.BWOOVMtz.js} +3 -3
  37. package/dist/_astro/{LifeShared.tnT7aQON.js → LifeShared.bY2l01Ha.js} +2 -2
  38. package/dist/_astro/LifeStagesBoard.CIzxPOJB.js +1 -0
  39. package/dist/_astro/LifeYearCycleSelect.BlsyPmmI.js +1 -0
  40. package/dist/_astro/LifeYearPlansBoard.DaA9O08j.js +1 -0
  41. package/dist/_astro/MultiSelectDropdown.D-rbpivp.js +1 -0
  42. package/dist/_astro/{NamePromptDialog.Csfnh5eM.js → NamePromptDialog.KPCeXmri.js} +1 -1
  43. package/dist/_astro/NavLibraries.DVR5Ua-S.js +1 -0
  44. package/dist/_astro/PluginsPage.B063QIlQ.js +18 -0
  45. package/dist/_astro/PmBugsBoard.Cu-v0Gfd.js +1 -0
  46. package/dist/_astro/PmIterationsBoard.CgRzkP-j.js +1 -0
  47. package/dist/_astro/{PmProjectDetail.DneFVBpy.js → PmProjectDetail.DVCEh0Lm.js} +1 -1
  48. package/dist/_astro/PmProjectsBoard.z-bQa98r.js +1 -0
  49. package/dist/_astro/PmRequirementsBoard.B0W6bsW2.js +1 -0
  50. package/dist/_astro/PmRequirementsBoard.CyfBI0u_.js +1 -0
  51. package/dist/_astro/PmShared.BQVzwsiz.js +1 -0
  52. package/dist/_astro/ReportsPage.najSzJeT.js +1 -0
  53. package/dist/_astro/ReqAnalysisBoard.BQb8dHFD.js +39 -0
  54. package/dist/_astro/RequirementBreakdownLibrary.Cn6OV6xt.js +2 -0
  55. package/dist/_astro/RequirementsLibrary.CqKNFVsP.js +1 -0
  56. package/dist/_astro/SearchableSelect.DXclLMJI.js +1 -0
  57. package/dist/_astro/SelectDropdown.D7IeyHDI.js +1 -0
  58. package/dist/_astro/SettingsDialog.db3BpFw0.js +1 -0
  59. package/dist/_astro/SlideOverDrawer.BMg2tce6.js +1 -0
  60. package/dist/_astro/SpaceSwitcher.DSUVAPOi.js +7 -0
  61. package/dist/_astro/{TableFieldConfig.C7O-mL-p.js → TableFieldConfig.72AL-8p-.js} +1 -1
  62. package/dist/_astro/{TagSelect.UUXgkMqJ.js → TagSelect.B_r2p0fp.js} +1 -1
  63. package/dist/_astro/TasksBoard.CCDhCSR7.js +1 -0
  64. package/dist/_astro/TemplatesLibrary.peYzrHZ2.js +1 -0
  65. package/dist/_astro/TestReportsLibrary.fWiEyCRx.js +1 -0
  66. package/dist/_astro/TestStatsBoard.BSUBsWSu.js +1 -0
  67. package/dist/_astro/Toast.BydY-X7T.js +1 -0
  68. package/dist/_astro/TodosBoard.By5YdlUe.js +1 -0
  69. package/dist/_astro/UiAutoBoard.BGdlp5Sr.js +3 -0
  70. package/dist/_astro/UiAutoEnvPanel.BUASgPLB.js +10 -0
  71. package/dist/_astro/UiAutoGenerationDialog.D1PyCgrD.js +12 -0
  72. package/dist/_astro/UiAutoProjectsPage.B6A9NlVK.js +3 -0
  73. package/dist/_astro/app-config.Dvfzl5_N.js +1 -0
  74. package/dist/_astro/app-version.CNpnKIb9.js +1 -0
  75. package/dist/_astro/{bash-tools.D9HCzC_7.js → bash-tools.CS2w8LOb.js} +1 -1
  76. package/dist/_astro/business-map.BiJ85oxm.js +1 -0
  77. package/dist/_astro/business-map.DKwdW1VL.css +1 -0
  78. package/dist/_astro/case-gen-run.Cvvdv_kv.js +26 -0
  79. package/dist/_astro/case-prompt.CZ3vWUju.js +2 -0
  80. package/dist/_astro/{case-review.TdDs1WFM.js → case-review.DFWZkoR9.js} +1 -1
  81. package/dist/_astro/{case-template.Cd2xNbgy.js → case-template.Clb7HrDB.js} +1 -1
  82. package/dist/_astro/defect-submit.Dc49lFjm.css +1 -0
  83. package/dist/_astro/defect-workbench.CjTb4FDv.js +6 -0
  84. package/dist/_astro/dialog.XgRGNF_Q.js +1 -0
  85. package/dist/_astro/doc-roots.C-20VD0x.js +1 -0
  86. package/dist/_astro/{hydrate-cache.B15Nrpq0.js → hydrate-cache.O4CIma9y.js} +1 -1
  87. package/dist/_astro/i18n.Cp4so7KR.js +7 -0
  88. package/dist/_astro/{llm.DN5S1KBK.js → llm.BCYNgppW.js} +1 -1
  89. package/dist/_astro/mcp-tools.Kf-lupGn.js +7 -0
  90. package/dist/_astro/{open-docs-in-session.CRiZT022.js → open-docs-in-session.BpcAcBSI.js} +1 -1
  91. package/dist/_astro/plugins.Db9xoFZb.js +1 -0
  92. package/dist/_astro/project-docs.bB9lQ1Ki.js +1 -0
  93. package/dist/_astro/prompts-meta.VAjE4OET.js +2 -0
  94. package/dist/_astro/report-prompt.CwHuOcRN.js +1 -0
  95. package/dist/_astro/req-analysis.C_gARMrB.js +31 -0
  96. package/dist/_astro/requirement-breakdown-library.l0rPd7b3.js +1 -0
  97. package/dist/_astro/{settings.38J2uD5M.js → settings.D02wZj3w.js} +2 -2
  98. package/dist/_astro/space-skills.CPucW8zt.js +1 -0
  99. package/dist/_astro/{spaces-client.DV04tRyD.js → spaces-client.BAtG6PkW.js} +1 -1
  100. package/dist/_astro/story-review.DTN91Vl9.js +7 -0
  101. package/dist/_astro/test-points.C7ZgggQT.js +8 -0
  102. package/dist/_astro/test-reports.0gr6-c_0.js +19 -0
  103. package/dist/_astro/ui-auto-prompt.BmO3ja2m.js +8 -0
  104. package/dist/_astro/{view-prefs.DhdLZjGh.js → view-prefs.COAKEQtZ.js} +1 -1
  105. package/dist/business-map/index.html +983 -0
  106. package/dist/case-exec/index.html +10 -7
  107. package/dist/{prompts → case-execution}/index.html +12 -9
  108. package/dist/cases/generate/index.html +9 -6
  109. package/dist/cases/library/index.html +10 -7
  110. package/dist/dashboard/index.html +10 -7
  111. package/dist/defect-rules/index.html +690 -0
  112. package/dist/defect-submit/index.html +690 -0
  113. package/dist/defect-submit/templates/index.html +690 -0
  114. package/dist/docs/changelog/index.html +265 -51
  115. package/dist/docs/install/index.html +44 -12
  116. package/dist/docs/manual/index.html +213 -75
  117. package/dist/knowledge/index.html +10 -7
  118. package/dist/life/kr-tasks/index.html +10 -7
  119. package/dist/life/kr-todos/index.html +10 -7
  120. package/dist/life/objectives/index.html +10 -7
  121. package/dist/life/reviews/index.html +10 -7
  122. package/dist/life/stages/index.html +10 -7
  123. package/dist/life/year-plans/index.html +10 -7
  124. package/dist/plugins/index.html +10 -7
  125. package/dist/pm/bugs/index.html +10 -7
  126. package/dist/pm/iterations/index.html +10 -7
  127. package/dist/pm/projects/detail/index.html +10 -7
  128. package/dist/pm/projects/index.html +10 -7
  129. package/dist/pm/requirements/index.html +10 -7
  130. package/dist/reports/index.html +10 -7
  131. package/dist/requirement-analysis/index.html +10 -7
  132. package/dist/requirement-breakdowns/index.html +983 -0
  133. package/dist/requirements/index.html +10 -7
  134. package/dist/tasks/index.html +10 -7
  135. package/dist/templates/index.html +10 -7
  136. package/dist/test-automation/index.html +10 -7
  137. package/dist/test-automation/projects/index.html +10 -7
  138. package/dist/test-reports/index.html +10 -7
  139. package/dist/test-stats/index.html +10 -7
  140. package/dist/todos/index.html +10 -7
  141. package/dist/workbench/index.html +9 -6
  142. package/docs/Codex-MCP/351/233/206/346/210/220.md +296 -0
  143. package/docs//344/270/232/345/212/241/345/234/260/345/233/276/350/257/204/344/274/260.md +39 -0
  144. package/docs//344/270/232/345/212/241/345/234/260/345/233/276/350/257/206/345/210/253/351/207/215/346/236/204/346/226/271/346/241/210.md +88 -0
  145. package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +22 -3
  146. package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +41 -1
  147. package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +63 -17
  148. package/docs//346/217/222/344/273/266/344/273/223/345/272/223/344/270/216/346/212/200/350/203/275/346/225/264/345/220/210/346/226/271/346/241/210.md +187 -0
  149. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +208 -69
  150. package/lh-plugins/business-map/assistant.mjs +958 -0
  151. package/lh-plugins/business-map/auth-paths.mjs +61 -0
  152. package/lh-plugins/business-map/jobs.mjs +749 -0
  153. package/lh-plugins/business-map/login.mjs +295 -0
  154. package/lh-plugins/business-map/sources.mjs +1014 -0
  155. package/lh-plugins/case-execution/files.mjs +777 -0
  156. package/lh-plugins/case-execution/service.mjs +959 -0
  157. package/lh-plugins/case-execution-prompt.mjs +33 -0
  158. package/lh-plugins/lh-business-map.mjs +2431 -0
  159. package/lh-plugins/lh-case-execution.mjs +304 -0
  160. package/lh-plugins/lh-config.mjs +13 -0
  161. package/lh-plugins/lh-defect-submit.mjs +989 -0
  162. package/lh-plugins/lh-project-docs.mjs +31 -140
  163. package/lh-plugins/lh-reports.mjs +29 -57
  164. package/lh-plugins/lh-req-analysis.mjs +32 -3
  165. package/lh-plugins/lh-req-breakdown-library.mjs +1084 -0
  166. package/lh-plugins/lh-uiauto.mjs +514 -22
  167. package/lh-plugins/plugin-prompts.mjs +19 -15
  168. package/lh-plugins/req-analysis-revision.mjs +24 -0
  169. package/lh-plugins/test-points-prompt.mjs +2 -3
  170. package/lh-plugins/uiauto-auth-setup.mjs +218 -0
  171. package/lh-plugins/uiauto-explorer/apps.mjs +13 -2
  172. package/lh-plugins/uiauto-explorer/runner.mjs +15 -2
  173. package/lh-plugins/uiauto-explorer/sessions.mjs +305 -17
  174. package/lh-plugins/uiauto-node.mjs +102 -11
  175. package/lh-plugins/uiauto-prompt.mjs +20 -15
  176. package/lh-plugins/uiauto-sso.mjs +407 -0
  177. package/package.json +5 -2
  178. package/skills/case-execution/SKILL.md +30 -0
  179. package/skills/lantern-defect-submit/SKILL.md +15 -0
  180. package/skills/lantern-workflow/SKILL.md +57 -0
  181. package/skills/office/SKILL.md +26 -0
  182. package/dist/_astro/Base.DIbzr8uT.css +0 -1
  183. package/dist/_astro/Base.astro_astro_type_script_index_0_lang.CPR_CfsE.js +0 -2
  184. package/dist/_astro/CaseExecBoard.DICluCbK.js +0 -1
  185. package/dist/_astro/CaseGenerateApp.CcAtVSQJ.js +0 -10
  186. package/dist/_astro/CasesLibrary.Ci_0hYqL.js +0 -21
  187. package/dist/_astro/ChatApp.DFKZOkZy.js +0 -227
  188. package/dist/_astro/DashboardBoard.Qvf8o4v1.js +0 -5
  189. package/dist/_astro/DocsFileBrowser.DwKBffbM.js +0 -1
  190. package/dist/_astro/KnowledgeLibrary.MDpMqeOd.js +0 -1
  191. package/dist/_astro/LifeKrTasksBoard.DsvW_S66.js +0 -1
  192. package/dist/_astro/LifeKrTodosBoard.D2KTqvg1.js +0 -1
  193. package/dist/_astro/LifeObjectivesBoard.B0cDK934.js +0 -1
  194. package/dist/_astro/LifePlanTypeSelect.BELDvMWU.js +0 -1
  195. package/dist/_astro/LifeStagesBoard.CZftLR9K.js +0 -1
  196. package/dist/_astro/LifeYearCycleSelect.Bw2eRbSm.js +0 -1
  197. package/dist/_astro/LifeYearPlansBoard.DB-RJFEl.js +0 -1
  198. package/dist/_astro/MultiSelectDropdown.CBC7aNOv.js +0 -1
  199. package/dist/_astro/NavLibraries.DdQYsZbe.js +0 -1
  200. package/dist/_astro/OverflowHint.CHZeFfUj.js +0 -1
  201. package/dist/_astro/PluginsPage.BVrMtkLi.js +0 -17
  202. package/dist/_astro/PluginsPage.xdbDGigE.js +0 -1
  203. package/dist/_astro/PmBugsBoard.CGpXUTPu.js +0 -1
  204. package/dist/_astro/PmIterationsBoard.BaKiFIam.js +0 -1
  205. package/dist/_astro/PmProjectsBoard.BxoMF9gK.js +0 -1
  206. package/dist/_astro/PmRequirementsBoard.-SI8VZXI.js +0 -1
  207. package/dist/_astro/PmRequirementsBoard.DsK6RF7Q.js +0 -1
  208. package/dist/_astro/PmShared.BK8kWRSV.js +0 -1
  209. package/dist/_astro/PromptMountDialog.mrTx3U5T.js +0 -1
  210. package/dist/_astro/PromptsLibrary.B2LMGsrj.js +0 -1
  211. package/dist/_astro/ReportsPage.B9lGg1_s.js +0 -16
  212. package/dist/_astro/ReqAnalysisBoard.D-KmRwQM.js +0 -39
  213. package/dist/_astro/RequirementsLibrary.cJc-bnGQ.js +0 -1
  214. package/dist/_astro/SearchableSelect.SyLRS-Jj.js +0 -1
  215. package/dist/_astro/SelectDropdown.T3CKHaLt.js +0 -1
  216. package/dist/_astro/SettingsDialog.C62iJkMt.js +0 -1
  217. package/dist/_astro/SpaceSwitcher.C47_S1g9.js +0 -7
  218. package/dist/_astro/TasksBoard.BUEg2BYk.js +0 -1
  219. package/dist/_astro/TemplatesLibrary.BLVIphXO.js +0 -1
  220. package/dist/_astro/TestReportsLibrary.DVq30Jae.js +0 -1
  221. package/dist/_astro/TestStatsBoard.-5BWQ6bI.js +0 -1
  222. package/dist/_astro/Toast.BO2NFckG.js +0 -1
  223. package/dist/_astro/TodosBoard.DI_lTp2e.js +0 -1
  224. package/dist/_astro/UiAutoBoard.ChFdgv7s.js +0 -2
  225. package/dist/_astro/UiAutoEnvPanel.B50q4kYb.js +0 -19
  226. package/dist/_astro/UiAutoGenerationDialog.CLkFAHrm.js +0 -1
  227. package/dist/_astro/UiAutoProjectsPage.DCsDeN5d.js +0 -3
  228. package/dist/_astro/app-config.DkyjuL-S.js +0 -1
  229. package/dist/_astro/app-version.3eY3FSw1.js +0 -1
  230. package/dist/_astro/case-gen-run.BQeK-XUw.js +0 -22
  231. package/dist/_astro/case-types.DlFkbZJN.js +0 -1
  232. package/dist/_astro/dialog.DZHZCe_T.js +0 -1
  233. package/dist/_astro/doc-roots.CO3IBiY6.js +0 -1
  234. package/dist/_astro/i18n.D_aOCHSN.js +0 -7
  235. package/dist/_astro/markdown-client.BS19nLL3.js +0 -62
  236. package/dist/_astro/plugins.BRvXWHLe.js +0 -1
  237. package/dist/_astro/project-docs.CCjtiFjB.js +0 -1
  238. package/dist/_astro/prompts-meta.BUGutlsk.js +0 -2
  239. package/dist/_astro/report-prompt.B9C4cv84.js +0 -1
  240. package/dist/_astro/req-analysis.FrD6BfwK.js +0 -31
  241. package/dist/_astro/story-review.R8iWiFzl.js +0 -14
  242. package/dist/_astro/test-reports.CuIjlEyK.js +0 -19
  243. package/dist/_astro/ui-auto-prompt.H9_yhau9.js +0 -9
  244. package/dist/_astro/ui-auto.DMv940x4.js +0 -1
@@ -0,0 +1,262 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_astro/lib.S37S0T6S.js","_astro/react.Blvh0GOs.js","_astro/jszip.min.Bh2Mgo40.js","_astro/case-fields.CmePqYfh.js","_astro/UiAutoGenerationDialog.D1PyCgrD.js","_astro/dialog.XgRGNF_Q.js","_astro/portal.Chh6O5xk.js","_astro/react-dom.DLW9pGCF.js","_astro/app-config.Dvfzl5_N.js","_astro/settings.D02wZj3w.js","_astro/jsx-runtime.DUg_B_vD.js","_astro/view-prefs.COAKEQtZ.js","_astro/PmShared.BQVzwsiz.js","_astro/plugins.Db9xoFZb.js","_astro/pm.BXmOiFfW.js","_astro/SelectDropdown.D7IeyHDI.js","_astro/listbox.DNxAJmEo.js","_astro/use-text-value.B3mOiuGb.js","_astro/SlideOverDrawer.BMg2tce6.js","_astro/Toast.BydY-X7T.js","_astro/open-docs-in-session.BpcAcBSI.js","_astro/fs-tools.3F9MFrLf.js"])))=>i.map(i=>d[i]);
2
+ import{s as e,t}from"./react.Blvh0GOs.js";import{t as n}from"./react-dom.DLW9pGCF.js";import{a as r,n as i,r as a,t as o}from"./dialog.XgRGNF_Q.js";import{i as s,n as c,r as l,t as u}from"./menu.Dnrpz489.js";import{g as d}from"./business-map.BiJ85oxm.js";import{B as f,i as p,p as m,r as h,t as g,u as _,z as v}from"./app-config.Dvfzl5_N.js";import{a as ee,b as y,c as te,f as b,h as x,m as S,p as C,r as w,s as T,u as E}from"./settings.D02wZj3w.js";import{t as D}from"./jsx-runtime.DUg_B_vD.js";import{t as ne}from"./ConfirmDialog.DQFd6g2r.js";import{a as re,i as ie,o as ae,r as O,t as oe}from"./plugins.Db9xoFZb.js";import{C as k,E as se,M as ce,O as le,R as ue,S as A,T as j,a as M,d as de,g as N,h as fe,k as pe,l as me,r as he,s as ge,t as _e,w as P,x as ve,y as F}from"./pm.BXmOiFfW.js";import{n as ye,o as be}from"./view-prefs.COAKEQtZ.js";import{n as xe,t as I}from"./SelectDropdown.D7IeyHDI.js";import{t as L}from"./SlideOverDrawer.BMg2tce6.js";import{showToast as Se}from"./Toast.BydY-X7T.js";import{_ as Ce,a as we,h as Te,o as R,r as Ee,s as De,t as Oe}from"./case-exec.BMNk9OyF.js";import{t as ke}from"./DatePicker.BRO_CjVQ.js";import{a as Ae,i as je,n as Me,r as Ne}from"./composer-task.DRi5tAJs.js";import{A as Pe,C as Fe,D as Ie,E as Le,O as Re,S as ze,T as Be,_ as Ve,a as He,b as Ue,c as We,d as Ge,f as Ke,g as qe,h as Je,i as Ye,j as Xe,k as Ze,l as Qe,m as $e,n as et,o as tt,p as nt,r as rt,s as it,u as at,v as ot,w as st,x as z,y as ct}from"./open-docs-in-session.BpcAcBSI.js";import{_ as lt,a as ut,c as dt,g as ft,h as pt,l as mt,s as ht,t as gt,v as _t,y as vt}from"./case-gen-run.Cvvdv_kv.js";import{a as yt,c as bt,l as xt}from"./case-fields.CmePqYfh.js";import{c as St,f as Ct,p as wt,r as Tt,u as Et,v as Dt}from"./project-docs.bB9lQ1Ki.js";import{i as Ot,n as kt,r as At}from"./case-template.Clb7HrDB.js";import{A as jt,L as Mt,T as Nt,_ as Pt,tt as Ft}from"./req-analysis.C_gARMrB.js";import{a as It,i as Lt,r as Rt,s as zt,t as Bt}from"./llm.BCYNgppW.js";import{n as Vt,t as Ht}from"./doc-roots.C-20VD0x.js";import{i as Ut}from"./space-skills.CPucW8zt.js";import{n as Wt,t as Gt}from"./case-prompt.CZ3vWUju.js";import{t as B}from"./ExcelFieldTags.CXif3Ilh.js";import{t as Kt}from"./MultiSelectDropdown.D-rbpivp.js";import{t as qt}from"./SearchableSelect.DXclLMJI.js";import{t as Jt}from"./NamePromptDialog.KPCeXmri.js";import{n as Yt,r as Xt,t as Zt}from"./composer-draft.llpvz3MW.js";import{n as Qt}from"./i18n.Cp4so7KR.js";import{_ as $t,a as en,b as tn,c as nn,d as rn,f as an,g as on,h as sn,i as cn,l as ln,m as un,n as dn,o as fn,p as pn,r as mn,s as hn,t as gn,u as _n,v as vn,y as yn}from"./fs-tools.3F9MFrLf.js";import{L as bn,S as xn,at as Sn,c as Cn,ct as wn,it as Tn,n as En,ot as Dn,q as V,t as On}from"./UiAutoGenerationDialog.D1PyCgrD.js";import{i as kn,s as An}from"./requirement-breakdown-library.l0rPd7b3.js";import{C as jn,D as Mn,E as Nn,F as Pn,O as Fn,P as In,S as Ln,T as Rn,_ as zn,a as Bn,b as Vn,c as Hn,d as Un,g as Wn,i as Gn,j as Kn,k as H,l as qn,m as Jn,n as Yn,o as Xn,r as Zn,t as Qn,u as $n,v as er,x as tr,y as nr}from"./tasks.DEyD8pmq.js";import{_ as rr,a as ir,c as ar,d as or,f as sr,g as cr,h as lr,i as ur,l as dr,m as fr,n as pr,o as mr,p as hr,r as gr,s as _r,t as vr,u as yr,v as br,y as xr}from"./bash-tools.CS2w8LOb.js";import{A as Sr,C as Cr,D as wr,E as Tr,O as Er,S as Dr,T as Or,_ as kr,b as Ar,g as jr,h as Mr,j as Nr,k as Pr,m as Fr,o as Ir,p as Lr,s as Rr,t as zr,u as Br,v as Vr,w as Hr,x as Ur}from"./mcp-tools.Kf-lupGn.js";import{n as Wr,t as Gr}from"./prompts-meta.VAjE4OET.js";import{o as Kr,r as qr,t as Jr}from"./report-prompt.CwHuOcRN.js";import{s as Yr}from"./test-stats.Cf3_L4wu.js";import{f as Xr,n as Zr,u as Qr}from"./test-points.C7ZgggQT.js";var U=e(t(),1),$r=e(n(),1),ei=`/__tb_sessions/runs`;async function ti(e){try{return(await fetch(ei,{signal:e??AbortSignal.timeout(1500)})).ok}catch{return!1}}async function ni(e){let t=await fetch(ei,{signal:e??AbortSignal.timeout(3e3)});if(!t.ok)return[];let n=await t.json();return Array.isArray(n.runs)?n.runs:[]}async function ri(e){let t=await fetch(ei,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error||`HTTP ${t.status}`}}async function ii(e){await fetch(`${ei}/${encodeURIComponent(e)}/stop`,{method:`POST`}).catch(()=>{})}async function ai(e){try{let t=await fetch(`${ei}/${encodeURIComponent(e)}`,{signal:AbortSignal.timeout(3e3)});return t.status===404?{ok:!1}:t.ok?await t.json():null}catch{return null}}function oi(e){return e===`completed`||e===`stopped`||e===`error`}function si(e,t,n,r){let i=new AbortController,a=`${ei}/${encodeURIComponent(e)}/events?after=${Math.max(0,t)}`;return(async()=>{try{let e=await fetch(a,{headers:{Accept:`text/event-stream`},signal:i.signal});if(!e.ok||!e.body){r?.(Error(`SSE ${e.status}`));return}let t=e.body.getReader(),o=new TextDecoder,s=``;for(;;){let{done:e,value:a}=await t.read();if(e){i.signal.aborted||r?.(Error(`SSE disconnected`));break}s+=o.decode(a,{stream:!0});let c=s.split(`
3
+ `);s=c.pop()??``;for(let e of c){let t=e.trim();if(!t.startsWith(`data:`))continue;let r=t.slice(5).trim();if(r)try{n(JSON.parse(r))}catch{}}}}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;r?.(e instanceof Error?e:Error(String(e)))}})(),()=>i.abort()}function ci(e,t,n){let r=!1,i=Math.max(0,t),a=0,o=null,s,c=n.maxAttempts??10,l=()=>{r=!0,s!=null&&clearTimeout(s),s=void 0,o?.(),o=null},u=()=>{r||n.signal?.aborted||(o?.(),o=si(e,i,e=>{typeof e.seq==`number`&&Number.isFinite(e.seq)&&(i=Math.max(i,e.seq)),n.onEvent(e),e.type===`status`&&oi(e.status)&&(n.onTerminal?.(e),l())},t=>{r||n.signal?.aborted||(async()=>{a+=1;try{let r=await ai(e);if(r?.ok&&typeof r.seq==`number`&&(i=Math.max(i,r.seq)),r?.ok&&oi(r.status)){let e={type:`status`,status:r.status,seq:r.seq,assistant:r.assistant};n.onEvent(e),n.onTerminal?.(e),l();return}if(r&&r.ok===!1){n.onGaveUp?.(Error(t.message||`run not found`)),l();return}}catch{}if(a>=c){n.onGaveUp?.(t),l();return}let r=Math.min(4e3,250*a);s=setTimeout(u,r)})()}))},d=()=>l();return n.signal?.addEventListener(`abort`,d),u(),()=>{n.signal?.removeEventListener(`abort`,d),l()}}function li(e){for(let t of e)if(t.role===`user`&&typeof t.content==`string`){let e=t.content.trim();if(e)return e}return``}function ui(e,t){let n=(e||``).trim()||`新对话`;return n===`新对话`||n===`新会话`||n===`新编排`||n===`未命名编排`||/^编排\s+\d{1,2}\/\d{1,2}\s+\d{1,2}:\d{2}/.test(n)?!0:n===Le(t)}function di(e){let t=String(e??``).trim().replace(/^["「『]+|["」』]+$/g,``).replace(/\s+/g,` `).replace(/^标题[::]\s*/i,``);return t=t.replace(/[。.!!]+$/g,``).trim(),t?t.length>28?`${t.slice(0,28)}…`:t:``}async function fi(e,t,n){let r=t.trim().slice(0,800);if(!r)return null;let i=[{role:`system`,content:`你为对话生成侧栏短标题。只输出标题本身:中文优先,不超过 16 个字,无引号、无标点收尾、无解释。`},{role:`user`,content:`用户首条消息:\n${r}\n\n请给出标题:`}];try{return di(await Rt(e,i,n))||null}catch{return null}}function pi(e){let t=Array.isArray(e.messages)?e.messages:[],n=0,r=0,i=0,a=0,o=0;for(let e of t){if(!e||typeof e!=`object`)continue;let t=e;t.role===`user`?n+=1:t.role===`assistant`&&(r+=1);let s=t.usage;if(s&&typeof s==`object`){let e=s;typeof e.promptTokens==`number`&&(i+=e.promptTokens),typeof e.completionTokens==`number`&&(a+=e.completionTokens),typeof e.totalTokens==`number`?o+=e.totalTokens:(typeof e.promptTokens==`number`||typeof e.completionTokens==`number`)&&(o+=(Number(e.promptTokens)||0)+(Number(e.completionTokens)||0))}}let s=e.goal,c=!!(s&&s.status!==`cleared`&&s.text?.trim());return{sessionId:e.id,title:e.title||`新对话`,messageCount:t.length,userCount:n,assistantCount:r,promptTokens:i,completionTokens:a,totalTokens:o,createdAt:e.createdAt,updatedAt:e.updatedAt,hasGoal:c,todoCount:Array.isArray(e.todos)?e.todos.length:0}}function mi(e){let t=new Date(e.createdAt).toLocaleString(),n=new Date(e.updatedAt).toLocaleString();return[`会话:${e.title}`,`消息 ${e.messageCount}(用户 ${e.userCount} / 助手 ${e.assistantCount})`,`用量≈ 输入 ${e.promptTokens} · 输出 ${e.completionTokens} · 合计 ${e.totalTokens}`,`待办 ${e.todoCount} · 目标 ${e.hasGoal?`有`:`无`}`,`创建 ${t}`,`更新 ${n}`].join(`
4
+ `)}var hi=new Map,gi=new Map,_i=40;function vi(e,t,n=``){return`${e}:${t}:${n}`}function yi(e){for(;e.size>_i;){let t=e.keys().next().value;if(t===void 0)break;e.delete(t)}}function bi(e,t,n,r,i=``){let a=e===`outline`?hi:gi,o=vi(t,n,i),s=a.get(t);if(s&&s.stamp===o)return s.value;let c=r();return a.set(t,{stamp:o,value:c}),yi(a),c}var xi=`/__tb_sessions/log`;function Si(e){let t=String(e.userContent??``).trim(),n=String(e.assistantContent??``).trim(),r=String(e.reasoning??``).trim(),i=[];if(t&&i.push({role:`user`,content:t}),n||r){let e={role:`assistant`,content:n};r&&(e.reasoning_content=r),i.push(e)}return i}async function Ci(e){try{let t=await fetch(xi,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:AbortSignal.timeout(5e3)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,path:n.path}:{ok:!1,error:n.error||`HTTP ${t.status}`}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}}function wi(e){return String(e??``).trim()}function Ti(e,t=80){let n=wi(e).replace(/\s+/g,` `);return n?n.length>t?`${n.slice(0,t)}…`:n:``}function Ei(e,t=40){let n=[],r=null;for(let i=0;i<e.length;i++){let a=e[i];if(a.role===`user`){let e=wi(a.content),t=Ti(e);if(!t)continue;r&&n.push({index:n.length+1,userPreview:r.preview,assistantPreview:``,userText:r.text,assistantText:``,userTime:r.time,endMessageIndex:r.messageIndex}),r={text:e,preview:t,time:typeof a.time==`number`?a.time:void 0,messageIndex:i}}else if(a.role===`assistant`&&r){let e=wi(a.content),t=wi(a.reasoning)||void 0;n.push({index:n.length+1,userPreview:r.preview,assistantPreview:Ti(e)||(t?`(含思考)`:``),userText:r.text,assistantText:e,reasoning:t,reasoningDuration:typeof a.reasoningDuration==`number`?a.reasoningDuration:void 0,userTime:r.time,assistantTime:typeof a.time==`number`?a.time:void 0,endMessageIndex:i}),r=null}if(n.length>=t)break}return r&&n.length<t&&n.push({index:n.length+1,userPreview:r.preview,assistantPreview:``,userText:r.text,assistantText:``,userTime:r.time,endMessageIndex:r.messageIndex}),n}function Di(e,t){let n=String(t??``).trim();return!n||n===`inherit`||n===e.model?e:{...e,model:n}}var Oi=`/__tb_fs`,ki=`你可以使用 office_to_pdf:优先用本机 LibreOffice 转为 PDF;若未安装,则对 docx/xlsx/pptx 降级抽取正文为同目录 .extracted.md(需写权限)。`,Ai={type:`function`,function:{name:`office_to_pdf`,description:`Convert Office docs to PDF via LibreOffice when available; otherwise extract text to .extracted.md for docx/xlsx/pptx.`,parameters:{type:`object`,properties:{path:{type:`string`,description:`Input file path relative to workspace (or absolute when allowed)`},outDir:{type:`string`,description:`Optional output directory (default: same as input)`}},required:[`path`]}}};async function ji(e,t,n){if(e!==`office_to_pdf`)return JSON.stringify({error:`unknown tool: ${e}`});let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({ok:!1,error:`invalid JSON arguments`})}let i=String(r.path??``).trim();if(!i)return JSON.stringify({ok:!1,error:`path is required`});try{let e=await(await fetch(`${Oi}/office-to-pdf`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:i,outDir:typeof r.outDir==`string`?r.outDir:void 0,access:n}),signal:AbortSignal.timeout(13e4)})).json().catch(()=>({}));return JSON.stringify(e,null,2)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}}var Mi=`/__tb_fs`,Ni=`你可以使用 load_workspace_dependencies:查询本机 node / npm / pnpm / python 等可执行文件绝对路径(需本地 fs 服务)。`,Pi={type:`function`,function:{name:`load_workspace_dependencies`,description:`Resolve absolute paths of common runtimes/package managers on this machine (node, npm, pnpm, python, …).`,parameters:{type:`object`,properties:{}}}};async function Fi(e){if(e!==`load_workspace_dependencies`)return JSON.stringify({error:`unknown tool: ${e}`});try{let e=await fetch(`${Mi}/workspace-dependencies`,{signal:AbortSignal.timeout(8e3)}),t=await e.json().catch(()=>({}));if(!e.ok){let n=typeof t==`object`&&t&&`error`in t?String(t.error):`HTTP ${e.status}`;return JSON.stringify({ok:!1,error:n})}return JSON.stringify(t,null,2)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}}function Ii(e){return Array.isArray(e)}function Li(e){return Ii(e)?e.some(e=>e.type===`image_url`):!1}function Ri(e){let t=e.filter(e=>e.type===`text`).map(e=>e.text),n=e.filter(e=>e.type===`image_url`).length,r=n>0?`[image-offload] 已卸载 ${n} 张图片(超预算,仅保留最近附图)。`:``;return[{type:`text`,text:[...t,r].filter(Boolean).join(`
5
+ `)||r||`(图片已卸载)`}]}function zi(e,t={}){let n=Math.max(0,Math.floor(t.keepRecentImageMessages??1)),r=[];for(let t=0;t<e.length;t++){let n=e[t];n.role===`user`&&Li(n.content)&&r.push(t)}if(r.length<=n)return e;let i=new Set(r.slice(-n)),a=!1,o=e.map((e,t)=>e.role!==`user`||!Li(e.content)||i.has(t)||!Ii(e.content)?e:(a=!0,{...e,content:Ri(e.content)}));return a?o:e}function Bi(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Vi=Bi();function Hi(e){Vi=e}var Ui={exec:()=>null};function W(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(Wi.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var Wi={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`)},Gi=/^(?:[ \t]*(?:\n|$))+/,Ki=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,qi=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Ji=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Yi=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Xi=/(?:[*+-]|\d{1,9}[.)])/,Zi=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Qi=W(Zi).replace(/bull/g,Xi).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),$i=W(Zi).replace(/bull/g,Xi).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),ea=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,ta=/^[^\n]+/,na=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ra=W(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,na).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),ia=W(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Xi).getRegex(),aa=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,oa=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,sa=W(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,oa).replace(`tag`,aa).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ca=W(ea).replace(`hr`,Ji).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,aa).getRegex(),la={blockquote:W(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,ca).getRegex(),code:Ki,def:ra,fences:qi,heading:Yi,hr:Ji,html:sa,lheading:Qi,list:ia,newline:Gi,paragraph:ca,table:Ui,text:ta},ua=W(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,Ji).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,aa).getRegex(),da={...la,lheading:$i,table:ua,paragraph:W(ea).replace(`hr`,Ji).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,ua).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,aa).getRegex()},fa={...la,html:W(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,oa).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Ui,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:W(ea).replace(`hr`,Ji).replace(`heading`,` *#{1,6} *[^
6
+ ]`).replace(`lheading`,Qi).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},pa=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,ma=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ha=/^( {2,}|\\)\n(?!\s*$)/,ga=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,_a=/[\p{P}\p{S}]/u,va=/[\s\p{P}\p{S}]/u,ya=/[^\s\p{P}\p{S}]/u,ba=W(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,va).getRegex(),xa=/(?!~)[\p{P}\p{S}]/u,Sa=/(?!~)[\s\p{P}\p{S}]/u,Ca=/(?:[^\s\p{P}\p{S}]|~)/u,wa=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,Ta=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Ea=W(Ta,`u`).replace(/punct/g,_a).getRegex(),Da=W(Ta,`u`).replace(/punct/g,xa).getRegex(),Oa=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,ka=W(Oa,`gu`).replace(/notPunctSpace/g,ya).replace(/punctSpace/g,va).replace(/punct/g,_a).getRegex(),Aa=W(Oa,`gu`).replace(/notPunctSpace/g,Ca).replace(/punctSpace/g,Sa).replace(/punct/g,xa).getRegex(),ja=W(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,ya).replace(/punctSpace/g,va).replace(/punct/g,_a).getRegex(),Ma=W(/\\(punct)/,`gu`).replace(/punct/g,_a).getRegex(),Na=W(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Pa=W(oa).replace(`(?:-->|$)`,`-->`).getRegex(),Fa=W(`^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,Pa).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Ia=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,La=W(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace(`label`,Ia).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Ra=W(/^!?\[(label)\]\[(ref)\]/).replace(`label`,Ia).replace(`ref`,na).getRegex(),za=W(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,na).getRegex(),Ba={_backpedal:Ui,anyPunctuation:Ma,autolink:Na,blockSkip:wa,br:ha,code:ma,del:Ui,emStrongLDelim:Ea,emStrongRDelimAst:ka,emStrongRDelimUnd:ja,escape:pa,link:La,nolink:za,punctuation:ba,reflink:Ra,reflinkSearch:W(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,Ra).replace(`nolink`,za).getRegex(),tag:Fa,text:ga,url:Ui},Va={...Ba,link:W(/^!?\[(label)\]\((.*?)\)/).replace(`label`,Ia).getRegex(),reflink:W(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,Ia).getRegex()},Ha={...Ba,emStrongRDelimAst:Aa,emStrongLDelim:Da,url:W(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,`i`).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Ua={...Ha,br:W(ha).replace(`{2,}`,`*`).getRegex(),text:W(Ha.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},Wa={normal:la,gfm:da,pedantic:fa},Ga={normal:Ba,gfm:Ha,breaks:Ua,pedantic:Va},Ka={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},qa=e=>Ka[e];function Ja(e,t){if(t){if(Wi.escapeTest.test(e))return e.replace(Wi.escapeReplace,qa)}else if(Wi.escapeTestNoEncode.test(e))return e.replace(Wi.escapeReplaceNoEncode,qa);return e}function Ya(e){try{e=encodeURI(e).replace(Wi.percentDecode,`%`)}catch{return null}return e}function Xa(e,t){let n=e.replace(Wi.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(Wi.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t){if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``)}for(;r<n.length;r++)n[r]=n[r].trim().replace(Wi.slashPipe,`|`);return n}function G(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function Za(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function Qa(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function $a(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
7
+ `).map(e=>{let t=e.match(n.other.beginningSpace);if(t===null)return e;let[r]=t;return r.length>=i.length?e.slice(i.length):e}).join(`
8
+ `)}var eo=class{options;rules;lexer;constructor(e){this.options=e||Vi}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:`space`,raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,``);return{type:`code`,raw:t[0],codeBlockStyle:`indented`,text:this.options.pedantic?e:G(e,`
9
+ `)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=$a(e,t[3]||``,this.rules);return{type:`code`,raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,`$1`):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=G(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:`hr`,raw:G(t[0],`
10
+ `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=G(t[0],`
11
+ `).split(`
12
+ `),n=``,r=``,i=[];for(;e.length>0;){let t=!1,a=[],o=0;for(;o<e.length;o++)if(this.rules.other.blockquoteStart.test(e[o]))a.push(e[o]),t=!0;else if(!t)a.push(e[o]);else break;e=e.slice(o);let s=a.join(`
13
+ `),c=s.replace(this.rules.other.blockquoteSetextReplace,`
14
+ $1`).replace(this.rules.other.blockquoteSetextReplace2,``);n=n?`${n}
15
+ ${s}`:s,r=r?`${r}
16
+ ${c}`:c;let l=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,i,!0),this.lexer.state.top=l,e.length===0)break;let u=i.at(-1);if(u?.type===`code`)break;if(u?.type===`blockquote`){let t=u,a=t.raw+`
17
+ `+e.join(`
18
+ `),o=this.blockquote(a);i[i.length-1]=o,n=n.substring(0,n.length-t.raw.length)+o.raw,r=r.substring(0,r.length-t.text.length)+o.text;break}if(u?.type===`list`){let t=u,a=t.raw+`
19
+ `+e.join(`
20
+ `),o=this.list(a);i[i.length-1]=o,n=n.substring(0,n.length-u.raw.length)+o.raw,r=r.substring(0,r.length-t.raw.length)+o.raw,e=a.substring(i.at(-1).raw.length).split(`
21
+ `)}}return{type:`blockquote`,raw:n,tokens:i,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,i={type:`list`,raw:``,ordered:r,start:r?+n.slice(0,-1):``,loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:`[*+-]`);let a=this.rules.other.listItemRegex(n),o=!1;for(;e;){let n=!1,r=``,s=``;if(!(t=a.exec(e))||this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let c=t[2].split(`
22
+ `,1)[0].replace(this.rules.other.listReplaceTabs,e=>` `.repeat(3*e.length)),l=e.split(`
23
+ `,1)[0],u=!c.trim(),d=0;if(this.options.pedantic?(d=2,s=c.trimStart()):u?d=t[1].length+1:(d=t[2].search(this.rules.other.nonSpaceChar),d=d>4?1:d,s=c.slice(d),d+=t[1].length),u&&this.rules.other.blankLine.test(l)&&(r+=l+`
24
+ `,e=e.substring(l.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(d),n=this.rules.other.hrRegex(d),i=this.rules.other.fencesBeginRegex(d),a=this.rules.other.headingBeginRegex(d),o=this.rules.other.htmlBeginRegex(d);for(;e;){let f=e.split(`
25
+ `,1)[0],p;if(l=f,this.options.pedantic?(l=l.replace(this.rules.other.listReplaceNesting,` `),p=l):p=l.replace(this.rules.other.tabCharGlobal,` `),i.test(l)||a.test(l)||o.test(l)||t.test(l)||n.test(l))break;if(p.search(this.rules.other.nonSpaceChar)>=d||!l.trim())s+=`
26
+ `+p.slice(d);else{if(u||c.replace(this.rules.other.tabCharGlobal,` `).search(this.rules.other.nonSpaceChar)>=4||i.test(c)||a.test(c)||n.test(c))break;s+=`
27
+ `+l}!u&&!l.trim()&&(u=!0),r+=f+`
28
+ `,e=e.substring(f.length+1),c=p.slice(d)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(o=!0));let f=null,p;this.options.gfm&&(f=this.rules.other.listIsTask.exec(s),f&&(p=f[0]!==`[ ] `,s=s.replace(this.rules.other.listReplaceTask,``))),i.items.push({type:`list_item`,raw:r,task:!!f,checked:p,loose:!1,text:s,tokens:[]}),i.raw+=r}let s=i.items.at(-1);if(s)s.raw=s.raw.trimEnd(),s.text=s.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let e=0;e<i.items.length;e++)if(this.lexer.state.top=!1,i.items[e].tokens=this.lexer.blockTokens(i.items[e].text,[]),!i.loose){let t=i.items[e].tokens.filter(e=>e.type===`space`);i.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}if(i.loose)for(let e=0;e<i.items.length;e++)i.items[e].loose=!0;return i}}html(e){let t=this.rules.block.html.exec(e);if(t)return{type:`html`,block:!0,raw:t[0],pre:t[1]===`pre`||t[1]===`script`||t[1]===`style`,text:t[0]}}def(e){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal,` `),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,`$1`).replace(this.rules.inline.anyPunctuation,`$1`):``,r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,`$1`):t[3];return{type:`def`,tag:e,raw:t[0],href:n,title:r}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=Xa(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,``).split(`|`),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,``).split(`
29
+ `):[],a={type:`table`,raw:t[0],header:[],align:[],rows:[]};if(n.length===r.length){for(let e of r)this.rules.other.tableAlignRight.test(e)?a.align.push(`right`):this.rules.other.tableAlignCenter.test(e)?a.align.push(`center`):this.rules.other.tableAlignLeft.test(e)?a.align.push(`left`):a.align.push(null);for(let e=0;e<n.length;e++)a.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:a.align[e]});for(let e of i)a.rows.push(Xa(e,a.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:a.align[t]})));return a}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t)return{type:`heading`,raw:t[0],depth:t[2].charAt(0)===`=`?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e=t[1].charAt(t[1].length-1)===`
30
+ `?t[1].slice(0,-1):t[1];return{type:`paragraph`,raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:`text`,raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:`escape`,raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:`html`,raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=G(e.slice(0,-1),`\\`);if((e.length-t.length)%2==0)return}else{let e=Za(t[2],`()`);if(e===-2)return;if(e>-1){let n=(t[0].indexOf(`!`)===0?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=``}}let n=t[2],r=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):``;return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),Qa(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,`$1`),title:r&&r.replace(this.rules.inline.anyPunctuation,`$1`)},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal,` `).toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:`text`,raw:e,text:e}}return Qa(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=``){let r=this.rules.inline.emStrongLDelim.exec(e);if(r&&!(r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[2])||!n||this.rules.inline.punctuation.exec(n))){let n=[...r[0]].length-1,i,a,o=n,s=0,c=r[0][0]===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+n);(r=c.exec(t))!=null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}if((r[5]||r[6])&&n%3&&!((n+a)%3)){s+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+s);let t=[...r[0]][0].length,c=e.slice(0,n+r.index+t+a);if(Math.min(n,a)%2){let e=c.slice(1,-1);return{type:`em`,raw:c,text:e,tokens:this.lexer.inlineTokens(e)}}let l=c.slice(2,-2);return{type:`strong`,raw:c,text:l,tokens:this.lexer.inlineTokens(l)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal,` `),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:`codespan`,raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:`br`,raw:t[0]}}del(e){let t=this.rules.inline.del.exec(e);if(t)return{type:`del`,raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return t[2]===`@`?(e=t[1],n=`mailto:`+e):(e=t[1],n=e),{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if(t[2]===`@`)e=t[0],n=`mailto:`+e;else{let r;do r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??``;while(r!==t[0]);e=t[0],n=t[1]===`www.`?`http://`+t[0]:t[0]}return{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:`text`,raw:t[0],text:t[0],escaped:e}}}},to=class e{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Vi,this.options.tokenizer=this.options.tokenizer||new eo,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:Wi,block:Wa.normal,inline:Ga.normal};this.options.pedantic?(t.block=Wa.pedantic,t.inline=Ga.pedantic):this.options.gfm&&(t.block=Wa.gfm,t.inline=this.options.breaks?Ga.breaks:Ga.gfm),this.tokenizer.rules=t}static get rules(){return{block:Wa,inline:Ga}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(Wi.carriageReturn,`
31
+ `),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){for(this.options.pedantic&&(e=e.replace(Wi.tabCharGlobal,` `).replace(Wi.spaceLine,``));e;){let r;if(this.options.extensions?.block?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let n=t.at(-1);r.raw.length===1&&n!==void 0?n.raw+=`
32
+ `:t.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=`
33
+ `+r.raw,n.text+=`
34
+ `+r.text,this.inlineQueue.at(-1).src=n.text):t.push(r);continue}if((r=this.tokenizer.fences(e))||(r=this.tokenizer.heading(e))||(r=this.tokenizer.hr(e))||(r=this.tokenizer.blockquote(e))||(r=this.tokenizer.list(e))||(r=this.tokenizer.html(e))){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=`
35
+ `+r.raw,n.text+=`
36
+ `+r.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title});continue}if((r=this.tokenizer.table(e))||(r=this.tokenizer.lheading(e))){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startBlock){let t=1/0,n=e.slice(1),r;this.options.extensions.startBlock.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(this.state.top&&(r=this.tokenizer.paragraph(i))){let a=t.at(-1);n&&a?.type===`paragraph`?(a.raw+=`
37
+ `+r.raw,a.text+=`
38
+ `+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):t.push(r),n=i.length!==e.length,e=e.substring(r.raw.length)}else if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`text`?(n.raw+=`
39
+ `+r.raw,n.text+=`
40
+ `+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n=e,r=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(n))!=null;)e.includes(r[0].slice(r[0].lastIndexOf(`[`)+1,-1))&&(n=n.slice(0,r.index)+`[`+`a`.repeat(r[0].length-2)+`]`+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(n))!=null;)n=n.slice(0,r.index)+`++`+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(r=this.tokenizer.rules.inline.blockSkip.exec(n))!=null;)n=n.slice(0,r.index)+`[`+`a`.repeat(r[0].length-2)+`]`+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let i=!1,a=``;for(;e;){i||(a=``),i=!1;let r;if(this.options.extensions?.inline?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if((r=this.tokenizer.escape(e))||(r=this.tokenizer.tag(e))||(r=this.tokenizer.link(e))){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);let n=t.at(-1);r.type===`text`&&n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if((r=this.tokenizer.emStrong(e,n,a))||(r=this.tokenizer.codespan(e))||(r=this.tokenizer.br(e))||(r=this.tokenizer.del(e))||(r=this.tokenizer.autolink(e))||!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),t.push(r);continue}let o=e;if(this.options.extensions?.startInline){let t=1/0,n=e.slice(1),r;this.options.extensions.startInline.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(o=e.substring(0,t+1))}if(r=this.tokenizer.inlineText(o)){e=e.substring(r.raw.length),r.raw.slice(-1)!==`_`&&(a=r.raw.slice(-1)),i=!0;let n=t.at(-1);n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return t}},no=class{options;parser;constructor(e){this.options=e||Vi}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(Wi.notSpaceStart)?.[0],i=e.replace(Wi.endingNewline,``)+`
41
+ `;return r?`<pre><code class="language-`+Ja(r)+`">`+(n?i:Ja(i,!0))+`</code></pre>
42
+ `:`<pre><code>`+(n?i:Ja(i,!0))+`</code></pre>
43
+ `}blockquote({tokens:e}){return`<blockquote>
44
+ ${this.parser.parse(e)}</blockquote>
45
+ `}html({text:e}){return e}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
46
+ `}hr(e){return`<hr>
47
+ `}list(e){let t=e.ordered,n=e.start,r=``;for(let t=0;t<e.items.length;t++){let n=e.items[t];r+=this.listitem(n)}let i=t?`ol`:`ul`,a=t&&n!==1?` start="`+n+`"`:``;return`<`+i+a+`>
48
+ `+r+`</`+i+`>
49
+ `}listitem(e){let t=``;if(e.task){let n=this.checkbox({checked:!!e.checked});e.loose?e.tokens[0]?.type===`paragraph`?(e.tokens[0].text=n+` `+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&e.tokens[0].tokens[0].type===`text`&&(e.tokens[0].tokens[0].text=n+` `+Ja(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:`text`,raw:n+` `,text:n+` `,escaped:!0}):t+=n+` `}return t+=this.parser.parse(e.tokens,!!e.loose),`<li>${t}</li>
50
+ `}checkbox({checked:e}){return`<input `+(e?`checked="" `:``)+`disabled="" type="checkbox">`}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
51
+ `}table(e){let t=``,n=``;for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let r=``;for(let t=0;t<e.rows.length;t++){let i=e.rows[t];n=``;for(let e=0;e<i.length;e++)n+=this.tablecell(i[e]);r+=this.tablerow({text:n})}return r&&=`<tbody>${r}</tbody>`,`<table>
52
+ <thead>
53
+ `+t+`</thead>
54
+ `+r+`</table>
55
+ `}tablerow({text:e}){return`<tr>
56
+ ${e}</tr>
57
+ `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
58
+ `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${Ja(e,!0)}</code>`}br(e){return`<br>`}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=Ya(e);if(i===null)return r;e=i;let a=`<a href="`+e+`"`;return t&&(a+=` title="`+Ja(t)+`"`),a+=`>`+r+`</a>`,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=Ya(e);if(i===null)return Ja(n);e=i;let a=`<img src="${e}" alt="${n}"`;return t&&(a+=` title="${Ja(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:Ja(e.text)}},ro=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}},io=class e{options;renderer;textRenderer;constructor(e){this.options=e||Vi,this.options.renderer=this.options.renderer||new no,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ro}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e,t=!0){let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let e=i,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(t!==!1||![`space`,`hr`,`heading`,`code`,`table`,`blockquote`,`list`,`html`,`paragraph`,`text`].includes(e.type)){n+=t||``;continue}}let a=i;switch(a.type){case`space`:n+=this.renderer.space(a);continue;case`hr`:n+=this.renderer.hr(a);continue;case`heading`:n+=this.renderer.heading(a);continue;case`code`:n+=this.renderer.code(a);continue;case`table`:n+=this.renderer.table(a);continue;case`blockquote`:n+=this.renderer.blockquote(a);continue;case`list`:n+=this.renderer.list(a);continue;case`html`:n+=this.renderer.html(a);continue;case`paragraph`:n+=this.renderer.paragraph(a);continue;case`text`:{let i=a,o=this.renderer.text(i);for(;r+1<e.length&&e[r+1].type===`text`;)i=e[++r],o+=`
59
+ `+this.renderer.text(i);n+=t?this.renderer.paragraph({type:`paragraph`,raw:o,text:o,tokens:[{type:`text`,raw:o,text:o,escaped:!0}]}):o;continue}default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}parseInline(e,t=this.renderer){let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let e=this.options.extensions.renderers[i.type].call({parser:this},i);if(e!==!1||![`escape`,`html`,`link`,`image`,`strong`,`em`,`codespan`,`br`,`del`,`text`].includes(i.type)){n+=e||``;continue}}let a=i;switch(a.type){case`escape`:n+=t.text(a);break;case`html`:n+=t.html(a);break;case`link`:n+=t.link(a);break;case`image`:n+=t.image(a);break;case`strong`:n+=t.strong(a);break;case`em`:n+=t.em(a);break;case`codespan`:n+=t.codespan(a);break;case`br`:n+=t.br(a);break;case`del`:n+=t.del(a);break;case`text`:n+=t.text(a);break;default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}},ao=class{options;block;constructor(e){this.options=e||Vi}static passThroughHooks=new Set([`preprocess`,`postprocess`,`processAllTokens`]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}provideLexer(){return this.block?to.lex:to.lexInline}provideParser(){return this.block?io.parse:io.parseInline}},oo=class{defaults=Bi();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=io;Renderer=no;TextRenderer=ro;Lexer=to;Tokenizer=eo;Hooks=ao;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case`table`:{let e=r;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case`list`:{let e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new no(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new eo(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new ao;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=ao.passThroughHooks.has(n)?e=>{if(this.defaults.async)return Promise.resolve(i.call(t,e)).then(e=>a.call(t,e));let n=i.call(t,e);return a.call(t,n)}:(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return to.lex(e,t??this.defaults)}parser(e,t){return io.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(t==null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));i.hooks&&(i.hooks.options=i,i.hooks.block=e);let o=i.hooks?i.hooks.provideLexer():e?to.lex:to.lexInline,s=i.hooks?i.hooks.provideParser():e?io.parse:io.parseInline;if(i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(t):t).then(e=>o(e,i)).then(e=>i.hooks?i.hooks.processAllTokens(e):e).then(e=>i.walkTokens?Promise.all(this.walkTokens(e,i.walkTokens)).then(()=>e):e).then(e=>s(e,i)).then(e=>i.hooks?i.hooks.postprocess(e):e).catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let e=o(t,i);i.hooks&&(e=i.hooks.processAllTokens(e)),i.walkTokens&&this.walkTokens(e,i.walkTokens);let n=s(e,i);return i.hooks&&(n=i.hooks.postprocess(n)),n}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
60
+ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+Ja(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}},so=new oo;function K(e,t){return so.parse(e,t)}K.options=K.setOptions=function(e){return so.setOptions(e),K.defaults=so.defaults,Hi(K.defaults),K},K.getDefaults=Bi,K.defaults=Vi,K.use=function(...e){return so.use(...e),K.defaults=so.defaults,Hi(K.defaults),K},K.walkTokens=function(e,t){return so.walkTokens(e,t)},K.parseInline=so.parseInline,K.Parser=io,K.parser=io.parse,K.Renderer=no,K.TextRenderer=ro,K.Lexer=to,K.lexer=to.lex,K.Tokenizer=eo,K.Hooks=ao,K.parse=K,K.options,K.setOptions,K.use,K.walkTokens,K.parseInline,io.parse,to.lex;function q(e,t){this.v=e,this.k=t}function co(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function lo(e){if(Array.isArray(e))return e}function uo(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function fo(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
61
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function po(e,t){return lo(e)||uo(e,t)||mo(e,t)||fo()}function mo(e,t){if(e){if(typeof e==`string`)return co(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?co(e,t):void 0}}function ho(e){var t,n;function r(t,n){try{var a=e[t](n),o=a.value,s=o instanceof q;Promise.resolve(s?o.v:o).then(function(n){if(s){var c=t===`return`&&o.k?t:`next`;if(!o.k||n.done)return r(c,n);n=e[c](n).value}i(!!a.done,n)},function(e){r(`throw`,e)})}catch(e){i(2,e)}}function i(e,i){e===2?t.reject(i):t.resolve({value:i,done:e}),(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise(function(a,o){var s={key:e,arg:i,resolve:a,reject:o,next:null};n?n=n.next=s:(t=n=s,r(e,i))})},typeof e.return!=`function`&&(this.return=void 0)}ho.prototype[typeof Symbol==`function`&&Symbol.asyncIterator||`@@asyncIterator`]=function(){return this},ho.prototype.next=function(e){return this._invoke(`next`,e)},ho.prototype.throw=function(e){return this._invoke(`throw`,e)},ho.prototype.return=function(e){return this._invoke(`return`,e)};var go=Object.entries,_o=Object.setPrototypeOf,vo=Object.isFrozen,yo=Object.getPrototypeOf,bo=Object.getOwnPropertyDescriptor,xo=Object.freeze,So=Object.seal,Co=Object.create,wo=typeof Reflect<`u`&&Reflect,To=wo.apply,Eo=wo.construct;xo||=function(e){return e},So||=function(e){return e},To||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},Eo||=function(e){return new e(...[...arguments].slice(1))};var Do=J(Array.prototype.forEach);Array.prototype.indexOf;var Oo=J(Array.prototype.lastIndexOf),ko=J(Array.prototype.pop),Ao=J(Array.prototype.push),jo=J(Array.prototype.slice),Mo=J(Array.prototype.splice),No=Array.isArray,Po=Zo(Set),Fo=J(Set.prototype.add),Io=J(Set.prototype.has),Lo=J(String.prototype.toLowerCase),Ro=J(String.prototype.toString),zo=J(String.prototype.match),Bo=J(String.prototype.replace),Vo=J(String.prototype.indexOf),Ho=J(String.prototype.trim),Uo=J(Number.prototype.toString),Wo=J(Boolean.prototype.toString),Go=typeof BigInt>`u`?null:J(BigInt.prototype.toString),Ko=typeof Symbol>`u`?null:J(Symbol.prototype.toString),qo=J(Object.prototype.hasOwnProperty),Jo=J(Object.prototype.toString),Yo=J(RegExp.prototype.test),Xo=Zo(TypeError);function J(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return To(e,t,n)}}function Zo(e){return function(){return Eo(e,[...arguments])}}function Y(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Lo;if(_o&&_o(e,null),!No(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(vo(t)||(t[r]=e),i=e)}e[i]=!0}return e}function Qo(e){for(let t=0;t<e.length;t++)qo(e,t)||(e[t]=null);return e}function $o(e){let t=Co(null);for(let r of go(e)){var n=po(r,2);let i=n[0],a=n[1];qo(e,i)&&(t[i]=No(a)?Qo(a):a&&typeof a==`object`&&a.constructor===Object?$o(a):a)}return t}function es(e){switch(typeof e){case`string`:return e;case`number`:return Uo(e);case`boolean`:return Wo(e);case`bigint`:return Go?Go(e):`0`;case`symbol`:return Ko?Ko(e):`Symbol()`;case`undefined`:return Jo(e);case`function`:case`object`:{if(e===null)return Jo(e);let t=e,n=ts(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:Jo(e)}return Jo(e)}default:return Jo(e)}}function ts(e,t){for(;e!==null;){let n=bo(e,t);if(n){if(n.get)return J(n.get);if(typeof n.value==`function`)return J(n.value)}e=yo(e)}function n(){return null}return n}function ns(e,t){for(;e!==null;){let n=bo(e,t);if(n)return n.get?J(n.get):null;e=yo(e)}return null}function rs(e){try{return Yo(e,``),!0}catch{return!1}}var is=xo(`a.abbr.acronym.address.area.article.aside.audio.b.bdi.bdo.big.blink.blockquote.body.br.button.canvas.caption.center.cite.code.col.colgroup.content.data.datalist.dd.decorator.del.details.dfn.dialog.dir.div.dl.dt.element.em.fieldset.figcaption.figure.font.footer.form.h1.h2.h3.h4.h5.h6.head.header.hgroup.hr.html.i.img.input.ins.kbd.label.legend.li.main.map.mark.marquee.menu.menuitem.meter.nav.nobr.ol.optgroup.option.output.p.picture.pre.progress.q.rp.rt.ruby.s.samp.search.section.select.shadow.slot.small.source.spacer.span.strike.strong.style.sub.summary.sup.table.tbody.td.template.textarea.tfoot.th.thead.time.tr.track.tt.u.ul.var.video.wbr`.split(`.`)),as=xo(`svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.enterkeyhint.exportparts.filter.font.g.glyph.glyphref.hkern.image.inputmode.line.lineargradient.marker.mask.metadata.mpath.part.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),os=xo([`feBlend`,`feColorMatrix`,`feComponentTransfer`,`feComposite`,`feConvolveMatrix`,`feDiffuseLighting`,`feDisplacementMap`,`feDistantLight`,`feDropShadow`,`feFlood`,`feFuncA`,`feFuncB`,`feFuncG`,`feFuncR`,`feGaussianBlur`,`feImage`,`feMerge`,`feMergeNode`,`feMorphology`,`feOffset`,`fePointLight`,`feSpecularLighting`,`feSpotLight`,`feTile`,`feTurbulence`]),ss=xo([`animate`,`color-profile`,`cursor`,`discard`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`foreignobject`,`hatch`,`hatchpath`,`mesh`,`meshgradient`,`meshpatch`,`meshrow`,`missing-glyph`,`script`,`set`,`solidcolor`,`unknown`,`use`]),cs=xo(`math.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mmultiscripts.mn.mo.mover.mpadded.mphantom.mroot.mrow.ms.mspace.msqrt.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.mprescripts`.split(`.`)),ls=xo([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),us=xo([`#text`]),ds=xo(`accept.action.align.alt.autocapitalize.autocomplete.autopictureinpicture.autoplay.background.bgcolor.border.capture.cellpadding.cellspacing.checked.cite.class.clear.color.cols.colspan.command.commandfor.controls.controlslist.coords.crossorigin.datetime.decoding.default.dir.disabled.disablepictureinpicture.disableremoteplayback.download.draggable.enctype.enterkeyhint.exportparts.face.for.headers.height.hidden.high.href.hreflang.id.inert.inputmode.integrity.ismap.kind.label.lang.list.loading.loop.low.max.maxlength.media.method.min.minlength.multiple.muted.name.nonce.noshade.novalidate.nowrap.open.optimum.part.pattern.placeholder.playsinline.popover.popovertarget.popovertargetaction.poster.preload.pubdate.radiogroup.readonly.rel.required.rev.reversed.role.rows.rowspan.spellcheck.scope.selected.shape.size.sizes.slot.span.srclang.start.src.srcset.step.style.summary.tabindex.title.translate.type.usemap.valign.value.width.wrap.xmlns`.split(`.`)),fs=xo(`accent-height.accumulate.additive.alignment-baseline.amplitude.ascent.attributename.attributetype.azimuth.basefrequency.baseline-shift.begin.bias.by.class.clip.clippathunits.clip-path.clip-rule.color.color-interpolation.color-interpolation-filters.color-profile.color-rendering.cx.cy.d.dx.dy.diffuseconstant.direction.display.divisor.dominant-baseline.dur.edgemode.elevation.end.exponent.fill.fill-opacity.fill-rule.filter.filterunits.flood-color.flood-opacity.font-family.font-size.font-size-adjust.font-stretch.font-style.font-variant.font-weight.fx.fy.g1.g2.glyph-name.glyphref.gradientunits.gradienttransform.height.href.id.image-rendering.in.in2.intercept.k.k1.k2.k3.k4.kerning.keypoints.keysplines.keytimes.lang.lengthadjust.letter-spacing.kernelmatrix.kernelunitlength.lighting-color.local.marker-end.marker-mid.marker-start.markerheight.markerunits.markerwidth.maskcontentunits.maskunits.max.mask.mask-type.media.method.mode.min.name.numoctaves.offset.operator.opacity.order.orient.orientation.origin.overflow.paint-order.path.pathlength.patterncontentunits.patterntransform.patternunits.pointer-events.points.preservealpha.preserveaspectratio.primitiveunits.r.rx.ry.radius.refx.refy.repeatcount.repeatdur.restart.result.rotate.scale.seed.shape-rendering.slope.specularconstant.specularexponent.spreadmethod.startoffset.stddeviation.stitchtiles.stop-color.stop-opacity.stroke-dasharray.stroke-dashoffset.stroke-linecap.stroke-linejoin.stroke-miterlimit.stroke-opacity.stroke.stroke-width.style.surfacescale.systemlanguage.tabindex.tablevalues.targetx.targety.transform.transform-origin.text-anchor.text-decoration.text-orientation.text-rendering.textlength.type.u1.u2.unicode.values.vector-effect.viewbox.visibility.version.vert-adv-y.vert-origin-x.vert-origin-y.width.word-spacing.wrap.writing-mode.xchannelselector.ychannelselector.x.x1.x2.xmlns.y.y1.y2.z.zoomandpan`.split(`.`)),ps=xo(`accent.accentunder.align.bevelled.close.columnalign.columnlines.columnspacing.columnspan.denomalign.depth.dir.display.displaystyle.encoding.fence.frame.height.href.id.largeop.length.linethickness.lquote.lspace.mathbackground.mathcolor.mathsize.mathvariant.maxsize.minsize.movablelimits.notation.numalign.open.rowalign.rowlines.rowspacing.rowspan.rspace.rquote.scriptlevel.scriptminsize.scriptsizemultiplier.selection.separator.separators.stretchy.subscriptshift.supscriptshift.symmetric.voffset.width.xmlns`.split(`.`)),ms=xo([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),hs=So(/{{[\w\W]*|^[\w\W]*}}/g),gs=So(/<%[\w\W]*|^[\w\W]*%>/g),_s=So(/\${[\w\W]*/g),vs=So(/^data-[\-\w.\u00B7-\uFFFF]+$/),ys=So(/^aria-[\-\w]+$/),bs=So(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),xs=So(/^(?:\w+script|data):/i),Ss=So(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Cs=So(/^html$/i),ws=So(/^[a-z][.\w]*(-[.\w]+)+$/i),Ts=So(/<[/\w!]/g),Es=So(/<[/\w]/g),Ds=So(/<\/no(script|embed|frames)/i),Os=So(/\/>/i),X={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},ks=xo(Y({},[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`])),As=function(){return typeof window>`u`?null:window},js=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},Ms=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Ns=function(e,t,n,r){return qo(e,t)&&No(e[t])?Y(r.base?$o(r.base):{},e[t],r.transform):n},Ps=function(e,t,n){let r=qo(e,t)?e[t]:void 0;return r&&typeof r==`object`?$o(r):n()};function Fs(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:As(),t=e=>Fs(e);if(t.version=`3.4.17`,t.removed=[],!e||!e.document||e.document.nodeType!==X.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=ts(d,`cloneNode`),p=ts(d,`remove`),m=ts(d,`removeAttributeNode`),h=ts(d,`nextSibling`),g=ts(d,`childNodes`),_=ts(d,`parentNode`),v=ts(d,`shadowRoot`),ee=ts(d,`attributes`),y=o&&o.prototype?ts(o.prototype,`nodeType`):null,te=o&&o.prototype?ts(o.prototype,`nodeName`):null,b=o&&o.prototype?ts(o.prototype,`ownerDocument`):null,x=function(e){return y?y(e):e.nodeType},S=function(e){return te?te(e):e.nodeName},C=ns(d,`namespaceURI`),w=function(e){return C?C(e):e.namespaceURI};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let T,E=``,D,ne=!1,re=0,ie=function(){if(re>0)throw Xo(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},ae=function(e){ie(),re++;try{return T.createHTML(e)}finally{re--}},O=function(e){ie(),re++;try{return T.createScriptURL(e)}finally{re--}},oe=function(){return ne||=(D=js(u,i),!0),D},k=n,se=k.implementation,ce=k.createNodeIterator,le=k.createDocumentFragment,ue=k.getElementsByTagName,A=r.importNode,j=Ms();t.isSupported=typeof go==`function`&&typeof _==`function`&&se&&se.createHTMLDocument!==void 0;let M=hs,de=gs,N=_s,fe=vs,pe=ys,me=xs,he=Ss,ge=ws,_e=bs,P=null,ve=Y({},[...is,...as,...os,...cs,...us]),F=null,ye=Y({},[...ds,...fs,...ps,...ms]),be=Object.seal(Co(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),xe=null,I=null,L=Object.seal(Co(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Se=!0,Ce=!0,we=!1,Te=!0,R=!1,Ee=!0,De=!1,Oe=!1,ke=null,Ae=null,je=!1,Me=!1,Ne=!1,Pe=!1,Fe=!0,Ie=!1,Le=`user-content-`,Re=!0,ze=!1,Be=null,Ve={},He=null,Ue=Y({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),We=null,Ge=Y({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Ke=null,qe=Y({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Je=`http://www.w3.org/1998/Math/MathML`,Ye=`http://www.w3.org/2000/svg`,Xe=`http://www.w3.org/1999/xhtml`,Ze=Xe,Qe=!1,$e=null,et=Y({},[Je,Ye,Xe],Ro),tt=xo([`mi`,`mo`,`mn`,`ms`,`mtext`]),nt=Y({},tt),rt=xo([`annotation-xml`]),it=Y({},rt),at=Y({},[`title`,`style`,`font`,`a`,`script`]),ot=null,st=[`application/xhtml+xml`,`text/html`],z=null,ct=null,lt=n.createElement(`form`),ut=function(e){return e instanceof RegExp||e instanceof Function},dt=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(ct&&ct===e)return;(!e||typeof e!=`object`)&&(e={}),e=$o(e),ot=st.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,z=ot===`application/xhtml+xml`?Ro:Lo,P=Ns(e,`ALLOWED_TAGS`,ve,{transform:z}),F=Ns(e,`ALLOWED_ATTR`,ye,{transform:z}),$e=Ns(e,`ALLOWED_NAMESPACES`,et,{transform:Ro}),Ke=Ns(e,`ADD_URI_SAFE_ATTR`,qe,{transform:z,base:qe}),We=Ns(e,`ADD_DATA_URI_TAGS`,Ge,{transform:z,base:Ge}),He=Ns(e,`FORBID_CONTENTS`,Ue,{transform:z}),xe=Ns(e,`FORBID_TAGS`,$o({}),{transform:z}),I=Ns(e,`FORBID_ATTR`,$o({}),{transform:z}),Ve=qo(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?$o(e.USE_PROFILES):e.USE_PROFILES:!1,Se=e.ALLOW_ARIA_ATTR!==!1,Ce=e.ALLOW_DATA_ATTR!==!1,we=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Te=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,R=e.SAFE_FOR_TEMPLATES||!1,Ee=e.SAFE_FOR_XML!==!1,De=e.WHOLE_DOCUMENT||!1,Me=e.RETURN_DOM||!1,Ne=e.RETURN_DOM_FRAGMENT||!1,Pe=e.RETURN_TRUSTED_TYPE||!1,je=e.FORCE_BODY||!1,Fe=e.SANITIZE_DOM!==!1,Ie=e.SANITIZE_NAMED_PROPS||!1,Re=e.KEEP_CONTENT!==!1,ze=e.IN_PLACE||!1,_e=rs(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:bs,Ze=typeof e.NAMESPACE==`string`?e.NAMESPACE:Xe,nt=Ps(e,`MATHML_TEXT_INTEGRATION_POINTS`,()=>Y({},tt)),it=Ps(e,`HTML_INTEGRATION_POINTS`,()=>Y({},rt));let t=Ps(e,`CUSTOM_ELEMENT_HANDLING`,()=>Co(null));if(be=Co(null),qo(t,`tagNameCheck`)&&ut(t.tagNameCheck)&&(be.tagNameCheck=t.tagNameCheck),qo(t,`attributeNameCheck`)&&ut(t.attributeNameCheck)&&(be.attributeNameCheck=t.attributeNameCheck),qo(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(be.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),So(be),R&&(Ce=!1),Ne&&(Me=!0),Ve&&(P=Y({},us),F=Co(null),Ve.html===!0&&(Y(P,is),Y(F,ds)),Ve.svg===!0&&(Y(P,as),Y(F,fs),Y(F,ms)),Ve.svgFilters===!0&&(Y(P,os),Y(F,fs),Y(F,ms)),Ve.mathMl===!0&&(Y(P,cs),Y(F,ps),Y(F,ms))),L.tagCheck=null,L.attributeCheck=null,qo(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?L.tagCheck=e.ADD_TAGS:No(e.ADD_TAGS)&&(P===ve&&(P=$o(P)),Y(P,e.ADD_TAGS,z))),qo(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?L.attributeCheck=e.ADD_ATTR:No(e.ADD_ATTR)&&(F===ye&&(F=$o(F)),Y(F,e.ADD_ATTR,z))),qo(e,`ADD_FORBID_CONTENTS`)&&No(e.ADD_FORBID_CONTENTS)&&(He===Ue&&(He=$o(He)),Y(He,e.ADD_FORBID_CONTENTS,z)),Re&&(P[`#text`]=!0),De&&Y(P,[`html`,`head`,`body`]),P.table&&(Y(P,[`tbody`]),delete xe.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw Xo(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw Xo(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=T;T=e.TRUSTED_TYPES_POLICY;try{E=ae(``)}catch(e){throw T=t,e}}else e.TRUSTED_TYPES_POLICY===null?(T=void 0,E=``):(T===void 0&&(T=oe()),T&&typeof E==`string`&&(E=ae(``)));xo&&xo(e),ct=e},ft=Y({},[...as,...os,...ss]),pt=Y({},[...cs,...ls]),mt=function(e,t,n){return t.namespaceURI===Xe?e===`svg`:t.namespaceURI===Je?e===`svg`&&(n===`annotation-xml`||nt[n]):!!ft[e]},ht=function(e,t,n){return t.namespaceURI===Xe?e===`math`:t.namespaceURI===Ye?e===`math`&&it[n]:!!pt[e]},gt=function(e,t,n){return t.namespaceURI===Ye&&!it[n]||t.namespaceURI===Je&&!nt[n]?!1:!pt[e]&&(at[e]||!ft[e])},_t=function(e){let t=w(e),n=Lo(S(e)),r=_(e),i,a;return r&&x(r)===X.element?(i={namespaceURI:w(r)},a=Lo(S(r))):(i={namespaceURI:Ze},a=`template`),$e[t]?t===Ye?mt(n,i,a):t===Je?ht(n,i,a):t===Xe?gt(n,i,a):!!(ot===`application/xhtml+xml`&&$e[t]):!1},vt=function(e){Ao(t.removed,{element:e});try{_(e).removeChild(e)}catch{if(p(e),!_(e))throw Xo(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},yt=function(e,t,n){try{m(e,t)}catch{try{e.removeAttribute(n)}catch{}}},bt=function(e){wt(e);let t=g(e);t&&Do(jo(t),e=>{try{p(e)}catch{}});let n=x(e)===X.element?ee(e):null;if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;typeof i==`string`&&yt(e,r,i)}},xt=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}Ao(t.removed,{attribute:r||null,from:n});try{r?m(n,r):n.removeAttribute(e)}catch{try{n.removeAttribute(e)}catch{}}if(e===`is`){if(Me||Ne)try{vt(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},St=function(e){let t=ee(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;typeof i!=`string`||F[z(i)]||yt(e,r,i)}},Ct=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0&&arguments[2],r=[e];for(;r.length>0;){let e=r.pop();if(t(e)===!1)continue;if(n&&x(e)===X.element){let t=v(e);zt(t)&&r.push(t)}let i=g(e);if(i)for(let e=i.length-1;e>=0;--e)r.push(i[e])}},wt=function(e){Ct(e,e=>{x(e)===X.element&&St(e)})},Tt=function(e){let t=[];return Ct(e,e=>{t.push(e)},!0),t},Et=function(e,t){let n=Po();Do(Tt(e),e=>{x(e)===X.element&&Fo(n,e)}),Do(t,e=>{x(e)===X.element&&!Io(n,e)&&St(e)})},Dt=function(e,n){let r=!1;return Do(t.removed,t=>{t.element&&(r||=t.element===e,wt(t.element))}),Et(e,n),r},Ot=function(e,t){let n=Be,r=null,i=()=>(r||(r=Po(),Do(t,e=>{Fo(r,e)})),r);for(let t=0;;t++){let r=Tt(e),a=[e],o=!1;if(Do(r,e=>{x(e)===X.documentFragment?Ao(a,e):!o&&!Io(n,e)&&(o=Io(i(),e))}),!o)return;if(t>=8)throw Xo(`the tree kept changing during in-place sanitization; refusing to return it`);Do(a,(t,n)=>{kt(t,n>0,e,i())})}},kt=function(e,t,n,r){let i=Pt(e),a;for(;a=i.nextNode();)Io(r,a)&&!Io(Be,a)&&(t&&Vt(j.uponSanitizeShadowNode,a,null),Kt(a,n),$t(a,n),zt(a.content)&&en(a.content))},At=function(e){Be&&Fo(Be,e)},jt=function(e,t){return Ee?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},Mt=function(e){Ee&&Ct(e,e=>{let t=x(e);if(t===X.processingInstruction||t===X.comment&&Yo(Es,e.data)){try{p(e)}catch{}return!1}if(t===X.element){let t=e,n=z(S(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&jt(`for`,n)&&t.removeAttribute(`for`)}catch{}}return!0})},Nt=function(e){let t=null,r=null;if(je)e=`<remove></remove>`+e;else{let t=zo(e,/^[\r\n\t ]+/);r=t&&t[0]}ot===`application/xhtml+xml`&&Ze===Xe&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=T?ae(e):e;if(Ze===Xe)try{t=new l().parseFromString(i,ot)}catch{}if(!t||!t.documentElement){t=se.createDocument(Ze,`template`,null);try{t.documentElement.innerHTML=Qe?E:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),Ze===Xe?ue.call(t,De?`html`:`body`)[0]:De?t.documentElement:a},Pt=function(e){let t=b?b(e):e.ownerDocument;return ce.call(t||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Ft=function(e){return e=Bo(e,M,` `),e=Bo(e,de,` `),e=Bo(e,N,` `),e},It=function(e){Lt(e);let t=e.querySelectorAll?.call(e,`template`);t&&Do(t,e=>{zt(e.content)&&It(e.content)})},Lt=function(e){e.normalize();let t=b?b(e):e.ownerDocument,n=ce.call(t||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),r=n.nextNode();for(;r;)r.data=Ft(r.data),r=n.nextNode()},Rt=function(e){let t=te?te(e):null;return typeof t!=`string`||z(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==ee(e)||typeof e.removeAttribute!=`function`||typeof e.removeAttributeNode!=`function`||typeof e.getAttributeNode!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==y(e)||e.childNodes!==g(e)},zt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return y(e)===X.documentFragment}catch{return!1}},Bt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return typeof y(e)==`number`}catch{return!1}};function Vt(e,n,r){e.length!==0&&Do(e,e=>{e.call(t,n,r,ct)})}let Ht=function(e,t){return!!(Ee&&e.hasChildNodes()&&!Bt(e.firstElementChild)&&Yo(Ts,e.textContent)&&Yo(Ts,e.innerHTML)||Ee&&ks[t]&&x(e)===X.element&&w(e)===Xe&&(Bt(e.firstElementChild)||typeof e.textContent==`string`&&Yo(Ts,e.textContent))||e.nodeType===X.processingInstruction||Ee&&e.nodeType===X.comment&&Yo(Es,e.data))},Ut=function(e,t){return e instanceof RegExp?Yo(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},Wt=function(e,t,n){if(!xe[t]&&Yt(t)&&Ut(be.tagNameCheck,t))return!1;if(Re&&!He[t]&&!He[Lo(t)]){let t=_(e),r=g(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,h(e))}}}return vt(e),!0},Gt=function(e,t,n,r){return e.length===0?t:t===n||t===r?$o(t):t},B=function(e,t){return e===t||_(e)!==null?!1:(ze&&wt(e),!0)},Kt=function(e,n){if(At(e),Vt(j.beforeSanitizeElements,e,null),B(e,n))return!0;if(Rt(e))return vt(e),!0;let r=z(S(e));if(P=Gt(j.uponSanitizeElement,P,ve,ke),Vt(j.uponSanitizeElement,e,{tagName:r,allowedTags:P}),B(e,n))return!0;if(Ht(e,r))return vt(e),!0;if(xe[r]||!(L.tagCheck instanceof Function&&L.tagCheck(r))&&!P[r]){let t=Wt(e,r,n);return t===!1&&(Vt(j.afterSanitizeElements,e,null),B(e,n))?!0:t}if(x(e)===X.element&&!_t(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&Yo(Ds,e.innerHTML))return vt(e),!0;if(R&&e.nodeType===X.text){let n=Ft(e.textContent);e.textContent!==n&&(Ao(t.removed,{element:e.cloneNode()}),e.textContent=n)}return Vt(j.afterSanitizeElements,e,null),B(e,n)},qt=function(e,t,r){if(I[t]||jt(t,e)||Fe&&(t===`id`||t===`name`)&&(r in n||r in lt))return!1;let i=F[t]||L.attributeCheck instanceof Function&&L.attributeCheck(t,e);return Ce&&Yo(fe,t)||Se&&Yo(pe,t)?!0:i?Ke[t]||Yo(_e,Bo(r,he,``))||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&Vo(r,`data:`)===0&&We[e]||we&&!Yo(me,Bo(r,he,``))?!0:!r:Yt(e)&&Ut(be.tagNameCheck,e)&&Ut(be.attributeNameCheck,t,e)||t===`is`&&be.allowCustomizedBuiltInElements&&Ut(be.tagNameCheck,r)},Jt=Y({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Yt=function(e){return!Jt[Lo(e)]&&Yo(ge,e)},Xt=function(e,t,n,r){if(T&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return ae(r);case`TrustedScriptURL`:return O(r)}return r},Zt=function(e,t,n,r){try{return n?e.setAttributeNS(n,t,r):e.setAttribute(t,r),!Rt(e)||(vt(e),!1)}catch{return xt(t,e),!1}},Qt=function(e,t){return Ee&&Yo(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,t)?!0:Lo(e)===`attributename`&&zo(t,`href`)!==null},$t=function(e,n){if(Vt(j.beforeSanitizeAttributes,e,null),B(e,n))return;let r=e.attributes;if(!r||Rt(e))return;F=Gt(j.uponSanitizeAttribute,F,ye,Ae);let i={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:F,forceKeepAttr:void 0},a=r.length,o=z(e.nodeName);for(;a--;){let n=r[a],s=n.name,c=n.namespaceURI,l=n.value,u=z(s),d=l,f=s===`value`?d:Ho(d),p=!1;i.attrName=u,i.attrValue=f,i.keepAttr=!0,i.forceKeepAttr=void 0,Vt(j.uponSanitizeAttribute,e,i),f=i.attrValue,Ie&&(u===`id`||u===`name`)&&Vo(f,Le)!==0&&(xt(s,e,n),f=Le+f,p=!0),Qt(s,f)?xt(s,e,n):i.forceKeepAttr||(i.keepAttr?!Te&&Yo(Os,f)?xt(s,e,n):(R&&(f=Ft(f)),qt(o,u,f)?(f=Xt(o,u,c,f),f!==d&&Zt(e,s,c,f)&&p&&ko(t.removed)):xt(s,e,n)):xt(s,e,n))}Vt(j.afterSanitizeAttributes,e,null),B(e,n)},en=function(e){let t=null,n=Pt(e);for(Vt(j.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(Vt(j.uponSanitizeShadowNode,t,null),Kt(t,e),$t(t,e),zt(t.content)&&en(t.content),x(t)===X.element){let e=v(t);zt(e)&&(tn(e),en(e))}R&&Lt(e),Vt(j.afterSanitizeShadowDOM,e,null)},tn=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){en(e.shadow);continue}let n=e.node,r=x(n)===X.element,i=g(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=te?te(n):null;if(typeof e==`string`&&z(e)===`template`){let e=n.content;zt(e)&&t.push({node:e,shadow:null})}}if(r){let e=v(n);zt(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(Qe=!e,Qe&&(e=`<!-->`),typeof e!=`string`&&!Bt(e)&&(e=es(e),typeof e!=`string`))throw Xo(`dirty is not a string, aborting`);if(!t.isSupported)return e;Oe?(P=ke,F=Ae):dt(n),(j.uponSanitizeElement.length>0||j.uponSanitizeAttribute.length>0)&&(P=$o(P)),j.uponSanitizeAttribute.length>0&&(F=$o(F)),t.removed=[];let c=ze&&typeof e!=`string`&&Bt(e),l=[],u=Be;if(c){Mt(e);let t=S(e);if(typeof t==`string`){let n=z(t);if(!P[n]||xe[n])throw bt(e),Xo(`root node is forbidden and cannot be sanitized in-place`)}if(Rt(e))throw bt(e),Xo(`root node is clobbered and cannot be sanitized in-place`);l=Tt(e),Be=Po()}else if(Bt(e))i=Nt(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===X.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),tn(i);else{if(!Me&&!R&&!De&&e.indexOf(`<`)===-1)return T&&Pe?ae(e):e;if(i=Nt(e),!i)return Me?null:Pe?E:``}i&&je&&vt(i.firstChild);let d=c?e:i;try{c&&tn(e);let t=Pt(d);for(;o=t.nextNode();)Kt(o,d),$t(o,d),zt(o.content)&&en(o.content);c&&Ot(e,l)}catch(t){throw c&&(bt(e),Dt(e,l)),t}finally{Be=u}if(c){if(Dt(e,l))throw Xo(`a node selected for removal could not be safely returned; refusing to sanitize in place`);return R&&It(e),e}if(Me){if(R&&It(i),Ne)for(s=le.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(F.shadowroot||F.shadowrootmode)&&(s=A.call(r,s,!0)),s}let f=De?i.outerHTML:i.innerHTML;return De&&P[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&Yo(Cs,i.ownerDocument.doctype.name)&&(f=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
62
+ `+f),R&&(f=Ft(f)),T&&Pe?ae(f):f},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};dt(e),Oe=!0,ke=P,Ae=F},t.clearConfig=function(){ct=null,Oe=!1,ke=null,Ae=null,T=D,E=``},t.isValidAttribute=function(e,t,n){ct||dt({});let r=z(e),i=z(t);return typeof n==`string`&&(Qt(t,n)||!Te&&Yo(Os,n))?!1:qt(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&qo(j,e)&&Ao(j[e],t)},t.removeHook=function(e,t){if(qo(j,e)){if(t!==void 0){let n=Oo(j[e],t);return n===-1?void 0:Mo(j[e],n,1)[0]}return ko(j[e])}},t.removeHooks=function(e){qo(j,e)&&(j[e]=[])},t.removeAllHooks=function(){j=Ms()},t}var Is=Fs();function Ls(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}var Rs=new oo({renderer:{code({text:e,lang:t,escaped:n}){return`<div class="code-block"><div class="code-block-head"><span>${Ls((t??``).trim().split(/\s+/)[0]||`代码块`)}</span><button type="button" data-copy-code>复制</button></div><pre><code>${n?e:Ls(e)}</code></pre></div>`},link(e){return`<a href="${Ls(e.href||``)}"${e.title?` title="${Ls(e.title)}"`:``} target="_blank" rel="noopener noreferrer">${this.parser.parseInline(e.tokens??[])}</a>`}}});function zs(e){let t=e.cloneNode(!0);return t.querySelectorAll(`br`).forEach(e=>e.replaceWith(`
63
+ `)),(t.textContent||``).replace(/\r\n/g,`
64
+ `).replace(/\n{3,}/g,`
65
+
66
+ `).trim()}function Bs(e){if(!e.includes(`<td`)&&!e.includes(`<th`)||typeof DOMParser>`u`)return e;let t=new DOMParser().parseFromString(`<div id="__md_root">${e}</div>`,`text/html`),n=t.getElementById(`__md_root`);return n?(n.querySelectorAll(`table`).forEach(e=>{if(e.parentElement?.classList.contains(`chat-md-table-scroll`))return;let n=t.createElement(`div`);n.className=`chat-md-table-scroll`,e.replaceWith(n),n.appendChild(e)}),n.querySelectorAll(`td, th`).forEach(e=>{if(e.querySelector(`:scope > .chat-md-cell`))return;let n=zs(e);if(!n)return;let r=t.createElement(`span`);for(r.className=`chat-md-cell`,r.setAttribute(`data-hint-fit`,``),r.setAttribute(`data-hint`,n);e.firstChild;)r.appendChild(e.firstChild);e.appendChild(r)}),n.innerHTML):e}var Vs=new Map,Hs=160,Us=``,Ws=``;function Gs(e){if(Us!==``&&e===Us)return Ws;let t=Vs.get(e);if(t!==void 0)return Us=e,Ws=t,t;let n=Rs.parse(e,{async:!1}),r=Bs(Is.sanitize(n,{ADD_ATTR:[`target`,`data-hint`,`data-hint-fit`]}));if(!(Us!==``&&e.startsWith(Us))){if(Vs.size>=Hs){let e=Vs.keys().next().value;e!==void 0&&Vs.delete(e)}Vs.set(e,r)}return Us=e,Ws=r,r}var Z=D(),Ks=(0,U.memo)(function({text:e,className:t}){return(0,Z.jsx)(`div`,{className:t,dangerouslySetInnerHTML:{__html:Gs(e)}})}),qs=6e4,Js=8e4,Ys=24e3,Xs=180;function Zs(e){return typeof e==`string`?e.trim():``}function Qs(e){return Zs(e).toLowerCase().replace(/\.(md|txt|docx?|xlsx?|csv|xmind)$/i,``).replace(/[\s_\-—::/\\()[\]()【】]+/g,``)}function $s(e){return e.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi,`Bearer [已隐藏]`).replace(/([\w-]*(?:password|passwd|pwd|secret|token|cookie|authorization|api[_-]?key|access[_-]?key|session[_-]?id|csrf)[\w-]*\s*[:=:]\s*)[^\s,;,;]+/gi,`$1[已隐藏]`)}function ec(e){let t=Zs(e);if(!t)return``;try{let e=new URL(t);return`${e.origin}${e.pathname}`}catch{return t.replace(/[?#].*$/,``)}}function tc(e){let t=Zs(e).replace(/\.[^.]+$/,``),n=t.match(/^(.+?)[vV](\d+(?:\.\d+)+)/);return n?`${Qs(n[1])}v${n[2]}`:Qs(t)}function nc(e){return[e.sourceTitle,e.sourcePath?.split(/[\\/]/).pop(),e.title,e.docTitle].map(Zs).filter(Boolean)}function rc(e){let t=Qs(e),n=new Set;for(let e=0;e<t.length-1;e+=1)n.add(t.slice(e,e+2));return n}function ic(e,t){let n=rc(e),r=rc(t);if(!n.size||!r.size)return 0;let i=0;for(let e of n)r.has(e)&&(i+=1);return i/(n.size+r.size-i)}function ac(e,t){let n=nc(t),r=n.map(Qs),i=Qs(t.sourceTitle),a=new Set(n.map(tc)),o=[e.sourceTitle,e.sourcePath,e.title,e.project],s=0;i&&Qs(e.sourceTitle)===i&&(s+=160),a.has(tc(e.sourceTitle))&&(s+=120),a.has(tc(e.title))&&(s+=100);for(let e of o.map(Qs))e&&(r.some(t=>t===e)?s+=70:r.some(t=>t.includes(e))?s+=35:r.some(t=>e.includes(t))&&(s+=25));return e.iteration&&n.some(t=>t.toUpperCase().includes(e.iteration))&&(s+=20),s}function oc(e,t){return Math.max(...nc(t).map(t=>{let n=Qs(e.name),r=Qs(t);return!n||!r?0:r.includes(n)?150:n.includes(r)?130:Math.round(ic(e.name,t)*100)}))}function sc(e,t){return e.map((e,n)=>({entry:e,index:n,score:ac(e,t)})).sort((e,t)=>t.score-e.score||e.index-t.index).find(e=>e.score>0)?.entry}function cc(e,t){return e.length===1?e[0]:e.map((e,n)=>({system:e,index:n,score:oc(e,t)})).sort((e,t)=>t.score-e.score||e.index-t.index).find(e=>e.score>=20)?.system}function lc(e,t,n){return e.length<=t?e:`${e.slice(0,t).trimEnd()}\n\n[${n}内容较长,已按 ${t} 字符截断;未显示部分请以原始来源为准]`}function uc(e,t){let n=Zs(t?.text);if(!n)return null;let r=[`### 需求拆解库(最新 XMind):${e.title}`,`- 项目:${e.project||`未分类`}`,`- 迭代:${e.iteration||`未标注`}`,...e.note?[`- 备注:${e.note}`]:[],``,`以下内容是用户在 XMind 客户端维护后的最新原文结构:`,n];return{entryId:e.id,title:e.title,fileName:e.fileName,block:lc(r.join(`
67
+ `),Js,`需求拆解库`)}}function dc(e,t){let n=[],r=new Set,i=e.directories.find(e=>e.id===t);for(;i&&!r.has(i.id);)r.add(i.id),n.unshift(i.name),i=e.directories.find(e=>e.id===i?.parentId);return n.join(` / `)||`未归类`}function fc(e,t=1200){return Array.isArray(e)?e.map(Zs).filter(Boolean).join(`;`).slice(0,t):``}function pc(e){let t=Zs(e.title),n=Zs(e.note),r=ec(e.ref);return $s([t,n||r].filter(Boolean).join(`:`)).slice(0,Xs)}function mc(e,t=` `){let n=e.map(pc).filter(Boolean).slice(0,2);return n.length?[`${t}- 证据:`,...n.map(e=>`${t} - ${e}`)]:[]}function hc(e,t){let n=[`- ${t.code} ${t.name}|目录:${dc(e,t.directoryId)}|状态:${t.status}`];t.purpose&&n.push(` - 作用:${t.purpose}`),t.entry&&n.push(` - 入口:${t.entry}`);let r=fc(t.roles);r&&n.push(` - 角色:${r}`);let i=fc(t.inputs);i&&n.push(` - 输入:${i}`);let a=fc(t.outputs);a&&n.push(` - 输出:${a}`);let o=fc(t.rules);o&&n.push(` - 业务规则:${o}`);let s=fc(t.writes);s&&n.push(` - 落库:${s}`);let c=fc(t.exceptions);return c&&n.push(` - 异常:${c}`),n.push(...mc(t.evidence)),n}function gc(e,t){let n=e.systems.find(e=>e.id===t);if(!n)return null;let r=[...n.functions].sort((e,t)=>dc(n,e.directoryId).localeCompare(dc(n,t.directoryId),`zh`)||e.order-t.order||e.code.localeCompare(t.code)),i=n.flows.slice(0,80),a=[`### 业务地图:${n.name}`,...n.description?[`- 说明:${n.description}`]:[],`- 功能:${r.length} 个;业务流程:${n.flows.length} 条`,``,`#### 功能目录与规则`,...r.flatMap(e=>hc(n,e))];if(i.length){a.push(``,`#### 业务流程`);let e=[];for(let t of i)a.push(`- ${t.code} ${t.name}|结果:${t.result||`未填写`}|状态:${t.status}`),a.push(...mc(t.evidence)),t.steps.forEach((r,i)=>{let o=n.functions.find(e=>e.id===r.functionId),s=r.dependencies.map(e=>`${e.system}·${e.label}`).filter(Boolean);s.length&&e.push(`- ${t.code}「${r.title}」→ ${s.join(`;`)}`);let c=[r.role?`角色=${r.role}`:``,r.system?`系统=${r.system}`:``,o?`功能=${o.code} ${o.name}`:r.manual?`人工步骤`:``,s.length?`依赖=${s.join(`;`)}`:``,r.input?`输入=${r.input}`:``,r.output?`输出=${r.output}`:``,r.next?`下一步=${r.next}`:``,r.branch?`分支=${r.branch}`:``,r.branchBroken?`分支待补全`:``].filter(Boolean);a.push(` ${i+1}. ${r.title}${c.length?`|${c.join(`|`)}`:``}`),a.push(...mc(r.evidence,` `))});e.length&&a.push(``,`#### 跨系统依赖`,...e),n.flows.length>i.length&&a.push(`- 其余 ${n.flows.length-i.length} 条流程未注入`)}return{systemId:n.id,systemName:n.name,functionCount:r.length,flowCount:n.flows.length,block:lc(a.join(`
68
+ `),qs,`业务地图`)}}async function _c(e,t){let n=e.requirementBreakdownContext,r=e.businessContext,i=[],a=e.requirementBreakdownContext?.entryId;if(a)try{let e=await t.getRequirementBreakdown(a),r=uc(e.entry,e.content);r?n=r:i.push(`需求拆解 XMind 没有可读取内容,已使用上次缓存`)}catch(e){let t=e instanceof Error?e.message:String(e);i.push(`需求拆解 XMind 刷新失败:${t},已使用上次缓存`)}let o=e.businessContext?.systemId;if(o)try{let e=gc(await t.loadBusinessMap(),o);e?r=e:i.push(`业务地图系统已不存在,已使用上次缓存`)}catch(e){let t=e instanceof Error?e.message:String(e);i.push(`业务地图刷新失败:${t},已使用上次缓存`)}return{requirementBreakdownContext:n,businessContext:r,warnings:i}}function vc(e,t){let n=e=>new Set([...rc(e)].filter(e=>/^[\p{L}\p{Script=Han}]{2,}$/u.test(e))),r=n(e),i=n(t);if(!r.size||!i.size)return 0;let a=0;for(let e of r)i.has(e)&&(a+=1);return a}function yc(e,t){if(!e?.block||!t.trim())return e;let n=e.block.split(`
69
+ `),r=n.findIndex(e=>/^\s*-\s+/.test(e));if(r<0)return e;let i=n.slice(0,r),a=n.slice(r),o=a.map((e,n)=>({line:e,index:n,depth:Math.max(0,(e.match(/^\s*/)?.[0].length||0)/2),parent:-1,score:vc(t,e.replace(/^\s*-\s*/,``))})),s=[];for(let e of o){for(;s.length&&o[s[s.length-1]].depth>=e.depth;)s.pop();e.parent=s.at(-1)??-1,s.push(e.index)}let c=o.filter(e=>e.score>=2).sort((e,t)=>t.score-e.score||e.index-t.index).slice(0,16);if(!c.length)return e;let l=new Set;for(let e of c){let t=e.index;for(;t>=0;)l.add(t),t=o[t]?.parent??-1;for(let t=e.index+1;t<o.length&&!(o[t].depth<=e.depth);t+=1)l.add(t)}let u=a.filter((e,t)=>l.has(t)).join(`
70
+ `),d=lc([...i,`[本批已按当前测试点裁剪 XMind 树;未显示的分支仍属于同一需求,不代表不存在]`,u].join(`
71
+ `),Ys,`需求拆解库本批上下文`);return{...e,block:d}}function bc(e){let t=[],n=null;for(let r of e)/^-\s+/.test(r)?(n?.length&&t.push(n),n=[r]):n&&n.push(r);return n?.length&&t.push(n),t}function xc(e,t){if(!e?.block||!t.trim())return e;let n=e.block.split(`
72
+ `),r=n.indexOf(`#### 功能目录与规则`),i=n.indexOf(`#### 业务流程`),a=n.indexOf(`#### 跨系统依赖`);if(r<0)return e;let o=n.slice(0,r),s=i>=0?i:a>=0?a:n.length,c=bc(n.slice(r+1,s)),l=a>=0?a:n.length,u=i>=0?bc(n.slice(i+1,l)):[],d=a>=0?n.slice(a+1).filter(Boolean):[],f=c.map(e=>({text:e.join(`
73
+ `).trim(),score:vc(t,e.join(`
74
+ `))})),p=u.map(e=>({text:e.join(`
75
+ `).trim(),score:vc(t,e.join(`
76
+ `))})),m=f.filter(e=>e.score>=2).sort((e,t)=>t.score-e.score).slice(0,12),h=p.filter(e=>e.score>=2).sort((e,t)=>t.score-e.score).slice(0,8);if(!m.length&&!h.length)return e;let g=[...o,`[本批已按当前测试点裁剪业务地图;未显示内容仍属于当前系统,不代表不存在]`,`#### 功能目录与规则`,...m.length?m.map(e=>e.text):[`- 本批没有直接命中的功能,按已列流程与测试点判断`]];return h.length&&g.push(``,`#### 业务流程`,...h.map(e=>e.text)),d.length&&g.push(``,`#### 跨系统依赖`,...d),{...e,block:lc(g.join(`
77
+ `),Ys,`业务地图本批上下文`)}}function Sc(e,t,n){return{requirementBreakdownContext:yc(e,n),businessContext:xc(t,n)}}var Cc=/(\s*(TP-[A-Za-z0-9_-]+)\s*)|\(\s*(TP-[A-Za-z0-9_-]+)\s*\)/i;function wc(e){let t=String(e||``).replace(/\r\n/g,`
78
+ `);if(!t.trim())return[];let n=t.split(`
79
+ `),r=[],i=``,a=null,o=()=>{a&&a.lines.some(e=>e.trim())&&r.push(a),a=null};for(let e of n)if(/^#{1,6}\s/.test(e.trim())||/^#{1,6}\s/.test(e))o(),i=e;else if(/^\s*-\s+\*\*/.test(e)){let t=e.match(Cc),n=(t?.[1]||t?.[2]||``).toUpperCase();o(),a={id:n||`anon_${r.length+1}`,storyHeader:i,lines:[e]}}else a&&a.lines.push(e);return o(),r}function Tc(e,t){if(!t.length)return``;let n=new Set(t.map(e=>e.toUpperCase())),r=e.filter(e=>n.has(e.id.toUpperCase()));if(!r.length)return``;let i=[],a=`\0`;for(let e of r)e.storyHeader&&e.storyHeader!==a&&(a=e.storyHeader,i.push(e.storyHeader)),i.push(...e.lines);return i.join(`
80
+ `).trim()}function Ec(e,t){let n=Math.max(1,Math.floor(t)),r=[];for(let t=0;t<e.length;t+=n)r.push(e.slice(t,t+n));return r}function Dc(e,t){let n=t?.maxPerBatch??40,r=t?.threshold??40,i=(e.testPointIds??[]).map(e=>String(e).trim()).filter(Boolean);if(i.length<=r)return[{index:1,total:1,ids:i,testPointBlock:e.testPointBlock??``,label:i.length?`${i.length} 条测试点`:`全量`}];let a=wc(e.testPointBlock??``),o=new Map(a.map(e=>[e.id.toUpperCase(),e])),s=Ec(i.map(e=>e.toUpperCase()),n),c=s.length;return s.map((t,n)=>{let r=t.map(e=>o.get(e)).filter(Boolean),i=r.length>0?Tc(r,t):Oc(e.testPointBlock??``,t),a=t[0]??``,s=t[t.length-1]??``;return{index:n+1,total:c,ids:t,testPointBlock:i,label:`${a}…${s}(${t.length} 条)`}})}function Oc(e,t){let n=new Set(t.map(e=>e.toUpperCase())),r=String(e||``).replace(/\r\n/g,`
81
+ `).split(`
82
+ `),i=[],a=``,o=!1;for(let e of r)if(/^#{1,6}\s/.test(e))a=e,o=!1;else if(/^\s*-\s+\*\*/.test(e)){let t=e.match(Cc),r=(t?.[1]||t?.[2]||``).toUpperCase();o=!!(r&&n.has(r)),o&&(a&&i[i.length-1]!==a&&i.push(a),i.push(e))}else o&&i.push(e);return i.join(`
83
+ `).trim()}function kc(e,t){let n=Sc(e.requirementBreakdownContext,e.businessContext,[t.label,t.testPointBlock].filter(Boolean).join(`
84
+ `));return{...e,testPointIds:t.ids.length?t.ids:e.testPointIds,testPointBlock:t.testPointBlock||e.testPointBlock,requirementBreakdownContext:n.requirementBreakdownContext,businessContext:n.businessContext}}function Ac(){let e=h().knowledgeCategories;return e?.length?[...e]:[...v]}function jc(e){let t=f(e);return _({knowledgeCategories:t}),g(),t}function Mc(e){let t=e.trim();if(!t)throw Error(`分类名称不能为空`);if(t.length>40)throw Error(`分类名称过长(最多 40 字)`);if(/[\\/]/.test(t))throw Error(`分类名称不可包含路径分隔符`);let n=Ac();if(n.includes(t))throw Error(`已存在「${t}」`);return jc([...n,t]),t}function Nc(e,t){let n=t.trim();if(!n)throw Error(`分类名称不能为空`);if(n.length>40)throw Error(`分类名称过长(最多 40 字)`);if(/[\\/]/.test(n))throw Error(`分类名称不可包含路径分隔符`);let r=Ac(),i=r.indexOf(e);if(i<0)throw Error(`分类不存在`);if(r.some((e,t)=>t!==i&&e===n))throw Error(`已存在「${n}」`);let a=[...r];return a[i]=n,jc(a),n}function Pc(e){let t=Ac();if(t.length<=1)throw Error(`至少保留一个分类`);if(!t.includes(e))throw Error(`分类不存在`);return jc(t.filter(t=>t!==e))}function Fc(e){let t=e.titleHint.trim()||`未命名`;return`${e.category} · ${t}`}function Ic(e){return Ac().includes(e)}function Lc(e){let t=e.match(/```(?:json)?\s*([\s\S]*?)```/)?.[1]??e.match(/\{[\s\S]*\}/)?.[0];if(!t)return null;try{let e=JSON.parse(t);if(!e||typeof e!=`object`)return null;let n=e.标题??e.知识库名称??e.title??e.name,r=e.分类??e.category,i=e.描述??e.description,a=e.正文??e.body??e.content??e.markdown,o=typeof n==`string`?n.trim():``,s=typeof r==`string`?r.trim():``,c=typeof i==`string`?i.trim():``,l=typeof a==`string`?a.trim():``;if(!l)return null;let u=e.质检通过??e.qcPass??e.pass,d=typeof u==`boolean`?u:typeof u!=`string`||!/^(false|0|no|否|未通过|fail)/i.test(u.trim()),f=e.质检问题??e.qcIssues??e.issues,p=Array.isArray(f)?f.map(e=>String(e).trim()).filter(Boolean):typeof f==`string`&&f.trim()?[f.trim()]:[],m=e.质检说明??e.qcNote??e.note;return{title:o,category:s,description:c,body:l,qcPass:d,qcIssues:p,qcNote:typeof m==`string`?m.trim():``}}catch{return null}}function Rc(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,``).replace(/\.md$/i,``).slice(0,64)||`未命名知识`}function zc(e){let t=e.trim();return!t||/[:#{}[\],&*?|>!<>=%@`"'\\\n]/.test(t)||/^\s|\s$/.test(e)?JSON.stringify(t):t}function Bc(e){return(e.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?([\s\S]*)$/)?.[1]??e).trim()}function Vc(e){let t=e.description.trim(),n=Bc(e.body),r=n.startsWith(`#`)?n:`# ${e.title}\n\n${n}`,i=[`---`,`title: ${zc(e.title)}`,`category: ${zc(e.category)}`];return t&&i.push(`description: ${zc(t)}`),i.push(`---`,``,r,``),i.join(`
85
+ `)}function Hc(e,t){let n=[...e.qcIssues],r=(e.title||t.titleHint||`未命名知识`).trim(),i=(e.category||t.category||``).trim();Ic(i)||(i=t.category),e.qcPass||n.push(`模型自检未通过(质检通过=false)`),(!r||r.length<2)&&n.push(`标题过短(至少 2 字)`),r.length>80&&n.push(`标题过长(最多 80 字)`),/[\\/]/.test(r)&&n.push(`标题不可包含路径分隔符`),Ic(i)||n.push(`分类必须是:${Ac().join(` / `)}`),e.body.trim()?e.body.trim().length<60&&n.push(`正文过短(建议不少于 60 字)`):n.push(`正文为空`);let a=[...new Set(n.filter(Boolean))];return{ok:a.length===0,issues:a,title:r,category:i,fileBase:Rc(r),description:(e.description||``).trim().slice(0,120)}}function Uc(e){let t=e.titleHint.trim()||`(可在结果中自拟简洁中文名)`;return`你是资深测试知识库编辑,擅长把规范、方法论、环境约定写成可复用的 Markdown 文档。
86
+
87
+ 【任务】
88
+ 根据用户在对话中提供的素材/需求,编写一份完整的知识库 Markdown 正文,入库到知识库对应分类目录。
89
+ 具体要求以用户本轮及近期对话输入为准。
90
+
91
+ 【目标分类】
92
+ ${e.category}
93
+ (分类仅限:${Ac().join(` / `)};不要写成需求文档或测试用例)
94
+
95
+ 【用户期望标题】
96
+ ${t}
97
+
98
+ 【内容要求】
99
+ 1. 结构清晰:标题、条目/表格/步骤可执行;避免空话。
100
+ 2. 可复用:适合后续对话用「@」引用。
101
+ 3. 不要输出用例表格字段集;不要写成需求 PRD。
102
+
103
+ 【输出前自检(必须)】
104
+ 1. 分类是否正确?
105
+ 2. 标题是否简洁可作文件名?
106
+ 3. 正文是否可落地、无互相矛盾?
107
+ 4. 若未通过,将「质检通过」设为 false,并在「质检问题」列出具体项。
108
+
109
+ 【输出格式(强制)】
110
+ 仅输出一个 JSON 对象(可无代码围栏),不要其它解释:
111
+ {
112
+ "标题": "简短中文名(不含 .md)",
113
+ "分类": "${e.category}",
114
+ "描述": "一句话摘要",
115
+ "质检通过": true,
116
+ "质检问题": [],
117
+ "质检说明": "一句话说明质检结论",
118
+ "正文": "# 标题\\n\\n完整 Markdown 正文……"
119
+ }
120
+
121
+ 约束:
122
+ - 「正文」为完整 Markdown 字符串(可含换行);frontmatter 由系统自动拼接,正文不要再写 --- frontmatter。
123
+ - 「质检通过」为 false 时系统不会入库。
124
+ - 不要输出 JSON 以外的闲聊;界面只展示执行摘要。`}function Wc(e=0){let t=Math.max(0,Math.floor(e));return`正在编写知识库文档…\n\n进度约 ${Math.min(95,Math.max(1,Math.round(95*(1-Math.exp(-t/90)))))}% · 已用 ${t}s\n完成后将质检并自动入库到知识库管理。`}function Gc(e){if(!e.ok){let t=[`**执行失败 / 未入库**`,``,e.error||`质检未通过或解析失败`],n=e.issues??[];if(n.length){t.push(``,`**质检问题**`);for(let e of n)t.push(`- ${e}`)}return t.push(``,`可调整说明后重新发送,或在插件中修改分类/标题。`),t.join(`
125
+ `)}let t=[`**执行成功**`,``,`- 标题:${e.title||`—`}`];return e.category&&t.push(`- 分类:${e.category}`),e.path&&t.push(`- 入库文件:知识库管理/${e.path}`),e.qcNote&&t.push(``,`**质检说明**`,e.qcNote),t.push(``,`下方卡片可点击打开文件;对话中也可用「@」引用(构建后或刷新列表)。`),t.join(`
126
+ `)}async function Kc(e){let t=`${e}.md`;try{let{entries:n}=await St(`knowledge`,`.`),r=new Set(n.filter(e=>e.type===`file`).map(e=>e.name));if(!r.has(t))return t;for(let t=2;t<100;t++){let n=`${e}-${t}.md`;if(!r.has(n))return n}}catch{}return`${e}-${Date.now().toString(36)}.md`}async function qc(e,t){let n=Lc(e);if(!n){let e=`未能解析出知识库结果,未写入文件`;return{ok:!1,error:e,issues:[],summary:Gc({ok:!1,error:e})}}let r=Hc(n,t);if(!r.ok){let e=`入库前质检未通过`;return{ok:!1,error:e,issues:r.issues,summary:Gc({ok:!1,error:e,issues:r.issues,qcNote:n.qcNote})}}if(!O(`knowledgeLib`)){let e=ae(`knowledgeLib`);return{ok:!1,error:e,issues:[],summary:Gc({ok:!1,error:e})}}try{let e=await Kc(r.fileBase),t=Vc({title:r.title,category:r.category,description:r.description,body:n.body});await Dt(`knowledge`,e,t.endsWith(`
127
+ `)?t:`${t}\n`);let i=Gc({ok:!0,title:r.title,path:e,category:r.category,qcNote:n.qcNote});return{ok:!0,path:e,title:r.title,category:r.category,qcNote:n.qcNote,summary:i}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,issues:[],summary:Gc({ok:!1,error:t})}}}var Jc=`你是 Lantern Harness(仓库 lantern-harness)的「插件开发」助手,只负责在本项目里开发「扩展插件」。
128
+
129
+ # 铁律:先评估、再确认、后开发
130
+ 1. 收到需求后,先只读调研相关代码(fs_read / fs_glob / fs_grep,必要时用只读命令),弄清现有插件约定。
131
+ 调研纪律:先用 fs_grep 定位符号 / 字符串,再只读命中片段;不要为了「看清楚」把整个目录、整份大文件逐个读一遍;
132
+ 与本次插件无关的模块不必打开;发出确认选项前,读取次数控制在必要范围(一般 8 次以内,确有必要再增加)。
133
+ 2. 在改任何文件之前,必须调用 ask_user_question 提出 2~4 个选择题(每题 2~4 个选项),覆盖:
134
+ - 插件形态:纯提示词型 / 带配置面板 / 侧栏库 / 需要本地服务能力
135
+ - 范围与边界:做什么、不做什么
136
+ - 命名与入口:插件 id / 中文名 / 从「+」「/」还是侧栏进入
137
+ - 默认开关:新插件在新建空间里默认开还是关(推荐默认关)
138
+ 每题给出推荐项,便于用户直接确认。
139
+ 3. 用户回答之前,禁止 fs_write / fs_mkdir / 改配置 / 写文档;这一轮只允许只读调研。
140
+ 4. 用户确认后才开始实现;用户改选或补充要求时,按新答案调整后再动手。
141
+ 5. 「确认」只认用户明确表达(如「开始实施」「按这个方案做」「确认」)。用户跳过(skipped)、关闭提问卡片、没作答、沉默,都不算确认,也绝不等于批准实施:
142
+ - 这类情况先停手,用几行说明你将采用的默认假设(哪几项按推荐)、插件形态与准备改动的文件范围;
143
+ - 然后等用户明确回复「开始实施」再写文件;跳过当轮只能写代码计划,禁止 fs_write / fs_mkdir / 改配置。
144
+ 6. 只改与本次插件相关的文件:不重构无关代码、不改主题样式、不动其它插件行为、不执行 git commit / git push。
145
+ 7. 完成后用简短条目汇报:插件 id / 中文名 / 入口位置 / 默认开关 / 改动文件 / 用户如何验证。
146
+
147
+ # 项目插件实现位置(先读再改)
148
+ - 注册表:src/lib/plugins.ts → PluginId 联合类型 + PLUGIN_CATALOG(字段:id/name/description/version/requiresDev/defaultEnabled/hasPanel/requires)
149
+ - 新建空间默认开关:config/app.defaults.json 的 plugins;同时补 src/lib/app-config.ts 的 emptyAppConfig().plugins
150
+ - 我的插件页:src/components/islands/PluginsPage.tsx(按注册表自动渲染;Tab「扩展插件」即扩展插件列表,卡片按 PLUGIN_CATALOG 的 category 分组)
151
+ - 工作台入口:hasPanel=true 的插件会自动出现在「+」弹窗与「/」菜单;入口文案与面板打开逻辑在 src/components/islands/ChatApp.tsx(pluginMenuItems / openPluginPanel / pickPluginMenu / 菜单 tip)
152
+ - 胶囊型入口(与「计划」「插件开发」一致):在 ChatApp 的 composerChip 增加一个取值,+ 菜单里点击后只激活胶囊,用户在主输入框描述要求后发送
153
+ - 带配置面板的插件:新建 src/components/islands/XxxPanel.tsx(复用 SlideOverDrawer);配置类型放 src/lib/xxx.ts;若配置需要跟会话保存,加到 src/lib/sessions.ts 的 ChatSession 与 SessionMetaPatch,并在 ChatApp 的会话切换 / 新建流程里同步
154
+ - 技能驱动插件:把业务正文、流程和校验放进空间技能;插件只声明推荐关系。需要组装会话系统规则时,在 src/lib/xxx.ts 通过技能服务读取,不要新增独立提示词库或提示词管理入口。
155
+ - 侧栏库:src/lib/nav-menu.ts(NavEntryId / NavEntryDef / i18n 键)、src/lib/plugin-nav.ts、src/components/islands/NavLibraries.tsx、src/lib/i18n.ts,以及 lh-plugins/lh-project-docs.mjs 的 DOC_ROOT_DIRS
156
+ - 本地 API:新建 lh-plugins/lh-xxx.mjs(导出 lhXxxPlugin,提供 configureServer 中间件),并在 astro.config.mjs 与 cli/server.mjs 的插件列表里注册;数据根用 builtin/session/space-context.mjs 的 getDataRoot() / getBaseRoot();PLUGIN_CATALOG 里补 category(内容库 / 生成能力 / 记忆与检索 / 待办与效率 / 开发工具),没有合适的分类时先问用户
157
+ - 文档:更新 docs/操作手册.md 的插件表与对应章节;在 CHANGELOG.md 顶部(当前版本或 Unreleased)增加条目
158
+
159
+ # 默认值约定
160
+ - 新建空间的插件开关默认关闭:config/app.defaults.json 与 src/lib/app-config.ts 的 emptyAppConfig().plugins 都写 false,不要为新插件破例。
161
+ - 「用户故事审查」是例外:它随「需求分析」默认打开(defaultEnabled true + autoEnableWith: 'reqAnalysis'),但可以被单独关掉;只有挂在父插件下、默认就该一起用的子项才这么写。
162
+ - PLUGIN_CATALOG 里的 defaultEnabled 也写 false:新增插件默认关闭,由用户在「我的插件」里手动开启。
163
+ - 依赖其它插件时用 requires 声明(如生成器依赖对应管理插件);父项打开时子项若应默认一起开,再加 autoEnableWith。
164
+
165
+ # 验证
166
+ - 可用时至少运行 pnpm typecheck;涉及服务端或纯函数时补充/运行相关 node:test。
167
+ - 不执行 git commit / git push,不擅自格式化无关文件。
168
+ - 改完说明哪些点没有实际运行验证,不要声称已跑通。
169
+
170
+ # 回答风格
171
+ - 中文、直接、少客套;评估阶段先说结论(做成哪种插件、为什么),再给确认选项。
172
+ - 不要空泛地描述「可以开发」,要给具体方案与取舍。
173
+ - 需要用户批准开工时,用一句明确的话收尾,例如「确认无误请回复:开始实施」。`;function Yc(e,t){let n=String(t??``).trim(),r=[Jc];return n&&r.push(`# 本次运行环境\n项目根(可直接用 fs_* 工具读写):${n}`),r.push(`# 本次需求\n${e.requirement.trim()||`(未填写,按用户后续消息执行)`}`),r.join(`
174
+
175
+ `)}var Xc=`/__tb_fs`,Zc=`你可以使用 Skill 工具(本地 fs 可用时):
176
+ - skill_list:列出工作区 / 项目根下约定目录中的 SKILL.md
177
+ - skill_load:按 id(目录名)或 path 加载技能正文到本轮上下文
178
+ - 需要遵循某技能流程时先 skill_list 再 skill_load,勿臆造技能内容`,Qc=[{type:`function`,function:{name:`skill_validate`,description:`Validate output using a registered space skill. Deterministically checks rows, template columns, source IDs, priorities and statistics; does not run a model or write business data.`,parameters:{type:`object`,properties:{id:{type:`string`},input:{type:`object`}},required:[`id`,`input`]}}},{type:`function`,function:{name:`skill_list`,description:`List available skills (SKILL.md) under the workspace / project (.cursor/skills, .agents/skills, skills/, or */SKILL.md).`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`skill_load`,description:`Load a skill by id (directory name) or path to SKILL.md. Returns the skill markdown body (may be truncated).`,parameters:{type:`object`,properties:{name:{type:`string`,description:`Skill id / directory name from skill_list, or relative/absolute path to SKILL.md`},path:{type:`string`,description:`Optional path to SKILL.md (alias of name)`}}}}}];async function $c(e,t){if(e===`skill_validate`)try{let e=JSON.parse(t||`{}`),n=await fetch(`${Xc}/skill/validate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:AbortSignal.timeout(8e3)});return JSON.stringify(await n.json())}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}if(e===`skill_list`)try{let e=await fetch(`${Xc}/skills`,{signal:AbortSignal.timeout(5e3)}),t=await e.json().catch(()=>({}));return e.ok?JSON.stringify({ok:!0,count:t.count??t.skills?.length??0,skills:t.skills??[]},null,2):JSON.stringify({ok:!1,error:t.error||`HTTP ${e.status}`})}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}if(e===`skill_load`){let e={};try{e=JSON.parse(t||`{}`)}catch{return JSON.stringify({ok:!1,error:`invalid JSON arguments`})}let n=String(e.name??e.path??e.id??``).trim();if(!n)return JSON.stringify({ok:!1,error:`name or path is required`});try{let e=await fetch(`${Xc}/skill-load`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n}),signal:AbortSignal.timeout(8e3)}),t=await e.json().catch(()=>({}));if(!e.ok){let n=typeof t==`object`&&t&&`error`in t?String(t.error):`HTTP ${e.status}`;return JSON.stringify({ok:!1,error:n})}return JSON.stringify(t,null,2)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}}return JSON.stringify({error:`unknown tool: ${e}`})}var el=`写操作只在用户明确要求时执行;改 / 删之前先用 list 拿到真实 id,不要臆造 id。参数可以用 id,也可以传名称(project / iteration / requirement),系统先精确再忽略大小写匹配。日期一律 YYYY-MM-DD;不确定就不要填,不要凭空猜测。`,tl=`项目列表工具(空间级,页面在 /pm/projects/):`+el+`新建项目只需要 name;归档用 pm_project_update 把 status 改成 archived。删除项目会连带删掉它的迭代、需求与缺陷,执行前先向用户确认影响范围。`,nl=`迭代管理工具(空间级,页面在 /pm/iterations/):`+el+`迭代必须挂在项目下;endDate 不能早于 startDate。进度按日期流逝计算,不要把它当成需求完成度。`,rl=`需求管理工具(空间级,页面在 /pm/requirements/):`+el+`需求必须挂在项目下,iterationId 可留空表示未排期;编号 REQ-### 由系统分配,不要自己编。acceptanceCriteria 是 [{ text, done }] 数组,仅在用户给出验收标准时填写。`,il=`缺陷管理工具(空间级,页面在 /pm/bugs/):`+el+`缺陷必须挂在项目下;iterationId / requirementId 可留空,填了就必须属于同一项目。编号 BUG-### 由系统分配,不要自己编。`,al={project:{type:`string`,description:`Project name (exact, then case-insensitive).`},projectId:{type:`string`,description:`Project id from pm_project_list. Prefer this.`},keyword:{type:`string`,description:`Match name / description / title.`},limit:{type:`number`,description:`Max rows, default 50.`}},ol=[{type:`function`,function:{name:`pm_project_list`,description:`List projects in the current space with iteration / requirement / bug counts. Use before any project write to get ids.`,parameters:{type:`object`,properties:{status:{type:`string`,enum:[...ge,`all`]},keyword:{type:`string`},limit:{type:`number`}}}}},{type:`function`,function:{name:`pm_project_add`,description:`Create one or more projects. Only when the user explicitly asks. name is required.`,parameters:{type:`object`,properties:{items:{type:`array`,items:{type:`object`,properties:{name:{type:`string`},description:{type:`string`},status:{type:`string`,enum:ge}},required:[`name`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_project_update`,description:`Update one project by id or name. Only pass fields that change.`,parameters:{type:`object`,properties:{id:{type:`string`},project:{type:`string`,description:`Project name, used when id is omitted.`},name:{type:`string`},description:{type:`string`},status:{type:`string`,enum:ge}}}}},{type:`function`,function:{name:`pm_project_delete`,description:`Delete projects by id or name. Also deletes their iterations, requirements and bugs; confirm scope with the user first.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},project:{type:`string`}}}}}],sl=[{type:`function`,function:{name:`pm_iteration_list`,description:`List iterations, optionally filtered by project / status. Includes date-based progress and overdue days.`,parameters:{type:`object`,properties:{...al,status:{type:`string`,enum:[...M,`all`]}}}}},{type:`function`,function:{name:`pm_iteration_add`,description:`Create one or more iterations under a project.`,parameters:{type:`object`,properties:{project:{type:`string`,description:`Project name (exact, then case-insensitive).`},projectId:{type:`string`,description:`Project id. Prefer this.`},items:{type:`array`,items:{type:`object`,properties:{name:{type:`string`},startDate:{type:`string`,description:`YYYY-MM-DD.`},endDate:{type:`string`,description:`YYYY-MM-DD, not before startDate.`},status:{type:`string`,enum:M},remark:{type:`string`}},required:[`name`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_iteration_update`,description:`Update one iteration by id or name. Use status "done" when the iteration is closed.`,parameters:{type:`object`,properties:{id:{type:`string`},iteration:{type:`string`,description:`Iteration name, used when id is omitted.`},project:{type:`string`},projectId:{type:`string`},name:{type:`string`},startDate:{type:`string`},endDate:{type:`string`},status:{type:`string`,enum:M},remark:{type:`string`}}}}},{type:`function`,function:{name:`pm_iteration_delete`,description:`Delete iterations by id or name. Requirements and bugs keep existing but lose the iteration link.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},iteration:{type:`string`}}}}}],cl=[{type:`function`,function:{name:`pm_requirement_list`,description:`List requirements, optionally filtered by project / iteration / status / priority / keyword.`,parameters:{type:`object`,properties:{...al,iteration:{type:`string`},iterationId:{type:`string`},status:{type:`string`,enum:[...de,`all`]},priority:{type:`string`,enum:[...me,`all`]}}}}},{type:`function`,function:{name:`pm_requirement_add`,description:`Create one or more requirements under a project. The REQ-### code is assigned by the server.`,parameters:{type:`object`,properties:{project:{type:`string`},projectId:{type:`string`},items:{type:`array`,items:{type:`object`,properties:{title:{type:`string`,description:`需求描述(可多行)`},iterationId:{type:`string`,description:`Optional; must belong to the project.`},iteration:{type:`string`,description:`Iteration name instead of id.`},priority:{type:`string`,enum:me},status:{type:`string`,enum:de},description:{type:`string`},acceptanceCriteria:{type:`array`,items:{type:`object`,properties:{text:{type:`string`},done:{type:`boolean`}},required:[`text`]}},githubIssue:{type:`string`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_requirement_update`,description:`Update one requirement by id, REQ code or title. Use status "done" when it is completed.`,parameters:{type:`object`,properties:{id:{type:`string`},requirement:{type:`string`,description:`Requirement title or REQ-###.`},project:{type:`string`},projectId:{type:`string`},iteration:{type:`string`},iterationId:{type:`string`},title:{type:`string`},priority:{type:`string`,enum:me},status:{type:`string`,enum:de},description:{type:`string`},acceptanceCriteria:{type:`array`,items:{type:`object`,properties:{text:{type:`string`},done:{type:`boolean`}},required:[`text`]}},githubIssue:{type:`string`}}}}},{type:`function`,function:{name:`pm_requirement_delete`,description:`Delete requirements by id, REQ code or title. Linked bugs lose the link.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},requirement:{type:`string`}}}}}],ll=[{type:`function`,function:{name:`pm_bug_list`,description:`List bugs, optionally filtered by project / iteration / status / severity / keyword.`,parameters:{type:`object`,properties:{...al,iteration:{type:`string`},iterationId:{type:`string`},status:{type:`string`,enum:[...he,`all`]},severity:{type:`string`,enum:[..._e,`all`]}}}}},{type:`function`,function:{name:`pm_bug_add`,description:`Create one or more bugs under a project. The BUG-### code is assigned by the server.`,parameters:{type:`object`,properties:{project:{type:`string`},projectId:{type:`string`},items:{type:`array`,items:{type:`object`,properties:{title:{type:`string`},iterationId:{type:`string`},iteration:{type:`string`},requirementId:{type:`string`},requirement:{type:`string`,description:`Requirement title or REQ-###.`},severity:{type:`string`,enum:_e},status:{type:`string`,enum:he},reproduceSteps:{type:`string`},expectedResult:{type:`string`},actualResult:{type:`string`},environment:{type:`string`},githubIssue:{type:`string`},attachment:{type:`string`},remark:{type:`string`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_bug_update`,description:`Update one bug by id, BUG code or title. Bug status flow: pending → todo → fixed → verifying → passed (or cancelled). Set status "verifying" after a fix is pushed and awaits the user's confirmation; only the user sets "passed".`,parameters:{type:`object`,properties:{id:{type:`string`},bug:{type:`string`,description:`Bug title or BUG-###.`},project:{type:`string`},projectId:{type:`string`},iteration:{type:`string`},iterationId:{type:`string`},requirement:{type:`string`},requirementId:{type:`string`},title:{type:`string`},severity:{type:`string`,enum:_e},status:{type:`string`,enum:he},reproduceSteps:{type:`string`},expectedResult:{type:`string`},actualResult:{type:`string`},environment:{type:`string`},githubIssue:{type:`string`},attachment:{type:`string`},remark:{type:`string`}}}}},{type:`function`,function:{name:`pm_bug_delete`,description:`Delete bugs by id, BUG code or title.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},bug:{type:`string`}}}}}];function Q(e,t){let n=e[t];return typeof n==`string`?n.trim():``}function ul(e,t){let n=Q(t,`projectId`);return n?e.projects.some(e=>e.id===n)?n:``:j(e.projects,Q(t,`project`))}function dl(e,t,n){let r=Q(n,`iterationId`);if(r)return e.iterations.some(e=>e.id===r&&e.projectId===t)?r:``;let i=Q(n,`iteration`);if(!i)return``;let a=e.iterations.find(e=>e.projectId===t&&e.name===i);if(a)return a.id;let o=i.toLowerCase();return e.iterations.find(e=>e.projectId===t&&e.name.toLowerCase()===o)?.id??``}function fl(e,t,n){let r=Q(n,`requirementId`);if(r)return e.requirements.some(e=>e.id===r&&e.projectId===t)?r:``;let i=Q(n,`requirement`);if(!i)return``;let a=e.requirements.filter(e=>e.projectId===t);return se(a,i)}function pl(e,t,n,r,i){let a=Q(t,`id`);if(a)return e.some(e=>e.id===a)?{id:a}:{id:``,error:`${r}不存在:${a}`};let o=Q(t,n);if(!o)return{id:``,error:`缺少${r} id 或名称`};let s=o.toLowerCase(),c=e.find(e=>i(e)===o)??e.find(e=>i(e).toLowerCase()===s);return c?{id:c.id}:{id:``,error:`找不到${r}:${o}`}}function ml(e,t){let n={};for(let r of t){if(!(r in e))continue;let t=e[r];t!=null&&(n[r]=t)}return n}function hl(e,t){let n=Q(t,`id`);if(n)return e.requirements.find(e=>e.id===n)??null;let r=Q(t,`requirement`);if(!r)return null;let i=r.toLowerCase();return e.requirements.find(e=>e.autoId.toLowerCase()===i)??e.requirements.find(e=>e.title===r)??e.requirements.find(e=>e.title.toLowerCase()===i)??null}function gl(e,t){let n=Q(t,`id`);if(n)return e.bugs.find(e=>e.id===n)??null;let r=Q(t,`bug`);if(!r)return null;let i=r.toLowerCase();return e.bugs.find(e=>e.autoId.toLowerCase()===i)??e.bugs.find(e=>e.title===r)??e.bugs.find(e=>e.title.toLowerCase()===i)??null}function _l(e,t){let n=t[e.id];return`[${e.id}] ${e.name} | 状态=${e.status} | 迭代=${n?.iterations??0} | 需求=${n?.requirements??0} | 缺陷=${n?.bugs??0}`}function vl(e){let t=pe(e),n=le(e);return`[${e.id}] ${e.name} | 项目=${e.projectId} | ${e.startDate||`—`} → ${e.endDate||`—`} | 状态=${e.status} | 进度=${t}%`+(n===null?``:` | 逾期${n}天`)}function yl(e){return`[${e.id}] ${e.autoId} ${e.title} | 项目=${e.projectId} | 迭代=${e.iterationId||`—`} | 优先级=${e.priority} | 状态=${e.status}`}function bl(e){return`[${e.id}] ${e.autoId} ${e.title} | 项目=${e.projectId} | 迭代=${e.iterationId||`—`} | 严重程度=${e.severity} | 状态=${e.status}`}function xl(e,t){return e.length?e.map((e,t)=>`${t+1}. ${e}`).join(`
179
+ `):t}function Sl(e,t,n,r){return r.map(r=>{let i=r&&typeof r==`object`?{...r}:{};if(i.projectId=n,t!==`iterations`){let t=dl(e,n,i);(`iteration`in i||`iterationId`in i)&&(i.iterationId=t)}if(t===`bugs`){let t=fl(e,n,i);(`requirement`in i||`requirementId`in i)&&(i.requirementId=t)}return delete i.project,delete i.iteration,delete i.requirement,i})}async function Cl(e,t,n={}){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}try{let t=await F(),i=Math.max(1,Math.min(200,Number(r.limit)||50));if(e===`pm_project_list`){let e=Q(r,`status`),n=k(t.projects,{status:e||`all`,keyword:Q(r,`keyword`)}).slice(0,i),a=ce(t);return JSON.stringify({ok:!0,total:t.projects.length,count:n.length,items:n,summary:xl(n.map(e=>_l(e,a)),`当前没有匹配的项目。`)})}if(e===`pm_project_add`){let e=(Array.isArray(r.items)?r.items:[r]).map(e=>e&&typeof e==`object`?e:{}).filter(e=>typeof e.name==`string`);if(!e.length)return JSON.stringify({error:`项目名称不能为空`});let i=await fe(`projects`,e,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:i.length,items:i,summary:`已创建 ${i.length} 个项目:\n${xl(i.map(e=>_l(e,ce(t))),``)}`})}if(e===`pm_project_update`){let e=pl(t.projects,r,`project`,`项目`,e=>e.name);if(e.error)return JSON.stringify({error:e.error});let n=ml(r,[`name`,`description`,`status`]);if(!Object.keys(n).length)return JSON.stringify({error:`没有可更新的字段`});let i=await ue(`projects`,e.id,n);return JSON.stringify({ok:!0,item:i,summary:`已更新项目:${i.name}`})}if(e===`pm_project_delete`){let e=Array.isArray(r.ids)?r.ids:[Q(r,`id`)||Q(r,`project`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=t.projects.find(t=>t.id===e)??t.projects.find(t=>t.name===e);i&&n.push(i.id)}if(!n.length)return JSON.stringify({error:`缺少项目 id 或名称`});let i=await N(`projects`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 个项目,并连带删除 ${i.cascaded} 条迭代 / 需求 / 缺陷。`})}if(e===`pm_iteration_list`){let e=ul(t,r),n=Q(r,`status`),a=A(t.iterations,{projectId:e||`all`,status:n||`all`,keyword:Q(r,`keyword`)}).slice(0,i);return JSON.stringify({ok:!0,total:t.iterations.length,count:a.length,items:a,summary:xl(a.map(vl),`当前没有匹配的迭代。`)})}if(e===`pm_iteration_add`){let e=ul(t,r);if(!e)return JSON.stringify({error:`请先指定项目(projectId 或 project 名称)`});let i=Sl(t,`iterations`,e,Array.isArray(r.items)?r.items:[r]);if(!i.length)return JSON.stringify({error:`迭代名称不能为空`});let a=await fe(`iterations`,i,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:a.length,items:a,summary:`已创建 ${a.length} 个迭代:\n${xl(a.map(vl),``)}`})}if(e===`pm_iteration_update`){let e=pl(t.iterations,r,`iteration`,`迭代`,e=>e.name);if(e.error)return JSON.stringify({error:e.error});let n=ml(r,[`name`,`startDate`,`endDate`,`status`,`remark`]);if(`projectId`in r||`project`in r){let e=ul(t,r);if(!e)return JSON.stringify({error:`所属项目不存在`});n.projectId=e}if(!Object.keys(n).length)return JSON.stringify({error:`没有可更新的字段`});let i=await ue(`iterations`,e.id,n);return JSON.stringify({ok:!0,item:i,summary:`已更新迭代:${vl(i)}`})}if(e===`pm_iteration_delete`){let e=Array.isArray(r.ids)?r.ids:[Q(r,`id`)||Q(r,`iteration`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=t.iterations.find(t=>t.id===e)??t.iterations.find(t=>t.name===e);i&&n.push(i.id)}if(!n.length)return JSON.stringify({error:`缺少迭代 id 或名称`});let i=await N(`iterations`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 个迭代;关联需求与缺陷已解除迭代关联。`})}if(e===`pm_requirement_list`){let e=ul(t,r),n=e?dl(t,e,r):Q(r,`iterationId`)||`all`,a=Q(r,`status`),o=Q(r,`priority`),s=P(t.requirements,{projectId:e||`all`,iterationId:n||`all`,status:a||`all`,priority:o||`all`,keyword:Q(r,`keyword`)}).slice(0,i);return JSON.stringify({ok:!0,total:t.requirements.length,count:s.length,items:s,summary:xl(s.map(yl),`当前没有匹配的需求。`)})}if(e===`pm_requirement_add`){let e=ul(t,r);if(!e)return JSON.stringify({error:`请先指定项目(projectId 或 project 名称)`});let i=Sl(t,`requirements`,e,Array.isArray(r.items)?r.items:[r]);if(!i.length)return JSON.stringify({error:`需求描述不能为空`});let a=await fe(`requirements`,i,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:a.length,items:a,summary:`已创建 ${a.length} 条需求:\n${xl(a.map(yl),``)}`})}if(e===`pm_requirement_update`){let e=hl(t,r);if(!e)return JSON.stringify({error:`找不到需求:请传 id、REQ-### 或标题`});let n={id:e.id},i=ml(r,[`title`,`priority`,`status`,`description`,`acceptanceCriteria`,`githubIssue`]),a=`projectId`in r||`project`in r?ul(t,r):e.projectId;if(!a)return JSON.stringify({error:`所属项目不存在`});if(a!==e.projectId&&(i.projectId=a),(`iterationId`in r||`iteration`in r)&&(i.iterationId=dl(t,a,r)),!Object.keys(i).length)return JSON.stringify({error:`没有可更新的字段`});let o=await ue(`requirements`,n.id,i);return JSON.stringify({ok:!0,item:o,summary:`已更新需求:${yl(o)}`})}if(e===`pm_requirement_delete`){let e=Array.isArray(r.ids)?r.ids:[Q(r,`id`)||Q(r,`requirement`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=se(t.requirements,e),a=t.requirements.find(t=>t.id===e)??t.requirements.find(t=>t.autoId===e)??t.requirements.find(e=>e.id===i);a&&n.push(a.id)}if(!n.length)return JSON.stringify({error:`缺少需求 id / 编号 / 名称`});let i=await N(`requirements`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 条需求;关联缺陷已解除需求关联。`})}if(e===`pm_bug_list`){let e=ul(t,r),n=e?dl(t,e,r):Q(r,`iterationId`)||`all`,a=Q(r,`status`),o=Q(r,`severity`),s=ve(t.bugs,{projectId:e||`all`,iterationId:n||`all`,status:a||`all`,severity:o||`all`,keyword:Q(r,`keyword`)}).slice(0,i);return JSON.stringify({ok:!0,total:t.bugs.length,count:s.length,items:s,summary:xl(s.map(bl),`当前没有匹配的缺陷。`)})}if(e===`pm_bug_add`){let e=ul(t,r);if(!e)return JSON.stringify({error:`请先指定项目(projectId 或 project 名称)`});let i=Sl(t,`bugs`,e,Array.isArray(r.items)?r.items:[r]);if(!i.length)return JSON.stringify({error:`缺陷标题不能为空`});let a=await fe(`bugs`,i,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:a.length,items:a,summary:`已创建 ${a.length} 条缺陷:\n${xl(a.map(bl),``)}`})}if(e===`pm_bug_update`){let e=gl(t,r);if(!e)return JSON.stringify({error:`找不到缺陷:请传 id、BUG-### 或标题`});let n={id:e.id},i=ml(r,[`title`,`severity`,`status`,`reproduceSteps`,`expectedResult`,`actualResult`,`environment`,`githubIssue`,`attachment`,`remark`]),a=`projectId`in r||`project`in r?ul(t,r):e.projectId;if(!a)return JSON.stringify({error:`所属项目不存在`});if(a!==e.projectId&&(i.projectId=a),(`iterationId`in r||`iteration`in r)&&(i.iterationId=dl(t,a,r)),(`requirementId`in r||`requirement`in r)&&(i.requirementId=fl(t,a,r)),!Object.keys(i).length)return JSON.stringify({error:`没有可更新的字段`});let o=await ue(`bugs`,n.id,i);return JSON.stringify({ok:!0,item:o,summary:`已更新缺陷:${bl(o)}`})}if(e===`pm_bug_delete`){let e=Array.isArray(r.ids)?r.ids:[Q(r,`id`)||Q(r,`bug`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=t.bugs.find(t=>t.id===e)??t.bugs.find(t=>t.autoId===e)??t.bugs.find(t=>t.title===e)??t.bugs.find(t=>t.title.toLowerCase()===e.toLowerCase());i&&n.push(i.id)}if(!n.length)return JSON.stringify({error:`缺少缺陷 id / 编号 / 名称`});let i=await N(`bugs`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 条缺陷。`})}return JSON.stringify({error:`unknown pm tool: ${e}`})}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var wl=`待办事项工具(空间级,跨会话保留,页面在 /todos/):
180
+ - 只有用户明确要求把某件事记成待办时才调用 todo_add:例如「记一下 / 加个待办 / 帮我跟进 / 周五一前完成记得提醒我 / 把这件事加到待办」。
181
+ - 用户只是在聊天里说到一件事、行程或计划,没有要你记录(没有「记 / 待办 / 跟进 / 提醒我」这类意图)时,不要调用 todo_add,也不要弹确认卡片;把内容正常聊完即可。不要从普通对话里自动「提炼」待办。
182
+ - 不要先用 ask_user_question 逐项追问待办字段。直接调用 todo_add,把已知内容填好;系统会弹出「待办快卡」:用户确认名称,状态自动为「进行中」、日期自动取当天(开始 / 截止可在快卡里直接改成区间)、所属任务默认「日常待办」(快卡里可下拉换成已有任务,任务管理里没有「日常待办」就按 进行中 / 重要不紧急 / 当年第一天 ~ 当年最后一天 创建),紧急程度跟随所属任务,点「确认新增」才落库。
183
+ - 用户明确说了要归到某个任务(如「加到登录模块这个任务下」)时,照常在 taskId / linkedTask 里填该任务,系统会保留你的指定,不再套「日常待办」。
184
+ - 调用 todo_add 必须给出待办标题(title);不要为了打开一张空白卡片而调用工具。用户想自己填名称时,让 ta 用侧栏「+ → 待办」。
185
+ - 用户问「还有哪些待办 / 进度」时用 todo_list;完成后用 todo_update 把 status 改为 done;删掉用 todo_delete。
186
+ - 日期一律 YYYY-MM-DD;不确定截止日期就先不填,不要凭空猜测;用户说了相对日期(如「后天」)时换算成具体日期。
187
+ - 只记录用户明确要求或明确同意的事项,不要把闲聊、假设写成待办。`,Tl=[`all`,...nr],El=[{type:`function`,function:{name:`todo_add`,description:`Create one or more long-lived todos in the current space (visible on the /todos/ page). Call ONLY when the user explicitly asks to record / track something as a todo (e.g. "记一下", "加个待办", "帮我跟进", "提醒我周五前完成"). Do NOT call it just because the conversation mentions a task, plan or trip, and do NOT extract todos from ordinary chat. A title is required: never call with empty items to open a blank card (the user has "+ → 待办" for manual entry). This opens a compact confirm card where the user checks the title, may change the date range (start ~ due), and may pick a different task from the task dropdown: status defaults to in_progress, dates default to today, the todo is attached to the "日常待办" task (auto-created when missing), and its priority follows the linked task. Pass taskId/linkedTask only when the user explicitly named a task. Do not ask the user for the other fields first.`,parameters:{type:`object`,properties:{items:{type:`array`,description:`Todos to create; each needs a title. Never send an empty array — only call this tool when the user explicitly asked to record a todo.`,items:{type:`object`,properties:{title:{type:`string`,description:`Short imperative title.`},status:{type:`string`,enum:nr,description:`New todos are always saved as in_progress; kept for update compatibility.`},priority:{type:`string`,enum:zn,description:`urgent_important | important | urgent | normal. Omit when unclear.`},linkedTask:{type:`string`,description:`Related task name / project name.`},taskId:{type:`string`,description:`Task id from the 任务管理 plugin (task_add / task_list). Prefer over linkedTask. Omit to use the default 日常待办 task.`},startDate:{type:`string`,description:`YYYY-MM-DD. Omit to default to today.`},dueDate:{type:`string`,description:`YYYY-MM-DD. Omit to default to today; keep an explicit deadline.`},note:{type:`string`,description:`Extra detail, dependencies, links.`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`todo_list`,description:`List long-lived todos of the current space, optionally filtered by status, priority or keyword.`,parameters:{type:`object`,properties:{status:{type:`string`,enum:Tl,description:`Default all.`},priority:{type:`string`,enum:[...zn,`all`],description:`Default all.`},keyword:{type:`string`,description:`Match title / linked task / note.`},limit:{type:`number`,description:`Max rows, default 50.`}}}}},{type:`function`,function:{name:`todo_update`,description:`Update one todo by id. Only pass fields that change; use status "done" when the user finishes it.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`Todo id from todo_list / todo_add.`},title:{type:`string`},status:{type:`string`,enum:nr},priority:{type:`string`,enum:zn},linkedTask:{type:`string`},taskId:{type:`string`,description:`Task id; empty string unlinks.`},startDate:{type:`string`,description:`YYYY-MM-DD.`},dueDate:{type:`string`,description:`YYYY-MM-DD.`},note:{type:`string`}},required:[`id`]}}},{type:`function`,function:{name:`todo_delete`,description:`Delete one or more todos by id.`,parameters:{type:`object`,properties:{ids:{type:`array`,description:`Todo ids to delete.`,items:{type:`string`}}},required:[`ids`]}}}];function Dl(e){let t=jn(e),n=In(e);return[`[${e.id}] ${e.title}`,`状态=${Vn[t]}`,e.priority?`紧急程度=${er[e.priority]}`:``,e.dueDate?`截止=${e.dueDate}`:``,n!==null&&t!==`done`&&t!==`cancelled`?n<0?`逾期${Math.abs(n)}天`:`剩余${n}天`:``,e.linkedTask?`关联=${e.linkedTask}`:``,e.note?`备注=${e.note}`:``].filter(Boolean).join(` | `)}function Ol(e){return e.length?e.map((e,t)=>`${t+1}. ${Dl(e)}`).join(`
188
+ `):`当前没有匹配的待办。`}function kl(e){return typeof e==`string`&&nr.includes(e)}function Al(e){return typeof e==`string`&&zn.includes(e)}function jl(e){let t={};return typeof e.title==`string`&&(t.title=e.title.trim()),kl(e.status)&&(t.status=e.status),Al(e.priority)&&(t.priority=e.priority),typeof e.linkedTask==`string`&&(t.linkedTask=e.linkedTask.trim()),typeof e.taskId==`string`&&(t.taskId=e.taskId.trim()),typeof e.startDate==`string`&&(t.startDate=e.startDate.trim()),typeof e.dueDate==`string`&&(t.dueDate=e.dueDate.trim()),typeof e.note==`string`&&(t.note=e.note.trim()),t}async function Ml(e,t,n={}){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}try{if(e===`todo_add`){let e=(Array.isArray(r.items)?r.items:[r]).map(H).filter(e=>!!e);if(!e.length)return JSON.stringify({error:`待办名称不能为空`});let t=await tr(e,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:t.length,items:t,summary:`已记录 ${t.length} 条待办:\n${Ol(t)}`})}if(e===`todo_list`){let e=await Fn(),t=r.status,n=kl(t)?t:`all`,i=Al(r.priority)?r.priority:`all`,a=typeof r.keyword==`string`?r.keyword:``,o=Math.max(1,Math.min(200,Number(r.limit)||50)),s=Rn(e,{status:n,priority:i,keyword:a}).slice(0,o);return JSON.stringify({ok:!0,total:e.length,count:s.length,items:s,summary:Ol(s)})}if(e===`todo_update`){let e=typeof r.id==`string`?r.id.trim():``;if(!e)return JSON.stringify({error:`缺少待办 id`});let t=jl(r);if(!Object.keys(t).length)return JSON.stringify({error:`没有可更新的字段`});let n=await Pn(e,t);return JSON.stringify({ok:!0,item:n,summary:`已更新待办:${Dl(n)}`})}if(e===`todo_delete`){let e=(Array.isArray(r.ids)?r.ids:[r.id]).filter(e=>typeof e==`string`&&!!e.trim()).map(e=>e.trim());if(!e.length)return JSON.stringify({error:`缺少待办 id`});let t=await Ln(e);return JSON.stringify({ok:!0,removed:t,summary:`已删除 ${t} 条待办。`})}return JSON.stringify({error:`unknown todo tool: ${e}`})}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var Nl=`日常待办`;function Pl(e=Kn()){let t=/^\d{4}/.test(e)?e.slice(0,4):String(new Date().getFullYear());return{title:Nl,status:`in_progress`,priority:`important`,startDate:`${t}-01-01`,dueDate:`${t}-12-31`}}function Fl(e){let t=e.filter(e=>e.title.trim()===Nl).filter(e=>e.status!==`closed`&&e.status!==`cancelled`);return t.find(e=>e.status===`in_progress`)??t[0]??null}function Il(e,t){let n=t.taskId?.trim();if(n){let t=e.find(e=>e.id===n);if(t)return t}let r=t.linkedTask?.trim();if(!r)return null;let i=e.filter(e=>e.title.trim()===r);return i.find(e=>e.status!==`closed`&&e.status!==`cancelled`)??i[0]??null}function Ll(e,t,n=Kn()){let r=e=>/^\d{4}-\d{2}-\d{2}$/.test(e),i=r(e),a=r(t),o=i?e:a&&t<n?t:n;return{startDate:o,dueDate:a?t<o?o:t:o}}async function Rl(e,t=Kn()){let n=[],r=!0;try{n=await $n()}catch{r=!1}let i=r?Fl(n):null,a=e.map(e=>{let a={...e,status:`in_progress`,...Ll(e.startDate,e.dueDate,t)};if(!r)return{...a,taskId:``,linkedTask:``};let o=Il(n,e);return o?{...a,taskId:o.id,linkedTask:o.title}:e.linkedTask.trim()?{...a,taskId:``}:{...a,taskId:i?.id??``,linkedTask:i?.title??`日常待办`}}),o=!i&&r&&a.some(e=>!e.taskId.trim()&&e.linkedTask.trim()===`日常待办`);return{items:a,tasksAvailable:r,willCreateRoutine:o}}async function zl(e){if(!e.some(e=>!e.taskId.trim()&&e.linkedTask.trim()===`日常待办`))return e;let t=Fl(await $n());if(!t){let[e]=await Bn([Pl()],{mode:`ai`});t=e??null}let n=t;if(!n)throw Error(`创建「日常待办」任务失败`);return e.map(e=>!e.taskId.trim()&&e.linkedTask.trim()===`日常待办`?{...e,taskId:n.id,linkedTask:n.title,priority:n.priority}:e)}var Bl=`任务管理工具(空间级,跨会话保留,页面在 /tasks/):
189
+ - 用户说「建个任务 / 开个项目任务 / 把这件事拆成任务」时调用 task_add;一次可传多条。
190
+ - 不要先用 ask_user_question 逐项追问任务字段。直接调用 task_add,把已知字段填好;系统会弹出与「+ → 任务」完全相同的确认卡片,用户在卡片里补充或修改,点「确认新增」才落库。
191
+ - 用户没说任务内容时也直接调用 task_add(items 传空数组或 [{ "title": "" }]),系统会打开空白确认卡片让用户自己填。
192
+ - 只查询用 task_list;改状态 / 日期用 task_update;删任务用 task_delete。
193
+ - 任务下的待办用 todo_add 的 taskId 关联,任务本身不重复记录待办内容。
194
+ - 日期一律 YYYY-MM-DD;不确定就先不填,不要凭空猜测。`,Vl=[...Zn,`urgent`,`all`];function Hl(e){return typeof e==`string`&&Zn.includes(e)}function Ul(e){let t=Jn(e);return[`[${e.id}] ${e.title}`,`状态=${Gn[e.status]}`,e.priority?`紧急程度=${Yn[e.priority]}`:``,e.startDate?`开始=${e.startDate}`:``,e.dueDate?`截止=${e.dueDate}`:``,t===null?``:`周期=${t}天`,e.note?`备注=${e.note}`:``].filter(Boolean).join(` | `)}function Wl(e){return e.length?e.map((e,t)=>`${t+1}. ${Ul(e)}`).join(`
195
+ `):`当前没有匹配的任务。`}var Gl=[{type:`function`,function:{name:`task_add`,description:`Create one or more long-lived tasks in the current space (visible on the /tasks/ page). Use when the user asks to create a task / project item. This opens the same editable confirm card as the manual + menu, so do not ask the user for the fields first.`,parameters:{type:`object`,properties:{items:{type:`array`,description:`Tasks to create. Pass an empty array to open a blank confirm card for the user to fill in.`,items:{type:`object`,properties:{title:{type:`string`,description:`Short task title.`},status:{type:`string`,enum:Zn,description:`pool | in_progress | done | closed. Default pool.`},priority:{type:`string`,enum:Qn,description:`urgent_important | important | urgent | normal. Omit when unclear.`},startDate:{type:`string`,description:`YYYY-MM-DD.`},dueDate:{type:`string`,description:`YYYY-MM-DD.`},note:{type:`string`,description:`Extra detail, scope, links.`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`task_list`,description:`List tasks of the current space, optionally filtered by status, priority or keyword.`,parameters:{type:`object`,properties:{status:{type:`string`,enum:Vl,description:`Default all.`},priority:{type:`string`,enum:[...Qn,`all`],description:`Default all.`},keyword:{type:`string`,description:`Match title / note.`},limit:{type:`number`,description:`Max rows, default 50.`}}}}},{type:`function`,function:{name:`task_update`,description:`Update one task by id. Only pass fields that change.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`Task id from task_list / task_add.`},title:{type:`string`},status:{type:`string`,enum:Zn},priority:{type:`string`,enum:[...Qn,``]},startDate:{type:`string`,description:`YYYY-MM-DD; empty string clears.`},dueDate:{type:`string`,description:`YYYY-MM-DD; empty string clears.`},note:{type:`string`}},required:[`id`]}}},{type:`function`,function:{name:`task_delete`,description:`Delete one or more tasks by id. Linked todos are kept (only unlinked).`,parameters:{type:`object`,properties:{ids:{type:`array`,description:`Task ids to delete.`,items:{type:`string`}}},required:[`ids`]}}}];function Kl(e){try{let t=JSON.parse(e||`{}`);return(Array.isArray(t.items)?t.items:[t]).filter(e=>!!e&&typeof e==`object`&&typeof e.title==`string`)}catch{return[]}}async function ql(e,t,n={}){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}try{if(e===`task_add`){let e=(Array.isArray(r.items)?r.items:[r]).map(Un).filter(e=>!!e);if(!e.length)return JSON.stringify({error:`任务名称不能为空`});let t=await Bn(e,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:t.length,items:t,summary:`已创建 ${t.length} 个任务:\n${Wl(t)}`})}if(e===`task_list`){let e=await $n(),t=r.status,n=Hl(t)?t:t===`urgent`?`urgent`:`all`,i=typeof r.priority==`string`&&Qn.includes(r.priority)?r.priority:`all`,a=typeof r.keyword==`string`?r.keyword:``,o=Math.max(1,Math.min(200,Number(r.limit)||50)),s=Hn(e,{status:n,priority:i,keyword:a}).slice(0,o);return JSON.stringify({ok:!0,total:e.length,count:s.length,items:s,summary:Wl(s)})}if(e===`task_update`){let e=typeof r.id==`string`?r.id.trim():``;if(!e)return JSON.stringify({error:`缺少任务 id`});let t={};if(typeof r.title==`string`&&(t.title=r.title.trim()),Hl(r.status)&&(t.status=r.status),r.priority===``?t.priority=``:qn(r.priority)&&(t.priority=r.priority),typeof r.startDate==`string`&&(t.startDate=r.startDate.trim()),typeof r.dueDate==`string`&&(t.dueDate=r.dueDate.trim()),typeof r.note==`string`&&(t.note=r.note.trim()),!Object.keys(t).length)return JSON.stringify({error:`没有可更新的字段`});let n=await Wn(e,t);return JSON.stringify({ok:!0,item:n,summary:`已更新任务:${Ul(n)}`})}if(e===`task_delete`){let e=(Array.isArray(r.ids)?r.ids:[r.id]).filter(e=>typeof e==`string`&&!!e.trim()).map(e=>e.trim());if(!e.length)return JSON.stringify({error:`缺少任务 id`});let t=await Xn(e);return JSON.stringify({ok:!0,removed:t,summary:`已删除 ${t} 个任务。`})}return JSON.stringify({error:`unknown task tool: ${e}`})}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var Jl=`/__tb_sessions/query`;function Yl(e){if(!e||typeof e!=`object`)return``;let t=e;return typeof t.content==`string`?t.content:Array.isArray(t.content)?t.content.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e?String(e.text??``):``).join(`
196
+ `):``}function Xl(e,t){let n=t.trim().toLowerCase();if(!n)return null;let r=(e.title||``).trim(),i=0,a=``;r.toLowerCase().includes(n)&&(i+=10,a=r);let o=Array.isArray(e.messages)?e.messages:[];for(let e=o.length-1;e>=0;e--){let t=Yl(o[e]),r=t.toLowerCase().indexOf(n);if(!(r<0)){if(i+=1,!a){let e=Math.max(0,r-24),i=Math.min(t.length,r+n.length+48);a=`${e>0?`…`:``}${t.slice(e,i).replace(/\s+/g,` `)}${i<t.length?`…`:``}`}if(o.length-e>40)break}}return i<=0?null:{score:i,snippet:a||r||e.id}}function Zl(e,t,n){let r=String(t??``).trim();if(!r||!e?.sessions?.length)return[];let i=Math.min(Math.max(n?.limit??20,1),50),a=n?.includeArchived===!0,o=[];for(let t of e.sessions){if(t.deleted||t.archived&&!a)continue;let e=Xl(t,r);e&&o.push({sessionId:t.id,title:t.title||`新对话`,archived:!!t.archived,score:e.score,snippet:e.snippet,updatedAt:t.updatedAt})}return o.sort((e,t)=>t.score-e.score||t.updatedAt-e.updatedAt),o.slice(0,i)}async function Ql(e,t){let n=String(e??``).trim();if(!n)return{backend:`sqlite`,hits:[]};try{let e=new URLSearchParams({q:n,limit:String(t?.limit??20)});t?.includeArchived&&e.set(`archived`,`1`);let r=await fetch(`${Jl}?${e}`,{signal:AbortSignal.timeout(4e3)}),i=await r.json().catch(()=>null);return!r.ok||!i||!Array.isArray(i.hits)?null:{backend:i.backend||`sqlite`,hits:i.hits}}catch{return null}}var $l=`你可以使用工作区变更工具:
197
+ - workspace_changes_list:查看本会话内已记录的写文件/建目录
198
+ - workspace_changes_clear:清空本会话变更记录(不回滚磁盘文件)`,eu=[{type:`function`,function:{name:`workspace_changes_list`,description:`List workspace file mutations recorded in this chat session (fs_write / fs_mkdir).`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`workspace_changes_clear`,description:`Clear the in-session workspace change log (does not delete files on disk).`,parameters:{type:`object`,properties:{}}}}];function tu(e){return String(e??``).trim().replace(/\\/g,`/`).replace(/^\.\//,``)}function nu(e,t){let n=tu(t.path);if(!n)return Array.isArray(e)?[...e]:[];let r={path:n,op:t.op,at:t.at??Date.now()};return[...Array.isArray(e)?e.filter(e=>tu(e.path)!==n):[],r].slice(-100)}function ru(e,t){if(e!==`fs_write`&&e!==`fs_mkdir`)return null;try{let n=JSON.parse(t||`{}`);if(n.error||n.ok===!1)return null;let r=tu(String(n.path??``));return r?{path:r,op:e===`fs_mkdir`?`mkdir`:`write`}:null}catch{return null}}function iu(e,t){if(e===`workspace_changes_list`){let e=Array.isArray(t)?t:[];return{text:JSON.stringify({ok:!0,count:e.length,changes:e.map(e=>({path:e.path,op:e.op,at:new Date(e.at).toISOString()}))},null,2)}}return e===`workspace_changes_clear`?{text:JSON.stringify({ok:!0,cleared:!0,count:0}),next:[]}:{text:JSON.stringify({error:`unknown tool: ${e}`})}}var au=6e5;function ou(e){if(e==null||!Number.isFinite(e)||e<0)return`unavailable`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;if(n<60)return r?`${n}m${r}s`:`${n}m`;let i=Math.floor(n/60),a=n%60;return a?`${i}h${a}m`:`${i}h`}function su(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||`unavailable`}catch{return`unavailable`}}function cu(e,t){try{return`${new Intl.DateTimeFormat(`en-CA`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1,timeZoneName:`shortOffset`}).format(e).replace(`,`,``)} (${t})`}catch{return e.toISOString()}}function lu(e={}){let t=e.now??Date.now(),n=su(),r=e.lastInjectAt??null;if(!(r==null||!Number.isFinite(r)||t-r>=6e5)&&r!=null)return{text:`【时间上下文 time-context】沿用上次采样(节流 ${au/6e4} 分钟)。浏览器时区:${n}。解释未标注时区的日期时间时请使用该时区;若不确定请向用户确认。`,injected:!1,at:r};let i=e.lastUserMessageAt!=null&&Number.isFinite(e.lastUserMessageAt)?t-e.lastUserMessageAt:null;return{text:[`【时间上下文 time-context】`,`当前时间:${cu(new Date(t),n)}`,`浏览器时区:${n}`,`距上一轮用户消息:${ou(i)}`,`解释未标注时区的日期时间时请使用上述时区;若时区信息混杂或缺失,请向用户确认。`].join(`
199
+ `),injected:!0,at:t}}var uu=`会话交互工具(默认可用):
200
+ - todo_write:维护本会话完整待办列表(替换式写入);多步任务用它展示进度;允许多个 in_progress
201
+ - ask_user_question:向用户提出结构化问题并等待回答;缺信息或需确认时使用,勿空猜`,du={type:`function`,function:{name:`todo_write`,description:`Record and update a task list for multi-step work. Replace the complete list each call. Keep active work in_progress (several allowed in parallel). Mark completed as soon as done. Skip for trivial single-step tasks.`,parameters:{type:`object`,properties:{todos:{type:`array`,description:`The COMPLETE task list, replacing any previous list.`,items:{type:`object`,properties:{content:{type:`string`,description:`What the task is — a short imperative line.`},status:{type:`string`,enum:[`pending`,`in_progress`,`completed`],description:`pending | in_progress | completed`}},required:[`content`,`status`]}}},required:[`todos`]}}},fu={type:`function`,function:{name:`ask_user_question`,description:`Ask the user a concise structured question when you need confirmation, a choice, or missing information before proceeding. Pauses until the user answers.`,parameters:{type:`object`,properties:{questions:{type:`array`,description:`Questions to ask the user before continuing.`,items:{type:`object`,properties:{id:{type:`string`,description:`Stable id; echoed in the answer.`},question:{type:`string`,description:`The specific question.`},header:{type:`string`,description:`Optional short heading.`},options:{type:`array`,items:{type:`object`,properties:{label:{type:`string`},description:{type:`string`}},required:[`label`]}},multi_select:{type:`boolean`,description:`Allow selecting more than one option. Default false.`}},required:[`id`,`question`]}}},required:[`questions`]}}};function pu(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=String(n.content??``).trim(),r=String(n.status??``);e&&(r===`pending`||r===`in_progress`||r===`completed`)&&t.push({content:e,status:r})}return t}function mu(e){let t={};try{t=JSON.parse(e||`{}`)}catch{return[]}if(!Array.isArray(t.questions))return[];let n=[];for(let e of t.questions){if(!e||typeof e!=`object`)continue;let t=String(e.id??``).trim(),r=String(e.question??``).trim();if(!t||!r)continue;let i=e.options,a=Array.isArray(i)?i.map(e=>({label:String(e?.label??``).trim(),description:e?.description?String(e.description):void 0})).filter(e=>e.label):void 0;n.push({id:t,question:r,header:e.header?String(e.header):void 0,options:a?.length?a:void 0,multi_select:!!e.multi_select})}return n}function hu(e,t){let n=e.options??[];if(!n.length)return null;let r=t.trim().split(/[,,、;;\s]+/).filter(Boolean);if(!r.length)return null;let i=[];for(let e of r){let t=Number(e.replace(/^第/,``).replace(/[.。)]$/,``));if(!Number.isInteger(t)||t<1||t>n.length)return null;let r=n[t-1]?.label;r&&!i.includes(r)&&i.push(r)}return!e.multi_select&&i.length>1?null:i.length?i:null}function gu(e,t){let n=t??{selected:[],text:``};if(n.skipped)return{id:e.id,selected:[],skipped:!0};let r=n.text.trim();if(r){let t=e.options?.length?hu(e,r):null;return t?{id:e.id,selected:t}:{id:e.id,text:r}}return{id:e.id,selected:[...n.selected]}}function _u(e,t){return e.map((e,n)=>{let r=t[n],i=r?.skipped?`(跳过,未作答)`:r?.text?.trim()?r.text.trim():(r?.selected??[]).join(`、`)||`(跳过,未作答)`,a=e.header?`${e.header} / ${e.question}`:e.question;return`${n+1}. ${a}\n → ${i}`}).join(`
202
+ `)}var vu=`【计划模式 · 探查中】当前禁止写操作(不可 fs_write / bash / pwsh 等)。
203
+ - 先用只读工具(fs_list / fs_read / fs_glob / fs_grep / web_* / kb_*)探查
204
+ - 形成方案后调用 submit_plan,等待用户批准;未批准前不要声称已修改文件
205
+ - 可用 ask_user_question / todo_write 澄清与拆解`,yu=`【计划模式 · 已批准】用户已批准方案,可以按批准内容实施(写文件 / 执行命令)。
206
+ - 实施中若需大幅变更方案,再次 submit_plan 征求批准
207
+ - 仍优先小步、可回滚的改动`,bu={type:`function`,function:{name:`submit_plan`,description:`Submit an implementation plan for user approval (plan mode). Blocks until the user approves or rejects.`,parameters:{type:`object`,properties:{title:{type:`string`,description:`Short plan title`},summary:{type:`string`,description:`What will change and why`},steps:{type:`array`,items:{type:`string`},description:`Ordered implementation steps`}},required:[`title`,`steps`]}}};function xu(e){try{let t=JSON.parse(e||`{}`),n=String(t.title??``).trim(),r=String(t.summary??``).trim(),i=Array.isArray(t.steps)?t.steps.map(e=>String(e??``).trim()).filter(Boolean):[];return!n||!i.length?null:{title:n,summary:r,steps:i.slice(0,24)}}catch{return null}}function Su(e){return e===`planning`||e===`approved`?e:`off`}function Cu(e){if(!e||typeof e!=`object`)return null;let t=e,n=String(t.title??``).trim(),r=String(t.summary??``).trim(),i=Array.isArray(t.steps)?t.steps.map(e=>String(e??``).trim()).filter(Boolean):[];return!n||!i.length?null:{title:n,summary:r,steps:i.slice(0,24)}}var wu=8e4,Tu=.28;function Eu(e){return(e.content?.length??0)+(e.reasoning?.length??0)}function Du(e){return e.reduce((e,t)=>e+Eu(t),0)}function Ou(e,t){let n=typeof t==`number`&&t>0?t:e?Bt[e]:void 0;return n&&n>0?Math.max(24e3,Math.floor(n*4*Tu)):wu}function ku(e,t,n){return Du(e)>=Ou(t,n)}function Au(e){return e.map(e=>{let t=e.role===`user`?`User`:`Assistant`,n=(e.content||``).trim(),r=e.reasoning?.trim()?`\n[thinking]\n${e.reasoning.trim().slice(0,1200)}`:``;return`${t}:\n${n.slice(0,6e3)}${r}`}).join(`
208
+
209
+ ---
210
+
211
+ `).slice(0,6e4)}async function ju(e,t,n){let r=Au(t);if(!r.trim())return``;let i=[{role:`system`,content:`你是会话压缩助手。将对话历史压缩为简洁中文摘要,保留:目标、关键决策、文件路径、未完成事项、约束。不要编造;不要输出寒暄;用条目或短段落,控制在 800 字以内。`},{role:`user`,content:`请压缩下列对话历史:\n\n${r}`}];return(await Rt(e,i,n)).trim()||`(摘要为空)`}async function Mu(e,t,n){let r=Math.max(2,n?.keepRecent??8);if(t.length<=r+1||!n?.force&&!ku(t,e.model,n?.contextWindow))return{messages:t,summary:``,compacted:!1};let i=t.slice(0,-r),a=t.slice(-r),o=await ju(e,i,n?.signal);return{messages:[{role:`user`,content:`【会话摘要 · 较早消息已压缩】\n${o}`},{role:`assistant`,content:`已记录摘要。后续回复将基于摘要与最近对话继续。`},...a],summary:o,compacted:!0}}function Nu(e){return/^\/compact(?:\s|$)/i.test(e.trim())}var Pu=`你可以使用会话目标工具:
212
+ - goal_get:读取本会话当前目标
213
+ - goal_set:设定或更新目标(status=active)
214
+ - goal_done:将目标标为已完成
215
+ - goal_clear:清除目标
216
+ 有活跃目标时应围绕其推进;重大偏离前用 ask_user_question 或更新目标。
217
+ 系统可能在目标未完成时自动续轮(goal-round-driver);完成后务必 goal_done,避免空转。`,Fu=[{type:`function`,function:{name:`goal_get`,description:`Get the current session goal (text + status).`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`goal_set`,description:`Set or replace the session goal. Marks it active.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Goal statement for this session`}},required:[`text`]}}},{type:`function`,function:{name:`goal_done`,description:`Mark the current session goal as done.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`goal_clear`,description:`Clear the session goal.`,parameters:{type:`object`,properties:{}}}}];function Iu(e){if(!e||typeof e!=`object`)return null;let t=e,n=String(t.text??``).trim();if(!n)return null;let r=t.status===`done`||t.status===`cleared`||t.status===`active`?t.status:`active`;return{text:n.slice(0,500),status:r,updatedAt:typeof t.updatedAt==`number`?t.updatedAt:Date.now()}}function Lu(e){return!e||e.status===`cleared`||!e.text?JSON.stringify({ok:!0,goal:null}):JSON.stringify({ok:!0,goal:{text:e.text,status:e.status}})}function Ru(e){return!e||e.status!==`active`?null:e.text.trim()||null}function zu(e){let t=e.trim();if(!/^\/goal(?:\s|$)/i.test(t))return null;let n=t.replace(/^\/goal\s*/i,``).trim();if(!n)return{kind:`show`};if(/^clear\b/i.test(n))return{kind:`clear`};if(/^done\b/i.test(n))return{kind:`done`};if(/^set\s+/i.test(n)){let e=n.replace(/^set\s+/i,``).trim();return e?{kind:`set`,text:e}:{kind:`show`}}return{kind:`set`,text:n}}function Bu(e){return zu(e)!=null}var Vu=`[goal-round-driver]`;function Hu(e,t,n){return`${Vu} 续轮 ${t}/${n}:请继续推进目标「${e.trim().slice(0,200)}」。若已完成请调用 goal_done;若阻塞请说明原因或 ask_user_question,勿空转重复相同工具。`}function Uu(e){return e.trimStart().startsWith(Vu)}function Wu(e){let t=Math.max(1,Math.floor(e.maxRounds??3));return!(!e.goalActive||!e.turnOk||e.aborted||e.hasFollowUp||e.askUserPending||e.roundsUsed>=t)}function Gu(e){return e.trim().replace(/[\\/:*?"<>|]+/g,`_`).replace(/\s+/g,` `).slice(0,48)||`session`}function Ku(e){if(!e||typeof e!=`object`)return{raw:e};let t=e,n={role:t.role,content:(t.content,t.content)};return typeof t.reasoning==`string`&&t.reasoning&&(n.reasoning=t.reasoning),typeof t.time==`number`&&(n.time=t.time),typeof t.model==`string`&&(n.model=t.model),t.usage&&typeof t.usage==`object`&&(n.usage=t.usage),typeof t.scheduleId==`string`&&(n.scheduleId=t.scheduleId),Array.isArray(t.attachments)&&(n.attachments=t.attachments.map(e=>{if(!e||typeof e!=`object`)return e;let t=e;return{name:t.name,size:t.size,type:t.type}})),Array.isArray(t.images)&&(n.images=t.images.map(e=>{if(!e||typeof e!=`object`)return e;let t=e;return{id:t.id,name:t.name,omittedDataUrl:!0}})),Array.isArray(t.refs)&&(n.refs=t.refs),n}var qu=`lantern-harness-session-v1`;function Ju(e){return{exportedAt:new Date().toISOString(),format:qu,session:{id:e.id,title:e.title,createdAt:e.createdAt,updatedAt:e.updatedAt,archived:e.archived,pinned:e.pinned,workspacePath:e.workspacePath,goal:e.goal,todos:e.todos,messages:(e.messages??[]).map(Ku)}}}function Yu(e){return`${JSON.stringify(Ju(e),null,2)}\n`}function Xu(e){let t=[];t.push(JSON.stringify({type:`session`,exportedAt:new Date().toISOString(),id:e.id,title:e.title,createdAt:e.createdAt,updatedAt:e.updatedAt,workspacePath:e.workspacePath,goal:e.goal}));for(let n of e.messages??[])t.push(JSON.stringify({type:`message`,sessionId:e.id,...Ku(n)}));return`${t.join(`
218
+ `)}\n`}function Zu(e,t,n){let r=new Blob([t],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.rel=`noopener`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function Qu(e,t=`json`){if(typeof document>`u`)return{ok:!1,error:`download requires browser`};let n=new Date().toISOString().replace(/[:.]/g,`-`).slice(0,19),r=`session-${Gu(e.title)}-${n}`;if(t===`jsonl`){let t=`${r}.jsonl`;return Zu(t,Xu(e),`application/x-ndjson;charset=utf-8`),{ok:!0,filename:t}}let i=`${r}.json`;return Zu(i,Yu(e),`application/json;charset=utf-8`),{ok:!0,filename:i}}var $u=`tw-session-schedules`,ed=`/__tb_schedule`,td=`你可以使用定时提醒工具:
219
+ - schedule_create:创建提醒(text + dueAt ISO 或 delayMinutes)
220
+ - schedule_list:列出本会话未取消的提醒
221
+ - schedule_update:修改 text / dueAt
222
+ - schedule_cancel:取消提醒
223
+ 本地服务在线时提醒落盘并由主机到点写入原会话;否则仅页面打开时投递。`,nd=[{type:`function`,function:{name:`schedule_create`,description:`Create a session reminder. Provide dueAt (ISO datetime) or delayMinutes from now.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Reminder content`},dueAt:{type:`string`,description:`ISO 8601 datetime`},delayMinutes:{type:`number`,description:`Minutes from now (alternative to dueAt)`}},required:[`text`]}}},{type:`function`,function:{name:`schedule_list`,description:`List scheduled reminders for the current session.`,parameters:{type:`object`,properties:{includeDelivered:{type:`boolean`}}}}},{type:`function`,function:{name:`schedule_update`,description:`Update a scheduled reminder text and/or dueAt.`,parameters:{type:`object`,properties:{id:{type:`string`},text:{type:`string`},dueAt:{type:`string`},delayMinutes:{type:`number`}},required:[`id`]}}},{type:`function`,function:{name:`schedule_cancel`,description:`Cancel a scheduled reminder.`,parameters:{type:`object`,properties:{id:{type:`string`}},required:[`id`]}}}];function rd(){return`sch_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}var id=null;async function ad(){try{let e=await fetch(`${ed}/health`,{signal:AbortSignal.timeout(1500)});return e.ok?(id=!!(await e.json()).ok,id):(id=!1,!1)}catch{return id=!1,!1}}function od(){try{let e=localStorage.getItem(m($u));if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.map(e=>cd(e)).filter(e=>!!e):[]}catch{return[]}}function sd(e){localStorage.setItem(m($u),JSON.stringify(e.slice(-200)))}function cd(e){if(!e||typeof e!=`object`)return null;let t=e,n=String(t.id??``).trim(),r=String(t.sessionId??``).trim(),i=String(t.text??``).trim(),a=Number(t.dueAt);if(!n||!r||!i||!Number.isFinite(a))return null;let o=t.status===`delivered`||t.status===`cancelled`||t.status===`scheduled`?t.status:`scheduled`;return{id:n,sessionId:r,text:i.slice(0,500),dueAt:a,status:o,createdAt:Number(t.createdAt)||Date.now(),updatedAt:Number(t.updatedAt)||Date.now()}}function ld(e){if(typeof e.delayMinutes==`number`&&Number.isFinite(e.delayMinutes)){let t=Math.max(.1,e.delayMinutes);return Date.now()+Math.round(t*6e4)}let t=String(e.dueAt??``).trim();if(!t)return null;let n=Date.parse(t);return Number.isFinite(n)?n:null}function ud(e,t=!1){return od().filter(t=>t.sessionId===e).filter(e=>t||e.status===`scheduled`).sort((e,t)=>e.dueAt-t.dueAt)}function dd(e,t){let n=String(t.text??``).trim();if(!n)return{ok:!1,error:`text is required`};if(!e)return{ok:!1,error:`no active session`};let r=ld(t);if(r==null)return{ok:!1,error:`dueAt or delayMinutes is required`};if(r<Date.now()-5e3)return{ok:!1,error:`dueAt is in the past`};let i=Date.now(),a={id:rd(),sessionId:e,text:n.slice(0,500),dueAt:r,status:`scheduled`,createdAt:i,updatedAt:i},o=od();return o.push(a),sd(o),{ok:!0,reminder:a}}function fd(e,t){let n=String(t.id??``).trim();if(!n)return{ok:!1,error:`id is required`};let r=od(),i=r.findIndex(t=>t.id===n&&t.sessionId===e);if(i<0)return{ok:!1,error:`reminder not found`};let a=r[i];if(a.status!==`scheduled`)return{ok:!1,error:`cannot update status=${a.status}`};let o=a.dueAt;if(t.dueAt!=null||t.delayMinutes!=null){let e=ld(t);if(e==null)return{ok:!1,error:`invalid dueAt / delayMinutes`};o=e}let s=t.text==null?a.text:String(t.text).trim();if(!s)return{ok:!1,error:`text cannot be empty`};let c={...a,text:s.slice(0,500),dueAt:o,updatedAt:Date.now()};return r[i]=c,sd(r),{ok:!0,reminder:c}}function pd(e,t){let n=String(t??``).trim();if(!n)return{ok:!1,error:`id is required`};let r=od(),i=r.findIndex(t=>t.id===n&&t.sessionId===e);if(i<0)return{ok:!1,error:`reminder not found`};let a={...r[i],status:`cancelled`,updatedAt:Date.now()};return r[i]=a,sd(r),{ok:!0,reminder:a}}function md(e=Date.now()){let t=od(),n=[],r=!1;for(let i=0;i<t.length;i++){let a=t[i];if(a.status===`scheduled`&&a.dueAt<=e){let o={...a,status:`delivered`,updatedAt:e};t[i]=o,n.push(o),r=!0}}return r&&sd(t),n}function hd(e,t){return`⏰ 定时提醒:${e}\n<!--tb-schedule:${t}-->`}async function gd(e,t){try{let n=await fetch(`${ed}${e}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t),signal:AbortSignal.timeout(8e3)});return n.ok?await n.json():null}catch{return null}}async function _d(){if(id!==!1){let e=await gd(`/claim`,{});if(e&&e.ok)return id=!0,Array.isArray(e.reminders)?e.reminders.map(cd).filter(e=>!!e):[];if(id===!0)return md();if(await ad(),id){let e=await gd(`/claim`,{});if(e&&e.ok&&Array.isArray(e.reminders))return e.reminders.map(cd).filter(e=>!!e)}}return md()}async function vd(e,t,n){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}if(id??await ad()){if(e===`schedule_create`){let e=await gd(`/create`,{...r,sessionId:n});if(e)return JSON.stringify(e,null,2)}else if(e===`schedule_list`)try{let e=new URLSearchParams({sessionId:n,includeDelivered:r.includeDelivered?`1`:`0`}),t=await fetch(`${ed}/list?${e}`,{signal:AbortSignal.timeout(5e3)});if(t.ok)return JSON.stringify(await t.json(),null,2)}catch{}else if(e===`schedule_update`){let e=await gd(`/update`,{...r,sessionId:n});if(e)return JSON.stringify(e,null,2)}else if(e===`schedule_cancel`){let e=await gd(`/cancel`,{id:r.id,sessionId:n});if(e)return JSON.stringify(e,null,2)}else return JSON.stringify({error:`unknown tool: ${e}`});id=!1}if(e===`schedule_create`)return JSON.stringify(dd(n,r),null,2);if(e===`schedule_list`){let e=ud(n,!!r.includeDelivered);return JSON.stringify({ok:!0,count:e.length,reminders:e},null,2)}return e===`schedule_update`?JSON.stringify(fd(n,r),null,2):e===`schedule_cancel`?JSON.stringify(pd(n,r.id),null,2):JSON.stringify({error:`unknown tool: ${e}`})}var yd=[{id:`explore`,label:`探索`,description:`只读查文件 / 搜网页,汇总结论(不可写盘、无 bash)`,mode:`explore`},{id:`general`,label:`通用`,description:`可读写工作区文件 + 网页(无 bash、不可再派生子代理)`,mode:`general`}],bd=`你可以使用子代理工具(进程内;默认与主会话同模型,可在设置里改子代理模型):
224
+ - list_agents:列出可用预设与正在运行/最近完成的子代理(仅本会话)
225
+ - spawn_subagent:派生子代理执行独立任务(默认等待完成;background=true 则后台跑)
226
+ - fork_subagent:带着当前对话上下文 fork 子代理并行干活(仍是子代理,不是分叉会话)
227
+ - subagent_list / subagent_status / subagent_await / subagent_abort:查看、查询、等待、中断
228
+ - subagent_message:向运行中的子代理追加指示(steer)
229
+ 适合可隔离的探索/子任务;主会话勿把全部工作塞给子代理。`,xd=[{type:`function`,function:{name:`list_agents`,description:`List available subagent presets and recent/running subagents.`,parameters:{type:`object`,properties:{includeRecent:{type:`boolean`,description:`Include recent finished agents (default true)`}}}}},{type:`function`,function:{name:`spawn_subagent`,description:`Spawn a subagent to run a focused task. Default waits until done and returns the result.`,parameters:{type:`object`,properties:{agent:{type:`string`,description:`Preset id: explore | general (default explore)`},prompt:{type:`string`,description:`Task for the subagent`},background:{type:`boolean`,description:`If true, return id immediately; use subagent_await later`}},required:[`prompt`]}}},{type:`function`,function:{name:`fork_subagent`,description:`Fork a subagent with a slice of the current conversation context, then run a task.`,parameters:{type:`object`,properties:{agent:{type:`string`,description:`Preset id: explore | general`},prompt:{type:`string`,description:`Task for the forked subagent`},background:{type:`boolean`}},required:[`prompt`]}}},{type:`function`,function:{name:`subagent_list`,description:`List running and recent subagents for this page session.`,parameters:{type:`object`,properties:{includeDone:{type:`boolean`}}}}},{type:`function`,function:{name:`subagent_status`,description:`Get status of one subagent by id in this page session (no wait).`,parameters:{type:`object`,properties:{id:{type:`string`}},required:[`id`]}}},{type:`function`,function:{name:`subagent_await`,description:`Wait for a background subagent to finish and return its result.`,parameters:{type:`object`,properties:{id:{type:`string`},timeoutMs:{type:`number`,description:`Default 120000`}},required:[`id`]}}},{type:`function`,function:{name:`subagent_abort`,description:`Abort a running subagent in this chat session.`,parameters:{type:`object`,properties:{id:{type:`string`}},required:[`id`]}}},{type:`function`,function:{name:`subagent_message`,description:`Steer a running subagent by queueing an extra user instruction (applied mid-run when possible).`,parameters:{type:`object`,properties:{id:{type:`string`},message:{type:`string`,description:`Extra instruction for the subagent`}},required:[`id`,`message`]}}}],Sd=2,Cd=6,wd=24,Td=12e3,Ed=new Map,Dd=new Map,Od=new Map,kd=new Map;function Ad(){return`sa_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}function jd(e){let t=String(e??`explore`).trim()||`explore`;return yd.find(e=>e.id===t)??yd[0]}function Md(e){let t=String(e.sessionId??``).trim();if(!t)throw Error(`sessionId is required for subagent tools`);return t}function Nd(e){let t=0;for(let n of Ed.values())n.status===`running`&&(e&&n.sessionId!==e||t++);return t}function Pd(){if(Ed.size<=wd)return;let e=[...Ed.values()].sort((e,t)=>e.updatedAt-t.updatedAt);for(let t of e){if(Ed.size<=wd)break;t.status!==`running`&&(Ed.delete(t.id),Dd.delete(t.id),Od.delete(t.id),kd.delete(t.id))}}function Fd(e){return{id:e.id,sessionId:e.sessionId,agent:e.agent,prompt:e.prompt.slice(0,200),forked:e.forked,status:e.status,createdAt:e.createdAt,updatedAt:e.updatedAt,result:e.result,error:e.error,toolCalls:e.toolCalls}}function Id(e){let t=kd.get(e);return t?.length?(kd.set(e,[]),t):[]}function Ld(e,t){return e.mode===`explore`?`readonly`:t===`full`?`readwrite`:t}async function Rd(e,t,n,r){let i=new AbortController;Dd.set(e.id,i);let a=()=>i.abort();n.parentSignal?.addEventListener(`abort`,a);let o=0;try{if(i.signal.aborted||n.parentSignal?.aborted)throw new DOMException(`Aborted`,`AbortError`);let a=Ld(t,n.access),s=[],c=`你是 Lantern Harness 子代理「${t.id}」(${t.label})。\n任务:独立完成用户交给你的子任务,给出简洁可核对的结论。\n- 不要声称自己是主会话;不要尝试再派生子代理或执行 shell\n- 工具轮次有限,优先检索再结论`;n.fsEnabled&&(s.push(...ln(a)),c+=`\n\n${dn}`),n.webEnabled&&(s.push(...cr),c+=`\n\n${lr}`),s.length||(c+=`
230
+ (当前无 fs/web 工具,仅凭已有上下文回答。)`);let l=[{role:`system`,content:c}];if(r&&n.parentMessages?.length){let e=n.parentMessages.filter(e=>e.role===`user`||e.role===`assistant`).slice(-12).map(e=>({role:e.role,content:typeof e.content==`string`?e.content.slice(0,4e3):JSON.stringify(e.content).slice(0,4e3)}));l.push(...e)}l.push({role:`user`,content:`【子代理任务】\n${e.prompt}`}),n.onHint?.(`子代理 ${e.id}(${t.id})运行中…`);let u=``;for(let t=0;t<3;t++){if(i.signal.aborted||n.parentSignal?.aborted)throw new DOMException(`Aborted`,`AbortError`);let r=Id(e.id),c=[...l];(t>0||r.length)&&c.push({role:`user`,content:[r.length?`【追加指示】\n${r.join(`
231
+ `)}`:``,u.trim()?`【此前进展】\n${u.trim().slice(0,6e3)}`:``,t>0?`请在此前基础上继续完成任务,给出简洁结论。`:``].filter(Boolean).join(`
232
+
233
+ `)});let d=``;for await(let t of zt(n.settings,c,i.signal,{tools:s.length?s:void 0,maxToolRounds:4,thinking:!1,runTool:s.length?async(t,r)=>(o++,n.onHint?.(`子代理 ${e.id}: ${t}`),t.startsWith(`fs_`)?n.runFs(t,r,a):t.startsWith(`web_`)?n.runWeb(t,r):JSON.stringify({error:`subagent cannot use tool: ${t}`})):void 0}))t.type===`content`&&(d+=t.delta);if(d.trim()&&(u=d.trim()),!kd.get(e.id)?.length)break}let d=u.trim().slice(0,Td);e.status=`done`,e.result=d||`(子代理无文本输出)`,e.toolCalls=o,e.updatedAt=Date.now()}catch(t){let r=t instanceof DOMException&&t.name===`AbortError`||i.signal.aborted||!!n.parentSignal?.aborted;e.status=r?`aborted`:`error`,e.error=r?`aborted`:t instanceof Error?t.message:String(t),e.toolCalls=o,e.updatedAt=Date.now()}finally{n.parentSignal?.removeEventListener(`abort`,a),Dd.delete(e.id),kd.delete(e.id),Pd()}}function zd(e,t,n,r,i){if(!e)return{ok:!1,error:`prompt is required`};let a=``;try{a=Md(n)}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}if(Nd(a)>=i)return{ok:!1,error:`too many running subagents (max ${i})`};let o=jd(t),s=Date.now(),c={id:Ad(),sessionId:a,agent:o.id,prompt:e.slice(0,4e3),forked:r,status:`running`,createdAt:s,updatedAt:s};Ed.set(c.id,c);let l=Rd(c,o,n,r).then(()=>c);return Od.set(c.id,l),{ok:!0,rec:c,job:l}}function Bd(e,t,n){let r=zd(String(e.prompt??``).trim(),e.agent,t,n,Sd);return r.ok?e.background===!0?(r.job.finally(()=>{}),JSON.stringify({ok:!0,id:r.rec.id,agent:r.rec.agent,status:`running`,forked:n,hint:`Use subagent_await to get the result`})):r.job.then(e=>JSON.stringify({ok:e.status===`done`,id:e.id,agent:e.agent,status:e.status,forked:e.forked,toolCalls:e.toolCalls??0,result:e.result,error:e.error},null,2)):JSON.stringify({ok:!1,error:r.error})}async function Vd(e,t,n){let r=zd(e.trim(),n?.agent??`explore`,t,!!n?.forked,Cd);if(!r.ok)return{ok:!1,id:``,text:null,error:r.error};let i=await r.job;return i.status===`done`?{ok:!0,id:i.id,text:i.result??null}:{ok:!1,id:i.id,text:null,error:i.error??i.status}}function Hd(e=!0,t){return[...Ed.values()].filter(e=>!t||e.sessionId===t).filter(t=>e||t.status===`running`).sort((e,t)=>t.updatedAt-e.updatedAt).map(Fd)}function Ud(e,t){let n=String(e??``).trim();if(!n)return{ok:!1,error:`id is required`};let r=Ed.get(n);return!r||t&&r.sessionId!==t?{ok:!1,error:`subagent not found`}:r.status===`running`?(Dd.get(n)?.abort(),{ok:!0,record:{...Fd(r),status:`aborted`}}):{ok:!0,record:Fd(r)}}function Wd(e,t,n){let r=String(e??``).trim(),i=String(t??``).trim();if(!r)return{ok:!1,error:`id is required`};if(!i)return{ok:!1,error:`message is required`};let a=Ed.get(r);if(!a||n&&a.sessionId!==n)return{ok:!1,error:`subagent not found`};if(a.status!==`running`)return{ok:!1,error:`subagent is not running`};let o=kd.get(r)??[];return o.push(i.slice(0,4e3)),kd.set(r,o),{ok:!0,queued:o.length}}async function Gd(e,t,n){let r=String(e??``).trim();if(!r)return JSON.stringify({ok:!1,error:`id is required`});let i=typeof t==`number`&&Number.isFinite(t)?Math.min(Math.max(1e3,t),3e5):12e4,a=Ed.get(r);if(!a||n&&a.sessionId!==n)return JSON.stringify({ok:!1,error:`subagent not found`});if(a.status!==`running`)return JSON.stringify({ok:a.status===`done`,...Fd(a)},null,2);let o=Od.get(r);if(!o)return JSON.stringify({ok:!1,error:`subagent waiter missing`});let s=await Promise.race([o,new Promise(e=>{setTimeout(()=>e(null),i)})]);return s?JSON.stringify({ok:s.status===`done`,...Fd(s)},null,2):JSON.stringify({ok:!1,id:r,status:`running`,error:`timeout after ${i}ms`})}async function Kd(e,t,n){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}let i=``;try{i=Md(n)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}if(e===`list_agents`){let e=r.includeRecent!==!1;return JSON.stringify({ok:!0,presets:yd,agents:Hd(e,i),running:Nd(i),maxConcurrent:Sd,sessionId:i},null,2)}if(e===`subagent_list`)return JSON.stringify({ok:!0,agents:Hd(r.includeDone!==!1,i),running:Nd(i),sessionId:i},null,2);if(e===`subagent_status`){let e=String(r.id??``).trim();if(!e)return JSON.stringify({ok:!1,error:`id is required`});let t=Ed.get(e);return!t||t.sessionId!==i?JSON.stringify({ok:!1,error:`subagent not found`}):JSON.stringify({ok:!0,...Fd(t)},null,2)}return e===`subagent_abort`?JSON.stringify(Ud(r.id,i),null,2):e===`subagent_message`?JSON.stringify(Wd(r.id,r.message,i),null,2):e===`subagent_await`?await Gd(r.id,r.timeoutMs,i):e===`spawn_subagent`?await Promise.resolve(Bd(r,n,!1)):e===`fork_subagent`?await Promise.resolve(Bd(r,n,!0)):JSON.stringify({error:`unknown tool: ${e}`})}var qd=4e4,Jd=5e4,Yd=12,Xd=4,Zd=80,Qd=`你可以使用 workflow 工具(仅当用户明确要求工作流 / 大规模多代理编排时):
234
+ - 参数:meta{name,description,phases?}、script(纯 JS 函数体,可用 top-level await)、args?
235
+ - 脚本内钩子:agent(prompt, opts?)、parallel(fns)、pipeline(fns)、phase(name)、log(...)
236
+ - agent() 返回子代理结论文本,失败返回 null
237
+ - 一两个子任务请用 spawn_subagent / fork_subagent,勿滥用 workflow`,$d=[{type:`function`,function:{name:`workflow`,description:`Run a JavaScript orchestration script that fans out subagents and returns a JSON value. Use ONLY when the user explicitly asks for a workflow or large multi-agent orchestration. Script body may use top-level await and helpers: agent, parallel, pipeline, phase, log. Example body: const xs = await parallel([() => agent("task A"), () => agent("task B")]); return xs.filter(Boolean);`,parameters:{type:`object`,properties:{meta:{type:`object`,description:`Workflow identity`,properties:{name:{type:`string`},description:{type:`string`},phases:{type:`array`,items:{type:`string`}}},required:[`name`,`description`]},script:{type:`string`,description:`Plain JavaScript body (no export). Globals: args, agent, parallel, pipeline, phase, log.`},args:{type:`object`,description:`JSON object exposed to the script as args (wrap arrays in a field)`}},required:[`meta`,`script`]}}}];function ef(){return`wf_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}function tf(e){if(!e||typeof e!=`object`)return{error:`meta is required`};let t=e,n=String(t.name??``).trim(),r=String(t.description??``).trim();if(!n)return{error:`meta.name is required`};if(!r)return{error:`meta.description is required`};let i=Array.isArray(t.phases)?t.phases.map(e=>String(e).trim()).filter(Boolean).slice(0,20):void 0;return{name:n.slice(0,80),description:r.slice(0,400),phases:i}}function nf(e){return/\brequire\b|\bprocess\.|\bchild_process\b|\bfs\.|\bglobalThis\b|\bFunction\s*\(|\beval\s*\(|\bimport\s*\(|\bXMLHttpRequest\b|\blocalStorage\b|\bindexedDB\b|\bdocument\.|\bwindow\./.test(e)?`script uses disallowed APIs (browser/Node escape)`:null}async function rf(e,t,n,r){let i=Array(e.length),a=0;async function o(){for(;a<e.length;){if(r?.aborted)throw new DOMException(`Aborted`,`AbortError`);let t=a++;i[t]=await n(e[t],t)}}let s=Math.min(Math.max(1,t),e.length||1);return await Promise.all(Array.from({length:s},()=>o())),i}async function af(e,t,n,r){let i=ef(),a=[],o=[],s=0,c=Yd,l=(...t)=>{let n=t.map(e=>{if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}).join(` `);a.push(n.slice(0,500)),a.length>Zd&&a.splice(0,a.length-Zd),r.onHint?.(`workflow ${e.name}: ${n.slice(0,80)}`)},u=async(e,t)=>{if(r.parentSignal?.aborted)throw new DOMException(`Aborted`,`AbortError`);let n=String(e??``).trim();if(!n)return null;if(c<=0)return l(`agent budget exhausted`),null;c--,s++;let i=t?.label?` [${t.label}]`:``;l(`agent${i}: ${n.slice(0,120)}`);let a=await Vd(n,r,{agent:t?.agent??`explore`,forked:!1});return a.ok?a.text:(l(`agent failed${i}: ${a.error??`error`}`),null)},d=async(e,t=Xd)=>{if(!Array.isArray(e))throw Error(`parallel() expects an array of functions`);return rf(e.slice(0,Yd),Math.min(Xd,t||Xd),async e=>{if(typeof e!=`function`)return null;try{return await e()}catch(e){return l(`parallel task error`,e instanceof Error?e.message:String(e)),null}},r.parentSignal)},f=async e=>{if(!Array.isArray(e))throw Error(`pipeline() expects an array of functions`);let t=[];for(let n of e.slice(0,Yd)){if(r.parentSignal?.aborted)throw new DOMException(`Aborted`,`AbortError`);if(typeof n!=`function`)t.push(null);else try{t.push(await n())}catch(e){l(`pipeline task error`,e instanceof Error?e.message:String(e)),t.push(null)}}return t},p=t=>{let n=String(t??``).trim()||`phase`;o.push(n.slice(0,80)),l(`phase: ${n}`),r.onHint?.(`workflow ${e.name} · ${n}`)},m=(...e)=>l(...e),h=nf(t);if(h)return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:0,stopReason:`error`,error:h};if(t.length>qd)return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:0,stopReason:`error`,error:`script too long (max ${qd})`};try{let c=Object.getPrototypeOf(async function(){}).constructor,l=await new c(`args`,`agent`,`parallel`,`pipeline`,`phase`,`log`,`"use strict";\n${t}`)(n,u,d,f,p,m);if(r.parentSignal?.aborted)return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:s,stopReason:`cancelled`,error:`workflow run was cancelled`,logs:a,phases:o};let h=l===void 0?null:l;try{let e=JSON.stringify(h);h=e&&e.length>Jd?{truncated:!0,preview:e.slice(0,Jd)}:e===void 0?null:JSON.parse(e)}catch{h=String(h).slice(0,Jd)}return{ok:!0,kind:`foreground`,runId:i,name:e.name,agentsStarted:s,result:h,stopReason:`completed`,logs:a,phases:o}}catch(t){let n=t instanceof DOMException&&t.name===`AbortError`||!!r.parentSignal?.aborted;return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:s,stopReason:n?`cancelled`:`error`,error:n?`workflow run was cancelled`:t instanceof Error?t.message:String(t),logs:a,phases:o}}}async function of(e,t,n){if(e!==`workflow`)return JSON.stringify({error:`unknown tool: ${e}`});let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}let i=tf(r.meta);if(`error`in i)return JSON.stringify({ok:!1,error:i.error});let a=String(r.script??``);if(!a.trim())return JSON.stringify({ok:!1,error:`script is required`});let o=r.args&&typeof r.args==`object`&&!Array.isArray(r.args)?r.args:{};n.onHint?.(`workflow "${i.name}" 启动…`);let s=await af(i,a,o,n);return s.ok?[`workflow "${s.name}" completed (${s.agentsStarted} agent${s.agentsStarted===1?``:`s`}).`,`Return value:`,JSON.stringify(s.result,null,2)].join(`
238
+ `):s.stopReason===`cancelled`?`Error: workflow run was cancelled${s.error&&s.error!==`workflow run was cancelled`?` (${s.error})`:``}`:`Error: workflow run failed: ${s.error??`unknown`}`}function sf(e){return e===`md`?`Markdown`:e===`xlsx`||e===`xls`?`Excel`:e===`docx`||e===`doc`?`Word`:e===`dir`?`文件夹`:e===`file`?`文件`:e.toUpperCase()}function cf(e,t){return!(t&&![e.title,e.category,e.id,e.description,e.path,e.format,sf(e.format)].join(`
239
+ `).toLowerCase().includes(t)&&(t!==`excel`&&t!==`表格`&&t!==`xls`||e.format!==`xlsx`&&e.format!==`xls`)&&(t!==`word`&&t!==`文档`&&t!==`doc`||e.format!==`docx`&&e.format!==`doc`)&&(t!==`md`&&t!==`markdown`&&t!==`标记`||e.format!==`md`))}var lf=`用户可能通过「@」引用了知识库与模板下的 Markdown / Excel / Word 等文档(消息中会列出路径)。仅当用户引用了文档,或问题明显依赖知识库/模板时,再调用 kb_read / kb_search;一般闲聊或无关问题不要为了凑答去检索。读取时:Markdown 为全文,Excel/Word 为字段或元数据摘要;不要臆造未读到的正文。`,uf=[{type:`function`,function:{name:`kb_search`,description:`在知识库与模板(含 Markdown、Excel、Word)中按关键词搜索,返回 path、标题、格式与摘要。`,parameters:{type:`object`,properties:{query:{type:`string`,description:`搜索关键词,如 接口、excel、用例`},scope:{type:`string`,enum:[`all`,`knowledge`,`templates`],description:`限定范围,默认 all`}},required:[`query`]}}},{type:`function`,function:{name:`kb_read`,description:`按 path 读取文档。Markdown 返回全文;Excel/Word 返回构建期摘要。path 如 测试模板库/接口测试用例/接口测试用例模版.xlsx 或 知识库管理/xxx.md`,parameters:{type:`object`,properties:{path:{type:`string`,description:`相对路径(与引用列表中的 path 一致)`}},required:[`path`]}}}];function df(e){return e.trim().replace(/^\/+/,``).replace(/\\/g,`/`)}function ff(e,t){let n=df(t),r=n.replace(/\.md$/i,``);return e.find(e=>{let t=df(e.path);return t===n||t===`${r}.md`||`${e.collection}/${e.id}`===n||`${e.collection}/${e.id}.md`===n||e.id===n||e.id===r})}async function pf(e,t,n){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}let i=typeof n.base==`string`&&n.base?n.base:`/`,a=i.endsWith(`/`)?i:`${i}/`;try{switch(e){case`kb_search`:{let e=String(r.query??``).trim().toLowerCase(),t=String(r.scope??`all`);if(!e)return JSON.stringify({error:`query required`,results:[]});let i=n.docs.filter(e=>t===`all`||e.collection===t).filter(t=>cf(t,e)).slice(0,12).map(e=>({path:e.path,title:e.title,category:e.category,collection:e.collection,format:e.format,snippet:e.description||e.category}));return JSON.stringify({results:i,count:i.length})}case`kb_read`:{let e=ff(n.docs,String(r.path??``));if(!e)return JSON.stringify({error:`未找到文档;请使用 kb_search 返回的 path`,path:String(r.path??``)});if(e.attachText)return JSON.stringify({path:e.path,title:e.title,category:e.category,format:e.format,content:e.attachText,note:`Office 模板返回构建期摘要,非完整二进制内容`});let t=`${a}raw/${e.collection}/${e.id}.md`,i=await fetch(t);if(!i.ok)return JSON.stringify({error:`读取失败 HTTP ${i.status}`,path:e.path});let o=await i.text();return JSON.stringify({path:e.path,title:e.title,category:e.category,format:e.format,content:o})}default:return JSON.stringify({error:`unknown tool: ${e}`})}}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var mf=e=>e;function hf(e){if(e.structuredPlugin)return[];let t=e.caps,n=e.access,r=!!e.planGatesWrites,i=e.planPhase??`off`,a=[];return t.knowledge&&a.push(...mf(uf)),t.fs&&(a.push(...mf(ln(n))),a.push(...mf(cn)),a.push(...mf(Qc)),a.push(...mf(eu)),a.push(Pi),r||(a.push(Ai),a.push(mn))),t.bash&&n!==`readonly`&&(a.push(gr),a.push(...mf(vr))),t.pwsh&&n!==`readonly`&&(a.push(_r),a.push(...mf(ir))),(t.bash||t.pwsh)&&n!==`readonly`&&a.push(...mf(ur)),t.web&&a.push(...mf(cr)),t.memory&&a.push(...mf(Fr)),t.interact!==!1&&a.push(du),t.todos&&a.push(...mf(El)),t.tasks&&a.push(...mf(Gl)),t.projects&&a.push(...mf(ol)),t.iterations&&a.push(...mf(sl)),t.pmRequirements&&a.push(...mf(cl)),t.bugs&&a.push(...mf(ll)),t.interact!==!1&&a.push(fu),t.goal!==!1&&a.push(...mf(Fu)),t.schedule!==!1&&a.push(...mf(nd)),t.subagent!==!1&&a.push(...mf(xd)),t.workflow!==!1&&a.push(...mf($d)),t.mcp!==!1&&e.mcpTools?.length&&a.push(...e.mcpTools),(i===`planning`||i===`approved`)&&a.push(bu),a}function gf(e){return!(e&&e!==`ask_user_question`&&e!==`submit_plan`&&e!==`workflow`&&e!==`spawn_subagent`&&e!==`fork_subagent`&&e!==`list_agents`&&!e.startsWith(`subagent_`))}function _f(e){return e.filter(e=>{let t=e.function?.name??``;return!!t&&!gf(t)})}function vf(e){let t=String(e||``);return t===`bash`||t===`pwsh`||t.endsWith(`_session_exec`)?12e4:t.startsWith(`bash_session_`)||t.startsWith(`pwsh_session_`)?3e4:t===`web_fetch`?35e3:t===`web_search`?3e4:t.startsWith(`mcp__`)?6e4:t.startsWith(`fs_`)||t.startsWith(`kb_`)||t.startsWith(`memory_`)?3e4:t.startsWith(`subagent_`)||t===`spawn_subagent`||t===`fork_subagent`?3e5:6e4}async function yf(e,t,n=`tool`){let r=Math.max(1e3,Math.min(6e5,Number(t)||6e4)),i;try{return await Promise.race([e,new Promise((e,t)=>{i=setTimeout(()=>{t(Error(`${n} timed out after ${r}ms`))},r)})])}finally{i&&clearTimeout(i)}}function bf(e){return async(t,n)=>{try{return await yf(e(t,n),vf(t),t||`tool`)}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}}var xf=/^\d{4}-\d{2}-\d{2}$/;function Sf(e){return String(e).padStart(2,`0`)}function Cf(e,t,n){return`${e}-${Sf(t+1)}-${Sf(n)}`}function wf(e){return e.replace(/-/g,`.`)}function Tf(e,t=new Date,n){let r=t.getFullYear(),i=t.getMonth(),a=t.getDate();if(e===`day`){let e=Cf(r,i,a);return{from:e,to:e,label:`日报(${wf(e)})`}}if(e===`month`){let e=new Date(r,i+1,0).getDate();return{from:Cf(r,i,1),to:Cf(r,i,e),label:`月报(${r}.${Sf(i+1)})`}}let o=t.getDay(),s=o===0?-6:1-o,c=n?.weekOffset??0,l=new Date(r,i,a+s+c*7),u=new Date(l.getFullYear(),l.getMonth(),l.getDate()+6),d=Cf(l.getFullYear(),l.getMonth(),l.getDate()),f=Cf(u.getFullYear(),u.getMonth(),u.getDate());return{from:d,to:f,label:`周报(${wf(d)}-${wf(f)})`}}function Ef(e){let t=e.trim();return/上一周|上周/.test(t)}function Df(e,t,n){return xf.test(e)?e>=t&&e<=n:!1}function Of(e,t,n,r){let i=xf.test(e)?e:xf.test(t)?t:``,a=xf.test(t)?t:xf.test(e)?e:``;return!i||!a?!1:(i<=a?i:a)<=r&&(i<=a?a:i)>=n}function kf(e,t,n){return e.filter(e=>e.startDate||e.dueDate?Of(e.startDate,e.dueDate,t,n):Df((e.createdAt||``).slice(0,10),t,n))}function Af(e,t,n){return e.filter(e=>e.startDate||e.dueDate?Of(e.startDate,e.dueDate,t,n):Df((e.createdAt||``).slice(0,10),t,n))}function jf(e,t,n){return e.filter(e=>!e.draft&&Df(e.date,t,n))}function Mf(e,t,n){return e.filter(e=>e.draft?!1:Df(e.date,t,n)?!0:Of(e.startDate||e.date,e.endDate||e.date,t,n))}function Nf(e){if(!e.length)return[`### 待办事项`,``,`本期无相关记录。`,``];let t=[`### 待办事项`,``];for(let n of e){let e=[Vn[n.status]||n.status,n.linkedTask?`任务:${n.linkedTask}`:``,n.startDate||n.dueDate?`${n.startDate||`—`} ~ ${n.dueDate||`—`}`:``].filter(Boolean);t.push(`- ${n.title||`(无标题)`}(${e.join(` · `)})`),n.note.trim()&&t.push(` 备注:${n.note.trim()}`)}return t.push(``),t}function Pf(e){if(!e.length)return[`### 任务管理`,``,`本期无相关记录。`,``];let t=[`### 任务管理`,``];for(let n of e){let e=[Gn[n.status]||n.status,n.startDate||n.dueDate?`${n.startDate||`—`} ~ ${n.dueDate||`—`}`:``].filter(Boolean);t.push(`- ${n.title||`(无标题)`}(${e.join(` · `)})`),n.note.trim()&&t.push(` 备注:${n.note.trim()}`)}return t.push(``),t}function Ff(e){if(!e.length)return[`### 测试统计`,``,`本期无相关记录。`,``];let t=[`### 测试统计`,``],n=[...e].sort((e,t)=>t.date.localeCompare(e.date)||t.createdAt.localeCompare(e.createdAt));for(let e of n){let n=e.dimensions[0]||`(未选维度)`;t.push(`- ${e.date} · ${n}:${e.count}`)}return t.push(``),t}function If(e,t){if(!e.length)return[`### 用例执行统计`,``,`本期无相关记录。`,``];let n=[`### 用例执行统计`,``],r=Oe(t?.length?t:e),i=new Map;for(let t of e){let e=t.project.trim()||`(无项目:${t.id})`,n=i.get(e);n?n.push(t):i.set(e,[t])}let a=[...i.entries()].sort((e,t)=>{let n=Ce(e[1])[0]?.date??``;return(Ce(t[1])[0]?.date??``).localeCompare(n)});for(let[e,t]of a){let e=Ce(t),i=e[0]?.project.trim()??``,a=i||`(无项目)`,o=i?r.get(i)??0:0,s=e.find(e=>e.total>0)??e[0],c=s?Ee(s,o||void 0):0,l=s?we(s,o||void 0).toFixed(2):`0.00`,u=e.find(e=>e.startDate||e.endDate)??e[0],d=u?.startDate||u?.endDate?`(周期 ${u?.startDate||`—`} ~ ${u?.endDate||`—`})`:``,f=o>0?String(o):`—`;n.push(`- **${a}**${d}:基线 ${f} · 已执行 ${c} / ${f}(${l}%)`);for(let t of e){let e=R(t),r=De(t),i=Ee(t,o||void 0),a=we(t,o||void 0).toFixed(2),s=o>0?o:t.total||`—`;n.push(` - ${t.date}:本轮总数 ${t.total} · 待执行 ${t.pending} · 本轮已执行 ${r} · 剩余 ${e} · 累计已执行 ${i} / ${s}(${a}%)`)}}return n.push(``),n}function Lf(e){let{period:t,include:n}=e,r=[`## 本期工作数据`,``,`区间:${t.from} ~ ${t.to}(${t.label})`,``,`以下由插件按区间带入,请据此整理汇报;不要编造未出现的数字或事项。`,``];return n.todos&&r.push(...Nf(e.todos??[])),n.tasks&&r.push(...Pf(e.tasks??[])),n.testStats&&r.push(...Ff(e.testStats??[])),n.caseExec&&r.push(...If(e.caseExec??[],e.caseExecAll)),!n.todos&&!n.tasks&&!n.testStats&&!n.caseExec?``:r.join(`
240
+ `).trimEnd()+`
241
+ `}async function Rf(e,t,n=new Date,r){let i=Tf(e,n,{weekOffset:r?.weekOffset}),a={todos:!!t.todos,tasks:!!t.tasks,testStats:!!t.testStats,caseExec:!!t.caseExec};if(!a.todos&&!a.tasks&&!a.testStats&&!a.caseExec)return``;let[o,s,c,l]=await Promise.all([a.todos?Fn().then(e=>kf(e,i.from,i.to)).catch(()=>[]):Promise.resolve(void 0),a.tasks?$n().then(e=>Af(e,i.from,i.to)).catch(()=>[]):Promise.resolve(void 0),a.testStats?Yr().then(e=>jf(e.items,i.from,i.to)).catch(()=>[]):Promise.resolve(void 0),a.caseExec?Te().then(e=>({periodItems:Mf(e.items,i.from,i.to),all:e.items.filter(e=>!e.draft)})).catch(()=>({periodItems:[],all:[]})):Promise.resolve(void 0)]);return Lf({period:i,todos:o,tasks:s,testStats:c,caseExec:l?.periodItems,caseExecAll:l?.all,include:a})}function zf(e){let t=e.trim();return t.startsWith(`生成日报`)||/^生成.*日报/.test(t)?`day`:t.startsWith(`生成周报`)||/^生成.*(上周|上一周)?周报/.test(t)?`week`:t.startsWith(`生成月报`)||/^生成.*月报/.test(t)?`month`:null}var Bf=10485760,Vf=new Set([`png`,`jpg`,`jpeg`,`webp`,`gif`]),Hf=new Set([`xlsx`,`xls`,`xlsm`,`xlsb`,`ods`]),Uf=new Set([`docx`]),Wf=new Set(`md.markdown.txt.text.json.csv.tsv.yaml.yml.xml.html.htm.log.sql.feature.toml.ini.conf.properties.rst.css.js.ts.tsx.jsx.py.java.go.rs.sh.bash.zsh.env.gitignore.dockerfile.makefile.svg`.split(`.`)),Gf=[...Wf,...Vf,...Hf,...Uf,`doc`,`pdf`];function Kf(e){let t=e.lastIndexOf(`.`);return t>=0?e.slice(t+1).toLowerCase():``}async function qf(e){let t=await e.arrayBuffer(),n=bt(t,{type:`array`}),r=[`# ${e.name}`,`工作表数:${n.SheetNames.length}`,``];for(let e of n.SheetNames){let t=n.Sheets[e];if(!t)continue;let i=xt.sheet_to_csv(t);r.push(`## ${e}`,i.trim()||`(空表)`,``)}return r.join(`
242
+ `).trim()}async function Jf(t){let n=await y(()=>import(`./lib.S37S0T6S.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1,2])),r=await t.arrayBuffer(),i=await n.extractRawText({arrayBuffer:r}),a=(i.value??``).trim(),o=[`# ${t.name}`,``];return i.messages?.length&&o.push(`(解析备注:${i.messages.slice(0,3).map(e=>e.message).join(`;`)})`,``),o.push(a||`(未提取到正文)`),o.join(`
243
+ `)}async function Yf(e){let t;try{t=await fetch(`/__tb_attach/text?name=${encodeURIComponent(e.name)}`,{method:`POST`,headers:{"Content-Type":`application/octet-stream`},body:await e.arrayBuffer()})}catch{throw Error(`${e.name}:解析 .doc 需要本地服务(lantern web / pnpm dev)`)}let n={};try{n=await t.json()}catch{throw Error(`${e.name}:本地服务返回异常`)}if(!t.ok||!n.ok||!n.content)throw Error(n.error||`${e.name}:无法解析 .doc`);return n.content}async function Xf(e){let t=Kf(e.name);if(!t)throw Error(`${e.name}:无法识别扩展名`);if(e.size>10485760)throw Error(`${e.name}:超过 ${Math.round(Bf/1024/1024)} MB`);if(Vf.has(t)||e.type.startsWith(`image/`))return{kind:`image`,file:e};if(Hf.has(t))return{kind:`text`,name:e.name,size:e.size,content:await qf(e)};if(Uf.has(t))return{kind:`text`,name:e.name,size:e.size,content:await Jf(e)};if(t===`doc`){let t=await Yf(e);return{kind:`text`,name:e.name,size:e.size,content:t}}if(t===`pdf`)throw Error(`${e.name}:PDF 暂不解析正文,请转 Markdown/图片后添加`);if(Wf.has(t)||e.type.startsWith(`text/`)||e.type===`application/json`)return{kind:`text`,name:e.name,size:e.size,content:await e.text()};throw Error(`${e.name}:暂不支持的类型 .${t}`)}var Zf=[{prefix:`知识库管理`,aliases:[`knowledge`],collection:`knowledge`,category:`知识库`},{prefix:`用例管理`,aliases:[`cases`],collection:`cases`,category:`用例`},{prefix:`测试模板库`,aliases:[`templates`],collection:`templates`,category:`模板`}];function Qf(e){return e.replace(/\\/g,`/`).replace(/\/+/g,`/`)}function $f(e){let t=Qf(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t}function ep(e){let t=e.lastIndexOf(`.`);return t>=0?e.slice(t+1).toLowerCase():`file`}function tp(e){let t=e.trim();if(!/^file:/i.test(t))return null;try{let e=new URL(t),n=decodeURIComponent(e.pathname||``);return/^\/[A-Za-z]:\//.test(n)&&(n=n.slice(1)),Qf(n)}catch{return null}}function np(e){let t=Qf(e);return t.startsWith(`/`)||/^[A-Za-z]:\//.test(t)}function rp(e){let t=e.trim();return!t||t.includes(`
244
+ `)||/\s/.test(t)||t.includes(`://`)||t.includes(`/`)||t.includes(`\\`)?!1:/\.[A-Za-z0-9]{1,16}$/.test(t)}function ip(e){let t=e.trim();return!t||t.includes(`
245
+ `)?!1:!!(/^file:/i.test(t)||np(t)||(t.includes(`/`)||t.includes(`\\`))&&!/\s/.test(t)&&t.length<512)}function ap(e){let t=[],n=e.getData(`text/uri-list`)||``;for(let e of n.split(/\r?\n/)){let n=e.trim();if(!n||n.startsWith(`#`))continue;let r=tp(n);r?t.push(r):np(n)&&t.push(Qf(n))}let r=(e.getData(`text/plain`)||``).trim();if(r&&!r.includes(`
246
+ `)){let e=tp(r);e?t.push(e):ip(r)&&!rp(r)&&t.push(Qf(r))}return[...new Set(t)]}function op(e){return{collection:e.collection,id:`${e.collection}:${e.path}`,title:e.title||$f(e.path),category:e.category,path:e.path,format:e.format||ep(e.path)}}function sp(e,t){let n=Qf(e),r=Qf(t).replace(/\/$/,``);return n===r?``:n.startsWith(`${r}/`)?n.slice(r.length+1):null}function cp(e,t){let n=Qf(e.trim()),r=tp(n);r&&(n=r);let i=t.projectRoot?Qf(t.projectRoot):``,a=t.workspace?Qf(t.workspace):``,o=n;if(i){let e=sp(n,i);e!=null&&(o=e)}for(let{prefix:e,aliases:t,collection:n,category:r}of Zf)for(let i of[e,...t??[]])if(o!==i&&o.startsWith(`${i}/`)){let e=o.slice(i.length+1);if(!e)continue;return op({collection:n,path:e,title:$f(e),category:r,format:ep(e)})}if(a){let e=sp(n,a);if(e!=null&&e!==``)return op({collection:`workspace`,path:e,title:$f(e),category:t.workspaceLabel||`工作区`,format:ep(e)})}if(!np(o)&&o.includes(`/`)){let e=o.split(`/`)[0]||``,n=Zf.find(t=>t.prefix===e||t.aliases?.includes(e));if(n){let t=o.slice(e.length+1);if(t)return op({collection:n.collection,path:t,title:$f(t),category:n.category,format:ep(t)})}return op({collection:`workspace`,path:o,title:$f(o),category:t.workspaceLabel||`工作区`,format:ep(o)})}return null}function lp(e,t){let n=e.trim();if(!n)return null;let r=n.toLowerCase(),i=t.filter(e=>{let t=$f(e.path).toLowerCase(),n=(e.title||``).toLowerCase();return t===r||n===r||e.path.toLowerCase()===r});return i.length===1?op(i[0]):null}function up({mode:e,entityLabel:t,currentLabel:n,placeholder:s,hint:c,deleteMessage:l,deleteNote:u,error:d=``,onClose:f,onSubmit:p,onDelete:m}){let[h,g]=(0,U.useState)(``),_=(0,U.useRef)(null);if((0,U.useEffect)(()=>{if(e!==`add`&&e!==`edit`)return;g(e===`edit`?n:``);let t=window.setTimeout(()=>{_.current?.focus(),_.current?.select()},50);return()=>window.clearTimeout(t)},[e,n]),typeof document>`u`)return null;let v=h.trim(),ee=(0,Z.jsxs)(a,{open:e!==null,onClose:f,className:`relative z-110`,children:[(0,Z.jsx)(o,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,Z.jsxs)(r,{transition:!0,className:`tw-confirm-dialog tw-dialog-panel-anim relative w-full max-w-sm rounded-xl border border-stone-200 bg-white p-5 shadow-xl`,children:[(0,Z.jsx)(i,{className:`tw-confirm-title pr-8 text-base font-semibold text-stone-900`,children:e===`delete`?`删除${t}`:e===`edit`?`编辑${t}`:`新增${t}`}),e===`delete`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`tw-confirm-msg mt-3 text-sm leading-relaxed text-stone-600`,children:l?l(n):`确定删除「${n}」?删除后该项将不再出现在配置里,已生成的内容不受影响。`}),u?(0,Z.jsx)(`p`,{className:`mt-2 rounded-lg bg-stone-50 px-3 py-2 text-[11px] leading-4 text-stone-500`,children:u}):null]}):(0,Z.jsxs)(`label`,{className:`tw-confirm-msg mt-4 block text-xs font-medium text-stone-500`,children:[`名称`,(0,Z.jsx)(`input`,{ref:_,value:h,maxLength:40,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),v&&p(v))},placeholder:s,className:`mt-1.5 h-9 w-full rounded-lg border border-stone-200 bg-white px-3 text-sm text-stone-800 outline-none transition-colors focus:border-[#4176e6] focus:ring-2 focus:ring-[#4176e6]/30`})]}),d?(0,Z.jsx)(`p`,{className:`mt-2 text-[11px] font-normal leading-relaxed text-red-600`,role:`alert`,children:d}):null,e===`delete`||!c?null:(0,Z.jsx)(`p`,{className:`mt-2 text-[11px] leading-4 text-stone-400`,children:c(v)}),(0,Z.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:f,className:`tw-confirm-cancel h-8 rounded-lg px-3 text-sm text-stone-600 transition-colors hover:bg-stone-100`,children:`取消`}),e===`delete`?(0,Z.jsx)(`button`,{type:`button`,onClick:m,className:`h-8 rounded-lg bg-red-600 px-4 text-sm font-medium text-white transition-colors hover:bg-red-700`,children:`删除`}):(0,Z.jsx)(`button`,{type:`button`,disabled:!v,onClick:()=>p(v),className:`h-8 rounded-lg bg-[#4176e6] px-4 text-sm font-medium text-white transition-colors hover:bg-[#3565c7] disabled:opacity-40`,children:e===`edit`?`保存`:`新增`})]})]})})]});return(0,$r.createPortal)(ee,document.body)}function dp({mode:e,currentLabel:t,templateFolder:n,error:r=``,onClose:i,onSubmit:a,onDelete:o}){return(0,Z.jsx)(up,{mode:e,entityLabel:`用例类型`,currentLabel:t,placeholder:`如:安全测试`,error:r,onClose:i,onSubmit:a,onDelete:o,deleteMessage:e=>(0,Z.jsxs)(Z.Fragment,{children:[`确定删除「`,e,`」?已有用例与模板不会被删除,但该类型将不再出现在生成配置里。`]}),deleteNote:(0,Z.jsxs)(Z.Fragment,{children:[`关联模板目录:测试模板库/`,n,`/`]}),hint:e=>(0,Z.jsxs)(Z.Fragment,{children:[`模板目录随名称生成:测试模板库/`,e||`名称`,`用例/`]})})}var fp=[{value:`md`,label:`Markdown 表格`},{value:`xlsx`,label:`Excel`},{value:`csv`,label:`CSV`}];async function pp(e,t){let n=t.find(t=>t.id===e)?.templateFolder??ft(e).templateFolder;try{let{entries:e}=await St(`templates`,n),t=e.filter(e=>e.type===`file`).sort((e,t)=>(t.mtime??0)-(e.mtime??0)),r=[];for(let e of t){let t=e.name.toLowerCase(),n=[...yt],i=``;try{if(t.endsWith(`.xlsx`)||t.endsWith(`.xls`)){let t=await Ct(`templates`,e.path);if(t.encoding===`base64`&&t.contentBase64){let e=Ot(t.contentBase64);n=e.headers,i=e.body}}else if(t.endsWith(`.csv`)){let t=await wt(`templates`,e.path),r=kt(t.content);n=r.headers,i=r.body}else if(t.endsWith(`.md`)||t.endsWith(`.txt`)){let t=await wt(`templates`,e.path),r=At(t.content);n=r.headers,i=r.body}}catch{i=``}r.push({id:e.path,title:e.name.replace(/\.[^.]+$/,``),body:i,headers:n})}return r}catch{return[]}}async function mp(t){let n=t.toLowerCase();if(n.endsWith(`.md`)||n.endsWith(`.txt`)||n.endsWith(`.csv`))return(await wt(`requirements`,t)).content;if(n.endsWith(`.xlsx`)||n.endsWith(`.xls`)){let e=await Ct(`requirements`,t);if(e.encoding!==`base64`||!e.contentBase64)throw Error(`无法读取 Excel`);let n=await y(()=>import(`./case-fields.CmePqYfh.js`).then(e=>e.d),__vite__mapDeps([3,1])),r=n.read(e.contentBase64,{type:`base64`,cellDates:!0}),i=[];for(let e of r.SheetNames){let t=r.Sheets[e];if(!t)continue;let a=n.utils.sheet_to_csv(t,{blankrows:!1}).trim();a&&i.push(`## 工作表:${e}\n${a}`)}return i.join(`
247
+
248
+ `).trim()}if(n.endsWith(`.docx`)){let n=await Ct(`requirements`,t);if(n.encoding!==`base64`||!n.contentBase64)throw Error(`无法读取 docx`);let r=atob(n.contentBase64),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return((await(await y(()=>import(`./lib.S37S0T6S.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1,2]))).extractRawText({arrayBuffer:i.buffer})).value??``).trim()}return``}function hp({open:e,onClose:t,initial:n,presetStories:r,onConfirm:i}){let[a,o]=(0,U.useState)(!1),[s,c]=(0,U.useState)([]),[l,u]=(0,U.useState)(n?.reqPath??``),[f,m]=(0,U.useState)(n?.reqSource?.kind===`stories`?`stories`:`doc`),[h,g]=(0,U.useState)([]),[_,v]=(0,U.useState)(!1),[ee,y]=(0,U.useState)(n?.reqSource?.kind===`stories`?n.reqSource.docId:``),[te,b]=(0,U.useState)(n?.reqSource?.kind===`stories`?n.reqSource.storyIds:[]),[x,S]=(0,U.useState)(()=>lt()),[C,w]=(0,U.useState)(n?.caseType??lt()[0]?.id??`functional`),[T,E]=(0,U.useState)([]),[D,ne]=(0,U.useState)(n?.templateId??``),[ie,ae]=(0,U.useState)(!1),[oe,k]=(0,U.useState)(``),[se,ce]=(0,U.useState)(n?.promptBody??``),[le,ue]=(0,U.useState)([]),[A,j]=(0,U.useState)(n?.knowledgePaths??[]),[M,de]=(0,U.useState)(n?.testPointIds??[]),[N,fe]=(0,U.useState)(n?.outputFormat??`xlsx`),[pe,me]=(0,U.useState)(null),[he,ge]=(0,U.useState)(!1),[_e,P]=(0,U.useState)(null),[ve,F]=(0,U.useState)(null),[ye,be]=(0,U.useState)(()=>O(`knowledgeLib`)),[Ce,we]=(0,U.useState)(()=>O(`requirements`)),[Te,R]=(0,U.useState)(()=>O(`templates`)),[Ee,De]=(0,U.useState)(()=>O(`reqAnalysis`)),[Oe,ke]=(0,U.useState)(()=>O(`businessMap`)),[Ae,je]=(0,U.useState)(()=>O(`reqBreakdowns`)),[Me,Ne]=(0,U.useState)([]),[Pe,Fe]=(0,U.useState)([]),[Ie,Le]=(0,U.useState)(n?.businessContext?.systemId??``),[Re,ze]=(0,U.useState)(n?.requirementBreakdownContext?.entryId??``),[Be,Ve]=(0,U.useState)(``),He=(0,U.useMemo)(()=>T.find(e=>e.id===D)??T[0],[T,D]),Ue=x.find(e=>e.id===C)??x[0]??ft(C),We=Ue.label;(0,U.useEffect)(()=>{if(!e)return;let t=!0;return ae(!1),Gt().then(()=>Wt(C,Ue.label)).then(({skill:e,content:n})=>{t&&(k(e.legacyPath),ce(n),n.trim()||me(`技能「${e.name}」正文为空,请先到技能页补全`))}).catch(e=>{t&&(k(``),ce(``),me(e instanceof Error?e.message:String(e)))}).finally(()=>{t&&ae(!0)}),()=>{t=!1}},[e,C,Ue.label]);function Ge(e){let t=lt();S(t),w(n=>{let r=e??n;return t.some(e=>e.id===r)?r:t[0]?.id??n})}function Ke(e){try{_e===`add`?(Ge(pt(e).id),Se(`已新增用例类型「${e}」`,`success`)):_e===`edit`&&(vt(C,e),Ge(C),Se(`已重命名为「${e}」`,`success`)),P(null),F(null)}catch(e){let t=e instanceof Error?e.message:String(e);F(t),Se(`${_e===`add`?`新增`:`保存`}失败:${t}`,`error`)}}function qe(){try{let e=x.find(e=>e.id===C)?.label??`该类型`,t=_t(C);S(t),w(t[0]?.id??``),P(null),F(null),Se(`已删除用例类型「${e}」`,`success`)}catch(e){let t=e instanceof Error?e.message:String(e);F(t),Se(`删除失败:${t}`,`error`)}}(0,U.useEffect)(()=>{let e=()=>{be(O(`knowledgeLib`)),we(O(`requirements`)),R(O(`templates`)),De(O(`reqAnalysis`)),ke(O(`businessMap`)),je(O(`reqBreakdowns`))},t=re(()=>e());return p().then(e),t},[]),(0,U.useEffect)(()=>{if(!e)return;Ge(n?.caseType);let t=n?.reqSource,i=t?.kind===`stories`;m(i?`stories`:`doc`),u(t?.kind===`doc`?t.path:n?.reqPath??``),y(i?t.docId:``),b(i?t.storyIds:[]),w(n?.caseType??lt()[0]?.id??`functional`),ne(n?.templateId??``),k(``),ae(!1),ce(``),j(n?.knowledgePaths??[]),de(n?.testPointIds??[]),ze(n?.requirementBreakdownContext?.entryId??``),Le(n?.businessContext?.systemId??``),fe(n?.outputFormat??`xlsx`),P(null),F(null),me(null),r?.docId&&(m(`stories`),y(r.docId),b(r.storyIds),ze(``),Le(``)),(async()=>{let e=await Tt(`templates`),t=await Tt(`requirements`),n=await Tt(`knowledge`);o(e);let i=[];if(O(`reqAnalysis`)&&await Pt())try{i=await jt(),i.sort((e,t)=>String(t.updatedAt).localeCompare(String(e.updatedAt))),v(!0),g(i)}catch{v(!1)}else v(!1);if(r?.docId){let e=i.find(e=>e.id===r.docId);e&&(y(e.id),b(r.storyIds.length?r.storyIds:e.stories.map(e=>e.id)))}async function a(e,t,n){let{entries:r}=await St(e,t);for(let t of r)t.type===`file`?n.push(t):await a(e,t.path,n)}if(!Ce||!t)c([]),u(``);else try{let e=[];await a(`requirements`,`.`,e),c(e),u(t=>t&&e.some(e=>e.path===t)?t:``)}catch{}if(!ye||!n)ue([]),j([]);else try{let e=[];await a(`knowledge`,`.`,e),e.sort((e,t)=>(t.mtime??0)-(e.mtime??0)),ue(e),j(t=>t.filter(t=>e.some(e=>e.path===t)))}catch{}})()},[e,n,ye,Ce,r]),(0,U.useEffect)(()=>{if(!e)return;let t=!0;return Ve(``),Oe?d().then(e=>{if(!t)return;let n=[...e.systems].sort((e,t)=>e.name.localeCompare(t.name,`zh`));Ne(n),Le(e=>e&&n.some(t=>t.id===e)?e:``)}).catch(e=>{t&&(Ne([]),Ve(`业务地图读取失败:${e instanceof Error?e.message:String(e)}`))}):(Ne([]),Le(``)),Ae?An().then(e=>{t&&(Fe(e.entries),ze(t=>t&&e.entries.some(e=>e.id===t)?t:``))}).catch(e=>{t&&(Fe([]),Ve(`需求拆解库读取失败:${e instanceof Error?e.message:String(e)}`))}):(Fe([]),ze(``)),()=>{t=!1}},[e,Oe,Ae]),(0,U.useEffect)(()=>{if(!e||!a)return;if(!Te){E([]),ne(``);return}let t=!1;return pp(C,x).then(e=>{t||(E(e),ne(t=>t&&e.some(e=>e.id===t)?t:n?.templateId&&e.some(e=>e.id===n.templateId)?n.templateId:e[0]?.id??``))}),()=>{t=!0}},[e,a,Te,C,x,n?.templateId]);let Je=s.map(e=>({value:e.path,label:e.path})),Ye=T.map(e=>({value:e.id,label:e.title})),Xe=le.map(e=>({value:e.path,label:e.path.replace(/\.[^.]+$/,``)})),Ze=[{value:``,label:`不引用需求拆解库`},...Pe.map(e=>({value:e.id,label:`${e.title} · ${e.iteration}`}))],Qe=[{value:``,label:`不引用业务地图`},...Me.map(e=>({value:e.id,label:`${e.name}(${e.functions.length} 功能 / ${e.flows.length} 流程)`}))],$e=(0,U.useMemo)(()=>h.find(e=>e.id===ee)??null,[h,ee]),et=(0,U.useMemo)(()=>f===`stories`?{title:$e?.title,docTitle:$e?.title,sourceTitle:$e?.sourceTitle,sourcePath:$e?.sourcePath}:{title:l.split(`/`).pop(),sourceTitle:l.split(`/`).pop(),sourcePath:l},[f,$e,l]),tt=(0,U.useMemo)(()=>sc(Pe,et),[Pe,et]),nt=(0,U.useMemo)(()=>cc(Me,et),[Me,et]);(0,U.useEffect)(()=>{e&&Ae&&ze(e=>e&&Pe.some(t=>t.id===e)?e:tt?.id||``)},[e,Ae,Pe,tt,et]),(0,U.useEffect)(()=>{e&&Oe&&Le(e=>e&&Me.some(t=>t.id===e)?e:nt?.id||``)},[e,Oe,Me,nt,et]);let rt=$e?.stories??[],it=te.filter(e=>rt.some(t=>t.id===e)).length,at=$e?.testPoints?.points??[],ot=M.filter(e=>at.some(t=>t.id===e)),st=at.map(e=>({value:e.id,label:`${e.id} · ${Zr[e.dimension].label} ${e.priority} · ${e.title}`})),z=Ee?f===`doc`?`切到「用户故事」来源后可选`:$e?at.length?`选择要覆盖的测试点…`:`这份分析还没有测试点`:`先选择一份需求分析记录`:`需求分析插件未启用`,ct=f===`doc`?`测试点来自「需求分析」拆好的结果:切到「用户故事」来源就能选。`:$e?at.length?`选中的测试点连同前置 / 步骤 / 预期一起拼进技能要求;不选则按需求本身生成。`:`先去需求分析的「测试点」Tab 生成,再回来按测试点写用例。`:`选好需求分析记录后,这里会列出它的测试点。`;async function ut(){ge(!0),me(null);try{if(!ie||!oe||!se.trim()){let e=oe?`自动关联技能「${oe}」还是空的,先补上规则再生成`:`「${We}」的默认技能尚未就绪,请重新打开插件`;me(e),Se(e,`error`);return}let e=T.find(e=>e.id===D)??T[0],r=($e?.stories??[]).map(e=>e.id),a=r.filter(e=>te.includes(e)),o=f===`stories`?ee?{kind:`stories`,docId:ee,storyIds:a}:void 0:l?{kind:`doc`,path:l}:void 0,s=``,c=``,u;if(o?.kind===`doc`){s=o.path.split(`/`).pop()?.replace(/\.[^.]+$/,``)??``;try{let e=await mp(o.path),t=/大模块/.test(e)&&/小模块/.test(e)?`Ideal 需求表:按「需求条目 → 条目内测试点」顺序编写;「模块」填大模块原文,「子模块」填小模块名(层级路径只取最后一段,不要自造更细的名字)。
249
+ `:`按文档条目 / 章节自上而下的顺序编写用例,不要重排。
250
+ `;c=`### 需求文档:${o.path}\n${t}${e}`}catch(e){me(e instanceof Error?e.message:String(e));return}}else if(o?.kind===`stories`){if(!_){me(Ee?`需求分析服务未就绪,暂时读不到用户故事;可切回「需求文档」`:`需求分析插件未启用,读不到用户故事;可切回「需求文档」`);return}if(!$e){me(`所选需求分析记录已不存在,请重新选择`);return}if(!it){me(`请至少勾选一条用户故事,或点「全选」`);return}s=$e.title;let e=$e.outline??[];if(e.length&&(u=[...Mt(e).entries()].sort((e,t)=>e[1]-t[1]).map(([e])=>e)),c=`### 用户故事:${$e.title}\n按下列用户故事逐条覆盖;用例顺序以「需求条目(RO)→ 条目内测试点(TP)」为准,模块字段取来源需求的章节 / Ideal 小模块原文(优先于 US 编号)。\n${Ft($e,a)}`,$e.sourcePath)try{let e=await mp($e.sourcePath),t=Nt(e);t&&(c=`${t}\n\n${c}`)}catch{}}let p=[];for(let e of A)try{let t=await wt(`knowledge`,e);p.push(`\n### 知识库:${e}\n${t.content}`)}catch{p.push(`\n### 知识库:${e}\n(无法读取)`)}let m=at.filter(e=>ot.includes(e.id)),h=m.length?Qr(m,r):[],g,v;try{if(Ae&&Re){let e=await kn(Re,!0);if(g=uc(e.entry,e.content)??void 0,!g)throw Error(`所选需求拆解 XMind 没有可读取的内容`)}if(Oe&&Ie&&(v=gc(await d(),Ie)??void 0,!v))throw Error(`所选业务地图系统已不存在`)}catch(e){let t=e instanceof Error?e.message:String(e);me(`业务上下文读取失败:${t}`),Se(`业务上下文读取失败:${t}`,`error`);return}i({active:!0,caseType:C,outputFormat:N,reqPath:o?.kind===`doc`?o.path:void 0,reqSource:o,docTitle:s||void 0,reqBlock:[c,...p].filter(Boolean).join(`
251
+
252
+ `)||void 0,templateId:e?.id,templateTitle:e?.title,promptPath:oe,knowledgePaths:A.length?[...A]:void 0,testPointIds:h.length?h.map(e=>e.id):void 0,outlineOrder:u,testPointBlock:h.length?Xr(h,r):void 0,requirementBreakdownContext:g,businessContext:v,templateHeaders:e?.headers?.length?e.headers:[...yt],templateBody:(e?.body||``).trim(),promptBody:se.trim(),confirmedAt:Date.now(),linkedCasePath:n?.linkedCasePath}),t()}finally{ge(!1)}}return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(L,{open:e,onClose:t,title:`生成测试用例 · 配置`,closeAriaLabel:`关闭生成测试用例面板`,widthClass:`max-w-3xl`,escDisabled:_e!==null,footer:(0,Z.jsxs)(`footer`,{className:`shrink-0 border-t border-stone-100 px-4 py-3 flex items-center gap-2`,children:[(0,Z.jsx)(`p`,{className:`flex-1 min-w-0 truncate text-[11px] text-stone-400`,children:`配置仅对当前会话生效,可在输入区胶囊里再改`}),(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:he||!a||!ie||!se.trim(),onClick:()=>void ut(),className:`h-9 px-5 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`确认`})]}),children:[a?null:(0,Z.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写文档库。`}),pe?(0,Z.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:pe}):null,(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 gap-x-4 gap-y-1 lg:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`order-1 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`用例类型`}),(0,Z.jsx)(I,{options:x.map(e=>({value:e.id,label:e.label})),value:C,onChange:w,dimWhenOpen:!0})]}),(0,Z.jsxs)(`div`,{className:`order-3 min-w-0 lg:order-2`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:[`用例模板`,(0,Z.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[`(`,We,` · `,Ue.templateFolder,`)`]})]}),(0,Z.jsx)(qt,{options:Ye,value:He?.id??``,onChange:ne,allowEmpty:!1,disabled:!Te,placeholder:Te?Ye.length?`搜索并选择模板…`:`暂无「${Ue.templateFolder}」模板`:`测试模板库未启用`})]}),(0,Z.jsxs)(`div`,{className:`order-2 flex min-w-0 items-start justify-end gap-1 pt-1.5 lg:order-3`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-[#4176e6] transition-colors hover:border-[#4176e6]/40 hover:bg-[#edf3fe]`,onClick:()=>{F(null),P(`add`)},children:`新增`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-stone-600 transition-colors hover:border-stone-300 hover:bg-stone-50`,onClick:()=>{F(null),P(`edit`)},children:`编辑`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-red-600 transition-colors hover:border-red-300 hover:bg-red-50 disabled:opacity-40 disabled:hover:border-stone-200 disabled:hover:bg-transparent`,disabled:x.length<=1,onClick:()=>{F(null),P(`delete`)},children:`删除`})]}),(0,Z.jsx)(`div`,{className:`order-4 min-w-0 lg:order-4`,children:Te?He?.headers?.length?(0,Z.jsx)(B,{fields:He.headers}):null:(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「测试模板库」后再选择;未启用时按默认字段生成。`})})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-4 lg:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`输出格式`}),(0,Z.jsx)(I,{options:fp,value:N,onChange:fe,dimWhenOpen:!0})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`引用知识库(可多选)`}),(0,Z.jsx)(Kt,{options:Xe,values:A,onChange:j,disabled:!ye,placeholder:ye?Xe.length?`选择知识库文档…`:`暂无知识库文档`:`知识库管理未启用`}),ye?null:(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「知识库管理」后再引用。`})]})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-stone-500`,children:`需求来源`}),(0,Z.jsxs)(`div`,{className:`inline-flex rounded-lg border border-stone-200 bg-stone-50 p-0.5`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{m(`doc`),ze(``),Le(``)},className:`h-7 rounded-md px-2.5 text-xs transition-colors ${f===`doc`?`bg-white text-stone-900 shadow-sm`:`text-stone-500 hover:text-stone-700`}`,children:`需求文档`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!_,onClick:()=>{_&&(m(`stories`),ze(``),Le(``))},className:`h-7 rounded-md px-2.5 text-xs transition-colors disabled:opacity-40 ${f===`stories`?`bg-white text-stone-900 shadow-sm`:`text-stone-500 hover:text-stone-700`}`,children:`用户故事`})]}),(0,Z.jsx)(`p`,{className:`text-[11px] text-stone-400`,children:f===`stories`?`来自「需求分析」拆好的故事:按 US 编号逐条覆盖,改动后重新生成即可`:`来自「需求文档库」的原始文档`})]}),(0,Z.jsx)(`div`,{className:`mt-2`,children:f===`stories`?(0,Z.jsx)(qt,{options:h.map(e=>({value:e.id,label:`${e.title}(${e.stories.length} 个故事)`})),value:ee,onChange:e=>{y(e);let t=h.find(t=>t.id===e);b(t?.stories.map(e=>e.id)??[]),de([]),ze(``),Le(``)},allowEmpty:!1,disabled:!_,placeholder:Ee?_?h.length?`搜索并选择需求分析记录…`:`暂无需求分析记录,请先在「需求分析」拆解`:`需求分析服务未就绪`:`需求分析插件未启用`}):(0,Z.jsx)(qt,{options:Je,value:l,onChange:e=>{u(e),ze(``),Le(``)},allowEmpty:!1,disabled:!Ce,placeholder:Ce?Je.length?`搜索并选择需求文档…`:`请先在需求文档库中上传`:`需求文档库未启用`})}),f===`stories`?(0,Z.jsxs)(`div`,{className:`mt-2 rounded-lg bg-stone-50/80 p-2.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 text-[11px] text-stone-500`,children:[`选择故事`,(0,Z.jsxs)(`span`,{className:`ml-1 text-stone-400`,children:[it,`/`,rt.length]})]}),(0,Z.jsx)(`button`,{type:`button`,className:`text-[11px] text-[#4176e6] hover:underline`,onClick:()=>b(rt.map(e=>e.id)),children:`全选`}),(0,Z.jsx)(`button`,{type:`button`,className:`text-[11px] text-stone-500 hover:underline`,onClick:()=>b([]),children:`全不选`})]}),rt.length?(0,Z.jsx)(`div`,{className:`mt-1.5 grid max-h-56 grid-cols-1 gap-x-4 overflow-y-auto sm:grid-cols-2`,children:rt.map(e=>(0,Z.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-1.5 py-1 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:te.includes(e.id),onChange:t=>b(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,Z.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-stone-400`,children:e.id}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(xe,{text:e.title,className:`block truncate text-stone-800`})}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:e.priority})]},e.id))}):(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400`,children:ee?`这份分析还没有拆出用户故事`:`先选择一份需求分析记录`}),Ee?null:(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400`,children:`需求分析插件已关闭;用户故事来源暂不可用,可改用「需求文档」。`})]}):Ce?null:(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「需求文档库」后再选择。`})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3 gap-y-1`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-stone-500`,children:`补充业务上下文(可选)`}),(0,Z.jsx)(`p`,{className:`text-[11px] text-stone-400`,children:`根据当前需求自动匹配,也可手动切换;不会读取业务地图的登录凭据。`})]}),(0,Z.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2 text-xs text-stone-500`,children:[(0,Z.jsx)(`span`,{children:`需求拆解库 XMind`}),tt&&Re===tt.id?(0,Z.jsx)(`span`,{className:`text-[10px] text-[#4176e6]`,children:`自动匹配`}):null]}),(0,Z.jsx)(I,{options:Ze,value:Re,onChange:ze,disabled:!Ae,ariaLabel:`引用需求拆解库`}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:Ae?Pe.length?`生成时重新读取所选 XMind 的最新磁盘内容。`:`当前还没有可引用的需求拆解 XMind。`:`需求拆解库插件未启用。`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2 text-xs text-stone-500`,children:[(0,Z.jsx)(`span`,{children:`业务地图系统`}),nt&&Ie===nt.id?(0,Z.jsx)(`span`,{className:`text-[10px] text-[#4176e6]`,children:`自动匹配`}):null]}),(0,Z.jsx)(I,{options:Qe,value:Ie,onChange:Le,disabled:!Oe,ariaLabel:`引用业务地图系统`}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:Oe?Me.length?`只注入所选系统的功能规则、输入输出和业务流程。`:`当前空间还没有业务系统。`:`业务地图插件未启用。`})]})]}),Be?(0,Z.jsx)(`p`,{className:`mt-2 rounded-lg border border-amber-200 bg-amber-50 px-2.5 py-2 text-[11px] text-amber-800`,children:Be}):null]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 text-xs font-medium text-stone-500`,children:[`测试点(可多选)`,at.length?(0,Z.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[ot.length,`/`,at.length]}):null]}),at.length?(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 text-[11px]`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`text-[#4176e6] transition-colors hover:text-[#3565c7]`,onClick:()=>de(at.map(e=>e.id)),children:`全选`}),(0,Z.jsx)(`button`,{type:`button`,className:`text-stone-500 transition-colors hover:text-stone-700`,onClick:()=>de([]),children:`清空`})]}):null]}),(0,Z.jsx)(Kt,{options:st,values:ot,onChange:de,disabled:!st.length,placeholder:z}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:ct})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-stone-50/60 px-4 py-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold text-stone-600`,children:`本次配置`}),(0,Z.jsxs)(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-4 gap-y-2 sm:grid-cols-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`用例类型`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:We})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`用例模板`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:He?.title||`—`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`输出格式`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:fp.find(e=>e.value===N)?.label??N})]}),(0,Z.jsxs)(`div`,{className:`col-span-2 min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`需求来源`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:f===`stories`?$e?`用户故事 · ${$e.title}(${it}/${rt.length} 条)`:`用户故事 · 未选择`:l?`需求文档 · ${l}`:`需求文档 · 未选择`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`引用知识库`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:A.length?`${A.length} 个文档`:`未引用`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`测试点`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:ot.length?`${ot.length} 条`:`未选择`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`需求拆解 XMind`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Pe.find(e=>e.id===Re)?.title||`未引用`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`业务地图`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Me.find(e=>e.id===Ie)?.name||`未引用`})]})]}),(0,Z.jsx)(`p`,{className:`mt-2.5 text-[10px] leading-4 text-stone-400`,children:`确认后输入区出现「生成测试用例」胶囊,直接发送或补充范围说明即可;点 × 取消后按普通对话修改,不再整批生成。`})]})]}),(0,Z.jsx)(dp,{mode:_e,currentLabel:Ue.label,templateFolder:Ue.templateFolder,error:ve??``,onClose:()=>{P(null),F(null)},onSubmit:Ke,onDelete:qe})]})}function gp({open:e,onClose:t,initial:n,onConfirm:r}){let[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(``),[c,l]=(0,U.useState)(()=>Ac()),[u,d]=(0,U.useState)(Ac()[0]??`测试规范`),[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)(null);function v(e){let t=Ac();l(t),d(n=>{let r=e??n;return t.includes(r)?r:t[0]??n})}function ee(e){let t=m===`add`;try{if(t){let t=Mc(e);v(t),Se(`已新增分类「${t}」`,`success`)}else{let t=Nc(u,e);v(t),Se(`已重命名为「${t}」`,`success`)}h(null),_(null)}catch(e){let n=e instanceof Error?e.message:String(e);_(n),Se(`${t?`新增`:`保存`}分类失败:${n}`,`error`)}}function y(){try{let e=u,t=Pc(u);l(t),d(t[0]??``),h(null),_(null),p(null),Se(`已删除分类「${e}」`,`success`)}catch(e){let t=e instanceof Error?e.message:String(e);_(t),Se(`删除分类失败:${t}`,`error`)}}(0,U.useEffect)(()=>{e&&(v(n?.category),s(n?.titleHint??``),d(n?.category??Ac()[0]??`测试规范`),h(null),_(null),p(null),Tt(`knowledge`).then(a))},[e,n]);function te(){p(null),i?(r({active:!0,titleHint:o.trim(),category:u,confirmedAt:Date.now(),linkedKnowledgePath:n?.linkedKnowledgePath}),t()):p(`本地文档服务未就绪,无法写入知识库`)}return(0,Z.jsxs)(L,{open:e,onClose:t,title:`生成知识库 · 配置`,closeAriaLabel:`关闭生成知识库面板`,escDisabled:m!==null,footer:(0,Z.jsxs)(`footer`,{className:`shrink-0 p-4 border-t border-stone-100 flex items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!i,onClick:te,className:`flex-1 h-9 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`确认`})]}),children:[i?null:(0,Z.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写知识库。`}),(0,Z.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`按所选分类沉淀测试规范、方法论或环境约定:确认后输入区出现「生成知识库」胶囊,粘贴或描述素材后发送;点 × 取消后按普通对话修改,不再整批生成。质检通过后写入知识库,可在「知识库管理」中查看与 @ 引用。`}),f?(0,Z.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:f}):null,(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 text-xs font-medium text-stone-500`,children:`分类`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-[#4176e6] transition-colors hover:border-[#4176e6]/40 hover:bg-[#edf3fe]`,onClick:()=>{h(`add`),_(null)},children:`新增`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-stone-600 transition-colors hover:border-stone-300 hover:bg-stone-50`,onClick:()=>{h(`edit`),_(null)},children:`编辑`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-red-600 transition-colors hover:border-red-300 hover:bg-red-50 disabled:opacity-40 disabled:hover:border-stone-200 disabled:hover:bg-transparent`,disabled:c.length<=1,onClick:()=>{h(`delete`),_(null)},children:`删除`})]}),(0,Z.jsx)(I,{options:c.map(e=>({value:e,label:e})),value:u,onChange:d,dimWhenOpen:!0}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400 leading-4`,children:`分类决定两件事:生成时告诉模型按哪类知识写(规范 / 方法论 / 环境约定侧重不同), 入库时写进文档 frontmatter 的 category,知识库管理里就按它归类展示。`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,htmlFor:`kg-title`,children:`期望名称`}),(0,Z.jsx)(`input`,{id:`kg-title`,value:o,onChange:e=>s(e.target.value),placeholder:`如:接口自动化环境约定.md`,className:`mt-1 w-full h-9 px-3 text-sm rounded-lg border border-stone-200 focus:outline-none focus:ring-2 focus:ring-[#4176e6]/40`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-4`,children:`可填期望文件名;留空则由模型自拟。素材与编写要求在主输入框描述。`})]}),(0,Z.jsx)(up,{mode:m,entityLabel:`知识库分类`,currentLabel:u,placeholder:`如:安全基线`,error:g??``,onClose:()=>{h(null),_(null)},onSubmit:ee,onDelete:y,hint:()=>(0,Z.jsx)(Z.Fragment,{children:`分类写入文档 frontmatter,文件平铺存放于 知识库管理/;改名不会自动迁移已有文件。`}),deleteMessage:e=>(0,Z.jsxs)(Z.Fragment,{children:[`确定删除「`,e,`」?已入库的知识文档不会被删除,但该分类将不能再用于生成。`]})})]})}function _p({task:e,onClose:t,onSave:n,onRemove:s,readOnly:c=!1}){let[l,u]=(0,U.useState)(``),d=!!e;(0,U.useEffect)(()=>{u(e?.body??``)},[e]);let f=!!e&&l.trim()!==e?.body.trim();return(0,Z.jsxs)(a,{open:d,onClose:t,className:`relative z-110`,children:[(0,Z.jsx)(o,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,Z.jsxs)(r,{transition:!0,className:`tw-dialog-panel-anim relative flex max-h-[85vh] w-full max-w-2xl flex-col rounded-xl border border-stone-200 bg-white p-5 shadow-xl`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`absolute top-3.5 right-3.5 flex h-7 w-7 items-center justify-center rounded-md text-stone-400 transition-colors hover:bg-stone-100 hover:text-stone-700`,"aria-label":`关闭`,children:`✕`}),(0,Z.jsx)(i,{className:`pr-8 text-base font-semibold text-stone-900`,children:e?.label||`任务要求`}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px] text-stone-400`,children:[(0,Z.jsx)(`span`,{children:c?`已随消息发送给模型`:`发送时这段要求会随消息一起带给模型`}),e?.detail?(0,Z.jsxs)(`span`,{className:`truncate`,children:[`· `,e.detail]}):null]}),(0,Z.jsx)(`textarea`,{value:l,onChange:e=>{c||u(e.target.value)},readOnly:c,spellCheck:!1,className:`mt-3 min-h-[240px] flex-1 resize-none overflow-y-auto rounded-lg border border-stone-200 px-3 py-2.5 font-mono text-[12.5px] leading-relaxed text-stone-700 outline-none ${c?`bg-stone-50/80`:`bg-stone-50/60 focus:border-[#4176e6]/40 focus:bg-white`}`}),(0,Z.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-2`,children:[c||!s?(0,Z.jsx)(`span`,{}):(0,Z.jsx)(`button`,{type:`button`,onClick:s,className:`h-8 rounded-lg border border-stone-200 px-3 text-sm text-stone-500 transition-colors hover:border-red-300 hover:bg-red-50 hover:text-red-600`,children:`移除`}),(0,Z.jsx)(`div`,{className:`flex items-center gap-2`,children:c||!n?(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-8 rounded-lg bg-[#4176e6] px-3.5 text-sm text-white transition-colors hover:bg-[#3566d0]`,children:`关闭`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-8 rounded-lg border border-stone-200 px-3 text-sm text-stone-600 transition-colors hover:bg-stone-100`,children:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!l.trim(),onClick:()=>n(l.trim()),className:`h-8 rounded-lg bg-[#4176e6] px-3.5 text-sm text-white transition-colors hover:bg-[#3566d0] disabled:cursor-not-allowed disabled:bg-stone-300`,children:f?`保存修改`:`完成`})]})})]})]})})]})}var vp={user:`用户档案`,memory:`长期记忆`,key:`项目关键记忆`,project:`项目日志`};function yp(e){return e?e.replace(/\\/g,`/`).replace(/^\/Users\/[^/]+/,`~`):``}var bp={project:{title:`项目日志`,fileHint:`MEMORY.md`,desc:`项目进展流水账,按需查阅,默认不注入上下文。`,curated:!1},key:{title:`项目关键记忆`,fileHint:`KEY.md`,desc:`项目关键约定与事实;写入需经待确认记忆建议采纳后注入。`,curated:!0},memory:{title:`长期记忆`,fileHint:`MEMORY.md`,desc:`全局环境与跨项目事实,注入所有会话;写入需审查建议并经确认。`,curated:!0}},xp=[{id:`guide`,label:`指南`},{id:`suggestions`,label:`待确认记忆建议`},{id:`project`,label:`项目日志`},{id:`key`,label:`项目关键记忆 KEY.md`},{id:`memory`,label:`长期记忆 MEMORY.md`},{id:`agents`,label:`全局规则 AGENTS.md`},{id:`archive`,label:`归档`},{id:`settings`,label:`设置`}];function Sp({live:e,pluginOn:t,workspacePath:n=``,onHealthChange:r}){let[i,a]=(0,U.useState)(`suggestions`),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)({}),[u,d]=(0,U.useState)(``),[f,p]=(0,U.useState)([]),[m,h]=(0,U.useState)([]),[g,_]=(0,U.useState)(`memory`),[v,ee]=(0,U.useState)(null),[y,te]=(0,U.useState)([]),[b,x]=(0,U.useState)(null),[S,C]=(0,U.useState)(``),[w,E]=(0,U.useState)(!1),[D,re]=(0,U.useState)(null),[ie,ae]=(0,U.useState)(null),[O,oe]=(0,U.useState)(null),k=n.trim(),se=(0,U.useRef)(r);se.current=r;let ce=(0,U.useCallback)(async()=>{if(!e)s(null),l({}),p([]),te([]),se.current?.(null);else{x(null);try{let[e,t,n,r,a]=await Promise.all([Dr(),Cr(k,`all`),Hr(),Ur(),fn().catch(()=>null)]);s(e),l(t.tracks),d(t.projectId||``),p(n),ee(r),te(a?.files?.length?a.files:a?.text?[{path:`AGENTS.md`,name:`AGENTS.md`}]:[]),i===`archive`&&h(await Ar(g,k)),se.current?.(e)}catch(e){x(e instanceof Error?e.message:String(e))}}},[e,k,i,g]);if((0,U.useEffect)(()=>{ce()},[ce]),!t)return(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-600`,children:`会话记忆未启用`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`在「我的插件」中打开「会话记忆」后,可在此管理记忆轨与待确认记忆建议`})]});if(!e)return(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-600`,children:`会话记忆中间件未就绪`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`本地记忆服务未就绪`})]});let le=i===`memory`||i===`key`,ue=i===`memory`||i===`key`||i===`project`,A=ue?c[i]?.entries??[]:[],j=ue?c[i]?.path:null,M=o?.path||`.lantern/local/memories`;async function de(e){E(!0);try{await Mr(e),await ce()}catch(e){x(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function N(e){E(!0);try{await Pr(e),await ce()}catch(e){x(e instanceof Error?e.message:String(e))}finally{E(!1)}}function fe(e){le&&ae(e)}async function pe(){if(ie==null||!le)return;let e=ie;ae(null),E(!0);try{await jr(i,e,k),await ce()}catch(e){x(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function me(){if(O==null)return;let e=O;oe(null),E(!0);try{await kr(g,e,k),await ce()}catch(e){x(e instanceof Error?e.message:String(e))}finally{E(!1)}}function he(e){re(e)}async function ge(){if(D==null)return;let e=D;re(null),E(!0);try{await Vr(i,e,k),await ce()}catch(e){x(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function _e(){if(le&&S.trim()){E(!0);try{await Or(i,S.trim(),k),C(``),await ce()}catch(e){x(e instanceof Error?e.message:String(e))}finally{E(!1)}}}async function P(e){E(!0);try{let t=await Nr(e);ee(t)}catch(e){x(e instanceof Error?e.message:String(e))}finally{E(!1)}}function ve(e){let t=bp[e],n=e===`key`?`KEY.md`:t.fileHint,r=e===`key`?`项目关键记忆 ${n}`:e===`memory`?`长期记忆 ${n}`:t.title,i=yp(j)||`${yp(M)}/…/${n}`;return(0,Z.jsxs)(`div`,{className:`mb-3 space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 flex-wrap min-w-0`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:r}),t.curated?null:(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 text-[10px] rounded bg-stone-100 text-stone-500 border border-stone-200`,children:`只读追加`}),(0,Z.jsxs)(`span`,{className:`text-[11px] text-stone-400 tabular-nums`,children:[A.length,` 条`]}),(0,Z.jsx)(`span`,{className:`max-w-full break-all whitespace-normal text-[11px] text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/20 rounded-lg px-2 py-0.5 font-mono leading-4`,"data-hint":j||i,children:i})]}),(0,Z.jsx)(`p`,{className:`text-xs text-stone-500 leading-5 break-words`,children:t.desc}),k?(0,Z.jsxs)(`p`,{className:`text-[11px] text-stone-400 break-all`,children:[`当前会话工作目录:`,(0,Z.jsx)(`span`,{className:`font-mono`,children:k}),u?(0,Z.jsxs)(Z.Fragment,{children:[` · `,`项目 id `,(0,Z.jsx)(`span`,{className:`font-mono`,children:u.slice(0,12)})]}):null]}):null]})}return(0,Z.jsxs)(`div`,{className:`h-full flex flex-col min-h-0`,children:[(0,Z.jsxs)(`div`,{className:`shrink-0 flex flex-wrap items-center gap-2 px-4 py-2 border-b border-stone-200/80`,children:[xp.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:`h-7 px-2.5 text-xs rounded-md whitespace-normal text-left leading-tight ${i===e.id?`bg-stone-900 text-white`:`text-stone-600 hover:bg-stone-100`}`,children:[e.label,e.id===`suggestions`&&f.length>0?(0,Z.jsxs)(`span`,{className:`ml-1 tabular-nums`,children:[`(`,f.length,`)`]}):null]},e.id)),(0,Z.jsxs)(`span`,{className:`text-[11px] text-stone-400 tabular-nums`,children:[o?.entryCount??0,` 条 · 待确认 `,o?.suggestionCount??f.length]})]}),b?(0,Z.jsx)(`div`,{className:`mx-4 mt-3 px-3 py-2 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg`,children:b}):null,(0,Z.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:[i===`guide`?(0,Z.jsxs)(`div`,{className:`space-y-3 max-w-2xl`,children:[(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`确认制:为什么必须你点头`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`记忆会改变后续对话行为。长期记忆 / 项目关键记忆经「待确认记忆建议」采纳后才写入并注入;项目日志可直写但不注入。`})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`待确认记忆建议:AI 只提议,你拍板`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`后台或对话中产出的记忆建议进入独立队列。采纳可写入对应轨;拒绝则丢弃。`}),(0,Z.jsxs)(`ul`,{className:`mt-2 space-y-1.5 text-xs text-stone-600`,children:[(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2 break-words`,children:`采纳 → 长期记忆 MEMORY.md / 项目关键记忆 KEY.md`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`拒绝 → 丢弃,不落盘`})]})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`各轨文件(对齐 dsh)`}),(0,Z.jsxs)(`ul`,{className:`mt-2 space-y-1.5 text-xs text-stone-600`,children:[(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`项目日志 · 项目目录 MEMORY.md(不注入)`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`项目关键记忆 KEY.md(注入,需确认)`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`长期记忆 MEMORY.md(注入,需确认)`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`全局规则:展示工作区 AGENTS.md 等规则文件`})]})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`编辑与维护`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`可在本 Tab 浏览条目、手动添加(注入轨)、归档或删除。文件为 § 分隔结构化记忆,用外部编辑器打开时请谨慎修改。`}),(0,Z.jsxs)(`p`,{className:`mt-2 text-[11px] text-amber-700/90`,children:[`存储目录:`,(0,Z.jsx)(`code`,{className:`font-mono`,children:M})]})]})]}):null,i===`suggestions`?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`待确认记忆建议`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-500 leading-5`,children:`后台审查或对话沉淀产出的记忆建议:采纳后写入记忆文件并注入;拒绝则丢弃。`})]}),f.length===0?(0,Z.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-16 text-center text-sm text-stone-400`,children:`没有待确认的建议。`}):(0,Z.jsx)(`ul`,{className:`space-y-3`,children:f.map(e=>(0,Z.jsxs)(`li`,{className:`rounded-lg border border-amber-200/80 bg-amber-50/30 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-stone-400 mb-1 flex-wrap`,children:[(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-amber-100 text-amber-900 border border-amber-200 font-medium`,children:`待确认记忆建议`}),(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-white text-stone-600 border border-stone-200`,children:vp[e.target]??e.target}),(0,Z.jsx)(`span`,{children:e.time}),e.hits&&e.hits>1?(0,Z.jsxs)(`span`,{children:[`×`,e.hits]}):null]}),(0,Z.jsx)(`p`,{className:`text-sm text-stone-800 whitespace-pre-wrap`,children:e.content}),e.reason?(0,Z.jsxs)(`p`,{className:`mt-1 text-xs text-stone-500`,children:[`原因:`,e.reason]}):null,(0,Z.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:w,onClick:()=>void de(e.id),className:`h-7 px-2.5 text-xs text-white bg-emerald-600 rounded-md hover:bg-emerald-700 disabled:opacity-40`,children:`采纳`}),(0,Z.jsx)(`button`,{type:`button`,disabled:w,onClick:()=>void N(e.id),className:`h-7 px-2.5 text-xs text-stone-600 border border-stone-200 rounded-md hover:bg-stone-50 disabled:opacity-40`,children:`拒绝`})]})]},e.id))})]}):null,ue?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[ve(i),le?(0,Z.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white p-3 space-y-2`,children:[(0,Z.jsx)(`textarea`,{value:S,onChange:e=>C(e.target.value),placeholder:i===`key`?`输入一条项目关键约定,例如:本仓库包管理器用 pnpm…`:`输入一条想长期记住的全局事实/惯例/环境…`,rows:3,className:`w-full text-sm rounded-lg border border-stone-200 px-3 py-2 focus:outline-none focus:border-[#4176e6] resize-y`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] text-stone-400`,children:`手动写入会直接落盘;重要偏好更推荐走「待确认记忆建议」。`}),(0,Z.jsx)(`button`,{type:`button`,disabled:w||!S.trim(),onClick:()=>void _e(),className:`shrink-0 h-8 px-3 text-xs text-white bg-[#4176e6] rounded-lg disabled:opacity-40`,children:`保存`})]})]}):(0,Z.jsx)(`p`,{className:`text-xs text-stone-400`,children:`本轨由对话中 memory_append 自动追加,一般不注入上下文。`}),A.length===0?(0,Z.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-12 text-center text-sm text-stone-400`,children:`(文件不存在或为空)`}):(0,Z.jsx)(`ul`,{className:`space-y-2`,children:A.map(e=>(0,Z.jsxs)(`li`,{className:`rounded-lg border border-stone-200 bg-white px-3 py-2.5 flex gap-2`,children:[(0,Z.jsx)(`p`,{className:`flex-1 text-sm text-stone-800 whitespace-pre-wrap`,children:e.text}),(0,Z.jsxs)(`div`,{className:`shrink-0 self-start flex flex-col gap-0.5`,children:[le?(0,Z.jsx)(`button`,{type:`button`,disabled:w,onClick:()=>void fe(e.index),className:`h-7 px-2 text-[11px] text-stone-500 hover:bg-stone-50 rounded-md`,children:`归档`}):null,(0,Z.jsx)(`button`,{type:`button`,disabled:w,onClick:()=>void he(e.index),className:`h-7 px-2 text-[11px] text-red-600 hover:bg-red-50 rounded-md`,children:`删除`})]})]},`${i}-${e.index}`))})]}):null,i===`agents`?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`全局规则`}),(0,Z.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`工作区规则文件(AGENTS.md 等),随系统提示注入。`}),y.length===0?(0,Z.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-12 text-center text-sm text-stone-400`,children:`(未找到规则文件)`}):(0,Z.jsx)(`ul`,{className:`space-y-2 w-full`,children:y.map(e=>{let t=yp(e.abs)||yp(e.path)||e.label||e.path||e.name;return(0,Z.jsx)(`li`,{className:`w-full`,children:(0,Z.jsxs)(`div`,{className:`w-full flex items-center gap-4 rounded-xl border border-stone-200 bg-white px-4 py-3.5`,children:[(0,Z.jsx)(`span`,{className:`w-12 h-12 rounded-xl bg-[#edf3fe] text-[#4176e6] flex items-center justify-center text-[11px] font-semibold shrink-0`,children:(e.name.split(`.`).pop()||`MD`).toUpperCase()}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-[15px] font-medium text-stone-800 break-all`,children:e.name||`AGENTS.md`}),(0,Z.jsx)(`span`,{className:`block text-xs text-stone-400 break-all font-mono mt-1`,children:t})]}),(0,Z.jsx)(`button`,{type:`button`,disabled:w,onClick:()=>{x(null),E(!0),rn(e.path||e.name||`AGENTS.md`,T(),{abs:e.abs}).catch(e=>x(e instanceof Error?e.message:String(e))).finally(()=>E(!1))},className:`shrink-0 h-9 px-4 text-xs text-[#4176e6] border border-[#4176e6]/30 rounded-lg hover:bg-[#f5f8ff] disabled:opacity-40`,children:`打开文件`})]})},e.abs||e.path)})})]}):null,i===`archive`?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`div`,{className:`flex gap-2`,children:[`user`,`memory`,`key`].map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{_(e)},className:`h-7 px-2.5 text-xs rounded-md ${g===e?`bg-stone-800 text-white`:`border border-stone-200`}`,children:vp[e]??e},e))}),m.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-stone-400 text-center py-10`,children:`暂无归档`}):(0,Z.jsx)(`ul`,{className:`space-y-2`,children:m.map(e=>(0,Z.jsxs)(`li`,{className:`rounded-lg border border-stone-200 bg-white px-3 py-2.5 flex gap-2`,children:[(0,Z.jsx)(`p`,{className:`flex-1 text-sm text-stone-800 whitespace-pre-wrap`,children:e.text}),(0,Z.jsxs)(`div`,{className:`shrink-0 self-start flex flex-col gap-0.5`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:w,onClick:()=>void(async()=>{E(!0);try{await wr(g,e.index,k),await ce()}catch(e){x(e instanceof Error?e.message:String(e))}finally{E(!1)}})(),className:`h-7 px-2 text-[11px] text-emerald-700 hover:bg-emerald-50 rounded-md`,children:`转正`}),(0,Z.jsx)(`button`,{type:`button`,disabled:w,onClick:()=>oe(e.index),className:`h-7 px-2 text-[11px] text-red-600 hover:bg-red-50 rounded-md`,children:`删除`})]})]},`a-${e.index}`))})]}):null,i===`settings`&&v?(0,Z.jsxs)(`div`,{className:`space-y-4 max-w-md`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Z.jsx)(`span`,{children:`每回合注入 USER / MEMORY / KEY`}),(0,Z.jsx)(`input`,{type:`checkbox`,checked:v.injectMemory,onChange:e=>void P({injectMemory:e.target.checked})})]}),(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Z.jsx)(`span`,{children:`收尾提示写 project`}),(0,Z.jsx)(`input`,{type:`checkbox`,checked:v.perTurnProjectWrites,onChange:e=>void P({perTurnProjectWrites:e.target.checked})})]}),(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Z.jsx)(`span`,{children:`重要事实用 suggest(KEY)`}),(0,Z.jsx)(`input`,{type:`checkbox`,checked:v.perTurnKeyWrites,onChange:e=>void P({perTurnKeyWrites:e.target.checked})})]}),(0,Z.jsxs)(`p`,{className:`text-xs text-stone-400 leading-5 break-all`,children:[`存储目录:`,(0,Z.jsx)(`code`,{className:`font-mono`,children:o?.path??`.lantern/local/memories`}),`。memory/key 经待确认记忆建议后注入;project 不注入。`]})]}):null]}),(0,Z.jsx)(ne,{open:D!=null,title:`删除记忆`,message:`永久删除该条目?此操作不可恢复。`,confirmLabel:`删除`,cancelLabel:`取消`,danger:!0,onClose:()=>re(null),onConfirm:()=>void ge()}),(0,Z.jsx)(ne,{open:ie!=null,title:`归档记忆`,message:`归档该条目?归档后不再注入上下文。`,confirmLabel:`归档`,cancelLabel:`取消`,onClose:()=>ae(null),onConfirm:()=>void pe()}),(0,Z.jsx)(ne,{open:O!=null,title:`删除归档`,message:`永久删除该归档?此操作不可恢复。`,confirmLabel:`删除`,cancelLabel:`取消`,danger:!0,onClose:()=>oe(null),onConfirm:()=>void me()})]})}var Cp=`/`,wp=[{id:`all`,label:`全部待办`},{id:`open`,label:`未完成`},{id:`done`,label:`已完成`}],Tp={urgent_important:`bg-red-500`,important:`bg-amber-500`,urgent:`bg-orange-500`,normal:`bg-stone-300`},Ep={urgent_important:`text-red-600`,important:`text-amber-600`,urgent:`text-orange-600`,normal:`text-stone-500`};function Dp(){let e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function Op(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?`${t[1]}/${t[2]}/${t[3]}`:``}function kp(e,t){let n=Op(e.dueDate),r=e.status===`done`||e.status===`cancelled`,i=In(e,t),a=``,o=`text-stone-500`;return r?a=Vn[e.status]:i===null?(a=`未设置截止`,o=`text-stone-400`):i<0?(a=`逾期 ${Math.abs(i)} 天`,o=`text-red-600`):i===0?(a=`今天截止`,o=`text-[#4176e6]`):a=`剩余 ${i} 天`,{due:n,remain:a,tone:r?`text-stone-400`:o}}function Ap(e){return[...e].filter(e=>e.status===`done`||e.status===`cancelled`).sort((e,t)=>e.updatedAt<t.updatedAt?1:-1).slice(0,30)}function jp(e,t,n){if(t===`done`)return[{key:`done`,label:`已完成 / 已取消`,items:Ap(e)}];let r=e.filter(e=>{let t=jn(e,n);return t!==`done`&&t!==`cancelled`}),i=[],a=[],o=[],s=[];for(let e of r){let t=In(e,n);t===null?s.push(e):t<0?i.push(e):t===0?a.push(e):o.push(e)}let c=[{key:`overdue`,label:`已逾期`,items:i,tone:`text-red-600`},{key:`today`,label:`今天截止`,items:a,tone:`text-[#4176e6]`},{key:`later`,label:`接下来`,items:o},{key:`undated`,label:`没有截止日期`,items:s}];return t===`all`&&c.push({key:`done`,label:`已完成 / 已取消`,items:Ap(e)}),c.filter(e=>e.items.length>0)}function Mp(e){let[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(`all`),[s,c]=(0,U.useState)({}),l=(0,U.useCallback)(async()=>{try{let e=await Fn();n(e),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}},[]);(0,U.useEffect)(()=>{l();let e=window.setInterval(()=>void l(),15e3);return()=>window.clearInterval(e)},[l]);let u=Dp(),d=(0,U.useMemo)(()=>t?jp(t,a,u):[],[t,a,u]),f=(0,U.useMemo)(()=>{let e=t??[],n=0,r=0,i=0;for(let t of e){let e=jn(t,u);if(e===`done`||e===`cancelled`)continue;i+=1;let a=In(t,u);a!==null&&a<0?n+=1:a===0&&(r+=1)}return{overdue:n,dueToday:r,open:i}},[t,u]);async function p(e){if(s[e.id])return;let t=e.status===`done`?`pending`:`done`;c(t=>({...t,[e.id]:!0})),n(n=>n&&n.map(n=>n.id===e.id?{...n,status:t}:n));try{await Pn(e.id,{status:t}),i(null)}catch(t){n(t=>t&&t.map(t=>t.id===e.id?{...t,status:e.status}:t)),i(t instanceof Error?t.message:String(t))}finally{c(t=>{let n={...t};return delete n[e.id],n})}}return e.live===!1?(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-600`,children:`待办事项需要本地服务`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`当前未就绪(仅 npm run dev / 本地一体服务可用)`})]}):(0,Z.jsxs)(`div`,{className:`h-full flex flex-col min-h-0`,children:[(0,Z.jsx)(`div`,{className:`shrink-0 border-b border-stone-200/80`,children:(0,Z.jsxs)(`div`,{className:`mx-auto flex w-full max-w-[min(64rem,100%)] flex-wrap items-center gap-2 px-4 py-2 sm:px-8 lg:px-12`,children:[wp.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),"aria-pressed":a===e.id,className:`h-7 px-2.5 text-xs rounded-md ${a===e.id?`bg-stone-900 text-white`:`text-stone-600 hover:bg-stone-100`}`,children:[e.label,e.id===`all`&&f.dueToday+f.overdue>0?(0,Z.jsx)(`span`,{className:`ml-1 tabular-nums`,children:f.dueToday+f.overdue}):null]},e.id)),(0,Z.jsxs)(`span`,{className:`ml-auto text-[11px] text-stone-400 tabular-nums`,children:[`未完成 `,f.open,f.overdue?` · 逾期 ${f.overdue}`:``]}),(0,Z.jsx)(`a`,{href:`${Cp}todos/`,className:`text-[11px] text-[#4176e6] hover:underline shrink-0`,children:`打开待办页 →`})]})}),r?(0,Z.jsx)(`div`,{className:`mx-auto mt-3 w-full max-w-[min(64rem,100%)] px-4 sm:px-8 lg:px-12`,children:(0,Z.jsx)(`div`,{className:`px-3 py-2 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg`,children:r})}):null,(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-4 py-3 sm:px-8 lg:px-12`,children:t===null?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,Z.jsx)(`span`,{className:`tw-lib-spin`,"aria-hidden":`true`})}):d.length===0?(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-500`,children:a===`all`?`当前空间还没有待办`:a===`done`?`还没有已完成的待办`:`当前没有未完成的待办`}),(0,Z.jsx)(`a`,{href:`${Cp}todos/`,className:`mt-2 text-xs text-[#4176e6] hover:underline`,children:`去待办页新增 →`})]}):(0,Z.jsx)(`div`,{className:`mx-auto w-full max-w-[min(64rem,100%)] space-y-5`,children:d.map(e=>(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`h3`,{className:`mb-2 flex items-center gap-1.5 px-0.5 text-[11px] font-medium ${e.tone??`text-stone-500`}`,children:[e.label,(0,Z.jsx)(`span`,{className:`text-stone-400 tabular-nums`,children:e.items.length})]}),(0,Z.jsx)(`ul`,{className:`list-none m-0 space-y-1.5 p-0`,children:e.items.map(e=>{let t=e.status===`done`||e.status===`cancelled`,n=kp(e,u);return(0,Z.jsxs)(`li`,{className:`group flex min-w-0 items-start gap-2.5 rounded-xl border border-stone-200 bg-white px-3 py-2.5 hover:border-stone-300`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>void p(e),"aria-label":t?`恢复 ${e.title}`:`完成 ${e.title}`,"aria-pressed":t,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded-full border transition-colors ${t?`border-[#4176e6] bg-[#4176e6] text-white`:`border-stone-300 text-transparent hover:border-[#4176e6]`}`,children:(0,Z.jsx)(`svg`,{viewBox:`0 0 20 20`,width:`10`,height:`10`,fill:`none`,stroke:`currentColor`,strokeWidth:`3`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,Z.jsx)(`path`,{d:`m4 10 4 4 8-9`})})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 break-words text-[13px] leading-5 ${t?`text-stone-400 line-through`:`text-stone-800`}`,children:e.title}),t?(0,Z.jsx)(`span`,{className:`shrink-0 pt-0.5 text-[11px] text-stone-400`,children:Vn[e.status]}):e.priority?(0,Z.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 pt-0.5 text-[11px] ${Ep[e.priority]??`text-stone-400`}`,children:[(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${Tp[e.priority]??`bg-stone-300`}`}),er[e.priority]]}):null]}),(0,Z.jsxs)(`div`,{className:`mt-1 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px] leading-4`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-stone-400 tabular-nums`,children:n.due?`截止 ${n.due}`:`无截止日期`}),(0,Z.jsx)(`span`,{className:`shrink-0 text-stone-300`,children:`·`}),(0,Z.jsx)(`span`,{className:`shrink-0 tabular-nums ${n.tone}`,children:n.remain}),e.linkedTask?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-stone-300`,children:`·`}),(0,Z.jsxs)(`span`,{className:`min-w-0 truncate ${t?`text-stone-400`:`text-stone-500`}`,children:[`任务 `,e.linkedTask]})]}):null]})]})]},e.id)})})]},e.key))})})]})}function Np({className:e=``}){return(0,Z.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,className:e,children:(0,Z.jsx)(`path`,{d:`m6 9 6 6 6-6`})})}function Pp({className:e=``}){return(0,Z.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,className:e,children:[(0,Z.jsx)(`path`,{d:`M9 3h6`}),(0,Z.jsx)(`path`,{d:`M10 3v6.2L5.6 17A2.4 2.4 0 0 0 7.7 20.6h8.6a2.4 2.4 0 0 0 2.1-3.6L14 9.2V3`}),(0,Z.jsx)(`path`,{d:`M7.5 14h9`})]})}function Fp({kind:e}){return e===`install`?(0,Z.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`15`,height:`15`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,className:`shrink-0`,children:[(0,Z.jsx)(`path`,{d:`m5 8 4 4-4 4`}),(0,Z.jsx)(`path`,{d:`M13 16h6`})]}):e===`history`?(0,Z.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`15`,height:`15`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,className:`shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M7 3.5h6.5L18 8v12.5H7Z`}),(0,Z.jsx)(`path`,{d:`M13.5 3.5V8H18`}),(0,Z.jsx)(`path`,{d:`M10 12.5h5`}),(0,Z.jsx)(`path`,{d:`M10 16h5`})]}):(0,Z.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`15`,height:`15`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,className:`shrink-0`,children:(0,Z.jsx)(`path`,{d:`M3 7.5A2.5 2.5 0 0 1 5.5 5h3.2l2 2h7.8A2.5 2.5 0 0 1 21 9.5v7A2.5 2.5 0 0 1 18.5 19h-13A2.5 2.5 0 0 1 3 16.5Z`})})}var Ip=`w-full flex items-center gap-2.5 px-3 py-2 text-left text-[13px] data-[focus]:bg-stone-100 disabled:opacity-50`;function Lp({workspace:e,compact:t=!1}){let[n,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(!1),[m,h]=(0,U.useState)(!1);(0,U.useEffect)(()=>{if(!e.trim()){d(null);return}let t=!0;return bn().then(n=>{t&&d(V(n.projects,e))}).catch(()=>{t&&d(null)}),()=>{t=!1}},[e]);let g=()=>{e.trim()&&bn().then(t=>d(V(t.projects,e))).catch(()=>void 0)};if(!n)return null;let _=n.setupPlan??[],v=n.setup?.status===`running`,ee=!n.frameworkReady&&n.setup?.status!==`running`&&n.setup?.status!==`done`;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(l,{children:[(0,Z.jsxs)(u,{"aria-label":`自动化项目:${n.name}`,className:`tw-composer-bar-ws group flex items-center gap-1 h-7 shrink-0 text-[13px] leading-5 font-medium text-stone-600 rounded-md outline-none focus:outline-none focus-visible:outline-none hover:bg-stone-100 data-[open]:bg-stone-100 transition-colors ${t?`px-1.5`:`max-w-[min(40vw,11rem)] pl-1.5 pr-1`}`,children:[(0,Z.jsx)(Pp,{className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),t?null:(0,Z.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:n.name}),v?(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-[#4176e6]`}):ee?(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full bg-amber-500`}):null,t?null:(0,Z.jsx)(Np,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Z.jsxs)(s,{transition:!0,anchor:{to:`top start`,gap:8},className:`tw-select-menu tw-menu-anim z-50 w-[min(100vw-2rem,15rem)] rounded-xl border border-stone-200 py-1 shadow-xl focus:outline-none`,children:[(0,Z.jsxs)(`p`,{className:`truncate px-3 pb-1 pt-1 text-[11px] text-stone-400`,children:[n.frameworkLabel||n.framework,v?` · 正在安装依赖`:ee?` · 环境未就绪`:``]}),(0,Z.jsx)(c,{children:(0,Z.jsxs)(`button`,{type:`button`,className:Ip,onClick:()=>p(!0),disabled:!n.setupSupported,children:[(0,Z.jsx)(Fp,{kind:`install`}),`安装依赖`]})}),n.hasGenerationRecord?(0,Z.jsx)(c,{children:(0,Z.jsxs)(`button`,{type:`button`,className:Ip,onClick:()=>h(!0),children:[(0,Z.jsx)(Fp,{kind:`history`}),`查看生成过程`]})}):null,(0,Z.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Z.jsx)(c,{children:(0,Z.jsxs)(`a`,{className:Ip,href:`/test-automation/projects/`,children:[(0,Z.jsx)(Fp,{kind:`open`}),`打开自动化项目页`]})})]})]}),(0,Z.jsxs)(a,{open:f,onClose:()=>p(!1),className:`relative z-110`,children:[(0,Z.jsx)(o,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,Z.jsxs)(r,{transition:!0,className:`tw-pop-dialog-anim relative flex max-h-[86vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-[var(--tw-border)] bg-[var(--tw-surface-panel)] shadow-xl`,children:[(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-[var(--tw-border)] px-5 py-3.5`,children:[(0,Z.jsxs)(i,{className:`truncate text-base font-semibold text-[var(--tw-label-primary)]`,children:[`安装依赖 · `,n.name]}),(0,Z.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-[11px] text-[var(--tw-label-tertiary)]`,children:n.dir})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto px-5 py-4`,children:(0,Z.jsx)(En,{projectId:n.id,plan:_,note:n.setupNote??``,showTitle:!1,onStatusChange:g})}),(0,Z.jsx)(`div`,{className:`flex shrink-0 justify-end border-t border-[var(--tw-border)] px-5 py-3`,children:(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-8 items-center rounded-lg border border-[var(--tw-border)] px-3 text-sm text-[var(--tw-label-secondary)] transition-colors hover:bg-[var(--tw-session-hover-bg)] hover:text-[var(--tw-label-primary)]`,onClick:()=>{p(!1),g()},children:`关闭`})})]})})]}),m?(0,Z.jsx)(On,{project:n,onClose:()=>{h(!1),g()},onSetupFinished:g}):null]})}var Rp=`__routine__`;function zp(e){let t=Kn(),n=Kn();return{title:``,status:e===`todo`?Nn(t,n)??`in_progress`:`pool`,statusManual:!1,priority:``,taskId:``,linkedTask:``,startDate:t,dueDate:n,note:``}}function Bp(e,t){let n=Array.isArray(t)?t:[],r=[];for(let t of n){if(!t||typeof t!=`object`)continue;let n=t,i=typeof n.title==`string`?n.title.trim():``;if(!i)continue;let a=e===`todo`?nr:Zn,o=e===`todo`?zn:Qn,s=zp(e),c=typeof n.status==`string`&&a.includes(n.status),l=c?n.status:e===`todo`?s.status:`pool`;r.push({...s,title:i,status:l,statusManual:e===`todo`&&c,priority:typeof n.priority==`string`&&o.includes(n.priority)?n.priority:``,taskId:typeof n.taskId==`string`?n.taskId.trim():``,linkedTask:typeof n.linkedTask==`string`?n.linkedTask.trim():``,startDate:typeof n.startDate==`string`?n.startDate.trim().slice(0,10):s.startDate,dueDate:typeof n.dueDate==`string`?n.dueDate.trim().slice(0,10):s.dueDate,note:typeof n.note==`string`?n.note.trim():``})}return r}function Vp(e,t){return t.map(t=>{let n={title:t.title.trim(),status:t.status,priority:t.priority,startDate:t.startDate,dueDate:t.dueDate,note:t.note};return e===`todo`&&(n.taskId=t.taskId,n.linkedTask=t.linkedTask,n.statusManual=!!t.statusManual),n})}var Hp=`text-[11px] font-medium text-stone-500`,Up=`h-9 w-full rounded-lg border border-stone-200 px-2.5 text-[13px] text-stone-800 outline-none focus:border-[#4176e6]`;function Wp(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?`${t[1]}/${t[2]}/${t[3]}`:``}function Gp(e){return(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:e.label}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.children})]})}function Kp(e){return(0,Z.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:e.label}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.children})]})}function qp(e){let{startDate:t,dueDate:n}=e,r=n||t,i=`h-7 rounded-md px-1.5 text-[12px] text-stone-700 tabular-nums transition-colors hover:bg-stone-100`;return(0,Z.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`日期`}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-0.5`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(ke,{value:t,ariaLabel:`开始日期`,placeholder:`开始日期`,clearable:!1,className:i,onChange:t=>{t&&e.onChange({startDate:t,dueDate:t>r?t:r})}})}),(0,Z.jsx)(`span`,{className:`shrink-0 px-0.5 text-[11px] text-stone-300`,"aria-hidden":!0,children:`~`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(ke,{value:n,ariaLabel:`截止日期`,placeholder:`截止日期`,clearable:!1,className:i,onChange:n=>{n&&e.onChange({startDate:n<t?n:t,dueDate:n})}})})]})]})}function Jp(e){let[t,n]=(0,U.useState)(()=>e.items),[r,i]=(0,U.useState)(0),[a,o]=(0,U.useState)([]);(0,U.useEffect)(()=>{n(e.items),i(0)},[e.items]);let s=e.kind===`todo`,c=!!e.quick&&s,l=s&&e.tasksOn!==!1,u=s&&!c&&l,d=s?`待办`:`任务`,f=s?`待办事项`:`任务管理`;(0,U.useEffect)(()=>{if(!l)return;let e=!0;return $n().then(t=>{e&&o(t)}).catch(()=>{}),()=>{e=!1}},[l]);let p=s?nr:Zn,m=s?zn:Qn,h=(0,U.useMemo)(()=>p.map(e=>({value:e,label:s?Vn[e]:Gn[e]})),[s,p]),g=(0,U.useMemo)(()=>[...m.map(e=>({value:e,label:s?er[e]:Yn[e]}))],[s,m]),_=(0,U.useMemo)(()=>[{value:``,label:`不关联`},...a.filter(e=>e.status!==`closed`&&e.status!==`cancelled`).map(e=>({value:e.id,label:e.title}))],[a]),v=(0,U.useMemo)(()=>!!Fl(a),[a]),ee=(0,U.useMemo)(()=>{let e=new Set(t.map(e=>e.taskId).filter(Boolean));return[{value:``,label:`不关联`},...v?[]:[{value:Rp,label:`${Nl}(确认后自动创建)`}],...a.filter(t=>e.has(t.id)||t.status!==`closed`&&t.status!==`cancelled`).map(e=>({value:e.id,label:e.title}))]},[t,a,v]);function y(e){return e.taskId&&a.some(t=>t.id===e.taskId)?e.taskId:!v&&e.linkedTask.trim()===`日常待办`?Rp:``}function te(e,t){if(t===Rp){b(e,{taskId:``,linkedTask:Nl});return}let n=a.find(e=>e.id===t);b(e,{taskId:n?.id??``,linkedTask:n?.title??``,...n?{priority:n.priority}:{}})}function b(e,t){n(n=>n.map((n,r)=>{if(r!==e)return n;let i={...n,...t};if(!s)return i;if(`status`in t&&!(`startDate`in t||`dueDate`in t))i.statusManual=!0;else if((`startDate`in t||`dueDate`in t)&&!i.statusManual&&!Mn(i.status)){let e=Nn(i.startDate,i.dueDate);e&&(i.status=e)}return i.dueDate&&i.dueDate<Kn()&&!Mn(i.status)&&(i.status=`overdue`,i.statusManual=!1),i}))}function x(e,n){let r=t[e],i=a.find(e=>e.id===n);i?b(e,{taskId:i.id,linkedTask:i.title,startDate:i.startDate||r?.startDate||``,dueDate:i.dueDate||r?.dueDate||``,priority:r?.priority||i.priority||``}):b(e,{taskId:``,linkedTask:``})}function S(e){n(t=>t.filter((t,n)=>n!==e))}let C=t.length>0&&t.every(e=>!!e.title.trim()),w=u&&r>=1,T=c&&t.some(e=>!e.taskId.trim()&&e.linkedTask.trim()===`日常待办`)&&!v,E=w?`所属任务的日期与紧急程度已带到第一页,可回去再调`:c?T?e.quickNote??`确认后会自动创建任务「日常待办」并关联`:`状态 / 所属任务 / 日期已填好(日期可点开改),确认后写入「待办事项」`:`确认后才会写入「${f}」`;return(0,Z.jsxs)(`div`,{className:[`tw-create-card tw-create-card-anim mb-2 flex max-h-[min(62vh,560px)] flex-col overflow-hidden rounded-2xl border border-stone-200 bg-white shadow-[0_6px_24px_rgba(15,23,42,0.08)]`,e.closing?`is-closing`:``].filter(Boolean).join(` `),children:[(0,Z.jsxs)(`div`,{className:`shrink-0 px-5 pt-4`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 text-[11px] leading-4 text-stone-400`,children:[(0,Z.jsxs)(`span`,{children:[`新增 `,t.length,` 条`,d]}),u?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-stone-300`,children:`·`}),(0,Z.jsxs)(`span`,{className:`tabular-nums`,children:[`第 `,r+1,` / 2 步`]})]}):null]}),(0,Z.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:w?`关联任务`:r===0?`确认内容后再添加到${f}`:f})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-3`,children:(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[t.map((e,n)=>{let r=a.find(t=>t.id===e.taskId);return(0,Z.jsx)(`div`,{className:`rounded-xl border border-stone-200 bg-stone-50/40 p-3`,children:c?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(`input`,{value:e.title,onChange:e=>b(n,{title:e.target.value}),placeholder:`待办名称`,className:`${Up} bg-white`,autoFocus:n===0}),t.length>1?(0,Z.jsx)(`button`,{type:`button`,onClick:()=>S(n),"aria-label":`移除这一条`,className:`h-9 shrink-0 rounded-lg px-2 text-[12px] text-stone-400 hover:bg-white hover:text-red-600`,children:`移除`}):null]}),(0,Z.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded-lg border border-stone-200 bg-white px-2.5 py-2`,children:[(0,Z.jsx)(Kp,{label:`状态`,children:Vn[e.status]??`进行中`}),l?(0,Z.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`所属任务`}),a.length||!v?(0,Z.jsx)(I,{flat:!0,ariaLabel:`所属任务`,menuMatchTrigger:!1,menuMinWidth:200,options:ee,value:y(e),onChange:e=>te(n,e),className:`min-w-0`,triggerClassName:`h-7 gap-1 rounded-md border-0 bg-transparent pl-0 pr-0.5 text-[12px] hover:bg-stone-50`}):(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.linkedTask||`未关联`})]}):null,(0,Z.jsx)(qp,{startDate:e.startDate,dueDate:e.dueDate,onChange:e=>b(n,e)})]})]}):w?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:Hp,children:`所属任务`}),a.length?(0,Z.jsx)(I,{flat:!0,ariaLabel:`所属任务`,options:_,value:e.taskId,onChange:e=>x(n,e),className:`w-full`}):(0,Z.jsx)(`span`,{className:`flex h-9 items-center rounded-lg border border-stone-200 bg-white px-2 text-[13px] text-stone-400`,children:`任务管理里还没有任务,可稍后到任务管理关联`})]}),r?(0,Z.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded-lg border border-stone-200 bg-white px-2.5 py-2`,children:[(0,Z.jsx)(Gp,{label:`任务名称`,children:r.title}),(0,Z.jsx)(Gp,{label:`状态`,children:Gn[r.status]??r.status}),(0,Z.jsx)(Gp,{label:`紧急程度`,children:r.priority?Yn[r.priority]:`未选择`}),(0,Z.jsx)(Gp,{label:`开始日期`,children:Wp(r.startDate)||`未设置`}),(0,Z.jsx)(Gp,{label:`结束日期`,children:Wp(r.dueDate)||`未设置`})]}):(0,Z.jsx)(`p`,{className:`mt-2 text-[11px] leading-4 text-stone-400`,children:`选中任务后,它的开始 / 结束日期与紧急程度会自动带到第一页。`})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(`input`,{value:e.title,onChange:e=>b(n,{title:e.target.value}),placeholder:s?`待办名称`:`任务名称`,className:`${Up} bg-white`,autoFocus:n===0}),t.length>1?(0,Z.jsx)(`button`,{type:`button`,onClick:()=>S(n),"aria-label":`移除这一条`,className:`h-9 shrink-0 rounded-lg px-2 text-[12px] text-stone-400 hover:bg-white hover:text-red-600`,children:`移除`}):null]}),(0,Z.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2`,children:[(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:Hp,children:`状态`}),(0,Z.jsx)(I,{flat:!0,ariaLabel:s?`待办状态`:`任务状态`,options:h,value:e.status,onChange:e=>b(n,{status:e}),className:`w-full`})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:Hp,children:`紧急程度`}),(0,Z.jsx)(I,{flat:!0,ariaLabel:`紧急程度`,options:g,value:e.priority,onChange:e=>b(n,{priority:e}),className:`w-full`,renderTrigger:()=>(0,Z.jsx)(`span`,{className:`truncate ${e.priority?`text-stone-800`:`text-stone-400`}`,children:e.priority?s?er[e.priority]:Yn[e.priority]:`未选择`})})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:Hp,children:`开始日期`}),(0,Z.jsx)(ke,{value:e.startDate,onChange:e=>b(n,{startDate:e}),placeholder:`选择日期`,className:`h-9 rounded-lg border border-stone-200 bg-white px-2 text-[13px] tabular-nums`})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:Hp,children:`截止日期`}),(0,Z.jsx)(ke,{value:e.dueDate,onChange:e=>b(n,{dueDate:e}),placeholder:`选择日期`,className:`h-9 rounded-lg border border-stone-200 bg-white px-2 text-[13px] tabular-nums`})]})]}),(0,Z.jsxs)(`label`,{className:`mt-2 flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:Hp,children:`备注`}),(0,Z.jsx)(`input`,{value:e.note,onChange:e=>b(n,{note:e.target.value}),placeholder:`备注(可选)`,className:`${Up} bg-white`})]})]})},n)}),t.length?null:(0,Z.jsx)(`p`,{className:`py-4 text-center text-[12px] text-stone-400`,children:`内容已清空,点「取消」放弃这次新增。`})]})}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-t border-stone-100 px-5 py-3`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[11px] text-stone-400`,children:E}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:w?()=>i(0):e.onCancel,className:`h-8 rounded-lg px-3 text-[12px] text-stone-600 outline-none hover:bg-stone-100`,children:w?`上一步`:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!w&&!C,onClick:()=>{u&&r===0?i(1):e.onConfirm(t)},className:`h-8 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4] disabled:cursor-not-allowed disabled:bg-stone-300`,children:u&&r===0?`下一步`:e.manual?`提交`:`确认新增`})]})]})]})}function Yp(e,t,n){let r=e;if(n.skillContext&&(r+=`\n\n本次用户选择的技能(不改变平台工具权限):\n${n.skillContext}`),n.knowledge&&(r=`${r}\n\n${lf}`),n.fs&&(r=`${r}\n\n${dn}\n\n${Zc}\n\n${$l}\n\n${Ni}\n\n${ki}`),n.bash&&(r=`${r}\n\n${pr}`),n.pwsh&&(r=`${r}\n\n${mr}`),n.web&&(r=`${r}\n\n${lr}`),n.memory&&(r=`${r}\n\n${Lr}`),n.interact&&(r=`${r}\n\n${uu}`),n.todos&&(r=`${r}\n\n${wl}`),n.tasks&&(r=`${r}\n\n${Bl}`),n.projects&&(r=`${r}\n\n${tl}`),n.iterations&&(r=`${r}\n\n${nl}`),n.pmRequirements&&(r=`${r}\n\n${rl}`),n.bugs&&(r=`${r}\n\n${il}`),n.planPhase===`planning`&&(r=`${r}\n\n${vu}`),n.planPhase===`approved`&&(r=`${r}\n\n${yu}`),n.goalEnabled){r=`${r}\n\n${Pu}`;let e=Ru(n.goal);e&&(r=`${r}\n\n【当前会话目标】${e}`)}n.scheduleEnabled&&(r=`${r}\n\n${td}`),n.subagentEnabled&&(r=`${r}\n\n${bd}`),n.workflowEnabled&&(r=`${r}\n\n${Qd}`),n.mcpEnabled&&(r=`${r}\n\n${zr}`);let i=n.memory?t.slice(-10):t;return[{role:`system`,content:r},...i]}function Xp(e){if(!/(?:^|[\s\n])\/$/.test(e))return null;let t=e.lastIndexOf(`/`);return t<0?null:{from:t}}function Zp(e){let t=/(?:^|[\s\n])@([^\s@]*)$/.exec(e);if(!t)return null;let n=e.lastIndexOf(`@`);return n<0?null:{from:n,query:t[1]??``}}function Qp(e){let t=/\s*(?:[((](?:recommended|推荐)[))])\s*$/i;return t.test(e)?{label:e.replace(t,``),recommended:!0}:{label:e,recommended:!1}}var $p=Wr,em=5,tm=[`image/png`,`image/jpeg`,`image/jpg`,`image/webp`,`image/gif`],nm=[`dialog`,`thread`,`todos`,`memory`],rm=`chat.tab`;function im(e){let t=[];if(e.content&&t.push(e.content),e.refs?.length){let n=e.refs.filter(e=>e.collection!==`workspace`),r=e.refs.filter(e=>e.collection===`workspace`);if(n.length){let e=n.filter(e=>e.collection===`knowledge`||e.collection===`templates`),r=n.filter(e=>e.collection===`cases`||e.collection===`testReports`);if(e.length){let n=e.map(e=>`- ${e.path} 《${e.title}》(${e.category} · ${sf(e.format)})`);t.push(`引用项目文档(请使用 kb_read 读取):\n${n.join(`
253
+ `)}`)}if(r.length){let e=r.map(e=>`- ${e.collection}/${e.path} 《${e.title}》(${e.category})`);t.push(`引用管理文档(路径已给出,正文可能已在上文):\n${e.join(`
254
+ `)}`)}}if(r.length){let e=r.map(e=>`- ${e.path} 《${e.title}》(${e.format===`dir`?`文件夹`:`文件`})`);t.push(`引用工作区路径(请使用 fs_list / fs_read):\n${e.join(`
255
+ `)}`)}}return e.attachments?.length&&t.push(e.attachments.map(e=>`附件《${e.name}》:\n\`\`\`\`\n${e.content}\n\`\`\`\``).join(`
256
+
257
+ `)),t.join(`
258
+
259
+ `)}function am(e,t){let n=im(e),r=t?.supportsVision===!0;if(!e.images?.length||!r){if(e.images?.length&&!r){let t=`(当前模型未声明支持视觉,已忽略图片:${e.images.map(e=>e.name||`image`).join(`, `)})`;return n?`${n}\n\n${t}`:t}return n}let i=[];n?i.push({type:`text`,text:n}):i.push({type:`text`,text:`请查看图片。`});for(let t of e.images)i.push({type:`image_url`,image_url:{url:t.dataUrl}});return i}function om(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result??``)),r.onerror=()=>n(Error(`读取图片失败`)),r.readAsDataURL(e)})}async function sm(e){if(!tm.includes(e.type)&&!/\.(png|jpe?g|webp|gif)$/i.test(e.name))throw Error(`${e.name||`图片`}:不支持的格式`);if(e.size>10485760)throw Error(`${e.name||`图片`}:超过 ${Math.round(Bf/1024/1024)} MB`);let t=await om(e);if(!t.startsWith(`data:image/`))throw Error(`无法识别为图片`);return{id:`img_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`,name:e.name||`paste-${new Date().toISOString().slice(11,19).replace(/:/g,``)}.png`,size:e.size,mime:e.type||`image/png`,dataUrl:t}}function cm(e,t){return e.length+t.length}var lm=[{value:`low`,label:`Low`,desc:`响应更快,适合简单问答`},{value:`high`,label:`High`,desc:`质量与速度均衡(默认)`},{value:`max`,label:`Max`,desc:`最深推理,适合复杂分析`}],um=[{value:`readonly`,label:`仅可查看`},{value:`readwrite`,label:`工作区内修改`},{value:`full`,label:`完全权限`}];function dm(e){return e===`present`?`交付文件`:e===`todo_write`?`待办`:e.startsWith(`todo_`)?`待办事项`:e===`ask_user_question`?`向用户提问`:e===`bash`?`Bash`:e===`pwsh`?`PowerShell`:e.startsWith(`bash_session_`)||e.startsWith(`pwsh_session_`)?`持久终端`:e.startsWith(`working_directory_`)?`工作目录`:e.startsWith(`skill_`)?`Skill`:e.startsWith(`workspace_changes_`)?`工作区变更`:e===`load_workspace_dependencies`?`工作区依赖`:e===`office_to_pdf`?`Office转PDF`:e===`submit_plan`?`提交计划`:e===`ui_plan_steps`?`写入步骤计划`:e.startsWith(`goal_`)?`会话目标`:e.startsWith(`schedule_`)?`定时提醒`:e===`list_agents`||e===`spawn_subagent`||e===`fork_subagent`||e.startsWith(`subagent_`)?`子代理`:e.startsWith(`mcp__`)?`MCP`:e===`workflow`?`工作流`:e===`job_list`?`任务列表`:e===`job_output`?`任务输出`:e===`job_kill`?`终止任务`:e===`web_search`?Qt(`tool.kind.webSearch`):e===`web_fetch`?Qt(`tool.kind.webFetch`):e.startsWith(`kb_`)?Qt(`tool.kind.kb`):e.startsWith(`fs_`)?Qt(`tool.kind.fs`):e.startsWith(`memory_`)?Qt(`tool.kind.memory`):e}function fm(e){let t=String(e??``).trim();if(!t)return`请求失败`;if(/service_unavailable|too busy|瞬时繁忙|服务繁忙/i.test(t))return`模型服务瞬时繁忙,请稍后重试`;try{let e=JSON.parse(t),n=e?.error??e;if(n&&typeof n==`object`){let e=`${n.message||``} ${n.code||``} ${n.type||``}`;if(/service_unavailable|too busy/i.test(e))return`模型服务瞬时繁忙,请稍后重试`;if(typeof n.message==`string`&&n.message.trim())return n.message.trim()}}catch{}return t.length>280?`${t.slice(0,280)}…`:t}function pm(e){return e===`present`?`fs`:e===`todo_write`||e.startsWith(`todo_`)||e===`ask_user_question`||e===`bash`||e===`pwsh`||e.startsWith(`bash_session_`)||e.startsWith(`pwsh_session_`)||e.startsWith(`working_directory_`)||e.startsWith(`skill_`)||e.startsWith(`workspace_changes_`)||e===`load_workspace_dependencies`||e===`office_to_pdf`||e===`submit_plan`||e===`ui_plan_steps`||e.startsWith(`goal_`)||e.startsWith(`schedule_`)||e===`list_agents`||e===`spawn_subagent`||e===`fork_subagent`||e.startsWith(`subagent_`)||e===`workflow`||e.startsWith(`job_`)?`tool`:e===`web_search`?`web_search`:e===`web_fetch`?`web_fetch`:e.startsWith(`fs_`)?`fs`:e.startsWith(`kb_`)?`kb`:e.startsWith(`memory_`)?`memory`:`tool`}function mm({kind:e,status:t}){let n=t===`error`?`w-3.5 h-3.5 shrink-0 text-red-500`:t===`running`?`w-3.5 h-3.5 shrink-0 text-stone-500`:`w-3.5 h-3.5 shrink-0 text-stone-400`;return t===`running`&&e===`thinking`?(0,Z.jsx)(`span`,{className:`w-3.5 h-3.5 shrink-0 rounded-full border-2 border-purple-400 border-t-transparent animate-spin`}):e===`thinking`?(0,Z.jsxs)($,{className:n,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,Z.jsx)(`path`,{d:`M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4`})]}):e===`web_search`||e===`web_fetch`?(0,Z.jsxs)($,{className:n,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Z.jsx)(`path`,{d:`M2 12h20`}),(0,Z.jsx)(`path`,{d:`M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z`})]}):e===`fs`||e===`kb`?(0,Z.jsxs)($,{className:n,children:[(0,Z.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Z.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}):e===`memory`?(0,Z.jsx)($,{className:n,children:(0,Z.jsx)(`path`,{d:`M12 2a4 4 0 0 1 4 4v2h2a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2V6a4 4 0 0 1 4-4Z`})}):(0,Z.jsx)($,{className:n,children:(0,Z.jsx)(`path`,{d:`m12 3 1.9 5.8H20l-4.9 3.6 1.9 5.8L12 14.6 7.1 18.2l1.9-5.8L4 8.8h6.1Z`})})}function hm(e,t){if(!t)return``;if(e.startsWith(`web_`))return xr(e,t);if(e===`present`)try{let e=(JSON.parse(t).files??[]).map(e=>e.path).filter(Boolean);return e.slice(0,3).join(`, `)+(e.length>3?`…`:``)}catch{return``}try{let n=JSON.parse(t);if(e===`submit_plan`){let e=typeof n.title==`string`?n.title.trim():``;return e.length>60?`${e.slice(0,60)}…`:e}if(e===`ui_plan_steps`){let e=Array.isArray(n.steps)?n.steps.length:0;return[typeof n.title==`string`?n.title.trim():``,e?`${e} 步`:``].filter(Boolean).join(` · `)}if(e===`bash`||e===`pwsh`){let e=typeof n.command==`string`?n.command.trim():``,t=n.background===!0?` [bg]`:``;return`${e.length>80?`${e.slice(0,80)}…`:e}${t}`}if(e.startsWith(`bash_session_`)||e.startsWith(`pwsh_session_`)){let e=typeof n.sessionId==`string`?n.sessionId.trim():``,t=typeof n.command==`string`?n.command.trim():``;return[e,t.length>48?`${t.slice(0,48)}…`:t].filter(Boolean).join(` · `)}if(e.startsWith(`working_directory_`)){let e=typeof n.path==`string`?n.path.trim():``;return[typeof n.id==`string`?n.id.trim():``,e].filter(Boolean).join(` · `)}if(e.startsWith(`skill_`))return[typeof n.name==`string`?n.name.trim():``,typeof n.path==`string`?n.path.trim():``].filter(Boolean).join(` · `);if(e.startsWith(`workspace_changes_`))return``;if(e.startsWith(`job_`))return typeof n.jobId==`string`?n.jobId.trim():``;if(e.startsWith(`schedule_`)){let e=typeof n.text==`string`?n.text.trim():``,t=typeof n.id==`string`?n.id.trim():``,r=typeof n.dueAt==`string`?n.dueAt.trim():``,i=typeof n.delayMinutes==`number`&&Number.isFinite(n.delayMinutes)?`+${n.delayMinutes}m`:``;return[e,t,r||i].filter(Boolean).join(` · `)}if(e===`list_agents`||e===`spawn_subagent`||e===`fork_subagent`||e.startsWith(`subagent_`)){let t=typeof n.agent==`string`?n.agent.trim():``,r=typeof n.prompt==`string`?n.prompt.trim():``,i=typeof n.id==`string`?n.id.trim():``,a=r.length>48?`${r.slice(0,48)}…`:r;return[e===`fork_subagent`?`fork`:``,t,i,a].filter(Boolean).join(` · `)}if(e===`workflow`){let e=n.meta;return(typeof e?.name==`string`?e.name.trim():``)||`workflow`}if(e===`fs_glob`||e===`fs_grep`){let e=typeof n.pattern==`string`?n.pattern.trim():``;return[e,typeof n.path==`string`?n.path.trim():``].filter(Boolean).join(` @ `)||e}if(typeof n.path==`string`&&n.path.trim())return n.path.trim();if(typeof n.query==`string`&&n.query.trim())return n.query.trim()}catch{}return``}function gm(e){let t=e.indexOf(`
260
+ `);return(t===-1?e:e.slice(0,t)).trim()}function _m({text:e,live:t}){let n=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(!t)return;let e=n.current;e&&(e.scrollTop=e.scrollHeight)},[e,t]),(0,Z.jsx)(`div`,{ref:n,className:`mt-1.5 mb-2 pl-5.5 text-[13px] leading-5 text-stone-500 whitespace-pre-wrap max-h-64 overflow-y-auto`,children:e})}function vm(e){let t=``,n=0,r=/\r?\n(?:[\t ]*\r?\n)+/g;for(;;){let i=r.exec(e),a=i===null?e.length:i.index+i[0].indexOf(`
261
+ `),o=e.indexOf(`
262
+ `,n);if(o!==-1&&o<=a){let r=e.slice(n,o).trim();r!==``&&(t=r)}if(i===null)return t;n=i.index+i[0].length}}function ym(e,t,n,r){return e===`concise`?r===`running`?Qt(`tool.running`):null:e===`standard`?Qt(r===`running`?`tool.callingKind`:`tool.doneKind`,{kind:t}):Qt(e===`detailed`?r===`running`?`tool.callingNamed`:`tool.doneNamed`:r===`running`?`tool.callingFull`:`tool.doneFull`,{kind:t,name:n})}function $({className:e=``,children:t}){return(0,Z.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:t})}var bm=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.jsx)(`path`,{d:`m6 9 6 6 6-6`})}),xm=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.jsx)(`path`,{d:`m9 18 6-6-6-6`})}),Sm=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.jsx)(`path`,{d:`M20 6 9 17l-5-5`})}),Cm=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`}),(0,Z.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),wm=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`}),(0,Z.jsx)(`path`,{d:`M3 5v14a9 3 0 0 0 18 0V5`}),(0,Z.jsx)(`path`,{d:`M3 12a9 3 0 0 0 18 0`})]}),Tm=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`m12 14 4-4`}),(0,Z.jsx)(`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`})]}),Em=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Z.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}),Dm=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.jsx)(`path`,{d:`m16.5 9.4-7.07 7.07a3 3 0 0 1-4.24-4.24l7.07-7.07a2 2 0 1 1 2.83 2.83L8.02 14.1a1 1 0 0 1-1.41-1.41l7.07-7.07`})}),Om=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`m5 12 7-7 7 7`}),(0,Z.jsx)(`path`,{d:`M12 19V5`})]}),km=({className:e=``,open:t=!1})=>(0,Z.jsx)($,{className:e,children:t?(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsx)(`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.55 6A2 2 0 0 1 18.45 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.69.9H18a2 2 0 0 1 2 2v2`})}):(0,Z.jsx)(`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9l-.81-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`})}),Am=({className:e=``,open:t=!1})=>(0,Z.jsx)(`svg`,{className:`${e} tw-arrow ${t?`is-open`:``}`,viewBox:`0 0 12 12`,fill:`currentColor`,"aria-hidden":!0,children:(0,Z.jsx)(`path`,{d:`M4.2 2.4a.75.75 0 0 1 1.2-.57l4.2 3.35a.75.75 0 0 1 0 1.14l-4.2 3.35A.75.75 0 0 1 4.2 9.1V2.9Z`})}),jm=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,Z.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),Mm=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Z.jsx)(`path`,{d:`M12 8v8`}),(0,Z.jsx)(`path`,{d:`M8 12h8`})]}),Nm=({className:e=``,filled:t=!1})=>(0,Z.jsx)($,{className:e,children:t?(0,Z.jsx)(`path`,{fill:`currentColor`,stroke:`none`,d:`M12 2a3 3 0 0 1 3 3v3.5l2.5 2.5V13h-3.5V20l-1.5 2-1.5-2v-7H7.5v-2L10 8.5V5a3 3 0 0 1 3-3Z`}):(0,Z.jsx)(`path`,{d:`M12 17v5M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16h14v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6a2 2 0 0 0-2-2h-2a2 2 0 0 0-2 2z`})}),Pm=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Z.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Z.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]}),Fm=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`M4 8h16v11a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V8Z`}),(0,Z.jsx)(`path`,{d:`M8 8V5a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v3`}),(0,Z.jsx)(`path`,{d:`M10 12h4`})]}),Im=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`M12 22v-5`}),(0,Z.jsx)(`path`,{d:`M9 8V2`}),(0,Z.jsx)(`path`,{d:`M15 8V2`}),(0,Z.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});function Lm(e){let t=Math.max(0,Math.floor((Date.now()-e)/1e3));if(t<60)return`刚刚`;let n=Math.floor(t/60);if(n<60)return`${n}分钟`;let r=Math.floor(n/60);if(r<24)return`${r}小时`;let i=Math.floor(r/24);if(i<30)return`${i}天`;let a=Math.floor(i/30);return a<12?`${a}个月`:`${Math.floor(a/12)}年`}function Rm(e){let t=Lm(e);return t===`刚刚`?`刚刚`:t.endsWith(`前`)?t:`${t}前`}function zm({open:e,onToggle:t,onRename:n,onDelete:r}){let i=(0,U.useRef)(null);return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(`button`,{ref:i,type:`button`,"aria-label":`更多`,onClick:e=>{e.stopPropagation(),t()},className:`w-6 h-6 flex items-center justify-center rounded text-(--tw-label-tertiary) hover:text-(--tw-label-primary) hover:bg-(--tw-session-hover-bg)`,children:(0,Z.jsx)(Pm,{className:`w-3.5 h-3.5`})}),(0,Z.jsxs)(Bm,{open:e,anchorRef:i,dataAttr:`data-ws-menu`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:e=>{e.stopPropagation(),n()},children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M12 20h9`}),(0,Z.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),r?(0,Z.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:e=>{e.stopPropagation(),r()},children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M3 6h18`}),(0,Z.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Z.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`删除工作区`]}):null]})]})}function Bm({open:e,anchorRef:t,dataAttr:n,children:r}){let[i,a]=(0,U.useState)(null);return(0,U.useLayoutEffect)(()=>{if(!e){a(null);return}let n=()=>{let e=t.current;if(!e)return;let n=e.getBoundingClientRect(),r=n.bottom+200>window.innerHeight-8,i=Math.max(8,Math.min(n.left,window.innerWidth-160-8));a({top:r?n.top-4:n.bottom+4,left:i,openUp:r})};return n(),window.addEventListener(`scroll`,n,!0),window.addEventListener(`resize`,n),()=>{window.removeEventListener(`scroll`,n,!0),window.removeEventListener(`resize`,n)}},[e,t]),!e||!i||typeof document>`u`?null:(0,$r.createPortal)((0,Z.jsx)(`div`,{[n]:``,className:`tw-popover tw-popover-anim z-80 w-40 rounded-xl border border-stone-200 py-1 shadow-lg`,style:{position:`fixed`,top:i.top,left:i.left,transform:i.openUp?`translateY(-100%)`:void 0},children:r}),document.body)}function Vm({s:e,nested:t=!1,active:n,menuOpen:r,busy:i,exiting:a=!1,onOpen:o,onRename:s,onToggleMenu:c,onTogglePin:l,onToggleArchive:u,onExport:d,onFork:f,onRemove:p,onRestore:m}){let h=(0,U.useRef)(null),g=(0,U.useRef)(null),_=(0,U.useRef)(null),v=(0,U.useRef)(null),ee=(0,U.useRef)(null),y=(0,U.useRef)(null),[te,b]=(0,U.useState)(!1),[x,S]=(0,U.useState)(!1),[C,w]=(0,U.useState)(null);function T(){ee.current!=null&&(clearTimeout(ee.current),ee.current=null)}function E(){y.current!=null&&(clearTimeout(y.current),y.current=null)}function D(){E(),y.current=setTimeout(()=>{S(!1),T()},180)}function ne(){E(),T(),ee.current=setTimeout(()=>S(!0),1e3)}let re=e.uiAuto?wn(e.title):e.title.trim()||`新对话`,ie=re;(0,U.useLayoutEffect)(()=>{let e=_.current,t=v.current;if(!e||!t)return;let n=()=>{t.style.maxWidth=`none`,t.style.overflow=`visible`,t.style.display=`inline-block`;let n=t.scrollWidth;t.style.maxWidth=``,t.style.overflow=``,t.style.display=``;let r=e.clientWidth,i=n>r+1;b(i),i?t.style.setProperty(`--tw-marquee-shift`,`${Math.min(0,r-n-28)}px`):t.style.removeProperty(`--tw-marquee-shift`)};n();let r=typeof ResizeObserver<`u`?new ResizeObserver(n):null;return r?.observe(e),()=>r?.disconnect()},[re]),(0,U.useLayoutEffect)(()=>{if(!x||r){w(null);return}let e=()=>{let e=h.current;if(!e)return;let t=e.getBoundingClientRect();w({top:t.top+t.height/2,left:t.right+8})};return e(),window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[x,r,re]),(0,U.useEffect)(()=>{r&&(T(),E(),S(!1))},[r]);let ae=i?`生成中`:`空闲`,O=!!(e.archived||e.deleted);return(0,Z.jsxs)(`div`,{ref:h,className:`tw-session-row relative ${t?`is-nested`:``} ${n?`is-selected`:``} ${r?`is-menu-open`:``} ${i?`is-busy`:``} ${a?`is-exiting`:``} ${O&&!a?`opacity-50`:``}`,onMouseLeave:()=>{T(),D()},children:[i?(0,Z.jsx)(`span`,{className:`tw-session-busy-slot`,"data-hint":`生成中`,"aria-label":`生成中`,children:(0,Z.jsx)(`span`,{className:`tw-session-busy-dot`,"aria-hidden":!0})}):null,e.pinned&&!O?(0,Z.jsx)(`span`,{className:`tw-slot`,"aria-hidden":!0,children:(0,Z.jsx)(Nm,{filled:!0,className:`tw-pin-indicator w-3 h-3`})}):null,(0,Z.jsx)(`button`,{ref:_,type:`button`,onClick:o,onDoubleClick:s,onMouseEnter:()=>ne(),onMouseLeave:()=>{T(),D()},className:`tw-session-title text-left outline-none focus:outline-none focus-visible:outline-none ${te?`is-overflow`:``}`,children:(0,Z.jsx)(`span`,{ref:v,className:`tw-session-title-inner`,children:re})}),(0,Z.jsx)(`span`,{className:`tw-session-time pr-1`,children:Lm(e.updatedAt)}),(0,Z.jsxs)(`div`,{"data-session-menu":``,className:`tw-row-actions items-center gap-0.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(`button`,{ref:g,type:`button`,"aria-label":`更多`,onClick:c,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Z.jsx)(Pm,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(Bm,{open:r,anchorRef:g,dataAttr:`data-session-menu`,children:e.deleted?(0,Z.jsxs)(Z.Fragment,{children:[m?(0,Z.jsx)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:m,children:`恢复会话`}):null,(0,Z.jsx)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:p,children:`永久删除`})]}):(0,Z.jsxs)(Z.Fragment,{children:[!e.archived&&(0,Z.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:l,children:[(0,Z.jsx)(Nm,{filled:!!e.pinned,className:`w-3.5 h-3.5`}),e.pinned?`取消置顶`:`置顶会话`]}),(0,Z.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:s,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M12 20h9`}),(0,Z.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),(0,Z.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:u,children:[(0,Z.jsx)(Fm,{className:`w-3.5 h-3.5`}),e.archived?`取消归档`:`归档会话`]}),(0,Z.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:d,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,Z.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,Z.jsx)(`line`,{x1:`12`,x2:`12`,y1:`15`,y2:`3`})]}),`导出会话`]}),f&&!e.archived?(0,Z.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:f,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`circle`,{cx:`6`,cy:`6`,r:`2.5`}),(0,Z.jsx)(`circle`,{cx:`18`,cy:`6`,r:`2.5`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`18`,r:`2.5`}),(0,Z.jsx)(`path`,{d:`M8.2 7.2 10.5 15`}),(0,Z.jsx)(`path`,{d:`M15.8 7.2 13.5 15`})]}),`分叉会话`]}):null,e.archived?(0,Z.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:p,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M3 6h18`}),(0,Z.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Z.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`永久删除`]}):null]})})]}),!e.deleted&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":e.archived?`取消归档`:`归档会话`,"data-hint":e.archived?`取消归档`:`归档会话`,onClick:u,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Z.jsx)(Fm,{className:`w-3.5 h-3.5`})}),!e.archived&&!e.deleted&&(0,Z.jsx)(`button`,{type:`button`,"data-hint":e.pinned?`取消置顶`:`置顶`,onClick:l,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Z.jsx)(Nm,{filled:!!e.pinned,className:`w-3.5 h-3.5`})})]}),x&&!r&&C&&typeof document<`u`?(0,$r.createPortal)((0,Z.jsxs)(`div`,{className:`tw-session-preview`,role:`tooltip`,style:{position:`fixed`,top:C.top,left:C.left,transform:`translateY(-50%)`},onMouseEnter:()=>{T(),E(),S(!0)},onMouseLeave:()=>D(),children:[(0,Z.jsx)(`div`,{className:`tw-session-preview-title`,children:ie}),(0,Z.jsx)(`div`,{className:`tw-session-preview-meta`,children:Rm(e.updatedAt)}),(0,Z.jsx)(`div`,{className:`tw-session-preview-status ${i?`is-busy`:``}`,children:ae})]}),document.body):null]})}var Hm=`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`;function Um({level:e,className:t=``}){return(0,Z.jsxs)($,{className:t,children:[(0,Z.jsx)(`path`,{d:Hm}),e===`readonly`&&(0,Z.jsx)(`path`,{d:`m9 12 2 2 4-4`}),e===`readwrite`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`path`,{d:`M9 10h6`}),(0,Z.jsx)(`path`,{d:`M9 14h3`})]}),e===`full`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`path`,{d:`M12 8v4`}),(0,Z.jsx)(`path`,{d:`M12 16h.01`})]})]})}function Wm(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Gm(e){return`${e.toLocaleString(`en-US`)} tok`}function Km(e){let t=e/1e3;if(t<60)return`${Math.round(t*10)/10} 秒`;let n=Math.round(t);return`${Math.floor(n/60)} 分 ${n%60} 秒`}function qm(e){return e>=99.95?`100`:e>=10?String(Math.round(e)):e.toFixed(1)}function Jm(e){let t=0;for(let n of e)t+=/[\u4e00-\u9fff]/.test(n)?1:.25;return Math.max(1,Math.round(t))}function Ym(e){return e.uncachedTokens==null?e.cachedTokens==null?e.promptTokens:Math.max(0,e.promptTokens-e.cachedTokens):e.uncachedTokens}function Xm(e){return e?typeof e.completionTokens==`number`&&e.completionTokens>0?e.completionTokens:typeof e.totalTokens==`number`&&typeof e.promptTokens==`number`?Math.max(0,e.totalTokens-e.promptTokens):typeof e.completionTokens==`number`?Math.max(0,e.completionTokens):0:0}function Zm(e,t){return t<=0?null:e/t*100}function Qm(e){return e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function $m(e){let t=new Date(e),n=`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`;return t.toDateString()===new Date().toDateString()?n:`${t.getMonth()+1}/${t.getDate()} ${n}`}async function eh(e){try{return await navigator.clipboard.writeText(e),!0}catch{try{let t=document.createElement(`textarea`);t.value=e,t.style.cssText=`position:fixed;opacity:0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}}function th({text:e}){let[t,n]=(0,U.useState)(!1),r=(0,U.useRef)(null);(0,U.useEffect)(()=>()=>{r.current!==null&&window.clearTimeout(r.current)},[]);async function i(){t||await eh(e)&&(n(!0),r.current=window.setTimeout(()=>n(!1),1e3))}return(0,Z.jsx)(`button`,{type:`button`,onClick:i,"aria-label":t?`已复制`:`复制`,className:`tw-icon-btn tw-msg-action-btn inline-flex items-center justify-center rounded-md transition-colors`,children:t?(0,Z.jsx)(Sm,{className:`w-3.5 h-3.5 text-emerald-600`}):(0,Z.jsx)(Cm,{className:`w-3.5 h-3.5`})})}function nh({pct:e}){return(0,Z.jsxs)(`svg`,{className:`w-3.5 h-3.5 -rotate-90`,viewBox:`0 0 20 20`,"aria-hidden":`true`,children:[(0,Z.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`var(--color-stone-200)`,strokeWidth:`3`}),(0,Z.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`#4176e6`,strokeWidth:`3`,strokeLinecap:`round`,strokeDasharray:`${Math.max(e,1)/100*50.27} 50.27`})]})}function rh(){let[e,t]=(0,U.useState)(!1),n=(0,U.useRef)(null),r=(0,U.useRef)(null),[i,a]=(0,U.useState)(null);return(0,U.useEffect)(()=>{if(!e){a(null);return}let t=()=>{let e=n.current,t=r.current;if(!e||!t)return;let i=e.getBoundingClientRect(),o=t.getBoundingClientRect(),s=i.left+i.width/2-o.width/2;s=Math.max(12,Math.min(s,window.innerWidth-o.width-12));let c=i.top-o.height-8;c<12&&(c=i.bottom+8),a({position:`fixed`,left:s,top:c,visibility:`visible`})};a({position:`fixed`,left:0,top:0,visibility:`hidden`});let i=requestAnimationFrame(t);return window.addEventListener(`resize`,t),window.addEventListener(`scroll`,t,!0),()=>{cancelAnimationFrame(i),window.removeEventListener(`resize`,t),window.removeEventListener(`scroll`,t,!0)}},[e]),(0,U.useEffect)(()=>{if(!e)return;let i=e=>{e.key===`Escape`&&t(!1)},a=e=>{let i=e.target;n.current?.contains(i)||r.current?.contains(i)||t(!1)};return document.addEventListener(`keydown`,i),document.addEventListener(`click`,a,!0),()=>{document.removeEventListener(`keydown`,i),document.removeEventListener(`click`,a,!0)}},[e]),{open:e,setOpen:t,rootRef:n,panelRef:r,pos:i}}function ih({title:e,titleValue:t,icon:n,children:r}){return(0,Z.jsxs)(`div`,{className:`tw-popover w-[min(320px,calc(100vw-24px))] rounded-2xl border border-stone-200 p-3.5 shadow-xl text-left`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[n,(0,Z.jsx)(`span`,{className:`tw-popover-title font-medium text-stone-800`,children:e}),t!==void 0&&(0,Z.jsx)(`span`,{className:`tw-popover-muted ml-auto text-stone-500 tabular-nums`,children:t})]}),(0,Z.jsx)(`div`,{className:`mt-2.5 mb-2.5 border-t border-stone-100`}),r]})}function ah({rows:e}){return(0,Z.jsx)(`dl`,{className:`grid grid-cols-[1fr_auto] gap-x-6 gap-y-2 text-[13px]`,children:e.filter(e=>!e.hide).map(e=>(0,Z.jsxs)(`div`,{className:`contents`,children:[(0,Z.jsx)(`dt`,{className:`text-stone-500`,children:e.label}),(0,Z.jsx)(`dd`,{className:`text-stone-800 tabular-nums text-right`,children:e.value})]},e.label))})}function oh({label:e,icon:t,ariaLabel:n,title:r,titleValue:i,children:a,variant:o=`pill`}){let{open:s,setOpen:c,rootRef:l,panelRef:u,pos:d}=rh();return(0,Z.jsxs)(`span`,{ref:l,className:`relative inline-flex items-center`,children:[(0,Z.jsxs)(`button`,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":s,"aria-label":n,onClick:()=>c(!s),className:o===`ghost`?`tw-msg-action-meta inline-flex items-center gap-1 tabular-nums transition-colors ${s?`text-stone-600`:`text-stone-400 hover:text-stone-600`}`:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full transition-colors ${s?`bg-stone-200/70 text-stone-600`:`hover:bg-stone-200/60 hover:text-stone-600`}`,children:[t,(0,Z.jsx)(`span`,{className:`leading-none`,children:e})]}),s&&(0,$r.createPortal)((0,Z.jsx)(`div`,{ref:u,role:`dialog`,"aria-label":r,style:d??{position:`fixed`,left:0,top:0,visibility:`hidden`},className:`z-80`,children:(0,Z.jsx)(ih,{title:r,titleValue:i,icon:t,children:a})}),document.body)]})}function sh({messages:e,busy:t,onRestoreCheckpoint:n}){let[r,i]=(0,U.useState)(()=>new Set),a=(0,U.useMemo)(()=>Ei(e.map(e=>({role:e.role,content:typeof e.content==`string`?e.content:im(e),time:e.time}))),[e]);function o(e){i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return a.length?(0,Z.jsx)(`ol`,{className:`list-none m-0 p-0 w-full max-w-[min(64rem,100%)] mx-auto space-y-2`,children:a.map(e=>{let i=r.has(e.index),a=!!e.assistantText;return(0,Z.jsxs)(`li`,{className:`rounded-xl border bg-white shadow-sm overflow-hidden ${i?`border-[#4176e6]/35`:`border-stone-200`}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-1 px-3 py-2.5`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>o(e.index),"aria-expanded":i,className:`min-w-0 flex-1 text-left hover:bg-stone-50/80 rounded-lg -mx-1 px-1 py-0.5 transition-colors`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Z.jsxs)(`span`,{className:`text-[11px] font-medium text-stone-400 tabular-nums`,children:[`第 `,e.index,` 轮`]}),(0,Z.jsx)(bm,{className:`w-3.5 h-3.5 text-stone-400 ml-auto shrink-0 transition-transform ${i?`rotate-180`:``}`})]}),i?null:(0,Z.jsxs)(`div`,{className:`space-y-1 text-[13px] leading-5`,children:[(0,Z.jsxs)(`p`,{className:`m-0 text-stone-800 truncate`,children:[(0,Z.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`用户`}),e.userPreview]}),(0,Z.jsxs)(`p`,{className:`m-0 text-stone-600 truncate`,children:[(0,Z.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`助手`}),e.assistantPreview||`(待回复)`]})]})]}),n?(0,Z.jsx)(`button`,{type:`button`,disabled:t||!a,"data-hint":a?`截断到本轮末,填入续写并发送`:`待本轮助手回复完成后可从此处继续`,className:`shrink-0 mt-0.5 text-[11px] text-[#4176e6] hover:underline disabled:opacity-40 disabled:no-underline px-1 whitespace-nowrap`,onClick:()=>n(e.endMessageIndex,e.index),children:`从此处继续`}):null]}),i?(0,Z.jsxs)(`div`,{className:`px-3 pb-3 space-y-2.5 text-[13px] leading-5 border-t border-stone-100 pt-2.5`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`用户`}),(0,Z.jsx)(`div`,{className:`whitespace-pre-wrap break-words text-stone-800`,children:e.userText||`—`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`助手`}),e.assistantText?(0,Z.jsx)(Ks,{text:e.assistantText,className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`}):(0,Z.jsx)(`div`,{className:`text-stone-400`,children:`(待回复)`})]})]}):null]},e.index)})}):(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-stone-400`,children:`暂无回合(还没有用户/助手对话)`})}function ch({messages:e,model:t,systemPromptTokens:n,compact:r=!1}){let i=e.filter(e=>e.role===`assistant`&&e.usage);if(!i.length)return null;let a=i[i.length-1],o=e.filter(e=>e.role===`user`).length,s=i.length,c=i.reduce((e,t)=>e+(t.usage?.totalTokens??0),0),l=i.reduce((e,t)=>e+(t.usage?.promptTokens??0),0),u=i.reduce((e,t)=>e+(t.usage?.cachedTokens??0),0),d=i.reduce((e,t)=>e+(t.usage?Ym(t.usage):0),0),f=i.reduce((e,t)=>e+(t.usage?.cacheWriteTokens??0),0),p=i.reduce((e,t)=>e+Xm(t.usage),0),m=i.some(e=>e.usage?.cachedTokens!=null),h=m?Zm(u,l):null,g=i.reduce((e,t)=>e+(t.llmMs??0),0),_=i.reduce((e,t)=>e+(t.toolMs??0),0),v=i.map(e=>e.ttftMs).filter(e=>e!=null&&e>0),y=v.length?v.reduce((e,t)=>e+t,0)/v.length:0,te=i.reduce((e,t)=>t.llmMs==null||t.ttftMs==null?e:e+Math.max(0,t.llmMs-t.ttftMs),0),b=i.map(e=>e.tps).filter(e=>e!=null&&e>0),x=b.length?b.reduce((e,t)=>e+t,0)/b.length:void 0,S=te>200&&p>0?p/(te/1e3):x??(a.tps&&a.tps>0?a.tps:void 0),C=ee().contextWindow||(t?Bt[t]:void 0),w=a.usage?.promptTokens??0,T=C?Math.min(100,w/C*100):void 0,E=Math.min(n,w),D=Math.max(0,w-E);return(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-1 pt-2 text-xs text-stone-400 tabular-nums select-none ${r?`flex-wrap gap-y-1`:``}`,children:[(0,Z.jsx)(oh,{icon:(0,Z.jsx)(Tm,{className:`w-3.5 h-3.5`}),label:(0,Z.jsxs)(Z.Fragment,{children:[o,` 轮 `,s,` 步`,!r&&S?` · ${Math.round(S)} tok/s`:``]}),ariaLabel:`会话统计`,title:`会话统计`,children:(0,Z.jsx)(ah,{rows:[{label:`模型用时`,value:g>0?Km(g):`—`},{label:`工具调用用时`,value:_>0?Km(_):`—`},{label:`首 token 平均 (TTFT)`,value:v.length?Km(y):`—`},{label:`输出速度 (TPS)`,value:S?`${Math.round(S)} tok/s`:`—`}]})}),(0,Z.jsx)(oh,{icon:(0,Z.jsx)(wm,{className:`w-3.5 h-3.5`}),label:(0,Z.jsxs)(Z.Fragment,{children:[Wm(c),` tok`,!r&&h!=null?` · 缓存命中 ${qm(h)}%`:``]}),ariaLabel:`Token 用量`,title:`Token 用量`,titleValue:Gm(c),children:(0,Z.jsx)(ah,{rows:[{label:`缓存命中`,value:h==null?`—`:`${qm(h)}%`,hide:h==null},{label:`未缓存输入`,value:Gm(d)},{label:`缓存读取`,value:Gm(u),hide:!m},{label:`缓存写入`,value:Gm(f),hide:f<=0},{label:`输出`,value:Gm(p)}]})}),T!==void 0&&C&&(0,Z.jsxs)(oh,{icon:(0,Z.jsx)(nh,{pct:T}),label:`${qm(T)}%`,ariaLabel:`上下文占用`,title:`上下文已用 ${qm(T)}%`,titleValue:`~${Wm(w)} / ${Wm(C)}`,children:[(0,Z.jsxs)(`div`,{className:`h-2 rounded-full bg-stone-100 overflow-hidden flex mb-3`,children:[(0,Z.jsx)(`span`,{className:`h-full bg-stone-400`,style:{width:`${E/C*100}%`},"data-hint":`系统提示词`}),(0,Z.jsx)(`span`,{className:`h-full bg-[#4176e6]`,style:{width:`${D/C*100}%`},"data-hint":`对话消息`})]}),(0,Z.jsx)(ah,{rows:[{label:`系统提示词`,value:`~${Wm(E)}`},{label:`对话消息`,value:`~${Wm(D)}`}]}),(0,Z.jsx)(`p`,{className:`mt-2.5 text-[11px] leading-4 text-stone-400`,children:`分段为示意估算(API 不返回上下文拆分);总量以最近一轮 prompt_tokens 为准。`})]})]})}function lh({usage:e,model:t}){let n=e.cachedTokens==null?null:Zm(e.cachedTokens,e.promptTokens);return(0,Z.jsx)(oh,{variant:`ghost`,icon:(0,Z.jsx)(wm,{className:`w-3.5 h-3.5 shrink-0`}),label:(0,Z.jsxs)(Z.Fragment,{children:[`用量 `,Wm(e.totalTokens),` tok`]}),ariaLabel:`本轮用量`,title:`本轮用量`,titleValue:Gm(e.totalTokens),children:(0,Z.jsx)(ah,{rows:[{label:`提供方 / 模型`,value:t??`—`,hide:!t},{label:`缓存命中`,value:n==null?`—`:`${qm(n)}%`,hide:n==null},{label:`未缓存输入`,value:Gm(Ym(e))},{label:`缓存读取`,value:Gm(e.cachedTokens??0),hide:e.cachedTokens==null},{label:`缓存写入`,value:Gm(e.cacheWriteTokens??0),hide:!(e.cacheWriteTokens&&e.cacheWriteTokens>0)},{label:`输出`,value:Gm(e.completionTokens)}]})})}function uh({settings:e}){let[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)([]),[s,c]=(0,U.useState)(`idle`),l=(0,U.useRef)(null),u=(0,U.useRef)(0);if((0,U.useEffect)(()=>{if(!t)return;let e=()=>{n(!1),i(null)},r=t=>{l.current?.contains(t.target)||e()},a=t=>{t.key===`Escape`&&e()};return document.addEventListener(`mousedown`,r),document.addEventListener(`keydown`,a),()=>{document.removeEventListener(`mousedown`,r),document.removeEventListener(`keydown`,a)}},[t]),(0,U.useEffect)(()=>{if(!t||!e)return;let n=e.availableModels?.length?e.availableModels:[e.model];o(n),c(e.availableModels?.length?`ok`:`loading`);let r=++u.current;Lt(e.baseURL,e.apiKey).then(t=>{if(r!==u.current)return;let n=t.length?t:[e.model];o(n),c(`ok`),t.length&&x({availableModels:t})}).catch(()=>{r===u.current&&c(n.length>1?`ok`:`fail`)})},[t,e]),!e)return(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>S(`model`),className:`flex items-center gap-1 h-7 shrink-0 pl-2 pr-1 text-[13px] leading-5 font-medium text-stone-500 rounded-md hover:bg-stone-100 transition-colors`,children:[(0,Z.jsx)(`span`,{className:`whitespace-nowrap`,children:`配置模型`}),(0,Z.jsx)(bm,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`})]});let d=e.reasoningEffort??`high`,f=lm.find(e=>e.value===d)?.label??`High`;function p(e){x(e),n(!1),i(null)}let m=e=>`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-left text-[13px] transition-colors ${e?`bg-stone-100`:`hover:bg-stone-100`}`;return(0,Z.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{n(e=>!e),i(null)},className:`tw-composer-bar-model group flex items-center gap-1 h-7 shrink-0 pl-2 pr-1 text-[13px] leading-5 font-medium rounded-md outline-none focus:outline-none focus-visible:outline-none transition-colors ${t?`bg-stone-100`:`hover:bg-stone-100`}`,title:`${e.model} · ${f}`,"aria-label":`模型 ${e.model},推理 ${f}`,children:[(0,Z.jsx)(`span`,{className:`tw-composer-bar-model-name max-w-40 truncate text-stone-600`,children:e.model}),(0,Z.jsx)(`span`,{className:`tw-composer-bar-effort whitespace-nowrap text-stone-400`,children:f}),(0,Z.jsx)(bm,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${t?`rotate-180`:``}`})]}),t&&(0,Z.jsxs)(`div`,{className:`tw-popover tw-popover-anim absolute bottom-full right-0 mb-2 w-64 rounded-xl border border-stone-200 p-1 shadow-xl z-50`,children:[(0,Z.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`model`),onClick:()=>i(`model`),className:m(r===`model`),children:[(0,Z.jsx)(`span`,{className:`text-stone-700`,children:`模型`}),(0,Z.jsx)(`span`,{className:`ml-auto max-w-32 truncate text-stone-400`,children:e.model}),(0,Z.jsx)(xm,{className:`w-3.5 h-3.5 text-stone-400`})]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`effort`),onClick:()=>i(`effort`),className:m(r===`effort`),children:[(0,Z.jsx)(`span`,{className:`text-stone-700`,children:`推理等级`}),(0,Z.jsx)(`span`,{className:`ml-auto text-stone-400`,children:f}),(0,Z.jsx)(xm,{className:`w-3.5 h-3.5 text-stone-400`})]}),r===`model`&&(0,Z.jsxs)(`div`,{className:`tw-popover tw-popover-anim absolute right-full bottom-0 mr-1.5 w-64 max-h-72 overflow-y-auto rounded-xl border border-stone-200 p-1 shadow-xl`,children:[s===`loading`&&a.length<=1&&(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-stone-400`,children:`正在识别可用模型…`}),a.map(t=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>p({model:t}),className:m(!1),children:[(0,Z.jsx)(`span`,{className:`flex-1 truncate ${t===e.model?`text-stone-900 font-medium`:`text-stone-600`}`,children:t}),t===e.model&&(0,Z.jsx)(Sm,{className:`w-3.5 h-3.5 text-[#4176e6]`})]},t)),(0,Z.jsx)(`div`,{className:`mt-1 border-t border-stone-100 pt-1`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{n(!1),i(null),S(`model`)},className:`w-full px-3 py-1.5 rounded-lg text-left text-xs text-stone-400 hover:bg-stone-100`,children:s===`fail`?`识别失败,打开设置检查…`:a.length>1?`打开设置 · 模型…`:`打开设置识别可用模型…`})})]}),r===`effort`&&(0,Z.jsx)(`div`,{className:`tw-popover tw-popover-anim absolute right-full bottom-0 mr-1.5 w-60 rounded-xl border border-stone-200 p-1 shadow-xl`,children:lm.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>p({reasoningEffort:e.value}),className:`w-full px-3 py-2 rounded-lg text-left hover:bg-stone-100 transition-colors`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[(0,Z.jsx)(`span`,{className:`flex-1 ${d===e.value?`text-stone-900 font-medium`:`text-stone-600`}`,children:e.label}),d===e.value&&(0,Z.jsx)(Sm,{className:`w-3.5 h-3.5 text-[#4176e6]`})]}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400`,children:e.desc})]},e.value))})]})]})}var dh=null;function fh(){if(!dh){let e=Je();dh={store:e,messages:e.sessions.find(t=>t.id===e.activeId)?.messages??[]}}return dh}var ph=new Map,mh=new Map,hh={current:null};function gh({slashDocs:e=[],embedded:t=!1,lockedSessionId:n,lockedWorkspacePath:r,lockedWorkspaceLabel:i}){let a=r?.trim()||``,o=!!(t&&a),[f,m]=(0,U.useState)(null),[h,g]=(0,U.useState)(!1),[_,v]=(0,U.useState)(()=>fh().store),[x,D]=(0,U.useState)(()=>fh().messages),[O,k]=(0,U.useState)(()=>Yt(fh().store.activeId??``)),[se,ce]=(0,U.useState)([]),[le,ue]=(0,U.useState)([]),[A,j]=(0,U.useState)([]),[M,de]=(0,U.useState)(!1),N=(0,U.useRef)(0),[fe,pe]=(0,U.useState)($p),[me,he]=(0,U.useState)(!1),[ge,_e]=(0,U.useState)(null),P=(0,U.useRef)(null);P.current=ge;let[ve,F]=(0,U.useState)(null),[xe,I]=(0,U.useState)(!1),[L,Ce]=(0,U.useState)(null),we=(0,U.useRef)(null);we.current=L;let[Te,R]=(0,U.useState)(null),Ee=(0,U.useRef)(null);Ee.current=Te;let De=(0,U.useRef)(null),[Oe,ke]=(0,U.useState)(null),[Le,Je]=(0,U.useState)(0),[lt,ft]=(0,U.useState)(()=>new URLSearchParams(location.search).get(`skill`)||``),[pt,_t]=(0,U.useState)(null),[vt,yt]=(0,U.useState)(!1),[bt,xt]=(0,U.useState)(``);(0,U.useEffect)(()=>{let e=lt;if(!e){yt(!1);return}let t=!0;return yt(!0),$c(`skill_load`,JSON.stringify({name:e})).then(e=>{let n=JSON.parse(e);if(!n.ok)throw Error(n.error||`技能不可用`);t&&_t({id:n.id,name:n.name,text:n.text,version:n.version||1})}).catch(e=>{t&&xt(e instanceof Error?e.message:String(e))}).finally(()=>{t&&yt(!1)}),()=>{t=!1}},[lt]);let[St,Ct]=(0,U.useState)(null),[wt,Tt]=(0,U.useState)(null),[Dt,Ot]=(0,U.useState)(null),[kt,At]=(0,U.useState)(null),[jt,Mt]=(0,U.useState)(null),[Nt,Pt]=(0,U.useState)(!1),[Ft,Lt]=(0,U.useState)([]),[Rt,Bt]=(0,U.useState)(null),[Wt,Gt]=(0,U.useState)(`error`);function B(e,t=`error`){Gt(t),Bt(e)}let[Kt,qt]=(0,U.useState)(`readonly`),[cn,ln]=(0,U.useState)(!1),[dn,mn]=(0,U.useState)(!0),[bn,En]=(0,U.useState)(!1),[V,On]=(0,U.useState)(()=>ie()),[An,jn]=(0,U.useState)(``),[Mn,Nn]=(0,U.useState)(``),[Pn,Fn]=(0,U.useState)(null),[In,Ln]=(0,U.useState)(null),[Rn,zn]=(0,U.useState)(!1),[Vn,Hn]=(0,U.useState)(null),[Un,Wn]=(0,U.useState)(null),[Gn,Kn]=(0,U.useState)(null),[H,qn]=(0,U.useState)(null),[Jn,Yn]=(0,U.useState)(!1),[Xn,Zn]=(0,U.useState)({}),Qn=(0,U.useRef)(``),[$n,er]=(0,U.useState)(``),[nr,ir]=(0,U.useState)(!1),[cr,lr]=(0,U.useState)(null),[ur,pr]=(0,U.useState)(()=>ye(rm,nm,`dialog`)),[mr,gr]=(0,U.useState)(()=>typeof window>`u`?{language:`zh-CN`,appearance:`system`,sessionFontSize:14,toolStepDetail:`standard`,busySendBehavior:`queue`,subagentModel:``}:te()),[_r,vr]=(0,U.useState)(!1),[xr,Cr]=(0,U.useState)(null),[wr,Or]=(0,U.useState)(0),[kr,Ar]=(0,U.useState)(!1),[jr,Mr]=(0,U.useState)(!1),[Nr,Pr]=(0,U.useState)(!1),[Fr,Lr]=(0,U.useState)(!0),[zr,Vr]=(0,U.useState)([]),[Hr,Ur]=(0,U.useState)([]),Wr=!!(V.memory&&Pn?.ok),Yr=!!V.knowledge,Xr=!!Gn?.ok,Zr=!!In?.ok,Qr=Rn&&!Zr,$r=!!Vn?.ok,ei=!!(Un?.ok&&Un.available),oi=(0,U.useRef)(null),si=(0,U.useRef)(ph),di=hh,hi=(0,U.useRef)(mh),gi=(0,U.useRef)(new Map),_i=(0,U.useRef)(new Map),vi=(0,U.useRef)(null),yi=(0,U.useRef)(!1),xi=(0,U.useRef)(null),wi=(0,U.useRef)(null),[Ti,Ei]=(0,U.useState)([]),[Oi,ki]=(0,U.useState)(null),Ai=(0,U.useRef)(null),Mi=(0,U.useRef)(0),Ni=(0,U.useRef)(new Set),[Pi,Ii]=(0,U.useState)(`off`),[Li,Ri]=(0,U.useState)(null),[Bi,Vi]=(0,U.useState)(`day`),[Hi,Ui]=(0,U.useState)([]),[W,Wi]=(0,U.useState)(null),[Gi,Ki]=(0,U.useState)(null),[qi,Ji]=(0,U.useState)(null);function Yi(e,t,n,r){e&&G.current&&q(Xe(G.current,e,{planPhase:t===`off`?void 0:t,planProposal:n??void 0},r))}function Xi(e,t,n){Ii(e),Ji(t),Ri(e===`planning`||e===`approved`?`plan`:e=>e===`plan`?null:e),Yi(n??G.current?.activeId,e,t)}function Zi(e){let t=Su(e?.planPhase),n=Cu(e?.planProposal);Ii(t),Ji(n),(t===`planning`||t===`approved`)&&Ri(`plan`)}let[Qi,$i]=(0,U.useState)(null),[ea,ta]=(0,U.useState)({}),[na,ra]=(0,U.useState)(0),[ia,aa]=(0,U.useState)(!1),[oa,sa]=(0,U.useState)(null),[ca,la]=(0,U.useState)(!1),[ua,da]=(0,U.useState)(``),[fa,pa]=(0,U.useState)(null),[ma,ha]=(0,U.useState)(!1),ga=(0,U.useRef)(null),_a=(0,U.useRef)(null);function va(){_a.current!==null&&(window.clearTimeout(_a.current),_a.current=null)}function ya(){va(),ha(!1)}function ba(e,t,n={}){return new Promise(r=>{ga.current?.(null),ga.current=r,ya(),pa({kind:e,items:t,quick:n.quick,quickNote:n.quickNote})})}function xa(e){let t=ga.current;ga.current=null,ha(!0),va(),_a.current=window.setTimeout(()=>{_a.current=null,pa(null),ha(!1)},160),t?.(e)}let Sa=(0,U.useRef)(()=>{});Sa.current=()=>xa(null),(0,U.useEffect)(()=>{if(!fa||ma)return;let e=e=>{let t=e.target;t instanceof Element&&(t.closest(`.tw-create-card`)||t.closest(`[data-headlessui-portal]`)||t.closest(`.tw-select-menu`)||t.closest(`.tw-date-panel`)||Sa.current())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[fa,ma]);function Ca(e){Pr(!1),V[e===`todo`?`todos`:`tasks`]&&(ya(),pa({kind:e,manual:!0,items:[zp(e)]}))}async function wa(e,t){let n=e===`todo`?`待办`:`任务`;try{e===`todo`?await tr(t.map(e=>({title:e.title.trim(),status:e.status,priority:e.priority,taskId:e.taskId,linkedTask:e.linkedTask,startDate:e.startDate,dueDate:e.dueDate,note:e.note})),{mode:`manual`}):await Bn(t.map(e=>({title:e.title.trim(),status:e.status,priority:e.priority,startDate:e.startDate,dueDate:e.dueDate,note:e.note})),{mode:`manual`}),B(`已新增 ${t.length} 条${n},可在侧栏「${n===`待办`?`待办事项`:`任务管理`}」查看。`,`ok`)}catch(e){Gt(`error`),B(e instanceof Error?e.message:String(e))}}(0,U.useEffect)(()=>()=>{ga.current?.(null),ga.current=null,_a.current!==null&&(window.clearTimeout(_a.current),_a.current=null)},[]);let Ta=(0,U.useRef)([]),Ea=(0,U.useRef)(null);function Da(e){Ta.current=e,Vr(e)}function Oa(e){if(e.taskCards?.length){let t=e.taskCards.map(e=>e.label).join(` · `);return t.length>28?`${t.slice(0,28)}…`:t}let t=(e.displayContent||e.content).trim().replace(/\s+/g,` `);if(t)return t.length>28?`${t.slice(0,28)}…`:t;let n=e.files.length+e.imgs.length+e.refs.length;return n>0?`附件 ${n} 项`:`(空消息)`}let ka=(0,U.useRef)(null),Aa=(0,U.useRef)(null),ja=(0,U.useRef)({stack:[``],index:0}),Ma=(0,U.useRef)(!1),Na=(0,U.useRef)(null),Pa=(0,U.useRef)(null),Fa=(0,U.useRef)(null),Ia=(0,U.useRef)(null),La=(0,U.useRef)(null),Ra=(0,U.useRef)(null),za=(0,U.useRef)({}),Ba=!!(Zr&&H?.workspace),Va=Zp(O),Ha=(()=>{if(!Va||!Yr)return[];let t=Va.query.toLowerCase();return(t?e.filter(e=>cf(e,t)):e).slice(0,10)})(),Ua=(()=>{if(!Va||!Ba)return[];let e=Va.query.toLowerCase(),t=Hr.map(e=>({collection:`workspace`,id:`ws:${e.path}`,title:e.name,category:yn(H?.workspace,H?.projectRoot),description:e.path,format:e.type===`dir`?`dir`:`file`,path:e.path}));return(e?t.filter(t=>cf(t,e)||t.path.toLowerCase().includes(e)||t.title.toLowerCase().includes(e)):t).slice(0,10)})(),Wa=[...Ha.map(e=>({section:`project`,doc:e})),...Ua.map(e=>({section:`workspace`,doc:e}))],Ga=!(!Va||kr),Ka=Xp(O),qa=oe.filter(e=>e.hasPanel&&V[e.id]),Ja=!!(Ka&&!jr&&!Ga&&qa.length>0),Ya=(0,U.useRef)(!0),Xa=(0,U.useRef)(!1),G=(0,U.useRef)(null),Za=(0,U.useRef)(null),Qa=(0,U.useRef)([]),$a=(0,U.useRef)(null),eo=(0,U.useRef)(null),to=(0,U.useRef)(null),no=(0,U.useRef)(null),ro=(0,U.useRef)(!1),io=(0,U.useRef)(new Set),[ao,oo]=(0,U.useState)([]),so=(0,U.useRef)(new Map);to.current!==null&&x===to.current&&(to.current=null),eo.current===null&&to.current===null&&(Qa.current=x);let K=(0,U.useRef)(O);K.current=O,Za.current=H,(0,U.useEffect)(()=>{let e=_?.activeId;if(!e)return;let t=window.setTimeout(()=>Xt(e,O),400);return()=>window.clearTimeout(t)},[O,_?.activeId]),(0,U.useEffect)(()=>{let e=()=>{let e=G.current?.activeId;e&&Xt(e,K.current)},t=()=>{document.visibilityState===`hidden`&&e()};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t)}},[]);function q(e){G.current=e,v(e),z(e)}let co=_?.sessions.find(e=>e.id===_.activeId),lo=co?.id,uo=co?.access;(0,U.useEffect)(()=>{lo&&qt(uo??T())},[lo,uo]),(0,U.useEffect)(()=>()=>{for(let e of so.current.values())clearTimeout(e);so.current.clear(),no.current!=null&&clearTimeout(no.current),$a.current!=null&&clearTimeout($a.current)},[]),(0,U.useEffect)(()=>{let e=!1,t=C(()=>m(E())),n=re(e=>On(e)),r=b(e=>{gr(e),w(e)});return(async()=>{if(await p(),e)return;let t=te();gr(t),w(t),m(E()),qt(T()),On(ie()),mn($e());let n=new URLSearchParams(window.location.search),r=n.get(`session`),i=await Ge({preferSessionId:r});if(e)return;let a=i;if(r&&!a.sessions.some(e=>e.id===r))try{let e=sessionStorage.getItem(et(r));if(e){let t=JSON.parse(e)?.session;t&&t.id===r&&(a={...a,sessions:[t,...a.sessions.filter(e=>e.id!==r)],activeId:r},await Qe(a))}}catch{}if(r)try{sessionStorage.removeItem(et(r))}catch{}let o=n.get(`focusRoot`),s=n.get(`focusPath`),c=n.get(`attachRoot`),l=n.get(`attachPath`),u=n.get(`attachName`),d=null;if(o&&s)try{d=`${o}:${decodeURIComponent(s).replace(/\\/g,`/`).replace(/^\/+/,``)}`}catch{d=`${o}:${s}`}if(r){let e=a.sessions.find(e=>e.id===r);nt(e)&&(a=Be(a,r),z(a))}d&&ke(d);let f=n.get(`attachPrompt`);if(c&&l){let e=c;if(e===`cases`||e===`knowledge`||e===`templates`||e===`testReports`){let t=l,n=u||``;try{t=decodeURIComponent(l).replace(/\\/g,`/`).replace(/^\/+/,``),u&&(n=decodeURIComponent(u))}catch{}n||=t.split(`/`).pop()||t;let r=(n.split(`.`).pop()||`md`).toLowerCase(),i=e===`cases`?`用例`:e===`knowledge`?`知识库`:e===`testReports`?`报告`:`模板`;if(j([{collection:e,id:`${e}:${t}`,title:n,category:i,path:t,format:r}]),e===`testReports`&&f){let e=f;try{e=decodeURIComponent(f).replace(/^.*\//,``)}catch{e=f.replace(/^.*\//,``)}e&&Ut(e).then(e=>{e.trim()&&Nn(e.trim())}).catch(()=>{})}}}let h=n.get(`report`);try{let e=new URL(window.location.href);e.searchParams.delete(`report`),e.searchParams.delete(`session`),e.searchParams.delete(`focusRoot`),e.searchParams.delete(`focusPath`),e.searchParams.delete(`attachRoot`),e.searchParams.delete(`attachPath`),e.searchParams.delete(`attachName`),e.searchParams.delete(`attachPrompt`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}catch{}let _=[];try{_=(await ni()).map(e=>e.sessionId)}catch{_=[]}let ee=new Set(_);a=ee.size?{...a,sessions:a.sessions.map(e=>{if(ee.has(e.id))return e;let t=ze(e.messages);return t===e.messages?e:{...e,messages:t}})}:Fe(a);let y=T();a.sessions.some(e=>!e.access)&&(a={...a,sessions:a.sessions.map(e=>e.access?e:{...e,access:y})}),a=ot(a,a.activeId,e=>!!Yt(e).trim()||Ne(e).length>0),G.current=a,v(a),z(a);let b=a.sessions.find(e=>e.id===a.activeId),x=b?ph.get(b.id)?.messages:void 0;if(D(x??b?.messages??[]),x&&(Qa.current=x),k(e=>{let t=e.trim()?e:Yt(a.activeId);return qo(t),t}),Ui(Ne(a.activeId)),_e(b?.caseGen?.active?b.caseGen:null),Ce(b?.knowledgeGen?.active?b.knowledgeGen:null),R(b?.pluginDev?.active?b.pluginDev:null),qt(b?.access??y),b?.pluginDev?.active&&(Ri(`pluginDev`),b.access!==`readwrite`&&b.access!==`full`)){qt(`readwrite`);let e={...a,sessions:a.sessions.map(e=>e.id===a.activeId?{...e,access:`readwrite`}:e)};G.current=e,v(e),z(e)}Ei(pu(b?.todos));{let e=Iu(b?.goal);Ai.current=e,ki(e)}if(Zi(b),(h===`day`||h===`week`||h===`month`)&&ie().reports){let e=G.current?.sessions.find(e=>e.id===G.current?.activeId);if((!e||e.archived||e.deleted||Array.isArray(e.messages)&&e.messages.length>0||e.caseGen?.active||e.knowledgeGen?.active||e.pluginDev?.active)&&G.current){let e=G.current.activeId,t=To(e)??G.current,n=Za.current?.workspace?.trim()||void 0,r=tt(t,{workspacePath:n,access:T()});G.current=r,v(r),z(r),D([]),_e(null),Ce(null),R(null),Ri(null),Ei([]),Ai.current=null,ki(null),Ii(`off`),k(``),qo(``),Ui([]),qt(T())}ts(h)}b?.workspacePath&&Zn(e=>({...e,[b.workspacePath]:!0})),(b?.messages??[]).length||pr(`dialog`);let S=[...ph.keys()],C=[...new Set([..._,...S])];Lt(C),g(!0),C.length&&queueMicrotask(()=>{for(let e of C)No(e,!0),e===G.current?.activeId&&(yi.current=!0,Pt(!0),oi.current=ph.get(e)?.abort??null,_.includes(e)&&!ph.has(e)&&Io(e,0))});try{let e=new URL(window.location.href),t=e.searchParams.get(`plugin`);if(t===`knowledgeGen`||t===`caseGen`||t===`pluginDev`){let n=t;if(ie()[n]){let t=G.current?.sessions.find(e=>e.id===G.current?.activeId);if((!nt(t)||Array.isArray(t.messages)&&t.messages.length>0||t.caseGen?.active||t.knowledgeGen?.active||n!==`pluginDev`&&t.pluginDev?.active)&&G.current){let e=G.current.activeId,t=To(e)??G.current,n=Za.current?.workspace?.trim()||H?.workspace?.trim()||void 0,r=tt(t,{workspacePath:n,access:T()});G.current=r,v(r),z(r),D([]),_e(null),Ce(null),R(null),Ri(null),Ei([]),Ai.current=null,ki(null),Ii(`off`),k(``),qo(``),Ui([]),qt(T())}if(n===`pluginDev`)es();else if(n===`knowledgeGen`)I(!0);else{let t=e.searchParams.get(`reqDoc`);t&&(F({docId:t,storyIds:(e.searchParams.get(`stories`)??``).split(`,`).map(e=>e.trim()).filter(Boolean)}),e.searchParams.delete(`reqDoc`),e.searchParams.delete(`stories`)),he(!0)}}else B(ae(n));e.searchParams.delete(`plugin`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}}catch{}(async()=>{try{let e=(await Ut(Gr)).trim();e?pe(e):Se(`「空间基础规则」技能是空的,系统提示词暂时用内置兜底。`,`error`)}catch{Se(`没有读到「空间基础规则」技能,系统提示词暂时用内置兜底。`,`error`)}})(),Dr().then(e=>Fn(e)),hn().then(e=>{Ln(e),zn(!0)}),ar().then(e=>Hn(e)),dr().then(e=>Wn(e)),rr().then(e=>Kn(e)),nn().then(e=>{qn(e),e?.workspace&&Zn(t=>({...t,[e.workspace]:!0}))})})(),()=>{e=!0,t(),n(),r()}},[]),(0,U.useEffect)(()=>{!V.memory&&ur===`memory`&&pr(`dialog`)},[V.memory,ur]),(0,U.useEffect)(()=>{!V.todos&&ur===`todos`&&pr(`dialog`)},[V.todos,ur]),(0,U.useEffect)(()=>{be(rm,ur)},[ur]),(0,U.useEffect)(()=>{if(!V.reports){jn(``);return}let e=!0;return(async()=>{try{await Kr(!0);let t=await qr();e&&jn(t),t||Se(`工作汇报关联技能没读到(内容为空或缺失),汇报不会注入业务规则。`,`error`)}catch(e){let t=e instanceof Error?e.message:String(e);Se(`读取工作汇报提示词失败:${t}`,`error`)}})(),()=>{e=!1}},[V.reports]),(0,U.useEffect)(()=>{if(!h)return;let e=!1,t=async()=>{if(!G.current)return;let t=await _d();if(e||!G.current)return;let n=G.current,r=!1;for(let e of t){let t=n.sessions.find(t=>t.id===e.sessionId)?.messages??[],i=`<!--tb-schedule:${e.id}-->`;if(!t.some(t=>t.scheduleId===e.id||typeof t.content==`string`&&t.content.includes(i))){let t={role:`assistant`,content:hd(e.text,e.id),time:Date.now(),scheduleId:e.id};n=rt(n,e.sessionId,t),e.sessionId===n.activeId&&(r=!0)}try{typeof Notification<`u`&&Notification.permission===`granted`&&new Notification(`Lantern Harness 定时提醒`,{body:e.text})}catch{}}let i=await We();if(!e&&G.current){if(i){let e=qe(n,i);e!==n&&(n=e,n.activeId&&(r=!0))}if((n!==G.current||t.length)&&q(n),r){let e=n.sessions.find(e=>e.id===n.activeId);D(e?.messages??[])}}};t();let n=window.setInterval(()=>{t()},1e4);return()=>{e=!0,window.clearInterval(n)}},[h]),(0,U.useEffect)(()=>{if(!h||!Zr||!H)return;let e=_?.sessions.find(e=>e.id===_.activeId),t=e?.id??``;if(Qn.current===t)return;let n=ho(e);if(!n)return;let r=Za.current;r&&(n===r.workspace?Qn.current=t:Jn||(Qn.current=t,go(e)))},[h,Zr,_?.activeId,H?.items]),(0,U.useEffect)(()=>{let e=e=>{if(e.key!==`Shift`||e.repeat||e.ctrlKey||e.metaKey||e.altKey)return;let t=document.activeElement;t instanceof HTMLElement&&t!==document.body&&(t.tagName===`TEXTAREA`||t.tagName===`INPUT`||t.tagName===`SELECT`||t.isContentEditable||t.blur())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,U.useEffect)(()=>{Or(0),Ar(!1)},[Va?.query,Va?.from]),(0,U.useEffect)(()=>{Mr(!1),Je(0)},[Ka?.from]),(0,U.useEffect)(()=>{Je(e=>qa.length?Math.min(e,qa.length-1):0)},[qa.length]),(0,U.useEffect)(()=>{if(!Ga||!Ba){Ba||Ur([]);return}let e=!1;return _n(Kt,{maxDepth:3,maxEntries:80}).then(t=>{e||Ur(t)}),()=>{e=!0}},[Ga,Ba,Kt,H?.workspace]),(0,U.useEffect)(()=>{if(!Ga)return;let e=Pa.current;e&&e.querySelector(`[data-mention-index="${wr}"]`)?.scrollIntoView({block:`nearest`})},[wr,Ga,Wa.length]),(0,U.useEffect)(()=>{if(!Ja)return;let e=Fa.current;e&&e.querySelector(`[data-plugin-index="${Le}"]`)?.scrollIntoView({block:`nearest`})},[Le,Ja,qa.length]),(0,U.useEffect)(()=>{if(!Ga&&!Ja&&!Nr)return;function e(e){let t=e.target;Pa.current?.contains(t)||Fa.current?.contains(t)||Ia.current?.contains(t)||Aa.current?.contains(t)||e.target?.closest?.(`[data-add-menu-btn]`)||(Ar(!0),Mr(!0),Pr(!1))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Ga,Ja,Nr]),(0,U.useEffect)(()=>{if(!Rt||Wt!==`ok`)return;function e(e){let t=e.target;La.current?.contains(t)||B(null)}let t=window.setTimeout(()=>{document.addEventListener(`pointerdown`,e,!0)},0);return()=>{window.clearTimeout(t),document.removeEventListener(`pointerdown`,e,!0)}},[Rt,Wt]),(0,U.useEffect)(()=>{if(!cr&&!Dt)return;function e(e){let t=e.target;t?.closest?.(`[data-session-menu]`)||t?.closest?.(`[data-ws-menu]`)||(lr(null),Ot(null))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[cr,Dt]);function fo(){Dr().then(e=>Fn(e)),hn().then(e=>{Ln(e),zn(!0)}),ar().then(e=>Hn(e)),dr().then(e=>Wn(e)),rr().then(e=>Kn(e)),nn().then(e=>qn(e))}function po(e,t){qn(e),Zn(n=>{if(!t?.exclusiveExpand)return{...n,[e.workspace]:!0};let r={};for(let t of e.items??[])r[t.path]=t.path===e.workspace;return e.projectRoot&&r[e.projectRoot]===void 0&&(r[e.projectRoot]=e.projectRoot===e.workspace),r})}async function mo(e,t=`select`){if(Zr&&!Jn){Yn(!0),B(null);try{po(t===`add`?await en(e):await vn(e))}catch(e){B(e instanceof Error?e.message:String(e))}finally{Yn(!1)}}}function ho(e){let t=Za.current;if(!t)return null;let n=e?.workspacePath?.trim();return n&&(n===t.harnessRoot||t.items.some(e=>e.path===n))?n:t.projectRoot?.trim()||null}async function go(e){if(!Zr||Jn)return;let t=ho(e);if(!t)return;let n=Za.current;if(n&&t!==n.workspace){Yn(!0);try{po(await vn(t))}catch{}finally{Yn(!1)}}}async function _o(e){if(!Zr||Jn)return;await mo(e.path,`select`);let t=G.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId);n&&!n.workspacePath&&((n.messages??[]).length>0||(q(He(t,n.id,e.path)),Zn(t=>({...t,[e.path]:!0}))))}async function vo(){if(Zr&&!Jn){Yn(!0),B(null);try{let e=await an();if(!e)return;po(await en(e),{exclusiveExpand:!0})}catch(e){B(e instanceof Error?e.message:String(e))}finally{Yn(!1)}}}async function yo(){let e=kt;if(e&&Zr&&!Jn){if(e.id===`ws_project`)At(null);else{At(null),Ot(null),Yn(!0),B(null);try{G.current&&q(Ie(G.current,e.path));let t=await pn(e.id);po(t),t.projectRoot&&Zn(e=>({...e,[t.projectRoot]:!0}))}catch(e){B(e instanceof Error?e.message:String(e))}finally{Yn(!1)}}}}function bo(e){Zr&&!Jn&&e.id!==`ws_project`&&(lr(null),Ot(null),At(e))}async function xo(e){let t=jt;if(Mt(null),t&&Zr){Yn(!0),B(null);try{po(await un(t,e))}catch(e){B(e instanceof Error?e.message:String(e))}finally{Yn(!1)}}}function So(e){let t=za.current[e];return!!(t&&(t.input?.trim()||(t.attachments?.length??0)>0||(t.images?.length??0)>0||(t.docRefs?.length??0)>0)||Yt(e).trim()||Ne(e).length>0)}function Co(){try{if(window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return 0}catch{}return 180}function wo(e){let t=e.filter(e=>e&&!io.current.has(e));if(!t.length||!G.current)return;for(let e of t)io.current.add(e);oo([...io.current]);let n=Co();for(let e of t){let t=so.current.get(e);t!=null&&clearTimeout(t);let r=setTimeout(()=>{if(so.current.delete(e),io.current.delete(e),oo([...io.current]),!G.current||G.current.activeId===e)return;let t=G.current.sessions.find(t=>t.id===e);if(!t||!Ke(t)||So(e))return;delete za.current[e],Zt(e),Ae(e,[]);let n=it(G.current,e);G.current=n,v(n),z(n)},n);so.current.set(e,r)}}function To(e){if(!e||!G.current)return G.current;let t=G.current.sessions.find(t=>t.id===e);return!t||!Ke(t)||So(e)||wo([e]),G.current}function Eo(e){if(!G.current)return G.current;let t=G.current,n=t.sessions.filter(t=>t.id!==e&&Ke(t)&&!So(t.id)&&!io.current.has(t.id)).map(e=>e.id);return n.length&&wo(n),t}function Do(e){Va&&(e.collection!==`workspace`&&!Yr?B(ae(`knowledge`)):A.length>=em?B(`最多引用 ${em} 篇文档`):(B(null),j(t=>t.some(t=>t.collection===e.collection&&t.path===e.path)?t:[...t,{collection:e.collection,id:e.id,title:e.title,category:e.category,path:e.path,format:e.format}].slice(0,em)),k(O.slice(0,Va.from).replace(/\s+$/,``)),Ar(!0),Aa.current?.focus()))}function Oo(){Ka&&(k(O.slice(0,Ka.from).replace(/\s+$/,``)),Mr(!0))}function ko(e){if(!V[e])return B(ae(e)),!1;if(B(null),e===`caseGen`)return he(!0),!0;if(e===`knowledgeGen`)return I(!0),!0;if(e===`pluginDev`)return es(),!0;if(e===`memory`)return pr(`memory`),!0;if(e===`knowledge`){let e=O.replace(/\s+$/,``);return k(e?`${e} @`:`@`),Ar(!1),requestAnimationFrame(()=>Aa.current?.focus()),!0}return!1}function Ao(e){Oo(),ko(e)}function jo(){let e=ka.current;if(!e)return;let t=e.scrollHeight-e.clientHeight-e.scrollTop<=48;if(Xa.current){if(!t)return;Xa.current=!1}Ya.current=t,ln(!t)}function Mo(){let e=ka.current;e&&(Ya.current=!0,Xa.current=!0,ln(!1),e.scrollTo({top:e.scrollHeight,behavior:`smooth`}))}(0,U.useEffect)(()=>{if(!h||!G.current)return;let e=G.current.sessions.find(e=>e.id===G.current.activeId)?.messages??[],t=ro.current;t&&(ro.current=!1);let n=!t&&JSON.stringify(e)!==JSON.stringify(x),r=Re(G.current,x,{touchUpdatedAt:n});if(G.current=r,v(r),z(r),Ya.current&&!Xa.current){let e=ka.current;e&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Ya.current&&!Xa.current&&ka.current===e&&e.scrollTo({top:e.scrollHeight})})})}},[x,h]),(0,U.useEffect)(()=>{let e=()=>{G.current&&z(G.current)};return window.addEventListener(`pagehide`,e),()=>window.removeEventListener(`pagehide`,e)},[]),(0,U.useLayoutEffect)(()=>{let e=Aa.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,280)}px`)},[O]),(0,U.useEffect)(()=>{if(!h||!Oe||!x.length)return;let e=Oe,t=window.setTimeout(()=>{let t=(ka.current??document).querySelector(`[data-focus-doc="${CSS.escape(e)}"]`);t instanceof HTMLElement&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`ring-2`,`ring-[#4176e6]`,`ring-offset-2`),window.setTimeout(()=>{t.classList.remove(`ring-2`,`ring-[#4176e6]`,`ring-offset-2`)},2400)),ke(null)},80);return()=>window.clearTimeout(t)},[h,Oe,x]);function No(e,t){Lt(n=>{let r=n.includes(e);return t&&!r?[...n,e]:!t&&r?n.filter(t=>t!==e):n}),G.current?.activeId===e&&(yi.current=t,Pt(t)),t||Vo()}function Po(e){e&&(si.current.get(e)?.abort.abort(),hi.current.get(e)?.(),hi.current.delete(e),ii(e))}function Fo(e,t){if(t.type===`reasoning`&&t.delta)Ho(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=It((r.reasoning??``)+t.delta),a=[...r.activitySteps??[]],o=a.findIndex(e=>e.kind===`thinking`),s={id:`thinking`,kind:`thinking`,title:`思考`,detail:vm(i).replaceAll(`**`,``).slice(0,80)||void 0,status:`running`};o>=0?a[o]={...a[o],...s}:a.unshift(s);let c=n.slice(),l=_i.current.get(e),u=r.ttftMs;return l&&l.firstToken==null&&(l.firstToken=Date.now(),u=Math.max(0,l.firstToken-l.start)),c[c.length-1]={...r,reasoning:i,activitySteps:a,turnStatus:`running`,ttftMs:u},c});else if(t.type===`content`&&t.delta)Ho(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=(r.activitySteps??[]).map(e=>e.kind===`thinking`&&e.status===`running`?{...e,status:`done`}:e),a=n.slice(),o=_i.current.get(e),s=r.ttftMs;return o&&o.firstToken==null&&(o.firstToken=Date.now(),s=Math.max(0,o.firstToken-o.start)),a[a.length-1]={...r,content:It((r.content??``)+t.delta),activitySteps:i,turnStatus:`running`,ttftMs:s},a});else if(t.type===`tool`&&t.name){let n=dm(t.name),r=hm(t.name,t.args),i=`tool_${t.name}_${t.args?.slice(0,24)??``}`;Wo(e,i,t.status);let a=t.status===`done`&&typeof t.result==`string`&&/^\s*\{\s*"error"\s*:/.test(t.result);Ho(e,e=>{let o=e[e.length-1];if(o?.role!==`assistant`)return e;let s=[...o.activitySteps??[]],c=s.findIndex(e=>e.id===i||e.detail===r&&e.title===n&&e.status===`running`),l={id:i,kind:pm(t.name),title:n,detail:r||void 0,status:t.status===`running`?`running`:a?`error`:`done`};c>=0?s[c]={...s[c],...l}:s.push(l);let u=e.slice();return u[u.length-1]={...o,activitySteps:s,turnStatus:`running`},u}),G.current?.activeId===e&&Cr(ym(te().toolStepDetail,n,t.name,t.status===`running`?`running`:`done`))}else if(t.type===`usage`&&t.usage)Ho(e,e=>{let n=e[e.length-1];if(n?.role!==`assistant`)return e;let r=e.slice();return r[r.length-1]={...n,usage:t.usage},r});else if(t.type===`status`){let n=t.status;(n===`completed`||n===`stopped`||n===`error`)&&(Ho(e,e=>{let r=e[e.length-1];if(r?.role!==`assistant`)return e;let i=t.assistant,a=e.slice(),o=typeof i?.toolMs==`number`?i.toolMs:void 0,s=typeof i?.llmMs==`number`?i.llmMs:void 0,c=typeof i?.ttftMs==`number`?i.ttftMs:void 0,l=typeof i?.tps==`number`?i.tps:void 0;return a[a.length-1]={...r,content:typeof i?.content==`string`?i.content:r.content,reasoning:typeof i?.reasoning==`string`?i.reasoning:r.reasoning,reasoningApi:typeof i?.reasoningApi==`string`?i.reasoningApi:r.reasoningApi,activitySteps:(i?.activitySteps??r.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e),turnStatus:n===`completed`?`completed`:`stopped`,time:Date.now(),usage:i?.usage??r.usage,model:typeof i?.model==`string`?i.model:r.model,toolMs:o==null?r.toolMs:Math.max(o,r.toolMs??0),llmMs:s??r.llmMs,ttftMs:c??r.ttftMs,tps:l??r.tps},a}),n===`error`&&t.error&&G.current?.activeId===e&&B(fm(t.error)),si.current.delete(e),di.current===e&&(di.current=null),No(e,!1),G.current?.activeId===e&&Cr(null))}}function Io(e,t=0){si.current.has(e)||(hi.current.get(e)?.(),No(e,!0),(async()=>{let n=await ai(e),r=t;if(n?.ok&&n.assistant){if(r=Math.max(r,n.seq??0),Ho(e,e=>{let t=e[e.length-1],r=t?.role===`assistant`?t:{role:`assistant`,content:``,turnStatus:`running`},i=n.assistant,a={...r,content:typeof i?.content==`string`?i.content:r.content,reasoning:typeof i?.reasoning==`string`?i.reasoning:r.reasoning,reasoningApi:typeof i?.reasoningApi==`string`?i.reasoningApi:r.reasoningApi,activitySteps:i?.activitySteps??r.activitySteps,turnStatus:n.status===`completed`?`completed`:n.status===`stopped`||n.status===`error`?`stopped`:`running`,usage:i?.usage??r.usage,model:typeof i?.model==`string`?i.model:r.model,llmMs:typeof i?.llmMs==`number`?i.llmMs:r.llmMs,ttftMs:typeof i?.ttftMs==`number`?i.ttftMs:r.ttftMs,toolMs:typeof i?.toolMs==`number`?Math.max(i.toolMs,r.toolMs??0):r.toolMs,tps:typeof i?.tps==`number`?i.tps:r.tps};if(t?.role===`assistant`){let t=e.slice();return t[t.length-1]=a,t}return[...e,a]}),n.status&&n.status!==`running`&&n.status!==`waiting_user`){No(e,!1);return}}else if(n&&n.ok===!1){No(e,!1);return}let i=ci(e,r,{onEvent:t=>Fo(e,t),onGaveUp:t=>{si.current.has(e)||(G.current?.activeId===e&&B(t.message||`与服务端回合断开`),No(e,!1))}});hi.current.set(e,i)})())}function Lo(e){G.current=e,$a.current??=setTimeout(()=>{$a.current=null;let e=G.current;e&&(v(e),z(e))},400)}function Ro(e,t){Qa.current=e,eo.current={sessionId:t,msgs:e},no.current??=setTimeout(()=>{no.current=null;let e=eo.current;eo.current=null,e&&G.current?.activeId===e.sessionId&&(to.current=e.msgs,D(e.msgs))},16)}function zo(e){no.current!=null&&(clearTimeout(no.current),no.current=null);let t=eo.current?.msgs??Qa.current;eo.current=null;let n=e(t),r=di.current??G.current?.activeId,i=r?si.current.get(r):void 0;i&&(i.messages=n),Qa.current=n,to.current=n,D(n)}function Bo(){no.current!=null&&(clearTimeout(no.current),no.current=null);let e=eo.current;eo.current=null,e&&G.current?.activeId===e.sessionId&&(to.current=e.msgs,D(e.msgs))}function Vo(){$a.current!=null&&(clearTimeout($a.current),$a.current=null),Bo();let e=G.current;e&&(v(e),z(e))}function Ho(e,t,n){let r=si.current.get(e),i=G.current?.sessions.find(t=>t.id===e)?.messages??[],a=r?.messages??(G.current?.activeId===e?Qa.current:i),o=typeof t==`function`?t(a):t;r&&(r.messages=o),G.current?.activeId===e&&Ro(o,e),G.current&&Lo(Pe(G.current,e,o,{touchUpdatedAt:n?.touchUpdatedAt!==!1}))}function Uo(e){let t=di.current??G.current?.activeId;t&&Ho(t,t=>{let n=t[t.length-1];if(n?.role!==`assistant`)return t;let r=t.slice();return r[r.length-1]=e(n),r})}function Wo(e,t,n){let r=`${e}:${t}`;if(n===`running`){gi.current.set(r,Date.now());return}if(n!==`done`&&n!==`error`)return;let i=gi.current.get(r);if(gi.current.delete(r),i==null)return;let a=Math.max(0,Date.now()-i);Ho(e,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,toolMs:(t.toolMs??0)+a},n})}async function Go(e){if(!e.length)return;let t=[],n=[],r=cm(se,le);for(let i of e)if(r+t.length>=6)n.push(`${i.name||`图片`}(最多 6 个文件)`);else try{t.push(await sm(i))}catch(e){n.push(e instanceof Error?e.message:String(e))}t.length&&ue(e=>[...e,...t].slice(0,6)),B(n.length?`以下图片未添加:${n.join(`、`)}`:null)}function Ko(e){let t=W;if(!t)return;let n={...t,body:e,at:Date.now()};Ui(e=>{let t=e.map(e=>e.id===n.id?n:e);return Ae(G.current?.activeId,t),t}),Wi(null)}function qo(e){ja.current={stack:[e],index:0}}function Jo(e){if(Ma.current)return;let t=ja.current;if(t.stack[t.index]===e)return;let n=t.stack.slice(0,t.index+1);n.push(e),n.length>80&&n.shift(),ja.current={stack:n,index:n.length-1}}function Yo(){let e=ja.current;e.index<=0||(Ma.current=!0,--e.index,k(e.stack[e.index]??``),Ma.current=!1)}function Xo(){let e=ja.current;e.index>=e.stack.length-1||(Ma.current=!0,e.index+=1,k(e.stack[e.index]??``),Ma.current=!1)}function J(e){je(G.current?.activeId,e),Ui(t=>t.filter(t=>t.id!==e)),Wi(t=>t?.id===e?null:t),(e.startsWith(`case-fix:`)||e.startsWith(`case-batch-fix:`)||e.startsWith(`blindspot-writeback:`))&&j(e=>e.filter(e=>e.collection!==`cases`))}function Zo(){qo(``),k(``),ce([]),ue([]),j([]),Ui([]),Ae(G.current?.activeId,[]),Ar(!1),Mr(!1)}function Y(){if(Li===`plan`&&(Ss(),Ii(`off`)),Li===`pluginDev`){R(null),Ee.current=null,G.current&&q(Ze(G.current,{pluginDev:void 0}));let e=De.current;De.current=null,e===`readonly`&&(qt(`readonly`),G.current&&q(Ze(G.current,{access:`readonly`})))}Ri(null)}function Qo(){Ri(`goal`),requestAnimationFrame(()=>Aa.current?.focus())}function $o(){Pi===`off`?Xi(`planning`,null):Ri(`plan`),requestAnimationFrame(()=>Aa.current?.focus())}function es(){Zr?(Ri(`pluginDev`),Kt===`readonly`&&(De.current=`readonly`,qt(`readwrite`),G.current&&q(Ze(G.current,{access:`readwrite`}))),requestAnimationFrame(()=>Aa.current?.focus())):B(`本地文件服务未就绪:插件开发需要读写项目源码`)}function ts(e){Vi(e),Ri(`reports`),window.setTimeout(()=>Aa.current?.focus(),400)}function ns(e){return e.filter(e=>e.role===`user`||e.role===`assistant`).map(e=>({role:e.role,content:typeof e.content==`string`?e.content:``,reasoning:e.reasoning}))}async function rs(e){if(!f)return S(`model`),!1;let t=ns(Qa.current);if(t.length<4)return B(`对话轮次较少,无需压缩`),!1;Cr(`正在压缩上下文…`);try{let{messages:n,compacted:r}=await Mu(f,t,{force:e.force,signal:e.signal});if(!r)return Cr(null),B(`当前上下文未超过阈值,未压缩`),!1;let i=Date.now(),a=n.map((e,t)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:i+t}));return Qa.current=a,D(a),G.current&&q(Re(G.current,a,{touchUpdatedAt:!0})),Cr(null),!0}catch(e){return Cr(null),e instanceof DOMException&&e.name===`AbortError`||B(e instanceof Error?e.message:String(e)),!1}}function is(e){let t=[`请根据以下需求生成测试用例`],n=e.reqSource;return n?.kind===`stories`?t.push(`(来源:${e.docTitle||`用户故事`},共 ${n.storyIds.length} 条故事)`):n?.kind===`doc`&&t.push(`(来源文档:${e.docTitle||n.path.split(`/`).pop()||n.path})`),e.testPointIds?.length&&t.push(`,参考 ${e.testPointIds.length} 条测试点`),e.templateTitle&&t.push(`,按「${e.templateTitle}」模板输出`),t.push(`。`),t.join(``)}async function as(e,r){if(vt||bt){Se(vt?`技能正在加载,请稍候`:bt,`error`);return}let i=e===void 0,a=i&&Li===`reports`?`生成${Jr[Bi]}`:``,o=i&&P.current?.active&&V.caseGen?is(P.current):``,s=i?Me(Hi):``,c=i?Hi.filter(e=>e.body.trim()).map(e=>({id:e.id,label:e.label.trim()||`任务要求`,detail:e.detail,body:e.body})):[],l=(e??O).trim()||a||o,u=s?l?`${l}\n\n${s}`:s:l,d=c.length&&l||void 0,p=i?se:[],m=i?A:[],h=i?le:[];if(!u&&!p.length&&!m.length&&!h.length)return;if(!f){S(`model`);return}let g=i&&Li===`reports`?Bi:V.reports?zf(l):null;if(g&&V.reports)try{let e=g===`week`&&Ef(l)?-1:0,t=await Rf(g,{todos:!!V.todos,tasks:!!V.tasks,testStats:!!V.testStats,caseExec:!!V.caseExec},new Date,{weekOffset:e});t&&(u=`${u}\n\n${t}`,d||=l||Jr[g])}catch{}if(i&&Li===`reports`&&Ri(null),Nu(u)&&!p.length&&!m.length&&!h.length){if(yi.current){B(`请等待当前回复结束后再压缩`);return}i&&Zo(),await rs({force:!0})&&B(null);return}if(t&&!p.length&&!m.length&&!h.length&&/^(生成代码|重新出码|出码)$/.test(l)){let e=n||G.current?.activeId,t=e?G.current?.sessions.find(t=>t.id===e)?.uiAuto:void 0;if(e&&t){i&&Zo();let t=Date.now(),n={role:`user`,content:l,time:t},r={role:`assistant`,content:`正在按当前步骤出码,完成后会切到「代码」页…`,time:t+1},a=[...Qa.current,n,r];Qa.current=a,D(a),G.current&&q(Re(G.current,a,{touchUpdatedAt:!0}));try{window.dispatchEvent(new CustomEvent(Sn,{detail:{action:`emit`,chatSessionId:e}}))}catch{}return}}if(Li===`goal`&&u&&!p.length&&!m.length&&!h.length&&!Bu(u)&&!Nu(u)){i&&Zo();let e={text:u.slice(0,500),status:`active`,updatedAt:Date.now()};Ai.current=e,ki(e),Mi.current=0,G.current&&q(Ze(G.current,{goal:e})),Ri(null),B(`已设定目标:${e.text}`);return}if(Bu(u)&&!p.length&&!m.length&&!h.length){let e=zu(u);if(i&&Zo(),!e)return;if(e.kind===`show`){let e=Oi;B(e&&e.status!==`cleared`?`当前目标(${e.status}):${e.text}`:`当前无会话目标。可用 /goal set <内容> 设定`);return}if(e.kind===`clear`){Ai.current=null,ki(null),Mi.current=0,G.current&&q(Ze(G.current,{goal:void 0})),B(`已清除会话目标`);return}if(e.kind===`done`){if(!Oi?.text){B(`当前无目标可标记完成`);return}let e={...Oi,status:`done`,updatedAt:Date.now()};Ai.current=e,ki(e),Mi.current=0,G.current&&q(Ze(G.current,{goal:e})),B(`已标记目标完成:${e.text}`);return}if(e.kind===`set`&&e.text){let t={text:e.text.slice(0,500),status:`active`,updatedAt:Date.now()};Ai.current=t,ki(t),Mi.current=0,G.current&&q(Ze(G.current,{goal:t})),B(`已设定目标:${t.text}`);return}return}if(Li===`pluginDev`&&u&&!p.length&&!m.length&&!h.length){if(yi.current){B(`请等待当前回复结束后再开始插件开发`);return}await _s(u)}let _={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:u,...d?{displayContent:d}:{},...c.length?{taskCards:c}:{},files:[...p],refs:[...m],imgs:[...h]};if(yi.current){let e=te().busySendBehavior??`queue`;if((r?.forceBusy??e)===`queue`){Da([...Ta.current,_]),i&&Zo();return}Ea.current=_,i&&Zo(),Po(G.current?.activeId)}else await os(_)}async function os(t){let n=G.current?.activeId;if(!f||!n||si.current.has(n))return;let{content:r,displayContent:i,taskCards:a,files:o,refs:s,imgs:c}=t;Uu(r)||(Mi.current=0),B(null);let l=Date.now(),u={role:`user`,content:r,time:l};i&&(u.displayContent=i),a?.length&&(u.taskCards=a),o.length&&(u.attachments=o),s.length&&(u.refs=s),c.length&&(u.images=c);let p=Qa.current,m=p[p.length-1];m?.role===`assistant`&&!m.content&&!m.reasoning&&(p=p.slice(0,-1));let h=[...p,u],g=new AbortController,_=ee();if(ku(ns(h),f.model,_.contextWindow)){Cr(`上下文较长,正在压缩…(可在右下角中断)`);try{let{messages:e,compacted:t}=await Mu(f,ns(h),{force:!1,signal:g.signal,contextWindow:_.contextWindow});if(t){let t=Date.now();h=e.map((e,n)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:t+n})),Qa.current=h,D(h),G.current&&q(Re(G.current,h,{touchUpdatedAt:!0}))}}catch{}Cr(null)}let v=[...h,{role:`assistant`,content:``,time:l,turnStatus:`running`}];Qa.current=v,D(v),Zo(),di.current=n,si.current.set(n,{abort:g,messages:v}),oi.current=g,No(n,!0),Ya.current=!0,ln(!1);let b=zi(h.map(e=>{let t={role:e.role,content:am(e,{supportsVision:_.supportsVision})},n=(e.reasoningApi??e.reasoning)?.trim();return e.role===`assistant`&&n&&(t.reasoning_content=n),t}),{keepRecentImageMessages:1}),x=Wr,S=Yr,C=Zr,w=Xr,T=!!V.todos,E=!!V.tasks,ne=!!V.projects,re=!!V.iterations,ie=!!V.pmRequirements,ae=!!V.bugs,O=Pi===`planning`,oe=V.pluginDev&&Ee.current?.active?Ee.current:null,k=oe?Kt===`full`?`full`:`readwrite`:O?`readonly`:Kt,se=$r&&k!==`readonly`,ce=ei&&k!==`readonly`,le=Za.current?.workspace?.trim()||``,ue=le?`\n当前工作区:${le}`:``,A=V.knowledgeGen&&we.current?.active?we.current:null,j=!A&&V.caseGen&&P.current?.active?P.current:null;if(j&&(j.requirementBreakdownContext?.entryId||j.businessContext?.systemId)){Cr(`刷新需求拆解与业务地图上下文…`);let e=await _c(j,{getRequirementBreakdown:async e=>kn(e,!0),loadBusinessMap:d});j={...j,requirementBreakdownContext:e.requirementBreakdownContext,businessContext:e.businessContext},P.current=j,_e(j),G.current&&q(Ze(G.current,{caseGen:j})),e.warnings.length&&Se(e.warnings.join(`;`),`error`),Cr(null)}let M=!!(A||j),de=le,N=fe;if(oe)N=Yc(oe,Za.current?.harnessRoot||Za.current?.projectRoot||le);else if(A)N=Uc(A);else if(j){if(!j.promptBody?.trim()){B(`生成测试用例的默认技能尚未就绪,请重新打开插件。`),si.current.delete(n),di.current=null,oi.current=null,No(n,!1),D(e=>e[e.length-1]?.role===`assistant`&&!e[e.length-1]?.content?e.slice(0,-1):e);return}try{N=gt(j,j.docTitle||j.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``)}catch(e){B(e instanceof Error?e.message:String(e)),si.current.delete(n),di.current=null,oi.current=null,No(n,!1);return}}let pe=!(!G.current?.sessions.find(e=>e.id===n)?.uiAuto||M||oe);if(!M){let e=An;if(!oe&&!e.trim()&&V.reports)try{await Kr(!0),e=await qr()}catch{}!oe&&e.trim()&&(N=`${N}\n\n${e.trim()}`),!oe&&Mn.trim()&&(N=`${N}\n\n${Mn.trim()}`);let t=lu({lastUserMessageAt:[...h].reverse().find(e=>e.role===`user`&&e!==h[h.length-1])?.time??[...h].reverse().find(e=>e.role===`user`)?.time??null,lastInjectAt:vi.current});if(t.injected&&(vi.current=t.at),N=`${N}\n\n${t.text}`,C&&!pe)try{let e=await fn();e?.text&&(N=`${N}\n\n${gn}\n\n${e.text}`)}catch{}}pe&&(N=`${N}\n\n${Tn}`);let me=[];if(!M&&!oe&&_.supportsTools)try{me=Rr(await Ir())}catch{me=[]}let he=Yp(N,b,{skillContext:pt?`${pt.name} · ${pt.id} · v${pt.version}\n${pt.text}`:void 0,memory:x&&!M,knowledge:S&&!M,fs:C&&!M,web:w&&!M,bash:se&&!M,pwsh:ce&&!M,interact:!M,todos:T&&!M,tasks:E&&!M,projects:ne&&!M,iterations:re&&!M,pmRequirements:ie&&!M,bugs:ae&&!M,planPhase:M||oe?`off`:Pi,goalEnabled:!M,goal:Oi,scheduleEnabled:!M,subagentEnabled:!M,workflowEnabled:!M,mcpEnabled:me.length>0}).map((e,t)=>t===0&&e.role===`system`&&C&&ue&&!M?{...e,content:`${typeof e.content==`string`?e.content:``}${ue}`}:e);if(x&&!M&&!oe){Cr(`记忆注入中…`);let{context:e}=await Er(r,{cwd:de});if(e&&he[0]?.role===`system`){let t=typeof he[0].content==`string`?he[0].content:``;he=[{...he[0],content:`${t}\n\n${e}`},...he.slice(1)]}Cr(null)}let ge=_.supportsTools?[...hf({access:k,planPhase:M||oe?`off`:Pi,planGatesWrites:O,structuredPlugin:M,mcpTools:me,caps:{knowledge:S,fs:C,web:w,bash:se,pwsh:ce,memory:x,todos:T,tasks:E,projects:ne,iterations:re,pmRequirements:ie,bugs:ae,subagent:!M,workflow:!M,interact:!M,goal:!M,schedule:!M,mcp:me.length>0}}),...pe?Cn:[]]:[],ve=Date.now(),F=0;_i.current.set(n,{start:ve});let ye=0,be=!1,xe=``,I=!1,L,Te=!!(A||j),R={index:1,total:1,label:``};function De(e){return A?Wc(e):ut(e,R.total>1?{index:R.index,total:R.total,label:R.label}:void 0)}function Oe(){return A?`正在编写知识库…`:`正在编写用例…`}let ke=!1;try{let t=``,r=``;if(Te){Cr(Oe());let e=()=>{let e=Math.max(0,Math.floor((Date.now()-ve)/1e3));Uo(t=>({...t,content:De(e)}))};e(),L=window.setInterval(e,1e3)}if(!(T||E||ne||re||ie||ae||pe)&&!Te&&!oe&&await ti(g.signal)){let e=_f(ge);(await ri({sessionId:n,messages:he,settings:{baseURL:f.baseURL,apiKey:f.apiKey,model:f.model,reasoningEffort:f.reasoningEffort},tools:e,thinking:!0,workspace:le||``,access:k})).ok&&(ke=!0,await new Promise(e=>{let t=!1,r=()=>{t||(t=!0,e())},i=()=>{ii(n)};g.signal.addEventListener(`abort`,i),hi.current.get(n)?.();let a=ci(n,0,{signal:g.signal,onEvent:e=>Fo(n,e),onTerminal:e=>{I=e.status===`completed`,g.signal.removeEventListener(`abort`,i),hi.current.delete(n),r()},onGaveUp:e=>{G.current?.activeId===n&&B(e.message||`与服务端回合断开`),Ho(n,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,turnStatus:`stopped`,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n}),g.signal.removeEventListener(`abort`,i),hi.current.delete(n),r()}});hi.current.set(n,()=>{a(),r()})}))}if(!ke){if(j&&Dc(j).length>1){let e=Dc(j);R.total=e.length,R.index=1,R.label=e[0]?.label??``;let t=j.docTitle||j.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``,n={skillContext:pt?`${pt.name} · ${pt.id} · v${pt.version}\n${pt.text}`:void 0,memory:!1,knowledge:!1,fs:!1,web:!1,bash:!1,pwsh:!1,interact:!1,todos:!1,tasks:!1,projects:!1,iterations:!1,pmRequirements:!1,bugs:!1,planPhase:`off`,goalEnabled:!1,goal:null,scheduleEnabled:!1,subagentEnabled:!1,workflowEnabled:!1,mcpEnabled:!1},r=[],i;for(let a of e){if(g.signal.aborted)throw new DOMException(`Aborted`,`AbortError`);R.index=a.index,R.total=a.total,R.label=a.label,Cr(`正在编写用例(第 ${a.index}/${a.total} 批)…`);{let e=Math.max(0,Math.floor((Date.now()-ve)/1e3));Uo(t=>({...t,content:De(e)}))}let e=kc(j,a),o=Yp(gt(e,t,{index:a.index,total:a.total,pointCount:a.ids.length}),b,n),s=``,c=zt(f,o,g.signal,{thinking:!0});for await(let e of c)if(e.type===`usage`){let t=Date.now();i=i?{promptTokens:i.promptTokens+e.usage.promptTokens,completionTokens:i.completionTokens+e.usage.completionTokens,totalTokens:i.totalTokens+e.usage.totalTokens,cachedTokens:(i.cachedTokens??0)+(e.usage.cachedTokens??0),uncachedTokens:(i.uncachedTokens??0)+(e.usage.uncachedTokens??0),cacheWriteTokens:(i.cacheWriteTokens??0)+(e.usage.cacheWriteTokens??0)}:{...e.usage};let n=Xm(i),r=F?(t-F)/1e3:0,a=r>.2&&n>0?n/r:void 0;Uo(e=>({...e,usage:i,tps:a,model:f.model,ttftMs:F?F-ve:e.ttftMs,llmMs:t-ve}))}else F===0&&(e.type===`content`||e.type===`reasoning`||e.type===`reasoning_api`)&&(F=Date.now(),Uo(e=>({...e,ttftMs:F-ve,model:f.model}))),e.type===`reasoning_api`?Uo(t=>({...t,reasoningApi:e.content})):e.type===`reasoning`?(ye===0&&(ye=Date.now()),xe+=e.delta):e.type===`content`&&(s+=e.delta);r.push({index:a.index,total:a.total,raw:s})}L!=null&&(window.clearInterval(L),L=void 0),I=!0,Cr(`正在检测覆盖并入库…`);let a=await dt(r,j,t);if(Uo(e=>({...e,content:a.summary,caseFile:a.ok?{path:a.path,name:a.path.split(`/`).pop()||a.path,count:a.count}:void 0,usage:i??e.usage,llmMs:Date.now()-ve,reasoningDuration:ye>0?Math.max(1,Math.round((Date.now()-ye)/1e3)):e.reasoningDuration})),a.ok&&G.current){let e={...j,active:!1,linkedCasePath:a.path};_e(e),P.current=e,q(Ze(G.current,{caseGen:e}))}}else{let i=zt(f,he,g.signal,{tools:ge.length?ge:void 0,runTool:ge.length?bf(async(t,r)=>{vr(!0);let i=dm(t);Cr(ym(te().toolStepDetail,i,t,`running`));let a=Date.now();try{if(t===`ui_plan_steps`){let e=G.current?.sessions.find(e=>e.id===n)?.uiAuto,i=String(e?.uiautoSessionId||``).trim();return i?await xn(t,r,{sessionId:i,target:`ts`,onPlan:e=>{let t=``;try{let e=JSON.parse(r||`{}`);t=typeof e.title==`string`?e.title.trim():``}catch{}t&&G.current&&q(ct(G.current,n,t));try{window.dispatchEvent(new CustomEvent(Dn,{detail:{uiautoSessionId:i,chatSessionId:n,plan:e,title:t}}))}catch{}}}):JSON.stringify({error:`当前不是脚本编排会话,无法写入步骤栏`})}if(t.startsWith(`kb_`))return await pf(t,r,{base:`/`,docs:e});if(t.startsWith(`fs_`)){let e=await sn(t,r,k),i=ru(t,e);if(i&&G.current){let e=nu(G.current.sessions.find(e=>e.id===n)?.workspaceChanges,i);q(Xe(G.current,n,{workspaceChanges:e}))}return e}if(t.startsWith(`skill_`))return await $c(t,r);if(t===`load_workspace_dependencies`)return await Fi(t);if(t===`office_to_pdf`)return O?JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`}):await ji(t,r,k);if(t.startsWith(`workspace_changes_`)){let e=G.current?.sessions.find(e=>e.id===n),{text:r,next:i}=iu(t,e?.workspaceChanges);return i&&G.current&&q(Xe(G.current,n,{workspaceChanges:i})),r}if(t.startsWith(`working_directory_`)){let{text:e,info:i}=await $t(t,r);return i&&(po(i),t===`working_directory_set`&&G.current&&q(Xe(G.current,n,{workspacePath:i.workspace}))),e}if(t===`present`){if(O)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await on(r,k);try{let t=JSON.parse(e);t.ok&&t.files?.length&&Uo(e=>{let n=e.presentFiles??[],r=new Map(n.map(e=>[e.path,e]));for(let e of t.files)r.set(e.path,e);return{...e,presentFiles:[...r.values()]}})}catch{}return e}if(t===`todo_add`){if(O)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e;try{e=JSON.parse(r||`{}`).items}catch{e=void 0}let t=Bp(`todo`,e);if(!t.length)return JSON.stringify({error:`没有可记录的待办:只有用户明确要求记录待办时才调用 todo_add,并给出待办标题;不要为了弹出卡片而调用工具。`});let n=await Rl(t),i=await ba(`todo`,n.items,{quick:!0,quickNote:n.willCreateRoutine?`确认后会创建任务「日常待办」并关联,状态 / 日期已自动填好`:void 0});if(!i)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增待办,未写入任何数据。`});let a;try{a=await zl(i)}catch(e){return JSON.stringify({error:`创建所属任务失败:${e instanceof Error?e.message:String(e)}`})}r=JSON.stringify({items:Vp(`todo`,a)})}if(t===`task_add`){if(O)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=Bp(`task`,Kl(r));e.length||e.push(zp(`task`));let t=await ba(`task`,e);if(!t)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增任务,未写入任何数据。`});r=JSON.stringify({items:Vp(`task`,t)})}if(t.startsWith(`task_`)){let e=await ql(t,r,{sessionId:n});if(t===`task_add`)try{let t=JSON.parse(e);t.ok&&t.count&&B(`已创建 ${t.count} 个任务,可在侧栏「任务管理」查看。`,`ok`)}catch{}return e}if(t.startsWith(`todo_`)&&t!==`todo_write`){if(O&&t!==`todo_list`)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await Ml(t,r,{sessionId:n});if(t===`todo_add`)try{let t=JSON.parse(e);t.ok&&t.count&&B(`已记录 ${t.count} 条待办,可在侧栏「待办事项」查看。`,`ok`)}catch{}return e}if(t===`todo_write`){let e;try{e=JSON.parse(r||`{}`).todos}catch{return JSON.stringify({error:`invalid JSON arguments`})}let t=pu(e);return G.current?.activeId===n&&Ei(t),G.current&&q(Xe(G.current,n,{todos:t})),JSON.stringify({ok:!0,count:t.length,todos:t})}if(t.startsWith(`pm_`)){if(O&&!t.endsWith(`_list`))return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await Cl(t,r,{sessionId:n});if(t.endsWith(`_add`))try{let n=JSON.parse(e);if(n.ok&&n.count){let e=t.startsWith(`pm_project_`)?`项目列表`:t.startsWith(`pm_iteration_`)?`迭代管理`:t.startsWith(`pm_requirement_`)?`需求管理`:`缺陷管理`,r=t.startsWith(`pm_iteration_`)?`迭代`:t.startsWith(`pm_requirement_`)?`条需求`:t.startsWith(`pm_bug_`)?`条缺陷`:`个项目`;B(`已创建 ${n.count} ${r},可在侧栏「${e}」查看。`,`ok`)}}catch{}return e}if(t.startsWith(`goal_`)){if(t===`goal_get`)return Lu(G.current?.activeId===n?Ai.current:Iu(G.current?.sessions.find(e=>e.id===n)?.goal));if(t===`goal_set`){let e=``;try{e=String(JSON.parse(r||`{}`).text??``).trim()}catch{return JSON.stringify({error:`invalid JSON arguments`})}if(!e)return JSON.stringify({error:`text is required`});let t={text:e.slice(0,500),status:`active`,updatedAt:Date.now()};return G.current?.activeId===n&&(Ai.current=t,ki(t),Mi.current=0),G.current&&q(Xe(G.current,n,{goal:t})),Lu(t)}if(t===`goal_done`){let e=G.current?.activeId===n?Ai.current:Iu(G.current?.sessions.find(e=>e.id===n)?.goal);if(!e?.text)return JSON.stringify({ok:!1,error:`no goal to complete`});let t={...e,status:`done`,updatedAt:Date.now()};return G.current?.activeId===n&&(Ai.current=t,ki(t),Mi.current=0),G.current&&q(Xe(G.current,n,{goal:t})),Lu(t)}return t===`goal_clear`?(G.current?.activeId===n&&(Ai.current=null,ki(null),Mi.current=0),G.current&&q(Xe(G.current,n,{goal:void 0})),JSON.stringify({ok:!0,goal:null})):JSON.stringify({error:`unknown tool: ${t}`})}if(t.startsWith(`schedule_`))return await vd(t,r,n);if(t===`list_agents`||t===`spawn_subagent`||t===`fork_subagent`||t.startsWith(`subagent_`))return await Kd(t,r,{settings:Di(f,te().subagentModel),sessionId:n,parentSignal:g.signal,access:k,fsEnabled:C,webEnabled:w,parentMessages:b,onHint:e=>Cr(e),runFs:(e,t,n)=>sn(e,t,n),runWeb:(e,t)=>br(e,t)});if(t===`workflow`)return await of(t,r,{settings:f,sessionId:n,parentSignal:g.signal,access:k,fsEnabled:C,webEnabled:w,parentMessages:b,onHint:e=>Cr(e),runFs:(e,t,n)=>sn(e,t,n),runWeb:(e,t)=>br(e,t)});if(t===`ask_user_question`){let e=mu(r);if(!e.length)return JSON.stringify({error:`questions is required`});let t={};for(let n of e)t[n.id]={selected:[],text:``};return ta(t),ra(0),aa(!1),sa(null),la(!1),da(``),$i(e),await new Promise((e,t)=>{xi.current={resolve:e,reject:t};let n=oi.current,r=()=>{n?.signal.removeEventListener(`abort`,r),xs()};n?.signal.addEventListener(`abort`,r)})}if(t===`submit_plan`){let e=xu(r);return e?(Xi(`planning`,e,n),await new Promise((e,t)=>{wi.current={resolve:e,reject:t};let n=oi.current,r=()=>{n?.signal.removeEventListener(`abort`,r),Ss()};n?.signal.addEventListener(`abort`,r)})):JSON.stringify({error:`title and steps are required`})}return t===`bash`?await or(r,k):t===`pwsh`?await fr(r,k):t.startsWith(`bash_session_`)?await yr(t,r,k):t.startsWith(`pwsh_session_`)?await hr(t,r,k):t.startsWith(`job_`)?await sr(t,r,k):t.startsWith(`web_`)?await br(t,r):t.startsWith(`memory_`)?await Sr(t,r,de):t.startsWith(`mcp__`)?await Br(t,r):JSON.stringify({error:`unknown tool: ${t}`})}finally{let e=Math.max(0,Date.now()-a);Uo(t=>({...t,toolMs:(t.toolMs??0)+e})),vr(!1),fo()}}):void 0});for await(let e of i){if(e.type===`tool`){let t=dm(e.name);Cr(ym(te().toolStepDetail,t,e.name,e.status===`running`?`running`:`done`));let n=hm(e.name,e.args),r=`tool_${e.name}_${e.args?.slice(0,24)??``}`,i=e.status===`done`&&typeof e.result==`string`&&/^\s*\{\s*"error"\s*:/.test(e.result);Uo(a=>{let o=[...a.activitySteps??[]],s=o.findIndex(e=>e.id===r||e.detail===n&&e.title===t&&e.status===`running`),c={id:r,kind:pm(e.name),title:t,detail:n||void 0,status:e.status===`running`?`running`:i?`error`:`done`};return s>=0?o[s]={...o[s],...c}:o.push(c),{...a,activitySteps:o}});continue}if(e.type===`usage`){let t=Date.now(),n=F?(t-F)/1e3:0,r=Xm(e.usage),i=n>.2&&r>0?r/n:void 0;Uo(n=>({...n,usage:e.usage,tps:i,model:f.model,ttftMs:F?F-ve:n.ttftMs,llmMs:t-ve}));continue}if(F===0&&(F=Date.now(),Uo(e=>({...e,ttftMs:F-ve,model:f.model}))),e.type===`reasoning_api`){Uo(t=>({...t,reasoningApi:e.content}));continue}e.type===`reasoning`&&ye===0&&(ye=Date.now());let n=e.type===`content`&&ye>0&&!be;if(n&&(be=!0),Te){if(e.type===`content`?A?r+=e.delta:t+=e.delta:e.type===`reasoning`&&(xe+=e.delta),n){let e=Math.max(0,Math.floor((Date.now()-ve)/1e3));Uo(t=>({...t,content:De(e),reasoningDuration:Math.max(1,Math.round((Date.now()-ye)/1e3))}))}}else e.type===`reasoning`&&(xe+=e.delta),Uo(t=>{let r=e.type===`reasoning`?{...t,reasoning:It(xe)}:{...t,content:It(t.content+(e.type===`content`?e.delta:``))};if(e.type===`reasoning`){let e=[...r.activitySteps??[]],t=e.findIndex(e=>e.kind===`thinking`),n={id:`thinking`,kind:`thinking`,title:`思考`,detail:vm(r.reasoning??``).replaceAll(`**`,``).slice(0,80)||void 0,status:`running`};t>=0?e[t]={...e[t],...n}:e.unshift(n),r.activitySteps=e}if(n){r.reasoningDuration=Math.max(1,Math.round((Date.now()-ye)/1e3));let e=[...r.activitySteps??[]],t=e.findIndex(e=>e.kind===`thinking`);t>=0&&(e[t]={...e[t],status:`done`}),r.activitySteps=e}return r})}if(I=!0,!Te){let e=[...G.current?.sessions.find(e=>e.id===n)?.messages??[]].reverse().find(e=>e.role===`assistant`);if(e&&typeof e.content==`string`&&!e.content.trim()){let t=typeof e.reasoning==`string`&&!!e.reasoning.trim(),n=(e.activitySteps??[]).some(e=>e.kind===`tool`||e.kind===`fs`);B(t&&n?`模型已跑完工具并完成思考,但没有写出正文(常见于思考过长只想不写)。请回复「继续」补写结论,或缩小改动范围后重试`:t?`模型本轮只输出了思考、没有正文。请重试或回复「继续」`:`模型本轮没有返回正文(可能工具轮次用尽或输出被截断),请重试或回复「继续」`)}}{let e=ye>0&&!be?Math.max(1,Math.round((Date.now()-ye)/1e3)):null;Uo(t=>{let n=(t.activitySteps??[]).map(e=>e.kind===`thinking`&&e.status===`running`?{...e,status:`done`}:e),r={...t,activitySteps:n};return e!=null&&t.reasoning&&t.reasoningDuration==null&&(r.reasoningDuration=e),r})}if(L!=null&&(window.clearInterval(L),L=void 0),A){Cr(`正在质检并入库…`);let e=await qc(r,A);if(Uo(t=>({...t,content:e.summary,docsFile:e.ok?{root:`knowledge`,path:e.path,name:e.path.split(`/`).pop()||e.title||e.path,note:e.category}:void 0})),e.ok&&G.current){let t={...A,active:!1,linkedKnowledgePath:e.path};Ce(t),we.current=t,q(Ze(G.current,{knowledgeGen:t}))}}else if(j){Cr(`正在检测覆盖并入库…`);let e=j.docTitle||j.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``,n=await ht(t,j,e);if(Uo(e=>({...e,content:n.summary,caseFile:n.ok?{path:n.path,name:n.path.split(`/`).pop()||n.path,count:n.count}:void 0})),n.ok&&G.current){let e={...j,active:!1,linkedCasePath:n.path};_e(e),P.current=e,q(Ze(G.current,{caseGen:e}))}}}}ke&&I&&Uo(e=>({...e,turnStatus:e.turnStatus===`stopped`?`stopped`:`completed`,activitySteps:(e.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)}))}catch(e){e instanceof DOMException&&e.name===`AbortError`||G.current?.activeId===n&&B(e instanceof Error?e.message:String(e)),Ho(n,e=>{let t=e[e.length-1];if(t?.role===`assistant`&&!t.content&&!t.reasoning&&!t.activitySteps?.length)return e.slice(0,-1);if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n})}finally{L!=null&&(window.clearInterval(L),L=void 0);let e=Date.now(),t=_i.current.get(n),i=F||t?.firstToken||0;Uo(t=>{let n=t.llmMs??e-ve,r=t.ttftMs??(i?i-ve:void 0),a=r==null?0:Math.max(0,(n-r)/1e3),o=Xm(t.usage),s=t.tps??(a>.2&&o>0?o/a:void 0);return{...t,time:e,model:t.model??f.model,llmMs:n,ttftMs:r,tps:s,turnStatus:t.turnStatus===`stopped`||t.turnStatus===`completed`?t.turnStatus:I?`completed`:(g.signal.aborted||!ke)&&t.turnStatus===`running`?`stopped`:t.turnStatus,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)}}),_i.current.delete(n),si.current.delete(n),hi.current.get(n)?.(),hi.current.delete(n),di.current===n&&(di.current=null),oi.current===g&&(oi.current=null),No(n,!1);{let e=te().toolStepDetail;e===`full`?window.setTimeout(()=>Cr(null),2800):e===`detailed`?window.setTimeout(()=>Cr(null),1200):Cr(null)}if(I&&x&&Tr(r,de).finally(()=>{fo()}),I&&G.current){let e=[...G.current.sessions.find(e=>e.id===n)?.messages??[]].reverse().find(e=>e.role===`assistant`),t=Si({userContent:r,assistantContent:typeof e?.content==`string`?e.content:``,reasoning:e?.reasoning});t.length&&Ci({sessionId:n,model:e?.model??f.model,messages:t})}if(I&&f&&!g.signal.aborted&&G.current){let e=G.current.sessions.find(e=>e.id===n),t=e?.messages??[];if(e&&!Ni.current.has(n)&&ui(e.title,t)){let e=li(t);e&&(Ni.current.add(n),fi(f,e).then(e=>{if(!e||!G.current)return;let t=G.current.sessions.find(e=>e.id===n);if(!t||!ui(t.title,t.messages))return;q(ct(G.current,n,e));let r=String(t.uiAuto?.uiautoSessionId||``).trim();if(r){y(async()=>{let{saveGeneration:e}=await import(`./UiAutoGenerationDialog.D1PyCgrD.js`).then(e=>e.w);return{saveGeneration:e}},__vite__mapDeps([4,1,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])).then(({saveGeneration:t})=>t({sessionId:r,title:e})).catch(()=>void 0);try{window.dispatchEvent(new CustomEvent(Dn,{detail:{uiautoSessionId:r,chatSessionId:n,title:e}}))}catch{}}}))}}let a=G.current?.activeId===n,o=null;if(a){o=Ea.current,Ea.current=null,!o&&Ta.current.length&&(o=Ta.current[0],Da(Ta.current.slice(1)));let e=Ru(Ai.current);if(!o&&!M&&Wu({goalActive:!!e,turnOk:I,aborted:g.signal.aborted,hasFollowUp:!1,askUserPending:!!xi.current,roundsUsed:Mi.current,maxRounds:3})){let t=Mi.current+1;Mi.current=t,o={id:`goal_drv_${Date.now().toString(36)}`,content:Hu(e,t,3),files:[],refs:[],imgs:[]}}}o&&window.setTimeout(()=>{os(o)},0)}}function ss(){Ea.current=null,Da([]),Mi.current=0;let e=G.current?.activeId;e&&Ho(e,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,turnStatus:`stopped`,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n}),Po(e)}function cs(e){Da(Ta.current.filter(t=>t.id!==e))}function ls(e){let t=Ta.current.find(t=>t.id===e);t&&(cs(e),k(t.content),ce(t.files),ue(t.imgs),j(t.refs),requestAnimationFrame(()=>Aa.current?.focus()))}function us(e){let t=Ta.current.find(t=>t.id===e);t&&(Da(Ta.current.filter(t=>t.id!==e)),yi.current?(Ea.current=t,Po(G.current?.activeId)):os(t))}function ds(e){let t=[...Ta.current],n=e??t.shift()??null;n&&(Da(t),yi.current?(Ea.current=n,Po(G.current?.activeId)):os(n))}function fs(e,t){let n=!(Qa.current[e]?.reasoningOpen??!1);if(zo(t=>t.map((t,n)=>n===e?{...t,reasoningOpen:!t.reasoningOpen}:t)),n){let e=t.currentTarget;requestAnimationFrame(()=>{(e.nextElementSibling??e).scrollIntoView({block:`nearest`,behavior:`smooth`})})}}function ps(e){e&&(O.trim()||se.length>0||le.length>0||A.length>0?za.current[e]={input:O,attachments:se,images:le,docRefs:A}:delete za.current[e],Xt(e,O))}function ms(e){let t=e?za.current[e]:void 0,n=t?.input??Yt(e);qo(n),k(n),ce(t?.attachments??[]),ue(t?.images??[]),j(t?.docRefs??[]),Ui(Ne(e))}function hs(e){e?.abortRun!==!1&&Po(G.current?.activeId),yi.current=!1,Pt(!1),ce([]),ue([]),j([]),Ui([]),Wi(null),qo(``),k(``),B(null),ln(!1),Ya.current=!0,e?.clearDraft&&G.current?.activeId&&(delete za.current[G.current.activeId],Zt(G.current.activeId))}function gs(e,t){if(!G.current)return;pr(`dialog`);let n=G.current.activeId,r=G.current.sessions.find(e=>e.id===n),i=!!r&&!r.archived&&!r.deleted&&(!Array.isArray(r.messages)||r.messages.length===0),a=n=>({...n,title:n.title?.trim()||`新对话`,caseGen:e===`caseGen`?t:void 0,knowledgeGen:e===`knowledgeGen`?t:void 0,updatedAt:Date.now()}),o;if(i&&n)hs({clearDraft:!0,abortRun:!1}),o={...G.current,activeId:n,sessions:G.current.sessions.map(e=>e.id===n?a(e):e)};else{ps(n),hs({clearDraft:!0,abortRun:!1});let e=To(n)??G.current,t=H?.workspace?.trim()||void 0;o=tt(e,{workspacePath:t,access:T()});let r=o.activeId;o={...o,sessions:o.sessions.map(e=>e.id===r?a(e):e)}}q(o),D([]),_e(e===`caseGen`?t:null),P.current=e===`caseGen`?t:null,Ce(e===`knowledgeGen`?t:null),we.current=e===`knowledgeGen`?t:null,(e===`caseGen`||e===`knowledgeGen`)&&k(``);let s=o.sessions.find(e=>e.id===o.activeId)?.workspacePath||H?.workspace?.trim()||H?.projectRoot;s&&Zn(e=>({...e,[s]:!0})),go(o.sessions.find(e=>e.id===o.activeId));let c=()=>Aa.current?.focus();requestAnimationFrame(c),window.setTimeout(c,320)}async function _s(e){let t=G.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId),r=Za.current?.harnessRoot?.trim()||Za.current?.projectRoot?.trim()||Za.current?.workspace?.trim(),i=n?.pluginDev?.active?n.pluginDev:{active:!0,requirement:e.trim(),confirmedAt:Date.now()};if(q(Ze(t,{pluginDev:i,access:Kt===`full`?`full`:`readwrite`,...r?{workspacePath:r}:{}})),R(i),Ee.current=i,De.current=null,Ss(),Ii(`off`),r&&Zn(e=>({...e,[r]:!0})),Zr&&r&&Za.current?.workspace!==r)try{po(await vn(r))}catch{}}function vs(e){if(e?.active){gs(`caseGen`,e);return}let t=P.current,n=t?.linkedCasePath?{...t,active:!1}:void 0;_e(n??null),P.current=n??null,G.current&&q(Ze(G.current,{caseGen:n}))}function ys(e){if(e?.active){gs(`knowledgeGen`,e);return}let t=we.current,n=t?.linkedKnowledgePath?{...t,active:!1}:void 0;Ce(n??null),we.current=n??null,G.current&&q(Ze(G.current,{knowledgeGen:n}))}function bs(e){if(!G.current)return;pr(`dialog`);let t=G.current.activeId;ps(t),hs({clearDraft:!0,abortRun:!1});let n=To(t)??G.current;G.current=n;let r=e?.trim()||H?.workspace?.trim()||void 0,i=tt(n,{workspacePath:r,access:T()});G.current=i,i=Eo(i.activeId),q(i),D([]),_e(null),Ce(null),R(null),Ee.current=null,Ei([]),Ai.current=null,ki(null),Mi.current=0,Ii(`off`),Ri(e=>e===`pluginDev`?null:e),xs(),Ss();let a=r||H?.projectRoot;a&&Zn(e=>({...e,[a]:!0})),go(i.sessions.find(e=>e.id===i.activeId))}function xs(){let e=xi.current;e&&(xi.current=null,$i(null),ta({}),ra(0),aa(!1),sa(null),la(!1),da(``),e.resolve(JSON.stringify({canceled:!0,error:`user aborted`})))}function Ss(){let e=wi.current;e?(wi.current=null,Xi(Pi===`off`?`off`:`planning`,null),e.resolve(JSON.stringify({approved:!1,canceled:!0}))):qi&&Xi(Pi===`approved`?`approved`:`planning`,null)}function Cs(){let e=wi.current;wi.current=null,Xi(`approved`,null),e?.resolve(JSON.stringify({approved:!0,message:`用户已批准计划,可以开始实施`}))}function ws(){let e=wi.current;wi.current=null,Xi(`planning`,null),e?.resolve(JSON.stringify({approved:!1,message:`用户驳回了计划,请修订后再次 submit_plan`}))}function Ts(){Pi===`off`?Xi(`planning`,null):(Ss(),Xi(`off`,null))}function Es(e,t){return!e||!t?!1:t.skipped||t.text.trim()!==``?!0:e.options?.length?t.selected.length>0:!1}function Ds(e,t,n){let r=xi.current;if(!r)return;xi.current=null,$i(null),ta({}),ra(0),aa(!1),sa(null),la(!1),da(``),B(null);let i=t.filter(e=>e.skipped).length,a=String(n?.skipReason??``).trim();r.resolve(JSON.stringify({answers:t,summary:_u(e,t),...i?{skipped:!0,approvalRequired:!0,...a?{skipReason:a}:{},note:`用户跳过了部分或全部问题:跳过的题不算确认,也未批准实施。`+(a?`用户给出的跳过原因:${a}。`:``)+`本轮只允许只读调研与文字方案,禁止 fs_write / fs_mkdir / 改配置;请先说明采用的默认假设(哪几项按推荐)与准备改动的范围`+(a?`,并针对上述原因给出调整`:``)+`,然后等用户明确回复「开始实施」再动手。`}:{note:`answers 为结构化答案;summary 是同一批答案的中文文本版本,可直接据此继续,无需再次提问。`},...n}))}function Os(e,t,n){ta(r=>{let i=r[e.id]??{selected:[],text:``},a=e.multi_select?n?i.selected.filter(e=>e!==t):[...i.selected,t]:[t];return{...r,[e.id]:{selected:a,text:``,skipped:!1}}}),sa(null),e.multi_select||ra(e=>Math.min(e+1,(Qi?.length??1)-1))}function X(e){let t=Qi?.length??0;t&&(ra(Math.max(0,Math.min(e,t-1))),sa(null))}function ks(e,t){e&&(ta(n=>{let r=n[e.id]??{selected:[],text:``};return{...n,[e.id]:{selected:e.multi_select?r.selected:[],text:t,skipped:!1}}}),sa(null))}function As(e,t){let n=t.trim(),r=n&&e.options?.length?hu(e,n):null,i=r?{selected:r,text:``,skipped:!1}:{selected:e.multi_select?ea[e.id]?.selected??[]:[],text:n,skipped:!1},a={...ea,[e.id]:i};ta(a),sa(null),Bc?Ms(a):X(Lc+1)}function js(e){return(Qi??[]).map(t=>{let n=gu(t,e[t.id]??{selected:[],text:``});return n.skipped||n.text?.trim()||n.selected?.length?n:{id:t.id,selected:[],skipped:!0}})}function Ms(e=ea,t=!1){let n=Qi;if(!n?.length||!xi.current)return!1;let r=js(e),i=r.findIndex(e=>!e.skipped&&!e.text?.trim()&&!e.selected?.length);if(i>=0)return X(i),sa(n[i]?.options?.length?`请先选择选项再提交`:`请先填写回答再提交`),!1;if(!t&&r.some(e=>e.skipped))return la(!0),sa(null),!1;let a=ua.trim();return Ds(n,r,a?{skipReason:a}:void 0),!0}function Ns(){let e=Qi,t=Rc;if(!e?.length||!t)return;let n={...ea,[t.id]:{selected:[],text:``,skipped:!0}};ta(n),sa(null),Bc?Ms(n):X(Lc+1)}function Ps(){Ms(ea,!0)}function Fs(){la(!1);let e=js(ea).findIndex(e=>e.skipped);X(e>=0?e:0)}function Is(e){if(!G.current)return;lr(null),Ot(null);let t=G.current.activeId;ps(t),xs(),Ss(),Ii(`off`),B(null);let n=To(t)??G.current;G.current=n;let r=new Set(n.sessions.map(e=>e.id)),i=at(n,e,{activate:!0}),a=i.sessions.find(e=>!r.has(e.id));if(!a)return;let o=a.id;q(i);let s=i.sessions.find(e=>e.id===o),c=s?.messages??[];Qa.current=c,D(c),yi.current=!1,Pt(!1),oi.current=null,_e(s?.caseGen?.active?s.caseGen:null),Ce(s?.knowledgeGen?.active?s.knowledgeGen:null),R(s?.pluginDev?.active?s.pluginDev:null),Ee.current=s?.pluginDev?.active?s.pluginDev:null,Ei(Array.isArray(s?.todos)?s.todos:[]),Ai.current=s?.goal??null,ki(s?.goal??null),Mi.current=0,Xi(`off`,null,o),Ri(null),ms(o);let l=s?.workspacePath||H?.projectRoot;l&&Zn(e=>({...e,[l]:!0})),go(s)}function Ls(e){if(!G.current)return;pr(`dialog`),lr(null);let t=so.current.get(e);if(t!=null&&(clearTimeout(t),so.current.delete(e)),io.current.has(e)&&(io.current.delete(e),oo([...io.current])),e===G.current.activeId)return;let n=G.current.activeId;if(ps(n),xs(),wi.current){let e=wi.current;wi.current=null,e.resolve(JSON.stringify({approved:!1,canceled:!0,reason:`switched session`}))}Yi(n,Pi,qi,{touchUpdatedAt:!1}),B(null),ln(!1),Ya.current=!0;let r=To(n)??G.current;G.current=r,r=Eo(e),G.current=r,r.sessions.some(t=>t.id===e)||(r=G.current);let i=Be(r,e),a=i.sessions.find(t=>t.id===e),o=si.current.get(e)?.messages??a?.messages??[];eo.current=null,to.current=null,no.current!=null&&(clearTimeout(no.current),no.current=null),Qa.current=o,ro.current=!0,D(o);let s=si.current.has(e)||Ft.includes(e);yi.current=s,Pt(s),oi.current=si.current.get(e)?.abort??null,s&&!si.current.has(e)&&!hi.current.has(e)&&Io(e,0),_e(a?.caseGen?.active?a.caseGen:null),Ce(a?.knowledgeGen?.active?a.knowledgeGen:null),R(a?.pluginDev?.active?a.pluginDev:null),Ri(e=>a?.pluginDev?.active?`pluginDev`:e===`pluginDev`?null:e),Ei(pu(a?.todos));{let e=Iu(a?.goal);Ai.current=e,ki(e),Mi.current=0}Zi(a),ms(e),q(i),go(a)}(0,U.useEffect)(()=>{t&&n&&h&&G.current?.activeId!==n&&Ls(n)},[t,n,h]),(0,U.useEffect)(()=>{if(!t||!h)return;let e=G.current,r=n||e?.activeId,i=`readwrite`;if(e&&r){let t=e.sessions.find(e=>e.id===r);if(t){let n=e;a&&t.workspacePath!==a&&(n=He(n,r,a)),i=t.uiAuto?`readonly`:`readwrite`,t.access!==i&&(n=Xe(n,r,{access:i})),n!==e&&q(n)}}if(qt(i),!a||!Zr||Jn)return;let o=Za.current;o&&o.workspace===a||(Yn(!0),vn(a).then(e=>po(e)).catch(()=>void 0).finally(()=>Yn(!1)))},[t,h,a,n,Zr]),(0,U.useEffect)(()=>{if(!t)return;let e=e=>{let t=e.detail?.sessionId;t&&t===G.current?.activeId&&(si.current.has(t)||Ge({preferSessionId:t}).then(e=>{let n=e.sessions.find(e=>e.id===t);if(!n)return;G.current=e,v(e);let r=si.current.get(t)?.messages;D(r??n.messages??[])}).catch(()=>void 0))};return window.addEventListener(`lantern:chat-session-updated`,e),()=>window.removeEventListener(`lantern:chat-session-updated`,e)},[t]);function Rs(e){if(!G.current)return;lr(null),Ot(null);let t=G.current.activeId===e;t&&hs({clearDraft:!0}),delete za.current[e],Zt(e),Ae(e,[]);let n=it(G.current,e);if(q(n),t){let e=n.sessions.find(e=>e.id===n.activeId);D(e?.messages??[]),_e(e?.caseGen?.active?e.caseGen:null),Ce(e?.knowledgeGen?.active?e.knowledgeGen:null),R(e?.pluginDev?.active?e.pluginDev:null),Ri(t=>e?.pluginDev?.active?`pluginDev`:t===`pluginDev`?null:t)}}function zs(e,t){if(!G.current)return;lr(null);let n=G.current.activeId===e&&t;n&&hs();let r=Ye(G.current,e,t);if(q(r),n){let e=r.sessions.find(e=>e.id===r.activeId);D(e?.messages??[])}}function Bs(e){if(!G.current)return;let t=G.current.sessions.find(t=>t.id===e);t&&(lr(null),q(Ve(G.current,e,!t.pinned)))}function Vs(e){G.current&&G.current.sessions.some(t=>t.id===e)&&(lr(null),Ot(null),Ct(e))}function Hs(){let e=G.current?.activeId,t=G.current?.sessions.find(t=>t.id===e);t?B(bi(`stats`,t.id,t.updatedAt,()=>mi(pi(t))),`ok`):B(`无活跃会话可统计`)}function Us(e){G.current&&St&&(Ni.current.add(St),q(ct(G.current,St,e)),Ct(null))}function Ws(){mn(e=>(Ue(!e),!e))}async function Gs(e){let t=Array.from(e.target.files??[]);e.target.value=``,await $s(t)}function qs(e){[...e.dataTransfer.types].includes(`Files`)&&(e.preventDefault(),N.current+=1,de(!0))}function Js(e){([...e.dataTransfer.types].includes(`Files`)||N.current!==0)&&(e.preventDefault(),N.current=Math.max(0,N.current-1),N.current===0&&de(!1))}function Ys(e){[...e.dataTransfer.types].includes(`Files`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)}function Xs(e){e.preventDefault(),N.current=0,de(!1);let t=Array.from(e.dataTransfer.files??[]);t.length&&$s(t)}function Zs(){let t=e.map(e=>({collection:e.collection,path:e.path,title:e.title,category:e.category,format:String(e.format)})),n=Hr.map(e=>({collection:`workspace`,path:e.path,title:e.name,category:yn(H?.workspace,H?.projectRoot),format:e.type===`dir`?`dir`:`file`}));return[...t,...n]}function Qs(e){e.length&&j(t=>{let n=[...t];for(let t of e){if(n.length>=em)break;n.some(e=>e.collection===t.collection&&e.path===t.path)||n.push(t)}return n})}async function $s(e,t){let n=[],r=[],i=[],a=cm(se,le);for(let o of e)if(a>=6)i.push(`${o.name}(最多 6 个文件)`);else try{let e=await Xf(o);e.kind===`image`?r.push(await sm(e.file)):n.push({name:e.name,size:e.size,content:e.content,path:t?.get(o.name)||t?.get(e.name)}),a+=1}catch(e){i.push(e instanceof Error?e.message:String(e))}n.length&&ce(e=>[...e,...n]),r.length&&ue(e=>[...e,...r]),B(i.length?`以下文件未添加:${i.join(`、`)}`:null),Aa.current?.focus()}function ec(e){let t=e.clipboardData;if(!t)return;let n=Array.from(t.items??[]),r=n.filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.filter(e=>e.kind===`file`&&!e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e);for(let e of Array.from(t.files??[]))e.type.startsWith(`image/`)?r.some(t=>t.name===e.name&&t.size===e.size)||r.push(e):i.some(t=>t.name===e.name&&t.size===e.size)||i.push(e);let a=ap(t),o=(t.getData(`text/plain`)||``).trim(),s=Zs(),c=yn(H?.workspace,H?.projectRoot),l={projectRoot:H?.projectRoot,workspace:H?.workspace,workspaceLabel:c},u=[],d=new Map;for(let e of a){let t=cp(e,l);t?(u.push(t),d.set($f(e),t.path)):d.set($f(e),e)}let f=null;!r.length&&!i.length&&!a.length&&rp(o)&&(f=lp(o,s));let p=[],m=[];for(let e of i){let t=d.get(e.name),n=(t?cp(t,l):null)||lp(e.name,s);n?p.push(n):m.push(e)}(u.length>0||p.length>0||f||r.length>0||m.length>0)&&(e.preventDefault(),B(null),Qs([...u,...p,...f?[f]:[]]),r.length&&Go(r),m.length&&$s(m,d),Aa.current?.focus())}function tc(e){let t=e.target.closest(`[data-copy-code]`);t&&eh(t.closest(`.code-block`)?.querySelector(`pre`)?.textContent??``).then(e=>{e&&(t.textContent=`已复制`,window.setTimeout(()=>{t.textContent=`复制`},1e3))})}let nc=x.length===0,rc=n||_?.activeId,ic=!!(t||rc&&_?.sessions.find(e=>e.id===rc)?.uiAuto),ac=!!(O.trim()||se.length||A.length||le.length||Hi.length||Li===`reports`||ge?.active&&V.caseGen),oc=-1,sc=-1;x.forEach((e,t)=>{e.role===`user`?oc=t:e.role===`assistant`&&(sc=t)});let cc=e=>e===oc||e===sc?``:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity`,lc=um.find(e=>e.value===Kt)??um[0],uc=Li===`pluginDev`,dc=(_?.sessions??[]).filter(e=>!e.archived&&!e.deleted),fc=(_?.sessions??[]).filter(e=>e.archived&&!e.deleted),pc=H?.items??[],mc=new Set(pc.map(e=>e.path)),hc=H?.workspace??``,gc=H?.projectRoot??``,vc=_?.sessions.find(e=>e.id===_.activeId),yc=vc?.workspacePath,bc=!yc||!mc.has(yc),xc=a||H?.workspace?.trim()||``,Sc=pc.find(e=>e.path===xc),Cc=a?i?.trim()||yn(a,gc)||`当前项目`:Sc?tn(Sc,gc):xc?yn(xc,gc):`工作区`,wc=$n.trim().toLowerCase(),Tc=(0,U.useMemo)(()=>wc?new Set(Zl(_,$n,{limit:50,includeArchived:!0}).map(e=>e.sessionId)):null,[wc,_,$n]),[Ec,Oc]=(0,U.useState)(null);(0,U.useEffect)(()=>{if(!wc){Oc(null);return}let e=!1;return Oc(null),Ql($n,{limit:50,includeArchived:!0}).then(t=>{!e&&t?.hits&&Oc(new Set(t.hits.map(e=>e.sessionId)))}),()=>{e=!0}},[wc,$n]);let Ac=Ec??Tc,jc=Ac?fc.filter(e=>Ac.has(e.id)):fc;function Mc(e){let t=e.id===`ws_project`||e.path===gc;return st(dc.filter(n=>!(n.workspacePath!==e.path&&(!t||n.workspacePath&&mc.has(n.workspacePath)))).filter(e=>!Ac||Ac.has(e.id)))}let Nc=pc.filter(e=>!wc||e.name.toLowerCase().includes(wc)||e.path.toLowerCase().includes(wc)?!0:Mc(e).length>0);function Pc({s:e,nested:t=!1}){let n=e.id===_?.activeId,r=cr===e.id,i=Ft.includes(e.id),a=ao.includes(e.id);return(0,Z.jsx)(Vm,{s:e,nested:t,active:n,menuOpen:r,busy:i,exiting:a,onOpen:()=>Ls(e.id),onRename:()=>Vs(e.id),onToggleMenu:()=>{Ot(null),lr(r?null:e.id)},onTogglePin:()=>Bs(e.id),onToggleArchive:()=>zs(e.id,!e.archived),onExport:()=>{lr(null);let t=Qu(e,`json`);B(t.ok?`已导出 ${t.filename}`:t.error)},onFork:()=>Is(e.id),onRemove:()=>{lr(null),Ot(null),Tt(e.id)}})}let Ic=Qi?.length??0,Lc=Math.max(0,Math.min(na,Ic-1)),Rc=Qi?.[Lc],zc=Rc&&ea[Rc.id]||{selected:[],text:``},Bc=Lc>=Ic-1,Vc=Es(Rc,zc),Hc=(Qi??[]).map((e,t)=>({q:e,index:t})).filter(({q:e})=>ea[e.id]?.skipped);return(0,Z.jsxs)(`div`,{className:`tw-app h-full min-h-0 flex overflow-hidden ${t?`bg-(--tw-surface-panel)`:`bg-(--tw-surface-page)`}`,children:[t?null:(0,Z.jsxs)(`aside`,{className:`tw-session-rail shrink-0 border-r border-(--tw-border) flex flex-col transition-[width] ${dn?`w-64`:`w-10`}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 ${dn?`px-2.5 pt-2.5`:`px-1 pt-2 justify-center`}`,children:[dn&&(0,Z.jsx)(`div`,{className:`flex-1 min-w-0 text-[13px] font-medium text-stone-700 truncate px-1`,children:Qt(`chat.workbench`,void 0,mr.language)}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":dn?`收起侧栏`:`展开侧栏`,onClick:Ws,className:`w-8 h-8 shrink-0 flex items-center justify-center rounded-lg text-stone-500 hover:bg-stone-200/70`,children:(0,Z.jsx)($,{className:`w-4 h-4`,children:dn?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Z.jsx)(`path`,{d:`M9 3v18`})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Z.jsx)(`path`,{d:`M15 3v18`})]})})})]}),dn?(0,Z.jsx)(`div`,{className:`px-2.5 pt-2 space-y-1.5`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>bs(),className:`w-full h-9 flex items-center justify-center gap-1.5 text-[13px] font-medium text-stone-700 bg-white rounded-full border border-stone-200/80 shadow-sm hover:bg-stone-50 transition-colors`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]}),Qt(`chat.newSession`,void 0,mr.language)]})}):(0,Z.jsx)(`div`,{className:`px-1 pt-1 flex flex-col gap-1`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:()=>bs(),"data-hint":`新会话`,className:`w-8 h-8 flex items-center justify-center rounded-lg text-[#4176e6] hover:bg-white/80`,children:(0,Z.jsxs)($,{className:`w-4 h-4`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]})})}),dn&&(0,Z.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-2 py-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5 pb-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 text-[12px] font-semibold text-stone-500`,children:Qt(`chat.workspace`,void 0,mr.language)}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`搜索`,onClick:()=>{ir(e=>!e),nr&&er(``)},className:`w-6 h-6 flex items-center justify-center rounded text-stone-400 hover:text-stone-700 hover:bg-stone-200/70`,children:(0,Z.jsx)(jm,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":Zr?`添加工作区(选择本地文件夹)`:`本地文件服务未就绪`,disabled:!Zr||Jn,onClick:()=>void vo(),className:`w-6 h-6 flex items-center justify-center rounded text-stone-400 hover:text-stone-700 hover:bg-stone-200/70 disabled:opacity-40`,children:(0,Z.jsx)(Mm,{className:`w-3.5 h-3.5`})})]}),nr&&(0,Z.jsx)(`input`,{value:$n,onChange:e=>er(e.target.value),placeholder:`搜索工作区 / 会话标题 / 消息`,className:`w-full mb-2 px-2.5 py-1.5 text-[12px] rounded-lg border border-stone-200 bg-white text-stone-700 placeholder:text-stone-400 focus:outline-none focus:ring-1 focus:ring-[#4176e6]/40`}),Qr&&(0,Z.jsx)(`div`,{className:`px-1.5 py-2 text-[11px] text-amber-700/80`,children:`本地文件服务未就绪,工作区暂不可用`}),(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[Nc.map(e=>{let t=Mc(e),n=Xn[e.path]===void 0?t.length>0&&e.path===hc:!!Xn[e.path],r=e.id===`ws_project`||e.path===gc,i=hc?e.path===hc:!!(vc&&(bc?r:yc===e.path)),a=Dt===e.id;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`tw-project-row group relative ${i?`is-active`:``} ${n?`is-expanded`:``} ${a?`is-menu-open`:``}`,children:[(0,Z.jsxs)(`button`,{type:`button`,"data-hint":e.path,onClick:t=>{t.stopPropagation(),lr(null),Ot(null);let r=!n;Zn(r?()=>{let t={};for(let n of pc)t[n.path]=n.path===e.path;return t}:t=>({...t,[e.path]:!1})),r&&Zr&&e.path!==hc&&mo(e.path,`select`)},className:`flex-1 min-w-0 h-full flex items-center gap-1.5 text-left outline-none focus:outline-none`,children:[(0,Z.jsx)(`span`,{className:`tw-slot tw-folder`,children:(0,Z.jsx)(km,{open:n,className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`span`,{className:`tw-slot tw-chevron`,children:(0,Z.jsx)(Am,{open:n,className:`w-3 h-3`})}),(0,Z.jsx)(`span`,{className:`tw-project-title`,children:tn(e,gc)})]}),(0,Z.jsxs)(`div`,{className:`tw-ws-actions relative shrink-0`,"data-ws-menu":``,children:[(0,Z.jsx)(zm,{open:a,onToggle:()=>{lr(null),Ot(a?null:e.id)},onRename:()=>{lr(null),Ot(null),Mt(e.id)},onDelete:e.id===`ws_project`?void 0:()=>bo(e)}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`在此工作区新建会话`,onClick:t=>{t.stopPropagation(),bs(e.path)},className:`w-6 h-6 flex items-center justify-center rounded text-(--tw-label-tertiary) hover:text-(--tw-label-primary) hover:bg-(--tw-session-hover-bg)`,children:(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]})})]})]}),(0,Z.jsx)(`div`,{className:`tw-collapse ${n?`is-open`:``}`,children:(0,Z.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5 pb-0.5`,children:t.length?t.map(e=>(0,Z.jsx)(Pc,{s:e,nested:!0},e.id)):(0,Z.jsx)(`div`,{className:`tw-session-empty text-(--tw-label-tertiary)`,children:`该工作区还没有会话`})})})]},e.id)}),!Nc.length&&Zr&&(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-stone-400`,children:`暂无工作区`})]}),jc.length>0&&(0,Z.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-stone-200/60`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>En(e=>!e),className:`w-full flex items-center gap-1 px-1.5 pb-1 text-[11px] text-stone-400 hover:text-stone-600`,children:[(0,Z.jsx)(bm,{className:`w-3 h-3 transition-transform ${bn?`rotate-180`:``}`}),`已归档 (`,jc.length,`)`]}),(0,Z.jsx)(`div`,{className:`tw-collapse ${bn?`is-open`:``}`,children:(0,Z.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5`,children:jc.map(e=>(0,Z.jsx)(Pc,{s:e},e.id))})})]})]}),dn&&(hc||_r||xr)&&(0,Z.jsxs)(`div`,{className:`shrink-0 border-t border-stone-200/60 px-3 py-2 space-y-1`,children:[hc&&(0,Z.jsxs)(`div`,{className:`tw-rail-workspace-footer`,"data-hint":hc,children:[(0,Z.jsx)(`span`,{className:`tw-rail-workspace-label`,"data-i18n":`chat.workspace`,children:`工作区`}),(0,Z.jsx)(`span`,{className:`tw-rail-workspace-name`,children:yn(hc,gc)})]}),(_r||xr)&&(0,Z.jsx)(`div`,{className:`text-[11px] text-(--tw-accent)`,children:xr??Qt(`tool.running`,void 0,mr.language)})]})]}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex flex-col flex-1`,children:[pt||vt||bt?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-(--tw-border) px-6 py-2 text-xs text-(--tw-label-secondary)`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:vt?`正在加载技能…`:bt||`本次技能:${pt?.name} · v${pt?.version}`}),(0,Z.jsx)(`a`,{href:`/plugins/?tab=skills`,className:`text-(--tw-accent)`,children:`配置技能`}),(0,Z.jsx)(`button`,{onClick:()=>{_t(null),ft(``),xt(``);let e=new URL(location.href);e.searchParams.delete(`skill`),history.replaceState(null,``,e)},children:`取消关联`})]}):null,!nc&&!t?(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-(--tw-border) bg-(--tw-surface-page)`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-3 px-6 pt-4 pb-2 min-w-0`,children:(0,Z.jsx)(`button`,{type:`button`,"data-hint":`点击重命名`,onClick:()=>{let e=_?.activeId;e&&Vs(e)},className:`min-w-0 flex-1 text-left text-[18px] leading-7 font-semibold text-(--tw-label-primary) truncate hover:text-[#4176e6] transition-colors`,children:(()=>{let e=_?.sessions.find(e=>e.id===_.activeId)?.title||`新对话`;return _?.sessions.find(e=>e.id===_.activeId)?.uiAuto?wn(e):e})()})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-6 px-6`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>pr(`dialog`),className:`relative h-10 text-sm transition-colors ${ur===`dialog`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`对话`,ur===`dialog`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>pr(`thread`),className:`relative h-10 text-sm transition-colors ${ur===`thread`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`回合`,ur===`thread`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),V.memory&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>pr(`memory`),className:`relative h-10 text-sm transition-colors ${ur===`memory`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`记忆`,(Pn?.suggestionCount??0)>0?(0,Z.jsx)(`span`,{className:`min-w-4.5 h-4.5 px-1 inline-flex items-center justify-center rounded-full bg-red-500 text-[10px] font-medium text-white tabular-nums leading-none`,"data-hint":`${Pn?.suggestionCount} 条待确认`,children:Pn.suggestionCount>99?`99+`:Pn.suggestionCount}):null]}),ur===`memory`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),V.todos&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>pr(`todos`),className:`relative h-10 text-sm transition-colors ${ur===`todos`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`待办`,ur===`todos`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]})]}),Oi&&Oi.status!==`cleared`&&ur===`dialog`?(0,Z.jsx)(`div`,{className:`px-6 pb-2`,children:(0,Z.jsxs)(`div`,{className:`rounded-xl border border-[#4176e6]/25 bg-[#f5f8ff] px-3 py-2 flex items-start gap-2`,children:[(0,Z.jsxs)(`span`,{className:`text-[11px] font-medium text-[#4176e6] shrink-0 pt-0.5`,children:[`目标`,Oi.status===`done`?`·完成`:``]}),(0,Z.jsx)(`span`,{className:`flex-1 min-w-0 text-[12px] leading-5 ${Oi.status===`done`?`text-stone-400 line-through`:`text-stone-800`}`,children:Oi.text}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`清除目标`,className:`text-[11px] text-stone-400 hover:text-stone-600 shrink-0`,onClick:()=>{Ai.current=null,ki(null),Mi.current=0,G.current&&q(Ze(G.current,{goal:void 0}))},children:`清除`})]})}):null,Ti.length>0&&ur===`dialog`?(0,Z.jsx)(`div`,{className:`px-6 pb-3`,children:(0,Z.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white px-3 py-2.5`,children:[(0,Z.jsxs)(`div`,{className:`text-[11px] font-medium text-stone-500 mb-1.5`,children:[`待办 · `,Ti.filter(e=>e.status===`completed`).length,`/`,Ti.length]}),(0,Z.jsx)(`ul`,{className:`space-y-1 max-h-28 overflow-y-auto`,children:Ti.map((e,t)=>(0,Z.jsxs)(`li`,{className:`flex items-start gap-2 text-[12px] text-stone-700`,children:[(0,Z.jsx)(`span`,{className:`mt-0.5 w-3.5 h-3.5 rounded-sm border shrink-0 flex items-center justify-center text-[9px] ${e.status===`completed`?`bg-emerald-500 border-emerald-500 text-white`:e.status===`in_progress`?`border-[#4176e6] text-[#4176e6]`:`border-stone-300 text-transparent`}`,"aria-hidden":!0,children:e.status===`completed`?`✓`:e.status===`in_progress`?`…`:``}),(0,Z.jsx)(`span`,{className:e.status===`completed`?`line-through text-stone-400`:``,children:e.content})]},`${t}-${e.content}`))})]})}):null]}):null,ur===`todos`&&V.todos?(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Z.jsx)(Mp,{})},`todos-${_?.activeId??``}`):ur===`memory`&&V.memory?(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Z.jsx)(Sp,{live:Wr,pluginOn:!!V.memory,workspacePath:_?.sessions.find(e=>e.id===_.activeId)?.workspacePath||H?.projectRoot||``,onHealthChange:e=>Fn(e)})},`memory-${_?.activeId??``}`):ur===`thread`?(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter overflow-y-auto px-4 py-3 sm:px-8 lg:px-12`,children:(0,Z.jsx)(sh,{messages:x,busy:!!(_?.activeId&&Ft.includes(_.activeId)),onRestoreCheckpoint:(e,t)=>{let n=G.current?.activeId;if(!n)return;if(Ft.includes(n)||Nt){B(`请等待当前回复结束后再从此处继续`);return}let r=Math.max(0,Math.min(e,Qa.current.length-1)),i=Qa.current.slice(0,r+1);Qa.current=i,D(i),G.current&&q(Re(G.current,i,{touchUpdatedAt:!0}));let a=`请从第 ${t} 轮继续`;pr(`dialog`),k(a),B(`已回到第 ${t} 轮,正在继续…`,`ok`),window.setTimeout(()=>{as(a)},0)}})},`thread-${_?.activeId??``}`):(0,Z.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col${nc?` justify-center`:``}`,children:[nc&&!t?(0,Z.jsxs)(`div`,{className:`shrink-0 flex flex-col items-center text-center px-8 sm:px-10 lg:px-12 pb-8`,children:[(0,Z.jsx)(`img`,{src:`/brand/brand-mark.png`,alt:``,width:64,height:64,className:`w-16 h-16 rounded-[14px] object-contain`}),(0,Z.jsx)(`h2`,{className:`mt-5 text-[22px] leading-8 font-semibold tracking-tight text-stone-800 text-balance`,children:Qt(`chat.emptyTitle`,void 0,mr.language)})]}):null,nc?null:(0,Z.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,Z.jsx)(`div`,{ref:ka,onScroll:jo,className:`h-full overflow-y-auto ${t?`px-5 py-4`:`px-8 sm:px-10 lg:px-12 py-6`}`,style:{fontSize:`var(--tw-session-font-size, ${mr.sessionFontSize}px)`},children:(0,Z.jsx)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto flex flex-col gap-4`,onClick:tc,children:x.map((e,t)=>e.role===`user`?(0,Z.jsxs)(`div`,{className:`group flex flex-col items-end gap-1`,children:[e.taskCards?.length||e.refs?.length||e.attachments?.length||e.images?.length?(0,Z.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-1.5 max-w-[82%]`,children:[e.taskCards?.map(t=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Ki({id:t.id,label:t.label,detail:t.detail,body:t.body,at:e.time??Date.now()}),className:`flex items-center gap-1.5 rounded-lg border border-[#4176e6]/25 bg-[#edf3fe] py-1 pr-2.5 pl-2.5 text-xs text-[#4176e6] transition-colors hover:border-[#4176e6]/45`,children:[(0,Z.jsxs)($,{className:`h-3.5 w-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Z.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Z.jsx)(`path`,{d:`M8 13h8`}),(0,Z.jsx)(`path`,{d:`M8 17h5`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[10px] text-[#4176e6]/80`,children:`要求`}),(0,Z.jsx)(`span`,{className:`max-w-56 truncate text-left`,children:t.label}),t.detail?(0,Z.jsx)(`span`,{className:`max-w-40 truncate text-[10px] text-[#4176e6]/70`,children:t.detail}):null]},t.id)),e.refs?.map(e=>(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/30 rounded-lg`,"data-hint":e.collection===`workspace`?e.path:`${e.collection}/${e.path}`,children:[(0,Z.jsx)(Em,{className:`w-3.5 h-3.5`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:e.collection===`workspace`?`工作区`:e.collection===`cases`||e.collection===`knowledge`?e.category:sf(e.format)}),(0,Z.jsx)(`span`,{className:`max-w-48 truncate`,children:e.title})]},e.path)),e.attachments?.map(e=>(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-stone-600 bg-white border border-stone-200 rounded-lg`,children:[(0,Z.jsx)(Em,{className:`w-3.5 h-3.5 text-[#4176e6]`}),(0,Z.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Z.jsx)(`span`,{className:`text-stone-400`,children:Qm(e.size)})]},e.name)),e.images?.map(e=>(0,Z.jsx)(`a`,{href:e.dataUrl,target:`_blank`,rel:`noreferrer`,className:`block overflow-hidden rounded-lg border border-stone-200 bg-white`,"data-hint":e.name,children:(0,Z.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`max-h-40 max-w-48 object-contain`})},e.id))]}):null,(e.taskCards?.length?e.displayContent:e.displayContent||e.content)?(0,Z.jsx)(`div`,{className:`tw-chat-text max-w-[82%] px-4 py-2.5 bg-[#edf3fe] rounded-2xl whitespace-pre-wrap break-words`,children:e.taskCards?.length?e.displayContent:e.displayContent||e.content}):null,(0,Z.jsxs)(`div`,{className:`tw-msg-actions ${cc(t)}`,children:[e.time!=null&&(0,Z.jsx)(`span`,{className:`tw-msg-action-time pr-0.5`,children:$m(e.time)}),(0,Z.jsx)(th,{text:e.content})]})]},t):(0,Z.jsxs)(`div`,{className:`group`,children:[e.turnStatus===`stopped`?(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsx)(`div`,{className:`text-[13px] text-stone-500 py-1`,children:`已停止`}),(0,Z.jsx)(`div`,{className:`border-t border-stone-200/80`})]}):null,(()=>{let n=e.activitySteps??[],r=n.some(e=>e.status===`running`),i=t===x.length-1&&e.turnStatus!==`stopped`&&(Nt||r),a=i&&!e.content,o=n.filter(e=>e.kind!==`thinking`);if(!(a||e.reasoning||o.length>0||n.length>0))return null;let s=e.reasoningOpen??!1,c=!s&&e.reasoning?(i?vm(e.reasoning):gm(e.reasoning)).replaceAll(`**`,``).slice(0,120):``;return(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:e=>fs(t,e),className:`flex w-full items-center gap-2 py-1 text-left select-none`,children:[a||i&&!e.content?(0,Z.jsx)(`span`,{className:`w-3.5 h-3.5 shrink-0 rounded-full border-2 border-purple-400 border-t-transparent animate-spin`}):(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`,children:[(0,Z.jsx)(`path`,{d:`M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5`}),(0,Z.jsx)(`path`,{d:`M9 18h6`}),(0,Z.jsx)(`path`,{d:`M10 22h4`})]}),(0,Z.jsx)(`span`,{className:`text-[13px] font-medium shrink-0 ${i&&!e.content?`text-shimmer`:`text-shimmer-static`}`,children:i&&!e.content?n.some(e=>e.kind!==`thinking`&&e.status===`running`)?`正在分析请求`:`思考中…`:i?`正在生成…`:e.turnStatus===`stopped`?`已完成分析`:`思考完成`}),!i&&e.reasoningDuration!=null&&(0,Z.jsxs)(`span`,{className:`text-xs text-stone-400 shrink-0`,children:[`用时 `,e.reasoningDuration,`s`]}),(0,Z.jsx)(bm,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${s?`rotate-180`:``}`}),c?(0,Z.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-xs ${i?`text-shimmer-muted think-mask`:`text-stone-400`}`,children:c}):null]}),s&&e.reasoning?(0,Z.jsx)(_m,{text:e.reasoning,live:i}):null,(s||r)&&o.length>0?(0,Z.jsx)(`ul`,{className:`mt-1.5 mb-1 pl-5.5 space-y-1.5`,children:o.map(e=>(0,Z.jsxs)(`li`,{className:`text-[12px] flex items-start gap-2 min-w-0 ${e.status===`error`?`text-red-600`:e.status===`running`?`text-stone-600`:`text-stone-500`}`,children:[(0,Z.jsx)(mm,{kind:e.kind,status:e.status}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 leading-5`,children:[(0,Z.jsx)(`span`,{className:`font-medium ${e.status===`running`?`text-shimmer`:``}`,children:e.title}),e.detail?(0,Z.jsxs)(`span`,{className:`text-stone-400`,children:[` · `,(0,Z.jsx)(`span`,{className:e.status===`error`?`text-red-600`:e.status===`running`?`text-shimmer-muted`:``,"data-hint":e.detail,children:e.detail.length>72?`${e.detail.slice(0,72)}…`:e.detail})]}):e.status===`running`?(0,Z.jsxs)(`span`,{className:`text-stone-400 text-shimmer-muted`,children:[` · `,`…`]}):null]})]},e.id))}):null,e.turnStatus===`stopped`?(0,Z.jsx)(`div`,{className:`mt-1.5 pl-5.5`,children:(0,Z.jsx)(`span`,{className:`tw-turn-stopped-pill`,children:`已停止`})}):null]})})(),e.content?(0,Z.jsx)(Ks,{text:e.content,className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`}):null,e.caseFile?(0,Z.jsxs)(`button`,{type:`button`,"data-focus-doc":`cases:${e.caseFile.path.replace(/\\/g,`/`)}`,"data-hint":`双击本地打开`,onDoubleClick:()=>{Et(`cases`,e.caseFile.path).catch(e=>B(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Z.jsx)(`span`,{className:`w-10 h-10 rounded-lg bg-emerald-50 text-emerald-700 flex items-center justify-center text-[10px] font-semibold shrink-0`,children:e.caseFile.name.split(`.`).pop()?.toUpperCase()||`FILE`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.caseFile.name}),(0,Z.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[Vt(`cases`),e.caseFile.path,e.caseFile.count>0?` · ${e.caseFile.count} 条`:``,` · 双击本地打开`]})]})]}):null,e.docsFile?(0,Z.jsxs)(`button`,{type:`button`,"data-focus-doc":`${e.docsFile.root}:${e.docsFile.path.replace(/\\/g,`/`)}`,"data-hint":`点击本地打开`,onClick:()=>{Et(e.docsFile.root,e.docsFile.path).catch(e=>B(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Z.jsx)(`span`,{className:`w-10 h-10 rounded-lg flex items-center justify-center text-[10px] font-semibold shrink-0 ${e.docsFile.root===`knowledge`?`bg-amber-50 text-amber-800`:`bg-sky-50 text-sky-700`}`,children:e.docsFile.name.split(`.`).pop()?.toUpperCase()||`MD`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.docsFile.name}),(0,Z.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[Vt(e.docsFile.root),e.docsFile.path,e.docsFile.note?` · ${e.docsFile.note}`:``,` · 点击打开`]})]})]}):null,e.presentFiles?.length?e.presentFiles.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-hint":`点击本地打开`,onClick:()=>{rn(e.path,Kt).catch(e=>B(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Z.jsx)(`span`,{className:`w-10 h-10 rounded-lg bg-violet-50 text-violet-700 flex items-center justify-center text-[10px] font-semibold shrink-0`,children:e.name.split(`.`).pop()?.toUpperCase()||`FILE`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.name}),(0,Z.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[e.path,e.description?` · ${e.description}`:``,` · 点击打开`]})]})]},e.path)):null,e.content&&!(t===x.length-1&&Nt)?(0,Z.jsxs)(`div`,{className:`tw-msg-actions mt-1 ${cc(t)}`,children:[(0,Z.jsx)(th,{text:e.content}),e.usage&&(0,Z.jsx)(lh,{usage:e.usage,model:e.model??f?.model}),e.time!=null&&(0,Z.jsx)(`span`,{className:`tw-msg-action-time`,children:$m(e.time)})]}):null]},t))})}),cn&&(0,Z.jsx)(`button`,{type:`button`,onClick:Mo,"aria-label":`回到底部`,className:`absolute bottom-3 w-8 h-8 rounded-full bg-white border border-stone-200 shadow-md flex items-center justify-center text-stone-500 hover:text-stone-800 transition-colors ${t?`right-5`:`right-8 sm:right-10 lg:right-12`}`,children:(0,Z.jsx)(bm,{className:`w-4 h-4`})})]},`dialog-${_?.activeId??``}`),Rt&&(0,Z.jsx)(`div`,{className:`shrink-0 pb-2 ${t?`px-5`:`px-8 sm:px-10 lg:px-12`}`,children:(0,Z.jsxs)(`div`,{ref:La,className:`w-full max-w-[min(64rem,100%)] mx-auto flex items-start gap-3 px-4 py-3 rounded-xl text-sm border ${Wt===`ok`?`tw-notice-anim`:``} ${Wt===`ok`?`bg-emerald-50 border-emerald-200 text-emerald-900`:`bg-red-50 border-red-200 text-red-800`}`,children:[(0,Z.jsx)(`span`,{className:`mt-0.5 w-5 h-5 shrink-0 rounded-full flex items-center justify-center text-xs font-semibold ${Wt===`ok`?`bg-emerald-100 text-emerald-700`:`bg-red-100 text-red-600`}`,children:Wt===`ok`?`i`:`!`}),(0,Z.jsx)(`pre`,{className:`flex-1 min-w-0 m-0 font-sans text-[13px] leading-5 whitespace-pre-wrap break-words`,children:Rt.replace(/\*\*/g,``).replace(/\s*:\s*\*\*/g,`: `).trim()}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>B(null),className:`shrink-0 text-xs ${Wt===`ok`?`text-emerald-500 hover:text-emerald-700`:`text-red-400 hover:text-red-600`}`,children:`关闭`})]})}),(0,Z.jsxs)(`div`,{className:`shrink-0 ${t?`px-5 pb-2`:`px-8 sm:px-10 lg:px-12 pb-5`}`,children:[(0,Z.jsxs)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto`,children:[L?.active&&V.knowledgeGen?(0,Z.jsx)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-amber-300/60 bg-amber-50 text-xs text-amber-900`,children:(0,Z.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成知识库已启用 · `,Fc(L)]})}):null,ge?.active&&V.caseGen?(0,Z.jsx)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-[#4176e6]/30 bg-[#edf3fe] text-xs text-[#3565c7]`,children:(0,Z.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成测试用例已启用 · `,mt(ge)]})}):null,zr.length>0?(0,Z.jsx)(`div`,{className:`mb-2 rounded-xl border border-stone-200/80 bg-stone-100/80 overflow-hidden`,children:zr.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-stone-200/60 last:border-b-0`,children:[(0,Z.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-stone-400 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-stone-700`,children:Oa(e)}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`编辑回输入框`,onClick:()=>ls(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M12 20h9`}),(0,Z.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]})}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`从队列移除`,onClick:()=>cs(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M3 6h18`}),(0,Z.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Z.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]})}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`插话立即发送(其后队列仍会续发)`,onClick:()=>us(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none text-[#4176e6]`,children:(0,Z.jsx)(Om,{className:`w-3.5 h-3.5`})})]},e.id))}):null,qi?(0,Z.jsxs)(`div`,{className:`mb-2 rounded-xl border border-amber-300/60 bg-amber-50/90 px-4 py-3 shadow-sm`,children:[(0,Z.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 mb-1`,children:`待批准计划`}),(0,Z.jsx)(`div`,{className:`text-[14px] font-medium text-stone-900`,children:qi.title}),qi.summary?(0,Z.jsx)(`p`,{className:`mt-1 text-[13px] text-stone-600 leading-5`,children:qi.summary}):null,(0,Z.jsx)(`ol`,{className:`mt-2 list-decimal pl-5 space-y-1 text-[13px] text-stone-700`,children:qi.steps.map((e,t)=>(0,Z.jsx)(`li`,{children:e},`${t}-${e.slice(0,24)}`))}),(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg border border-stone-200 bg-white text-[12px] text-stone-600 hover:bg-stone-50`,onClick:()=>ws(),children:`驳回`}),(0,Z.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg bg-[#4176e6] text-[12px] text-white hover:bg-[#3467d4]`,onClick:()=>Cs(),children:`批准实施`})]})]}):null,fa?(0,Z.jsx)(Jp,{kind:fa.kind,items:fa.items,manual:fa.manual,quick:fa.quick,quickNote:fa.quickNote,tasksOn:V.tasks,closing:ma,onConfirm:e=>{fa.manual?(xa(null),wa(fa.kind,e)):xa(e)},onCancel:()=>xa(null)}):null,Ic>0&&Rc?(0,Z.jsxs)(`div`,{className:`mb-2 flex max-h-[min(60vh,520px)] flex-col overflow-hidden rounded-2xl border border-stone-200 bg-white shadow-[0_6px_24px_rgba(15,23,42,0.08)]`,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 justify-between gap-4 px-5 ${ia?`items-center py-3.5`:`items-start pt-4`}`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-[11px] leading-4 text-stone-400`,children:ca?`跳过确认`:Rc.header||`模型需要你的确认`}),(0,Z.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:ca?`确认 ${Hc.length} 道跳过的题怎么处理`:Rc.question})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[ia?(0,Z.jsx)(`span`,{className:`text-[11px] leading-4 text-stone-400`,children:ca?`已跳过 ${Hc.length} 题`:`第 ${Lc+1} 步 / 共 ${Ic} 步`}):null,(0,Z.jsx)(`button`,{type:`button`,"aria-label":ia?`展开问题`:`收起问题`,onClick:()=>aa(e=>!e),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600`,children:(0,Z.jsx)(bm,{className:`h-4 w-4 transition-transform ${ia?`rotate-180`:``}`})})]})]}),ia?null:ca?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-2`,children:[(0,Z.jsx)(`p`,{className:`text-[12px] leading-5 text-stone-500`,children:`跳过不算确认,本轮不会开始改代码。留下原因后我只出方案,等你回复「开始实施」。`}),(0,Z.jsx)(`ul`,{className:`mt-2 space-y-1 rounded-lg bg-stone-50 px-3 py-2`,children:Hc.map(({q:e,index:t})=>(0,Z.jsxs)(`li`,{className:`text-[12px] leading-5 text-stone-600`,children:[(0,Z.jsxs)(`span`,{className:`text-stone-400`,children:[t+1,`.`]}),` `,e.header?`${e.header} / `:``,e.question,(0,Z.jsx)(`span`,{className:`ml-1 text-stone-400`,children:`— 已跳过`})]},e.id))}),(0,Z.jsx)(`textarea`,{autoFocus:!0,value:ua,onChange:e=>da(e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Ps())},rows:3,className:`mt-2 w-full resize-none rounded-lg border border-stone-200 px-2.5 py-2 text-[13px] leading-5 outline-none focus:border-[#4176e6]`,placeholder:`为什么跳过这几题?例如:先只做评估,方案我稍后定 / 这几项按你推荐的来`})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Fs(),className:`h-8 shrink-0 rounded-lg px-2 text-[12px] text-stone-500 outline-none hover:bg-stone-100 hover:text-stone-700`,children:`返回继续回答`}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Ps(),className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4]`,children:`提交并继续`})]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-1`,children:[Rc.options?.length?(0,Z.jsx)(`div`,{className:`mt-2 flex flex-col gap-0.5`,role:Rc.multi_select?`group`:`radiogroup`,children:Rc.options.map((e,t)=>{let n=zc.selected.includes(e.label),r=Qp(e.label);return(0,Z.jsxs)(`button`,{type:`button`,role:Rc.multi_select?`checkbox`:`radio`,"aria-checked":n,onClick:()=>Os(Rc,e.label,n),className:`flex w-full shrink-0 items-start gap-2 rounded-lg border px-2 py-2 text-left outline-none transition-colors ${n?`border-[#4176e6]/40 bg-[#f2f7ff]`:`border-transparent hover:bg-stone-50`}`,children:[Rc.multi_select?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded border ${n?`border-[#4176e6] bg-[#4176e6] text-white`:`border-stone-300 text-transparent`}`,children:(0,Z.jsx)(Sm,{className:`h-3 w-3`})}):(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-5 w-5 shrink-0 place-items-center rounded-md text-[11px] font-medium ${n?`bg-[#4176e6] text-white`:`bg-stone-100 text-stone-500`}`,children:t+1}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,Z.jsx)(`span`,{className:`text-[13px] leading-5 font-medium text-stone-800`,children:r.label}),r.recommended?(0,Z.jsx)(`span`,{className:`rounded bg-[#edf3fe] px-1 text-[10px] leading-4 font-semibold text-[#4176e6]`,children:`推荐`}):null]}),e.description?(0,Z.jsx)(`span`,{className:`mt-0.5 block text-[12px] leading-4.5 text-stone-400`,children:e.description}):null]})]},`${e.label}-${t}`)})}):(0,Z.jsx)(`div`,{className:`px-1.5 py-2`,children:(0,Z.jsx)(`textarea`,{autoFocus:!0,value:zc.text,onChange:e=>ks(Rc,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),As(Rc,zc.text))},rows:2,className:`w-full resize-none rounded-lg border border-stone-200 px-2.5 py-2 text-[13px] leading-5 outline-none focus:border-[#4176e6]`,placeholder:`输入你的回答…`})}),Rc.options?.length?(0,Z.jsx)(`div`,{className:`mt-1 px-1.5 pb-1`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-stone-200 px-2 py-1.5 focus-within:border-[#4176e6]`,children:[(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded bg-stone-100 text-[10px] font-medium text-stone-500`,children:`#`}),(0,Z.jsx)(`textarea`,{value:zc.text,onChange:e=>ks(Rc,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),As(Rc,zc.text))},rows:1,className:`min-h-5 w-full resize-none bg-transparent text-[13px] leading-5 outline-none`,placeholder:`输入序号选择(如 1${Rc.multi_select?` 或 1,3`:``}),也可直接写你的回答`})]})}):null,(0,Z.jsx)(`div`,{className:`px-2 pb-2 pt-1 text-[11px] leading-4 text-stone-400`,children:Rc.options?.length?`回车确认这一步;跳过的题会在提交前让你说明原因,不会直接开始实施`:`回车确认;跳过的题会在提交前让你说明原因,不会直接开始实施`})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`上一步`,disabled:Lc===0,onClick:()=>X(Lc-1),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600 disabled:cursor-default disabled:text-stone-200 disabled:hover:bg-transparent`,children:(0,Z.jsx)(xm,{className:`h-4 w-4 rotate-180`})}),(0,Z.jsxs)(`span`,{className:`px-1 text-[12px] font-medium text-stone-500`,children:[`第 `,Lc+1,` 步 / 共 `,Ic,` 步`]}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`下一步`,disabled:Bc,onClick:()=>X(Lc+1),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600 disabled:cursor-default disabled:text-stone-200 disabled:hover:bg-transparent`,children:(0,Z.jsx)(xm,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[oa?(0,Z.jsx)(`span`,{className:`truncate text-[11px] text-rose-500`,children:oa}):null,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Ns(),className:`h-8 shrink-0 rounded-lg px-2 text-[12px] text-stone-500 outline-none hover:bg-stone-100 hover:text-stone-700`,children:`跳过`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!Vc,onClick:()=>Bc?Ms():X(Lc+1),className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4] disabled:cursor-not-allowed disabled:bg-stone-300`,children:Bc?`提交回答`:`下一步`})]})]})]})]}):null,(0,Z.jsxs)(`div`,{ref:Ra,onDragEnter:qs,onDragLeave:Js,onDragOver:Ys,onDrop:Xs,className:`pt-2 rounded-[20px] bg-white border shadow-[0_4px_20px_rgba(15,23,42,0.06)] transition-[box-shadow,border-color,background-color] focus-within:shadow-[0_4px_24px_rgba(65,118,230,0.14)] ${M?`border-[#4176e6] bg-[#edf3fe]/60 shadow-[0_4px_24px_rgba(65,118,230,0.18)]`:`border-stone-200`}`,children:[(A.length>0||se.length>0||le.length>0||Hi.length>0)&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-0.5 pb-2`,children:[Hi.map(e=>(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5 rounded-lg border border-[#4176e6]/25 bg-[#edf3fe] py-1 pr-1 pl-2.5 text-xs text-[#4176e6]`,children:[(0,Z.jsxs)($,{className:`h-3.5 w-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Z.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Z.jsx)(`path`,{d:`M8 13h8`}),(0,Z.jsx)(`path`,{d:`M8 17h5`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[10px] text-[#4176e6]/80`,children:`要求`}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Wi(e),className:`max-w-56 truncate text-left hover:underline`,children:e.label}),e.detail?(0,Z.jsx)(`span`,{className:`max-w-44 truncate text-[10px] text-[#4176e6]/70`,children:e.detail}):null,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>J(e.id),className:`flex h-5 w-5 items-center justify-center rounded text-[#4176e6]/70 hover:bg-white/80 hover:text-[#4176e6]`,"aria-label":`取消${e.label}`,children:(0,Z.jsxs)($,{className:`h-3 w-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},e.id)),A.map(e=>(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5 pl-2.5 pr-1 py-1 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/25 rounded-lg`,"data-hint":e.collection===`workspace`?e.path:`${e.collection}/${e.path}`,children:[(0,Z.jsx)(Em,{className:`w-3.5 h-3.5`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:e.collection===`workspace`?`工作区`:e.collection===`cases`||e.collection===`knowledge`?e.category:sf(e.format)}),(0,Z.jsx)(`span`,{className:`max-w-48 truncate`,children:e.title}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{j(t=>t.filter(t=>t.collection!==e.collection||t.path!==e.path)),e.collection===`cases`&&(Ui(e=>{let t=e.filter(e=>!(e.id.startsWith(`case-fix:`)||e.id.startsWith(`case-batch-fix:`)||e.id.startsWith(`blindspot-writeback:`)));return Ae(G.current?.activeId,t),t}),Wi(null))},className:`w-5 h-5 flex items-center justify-center rounded text-[#4176e6]/70 hover:text-[#4176e6] hover:bg-white/80`,children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.collection}:${e.path}`)),se.map((e,t)=>(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5 pl-2.5 pr-1 py-1 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/25 rounded-lg`,"data-hint":e.path||e.name,children:[(0,Z.jsx)(Em,{className:`w-3.5 h-3.5`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:`文件`}),(0,Z.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`移除`,onClick:()=>ce(e=>e.filter((e,n)=>n!==t)),className:`w-5 h-5 flex items-center justify-center rounded text-[#4176e6]/70 hover:text-[#4176e6] hover:bg-white/80`,children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.name}-${t}`)),le.map(e=>(0,Z.jsxs)(`span`,{className:`relative group inline-flex rounded-lg border border-stone-200 overflow-hidden bg-stone-50`,"data-hint":`${e.name} · ${Qm(e.size)}`,children:[(0,Z.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`h-14 w-14 object-cover`}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`移除图片`,onClick:()=>ue(t=>t.filter(t=>t.id!==e.id)),className:`absolute top-0.5 right-0.5 w-5 h-5 flex items-center justify-center rounded bg-black/55 text-white hover:bg-black/75`,children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},e.id))]}),(0,Z.jsxs)(`div`,{className:`relative`,children:[Nr&&!Ja&&!Ga&&(0,Z.jsx)(`div`,{ref:Ia,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-3 z-40 overflow-hidden rounded-xl border border-stone-200 py-2.5 shadow-[0_4px_14px_-4px_rgba(15,23,42,0.08)] ${ic?`max-h-[min(70vh,20rem)]`:`h-[min(70vh,20rem)]`}`,children:(0,Z.jsxs)(`div`,{className:`tw-dsh-scroll h-full overflow-y-auto overflow-x-hidden`,children:[(0,Z.jsx)(`div`,{className:`px-3 pt-0.5 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`添加`}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{Pr(!1),Na.current?.click()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Z.jsx)(Dm,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`文件`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`file`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`添加本地附件`})]}),ic?null:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{Pr(!1),Qo()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`目标`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`goal`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`设置或查看长期任务目标`})]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{Pr(!1),Pi===`off`?$o():Ts()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100 ${Pi===`planning`?`bg-amber-50`:Pi===`approved`?`bg-emerald-50`:``}`,children:[(0,Z.jsxs)($,{className:`w-4 h-4 shrink-0 ${Pi===`planning`?`text-amber-800`:Pi===`approved`?`text-emerald-800`:`text-stone-500`}`,children:[(0,Z.jsx)(`path`,{d:`M8 6h13`}),(0,Z.jsx)(`path`,{d:`M8 12h13`}),(0,Z.jsx)(`path`,{d:`M8 18h13`}),(0,Z.jsx)(`path`,{d:`M3 6h.01`}),(0,Z.jsx)(`path`,{d:`M3 12h.01`}),(0,Z.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`计划`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`plan`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`进入或退出计划模式`})]}),V.todos||V.tasks?(0,Z.jsxs)(Z.Fragment,{children:[V.todos?(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Ca(`todo`),className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`path`,{d:`M8 6h13`}),(0,Z.jsx)(`path`,{d:`M8 12h13`}),(0,Z.jsx)(`path`,{d:`M8 18h13`}),(0,Z.jsx)(`path`,{d:`M3 6h.01`}),(0,Z.jsx)(`path`,{d:`M3 12h.01`}),(0,Z.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`待办`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`todo`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一条待办`})]}):null,V.tasks?(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Ca(`task`),className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`path`,{d:`M9 5h10`}),(0,Z.jsx)(`path`,{d:`M9 12h10`}),(0,Z.jsx)(`path`,{d:`M9 19h10`}),(0,Z.jsx)(`path`,{d:`M4 5h.01`}),(0,Z.jsx)(`path`,{d:`M4 12h.01`}),(0,Z.jsx)(`path`,{d:`M4 19h.01`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`任务`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`task`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一个任务`})]}):null]}):null,qa.length?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Lr(e=>!e),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-stone-50`,children:[(0,Z.jsx)(`span`,{className:`flex-1 text-[11px] font-medium text-stone-400 tracking-wide`,children:`扩展插件`}),(0,Z.jsx)(bm,{className:`w-3.5 h-3.5 text-stone-400 shrink-0 transition-transform ${Fr?`rotate-180`:``}`})]}),Fr?qa.map(e=>{let t=e.id===`caseGen`?`case`:e.id===`knowledgeGen`?`knowledge`:e.id===`pluginDev`?`dev`:``,n=e.id===`caseGen`?`打开配置后生成用例并写入用例库`:e.id===`knowledgeGen`?`对话生成规范/方法论并写入知识库`:e.id===`pluginDev`?`输入需求后先评估确认,再开发扩展插件`:``;return(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{Pr(!1),Ao(e.id)},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Z.jsx)(Im,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[e.name,t?(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:t}):null]}),n?(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:n}):null]},e.id)}):null]}):null]}),(0,Z.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Z.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`指令`}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{Pr(!1),yi.current?B(`请等待当前回复结束后再压缩`):rs({force:!0}).then(e=>{e&&B(`已压缩上下文`)})},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Z.jsx)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`})}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`压缩`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`compact`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`压缩以上对话内容`})]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{Pr(!1),Hs()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`path`,{d:`M3 3v18h18`}),(0,Z.jsx)(`path`,{d:`M7 14v4`}),(0,Z.jsx)(`path`,{d:`M12 10v8`}),(0,Z.jsx)(`path`,{d:`M17 6v12`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`会话统计`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`stats`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`查看本会话用量摘要`})]})]})}),Ja&&(0,Z.jsxs)(`div`,{ref:Fa,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-2 mx-2 z-40 max-h-64 overflow-y-auto rounded-xl border border-stone-200 shadow-xl p-1`,children:[(0,Z.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`插件`}),qa.map((e,t)=>(0,Z.jsxs)(`button`,{type:`button`,"data-plugin-index":t,onMouseDown:e=>e.preventDefault(),onMouseEnter:()=>Je(t),onClick:()=>Ao(e.id),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===Le?`is-active`:``}`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Z.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 flex-1`,children:e.name})}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400 line-clamp-2`,children:e.description})]},e.id))]}),Ga&&(0,Z.jsx)(`div`,{ref:Pa,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-2 mx-2 z-40 max-h-64 overflow-y-auto rounded-xl border border-stone-200 shadow-xl p-1`,children:Wa.length===0?(0,Z.jsxs)(`div`,{className:`px-3 py-2 text-xs text-stone-400 space-y-1`,children:[Yr?(0,Z.jsx)(`p`,{children:`项目文档:无匹配`}):null,Ba?(0,Z.jsx)(`p`,{children:`工作区:无匹配`}):(0,Z.jsx)(`p`,{children:`工作区:请先在侧栏添加并选择工作区`}),Yr?null:(0,Z.jsxs)(`p`,{children:[`「知识库检索」未启用:启用后才能用 @ 引用`,Ht(`knowledge`),` / `,Ht(`templates`),`文档`]})]}):(0,Z.jsxs)(Z.Fragment,{children:[Ha.length>0?(0,Z.jsxs)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:[`项目文档(`,Ht(`knowledge`),` / `,Ht(`templates`),`)`]}):null,Wa.map((e,t)=>{let n=e.doc,r=Wa[t-1],i=e.section===`workspace`&&r?.section!==`workspace`;return(0,Z.jsxs)(`div`,{children:[i?(0,Z.jsxs)(Z.Fragment,{children:[Ha.length>0?(0,Z.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}):null,(0,Z.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:`工作区`})]}):null,(0,Z.jsxs)(`button`,{type:`button`,"data-mention-index":t,onMouseDown:e=>e.preventDefault(),onClick:()=>Do(n),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===wr?`is-active`:``}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] text-stone-800`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:n.collection===`knowledge`?Ht(`knowledge`):n.collection===`templates`?Ht(`templates`):n.format===`dir`?`文件夹`:`文件`}),n.collection===`workspace`?null:(0,Z.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:sf(n.format)}),(0,Z.jsx)(`span`,{className:`truncate font-medium`,children:n.title})]}),(0,Z.jsx)(`div`,{className:`mt-0.5 pl-0 text-xs text-stone-400 truncate`,children:n.collection===`workspace`?n.path:`${n.category}${n.description?` · ${n.description}`:``}`})]})]},`${n.collection}/${n.id}`)}),Yr?null:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}),(0,Z.jsx)(`p`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`「知识库检索」未启用:@ 仅引用工作区文件`})]})]})}),(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 px-3`,children:[Li===`goal`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-goal`,"data-hint":`会话目标`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Z.jsx)(`span`,{children:`目标`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`取消目标输入`,onClick:()=>Ri(null),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,Li===`plan`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-plan${Pi===`approved`?` is-approved`:``}`,"data-hint":Pi===`approved`?`计划模式·已批准`:`计划模式·探查中`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M8 6h13`}),(0,Z.jsx)(`path`,{d:`M8 12h13`}),(0,Z.jsx)(`path`,{d:`M8 18h13`}),(0,Z.jsx)(`path`,{d:`M3 6h.01`}),(0,Z.jsx)(`path`,{d:`M3 12h.01`}),(0,Z.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Z.jsx)(`span`,{children:`计划`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`退出计划模式`,onClick:()=>Y(),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,Li===`pluginDev`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-plugin-dev`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M9 7V3`}),(0,Z.jsx)(`path`,{d:`M15 7V3`}),(0,Z.jsx)(`path`,{d:`M6 7h12v4a6 6 0 0 1-12 0V7Z`}),(0,Z.jsx)(`path`,{d:`M12 17v4`})]}),(0,Z.jsx)(`span`,{children:`插件开发`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`退出插件开发`,onClick:()=>Y(),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,Li===`reports`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-report`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Z.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Z.jsx)(`path`,{d:`M8 13h8`}),(0,Z.jsx)(`path`,{d:`M8 17h5`})]}),(0,Z.jsxs)(`span`,{children:[`生成`,Jr[Bi]]}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`取消汇报生成`,onClick:()=>Y(),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,L?.active&&V.knowledgeGen?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-knowledge-gen`,"data-hint":`改配置 · ${Fc(L)}`,role:`button`,tabIndex:0,onClick:()=>I(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),I(!0))},children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M4 19.5A2.5 2.5 0 0 1 6.5 17H20`}),(0,Z.jsx)(`path`,{d:`M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z`})]}),(0,Z.jsx)(`span`,{children:`生成知识库`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`取消生成知识库`,onClick:e=>{e.stopPropagation(),ys(null)},children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,ge?.active&&V.caseGen?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-case-gen`,"data-hint":`改配置 · ${mt(ge)}`,role:`button`,tabIndex:0,onClick:()=>he(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),he(!0))},children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Z.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Z.jsx)(`path`,{d:`M8 13h8`}),(0,Z.jsx)(`path`,{d:`M8 17h5`})]}),(0,Z.jsx)(`span`,{children:`生成测试用例`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`取消生成测试用例`,onClick:e=>{e.stopPropagation(),vs(null)},children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,(0,Z.jsx)(`textarea`,{ref:Aa,value:O,onChange:e=>{let t=e.target.value;Jo(t),k(t)},onPaste:ec,onKeyDown:e=>{if((e.metaKey||e.ctrlKey)&&!e.altKey&&(e.key===`z`||e.key===`Z`))e.preventDefault(),e.shiftKey?Xo():Yo();else if(e.ctrlKey&&!e.metaKey&&!e.altKey&&!e.shiftKey&&(e.key===`y`||e.key===`Y`))e.preventDefault(),Xo();else{if(Ja&&qa.length){if(e.key===`ArrowDown`){e.preventDefault(),Je(e=>(e+1)%qa.length);return}if(e.key===`ArrowUp`){e.preventDefault(),Je(e=>(e-1+qa.length)%qa.length);return}if(e.key===`Escape`){e.preventDefault(),Mr(!0),Ka&&k(O.slice(0,Ka.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=qa[Le]??qa[0];t&&Ao(t.id);return}}if(Ga&&Wa.length){if(e.key===`ArrowDown`){e.preventDefault(),Or(e=>(e+1)%Wa.length);return}if(e.key===`ArrowUp`){e.preventDefault(),Or(e=>(e-1+Wa.length)%Wa.length);return}if(e.key===`Escape`){e.preventDefault(),Ar(!0),Va&&k(O.slice(0,Va.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=Wa[wr]?.doc;t&&Do(t);return}}if(e.key===`Escape`&&Nr)e.preventDefault(),Pr(!1);else if(e.key===`Escape`&&(Va||Ka)){e.preventDefault(),Ar(!0),Mr(!0);let t=Va?.from??Ka?.from;t!=null&&k(O.slice(0,t))}else if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=e.metaKey||e.ctrlKey;if(yi.current){if(t){let e=O.trim();if(e||se.length>0||le.length>0||A.length>0){let t={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:e,files:[...se],refs:[...A],imgs:[...le]};Zo(),ds(t)}else Ta.current.length&&ds();return}as(void 0,{forceBusy:te().busySendBehavior??`queue`})}else as()}}},rows:1,placeholder:f?L?.active&&V.knowledgeGen?`粘贴或描述素材后发送(点 × 取消生成)`:ge?.active&&V.caseGen?`可补充生成范围;直接发送即按配置生成用例(点 × 取消)`:Hi.length>0?`可补充说明;直接发送会带上「要求」与引用文件`:zr.length>0&&Nt?`Cmd/Ctrl+Enter 插话发送全部排队消息`:Yr?`请输入内容,或用 @ 引用文档`:Ba?`请输入内容,或用 @ 引用工作区文件`:`请输入内容(@ 引用文档需先启用「知识库检索」)`:`请先配置模型(左下角「设置」→ 模型)`,className:`tw-chat-input block min-w-0 flex-1 min-h-13 pl-0 pr-2 pt-1.5 pb-0.5 bg-transparent resize-none focus:outline-none placeholder:text-(--tw-label-tertiary)`})]})]}),(0,Z.jsxs)(`div`,{className:`tw-composer-bar flex items-center gap-1.5 px-3 pb-3 pt-3`,children:[(0,Z.jsx)(`button`,{type:`button`,"data-add-menu-btn":!0,"aria-label":Pi===`off`?`添加`:Pi===`planning`?`添加(计划模式·探查中)`:`添加(计划模式·已批准)`,onClick:()=>{Pr(e=>!e),Ar(!0),Mr(!0)},className:`tw-icon-btn w-8 h-8 shrink-0 rounded-full flex items-center justify-center outline-none focus:outline-none focus-visible:outline-none transition-colors ${Nr?`bg-(--tw-session-hover-bg)`:``}`,children:(0,Z.jsxs)($,{className:`w-4 h-4`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]})}),Zr||o?o?(0,Z.jsxs)(`span`,{className:`tw-composer-bar-ws flex items-center gap-1 h-7 shrink-0 max-w-[9rem] pl-1.5 pr-2 text-[13px] leading-5 font-medium text-stone-600`,"aria-label":`项目:${Cc}`,children:[(0,Z.jsx)(km,{className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Z.jsx)(`span`,{className:`truncate`,children:Cc})]}):(0,Z.jsxs)(l,{children:[(0,Z.jsxs)(u,{title:xc?`工作区:${xc}`:`选择工作区`,"aria-label":Cc?`工作区:${Cc}`:`选择工作区`,disabled:Jn,className:`tw-composer-bar-ws group flex items-center gap-1 h-7 shrink-0 max-w-[min(40vw,11rem)] pl-1.5 pr-1 text-[13px] leading-5 font-medium text-stone-600 rounded-md outline-none focus:outline-none focus-visible:outline-none hover:bg-stone-100 data-[open]:bg-stone-100 transition-colors disabled:opacity-50`,children:[(0,Z.jsx)(km,{className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Z.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:Cc}),(0,Z.jsx)(bm,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Z.jsxs)(s,{transition:!0,anchor:{to:`top start`,gap:8},className:`tw-select-menu tw-menu-anim z-50 w-[min(100vw-2rem,16rem)] rounded-xl border border-stone-200 py-1 shadow-xl focus:outline-none`,children:[(H?.items??[]).map(e=>{let t=e.path===xc;return(0,Z.jsx)(c,{children:(0,Z.jsxs)(`button`,{type:`button`,disabled:Jn,onClick:()=>void _o(e),className:`w-full flex items-center gap-2.5 px-3 py-2 text-left data-[focus]:bg-stone-100 disabled:opacity-50`,children:[(0,Z.jsx)(km,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Z.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] ${t?`text-stone-900 font-medium`:`text-stone-700`}`,"data-hint":e.path,children:tn(e,gc)}),t&&(0,Z.jsx)(Sm,{className:`w-3.5 h-3.5 shrink-0 text-[#4176e6]`})]})},e.id)}),(H?.items?.length??0)>0&&(0,Z.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Z.jsx)(c,{children:(0,Z.jsxs)(`button`,{type:`button`,disabled:Jn,onClick:()=>void vo(),className:`w-full flex items-center gap-2.5 px-3 py-2 text-left text-[13px] text-stone-700 data-[focus]:bg-stone-100 disabled:opacity-50`,children:[(0,Z.jsx)(`span`,{className:`w-4 h-4 shrink-0 flex items-center justify-center text-stone-500 text-base leading-none`,children:`+`}),`添加工作区...`]})})]})]}):null,(0,Z.jsx)(Lp,{workspace:xc,compact:t}),t?null:(0,Z.jsxs)(l,{children:[(0,Z.jsxs)(u,{title:`访问权限:${lc.label}`,"aria-label":`访问权限:${lc.label}`,className:`tw-composer-bar-access group flex items-center gap-1 h-7 shrink-0 max-w-55 pl-2 pr-1 text-[13px] leading-5 font-medium text-stone-600 rounded-md outline-none focus:outline-none focus-visible:outline-none hover:bg-stone-100 data-[open]:bg-stone-100 transition-colors`,children:[(0,Z.jsx)(Um,{level:Kt,className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Z.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:lc.label}),(0,Z.jsx)(`span`,{className:`ml-0.5 w-1.5 h-1.5 rounded-full shrink-0 ${Zr?`bg-emerald-500`:`bg-stone-300`}`,"data-hint":Zr?`Runner 在线`:`Runner 离线`}),(0,Z.jsx)(bm,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Z.jsxs)(s,{transition:!0,anchor:{to:`top start`,gap:8},className:`tw-select-menu tw-menu-anim z-50 w-56 rounded-xl border border-stone-200 p-1 shadow-xl focus:outline-none`,children:[(0,Z.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:Zr?`本地文件服务已连接`:`本地文件服务未就绪`}),um.map(e=>{let t=uc&&e.value===`readonly`;return(0,Z.jsx)(c,{disabled:t,children:(0,Z.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>{qt(e.value),G.current&&q(Ze(G.current,{access:e.value}))},className:`w-full flex items-center gap-2 px-3 py-2 rounded-lg text-left text-[13px] data-[focus]:bg-stone-100 disabled:cursor-not-allowed`,children:[(0,Z.jsx)(Um,{level:e.value,className:`w-4 h-4 shrink-0 ${t?`text-stone-300`:`text-stone-500`}`}),(0,Z.jsx)(`span`,{className:`flex-1 ${t?`text-stone-400`:Kt===e.value?`text-stone-900 font-medium`:`text-stone-700`}`,children:e.label}),t?(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`插件开发需要写入`}):Kt===e.value?(0,Z.jsx)(Sm,{className:`w-3.5 h-3.5 text-[#4176e6]`}):null]})},e.value)})]})]}),(0,Z.jsx)(`span`,{className:`flex-1`}),(0,Z.jsx)(uh,{settings:f}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{yi.current?ss():as()},disabled:!Nt&&!ac,"aria-label":Nt?`停止生成`:`发送`,className:`w-8 h-8 shrink-0 rounded-full flex items-center justify-center outline-none focus:outline-none focus-visible:outline-none transition-colors ${Nt?`bg-stone-200 text-stone-700 hover:bg-stone-300`:`bg-[#4176e6] text-white hover:bg-[#3565c7] disabled:bg-[#a9c3ef] disabled:cursor-not-allowed`}`,children:Nt?(0,Z.jsx)(`span`,{className:`w-2.5 h-2.5 bg-current rounded-xs`}):(0,Z.jsx)(Om,{className:`w-4 h-4`})})]})]}),(0,Z.jsx)(ch,{messages:x,model:f?.model,systemPromptTokens:Jm(fe),compact:t})]}),(0,Z.jsx)(`input`,{ref:Na,type:`file`,multiple:!0,hidden:!0,accept:[...Gf.map(e=>`.${e}`),`image/*`,`text/*`,`application/json`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/msword`].join(`,`),onChange:e=>void Gs(e)})]})]})]}),(0,Z.jsx)(hp,{open:me,initial:ge,presetStories:ve,onClose:()=>{he(!1),F(null)},onConfirm:e=>vs(e)}),(0,Z.jsx)(gp,{open:xe,initial:L,onClose:()=>I(!1),onConfirm:e=>ys(e)}),(0,Z.jsx)(Jt,{open:!!St,title:`重命名会话`,label:`会话名称`,placeholder:`请输入会话名称`,initialValue:St?_?.sessions.find(e=>e.id===St)?.title??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>Ct(null),onConfirm:Us}),(0,Z.jsx)(Jt,{open:!!jt,title:`重命名工作区`,label:`显示名称`,placeholder:`请输入工作区名称`,initialValue:jt?H?.items.find(e=>e.id===jt)?.name??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>Mt(null),onConfirm:e=>void xo(e)}),(0,Z.jsx)(_p,{task:W,onClose:()=>Wi(null),onSave:Ko,onRemove:()=>{W&&J(W.id)}}),(0,Z.jsx)(_p,{task:Gi,readOnly:!0,onClose:()=>Ki(null)}),(0,Z.jsx)(ne,{open:!!wt,title:`删除会话`,message:wt?`确定永久删除「${_?.sessions.find(e=>e.id===wt)?.title??`该会话`}」?此操作不可恢复。`:``,confirmLabel:`删除`,cancelLabel:`取消`,danger:`outline`,onClose:()=>Tt(null),onConfirm:()=>{if(!wt)return;let e=wt;Tt(null),Rs(e)}}),(0,Z.jsx)(ne,{open:!!kt,title:`删除工作区`,message:kt?`将把「${kt.name}」从工作区列表中移除。文件夹与会话记录会保留,其会话将归入项目根工作区。`:``,confirmLabel:`删除工作区`,cancelLabel:`取消`,danger:`outline`,onClose:()=>At(null),onConfirm:()=>void yo()})]})}export{gh as t};