@fgbg/mdocs 1.3.17 → 1.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +14 -0
  3. package/agent-skills/index.json +1 -1
  4. package/agent-skills/usage-search/SKILL.md +14 -11
  5. package/dist/server/agent/Agent/tool-ui-effects.js +7 -1
  6. package/dist/server/agent/Agent/tool-ui-effects.js.map +1 -1
  7. package/dist/server/db/schema.js +30 -0
  8. package/dist/server/db/schema.js.map +1 -1
  9. package/dist/server/search/document-index-manager.js +33 -40
  10. package/dist/server/search/document-index-manager.js.map +1 -1
  11. package/dist/server/search/document-index-manager.test.js +194 -14
  12. package/dist/server/search/document-index-manager.test.js.map +1 -1
  13. package/dist/server/search/search.service.js +150 -42
  14. package/dist/server/search/search.service.js.map +1 -1
  15. package/dist/web/assets/{AgentChatPanel-C3c14Bo_.js → AgentChatPanel-DTj8Nz0Z.js} +2 -2
  16. package/dist/web/assets/{AgentSkillFormCard-BYUjSFe1.js → AgentSkillFormCard-DTgxybJh.js} +3 -3
  17. package/dist/web/assets/{AiWriteWorkbench-ze827qk7.js → AiWriteWorkbench-D2RzXzty.js} +3 -3
  18. package/dist/web/assets/{DiagramEditor-NtNY3sZL-Cie6NhLx.js → DiagramEditor-NtNY3sZL-B2Aeu79R.js} +1 -1
  19. package/dist/web/assets/{DocChrome-ixaNyUG9.js → DocChrome-4qmjr6wa.js} +1 -1
  20. package/dist/web/assets/{DocumentEditor-ByqPHijF.js → DocumentEditor-KEURMFDp.js} +1 -1
  21. package/dist/web/assets/{HtmlEditor-CpqCAPAr.js → HtmlEditor-jCKtKOCT.js} +1 -1
  22. package/dist/web/assets/{MergeView-D93ZHlTG.js → MergeView-eRcs-x1s.js} +2 -2
  23. package/dist/web/assets/{PlaygroundPage-CodSaeWS.js → PlaygroundPage-M7fqYn4Z.js} +1 -1
  24. package/dist/web/assets/SettingsPage-mS3g_vBq.js +1 -0
  25. package/dist/web/assets/{Toolbar-CSKpV4ua.js → Toolbar-F3tR5o7R.js} +1 -1
  26. package/dist/web/assets/{VisitorPickerModal-CqDA1S9F.js → VisitorPickerModal-CPjKg8ox.js} +1 -1
  27. package/dist/web/assets/{check-CN9m0reb.js → check-CQSGOkW1.js} +1 -1
  28. package/dist/web/assets/{copy-DFs3qk19.js → copy-BMAJ--_Y.js} +1 -1
  29. package/dist/web/assets/index-C8iEyMxp.css +1 -0
  30. package/dist/web/assets/{index-CUdIA5aE.js → index-DUu4Is5p.js} +50 -45
  31. package/dist/web/assets/{meta2dEngine-BD2XbzaV-SYn2XtSh.js → meta2dEngine-BD2XbzaV-BAZUiXoN.js} +1 -1
  32. package/dist/web/assets/{plus-QDhBbIRF.js → plus-C3uXIATM.js} +1 -1
  33. package/dist/web/assets/{react-Bf45libg.js → react-BXGUMaBS.js} +3 -3
  34. package/dist/web/index.html +2 -2
  35. package/package.json +1 -1
  36. package/dist/web/assets/SettingsPage-C8doYEbb.js +0 -6
  37. package/dist/web/assets/index-C0ujN3sT.css +0 -1
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/diagram-Bk84WZto.js","assets/ui-CvA4pq3d.js","assets/react-vendor-BuABiQkA.js","assets/motion-DFABYlwt.js"])))=>i.map(i=>d[i]);
2
- import{r as i,j as e,_ as ct,b as dt}from"./react-vendor-BuABiQkA.js";import{o as ae,N as Ke,C as ut,am as Xe,Y as ne,an as qe,ao as mt,q as Fe,ap as Pe,aq as pt,ar as ft,as as ht,at as gt,au as xt,av as yt,aw as Ue,ax as jt,ay as kt,az as Nt}from"./index-CUdIA5aE.js";import{H as bt,S as vt,A as wt,a as Ct}from"./AgentSkillFormCard-BYUjSFe1.js";import{C as Ye}from"./check-CN9m0reb.js";import{C as Ge}from"./copy-DFs3qk19.js";import{P as St}from"./plus-QDhBbIRF.js";import{ae as _t,af as At}from"./ui-CvA4pq3d.js";import"./diagram-Bk84WZto.js";import"./motion-DFABYlwt.js";/**
2
+ import{r as i,j as e,_ as ct,b as dt}from"./react-vendor-BuABiQkA.js";import{o as ae,N as Ke,C as ut,an as Xe,Y as ne,ao as qe,ap as mt,q as Fe,aq as Pe,ar as pt,as as ft,at as ht,au as gt,av as xt,aw as yt,ax as Ue,ay as jt,az as kt,aA as Nt}from"./index-DUu4Is5p.js";import{H as bt,S as vt,A as wt,a as Ct}from"./AgentSkillFormCard-DTgxybJh.js";import{C as Ye}from"./check-CQSGOkW1.js";import{C as Ge}from"./copy-BMAJ--_Y.js";import{P as St}from"./plus-C3uXIATM.js";import{ae as At,af as _t}from"./ui-CvA4pq3d.js";import"./diagram-Bk84WZto.js";import"./motion-DFABYlwt.js";/**
3
3
  * @license lucide-react v0.562.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -19,4 +19,4 @@ import{r as i,j as e,_ as ct,b as dt}from"./react-vendor-BuABiQkA.js";import{o a
19
19
  *
20
20
  * This source code is licensed under the ISC license.
21
21
  * See the LICENSE file in the root directory of this source tree.
22
- */const zt=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Dt=ae("zoom-out",zt);function je(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(je).join(""):typeof s=="object"&&"props"in s?je((n=s.props)==null?void 0:n.children):""}function qt(s){return s?/\blanguage-mermaid\b|\bmermaid\b/i.test(s):!1}function Ft(s){const n=Array.isArray(s)?s:[s];for(const a of n){if(a==null||typeof a!="object"||!("props"in a))continue;const c=a.props;if(!(!c||!qt(c.className)))return je(c.children).replace(/\n$/,"")}return null}const Pt=.4,Lt=4,se=.2;let xe=null;function Bt(){return xe||(xe=ct(()=>import("./diagram-Bk84WZto.js").then(s=>s.z),__vite__mapDeps([0,1,2,3])).then(s=>{const n=s.default;return n.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral",fontFamily:"ui-sans-serif, system-ui, sans-serif"}),n})),xe}const Ot=32,W=new Map;function Le(s){return W.get(s)??null}function Wt(s,n){for(W.has(s)&&W.delete(s),W.set(s,n);W.size>Ot;){const a=W.keys().next().value;if(a==null)break;W.delete(a)}}function ye(s){return Math.min(Lt,Math.max(Pt,s))}function Ht(s){const[n,a]=i.useState(1),[c,b]=i.useState({x:0,y:0}),h=i.useRef(null),[_,y]=i.useState(!1);i.useEffect(()=>{const u=I=>{I.key==="Escape"&&s.onClose()};window.addEventListener("keydown",u);const m=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",u),document.body.style.overflow=m}},[s.onClose]);function A(u){u.button===0&&(u.currentTarget.setPointerCapture(u.pointerId),h.current={pointerId:u.pointerId,startX:u.clientX,startY:u.clientY,originX:c.x,originY:c.y},y(!0))}function C(u){const m=h.current;!m||m.pointerId!==u.pointerId||b({x:m.originX+(u.clientX-m.startX),y:m.originY+(u.clientY-m.startY)})}function E(u){const m=h.current;if(!(!m||m.pointerId!==u.pointerId)){h.current=null,y(!1);try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}}}function N(u){u.preventDefault();const m=u.deltaY>0?-se:se;a(I=>ye(Number((I+m).toFixed(2))))}return dt.createPortal(e.jsxs("div",{className:"mdocs-agent-mermaid-float",role:"dialog","aria-modal":"true","aria-label":"Mermaid 图预览",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-backdrop","aria-label":"关闭预览",onClick:s.onClose}),e.jsxs("div",{className:"mdocs-agent-mermaid-float-chrome",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-float-tools",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>a(u=>ye(Number((u-se).toFixed(2)))),title:"缩小","aria-label":"缩小",children:e.jsx(Dt,{size:16,"aria-hidden":!0})}),e.jsxs("span",{className:"mdocs-agent-mermaid-float-scale",children:[Math.round(n*100),"%"]}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>a(u=>ye(Number((u+se).toFixed(2)))),title:"放大","aria-label":"放大",children:e.jsx(Tt,{size:16,"aria-hidden":!0})}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>{a(1),b({x:0,y:0})},title:"重置",children:"重置"}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:s.onClose,title:"关闭","aria-label":"关闭",children:e.jsx(ne,{size:16,"aria-hidden":!0})})]}),e.jsx("div",{className:_?"mdocs-agent-mermaid-float-stage is-dragging":"mdocs-agent-mermaid-float-stage",onPointerDown:A,onPointerMove:C,onPointerUp:E,onPointerCancel:E,onWheel:N,children:e.jsx("div",{className:"mdocs-agent-mermaid-float-canvas",style:{transform:`translate(calc(-50% + ${c.x}px), calc(-50% + ${c.y}px)) scale(${n})`},dangerouslySetInnerHTML:{__html:s.svg}})}),e.jsx("p",{className:"mdocs-agent-mermaid-float-hint",children:"拖动平移 · 滚轮缩放 · Esc 关闭"})]})]}),document.body)}function Kt(s){const n=i.useId().replace(/:/g,""),[a,c]=i.useState("diagram"),[b,h]=i.useState(()=>Le(s.source.trim())),[_,y]=i.useState(null),[A,C]=i.useState(!1),[E,N]=i.useState(!1),u=i.useRef(null),m=s.source.trim(),I=i.useMemo(()=>m,[m]);i.useEffect(()=>()=>{u.current!=null&&window.clearTimeout(u.current)},[]),i.useEffect(()=>{if(a!=="diagram")return;if(!I){h(null),y(null);return}const j=Le(I);if(j){h(j),y(null);return}let M=!1;const P=window.setTimeout(()=>{(async()=>{try{const F=await Bt();if(M)return;const T=`mdocs-agent-mmd-${n}-${Date.now()}`,{svg:R}=await F.render(T,I);if(M)return;Wt(I,R),h(R),y(null)}catch(F){if(M)return;h(null),y(F instanceof Error?F.message:"Mermaid 渲染失败")}})()},200);return()=>{M=!0,window.clearTimeout(P)}},[a,I,n]);async function H(){!m||!await Xe(m)||(C(!0),u.current!=null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>C(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-mermaid",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toolbar",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toggle",role:"group","aria-label":"Mermaid 显示模式",children:[e.jsxs("button",{type:"button",className:a==="diagram"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("diagram"),"aria-pressed":a==="diagram",title:"图谱",children:[e.jsx(Ke,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"图谱"})]}),e.jsxs("button",{type:"button",className:a==="code"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("code"),"aria-pressed":a==="code",title:"代码",children:[e.jsx(ut,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"代码"})]})]}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy mdocs-agent-mermaid-copy",onClick:()=>void H(),"aria-label":A?"已复制":"复制代码",title:A?"已复制":"复制",children:A?e.jsx(Ye,{size:14,"aria-hidden":!0}):e.jsx(Ge,{size:14,"aria-hidden":!0})})]}),a==="diagram"?e.jsx("div",{className:"mdocs-agent-mermaid-diagram",children:_?e.jsxs("div",{className:"mdocs-agent-mermaid-error",role:"alert",children:[e.jsx("p",{children:"无法渲染该图,可切换到代码查看源码。"}),e.jsx("pre",{children:_})]}):b?e.jsx("div",{className:"mdocs-agent-mermaid-svg mdocs-agent-mermaid-svg-hit",role:"button",tabIndex:0,onClick:()=>N(!0),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),N(!0))},title:"点击放大预览","aria-label":"点击放大预览 Mermaid 图",children:e.jsx("span",{className:"mdocs-agent-mermaid-svg-inner",dangerouslySetInnerHTML:{__html:b}})}):e.jsx("div",{className:"mdocs-agent-mermaid-loading",children:"渲染中…"})}):e.jsx("div",{className:"mdocs-agent-panel-md-pre-wrap mdocs-agent-mermaid-code",children:e.jsx("pre",{children:s.codeChildren??e.jsx("code",{className:"language-mermaid",children:m})})}),E&&b?e.jsx(Ht,{svg:b,onClose:()=>N(!1)}):null]})}const Xt=i.memo(Kt,(s,n)=>s.source===n.source);function ke(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(ke).join(""):typeof s=="object"&&"props"in s?ke((n=s.props)==null?void 0:n.children):""}function Ut(s){const[n,a]=i.useState(!1),c=i.useRef(null),b=i.useRef(null),h=ke(s.children).replace(/\n$/,"");i.useEffect(()=>()=>{c.current!=null&&window.clearTimeout(c.current)},[]);async function _(y){var N,u,m;y.preventDefault(),y.stopPropagation();const C=(((m=(u=(N=b.current)==null?void 0:N.querySelector("pre"))==null?void 0:u.innerText)==null?void 0:m.replace(/\n$/,""))??"")||h;!C||!await Xe(C)||(a(!0),c.current!=null&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>a(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-panel-md-pre-wrap",ref:b,children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy",onClick:y=>void _(y),"aria-label":n?"已复制":"复制代码",title:n?"已复制":"复制",children:n?e.jsx(Ye,{size:14,"aria-hidden":!0}):e.jsx(Ge,{size:14,"aria-hidden":!0})}),e.jsx("pre",{children:s.children})]})}function Yt(s){const n=Ft(s.children);return n!=null?e.jsx(Xt,{source:n,codeChildren:s.children}):e.jsx(Ut,{children:s.children})}const Gt={pre:({children:s})=>e.jsx(Yt,{children:s})},Be=i.memo(function(n){return e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(_t,{remarkPlugins:[At],components:Gt,children:n.children})})}),Vt=["如何发布文档?","草稿是什么?","如何创建工作空间?"];function Oe(s,n){return n.map((a,c)=>{const b=a.skillNames&&a.skillNames.length>0?a.skillNames:a.skillIds&&a.skillIds.length>0?a.skillIds:void 0;return{id:`h-${s}-${c}-${a.role}`,role:a.role,content:a.content,skillNames:b}})}function Jt(s,n){const a=s.slice(),c=a[a.length-1];return(c==null?void 0:c.type)==="text"?a[a.length-1]={type:"text",text:c.text+n}:a.push({type:"text",text:n}),a}function Zt(s,n){const a=s.slice(),c=a[a.length-1];return(c==null?void 0:c.type)==="thinking"?a[a.length-1]={type:"thinking",text:c.text+n}:a.push({type:"thinking",text:n}),a}function We(s){return s!=null&&s.length?s.filter(n=>n.type==="text").map(n=>n.text).join(""):""}function Qt(s){return!!(s!=null&&s.some(n=>n.type==="thinking"&&n.text.length>0))}function es(s){const n=new Date(s);if(Number.isNaN(n.getTime()))return"";const a=new Date;return n.getFullYear()===a.getFullYear()&&n.getMonth()===a.getMonth()&&n.getDate()===a.getDate()?n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):n.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function He(s){if(s>=1e3){const n=s/1e3;return`${n>=10?Math.round(n):Math.round(n*10)/10}K`}return String(s)}function ts(s){const{block:n,onResolved:a}=s,[c,b]=i.useState(""),[h,_]=i.useState(!1),[y,A]=i.useState(1),C=i.useRef(!1),E=i.useRef(a);E.current=a;const N=n.status==="open",u=i.useRef(0);i.useEffect(()=>{if(!N)return;C.current=!1;const j=new Date(n.expiresAt).getTime(),M=Date.now(),P=Math.max(j-M,1);u.current=P,A(1);const F=()=>{const R=j-Date.now(),p=Math.max(0,Math.min(1,R/P));A(p),R<=0&&!C.current&&(C.current=!0,kt(n.requestId).catch(()=>{}).finally(()=>{E.current(n.requestId,"","expired")}))};F();const T=window.setInterval(F,100);return()=>window.clearInterval(T)},[N,n.expiresAt,n.requestId]);async function m(j){const M=j.trim();if(!(!M||h||!N)){_(!0);try{await Nt(n.requestId,M),a(n.requestId,M,"selected")}catch{a(n.requestId,M,"failed")}finally{_(!1)}}}async function I(){if(!(h||!N)){_(!0),C.current=!0;try{await Ue(n.requestId),a(n.requestId,"","cancelled")}catch{a(n.requestId,"","failed")}finally{_(!1)}}}const H=Math.max(0,Math.ceil(y*u.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(N?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:n.title}),N?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[H,"s"]}):null]}),N?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(y*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${y})`}})}):null,n.status==="selected"&&n.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",n.selected]}):null,n.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,n.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,n.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,N?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:n.options.map(j=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:h,onClick:()=>void m(j),children:j},j))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:c,disabled:h,placeholder:"或输入自己的内容…",onChange:j=>b(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),m(c))}}),e.jsx("button",{type:"button",disabled:h||!c.trim(),onClick:()=>void m(c),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:h,onClick:()=>void I(),children:"取消"})})]}):null]})}function ss(s){const b=2*Math.PI*8.75,h=Math.min(100,Math.max(0,s.percent)),_=b*(1-h/100),y=h>=90?"danger":h>=70?"warn":"ok",A=`上下文 ${h}% · 已用 ${He(s.used)} / ${He(s.limit)} tokens`;return e.jsx("span",{className:"mdocs-agent-panel-context mdocs-agent-panel-context-"+y,"data-tooltip":A,"aria-label":A,role:"img",tabIndex:0,children:e.jsxs("svg",{width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,children:[e.jsx("circle",{className:"mdocs-agent-panel-context-track",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5}),e.jsx("circle",{className:"mdocs-agent-panel-context-value",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:b,strokeDashoffset:_,transform:`rotate(-90 ${20/2} ${20/2})`})]})})}function ns(s){var n;for(const a of s)if(!(a.role!=="assistant"||!((n=a.blocks)!=null&&n.length))){for(const c of a.blocks)if((c.type==="choice_card"||c.type==="skill_form_card")&&c.status==="open")return!0}return!1}const ps=i.forwardRef(function(n,a){const{open:c,onClose:b,visitorName:h,anchorStyle:_,fullscreen:y,onToggleFullscreen:A,domainId:C,documentId:E,documentTitle:N,documentPath:u,graphFileId:m,graphLabel:I,onOpenDocument:H,onTreeChanged:j,onDocumentOverwritten:M,onOpenCoding:P}=n,F=((h==null?void 0:h.trim().charAt(0))||"我").toUpperCase(),[T,R]=i.useState(!1),[p,U]=i.useState(null),[Ve,Y]=i.useState(null),[z,w]=i.useState([]),[re,G]=i.useState(null),[Ne,Je]=i.useState([]),[Ze,be]=i.useState(!1),[V,J]=i.useState(""),[X,ve]=i.useState([]),[we,ie]=i.useState(!1),[v,Z]=i.useState(!1),[Ce,L]=i.useState(null),[Q,Se]=i.useState(null),[oe,O]=i.useState(!1),[B,_e]=i.useState(!1),Qe=i.useRef(null),ee=i.useRef(null),D=i.useRef(null),Ae=i.useRef(0),K=i.useRef(!0),[et,le]=i.useState(!1),ce=i.useRef(z);ce.current=z;const Ie=!!(E!=null&&E.trim())&&!we,tt=(N==null?void 0:N.trim())||"当前文档",Me=(u==null?void 0:u.trim())||"",de=!!(m!=null&&m.trim())&&!we,st=(I==null?void 0:I.trim())||"当前图谱";i.useEffect(()=>{ie(!1)},[E,m]);function Ee(t){return Ae.current+=1,`${t}-${Ae.current}`}const Re=120;function $e(t){return t.scrollHeight-t.scrollTop-t.clientHeight}function te(){const t=ee.current;t&&(t.scrollTop=t.scrollHeight,le(!1))}function q(){K.current&&te()}function nt(){const t=ee.current;if(!t)return;const f=$e(t);K.current=f<=48,le(f>Re)}function at(){K.current=!0,te()}i.useLayoutEffect(()=>{q();const t=ee.current;t&&le($e(t)>Re)},[z]);async function rt(){be(!0);try{const t=await ht();Je(t.sessions),re||G(t.lastOpenedSessionId)}catch{}finally{be(!1)}}async function ue(){try{const t=await ft();Se(t)}catch{}}async function Te(){try{const t=await qe();U(t),Y(null)}catch(t){U(null),Y(t instanceof Error?t.message:String(t))}}i.useEffect(()=>{var f;if(!c){R(!1),(f=D.current)==null||f.abort(),D.current=null,Z(!1);return}let t=!1;return(async()=>{try{const o=await qe();t||(U(o),Y(null))}catch(o){t||(U(null),Y(o instanceof Error?o.message:String(o)))}})(),ue(),()=>{t=!0}},[c]),i.useEffect(()=>{if(!c)return;let t=!1;return(async()=>{try{const f=await mt();if(t)return;G(f.sessionId),w(o=>o.length>0?o:Oe(f.sessionId,f.messages))}catch{}})(),()=>{t=!0}},[c]),i.useEffect(()=>{!c||!T||rt()},[c,T]);function me(){if(!B){if(ns(ce.current)){O(!0);return}O(!1),b()}}async function it(){var o;if(B)return;_e(!0);const t=ce.current,f=[];for(const S of t)if(!(S.role!=="assistant"||!S.blocks))for(const g of S.blocks)g.type==="choice_card"&&g.status==="open"&&f.push(Ue(g.requestId).catch(()=>{})),g.type==="skill_form_card"&&g.status==="open"&&f.push(jt(g.requestId).catch(()=>{}));await Promise.all(f),(o=D.current)==null||o.abort(),w(S=>S.map(g=>g.role!=="assistant"||!g.blocks?g:{...g,blocks:g.blocks.map(x=>x.type==="choice_card"&&x.status==="open"?{...x,status:"cancelled"}:x.type==="skill_form_card"&&x.status==="open"?{...x,status:"cancelled"}:x)})),O(!1),_e(!1),b()}const pe=i.useRef(me);pe.current=me,i.useImperativeHandle(a,()=>({requestClose:()=>pe.current()}),[]),i.useEffect(()=>{if(!c){O(!1);return}const t=f=>{if(f.key==="Escape"){if(oe){B||O(!1);return}if(T){R(!1);return}pe.current()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[c,T,oe,B]);async function fe(t){var x;const f=t.trim();if(!f||v)return;if(!(p!=null&&p.enabled)){L((p==null?void 0:p.reason)==="missing_api_key"?"请先配置 API Key":(p==null?void 0:p.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(x=D.current)==null||x.abort();const o=new AbortController;D.current=o;const S={id:Ee("u"),role:"user",content:f,skillNames:X.length>0?[...X]:void 0},g=Ee("a");K.current=!0,w($=>[...$,S,{id:g,role:"assistant",content:""}]),J(""),Z(!0),L(null),R(!1),requestAnimationFrame(()=>{te(),requestAnimationFrame(te)});try{let $=!1;await yt(f,{skillNames:X.length>0?X:void 0,references:{domainId:(C==null?void 0:C.trim())||void 0,documentId:!de&&Ie?E.trim():void 0,graphFileId:de?m.trim():void 0},signal:o.signal,onEvent:l=>{l.type==="text_delta"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=Jt(r.blocks??[],l.text);return{...r,blocks:d,content:We(d)}})),requestAnimationFrame(()=>q())):l.type==="thinking_delta"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=Zt(r.blocks??[],l.text);return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="sources"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=(r.blocks??[]).slice(),ge=d[d.length-1];return(ge==null?void 0:ge.type)==="sources"?d[d.length-1]={type:"sources",items:l.items}:d.push({type:"sources",items:l.items}),{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="document_table"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"document_table",title:l.title,rows:l.rows}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="document_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"document_card",documentId:l.documentId,title:l.title,path:l.path,preview:l.preview}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="tool_notice"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"tool_notice",toolName:l.toolName,text:l.text}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="choice_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"choice_card",requestId:l.requestId,title:l.title,options:l.options,expiresAt:l.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="choice_expired"?w(k=>k.map(r=>r.id!==g||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===l.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):l.type==="skill_form_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"skill_form_card",requestId:l.requestId,mode:l.mode,title:l.title,currentName:l.currentName,initialName:l.initialName,initialDescription:l.initialDescription,initialBody:l.initialBody,expiresAt:l.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="skill_form_expired"?w(k=>k.map(r=>r.id!==g||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===l.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):l.type==="tree_changed"?j==null||j():l.type==="document_overwritten"?M==null||M({documentId:l.documentId,headCommitId:l.headCommitId}):l.type==="open_coding"?P==null||P({documentId:l.documentId,displayName:l.displayName}):l.type==="context_usage"?Se({percent:l.percent,used:l.used,limit:l.limit}):l.type==="error"&&($=!0,L(l.message))}}),!o.signal.aborted&&!$&&ve([])}catch($){if(o.signal.aborted)return;L($ instanceof Error?$.message:String($))}finally{D.current===o&&(D.current=null),Z(!1)}}async function ot(){var t;if(!v){(t=D.current)==null||t.abort(),L(null),R(!1),Z(!1);try{const f=await gt();G(f.sessionId),w([]),J(""),K.current=!0,ue()}catch(f){L(f instanceof Error?f.message:String(f))}}}async function lt(t){var f;if(!v){if(t===re){R(!1);return}(f=D.current)==null||f.abort(),L(null);try{const o=await xt(t);G(o.sessionId),w(Oe(o.sessionId,o.messages)),J(""),R(!1),K.current=!0,requestAnimationFrame(()=>q()),ue()}catch(o){L(o instanceof Error?o.message:String(o))}}}function ze(t){!t||!H||H(t)}if(!c)return null;const he=(p==null?void 0:p.reason)==="missing_api_key",De=Ve??(p&&!p.enabled&&!he?p.reason==="skills_missing"?"skills 未就绪":"助手暂不可用":null);return e.jsxs("div",{ref:Qe,className:"mdocs-agent-panel"+(y?" mdocs-agent-panel--fullscreen":""),role:"dialog","aria-label":"mdocs 智能助手","aria-modal":y?!0:void 0,style:y?void 0:_,children:[e.jsxs("header",{className:"mdocs-agent-panel-header",children:[e.jsxs("div",{className:"mdocs-agent-panel-title",children:[e.jsx("img",{src:Fe,alt:"",className:"mdocs-agent-panel-title-logo"}),e.jsx("span",{children:"mdocs 智能助手"})]}),e.jsxs("div",{className:"mdocs-agent-panel-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:v,onClick:()=>void ot(),children:e.jsx(St,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(T?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>R(t=>!t),children:e.jsx(bt,{size:16,strokeWidth:1.8})}),A?e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:y?"退出全屏":"全屏","aria-label":y?"退出全屏":"全屏",onClick:A,children:y?e.jsx(Rt,{size:16,strokeWidth:1.8}):e.jsx(Mt,{size:16,strokeWidth:1.8})}):null,e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"关闭","aria-label":"关闭",onClick:me,children:e.jsx(ne,{size:16,strokeWidth:1.8})})]})]}),T?e.jsxs("div",{className:"mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>R(!1),children:"返回对话"})]}),Ze?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):Ne.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):e.jsx("ul",{className:"mdocs-agent-panel-history-list",children:Ne.map(t=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(t.id===re?" active":""),disabled:v,onClick:()=>void lt(t.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:t.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:es(t.updatedAt)})]})},t.id))})]}):e.jsxs("div",{className:"mdocs-agent-panel-body",children:[e.jsxs("div",{className:"mdocs-agent-panel-scroll-wrap",children:[e.jsx("div",{className:"mdocs-agent-panel-welcome",ref:ee,onScroll:nt,children:z.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-hello",children:"你好,我是 mdocs 智能助手"}),e.jsx("p",{className:"mdocs-agent-panel-desc",children:"我能答疑、搜文档、整理结构,也能帮你写全文;需要精细改稿请点文档顶栏「帮写」。"}),he?e.jsx(Pe,{onConfigured:Te}):De?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:De}):e.jsx("div",{className:"mdocs-agent-panel-chips",children:Vt.map(t=>e.jsx("button",{type:"button",className:"mdocs-agent-panel-chip",onClick:()=>void fe(t),disabled:v||!(p!=null&&p.enabled),children:t},t))})]}):e.jsx("div",{className:"mdocs-agent-panel-messages",children:z.map(t=>{var f;return e.jsxs("div",{className:"mdocs-agent-panel-msg"+(t.role==="user"?" mdocs-agent-panel-msg-user":" mdocs-agent-panel-msg-assistant"),children:[t.role==="assistant"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-ai","aria-hidden":!0,children:e.jsx("img",{src:Fe,alt:""})}):null,e.jsxs("div",{className:"mdocs-agent-panel-msg-bubble",children:[t.role==="user"&&t.skillNames&&t.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",t.skillNames.length]}):null,t.role==="assistant"?t.blocks&&t.blocks.length>0?e.jsxs("div",{className:"mdocs-agent-panel-timeline",children:[t.blocks.map((o,S)=>{var g;return o.type==="thinking"?o.text?e.jsxs("details",{className:"mdocs-agent-panel-think-fold",open:v&&t.id===((g=z[z.length-1])==null?void 0:g.id),children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:o.text})]},`${t.id}-th-${S}`):null:o.type==="text"?o.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Be,{children:o.text})},`${t.id}-t-${S}`):null:o.type==="sources"?o.items.length===0?null:e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:["已阅读 ",o.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:o.items.map(x=>e.jsx("li",{children:e.jsx("a",{href:x.url,target:"_blank",rel:"noreferrer",children:x.name})},x.id))})]})},`${t.id}-s-${S}`):o.type==="tool_notice"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:o.text})},`${t.id}-n-${S}`):o.type==="choice_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(ts,{block:o,onResolved:(x,$,l)=>{w(k=>k.map(r=>r.id!==t.id||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===x?{...d,status:l,selected:l==="selected"?$:d.selected}:d)}))}})},`${t.id}-ch-${S}`):o.type==="skill_form_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(vt,{block:o,onResolved:(x,$,l)=>{w(k=>k.map(r=>r.id!==t.id||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===x?{...d,status:$,submittedName:$==="submitted"?l:d.submittedName}:d)}))}})},`${t.id}-sf-${S}`):o.type==="document_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:x=>{x.preventDefault(),x.stopPropagation(),ze(o.documentId)},children:["《",o.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"文档预览"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[o.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:o.path}):null,o.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:o.preview}):e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview muted",children:"(无正文预览)"})]})]})},`${t.id}-c-${S}`):e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[o.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:o.rows.length===0?"无结果":`${o.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:o.rows.length===0?e.jsx("p",{className:"mdocs-agent-panel-doc-table-empty",children:"无结果"}):e.jsxs("table",{className:"mdocs-agent-panel-doc-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"文章名字"}),e.jsx("th",{children:"文章内容"})]})}),e.jsx("tbody",{children:o.rows.map(x=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>ze(x.documentId),children:x.title})}),e.jsx("td",{children:x.summary||"-"})]},x.documentId))})]})})]})},`${t.id}-d-${S}`)}),v&&t.id===((f=z[z.length-1])==null?void 0:f.id)&&!We(t.blocks)&&!Qt(t.blocks)?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null]}):t.content?e.jsx(Be,{children:t.content}):v?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null:t.content]}),t.role==="user"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-user","aria-hidden":!0,children:F}):null]},t.id)})})}),et?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:at,title:"回到底部","aria-label":"回到底部",children:[e.jsx(wt,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),Ce?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Ce}):null,he&&z.length>0?e.jsx(Pe,{onConfigured:Te}):null,e.jsx(Ct,{selectedNames:X,onChange:ve,disabled:v||!(p!=null&&p.enabled)}),e.jsxs("div",{className:"mdocs-agent-panel-input-wrap",children:[de?e.jsxs("div",{className:"mdocs-agent-doc-ref mdocs-agent-graph-ref",children:[e.jsx(Ke,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:st}),e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:"图谱(只读)"})]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前图谱",disabled:v,onClick:()=>ie(!0),children:e.jsx(ne,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):Ie?e.jsxs("div",{className:"mdocs-agent-doc-ref",children:[e.jsx(pt,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:tt}),Me?e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:Me}):null]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前文档",disabled:v,onClick:()=>ie(!0),children:e.jsx(ne,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):null,e.jsxs("div",{className:"mdocs-agent-panel-input-body",children:[e.jsx("textarea",{className:"mdocs-agent-panel-input",rows:2,placeholder:p!=null&&p.enabled?"把你的问题告诉我…":"请先配置 API Key",value:V,disabled:v||!(p!=null&&p.enabled),onChange:t=>J(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),fe(V))}}),Q?e.jsx(ss,{percent:Q.percent,used:Q.used,limit:Q.limit}):null,e.jsx("button",{type:"button",className:v?"mdocs-agent-panel-send mdocs-agent-panel-send-stop":"mdocs-agent-panel-send",disabled:v?!1:!(p!=null&&p.enabled)||!V.trim(),onClick:()=>{var t;if(v){(t=D.current)==null||t.abort();return}fe(V)},title:v?"停止":"发送","aria-label":v?"停止":"发送",children:v?"■":"↑"})]})]}),e.jsx("p",{className:"mdocs-agent-panel-footnote",children:"内容由 AI 生成,仅供参考"})]}),oe?e.jsx("div",{className:"mdocs-agent-close-confirm-backdrop",role:"presentation",onClick:()=>{B||O(!1)},children:e.jsxs("div",{className:"mdocs-message-dialog mdocs-agent-close-confirm",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-agent-close-confirm-title",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{id:"mdocs-agent-close-confirm-title",className:"mdocs-message-dialog-title",children:"有待处理的倒计时"}),e.jsx("p",{className:"mdocs-message-dialog-body",children:"当前还有选择卡或 Skill 表单在倒计时。强制关闭会取消这些操作并退出助手;也可以继续等待完成后再关。"}),e.jsxs("div",{className:"mdocs-message-dialog-actions mdocs-agent-close-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",disabled:B,onClick:()=>O(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:B,onClick:()=>void it(),children:B?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{ps as AgentChatPanel};
22
+ */const zt=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Dt=ae("zoom-out",zt);function je(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(je).join(""):typeof s=="object"&&"props"in s?je((n=s.props)==null?void 0:n.children):""}function qt(s){return s?/\blanguage-mermaid\b|\bmermaid\b/i.test(s):!1}function Ft(s){const n=Array.isArray(s)?s:[s];for(const a of n){if(a==null||typeof a!="object"||!("props"in a))continue;const c=a.props;if(!(!c||!qt(c.className)))return je(c.children).replace(/\n$/,"")}return null}const Pt=.4,Lt=4,se=.2;let xe=null;function Bt(){return xe||(xe=ct(()=>import("./diagram-Bk84WZto.js").then(s=>s.z),__vite__mapDeps([0,1,2,3])).then(s=>{const n=s.default;return n.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral",fontFamily:"ui-sans-serif, system-ui, sans-serif"}),n})),xe}const Ot=32,W=new Map;function Le(s){return W.get(s)??null}function Wt(s,n){for(W.has(s)&&W.delete(s),W.set(s,n);W.size>Ot;){const a=W.keys().next().value;if(a==null)break;W.delete(a)}}function ye(s){return Math.min(Lt,Math.max(Pt,s))}function Ht(s){const[n,a]=i.useState(1),[c,b]=i.useState({x:0,y:0}),h=i.useRef(null),[A,y]=i.useState(!1);i.useEffect(()=>{const u=I=>{I.key==="Escape"&&s.onClose()};window.addEventListener("keydown",u);const m=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",u),document.body.style.overflow=m}},[s.onClose]);function _(u){u.button===0&&(u.currentTarget.setPointerCapture(u.pointerId),h.current={pointerId:u.pointerId,startX:u.clientX,startY:u.clientY,originX:c.x,originY:c.y},y(!0))}function C(u){const m=h.current;!m||m.pointerId!==u.pointerId||b({x:m.originX+(u.clientX-m.startX),y:m.originY+(u.clientY-m.startY)})}function E(u){const m=h.current;if(!(!m||m.pointerId!==u.pointerId)){h.current=null,y(!1);try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}}}function N(u){u.preventDefault();const m=u.deltaY>0?-se:se;a(I=>ye(Number((I+m).toFixed(2))))}return dt.createPortal(e.jsxs("div",{className:"mdocs-agent-mermaid-float",role:"dialog","aria-modal":"true","aria-label":"Mermaid 图预览",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-backdrop","aria-label":"关闭预览",onClick:s.onClose}),e.jsxs("div",{className:"mdocs-agent-mermaid-float-chrome",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-float-tools",children:[e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>a(u=>ye(Number((u-se).toFixed(2)))),title:"缩小","aria-label":"缩小",children:e.jsx(Dt,{size:16,"aria-hidden":!0})}),e.jsxs("span",{className:"mdocs-agent-mermaid-float-scale",children:[Math.round(n*100),"%"]}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>a(u=>ye(Number((u+se).toFixed(2)))),title:"放大","aria-label":"放大",children:e.jsx(Tt,{size:16,"aria-hidden":!0})}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:()=>{a(1),b({x:0,y:0})},title:"重置",children:"重置"}),e.jsx("button",{type:"button",className:"mdocs-agent-mermaid-float-btn",onClick:s.onClose,title:"关闭","aria-label":"关闭",children:e.jsx(ne,{size:16,"aria-hidden":!0})})]}),e.jsx("div",{className:A?"mdocs-agent-mermaid-float-stage is-dragging":"mdocs-agent-mermaid-float-stage",onPointerDown:_,onPointerMove:C,onPointerUp:E,onPointerCancel:E,onWheel:N,children:e.jsx("div",{className:"mdocs-agent-mermaid-float-canvas",style:{transform:`translate(calc(-50% + ${c.x}px), calc(-50% + ${c.y}px)) scale(${n})`},dangerouslySetInnerHTML:{__html:s.svg}})}),e.jsx("p",{className:"mdocs-agent-mermaid-float-hint",children:"拖动平移 · 滚轮缩放 · Esc 关闭"})]})]}),document.body)}function Kt(s){const n=i.useId().replace(/:/g,""),[a,c]=i.useState("diagram"),[b,h]=i.useState(()=>Le(s.source.trim())),[A,y]=i.useState(null),[_,C]=i.useState(!1),[E,N]=i.useState(!1),u=i.useRef(null),m=s.source.trim(),I=i.useMemo(()=>m,[m]);i.useEffect(()=>()=>{u.current!=null&&window.clearTimeout(u.current)},[]),i.useEffect(()=>{if(a!=="diagram")return;if(!I){h(null),y(null);return}const j=Le(I);if(j){h(j),y(null);return}let M=!1;const P=window.setTimeout(()=>{(async()=>{try{const F=await Bt();if(M)return;const T=`mdocs-agent-mmd-${n}-${Date.now()}`,{svg:R}=await F.render(T,I);if(M)return;Wt(I,R),h(R),y(null)}catch(F){if(M)return;h(null),y(F instanceof Error?F.message:"Mermaid 渲染失败")}})()},200);return()=>{M=!0,window.clearTimeout(P)}},[a,I,n]);async function H(){!m||!await Xe(m)||(C(!0),u.current!=null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>C(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-mermaid",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toolbar",children:[e.jsxs("div",{className:"mdocs-agent-mermaid-toggle",role:"group","aria-label":"Mermaid 显示模式",children:[e.jsxs("button",{type:"button",className:a==="diagram"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("diagram"),"aria-pressed":a==="diagram",title:"图谱",children:[e.jsx(Ke,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"图谱"})]}),e.jsxs("button",{type:"button",className:a==="code"?"mdocs-agent-mermaid-toggle-btn is-active":"mdocs-agent-mermaid-toggle-btn",onClick:()=>c("code"),"aria-pressed":a==="code",title:"代码",children:[e.jsx(ut,{size:14,"aria-hidden":!0}),e.jsx("span",{children:"代码"})]})]}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy mdocs-agent-mermaid-copy",onClick:()=>void H(),"aria-label":_?"已复制":"复制代码",title:_?"已复制":"复制",children:_?e.jsx(Ye,{size:14,"aria-hidden":!0}):e.jsx(Ge,{size:14,"aria-hidden":!0})})]}),a==="diagram"?e.jsx("div",{className:"mdocs-agent-mermaid-diagram",children:A?e.jsxs("div",{className:"mdocs-agent-mermaid-error",role:"alert",children:[e.jsx("p",{children:"无法渲染该图,可切换到代码查看源码。"}),e.jsx("pre",{children:A})]}):b?e.jsx("div",{className:"mdocs-agent-mermaid-svg mdocs-agent-mermaid-svg-hit",role:"button",tabIndex:0,onClick:()=>N(!0),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),N(!0))},title:"点击放大预览","aria-label":"点击放大预览 Mermaid 图",children:e.jsx("span",{className:"mdocs-agent-mermaid-svg-inner",dangerouslySetInnerHTML:{__html:b}})}):e.jsx("div",{className:"mdocs-agent-mermaid-loading",children:"渲染中…"})}):e.jsx("div",{className:"mdocs-agent-panel-md-pre-wrap mdocs-agent-mermaid-code",children:e.jsx("pre",{children:s.codeChildren??e.jsx("code",{className:"language-mermaid",children:m})})}),E&&b?e.jsx(Ht,{svg:b,onClose:()=>N(!1)}):null]})}const Xt=i.memo(Kt,(s,n)=>s.source===n.source);function ke(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(ke).join(""):typeof s=="object"&&"props"in s?ke((n=s.props)==null?void 0:n.children):""}function Ut(s){const[n,a]=i.useState(!1),c=i.useRef(null),b=i.useRef(null),h=ke(s.children).replace(/\n$/,"");i.useEffect(()=>()=>{c.current!=null&&window.clearTimeout(c.current)},[]);async function A(y){var N,u,m;y.preventDefault(),y.stopPropagation();const C=(((m=(u=(N=b.current)==null?void 0:N.querySelector("pre"))==null?void 0:u.innerText)==null?void 0:m.replace(/\n$/,""))??"")||h;!C||!await Xe(C)||(a(!0),c.current!=null&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>a(!1),1500))}return e.jsxs("div",{className:"mdocs-agent-panel-md-pre-wrap",ref:b,children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-md-copy",onClick:y=>void A(y),"aria-label":n?"已复制":"复制代码",title:n?"已复制":"复制",children:n?e.jsx(Ye,{size:14,"aria-hidden":!0}):e.jsx(Ge,{size:14,"aria-hidden":!0})}),e.jsx("pre",{children:s.children})]})}function Yt(s){const n=Ft(s.children);return n!=null?e.jsx(Xt,{source:n,codeChildren:s.children}):e.jsx(Ut,{children:s.children})}const Gt={pre:({children:s})=>e.jsx(Yt,{children:s})},Be=i.memo(function(n){return e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(At,{remarkPlugins:[_t],components:Gt,children:n.children})})}),Vt=["如何发布文档?","草稿是什么?","如何创建工作空间?"];function Oe(s,n){return n.map((a,c)=>{const b=a.skillNames&&a.skillNames.length>0?a.skillNames:a.skillIds&&a.skillIds.length>0?a.skillIds:void 0;return{id:`h-${s}-${c}-${a.role}`,role:a.role,content:a.content,skillNames:b}})}function Jt(s,n){const a=s.slice(),c=a[a.length-1];return(c==null?void 0:c.type)==="text"?a[a.length-1]={type:"text",text:c.text+n}:a.push({type:"text",text:n}),a}function Zt(s,n){const a=s.slice(),c=a[a.length-1];return(c==null?void 0:c.type)==="thinking"?a[a.length-1]={type:"thinking",text:c.text+n}:a.push({type:"thinking",text:n}),a}function We(s){return s!=null&&s.length?s.filter(n=>n.type==="text").map(n=>n.text).join(""):""}function Qt(s){return!!(s!=null&&s.some(n=>n.type==="thinking"&&n.text.length>0))}function es(s){const n=new Date(s);if(Number.isNaN(n.getTime()))return"";const a=new Date;return n.getFullYear()===a.getFullYear()&&n.getMonth()===a.getMonth()&&n.getDate()===a.getDate()?n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):n.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function He(s){if(s>=1e3){const n=s/1e3;return`${n>=10?Math.round(n):Math.round(n*10)/10}K`}return String(s)}function ts(s){const{block:n,onResolved:a}=s,[c,b]=i.useState(""),[h,A]=i.useState(!1),[y,_]=i.useState(1),C=i.useRef(!1),E=i.useRef(a);E.current=a;const N=n.status==="open",u=i.useRef(0);i.useEffect(()=>{if(!N)return;C.current=!1;const j=new Date(n.expiresAt).getTime(),M=Date.now(),P=Math.max(j-M,1);u.current=P,_(1);const F=()=>{const R=j-Date.now(),p=Math.max(0,Math.min(1,R/P));_(p),R<=0&&!C.current&&(C.current=!0,kt(n.requestId).catch(()=>{}).finally(()=>{E.current(n.requestId,"","expired")}))};F();const T=window.setInterval(F,100);return()=>window.clearInterval(T)},[N,n.expiresAt,n.requestId]);async function m(j){const M=j.trim();if(!(!M||h||!N)){A(!0);try{await Nt(n.requestId,M),a(n.requestId,M,"selected")}catch{a(n.requestId,M,"failed")}finally{A(!1)}}}async function I(){if(!(h||!N)){A(!0),C.current=!0;try{await Ue(n.requestId),a(n.requestId,"","cancelled")}catch{a(n.requestId,"","failed")}finally{A(!1)}}}const H=Math.max(0,Math.ceil(y*u.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(N?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:n.title}),N?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[H,"s"]}):null]}),N?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(y*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${y})`}})}):null,n.status==="selected"&&n.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",n.selected]}):null,n.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,n.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,n.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,N?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:n.options.map(j=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:h,onClick:()=>void m(j),children:j},j))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:c,disabled:h,placeholder:"或输入自己的内容…",onChange:j=>b(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),m(c))}}),e.jsx("button",{type:"button",disabled:h||!c.trim(),onClick:()=>void m(c),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:h,onClick:()=>void I(),children:"取消"})})]}):null]})}function ss(s){const b=2*Math.PI*8.75,h=Math.min(100,Math.max(0,s.percent)),A=b*(1-h/100),y=h>=90?"danger":h>=70?"warn":"ok",_=`上下文 ${h}% · 已用 ${He(s.used)} / ${He(s.limit)} tokens`;return e.jsx("span",{className:"mdocs-agent-panel-context mdocs-agent-panel-context-"+y,"data-tooltip":_,"aria-label":_,role:"img",tabIndex:0,children:e.jsxs("svg",{width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,children:[e.jsx("circle",{className:"mdocs-agent-panel-context-track",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5}),e.jsx("circle",{className:"mdocs-agent-panel-context-value",cx:20/2,cy:20/2,r:8.75,fill:"none",strokeWidth:2.5,strokeLinecap:"round",strokeDasharray:b,strokeDashoffset:A,transform:`rotate(-90 ${20/2} ${20/2})`})]})})}function ns(s){var n;for(const a of s)if(!(a.role!=="assistant"||!((n=a.blocks)!=null&&n.length))){for(const c of a.blocks)if((c.type==="choice_card"||c.type==="skill_form_card")&&c.status==="open")return!0}return!1}const ps=i.forwardRef(function(n,a){const{open:c,onClose:b,visitorName:h,anchorStyle:A,fullscreen:y,onToggleFullscreen:_,domainId:C,documentId:E,documentTitle:N,documentPath:u,graphFileId:m,graphLabel:I,onOpenDocument:H,onTreeChanged:j,onDocumentOverwritten:M,onOpenCoding:P}=n,F=((h==null?void 0:h.trim().charAt(0))||"我").toUpperCase(),[T,R]=i.useState(!1),[p,U]=i.useState(null),[Ve,Y]=i.useState(null),[z,w]=i.useState([]),[re,G]=i.useState(null),[Ne,Je]=i.useState([]),[Ze,be]=i.useState(!1),[V,J]=i.useState(""),[X,ve]=i.useState([]),[we,ie]=i.useState(!1),[v,Z]=i.useState(!1),[Ce,L]=i.useState(null),[Q,Se]=i.useState(null),[oe,O]=i.useState(!1),[B,Ae]=i.useState(!1),Qe=i.useRef(null),ee=i.useRef(null),D=i.useRef(null),_e=i.useRef(0),K=i.useRef(!0),[et,le]=i.useState(!1),ce=i.useRef(z);ce.current=z;const Ie=!!(E!=null&&E.trim())&&!we,tt=(N==null?void 0:N.trim())||"当前文档",Me=(u==null?void 0:u.trim())||"",de=!!(m!=null&&m.trim())&&!we,st=(I==null?void 0:I.trim())||"当前图谱";i.useEffect(()=>{ie(!1)},[E,m]);function Ee(t){return _e.current+=1,`${t}-${_e.current}`}const Re=120;function $e(t){return t.scrollHeight-t.scrollTop-t.clientHeight}function te(){const t=ee.current;t&&(t.scrollTop=t.scrollHeight,le(!1))}function q(){K.current&&te()}function nt(){const t=ee.current;if(!t)return;const f=$e(t);K.current=f<=48,le(f>Re)}function at(){K.current=!0,te()}i.useLayoutEffect(()=>{q();const t=ee.current;t&&le($e(t)>Re)},[z]);async function rt(){be(!0);try{const t=await ht();Je(t.sessions),re||G(t.lastOpenedSessionId)}catch{}finally{be(!1)}}async function ue(){try{const t=await ft();Se(t)}catch{}}async function Te(){try{const t=await qe();U(t),Y(null)}catch(t){U(null),Y(t instanceof Error?t.message:String(t))}}i.useEffect(()=>{var f;if(!c){R(!1),(f=D.current)==null||f.abort(),D.current=null,Z(!1);return}let t=!1;return(async()=>{try{const o=await qe();t||(U(o),Y(null))}catch(o){t||(U(null),Y(o instanceof Error?o.message:String(o)))}})(),ue(),()=>{t=!0}},[c]),i.useEffect(()=>{if(!c)return;let t=!1;return(async()=>{try{const f=await mt();if(t)return;G(f.sessionId),w(o=>o.length>0?o:Oe(f.sessionId,f.messages))}catch{}})(),()=>{t=!0}},[c]),i.useEffect(()=>{!c||!T||rt()},[c,T]);function me(){if(!B){if(ns(ce.current)){O(!0);return}O(!1),b()}}async function it(){var o;if(B)return;Ae(!0);const t=ce.current,f=[];for(const S of t)if(!(S.role!=="assistant"||!S.blocks))for(const g of S.blocks)g.type==="choice_card"&&g.status==="open"&&f.push(Ue(g.requestId).catch(()=>{})),g.type==="skill_form_card"&&g.status==="open"&&f.push(jt(g.requestId).catch(()=>{}));await Promise.all(f),(o=D.current)==null||o.abort(),w(S=>S.map(g=>g.role!=="assistant"||!g.blocks?g:{...g,blocks:g.blocks.map(x=>x.type==="choice_card"&&x.status==="open"?{...x,status:"cancelled"}:x.type==="skill_form_card"&&x.status==="open"?{...x,status:"cancelled"}:x)})),O(!1),Ae(!1),b()}const pe=i.useRef(me);pe.current=me,i.useImperativeHandle(a,()=>({requestClose:()=>pe.current()}),[]),i.useEffect(()=>{if(!c){O(!1);return}const t=f=>{if(f.key==="Escape"){if(oe){B||O(!1);return}if(T){R(!1);return}pe.current()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[c,T,oe,B]);async function fe(t){var x;const f=t.trim();if(!f||v)return;if(!(p!=null&&p.enabled)){L((p==null?void 0:p.reason)==="missing_api_key"?"请先配置 API Key":(p==null?void 0:p.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(x=D.current)==null||x.abort();const o=new AbortController;D.current=o;const S={id:Ee("u"),role:"user",content:f,skillNames:X.length>0?[...X]:void 0},g=Ee("a");K.current=!0,w($=>[...$,S,{id:g,role:"assistant",content:""}]),J(""),Z(!0),L(null),R(!1),requestAnimationFrame(()=>{te(),requestAnimationFrame(te)});try{let $=!1;await yt(f,{skillNames:X.length>0?X:void 0,references:{domainId:(C==null?void 0:C.trim())||void 0,documentId:!de&&Ie?E.trim():void 0,graphFileId:de?m.trim():void 0},signal:o.signal,onEvent:l=>{l.type==="text_delta"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=Jt(r.blocks??[],l.text);return{...r,blocks:d,content:We(d)}})),requestAnimationFrame(()=>q())):l.type==="thinking_delta"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=Zt(r.blocks??[],l.text);return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="sources"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=(r.blocks??[]).slice(),ge=d[d.length-1];return(ge==null?void 0:ge.type)==="sources"?d[d.length-1]={type:"sources",items:l.items}:d.push({type:"sources",items:l.items}),{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="document_table"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"document_table",title:l.title,rows:l.rows}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="document_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"document_card",documentId:l.documentId,title:l.title,path:l.path,preview:l.preview}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="tool_notice"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"tool_notice",toolName:l.toolName,text:l.text}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="choice_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"choice_card",requestId:l.requestId,title:l.title,options:l.options,expiresAt:l.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="choice_expired"?w(k=>k.map(r=>r.id!==g||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===l.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):l.type==="skill_form_card"?(w(k=>k.map(r=>{if(r.id!==g)return r;const d=[...r.blocks??[],{type:"skill_form_card",requestId:l.requestId,mode:l.mode,title:l.title,currentName:l.currentName,initialName:l.initialName,initialDescription:l.initialDescription,initialBody:l.initialBody,expiresAt:l.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):l.type==="skill_form_expired"?w(k=>k.map(r=>r.id!==g||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===l.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):l.type==="tree_changed"?j==null||j():l.type==="document_overwritten"?M==null||M({documentId:l.documentId,headCommitId:l.headCommitId}):l.type==="open_coding"?P==null||P({documentId:l.documentId,displayName:l.displayName}):l.type==="context_usage"?Se({percent:l.percent,used:l.used,limit:l.limit}):l.type==="error"&&($=!0,L(l.message))}}),!o.signal.aborted&&!$&&ve([])}catch($){if(o.signal.aborted)return;L($ instanceof Error?$.message:String($))}finally{D.current===o&&(D.current=null),Z(!1)}}async function ot(){var t;if(!v){(t=D.current)==null||t.abort(),L(null),R(!1),Z(!1);try{const f=await gt();G(f.sessionId),w([]),J(""),K.current=!0,ue()}catch(f){L(f instanceof Error?f.message:String(f))}}}async function lt(t){var f;if(!v){if(t===re){R(!1);return}(f=D.current)==null||f.abort(),L(null);try{const o=await xt(t);G(o.sessionId),w(Oe(o.sessionId,o.messages)),J(""),R(!1),K.current=!0,requestAnimationFrame(()=>q()),ue()}catch(o){L(o instanceof Error?o.message:String(o))}}}function ze(t){!t||!H||H(t)}if(!c)return null;const he=(p==null?void 0:p.reason)==="missing_api_key",De=Ve??(p&&!p.enabled&&!he?p.reason==="skills_missing"?"skills 未就绪":"助手暂不可用":null);return e.jsxs("div",{ref:Qe,className:"mdocs-agent-panel"+(y?" mdocs-agent-panel--fullscreen":""),role:"dialog","aria-label":"mdocs 智能助手","aria-modal":y?!0:void 0,style:y?void 0:A,children:[e.jsxs("header",{className:"mdocs-agent-panel-header",children:[e.jsxs("div",{className:"mdocs-agent-panel-title",children:[e.jsx("img",{src:Fe,alt:"",className:"mdocs-agent-panel-title-logo"}),e.jsx("span",{children:"mdocs 智能助手"})]}),e.jsxs("div",{className:"mdocs-agent-panel-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:v,onClick:()=>void ot(),children:e.jsx(St,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(T?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>R(t=>!t),children:e.jsx(bt,{size:16,strokeWidth:1.8})}),_?e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:y?"退出全屏":"全屏","aria-label":y?"退出全屏":"全屏",onClick:_,children:y?e.jsx(Rt,{size:16,strokeWidth:1.8}):e.jsx(Mt,{size:16,strokeWidth:1.8})}):null,e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"关闭","aria-label":"关闭",onClick:me,children:e.jsx(ne,{size:16,strokeWidth:1.8})})]})]}),T?e.jsxs("div",{className:"mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>R(!1),children:"返回对话"})]}),Ze?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):Ne.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):e.jsx("ul",{className:"mdocs-agent-panel-history-list",children:Ne.map(t=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(t.id===re?" active":""),disabled:v,onClick:()=>void lt(t.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:t.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:es(t.updatedAt)})]})},t.id))})]}):e.jsxs("div",{className:"mdocs-agent-panel-body",children:[e.jsxs("div",{className:"mdocs-agent-panel-scroll-wrap",children:[e.jsx("div",{className:"mdocs-agent-panel-welcome",ref:ee,onScroll:nt,children:z.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-hello",children:"你好,我是 mdocs 智能助手"}),e.jsx("p",{className:"mdocs-agent-panel-desc",children:"我能答疑、搜文档、整理结构,也能帮你写全文;需要精细改稿请点文档顶栏「帮写」。"}),he?e.jsx(Pe,{onConfigured:Te}):De?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:De}):e.jsx("div",{className:"mdocs-agent-panel-chips",children:Vt.map(t=>e.jsx("button",{type:"button",className:"mdocs-agent-panel-chip",onClick:()=>void fe(t),disabled:v||!(p!=null&&p.enabled),children:t},t))})]}):e.jsx("div",{className:"mdocs-agent-panel-messages",children:z.map(t=>{var f;return e.jsxs("div",{className:"mdocs-agent-panel-msg"+(t.role==="user"?" mdocs-agent-panel-msg-user":" mdocs-agent-panel-msg-assistant"),children:[t.role==="assistant"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-ai","aria-hidden":!0,children:e.jsx("img",{src:Fe,alt:""})}):null,e.jsxs("div",{className:"mdocs-agent-panel-msg-bubble",children:[t.role==="user"&&t.skillNames&&t.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",t.skillNames.length]}):null,t.role==="assistant"?t.blocks&&t.blocks.length>0?e.jsxs("div",{className:"mdocs-agent-panel-timeline",children:[t.blocks.map((o,S)=>{var g;return o.type==="thinking"?o.text?e.jsxs("details",{className:"mdocs-agent-panel-think-fold",open:v&&t.id===((g=z[z.length-1])==null?void 0:g.id),children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:o.text})]},`${t.id}-th-${S}`):null:o.type==="text"?o.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Be,{children:o.text})},`${t.id}-t-${S}`):null:o.type==="sources"?o.items.length===0?null:e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:["已阅读 ",o.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:o.items.map(x=>e.jsx("li",{children:e.jsx("a",{href:x.url,target:"_blank",rel:"noreferrer",children:x.name})},x.id))})]})},`${t.id}-s-${S}`):o.type==="tool_notice"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:o.text})},`${t.id}-n-${S}`):o.type==="choice_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(ts,{block:o,onResolved:(x,$,l)=>{w(k=>k.map(r=>r.id!==t.id||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===x?{...d,status:l,selected:l==="selected"?$:d.selected}:d)}))}})},`${t.id}-ch-${S}`):o.type==="skill_form_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(vt,{block:o,onResolved:(x,$,l)=>{w(k=>k.map(r=>r.id!==t.id||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===x?{...d,status:$,submittedName:$==="submitted"?l:d.submittedName}:d)}))}})},`${t.id}-sf-${S}`):o.type==="document_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[e.jsxs("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:x=>{x.preventDefault(),x.stopPropagation(),ze(o.documentId)},children:["《",o.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"文档预览"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[o.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:o.path}):null,o.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:o.preview}):e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview muted",children:"(无正文预览)"})]})]})},`${t.id}-c-${S}`):e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsxs("details",{className:"mdocs-agent-panel-tool-fold",children:[e.jsxs("summary",{children:[o.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:o.rows.length===0?"无结果":`${o.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:o.rows.length===0?e.jsx("p",{className:"mdocs-agent-panel-doc-table-empty",children:"无结果"}):e.jsxs("table",{className:"mdocs-agent-panel-doc-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"文章名字"}),e.jsx("th",{children:"文章内容"})]})}),e.jsx("tbody",{children:o.rows.map(x=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>ze(x.documentId),children:x.title})}),e.jsx("td",{children:x.summary||"-"})]},x.documentId))})]})})]})},`${t.id}-d-${S}`)}),v&&t.id===((f=z[z.length-1])==null?void 0:f.id)&&!We(t.blocks)&&!Qt(t.blocks)?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null]}):t.content?e.jsx(Be,{children:t.content}):v?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null:t.content]}),t.role==="user"?e.jsx("div",{className:"mdocs-agent-panel-avatar mdocs-agent-panel-avatar-user","aria-hidden":!0,children:F}):null]},t.id)})})}),et?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:at,title:"回到底部","aria-label":"回到底部",children:[e.jsx(wt,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),Ce?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Ce}):null,he&&z.length>0?e.jsx(Pe,{onConfigured:Te}):null,e.jsx(Ct,{selectedNames:X,onChange:ve,disabled:v||!(p!=null&&p.enabled)}),e.jsxs("div",{className:"mdocs-agent-panel-input-wrap",children:[de?e.jsxs("div",{className:"mdocs-agent-doc-ref mdocs-agent-graph-ref",children:[e.jsx(Ke,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:st}),e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:"图谱(只读)"})]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前图谱",disabled:v,onClick:()=>ie(!0),children:e.jsx(ne,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):Ie?e.jsxs("div",{className:"mdocs-agent-doc-ref",children:[e.jsx(pt,{size:15,strokeWidth:1.75,className:"mdocs-agent-doc-ref-icon","aria-hidden":!0}),e.jsxs("div",{className:"mdocs-agent-doc-ref-text",children:[e.jsx("span",{className:"mdocs-agent-doc-ref-title",children:tt}),Me?e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:Me}):null]}),e.jsx("button",{type:"button",className:"mdocs-agent-doc-ref-unlink",title:"取消引用","aria-label":"取消引用当前文档",disabled:v,onClick:()=>ie(!0),children:e.jsx(ne,{size:14,strokeWidth:2,"aria-hidden":!0})})]}):null,e.jsxs("div",{className:"mdocs-agent-panel-input-body",children:[e.jsx("textarea",{className:"mdocs-agent-panel-input",rows:2,placeholder:p!=null&&p.enabled?"把你的问题告诉我…":"请先配置 API Key",value:V,disabled:v||!(p!=null&&p.enabled),onChange:t=>J(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),fe(V))}}),Q?e.jsx(ss,{percent:Q.percent,used:Q.used,limit:Q.limit}):null,e.jsx("button",{type:"button",className:v?"mdocs-agent-panel-send mdocs-agent-panel-send-stop":"mdocs-agent-panel-send",disabled:v?!1:!(p!=null&&p.enabled)||!V.trim(),onClick:()=>{var t;if(v){(t=D.current)==null||t.abort();return}fe(V)},title:v?"停止":"发送","aria-label":v?"停止":"发送",children:v?"■":"↑"})]})]}),e.jsx("p",{className:"mdocs-agent-panel-footnote",children:"内容由 AI 生成,仅供参考"})]}),oe?e.jsx("div",{className:"mdocs-agent-close-confirm-backdrop",role:"presentation",onClick:()=>{B||O(!1)},children:e.jsxs("div",{className:"mdocs-message-dialog mdocs-agent-close-confirm",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-agent-close-confirm-title",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{id:"mdocs-agent-close-confirm-title",className:"mdocs-message-dialog-title",children:"有待处理的倒计时"}),e.jsx("p",{className:"mdocs-message-dialog-body",children:"当前还有选择卡或 Skill 表单在倒计时。强制关闭会取消这些操作并退出助手;也可以继续等待完成后再关。"}),e.jsxs("div",{className:"mdocs-message-dialog-actions mdocs-agent-close-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",disabled:B,onClick:()=>O(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:B,onClick:()=>void it(),children:B?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{ps as AgentChatPanel};
@@ -1,11 +1,11 @@
1
- import{o as E,a8 as L,aB as D,ax as _,aC as B}from"./index-CUdIA5aE.js";import{r as a,j as e}from"./react-vendor-BuABiQkA.js";/**
1
+ import{o as E,a8 as D,aC as L,ay as _,aD as F}from"./index-DUu4Is5p.js";import{r as a,j as e}from"./react-vendor-BuABiQkA.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const F=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],X=E("arrow-down",F);/**
6
+ */const $=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],X=E("arrow-down",$);/**
7
7
  * @license lucide-react v0.562.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const $=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],K=E("history",$),j=5;function P(i){const t=a.useRef(!0),r=a.useRef(null),[d,k]=a.useState([]),[u,p]=a.useState(!1),[h,v]=a.useState(null);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const s=await L();if(!t.current)return;k(s)}catch(s){if(!t.current)return;v(s instanceof Error?s.message:String(s))}})()},[]),a.useEffect(()=>{if(!u)return;function s(o){const g=r.current;!g||g.contains(o.target)||p(!1)}function n(o){o.key==="Escape"&&p(!1)}return document.addEventListener("mousedown",s),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",s),document.removeEventListener("keydown",n)}},[u]);const c=d.filter(s=>i.selectedNames.includes(s.name));function f(s){if(i.disabled)return;const n=new Set(i.selectedNames);if(n.has(s))n.delete(s);else{if(n.size>=j)return;n.add(s)}i.onChange([...n])}return d.length===0&&!h?null:e.jsxs("div",{className:"mdocs-agent-skill-ref",ref:r,children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-bar",children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-anchor",children:[u&&d.length>0?e.jsxs("div",{className:"mdocs-agent-skill-popover",role:"listbox","aria-label":"选择 Skill",children:[e.jsxs("div",{className:"mdocs-agent-skill-popover-hint",children:["选择要引用的 Skill(最多 ",j," 个)"]}),e.jsx("ul",{className:"mdocs-agent-skill-popover-list",children:d.map(s=>{const n=i.selectedNames.includes(s.name),o=!n&&i.selectedNames.length>=j;return e.jsx("li",{children:e.jsxs("button",{type:"button",role:"option","aria-selected":n,className:"mdocs-agent-skill-popover-item"+(n?" mdocs-agent-skill-popover-item-on":""),disabled:i.disabled||o,onClick:()=>f(s.name),children:[e.jsx("span",{className:"mdocs-agent-skill-popover-check","aria-hidden":!0,children:n?"✓":""}),e.jsxs("span",{className:"mdocs-agent-skill-popover-text",children:[e.jsx("span",{className:"mdocs-agent-skill-popover-name",children:s.name}),s.description?e.jsx("span",{className:"mdocs-agent-skill-popover-desc",children:s.description}):e.jsx("span",{className:"mdocs-agent-skill-popover-desc mdocs-agent-skill-popover-desc-muted",children:"无简介"})]})]})},s.id)})})]}):null,e.jsxs("button",{type:"button",className:"mdocs-agent-skill-ref-toggle"+(u?" mdocs-agent-skill-ref-toggle-open":""),disabled:i.disabled||d.length===0,onClick:()=>p(s=>!s),"aria-expanded":u,"aria-haspopup":"listbox",title:"引用 Skill",children:["Skill",c.length>0?` · ${c.length}`:""]})]}),c.map(s=>e.jsxs("button",{type:"button",className:"mdocs-agent-skill-chip mdocs-agent-skill-chip-on",disabled:i.disabled,onClick:()=>f(s.name),title:"移除引用",children:[s.name,e.jsx("span",{"aria-hidden":!0,children:" ×"})]},s.name))]}),h?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:h}):null]})}const z=/^[A-Za-z0-9_]+$/;function T(i){const{block:t,onResolved:r}=i,[d,k]=a.useState(t.initialName),[u,p]=a.useState(t.initialDescription),[h,v]=a.useState(t.initialBody),[c,f]=a.useState(!1),[s,n]=a.useState(null),[o,g]=a.useState(1),x=a.useRef(!1),N=a.useRef(r);N.current=r;const m=t.status==="open",b=a.useRef(0);a.useEffect(()=>{if(!m)return;x.current=!1;const l=new Date(t.expiresAt).getTime(),M=Date.now(),y=Math.max(l-M,1);b.current=y,g(1);const S=()=>{const w=l-Date.now(),q=Math.max(0,Math.min(1,w/y));g(q),w<=0&&!x.current&&(x.current=!0,D(t.requestId).catch(()=>{}).finally(()=>{N.current(t.requestId,"expired")}))};S();const I=window.setInterval(S,100);return()=>window.clearInterval(I)},[m,t.expiresAt,t.requestId]);async function R(){if(c||!m)return;const l=d.trim();if(!l){n("名称不能为空");return}if(!z.test(l)){n("名称仅允许英文、数字、下划线");return}if(!h.trim()){n("正文不能为空");return}f(!0),n(null);try{await B(t.requestId,{name:l,description:u.trim(),body:h}),r(t.requestId,"submitted",l)}catch{r(t.requestId,"failed")}finally{f(!1)}}async function A(){if(!(c||!m)){f(!0),n(null),x.current=!0;try{await _(t.requestId),r(t.requestId,"cancelled")}catch{r(t.requestId,"failed")}finally{f(!1)}}}const C=Math.max(0,Math.ceil(o*b.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card mdocs-agent-skill-form-card"+(m?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:t.title}),m?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[C,"s"]}):null]}),m?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(o*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${o})`}})}):null,t.status==="submitted"?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已提交",t.submittedName?`:${t.submittedName}`:""]}):null,t.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,t.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,表单已失效"}):null,t.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,m?e.jsxs("div",{className:"mdocs-agent-skill-form-fields",children:[e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"名称(英文数字下划线)"}),e.jsx("input",{type:"text",value:d,onChange:l=>k(l.target.value),maxLength:64,disabled:c,autoComplete:"off",spellCheck:!1})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"简介"}),e.jsx("input",{type:"text",value:u,onChange:l=>p(l.target.value),maxLength:200,disabled:c})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:h,onChange:l=>v(l.target.value),rows:8,disabled:c})]}),s?e.jsx("p",{className:"mdocs-agent-skill-form-error",children:s}):null,e.jsxs("div",{className:"mdocs-agent-skill-form-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-skill-form-cancel",disabled:c,onClick:()=>void A(),children:"取消"}),e.jsx("button",{type:"button",disabled:c,onClick:()=>void R(),children:c?"提交中…":t.mode==="create"?"创建":"保存"})]})]}):null]})}export{X as A,K as H,T as S,P as a};
11
+ */const B=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],K=E("history",B),j=5;function P(i){const t=a.useRef(!0),r=a.useRef(null),[d,k]=a.useState([]),[u,p]=a.useState(!1),[h,v]=a.useState(null);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const s=await D();if(!t.current)return;k(s)}catch(s){if(!t.current)return;v(s instanceof Error?s.message:String(s))}})()},[]),a.useEffect(()=>{if(!u)return;function s(o){const g=r.current;!g||g.contains(o.target)||p(!1)}function n(o){o.key==="Escape"&&p(!1)}return document.addEventListener("mousedown",s),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",s),document.removeEventListener("keydown",n)}},[u]);const c=d.filter(s=>i.selectedNames.includes(s.name));function f(s){if(i.disabled)return;const n=new Set(i.selectedNames);if(n.has(s))n.delete(s);else{if(n.size>=j)return;n.add(s)}i.onChange([...n])}return d.length===0&&!h?null:e.jsxs("div",{className:"mdocs-agent-skill-ref",ref:r,children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-bar",children:[e.jsxs("div",{className:"mdocs-agent-skill-ref-anchor",children:[u&&d.length>0?e.jsxs("div",{className:"mdocs-agent-skill-popover",role:"listbox","aria-label":"选择 Skill",children:[e.jsxs("div",{className:"mdocs-agent-skill-popover-hint",children:["选择要引用的 Skill(最多 ",j," 个)"]}),e.jsx("ul",{className:"mdocs-agent-skill-popover-list",children:d.map(s=>{const n=i.selectedNames.includes(s.name),o=!n&&i.selectedNames.length>=j;return e.jsx("li",{children:e.jsxs("button",{type:"button",role:"option","aria-selected":n,className:"mdocs-agent-skill-popover-item"+(n?" mdocs-agent-skill-popover-item-on":""),disabled:i.disabled||o,onClick:()=>f(s.name),children:[e.jsx("span",{className:"mdocs-agent-skill-popover-check","aria-hidden":!0,children:n?"✓":""}),e.jsxs("span",{className:"mdocs-agent-skill-popover-text",children:[e.jsx("span",{className:"mdocs-agent-skill-popover-name",children:s.name}),s.description?e.jsx("span",{className:"mdocs-agent-skill-popover-desc",children:s.description}):e.jsx("span",{className:"mdocs-agent-skill-popover-desc mdocs-agent-skill-popover-desc-muted",children:"无简介"})]})]})},s.id)})})]}):null,e.jsxs("button",{type:"button",className:"mdocs-agent-skill-ref-toggle"+(u?" mdocs-agent-skill-ref-toggle-open":""),disabled:i.disabled||d.length===0,onClick:()=>p(s=>!s),"aria-expanded":u,"aria-haspopup":"listbox",title:"引用 Skill",children:["Skill",c.length>0?` · ${c.length}`:""]})]}),c.map(s=>e.jsxs("button",{type:"button",className:"mdocs-agent-skill-chip mdocs-agent-skill-chip-on",disabled:i.disabled,onClick:()=>f(s.name),title:"移除引用",children:[s.name,e.jsx("span",{"aria-hidden":!0,children:" ×"})]},s.name))]}),h?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:h}):null]})}const z=/^[A-Za-z0-9_]+$/;function T(i){const{block:t,onResolved:r}=i,[d,k]=a.useState(t.initialName),[u,p]=a.useState(t.initialDescription),[h,v]=a.useState(t.initialBody),[c,f]=a.useState(!1),[s,n]=a.useState(null),[o,g]=a.useState(1),x=a.useRef(!1),N=a.useRef(r);N.current=r;const m=t.status==="open",b=a.useRef(0);a.useEffect(()=>{if(!m)return;x.current=!1;const l=new Date(t.expiresAt).getTime(),M=Date.now(),y=Math.max(l-M,1);b.current=y,g(1);const S=()=>{const w=l-Date.now(),q=Math.max(0,Math.min(1,w/y));g(q),w<=0&&!x.current&&(x.current=!0,L(t.requestId).catch(()=>{}).finally(()=>{N.current(t.requestId,"expired")}))};S();const I=window.setInterval(S,100);return()=>window.clearInterval(I)},[m,t.expiresAt,t.requestId]);async function R(){if(c||!m)return;const l=d.trim();if(!l){n("名称不能为空");return}if(!z.test(l)){n("名称仅允许英文、数字、下划线");return}if(!h.trim()){n("正文不能为空");return}f(!0),n(null);try{await F(t.requestId,{name:l,description:u.trim(),body:h}),r(t.requestId,"submitted",l)}catch{r(t.requestId,"failed")}finally{f(!1)}}async function A(){if(!(c||!m)){f(!0),n(null),x.current=!0;try{await _(t.requestId),r(t.requestId,"cancelled")}catch{r(t.requestId,"failed")}finally{f(!1)}}}const C=Math.max(0,Math.ceil(o*b.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card mdocs-agent-skill-form-card"+(m?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:t.title}),m?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[C,"s"]}):null]}),m?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(o*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${o})`}})}):null,t.status==="submitted"?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已提交",t.submittedName?`:${t.submittedName}`:""]}):null,t.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,t.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,表单已失效"}):null,t.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,m?e.jsxs("div",{className:"mdocs-agent-skill-form-fields",children:[e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"名称(英文数字下划线)"}),e.jsx("input",{type:"text",value:d,onChange:l=>k(l.target.value),maxLength:64,disabled:c,autoComplete:"off",spellCheck:!1})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"简介"}),e.jsx("input",{type:"text",value:u,onChange:l=>p(l.target.value),maxLength:200,disabled:c})]}),e.jsxs("label",{className:"mdocs-agent-skill-form-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:h,onChange:l=>v(l.target.value),rows:8,disabled:c})]}),s?e.jsx("p",{className:"mdocs-agent-skill-form-error",children:s}):null,e.jsxs("div",{className:"mdocs-agent-skill-form-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-skill-form-cancel",disabled:c,onClick:()=>void A(),children:"取消"}),e.jsx("button",{type:"button",disabled:c,onClick:()=>void R(),children:c?"提交中…":t.mode==="create"?"创建":"保存"})]})]}):null]})}export{X as A,K as H,T as S,P as a};
@@ -1,7 +1,7 @@
1
- import{r as c,j as e}from"./react-vendor-BuABiQkA.js";import{ay as Se,az as Ie,aw as ve,an as de,ao as Me,q as Ae,ap as ue,a4 as Te,as as Le,aA as Re,at as $e,au as Ee,av as _e}from"./index-CUdIA5aE.js";import{H as qe,S as Pe,A as De,a as Be}from"./AgentSkillFormCard-BYUjSFe1.js";import{P as Fe}from"./plus-QDhBbIRF.js";import{ae as He,af as Ke}from"./ui-CvA4pq3d.js";import"./diagram-Bk84WZto.js";import"./motion-DFABYlwt.js";function Oe(t){const{block:s,onResolved:i}=t,[r,f]=c.useState(""),[g,p]=c.useState(!1),[N,k]=c.useState(1),h=c.useRef(!1),j=c.useRef(i);j.current=i;const u=s.status==="open",E=c.useRef(0);c.useEffect(()=>{if(!u)return;h.current=!1;const m=new Date(s.expiresAt).getTime(),b=Date.now(),P=Math.max(m-b,1);E.current=P,k(1);const $=()=>{const K=m-Date.now(),A=Math.max(0,Math.min(1,K/P));k(A),K<=0&&!h.current&&(h.current=!0,Se(s.requestId).catch(()=>{}).finally(()=>{j.current(s.requestId,"","expired")}))};$();const H=window.setInterval($,100);return()=>window.clearInterval(H)},[u,s.expiresAt,s.requestId]);async function y(m){const b=m.trim();if(!(!b||g||!u)){p(!0);try{await Ie(s.requestId,b),i(s.requestId,b,"selected")}catch{i(s.requestId,b,"failed")}finally{p(!1)}}}async function R(){if(!(g||!u)){p(!0),h.current=!0;try{await ve(s.requestId),i(s.requestId,"","cancelled")}catch{i(s.requestId,"","failed")}finally{p(!1)}}}const F=Math.max(0,Math.ceil(N*E.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(u?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:s.title}),u?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[F,"s"]}):null]}),u?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(N*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${N})`}})}):null,s.status==="selected"&&s.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",s.selected]}):null,s.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,s.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,s.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,u?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:s.options.map(m=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:g,onClick:()=>void y(m),children:m},m))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:r,disabled:g,placeholder:"或输入自己的内容…",onChange:m=>f(m.target.value),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),y(r))}}),e.jsx("button",{type:"button",disabled:g||!r.trim(),onClick:()=>void y(r),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:g,onClick:()=>void R(),children:"取消"})})]}):null]})}function te(t){return t===""?[]:t.split(`
1
+ import{r as c,j as e}from"./react-vendor-BuABiQkA.js";import{az as Se,aA as Ie,ax as ve,ao as de,ap as Me,q as Ae,aq as ue,a4 as Te,at as Le,aB as Re,au as $e,av as Ee,aw as qe}from"./index-DUu4Is5p.js";import{H as _e,S as Pe,A as De,a as Be}from"./AgentSkillFormCard-DTgxybJh.js";import{P as Fe}from"./plus-C3uXIATM.js";import{ae as He,af as Ke}from"./ui-CvA4pq3d.js";import"./diagram-Bk84WZto.js";import"./motion-DFABYlwt.js";function Oe(t){const{block:s,onResolved:i}=t,[r,f]=c.useState(""),[g,p]=c.useState(!1),[N,k]=c.useState(1),h=c.useRef(!1),j=c.useRef(i);j.current=i;const u=s.status==="open",E=c.useRef(0);c.useEffect(()=>{if(!u)return;h.current=!1;const m=new Date(s.expiresAt).getTime(),b=Date.now(),P=Math.max(m-b,1);E.current=P,k(1);const $=()=>{const K=m-Date.now(),A=Math.max(0,Math.min(1,K/P));k(A),K<=0&&!h.current&&(h.current=!0,Se(s.requestId).catch(()=>{}).finally(()=>{j.current(s.requestId,"","expired")}))};$();const H=window.setInterval($,100);return()=>window.clearInterval(H)},[u,s.expiresAt,s.requestId]);async function y(m){const b=m.trim();if(!(!b||g||!u)){p(!0);try{await Ie(s.requestId,b),i(s.requestId,b,"selected")}catch{i(s.requestId,b,"failed")}finally{p(!1)}}}async function R(){if(!(g||!u)){p(!0),h.current=!0;try{await ve(s.requestId),i(s.requestId,"","cancelled")}catch{i(s.requestId,"","failed")}finally{p(!1)}}}const F=Math.max(0,Math.ceil(N*E.current/1e3));return e.jsxs("div",{className:"mdocs-agent-choice-card"+(u?"":" mdocs-agent-choice-card-done"),children:[e.jsxs("div",{className:"mdocs-agent-choice-head",children:[e.jsx("p",{className:"mdocs-agent-choice-title",children:s.title}),u?e.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[F,"s"]}):null]}),u?e.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(N*100),children:e.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${N})`}})}):null,s.status==="selected"&&s.selected?e.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",s.selected]}):null,s.status==="cancelled"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,s.status==="expired"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,s.status==="failed"?e.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,u?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-agent-choice-options",children:s.options.map(m=>e.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:g,onClick:()=>void y(m),children:m},m))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:r,disabled:g,placeholder:"或输入自己的内容…",onChange:m=>f(m.target.value),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),y(r))}}),e.jsx("button",{type:"button",disabled:g||!r.trim(),onClick:()=>void y(r),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:g,onClick:()=>void R(),children:"取消"})})]}):null]})}function te(t){return t===""?[]:t.split(`
2
2
  `)}function We(t){return t.join(`
3
3
  `)}function ne(t,s){const i=te(t),r=te(s),f=i.length,g=r.length,p=Array.from({length:f+1},()=>Array.from({length:g+1},()=>0));for(let y=f-1;y>=0;y--)for(let R=g-1;R>=0;R--)i[y]===r[R]?p[y][R]=p[y+1][R+1]+1:p[y][R]=Math.max(p[y+1][R],p[y][R+1]);const N=[];let k=0,h=0;for(;k<f||h<g;)if(k<f&&h<g&&i[k]===r[h])N.push({kind:"eq",oi:k,ni:h}),k++,h++;else if(h<g&&(k===f||p[k][h+1]>=p[k+1][h]))N.push({kind:"ins",oi:k,ni:h}),h++;else if(k<f)N.push({kind:"del",oi:k,ni:h}),k++;else break;const j=[];let u=0,E=0;for(;u<N.length;){if(N[u].kind==="eq"){u++;continue}const y=N[u].oi,R=N[u].ni,F=[],m=[];let b=y,P=R;for(;u<N.length&&N[u].kind!=="eq";){const $=N[u];$.kind==="del"?(F.push(i[$.oi]),b=$.oi+1):(m.push(r[$.ni]),P=$.ni+1),u++}j.push({id:`h${E++}`,oldStart:y,oldEnd:b,newStart:R,newEnd:P,oldLines:F,newLines:m})}return j}function ze(t,s){const i=te(t);return We([...i.slice(0,s.oldStart),...s.newLines,...i.slice(s.oldEnd)])}function U(t){return t===""?[]:t.split(`
4
4
  `)}function z(t){return t.join(`
5
- `)}function Je(t,s){const i=U(t),r=[];let f=0;return s.forEach((g,p)=>{g.oldStart>f&&r.push({kind:"same",lines:i.slice(f,g.oldStart),key:`s-${f}-${g.oldStart}`}),r.push({kind:"hunk",hunk:g,hunkIndex:p,key:`h-${g.id}-${p}`}),f=g.oldEnd}),f<i.length?r.push({kind:"same",lines:i.slice(f),key:`s-${f}-end`}):s.length===0&&i.length===0&&r.push({kind:"same",lines:[],key:"s-empty"}),r}function Ge(t){const s=[],i=[];for(const r of t)r.kind==="same"?s.push(z(r.lines)):i.push(z(r.hunk.newLines));return{sameTexts:s,newTexts:i}}function me(t,s){const i=[];let r=0,f=0;for(const g of t)if(g.kind==="same"){const p=s.sameTexts[r++]??"";i.push(...U(p))}else{const p=s.newTexts[f++]??"";i.push(...U(p))}return z(i)}function Ue(t){return t.oldLines.length===0?"add":t.newLines.length===0?"del":"mod"}function he(t){const s=Math.max(1,U(t.value).length);return e.jsxs("div",{className:`mdocs-ai-write-line ${t.className}`,children:[e.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),e.jsx("textarea",{className:"mdocs-ai-write-inline-edit",value:t.value,rows:s,spellCheck:!1,"aria-label":t["aria-label"],onChange:i=>t.onChange(i.target.value),onBlur:()=>t.onBlurFlush()})]})}function Ve(t){const s=!!t.sending,[i,r]=c.useState(0),[f,g]=c.useState(null),[p,N]=c.useState({sameTexts:[],newTexts:[]}),[k,h]=c.useState([]),j=c.useRef(!1),u=c.useRef(!1),E=c.useRef([]),y=c.useRef(p);y.current=p,E.current=k;const R=c.useMemo(()=>t.proposedMd==null||t.proposedMd===t.currentMd?[]:ne(t.currentMd,t.proposedMd),[t.currentMd,t.proposedMd]),F=!s&&(k.length>0?k.some(l=>l.kind==="hunk"):R.length>0);c.useEffect(()=>{if(s){h([]),j.current=!1,u.current=!1;return}if(t.proposedMd==null||t.proposedMd===t.currentMd){h([]),j.current=!1,u.current=!1;return}if(u.current){u.current=!1;return}const l=ne(t.currentMd,t.proposedMd);if(l.length===0){h([]);return}const x=Je(t.currentMd,l);h(x),j.current=!1,N(Ge(x))},[s,t.proposedMd,t.currentMd]);const m=c.useMemo(()=>k.filter(l=>l.kind==="hunk").map(l=>l.hunk),[k]);c.useEffect(()=>{if(m.length===0){r(0);return}r(l=>Math.min(l,m.length-1))},[m.length]);const b=f??i;function P(){return me(E.current,y.current)}function $(){if(!F||E.current.length===0)return t.proposedMd;const l=P();return j.current=!1,l===t.currentMd?(u.current=!1,t.onProposedChange(null),null):(l!==t.proposedMd&&(u.current=!0,t.onProposedChange(l)),l)}function H(l){const x=E.current.find(D=>D.kind==="hunk"&&D.hunk.id===l.id);if(!x)return;const S=y.current.newTexts[x.hunkIndex],I={...l,newLines:S!=null?U(S):l.newLines},v=P();if(j.current=!1,u.current=!1,v===t.currentMd){t.onProposedChange(null);return}const T=ze(t.currentMd,I);t.onCurrentChange(T),v===T?t.onProposedChange(null):t.onProposedChange(v)}function K(l){const x=E.current.find(v=>v.kind==="hunk"&&v.hunk.id===l.id);if(!x)return;const S={sameTexts:y.current.sameTexts.slice(),newTexts:y.current.newTexts.slice()};S.newTexts[x.hunkIndex]=z(l.oldLines);const I=me(E.current,S);j.current=!1,u.current=!1,I===t.currentMd?t.onProposedChange(null):t.onProposedChange(I)}function A(){const l=P();j.current=!1,u.current=!1,t.onCurrentChange(l),t.onProposedChange(null)}function J(){j.current=!1,u.current=!1,t.onProposedChange(null)}function C(l){m.length!==0&&r(x=>{const S=(x+l+m.length)%m.length,I=document.getElementById(`mdocs-ai-hunk-${S}`);return I==null||I.scrollIntoView({block:"center",behavior:"smooth"}),S})}function W(l,x){j.current=!0,N(S=>{const I=S.sameTexts.slice();return I[l]=x,{...S,sameTexts:I}})}function V(l,x){j.current=!0,N(S=>{const I=S.newTexts.slice();return I[l]=x,{...S,newTexts:I}})}const _=m[b]??null;let G=0;return e.jsxs("div",{className:"mdocs-ai-write-md-pane",children:[e.jsxs("div",{className:"mdocs-ai-write-diff-toolbar",children:[e.jsx("span",{className:"mdocs-ai-write-diff-count",children:s?"接收中·编辑我的稿":m.length===0?t.proposedMd?"与提案一致(可编辑)":"Markdown 源码(可编辑)":`${m.length} 处变更(可改提案)`}),!s&&m.length>0?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"mdocs-ai-write-diff-accept-all",onClick:A,children:"全部接受"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-diff-reject-all",onClick:J,children:"全部拒绝"})]}):null]}),F&&k.length>0?e.jsxs("div",{className:"mdocs-ai-write-inline",role:"document",children:[k.map(l=>{if(l.kind==="same"){const T=G++,D=p.sameTexts[T]??z(l.lines);return e.jsx("div",{className:"mdocs-ai-write-inline-same",children:e.jsx(he,{className:"ctx",value:D,"aria-label":"提案相同行",onChange:Z=>W(T,Z),onBlurFlush:()=>$()})},l.key)}const x=l.hunk,S=Ue(x),I=l.hunkIndex===b,v=p.newTexts[l.hunkIndex]??z(x.newLines);return e.jsxs("div",{id:`mdocs-ai-hunk-${l.hunkIndex}`,className:`mdocs-ai-write-inline-hunk mdocs-ai-write-inline-hunk-${S}`+(I?" is-active":""),onMouseEnter:()=>g(l.hunkIndex),onMouseLeave:()=>g(null),onClick:()=>r(l.hunkIndex),children:[e.jsxs("div",{className:"mdocs-ai-write-hunk-hover",hidden:f!==l.hunkIndex,children:[e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:T=>{T.stopPropagation(),K(x)},children:"拒绝"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:T=>{T.stopPropagation(),H(x)},children:"接受"})]}),e.jsx("pre",{className:"mdocs-ai-write-hunk-pre",children:x.oldLines.map((T,D)=>e.jsxs("div",{className:"mdocs-ai-write-line del mdocs-ai-write-line-readonly",children:[e.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),e.jsx("span",{className:"mdocs-ai-write-code",children:T||" "})]},`o${D}`))}),x.newLines.length>0||v!==""||S!=="del"?e.jsx(he,{className:"add",value:v,"aria-label":"提案新增行",onChange:T=>V(l.hunkIndex,T),onBlurFlush:()=>$()}):null]},l.key)}),_?e.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"变更导航",children:[e.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>C(-1),children:"↑"}),e.jsxs("span",{children:[b+1," / ",m.length]}),e.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>C(1),children:"↓"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>K(_),children:"拒绝"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>H(_),children:"接受"})]}):null]}):e.jsx("textarea",{className:"mdocs-ai-write-editor",value:t.currentMd,onChange:l=>t.onCurrentChange(l.target.value),spellCheck:!1,placeholder:`# 标题
5
+ `)}function Je(t,s){const i=U(t),r=[];let f=0;return s.forEach((g,p)=>{g.oldStart>f&&r.push({kind:"same",lines:i.slice(f,g.oldStart),key:`s-${f}-${g.oldStart}`}),r.push({kind:"hunk",hunk:g,hunkIndex:p,key:`h-${g.id}-${p}`}),f=g.oldEnd}),f<i.length?r.push({kind:"same",lines:i.slice(f),key:`s-${f}-end`}):s.length===0&&i.length===0&&r.push({kind:"same",lines:[],key:"s-empty"}),r}function Ge(t){const s=[],i=[];for(const r of t)r.kind==="same"?s.push(z(r.lines)):i.push(z(r.hunk.newLines));return{sameTexts:s,newTexts:i}}function me(t,s){const i=[];let r=0,f=0;for(const g of t)if(g.kind==="same"){const p=s.sameTexts[r++]??"";i.push(...U(p))}else{const p=s.newTexts[f++]??"";i.push(...U(p))}return z(i)}function Ue(t){return t.oldLines.length===0?"add":t.newLines.length===0?"del":"mod"}function he(t){const s=Math.max(1,U(t.value).length);return e.jsxs("div",{className:`mdocs-ai-write-line ${t.className}`,children:[e.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),e.jsx("textarea",{className:"mdocs-ai-write-inline-edit",value:t.value,rows:s,spellCheck:!1,"aria-label":t["aria-label"],onChange:i=>t.onChange(i.target.value),onBlur:()=>t.onBlurFlush()})]})}function Ve(t){const s=!!t.sending,[i,r]=c.useState(0),[f,g]=c.useState(null),[p,N]=c.useState({sameTexts:[],newTexts:[]}),[k,h]=c.useState([]),j=c.useRef(!1),u=c.useRef(!1),E=c.useRef([]),y=c.useRef(p);y.current=p,E.current=k;const R=c.useMemo(()=>t.proposedMd==null||t.proposedMd===t.currentMd?[]:ne(t.currentMd,t.proposedMd),[t.currentMd,t.proposedMd]),F=!s&&(k.length>0?k.some(l=>l.kind==="hunk"):R.length>0);c.useEffect(()=>{if(s){h([]),j.current=!1,u.current=!1;return}if(t.proposedMd==null||t.proposedMd===t.currentMd){h([]),j.current=!1,u.current=!1;return}if(u.current){u.current=!1;return}const l=ne(t.currentMd,t.proposedMd);if(l.length===0){h([]);return}const x=Je(t.currentMd,l);h(x),j.current=!1,N(Ge(x))},[s,t.proposedMd,t.currentMd]);const m=c.useMemo(()=>k.filter(l=>l.kind==="hunk").map(l=>l.hunk),[k]);c.useEffect(()=>{if(m.length===0){r(0);return}r(l=>Math.min(l,m.length-1))},[m.length]);const b=f??i;function P(){return me(E.current,y.current)}function $(){if(!F||E.current.length===0)return t.proposedMd;const l=P();return j.current=!1,l===t.currentMd?(u.current=!1,t.onProposedChange(null),null):(l!==t.proposedMd&&(u.current=!0,t.onProposedChange(l)),l)}function H(l){const x=E.current.find(D=>D.kind==="hunk"&&D.hunk.id===l.id);if(!x)return;const S=y.current.newTexts[x.hunkIndex],I={...l,newLines:S!=null?U(S):l.newLines},v=P();if(j.current=!1,u.current=!1,v===t.currentMd){t.onProposedChange(null);return}const T=ze(t.currentMd,I);t.onCurrentChange(T),v===T?t.onProposedChange(null):t.onProposedChange(v)}function K(l){const x=E.current.find(v=>v.kind==="hunk"&&v.hunk.id===l.id);if(!x)return;const S={sameTexts:y.current.sameTexts.slice(),newTexts:y.current.newTexts.slice()};S.newTexts[x.hunkIndex]=z(l.oldLines);const I=me(E.current,S);j.current=!1,u.current=!1,I===t.currentMd?t.onProposedChange(null):t.onProposedChange(I)}function A(){const l=P();j.current=!1,u.current=!1,t.onCurrentChange(l),t.onProposedChange(null)}function J(){j.current=!1,u.current=!1,t.onProposedChange(null)}function C(l){m.length!==0&&r(x=>{const S=(x+l+m.length)%m.length,I=document.getElementById(`mdocs-ai-hunk-${S}`);return I==null||I.scrollIntoView({block:"center",behavior:"smooth"}),S})}function W(l,x){j.current=!0,N(S=>{const I=S.sameTexts.slice();return I[l]=x,{...S,sameTexts:I}})}function V(l,x){j.current=!0,N(S=>{const I=S.newTexts.slice();return I[l]=x,{...S,newTexts:I}})}const q=m[b]??null;let G=0;return e.jsxs("div",{className:"mdocs-ai-write-md-pane",children:[e.jsxs("div",{className:"mdocs-ai-write-diff-toolbar",children:[e.jsx("span",{className:"mdocs-ai-write-diff-count",children:s?"接收中·编辑我的稿":m.length===0?t.proposedMd?"与提案一致(可编辑)":"Markdown 源码(可编辑)":`${m.length} 处变更(可改提案)`}),!s&&m.length>0?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"mdocs-ai-write-diff-accept-all",onClick:A,children:"全部接受"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-diff-reject-all",onClick:J,children:"全部拒绝"})]}):null]}),F&&k.length>0?e.jsxs("div",{className:"mdocs-ai-write-inline",role:"document",children:[k.map(l=>{if(l.kind==="same"){const T=G++,D=p.sameTexts[T]??z(l.lines);return e.jsx("div",{className:"mdocs-ai-write-inline-same",children:e.jsx(he,{className:"ctx",value:D,"aria-label":"提案相同行",onChange:Z=>W(T,Z),onBlurFlush:()=>$()})},l.key)}const x=l.hunk,S=Ue(x),I=l.hunkIndex===b,v=p.newTexts[l.hunkIndex]??z(x.newLines);return e.jsxs("div",{id:`mdocs-ai-hunk-${l.hunkIndex}`,className:`mdocs-ai-write-inline-hunk mdocs-ai-write-inline-hunk-${S}`+(I?" is-active":""),onMouseEnter:()=>g(l.hunkIndex),onMouseLeave:()=>g(null),onClick:()=>r(l.hunkIndex),children:[e.jsxs("div",{className:"mdocs-ai-write-hunk-hover",hidden:f!==l.hunkIndex,children:[e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:T=>{T.stopPropagation(),K(x)},children:"拒绝"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:T=>{T.stopPropagation(),H(x)},children:"接受"})]}),e.jsx("pre",{className:"mdocs-ai-write-hunk-pre",children:x.oldLines.map((T,D)=>e.jsxs("div",{className:"mdocs-ai-write-line del mdocs-ai-write-line-readonly",children:[e.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),e.jsx("span",{className:"mdocs-ai-write-code",children:T||" "})]},`o${D}`))}),x.newLines.length>0||v!==""||S!=="del"?e.jsx(he,{className:"add",value:v,"aria-label":"提案新增行",onChange:T=>V(l.hunkIndex,T),onBlurFlush:()=>$()}):null]},l.key)}),q?e.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"变更导航",children:[e.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>C(-1),children:"↑"}),e.jsxs("span",{children:[b+1," / ",m.length]}),e.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>C(1),children:"↓"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>K(q),children:"拒绝"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>H(q),children:"接受"})]}):null]}):e.jsx("textarea",{className:"mdocs-ai-write-editor",value:t.currentMd,onChange:l=>t.onCurrentChange(l.target.value),spellCheck:!1,placeholder:`# 标题
6
6
 
7
- 在此编辑 Markdown 源码…`})]})}let fe=0;function ge(t){return fe+=1,`${t}-${Date.now()}-${fe}`}function Ye(t,s){const i=t.slice(),r=i[i.length-1];return(r==null?void 0:r.type)==="text"?i[i.length-1]={type:"text",text:r.text+s}:i.push({type:"text",text:s}),i}function Xe(t,s){const i=t.slice(),r=i[i.length-1];return(r==null?void 0:r.type)==="thinking"?i[i.length-1]={type:"thinking",text:r.text+s}:i.push({type:"thinking",text:s}),i}function Q(t,s){const i=s.trim();return i?[...t,{type:"tool",text:i}]:t}function Qe(t){return t.some(s=>s.type==="text"||s.type==="thinking"?s.text.length>0:!0)}function Ze(t){const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const i=new Date;return s.getFullYear()===i.getFullYear()&&s.getMonth()===i.getMonth()&&s.getDate()===i.getDate()?s.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):s.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function xe(t,s){return s.map((i,r)=>{const f=`h-${t}-${r}-${i.role}`;if(i.role==="user"){const g=i.skillNames&&i.skillNames.length>0?i.skillNames:i.skillIds&&i.skillIds.length>0?i.skillIds:void 0;return{id:f,role:"user",content:i.content,skillNames:g}}return{id:f,role:"assistant",blocks:i.content?[{type:"text",text:i.content}]:[]}})}function rt(t){const[s,i]=c.useState(t.initialMarkdown),[r,f]=c.useState(null),[g]=c.useState(t.initialMarkdown),[p,N]=c.useState(t.displayName||"未命名"),[k,h]=c.useState([]),[j,u]=c.useState(null),[E,y]=c.useState([]),[R,F]=c.useState(!1),[m,b]=c.useState(!1),[P,$]=c.useState(""),[H,K]=c.useState([]),[A,J]=c.useState(!1),[C,W]=c.useState(null),[V,_]=c.useState(null),[G,l]=c.useState(!1),[x,S]=c.useState(null),I=c.useRef(null),v=c.useRef(null),T=c.useRef(null),D=c.useRef(!0),[Z,ee]=c.useState(!1),se=120;function ie(n){return n.scrollHeight-n.scrollTop-n.clientHeight}function Y(){const n=T.current;n&&(n.scrollTop=n.scrollHeight,ee(!1))}function ke(){D.current&&Y()}function pe(){const n=T.current;if(!n)return;const o=ie(n);D.current=o<=48,ee(o>se)}function ye(){D.current=!0,Y()}c.useLayoutEffect(()=>{if(!t.open)return;ke();const n=T.current;n&&ee(ie(n)>se)},[k,t.open]);async function X(){F(!0);try{const n=await Le("coding",t.documentId);y(n.sessions),j||u(n.lastOpenedSessionId)}catch{}finally{F(!1)}}async function ae(){try{const n=await de();W(n)}catch{W({enabled:!1,skillsReady:!1,model:null})}}if(c.useEffect(()=>{var o;if(!t.open){b(!1),(o=v.current)==null||o.abort();return}i(t.initialMarkdown),f(null),N(t.displayName||"未命名"),$(""),_(null),b(!1);let n=!1;return(async()=>{try{const w=await de();n||W(w)}catch{n||W({enabled:!1,skillsReady:!1,model:null})}try{const w=await Me("coding",t.documentId);if(n)return;u(w.sessionId),h(xe(w.sessionId,w.messages))}catch{n||(u(null),h([]))}X()})(),()=>{n=!0}},[t.open,t.initialMarkdown,t.displayName,t.documentId]),c.useEffect(()=>()=>{var n;return(n=v.current)==null?void 0:n.abort()},[]),c.useEffect(()=>{t.open&&m&&X()},[m,t.open,t.documentId]),!t.open)return null;const le=(C==null?void 0:C.reason)==="missing_api_key",we=r!=null&&r!==s?ne(s,r):[];async function je(){var n;if(!A){(n=v.current)==null||n.abort(),_(null),b(!1),J(!1);try{const o=await $e("coding",t.documentId);u(o.sessionId),h([]),$(""),X()}catch(o){_(o instanceof Error?o.message:String(o))}}}async function Ne(n){var o;if(!A){if(n===j){b(!1);return}(o=v.current)==null||o.abort(),_(null);try{const w=await Ee(n,"coding",t.documentId);u(w.sessionId),h(xe(w.sessionId,w.messages)),$(""),b(!1)}catch(w){_(w instanceof Error?w.message:String(w))}}}async function re(){var O;const n=P.trim();if(!n||A)return;if(!(C!=null&&C.enabled)){_("请先配置 API Key");return}(O=v.current)==null||O.abort();const o=new AbortController;v.current=o;const w=ge("u"),M=ge("a");D.current=!0,h(q=>[...q,{id:w,role:"user",content:n,skillNames:H.length>0?[...H]:void 0},{id:M,role:"assistant",blocks:[]}]),$(""),J(!0),_(null),requestAnimationFrame(()=>{Y(),requestAnimationFrame(Y)});const L=q=>{h(a=>a.map(d=>d.id===M&&d.role==="assistant"?{...d,blocks:q(d.blocks)}:d))};try{let q=!1;await _e(n,{mode:"coding",skillNames:H.length>0?H:void 0,documentId:t.documentId,workingMarkdown:s,baseMarkdown:g,signal:o.signal,onEvent:a=>{a.type==="text_delta"?L(d=>Ye(d,a.text)):a.type==="thinking_delta"?L(d=>Xe(d,a.text)):a.type==="markdown_set"?f(a.markdown):a.type==="tool_notice"?L(d=>Q(d,a.text)):a.type==="document_table"?L(d=>Q(d,a.title)):a.type==="document_card"?L(d=>Q(d,`读取文档「${a.title}」`)):a.type==="sources"?a.items.length>0&&L(d=>Q(d,`已阅读 ${a.items.length} 个手册页面`)):a.type==="skill_form_card"?L(d=>[...d,{type:"skill_form_card",requestId:a.requestId,mode:a.mode,title:a.title,currentName:a.currentName,initialName:a.initialName,initialDescription:a.initialDescription,initialBody:a.initialBody,expiresAt:a.expiresAt,status:"open"}]):a.type==="choice_card"?(D.current=!0,L(d=>[...d,{type:"choice_card",requestId:a.requestId,title:a.title,options:a.options,expiresAt:a.expiresAt,status:"open"}])):a.type==="choice_expired"?L(d=>d.map(B=>B.type==="choice_card"&&B.requestId===a.requestId&&B.status==="open"?{...B,status:"expired"}:B)):a.type==="skill_form_expired"?L(d=>d.map(B=>B.type==="skill_form_card"&&B.requestId===a.requestId&&B.status==="open"?{...B,status:"expired"}:B)):a.type==="error"&&(q=!0,_(a.message))}}),!o.signal.aborted&&!q&&K([]),X()}catch(q){o.signal.aborted||_(q instanceof Error?q.message:String(q))}finally{v.current===o&&(v.current=null),J(!1)}}function oe(n){return new Promise(o=>{I.current=o,S({message:n.message,confirmLabel:n.confirmLabel??"确定",cancelLabel:n.cancelLabel??"返回",danger:n.danger??!1})})}function ce(n){const o=I.current;I.current=null,S(null),o==null||o(n)}async function be(){if(!await oe({message:"是否回写",confirmLabel:"确认",cancelLabel:"返回"}))return;let o=s;we.length>0&&(o=r??s,i(o),f(null)),l(!0);const w=!t.documentId;try{const M=await t.onComplete({markdown:o,documentId:t.documentId,displayName:p.trim()||"未命名"}),L=M&&typeof M=="object"&&typeof M.documentId=="string"?M.documentId.trim():"";if(w&&L&&j)try{await Re(j,L)}catch{}t.onClose()}catch(M){if(M!=null&&M.silent||M instanceof Error&&M.message==="cancelled")return;_(M instanceof Error?M.message:String(M))}finally{l(!1)}}async function Ce(){var n;(s!==g||r!=null)&&!await oe({message:"取消帮写?未写回的修改将丢失。",confirmLabel:"放弃修改",danger:!0})||((n=v.current)==null||n.abort(),t.onClose())}return e.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[e.jsxs("header",{className:"mdocs-ai-write-header",children:[e.jsxs("div",{className:"mdocs-ai-write-header-left",children:[e.jsx("img",{src:Ae,alt:"",className:"mdocs-ai-write-title-logo"}),e.jsx("strong",{children:"帮写"}),e.jsx("input",{className:"mdocs-ai-write-title",value:p,onChange:n=>N(n.target.value),"aria-label":"文档标题"})]}),e.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[e.jsx("button",{type:"button",onClick:()=>void Ce(),disabled:G||x!=null,children:"取消"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void be(),disabled:G||x!=null,children:G?"写回中…":"完成并写回"})]})]}),e.jsxs("div",{className:"mdocs-ai-write-body",children:[e.jsxs("section",{className:"mdocs-ai-write-chat",children:[e.jsxs("div",{className:"mdocs-ai-write-chat-toolbar",children:[e.jsx("span",{className:"mdocs-ai-write-chat-toolbar-label",children:"对话"}),e.jsxs("div",{className:"mdocs-ai-write-chat-toolbar-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:A,onClick:()=>void je(),children:e.jsx(Fe,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(m?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>b(n=>!n),children:e.jsx(qe,{size:16,strokeWidth:1.8})})]})]}),m?e.jsxs("div",{className:"mdocs-ai-write-history mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>b(!1),children:"返回对话"})]}),R?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):E.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):e.jsx("ul",{className:"mdocs-agent-panel-history-list",children:E.map(n=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(n.id===j?" active":""),disabled:A,onClick:()=>void Ne(n.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:n.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:Ze(n.updatedAt)})]})},n.id))})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-ai-write-chat-scroll-wrap",children:[e.jsx("div",{className:"mdocs-ai-write-chat-messages",ref:T,onScroll:pe,children:k.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-ai-write-hint",children:"描述你想写或改的内容。助手可读取右侧当前稿与进场快照,再更新提案;请按段接受或拒绝后完成写回。"}),le?e.jsx(ue,{onConfigured:ae}):null]}):k.map(n=>e.jsx("div",{className:"mdocs-ai-write-msg"+(n.role==="user"?" mdocs-ai-write-msg-user":""),children:n.role==="user"?e.jsxs(e.Fragment,{children:[n.skillNames&&n.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",n.skillNames.length]}):null,n.content]}):Qe(n.blocks)?e.jsx("div",{className:"mdocs-ai-write-timeline",children:n.blocks.map((o,w)=>o.type==="thinking"?o.text?e.jsxs("details",{className:"mdocs-ai-write-thinking",open:A,children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-ai-write-thinking-body",children:o.text})]},`${n.id}-think-${w}`):null:o.type==="tool"?e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:o.text},`${n.id}-tool-${w}`):o.type==="skill_form_card"?e.jsx(Pe,{block:o,onResolved:(M,L,O)=>{h(q=>q.map(a=>a.id!==n.id||a.role!=="assistant"?a:{...a,blocks:a.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===M?{...d,status:L,submittedName:L==="submitted"?O:d.submittedName}:d)}))}},`${n.id}-sf-${w}`):o.type==="choice_card"?e.jsx(Oe,{block:o,onResolved:(M,L,O)=>{h(q=>q.map(a=>a.id!==n.id||a.role!=="assistant"?a:{...a,blocks:a.blocks.map(d=>d.type==="choice_card"&&d.requestId===M?{...d,status:O,selected:O==="selected"?L:d.selected}:d)}))}},`${n.id}-ch-${w}`):o.type==="text"&&o.text?e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(He,{remarkPlugins:[Ke],children:o.text})},`${n.id}-text-${w}`):null)}):A?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null},n.id))}),Z?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:ye,title:"回到底部","aria-label":"回到底部",children:[e.jsx(De,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),V?e.jsx("p",{className:"mdocs-ai-write-error",children:V}):null,le&&k.length>0?e.jsx(ue,{onConfigured:ae}):null,e.jsxs("div",{className:"mdocs-ai-write-input-row",children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:6},children:[e.jsx(Be,{selectedNames:H,onChange:K,disabled:A||!(C!=null&&C.enabled)}),e.jsx("textarea",{rows:2,value:P,disabled:A||!(C!=null&&C.enabled),placeholder:C!=null&&C.enabled?"说说要写什么…":"请先配置 API Key",onChange:n=>$(n.target.value),onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),re())}})]}),e.jsx("button",{type:"button",className:A?"mdocs-ai-write-stop":void 0,disabled:A?!1:!(C!=null&&C.enabled),onClick:()=>{var n;if(A){(n=v.current)==null||n.abort();return}re()},children:A?"停止":"发送"})]})]})]}),e.jsx(Ve,{currentMd:s,proposedMd:r,sending:A,onCurrentChange:i,onProposedChange:f})]}),x?e.jsx(Te,{message:x.message,confirmLabel:x.confirmLabel,cancelLabel:x.cancelLabel,danger:x.danger,onConfirm:()=>ce(!0),onCancel:()=>ce(!1)}):null]})}export{rt as AiWriteWorkbench};
7
+ 在此编辑 Markdown 源码…`})]})}let fe=0;function ge(t){return fe+=1,`${t}-${Date.now()}-${fe}`}function Ye(t,s){const i=t.slice(),r=i[i.length-1];return(r==null?void 0:r.type)==="text"?i[i.length-1]={type:"text",text:r.text+s}:i.push({type:"text",text:s}),i}function Xe(t,s){const i=t.slice(),r=i[i.length-1];return(r==null?void 0:r.type)==="thinking"?i[i.length-1]={type:"thinking",text:r.text+s}:i.push({type:"thinking",text:s}),i}function Q(t,s){const i=s.trim();return i?[...t,{type:"tool",text:i}]:t}function Qe(t){return t.some(s=>s.type==="text"||s.type==="thinking"?s.text.length>0:!0)}function Ze(t){const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const i=new Date;return s.getFullYear()===i.getFullYear()&&s.getMonth()===i.getMonth()&&s.getDate()===i.getDate()?s.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):s.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function xe(t,s){return s.map((i,r)=>{const f=`h-${t}-${r}-${i.role}`;if(i.role==="user"){const g=i.skillNames&&i.skillNames.length>0?i.skillNames:i.skillIds&&i.skillIds.length>0?i.skillIds:void 0;return{id:f,role:"user",content:i.content,skillNames:g}}return{id:f,role:"assistant",blocks:i.content?[{type:"text",text:i.content}]:[]}})}function rt(t){const[s,i]=c.useState(t.initialMarkdown),[r,f]=c.useState(null),[g]=c.useState(t.initialMarkdown),[p,N]=c.useState(t.displayName||"未命名"),[k,h]=c.useState([]),[j,u]=c.useState(null),[E,y]=c.useState([]),[R,F]=c.useState(!1),[m,b]=c.useState(!1),[P,$]=c.useState(""),[H,K]=c.useState([]),[A,J]=c.useState(!1),[C,W]=c.useState(null),[V,q]=c.useState(null),[G,l]=c.useState(!1),[x,S]=c.useState(null),I=c.useRef(null),v=c.useRef(null),T=c.useRef(null),D=c.useRef(!0),[Z,ee]=c.useState(!1),se=120;function ie(n){return n.scrollHeight-n.scrollTop-n.clientHeight}function Y(){const n=T.current;n&&(n.scrollTop=n.scrollHeight,ee(!1))}function ke(){D.current&&Y()}function pe(){const n=T.current;if(!n)return;const o=ie(n);D.current=o<=48,ee(o>se)}function ye(){D.current=!0,Y()}c.useLayoutEffect(()=>{if(!t.open)return;ke();const n=T.current;n&&ee(ie(n)>se)},[k,t.open]);async function X(){F(!0);try{const n=await Le("coding",t.documentId);y(n.sessions),j||u(n.lastOpenedSessionId)}catch{}finally{F(!1)}}async function ae(){try{const n=await de();W(n)}catch{W({enabled:!1,skillsReady:!1,model:null})}}if(c.useEffect(()=>{var o;if(!t.open){b(!1),(o=v.current)==null||o.abort();return}i(t.initialMarkdown),f(null),N(t.displayName||"未命名"),$(""),q(null),b(!1);let n=!1;return(async()=>{try{const w=await de();n||W(w)}catch{n||W({enabled:!1,skillsReady:!1,model:null})}try{const w=await Me("coding",t.documentId);if(n)return;u(w.sessionId),h(xe(w.sessionId,w.messages))}catch{n||(u(null),h([]))}X()})(),()=>{n=!0}},[t.open,t.initialMarkdown,t.displayName,t.documentId]),c.useEffect(()=>()=>{var n;return(n=v.current)==null?void 0:n.abort()},[]),c.useEffect(()=>{t.open&&m&&X()},[m,t.open,t.documentId]),!t.open)return null;const le=(C==null?void 0:C.reason)==="missing_api_key",we=r!=null&&r!==s?ne(s,r):[];async function je(){var n;if(!A){(n=v.current)==null||n.abort(),q(null),b(!1),J(!1);try{const o=await $e("coding",t.documentId);u(o.sessionId),h([]),$(""),X()}catch(o){q(o instanceof Error?o.message:String(o))}}}async function Ne(n){var o;if(!A){if(n===j){b(!1);return}(o=v.current)==null||o.abort(),q(null);try{const w=await Ee(n,"coding",t.documentId);u(w.sessionId),h(xe(w.sessionId,w.messages)),$(""),b(!1)}catch(w){q(w instanceof Error?w.message:String(w))}}}async function re(){var O;const n=P.trim();if(!n||A)return;if(!(C!=null&&C.enabled)){q("请先配置 API Key");return}(O=v.current)==null||O.abort();const o=new AbortController;v.current=o;const w=ge("u"),M=ge("a");D.current=!0,h(_=>[..._,{id:w,role:"user",content:n,skillNames:H.length>0?[...H]:void 0},{id:M,role:"assistant",blocks:[]}]),$(""),J(!0),q(null),requestAnimationFrame(()=>{Y(),requestAnimationFrame(Y)});const L=_=>{h(a=>a.map(d=>d.id===M&&d.role==="assistant"?{...d,blocks:_(d.blocks)}:d))};try{let _=!1;await qe(n,{mode:"coding",skillNames:H.length>0?H:void 0,documentId:t.documentId,workingMarkdown:s,baseMarkdown:g,signal:o.signal,onEvent:a=>{a.type==="text_delta"?L(d=>Ye(d,a.text)):a.type==="thinking_delta"?L(d=>Xe(d,a.text)):a.type==="markdown_set"?f(a.markdown):a.type==="tool_notice"?L(d=>Q(d,a.text)):a.type==="document_table"?L(d=>Q(d,a.title)):a.type==="document_card"?L(d=>Q(d,`读取文档「${a.title}」`)):a.type==="sources"?a.items.length>0&&L(d=>Q(d,`已阅读 ${a.items.length} 个手册页面`)):a.type==="skill_form_card"?L(d=>[...d,{type:"skill_form_card",requestId:a.requestId,mode:a.mode,title:a.title,currentName:a.currentName,initialName:a.initialName,initialDescription:a.initialDescription,initialBody:a.initialBody,expiresAt:a.expiresAt,status:"open"}]):a.type==="choice_card"?(D.current=!0,L(d=>[...d,{type:"choice_card",requestId:a.requestId,title:a.title,options:a.options,expiresAt:a.expiresAt,status:"open"}])):a.type==="choice_expired"?L(d=>d.map(B=>B.type==="choice_card"&&B.requestId===a.requestId&&B.status==="open"?{...B,status:"expired"}:B)):a.type==="skill_form_expired"?L(d=>d.map(B=>B.type==="skill_form_card"&&B.requestId===a.requestId&&B.status==="open"?{...B,status:"expired"}:B)):a.type==="error"&&(_=!0,q(a.message))}}),!o.signal.aborted&&!_&&K([]),X()}catch(_){o.signal.aborted||q(_ instanceof Error?_.message:String(_))}finally{v.current===o&&(v.current=null),J(!1)}}function oe(n){return new Promise(o=>{I.current=o,S({message:n.message,confirmLabel:n.confirmLabel??"确定",cancelLabel:n.cancelLabel??"返回",danger:n.danger??!1})})}function ce(n){const o=I.current;I.current=null,S(null),o==null||o(n)}async function be(){if(!await oe({message:"是否回写",confirmLabel:"确认",cancelLabel:"返回"}))return;let o=s;we.length>0&&(o=r??s,i(o),f(null)),l(!0);const w=!t.documentId;try{const M=await t.onComplete({markdown:o,documentId:t.documentId,displayName:p.trim()||"未命名"}),L=M&&typeof M=="object"&&typeof M.documentId=="string"?M.documentId.trim():"";if(w&&L&&j)try{await Re(j,L)}catch{}t.onClose()}catch(M){if(M!=null&&M.silent||M instanceof Error&&M.message==="cancelled")return;q(M instanceof Error?M.message:String(M))}finally{l(!1)}}async function Ce(){var n;(s!==g||r!=null)&&!await oe({message:"取消帮写?未写回的修改将丢失。",confirmLabel:"放弃修改",danger:!0})||((n=v.current)==null||n.abort(),t.onClose())}return e.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[e.jsxs("header",{className:"mdocs-ai-write-header",children:[e.jsxs("div",{className:"mdocs-ai-write-header-left",children:[e.jsx("img",{src:Ae,alt:"",className:"mdocs-ai-write-title-logo"}),e.jsx("strong",{children:"帮写"}),e.jsx("input",{className:"mdocs-ai-write-title",value:p,onChange:n=>N(n.target.value),"aria-label":"文档标题"})]}),e.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[e.jsx("button",{type:"button",onClick:()=>void Ce(),disabled:G||x!=null,children:"取消"}),e.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void be(),disabled:G||x!=null,children:G?"写回中…":"完成并写回"})]})]}),e.jsxs("div",{className:"mdocs-ai-write-body",children:[e.jsxs("section",{className:"mdocs-ai-write-chat",children:[e.jsxs("div",{className:"mdocs-ai-write-chat-toolbar",children:[e.jsx("span",{className:"mdocs-ai-write-chat-toolbar-label",children:"对话"}),e.jsxs("div",{className:"mdocs-ai-write-chat-toolbar-actions",children:[e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:A,onClick:()=>void je(),children:e.jsx(Fe,{size:16,strokeWidth:1.8})}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(m?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>b(n=>!n),children:e.jsx(_e,{size:16,strokeWidth:1.8})})]})]}),m?e.jsxs("div",{className:"mdocs-ai-write-history mdocs-agent-panel-history",children:[e.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[e.jsx("span",{children:"历史会话"}),e.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>b(!1),children:"返回对话"})]}),R?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):E.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):e.jsx("ul",{className:"mdocs-agent-panel-history-list",children:E.map(n=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(n.id===j?" active":""),disabled:A,onClick:()=>void Ne(n.id),children:[e.jsx("span",{className:"mdocs-agent-panel-history-title",children:n.title}),e.jsx("span",{className:"mdocs-agent-panel-history-time",children:Ze(n.updatedAt)})]})},n.id))})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-ai-write-chat-scroll-wrap",children:[e.jsx("div",{className:"mdocs-ai-write-chat-messages",ref:T,onScroll:pe,children:k.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mdocs-ai-write-hint",children:"描述你想写或改的内容。助手可读取右侧当前稿与进场快照,再更新提案;请按段接受或拒绝后完成写回。"}),le?e.jsx(ue,{onConfigured:ae}):null]}):k.map(n=>e.jsx("div",{className:"mdocs-ai-write-msg"+(n.role==="user"?" mdocs-ai-write-msg-user":""),children:n.role==="user"?e.jsxs(e.Fragment,{children:[n.skillNames&&n.skillNames.length>0?e.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",n.skillNames.length]}):null,n.content]}):Qe(n.blocks)?e.jsx("div",{className:"mdocs-ai-write-timeline",children:n.blocks.map((o,w)=>o.type==="thinking"?o.text?e.jsxs("details",{className:"mdocs-ai-write-thinking",open:A,children:[e.jsx("summary",{children:"思考中"}),e.jsx("pre",{className:"mdocs-ai-write-thinking-body",children:o.text})]},`${n.id}-think-${w}`):null:o.type==="tool"?e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:o.text},`${n.id}-tool-${w}`):o.type==="skill_form_card"?e.jsx(Pe,{block:o,onResolved:(M,L,O)=>{h(_=>_.map(a=>a.id!==n.id||a.role!=="assistant"?a:{...a,blocks:a.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===M?{...d,status:L,submittedName:L==="submitted"?O:d.submittedName}:d)}))}},`${n.id}-sf-${w}`):o.type==="choice_card"?e.jsx(Oe,{block:o,onResolved:(M,L,O)=>{h(_=>_.map(a=>a.id!==n.id||a.role!=="assistant"?a:{...a,blocks:a.blocks.map(d=>d.type==="choice_card"&&d.requestId===M?{...d,status:O,selected:O==="selected"?L:d.selected}:d)}))}},`${n.id}-ch-${w}`):o.type==="text"&&o.text?e.jsx("div",{className:"mdocs-agent-panel-md",children:e.jsx(He,{remarkPlugins:[Ke],children:o.text})},`${n.id}-text-${w}`):null)}):A?e.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null},n.id))}),Z?e.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:ye,title:"回到底部","aria-label":"回到底部",children:[e.jsx(De,{size:14,strokeWidth:2,"aria-hidden":!0}),e.jsx("span",{children:"置底"})]}):null]}),V?e.jsx("p",{className:"mdocs-ai-write-error",children:V}):null,le&&k.length>0?e.jsx(ue,{onConfigured:ae}):null,e.jsxs("div",{className:"mdocs-ai-write-input-row",children:[e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:6},children:[e.jsx(Be,{selectedNames:H,onChange:K,disabled:A||!(C!=null&&C.enabled)}),e.jsx("textarea",{rows:2,value:P,disabled:A||!(C!=null&&C.enabled),placeholder:C!=null&&C.enabled?"说说要写什么…":"请先配置 API Key",onChange:n=>$(n.target.value),onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),re())}})]}),e.jsx("button",{type:"button",className:A?"mdocs-ai-write-stop":void 0,disabled:A?!1:!(C!=null&&C.enabled),onClick:()=>{var n;if(A){(n=v.current)==null||n.abort();return}re()},children:A?"停止":"发送"})]})]})]}),e.jsx(Ve,{currentMd:s,proposedMd:r,sending:A,onCurrentChange:i,onProposedChange:f})]}),x?e.jsx(Te,{message:x.message,confirmLabel:x.confirmLabel,cancelLabel:x.cancelLabel,danger:x.danger,onConfirm:()=>ce(!0),onCancel:()=>ce(!1)}):null]})}export{rt as AiWriteWorkbench};
@@ -1,2 +1,2 @@
1
- import{Q as I,S as H,T as F,U as O,V as G}from"./react-Bf45libg.js";import{r as c,j as e}from"./react-vendor-BuABiQkA.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-SYn2XtSh.js";import{M as _}from"./meta2d-1-g23JOU.js";import"./editor-CL03se2B.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./index-CUdIA5aE.js";import"./plus-QDhBbIRF.js";import"./check-CN9m0reb.js";import"./copy-DFs3qk19.js";let q=0;const P=new Set;function $(n){return P.add(n),()=>{P.delete(n)}}function M(){return q}function J(){q++,P.forEach(n=>n())}function z(n){let t=null;try{const[r]=I();t=r}catch{}const i=t;if(!i)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore($,M,M),{setLocale:c.useCallback(r=>{i.setLocale(r),J()},[i]),t:c.useCallback((r,u)=>i.t(r,u),[i])}}const K={Activity:"meta2d.palette.groups.activity",Basic:"meta2d.palette.groups.basic","Fault tree":"meta2d.palette.groups.faultTree",Flow:"meta2d.palette.groups.flow","Sequence & class":"meta2d.palette.groups.sequenceClass"};function W(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function U(){return[{group:"Basic",key:"square",label:"Square",pen:{...s,height:100,name:"square",text:"",width:100}},{group:"Basic",key:"rect",label:"Rectangle",pen:{...s,name:"rectangle",text:"Rectangle"}},{group:"Basic",key:"roundRect",label:"Rounded",pen:{...s,borderRadius:.2,name:"rectangle",text:"Rounded"}},{group:"Basic",key:"circle",label:"Circle",pen:{...s,height:80,name:"circle",text:"Circle",width:80}},{group:"Basic",key:"triangle",label:"Triangle",pen:{...s,height:90,name:"triangle",text:"Triangle",width:100}},{group:"Basic",key:"diamond",label:"Diamond",pen:{...s,height:100,name:"diamond",text:"Decision",width:100}},{group:"Basic",key:"pentagon",label:"Pentagon",pen:{...s,height:100,name:"pentagon",text:"Pentagon",width:100}},{group:"Basic",key:"hexagon",label:"Hexagon",pen:{...s,height:100,name:"hexagon",text:"Hexagon",width:100}},{group:"Basic",key:"pentagram",label:"Star",pen:{...s,height:100,name:"pentagram",text:"",width:100}},{group:"Basic",key:"leftArrow",label:"Left arrow",pen:{height:60,name:"leftArrow",width:120}},{group:"Basic",key:"rightArrow",label:"Right arrow",pen:{height:60,name:"rightArrow",width:120}},{group:"Basic",key:"twowayArrow",label:"Two-way",pen:{height:60,name:"twowayArrow",width:150}},{group:"Basic",key:"cloud",label:"Cloud",pen:{height:100,name:"cloud",width:100}},{group:"Basic",key:"message",label:"Message",pen:{height:100,name:"message",textTop:-.1,width:100}},{group:"Basic",key:"file",label:"File",pen:{height:100,name:"file",width:80}},{group:"Basic",key:"cube",label:"Cube",pen:{height:100,name:"cube",width:60,z:.25}},{group:"Basic",key:"people",label:"Actor",pen:{height:100,name:"people",width:70}},{group:"Basic",key:"text",label:"Text",pen:{...s,background:"transparent",color:"transparent",height:32,name:"text",text:"text",width:120}},{group:"Basic",key:"line",label:"Line",pen:{color:"#1f1f1f",height:1,lineWidth:1,name:"line",width:160}},{group:"Flow",key:"flowTerminal",label:"Terminal",pen:{...s,borderRadius:.5,height:40,name:"rectangle",text:"Start / End",width:120}},{group:"Flow",key:"flowProcess",label:"Process",pen:{...s,height:40,name:"rectangle",text:"Process",width:120}},{group:"Flow",key:"flowDecision",label:"Decision",pen:{...s,height:60,name:"diamond",text:"Decision",width:120}},{group:"Flow",key:"flowData",label:"Data",pen:{...s,name:"flowData",offsetX:.14,text:"Data"}},{group:"Flow",key:"flowPrepare",label:"Prepare",pen:{...s,height:50,name:"hexagon",text:"Prepare",width:120}},{group:"Flow",key:"flowSubprocess",label:"Subprocess",pen:{...s,height:50,name:"flowSubprocess",text:"Subprocess",width:120}},{group:"Flow",key:"flowDb",label:"Database",pen:{...s,height:100,name:"flowDb",text:"DB",width:80}},{group:"Flow",key:"flowDocument",label:"Document",pen:{...s,height:100,name:"flowDocument",text:"Document",width:120}},{group:"Flow",key:"flowInternalStorage",label:"Int. storage",pen:{...s,height:80,name:"flowInternalStorage",text:"Internal",width:120}},{group:"Flow",key:"flowExternStorage",label:"Ext. storage",pen:{...s,height:80,name:"flowExternStorage",text:"External",width:120}},{group:"Flow",key:"flowQueue",label:"Queue",pen:{...s,height:100,name:"flowQueue",text:"Queue",width:100}},{group:"Flow",key:"flowManually",label:"Manual input",pen:{...s,height:80,name:"flowManually",text:"Manual",width:120}},{group:"Flow",key:"flowDisplay",label:"Display",pen:{...s,height:80,name:"flowDisplay",text:"Display",width:120}},{group:"Flow",key:"flowParallel",label:"Parallel",pen:{...s,height:50,name:"flowParallel",text:"Parallel",width:120}},{group:"Flow",key:"flowComment",label:"Comment",pen:{...s,height:100,name:"flowComment",text:"Note",width:100}},{group:"Activity",key:"actStart",label:"Start",pen:{background:"#555",height:30,lineWidth:0,name:"circle",text:"",width:30}},{group:"Activity",key:"actFinal",label:"Final",pen:{height:30,name:"activityFinal",width:30}},{group:"Activity",key:"actStep",label:"Action",pen:{...s,borderRadius:.25,height:50,name:"rectangle",text:"Action",width:120}},{group:"Activity",key:"actMerge",label:"Merge",pen:{...s,height:50,name:"diamond",text:"Merge",width:120}},{group:"Activity",key:"swimlaneV",label:"Swimlane V",pen:{height:500,lineTop:.08,name:"swimlaneV",text:"Swimlane",textBaseline:"top",textTop:20,width:200}},{group:"Activity",key:"swimlaneH",label:"Swimlane H",pen:{height:200,lineLeft:.08,name:"swimlaneH",text:"Swimlane",textAlign:"left",textLeft:.04,textWidth:.01,width:500}},{group:"Activity",key:"forkV",label:"Fork V",pen:{fillStyle:"#555",height:150,name:"forkV",strokeStyle:"transparent",text:"",width:10}},{group:"Activity",key:"forkH",label:"Fork H",pen:{fillStyle:"#555",height:10,name:"forkH",strokeStyle:"transparent",text:"",width:150}},{group:"Sequence & class",key:"lifeline",label:"Lifeline",pen:{height:400,name:"lifeline",text:"Object",textHeight:50,width:150}},{group:"Sequence & class",key:"sequenceFocus",label:"Activation",pen:{height:200,name:"sequenceFocus",text:"",width:12}},{group:"Sequence & class",key:"simpleClass",label:"Simple class",pen:{height:200,list:[{text:`- name: string
1
+ import{Q as I,S as H,T as F,U as O,V as G}from"./react-BXGUMaBS.js";import{r as c,j as e}from"./react-vendor-BuABiQkA.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-BAZUiXoN.js";import{M as _}from"./meta2d-1-g23JOU.js";import"./editor-CL03se2B.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";import"./index-DUu4Is5p.js";import"./plus-C3uXIATM.js";import"./check-CQSGOkW1.js";import"./copy-BMAJ--_Y.js";let q=0;const P=new Set;function $(n){return P.add(n),()=>{P.delete(n)}}function M(){return q}function J(){q++,P.forEach(n=>n())}function z(n){let t=null;try{const[r]=I();t=r}catch{}const i=t;if(!i)throw new Error("[useEditorLocale] No editor found. Pass an editor instance or use this hook inside an <Editor> tree.");return c.useSyncExternalStore($,M,M),{setLocale:c.useCallback(r=>{i.setLocale(r),J()},[i]),t:c.useCallback((r,u)=>i.t(r,u),[i])}}const K={Activity:"meta2d.palette.groups.activity",Basic:"meta2d.palette.groups.basic","Fault tree":"meta2d.palette.groups.faultTree",Flow:"meta2d.palette.groups.flow","Sequence & class":"meta2d.palette.groups.sequenceClass"};function W(n){return`meta2d.palette.${n}`}const s={background:"#fff",color:"#1f1f1f",height:60,lineWidth:1,textColor:"#1f1f1f",width:120};function U(){return[{group:"Basic",key:"square",label:"Square",pen:{...s,height:100,name:"square",text:"",width:100}},{group:"Basic",key:"rect",label:"Rectangle",pen:{...s,name:"rectangle",text:"Rectangle"}},{group:"Basic",key:"roundRect",label:"Rounded",pen:{...s,borderRadius:.2,name:"rectangle",text:"Rounded"}},{group:"Basic",key:"circle",label:"Circle",pen:{...s,height:80,name:"circle",text:"Circle",width:80}},{group:"Basic",key:"triangle",label:"Triangle",pen:{...s,height:90,name:"triangle",text:"Triangle",width:100}},{group:"Basic",key:"diamond",label:"Diamond",pen:{...s,height:100,name:"diamond",text:"Decision",width:100}},{group:"Basic",key:"pentagon",label:"Pentagon",pen:{...s,height:100,name:"pentagon",text:"Pentagon",width:100}},{group:"Basic",key:"hexagon",label:"Hexagon",pen:{...s,height:100,name:"hexagon",text:"Hexagon",width:100}},{group:"Basic",key:"pentagram",label:"Star",pen:{...s,height:100,name:"pentagram",text:"",width:100}},{group:"Basic",key:"leftArrow",label:"Left arrow",pen:{height:60,name:"leftArrow",width:120}},{group:"Basic",key:"rightArrow",label:"Right arrow",pen:{height:60,name:"rightArrow",width:120}},{group:"Basic",key:"twowayArrow",label:"Two-way",pen:{height:60,name:"twowayArrow",width:150}},{group:"Basic",key:"cloud",label:"Cloud",pen:{height:100,name:"cloud",width:100}},{group:"Basic",key:"message",label:"Message",pen:{height:100,name:"message",textTop:-.1,width:100}},{group:"Basic",key:"file",label:"File",pen:{height:100,name:"file",width:80}},{group:"Basic",key:"cube",label:"Cube",pen:{height:100,name:"cube",width:60,z:.25}},{group:"Basic",key:"people",label:"Actor",pen:{height:100,name:"people",width:70}},{group:"Basic",key:"text",label:"Text",pen:{...s,background:"transparent",color:"transparent",height:32,name:"text",text:"text",width:120}},{group:"Basic",key:"line",label:"Line",pen:{color:"#1f1f1f",height:1,lineWidth:1,name:"line",width:160}},{group:"Flow",key:"flowTerminal",label:"Terminal",pen:{...s,borderRadius:.5,height:40,name:"rectangle",text:"Start / End",width:120}},{group:"Flow",key:"flowProcess",label:"Process",pen:{...s,height:40,name:"rectangle",text:"Process",width:120}},{group:"Flow",key:"flowDecision",label:"Decision",pen:{...s,height:60,name:"diamond",text:"Decision",width:120}},{group:"Flow",key:"flowData",label:"Data",pen:{...s,name:"flowData",offsetX:.14,text:"Data"}},{group:"Flow",key:"flowPrepare",label:"Prepare",pen:{...s,height:50,name:"hexagon",text:"Prepare",width:120}},{group:"Flow",key:"flowSubprocess",label:"Subprocess",pen:{...s,height:50,name:"flowSubprocess",text:"Subprocess",width:120}},{group:"Flow",key:"flowDb",label:"Database",pen:{...s,height:100,name:"flowDb",text:"DB",width:80}},{group:"Flow",key:"flowDocument",label:"Document",pen:{...s,height:100,name:"flowDocument",text:"Document",width:120}},{group:"Flow",key:"flowInternalStorage",label:"Int. storage",pen:{...s,height:80,name:"flowInternalStorage",text:"Internal",width:120}},{group:"Flow",key:"flowExternStorage",label:"Ext. storage",pen:{...s,height:80,name:"flowExternStorage",text:"External",width:120}},{group:"Flow",key:"flowQueue",label:"Queue",pen:{...s,height:100,name:"flowQueue",text:"Queue",width:100}},{group:"Flow",key:"flowManually",label:"Manual input",pen:{...s,height:80,name:"flowManually",text:"Manual",width:120}},{group:"Flow",key:"flowDisplay",label:"Display",pen:{...s,height:80,name:"flowDisplay",text:"Display",width:120}},{group:"Flow",key:"flowParallel",label:"Parallel",pen:{...s,height:50,name:"flowParallel",text:"Parallel",width:120}},{group:"Flow",key:"flowComment",label:"Comment",pen:{...s,height:100,name:"flowComment",text:"Note",width:100}},{group:"Activity",key:"actStart",label:"Start",pen:{background:"#555",height:30,lineWidth:0,name:"circle",text:"",width:30}},{group:"Activity",key:"actFinal",label:"Final",pen:{height:30,name:"activityFinal",width:30}},{group:"Activity",key:"actStep",label:"Action",pen:{...s,borderRadius:.25,height:50,name:"rectangle",text:"Action",width:120}},{group:"Activity",key:"actMerge",label:"Merge",pen:{...s,height:50,name:"diamond",text:"Merge",width:120}},{group:"Activity",key:"swimlaneV",label:"Swimlane V",pen:{height:500,lineTop:.08,name:"swimlaneV",text:"Swimlane",textBaseline:"top",textTop:20,width:200}},{group:"Activity",key:"swimlaneH",label:"Swimlane H",pen:{height:200,lineLeft:.08,name:"swimlaneH",text:"Swimlane",textAlign:"left",textLeft:.04,textWidth:.01,width:500}},{group:"Activity",key:"forkV",label:"Fork V",pen:{fillStyle:"#555",height:150,name:"forkV",strokeStyle:"transparent",text:"",width:10}},{group:"Activity",key:"forkH",label:"Fork H",pen:{fillStyle:"#555",height:10,name:"forkH",strokeStyle:"transparent",text:"",width:150}},{group:"Sequence & class",key:"lifeline",label:"Lifeline",pen:{height:400,name:"lifeline",text:"Object",textHeight:50,width:150}},{group:"Sequence & class",key:"sequenceFocus",label:"Activation",pen:{height:200,name:"sequenceFocus",text:"",width:12}},{group:"Sequence & class",key:"simpleClass",label:"Simple class",pen:{height:200,list:[{text:`- name: string
2
2
  + setName(name: string): void`}],name:"simpleClass",text:"ClassName",textAlign:"center",textBaseline:"top",textHeight:200,textTop:10,width:270}},{group:"Sequence & class",key:"interfaceClass",label:"Class",pen:{height:200,list:[{text:"- name: string"},{text:"+ setName(name: string): void"}],name:"interfaceClass",text:"ClassName",textAlign:"center",textBaseline:"top",textHeight:200,textTop:10,width:270}},{group:"Fault tree",key:"andGate",label:"AND gate",pen:{height:150,name:"andGate",width:100}},{group:"Fault tree",key:"orGate",label:"OR gate",pen:{height:150,name:"orGate",width:100}},{group:"Fault tree",key:"basicEvent",label:"Basic event",pen:{height:150,name:"basicEvent",width:100}},{group:"Fault tree",key:"xorGate",label:"XOR gate",pen:{height:150,name:"xorGate",width:100}},{group:"Fault tree",key:"votingGate",label:"Voting gate",pen:{height:150,name:"votingGate",width:100}}]}function V(n){return G(structuredClone(n))}function Z(n){const t=new Map;for(const i of n){const r=t.get(i.group)??[];r.push(i),t.set(i.group,r)}return Array.from(t.entries())}function ee({name:n}){const t={fill:"#fff",stroke:"#1f1f1f",strokeWidth:1.2};return n==="circle"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("circle",{cx:"14",cy:"14",r:"10",...t})}):n==="diamond"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 25,14 14,25 3,14",...t})}):n==="triangle"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,4 25,24 3,24",...t})}):n==="pentagon"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 25,12 21,25 7,25 3,12",...t})}):n==="hexagon"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"8,4 20,4 25,14 20,24 8,24 3,14",...t})}):n==="pentagram"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("polygon",{points:"14,3 17,11 26,11 18,16 21,25 14,20 7,25 10,16 2,11 11,11",...t})}):n==="line"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("line",{x1:"4",x2:"24",y1:"14",y2:"14",...t})}):n==="text"?e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("text",{dominantBaseline:"middle",fill:"#1f1f1f",fontSize:"14",textAnchor:"middle",x:"14",y:"15",children:"T"})}):e.jsx("svg",{height:"24",viewBox:"0 0 28 28",width:"24",children:e.jsx("rect",{height:"14",rx:"2",width:"20",x:"4",y:"7",...t})})}function te({disabled:n,engineRef:t,item:i,t:r}){const u=()=>{const a=t.current;if(!(!a||n))try{a.canvas.addCaches=[V(i.pen)]}catch{}};return e.jsxs("div",{draggable:!n,onClick:a=>{a.stopPropagation(),u()},onDragStart:a=>{if(n){a.preventDefault();return}const f=JSON.stringify(V(i.pen));a.dataTransfer.setData("Meta2d",f),a.dataTransfer.setData("Text",f),a.dataTransfer.effectAllowed="copy"},onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),u())},role:"button",style:{alignItems:"center",border:"1px solid #efefef",borderRadius:6,cursor:n?"not-allowed":"grab",display:"flex",flexDirection:"column",gap:4,justifyContent:"center",minHeight:56,opacity:n?.5:1,outline:"none",padding:6},tabIndex:n?-1:0,title:`${r(W(i.key))||i.label} — drag or click to add`,children:[e.jsx(ee,{name:String(i.pen.name??"rectangle")}),e.jsx("span",{style:{fontSize:11},children:r(W(i.key))||i.label})]})}function ne({disabled:n,engineRef:t}){const{t:i}=z(),r=c.useMemo(()=>Z(U()),[]);return e.jsxs("aside",{style:{borderRight:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",padding:12,touchAction:"pan-y",width:240},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,marginBottom:4},children:i("meta2d.palette.title")}),e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:12},children:i("meta2d.palette.hint")}),r.map(([u,a])=>e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{color:"#8c8c8c",fontSize:12,marginBottom:6},children:i(K[u]||u)}),e.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"repeat(2, minmax(0, 1fr))"},children:a.map(f=>e.jsx(te,{disabled:n,engineRef:t,item:f,t:i},f.key))})]},u))]})}const N={borderLeft:"1px solid #f0f0f0",flexShrink:0,maxHeight:"100%",overflowX:"hidden",overflowY:"auto",overscrollBehavior:"contain",touchAction:"pan-y",width:220},A={color:"#8c8c8c",fontSize:12,marginBottom:4},D={borderBottom:"1px solid #f0f0f0",padding:"10px 12px"},y={alignItems:"center",display:"flex",gap:6,marginBottom:6},w={background:"#fafafa",border:"1px solid #e5e5e5",borderRadius:4,fontSize:12,height:28,outline:"none",padding:"0 6px"},b={color:"#8c8c8c",fontSize:11,minWidth:22},T={background:"#fff",border:"1px solid #d9d9d9",borderRadius:4,cursor:"pointer",fontSize:11,minWidth:48,padding:"4px 8px"},le=120;function ie({engine:n}){const{t}=z(),[i,r]=c.useState(null),[u,a]=c.useState(null),[f,v]=c.useState(""),p=c.useRef(null),j=c.useRef(null),B=c.useCallback((l,d)=>{!n||l===null||l===void 0||n.setValue({id:l,text:d},{render:!0})},[n]),k=c.useCallback(l=>{if(!l||l.length!==1){p.current&&(clearTimeout(p.current),p.current=null),r(null),a(null),v(""),j.current=null;return}const d=l[0];if((d.globalAlpha===null||d.globalAlpha===void 0)&&(d.globalAlpha=1),d.id!==j.current&&(p.current&&(clearTimeout(p.current),p.current=null),j.current=d.id,v(d.text??"")),r(d),n)try{a(n.getPenRect(d))}catch{a(null)}},[n]),C=c.useCallback(()=>{p.current&&(clearTimeout(p.current),p.current=null),r(null),a(null),v(""),j.current=null},[]);if(c.useEffect(()=>{if(n)return n.on("active",k),n.on("inactive",C),()=>{n.off("active",k),n.off("inactive",C),p.current&&(clearTimeout(p.current),p.current=null)}},[n,k,C]),!i||!n)return e.jsx("aside",{style:N,children:e.jsx("div",{style:{color:"#bbb",fontSize:12,padding:16,textAlign:"center"},children:t("meta2d.props.empty")})});const h=(l,d)=>{const m={id:i.id};m[l]=d,l==="dash"&&(m.lineDash=[void 0,[5,5]][d]),l!=="text"&&r(S=>S&&{...S,...m}),n.setValue(m,{render:!0})},o=l=>{v(l);const d=i.id;p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{p.current=null,B(d,l)},le)},x=()=>{p.current&&(clearTimeout(p.current),p.current=null),B(i.id,f)},g=(l,d)=>{if(!u)return;const m={id:i.id};m[l]=d,n.setValue(m,{render:!0}),a(S=>S?{...S,[l]:d}:null)},R=l=>{l(n),n.render(!0)};return e.jsxs("aside",{style:N,children:[e.jsxs("div",{style:D,children:[e.jsx("div",{style:A,children:t("meta2d.props.text")}),e.jsx("div",{style:y,children:e.jsx("input",{onBlur:x,onChange:l=>o(l.target.value),onKeyDown:l=>{l.stopPropagation(),l.key==="Enter"&&(l.preventDefault(),l.target.blur())},style:{...w,flex:1,width:"100%"},type:"text",value:f})})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.appearance")}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.color")}),e.jsx("input",{onChange:l=>h("color",l.target.value),style:{...w,flex:1},type:"color",value:i.color||"#1f1f1f"})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.bg")}),e.jsx("input",{onChange:l=>h("background",l.target.value),style:{...w,flex:1},type:"color",value:i.background||"#ffffff"})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.dash")}),e.jsxs("select",{onChange:l=>h("dash",Number(l.target.value)),style:{...w,flex:1},value:String(i.dash??0),children:[e.jsx("option",{value:"0",children:t("meta2d.props.solid")}),e.jsx("option",{value:"1",children:t("meta2d.props.dashLine")})]})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.radius")}),e.jsx("input",{max:1,min:0,onChange:l=>h("borderRadius",Number(l.target.value)),step:.01,style:{...w,flex:1},type:"range",value:String(i.borderRadius??0)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:i.borderRadius??0})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.alpha")}),e.jsx("input",{max:1,min:0,onChange:l=>h("globalAlpha",Number(l.target.value)),step:.01,style:{...w,flex:1},type:"range",value:String(i.globalAlpha??1)}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:11,width:32},children:(i.globalAlpha??1).toFixed(2)})]})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.position")}),[["X","x"],["Y","y"],["W","width"],["H","height"]].map(([l,d])=>e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:l}),e.jsx("input",{onChange:m=>g(d,Number(m.target.value)),style:{...w,flex:1},type:"number",value:u?u[d]:0})]},d))]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.textAlign")}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.h")}),e.jsxs("select",{onChange:l=>h("textAlign",l.target.value),style:{...w,flex:1},value:i.textAlign||"center",children:[e.jsx("option",{value:"left",children:t("meta2d.props.left")}),e.jsx("option",{value:"center",children:t("meta2d.props.center")}),e.jsx("option",{value:"right",children:t("meta2d.props.right")})]})]}),e.jsxs("div",{style:y,children:[e.jsx("span",{style:b,children:t("meta2d.props.v")}),e.jsxs("select",{onChange:l=>h("textBaseline",l.target.value),style:{...w,flex:1},value:i.textBaseline||"middle",children:[e.jsx("option",{value:"top",children:t("meta2d.props.topAlign")}),e.jsx("option",{value:"middle",children:t("meta2d.props.middle")}),e.jsx("option",{value:"bottom",children:t("meta2d.props.bottomAlign")})]})]})]}),e.jsxs("div",{style:D,children:[e.jsx("div",{style:{...A,marginBottom:6},children:t("meta2d.props.layer")}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:[e.jsx("button",{onClick:()=>R(l=>l.top()),style:T,type:"button",children:t("meta2d.props.top")}),e.jsx("button",{onClick:()=>R(l=>l.up()),style:T,type:"button",children:t("meta2d.props.up")}),e.jsx("button",{onClick:()=>R(l=>l.down()),style:T,type:"button",children:t("meta2d.props.down")}),e.jsx("button",{onClick:()=>R(l=>l.bottom()),style:T,type:"button",children:t("meta2d.props.bottom")})]})]})]})}const L={background:"#fff",border:"1px solid #d9d9d9",borderRadius:6,cursor:"pointer",minWidth:68,padding:"6px 12px"},E={...L,fontSize:12,minWidth:52,padding:"4px 10px"};function re(n){c.useEffect(()=>{const t=document.documentElement,i=document.body,r=t.style.overflow,u=i.style.overflow;return t.style.overflow="hidden",i.style.overflow="hidden",()=>{t.style.overflow=r,i.style.overflow=u}},[n])}function ye({diagram:n,onClose:t,onSave:i}){const{t:r}=z(),u=c.useRef(null),a=c.useRef(null),f=c.useRef(n),v=c.useRef(t),[p,j]=c.useState(null),[B,k]=c.useState(!1);re(!0),c.useLayoutEffect(()=>{v.current=t}),c.useEffect(()=>{if(!u.current)return;X();const o=new _(u.current,{grid:!0,rule:!1});a.current=o,j(o);try{const g=f.current;g!=null&&g.trim()?o.open(JSON.parse(g)):o.open(H()),F(o.data()),o.render(!0)}catch{o.open(H()),F(o.data()),o.render(!0)}const x=g=>{g.key==="Escape"&&v.current()};return window.addEventListener("keydown",x),()=>{window.removeEventListener("keydown",x);try{o.destroy()}catch{}a.current=null}},[]);const C=async()=>{const o=a.current;if(o){k(!0);try{F(o.data()),o.render(!0);const x=O(o.data()),g=JSON.stringify(x);i(g,await Q(o)||await Y(g)||'<svg xmlns="http://www.w3.org/2000/svg" width="320" height="180" viewBox="0 0 320 180"><rect width="100%" height="100%" fill="#fafafa" stroke="#eee"/></svg>')}finally{k(!1)}}},h=o=>{const x=a.current;x&&o(x)};return e.jsx("div",{onClick:t,style:{alignItems:"center",background:"rgb(0 0 0 / 35%)",display:"flex",inset:0,justifyContent:"center",overflow:"hidden",position:"fixed",zIndex:1e3},children:e.jsxs("div",{onClick:o=>o.stopPropagation(),onWheel:o=>o.stopPropagation(),style:{background:"#fff",borderRadius:10,boxShadow:"0 12px 30px rgb(0 0 0 / 20%)",display:"flex",flexDirection:"column",height:"86vh",maxHeight:"100%",maxWidth:"1200px",overflow:"hidden",width:"92vw"},children:[e.jsxs("div",{style:{alignItems:"center",borderBottom:"1px solid #f0f0f0",display:"flex",flexWrap:"wrap",gap:8,justifyContent:"space-between",padding:"10px 14px"},children:[e.jsx("span",{style:{fontWeight:600},children:r("meta2d.editor.title")}),e.jsxs("div",{style:{alignItems:"center",display:"flex",flexWrap:"wrap",gap:8},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:[e.jsx("button",{onClick:()=>h(o=>o.undo()),style:E,title:`${r("meta2d.editor.undo")} (Ctrl+Z)`,type:"button",children:r("meta2d.editor.undo")}),e.jsx("button",{onClick:()=>h(o=>o.redo()),style:E,title:`${r("meta2d.editor.redo")} (Ctrl+Y)`,type:"button",children:r("meta2d.editor.redo")}),e.jsx("button",{onClick:()=>h(o=>o.delete()),style:E,title:r("meta2d.editor.delete"),type:"button",children:r("meta2d.editor.delete")}),e.jsx("button",{onClick:()=>h(o=>o.fitView(!0)),style:E,title:r("meta2d.editor.fit"),type:"button",children:r("meta2d.editor.fit")}),e.jsx("button",{onClick:()=>h(o=>{o.scale(1),o.centerView()}),style:E,title:r("meta2d.editor.zoom100"),type:"button",children:r("meta2d.editor.zoom100")})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{onClick:t,style:L,type:"button",children:r("meta2d.editor.close")}),e.jsx("button",{disabled:B,onClick:()=>void C(),style:{...L,background:"#1677ff",border:"none",color:"#fff"},type:"button",children:r(B?"meta2d.editor.saving":"meta2d.editor.save")})]})]})]}),e.jsxs("div",{style:{display:"flex",flex:1,minHeight:0,overflow:"hidden"},children:[e.jsx(ne,{engineRef:a}),e.jsx("div",{ref:u,style:{flex:1,minHeight:0,minWidth:0}}),e.jsx(ie,{engine:p})]})]})})}export{ye as DiagramEditor};
@@ -1,4 +1,4 @@
1
- import{o as d,c as v,F as D,P as M,p as x,l as k,R as j,E as B,q as P,S as E,M as S}from"./index-CUdIA5aE.js";import{r as I,j as n}from"./react-vendor-BuABiQkA.js";import{g as W}from"./file-type-policy-GUk904tm.js";/**
1
+ import{o as d,c as v,F as D,P as M,p as x,l as k,R as j,E as B,q as P,S as E,M as S}from"./index-DUu4Is5p.js";import{r as I,j as n}from"./react-vendor-BuABiQkA.js";import{g as W}from"./file-type-policy-GUk904tm.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.