@fgbg/mdocs 1.3.24 → 1.3.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-skills/changelog/SKILL.md +16 -0
- package/dist/web/assets/{AgentChatPanel-NcsMAhWM.js → AgentChatPanel-TJVgAwlH.js} +3 -3
- package/dist/web/assets/{AgentSkillFormCard-B99CncJO.js → AgentSkillFormCard-3ZpgH1RY.js} +2 -2
- package/dist/web/assets/{AiWriteWorkbench-DomEbwzU.js → AiWriteWorkbench-B9HrhEmd.js} +4 -4
- package/dist/web/assets/{DiagramEditor-NtNY3sZL-BhsjOCtK.js → DiagramEditor-NtNY3sZL-CyddeNUo.js} +1 -1
- package/dist/web/assets/DocChrome-C5syeHbQ.js +11 -0
- package/dist/web/assets/DocumentEditor-mG7hvAWj.js +1 -0
- package/dist/web/assets/{HtmlEditor-g2NNYmv2.js → HtmlEditor-DABDor1R.js} +1 -1
- package/dist/web/assets/{MergeView-GL7xdFM4.js → MergeView-BczHMfos.js} +1 -1
- package/dist/web/assets/{PlaygroundPage-Bb4X1bvp.js → PlaygroundPage-zg5tjWQs.js} +1 -1
- package/dist/web/assets/SettingsPage-BU0is_e7.js +1 -0
- package/dist/web/assets/SheetEditor-4nXVP3NN.js +16 -0
- package/dist/web/assets/{Toolbar-Bk3LKZfg.js → Toolbar-xB4u1mY1.js} +1 -1
- package/dist/web/assets/{VisitorPickerModal-zafJ6beK.js → VisitorPickerModal-Djpm5bTf.js} +1 -1
- package/dist/web/assets/{check-BMeXlsHC.js → check--tqH9AMO.js} +1 -1
- package/dist/web/assets/{copy-CCsiKd_j.js → copy-5mwMd6zK.js} +1 -1
- package/dist/web/assets/{docPlainCharCount-BjBZaoHy.js → docPlainCharCount-CTaZfi-M.js} +1 -1
- package/dist/web/assets/{index-3B7_9QOQ.js → index-CINfyH_g.js} +17 -17
- package/dist/web/assets/index-DCgILSIv.css +1 -0
- package/dist/web/assets/{italic-B6bGjo1_.js → italic-phhei7W3.js} +1 -1
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-9HAADQ7Y.js → meta2dEngine-BD2XbzaV-BDjANcdr.js} +1 -1
- package/dist/web/assets/{plus-BD44y7Zf.js → plus-BxZJ-Mya.js} +1 -1
- package/dist/web/assets/{react-2y9P8xJn.js → react-8gAAnUbI.js} +5 -5
- package/dist/web/index.html +2 -2
- package/package.json +2 -2
- package/dist/web/assets/DocChrome-wfHrPEB7.js +0 -11
- package/dist/web/assets/DocumentEditor-CCuqHlmF.js +0 -1
- package/dist/web/assets/SettingsPage-B4INgMK-.js +0 -1
- package/dist/web/assets/SheetEditor-Cka57s62.js +0 -16
- package/dist/web/assets/index-BF754bDB.css +0 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
面向个人开发者与小团队:产品内 **智能助手 + 帮写**,外部 **CLI / Skills** 接入 Cursor / Claude;SQLite + 本地文件,**无账户**即可协作。
|
|
6
6
|
|
|
7
|
-
[文档站点](https://xuhuafeifei.github.io/mdocs-site/) · [GitHub](https://github.com/xuhuafeifei/mdocs) · [npm `@fgbg/mdocs`](https://www.npmjs.com/package/@fgbg/mdocs) · 当前版本 **1.3.
|
|
7
|
+
[文档站点](https://xuhuafeifei.github.io/mdocs-site/) · [GitHub](https://github.com/xuhuafeifei/mdocs) · [npm `@fgbg/mdocs`](https://www.npmjs.com/package/@fgbg/mdocs) · 当前版本 **1.3.26**
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
10
|
<img src="image/site主页.png" alt="mdocs 文档站点首页" width="860" />
|
|
@@ -10,6 +10,22 @@ source: changelog.md
|
|
|
10
10
|
|
|
11
11
|
现行文档里,产品概念「域」已改称 **工作空间**。下面各版本仍按当时的叫法记录。
|
|
12
12
|
|
|
13
|
+
## v1.3.26
|
|
14
|
+
|
|
15
|
+
同 v1.3.25(npm 上 1.3.25 卡在 processing,改发此版本)。
|
|
16
|
+
|
|
17
|
+
## v1.3.25
|
|
18
|
+
|
|
19
|
+
### 编辑器
|
|
20
|
+
- 升级 `@fgbg/lobe-editor@1.0.0-fork.23`
|
|
21
|
+
- **Qwen / 网页渲染 Markdown 粘贴**:优先使用剪贴板 rich HTML(标题、列表等),不再被弱 `text/plain`(仅残留 `**粗体**`)抢走 Markdown 确认框而变成扁文本
|
|
22
|
+
- **Shift 扩展选区 / 全选**:视口不再被选区 bounding box 拽动;回车跟滚仍保留
|
|
23
|
+
|
|
24
|
+
## v1.3.24
|
|
25
|
+
|
|
26
|
+
### 编辑器
|
|
27
|
+
- 升级 `@fgbg/lobe-editor@1.0.0-fork.22`(Enter 靠近视口底部时光标跟随滚动;代码块内粘贴跳过 Markdown 确认,避免取消后双份内容)
|
|
28
|
+
|
|
13
29
|
## v1.3.23
|
|
14
30
|
|
|
15
31
|
### 智能助手会话
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/diagram-BF8g9yg4.js","assets/ui-CEFkTVnG.js","assets/react-vendor-BVS1XoFi.js","assets/motion-BAXVQJfN.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as o,j as e,_ as lt,b as dt}from"./react-vendor-BVS1XoFi.js";import{o as ae,N as Xe,C as ut,
|
|
2
|
+
import{r as o,j as e,_ as lt,b as dt}from"./react-vendor-BVS1XoFi.js";import{o as ae,N as Xe,C as ut,aO as Ke,X as ne,aP as Fe,aQ as mt,Z as Pe,aR as Be,aS as pt,aT as ft,aU as ht,aV as gt,aW as xt,aX as yt,aY as Ue,aZ as jt,a_ as kt,a$ as Nt}from"./index-CINfyH_g.js";import{H as bt,S as vt,A as wt,a as Ct}from"./AgentSkillFormCard-3ZpgH1RY.js";import{C as Ye}from"./check--tqH9AMO.js";import{C as Ge}from"./copy-5mwMd6zK.js";import{P as St}from"./plus-BxZJ-Mya.js";import{ar as _t,ah as At}from"./ui-CEFkTVnG.js";import"./diagram-BF8g9yg4.js";import"./motion-BAXVQJfN.js";/**
|
|
3
3
|
* @license lucide-react v0.562.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
@@ -14,9 +14,9 @@ import{r as o,j as e,_ as lt,b as dt}from"./react-vendor-BVS1XoFi.js";import{o a
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the ISC license.
|
|
16
16
|
* See the LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/const
|
|
17
|
+
*/const $t=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Tt=ae("zoom-in",$t);/**
|
|
18
18
|
* @license lucide-react v0.562.0 - ISC
|
|
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 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 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 l=a.props;if(!(!l||!qt(l.className)))return ke(l.children).replace(/\n$/,"")}return null}const Pt=.4,Bt=4,se=.2;let xe=null;function Lt(){return xe||(xe=lt(()=>import("./diagram-BF8g9yg4.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(Bt,Math.max(Pt,s))}function Ht(s){const[n,a]=o.useState(1),[l,b]=o.useState({x:0,y:0}),g=o.useRef(null),[_,y]=o.useState(!1);o.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),g.current={pointerId:u.pointerId,startX:u.clientX,startY:u.clientY,originX:l.x,originY:l.y},y(!0))}function C(u){const m=g.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=g.current;if(!(!m||m.pointerId!==u.pointerId)){g.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($t,{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% + ${l.x}px), calc(-50% + ${l.y}px)) scale(${n})`},dangerouslySetInnerHTML:{__html:s.svg}})}),e.jsx("p",{className:"mdocs-agent-mermaid-float-hint",children:"拖动平移 · 滚轮缩放 · Esc 关闭"})]})]}),document.body)}function Xt(s){const n=o.useId().replace(/:/g,""),[a,l]=o.useState("diagram"),[b,g]=o.useState(()=>Le(s.source.trim())),[_,y]=o.useState(null),[A,C]=o.useState(!1),[E,N]=o.useState(!1),u=o.useRef(null),m=s.source.trim(),I=o.useMemo(()=>m,[m]);o.useEffect(()=>()=>{u.current!=null&&window.clearTimeout(u.current)},[]),o.useEffect(()=>{if(a!=="diagram")return;if(!I){g(null),y(null);return}const j=Le(I);if(j){g(j),y(null);return}let M=!1;const P=window.setTimeout(()=>{(async()=>{try{const F=await Lt();if(M)return;const $=`mdocs-agent-mmd-${n}-${Date.now()}`,{svg:T}=await F.render($,I);if(M)return;Wt(I,T),g(T),y(null)}catch(F){if(M)return;g(null),y(F instanceof Error?F.message:"Mermaid 渲染失败")}})()},200);return()=>{M=!0,window.clearTimeout(P)}},[a,I,n]);async function H(){!m||!await Ke(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:()=>l("diagram"),"aria-pressed":a==="diagram",title:"图谱",children:[e.jsx(Xe,{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:()=>l("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 Kt=o.memo(Xt,(s,n)=>s.source===n.source);function Ne(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(Ne).join(""):typeof s=="object"&&"props"in s?Ne((n=s.props)==null?void 0:n.children):""}function Ut(s){const[n,a]=o.useState(!1),l=o.useRef(null),b=o.useRef(null),g=Ne(s.children).replace(/\n$/,"");o.useEffect(()=>()=>{l.current!=null&&window.clearTimeout(l.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$/,""))??"")||g;!C||!await Ke(C)||(a(!0),l.current!=null&&window.clearTimeout(l.current),l.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(Kt,{source:n,codeChildren:s.children}):e.jsx(Ut,{children:s.children})}const Gt={pre:({children:s})=>e.jsx(Yt,{children:s})},Oe=o.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 We(s,n){return n.map((a,l)=>{const b=a.skillNames&&a.skillNames.length>0?a.skillNames:a.skillIds&&a.skillIds.length>0?a.skillIds:void 0;return{id:`h-${s}-${l}-${a.role}`,role:a.role,content:a.content,skillNames:b}})}function Zt(s,n){const a=s.slice(),l=a[a.length-1];return(l==null?void 0:l.type)==="text"?a[a.length-1]={type:"text",text:l.text+n}:a.push({type:"text",text:n}),a}function Jt(s,n){const a=s.slice(),l=a[a.length-1];return(l==null?void 0:l.type)==="thinking"?a[a.length-1]={type:"thinking",text:l.text+n}:a.push({type:"thinking",text:n}),a}function je(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,[l,b]=o.useState(""),[g,_]=o.useState(!1),[y,A]=o.useState(1),C=o.useRef(!1),E=o.useRef(a);E.current=a;const N=n.status==="open",u=o.useRef(0);o.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 T=j-Date.now(),p=Math.max(0,Math.min(1,T/P));A(p),T<=0&&!C.current&&(C.current=!0,kt(n.requestId).catch(()=>{}).finally(()=>{E.current(n.requestId,"","expired")}))};F();const $=window.setInterval(F,100);return()=>window.clearInterval($)},[N,n.expiresAt,n.requestId]);async function m(j){const M=j.trim();if(!(!M||g||!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(!(g||!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:g,onClick:()=>void m(j),children:j},j))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:l,disabled:g,placeholder:"或输入自己的内容…",onChange:j=>b(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),m(l))}}),e.jsx("button",{type:"button",disabled:g||!l.trim(),onClick:()=>void m(l),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:g,onClick:()=>void I(),children:"取消"})})]}):null]})}function ss(s){const b=2*Math.PI*8.75,g=Math.min(100,Math.max(0,s.percent)),_=b*(1-g/100),y=g>=90?"danger":g>=70?"warn":"ok",A=`上下文 ${g}% · 已用 ${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 l of a.blocks)if((l.type==="choice_card"||l.type==="skill_form_card")&&l.status==="open")return!0}return!1}const ps=o.forwardRef(function(n,a){const{open:l,onClose:b,visitorName:g,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=((g==null?void 0:g.trim().charAt(0))||"我").toUpperCase(),[$,T]=o.useState(!1),[p,U]=o.useState(null),[Ve,Y]=o.useState(null),[z,w]=o.useState([]),[re,G]=o.useState(null),[be,Ze]=o.useState([]),[Je,ve]=o.useState(!1),[V,Z]=o.useState(""),[K,we]=o.useState([]),[Ce,ie]=o.useState(!1),[v,J]=o.useState(!1),[Se,B]=o.useState(null),[Q,_e]=o.useState(null),[oe,O]=o.useState(!1),[L,Ae]=o.useState(!1),Qe=o.useRef(null),ee=o.useRef(null),D=o.useRef(null),Ie=o.useRef(0),X=o.useRef(!0),[et,ce]=o.useState(!1),le=o.useRef(z);le.current=z;const Me=!!(E!=null&&E.trim())&&!Ce,tt=(N==null?void 0:N.trim())||"当前文档",Re=(u==null?void 0:u.trim())||"",de=!!(m!=null&&m.trim())&&!Ce,st=(I==null?void 0:I.trim())||"当前图谱";o.useEffect(()=>{ie(!1)},[E,m]);function Ee(t){return Ie.current+=1,`${t}-${Ie.current}`}const Te=120;function $e(t){return t.scrollHeight-t.scrollTop-t.clientHeight}function te(){const t=ee.current;t&&(t.scrollTop=t.scrollHeight,ce(!1))}function q(){X.current&&te()}function nt(){const t=ee.current;if(!t)return;const f=$e(t);X.current=f<=48,ce(f>Te)}function at(){X.current=!0,te()}o.useLayoutEffect(()=>{q();const t=ee.current;t&&ce($e(t)>Te)},[z]);async function rt(){ve(!0);try{const t=await ht();Ze(t.sessions),re||G(t.lastOpenedSessionId)}catch{}finally{ve(!1)}}async function ue(){try{const t=await ft();_e(t)}catch{}}async function ze(){try{const t=await Fe();U(t),Y(null)}catch(t){U(null),Y(t instanceof Error?t.message:String(t))}}o.useEffect(()=>{var f;if(!l){T(!1),(f=D.current)==null||f.abort(),D.current=null,J(!1);return}let t=!1;return(async()=>{try{const c=await Fe();t||(U(c),Y(null))}catch(c){t||(U(null),Y(c instanceof Error?c.message:String(c)))}})(),ue(),()=>{t=!0}},[l]),o.useEffect(()=>{if(!l)return;let t=!1;return(async()=>{try{const f=await mt();if(t)return;G(f.sessionId),w(c=>c.length>0?c:We(f.sessionId,f.messages))}catch{}})(),()=>{t=!0}},[l]),o.useEffect(()=>{!l||!$||rt()},[l,$]);function me(){if(!L){if(ns(le.current)){O(!0);return}O(!1),b()}}async function it(){var c;if(L)return;Ae(!0);const t=le.current,f=[];for(const S of t)if(!(S.role!=="assistant"||!S.blocks))for(const x of S.blocks)x.type==="choice_card"&&x.status==="open"&&f.push(Ue(x.requestId).catch(()=>{})),x.type==="skill_form_card"&&x.status==="open"&&f.push(jt(x.requestId).catch(()=>{}));await Promise.all(f),(c=D.current)==null||c.abort(),w(S=>S.map(x=>x.role!=="assistant"||!x.blocks?x:{...x,blocks:x.blocks.map(h=>h.type==="choice_card"&&h.status==="open"?{...h,status:"cancelled"}:h.type==="skill_form_card"&&h.status==="open"?{...h,status:"cancelled"}:h)})),O(!1),Ae(!1),b()}const pe=o.useRef(me);pe.current=me,o.useImperativeHandle(a,()=>({requestClose:()=>pe.current()}),[]),o.useEffect(()=>{if(!l){O(!1);return}const t=f=>{if(f.key==="Escape"){if(oe){L||O(!1);return}if($){T(!1);return}pe.current()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[l,$,oe,L]);async function fe(t){var h;const f=t.trim();if(!f||v)return;if(!(p!=null&&p.enabled)){B((p==null?void 0:p.reason)==="missing_api_key"?"请先配置 API Key":(p==null?void 0:p.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(h=D.current)==null||h.abort();const c=new AbortController;D.current=c;const S={id:Ee("u"),role:"user",content:f,skillNames:K.length>0?[...K]:void 0},x=Ee("a");X.current=!0,w(R=>[...R,S,{id:x,role:"assistant",content:""}]),Z(""),J(!0),B(null),T(!1),requestAnimationFrame(()=>{te(),requestAnimationFrame(te)});try{let R=!1;await yt(f,{skillNames:K.length>0?K:void 0,references:{domainId:(C==null?void 0:C.trim())||void 0,documentId:!de&&Me?E.trim():void 0,graphFileId:de?m.trim():void 0},signal:c.signal,onEvent:i=>{i.type==="text_delta"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=Zt(r.blocks??[],i.text);return{...r,blocks:d,content:je(d)}})),requestAnimationFrame(()=>q())):i.type==="thinking_delta"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=Jt(r.blocks??[],i.text);return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="sources"?(w(k=>k.map(r=>{if(r.id!==x)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:i.items}:d.push({type:"sources",items:i.items}),{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="document_table"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=[...r.blocks??[],{type:"document_table",title:i.title,rows:i.rows}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="document_card"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=[...r.blocks??[],{type:"document_card",documentId:i.documentId,title:i.title,path:i.path,preview:i.preview}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="tool_notice"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=[...r.blocks??[],{type:"tool_notice",toolName:i.toolName,text:i.text}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="choice_card"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=[...r.blocks??[],{type:"choice_card",requestId:i.requestId,title:i.title,options:i.options,expiresAt:i.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="choice_expired"?w(k=>k.map(r=>r.id!==x||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===i.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):i.type==="skill_form_card"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=[...r.blocks??[],{type:"skill_form_card",requestId:i.requestId,mode:i.mode,title:i.title,currentName:i.currentName,initialName:i.initialName,initialDescription:i.initialDescription,initialBody:i.initialBody,expiresAt:i.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="skill_form_expired"?w(k=>k.map(r=>r.id!==x||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===i.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):i.type==="tree_changed"?j==null||j():i.type==="document_overwritten"?M==null||M({documentId:i.documentId,headCommitId:i.headCommitId}):i.type==="open_coding"?P==null||P({documentId:i.documentId,displayName:i.displayName}):i.type==="context_usage"?_e({percent:i.percent,used:i.used,limit:i.limit}):i.type==="error"&&(R=!0,B(i.message))}}),!c.signal.aborted&&!R&&we([])}catch(R){if(c.signal.aborted)return;B(R instanceof Error?R.message:String(R))}finally{D.current===c&&(D.current=null),J(!1)}}async function ot(){var t;if(!v){(t=D.current)==null||t.abort(),B(null),T(!1),J(!1);try{const f=await gt();G(f.sessionId),w([]),Z(""),X.current=!0,ue()}catch(f){B(f instanceof Error?f.message:String(f))}}}async function ct(t){var f;if(!v){if(t===re){T(!1);return}(f=D.current)==null||f.abort(),B(null);try{const c=await xt(t);G(c.sessionId),w(We(c.sessionId,c.messages)),Z(""),T(!1),X.current=!0,requestAnimationFrame(()=>q()),ue()}catch(c){B(c instanceof Error?c.message:String(c))}}}function De(t){!t||!H||H(t)}if(!l)return null;const he=(p==null?void 0:p.reason)==="missing_api_key",qe=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:Pe,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"+($?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>T(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(Et,{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})})]})]}),$?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:()=>T(!1),children:"返回对话"})]}),Je?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):be.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:be.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 ct(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(Be,{onConfigured:ze}):qe?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:qe}):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:Pe,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((c,S)=>{var x;if(c.type==="thinking"){if(!c.text)return null;const h=v&&t.id===((x=z[z.length-1])==null?void 0:x.id),R=!!je(t.blocks)||(t.blocks??[]).some(i=>i.type==="document_table"||i.type==="document_card"||i.type==="choice_card"||i.type==="tool_notice");return e.jsxs("details",{className:"mdocs-agent-panel-think-fold",open:h||!R,children:[e.jsx("summary",{children:h?"思考中...":"思考过程"}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:c.text})]},`${t.id}-th-${S}`)}return c.type==="text"?c.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Oe,{children:c.text})},`${t.id}-t-${S}`):null:c.type==="sources"?c.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:["已阅读 ",c.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:c.items.map(h=>e.jsx("li",{children:e.jsx("a",{href:h.url,target:"_blank",rel:"noreferrer",children:h.name})},h.id))})]})},`${t.id}-s-${S}`):c.type==="tool_notice"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:c.text})},`${t.id}-n-${S}`):c.type==="choice_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(ts,{block:c,onResolved:(h,R,i)=>{w(k=>k.map(r=>r.id!==t.id||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===h?{...d,status:i,selected:i==="selected"?R:d.selected}:d)}))}})},`${t.id}-ch-${S}`):c.type==="skill_form_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(vt,{block:c,onResolved:(h,R,i)=>{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===h?{...d,status:R,submittedName:R==="submitted"?i:d.submittedName}:d)}))}})},`${t.id}-sf-${S}`):c.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:h=>{h.preventDefault(),h.stopPropagation(),De(c.documentId)},children:["《",c.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"文档预览"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[c.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:c.path}):null,c.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:c.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:[c.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:c.rows.length===0?"无结果":`${c.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:c.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:c.rows.map(h=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>De(h.documentId),children:h.title})}),e.jsx("td",{children:h.summary||"-"})]},h.documentId))})]})})]})},`${t.id}-d-${S}`)}),v&&t.id===((f=z[z.length-1])==null?void 0:f.id)&&!je(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(Oe,{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]}),Se?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Se}):null,he&&z.length>0?e.jsx(Be,{onConfigured:ze}):null,e.jsx(Ct,{selectedNames:K,onChange:we,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(Xe,{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})})]}):Me?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}),Re?e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:Re}):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=>Z(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:()=>{L||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:L,onClick:()=>O(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:L,onClick:()=>void it(),children:L?"关闭中…":"强制关闭并退出"})]})]})}):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 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 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 l=a.props;if(!(!l||!qt(l.className)))return ke(l.children).replace(/\n$/,"")}return null}const Pt=.4,Bt=4,se=.2;let xe=null;function Lt(){return xe||(xe=lt(()=>import("./diagram-BF8g9yg4.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(Bt,Math.max(Pt,s))}function Ht(s){const[n,a]=o.useState(1),[l,b]=o.useState({x:0,y:0}),g=o.useRef(null),[_,y]=o.useState(!1);o.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),g.current={pointerId:u.pointerId,startX:u.clientX,startY:u.clientY,originX:l.x,originY:l.y},y(!0))}function C(u){const m=g.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=g.current;if(!(!m||m.pointerId!==u.pointerId)){g.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% + ${l.x}px), calc(-50% + ${l.y}px)) scale(${n})`},dangerouslySetInnerHTML:{__html:s.svg}})}),e.jsx("p",{className:"mdocs-agent-mermaid-float-hint",children:"拖动平移 · 滚轮缩放 · Esc 关闭"})]})]}),document.body)}function Xt(s){const n=o.useId().replace(/:/g,""),[a,l]=o.useState("diagram"),[b,g]=o.useState(()=>Le(s.source.trim())),[_,y]=o.useState(null),[A,C]=o.useState(!1),[E,N]=o.useState(!1),u=o.useRef(null),m=s.source.trim(),I=o.useMemo(()=>m,[m]);o.useEffect(()=>()=>{u.current!=null&&window.clearTimeout(u.current)},[]),o.useEffect(()=>{if(a!=="diagram")return;if(!I){g(null),y(null);return}const j=Le(I);if(j){g(j),y(null);return}let M=!1;const P=window.setTimeout(()=>{(async()=>{try{const F=await Lt();if(M)return;const T=`mdocs-agent-mmd-${n}-${Date.now()}`,{svg:$}=await F.render(T,I);if(M)return;Wt(I,$),g($),y(null)}catch(F){if(M)return;g(null),y(F instanceof Error?F.message:"Mermaid 渲染失败")}})()},200);return()=>{M=!0,window.clearTimeout(P)}},[a,I,n]);async function H(){!m||!await Ke(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:()=>l("diagram"),"aria-pressed":a==="diagram",title:"图谱",children:[e.jsx(Xe,{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:()=>l("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 Kt=o.memo(Xt,(s,n)=>s.source===n.source);function Ne(s){var n;return s==null||typeof s=="boolean"?"":typeof s=="string"||typeof s=="number"?String(s):Array.isArray(s)?s.map(Ne).join(""):typeof s=="object"&&"props"in s?Ne((n=s.props)==null?void 0:n.children):""}function Ut(s){const[n,a]=o.useState(!1),l=o.useRef(null),b=o.useRef(null),g=Ne(s.children).replace(/\n$/,"");o.useEffect(()=>()=>{l.current!=null&&window.clearTimeout(l.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$/,""))??"")||g;!C||!await Ke(C)||(a(!0),l.current!=null&&window.clearTimeout(l.current),l.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(Kt,{source:n,codeChildren:s.children}):e.jsx(Ut,{children:s.children})}const Gt={pre:({children:s})=>e.jsx(Yt,{children:s})},Oe=o.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 We(s,n){return n.map((a,l)=>{const b=a.skillNames&&a.skillNames.length>0?a.skillNames:a.skillIds&&a.skillIds.length>0?a.skillIds:void 0;return{id:`h-${s}-${l}-${a.role}`,role:a.role,content:a.content,skillNames:b}})}function Zt(s,n){const a=s.slice(),l=a[a.length-1];return(l==null?void 0:l.type)==="text"?a[a.length-1]={type:"text",text:l.text+n}:a.push({type:"text",text:n}),a}function Jt(s,n){const a=s.slice(),l=a[a.length-1];return(l==null?void 0:l.type)==="thinking"?a[a.length-1]={type:"thinking",text:l.text+n}:a.push({type:"thinking",text:n}),a}function je(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,[l,b]=o.useState(""),[g,_]=o.useState(!1),[y,A]=o.useState(1),C=o.useRef(!1),E=o.useRef(a);E.current=a;const N=n.status==="open",u=o.useRef(0);o.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 $=j-Date.now(),p=Math.max(0,Math.min(1,$/P));A(p),$<=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||g||!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(!(g||!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:g,onClick:()=>void m(j),children:j},j))}),e.jsxs("div",{className:"mdocs-agent-choice-custom",children:[e.jsx("input",{value:l,disabled:g,placeholder:"或输入自己的内容…",onChange:j=>b(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),m(l))}}),e.jsx("button",{type:"button",disabled:g||!l.trim(),onClick:()=>void m(l),children:"提交"})]}),e.jsx("div",{className:"mdocs-agent-choice-footer",children:e.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:g,onClick:()=>void I(),children:"取消"})})]}):null]})}function ss(s){const b=2*Math.PI*8.75,g=Math.min(100,Math.max(0,s.percent)),_=b*(1-g/100),y=g>=90?"danger":g>=70?"warn":"ok",A=`上下文 ${g}% · 已用 ${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 l of a.blocks)if((l.type==="choice_card"||l.type==="skill_form_card")&&l.status==="open")return!0}return!1}const ps=o.forwardRef(function(n,a){const{open:l,onClose:b,visitorName:g,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=((g==null?void 0:g.trim().charAt(0))||"我").toUpperCase(),[T,$]=o.useState(!1),[p,U]=o.useState(null),[Ve,Y]=o.useState(null),[z,w]=o.useState([]),[re,G]=o.useState(null),[be,Ze]=o.useState([]),[Je,ve]=o.useState(!1),[V,Z]=o.useState(""),[K,we]=o.useState([]),[Ce,ie]=o.useState(!1),[v,J]=o.useState(!1),[Se,B]=o.useState(null),[Q,_e]=o.useState(null),[oe,O]=o.useState(!1),[L,Ae]=o.useState(!1),Qe=o.useRef(null),ee=o.useRef(null),D=o.useRef(null),Ie=o.useRef(0),X=o.useRef(!0),[et,ce]=o.useState(!1),le=o.useRef(z);le.current=z;const Me=!!(E!=null&&E.trim())&&!Ce,tt=(N==null?void 0:N.trim())||"当前文档",Re=(u==null?void 0:u.trim())||"",de=!!(m!=null&&m.trim())&&!Ce,st=(I==null?void 0:I.trim())||"当前图谱";o.useEffect(()=>{ie(!1)},[E,m]);function Ee(t){return Ie.current+=1,`${t}-${Ie.current}`}const $e=120;function Te(t){return t.scrollHeight-t.scrollTop-t.clientHeight}function te(){const t=ee.current;t&&(t.scrollTop=t.scrollHeight,ce(!1))}function q(){X.current&&te()}function nt(){const t=ee.current;if(!t)return;const f=Te(t);X.current=f<=48,ce(f>$e)}function at(){X.current=!0,te()}o.useLayoutEffect(()=>{q();const t=ee.current;t&&ce(Te(t)>$e)},[z]);async function rt(){ve(!0);try{const t=await ht();Ze(t.sessions),re||G(t.lastOpenedSessionId)}catch{}finally{ve(!1)}}async function ue(){try{const t=await ft();_e(t)}catch{}}async function ze(){try{const t=await Fe();U(t),Y(null)}catch(t){U(null),Y(t instanceof Error?t.message:String(t))}}o.useEffect(()=>{var f;if(!l){$(!1),(f=D.current)==null||f.abort(),D.current=null,J(!1);return}let t=!1;return(async()=>{try{const c=await Fe();t||(U(c),Y(null))}catch(c){t||(U(null),Y(c instanceof Error?c.message:String(c)))}})(),ue(),()=>{t=!0}},[l]),o.useEffect(()=>{if(!l)return;let t=!1;return(async()=>{try{const f=await mt();if(t)return;G(f.sessionId),w(c=>c.length>0?c:We(f.sessionId,f.messages))}catch{}})(),()=>{t=!0}},[l]),o.useEffect(()=>{!l||!T||rt()},[l,T]);function me(){if(!L){if(ns(le.current)){O(!0);return}O(!1),b()}}async function it(){var c;if(L)return;Ae(!0);const t=le.current,f=[];for(const S of t)if(!(S.role!=="assistant"||!S.blocks))for(const x of S.blocks)x.type==="choice_card"&&x.status==="open"&&f.push(Ue(x.requestId).catch(()=>{})),x.type==="skill_form_card"&&x.status==="open"&&f.push(jt(x.requestId).catch(()=>{}));await Promise.all(f),(c=D.current)==null||c.abort(),w(S=>S.map(x=>x.role!=="assistant"||!x.blocks?x:{...x,blocks:x.blocks.map(h=>h.type==="choice_card"&&h.status==="open"?{...h,status:"cancelled"}:h.type==="skill_form_card"&&h.status==="open"?{...h,status:"cancelled"}:h)})),O(!1),Ae(!1),b()}const pe=o.useRef(me);pe.current=me,o.useImperativeHandle(a,()=>({requestClose:()=>pe.current()}),[]),o.useEffect(()=>{if(!l){O(!1);return}const t=f=>{if(f.key==="Escape"){if(oe){L||O(!1);return}if(T){$(!1);return}pe.current()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[l,T,oe,L]);async function fe(t){var h;const f=t.trim();if(!f||v)return;if(!(p!=null&&p.enabled)){B((p==null?void 0:p.reason)==="missing_api_key"?"请先配置 API Key":(p==null?void 0:p.reason)==="skills_missing"?"手册 skills 未就绪,请确认已构建 agent-skills":"助手暂不可用");return}(h=D.current)==null||h.abort();const c=new AbortController;D.current=c;const S={id:Ee("u"),role:"user",content:f,skillNames:K.length>0?[...K]:void 0},x=Ee("a");X.current=!0,w(R=>[...R,S,{id:x,role:"assistant",content:""}]),Z(""),J(!0),B(null),$(!1),requestAnimationFrame(()=>{te(),requestAnimationFrame(te)});try{let R=!1;await yt(f,{skillNames:K.length>0?K:void 0,references:{domainId:(C==null?void 0:C.trim())||void 0,documentId:!de&&Me?E.trim():void 0,graphFileId:de?m.trim():void 0},signal:c.signal,onEvent:i=>{i.type==="text_delta"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=Zt(r.blocks??[],i.text);return{...r,blocks:d,content:je(d)}})),requestAnimationFrame(()=>q())):i.type==="thinking_delta"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=Jt(r.blocks??[],i.text);return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="sources"?(w(k=>k.map(r=>{if(r.id!==x)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:i.items}:d.push({type:"sources",items:i.items}),{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="document_table"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=[...r.blocks??[],{type:"document_table",title:i.title,rows:i.rows}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="document_card"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=[...r.blocks??[],{type:"document_card",documentId:i.documentId,title:i.title,path:i.path,preview:i.preview}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="tool_notice"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=[...r.blocks??[],{type:"tool_notice",toolName:i.toolName,text:i.text}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="choice_card"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=[...r.blocks??[],{type:"choice_card",requestId:i.requestId,title:i.title,options:i.options,expiresAt:i.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="choice_expired"?w(k=>k.map(r=>r.id!==x||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===i.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):i.type==="skill_form_card"?(w(k=>k.map(r=>{if(r.id!==x)return r;const d=[...r.blocks??[],{type:"skill_form_card",requestId:i.requestId,mode:i.mode,title:i.title,currentName:i.currentName,initialName:i.initialName,initialDescription:i.initialDescription,initialBody:i.initialBody,expiresAt:i.expiresAt,status:"open"}];return{...r,blocks:d}})),requestAnimationFrame(()=>q())):i.type==="skill_form_expired"?w(k=>k.map(r=>r.id!==x||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="skill_form_card"&&d.requestId===i.requestId&&d.status==="open"?{...d,status:"expired"}:d)})):i.type==="tree_changed"?j==null||j():i.type==="document_overwritten"?M==null||M({documentId:i.documentId,headCommitId:i.headCommitId}):i.type==="open_coding"?P==null||P({documentId:i.documentId,displayName:i.displayName}):i.type==="context_usage"?_e({percent:i.percent,used:i.used,limit:i.limit}):i.type==="error"&&(R=!0,B(i.message))}}),!c.signal.aborted&&!R&&we([])}catch(R){if(c.signal.aborted)return;B(R instanceof Error?R.message:String(R))}finally{D.current===c&&(D.current=null),J(!1)}}async function ot(){var t;if(!v){(t=D.current)==null||t.abort(),B(null),$(!1),J(!1);try{const f=await gt();G(f.sessionId),w([]),Z(""),X.current=!0,ue()}catch(f){B(f instanceof Error?f.message:String(f))}}}async function ct(t){var f;if(!v){if(t===re){$(!1);return}(f=D.current)==null||f.abort(),B(null);try{const c=await xt(t);G(c.sessionId),w(We(c.sessionId,c.messages)),Z(""),$(!1),X.current=!0,requestAnimationFrame(()=>q()),ue()}catch(c){B(c instanceof Error?c.message:String(c))}}}function De(t){!t||!H||H(t)}if(!l)return null;const he=(p==null?void 0:p.reason)==="missing_api_key",qe=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:Pe,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:()=>$(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(Et,{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:()=>$(!1),children:"返回对话"})]}),Je?e.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):be.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:be.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 ct(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(Be,{onConfigured:ze}):qe?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:qe}):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:Pe,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((c,S)=>{var x;if(c.type==="thinking"){if(!c.text)return null;const h=v&&t.id===((x=z[z.length-1])==null?void 0:x.id),R=!!je(t.blocks)||(t.blocks??[]).some(i=>i.type==="document_table"||i.type==="document_card"||i.type==="choice_card"||i.type==="tool_notice");return e.jsxs("details",{className:"mdocs-agent-panel-think-fold",open:h||!R,children:[e.jsx("summary",{children:h?"思考中...":"思考过程"}),e.jsx("pre",{className:"mdocs-agent-panel-think-body",children:c.text})]},`${t.id}-th-${S}`)}return c.type==="text"?c.text?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(Oe,{children:c.text})},`${t.id}-t-${S}`):null:c.type==="sources"?c.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:["已阅读 ",c.items.length," 个页面"]}),e.jsx("ol",{className:"mdocs-agent-panel-sources-list",children:c.items.map(h=>e.jsx("li",{children:e.jsx("a",{href:h.url,target:"_blank",rel:"noreferrer",children:h.name})},h.id))})]})},`${t.id}-s-${S}`):c.type==="tool_notice"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:c.text})},`${t.id}-n-${S}`):c.type==="choice_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(ts,{block:c,onResolved:(h,R,i)=>{w(k=>k.map(r=>r.id!==t.id||!r.blocks?r:{...r,blocks:r.blocks.map(d=>d.type==="choice_card"&&d.requestId===h?{...d,status:i,selected:i==="selected"?R:d.selected}:d)}))}})},`${t.id}-ch-${S}`):c.type==="skill_form_card"?e.jsx("div",{className:"mdocs-agent-panel-block",children:e.jsx(vt,{block:c,onResolved:(h,R,i)=>{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===h?{...d,status:R,submittedName:R==="submitted"?i:d.submittedName}:d)}))}})},`${t.id}-sf-${S}`):c.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:h=>{h.preventDefault(),h.stopPropagation(),De(c.documentId)},children:["《",c.title,"》"]}),e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:"文档预览"})]}),e.jsxs("div",{className:"mdocs-agent-panel-doc-card-body",children:[c.path?e.jsx("p",{className:"mdocs-agent-panel-doc-card-path",children:c.path}):null,c.preview?e.jsx("p",{className:"mdocs-agent-panel-doc-card-preview",children:c.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:[c.title,e.jsx("span",{className:"mdocs-agent-panel-tool-fold-hint",children:c.rows.length===0?"无结果":`${c.rows.length} 条`})]}),e.jsx("div",{className:"mdocs-agent-panel-doc-table-wrap",children:c.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:c.rows.map(h=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",className:"mdocs-agent-panel-doc-link",onClick:()=>De(h.documentId),children:h.title})}),e.jsx("td",{children:h.summary||"-"})]},h.documentId))})]})})]})},`${t.id}-d-${S}`)}),v&&t.id===((f=z[z.length-1])==null?void 0:f.id)&&!je(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(Oe,{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]}),Se?e.jsx("p",{className:"mdocs-agent-panel-status-warn",children:Se}):null,he&&z.length>0?e.jsx(Be,{onConfigured:ze}):null,e.jsx(Ct,{selectedNames:K,onChange:we,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(Xe,{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})})]}):Me?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}),Re?e.jsx("span",{className:"mdocs-agent-doc-ref-path",children:Re}):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=>Z(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:()=>{L||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:L,onClick:()=>O(!1),children:"继续等待"}),e.jsx("button",{type:"button",disabled:L,onClick:()=>void it(),children:L?"关闭中…":"强制关闭并退出"})]})]})}):null]})});export{ps as AgentChatPanel};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as E,av as L,
|
|
1
|
+
import{o as E,av as L,b1 as D,aZ as _,b2 as F}from"./index-CINfyH_g.js";import{r as a,j as e}from"./react-vendor-BVS1XoFi.js";/**
|
|
2
2
|
* @license lucide-react v0.562.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -8,4 +8,4 @@ import{o as E,av as L,b0 as D,aY as _,b1 as F}from"./index-3B7_9QOQ.js";import{r
|
|
|
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 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"}]],
|
|
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"}]],Z=E("history",B),j=5;function K(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 P(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(),C=Date.now(),y=Math.max(l-C,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 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 M=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:[M,"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,Z as H,P as S,K as a};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{r as c,j as t}from"./react-vendor-BVS1XoFi.js";import{
|
|
1
|
+
import{r as c,j as t}from"./react-vendor-BVS1XoFi.js";import{a_ as Me,a$ as Ae,aY as Le,aP as ue,aQ as Te,Z as $e,aR as me,ar as Re,aU as Ee,b0 as _e,aV as Pe,aW as qe,aX as De}from"./index-CINfyH_g.js";import{H as He,S as Be,A as Fe,a as Ke}from"./AgentSkillFormCard-3ZpgH1RY.js";import{P as Oe}from"./plus-BxZJ-Mya.js";import{ar as We,ah as ze}from"./ui-CEFkTVnG.js";import"./diagram-BF8g9yg4.js";import"./motion-BAXVQJfN.js";function Je(e){const{block:n,onResolved:i}=e,[a,x]=c.useState(""),[h,d]=c.useState(!1),[y,p]=c.useState(1),f=c.useRef(!1),N=c.useRef(i);N.current=i;const u=n.status==="open",_=c.useRef(0);c.useEffect(()=>{if(!u)return;f.current=!1;const g=new Date(n.expiresAt).getTime(),b=Date.now(),D=Math.max(g-b,1);_.current=D,p(1);const R=()=>{const K=g-Date.now(),L=Math.max(0,Math.min(1,K/D));p(L),K<=0&&!f.current&&(f.current=!0,Me(n.requestId).catch(()=>{}).finally(()=>{N.current(n.requestId,"","expired")}))};R();const F=window.setInterval(R,100);return()=>window.clearInterval(F)},[u,n.expiresAt,n.requestId]);async function w(g){const b=g.trim();if(!(!b||h||!u)){d(!0);try{await Ae(n.requestId,b),i(n.requestId,b,"selected")}catch{i(n.requestId,b,"failed")}finally{d(!1)}}}async function $(){if(!(h||!u)){d(!0),f.current=!0;try{await Le(n.requestId),i(n.requestId,"","cancelled")}catch{i(n.requestId,"","failed")}finally{d(!1)}}}const B=Math.max(0,Math.ceil(y*_.current/1e3));return t.jsxs("div",{className:"mdocs-agent-choice-card"+(u?"":" mdocs-agent-choice-card-done"),children:[t.jsxs("div",{className:"mdocs-agent-choice-head",children:[t.jsx("p",{className:"mdocs-agent-choice-title",children:n.title}),u?t.jsxs("span",{className:"mdocs-agent-choice-timer","aria-live":"polite",children:[B,"s"]}):null]}),u?t.jsx("div",{className:"mdocs-agent-choice-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(y*100),children:t.jsx("div",{className:"mdocs-agent-choice-progress-bar",style:{transform:`scaleX(${y})`}})}):null,n.status==="selected"&&n.selected?t.jsxs("p",{className:"mdocs-agent-choice-result",children:["已选择:",n.selected]}):null,n.status==="cancelled"?t.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已取消"}):null,n.status==="expired"?t.jsx("p",{className:"mdocs-agent-choice-result muted",children:"已超时,选择已失效"}):null,n.status==="failed"?t.jsx("p",{className:"mdocs-agent-choice-result muted",children:"提交失败或已失效"}):null,u?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"mdocs-agent-choice-options",children:n.options.map(g=>t.jsx("button",{type:"button",className:"mdocs-agent-choice-option",disabled:h,onClick:()=>void w(g),children:g},g))}),t.jsxs("div",{className:"mdocs-agent-choice-custom",children:[t.jsx("input",{value:a,disabled:h,placeholder:"或输入自己的内容…",onChange:g=>x(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),w(a))}}),t.jsx("button",{type:"button",disabled:h||!a.trim(),onClick:()=>void w(a),children:"提交"})]}),t.jsx("div",{className:"mdocs-agent-choice-footer",children:t.jsx("button",{type:"button",className:"mdocs-agent-choice-cancel",disabled:h,onClick:()=>void $(),children:"取消"})})]}):null]})}function se(e){return e===""?[]:e.split(`
|
|
2
2
|
`)}function Ue(e){return e.join(`
|
|
3
|
-
`)}function ie(e,n){const i=se(e),a=se(n),x=i.length,h=a.length,d=Array.from({length:x+1},()=>Array.from({length:h+1},()=>0));for(let w=x-1;w>=0;w--)for(let $=h-1;$>=0;$--)i[w]===a[$]?d[w][$]=d[w+1][$+1]+1:d[w][$]=Math.max(d[w+1][$],d[w][$+1]);const y=[];let p=0,f=0;for(;p<x||f<h;)if(p<x&&f<h&&i[p]===a[f])y.push({kind:"eq",oi:p,ni:f}),p++,f++;else if(f<h&&(p===x||d[p][f+1]>=d[p+1][f]))y.push({kind:"ins",oi:p,ni:f}),f++;else if(p<x)y.push({kind:"del",oi:p,ni:f}),p++;else break;const N=[];let u=0,_=0;for(;u<y.length;){if(y[u].kind==="eq"){u++;continue}const w=y[u].oi,$=y[u].ni,B=[],g=[];let b=w,D=$;for(;u<y.length&&y[u].kind!=="eq";){const R=y[u];R.kind==="del"?(B.push(i[R.oi]),b=R.oi+1):(g.push(a[R.ni]),D=R.ni+1),u++}N.push({id:`h${_++}`,oldStart:w,oldEnd:b,newStart:$,newEnd:D,oldLines:B,newLines:g})}return N}function Ve(e,n){const i=se(e);return Ue([...i.slice(0,n.oldStart),...n.newLines,...i.slice(n.oldEnd)])}function pe(e){const n=[];for(const i of e){const a=n[n.length-1];i.kind==="same"&&(a==null?void 0:a.kind)==="same"?n[n.length-1]={kind:"same",lines:[...a.lines,...i.lines],key:a.key}:n.push(i)}return n}function ye(e){let n=0;return e.map(i=>{if(i.kind!=="hunk")return i;const a={...i,hunkIndex:n,key:`h-${i.hunk.id}-${n}`};return n+=1,a})}function
|
|
3
|
+
`)}function ie(e,n){const i=se(e),a=se(n),x=i.length,h=a.length,d=Array.from({length:x+1},()=>Array.from({length:h+1},()=>0));for(let w=x-1;w>=0;w--)for(let $=h-1;$>=0;$--)i[w]===a[$]?d[w][$]=d[w+1][$+1]+1:d[w][$]=Math.max(d[w+1][$],d[w][$+1]);const y=[];let p=0,f=0;for(;p<x||f<h;)if(p<x&&f<h&&i[p]===a[f])y.push({kind:"eq",oi:p,ni:f}),p++,f++;else if(f<h&&(p===x||d[p][f+1]>=d[p+1][f]))y.push({kind:"ins",oi:p,ni:f}),f++;else if(p<x)y.push({kind:"del",oi:p,ni:f}),p++;else break;const N=[];let u=0,_=0;for(;u<y.length;){if(y[u].kind==="eq"){u++;continue}const w=y[u].oi,$=y[u].ni,B=[],g=[];let b=w,D=$;for(;u<y.length&&y[u].kind!=="eq";){const R=y[u];R.kind==="del"?(B.push(i[R.oi]),b=R.oi+1):(g.push(a[R.ni]),D=R.ni+1),u++}N.push({id:`h${_++}`,oldStart:w,oldEnd:b,newStart:$,newEnd:D,oldLines:B,newLines:g})}return N}function Ve(e,n){const i=se(e);return Ue([...i.slice(0,n.oldStart),...n.newLines,...i.slice(n.oldEnd)])}function pe(e){const n=[];for(const i of e){const a=n[n.length-1];i.kind==="same"&&(a==null?void 0:a.kind)==="same"?n[n.length-1]={kind:"same",lines:[...a.lines,...i.lines],key:a.key}:n.push(i)}return n}function ye(e){let n=0;return e.map(i=>{if(i.kind!=="hunk")return i;const a={...i,hunkIndex:n,key:`h-${i.hunk.id}-${n}`};return n+=1,a})}function Ye(e,n){const i=e.map(a=>a.kind!=="hunk"||a.hunk.id!==n?a:{kind:"same",lines:a.hunk.oldLines.slice(),key:`s-rej-${a.hunk.id}`});return ye(pe(i))}function Ge(e,n,i){let a=0,x=!1;const h=[];for(const d of e){if(d.kind==="same"){h.push(d);continue}if(d.hunk.id===n){x=!0,a=i.length-d.hunk.oldLines.length,h.push({kind:"same",lines:i.slice(),key:`s-acc-${d.hunk.id}`});continue}if(!x||a===0){h.push(d);continue}h.push({...d,hunk:{...d.hunk,oldStart:d.hunk.oldStart+a,oldEnd:d.hunk.oldEnd+a}})}return ye(pe(h))}function X(e){return e===""?[]:e.split(`
|
|
4
4
|
`)}function U(e){return e.join(`
|
|
5
|
-
`)}function
|
|
5
|
+
`)}function Xe(e,n){const i=X(e),a=[];let x=0;return n.forEach((h,d)=>{h.oldStart>x&&a.push({kind:"same",lines:i.slice(x,h.oldStart),key:`s-${x}-${h.oldStart}`}),a.push({kind:"hunk",hunk:h,hunkIndex:d,key:`h-${h.id}-${d}`}),x=h.oldEnd}),x<i.length?a.push({kind:"same",lines:i.slice(x),key:`s-${x}-end`}):n.length===0&&i.length===0&&a.push({kind:"same",lines:[],key:"s-empty"}),a}function ne(e){const n=[],i=[];for(const a of e)a.kind==="same"?n.push(U(a.lines)):i.push(U(a.hunk.newLines));return{sameTexts:n,newTexts:i}}function he(e,n){const i=[];let a=0,x=0;for(const h of e)if(h.kind==="same"){const d=n.sameTexts[a++]??"";i.push(...X(d))}else{const d=n.newTexts[x++]??"";i.push(...X(d))}return U(i)}function Qe(e){return e.oldLines.length===0?"add":e.newLines.length===0?"del":"mod"}function fe(e){const n=Math.max(1,X(e.value).length);return t.jsxs("div",{className:`mdocs-ai-write-line ${e.className}`,children:[t.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),t.jsx("textarea",{className:"mdocs-ai-write-inline-edit",value:e.value,rows:n,spellCheck:!1,"aria-label":e["aria-label"],onChange:i=>e.onChange(i.target.value),onBlur:()=>e.onBlurFlush()})]})}function Ze(e){const n=!!e.sending,[i,a]=c.useState(0),[x,h]=c.useState(null),[d,y]=c.useState({sameTexts:[],newTexts:[]}),[p,f]=c.useState([]),N=c.useRef(!1),u=c.useRef(!1),_=c.useRef([]),w=c.useRef(d);w.current=d,_.current=p;const $=c.useMemo(()=>e.proposedMd==null||e.proposedMd===e.currentMd?[]:ie(e.currentMd,e.proposedMd),[e.currentMd,e.proposedMd]),B=!n&&(p.length>0?p.some(l=>l.kind==="hunk"):$.length>0);c.useEffect(()=>{if(n){f([]),N.current=!1,u.current=!1;return}if(e.proposedMd==null||e.proposedMd===e.currentMd){f([]),N.current=!1,u.current=!1;return}if(u.current){u.current=!1;return}const l=ie(e.currentMd,e.proposedMd);if(l.length===0){f([]);return}const k=Xe(e.currentMd,l);f(k),N.current=!1,y(ne(k))},[n,e.proposedMd,e.currentMd]);const g=c.useMemo(()=>p.filter(l=>l.kind==="hunk").map(l=>l.hunk),[p]);c.useEffect(()=>{if(g.length===0){a(0);return}a(l=>Math.min(l,g.length-1))},[g.length]);const b=x??i;function D(){return he(_.current,w.current)}function R(){if(!B||_.current.length===0)return e.proposedMd;const l=D();return N.current=!1,l===e.currentMd?(u.current=!1,e.onProposedChange(null),null):(l!==e.proposedMd&&(u.current=!0,e.onProposedChange(l)),l)}function F(l){const k=_.current.find(W=>W.kind==="hunk"&&W.hunk.id===l.id);if(!k)return;const v=w.current.newTexts[k.hunkIndex],C=v!=null?X(v):l.newLines.slice(),A={...l,newLines:C},I=D();if(N.current=!1,I===e.currentMd){u.current=!1,f([]),e.onProposedChange(null);return}const E=Ve(e.currentMd,A),O=Ge(_.current,l.id,C),G=O.some(W=>W.kind==="hunk");u.current=!0,f(O),y(ne(O)),e.onCurrentChange(E),!G||I===E?(u.current=!1,e.onProposedChange(null)):e.onProposedChange(I)}function K(l){const k=_.current.find(E=>E.kind==="hunk"&&E.hunk.id===l.id);if(!k)return;const v={sameTexts:w.current.sameTexts.slice(),newTexts:w.current.newTexts.slice()};v.newTexts[k.hunkIndex]=U(l.oldLines);const C=he(_.current,v),A=Ye(_.current,l.id),I=A.some(E=>E.kind==="hunk");N.current=!1,u.current=!0,f(A),y(ne(A)),!I||C===e.currentMd?(u.current=!1,e.onProposedChange(null)):e.onProposedChange(C)}function L(){const l=D();N.current=!1,u.current=!1,e.onCurrentChange(l),e.onProposedChange(null)}function V(){N.current=!1,u.current=!1,e.onProposedChange(null)}function S(l){g.length!==0&&a(k=>{const v=(k+l+g.length)%g.length,C=document.getElementById(`mdocs-ai-hunk-${v}`);return C==null||C.scrollIntoView({block:"center",behavior:"smooth"}),v})}function J(l,k){N.current=!0,y(v=>{const C=v.sameTexts.slice();return C[l]=k,{...v,sameTexts:C}})}function Q(l,k){N.current=!0,y(v=>{const C=v.newTexts.slice();return C[l]=k,{...v,newTexts:C}})}const P=g[b]??null;let Y=0;return t.jsxs("div",{className:"mdocs-ai-write-md-pane",children:[t.jsxs("div",{className:"mdocs-ai-write-diff-toolbar",children:[t.jsx("span",{className:"mdocs-ai-write-diff-count",children:n?"接收中·编辑我的稿":g.length===0?e.proposedMd?"与提案一致(可编辑)":"Markdown 源码(可编辑)":`${g.length} 处变更(可改提案)`}),!n&&g.length>0?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"mdocs-ai-write-diff-accept-all",onClick:L,children:"全部接受"}),t.jsx("button",{type:"button",className:"mdocs-ai-write-diff-reject-all",onClick:V,children:"全部拒绝"})]}):null]}),B&&p.length>0?t.jsxs("div",{className:"mdocs-ai-write-inline",role:"document",children:[p.map(l=>{if(l.kind==="same"){const I=Y++,E=d.sameTexts[I]??U(l.lines);return t.jsx("div",{className:"mdocs-ai-write-inline-same",children:t.jsx(fe,{className:"ctx",value:E,"aria-label":"提案相同行",onChange:O=>J(I,O),onBlurFlush:()=>R()})},l.key)}const k=l.hunk,v=Qe(k),C=l.hunkIndex===b,A=d.newTexts[l.hunkIndex]??U(k.newLines);return t.jsxs("div",{id:`mdocs-ai-hunk-${l.hunkIndex}`,className:`mdocs-ai-write-inline-hunk mdocs-ai-write-inline-hunk-${v}`+(C?" is-active":""),onMouseEnter:()=>h(l.hunkIndex),onMouseLeave:()=>h(null),onClick:()=>a(l.hunkIndex),children:[t.jsxs("div",{className:"mdocs-ai-write-hunk-hover",hidden:x!==l.hunkIndex,children:[t.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:I=>{I.stopPropagation(),K(k)},children:"拒绝"}),t.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:I=>{I.stopPropagation(),F(k)},children:"接受"})]}),t.jsx("pre",{className:"mdocs-ai-write-hunk-pre",children:k.oldLines.map((I,E)=>t.jsxs("div",{className:"mdocs-ai-write-line del mdocs-ai-write-line-readonly",children:[t.jsx("span",{className:"mdocs-ai-write-rail","aria-hidden":!0}),t.jsx("span",{className:"mdocs-ai-write-code",children:I||" "})]},`o${E}`))}),k.newLines.length>0||A!==""||v!=="del"?t.jsx(fe,{className:"add",value:A,"aria-label":"提案新增行",onChange:I=>Q(l.hunkIndex,I),onBlurFlush:()=>R()}):null]},l.key)}),P?t.jsxs("div",{className:"mdocs-ai-write-float-nav",role:"toolbar","aria-label":"变更导航",children:[t.jsx("button",{type:"button","aria-label":"上一段",onClick:()=>S(-1),children:"↑"}),t.jsxs("span",{children:[b+1," / ",g.length]}),t.jsx("button",{type:"button","aria-label":"下一段",onClick:()=>S(1),children:"↓"}),t.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-reject",onClick:()=>K(P),children:"拒绝"}),t.jsx("button",{type:"button",className:"mdocs-ai-write-hunk-accept",onClick:()=>F(P),children:"接受"})]}):null]}):t.jsx("textarea",{className:"mdocs-ai-write-editor",value:e.currentMd,onChange:l=>e.onCurrentChange(l.target.value),spellCheck:!1,placeholder:`# 标题
|
|
6
6
|
|
|
7
|
-
在此编辑 Markdown 源码…`})]})}let ge=0;function xe(e){return ge+=1,`${e}-${Date.now()}-${ge}`}function et(e,n){const i=e.slice(),a=i[i.length-1];return(a==null?void 0:a.type)==="text"?i[i.length-1]={type:"text",text:a.text+n}:i.push({type:"text",text:n}),i}function tt(e,n){const i=e.slice(),a=i[i.length-1];return(a==null?void 0:a.type)==="thinking"?i[i.length-1]={type:"thinking",text:a.text+n}:i.push({type:"thinking",text:n}),i}function te(e,n){const i=n.trim();return i?[...e,{type:"tool",text:i}]:e}function nt(e){return e.some(n=>n.type==="text"||n.type==="thinking"?n.text.length>0:!0)}function st(e){const n=new Date(e);if(Number.isNaN(n.getTime()))return"";const i=new Date;return n.getFullYear()===i.getFullYear()&&n.getMonth()===i.getMonth()&&n.getDate()===i.getDate()?n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):n.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function ke(e,n){return n.map((i,a)=>{const x=`h-${e}-${a}-${i.role}`;if(i.role==="user"){const h=i.skillNames&&i.skillNames.length>0?i.skillNames:i.skillIds&&i.skillIds.length>0?i.skillIds:void 0;return{id:x,role:"user",content:i.content,skillNames:h}}return{id:x,role:"assistant",blocks:i.content?[{type:"text",text:i.content}]:[]}})}function ut(e){const[n,i]=c.useState(e.initialMarkdown),[a,x]=c.useState(null),[h]=c.useState(e.initialMarkdown),[d,y]=c.useState(e.displayName||"未命名"),[p,f]=c.useState([]),[N,u]=c.useState(null),[_,w]=c.useState([]),[$,B]=c.useState(!1),[g,b]=c.useState(!1),[D,R]=c.useState(""),[F,O]=c.useState([]),[T,V]=c.useState(!1),[S,J]=c.useState(null),[Z,P]=c.useState(null),[G,l]=c.useState(!1),[k,v]=c.useState(null),C=c.useRef(null),A=c.useRef(null),I=c.useRef(null),E=c.useRef(!0),[K,X]=c.useState(!1),W=120;function ae(s){return s.scrollHeight-s.scrollTop-s.clientHeight}function Q(){const s=I.current;s&&(s.scrollTop=s.scrollHeight,X(!1))}function we(){E.current&&Q()}function je(){const s=I.current;if(!s)return;const o=ae(s);E.current=o<=48,X(o>W)}function Ne(){E.current=!0,Q()}c.useLayoutEffect(()=>{if(!e.open)return;we();const s=I.current;s&&X(ae(s)>W)},[p,e.open]);async function ee(){B(!0);try{const s=await Ee("coding",e.documentId);w(s.sessions),N||u(s.lastOpenedSessionId)}catch{}finally{B(!1)}}async function le(){try{const s=await ue();J(s)}catch{J({enabled:!1,skillsReady:!1,model:null})}}if(c.useEffect(()=>{var o;if(!e.open){b(!1),(o=A.current)==null||o.abort();return}i(e.initialMarkdown),x(null),y(e.displayName||"未命名"),R(""),P(null),b(!1);let s=!1;return(async()=>{try{const j=await ue();s||J(j)}catch{s||J({enabled:!1,skillsReady:!1,model:null})}try{const j=await Le("coding",e.documentId);if(s)return;u(j.sessionId),f(ke(j.sessionId,j.messages))}catch{s||(u(null),f([]))}ee()})(),()=>{s=!0}},[e.open,e.initialMarkdown,e.displayName,e.documentId]),c.useEffect(()=>()=>{var s;return(s=A.current)==null?void 0:s.abort()},[]),c.useEffect(()=>{e.open&&g&&ee()},[g,e.open,e.documentId]),!e.open)return null;const re=(S==null?void 0:S.reason)==="missing_api_key",be=a!=null&&a!==n?ie(n,a):[];async function Se(){var s;if(!T){(s=A.current)==null||s.abort(),P(null),b(!1),V(!1);try{const o=await Pe("coding",e.documentId);u(o.sessionId),f([]),R(""),ee()}catch(o){P(o instanceof Error?o.message:String(o))}}}async function Ce(s){var o;if(!T){if(s===N){b(!1);return}(o=A.current)==null||o.abort(),P(null);try{const j=await qe(s,"coding",e.documentId);u(j.sessionId),f(ke(j.sessionId,j.messages)),R(""),b(!1)}catch(j){P(j instanceof Error?j.message:String(j))}}}async function oe(){var z;const s=D.trim();if(!s||T)return;if(!(S!=null&&S.enabled)){P("请先配置 API Key");return}(z=A.current)==null||z.abort();const o=new AbortController;A.current=o;const j=xe("u"),M=xe("a");E.current=!0,f(q=>[...q,{id:j,role:"user",content:s,skillNames:F.length>0?[...F]:void 0},{id:M,role:"assistant",blocks:[]}]),R(""),V(!0),P(null),requestAnimationFrame(()=>{Q(),requestAnimationFrame(Q)});const L=q=>{f(r=>r.map(m=>m.id===M&&m.role==="assistant"?{...m,blocks:q(m.blocks)}:m))};try{let q=!1;await De(s,{mode:"coding",skillNames:F.length>0?F:void 0,documentId:e.documentId,workingMarkdown:n,baseMarkdown:h,signal:o.signal,onEvent:r=>{r.type==="text_delta"?L(m=>et(m,r.text)):r.type==="thinking_delta"?L(m=>tt(m,r.text)):r.type==="markdown_set"?x(r.markdown):r.type==="tool_notice"?L(m=>te(m,r.text)):r.type==="document_table"?L(m=>te(m,r.title)):r.type==="document_card"?L(m=>te(m,`读取文档「${r.title}」`)):r.type==="sources"?r.items.length>0&&L(m=>te(m,`已阅读 ${r.items.length} 个手册页面`)):r.type==="skill_form_card"?L(m=>[...m,{type:"skill_form_card",requestId:r.requestId,mode:r.mode,title:r.title,currentName:r.currentName,initialName:r.initialName,initialDescription:r.initialDescription,initialBody:r.initialBody,expiresAt:r.expiresAt,status:"open"}]):r.type==="choice_card"?(E.current=!0,L(m=>[...m,{type:"choice_card",requestId:r.requestId,title:r.title,options:r.options,expiresAt:r.expiresAt,status:"open"}])):r.type==="choice_expired"?L(m=>m.map(H=>H.type==="choice_card"&&H.requestId===r.requestId&&H.status==="open"?{...H,status:"expired"}:H)):r.type==="skill_form_expired"?L(m=>m.map(H=>H.type==="skill_form_card"&&H.requestId===r.requestId&&H.status==="open"?{...H,status:"expired"}:H)):r.type==="error"&&(q=!0,P(r.message))}}),!o.signal.aborted&&!q&&O([]),ee()}catch(q){o.signal.aborted||P(q instanceof Error?q.message:String(q))}finally{A.current===o&&(A.current=null),V(!1)}}function ce(s){return new Promise(o=>{C.current=o,v({message:s.message,confirmLabel:s.confirmLabel??"确定",cancelLabel:s.cancelLabel??"返回",danger:s.danger??!1})})}function de(s){const o=C.current;C.current=null,v(null),o==null||o(s)}async function Ie(){if(!await ce({message:"是否回写",confirmLabel:"确认",cancelLabel:"返回"}))return;let o=n;be.length>0&&(o=a??n,i(o),x(null)),l(!0);const j=!e.documentId;try{const M=await e.onComplete({markdown:o,documentId:e.documentId,displayName:d.trim()||"未命名"}),L=M&&typeof M=="object"&&typeof M.documentId=="string"?M.documentId.trim():"";if(j&&L&&N)try{await _e(N,L)}catch{}e.onClose()}catch(M){if(M!=null&&M.silent||M instanceof Error&&M.message==="cancelled")return;P(M instanceof Error?M.message:String(M))}finally{l(!1)}}async function ve(){var s;(n!==h||a!=null)&&!await ce({message:"取消帮写?未写回的修改将丢失。",confirmLabel:"放弃修改",danger:!0})||((s=A.current)==null||s.abort(),e.onClose())}return t.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[t.jsxs("header",{className:"mdocs-ai-write-header",children:[t.jsxs("div",{className:"mdocs-ai-write-header-left",children:[t.jsx("img",{src:$e,alt:"",className:"mdocs-ai-write-title-logo"}),t.jsx("strong",{children:"帮写"}),t.jsx("input",{className:"mdocs-ai-write-title",value:d,onChange:s=>y(s.target.value),"aria-label":"文档标题"})]}),t.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[t.jsx("button",{type:"button",onClick:()=>void ve(),disabled:G||k!=null,children:"取消"}),t.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void Ie(),disabled:G||k!=null,children:G?"写回中…":"完成并写回"})]})]}),t.jsxs("div",{className:"mdocs-ai-write-body",children:[t.jsxs("section",{className:"mdocs-ai-write-chat",children:[t.jsxs("div",{className:"mdocs-ai-write-chat-toolbar",children:[t.jsx("span",{className:"mdocs-ai-write-chat-toolbar-label",children:"对话"}),t.jsxs("div",{className:"mdocs-ai-write-chat-toolbar-actions",children:[t.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:T,onClick:()=>void Se(),children:t.jsx(Ke,{size:16,strokeWidth:1.8})}),t.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(g?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>b(s=>!s),children:t.jsx(He,{size:16,strokeWidth:1.8})})]})]}),g?t.jsxs("div",{className:"mdocs-ai-write-history mdocs-agent-panel-history",children:[t.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[t.jsx("span",{children:"历史会话"}),t.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>b(!1),children:"返回对话"})]}),$?t.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):_.length===0?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),t.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):t.jsx("ul",{className:"mdocs-agent-panel-history-list",children:_.map(s=>t.jsx("li",{children:t.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(s.id===N?" active":""),disabled:T,onClick:()=>void Ce(s.id),children:[t.jsx("span",{className:"mdocs-agent-panel-history-title",children:s.title}),t.jsx("span",{className:"mdocs-agent-panel-history-time",children:st(s.updatedAt)})]})},s.id))})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mdocs-ai-write-chat-scroll-wrap",children:[t.jsx("div",{className:"mdocs-ai-write-chat-messages",ref:I,onScroll:je,children:p.length===0?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"mdocs-ai-write-hint",children:"描述你想写或改的内容。助手可读取右侧当前稿与进场快照,再更新提案;请按段接受或拒绝后完成写回。"}),re?t.jsx(me,{onConfigured:le}):null]}):p.map(s=>t.jsx("div",{className:"mdocs-ai-write-msg"+(s.role==="user"?" mdocs-ai-write-msg-user":""),children:s.role==="user"?t.jsxs(t.Fragment,{children:[s.skillNames&&s.skillNames.length>0?t.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",s.skillNames.length]}):null,s.content]}):nt(s.blocks)?t.jsx("div",{className:"mdocs-ai-write-timeline",children:s.blocks.map((o,j)=>o.type==="thinking"?o.text?t.jsxs("details",{className:"mdocs-ai-write-thinking",open:T,children:[t.jsx("summary",{children:"思考中"}),t.jsx("pre",{className:"mdocs-ai-write-thinking-body",children:o.text})]},`${s.id}-think-${j}`):null:o.type==="tool"?t.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:o.text},`${s.id}-tool-${j}`):o.type==="skill_form_card"?t.jsx(Be,{block:o,onResolved:(M,L,z)=>{f(q=>q.map(r=>r.id!==s.id||r.role!=="assistant"?r:{...r,blocks:r.blocks.map(m=>m.type==="skill_form_card"&&m.requestId===M?{...m,status:L,submittedName:L==="submitted"?z:m.submittedName}:m)}))}},`${s.id}-sf-${j}`):o.type==="choice_card"?t.jsx(Je,{block:o,onResolved:(M,L,z)=>{f(q=>q.map(r=>r.id!==s.id||r.role!=="assistant"?r:{...r,blocks:r.blocks.map(m=>m.type==="choice_card"&&m.requestId===M?{...m,status:z,selected:z==="selected"?L:m.selected}:m)}))}},`${s.id}-ch-${j}`):o.type==="text"&&o.text?t.jsx("div",{className:"mdocs-agent-panel-md",children:t.jsx(We,{remarkPlugins:[ze],children:o.text})},`${s.id}-text-${j}`):null)}):T?t.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]}):null},s.id))}),K?t.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:Ne,title:"回到底部","aria-label":"回到底部",children:[t.jsx(Fe,{size:14,strokeWidth:2,"aria-hidden":!0}),t.jsx("span",{children:"置底"})]}):null]}),Z?t.jsx("p",{className:"mdocs-ai-write-error",children:Z}):null,re&&p.length>0?t.jsx(me,{onConfigured:le}):null,t.jsxs("div",{className:"mdocs-ai-write-input-row",children:[t.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:6},children:[t.jsx(Oe,{selectedNames:F,onChange:O,disabled:T||!(S!=null&&S.enabled)}),t.jsx("textarea",{rows:2,value:D,disabled:T||!(S!=null&&S.enabled),placeholder:S!=null&&S.enabled?"说说要写什么…":"请先配置 API Key",onChange:s=>R(s.target.value),onKeyDown:s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),oe())}})]}),t.jsx("button",{type:"button",className:T?"mdocs-ai-write-stop":void 0,disabled:T?!1:!(S!=null&&S.enabled),onClick:()=>{var s;if(T){(s=A.current)==null||s.abort();return}oe()},children:T?"停止":"发送"})]})]})]}),t.jsx(Qe,{currentMd:n,proposedMd:a,sending:T,onCurrentChange:i,onProposedChange:x})]}),k?t.jsx(Re,{message:k.message,confirmLabel:k.confirmLabel,cancelLabel:k.cancelLabel,danger:k.danger,onConfirm:()=>de(!0),onCancel:()=>de(!1)}):null]})}export{ut as AiWriteWorkbench};
|
|
7
|
+
在此编辑 Markdown 源码…`})]})}let ge=0;function xe(e){return ge+=1,`${e}-${Date.now()}-${ge}`}function et(e,n){const i=e.slice(),a=i[i.length-1];return(a==null?void 0:a.type)==="text"?i[i.length-1]={type:"text",text:a.text+n}:i.push({type:"text",text:n}),i}function tt(e,n){const i=e.slice(),a=i[i.length-1];return(a==null?void 0:a.type)==="thinking"?i[i.length-1]={type:"thinking",text:a.text+n}:i.push({type:"thinking",text:n}),i}function te(e,n){const i=n.trim();return i?[...e,{type:"tool",text:i}]:e}function nt(e){return e.some(n=>n.type==="text"||n.type==="thinking"?n.text.length>0:!0)}function st(e){const n=new Date(e);if(Number.isNaN(n.getTime()))return"";const i=new Date;return n.getFullYear()===i.getFullYear()&&n.getMonth()===i.getMonth()&&n.getDate()===i.getDate()?n.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):n.toLocaleDateString(void 0,{month:"2-digit",day:"2-digit"})}function ke(e,n){return n.map((i,a)=>{const x=`h-${e}-${a}-${i.role}`;if(i.role==="user"){const h=i.skillNames&&i.skillNames.length>0?i.skillNames:i.skillIds&&i.skillIds.length>0?i.skillIds:void 0;return{id:x,role:"user",content:i.content,skillNames:h}}return{id:x,role:"assistant",blocks:i.content?[{type:"text",text:i.content}]:[]}})}function ut(e){const[n,i]=c.useState(e.initialMarkdown),[a,x]=c.useState(null),[h]=c.useState(e.initialMarkdown),[d,y]=c.useState(e.displayName||"未命名"),[p,f]=c.useState([]),[N,u]=c.useState(null),[_,w]=c.useState([]),[$,B]=c.useState(!1),[g,b]=c.useState(!1),[D,R]=c.useState(""),[F,K]=c.useState([]),[L,V]=c.useState(!1),[S,J]=c.useState(null),[Q,P]=c.useState(null),[Y,l]=c.useState(!1),[k,v]=c.useState(null),C=c.useRef(null),A=c.useRef(null),I=c.useRef(null),E=c.useRef(!0),[O,G]=c.useState(!1),W=120;function ae(s){return s.scrollHeight-s.scrollTop-s.clientHeight}function Z(){const s=I.current;s&&(s.scrollTop=s.scrollHeight,G(!1))}function we(){E.current&&Z()}function je(){const s=I.current;if(!s)return;const o=ae(s);E.current=o<=48,G(o>W)}function Ne(){E.current=!0,Z()}c.useLayoutEffect(()=>{if(!e.open)return;we();const s=I.current;s&&G(ae(s)>W)},[p,e.open]);async function ee(){B(!0);try{const s=await Ee("coding",e.documentId);w(s.sessions),N||u(s.lastOpenedSessionId)}catch{}finally{B(!1)}}async function le(){try{const s=await ue();J(s)}catch{J({enabled:!1,skillsReady:!1,model:null})}}if(c.useEffect(()=>{var o;if(!e.open){b(!1),(o=A.current)==null||o.abort();return}i(e.initialMarkdown),x(null),y(e.displayName||"未命名"),R(""),P(null),b(!1);let s=!1;return(async()=>{try{const j=await ue();s||J(j)}catch{s||J({enabled:!1,skillsReady:!1,model:null})}try{const j=await Te("coding",e.documentId);if(s)return;u(j.sessionId),f(ke(j.sessionId,j.messages))}catch{s||(u(null),f([]))}ee()})(),()=>{s=!0}},[e.open,e.initialMarkdown,e.displayName,e.documentId]),c.useEffect(()=>()=>{var s;return(s=A.current)==null?void 0:s.abort()},[]),c.useEffect(()=>{e.open&&g&&ee()},[g,e.open,e.documentId]),!e.open)return null;const re=(S==null?void 0:S.reason)==="missing_api_key",be=a!=null&&a!==n?ie(n,a):[];async function Se(){var s;if(!L){(s=A.current)==null||s.abort(),P(null),b(!1),V(!1);try{const o=await Pe("coding",e.documentId);u(o.sessionId),f([]),R(""),ee()}catch(o){P(o instanceof Error?o.message:String(o))}}}async function Ce(s){var o;if(!L){if(s===N){b(!1);return}(o=A.current)==null||o.abort(),P(null);try{const j=await qe(s,"coding",e.documentId);u(j.sessionId),f(ke(j.sessionId,j.messages)),R(""),b(!1)}catch(j){P(j instanceof Error?j.message:String(j))}}}async function oe(){var z;const s=D.trim();if(!s||L)return;if(!(S!=null&&S.enabled)){P("请先配置 API Key");return}(z=A.current)==null||z.abort();const o=new AbortController;A.current=o;const j=xe("u"),M=xe("a");E.current=!0,f(q=>[...q,{id:j,role:"user",content:s,skillNames:F.length>0?[...F]:void 0},{id:M,role:"assistant",blocks:[]}]),R(""),V(!0),P(null),requestAnimationFrame(()=>{Z(),requestAnimationFrame(Z)});const T=q=>{f(r=>r.map(m=>m.id===M&&m.role==="assistant"?{...m,blocks:q(m.blocks)}:m))};try{let q=!1;await De(s,{mode:"coding",skillNames:F.length>0?F:void 0,documentId:e.documentId,workingMarkdown:n,baseMarkdown:h,signal:o.signal,onEvent:r=>{r.type==="text_delta"?T(m=>et(m,r.text)):r.type==="thinking_delta"?T(m=>tt(m,r.text)):r.type==="markdown_set"?x(r.markdown):r.type==="tool_notice"?T(m=>te(m,r.text)):r.type==="document_table"?T(m=>te(m,r.title)):r.type==="document_card"?T(m=>te(m,`读取文档「${r.title}」`)):r.type==="sources"?r.items.length>0&&T(m=>te(m,`已阅读 ${r.items.length} 个手册页面`)):r.type==="skill_form_card"?T(m=>[...m,{type:"skill_form_card",requestId:r.requestId,mode:r.mode,title:r.title,currentName:r.currentName,initialName:r.initialName,initialDescription:r.initialDescription,initialBody:r.initialBody,expiresAt:r.expiresAt,status:"open"}]):r.type==="choice_card"?(E.current=!0,T(m=>[...m,{type:"choice_card",requestId:r.requestId,title:r.title,options:r.options,expiresAt:r.expiresAt,status:"open"}])):r.type==="choice_expired"?T(m=>m.map(H=>H.type==="choice_card"&&H.requestId===r.requestId&&H.status==="open"?{...H,status:"expired"}:H)):r.type==="skill_form_expired"?T(m=>m.map(H=>H.type==="skill_form_card"&&H.requestId===r.requestId&&H.status==="open"?{...H,status:"expired"}:H)):r.type==="error"&&(q=!0,P(r.message))}}),!o.signal.aborted&&!q&&K([]),ee()}catch(q){o.signal.aborted||P(q instanceof Error?q.message:String(q))}finally{A.current===o&&(A.current=null),V(!1)}}function ce(s){return new Promise(o=>{C.current=o,v({message:s.message,confirmLabel:s.confirmLabel??"确定",cancelLabel:s.cancelLabel??"返回",danger:s.danger??!1})})}function de(s){const o=C.current;C.current=null,v(null),o==null||o(s)}async function Ie(){if(!await ce({message:"是否回写",confirmLabel:"确认",cancelLabel:"返回"}))return;let o=n;be.length>0&&(o=a??n,i(o),x(null)),l(!0);const j=!e.documentId;try{const M=await e.onComplete({markdown:o,documentId:e.documentId,displayName:d.trim()||"未命名"}),T=M&&typeof M=="object"&&typeof M.documentId=="string"?M.documentId.trim():"";if(j&&T&&N)try{await _e(N,T)}catch{}e.onClose()}catch(M){if(M!=null&&M.silent||M instanceof Error&&M.message==="cancelled")return;P(M instanceof Error?M.message:String(M))}finally{l(!1)}}async function ve(){var s;(n!==h||a!=null)&&!await ce({message:"取消帮写?未写回的修改将丢失。",confirmLabel:"放弃修改",danger:!0})||((s=A.current)==null||s.abort(),e.onClose())}return t.jsxs("div",{className:"mdocs-ai-write-overlay",role:"dialog","aria-modal":"true","aria-label":"帮写",children:[t.jsxs("header",{className:"mdocs-ai-write-header",children:[t.jsxs("div",{className:"mdocs-ai-write-header-left",children:[t.jsx("img",{src:$e,alt:"",className:"mdocs-ai-write-title-logo"}),t.jsx("strong",{children:"帮写"}),t.jsx("input",{className:"mdocs-ai-write-title",value:d,onChange:s=>y(s.target.value),"aria-label":"文档标题"})]}),t.jsxs("div",{className:"mdocs-ai-write-header-actions",children:[t.jsx("button",{type:"button",onClick:()=>void ve(),disabled:Y||k!=null,children:"取消"}),t.jsx("button",{type:"button",className:"mdocs-ai-write-primary",onClick:()=>void Ie(),disabled:Y||k!=null,children:Y?"写回中…":"完成并写回"})]})]}),t.jsxs("div",{className:"mdocs-ai-write-body",children:[t.jsxs("section",{className:"mdocs-ai-write-chat",children:[t.jsxs("div",{className:"mdocs-ai-write-chat-toolbar",children:[t.jsx("span",{className:"mdocs-ai-write-chat-toolbar-label",children:"对话"}),t.jsxs("div",{className:"mdocs-ai-write-chat-toolbar-actions",children:[t.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn",title:"新会话","aria-label":"新会话",disabled:L,onClick:()=>void Se(),children:t.jsx(Oe,{size:16,strokeWidth:1.8})}),t.jsx("button",{type:"button",className:"mdocs-agent-panel-icon-btn"+(g?" active":""),title:"历史会话","aria-label":"历史会话",onClick:()=>b(s=>!s),children:t.jsx(He,{size:16,strokeWidth:1.8})})]})]}),g?t.jsxs("div",{className:"mdocs-ai-write-history mdocs-agent-panel-history",children:[t.jsxs("div",{className:"mdocs-agent-panel-history-head",children:[t.jsx("span",{children:"历史会话"}),t.jsx("button",{type:"button",className:"mdocs-agent-panel-history-back",onClick:()=>b(!1),children:"返回对话"})]}),$?t.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"加载中…"}):_.length===0?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"mdocs-agent-panel-history-empty",children:"暂无历史会话"}),t.jsx("p",{className:"mdocs-agent-panel-history-hint",children:"发一条消息后会出现在这里"})]}):t.jsx("ul",{className:"mdocs-agent-panel-history-list",children:_.map(s=>t.jsx("li",{children:t.jsxs("button",{type:"button",className:"mdocs-agent-panel-history-item"+(s.id===N?" active":""),disabled:L,onClick:()=>void Ce(s.id),children:[t.jsx("span",{className:"mdocs-agent-panel-history-title",children:s.title}),t.jsx("span",{className:"mdocs-agent-panel-history-time",children:st(s.updatedAt)})]})},s.id))})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mdocs-ai-write-chat-scroll-wrap",children:[t.jsx("div",{className:"mdocs-ai-write-chat-messages",ref:I,onScroll:je,children:p.length===0?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"mdocs-ai-write-hint",children:"描述你想写或改的内容。助手可读取右侧当前稿与进场快照,再更新提案;请按段接受或拒绝后完成写回。"}),re?t.jsx(me,{onConfigured:le}):null]}):p.map(s=>t.jsx("div",{className:"mdocs-ai-write-msg"+(s.role==="user"?" mdocs-ai-write-msg-user":""),children:s.role==="user"?t.jsxs(t.Fragment,{children:[s.skillNames&&s.skillNames.length>0?t.jsxs("div",{className:"mdocs-agent-msg-skills",children:["Skill ×",s.skillNames.length]}):null,s.content]}):nt(s.blocks)?t.jsx("div",{className:"mdocs-ai-write-timeline",children:s.blocks.map((o,j)=>o.type==="thinking"?o.text?t.jsxs("details",{className:"mdocs-ai-write-thinking",open:L,children:[t.jsx("summary",{children:"思考中"}),t.jsx("pre",{className:"mdocs-ai-write-thinking-body",children:o.text})]},`${s.id}-think-${j}`):null:o.type==="tool"?t.jsx("p",{className:"mdocs-agent-panel-tool-notice",children:o.text},`${s.id}-tool-${j}`):o.type==="skill_form_card"?t.jsx(Be,{block:o,onResolved:(M,T,z)=>{f(q=>q.map(r=>r.id!==s.id||r.role!=="assistant"?r:{...r,blocks:r.blocks.map(m=>m.type==="skill_form_card"&&m.requestId===M?{...m,status:T,submittedName:T==="submitted"?z:m.submittedName}:m)}))}},`${s.id}-sf-${j}`):o.type==="choice_card"?t.jsx(Je,{block:o,onResolved:(M,T,z)=>{f(q=>q.map(r=>r.id!==s.id||r.role!=="assistant"?r:{...r,blocks:r.blocks.map(m=>m.type==="choice_card"&&m.requestId===M?{...m,status:z,selected:z==="selected"?T:m.selected}:m)}))}},`${s.id}-ch-${j}`):o.type==="text"&&o.text?t.jsx("div",{className:"mdocs-agent-panel-md",children:t.jsx(We,{remarkPlugins:[ze],children:o.text})},`${s.id}-text-${j}`):null)}):L?t.jsxs("span",{className:"mdocs-agent-panel-thinking","aria-label":"思考中",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]}):null},s.id))}),O?t.jsxs("button",{type:"button",className:"mdocs-chat-jump-bottom",onClick:Ne,title:"回到底部","aria-label":"回到底部",children:[t.jsx(Fe,{size:14,strokeWidth:2,"aria-hidden":!0}),t.jsx("span",{children:"置底"})]}):null]}),Q?t.jsx("p",{className:"mdocs-ai-write-error",children:Q}):null,re&&p.length>0?t.jsx(me,{onConfigured:le}):null,t.jsxs("div",{className:"mdocs-ai-write-input-row",children:[t.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:6},children:[t.jsx(Ke,{selectedNames:F,onChange:K,disabled:L||!(S!=null&&S.enabled)}),t.jsx("textarea",{rows:2,value:D,disabled:L||!(S!=null&&S.enabled),placeholder:S!=null&&S.enabled?"说说要写什么…":"请先配置 API Key",onChange:s=>R(s.target.value),onKeyDown:s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),oe())}})]}),t.jsx("button",{type:"button",className:L?"mdocs-ai-write-stop":void 0,disabled:L?!1:!(S!=null&&S.enabled),onClick:()=>{var s;if(L){(s=A.current)==null||s.abort();return}oe()},children:L?"停止":"发送"})]})]})]}),t.jsx(Ze,{currentMd:n,proposedMd:a,sending:L,onCurrentChange:i,onProposedChange:x})]}),k?t.jsx(Re,{message:k.message,confirmLabel:k.confirmLabel,cancelLabel:k.cancelLabel,danger:k.danger,onConfirm:()=>de(!0),onCancel:()=>de(!1)}):null]})}export{ut as AiWriteWorkbench};
|
package/dist/web/assets/{DiagramEditor-NtNY3sZL-BhsjOCtK.js → DiagramEditor-NtNY3sZL-CyddeNUo.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Q as I,S as H,T as F,U as O,V as G}from"./react-
|
|
1
|
+
import{Q as I,S as H,T as F,U as O,V as G}from"./react-8gAAnUbI.js";import{r as c,j as e}from"./react-vendor-BVS1XoFi.js";import{ensureMeta2dShapes as X,generateSvgFromMeta2d as Q,generateSvgFromDiagram as Y}from"./meta2dEngine-BD2XbzaV-BDjANcdr.js";import{M as _}from"./meta2d-DP4Vt_ZE.js";import"./editor-DBWWidi3.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./index-CINfyH_g.js";import"./plus-BxZJ-Mya.js";import"./check--tqH9AMO.js";import"./copy-5mwMd6zK.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};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{r as f,j as n}from"./react-vendor-BVS1XoFi.js";import{o as C,c as B,T as A,U as S,V as k,l as j,W as v,Y as I,Z as W,S as z,_ as H}from"./index-CINfyH_g.js";import{g as O}from"./file-type-policy-C6Nun42Q.js";/**
|
|
2
|
+
* @license lucide-react v0.562.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const R=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],T=C("chevron-up",R);/**
|
|
7
|
+
* @license lucide-react v0.562.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const L=[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],K=C("text-align-justify",L);function N(){if(typeof navigator>"u")return!1;const e=navigator.userAgent||"",a=navigator.platform||"";return/Mac|iPhone|iPad|iPod/i.test(a)||/Mac OS X|Macintosh/i.test(e)}function U(){return N()?"⌘+Enter":"Alt+Enter"}function _(e){return e.key!=="Enter"||e.shiftKey||e.ctrlKey?!1:N()?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}function $(e){const{t:a,lang:r}=B(),l=O(e.fileType||"md"),D=!!(l!=null&&l.aiWrite&&e.onAiWrite),P=!!(l!=null&&l.comments&&e.onToggleComments),u=e.canEdit&&(e.editing||!!e.actionsAlwaysVisible),[s,M]=f.useState(!1),h=e.domains.length?e.domains:[A],y=!e.readerChrome&&!!e.onPublish&&u&&!e.busy;f.useEffect(()=>{if(!y)return;const t=o=>{var d;_(o)&&(o.preventDefault(),(d=e.onPublish)==null||d.call(e))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[y,e.onPublish]);const E=e.readerChrome?a("publish"):a("publishHotkeyHint",{hotkey:U()}),w=n.jsxs("span",{className:"mdocs-save-indicator","aria-live":"polite",children:[n.jsx("span",{className:"mdocs-save-dot "+(e.busy?"saving":e.draftExists?"unsaved":"saved")}),n.jsx("span",{children:e.busy?a("publishing"):e.draftExists?a("unsaved"):a("published")})]}),c="mdocs-editor-toolbar"+(e.readerChrome?e.readerHeaderDocked?" mdocs-editor-toolbar--docked":" mdocs-editor-toolbar--float":""),m=e.readerChrome&&!e.readerHeaderDocked&&e.readerDragOffset?{transform:`translateY(${e.readerDragOffset}px)`}:void 0;if(e.readerChrome){const t=n.jsxs("div",{className:"mdocs-editor-toolbar-leading",onPointerDown:e.onReaderHeaderPointerDown,onPointerMove:e.onReaderHeaderPointerMove,onPointerUp:e.onReaderHeaderPointerUp,onPointerCancel:e.onReaderHeaderPointerUp,children:[n.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>{var i;return(i=e.onOpenMobileNav)==null?void 0:i.call(e)},"aria-label":a("expandSidebar"),children:n.jsx(S,{size:18,strokeWidth:1.75})}),n.jsx("input",{className:"mdocs-editor-title-input",value:e.displayName,onChange:i=>e.onDisplayNameChange(i.target.value),onBlur:e.onDisplayNameBlur,placeholder:a("displayNamePlaceholder"),disabled:!e.editing,readOnly:!e.editing})]}),o=n.jsx(k,{domains:h,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:i=>j(i,r,a)}),d=e.canEdit&&e.onPublish?n.jsx("button",{type:"button",className:"primary mdocs-reader-action-btn",disabled:e.busy,onMouseDown:i=>i.preventDefault(),onClick:()=>{var i,x;e.editing||(i=e.onEnterEdit)==null||i.call(e),(x=e.onPublish)==null||x.call(e)},children:e.busy?a("publishing"):a("publish")}):null,b=e.onSyncClick?n.jsx("button",{type:"button",className:"mdocs-sync-btn mdocs-reader-sync-btn"+(e.syncBehind?" behind":""),"aria-label":e.syncBehind?a("syncBehindHint"):a("syncPull"),onClick:()=>{var i;return void((i=e.onSyncClick)==null?void 0:i.call(e))},children:n.jsx(v,{size:16,strokeWidth:1.75})}):null,g=e.readerMoreMenu!=null?n.jsxs("div",{ref:e.readerMoreMenuRef,className:"mdocs-reader-more-menu",children:[n.jsx("button",{type:"button",className:"mdocs-reader-more-btn","aria-label":"更多","aria-expanded":e.readerMoreOpen,onClick:()=>{var i;return(i=e.onToggleReaderMore)==null?void 0:i.call(e)},children:n.jsx(I,{size:18,strokeWidth:1.75})}),e.readerMoreOpen?n.jsx("div",{className:"mdocs-reader-more-dropdown card",children:e.readerMoreMenu}):null]}):null;return e.readerActionsCollapsible?n.jsxs("div",{className:c+" mdocs-editor-toolbar--stacked",style:m,children:[n.jsxs("div",{className:"mdocs-reader-top-row",children:[t,b,n.jsx("button",{type:"button",className:"mdocs-reader-expand-btn",onClick:()=>M(i=>!i),"aria-label":s?"收起操作栏":"展开操作栏",children:n.jsx(T,{size:16,strokeWidth:2,style:{transform:s?"rotate(0deg)":"rotate(180deg)",transition:"transform 0.2s"}})}),g]}),s&&n.jsxs("div",{className:"mdocs-reader-actions-row",children:[o,e.leadingExtra,d,e.trailingExtra]})]}):n.jsxs("div",{className:c,style:m,children:[t,o,e.leadingExtra,b,d,g,e.trailingExtra]})}return n.jsxs("div",{className:c,style:m,children:[n.jsxs("div",{className:"mdocs-editor-toolbar-leading",children:[n.jsx("input",{className:"mdocs-editor-title-input",value:e.displayName,onChange:t=>e.onDisplayNameChange(t.target.value),onBlur:e.onDisplayNameBlur,placeholder:a("displayNamePlaceholder"),disabled:!e.editing}),n.jsx(k,{domains:h,value:e.currentDomainId,onChange:e.onDomainChange,onDomainsChange:e.onDomainsChange,ariaLabel:a("currentDomainAria"),localizeName:t=>j(t,r,a)}),D?n.jsxs("button",{type:"button",className:"secondary",onClick:()=>{var t;return(t=e.onAiWrite)==null?void 0:t.call(e)},style:{padding:"4px 10px",whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",gap:6},children:[n.jsx("img",{src:W,alt:"",width:16,height:16,style:{display:"block"}}),"帮写"]}):null,e.leadingExtra]}),n.jsx("span",{className:"mdocs-editor-toolbar-spacer","aria-hidden":!0}),n.jsxs("div",{className:"mdocs-editor-toolbar-trailing",children:[e.onToggleBookmark?n.jsxs("button",{type:"button",className:"ghost mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>{var t;return(t=e.onToggleBookmark)==null?void 0:t.call(e)},disabled:e.bookmarkBusy,"data-tooltip":e.isBookmarked?"取消收藏":"收藏",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,opacity:e.bookmarkBusy?.5:1},children:[n.jsx(z,{size:18,strokeWidth:1.5,style:{color:e.isBookmarked?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:e.isBookmarked?"#faad14":"none"}}),e.isBookmarked?n.jsx("span",{children:"已收藏"}):null]}):null,n.jsxs("div",{className:"mdocs-editor-toolbar-actions",children:[e.onSyncClick?n.jsxs("button",{type:"button",className:"mdocs-sync-btn mdocs-tooltip mdocs-tooltip-bottom"+(e.syncBehind?" behind":""),"data-tooltip":e.syncBehind?a("syncBehindHint"):a("syncPull"),onClick:()=>{var t;return void((t=e.onSyncClick)==null?void 0:t.call(e))},style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx(v,{size:16,strokeWidth:1.5}),n.jsx("span",{children:a("syncPull")})]}):null,u?n.jsxs(n.Fragment,{children:[w,e.onPublish?n.jsx("button",{type:"button",className:"primary mdocs-tooltip mdocs-tooltip-bottom",disabled:e.busy,"data-tooltip":E,onMouseDown:t=>t.preventDefault(),onClick:()=>{var t;return(t=e.onPublish)==null?void 0:t.call(e)},children:e.busy?a("publishing"):a("publish")}):null,e.onDelete?n.jsx("button",{type:"button",className:"danger",disabled:e.busy,onClick:()=>{var t;return(t=e.onDelete)==null?void 0:t.call(e)},children:a("delete")}):null]}):null,!e.editing&&e.canEdit&&e.onEnterEdit&&!e.actionsAlwaysVisible?n.jsx("button",{type:"button",className:"primary",onClick:()=>{var t;return(t=e.onEnterEdit)==null?void 0:t.call(e)},children:a("edit")}):null,e.trailingExtra,P?n.jsxs("button",{type:"button",className:"ghost mdocs-tooltip mdocs-tooltip-bottom",onClick:()=>{var t;return(t=e.onToggleComments)==null?void 0:t.call(e)},"data-tooltip":"评论",style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:e.commentPanelOpen?"var(--mdocs-hover-bg, #f0f0f0)":void 0},children:[n.jsx(H,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}}),e.commentCount&&e.commentCount>0?n.jsx("span",{style:{fontSize:"0.85rem"},children:e.commentCount}):null]}):null,e.onToggleDocInfo?n.jsxs("div",{ref:e.docInfoMenuRef,className:"mdocs-tooltip mdocs-tooltip-bottom","data-tooltip":a("docInfo"),style:{position:"relative"},children:[n.jsx("button",{type:"button",className:"secondary",onClick:()=>{var t;return(t=e.onToggleDocInfo)==null?void 0:t.call(e)},style:{padding:"4px 8px",minWidth:"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:n.jsx(K,{size:18,strokeWidth:1.5,style:{color:"var(--mdocs-text-secondary, #6b7280)"}})}),e.docInfoOpen?n.jsx("div",{className:"mdocs-doc-info-dropdown",children:e.docInfoMenu}):null]}):null]})]})]})}export{$ as D};
|