aitu-app 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/assets/{CanvasAudioPlayer-DgcRAPAw.js → CanvasAudioPlayer-HtUs8HDj.js} +1 -1
- package/assets/{ComicCreator-BycaWmuc.js → ComicCreator-DhxXCyJR.js} +2 -2
- package/assets/{DeferredAIInputBar-CwJirFC0.js → DeferredAIInputBar-B2R2-2RU.js} +2 -2
- package/assets/{DrawnixDeferredFeatures-iBvUtWse.js → DrawnixDeferredFeatures-DHTr0c-V.js} +1 -1
- package/assets/{KnowledgeBaseContent-BHBg5nrj.js → KnowledgeBaseContent-CAq5kXdt.js} +3 -3
- package/assets/{MVCreator-j2vSDPdb.js → MVCreator-B9uaRsGE.js} +1 -1
- package/assets/{ModelBenchmarkWorkbench-Dq5hRRXu.js → ModelBenchmarkWorkbench-CK33zizl.js} +1 -1
- package/assets/{MusicAnalyzer-BLhUXQSA.js → MusicAnalyzer-D2NTonEA.js} +1 -1
- package/assets/{PromptHistoryTool-DJngTSmU.js → PromptHistoryTool-q6vOxFr6.js} +1 -1
- package/assets/{ResizableDivider-AjiNRzA1.js → ResizableDivider-BvT-DCEo.js} +1 -1
- package/assets/{TaskQueuePanel-YDHmXxWX.js → TaskQueuePanel-PayswYlG.js} +1 -1
- package/assets/{VideoAnalyzer-Qb6tEi0u.js → VideoAnalyzer-DnowtohS.js} +1 -1
- package/assets/{VideoAnalyzer-BjWgocHv.js → VideoAnalyzer-DoaGlK92.js} +1 -1
- package/assets/{ai-chat-D2kHVW04.js → ai-chat-BnWVpTEI.js} +9 -9
- package/assets/{batch-image-generation-A6_tinN3.js → batch-image-generation-CkmX4dem.js} +1 -1
- package/assets/{bootstrap-Cz9TDvTq.js → bootstrap-CQRLkOtk.js} +6 -6
- package/assets/{clean-confirm-DD8itIZV.js → clean-confirm-CIViVQ8s.js} +1 -1
- package/assets/{diagram-engines-BjFHXhwN.js → diagram-engines-DpAsX7pc.js} +2 -2
- package/assets/{editor-engines-FCgCX6kJ.js → editor-engines-9_72Ghfn.js} +1 -1
- package/assets/{external-skill-service-DuwhmKoU.js → external-skill-service-BN8ZCtPn.js} +1 -1
- package/assets/{frame-size-matcher-D5rWn72p.js → frame-size-matcher-9rxQ-bAY.js} +1 -1
- package/assets/{index-DkwucWUB.js → index-291TeU7i.js} +1 -1
- package/assets/{index-CHHy4efO.js → index-BJ-vS89P.js} +1 -1
- package/assets/{index-D0v91lhB.js → index-BSZAS0wO.js} +1 -1
- package/assets/{index-BECWJUV2.js → index-C7DAD_xK.js} +1 -1
- package/assets/{index-7TrMzH1l.js → index-CIgiIDgZ.js} +1 -1
- package/assets/{index-CBf-BvIi.js → index-CpHWUe__.js} +1 -1
- package/assets/{index-DeHXjhMn.js → index-D1LQ9eQM.js} +1 -1
- package/assets/{index-DsGlObqC.js → index-DRGxmFyd.js} +1 -1
- package/assets/{index-DUugpXxH.js → index-DmtcRYr8.js} +1 -1
- package/assets/{index.es-Dgi90kXH.js → index.es-Ch45-H39.js} +1 -1
- package/assets/{jspdf.es.min-Bm9veIPK.js → jspdf.es.min-bNprb1JY.js} +2 -2
- package/assets/{link-popup-Dw0GTx0j.js → link-popup-B6ReK6iq.js} +1 -1
- package/assets/{markdown-to-drawnix-CDain2y9.js → markdown-to-drawnix-BqT-3zQO.js} +2 -2
- package/assets/{mermaid-to-drawnix-Ddpp0aQq.js → mermaid-to-drawnix-CSctnpU0.js} +2 -2
- package/assets/{model-benchmark-launcher-DLwj4o8h.js → model-benchmark-launcher-DNMp2MLQ.js} +1 -1
- package/assets/{photo-wall-splitter-D2Ji--gy.js → photo-wall-splitter-DhBTEpdG.js} +1 -1
- package/assets/{popup-toolbar-mBe3Bjaq.js → popup-toolbar-BChsudwW.js} +3 -3
- package/assets/{prompt-utils-CatisMlq.js → prompt-utils-BX0pRV-Z.js} +1 -1
- package/assets/{quick-creation-toolbar-jRI3BBKS.js → quick-creation-toolbar-3-AYFpEF.js} +1 -1
- package/assets/{settings-dialog-BOrvJdPV.js → settings-dialog-Ccemaout.js} +1 -1
- package/assets/{size-picker-Blua_9Dv.js → size-picker-DTrdjyLh.js} +1 -1
- package/assets/{skill-dsl-parser-1E3u-6mw.js → skill-dsl-parser-ZR--uu5h.js} +1 -1
- package/assets/{startup-app-BXcHjIQM.js → startup-app-CH3QzBb4.js} +1 -1
- package/assets/{task-sync-CPtlvCdr.js → task-sync-C5XXOQ5m.js} +1 -1
- package/assets/{tool-windows-CSaRGLIT.js → tool-windows-Bf_pMml-.js} +5 -5
- package/assets/{ttd-dialog-RLopc37W.js → ttd-dialog-CohjwODB.js} +2 -2
- package/assets/{ttd-dialog-submit-shortcut-C9_wsIZ5.js → ttd-dialog-submit-shortcut-BVB8O_wE.js} +1 -1
- package/assets/{useCharacters-BCCGOiPW.js → useCharacters-CFlPvydq.js} +1 -1
- package/assets/{useWorkflowSubmission-Bo-icE0J.js → useWorkflowSubmission-CKkOEcAT.js} +2 -2
- package/assets/{video-merge-webcodecs-BWAut6ma.js → video-merge-webcodecs-BInWo9HA.js} +1 -1
- package/assets/{video-recovery-service-L4OR1un7.js → video-recovery-service-DITdD0pC.js} +1 -1
- package/assets/{workflow-generation-utils-CUmdJnGW.js → workflow-generation-utils-e0nRpAgJ.js} +2 -2
- package/assets/{workflow-submission-service-kAjrrvI-.js → workflow-submission-service-BqiL_5Cj.js} +1 -1
- package/changelog.json +87 -6
- package/idle-prefetch-manifest.json +128 -276
- package/manifest.json +3 -3
- package/package.json +1 -1
- package/precache-manifest.json +6 -6
- package/sw.js +1 -1
- package/version.json +58 -3
- package/.DS_Store +0 -0
- package/user-manual/gifs//346/200/235/347/273/264/345/257/274/345/233/276/345/210/233/345/273/272/346/274/224/347/244/272.gif +0 -0
- package/user-manual/screenshots/ai-step-0.png +0 -0
- package/user-manual/screenshots/ai-step-1.png +0 -0
- package/user-manual/screenshots/ai-step-2.png +0 -0
- package/user-manual/screenshots/ai-step-3.png +0 -0
- package/user-manual/screenshots/app-menu.png +0 -0
- package/user-manual/screenshots/backup-restore.png +0 -0
- package/user-manual/screenshots/canvas-tools.png +0 -0
- package/user-manual/screenshots/debug-panel.png +0 -0
- package/user-manual/screenshots/drawing-step-0.png +0 -0
- package/user-manual/screenshots/drawing-step-1.png +0 -0
- package/user-manual/screenshots/drawing-step-2.png +0 -0
- package/user-manual/screenshots/edit-selected.png +0 -0
- package/user-manual/screenshots/element-selected.png +0 -0
- package/user-manual/screenshots/flowchart-step-1.png +0 -0
- package/user-manual/screenshots/flowchart-step-2.png +0 -0
- package/user-manual/screenshots/flowchart-step-3.png +0 -0
- package/user-manual/screenshots/image-preview-empty.png +0 -0
- package/user-manual/screenshots/insert-from-library.png +0 -0
- package/user-manual/screenshots/insert-tools.png +0 -0
- package/user-manual/screenshots/inspiration-step-1.png +0 -0
- package/user-manual/screenshots/inspiration-step-2.png +0 -0
- package/user-manual/screenshots/media-library.png +0 -0
- package/user-manual/screenshots/mindmap-step-1.png +0 -0
- package/user-manual/screenshots/mindmap-step-2.png +0 -0
- package/user-manual/screenshots/mindmap-toolbar-menu.png +0 -0
- package/user-manual/screenshots/project-drawer.png +0 -0
- package/user-manual/screenshots/settings-dialog.png +0 -0
- package/user-manual/screenshots/shape-step-1.png +0 -0
- package/user-manual/screenshots/shape-step-2.png +0 -0
- package/user-manual/screenshots/text-step-1.png +0 -0
- package/user-manual/screenshots/text-step-2.png +0 -0
- package/user-manual/screenshots/toolbox-drawer.png +0 -0
- package/user-manual/screenshots/toolbox-entry.png +0 -0
- package/user-manual/screenshots/video-entry.png +0 -0
- package/user-manual/screenshots/view-navigation.png +0 -0
- package/user-manual/screenshots/zoom-menu.png +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ai-chat-BlxYfB4O.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{_ as qe}from"./startup-runtime-BrfuwjQS.js";import{P as n,a8 as e,dU as vs,eB as pe,gz as je,dV as Ns,mN as Ke,mM as Tt,c3 as ye,gy as Ie,oG as De,qr as Cs,qs as Ss,ab as G,cA as Le,qt as Ve,qu as Ae,pW as Rt,qv as be,qw as ve,qx as rt,qy as zt,bQ as Pt,qz as $t,qA as Ut,cO as se,c1 as Bt,nb as Xe,pp as Es,qB as Ye,qC as at,qD as _t,qE as Ms,qF as As,qG as Is,oJ as Ds,qH as Ls,fA as Ft,eI as Wt,cF as q,mJ as Ts,qI as Rs,qJ as zs,cH as Ps,mK as $s,dE as Us,qK as it,qL as Bs,pX as Ge,qM as Qe,qN as Fs,c$ as Te,d0 as qt,co as Ne,qO as Ws,qP as qs,ep as Ot,d1 as Os,qQ as Hs,ao as X,qR as Ht,qS as Kt,kF as Vt,c8 as Ks,eo as Vs,et as jt,m$ as Xs,eM as Ze,qT as Ys,qU as Gs,qV as Qs,qW as Zs,nm as Js,bP as en,R as tn,qX as yt,qY as vt,cn as Xt,qZ as sn,q_ as nn,q$ as rn,g1 as an,r0 as on,r1 as cn,r2 as Nt,n9 as ln,pU as dn,r3 as un,r4 as hn,r5 as mn}from"./ai-chat-D2kHVW04.js";import{S as Je,g as fn,E as fe,b as gn}from"./skills-DHghxQBn.js";import{S as Ct}from"./skill-dsl-parser-1E3u-6mw.js";import{$ as pn,a as Yt,b as Gt,i as bn,M as xn,c as kn,e as wn,d as _n,f as St,g as jn,C as yn,h as ae}from"./editor-engines-FCgCX6kJ.js";/* empty css */import{x as vn}from"./bootstrap-Cz9TDvTq.js";import{ab as Nn,a9 as Cn}from"./tool-windows-CSaRGLIT.js";import"./diagram-engines-BjFHXhwN.js";import"./startup-app-BXcHjIQM.js";const ge="__system_skill__";function Sn(t){const s=new Date(t),r=new Date;return s.getFullYear()===r.getFullYear()&&s.getMonth()===r.getMonth()&&s.getDate()===r.getDate()?s.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):s.getFullYear()===r.getFullYear()?s.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit"}):s.toLocaleDateString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit"})}const En=({directories:t,notesByDir:s,noteTagsMap:r,noteCounts:a,selectedDirId:c,selectedNoteId:o,expandedDirIds:d,isCreatingDir:u,skillDirName:p="Skill",onSelectDir:v,onToggleExpand:j,onCreateDir:N,onCancelCreateDir:m,onRenameDir:k,onDeleteDir:l,onSelectNote:S,onCreateNote:b,onDeleteNote:g,onDuplicateDir:z,onDuplicateNote:P,onInsertNoteToCanvas:$})=>{const[O,f]=n.useState(""),[T,F]=n.useState(null),[R,J]=n.useState(""),[W,U]=n.useState(null);n.useEffect(()=>{const w=()=>U(null),B=()=>U(null);return document.addEventListener("click",w),document.addEventListener("scroll",B,!0),()=>{document.removeEventListener("click",w),document.removeEventListener("scroll",B,!0)}},[]);const te=n.useCallback((w,B,_,A=!1)=>{w.preventDefault(),w.stopPropagation(),U({x:w.clientX,y:w.clientY,type:B,id:_,isDefault:A})},[]),y=n.useCallback(async()=>{const w=O.trim();if(w)try{await N(w),f(""),m()}catch{}},[O,N,m]),D=n.useCallback(async w=>{const B=R.trim();if(B)try{await k(w,B),F(null)}catch{}},[R,k]);return e.jsxs("div",{className:"kb-tree",children:[u&&e.jsxs("div",{className:"kb-tree__create-row",children:[e.jsx("input",{className:"kb-tree__input",value:O,onChange:w=>f(w.target.value),onKeyDown:w=>{w.key==="Enter"&&y(),w.key==="Escape"&&m()},placeholder:"目录名称",autoFocus:!0}),e.jsx("button",{className:"kb-tree__icon-btn",onClick:y,children:e.jsx(pe,{size:14})}),e.jsx("button",{className:"kb-tree__icon-btn",onClick:m,children:e.jsx(je,{size:14})})]}),e.jsx("div",{className:"kb-tree__list",children:t.map(w=>e.jsx(Mn,{dir:w,isSelected:c===w.id,isExpanded:d.has(w.id),notes:s[w.id]||[],noteCount:a[w.id]||0,noteTagsMap:r,selectedNoteId:o,isRenaming:T===w.id,renameValue:R,onSelectDir:()=>{v(w.id),d.has(w.id)||j(w.id)},onToggleExpand:()=>{j(w.id),U(null)},onStartRename:()=>{F(w.id),J(w.name),U(null)},onRenameChange:J,onRenameConfirm:()=>D(w.id),onRenameCancel:()=>F(null),onDeleteDir:()=>{l(w.id),U(null)},onCreateNote:()=>{b(w.id),U(null)},onSelectNote:S,onDeleteNote:B=>{g(B),U(null)},onContextMenu:B=>te(B,"directory",w.id,w.isDefault),onNoteContextMenu:(B,_)=>te(B,"note",_),isSkillDir:w.name===p},w.id))}),W&&vs.createPortal(e.jsx("div",{className:"kb-context-menu",style:{top:W.y,left:W.x,zIndex:Ns.DROPDOWN_PORTAL},onClick:w=>w.stopPropagation(),children:W.type==="directory"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{z(W.id),U(null)},children:[e.jsx(Ke,{size:14}),e.jsx("span",{children:"复制目录"})]}),e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{var w;F(W.id),J(((w=t.find(B=>B.id===W.id))==null?void 0:w.name)||""),U(null)},children:[e.jsx(Tt,{size:14}),e.jsx("span",{children:"重命名"})]}),e.jsxs("div",{className:"kb-context-menu__item kb-context-menu__item--danger",onClick:()=>{l(W.id),U(null)},children:[e.jsx(ye,{size:14}),e.jsx("span",{children:"删除"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{P(W.id),U(null)},children:[e.jsx(Ke,{size:14}),e.jsx("span",{children:"创建副本"})]}),$&&e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{const B=Object.values(s).flat().find(_=>_.id===W.id);B&&$(B),U(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:()=>{g(W.id),U(null)},children:[e.jsx(ye,{size:14}),e.jsx("span",{children:"删除"})]})]})}),document.body)]})},Mn=({dir:t,isSelected:s,isExpanded:r,notes:a,noteCount:c,noteTagsMap:o,selectedNoteId:d,isRenaming:u,renameValue:p,isSkillDir:v=!1,onSelectDir:j,onToggleExpand:N,onStartRename:m,onRenameChange:k,onRenameConfirm:l,onRenameCancel:S,onDeleteDir:b,onCreateNote:g,onSelectNote:z,onDeleteNote:P,onContextMenu:$,onNoteContextMenu:O})=>e.jsxs("div",{className:`kb-tree__dir ${s?"kb-tree__dir--selected":""}`,children:[e.jsxs("div",{className:"kb-tree__dir-row",onClick:j,onContextMenu:$,children:[e.jsx("button",{className:"kb-tree__expand-btn",onClick:f=>{f.stopPropagation(),N()},children:r?e.jsx(Ie,{size:14}):e.jsx(De,{size:14})}),r?e.jsx(Cs,{size:16}):e.jsx(Ss,{size:16}),u?e.jsx("input",{className:"kb-tree__input kb-tree__input--inline",value:p,onChange:f=>k(f.target.value),onKeyDown:f=>{f.key==="Enter"&&l(),f.key==="Escape"&&S()},onClick:f=>f.stopPropagation(),autoFocus:!0}):e.jsx("span",{className:"kb-tree__dir-name",children:t.name}),e.jsx("span",{className:"kb-tree__dir-count",children:c}),e.jsxs("div",{className:"kb-tree__dir-actions",children:[e.jsx(G,{content:"新建笔记",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn",onClick:f=>{f.stopPropagation(),g()},children:e.jsx(Le,{size:12})})}),e.jsxs(e.Fragment,{children:[e.jsx(G,{content:"重命名",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn",onClick:f=>{f.stopPropagation(),m()},children:e.jsx(Tt,{size:12})})}),e.jsx(G,{content:"删除",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn kb-tree__icon-btn--danger",onClick:f=>{f.stopPropagation(),b()},children:e.jsx(ye,{size:12})})})]})]})]}),r&&e.jsxs("div",{className:"kb-tree__notes",children:[v&&Je.map(f=>{const T=`${ge}${f.id}`,F=d===T;return e.jsxs("div",{className:`kb-tree__note-row kb-tree__note-row--system ${F?"kb-tree__note-row--selected":""}`,onClick:()=>z(T),children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(Ve,{size:14})}),e.jsx("div",{className:"kb-tree__note-content",children:e.jsxs("div",{className:"kb-tree__note-title",children:[f.name,e.jsx("span",{className:"kb-tree__system-badge",children:"系统"})]})})]},T)}),v&&fn().map(f=>{const T=`${fe}${f.id}`,F=d===T;return e.jsxs("div",{className:`kb-tree__note-row kb-tree__note-row--system ${F?"kb-tree__note-row--selected":""}`,onClick:()=>z(T),children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(Ve,{size:14})}),e.jsx("div",{className:"kb-tree__note-content",children:e.jsxs("div",{className:"kb-tree__note-title",children:[f.name,e.jsx("span",{className:"kb-tree__system-badge",children:"系统"})]})})]},T)}),a.length===0&&!v&&e.jsx("div",{className:"kb-tree__notes-empty",children:"暂无笔记"}),a.length===0&&v&&Je.length===0&&e.jsx("div",{className:"kb-tree__notes-empty",children:"暂无笔记"}),Array.from(new Map(a.map(f=>[f.id,f])).values()).map(f=>{const T=d===f.id,F=o[f.id]||[],R=f.metadata;return e.jsx(An,{note:f,isSelected:T,tags:F,metadata:R,onSelect:()=>z(f.id),onDelete:()=>P(f.id),onContextMenu:J=>O(J,f.id)},f.id)})]})]}),An=({note:t,isSelected:s,tags:r,metadata:a,onSelect:c,onDelete:o,onContextMenu:d})=>e.jsxs("div",{className:`kb-tree__note-row ${s?"kb-tree__note-row--selected":""}`,onClick:c,onContextMenu:d,children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(Ae,{size:14})}),e.jsxs("div",{className:"kb-tree__note-content",children:[e.jsx("div",{className:"kb-tree__note-title",children:t.title||"无标题"}),(a==null?void 0:a.domain)&&e.jsxs("div",{className:"kb-tree__note-domain",children:[a.faviconUrl?e.jsx("img",{src:a.faviconUrl,alt:"",className:"kb-tree__favicon",onError:u=>{u.target.style.display="none"}}):e.jsx(Rt,{size:10}),e.jsx("span",{children:a.domain})]}),e.jsxs("div",{className:"kb-tree__note-meta",children:[r.length>0&&e.jsxs("div",{className:"kb-tree__note-tags",children:[r.slice(0,2).map(u=>e.jsx("span",{className:"kb-tree__tag-badge",style:{backgroundColor:`${u.color}20`,color:u.color},children:u.name},u.id)),r.length>2&&e.jsxs("span",{className:"kb-tree__tag-more",children:["+",r.length-2]})]}),r.length===0&&!(a!=null&&a.domain)&&e.jsx("span",{className:"kb-tree__note-time",children:Sn(t.updatedAt)})]})]}),e.jsx(G,{content:"删除笔记",showArrow:!1,children:e.jsx("button",{className:"kb-tree__note-delete",onClick:u=>{u.stopPropagation(),o()},children:e.jsx(ye,{size:12})})})]});function Oe(t){const s=t.url;if(!(s!=null&&s.startsWith(be)))return null;const r=s.slice(be.length),a=ve(t.alt||""),c=a.assetType||"image";if(c==="image")return null;const o=rt(t.title),d=a.label||"";return{type:"assetEmbed",assetId:r,assetType:c,label:d,width:o.width,height:o.height}}function Qt(t){if(t.children)for(let s=0;s<t.children.length;s++){const r=t.children[s];if(r.type==="image-block"){const a=Oe(r);if(a){t.children[s]=a;continue}}if(r.type==="paragraph"&&r.children){const a=[],c=[];for(const o of r.children){if(o.type==="image"){const d=Oe(o);if(d){a.push(d);continue}}c.push(o)}if(a.length>0){const o=[];c.length>0&&o.push({...r,children:c}),o.push(...a),t.children.splice(s,1,...o),s+=o.length-1;continue}}if(r.type==="image"){const a=Oe(r);if(a){t.children[s]=a;continue}}Qt(r)}}const In=pn("remarkAssetEmbed",()=>()=>Qt);function le(t){if(typeof t=="number"&&Number.isFinite(t)&&t>0)return Math.round(t);if(typeof t=="string"&&t.trim()){const s=Number.parseInt(t,10);if(Number.isFinite(s)&&s>0)return s}return null}const et=Yt("assetEmbed",()=>({inline:!1,group:"block",selectable:!0,draggable:!0,atom:!0,attrs:{assetId:{default:""},assetType:{default:"image"},label:{default:""},width:{default:null},height:{default:null}},parseMarkdown:{match:t=>{var s;if(t.type==="assetEmbed")return!0;if(t.type==="image-block"&&((s=t.url)!=null&&s.startsWith(be))){const r=ve(t.alt);if(r.assetType&&r.assetType!=="image")return!0}return!1},runner:(t,s,r)=>{if(s.type==="assetEmbed"){t.addNode(r,{assetId:s.assetId,assetType:s.assetType,label:s.label,width:le(s.width),height:le(s.height)});return}const a=s.url.slice(be.length),c=ve(s.alt),o=rt(s.title);t.addNode(r,{assetId:a,assetType:c.assetType||"video",label:c.label||"",width:le(o.width),height:le(o.height)})}},toMarkdown:{match:t=>t.type.name==="assetEmbed",runner:(t,s)=>{const{assetId:r,assetType:a,label:c}=s.attrs,o=c?`${a}|${c}`:a,d=zt({width:le(s.attrs.width),height:le(s.attrs.height)});t.openNode("paragraph"),t.addNode("image",void 0,void 0,{url:`${be}${r}`,alt:o,title:d}),t.closeNode()}},toDOM:t=>["div",{"data-type":"asset-embed","data-asset-id":t.attrs.assetId,"data-asset-type":t.attrs.assetType,"data-label":t.attrs.label,"data-width":t.attrs.width??"","data-height":t.attrs.height??""}],parseDOM:[{tag:'div[data-type="asset-embed"]',getAttrs:t=>({assetId:t.getAttribute("data-asset-id")||"",assetType:t.getAttribute("data-asset-type")||"image",label:t.getAttribute("data-label")||"",width:le(t.getAttribute("data-width")),height:le(t.getAttribute("data-height"))})}]})),Dn=({asset:t,style:s})=>{const r=n.useMemo(()=>({id:`markdown-audio-${t.id}`,type:"audio",points:[[0,0],[340,128]],children:[],audioUrl:t.url,title:t.name,previewImageUrl:t.thumbnail,prompt:t.prompt,createdAt:t.createdAt}),[t]),a=n.useMemo(()=>[{elementId:r.id,audioUrl:t.url,title:t.name,previewImageUrl:t.thumbnail}],[t.name,t.thumbnail,t.url,r.id]);return e.jsx("div",{className:"collimind-markdown-audio-card",style:s,children:e.jsx(vn,{element:r,selected:!1,canvasQueue:a})})};function re(t,s,r){return Math.min(Math.max(t,s),r)}function Re(t){if(!(typeof t!="number"||!Number.isFinite(t)||t<=0))return Math.round(t)}function ze(t,s,r){let a=re(t,r.minWidth,r.maxWidth),c=a/s;return(c<r.minHeight||c>r.maxHeight)&&(c=re(c,r.minHeight,r.maxHeight),a=c*s),{width:re(a,r.minWidth,r.maxWidth),height:re(c,r.minHeight,r.maxHeight)}}function Pe(t,s,r){let a=re(t,r.minHeight,r.maxHeight),c=a*s;return(c<r.minWidth||c>r.maxWidth)&&(c=re(c,r.minWidth,r.maxWidth),a=c/s),{width:re(c,r.minWidth,r.maxWidth),height:re(a,r.minHeight,r.maxHeight)}}const tt=Math.round(at*1.15);function Et(t){return re(Math.round(t*at/Ye),96,tt)}const Ln=({assetId:t,assetType:s,label:r,width:a,height:c,selected:o,readonly:d,updateAttrs:u})=>{const p=n.useSyncExternalStore($t,Ut),v=p.get(t),j=n.useRef(null),[N,m]=n.useState(null);n.useEffect(()=>{m(null)},[a,c]);const k=(N==null?void 0:N.width)??Re(a),l=(N==null?void 0:N.height)??Re(c),S=k??Ye,b=Et(S),g=s===se.AUDIO&&typeof l=="number"&&(l>240||l>S*.75),z=s===se.AUDIO?re(g?b:l??b,96,tt):l,P=n.useMemo(()=>{const f={};return k?f.width=`${k}px`:s===se.AUDIO?f.width="min(100%, 560px)":f.maxWidth=s===se.AUDIO?"min(100%, 560px)":"min(100%, 520px)",s===se.AUDIO?f.height=`${z}px`:l&&(f.height=`${l}px`),f},[s,l,k,z]),$=n.useCallback(f=>T=>{if(d)return;const F=j.current;if(!F)return;T.preventDefault(),T.stopPropagation();const R=F.getBoundingClientRect();if(!R.width||!R.height)return;const J=F.closest(".ProseMirror"),W=Math.max(160,((J==null?void 0:J.getBoundingClientRect().width)??R.width)-32),U=s===se.AUDIO?tt:1600,te=120,y=s===se.AUDIO?96:80,D={x:T.clientX,y:T.clientY,width:R.width,height:R.height};let w={width:Math.round(R.width),height:Math.round(R.height)};const B=A=>{const L=A.clientX-D.x,K=A.clientY-D.y,M=s!==se.AUDIO&&A.shiftKey&&D.width>0&&D.height>0,Y=f==="bottom"?D.width:re(D.width+L,te,W),Q=f==="right"?D.height:re(D.height+K,y,U);if(s===se.AUDIO){const Z=f==="bottom"?re(Math.round(Q*(Ye/at)),120,W):Math.round(Y),ie=Et(Z);w={width:Z,height:ie},m(w);return}if(M){const Z=D.width/D.height,ie={minWidth:te,maxWidth:W,minHeight:y,maxHeight:U};if(f==="right")w=ze(Y,Z,ie);else if(f==="bottom")w=Pe(Q,Z,ie);else{const Ce=Y/D.width,xe=Q/D.height;w=Math.abs(Ce-1)>=Math.abs(xe-1)?ze(Y,Z,ie):Pe(Q,Z,ie)}w={width:Math.round(w.width),height:Math.round(w.height)},m(w);return}w={width:Math.round(Y),height:Math.round(Q)},m(w)},_=()=>{document.removeEventListener("pointermove",B),document.removeEventListener("pointerup",_),m(w),u({width:w.width,height:w.height})};document.addEventListener("pointermove",B),document.addEventListener("pointerup",_,{once:!0})},[s,d,u]),O=(f,T)=>e.jsxs("div",{className:`collimind-asset-embed__shell ${o?"is-selected":""}`,"data-asset-type":s,"data-asset-id":t,children:[e.jsxs("div",{ref:j,className:"collimind-asset-embed__frame",style:P,children:[f,!d&&o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","data-resize-handle":"right",className:"collimind-asset-embed__handle collimind-asset-embed__handle--right",onPointerDown:$("right"),"aria-label":`调整${s===se.AUDIO?"音频":"视频"}宽度`}),e.jsx("button",{type:"button","data-resize-handle":"bottom",className:"collimind-asset-embed__handle collimind-asset-embed__handle--bottom",onPointerDown:$("bottom"),"aria-label":`调整${s===se.AUDIO?"音频":"视频"}高度`}),e.jsx("button",{type:"button","data-resize-handle":"corner",className:"collimind-asset-embed__handle collimind-asset-embed__handle--corner",onPointerDown:$("corner"),"aria-label":`同时调整${s===se.AUDIO?"音频":"视频"}宽高`})]})]}),T&&e.jsx("div",{className:"collimind-asset-embed__caption",children:T})]});return v?v.type===se.IMAGE?e.jsx(Bt,{className:"collimind-asset-embed__image",src:Xe(v.url),alt:r||v.name||"素材图片",showSkeleton:!1,eager:!0}):v.type===se.VIDEO?O(e.jsx("div",{className:"collimind-asset-embed__video-wrap",children:e.jsx(Es,{className:"collimind-asset-embed__video",src:v.url,poster:v.thumbnail,alt:r||v.name||"素材视频",thumbnailSize:"large",activateVideoOnClick:!0,playOnActivate:!0,videoProps:{controls:!0,preload:"metadata",playsInline:!0}})}),r||v.name):v.type===se.AUDIO?O(e.jsx(Dn,{asset:v,style:{width:"100%",maxHeight:"100%"}}),r||v.name):null:p.size===0?e.jsx("div",{className:"collimind-asset-embed__loading",style:P}):e.jsxs("div",{className:"collimind-asset-embed__missing",style:P,children:["素材不存在或已删除 (",t.slice(0,8),"…)"]})},Tn=Gt(et.node,()=>(t,s,r)=>{const a=document.createElement("div");a.className="collimind-asset-embed",a.setAttribute("data-asset-id",t.attrs.assetId);let c=t,o=!1,d=Pt.createRoot(a);const u=v=>{if(!s.editable)return;const j=r();j!=null&&s.dispatch(s.state.tr.setNodeMarkup(j,void 0,{...c.attrs,...v}))},p=()=>{d==null||d.render(e.jsx(Ln,{assetId:c.attrs.assetId,assetType:c.attrs.assetType,label:c.attrs.label,width:c.attrs.width??null,height:c.attrs.height??null,selected:o,readonly:!s.editable,updateAttrs:u}))};return p(),{dom:a,update:v=>v.type!==t.type?!1:(c=v,p(),!0),stopEvent:v=>{const j=v.target;return j instanceof HTMLElement?!!j.closest("[data-resize-handle]"):!1},selectNode:()=>{o=!0,a.classList.add("selected"),p()},deselectNode:()=>{o=!1,a.classList.remove("selected"),p()},destroy:()=>{if(d){const v=d;d=null,setTimeout(()=>v.unmount(),0)}}}}),Rn=[In,et.ctx,et.node,Tn].flat();function Me(t){if(typeof t=="number"&&Number.isFinite(t)&&t>0)return Math.round(t);if(typeof t=="string"&&t.trim()){const s=Number.parseInt(t,10);if(Number.isFinite(s)&&s>0)return s}return null}const st=Yt("image-block",()=>({inline:!1,group:"block",selectable:!0,draggable:!0,isolating:!0,marks:"",atom:!0,priority:100,attrs:{src:{default:""},alt:{default:""},caption:{default:""},ratio:{default:1},width:{default:null},height:{default:null}},parseMarkdown:{match:t=>{var s;if(t.type!=="image-block")return!1;if((s=t.url)!=null&&s.startsWith(be)){const r=ve(t.alt);if(r.assetType&&r.assetType!=="image")return!1}return!0},runner:(t,s,r)=>{const a=typeof s.alt=="string"?s.alt:"",c=rt(s.title),o=_t(a)?Number.parseFloat(a):1;t.addNode(r,{src:s.url,alt:_t(a)?"":a,caption:c.caption,ratio:Number.isFinite(o)&&o>0?o:1,width:c.width??null,height:c.height??null})}},toMarkdown:{match:t=>t.type.name==="image-block",runner:(t,s)=>{const r=zt({width:Me(s.attrs.width),height:Me(s.attrs.height),caption:s.attrs.caption}),a=s.attrs.alt||(!s.attrs.width&&!s.attrs.height&&s.attrs.ratio&&s.attrs.ratio!==1?`${Number.parseFloat(String(s.attrs.ratio)).toFixed(2)}`:"");t.openNode("paragraph"),t.addNode("image",void 0,void 0,{title:r,url:s.attrs.src,alt:a}),t.closeNode()}},toDOM:t=>["div",{"data-type":"opentu-image-block","data-src":t.attrs.src,"data-alt":t.attrs.alt,"data-caption":t.attrs.caption,"data-ratio":t.attrs.ratio,"data-width":t.attrs.width??"","data-height":t.attrs.height??""}],parseDOM:[{tag:'div[data-type="opentu-image-block"]',getAttrs:t=>({src:t.getAttribute("data-src")||"",alt:t.getAttribute("data-alt")||"",caption:t.getAttribute("data-caption")||"",ratio:Number(t.getAttribute("data-ratio")??1)||1,width:Me(t.getAttribute("data-width")),height:Me(t.getAttribute("data-height"))})},{tag:'img[data-type="image-block"]',getAttrs:t=>({src:t.getAttribute("src")||"",alt:"",caption:t.getAttribute("caption")||"",ratio:Number(t.getAttribute("ratio")??1)||1,width:null,height:null})}]}));function zn({attrs:t,readonly:s,config:r,updateAttrs:a}){const c=n.useRef(null),[o,d]=n.useState(t.src||""),[u,p]=n.useState(!1);n.useEffect(()=>{d(t.src||"")},[t.src]);const v=n.useCallback(()=>{a({src:o.trim()})},[o,a]),j=n.useCallback(async N=>{var k;const m=(k=N.target.files)==null?void 0:k[0];if(m)try{const l=await r.onUpload(m);if(!l)return;d(l),a({src:l})}catch(l){console.error("Failed to upload image block file",l)}finally{N.target.value=""}},[r,a]);return e.jsxs("div",{className:"image-edit collimind-markdown-image-block__edit",children:[e.jsx("div",{className:"image-icon",children:r.imageIcon||"🌌"}),e.jsxs("div",{className:`link-importer ${u?"focus":""}`,children:[e.jsx("input",{className:"link-input-area",value:o,disabled:s,onChange:N=>d(N.target.value),onFocus:()=>p(!0),onBlur:()=>p(!1),onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),v())}}),!o&&e.jsxs("div",{className:"placeholder",children:[e.jsx("input",{ref:c,className:"hidden",type:"file",accept:"image/*",disabled:s,onChange:j}),e.jsx("button",{type:"button",className:"uploader",disabled:s,onMouseDown:N=>N.preventDefault(),onClick:()=>{var N;return(N=c.current)==null?void 0:N.click()},children:r.uploadButton||"Upload"}),e.jsx("span",{className:"text",children:r.uploadPlaceholderText})]})]}),!!o&&e.jsx("button",{type:"button",className:"confirm",disabled:s,onMouseDown:N=>N.preventDefault(),onClick:v,children:r.confirmButton||"Confirm"})]})}function Pn({attrs:t,selected:s,readonly:r,updateAttrs:a}){const c=n.useRef(null),o=n.useSyncExternalStore($t,Ut),[d,u]=n.useState(null);n.useEffect(()=>{u(null)},[t.width,t.height]);const p=n.useMemo(()=>Ms(t.src),[t.src]),v=p?o.get(p):void 0,j=n.useMemo(()=>ve(t.alt),[t.alt]),N=p?j.label||(v==null?void 0:v.name)||"素材图片":t.alt||"图片",m=n.useMemo(()=>p?!v||v.type!==se.IMAGE?null:Xe(v.url):Xe(t.src),[v,p,t.src]),k=(d==null?void 0:d.width)??Re(t.width),l=(d==null?void 0:d.height)??Re(t.height),S=n.useMemo(()=>{const z={};return k?z.width=`${k}px`:z.maxWidth="min(100%, 420px)",l&&(z.height=`${l}px`),z},[l,k]),b=n.useMemo(()=>k&&l?{width:"100%",height:"100%",objectFit:"fill"}:k?{width:"100%",height:"auto"}:l?{width:"auto",height:"100%"}:{width:"100%",height:"auto"},[l,k]),g=n.useCallback(z=>P=>{if(r)return;const $=c.current;if(!$)return;P.preventDefault(),P.stopPropagation();const O=$.getBoundingClientRect();if(!O.width||!O.height)return;const f=$.closest(".ProseMirror"),T=Math.max(120,((f==null?void 0:f.getBoundingClientRect().width)??O.width)-32),F=80,R=80,J=1600,W={x:P.clientX,y:P.clientY,width:O.width,height:O.height};let U={width:Math.round(O.width),height:Math.round(O.height)};const te=D=>{const w=D.clientX-W.x,B=D.clientY-W.y,_=D.shiftKey&&W.width>0&&W.height>0,A=z==="bottom"?W.width:re(W.width+w,F,T),L=z==="right"?W.height:re(W.height+B,R,J);if(_){const K=W.width/W.height,M={minWidth:F,maxWidth:T,minHeight:R,maxHeight:J};if(z==="right")U=ze(A,K,M);else if(z==="bottom")U=Pe(L,K,M);else{const Y=A/W.width,Q=L/W.height;U=Math.abs(Y-1)>=Math.abs(Q-1)?ze(A,K,M):Pe(L,K,M)}U={width:Math.round(U.width),height:Math.round(U.height)},u(U);return}U={width:Math.round(A),height:Math.round(L)},u(U)},y=()=>{document.removeEventListener("pointermove",te),document.removeEventListener("pointerup",y),u(U),a({width:U.width,height:U.height})};document.addEventListener("pointermove",te),document.addEventListener("pointerup",y,{once:!0})},[r,a]);return p&&!v&&o.size===0?e.jsx("div",{className:"collimind-markdown-image-block__loading"}):m?e.jsxs("div",{className:`collimind-markdown-image-block__shell ${s?"is-selected":""}`,"data-asset-id":p||void 0,children:[e.jsxs("div",{ref:c,className:"collimind-markdown-image-block__frame",style:S,children:[e.jsx(Bt,{className:"collimind-markdown-image-block__image",src:m,alt:N,draggable:!1,style:b,showSkeleton:!1,eager:!0}),!r&&s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","data-resize-handle":"right",className:"collimind-markdown-image-block__handle collimind-markdown-image-block__handle--right",onPointerDown:g("right"),"aria-label":"调整图片宽度"}),e.jsx("button",{type:"button","data-resize-handle":"bottom",className:"collimind-markdown-image-block__handle collimind-markdown-image-block__handle--bottom",onPointerDown:g("bottom"),"aria-label":"调整图片高度"}),e.jsx("button",{type:"button","data-resize-handle":"corner",className:"collimind-markdown-image-block__handle collimind-markdown-image-block__handle--corner",onPointerDown:g("corner"),"aria-label":"同时调整图片宽高"})]})]}),t.caption&&e.jsx("div",{className:"collimind-markdown-image-block__caption",children:t.caption})]}):e.jsx("div",{className:"collimind-markdown-image-block__missing",children:p?`图片素材不存在或已删除 (${p.slice(0,8)}…)`:"图片地址无效"})}function $n(t){return t.attrs.src?e.jsx(Pn,{...t}):e.jsx(zn,{...t})}const Un=Gt(st.node,t=>{const s=t.get(bn.key);return(r,a,c)=>{const o=document.createElement("div");o.className="milkdown-image-block collimind-markdown-image-block",o.draggable=!0;let d=r,u=!1,p=Pt.createRoot(o);const v=m=>{if(!a.editable)return;const k=c();k!=null&&a.dispatch(a.state.tr.setNodeMarkup(k,void 0,{...d.attrs,...m}))},j=()=>{p==null||p.render(e.jsx($n,{attrs:d.attrs,selected:u,readonly:!a.editable,config:s,updateAttrs:v}))};j();const N=m=>{var l;const k=(l=m.detail)==null?void 0:l.src;k&&typeof k=="string"&&v({src:k})};return o.addEventListener("asset-commit",N),{dom:o,update:m=>m.type!==r.type?!1:(d=m,j(),!0),stopEvent:m=>{const k=m.target;return k instanceof HTMLElement?!!(k.closest(".image-edit")||k.closest("[data-resize-handle]")):!1},selectNode:()=>{u=!0,o.classList.add("selected"),j()},deselectNode:()=>{u=!1,o.classList.remove("selected"),j()},destroy:()=>{if(o.removeEventListener("asset-commit",N),p){const m=p;p=null,setTimeout(()=>m.unmount(),0)}}}}}),Bn=[st.ctx,st.node,Un].flat();function He(t){return new Promise((s,r)=>{const a=new FileReader;a.onload=()=>s(typeof a.result=="string"?a.result:""),a.onerror=()=>r(a.error),a.readAsDataURL(t)})}function Fn({markdown:t,onChange:s,placeholder:r,readOnly:a,editorRef:c,enableAssetEmbeds:o}){const d=n.useRef(s);n.useEffect(()=>{d.current=s},[s]);const u=n.useRef(t),p=n.useRef(null),v=n.useRef(null),j=n.useRef(null),{get:N,loading:m}=kn(k=>{const l=new yn({root:k,defaultValue:t,features:{[ae.CodeMirror]:!0,[ae.ListItem]:!0,[ae.LinkTooltip]:!0,[ae.Cursor]:!0,[ae.ImageBlock]:!0,[ae.BlockEdit]:!0,[ae.Toolbar]:!0,[ae.Placeholder]:!0,[ae.Table]:!0,[ae.Latex]:!0},featureConfigs:{[ae.Placeholder]:{text:r||"开始编辑..."},[ae.Cursor]:{color:"#3b82f6",width:4},[ae.ImageBlock]:{onUpload:He,inlineOnUpload:He,blockOnUpload:He},[ae.Latex]:{katexOptions:{strict:"ignore"}}}});return l.editor.use(Bn),o&&l.editor.use(Rn),d.current&&l.on(S=>{S.markdownUpdated((b,g)=>{if(p.current&&clearTimeout(p.current),g!==u.current){u.current=g;const z=d.current,P=()=>{v.current=null,z==null||z(g)};v.current=P,p.current=setTimeout(P,50)}})}),j.current=l,l},[]);return n.useEffect(()=>{if(m)return;const k=j.current;if(k){if(a)try{k.setReadonly(!0)}catch{}return c.current={getMarkdown:()=>u.current,setMarkdown:l=>{var S;try{u.current=l,(S=k.editor)==null||S.action(St(l))}catch{}},insertMarkdown:l=>{var S;try{(S=k.editor)==null||S.action(_n(l))}catch{}},focus:()=>{var l,S;try{(S=(l=k.editor)==null?void 0:l.ctx.get(wn))==null||S.focus()}catch{}}},()=>{var l;p.current&&(clearTimeout(p.current),p.current=null),(l=v.current)==null||l.call(v),v.current=null,c.current=null}}},[N,a,c,m]),n.useEffect(()=>{if(m)return;const k=j.current;if(k)try{k.setReadonly(!!a)}catch{}},[a,m]),n.useEffect(()=>{var l,S;if(m)return;const k=j.current;if(k)try{const b=u.current;t!==b&&(p.current&&(clearTimeout(p.current),p.current=null),(l=v.current)==null||l.call(v),u.current=t,(S=k.editor)==null||S.action(St(t)))}catch{}},[t,m]),e.jsx(jn,{})}const ot=n.memo(n.forwardRef(function({markdown:s,sourceMarkdown:r,onChange:a,placeholder:c="开始编辑...",readOnly:o=!1,className:d="",showModeSwitch:u=!0,initialMode:p="wysiwyg",enableAssetEmbeds:v=!1,enableAssetLibraryImagePicker:j=!1},N){const m=n.useContext(As),k=n.useRef(null),l=n.useRef(null),S=n.useRef(null),b=n.useRef(null),[g,z]=n.useState(p),[P,$]=n.useState(r||s),[O,f]=n.useState(!1),[T,F]=n.useState(!1),[R,J]=n.useState(p!=="wysiwyg"),W=n.useRef(r||s),U=j&&!!m;n.useEffect(()=>{W.current=P},[P]),n.useEffect(()=>{if(g!=="wysiwyg"){J(!1);return}let _=0,A=!1;const L=()=>{const K=S.current;if(!A){if(K!=null&&K.isConnected){J(!0);return}_=requestAnimationFrame(L)}};return L(),()=>{A=!0,_&&cancelAnimationFrame(_)}},[g]);const te=n.useCallback(_=>{var A,L;_!==g&&(_==="source"?$(r||((A=k.current)==null?void 0:A.getMarkdown())||s):r||((L=k.current)==null||L.setMarkdown(P),a==null||a(P)),z(_))},[g,s,P,r,a]),y=n.useCallback(_=>{const A=_.target.value;$(A),a==null||a(A)},[a]),D=n.useCallback(_=>{var L,K;if(!_)return;const A=g==="source"?W.current:r||((L=k.current)==null?void 0:L.getMarkdown())||W.current||s;if(g==="source"&&l.current){const M=l.current,Y=M.selectionStart??A.length,Q=M.selectionEnd??A.length,Z=`${A.slice(0,Y)}${_}${A.slice(Q)}`;$(Z),a==null||a(Z),requestAnimationFrame(()=>{M.focus();const ie=Y+_.length;M.setSelectionRange(ie,ie)});return}(K=k.current)==null||K.insertMarkdown(_),requestAnimationFrame(()=>{var Y;const M=(Y=k.current)==null?void 0:Y.getMarkdown();typeof M=="string"&&$(M)})},[s,g,a,r]);n.useImperativeHandle(N,()=>({getMarkdown:()=>{var _;return g==="source"?P:((_=k.current)==null?void 0:_.getMarkdown())||P},setMarkdown:_=>{var A;$(_),(A=k.current)==null||A.setMarkdown(_)},insertMarkdown:D,focus:()=>{var _,A;g==="source"?(_=l.current)==null||_.focus():(A=k.current)==null||A.focus()},getMode:()=>g,setMode:te}),[te,D,g,P]),n.useEffect(()=>{const _=r||s;_!==P&&$(_)},[s,P,r]);const w=n.useCallback(()=>{const _=S.current;if(!_){b.current=null,F(!1);return}const A=_.ownerDocument.activeElement,L=A instanceof HTMLElement?A.closest(".image-edit"):null,K=L&&_.contains(L)?L:_.querySelector(".image-edit");b.current=K??null,F(!!K)},[]),B=n.useCallback((_,A)=>{if(!_)return!1;const L=_.closest(".milkdown-image-block");return L?(L.dispatchEvent(new CustomEvent("asset-commit",{detail:{src:`asset://${A}`}})),!0):!1},[]);return n.useEffect(()=>{if(!U||o||g!=="wysiwyg"||!S.current){b.current=null,F(!1);return}const _=S.current;let A=0;const L=()=>{cancelAnimationFrame(A),A=requestAnimationFrame(w)},K=Y=>{const Q=Y.target;if(!(Q instanceof HTMLElement))return;const Z=Q.closest(".image-edit");if(Z&&_.contains(Z)){b.current=Z,F(!0);return}L()};L(),_.addEventListener("focusin",K),_.addEventListener("click",K,!0);const M=new MutationObserver(L);return M.observe(_,{childList:!0,subtree:!0}),()=>{cancelAnimationFrame(A),M.disconnect(),_.removeEventListener("focusin",K),_.removeEventListener("click",K,!0)}},[U,g,o,w]),e.jsxs("div",{className:`collimind-markdown-editor ${d}`,"data-readonly":o,"data-mode":g,"data-asset-embeds":v,children:[U&&T&&e.jsxs("button",{type:"button",className:"collimind-markdown-image-library-overlay",style:{right:u?68:8},onClick:()=>{w(),b.current&&f(!0)},children:[e.jsx(Is,{className:"collimind-icon-sm"}),e.jsx("span",{children:"从素材库插图"})]}),u&&e.jsxs("div",{className:"collimind-markdown-editor-mode-switch",children:[e.jsx(G,{content:"所见即所得模式",showArrow:!1,children:e.jsx("button",{type:"button",className:`collimind-markdown-editor-mode-btn ${g==="wysiwyg"?"active":""}`,onClick:()=>te("wysiwyg"),children:e.jsx(Ds,{className:"collimind-icon-sm"})})}),e.jsx(G,{content:"Markdown 源码模式",showArrow:!1,children:e.jsx("button",{type:"button",className:`collimind-markdown-editor-mode-btn ${g==="source"?"active":""}`,onClick:()=>te("source"),children:e.jsx(Ls,{className:"collimind-icon-sm"})})})]}),e.jsx("div",{ref:S,style:{display:g==="wysiwyg"?"contents":"none"},children:R&&e.jsx(xn,{children:e.jsx(Fn,{markdown:s,onChange:a,placeholder:c,readOnly:o,editorRef:k,enableAssetEmbeds:v})})}),g==="source"&&e.jsx("textarea",{ref:l,className:"collimind-markdown-editor-source",value:P,onChange:y,placeholder:c,readOnly:o||!!r,spellCheck:!1}),U&&O&&e.jsx(Ft,{isOpen:O,onClose:()=>{f(!1),w()},mode:Wt.SELECT,filterType:se.IMAGE,onSelect:_=>{var L;const A=b.current??((L=S.current)==null?void 0:L.querySelector(".image-edit"))??null;if(!B(A,_.id)){f(!1);return}f(!1),requestAnimationFrame(w)},selectButtonText:"插入素材库图片"})]})})),Mt=({allTags:t,selectedTagIds:s,onSelectedChange:r,onCreateTag:a,showCount:c=!1})=>{const[o,d]=n.useState(!1),[u,p]=n.useState(""),[v,j]=n.useState(!1),N=n.useRef(null);n.useEffect(()=>{if(!o)return;const b=g=>{N.current&&!N.current.contains(g.target)&&(d(!1),j(!1),p(""))};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[o]);const m=n.useCallback(b=>{const g=s.includes(b)?s.filter(z=>z!==b):[...s,b];r(g)},[s,r]),k=n.useCallback((b,g)=>{g.stopPropagation(),r(s.filter(z=>z!==b))},[s,r]),l=n.useCallback(async()=>{const b=u.trim();if(b)try{const g=await a(b);r([...s,g.id]),p(""),j(!1)}catch{}},[u,a,s,r]),S=t.filter(b=>s.includes(b.id));return e.jsxs("div",{className:"kb-tag-selector",ref:N,children:[e.jsxs("div",{className:"kb-tag-selector__selected",children:[S.map(b=>e.jsxs("span",{className:"kb-tag-selector__tag kb-tag-selector__tag--selected",style:{"--tag-color":b.color,borderColor:b.color,backgroundColor:`${b.color}15`},children:[e.jsx("span",{className:"kb-tag-selector__dot",style:{backgroundColor:b.color}}),e.jsx("span",{children:b.name}),e.jsx("button",{className:"kb-tag-selector__remove",onClick:g=>k(b.id,g),children:e.jsx(G,{content:"移除标签",showArrow:!1,children:e.jsx("span",{children:e.jsx(je,{size:11})})})})]},b.id)),e.jsxs("button",{className:"kb-tag-selector__add-btn",onClick:()=>d(b=>!b),children:[e.jsx(Le,{size:13}),e.jsx("span",{children:"标签"})]})]}),o&&e.jsxs("div",{className:"kb-tag-selector__dropdown",children:[e.jsxs("div",{className:"kb-tag-selector__tags",children:[t.length===0&&e.jsx("span",{className:"kb-tag-selector__empty",children:"暂无标签"}),t.map(b=>{const g=s.includes(b.id);return e.jsxs("button",{className:`kb-tag-selector__tag ${g?"kb-tag-selector__tag--selected":""}`,style:{"--tag-color":b.color,borderColor:g?b.color:void 0,backgroundColor:g?`${b.color}15`:void 0},onClick:()=>m(b.id),children:[e.jsx("span",{className:"kb-tag-selector__dot",style:{backgroundColor:b.color}}),e.jsx("span",{children:b.name}),c&&e.jsxs("span",{className:"kb-tag-selector__count",children:["(",b.count,")"]}),g&&e.jsx(je,{size:12})]},b.id)})]}),v?e.jsxs("div",{className:"kb-tag-selector__create",children:[e.jsx("input",{className:"kb-tag-selector__input",value:u,onChange:b=>p(b.target.value),onKeyDown:b=>{b.key==="Enter"&&l(),b.key==="Escape"&&(j(!1),p(""))},placeholder:"标签名称",autoFocus:!0}),e.jsx("button",{className:"kb-tag-selector__create-btn",onClick:l,children:"确定"})]}):e.jsxs("button",{className:"kb-tag-selector__new-btn",onClick:()=>j(!0),children:[e.jsx(Le,{size:13}),e.jsx("span",{children:"新建标签"})]})]})]})},Wn=({outputType:t,onOutputTypeChange:s,readOnly:r=!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:r?e.jsx("span",{className:"mcp-tool-selector__output-type-value",children:t==="image"?"图片":t==="video"?"视频":t==="audio"?"音频":t==="ppt"?"PPT":"文本"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${!t||t==="text"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>s==null?void 0:s(void 0),children:"文本"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${t==="image"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>s==null?void 0:s("image"),children:"图片"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${t==="video"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>s==null?void 0:s("video"),children:"视频"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${t==="audio"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>s==null?void 0:s("audio"),children:"音频"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${t==="ppt"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>s==null?void 0:s("ppt"),children:"PPT"})]})})]})}),qn=({note:t,allTags:s,noteTags:r,readOnly:a=!1,isSkillDirectory:c=!1,onUpdateNote:o,onSetNoteTags:d,onCreateTag:u})=>{var K;const[p,v]=n.useState(""),[j,N]=n.useState(!1),[m,k]=n.useState(!1),[l,S]=n.useState(null),b=n.useRef(null),g=n.useRef(null),z=n.useRef(null),P=n.useRef(null),$=Nn(),O=typeof window<"u"&&"speechSynthesis"in window,f=n.useMemo(()=>r.map(M=>M.id),[r]),[T,F]=n.useState(void 0);n.useEffect(()=>{var M;F(t&&c&&((M=t.metadata)==null?void 0:M.outputType)||void 0)},[t==null?void 0:t.id,c]);const R=t==null?void 0:t.metadata,J=R&&(R.sourceUrl||R.author||R.domain);n.useEffect(()=>{var Y;const M=t?`kb-note:${t.id}`:null;if(g.current&&(clearTimeout(g.current),g.current=null),b.current&&(clearTimeout(b.current),b.current=null),t)if(v(t.title),P.current=t.id,c&&!a){const Q=t.content||"";S(Q.trim()?Ct.isDSLContent(Q):null)}else S(null);else v(""),P.current=null,S(null);$.mediaType==="reading"&&M&&((Y=$.activeReadingSourceId)!=null&&Y.startsWith(M))&&$.stopPlayback()},[t==null?void 0:t.id,c,a]);const W=n.useCallback(M=>{v(M),t&&(g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{o(t.id,{title:M})},500))},[t,o]),U=n.useCallback(M=>{t&&(g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{o(t.id,{content:M})},500),c&&!a&&(b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{M.trim()?S(Ct.isDSLContent(M)):S(null)},500)))},[t,o,c,a]),te=n.useCallback(M=>{if(!t)return;F(M);const Y={...t.metadata,outputType:M};M||delete Y.outputType,q.updateNote(t.id,{metadata:Y})},[t]),y=n.useCallback(M=>{t&&d(t.id,M)},[t,d]),D=n.useCallback(()=>{var Z;if(!t)return;const M=`kb-note:${t.id}`;if($.mediaType==="reading"&&((Z=$.activeReadingSourceId)==null?void 0:Z.startsWith(M))){$.playing?$.pausePlayback():$.resumePlayback();return}const Q=Cn({elementId:M,title:t.title||"知识库笔记",content:[t.title,t.content].filter(Boolean).join(`
|
|
2
|
+
import{_ as qe}from"./startup-runtime-BrfuwjQS.js";import{P as n,a8 as e,dU as vs,eB as pe,gz as je,dV as Ns,mN as Ke,mM as Tt,c3 as ye,gy as Ie,oG as De,qr as Cs,qs as Ss,ab as G,cA as Le,qt as Ve,qu as Ae,pW as Rt,qv as be,qw as ve,qx as rt,qy as zt,bQ as Pt,qz as $t,qA as Ut,cO as se,c1 as Bt,nb as Xe,pp as Es,qB as Ye,qC as at,qD as _t,qE as Ms,qF as As,qG as Is,oJ as Ds,qH as Ls,fA as Ft,eI as Wt,cF as q,mJ as Ts,qI as Rs,qJ as zs,cH as Ps,mK as $s,dE as Us,qK as it,qL as Bs,pX as Ge,qM as Qe,qN as Fs,c$ as Te,d0 as qt,co as Ne,qO as Ws,qP as qs,ep as Ot,d1 as Os,qQ as Hs,ao as X,qR as Ht,qS as Kt,kF as Vt,c8 as Ks,eo as Vs,et as jt,m$ as Xs,eM as Ze,qT as Ys,qU as Gs,qV as Qs,qW as Zs,nm as Js,bP as en,R as tn,qX as yt,qY as vt,cn as Xt,qZ as sn,q_ as nn,q$ as rn,g1 as an,r0 as on,r1 as cn,r2 as Nt,n9 as ln,pU as dn,r3 as un,r4 as hn,r5 as mn}from"./ai-chat-BnWVpTEI.js";import{S as Je,g as fn,E as fe,b as gn}from"./skills-DHghxQBn.js";import{S as Ct}from"./skill-dsl-parser-ZR--uu5h.js";import{$ as pn,a as Yt,b as Gt,i as bn,M as xn,c as kn,e as wn,d as _n,f as St,g as jn,C as yn,h as ae}from"./editor-engines-9_72Ghfn.js";/* empty css */import{x as vn}from"./bootstrap-CQRLkOtk.js";import{ab as Nn,a9 as Cn}from"./tool-windows-Bf_pMml-.js";import"./diagram-engines-DpAsX7pc.js";import"./startup-app-CH3QzBb4.js";const ge="__system_skill__";function Sn(t){const s=new Date(t),r=new Date;return s.getFullYear()===r.getFullYear()&&s.getMonth()===r.getMonth()&&s.getDate()===r.getDate()?s.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):s.getFullYear()===r.getFullYear()?s.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit"}):s.toLocaleDateString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit"})}const En=({directories:t,notesByDir:s,noteTagsMap:r,noteCounts:a,selectedDirId:c,selectedNoteId:o,expandedDirIds:d,isCreatingDir:u,skillDirName:p="Skill",onSelectDir:v,onToggleExpand:j,onCreateDir:N,onCancelCreateDir:m,onRenameDir:k,onDeleteDir:l,onSelectNote:S,onCreateNote:b,onDeleteNote:g,onDuplicateDir:z,onDuplicateNote:P,onInsertNoteToCanvas:$})=>{const[O,f]=n.useState(""),[T,F]=n.useState(null),[R,J]=n.useState(""),[W,U]=n.useState(null);n.useEffect(()=>{const w=()=>U(null),B=()=>U(null);return document.addEventListener("click",w),document.addEventListener("scroll",B,!0),()=>{document.removeEventListener("click",w),document.removeEventListener("scroll",B,!0)}},[]);const te=n.useCallback((w,B,_,A=!1)=>{w.preventDefault(),w.stopPropagation(),U({x:w.clientX,y:w.clientY,type:B,id:_,isDefault:A})},[]),y=n.useCallback(async()=>{const w=O.trim();if(w)try{await N(w),f(""),m()}catch{}},[O,N,m]),D=n.useCallback(async w=>{const B=R.trim();if(B)try{await k(w,B),F(null)}catch{}},[R,k]);return e.jsxs("div",{className:"kb-tree",children:[u&&e.jsxs("div",{className:"kb-tree__create-row",children:[e.jsx("input",{className:"kb-tree__input",value:O,onChange:w=>f(w.target.value),onKeyDown:w=>{w.key==="Enter"&&y(),w.key==="Escape"&&m()},placeholder:"目录名称",autoFocus:!0}),e.jsx("button",{className:"kb-tree__icon-btn",onClick:y,children:e.jsx(pe,{size:14})}),e.jsx("button",{className:"kb-tree__icon-btn",onClick:m,children:e.jsx(je,{size:14})})]}),e.jsx("div",{className:"kb-tree__list",children:t.map(w=>e.jsx(Mn,{dir:w,isSelected:c===w.id,isExpanded:d.has(w.id),notes:s[w.id]||[],noteCount:a[w.id]||0,noteTagsMap:r,selectedNoteId:o,isRenaming:T===w.id,renameValue:R,onSelectDir:()=>{v(w.id),d.has(w.id)||j(w.id)},onToggleExpand:()=>{j(w.id),U(null)},onStartRename:()=>{F(w.id),J(w.name),U(null)},onRenameChange:J,onRenameConfirm:()=>D(w.id),onRenameCancel:()=>F(null),onDeleteDir:()=>{l(w.id),U(null)},onCreateNote:()=>{b(w.id),U(null)},onSelectNote:S,onDeleteNote:B=>{g(B),U(null)},onContextMenu:B=>te(B,"directory",w.id,w.isDefault),onNoteContextMenu:(B,_)=>te(B,"note",_),isSkillDir:w.name===p},w.id))}),W&&vs.createPortal(e.jsx("div",{className:"kb-context-menu",style:{top:W.y,left:W.x,zIndex:Ns.DROPDOWN_PORTAL},onClick:w=>w.stopPropagation(),children:W.type==="directory"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{z(W.id),U(null)},children:[e.jsx(Ke,{size:14}),e.jsx("span",{children:"复制目录"})]}),e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{var w;F(W.id),J(((w=t.find(B=>B.id===W.id))==null?void 0:w.name)||""),U(null)},children:[e.jsx(Tt,{size:14}),e.jsx("span",{children:"重命名"})]}),e.jsxs("div",{className:"kb-context-menu__item kb-context-menu__item--danger",onClick:()=>{l(W.id),U(null)},children:[e.jsx(ye,{size:14}),e.jsx("span",{children:"删除"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{P(W.id),U(null)},children:[e.jsx(Ke,{size:14}),e.jsx("span",{children:"创建副本"})]}),$&&e.jsxs("div",{className:"kb-context-menu__item",onClick:()=>{const B=Object.values(s).flat().find(_=>_.id===W.id);B&&$(B),U(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:()=>{g(W.id),U(null)},children:[e.jsx(ye,{size:14}),e.jsx("span",{children:"删除"})]})]})}),document.body)]})},Mn=({dir:t,isSelected:s,isExpanded:r,notes:a,noteCount:c,noteTagsMap:o,selectedNoteId:d,isRenaming:u,renameValue:p,isSkillDir:v=!1,onSelectDir:j,onToggleExpand:N,onStartRename:m,onRenameChange:k,onRenameConfirm:l,onRenameCancel:S,onDeleteDir:b,onCreateNote:g,onSelectNote:z,onDeleteNote:P,onContextMenu:$,onNoteContextMenu:O})=>e.jsxs("div",{className:`kb-tree__dir ${s?"kb-tree__dir--selected":""}`,children:[e.jsxs("div",{className:"kb-tree__dir-row",onClick:j,onContextMenu:$,children:[e.jsx("button",{className:"kb-tree__expand-btn",onClick:f=>{f.stopPropagation(),N()},children:r?e.jsx(Ie,{size:14}):e.jsx(De,{size:14})}),r?e.jsx(Cs,{size:16}):e.jsx(Ss,{size:16}),u?e.jsx("input",{className:"kb-tree__input kb-tree__input--inline",value:p,onChange:f=>k(f.target.value),onKeyDown:f=>{f.key==="Enter"&&l(),f.key==="Escape"&&S()},onClick:f=>f.stopPropagation(),autoFocus:!0}):e.jsx("span",{className:"kb-tree__dir-name",children:t.name}),e.jsx("span",{className:"kb-tree__dir-count",children:c}),e.jsxs("div",{className:"kb-tree__dir-actions",children:[e.jsx(G,{content:"新建笔记",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn",onClick:f=>{f.stopPropagation(),g()},children:e.jsx(Le,{size:12})})}),e.jsxs(e.Fragment,{children:[e.jsx(G,{content:"重命名",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn",onClick:f=>{f.stopPropagation(),m()},children:e.jsx(Tt,{size:12})})}),e.jsx(G,{content:"删除",showArrow:!1,children:e.jsx("button",{className:"kb-tree__icon-btn kb-tree__icon-btn--danger",onClick:f=>{f.stopPropagation(),b()},children:e.jsx(ye,{size:12})})})]})]})]}),r&&e.jsxs("div",{className:"kb-tree__notes",children:[v&&Je.map(f=>{const T=`${ge}${f.id}`,F=d===T;return e.jsxs("div",{className:`kb-tree__note-row kb-tree__note-row--system ${F?"kb-tree__note-row--selected":""}`,onClick:()=>z(T),children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(Ve,{size:14})}),e.jsx("div",{className:"kb-tree__note-content",children:e.jsxs("div",{className:"kb-tree__note-title",children:[f.name,e.jsx("span",{className:"kb-tree__system-badge",children:"系统"})]})})]},T)}),v&&fn().map(f=>{const T=`${fe}${f.id}`,F=d===T;return e.jsxs("div",{className:`kb-tree__note-row kb-tree__note-row--system ${F?"kb-tree__note-row--selected":""}`,onClick:()=>z(T),children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(Ve,{size:14})}),e.jsx("div",{className:"kb-tree__note-content",children:e.jsxs("div",{className:"kb-tree__note-title",children:[f.name,e.jsx("span",{className:"kb-tree__system-badge",children:"系统"})]})})]},T)}),a.length===0&&!v&&e.jsx("div",{className:"kb-tree__notes-empty",children:"暂无笔记"}),a.length===0&&v&&Je.length===0&&e.jsx("div",{className:"kb-tree__notes-empty",children:"暂无笔记"}),Array.from(new Map(a.map(f=>[f.id,f])).values()).map(f=>{const T=d===f.id,F=o[f.id]||[],R=f.metadata;return e.jsx(An,{note:f,isSelected:T,tags:F,metadata:R,onSelect:()=>z(f.id),onDelete:()=>P(f.id),onContextMenu:J=>O(J,f.id)},f.id)})]})]}),An=({note:t,isSelected:s,tags:r,metadata:a,onSelect:c,onDelete:o,onContextMenu:d})=>e.jsxs("div",{className:`kb-tree__note-row ${s?"kb-tree__note-row--selected":""}`,onClick:c,onContextMenu:d,children:[e.jsx("div",{className:"kb-tree__note-icon",children:e.jsx(Ae,{size:14})}),e.jsxs("div",{className:"kb-tree__note-content",children:[e.jsx("div",{className:"kb-tree__note-title",children:t.title||"无标题"}),(a==null?void 0:a.domain)&&e.jsxs("div",{className:"kb-tree__note-domain",children:[a.faviconUrl?e.jsx("img",{src:a.faviconUrl,alt:"",className:"kb-tree__favicon",onError:u=>{u.target.style.display="none"}}):e.jsx(Rt,{size:10}),e.jsx("span",{children:a.domain})]}),e.jsxs("div",{className:"kb-tree__note-meta",children:[r.length>0&&e.jsxs("div",{className:"kb-tree__note-tags",children:[r.slice(0,2).map(u=>e.jsx("span",{className:"kb-tree__tag-badge",style:{backgroundColor:`${u.color}20`,color:u.color},children:u.name},u.id)),r.length>2&&e.jsxs("span",{className:"kb-tree__tag-more",children:["+",r.length-2]})]}),r.length===0&&!(a!=null&&a.domain)&&e.jsx("span",{className:"kb-tree__note-time",children:Sn(t.updatedAt)})]})]}),e.jsx(G,{content:"删除笔记",showArrow:!1,children:e.jsx("button",{className:"kb-tree__note-delete",onClick:u=>{u.stopPropagation(),o()},children:e.jsx(ye,{size:12})})})]});function Oe(t){const s=t.url;if(!(s!=null&&s.startsWith(be)))return null;const r=s.slice(be.length),a=ve(t.alt||""),c=a.assetType||"image";if(c==="image")return null;const o=rt(t.title),d=a.label||"";return{type:"assetEmbed",assetId:r,assetType:c,label:d,width:o.width,height:o.height}}function Qt(t){if(t.children)for(let s=0;s<t.children.length;s++){const r=t.children[s];if(r.type==="image-block"){const a=Oe(r);if(a){t.children[s]=a;continue}}if(r.type==="paragraph"&&r.children){const a=[],c=[];for(const o of r.children){if(o.type==="image"){const d=Oe(o);if(d){a.push(d);continue}}c.push(o)}if(a.length>0){const o=[];c.length>0&&o.push({...r,children:c}),o.push(...a),t.children.splice(s,1,...o),s+=o.length-1;continue}}if(r.type==="image"){const a=Oe(r);if(a){t.children[s]=a;continue}}Qt(r)}}const In=pn("remarkAssetEmbed",()=>()=>Qt);function le(t){if(typeof t=="number"&&Number.isFinite(t)&&t>0)return Math.round(t);if(typeof t=="string"&&t.trim()){const s=Number.parseInt(t,10);if(Number.isFinite(s)&&s>0)return s}return null}const et=Yt("assetEmbed",()=>({inline:!1,group:"block",selectable:!0,draggable:!0,atom:!0,attrs:{assetId:{default:""},assetType:{default:"image"},label:{default:""},width:{default:null},height:{default:null}},parseMarkdown:{match:t=>{var s;if(t.type==="assetEmbed")return!0;if(t.type==="image-block"&&((s=t.url)!=null&&s.startsWith(be))){const r=ve(t.alt);if(r.assetType&&r.assetType!=="image")return!0}return!1},runner:(t,s,r)=>{if(s.type==="assetEmbed"){t.addNode(r,{assetId:s.assetId,assetType:s.assetType,label:s.label,width:le(s.width),height:le(s.height)});return}const a=s.url.slice(be.length),c=ve(s.alt),o=rt(s.title);t.addNode(r,{assetId:a,assetType:c.assetType||"video",label:c.label||"",width:le(o.width),height:le(o.height)})}},toMarkdown:{match:t=>t.type.name==="assetEmbed",runner:(t,s)=>{const{assetId:r,assetType:a,label:c}=s.attrs,o=c?`${a}|${c}`:a,d=zt({width:le(s.attrs.width),height:le(s.attrs.height)});t.openNode("paragraph"),t.addNode("image",void 0,void 0,{url:`${be}${r}`,alt:o,title:d}),t.closeNode()}},toDOM:t=>["div",{"data-type":"asset-embed","data-asset-id":t.attrs.assetId,"data-asset-type":t.attrs.assetType,"data-label":t.attrs.label,"data-width":t.attrs.width??"","data-height":t.attrs.height??""}],parseDOM:[{tag:'div[data-type="asset-embed"]',getAttrs:t=>({assetId:t.getAttribute("data-asset-id")||"",assetType:t.getAttribute("data-asset-type")||"image",label:t.getAttribute("data-label")||"",width:le(t.getAttribute("data-width")),height:le(t.getAttribute("data-height"))})}]})),Dn=({asset:t,style:s})=>{const r=n.useMemo(()=>({id:`markdown-audio-${t.id}`,type:"audio",points:[[0,0],[340,128]],children:[],audioUrl:t.url,title:t.name,previewImageUrl:t.thumbnail,prompt:t.prompt,createdAt:t.createdAt}),[t]),a=n.useMemo(()=>[{elementId:r.id,audioUrl:t.url,title:t.name,previewImageUrl:t.thumbnail}],[t.name,t.thumbnail,t.url,r.id]);return e.jsx("div",{className:"collimind-markdown-audio-card",style:s,children:e.jsx(vn,{element:r,selected:!1,canvasQueue:a})})};function re(t,s,r){return Math.min(Math.max(t,s),r)}function Re(t){if(!(typeof t!="number"||!Number.isFinite(t)||t<=0))return Math.round(t)}function ze(t,s,r){let a=re(t,r.minWidth,r.maxWidth),c=a/s;return(c<r.minHeight||c>r.maxHeight)&&(c=re(c,r.minHeight,r.maxHeight),a=c*s),{width:re(a,r.minWidth,r.maxWidth),height:re(c,r.minHeight,r.maxHeight)}}function Pe(t,s,r){let a=re(t,r.minHeight,r.maxHeight),c=a*s;return(c<r.minWidth||c>r.maxWidth)&&(c=re(c,r.minWidth,r.maxWidth),a=c/s),{width:re(c,r.minWidth,r.maxWidth),height:re(a,r.minHeight,r.maxHeight)}}const tt=Math.round(at*1.15);function Et(t){return re(Math.round(t*at/Ye),96,tt)}const Ln=({assetId:t,assetType:s,label:r,width:a,height:c,selected:o,readonly:d,updateAttrs:u})=>{const p=n.useSyncExternalStore($t,Ut),v=p.get(t),j=n.useRef(null),[N,m]=n.useState(null);n.useEffect(()=>{m(null)},[a,c]);const k=(N==null?void 0:N.width)??Re(a),l=(N==null?void 0:N.height)??Re(c),S=k??Ye,b=Et(S),g=s===se.AUDIO&&typeof l=="number"&&(l>240||l>S*.75),z=s===se.AUDIO?re(g?b:l??b,96,tt):l,P=n.useMemo(()=>{const f={};return k?f.width=`${k}px`:s===se.AUDIO?f.width="min(100%, 560px)":f.maxWidth=s===se.AUDIO?"min(100%, 560px)":"min(100%, 520px)",s===se.AUDIO?f.height=`${z}px`:l&&(f.height=`${l}px`),f},[s,l,k,z]),$=n.useCallback(f=>T=>{if(d)return;const F=j.current;if(!F)return;T.preventDefault(),T.stopPropagation();const R=F.getBoundingClientRect();if(!R.width||!R.height)return;const J=F.closest(".ProseMirror"),W=Math.max(160,((J==null?void 0:J.getBoundingClientRect().width)??R.width)-32),U=s===se.AUDIO?tt:1600,te=120,y=s===se.AUDIO?96:80,D={x:T.clientX,y:T.clientY,width:R.width,height:R.height};let w={width:Math.round(R.width),height:Math.round(R.height)};const B=A=>{const L=A.clientX-D.x,K=A.clientY-D.y,M=s!==se.AUDIO&&A.shiftKey&&D.width>0&&D.height>0,Y=f==="bottom"?D.width:re(D.width+L,te,W),Q=f==="right"?D.height:re(D.height+K,y,U);if(s===se.AUDIO){const Z=f==="bottom"?re(Math.round(Q*(Ye/at)),120,W):Math.round(Y),ie=Et(Z);w={width:Z,height:ie},m(w);return}if(M){const Z=D.width/D.height,ie={minWidth:te,maxWidth:W,minHeight:y,maxHeight:U};if(f==="right")w=ze(Y,Z,ie);else if(f==="bottom")w=Pe(Q,Z,ie);else{const Ce=Y/D.width,xe=Q/D.height;w=Math.abs(Ce-1)>=Math.abs(xe-1)?ze(Y,Z,ie):Pe(Q,Z,ie)}w={width:Math.round(w.width),height:Math.round(w.height)},m(w);return}w={width:Math.round(Y),height:Math.round(Q)},m(w)},_=()=>{document.removeEventListener("pointermove",B),document.removeEventListener("pointerup",_),m(w),u({width:w.width,height:w.height})};document.addEventListener("pointermove",B),document.addEventListener("pointerup",_,{once:!0})},[s,d,u]),O=(f,T)=>e.jsxs("div",{className:`collimind-asset-embed__shell ${o?"is-selected":""}`,"data-asset-type":s,"data-asset-id":t,children:[e.jsxs("div",{ref:j,className:"collimind-asset-embed__frame",style:P,children:[f,!d&&o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","data-resize-handle":"right",className:"collimind-asset-embed__handle collimind-asset-embed__handle--right",onPointerDown:$("right"),"aria-label":`调整${s===se.AUDIO?"音频":"视频"}宽度`}),e.jsx("button",{type:"button","data-resize-handle":"bottom",className:"collimind-asset-embed__handle collimind-asset-embed__handle--bottom",onPointerDown:$("bottom"),"aria-label":`调整${s===se.AUDIO?"音频":"视频"}高度`}),e.jsx("button",{type:"button","data-resize-handle":"corner",className:"collimind-asset-embed__handle collimind-asset-embed__handle--corner",onPointerDown:$("corner"),"aria-label":`同时调整${s===se.AUDIO?"音频":"视频"}宽高`})]})]}),T&&e.jsx("div",{className:"collimind-asset-embed__caption",children:T})]});return v?v.type===se.IMAGE?e.jsx(Bt,{className:"collimind-asset-embed__image",src:Xe(v.url),alt:r||v.name||"素材图片",showSkeleton:!1,eager:!0}):v.type===se.VIDEO?O(e.jsx("div",{className:"collimind-asset-embed__video-wrap",children:e.jsx(Es,{className:"collimind-asset-embed__video",src:v.url,poster:v.thumbnail,alt:r||v.name||"素材视频",thumbnailSize:"large",activateVideoOnClick:!0,playOnActivate:!0,videoProps:{controls:!0,preload:"metadata",playsInline:!0}})}),r||v.name):v.type===se.AUDIO?O(e.jsx(Dn,{asset:v,style:{width:"100%",maxHeight:"100%"}}),r||v.name):null:p.size===0?e.jsx("div",{className:"collimind-asset-embed__loading",style:P}):e.jsxs("div",{className:"collimind-asset-embed__missing",style:P,children:["素材不存在或已删除 (",t.slice(0,8),"…)"]})},Tn=Gt(et.node,()=>(t,s,r)=>{const a=document.createElement("div");a.className="collimind-asset-embed",a.setAttribute("data-asset-id",t.attrs.assetId);let c=t,o=!1,d=Pt.createRoot(a);const u=v=>{if(!s.editable)return;const j=r();j!=null&&s.dispatch(s.state.tr.setNodeMarkup(j,void 0,{...c.attrs,...v}))},p=()=>{d==null||d.render(e.jsx(Ln,{assetId:c.attrs.assetId,assetType:c.attrs.assetType,label:c.attrs.label,width:c.attrs.width??null,height:c.attrs.height??null,selected:o,readonly:!s.editable,updateAttrs:u}))};return p(),{dom:a,update:v=>v.type!==t.type?!1:(c=v,p(),!0),stopEvent:v=>{const j=v.target;return j instanceof HTMLElement?!!j.closest("[data-resize-handle]"):!1},selectNode:()=>{o=!0,a.classList.add("selected"),p()},deselectNode:()=>{o=!1,a.classList.remove("selected"),p()},destroy:()=>{if(d){const v=d;d=null,setTimeout(()=>v.unmount(),0)}}}}),Rn=[In,et.ctx,et.node,Tn].flat();function Me(t){if(typeof t=="number"&&Number.isFinite(t)&&t>0)return Math.round(t);if(typeof t=="string"&&t.trim()){const s=Number.parseInt(t,10);if(Number.isFinite(s)&&s>0)return s}return null}const st=Yt("image-block",()=>({inline:!1,group:"block",selectable:!0,draggable:!0,isolating:!0,marks:"",atom:!0,priority:100,attrs:{src:{default:""},alt:{default:""},caption:{default:""},ratio:{default:1},width:{default:null},height:{default:null}},parseMarkdown:{match:t=>{var s;if(t.type!=="image-block")return!1;if((s=t.url)!=null&&s.startsWith(be)){const r=ve(t.alt);if(r.assetType&&r.assetType!=="image")return!1}return!0},runner:(t,s,r)=>{const a=typeof s.alt=="string"?s.alt:"",c=rt(s.title),o=_t(a)?Number.parseFloat(a):1;t.addNode(r,{src:s.url,alt:_t(a)?"":a,caption:c.caption,ratio:Number.isFinite(o)&&o>0?o:1,width:c.width??null,height:c.height??null})}},toMarkdown:{match:t=>t.type.name==="image-block",runner:(t,s)=>{const r=zt({width:Me(s.attrs.width),height:Me(s.attrs.height),caption:s.attrs.caption}),a=s.attrs.alt||(!s.attrs.width&&!s.attrs.height&&s.attrs.ratio&&s.attrs.ratio!==1?`${Number.parseFloat(String(s.attrs.ratio)).toFixed(2)}`:"");t.openNode("paragraph"),t.addNode("image",void 0,void 0,{title:r,url:s.attrs.src,alt:a}),t.closeNode()}},toDOM:t=>["div",{"data-type":"opentu-image-block","data-src":t.attrs.src,"data-alt":t.attrs.alt,"data-caption":t.attrs.caption,"data-ratio":t.attrs.ratio,"data-width":t.attrs.width??"","data-height":t.attrs.height??""}],parseDOM:[{tag:'div[data-type="opentu-image-block"]',getAttrs:t=>({src:t.getAttribute("data-src")||"",alt:t.getAttribute("data-alt")||"",caption:t.getAttribute("data-caption")||"",ratio:Number(t.getAttribute("data-ratio")??1)||1,width:Me(t.getAttribute("data-width")),height:Me(t.getAttribute("data-height"))})},{tag:'img[data-type="image-block"]',getAttrs:t=>({src:t.getAttribute("src")||"",alt:"",caption:t.getAttribute("caption")||"",ratio:Number(t.getAttribute("ratio")??1)||1,width:null,height:null})}]}));function zn({attrs:t,readonly:s,config:r,updateAttrs:a}){const c=n.useRef(null),[o,d]=n.useState(t.src||""),[u,p]=n.useState(!1);n.useEffect(()=>{d(t.src||"")},[t.src]);const v=n.useCallback(()=>{a({src:o.trim()})},[o,a]),j=n.useCallback(async N=>{var k;const m=(k=N.target.files)==null?void 0:k[0];if(m)try{const l=await r.onUpload(m);if(!l)return;d(l),a({src:l})}catch(l){console.error("Failed to upload image block file",l)}finally{N.target.value=""}},[r,a]);return e.jsxs("div",{className:"image-edit collimind-markdown-image-block__edit",children:[e.jsx("div",{className:"image-icon",children:r.imageIcon||"🌌"}),e.jsxs("div",{className:`link-importer ${u?"focus":""}`,children:[e.jsx("input",{className:"link-input-area",value:o,disabled:s,onChange:N=>d(N.target.value),onFocus:()=>p(!0),onBlur:()=>p(!1),onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),v())}}),!o&&e.jsxs("div",{className:"placeholder",children:[e.jsx("input",{ref:c,className:"hidden",type:"file",accept:"image/*",disabled:s,onChange:j}),e.jsx("button",{type:"button",className:"uploader",disabled:s,onMouseDown:N=>N.preventDefault(),onClick:()=>{var N;return(N=c.current)==null?void 0:N.click()},children:r.uploadButton||"Upload"}),e.jsx("span",{className:"text",children:r.uploadPlaceholderText})]})]}),!!o&&e.jsx("button",{type:"button",className:"confirm",disabled:s,onMouseDown:N=>N.preventDefault(),onClick:v,children:r.confirmButton||"Confirm"})]})}function Pn({attrs:t,selected:s,readonly:r,updateAttrs:a}){const c=n.useRef(null),o=n.useSyncExternalStore($t,Ut),[d,u]=n.useState(null);n.useEffect(()=>{u(null)},[t.width,t.height]);const p=n.useMemo(()=>Ms(t.src),[t.src]),v=p?o.get(p):void 0,j=n.useMemo(()=>ve(t.alt),[t.alt]),N=p?j.label||(v==null?void 0:v.name)||"素材图片":t.alt||"图片",m=n.useMemo(()=>p?!v||v.type!==se.IMAGE?null:Xe(v.url):Xe(t.src),[v,p,t.src]),k=(d==null?void 0:d.width)??Re(t.width),l=(d==null?void 0:d.height)??Re(t.height),S=n.useMemo(()=>{const z={};return k?z.width=`${k}px`:z.maxWidth="min(100%, 420px)",l&&(z.height=`${l}px`),z},[l,k]),b=n.useMemo(()=>k&&l?{width:"100%",height:"100%",objectFit:"fill"}:k?{width:"100%",height:"auto"}:l?{width:"auto",height:"100%"}:{width:"100%",height:"auto"},[l,k]),g=n.useCallback(z=>P=>{if(r)return;const $=c.current;if(!$)return;P.preventDefault(),P.stopPropagation();const O=$.getBoundingClientRect();if(!O.width||!O.height)return;const f=$.closest(".ProseMirror"),T=Math.max(120,((f==null?void 0:f.getBoundingClientRect().width)??O.width)-32),F=80,R=80,J=1600,W={x:P.clientX,y:P.clientY,width:O.width,height:O.height};let U={width:Math.round(O.width),height:Math.round(O.height)};const te=D=>{const w=D.clientX-W.x,B=D.clientY-W.y,_=D.shiftKey&&W.width>0&&W.height>0,A=z==="bottom"?W.width:re(W.width+w,F,T),L=z==="right"?W.height:re(W.height+B,R,J);if(_){const K=W.width/W.height,M={minWidth:F,maxWidth:T,minHeight:R,maxHeight:J};if(z==="right")U=ze(A,K,M);else if(z==="bottom")U=Pe(L,K,M);else{const Y=A/W.width,Q=L/W.height;U=Math.abs(Y-1)>=Math.abs(Q-1)?ze(A,K,M):Pe(L,K,M)}U={width:Math.round(U.width),height:Math.round(U.height)},u(U);return}U={width:Math.round(A),height:Math.round(L)},u(U)},y=()=>{document.removeEventListener("pointermove",te),document.removeEventListener("pointerup",y),u(U),a({width:U.width,height:U.height})};document.addEventListener("pointermove",te),document.addEventListener("pointerup",y,{once:!0})},[r,a]);return p&&!v&&o.size===0?e.jsx("div",{className:"collimind-markdown-image-block__loading"}):m?e.jsxs("div",{className:`collimind-markdown-image-block__shell ${s?"is-selected":""}`,"data-asset-id":p||void 0,children:[e.jsxs("div",{ref:c,className:"collimind-markdown-image-block__frame",style:S,children:[e.jsx(Bt,{className:"collimind-markdown-image-block__image",src:m,alt:N,draggable:!1,style:b,showSkeleton:!1,eager:!0}),!r&&s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","data-resize-handle":"right",className:"collimind-markdown-image-block__handle collimind-markdown-image-block__handle--right",onPointerDown:g("right"),"aria-label":"调整图片宽度"}),e.jsx("button",{type:"button","data-resize-handle":"bottom",className:"collimind-markdown-image-block__handle collimind-markdown-image-block__handle--bottom",onPointerDown:g("bottom"),"aria-label":"调整图片高度"}),e.jsx("button",{type:"button","data-resize-handle":"corner",className:"collimind-markdown-image-block__handle collimind-markdown-image-block__handle--corner",onPointerDown:g("corner"),"aria-label":"同时调整图片宽高"})]})]}),t.caption&&e.jsx("div",{className:"collimind-markdown-image-block__caption",children:t.caption})]}):e.jsx("div",{className:"collimind-markdown-image-block__missing",children:p?`图片素材不存在或已删除 (${p.slice(0,8)}…)`:"图片地址无效"})}function $n(t){return t.attrs.src?e.jsx(Pn,{...t}):e.jsx(zn,{...t})}const Un=Gt(st.node,t=>{const s=t.get(bn.key);return(r,a,c)=>{const o=document.createElement("div");o.className="milkdown-image-block collimind-markdown-image-block",o.draggable=!0;let d=r,u=!1,p=Pt.createRoot(o);const v=m=>{if(!a.editable)return;const k=c();k!=null&&a.dispatch(a.state.tr.setNodeMarkup(k,void 0,{...d.attrs,...m}))},j=()=>{p==null||p.render(e.jsx($n,{attrs:d.attrs,selected:u,readonly:!a.editable,config:s,updateAttrs:v}))};j();const N=m=>{var l;const k=(l=m.detail)==null?void 0:l.src;k&&typeof k=="string"&&v({src:k})};return o.addEventListener("asset-commit",N),{dom:o,update:m=>m.type!==r.type?!1:(d=m,j(),!0),stopEvent:m=>{const k=m.target;return k instanceof HTMLElement?!!(k.closest(".image-edit")||k.closest("[data-resize-handle]")):!1},selectNode:()=>{u=!0,o.classList.add("selected"),j()},deselectNode:()=>{u=!1,o.classList.remove("selected"),j()},destroy:()=>{if(o.removeEventListener("asset-commit",N),p){const m=p;p=null,setTimeout(()=>m.unmount(),0)}}}}}),Bn=[st.ctx,st.node,Un].flat();function He(t){return new Promise((s,r)=>{const a=new FileReader;a.onload=()=>s(typeof a.result=="string"?a.result:""),a.onerror=()=>r(a.error),a.readAsDataURL(t)})}function Fn({markdown:t,onChange:s,placeholder:r,readOnly:a,editorRef:c,enableAssetEmbeds:o}){const d=n.useRef(s);n.useEffect(()=>{d.current=s},[s]);const u=n.useRef(t),p=n.useRef(null),v=n.useRef(null),j=n.useRef(null),{get:N,loading:m}=kn(k=>{const l=new yn({root:k,defaultValue:t,features:{[ae.CodeMirror]:!0,[ae.ListItem]:!0,[ae.LinkTooltip]:!0,[ae.Cursor]:!0,[ae.ImageBlock]:!0,[ae.BlockEdit]:!0,[ae.Toolbar]:!0,[ae.Placeholder]:!0,[ae.Table]:!0,[ae.Latex]:!0},featureConfigs:{[ae.Placeholder]:{text:r||"开始编辑..."},[ae.Cursor]:{color:"#3b82f6",width:4},[ae.ImageBlock]:{onUpload:He,inlineOnUpload:He,blockOnUpload:He},[ae.Latex]:{katexOptions:{strict:"ignore"}}}});return l.editor.use(Bn),o&&l.editor.use(Rn),d.current&&l.on(S=>{S.markdownUpdated((b,g)=>{if(p.current&&clearTimeout(p.current),g!==u.current){u.current=g;const z=d.current,P=()=>{v.current=null,z==null||z(g)};v.current=P,p.current=setTimeout(P,50)}})}),j.current=l,l},[]);return n.useEffect(()=>{if(m)return;const k=j.current;if(k){if(a)try{k.setReadonly(!0)}catch{}return c.current={getMarkdown:()=>u.current,setMarkdown:l=>{var S;try{u.current=l,(S=k.editor)==null||S.action(St(l))}catch{}},insertMarkdown:l=>{var S;try{(S=k.editor)==null||S.action(_n(l))}catch{}},focus:()=>{var l,S;try{(S=(l=k.editor)==null?void 0:l.ctx.get(wn))==null||S.focus()}catch{}}},()=>{var l;p.current&&(clearTimeout(p.current),p.current=null),(l=v.current)==null||l.call(v),v.current=null,c.current=null}}},[N,a,c,m]),n.useEffect(()=>{if(m)return;const k=j.current;if(k)try{k.setReadonly(!!a)}catch{}},[a,m]),n.useEffect(()=>{var l,S;if(m)return;const k=j.current;if(k)try{const b=u.current;t!==b&&(p.current&&(clearTimeout(p.current),p.current=null),(l=v.current)==null||l.call(v),u.current=t,(S=k.editor)==null||S.action(St(t)))}catch{}},[t,m]),e.jsx(jn,{})}const ot=n.memo(n.forwardRef(function({markdown:s,sourceMarkdown:r,onChange:a,placeholder:c="开始编辑...",readOnly:o=!1,className:d="",showModeSwitch:u=!0,initialMode:p="wysiwyg",enableAssetEmbeds:v=!1,enableAssetLibraryImagePicker:j=!1},N){const m=n.useContext(As),k=n.useRef(null),l=n.useRef(null),S=n.useRef(null),b=n.useRef(null),[g,z]=n.useState(p),[P,$]=n.useState(r||s),[O,f]=n.useState(!1),[T,F]=n.useState(!1),[R,J]=n.useState(p!=="wysiwyg"),W=n.useRef(r||s),U=j&&!!m;n.useEffect(()=>{W.current=P},[P]),n.useEffect(()=>{if(g!=="wysiwyg"){J(!1);return}let _=0,A=!1;const L=()=>{const K=S.current;if(!A){if(K!=null&&K.isConnected){J(!0);return}_=requestAnimationFrame(L)}};return L(),()=>{A=!0,_&&cancelAnimationFrame(_)}},[g]);const te=n.useCallback(_=>{var A,L;_!==g&&(_==="source"?$(r||((A=k.current)==null?void 0:A.getMarkdown())||s):r||((L=k.current)==null||L.setMarkdown(P),a==null||a(P)),z(_))},[g,s,P,r,a]),y=n.useCallback(_=>{const A=_.target.value;$(A),a==null||a(A)},[a]),D=n.useCallback(_=>{var L,K;if(!_)return;const A=g==="source"?W.current:r||((L=k.current)==null?void 0:L.getMarkdown())||W.current||s;if(g==="source"&&l.current){const M=l.current,Y=M.selectionStart??A.length,Q=M.selectionEnd??A.length,Z=`${A.slice(0,Y)}${_}${A.slice(Q)}`;$(Z),a==null||a(Z),requestAnimationFrame(()=>{M.focus();const ie=Y+_.length;M.setSelectionRange(ie,ie)});return}(K=k.current)==null||K.insertMarkdown(_),requestAnimationFrame(()=>{var Y;const M=(Y=k.current)==null?void 0:Y.getMarkdown();typeof M=="string"&&$(M)})},[s,g,a,r]);n.useImperativeHandle(N,()=>({getMarkdown:()=>{var _;return g==="source"?P:((_=k.current)==null?void 0:_.getMarkdown())||P},setMarkdown:_=>{var A;$(_),(A=k.current)==null||A.setMarkdown(_)},insertMarkdown:D,focus:()=>{var _,A;g==="source"?(_=l.current)==null||_.focus():(A=k.current)==null||A.focus()},getMode:()=>g,setMode:te}),[te,D,g,P]),n.useEffect(()=>{const _=r||s;_!==P&&$(_)},[s,P,r]);const w=n.useCallback(()=>{const _=S.current;if(!_){b.current=null,F(!1);return}const A=_.ownerDocument.activeElement,L=A instanceof HTMLElement?A.closest(".image-edit"):null,K=L&&_.contains(L)?L:_.querySelector(".image-edit");b.current=K??null,F(!!K)},[]),B=n.useCallback((_,A)=>{if(!_)return!1;const L=_.closest(".milkdown-image-block");return L?(L.dispatchEvent(new CustomEvent("asset-commit",{detail:{src:`asset://${A}`}})),!0):!1},[]);return n.useEffect(()=>{if(!U||o||g!=="wysiwyg"||!S.current){b.current=null,F(!1);return}const _=S.current;let A=0;const L=()=>{cancelAnimationFrame(A),A=requestAnimationFrame(w)},K=Y=>{const Q=Y.target;if(!(Q instanceof HTMLElement))return;const Z=Q.closest(".image-edit");if(Z&&_.contains(Z)){b.current=Z,F(!0);return}L()};L(),_.addEventListener("focusin",K),_.addEventListener("click",K,!0);const M=new MutationObserver(L);return M.observe(_,{childList:!0,subtree:!0}),()=>{cancelAnimationFrame(A),M.disconnect(),_.removeEventListener("focusin",K),_.removeEventListener("click",K,!0)}},[U,g,o,w]),e.jsxs("div",{className:`collimind-markdown-editor ${d}`,"data-readonly":o,"data-mode":g,"data-asset-embeds":v,children:[U&&T&&e.jsxs("button",{type:"button",className:"collimind-markdown-image-library-overlay",style:{right:u?68:8},onClick:()=>{w(),b.current&&f(!0)},children:[e.jsx(Is,{className:"collimind-icon-sm"}),e.jsx("span",{children:"从素材库插图"})]}),u&&e.jsxs("div",{className:"collimind-markdown-editor-mode-switch",children:[e.jsx(G,{content:"所见即所得模式",showArrow:!1,children:e.jsx("button",{type:"button",className:`collimind-markdown-editor-mode-btn ${g==="wysiwyg"?"active":""}`,onClick:()=>te("wysiwyg"),children:e.jsx(Ds,{className:"collimind-icon-sm"})})}),e.jsx(G,{content:"Markdown 源码模式",showArrow:!1,children:e.jsx("button",{type:"button",className:`collimind-markdown-editor-mode-btn ${g==="source"?"active":""}`,onClick:()=>te("source"),children:e.jsx(Ls,{className:"collimind-icon-sm"})})})]}),e.jsx("div",{ref:S,style:{display:g==="wysiwyg"?"contents":"none"},children:R&&e.jsx(xn,{children:e.jsx(Fn,{markdown:s,onChange:a,placeholder:c,readOnly:o,editorRef:k,enableAssetEmbeds:v})})}),g==="source"&&e.jsx("textarea",{ref:l,className:"collimind-markdown-editor-source",value:P,onChange:y,placeholder:c,readOnly:o||!!r,spellCheck:!1}),U&&O&&e.jsx(Ft,{isOpen:O,onClose:()=>{f(!1),w()},mode:Wt.SELECT,filterType:se.IMAGE,onSelect:_=>{var L;const A=b.current??((L=S.current)==null?void 0:L.querySelector(".image-edit"))??null;if(!B(A,_.id)){f(!1);return}f(!1),requestAnimationFrame(w)},selectButtonText:"插入素材库图片"})]})})),Mt=({allTags:t,selectedTagIds:s,onSelectedChange:r,onCreateTag:a,showCount:c=!1})=>{const[o,d]=n.useState(!1),[u,p]=n.useState(""),[v,j]=n.useState(!1),N=n.useRef(null);n.useEffect(()=>{if(!o)return;const b=g=>{N.current&&!N.current.contains(g.target)&&(d(!1),j(!1),p(""))};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[o]);const m=n.useCallback(b=>{const g=s.includes(b)?s.filter(z=>z!==b):[...s,b];r(g)},[s,r]),k=n.useCallback((b,g)=>{g.stopPropagation(),r(s.filter(z=>z!==b))},[s,r]),l=n.useCallback(async()=>{const b=u.trim();if(b)try{const g=await a(b);r([...s,g.id]),p(""),j(!1)}catch{}},[u,a,s,r]),S=t.filter(b=>s.includes(b.id));return e.jsxs("div",{className:"kb-tag-selector",ref:N,children:[e.jsxs("div",{className:"kb-tag-selector__selected",children:[S.map(b=>e.jsxs("span",{className:"kb-tag-selector__tag kb-tag-selector__tag--selected",style:{"--tag-color":b.color,borderColor:b.color,backgroundColor:`${b.color}15`},children:[e.jsx("span",{className:"kb-tag-selector__dot",style:{backgroundColor:b.color}}),e.jsx("span",{children:b.name}),e.jsx("button",{className:"kb-tag-selector__remove",onClick:g=>k(b.id,g),children:e.jsx(G,{content:"移除标签",showArrow:!1,children:e.jsx("span",{children:e.jsx(je,{size:11})})})})]},b.id)),e.jsxs("button",{className:"kb-tag-selector__add-btn",onClick:()=>d(b=>!b),children:[e.jsx(Le,{size:13}),e.jsx("span",{children:"标签"})]})]}),o&&e.jsxs("div",{className:"kb-tag-selector__dropdown",children:[e.jsxs("div",{className:"kb-tag-selector__tags",children:[t.length===0&&e.jsx("span",{className:"kb-tag-selector__empty",children:"暂无标签"}),t.map(b=>{const g=s.includes(b.id);return e.jsxs("button",{className:`kb-tag-selector__tag ${g?"kb-tag-selector__tag--selected":""}`,style:{"--tag-color":b.color,borderColor:g?b.color:void 0,backgroundColor:g?`${b.color}15`:void 0},onClick:()=>m(b.id),children:[e.jsx("span",{className:"kb-tag-selector__dot",style:{backgroundColor:b.color}}),e.jsx("span",{children:b.name}),c&&e.jsxs("span",{className:"kb-tag-selector__count",children:["(",b.count,")"]}),g&&e.jsx(je,{size:12})]},b.id)})]}),v?e.jsxs("div",{className:"kb-tag-selector__create",children:[e.jsx("input",{className:"kb-tag-selector__input",value:u,onChange:b=>p(b.target.value),onKeyDown:b=>{b.key==="Enter"&&l(),b.key==="Escape"&&(j(!1),p(""))},placeholder:"标签名称",autoFocus:!0}),e.jsx("button",{className:"kb-tag-selector__create-btn",onClick:l,children:"确定"})]}):e.jsxs("button",{className:"kb-tag-selector__new-btn",onClick:()=>j(!0),children:[e.jsx(Le,{size:13}),e.jsx("span",{children:"新建标签"})]})]})]})},Wn=({outputType:t,onOutputTypeChange:s,readOnly:r=!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:r?e.jsx("span",{className:"mcp-tool-selector__output-type-value",children:t==="image"?"图片":t==="video"?"视频":t==="audio"?"音频":t==="ppt"?"PPT":"文本"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${!t||t==="text"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>s==null?void 0:s(void 0),children:"文本"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${t==="image"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>s==null?void 0:s("image"),children:"图片"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${t==="video"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>s==null?void 0:s("video"),children:"视频"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${t==="audio"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>s==null?void 0:s("audio"),children:"音频"}),e.jsx("button",{className:`mcp-tool-selector__output-type-btn ${t==="ppt"?"mcp-tool-selector__output-type-btn--active":""}`,onClick:()=>s==null?void 0:s("ppt"),children:"PPT"})]})})]})}),qn=({note:t,allTags:s,noteTags:r,readOnly:a=!1,isSkillDirectory:c=!1,onUpdateNote:o,onSetNoteTags:d,onCreateTag:u})=>{var K;const[p,v]=n.useState(""),[j,N]=n.useState(!1),[m,k]=n.useState(!1),[l,S]=n.useState(null),b=n.useRef(null),g=n.useRef(null),z=n.useRef(null),P=n.useRef(null),$=Nn(),O=typeof window<"u"&&"speechSynthesis"in window,f=n.useMemo(()=>r.map(M=>M.id),[r]),[T,F]=n.useState(void 0);n.useEffect(()=>{var M;F(t&&c&&((M=t.metadata)==null?void 0:M.outputType)||void 0)},[t==null?void 0:t.id,c]);const R=t==null?void 0:t.metadata,J=R&&(R.sourceUrl||R.author||R.domain);n.useEffect(()=>{var Y;const M=t?`kb-note:${t.id}`:null;if(g.current&&(clearTimeout(g.current),g.current=null),b.current&&(clearTimeout(b.current),b.current=null),t)if(v(t.title),P.current=t.id,c&&!a){const Q=t.content||"";S(Q.trim()?Ct.isDSLContent(Q):null)}else S(null);else v(""),P.current=null,S(null);$.mediaType==="reading"&&M&&((Y=$.activeReadingSourceId)!=null&&Y.startsWith(M))&&$.stopPlayback()},[t==null?void 0:t.id,c,a]);const W=n.useCallback(M=>{v(M),t&&(g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{o(t.id,{title:M})},500))},[t,o]),U=n.useCallback(M=>{t&&(g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{o(t.id,{content:M})},500),c&&!a&&(b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{M.trim()?S(Ct.isDSLContent(M)):S(null)},500)))},[t,o,c,a]),te=n.useCallback(M=>{if(!t)return;F(M);const Y={...t.metadata,outputType:M};M||delete Y.outputType,q.updateNote(t.id,{metadata:Y})},[t]),y=n.useCallback(M=>{t&&d(t.id,M)},[t,d]),D=n.useCallback(()=>{var Z;if(!t)return;const M=`kb-note:${t.id}`;if($.mediaType==="reading"&&((Z=$.activeReadingSourceId)==null?void 0:Z.startsWith(M))){$.playing?$.pausePlayback():$.resumePlayback();return}const Q=Cn({elementId:M,title:t.title||"知识库笔记",content:[t.title,t.content].filter(Boolean).join(`
|
|
3
3
|
|
|
4
4
|
`),origin:{kind:"kb-note",id:t.id}});Q&&Ts({source:Q,queue:[Q]})},[t,$]),w=n.useCallback(async()=>{if(!t)return;const M=await Rs(t.id);if(!M)return;const Y=new Blob([M.content],{type:"text/markdown;charset=utf-8"}),Q=URL.createObjectURL(Y),Z=document.createElement("a");Z.href=Q,Z.download=M.filename,document.body.appendChild(Z),Z.click(),document.body.removeChild(Z),URL.revokeObjectURL(Q)},[t]),B=n.useCallback(()=>{a||k(!0)},[a]),_=n.useCallback(M=>{var Y;(Y=z.current)==null||Y.insertMarkdown(zs(M)),k(!1)},[]);if(n.useEffect(()=>()=>{g.current&&clearTimeout(g.current),b.current&&clearTimeout(b.current)},[]),!t)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(Ps,{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 A=`kb-note:${t.id}`,L=$.mediaType==="reading"&&((K=$.activeReadingSourceId)==null?void 0:K.startsWith(A));return e.jsxs("div",{className:`kb-note-editor ${a?"kb-note-editor--readonly":""}`,children:[a&&e.jsxs("div",{className:"kb-note-editor__readonly-banner",children:[e.jsx(Ve,{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:p,onChange:M=>!a&&W(M.target.value),placeholder:"笔记标题",readOnly:a}),e.jsxs("div",{className:"kb-note-editor__actions",children:[O&&e.jsx(G,{content:L?$.playing?"暂停朗读":"继续朗读":"语音朗读",showArrow:!1,children:e.jsx("button",{className:`kb-note-editor__action-btn ${L?"kb-note-editor__action-btn--active":""}`,onClick:D,children:L&&$.playing?e.jsx($s,{size:14}):e.jsx(Us,{size:14})})}),O&&L&&e.jsx(G,{content:"停止朗读",showArrow:!1,children:e.jsx("button",{className:"kb-note-editor__action-btn kb-note-editor__action-btn--danger",onClick:$.stopPlayback,children:"■"})}),e.jsx(G,{content:"导出 Markdown",showArrow:!1,children:e.jsx("button",{className:"kb-note-editor__action-btn",onClick:w,children:e.jsx(it,{size:14})})}),!a&&e.jsx(G,{content:"插入素材",showArrow:!1,children:e.jsx("button",{className:"kb-note-editor__action-btn",onClick:B,children:e.jsx(Bs,{size:14})})})]})]}),J&&e.jsxs("div",{className:`kb-note-editor__metadata-section ${j?"kb-note-editor__metadata-section--collapsed":""}`,children:[e.jsx(G,{content:j?"展开来源信息":"收起来源信息",showArrow:!1,children:e.jsxs("button",{className:"kb-note-editor__metadata-toggle",onClick:()=>N(!j),children:[j?e.jsx(De,{size:14}):e.jsx(Ie,{size:14}),e.jsx("span",{children:"来源信息"})]})}),j&&e.jsxs("div",{className:"kb-note-editor__metadata-collapsed",children:[R.author&&e.jsxs("span",{className:"kb-note-editor__metadata-collapsed-item",children:[e.jsx(Ge,{size:10}),e.jsx("span",{children:R.author})]}),R.sourceUrl&&e.jsx(G,{content:R.sourceUrl,showArrow:!1,children:e.jsxs("a",{href:R.sourceUrl,target:"_blank",rel:"noopener noreferrer",className:"kb-note-editor__metadata-collapsed-link",onClick:M=>M.stopPropagation(),children:[e.jsx(Qe,{size:10}),e.jsx("span",{children:R.domain||R.sourceUrl})]})})]}),!j&&e.jsxs("div",{className:"kb-note-editor__metadata-body",children:[e.jsx("div",{className:"kb-note-editor__tags",children:e.jsx(Mt,{allTags:s,selectedTagIds:f,onSelectedChange:y,onCreateTag:u})}),e.jsxs("div",{className:"kb-note-editor__metadata-info",children:[R.domain&&e.jsxs("span",{className:"kb-note-editor__metadata-item",children:[R.faviconUrl?e.jsx("img",{src:R.faviconUrl,alt:"",className:"kb-note-editor__favicon",onError:M=>{M.currentTarget.style.display="none"}}):e.jsx(Rt,{size:12}),e.jsx("span",{children:R.domain})]}),R.author&&e.jsxs("span",{className:"kb-note-editor__metadata-item",children:[e.jsx(Ge,{size:12}),e.jsx("span",{children:R.author})]}),R.publishedAt&&e.jsxs("span",{className:"kb-note-editor__metadata-item",children:[e.jsx(Fs,{size:12}),e.jsx("span",{children:R.publishedAt})]})]}),R.sourceUrl&&e.jsx("a",{href:R.sourceUrl,target:"_blank",rel:"noopener noreferrer",className:"kb-note-editor__source-link",children:R.sourceUrl}),R.description&&e.jsx("p",{className:"kb-note-editor__metadata-desc",children:R.description})]})]}),!J&&e.jsx("div",{className:"kb-note-editor__tags",children:e.jsx(Mt,{allTags:s,selectedTagIds:f,onSelectedChange:y,onCreateTag:u})}),c&&e.jsx("div",{className:"kb-note-editor__mcp-tools",children:e.jsx(Wn,{outputType:T,onOutputTypeChange:te,readOnly:a})}),e.jsx("div",{className:"kb-note-editor__content",children:e.jsx(ot,{ref:z,markdown:t.content,onChange:a?void 0:U,placeholder:"开始写点什么...",showModeSwitch:!a,readOnly:a,enableAssetEmbeds:!0,enableAssetLibraryImagePicker:!a,className:"kb-note-markdown"},t.id)}),c&&!a&&l!==null&&e.jsx("div",{className:`kb-note-editor__dsl-status ${l?"kb-note-editor__dsl-status--valid":"kb-note-editor__dsl-status--fallback"}`,children:l?"✓ 已识别为工作流 DSL(正则解析),将直接执行":"⚡ 将由 AI 解析为工作流(大模型解析)"}),m&&e.jsx(Ft,{isOpen:m,onClose:()=>k(!1),mode:Wt.SELECT,onSelect:_,selectButtonText:"插入到笔记"})]})},On=({allTags:t,selectedTagIds:s,onSelectedChange:r})=>{const[a,c]=n.useState(""),[o,d]=n.useState(!1),u=n.useMemo(()=>{if(!a)return t;const N=a.toLowerCase();return t.filter(m=>m.name.toLowerCase().includes(N))},[t,a]),p=N=>{const m=s.includes(N)?s.filter(k=>k!==N):[...s,N];r(m)},v=()=>{r([]),d(!1)},j=e.jsxs("div",{className:"kb-filter-dropdown__content",children:[e.jsx("div",{className:"kb-filter-dropdown__search",children:e.jsx(Te,{value:a,onChange:N=>c(N),placeholder:"搜索标签...",prefixIcon:e.jsx(qt,{size:14}),size:"small",clearable:!0})}),e.jsx("div",{className:"kb-filter-dropdown__list",children:u.length>0?u.map(N=>{const m=s.includes(N.id);return e.jsxs("div",{className:`kb-filter-dropdown__item ${m?"is-selected":""}`,onClick:()=>p(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(pe,{size:14,className:"kb-filter-dropdown__item-check"})]},N.id)}):e.jsx("div",{className:"kb-filter-dropdown__empty",children:"无匹配标签"})}),s.length>0&&e.jsx("div",{className:"kb-filter-dropdown__footer",children:e.jsxs(Ne,{theme:"default",variant:"text",size:"small",onClick:v,className:"kb-filter-dropdown__clear-btn",children:[e.jsx(je,{size:14,style:{marginRight:4}}),"清除标签过滤"]})})]});return e.jsx(Ws,{content:j,visible:o,onVisibleChange:N=>d(N),trigger:"click",placement:"bottom-left",overlayClassName:"kb-filter-dropdown__popup",children:e.jsxs(Ne,{variant:s.length>0?"base":"outline",theme:s.length>0?"primary":"default",size:"small",className:`kb-filter-trigger ${s.length>0?"is-active":""}`,children:[e.jsx(qs,{size:14,style:{marginRight:4}}),"标签",s.length>0&&` (${s.length})`]})})},Hn=({visible:t,onClose:s,allTags:r,onCreateTag:a,onUpdateTag:c,onDeleteTag:o,onSelectTag:d})=>{const{confirm:u,confirmDialog:p}=Ot(),[v,j]=n.useState(!1),[N,m]=n.useState(""),[k,l]=n.useState(null),[S,b]=n.useState(""),g=n.useRef(null);n.useEffect(()=>{v&&g.current&&setTimeout(()=>{var f;(f=g.current)==null||f.focus()},100)},[v]);const z=async()=>{if(!N.trim()){j(!1);return}try{await a(N.trim()),m(""),j(!1),X.success("标签创建成功")}catch{X.error("标签创建失败")}},P=async f=>{if(!S.trim()){l(null);return}try{await c(f,S.trim()),l(null),X.success("标签更新成功")}catch{X.error("标签更新失败")}},$=async(f,T)=>{f.stopPropagation();try{const F=r.find(J=>J.id===T);if(!await u({title:"确认删除标签",description:`确定要删除标签「${(F==null?void 0:F.name)||"未命名标签"}」吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0}))return;await o(T),X.success("标签删除成功")}catch{X.error("标签删除失败")}},O=(f,T)=>{f.stopPropagation(),l(T.id),b(T.name)};return e.jsxs(Os,{header:"管理标签",visible:t,onClose:s,footer:null,width:400,className:"kb-tag-management-dialog",children:[e.jsxs("div",{className:"kb-tag-list",children:[v?e.jsx("div",{className:"kb-tag-item kb-tag-item--creating",children:e.jsx(Te,{ref:g,value:N,onChange:f=>m(f),onEnter:z,onBlur:z,placeholder:"输入标签名称...",size:"small"})}):e.jsxs("div",{className:"kb-tag-item kb-tag-item--create-btn",onClick:()=>j(!0),children:[e.jsx(Le,{size:16}),e.jsx("span",{children:"新建标签"})]}),r.map(f=>e.jsx("div",{className:"kb-tag-item",onClick:()=>{d&&!k&&(d(f.id),s())},children:k===f.id?e.jsxs("div",{className:"kb-tag-item__editing",onClick:T=>T.stopPropagation(),children:[e.jsx(Te,{value:S,onChange:T=>b(T),onEnter:()=>P(f.id),size:"small",autofocus:!0}),e.jsx(Ne,{shape:"circle",variant:"text",size:"small",onClick:()=>P(f.id),children:e.jsx(pe,{size:14})}),e.jsx(Ne,{shape:"circle",variant:"text",size:"small",onClick:()=>l(null),children:e.jsx(je,{size:14})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"kb-tag-item__dot",style:{backgroundColor:f.color}}),e.jsx("span",{className:"kb-tag-item__name",children:f.name}),e.jsx("span",{className:"kb-tag-item__count",children:f.count?`(${f.count} 个笔记)`:"(0 个笔记)"}),e.jsxs("div",{className:"kb-tag-item__actions",children:[e.jsx(G,{content:"重命名",showArrow:!1,children:e.jsx("button",{className:"kb-tag-item__action-btn",onClick:T=>O(T,f),children:e.jsx(Hs,{size:12})})}),e.jsx(G,{content:"删除",showArrow:!1,children:e.jsx("button",{className:"kb-tag-item__action-btn kb-tag-item__action-btn--delete",onClick:T=>$(T,f.id),children:e.jsx(ye,{size:12})})})]})]})},f.id))]}),p]})},At=10,Kn=({currentNoteId:t,allNotes:s,noteTagsMap:r,onSelectNote:a})=>{const[c,o]=n.useState([]),[d,u]=n.useState(!1),[p,v]=n.useState(!1);n.useEffect(()=>{let l=!1;return(async()=>{try{const b=await Ht().getRelatedNotes(t,At);l||o(b)}catch{l||o([])}})(),()=>{l=!0}},[t]);const j=n.useMemo(()=>s.find(l=>l.id===t),[s,t]),N=n.useMemo(()=>{var S;const l=(S=j==null?void 0:j.metadata)==null?void 0:S.sourceUrl;return l?s.filter(b=>{var g;return b.id!==t&&((g=b==null?void 0:b.metadata)==null?void 0:g.sourceUrl)===l}):[]},[s,t,j]),m=n.useMemo(()=>new Set(N.map(l=>l.id)),[N]),k=n.useMemo(()=>{if(c.length>0){const g=new Set;return c.filter(z=>m.has(z.id)||g.has(z.id)?!1:(g.add(z.id),!0))}const l=r[t]||[],S=new Set(l.map(g=>g.id));if(!j)return[];const b=[];for(const g of s){if(g.id===t||m.has(g.id))continue;const P=(r[g.id]||[]).map(R=>R.id),$=P.filter(R=>S.has(R)).length,O=new Set([...S,...P]).size,f=O>0?$/O:0,T=Vn(j.title,g.title),F=f*.7+T*.3;F>.05&&b.push({id:g.id,title:g.title||"无标题",score:F})}return b.sort((g,z)=>z.score-g.score).slice(0,At)},[c,m,s,t,r,j]);return N.length===0&&k.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:()=>u(!d),children:[d?e.jsx(De,{size:12}):e.jsx(Ie,{size:12}),e.jsx(Kt,{size:12}),e.jsx("span",{children:"相关笔记"}),e.jsx("span",{className:"kb-related-notes__count",children:N.length})]}),!d&&e.jsx("div",{className:"kb-related-notes__list",children:N.map(l=>e.jsxs("div",{className:"kb-related-notes__item",onClick:()=>a(l.id),children:[e.jsx(Ae,{size:12,className:"kb-related-notes__icon"}),e.jsx("span",{className:"kb-related-notes__name",children:l.title||"无标题"}),e.jsx(G,{content:"跳转",showArrow:!1,children:e.jsx("button",{className:"kb-related-notes__goto-btn",onClick:S=>{S.stopPropagation(),a(l.id)},children:e.jsx(Qe,{size:10})})})]},`related-${l.id}`))})]}),k.length>0&&e.jsxs("div",{className:"kb-related-notes__section",children:[e.jsxs("button",{className:"kb-related-notes__section-header",onClick:()=>v(!p),children:[p?e.jsx(De,{size:12}):e.jsx(Ie,{size:12}),e.jsx(Ae,{size:12}),e.jsx("span",{children:"相似笔记"}),e.jsx("span",{className:"kb-related-notes__count",children:k.length})]}),!p&&e.jsx("div",{className:"kb-related-notes__list",children:k.map(l=>{const S="score"in l?l.score:void 0;return e.jsxs("div",{className:"kb-related-notes__item",onClick:()=>a(l.id),children:[e.jsx(Ae,{size:12,className:"kb-related-notes__icon"}),e.jsx("span",{className:"kb-related-notes__name",children:l.title}),S!==void 0&&e.jsxs("span",{className:"kb-related-notes__similarity",children:[Math.round(S*100),"%"]}),e.jsx(G,{content:"跳转",showArrow:!1,children:e.jsx("button",{className:"kb-related-notes__goto-btn",onClick:b=>{b.stopPropagation(),a(l.id)},children:e.jsx(Qe,{size:10})})})]},`similar-${l.id}`)})})]})]})};function Vn(t,s){if(!t||!s)return 0;const r=t.toLowerCase(),a=s.toLowerCase(),c=new Set;for(let p=0;p<r.length-1;p++)c.add(r.substring(p,p+2));const o=new Set;for(let p=0;p<a.length-1;p++)o.add(a.substring(p,p+2));let d=0;for(const p of c)o.has(p)&&d++;const u=c.size+o.size;return u===0?0:2*d/u}const Xn=`你是一个专业的知识提取助手,擅长从文本中识别和提取关键知识点。你的任务是分析给定的文本内容,提取出有价值的知识点,并以结构化的 Markdown 格式返回。
|
|
5
5
|
|
|
@@ -48,6 +48,6 @@ ${t}
|
|
|
48
48
|
`).trim()}const or=({noteId:t,noteContent:s,noteTitle:r,onInsertToNote:a,onSaved:c})=>{const o=Vs("text"),[d,u]=n.useState([]),[p,v]=n.useState(""),[j,N]=n.useState(o.modelId||It),[m,k]=n.useState(()=>jt(o.profileId,o.modelId||It)),[l,S]=n.useState(!1),[b,g]=n.useState(null),[z,P]=n.useState(null),$=n.useRef(!1),O=n.useRef(null),f=n.useRef(null);n.useEffect(()=>{let y=!0;return(async()=>{u([]);try{const w=await sr(t);y&&(w&&w.messages.length>0?u(w.messages):u([{id:"init",role:"model",content:"我已经阅读了这篇笔记。你可以让我提取摘要、关键点,或者直接与我讨论笔记内容。",type:"text",timestamp:Date.now()}]))}catch(w){console.error("Failed to load chat history",w)}})(),()=>{y=!1}},[t]),n.useEffect(()=>{d.length>0&&nr(t,d).catch(console.error)},[d,t]),n.useEffect(()=>{O.current&&(O.current.scrollTop=O.current.scrollHeight)},[d]),n.useEffect(()=>{f.current&&(f.current.style.height="auto",f.current.style.height=`${Math.min(f.current.scrollHeight,120)}px`)},[p]);const T=n.useCallback(()=>{z&&(ne("stop_generation",{status:"cancelled",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length}),z.abort(),P(null),$.current=!1,S(!1),u(y=>[...y,{id:Date.now().toString(),role:"model",content:"🚫 已停止生成",type:"text",timestamp:Date.now()}]))},[z,s.length,j,m]),F=n.useCallback(async()=>{const y=p.trim();if(!y||$.current||l)return;$.current=!0;const D=Date.now();ne("chat",{status:"start",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,inputLength:y.length});const w={id:Date.now().toString(),role:"user",content:y,type:"text",timestamp:Date.now()};u(_=>[..._,w]),v(""),S(!0),f.current&&(f.current.style.height="auto");const B=new AbortController;P(B);try{const _=d.concat(w).map(L=>({role:L.role==="model"?"assistant":"user",content:[{type:"text",text:L.content}]}));if(_.length<=2){const L=`Context:
|
|
49
49
|
${s}
|
|
50
50
|
|
|
51
|
-
Task: ${w.content}`,K=_.length-1;_[K].content=[{type:"text",text:L}]}const A=(Date.now()+1).toString();g(A),u(L=>[...L,{id:A,role:"model",content:"正在思考...",type:"text",timestamp:Date.now()}]),await Zn(_,{model:m||j,onProgress:L=>{u(K=>K.map(M=>M.id===A?{...M,content:L}:M))},signal:B.signal}),ne("chat",{status:"success",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,inputLength:y.length,durationMs:Date.now()-D})}catch(_){_.name!=="AbortError"?(ne("chat",{status:"failed",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,inputLength:y.length,durationMs:Date.now()-D,error:_.message||"chat_failed"}),u(A=>[...A,{id:Date.now().toString(),role:"model",content:`Error: ${_.message||"Something went wrong"}`,type:"text",timestamp:Date.now()}])):ne("chat",{status:"cancelled",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,inputLength:y.length,durationMs:Date.now()-D})}finally{$.current=!1,S(!1),P(null),g(null)}},[p,l,d,s,j,m]),R=n.useCallback(async()=>{if($.current||l)return;$.current=!0;const y=Date.now();ne("quick_extract",{status:"start",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length}),S(!0);const D={id:Date.now().toString(),role:"user",content:"提取知识点",type:"text",timestamp:Date.now()};u(_=>[..._,D]);const w=new AbortController;P(w);const B=(Date.now()+1).toString();u(_=>[..._,{id:B,role:"model",content:"正在分析笔记内容并提取知识点...",type:"text",timestamp:Date.now()}]);try{const _=await Jn(s,{title:r,model:m||j,signal:w.signal}),A=nt(_);ne("quick_extract",{status:"success",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,resultLength:A.length,knowledgePointCount:_.knowledgePoints.length,durationMs:Date.now()-y}),u(L=>L.map(K=>K.id===B?{...K,content:"知识点提取完成:",type:"extraction-result",data:_}:K))}catch(_){_.name!=="AbortError"?(ne("quick_extract",{status:"failed",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,durationMs:Date.now()-y,error:_.message||"extract_failed"}),u(A=>A.map(L=>L.id===B?{...L,content:`提取失败: ${_.message}`}:L))):ne("quick_extract",{status:"cancelled",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,durationMs:Date.now()-y})}finally{$.current=!1,S(!1),P(null)}},[l,s,r,j,m]),J=y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),F())},W=n.useCallback(y=>{if(!y){X.warning("没有可复制的内容");return}ne("copy_result",{status:"start",resultLength:y.length}),Xs(y).then(()=>{ne("copy_result",{status:"success",resultLength:y.length}),X.success("复制成功")}).catch(()=>{ne("copy_result",{status:"failed",resultLength:y.length}),X.error("复制失败")})},[]),U=n.useCallback(y=>y.type==="text"?y.content:y.type==="extraction-result"&&y.data?nt(y.data):"",[]),te=n.useCallback(y=>{if(y.type==="extraction-result"&&y.data)try{const D=ar(y.data,{format:"markdown",includeSource:!0,includeTags:!0});ir(D.content,D.filename,D.mimeType),ne("download_markdown",{status:"success",resultLength:D.content.length,knowledgePointCount:y.data.knowledgePoints.length})}catch(D){console.error("Failed to export",D),ne("download_markdown",{status:"failed",knowledgePointCount:y.data.knowledgePoints.length,error:D instanceof Error?D.message:"export_failed"}),X.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(Ze,{size:18}),e.jsx("span",{children:"知识提取 & 对话"})]})}),e.jsx("div",{className:"kb-extraction-chat__messages",ref:O,children:d.map(y=>e.jsxs("div",{className:`kb-message kb-message--${y.role}`,children:[e.jsx("div",{className:"kb-message__avatar",children:y.role==="user"?e.jsx(Ge,{}):e.jsx(Ys,{})}),e.jsxs("div",{className:"kb-message__body",children:[e.jsx("div",{className:"kb-message__content",children:y.role==="model"?e.jsx("div",{className:"kb-message__content-scroll",children:y.type==="text"?y.id===b&&(y.content==="正在思考..."||y.content==="正在分析笔记内容并提取知识点...")?e.jsxs("div",{className:"kb-message__thinking","aria-label":"思考中",children:[e.jsx("span",{className:"kb-message__thinking-text",children:y.content.replace(/\.+$/,"")}),e.jsxs("span",{className:"kb-message__thinking-dots",children:[e.jsx("span",{children:"."}),e.jsx("span",{children:"."}),e.jsx("span",{children:"."})]})]}):y.content?e.jsx("div",{className:"kb-message__markdown-wrap",children:e.jsx(ot,{markdown:y.content,readOnly:!0,showModeSwitch:!1,initialMode:"wysiwyg",className:"kb-extraction-markdown"})}):null:e.jsx(Dt,{result:y.data})}):y.type==="text"?e.jsx("div",{className:"kb-message__text",children:y.content}):e.jsx(Dt,{result:y.data})}),y.role==="model"&&e.jsxs("div",{className:"kb-message__actions",children:[e.jsx(G,{content:"复制",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>W(U(y)),children:e.jsx(Ke,{size:14})})}),e.jsx(G,{content:"插入到笔记",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>{var w;const D=U(y);D&&(ne("insert_to_note",{status:"success",resultLength:D.length,knowledgePointCount:y.type==="extraction-result"?(w=y.data)==null?void 0:w.knowledgePoints.length:void 0}),a==null||a(D))},children:e.jsx(Gs,{size:14})})}),y.type==="extraction-result"&&e.jsx(G,{content:"导出 Markdown",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>te(y),children:e.jsx(it,{size:14})})})]})]})]},y.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:f,className:"kb-extraction-chat__textarea",value:p,onChange:y=>v(y.target.value),onKeyDown:J,placeholder:"输入问题,与 AI 讨论笔记内容...",disabled:l,rows:1})}),e.jsxs("div",{className:"kb-extraction-chat__input-actions",children:[e.jsx("div",{className:"kb-extraction-chat__model-selector",children:e.jsx(Qs,{value:j,valueRef:m,onChange:(y,D)=>{ne("change_model",{status:"success",model:y,profileId:D==null?void 0:D.profileId,noteLength:s.length}),N(y),k(D||jt(null,y))},variant:"capsule"})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(G,{content:"一键提取知识点",showArrow:!1,children:e.jsx("span",{children:e.jsx("button",{className:"kb-extraction-chat__icon-btn",onClick:R,disabled:l,children:e.jsx(Ze,{size:16})})})}),e.jsx(G,{content:l?"停止生成":"发送",showArrow:!1,children:e.jsx("span",{children:e.jsx("button",{className:`kb-extraction-chat__send-btn ${p.trim()||l?"kb-extraction-chat__send-btn--active":""}`,onClick:l?T:F,disabled:!p.trim()&&!l,children:l?e.jsx(Zs,{size:18}):e.jsx(Js,{size:18})})})})]})]})]})]})},Dt=({result:t})=>{const s=tn.useMemo(()=>nt(t),[t]);return e.jsx("div",{className:"kb-extraction-result-view",children:e.jsx(ot,{markdown:s,readOnly:!0,showModeSwitch:!1,initialMode:"wysiwyg",className:"kb-extraction-markdown"})})},Lt=[{label:"更新时间",value:"updatedAt"},{label:"创建时间",value:"createdAt"},{label:"标题",value:"title"}],cr=({value:t,onChange:s})=>{var o;const r=((o=Lt.find(d=>d.value===t.field))==null?void 0:o.label)||"排序",a=d=>{const u=d.value;["asc","desc"].includes(u)?s({...t,order:u}):u===t.field?s({...t,order:t.order==="asc"?"desc":"asc"}):s({...t,field:u,order:u==="title"?"asc":"desc"})},c=[{content:"排序字段",disabled:!0,className:"kb-sort-dropdown__header"},...Lt.map(d=>({content:d.label,value:d.value,prefixIcon:t.field===d.value?e.jsx(pe,{size:14}):e.jsx("div",{style:{width:14}})})),{divider:!0},{content:"排序方式",disabled:!0,className:"kb-sort-dropdown__header"},{content:"升序",value:"asc",prefixIcon:t.order==="asc"?e.jsx(pe,{size:14}):e.jsx("div",{style:{width:14}}),suffixIcon:e.jsx(yt,{size:14})},{content:"降序",value:"desc",prefixIcon:t.order==="desc"?e.jsx(pe,{size:14}):e.jsx("div",{style:{width:14}}),suffixIcon:e.jsx(vt,{size:14})}];return e.jsx(Xt,{options:c,onClick:a,trigger:"click",minColumnWidth:120,children:e.jsxs(Ne,{variant:"outline",size:"small",className:"kb-sort-trigger",children:[t.order==="asc"?e.jsx(yt,{size:14,style:{marginRight:4}}):e.jsx(vt,{size:14,style:{marginRight:4}}),r]})})},wr=({initialNoteId:t})=>{var bt;const[s,r]=n.useState([]),[a,c]=n.useState([]),[o,d]=n.useState([]),[u,p]=n.useState(null),[v,j]=n.useState([]),[N,m]=n.useState({}),[k,l]=n.useState(null),[S,b]=n.useState(new Set),[g,z]=n.useState(null),[P,$]=n.useState(""),[O,f]=n.useState(q.loadSortPreference?q.loadSortPreference():{field:"updatedAt",order:"desc"}),[T,F]=n.useState([]),[R,J]=n.useState(!1),[W,U]=n.useState(!1),[te,y]=n.useState(!1),[D,w]=n.useState(null),B=n.useRef(null),_=n.useRef(0),A=n.useRef(null),{confirm:L,confirmDialog:K}=Ot(),[M,Y]=n.useState(!1),[Q,Z]=n.useState("related"),[ie,Ce]=n.useState(280),[xe,ct]=n.useState(300),ke=n.useRef(!1),we=n.useRef(!1),$e=n.useRef(null);n.useEffect(()=>{const i=localStorage.getItem("kb-sidebar-width");if(i){const h=parseInt(i,10);!isNaN(h)&&h>100&&h<800&&Ce(h)}const x=localStorage.getItem("kb-right-sidebar-width");if(x){const h=parseInt(x,10);!isNaN(h)&&h>100&&h<800&&ct(h)}},[]),n.useEffect(()=>{const i=h=>{if(!$e.current)return;const E=$e.current.getBoundingClientRect();if(ke.current){h.preventDefault();const C=Math.max(200,Math.min(600,h.clientX-E.left));Ce(C)}else if(we.current){h.preventDefault();const C=Math.max(200,Math.min(600,E.right-h.clientX));ct(C)}},x=()=>{ke.current&&(ke.current=!1,localStorage.setItem("kb-sidebar-width",ie.toString()),document.body.style.cursor=""),we.current&&(we.current=!1,localStorage.setItem("kb-right-sidebar-width",xe.toString()),document.body.style.cursor="")};return ke.current||we.current?(document.addEventListener("mousemove",i),document.addEventListener("mouseup",x)):document.addEventListener("mousemove",i),document.addEventListener("mousemove",i),document.addEventListener("mouseup",x),()=>{document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",x)}},[ie,xe]);const es=i=>{i.preventDefault(),ke.current=!0,document.body.style.cursor="col-resize"},ts=i=>{i.preventDefault(),we.current=!0,document.body.style.cursor="col-resize"},[lt,ss]=n.useState(null),dt=n.useRef(!1),ut=n.useRef(!1);n.useEffect(()=>{if(dt.current)return;dt.current=!0,(async()=>{await q.initialize();try{await mn()}catch(h){console.warn("[KnowledgeBaseContent] 提示词优化模板初始化失败:",h)}await ee();try{const h=await q.getStorageUsage();ss(h)}catch{}if(t){oe(t);return}const x=window.__kbPendingNavigation;if(x){window.__kbPendingNavigation=null;const{directoryName:h,autoCreateNote:E}=x;if(h){const I=(await q.getAllDirectories()).find(H=>H.name===h);if(I&&(l(I.id),b(H=>{const V=new Set(H);return V.add(I.id),V}),E)){const H=h==="Skill"?"新Skill":"新笔记",V=await q.createNote(H,I.id);await ee(),b(ue=>{const _e=new Set(ue);return _e.add(I.id),_e}),z(V.id);const ce=await q.getNoteById(V.id);p(ce),j([])}}}})()},[]);const ee=n.useCallback(async()=>{const[i,x,h]=await Promise.all([q.getAllDirectories(),q.getAllNoteMetas(),q.getAllTags()]),E=Array.from(new Map(i.map(H=>[H.id,H])).values());r(E);const C=Array.from(new Map(x.map(H=>[H.id,H])).values());c(C);const I=Array.from(new Map(h.map(H=>[H.id,H])).values());d(I),!k&&!g&&E.length>0&&(l(E[0].id),b(new Set([E[0].id]))),await ns(C)},[k,g]),ns=n.useCallback(async i=>{try{const[x,h]=await Promise.all([q.getAllTags(),q.getAllNoteTags()]),E=new Map(x.map(I=>[I.id,I])),C={};for(const I of i)C[I.id]=[];for(const I of h)if(C[I.noteId]&&E.has(I.tagId)){const H=E.get(I.tagId);H&&(C[I.noteId].some(V=>V.id===H.id)||C[I.noteId].push(H))}for(const I in C)C[I].sort((H,V)=>H.name.localeCompare(V.name));m(C)}catch(x){console.error("Failed to refresh note tags map:",x)}},[]);n.useEffect(()=>{if(!P.trim()){w(null);return}return B.current&&clearTimeout(B.current),B.current=setTimeout(async()=>{try{const x=await Ht().search(P,{limit:50,filter:k?{directoryId:k}:{}});w(x)}catch{w(null)}},300),()=>{B.current&&clearTimeout(B.current)}},[P,k]);const de=n.useMemo(()=>{if(D&&P.trim()){const x=new Set(D.map(C=>C.id)),h=new Map(D.map((C,I)=>[C.id,I]));let E=a.filter(C=>x.has(C.id));if(T.length>0){const C=new Set(T);E=E.filter(I=>(N[I.id]||[]).some(V=>C.has(V.id)))}return E.sort((C,I)=>(h.get(C.id)??0)-(h.get(I.id)??0))}let i=a;if(T.length>0){const x=new Set(T);i=i.filter(h=>(N[h.id]||[]).some(C=>x.has(C.id)))}return q.sortNoteMetas(i,O)},[a,k,P,T,O,N,D]),rs=n.useMemo(()=>{const i={},x=new Set;for(const h of de)x.has(h.id)||(x.add(h.id),i[h.directoryId]=(i[h.directoryId]||0)+1);return i},[de]),as=n.useMemo(()=>{var x;const i={};for(const h of de){const E=i[x=h.directoryId]??(i[x]=[]);E.some(C=>C.id===h.id)||E.push(h)}return i},[de]),Ue=n.useCallback(async i=>{await q.createDirectory(i),await ee()},[ee]),is=n.useCallback(async(i,x)=>{await q.updateDirectory(i,{name:x}),await ee()},[ee]),os=n.useCallback(async i=>{var E;const x=s.find(C=>C.id===i);if(!(!x||!await L({title:"确认删除目录",description:`确定要删除目录 "${x.name}" 及其下的所有笔记吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0})))try{await q.deleteDirectory(i),k===i&&(l(((E=s[0])==null?void 0:E.id)||null),z(null),p(null)),await ee(),X.success("目录已删除")}catch(C){X.error(`删除失败: ${C.message}`)}},[ee,k,s]),cs=n.useCallback(async i=>{try{await q.duplicateDirectory(i),await ee(),X.success("目录复制成功")}catch(x){X.error(`复制目录失败: ${x.message}`)}},[ee]),ls=n.useCallback(i=>{b(x=>{const h=new Set(x);return h.has(i)?h.delete(i):h.add(i),h})},[]),oe=n.useCallback(async i=>{const x=++_.current;if(z(i),l(null),j(N[i]||[]),i.startsWith(ge)){const E=i.slice(ge.length),C=Je.find(I=>I.id===E);if(C){const I=["image","inspiration","grid_image"],H=["ppt"],V=C.mcpTool&&I.some(ue=>C.mcpTool.includes(ue))?"image":C.mcpTool&&H.some(ue=>C.mcpTool.includes(ue))?"ppt":void 0,ce={id:i,title:C.name,content:C.description||"",directoryId:"",createdAt:0,updatedAt:0,metadata:{...V?{outputType:V}:{}}};x===_.current&&(p(ce),j([]))}return}if(i.startsWith(fe)){const E=i.slice(fe.length),C=gn(E);if(C){const I={id:i,title:C.name,content:C.content||C.description||"",directoryId:"",createdAt:0,updatedAt:0,metadata:{...C.outputType?{outputType:C.outputType}:{},...C.category?{category:C.category}:{}}};x===_.current&&(p(I),j([]))}return}const h=await q.getNoteById(i);if(x===_.current&&(p(h),h)){const E=await q.getTagsForNote(h.id);if(x!==_.current)return;j(E),b(C=>{const I=new Set(C);return I.add(h.directoryId),I})}},[s,N]),Be=n.useCallback(async i=>{const x=new Set(a.filter(V=>V.directoryId===i).map(V=>V.title)),h=s.find(V=>V.id===i),E=(h==null?void 0:h.name)==="Skill"?"新Skill":"新笔记";let C=E,I=1;for(;x.has(C);)C=`${E} ${I}`,I++;const H=await q.createNote(C,i);await ee(),b(V=>{const ce=new Set(V);return ce.add(i),ce}),oe(H.id)},[ee,oe,a,s]),Fe=n.useCallback(async(i,x)=>{await q.updateNote(i,x),c(h=>h.map(E=>E.id===i?{...E,...x,updatedAt:Date.now()}:E)),(u==null?void 0:u.id)===i&&p(h=>h&&{...h,...x,updatedAt:Date.now()});try{const h=window.__drawnixBoard;if(h&&h.children){const{Transforms:E}=await qe(async()=>{const{Transforms:C}=await import("./ai-chat-D2kHVW04.js").then(I=>I.sM);return{Transforms:C}},__vite__mapDeps([0]),import.meta.url);h.children.forEach((C,I)=>{if(C.noteId===i){const H={};x.title!==void 0&&(H.title=x.title),x.content!==void 0&&(H.body=x.content),Object.keys(H).length>0&&E.setNode(h,H,[I])}})}}catch(h){console.warn("[KB] Failed to sync note update to canvas card:",h)}},[u]),ds=n.useCallback(async i=>{if(!u)return;const x=u.content?`
|
|
51
|
+
Task: ${w.content}`,K=_.length-1;_[K].content=[{type:"text",text:L}]}const A=(Date.now()+1).toString();g(A),u(L=>[...L,{id:A,role:"model",content:"正在思考...",type:"text",timestamp:Date.now()}]),await Zn(_,{model:m||j,onProgress:L=>{u(K=>K.map(M=>M.id===A?{...M,content:L}:M))},signal:B.signal}),ne("chat",{status:"success",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,inputLength:y.length,durationMs:Date.now()-D})}catch(_){_.name!=="AbortError"?(ne("chat",{status:"failed",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,inputLength:y.length,durationMs:Date.now()-D,error:_.message||"chat_failed"}),u(A=>[...A,{id:Date.now().toString(),role:"model",content:`Error: ${_.message||"Something went wrong"}`,type:"text",timestamp:Date.now()}])):ne("chat",{status:"cancelled",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,inputLength:y.length,durationMs:Date.now()-D})}finally{$.current=!1,S(!1),P(null),g(null)}},[p,l,d,s,j,m]),R=n.useCallback(async()=>{if($.current||l)return;$.current=!0;const y=Date.now();ne("quick_extract",{status:"start",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length}),S(!0);const D={id:Date.now().toString(),role:"user",content:"提取知识点",type:"text",timestamp:Date.now()};u(_=>[..._,D]);const w=new AbortController;P(w);const B=(Date.now()+1).toString();u(_=>[..._,{id:B,role:"model",content:"正在分析笔记内容并提取知识点...",type:"text",timestamp:Date.now()}]);try{const _=await Jn(s,{title:r,model:m||j,signal:w.signal}),A=nt(_);ne("quick_extract",{status:"success",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,resultLength:A.length,knowledgePointCount:_.knowledgePoints.length,durationMs:Date.now()-y}),u(L=>L.map(K=>K.id===B?{...K,content:"知识点提取完成:",type:"extraction-result",data:_}:K))}catch(_){_.name!=="AbortError"?(ne("quick_extract",{status:"failed",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,durationMs:Date.now()-y,error:_.message||"extract_failed"}),u(A=>A.map(L=>L.id===B?{...L,content:`提取失败: ${_.message}`}:L))):ne("quick_extract",{status:"cancelled",model:j,profileId:m==null?void 0:m.profileId,noteLength:s.length,durationMs:Date.now()-y})}finally{$.current=!1,S(!1),P(null)}},[l,s,r,j,m]),J=y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),F())},W=n.useCallback(y=>{if(!y){X.warning("没有可复制的内容");return}ne("copy_result",{status:"start",resultLength:y.length}),Xs(y).then(()=>{ne("copy_result",{status:"success",resultLength:y.length}),X.success("复制成功")}).catch(()=>{ne("copy_result",{status:"failed",resultLength:y.length}),X.error("复制失败")})},[]),U=n.useCallback(y=>y.type==="text"?y.content:y.type==="extraction-result"&&y.data?nt(y.data):"",[]),te=n.useCallback(y=>{if(y.type==="extraction-result"&&y.data)try{const D=ar(y.data,{format:"markdown",includeSource:!0,includeTags:!0});ir(D.content,D.filename,D.mimeType),ne("download_markdown",{status:"success",resultLength:D.content.length,knowledgePointCount:y.data.knowledgePoints.length})}catch(D){console.error("Failed to export",D),ne("download_markdown",{status:"failed",knowledgePointCount:y.data.knowledgePoints.length,error:D instanceof Error?D.message:"export_failed"}),X.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(Ze,{size:18}),e.jsx("span",{children:"知识提取 & 对话"})]})}),e.jsx("div",{className:"kb-extraction-chat__messages",ref:O,children:d.map(y=>e.jsxs("div",{className:`kb-message kb-message--${y.role}`,children:[e.jsx("div",{className:"kb-message__avatar",children:y.role==="user"?e.jsx(Ge,{}):e.jsx(Ys,{})}),e.jsxs("div",{className:"kb-message__body",children:[e.jsx("div",{className:"kb-message__content",children:y.role==="model"?e.jsx("div",{className:"kb-message__content-scroll",children:y.type==="text"?y.id===b&&(y.content==="正在思考..."||y.content==="正在分析笔记内容并提取知识点...")?e.jsxs("div",{className:"kb-message__thinking","aria-label":"思考中",children:[e.jsx("span",{className:"kb-message__thinking-text",children:y.content.replace(/\.+$/,"")}),e.jsxs("span",{className:"kb-message__thinking-dots",children:[e.jsx("span",{children:"."}),e.jsx("span",{children:"."}),e.jsx("span",{children:"."})]})]}):y.content?e.jsx("div",{className:"kb-message__markdown-wrap",children:e.jsx(ot,{markdown:y.content,readOnly:!0,showModeSwitch:!1,initialMode:"wysiwyg",className:"kb-extraction-markdown"})}):null:e.jsx(Dt,{result:y.data})}):y.type==="text"?e.jsx("div",{className:"kb-message__text",children:y.content}):e.jsx(Dt,{result:y.data})}),y.role==="model"&&e.jsxs("div",{className:"kb-message__actions",children:[e.jsx(G,{content:"复制",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>W(U(y)),children:e.jsx(Ke,{size:14})})}),e.jsx(G,{content:"插入到笔记",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>{var w;const D=U(y);D&&(ne("insert_to_note",{status:"success",resultLength:D.length,knowledgePointCount:y.type==="extraction-result"?(w=y.data)==null?void 0:w.knowledgePoints.length:void 0}),a==null||a(D))},children:e.jsx(Gs,{size:14})})}),y.type==="extraction-result"&&e.jsx(G,{content:"导出 Markdown",showArrow:!1,children:e.jsx("button",{className:"kb-message__action-btn",onClick:()=>te(y),children:e.jsx(it,{size:14})})})]})]})]},y.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:f,className:"kb-extraction-chat__textarea",value:p,onChange:y=>v(y.target.value),onKeyDown:J,placeholder:"输入问题,与 AI 讨论笔记内容...",disabled:l,rows:1})}),e.jsxs("div",{className:"kb-extraction-chat__input-actions",children:[e.jsx("div",{className:"kb-extraction-chat__model-selector",children:e.jsx(Qs,{value:j,valueRef:m,onChange:(y,D)=>{ne("change_model",{status:"success",model:y,profileId:D==null?void 0:D.profileId,noteLength:s.length}),N(y),k(D||jt(null,y))},variant:"capsule"})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(G,{content:"一键提取知识点",showArrow:!1,children:e.jsx("span",{children:e.jsx("button",{className:"kb-extraction-chat__icon-btn",onClick:R,disabled:l,children:e.jsx(Ze,{size:16})})})}),e.jsx(G,{content:l?"停止生成":"发送",showArrow:!1,children:e.jsx("span",{children:e.jsx("button",{className:`kb-extraction-chat__send-btn ${p.trim()||l?"kb-extraction-chat__send-btn--active":""}`,onClick:l?T:F,disabled:!p.trim()&&!l,children:l?e.jsx(Zs,{size:18}):e.jsx(Js,{size:18})})})})]})]})]})]})},Dt=({result:t})=>{const s=tn.useMemo(()=>nt(t),[t]);return e.jsx("div",{className:"kb-extraction-result-view",children:e.jsx(ot,{markdown:s,readOnly:!0,showModeSwitch:!1,initialMode:"wysiwyg",className:"kb-extraction-markdown"})})},Lt=[{label:"更新时间",value:"updatedAt"},{label:"创建时间",value:"createdAt"},{label:"标题",value:"title"}],cr=({value:t,onChange:s})=>{var o;const r=((o=Lt.find(d=>d.value===t.field))==null?void 0:o.label)||"排序",a=d=>{const u=d.value;["asc","desc"].includes(u)?s({...t,order:u}):u===t.field?s({...t,order:t.order==="asc"?"desc":"asc"}):s({...t,field:u,order:u==="title"?"asc":"desc"})},c=[{content:"排序字段",disabled:!0,className:"kb-sort-dropdown__header"},...Lt.map(d=>({content:d.label,value:d.value,prefixIcon:t.field===d.value?e.jsx(pe,{size:14}):e.jsx("div",{style:{width:14}})})),{divider:!0},{content:"排序方式",disabled:!0,className:"kb-sort-dropdown__header"},{content:"升序",value:"asc",prefixIcon:t.order==="asc"?e.jsx(pe,{size:14}):e.jsx("div",{style:{width:14}}),suffixIcon:e.jsx(yt,{size:14})},{content:"降序",value:"desc",prefixIcon:t.order==="desc"?e.jsx(pe,{size:14}):e.jsx("div",{style:{width:14}}),suffixIcon:e.jsx(vt,{size:14})}];return e.jsx(Xt,{options:c,onClick:a,trigger:"click",minColumnWidth:120,children:e.jsxs(Ne,{variant:"outline",size:"small",className:"kb-sort-trigger",children:[t.order==="asc"?e.jsx(yt,{size:14,style:{marginRight:4}}):e.jsx(vt,{size:14,style:{marginRight:4}}),r]})})},wr=({initialNoteId:t})=>{var bt;const[s,r]=n.useState([]),[a,c]=n.useState([]),[o,d]=n.useState([]),[u,p]=n.useState(null),[v,j]=n.useState([]),[N,m]=n.useState({}),[k,l]=n.useState(null),[S,b]=n.useState(new Set),[g,z]=n.useState(null),[P,$]=n.useState(""),[O,f]=n.useState(q.loadSortPreference?q.loadSortPreference():{field:"updatedAt",order:"desc"}),[T,F]=n.useState([]),[R,J]=n.useState(!1),[W,U]=n.useState(!1),[te,y]=n.useState(!1),[D,w]=n.useState(null),B=n.useRef(null),_=n.useRef(0),A=n.useRef(null),{confirm:L,confirmDialog:K}=Ot(),[M,Y]=n.useState(!1),[Q,Z]=n.useState("related"),[ie,Ce]=n.useState(280),[xe,ct]=n.useState(300),ke=n.useRef(!1),we=n.useRef(!1),$e=n.useRef(null);n.useEffect(()=>{const i=localStorage.getItem("kb-sidebar-width");if(i){const h=parseInt(i,10);!isNaN(h)&&h>100&&h<800&&Ce(h)}const x=localStorage.getItem("kb-right-sidebar-width");if(x){const h=parseInt(x,10);!isNaN(h)&&h>100&&h<800&&ct(h)}},[]),n.useEffect(()=>{const i=h=>{if(!$e.current)return;const E=$e.current.getBoundingClientRect();if(ke.current){h.preventDefault();const C=Math.max(200,Math.min(600,h.clientX-E.left));Ce(C)}else if(we.current){h.preventDefault();const C=Math.max(200,Math.min(600,E.right-h.clientX));ct(C)}},x=()=>{ke.current&&(ke.current=!1,localStorage.setItem("kb-sidebar-width",ie.toString()),document.body.style.cursor=""),we.current&&(we.current=!1,localStorage.setItem("kb-right-sidebar-width",xe.toString()),document.body.style.cursor="")};return ke.current||we.current?(document.addEventListener("mousemove",i),document.addEventListener("mouseup",x)):document.addEventListener("mousemove",i),document.addEventListener("mousemove",i),document.addEventListener("mouseup",x),()=>{document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",x)}},[ie,xe]);const es=i=>{i.preventDefault(),ke.current=!0,document.body.style.cursor="col-resize"},ts=i=>{i.preventDefault(),we.current=!0,document.body.style.cursor="col-resize"},[lt,ss]=n.useState(null),dt=n.useRef(!1),ut=n.useRef(!1);n.useEffect(()=>{if(dt.current)return;dt.current=!0,(async()=>{await q.initialize();try{await mn()}catch(h){console.warn("[KnowledgeBaseContent] 提示词优化模板初始化失败:",h)}await ee();try{const h=await q.getStorageUsage();ss(h)}catch{}if(t){oe(t);return}const x=window.__kbPendingNavigation;if(x){window.__kbPendingNavigation=null;const{directoryName:h,autoCreateNote:E}=x;if(h){const I=(await q.getAllDirectories()).find(H=>H.name===h);if(I&&(l(I.id),b(H=>{const V=new Set(H);return V.add(I.id),V}),E)){const H=h==="Skill"?"新Skill":"新笔记",V=await q.createNote(H,I.id);await ee(),b(ue=>{const _e=new Set(ue);return _e.add(I.id),_e}),z(V.id);const ce=await q.getNoteById(V.id);p(ce),j([])}}}})()},[]);const ee=n.useCallback(async()=>{const[i,x,h]=await Promise.all([q.getAllDirectories(),q.getAllNoteMetas(),q.getAllTags()]),E=Array.from(new Map(i.map(H=>[H.id,H])).values());r(E);const C=Array.from(new Map(x.map(H=>[H.id,H])).values());c(C);const I=Array.from(new Map(h.map(H=>[H.id,H])).values());d(I),!k&&!g&&E.length>0&&(l(E[0].id),b(new Set([E[0].id]))),await ns(C)},[k,g]),ns=n.useCallback(async i=>{try{const[x,h]=await Promise.all([q.getAllTags(),q.getAllNoteTags()]),E=new Map(x.map(I=>[I.id,I])),C={};for(const I of i)C[I.id]=[];for(const I of h)if(C[I.noteId]&&E.has(I.tagId)){const H=E.get(I.tagId);H&&(C[I.noteId].some(V=>V.id===H.id)||C[I.noteId].push(H))}for(const I in C)C[I].sort((H,V)=>H.name.localeCompare(V.name));m(C)}catch(x){console.error("Failed to refresh note tags map:",x)}},[]);n.useEffect(()=>{if(!P.trim()){w(null);return}return B.current&&clearTimeout(B.current),B.current=setTimeout(async()=>{try{const x=await Ht().search(P,{limit:50,filter:k?{directoryId:k}:{}});w(x)}catch{w(null)}},300),()=>{B.current&&clearTimeout(B.current)}},[P,k]);const de=n.useMemo(()=>{if(D&&P.trim()){const x=new Set(D.map(C=>C.id)),h=new Map(D.map((C,I)=>[C.id,I]));let E=a.filter(C=>x.has(C.id));if(T.length>0){const C=new Set(T);E=E.filter(I=>(N[I.id]||[]).some(V=>C.has(V.id)))}return E.sort((C,I)=>(h.get(C.id)??0)-(h.get(I.id)??0))}let i=a;if(T.length>0){const x=new Set(T);i=i.filter(h=>(N[h.id]||[]).some(C=>x.has(C.id)))}return q.sortNoteMetas(i,O)},[a,k,P,T,O,N,D]),rs=n.useMemo(()=>{const i={},x=new Set;for(const h of de)x.has(h.id)||(x.add(h.id),i[h.directoryId]=(i[h.directoryId]||0)+1);return i},[de]),as=n.useMemo(()=>{var x;const i={};for(const h of de){const E=i[x=h.directoryId]??(i[x]=[]);E.some(C=>C.id===h.id)||E.push(h)}return i},[de]),Ue=n.useCallback(async i=>{await q.createDirectory(i),await ee()},[ee]),is=n.useCallback(async(i,x)=>{await q.updateDirectory(i,{name:x}),await ee()},[ee]),os=n.useCallback(async i=>{var E;const x=s.find(C=>C.id===i);if(!(!x||!await L({title:"确认删除目录",description:`确定要删除目录 "${x.name}" 及其下的所有笔记吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0})))try{await q.deleteDirectory(i),k===i&&(l(((E=s[0])==null?void 0:E.id)||null),z(null),p(null)),await ee(),X.success("目录已删除")}catch(C){X.error(`删除失败: ${C.message}`)}},[ee,k,s]),cs=n.useCallback(async i=>{try{await q.duplicateDirectory(i),await ee(),X.success("目录复制成功")}catch(x){X.error(`复制目录失败: ${x.message}`)}},[ee]),ls=n.useCallback(i=>{b(x=>{const h=new Set(x);return h.has(i)?h.delete(i):h.add(i),h})},[]),oe=n.useCallback(async i=>{const x=++_.current;if(z(i),l(null),j(N[i]||[]),i.startsWith(ge)){const E=i.slice(ge.length),C=Je.find(I=>I.id===E);if(C){const I=["image","inspiration","grid_image"],H=["ppt"],V=C.mcpTool&&I.some(ue=>C.mcpTool.includes(ue))?"image":C.mcpTool&&H.some(ue=>C.mcpTool.includes(ue))?"ppt":void 0,ce={id:i,title:C.name,content:C.description||"",directoryId:"",createdAt:0,updatedAt:0,metadata:{...V?{outputType:V}:{}}};x===_.current&&(p(ce),j([]))}return}if(i.startsWith(fe)){const E=i.slice(fe.length),C=gn(E);if(C){const I={id:i,title:C.name,content:C.content||C.description||"",directoryId:"",createdAt:0,updatedAt:0,metadata:{...C.outputType?{outputType:C.outputType}:{},...C.category?{category:C.category}:{}}};x===_.current&&(p(I),j([]))}return}const h=await q.getNoteById(i);if(x===_.current&&(p(h),h)){const E=await q.getTagsForNote(h.id);if(x!==_.current)return;j(E),b(C=>{const I=new Set(C);return I.add(h.directoryId),I})}},[s,N]),Be=n.useCallback(async i=>{const x=new Set(a.filter(V=>V.directoryId===i).map(V=>V.title)),h=s.find(V=>V.id===i),E=(h==null?void 0:h.name)==="Skill"?"新Skill":"新笔记";let C=E,I=1;for(;x.has(C);)C=`${E} ${I}`,I++;const H=await q.createNote(C,i);await ee(),b(V=>{const ce=new Set(V);return ce.add(i),ce}),oe(H.id)},[ee,oe,a,s]),Fe=n.useCallback(async(i,x)=>{await q.updateNote(i,x),c(h=>h.map(E=>E.id===i?{...E,...x,updatedAt:Date.now()}:E)),(u==null?void 0:u.id)===i&&p(h=>h&&{...h,...x,updatedAt:Date.now()});try{const h=window.__drawnixBoard;if(h&&h.children){const{Transforms:E}=await qe(async()=>{const{Transforms:C}=await import("./ai-chat-BnWVpTEI.js").then(I=>I.sM);return{Transforms:C}},__vite__mapDeps([0]),import.meta.url);h.children.forEach((C,I)=>{if(C.noteId===i){const H={};x.title!==void 0&&(H.title=x.title),x.content!==void 0&&(H.body=x.content),Object.keys(H).length>0&&E.setNode(h,H,[I])}})}}catch(h){console.warn("[KB] Failed to sync note update to canvas card:",h)}},[u]),ds=n.useCallback(async i=>{if(!u)return;const x=u.content?`
|
|
52
52
|
|
|
53
|
-
`:"",h=(u.content||"")+x+i;await Fe(u.id,{content:h}),X.success("已插入到笔记末尾")},[u,Fe]),us=n.useCallback(async i=>{var h,E;const x=window.__drawnixBoard;if(!x){X.warning("请先打开画布");return}try{if(x.children.find(he=>he.noteId===i.id)&&!await L({title:"重复插入提醒",description:"画布中已存在关联该笔记的卡片,是否再次插入?",confirmText:"继续插入",cancelText:"取消"}))return;const I=await q.getNoteById(i.id);if(!I){X.error("获取笔记内容失败");return}const{getViewportOrigination:H}=await qe(async()=>{const{getViewportOrigination:he}=await import("./ai-chat-
|
|
53
|
+
`:"",h=(u.content||"")+x+i;await Fe(u.id,{content:h}),X.success("已插入到笔记末尾")},[u,Fe]),us=n.useCallback(async i=>{var h,E;const x=window.__drawnixBoard;if(!x){X.warning("请先打开画布");return}try{if(x.children.find(he=>he.noteId===i.id)&&!await L({title:"重复插入提醒",description:"画布中已存在关联该笔记的卡片,是否再次插入?",confirmText:"继续插入",cancelText:"取消"}))return;const I=await q.getNoteById(i.id);if(!I){X.error("获取笔记内容失败");return}const{getViewportOrigination:H}=await qe(async()=>{const{getViewportOrigination:he}=await import("./ai-chat-BnWVpTEI.js").then(We=>We.sM);return{getViewportOrigination:he}},__vite__mapDeps([0]),import.meta.url),V=H(x),ce=((h=x.host)==null?void 0:h.clientWidth)||800,ue=((E=x.host)==null?void 0:E.clientHeight)||600,_e=Math.round(window.innerWidth*.5),xt=180,kt=((V==null?void 0:V[0])??0)+ce/2-_e/2,wt=((V==null?void 0:V[1])??0)+ue/2-xt/2,{Transforms:js}=await qe(async()=>{const{Transforms:he}=await import("./ai-chat-BnWVpTEI.js").then(We=>We.sM);return{Transforms:he}},__vite__mapDeps([0]),import.meta.url),ys={type:"card",id:`card-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,title:I.title||"无标题",body:I.content||"",noteId:I.id,fillColor:"#FA8C16",points:[[kt,wt],[kt+_e,wt+xt]]};js.insertNode(x,ys,[x.children.length]),X.success("已插入到画布")}catch(C){console.error("[KB] Failed to insert note to canvas:",C),X.error(`插入失败: ${C.message}`)}},[]),hs=n.useCallback(async i=>{try{await q.duplicateNote(i),await ee(),X.success("笔记复制成功")}catch(x){X.error(`复制笔记失败: ${x.message}`)}},[ee]),ms=n.useCallback(async i=>{if(i.startsWith(ge)){X.warning("系统内置 Skill,不可删除");return}if(i.startsWith(fe)){X.warning("外部 Skill,不可在此删除(请在设置中管理外部 Skill 包)");return}const x=a.find(E=>E.id===i);if(!(!x||!await L({title:"确认删除笔记",description:`确定要删除笔记 "${x.title||"无标题"}" 吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0})))try{await q.deleteNote(i),g===i&&(z(null),p(null),j([])),await ee(),X.success("笔记已删除")}catch(E){X.error(`删除失败: ${E.message}`)}},[g,ee,a]);n.useEffect(()=>{!ut.current&&de.length>0&&(oe(de[0].id),ut.current=!0)},[de,oe]),n.useEffect(()=>{const i=x=>{const{noteId:h}=x.detail;h&&oe(h)};return window.addEventListener("kb:open-note",i),()=>window.removeEventListener("kb:open-note",i)},[oe]),n.useEffect(()=>{const i=async x=>{const{directoryName:h,autoCreateNote:E}=x.detail;if(!h)return;window.__kbPendingNavigation&&(window.__kbPendingNavigation=null);const I=(await q.getAllDirectories()).find(H=>H.name===h);I&&(l(I.id),b(H=>{const V=new Set(H);return V.add(I.id),V}),E&&await Be(I.id))};return window.addEventListener("kb:navigate",i),()=>window.removeEventListener("kb:navigate",i)},[Be]);const fs=n.useCallback(async(i,x)=>{await q.setNoteTags(i,x);const h=await q.getTagsForNote(i);j(h),m(C=>({...C,[i]:h}));const E=await q.getAllTags();d(E)},[]),ht=n.useCallback(async i=>{const x=await q.createTag(i),h=await q.getAllTags();return d(h),x},[]),gs=n.useCallback(async(i,x)=>{await q.updateTag(i,{name:x});const h=await q.getAllTags();d(h)},[]),ps=n.useCallback(async i=>{await q.deleteTag(i);const x=await q.getAllTags();if(d(x),u){const h=await q.getTagsForNote(u.id);j(h),m(E=>({...E,[u.id]:h}))}},[u]),bs=n.useCallback(i=>{f(i),q.saveSortPreference&&q.saveSortPreference(i)},[]);n.useEffect(()=>{if(!W)return;const i=x=>{A.current&&!A.current.contains(x.target)&&U(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[W]);const Se=n.useRef(null),mt=n.useCallback(()=>{var i;(i=Se.current)==null||i.click()},[]),xs=n.useCallback(async i=>{const x=i.target.files;if(!(!x||!k)){for(const h of Array.from(x)){if(!h.name.endsWith(".md")&&!h.name.endsWith(".markdown"))continue;const E=await h.text();await sn(E,k,h.name)}await ee(),Se.current&&(Se.current.value="")}},[k,ee]),ft=n.useCallback(async()=>{try{const i=await nn(),x=URL.createObjectURL(i),h=document.createElement("a");h.href=x,h.download=`knowledge-base-${new Date().toISOString().slice(0,10)}.zip`,document.body.appendChild(h),h.click(),document.body.removeChild(h),URL.revokeObjectURL(x)}catch(i){console.error("Export failed:",i),X.error("导出失败")}},[]),Ee=n.useRef(null),gt=n.useCallback(()=>{var i;(i=Ee.current)==null||i.click()},[]),ks=n.useCallback(async i=>{var h;const x=(h=i.target.files)==null?void 0:h[0];if(x){try{if(x.name.toLowerCase().endsWith(".zip")){const E=await rn(x);E.noteCount===0&&E.dirCount===0?X.warning("导入完成:没有新增内容(可能已存在重复内容)"):X.success(`导入完成:${E.dirCount} 个新目录、${E.noteCount} 篇笔记`)}else{const E=await x.text(),C=JSON.parse(E);if(C.version!==1&&C.version!==2){X.error("不支持的导入格式");return}const I=await an(C);X.success(`导入完成:${I.dirCount} 个目录、${I.noteCount} 篇笔记、${I.tagCount} 个标签`)}await ee()}catch(E){console.error(E),X.error("导入失败,请确认文件格式正确")}Ee.current&&(Ee.current.value="")}},[ee]),pt=n.useCallback(()=>{const i=window.prompt("请输入目录名称","新建目录");i&&Ue(i)},[Ue]),ws=n.useCallback(i=>{switch(i.value){case"create-dir":pt();break;case"manage-tags":J(!0);break;case"import-md":mt();break;case"import-zip":gt();break;case"export-zip":ft();break}},[pt,mt,gt,ft]),_s=n.useMemo(()=>[{content:"新建目录",value:"create-dir",prefixIcon:e.jsx(on,{size:14})},{content:"管理标签",value:"manage-tags",prefixIcon:e.jsx(cn,{size:14})},{content:"导入 Markdown",value:"import-md",prefixIcon:e.jsx(Nt,{size:14})},{content:"导入 ZIP",value:"import-zip",prefixIcon:e.jsx(Nt,{size:14})},{content:"导出 ZIP",value:"export-zip",prefixIcon:e.jsx(it,{size:14})}],[]);return e.jsxs("div",{className:"kb-drawer",children:[e.jsx("input",{ref:Se,type:"file",accept:".md,.markdown",multiple:!0,style:{display:"none"},onChange:xs}),e.jsx("input",{ref:Ee,type:"file",accept:".json,.zip",style:{display:"none"},onChange:ks}),e.jsxs("div",{className:"kb-drawer__body",ref:$e,children:[e.jsxs("div",{className:"kb-drawer__sidebar",style:{width:ie},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(Te,{size:"small",prefixIcon:e.jsx(qt,{size:14}),placeholder:"搜索笔记...",value:P,onChange:i=>$(i),clearable:!0,style:{flex:1}}),e.jsx(Xt,{trigger:"click",options:_s,onClick:ws,minColumnWidth:120,maxColumnWidth:200,popupProps:{overlayStyle:{width:200}},children:e.jsx(G,{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:i=>i.currentTarget.style.backgroundColor="var(--td-bg-color-container-hover)",onMouseLeave:i=>i.currentTarget.style.backgroundColor="transparent",children:e.jsx(ln,{size:18})})})})]}),e.jsxs("div",{className:"kb-drawer__filters",style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(On,{allTags:o,selectedTagIds:T,onSelectedChange:F}),e.jsx("div",{style:{flex:1}}),e.jsx(cr,{value:O,onChange:bs})]})]}),e.jsx(En,{directories:s,notesByDir:as,noteTagsMap:N,noteCounts:rs,selectedDirId:k,selectedNoteId:g,expandedDirIds:S,onSelectDir:i=>{l(i),z(null),p(null)},onToggleExpand:ls,onCreateDir:Ue,onRenameDir:is,onDeleteDir:os,onDuplicateDir:cs,onSelectNote:oe,onCreateNote:Be,onDeleteNote:ms,onDuplicateNote:hs,isCreatingDir:te,onCancelCreateDir:()=>y(!1),onInsertNoteToCanvas:us}),lt&&e.jsxs("div",{className:"kb-drawer__storage-bar",children:[e.jsx(dn,{size:12}),e.jsxs("span",{className:"kb-drawer__storage-text",children:["已用 ",lr(lt.used)]})]})]}),e.jsx("div",{className:"kb-resizer",onMouseDown:es}),e.jsx("div",{className:"kb-drawer__editor",children:e.jsx(qn,{note:u,allTags:o,noteTags:v,readOnly:!!(g&&(g.startsWith(ge)||g.startsWith(fe))),isSkillDirectory:!!(u&&(((bt=s.find(i=>i.id===u.directoryId))==null?void 0:bt.name)==="Skill"||g&&g.startsWith(ge)||g&&g.startsWith(fe))),onUpdateNote:Fe,onSetNoteTags:fs,onCreateTag:ht})}),u&&e.jsx(e.Fragment,{children:M?e.jsx(G,{content:"展开侧边栏",showArrow:!1,children:e.jsx("button",{className:"kb-drawer__right-toggle",onClick:()=>Y(!1),children:e.jsx(un,{size:14})})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"kb-resizer",onMouseDown:ts}),e.jsxs("div",{className:"kb-drawer__right-sidebar",style:{width:xe},children:[e.jsxs("div",{className:"kb-drawer__right-header",children:[e.jsxs("div",{className:"kb-drawer__right-tabs",children:[e.jsx(G,{content:"相似笔记",showArrow:!1,children:e.jsx("button",{className:`kb-drawer__right-tab ${Q==="related"?"kb-drawer__right-tab--active":""}`,onClick:()=>Z("related"),children:e.jsx(Kt,{size:14})})}),e.jsx(G,{content:"知识提取",showArrow:!1,children:e.jsx("button",{className:`kb-drawer__right-tab ${Q==="extraction"?"kb-drawer__right-tab--active":""}`,onClick:()=>Z("extraction"),children:e.jsx(Ze,{size:14})})})]}),e.jsx(G,{content:"收起侧边栏",showArrow:!1,children:e.jsx("button",{className:"kb-drawer__right-collapse-btn",onClick:()=>Y(!0),children:e.jsx(hn,{size:14})})})]}),e.jsx("div",{className:"kb-drawer__right-content",children:Q==="related"?e.jsx(Kn,{currentNoteId:u.id,allNotes:a,noteTagsMap:N,onSelectNote:oe}):e.jsx(or,{noteId:u.id,noteContent:u.content,noteTitle:u.title,onSaved:()=>ee(),onInsertToNote:ds},u.id)})]})]})})]}),e.jsx(Hn,{visible:R,onClose:()=>J(!1),allTags:o,onCreateTag:ht,onUpdateTag:gs,onDeleteTag:ps}),K]})};function lr(t){if(t===0)return"0 B";const s=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(1024));return`${(t/Math.pow(1024,r)).toFixed(1)} ${s[r]}`}export{wr as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{sm as ns,sn as os,so as is,sp as ls,sq as cs,bO as Jt,sr as ds,r_ as st,s6 as Xt,ss as Da,st as us,su as ms,sc as Oa,P as s,r$ as Mt,en as rt,rY as ye,Q as Ce,bm as fs,T as Ae,aD as He,bP as ze,rZ as nt,a8 as t,s3 as Ba,s4 as La,f3 as Ne,nN as Qt,f2 as Nt,s5 as ea,rF as Fa,rI as za,rK as Ua,rT as ps,rL as hs,rM as vs,rN as gs,aR as _s,sv as bs,sw as ys,sb as Ss,rc as ha,el as Is,nZ as va,o4 as ga,sd as _a,nq as Cs,ns as xs,o5 as js,o8 as ws,nO as ba,rq as ya,ao as et,sg as ks,se as Sa,eP as Ct,sf as Ft,n$ as Ts,sh as zt,si as Ia,sj as Ms,nF as Ut,a3 as Ns,c1 as ut,nL as Ca,ab as tt,pp as $s,sx as As,sy as Ps,fA as xa,cO as Gt,eI as ja,sk as Es,rw as xt,rx as Rs,ry as Vs,oG as Ds,c5 as Os,rA as Bs,rB as Ls,rC as Fs}from"./ai-chat-
|
|
1
|
+
import{sm as ns,sn as os,so as is,sp as ls,sq as cs,bO as Jt,sr as ds,r_ as st,s6 as Xt,ss as Da,st as us,su as ms,sc as Oa,P as s,r$ as Mt,en as rt,rY as ye,Q as Ce,bm as fs,T as Ae,aD as He,bP as ze,rZ as nt,a8 as t,s3 as Ba,s4 as La,f3 as Ne,nN as Qt,f2 as Nt,s5 as ea,rF as Fa,rI as za,rK as Ua,rT as ps,rL as hs,rM as vs,rN as gs,aR as _s,sv as bs,sw as ys,sb as Ss,rc as ha,el as Is,nZ as va,o4 as ga,sd as _a,nq as Cs,ns as xs,o5 as js,o8 as ws,nO as ba,rq as ya,ao as et,sg as ks,se as Sa,eP as Ct,sf as Ft,n$ as Ts,sh as zt,si as Ia,sj as Ms,nF as Ut,a3 as Ns,c1 as ut,nL as Ca,ab as tt,pp as $s,sx as As,sy as Ps,fA as xa,cO as Gt,eI as ja,sk as Es,rw as xt,rx as Rs,ry as Vs,oG as Ds,c5 as Os,rA as Bs,rB as Ls,rC as Fs}from"./ai-chat-BnWVpTEI.js";import{e as zs}from"./task-sync-C5XXOQ5m.js";import{ax as wa,aW as Us,ap as Ga}from"./tool-windows-Bf_pMml-.js";/* empty css */import{R as Gs}from"./ResizableDivider-BvT-DCEo.js";import{r as Ks,a as Hs,b as ka,w as Kt,d as Ws,g as Ys,f as qs}from"./workflow-generation-utils-e0nRpAgJ.js";/* empty css */import{u as Js}from"./VideoAnalyzer-DnowtohS.js";/* empty css */import"./startup-runtime-BrfuwjQS.js";const $t="mv-creator:records",Zs=50;async function At(){return ns($t)}async function Ta(e){return is($t,e,Zs)}async function le(e,o){return os($t,e,o)}async function Xs(e){return ls($t,e)}const Qs=10,Ka="原创性与合规要求:若音乐、歌词、创作 Brief 或用户提示词包含知名影视、动画、游戏、音乐、品牌、角色、商标、Logo、台词、歌词或受保护作品名称,不要复刻或仿写,不要使用原名称、标志性造型、独特服装、台词、歌词、镜头或世界观;请改写为原创的泛化角色、场景、音乐情绪和视觉元素,并保持商业可用。";function Ha(e,o,i,m){return{id:Jt(),createdAt:Date.now(),label:o,prompt:i,shots:structuredClone(e),...m!=null&&m.characters?{characters:structuredClone(m.characters)}:{},...m!=null&&m.videoStyle?{videoStyle:m.videoStyle}:{}}}function Wa(e,o){return ds(e,"storyboardVersions",o,Qs,{editedShots:o.shots})}const Tt=cs;function er(e,o){return ms(e,"storyboardVersions",o,{getVersionPatch:i=>({editedShots:i.shots,...i.characters?{characters:structuredClone(i.characters)}:{},...i.videoStyle?{videoStyle:i.videoStyle}:{}}),getOriginalPatch:i=>{var u;const m=(u=i.storyboardVersions)==null?void 0:u[i.storyboardVersions.length-1];return m?{editedShots:[...m.shots]}:null},originalVersionId:Tt})}function Ke(e,o){return us(e,"storyboardVersions",o)}function Ya(e,o=e.editedShots||[]){var A,M,S;const i=e.selectedClipDuration||o.reduce((v,W)=>Math.max(v,W.endTime||0),0),m=(A=e.musicStyleTags)==null?void 0:A.filter(Boolean).join(", "),u=e.characters||[],y=Oa(e.creativeBrief),_=["# 爆款MV脚本","",`**音乐标题:** ${e.musicTitle||"-"}`,`**音乐风格:** ${m||"-"}`,`**时长:** ${i||0}s`,`**画面比例:** ${e.aspectRatio||"16x9"}`,`**视频风格:** ${e.videoStyle||"-"}`];y&&_.push("","## 创作 Brief","",y),(M=e.musicLyrics)!=null&&M.trim()&&_.push("","## 歌词","",e.musicLyrics.trim()),(S=e.rewritePrompt)!=null&&S.trim()&&_.push("","## 改编提示词","",e.rewritePrompt.trim()),u.length>0&&(_.push("","## 角色设定",""),u.forEach((v,W)=>{_.push(`### ${W+1}. ${v.name||v.id}`),_.push(`- ID:${v.id}`),_.push(`- 外观提示词:${v.description||"-"}`),v.referenceImageUrl&&_.push(`- 参考图:${v.referenceImageUrl}`),_.push("")}));const k=o.map((v,W)=>{var L;return[`### ${W+1}. ${v.label||`镜头 ${W+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{_ as gt}from"./startup-runtime-BrfuwjQS.js";import{ep as kt,P as l,oP as C,qf as $,R as wt,qg as F,qh as Me,qi as St,oC as Pe,a8 as t,c$ as Nt,eU as jt,ab as Ee,eN as Ct,fx as re,nN as It,dr as Mt,qj as Et,ox as ye,ot as yt,ao as Ae,pH as ge,qk as At,qb as Rt,eL as Lt,pi as Pt,bM as Dt,ql as Tt,c1 as $t}from"./ai-chat-
|
|
1
|
+
import{_ as gt}from"./startup-runtime-BrfuwjQS.js";import{ep as kt,P as l,oP as C,qf as $,R as wt,qg as F,qh as Me,qi as St,oC as Pe,a8 as t,c$ as Nt,eU as jt,ab as Ee,eN as Ct,fx as re,nN as It,dr as Mt,qj as Et,ox as ye,ot as yt,ao as Ae,pH as ge,qk as At,qb as Rt,eL as Lt,pi as Pt,bM as Dt,ql as Tt,c1 as $t}from"./ai-chat-BnWVpTEI.js";import{b as Kt}from"./model-benchmark-launcher-DNMp2MLQ.js";import{aV as Vt}from"./tool-windows-Bf_pMml-.js";const le={text:"文本",image:"图片",video:"视频",audio:"音频"},ae={"cross-provider":"跨供应商对比","cross-model":"多模型批测",custom:"自定义测试"},Ot={"cross-provider":"锁定一个模型,横向比较不同供应商的稳定性、速度和效果差异。","cross-model":"锁定一个供应商,一次跑完同类模型,快速筛掉慢和差的型号。",custom:"手动编排供应商与模型组合,适合做定向复测和候选名单对比。"},Ft={speed:"速度优先",cost:"成本优先",balanced:"综合平衡","value-for-money":"性价比"},Re={draft:"待启动",running:"测试中",completed:"已完成",partial:"部分失败",failed:"全部失败"},be={pending:"待测",running:"测试中",completed:"已完成",failed:"失败"},Bt=6,qt=8,He=32e3;function zt(o){return o instanceof Error?o.message:"unknown_error"}function Gt(o){const i=new Set;return{...o.reduce((c,p)=>(p.entries.forEach(h=>{i.add(`${p.modality}::${h.selectionKey}`),c.detailRowCount+=1,h.status==="completed"&&(c.completedEntryCount+=1),h.status==="failed"&&(c.failedEntryCount+=1),h.status==="running"&&(c.runningEntryCount+=1),h.status==="pending"&&(c.pendingEntryCount+=1),h.favorite&&(c.favoriteEntryCount+=1),h.rejected&&(c.rejectedEntryCount+=1)}),c),{sessionCount:o.length,detailRowCount:0,completedEntryCount:0,failedEntryCount:0,runningEntryCount:0,pendingEntryCount:0,favoriteEntryCount:0,rejectedEntryCount:0}),modelSummaryRowCount:i.size}}function N(o,i){ge("model_benchmark_config_changed",{source:"workbench",control:o,...i})}function ie(o){return o?new Date(o).toLocaleString("zh-CN",{hour12:!1}):""}function ot(o){return o.length>He?`${o.slice(0,He-8)}...[截断]`:o}function W(o){return o?o.startsWith("data:")?"[内嵌数据已省略]":ot(o):""}function Je(o){return o!=null&&o.length?ot(o.map(i=>W(i)).join(`
|
|
2
2
|
`)):""}function Ze(o){return o?"是":"否"}function _e(o){let i=0,r=0;return o.forEach(c=>{typeof c=="number"&&Number.isFinite(c)&&(i+=c,r+=1)}),r>0?Number((i/r).toFixed(2)):null}function Ut(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 Le(o){return o!==null}function Xt(o){return o.trim().toLowerCase().split(/\s+/).filter(Boolean)}function xe(o,i){const r=Xt(o);if(r.length===0)return!0;const c=i.filter(Boolean).join(" ").toLowerCase();return r.every(p=>c.includes(p))}function Qt(o){return o==="text"?"supportsText":o==="image"?"supportsImage":o==="video"?"supportsVideo":"supportsAudio"}function et(o,i){const r=Qt(i);return o.filter(c=>c.enabled&&(c.id===yt||c.capabilities[r]))}function Wt(){const[o,i]=l.useState(0);return l.useEffect(()=>Pe.subscribe(()=>{i(r=>r+1)}),[]),o}function Yt(){const[o,i]=l.useState(()=>ye.get());return l.useEffect(()=>{const r=c=>{i(c)};return ye.addListener(r),()=>{ye.removeListener(r)}},[]),o}function ve(o){return!o||o<0?"--":o<1e3?`${o}ms`:`${(o/1e3).toFixed(o>=1e4?1:2)}s`}function Ht(o){const i=new Map;o.entries.forEach(c=>{var ce,m;const p=(ce=c.modelId)==null?void 0:ce.trim(),h=(m=c.modelLabel)==null?void 0:m.trim();p&&h&&!i.has(p)&&i.set(p,{modelId:p,modelLabel:h})});const r=new Map;return i.forEach(({modelLabel:c})=>{r.set(c,(r.get(c)||0)+1)}),Array.from(i.values()).map(({modelId:c,modelLabel:p})=>(r.get(p)||0)>1?`${p} · ${c}`:p)}function tt(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 I(o,i){const r=Pe.getState(o).models.filter(p=>p.type===i),c=new Map;return r.forEach(p=>{c.has(p.id)||c.set(p.id,p)}),Array.from(c.values())}function nt(o){return o.shortLabel||o.label||o.id}function st(o){const i=nt(o);return i===o.id?i:`${i} · ${o.id}`}function Jt(o,i){return`${o}::${i}`}function rs({}){const{confirm:o,confirmDialog:i}=kt(),r=Vt(Kt),c=Yt(),p=Wt(),[h,ce]=l.useState(()=>C.getState()),[m,De]=l.useState("text"),[u,Te]=l.useState("cross-provider"),[v,de]=l.useState(""),[R,me]=l.useState(""),[B,K]=l.useState([]),[q,Y]=l.useState([]),[z,H]=l.useState([]),[G,Zt]=l.useState(""),[U,es]=l.useState(!1),[rt,$e]=l.useState($("text").id),[ue,ke]=l.useState($("text").prompt),[Ke,lt]=l.useState([]),[Ve,at]=l.useState(2),[we,Oe]=l.useState(!1),[Se,Fe]=l.useState(!1),[Ne,it]=l.useState("speed"),[je,ct]=l.useState(""),[pe,dt]=l.useState("all"),Be=l.useRef(""),L=l.useRef(!1),Ce=l.useRef(!1),he=l.useRef(null);l.useRef({}),l.useEffect(()=>{const e=C.observe().subscribe(s=>{l.startTransition(()=>{ce(s)})});return()=>e.unsubscribe()},[]);const j=l.useMemo(()=>et(c,m),[m,c]),J=l.useMemo(()=>new Map(j.map(e=>[e.id,e])),[j]),y=v&&J.get(v)||null,mt=wt.useCallback(async e=>{await o({title:"确认删除会话",description:`确定要删除会话「${e.title||"未命名会话"}」吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0})&&C.removeSession(e.id)},[o]),P=l.useMemo(()=>v?I(v,m):[],[p,m,v]),Ie=l.useMemo(()=>{const e=new Map;return j.forEach(s=>{I(s.id,m).forEach(d=>{e.has(d.id)||e.set(d.id,d)})}),Array.from(e.values())},[j,p,m]),D=l.useMemo(()=>j.flatMap(e=>I(e.id,m).map(s=>F(e.id,e.name,s))),[j,p,m]);l.useEffect(()=>{if(L.current)return;if(!j.length){de("");return}const e=$(m);$e(e.id),ke(s=>s===$("text").prompt||s===$("image").prompt||s===$("video").prompt||s===$("audio").prompt?e.prompt:s),(!v||!J.has(v))&&de(j[0].id)},[j,m,J,v]),l.useEffect(()=>{if(L.current)return;const e=P.map(s=>s.id);if(e.length===0){K([]);return}K(s=>Me(s,e,{fallback:"all"}))},[P]),l.useEffect(()=>{if(L.current)return;const e=Ie.map(s=>s.id);if(e.length===0){me("");return}e.includes(R)||me(e[0])},[Ie,R]);const V=l.useMemo(()=>R?j.map(e=>{const s=I(e.id,m).find(d=>d.id===R);return s?F(e.id,e.name,s):null}).filter(Le):[],[j,m,R]);l.useEffect(()=>{L.current||Y(e=>Me(e,V.map(s=>s.profileId),{fallback:"all"}))},[V]),l.useEffect(()=>{L.current||H(e=>Me(e,D.map(s=>s.selectionKey),{fallback:"first",limit:Bt}))},[D]);const b=l.useMemo(()=>h.sessions.find(e=>e.id===h.activeSessionId)||null,[h.activeSessionId,h.sessions]),qe=l.useMemo(()=>h.sessions.filter(e=>pe!=="all"&&e.modality!==pe?!1:xe(je,[e.title,e.prompt,...(e.knowledgeContextRefs||[]).map(s=>s.title),ae[e.compareMode],le[e.modality],...e.entries.flatMap(s=>[s.profileName,s.profileId,s.modelLabel,s.modelId,s.vendor])])),[pe,je,h.sessions]);l.useEffect(()=>{b&&it(b.rankingMode)},[b]);const ut=l.useMemo(()=>tt(b),[b]),pt=l.useMemo(()=>b?St(b.entries,b.rankingMode):[],[b]),T=l.useMemo(()=>{if(u==="cross-provider")return V.filter(e=>q.includes(e.profileId));if(u==="cross-model"){if(!v)return[];const e=J.get(v);return e?P.filter(s=>B.includes(s.id)).map(s=>F(e.id,e.name,s)):[]}return D.filter(e=>z.includes(e.selectionKey))},[P,u,V,D,J,z,B,v,q]),ze=l.useMemo(()=>{if(!b||b.modality!==m||b.compareMode!==u)return!1;const e=T.map(d=>d.selectionKey);if(e.length===0||b.entries.length!==e.length)return!1;const s=new Set(e);return b.entries.every(d=>s.has(d.selectionKey))},[b,u,m,T]),Ge=l.useMemo(()=>b&&ze?b.entries.map(e=>({key:e.selectionKey,modelLabel:e.modelLabel,profileName:e.profileName,badgeLabel:be[e.status]||be.pending})):T.map(e=>({key:e.selectionKey,modelLabel:e.modelLabel,profileName:e.profileName,badgeLabel:be.pending})),[b,ze,T]),g=b,Z=g?ut:tt(null),Ue=g?pt:[];Ge.length,Ge.slice(0,qt);const M=Ue.find(e=>e.status==="completed")||null,Xe=l.useMemo(()=>P.filter(e=>{const s=B.includes(e.id);return U&&!s?!1:xe(G,[nt(e),e.id,y==null?void 0:y.name])}),[y==null?void 0:y.name,P,G,B,U]),Qe=l.useMemo(()=>V.filter(e=>{const s=q.includes(e.profileId);return U&&!s?!1:xe(G,[e.profileName,e.modelLabel,e.modelId,e.profileId])}),[V,G,q,U]),We=l.useMemo(()=>D.filter(e=>{const s=z.includes(e.selectionKey);return U&&!s?!1:xe(G,[e.profileName,e.modelLabel,e.modelId,e.profileId])}),[D,G,z,U]),fe=l.useMemo(()=>u==="cross-model"?Xe.map(e=>e.id):u==="cross-provider"?Qe.map(e=>e.profileId):We.map(e=>e.selectionKey),[u,Xe,Qe,We]);l.useEffect(()=>{if(fe.length===0){he.current=null;return}he.current&&fe.includes(he.current)||(he.current=fe[0])},[fe]),l.useEffect(()=>{var f;if(!r||!h.ready)return;const e=JSON.stringify(r);if(Be.current===e)return;const s=r.modality||"text",d=et(c,s),k=r.profileId||"",X=r.modelId||"",O=k?Pe.getState(k):null,ee=k&&X?I(k,s):[],te=!X||ee.some(_=>_.id===X);if(O&&X&&!te&&(O.status==="idle"||O.status==="loading"))return;L.current=!0,Be.current=e;const se=r.compareMode||(r.modelId?"cross-provider":"cross-model");let S=se,Q=[];const oe=r.profileId&&r.modelId?Jt(r.profileId,r.modelId):"";se==="cross-provider"&&r.modelId&&(Q=d.filter(_=>I(_.id,s).some(ne=>ne.id===r.modelId)).map(_=>_.id),Q.length<=1&&(S="custom"));const a=$(s);De(s),Te(S),$e(a.id),ke(a.prompt);const n=r.profileId||Q[0]||((f=d[0])==null?void 0:f.id)||"";if(n&&de(n),S==="cross-provider"&&r.modelId)me(r.modelId),Y(Q);else if(S==="cross-model"&&r.modelId)K([r.modelId]);else if(S==="cross-model"&&!r.modelId&&n){const _=I(n,s);K(_.map(ne=>ne.id))}else S==="custom"&&oe&&H([oe]);const E=window.setTimeout(()=>{let _;if(S==="cross-provider"&&r.modelId)_=d.map(x=>{const w=I(x.id,s).find(A=>A.id===r.modelId);return w?F(x.id,x.name,w):null}).filter(Le);else if(S==="cross-model"&&r.modelId){const x=d.find(w=>w.id===n);if(x){const w=I(x.id,s).find(A=>A.id===r.modelId);_=w?[F(x.id,x.name,w)]:[]}else _=[]}else if(S==="custom"){const x=d.find(w=>w.id===(r.profileId||n));if(x&&r.modelId){const w=I(x.id,s).find(A=>A.id===r.modelId);_=w?[F(x.id,x.name,w)]:[]}else _=[]}else{const x=n||v;x?_=I(x,s).map(w=>{const A=d.find(vt=>vt.id===x);return A?F(A.id,A.name,w):null}).filter(Le):_=[]}if(!_.length)return;if(!r.autoRun){requestAnimationFrame(()=>{setTimeout(()=>{L.current=!1},0)});return}const ne=C.createSession({modality:s,compareMode:S,promptPresetId:a.id,prompt:a.prompt,rankingMode:Ne,targets:_,source:"shortcut"});C.runSession(ne.id),requestAnimationFrame(()=>{setTimeout(()=>{L.current=!1},0)})},120);return()=>{window.clearTimeout(E)}},[p,r,c,Ne,v,h.ready]);const ht=async()=>{if(!(Ce.current||we)&&!(T.length===0||!ue.trim())){Ce.current=!0,Oe(!0);try{const e=C.createSession({modality:m,compareMode:u,promptPresetId:rt,prompt:ue,knowledgeContextRefs:Ke,rankingMode:Ne,targets:T,source:"manual"});await C.runSession(e.id,Ve)}finally{Ce.current=!1,Oe(!1)}}},ft=async()=>{if(Se)return;const e=h.sessions;if(e.length===0){Ae.warning("暂无历史会话可导出");return}const s=Date.now(),d=Gt(e);ge("model_benchmark_excel_export_started",{source:"workbench",...d}),Fe(!0);try{const k=await gt(()=>import("./office-data-DMEex_0S.js").then(a=>a.x),[],import.meta.url),X=e.flatMap(a=>a.entries.map(n=>{var E;return{会话标题:a.title,会话ID:a.id,会话创建时间:ie(a.createdAt),模态:le[a.modality],对比方式:ae[a.compareMode],会话状态:Re[a.status],提示词预设:a.promptPresetId,提示词:W(a.prompt),知识库上下文:Je((E=a.knowledgeContextRefs)==null?void 0:E.map(f=>f.title)),供应商配置:n.profileName,供应商ID:n.profileId,模型名称:n.modelLabel,模型ID:n.modelId,厂商:n.vendor,选择Key:n.selectionKey,结果ID:n.id,结果状态:be[n.status],开始时间:ie(n.startedAt),首响时间:ie(n.firstResponseAt),完成时间:ie(n.completedAt),首响ms:n.firstResponseMs,总耗时ms:n.totalDurationMs,预估成本:n.estimatedCost,用户评分:n.userScore,已收藏:Ze(n.favorite),已淘汰:Ze(n.rejected),错误摘要:W(n.errorSummary),预览文本:W(n.preview.text),预览链接:W(n.preview.url),预览链接列表:Je(n.preview.urls),预览格式:n.preview.format||"",预览时长:n.preview.duration??"",预览标题:W(n.preview.title)}})),O=new Map;e.forEach(a=>{a.entries.forEach(n=>{const E=`${a.modality}::${n.selectionKey}`,f=O.get(E)||{profileName:n.profileName,profileId:n.profileId,modelLabel:n.modelLabel,modelId:n.modelId,vendor:n.vendor,modality:le[a.modality],selectionKey:n.selectionKey,sessionIds:new Set,count:0,completedCount:0,failedCount:0,runningCount:0,pendingCount:0,favoriteCount:0,rejectedCount:0,firstResponseValues:[],totalDurationValues:[],costValues:[],scoreValues:[],latestAt:0};f.sessionIds.add(a.id),f.count+=1,n.status==="completed"&&(f.completedCount+=1),n.status==="failed"&&(f.failedCount+=1),n.status==="running"&&(f.runningCount+=1),n.status==="pending"&&(f.pendingCount+=1),n.favorite&&(f.favoriteCount+=1),n.rejected&&(f.rejectedCount+=1),typeof n.firstResponseMs=="number"&&f.firstResponseValues.push(n.firstResponseMs),typeof n.totalDurationMs=="number"&&f.totalDurationValues.push(n.totalDurationMs),typeof n.estimatedCost=="number"&&f.costValues.push(n.estimatedCost),typeof n.userScore=="number"&&f.scoreValues.push(n.userScore),f.latestAt=Math.max(f.latestAt,n.completedAt||n.startedAt||a.updatedAt||a.createdAt),O.set(E,f)})});const ee=Array.from(O.values()).map(a=>({供应商配置:a.profileName,供应商ID:a.profileId,模型名称:a.modelLabel,模型ID:a.modelId,厂商:a.vendor,模态:a.modality,选择Key:a.selectionKey,测试次数:a.count,涉及会话数:a.sessionIds.size,完成次数:a.completedCount,失败次数:a.failedCount,运行中次数:a.runningCount,待测次数:a.pendingCount,收藏次数:a.favoriteCount,淘汰次数:a.rejectedCount,平均首响ms:_e(a.firstResponseValues),最快首响ms:a.firstResponseValues.length>0?Math.min(...a.firstResponseValues):null,平均总耗时ms:_e(a.totalDurationValues),最快总耗时ms:a.totalDurationValues.length>0?Math.min(...a.totalDurationValues):null,平均成本:_e(a.costValues),平均评分:_e(a.scoreValues),最近测试时间:ie(a.latestAt)})).sort((a,n)=>{const E=(n.平均评分??-1)-(a.平均评分??-1);if(E!==0)return E;const f=(a.平均首响ms??Number.MAX_SAFE_INTEGER)-(n.平均首响ms??Number.MAX_SAFE_INTEGER);return f!==0?f:(a.平均成本??Number.MAX_SAFE_INTEGER)-(n.平均成本??Number.MAX_SAFE_INTEGER)}),te=k.utils.book_new(),se=k.utils.json_to_sheet(ee),S=k.utils.json_to_sheet(X);se["!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}],S["!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}],k.utils.book_append_sheet(te,se,"模型汇总"),k.utils.book_append_sheet(te,S,"原始结果");const Q=k.write(te,{bookType:"xlsx",type:"array"}),oe=new Blob([Q],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});At(oe,Ut()),ge("model_benchmark_excel_export_completed",{source:"workbench",...d,modelSummaryRowCount:ee.length,durationMs:Date.now()-s,fileSize:oe.size}),Ae.success(`已导出 ${ee.length} 个模型结果`)}catch(k){console.error("[ModelBenchmark] Excel export failed:",k),ge("model_benchmark_excel_export_failed",{source:"workbench",...d,durationMs:Date.now()-s,errorMessage:zt(k)}),Ae.error("导出 Excel 失败,请稍后重试")}finally{Fe(!1)}},bt=e=>{const s=e.preview.rawData?t.jsxs("details",{className:"model-benchmark__raw-data",children:[t.jsx("summary",{children:"原始数据 (JSON)"}),t.jsx("pre",{children:JSON.stringify(e.preview.rawData,null,2)})]}):null;return e.modality==="text"?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsx("pre",{className:"model-benchmark__preview-text",children:e.preview.text||"暂无返回"}),s]}):e.modality==="image"&&e.preview.url?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsx($t,{className:"model-benchmark__preview-image",src:e.preview.url,alt:e.modelLabel,showSkeleton:!1}),s]}):e.modality==="video"&&e.preview.url?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsx("video",{className:"model-benchmark__preview-video",src:e.preview.url,controls:!0,preload:"metadata"}),s]}):e.modality==="audio"&&e.preview.url?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsxs("div",{className:"model-benchmark__preview-audio-shell",children:[t.jsx("audio",{controls:!0,preload:"none",src:e.preview.url}),e.preview.text?t.jsx("pre",{className:"model-benchmark__preview-text",children:e.preview.text}):null]}),s]}):t.jsxs("div",{className:"model-benchmark__preview-empty",children:[e.status==="failed"?"加载失败":"暂无预览",s]})};u==="cross-model"?`${(y==null?void 0:y.name)||"未选择"}`:u==="cross-provider"&&`${R||"未选择"}`;const _t=Ie.map(e=>({label:st(e),value:e.id})),Ye=V.map(e=>({label:`${e.profileName} · ${e.modelLabel}`,value:e.profileId})),xt=[{label:"全部",value:"all",icon:t.jsx(Rt,{size:14})},{label:"图片",value:"image",icon:t.jsx(Lt,{size:"14px"})},{label:"视频",value:"video",icon:t.jsx(Pt,{size:"14px"})},{label:"音频",value:"audio",icon:t.jsx(Dt,{size:14,strokeWidth:1.9})},{label:"文本",value:"text",icon:t.jsx(Tt,{size:"14px"})}];return t.jsxs("div",{className:"model-benchmark",children:[t.jsxs("aside",{className:"model-benchmark__sidebar",children:[t.jsxs("div",{className:"model-benchmark__sidebar-head",children:[t.jsx("div",{className:"model-benchmark__panel-title",children:"历史会话"}),t.jsx("button",{type:"button",className:"model-benchmark__ghost-button",onClick:ft,disabled:h.sessions.length===0||Se,children:Se?"导出中...":"导出 Excel"})]}),t.jsxs("div",{className:"model-benchmark__sidebar-filters",children:[t.jsx(Nt,{value:je,onChange:ct,placeholder:"搜索会话 / 模型 / 供应商",prefixIcon:t.jsx(jt,{}),size:"small",clearable:!0}),t.jsx("div",{className:"model-benchmark__sidebar-tabs",children:xt.map(e=>t.jsx(Ee,{content:e.label,children:t.jsx("button",{type:"button",className:pe===e.value?"model-benchmark__sidebar-tab model-benchmark__sidebar-tab--active":"model-benchmark__sidebar-tab",onClick:()=>dt(e.value),"aria-label":e.label,children:e.icon})},e.value))})]}),t.jsx("div",{className:"model-benchmark__session-list",children:qe.length>0?qe.map(e=>{const s=Ht(e);return t.jsxs("div",{className:"model-benchmark__session-row",children:[t.jsxs("button",{type:"button",className:`model-benchmark__session-item ${e.id===h.activeSessionId?"model-benchmark__session-item--active":""}`,onClick:()=>C.setActiveSession(e.id),children:[t.jsx("span",{className:"model-benchmark__session-title",children:e.title}),t.jsx("span",{className:"model-benchmark__session-models",children:s.length>0?s.join(" / "):"暂无模型信息"}),t.jsxs("span",{className:"model-benchmark__session-meta",children:[ae[e.compareMode]," ·"," ",e.entries.length," 个目标 ·"," ",Re[e.status]]})]}),t.jsx("button",{type:"button",className:"model-benchmark__session-delete",onClick:()=>void mt(e),"aria-label":`删除会话 ${e.title}`,children:t.jsx(Ee,{content:"删除会话",showArrow:!1,children:t.jsx("span",{children:t.jsx(Ct,{})})})})]},e.id)}):t.jsx("div",{className:"model-benchmark__session-empty",children:h.sessions.length===0?"暂无历史会话":"没有匹配的历史会话"})})]}),t.jsx("main",{className:"model-benchmark__main",children:t.jsxs("div",{className:"model-benchmark__main-shell",children:[t.jsxs("section",{className:"model-benchmark__config-dashboard",children:[t.jsxs("div",{className:"model-benchmark__config-row model-benchmark__config-row--top",children:[t.jsx("div",{className:"model-benchmark__modality-tabs",children:Object.keys(le).map(e=>t.jsx("button",{type:"button",className:m===e?"active":"",onClick:()=>{m!==e&&N("modality",{previousModality:m,modality:e}),De(e)},children:le[e]},e))}),t.jsx("div",{className:"model-benchmark__mode-selector",children:Object.entries(ae).map(([e,s])=>t.jsx(Ee,{content:Ot[e],placement:"top",children:t.jsx("button",{type:"button",className:u===e?"active":"",onClick:()=>{const d=e;u!==d&&N("compare_mode",{modality:m,previousCompareMode:u,compareMode:d}),Te(d)},children:s})},e))})]}),t.jsxs("div",{className:"model-benchmark__config-main",children:[t.jsxs("div",{className:"model-benchmark__config-controls",children:[t.jsxs("div",{className:"model-benchmark__primary-select-row",children:[u==="cross-model"?t.jsx(re,{className:"model-benchmark__select",label:"目标供应商: ",value:v,onChange:e=>{const s=e;N("target_profile",{modality:m,compareMode:u,previousProfileId:v,profileId:s}),de(s)},options:j.map(e=>({label:e.name,value:e.id}))}):null,u==="cross-provider"?t.jsx(re,{filterable:!0,className:"model-benchmark__select",label:"对比模型: ",value:R,options:_t,placeholder:"搜索并选择要横向对比的模型",onChange:e=>{const s=e||"";N("target_model",{modality:m,compareMode:u,previousModelId:R,modelId:s}),me(s)}}):null]}),t.jsxs("div",{className:"model-benchmark__secondary-select-row",children:[u==="cross-provider"?t.jsx(re,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:t.jsxs("div",{className:"model-benchmark__select-actions",children:[t.jsx("button",{type:"button",onClick:()=>{const e=Ye.map(s=>s.value);N("provider_selection",{modality:m,compareMode:u,selectionAction:"select_all",selectedCount:e.length}),Y(e)},children:"全选"}),t.jsx("button",{type:"button",onClick:()=>{N("provider_selection",{modality:m,compareMode:u,selectionAction:"clear",selectedCount:0}),Y([])},children:"清除"})]}),className:"model-benchmark__multi-select",label:"参测供应商: ",value:q,options:Ye,placeholder:"多选要参与对比的供应商 (已选即为批测队列)",onChange:e=>{const s=Array.isArray(e)?e:[];N("provider_selection",{modality:m,compareMode:u,selectionAction:"change",previousSelectedCount:q.length,selectedCount:s.length}),Y(s)}}):null,u==="cross-model"?t.jsx(re,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:t.jsxs("div",{className:"model-benchmark__select-actions",children:[t.jsx("button",{type:"button",onClick:()=>{const e=P.map(s=>s.id);N("model_selection",{modality:m,compareMode:u,selectionAction:"select_all",selectedCount:e.length}),K(e)},children:"全选"}),t.jsx("button",{type:"button",onClick:()=>{N("model_selection",{modality:m,compareMode:u,selectionAction:"clear",selectedCount:0}),K([])},children:"清除"})]}),className:"model-benchmark__multi-select",label:"参测模型: ",value:B,options:P.map(e=>({label:st(e),value:e.id})),placeholder:"多选要测试的模型 (已选即为批测队列)",onChange:e=>{const s=Array.isArray(e)?e:[];N("model_selection",{modality:m,compareMode:u,selectionAction:"change",previousSelectedCount:B.length,selectedCount:s.length}),K(s)}}):null,u==="custom"?t.jsx(re,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:t.jsxs("div",{className:"model-benchmark__select-actions",children:[t.jsx("button",{type:"button",onClick:()=>{const e=D.map(s=>s.selectionKey);N("custom_selection",{modality:m,compareMode:u,selectionAction:"select_all",selectedCount:e.length}),H(e)},children:"全选"}),t.jsx("button",{type:"button",onClick:()=>{N("custom_selection",{modality:m,compareMode:u,selectionAction:"clear",selectedCount:0}),H([])},children:"清除"})]}),className:"model-benchmark__multi-select",label:"目标组合: ",value:z,options:D.map(e=>({label:`${e.profileName} · ${e.modelLabel}`,value:e.selectionKey})),placeholder:"手动编排供应商与模型组合",onChange:e=>{const s=Array.isArray(e)?e:[];N("custom_selection",{modality:m,compareMode:u,selectionAction:"change",previousSelectedCount:z.length,selectedCount:s.length}),H(s)}}):null]})]}),t.jsxs("div",{className:"model-benchmark__config-actions",children:[t.jsxs("div",{className:"model-benchmark__prompt-area",children:[t.jsx("textarea",{value:ue,onChange:e=>ke(e.target.value),placeholder:"在此输入测试提示词..."}),t.jsx(It,{value:Ke,onChange:lt,className:"model-benchmark__knowledge-context"})]}),t.jsxs("div",{className:"model-benchmark__action-row-inline",children:[t.jsxs("div",{className:"model-benchmark__concurrency",children:[t.jsx("span",{children:"最大并发:"}),t.jsx("input",{type:"text",inputMode:"numeric","aria-label":"最大并发",value:Ve,onChange:e=>{const s=e.target.value.replace(/\D/g,""),d=Number(s);at(Math.min(Mt,Math.max(1,d||1)))}})]}),t.jsx("button",{type:"button",className:"model-benchmark__primary-button",onClick:ht,disabled:we||!h.ready||T.length===0||!ue.trim(),children:we?"测试中...":`开始测试 (${T.length})`})]})]})]})]}),t.jsx("div",{className:"model-benchmark__main-head",children:t.jsxs("div",{children:[t.jsx("div",{className:"model-benchmark__eyebrow",children:g?ae[g.compareMode]:"Result Board"}),t.jsx("h3",{children:g?g.title:"还没有测试结果"}),g?t.jsxs("p",{className:"model-benchmark__main-desc",children:[Z.total," 个目标",Z.completed>0?`,${Z.completed} 成功`:"",Z.failed>0?`,${Z.failed} 失败`:""," · ",Re[g.status]," · ",Ft[g.rankingMode]]}):t.jsx("p",{className:"model-benchmark__main-desc",children:"请先在上方明确范围,或点击历史会话查看以往结果。"})]})}),g?t.jsxs(t.Fragment,{children:[M?t.jsxs("section",{className:"model-benchmark__spotlight",children:[t.jsxs("div",{className:"model-benchmark__spotlight-copy",children:[t.jsx("div",{className:"model-benchmark__eyebrow",children:"当前第一名"}),t.jsx("h4",{children:g.compareMode==="cross-provider"?M.profileName:M.modelLabel}),t.jsxs("p",{children:[g.compareMode==="cross-provider"?`${M.modelLabel},`:`来自 ${M.profileName},`,"首响 ",ve(M.firstResponseMs),",总耗时 ",ve(M.totalDurationMs)]})]}),t.jsxs("div",{className:"model-benchmark__spotlight-meta",children:[M.userScore?t.jsxs("span",{children:[M.userScore," 分"]}):null,M.favorite?t.jsx("span",{children:"已收藏"}):null]})]}):null,t.jsx("div",{className:"model-benchmark__result-grid",children:Ue.map((e,s)=>t.jsxs("article",{className:`model-benchmark__result-card model-benchmark__result-card--${e.status}`,children:[t.jsxs("header",{className:"model-benchmark__result-head",children:[t.jsxs("div",{className:"model-benchmark__result-rank",children:["#",s+1]}),t.jsxs("div",{className:"model-benchmark__result-heading",children:[t.jsx("div",{className:"model-benchmark__result-title",children:e.modelLabel}),t.jsx("div",{className:"model-benchmark__result-subtitle",children:e.profileName})]}),t.jsx("span",{className:`model-benchmark__status model-benchmark__status--${e.status}`,children:e.status==="completed"?"完成":e.status==="failed"?"失败":e.status==="running"?"测试中":"等待中"})]}),t.jsxs("div",{className:"model-benchmark__result-metrics",children:[t.jsxs("span",{children:["首响 ",ve(e.firstResponseMs)]}),t.jsxs("span",{children:["总耗时 ",ve(e.totalDurationMs)]}),t.jsxs("span",{children:["成本"," ",e.estimatedCost===null?"未知":`¥${e.estimatedCost.toFixed(4)}`]}),t.jsxs("span",{children:["性价比"," ",(()=>{const d=Et(e);return d===null?"—":`${d}/10`})()]})]}),t.jsx("div",{className:"model-benchmark__preview",children:bt(e)}),e.errorSummary?t.jsx("div",{className:"model-benchmark__error",children:e.errorSummary}):null,t.jsxs("div",{className:"model-benchmark__feedback",children:[t.jsx("div",{className:"model-benchmark__score-row",children:[1,2,3,4,5].map(d=>t.jsxs("button",{type:"button",className:`model-benchmark__score-chip ${e.userScore===d?"model-benchmark__score-chip--active":""}`,onClick:()=>C.setEntryFeedback(g.id,e.id,{userScore:e.userScore===d?null:d}),children:[d,"分"]},d))}),t.jsxs("div",{className:"model-benchmark__action-row",children:[t.jsx("button",{type:"button",className:`model-benchmark__ghost-button ${e.favorite?"model-benchmark__ghost-button--active":""}`,onClick:()=>C.setEntryFeedback(g.id,e.id,{favorite:!e.favorite}),children:"收藏"}),t.jsx("button",{type:"button",className:`model-benchmark__ghost-button ${e.rejected?"model-benchmark__ghost-button--danger":""}`,onClick:()=>C.setEntryFeedback(g.id,e.id,{rejected:!e.rejected}),children:"淘汰"})]})]})]},e.id))})]}):t.jsx("div",{className:"model-benchmark__empty",children:"先在左侧选定“同供应商多模型”或“同模型跨供应商”,把批测目标编满后再开跑。"})]})}),i]})}export{rs as default};
|