aitu-app 0.6.63 → 0.6.64

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 (153) hide show
  1. package/README.md +3 -3
  2. package/assets/{CanvasAudioPlayer-Du5kXrAd.js → CanvasAudioPlayer-B2W5__ni.js} +1 -1
  3. package/assets/{ChatDrawer-CqZHx7x_.js → ChatDrawer-M1q92KNU.js} +2 -2
  4. package/assets/{ChatMessagesArea-AG3RXe34.js → ChatMessagesArea-D9LNDmbK.js} +2 -2
  5. package/assets/{DeferredAIInputBar-CNAPl6C2.js → DeferredAIInputBar-CKhI8Jhd.js} +2 -2
  6. package/assets/{DrawnixDeferredFeatures-BrhbEEBa.js → DrawnixDeferredFeatures-DxyxvT2y.js} +1 -1
  7. package/assets/{KnowledgeBaseContent-3hE8vBra.js → KnowledgeBaseContent-C_JxGQXg.js} +3 -3
  8. package/assets/{MVCreator-2NIxaaSL.js → MVCreator-DOt6pxq2.js} +1 -1
  9. package/assets/{ModelBenchmarkWorkbench-CacNyFbi.js → ModelBenchmarkWorkbench-3j77ocpe.js} +1 -1
  10. package/assets/{ModelDropdown-3MjTl1AO.js → ModelDropdown-CHYgRb1r.js} +1 -1
  11. package/assets/{MusicAnalyzer-Mmu92A4Y.js → MusicAnalyzer-BTXks5oV.js} +1 -1
  12. package/assets/{MusicAnalyzer-Drf2j8jn.js → MusicAnalyzer-Dr-DPePj.js} +1 -1
  13. package/assets/{ResizableDivider-B_67th7H.js → ResizableDivider-P1jpoJ3i.js} +1 -1
  14. package/assets/{TaskQueuePanel-VfjKIooN.js → TaskQueuePanel-D6NtMAbm.js} +1 -1
  15. package/assets/{VideoAnalyzer-DNWjNcIx.js → VideoAnalyzer-BHZMqLIa.js} +1 -1
  16. package/assets/{ai-generation-preferences-service-Ch1XhjkZ.js → ai-generation-preferences-service-CabuQA69.js} +1 -1
  17. package/assets/{arc-DE4qRd9D.js → arc-BajUk0_Z.js} +1 -1
  18. package/assets/{arc-DJ5Mb9x1.js → arc-Z9PGo_2L.js} +1 -1
  19. package/assets/{batch-image-generation-Bk8HSFol.js → batch-image-generation-RKz5tz-Y.js} +1 -1
  20. package/assets/{blockDiagram-38ab4fdb-B62iB8ti.js → blockDiagram-38ab4fdb-BsEJDcLK.js} +1 -1
  21. package/assets/{blockDiagram-38ab4fdb-D2MnfN1Q.js → blockDiagram-38ab4fdb-Cfmk3_6A.js} +1 -1
  22. package/assets/{c4Diagram-3d4e48cf-CgUaipiZ.js → c4Diagram-3d4e48cf-D2OyfHpd.js} +1 -1
  23. package/assets/{c4Diagram-3d4e48cf-DHV35ltP.js → c4Diagram-3d4e48cf-K-ewbsK1.js} +1 -1
  24. package/assets/{canvas-insertion-ZEZkcXvB.js → canvas-insertion-CYbFgP4L.js} +1 -1
  25. package/assets/channel-6DAc0JPc.js +1 -0
  26. package/assets/channel-WrMsNCbC.js +1 -0
  27. package/assets/{classDiagram-70f12bd4-C6X-VZXt.js → classDiagram-70f12bd4-BGEF352u.js} +1 -1
  28. package/assets/{classDiagram-70f12bd4-OH5sF1K-.js → classDiagram-70f12bd4-Gn3MZjEL.js} +1 -1
  29. package/assets/{classDiagram-v2-f2320105-otk4V9KH.js → classDiagram-v2-f2320105-C_aAfIgL.js} +1 -1
  30. package/assets/{classDiagram-v2-f2320105-D1I5s2af.js → classDiagram-v2-f2320105-DYPMFlcT.js} +1 -1
  31. package/assets/{clipper-BWlMmsTH.js → clipper-ByL4oIbZ.js} +1 -1
  32. package/assets/clone-keJVIubx.js +1 -0
  33. package/assets/{createText-2e5e7dd3-DuiUpOXV.js → createText-2e5e7dd3-C0UgSBh5.js} +1 -1
  34. package/assets/{createText-2e5e7dd3-D78Dn_q8.js → createText-2e5e7dd3-CoA6JNKB.js} +1 -1
  35. package/assets/{edges-e0da2a9e-Br3GgeJK.js → edges-e0da2a9e-DmyL0L_b.js} +1 -1
  36. package/assets/{edges-e0da2a9e-Dio4S9-4.js → edges-e0da2a9e-qdTreft0.js} +1 -1
  37. package/assets/{erDiagram-9861fffd-BYkBBs0M.js → erDiagram-9861fffd-Bjyf78Da.js} +1 -1
  38. package/assets/{erDiagram-9861fffd-DuZccGHy.js → erDiagram-9861fffd-DYWtVkXG.js} +1 -1
  39. package/assets/{flowDb-956e92f1-BvHxN76x.js → flowDb-956e92f1-Clfuqh48.js} +1 -1
  40. package/assets/{flowDb-956e92f1-D6cTY_st.js → flowDb-956e92f1-vnfymslR.js} +1 -1
  41. package/assets/{flowDiagram-66a62f08-Bh5LanWu.js → flowDiagram-66a62f08-54OX2XOH.js} +1 -1
  42. package/assets/{flowDiagram-66a62f08-rCNbZEwY.js → flowDiagram-66a62f08-lS8fOa4T.js} +1 -1
  43. package/assets/flowDiagram-v2-96b9c2cf-Bw7qAcFu.js +1 -0
  44. package/assets/flowDiagram-v2-96b9c2cf-DGyrUMgR.js +1 -0
  45. package/assets/{flowchart-elk-definition-4a651766-llVLlxyE.js → flowchart-elk-definition-4a651766-CXdElD40.js} +1 -1
  46. package/assets/{flowchart-elk-definition-4a651766-CIShIr5E.js → flowchart-elk-definition-4a651766-D4UghemK.js} +1 -1
  47. package/assets/{ganttDiagram-c361ad54-j2pPvoOi.js → ganttDiagram-c361ad54-Bl7rQCLW.js} +1 -1
  48. package/assets/{ganttDiagram-c361ad54-CUtUP4cJ.js → ganttDiagram-c361ad54-CwAjbWcn.js} +1 -1
  49. package/assets/{gitGraphDiagram-72cf32ee-hQmVrZTT.js → gitGraphDiagram-72cf32ee-B-ykaDuR.js} +1 -1
  50. package/assets/{gitGraphDiagram-72cf32ee-BijhDF7a.js → gitGraphDiagram-72cf32ee-ChvlaDvG.js} +1 -1
  51. package/assets/{graph-CVdXivUk.js → graph-Bq1HvHkL.js} +1 -1
  52. package/assets/{graph-iERr38Mn.js → graph-DM094zt_.js} +1 -1
  53. package/assets/{index-3862675e-BCU8UapW.js → index-3862675e-CA0xjB9W.js} +1 -1
  54. package/assets/{index-3862675e-BdD6mhWW.js → index-3862675e-DGrSmeWu.js} +1 -1
  55. package/assets/{index-CxqCKbLy.js → index-AFp_qpAI.js} +1 -1
  56. package/assets/{index-q02ppfIX.js → index-B4dceFKj.js} +1 -1
  57. package/assets/{index-BmNN2uGW.js → index-B67KSDhv.js} +1 -1
  58. package/assets/{index-ByxyNkwM.js → index-BC221_MJ.js} +1 -1
  59. package/assets/{index-nPSeKWRU.js → index-BGFWA6Zt.js} +1 -1
  60. package/assets/{index-DCjrDHEd.js → index-BH3jS3gm.js} +1 -1
  61. package/assets/{index-B-bas2QJ.js → index-BKTLxghO.js} +1 -1
  62. package/assets/{index-CW9BeyEu.js → index-Bks4xBST.js} +1 -1
  63. package/assets/{index-CvlBHvN3.js → index-BmEFRKV7.js} +1 -1
  64. package/assets/{index-DuFyvKRm.js → index-C3h-b0UN.js} +1 -1
  65. package/assets/{index-CmOEsqBQ.js → index-C5Onm0uO.js} +1 -1
  66. package/assets/{index-DYtXgeSz.js → index-CGelrSXy.js} +1 -1
  67. package/assets/{index-vw8fjMik.js → index-CKBsqCzR.js} +1 -1
  68. package/assets/{index-DjGrNkrV.js → index-CKjzms_e.js} +1 -1
  69. package/assets/{index-CxUWaNUo.js → index-CMLI8gQy.js} +1 -1
  70. package/assets/{index-CkjuY786.js → index-CVEllvWf.js} +1 -1
  71. package/assets/{index-BUZUbTWS.js → index-CW_ala_3.js} +1 -1
  72. package/assets/{index-BxdH1-er.js → index-Ci5Z3DWY.js} +1 -1
  73. package/assets/{index-BeRhCeQu.js → index-CtNjfEqK.js} +1 -1
  74. package/assets/{index-BakDREx4.js → index-CvbEsbIE.js} +1 -1
  75. package/assets/{index-BnaNWg7x.js → index-DM-iV9Y8.js} +2 -2
  76. package/assets/{index-DMfHKITi.js → index-DTqVJVfv.js} +1 -1
  77. package/assets/{index-BdSFouqR.js → index-DZtf3zC8.js} +1 -1
  78. package/assets/{index-ByECpktB.js → index-D_LadtY8.js} +1 -1
  79. package/assets/{index-UeGDfQIX.js → index-DiSWR48t.js} +1 -1
  80. package/assets/{index-D0O0qYML.js → index-DsFroXrj.js} +1 -1
  81. package/assets/{index-BN7eABQE.js → index-DxqCsnoj.js} +1 -1
  82. package/assets/{index-B_eFETCZ.js → index-Jvh12pKI.js} +1 -1
  83. package/assets/{index-CMQMxwMb.js → index-gHdnUGOu.js} +3 -3
  84. package/assets/{index-CE0NChcB.js → index-kKjFXTNL.js} +1 -1
  85. package/assets/{index-D4R9cQ86.js → index-v1v0x1ci.js} +3 -3
  86. package/assets/{infoDiagram-f8f76790-Cmv7jbWa.js → infoDiagram-f8f76790-C-wYgjah.js} +1 -1
  87. package/assets/{infoDiagram-f8f76790-D0DSz5Ue.js → infoDiagram-f8f76790-Cu-3eq4R.js} +1 -1
  88. package/assets/{journeyDiagram-49397b02-D6HU8bXU.js → journeyDiagram-49397b02-BG8aYQK6.js} +1 -1
  89. package/assets/{journeyDiagram-49397b02-Db00D03K.js → journeyDiagram-49397b02-DXPaY9vn.js} +1 -1
  90. package/assets/{layout-CPj4wl_r.js → layout-DvIBYRXu.js} +1 -1
  91. package/assets/{layout-DGJFFi9s.js → layout-SoDWNnQD.js} +1 -1
  92. package/assets/{line-D_WC7vRh.js → line-Bxc-zIvZ.js} +1 -1
  93. package/assets/{line-CpXi5g86.js → line-CFFXuH78.js} +1 -1
  94. package/assets/{linear-n85WiAhX.js → linear-BF0xIQKP.js} +1 -1
  95. package/assets/{linear-UpmxQM2f.js → linear-DQ3XkjOP.js} +1 -1
  96. package/assets/{main-DX4kRYQX.js → main-8GBlYJSO.js} +8 -8
  97. package/assets/{mermaid.core-N7WwfYcf.js → mermaid.core-BGyfnsLl.js} +3 -3
  98. package/assets/{mindmap-definition-fc14e90a-C8U6pdZ2.js → mindmap-definition-fc14e90a-CrYWIUXi.js} +1 -1
  99. package/assets/{mindmap-definition-fc14e90a-D2hbUBx2.js → mindmap-definition-fc14e90a-DOkI3ebm.js} +1 -1
  100. package/assets/{model-benchmark-launcher-BrOG9Vlm.js → model-benchmark-launcher-DtJmU6Wc.js} +1 -1
  101. package/assets/{model-benchmark-service-DDklUBjC.js → model-benchmark-service-B0QCqInK.js} +1 -1
  102. package/assets/{model-selection-BaH65gMK.js → model-selection-CbzU26xQ.js} +1 -1
  103. package/assets/{photo-wall-splitter-QuaIbsZ1.js → photo-wall-splitter-BPzdMtA1.js} +1 -1
  104. package/assets/{pieDiagram-8a3498a8-BPHw5PxR.js → pieDiagram-8a3498a8-ChLZxjKv.js} +1 -1
  105. package/assets/{pieDiagram-8a3498a8-DKV5uwrs.js → pieDiagram-8a3498a8-DAWd9-jL.js} +1 -1
  106. package/assets/{quadrantDiagram-120e2f19-pe-wI-U4.js → quadrantDiagram-120e2f19-CBBovNE2.js} +1 -1
  107. package/assets/{quadrantDiagram-120e2f19-DQdaeBYM.js → quadrantDiagram-120e2f19-DSvfgE7I.js} +1 -1
  108. package/assets/{requirementDiagram-deff3bca-DYepoptc.js → requirementDiagram-deff3bca-De51fyhT.js} +1 -1
  109. package/assets/{requirementDiagram-deff3bca-QX4OaNTO.js → requirementDiagram-deff3bca-ke6SiEw1.js} +1 -1
  110. package/assets/{sankeyDiagram-04a897e0-DJkKTFXr.js → sankeyDiagram-04a897e0-BxiqkhtK.js} +1 -1
  111. package/assets/{sankeyDiagram-04a897e0-1bYf2R8i.js → sankeyDiagram-04a897e0-Clr8_HiZ.js} +1 -1
  112. package/assets/{sequenceDiagram-704730f1-B52OA1Y3.js → sequenceDiagram-704730f1-Bc8zPHLG.js} +1 -1
  113. package/assets/{sequenceDiagram-704730f1-B4QsYTCd.js → sequenceDiagram-704730f1-BfBUJmAu.js} +1 -1
  114. package/assets/{settings-dialog-Bueh6yYA.js → settings-dialog-C9BMj8Zj.js} +1 -1
  115. package/assets/{skill-dsl-parser-CPpdtdC1.js → skill-dsl-parser-BxkJ9Ixc.js} +1 -1
  116. package/assets/{stateDiagram-587899a1-D221rMST.js → stateDiagram-587899a1-DAil8S_m.js} +1 -1
  117. package/assets/{stateDiagram-587899a1-X7bhoHKe.js → stateDiagram-587899a1-Vop8VRn5.js} +1 -1
  118. package/assets/{stateDiagram-v2-d93cdb3a-D9VdRPIN.js → stateDiagram-v2-d93cdb3a-8b1lkei5.js} +1 -1
  119. package/assets/{stateDiagram-v2-d93cdb3a-CGMASaM9.js → stateDiagram-v2-d93cdb3a-BHm8pPuv.js} +1 -1
  120. package/assets/{styles-6aaf32cf-D_xcN1dm.js → styles-6aaf32cf-BlD8JxQr.js} +1 -1
  121. package/assets/{styles-6aaf32cf-DHTzglnJ.js → styles-6aaf32cf-C4CEUYqK.js} +1 -1
  122. package/assets/{styles-9a916d00-w5Yn3LRO.js → styles-9a916d00-C6tkW5rH.js} +1 -1
  123. package/assets/{styles-9a916d00-BVoYXPeR.js → styles-9a916d00-Oss0YMv5.js} +1 -1
  124. package/assets/{styles-c10674c1-xX_gtHzZ.js → styles-c10674c1-D4YQTLGD.js} +1 -1
  125. package/assets/{styles-c10674c1-C3cgfc7I.js → styles-c10674c1-D6N_fge5.js} +1 -1
  126. package/assets/{svgDrawCommon-08f97a94-DFof-iml.js → svgDrawCommon-08f97a94-BOSx1sQS.js} +1 -1
  127. package/assets/{svgDrawCommon-08f97a94-DxU2UGYh.js → svgDrawCommon-08f97a94-RZvmFGZL.js} +1 -1
  128. package/assets/{timeline-definition-85554ec2-CzV_JohE.js → timeline-definition-85554ec2-BL5y0l6c.js} +1 -1
  129. package/assets/{timeline-definition-85554ec2-FPml3o0r.js → timeline-definition-85554ec2-BY6Jx-ZP.js} +1 -1
  130. package/assets/{tool-windows-hjm6YiPY.js → tool-windows-C4D0lII2.js} +137 -137
  131. package/assets/{ttd-dialog-CqISZ7cy.js → ttd-dialog-qD0QkDID.js} +4 -4
  132. package/assets/{use-runtime-models-C0uyCfar.js → use-runtime-models-BLwgp0M1.js} +1 -1
  133. package/assets/{useCharacters-BGdX9007.js → useCharacters-945b6dqW.js} +1 -1
  134. package/assets/{useWorkflowSubmission-BmFQdWt3.js → useWorkflowSubmission-Z0u0KCNN.js} +2 -2
  135. package/assets/{video-analyze-DszumYAr.js → video-analyze-Co9na7Gr.js} +1 -1
  136. package/assets/{video-generation-DEL-kJgF.js → video-generation-x2UMMPYg.js} +1 -1
  137. package/assets/{video-recovery-service-C9y_bfU1.js → video-recovery-service-BsV5nlEP.js} +1 -1
  138. package/assets/{workflow-generation-utils-Da12qXTb.js → workflow-generation-utils-CZULSJWQ.js} +2 -2
  139. package/assets/{workflow-submission-service-BuFuRV_m.js → workflow-submission-service-C-eCWm_8.js} +1 -1
  140. package/assets/{xychartDiagram-e933f94c-C41tCiSk.js → xychartDiagram-e933f94c-CNjZprqQ.js} +1 -1
  141. package/assets/{xychartDiagram-e933f94c-HanO46iU.js → xychartDiagram-e933f94c-DjIBec-i.js} +1 -1
  142. package/changelog.json +16 -0
  143. package/idle-prefetch-manifest.json +6 -6
  144. package/manifest.json +3 -3
  145. package/package.json +1 -1
  146. package/precache-manifest.json +304 -304
  147. package/sw.js +5 -5
  148. package/version.json +7 -3
  149. package/assets/channel-B5QZCgOy.js +0 -1
  150. package/assets/channel-CU3dhzIS.js +0 -1
  151. package/assets/clone-BAOxFbud.js +0 -1
  152. package/assets/flowDiagram-v2-96b9c2cf-BEdEe3Ip.js +0 -1
  153. package/assets/flowDiagram-v2-96b9c2cf-CVItVSoD.js +0 -1
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./tool-windows-Cos6lOhr.css"])))=>i.map(i=>d[i]);
2
- import{r as t,y as e,bD as Ot,hj as ce,bW as me,dM as Xt,cV as Te,cT as lt,iS as he,bw as _e,i$ as ke,mM as Vt,mN as Yt,bV as V,hk as we,mO as ze,hp as ge,kq as dt,cy as Ht,hh as C,ct as qt,cM as Qt,mP as Zt,cP as Gt,cQ as Jt,mQ as Le,mR as es,kr as De,lv as Ae,mS as ts,hM as ss,bx as ns,ig as je,iK as ut,fF as xe,mT as as,mU as rs,bm as mt,cr as os,mV as is,al as I,mW as ht,mX as xt,bj as cs,hw as ls,hv as Je,hn as $e,hq as ds,mY as us,mZ as ms,hL as hs,aI as xs,m_ as et,m$ as tt,jt as ft,_ as Me,n0 as fs,n1 as ps,n2 as st,gZ as bs,kn as gs,n3 as _s,n4 as ks}from"./tool-windows-hjm6YiPY.js";import{a as Ie,g as ws,E as oe,d as nt,c as js}from"./skill-dsl-parser-CPpdtdC1.js";import{ap as vs,Q as Pe}from"./index-BnaNWg7x.js";/* empty css */import{g as pt}from"./index-D4R9cQ86.js";import{M as Ns}from"./ChatDrawer-CqZHx7x_.js";import"./katex-Cu_Erd72.js";import"./index-q02ppfIX.js";import"./index.dom-C3-224fz.js";import"./video-generation-DEL-kJgF.js";import"./canvas-insertion-ZEZkcXvB.js";import"./video-analyze-DszumYAr.js";import"./use-runtime-models-C0uyCfar.js";import"./model-benchmark-service-DDklUBjC.js";import"./model-selection-BaH65gMK.js";import"./main-DX4kRYQX.js";const ie="__system_skill__";function ys(s){const n=new Date(s),i=new Date;return n.getFullYear()===i.getFullYear()&&n.getMonth()===i.getMonth()&&n.getDate()===i.getDate()?n.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):n.getFullYear()===i.getFullYear()?n.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit"}):n.toLocaleDateString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit"})}const Cs=({directories:s,notesByDir:n,noteTagsMap:i,noteCounts:c,selectedDirId:k,selectedNoteId:f,expandedDirIds:x,isCreatingDir:l,skillDirName:j="Skill",onSelectDir:L,onToggleExpand:v,onCreateDir:N,onCancelCreateDir:M,onRenameDir:T,onDeleteDir:b,onSelectNote:y,onCreateNote:d,onDeleteNote:m,onDuplicateDir:A,onDuplicateNote:F,onInsertNoteToCanvas:P})=>{const[B,h]=t.useState(""),[S,W]=t.useState(null),[E,q]=t.useState(""),[H,Y]=t.useState(null);t.useEffect(()=>{const p=()=>Y(null),R=()=>Y(null);return document.addEventListener("click",p),document.addEventListener("scroll",R,!0),()=>{document.removeEventListener("click",p),document.removeEventListener("scroll",R,!0)}},[]);const _=t.useCallback((p,R,O,J=!1)=>{p.preventDefault(),p.stopPropagation(),Y({x:p.clientX,y:p.clientY,type:R,id:O,isDefault:J})},[]),K=t.useCallback(async()=>{const p=B.trim();if(p)try{await N(p),h(""),M()}catch{}},[B,N,M]),U=t.useCallback(async p=>{const R=E.trim();if(R)try{await T(p,R),W(null)}catch{}},[E,T]);return e.jsxs("div",{className:"kb-tree",children:[l&&e.jsxs("div",{className:"kb-tree__create-row",children:[e.jsx("input",{className:"kb-tree__input",value:B,onChange:p=>h(p.target.value),onKeyDown:p=>{p.key==="Enter"&&K(),p.key==="Escape"&&M()},placeholder:"目录名称",autoFocus:!0}),e.jsx("button",{className:"kb-tree__icon-btn",onClick:K,children:e.jsx(ce,{size:14})}),e.jsx("button",{className:"kb-tree__icon-btn",onClick:M,children:e.jsx(me,{size:14})})]}),e.jsx("div",{className:"kb-tree__list",children:s.map(p=>e.jsx(Ss,{dir:p,isSelected:k===p.id,isExpanded:x.has(p.id),notes:n[p.id]||[],noteCount:c[p.id]||0,noteTagsMap:i,selectedNoteId:f,isRenaming:S===p.id,renameValue:E,onSelectDir:()=>{L(p.id),x.has(p.id)||v(p.id)},onToggleExpand:()=>{v(p.id),Y(null)},onStartRename:()=>{W(p.id),q(p.name),Y(null)},onRenameChange:q,onRenameConfirm:()=>U(p.id),onRenameCancel:()=>W(null),onDeleteDir:()=>{b(p.id),Y(null)},onCreateNote:()=>{d(p.id),Y(null)},onSelectNote:y,onDeleteNote:R=>{m(R),Y(null)},onContextMenu:R=>_(R,"directory",p.id,p.isDefault),onNoteContextMenu:(R,O)=>_(R,"note",O),isSkillDir:p.name===j},p.id))}),H&&Ot.createPortal(e.jsx("div",{className:"kb-context-menu",style:{top:H.y,left:H.x,zIndex:Xt.DROPDOWN_PORTAL},onClick:p=>p.stopPropagation(),children:H.type==="directory"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{A(H.id),Y(null)},children:[e.jsx(Te,{size:14}),e.jsx("span",{children:"复制目录"})]}),e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{var p;W(H.id),q(((p=s.find(R=>R.id===H.id))==null?void 0:p.name)||""),Y(null)},children:[e.jsx(lt,{size:14}),e.jsx("span",{children:"重命名"})]}),e.jsxs("div",{className:"kb-context-menu__item kb-context-menu__item--danger",onClick:()=>{b(H.id),Y(null)},children:[e.jsx(he,{size:14}),e.jsx("span",{children:"删除"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{F(H.id),Y(null)},children:[e.jsx(Te,{size:14}),e.jsx("span",{children:"创建副本"})]}),P&&e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{const R=Object.values(n).flat().find(O=>O.id===H.id);R&&P(R),Y(null)},children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),e.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]}),e.jsx("span",{children:"插入到画布"})]}),e.jsxs("div",{className:"kb-context-menu__item kb-context-menu__item--danger",onClick:()=>{m(H.id),Y(null)},children:[e.jsx(he,{size:14}),e.jsx("span",{children:"删除"})]})]})}),document.body)]})},Ss=({dir:s,isSelected:n,isExpanded:i,notes:c,noteCount:k,noteTagsMap:f,selectedNoteId:x,isRenaming:l,renameValue:j,isSkillDir:L=!1,onSelectDir:v,onToggleExpand:N,onStartRename:M,onRenameChange:T,onRenameConfirm:b,onRenameCancel:y,onDeleteDir:d,onCreateNote:m,onSelectNote:A,onDeleteNote:F,onContextMenu:P,onNoteContextMenu:B})=>e.jsxs("div",{className:`kb-tree__dir ${n?"kb-tree__dir--selected":""}`,children:[e.jsxs("div",{className:"kb-tree__dir-row",onClick:v,onContextMenu:P,children:[e.jsx("button",{className:"kb-tree__expand-btn",onClick:h=>{h.stopPropagation(),N()},children:i?e.jsx(_e,{size:14}):e.jsx(ke,{size:14})}),i?e.jsx(Vt,{size:16}):e.jsx(Yt,{size:16}),l?e.jsx("input",{className:"kb-tree__input kb-tree__input--inline",value:j,onChange:h=>T(h.target.value),onKeyDown:h=>{h.key==="Enter"&&b(),h.key==="Escape"&&y()},onClick:h=>h.stopPropagation(),autoFocus:!0}):e.jsx("span",{className:"kb-tree__dir-name",children:s.name}),e.jsx("span",{className:"kb-tree__dir-count",children:k}),e.jsxs("div",{className:"kb-tree__dir-actions",children:[e.jsx(V,{content:"新建笔记",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn",onClick:h=>{h.stopPropagation(),m()},children:e.jsx(we,{size:12})})}),e.jsxs(e.Fragment,{children:[e.jsx(V,{content:"重命名",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn",onClick:h=>{h.stopPropagation(),M()},children:e.jsx(lt,{size:12})})}),e.jsx(V,{content:"删除",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn kb-tree__icon-btn--danger",onClick:h=>{h.stopPropagation(),d()},children:e.jsx(he,{size:12})})})]})]})]}),i&&e.jsxs("div",{className:"kb-tree__notes",children:[L&&Ie.map(h=>{const S=`${ie}${h.id}`,W=x===S;return e.jsxs("div",{className:`kb-tree__note-row kb-tree__note-row--system ${W?"kb-tree__note-row--selected":""}`,onClick:()=>A(S),children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(ze,{size:14})}),e.jsx("div",{className:"kb-tree__note-content",children:e.jsxs("div",{className:"kb-tree__note-title",children:[h.name,e.jsx("span",{className:"kb-tree__system-badge",children:"系统"})]})})]},S)}),L&&ws().map(h=>{const S=`${oe}${h.id}`,W=x===S;return e.jsxs("div",{className:`kb-tree__note-row kb-tree__note-row--system ${W?"kb-tree__note-row--selected":""}`,onClick:()=>A(S),children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(ze,{size:14})}),e.jsx("div",{className:"kb-tree__note-content",children:e.jsxs("div",{className:"kb-tree__note-title",children:[h.name,e.jsx("span",{className:"kb-tree__system-badge",children:"系统"})]})})]},S)}),c.length===0&&!L&&e.jsx("div",{className:"kb-tree__notes-empty",children:"暂无笔记"}),c.length===0&&L&&Ie.length===0&&e.jsx("div",{className:"kb-tree__notes-empty",children:"暂无笔记"}),Array.from(new Map(c.map(h=>[h.id,h])).values()).map(h=>{const S=x===h.id,W=f[h.id]||[],E=h.metadata;return e.jsx(Es,{note:h,isSelected:S,tags:W,metadata:E,onSelect:()=>A(h.id),onDelete:()=>F(h.id),onContextMenu:q=>B(q,h.id)},h.id)})]})]}),Es=({note:s,isSelected:n,tags:i,metadata:c,onSelect:k,onDelete:f,onContextMenu:x})=>e.jsxs("div",{className:`kb-tree__note-row ${n?"kb-tree__note-row--selected":""}`,onClick:k,onContextMenu:x,children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(ge,{size:14})}),e.jsxs("div",{className:"kb-tree__note-content",children:[e.jsx("div",{className:"kb-tree__note-title",children:s.title||"无标题"}),(c==null?void 0:c.domain)&&e.jsxs("div",{className:"kb-tree__note-domain",children:[c.faviconUrl?e.jsx("img",{src:c.faviconUrl,alt:"",className:"kb-tree__favicon",onError:l=>{l.target.style.display="none"}}):e.jsx(dt,{size:10}),e.jsx("span",{children:c.domain})]}),e.jsxs("div",{className:"kb-tree__note-meta",children:[i.length>0&&e.jsxs("div",{className:"kb-tree__note-tags",children:[i.slice(0,2).map(l=>e.jsx("span",{className:"kb-tree__tag-badge",style:{backgroundColor:`${l.color}20`,color:l.color},children:l.name},l.id)),i.length>2&&e.jsxs("span",{className:"kb-tree__tag-more",children:["+",i.length-2]})]}),i.length===0&&!(c!=null&&c.domain)&&e.jsx("span",{className:"kb-tree__note-time",children:ys(s.updatedAt)})]})]}),e.jsx("button",{className:"kb-tree__note-delete",onClick:l=>{l.stopPropagation(),f()},title:"删除笔记",children:e.jsx(he,{size:12})})]}),at=({allTags:s,selectedTagIds:n,onSelectedChange:i,onCreateTag:c,showCount:k=!1})=>{const[f,x]=t.useState(!1),[l,j]=t.useState(""),[L,v]=t.useState(!1),N=t.useRef(null);t.useEffect(()=>{if(!f)return;const d=m=>{N.current&&!N.current.contains(m.target)&&(x(!1),v(!1),j(""))};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[f]);const M=t.useCallback(d=>{const m=n.includes(d)?n.filter(A=>A!==d):[...n,d];i(m)},[n,i]),T=t.useCallback((d,m)=>{m.stopPropagation(),i(n.filter(A=>A!==d))},[n,i]),b=t.useCallback(async()=>{const d=l.trim();if(d)try{const m=await c(d);i([...n,m.id]),j(""),v(!1)}catch{}},[l,c,n,i]),y=s.filter(d=>n.includes(d.id));return e.jsxs("div",{className:"kb-tag-selector",ref:N,children:[e.jsxs("div",{className:"kb-tag-selector__selected",children:[y.map(d=>e.jsxs("span",{className:"kb-tag-selector__tag kb-tag-selector__tag--selected",style:{"--tag-color":d.color,borderColor:d.color,backgroundColor:`${d.color}15`},children:[e.jsx("span",{className:"kb-tag-selector__dot",style:{backgroundColor:d.color}}),e.jsx("span",{children:d.name}),e.jsx("button",{className:"kb-tag-selector__remove",onClick:m=>T(d.id,m),children:e.jsx(V,{content:"移除标签",showArrow:!1,children:e.jsx("span",{children:e.jsx(me,{size:11})})})})]},d.id)),e.jsxs("button",{className:"kb-tag-selector__add-btn",onClick:()=>x(d=>!d),children:[e.jsx(we,{size:13}),e.jsx("span",{children:"标签"})]})]}),f&&e.jsxs("div",{className:"kb-tag-selector__dropdown",children:[e.jsxs("div",{className:"kb-tag-selector__tags",children:[s.length===0&&e.jsx("span",{className:"kb-tag-selector__empty",children:"暂无标签"}),s.map(d=>{const m=n.includes(d.id);return e.jsxs("button",{className:`kb-tag-selector__tag ${m?"kb-tag-selector__tag--selected":""}`,style:{"--tag-color":d.color,borderColor:m?d.color:void 0,backgroundColor:m?`${d.color}15`:void 0},onClick:()=>M(d.id),children:[e.jsx("span",{className:"kb-tag-selector__dot",style:{backgroundColor:d.color}}),e.jsx("span",{children:d.name}),k&&e.jsxs("span",{className:"kb-tag-selector__count",children:["(",d.count,")"]}),m&&e.jsx(me,{size:12})]},d.id)})]}),L?e.jsxs("div",{className:"kb-tag-selector__create",children:[e.jsx("input",{className:"kb-tag-selector__input",value:l,onChange:d=>j(d.target.value),onKeyDown:d=>{d.key==="Enter"&&b(),d.key==="Escape"&&(v(!1),j(""))},placeholder:"标签名称",autoFocus:!0}),e.jsx("button",{className:"kb-tag-selector__create-btn",onClick:b,children:"确定"})]}):e.jsxs("button",{className:"kb-tag-selector__new-btn",onClick:()=>v(!0),children:[e.jsx(we,{size:13}),e.jsx("span",{children:"新建标签"})]})]})]})},Rs=({outputType:s,onOutputTypeChange:n,readOnly:i=!1})=>e.jsx("div",{className:"mcp-tool-selector",children:e.jsxs("div",{className:"mcp-tool-selector__output-type",children:[e.jsx("span",{className:"mcp-tool-selector__output-type-label",children:"输出类型"}),e.jsx("div",{className:"mcp-tool-selector__output-type-options",children:i?e.jsx("span",{className:"mcp-tool-selector__output-type-value",children:s==="image"?"图片":s==="video"?"视频":s==="ppt"?"PPT":"文本"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${!s||s==="text"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>n==null?void 0:n(void 0),children:"文本"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${s==="image"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>n==null?void 0:n("image"),children:"图片"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${s==="video"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>n==null?void 0:n("video"),children:"视频"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${s==="ppt"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>n==null?void 0:n("ppt"),children:"PPT"})]})})]})}),Ms=({note:s,allTags:n,noteTags:i,readOnly:c=!1,isSkillDirectory:k=!1,onUpdateNote:f,onSetNoteTags:x,onCreateTag:l})=>{var fe;const[j,L]=t.useState(""),[v,N]=t.useState(!1),[M,T]=t.useState(!1),[b,y]=t.useState(null),d=t.useRef(null),m=t.useRef(null),A=t.useRef(null),F=t.useRef(null),P=Ht(),B=typeof window<"u"&&"speechSynthesis"in window,h=t.useMemo(()=>i.map(z=>z.id),[i]),[S,W]=t.useState(void 0);t.useEffect(()=>{var z;W(s&&k&&((z=s.metadata)==null?void 0:z.outputType)||void 0)},[s==null?void 0:s.id,k]);const E=s==null?void 0:s.metadata,q=E&&(E.sourceUrl||E.author||E.domain);t.useEffect(()=>{var Q;const z=s?`kb-note:${s.id}`:null;if(m.current&&(clearTimeout(m.current),m.current=null),d.current&&(clearTimeout(d.current),d.current=null),s)if(L(s.title),F.current=s.id,k&&!c){const Z=s.content||"";y(Z.trim()?nt.isDSLContent(Z):null)}else y(null);else L(""),F.current=null,y(null);P.mediaType==="reading"&&z&&((Q=P.activeReadingSourceId)!=null&&Q.startsWith(z))&&P.stopPlayback()},[s==null?void 0:s.id,k,c]);const H=t.useCallback(z=>{L(z),s&&(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{f(s.id,{title:z})},500))},[s,f]),Y=t.useCallback(z=>{s&&(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{f(s.id,{content:z})},500),k&&!c&&(d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{z.trim()?y(nt.isDSLContent(z)):y(null)},500)))},[s,f,k,c]),_=t.useCallback(z=>{if(!s)return;W(z);const Q={...s.metadata,outputType:z};z||delete Q.outputType,C.updateNote(s.id,{metadata:Q})},[s]),K=t.useCallback(z=>{s&&x(s.id,z)},[s,x]),U=t.useCallback(()=>{var G;if(!s)return;const z=`kb-note:${s.id}`;if(P.mediaType==="reading"&&((G=P.activeReadingSourceId)==null?void 0:G.startsWith(z))){P.playing?P.pausePlayback():P.resumePlayback();return}const Z=qt({elementId:z,title:s.title||"知识库笔记",content:[s.title,s.content].filter(Boolean).join(`
2
+ import{r as t,y as e,bD as Ot,hj as ce,bW as me,dM as Xt,cV as Te,cT as lt,iS as he,bw as _e,i$ as ke,mM as Vt,mN as Yt,bV as V,hk as we,mO as ze,hp as ge,kq as dt,cy as Ht,hh as C,ct as qt,cM as Qt,mP as Zt,cP as Gt,cQ as Jt,mQ as Le,mR as es,kr as De,lv as Ae,mS as ts,hM as ss,bx as ns,ig as je,iK as ut,fF as xe,mT as as,mU as rs,bm as mt,cr as os,mV as is,al as I,mW as ht,mX as xt,bj as cs,hw as ls,hv as Je,hn as $e,hq as ds,mY as us,mZ as ms,hL as hs,aI as xs,m_ as et,m$ as tt,jt as ft,_ as Me,n0 as fs,n1 as ps,n2 as st,gZ as bs,kn as gs,n3 as _s,n4 as ks}from"./tool-windows-C4D0lII2.js";import{a as Ie,g as ws,E as oe,d as nt,c as js}from"./skill-dsl-parser-BxkJ9Ixc.js";import{ap as vs,Q as Pe}from"./index-DM-iV9Y8.js";/* empty css */import{g as pt}from"./index-v1v0x1ci.js";import{M as Ns}from"./ChatDrawer-M1q92KNU.js";import"./katex-Cu_Erd72.js";import"./index-B4dceFKj.js";import"./index.dom-C3-224fz.js";import"./video-generation-x2UMMPYg.js";import"./canvas-insertion-CYbFgP4L.js";import"./video-analyze-Co9na7Gr.js";import"./use-runtime-models-BLwgp0M1.js";import"./model-benchmark-service-B0QCqInK.js";import"./model-selection-CbzU26xQ.js";import"./main-8GBlYJSO.js";const ie="__system_skill__";function ys(s){const n=new Date(s),i=new Date;return n.getFullYear()===i.getFullYear()&&n.getMonth()===i.getMonth()&&n.getDate()===i.getDate()?n.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):n.getFullYear()===i.getFullYear()?n.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit"}):n.toLocaleDateString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit"})}const Cs=({directories:s,notesByDir:n,noteTagsMap:i,noteCounts:c,selectedDirId:k,selectedNoteId:f,expandedDirIds:x,isCreatingDir:l,skillDirName:j="Skill",onSelectDir:L,onToggleExpand:v,onCreateDir:N,onCancelCreateDir:M,onRenameDir:T,onDeleteDir:b,onSelectNote:y,onCreateNote:d,onDeleteNote:m,onDuplicateDir:A,onDuplicateNote:F,onInsertNoteToCanvas:P})=>{const[B,h]=t.useState(""),[S,W]=t.useState(null),[E,q]=t.useState(""),[H,Y]=t.useState(null);t.useEffect(()=>{const p=()=>Y(null),R=()=>Y(null);return document.addEventListener("click",p),document.addEventListener("scroll",R,!0),()=>{document.removeEventListener("click",p),document.removeEventListener("scroll",R,!0)}},[]);const _=t.useCallback((p,R,O,J=!1)=>{p.preventDefault(),p.stopPropagation(),Y({x:p.clientX,y:p.clientY,type:R,id:O,isDefault:J})},[]),K=t.useCallback(async()=>{const p=B.trim();if(p)try{await N(p),h(""),M()}catch{}},[B,N,M]),U=t.useCallback(async p=>{const R=E.trim();if(R)try{await T(p,R),W(null)}catch{}},[E,T]);return e.jsxs("div",{className:"kb-tree",children:[l&&e.jsxs("div",{className:"kb-tree__create-row",children:[e.jsx("input",{className:"kb-tree__input",value:B,onChange:p=>h(p.target.value),onKeyDown:p=>{p.key==="Enter"&&K(),p.key==="Escape"&&M()},placeholder:"目录名称",autoFocus:!0}),e.jsx("button",{className:"kb-tree__icon-btn",onClick:K,children:e.jsx(ce,{size:14})}),e.jsx("button",{className:"kb-tree__icon-btn",onClick:M,children:e.jsx(me,{size:14})})]}),e.jsx("div",{className:"kb-tree__list",children:s.map(p=>e.jsx(Ss,{dir:p,isSelected:k===p.id,isExpanded:x.has(p.id),notes:n[p.id]||[],noteCount:c[p.id]||0,noteTagsMap:i,selectedNoteId:f,isRenaming:S===p.id,renameValue:E,onSelectDir:()=>{L(p.id),x.has(p.id)||v(p.id)},onToggleExpand:()=>{v(p.id),Y(null)},onStartRename:()=>{W(p.id),q(p.name),Y(null)},onRenameChange:q,onRenameConfirm:()=>U(p.id),onRenameCancel:()=>W(null),onDeleteDir:()=>{b(p.id),Y(null)},onCreateNote:()=>{d(p.id),Y(null)},onSelectNote:y,onDeleteNote:R=>{m(R),Y(null)},onContextMenu:R=>_(R,"directory",p.id,p.isDefault),onNoteContextMenu:(R,O)=>_(R,"note",O),isSkillDir:p.name===j},p.id))}),H&&Ot.createPortal(e.jsx("div",{className:"kb-context-menu",style:{top:H.y,left:H.x,zIndex:Xt.DROPDOWN_PORTAL},onClick:p=>p.stopPropagation(),children:H.type==="directory"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{A(H.id),Y(null)},children:[e.jsx(Te,{size:14}),e.jsx("span",{children:"复制目录"})]}),e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{var p;W(H.id),q(((p=s.find(R=>R.id===H.id))==null?void 0:p.name)||""),Y(null)},children:[e.jsx(lt,{size:14}),e.jsx("span",{children:"重命名"})]}),e.jsxs("div",{className:"kb-context-menu__item kb-context-menu__item--danger",onClick:()=>{b(H.id),Y(null)},children:[e.jsx(he,{size:14}),e.jsx("span",{children:"删除"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{F(H.id),Y(null)},children:[e.jsx(Te,{size:14}),e.jsx("span",{children:"创建副本"})]}),P&&e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{const R=Object.values(n).flat().find(O=>O.id===H.id);R&&P(R),Y(null)},children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),e.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]}),e.jsx("span",{children:"插入到画布"})]}),e.jsxs("div",{className:"kb-context-menu__item kb-context-menu__item--danger",onClick:()=>{m(H.id),Y(null)},children:[e.jsx(he,{size:14}),e.jsx("span",{children:"删除"})]})]})}),document.body)]})},Ss=({dir:s,isSelected:n,isExpanded:i,notes:c,noteCount:k,noteTagsMap:f,selectedNoteId:x,isRenaming:l,renameValue:j,isSkillDir:L=!1,onSelectDir:v,onToggleExpand:N,onStartRename:M,onRenameChange:T,onRenameConfirm:b,onRenameCancel:y,onDeleteDir:d,onCreateNote:m,onSelectNote:A,onDeleteNote:F,onContextMenu:P,onNoteContextMenu:B})=>e.jsxs("div",{className:`kb-tree__dir ${n?"kb-tree__dir--selected":""}`,children:[e.jsxs("div",{className:"kb-tree__dir-row",onClick:v,onContextMenu:P,children:[e.jsx("button",{className:"kb-tree__expand-btn",onClick:h=>{h.stopPropagation(),N()},children:i?e.jsx(_e,{size:14}):e.jsx(ke,{size:14})}),i?e.jsx(Vt,{size:16}):e.jsx(Yt,{size:16}),l?e.jsx("input",{className:"kb-tree__input kb-tree__input--inline",value:j,onChange:h=>T(h.target.value),onKeyDown:h=>{h.key==="Enter"&&b(),h.key==="Escape"&&y()},onClick:h=>h.stopPropagation(),autoFocus:!0}):e.jsx("span",{className:"kb-tree__dir-name",children:s.name}),e.jsx("span",{className:"kb-tree__dir-count",children:k}),e.jsxs("div",{className:"kb-tree__dir-actions",children:[e.jsx(V,{content:"新建笔记",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn",onClick:h=>{h.stopPropagation(),m()},children:e.jsx(we,{size:12})})}),e.jsxs(e.Fragment,{children:[e.jsx(V,{content:"重命名",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn",onClick:h=>{h.stopPropagation(),M()},children:e.jsx(lt,{size:12})})}),e.jsx(V,{content:"删除",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn kb-tree__icon-btn--danger",onClick:h=>{h.stopPropagation(),d()},children:e.jsx(he,{size:12})})})]})]})]}),i&&e.jsxs("div",{className:"kb-tree__notes",children:[L&&Ie.map(h=>{const S=`${ie}${h.id}`,W=x===S;return e.jsxs("div",{className:`kb-tree__note-row kb-tree__note-row--system ${W?"kb-tree__note-row--selected":""}`,onClick:()=>A(S),children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(ze,{size:14})}),e.jsx("div",{className:"kb-tree__note-content",children:e.jsxs("div",{className:"kb-tree__note-title",children:[h.name,e.jsx("span",{className:"kb-tree__system-badge",children:"系统"})]})})]},S)}),L&&ws().map(h=>{const S=`${oe}${h.id}`,W=x===S;return e.jsxs("div",{className:`kb-tree__note-row kb-tree__note-row--system ${W?"kb-tree__note-row--selected":""}`,onClick:()=>A(S),children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(ze,{size:14})}),e.jsx("div",{className:"kb-tree__note-content",children:e.jsxs("div",{className:"kb-tree__note-title",children:[h.name,e.jsx("span",{className:"kb-tree__system-badge",children:"系统"})]})})]},S)}),c.length===0&&!L&&e.jsx("div",{className:"kb-tree__notes-empty",children:"暂无笔记"}),c.length===0&&L&&Ie.length===0&&e.jsx("div",{className:"kb-tree__notes-empty",children:"暂无笔记"}),Array.from(new Map(c.map(h=>[h.id,h])).values()).map(h=>{const S=x===h.id,W=f[h.id]||[],E=h.metadata;return e.jsx(Es,{note:h,isSelected:S,tags:W,metadata:E,onSelect:()=>A(h.id),onDelete:()=>F(h.id),onContextMenu:q=>B(q,h.id)},h.id)})]})]}),Es=({note:s,isSelected:n,tags:i,metadata:c,onSelect:k,onDelete:f,onContextMenu:x})=>e.jsxs("div",{className:`kb-tree__note-row ${n?"kb-tree__note-row--selected":""}`,onClick:k,onContextMenu:x,children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(ge,{size:14})}),e.jsxs("div",{className:"kb-tree__note-content",children:[e.jsx("div",{className:"kb-tree__note-title",children:s.title||"无标题"}),(c==null?void 0:c.domain)&&e.jsxs("div",{className:"kb-tree__note-domain",children:[c.faviconUrl?e.jsx("img",{src:c.faviconUrl,alt:"",className:"kb-tree__favicon",onError:l=>{l.target.style.display="none"}}):e.jsx(dt,{size:10}),e.jsx("span",{children:c.domain})]}),e.jsxs("div",{className:"kb-tree__note-meta",children:[i.length>0&&e.jsxs("div",{className:"kb-tree__note-tags",children:[i.slice(0,2).map(l=>e.jsx("span",{className:"kb-tree__tag-badge",style:{backgroundColor:`${l.color}20`,color:l.color},children:l.name},l.id)),i.length>2&&e.jsxs("span",{className:"kb-tree__tag-more",children:["+",i.length-2]})]}),i.length===0&&!(c!=null&&c.domain)&&e.jsx("span",{className:"kb-tree__note-time",children:ys(s.updatedAt)})]})]}),e.jsx("button",{className:"kb-tree__note-delete",onClick:l=>{l.stopPropagation(),f()},title:"删除笔记",children:e.jsx(he,{size:12})})]}),at=({allTags:s,selectedTagIds:n,onSelectedChange:i,onCreateTag:c,showCount:k=!1})=>{const[f,x]=t.useState(!1),[l,j]=t.useState(""),[L,v]=t.useState(!1),N=t.useRef(null);t.useEffect(()=>{if(!f)return;const d=m=>{N.current&&!N.current.contains(m.target)&&(x(!1),v(!1),j(""))};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[f]);const M=t.useCallback(d=>{const m=n.includes(d)?n.filter(A=>A!==d):[...n,d];i(m)},[n,i]),T=t.useCallback((d,m)=>{m.stopPropagation(),i(n.filter(A=>A!==d))},[n,i]),b=t.useCallback(async()=>{const d=l.trim();if(d)try{const m=await c(d);i([...n,m.id]),j(""),v(!1)}catch{}},[l,c,n,i]),y=s.filter(d=>n.includes(d.id));return e.jsxs("div",{className:"kb-tag-selector",ref:N,children:[e.jsxs("div",{className:"kb-tag-selector__selected",children:[y.map(d=>e.jsxs("span",{className:"kb-tag-selector__tag kb-tag-selector__tag--selected",style:{"--tag-color":d.color,borderColor:d.color,backgroundColor:`${d.color}15`},children:[e.jsx("span",{className:"kb-tag-selector__dot",style:{backgroundColor:d.color}}),e.jsx("span",{children:d.name}),e.jsx("button",{className:"kb-tag-selector__remove",onClick:m=>T(d.id,m),children:e.jsx(V,{content:"移除标签",showArrow:!1,children:e.jsx("span",{children:e.jsx(me,{size:11})})})})]},d.id)),e.jsxs("button",{className:"kb-tag-selector__add-btn",onClick:()=>x(d=>!d),children:[e.jsx(we,{size:13}),e.jsx("span",{children:"标签"})]})]}),f&&e.jsxs("div",{className:"kb-tag-selector__dropdown",children:[e.jsxs("div",{className:"kb-tag-selector__tags",children:[s.length===0&&e.jsx("span",{className:"kb-tag-selector__empty",children:"暂无标签"}),s.map(d=>{const m=n.includes(d.id);return e.jsxs("button",{className:`kb-tag-selector__tag ${m?"kb-tag-selector__tag--selected":""}`,style:{"--tag-color":d.color,borderColor:m?d.color:void 0,backgroundColor:m?`${d.color}15`:void 0},onClick:()=>M(d.id),children:[e.jsx("span",{className:"kb-tag-selector__dot",style:{backgroundColor:d.color}}),e.jsx("span",{children:d.name}),k&&e.jsxs("span",{className:"kb-tag-selector__count",children:["(",d.count,")"]}),m&&e.jsx(me,{size:12})]},d.id)})]}),L?e.jsxs("div",{className:"kb-tag-selector__create",children:[e.jsx("input",{className:"kb-tag-selector__input",value:l,onChange:d=>j(d.target.value),onKeyDown:d=>{d.key==="Enter"&&b(),d.key==="Escape"&&(v(!1),j(""))},placeholder:"标签名称",autoFocus:!0}),e.jsx("button",{className:"kb-tag-selector__create-btn",onClick:b,children:"确定"})]}):e.jsxs("button",{className:"kb-tag-selector__new-btn",onClick:()=>v(!0),children:[e.jsx(we,{size:13}),e.jsx("span",{children:"新建标签"})]})]})]})},Rs=({outputType:s,onOutputTypeChange:n,readOnly:i=!1})=>e.jsx("div",{className:"mcp-tool-selector",children:e.jsxs("div",{className:"mcp-tool-selector__output-type",children:[e.jsx("span",{className:"mcp-tool-selector__output-type-label",children:"输出类型"}),e.jsx("div",{className:"mcp-tool-selector__output-type-options",children:i?e.jsx("span",{className:"mcp-tool-selector__output-type-value",children:s==="image"?"图片":s==="video"?"视频":s==="ppt"?"PPT":"文本"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${!s||s==="text"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>n==null?void 0:n(void 0),children:"文本"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${s==="image"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>n==null?void 0:n("image"),children:"图片"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${s==="video"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>n==null?void 0:n("video"),children:"视频"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${s==="ppt"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>n==null?void 0:n("ppt"),children:"PPT"})]})})]})}),Ms=({note:s,allTags:n,noteTags:i,readOnly:c=!1,isSkillDirectory:k=!1,onUpdateNote:f,onSetNoteTags:x,onCreateTag:l})=>{var fe;const[j,L]=t.useState(""),[v,N]=t.useState(!1),[M,T]=t.useState(!1),[b,y]=t.useState(null),d=t.useRef(null),m=t.useRef(null),A=t.useRef(null),F=t.useRef(null),P=Ht(),B=typeof window<"u"&&"speechSynthesis"in window,h=t.useMemo(()=>i.map(z=>z.id),[i]),[S,W]=t.useState(void 0);t.useEffect(()=>{var z;W(s&&k&&((z=s.metadata)==null?void 0:z.outputType)||void 0)},[s==null?void 0:s.id,k]);const E=s==null?void 0:s.metadata,q=E&&(E.sourceUrl||E.author||E.domain);t.useEffect(()=>{var Q;const z=s?`kb-note:${s.id}`:null;if(m.current&&(clearTimeout(m.current),m.current=null),d.current&&(clearTimeout(d.current),d.current=null),s)if(L(s.title),F.current=s.id,k&&!c){const Z=s.content||"";y(Z.trim()?nt.isDSLContent(Z):null)}else y(null);else L(""),F.current=null,y(null);P.mediaType==="reading"&&z&&((Q=P.activeReadingSourceId)!=null&&Q.startsWith(z))&&P.stopPlayback()},[s==null?void 0:s.id,k,c]);const H=t.useCallback(z=>{L(z),s&&(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{f(s.id,{title:z})},500))},[s,f]),Y=t.useCallback(z=>{s&&(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{f(s.id,{content:z})},500),k&&!c&&(d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{z.trim()?y(nt.isDSLContent(z)):y(null)},500)))},[s,f,k,c]),_=t.useCallback(z=>{if(!s)return;W(z);const Q={...s.metadata,outputType:z};z||delete Q.outputType,C.updateNote(s.id,{metadata:Q})},[s]),K=t.useCallback(z=>{s&&x(s.id,z)},[s,x]),U=t.useCallback(()=>{var G;if(!s)return;const z=`kb-note:${s.id}`;if(P.mediaType==="reading"&&((G=P.activeReadingSourceId)==null?void 0:G.startsWith(z))){P.playing?P.pausePlayback():P.resumePlayback();return}const Z=qt({elementId:z,title:s.title||"知识库笔记",content:[s.title,s.content].filter(Boolean).join(`
3
3
 
4
4
  `),origin:{kind:"kb-note",id:s.id}});Z&&Qt({source:Z,queue:[Z]})},[s,P]),p=t.useCallback(async()=>{if(!s)return;const z=await C.exportNoteAsMarkdown(s.id);if(!z)return;const Q=new Blob([z.content],{type:"text/markdown;charset=utf-8"}),Z=URL.createObjectURL(Q),G=document.createElement("a");G.href=Z,G.download=z.filename,document.body.appendChild(G),G.click(),document.body.removeChild(G),URL.revokeObjectURL(Z)},[s]),R=t.useCallback(()=>{c||T(!0)},[c]),O=t.useCallback(z=>{var Q;(Q=A.current)==null||Q.insertMarkdown(vs(z)),T(!1)},[]);if(t.useEffect(()=>()=>{m.current&&clearTimeout(m.current),d.current&&clearTimeout(d.current)},[]),!s)return e.jsx("div",{className:"kb-note-editor kb-note-editor--empty",children:e.jsxs("div",{className:"kb-note-editor__placeholder",children:[e.jsx("div",{className:"kb-note-editor__placeholder-icon",children:e.jsx(Zt,{size:64,strokeWidth:1})}),e.jsx("h3",{className:"kb-note-editor__placeholder-title",children:"无笔记选中"}),e.jsx("p",{className:"kb-note-editor__placeholder-text",children:"选择左侧的一篇笔记开始编辑,或者创建一个新笔记"})]})});const J=`kb-note:${s.id}`,te=P.mediaType==="reading"&&((fe=P.activeReadingSourceId)==null?void 0:fe.startsWith(J));return e.jsxs("div",{className:`kb-note-editor ${c?"kb-note-editor--readonly":""}`,children:[c&&e.jsxs("div",{className:"kb-note-editor__readonly-banner",children:[e.jsx(ze,{size:14}),e.jsx("span",{children:"系统内置 Skill,不可修改"})]}),e.jsxs("div",{className:"kb-note-editor__title-row",children:[e.jsx("input",{className:"kb-note-editor__title",value:j,onChange:z=>!c&&H(z.target.value),placeholder:"笔记标题",readOnly:c}),e.jsxs("div",{className:"kb-note-editor__actions",children:[B&&e.jsx(V,{content:te?P.playing?"暂停朗读":"继续朗读":"语音朗读",showArrow:!1,children:e.jsx("button",{className:`kb-note-editor__action-btn ${te?"kb-note-editor__action-btn--active":""}`,onClick:U,children:te&&P.playing?e.jsx(Gt,{size:14}):e.jsx(Jt,{size:14})})}),B&&te&&e.jsx(V,{content:"停止朗读",showArrow:!1,children:e.jsx("button",{className:"kb-note-editor__action-btn kb-note-editor__action-btn--danger",onClick:P.stopPlayback,children:"■"})}),e.jsx(V,{content:"导出 Markdown",showArrow:!1,children:e.jsx("button",{className:"kb-note-editor__action-btn",onClick:p,children:e.jsx(Le,{size:14})})}),!c&&e.jsx(V,{content:"插入素材",showArrow:!1,children:e.jsx("button",{className:"kb-note-editor__action-btn",onClick:R,children:e.jsx(es,{size:14})})})]})]}),q&&e.jsxs("div",{className:`kb-note-editor__metadata-section ${v?"kb-note-editor__metadata-section--collapsed":""}`,children:[e.jsxs("button",{className:"kb-note-editor__metadata-toggle",onClick:()=>N(!v),title:v?"展开来源信息":"收起来源信息",children:[v?e.jsx(ke,{size:14}):e.jsx(_e,{size:14}),e.jsx("span",{children:"来源信息"})]}),v&&e.jsxs("div",{className:"kb-note-editor__metadata-collapsed",children:[E.author&&e.jsxs("span",{className:"kb-note-editor__metadata-collapsed-item",children:[e.jsx(De,{size:10}),e.jsx("span",{children:E.author})]}),E.sourceUrl&&e.jsxs("a",{href:E.sourceUrl,target:"_blank",rel:"noopener noreferrer",className:"kb-note-editor__metadata-collapsed-link",onClick:z=>z.stopPropagation(),title:E.sourceUrl,children:[e.jsx(Ae,{size:10}),e.jsx("span",{children:E.domain||E.sourceUrl})]})]}),!v&&e.jsxs("div",{className:"kb-note-editor__metadata-body",children:[e.jsx("div",{className:"kb-note-editor__tags",children:e.jsx(at,{allTags:n,selectedTagIds:h,onSelectedChange:K,onCreateTag:l})}),e.jsxs("div",{className:"kb-note-editor__metadata-info",children:[E.domain&&e.jsxs("span",{className:"kb-note-editor__metadata-item",children:[E.faviconUrl?e.jsx("img",{src:E.faviconUrl,alt:"",className:"kb-note-editor__favicon",onError:z=>{z.currentTarget.style.display="none"}}):e.jsx(dt,{size:12}),e.jsx("span",{children:E.domain})]}),E.author&&e.jsxs("span",{className:"kb-note-editor__metadata-item",children:[e.jsx(De,{size:12}),e.jsx("span",{children:E.author})]}),E.publishedAt&&e.jsxs("span",{className:"kb-note-editor__metadata-item",children:[e.jsx(ts,{size:12}),e.jsx("span",{children:E.publishedAt})]})]}),E.sourceUrl&&e.jsx("a",{href:E.sourceUrl,target:"_blank",rel:"noopener noreferrer",className:"kb-note-editor__source-link",children:E.sourceUrl}),E.description&&e.jsx("p",{className:"kb-note-editor__metadata-desc",children:E.description})]})]}),!q&&e.jsx("div",{className:"kb-note-editor__tags",children:e.jsx(at,{allTags:n,selectedTagIds:h,onSelectedChange:K,onCreateTag:l})}),k&&e.jsx("div",{className:"kb-note-editor__mcp-tools",children:e.jsx(Rs,{outputType:S,onOutputTypeChange:_,readOnly:c})}),e.jsx("div",{className:"kb-note-editor__content",children:e.jsx(Pe,{ref:A,markdown:s.content,onChange:c?void 0:Y,placeholder:"开始写点什么...",showModeSwitch:!c,readOnly:c,enableAssetEmbeds:!0,enableAssetLibraryImagePicker:!c,className:"kb-note-markdown"},s.id)}),k&&!c&&b!==null&&e.jsx("div",{className:`kb-note-editor__dsl-status ${b?"kb-note-editor__dsl-status--valid":"kb-note-editor__dsl-status--fallback"}`,children:b?"✓ 已识别为工作流 DSL(正则解析),将直接执行":"⚡ 将由 AI 解析为工作流(大模型解析)"}),M&&e.jsx(ss,{isOpen:M,onClose:()=>T(!1),mode:ns.SELECT,onSelect:O,selectButtonText:"插入到笔记"})]})},Ts=({allTags:s,selectedTagIds:n,onSelectedChange:i})=>{const[c,k]=t.useState(""),[f,x]=t.useState(!1),l=t.useMemo(()=>{if(!c)return s;const N=c.toLowerCase();return s.filter(M=>M.name.toLowerCase().includes(N))},[s,c]),j=N=>{const M=n.includes(N)?n.filter(T=>T!==N):[...n,N];i(M)},L=()=>{i([]),x(!1)},v=e.jsxs("div",{className:"kb-filter-dropdown__content",children:[e.jsx("div",{className:"kb-filter-dropdown__search",children:e.jsx(je,{value:c,onChange:N=>k(N),placeholder:"搜索标签...",prefixIcon:e.jsx(ut,{size:14}),size:"small",clearable:!0})}),e.jsx("div",{className:"kb-filter-dropdown__list",children:l.length>0?l.map(N=>{const M=n.includes(N.id);return e.jsxs("div",{className:`kb-filter-dropdown__item ${M?"is-selected":""}`,onClick:()=>j(N.id),children:[e.jsx("span",{className:"kb-filter-dropdown__item-dot",style:{backgroundColor:N.color}}),e.jsx("span",{className:"kb-filter-dropdown__item-name",children:N.name}),e.jsxs("span",{className:"kb-filter-dropdown__item-count",children:["(",N.count||0,")"]}),M&&e.jsx(ce,{size:14,className:"kb-filter-dropdown__item-check"})]},N.id)}):e.jsx("div",{className:"kb-filter-dropdown__empty",children:"无匹配标签"})}),n.length>0&&e.jsx("div",{className:"kb-filter-dropdown__footer",children:e.jsxs(xe,{theme:"default",variant:"text",size:"small",onClick:L,className:"kb-filter-dropdown__clear-btn",children:[e.jsx(me,{size:14,style:{marginRight:4}}),"清除标签过滤"]})})]});return e.jsx(as,{content:v,visible:f,onVisibleChange:N=>x(N),trigger:"click",placement:"bottom-left",overlayClassName:"kb-filter-dropdown__popup",children:e.jsxs(xe,{variant:n.length>0?"base":"outline",theme:n.length>0?"primary":"default",size:"small",className:`kb-filter-trigger ${n.length>0?"is-active":""}`,children:[e.jsx(rs,{size:14,style:{marginRight:4}}),"标签",n.length>0&&` (${n.length})`]})})},zs=({visible:s,onClose:n,allTags:i,onCreateTag:c,onUpdateTag:k,onDeleteTag:f,onSelectTag:x})=>{const{confirm:l,confirmDialog:j}=mt(),[L,v]=t.useState(!1),[N,M]=t.useState(""),[T,b]=t.useState(null),[y,d]=t.useState(""),m=t.useRef(null);t.useEffect(()=>{L&&m.current&&setTimeout(()=>{var h;(h=m.current)==null||h.focus()},100)},[L]);const A=async()=>{if(!N.trim()){v(!1);return}try{await c(N.trim()),M(""),v(!1),I.success("标签创建成功")}catch{I.error("标签创建失败")}},F=async h=>{if(!y.trim()){b(null);return}try{await k(h,y.trim()),b(null),I.success("标签更新成功")}catch{I.error("标签更新失败")}},P=async(h,S)=>{h.stopPropagation();try{const W=i.find(q=>q.id===S);if(!await l({title:"确认删除标签",description:`确定要删除标签「${(W==null?void 0:W.name)||"未命名标签"}」吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0}))return;await f(S),I.success("标签删除成功")}catch{I.error("标签删除失败")}},B=(h,S)=>{h.stopPropagation(),b(S.id),d(S.name)};return e.jsxs(os,{header:"管理标签",visible:s,onClose:n,footer:null,width:400,className:"kb-tag-management-dialog",children:[e.jsxs("div",{className:"kb-tag-list",children:[L?e.jsx("div",{className:"kb-tag-item kb-tag-item--creating",children:e.jsx(je,{ref:m,value:N,onChange:h=>M(h),onEnter:A,onBlur:A,placeholder:"输入标签名称...",size:"small"})}):e.jsxs("div",{className:"kb-tag-item kb-tag-item--create-btn",onClick:()=>v(!0),children:[e.jsx(we,{size:16}),e.jsx("span",{children:"新建标签"})]}),i.map(h=>e.jsx("div",{className:"kb-tag-item",onClick:()=>{x&&!T&&(x(h.id),n())},children:T===h.id?e.jsxs("div",{className:"kb-tag-item__editing",onClick:S=>S.stopPropagation(),children:[e.jsx(je,{value:y,onChange:S=>d(S),onEnter:()=>F(h.id),size:"small",autofocus:!0}),e.jsx(xe,{shape:"circle",variant:"text",size:"small",onClick:()=>F(h.id),children:e.jsx(ce,{size:14})}),e.jsx(xe,{shape:"circle",variant:"text",size:"small",onClick:()=>b(null),children:e.jsx(me,{size:14})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"kb-tag-item__dot",style:{backgroundColor:h.color}}),e.jsx("span",{className:"kb-tag-item__name",children:h.name}),e.jsx("span",{className:"kb-tag-item__count",children:h.count?`(${h.count} 个笔记)`:"(0 个笔记)"}),e.jsxs("div",{className:"kb-tag-item__actions",children:[e.jsx(V,{content:"重命名",showArrow:!1,children:e.jsx("button",{className:"kb-tag-item__action-btn",onClick:S=>B(S,h),children:e.jsx(is,{size:12})})}),e.jsx(V,{content:"删除",showArrow:!1,children:e.jsx("button",{className:"kb-tag-item__action-btn kb-tag-item__action-btn--delete",onClick:S=>P(S,h.id),children:e.jsx(he,{size:12})})})]})]})},h.id))]}),j]})},rt=10,Ds=({currentNoteId:s,allNotes:n,noteTagsMap:i,onSelectNote:c})=>{const[k,f]=t.useState([]),[x,l]=t.useState(!1),[j,L]=t.useState(!1);t.useEffect(()=>{let b=!1;return(async()=>{try{const d=await pt().getRelatedNotes(s,rt);b||f(d)}catch{b||f([])}})(),()=>{b=!0}},[s]);const v=t.useMemo(()=>n.find(b=>b.id===s),[n,s]),N=t.useMemo(()=>{var y;const b=(y=v==null?void 0:v.metadata)==null?void 0:y.sourceUrl;return b?n.filter(d=>{var m;return d.id!==s&&((m=d==null?void 0:d.metadata)==null?void 0:m.sourceUrl)===b}):[]},[n,s,v]),M=t.useMemo(()=>new Set(N.map(b=>b.id)),[N]),T=t.useMemo(()=>{if(k.length>0){const m=new Set;return k.filter(A=>M.has(A.id)||m.has(A.id)?!1:(m.add(A.id),!0))}const b=i[s]||[],y=new Set(b.map(m=>m.id));if(!v)return[];const d=[];for(const m of n){if(m.id===s||M.has(m.id))continue;const F=(i[m.id]||[]).map(E=>E.id),P=F.filter(E=>y.has(E)).length,B=new Set([...y,...F]).size,h=B>0?P/B:0,S=As(v.title,m.title),W=h*.7+S*.3;W>.05&&d.push({id:m.id,title:m.title||"无标题",score:W})}return d.sort((m,A)=>A.score-m.score).slice(0,rt)},[k,M,n,s,i,v]);return N.length===0&&T.length===0?null:e.jsxs("div",{className:"kb-related-notes",children:[N.length>0&&e.jsxs("div",{className:"kb-related-notes__section",children:[e.jsxs("button",{className:"kb-related-notes__section-header",onClick:()=>l(!x),children:[x?e.jsx(ke,{size:12}):e.jsx(_e,{size:12}),e.jsx(ht,{size:12}),e.jsx("span",{children:"相关笔记"}),e.jsx("span",{className:"kb-related-notes__count",children:N.length})]}),!x&&e.jsx("div",{className:"kb-related-notes__list",children:N.map(b=>e.jsxs("div",{className:"kb-related-notes__item",onClick:()=>c(b.id),children:[e.jsx(ge,{size:12,className:"kb-related-notes__icon"}),e.jsx("span",{className:"kb-related-notes__name",children:b.title||"无标题"}),e.jsx(V,{content:"跳转",showArrow:!1,children:e.jsx("button",{className:"kb-related-notes__goto-btn",onClick:y=>{y.stopPropagation(),c(b.id)},children:e.jsx(Ae,{size:10})})})]},`related-${b.id}`))})]}),T.length>0&&e.jsxs("div",{className:"kb-related-notes__section",children:[e.jsxs("button",{className:"kb-related-notes__section-header",onClick:()=>L(!j),children:[j?e.jsx(ke,{size:12}):e.jsx(_e,{size:12}),e.jsx(ge,{size:12}),e.jsx("span",{children:"相似笔记"}),e.jsx("span",{className:"kb-related-notes__count",children:T.length})]}),!j&&e.jsx("div",{className:"kb-related-notes__list",children:T.map(b=>{const y="score"in b?b.score:void 0;return e.jsxs("div",{className:"kb-related-notes__item",onClick:()=>c(b.id),children:[e.jsx(ge,{size:12,className:"kb-related-notes__icon"}),e.jsx("span",{className:"kb-related-notes__name",children:b.title}),y!==void 0&&e.jsxs("span",{className:"kb-related-notes__similarity",children:[Math.round(y*100),"%"]}),e.jsx(V,{content:"跳转",showArrow:!1,children:e.jsx("button",{className:"kb-related-notes__goto-btn",onClick:d=>{d.stopPropagation(),c(b.id)},children:e.jsx(Ae,{size:10})})})]},`similar-${b.id}`)})})]})]})};function As(s,n){if(!s||!n)return 0;const i=s.toLowerCase(),c=n.toLowerCase(),k=new Set;for(let j=0;j<i.length-1;j++)k.add(i.substring(j,j+2));const f=new Set;for(let j=0;j<c.length-1;j++)f.add(c.substring(j,j+2));let x=0;for(const j of k)f.has(j)&&x++;const l=k.size+f.size;return l===0?0:2*x/l}const $s=`你是一个专业的知识提取助手,擅长从文本中识别和提取关键知识点。你的任务是分析给定的文本内容,提取出有价值的知识点,并以结构化的 Markdown 格式返回。
5
5
 
@@ -48,6 +48,6 @@ ${s}
48
48
  `).trim()}const Hs=({noteId:s,noteContent:n,noteTitle:i,onInsertToNote:c,onSaved:k})=>{const f=ls("text"),[x,l]=t.useState([]),[j,L]=t.useState(""),[v,N]=t.useState(f.modelId||ot),[M,T]=t.useState(()=>Je(f.profileId,f.modelId||ot)),[b,y]=t.useState(!1),[d,m]=t.useState(null),[A,F]=t.useState(null),P=t.useRef(null),B=t.useRef(null);t.useEffect(()=>{let _=!0;return(async()=>{l([]);try{const U=await Ks(s);_&&(U&&U.messages.length>0?l(U.messages):l([{id:"init",role:"model",content:"我已经阅读了这篇笔记。你可以让我提取摘要、关键点,或者直接与我讨论笔记内容。",type:"text",timestamp:Date.now()}]))}catch(U){console.error("Failed to load chat history",U)}})(),()=>{_=!1}},[s]),t.useEffect(()=>{x.length>0&&Os(s,x).catch(console.error)},[x,s]),t.useEffect(()=>{P.current&&(P.current.scrollTop=P.current.scrollHeight)},[x]),t.useEffect(()=>{B.current&&(B.current.style.height="auto",B.current.style.height=`${Math.min(B.current.scrollHeight,120)}px`)},[j]);const h=t.useCallback(()=>{A&&(A.abort(),F(null),y(!1),l(_=>[..._,{id:Date.now().toString(),role:"model",content:"🚫 已停止生成",type:"text",timestamp:Date.now()}]))},[A]),S=t.useCallback(async()=>{if(!j.trim()||b)return;const _={id:Date.now().toString(),role:"user",content:j,type:"text",timestamp:Date.now()};l(U=>[...U,_]),L(""),y(!0),B.current&&(B.current.style.height="auto");const K=new AbortController;F(K);try{const U=x.concat(_).map(R=>({role:R.role==="model"?"assistant":"user",content:[{type:"text",text:R.content}]}));if(U.length<=2){const R=`Context:
49
49
  ${n}
50
50
 
51
- Task: ${_.content}`,O=U.length-1;U[O].content=[{type:"text",text:R}]}const p=(Date.now()+1).toString();m(p),l(R=>[...R,{id:p,role:"model",content:"正在思考...",type:"text",timestamp:Date.now()}]),await Us(U,{model:M||v,onProgress:R=>{l(O=>O.map(J=>J.id===p?{...J,content:R}:J))},signal:K.signal})}catch(U){U.name!=="AbortError"&&l(p=>[...p,{id:Date.now().toString(),role:"model",content:`Error: ${U.message||"Something went wrong"}`,type:"text",timestamp:Date.now()}])}finally{y(!1),F(null),m(null)}},[j,b,x,n,v,M]),W=t.useCallback(async()=>{if(b)return;y(!0);const _={id:Date.now().toString(),role:"user",content:"提取知识点",type:"text",timestamp:Date.now()};l(p=>[...p,_]);const K=new AbortController;F(K);const U=(Date.now()+1).toString();l(p=>[...p,{id:U,role:"model",content:"正在分析笔记内容并提取知识点...",type:"text",timestamp:Date.now()}]);try{const p=await Ws(n,{title:i,model:M||v,signal:K.signal});l(R=>R.map(O=>O.id===U?{...O,content:"知识点提取完成:",type:"extraction-result",data:p}:O))}catch(p){p.name!=="AbortError"&&l(R=>R.map(O=>O.id===U?{...O,content:`提取失败: ${p.message}`}:O))}finally{y(!1),F(null)}},[b,n,i,v,M]),E=_=>{_.key==="Enter"&&!_.shiftKey&&(_.preventDefault(),S())},q=t.useCallback(_=>{if(!_){I.warning("没有可复制的内容");return}navigator.clipboard.writeText(_).then(()=>{I.success("复制成功")}).catch(()=>{I.error("复制失败")})},[]),H=t.useCallback(_=>_.type==="text"?_.content:_.type==="extraction-result"&&_.data?_t(_.data):"",[]),Y=t.useCallback(_=>{if(_.type==="extraction-result"&&_.data)try{const K=Vs(_.data,{format:"markdown",includeSource:!0,includeTags:!0});Ys(K.content,K.filename,K.mimeType)}catch(K){console.error("Failed to export",K),I.error("导出失败")}},[]);return e.jsxs("div",{className:"kb-extraction-chat",children:[e.jsx("div",{className:"kb-extraction-chat__header",children:e.jsxs("div",{className:"kb-extraction-chat__title",children:[e.jsx($e,{size:18}),e.jsx("span",{children:"知识提取 & 对话"})]})}),e.jsx("div",{className:"kb-extraction-chat__messages",ref:P,children:x.map(_=>e.jsxs("div",{className:`kb-message kb-message--${_.role}`,children:[e.jsx("div",{className:"kb-message__avatar",children:_.role==="user"?e.jsx(De,{}):e.jsx(ds,{})}),e.jsxs("div",{className:"kb-message__body",children:[e.jsx("div",{className:"kb-message__content",children:_.role==="model"?e.jsx("div",{className:"kb-message__content-scroll",children:_.type==="text"?_.id===d&&(_.content==="正在思考..."||_.content==="正在分析笔记内容并提取知识点...")?e.jsxs("div",{className:"kb-message__thinking","aria-label":"思考中",children:[e.jsx("span",{className:"kb-message__thinking-text",children:_.content.replace(/\.+$/,"")}),e.jsxs("span",{className:"kb-message__thinking-dots",children:[e.jsx("span",{children:"."}),e.jsx("span",{children:"."}),e.jsx("span",{children:"."})]})]}):_.content?e.jsx("div",{className:"kb-message__markdown-wrap",children:e.jsx(Pe,{markdown:_.content,readOnly:!0,showModeSwitch:!1,initialMode:"wysiwyg",className:"kb-extraction-markdown"})}):null:e.jsx(it,{result:_.data})}):_.type==="text"?e.jsx("div",{className:"kb-message__text",children:_.content}):e.jsx(it,{result:_.data})}),_.role==="model"&&e.jsxs("div",{className:"kb-message__actions",children:[e.jsx(V,{content:"复制",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>q(H(_)),children:e.jsx(Te,{size:14})})}),e.jsx(V,{content:"插入到笔记",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>{const K=H(_);K&&(c==null||c(K))},children:e.jsx(us,{size:14})})}),_.type==="extraction-result"&&e.jsx(V,{content:"导出 Markdown",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>Y(_),children:e.jsx(Le,{size:14})})})]})]})]},_.id))}),e.jsxs("div",{className:"kb-extraction-chat__input-area",children:[e.jsx("div",{className:"kb-extraction-chat__input-wrapper",children:e.jsx("textarea",{ref:B,className:"kb-extraction-chat__textarea",value:j,onChange:_=>L(_.target.value),onKeyDown:E,placeholder:"输入问题,与 AI 讨论笔记内容...",disabled:b,rows:1})}),e.jsxs("div",{className:"kb-extraction-chat__input-actions",children:[e.jsx("div",{className:"kb-extraction-chat__model-selector",children:e.jsx(Ns,{value:v,valueRef:M,onChange:(_,K)=>{N(_),T(K||Je(null,_))},variant:"capsule"})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(V,{content:"一键提取知识点",showArrow:!1,children:e.jsx("span",{children:e.jsx("button",{className:"kb-extraction-chat__icon-btn",onClick:W,disabled:b,children:e.jsx($e,{size:16})})})}),e.jsx("button",{className:`kb-extraction-chat__send-btn ${j.trim()||b?"kb-extraction-chat__send-btn--active":""}`,onClick:b?h:S,disabled:!j.trim()&&!b,title:b?"停止生成":"发送",children:b?e.jsx(ms,{size:18}):e.jsx(hs,{size:18})})]})]})]})]})},it=({result:s})=>{const n=xs.useMemo(()=>_t(s),[s]);return e.jsx("div",{className:"kb-extraction-result-view",children:e.jsx(Pe,{markdown:n,readOnly:!0,showModeSwitch:!1,initialMode:"wysiwyg",className:"kb-extraction-markdown"})})},ct=[{label:"更新时间",value:"updatedAt"},{label:"创建时间",value:"createdAt"},{label:"标题",value:"title"}],qs=({value:s,onChange:n})=>{var f;const i=((f=ct.find(x=>x.value===s.field))==null?void 0:f.label)||"排序",c=x=>{const l=x.value;["asc","desc"].includes(l)?n({...s,order:l}):l===s.field?n({...s,order:s.order==="asc"?"desc":"asc"}):n({...s,field:l,order:l==="title"?"asc":"desc"})},k=[{content:"排序字段",disabled:!0,className:"kb-sort-dropdown__header"},...ct.map(x=>({content:x.label,value:x.value,prefixIcon:s.field===x.value?e.jsx(ce,{size:14}):e.jsx("div",{style:{width:14}})})),{divider:!0},{content:"排序方式",disabled:!0,className:"kb-sort-dropdown__header"},{content:"升序",value:"asc",prefixIcon:s.order==="asc"?e.jsx(ce,{size:14}):e.jsx("div",{style:{width:14}}),suffixIcon:e.jsx(et,{size:14})},{content:"降序",value:"desc",prefixIcon:s.order==="desc"?e.jsx(ce,{size:14}):e.jsx("div",{style:{width:14}}),suffixIcon:e.jsx(tt,{size:14})}];return e.jsx(ft,{options:k,onClick:c,trigger:"click",minColumnWidth:120,children:e.jsxs(xe,{variant:"outline",size:"small",className:"kb-sort-trigger",children:[s.order==="asc"?e.jsx(et,{size:14,style:{marginRight:4}}):e.jsx(tt,{size:14,style:{marginRight:4}}),i]})})},xn=({initialNoteId:s})=>{var qe;const[n,i]=t.useState([]),[c,k]=t.useState([]),[f,x]=t.useState([]),[l,j]=t.useState(null),[L,v]=t.useState([]),[N,M]=t.useState({}),[T,b]=t.useState(null),[y,d]=t.useState(new Set),[m,A]=t.useState(null),[F,P]=t.useState(""),[B,h]=t.useState(C.loadSortPreference?C.loadSortPreference():{field:"updatedAt",order:"desc"}),[S,W]=t.useState([]),[E,q]=t.useState(!1),[H,Y]=t.useState(!1),[_,K]=t.useState(!1),[U,p]=t.useState(null),R=t.useRef(null),O=t.useRef(0),J=t.useRef(null),{confirm:te,confirmDialog:fe}=mt(),[z,Q]=t.useState(!1),[Z,G]=t.useState("related"),[ve,Ue]=t.useState(280),[Ne,We]=t.useState(300),le=t.useRef(!1),de=t.useRef(!1),ye=t.useRef(null);t.useEffect(()=>{const a=localStorage.getItem("kb-sidebar-width");if(a){const r=parseInt(a,10);!isNaN(r)&&r>100&&r<800&&Ue(r)}const o=localStorage.getItem("kb-right-sidebar-width");if(o){const r=parseInt(o,10);!isNaN(r)&&r>100&&r<800&&We(r)}},[]),t.useEffect(()=>{const a=r=>{if(!ye.current)return;const g=ye.current.getBoundingClientRect();if(le.current){r.preventDefault();const u=Math.max(200,Math.min(600,r.clientX-g.left));Ue(u)}else if(de.current){r.preventDefault();const u=Math.max(200,Math.min(600,g.right-r.clientX));We(u)}},o=()=>{le.current&&(le.current=!1,localStorage.setItem("kb-sidebar-width",ve.toString()),document.body.style.cursor=""),de.current&&(de.current=!1,localStorage.setItem("kb-right-sidebar-width",Ne.toString()),document.body.style.cursor="")};return le.current||de.current?(document.addEventListener("mousemove",a),document.addEventListener("mouseup",o)):document.addEventListener("mousemove",a),document.addEventListener("mousemove",a),document.addEventListener("mouseup",o),()=>{document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",o)}},[ve,Ne]);const kt=a=>{a.preventDefault(),le.current=!0,document.body.style.cursor="col-resize"},wt=a=>{a.preventDefault(),de.current=!0,document.body.style.cursor="col-resize"},[Fe,jt]=t.useState(null),Be=t.useRef(!1),Ke=t.useRef(!1);t.useEffect(()=>{if(Be.current)return;Be.current=!0,(async()=>{await C.initialize(),await X();try{const r=await C.getStorageUsage();jt(r)}catch{}if(s){ee(s);return}const o=window.__kbPendingNavigation;if(o){window.__kbPendingNavigation=null;const{directoryName:r,autoCreateNote:g}=o;if(r){const w=(await C.getAllDirectories()).find(D=>D.name===r);if(w&&(b(w.id),d(D=>{const $=new Set(D);return $.add(w.id),$}),g)){const D=r==="Skill"?"新Skill":"新笔记",$=await C.createNote(D,w.id);await X(),d(ae=>{const ue=new Set(ae);return ue.add(w.id),ue}),A($.id);const se=await C.getNoteById($.id);j(se),v([])}}}})()},[]);const X=t.useCallback(async()=>{const[a,o,r]=await Promise.all([C.getAllDirectories(),C.getAllNoteMetas(),C.getAllTags()]),g=Array.from(new Map(a.map(D=>[D.id,D])).values());i(g);const u=Array.from(new Map(o.map(D=>[D.id,D])).values());k(u);const w=Array.from(new Map(r.map(D=>[D.id,D])).values());x(w),!T&&!m&&g.length>0&&(b(g[0].id),d(new Set([g[0].id]))),await vt(u)},[T,m]),vt=t.useCallback(async a=>{try{const[o,r]=await Promise.all([C.getAllTags(),C.getAllNoteTags()]),g=new Map(o.map(w=>[w.id,w])),u={};for(const w of a)u[w.id]=[];for(const w of r)if(u[w.noteId]&&g.has(w.tagId)){const D=g.get(w.tagId);D&&(u[w.noteId].some($=>$.id===D.id)||u[w.noteId].push(D))}for(const w in u)u[w].sort((D,$)=>D.name.localeCompare($.name));M(u)}catch(o){console.error("Failed to refresh note tags map:",o)}},[]);t.useEffect(()=>{if(!F.trim()){p(null);return}return R.current&&clearTimeout(R.current),R.current=setTimeout(async()=>{try{const o=await pt().search(F,{limit:50,filter:T?{directoryId:T}:{}});p(o)}catch{p(null)}},300),()=>{R.current&&clearTimeout(R.current)}},[F,T]);const ne=t.useMemo(()=>{if(U&&F.trim()){const o=new Set(U.map(u=>u.id)),r=new Map(U.map((u,w)=>[u.id,w]));let g=c.filter(u=>o.has(u.id));if(S.length>0){const u=new Set(S);g=g.filter(w=>(N[w.id]||[]).some($=>u.has($.id)))}return g.sort((u,w)=>(r.get(u.id)??0)-(r.get(w.id)??0))}let a=c;if(S.length>0){const o=new Set(S);a=a.filter(r=>(N[r.id]||[]).some(u=>o.has(u.id)))}return C.sortNoteMetas(a,B)},[c,T,F,S,B,N,U]),Nt=t.useMemo(()=>{const a={},o=new Set;for(const r of ne)o.has(r.id)||(o.add(r.id),a[r.directoryId]=(a[r.directoryId]||0)+1);return a},[ne]),yt=t.useMemo(()=>{var o;const a={};for(const r of ne){const g=a[o=r.directoryId]??(a[o]=[]);g.some(u=>u.id===r.id)||g.push(r)}return a},[ne]),Ce=t.useCallback(async a=>{await C.createDirectory(a),await X()},[X]),Ct=t.useCallback(async(a,o)=>{await C.updateDirectory(a,{name:o}),await X()},[X]),St=t.useCallback(async a=>{var g;const o=n.find(u=>u.id===a);if(!(!o||!await te({title:"确认删除目录",description:`确定要删除目录 "${o.name}" 及其下的所有笔记吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0})))try{await C.deleteDirectory(a),T===a&&(b(((g=n[0])==null?void 0:g.id)||null),A(null),j(null)),await X(),I.success("目录已删除")}catch(u){I.error(`删除失败: ${u.message}`)}},[X,T,n]),Et=t.useCallback(async a=>{try{await C.duplicateDirectory(a),await X(),I.success("目录复制成功")}catch(o){I.error(`复制目录失败: ${o.message}`)}},[X]),Rt=t.useCallback(a=>{d(o=>{const r=new Set(o);return r.has(a)?r.delete(a):r.add(a),r})},[]),ee=t.useCallback(async a=>{const o=++O.current;if(A(a),b(null),v(N[a]||[]),a.startsWith(ie)){const g=a.slice(ie.length),u=Ie.find(w=>w.id===g);if(u){const w=["image","inspiration","grid_image"],D=["ppt"],$=u.mcpTool&&w.some(ae=>u.mcpTool.includes(ae))?"image":u.mcpTool&&D.some(ae=>u.mcpTool.includes(ae))?"ppt":void 0,se={id:a,title:u.name,content:u.description||"",directoryId:"",createdAt:0,updatedAt:0,metadata:{...$?{outputType:$}:{}}};o===O.current&&(j(se),v([]))}return}if(a.startsWith(oe)){const g=a.slice(oe.length),u=js(g);if(u){const w={id:a,title:u.name,content:u.content||u.description||"",directoryId:"",createdAt:0,updatedAt:0,metadata:{...u.outputType?{outputType:u.outputType}:{},...u.category?{category:u.category}:{}}};o===O.current&&(j(w),v([]))}return}const r=await C.getNoteById(a);if(o===O.current&&(j(r),r)){const g=await C.getTagsForNote(r.id);if(o!==O.current)return;v(g),d(u=>{const w=new Set(u);return w.add(r.directoryId),w})}},[n,N]),Se=t.useCallback(async a=>{const o=new Set(c.filter($=>$.directoryId===a).map($=>$.title)),r=n.find($=>$.id===a),g=(r==null?void 0:r.name)==="Skill"?"新Skill":"新笔记";let u=g,w=1;for(;o.has(u);)u=`${g} ${w}`,w++;const D=await C.createNote(u,a);await X(),d($=>{const se=new Set($);return se.add(a),se}),ee(D.id)},[X,ee,c,n]),Ee=t.useCallback(async(a,o)=>{await C.updateNote(a,o),k(r=>r.map(g=>g.id===a?{...g,...o,updatedAt:Date.now()}:g)),(l==null?void 0:l.id)===a&&j(r=>r&&{...r,...o,updatedAt:Date.now()});try{const r=window.__drawnixBoard;if(r&&r.children){const{Transforms:g}=await Me(async()=>{const{Transforms:u}=await import("./tool-windows-hjm6YiPY.js").then(w=>w.oE);return{Transforms:u}},__vite__mapDeps([0]),import.meta.url);r.children.forEach((u,w)=>{if(u.noteId===a){const D={};o.title!==void 0&&(D.title=o.title),o.content!==void 0&&(D.body=o.content),Object.keys(D).length>0&&g.setNode(r,D,[w])}})}}catch(r){console.warn("[KB] Failed to sync note update to canvas card:",r)}},[l]),Mt=t.useCallback(async a=>{if(!l)return;const o=l.content?`
51
+ Task: ${_.content}`,O=U.length-1;U[O].content=[{type:"text",text:R}]}const p=(Date.now()+1).toString();m(p),l(R=>[...R,{id:p,role:"model",content:"正在思考...",type:"text",timestamp:Date.now()}]),await Us(U,{model:M||v,onProgress:R=>{l(O=>O.map(J=>J.id===p?{...J,content:R}:J))},signal:K.signal})}catch(U){U.name!=="AbortError"&&l(p=>[...p,{id:Date.now().toString(),role:"model",content:`Error: ${U.message||"Something went wrong"}`,type:"text",timestamp:Date.now()}])}finally{y(!1),F(null),m(null)}},[j,b,x,n,v,M]),W=t.useCallback(async()=>{if(b)return;y(!0);const _={id:Date.now().toString(),role:"user",content:"提取知识点",type:"text",timestamp:Date.now()};l(p=>[...p,_]);const K=new AbortController;F(K);const U=(Date.now()+1).toString();l(p=>[...p,{id:U,role:"model",content:"正在分析笔记内容并提取知识点...",type:"text",timestamp:Date.now()}]);try{const p=await Ws(n,{title:i,model:M||v,signal:K.signal});l(R=>R.map(O=>O.id===U?{...O,content:"知识点提取完成:",type:"extraction-result",data:p}:O))}catch(p){p.name!=="AbortError"&&l(R=>R.map(O=>O.id===U?{...O,content:`提取失败: ${p.message}`}:O))}finally{y(!1),F(null)}},[b,n,i,v,M]),E=_=>{_.key==="Enter"&&!_.shiftKey&&(_.preventDefault(),S())},q=t.useCallback(_=>{if(!_){I.warning("没有可复制的内容");return}navigator.clipboard.writeText(_).then(()=>{I.success("复制成功")}).catch(()=>{I.error("复制失败")})},[]),H=t.useCallback(_=>_.type==="text"?_.content:_.type==="extraction-result"&&_.data?_t(_.data):"",[]),Y=t.useCallback(_=>{if(_.type==="extraction-result"&&_.data)try{const K=Vs(_.data,{format:"markdown",includeSource:!0,includeTags:!0});Ys(K.content,K.filename,K.mimeType)}catch(K){console.error("Failed to export",K),I.error("导出失败")}},[]);return e.jsxs("div",{className:"kb-extraction-chat",children:[e.jsx("div",{className:"kb-extraction-chat__header",children:e.jsxs("div",{className:"kb-extraction-chat__title",children:[e.jsx($e,{size:18}),e.jsx("span",{children:"知识提取 & 对话"})]})}),e.jsx("div",{className:"kb-extraction-chat__messages",ref:P,children:x.map(_=>e.jsxs("div",{className:`kb-message kb-message--${_.role}`,children:[e.jsx("div",{className:"kb-message__avatar",children:_.role==="user"?e.jsx(De,{}):e.jsx(ds,{})}),e.jsxs("div",{className:"kb-message__body",children:[e.jsx("div",{className:"kb-message__content",children:_.role==="model"?e.jsx("div",{className:"kb-message__content-scroll",children:_.type==="text"?_.id===d&&(_.content==="正在思考..."||_.content==="正在分析笔记内容并提取知识点...")?e.jsxs("div",{className:"kb-message__thinking","aria-label":"思考中",children:[e.jsx("span",{className:"kb-message__thinking-text",children:_.content.replace(/\.+$/,"")}),e.jsxs("span",{className:"kb-message__thinking-dots",children:[e.jsx("span",{children:"."}),e.jsx("span",{children:"."}),e.jsx("span",{children:"."})]})]}):_.content?e.jsx("div",{className:"kb-message__markdown-wrap",children:e.jsx(Pe,{markdown:_.content,readOnly:!0,showModeSwitch:!1,initialMode:"wysiwyg",className:"kb-extraction-markdown"})}):null:e.jsx(it,{result:_.data})}):_.type==="text"?e.jsx("div",{className:"kb-message__text",children:_.content}):e.jsx(it,{result:_.data})}),_.role==="model"&&e.jsxs("div",{className:"kb-message__actions",children:[e.jsx(V,{content:"复制",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>q(H(_)),children:e.jsx(Te,{size:14})})}),e.jsx(V,{content:"插入到笔记",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>{const K=H(_);K&&(c==null||c(K))},children:e.jsx(us,{size:14})})}),_.type==="extraction-result"&&e.jsx(V,{content:"导出 Markdown",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>Y(_),children:e.jsx(Le,{size:14})})})]})]})]},_.id))}),e.jsxs("div",{className:"kb-extraction-chat__input-area",children:[e.jsx("div",{className:"kb-extraction-chat__input-wrapper",children:e.jsx("textarea",{ref:B,className:"kb-extraction-chat__textarea",value:j,onChange:_=>L(_.target.value),onKeyDown:E,placeholder:"输入问题,与 AI 讨论笔记内容...",disabled:b,rows:1})}),e.jsxs("div",{className:"kb-extraction-chat__input-actions",children:[e.jsx("div",{className:"kb-extraction-chat__model-selector",children:e.jsx(Ns,{value:v,valueRef:M,onChange:(_,K)=>{N(_),T(K||Je(null,_))},variant:"capsule"})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(V,{content:"一键提取知识点",showArrow:!1,children:e.jsx("span",{children:e.jsx("button",{className:"kb-extraction-chat__icon-btn",onClick:W,disabled:b,children:e.jsx($e,{size:16})})})}),e.jsx("button",{className:`kb-extraction-chat__send-btn ${j.trim()||b?"kb-extraction-chat__send-btn--active":""}`,onClick:b?h:S,disabled:!j.trim()&&!b,title:b?"停止生成":"发送",children:b?e.jsx(ms,{size:18}):e.jsx(hs,{size:18})})]})]})]})]})},it=({result:s})=>{const n=xs.useMemo(()=>_t(s),[s]);return e.jsx("div",{className:"kb-extraction-result-view",children:e.jsx(Pe,{markdown:n,readOnly:!0,showModeSwitch:!1,initialMode:"wysiwyg",className:"kb-extraction-markdown"})})},ct=[{label:"更新时间",value:"updatedAt"},{label:"创建时间",value:"createdAt"},{label:"标题",value:"title"}],qs=({value:s,onChange:n})=>{var f;const i=((f=ct.find(x=>x.value===s.field))==null?void 0:f.label)||"排序",c=x=>{const l=x.value;["asc","desc"].includes(l)?n({...s,order:l}):l===s.field?n({...s,order:s.order==="asc"?"desc":"asc"}):n({...s,field:l,order:l==="title"?"asc":"desc"})},k=[{content:"排序字段",disabled:!0,className:"kb-sort-dropdown__header"},...ct.map(x=>({content:x.label,value:x.value,prefixIcon:s.field===x.value?e.jsx(ce,{size:14}):e.jsx("div",{style:{width:14}})})),{divider:!0},{content:"排序方式",disabled:!0,className:"kb-sort-dropdown__header"},{content:"升序",value:"asc",prefixIcon:s.order==="asc"?e.jsx(ce,{size:14}):e.jsx("div",{style:{width:14}}),suffixIcon:e.jsx(et,{size:14})},{content:"降序",value:"desc",prefixIcon:s.order==="desc"?e.jsx(ce,{size:14}):e.jsx("div",{style:{width:14}}),suffixIcon:e.jsx(tt,{size:14})}];return e.jsx(ft,{options:k,onClick:c,trigger:"click",minColumnWidth:120,children:e.jsxs(xe,{variant:"outline",size:"small",className:"kb-sort-trigger",children:[s.order==="asc"?e.jsx(et,{size:14,style:{marginRight:4}}):e.jsx(tt,{size:14,style:{marginRight:4}}),i]})})},xn=({initialNoteId:s})=>{var qe;const[n,i]=t.useState([]),[c,k]=t.useState([]),[f,x]=t.useState([]),[l,j]=t.useState(null),[L,v]=t.useState([]),[N,M]=t.useState({}),[T,b]=t.useState(null),[y,d]=t.useState(new Set),[m,A]=t.useState(null),[F,P]=t.useState(""),[B,h]=t.useState(C.loadSortPreference?C.loadSortPreference():{field:"updatedAt",order:"desc"}),[S,W]=t.useState([]),[E,q]=t.useState(!1),[H,Y]=t.useState(!1),[_,K]=t.useState(!1),[U,p]=t.useState(null),R=t.useRef(null),O=t.useRef(0),J=t.useRef(null),{confirm:te,confirmDialog:fe}=mt(),[z,Q]=t.useState(!1),[Z,G]=t.useState("related"),[ve,Ue]=t.useState(280),[Ne,We]=t.useState(300),le=t.useRef(!1),de=t.useRef(!1),ye=t.useRef(null);t.useEffect(()=>{const a=localStorage.getItem("kb-sidebar-width");if(a){const r=parseInt(a,10);!isNaN(r)&&r>100&&r<800&&Ue(r)}const o=localStorage.getItem("kb-right-sidebar-width");if(o){const r=parseInt(o,10);!isNaN(r)&&r>100&&r<800&&We(r)}},[]),t.useEffect(()=>{const a=r=>{if(!ye.current)return;const g=ye.current.getBoundingClientRect();if(le.current){r.preventDefault();const u=Math.max(200,Math.min(600,r.clientX-g.left));Ue(u)}else if(de.current){r.preventDefault();const u=Math.max(200,Math.min(600,g.right-r.clientX));We(u)}},o=()=>{le.current&&(le.current=!1,localStorage.setItem("kb-sidebar-width",ve.toString()),document.body.style.cursor=""),de.current&&(de.current=!1,localStorage.setItem("kb-right-sidebar-width",Ne.toString()),document.body.style.cursor="")};return le.current||de.current?(document.addEventListener("mousemove",a),document.addEventListener("mouseup",o)):document.addEventListener("mousemove",a),document.addEventListener("mousemove",a),document.addEventListener("mouseup",o),()=>{document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",o)}},[ve,Ne]);const kt=a=>{a.preventDefault(),le.current=!0,document.body.style.cursor="col-resize"},wt=a=>{a.preventDefault(),de.current=!0,document.body.style.cursor="col-resize"},[Fe,jt]=t.useState(null),Be=t.useRef(!1),Ke=t.useRef(!1);t.useEffect(()=>{if(Be.current)return;Be.current=!0,(async()=>{await C.initialize(),await X();try{const r=await C.getStorageUsage();jt(r)}catch{}if(s){ee(s);return}const o=window.__kbPendingNavigation;if(o){window.__kbPendingNavigation=null;const{directoryName:r,autoCreateNote:g}=o;if(r){const w=(await C.getAllDirectories()).find(D=>D.name===r);if(w&&(b(w.id),d(D=>{const $=new Set(D);return $.add(w.id),$}),g)){const D=r==="Skill"?"新Skill":"新笔记",$=await C.createNote(D,w.id);await X(),d(ae=>{const ue=new Set(ae);return ue.add(w.id),ue}),A($.id);const se=await C.getNoteById($.id);j(se),v([])}}}})()},[]);const X=t.useCallback(async()=>{const[a,o,r]=await Promise.all([C.getAllDirectories(),C.getAllNoteMetas(),C.getAllTags()]),g=Array.from(new Map(a.map(D=>[D.id,D])).values());i(g);const u=Array.from(new Map(o.map(D=>[D.id,D])).values());k(u);const w=Array.from(new Map(r.map(D=>[D.id,D])).values());x(w),!T&&!m&&g.length>0&&(b(g[0].id),d(new Set([g[0].id]))),await vt(u)},[T,m]),vt=t.useCallback(async a=>{try{const[o,r]=await Promise.all([C.getAllTags(),C.getAllNoteTags()]),g=new Map(o.map(w=>[w.id,w])),u={};for(const w of a)u[w.id]=[];for(const w of r)if(u[w.noteId]&&g.has(w.tagId)){const D=g.get(w.tagId);D&&(u[w.noteId].some($=>$.id===D.id)||u[w.noteId].push(D))}for(const w in u)u[w].sort((D,$)=>D.name.localeCompare($.name));M(u)}catch(o){console.error("Failed to refresh note tags map:",o)}},[]);t.useEffect(()=>{if(!F.trim()){p(null);return}return R.current&&clearTimeout(R.current),R.current=setTimeout(async()=>{try{const o=await pt().search(F,{limit:50,filter:T?{directoryId:T}:{}});p(o)}catch{p(null)}},300),()=>{R.current&&clearTimeout(R.current)}},[F,T]);const ne=t.useMemo(()=>{if(U&&F.trim()){const o=new Set(U.map(u=>u.id)),r=new Map(U.map((u,w)=>[u.id,w]));let g=c.filter(u=>o.has(u.id));if(S.length>0){const u=new Set(S);g=g.filter(w=>(N[w.id]||[]).some($=>u.has($.id)))}return g.sort((u,w)=>(r.get(u.id)??0)-(r.get(w.id)??0))}let a=c;if(S.length>0){const o=new Set(S);a=a.filter(r=>(N[r.id]||[]).some(u=>o.has(u.id)))}return C.sortNoteMetas(a,B)},[c,T,F,S,B,N,U]),Nt=t.useMemo(()=>{const a={},o=new Set;for(const r of ne)o.has(r.id)||(o.add(r.id),a[r.directoryId]=(a[r.directoryId]||0)+1);return a},[ne]),yt=t.useMemo(()=>{var o;const a={};for(const r of ne){const g=a[o=r.directoryId]??(a[o]=[]);g.some(u=>u.id===r.id)||g.push(r)}return a},[ne]),Ce=t.useCallback(async a=>{await C.createDirectory(a),await X()},[X]),Ct=t.useCallback(async(a,o)=>{await C.updateDirectory(a,{name:o}),await X()},[X]),St=t.useCallback(async a=>{var g;const o=n.find(u=>u.id===a);if(!(!o||!await te({title:"确认删除目录",description:`确定要删除目录 "${o.name}" 及其下的所有笔记吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0})))try{await C.deleteDirectory(a),T===a&&(b(((g=n[0])==null?void 0:g.id)||null),A(null),j(null)),await X(),I.success("目录已删除")}catch(u){I.error(`删除失败: ${u.message}`)}},[X,T,n]),Et=t.useCallback(async a=>{try{await C.duplicateDirectory(a),await X(),I.success("目录复制成功")}catch(o){I.error(`复制目录失败: ${o.message}`)}},[X]),Rt=t.useCallback(a=>{d(o=>{const r=new Set(o);return r.has(a)?r.delete(a):r.add(a),r})},[]),ee=t.useCallback(async a=>{const o=++O.current;if(A(a),b(null),v(N[a]||[]),a.startsWith(ie)){const g=a.slice(ie.length),u=Ie.find(w=>w.id===g);if(u){const w=["image","inspiration","grid_image"],D=["ppt"],$=u.mcpTool&&w.some(ae=>u.mcpTool.includes(ae))?"image":u.mcpTool&&D.some(ae=>u.mcpTool.includes(ae))?"ppt":void 0,se={id:a,title:u.name,content:u.description||"",directoryId:"",createdAt:0,updatedAt:0,metadata:{...$?{outputType:$}:{}}};o===O.current&&(j(se),v([]))}return}if(a.startsWith(oe)){const g=a.slice(oe.length),u=js(g);if(u){const w={id:a,title:u.name,content:u.content||u.description||"",directoryId:"",createdAt:0,updatedAt:0,metadata:{...u.outputType?{outputType:u.outputType}:{},...u.category?{category:u.category}:{}}};o===O.current&&(j(w),v([]))}return}const r=await C.getNoteById(a);if(o===O.current&&(j(r),r)){const g=await C.getTagsForNote(r.id);if(o!==O.current)return;v(g),d(u=>{const w=new Set(u);return w.add(r.directoryId),w})}},[n,N]),Se=t.useCallback(async a=>{const o=new Set(c.filter($=>$.directoryId===a).map($=>$.title)),r=n.find($=>$.id===a),g=(r==null?void 0:r.name)==="Skill"?"新Skill":"新笔记";let u=g,w=1;for(;o.has(u);)u=`${g} ${w}`,w++;const D=await C.createNote(u,a);await X(),d($=>{const se=new Set($);return se.add(a),se}),ee(D.id)},[X,ee,c,n]),Ee=t.useCallback(async(a,o)=>{await C.updateNote(a,o),k(r=>r.map(g=>g.id===a?{...g,...o,updatedAt:Date.now()}:g)),(l==null?void 0:l.id)===a&&j(r=>r&&{...r,...o,updatedAt:Date.now()});try{const r=window.__drawnixBoard;if(r&&r.children){const{Transforms:g}=await Me(async()=>{const{Transforms:u}=await import("./tool-windows-C4D0lII2.js").then(w=>w.oE);return{Transforms:u}},__vite__mapDeps([0]),import.meta.url);r.children.forEach((u,w)=>{if(u.noteId===a){const D={};o.title!==void 0&&(D.title=o.title),o.content!==void 0&&(D.body=o.content),Object.keys(D).length>0&&g.setNode(r,D,[w])}})}}catch(r){console.warn("[KB] Failed to sync note update to canvas card:",r)}},[l]),Mt=t.useCallback(async a=>{if(!l)return;const o=l.content?`
52
52
 
53
- `:"",r=(l.content||"")+o+a;await Ee(l.id,{content:r}),I.success("已插入到笔记末尾")},[l,Ee]),Tt=t.useCallback(async a=>{var r,g;const o=window.__drawnixBoard;if(!o){I.warning("请先打开画布");return}try{if(o.children.find(re=>re.noteId===a.id)&&!await te({title:"重复插入提醒",description:"画布中已存在关联该笔记的卡片,是否再次插入?",confirmText:"继续插入",cancelText:"取消"}))return;const w=await C.getNoteById(a.id);if(!w){I.error("获取笔记内容失败");return}const{getViewportOrigination:D}=await Me(async()=>{const{getViewportOrigination:re}=await import("./tool-windows-hjm6YiPY.js").then(Re=>Re.oE);return{getViewportOrigination:re}},__vite__mapDeps([0]),import.meta.url),$=D(o),se=((r=o.host)==null?void 0:r.clientWidth)||800,ae=((g=o.host)==null?void 0:g.clientHeight)||600,ue=Math.round(window.innerWidth*.5),Qe=180,Ze=(($==null?void 0:$[0])??0)+se/2-ue/2,Ge=(($==null?void 0:$[1])??0)+ae/2-Qe/2,{Transforms:Bt}=await Me(async()=>{const{Transforms:re}=await import("./tool-windows-hjm6YiPY.js").then(Re=>Re.oE);return{Transforms:re}},__vite__mapDeps([0]),import.meta.url),Kt={type:"card",id:`card-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,title:w.title||"无标题",body:w.content||"",noteId:w.id,fillColor:"#FA8C16",points:[[Ze,Ge],[Ze+ue,Ge+Qe]]};Bt.insertNode(o,Kt,[o.children.length]),I.success("已插入到画布")}catch(u){console.error("[KB] Failed to insert note to canvas:",u),I.error(`插入失败: ${u.message}`)}},[]),zt=t.useCallback(async a=>{try{await C.duplicateNote(a),await X(),I.success("笔记复制成功")}catch(o){I.error(`复制笔记失败: ${o.message}`)}},[X]),Dt=t.useCallback(async a=>{if(a.startsWith(ie)){I.warning("系统内置 Skill,不可删除");return}if(a.startsWith(oe)){I.warning("外部 Skill,不可在此删除(请在设置中管理外部 Skill 包)");return}const o=c.find(g=>g.id===a);if(!(!o||!await te({title:"确认删除笔记",description:`确定要删除笔记 "${o.title||"无标题"}" 吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0})))try{await C.deleteNote(a),m===a&&(A(null),j(null),v([])),await X(),I.success("笔记已删除")}catch(g){I.error(`删除失败: ${g.message}`)}},[m,X,c]);t.useEffect(()=>{!Ke.current&&ne.length>0&&(ee(ne[0].id),Ke.current=!0)},[ne,ee]),t.useEffect(()=>{const a=o=>{const{noteId:r}=o.detail;r&&ee(r)};return window.addEventListener("kb:open-note",a),()=>window.removeEventListener("kb:open-note",a)},[ee]),t.useEffect(()=>{const a=async o=>{const{directoryName:r,autoCreateNote:g}=o.detail;if(!r)return;window.__kbPendingNavigation&&(window.__kbPendingNavigation=null);const w=(await C.getAllDirectories()).find(D=>D.name===r);w&&(b(w.id),d(D=>{const $=new Set(D);return $.add(w.id),$}),g&&await Se(w.id))};return window.addEventListener("kb:navigate",a),()=>window.removeEventListener("kb:navigate",a)},[Se]);const At=t.useCallback(async(a,o)=>{await C.setNoteTags(a,o);const r=await C.getTagsForNote(a);v(r),M(u=>({...u,[a]:r}));const g=await C.getAllTags();x(g)},[]),Oe=t.useCallback(async a=>{const o=await C.createTag(a),r=await C.getAllTags();return x(r),o},[]),$t=t.useCallback(async(a,o)=>{await C.updateTag(a,{name:o});const r=await C.getAllTags();x(r)},[]),It=t.useCallback(async a=>{await C.deleteTag(a);const o=await C.getAllTags();if(x(o),l){const r=await C.getTagsForNote(l.id);v(r),M(g=>({...g,[l.id]:r}))}},[l]),Lt=t.useCallback(a=>{h(a),C.saveSortPreference&&C.saveSortPreference(a)},[]);t.useEffect(()=>{if(!H)return;const a=o=>{J.current&&!J.current.contains(o.target)&&Y(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[H]);const pe=t.useRef(null),Xe=t.useCallback(()=>{var a;(a=pe.current)==null||a.click()},[]),Pt=t.useCallback(async a=>{const o=a.target.files;if(!(!o||!T)){for(const r of Array.from(o)){if(!r.name.endsWith(".md")&&!r.name.endsWith(".markdown"))continue;const g=await r.text();await C.importNoteFromMarkdown(g,T,r.name)}await X(),pe.current&&(pe.current.value="")}},[T,X]),Ve=t.useCallback(async()=>{try{const a=await C.exportAsZip(),o=URL.createObjectURL(a),r=document.createElement("a");r.href=o,r.download=`knowledge-base-${new Date().toISOString().slice(0,10)}.zip`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(o)}catch(a){console.error("Export failed:",a),I.error("导出失败")}},[]),be=t.useRef(null),Ye=t.useCallback(()=>{var a;(a=be.current)==null||a.click()},[]),Ut=t.useCallback(async a=>{var r;const o=(r=a.target.files)==null?void 0:r[0];if(o){try{if(o.name.toLowerCase().endsWith(".zip")){const g=await C.importFromZip(o);g.noteCount===0&&g.dirCount===0?I.warning("导入完成:没有新增内容(可能已存在重复内容)"):I.success(`导入完成:${g.dirCount} 个新目录、${g.noteCount} 篇笔记`)}else{const g=await o.text(),u=JSON.parse(g);if(u.version!==1&&u.version!==2){I.error("不支持的导入格式");return}const w=await C.importAllData(u);I.success(`导入完成:${w.dirCount} 个目录、${w.noteCount} 篇笔记、${w.tagCount} 个标签`)}await X()}catch(g){console.error(g),I.error("导入失败,请确认文件格式正确")}be.current&&(be.current.value="")}},[X]),He=t.useCallback(()=>{const a=window.prompt("请输入目录名称","新建目录");a&&Ce(a)},[Ce]),Wt=t.useCallback(a=>{switch(a.value){case"create-dir":He();break;case"manage-tags":q(!0);break;case"import-md":Xe();break;case"import-zip":Ye();break;case"export-zip":Ve();break}},[He,Xe,Ye,Ve]),Ft=t.useMemo(()=>[{content:"新建目录",value:"create-dir",prefixIcon:e.jsx(fs,{size:14})},{content:"管理标签",value:"manage-tags",prefixIcon:e.jsx(ps,{size:14})},{content:"导入 Markdown",value:"import-md",prefixIcon:e.jsx(st,{size:14})},{content:"导入 ZIP",value:"import-zip",prefixIcon:e.jsx(st,{size:14})},{content:"导出 ZIP",value:"export-zip",prefixIcon:e.jsx(Le,{size:14})}],[]);return e.jsxs("div",{className:"kb-drawer",children:[e.jsx("input",{ref:pe,type:"file",accept:".md,.markdown",multiple:!0,style:{display:"none"},onChange:Pt}),e.jsx("input",{ref:be,type:"file",accept:".json,.zip",style:{display:"none"},onChange:Ut}),e.jsxs("div",{className:"kb-drawer__body",ref:ye,children:[e.jsxs("div",{className:"kb-drawer__sidebar",style:{width:ve},children:[e.jsxs("div",{className:"kb-drawer__toolbar",children:[e.jsxs("div",{className:"kb-drawer__search",style:{display:"flex",gap:"8px",alignItems:"center",marginBottom:"8px"},children:[e.jsx(je,{size:"small",prefixIcon:e.jsx(ut,{size:14}),placeholder:"搜索笔记...",value:F,onChange:a=>P(a),clearable:!0,style:{flex:1}}),e.jsx(ft,{trigger:"click",options:Ft,onClick:Wt,minColumnWidth:120,maxColumnWidth:200,popupProps:{overlayStyle:{width:200}},children:e.jsx(V,{content:"更多操作",showArrow:!1,children:e.jsx("button",{style:{background:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"4px",color:"var(--td-text-color-secondary)",borderRadius:"4px"},onMouseEnter:a=>a.currentTarget.style.backgroundColor="var(--td-bg-color-container-hover)",onMouseLeave:a=>a.currentTarget.style.backgroundColor="transparent",children:e.jsx(bs,{size:18})})})})]}),e.jsxs("div",{className:"kb-drawer__filters",style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(Ts,{allTags:f,selectedTagIds:S,onSelectedChange:W}),e.jsx("div",{style:{flex:1}}),e.jsx(qs,{value:B,onChange:Lt})]})]}),e.jsx(Cs,{directories:n,notesByDir:yt,noteTagsMap:N,noteCounts:Nt,selectedDirId:T,selectedNoteId:m,expandedDirIds:y,onSelectDir:a=>{b(a),A(null),j(null)},onToggleExpand:Rt,onCreateDir:Ce,onRenameDir:Ct,onDeleteDir:St,onDuplicateDir:Et,onSelectNote:ee,onCreateNote:Se,onDeleteNote:Dt,onDuplicateNote:zt,isCreatingDir:_,onCancelCreateDir:()=>K(!1),onInsertNoteToCanvas:Tt}),Fe&&e.jsxs("div",{className:"kb-drawer__storage-bar",children:[e.jsx(gs,{size:12}),e.jsxs("span",{className:"kb-drawer__storage-text",children:["已用 ",Qs(Fe.used)]})]})]}),e.jsx("div",{className:"kb-resizer",onMouseDown:kt}),e.jsx("div",{className:"kb-drawer__editor",children:e.jsx(Ms,{note:l,allTags:f,noteTags:L,readOnly:!!(m&&(m.startsWith(ie)||m.startsWith(oe))),isSkillDirectory:!!(l&&(((qe=n.find(a=>a.id===l.directoryId))==null?void 0:qe.name)==="Skill"||m&&m.startsWith(ie)||m&&m.startsWith(oe))),onUpdateNote:Ee,onSetNoteTags:At,onCreateTag:Oe})}),l&&e.jsx(e.Fragment,{children:z?e.jsx(V,{content:"展开侧边栏",showArrow:!1,children:e.jsx("button",{className:"kb-drawer__right-toggle",onClick:()=>Q(!1),children:e.jsx(_s,{size:14})})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"kb-resizer",onMouseDown:wt}),e.jsxs("div",{className:"kb-drawer__right-sidebar",style:{width:Ne},children:[e.jsxs("div",{className:"kb-drawer__right-header",children:[e.jsxs("div",{className:"kb-drawer__right-tabs",children:[e.jsx(V,{content:"相似笔记",showArrow:!1,children:e.jsx("button",{className:`kb-drawer__right-tab ${Z==="related"?"kb-drawer__right-tab--active":""}`,onClick:()=>G("related"),children:e.jsx(ht,{size:14})})}),e.jsx(V,{content:"知识提取",showArrow:!1,children:e.jsx("button",{className:`kb-drawer__right-tab ${Z==="extraction"?"kb-drawer__right-tab--active":""}`,onClick:()=>G("extraction"),children:e.jsx($e,{size:14})})})]}),e.jsx(V,{content:"收起侧边栏",showArrow:!1,children:e.jsx("button",{className:"kb-drawer__right-collapse-btn",onClick:()=>Q(!0),children:e.jsx(ks,{size:14})})})]}),e.jsx("div",{className:"kb-drawer__right-content",children:Z==="related"?e.jsx(Ds,{currentNoteId:l.id,allNotes:c,noteTagsMap:N,onSelectNote:ee}):e.jsx(Hs,{noteId:l.id,noteContent:l.content,noteTitle:l.title,onSaved:()=>X(),onInsertToNote:Mt},l.id)})]})]})})]}),e.jsx(zs,{visible:E,onClose:()=>q(!1),allTags:f,onCreateTag:Oe,onUpdateTag:$t,onDeleteTag:It}),fe]})};function Qs(s){if(s===0)return"0 B";const n=["B","KB","MB","GB"],i=Math.floor(Math.log(s)/Math.log(1024));return`${(s/Math.pow(1024,i)).toFixed(1)} ${n[i]}`}export{xn as default};
53
+ `:"",r=(l.content||"")+o+a;await Ee(l.id,{content:r}),I.success("已插入到笔记末尾")},[l,Ee]),Tt=t.useCallback(async a=>{var r,g;const o=window.__drawnixBoard;if(!o){I.warning("请先打开画布");return}try{if(o.children.find(re=>re.noteId===a.id)&&!await te({title:"重复插入提醒",description:"画布中已存在关联该笔记的卡片,是否再次插入?",confirmText:"继续插入",cancelText:"取消"}))return;const w=await C.getNoteById(a.id);if(!w){I.error("获取笔记内容失败");return}const{getViewportOrigination:D}=await Me(async()=>{const{getViewportOrigination:re}=await import("./tool-windows-C4D0lII2.js").then(Re=>Re.oE);return{getViewportOrigination:re}},__vite__mapDeps([0]),import.meta.url),$=D(o),se=((r=o.host)==null?void 0:r.clientWidth)||800,ae=((g=o.host)==null?void 0:g.clientHeight)||600,ue=Math.round(window.innerWidth*.5),Qe=180,Ze=(($==null?void 0:$[0])??0)+se/2-ue/2,Ge=(($==null?void 0:$[1])??0)+ae/2-Qe/2,{Transforms:Bt}=await Me(async()=>{const{Transforms:re}=await import("./tool-windows-C4D0lII2.js").then(Re=>Re.oE);return{Transforms:re}},__vite__mapDeps([0]),import.meta.url),Kt={type:"card",id:`card-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,title:w.title||"无标题",body:w.content||"",noteId:w.id,fillColor:"#FA8C16",points:[[Ze,Ge],[Ze+ue,Ge+Qe]]};Bt.insertNode(o,Kt,[o.children.length]),I.success("已插入到画布")}catch(u){console.error("[KB] Failed to insert note to canvas:",u),I.error(`插入失败: ${u.message}`)}},[]),zt=t.useCallback(async a=>{try{await C.duplicateNote(a),await X(),I.success("笔记复制成功")}catch(o){I.error(`复制笔记失败: ${o.message}`)}},[X]),Dt=t.useCallback(async a=>{if(a.startsWith(ie)){I.warning("系统内置 Skill,不可删除");return}if(a.startsWith(oe)){I.warning("外部 Skill,不可在此删除(请在设置中管理外部 Skill 包)");return}const o=c.find(g=>g.id===a);if(!(!o||!await te({title:"确认删除笔记",description:`确定要删除笔记 "${o.title||"无标题"}" 吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0})))try{await C.deleteNote(a),m===a&&(A(null),j(null),v([])),await X(),I.success("笔记已删除")}catch(g){I.error(`删除失败: ${g.message}`)}},[m,X,c]);t.useEffect(()=>{!Ke.current&&ne.length>0&&(ee(ne[0].id),Ke.current=!0)},[ne,ee]),t.useEffect(()=>{const a=o=>{const{noteId:r}=o.detail;r&&ee(r)};return window.addEventListener("kb:open-note",a),()=>window.removeEventListener("kb:open-note",a)},[ee]),t.useEffect(()=>{const a=async o=>{const{directoryName:r,autoCreateNote:g}=o.detail;if(!r)return;window.__kbPendingNavigation&&(window.__kbPendingNavigation=null);const w=(await C.getAllDirectories()).find(D=>D.name===r);w&&(b(w.id),d(D=>{const $=new Set(D);return $.add(w.id),$}),g&&await Se(w.id))};return window.addEventListener("kb:navigate",a),()=>window.removeEventListener("kb:navigate",a)},[Se]);const At=t.useCallback(async(a,o)=>{await C.setNoteTags(a,o);const r=await C.getTagsForNote(a);v(r),M(u=>({...u,[a]:r}));const g=await C.getAllTags();x(g)},[]),Oe=t.useCallback(async a=>{const o=await C.createTag(a),r=await C.getAllTags();return x(r),o},[]),$t=t.useCallback(async(a,o)=>{await C.updateTag(a,{name:o});const r=await C.getAllTags();x(r)},[]),It=t.useCallback(async a=>{await C.deleteTag(a);const o=await C.getAllTags();if(x(o),l){const r=await C.getTagsForNote(l.id);v(r),M(g=>({...g,[l.id]:r}))}},[l]),Lt=t.useCallback(a=>{h(a),C.saveSortPreference&&C.saveSortPreference(a)},[]);t.useEffect(()=>{if(!H)return;const a=o=>{J.current&&!J.current.contains(o.target)&&Y(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[H]);const pe=t.useRef(null),Xe=t.useCallback(()=>{var a;(a=pe.current)==null||a.click()},[]),Pt=t.useCallback(async a=>{const o=a.target.files;if(!(!o||!T)){for(const r of Array.from(o)){if(!r.name.endsWith(".md")&&!r.name.endsWith(".markdown"))continue;const g=await r.text();await C.importNoteFromMarkdown(g,T,r.name)}await X(),pe.current&&(pe.current.value="")}},[T,X]),Ve=t.useCallback(async()=>{try{const a=await C.exportAsZip(),o=URL.createObjectURL(a),r=document.createElement("a");r.href=o,r.download=`knowledge-base-${new Date().toISOString().slice(0,10)}.zip`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(o)}catch(a){console.error("Export failed:",a),I.error("导出失败")}},[]),be=t.useRef(null),Ye=t.useCallback(()=>{var a;(a=be.current)==null||a.click()},[]),Ut=t.useCallback(async a=>{var r;const o=(r=a.target.files)==null?void 0:r[0];if(o){try{if(o.name.toLowerCase().endsWith(".zip")){const g=await C.importFromZip(o);g.noteCount===0&&g.dirCount===0?I.warning("导入完成:没有新增内容(可能已存在重复内容)"):I.success(`导入完成:${g.dirCount} 个新目录、${g.noteCount} 篇笔记`)}else{const g=await o.text(),u=JSON.parse(g);if(u.version!==1&&u.version!==2){I.error("不支持的导入格式");return}const w=await C.importAllData(u);I.success(`导入完成:${w.dirCount} 个目录、${w.noteCount} 篇笔记、${w.tagCount} 个标签`)}await X()}catch(g){console.error(g),I.error("导入失败,请确认文件格式正确")}be.current&&(be.current.value="")}},[X]),He=t.useCallback(()=>{const a=window.prompt("请输入目录名称","新建目录");a&&Ce(a)},[Ce]),Wt=t.useCallback(a=>{switch(a.value){case"create-dir":He();break;case"manage-tags":q(!0);break;case"import-md":Xe();break;case"import-zip":Ye();break;case"export-zip":Ve();break}},[He,Xe,Ye,Ve]),Ft=t.useMemo(()=>[{content:"新建目录",value:"create-dir",prefixIcon:e.jsx(fs,{size:14})},{content:"管理标签",value:"manage-tags",prefixIcon:e.jsx(ps,{size:14})},{content:"导入 Markdown",value:"import-md",prefixIcon:e.jsx(st,{size:14})},{content:"导入 ZIP",value:"import-zip",prefixIcon:e.jsx(st,{size:14})},{content:"导出 ZIP",value:"export-zip",prefixIcon:e.jsx(Le,{size:14})}],[]);return e.jsxs("div",{className:"kb-drawer",children:[e.jsx("input",{ref:pe,type:"file",accept:".md,.markdown",multiple:!0,style:{display:"none"},onChange:Pt}),e.jsx("input",{ref:be,type:"file",accept:".json,.zip",style:{display:"none"},onChange:Ut}),e.jsxs("div",{className:"kb-drawer__body",ref:ye,children:[e.jsxs("div",{className:"kb-drawer__sidebar",style:{width:ve},children:[e.jsxs("div",{className:"kb-drawer__toolbar",children:[e.jsxs("div",{className:"kb-drawer__search",style:{display:"flex",gap:"8px",alignItems:"center",marginBottom:"8px"},children:[e.jsx(je,{size:"small",prefixIcon:e.jsx(ut,{size:14}),placeholder:"搜索笔记...",value:F,onChange:a=>P(a),clearable:!0,style:{flex:1}}),e.jsx(ft,{trigger:"click",options:Ft,onClick:Wt,minColumnWidth:120,maxColumnWidth:200,popupProps:{overlayStyle:{width:200}},children:e.jsx(V,{content:"更多操作",showArrow:!1,children:e.jsx("button",{style:{background:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"4px",color:"var(--td-text-color-secondary)",borderRadius:"4px"},onMouseEnter:a=>a.currentTarget.style.backgroundColor="var(--td-bg-color-container-hover)",onMouseLeave:a=>a.currentTarget.style.backgroundColor="transparent",children:e.jsx(bs,{size:18})})})})]}),e.jsxs("div",{className:"kb-drawer__filters",style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(Ts,{allTags:f,selectedTagIds:S,onSelectedChange:W}),e.jsx("div",{style:{flex:1}}),e.jsx(qs,{value:B,onChange:Lt})]})]}),e.jsx(Cs,{directories:n,notesByDir:yt,noteTagsMap:N,noteCounts:Nt,selectedDirId:T,selectedNoteId:m,expandedDirIds:y,onSelectDir:a=>{b(a),A(null),j(null)},onToggleExpand:Rt,onCreateDir:Ce,onRenameDir:Ct,onDeleteDir:St,onDuplicateDir:Et,onSelectNote:ee,onCreateNote:Se,onDeleteNote:Dt,onDuplicateNote:zt,isCreatingDir:_,onCancelCreateDir:()=>K(!1),onInsertNoteToCanvas:Tt}),Fe&&e.jsxs("div",{className:"kb-drawer__storage-bar",children:[e.jsx(gs,{size:12}),e.jsxs("span",{className:"kb-drawer__storage-text",children:["已用 ",Qs(Fe.used)]})]})]}),e.jsx("div",{className:"kb-resizer",onMouseDown:kt}),e.jsx("div",{className:"kb-drawer__editor",children:e.jsx(Ms,{note:l,allTags:f,noteTags:L,readOnly:!!(m&&(m.startsWith(ie)||m.startsWith(oe))),isSkillDirectory:!!(l&&(((qe=n.find(a=>a.id===l.directoryId))==null?void 0:qe.name)==="Skill"||m&&m.startsWith(ie)||m&&m.startsWith(oe))),onUpdateNote:Ee,onSetNoteTags:At,onCreateTag:Oe})}),l&&e.jsx(e.Fragment,{children:z?e.jsx(V,{content:"展开侧边栏",showArrow:!1,children:e.jsx("button",{className:"kb-drawer__right-toggle",onClick:()=>Q(!1),children:e.jsx(_s,{size:14})})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"kb-resizer",onMouseDown:wt}),e.jsxs("div",{className:"kb-drawer__right-sidebar",style:{width:Ne},children:[e.jsxs("div",{className:"kb-drawer__right-header",children:[e.jsxs("div",{className:"kb-drawer__right-tabs",children:[e.jsx(V,{content:"相似笔记",showArrow:!1,children:e.jsx("button",{className:`kb-drawer__right-tab ${Z==="related"?"kb-drawer__right-tab--active":""}`,onClick:()=>G("related"),children:e.jsx(ht,{size:14})})}),e.jsx(V,{content:"知识提取",showArrow:!1,children:e.jsx("button",{className:`kb-drawer__right-tab ${Z==="extraction"?"kb-drawer__right-tab--active":""}`,onClick:()=>G("extraction"),children:e.jsx($e,{size:14})})})]}),e.jsx(V,{content:"收起侧边栏",showArrow:!1,children:e.jsx("button",{className:"kb-drawer__right-collapse-btn",onClick:()=>Q(!0),children:e.jsx(ks,{size:14})})})]}),e.jsx("div",{className:"kb-drawer__right-content",children:Z==="related"?e.jsx(Ds,{currentNoteId:l.id,allNotes:c,noteTagsMap:N,onSelectNote:ee}):e.jsx(Hs,{noteId:l.id,noteContent:l.content,noteTitle:l.title,onSaved:()=>X(),onInsertToNote:Mt},l.id)})]})]})})]}),e.jsx(zs,{visible:E,onClose:()=>q(!1),allTags:f,onCreateTag:Oe,onUpdateTag:$t,onDeleteTag:It}),fe]})};function Qs(s){if(s===0)return"0 B";const n=["B","KB","MB","GB"],i=Math.floor(Math.log(s)/Math.log(1024));return`${(s/Math.pow(1024,i)).toFixed(1)} ${n[i]}`}export{xn as default};
@@ -1,4 +1,4 @@
1
- import{nZ as ba,n_ as _a,n$ as xa,o0 as ya,y as t,aI as Sa,o1 as ja,i1 as Ce,nL as Ot,o2 as Ia,o3 as Ca,lH as sa,o4 as Na,r as s,nG as ce,g$ as de,ie as wa,h0 as be,h1 as Ae,hF as Jt,o5 as ka,nH as Ue,nJ as Rt,nn as ra,nq as na,ns as ia,nB as yt,nC as St,nt as Ma,nu as Ta,nw as $a,nQ as jt,nR as Ea,nS as Aa,nT as Pa,bL as Da,nU as It,al as Xe,nV as Va,cX as lt,ib as la,nW as Ct,nX as Nt,hK as wt,kX as Oa,bV as Ge,ka as Ra,o6 as La,o7 as Fa,hM as Zt,as as kt,bx as qt,ni as ot,nj as Ga,nk as za,i$ as Ua,fP as Ba}from"./tool-windows-hjm6YiPY.js";import{e as Ha}from"./MusicAnalyzer-Mmu92A4Y.js";import{M as Be}from"./ModelDropdown-3MjTl1AO.js";import{u as He}from"./use-runtime-models-C0uyCfar.js";import{a as Ke}from"./model-selection-BaH65gMK.js";import{setCanvasBoard as Xt,quickInsert as Qt}from"./canvas-insertion-ZEZkcXvB.js";/* empty css *//* empty css */import{R as Ka}from"./ResizableDivider-B_67th7H.js";import{r as Wa,a as Ya,b as ct,w as Mt,d as Ja,f as Za}from"./workflow-generation-utils-Da12qXTb.js";/* empty css *//* empty css */import"./model-benchmark-service-DDklUBjC.js";const pt="mv-creator:records",qa=50;async function ht(){return ba(pt)}async function Xa(e){return _a(pt,e,qa)}async function Q(e,n){return xa(pt,e,n)}async function Qa(e){return ya(pt,e)}const ea=[{id:"analyze",label:"分析"},{id:"script",label:"脚本"},{id:"generate",label:"生成"}],es=({current:e,onNavigate:n,hasRecord:m,hasShots:g})=>{const d=ea.findIndex(p=>p.id===e);return t.jsx("div",{className:"va-step-bar",children:ea.map((p,y)=>{const k=p.id===e,M=y<d,I=!m&&y>0||(p.id==="script"||p.id==="generate")&&!g;return t.jsxs(Sa.Fragment,{children:[y>0&&t.jsx("span",{className:"va-step-arrow",children:"→"}),t.jsxs("button",{className:`va-step ${k?"active":""} ${M?"past":""}`,onClick:()=>!I&&n(p.id),disabled:I,children:[t.jsx("span",{className:"va-step-num",children:y+1}),p.label]})]},p.id)})})},ts=10;function oa(e,n,m){return{id:sa(),createdAt:Date.now(),label:n,prompt:m,shots:structuredClone(e)}}function ca(e,n){return Na(e,"storyboardVersions",n,ts,{editedShots:n.shots})}const mt=ja;function as(e,n){return Ca(e,"storyboardVersions",n,{getVersionPatch:m=>({editedShots:m.shots}),getOriginalPatch:m=>{var d;const g=(d=m.storyboardVersions)==null?void 0:d[m.storyboardVersions.length-1];return g?{editedShots:[...g.shots]}:null},originalVersionId:mt})}function De(e,n){return Ia(e,"storyboardVersions",n)}function da(e,n=e.editedShots||[]){var k,M,I;const m=e.selectedClipDuration||n.reduce((v,h)=>Math.max(v,h.endTime||0),0),g=(k=e.musicStyleTags)==null?void 0:k.filter(Boolean).join(", "),d=e.characters||[],p=["# 爆款MV脚本","",`**创意描述:** ${e.creationPrompt||"-"}`,`**音乐标题:** ${e.musicTitle||"-"}`,`**音乐风格:** ${g||"-"}`,`**时长:** ${m||0}s`,`**画面比例:** ${e.aspectRatio||"16x9"}`,`**视频风格:** ${e.videoStyle||"-"}`];(M=e.musicLyrics)!=null&&M.trim()&&p.push("","## 歌词","",e.musicLyrics.trim()),(I=e.rewritePrompt)!=null&&I.trim()&&p.push("","## 改编提示词","",e.rewritePrompt.trim()),d.length>0&&(p.push("","## 角色设定",""),d.forEach((v,h)=>{p.push(`### ${h+1}. ${v.name||v.id}`),p.push(`- ID:${v.id}`),p.push(`- 外观提示词:${v.description||"-"}`),v.referenceImageUrl&&p.push(`- 参考图:${v.referenceImageUrl}`),p.push("")}));const y=n.map((v,h)=>{var T;return[`### ${h+1}. ${v.label||`镜头 ${h+1}`} (${v.startTime}s-${v.endTime}s)`,"",`**画面描述:** ${v.description||"-"}`,"",`**旁白:** ${v.narration||"-"}`,v.dialogue?`
1
+ import{nZ as ba,n_ as _a,n$ as xa,o0 as ya,y as t,aI as Sa,o1 as ja,i1 as Ce,nL as Ot,o2 as Ia,o3 as Ca,lH as sa,o4 as Na,r as s,nG as ce,g$ as de,ie as wa,h0 as be,h1 as Ae,hF as Jt,o5 as ka,nH as Ue,nJ as Rt,nn as ra,nq as na,ns as ia,nB as yt,nC as St,nt as Ma,nu as Ta,nw as $a,nQ as jt,nR as Ea,nS as Aa,nT as Pa,bL as Da,nU as It,al as Xe,nV as Va,cX as lt,ib as la,nW as Ct,nX as Nt,hK as wt,kX as Oa,bV as Ge,ka as Ra,o6 as La,o7 as Fa,hM as Zt,as as kt,bx as qt,ni as ot,nj as Ga,nk as za,i$ as Ua,fP as Ba}from"./tool-windows-C4D0lII2.js";import{e as Ha}from"./MusicAnalyzer-BTXks5oV.js";import{M as Be}from"./ModelDropdown-CHYgRb1r.js";import{u as He}from"./use-runtime-models-BLwgp0M1.js";import{a as Ke}from"./model-selection-CbzU26xQ.js";import{setCanvasBoard as Xt,quickInsert as Qt}from"./canvas-insertion-CYbFgP4L.js";/* empty css *//* empty css */import{R as Ka}from"./ResizableDivider-P1jpoJ3i.js";import{r as Wa,a as Ya,b as ct,w as Mt,d as Ja,f as Za}from"./workflow-generation-utils-CZULSJWQ.js";/* empty css *//* empty css */import"./model-benchmark-service-B0QCqInK.js";const pt="mv-creator:records",qa=50;async function ht(){return ba(pt)}async function Xa(e){return _a(pt,e,qa)}async function Q(e,n){return xa(pt,e,n)}async function Qa(e){return ya(pt,e)}const ea=[{id:"analyze",label:"分析"},{id:"script",label:"脚本"},{id:"generate",label:"生成"}],es=({current:e,onNavigate:n,hasRecord:m,hasShots:g})=>{const d=ea.findIndex(p=>p.id===e);return t.jsx("div",{className:"va-step-bar",children:ea.map((p,y)=>{const k=p.id===e,M=y<d,I=!m&&y>0||(p.id==="script"||p.id==="generate")&&!g;return t.jsxs(Sa.Fragment,{children:[y>0&&t.jsx("span",{className:"va-step-arrow",children:"→"}),t.jsxs("button",{className:`va-step ${k?"active":""} ${M?"past":""}`,onClick:()=>!I&&n(p.id),disabled:I,children:[t.jsx("span",{className:"va-step-num",children:y+1}),p.label]})]},p.id)})})},ts=10;function oa(e,n,m){return{id:sa(),createdAt:Date.now(),label:n,prompt:m,shots:structuredClone(e)}}function ca(e,n){return Na(e,"storyboardVersions",n,ts,{editedShots:n.shots})}const mt=ja;function as(e,n){return Ca(e,"storyboardVersions",n,{getVersionPatch:m=>({editedShots:m.shots}),getOriginalPatch:m=>{var d;const g=(d=m.storyboardVersions)==null?void 0:d[m.storyboardVersions.length-1];return g?{editedShots:[...g.shots]}:null},originalVersionId:mt})}function De(e,n){return Ia(e,"storyboardVersions",n)}function da(e,n=e.editedShots||[]){var k,M,I;const m=e.selectedClipDuration||n.reduce((v,h)=>Math.max(v,h.endTime||0),0),g=(k=e.musicStyleTags)==null?void 0:k.filter(Boolean).join(", "),d=e.characters||[],p=["# 爆款MV脚本","",`**创意描述:** ${e.creationPrompt||"-"}`,`**音乐标题:** ${e.musicTitle||"-"}`,`**音乐风格:** ${g||"-"}`,`**时长:** ${m||0}s`,`**画面比例:** ${e.aspectRatio||"16x9"}`,`**视频风格:** ${e.videoStyle||"-"}`];(M=e.musicLyrics)!=null&&M.trim()&&p.push("","## 歌词","",e.musicLyrics.trim()),(I=e.rewritePrompt)!=null&&I.trim()&&p.push("","## 改编提示词","",e.rewritePrompt.trim()),d.length>0&&(p.push("","## 角色设定",""),d.forEach((v,h)=>{p.push(`### ${h+1}. ${v.name||v.id}`),p.push(`- ID:${v.id}`),p.push(`- 外观提示词:${v.description||"-"}`),v.referenceImageUrl&&p.push(`- 参考图:${v.referenceImageUrl}`),p.push("")}));const y=n.map((v,h)=>{var T;return[`### ${h+1}. ${v.label||`镜头 ${h+1}`} (${v.startTime}s-${v.endTime}s)`,"",`**画面描述:** ${v.description||"-"}`,"",`**旁白:** ${v.narration||"-"}`,v.dialogue?`
2
2
  **角色对白:** ${v.dialogue}`:"",v.dialogue_speakers?`
3
3
  **对白角色:** ${v.dialogue_speakers}`:"",v.speech_relation?`
4
4
  **语音关系:** ${v.speech_relation}`:"",v.camera_movement?`
@@ -1,2 +1,2 @@
1
- import{bm as us,mJ as ps,r as a,aI as hs,iX as Ce,y as s,ig as fs,ih as bs,bV as je,i9 as _s,i8 as ee,iQ as we,iO as vs,al as Ne,_ as xs,mK as ks,lR as gs,jK as js,jL as ws,ho as Ns,mL as Ss}from"./tool-windows-hjm6YiPY.js";import{m as N,g as $,b as F,r as Se,a as Is,c as Ms}from"./model-benchmark-service-DDklUBjC.js";import{b as Cs}from"./model-benchmark-launcher-BrOG9Vlm.js";const se={text:"文本",image:"图片",video:"视频",audio:"音频"},te={"cross-provider":"跨供应商对比","cross-model":"多模型批测",custom:"自定义测试"},Es={"cross-provider":"锁定一个模型,横向比较不同供应商的稳定性、速度和效果差异。","cross-model":"锁定一个供应商,一次跑完同类模型,快速筛掉慢和差的型号。",custom:"手动编排供应商与模型组合,适合做定向复测和候选名单对比。"},ys={speed:"速度优先",cost:"成本优先",balanced:"综合平衡","value-for-money":"性价比"},Ie={draft:"待启动",running:"测试中",completed:"已完成",partial:"部分失败",failed:"全部失败"},pe={pending:"待测",running:"测试中",completed:"已完成",failed:"失败"},As=6,Ls=8,Ge=32e3;function oe(o){return o?new Date(o).toLocaleString("zh-CN",{hour12:!1}):""}function Je(o){return o.length>Ge?`${o.slice(0,Ge-8)}...[截断]`:o}function G(o){return o?o.startsWith("data:")?"[内嵌数据已省略]":Je(o):""}function Rs(o){return o!=null&&o.length?Je(o.map(i=>G(i)).join(`
1
+ import{bm as us,mJ as ps,r as a,aI as hs,iX as Ce,y as s,ig as fs,ih as bs,bV as je,i9 as _s,i8 as ee,iQ as we,iO as vs,al as Ne,_ as xs,mK as ks,lR as gs,jK as js,jL as ws,ho as Ns,mL as Ss}from"./tool-windows-C4D0lII2.js";import{m as N,g as $,b as F,r as Se,a as Is,c as Ms}from"./model-benchmark-service-B0QCqInK.js";import{b as Cs}from"./model-benchmark-launcher-DtJmU6Wc.js";const se={text:"文本",image:"图片",video:"视频",audio:"音频"},te={"cross-provider":"跨供应商对比","cross-model":"多模型批测",custom:"自定义测试"},Es={"cross-provider":"锁定一个模型,横向比较不同供应商的稳定性、速度和效果差异。","cross-model":"锁定一个供应商,一次跑完同类模型,快速筛掉慢和差的型号。",custom:"手动编排供应商与模型组合,适合做定向复测和候选名单对比。"},ys={speed:"速度优先",cost:"成本优先",balanced:"综合平衡","value-for-money":"性价比"},Ie={draft:"待启动",running:"测试中",completed:"已完成",partial:"部分失败",failed:"全部失败"},pe={pending:"待测",running:"测试中",completed:"已完成",failed:"失败"},As=6,Ls=8,Ge=32e3;function oe(o){return o?new Date(o).toLocaleString("zh-CN",{hour12:!1}):""}function Je(o){return o.length>Ge?`${o.slice(0,Ge-8)}...[截断]`:o}function G(o){return o?o.startsWith("data:")?"[内嵌数据已省略]":Je(o):""}function Rs(o){return o!=null&&o.length?Je(o.map(i=>G(i)).join(`
2
2
  `)):""}function ze(o){return o?"是":"否"}function he(o){let i=0,r=0;return o.forEach(d=>{typeof d=="number"&&Number.isFinite(d)&&(i+=d,r+=1)}),r>0?Number((i/r).toFixed(2)):null}function Ts(o=new Date){const i=`${o.getFullYear()}${String(o.getMonth()+1).padStart(2,"0")}${String(o.getDate()).padStart(2,"0")}`,r=`${String(o.getHours()).padStart(2,"0")}${String(o.getMinutes()).padStart(2,"0")}${String(o.getSeconds()).padStart(2,"0")}`;return`model-benchmark-history_${i}_${r}.xlsx`}function Me(o){return o!==null}function Ds(o){return o.trim().toLowerCase().split(/\s+/).filter(Boolean)}function fe(o,i){const r=Ds(o);if(r.length===0)return!0;const d=i.filter(Boolean).join(" ").toLowerCase();return r.every(u=>d.includes(u))}function Ps(o){return o==="text"?"supportsText":o==="image"?"supportsImage":o==="video"?"supportsVideo":"supportsAudio"}function Xe(o,i){const r=Ps(i);return o.filter(d=>d.enabled&&(d.id===vs||d.capabilities[r]))}function $s(){const[o,i]=a.useState(0);return a.useEffect(()=>Ce.subscribe(()=>{i(r=>r+1)}),[]),o}function Bs(){const[o,i]=a.useState(()=>we.get());return a.useEffect(()=>{const r=d=>{i(d)};return we.addListener(r),()=>{we.removeListener(r)}},[]),o}function be(o){return!o||o<0?"--":o<1e3?`${o}ms`:`${(o/1e3).toFixed(o>=1e4?1:2)}s`}function Ks(o){const i=new Map;o.entries.forEach(d=>{var re,h;const u=(re=d.modelId)==null?void 0:re.trim(),v=(h=d.modelLabel)==null?void 0:h.trim();u&&v&&!i.has(u)&&i.set(u,{modelId:u,modelLabel:v})});const r=new Map;return i.forEach(({modelLabel:d})=>{r.set(d,(r.get(d)||0)+1)}),Array.from(i.values()).map(({modelId:d,modelLabel:u})=>(r.get(u)||0)>1?`${u} · ${d}`:u)}function Qe(o){return o?o.entries.reduce((i,r)=>(i.total+=1,r.status==="completed"&&(i.completed+=1),r.status==="failed"&&(i.failed+=1),r.status==="running"&&(i.running+=1),i),{total:0,completed:0,failed:0,running:0}):{total:0,completed:0,failed:0,running:0}}function S(o,i){const r=Ce.getState(o).models.filter(u=>u.type===i),d=new Map;return r.forEach(u=>{d.has(u.id)||d.set(u.id,u)}),Array.from(d.values())}function We(o){return o.shortLabel||o.label||o.id}function Ue(o){const i=We(o);return i===o.id?i:`${i} · ${o.id}`}function Vs(o,i){return`${o}::${i}`}function Xs({}){const{confirm:o,confirmDialog:i}=us(),r=ps(Cs),d=Bs(),u=$s(),[v,re]=a.useState(()=>N.getState()),[h,Ee]=a.useState("text"),[_,ye]=a.useState("cross-provider"),[k,le]=a.useState(""),[B,ne]=a.useState(""),[z,K]=a.useState([]),[X,Q]=a.useState([]),[U,J]=a.useState([]),[O,Fs]=a.useState(""),[q,Os]=a.useState(!1),[Ye,Ae]=a.useState($("text").id),[ae,_e]=a.useState($("text").prompt),[Le,He]=a.useState(2),[ve,Re]=a.useState(!1),[xe,Ze]=a.useState("speed"),[ke,es]=a.useState(""),[ie,ss]=a.useState("all"),Te=a.useRef(""),A=a.useRef(!1),ce=a.useRef(null);a.useRef({}),a.useEffect(()=>{const e=N.observe().subscribe(t=>{a.startTransition(()=>{re(t)})});return()=>e.unsubscribe()},[]);const w=a.useMemo(()=>Xe(d,h),[h,d]),W=a.useMemo(()=>new Map(w.map(e=>[e.id,e])),[w]),C=k&&W.get(k)||null,ts=hs.useCallback(async e=>{await o({title:"确认删除会话",description:`确定要删除会话「${e.title||"未命名会话"}」吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0})&&N.removeSession(e.id)},[o]),L=a.useMemo(()=>k?S(k,h):[],[u,h,k]),ge=a.useMemo(()=>{const e=new Map;return w.forEach(t=>{S(t.id,h).forEach(c=>{e.has(c.id)||e.set(c.id,c)})}),Array.from(e.values())},[w,u,h]),R=a.useMemo(()=>w.flatMap(e=>S(e.id,h).map(t=>F(e.id,e.name,t))),[w,u,h]);a.useEffect(()=>{if(A.current){console.debug("[Benchmark] reconcile profile/prompt: skipped (launchGuard)");return}if(!w.length){le("");return}const e=$(h);Ae(e.id),_e(t=>t===$("text").prompt||t===$("image").prompt||t===$("video").prompt||t===$("audio").prompt?e.prompt:t),(!k||!W.has(k))&&le(w[0].id)},[w,h,W,k]),a.useEffect(()=>{if(A.current){console.debug("[Benchmark] reconcile modelIds: skipped (launchGuard)");return}const e=L.map(t=>t.id);if(e.length===0){K([]);return}K(t=>{const c=Se(t,e,{fallback:"all"});return c!==t&&console.debug("[Benchmark] reconcile modelIds: changed",{from:t,to:c}),c})},[L]),a.useEffect(()=>{if(A.current){console.debug("[Benchmark] reconcile selectedModelId: skipped (launchGuard)");return}const e=ge.map(t=>t.id);if(e.length===0){ne("");return}e.includes(B)||ne(e[0])},[ge,B]);const V=a.useMemo(()=>B?w.map(e=>{const t=S(e.id,h).find(c=>c.id===B);return t?F(e.id,e.name,t):null}).filter(Me):[],[w,h,B]);a.useEffect(()=>{if(A.current){console.debug("[Benchmark] reconcile providerIds: skipped (launchGuard)");return}Q(e=>Se(e,V.map(t=>t.profileId),{fallback:"all"}))},[V]),a.useEffect(()=>{if(A.current){console.debug("[Benchmark] reconcile customKeys: skipped (launchGuard)");return}J(e=>Se(e,R.map(t=>t.selectionKey),{fallback:"first",limit:As}))},[R]);const f=a.useMemo(()=>v.sessions.find(e=>e.id===v.activeSessionId)||null,[v.activeSessionId,v.sessions]),De=a.useMemo(()=>v.sessions.filter(e=>ie!=="all"&&e.modality!==ie?!1:fe(ke,[e.title,e.prompt,te[e.compareMode],se[e.modality],...e.entries.flatMap(t=>[t.profileName,t.profileId,t.modelLabel,t.modelId,t.vendor])])),[ie,ke,v.sessions]);a.useEffect(()=>{f&&Ze(f.rankingMode)},[f]);const os=a.useMemo(()=>Qe(f),[f]),rs=a.useMemo(()=>f?Is(f.entries,f.rankingMode):[],[f]),T=a.useMemo(()=>{if(_==="cross-provider")return V.filter(e=>X.includes(e.profileId));if(_==="cross-model"){if(!k)return[];const e=W.get(k);return e?L.filter(t=>z.includes(t.id)).map(t=>F(e.id,e.name,t)):[]}return R.filter(e=>U.includes(e.selectionKey))},[L,_,V,R,W,U,z,k,X]),Pe=a.useMemo(()=>{if(!f||f.modality!==h||f.compareMode!==_)return!1;const e=T.map(c=>c.selectionKey);if(e.length===0||f.entries.length!==e.length)return!1;const t=new Set(e);return f.entries.every(c=>t.has(c.selectionKey))},[f,_,h,T]),$e=a.useMemo(()=>f&&Pe?f.entries.map(e=>({key:e.selectionKey,modelLabel:e.modelLabel,profileName:e.profileName,badgeLabel:pe[e.status]||pe.pending})):T.map(e=>({key:e.selectionKey,modelLabel:e.modelLabel,profileName:e.profileName,badgeLabel:pe.pending})),[f,Pe,T]),x=f,Y=x?os:Qe(null),Be=x?rs:[];$e.length,$e.slice(0,Ls);const I=Be.find(e=>e.status==="completed")||null,Ke=a.useMemo(()=>L.filter(e=>{const t=z.includes(e.id);return q&&!t?!1:fe(O,[We(e),e.id,C==null?void 0:C.name])}),[C==null?void 0:C.name,L,O,z,q]),Ve=a.useMemo(()=>V.filter(e=>{const t=X.includes(e.profileId);return q&&!t?!1:fe(O,[e.profileName,e.modelLabel,e.modelId,e.profileId])}),[V,O,X,q]),Fe=a.useMemo(()=>R.filter(e=>{const t=U.includes(e.selectionKey);return q&&!t?!1:fe(O,[e.profileName,e.modelLabel,e.modelId,e.profileId])}),[R,O,U,q]),de=a.useMemo(()=>_==="cross-model"?Ke.map(e=>e.id):_==="cross-provider"?Ve.map(e=>e.profileId):Fe.map(e=>e.selectionKey),[_,Ke,Ve,Fe]);a.useEffect(()=>{if(de.length===0){ce.current=null;return}ce.current&&de.includes(ce.current)||(ce.current=de[0])},[de]),a.useEffect(()=>{var qe;if(!r){console.debug("[Benchmark] useEffect: no initialRequest, skip");return}if(!v.ready){console.debug("[Benchmark] useEffect: storeState not ready, waiting...");return}const e=JSON.stringify(r);if(Te.current===e){console.debug("[Benchmark] useEffect: same signature, skip",{signature:e});return}const t=r.modality||"text",c=Xe(d,t),E=r.profileId||"",D=r.modelId||"",P=E?Ce.getState(E):null,me=E&&D?S(E,t):[],ue=!D||me.some(b=>b.id===D);if(P&&D&&!ue&&(P.status==="idle"||P.status==="loading")){console.debug("[Benchmark] useEffect: waiting for requested model discovery",{signature:e,requestedProfileId:E,requestedModelId:D,status:P.status,discoveryVersion:u});return}A.current=!0,Te.current=e;const H=r.compareMode||(r.modelId?"cross-provider":"cross-model");let j=H,n=[];const l=r.profileId&&r.modelId?Vs(r.profileId,r.modelId):"";H==="cross-provider"&&r.modelId&&(n=c.filter(b=>S(b.id,t).some(Z=>Z.id===r.modelId)).map(b=>b.id),n.length<=1&&(j="custom",console.debug("[Benchmark] cross-provider → custom downgrade",{modelId:r.modelId,matchingProviderIds:n}))),console.debug("[Benchmark] useEffect: applying initialRequest",{nextModality:t,nextCompareMode:j,requestedCompareMode:H,profileId:r.profileId,modelId:r.modelId,profileCount:c.length,matchingProviderIds:n});const M=$(t);Ee(t),ye(j),Ae(M.id),_e(M.prompt);const m=r.profileId||n[0]||((qe=c[0])==null?void 0:qe.id)||"";if(m&&le(m),j==="cross-provider"&&r.modelId)ne(r.modelId),Q(n);else if(j==="cross-model"&&r.modelId)K([r.modelId]);else if(j==="cross-model"&&!r.modelId&&m){const b=S(m,t);K(b.map(Z=>Z.id))}else j==="custom"&&l&&J([l]);const ds=window.setTimeout(()=>{let b;if(j==="cross-provider"&&r.modelId)b=c.map(p=>{const g=S(p.id,t).find(y=>y.id===r.modelId);return g?F(p.id,p.name,g):null}).filter(Me);else if(j==="cross-model"&&r.modelId){const p=c.find(g=>g.id===m);if(p){const g=S(p.id,t).find(y=>y.id===r.modelId);b=g?[F(p.id,p.name,g)]:[]}else b=[]}else if(j==="custom"){const p=c.find(g=>g.id===(r.profileId||m));if(p&&r.modelId){const g=S(p.id,t).find(y=>y.id===r.modelId);b=g?[F(p.id,p.name,g)]:[]}else b=[]}else{const p=m||k;p?b=S(p,t).map(g=>{const y=c.find(ms=>ms.id===p);return y?F(y.id,y.name,g):null}).filter(Me):b=[]}if(!b.length){console.debug("[Benchmark] setTimeout: no targets built, abort");return}if(console.debug("[Benchmark] setTimeout: creating session",{targetCount:b.length,targets:b.map(p=>`${p.profileName}/${p.modelId}`),autoRun:r.autoRun}),!r.autoRun){requestAnimationFrame(()=>{setTimeout(()=>{A.current=!1,console.debug("[Benchmark] guard released without autoRun")},0)});return}const Z=N.createSession({modality:t,compareMode:j,promptPresetId:M.id,prompt:M.prompt,rankingMode:xe,targets:b,source:"shortcut"});N.runSession(Z.id),requestAnimationFrame(()=>{setTimeout(()=>{A.current=!1,console.debug("[Benchmark] guard released")},0)})},120);return()=>{window.clearTimeout(ds)}},[u,r,d,xe,k,v.ready]);const ls=async()=>{if(T.length===0||!ae.trim())return;const e=N.createSession({modality:h,compareMode:_,promptPresetId:Ye,prompt:ae,rankingMode:xe,targets:T,source:"manual"});await N.runSession(e.id,Le)},ns=async()=>{if(ve)return;const e=v.sessions;if(e.length===0){Ne.warning("暂无历史会话可导出");return}Re(!0);try{const t=await xs(()=>import("./xlsx-CkFp8p6R.js"),[],import.meta.url),c=e.flatMap(n=>n.entries.map(l=>({会话标题:n.title,会话ID:n.id,会话创建时间:oe(n.createdAt),模态:se[n.modality],对比方式:te[n.compareMode],会话状态:Ie[n.status],提示词预设:n.promptPresetId,提示词:G(n.prompt),供应商配置:l.profileName,供应商ID:l.profileId,模型名称:l.modelLabel,模型ID:l.modelId,厂商:l.vendor,选择Key:l.selectionKey,结果ID:l.id,结果状态:pe[l.status],开始时间:oe(l.startedAt),首响时间:oe(l.firstResponseAt),完成时间:oe(l.completedAt),首响ms:l.firstResponseMs,总耗时ms:l.totalDurationMs,预估成本:l.estimatedCost,用户评分:l.userScore,已收藏:ze(l.favorite),已淘汰:ze(l.rejected),错误摘要:G(l.errorSummary),预览文本:G(l.preview.text),预览链接:G(l.preview.url),预览链接列表:Rs(l.preview.urls),预览格式:l.preview.format||"",预览时长:l.preview.duration??"",预览标题:G(l.preview.title)}))),E=new Map;e.forEach(n=>{n.entries.forEach(l=>{const M=`${n.modality}::${l.selectionKey}`,m=E.get(M)||{profileName:l.profileName,profileId:l.profileId,modelLabel:l.modelLabel,modelId:l.modelId,vendor:l.vendor,modality:se[n.modality],selectionKey:l.selectionKey,sessionIds:new Set,count:0,completedCount:0,failedCount:0,runningCount:0,pendingCount:0,favoriteCount:0,rejectedCount:0,firstResponseValues:[],totalDurationValues:[],costValues:[],scoreValues:[],latestAt:0};m.sessionIds.add(n.id),m.count+=1,l.status==="completed"&&(m.completedCount+=1),l.status==="failed"&&(m.failedCount+=1),l.status==="running"&&(m.runningCount+=1),l.status==="pending"&&(m.pendingCount+=1),l.favorite&&(m.favoriteCount+=1),l.rejected&&(m.rejectedCount+=1),typeof l.firstResponseMs=="number"&&m.firstResponseValues.push(l.firstResponseMs),typeof l.totalDurationMs=="number"&&m.totalDurationValues.push(l.totalDurationMs),typeof l.estimatedCost=="number"&&m.costValues.push(l.estimatedCost),typeof l.userScore=="number"&&m.scoreValues.push(l.userScore),m.latestAt=Math.max(m.latestAt,l.completedAt||l.startedAt||n.updatedAt||n.createdAt),E.set(M,m)})});const D=Array.from(E.values()).map(n=>({供应商配置:n.profileName,供应商ID:n.profileId,模型名称:n.modelLabel,模型ID:n.modelId,厂商:n.vendor,模态:n.modality,选择Key:n.selectionKey,测试次数:n.count,涉及会话数:n.sessionIds.size,完成次数:n.completedCount,失败次数:n.failedCount,运行中次数:n.runningCount,待测次数:n.pendingCount,收藏次数:n.favoriteCount,淘汰次数:n.rejectedCount,平均首响ms:he(n.firstResponseValues),最快首响ms:n.firstResponseValues.length>0?Math.min(...n.firstResponseValues):null,平均总耗时ms:he(n.totalDurationValues),最快总耗时ms:n.totalDurationValues.length>0?Math.min(...n.totalDurationValues):null,平均成本:he(n.costValues),平均评分:he(n.scoreValues),最近测试时间:oe(n.latestAt)})).sort((n,l)=>{const M=(l.平均评分??-1)-(n.平均评分??-1);if(M!==0)return M;const m=(n.平均首响ms??Number.MAX_SAFE_INTEGER)-(l.平均首响ms??Number.MAX_SAFE_INTEGER);return m!==0?m:(n.平均成本??Number.MAX_SAFE_INTEGER)-(l.平均成本??Number.MAX_SAFE_INTEGER)}),P=t.utils.book_new(),me=t.utils.json_to_sheet(D),ue=t.utils.json_to_sheet(c);me["!cols"]=[{wch:18},{wch:22},{wch:24},{wch:32},{wch:14},{wch:10},{wch:32},{wch:8},{wch:10},{wch:8},{wch:8},{wch:10},{wch:8},{wch:8},{wch:8},{wch:18},{wch:18},{wch:12},{wch:18},{wch:12},{wch:12},{wch:12},{wch:20}],ue["!cols"]=[{wch:28},{wch:24},{wch:20},{wch:10},{wch:14},{wch:10},{wch:18},{wch:60},{wch:18},{wch:22},{wch:24},{wch:32},{wch:14},{wch:32},{wch:24},{wch:10},{wch:20},{wch:20},{wch:20},{wch:12},{wch:12},{wch:12},{wch:10},{wch:8},{wch:8},{wch:36},{wch:60},{wch:60},{wch:80},{wch:12},{wch:10},{wch:28}],t.utils.book_append_sheet(P,me,"模型汇总"),t.utils.book_append_sheet(P,ue,"原始结果");const H=t.write(P,{bookType:"xlsx",type:"array"}),j=new Blob([H],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});ks(j,Ts()),Ne.success(`已导出 ${D.length} 个模型结果`)}catch(t){console.error("[ModelBenchmark] Excel export failed:",t),Ne.error("导出 Excel 失败,请稍后重试")}finally{Re(!1)}},as=e=>{const t=e.preview.rawData?s.jsxs("details",{className:"model-benchmark__raw-data",children:[s.jsx("summary",{children:"原始数据 (JSON)"}),s.jsx("pre",{children:JSON.stringify(e.preview.rawData,null,2)})]}):null;return e.modality==="text"?s.jsxs("div",{className:"model-benchmark__preview-content",children:[s.jsx("pre",{className:"model-benchmark__preview-text",children:e.preview.text||"暂无返回"}),t]}):e.modality==="image"&&e.preview.url?s.jsxs("div",{className:"model-benchmark__preview-content",children:[s.jsx("img",{className:"model-benchmark__preview-image",src:e.preview.url,alt:e.modelLabel,loading:"lazy"}),t]}):e.modality==="video"&&e.preview.url?s.jsxs("div",{className:"model-benchmark__preview-content",children:[s.jsx("video",{className:"model-benchmark__preview-video",src:e.preview.url,controls:!0,preload:"metadata"}),t]}):e.modality==="audio"&&e.preview.url?s.jsxs("div",{className:"model-benchmark__preview-content",children:[s.jsxs("div",{className:"model-benchmark__preview-audio-shell",children:[s.jsx("audio",{controls:!0,preload:"none",src:e.preview.url}),e.preview.text?s.jsx("pre",{className:"model-benchmark__preview-text",children:e.preview.text}):null]}),t]}):s.jsxs("div",{className:"model-benchmark__preview-empty",children:[e.status==="failed"?"加载失败":"暂无预览",t]})};_==="cross-model"?`${(C==null?void 0:C.name)||"未选择"}`:_==="cross-provider"&&`${B||"未选择"}`;const is=ge.map(e=>({label:Ue(e),value:e.id})),Oe=V.map(e=>({label:`${e.profileName} · ${e.modelLabel}`,value:e.profileId})),cs=[{label:"全部",value:"all",icon:s.jsx(gs,{size:14})},{label:"图片",value:"image",icon:s.jsx(js,{size:"14px"})},{label:"视频",value:"video",icon:s.jsx(ws,{size:"14px"})},{label:"音频",value:"audio",icon:s.jsx(Ns,{size:14,strokeWidth:1.9})},{label:"文本",value:"text",icon:s.jsx(Ss,{size:"14px"})}];return s.jsxs("div",{className:"model-benchmark",children:[s.jsxs("aside",{className:"model-benchmark__sidebar",children:[s.jsxs("div",{className:"model-benchmark__sidebar-head",children:[s.jsx("div",{className:"model-benchmark__panel-title",children:"历史会话"}),s.jsx("button",{type:"button",className:"model-benchmark__ghost-button",onClick:ns,disabled:v.sessions.length===0||ve,children:ve?"导出中...":"导出 Excel"})]}),s.jsxs("div",{className:"model-benchmark__sidebar-filters",children:[s.jsx(fs,{value:ke,onChange:es,placeholder:"搜索会话 / 模型 / 供应商",prefixIcon:s.jsx(bs,{}),size:"small",clearable:!0}),s.jsx("div",{className:"model-benchmark__sidebar-tabs",children:cs.map(e=>s.jsx(je,{content:e.label,children:s.jsx("button",{type:"button",className:ie===e.value?"model-benchmark__sidebar-tab model-benchmark__sidebar-tab--active":"model-benchmark__sidebar-tab",onClick:()=>ss(e.value),"aria-label":e.label,title:e.label,children:e.icon})},e.value))})]}),s.jsx("div",{className:"model-benchmark__session-list",children:De.length>0?De.map(e=>{const t=Ks(e);return s.jsxs("div",{className:"model-benchmark__session-row",children:[s.jsxs("button",{type:"button",className:`model-benchmark__session-item ${e.id===v.activeSessionId?"model-benchmark__session-item--active":""}`,onClick:()=>N.setActiveSession(e.id),children:[s.jsx("span",{className:"model-benchmark__session-title",children:e.title}),s.jsx("span",{className:"model-benchmark__session-models",children:t.length>0?t.join(" / "):"暂无模型信息"}),s.jsxs("span",{className:"model-benchmark__session-meta",children:[te[e.compareMode]," ·"," ",e.entries.length," 个目标 ·"," ",Ie[e.status]]})]}),s.jsx("button",{type:"button",className:"model-benchmark__session-delete",onClick:()=>void ts(e),"aria-label":`删除会话 ${e.title}`,children:s.jsx(je,{content:"删除会话",showArrow:!1,children:s.jsx("span",{children:s.jsx(_s,{})})})})]},e.id)}):s.jsx("div",{className:"model-benchmark__session-empty",children:v.sessions.length===0?"暂无历史会话":"没有匹配的历史会话"})})]}),s.jsx("main",{className:"model-benchmark__main",children:s.jsxs("div",{className:"model-benchmark__main-shell",children:[s.jsxs("section",{className:"model-benchmark__config-dashboard",children:[s.jsxs("div",{className:"model-benchmark__config-row model-benchmark__config-row--top",children:[s.jsx("div",{className:"model-benchmark__modality-tabs",children:Object.keys(se).map(e=>s.jsx("button",{type:"button",className:h===e?"active":"",onClick:()=>Ee(e),children:se[e]},e))}),s.jsx("div",{className:"model-benchmark__mode-selector",children:Object.entries(te).map(([e,t])=>s.jsx(je,{content:Es[e],placement:"top",children:s.jsx("button",{type:"button",className:_===e?"active":"",onClick:()=>ye(e),children:t})},e))})]}),s.jsxs("div",{className:"model-benchmark__config-main",children:[s.jsxs("div",{className:"model-benchmark__config-controls",children:[s.jsxs("div",{className:"model-benchmark__primary-select-row",children:[_==="cross-model"?s.jsx(ee,{className:"model-benchmark__select",label:"目标供应商: ",value:k,onChange:e=>le(e),options:w.map(e=>({label:e.name,value:e.id}))}):null,_==="cross-provider"?s.jsx(ee,{filterable:!0,className:"model-benchmark__select",label:"对比模型: ",value:B,options:is,placeholder:"搜索并选择要横向对比的模型",onChange:e=>ne(e||"")}):null]}),s.jsxs("div",{className:"model-benchmark__secondary-select-row",children:[_==="cross-provider"?s.jsx(ee,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:s.jsxs("div",{className:"model-benchmark__select-actions",children:[s.jsx("button",{type:"button",onClick:()=>Q(Oe.map(e=>e.value)),children:"全选"}),s.jsx("button",{type:"button",onClick:()=>Q([]),children:"清除"})]}),className:"model-benchmark__multi-select",label:"参测供应商: ",value:X,options:Oe,placeholder:"多选要参与对比的供应商 (已选即为批测队列)",onChange:e=>Q(Array.isArray(e)?e:[])}):null,_==="cross-model"?s.jsx(ee,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:s.jsxs("div",{className:"model-benchmark__select-actions",children:[s.jsx("button",{type:"button",onClick:()=>K(L.map(e=>e.id)),children:"全选"}),s.jsx("button",{type:"button",onClick:()=>K([]),children:"清除"})]}),className:"model-benchmark__multi-select",label:"参测模型: ",value:z,options:L.map(e=>({label:Ue(e),value:e.id})),placeholder:"多选要测试的模型 (已选即为批测队列)",onChange:e=>K(Array.isArray(e)?e:[])}):null,_==="custom"?s.jsx(ee,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:s.jsxs("div",{className:"model-benchmark__select-actions",children:[s.jsx("button",{type:"button",onClick:()=>J(R.map(e=>e.selectionKey)),children:"全选"}),s.jsx("button",{type:"button",onClick:()=>J([]),children:"清除"})]}),className:"model-benchmark__multi-select",label:"目标组合: ",value:U,options:R.map(e=>({label:`${e.profileName} · ${e.modelLabel}`,value:e.selectionKey})),placeholder:"手动编排供应商与模型组合",onChange:e=>J(Array.isArray(e)?e:[])}):null]})]}),s.jsxs("div",{className:"model-benchmark__config-actions",children:[s.jsx("div",{className:"model-benchmark__prompt-area",children:s.jsx("textarea",{value:ae,onChange:e=>_e(e.target.value),placeholder:"在此输入测试提示词..."})}),s.jsxs("div",{className:"model-benchmark__action-row-inline",children:[s.jsxs("div",{className:"model-benchmark__concurrency",children:[s.jsx("span",{children:"最大并发:"}),s.jsx("input",{type:"text",inputMode:"numeric","aria-label":"最大并发",value:Le,onChange:e=>{const t=e.target.value.replace(/\D/g,""),c=Number(t);He(Math.min(10,Math.max(1,c||1)))}})]}),s.jsxs("button",{type:"button",className:"model-benchmark__primary-button",onClick:ls,disabled:!v.ready||T.length===0||!ae.trim(),children:["开始测试 (",T.length,")"]})]})]})]})]}),s.jsx("div",{className:"model-benchmark__main-head",children:s.jsxs("div",{children:[s.jsx("div",{className:"model-benchmark__eyebrow",children:x?te[x.compareMode]:"Result Board"}),s.jsx("h3",{children:x?x.title:"还没有测试结果"}),x?s.jsxs("p",{className:"model-benchmark__main-desc",children:[Y.total," 个目标",Y.completed>0?`,${Y.completed} 成功`:"",Y.failed>0?`,${Y.failed} 失败`:""," · ",Ie[x.status]," · ",ys[x.rankingMode]]}):s.jsx("p",{className:"model-benchmark__main-desc",children:"请先在上方明确范围,或点击历史会话查看以往结果。"})]})}),x?s.jsxs(s.Fragment,{children:[I?s.jsxs("section",{className:"model-benchmark__spotlight",children:[s.jsxs("div",{className:"model-benchmark__spotlight-copy",children:[s.jsx("div",{className:"model-benchmark__eyebrow",children:"当前第一名"}),s.jsx("h4",{children:x.compareMode==="cross-provider"?I.profileName:I.modelLabel}),s.jsxs("p",{children:[x.compareMode==="cross-provider"?`${I.modelLabel},`:`来自 ${I.profileName},`,"首响 ",be(I.firstResponseMs),",总耗时 ",be(I.totalDurationMs)]})]}),s.jsxs("div",{className:"model-benchmark__spotlight-meta",children:[I.userScore?s.jsxs("span",{children:[I.userScore," 分"]}):null,I.favorite?s.jsx("span",{children:"已收藏"}):null]})]}):null,s.jsx("div",{className:"model-benchmark__result-grid",children:Be.map((e,t)=>s.jsxs("article",{className:`model-benchmark__result-card model-benchmark__result-card--${e.status}`,children:[s.jsxs("header",{className:"model-benchmark__result-head",children:[s.jsxs("div",{className:"model-benchmark__result-rank",children:["#",t+1]}),s.jsxs("div",{className:"model-benchmark__result-heading",children:[s.jsx("div",{className:"model-benchmark__result-title",children:e.modelLabel}),s.jsx("div",{className:"model-benchmark__result-subtitle",children:e.profileName})]}),s.jsx("span",{className:`model-benchmark__status model-benchmark__status--${e.status}`,children:e.status==="completed"?"完成":e.status==="failed"?"失败":e.status==="running"?"测试中":"等待中"})]}),s.jsxs("div",{className:"model-benchmark__result-metrics",children:[s.jsxs("span",{children:["首响 ",be(e.firstResponseMs)]}),s.jsxs("span",{children:["总耗时 ",be(e.totalDurationMs)]}),s.jsxs("span",{children:["成本"," ",e.estimatedCost===null?"未知":`¥${e.estimatedCost.toFixed(4)}`]}),s.jsxs("span",{children:["性价比"," ",(()=>{const c=Ms(e);return c===null?"—":`${c}/10`})()]})]}),s.jsx("div",{className:"model-benchmark__preview",children:as(e)}),e.errorSummary?s.jsx("div",{className:"model-benchmark__error",children:e.errorSummary}):null,s.jsxs("div",{className:"model-benchmark__feedback",children:[s.jsx("div",{className:"model-benchmark__score-row",children:[1,2,3,4,5].map(c=>s.jsxs("button",{type:"button",className:`model-benchmark__score-chip ${e.userScore===c?"model-benchmark__score-chip--active":""}`,onClick:()=>N.setEntryFeedback(x.id,e.id,{userScore:e.userScore===c?null:c}),children:[c,"分"]},c))}),s.jsxs("div",{className:"model-benchmark__action-row",children:[s.jsx("button",{type:"button",className:`model-benchmark__ghost-button ${e.favorite?"model-benchmark__ghost-button--active":""}`,onClick:()=>N.setEntryFeedback(x.id,e.id,{favorite:!e.favorite}),children:"收藏"}),s.jsx("button",{type:"button",className:`model-benchmark__ghost-button ${e.rejected?"model-benchmark__ghost-button--danger":""}`,onClick:()=>N.setEntryFeedback(x.id,e.id,{rejected:!e.rejected}),children:"淘汰"})]})]})]},e.id))})]}):s.jsx("div",{className:"model-benchmark__empty",children:"先在左侧选定“同供应商多模型”或“同模型跨供应商”,把批测目标编满后再开跑。"})]})}),i]})}export{Xs as default};
@@ -1 +1 @@
1
- import{r as s,y as r,iO as Pe,iI as Oe,ls as Fe,lt as We,bL as Ze,iR as Ge,lu as Qe,l2 as qe,hb as Xe,j7 as Ye,iT as Ie,hv as Je,dp as Ke,al as Ce,iN as Ne,cV as eo,lv as oo,dM as ro,b7 as no,iK as so,bW as to,aI as ye,hj as io,hk as lo,bD as ao,j3 as co,bw as Ee}from"./tool-windows-hjm6YiPY.js";import{g as J,a as uo,b as Y,D as po,V as mo,i as ie,j as fo,h as ho,f as _o}from"./use-runtime-models-C0uyCfar.js";function wo({controlledValue:n,defaultValue:l,onChange:f}){const[_,u]=s.useState(l),p=n!==void 0,v=p?n:_,a=s.useCallback(c=>{const d=typeof c=="function"?c(v):c;p||u(d),f==null||f(d)},[p,v,f]);return{value:v,setValue:a}}function vo(n){return typeof n!="string"?null:n.trim()||null}function xo(n){var _;const l=(n==null?void 0:n.trim())||"";if(!l)return"供";const f=l.match(/[A-Za-z0-9]+/g);return f!=null&&f[0]?f[0][0].toUpperCase():((_=Array.from(l)[0])==null?void 0:_.toUpperCase())||"供"}const de=({vendor:n,profileName:l,iconUrl:f,size:_=18,className:u})=>{const p=s.useMemo(()=>vo(f),[f]),[v,a]=s.useState(p);s.useEffect(()=>{a(p)},[p]);const c=uo(n),d=l||J(n),M=!!(l||v),b={"--model-source-icon-size":`${_}px`,"--model-source-icon-accent":c.accent,"--model-source-icon-surface":c.surface,"--model-source-icon-border":c.border};return r.jsx("span",{className:`model-source-icon ${M?"model-source-icon--avatar":"model-source-icon--vendor"} ${u||""}`.trim(),style:b,"aria-hidden":"true",title:d,children:M?v?r.jsx("img",{src:v,alt:`${d} 图标`,className:"model-source-icon__image",loading:"lazy",onError:()=>a(null)}):r.jsx("span",{className:"model-source-icon__text",children:xo(d)}):r.jsx(Y,{vendor:n,size:Math.max(_-2,12)})})},go="ai-input-bar__input";function je(n){return n.isComposing||n.keyCode===229}const bo=({isOpen:n,setIsOpen:l,disabled:f=!1,openKeys:_=[],onOpenKey:u,trackPosition:p=!0,children:v})=>{const a=s.useRef(null),c=s.useRef(null),[d,M]=s.useState({top:0,left:0,width:0,bottom:0}),b=s.useCallback(x=>{if(!je(x.nativeEvent)){if(n){if(!u)return;u(x.key)&&x.preventDefault();return}_.includes(x.key)&&(x.preventDefault(),f||l(!0))}},[n,u,_,f,l]);return s.useEffect(()=>{if(!n||!u)return;const x=w=>{var h;if(je(w))return;const N=w.target,V=!!((h=N==null?void 0:N.classList)!=null&&h.contains(go));if(w.defaultPrevented&&!V)return;u(w.key)&&w.preventDefault()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[n,u]),s.useEffect(()=>{if(!n)return;const x=w=>{var V,A;const N=w.target;(V=a.current)!=null&&V.contains(N)||(A=c.current)!=null&&A.contains(N)||l(!1)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[n,l]),s.useLayoutEffect(()=>{if(!p||!n)return;const x=()=>{if(!a.current)return;const w=a.current.getBoundingClientRect();M({top:w.top,left:w.left,width:w.width,bottom:w.bottom})};return x(),window.addEventListener("resize",x),window.addEventListener("scroll",x,!0),()=>{window.removeEventListener("resize",x),window.removeEventListener("scroll",x,!0)}},[n,p]),r.jsx(r.Fragment,{children:v({isOpen:n,setIsOpen:l,containerRef:a,menuRef:c,portalPosition:d,handleTriggerKeyDown:b})})},O=Pe;function Io(n){return n.sourceProfileId?n.sourceProfileId:O}function Co(n,l){const f=new Map(l.map(a=>[a.id,a])),_=new Set,u=new Map;for(const a of n){const c=Io(a),d=`${c}::${a.type}::${a.id}`;if(_.has(d))continue;_.add(d);const M=u.get(c);M?M.push(a):u.set(c,[a])}const p=new Map(po.map((a,c)=>[a,c])),v=[];for(const[a,c]of u){const d=new Map;for(const w of c){const N=d.get(w.vendor);N?N.push(w):d.set(w.vendor,[w])}const M=Array.from(d.entries()).sort((w,N)=>(p.get(w[0])??999)-(p.get(N[0])??999)).map(([w,N])=>({vendor:w,label:J(w),models:Oe(N)})),b=f.get(a),x=a===O;v.push({providerId:a,providerName:x?(b==null?void 0:b.name)||We:(b==null?void 0:b.name)||a,providerIconUrl:x?(b==null?void 0:b.iconUrl)||Fe:b==null?void 0:b.iconUrl,vendorCategories:M,totalCount:c.length})}return v.sort((a,c)=>a.providerId===O?-1:c.providerId===O?1:a.providerName.localeCompare(c.providerName)),v}const No="aitu:settings:provider-nav";function le(n){return(n||"").toLowerCase().replace(/[\s\-_.:/]+/g,"").trim()}const Eo=ye.memo(({model:n})=>{const l=ho(n.sourceProfileId,n.id);return l?r.jsx("span",{className:"model-dropdown__item-price",children:l}):null}),jo=ye.memo(({model:n})=>{const l=_o(n.sourceProfileId,n.id);return l!=null&&l.description?r.jsx("div",{className:"model-dropdown__item-desc",children:l.description}):null});function L(n,l){const f=n.toLowerCase().trim(),_=l.toLowerCase().trim();if(!f||!_)return 0;const u=le(f),p=le(_);if(!p)return 0;if(f===_||u===p)return 120;if(f.startsWith(_)||u.startsWith(p))return 100;if(f.includes(_))return 80;if(u.includes(p))return 70;const v=_.split(/\s+/).filter(Boolean);if(v.length>1&&v.every(c=>{const d=le(c);return f.includes(c)||!!d&&u.includes(d)}))return 60;let a=0;for(const c of u)if(c===p[a]&&(a+=1,a===p.length))return 40;return 0}const Mo=({selectedModel:n,selectedSelectionKey:l,onSelect:f,onSelectModel:_,language:u="zh",models:p=qe,placement:v="up",header:a,disabled:c=!1,variant:d="minimal",placeholder:M,allowCustomValue:b=!0,isOpen:x,onOpenChange:w,providerProfilesOverride:N,showProviderAction:V=!0})=>{const{setAppState:A}=Ze(),{value:h,setValue:j}=wo({controlledValue:x,defaultValue:!1,onChange:w}),[P,y]=s.useState(""),[U,S]=s.useState(0),[R,G]=s.useState(null),[$,H]=s.useState(null),{contextMenu:Me,open:ae,close:T}=Ge(),K=s.useRef(null),ee=s.useRef(null),Q=s.useRef(null),De=Qe(),B=N||De,ce=s.useMemo(()=>new Map(B.map(e=>[e.id,e])),[B]),ue=s.useMemo(()=>new Map(p.map((e,o)=>[e.selectionKey||e.id,o])),[p]),q=s.useCallback(e=>e.selectionKey||e.id,[]),pe=s.useCallback(e=>e.sourceProfileId&&ce.get(e.sourceProfileId)||null,[ce]),I=s.useMemo(()=>Co(p,B),[p,B]),me=s.useMemo(()=>new Map(I.map(e=>[e.providerId,e.providerName])),[I]),oe=s.useMemo(()=>new Map(I.map(e=>[e.providerId,e.totalCount])),[I]),re=s.useCallback(e=>me.get(e.sourceProfileId||O)||e.sourceProfileName||J(e.vendor),[me]),k=s.useMemo(()=>I.find(e=>e.providerId===R)||I[0]||null,[I,R]),X=s.useMemo(()=>k&&(k.vendorCategories.find(e=>e.vendor===$)||k.vendorCategories[0])||null,[k,$]);s.useEffect(()=>{if(h&&Q.current){const e=Q.current.querySelector(`[data-model-index="${U}"]`);if(e){const o=Q.current,t=e.offsetTop,g=e.offsetHeight,E=o.scrollTop,Z=o.offsetHeight,m=4;U===0?o.scrollTop=0:t-m<E?o.scrollTop=t-m:t+g>E+Z&&(o.scrollTop=t+g-Z+m)}}},[U,h]);const i=p.find(e=>q(e)===(l||n))||Xe(n),C=s.useMemo(()=>i?pe(i):null,[i,pe]),Te=(i==null?void 0:i.shortCode)||"img",F=!!P.trim(),W=s.useMemo(()=>i!=null&&i.sourceProfileId?i.sourceProfileId:l!=null&&l.includes("::")?l.split("::")[0]:O,[i,l]),z=(i==null?void 0:i.vendor)??null;s.useEffect(()=>{d==="form"&&!h&&y((i==null?void 0:i.label)||n)},[n,i,d,h]);const fe=s.useMemo(()=>{const e=P.trim();return e?p.map(o=>{const t=Math.max(L(o.id,e),L(o.label,e),L(o.shortLabel||"",e),L(o.shortCode||"",e),L(o.description||"",e),L(re(o),e),L(J(o.vendor),e));return{model:o,score:t}}).filter(({score:o})=>o>0).sort((o,t)=>t.score-o.score||Ye(o.model,t.model,{fallbackOrderMap:ue})):[]},[re,p,P,ue]),he=s.useMemo(()=>fe.map(({model:e})=>e),[fe]),D=s.useMemo(()=>F?he:(X==null?void 0:X.models)||[],[F,he,X]),ke=s.useMemo(()=>I.map(e=>{var o,t;return{id:e.providerId,label:e.providerName,count:e.totalCount,icon:e.providerIconUrl?r.jsx(de,{vendor:((o=e.vendorCategories[0])==null?void 0:o.vendor)||"OTHER",profileName:e.providerName,iconUrl:e.providerIconUrl,size:16}):r.jsx(Y,{vendor:((t=e.vendorCategories[0])==null?void 0:t.vendor)||"OTHER",size:16})}}),[I]),ze=s.useMemo(()=>((k==null?void 0:k.vendorCategories)||[]).map(e=>({id:e.vendor,label:e.label,count:e.models.length,icon:r.jsx(Y,{vendor:e.vendor,size:14})})),[k]),Re=s.useCallback(e=>{var t;G(e),y("");const o=I.find(g=>g.providerId===e);H(((t=o==null?void 0:o.vendorCategories[0])==null?void 0:t.vendor)??null),S(0)},[I]),Le=s.useCallback(e=>{H(e),S(0)},[]),Ve=s.useCallback((e,o)=>{e.preventDefault(),e.stopPropagation(),ae(e,{modelId:o})},[ae]),Ae=s.useCallback(()=>{const e=B.filter(E=>E.id!==Pe),o=e[e.length-1]||null,t=o&&oe.get(o.id)||0,g=o&&t===0?{action:"select",profileId:o.id}:e.some(E=>E.id===Ie&&(oe.get(E.id)||0)===0)?{action:"select",profileId:Ie}:{action:"create"};window.__aituPendingProviderNavigationIntent=g,window.dispatchEvent(new CustomEvent(No,{detail:g})),j(!1),A(E=>({...E,openSettings:!0}))},[B,oe,A,j]);s.useEffect(()=>{const e=l||n,o=D.findIndex(t=>q(t)===e);S(o>=0?o:0)},[D,n,l,q]),s.useEffect(()=>{var o;if(F)return;if(!R||!I.some(t=>t.providerId===R)){const t=I.find(g=>g.providerId===W);if(G((t==null?void 0:t.providerId)||((o=I[0])==null?void 0:o.providerId)||null),z){H(z);return}}const e=I.find(t=>t.providerId===R)||I[0]||null;if(e){const t=e.vendorCategories.map(g=>g.vendor);(!$||!t.includes($))&&H(t[0]??null)}},[I,R,$,F,W,z]),s.useEffect(()=>{h||T()},[h,T]);const _e=s.useCallback(e=>{if(e==null||e.preventDefault(),c)return;const o=!h;o&&(G(W),z&&H(z)),o?y(""):d==="form"&&y((i==null?void 0:i.label)||n),j(o)},[c,h,j,d,i,n,W,z]),ne=s.useCallback(e=>{T(),f(e.id,Je(e.sourceProfileId||null,e.id)),_==null||_(e),j(!1),y(d==="form"?e.label||e.id:"")},[T,f,_,j,d]),we=s.useCallback(async e=>{try{await Ke(e),Ce.success(u==="zh"?"模型名已复制":"Model name copied"),T()}catch(o){console.error("[ModelDropdown] failed to copy model id",o),Ce.error(u==="zh"?"复制失败":"Copy failed")}},[T,u]),ve=s.useCallback(e=>{var t;const o=p.find(g=>g.id===e);return(t=Ne.getModelPrice(o==null?void 0:o.sourceProfileId,e))==null?void 0:t.docsUrl},[p]),xe=s.useCallback(e=>{var t;const o=p.find(g=>g.id===e);if(o!=null&&o.description)return o.description;if(o!=null&&o.sourceProfileId)return(t=Ne.getModelPrice(o.sourceProfileId,e))==null?void 0:t.description},[p]),Ue=s.useCallback(({modelId:e})=>{const o=xe(e),t=[{key:"model-id",label:e,disabled:!0}];o&&t.push({key:"model-desc",label:r.jsx("span",{style:{fontSize:11,color:"var(--td-text-color-secondary)",whiteSpace:"normal",lineHeight:1.4,display:"block",maxWidth:260},children:o.length>80?o.slice(0,80)+"…":o}),disabled:!0}),t.push({key:"divider-1",type:"divider"},{key:"copy-model-id",label:u==="zh"?"复制模型名":"Copy model name",icon:r.jsx(eo,{size:14}),onSelect:({modelId:E})=>we(E)});const g=ve(e);return g&&t.push({key:"open-docs",label:u==="zh"?"查看模型文档":"View model docs",icon:r.jsx(oo,{size:14}),onSelect:()=>window.open(g,"_blank","noopener")}),t},[xe,ve,we,u]),Se=s.useCallback(e=>{if(e==="Escape")return j(!1),d==="form"&&y((i==null?void 0:i.label)||n),!0;if(e==="ArrowDown")return D.length>0&&S(o=>o<D.length-1?o+1:0),!0;if(e==="ArrowUp")return D.length>0&&S(o=>o>0?o-1:D.length-1),!0;if(e==="Enter"||e==="Tab"){const o=D[U];if(o)return ne(o),!0;if(d==="form"&&b&&P.trim())return f(P.trim()),j(!1),!0}return!1},[D,U,ne,d,b,i,f,P,n,j]);s.useEffect(()=>{var e,o;h&&d==="form"&&((e=K.current)==null||e.focus(),(o=K.current)==null||o.select())},[h,d]),s.useEffect(()=>{var e;h&&d==="minimal"&&((e=ee.current)==null||e.focus())},[h,d]),s.useEffect(()=>{!h&&d==="minimal"&&P&&y("")},[h,P,d]);const $e=e=>d==="minimal"?r.jsxs("button",{className:`model-dropdown__trigger model-dropdown__trigger--minimal ${h?"model-dropdown__trigger--open":""}`,onMouseDown:_e,onKeyDown:e,type:"button","aria-haspopup":"listbox","aria-expanded":h,"aria-label":`${(i==null?void 0:i.shortLabel)||(i==null?void 0:i.label)||n} (↑↓ Tab)`,disabled:c,children:[i?r.jsx(de,{vendor:i.vendor,profileName:(C==null?void 0:C.name)||i.sourceProfileName,iconUrl:C==null?void 0:C.iconUrl,size:15,className:"model-dropdown__trigger-source-icon"}):null,r.jsx("span",{className:"model-dropdown__at",children:"#"}),r.jsx("span",{className:"model-dropdown__code",children:Te}),r.jsx(ie,{modelId:n,profileId:(C==null?void 0:C.id)||(i==null?void 0:i.sourceProfileId)||null}),r.jsx(Ee,{size:14,className:`model-dropdown__chevron ${h?"model-dropdown__chevron--open":""}`})]}):r.jsxs("div",{className:`model-dropdown__trigger model-dropdown__trigger--form ${h?"model-dropdown__trigger--open":""}`,onMouseDown:o=>{o.preventDefault(),h||(j(!0),y(""),G(W),z&&H(z))},children:[r.jsxs("div",{className:"model-dropdown__form-content",children:[i?r.jsx(de,{vendor:i.vendor,profileName:(C==null?void 0:C.name)||i.sourceProfileName,iconUrl:C==null?void 0:C.iconUrl,size:18,className:"model-dropdown__trigger-source-icon"}):null,r.jsx("input",{ref:K,type:"text",className:"model-dropdown__form-input",value:P,onChange:o=>{y(o.target.value),h||j(!0)},placeholder:M||(u==="zh"?"选择或输入模型":"Select or enter model"),disabled:c}),r.jsx(ie,{modelId:n,profileId:(C==null?void 0:C.id)||(i==null?void 0:i.sourceProfileId)||null})]}),r.jsx(Ee,{size:16,className:`model-dropdown__chevron ${h?"model-dropdown__chevron--open":""}`,onMouseDown:o=>{o.preventDefault(),o.stopPropagation(),_e()}})]});return r.jsx(bo,{isOpen:h,setIsOpen:j,disabled:c,openKeys:["Enter"," "],onOpenKey:Se,trackPosition:d==="form"||v==="down"||v==="up",children:({containerRef:e,menuRef:o,portalPosition:t,handleTriggerKeyDown:g})=>{const E=d==="form"||v==="down"||v==="up",Z=r.jsxs("div",{className:`model-dropdown__menu model-dropdown__menu--${v} ${d==="form"?"model-dropdown__menu--form":""} ${E?"model-dropdown__menu--portalled":""} ${no}`,ref:o,role:"listbox","aria-label":u==="zh"?"选择模型":"Select Model",onMouseDown:m=>m.stopPropagation(),onClick:m=>m.stopPropagation(),style:E?{position:"fixed",zIndex:ro.DROPDOWN_PORTAL,left:t.left,width:d==="form"?Math.max(t.width,I.length>1?620:520):"auto",top:v==="down"?t.bottom+4:"auto",bottom:v==="up"?window.innerHeight-t.top+4:"auto",visibility:t.width===0?"hidden":"visible"}:{zIndex:1e3},children:[d==="minimal"?r.jsxs("div",{className:"model-dropdown__toolbar",children:[a?r.jsx("div",{className:"model-dropdown__toolbar-title",children:a}):null,r.jsx("div",{className:"model-dropdown__search",children:r.jsxs("div",{className:"model-dropdown__search-input-wrapper",children:[r.jsx(so,{className:"model-dropdown__search-icon"}),r.jsx("input",{ref:ee,type:"text",className:"model-dropdown__search-input",value:P,onChange:m=>y(m.target.value),placeholder:u==="zh"?"搜索模型名 / 展示名 / 供应商":"Search model id / label / provider"}),P?r.jsx("button",{type:"button",className:"model-dropdown__search-clear",onClick:()=>{var m;y(""),(m=ee.current)==null||m.focus()},"aria-label":u==="zh"?"清空搜索":"Clear search",children:r.jsx(to,{size:14})}):null]})})]}):a?r.jsx("div",{className:"model-dropdown__header",children:a}):null,r.jsx(mo,{tabs:ke,activeTab:R,onTabChange:Re,middleTabs:ze,activeMiddleTab:$,onMiddleTabChange:Le,searchQuery:P,compact:!0,tabsFooter:V?r.jsx("button",{type:"button",className:"model-dropdown__provider-action",onClick:Ae,"aria-label":u==="zh"?"新增供应商或打开供应商设置":"Add provider or open provider settings",children:r.jsx(lo,{size:16})}):null,children:r.jsx("div",{className:"model-dropdown__list-pane",children:r.jsx("div",{className:"model-dropdown__list",ref:Q,onScroll:T,children:D.length>0?D.map((m,se)=>{var be;const ge=q(m),te=ge===(l||n),He=se===U;return r.jsxs("div",{"data-model-index":se,className:`model-dropdown__item ${te?"model-dropdown__item--selected":""} ${He?"model-dropdown__item--highlighted":""}`,onClick:()=>ne(m),onMouseEnter:()=>{S(se)},onContextMenu:Be=>Ve(Be,m.id),role:"option","aria-selected":te,children:[r.jsxs("div",{className:"model-dropdown__item-content",children:[r.jsxs("div",{className:"model-dropdown__item-name",children:[r.jsx("span",{className:"model-dropdown__item-source-icon",children:r.jsx(Y,{vendor:m.vendor,size:16})}),r.jsxs("span",{className:"model-dropdown__item-code",children:["#",m.shortCode||m.id]}),r.jsx("span",{className:"model-dropdown__item-label",children:m.shortLabel||m.label}),F?r.jsx("span",{className:"model-dropdown__item-group-tag",children:re(m)}):null,((be=m.tags)==null?void 0:be.includes("new"))&&r.jsx("span",{className:"model-dropdown__item-new",children:"NEW"}),r.jsx(ie,{modelId:m.id,profileId:m.sourceProfileId||null}),r.jsx(fo,{modelId:m.id}),r.jsx(Eo,{model:m})]}),m.description?r.jsx("div",{className:"model-dropdown__item-desc",children:m.description}):r.jsx(jo,{model:m})]}),te&&r.jsx(io,{size:16,className:"model-dropdown__item-check"})]},ge)}):r.jsx("div",{className:"model-dropdown__empty",children:u==="zh"?"未找到匹配的模型":"No matching models"})})})})]});return r.jsxs("div",{className:`model-dropdown model-dropdown--variant-${d} ${c?"model-dropdown--disabled":""}`,ref:e,"data-testid":"model-selector",children:[$e(g),h&&(E?ao.createPortal(Z,document.body):Z),h?r.jsx(co,{state:Me,items:Ue,onClose:T}):null]})}})};export{bo as K,Mo as M,wo as u};
1
+ import{r as s,y as r,iO as Pe,iI as Oe,ls as Fe,lt as We,bL as Ze,iR as Ge,lu as Qe,l2 as qe,hb as Xe,j7 as Ye,iT as Ie,hv as Je,dp as Ke,al as Ce,iN as Ne,cV as eo,lv as oo,dM as ro,b7 as no,iK as so,bW as to,aI as ye,hj as io,hk as lo,bD as ao,j3 as co,bw as Ee}from"./tool-windows-C4D0lII2.js";import{g as J,a as uo,b as Y,D as po,V as mo,i as ie,j as fo,h as ho,f as _o}from"./use-runtime-models-BLwgp0M1.js";function wo({controlledValue:n,defaultValue:l,onChange:f}){const[_,u]=s.useState(l),p=n!==void 0,v=p?n:_,a=s.useCallback(c=>{const d=typeof c=="function"?c(v):c;p||u(d),f==null||f(d)},[p,v,f]);return{value:v,setValue:a}}function vo(n){return typeof n!="string"?null:n.trim()||null}function xo(n){var _;const l=(n==null?void 0:n.trim())||"";if(!l)return"供";const f=l.match(/[A-Za-z0-9]+/g);return f!=null&&f[0]?f[0][0].toUpperCase():((_=Array.from(l)[0])==null?void 0:_.toUpperCase())||"供"}const de=({vendor:n,profileName:l,iconUrl:f,size:_=18,className:u})=>{const p=s.useMemo(()=>vo(f),[f]),[v,a]=s.useState(p);s.useEffect(()=>{a(p)},[p]);const c=uo(n),d=l||J(n),M=!!(l||v),b={"--model-source-icon-size":`${_}px`,"--model-source-icon-accent":c.accent,"--model-source-icon-surface":c.surface,"--model-source-icon-border":c.border};return r.jsx("span",{className:`model-source-icon ${M?"model-source-icon--avatar":"model-source-icon--vendor"} ${u||""}`.trim(),style:b,"aria-hidden":"true",title:d,children:M?v?r.jsx("img",{src:v,alt:`${d} 图标`,className:"model-source-icon__image",loading:"lazy",onError:()=>a(null)}):r.jsx("span",{className:"model-source-icon__text",children:xo(d)}):r.jsx(Y,{vendor:n,size:Math.max(_-2,12)})})},go="ai-input-bar__input";function je(n){return n.isComposing||n.keyCode===229}const bo=({isOpen:n,setIsOpen:l,disabled:f=!1,openKeys:_=[],onOpenKey:u,trackPosition:p=!0,children:v})=>{const a=s.useRef(null),c=s.useRef(null),[d,M]=s.useState({top:0,left:0,width:0,bottom:0}),b=s.useCallback(x=>{if(!je(x.nativeEvent)){if(n){if(!u)return;u(x.key)&&x.preventDefault();return}_.includes(x.key)&&(x.preventDefault(),f||l(!0))}},[n,u,_,f,l]);return s.useEffect(()=>{if(!n||!u)return;const x=w=>{var h;if(je(w))return;const N=w.target,V=!!((h=N==null?void 0:N.classList)!=null&&h.contains(go));if(w.defaultPrevented&&!V)return;u(w.key)&&w.preventDefault()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[n,u]),s.useEffect(()=>{if(!n)return;const x=w=>{var V,A;const N=w.target;(V=a.current)!=null&&V.contains(N)||(A=c.current)!=null&&A.contains(N)||l(!1)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[n,l]),s.useLayoutEffect(()=>{if(!p||!n)return;const x=()=>{if(!a.current)return;const w=a.current.getBoundingClientRect();M({top:w.top,left:w.left,width:w.width,bottom:w.bottom})};return x(),window.addEventListener("resize",x),window.addEventListener("scroll",x,!0),()=>{window.removeEventListener("resize",x),window.removeEventListener("scroll",x,!0)}},[n,p]),r.jsx(r.Fragment,{children:v({isOpen:n,setIsOpen:l,containerRef:a,menuRef:c,portalPosition:d,handleTriggerKeyDown:b})})},O=Pe;function Io(n){return n.sourceProfileId?n.sourceProfileId:O}function Co(n,l){const f=new Map(l.map(a=>[a.id,a])),_=new Set,u=new Map;for(const a of n){const c=Io(a),d=`${c}::${a.type}::${a.id}`;if(_.has(d))continue;_.add(d);const M=u.get(c);M?M.push(a):u.set(c,[a])}const p=new Map(po.map((a,c)=>[a,c])),v=[];for(const[a,c]of u){const d=new Map;for(const w of c){const N=d.get(w.vendor);N?N.push(w):d.set(w.vendor,[w])}const M=Array.from(d.entries()).sort((w,N)=>(p.get(w[0])??999)-(p.get(N[0])??999)).map(([w,N])=>({vendor:w,label:J(w),models:Oe(N)})),b=f.get(a),x=a===O;v.push({providerId:a,providerName:x?(b==null?void 0:b.name)||We:(b==null?void 0:b.name)||a,providerIconUrl:x?(b==null?void 0:b.iconUrl)||Fe:b==null?void 0:b.iconUrl,vendorCategories:M,totalCount:c.length})}return v.sort((a,c)=>a.providerId===O?-1:c.providerId===O?1:a.providerName.localeCompare(c.providerName)),v}const No="aitu:settings:provider-nav";function le(n){return(n||"").toLowerCase().replace(/[\s\-_.:/]+/g,"").trim()}const Eo=ye.memo(({model:n})=>{const l=ho(n.sourceProfileId,n.id);return l?r.jsx("span",{className:"model-dropdown__item-price",children:l}):null}),jo=ye.memo(({model:n})=>{const l=_o(n.sourceProfileId,n.id);return l!=null&&l.description?r.jsx("div",{className:"model-dropdown__item-desc",children:l.description}):null});function L(n,l){const f=n.toLowerCase().trim(),_=l.toLowerCase().trim();if(!f||!_)return 0;const u=le(f),p=le(_);if(!p)return 0;if(f===_||u===p)return 120;if(f.startsWith(_)||u.startsWith(p))return 100;if(f.includes(_))return 80;if(u.includes(p))return 70;const v=_.split(/\s+/).filter(Boolean);if(v.length>1&&v.every(c=>{const d=le(c);return f.includes(c)||!!d&&u.includes(d)}))return 60;let a=0;for(const c of u)if(c===p[a]&&(a+=1,a===p.length))return 40;return 0}const Mo=({selectedModel:n,selectedSelectionKey:l,onSelect:f,onSelectModel:_,language:u="zh",models:p=qe,placement:v="up",header:a,disabled:c=!1,variant:d="minimal",placeholder:M,allowCustomValue:b=!0,isOpen:x,onOpenChange:w,providerProfilesOverride:N,showProviderAction:V=!0})=>{const{setAppState:A}=Ze(),{value:h,setValue:j}=wo({controlledValue:x,defaultValue:!1,onChange:w}),[P,y]=s.useState(""),[U,S]=s.useState(0),[R,G]=s.useState(null),[$,H]=s.useState(null),{contextMenu:Me,open:ae,close:T}=Ge(),K=s.useRef(null),ee=s.useRef(null),Q=s.useRef(null),De=Qe(),B=N||De,ce=s.useMemo(()=>new Map(B.map(e=>[e.id,e])),[B]),ue=s.useMemo(()=>new Map(p.map((e,o)=>[e.selectionKey||e.id,o])),[p]),q=s.useCallback(e=>e.selectionKey||e.id,[]),pe=s.useCallback(e=>e.sourceProfileId&&ce.get(e.sourceProfileId)||null,[ce]),I=s.useMemo(()=>Co(p,B),[p,B]),me=s.useMemo(()=>new Map(I.map(e=>[e.providerId,e.providerName])),[I]),oe=s.useMemo(()=>new Map(I.map(e=>[e.providerId,e.totalCount])),[I]),re=s.useCallback(e=>me.get(e.sourceProfileId||O)||e.sourceProfileName||J(e.vendor),[me]),k=s.useMemo(()=>I.find(e=>e.providerId===R)||I[0]||null,[I,R]),X=s.useMemo(()=>k&&(k.vendorCategories.find(e=>e.vendor===$)||k.vendorCategories[0])||null,[k,$]);s.useEffect(()=>{if(h&&Q.current){const e=Q.current.querySelector(`[data-model-index="${U}"]`);if(e){const o=Q.current,t=e.offsetTop,g=e.offsetHeight,E=o.scrollTop,Z=o.offsetHeight,m=4;U===0?o.scrollTop=0:t-m<E?o.scrollTop=t-m:t+g>E+Z&&(o.scrollTop=t+g-Z+m)}}},[U,h]);const i=p.find(e=>q(e)===(l||n))||Xe(n),C=s.useMemo(()=>i?pe(i):null,[i,pe]),Te=(i==null?void 0:i.shortCode)||"img",F=!!P.trim(),W=s.useMemo(()=>i!=null&&i.sourceProfileId?i.sourceProfileId:l!=null&&l.includes("::")?l.split("::")[0]:O,[i,l]),z=(i==null?void 0:i.vendor)??null;s.useEffect(()=>{d==="form"&&!h&&y((i==null?void 0:i.label)||n)},[n,i,d,h]);const fe=s.useMemo(()=>{const e=P.trim();return e?p.map(o=>{const t=Math.max(L(o.id,e),L(o.label,e),L(o.shortLabel||"",e),L(o.shortCode||"",e),L(o.description||"",e),L(re(o),e),L(J(o.vendor),e));return{model:o,score:t}}).filter(({score:o})=>o>0).sort((o,t)=>t.score-o.score||Ye(o.model,t.model,{fallbackOrderMap:ue})):[]},[re,p,P,ue]),he=s.useMemo(()=>fe.map(({model:e})=>e),[fe]),D=s.useMemo(()=>F?he:(X==null?void 0:X.models)||[],[F,he,X]),ke=s.useMemo(()=>I.map(e=>{var o,t;return{id:e.providerId,label:e.providerName,count:e.totalCount,icon:e.providerIconUrl?r.jsx(de,{vendor:((o=e.vendorCategories[0])==null?void 0:o.vendor)||"OTHER",profileName:e.providerName,iconUrl:e.providerIconUrl,size:16}):r.jsx(Y,{vendor:((t=e.vendorCategories[0])==null?void 0:t.vendor)||"OTHER",size:16})}}),[I]),ze=s.useMemo(()=>((k==null?void 0:k.vendorCategories)||[]).map(e=>({id:e.vendor,label:e.label,count:e.models.length,icon:r.jsx(Y,{vendor:e.vendor,size:14})})),[k]),Re=s.useCallback(e=>{var t;G(e),y("");const o=I.find(g=>g.providerId===e);H(((t=o==null?void 0:o.vendorCategories[0])==null?void 0:t.vendor)??null),S(0)},[I]),Le=s.useCallback(e=>{H(e),S(0)},[]),Ve=s.useCallback((e,o)=>{e.preventDefault(),e.stopPropagation(),ae(e,{modelId:o})},[ae]),Ae=s.useCallback(()=>{const e=B.filter(E=>E.id!==Pe),o=e[e.length-1]||null,t=o&&oe.get(o.id)||0,g=o&&t===0?{action:"select",profileId:o.id}:e.some(E=>E.id===Ie&&(oe.get(E.id)||0)===0)?{action:"select",profileId:Ie}:{action:"create"};window.__aituPendingProviderNavigationIntent=g,window.dispatchEvent(new CustomEvent(No,{detail:g})),j(!1),A(E=>({...E,openSettings:!0}))},[B,oe,A,j]);s.useEffect(()=>{const e=l||n,o=D.findIndex(t=>q(t)===e);S(o>=0?o:0)},[D,n,l,q]),s.useEffect(()=>{var o;if(F)return;if(!R||!I.some(t=>t.providerId===R)){const t=I.find(g=>g.providerId===W);if(G((t==null?void 0:t.providerId)||((o=I[0])==null?void 0:o.providerId)||null),z){H(z);return}}const e=I.find(t=>t.providerId===R)||I[0]||null;if(e){const t=e.vendorCategories.map(g=>g.vendor);(!$||!t.includes($))&&H(t[0]??null)}},[I,R,$,F,W,z]),s.useEffect(()=>{h||T()},[h,T]);const _e=s.useCallback(e=>{if(e==null||e.preventDefault(),c)return;const o=!h;o&&(G(W),z&&H(z)),o?y(""):d==="form"&&y((i==null?void 0:i.label)||n),j(o)},[c,h,j,d,i,n,W,z]),ne=s.useCallback(e=>{T(),f(e.id,Je(e.sourceProfileId||null,e.id)),_==null||_(e),j(!1),y(d==="form"?e.label||e.id:"")},[T,f,_,j,d]),we=s.useCallback(async e=>{try{await Ke(e),Ce.success(u==="zh"?"模型名已复制":"Model name copied"),T()}catch(o){console.error("[ModelDropdown] failed to copy model id",o),Ce.error(u==="zh"?"复制失败":"Copy failed")}},[T,u]),ve=s.useCallback(e=>{var t;const o=p.find(g=>g.id===e);return(t=Ne.getModelPrice(o==null?void 0:o.sourceProfileId,e))==null?void 0:t.docsUrl},[p]),xe=s.useCallback(e=>{var t;const o=p.find(g=>g.id===e);if(o!=null&&o.description)return o.description;if(o!=null&&o.sourceProfileId)return(t=Ne.getModelPrice(o.sourceProfileId,e))==null?void 0:t.description},[p]),Ue=s.useCallback(({modelId:e})=>{const o=xe(e),t=[{key:"model-id",label:e,disabled:!0}];o&&t.push({key:"model-desc",label:r.jsx("span",{style:{fontSize:11,color:"var(--td-text-color-secondary)",whiteSpace:"normal",lineHeight:1.4,display:"block",maxWidth:260},children:o.length>80?o.slice(0,80)+"…":o}),disabled:!0}),t.push({key:"divider-1",type:"divider"},{key:"copy-model-id",label:u==="zh"?"复制模型名":"Copy model name",icon:r.jsx(eo,{size:14}),onSelect:({modelId:E})=>we(E)});const g=ve(e);return g&&t.push({key:"open-docs",label:u==="zh"?"查看模型文档":"View model docs",icon:r.jsx(oo,{size:14}),onSelect:()=>window.open(g,"_blank","noopener")}),t},[xe,ve,we,u]),Se=s.useCallback(e=>{if(e==="Escape")return j(!1),d==="form"&&y((i==null?void 0:i.label)||n),!0;if(e==="ArrowDown")return D.length>0&&S(o=>o<D.length-1?o+1:0),!0;if(e==="ArrowUp")return D.length>0&&S(o=>o>0?o-1:D.length-1),!0;if(e==="Enter"||e==="Tab"){const o=D[U];if(o)return ne(o),!0;if(d==="form"&&b&&P.trim())return f(P.trim()),j(!1),!0}return!1},[D,U,ne,d,b,i,f,P,n,j]);s.useEffect(()=>{var e,o;h&&d==="form"&&((e=K.current)==null||e.focus(),(o=K.current)==null||o.select())},[h,d]),s.useEffect(()=>{var e;h&&d==="minimal"&&((e=ee.current)==null||e.focus())},[h,d]),s.useEffect(()=>{!h&&d==="minimal"&&P&&y("")},[h,P,d]);const $e=e=>d==="minimal"?r.jsxs("button",{className:`model-dropdown__trigger model-dropdown__trigger--minimal ${h?"model-dropdown__trigger--open":""}`,onMouseDown:_e,onKeyDown:e,type:"button","aria-haspopup":"listbox","aria-expanded":h,"aria-label":`${(i==null?void 0:i.shortLabel)||(i==null?void 0:i.label)||n} (↑↓ Tab)`,disabled:c,children:[i?r.jsx(de,{vendor:i.vendor,profileName:(C==null?void 0:C.name)||i.sourceProfileName,iconUrl:C==null?void 0:C.iconUrl,size:15,className:"model-dropdown__trigger-source-icon"}):null,r.jsx("span",{className:"model-dropdown__at",children:"#"}),r.jsx("span",{className:"model-dropdown__code",children:Te}),r.jsx(ie,{modelId:n,profileId:(C==null?void 0:C.id)||(i==null?void 0:i.sourceProfileId)||null}),r.jsx(Ee,{size:14,className:`model-dropdown__chevron ${h?"model-dropdown__chevron--open":""}`})]}):r.jsxs("div",{className:`model-dropdown__trigger model-dropdown__trigger--form ${h?"model-dropdown__trigger--open":""}`,onMouseDown:o=>{o.preventDefault(),h||(j(!0),y(""),G(W),z&&H(z))},children:[r.jsxs("div",{className:"model-dropdown__form-content",children:[i?r.jsx(de,{vendor:i.vendor,profileName:(C==null?void 0:C.name)||i.sourceProfileName,iconUrl:C==null?void 0:C.iconUrl,size:18,className:"model-dropdown__trigger-source-icon"}):null,r.jsx("input",{ref:K,type:"text",className:"model-dropdown__form-input",value:P,onChange:o=>{y(o.target.value),h||j(!0)},placeholder:M||(u==="zh"?"选择或输入模型":"Select or enter model"),disabled:c}),r.jsx(ie,{modelId:n,profileId:(C==null?void 0:C.id)||(i==null?void 0:i.sourceProfileId)||null})]}),r.jsx(Ee,{size:16,className:`model-dropdown__chevron ${h?"model-dropdown__chevron--open":""}`,onMouseDown:o=>{o.preventDefault(),o.stopPropagation(),_e()}})]});return r.jsx(bo,{isOpen:h,setIsOpen:j,disabled:c,openKeys:["Enter"," "],onOpenKey:Se,trackPosition:d==="form"||v==="down"||v==="up",children:({containerRef:e,menuRef:o,portalPosition:t,handleTriggerKeyDown:g})=>{const E=d==="form"||v==="down"||v==="up",Z=r.jsxs("div",{className:`model-dropdown__menu model-dropdown__menu--${v} ${d==="form"?"model-dropdown__menu--form":""} ${E?"model-dropdown__menu--portalled":""} ${no}`,ref:o,role:"listbox","aria-label":u==="zh"?"选择模型":"Select Model",onMouseDown:m=>m.stopPropagation(),onClick:m=>m.stopPropagation(),style:E?{position:"fixed",zIndex:ro.DROPDOWN_PORTAL,left:t.left,width:d==="form"?Math.max(t.width,I.length>1?620:520):"auto",top:v==="down"?t.bottom+4:"auto",bottom:v==="up"?window.innerHeight-t.top+4:"auto",visibility:t.width===0?"hidden":"visible"}:{zIndex:1e3},children:[d==="minimal"?r.jsxs("div",{className:"model-dropdown__toolbar",children:[a?r.jsx("div",{className:"model-dropdown__toolbar-title",children:a}):null,r.jsx("div",{className:"model-dropdown__search",children:r.jsxs("div",{className:"model-dropdown__search-input-wrapper",children:[r.jsx(so,{className:"model-dropdown__search-icon"}),r.jsx("input",{ref:ee,type:"text",className:"model-dropdown__search-input",value:P,onChange:m=>y(m.target.value),placeholder:u==="zh"?"搜索模型名 / 展示名 / 供应商":"Search model id / label / provider"}),P?r.jsx("button",{type:"button",className:"model-dropdown__search-clear",onClick:()=>{var m;y(""),(m=ee.current)==null||m.focus()},"aria-label":u==="zh"?"清空搜索":"Clear search",children:r.jsx(to,{size:14})}):null]})})]}):a?r.jsx("div",{className:"model-dropdown__header",children:a}):null,r.jsx(mo,{tabs:ke,activeTab:R,onTabChange:Re,middleTabs:ze,activeMiddleTab:$,onMiddleTabChange:Le,searchQuery:P,compact:!0,tabsFooter:V?r.jsx("button",{type:"button",className:"model-dropdown__provider-action",onClick:Ae,"aria-label":u==="zh"?"新增供应商或打开供应商设置":"Add provider or open provider settings",children:r.jsx(lo,{size:16})}):null,children:r.jsx("div",{className:"model-dropdown__list-pane",children:r.jsx("div",{className:"model-dropdown__list",ref:Q,onScroll:T,children:D.length>0?D.map((m,se)=>{var be;const ge=q(m),te=ge===(l||n),He=se===U;return r.jsxs("div",{"data-model-index":se,className:`model-dropdown__item ${te?"model-dropdown__item--selected":""} ${He?"model-dropdown__item--highlighted":""}`,onClick:()=>ne(m),onMouseEnter:()=>{S(se)},onContextMenu:Be=>Ve(Be,m.id),role:"option","aria-selected":te,children:[r.jsxs("div",{className:"model-dropdown__item-content",children:[r.jsxs("div",{className:"model-dropdown__item-name",children:[r.jsx("span",{className:"model-dropdown__item-source-icon",children:r.jsx(Y,{vendor:m.vendor,size:16})}),r.jsxs("span",{className:"model-dropdown__item-code",children:["#",m.shortCode||m.id]}),r.jsx("span",{className:"model-dropdown__item-label",children:m.shortLabel||m.label}),F?r.jsx("span",{className:"model-dropdown__item-group-tag",children:re(m)}):null,((be=m.tags)==null?void 0:be.includes("new"))&&r.jsx("span",{className:"model-dropdown__item-new",children:"NEW"}),r.jsx(ie,{modelId:m.id,profileId:m.sourceProfileId||null}),r.jsx(fo,{modelId:m.id}),r.jsx(Eo,{model:m})]}),m.description?r.jsx("div",{className:"model-dropdown__item-desc",children:m.description}):r.jsx(jo,{model:m})]}),te&&r.jsx(io,{size:16,className:"model-dropdown__item-check"})]},ge)}):r.jsx("div",{className:"model-dropdown__empty",children:u==="zh"?"未找到匹配的模型":"No matching models"})})})})]});return r.jsxs("div",{className:`model-dropdown model-dropdown--variant-${d} ${c?"model-dropdown--disabled":""}`,ref:e,"data-testid":"model-selector",children:[$e(g),h&&(E?ao.createPortal(Z,document.body):Z),h?r.jsx(co,{state:Me,items:Ue,onClose:T}):null]})}})};export{bo as K,Mo as M,wo as u};
@@ -1 +1 @@
1
- import{nm as g,lH as M,nc as G,nn as D,no as S,np as R,h1 as h,nq as I,nr as w,ns as x,nt as b,nu as v,nv as P,nw as B,nx as F,n9 as U,n7 as A}from"./tool-windows-hjm6YiPY.js";function z(t){return B(t,"musicAnalyzerAction",["analyze","rewrite","lyrics-gen"])}function V(t){return F(t,{missingMessage:"分析任务缺少结果内容",fromStructured:r=>U(r)})}function H(t){const r=t.params.musicAnalyzerSourceSnapshot;return(r==null?void 0:r.type)==="upload"?r:null}function L(t){var i;const r=(i=t.result)==null?void 0:i.analysisData;return!r||typeof r!="object"||typeof r.lyricsDraft!="string"&&typeof r.title!="string"&&!Array.isArray(r.styleTags)?null:{title:String(r.title||"").trim(),styleTags:Array.isArray(r.styleTags)?r.styleTags.map(u=>String(u||"").trim()).filter(Boolean):[],lyricsDraft:String(r.lyricsDraft||"").trim()}}async function j(t){if(t.status!=="completed")return null;const r=z(t);if(!r)return null;if(r==="analyze"){const l=await g(),p=l.find(m=>m.analyzeTaskId===t.id);if(p)return{records:l,record:p};const e=V(t),n=H(t),c=String(t.params.musicAnalyzerSourceLabel||(n==null?void 0:n.fileName)||"本地音频").trim(),o={id:M(),createdAt:Date.now(),source:"upload",sourceLabel:c,sourceSnapshot:n,analysisModel:String(t.params.model||""),analysisModelRef:t.params.modelRef||null,analysis:e,styleTags:e.sunoStyleTags.length>0?e.sunoStyleTags:e.genreTags,title:e.sunoTitle||e.titleSuggestions[0]||c.replace(/\.[^.]+$/,""),lyricsDraft:e.sunoLyricsDraft||"",analyzeTaskId:t.id,starred:!1};return{records:await G(o),record:o}}if(r==="lyrics-gen"){const l=D(t,"musicAnalyzerRecordId");if(!l)return null;const e=(await g()).find(C=>C.id===l);if(!e||e.pendingLyricsGenTaskId!==t.id)return null;const n=O(t),c=(n==null?void 0:n.title)||e.title||"",o=n&&n.styleTags.length>0?n.styleTags:e.styleTags||[],d=(n==null?void 0:n.lyricsDraft)||e.lyricsDraft||"",m=n?S({...e,title:c,styleTags:o,lyricsDraft:d},R({...e,title:c,styleTags:o,lyricsDraft:d},t.type===h.CHAT?"AI 草稿":"Suno 歌词",e.creationPrompt)):{};return I(e,{title:c,styleTags:o,lyricsDraft:d,...m,pendingLyricsGenTaskId:null},A)}const i=D(t,"musicAnalyzerRecordId");if(!i)return null;const s=(await g()).find(l=>l.id===i);if(!s||s.pendingRewriteTaskId!==t.id)return null;const a=L(t)||w(x(t)),y=(s.lyricsVersions||[]).length,f=R({...s,title:a.title||s.title,styleTags:a.styleTags.length>0?a.styleTags:s.styleTags,lyricsDraft:a.lyricsDraft||s.lyricsDraft},`AI 改写 #${y+1}`,s.rewritePrompt),T=S(s,f);return I(s,{title:a.title||s.title,styleTags:a.styleTags.length>0?a.styleTags:s.styleTags,lyricsDraft:a.lyricsDraft||s.lyricsDraft,pendingRewriteTaskId:null,...T},A)}function O(t){const r=t.result;if(!r)return null;const i=L(t);if(i)return i;const u=x(t);if(u)try{return w(u)}catch{}const s=r.lyricsText||"",a=r.lyricsTitle||r.title||"",y=r.lyricsTags;if(!s&&!a)return null;const f=Array.isArray(y)?y.map(T=>String(T||"").trim()).filter(Boolean):[];return{title:String(a).trim(),styleTags:f,lyricsDraft:String(s).trim()}}function q(t){return P(t)}async function J(t,r){return v(t,r,{loadRecords:g,updateRecord:A})}function N(t){return z(t)!==null}function W(t){if(t.type!==h.AUDIO)return null;const r=t.params.batchId;return r?b(r,{prefix:"ma_"}):null}export{J as a,q as e,W as g,N as i,j as s};
1
+ import{nm as g,lH as M,nc as G,nn as D,no as S,np as R,h1 as h,nq as I,nr as w,ns as x,nt as b,nu as v,nv as P,nw as B,nx as F,n9 as U,n7 as A}from"./tool-windows-C4D0lII2.js";function z(t){return B(t,"musicAnalyzerAction",["analyze","rewrite","lyrics-gen"])}function V(t){return F(t,{missingMessage:"分析任务缺少结果内容",fromStructured:r=>U(r)})}function H(t){const r=t.params.musicAnalyzerSourceSnapshot;return(r==null?void 0:r.type)==="upload"?r:null}function L(t){var i;const r=(i=t.result)==null?void 0:i.analysisData;return!r||typeof r!="object"||typeof r.lyricsDraft!="string"&&typeof r.title!="string"&&!Array.isArray(r.styleTags)?null:{title:String(r.title||"").trim(),styleTags:Array.isArray(r.styleTags)?r.styleTags.map(u=>String(u||"").trim()).filter(Boolean):[],lyricsDraft:String(r.lyricsDraft||"").trim()}}async function j(t){if(t.status!=="completed")return null;const r=z(t);if(!r)return null;if(r==="analyze"){const l=await g(),p=l.find(m=>m.analyzeTaskId===t.id);if(p)return{records:l,record:p};const e=V(t),n=H(t),c=String(t.params.musicAnalyzerSourceLabel||(n==null?void 0:n.fileName)||"本地音频").trim(),o={id:M(),createdAt:Date.now(),source:"upload",sourceLabel:c,sourceSnapshot:n,analysisModel:String(t.params.model||""),analysisModelRef:t.params.modelRef||null,analysis:e,styleTags:e.sunoStyleTags.length>0?e.sunoStyleTags:e.genreTags,title:e.sunoTitle||e.titleSuggestions[0]||c.replace(/\.[^.]+$/,""),lyricsDraft:e.sunoLyricsDraft||"",analyzeTaskId:t.id,starred:!1};return{records:await G(o),record:o}}if(r==="lyrics-gen"){const l=D(t,"musicAnalyzerRecordId");if(!l)return null;const e=(await g()).find(C=>C.id===l);if(!e||e.pendingLyricsGenTaskId!==t.id)return null;const n=O(t),c=(n==null?void 0:n.title)||e.title||"",o=n&&n.styleTags.length>0?n.styleTags:e.styleTags||[],d=(n==null?void 0:n.lyricsDraft)||e.lyricsDraft||"",m=n?S({...e,title:c,styleTags:o,lyricsDraft:d},R({...e,title:c,styleTags:o,lyricsDraft:d},t.type===h.CHAT?"AI 草稿":"Suno 歌词",e.creationPrompt)):{};return I(e,{title:c,styleTags:o,lyricsDraft:d,...m,pendingLyricsGenTaskId:null},A)}const i=D(t,"musicAnalyzerRecordId");if(!i)return null;const s=(await g()).find(l=>l.id===i);if(!s||s.pendingRewriteTaskId!==t.id)return null;const a=L(t)||w(x(t)),y=(s.lyricsVersions||[]).length,f=R({...s,title:a.title||s.title,styleTags:a.styleTags.length>0?a.styleTags:s.styleTags,lyricsDraft:a.lyricsDraft||s.lyricsDraft},`AI 改写 #${y+1}`,s.rewritePrompt),T=S(s,f);return I(s,{title:a.title||s.title,styleTags:a.styleTags.length>0?a.styleTags:s.styleTags,lyricsDraft:a.lyricsDraft||s.lyricsDraft,pendingRewriteTaskId:null,...T},A)}function O(t){const r=t.result;if(!r)return null;const i=L(t);if(i)return i;const u=x(t);if(u)try{return w(u)}catch{}const s=r.lyricsText||"",a=r.lyricsTitle||r.title||"",y=r.lyricsTags;if(!s&&!a)return null;const f=Array.isArray(y)?y.map(T=>String(T||"").trim()).filter(Boolean):[];return{title:String(a).trim(),styleTags:f,lyricsDraft:String(s).trim()}}function q(t){return P(t)}async function J(t,r){return v(t,r,{loadRecords:g,updateRecord:A})}function N(t){return z(t)!==null}function W(t){if(t.type!==h.AUDIO)return null;const r=t.params.batchId;return r?b(r,{prefix:"ma_"}):null}export{J as a,q as e,W as g,N as i,j as s};
@@ -1,4 +1,4 @@
1
- import{y as e,aI as He,at as Ge,r as a,n5 as ie,n6 as pe,n7 as ae,n8 as Fe,n9 as Me,g$ as G,lq as Ye,h1 as V,lH as qe,na as Ue,nb as Be,nc as We,nd as Qe,hf as fe,ne as we,nf as Ee,ng as Je,nh as Re,hz as Xe,ib as Ze,ni as ge,nj as es,nk as ss,nl as as,i$ as ts,fP as ns,h0 as te,bV as ls,nm as is}from"./tool-windows-hjm6YiPY.js";import{M as ye}from"./ModelDropdown-3MjTl1AO.js";import{u as he}from"./use-runtime-models-C0uyCfar.js";import{a as je}from"./model-selection-BaH65gMK.js";import{quickInsert as Ve}from"./canvas-insertion-ZEZkcXvB.js";import{s as Ce,i as rs,g as cs,a as os}from"./MusicAnalyzer-Mmu92A4Y.js";/* empty css */import"./model-benchmark-service-DDklUBjC.js";const De=[{id:"create",label:"创作"},{id:"lyrics",label:"歌词"},{id:"generate",label:"生成"}],ds=({current:s,onNavigate:n,hasRecord:i})=>{const b=De.findIndex(o=>o.id===s);return e.jsx("div",{className:"va-step-bar",children:De.map((o,x)=>{const y=o.id===s,S=x<b,j=!i&&x>0;return e.jsxs(He.Fragment,{children:[x>0&&e.jsx("span",{className:"va-step-arrow",children:"→"}),e.jsxs("button",{className:`va-step ${y?"active":""} ${S?"past":""}`,onClick:()=>!j&&n(o.id),disabled:j,children:[e.jsx("span",{className:"va-step-num",children:x+1}),o.label]})]},o.id)})})};function ze(s){return(s||"").trim().toLowerCase().replace(/[^a-z0-9]/g,"")||"mp3"}function us(s){const n=s.name.split(".").pop();return n&&n.length<=8?ze(n):ze(s.type.split("/")[1])}async function ms(s,n){const i=us(s),o=`/__aitu_cache__/audio/${`music-analyzer-source-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}.${i}`;return await Ge.cacheMediaFromBlob(o,s,"audio",{metadata:{source:"music-analyzer-input",fileName:s.name,mimeType:s.type||"audio/mpeg",size:s.size}}),{type:"upload",cacheUrl:o,fileName:s.name||`music-source.${i}`,mimeType:s.type||"audio/mpeg",size:s.size}}async function hs(s){if(!s||s.type!=="upload")return null;const n=await Ge.getCachedBlob(s.cacheUrl);return n?new File([n],s.fileName||"music-source.mp3",{type:s.mimeType||n.type||"audio/mpeg",lastModified:Date.now()}):null}const xe="gemini-2.5-pro",Ne="music-analyzer:model",be="music-analyzer:lyrics-model",ke="music-analyzer:creation-prompt";function ps(s){return`${(s/1024/1024).toFixed(1)}MB`}function fs(){try{return sessionStorage.getItem(ke)||""}catch{return""}}function $e(s){try{if(s){sessionStorage.setItem(ke,s);return}sessionStorage.removeItem(ke)}catch{}}const ys=({existingRecord:s,onComplete:n,onRecordsChange:i,onCreateNew:b,onNext:o,onLyricsReady:x})=>{const[y,S]=a.useState((s==null?void 0:s.source)==="upload"?"reference":"scratch"),[j,D]=a.useState(()=>(s==null?void 0:s.creationPrompt)||fs()),[A,L]=a.useState(()=>(s==null?void 0:s.pendingLyricsGenTaskId)||null),[I,z]=a.useState(""),[h,C]=a.useState(null),[c,f]=a.useState(null),[d,N]=a.useState(""),[u,p]=a.useState(!0),[K,Z]=a.useState(""),[F,re]=a.useState(""),[H,ne]=a.useState(""),le=a.useRef(null),_=a.useRef(null),J=a.useRef(),[T,k]=a.useState(""),[U,oe]=a.useState(()=>(s==null?void 0:s.analysisModel)||ie(Ne,xe).modelId),[ee,ce]=a.useState(()=>(s==null?void 0:s.analysisModelRef)||ie(Ne,xe).modelRef),[M,R]=a.useState(()=>ie(be,fe()).modelId),[Y,$]=a.useState(()=>ie(be,fe()).modelRef),r=a.useCallback((l,v)=>{oe(l),ce(v||null),pe(Ne,l,v)},[]),g=a.useCallback((l,v)=>{R(l),$(v||null),pe(be,l,v)},[]),w=a.useMemo(()=>{if(_.current&&URL.revokeObjectURL(_.current),!h)return _.current=null,null;const l=URL.createObjectURL(h);return _.current=l,l},[h]);a.useEffect(()=>()=>{_.current&&URL.revokeObjectURL(_.current)},[]),a.useEffect(()=>{let l=!1;return(async()=>{if(!s){!c&&!A&&(C(null),k(""));return}oe(s.analysisModel||xe),ce(s.analysisModelRef||null),D(s.creationPrompt||"");const m=s.analysis?Me(s.analysis):null;if(Z(s.title||(m==null?void 0:m.sunoTitle)||""),re((s.styleTags||(m==null?void 0:m.sunoStyleTags)||(m==null?void 0:m.genreTags)||[]).join(", ")),ne(s.lyricsDraft||(m==null?void 0:m.sunoLyricsDraft)||""),k(""),s.source==="upload"){const P=await hs(s.sourceSnapshot);if(l)return;C(P),P||k("原上传音频缓存已失效,无法自动回填音频")}})(),()=>{l=!0}},[s,c,A]),a.useEffect(()=>{if((s==null?void 0:s.source)==="scratch"){$e(s.creationPrompt||"");return}s||$e(j)},[j,s]),a.useEffect(()=>{if(!(!s||y!=="reference"))return clearTimeout(J.current),J.current=setTimeout(async()=>{const l=F.split(",").map(P=>P.trim()).filter(Boolean),v=await ae(s.id,{title:K.trim(),styleTags:l,lyricsDraft:H});i(v);const m=v.find(P=>P.id===s.id);m&&n(m)},400),()=>clearTimeout(J.current)},[H,F,K,s,y,n,i]);const W=he("text"),B=a.useMemo(()=>W.filter(l=>/^gemini/i.test(l.id)),[W]),t=he("audio"),O=a.useMemo(()=>Fe(W,t),[W,t]),E=a.useMemo(()=>s!=null&&s.analysis?Me(s.analysis):null,[s==null?void 0:s.analysis]),se=a.useCallback(l=>{var m;const v=(m=l.target.files)==null?void 0:m[0];v!=null&&v.type.startsWith("audio/")?(C(v),k("")):k("请选择音频文件")},[]),q=a.useCallback(l=>{l.preventDefault();const v=l.dataTransfer.files[0];v!=null&&v.type.startsWith("audio/")?(C(v),k("")):k("请选择音频文件")},[]),Q=a.useCallback(async()=>{if(!h){k("请先上传音频");return}k(""),N("缓存音频...");try{const l=await ms(h),v=G.createTask({prompt:`分析音频:${h.name||"本地音频"}`,model:U,modelRef:ee,mimeType:l.mimeType,audioCacheUrl:l.cacheUrl,musicAnalyzerAction:"analyze",musicAnalyzerPrompt:Ye,musicAnalyzerSource:"upload",musicAnalyzerSourceLabel:l.fileName,musicAnalyzerSourceSnapshot:l,autoInsertToCanvas:!1},V.CHAT);f(v.id),N("音频分析中 0%")}catch(l){k(l.message||"音频分析失败")}},[h,U,ee]),de=a.useCallback(async()=>{if(!j.trim()){k("请先描述你想创作的歌曲");return}const l=Ue(M);k(""),z(l?"歌词生成中...":"歌词草稿生成中 0%");try{const v={id:qe(),createdAt:Date.now(),source:"scratch",sourceLabel:j.slice(0,30)||"从零创作",creationPrompt:j,starred:!1},m=l?G.createTask({prompt:j,model:M,modelRef:Y,sunoAction:"lyrics",musicAnalyzerAction:"lyrics-gen",musicAnalyzerRecordId:v.id,autoInsertToCanvas:!1},V.AUDIO):G.createTask({prompt:`从零创作歌词:${v.sourceLabel}`,model:M,modelRef:Y,musicAnalyzerAction:"lyrics-gen",musicAnalyzerPrompt:Be({userPrompt:j,mode:"create"}),musicAnalyzerRecordId:v.id,autoInsertToCanvas:!1},V.CHAT);v.pendingLyricsGenTaskId=m.id;const P=await We(v);i(P),n(v),L(m.id)}catch(v){k(v.message||"歌词生成失败"),z("")}},[j,n,i,M,Y]);a.useEffect(()=>{if(!c)return;const l=G.getTask(c);typeof(l==null?void 0:l.progress)=="number"&&N(`音频分析中 ${Math.round(l.progress)}%`);const v=G.observeTaskUpdates().subscribe(m=>{var P;if(m.task.id===c){if(m.task.status==="failed"){f(null),N(""),k(((P=m.task.error)==null?void 0:P.message)||"音频分析失败");return}if(m.task.status==="completed"){Ce(m.task).then(X=>{X&&(i(X.records),n(X.record))}).catch(X=>k(X.message||"分析结果同步失败")).finally(()=>{f(null),N("")});return}typeof m.task.progress=="number"&&N(`音频分析中 ${Math.round(m.task.progress)}%`)}});return()=>v.unsubscribe()},[c,n,i]),a.useEffect(()=>{if(!A)return;const l=G.getTask(A);if(typeof(l==null?void 0:l.progress)=="number"){const m=l.type===V.CHAT?"歌词草稿生成中":"歌词生成中";z(`${m} ${Math.round(l.progress)}%`)}const v=G.observeTaskUpdates().subscribe(m=>{var P;if(m.task.id===A){if(m.task.status==="failed"){const X=String(m.task.params.musicAnalyzerRecordId||"").trim();L(null),z(""),k(((P=m.task.error)==null?void 0:P.message)||"歌词生成失败"),X&&ae(X,{pendingLyricsGenTaskId:null}).then(i);return}if(m.task.status==="completed"){L(null),z(""),x==null||x();return}if(typeof m.task.progress=="number"){const X=m.task.type===V.CHAT?"歌词草稿生成中":"歌词生成中";z(`${X} ${Math.round(m.task.progress)}%`)}}});return()=>v.unsubscribe()},[x,i,A]);const ve=a.useCallback(async()=>{E&&await Ve("text",Qe(E))},[E]);return e.jsxs("div",{className:"ma-create-page",children:[e.jsxs("div",{className:"ma-mode-toggle",children:[e.jsx("button",{className:`ma-mode-btn ${y==="scratch"?"active":""}`,onClick:()=>S("scratch"),children:"从零创作"}),e.jsx("button",{className:`ma-mode-btn ${y==="reference"?"active":""}`,onClick:()=>S("reference"),children:"参考音频"})]}),e.jsxs("div",{className:"va-page",children:[y==="scratch"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"歌词草稿模型"}),e.jsx("span",{className:"ma-muted",children:"文本模型会补齐 Suno 所需标题/标签/歌词"})]}),e.jsx(ye,{selectedModel:M,selectedSelectionKey:je(M,Y),onSelect:g,models:O,variant:"form",placement:"down",placeholder:"选择歌词草稿模型"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"描述你想创作的歌曲"})}),e.jsx("textarea",{className:"ma-textarea",value:j,onChange:l=>D(l.target.value),rows:6,placeholder:"例如:一首关于夏天海边的轻快流行歌,女声,带有吉他和电子节拍"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"上传音频"}),h&&e.jsx("span",{className:"ma-muted",children:ps(h.size)})]}),e.jsx("div",{className:"va-dropzone ma-dropzone",onClick:()=>{var l;return(l=le.current)==null?void 0:l.click()},onDragOver:l=>l.preventDefault(),onDrop:q,children:h?e.jsxs("div",{className:"ma-audio-preview",children:[e.jsxs("div",{className:"ma-audio-preview__meta",children:[e.jsx("strong",{children:h.name}),e.jsx("button",{className:"va-nav-btn",onClick:l=>{l.stopPropagation(),C(null),k(""),le.current&&(le.current.value="")},children:"清空"})]}),w&&e.jsx("audio",{controls:!0,src:w})]}):e.jsxs("div",{className:"ma-dropzone__placeholder",children:[e.jsx("span",{children:"点击或拖拽上传本地音频"}),e.jsx("small",{children:"支持 mp3、wav、m4a 等常见格式"})]})}),e.jsx("input",{ref:le,type:"file",accept:"audio/*",hidden:!0,onChange:se})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"分析模型"})}),e.jsx(ye,{selectedModel:U,selectedSelectionKey:je(U,ee),onSelect:r,models:B,variant:"form",placement:"down",placeholder:"选择 Gemini 分析模型"})]})]}),E&&y==="reference"&&e.jsxs("div",{className:"ma-card",children:[e.jsxs("button",{className:"ma-section-toggle",onClick:()=>p(l=>!l),children:[e.jsx("span",{children:"分析摘要"}),e.jsx("span",{children:u?"收起":"展开"})]}),u&&e.jsxs("div",{className:"ma-analysis-summary",children:[e.jsx("p",{children:E.summary}),e.jsxs("div",{className:"ma-chip-row",children:[e.jsx("span",{className:"ma-chip",children:E.language||"未知语言"}),e.jsx("span",{className:"ma-chip",children:E.mood||"未知情绪"}),E.genreTags.map(l=>e.jsx("span",{className:"ma-chip ma-chip--accent",children:l},l))]}),e.jsx("div",{className:"ma-tag-row",children:E.structure.map(l=>e.jsx("code",{children:l},l))}),E.titleSuggestions.length>0&&e.jsxs("div",{className:"ma-suggestions",children:["推荐标题:",E.titleSuggestions.join(" / ")]}),(E.sunoTitle||E.sunoStyleTags.length>0||E.sunoLyricsDraft)&&e.jsxs("div",{className:"ma-suno-summary",children:[e.jsx("div",{className:"ma-suno-summary__title",children:"Suno 生成草稿"}),e.jsxs("div",{className:"ma-suno-summary__form",children:[e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"歌曲标题"}),e.jsx("input",{className:"ma-input",value:K,onChange:l=>Z(l.target.value),placeholder:"可直接用于 Suno 的标题"})]}),e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"Suno 风格标签"}),e.jsx("input",{className:"ma-input",value:F,onChange:l=>re(l.target.value),placeholder:"逗号分隔的风格标签"})]}),e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"带 Suno 标签的歌词草稿"}),e.jsx("textarea",{className:"ma-textarea",rows:12,value:H,onChange:l=>ne(l.target.value),placeholder:"分析阶段整理出的可用歌词草稿"})]})]})]})]})]}),(T||d||I)&&e.jsxs("div",{className:"ma-status-stack",children:[T&&e.jsx("div",{className:"ma-error",children:T}),d&&e.jsx("div",{className:"ma-progress",children:d}),I&&e.jsx("div",{className:"ma-progress",children:I})]}),e.jsx("div",{className:"va-page-actions",children:y==="scratch"?e.jsx("button",{className:"va-btn-primary",onClick:de,disabled:!j.trim()||!!A,children:"生成歌词"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:b,children:"新建"}),e.jsx("button",{onClick:ve,disabled:!(s!=null&&s.analysis),children:"插入分析"}),e.jsx("button",{className:"va-btn-primary",onClick:Q,disabled:!h||!!c,children:"开始分析"}),e.jsx("button",{onClick:o,disabled:!s,children:"下一步"})]})})]})]})},Se="music-analyzer:model",Pe="gemini-2.5-pro",js=({record:s,onRecordUpdate:n,onRecordsChange:i,onNext:b})=>{var M,R,Y,$;const[o,x]=a.useState(()=>we(s)),[y,S]=a.useState(s.lyricsDraft||""),[j,D]=a.useState(s.title||((R=(M=s.analysis)==null?void 0:M.titleSuggestions)==null?void 0:R[0])||""),[A,L]=a.useState((s.styleTags||((Y=s.analysis)==null?void 0:Y.genreTags)||[]).join(", ")),[I,z]=a.useState(()=>s.pendingRewriteTaskId||null),[h,C]=a.useState(""),[c,f]=a.useState(""),[d,N]=a.useState(()=>s.analysisModel||ie(Se,Pe).modelId),[u,p]=a.useState(()=>s.analysisModelRef||ie(Se,Pe).modelRef),[K,Z]=a.useState(!1),F=a.useRef(),re=a.useCallback((r,g)=>{N(r),p(g||null),pe(Se,r,g)},[]);a.useEffect(()=>{var r,g,w;x(we(s)),S(s.lyricsDraft||""),D(s.title||((g=(r=s.analysis)==null?void 0:r.titleSuggestions)==null?void 0:g[0])||""),L((s.styleTags||((w=s.analysis)==null?void 0:w.genreTags)||[]).join(", ")),z(s.pendingRewriteTaskId||null)},[s]),a.useEffect(()=>(clearTimeout(F.current),F.current=setTimeout(async()=>{const r=A.split(",").map(w=>w.trim()).filter(Boolean),g=await ae(s.id,{rewritePrompt:o,lyricsDraft:y,title:j,styleTags:r,pendingRewriteTaskId:I});i(g),n({...s,rewritePrompt:o,lyricsDraft:y,title:j,styleTags:r,pendingRewriteTaskId:I})},400),()=>clearTimeout(F.current)),[y,n,i,I,s.id,o,A,j]);const H=he("text"),ne=he("audio"),le=a.useMemo(()=>Fe(H,ne),[H,ne]),_=a.useMemo(()=>Ue(d),[d]),J=a.useMemo(()=>{const r=[{id:Ee,label:"原始版本"}];for(const g of s.lyricsVersions||[])r.push({id:g.id,label:g.label});return r},[s.lyricsVersions]),T=s.activeVersionId||Ee,k=J.length>1,U=String(s.creationPrompt||"").trim(),oe=a.useCallback(async r=>{const g=Je(s,r);if(!g)return;const w=await ae(s.id,g);i(w),n({...s,...g}),Z(!1)},[n,i,s]),ee=a.useCallback(async()=>{f(""),C(_?"歌词生成中...":"歌词改写中 0%");try{let r;if(_){const W=[o.trim()?`本轮改写要求:
1
+ import{y as e,aI as He,at as Ge,r as a,n5 as ie,n6 as pe,n7 as ae,n8 as Fe,n9 as Me,g$ as G,lq as Ye,h1 as V,lH as qe,na as Ue,nb as Be,nc as We,nd as Qe,hf as fe,ne as we,nf as Ee,ng as Je,nh as Re,hz as Xe,ib as Ze,ni as ge,nj as es,nk as ss,nl as as,i$ as ts,fP as ns,h0 as te,bV as ls,nm as is}from"./tool-windows-C4D0lII2.js";import{M as ye}from"./ModelDropdown-CHYgRb1r.js";import{u as he}from"./use-runtime-models-BLwgp0M1.js";import{a as je}from"./model-selection-CbzU26xQ.js";import{quickInsert as Ve}from"./canvas-insertion-CYbFgP4L.js";import{s as Ce,i as rs,g as cs,a as os}from"./MusicAnalyzer-BTXks5oV.js";/* empty css */import"./model-benchmark-service-B0QCqInK.js";const De=[{id:"create",label:"创作"},{id:"lyrics",label:"歌词"},{id:"generate",label:"生成"}],ds=({current:s,onNavigate:n,hasRecord:i})=>{const b=De.findIndex(o=>o.id===s);return e.jsx("div",{className:"va-step-bar",children:De.map((o,x)=>{const y=o.id===s,S=x<b,j=!i&&x>0;return e.jsxs(He.Fragment,{children:[x>0&&e.jsx("span",{className:"va-step-arrow",children:"→"}),e.jsxs("button",{className:`va-step ${y?"active":""} ${S?"past":""}`,onClick:()=>!j&&n(o.id),disabled:j,children:[e.jsx("span",{className:"va-step-num",children:x+1}),o.label]})]},o.id)})})};function ze(s){return(s||"").trim().toLowerCase().replace(/[^a-z0-9]/g,"")||"mp3"}function us(s){const n=s.name.split(".").pop();return n&&n.length<=8?ze(n):ze(s.type.split("/")[1])}async function ms(s,n){const i=us(s),o=`/__aitu_cache__/audio/${`music-analyzer-source-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}.${i}`;return await Ge.cacheMediaFromBlob(o,s,"audio",{metadata:{source:"music-analyzer-input",fileName:s.name,mimeType:s.type||"audio/mpeg",size:s.size}}),{type:"upload",cacheUrl:o,fileName:s.name||`music-source.${i}`,mimeType:s.type||"audio/mpeg",size:s.size}}async function hs(s){if(!s||s.type!=="upload")return null;const n=await Ge.getCachedBlob(s.cacheUrl);return n?new File([n],s.fileName||"music-source.mp3",{type:s.mimeType||n.type||"audio/mpeg",lastModified:Date.now()}):null}const xe="gemini-2.5-pro",Ne="music-analyzer:model",be="music-analyzer:lyrics-model",ke="music-analyzer:creation-prompt";function ps(s){return`${(s/1024/1024).toFixed(1)}MB`}function fs(){try{return sessionStorage.getItem(ke)||""}catch{return""}}function $e(s){try{if(s){sessionStorage.setItem(ke,s);return}sessionStorage.removeItem(ke)}catch{}}const ys=({existingRecord:s,onComplete:n,onRecordsChange:i,onCreateNew:b,onNext:o,onLyricsReady:x})=>{const[y,S]=a.useState((s==null?void 0:s.source)==="upload"?"reference":"scratch"),[j,D]=a.useState(()=>(s==null?void 0:s.creationPrompt)||fs()),[A,L]=a.useState(()=>(s==null?void 0:s.pendingLyricsGenTaskId)||null),[I,z]=a.useState(""),[h,C]=a.useState(null),[c,f]=a.useState(null),[d,N]=a.useState(""),[u,p]=a.useState(!0),[K,Z]=a.useState(""),[F,re]=a.useState(""),[H,ne]=a.useState(""),le=a.useRef(null),_=a.useRef(null),J=a.useRef(),[T,k]=a.useState(""),[U,oe]=a.useState(()=>(s==null?void 0:s.analysisModel)||ie(Ne,xe).modelId),[ee,ce]=a.useState(()=>(s==null?void 0:s.analysisModelRef)||ie(Ne,xe).modelRef),[M,R]=a.useState(()=>ie(be,fe()).modelId),[Y,$]=a.useState(()=>ie(be,fe()).modelRef),r=a.useCallback((l,v)=>{oe(l),ce(v||null),pe(Ne,l,v)},[]),g=a.useCallback((l,v)=>{R(l),$(v||null),pe(be,l,v)},[]),w=a.useMemo(()=>{if(_.current&&URL.revokeObjectURL(_.current),!h)return _.current=null,null;const l=URL.createObjectURL(h);return _.current=l,l},[h]);a.useEffect(()=>()=>{_.current&&URL.revokeObjectURL(_.current)},[]),a.useEffect(()=>{let l=!1;return(async()=>{if(!s){!c&&!A&&(C(null),k(""));return}oe(s.analysisModel||xe),ce(s.analysisModelRef||null),D(s.creationPrompt||"");const m=s.analysis?Me(s.analysis):null;if(Z(s.title||(m==null?void 0:m.sunoTitle)||""),re((s.styleTags||(m==null?void 0:m.sunoStyleTags)||(m==null?void 0:m.genreTags)||[]).join(", ")),ne(s.lyricsDraft||(m==null?void 0:m.sunoLyricsDraft)||""),k(""),s.source==="upload"){const P=await hs(s.sourceSnapshot);if(l)return;C(P),P||k("原上传音频缓存已失效,无法自动回填音频")}})(),()=>{l=!0}},[s,c,A]),a.useEffect(()=>{if((s==null?void 0:s.source)==="scratch"){$e(s.creationPrompt||"");return}s||$e(j)},[j,s]),a.useEffect(()=>{if(!(!s||y!=="reference"))return clearTimeout(J.current),J.current=setTimeout(async()=>{const l=F.split(",").map(P=>P.trim()).filter(Boolean),v=await ae(s.id,{title:K.trim(),styleTags:l,lyricsDraft:H});i(v);const m=v.find(P=>P.id===s.id);m&&n(m)},400),()=>clearTimeout(J.current)},[H,F,K,s,y,n,i]);const W=he("text"),B=a.useMemo(()=>W.filter(l=>/^gemini/i.test(l.id)),[W]),t=he("audio"),O=a.useMemo(()=>Fe(W,t),[W,t]),E=a.useMemo(()=>s!=null&&s.analysis?Me(s.analysis):null,[s==null?void 0:s.analysis]),se=a.useCallback(l=>{var m;const v=(m=l.target.files)==null?void 0:m[0];v!=null&&v.type.startsWith("audio/")?(C(v),k("")):k("请选择音频文件")},[]),q=a.useCallback(l=>{l.preventDefault();const v=l.dataTransfer.files[0];v!=null&&v.type.startsWith("audio/")?(C(v),k("")):k("请选择音频文件")},[]),Q=a.useCallback(async()=>{if(!h){k("请先上传音频");return}k(""),N("缓存音频...");try{const l=await ms(h),v=G.createTask({prompt:`分析音频:${h.name||"本地音频"}`,model:U,modelRef:ee,mimeType:l.mimeType,audioCacheUrl:l.cacheUrl,musicAnalyzerAction:"analyze",musicAnalyzerPrompt:Ye,musicAnalyzerSource:"upload",musicAnalyzerSourceLabel:l.fileName,musicAnalyzerSourceSnapshot:l,autoInsertToCanvas:!1},V.CHAT);f(v.id),N("音频分析中 0%")}catch(l){k(l.message||"音频分析失败")}},[h,U,ee]),de=a.useCallback(async()=>{if(!j.trim()){k("请先描述你想创作的歌曲");return}const l=Ue(M);k(""),z(l?"歌词生成中...":"歌词草稿生成中 0%");try{const v={id:qe(),createdAt:Date.now(),source:"scratch",sourceLabel:j.slice(0,30)||"从零创作",creationPrompt:j,starred:!1},m=l?G.createTask({prompt:j,model:M,modelRef:Y,sunoAction:"lyrics",musicAnalyzerAction:"lyrics-gen",musicAnalyzerRecordId:v.id,autoInsertToCanvas:!1},V.AUDIO):G.createTask({prompt:`从零创作歌词:${v.sourceLabel}`,model:M,modelRef:Y,musicAnalyzerAction:"lyrics-gen",musicAnalyzerPrompt:Be({userPrompt:j,mode:"create"}),musicAnalyzerRecordId:v.id,autoInsertToCanvas:!1},V.CHAT);v.pendingLyricsGenTaskId=m.id;const P=await We(v);i(P),n(v),L(m.id)}catch(v){k(v.message||"歌词生成失败"),z("")}},[j,n,i,M,Y]);a.useEffect(()=>{if(!c)return;const l=G.getTask(c);typeof(l==null?void 0:l.progress)=="number"&&N(`音频分析中 ${Math.round(l.progress)}%`);const v=G.observeTaskUpdates().subscribe(m=>{var P;if(m.task.id===c){if(m.task.status==="failed"){f(null),N(""),k(((P=m.task.error)==null?void 0:P.message)||"音频分析失败");return}if(m.task.status==="completed"){Ce(m.task).then(X=>{X&&(i(X.records),n(X.record))}).catch(X=>k(X.message||"分析结果同步失败")).finally(()=>{f(null),N("")});return}typeof m.task.progress=="number"&&N(`音频分析中 ${Math.round(m.task.progress)}%`)}});return()=>v.unsubscribe()},[c,n,i]),a.useEffect(()=>{if(!A)return;const l=G.getTask(A);if(typeof(l==null?void 0:l.progress)=="number"){const m=l.type===V.CHAT?"歌词草稿生成中":"歌词生成中";z(`${m} ${Math.round(l.progress)}%`)}const v=G.observeTaskUpdates().subscribe(m=>{var P;if(m.task.id===A){if(m.task.status==="failed"){const X=String(m.task.params.musicAnalyzerRecordId||"").trim();L(null),z(""),k(((P=m.task.error)==null?void 0:P.message)||"歌词生成失败"),X&&ae(X,{pendingLyricsGenTaskId:null}).then(i);return}if(m.task.status==="completed"){L(null),z(""),x==null||x();return}if(typeof m.task.progress=="number"){const X=m.task.type===V.CHAT?"歌词草稿生成中":"歌词生成中";z(`${X} ${Math.round(m.task.progress)}%`)}}});return()=>v.unsubscribe()},[x,i,A]);const ve=a.useCallback(async()=>{E&&await Ve("text",Qe(E))},[E]);return e.jsxs("div",{className:"ma-create-page",children:[e.jsxs("div",{className:"ma-mode-toggle",children:[e.jsx("button",{className:`ma-mode-btn ${y==="scratch"?"active":""}`,onClick:()=>S("scratch"),children:"从零创作"}),e.jsx("button",{className:`ma-mode-btn ${y==="reference"?"active":""}`,onClick:()=>S("reference"),children:"参考音频"})]}),e.jsxs("div",{className:"va-page",children:[y==="scratch"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"歌词草稿模型"}),e.jsx("span",{className:"ma-muted",children:"文本模型会补齐 Suno 所需标题/标签/歌词"})]}),e.jsx(ye,{selectedModel:M,selectedSelectionKey:je(M,Y),onSelect:g,models:O,variant:"form",placement:"down",placeholder:"选择歌词草稿模型"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"描述你想创作的歌曲"})}),e.jsx("textarea",{className:"ma-textarea",value:j,onChange:l=>D(l.target.value),rows:6,placeholder:"例如:一首关于夏天海边的轻快流行歌,女声,带有吉他和电子节拍"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"上传音频"}),h&&e.jsx("span",{className:"ma-muted",children:ps(h.size)})]}),e.jsx("div",{className:"va-dropzone ma-dropzone",onClick:()=>{var l;return(l=le.current)==null?void 0:l.click()},onDragOver:l=>l.preventDefault(),onDrop:q,children:h?e.jsxs("div",{className:"ma-audio-preview",children:[e.jsxs("div",{className:"ma-audio-preview__meta",children:[e.jsx("strong",{children:h.name}),e.jsx("button",{className:"va-nav-btn",onClick:l=>{l.stopPropagation(),C(null),k(""),le.current&&(le.current.value="")},children:"清空"})]}),w&&e.jsx("audio",{controls:!0,src:w})]}):e.jsxs("div",{className:"ma-dropzone__placeholder",children:[e.jsx("span",{children:"点击或拖拽上传本地音频"}),e.jsx("small",{children:"支持 mp3、wav、m4a 等常见格式"})]})}),e.jsx("input",{ref:le,type:"file",accept:"audio/*",hidden:!0,onChange:se})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"分析模型"})}),e.jsx(ye,{selectedModel:U,selectedSelectionKey:je(U,ee),onSelect:r,models:B,variant:"form",placement:"down",placeholder:"选择 Gemini 分析模型"})]})]}),E&&y==="reference"&&e.jsxs("div",{className:"ma-card",children:[e.jsxs("button",{className:"ma-section-toggle",onClick:()=>p(l=>!l),children:[e.jsx("span",{children:"分析摘要"}),e.jsx("span",{children:u?"收起":"展开"})]}),u&&e.jsxs("div",{className:"ma-analysis-summary",children:[e.jsx("p",{children:E.summary}),e.jsxs("div",{className:"ma-chip-row",children:[e.jsx("span",{className:"ma-chip",children:E.language||"未知语言"}),e.jsx("span",{className:"ma-chip",children:E.mood||"未知情绪"}),E.genreTags.map(l=>e.jsx("span",{className:"ma-chip ma-chip--accent",children:l},l))]}),e.jsx("div",{className:"ma-tag-row",children:E.structure.map(l=>e.jsx("code",{children:l},l))}),E.titleSuggestions.length>0&&e.jsxs("div",{className:"ma-suggestions",children:["推荐标题:",E.titleSuggestions.join(" / ")]}),(E.sunoTitle||E.sunoStyleTags.length>0||E.sunoLyricsDraft)&&e.jsxs("div",{className:"ma-suno-summary",children:[e.jsx("div",{className:"ma-suno-summary__title",children:"Suno 生成草稿"}),e.jsxs("div",{className:"ma-suno-summary__form",children:[e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"歌曲标题"}),e.jsx("input",{className:"ma-input",value:K,onChange:l=>Z(l.target.value),placeholder:"可直接用于 Suno 的标题"})]}),e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"Suno 风格标签"}),e.jsx("input",{className:"ma-input",value:F,onChange:l=>re(l.target.value),placeholder:"逗号分隔的风格标签"})]}),e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"带 Suno 标签的歌词草稿"}),e.jsx("textarea",{className:"ma-textarea",rows:12,value:H,onChange:l=>ne(l.target.value),placeholder:"分析阶段整理出的可用歌词草稿"})]})]})]})]})]}),(T||d||I)&&e.jsxs("div",{className:"ma-status-stack",children:[T&&e.jsx("div",{className:"ma-error",children:T}),d&&e.jsx("div",{className:"ma-progress",children:d}),I&&e.jsx("div",{className:"ma-progress",children:I})]}),e.jsx("div",{className:"va-page-actions",children:y==="scratch"?e.jsx("button",{className:"va-btn-primary",onClick:de,disabled:!j.trim()||!!A,children:"生成歌词"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:b,children:"新建"}),e.jsx("button",{onClick:ve,disabled:!(s!=null&&s.analysis),children:"插入分析"}),e.jsx("button",{className:"va-btn-primary",onClick:Q,disabled:!h||!!c,children:"开始分析"}),e.jsx("button",{onClick:o,disabled:!s,children:"下一步"})]})})]})]})},Se="music-analyzer:model",Pe="gemini-2.5-pro",js=({record:s,onRecordUpdate:n,onRecordsChange:i,onNext:b})=>{var M,R,Y,$;const[o,x]=a.useState(()=>we(s)),[y,S]=a.useState(s.lyricsDraft||""),[j,D]=a.useState(s.title||((R=(M=s.analysis)==null?void 0:M.titleSuggestions)==null?void 0:R[0])||""),[A,L]=a.useState((s.styleTags||((Y=s.analysis)==null?void 0:Y.genreTags)||[]).join(", ")),[I,z]=a.useState(()=>s.pendingRewriteTaskId||null),[h,C]=a.useState(""),[c,f]=a.useState(""),[d,N]=a.useState(()=>s.analysisModel||ie(Se,Pe).modelId),[u,p]=a.useState(()=>s.analysisModelRef||ie(Se,Pe).modelRef),[K,Z]=a.useState(!1),F=a.useRef(),re=a.useCallback((r,g)=>{N(r),p(g||null),pe(Se,r,g)},[]);a.useEffect(()=>{var r,g,w;x(we(s)),S(s.lyricsDraft||""),D(s.title||((g=(r=s.analysis)==null?void 0:r.titleSuggestions)==null?void 0:g[0])||""),L((s.styleTags||((w=s.analysis)==null?void 0:w.genreTags)||[]).join(", ")),z(s.pendingRewriteTaskId||null)},[s]),a.useEffect(()=>(clearTimeout(F.current),F.current=setTimeout(async()=>{const r=A.split(",").map(w=>w.trim()).filter(Boolean),g=await ae(s.id,{rewritePrompt:o,lyricsDraft:y,title:j,styleTags:r,pendingRewriteTaskId:I});i(g),n({...s,rewritePrompt:o,lyricsDraft:y,title:j,styleTags:r,pendingRewriteTaskId:I})},400),()=>clearTimeout(F.current)),[y,n,i,I,s.id,o,A,j]);const H=he("text"),ne=he("audio"),le=a.useMemo(()=>Fe(H,ne),[H,ne]),_=a.useMemo(()=>Ue(d),[d]),J=a.useMemo(()=>{const r=[{id:Ee,label:"原始版本"}];for(const g of s.lyricsVersions||[])r.push({id:g.id,label:g.label});return r},[s.lyricsVersions]),T=s.activeVersionId||Ee,k=J.length>1,U=String(s.creationPrompt||"").trim(),oe=a.useCallback(async r=>{const g=Je(s,r);if(!g)return;const w=await ae(s.id,g);i(w),n({...s,...g}),Z(!1)},[n,i,s]),ee=a.useCallback(async()=>{f(""),C(_?"歌词生成中...":"歌词改写中 0%");try{let r;if(_){const W=[o.trim()?`本轮改写要求:
2
2
  ${o.trim()}`:"",U&&U!==o.trim()?`第一步创作提示词:
3
3
  ${U}`:"",y.trim()?`当前歌词草稿:
4
4
  ${y.trim()}`:""].filter(Boolean).join(`