-`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`${n}>
-`}strong({tokens:e}){return`${this.parser.parseInline(e)}`}em({tokens:e}){return`${this.parser.parseInline(e)}`}codespan({text:e}){return`${B(e,!0)}`}br(e){return` `}del({tokens:e}){return`${this.parser.parseInline(e)}`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=Gn(e);if(i===null)return r;e=i;let a=``+r+``,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=Gn(e);if(i===null)return B(n);e=i;let a=``,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:B(e.text)}},$n=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}},H=class e{constructor(e){F(this,`options`,void 0),F(this,`renderer`,void 0),F(this,`textRenderer`,void 0),this.options=e||Lt,this.options.renderer=this.options.renderer||new Qn,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new $n}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e,t=!0){let n=``;for(let r=0;r{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new Qn(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new Zn(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new er;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=er.passThroughHooks.has(n)?e=>{if(this.defaults.async&&er.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return V.lex(e,t??this.defaults)}parser(e,t){return H.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer():e?V.lex:V.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser():e?H.parse:H.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer():e?V.lex:V.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser():e?H.parse:H.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
-Please report this to https://github.com/markedjs/marked.`,e){let e=`
An error occurred:
`+B(n.message+``,!0)+`
`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function U(e,t){return tr.parse(e,t)}U.options=U.setOptions=function(e){return tr.setOptions(e),U.defaults=tr.defaults,Rt(U.defaults),U},U.getDefaults=It,U.defaults=Lt,U.use=function(...e){return tr.use(...e),U.defaults=tr.defaults,Rt(U.defaults),U},U.walkTokens=function(e,t){return tr.walkTokens(e,t)},U.parseInline=tr.parseInline,U.Parser=H,U.parser=H.parse,U.Renderer=Qn,U.TextRenderer=$n,U.Lexer=V,U.lexer=V.lex,U.Tokenizer=Zn,U.Hooks=er,U.parse=U,U.options,U.setOptions,U.use,U.walkTokens,U.parseInline,H.parse,V.lex;function nr(e,t){this.v=e,this.k=t}function rr(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`?null:Y(BigInt.prototype.toString),zr=typeof Symbol>`u`?null:Y(Symbol.prototype.toString),K=Y(Object.prototype.hasOwnProperty),Br=Y(Object.prototype.toString),Vr=RegExp.prototype.test,q=function(e,t){return e instanceof RegExp&&(e.lastIndex=0),vr(Vr,e,[t])},J=Hr(TypeError);function Y(e){return function(t){var n=[...arguments].slice(1);return vr(e,t,n)}}function Hr(e){return function(){return yr(e,[...arguments])}}function X(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ar;if(fr&&fr(e,null),!Er(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(pr(t)||(t[r]=e),i=e)}e[i]=!0}return e}function Ur(e){for(let t=0;t/g),ci=G(/\${[\w\W]*/g),li=G(/{{|}}|\${|<%|%>|<%|%>/),ui=G(/^data-[\-\w.\u00B7-\uFFFF]+$/),di=G(/^aria-[\-\w]+$/),fi=G(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),pi=G(/^(?:\w+script|data):/i),mi=G(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),hi=G(/^html$/i),gi=G(/^[a-z][.\w]*(-[.\w]+)+$/i),_i=G(/<[/\w!]/g),vi=G(/<[/\w]/g),yi=G(/<\/no(script|embed|frames)/i),bi=G(/\/>/i),xi=G(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i),Si=G(/^[\r\n\t ]+/),Q={element:1,text:3,processingInstruction:7,comment:8,document:9,documentFragment:11},Ci=W(X({},[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`])),wi=function(){return typeof window>`u`?null:window},Ti=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},Ei=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Di=function(e,t,n,r){return K(e,t)&&Er(e[t])?X(r.base?Gr(r.base):{},e[t],r.transform):n},Oi=function(e,t,n){let r=K(e,t)?e[t]:void 0;return r&&typeof r==`object`?Wr(r):n};function ki(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:wi(),t=e=>ki(e);if(t.version=`3.4.18`,t.removed=[],!e||!e.document||e.document.nodeType!==Q.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript,a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter,l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=Z(d,`cloneNode`),p=Z(d,`remove`),m=Z(d,`removeAttributeNode`),h=Z(d,`nextSibling`),g=Z(d,`childNodes`),_=Z(d,`parentNode`),ee=Z(d,`shadowRoot`),te=Z(d,`attributes`),ne=o&&o.prototype?Z(o.prototype,`nodeType`):null,v=o&&o.prototype?Z(o.prototype,`nodeName`):null,y=o&&o.prototype?Z(o.prototype,`ownerDocument`):null,b=function(e){return ne?ne(e):e.nodeType},x=function(e){return v?v(e):e.nodeName},re=qr(d,`namespaceURI`),ie=function(e){return re?re(e):e.namespaceURI};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let S,ae=``,oe,se=!1,ce=0,le=function(){if(ce>0)throw J(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},ue=function(e){le(),ce++;try{return S.createHTML(e)}finally{ce--}},de=function(e){return S&&Ge?ue(e):e},fe=function(e){le(),ce++;try{return S.createScriptURL(e)}finally{ce--}},pe=function(){return se||(oe=Ti(u,i),se=!0),oe},me=n,he=me.implementation,ge=me.createNodeIterator,_e=me.createDocumentFragment,ve=me.getElementsByTagName,ye=r.importNode,C=Ei();t.isSupported=typeof ur==`function`&&typeof _==`function`&&he&&he.createHTMLDocument!==void 0;let be=oi,xe=si,Se=ci,Ce=ui,we=di,Te=pi,Ee=mi,De=gi,Oe=fi,w=null,ke=X({},[...Yr,...Xr,...Zr,...$r,...ti]),T=null,Ae=X({},[...ni,...ri,...ii,...ai]),E=null,je=null,Me=null,Ne=Object.seal(gr(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Pe=!0,Fe=!0,Ie=!1,Le=!0,D=!1,Re=!0,ze=!1,Be=!1,Ve=null,He=null,Ue=!1,O=!1,We=!1,Ge=!1,Ke=!0,qe=!1,Je=`user-content-`,Ye=!0,Xe=!1,Ze=null,Qe=!1,k=null,$e=X({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),et=null,A=X({},[`audio`,`video`,`img`,`source`,`image`,`track`]),j=null,tt=X({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),nt=`http://www.w3.org/1998/Math/MathML`,rt=`http://www.w3.org/2000/svg`,M=`http://www.w3.org/1999/xhtml`,it=M,at=!1,ot=null,st=X({},[nt,rt,M],jr),ct=W(X({},[`mi`,`mo`,`mn`,`ms`,`mtext`])),lt=null,ut=W(X({},[`annotation-xml`])),dt=null,ft=W(gr(null)),pt=X({},[`title`,`style`,`font`,`a`,`script`]),mt=null,ht=[`application/xhtml+xml`,`text/html`],N=null,gt=null,_t=n.createElement(`form`),vt=function(e){return e instanceof RegExp||e instanceof Function},P=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};e&&typeof e==`object`||(e={}),e=Wr(e),mt=ht.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,N=mt===`application/xhtml+xml`?jr:Ar,w=Di(e,`ALLOWED_TAGS`,ke,{transform:N}),T=Di(e,`ALLOWED_ATTR`,Ae,{transform:N}),ot=Di(e,`ALLOWED_NAMESPACES`,st,{transform:jr}),j=Di(e,`ADD_URI_SAFE_ATTR`,tt,{transform:N,base:tt}),et=Di(e,`ADD_DATA_URI_TAGS`,A,{transform:N,base:A}),k=Di(e,`FORBID_CONTENTS`,$e,{transform:N}),je=Di(e,`FORBID_TAGS`,gr(null),{transform:N}),Me=Di(e,`FORBID_ATTR`,gr(null),{transform:N}),Qe=K(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?Wr(e.USE_PROFILES):e.USE_PROFILES:!1,Pe=e.ALLOW_ARIA_ATTR!==!1,Fe=e.ALLOW_DATA_ATTR!==!1,Ie=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Le=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,D=e.SAFE_FOR_TEMPLATES||!1,Re=e.SAFE_FOR_XML!==!1,ze=e.WHOLE_DOCUMENT||!1,O=e.RETURN_DOM||!1,We=e.RETURN_DOM_FRAGMENT||!1,Ge=e.RETURN_TRUSTED_TYPE||!1,Ue=e.FORCE_BODY||!1,Ke=e.SANITIZE_DOM!==!1,qe=e.SANITIZE_NAMED_PROPS||!1,Ye=e.KEEP_CONTENT!==!1,Xe=e.IN_PLACE||!1,Oe=Jr(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:fi,it=typeof e.NAMESPACE==`string`?e.NAMESPACE:M,lt=Oi(e,`MATHML_TEXT_INTEGRATION_POINTS`,ct),dt=Oi(e,`HTML_INTEGRATION_POINTS`,ut);let t=Oi(e,`CUSTOM_ELEMENT_HANDLING`,ft);if(E=gr(null),K(t,`tagNameCheck`)&&vt(t.tagNameCheck)&&(E.tagNameCheck=t.tagNameCheck),K(t,`attributeNameCheck`)&&vt(t.attributeNameCheck)&&(E.attributeNameCheck=t.attributeNameCheck),K(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(E.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),G(E),D&&(Fe=!1),We&&(O=!0),Qe&&((K(e,`ALLOWED_TAGS`)||K(e,`ALLOWED_ATTR`))&&typeof console<`u`&&typeof console.warn==`function`&&console.warn(`DOMPurify: USE_PROFILES overrides ALLOWED_TAGS and ALLOWED_ATTR. Do not use these options together.`),w=X({},ti),T=gr(null),Qe.html===!0&&(X(w,Yr),X(T,ni)),Qe.svg===!0&&(X(w,Xr),X(T,ri),X(T,ai)),Qe.svgFilters===!0&&(X(w,Zr),X(T,ri),X(T,ai)),Qe.mathMl===!0&&(X(w,$r),X(T,ii),X(T,ai))),Ne.tagCheck=null,Ne.attributeCheck=null,K(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?Ne.tagCheck=e.ADD_TAGS:Er(e.ADD_TAGS)&&(w===ke&&(w=Gr(w)),X(w,e.ADD_TAGS,N))),K(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?Ne.attributeCheck=e.ADD_ATTR:Er(e.ADD_ATTR)&&(T===Ae&&(T=Gr(T)),X(T,e.ADD_ATTR,N))),K(e,`ADD_FORBID_CONTENTS`)&&Er(e.ADD_FORBID_CONTENTS)&&(k===$e&&(k=Gr(k)),X(k,e.ADD_FORBID_CONTENTS,N)),Ye&&(w[`#text`]=!0),ze&&X(w,[`html`,`head`,`body`]),w.table&&(w.tbody=!0,delete je.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw J(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw J(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=S;S=e.TRUSTED_TYPES_POLICY;try{ae=ue(``)}catch(e){throw S=t,e}}else e.TRUSTED_TYPES_POLICY===null?(S=void 0,ae=``):(S===void 0&&(S=pe()),S&&typeof ae==`string`&&(ae=ue(``)));gt=W(e)},yt=X({},[...Xr,...Zr,...Qr]),bt=X({},[...$r,...ei]),xt=function(e,t,n){return t===M?e===`svg`:t===nt?e===`svg`&&(n===`annotation-xml`||lt[n]):!!yt[e]},St=function(e,t,n){return t===M?e===`math`:t===rt?e===`math`&&dt[n]:!!bt[e]},Ct=function(e,t,n){return t===rt&&!dt[n]||t===nt&&!lt[n]?!1:!bt[e]&&(pt[e]||!yt[e])},wt=function(e){let t=ie(e),n=Ar(x(e)),r=_(e),i=it,a=`template`;return r&&b(r)===Q.element&&(i=ie(r),a=Ar(x(r))),ot[t]?t===rt?xt(n,i,a):t===nt?St(n,i,a):t===M?Ct(n,i,a):mt===`application/xhtml+xml`:!1},Tt=function(e){Cr(t.removed,{element:e});try{_(e).removeChild(e)}catch{if(p(e),!_(e))throw J(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},Et=function(e,t,n){try{m(e,t)}catch{try{e.removeAttribute(n)}catch{}}},Dt=function(e){jt(e);let t=g(e);t&&br(wr(t),e=>{try{p(e)}catch{}}),b(e)===Q.element&&kt(e,!1)},Ot=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}if(Cr(t.removed,{attribute:r||null,from:n}),r)Et(n,r,e);else try{n.removeAttribute(e)}catch{}if(e===`is`){if(O||We)try{Tt(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},kt=function(e,t){let n=te(e);if(n)for(let r=n.length-1;r>=0;--r){let i=n[r],a=i&&i.name;typeof a==`string`&&!(t&&T[N(a)])&&Et(e,i,a)}},At=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0&&arguments[2],r=[e];for(;r.length>0;){let e=r.pop();if(t(e)===!1)continue;if(n&&b(e)===Q.element){let t=ee(e);R(t)&&r.push(t)}let i=g(e);if(i)for(let e=i.length-1;e>=0;--e)r.push(i[e])}},jt=function(e){At(e,e=>{b(e)===Q.element&&kt(e,!0)})},Mt=function(e){let t=[];return At(e,e=>{t.push(e)},!0),t},Nt=function(e,t){let n=Dr();br(Mt(e),e=>{b(e)===Q.element&&Or(n,e)}),br(t,e=>{b(e)===Q.element&&!kr(n,e)&&kt(e,!0)})},Pt=function(e,n){let r=!1;return br(t.removed,t=>{t.element&&(r=r||t.element===e,jt(t.element))}),Nt(e,n),r},F=function(e,t){let n=Ze,r=null,i=()=>(r||(r=Dr(),br(t,e=>{Or(r,e)})),r);for(let t=0;;t++){let r=Mt(e),a=[e],o=!1;if(br(r,e=>{b(e)===Q.documentFragment?Cr(a,e):!o&&!kr(n,e)&&(o=kr(i(),e))}),!o)return;if(t>=8)throw J(`the tree kept changing during in-place sanitization; refusing to return it`);br(a,(t,n)=>{Ft(t,n>0,e,i())})}},Ft=function(e,t,n,r){let i=I(e),a;for(;a=i.nextNode();)kr(r,a)&&!kr(Ze,a)&&(t&&z(C.uponSanitizeShadowNode,a,null),an(a,n))},It=function(e){Ze&&Or(Ze,e)},Lt=function(e,t){return Re?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},Rt=function(e){Re&&At(e,e=>{let t=b(e);if(t===Q.processingInstruction||t===Q.comment&&q(vi,e.data)){try{p(e)}catch{}return!1}if(t===Q.element){let t=e,n=N(x(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&Lt(`for`,n)&&t.removeAttribute(`for`)}catch{}}return!0})},zt=function(e){let t=null,r=null;if(Ue)e=``+e;else{let t=Mr(e,Si);r=t&&t[0]}mt===`application/xhtml+xml`&&it===M&&(e=``+e+``);let i=S?ue(e):e;if(it===M)try{t=new l().parseFromString(i,mt)}catch{}if(!t||!t.documentElement){t=he.createDocument(it,`template`,null);try{t.documentElement.innerHTML=at?ae:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),it===M?ve.call(t,ze?`html`:`body`)[0]:ze?t.documentElement:a},I=function(e){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=y?y(e):e.ownerDocument;return ge.call(n||e,e,(t?0:c.SHOW_ELEMENT)|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Bt=function(e){return e=Nr(e,be,` `),e=Nr(e,xe,` `),e=Nr(e,Se,` `),e},L=function(e){Vt(e);let t=e.querySelectorAll?.call(e,`template`);t&&br(t,e=>{R(e.content)&&L(e.content)})},Vt=function(e){e.normalize();let t=I(e,!0),n=t.nextNode();for(;n;)n.data=Bt(n.data),n=t.nextNode()},Ht=function(e){let t=v?v(e):null;return typeof t!=`string`||N(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==te(e)||typeof e.removeAttribute!=`function`||typeof e.removeAttributeNode!=`function`||typeof e.getAttributeNode!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==ne(e)||e.childNodes!==g(e)},Ut=function(e){if(!ne||typeof e!=`object`||!e)return null;try{let t=ne(e);return typeof t==`number`?t:null}catch{return null}},R=function(e){return Ut(e)===Q.documentFragment},Wt=function(e){return Ut(e)!==null};function z(e,n,r){e.length!==0&&br(e,e=>{e.call(t,n,r,gt)})}let Gt=function(e,t,n){return!!(Re&&n===Q.element&&e.hasChildNodes()&&!Wt(e.firstElementChild)&&q(_i,e.textContent)&&q(_i,e.innerHTML)||Re&&Ci[t]&&n===Q.element&&ie(e)===M&&(Wt(e.firstElementChild)||typeof e.textContent==`string`&&q(_i,e.textContent))||n===Q.processingInstruction||Re&&n===Q.comment&&q(vi,e.data))},Kt=function(e,t){return e instanceof RegExp?q(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},qt=function(e,t,n){if(!je[t]&&$t(t)&&Kt(E.tagNameCheck,t))return!1;if(Ye&&!k[t]&&!k[Ar(t)]){let t=_(e),r=g(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,h(e))}}}return Tt(e),!0},Jt=function(e,t,n,r){return e.length===0?t:t===n||t===r?Gr(t):t},Yt=function(e,t){return e===t||_(e)!==null?!1:(Xe&&jt(e),!0)},Xt=function(e,n){if(It(e),z(C.beforeSanitizeElements,e,null),Yt(e,n))return!0;if(Ht(e))return Tt(e),!0;let r=N(x(e)),i=b(e);if(w=Jt(C.uponSanitizeElement,w,ke,Ve),z(C.uponSanitizeElement,e,{tagName:r,allowedTags:w}),Yt(e,n))return!0;if(Gt(e,r,i))return Tt(e),!0;if(je[r]||!(Ne.tagCheck instanceof Function&&Ne.tagCheck(r))&&!w[r]){let t=qt(e,r,n);return t===!1&&(z(C.afterSanitizeElements,e,null),Yt(e,n))?!0:t}if(i===Q.element&&!wt(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&q(yi,e.innerHTML))return Tt(e),!0;if(D&&i===Q.text){let n=e.textContent,r=Bt(n);n!==r&&(Cr(t.removed,{element:e.cloneNode()}),e.textContent=r)}return z(C.afterSanitizeElements,e,null),Yt(e,n)},Zt=function(e,t,r){if(Me[t]||Lt(t,e)||Ke&&(t===`id`||t===`name`)&&(r in n||r in _t))return!1;let i=T[t]||Ne.attributeCheck instanceof Function&&Ne.attributeCheck(t,e);if(Fe&&q(Ce,t)||Pe&&q(we,t))return!0;if(!i)return $t(e)&&Kt(E.tagNameCheck,e)&&Kt(E.attributeNameCheck,t,e)||t===`is`&&E.allowCustomizedBuiltInElements&&Kt(E.tagNameCheck,r);if(j[t])return!0;let a=Nr(r,Ee,``);return q(Oe,a)||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&Pr(r,`data:`)===0&&et[e]||Ie&&!q(Te,a)?!0:!r},Qt=X({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),$t=function(e){return!Qt[Ar(e)]&&q(De,e)},en=function(e,t,n,r){if(S&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return ue(r);case`TrustedScriptURL`:return fe(r)}return r},tn=function(e,t,n,r){try{return n?e.setAttributeNS(n,t,r):e.setAttribute(t,r),!Ht(e)||(Tt(e),!1)}catch{return Ot(t,e),!1}},nn=function(e,t){return Re&&q(xi,t)?!0:Ar(e)===`attributename`&&Pr(t,`href`)!==-1},rn=function(e,n){if(z(C.beforeSanitizeAttributes,e,null),Yt(e,n))return;let r=e.attributes;if(!r||Ht(e))return;T=Jt(C.uponSanitizeAttribute,T,Ae,He);let i={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:T,forceKeepAttr:void 0},a=r.length,o=N(x(e));for(;a--;){let n=r[a],s=n.name,c=n.namespaceURI,l=n.value,u=N(s),d=l,f=s===`value`?d:Fr(d),p=!1;i.attrName=u,i.attrValue=f,i.keepAttr=!0,i.forceKeepAttr=void 0,z(C.uponSanitizeAttribute,e,i),f=i.attrValue,qe&&(u===`id`||u===`name`)&&Pr(f,Je)!==0&&(Ot(s,e,n),f=Je+f,p=!0),nn(s,f)?Ot(s,e,n):i.forceKeepAttr||(i.keepAttr?!Le&&q(bi,f)?Ot(s,e,n):(D&&(f=Bt(f)),Zt(o,u,f)?(f=en(o,u,c,f),f!==d&&tn(e,s,c,f)&&p&&Sr(t.removed)):Ot(s,e,n)):Ot(s,e,n))}z(C.afterSanitizeAttributes,e,null),Yt(e,n)},an=function(e,t){Xt(e,t),rn(e,t),R(e.content)&&on(e.content)},on=function(e){let t=null,n=I(e);for(z(C.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(z(C.uponSanitizeShadowNode,t,null),an(t,e),b(t)===Q.element){let e=ee(t);R(e)&&(sn(e),on(e))}D&&Vt(e),z(C.afterSanitizeShadowDOM,e,null)},sn=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){on(e.shadow);continue}let n=e.node,r=b(n)===Q.element,i=g(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=v?v(n):null;if(typeof e==`string`&&N(e)===`template`){let e=n.content;R(e)&&t.push({node:e,shadow:null})}}if(r){let e=ee(n);R(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(at=!e,at&&(e=``),typeof e!=`string`&&!Wt(e)&&(e=Kr(e),typeof e!=`string`))throw J(`dirty is not a string, aborting`);if(!t.isSupported)return e;Be?(w=Ve,T=He):P(n),t.removed=[];let c=Xe&&typeof e!=`string`&&Wt(e),l=[],u=Ze;if(c){Rt(e);let t=x(e);if(typeof t==`string`){let n=N(t);if(!w[n]||je[n])throw Dt(e),J(`root node is forbidden and cannot be sanitized in-place`)}if(Ht(e))throw Dt(e),J(`root node is clobbered and cannot be sanitized in-place`);l=Mt(e),Ze=Dr()}else if(Wt(e))i=zt(``),a=i.ownerDocument.importNode(e,!0),a.nodeType===Q.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),sn(i);else{if(!O&&!D&&!ze&&e.indexOf(`<`)===-1)return de(e);if(i=zt(e),!i)return O?null:Ge?ae:``}i&&Ue&&Tt(i.firstChild);let d=c?e:i;try{c&&sn(e);let t=I(d);for(;o=t.nextNode();)an(o,d);c&&F(e,l)}catch(t){throw c&&(Dt(e),Pt(e,l)),t}finally{Ze=u}if(c){if(Pt(e,l))throw J(`a node selected for removal could not be safely returned; refusing to sanitize in place`);return D&&L(e),e}if(O){if(D&&L(i),We)for(s=_e.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(T.shadowroot||T.shadowrootmode)&&(s=ye.call(r,s,!0)),s}let f=()=>ze?i.outerHTML:i.innerHTML,p=f();return D&&q(li,p)&&(Vt(i),p=f()),ze&&w[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&q(hi,i.ownerDocument.doctype.name)&&(p=`
-`+p),de(p)},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};P(e),Be=!0,Ve=w,He=T},t.clearConfig=function(){gt=null,Be=!1,Ve=null,He=null,S=oe,ae=``},t.isValidAttribute=function(e,t,n){gt||P({});let r=N(e),i=N(t);return typeof n==`string`&&(nn(t,n)||!Le&&q(bi,n))?!1:Zt(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&K(C,e)&&Cr(C[e],t)},t.removeHook=function(e,t){if(K(C,e)){if(t!==void 0){let n=xr(C[e],t);return n===-1?void 0:Tr(C[e],n,1)[0]}return Sr(C[e])}},t.removeHooks=function(e){K(C,e)&&(C[e]=[])},t.removeAllHooks=function(){C=Ei()},t}var Ai=ki(),ji=[`critical`,`high`,`medium`,`low`,`info`],Mi={critical:`red`,high:`orange`,medium:`amber`,low:`blue`,info:`grey`},Ni={critical:`严重`,high:`高危`,medium:`中危`,low:`低危`,info:`信息`},Pi={running:`blue`,pending:`amber`,queued:`amber`,paused:`grey`,success:`green`,succeeded:`green`,completed:`green`,done:`green`,failed:`red`,error:`red`,cancelled:`grey`,canceled:`grey`,stopped:`grey`,active:`green`,inactive:`grey`,online:`green`,offline:`grey`,open:`red`,closed:`green`,archived:`grey`};function Fi(e,t=`zh-CN`){if(!e)return`—`;let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.getTime())?n.toLocaleString(t,{hour12:!1}):`—`}function Ii(e,t=`zh-CN`){if(!e)return`—`;let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.getTime())?n.toLocaleDateString(t):`—`}function Li(e,t){if(!e)return`—`;let n=new Date(e);if(!Number.isFinite(n.getTime()))return`—`;let r=Date.now()-n.getTime();return r<6e4?t?.(`common.justNow`,null,`刚刚`)||`刚刚`:r<36e5?t?.(`common.minutesAgo`,{n:Math.floor(r/6e4)},`${Math.floor(r/6e4)} 分钟前`):r<864e5?t?.(`common.hoursAgo`,{n:Math.floor(r/36e5)},`${Math.floor(r/36e5)} 小时前`):r<2592e6?t?.(`common.daysAgo`,{n:Math.floor(r/864e5)},`${Math.floor(r/864e5)} 天前`):Ii(e)}function Ri(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return`—`;if(t<1024)return`${t} B`;let n=[`KB`,`MB`,`GB`,`TB`],r=t/1024,i=0;for(;r>=1024&&i=100?0:1)} ${n[i]}`}function zi(e,t=`zh-CN`){let n=Number(e);return Number.isFinite(n)?n.toLocaleString(t):`—`}function Bi(e,t=1){let n=Number(e);return Number.isFinite(n)?`${(n*(n<=1?100:1)).toFixed(t)}%`:`—`}function Vi(e){return Mi[String(e||``).toLowerCase()]||`grey`}function Hi(e){return Pi[String(e||``).toLowerCase()]||`grey`}function Ui(e,t=120){let n=String(e??``);return n.length>t?`${n.slice(0,t)}…`:n}var{Title:Wi,Text:Gi,Paragraph:Ki}=c;function qi(e){Ce.success({content:e,duration:2})}function Ji(e){Ce.warning({content:e,duration:3})}function Yi(e,t=`操作失败`){Ce.error({content:rt(e,t),duration:4})}function Xi({title:e,description:t,extra:n,children:r}){return(0,M.jsxs)(`header`,{className:`cs-page-header`,children:[(0,M.jsxs)(`div`,{className:`cs-page-header-main`,children:[(0,M.jsx)(Wi,{heading:3,className:`cs-page-title`,children:e}),t&&(0,M.jsx)(Gi,{type:`tertiary`,className:`cs-page-desc`,children:t}),r]}),n&&(0,M.jsx)(f,{className:`cs-page-header-extra`,wrap:!0,children:n})]})}function Zi({title:e,description:t,extra:n,children:r,className:i=``,bodyClassName:a=``}){return(0,M.jsxs)(s,{className:`cs-section-card ${i}`,title:e?(0,M.jsx)(`span`,{className:`cs-section-title`,children:e}):void 0,headerExtraContent:n,bordered:!1,children:[t&&(0,M.jsx)(Ki,{type:`tertiary`,className:`cs-section-desc`,children:t}),(0,M.jsx)(`div`,{className:a,children:r})]})}function Qi({metrics:e,columns:t=4}){return(0,M.jsx)(`div`,{className:`cs-stat-grid`,style:{"--cs-stat-columns":t},children:e.map(e=>(0,M.jsx)($i,{...e},e.id||e.label))})}function $i({label:e,value:t,valueTitle:n,detail:r,tone:i,severity:a,icon:o,onClick:c,pressed:l,loading:u=!1}){let d=(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`span`,{className:`cs-stat-head`,children:[(0,M.jsx)(Gi,{type:`tertiary`,className:`cs-stat-label`,children:e}),o&&(0,M.jsx)(`span`,{className:`cs-stat-icon ${i?`tone-${i}`:``}`,"aria-hidden":`true`,children:o})]}),(0,M.jsx)(_,{loading:u,placeholder:(0,M.jsx)(_.Title,{style:{width:`60%`,height:36,margin:`8px 0`}}),children:(0,M.jsx)(`span`,{className:`cs-stat-value ${i?`tone-${i}`:``}`,title:n,children:t??`—`})}),r&&(0,M.jsx)(`span`,{className:`cs-stat-detail`,children:r})]});return c?(0,M.jsx)(b,{className:`cs-stat-card is-clickable`,theme:`borderless`,onClick:c,"aria-label":String(e),"aria-pressed":l,"data-severity":a,children:d}):(0,M.jsx)(s,{className:`cs-stat-card`,"data-severity":a,bordered:!1,children:d})}function ea({columns:e,dataSource:t,rowKey:n=`id`,loading:r,pagination:i,emptyText:a,onRefresh:s,toolbar:c,size:l=`default`,className:u=``,...d}){let f=P(),p=i!==!1&&{pageSize:10,showSizeChanger:!0,pageSizeOpts:[10,20,50,100],showTotal:!0,...i||{}};return(0,M.jsxs)(`div`,{className:`cs-table-wrap ${u}`,children:[(c||s)&&(0,M.jsxs)(`div`,{className:`cs-table-toolbar`,children:[(0,M.jsx)(`div`,{className:`cs-table-toolbar-main`,children:c}),s&&(0,M.jsx)(b,{icon:(0,M.jsx)(T,{}),theme:`borderless`,onClick:s,loading:r,children:f(`common.refresh`,null,`刷新`)})]}),(0,M.jsx)(`div`,{className:`cs-table-scroll`,children:(0,M.jsx)(ke,{columns:e,dataSource:t||[],rowKey:n,loading:r,pagination:p,size:l,empty:(0,M.jsx)(o,{image:(0,M.jsx)(je,{size:`extra-large`}),title:a||f(`common.noData`,null,`暂无数据`),description:null,className:`cs-table-empty`}),...d})})]})}function ta({error:e,onRetry:t}){let n=P();return e?(0,M.jsx)(i,{type:`danger`,bordered:!0,closeIcon:null,className:`cs-error-banner`,description:(0,M.jsxs)(f,{wrap:!0,children:[(0,M.jsx)(`span`,{children:rt(e,n(`common.loadFailed`,null,`加载失败`))}),t&&(0,M.jsx)(b,{size:`small`,onClick:t,children:n(`common.refresh`,null,`刷新`)})]})}):null}function na({severity:e,size:t=`small`}){let n=String(e||``).toLowerCase();return(0,M.jsx)(te,{size:t,color:Vi(n),shape:`circle`,className:`cs-severity-tag`,"data-severity":ji.includes(n)?n:void 0,children:Ni[n]||e||`—`})}function ra({status:e,label:t,size:n=`small`}){let r=String(e||``).toLowerCase();return(0,M.jsx)(te,{size:n,color:Hi(r),shape:`square`,children:t||e||`—`})}function ia({text:e,label:t,size:n=`default`,theme:r=`borderless`}){let i=P();return(0,M.jsx)(b,{size:n,theme:r,icon:(0,M.jsx)(x,{}),"aria-label":t||i(`common.copy`,null,`复制`),onClick:async()=>{try{await navigator.clipboard.writeText(String(e??``)),qi(i(`common.copied`,null,`已复制`))}catch(e){Yi(e,i(`common.copyFailed`,null,`复制失败`))}},children:t})}function aa({content:e,className:t=``}){let n=(0,O.useMemo)(()=>{let t=U.parse(String(e??``),{breaks:!0,gfm:!0});return Ai.sanitize(t,{ADD_ATTR:[`target`,`rel`]})},[e]);return(0,M.jsx)(`div`,{className:`cs-markdown ${t}`,dangerouslySetInnerHTML:{__html:n}})}function oa({value:e,collapsed:t=!1,title:n}){let[r,i]=(0,O.useState)(!t),a=P(),o=(0,O.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]);return(0,M.jsxs)(`div`,{className:`cs-json-viewer`,children:[(0,M.jsxs)(`div`,{className:`cs-json-viewer-head`,children:[(0,M.jsx)(Gi,{strong:!0,children:n||`JSON`}),(0,M.jsxs)(f,{spacing:4,children:[(0,M.jsx)(ia,{text:o}),(0,M.jsx)(b,{theme:`borderless`,size:`small`,icon:r?(0,M.jsx)(d,{}):(0,M.jsx)(l,{}),"aria-expanded":r,"aria-label":a(r?`common.collapse`:`common.expand`,null,r?`收起`:`展开`),onClick:()=>i(e=>!e)})]})]}),(0,M.jsx)(ee,{isOpen:r,children:(0,M.jsx)(`pre`,{className:`cs-json-viewer-body`,children:o})})]})}function sa({items:e,columns:t=2}){return(0,M.jsx)(v,{className:`cs-description-list`,layout:`horizontal`,align:`plain`,column:t,data:e.filter(Boolean).map(e=>({key:e.label,value:e.value??`—`}))})}function ca({title:e,content:t,okText:n,danger:r=!0,onOk:i}){ie.confirm({title:e,content:t,okText:n||`确定`,cancelText:`取消`,okButtonProps:r?{type:`danger`}:void 0,onOk:i})}var la=`a[href], button, input, select, textarea, iframe, [tabindex], [contenteditable="true"]`;function ua({title:e,visible:t,onCancel:n,width:r=560,footer:i,children:a,className:o,closeOnEsc:s=!0,mask:c=!0,maskClosable:l=!0,onOk:u,formId:d,okText:f,cancelText:p,okButtonProps:m,cancelButtonProps:h,confirmLoading:g,..._}){let ee=P(),te=(0,O.useRef)(null),[ne,v]=(0,O.useState)(!1),y=g??ne,x=(0,O.useCallback)(e=>{let t=e?.closest(`[role="dialog"]`);if(!t)return;te.current=t;let n=document.activeElement;return c&&(t.setAttribute(`aria-modal`,`true`),queueMicrotask(()=>{te.current===t&&!t.contains(document.activeElement)&&t.focus({preventScroll:!0})})),()=>{if(te.current=null,!c)return;t.removeAttribute(`aria-modal`);let e=document.activeElement;n?.isConnected&&(t.contains(e)||e===document.body)&&n.focus({preventScroll:!0})}},[c]);(0,O.useEffect)(()=>{if(!t)return;let e=e=>{let t=te.current,r=document.activeElement;if(e.defaultPrevented||!t?.contains(r)||(e.key===`Escape`&&s&&n&&(e.preventDefault(),n(e)),e.key!==`Tab`||!c))return;let i=[...t.querySelectorAll(la)].filter(e=>e.tabIndex>=0&&!e.matches(`:disabled`)&&e.getClientRects().length),a=i[0],o=i.at(-1);(!a||(e.shiftKey?r===a||r===t:r===o))&&(e.preventDefault(),(e.shiftKey?o:a)?.focus())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s,c,n,t]);let re=e=>{if(y)return;let t=u?.(e);if(g===void 0&&typeof t?.then==`function`){v(!0);let e=()=>v(!1);Promise.resolve(t).then(e,e)}},ie=i===void 0&&(u||d)?(0,M.jsxs)(M.Fragment,{children:[n&&(0,M.jsx)(b,{type:`tertiary`,onClick:n,...h,children:p||ee(`common.cancel`,null,`取消`)}),(0,M.jsx)(b,{theme:`solid`,type:`primary`,...m,loading:y,disabled:y||m?.disabled,onClick:d?void 0:re,form:d,htmlType:d?`submit`:`button`,children:f||ee(`common.ok`,null,`确定`)})]}):i;return(0,M.jsxs)(Te,{title:e,visible:t,onCancel:n,width:r,footer:ie,mask:c,maskClosable:l&&!y,closeOnEsc:!1,className:`cs-drawer ${o||``}`,"aria-label":typeof e==`string`?e:void 0,..._,children:[(0,M.jsx)(`span`,{hidden:!0,ref:x}),a]})}function da(e,t=[],{initial:n=null,skip:r=!1}={}){let[i,a]=(0,O.useState)(n),[o,s]=(0,O.useState)(!r),[c,l]=(0,O.useState)(null),u=(0,O.useRef)(0),d=(0,O.useRef)(null),f=(0,O.useRef)(!1),p=(0,O.useCallback)(async(t={})=>{if(r||t.silent&&!t.force&&f.current)return null;d.current?.abort();let n=new AbortController;d.current=n,f.current=!0;let i=++u.current;t.silent||s(!0),l(null);try{let t=await Qe(n.signal,()=>e({signal:n.signal}));return!n.signal.aborted&&i===u.current&&a(t),t}catch(e){return n.signal.aborted||i===u.current&&l(e),null}finally{d.current===n&&(d.current=null,f.current=!1),!n.signal.aborted&&i===u.current&&s(!1)}},t);return(0,O.useEffect)(()=>{if(r)d.current?.abort(),d.current=null,f.current=!1,s(!1);else return p(),()=>{u.current+=1,d.current?.abort(),d.current=null,f.current=!1}},[p,r]),{data:i,setData:a,loading:o,error:c,reload:p}}function fa(e,t=300){let[n,r]=(0,O.useState)(e);return(0,O.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function pa(e,t){let n=(0,O.useRef)(e);(0,O.useEffect)(()=>{n.current=e},[e]),(0,O.useEffect)(()=>{if(!t)return;let e=setInterval(()=>n.current(),t);return()=>clearInterval(e)},[t])}function ma(e,t){let[n,r]=(0,O.useState)(()=>{try{let n=localStorage.getItem(e);return n===null?t:JSON.parse(n)}catch{return t}});return(0,O.useEffect)(()=>{try{localStorage.setItem(e,JSON.stringify(n))}catch{}},[e,n]),[n,r]}var{Text:ha}=c,ga={position:`right`,contentClassName:`cs-nav-flyout`};function _a(){let[e,t]=(0,O.useState)(()=>window.matchMedia(`(max-width: 900px)`).matches);return(0,O.useEffect)(()=>{let e=window.matchMedia(`(max-width: 900px)`),n=e=>t(e.matches);return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function va(e,t,n,r){return e.filter(e=>(!e.anyPermission||r(e.anyPermission))&&(!e.permission||n(e.permission))).map(e=>{let r=e.children?e.children.filter(e=>!e.permission||n(e.permission)):null;return r&&r.length===0?null:{itemKey:e.id,text:t(e.i18n,null,e.fallback),icon:e.icon?(0,M.jsx)(e.icon,{"aria-hidden":`true`}):void 0,items:r?r.map(e=>({itemKey:e.id,text:t(e.i18n,null,e.fallback)})):void 0}}).filter(Boolean)}function ya(){let{preference:e,setPreference:t}=Dt(),n=P(),r=[{key:`system`,label:n(`theme.system`,null,`跟随系统`)},{key:`light`,label:n(`theme.light`,null,`浅色`)},{key:`dark`,label:n(`theme.dark`,null,`暗色`)}],i=r.find(t=>t.key===e)||r[0];return(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:r.map(n=>({node:`item`,name:n.label,active:n.key===e,onClick:()=>t(n.key)})),children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:e===`dark`?(0,M.jsx)(ye,{}):(0,M.jsx)(Se,{}),"aria-label":i.label})})}function ba(){let{lang:e,setLanguage:t}=vt();return(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:ct.map(n=>({node:`item`,name:n.label,active:n.id===e,onClick:()=>t(n.id)})),children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:(0,M.jsx)(re,{}),"aria-label":e})})}function xa({navigate:e}){let t=P(),[n,r]=(0,O.useState)([]),[i,a]=(0,O.useState)(0),[o,s]=(0,O.useState)(!1),[c,l]=(0,O.useState)(!1),u=(0,O.useRef)(null),d=(0,O.useRef)(!1),f=async({force:e=!1}={})=>{if(!e&&d.current)return;u.current?.abort();let t=new AbortController;u.current=t,d.current=!0;try{let e=await j.get(`/notifications/summary`,{limit:80,lang:document.documentElement.lang||`zh-CN`},{signal:t.signal});if(t.signal.aborted)return;let n=Array.isArray(e?.items)?e.items:[];r(n),a(e?.unreadCount??n.filter(e=>!e.read).length)}catch{}finally{u.current===t&&(u.current=null,d.current=!1)}};(0,O.useEffect)(()=>(f({force:!0}),()=>{u.current?.abort(),u.current=null,d.current=!1}),[]),pa(()=>f(),6e4);let p=async()=>{let e=n.filter(e=>!e.read).map(e=>e.id).filter(Boolean);if(e.length&&!c){l(!0);try{await j.post(`/notifications/read`,{eventIds:e}),await f({force:!0})}catch(e){Yi(e)}finally{l(!1)}}},m=t=>{s(!1),t.type===`vulnerability_created`&&t.vulnerabilityId?e(`/vulnerabilities?id=${encodeURIComponent(t.vulnerabilityId)}`):(t.type===`task_completed`||t.type===`long_running_tasks`)&&t.conversationId?e(`/chat?conversation=${encodeURIComponent(t.conversationId)}`):t.type===`task_failed`?e(`/mcp-monitor`):t.type===`hitl_pending`?e(`/hitl`):t.type===`c2_session_online`&&e(`/c2-sessions`)},g=(0,M.jsxs)(`div`,{className:`cs-notification-panel`,children:[(0,M.jsxs)(`div`,{className:`cs-notification-head`,children:[(0,M.jsx)(ha,{strong:!0,children:t(`notifications.title`,null,`通知`)}),(0,M.jsx)(b,{size:`small`,theme:`borderless`,onClick:p,loading:c,children:t(`notifications.markAllRead`,null,`全部标记已读`)})]}),(0,M.jsxs)(`div`,{className:`cs-notification-list`,children:[n.length===0&&(0,M.jsx)(ha,{type:`tertiary`,children:t(`notifications.empty`,null,`暂无新通知`)}),n.map(e=>(0,M.jsxs)(`button`,{type:`button`,className:`cs-notification-item`,onClick:()=>m(e),children:[(0,M.jsx)(`span`,{className:`cs-notification-dot level-${e.level||`p2`}`}),(0,M.jsxs)(`span`,{className:`cs-notification-body`,children:[(0,M.jsx)(`span`,{className:`cs-notification-title`,children:e.title||e.message||e.type}),(0,M.jsxs)(`span`,{className:`cs-notification-meta`,children:[e.ts?Fi(e.ts):``,e.count>1?` · ×${e.count}`:``]})]})]},e.id||`${e.type}-${e.ts}`))]})]});return(0,M.jsx)(h,{content:g,trigger:`click`,position:`bottomRight`,visible:o,onVisibleChange:s,children:(0,M.jsx)(oe,{count:i||null,overflowCount:99,type:`danger`,children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:(0,M.jsx)(y,{}),"aria-label":t(`notifications.title`,null,`通知`)})})})}function Sa({navigate:e}){let{user:t,logout:n,refresh:r}=st(),i=P(),[o,s]=(0,O.useState)(!1),c=(0,O.useId)(),[l,d]=(0,O.useState)(null),[f,p]=(0,O.useState)(!1);return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:[{node:`title`,name:t?.display_name||t?.username||`admin`},{node:`item`,name:i(`auth.changePassword`,null,`修改密码`),icon:(0,M.jsx)(a,{}),onClick:()=>s(!0)},{node:`item`,name:i(`auth.refreshSession`,null,`刷新会话权限`),onClick:()=>r().then(()=>qi(i(`auth.sessionRefreshed`,null,`会话已刷新`))).catch(e=>Yi(e))},{node:`divider`},{node:`item`,name:i(`auth.logout`,null,`退出登录`),icon:(0,M.jsx)(ne,{}),onClick:async()=>{await n(),e(`/dashboard`)}}],children:(0,M.jsxs)(b,{theme:`borderless`,type:`tertiary`,className:`cs-user-trigger`,"aria-label":i(`auth.userMenu`,null,`用户菜单`),children:[(0,M.jsx)(u,{size:`extra-small`,color:`blue`,children:(t?.display_name||t?.username||`A`).slice(0,1).toUpperCase()}),(0,M.jsx)(`span`,{className:`cs-user-name`,children:t?.display_name||t?.username||`admin`})]})}),(0,M.jsx)(ua,{title:i(`auth.changePassword`,null,`修改密码`),visible:o,onCancel:()=>s(!1),formId:c,okText:i(`common.save`,null,`保存`),confirmLoading:f,width:420,children:(0,M.jsxs)(C,{id:c,onSubmit:async e=>{p(!0);try{await j.post(`/auth/change-password`,{oldPassword:e.oldPassword,newPassword:e.newPassword}),qi(i(`auth.passwordChanged`,null,`密码已更新`)),s(!1),l?.reset()}catch(e){Yi(e,i(`auth.changeFailed`,null,`修改密码失败`))}finally{p(!1)}},getFormApi:d,children:[(0,M.jsx)(C.Input,{field:`oldPassword`,label:i(`auth.currentPassword`,null,`当前密码`),type:`password`,rules:[{required:!0,message:i(`auth.required`,null,`必填`)}]}),(0,M.jsx)(C.Input,{field:`newPassword`,label:i(`auth.newPassword`,null,`新密码`),type:`password`,rules:[{required:!0,min:8,message:i(`auth.passwordMin`,null,`至少 8 位`)}]}),(0,M.jsx)(C.Input,{field:`confirmPassword`,label:i(`auth.confirmPassword`,null,`确认新密码`),type:`password`,rules:[{required:!0,message:i(`auth.required`,null,`必填`)},{validator:(e,t)=>t===l?.getValue(`newPassword`),message:i(`auth.passwordMismatch`,null,`两次输入不一致`)}]})]})})]})}function Ca(){let{session:e,hasPermission:t,hasAnyPermission:n}=st(),r=(0,O.useId)(),i=P(),a=Re(),o=D(),s=_a(),[c,l]=(0,O.useState)(()=>localStorage.getItem(`csai-nav-collapsed`)===`1`),[u,d]=(0,O.useState)(!1),[p,m]=(0,O.useState)([]),h=a.pathname.replace(/^\//,``).split(`/`)[0]||`dashboard`,g=jt(h),_=(0,O.useMemo)(()=>[h],[h]),ee=(0,O.useMemo)(()=>va(Ot,i,t,n),[i,t,n]);(0,O.useEffect)(()=>{d(!1),g?.parent&&m(e=>e.includes(g.parent)?e:[...e,g.parent])},[a.pathname,g?.parent]),(0,O.useEffect)(()=>{document.title=`${g?i(g.i18n,null,g.fallback):`工作台`} · CyberStrikeAI`},[g,i]);let te=({itemKey:e})=>{let t=a.search,n=[`chat`,`vulnerabilities`,`settings`,`deep-assessments`].includes(e)&&h===e?t:``;o(`/${e}${n}`)},ne=()=>{l(e=>(localStorage.setItem(`csai-nav-collapsed`,e?`0`:`1`),!e))},v=c&&!s,y=!v&&e?.appVersion,x=(0,M.jsxs)(`div`,{className:`cs-sidebar-inner ${v?`is-compact`:``}`,children:[(0,M.jsxs)(b,{className:`cs-brand`,theme:`borderless`,type:`tertiary`,onClick:()=>o(`/dashboard`),"aria-label":`CyberStrikeAI`,"aria-describedby":y?r:void 0,children:[(0,M.jsx)(`img`,{src:`/static/logo.png`,alt:``,className:`cs-brand-logo`}),!v&&(0,M.jsxs)(`span`,{className:`cs-brand-copy`,children:[(0,M.jsxs)(`span`,{className:`cs-brand-name`,children:[`CyberStrike`,(0,M.jsx)(`span`,{children:`AI`})]}),y&&(0,M.jsx)(`span`,{id:r,className:`cs-brand-version`,dir:`ltr`,title:`${i(`header.version`,null,`当前版本`)} ${y}`,children:y})]})]}),(0,M.jsx)(`div`,{className:`cs-nav-scroll`,children:kt.map(e=>{let t=ee.filter(t=>e.pages.includes(t.itemKey));return t.length?(0,M.jsxs)(`section`,{className:`cs-nav-section`,"aria-label":i(e.i18n,null,e.fallback),children:[!v&&(0,M.jsx)(`div`,{className:`cs-nav-section-label`,children:i(e.i18n,null,e.fallback)}),(0,M.jsx)(he,{className:`cs-nav`,style:{width:`100%`},items:t,selectedKeys:_,onSelect:te,isCollapsed:v,subDropdownProps:ga,openKeys:p,onOpenChange:({openKeys:e})=>m(e)})]},e.id):null})}),!s&&(0,M.jsx)(`div`,{className:`cs-nav-footer`,children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,block:!0,icon:v?(0,M.jsx)(ae,{}):(0,M.jsx)(ce,{}),"aria-label":i(v?`nav.expand`:`nav.collapse`,null,v?`展开菜单`:`收起菜单`),onClick:ne,children:!v&&i(`nav.collapse`,null,`收起菜单`)})})]}),re=g?i(g.i18n,null,g.fallback):`CyberStrikeAI`,ie=g?.parent?jt(g.parent):null,S=ie?i(ie.i18n,null,ie.fallback):``;return(0,M.jsxs)(`div`,{className:`cs-shell ${c&&!s?`is-collapsed`:``}`,children:[!s&&(0,M.jsx)(`aside`,{className:`cs-sider`,children:x}),s&&(0,M.jsx)(Te,{visible:u,onCancel:()=>d(!1),placement:`left`,width:264,title:i(`nav.navigation`,null,`导航`),bodyStyle:{padding:0},className:`cs-mobile-nav`,children:x}),(0,M.jsxs)(`div`,{className:`cs-main`,children:[(0,M.jsxs)(`header`,{className:`cs-header`,children:[(0,M.jsxs)(`div`,{className:`cs-header-left`,children:[s&&(0,M.jsx)(b,{theme:`borderless`,icon:(0,M.jsx)(Ae,{}),onClick:()=>d(!0),"aria-label":i(`common.expandPanel`,null,`展开面板`)}),(0,M.jsxs)(Me,{className:`cs-header-crumb`,compact:!1,children:[(0,M.jsx)(Me.Item,{onClick:()=>o(`/dashboard`),children:i(`nav.groupWorkspace`,null,`工作台`)}),S&&(0,M.jsx)(Me.Item,{children:S}),(0,M.jsx)(Me.Item,{children:re})]})]}),(0,M.jsxs)(f,{className:`cs-header-actions`,spacing:4,children:[(0,M.jsx)(xa,{navigate:o}),(0,M.jsx)(ba,{}),(0,M.jsx)(ya,{}),(0,M.jsx)(Sa,{navigate:o})]})]}),(0,M.jsx)(`main`,{className:`cs-content ${h===`chat`?`cs-content-workspace`:``}`,id:`main-content`,children:(0,M.jsx)(Le,{context:{navigate:o,pageId:h,mobile:s}})})]})]})}var{Title:wa,Text:Ta,Paragraph:Ea}=c;function Da(){let{login:e}=st(),n=P(),[r,a]=(0,O.useState)(!1),[o,c]=(0,O.useState)(``);async function l(t){a(!0),c(``);try{await e(t.username,t.password)}catch(e){c(rt(e,n(`login.loginFailed`,null,`登录失败`)))}finally{a(!1)}}return(0,M.jsxs)(`main`,{className:`cs-login-page`,children:[(0,M.jsxs)(`section`,{className:`cs-login-story`,children:[(0,M.jsxs)(`div`,{className:`cs-login-brand`,children:[(0,M.jsx)(`img`,{src:`/static/logo.png`,alt:``,className:`cs-login-logo`}),(0,M.jsxs)(`span`,{className:`cs-brand-name`,children:[`CyberStrike`,(0,M.jsx)(`span`,{children:`AI`})]})]}),(0,M.jsxs)(`div`,{className:`cs-login-intro`,children:[(0,M.jsx)(`span`,{className:`cs-login-emblem`,"aria-hidden":`true`,children:(0,M.jsx)(me,{size:`extra-large`})}),(0,M.jsx)(wa,{heading:1,className:`cs-login-headline`,children:n(`login.headline`,null,`让每一次探索,都有据可循。`)}),(0,M.jsx)(Ea,{type:`tertiary`,children:n(`login.intro`,null,`从目标梳理到证据归档,在一个工作台中完成你的安全研究。`)}),(0,M.jsxs)(`div`,{className:`cs-login-features`,children:[(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(m,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.projectTitle`,null,`围绕项目协作`)}),n(`login.projectHint`,null,`跨会话共享目标、上下文与研究进展`)]})]}),(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(de,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.assessmentTitle`,null,`让探索持续推进`)}),n(`login.assessmentHint`,null,`规划、执行与人工复核,始终保持可控`)]})]}),(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(t,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.evidenceTitle`,null,`以证据支撑结论`)}),n(`login.evidenceHint`,null,`保留发现、来源与验收记录`)]})]})]})]}),(0,M.jsx)(Ta,{type:`tertiary`,size:`small`,children:n(`login.platformTagline`,null,`AI 驱动的安全研究工作台`)})]}),(0,M.jsx)(`section`,{className:`cs-login-form-panel`,children:(0,M.jsxs)(s,{className:`cs-login-card`,bordered:!1,children:[(0,M.jsx)(wa,{heading:2,className:`cs-login-form-heading`,children:n(`login.welcome`,null,`欢迎回来`)}),(0,M.jsx)(Ta,{type:`tertiary`,children:n(`login.welcomeHint`,null,`登录你的安全工作台,继续探索。`)}),(0,M.jsxs)(C,{onSubmit:l,className:`cs-login-form`,children:[o&&(0,M.jsx)(i,{type:`danger`,description:o,closeIcon:null,className:`cs-error-banner`}),(0,M.jsx)(C.Input,{field:`username`,label:n(`login.username`,null,`用户名`),prefix:(0,M.jsx)(ue,{}),placeholder:n(`login.usernamePlaceholder`,null,`请输入用户名`),size:`large`,autoComplete:`username`,rules:[{required:!0,message:n(`login.usernameRequired`,null,`请输入用户名`)}]}),(0,M.jsx)(C.Input,{field:`password`,label:n(`login.password`,null,`密码`),prefix:(0,M.jsx)(ge,{}),type:`password`,size:`large`,autoComplete:`current-password`,placeholder:n(`login.passwordPlaceholder`,null,`请输入密码`),rules:[{required:!0,message:n(`login.passwordRequired`,null,`请输入密码`)}]}),(0,M.jsx)(b,{htmlType:`submit`,theme:`solid`,type:`primary`,size:`large`,block:!0,loading:r,children:n(`login.submit`,null,`登录`)})]}),(0,M.jsx)(Ta,{type:`tertiary`,className:`cs-login-note`,children:n(`login.authorizedOnly`,null,`仅在明确授权的范围内开展安全测试`)})]})})]})}var Oa=`modulepreload`,ka=function(e){return`/static/app/`+e},Aa={},ja=function(e){return e.pathname.endsWith(`.css`)},Ma=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},$=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=ka(t,n);let r=s(t),i=ja(r);return Ma(Aa,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:Oa,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{let i=a=>{t.removeEventListener(`load`,i),t.removeEventListener(`error`,i),a.type===`error`?n(Error(`Unable to preload CSS for ${r}`)):e(a)};t.addEventListener(`load`,i),t.addEventListener(`error`,i)})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Na={dashboard:(0,O.lazy)(()=>$(()=>import(`./dashboard-DeXgyliz.js`),__vite__mapDeps([0,1,2,3,4,5]))),chat:(0,O.lazy)(()=>$(()=>import(`./chat-SoNJlUtQ.js`),__vite__mapDeps([6,1,2,3,4,7,8,9,10,11,12]))),"deep-assessments":(0,O.lazy)(()=>$(()=>import(`./deep-assessments-CeZoXWD8.js`),__vite__mapDeps([13,1,2,3,4,10,9,14,15,16]))),hitl:(0,O.lazy)(()=>$(()=>import(`./hitl-SyJj-0iX.js`),__vite__mapDeps([17,1,2,3,4,18]))),"tool-guard":(0,O.lazy)(()=>$(()=>import(`./tool-guard-CjP9k4xW.js`),__vite__mapDeps([19,1,2,3,4,20]))),projects:(0,O.lazy)(()=>$(()=>import(`./projects-BDK_5JF_.js`),__vite__mapDeps([21,1,2,3,4,9,14,15,22,11,23,24]))),"asset-overview":(0,O.lazy)(()=>$(()=>import(`./asset-overview-CZ4LQUQK.js`),__vite__mapDeps([25,1,2,3,4,26,23,27]))),"asset-library":(0,O.lazy)(()=>$(()=>import(`./asset-library-BATke9oD.js`),__vite__mapDeps([28,1,2,3,4,11,23,26,22,29]))),"info-collect":(0,O.lazy)(()=>$(()=>import(`./info-collect-tZh4Ex_m.js`),__vite__mapDeps([30,1,2,3,4,11,26,23,31]))),vulnerabilities:(0,O.lazy)(()=>$(()=>import(`./vulnerabilities-Cp2H761l.js`),__vite__mapDeps([32,1,2,3,4,7,11,33]))),tasks:(0,O.lazy)(()=>$(()=>import(`./tasks-B7Ht6Kqu.js`),__vite__mapDeps([34,1,2,3,4,11,35]))),workflows:(0,O.lazy)(()=>$(()=>import(`./workflows-BE-p3Qg8.js`),__vite__mapDeps([36,1,2,3,4,37]))),webshell:(0,O.lazy)(()=>$(()=>import(`./webshell-DwxDKO10.js`),__vite__mapDeps([38,1,2,3,4,11,39]))),"c2-listeners":(0,O.lazy)(()=>$(()=>import(`./c2-listeners-BQWhW0Gk.js`),__vite__mapDeps([40,1,2,3,4,41,42,43,11,44]))),"c2-sessions":(0,O.lazy)(()=>$(()=>import(`./c2-sessions-FyY2Qs8w.js`),__vite__mapDeps([45,1,2,3,4,41,42,43,46]))),"c2-tasks":(0,O.lazy)(()=>$(()=>import(`./c2-tasks-DaPeELPh.js`),__vite__mapDeps([47,1,2,3,4,41,42,43,48]))),"c2-payloads":(0,O.lazy)(()=>$(()=>import(`./c2-payloads-Dsgf1ekf.js`),__vite__mapDeps([49,1,2,3,4,41,42,43,50]))),"c2-events":(0,O.lazy)(()=>$(()=>import(`./c2-events-CRzsI2lE.js`),__vite__mapDeps([51,1,2,3,4,41,42,43,52]))),"c2-profiles":(0,O.lazy)(()=>$(()=>import(`./c2-profiles-BeA34AGv.js`),__vite__mapDeps([53,1,2,3,4,41,42,54]))),"chat-files":(0,O.lazy)(()=>$(()=>import(`./chat-files-C42sYCEL.js`),__vite__mapDeps([55,1,2,3,4,56]))),"plugin-hub":(0,O.lazy)(()=>$(()=>import(`./plugin-hub-CksKkMqp.js`),__vite__mapDeps([57,1,2,3,4,8,58]))),"mcp-monitor":(0,O.lazy)(()=>$(()=>import(`./mcp-monitor-Da5IyxS4.js`),__vite__mapDeps([59,1,2,3,4,60]))),"mcp-management":(0,O.lazy)(()=>$(()=>import(`./mcp-management-hsz83LkQ.js`),__vite__mapDeps([61,1,2,3,4,62]))),"knowledge-retrieval-logs":(0,O.lazy)(()=>$(()=>import(`./knowledge-retrieval-logs-1o1SzSFP.js`),__vite__mapDeps([63,1,2,3,4]))),"knowledge-management":(0,O.lazy)(()=>$(()=>import(`./knowledge-management-CEHirgdD.js`),__vite__mapDeps([64,1,2,3,4]))),"skills-monitor":(0,O.lazy)(()=>$(()=>import(`./skills-monitor-B_jKEqI_.js`),__vite__mapDeps([65,1,3,2,4]))),"skills-management":(0,O.lazy)(()=>$(()=>import(`./skills-management-mXFB_l5H.js`),__vite__mapDeps([66,1,2,3,4]))),"agents-management":(0,O.lazy)(()=>$(()=>import(`./agents-management-BtgSrIfK.js`),__vite__mapDeps([67,1,2,3,4]))),"roles-management":(0,O.lazy)(()=>$(()=>import(`./roles-management-Dj76kdoF.js`),__vite__mapDeps([68,1,2,3,4,69]))),"platform-rbac":(0,O.lazy)(()=>$(()=>import(`./platform-rbac-Cg2CXbmQ.js`),__vite__mapDeps([70,1,2,3,4]))),settings:(0,O.lazy)(()=>$(()=>import(`./settings-1TCOaSN2.js`),__vite__mapDeps([71,1,2,3,4,10,72]))),"api-docs":(0,O.lazy)(()=>$(()=>import(`./api-docs-DNX0F9D0.js`),__vite__mapDeps([73,1,2,3,4,74])))},{Title:Pa,Text:Fa}=c;function Ia(){return(0,M.jsx)(`div`,{className:`cs-page-loading`,children:(0,M.jsx)(se,{size:`large`})})}function La({code:e,title:t,description:n}){return(0,M.jsxs)(`div`,{className:`cs-page-loading`,style:{flexDirection:`column`,gap:8},children:[(0,M.jsx)(Pa,{heading:2,style:{margin:0},children:e}),(0,M.jsx)(Fa,{strong:!0,children:t}),n&&(0,M.jsx)(Fa,{type:`tertiary`,children:n})]})}function Ra(){let{pageId:e}=Ue(),{hasPermission:t,hasAnyPermission:n}=st(),r=P(),i=jt(e),a=e?Na[e]:null,o=(0,O.useMemo)(()=>{if(!i)return!0;if(i.anyPermission)return n(i.anyPermission);if(i.permission)return t(i.permission);let e=i.parent?jt(i.parent):null;return!e?.anyPermission||n(e.anyPermission)},[i,t,n]);return i?a?o?(0,M.jsx)(O.Suspense,{fallback:(0,M.jsx)(Ia,{}),children:(0,M.jsx)(a,{})}):(0,M.jsx)(La,{code:`403`,title:r(`common.forbidden`,null,`当前账号没有访问该页面的权限`)}):(0,M.jsx)(La,{code:`404`,title:i.fallback,description:r(`common.pagePending`,null,`页面尚未注册`)}):(0,M.jsx)(La,{code:`404`,title:r(`common.pageNotFound`,null,`页面不存在`)})}function za(){let{authenticated:e,checking:t}=st();return t?(0,M.jsx)(Ia,{}):e?(0,M.jsx)(Be,{children:(0,M.jsxs)(Ve,{element:(0,M.jsx)(Ca,{}),children:[(0,M.jsx)(Ve,{path:`/`,element:(0,M.jsx)(Ie,{to:`/dashboard`,replace:!0})}),(0,M.jsx)(Ve,{path:`/system-update`,element:(0,M.jsx)(Ie,{to:`/settings?section=update`,replace:!0})}),(0,M.jsx)(Ve,{path:`/:pageId`,element:(0,M.jsx)(Ra,{})}),(0,M.jsx)(Ve,{path:`*`,element:(0,M.jsx)(Ie,{to:`/dashboard`,replace:!0})})]})}):(0,M.jsx)(Da,{})}var Ba={"zh-CN":pe,"en-US":Ee,"ru-RU":xe,"ar-SA":w};function Va(){let{lang:e}=vt();return(0,M.jsx)(n,{locale:Ba[e]||pe,direction:e===`ar-SA`?`rtl`:`ltr`,children:(0,M.jsx)(ot,{children:(0,M.jsx)(ze,{children:(0,M.jsx)(za,{})})})})}(0,We.createRoot)(document.getElementById(`root`)).render((0,M.jsx)(O.StrictMode,{children:(0,M.jsx)(Et,{children:(0,M.jsx)(_t,{children:(0,M.jsx)(Va,{})})})}));export{Ui as A,nt as B,Ni as C,zi as D,Fi as E,st as F,j as I,tt as L,ct as M,vt as N,Bi as O,P,rt as R,Ji as S,Ri as T,A as V,Qi as _,da as a,Yi as b,ua as c,sa as d,aa as f,$i as g,na as h,ma as i,Dt as j,Li as k,ta as l,Zi as m,fa as n,ia as o,Xi as p,pa as r,ea as s,$ as t,oa as u,ra as v,ji as w,qi as x,ca as y,Ze as z};
\ No newline at end of file
diff --git a/web/static/app/assets/index-_8d9XBPJ.js b/web/static/app/assets/index-_8d9XBPJ.js
new file mode 100644
index 00000000..7c220614
--- /dev/null
+++ b/web/static/app/assets/index-_8d9XBPJ.js
@@ -0,0 +1,64 @@
+const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dashboard-D6tX6vKc.js","assets/rolldown-runtime-WkwZ5CU-.js","assets/react-QV7DAAIx.js","assets/semi-65W_4I1v.js","assets/semi-BUXPdXzR.css","assets/dashboard-Dk6QMmtm.css","assets/chat-BUYQ3rrK.js","assets/retest-EzTZPjnQ.js","assets/agent-handoff-DzQOcr38.js","assets/project-form-Dt6NB8i_.js","assets/model-channel-mQ6lfvSO.js","assets/project-options-CMQbwv_U.js","assets/chat-B_1ruiFc.css","assets/deep-assessments-C0yrTrga.js","assets/graph-parents-i1hc3RVG.js","assets/graph-parents-BbkuhUnk.css","assets/deep-assessments-BVUI7zDD.css","assets/hitl-Bu3O9ejX.js","assets/hitl-BqmzzDjt.css","assets/tool-guard-Dk4HsC4O.js","assets/tool-guard-DKIWLN1V.css","assets/projects-B6zINg50.js","assets/AssetEditorModal-DrEuccaT.js","assets/assetTarget-D2PEjBAg.js","assets/projects-CCzxY6zz.css","assets/asset-overview-CJx-FRnL.js","assets/AssetBits-DtqSAj0f.js","assets/asset-overview-DEMYiRVr.css","assets/asset-library-Cj9VhYXV.js","assets/asset-library-a5Vth3JU.css","assets/info-collect-ByWtvjrf.js","assets/info-collect-BrIcieOX.css","assets/vulnerabilities-BDm_fRci.js","assets/vulnerabilities-BPt2JmiL.css","assets/tasks-C-O0ZxhT.js","assets/tasks-BtBBHKoW.css","assets/workflows-DDqn8hp2.js","assets/workflows-EsKm07MV.css","assets/webshell-i057Xx9K.js","assets/webshell-BdcYpY5u.css","assets/c2-listeners-DZ-iU1EK.js","assets/c2-shared-d6x5yKU9.js","assets/c2-shared-B-Nz9eUh.css","assets/c2-shared-lPZEmiJx.js","assets/c2-listeners-KjhK45yg.css","assets/c2-sessions-BzU3PAL8.js","assets/c2-sessions-DLf_n8Eq.css","assets/c2-tasks-DGQ9YyKu.js","assets/c2-tasks-B5H34xZF.css","assets/c2-payloads-DHMSGvwF.js","assets/c2-payloads-CnRJmaJm.css","assets/c2-events-Be-OFfdA.js","assets/c2-events-BVd4qqKy.css","assets/c2-profiles-BF6FGU2n.js","assets/c2-profiles-BpNJlhDC.css","assets/chat-files-it1nAhw-.js","assets/chat-files-wKL7Vwmw.css","assets/plugin-hub-B-d85AF3.js","assets/plugin-hub-Yl4AUy33.css","assets/mcp-monitor-Du61ugEZ.js","assets/mcp-monitor-8VvqmnVY.css","assets/mcp-management-BDsOVfL3.js","assets/mcp-management-CEr7J00D.css","assets/knowledge-retrieval-logs-4_2LIOnY.js","assets/knowledge-management--PPUE20m.js","assets/skills-monitor-ZMwFvsjS.js","assets/skills-management-Dy4a2scy.js","assets/agents-management-2nvjyStC.js","assets/roles-management-Cc2pBLLE.js","assets/roles-management-CAkb5FLz.css","assets/platform-rbac-CHfcwOkN.js","assets/settings-C_ZMENXl.js","assets/settings-Cjg19I8_.css","assets/api-docs-BECDxS6A.js","assets/api-docs-B_T3BEfL.css"])))=>i.map(i=>d[i]);
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{$t as t,A as n,At as r,B as i,Ct as a,E as o,F as s,G as c,Gt as l,H as u,Ht as d,I as f,J as p,Jt as m,K as h,Kt as g,L as _,M as ee,N as te,Nt as ne,O as v,Qt as y,R as b,Rt as x,St as re,T as ie,Tt as S,Ut as ae,V as oe,W as se,Wt as ce,Xt as le,Y as ue,Yt as de,Zt as fe,an as pe,at as me,b as he,bt as ge,dt as _e,et as ve,ht as ye,i as C,kt as be,n as xe,nt as Se,o as Ce,ot as we,p as Te,r as Ee,rn as De,st as Oe,t as w,u as ke,ut as T,vt as Ae,w as E,wt as je,z as Me,zt as Ne}from"./semi-65W_4I1v.js";import{S as Pe,b as Fe,d as Ie,f as Le,g as D,h as Re,l as ze,m as Be,p as Ve,t as He,v as Ue}from"./react-QV7DAAIx.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var O=e(Pe(),1),We=Fe(),Ge=`cyberstrike-auth`;function Ke(){try{let e=localStorage.getItem(Ge);if(!e)return null;let t=JSON.parse(e);if(!t?.token||!t?.expiresAt)return null;let n=new Date(t.expiresAt);return!Number.isFinite(n.getTime())||n.getTime()<=Date.now()?null:{token:t.token,expiresAt:n.toISOString(),user:t.user||null,roles:Array.isArray(t.roles)?t.roles:[],permissions:Array.isArray(t.permissions)?t.permissions:[],scope:t.scope||``}}catch(e){return console.warn(`读取会话失败:`,e),null}}function qe(e){e?localStorage.setItem(Ge,JSON.stringify(e)):localStorage.removeItem(Ge)}var Je=null,Ye=null;function Xe(e){Je=e||null}function Ze(){return Je}function Qe(e,t){let n=Ye;Ye=e||null;try{return t()}finally{Ye=n}}var k=class extends Error{constructor(e,{status:t=0,payload:n=null,path:r=``}={}){super(e),this.name=`ApiError`,this.status=t,this.payload=n,this.path=r}};function $e(e,t){let n=e.startsWith(`http`)?e:`/api${e.startsWith(`/`)?e:`/${e}`}`;if(!t)return n;let r=new URLSearchParams;for(let[e,n]of Object.entries(t))n!=null&&n!==``&&(Array.isArray(n)?n.forEach(t=>r.append(e,t)):r.append(e,String(n)));let i=r.toString();return i?`${n}${n.includes(`?`)?`&`:`?`}${i}`:n}async function et(e){let t=e.headers.get(`content-type`)||``;try{if(t.includes(`application/json`)){let t=await e.json();return{message:t.error||t.message||`请求失败(HTTP ${e.status})`,payload:t}}let n=await e.text();return{message:n?.slice(0,300)||`请求失败(HTTP ${e.status})`,payload:n}}catch{return{message:`请求失败(HTTP ${e.status})`,payload:null}}}async function A(e,t={}){let{method:n=`GET`,body:r,query:i,headers:a={},signal:o,raw:s=!1,timeout:c=6e4}=t,l=o===void 0?n.toUpperCase()===`GET`?Ye:void 0:o,u={Accept:`application/json`,...a},d=r;r!=null&&!(r instanceof FormData)&&typeof r!=`string`&&!(r instanceof Blob)&&(u[`Content-Type`]=`application/json`,d=JSON.stringify(r)),Je&&!u.Authorization&&(u.Authorization=`Bearer ${Je}`);let f=new AbortController,p=c?setTimeout(()=>f.abort(),c):null,m=()=>f.abort();l&&(l.aborted?f.abort():l.addEventListener(`abort`,m,{once:!0}));let h;try{h=await fetch($e(e,i),{method:n,headers:u,body:d,signal:f.signal})}catch(t){throw t.name===`AbortError`?new k(`请求已取消`,{path:e}):new k(`网络连接失败,请检查服务状态`,{path:e})}finally{p&&clearTimeout(p),l&&l.removeEventListener(`abort`,m)}if(h.status===401&&window.dispatchEvent(new CustomEvent(`csai:unauthorized`)),!h.ok){let{message:t,payload:n}=await et(h);throw new k(t,{status:h.status,payload:n,path:e})}return s?h:h.status===204?null:(h.headers.get(`content-type`)||``).includes(`application/json`)?h.json():h.text()}var j={get:(e,t,n={})=>A(e,{...n,query:t}),post:(e,t,n={})=>A(e,{...n,method:`POST`,body:t}),put:(e,t,n={})=>A(e,{...n,method:`PUT`,body:t}),patch:(e,t,n={})=>A(e,{...n,method:`PATCH`,body:t}),del:(e,t={})=>A(e,{...t,method:`DELETE`}),raw:(e,t={})=>A(e,{...t,raw:!0})};async function tt(e,{query:t,filename:n,method:r=`GET`,body:i}={}){let a=await A(e,{method:r,body:i,query:t,raw:!0,timeout:12e4}),o=await a.blob(),s=a.headers.get(`content-disposition`)||``,c=s.match(/filename\*=UTF-8''([^;]+)/i),l=s.match(/filename="?([^";]+)"?/i),u=n||(c?decodeURIComponent(c[1]):l?.[1])||`download.bin`,d=URL.createObjectURL(o),f=document.createElement(`a`);return f.href=d,f.download=u,document.body.appendChild(f),f.click(),f.remove(),setTimeout(()=>URL.revokeObjectURL(d),1e3),u}function nt(e,t,{onEvent:n,onError:r,onClose:i,signal:a}={}){let o=new AbortController;a&&(a.aborted?o.abort():a.addEventListener(`abort`,()=>o.abort(),{once:!0}));let s={"Content-Type":`application/json`,Accept:`text/event-stream`};return Je&&(s.Authorization=`Bearer ${Je}`),(async()=>{try{let r=await fetch($e(e),{method:`POST`,headers:s,body:JSON.stringify(t||{}),signal:o.signal});if(r.status===401&&window.dispatchEvent(new CustomEvent(`csai:unauthorized`)),!r.ok){let{message:t}=await et(r);throw new k(t,{status:r.status,path:e})}if(!r.body)throw new k(`服务端未返回流式响应`,{path:e});let a=r.body.getReader(),c=new TextDecoder,l=``,u=!1;for(;!u;){let{done:e,value:t}=await a.read();if(e)break;l+=c.decode(t,{stream:!0});let r;for(;(r=l.indexOf(`
+`))>=0;){let e=l.slice(0,r).replace(/\r$/,``);if(l=l.slice(r+1),!e.startsWith(`data:`))continue;let t=e.slice(5).trim();if(!t)continue;if(t===`[DONE]`){u=!0;break}let i;try{i=JSON.parse(t)}catch{continue}n?.(i)}}i?.()}catch(e){if(e.name===`AbortError`){i?.();return}r?.(e)}})(),()=>o.abort()}function rt(e,t=`操作失败`){return e?typeof e==`string`?e:e.message||t:t}var M=e(He(),1),it=(0,O.createContext)(null);function at(e,t){return e?{token:t||e.token,expiresAt:e.expires_at||e.expiresAt||``,appVersion:typeof e.app_version==`string`?e.app_version.trim():``,user:e.user||null,roles:Array.isArray(e.roles)?e.roles:[],permissions:Array.isArray(e.permissions)?e.permissions:[],scope:e.scope||``}:null}function ot({children:e}){let t=(0,O.useRef)(Ke()).current,[n,r]=(0,O.useState)(t),[i,a]=(0,O.useState)(!!t);(0,O.useEffect)(()=>{if(Xe(t?.token||null),!t?.token){a(!1);return}let e=!1;return j.get(`/auth/validate`).then(n=>{if(e)return;let i=at(n,t.token);r(i),qe(i)}).catch(()=>{e||(r(null),qe(null),Xe(null))}).finally(()=>{e||a(!1)}),()=>{e=!0}},[]);let o=(0,O.useCallback)(()=>{r(null),Xe(null),qe(null)},[]);(0,O.useEffect)(()=>{let e=()=>o();return window.addEventListener(`csai:unauthorized`,e),()=>window.removeEventListener(`csai:unauthorized`,e)},[o]);let s=(0,O.useCallback)(async(e,t)=>{let n=await j.post(`/auth/login`,{username:String(e||``).trim(),password:t}),i=at(n,n?.token);return Xe(i?.token||null),qe(i),r(i),i},[]),c=(0,O.useCallback)(async()=>{try{await j.post(`/auth/logout`,{})}catch{}o()},[o]),l=(0,O.useMemo)(()=>new Set(n?.permissions||[]),[n]),u=(0,O.useCallback)(e=>!e||String(e).split(/\s+/).some(e=>l.has(e)),[l]),d=(0,O.useCallback)(e=>{let t=Array.isArray(e)?e:String(e||``).split(/\s+/).filter(Boolean);return!t.length||t.some(e=>l.has(e))},[l]),f=(0,O.useCallback)(async()=>{if(!n?.token)return null;let e=at(await j.get(`/auth/validate`),n.token);return r(e),qe(e),e},[n?.token]),p=(0,O.useMemo)(()=>({session:n,user:n?.user||null,roles:n?.roles||[],permissions:l,hasPermission:u,hasAnyPermission:d,checking:i,authenticated:!!n?.token,login:s,logout:c,refresh:f}),[n,l,u,d,i,s,c,f]);return(0,M.jsx)(it.Provider,{value:p,children:e})}function st(){let e=(0,O.useContext)(it);if(!e)throw Error(`useAuth 必须在 AuthProvider 内使用`);return e}var ct=[{id:`zh-CN`,label:`简体中文`},{id:`en-US`,label:`English`},{id:`ru-RU`,label:`Русский`},{id:`ar-SA`,label:`العربية`}],lt=`csai_lang`,ut=`zh-CN`,dt=`/static/i18n`,ft=new Map;function pt(){try{let e=localStorage.getItem(lt);if(e&&ct.some(t=>t.id===e))return e}catch{}let e=String(navigator.language||``).toLowerCase();return e.startsWith(`zh`)?`zh-CN`:e.startsWith(`ru`)?`ru-RU`:e.startsWith(`ar`)?`ar-SA`:e.startsWith(`en`)?`en-US`:ut}function mt(e){return ft.has(e)||ft.set(e,fetch(`${dt}/${e}.json`,{cache:`no-cache`}).then(e=>e.ok?e.json():{}).catch(()=>({}))),ft.get(e)}function ht(e,t){if(!e)return;let n=e;for(let e of String(t).split(`.`)){if(typeof n!=`object`||!n)return;n=n[e]}return typeof n==`string`?n:void 0}function N(e,t){return t?e.replace(/\{\{\s*(\w+)\s*\}\}/g,(e,n)=>t[n]===void 0?e:String(t[n])):e}var gt=(0,O.createContext)({lang:ut,t:e=>e,ready:!1,setLanguage:()=>{}});function _t({children:e}){let[t,n]=(0,O.useState)(pt),[r,i]=(0,O.useState)({}),[a,o]=(0,O.useState)(!1);(0,O.useEffect)(()=>{let e=!1;Promise.all([mt(t),mt(ut),mt(`en-US`)]).then(([t,n,r])=>{e||(i({current:t,fallback:n,english:r}),o(!0))}),document.documentElement.lang=t,document.documentElement.dir=t===`ar-SA`?`rtl`:`ltr`;try{localStorage.setItem(lt,t)}catch{}return()=>{e=!0}},[t]);let s=(0,O.useCallback)((e,t,n)=>{if(!e)return n??``;let i=ht(r.current,e)??ht(r.fallback,e)??ht(r.english,e);return i===void 0?n??e:N(i,t)},[r]),c=(0,O.useCallback)(e=>{e&&e!==t&&(o(!1),n(e),window.dispatchEvent(new CustomEvent(`csai:languagechange`,{detail:{lang:e}})))},[t]),l=(0,O.useMemo)(()=>({lang:t,t:s,ready:a,setLanguage:c}),[t,s,a,c]);return(0,M.jsx)(gt.Provider,{value:l,children:e})}function vt(){return(0,O.useContext)(gt)}function P(){return(0,O.useContext)(gt).t}var yt=`cyberstrike-theme`,bt=[`system`,`light`,`dark`];function xt(){try{let e=localStorage.getItem(yt);return bt.includes(e)?e:`system`}catch{return`system`}}function St(){return typeof window<`u`&&window.matchMedia?window.matchMedia(`(prefers-color-scheme: dark)`).matches:!1}function Ct(e){return e===`dark`||e===`light`?e:St()?`dark`:`light`}function wt(e){let t=Ct(e),n=document.documentElement;return n.setAttribute(`data-theme`,t),n.setAttribute(`data-theme-preference`,e),n.style.colorScheme=t,document.body?.setAttribute(`theme-mode`,t===`dark`?`dark`:`light`),t}var F=(0,O.createContext)({preference:`system`,theme:`light`,setPreference:()=>{},toggle:()=>{}});function Tt({children:e}){let[t,n]=(0,O.useState)(xt),[r,i]=(0,O.useState)(()=>Ct(xt()));(0,O.useLayoutEffect)(()=>{i(wt(t));try{localStorage.setItem(yt,t)}catch{}if(t!==`system`||!window.matchMedia)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>i(wt(t));return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[t]),(0,O.useEffect)(()=>{document.body?.setAttribute(`theme-mode`,r===`dark`?`dark`:`light`)},[r]);let a=(0,O.useCallback)(e=>{bt.includes(e)&&n(e)},[]),o=(0,O.useCallback)(()=>{n(e=>Ct(e)===`dark`?`light`:`dark`)},[]),s=(0,O.useMemo)(()=>({preference:t,theme:r,setPreference:a,toggle:o}),[t,r,a,o]);return(0,M.jsx)(F.Provider,{value:s,children:e})}function Et(){return(0,O.useContext)(F)}var Dt=[{id:`dashboard`,i18n:`nav.dashboard`,fallback:`仪表盘`,icon:S},{id:`chat`,i18n:`nav.chat`,fallback:`对话`,icon:Ne},{id:`deep-assessments`,i18n:`nav.deepAssessments`,fallback:`深度测评`,icon:t},{id:`security`,i18n:`nav.security`,fallback:`安全防护`,icon:me,anyPermission:[`hitl:read`,`config:read`],children:[{id:`hitl`,i18n:`nav.hitl`,fallback:`人机协同`,permission:`hitl:read`},{id:`tool-guard`,i18n:`nav.toolGuard`,fallback:`调用拦截`,permission:`config:read`}]},{id:`projects`,i18n:`nav.projects`,fallback:`项目管理`,icon:m},{id:`assets`,i18n:`nav.assets`,fallback:`资产管理`,icon:r,anyPermission:[`asset:read`,`fofa:execute`],children:[{id:`asset-overview`,i18n:`nav.assetOverview`,fallback:`资产概览`},{id:`asset-library`,i18n:`nav.assetLibrary`,fallback:`资产库`},{id:`info-collect`,i18n:`nav.infoCollect`,fallback:`信息收集`}]},{id:`vulnerabilities`,i18n:`nav.vulnerabilities`,fallback:`漏洞管理`,icon:me},{id:`tasks`,i18n:`nav.tasks`,fallback:`任务管理`,icon:g},{id:`workflows`,i18n:`nav.workflows`,fallback:`工作流`,icon:de},{id:`webshell`,i18n:`nav.webshell`,fallback:`WebShell管理`,icon:ve},{id:`c2`,i18n:`nav.c2`,fallback:`C2`,icon:fe,children:[{id:`c2-listeners`,i18n:`nav.c2Listeners`,fallback:`监听器`},{id:`c2-sessions`,i18n:`nav.c2Sessions`,fallback:`会话`},{id:`c2-tasks`,i18n:`nav.c2Tasks`,fallback:`任务`},{id:`c2-payloads`,i18n:`nav.c2Payloads`,fallback:`载荷`},{id:`c2-events`,i18n:`nav.c2Events`,fallback:`事件`},{id:`c2-profiles`,i18n:`nav.c2Profiles`,fallback:`流量伪装`}]},{id:`chat-files`,i18n:`nav.chatFiles`,fallback:`文件管理`,icon:be},{id:`plugin-hub`,i18n:`nav.pluginHub`,fallback:`能力平台`,icon:De,permission:`plugins:read`},{id:`mcp`,i18n:`nav.mcp`,fallback:`MCP`,icon:Oe,children:[{id:`mcp-monitor`,i18n:`nav.mcpMonitor`,fallback:`MCP状态监控`},{id:`mcp-management`,i18n:`nav.mcpManagement`,fallback:`MCP管理`}]},{id:`knowledge`,i18n:`nav.knowledge`,fallback:`知识`,icon:le,children:[{id:`knowledge-retrieval-logs`,i18n:`nav.knowledgeRetrievalLogs`,fallback:`检索历史`},{id:`knowledge-management`,i18n:`nav.knowledgeManagement`,fallback:`知识管理`}]},{id:`skills`,i18n:`nav.skills`,fallback:`技能`,icon:_e,children:[{id:`skills-monitor`,i18n:`nav.skillsMonitor`,fallback:`技能状态`},{id:`skills-management`,i18n:`nav.skillsManagement`,fallback:`技能管理`}]},{id:`agents`,i18n:`nav.agents`,fallback:`智能体`,icon:p,children:[{id:`agents-management`,i18n:`nav.agentsManagement`,fallback:`智能体管理`}]},{id:`roles`,i18n:`nav.roles`,fallback:`角色`,icon:ue,children:[{id:`roles-management`,i18n:`nav.rolesManagement`,fallback:`角色管理`}]},{id:`platform-rbac`,i18n:`nav.platformRbac`,fallback:`平台权限`,icon:ge},{id:`settings`,i18n:`nav.settings`,fallback:`系统设置`,icon:we},{id:`api-docs`,i18n:`apiDocs.title`,fallback:`API 文档`,icon:t}],Ot=[{id:`workspace`,i18n:`nav.groupWorkspace`,fallback:`工作台`,pages:[`dashboard`,`chat`,`deep-assessments`,`security`]},{id:`operations`,i18n:`nav.groupOperations`,fallback:`安全作业`,pages:[`projects`,`assets`,`vulnerabilities`,`tasks`,`workflows`,`webshell`,`c2`,`chat-files`]},{id:`capabilities`,i18n:`nav.groupCapabilities`,fallback:`能力中心`,pages:[`plugin-hub`,`mcp`,`knowledge`,`skills`,`agents`,`roles`]},{id:`platform`,i18n:`nav.groupPlatform`,fallback:`平台管理`,pages:[`platform-rbac`,`settings`,`api-docs`]}],kt=Dt.flatMap(e=>e.children?e.children.map(t=>({...t,parent:e.id})):[e]);function At(e){return kt.find(t=>t.id===e)||Dt.find(t=>t.id===e)||null}function jt(e){"@babel/helpers - typeof";return jt=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},jt(e)}function Mt(e,t){if(jt(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(jt(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Nt(e){var t=Mt(e,`string`);return jt(t)==`symbol`?t:t+``}function I(e,t,n){return(t=Nt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var Pt;function Ft(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var It=Ft();function Lt(e){It=e}var Rt={exec:()=>null};function L(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(R.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var zt=(()=>{try{return!0}catch{return!1}})(),R={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`)},Bt=/^(?:[ \t]*(?:\n|$))+/,Vt=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ht=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,z=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ut=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,B=/(?:[*+-]|\d{1,9}[.)])/,Wt=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Gt=L(Wt).replace(/bull/g,B).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),Kt=L(Wt).replace(/bull/g,B).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),qt=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Jt=/^[^\n]+/,Yt=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Xt=L(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,Yt).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Zt=L(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,B).getRegex(),Qt=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,$t=/|$))/,en=L(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,$t).replace(`tag`,Qt).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),tn=L(qt).replace(`hr`,z).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Qt).getRegex(),nn={blockquote:L(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,tn).getRegex(),code:Vt,def:Xt,fences:Ht,heading:Ut,hr:z,html:en,lheading:Gt,list:Zt,newline:Bt,paragraph:tn,table:Rt,text:Jt},rn=L(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,z).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Qt).getRegex(),an={...nn,lheading:Kt,table:rn,paragraph:L(qt).replace(`hr`,z).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,rn).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Qt).getRegex()},on={...nn,html:L(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?\\1> *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,$t).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Rt,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:L(qt).replace(`hr`,z).replace(`heading`,` *#{1,6} *[^
+]`).replace(`lheading`,Gt).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},sn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,cn=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ln=/^( {2,}|\\)\n(?!\s*$)/,un=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\`+)[^`]+\k(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,zt?"(?`+)[^`]+\k(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),yn=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,bn=L(yn,`u`).replace(/punct/g,dn).getRegex(),xn=L(yn,`u`).replace(/punct/g,hn).getRegex(),Sn=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,Cn=L(Sn,`gu`).replace(/notPunctSpace/g,pn).replace(/punctSpace/g,fn).replace(/punct/g,dn).getRegex(),wn=L(Sn,`gu`).replace(/notPunctSpace/g,_n).replace(/punctSpace/g,gn).replace(/punct/g,hn).getRegex(),Tn=L(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,pn).replace(/punctSpace/g,fn).replace(/punct/g,dn).getRegex(),En=L(/\\(punct)/,`gu`).replace(/punct/g,dn).getRegex(),Dn=L(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),On=L($t).replace(`(?:-->|$)`,`-->`).getRegex(),kn=L(`^comment|^[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^`).replace(`comment`,On).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),An=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,jn=L(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace(`label`,An).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Mn=L(/^!?\[(label)\]\[(ref)\]/).replace(`label`,An).replace(`ref`,Yt).getRegex(),Nn=L(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,Yt).getRegex(),Pn=L(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,Mn).replace(`nolink`,Nn).getRegex(),Fn=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,In={_backpedal:Rt,anyPunctuation:En,autolink:Dn,blockSkip:vn,br:ln,code:cn,del:Rt,emStrongLDelim:bn,emStrongRDelimAst:Cn,emStrongRDelimUnd:Tn,escape:sn,link:jn,nolink:Nn,punctuation:mn,reflink:Mn,reflinkSearch:Pn,tag:kn,text:un,url:Rt},Ln={...In,link:L(/^!?\[(label)\]\((.*?)\)/).replace(`label`,An).getRegex(),reflink:L(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,An).getRegex()},Rn={...In,emStrongRDelimAst:wn,emStrongLDelim:xn,url:L(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,Fn).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:L(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\":`>`,'"':`"`,"'":`'`},Un=e=>Hn[e];function V(e,t){if(t){if(R.escapeTest.test(e))return e.replace(R.escapeReplace,Un)}else if(R.escapeTestNoEncode.test(e))return e.replace(R.escapeReplaceNoEncode,Un);return e}function Wn(e){try{e=encodeURI(e).replace(R.percentDecode,`%`)}catch{return null}return e}function Gn(e,t){let n=e.replace(R.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(R.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t){if(n.length>t)n.splice(t);else for(;n.length0?-2:-1}function Jn(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function Yn(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
+`).map(e=>{let t=e.match(n.other.beginningSpace);if(t===null)return e;let[r]=t;return r.length>=i.length?e.slice(i.length):e}).join(`
+`)}var Xn=class{constructor(e){I(this,`options`,void 0),I(this,`rules`,void 0),I(this,`lexer`,void 0),this.options=e||It}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:`space`,raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,``);return{type:`code`,raw:t[0],codeBlockStyle:`indented`,text:this.options.pedantic?e:Kn(e,`
+`)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=Yn(e,t[3]||``,this.rules);return{type:`code`,raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,`$1`):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=Kn(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:`hr`,raw:Kn(t[0],`
+`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=Kn(t[0],`
+`).split(`
+`),n=``,r=``,i=[];for(;e.length>0;){let t=!1,a=[],o=0;for(;o1,i={type:`list`,raw:``,ordered:r,start:r?+n.slice(0,-1):``,loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:`[*+-]`);let a=this.rules.other.listItemRegex(n),o=!1;for(;e;){let n=!1,r=``,s=``;if(!(t=a.exec(e))||this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let c=t[2].split(`
+`,1)[0].replace(this.rules.other.listReplaceTabs,e=>` `.repeat(3*e.length)),l=e.split(`
+`,1)[0],u=!c.trim(),d=0;if(this.options.pedantic?(d=2,s=c.trimStart()):u?d=t[1].length+1:(d=t[2].search(this.rules.other.nonSpaceChar),d=d>4?1:d,s=c.slice(d),d+=t[1].length),u&&this.rules.other.blankLine.test(l)&&(r+=l+`
+`,e=e.substring(l.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(d),n=this.rules.other.hrRegex(d),i=this.rules.other.fencesBeginRegex(d),a=this.rules.other.headingBeginRegex(d),o=this.rules.other.htmlBeginRegex(d);for(;e;){let f=e.split(`
+`,1)[0],p;if(l=f,this.options.pedantic?(l=l.replace(this.rules.other.listReplaceNesting,` `),p=l):p=l.replace(this.rules.other.tabCharGlobal,` `),i.test(l)||a.test(l)||o.test(l)||t.test(l)||n.test(l))break;if(p.search(this.rules.other.nonSpaceChar)>=d||!l.trim())s+=`
+`+p.slice(d);else{if(u||c.replace(this.rules.other.tabCharGlobal,` `).search(this.rules.other.nonSpaceChar)>=4||i.test(c)||a.test(c)||n.test(c))break;s+=`
+`+l}!u&&!l.trim()&&(u=!0),r+=f+`
+`,e=e.substring(f.length+1),c=p.slice(d)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(o=!0));let f=null,p;this.options.gfm&&(f=this.rules.other.listIsTask.exec(s),f&&(p=f[0]!==`[ ] `,s=s.replace(this.rules.other.listReplaceTask,``))),i.items.push({type:`list_item`,raw:r,task:!!f,checked:p,loose:!1,text:s,tokens:[]}),i.raw+=r}let s=i.items.at(-1);if(s)s.raw=s.raw.trimEnd(),s.text=s.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let e=0;ee.type===`space`);i.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}if(i.loose)for(let e=0;e({text:e,tokens:this.lexer.inline(e),header:!1,align:a.align[t]})));return a}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t)return{type:`heading`,raw:t[0],depth:t[2].charAt(0)===`=`?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e=t[1].charAt(t[1].length-1)===`
+`?t[1].slice(0,-1):t[1];return{type:`paragraph`,raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:`text`,raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:`escape`,raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:`html`,raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=Kn(e.slice(0,-1),`\\`);if((e.length-t.length)%2==0)return}else{let e=qn(t[2],`()`);if(e===-2)return;if(e>-1){let n=(t[0].indexOf(`!`)===0?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=``}}let n=t[2],r=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):``;return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),Jn(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,`$1`),title:r&&r.replace(this.rules.inline.anyPunctuation,`$1`)},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal,` `).toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:`text`,raw:e,text:e}}return Jn(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=``){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[2])||!n||this.rules.inline.punctuation.exec(n))){let n=[...r[0]].length-1,i,a,o=n,s=0,c=r[0][0]===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+n);(r=c.exec(t))!=null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}if((r[5]||r[6])&&n%3&&!((n+a)%3)){s+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+s);let t=[...r[0]][0].length,c=e.slice(0,n+r.index+t+a);if(Math.min(n,a)%2){let e=c.slice(1,-1);return{type:`em`,raw:c,text:e,tokens:this.lexer.inlineTokens(e)}}let l=c.slice(2,-2);return{type:`strong`,raw:c,text:l,tokens:this.lexer.inlineTokens(l)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal,` `),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:`codespan`,raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:`br`,raw:t[0]}}del(e){let t=this.rules.inline.del.exec(e);if(t)return{type:`del`,raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return t[2]===`@`?(e=t[1],n=`mailto:`+e):(e=t[1],n=e),{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if(t[2]===`@`)e=t[0],n=`mailto:`+e;else{let r;do r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??``;while(r!==t[0]);e=t[0],n=t[1]===`www.`?`http://`+t[0]:t[0]}return{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:`text`,raw:t[0],text:t[0],escaped:e}}}},H=class e{constructor(e){I(this,`tokens`,void 0),I(this,`options`,void 0),I(this,`state`,void 0),I(this,`tokenizer`,void 0),I(this,`inlineQueue`,void 0),this.tokens=[],this.tokens.links=Object.create(null),this.options=e||It,this.options.tokenizer=this.options.tokenizer||new Xn,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:R,block:Bn.normal,inline:Vn.normal};this.options.pedantic?(t.block=Bn.pedantic,t.inline=Vn.pedantic):this.options.gfm&&(t.block=Bn.gfm,t.inline=this.options.breaks?Vn.breaks:Vn.gfm),this.tokenizer.rules=t}static get rules(){return{block:Bn,inline:Vn}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(R.carriageReturn,`
+`),this.blockTokens(e,this.tokens);for(let e=0;e(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let n=t.at(-1);r.raw.length===1&&n!==void 0?n.raw+=`
+`:t.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(`
+`)?``:`
+`)+r.raw,n.text+=`
+`+r.text,this.inlineQueue.at(-1).src=n.text):t.push(r);continue}if((r=this.tokenizer.fences(e))||(r=this.tokenizer.heading(e))||(r=this.tokenizer.hr(e))||(r=this.tokenizer.blockquote(e))||(r=this.tokenizer.list(e))||(r=this.tokenizer.html(e))){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(`
+`)?``:`
+`)+r.raw,n.text+=`
+`+r.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title},t.push(r));continue}if((r=this.tokenizer.table(e))||(r=this.tokenizer.lheading(e))){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startBlock){let t=1/0,n=e.slice(1),r;this.options.extensions.startBlock.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(this.state.top&&(r=this.tokenizer.paragraph(i))){let a=t.at(-1);n&&a?.type===`paragraph`?(a.raw+=(a.raw.endsWith(`
+`)?``:`
+`)+r.raw,a.text+=`
+`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):t.push(r),n=i.length!==e.length,e=e.substring(r.raw.length)}else if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`text`?(n.raw+=(n.raw.endsWith(`
+`)?``:`
+`)+r.raw,n.text+=`
+`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n=e,r=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(n))!=null;)e.includes(r[0].slice(r[0].lastIndexOf(`[`)+1,-1))&&(n=n.slice(0,r.index)+`[`+`a`.repeat(r[0].length-2)+`]`+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(n))!=null;)n=n.slice(0,r.index)+`++`+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(r=this.tokenizer.rules.inline.blockSkip.exec(n))!=null;)i=r[2]?r[2].length:0,n=n.slice(0,r.index+i)+`[`+`a`.repeat(r[0].length-i-2)+`]`+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n;let a=!1,o=``;for(;e;){a||(o=``),a=!1;let r;if(this.options.extensions?.inline?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if((r=this.tokenizer.escape(e))||(r=this.tokenizer.tag(e))||(r=this.tokenizer.link(e))){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);let n=t.at(-1);r.type===`text`&&n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if((r=this.tokenizer.emStrong(e,n,o))||(r=this.tokenizer.codespan(e))||(r=this.tokenizer.br(e))||(r=this.tokenizer.del(e))||(r=this.tokenizer.autolink(e))||!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startInline){let t=1/0,n=e.slice(1),r;this.options.extensions.startInline.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(r=this.tokenizer.inlineText(i)){e=e.substring(r.raw.length),r.raw.slice(-1)!==`_`&&(o=r.raw.slice(-1)),a=!0;let n=t.at(-1);n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return t}},Zn=class{constructor(e){I(this,`options`,void 0),I(this,`parser`,void 0),this.options=e||It}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(R.notSpaceStart)?.[0],i=e.replace(R.endingNewline,``)+`
+`;return r?`
+`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`${n}>
+`}strong({tokens:e}){return`${this.parser.parseInline(e)}`}em({tokens:e}){return`${this.parser.parseInline(e)}`}codespan({text:e}){return`${V(e,!0)}`}br(e){return` `}del({tokens:e}){return`${this.parser.parseInline(e)}`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=Wn(e);if(i===null)return r;e=i;let a=``+r+``,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=Wn(e);if(i===null)return V(n);e=i;let a=``,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:V(e.text)}},Qn=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}},U=class e{constructor(e){I(this,`options`,void 0),I(this,`renderer`,void 0),I(this,`textRenderer`,void 0),this.options=e||It,this.options.renderer=this.options.renderer||new Zn,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Qn}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e,t=!0){let n=``;for(let r=0;r{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new Zn(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new Xn(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new $n;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=$n.passThroughHooks.has(n)?e=>{if(this.defaults.async&&$n.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return H.lex(e,t??this.defaults)}parser(e,t){return U.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer():e?H.lex:H.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser():e?U.parse:U.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer():e?H.lex:H.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser():e?U.parse:U.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
+Please report this to https://github.com/markedjs/marked.`,e){let e=`
An error occurred:
`+V(n.message+``,!0)+`
`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function W(e,t){return er.parse(e,t)}W.options=W.setOptions=function(e){return er.setOptions(e),W.defaults=er.defaults,Lt(W.defaults),W},W.getDefaults=Ft,W.defaults=It,W.use=function(...e){return er.use(...e),W.defaults=er.defaults,Lt(W.defaults),W},W.walkTokens=function(e,t){return er.walkTokens(e,t)},W.parseInline=er.parseInline,W.Parser=U,W.parser=U.parse,W.Renderer=Zn,W.TextRenderer=Qn,W.Lexer=H,W.lexer=H.lex,W.Tokenizer=Xn,W.Hooks=$n,W.parse=W,W.options,W.setOptions,W.use,W.walkTokens,W.parseInline,U.parse,H.lex;function tr(e,t){this.v=e,this.k=t}function nr(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`?null:Y(BigInt.prototype.toString),Rr=typeof Symbol>`u`?null:Y(Symbol.prototype.toString),q=Y(Object.prototype.hasOwnProperty),zr=Y(Object.prototype.toString),Br=RegExp.prototype.test,J=function(e,t){return e instanceof RegExp&&(e.lastIndex=0),_r(Br,e,[t])},Vr=Hr(TypeError);function Y(e){return function(t){var n=[...arguments].slice(1);return _r(e,t,n)}}function Hr(e){return function(){return vr(e,[...arguments])}}function X(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:kr;if(dr&&dr(e,null),!Tr(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(fr(t)||(t[r]=e),i=e)}e[i]=!0}return e}function Ur(e){for(let t=0;t/g),ci=K(/\${[\w\W]*/g),li=K(/{{|}}|\${|<%|%>|<%|%>/),ui=K(/^data-[\-\w.\u00B7-\uFFFF]+$/),di=K(/^aria-[\-\w]+$/),fi=K(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),pi=K(/^(?:\w+script|data):/i),mi=K(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),hi=K(/^html$/i),gi=K(/^[a-z][.\w]*(-[.\w]+)+$/i),_i=K(/<[/\w!]/g),vi=K(/<[/\w]/g),yi=K(/<\/no(script|embed|frames)/i),bi=K(/\/>/i),xi=K(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i),Si=K(/^[\r\n\t ]+/),Q={element:1,text:3,processingInstruction:7,comment:8,document:9,documentFragment:11},Ci=G(X({},[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`])),wi=function(){return typeof window>`u`?null:window},Ti=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},Ei=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Di=function(e,t,n,r){return q(e,t)&&Tr(e[t])?X(r.base?Gr(r.base):{},e[t],r.transform):n},Oi=function(e,t,n){let r=q(e,t)?e[t]:void 0;return r&&typeof r==`object`?Wr(r):n};function ki(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:wi(),t=e=>ki(e);if(t.version=`3.4.18`,t.removed=[],!e||!e.document||e.document.nodeType!==Q.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript,a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter,l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=Z(d,`cloneNode`),p=Z(d,`remove`),m=Z(d,`removeAttributeNode`),h=Z(d,`nextSibling`),g=Z(d,`childNodes`),_=Z(d,`parentNode`),ee=Z(d,`shadowRoot`),te=Z(d,`attributes`),ne=o&&o.prototype?Z(o.prototype,`nodeType`):null,v=o&&o.prototype?Z(o.prototype,`nodeName`):null,y=o&&o.prototype?Z(o.prototype,`ownerDocument`):null,b=function(e){return ne?ne(e):e.nodeType},x=function(e){return v?v(e):e.nodeName},re=qr(d,`namespaceURI`),ie=function(e){return re?re(e):e.namespaceURI};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let S,ae=``,oe,se=!1,ce=0,le=function(){if(ce>0)throw Vr(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},ue=function(e){le(),ce++;try{return S.createHTML(e)}finally{ce--}},de=function(e){return S&&Ge?ue(e):e},fe=function(e){le(),ce++;try{return S.createScriptURL(e)}finally{ce--}},pe=function(){return se||(oe=Ti(u,i),se=!0),oe},me=n,he=me.implementation,ge=me.createNodeIterator,_e=me.createDocumentFragment,ve=me.getElementsByTagName,ye=r.importNode,C=Ei();t.isSupported=typeof lr==`function`&&typeof _==`function`&&he&&he.createHTMLDocument!==void 0;let be=oi,xe=si,Se=ci,Ce=ui,we=di,Te=pi,Ee=mi,De=gi,Oe=fi,w=null,ke=X({},[...Yr,...Xr,...Zr,...$r,...ti]),T=null,Ae=X({},[...ni,...ri,...ii,...ai]),E=null,je=null,Me=null,Ne=Object.seal(hr(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Pe=!0,Fe=!0,Ie=!1,Le=!0,D=!1,Re=!0,ze=!1,Be=!1,Ve=null,He=null,Ue=!1,O=!1,We=!1,Ge=!1,Ke=!0,qe=!1,Je=`user-content-`,Ye=!0,Xe=!1,Ze=null,Qe=!1,k=null,$e=X({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),et=null,A=X({},[`audio`,`video`,`img`,`source`,`image`,`track`]),j=null,tt=X({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),nt=`http://www.w3.org/1998/Math/MathML`,rt=`http://www.w3.org/2000/svg`,M=`http://www.w3.org/1999/xhtml`,it=M,at=!1,ot=null,st=X({},[nt,rt,M],Ar),ct=G(X({},[`mi`,`mo`,`mn`,`ms`,`mtext`])),lt=null,ut=G(X({},[`annotation-xml`])),dt=null,ft=G(hr(null)),pt=X({},[`title`,`style`,`font`,`a`,`script`]),mt=null,ht=[`application/xhtml+xml`,`text/html`],N=null,gt=null,_t=n.createElement(`form`),vt=function(e){return e instanceof RegExp||e instanceof Function},P=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};e&&typeof e==`object`||(e={}),e=Wr(e),mt=ht.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,N=mt===`application/xhtml+xml`?Ar:kr,w=Di(e,`ALLOWED_TAGS`,ke,{transform:N}),T=Di(e,`ALLOWED_ATTR`,Ae,{transform:N}),ot=Di(e,`ALLOWED_NAMESPACES`,st,{transform:Ar}),j=Di(e,`ADD_URI_SAFE_ATTR`,tt,{transform:N,base:tt}),et=Di(e,`ADD_DATA_URI_TAGS`,A,{transform:N,base:A}),k=Di(e,`FORBID_CONTENTS`,$e,{transform:N}),je=Di(e,`FORBID_TAGS`,hr(null),{transform:N}),Me=Di(e,`FORBID_ATTR`,hr(null),{transform:N}),Qe=q(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?Wr(e.USE_PROFILES):e.USE_PROFILES:!1,Pe=e.ALLOW_ARIA_ATTR!==!1,Fe=e.ALLOW_DATA_ATTR!==!1,Ie=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Le=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,D=e.SAFE_FOR_TEMPLATES||!1,Re=e.SAFE_FOR_XML!==!1,ze=e.WHOLE_DOCUMENT||!1,O=e.RETURN_DOM||!1,We=e.RETURN_DOM_FRAGMENT||!1,Ge=e.RETURN_TRUSTED_TYPE||!1,Ue=e.FORCE_BODY||!1,Ke=e.SANITIZE_DOM!==!1,qe=e.SANITIZE_NAMED_PROPS||!1,Ye=e.KEEP_CONTENT!==!1,Xe=e.IN_PLACE||!1,Oe=Jr(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:fi,it=typeof e.NAMESPACE==`string`?e.NAMESPACE:M,lt=Oi(e,`MATHML_TEXT_INTEGRATION_POINTS`,ct),dt=Oi(e,`HTML_INTEGRATION_POINTS`,ut);let t=Oi(e,`CUSTOM_ELEMENT_HANDLING`,ft);if(E=hr(null),q(t,`tagNameCheck`)&&vt(t.tagNameCheck)&&(E.tagNameCheck=t.tagNameCheck),q(t,`attributeNameCheck`)&&vt(t.attributeNameCheck)&&(E.attributeNameCheck=t.attributeNameCheck),q(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(E.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),K(E),D&&(Fe=!1),We&&(O=!0),Qe&&((q(e,`ALLOWED_TAGS`)||q(e,`ALLOWED_ATTR`))&&typeof console<`u`&&typeof console.warn==`function`&&console.warn(`DOMPurify: USE_PROFILES overrides ALLOWED_TAGS and ALLOWED_ATTR. Do not use these options together.`),w=X({},ti),T=hr(null),Qe.html===!0&&(X(w,Yr),X(T,ni)),Qe.svg===!0&&(X(w,Xr),X(T,ri),X(T,ai)),Qe.svgFilters===!0&&(X(w,Zr),X(T,ri),X(T,ai)),Qe.mathMl===!0&&(X(w,$r),X(T,ii),X(T,ai))),Ne.tagCheck=null,Ne.attributeCheck=null,q(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?Ne.tagCheck=e.ADD_TAGS:Tr(e.ADD_TAGS)&&(w===ke&&(w=Gr(w)),X(w,e.ADD_TAGS,N))),q(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?Ne.attributeCheck=e.ADD_ATTR:Tr(e.ADD_ATTR)&&(T===Ae&&(T=Gr(T)),X(T,e.ADD_ATTR,N))),q(e,`ADD_FORBID_CONTENTS`)&&Tr(e.ADD_FORBID_CONTENTS)&&(k===$e&&(k=Gr(k)),X(k,e.ADD_FORBID_CONTENTS,N)),Ye&&(w[`#text`]=!0),ze&&X(w,[`html`,`head`,`body`]),w.table&&(w.tbody=!0,delete je.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw Vr(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw Vr(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=S;S=e.TRUSTED_TYPES_POLICY;try{ae=ue(``)}catch(e){throw S=t,e}}else e.TRUSTED_TYPES_POLICY===null?(S=void 0,ae=``):(S===void 0&&(S=pe()),S&&typeof ae==`string`&&(ae=ue(``)));gt=G(e)},yt=X({},[...Xr,...Zr,...Qr]),bt=X({},[...$r,...ei]),xt=function(e,t,n){return t===M?e===`svg`:t===nt?e===`svg`&&(n===`annotation-xml`||lt[n]):!!yt[e]},St=function(e,t,n){return t===M?e===`math`:t===rt?e===`math`&&dt[n]:!!bt[e]},Ct=function(e,t,n){return t===rt&&!dt[n]||t===nt&&!lt[n]?!1:!bt[e]&&(pt[e]||!yt[e])},wt=function(e){let t=ie(e),n=kr(x(e)),r=_(e),i=it,a=`template`;return r&&b(r)===Q.element&&(i=ie(r),a=kr(x(r))),ot[t]?t===rt?xt(n,i,a):t===nt?St(n,i,a):t===M?Ct(n,i,a):mt===`application/xhtml+xml`:!1},F=function(e){Sr(t.removed,{element:e});try{_(e).removeChild(e)}catch{if(p(e),!_(e))throw Vr(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},Tt=function(e,t,n){try{m(e,t)}catch{try{e.removeAttribute(n)}catch{}}},Et=function(e){At(e);let t=g(e);t&&yr(Cr(t),e=>{try{p(e)}catch{}}),b(e)===Q.element&&Ot(e,!1)},Dt=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}if(Sr(t.removed,{attribute:r||null,from:n}),r)Tt(n,r,e);else try{n.removeAttribute(e)}catch{}if(e===`is`){if(O||We)try{F(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},Ot=function(e,t){let n=te(e);if(n)for(let r=n.length-1;r>=0;--r){let i=n[r],a=i&&i.name;typeof a==`string`&&!(t&&T[N(a)])&&Tt(e,i,a)}},kt=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0&&arguments[2],r=[e];for(;r.length>0;){let e=r.pop();if(t(e)===!1)continue;if(n&&b(e)===Q.element){let t=ee(e);z(t)&&r.push(t)}let i=g(e);if(i)for(let e=i.length-1;e>=0;--e)r.push(i[e])}},At=function(e){kt(e,e=>{b(e)===Q.element&&Ot(e,!0)})},jt=function(e){let t=[];return kt(e,e=>{t.push(e)},!0),t},Mt=function(e,t){let n=Er();yr(jt(e),e=>{b(e)===Q.element&&Dr(n,e)}),yr(t,e=>{b(e)===Q.element&&!Or(n,e)&&Ot(e,!0)})},Nt=function(e,n){let r=!1;return yr(t.removed,t=>{t.element&&(r=r||t.element===e,At(t.element))}),Mt(e,n),r},I=function(e,t){let n=Ze,r=null,i=()=>(r||(r=Er(),yr(t,e=>{Dr(r,e)})),r);for(let t=0;;t++){let r=jt(e),a=[e],o=!1;if(yr(r,e=>{b(e)===Q.documentFragment?Sr(a,e):!o&&!Or(n,e)&&(o=Or(i(),e))}),!o)return;if(t>=8)throw Vr(`the tree kept changing during in-place sanitization; refusing to return it`);yr(a,(t,n)=>{Pt(t,n>0,e,i())})}},Pt=function(e,t,n,r){let i=L(e),a;for(;a=i.nextNode();)Or(r,a)&&!Or(Ze,a)&&(t&&B(C.uponSanitizeShadowNode,a,null),rn(a,n))},Ft=function(e){Ze&&Dr(Ze,e)},It=function(e,t){return Re?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},Lt=function(e){Re&&kt(e,e=>{let t=b(e);if(t===Q.processingInstruction||t===Q.comment&&J(vi,e.data)){try{p(e)}catch{}return!1}if(t===Q.element){let t=e,n=N(x(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&It(`for`,n)&&t.removeAttribute(`for`)}catch{}}return!0})},Rt=function(e){let t=null,r=null;if(Ue)e=``+e;else{let t=jr(e,Si);r=t&&t[0]}mt===`application/xhtml+xml`&&it===M&&(e=``+e+``);let i=S?ue(e):e;if(it===M)try{t=new l().parseFromString(i,mt)}catch{}if(!t||!t.documentElement){t=he.createDocument(it,`template`,null);try{t.documentElement.innerHTML=at?ae:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),it===M?ve.call(t,ze?`html`:`body`)[0]:ze?t.documentElement:a},L=function(e){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=y?y(e):e.ownerDocument;return ge.call(n||e,e,(t?0:c.SHOW_ELEMENT)|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},zt=function(e){return e=Mr(e,be,` `),e=Mr(e,xe,` `),e=Mr(e,Se,` `),e},R=function(e){Bt(e);let t=e.querySelectorAll?.call(e,`template`);t&&yr(t,e=>{z(e.content)&&R(e.content)})},Bt=function(e){e.normalize();let t=L(e,!0),n=t.nextNode();for(;n;)n.data=zt(n.data),n=t.nextNode()},Vt=function(e){let t=v?v(e):null;return typeof t!=`string`||N(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==te(e)||typeof e.removeAttribute!=`function`||typeof e.removeAttributeNode!=`function`||typeof e.getAttributeNode!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==ne(e)||e.childNodes!==g(e)},Ht=function(e){if(!ne||typeof e!=`object`||!e)return null;try{let t=ne(e);return typeof t==`number`?t:null}catch{return null}},z=function(e){return Ht(e)===Q.documentFragment},Ut=function(e){return Ht(e)!==null};function B(e,n,r){e.length!==0&&yr(e,e=>{e.call(t,n,r,gt)})}let Wt=function(e,t,n){return!!(Re&&n===Q.element&&e.hasChildNodes()&&!Ut(e.firstElementChild)&&J(_i,e.textContent)&&J(_i,e.innerHTML)||Re&&Ci[t]&&n===Q.element&&ie(e)===M&&(Ut(e.firstElementChild)||typeof e.textContent==`string`&&J(_i,e.textContent))||n===Q.processingInstruction||Re&&n===Q.comment&&J(vi,e.data))},Gt=function(e,t){return e instanceof RegExp?J(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},Kt=function(e,t,n){if(!je[t]&&Qt(t)&&Gt(E.tagNameCheck,t))return!1;if(Ye&&!k[t]&&!k[kr(t)]){let t=_(e),r=g(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,h(e))}}}return F(e),!0},qt=function(e,t,n,r){return e.length===0?t:t===n||t===r?Gr(t):t},Jt=function(e,t){return e===t||_(e)!==null?!1:(Xe&&At(e),!0)},Yt=function(e,n){if(Ft(e),B(C.beforeSanitizeElements,e,null),Jt(e,n))return!0;if(Vt(e))return F(e),!0;let r=N(x(e)),i=b(e);if(w=qt(C.uponSanitizeElement,w,ke,Ve),B(C.uponSanitizeElement,e,{tagName:r,allowedTags:w}),Jt(e,n))return!0;if(Wt(e,r,i))return F(e),!0;if(je[r]||!(Ne.tagCheck instanceof Function&&Ne.tagCheck(r))&&!w[r]){let t=Kt(e,r,n);return t===!1&&(B(C.afterSanitizeElements,e,null),Jt(e,n))?!0:t}if(i===Q.element&&!wt(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&J(yi,e.innerHTML))return F(e),!0;if(D&&i===Q.text){let n=e.textContent,r=zt(n);n!==r&&(Sr(t.removed,{element:e.cloneNode()}),e.textContent=r)}return B(C.afterSanitizeElements,e,null),Jt(e,n)},Xt=function(e,t,r){if(Me[t]||It(t,e)||Ke&&(t===`id`||t===`name`)&&(r in n||r in _t))return!1;let i=T[t]||Ne.attributeCheck instanceof Function&&Ne.attributeCheck(t,e);if(Fe&&J(Ce,t)||Pe&&J(we,t))return!0;if(!i)return Qt(e)&&Gt(E.tagNameCheck,e)&&Gt(E.attributeNameCheck,t,e)||t===`is`&&E.allowCustomizedBuiltInElements&&Gt(E.tagNameCheck,r);if(j[t])return!0;let a=Mr(r,Ee,``);return J(Oe,a)||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&Nr(r,`data:`)===0&&et[e]||Ie&&!J(Te,a)?!0:!r},Zt=X({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Qt=function(e){return!Zt[kr(e)]&&J(De,e)},$t=function(e,t,n,r){if(S&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return ue(r);case`TrustedScriptURL`:return fe(r)}return r},en=function(e,t,n,r){try{return n?e.setAttributeNS(n,t,r):e.setAttribute(t,r),!Vt(e)||(F(e),!1)}catch{return Dt(t,e),!1}},tn=function(e,t){return Re&&J(xi,t)?!0:kr(e)===`attributename`&&Nr(t,`href`)!==-1},nn=function(e,n){if(B(C.beforeSanitizeAttributes,e,null),Jt(e,n))return;let r=e.attributes;if(!r||Vt(e))return;T=qt(C.uponSanitizeAttribute,T,Ae,He);let i={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:T,forceKeepAttr:void 0},a=r.length,o=N(x(e));for(;a--;){let n=r[a],s=n.name,c=n.namespaceURI,l=n.value,u=N(s),d=l,f=s===`value`?d:Pr(d),p=!1;i.attrName=u,i.attrValue=f,i.keepAttr=!0,i.forceKeepAttr=void 0,B(C.uponSanitizeAttribute,e,i),f=i.attrValue,qe&&(u===`id`||u===`name`)&&Nr(f,Je)!==0&&(Dt(s,e,n),f=Je+f,p=!0),tn(s,f)?Dt(s,e,n):i.forceKeepAttr||(i.keepAttr?!Le&&J(bi,f)?Dt(s,e,n):(D&&(f=zt(f)),Xt(o,u,f)?(f=$t(o,u,c,f),f!==d&&en(e,s,c,f)&&p&&xr(t.removed)):Dt(s,e,n)):Dt(s,e,n))}B(C.afterSanitizeAttributes,e,null),Jt(e,n)},rn=function(e,t){Yt(e,t),nn(e,t),z(e.content)&&an(e.content)},an=function(e){let t=null,n=L(e);for(B(C.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(B(C.uponSanitizeShadowNode,t,null),rn(t,e),b(t)===Q.element){let e=ee(t);z(e)&&(on(e),an(e))}D&&Bt(e),B(C.afterSanitizeShadowDOM,e,null)},on=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){an(e.shadow);continue}let n=e.node,r=b(n)===Q.element,i=g(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=v?v(n):null;if(typeof e==`string`&&N(e)===`template`){let e=n.content;z(e)&&t.push({node:e,shadow:null})}}if(r){let e=ee(n);z(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(at=!e,at&&(e=``),typeof e!=`string`&&!Ut(e)&&(e=Kr(e),typeof e!=`string`))throw Vr(`dirty is not a string, aborting`);if(!t.isSupported)return e;Be?(w=Ve,T=He):P(n),t.removed=[];let c=Xe&&typeof e!=`string`&&Ut(e),l=[],u=Ze;if(c){Lt(e);let t=x(e);if(typeof t==`string`){let n=N(t);if(!w[n]||je[n])throw Et(e),Vr(`root node is forbidden and cannot be sanitized in-place`)}if(Vt(e))throw Et(e),Vr(`root node is clobbered and cannot be sanitized in-place`);l=jt(e),Ze=Er()}else if(Ut(e))i=Rt(``),a=i.ownerDocument.importNode(e,!0),a.nodeType===Q.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),on(i);else{if(!O&&!D&&!ze&&e.indexOf(`<`)===-1)return de(e);if(i=Rt(e),!i)return O?null:Ge?ae:``}i&&Ue&&F(i.firstChild);let d=c?e:i;try{c&&on(e);let t=L(d);for(;o=t.nextNode();)rn(o,d);c&&I(e,l)}catch(t){throw c&&(Et(e),Nt(e,l)),t}finally{Ze=u}if(c){if(Nt(e,l))throw Vr(`a node selected for removal could not be safely returned; refusing to sanitize in place`);return D&&R(e),e}if(O){if(D&&R(i),We)for(s=_e.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(T.shadowroot||T.shadowrootmode)&&(s=ye.call(r,s,!0)),s}let f=()=>ze?i.outerHTML:i.innerHTML,p=f();return D&&J(li,p)&&(Bt(i),p=f()),ze&&w[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&J(hi,i.ownerDocument.doctype.name)&&(p=`
+`+p),de(p)},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};P(e),Be=!0,Ve=w,He=T},t.clearConfig=function(){gt=null,Be=!1,Ve=null,He=null,S=oe,ae=``},t.isValidAttribute=function(e,t,n){gt||P({});let r=N(e),i=N(t);return typeof n==`string`&&(tn(t,n)||!Le&&J(bi,n))?!1:Xt(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&q(C,e)&&Sr(C[e],t)},t.removeHook=function(e,t){if(q(C,e)){if(t!==void 0){let n=br(C[e],t);return n===-1?void 0:wr(C[e],n,1)[0]}return xr(C[e])}},t.removeHooks=function(e){q(C,e)&&(C[e]=[])},t.removeAllHooks=function(){C=Ei()},t}var Ai=ki(),ji=[`critical`,`high`,`medium`,`low`,`info`],Mi={critical:`red`,high:`orange`,medium:`amber`,low:`blue`,info:`grey`},Ni={critical:`严重`,high:`高危`,medium:`中危`,low:`低危`,info:`信息`},Pi={running:`blue`,pending:`amber`,queued:`amber`,paused:`grey`,success:`green`,succeeded:`green`,completed:`green`,done:`green`,failed:`red`,error:`red`,cancelled:`grey`,canceled:`grey`,stopped:`grey`,active:`green`,inactive:`grey`,online:`green`,offline:`grey`,open:`red`,closed:`green`,archived:`grey`};function Fi(e,t=`zh-CN`){if(!e)return`—`;let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.getTime())?n.toLocaleString(t,{hour12:!1}):`—`}function Ii(e,t=`zh-CN`){if(!e)return`—`;let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.getTime())?n.toLocaleDateString(t):`—`}function Li(e,t=`zh-CN`){if(!e)return`—`;let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.getTime())?n.toLocaleTimeString(t,{hour12:!1}):`—`}function Ri(e,t){if(!e)return`—`;let n=new Date(e);if(!Number.isFinite(n.getTime()))return`—`;let r=Date.now()-n.getTime();return r<6e4?t?.(`common.justNow`,null,`刚刚`)||`刚刚`:r<36e5?t?.(`common.minutesAgo`,{n:Math.floor(r/6e4)},`${Math.floor(r/6e4)} 分钟前`):r<864e5?t?.(`common.hoursAgo`,{n:Math.floor(r/36e5)},`${Math.floor(r/36e5)} 小时前`):r<2592e6?t?.(`common.daysAgo`,{n:Math.floor(r/864e5)},`${Math.floor(r/864e5)} 天前`):Ii(e)}function zi(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return`—`;if(t<1024)return`${t} B`;let n=[`KB`,`MB`,`GB`,`TB`],r=t/1024,i=0;for(;r>=1024&&i=100?0:1)} ${n[i]}`}function Bi(e,t=`zh-CN`){let n=Number(e);return Number.isFinite(n)?n.toLocaleString(t):`—`}function Vi(e,t=1){let n=Number(e);return Number.isFinite(n)?`${(n*(n<=1?100:1)).toFixed(t)}%`:`—`}function Hi(e){return Mi[String(e||``).toLowerCase()]||`grey`}function Ui(e){return Pi[String(e||``).toLowerCase()]||`grey`}function Wi(e,t=120){let n=String(e??``);return n.length>t?`${n.slice(0,t)}…`:n}var{Title:Gi,Text:Ki,Paragraph:qi}=c;function Ji(e){Ce.success({content:e,duration:2})}function Yi(e){Ce.warning({content:e,duration:3})}function Xi(e,t=`操作失败`){Ce.error({content:rt(e,t),duration:4})}function Zi({title:e,description:t,extra:n,children:r}){return(0,M.jsxs)(`header`,{className:`cs-page-header`,children:[(0,M.jsxs)(`div`,{className:`cs-page-header-main`,children:[(0,M.jsx)(Gi,{heading:3,className:`cs-page-title`,children:e}),t&&(0,M.jsx)(Ki,{type:`tertiary`,className:`cs-page-desc`,children:t}),r]}),n&&(0,M.jsx)(f,{className:`cs-page-header-extra`,wrap:!0,children:n})]})}function Qi({title:e,description:t,extra:n,children:r,className:i=``,bodyClassName:a=``}){return(0,M.jsxs)(s,{className:`cs-section-card ${i}`,title:e?(0,M.jsx)(`span`,{className:`cs-section-title`,children:e}):void 0,headerExtraContent:n,bordered:!1,children:[t&&(0,M.jsx)(qi,{type:`tertiary`,className:`cs-section-desc`,children:t}),(0,M.jsx)(`div`,{className:a,children:r})]})}function $i({metrics:e,columns:t=4}){return(0,M.jsx)(`div`,{className:`cs-stat-grid`,style:{"--cs-stat-columns":t},children:e.map(e=>(0,M.jsx)(ea,{...e},e.id||e.label))})}function ea({label:e,value:t,valueTitle:n,detail:r,tone:i,severity:a,icon:o,onClick:c,pressed:l,loading:u=!1}){let d=(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`span`,{className:`cs-stat-head`,children:[(0,M.jsx)(Ki,{type:`tertiary`,className:`cs-stat-label`,children:e}),o&&(0,M.jsx)(`span`,{className:`cs-stat-icon ${i?`tone-${i}`:``}`,"aria-hidden":`true`,children:o})]}),(0,M.jsx)(_,{loading:u,placeholder:(0,M.jsx)(_.Title,{style:{width:`60%`,height:36,margin:`8px 0`}}),children:(0,M.jsx)(`span`,{className:`cs-stat-value ${i?`tone-${i}`:``}`,title:n,children:t??`—`})}),r&&(0,M.jsx)(`span`,{className:`cs-stat-detail`,children:r})]});return c?(0,M.jsx)(b,{className:`cs-stat-card is-clickable`,theme:`borderless`,onClick:c,"aria-label":String(e),"aria-pressed":l,"data-severity":a,children:d}):(0,M.jsx)(s,{className:`cs-stat-card`,"data-severity":a,bordered:!1,children:d})}function ta({columns:e,dataSource:t,rowKey:n=`id`,loading:r,pagination:i,emptyText:a,onRefresh:s,toolbar:c,size:l=`default`,className:u=``,...d}){let f=P(),p=i!==!1&&{pageSize:10,showSizeChanger:!0,pageSizeOpts:[10,20,50,100],showTotal:!0,...i||{}};return(0,M.jsxs)(`div`,{className:`cs-table-wrap ${u}`,children:[(c||s)&&(0,M.jsxs)(`div`,{className:`cs-table-toolbar`,children:[(0,M.jsx)(`div`,{className:`cs-table-toolbar-main`,children:c}),s&&(0,M.jsx)(b,{icon:(0,M.jsx)(T,{}),theme:`borderless`,onClick:s,loading:r,children:f(`common.refresh`,null,`刷新`)})]}),(0,M.jsx)(`div`,{className:`cs-table-scroll`,children:(0,M.jsx)(ke,{columns:e,dataSource:t||[],rowKey:n,loading:r,pagination:p,size:l,empty:(0,M.jsx)(o,{image:(0,M.jsx)(je,{size:`extra-large`}),title:a||f(`common.noData`,null,`暂无数据`),description:null,className:`cs-table-empty`}),...d})})]})}function na({error:e,onRetry:t}){let n=P();return e?(0,M.jsx)(i,{type:`danger`,bordered:!0,closeIcon:null,className:`cs-error-banner`,description:(0,M.jsxs)(f,{wrap:!0,children:[(0,M.jsx)(`span`,{children:rt(e,n(`common.loadFailed`,null,`加载失败`))}),t&&(0,M.jsx)(b,{size:`small`,onClick:t,children:n(`common.refresh`,null,`刷新`)})]})}):null}function ra({severity:e,size:t=`small`}){let n=String(e||``).toLowerCase();return(0,M.jsx)(te,{size:t,color:Hi(n),shape:`circle`,className:`cs-severity-tag`,"data-severity":ji.includes(n)?n:void 0,children:Ni[n]||e||`—`})}function ia({status:e,label:t,size:n=`small`}){let r=String(e||``).toLowerCase();return(0,M.jsx)(te,{size:n,color:Ui(r),shape:`square`,children:t||e||`—`})}function aa({text:e,label:t,size:n=`default`,theme:r=`borderless`}){let i=P();return(0,M.jsx)(b,{size:n,theme:r,icon:(0,M.jsx)(x,{}),"aria-label":t||i(`common.copy`,null,`复制`),onClick:async()=>{try{await navigator.clipboard.writeText(String(e??``)),Ji(i(`common.copied`,null,`已复制`))}catch(e){Xi(e,i(`common.copyFailed`,null,`复制失败`))}},children:t})}function oa({content:e,className:t=``}){let n=(0,O.useMemo)(()=>{let t=W.parse(String(e??``),{breaks:!0,gfm:!0});return Ai.sanitize(t,{ADD_ATTR:[`target`,`rel`]})},[e]);return(0,M.jsx)(`div`,{className:`cs-markdown ${t}`,dangerouslySetInnerHTML:{__html:n}})}function sa({value:e,collapsed:t=!1,title:n}){let[r,i]=(0,O.useState)(!t),a=P(),o=(0,O.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]);return(0,M.jsxs)(`div`,{className:`cs-json-viewer`,children:[(0,M.jsxs)(`div`,{className:`cs-json-viewer-head`,children:[(0,M.jsx)(Ki,{strong:!0,children:n||`JSON`}),(0,M.jsxs)(f,{spacing:4,children:[(0,M.jsx)(aa,{text:o}),(0,M.jsx)(b,{theme:`borderless`,size:`small`,icon:r?(0,M.jsx)(d,{}):(0,M.jsx)(l,{}),"aria-expanded":r,"aria-label":a(r?`common.collapse`:`common.expand`,null,r?`收起`:`展开`),onClick:()=>i(e=>!e)})]})]}),(0,M.jsx)(ee,{isOpen:r,children:(0,M.jsx)(`pre`,{className:`cs-json-viewer-body`,children:o})})]})}function ca({items:e,columns:t=2}){return(0,M.jsx)(v,{className:`cs-description-list`,layout:`horizontal`,align:`plain`,column:t,data:e.filter(Boolean).map(e=>({key:e.label,value:e.value??`—`}))})}function la({title:e,content:t,okText:n,danger:r=!0,onOk:i}){ie.confirm({title:e,content:t,okText:n||`确定`,cancelText:`取消`,okButtonProps:r?{type:`danger`}:void 0,onOk:i})}var ua=`a[href], button, input, select, textarea, iframe, [tabindex], [contenteditable="true"]`;function da({title:e,visible:t,onCancel:n,width:r=560,footer:i,children:a,className:o,closeOnEsc:s=!0,mask:c=!0,maskClosable:l=!0,onOk:u,formId:d,okText:f,cancelText:p,okButtonProps:m,cancelButtonProps:h,confirmLoading:g,..._}){let ee=P(),te=(0,O.useRef)(null),[ne,v]=(0,O.useState)(!1),y=g??ne,x=(0,O.useCallback)(e=>{let t=e?.closest(`[role="dialog"]`);if(!t)return;te.current=t;let n=document.activeElement;return c&&(t.setAttribute(`aria-modal`,`true`),queueMicrotask(()=>{te.current===t&&!t.contains(document.activeElement)&&t.focus({preventScroll:!0})})),()=>{if(te.current=null,!c)return;t.removeAttribute(`aria-modal`);let e=document.activeElement;n?.isConnected&&(t.contains(e)||e===document.body)&&n.focus({preventScroll:!0})}},[c]);(0,O.useEffect)(()=>{if(!t)return;let e=e=>{let t=te.current,r=document.activeElement;if(e.defaultPrevented||!t?.contains(r)||(e.key===`Escape`&&s&&n&&(e.preventDefault(),n(e)),e.key!==`Tab`||!c))return;let i=[...t.querySelectorAll(ua)].filter(e=>e.tabIndex>=0&&!e.matches(`:disabled`)&&e.getClientRects().length),a=i[0],o=i.at(-1);(!a||(e.shiftKey?r===a||r===t:r===o))&&(e.preventDefault(),(e.shiftKey?o:a)?.focus())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s,c,n,t]);let re=e=>{if(y)return;let t=u?.(e);if(g===void 0&&typeof t?.then==`function`){v(!0);let e=()=>v(!1);Promise.resolve(t).then(e,e)}},ie=i===void 0&&(u||d)?(0,M.jsxs)(M.Fragment,{children:[n&&(0,M.jsx)(b,{type:`tertiary`,onClick:n,...h,children:p||ee(`common.cancel`,null,`取消`)}),(0,M.jsx)(b,{theme:`solid`,type:`primary`,...m,loading:y,disabled:y||m?.disabled,onClick:d?void 0:re,form:d,htmlType:d?`submit`:`button`,children:f||ee(`common.ok`,null,`确定`)})]}):i;return(0,M.jsxs)(Te,{title:e,visible:t,onCancel:n,width:r,footer:ie,mask:c,maskClosable:l&&!y,closeOnEsc:!1,className:`cs-drawer ${o||``}`,"aria-label":typeof e==`string`?e:void 0,..._,children:[(0,M.jsx)(`span`,{hidden:!0,ref:x}),a]})}function fa(e,t=[],{initial:n=null,skip:r=!1}={}){let[i,a]=(0,O.useState)(n),[o,s]=(0,O.useState)(!r),[c,l]=(0,O.useState)(null),u=(0,O.useRef)(0),d=(0,O.useRef)(null),f=(0,O.useRef)(!1),p=(0,O.useCallback)(async(t={})=>{if(r||t.silent&&!t.force&&f.current)return null;d.current?.abort();let n=new AbortController;d.current=n,f.current=!0;let i=++u.current;t.silent||s(!0),l(null);try{let t=await Qe(n.signal,()=>e({signal:n.signal}));return!n.signal.aborted&&i===u.current&&a(t),t}catch(e){return n.signal.aborted||i===u.current&&l(e),null}finally{d.current===n&&(d.current=null,f.current=!1),!n.signal.aborted&&i===u.current&&s(!1)}},t);return(0,O.useEffect)(()=>{if(r)d.current?.abort(),d.current=null,f.current=!1,s(!1);else return p(),()=>{u.current+=1,d.current?.abort(),d.current=null,f.current=!1}},[p,r]),{data:i,setData:a,loading:o,error:c,reload:p}}function pa(e,t=300){let[n,r]=(0,O.useState)(e);return(0,O.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function ma(e,t){let n=(0,O.useRef)(e);(0,O.useEffect)(()=>{n.current=e},[e]),(0,O.useEffect)(()=>{if(!t)return;let e=setInterval(()=>n.current(),t);return()=>clearInterval(e)},[t])}function ha(e,t){let[n,r]=(0,O.useState)(()=>{try{let n=localStorage.getItem(e);return n===null?t:JSON.parse(n)}catch{return t}});return(0,O.useEffect)(()=>{try{localStorage.setItem(e,JSON.stringify(n))}catch{}},[e,n]),[n,r]}var{Text:ga}=c,_a={position:`right`,contentClassName:`cs-nav-flyout`};function va(){let[e,t]=(0,O.useState)(()=>window.matchMedia(`(max-width: 900px)`).matches);return(0,O.useEffect)(()=>{let e=window.matchMedia(`(max-width: 900px)`),n=e=>t(e.matches);return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function ya(e,t,n,r){return e.filter(e=>(!e.anyPermission||r(e.anyPermission))&&(!e.permission||n(e.permission))).map(e=>{let r=e.children?e.children.filter(e=>!e.permission||n(e.permission)):null;return r&&r.length===0?null:{itemKey:e.id,text:t(e.i18n,null,e.fallback),icon:e.icon?(0,M.jsx)(e.icon,{"aria-hidden":`true`}):void 0,items:r?r.map(e=>({itemKey:e.id,text:t(e.i18n,null,e.fallback)})):void 0}}).filter(Boolean)}function ba(){let{preference:e,setPreference:t}=Et(),n=P(),r=[{key:`system`,label:n(`theme.system`,null,`跟随系统`)},{key:`light`,label:n(`theme.light`,null,`浅色`)},{key:`dark`,label:n(`theme.dark`,null,`暗色`)}],i=r.find(t=>t.key===e)||r[0];return(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:r.map(n=>({node:`item`,name:n.label,active:n.key===e,onClick:()=>t(n.key)})),children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:e===`dark`?(0,M.jsx)(ye,{}):(0,M.jsx)(Se,{}),"aria-label":i.label})})}function xa(){let{lang:e,setLanguage:t}=vt();return(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:ct.map(n=>({node:`item`,name:n.label,active:n.id===e,onClick:()=>t(n.id)})),children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:(0,M.jsx)(re,{}),"aria-label":e})})}function Sa({navigate:e}){let t=P(),[n,r]=(0,O.useState)([]),[i,a]=(0,O.useState)(0),[o,s]=(0,O.useState)(!1),[c,l]=(0,O.useState)(!1),u=(0,O.useRef)(null),d=(0,O.useRef)(!1),f=async({force:e=!1}={})=>{if(!e&&d.current)return;u.current?.abort();let t=new AbortController;u.current=t,d.current=!0;try{let e=await j.get(`/notifications/summary`,{limit:80,lang:document.documentElement.lang||`zh-CN`},{signal:t.signal});if(t.signal.aborted)return;let n=Array.isArray(e?.items)?e.items:[];r(n),a(e?.unreadCount??n.filter(e=>!e.read).length)}catch{}finally{u.current===t&&(u.current=null,d.current=!1)}};(0,O.useEffect)(()=>(f({force:!0}),()=>{u.current?.abort(),u.current=null,d.current=!1}),[]),ma(()=>f(),6e4);let p=async()=>{let e=n.filter(e=>!e.read).map(e=>e.id).filter(Boolean);if(e.length&&!c){l(!0);try{await j.post(`/notifications/read`,{eventIds:e}),await f({force:!0})}catch(e){Xi(e)}finally{l(!1)}}},m=t=>{s(!1),t.type===`vulnerability_created`&&t.vulnerabilityId?e(`/vulnerabilities?id=${encodeURIComponent(t.vulnerabilityId)}`):(t.type===`task_completed`||t.type===`long_running_tasks`)&&t.conversationId?e(`/chat?conversation=${encodeURIComponent(t.conversationId)}`):t.type===`task_failed`?e(`/mcp-monitor`):t.type===`hitl_pending`?e(`/hitl`):t.type===`c2_session_online`&&e(`/c2-sessions`)},g=(0,M.jsxs)(`div`,{className:`cs-notification-panel`,children:[(0,M.jsxs)(`div`,{className:`cs-notification-head`,children:[(0,M.jsx)(ga,{strong:!0,children:t(`notifications.title`,null,`通知`)}),(0,M.jsx)(b,{size:`small`,theme:`borderless`,onClick:p,loading:c,children:t(`notifications.markAllRead`,null,`全部标记已读`)})]}),(0,M.jsxs)(`div`,{className:`cs-notification-list`,children:[n.length===0&&(0,M.jsx)(ga,{type:`tertiary`,children:t(`notifications.empty`,null,`暂无新通知`)}),n.map(e=>(0,M.jsxs)(`button`,{type:`button`,className:`cs-notification-item`,onClick:()=>m(e),children:[(0,M.jsx)(`span`,{className:`cs-notification-dot level-${e.level||`p2`}`}),(0,M.jsxs)(`span`,{className:`cs-notification-body`,children:[(0,M.jsx)(`span`,{className:`cs-notification-title`,children:e.title||e.message||e.type}),(0,M.jsxs)(`span`,{className:`cs-notification-meta`,children:[e.ts?Fi(e.ts):``,e.count>1?` · ×${e.count}`:``]})]})]},e.id||`${e.type}-${e.ts}`))]})]});return(0,M.jsx)(h,{content:g,trigger:`click`,position:`bottomRight`,visible:o,onVisibleChange:s,children:(0,M.jsx)(oe,{count:i||null,overflowCount:99,type:`danger`,children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:(0,M.jsx)(y,{}),"aria-label":t(`notifications.title`,null,`通知`)})})})}function Ca({navigate:e}){let{user:t,logout:n,refresh:r}=st(),i=P(),[o,s]=(0,O.useState)(!1),c=(0,O.useId)(),[l,d]=(0,O.useState)(null),[f,p]=(0,O.useState)(!1);return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:[{node:`title`,name:t?.display_name||t?.username||`admin`},{node:`item`,name:i(`auth.changePassword`,null,`修改密码`),icon:(0,M.jsx)(a,{}),onClick:()=>s(!0)},{node:`item`,name:i(`auth.refreshSession`,null,`刷新会话权限`),onClick:()=>r().then(()=>Ji(i(`auth.sessionRefreshed`,null,`会话已刷新`))).catch(e=>Xi(e))},{node:`divider`},{node:`item`,name:i(`auth.logout`,null,`退出登录`),icon:(0,M.jsx)(ne,{}),onClick:async()=>{await n(),e(`/dashboard`)}}],children:(0,M.jsxs)(b,{theme:`borderless`,type:`tertiary`,className:`cs-user-trigger`,"aria-label":i(`auth.userMenu`,null,`用户菜单`),children:[(0,M.jsx)(u,{size:`extra-small`,color:`blue`,children:(t?.display_name||t?.username||`A`).slice(0,1).toUpperCase()}),(0,M.jsx)(`span`,{className:`cs-user-name`,children:t?.display_name||t?.username||`admin`})]})}),(0,M.jsx)(da,{title:i(`auth.changePassword`,null,`修改密码`),visible:o,onCancel:()=>s(!1),formId:c,okText:i(`common.save`,null,`保存`),confirmLoading:f,width:420,children:(0,M.jsxs)(C,{id:c,onSubmit:async e=>{p(!0);try{await j.post(`/auth/change-password`,{oldPassword:e.oldPassword,newPassword:e.newPassword}),Ji(i(`auth.passwordChanged`,null,`密码已更新`)),s(!1),l?.reset()}catch(e){Xi(e,i(`auth.changeFailed`,null,`修改密码失败`))}finally{p(!1)}},getFormApi:d,children:[(0,M.jsx)(C.Input,{field:`oldPassword`,label:i(`auth.currentPassword`,null,`当前密码`),type:`password`,rules:[{required:!0,message:i(`auth.required`,null,`必填`)}]}),(0,M.jsx)(C.Input,{field:`newPassword`,label:i(`auth.newPassword`,null,`新密码`),type:`password`,rules:[{required:!0,min:8,message:i(`auth.passwordMin`,null,`至少 8 位`)}]}),(0,M.jsx)(C.Input,{field:`confirmPassword`,label:i(`auth.confirmPassword`,null,`确认新密码`),type:`password`,rules:[{required:!0,message:i(`auth.required`,null,`必填`)},{validator:(e,t)=>t===l?.getValue(`newPassword`),message:i(`auth.passwordMismatch`,null,`两次输入不一致`)}]})]})})]})}function wa(){let{session:e,hasPermission:t,hasAnyPermission:n}=st(),r=(0,O.useId)(),i=P(),a=Re(),o=D(),s=va(),[c,l]=(0,O.useState)(()=>localStorage.getItem(`csai-nav-collapsed`)===`1`),[u,d]=(0,O.useState)(!1),[p,m]=(0,O.useState)([]),h=a.pathname.replace(/^\//,``).split(`/`)[0]||`dashboard`,g=At(h),_=(0,O.useMemo)(()=>[h],[h]),ee=(0,O.useMemo)(()=>ya(Dt,i,t,n),[i,t,n]);(0,O.useEffect)(()=>{d(!1),g?.parent&&m(e=>e.includes(g.parent)?e:[...e,g.parent])},[a.pathname,g?.parent]),(0,O.useEffect)(()=>{document.title=`${g?i(g.i18n,null,g.fallback):`工作台`} · CyberStrikeAI`},[g,i]);let te=({itemKey:e})=>{let t=a.search,n=[`chat`,`vulnerabilities`,`settings`,`deep-assessments`].includes(e)&&h===e?t:``;o(`/${e}${n}`)},ne=()=>{l(e=>(localStorage.setItem(`csai-nav-collapsed`,e?`0`:`1`),!e))},v=c&&!s,y=!v&&e?.appVersion,x=(0,M.jsxs)(`div`,{className:`cs-sidebar-inner ${v?`is-compact`:``}`,children:[(0,M.jsxs)(b,{className:`cs-brand`,theme:`borderless`,type:`tertiary`,onClick:()=>o(`/dashboard`),"aria-label":`CyberStrikeAI`,"aria-describedby":y?r:void 0,children:[(0,M.jsx)(`img`,{src:`/static/logo.png`,alt:``,className:`cs-brand-logo`}),!v&&(0,M.jsxs)(`span`,{className:`cs-brand-copy`,children:[(0,M.jsxs)(`span`,{className:`cs-brand-name`,children:[`CyberStrike`,(0,M.jsx)(`span`,{children:`AI`})]}),y&&(0,M.jsx)(`span`,{id:r,className:`cs-brand-version`,dir:`ltr`,title:`${i(`header.version`,null,`当前版本`)} ${y}`,children:y})]})]}),(0,M.jsx)(`div`,{className:`cs-nav-scroll`,children:Ot.map(e=>{let t=ee.filter(t=>e.pages.includes(t.itemKey));return t.length?(0,M.jsxs)(`section`,{className:`cs-nav-section`,"aria-label":i(e.i18n,null,e.fallback),children:[!v&&(0,M.jsx)(`div`,{className:`cs-nav-section-label`,children:i(e.i18n,null,e.fallback)}),(0,M.jsx)(he,{className:`cs-nav`,style:{width:`100%`},items:t,selectedKeys:_,onSelect:te,isCollapsed:v,subDropdownProps:_a,openKeys:p,onOpenChange:({openKeys:e})=>m(e)})]},e.id):null})}),!s&&(0,M.jsx)(`div`,{className:`cs-nav-footer`,children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,block:!0,icon:v?(0,M.jsx)(ae,{}):(0,M.jsx)(ce,{}),"aria-label":i(v?`nav.expand`:`nav.collapse`,null,v?`展开菜单`:`收起菜单`),onClick:ne,children:!v&&i(`nav.collapse`,null,`收起菜单`)})})]}),re=g?i(g.i18n,null,g.fallback):`CyberStrikeAI`,ie=g?.parent?At(g.parent):null,S=ie?i(ie.i18n,null,ie.fallback):``;return(0,M.jsxs)(`div`,{className:`cs-shell ${c&&!s?`is-collapsed`:``}`,children:[!s&&(0,M.jsx)(`aside`,{className:`cs-sider`,children:x}),s&&(0,M.jsx)(Te,{visible:u,onCancel:()=>d(!1),placement:`left`,width:264,title:i(`nav.navigation`,null,`导航`),bodyStyle:{padding:0},className:`cs-mobile-nav`,children:x}),(0,M.jsxs)(`div`,{className:`cs-main`,children:[(0,M.jsxs)(`header`,{className:`cs-header`,children:[(0,M.jsxs)(`div`,{className:`cs-header-left`,children:[s&&(0,M.jsx)(b,{theme:`borderless`,icon:(0,M.jsx)(Ae,{}),onClick:()=>d(!0),"aria-label":i(`common.expandPanel`,null,`展开面板`)}),(0,M.jsxs)(Me,{className:`cs-header-crumb`,compact:!1,children:[(0,M.jsx)(Me.Item,{onClick:()=>o(`/dashboard`),children:i(`nav.groupWorkspace`,null,`工作台`)}),S&&(0,M.jsx)(Me.Item,{children:S}),(0,M.jsx)(Me.Item,{children:re})]})]}),(0,M.jsxs)(f,{className:`cs-header-actions`,spacing:4,children:[(0,M.jsx)(Sa,{navigate:o}),(0,M.jsx)(xa,{}),(0,M.jsx)(ba,{}),(0,M.jsx)(Ca,{navigate:o})]})]}),(0,M.jsx)(`main`,{className:`cs-content ${h===`chat`?`cs-content-workspace`:``}`,id:`main-content`,children:(0,M.jsx)(Le,{context:{navigate:o,pageId:h,mobile:s}})})]})]})}var{Title:Ta,Text:Ea,Paragraph:Da}=c;function Oa(){let{login:e}=st(),n=P(),[r,a]=(0,O.useState)(!1),[o,c]=(0,O.useState)(``);async function l(t){a(!0),c(``);try{await e(t.username,t.password)}catch(e){c(rt(e,n(`login.loginFailed`,null,`登录失败`)))}finally{a(!1)}}return(0,M.jsxs)(`main`,{className:`cs-login-page`,children:[(0,M.jsxs)(`section`,{className:`cs-login-story`,children:[(0,M.jsxs)(`div`,{className:`cs-login-brand`,children:[(0,M.jsx)(`img`,{src:`/static/logo.png`,alt:``,className:`cs-login-logo`}),(0,M.jsxs)(`span`,{className:`cs-brand-name`,children:[`CyberStrike`,(0,M.jsx)(`span`,{children:`AI`})]})]}),(0,M.jsxs)(`div`,{className:`cs-login-intro`,children:[(0,M.jsx)(`span`,{className:`cs-login-emblem`,"aria-hidden":`true`,children:(0,M.jsx)(me,{size:`extra-large`})}),(0,M.jsx)(Ta,{heading:1,className:`cs-login-headline`,children:n(`login.headline`,null,`让每一次探索,都有据可循。`)}),(0,M.jsx)(Da,{type:`tertiary`,children:n(`login.intro`,null,`从目标梳理到证据归档,在一个工作台中完成你的安全研究。`)}),(0,M.jsxs)(`div`,{className:`cs-login-features`,children:[(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(m,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.projectTitle`,null,`围绕项目协作`)}),n(`login.projectHint`,null,`跨会话共享目标、上下文与研究进展`)]})]}),(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(de,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.assessmentTitle`,null,`让探索持续推进`)}),n(`login.assessmentHint`,null,`规划、执行与人工复核,始终保持可控`)]})]}),(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(t,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.evidenceTitle`,null,`以证据支撑结论`)}),n(`login.evidenceHint`,null,`保留发现、来源与验收记录`)]})]})]})]}),(0,M.jsx)(Ea,{type:`tertiary`,size:`small`,children:n(`login.platformTagline`,null,`AI 驱动的安全研究工作台`)})]}),(0,M.jsx)(`section`,{className:`cs-login-form-panel`,children:(0,M.jsxs)(s,{className:`cs-login-card`,bordered:!1,children:[(0,M.jsx)(Ta,{heading:2,className:`cs-login-form-heading`,children:n(`login.welcome`,null,`欢迎回来`)}),(0,M.jsx)(Ea,{type:`tertiary`,children:n(`login.welcomeHint`,null,`登录你的安全工作台,继续探索。`)}),(0,M.jsxs)(C,{onSubmit:l,className:`cs-login-form`,children:[o&&(0,M.jsx)(i,{type:`danger`,description:o,closeIcon:null,className:`cs-error-banner`}),(0,M.jsx)(C.Input,{field:`username`,label:n(`login.username`,null,`用户名`),prefix:(0,M.jsx)(ue,{}),placeholder:n(`login.usernamePlaceholder`,null,`请输入用户名`),size:`large`,autoComplete:`username`,rules:[{required:!0,message:n(`login.usernameRequired`,null,`请输入用户名`)}]}),(0,M.jsx)(C.Input,{field:`password`,label:n(`login.password`,null,`密码`),prefix:(0,M.jsx)(ge,{}),type:`password`,size:`large`,autoComplete:`current-password`,placeholder:n(`login.passwordPlaceholder`,null,`请输入密码`),rules:[{required:!0,message:n(`login.passwordRequired`,null,`请输入密码`)}]}),(0,M.jsx)(b,{htmlType:`submit`,theme:`solid`,type:`primary`,size:`large`,block:!0,loading:r,children:n(`login.submit`,null,`登录`)})]}),(0,M.jsx)(Ea,{type:`tertiary`,className:`cs-login-note`,children:n(`login.authorizedOnly`,null,`仅在明确授权的范围内开展安全测试`)})]})})]})}var ka=`modulepreload`,Aa=function(e){return`/static/app/`+e},ja={},Ma=function(e){return e.pathname.endsWith(`.css`)},Na=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},$=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=Aa(t,n);let r=s(t),i=Ma(r);return Na(ja,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:ka,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{let i=a=>{t.removeEventListener(`load`,i),t.removeEventListener(`error`,i),a.type===`error`?n(Error(`Unable to preload CSS for ${r}`)):e(a)};t.addEventListener(`load`,i),t.addEventListener(`error`,i)})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Pa={dashboard:(0,O.lazy)(()=>$(()=>import(`./dashboard-D6tX6vKc.js`),__vite__mapDeps([0,1,2,3,4,5]))),chat:(0,O.lazy)(()=>$(()=>import(`./chat-BUYQ3rrK.js`),__vite__mapDeps([6,1,2,3,4,7,8,9,10,11,12]))),"deep-assessments":(0,O.lazy)(()=>$(()=>import(`./deep-assessments-C0yrTrga.js`),__vite__mapDeps([13,1,2,3,4,10,9,14,15,16]))),hitl:(0,O.lazy)(()=>$(()=>import(`./hitl-Bu3O9ejX.js`),__vite__mapDeps([17,1,2,3,4,18]))),"tool-guard":(0,O.lazy)(()=>$(()=>import(`./tool-guard-Dk4HsC4O.js`),__vite__mapDeps([19,1,2,3,4,20]))),projects:(0,O.lazy)(()=>$(()=>import(`./projects-B6zINg50.js`),__vite__mapDeps([21,1,2,3,4,9,14,15,22,11,23,24]))),"asset-overview":(0,O.lazy)(()=>$(()=>import(`./asset-overview-CJx-FRnL.js`),__vite__mapDeps([25,1,2,3,4,26,23,27]))),"asset-library":(0,O.lazy)(()=>$(()=>import(`./asset-library-Cj9VhYXV.js`),__vite__mapDeps([28,1,2,3,4,11,23,26,22,29]))),"info-collect":(0,O.lazy)(()=>$(()=>import(`./info-collect-ByWtvjrf.js`),__vite__mapDeps([30,1,2,3,4,11,26,23,31]))),vulnerabilities:(0,O.lazy)(()=>$(()=>import(`./vulnerabilities-BDm_fRci.js`),__vite__mapDeps([32,1,2,3,4,7,11,33]))),tasks:(0,O.lazy)(()=>$(()=>import(`./tasks-C-O0ZxhT.js`),__vite__mapDeps([34,1,2,3,4,11,35]))),workflows:(0,O.lazy)(()=>$(()=>import(`./workflows-DDqn8hp2.js`),__vite__mapDeps([36,1,2,3,4,37]))),webshell:(0,O.lazy)(()=>$(()=>import(`./webshell-i057Xx9K.js`),__vite__mapDeps([38,1,2,3,4,11,39]))),"c2-listeners":(0,O.lazy)(()=>$(()=>import(`./c2-listeners-DZ-iU1EK.js`),__vite__mapDeps([40,1,2,3,4,41,42,43,11,44]))),"c2-sessions":(0,O.lazy)(()=>$(()=>import(`./c2-sessions-BzU3PAL8.js`),__vite__mapDeps([45,1,2,3,4,41,42,43,46]))),"c2-tasks":(0,O.lazy)(()=>$(()=>import(`./c2-tasks-DGQ9YyKu.js`),__vite__mapDeps([47,1,2,3,4,41,42,43,48]))),"c2-payloads":(0,O.lazy)(()=>$(()=>import(`./c2-payloads-DHMSGvwF.js`),__vite__mapDeps([49,1,2,3,4,41,42,43,50]))),"c2-events":(0,O.lazy)(()=>$(()=>import(`./c2-events-Be-OFfdA.js`),__vite__mapDeps([51,1,2,3,4,41,42,43,52]))),"c2-profiles":(0,O.lazy)(()=>$(()=>import(`./c2-profiles-BF6FGU2n.js`),__vite__mapDeps([53,1,2,3,4,41,42,54]))),"chat-files":(0,O.lazy)(()=>$(()=>import(`./chat-files-it1nAhw-.js`),__vite__mapDeps([55,1,2,3,4,56]))),"plugin-hub":(0,O.lazy)(()=>$(()=>import(`./plugin-hub-B-d85AF3.js`),__vite__mapDeps([57,1,2,3,4,8,58]))),"mcp-monitor":(0,O.lazy)(()=>$(()=>import(`./mcp-monitor-Du61ugEZ.js`),__vite__mapDeps([59,1,2,3,4,60]))),"mcp-management":(0,O.lazy)(()=>$(()=>import(`./mcp-management-BDsOVfL3.js`),__vite__mapDeps([61,1,2,3,4,62]))),"knowledge-retrieval-logs":(0,O.lazy)(()=>$(()=>import(`./knowledge-retrieval-logs-4_2LIOnY.js`),__vite__mapDeps([63,1,2,3,4]))),"knowledge-management":(0,O.lazy)(()=>$(()=>import(`./knowledge-management--PPUE20m.js`),__vite__mapDeps([64,1,2,3,4]))),"skills-monitor":(0,O.lazy)(()=>$(()=>import(`./skills-monitor-ZMwFvsjS.js`),__vite__mapDeps([65,1,3,2,4]))),"skills-management":(0,O.lazy)(()=>$(()=>import(`./skills-management-Dy4a2scy.js`),__vite__mapDeps([66,1,2,3,4]))),"agents-management":(0,O.lazy)(()=>$(()=>import(`./agents-management-2nvjyStC.js`),__vite__mapDeps([67,1,2,3,4]))),"roles-management":(0,O.lazy)(()=>$(()=>import(`./roles-management-Cc2pBLLE.js`),__vite__mapDeps([68,1,2,3,4,69]))),"platform-rbac":(0,O.lazy)(()=>$(()=>import(`./platform-rbac-CHfcwOkN.js`),__vite__mapDeps([70,1,2,3,4]))),settings:(0,O.lazy)(()=>$(()=>import(`./settings-C_ZMENXl.js`),__vite__mapDeps([71,1,2,3,4,10,72]))),"api-docs":(0,O.lazy)(()=>$(()=>import(`./api-docs-BECDxS6A.js`),__vite__mapDeps([73,1,2,3,4,74])))},{Title:Fa,Text:Ia}=c;function La(){return(0,M.jsx)(`div`,{className:`cs-page-loading`,children:(0,M.jsx)(se,{size:`large`})})}function Ra({code:e,title:t,description:n}){return(0,M.jsxs)(`div`,{className:`cs-page-loading`,style:{flexDirection:`column`,gap:8},children:[(0,M.jsx)(Fa,{heading:2,style:{margin:0},children:e}),(0,M.jsx)(Ia,{strong:!0,children:t}),n&&(0,M.jsx)(Ia,{type:`tertiary`,children:n})]})}function za(){let{pageId:e}=Ue(),{hasPermission:t,hasAnyPermission:n}=st(),r=P(),i=At(e),a=e?Pa[e]:null,o=(0,O.useMemo)(()=>{if(!i)return!0;if(i.anyPermission)return n(i.anyPermission);if(i.permission)return t(i.permission);let e=i.parent?At(i.parent):null;return!e?.anyPermission||n(e.anyPermission)},[i,t,n]);return i?a?o?(0,M.jsx)(O.Suspense,{fallback:(0,M.jsx)(La,{}),children:(0,M.jsx)(a,{})}):(0,M.jsx)(Ra,{code:`403`,title:r(`common.forbidden`,null,`当前账号没有访问该页面的权限`)}):(0,M.jsx)(Ra,{code:`404`,title:i.fallback,description:r(`common.pagePending`,null,`页面尚未注册`)}):(0,M.jsx)(Ra,{code:`404`,title:r(`common.pageNotFound`,null,`页面不存在`)})}function Ba(){let{authenticated:e,checking:t}=st();return t?(0,M.jsx)(La,{}):e?(0,M.jsx)(Be,{children:(0,M.jsxs)(Ve,{element:(0,M.jsx)(wa,{}),children:[(0,M.jsx)(Ve,{path:`/`,element:(0,M.jsx)(Ie,{to:`/dashboard`,replace:!0})}),(0,M.jsx)(Ve,{path:`/system-update`,element:(0,M.jsx)(Ie,{to:`/settings?section=update`,replace:!0})}),(0,M.jsx)(Ve,{path:`/:pageId`,element:(0,M.jsx)(za,{})}),(0,M.jsx)(Ve,{path:`*`,element:(0,M.jsx)(Ie,{to:`/dashboard`,replace:!0})})]})}):(0,M.jsx)(Oa,{})}var Va={"zh-CN":pe,"en-US":Ee,"ru-RU":xe,"ar-SA":w};function Ha(){let{lang:e}=vt();return(0,M.jsx)(n,{locale:Va[e]||pe,direction:e===`ar-SA`?`rtl`:`ltr`,children:(0,M.jsx)(ot,{children:(0,M.jsx)(ze,{children:(0,M.jsx)(Ba,{})})})})}(0,We.createRoot)(document.getElementById(`root`)).render((0,M.jsx)(O.StrictMode,{children:(0,M.jsx)(Tt,{children:(0,M.jsx)(_t,{children:(0,M.jsx)(Ha,{})})})}));export{Ri as A,Ze as B,Ni as C,Bi as D,Fi as E,P as F,A as H,st as I,j as L,Et as M,ct as N,Vi as O,vt as P,tt as R,Yi as S,zi as T,nt as V,$i as _,fa as a,Xi as b,da as c,ca as d,oa as f,ea as g,ra as h,ha as i,Wi as j,Li as k,na as l,Qi as m,pa as n,aa as o,Zi as p,ma as r,ta as s,$ as t,sa as u,ia as v,ji as w,Ji as x,la as y,rt as z};
\ No newline at end of file
diff --git a/web/static/app/assets/info-collect-ByWtvjrf.js b/web/static/app/assets/info-collect-ByWtvjrf.js
new file mode 100644
index 00000000..bbfbfd72
--- /dev/null
+++ b/web/static/app/assets/info-collect-ByWtvjrf.js
@@ -0,0 +1 @@
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,Bt as i,E as a,G as o,I as s,R as c,S as l,U as u,W as d,d as f,lt as ee,p,ut as m,v as h,x as g,y as _}from"./semi-65W_4I1v.js";import{F as v,I as te,L as y,S as b,b as x,c as S,d as C,i as ne,l as w,m as re,p as ie,s as T,u as ae,x as oe}from"./index-_8d9XBPJ.js";import{t as se}from"./project-options-CMQbwv_U.js";import{a as E}from"./AssetBits-DtqSAj0f.js";import{a as D,i as O,o as k}from"./assetTarget-D2PEjBAg.js";var A=e(t(),1),j={fofa:{label:`FOFA`,maxSize:1e4,defaultFields:`host,ip,port,domain,title,protocol,country,region,city,server`,placeholder:`app="Apache" && country="CN"`,fieldPresets:[[`最小字段`,`host,ip,port,domain`],[`Web 常用`,`host,title,ip,port,domain,protocol,server,icp,country,region,city`],[`情报增强`,`host,ip,port,domain,title,protocol,country,region,city,server,asn,org,icp,header,banner`]],queryPresets:[[`Apache + 中国`,`app="Apache" && country="CN"`],[`登录页 + 中国`,`title="登录" && country="CN"`],[`指定域名`,`domain="example.com"`],[`指定 IP`,`ip="1.1.1.1"`]],supportsFull:!0},zoomeye:{label:`ZoomEye`,maxSize:1e4,defaultFields:`ip,port,domain,hostname,title,service,app,country,city`,placeholder:`app="Apache" && country="CN"`,fieldPresets:[[`最小字段`,`ip,port,domain,hostname`],[`Web 常用`,`ip,port,domain,hostname,title,service,app,country,city`],[`情报增强`,`ip,port,domain,hostname,title,service,app,country,city,org,isp,ssl`]],queryPresets:[[`Apache + 中国`,`app="Apache" && country="CN"`],[`SSH 服务`,`service="ssh"`],[`指定域名`,`domain="example.com"`],[`指定 IP`,`ip="1.1.1.1"`]],supportsFull:!1},quake:{label:`Quake`,maxSize:1e4,defaultFields:`ip,port,domain,service.name,service.http.title,location.country_cn,location.province_cn,location.city_cn`,placeholder:`service.name:"http" AND country_cn:"中国"`,fieldPresets:[[`最小字段`,`ip,port,domain`],[`Web 常用`,`ip,port,domain,service.name,service.http.title,location.country_cn,location.city_cn`],[`情报增强`,`ip,port,domain,service.name,service.http.title,service.http.server,location.country_cn,location.province_cn,location.city_cn,asn`]],queryPresets:[[`HTTP + 中国`,`service.name:"http" AND country_cn:"中国"`],[`443 端口`,`port:443`],[`指定域名`,`domain:"example.com"`],[`指定 IP`,`ip:"1.1.1.1"`]],supportsFull:!0},shodan:{label:`Shodan`,maxSize:1e3,defaultFields:`ip_str,port,hostnames,domains,org,isp,location.country_name,location.city,product,transport`,placeholder:`product:nginx country:CN`,fieldPresets:[[`最小字段`,`ip_str,port,hostnames,domains`],[`Web 常用`,`ip_str,port,hostnames,domains,product,org,location.country_name,location.city`],[`情报增强`,`ip_str,port,hostnames,domains,org,isp,asn,location.country_name,location.city,product,transport,ssl.cert.subject.cn`]],queryPresets:[[`Nginx + 中国`,`product:nginx country:CN`],[`SSH 服务`,`port:22`],[`证书域名`,`ssl.cert.subject.cn:example.com`],[`Amazon 443`,`org:"Amazon" port:443`]],supportsFull:!1}},ce=Object.entries(j).map(([e,t])=>({value:e,label:t.label}));function le(e){return j[e]||j.fofa}function ue(e,t=5){let n=[`host`,`ip`,`port`,`domain`,`title`,`protocol`,`server`,`country`,`city`].filter(t=>e.includes(t)),r=e.filter(e=>!n.includes(e));return[...n,...r].slice(0,t)}function de(e,t){if(!e||typeof e!=`object`)return``;let n=t=>{for(let n of t){let t=e[n];if(Array.isArray(t)&&t.length)return String(t[0]);if(t)return String(t)}return``},r=n([`host`,`url`,`hostname`]);if(r)return r;let i=n([`domain`,`domains`,`hostnames`]);if(i)return i;let a=n([`ip`,`ip_str`]),o=e.port;return a?o?`${a}:${o}`:a:``}function fe(e,t){let n=new Set(t.map(Number));return(e||[]).filter((e,t)=>n.has(t))}var M=e(n(),1),{Text:N}=o;function P(e){if(e==null||e===``)return(0,M.jsx)(N,{type:`tertiary`,children:`—`});let t=Array.isArray(e)?e.join(`, `):typeof e==`object`?JSON.stringify(e):String(e);return(0,M.jsx)(E,{text:t,max:44})}function F(e,t){let n=de(e,t);return n?/^https?:\/\//i.test(n)?(0,M.jsx)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,className:`info-collect-target-link`,children:(0,M.jsx)(E,{text:n,max:44})}):(0,M.jsx)(E,{text:n,max:44}):(0,M.jsx)(N,{type:`tertiary`,children:`—`})}function pe({fields:e,results:t,visibleFields:n,selectedKeys:r,onSelectionChange:i,onOpenDetail:a,loading:o}){let s=v(),l=Array.isArray(e)?e:[],u=(Array.isArray(n)?n:[]).filter(e=>l.includes(e)),d=[{title:s(`assets.target`,null,`目标`),dataIndex:`__target`,width:240,render:(e,t)=>F(t,l)},...u.map(e=>({title:e,dataIndex:e,render:(t,n)=>P(n[e])})),{title:s(`common.actions`,null,`操作`),dataIndex:`__actions`,width:90,render:(e,t)=>(0,M.jsx)(c,{theme:`borderless`,size:`small`,onClick:()=>a(t),children:s(`common.view`,null,`详情`)})}],f=(t||[]).map((e,t)=>({...e,__key:String(t),__index:t}));return(0,M.jsx)(T,{columns:d,dataSource:f,rowKey:`__key`,loading:o,pagination:!1,rowSelection:{selectedRowKeys:r,onChange:e=>i(e)},emptyText:s(`infoCollect.noResults`,null,`暂无结果`)})}var{Text:I}=o;function me({visible:e,provider:t,text:n,onClose:i,onApply:a}){let o=v(),[u,f]=(0,A.useState)(!1),[ee,p]=(0,A.useState)(null),[m,h]=(0,A.useState)(null),[g,_]=(0,A.useState)(``),[te,b]=(0,A.useState)(0);(0,A.useEffect)(()=>{if(!e)return;let r=String(n||``).trim();if(!r)return;let i=!1;return f(!0),p(null),h(null),_(``),y.post(`/fofa/parse`,{provider:t,text:r}).then(e=>{i||(h(e||{}),_(String(e?.query||``)))}).catch(e=>{i||p(e)}).finally(()=>{i||f(!1)}),()=>{i=!0}},[e,t,n,te]);let x=e=>{let t=String(g||``).trim();t&&a?.(t,!!e)},C=Array.isArray(m?.warnings)?m.warnings.filter(Boolean):[];return(0,M.jsx)(S,{visible:e,title:o(`infoCollect.parseResultTitle`,null,`语法解析结果`),width:640,onCancel:i,footer:(0,M.jsxs)(s,{children:[(0,M.jsx)(c,{theme:`borderless`,onClick:i,children:o(`common.cancel`,null,`取消`)}),(0,M.jsx)(c,{onClick:()=>x(!1),disabled:!g.trim()||u,children:o(`infoCollect.parseModalApply`,null,`填入查询框`)}),(0,M.jsx)(c,{theme:`solid`,type:`primary`,onClick:()=>x(!0),disabled:!g.trim()||u,children:o(`infoCollect.parseModalApplyRun`,null,`填入并查询`)})]}),children:(0,M.jsxs)(s,{vertical:!0,align:`start`,spacing:10,style:{width:`100%`},children:[(0,M.jsxs)(I,{type:`tertiary`,children:[o(`infoCollect.naturalLanguageLabel`,null,`自然语言`),`:`,String(n||``).trim()||`—`]}),u&&(0,M.jsxs)(s,{children:[(0,M.jsx)(d,{size:`small`}),(0,M.jsx)(I,{type:`tertiary`,children:o(`infoCollect.parsePending`,null,`正在解析,请稍候…`)})]}),(0,M.jsx)(w,{error:ee,onRetry:()=>b(e=>e+1)}),m&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(l,{value:g,rows:3,className:`info-collect-parse-query`,onChange:_}),m.explanation&&(0,M.jsxs)(`div`,{className:`info-collect-parse-block`,children:[(0,M.jsx)(I,{strong:!0,size:`small`,children:o(`infoCollect.explanation`,null,`字段映射说明`)}),(0,M.jsx)(I,{type:`tertiary`,size:`small`,children:m.explanation})]}),C.length>0&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,description:C.join(`;`)})]})]})})}function L(e,t,n){if(e&&!Array.isArray(e)&&typeof e==`object`){let t=e[n];return Array.isArray(t)?t.filter(Boolean).join(`,`):t==null?``:String(t).trim()}let r=Array.isArray(t)?t.indexOf(n):-1;if(r<0||!Array.isArray(e))return``;let i=e[r];return i==null?``:String(i).trim()}function R(e,t,n){for(let r of n){let n=L(e,t,r);if(n)return n}return``}function z(e,t,n=`fofa`){let r=Number.parseInt(L(e,t,`port`),10),i=R(e,t,[`ip`,`ip_str`]),a=O(i)||D(i)?i.toLowerCase():``,o=R(e,t,[`domain`,`hostname`,`hostnames`,`domains`]).split(`,`)[0].replace(/^\[|\]$/g,``).replace(/^"|"$/g,``),s=o&&!O(o)&&!D(o)?k(o):``,c=R(e,t,[`protocol`,`service.name`,`transport`]).toLowerCase();return{host:R(e,t,[`host`,`hostname`]).split(`,`)[0].trim(),ip:a,port:Number.isFinite(r)?r:0,domain:s,protocol:/^[a-z][a-z0-9+.-]{0,31}$/.test(c)?c:``,title:R(e,t,[`title`,`service.http.title`]),server:R(e,t,[`server`,`product`]),country:R(e,t,[`country`,`location.country_cn`,`location.country_name`]),province:R(e,t,[`region`,`province`,`location.province_cn`]),city:R(e,t,[`city`,`location.city_cn`,`location.city`]),source:n||`fofa`,status:`active`}}async function he(e,{fields:t,provider:n,query:r,projectId:i,collectionName:a}){let o=(e||[]).map(e=>z(e,t,n)),s=o.filter(e=>e.host||e.ip||e.domain),c=o.length-s.length;if(!s.length)return{assets:s,invalidCount:c,created:0,updated:0,skipped:0};i&&s.forEach(e=>{e.project_id=i});let l={assets:s,source:n||`fofa`,source_query:r||``};i&&(l.collection={project_id:i,name:String(a||r||`导入资产`).trim()});let u=await y.post(`/assets/import`,l);return{assets:s,invalidCount:c,created:Number(u?.created||0),updated:Number(u?.updated||0),skipped:Number(u?.skipped||0),collection:u?.collection||null}}var{Text:B}=o,ge=`csf.info-collect.form`,V={provider:`fofa`,query:``,size:100,fields:j.fofa.defaultFields,full:!1};function H(){let e=v(),{hasPermission:t}=te(),n=t(`fofa:execute`),o=t(`asset:write`),[d,S]=ne(ge,V),[T,E]=(0,A.useState)(``),[D,O]=(0,A.useState)(!1),[k,j]=(0,A.useState)(null),[N,P]=(0,A.useState)(!1),[F,I]=(0,A.useState)(null),[L,R]=(0,A.useState)([]),[z,H]=(0,A.useState)([]),[U,_e]=(0,A.useState)(null),[ve,ye]=(0,A.useState)(!1),[be,xe]=(0,A.useState)([]),[W,Se]=(0,A.useState)(``),[Ce,we]=(0,A.useState)(``),G=le(d.provider),Te=G.label;(0,A.useEffect)(()=>{if(!t(`project:read`))return;let e=!1;return y.get(`/projects`,{limit:500}).then(t=>{e||xe(Array.isArray(t?.projects)?t.projects:[])}).catch(()=>{e||xe([])}),()=>{e=!0}},[t]),(0,A.useEffect)(()=>{H([]),R([]),j(null),I(null)},[d.provider]);let K=e=>S(t=>({...V,...t,...e})),Ee=e=>{let t=le(e);K({provider:e,fields:t.defaultFields,size:Math.min(Number(d.size||100),t.maxSize),full:!1})},q=Math.min(Math.max(Number(d.size||100),1),G.maxSize),J=async(t=1,r)=>{if(!n){b(e(`infoCollect.permissionDenied`,null,`当前账号没有 fofa:execute 权限`));return}let i=String(r??d.query??``).trim();if(!i)b(e(`infoCollect.enterFofaQuery`,null,`请输入查询语法`));else{P(!0),I(null);try{let e=await y.post(`/fofa/search`,{provider:d.provider,query:i,size:q,page:t,fields:d.fields,full:!!d.full});j(e),R([]),H(ue(e?.fields||[],5))}catch(e){I(e),j(null)}finally{P(!1)}}},De=()=>{S({...V}),j(null),I(null),R([]),H([]),E(``)},Y=Array.isArray(k?.fields)?k.fields:[],X=Array.isArray(k?.results)?k.results:[],Z=Number(k?.total||0),Q=Number(k?.size||q),$=Number(k?.page||1),Oe=async()=>{if(ve)return;if(!o){b(e(`infoCollect.noImportPermission`,null,`当前账号没有 asset:write 权限`));return}if(!L.length){b(e(`infoCollect.selectRowsFirst`,null,`请先选择需要入库的结果`));return}let t=fe(X,L);ye(!0);try{let n=await he(t,{fields:Y,provider:k?.provider||d.provider,query:k?.query||d.query,projectId:W,collectionName:Ce});if(!n.assets.length){b(e(`assets.noValidImportTarget`,null,`所选结果中没有可入库的有效资产目标`));return}let r=n.invalidCount?e(`assets.importDoneWithInvalid`,{created:n.created,updated:n.updated,invalid:n.invalidCount},`已新增 ${n.created} 条,更新 ${n.updated} 条,跳过 ${n.invalidCount} 条无有效目标的结果`):e(`assets.importDone`,{created:n.created,updated:n.updated},`已新增 ${n.created} 条,更新 ${n.updated} 条`),i=n.collection?.name?`,已写入资产库,并记下检索结果「${n.collection.name}」`:``;oe(`${r}${i}`),R([])}catch(t){x(t,e(`assets.importFailed`,null,`资产入库失败`))}finally{ye(!1)}},ke=(e,t)=>{K({query:e}),O(!1),t&&J(1,e)},Ae=(0,A.useMemo)(()=>U?Y.map(e=>{let t=U[e];return{label:e,value:Array.isArray(t)?t.join(`, `):t==null?`—`:String(t)}}):[],[U,Y]),je=k?e(`infoCollect.resultsMeta`,{total:Z,count:X.length,page:$,size:Q},`${Te} · 共 ${Z} 条 · 第 ${$} 页 · 每页 ${Q} 条 · 返回 ${X.length} 条`):``;return(0,M.jsxs)(`div`,{className:`info-collect-page`,children:[(0,M.jsx)(ie,{title:e(`infoCollectPage.title`,null,`信息收集`),description:`使用 FOFA 等空间测绘语法检索资产,并把结果直接入库。`,extra:(0,M.jsxs)(s,{children:[(0,M.jsx)(c,{icon:(0,M.jsx)(m,{}),onClick:()=>{k&&J($)},children:e(`common.refresh`,null,`刷新`)}),(0,M.jsx)(c,{onClick:De,children:e(`infoCollectPage.reset`,null,`重置`)})]})}),!n&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,className:`info-collect-permission`,description:e(`infoCollect.permissionDeniedHint`,null,`当前账号没有 fofa:execute 权限:查询、列字段与入库操作不可用,请联系管理员授权。`)}),(0,M.jsx)(w,{error:F,onRetry:()=>J($)}),(0,M.jsx)(re,{title:e(`infoCollectPage.fofaQuerySyntax`,null,`查询语法`),children:(0,M.jsxs)(`div`,{className:`info-collect-form`,children:[(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(_,{value:d.provider,optionList:ce,onChange:Ee,style:{width:150}}),(0,M.jsxs)(`span`,{className:`info-collect-size`,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:e(`infoCollectPage.returnCount`,null,`返回数量`)}),(0,M.jsx)(g,{value:q,min:1,max:G.maxSize,onChange:e=>K({size:e}),style:{width:120}})]}),(0,M.jsx)(f,{checked:!!d.full,disabled:!G.supportsFull,onChange:e=>K({full:e})}),(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:`full`}),(0,M.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,M.jsx)(ee,{}),onClick:()=>J(1),loading:N,disabled:!n,children:e(`infoCollectPage.confirm`,null,`查询`)}),(0,M.jsx)(c,{disabled:!T.trim()||!n,onClick:()=>O(!0),title:e(`infoCollectPage.parseBtnTitle`,null,`将自然语言解析为查询语法`),children:e(`infoCollectPage.parseBtn`,null,`AI 解析`)})]}),(0,M.jsx)(l,{value:d.query,rows:3,placeholder:`${Te}:${G.placeholder}`,className:`info-collect-query`,onChange:e=>K({query:e})}),(0,M.jsxs)(s,{wrap:!0,className:`info-collect-presets`,children:[(0,M.jsxs)(B,{type:`tertiary`,size:`small`,children:[e(`infoCollectPage.fillExample`,null,`示例`),`:`]}),G.queryPresets.map(([e,t])=>(0,M.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>K({query:t}),children:e},e))]}),(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:e(`infoCollectPage.returnFields`,null,`返回字段`)}),(0,M.jsx)(u,{value:d.fields,onChange:e=>K({fields:e}),className:`info-collect-fields`,style:{width:420}}),G.fieldPresets.map(([e,t])=>(0,M.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>K({fields:t}),children:e},e))]}),(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(_,{value:W,optionList:[{value:``,label:`不归入项目集合`},...se(be,e,{currentId:W})],placeholder:`归入项目`,style:{width:220},onChange:e=>Se(e||``)}),(0,M.jsx)(u,{value:Ce,disabled:!W,placeholder:`集合名称,留空则使用查询语句`,style:{width:280},onChange:we})]}),(0,M.jsx)(l,{value:T,rows:2,placeholder:e(`infoCollectPage.nlPlaceholder`,null,`自然语言:例如 找中国 Apache 站点,标题包含登录`),className:`info-collect-natural`,onChange:E})]})}),(0,M.jsxs)(re,{className:`info-collect-results`,title:e(`infoCollectPage.queryResults`,null,`查询结果`),extra:(0,M.jsxs)(s,{className:`info-collect-results-actions`,wrap:!0,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:je}),(0,M.jsx)(_,{multiple:!0,value:z,optionList:Y.map(e=>({value:e,label:e})),disabled:!Y.length,placeholder:e(`infoCollectPage.showColumns`,null,`显示字段`),maxTagCount:5,style:{minWidth:220},onChange:e=>{let t=(e||[]).slice(0,5);(e||[]).length>5&&b(`最多显示 5 个字段`),H(t)}}),(0,M.jsx)(c,{icon:(0,M.jsx)(i,{}),disabled:!o||!L.length,loading:ve,onClick:Oe,children:e(`assets.importSelected`,null,`入库所选`)})]}),children:[k?.warning&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,className:`info-collect-warning`,description:k.warning}),!k&&!N&&!F?(0,M.jsx)(a,{title:e(`infoCollect.noResults`,null,`暂无结果`),description:n?`输入查询语法后点击“查询”。`:`当前账号缺少 fofa:execute 权限。`,style:{padding:40}}):(0,M.jsx)(pe,{fields:Y,results:X,visibleFields:z,selectedKeys:L,onSelectionChange:R,onOpenDetail:_e,loading:N}),k&&Z>Q&&(0,M.jsx)(`div`,{className:`info-collect-pagination`,children:(0,M.jsx)(h,{total:Z,pageSize:Q,currentPage:$,onPageChange:e=>J(e),showTotal:!0})}),k&&(0,M.jsx)(B,{type:`tertiary`,size:`small`,className:`info-collect-selected-meta`,children:e(`infoCollectPage.selectedRows`,{count:L.length},`已选择 ${L.length} 条`)})]}),(0,M.jsx)(p,{visible:!!U,onCancel:()=>_e(null),title:e(`infoCollect.detailTitle`,null,`结果详情`),width:600,placement:`right`,children:U&&(0,M.jsxs)(`div`,{className:`info-collect-detail`,children:[(0,M.jsx)(B,{strong:!0,children:de(U,Y)||`—`}),(0,M.jsx)(C,{items:Ae,columns:1}),(0,M.jsx)(ae,{value:U,title:`原始 JSON`})]})}),(0,M.jsx)(me,{visible:D,provider:d.provider,text:T,onClose:()=>O(!1),onApply:ke})]})}export{H as default};
\ No newline at end of file
diff --git a/web/static/app/assets/info-collect-tZh4Ex_m.js b/web/static/app/assets/info-collect-tZh4Ex_m.js
deleted file mode 100644
index 7e29033f..00000000
--- a/web/static/app/assets/info-collect-tZh4Ex_m.js
+++ /dev/null
@@ -1 +0,0 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,Bt as i,E as a,G as o,I as s,R as c,S as l,U as u,W as d,d as f,lt as ee,p,ut as m,v as h,x as g,y as _}from"./semi-65W_4I1v.js";import{F as te,I as v,P as y,S as b,b as x,c as S,d as C,i as ne,l as re,m as w,p as ie,s as T,u as ae,x as oe}from"./index-BdnarFZR.js";import{t as se}from"./project-options-CMQbwv_U.js";import{a as E}from"./AssetBits-DtqSAj0f.js";import{a as D,i as O,o as k}from"./assetTarget-D2PEjBAg.js";var A=e(t(),1),j={fofa:{label:`FOFA`,maxSize:1e4,defaultFields:`host,ip,port,domain,title,protocol,country,region,city,server`,placeholder:`app="Apache" && country="CN"`,fieldPresets:[[`最小字段`,`host,ip,port,domain`],[`Web 常用`,`host,title,ip,port,domain,protocol,server,icp,country,region,city`],[`情报增强`,`host,ip,port,domain,title,protocol,country,region,city,server,asn,org,icp,header,banner`]],queryPresets:[[`Apache + 中国`,`app="Apache" && country="CN"`],[`登录页 + 中国`,`title="登录" && country="CN"`],[`指定域名`,`domain="example.com"`],[`指定 IP`,`ip="1.1.1.1"`]],supportsFull:!0},zoomeye:{label:`ZoomEye`,maxSize:1e4,defaultFields:`ip,port,domain,hostname,title,service,app,country,city`,placeholder:`app="Apache" && country="CN"`,fieldPresets:[[`最小字段`,`ip,port,domain,hostname`],[`Web 常用`,`ip,port,domain,hostname,title,service,app,country,city`],[`情报增强`,`ip,port,domain,hostname,title,service,app,country,city,org,isp,ssl`]],queryPresets:[[`Apache + 中国`,`app="Apache" && country="CN"`],[`SSH 服务`,`service="ssh"`],[`指定域名`,`domain="example.com"`],[`指定 IP`,`ip="1.1.1.1"`]],supportsFull:!1},quake:{label:`Quake`,maxSize:1e4,defaultFields:`ip,port,domain,service.name,service.http.title,location.country_cn,location.province_cn,location.city_cn`,placeholder:`service.name:"http" AND country_cn:"中国"`,fieldPresets:[[`最小字段`,`ip,port,domain`],[`Web 常用`,`ip,port,domain,service.name,service.http.title,location.country_cn,location.city_cn`],[`情报增强`,`ip,port,domain,service.name,service.http.title,service.http.server,location.country_cn,location.province_cn,location.city_cn,asn`]],queryPresets:[[`HTTP + 中国`,`service.name:"http" AND country_cn:"中国"`],[`443 端口`,`port:443`],[`指定域名`,`domain:"example.com"`],[`指定 IP`,`ip:"1.1.1.1"`]],supportsFull:!0},shodan:{label:`Shodan`,maxSize:1e3,defaultFields:`ip_str,port,hostnames,domains,org,isp,location.country_name,location.city,product,transport`,placeholder:`product:nginx country:CN`,fieldPresets:[[`最小字段`,`ip_str,port,hostnames,domains`],[`Web 常用`,`ip_str,port,hostnames,domains,product,org,location.country_name,location.city`],[`情报增强`,`ip_str,port,hostnames,domains,org,isp,asn,location.country_name,location.city,product,transport,ssl.cert.subject.cn`]],queryPresets:[[`Nginx + 中国`,`product:nginx country:CN`],[`SSH 服务`,`port:22`],[`证书域名`,`ssl.cert.subject.cn:example.com`],[`Amazon 443`,`org:"Amazon" port:443`]],supportsFull:!1}},ce=Object.entries(j).map(([e,t])=>({value:e,label:t.label}));function le(e){return j[e]||j.fofa}function ue(e,t=5){let n=[`host`,`ip`,`port`,`domain`,`title`,`protocol`,`server`,`country`,`city`].filter(t=>e.includes(t)),r=e.filter(e=>!n.includes(e));return[...n,...r].slice(0,t)}function de(e,t){if(!e||typeof e!=`object`)return``;let n=t=>{for(let n of t){let t=e[n];if(Array.isArray(t)&&t.length)return String(t[0]);if(t)return String(t)}return``},r=n([`host`,`url`,`hostname`]);if(r)return r;let i=n([`domain`,`domains`,`hostnames`]);if(i)return i;let a=n([`ip`,`ip_str`]),o=e.port;return a?o?`${a}:${o}`:a:``}function fe(e,t){let n=new Set(t.map(Number));return(e||[]).filter((e,t)=>n.has(t))}var M=e(n(),1),{Text:N}=o;function P(e){if(e==null||e===``)return(0,M.jsx)(N,{type:`tertiary`,children:`—`});let t=Array.isArray(e)?e.join(`, `):typeof e==`object`?JSON.stringify(e):String(e);return(0,M.jsx)(E,{text:t,max:44})}function F(e,t){let n=de(e,t);return n?/^https?:\/\//i.test(n)?(0,M.jsx)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,className:`info-collect-target-link`,children:(0,M.jsx)(E,{text:n,max:44})}):(0,M.jsx)(E,{text:n,max:44}):(0,M.jsx)(N,{type:`tertiary`,children:`—`})}function pe({fields:e,results:t,visibleFields:n,selectedKeys:r,onSelectionChange:i,onOpenDetail:a,loading:o}){let s=y(),l=Array.isArray(e)?e:[],u=(Array.isArray(n)?n:[]).filter(e=>l.includes(e)),d=[{title:s(`assets.target`,null,`目标`),dataIndex:`__target`,width:240,render:(e,t)=>F(t,l)},...u.map(e=>({title:e,dataIndex:e,render:(t,n)=>P(n[e])})),{title:s(`common.actions`,null,`操作`),dataIndex:`__actions`,width:90,render:(e,t)=>(0,M.jsx)(c,{theme:`borderless`,size:`small`,onClick:()=>a(t),children:s(`common.view`,null,`详情`)})}],f=(t||[]).map((e,t)=>({...e,__key:String(t),__index:t}));return(0,M.jsx)(T,{columns:d,dataSource:f,rowKey:`__key`,loading:o,pagination:!1,rowSelection:{selectedRowKeys:r,onChange:e=>i(e)},emptyText:s(`infoCollect.noResults`,null,`暂无结果`)})}var{Text:I}=o;function me({visible:e,provider:t,text:n,onClose:i,onApply:a}){let o=y(),[u,f]=(0,A.useState)(!1),[ee,p]=(0,A.useState)(null),[m,h]=(0,A.useState)(null),[g,_]=(0,A.useState)(``),[te,b]=(0,A.useState)(0);(0,A.useEffect)(()=>{if(!e)return;let r=String(n||``).trim();if(!r)return;let i=!1;return f(!0),p(null),h(null),_(``),v.post(`/fofa/parse`,{provider:t,text:r}).then(e=>{i||(h(e||{}),_(String(e?.query||``)))}).catch(e=>{i||p(e)}).finally(()=>{i||f(!1)}),()=>{i=!0}},[e,t,n,te]);let x=e=>{let t=String(g||``).trim();t&&a?.(t,!!e)},C=Array.isArray(m?.warnings)?m.warnings.filter(Boolean):[];return(0,M.jsx)(S,{visible:e,title:o(`infoCollect.parseResultTitle`,null,`语法解析结果`),width:640,onCancel:i,footer:(0,M.jsxs)(s,{children:[(0,M.jsx)(c,{theme:`borderless`,onClick:i,children:o(`common.cancel`,null,`取消`)}),(0,M.jsx)(c,{onClick:()=>x(!1),disabled:!g.trim()||u,children:o(`infoCollect.parseModalApply`,null,`填入查询框`)}),(0,M.jsx)(c,{theme:`solid`,type:`primary`,onClick:()=>x(!0),disabled:!g.trim()||u,children:o(`infoCollect.parseModalApplyRun`,null,`填入并查询`)})]}),children:(0,M.jsxs)(s,{vertical:!0,align:`start`,spacing:10,style:{width:`100%`},children:[(0,M.jsxs)(I,{type:`tertiary`,children:[o(`infoCollect.naturalLanguageLabel`,null,`自然语言`),`:`,String(n||``).trim()||`—`]}),u&&(0,M.jsxs)(s,{children:[(0,M.jsx)(d,{size:`small`}),(0,M.jsx)(I,{type:`tertiary`,children:o(`infoCollect.parsePending`,null,`正在解析,请稍候…`)})]}),(0,M.jsx)(re,{error:ee,onRetry:()=>b(e=>e+1)}),m&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(l,{value:g,rows:3,className:`info-collect-parse-query`,onChange:_}),m.explanation&&(0,M.jsxs)(`div`,{className:`info-collect-parse-block`,children:[(0,M.jsx)(I,{strong:!0,size:`small`,children:o(`infoCollect.explanation`,null,`字段映射说明`)}),(0,M.jsx)(I,{type:`tertiary`,size:`small`,children:m.explanation})]}),C.length>0&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,description:C.join(`;`)})]})]})})}function L(e,t,n){if(e&&!Array.isArray(e)&&typeof e==`object`){let t=e[n];return Array.isArray(t)?t.filter(Boolean).join(`,`):t==null?``:String(t).trim()}let r=Array.isArray(t)?t.indexOf(n):-1;if(r<0||!Array.isArray(e))return``;let i=e[r];return i==null?``:String(i).trim()}function R(e,t,n){for(let r of n){let n=L(e,t,r);if(n)return n}return``}function z(e,t,n=`fofa`){let r=Number.parseInt(L(e,t,`port`),10),i=R(e,t,[`ip`,`ip_str`]),a=O(i)||D(i)?i.toLowerCase():``,o=R(e,t,[`domain`,`hostname`,`hostnames`,`domains`]).split(`,`)[0].replace(/^\[|\]$/g,``).replace(/^"|"$/g,``),s=o&&!O(o)&&!D(o)?k(o):``,c=R(e,t,[`protocol`,`service.name`,`transport`]).toLowerCase();return{host:R(e,t,[`host`,`hostname`]).split(`,`)[0].trim(),ip:a,port:Number.isFinite(r)?r:0,domain:s,protocol:/^[a-z][a-z0-9+.-]{0,31}$/.test(c)?c:``,title:R(e,t,[`title`,`service.http.title`]),server:R(e,t,[`server`,`product`]),country:R(e,t,[`country`,`location.country_cn`,`location.country_name`]),province:R(e,t,[`region`,`province`,`location.province_cn`]),city:R(e,t,[`city`,`location.city_cn`,`location.city`]),source:n||`fofa`,status:`active`}}async function he(e,{fields:t,provider:n,query:r,projectId:i,collectionName:a}){let o=(e||[]).map(e=>z(e,t,n)),s=o.filter(e=>e.host||e.ip||e.domain),c=o.length-s.length;if(!s.length)return{assets:s,invalidCount:c,created:0,updated:0,skipped:0};i&&s.forEach(e=>{e.project_id=i});let l={assets:s,source:n||`fofa`,source_query:r||``};i&&(l.collection={project_id:i,name:String(a||r||`导入资产`).trim()});let u=await v.post(`/assets/import`,l);return{assets:s,invalidCount:c,created:Number(u?.created||0),updated:Number(u?.updated||0),skipped:Number(u?.skipped||0),collection:u?.collection||null}}var{Text:B}=o,ge=`csf.info-collect.form`,V={provider:`fofa`,query:``,size:100,fields:j.fofa.defaultFields,full:!1};function H(){let e=y(),{hasPermission:t}=te(),n=t(`fofa:execute`),o=t(`asset:write`),[d,S]=ne(ge,V),[T,E]=(0,A.useState)(``),[D,O]=(0,A.useState)(!1),[k,j]=(0,A.useState)(null),[N,P]=(0,A.useState)(!1),[F,I]=(0,A.useState)(null),[L,R]=(0,A.useState)([]),[z,H]=(0,A.useState)([]),[U,_e]=(0,A.useState)(null),[ve,ye]=(0,A.useState)(!1),[be,xe]=(0,A.useState)([]),[W,Se]=(0,A.useState)(``),[Ce,we]=(0,A.useState)(``),G=le(d.provider),Te=G.label;(0,A.useEffect)(()=>{if(!t(`project:read`))return;let e=!1;return v.get(`/projects`,{limit:500}).then(t=>{e||xe(Array.isArray(t?.projects)?t.projects:[])}).catch(()=>{e||xe([])}),()=>{e=!0}},[t]),(0,A.useEffect)(()=>{H([]),R([]),j(null),I(null)},[d.provider]);let K=e=>S(t=>({...V,...t,...e})),Ee=e=>{let t=le(e);K({provider:e,fields:t.defaultFields,size:Math.min(Number(d.size||100),t.maxSize),full:!1})},q=Math.min(Math.max(Number(d.size||100),1),G.maxSize),J=async(t=1,r)=>{if(!n){b(e(`infoCollect.permissionDenied`,null,`当前账号没有 fofa:execute 权限`));return}let i=String(r??d.query??``).trim();if(!i)b(e(`infoCollect.enterFofaQuery`,null,`请输入查询语法`));else{P(!0),I(null);try{let e=await v.post(`/fofa/search`,{provider:d.provider,query:i,size:q,page:t,fields:d.fields,full:!!d.full});j(e),R([]),H(ue(e?.fields||[],5))}catch(e){I(e),j(null)}finally{P(!1)}}},De=()=>{S({...V}),j(null),I(null),R([]),H([]),E(``)},Y=Array.isArray(k?.fields)?k.fields:[],X=Array.isArray(k?.results)?k.results:[],Z=Number(k?.total||0),Q=Number(k?.size||q),$=Number(k?.page||1),Oe=async()=>{if(ve)return;if(!o){b(e(`infoCollect.noImportPermission`,null,`当前账号没有 asset:write 权限`));return}if(!L.length){b(e(`infoCollect.selectRowsFirst`,null,`请先选择需要入库的结果`));return}let t=fe(X,L);ye(!0);try{let n=await he(t,{fields:Y,provider:k?.provider||d.provider,query:k?.query||d.query,projectId:W,collectionName:Ce});if(!n.assets.length){b(e(`assets.noValidImportTarget`,null,`所选结果中没有可入库的有效资产目标`));return}let r=n.invalidCount?e(`assets.importDoneWithInvalid`,{created:n.created,updated:n.updated,invalid:n.invalidCount},`已新增 ${n.created} 条,更新 ${n.updated} 条,跳过 ${n.invalidCount} 条无有效目标的结果`):e(`assets.importDone`,{created:n.created,updated:n.updated},`已新增 ${n.created} 条,更新 ${n.updated} 条`),i=n.collection?.name?`,已写入资产库,并记下检索结果「${n.collection.name}」`:``;oe(`${r}${i}`),R([])}catch(t){x(t,e(`assets.importFailed`,null,`资产入库失败`))}finally{ye(!1)}},ke=(e,t)=>{K({query:e}),O(!1),t&&J(1,e)},Ae=(0,A.useMemo)(()=>U?Y.map(e=>{let t=U[e];return{label:e,value:Array.isArray(t)?t.join(`, `):t==null?`—`:String(t)}}):[],[U,Y]),je=k?e(`infoCollect.resultsMeta`,{total:Z,count:X.length,page:$,size:Q},`${Te} · 共 ${Z} 条 · 第 ${$} 页 · 每页 ${Q} 条 · 返回 ${X.length} 条`):``;return(0,M.jsxs)(`div`,{className:`info-collect-page`,children:[(0,M.jsx)(ie,{title:e(`infoCollectPage.title`,null,`信息收集`),description:`使用 FOFA 等空间测绘语法检索资产,并把结果直接入库。`,extra:(0,M.jsxs)(s,{children:[(0,M.jsx)(c,{icon:(0,M.jsx)(m,{}),onClick:()=>{k&&J($)},children:e(`common.refresh`,null,`刷新`)}),(0,M.jsx)(c,{onClick:De,children:e(`infoCollectPage.reset`,null,`重置`)})]})}),!n&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,className:`info-collect-permission`,description:e(`infoCollect.permissionDeniedHint`,null,`当前账号没有 fofa:execute 权限:查询、列字段与入库操作不可用,请联系管理员授权。`)}),(0,M.jsx)(re,{error:F,onRetry:()=>J($)}),(0,M.jsx)(w,{title:e(`infoCollectPage.fofaQuerySyntax`,null,`查询语法`),children:(0,M.jsxs)(`div`,{className:`info-collect-form`,children:[(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(_,{value:d.provider,optionList:ce,onChange:Ee,style:{width:150}}),(0,M.jsxs)(`span`,{className:`info-collect-size`,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:e(`infoCollectPage.returnCount`,null,`返回数量`)}),(0,M.jsx)(g,{value:q,min:1,max:G.maxSize,onChange:e=>K({size:e}),style:{width:120}})]}),(0,M.jsx)(f,{checked:!!d.full,disabled:!G.supportsFull,onChange:e=>K({full:e})}),(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:`full`}),(0,M.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,M.jsx)(ee,{}),onClick:()=>J(1),loading:N,disabled:!n,children:e(`infoCollectPage.confirm`,null,`查询`)}),(0,M.jsx)(c,{disabled:!T.trim()||!n,onClick:()=>O(!0),title:e(`infoCollectPage.parseBtnTitle`,null,`将自然语言解析为查询语法`),children:e(`infoCollectPage.parseBtn`,null,`AI 解析`)})]}),(0,M.jsx)(l,{value:d.query,rows:3,placeholder:`${Te}:${G.placeholder}`,className:`info-collect-query`,onChange:e=>K({query:e})}),(0,M.jsxs)(s,{wrap:!0,className:`info-collect-presets`,children:[(0,M.jsxs)(B,{type:`tertiary`,size:`small`,children:[e(`infoCollectPage.fillExample`,null,`示例`),`:`]}),G.queryPresets.map(([e,t])=>(0,M.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>K({query:t}),children:e},e))]}),(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:e(`infoCollectPage.returnFields`,null,`返回字段`)}),(0,M.jsx)(u,{value:d.fields,onChange:e=>K({fields:e}),className:`info-collect-fields`,style:{width:420}}),G.fieldPresets.map(([e,t])=>(0,M.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>K({fields:t}),children:e},e))]}),(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(_,{value:W,optionList:[{value:``,label:`不归入项目集合`},...se(be,e,{currentId:W})],placeholder:`归入项目`,style:{width:220},onChange:e=>Se(e||``)}),(0,M.jsx)(u,{value:Ce,disabled:!W,placeholder:`集合名称,留空则使用查询语句`,style:{width:280},onChange:we})]}),(0,M.jsx)(l,{value:T,rows:2,placeholder:e(`infoCollectPage.nlPlaceholder`,null,`自然语言:例如 找中国 Apache 站点,标题包含登录`),className:`info-collect-natural`,onChange:E})]})}),(0,M.jsxs)(w,{className:`info-collect-results`,title:e(`infoCollectPage.queryResults`,null,`查询结果`),extra:(0,M.jsxs)(s,{className:`info-collect-results-actions`,wrap:!0,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:je}),(0,M.jsx)(_,{multiple:!0,value:z,optionList:Y.map(e=>({value:e,label:e})),disabled:!Y.length,placeholder:e(`infoCollectPage.showColumns`,null,`显示字段`),maxTagCount:5,style:{minWidth:220},onChange:e=>{let t=(e||[]).slice(0,5);(e||[]).length>5&&b(`最多显示 5 个字段`),H(t)}}),(0,M.jsx)(c,{icon:(0,M.jsx)(i,{}),disabled:!o||!L.length,loading:ve,onClick:Oe,children:e(`assets.importSelected`,null,`入库所选`)})]}),children:[k?.warning&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,className:`info-collect-warning`,description:k.warning}),!k&&!N&&!F?(0,M.jsx)(a,{title:e(`infoCollect.noResults`,null,`暂无结果`),description:n?`输入查询语法后点击“查询”。`:`当前账号缺少 fofa:execute 权限。`,style:{padding:40}}):(0,M.jsx)(pe,{fields:Y,results:X,visibleFields:z,selectedKeys:L,onSelectionChange:R,onOpenDetail:_e,loading:N}),k&&Z>Q&&(0,M.jsx)(`div`,{className:`info-collect-pagination`,children:(0,M.jsx)(h,{total:Z,pageSize:Q,currentPage:$,onPageChange:e=>J(e),showTotal:!0})}),k&&(0,M.jsx)(B,{type:`tertiary`,size:`small`,className:`info-collect-selected-meta`,children:e(`infoCollectPage.selectedRows`,{count:L.length},`已选择 ${L.length} 条`)})]}),(0,M.jsx)(p,{visible:!!U,onCancel:()=>_e(null),title:e(`infoCollect.detailTitle`,null,`结果详情`),width:600,placement:`right`,children:U&&(0,M.jsxs)(`div`,{className:`info-collect-detail`,children:[(0,M.jsx)(B,{strong:!0,children:de(U,Y)||`—`}),(0,M.jsx)(C,{items:Ae,columns:1}),(0,M.jsx)(ae,{value:U,title:`原始 JSON`})]})}),(0,M.jsx)(me,{visible:D,provider:d.provider,text:T,onClose:()=>O(!1),onApply:ke})]})}export{H as default};
\ No newline at end of file
diff --git a/web/static/app/assets/knowledge-management--PPUE20m.js b/web/static/app/assets/knowledge-management--PPUE20m.js
new file mode 100644
index 00000000..8203c87c
--- /dev/null
+++ b/web/static/app/assets/knowledge-management--PPUE20m.js
@@ -0,0 +1 @@
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r}from"./react-QV7DAAIx.js";import{B as ee,G as i,I as a,Lt as o,N as s,Pt as te,R as c,U as ne,ft as re,i as l,lt as u,ot as d,ut as f,y as p}from"./semi-65W_4I1v.js";import{D as m,E as h,F as ie,I as ae,L as g,_,a as v,b as y,c as b,d as x,f as S,l as oe,m as se,p as C,s as w,x as T,y as ce}from"./index-_8d9XBPJ.js";var E=e(t(),1),D=e(r(),1),{Text:O}=i;function k(){let e=ie(),t=n(),{hasPermission:r}=ae(),i=r(`knowledge:write`),k=r(`config:read`),[A,le]=(0,E.useState)(``),[j,M]=(0,E.useState)(``),[N,P]=(0,E.useState)(1),[F,I]=(0,E.useState)(20),[L,R]=(0,E.useState)(null),[z,B]=(0,E.useState)(null),[V,H]=(0,E.useState)(!1),[U,W]=(0,E.useState)(!1),[G,K]=(0,E.useState)(null),q=v(()=>g.get(`/knowledge/items`,{category:A||void 0,search:j||void 0,limit:F,offset:(N-1)*F}),[A,j,N,F]),J=v(()=>g.get(`/knowledge/stats`),[]),Y=v(()=>g.get(`/knowledge/categories`),[]),X=v(()=>g.get(`/knowledge/index-status`),[]),ue=Array.isArray(q.data?.items)?q.data.items:[],de=Number(q.data?.total||0),Z=q.data?.enabled===!1||X.data?.enabled===!1,fe=(Array.isArray(Y.data?.categories)?Y.data.categories:[]).map(e=>typeof e==`string`?{value:e,label:e}:{value:e.name||e.category,label:e.name||e.category}),Q=(0,E.useCallback)(()=>{q.reload(),J.reload(),X.reload()},[q,J,X]),pe=async()=>{let e=await L.form.validate();H(!0);try{let t={category:e.category.trim(),title:e.title.trim(),content:e.content};L.item?.id?await g.put(`/knowledge/items/${encodeURIComponent(L.item.id)}`,t):await g.post(`/knowledge/items`,t),T(L.item?.id?`知识项已更新`:`知识项已创建`),R(null),Q()}catch(e){y(e,`保存失败`)}finally{H(!1)}},me=e=>ce({title:`删除知识项「${e.title}」?`,content:`删除后需要重新索引,且不可恢复。`,onOk:async()=>{await g.del(`/knowledge/items/${encodeURIComponent(e.id)}`),T(`已删除`),Q()}}),$=async e=>{try{await g.post(`/knowledge/index`,e?{full:!0}:{}),T(`索引任务已提交`),X.reload()}catch(e){y(e,`构建索引失败`)}},he=async e=>{try{K(await g.post(`/knowledge/search`,{query:e,topK:5}))}catch(e){y(e,`检索失败`)}};return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(C,{title:e(`knowledge.title`,null,`知识管理`),description:`知识条目会参与智能体检索;修改后需要重建索引才能生效。`,extra:(0,D.jsxs)(a,{wrap:!0,children:[k&&(0,D.jsx)(c,{icon:(0,D.jsx)(d,{}),onClick:()=>t(`/settings?section=knowledge`),children:`知识库设置`}),(0,D.jsx)(c,{icon:(0,D.jsx)(f,{}),onClick:Q,children:`刷新`}),i&&(0,D.jsx)(c,{disabled:Z,onClick:()=>$(!1),children:`构建索引`}),i&&(0,D.jsx)(c,{disabled:Z,onClick:()=>$(!0),children:`全量重建`}),i&&(0,D.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,D.jsx)(re,{}),disabled:Z,onClick:()=>R({item:null,form:{}}),children:`新增知识`})]})}),Z&&(0,D.jsx)(ee,{type:`warning`,bordered:!0,closeIcon:null,style:{marginBottom:16},description:(0,D.jsxs)(a,{wrap:!0,children:[(0,D.jsx)(`span`,{children:q.data?.message||X.data?.message||`知识库功能未启用,请先在系统设置中开启知识检索并配置嵌入模型。`}),k&&(0,D.jsx)(c,{size:`small`,theme:`solid`,type:`primary`,onClick:()=>t(`/settings?section=knowledge`),children:`前往启用知识库`})]})}),(0,D.jsx)(_,{columns:4,metrics:[{id:`items`,label:`知识条目`,value:m(J.data?.total_items||0),loading:J.loading},{id:`categories`,label:`分类数`,value:m(J.data?.total_categories||0),loading:J.loading},{id:`indexed`,label:`已索引`,value:m(X.data?.indexed_items??X.data?.total_indexed??0),loading:X.loading},{id:`pending`,label:`待索引`,value:m(X.data?.pending_items??0),loading:X.loading}]}),(0,D.jsxs)(se,{title:`知识条目`,children:[(0,D.jsx)(oe,{error:q.error,onRetry:()=>q.reload()}),(0,D.jsx)(w,{columns:[{title:`标题`,dataIndex:`title`,render:(e,t)=>(0,D.jsx)(O,{strong:!0,children:e||t.filePath})},{title:`分类`,dataIndex:`category`,width:160,render:e=>e?(0,D.jsx)(s,{size:`small`,children:e}):`—`},{title:`更新时间`,dataIndex:`updatedAt`,width:180,render:e=>h(e)},{title:`操作`,width:150,render:(e,t)=>(0,D.jsxs)(a,{children:[(0,D.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>B(t),children:`查看`}),i&&(0,D.jsx)(c,{size:`small`,theme:`borderless`,icon:(0,D.jsx)(te,{}),onClick:()=>R({item:t,form:{}})}),i&&(0,D.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,D.jsx)(o,{}),onClick:()=>me(t)})]})}],dataSource:ue,rowKey:`id`,loading:q.loading,pagination:{currentPage:N,pageSize:F,total:de,onPageChange:P,onPageSizeChange:e=>{I(e),P(1)}},toolbar:(0,D.jsxs)(a,{children:[(0,D.jsx)(ne,{prefix:(0,D.jsx)(u,{}),value:j,onChange:e=>{M(e),P(1)},placeholder:`搜索标题或内容`,style:{width:220}}),(0,D.jsx)(p,{value:A,onChange:e=>{le(e||``),P(1)},placeholder:`全部分类`,style:{width:180},showClear:!0,optionList:fe}),(0,D.jsx)(c,{onClick:()=>W(!0),children:`检索测试`})]})})]}),(0,D.jsx)(b,{title:L?.item?`编辑知识项`:`新增知识项`,visible:!!L,onCancel:()=>R(null),onOk:pe,confirmLoading:V,width:760,children:(0,D.jsxs)(l,{getFormApi:e=>R(t=>t&&{...t,form:e}),initValues:L?.item?{category:L.item.category,title:L.item.title,content:L.item.content}:{},children:[(0,D.jsx)(l.Input,{field:`category`,label:`分类`,rules:[{required:!0,message:`请输入分类`}],placeholder:`例如 sql_injection`}),(0,D.jsx)(l.Input,{field:`title`,label:`标题`,rules:[{required:!0,message:`请输入标题`}]}),(0,D.jsx)(l.TextArea,{field:`content`,label:`内容(Markdown)`,rules:[{required:!0,message:`请输入内容`}],autosize:{minRows:10,maxRows:24}})]})},L?.item?.id||`new`),(0,D.jsx)(b,{title:z?.title||`知识项`,visible:!!z,onCancel:()=>B(null),width:640,children:z&&(0,D.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,D.jsx)(x,{items:[{label:`分类`,value:z.category},{label:`文件路径`,value:z.filePath},{label:`创建时间`,value:h(z.createdAt)},{label:`更新时间`,value:h(z.updatedAt)}]}),(0,D.jsx)(S,{content:z.content||`(内容需要打开原文查看)`})]})}),(0,D.jsxs)(b,{title:`知识检索测试`,visible:U,onCancel:()=>{W(!1),K(null)},footer:null,width:720,children:[(0,D.jsxs)(l,{onSubmit:({query:e})=>he(e),children:[(0,D.jsx)(l.Input,{field:`query`,label:`检索语句`,rules:[{required:!0,message:`请输入检索语句`}]}),(0,D.jsx)(c,{htmlType:`submit`,theme:`solid`,type:`primary`,children:`检索`})]}),G&&(0,D.jsxs)(`div`,{style:{marginTop:16,display:`flex`,flexDirection:`column`,gap:8},children:[(G.results||[]).map((e,t)=>(0,D.jsxs)(`div`,{style:{border:`1px solid var(--semi-color-border)`,borderRadius:8,padding:12},children:[(0,D.jsxs)(a,{children:[(0,D.jsxs)(s,{color:`blue`,children:[`#`,t+1]}),(0,D.jsx)(O,{strong:!0,children:e.item?.title||e.title||e.id}),e.score!==void 0&&(0,D.jsxs)(O,{type:`tertiary`,children:[`相似度 `,Number(e.score).toFixed(3)]})]}),(0,D.jsx)(`div`,{style:{marginTop:8},children:(0,D.jsx)(S,{content:String(e.content||e.item?.content||``).slice(0,600)})})]},e.id||t)),(G.results||[]).length===0&&(0,D.jsx)(O,{type:`tertiary`,children:`没有命中结果`})]})]})]})}export{k as default};
\ No newline at end of file
diff --git a/web/static/app/assets/knowledge-management-CEHirgdD.js b/web/static/app/assets/knowledge-management-CEHirgdD.js
deleted file mode 100644
index c67492ad..00000000
--- a/web/static/app/assets/knowledge-management-CEHirgdD.js
+++ /dev/null
@@ -1 +0,0 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r}from"./react-QV7DAAIx.js";import{B as ee,G as i,I as a,Lt as te,N as o,Pt as ne,R as s,U as re,ft as ie,i as c,lt as l,ot as u,ut as d,y as f}from"./semi-65W_4I1v.js";import{D as p,E as m,F as ae,I as h,P as g,_,a as v,b as y,c as b,d as x,f as S,l as oe,m as se,p as C,s as w,x as T,y as ce}from"./index-BdnarFZR.js";var E=e(t(),1),D=e(r(),1),{Text:O}=i;function k(){let e=g(),t=n(),{hasPermission:r}=ae(),i=r(`knowledge:write`),k=r(`config:read`),[A,le]=(0,E.useState)(``),[j,M]=(0,E.useState)(``),[N,P]=(0,E.useState)(1),[F,I]=(0,E.useState)(20),[L,R]=(0,E.useState)(null),[z,B]=(0,E.useState)(null),[V,H]=(0,E.useState)(!1),[U,W]=(0,E.useState)(!1),[G,K]=(0,E.useState)(null),q=v(()=>h.get(`/knowledge/items`,{category:A||void 0,search:j||void 0,limit:F,offset:(N-1)*F}),[A,j,N,F]),J=v(()=>h.get(`/knowledge/stats`),[]),Y=v(()=>h.get(`/knowledge/categories`),[]),X=v(()=>h.get(`/knowledge/index-status`),[]),ue=Array.isArray(q.data?.items)?q.data.items:[],de=Number(q.data?.total||0),Z=q.data?.enabled===!1||X.data?.enabled===!1,fe=(Array.isArray(Y.data?.categories)?Y.data.categories:[]).map(e=>typeof e==`string`?{value:e,label:e}:{value:e.name||e.category,label:e.name||e.category}),Q=(0,E.useCallback)(()=>{q.reload(),J.reload(),X.reload()},[q,J,X]),pe=async()=>{let e=await L.form.validate();H(!0);try{let t={category:e.category.trim(),title:e.title.trim(),content:e.content};L.item?.id?await h.put(`/knowledge/items/${encodeURIComponent(L.item.id)}`,t):await h.post(`/knowledge/items`,t),T(L.item?.id?`知识项已更新`:`知识项已创建`),R(null),Q()}catch(e){y(e,`保存失败`)}finally{H(!1)}},me=e=>ce({title:`删除知识项「${e.title}」?`,content:`删除后需要重新索引,且不可恢复。`,onOk:async()=>{await h.del(`/knowledge/items/${encodeURIComponent(e.id)}`),T(`已删除`),Q()}}),$=async e=>{try{await h.post(`/knowledge/index`,e?{full:!0}:{}),T(`索引任务已提交`),X.reload()}catch(e){y(e,`构建索引失败`)}},he=async e=>{try{K(await h.post(`/knowledge/search`,{query:e,topK:5}))}catch(e){y(e,`检索失败`)}};return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(C,{title:e(`knowledge.title`,null,`知识管理`),description:`知识条目会参与智能体检索;修改后需要重建索引才能生效。`,extra:(0,D.jsxs)(a,{wrap:!0,children:[k&&(0,D.jsx)(s,{icon:(0,D.jsx)(u,{}),onClick:()=>t(`/settings?section=knowledge`),children:`知识库设置`}),(0,D.jsx)(s,{icon:(0,D.jsx)(d,{}),onClick:Q,children:`刷新`}),i&&(0,D.jsx)(s,{disabled:Z,onClick:()=>$(!1),children:`构建索引`}),i&&(0,D.jsx)(s,{disabled:Z,onClick:()=>$(!0),children:`全量重建`}),i&&(0,D.jsx)(s,{theme:`solid`,type:`primary`,icon:(0,D.jsx)(ie,{}),disabled:Z,onClick:()=>R({item:null,form:{}}),children:`新增知识`})]})}),Z&&(0,D.jsx)(ee,{type:`warning`,bordered:!0,closeIcon:null,style:{marginBottom:16},description:(0,D.jsxs)(a,{wrap:!0,children:[(0,D.jsx)(`span`,{children:q.data?.message||X.data?.message||`知识库功能未启用,请先在系统设置中开启知识检索并配置嵌入模型。`}),k&&(0,D.jsx)(s,{size:`small`,theme:`solid`,type:`primary`,onClick:()=>t(`/settings?section=knowledge`),children:`前往启用知识库`})]})}),(0,D.jsx)(_,{columns:4,metrics:[{id:`items`,label:`知识条目`,value:p(J.data?.total_items||0),loading:J.loading},{id:`categories`,label:`分类数`,value:p(J.data?.total_categories||0),loading:J.loading},{id:`indexed`,label:`已索引`,value:p(X.data?.indexed_items??X.data?.total_indexed??0),loading:X.loading},{id:`pending`,label:`待索引`,value:p(X.data?.pending_items??0),loading:X.loading}]}),(0,D.jsxs)(se,{title:`知识条目`,children:[(0,D.jsx)(oe,{error:q.error,onRetry:()=>q.reload()}),(0,D.jsx)(w,{columns:[{title:`标题`,dataIndex:`title`,render:(e,t)=>(0,D.jsx)(O,{strong:!0,children:e||t.filePath})},{title:`分类`,dataIndex:`category`,width:160,render:e=>e?(0,D.jsx)(o,{size:`small`,children:e}):`—`},{title:`更新时间`,dataIndex:`updatedAt`,width:180,render:e=>m(e)},{title:`操作`,width:150,render:(e,t)=>(0,D.jsxs)(a,{children:[(0,D.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>B(t),children:`查看`}),i&&(0,D.jsx)(s,{size:`small`,theme:`borderless`,icon:(0,D.jsx)(ne,{}),onClick:()=>R({item:t,form:{}})}),i&&(0,D.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,D.jsx)(te,{}),onClick:()=>me(t)})]})}],dataSource:ue,rowKey:`id`,loading:q.loading,pagination:{currentPage:N,pageSize:F,total:de,onPageChange:P,onPageSizeChange:e=>{I(e),P(1)}},toolbar:(0,D.jsxs)(a,{children:[(0,D.jsx)(re,{prefix:(0,D.jsx)(l,{}),value:j,onChange:e=>{M(e),P(1)},placeholder:`搜索标题或内容`,style:{width:220}}),(0,D.jsx)(f,{value:A,onChange:e=>{le(e||``),P(1)},placeholder:`全部分类`,style:{width:180},showClear:!0,optionList:fe}),(0,D.jsx)(s,{onClick:()=>W(!0),children:`检索测试`})]})})]}),(0,D.jsx)(b,{title:L?.item?`编辑知识项`:`新增知识项`,visible:!!L,onCancel:()=>R(null),onOk:pe,confirmLoading:V,width:760,children:(0,D.jsxs)(c,{getFormApi:e=>R(t=>t&&{...t,form:e}),initValues:L?.item?{category:L.item.category,title:L.item.title,content:L.item.content}:{},children:[(0,D.jsx)(c.Input,{field:`category`,label:`分类`,rules:[{required:!0,message:`请输入分类`}],placeholder:`例如 sql_injection`}),(0,D.jsx)(c.Input,{field:`title`,label:`标题`,rules:[{required:!0,message:`请输入标题`}]}),(0,D.jsx)(c.TextArea,{field:`content`,label:`内容(Markdown)`,rules:[{required:!0,message:`请输入内容`}],autosize:{minRows:10,maxRows:24}})]})},L?.item?.id||`new`),(0,D.jsx)(b,{title:z?.title||`知识项`,visible:!!z,onCancel:()=>B(null),width:640,children:z&&(0,D.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,D.jsx)(x,{items:[{label:`分类`,value:z.category},{label:`文件路径`,value:z.filePath},{label:`创建时间`,value:m(z.createdAt)},{label:`更新时间`,value:m(z.updatedAt)}]}),(0,D.jsx)(S,{content:z.content||`(内容需要打开原文查看)`})]})}),(0,D.jsxs)(b,{title:`知识检索测试`,visible:U,onCancel:()=>{W(!1),K(null)},footer:null,width:720,children:[(0,D.jsxs)(c,{onSubmit:({query:e})=>he(e),children:[(0,D.jsx)(c.Input,{field:`query`,label:`检索语句`,rules:[{required:!0,message:`请输入检索语句`}]}),(0,D.jsx)(s,{htmlType:`submit`,theme:`solid`,type:`primary`,children:`检索`})]}),G&&(0,D.jsxs)(`div`,{style:{marginTop:16,display:`flex`,flexDirection:`column`,gap:8},children:[(G.results||[]).map((e,t)=>(0,D.jsxs)(`div`,{style:{border:`1px solid var(--semi-color-border)`,borderRadius:8,padding:12},children:[(0,D.jsxs)(a,{children:[(0,D.jsxs)(o,{color:`blue`,children:[`#`,t+1]}),(0,D.jsx)(O,{strong:!0,children:e.item?.title||e.title||e.id}),e.score!==void 0&&(0,D.jsxs)(O,{type:`tertiary`,children:[`相似度 `,Number(e.score).toFixed(3)]})]}),(0,D.jsx)(`div`,{style:{marginTop:8},children:(0,D.jsx)(S,{content:String(e.content||e.item?.content||``).slice(0,600)})})]},e.id||t)),(G.results||[]).length===0&&(0,D.jsx)(O,{type:`tertiary`,children:`没有命中结果`})]})]})]})}export{k as default};
\ No newline at end of file
diff --git a/web/static/app/assets/knowledge-retrieval-logs-1o1SzSFP.js b/web/static/app/assets/knowledge-retrieval-logs-4_2LIOnY.js
similarity index 86%
rename from web/static/app/assets/knowledge-retrieval-logs-1o1SzSFP.js
rename to web/static/app/assets/knowledge-retrieval-logs-4_2LIOnY.js
index a1a6820a..f783cbdf 100644
--- a/web/static/app/assets/knowledge-retrieval-logs-1o1SzSFP.js
+++ b/web/static/app/assets/knowledge-retrieval-logs-4_2LIOnY.js
@@ -1 +1 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,Lt as a,N as o,R as s,U as c,lt as l,ut as u}from"./semi-65W_4I1v.js";import{E as d,F as f,I as p,P as m,a as h,c as g,d as _,l as v,m as y,p as b,s as x,u as S,x as C,y as w}from"./index-BdnarFZR.js";var T=e(t(),1),E=e(n(),1),{Text:D}=r;function O(){let e=m(),{hasPermission:t}=f(),n=t(`knowledge:delete`),[r,O]=(0,T.useState)(``),[k,A]=(0,T.useState)(50),[j,M]=(0,T.useState)(null),N=h(()=>p.get(`/knowledge/retrieval-logs`,{conversationId:r||void 0,limit:k}),[r,k]),P=Array.isArray(N.data?.logs)?N.data.logs:[],F=e=>w({title:`删除该检索日志?`,content:e.query||e.id,onOk:async()=>{await p.del(`/knowledge/retrieval-logs/${encodeURIComponent(e.id)}`),C(`已删除`),N.reload()}});return(0,E.jsxs)(`div`,{children:[(0,E.jsx)(b,{title:e(`knowledge.retrievalLogsTitle`,null,`检索历史`),description:`记录智能体每次知识库检索的语句、命中项与会话,用于回溯回答依据。`,extra:(0,E.jsx)(s,{icon:(0,E.jsx)(u,{}),onClick:()=>N.reload(),loading:N.loading,children:`刷新`})}),(0,E.jsxs)(y,{title:`检索记录(${P.length})`,children:[(0,E.jsx)(v,{error:N.error,onRetry:()=>N.reload()}),(0,E.jsx)(x,{columns:[{title:`检索语句`,dataIndex:`query`,render:(e,t)=>(0,E.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>M(t),style:{background:`none`,border:`none`,padding:0,cursor:`pointer`,textAlign:`left`,color:`var(--semi-color-primary)`},children:e||`—`})},{title:`风险类型`,dataIndex:`riskType`,width:140,render:e=>e?(0,E.jsx)(o,{size:`small`,children:e}):`—`},{title:`命中知识项`,dataIndex:`retrievedItems`,width:120,render:e=>(0,E.jsxs)(D,{type:`tertiary`,children:[Array.isArray(e)?e.length:0,` 条`]})},{title:`会话`,dataIndex:`conversationId`,width:200,render:e=>(0,E.jsx)(D,{type:`tertiary`,ellipsis:{showTooltip:!0},children:e||`—`})},{title:`时间`,dataIndex:`createdAt`,width:180,render:e=>d(e)},{title:`操作`,width:110,render:(e,t)=>(0,E.jsxs)(i,{children:[(0,E.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>M(t),children:`详情`}),n&&(0,E.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,E.jsx)(a,{}),onClick:()=>F(t)})]})}],dataSource:P,rowKey:`id`,loading:N.loading,pagination:!1,toolbar:(0,E.jsxs)(i,{children:[(0,E.jsx)(c,{prefix:(0,E.jsx)(l,{}),placeholder:`按会话 ID 过滤`,value:r,onChange:O,style:{width:260}}),(0,E.jsx)(c,{placeholder:`条数`,value:String(k),onChange:e=>A(Math.min(Math.max(Number(e)||50,1),500)),style:{width:100},suffix:(0,E.jsx)(D,{type:`tertiary`,children:`条`})})]})})]}),(0,E.jsx)(g,{title:`检索日志详情`,visible:!!j,onCancel:()=>M(null),width:560,children:j&&(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,E.jsx)(_,{items:[{label:`日志 ID`,value:j.id},{label:`检索语句`,value:j.query},{label:`风险类型`,value:j.riskType||`—`},{label:`会话 ID`,value:j.conversationId||`—`},{label:`消息 ID`,value:j.messageId||`—`},{label:`时间`,value:d(j.createdAt)}]}),(0,E.jsx)(S,{value:j.retrievedItems||[],title:`命中知识项`})]})})]})}export{O as default};
\ No newline at end of file
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,Lt as a,N as o,R as s,U as c,lt as l,ut as u}from"./semi-65W_4I1v.js";import{E as d,F as f,I as p,L as m,a as h,c as g,d as _,l as v,m as y,p as b,s as x,u as S,x as C,y as w}from"./index-_8d9XBPJ.js";var T=e(t(),1),E=e(n(),1),{Text:D}=r;function O(){let e=f(),{hasPermission:t}=p(),n=t(`knowledge:delete`),[r,O]=(0,T.useState)(``),[k,A]=(0,T.useState)(50),[j,M]=(0,T.useState)(null),N=h(()=>m.get(`/knowledge/retrieval-logs`,{conversationId:r||void 0,limit:k}),[r,k]),P=Array.isArray(N.data?.logs)?N.data.logs:[],F=e=>w({title:`删除该检索日志?`,content:e.query||e.id,onOk:async()=>{await m.del(`/knowledge/retrieval-logs/${encodeURIComponent(e.id)}`),C(`已删除`),N.reload()}});return(0,E.jsxs)(`div`,{children:[(0,E.jsx)(b,{title:e(`knowledge.retrievalLogsTitle`,null,`检索历史`),description:`记录智能体每次知识库检索的语句、命中项与会话,用于回溯回答依据。`,extra:(0,E.jsx)(s,{icon:(0,E.jsx)(u,{}),onClick:()=>N.reload(),loading:N.loading,children:`刷新`})}),(0,E.jsxs)(y,{title:`检索记录(${P.length})`,children:[(0,E.jsx)(v,{error:N.error,onRetry:()=>N.reload()}),(0,E.jsx)(x,{columns:[{title:`检索语句`,dataIndex:`query`,render:(e,t)=>(0,E.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>M(t),style:{background:`none`,border:`none`,padding:0,cursor:`pointer`,textAlign:`left`,color:`var(--semi-color-primary)`},children:e||`—`})},{title:`风险类型`,dataIndex:`riskType`,width:140,render:e=>e?(0,E.jsx)(o,{size:`small`,children:e}):`—`},{title:`命中知识项`,dataIndex:`retrievedItems`,width:120,render:e=>(0,E.jsxs)(D,{type:`tertiary`,children:[Array.isArray(e)?e.length:0,` 条`]})},{title:`会话`,dataIndex:`conversationId`,width:200,render:e=>(0,E.jsx)(D,{type:`tertiary`,ellipsis:{showTooltip:!0},children:e||`—`})},{title:`时间`,dataIndex:`createdAt`,width:180,render:e=>d(e)},{title:`操作`,width:110,render:(e,t)=>(0,E.jsxs)(i,{children:[(0,E.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>M(t),children:`详情`}),n&&(0,E.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,E.jsx)(a,{}),onClick:()=>F(t)})]})}],dataSource:P,rowKey:`id`,loading:N.loading,pagination:!1,toolbar:(0,E.jsxs)(i,{children:[(0,E.jsx)(c,{prefix:(0,E.jsx)(l,{}),placeholder:`按会话 ID 过滤`,value:r,onChange:O,style:{width:260}}),(0,E.jsx)(c,{placeholder:`条数`,value:String(k),onChange:e=>A(Math.min(Math.max(Number(e)||50,1),500)),style:{width:100},suffix:(0,E.jsx)(D,{type:`tertiary`,children:`条`})})]})})]}),(0,E.jsx)(g,{title:`检索日志详情`,visible:!!j,onCancel:()=>M(null),width:560,children:j&&(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,E.jsx)(_,{items:[{label:`日志 ID`,value:j.id},{label:`检索语句`,value:j.query},{label:`风险类型`,value:j.riskType||`—`},{label:`会话 ID`,value:j.conversationId||`—`},{label:`消息 ID`,value:j.messageId||`—`},{label:`时间`,value:d(j.createdAt)}]}),(0,E.jsx)(S,{value:j.retrievedItems||[],title:`命中知识项`})]})})]})}export{O as default};
\ No newline at end of file
diff --git a/web/static/app/assets/mcp-management-hsz83LkQ.js b/web/static/app/assets/mcp-management-BDsOVfL3.js
similarity index 75%
rename from web/static/app/assets/mcp-management-hsz83LkQ.js
rename to web/static/app/assets/mcp-management-BDsOVfL3.js
index e3d011a8..0145c8e8 100644
--- a/web/static/app/assets/mcp-management-hsz83LkQ.js
+++ b/web/static/app/assets/mcp-management-BDsOVfL3.js
@@ -1 +1 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,G as i,I as a,N as o,P as s,R as c,S as l,U as u,d,ft as f,lt as p,ut as m,y as h}from"./semi-65W_4I1v.js";import{F as g,I as _,P as v,R as y,_ as b,a as x,b as S,c as C,l as w,m as T,n as E,o as D,p as O,r as k,s as A,x as j,y as M}from"./index-BdnarFZR.js";var N=e(t(),1),P={connected:{color:`green`,label:`已连接`},connecting:{color:`blue`,label:`连接中`},disconnected:{color:`amber`,label:`未连接`},disabled:{color:`grey`,label:`已停用`},error:{color:`red`,label:`连接失败`}};function F(e){return P[String(e||``).toLowerCase()]||{color:`grey`,label:e||`未知`}}function I(e){return e?String(e.type||e.transport||(e.command?`stdio`:`http`)).toLowerCase():`http`}function L(e){return e?e.is_external&&e.external_mcp?`${e.external_mcp}::${e.name}`:e.name||``:``}function R(e){return e?e.is_external?`外部 · ${e.external_mcp||`未知`}`:`内置`:`—`}var z=e(n(),1),{Text:B}=i,V={"my-stdio-server":{command:`python3`,args:["${HOME}/mcp-servers/main.py",`--port`,"${MCP_PORT:-3000}"],env:{API_KEY:"${API_KEY}",LOG_LEVEL:"${LOG_LEVEL:-INFO}"},timeout:300},"my-http-server":{type:`http`,url:`https://mcp.example.com/mcp`,headers:{Authorization:"Bearer ${MCP_TOKEN}"}},"my-sse-server":{type:`sse`,url:`http://127.0.0.1:8081/mcp/sse`}};function H(e,{editingName:t}){if(typeof e!=`object`||!e||Array.isArray(e))return{error:`配置必须是 JSON 对象`};let n=Object.keys(e);if(!n.length)return{error:`至少需要一个 MCP 配置`};if(t&&!e[t])return{error:`编辑模式下 JSON 必须包含配置名称 "${t}"`};for(let t of n){if(!t.trim())return{error:`配置名称不能为空`};let n=e[t];if(typeof n!=`object`||!n||Array.isArray(n))return{error:`"${t}" 的配置必须是对象`};delete n.external_mcp_enable;let r=n.type||n.transport||(n.command?`stdio`:n.url?`http`:``);if(!r)return{error:`"${t}" 需要指定 command(stdio)或 url + type(http/sse)`};if(r===`stdio`&&!n.command)return{error:`"${t}" 的 stdio 模式需要 command`};if((r===`http`||r===`sse`)&&!n.url)return{error:`"${t}" 的 ${r} 模式需要 url`}}return{error:``,names:n}}function U({canWrite:e,onChanged:t,refreshKey:n=0}){let i=v(),s=x(()=>_.get(`/external-mcp`),[n]),[u,d]=(0,N.useState)(``),[p,h]=(0,N.useState)(!1),[g,b]=(0,N.useState)(null),[E,O]=(0,N.useState)(``),[A,P]=(0,N.useState)(``),[L,R]=(0,N.useState)(!1),U=(0,N.useMemo)(()=>{let e=s.data?.servers||{};return Object.entries(e).sort(([e],[t])=>e.localeCompare(t))},[s.data]),W=(0,N.useCallback)(e=>s.reload(e),[s.reload]);k(()=>{typeof document<`u`&&document.hidden||W({silent:!0})},8e3);let G=(0,N.useCallback)(()=>{b(null),O(``),P(``),h(!0)},[]),K=(0,N.useCallback)(async e=>{b(e),O(``),P(``),h(!0);try{let t={...(await _.get(`/external-mcp/${encodeURIComponent(e)}`))?.config||{}};delete t.tool_count,delete t.external_mcp_enable,O(JSON.stringify({[e]:t},null,2))}catch(e){h(!1),S(e,i(`mcp.getConfigFailed`,null,`获取外部MCP配置失败`))}},[i]),q=(0,N.useCallback)(()=>{h(!1),b(null),P(``)},[]),J=(0,N.useCallback)(async(e,n)=>{let r=n===`connected`?`stop`:`start`;d(e);try{await _.post(`/external-mcp/${encodeURIComponent(e)}/${r}`,{}),j(r===`start`?`已提交启动请求,正在后台连接`:`外部 MCP 已停止`),W({silent:!0}),t?.()}catch(e){S(e,i(`mcp.operationFailed`,null,`操作失败`))}finally{d(``)}},[t,W,i]),Y=(0,N.useCallback)(e=>{M({title:i(`mcp.deleteExternalConfirm`,{name:e},`确定要删除外部MCP "${e}" 吗?`),content:`删除后该 MCP 的工具将从对话中移除。`,okText:i(`common.delete`,null,`删除`),onOk:async()=>{try{await _.del(`/external-mcp/${encodeURIComponent(e)}`),j(i(`mcp.deleteSuccess`,null,`删除成功`)),W(),t?.()}catch(e){S(e,i(`mcp.operationFailed`,null,`删除失败`))}}})},[t,W,i]),X=(0,N.useCallback)(async()=>{let e=E.trim();if(!e){P(i(`mcp.jsonEmpty`,null,`JSON不能为空`));return}let n;try{n=JSON.parse(e)}catch(e){P(`${i(`mcp.jsonError`,null,`JSON格式错误`)}: ${e.message}`);return}let{error:r,names:a}=H(n,{editingName:g});if(r)P(r);else{P(``),R(!0);try{let e=g?[g]:a;for(let t of e)await _.put(`/external-mcp/${encodeURIComponent(t)}`,{config:n[t]});j(i(`mcp.saveSuccess`,null,`保存成功`)),q(),W(),t?.()}catch(e){P(`${i(`mcp.operationFailed`,null,`保存失败`)}: ${y(e)}`)}finally{R(!1)}}},[q,g,E,t,W,i]),Z=(0,z.jsxs)(a,{spacing:8,children:[(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(m,{}),theme:`borderless`,onClick:()=>W(),loading:s.loading,children:i(`common.refresh`,null,`刷新`)}),(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(f,{}),disabled:!e,onClick:G,children:i(`mcp.addExternalMCP`,null,`添加外部MCP`)})]});return(0,z.jsxs)(T,{title:i(`mcp.externalConfig`,null,`外部 MCP 配置`),description:`stdio 传 command/args/env,http 与 sse 传 url/headers;状态每 8 秒自动刷新。`,extra:Z,children:[(0,z.jsx)(w,{error:s.error,onRetry:()=>W()}),!U.length&&!s.loading&&(0,z.jsxs)(`div`,{className:`mcp-management-empty`,children:[(0,z.jsx)(`p`,{children:i(`mcp.noExternalMCP`,null,`暂无外部 MCP`)}),(0,z.jsx)(c,{size:`small`,disabled:!e,onClick:G,children:i(`mcp.clickToAddExternal`,null,`点击添加外部 MCP`)})]}),(0,z.jsx)(`div`,{className:`mcp-management-mcp-grid`,children:U.map(([t,n])=>{let s=n?.config||{},l=String(n?.status||`disconnected`),d=F(l),f=I(s),p=l===`connected`;return(0,z.jsxs)(`div`,{className:`mcp-management-mcp-card`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-mcp-head`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-mcp-title`,children:[(0,z.jsx)(B,{strong:!0,children:t}),(0,z.jsx)(o,{size:`small`,color:d.color,children:d.label}),(0,z.jsx)(o,{size:`small`,color:`grey`,children:f.toUpperCase()}),Number(n?.tool_count)>0&&(0,z.jsx)(o,{size:`small`,color:`blue`,children:`${n.tool_count} 个工具`})]}),(0,z.jsxs)(a,{spacing:4,wrap:!0,children:[(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e||u===t||l===`connecting`,loading:u===t,onClick:()=>J(t,l),children:l===`connecting`?i(`mcp.connecting`,null,`连接中`):p?i(`mcp.stop`,null,`停止`):i(`mcp.start`,null,`启动`)}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>K(t),children:i(`common.edit`,null,`编辑`)}),(0,z.jsx)(c,{size:`small`,type:`danger`,theme:`borderless`,disabled:!e,onClick:()=>Y(t),children:i(`common.delete`,null,`删除`)})]})]}),(l===`error`||l===`disconnected`)&&n?.error&&(0,z.jsx)(r,{type:l===`error`?`danger`:`warning`,className:`mcp-management-mcp-error`,description:(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:n.error})}),(0,z.jsxs)(`div`,{className:`mcp-management-mcp-meta`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.transportMode`,null,`传输方式`)}),(0,z.jsx)(`span`,{children:f.toUpperCase()})]}),s.description&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.description`,null,`描述`)}),(0,z.jsx)(`span`,{children:s.description})]}),f===`stdio`&&s.command&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.command`,null,`命令`)}),(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:s.command})]}),f!==`stdio`&&s.url&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:`URL`}),(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:s.url})]}),Number(s.timeout)>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.timeout`,null,`超时`)}),(0,z.jsxs)(`span`,{children:[s.timeout,` `,i(`mcp.secondsUnit`,null,`秒`)]})]})]})]},t)})}),(0,z.jsx)(C,{title:g?`${i(`mcp.editExternalMCP`,null,`编辑外部MCP`)} · ${g}`:i(`mcp.addExternalMCP`,null,`添加外部 MCP`),visible:p,onCancel:q,onOk:X,confirmLoading:L,width:760,okText:i(`common.save`,null,`保存`),cancelText:i(`common.cancel`,null,`取消`),children:(0,z.jsxs)(`div`,{className:`mcp-management-form`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-form-head`,children:[(0,z.jsx)(B,{type:`tertiary`,children:g?`编辑模式下只提交当前名称的配置;external_mcp_enable 由启停按钮维护。`:`支持一次粘贴多个 MCP:{"name": {...}};保存后逐个写入 config.yaml。`}),!g&&(0,z.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>O(JSON.stringify(V,null,2)),children:`载入示例`}),E&&(0,z.jsx)(D,{text:E,size:`small`})]}),(0,z.jsx)(l,{className:`mcp-management-json`,rows:16,value:E,spellCheck:!1,placeholder:`{"my-http-server": {"type": "http", "url": "https://mcp.example.com/mcp"}}`,onChange:e=>{O(e),A&&P(``)}}),A&&(0,z.jsx)(`div`,{className:`mcp-management-form-error`,children:A})]})})]})}var{Text:W}=i;function G({canWrite:e,refreshKey:t=0}){let n=v(),[r,i]=(0,N.useState)(1),[l,f]=(0,N.useState)(20),[g,y]=(0,N.useState)(``),b=E(g,350),[C,D]=(0,N.useState)(`all`),[O,k]=(0,N.useState)(!0),[M,P]=(0,N.useState)({}),[F,I]=(0,N.useState)(!1),B=(0,N.useRef)(new Map),V=x(()=>_.get(`/config/tools`,{page:r,page_size:l,search:b,tool_filter:C===`all`?``:C,include_external:O?``:`0`}),[r,l,b,C,O,t]),H=V.data?.tools||[],U=Number(V.data?.total)||0,G=(0,N.useDeferredValue)(H);(0,N.useEffect)(()=>{(H||[]).forEach(e=>B.current.set(L(e),e))},[H]);let K=(0,N.useMemo)(()=>Object.keys(M),[M]),q=(0,N.useCallback)(e=>Object.prototype.hasOwnProperty.call(M,L(e))?M[L(e)]:e.enabled,[M]),J=(0,N.useCallback)((e,t)=>{let n=L(e);P(r=>{let i={...r};return t===e.enabled?delete i[n]:i[n]=t,i})},[]),Y=(0,N.useCallback)(e=>{P(t=>{let n={...t};return(H||[]).forEach(t=>{let r=L(t);t.enabled===e?delete n[r]:n[r]=e}),n})},[H]),X=(0,N.useCallback)(()=>P({}),[]),Z=(0,N.useCallback)(async()=>{let e=Object.entries(M);if(e.length){I(!0);try{let t=e.map(([e,t])=>{let n=B.current.get(e);return{name:n?.name||e.split(`::`).pop()||e,enabled:t,is_external:!!n?.is_external,external_mcp:n?.external_mcp||``}});await _.put(`/config`,{tools:t}),await _.post(`/config/apply`,{}),j(n(`mcp.toolsConfigSaved`,null,`工具配置已成功保存`)),P({}),V.reload({silent:!0})}catch(e){S(e,n(`mcp.saveToolsConfigFailed`,null,`保存工具配置失败`))}finally{I(!1)}}},[M,V.reload,n]),Q=[{title:n(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`name`,render:e=>(0,z.jsx)(`span`,{className:`mcp-management-mono mcp-management-tool-name`,children:e})},{title:`来源`,dataIndex:`is_external`,width:180,render:(e,t)=>(0,z.jsx)(o,{size:`small`,color:e?`blue`:`grey`,children:R(t)})},{title:n(`mcp.filterEnabled`,null,`已启用`),dataIndex:`enabled`,width:110,render:(t,n)=>(0,z.jsx)(d,{size:`small`,checked:q(n),disabled:!e,onChange:e=>J(n,e)})},{title:n(`mcp.description`,null,`描述`),dataIndex:`description`,render:e=>(0,z.jsx)(W,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:560},children:e||n(`mcp.noDescription`,null,`暂无描述`)})}],$={currentPage:r,pageSize:l,total:U,showSizeChanger:!0,pageSizeOpts:[20,50,100],showTotal:!0,onPageChange:e=>i(e),onPageSizeChange:e=>{f(e),i(1)}},ee=[{value:`all`,label:n(`mcp.filterAll`,null,`全部`)},{value:`on`,label:n(`mcp.filterEnabled`,null,`已启用`)},{value:`off`,label:n(`mcp.filterDisabled`,null,`已停用`)}];return(0,z.jsxs)(T,{title:n(`mcp.toolConfig`,null,`MCP 工具配置`),description:`${n(`mcp.currentPageEnabled`,null,`当前页已启用`)} ${(G||[]).filter(e=>q(e)).length} / ${G.length} · ${n(`mcp.totalEnabled`,null,`已启用工具总数`)} ${V.data?.total_enabled??`—`}`,extra:(0,z.jsxs)(a,{spacing:8,children:[K.length>0&&(0,z.jsx)(o,{size:`small`,color:`amber`,children:`未保存 ${K.length} 项`}),K.length>0&&(0,z.jsx)(c,{size:`small`,theme:`borderless`,onClick:X,disabled:F,children:`放弃修改`}),(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(m,{}),theme:`borderless`,onClick:()=>V.reload(),loading:V.loading,children:n(`common.refresh`,null,`刷新`)}),(0,z.jsx)(c,{size:`small`,theme:`solid`,disabled:!e||!K.length,loading:F,onClick:Z,children:n(`mcp.saveToolConfig`,null,`保存工具配置`)})]}),children:[(0,z.jsx)(w,{error:V.error,onRetry:()=>V.reload()}),(0,z.jsx)(A,{columns:Q,dataSource:H,rowKey:e=>L(e),loading:V.loading,pagination:$,size:`small`,emptyText:n(`mcp.noTools`,null,`暂无工具`),toolbar:(0,z.jsxs)(a,{spacing:8,wrap:!0,children:[(0,z.jsx)(u,{prefix:(0,z.jsx)(p,{}),showClear:!0,style:{width:240},value:g,placeholder:n(`mcp.toolSearchPlaceholder`,null,`搜索工具…`),onChange:e=>{y(e),i(1)}}),(0,z.jsx)(h,{value:C,style:{width:140},optionList:ee,onChange:e=>{D(e),i(1)}}),(0,z.jsx)(s,{checked:O,onChange:e=>{k(e.target.checked),i(1)},children:`包含外部 MCP 工具`}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>Y(!0),children:n(`mcp.selectAll`,null,`全选`)}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>Y(!1),children:n(`mcp.deselectAll`,null,`全不选`)})]})}),(0,z.jsx)(`p`,{className:`mcp-management-hint`,children:`保存只提交本次改动的工具项;应用后由后端重新注册 MCP 工具。直接注册(未写入 config.yaml)的工具切换不会落盘。`})]})}function K(){let e=v(),{hasPermission:t}=g(),n=t(`mcp:write`),[r,i]=(0,N.useState)(0),o=x(()=>_.get(`/external-mcp/stats`),[r]),s=o.data||{},l=(0,N.useCallback)(()=>{i(e=>e+1),o.reload({silent:!0})},[o.reload]);return(0,z.jsxs)(`div`,{className:`mcp-management-page`,children:[(0,z.jsx)(O,{title:e(`mcp.managementTitle`,null,`MCP 管理`),description:`维护外部 MCP 连接与工具启用状态;改动写入 config.yaml 后立即生效。`,extra:(0,z.jsx)(a,{children:(0,z.jsx)(c,{icon:(0,z.jsx)(m,{}),onClick:l,loading:o.loading,children:e(`common.refresh`,null,`刷新`)})})}),(0,z.jsx)(b,{columns:4,metrics:[{id:`total`,label:e(`mcp.totalCount`,null,`总数`),value:o.error?`—`:s.total??0,detail:e(`mcp.externalConfig`,null,`外部 MCP 配置`),loading:o.loading&&!o.data},{id:`enabled`,label:e(`mcp.enabledCount`,null,`已启用`),value:o.error?`—`:s.enabled??0,tone:`success`,loading:o.loading&&!o.data},{id:`connected`,label:e(`mcp.connectedCount`,null,`已连接`),value:o.error?`—`:s.connected??0,tone:s.connected>0?`success`:void 0,loading:o.loading&&!o.data},{id:`disabled`,label:e(`mcp.disabledCount`,null,`已停用`),value:o.error?`—`:s.disabled??0,loading:o.loading&&!o.data}]}),(0,z.jsx)(w,{error:o.error,onRetry:l}),(0,z.jsx)(U,{canWrite:n,onChanged:l,refreshKey:r}),(0,z.jsx)(G,{canWrite:n,refreshKey:r})]})}export{K as default};
\ No newline at end of file
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,G as i,I as a,N as o,P as s,R as c,S as l,U as u,d,ft as f,lt as p,ut as m,y as h}from"./semi-65W_4I1v.js";import{F as g,I as _,L as v,_ as y,a as b,b as x,c as S,l as C,m as w,n as T,o as E,p as D,r as O,s as k,x as A,y as j,z as M}from"./index-_8d9XBPJ.js";var N=e(t(),1),P={connected:{color:`green`,label:`已连接`},connecting:{color:`blue`,label:`连接中`},disconnected:{color:`amber`,label:`未连接`},disabled:{color:`grey`,label:`已停用`},error:{color:`red`,label:`连接失败`}};function F(e){return P[String(e||``).toLowerCase()]||{color:`grey`,label:e||`未知`}}function I(e){return e?String(e.type||e.transport||(e.command?`stdio`:`http`)).toLowerCase():`http`}function L(e){return e?e.is_external&&e.external_mcp?`${e.external_mcp}::${e.name}`:e.name||``:``}function R(e){return e?e.is_external?`外部 · ${e.external_mcp||`未知`}`:`内置`:`—`}var z=e(n(),1),{Text:B}=i,V={"my-stdio-server":{command:`python3`,args:["${HOME}/mcp-servers/main.py",`--port`,"${MCP_PORT:-3000}"],env:{API_KEY:"${API_KEY}",LOG_LEVEL:"${LOG_LEVEL:-INFO}"},timeout:300},"my-http-server":{type:`http`,url:`https://mcp.example.com/mcp`,headers:{Authorization:"Bearer ${MCP_TOKEN}"}},"my-sse-server":{type:`sse`,url:`http://127.0.0.1:8081/mcp/sse`}};function H(e,{editingName:t}){if(typeof e!=`object`||!e||Array.isArray(e))return{error:`配置必须是 JSON 对象`};let n=Object.keys(e);if(!n.length)return{error:`至少需要一个 MCP 配置`};if(t&&!e[t])return{error:`编辑模式下 JSON 必须包含配置名称 "${t}"`};for(let t of n){if(!t.trim())return{error:`配置名称不能为空`};let n=e[t];if(typeof n!=`object`||!n||Array.isArray(n))return{error:`"${t}" 的配置必须是对象`};delete n.external_mcp_enable;let r=n.type||n.transport||(n.command?`stdio`:n.url?`http`:``);if(!r)return{error:`"${t}" 需要指定 command(stdio)或 url + type(http/sse)`};if(r===`stdio`&&!n.command)return{error:`"${t}" 的 stdio 模式需要 command`};if((r===`http`||r===`sse`)&&!n.url)return{error:`"${t}" 的 ${r} 模式需要 url`}}return{error:``,names:n}}function U({canWrite:e,onChanged:t,refreshKey:n=0}){let i=g(),s=b(()=>v.get(`/external-mcp`),[n]),[u,d]=(0,N.useState)(``),[p,h]=(0,N.useState)(!1),[_,y]=(0,N.useState)(null),[T,D]=(0,N.useState)(``),[k,P]=(0,N.useState)(``),[L,R]=(0,N.useState)(!1),U=(0,N.useMemo)(()=>{let e=s.data?.servers||{};return Object.entries(e).sort(([e],[t])=>e.localeCompare(t))},[s.data]),W=(0,N.useCallback)(e=>s.reload(e),[s.reload]);O(()=>{typeof document<`u`&&document.hidden||W({silent:!0})},8e3);let G=(0,N.useCallback)(()=>{y(null),D(``),P(``),h(!0)},[]),K=(0,N.useCallback)(async e=>{y(e),D(``),P(``),h(!0);try{let t={...(await v.get(`/external-mcp/${encodeURIComponent(e)}`))?.config||{}};delete t.tool_count,delete t.external_mcp_enable,D(JSON.stringify({[e]:t},null,2))}catch(e){h(!1),x(e,i(`mcp.getConfigFailed`,null,`获取外部MCP配置失败`))}},[i]),q=(0,N.useCallback)(()=>{h(!1),y(null),P(``)},[]),J=(0,N.useCallback)(async(e,n)=>{let r=n===`connected`?`stop`:`start`;d(e);try{await v.post(`/external-mcp/${encodeURIComponent(e)}/${r}`,{}),A(r===`start`?`已提交启动请求,正在后台连接`:`外部 MCP 已停止`),W({silent:!0}),t?.()}catch(e){x(e,i(`mcp.operationFailed`,null,`操作失败`))}finally{d(``)}},[t,W,i]),Y=(0,N.useCallback)(e=>{j({title:i(`mcp.deleteExternalConfirm`,{name:e},`确定要删除外部MCP "${e}" 吗?`),content:`删除后该 MCP 的工具将从对话中移除。`,okText:i(`common.delete`,null,`删除`),onOk:async()=>{try{await v.del(`/external-mcp/${encodeURIComponent(e)}`),A(i(`mcp.deleteSuccess`,null,`删除成功`)),W(),t?.()}catch(e){x(e,i(`mcp.operationFailed`,null,`删除失败`))}}})},[t,W,i]),X=(0,N.useCallback)(async()=>{let e=T.trim();if(!e){P(i(`mcp.jsonEmpty`,null,`JSON不能为空`));return}let n;try{n=JSON.parse(e)}catch(e){P(`${i(`mcp.jsonError`,null,`JSON格式错误`)}: ${e.message}`);return}let{error:r,names:a}=H(n,{editingName:_});if(r)P(r);else{P(``),R(!0);try{let e=_?[_]:a;for(let t of e)await v.put(`/external-mcp/${encodeURIComponent(t)}`,{config:n[t]});A(i(`mcp.saveSuccess`,null,`保存成功`)),q(),W(),t?.()}catch(e){P(`${i(`mcp.operationFailed`,null,`保存失败`)}: ${M(e)}`)}finally{R(!1)}}},[q,_,T,t,W,i]),Z=(0,z.jsxs)(a,{spacing:8,children:[(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(m,{}),theme:`borderless`,onClick:()=>W(),loading:s.loading,children:i(`common.refresh`,null,`刷新`)}),(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(f,{}),disabled:!e,onClick:G,children:i(`mcp.addExternalMCP`,null,`添加外部MCP`)})]});return(0,z.jsxs)(w,{title:i(`mcp.externalConfig`,null,`外部 MCP 配置`),description:`stdio 传 command/args/env,http 与 sse 传 url/headers;状态每 8 秒自动刷新。`,extra:Z,children:[(0,z.jsx)(C,{error:s.error,onRetry:()=>W()}),!U.length&&!s.loading&&(0,z.jsxs)(`div`,{className:`mcp-management-empty`,children:[(0,z.jsx)(`p`,{children:i(`mcp.noExternalMCP`,null,`暂无外部 MCP`)}),(0,z.jsx)(c,{size:`small`,disabled:!e,onClick:G,children:i(`mcp.clickToAddExternal`,null,`点击添加外部 MCP`)})]}),(0,z.jsx)(`div`,{className:`mcp-management-mcp-grid`,children:U.map(([t,n])=>{let s=n?.config||{},l=String(n?.status||`disconnected`),d=F(l),f=I(s),p=l===`connected`;return(0,z.jsxs)(`div`,{className:`mcp-management-mcp-card`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-mcp-head`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-mcp-title`,children:[(0,z.jsx)(B,{strong:!0,children:t}),(0,z.jsx)(o,{size:`small`,color:d.color,children:d.label}),(0,z.jsx)(o,{size:`small`,color:`grey`,children:f.toUpperCase()}),Number(n?.tool_count)>0&&(0,z.jsx)(o,{size:`small`,color:`blue`,children:`${n.tool_count} 个工具`})]}),(0,z.jsxs)(a,{spacing:4,wrap:!0,children:[(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e||u===t||l===`connecting`,loading:u===t,onClick:()=>J(t,l),children:l===`connecting`?i(`mcp.connecting`,null,`连接中`):p?i(`mcp.stop`,null,`停止`):i(`mcp.start`,null,`启动`)}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>K(t),children:i(`common.edit`,null,`编辑`)}),(0,z.jsx)(c,{size:`small`,type:`danger`,theme:`borderless`,disabled:!e,onClick:()=>Y(t),children:i(`common.delete`,null,`删除`)})]})]}),(l===`error`||l===`disconnected`)&&n?.error&&(0,z.jsx)(r,{type:l===`error`?`danger`:`warning`,className:`mcp-management-mcp-error`,description:(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:n.error})}),(0,z.jsxs)(`div`,{className:`mcp-management-mcp-meta`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.transportMode`,null,`传输方式`)}),(0,z.jsx)(`span`,{children:f.toUpperCase()})]}),s.description&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.description`,null,`描述`)}),(0,z.jsx)(`span`,{children:s.description})]}),f===`stdio`&&s.command&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.command`,null,`命令`)}),(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:s.command})]}),f!==`stdio`&&s.url&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:`URL`}),(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:s.url})]}),Number(s.timeout)>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.timeout`,null,`超时`)}),(0,z.jsxs)(`span`,{children:[s.timeout,` `,i(`mcp.secondsUnit`,null,`秒`)]})]})]})]},t)})}),(0,z.jsx)(S,{title:_?`${i(`mcp.editExternalMCP`,null,`编辑外部MCP`)} · ${_}`:i(`mcp.addExternalMCP`,null,`添加外部 MCP`),visible:p,onCancel:q,onOk:X,confirmLoading:L,width:760,okText:i(`common.save`,null,`保存`),cancelText:i(`common.cancel`,null,`取消`),children:(0,z.jsxs)(`div`,{className:`mcp-management-form`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-form-head`,children:[(0,z.jsx)(B,{type:`tertiary`,children:_?`编辑模式下只提交当前名称的配置;external_mcp_enable 由启停按钮维护。`:`支持一次粘贴多个 MCP:{"name": {...}};保存后逐个写入 config.yaml。`}),!_&&(0,z.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>D(JSON.stringify(V,null,2)),children:`载入示例`}),T&&(0,z.jsx)(E,{text:T,size:`small`})]}),(0,z.jsx)(l,{className:`mcp-management-json`,rows:16,value:T,spellCheck:!1,placeholder:`{"my-http-server": {"type": "http", "url": "https://mcp.example.com/mcp"}}`,onChange:e=>{D(e),k&&P(``)}}),k&&(0,z.jsx)(`div`,{className:`mcp-management-form-error`,children:k})]})})]})}var{Text:W}=i;function G({canWrite:e,refreshKey:t=0}){let n=g(),[r,i]=(0,N.useState)(1),[l,f]=(0,N.useState)(20),[_,y]=(0,N.useState)(``),S=T(_,350),[E,D]=(0,N.useState)(`all`),[O,j]=(0,N.useState)(!0),[M,P]=(0,N.useState)({}),[F,I]=(0,N.useState)(!1),B=(0,N.useRef)(new Map),V=b(()=>v.get(`/config/tools`,{page:r,page_size:l,search:S,tool_filter:E===`all`?``:E,include_external:O?``:`0`}),[r,l,S,E,O,t]),H=V.data?.tools||[],U=Number(V.data?.total)||0,G=(0,N.useDeferredValue)(H);(0,N.useEffect)(()=>{(H||[]).forEach(e=>B.current.set(L(e),e))},[H]);let K=(0,N.useMemo)(()=>Object.keys(M),[M]),q=(0,N.useCallback)(e=>Object.prototype.hasOwnProperty.call(M,L(e))?M[L(e)]:e.enabled,[M]),J=(0,N.useCallback)((e,t)=>{let n=L(e);P(r=>{let i={...r};return t===e.enabled?delete i[n]:i[n]=t,i})},[]),Y=(0,N.useCallback)(e=>{P(t=>{let n={...t};return(H||[]).forEach(t=>{let r=L(t);t.enabled===e?delete n[r]:n[r]=e}),n})},[H]),X=(0,N.useCallback)(()=>P({}),[]),Z=(0,N.useCallback)(async()=>{let e=Object.entries(M);if(e.length){I(!0);try{let t=e.map(([e,t])=>{let n=B.current.get(e);return{name:n?.name||e.split(`::`).pop()||e,enabled:t,is_external:!!n?.is_external,external_mcp:n?.external_mcp||``}});await v.put(`/config`,{tools:t}),await v.post(`/config/apply`,{}),A(n(`mcp.toolsConfigSaved`,null,`工具配置已成功保存`)),P({}),V.reload({silent:!0})}catch(e){x(e,n(`mcp.saveToolsConfigFailed`,null,`保存工具配置失败`))}finally{I(!1)}}},[M,V.reload,n]),Q=[{title:n(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`name`,render:e=>(0,z.jsx)(`span`,{className:`mcp-management-mono mcp-management-tool-name`,children:e})},{title:`来源`,dataIndex:`is_external`,width:180,render:(e,t)=>(0,z.jsx)(o,{size:`small`,color:e?`blue`:`grey`,children:R(t)})},{title:n(`mcp.filterEnabled`,null,`已启用`),dataIndex:`enabled`,width:110,render:(t,n)=>(0,z.jsx)(d,{size:`small`,checked:q(n),disabled:!e,onChange:e=>J(n,e)})},{title:n(`mcp.description`,null,`描述`),dataIndex:`description`,render:e=>(0,z.jsx)(W,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:560},children:e||n(`mcp.noDescription`,null,`暂无描述`)})}],$={currentPage:r,pageSize:l,total:U,showSizeChanger:!0,pageSizeOpts:[20,50,100],showTotal:!0,onPageChange:e=>i(e),onPageSizeChange:e=>{f(e),i(1)}},ee=[{value:`all`,label:n(`mcp.filterAll`,null,`全部`)},{value:`on`,label:n(`mcp.filterEnabled`,null,`已启用`)},{value:`off`,label:n(`mcp.filterDisabled`,null,`已停用`)}];return(0,z.jsxs)(w,{title:n(`mcp.toolConfig`,null,`MCP 工具配置`),description:`${n(`mcp.currentPageEnabled`,null,`当前页已启用`)} ${(G||[]).filter(e=>q(e)).length} / ${G.length} · ${n(`mcp.totalEnabled`,null,`已启用工具总数`)} ${V.data?.total_enabled??`—`}`,extra:(0,z.jsxs)(a,{spacing:8,children:[K.length>0&&(0,z.jsx)(o,{size:`small`,color:`amber`,children:`未保存 ${K.length} 项`}),K.length>0&&(0,z.jsx)(c,{size:`small`,theme:`borderless`,onClick:X,disabled:F,children:`放弃修改`}),(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(m,{}),theme:`borderless`,onClick:()=>V.reload(),loading:V.loading,children:n(`common.refresh`,null,`刷新`)}),(0,z.jsx)(c,{size:`small`,theme:`solid`,disabled:!e||!K.length,loading:F,onClick:Z,children:n(`mcp.saveToolConfig`,null,`保存工具配置`)})]}),children:[(0,z.jsx)(C,{error:V.error,onRetry:()=>V.reload()}),(0,z.jsx)(k,{columns:Q,dataSource:H,rowKey:e=>L(e),loading:V.loading,pagination:$,size:`small`,emptyText:n(`mcp.noTools`,null,`暂无工具`),toolbar:(0,z.jsxs)(a,{spacing:8,wrap:!0,children:[(0,z.jsx)(u,{prefix:(0,z.jsx)(p,{}),showClear:!0,style:{width:240},value:_,placeholder:n(`mcp.toolSearchPlaceholder`,null,`搜索工具…`),onChange:e=>{y(e),i(1)}}),(0,z.jsx)(h,{value:E,style:{width:140},optionList:ee,onChange:e=>{D(e),i(1)}}),(0,z.jsx)(s,{checked:O,onChange:e=>{j(e.target.checked),i(1)},children:`包含外部 MCP 工具`}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>Y(!0),children:n(`mcp.selectAll`,null,`全选`)}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>Y(!1),children:n(`mcp.deselectAll`,null,`全不选`)})]})}),(0,z.jsx)(`p`,{className:`mcp-management-hint`,children:`保存只提交本次改动的工具项;应用后由后端重新注册 MCP 工具。直接注册(未写入 config.yaml)的工具切换不会落盘。`})]})}function K(){let e=g(),{hasPermission:t}=_(),n=t(`mcp:write`),[r,i]=(0,N.useState)(0),o=b(()=>v.get(`/external-mcp/stats`),[r]),s=o.data||{},l=(0,N.useCallback)(()=>{i(e=>e+1),o.reload({silent:!0})},[o.reload]);return(0,z.jsxs)(`div`,{className:`mcp-management-page`,children:[(0,z.jsx)(D,{title:e(`mcp.managementTitle`,null,`MCP 管理`),description:`维护外部 MCP 连接与工具启用状态;改动写入 config.yaml 后立即生效。`,extra:(0,z.jsx)(a,{children:(0,z.jsx)(c,{icon:(0,z.jsx)(m,{}),onClick:l,loading:o.loading,children:e(`common.refresh`,null,`刷新`)})})}),(0,z.jsx)(y,{columns:4,metrics:[{id:`total`,label:e(`mcp.totalCount`,null,`总数`),value:o.error?`—`:s.total??0,detail:e(`mcp.externalConfig`,null,`外部 MCP 配置`),loading:o.loading&&!o.data},{id:`enabled`,label:e(`mcp.enabledCount`,null,`已启用`),value:o.error?`—`:s.enabled??0,tone:`success`,loading:o.loading&&!o.data},{id:`connected`,label:e(`mcp.connectedCount`,null,`已连接`),value:o.error?`—`:s.connected??0,tone:s.connected>0?`success`:void 0,loading:o.loading&&!o.data},{id:`disabled`,label:e(`mcp.disabledCount`,null,`已停用`),value:o.error?`—`:s.disabled??0,loading:o.loading&&!o.data}]}),(0,z.jsx)(C,{error:o.error,onRetry:l}),(0,z.jsx)(U,{canWrite:n,onChanged:l,refreshKey:r}),(0,z.jsx)(G,{canWrite:n,refreshKey:r})]})}export{K as default};
\ No newline at end of file
diff --git a/web/static/app/assets/mcp-monitor-Da5IyxS4.js b/web/static/app/assets/mcp-monitor-Da5IyxS4.js
deleted file mode 100644
index f5abd1dd..00000000
--- a/web/static/app/assets/mcp-monitor-Da5IyxS4.js
+++ /dev/null
@@ -1 +0,0 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{B as i,G as a,I as o,N as s,R as c,S as l,T as u,U as d,W as f,lt as p,p as m,ut as h,y as g}from"./semi-65W_4I1v.js";import{D as _,E as v,F as y,I as b,O as x,P as S,S as ee,_ as C,a as w,b as T,d as E,g as D,i as te,l as O,m as k,n as ne,o as A,p as re,r as j,s as M,u as N,x as P,y as ie}from"./index-BdnarFZR.js";var F=e(t(),1),I=[`completed`,`running`,`queued`,`failed`,`blocked`,`hard_timeout`,`cancelled`,`orphaned`],L={pending:`statusPending`,queued:`statusQueued`,running:`statusRunning`,completed:`statusCompleted`,failed:`statusFailed`,blocked:`statusBlocked`,cancelled:`statusCancelled`,hard_timeout:`statusHardTimeout`,orphaned:`statusOrphaned`},R={pending:`等待中`,queued:`排队中`,running:`执行中`,completed:`已完成`,failed:`失败`,blocked:`已拦截`,cancelled:`已终止`,hard_timeout:`执行超时`,orphaned:`孤儿任务`},z={completed:`green`,running:`blue`,queued:`amber`,failed:`red`,blocked:`orange`,hard_timeout:`red`,cancelled:`grey`,orphaned:`grey`};function B(e){return String(e||``).trim().toLowerCase()}function V(e,t){let n=B(t),r=L[n];return r?e(`mcpMonitor.${r}`,null,R[n]||n):t||`—`}function H(e){return z[B(e)]||`grey`}function U(e){return B(e)===`running`}function W(e){let t=String(e||``).trim();return t?t.includes(`::`)?t.replace(/::/g,`__`):t:``}function G(e){if(!e)return null;let t=Number(e.duration);if(Number.isFinite(t)&&t>0)return t/1e6;let n=e.startTime?new Date(e.startTime).getTime():NaN,r=e.endTime?new Date(e.endTime).getTime():NaN;return Number.isFinite(n)&&Number.isFinite(r)&&r>=n?r-n:null}function K(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return`—`;if(t<1e3)return`${Math.round(t)} ms`;if(t<6e4)return`${(t/1e3).toFixed(2)} s`;let n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return n<60?`${n} 分 ${r} 秒`:`${Math.floor(n/60)} 小时 ${n%60} 分`}function q(e){if(!e)return null;let t=(Number(e.totalCalls)||0)-(Number(e.blockedCalls)||0);return t<=0?null:(Number(e.successCalls)||0)/t}function J(e,t=1){return e==null||!Number.isFinite(Number(e))?`—`:`${(Number(e)*100).toFixed(t)}%`}function ae(e){let t=(e||[]).map(G).filter(e=>Number.isFinite(e)&&e>=0);return t.length?t.reduce((e,t)=>e+t,0)/t.length:null}function Y(e,t){let n=new Date(e);if(!Number.isFinite(n.getTime()))return``;let r=e=>String(e).padStart(2,`0`),i=`${r(n.getMonth()+1)}-${r(n.getDate())}`;return t===`30d`?i:t===`7d`?`${i} ${r(n.getHours())}h`:`${r(n.getHours())}:00`}function X(e,t){let n=e?.t?new Date(e.t).toLocaleString(`zh-CN`,{hour12:!1}):`—`;return t(`mcpMonitor.timelineTooltip`,{time:n,total:e?.total||0,failed:e?.failed||0,blocked:e?.blocked||0},`${n} 总调用 ${e?.total||0},失败 ${e?.failed||0},拦截 ${e?.blocked||0}`)}var Z=e(n(),1);function oe({summary:e,loading:t,avgMs:n=null,avgSamples:r=0}){let i=S(),a=q(e);return(0,Z.jsx)(C,{columns:4,metrics:[{id:`calls`,label:i(`mcpMonitor.totalCalls`,null,`调用次数`),value:e?e.totalCalls??0:`—`,detail:e?i(`mcpMonitor.statsFromAllTools`,null,`全部工具累计,含已拦截调用`):void 0,loading:t},{id:`rate`,label:i(`mcpMonitor.successRate`,null,`成功率`),value:J(a),detail:e?`${i(`common.ok`,null,`成功`)} ${e.successCalls??0} / ${i(`mcpMonitor.failedColumn`,null,`失败`)} ${e.failedCalls??0}`:void 0,tone:a===null?void 0:a>=.95?`success`:a>=.8?`warning`:`danger`,loading:t},{id:`avg`,label:`平均耗时`,value:n===null?`—`:K(n),detail:r>0?`按当前页 ${r} 条计时记录估算`:`当前页暂无可计时的执行记录`,loading:t},{id:`failed`,label:i(`mcpMonitor.failedMetric`,null,`失败数`),value:e?e.failedCalls??0:`—`,detail:e?`${i(`mcpMonitor.blockedCount`,{n:e.blockedCalls??0},`安全拦截 ${e.blockedCalls??0}`)} · ${i(`mcpMonitor.lastCall`,null,`最近调用`)} ${e.lastCallTime?v(e.lastCallTime):`—`}`:void 0,tone:e&&e.failedCalls>0?`danger`:void 0,loading:t}]})}function se({topTools:e,loading:t,onFilterTool:n,activeTool:r}){let i=S(),a=(0,F.useMemo)(()=>(e||[]).map(e=>{let t=Number(e.totalCalls)||0,n=Number(e.blockedCalls)||0,r=Number(e.successCalls)||0,i=t-n;return{...e,key:e.toolName,displayName:W(e.toolName),rate:i>0?r/i:null}}),[e]),o=[{title:i(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`displayName`,render:(e,t)=>(0,Z.jsx)(`button`,{type:`button`,className:`mcp-monitor-tool-link ${r&&r===t.toolName?`mcp-monitor-link-active`:``}`,onClick:()=>n?.(t.toolName),children:e||i(`mcpMonitor.unknownTool`,null,`未知工具`)})},{title:i(`mcpMonitor.columnCalls`,null,`调用`),dataIndex:`totalCalls`,width:90,render:e=>e??0},{title:i(`mcpMonitor.successColumn`,null,`成功`),dataIndex:`successCalls`,width:90,render:e=>e??0},{title:i(`mcpMonitor.failedColumn`,null,`失败`),dataIndex:`failedCalls`,width:90,render:e=>(0,Z.jsx)(`span`,{className:e>0?`mcp-monitor-danger`:void 0,children:e??0})},{title:i(`mcpMonitor.blockedColumn`,null,`拦截`),dataIndex:`blockedCalls`,width:90,render:e=>e?(0,Z.jsx)(s,{size:`small`,color:`orange`,children:e}):0},{title:i(`mcpMonitor.columnSuccessRate`,null,`成功率`),dataIndex:`rate`,width:110,render:e=>e===null?`—`:x(e,1)}];return(0,Z.jsx)(k,{title:i(`mcpMonitor.toolStatsTitle`,null,`工具统计`),description:i(`mcpMonitor.toolStatsHint`,null,`点击工具名筛选下方执行记录`),children:(0,Z.jsx)(M,{columns:o,dataSource:a,rowKey:`key`,loading:t,pagination:!1,size:`small`,emptyText:i(`mcpMonitor.noStatsData`,null,`暂无统计数据`)})})}var ce=[{value:`24h`,labelKey:`timelineRange24h`,fallback:`24 小时`},{value:`7d`,labelKey:`timelineRange7d`,fallback:`7 天`},{value:`30d`,labelKey:`timelineRange30d`,fallback:`30 天`}];function le({data:e,loading:t,error:n,range:r,onRangeChange:i,onRetry:a}){let o=S(),s=Array.isArray(e?.points)?e.points:[],c=e?.summary||{},l=Number(c.peak)||0,u=(0,F.useMemo)(()=>s.reduce((e,t)=>Math.max(e,Number(t.total)||0),0),[s]),d=Number(c.totalCalls)||0,f=Math.max(1,Math.ceil(s.length/8)),p=ce.map(e=>({value:e.value,label:o(`mcpMonitor.${e.labelKey}`,null,e.fallback)}));return(0,Z.jsxs)(k,{title:o(`mcpMonitor.timelineTitle`,null,`调用趋势`),description:o(`mcpMonitor.timelineHint`,null,`全部工具合计,失败与拦截单独着色`),extra:(0,Z.jsx)(g,{size:`small`,value:r,optionList:p,style:{width:120},onChange:i}),children:[(0,Z.jsx)(O,{error:n,onRetry:a}),(0,Z.jsxs)(`div`,{className:`mcp-monitor-timeline-summary`,children:[(0,Z.jsx)(D,{label:o(`mcpMonitor.timelineTotalLegend`,null,`总调用`),value:_(d),loading:t}),(0,Z.jsx)(D,{label:`峰值 / 桶`,value:_(l),detail:o(`mcpMonitor.scopeTimeline`,null,`当前时间范围`),loading:t}),(0,Z.jsxs)(`div`,{className:`mcp-monitor-timeline-legend`,children:[(0,Z.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,Z.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-total`}),o(`mcpMonitor.timelineTotalLegend`,null,`总调用`)]}),(0,Z.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,Z.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-failed`}),o(`mcpMonitor.timelineFailedLegend`,null,`失败`)]}),(0,Z.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,Z.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-blocked`}),o(`mcpMonitor.timelineBlockedLegend`,null,`安全拦截`)]})]})]}),t&&!s.length?(0,Z.jsx)(`div`,{className:`mcp-monitor-timeline-empty`,children:o(`mcpMonitor.timelineLoading`,null,`趋势加载中…`)}):d===0||u===0?(0,Z.jsxs)(`div`,{className:`mcp-monitor-timeline-empty`,children:[(0,Z.jsx)(`p`,{children:o(`mcpMonitor.timelineNoData`,null,`该时段暂无调用`)}),(0,Z.jsx)(`p`,{className:`mcp-monitor-timeline-hint`,children:o(`mcpMonitor.timelineEmptyHint`,null,`调用 MCP 工具后此处会出现趋势`)})]}):(0,Z.jsx)(`div`,{className:`mcp-monitor-timeline-chart`,role:`img`,"aria-label":o(`mcpMonitor.timelineTitle`,null,`调用趋势`),children:s.map((e,t)=>{let n=Number(e.total)||0,i=Number(e.failed)||0,a=Number(e.blocked)||0,s=n>0?Math.max(3,n/u*100):0,c=n>0?i/n*100:0,l=n>0?a/n*100:0,d=Y(e.t,r);return(0,Z.jsxs)(`div`,{className:`mcp-monitor-timeline-slot`,title:X(e,o),children:[(0,Z.jsx)(`div`,{className:`mcp-monitor-timeline-bar-wrap`,children:(0,Z.jsxs)(`div`,{className:`mcp-monitor-timeline-bar`,style:{height:`${s}%`},children:[l>0&&(0,Z.jsx)(`span`,{className:`mcp-monitor-timeline-seg mcp-monitor-seg-blocked`,style:{height:`${l}%`}}),c>0&&(0,Z.jsx)(`span`,{className:`mcp-monitor-timeline-seg mcp-monitor-seg-failed`,style:{height:`${c}%`}})]})}),(0,Z.jsx)(`span`,{className:`mcp-monitor-timeline-tick`,children:t%f===0?d:``})]},e.t||t)})})]})}function Q({status:e}){let t=S();return(0,Z.jsx)(s,{size:`small`,color:H(e),shape:`square`,children:V(t,e)})}function ue({data:e,loading:t,error:n,page:r,pageSize:i,status:a,toolInput:s,selected:l,onQuery:u,onPageChange:f,onRefresh:m,onOpenDetail:h,onCancel:_,onDelete:y,onSelectionChange:b,canWrite:x,canDelete:ee}){let C=S(),w=e?.executions||[],T=Number(e?.total)||0,E=[{value:`all`,label:C(`mcp.filterAll`,null,`全部`)},...I.map(e=>({value:e,label:V(C,e)}))],D=[{title:C(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`toolName`,render:e=>(0,Z.jsx)(`span`,{className:`mcp-monitor-cell-tool`,children:W(e)||C(`mcpMonitor.unknownTool`,null,`未知工具`)})},{title:C(`mcpMonitor.columnStatus`,null,`状态`),dataIndex:`status`,width:110,render:e=>(0,Z.jsx)(Q,{status:e})},{title:C(`mcpMonitor.columnStartTime`,null,`开始时间`),dataIndex:`startTime`,width:180,render:e=>v(e)},{title:C(`mcpMonitor.columnDuration`,null,`耗时`),dataIndex:`duration`,width:110,render:(e,t)=>K(G(t))},{title:C(`common.actions`,null,`操作`),dataIndex:`id`,width:230,render:(e,t)=>(0,Z.jsxs)(o,{spacing:4,wrap:!0,children:[(0,Z.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>h(e),children:C(`mcpMonitor.viewDetail`,null,`详情`)}),U(t.status)&&(0,Z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!x,onClick:()=>_(t),children:C(`mcpMonitor.terminateExecution`,null,`终止`)}),(0,Z.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,disabled:!ee,onClick:()=>y(t),children:C(`common.delete`,null,`删除`)})]})}];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(O,{error:n,onRetry:m}),(0,Z.jsx)(M,{columns:D,dataSource:w,rowKey:`id`,loading:t,pagination:{currentPage:r,pageSize:i,total:T,showSizeChanger:!0,pageSizeOpts:[20,50,100],showTotal:!0,onPageChange:e=>f(e,i),onPageSizeChange:e=>f(1,e)},onRefresh:m,emptyText:C(`mcpMonitor.noExecutions`,null,`暂无执行记录`),rowSelection:{selectedRowKeys:l,onChange:e=>b(e||[])},toolbar:(0,Z.jsxs)(o,{spacing:8,wrap:!0,children:[(0,Z.jsx)(d,{prefix:(0,Z.jsx)(p,{}),value:s,showClear:!0,style:{width:220},placeholder:C(`mcp.toolSearchPlaceholder`,null,`输入工具名称…`),onChange:e=>u({toolInput:e})}),(0,Z.jsx)(g,{value:a,style:{width:150},optionList:E,onChange:e=>u({status:e})})]})})]})}var{Text:$}=a;function de({executionId:e,onClose:t,canWrite:n,onCancelRequest:r}){let a=S(),{data:s,loading:l,error:u,reload:d}=w(()=>b.get(`/monitor/execution/${encodeURIComponent(e)}`),[e],{skip:!e}),p=e?s:null,h=p?U(p.status):!1;return(0,Z.jsxs)(m,{visible:!!e,onCancel:t,title:a(`mcpMonitor.viewDetail`,null,`执行详情`),width:720,footer:p?(0,Z.jsxs)(o,{children:[h&&(0,Z.jsx)(c,{theme:`solid`,disabled:!n,onClick:()=>r(p),children:a(`mcpMonitor.terminateExecution`,null,`终止`)}),(0,Z.jsx)(c,{onClick:t,children:a(`common.close`,null,`关闭`)})]}):null,children:[!p&&l&&(0,Z.jsx)(`div`,{className:`mcp-monitor-detail-loading`,children:(0,Z.jsx)(f,{})}),(0,Z.jsx)(O,{error:u,onRetry:d}),p&&(0,Z.jsxs)(`div`,{className:`mcp-monitor-detail`,children:[(0,Z.jsx)(E,{columns:2,items:[{label:`工具`,value:(0,Z.jsx)($,{strong:!0,children:W(p.toolName)||`—`})},{label:a(`mcpMonitor.columnStatus`,null,`状态`),value:(0,Z.jsx)(Q,{status:p.status})},{label:`执行 ID`,value:(0,Z.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.id})},{label:a(`mcpMonitor.columnStartTime`,null,`开始时间`),value:v(p.startTime)},{label:`结束时间`,value:p.endTime?v(p.endTime):`—`},{label:a(`mcpMonitor.columnDuration`,null,`耗时`),value:K(G(p))},{label:`关联会话`,value:p.conversationId?(0,Z.jsxs)(o,{spacing:4,children:[(0,Z.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.conversationId}),(0,Z.jsx)(A,{text:p.conversationId,size:`small`})]}):`—`},{label:`结果状态`,value:p.result?p.result.isError?`错误结果`:p.result.blocked?`已拦截`:`正常返回`:`无返回`}]}),p.error&&(0,Z.jsx)(i,{type:`danger`,className:`mcp-monitor-detail-error`,description:(0,Z.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.error})}),(0,Z.jsx)(`div`,{className:`mcp-monitor-detail-section`,children:(0,Z.jsx)(N,{title:a(`mcpDetailModal.requestParams`,null,`入参`),value:p.arguments??{}})}),(0,Z.jsx)(`div`,{className:`mcp-monitor-detail-section`,children:p.result?(0,Z.jsx)(N,{title:a(`mcpDetailModal.responseResult`,null,`出参`),value:p.result}):(0,Z.jsx)(`div`,{className:`mcp-monitor-detail-empty`,children:h?a(`mcpDetailModal.runningNoResponseYet`,null,`尚无返回,工具可能仍在执行。`):a(`chat.noResponseData`,null,`暂无响应数据`)})}),p.partialOutput&&(0,Z.jsxs)(`div`,{className:`mcp-monitor-detail-section`,children:[(0,Z.jsxs)(`div`,{className:`mcp-monitor-detail-section-head`,children:[(0,Z.jsx)($,{strong:!0,children:`实时输出尾部`}),(0,Z.jsxs)(o,{spacing:4,children:[p.partialOutputBytes?(0,Z.jsxs)($,{type:`tertiary`,children:[p.partialOutputBytes,` B`]}):null,(0,Z.jsx)(A,{text:p.partialOutput,size:`small`})]})]}),(0,Z.jsx)(`pre`,{className:`mcp-monitor-detail-pre`,children:p.partialOutput})]}),(0,Z.jsxs)(`div`,{className:`mcp-monitor-detail-footnote`,children:[V(a,p.status),` · `,a(`mcpMonitor.statsFromAllTools`,null,`全部工具累计`)]})]})]})}function fe(){let e=S(),{hasPermission:t}=y(),[n,i]=r(),a=t(`monitor:write`)||t(`mcp:write`),s=t(`monitor:delete`),[d,f]=(0,F.useState)(1),[p,m]=(0,F.useState)(20),[g,_]=(0,F.useState)(`all`),[v,x]=(0,F.useState)(``),C=ne(v,350),[E,D]=(0,F.useState)([]),[O,A]=te(`mcp-monitor-timeline-range`,`7d`),[M,N]=(0,F.useState)(null),[I,L]=(0,F.useState)(``),[R,z]=(0,F.useState)(!1),B=n.get(`id`)||``,V=[`24h`,`7d`,`30d`].includes(O)?O:`7d`,H=w(()=>b.get(`/monitor`,{page:d,page_size:p,status:g===`all`?``:g,tool:C}),[d,p,g,C]),U=w(()=>b.get(`/monitor/stats`,{top:12}),[]),K=w(()=>b.get(`/monitor/calls-timeline`,{range:V}),[V]),q=H.data?.executions||[],J=U.data?.summary||H.data?.summary||null,Y=U.data?.topTools||H.data?.topTools||[],X=Number(H.data?.retentionDays)||0,ce=(0,F.useMemo)(()=>q.filter(e=>G(e)!==null).length,[q]),Q=(0,F.useMemo)(()=>ae(q),[q]);j(()=>{typeof document<`u`&&document.hidden||(H.reload({silent:!0}),K.reload({silent:!0}))},5e3),j(()=>{typeof document<`u`&&document.hidden||U.reload({silent:!0})},2e4);let $=(0,F.useCallback)(()=>{H.reload(),U.reload({silent:!0}),K.reload({silent:!0})},[H.reload,U.reload,K.reload]),fe=(0,F.useCallback)(e=>{let t=new URLSearchParams(n);t.set(`id`,e),i(t,{replace:!0})},[n,i]),pe=(0,F.useCallback)(()=>{let e=new URLSearchParams(n);e.delete(`id`),i(e,{replace:!0})},[n,i]),me=(0,F.useCallback)(e=>{Object.prototype.hasOwnProperty.call(e,`toolInput`)&&x(e.toolInput),e.status!==void 0&&_(e.status),f(1),D([])},[]),he=(0,F.useCallback)((e,t)=>{f(e),t&&t!==p&&m(t)},[p]),ge=(0,F.useCallback)(e=>{x(W(e)),f(1),D([])},[]),_e=(0,F.useCallback)(t=>{ie({title:e(`mcpMonitor.deleteExecTitle`,null,`删除此执行记录`),content:`确定删除 ${W(t.toolName)||`该`} 的执行记录?此操作不可恢复。`,okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await b.del(`/monitor/execution/${encodeURIComponent(t.id)}`),D(e=>e.filter(e=>e!==t.id)),P(e(`mcpMonitor.execDeleted`,null,`执行记录已删除`)),$()}catch(t){T(t,e(`mcpMonitor.deleteExecFailed`,null,`删除执行记录失败`))}}})},[$,e]),ve=(0,F.useCallback)(async()=>{if(!E.length){ee(e(`mcpMonitor.selectExecFirst`,null,`请先选择要删除的执行记录`));return}let t=[];try{let e=await b.post(`/monitor/executions/names`,{ids:E});t=[...new Set(Object.values(e||{}).map(e=>W(e?.toolName)).filter(Boolean))]}catch{t=[]}let n=t.length?`涉及工具:${t.slice(0,3).join(`、`)}${t.length>3?` 等`:``}。`:``;ie({title:e(`mcpMonitor.batchDeleteConfirm`,{count:E.length},`确定删除选中的 ${E.length} 条执行记录?`),content:`${n}此操作不可恢复。`,okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await b.del(`/monitor/executions`,{body:{ids:E}}),P(`已删除 ${E.length} 条执行记录`),D([]),$()}catch(t){T(t,e(`mcp.batchDeleteFailed`,null,`批量删除执行记录失败`))}}})},[$,E,e]),ye=(0,F.useCallback)(e=>{N(e),L(``)},[]),be=(0,F.useCallback)(async()=>{if(M?.id){z(!0);try{await b.post(`/monitor/execution/${encodeURIComponent(M.id)}/cancel`,{note:I.trim()}),P(e(`mcpDetailModal.abortSuccess`,null,`已发送终止请求`)),N(null),$()}catch(t){T(t,e(`mcpDetailModal.abortFailed`,null,`终止失败`))}finally{z(!1)}}},[I,M,$,e]),xe=X>0?e(`mcpMonitor.retentionHint`,{days:X},`执行记录保留 ${X} 天,失败与拦截调用单独标记。`):`统计全部 MCP 工具调用,失败与拦截调用单独标记。`;return(0,Z.jsxs)(`div`,{className:`mcp-monitor-page`,children:[(0,Z.jsx)(re,{title:e(`mcp.monitorTitle`,null,`MCP 状态监控`),description:xe,extra:(0,Z.jsx)(o,{children:(0,Z.jsx)(c,{icon:(0,Z.jsx)(h,{}),onClick:$,loading:H.loading||U.loading,children:e(`common.refresh`,null,`刷新`)})})}),(0,Z.jsx)(oe,{summary:J,loading:U.loading&&!J,avgMs:Q,avgSamples:ce}),(0,Z.jsx)(le,{data:K.data,loading:K.loading,error:K.error,range:V,onRangeChange:e=>{e&&A(e)},onRetry:()=>K.reload()}),(0,Z.jsx)(se,{topTools:Y,loading:U.loading&&!Y.length,onFilterTool:ge,activeTool:C}),(0,Z.jsx)(k,{title:e(`mcp.latestExecutions`,null,`最新执行记录`),description:e(`mcpMonitor.emptyHint`,null,`在对话或任务中调用 MCP 工具后,执行记录将显示在此处`),extra:E.length>0?(0,Z.jsxs)(o,{spacing:8,children:[(0,Z.jsx)(`span`,{className:`mcp-monitor-selected`,children:e(`mcp.selectedCount`,{count:E.length},`已选择 ${E.length} 项`)}),(0,Z.jsx)(c,{size:`small`,disabled:!s,type:`danger`,onClick:ve,children:e(`mcp.deleteSelected`,null,`批量删除`)}),(0,Z.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>D([]),children:e(`mcpMonitor.deselectAll`,null,`取消全选`)})]}):null,children:(0,Z.jsx)(ue,{data:H.data,loading:H.loading,error:H.error,page:d,pageSize:p,status:g,toolInput:v,selected:E,onQuery:me,onPageChange:he,onRefresh:()=>H.reload(),onOpenDetail:fe,onCancel:ye,onDelete:_e,onSelectionChange:D,canWrite:a,canDelete:s})}),(0,Z.jsx)(de,{executionId:B,onClose:pe,canWrite:a,onCancelRequest:e=>{pe(),ye(e)}}),(0,Z.jsxs)(u,{title:e(`mcpMonitor.terminateExecution`,null,`终止执行`),visible:!!M,confirmLoading:R,maskClosable:!R,okText:e(`mcpMonitor.terminateExecution`,null,`终止`),cancelText:e(`common.cancel`,null,`取消`),onCancel:()=>N(null),onOk:be,children:[(0,Z.jsx)(`p`,{className:`mcp-monitor-cancel-hint`,children:e(`mcpDetailModal.abortHint`,null,`终止仅取消本次工具调用,不会停止整条对话;说明会与工具输出一起交给模型。`)}),(0,Z.jsx)(l,{rows:4,value:I,placeholder:e(`mcpDetailModal.abortNotePlaceholder`,null,`终止说明(可选),例如:命令执行时间过长,先终止。`),onChange:e=>L(e)})]})]})}export{fe as default};
\ No newline at end of file
diff --git a/web/static/app/assets/mcp-monitor-Du61ugEZ.js b/web/static/app/assets/mcp-monitor-Du61ugEZ.js
new file mode 100644
index 00000000..a15c1a86
--- /dev/null
+++ b/web/static/app/assets/mcp-monitor-Du61ugEZ.js
@@ -0,0 +1 @@
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{B as i,G as a,I as o,N as s,R as c,S as l,T as u,U as d,W as f,lt as p,p as m,ut as h,y as g}from"./semi-65W_4I1v.js";import{D as _,E as v,F as y,I as b,L as x,O as S,S as ee,_ as C,a as w,b as T,d as E,g as D,i as te,l as O,m as k,n as ne,o as A,p as re,r as ie,s as j,u as M,x as N,y as ae}from"./index-_8d9XBPJ.js";var P=e(t(),1),F=[`completed`,`running`,`queued`,`failed`,`blocked`,`hard_timeout`,`cancelled`,`orphaned`],I={pending:`statusPending`,queued:`statusQueued`,running:`statusRunning`,completed:`statusCompleted`,failed:`statusFailed`,blocked:`statusBlocked`,cancelled:`statusCancelled`,hard_timeout:`statusHardTimeout`,orphaned:`statusOrphaned`},L={pending:`等待中`,queued:`排队中`,running:`执行中`,completed:`已完成`,failed:`失败`,blocked:`已拦截`,cancelled:`已终止`,hard_timeout:`执行超时`,orphaned:`孤儿任务`},R={completed:`green`,running:`blue`,queued:`amber`,failed:`red`,blocked:`orange`,hard_timeout:`red`,cancelled:`grey`,orphaned:`grey`};function z(e){return String(e||``).trim().toLowerCase()}function B(e,t){let n=z(t),r=I[n];return r?e(`mcpMonitor.${r}`,null,L[n]||n):t||`—`}function V(e){return R[z(e)]||`grey`}function H(e){return z(e)===`running`}function U(e){let t=String(e||``).trim();return t?t.includes(`::`)?t.replace(/::/g,`__`):t:``}function W(e){if(!e)return null;let t=Number(e.duration);if(Number.isFinite(t)&&t>0)return t/1e6;let n=e.startTime?new Date(e.startTime).getTime():NaN,r=e.endTime?new Date(e.endTime).getTime():NaN;return Number.isFinite(n)&&Number.isFinite(r)&&r>=n?r-n:null}function G(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return`—`;if(t<1e3)return`${Math.round(t)} ms`;if(t<6e4)return`${(t/1e3).toFixed(2)} s`;let n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return n<60?`${n} 分 ${r} 秒`:`${Math.floor(n/60)} 小时 ${n%60} 分`}function K(e){if(!e)return null;let t=(Number(e.totalCalls)||0)-(Number(e.blockedCalls)||0);return t<=0?null:(Number(e.successCalls)||0)/t}function q(e,t=1){return e==null||!Number.isFinite(Number(e))?`—`:`${(Number(e)*100).toFixed(t)}%`}function oe(e){let t=(e||[]).map(W).filter(e=>Number.isFinite(e)&&e>=0);return t.length?t.reduce((e,t)=>e+t,0)/t.length:null}function J(e,t){let n=new Date(e);if(!Number.isFinite(n.getTime()))return``;let r=e=>String(e).padStart(2,`0`),i=`${r(n.getMonth()+1)}-${r(n.getDate())}`;return t===`30d`?i:t===`7d`?`${i} ${r(n.getHours())}h`:`${r(n.getHours())}:00`}function Y(e,t){let n=e?.t?new Date(e.t).toLocaleString(`zh-CN`,{hour12:!1}):`—`;return t(`mcpMonitor.timelineTooltip`,{time:n,total:e?.total||0,failed:e?.failed||0,blocked:e?.blocked||0},`${n} 总调用 ${e?.total||0},失败 ${e?.failed||0},拦截 ${e?.blocked||0}`)}var X=e(n(),1);function se({summary:e,loading:t,avgMs:n=null,avgSamples:r=0}){let i=y(),a=K(e);return(0,X.jsx)(C,{columns:4,metrics:[{id:`calls`,label:i(`mcpMonitor.totalCalls`,null,`调用次数`),value:e?e.totalCalls??0:`—`,detail:e?i(`mcpMonitor.statsFromAllTools`,null,`全部工具累计,含已拦截调用`):void 0,loading:t},{id:`rate`,label:i(`mcpMonitor.successRate`,null,`成功率`),value:q(a),detail:e?`${i(`common.ok`,null,`成功`)} ${e.successCalls??0} / ${i(`mcpMonitor.failedColumn`,null,`失败`)} ${e.failedCalls??0}`:void 0,tone:a===null?void 0:a>=.95?`success`:a>=.8?`warning`:`danger`,loading:t},{id:`avg`,label:`平均耗时`,value:n===null?`—`:G(n),detail:r>0?`按当前页 ${r} 条计时记录估算`:`当前页暂无可计时的执行记录`,loading:t},{id:`failed`,label:i(`mcpMonitor.failedMetric`,null,`失败数`),value:e?e.failedCalls??0:`—`,detail:e?`${i(`mcpMonitor.blockedCount`,{n:e.blockedCalls??0},`安全拦截 ${e.blockedCalls??0}`)} · ${i(`mcpMonitor.lastCall`,null,`最近调用`)} ${e.lastCallTime?v(e.lastCallTime):`—`}`:void 0,tone:e&&e.failedCalls>0?`danger`:void 0,loading:t}]})}function ce({topTools:e,loading:t,onFilterTool:n,activeTool:r}){let i=y(),a=(0,P.useMemo)(()=>(e||[]).map(e=>{let t=Number(e.totalCalls)||0,n=Number(e.blockedCalls)||0,r=Number(e.successCalls)||0,i=t-n;return{...e,key:e.toolName,displayName:U(e.toolName),rate:i>0?r/i:null}}),[e]),o=[{title:i(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`displayName`,render:(e,t)=>(0,X.jsx)(`button`,{type:`button`,className:`mcp-monitor-tool-link ${r&&r===t.toolName?`mcp-monitor-link-active`:``}`,onClick:()=>n?.(t.toolName),children:e||i(`mcpMonitor.unknownTool`,null,`未知工具`)})},{title:i(`mcpMonitor.columnCalls`,null,`调用`),dataIndex:`totalCalls`,width:90,render:e=>e??0},{title:i(`mcpMonitor.successColumn`,null,`成功`),dataIndex:`successCalls`,width:90,render:e=>e??0},{title:i(`mcpMonitor.failedColumn`,null,`失败`),dataIndex:`failedCalls`,width:90,render:e=>(0,X.jsx)(`span`,{className:e>0?`mcp-monitor-danger`:void 0,children:e??0})},{title:i(`mcpMonitor.blockedColumn`,null,`拦截`),dataIndex:`blockedCalls`,width:90,render:e=>e?(0,X.jsx)(s,{size:`small`,color:`orange`,children:e}):0},{title:i(`mcpMonitor.columnSuccessRate`,null,`成功率`),dataIndex:`rate`,width:110,render:e=>e===null?`—`:S(e,1)}];return(0,X.jsx)(k,{title:i(`mcpMonitor.toolStatsTitle`,null,`工具统计`),description:i(`mcpMonitor.toolStatsHint`,null,`点击工具名筛选下方执行记录`),children:(0,X.jsx)(j,{columns:o,dataSource:a,rowKey:`key`,loading:t,pagination:!1,size:`small`,emptyText:i(`mcpMonitor.noStatsData`,null,`暂无统计数据`)})})}var le=[{value:`24h`,labelKey:`timelineRange24h`,fallback:`24 小时`},{value:`7d`,labelKey:`timelineRange7d`,fallback:`7 天`},{value:`30d`,labelKey:`timelineRange30d`,fallback:`30 天`}];function ue({data:e,loading:t,error:n,range:r,onRangeChange:i,onRetry:a}){let o=y(),s=Array.isArray(e?.points)?e.points:[],c=e?.summary||{},l=Number(c.peak)||0,u=(0,P.useMemo)(()=>s.reduce((e,t)=>Math.max(e,Number(t.total)||0),0),[s]),d=Number(c.totalCalls)||0,f=Math.max(1,Math.ceil(s.length/8)),p=le.map(e=>({value:e.value,label:o(`mcpMonitor.${e.labelKey}`,null,e.fallback)}));return(0,X.jsxs)(k,{title:o(`mcpMonitor.timelineTitle`,null,`调用趋势`),description:o(`mcpMonitor.timelineHint`,null,`全部工具合计,失败与拦截单独着色`),extra:(0,X.jsx)(g,{size:`small`,value:r,optionList:p,style:{width:120},onChange:i}),children:[(0,X.jsx)(O,{error:n,onRetry:a}),(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-summary`,children:[(0,X.jsx)(D,{label:o(`mcpMonitor.timelineTotalLegend`,null,`总调用`),value:_(d),loading:t}),(0,X.jsx)(D,{label:`峰值 / 桶`,value:_(l),detail:o(`mcpMonitor.scopeTimeline`,null,`当前时间范围`),loading:t}),(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-legend`,children:[(0,X.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,X.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-total`}),o(`mcpMonitor.timelineTotalLegend`,null,`总调用`)]}),(0,X.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,X.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-failed`}),o(`mcpMonitor.timelineFailedLegend`,null,`失败`)]}),(0,X.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,X.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-blocked`}),o(`mcpMonitor.timelineBlockedLegend`,null,`安全拦截`)]})]})]}),t&&!s.length?(0,X.jsx)(`div`,{className:`mcp-monitor-timeline-empty`,children:o(`mcpMonitor.timelineLoading`,null,`趋势加载中…`)}):d===0||u===0?(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-empty`,children:[(0,X.jsx)(`p`,{children:o(`mcpMonitor.timelineNoData`,null,`该时段暂无调用`)}),(0,X.jsx)(`p`,{className:`mcp-monitor-timeline-hint`,children:o(`mcpMonitor.timelineEmptyHint`,null,`调用 MCP 工具后此处会出现趋势`)})]}):(0,X.jsx)(`div`,{className:`mcp-monitor-timeline-chart`,role:`img`,"aria-label":o(`mcpMonitor.timelineTitle`,null,`调用趋势`),children:s.map((e,t)=>{let n=Number(e.total)||0,i=Number(e.failed)||0,a=Number(e.blocked)||0,s=n>0?Math.max(3,n/u*100):0,c=n>0?i/n*100:0,l=n>0?a/n*100:0,d=J(e.t,r);return(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-slot`,title:Y(e,o),children:[(0,X.jsx)(`div`,{className:`mcp-monitor-timeline-bar-wrap`,children:(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-bar`,style:{height:`${s}%`},children:[l>0&&(0,X.jsx)(`span`,{className:`mcp-monitor-timeline-seg mcp-monitor-seg-blocked`,style:{height:`${l}%`}}),c>0&&(0,X.jsx)(`span`,{className:`mcp-monitor-timeline-seg mcp-monitor-seg-failed`,style:{height:`${c}%`}})]})}),(0,X.jsx)(`span`,{className:`mcp-monitor-timeline-tick`,children:t%f===0?d:``})]},e.t||t)})})]})}function Z({status:e}){let t=y();return(0,X.jsx)(s,{size:`small`,color:V(e),shape:`square`,children:B(t,e)})}function de({data:e,loading:t,error:n,page:r,pageSize:i,status:a,toolInput:s,selected:l,onQuery:u,onPageChange:f,onRefresh:m,onOpenDetail:h,onCancel:_,onDelete:b,onSelectionChange:x,canWrite:S,canDelete:ee}){let C=y(),w=e?.executions||[],T=Number(e?.total)||0,E=[{value:`all`,label:C(`mcp.filterAll`,null,`全部`)},...F.map(e=>({value:e,label:B(C,e)}))],D=[{title:C(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`toolName`,render:e=>(0,X.jsx)(`span`,{className:`mcp-monitor-cell-tool`,children:U(e)||C(`mcpMonitor.unknownTool`,null,`未知工具`)})},{title:C(`mcpMonitor.columnStatus`,null,`状态`),dataIndex:`status`,width:110,render:e=>(0,X.jsx)(Z,{status:e})},{title:C(`mcpMonitor.columnStartTime`,null,`开始时间`),dataIndex:`startTime`,width:180,render:e=>v(e)},{title:C(`mcpMonitor.columnDuration`,null,`耗时`),dataIndex:`duration`,width:110,render:(e,t)=>G(W(t))},{title:C(`common.actions`,null,`操作`),dataIndex:`id`,width:230,render:(e,t)=>(0,X.jsxs)(o,{spacing:4,wrap:!0,children:[(0,X.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>h(e),children:C(`mcpMonitor.viewDetail`,null,`详情`)}),H(t.status)&&(0,X.jsx)(c,{size:`small`,theme:`borderless`,disabled:!S,onClick:()=>_(t),children:C(`mcpMonitor.terminateExecution`,null,`终止`)}),(0,X.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,disabled:!ee,onClick:()=>b(t),children:C(`common.delete`,null,`删除`)})]})}];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(O,{error:n,onRetry:m}),(0,X.jsx)(j,{columns:D,dataSource:w,rowKey:`id`,loading:t,pagination:{currentPage:r,pageSize:i,total:T,showSizeChanger:!0,pageSizeOpts:[20,50,100],showTotal:!0,onPageChange:e=>f(e,i),onPageSizeChange:e=>f(1,e)},onRefresh:m,emptyText:C(`mcpMonitor.noExecutions`,null,`暂无执行记录`),rowSelection:{selectedRowKeys:l,onChange:e=>x(e||[])},toolbar:(0,X.jsxs)(o,{spacing:8,wrap:!0,children:[(0,X.jsx)(d,{prefix:(0,X.jsx)(p,{}),value:s,showClear:!0,style:{width:220},placeholder:C(`mcp.toolSearchPlaceholder`,null,`输入工具名称…`),onChange:e=>u({toolInput:e})}),(0,X.jsx)(g,{value:a,style:{width:150},optionList:E,onChange:e=>u({status:e})})]})})]})}var{Text:Q}=a;function fe({executionId:e,onClose:t,canWrite:n,onCancelRequest:r}){let a=y(),{data:s,loading:l,error:u,reload:d}=w(()=>x.get(`/monitor/execution/${encodeURIComponent(e)}`),[e],{skip:!e}),p=e?s:null,h=p?H(p.status):!1;return(0,X.jsxs)(m,{visible:!!e,onCancel:t,title:a(`mcpMonitor.viewDetail`,null,`执行详情`),width:720,footer:p?(0,X.jsxs)(o,{children:[h&&(0,X.jsx)(c,{theme:`solid`,disabled:!n,onClick:()=>r(p),children:a(`mcpMonitor.terminateExecution`,null,`终止`)}),(0,X.jsx)(c,{onClick:t,children:a(`common.close`,null,`关闭`)})]}):null,children:[!p&&l&&(0,X.jsx)(`div`,{className:`mcp-monitor-detail-loading`,children:(0,X.jsx)(f,{})}),(0,X.jsx)(O,{error:u,onRetry:d}),p&&(0,X.jsxs)(`div`,{className:`mcp-monitor-detail`,children:[(0,X.jsx)(E,{columns:2,items:[{label:`工具`,value:(0,X.jsx)(Q,{strong:!0,children:U(p.toolName)||`—`})},{label:a(`mcpMonitor.columnStatus`,null,`状态`),value:(0,X.jsx)(Z,{status:p.status})},{label:`执行 ID`,value:(0,X.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.id})},{label:a(`mcpMonitor.columnStartTime`,null,`开始时间`),value:v(p.startTime)},{label:`结束时间`,value:p.endTime?v(p.endTime):`—`},{label:a(`mcpMonitor.columnDuration`,null,`耗时`),value:G(W(p))},{label:`关联会话`,value:p.conversationId?(0,X.jsxs)(o,{spacing:4,children:[(0,X.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.conversationId}),(0,X.jsx)(A,{text:p.conversationId,size:`small`})]}):`—`},{label:`结果状态`,value:p.result?p.result.isError?`错误结果`:p.result.blocked?`已拦截`:`正常返回`:`无返回`}]}),p.error&&(0,X.jsx)(i,{type:`danger`,className:`mcp-monitor-detail-error`,description:(0,X.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.error})}),(0,X.jsx)(`div`,{className:`mcp-monitor-detail-section`,children:(0,X.jsx)(M,{title:a(`mcpDetailModal.requestParams`,null,`入参`),value:p.arguments??{}})}),(0,X.jsx)(`div`,{className:`mcp-monitor-detail-section`,children:p.result?(0,X.jsx)(M,{title:a(`mcpDetailModal.responseResult`,null,`出参`),value:p.result}):(0,X.jsx)(`div`,{className:`mcp-monitor-detail-empty`,children:h?a(`mcpDetailModal.runningNoResponseYet`,null,`尚无返回,工具可能仍在执行。`):a(`chat.noResponseData`,null,`暂无响应数据`)})}),p.partialOutput&&(0,X.jsxs)(`div`,{className:`mcp-monitor-detail-section`,children:[(0,X.jsxs)(`div`,{className:`mcp-monitor-detail-section-head`,children:[(0,X.jsx)(Q,{strong:!0,children:`实时输出尾部`}),(0,X.jsxs)(o,{spacing:4,children:[p.partialOutputBytes?(0,X.jsxs)(Q,{type:`tertiary`,children:[p.partialOutputBytes,` B`]}):null,(0,X.jsx)(A,{text:p.partialOutput,size:`small`})]})]}),(0,X.jsx)(`pre`,{className:`mcp-monitor-detail-pre`,children:p.partialOutput})]}),(0,X.jsxs)(`div`,{className:`mcp-monitor-detail-footnote`,children:[B(a,p.status),` · `,a(`mcpMonitor.statsFromAllTools`,null,`全部工具累计`)]})]})]})}function $(){let e=y(),{hasPermission:t}=b(),[n,i]=r(),a=t(`monitor:write`)||t(`mcp:write`),s=t(`monitor:delete`),[d,f]=(0,P.useState)(1),[p,m]=(0,P.useState)(20),[g,_]=(0,P.useState)(`all`),[v,S]=(0,P.useState)(``),C=ne(v,350),[E,D]=(0,P.useState)([]),[O,A]=te(`mcp-monitor-timeline-range`,`7d`),[j,M]=(0,P.useState)(null),[F,I]=(0,P.useState)(``),[L,R]=(0,P.useState)(!1),z=n.get(`id`)||``,B=[`24h`,`7d`,`30d`].includes(O)?O:`7d`,V=w(()=>x.get(`/monitor`,{page:d,page_size:p,status:g===`all`?``:g,tool:C}),[d,p,g,C]),H=w(()=>x.get(`/monitor/stats`,{top:12}),[]),G=w(()=>x.get(`/monitor/calls-timeline`,{range:B}),[B]),K=V.data?.executions||[],q=H.data?.summary||V.data?.summary||null,J=H.data?.topTools||V.data?.topTools||[],Y=Number(V.data?.retentionDays)||0,le=(0,P.useMemo)(()=>K.filter(e=>W(e)!==null).length,[K]),Z=(0,P.useMemo)(()=>oe(K),[K]);ie(()=>{typeof document<`u`&&document.hidden||(V.reload({silent:!0}),G.reload({silent:!0}))},5e3),ie(()=>{typeof document<`u`&&document.hidden||H.reload({silent:!0})},2e4);let Q=(0,P.useCallback)(()=>{V.reload(),H.reload({silent:!0}),G.reload({silent:!0})},[V.reload,H.reload,G.reload]),$=(0,P.useCallback)(e=>{let t=new URLSearchParams(n);t.set(`id`,e),i(t,{replace:!0})},[n,i]),pe=(0,P.useCallback)(()=>{let e=new URLSearchParams(n);e.delete(`id`),i(e,{replace:!0})},[n,i]),me=(0,P.useCallback)(e=>{Object.prototype.hasOwnProperty.call(e,`toolInput`)&&S(e.toolInput),e.status!==void 0&&_(e.status),f(1),D([])},[]),he=(0,P.useCallback)((e,t)=>{f(e),t&&t!==p&&m(t)},[p]),ge=(0,P.useCallback)(e=>{S(U(e)),f(1),D([])},[]),_e=(0,P.useCallback)(t=>{ae({title:e(`mcpMonitor.deleteExecTitle`,null,`删除此执行记录`),content:`确定删除 ${U(t.toolName)||`该`} 的执行记录?此操作不可恢复。`,okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/monitor/execution/${encodeURIComponent(t.id)}`),D(e=>e.filter(e=>e!==t.id)),N(e(`mcpMonitor.execDeleted`,null,`执行记录已删除`)),Q()}catch(t){T(t,e(`mcpMonitor.deleteExecFailed`,null,`删除执行记录失败`))}}})},[Q,e]),ve=(0,P.useCallback)(async()=>{if(!E.length){ee(e(`mcpMonitor.selectExecFirst`,null,`请先选择要删除的执行记录`));return}let t=[];try{let e=await x.post(`/monitor/executions/names`,{ids:E});t=[...new Set(Object.values(e||{}).map(e=>U(e?.toolName)).filter(Boolean))]}catch{t=[]}let n=t.length?`涉及工具:${t.slice(0,3).join(`、`)}${t.length>3?` 等`:``}。`:``;ae({title:e(`mcpMonitor.batchDeleteConfirm`,{count:E.length},`确定删除选中的 ${E.length} 条执行记录?`),content:`${n}此操作不可恢复。`,okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/monitor/executions`,{body:{ids:E}}),N(`已删除 ${E.length} 条执行记录`),D([]),Q()}catch(t){T(t,e(`mcp.batchDeleteFailed`,null,`批量删除执行记录失败`))}}})},[Q,E,e]),ye=(0,P.useCallback)(e=>{M(e),I(``)},[]),be=(0,P.useCallback)(async()=>{if(j?.id){R(!0);try{await x.post(`/monitor/execution/${encodeURIComponent(j.id)}/cancel`,{note:F.trim()}),N(e(`mcpDetailModal.abortSuccess`,null,`已发送终止请求`)),M(null),Q()}catch(t){T(t,e(`mcpDetailModal.abortFailed`,null,`终止失败`))}finally{R(!1)}}},[F,j,Q,e]),xe=Y>0?e(`mcpMonitor.retentionHint`,{days:Y},`执行记录保留 ${Y} 天,失败与拦截调用单独标记。`):`统计全部 MCP 工具调用,失败与拦截调用单独标记。`;return(0,X.jsxs)(`div`,{className:`mcp-monitor-page`,children:[(0,X.jsx)(re,{title:e(`mcp.monitorTitle`,null,`MCP 状态监控`),description:xe,extra:(0,X.jsx)(o,{children:(0,X.jsx)(c,{icon:(0,X.jsx)(h,{}),onClick:Q,loading:V.loading||H.loading,children:e(`common.refresh`,null,`刷新`)})})}),(0,X.jsx)(se,{summary:q,loading:H.loading&&!q,avgMs:Z,avgSamples:le}),(0,X.jsx)(ue,{data:G.data,loading:G.loading,error:G.error,range:B,onRangeChange:e=>{e&&A(e)},onRetry:()=>G.reload()}),(0,X.jsx)(ce,{topTools:J,loading:H.loading&&!J.length,onFilterTool:ge,activeTool:C}),(0,X.jsx)(k,{title:e(`mcp.latestExecutions`,null,`最新执行记录`),description:e(`mcpMonitor.emptyHint`,null,`在对话或任务中调用 MCP 工具后,执行记录将显示在此处`),extra:E.length>0?(0,X.jsxs)(o,{spacing:8,children:[(0,X.jsx)(`span`,{className:`mcp-monitor-selected`,children:e(`mcp.selectedCount`,{count:E.length},`已选择 ${E.length} 项`)}),(0,X.jsx)(c,{size:`small`,disabled:!s,type:`danger`,onClick:ve,children:e(`mcp.deleteSelected`,null,`批量删除`)}),(0,X.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>D([]),children:e(`mcpMonitor.deselectAll`,null,`取消全选`)})]}):null,children:(0,X.jsx)(de,{data:V.data,loading:V.loading,error:V.error,page:d,pageSize:p,status:g,toolInput:v,selected:E,onQuery:me,onPageChange:he,onRefresh:()=>V.reload(),onOpenDetail:$,onCancel:ye,onDelete:_e,onSelectionChange:D,canWrite:a,canDelete:s})}),(0,X.jsx)(fe,{executionId:z,onClose:pe,canWrite:a,onCancelRequest:e=>{pe(),ye(e)}}),(0,X.jsxs)(u,{title:e(`mcpMonitor.terminateExecution`,null,`终止执行`),visible:!!j,confirmLoading:L,maskClosable:!L,okText:e(`mcpMonitor.terminateExecution`,null,`终止`),cancelText:e(`common.cancel`,null,`取消`),onCancel:()=>M(null),onOk:be,children:[(0,X.jsx)(`p`,{className:`mcp-monitor-cancel-hint`,children:e(`mcpDetailModal.abortHint`,null,`终止仅取消本次工具调用,不会停止整条对话;说明会与工具输出一起交给模型。`)}),(0,X.jsx)(l,{rows:4,value:F,placeholder:e(`mcpDetailModal.abortNotePlaceholder`,null,`终止说明(可选),例如:命令执行时间过长,先终止。`),onChange:e=>I(e)})]})]})}export{$ as default};
\ No newline at end of file
diff --git a/web/static/app/assets/platform-rbac-Cg2CXbmQ.js b/web/static/app/assets/platform-rbac-CHfcwOkN.js
similarity index 89%
rename from web/static/app/assets/platform-rbac-Cg2CXbmQ.js
rename to web/static/app/assets/platform-rbac-CHfcwOkN.js
index 5ec0ed5b..16777f3b 100644
--- a/web/static/app/assets/platform-rbac-Cg2CXbmQ.js
+++ b/web/static/app/assets/platform-rbac-CHfcwOkN.js
@@ -1 +1 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,Lt as a,N as o,P as s,Pt as c,R as l,U as u,c as d,ft as f,i as p,ut as m,y as h}from"./semi-65W_4I1v.js";import{E as g,F as _,I as v,P as y,a as b,b as x,c as S,l as C,m as w,n as T,p as E,s as D,x as O,y as k}from"./index-BdnarFZR.js";var A=e(t(),1),j=e(n(),1),M=[[`project`,`项目`],[`conversation`,`会话`],[`asset`,`资产`],[`vulnerability`,`漏洞`],[`deep_assessment`,`深度测评`],[`batch_task`,`批量任务`]];function N({users:e,onCancel:t,onSaved:n}){let a=(0,A.useId)(),[o,s]=(0,A.useState)(M[0][0]),[c,d]=(0,A.useState)(``),[f,m]=(0,A.useState)(0),[g,_]=(0,A.useState)([]),[y,x]=(0,A.useState)(null),[w,E]=(0,A.useState)(!1),D=T(c,250),k=b(async()=>({type:o,q:D,offset:f,payload:await v.get(`/rbac/resources`,{type:o,q:D,limit:20,offset:f})}),[o,D,f]),N=k.data?.type===o&&k.data.q===D&&k.data.offset===f?k.data.payload:null,P=Array.isArray(N?.resources)?N.resources:[],F=new Map([...g,...P.map(e=>[e.id,e.label||e.id])]);return(0,j.jsx)(S,{visible:!0,title:`新增资源授权`,width:560,closable:!w,maskClosable:!w,closeOnEsc:!w,onCancel:t,formId:a,okText:`保存授权`,confirmLoading:w,cancelButtonProps:{disabled:w},children:(0,j.jsxs)(p,{id:a,onSubmit:async e=>{if(w)return;x(null);let t=String(e.ids||``).split(/[\s,,;;]+/).filter(Boolean),r=[...new Set([...g.map(([e])=>e),...t])];if(!r.length||r.length>100)x(Error(`请选择或输入 1 至 100 个资源 ID`));else{E(!0);try{await v.post(`/rbac/resource-assignments`,{user_id:e.user_id,resource_type:o,resource_ids:r}),O(`资源授权已保存`),n()}catch(e){x(e)}finally{E(!1)}}},initValues:{resource_type:o},children:[(0,j.jsx)(p.Select,{field:`user_id`,label:`用户`,filter:!0,optionList:e.map(e=>({value:e.id,label:e.display_name||e.username})),rules:[{required:!0,message:`请选择用户`}]}),(0,j.jsx)(p.Select,{field:`resource_type`,label:`资源类型`,optionList:M.map(([e,t])=>({value:e,label:t})),onChange:e=>{s(e),_([]),d(``),m(0)}}),(0,j.jsx)(p.Slot,{label:`按名称或 ID 搜索`,children:(0,j.jsx)(u,{"aria-label":`搜索资源`,value:c,onChange:e=>{d(e),m(0)}})}),(0,j.jsxs)(p.Slot,{label:`选择资源`,children:[(0,j.jsxs)(i,{wrap:!0,children:[(0,j.jsx)(l,{size:`small`,disabled:f===0||k.loading,onClick:()=>m(e=>Math.max(0,e-20)),children:`上一页`}),(0,j.jsxs)(r.Text,{type:`tertiary`,children:[f+P.length,` / `,N?.total??`—`]}),(0,j.jsx)(l,{size:`small`,disabled:!N?.has_more||k.loading,onClick:()=>m(e=>e+20),children:`下一页`})]}),(0,j.jsx)(h,{multiple:!0,style:{width:`100%`,marginTop:8},loading:k.loading,value:g.map(([e])=>e),"aria-label":`选择资源`,optionList:[...F].map(([e,t])=>({value:e,label:t})),onChange:e=>_((e||[]).map(e=>[e,F.get(e)||e]))})]}),(0,j.jsx)(p.TextArea,{field:`ids`,label:`手动输入资源 ID`,placeholder:`多个 ID 用空格或换行分隔`,rows:2}),(0,j.jsx)(C,{error:y||k.error})]})})}var{Text:P}=r;function F({value:e=[],options:t,onChange:n}){let r=(0,A.useMemo)(()=>{let e=new Map;return t.forEach(t=>{let[n]=t.split(`:`);e.has(n)||e.set(n,[]),e.get(n).push(t)}),[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0]))},[t]);return(0,j.jsx)(`div`,{style:{maxHeight:320,overflow:`auto`,border:`1px solid var(--semi-color-border)`,borderRadius:8,padding:12},children:r.map(([t,r])=>(0,j.jsxs)(`div`,{style:{marginBottom:10},children:[(0,j.jsx)(P,{type:`tertiary`,style:{fontSize:12,textTransform:`uppercase`},children:t}),(0,j.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:8,marginTop:4},children:r.map(t=>(0,j.jsx)(s,{checked:e.includes(t),onChange:r=>{let i=new Set(e);r.target.checked?i.add(t):i.delete(t),n([...i])},children:t.split(`:`)[1]},t))})]},t))})}function I(){let e=y(),{hasPermission:t}=_(),n=t(`rbac:write`),[r,s]=(0,A.useState)(`roles`),[u,h]=(0,A.useState)(null),[T,M]=(0,A.useState)(null),[I,L]=(0,A.useState)(!1),[R,z]=(0,A.useState)(!1),B=b(()=>v.get(`/rbac/metadata`),[]),V=b(()=>v.get(`/rbac/roles`),[]),H=b(()=>v.get(`/rbac/users`),[]),U=b(()=>v.get(`/rbac/resource-assignments`),[]),W=B.data?.permissions?Object.keys(B.data.permissions):[],G=Array.isArray(V.data?.roles)?V.data.roles:[],K=Array.isArray(H.data?.users)?H.data.users:[],q=Array.isArray(U.data?.assignments)?U.data.assignments:[],J=G.map(e=>({value:e.id,label:e.name})),Y=new Map(G.map(e=>[e.id,e.name])),X=new Map(K.map(e=>[e.id,e.display_name||e.username])),Z=async()=>{let e=await u.form.validate();z(!0);try{let t={name:e.name.trim(),description:e.description||``,scope:e.scope||``,permissions:u.permissions||[]};u.role?.id?await v.put(`/rbac/roles/${encodeURIComponent(u.role.id)}`,t):await v.post(`/rbac/roles`,t),O(`角色已保存`),h(null),V.reload(),B.reload()}catch(e){x(e,`保存角色失败`)}finally{z(!1)}},Q=async()=>{let e=await T.form.validate();z(!0);try{let t={display_name:e.display_name||``,enabled:e.enabled!==!1,roles:e.roles||[]};T.user?.id?(e.password&&(t.password=e.password),await v.put(`/rbac/users/${encodeURIComponent(T.user.id)}`,t)):await v.post(`/rbac/users`,{...t,username:e.username.trim(),password:e.password}),O(`用户已保存`),M(null),H.reload()}catch(e){x(e,`保存用户失败`)}finally{z(!1)}},$=e=>k({title:`删除角色「${e.name}」?`,onOk:async()=>{await v.del(`/rbac/roles/${encodeURIComponent(e.id)}`),O(`已删除`),V.reload()}}),ee=e=>k({title:`删除用户「${e.username}」?`,onOk:async()=>{await v.del(`/rbac/users/${encodeURIComponent(e.id)}`),O(`已删除`),H.reload()}}),te=e=>k({title:`删除该资源授权?`,content:`${e.resourceType||``} ${e.resourceId||``}`,onOk:async()=>{await v.del(`/rbac/resource-assignments/${encodeURIComponent(e.id)}`),O(`已删除`),U.reload()}});return(0,j.jsxs)(`div`,{children:[(0,j.jsx)(E,{title:e(`auth.rbacTitle`,null,`平台权限`),description:`平台账号、角色与资源授权;角色决定接口权限键,资源授权决定可见数据范围。`,extra:(0,j.jsx)(l,{icon:(0,j.jsx)(m,{}),onClick:()=>{V.reload(),H.reload(),U.reload(),B.reload()},children:`刷新`})}),(0,j.jsxs)(d,{type:`line`,activeKey:r,onChange:s,children:[(0,j.jsx)(d.TabPane,{itemKey:`roles`,tab:`角色权限(${G.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,j.jsx)(f,{}),onClick:()=>h({role:null,permissions:[],form:{}}),children:`新建角色`}),children:[(0,j.jsx)(C,{error:V.error,onRetry:()=>V.reload()}),(0,j.jsx)(D,{columns:[{title:`角色`,dataIndex:`name`,render:(e,t)=>(0,j.jsxs)(i,{vertical:!0,spacing:0,align:`start`,children:[(0,j.jsx)(P,{strong:!0,children:e}),(0,j.jsx)(P,{type:`tertiary`,children:t.description||`—`})]})},{title:`数据范围`,dataIndex:`scope`,width:130,render:e=>e?(0,j.jsx)(o,{size:`small`,children:e}):`—`},{title:`权限数`,dataIndex:`permissions`,width:100,render:e=>Array.isArray(e)?e.length:0},{title:`系统内置`,dataIndex:`is_system`,width:100,render:e=>e?(0,j.jsx)(o,{size:`small`,color:`blue`,children:`是`}):`否`},{title:`操作`,width:160,render:(e,t)=>(0,j.jsxs)(i,{children:[n&&!t.is_system&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,j.jsx)(c,{}),onClick:()=>h({role:t,permissions:t.permissions||[],form:{}}),children:`编辑`}),n&&!t.is_system&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>$(t)})]})}],dataSource:G,rowKey:`id`,loading:V.loading,pagination:{pageSize:20}})]})}),(0,j.jsx)(d.TabPane,{itemKey:`users`,tab:`平台用户(${K.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,j.jsx)(f,{}),onClick:()=>M({user:null,form:{}}),children:`新建用户`}),children:[(0,j.jsx)(C,{error:H.error,onRetry:()=>H.reload()}),(0,j.jsx)(D,{columns:[{title:`用户名`,dataIndex:`username`,render:(e,t)=>(0,j.jsxs)(i,{vertical:!0,spacing:0,align:`start`,children:[(0,j.jsx)(P,{strong:!0,children:e}),(0,j.jsx)(P,{type:`tertiary`,children:t.display_name||`—`})]})},{title:`角色`,dataIndex:`roles`,width:260,render:e=>Array.isArray(e)&&e.length?(0,j.jsx)(i,{wrap:!0,spacing:4,children:e.map(e=>(0,j.jsx)(o,{size:`small`,children:Y.get(e)||e},e))}):`—`},{title:`状态`,dataIndex:`enabled`,width:100,render:e=>e===!1?(0,j.jsx)(o,{size:`small`,color:`grey`,children:`停用`}):(0,j.jsx)(o,{size:`small`,color:`green`,children:`启用`})},{title:`操作`,width:160,render:(e,t)=>(0,j.jsxs)(i,{children:[n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,j.jsx)(c,{}),onClick:()=>M({user:t,form:{}}),children:`编辑`}),n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>ee(t)})]})}],dataSource:K,rowKey:`id`,loading:H.loading,pagination:{pageSize:20}})]})}),(0,j.jsx)(d.TabPane,{itemKey:`assignments`,tab:`资源授权(${q.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,icon:(0,j.jsx)(f,{}),onClick:()=>L(!0),children:`新增资源授权`}),children:[(0,j.jsx)(C,{error:U.error,onRetry:()=>U.reload()}),(0,j.jsx)(D,{columns:[{title:`资源类型`,dataIndex:`resourceType`,width:140,render:e=>e||`—`},{title:`资源`,dataIndex:`resourceId`,render:(e,t)=>t.resourceLabel||e||`—`},{title:`用户`,dataIndex:`userId`,render:e=>X.get(e)||e||`—`},{title:`创建时间`,dataIndex:`createdAt`,width:180,render:e=>g(e)},{title:`操作`,width:100,render:(e,t)=>n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>te(t)})}],dataSource:q,rowKey:`id`,loading:U.loading,pagination:{pageSize:20}})]})})]}),n&&I&&(0,j.jsx)(N,{users:K,onCancel:()=>L(!1),onSaved:()=>{L(!1),U.reload()}}),(0,j.jsx)(S,{title:u?.role?`编辑角色`:`新建角色`,visible:!!u,onCancel:()=>h(null),onOk:Z,confirmLoading:R,width:820,children:u&&(0,j.jsxs)(p,{getFormApi:e=>h(t=>t&&{...t,form:e}),initValues:u.role?{name:u.role.name,description:u.role.description,scope:u.role.scope}:{},children:[(0,j.jsx)(p.Input,{field:`name`,label:`角色名称`,rules:[{required:!0,message:`请输入角色名称`}]}),(0,j.jsx)(p.Input,{field:`description`,label:`描述`}),(0,j.jsx)(p.Select,{field:`scope`,label:`数据范围`,optionList:(B.data?.scopes||[`all`,`assigned`,`own`]).map(e=>({value:e,label:e}))}),(0,j.jsx)(p.Slot,{label:`权限`,children:(0,j.jsx)(F,{value:u.permissions,options:W,onChange:e=>h(t=>({...t,permissions:e}))})})]})},u?.role?.id||`new-rbac-role`),(0,j.jsx)(S,{title:T?.user?`编辑用户`:`新建用户`,visible:!!T,onCancel:()=>M(null),onOk:Q,confirmLoading:R,width:620,children:T&&(0,j.jsxs)(p,{getFormApi:e=>M(t=>t&&{...t,form:e}),initValues:T.user?{username:T.user.username,display_name:T.user.display_name,enabled:T.user.enabled!==!1,roles:T.user.roles||[]}:{enabled:!0,roles:[]},children:[(0,j.jsx)(p.Input,{field:`username`,label:`用户名`,disabled:!!T.user,rules:[{required:!0,message:`请输入用户名`}]}),(0,j.jsx)(p.Input,{field:`display_name`,label:`显示名称`}),(0,j.jsx)(p.Input,{field:`password`,label:T.user?`重置密码(留空不修改)`:`密码`,mode:`password`,rules:T.user?[]:[{required:!0,min:8,message:`至少 8 位`}]}),(0,j.jsx)(p.Select,{field:`roles`,label:`角色`,multiple:!0,optionList:J}),(0,j.jsx)(p.Slot,{label:`启用`,children:(0,j.jsx)(p.Switch,{field:`enabled`})})]})},T?.user?.id||`new-rbac-user`)]})}export{I as default};
\ No newline at end of file
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,Lt as a,N as o,P as s,Pt as c,R as l,U as u,c as d,ft as f,i as p,ut as m,y as h}from"./semi-65W_4I1v.js";import{E as g,F as _,I as v,L as y,a as b,b as x,c as S,l as C,m as w,n as T,p as E,s as D,x as O,y as k}from"./index-_8d9XBPJ.js";var A=e(t(),1),j=e(n(),1),M=[[`project`,`项目`],[`conversation`,`会话`],[`asset`,`资产`],[`vulnerability`,`漏洞`],[`deep_assessment`,`深度测评`],[`batch_task`,`批量任务`]];function N({users:e,onCancel:t,onSaved:n}){let a=(0,A.useId)(),[o,s]=(0,A.useState)(M[0][0]),[c,d]=(0,A.useState)(``),[f,m]=(0,A.useState)(0),[g,_]=(0,A.useState)([]),[v,x]=(0,A.useState)(null),[w,E]=(0,A.useState)(!1),D=T(c,250),k=b(async()=>({type:o,q:D,offset:f,payload:await y.get(`/rbac/resources`,{type:o,q:D,limit:20,offset:f})}),[o,D,f]),N=k.data?.type===o&&k.data.q===D&&k.data.offset===f?k.data.payload:null,P=Array.isArray(N?.resources)?N.resources:[],F=new Map([...g,...P.map(e=>[e.id,e.label||e.id])]);return(0,j.jsx)(S,{visible:!0,title:`新增资源授权`,width:560,closable:!w,maskClosable:!w,closeOnEsc:!w,onCancel:t,formId:a,okText:`保存授权`,confirmLoading:w,cancelButtonProps:{disabled:w},children:(0,j.jsxs)(p,{id:a,onSubmit:async e=>{if(w)return;x(null);let t=String(e.ids||``).split(/[\s,,;;]+/).filter(Boolean),r=[...new Set([...g.map(([e])=>e),...t])];if(!r.length||r.length>100)x(Error(`请选择或输入 1 至 100 个资源 ID`));else{E(!0);try{await y.post(`/rbac/resource-assignments`,{user_id:e.user_id,resource_type:o,resource_ids:r}),O(`资源授权已保存`),n()}catch(e){x(e)}finally{E(!1)}}},initValues:{resource_type:o},children:[(0,j.jsx)(p.Select,{field:`user_id`,label:`用户`,filter:!0,optionList:e.map(e=>({value:e.id,label:e.display_name||e.username})),rules:[{required:!0,message:`请选择用户`}]}),(0,j.jsx)(p.Select,{field:`resource_type`,label:`资源类型`,optionList:M.map(([e,t])=>({value:e,label:t})),onChange:e=>{s(e),_([]),d(``),m(0)}}),(0,j.jsx)(p.Slot,{label:`按名称或 ID 搜索`,children:(0,j.jsx)(u,{"aria-label":`搜索资源`,value:c,onChange:e=>{d(e),m(0)}})}),(0,j.jsxs)(p.Slot,{label:`选择资源`,children:[(0,j.jsxs)(i,{wrap:!0,children:[(0,j.jsx)(l,{size:`small`,disabled:f===0||k.loading,onClick:()=>m(e=>Math.max(0,e-20)),children:`上一页`}),(0,j.jsxs)(r.Text,{type:`tertiary`,children:[f+P.length,` / `,N?.total??`—`]}),(0,j.jsx)(l,{size:`small`,disabled:!N?.has_more||k.loading,onClick:()=>m(e=>e+20),children:`下一页`})]}),(0,j.jsx)(h,{multiple:!0,style:{width:`100%`,marginTop:8},loading:k.loading,value:g.map(([e])=>e),"aria-label":`选择资源`,optionList:[...F].map(([e,t])=>({value:e,label:t})),onChange:e=>_((e||[]).map(e=>[e,F.get(e)||e]))})]}),(0,j.jsx)(p.TextArea,{field:`ids`,label:`手动输入资源 ID`,placeholder:`多个 ID 用空格或换行分隔`,rows:2}),(0,j.jsx)(C,{error:v||k.error})]})})}var{Text:P}=r;function F({value:e=[],options:t,onChange:n}){let r=(0,A.useMemo)(()=>{let e=new Map;return t.forEach(t=>{let[n]=t.split(`:`);e.has(n)||e.set(n,[]),e.get(n).push(t)}),[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0]))},[t]);return(0,j.jsx)(`div`,{style:{maxHeight:320,overflow:`auto`,border:`1px solid var(--semi-color-border)`,borderRadius:8,padding:12},children:r.map(([t,r])=>(0,j.jsxs)(`div`,{style:{marginBottom:10},children:[(0,j.jsx)(P,{type:`tertiary`,style:{fontSize:12,textTransform:`uppercase`},children:t}),(0,j.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:8,marginTop:4},children:r.map(t=>(0,j.jsx)(s,{checked:e.includes(t),onChange:r=>{let i=new Set(e);r.target.checked?i.add(t):i.delete(t),n([...i])},children:t.split(`:`)[1]},t))})]},t))})}function I(){let e=_(),{hasPermission:t}=v(),n=t(`rbac:write`),[r,s]=(0,A.useState)(`roles`),[u,h]=(0,A.useState)(null),[T,M]=(0,A.useState)(null),[I,L]=(0,A.useState)(!1),[R,z]=(0,A.useState)(!1),B=b(()=>y.get(`/rbac/metadata`),[]),V=b(()=>y.get(`/rbac/roles`),[]),H=b(()=>y.get(`/rbac/users`),[]),U=b(()=>y.get(`/rbac/resource-assignments`),[]),W=B.data?.permissions?Object.keys(B.data.permissions):[],G=Array.isArray(V.data?.roles)?V.data.roles:[],K=Array.isArray(H.data?.users)?H.data.users:[],q=Array.isArray(U.data?.assignments)?U.data.assignments:[],J=G.map(e=>({value:e.id,label:e.name})),Y=new Map(G.map(e=>[e.id,e.name])),X=new Map(K.map(e=>[e.id,e.display_name||e.username])),Z=async()=>{let e=await u.form.validate();z(!0);try{let t={name:e.name.trim(),description:e.description||``,scope:e.scope||``,permissions:u.permissions||[]};u.role?.id?await y.put(`/rbac/roles/${encodeURIComponent(u.role.id)}`,t):await y.post(`/rbac/roles`,t),O(`角色已保存`),h(null),V.reload(),B.reload()}catch(e){x(e,`保存角色失败`)}finally{z(!1)}},Q=async()=>{let e=await T.form.validate();z(!0);try{let t={display_name:e.display_name||``,enabled:e.enabled!==!1,roles:e.roles||[]};T.user?.id?(e.password&&(t.password=e.password),await y.put(`/rbac/users/${encodeURIComponent(T.user.id)}`,t)):await y.post(`/rbac/users`,{...t,username:e.username.trim(),password:e.password}),O(`用户已保存`),M(null),H.reload()}catch(e){x(e,`保存用户失败`)}finally{z(!1)}},$=e=>k({title:`删除角色「${e.name}」?`,onOk:async()=>{await y.del(`/rbac/roles/${encodeURIComponent(e.id)}`),O(`已删除`),V.reload()}}),ee=e=>k({title:`删除用户「${e.username}」?`,onOk:async()=>{await y.del(`/rbac/users/${encodeURIComponent(e.id)}`),O(`已删除`),H.reload()}}),te=e=>k({title:`删除该资源授权?`,content:`${e.resourceType||``} ${e.resourceId||``}`,onOk:async()=>{await y.del(`/rbac/resource-assignments/${encodeURIComponent(e.id)}`),O(`已删除`),U.reload()}});return(0,j.jsxs)(`div`,{children:[(0,j.jsx)(E,{title:e(`auth.rbacTitle`,null,`平台权限`),description:`平台账号、角色与资源授权;角色决定接口权限键,资源授权决定可见数据范围。`,extra:(0,j.jsx)(l,{icon:(0,j.jsx)(m,{}),onClick:()=>{V.reload(),H.reload(),U.reload(),B.reload()},children:`刷新`})}),(0,j.jsxs)(d,{type:`line`,activeKey:r,onChange:s,children:[(0,j.jsx)(d.TabPane,{itemKey:`roles`,tab:`角色权限(${G.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,j.jsx)(f,{}),onClick:()=>h({role:null,permissions:[],form:{}}),children:`新建角色`}),children:[(0,j.jsx)(C,{error:V.error,onRetry:()=>V.reload()}),(0,j.jsx)(D,{columns:[{title:`角色`,dataIndex:`name`,render:(e,t)=>(0,j.jsxs)(i,{vertical:!0,spacing:0,align:`start`,children:[(0,j.jsx)(P,{strong:!0,children:e}),(0,j.jsx)(P,{type:`tertiary`,children:t.description||`—`})]})},{title:`数据范围`,dataIndex:`scope`,width:130,render:e=>e?(0,j.jsx)(o,{size:`small`,children:e}):`—`},{title:`权限数`,dataIndex:`permissions`,width:100,render:e=>Array.isArray(e)?e.length:0},{title:`系统内置`,dataIndex:`is_system`,width:100,render:e=>e?(0,j.jsx)(o,{size:`small`,color:`blue`,children:`是`}):`否`},{title:`操作`,width:160,render:(e,t)=>(0,j.jsxs)(i,{children:[n&&!t.is_system&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,j.jsx)(c,{}),onClick:()=>h({role:t,permissions:t.permissions||[],form:{}}),children:`编辑`}),n&&!t.is_system&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>$(t)})]})}],dataSource:G,rowKey:`id`,loading:V.loading,pagination:{pageSize:20}})]})}),(0,j.jsx)(d.TabPane,{itemKey:`users`,tab:`平台用户(${K.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,j.jsx)(f,{}),onClick:()=>M({user:null,form:{}}),children:`新建用户`}),children:[(0,j.jsx)(C,{error:H.error,onRetry:()=>H.reload()}),(0,j.jsx)(D,{columns:[{title:`用户名`,dataIndex:`username`,render:(e,t)=>(0,j.jsxs)(i,{vertical:!0,spacing:0,align:`start`,children:[(0,j.jsx)(P,{strong:!0,children:e}),(0,j.jsx)(P,{type:`tertiary`,children:t.display_name||`—`})]})},{title:`角色`,dataIndex:`roles`,width:260,render:e=>Array.isArray(e)&&e.length?(0,j.jsx)(i,{wrap:!0,spacing:4,children:e.map(e=>(0,j.jsx)(o,{size:`small`,children:Y.get(e)||e},e))}):`—`},{title:`状态`,dataIndex:`enabled`,width:100,render:e=>e===!1?(0,j.jsx)(o,{size:`small`,color:`grey`,children:`停用`}):(0,j.jsx)(o,{size:`small`,color:`green`,children:`启用`})},{title:`操作`,width:160,render:(e,t)=>(0,j.jsxs)(i,{children:[n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,j.jsx)(c,{}),onClick:()=>M({user:t,form:{}}),children:`编辑`}),n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>ee(t)})]})}],dataSource:K,rowKey:`id`,loading:H.loading,pagination:{pageSize:20}})]})}),(0,j.jsx)(d.TabPane,{itemKey:`assignments`,tab:`资源授权(${q.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,icon:(0,j.jsx)(f,{}),onClick:()=>L(!0),children:`新增资源授权`}),children:[(0,j.jsx)(C,{error:U.error,onRetry:()=>U.reload()}),(0,j.jsx)(D,{columns:[{title:`资源类型`,dataIndex:`resourceType`,width:140,render:e=>e||`—`},{title:`资源`,dataIndex:`resourceId`,render:(e,t)=>t.resourceLabel||e||`—`},{title:`用户`,dataIndex:`userId`,render:e=>X.get(e)||e||`—`},{title:`创建时间`,dataIndex:`createdAt`,width:180,render:e=>g(e)},{title:`操作`,width:100,render:(e,t)=>n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>te(t)})}],dataSource:q,rowKey:`id`,loading:U.loading,pagination:{pageSize:20}})]})})]}),n&&I&&(0,j.jsx)(N,{users:K,onCancel:()=>L(!1),onSaved:()=>{L(!1),U.reload()}}),(0,j.jsx)(S,{title:u?.role?`编辑角色`:`新建角色`,visible:!!u,onCancel:()=>h(null),onOk:Z,confirmLoading:R,width:820,children:u&&(0,j.jsxs)(p,{getFormApi:e=>h(t=>t&&{...t,form:e}),initValues:u.role?{name:u.role.name,description:u.role.description,scope:u.role.scope}:{},children:[(0,j.jsx)(p.Input,{field:`name`,label:`角色名称`,rules:[{required:!0,message:`请输入角色名称`}]}),(0,j.jsx)(p.Input,{field:`description`,label:`描述`}),(0,j.jsx)(p.Select,{field:`scope`,label:`数据范围`,optionList:(B.data?.scopes||[`all`,`assigned`,`own`]).map(e=>({value:e,label:e}))}),(0,j.jsx)(p.Slot,{label:`权限`,children:(0,j.jsx)(F,{value:u.permissions,options:W,onChange:e=>h(t=>({...t,permissions:e}))})})]})},u?.role?.id||`new-rbac-role`),(0,j.jsx)(S,{title:T?.user?`编辑用户`:`新建用户`,visible:!!T,onCancel:()=>M(null),onOk:Q,confirmLoading:R,width:620,children:T&&(0,j.jsxs)(p,{getFormApi:e=>M(t=>t&&{...t,form:e}),initValues:T.user?{username:T.user.username,display_name:T.user.display_name,enabled:T.user.enabled!==!1,roles:T.user.roles||[]}:{enabled:!0,roles:[]},children:[(0,j.jsx)(p.Input,{field:`username`,label:`用户名`,disabled:!!T.user,rules:[{required:!0,message:`请输入用户名`}]}),(0,j.jsx)(p.Input,{field:`display_name`,label:`显示名称`}),(0,j.jsx)(p.Input,{field:`password`,label:T.user?`重置密码(留空不修改)`:`密码`,mode:`password`,rules:T.user?[]:[{required:!0,min:8,message:`至少 8 位`}]}),(0,j.jsx)(p.Select,{field:`roles`,label:`角色`,multiple:!0,optionList:J}),(0,j.jsx)(p.Slot,{label:`启用`,children:(0,j.jsx)(p.Switch,{field:`enabled`})})]})},T?.user?.id||`new-rbac-user`)]})}export{I as default};
\ No newline at end of file
diff --git a/web/static/app/assets/plugin-hub-B-d85AF3.js b/web/static/app/assets/plugin-hub-B-d85AF3.js
new file mode 100644
index 00000000..d658c338
--- /dev/null
+++ b/web/static/app/assets/plugin-hub-B-d85AF3.js
@@ -0,0 +1,6 @@
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{B as a,Ft as o,G as s,I as c,Lt as l,Mt as u,N as d,P as f,R as p,S as m,U as h,W as g,Wt as _,Zt as v,_t as y,c as b,et as x,ft as S,h as C,l as w,lt as T,m as E,on as D,ot as O,pt as k,q as ee,qt as A,rn as j,rt as te,tt as ne,ut as M,x as re,y as ie,yt as N}from"./semi-65W_4I1v.js";import{B as ae,E as oe,F as P,I as se,L as F,_ as ce,a as I,b as L,c as le,d as R,l as ue,m as de,o as fe,p as pe,r as z,s as me,u as he,x as B,y as ge}from"./index-_8d9XBPJ.js";import{r as _e}from"./agent-handoff-DzQOcr38.js";var V=e(t(),1);function ve(e=`op`){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`${e}-${crypto.randomUUID()}`:`${e}-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}var ye={plugin_bearer_required:[`pluginHub.errorBearerRequired`,`需要 Bearer 登录凭据才能访问插件平台`],plugin_invalid_request:[`pluginHub.errorInvalidRequest`,`请求参数不合法,请检查插件 ID(仅限小写字母、数字和连字符)、标题与仓库地址`],plugin_invalid_source:[`pluginHub.errorInvalidSource`,`仅支持公开的 GitHub HTTPS 仓库地址及合法分支/Tag/Commit`],plugin_ambiguous_git_ref:[`pluginHub.errorAmbiguousRef`,`分支与 Tag 同名,请填写完整引用(如 refs/tags/xxx 或 refs/heads/xxx)`],plugin_source_not_found:[`pluginHub.errorSourceNotFound`,`未找到目标仓库或指定版本`],plugin_invalid_manifest:[`pluginHub.errorInvalidManifest`,`插件 Manifest 格式或字段校验未通过`],plugin_github_rate_limited:[`pluginHub.errorRateLimited`,`GitHub API 触发限流,建议配置 plugins.egress.github_token_env 后重试`],plugin_source_unavailable:[`pluginHub.errorSourceUnavailable`,`无法连接上游仓库,请检查网络或插件代理配置`],plugin_manifest_required:[`pluginHub.errorManifestRequired`,`该仓库未自带 csai-plugin.yaml,请先补全 Manifest 草案`],plugin_manifest_source_mismatch:[`pluginHub.errorSourceMismatch`,`Manifest 中的仓库地址或版本与探测结果不一致`],plugin_artifact_not_approved:[`pluginHub.errorArtifactNotApproved`,`当前宿主策略未批准该制品摘要,请联系管理员或核对批准策略`],plugin_operation_conflict:[`pluginHub.errorOperationConflict`,`该插件已有正在执行的变更任务,请等待当前操作完成`],plugin_plan_stale:[`pluginHub.errorPlanStale`,`安装计划已过期或已被消费,请重新生成锁定计划`],plugin_runtime_unavailable:[`pluginHub.errorRuntimeUnavailable`,`插件运行调度器尚未就绪,请稍后重试`],plugin_artifact_unavailable:[`pluginHub.errorArtifactUnavailable`,`未找到适配当前系统架构的可安装制品或镜像`],plugin_llm_binding_invalid:[`pluginHub.errorLLMBindingInvalid`,`所选模型通道无效或与该插件声明的协议不兼容`],plugin_llm_gateway_unavailable:[`pluginHub.errorLLMGatewayUnavailable`,`CSAI 插件模型网关未就绪`],plugin_web_unavailable:[`pluginHub.errorWebUnavailable`,`插件 WebUI 代理未就绪或应用尚未健康启动`],plugin_embed_origin_or_permission_rejected:[`pluginHub.errorEmbedRejected`,`无权访问该插件工作区或请求来源校验未通过`],plugin_record_not_found:[`pluginHub.errorNotFound`,`未找到对应的插件记录或计划已过期`],docker_cli_missing:[`pluginHub.errorDockerCliMissing`,`宿主未安装 Docker CLI / Engine,容器类插件无法启动`],docker_daemon_unavailable:[`pluginHub.errorDockerDaemonUnavailable`,`宿主 Docker 服务未启动,或当前运行用户无权访问 docker.sock`],docker_compose_missing:[`pluginHub.errorDockerComposeMissing`,`宿主缺少 Docker Compose v2 插件`],docker_engine_unsupported:[`pluginHub.errorDockerEngineUnsupported`,`宿主 Docker Engine 版本过低或不满足隔离档位要求`],docker_socket_missing:[`pluginHub.errorDockerSocketMissing`,`容器内未挂载 /var/run/docker.sock`],git_missing:[`pluginHub.errorGitMissing`,`宿主未安装 Git 工具`],plugin_install_failed:[`pluginHub.errorInstallFailed`,`插件安装失败,请查看运行日志或交给 Agent 排错修复`]};function H(e,t,n){let r=ye[typeof t==`string`?t:t?.payload?.error||(typeof t?.message==`string`?t.message:``)];return r?e(r[0],null,r[1]):(typeof t==`string`?t:t?.message)||n||e(`common.loadFailed`,null,`操作失败`)}function be({driver:e,probe:t,hostOS:n,hostArch:r,pluginTitle:i}){return[`请帮我在当前 CyberStrikeAI 宿主机上安装并配置插件平台缺少的运行驱动「${e}」。`,``,`### 当前诊断信息`,`- 宿主机平台:${n||`unknown`}/${r||`unknown`}`,`- 缺少驱动:${e}`,`- 预检错误码:${t?.code||`unavailable`}`,t?.guidance?`- 官方提示:${t.guidance}`:``,t?.install_command?`- 参考安装命令:\`${t.install_command}\``:``,i?`- 待安装插件:${i}`:``,``,`### 请按以下步骤协助完成`,`1. 先检查当前宿主机系统发行版、当前运行用户、包管理器以及目标依赖(如 Docker / Docker Compose / Git)与服务/权限状态;`,`2. 使用官方软件源或受信任方式安装并启动缺少的依赖(涉及 sudo 或系统变更时请清晰说明并走审批确认);`,"3. 如果安装了 Docker,请同时确认 `dockerd` 已开机自启、Compose v2 可用,并检查当前运行 CyberStrikeAI 的用户是否有权限访问 `/var/run/docker.sock`;","4. 执行验证命令确认驱动已正常可用(例如 `docker version && docker compose version` 或 `git --version`);","5. 完成后告诉我是否需要重启 CyberStrikeAI 服务(例如新增 `docker` 用户组后),以便我回到「能力平台」继续一键安装插件。"].filter(Boolean).join(`
+`)}function xe({install:e,logs:t,hostOS:n,hostArch:r}){let i=(Array.isArray(t)?t:[]).slice(-40).map(e=>`[${e.created_at||``}] ${e.line}`).join(`
+`);return[`我在 CyberStrikeAI 插件化能力平台中安装/运行插件「${e?.title||e?.plugin_id||`未知插件`}」失败,请帮我排查根因并直接在宿主机上修复缺少的运行环境或依赖。`,``,`### 插件状态与诊断信息`,`- 插件名称:${e?.title||`—`} (${e?.plugin_id||`—`})`,`- 实例 ID:${e?.id||`—`}`,`- 运行驱动:${e?.driver||`—`}`,`- 当前状态:${e?.observed_state||`failed`}`,`- 最近错误码:${e?.last_error_code||`plugin_install_failed`}`,e?.repository?`- 源码仓库:${e.repository}`:``,n?`- 宿主机平台:${n}/${r||``}`:``,``,`### 最近插件脱敏日志`,"```text",i||`(暂无日志输出,请直接检查对应驱动的宿主机运行环境)`,"```",``,`### 请协助完成`,`1. 根据错误码和日志定位失败根因(例如缺少 Docker / Compose / Git / Go / Node.js、dockerd 未启动、docker.sock 权限不足、端口或网络问题等);`,`2. 如果缺少运行环境或依赖,请直接帮我在宿主机上安装并配置就绪(涉及提权或系统改动时按审批确认);`,`3. 验证宿主机依赖已恢复正常,并告诉我接下来回到「能力平台」直接点击重试/启动即可。`].filter(Boolean).join(`
+`)}function Se(e){switch(String(e||``).toLowerCase()){case`healthy`:return`green`;case`starting`:case`installing`:case`stopping`:return`blue`;case`degraded`:case`cleanup_pending`:return`amber`;case`failed`:return`red`;default:return`grey`}}function Ce(e,t){let n={healthy:[`pluginHub.stateHealthy`,`运行中`],starting:[`pluginHub.stateStarting`,`启动中`],installing:[`pluginHub.stateInstalling`,`安装中`],stopping:[`pluginHub.stateStopping`,`停止中`],stopped:[`pluginHub.stateStopped`,`已停止`],degraded:[`pluginHub.stateDegraded`,`状态异常`],failed:[`pluginHub.stateFailed`,`失败`],cleanup_pending:[`pluginHub.stateCleanupPending`,`待清理`],removed:[`pluginHub.stateRemoved`,`已卸载`]}[String(t||``).toLowerCase()];return n?e(n[0],null,n[1]):t||`—`}function U(e,t){let n={auto:[`pluginHub.driverAuto`,`自动择优(Release → Git → 容器)`],release:[`pluginHub.driverRelease`,`Release 预编译包`],git:[`pluginHub.driverGit`,`Git 源码构建`],container:[`pluginHub.driverContainer`,`Docker / Compose 容器`],compose:[`pluginHub.driverCompose`,`Docker Compose`]}[String(t||``).toLowerCase()];return n?e(n[0],null,n[1]):t||`—`}var W={listCatalog:()=>F.get(`/plugins/catalog`),saveCatalog:e=>F.post(`/plugins/catalog`,e),deleteCatalog:e=>F.del(`/plugins/catalog/${encodeURIComponent(e)}`),restoreCatalog:()=>F.post(`/plugins/catalog/restore`,{}),listInstalls:()=>F.get(`/plugins/installs`),getInstall:e=>F.get(`/plugins/installs/${encodeURIComponent(e)}`),listLLMChannels:()=>F.get(`/plugins/llm/channels`),probes:(e=`standard`)=>F.get(`/plugins/runtime/probes`,{isolation:e}),inspectGit:(e,t)=>F.post(`/plugins/imports/inspect`,{repository:e.trim(),revision:(t||``).trim()}),createPlan:e=>F.post(`/plugins/install-plans`,e),install:({planId:e,planDigest:t,autoBindLLM:n})=>F.post(`/plugins/installs`,{kind:`install`,plan_id:e,plan_digest:t,idempotency_key:ve(`install`),auto_bind_llm:n}),operate:(e,t,n={})=>F.post(`/plugins/installs/${encodeURIComponent(e)}/operations`,{kind:t,idempotency_key:ve(t),...n}),getOperation:e=>F.get(`/plugins/operations/${encodeURIComponent(e)}`),readLogs:(e,t=0,n=100)=>F.get(`/plugins/installs/${encodeURIComponent(e)}/logs`,{after:t,limit:n}),issueEmbedSession:e=>F.post(`/plugins/installs/${encodeURIComponent(e)}/embed-sessions`,{}),patchLLM:(e,t)=>F.patch(`/plugins/installs/${encodeURIComponent(e)}/llm`,t)};function we(e,{after:t=0,onEntry:n,onError:r,onClose:i}={}){let a=new AbortController,o=ae(),s={Accept:`text/event-stream`};o&&(s.Authorization=`Bearer ${o}`);let c=`/api/plugins/installs/${encodeURIComponent(e)}/logs?after=${encodeURIComponent(String(t))}`;return(async()=>{try{let e=await fetch(c,{method:`GET`,headers:s,signal:a.signal});if(e.status===401&&window.dispatchEvent(new CustomEvent(`csai:unauthorized`)),!e.ok||!e.body)throw Error(`HTTP ${e.status}`);let t=e.body.getReader(),r=new TextDecoder,o=``;for(;;){let{done:e,value:i}=await t.read();if(e)break;o+=r.decode(i,{stream:!0});let a;for(;(a=o.indexOf(`
+`))>=0;){let e=o.slice(0,a).replace(/\r$/,``);if(o=o.slice(a+1),!e.startsWith(`data:`))continue;let t=e.slice(5).trim();if(t)try{n?.(JSON.parse(t))}catch{}}}i?.()}catch(e){if(e?.name===`AbortError`){i?.();return}r?.(e)}})(),()=>a.abort()}function Te(e){let t=e?.repository||`https://github.com/owner/repo`,n=t.split(`/`).pop()||`my-plugin`,r=n.toLowerCase().replace(/[^a-z0-9-]+/g,`-`).replace(/^-+|-+$/g,``)||`my-plugin`;return(e?.candidates||[]).includes(`container`)?JSON.stringify({apiVersion:`plugins.csai.io/v1`,kind:`WebPlugin`,metadata:{id:r,title:n,summary:`Imported container WebUI plugin`,version:`1.0.0`,repository:t},distribution:[{type:`container`,mode:`docker`,services:[{name:`web`,role:`web`,image:`ghcr.io/${t.replace(`https://github.com/`,``).toLowerCase()}:latest`,containerPort:8080,resources:{memoryMiB:512,pids:128}}]}],web:{route:`root`,entryPath:`/`,healthPath:`/`,allowHealthRedirect:!0},access:{mode:`plugin_login`},permissions:{persistentData:!1,modelGateway:!1,egress:[]}},null,2):JSON.stringify({apiVersion:`plugins.csai.io/v1`,kind:`WebPlugin`,metadata:{id:r,title:n,summary:`Imported Git WebUI plugin`,version:`1.0.0`,repository:t},distribution:[{type:`git`,url:t,revision:e?.resolved_ref||e?.commit||`main`,dependencies:[{name:`git`,minVersion:`2.30`},{name:`go`,minVersion:`1.22`}],build:[{program:`go`,args:[`build`,`-o`,`dist/app`,`.`]}],outputRoot:`dist`}],launch:{entrypoint:`app`,env:{PORT:`listen_port`,HOST:`listen_host`}},web:{route:`root`,entryPath:`/`,healthPath:`/`,allowHealthRedirect:!0},access:{mode:`platform`},permissions:{persistentData:!1,modelGateway:!1,egress:[]}},null,2)}var G=e(r(),1),{Text:Ee}=s;function De(e,t,n){let r=document.createElement(`form`);r.method=`POST`,r.action=e,r.target=n,r.style.display=`none`;let i=document.createElement(`input`);i.type=`hidden`,i.name=`ticket`,i.value=t,r.appendChild(i),document.body.appendChild(r),r.submit(),r.remove()}function Oe({install:e,canManage:t,onBack:n,onOpenDetail:r,onOpenLogs:i}){let a=P(),o=`csai-plugin-frame-${(0,V.useId)().replace(/[^a-zA-Z0-9_-]/g,``)}`,s=(0,V.useRef)(null),[l,f]=(0,V.useState)(!0),[m,h]=(0,V.useState)(``),[v,b]=(0,V.useState)(null),[S,C]=(0,V.useState)(!1),w=(0,V.useCallback)(async()=>{if(e?.id){f(!0),h(``);try{let t=await W.issueEmbedSession(e.id);b(t),requestAnimationFrame(()=>{De(t.action,t.ticket,o)})}catch(e){h(H(a,e,a(`pluginHub.embedInitFailed`,null,`无法建立插件工作区会话`))),f(!1)}}},[e?.id,o,a]);(0,V.useEffect)(()=>{w()},[w]);let T=async()=>{try{let t=await W.issueEmbedSession(e.id),n=`csai-plugin-standalone-${Date.now()}`;window.open(`about:blank`,n,`noopener`),De(t.action,t.ticket,n)}catch(e){L(H(a,e,a(`pluginHub.embedInitFailed`,null,`无法打开独立窗口`)))}};return(0,V.useEffect)(()=>{let e=()=>{document.fullscreenElement||C(!1)};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]),(0,G.jsxs)(`div`,{ref:s,className:`cs-ph-workspace ${S?`is-expanded`:``}`,children:[(0,G.jsxs)(`div`,{className:`cs-ph-workspace-bar`,children:[(0,G.jsxs)(`div`,{className:`cs-ph-workspace-title`,children:[(0,G.jsx)(p,{size:`small`,theme:`borderless`,icon:(0,G.jsx)(_,{}),onClick:n,children:a(`pluginHub.backToHub`,null,`返回能力平台`)}),(0,G.jsx)(Ee,{strong:!0,ellipsis:!0,style:{maxWidth:260},children:e.title||e.plugin_id}),(0,G.jsx)(d,{size:`small`,color:Se(e.observed_state),shape:`square`,children:Ce(a,e.observed_state)}),v?.origin&&(0,G.jsx)(Ee,{type:`tertiary`,size:`small`,className:`cs-ph-mono`,ellipsis:!0,style:{maxWidth:260},children:v.origin})]}),(0,G.jsxs)(c,{spacing:6,wrap:!0,children:[(0,G.jsx)(D,{content:a(`pluginHub.reconnectSession`,null,`刷新 / 重新建立隔离会话`),children:(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(M,{}),onClick:w,loading:l,children:a(`common.refresh`,null,`刷新`)})}),(0,G.jsx)(D,{content:a(`pluginHub.openFirstPartyTip`,null,`若浏览器严格拦截跨站 Cookie,可在独立首方窗口中打开`),children:(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(u,{}),onClick:T,children:a(`pluginHub.openStandalone`,null,`独立窗口`)})}),t&&(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(x,{}),onClick:i,children:a(`pluginHub.logs`,null,`日志`)}),(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(O,{}),onClick:r,children:a(`pluginHub.settingsAndDetail`,null,`详情与模型`)}),(0,G.jsx)(p,{size:`small`,icon:S?(0,G.jsx)(y,{}):(0,G.jsx)(N,{}),onClick:async()=>{let e=s.current;if(e){if(document.fullscreenElement){try{await document.exitFullscreen()}catch{}C(!1)}else{if(e.requestFullscreen)try{await e.requestFullscreen(),C(!0);return}catch{}C(e=>!e)}}},children:S?a(`pluginHub.exitFullscreen`,null,`退出全屏`):a(`mobile.fullscreen`,null,`全屏`)})]})]}),(0,G.jsxs)(`div`,{className:`cs-ph-workspace-frame-wrap`,children:[(0,G.jsx)(`iframe`,{name:o,title:e.title||e.plugin_id,className:`cs-ph-workspace-iframe`,sandbox:`allow-scripts allow-same-origin allow-forms allow-downloads`,allow:`clipboard-read; clipboard-write`,onLoad:()=>f(!1)}),l&&!m&&(0,G.jsxs)(`div`,{className:`cs-ph-workspace-overlay`,children:[(0,G.jsx)(g,{size:`large`}),(0,G.jsx)(Ee,{type:`tertiary`,children:a(`pluginHub.connectingWorkspace`,null,`正在建立隔离代理会话并加载插件页面…`)})]}),m&&(0,G.jsxs)(`div`,{className:`cs-ph-workspace-overlay`,children:[(0,G.jsx)(Ee,{type:`danger`,strong:!0,children:m}),(0,G.jsx)(Ee,{type:`tertiary`,size:`small`,children:a(`pluginHub.embedTroubleshooting`,null,`请确认插件处于运行中状态;若浏览器限制跨站 Cookie,可点击上方「独立窗口」以首方会话打开。`)}),(0,G.jsxs)(c,{children:[(0,G.jsx)(p,{theme:`solid`,type:`primary`,onClick:w,children:a(`pluginHub.retryConnect`,null,`重试连接`)}),(0,G.jsx)(p,{icon:(0,G.jsx)(u,{}),onClick:T,children:a(`pluginHub.openStandalone`,null,`独立窗口`)})]})]})]})]})}var{Text:K,Paragraph:q}=s;function ke({planResponse:e,channels:t,visible:n,canUseAgent:r,onCancel:i,onConfirmed:o,onAskAgentDriverFix:s}){let l=P(),[m,h]=(0,V.useState)(!0),[g,_]=(0,V.useState)(!1),[y,b]=(0,V.useState)(null),[x,S]=(0,V.useState)(!1);(0,V.useEffect)(()=>{n&&(h(!0),b(e?.driver_probe||null))},[n,e?.plan?.id,e?.driver_probe]);let C=e?.plan,w=e?.manifest,T=C?.artifact,E=y||e?.driver_probe||null,D=!(!E||E.available),O=!!w?.llm?.bindings?.length,k=(0,V.useMemo)(()=>(t||[]).find(e=>e.is_default)||(t||[])[0]||null,[t]),ee=(0,V.useMemo)(()=>!O||!k?!1:w.llm.bindings.some(e=>e.protocol===k.protocol),[O,k,w]);return(0,G.jsx)(le,{title:l(`pluginHub.planApprovalTitle`,null,`确认插件安装计划`),visible:n,onCancel:i,width:680,footer:(0,G.jsxs)(c,{children:[(0,G.jsx)(p,{onClick:i,children:l(`common.cancel`,null,`取消`)}),(0,G.jsx)(p,{theme:`solid`,type:`primary`,loading:g,disabled:!e?.can_confirm||D,onClick:async()=>{if(C&&e?.plan_digest){_(!0);try{let t=await W.install({planId:C.id,planDigest:e.plan_digest,autoBindLLM:O?m:void 0});B(l(`pluginHub.installQueued`,null,`安装任务已提交,正在后台准备并启动`)),o?.(t)}catch(e){L(H(l,e,l(`pluginHub.installFailed`,null,`提交安装失败`)))}finally{_(!1)}}},children:D?l(`pluginHub.driverMissingBtn`,null,`缺少运行驱动,请先安装依赖`):l(`pluginHub.confirmInstall`,null,`确认并一键安装`)})]}),children:C&&w&&(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,children:[D&&(0,G.jsx)(a,{type:`danger`,bordered:!0,closeIcon:null,title:l(`pluginHub.driverMissingTitle`,{driver:U(l,T?.driver)},`当前宿主机缺少所需驱动:${U(l,T?.driver)}`),description:(0,G.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8,marginTop:4},children:[(0,G.jsx)(K,{size:`small`,children:H(l,E.code,E.guidance)}),E.install_command&&(0,G.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,flexWrap:`wrap`},children:[(0,G.jsx)(`code`,{className:`cs-ph-mono`,style:{fontSize:12,padding:`4px 8px`,borderRadius:4,background:`var(--semi-color-fill-1)`,wordBreak:`break-all`},children:E.install_command}),(0,G.jsx)(fe,{text:E.install_command,label:l(`common.copy`,null,`复制`)})]}),(0,G.jsxs)(c,{wrap:!0,children:[r&&s&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,icon:(0,G.jsx)(v,{}),onClick:()=>s({driver:T?.driver,probe:E,hostOS:e.host_os,hostArch:e.host_arch,pluginTitle:w.metadata?.title||w.metadata?.id}),children:l(`pluginHub.askAgentInstallDriver`,null,`交给 CSAI Agent 自动安装配置`)}),E.download_url&&(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(u,{}),onClick:()=>window.open(E.download_url,`_blank`,`noopener,noreferrer`),children:l(`pluginHub.officialDownload`,null,`官方下载`)}),(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(M,{}),loading:x,onClick:async()=>{if(C&&T?.driver){S(!0);try{let e=await W.probes(C.isolation||`standard`),t=(w?.distribution||[]).some(e=>e.type===T.driver&&e.mode===`compose`),n=T.driver===`container`&&t?`compose`:T.driver,r=e?.drivers?.[n]||e?.drivers?.[T.driver];r&&(b(r),r.available&&B(l(`pluginHub.driverNowReady`,null,`运行驱动已就绪,可以继续一键安装`)))}catch(e){L(H(l,e))}finally{S(!1)}}},children:l(`pluginHub.recheckDriver`,null,`重新检测`)})]})]})}),!e.can_confirm&&(0,G.jsx)(a,{type:`warning`,bordered:!0,closeIcon:null,description:l(`pluginHub.hostApprovalRequiredBanner`,null,`当前宿主开启了 host_config_only 策略,需要先将下方 Manifest 与制品摘要写入 config.yaml 的 plugins.approved_artifacts 后方可安装。`)}),(0,G.jsx)(R,{columns:2,items:[{label:l(`pluginHub.pluginTitle`,null,`插件名称`),value:`${w.metadata?.title||w.metadata?.id} (${w.metadata?.version||`—`})`},{label:l(`pluginHub.repository`,null,`原作者仓库`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:w.metadata?.repository})},{label:l(`pluginHub.driver`,null,`运行驱动`),value:U(l,T?.driver)},{label:l(`pluginHub.isolation`,null,`隔离档位`),value:C.isolation},{label:l(`pluginHub.platform`,null,`目标平台`),value:`${C.platform?.os}/${C.platform?.arch}`},{label:l(`pluginHub.approvalPolicy`,null,`审批策略`),value:e.approval_policy||`admin_confirm`},{label:`Manifest SHA-256`,value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:C.manifestSha256})},{label:l(`pluginHub.artifactDigest`,null,`锁定制品摘要`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:e.artifact_digest})}]}),T?.driver===`git`&&(0,G.jsx)(R,{columns:1,items:[{label:l(`pluginHub.lockedCommit`,null,`锁定 Git Commit`),value:(0,G.jsxs)(`span`,{className:`cs-ph-mono`,children:[T.commit,` (`,T.requestedRef,`)`]})}]}),T?.driver===`release`&&(0,G.jsx)(R,{columns:1,items:[{label:l(`pluginHub.lockedReleaseAsset`,null,`锁定 Release 制品`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:T.assetURL})},{label:`SHA-256`,value:(0,G.jsxs)(`span`,{className:`cs-ph-mono`,children:[T.sha256,` (`,T.verification,`)`]})}]}),T?.driver===`container`&&Array.isArray(T.services)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,children:l(`pluginHub.lockedImages`,null,`锁定容器镜像 Digest`)}),(0,G.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6,marginTop:6},children:T.services.map(e=>(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsxs)(c,{children:[(0,G.jsx)(d,{color:`blue`,size:`small`,children:e.name}),(0,G.jsx)(K,{size:`small`,className:`cs-ph-mono`,children:e.requestedImage})]}),(0,G.jsxs)(K,{type:`tertiary`,size:`small`,className:`cs-ph-mono`,children:[e.repository,`@`,e.manifestDigest]})]},e.name))})]}),(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsx)(K,{strong:!0,children:l(`pluginHub.declaredPermissions`,null,`声明权限摘要`)}),(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsxs)(d,{color:w.permissions?.persistentData?`amber`:`grey`,children:[l(`pluginHub.permPersistentData`,null,`持久化数据卷`),`: `,w.permissions?.persistentData?`Yes`:`No`]}),(0,G.jsxs)(d,{color:w.permissions?.modelGateway?`blue`:`grey`,children:[l(`pluginHub.permModelGateway`,null,`CSAI 模型网关`),`: `,w.permissions?.modelGateway?`Yes`:`No`]}),(w.permissions?.egress||[]).map(e=>(0,G.jsx)(d,{color:`purple`,children:e},e))]})]}),O&&(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsx)(f,{checked:m,onChange:e=>h(!!e.target.checked),children:l(`pluginHub.autoBindDefaultLLM`,null,`安装时自动复用 CSAI 默认模型通道(开箱即用,不泄露真实上游 API Key)`)}),k?(0,G.jsx)(K,{type:`tertiary`,size:`small`,children:ee?l(`pluginHub.defaultChannelMatch`,{name:`${k.name} (${k.model})`},`当前默认通道:${k.name} (${k.model}),协议匹配,启动即自动注入。`):l(`pluginHub.defaultChannelMismatch`,{name:`${k.name} (${k.protocol})`},`当前默认通道 ${k.name} (${k.protocol}) 与该插件声明协议不同,安装后可在插件设置中指定通道。`)}):(0,G.jsx)(K,{type:`tertiary`,size:`small`,children:l(`pluginHub.noDefaultChannelHint`,null,`尚未在 CSAI 系统设置中配置模型通道,安装后可随时在插件详情中绑定模型。`)})]}),(0,G.jsx)(he,{value:w,collapsed:!0,title:`Manifest`})]})})}function Ae({visible:e,onCancel:t,onSaved:n}){let r=P(),[i,a]=(0,V.useState)(``),[o,s]=(0,V.useState)(``),[l,u]=(0,V.useState)(``),[d,f]=(0,V.useState)(``),[g,_]=(0,V.useState)(``),[v,y]=(0,V.useState)(``),[b,x]=(0,V.useState)(!1),[S,C]=(0,V.useState)(!1);(0,V.useEffect)(()=>{e&&(a(``),s(``),u(``),f(``),_(``),y(``))},[e]);let w=e=>{let t=String(e||``).trim().replace(/\.git$/i,``).replace(/\/+$/,``).split(`/`).pop()||``;return{seg:t,slug:t.toLowerCase().replace(/[^a-z0-9-]+/g,`-`).replace(/^-+|-+$/g,``)}};return(0,G.jsx)(le,{title:r(`pluginHub.addCatalogTitle`,null,`新增能力市场插件`),visible:e,onCancel:t,width:680,footer:(0,G.jsxs)(c,{children:[(0,G.jsx)(p,{onClick:t,children:r(`common.cancel`,null,`取消`)}),(0,G.jsx)(p,{theme:`solid`,type:`primary`,loading:S,onClick:async()=>{if(!i.trim()&&!v.trim())L(r(`pluginHub.catalogRepoRequired`,null,`请填写 GitHub 仓库地址或提供 Manifest`));else{C(!0);try{let e=await W.saveCatalog({id:l.trim(),title:d.trim(),repository:i.trim(),revision:o.trim(),summary:g.trim(),manifest:v.trim()});B(r(`pluginHub.catalogSaved`,null,`已保存到能力市场`)),n?.(e?.item)}catch(e){L(H(r,e,r(`pluginHub.catalogSaveFailed`,null,`保存到能力市场失败`)))}finally{C(!1)}}},children:r(`pluginHub.saveToMarket`,null,`保存到能力市场`)})]}),children:(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,children:[(0,G.jsx)(q,{type:`tertiary`,style:{margin:0},children:r(`pluginHub.addCatalogDesc`,null,`将公开 GitHub 仓库收录到本机能力市场。留空 Manifest 将以「支持探测导入」模式展示;提供合法 YAML/JSON Manifest 后将直接支持「一键下载安装」。`)}),(0,G.jsxs)(c,{style:{width:`100%`},align:`end`,wrap:!0,children:[(0,G.jsxs)(`div`,{style:{flex:2,minWidth:260},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.repositoryURL`,null,`GitHub 仓库地址`)}),(0,G.jsx)(h,{value:i,onChange:e=>{a(e);let{seg:t,slug:n}=w(e);!l&&n&&/^[a-z]/.test(n)&&u(n),!d&&t&&f(t)},placeholder:`https://github.com/owner/repo`,style:{marginTop:4}})]}),(0,G.jsxs)(`div`,{style:{flex:1,minWidth:130},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.revisionOptional`,null,`分支 / Tag(可选)`)}),(0,G.jsx)(h,{value:o,onChange:s,placeholder:`main / v1.0.0`,style:{marginTop:4}})]}),(0,G.jsx)(p,{loading:b,onClick:async()=>{if(i.trim()){x(!0);try{let e=(await W.inspectGit(i,o))?.inspection;if(e?.repository&&a(e.repository),e?.manifest){let t=e.manifest;t.metadata?.id&&u(t.metadata.id),t.metadata?.title&&f(t.metadata.title),t.metadata?.summary&&_(t.metadata.summary),y(JSON.stringify(t,null,2)),B(r(`pluginHub.catalogProbeWithManifest`,null,`已探测到仓库自带 Manifest,保存后支持一键安装`))}else{let{seg:t,slug:n}=w(e?.repository||i);!l&&n&&/^[a-z]/.test(n)&&u(n),!d&&t&&f(t),B(r(`pluginHub.catalogProbeSuccess`,null,`仓库只读探测完成,已自动填充基础信息`))}}catch(e){L(H(r,e,r(`pluginHub.inspectFailed`,null,`探测仓库失败`)))}finally{x(!1)}}},disabled:!i.trim(),children:r(`pluginHub.probeAndFill`,null,`探测并自动填充`)})]}),(0,G.jsxs)(c,{style:{width:`100%`},wrap:!0,children:[(0,G.jsxs)(`div`,{style:{flex:1,minWidth:220},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.pluginId`,null,`插件标识 ID`)}),(0,G.jsx)(h,{value:l,onChange:u,placeholder:`my-security-tool`,style:{marginTop:4}})]}),(0,G.jsxs)(`div`,{style:{flex:1,minWidth:220},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.pluginTitle`,null,`显示名称`)}),(0,G.jsx)(h,{value:d,onChange:f,placeholder:`My Security Tool`,style:{marginTop:4}})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.catalogSummaryLabel`,null,`功能简介`)}),(0,G.jsx)(h,{value:g,onChange:_,placeholder:r(`pluginHub.catalogSummaryPlaceholder`,null,`简述该开源安全工具的用途、架构或特性`),style:{marginTop:4}})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.catalogManifestOptional`,null,`插件 Manifest(可选,支持 YAML 或 JSON)`)}),(0,G.jsx)(m,{className:`cs-ph-code-editor`,value:v,onChange:y,placeholder:r(`pluginHub.catalogManifestPlaceholder`,null,`可选:粘贴 csai-plugin.yaml 或 JSON 声明;点击上方「探测并自动填充」可自动抓取仓库根目录的 csai-plugin.yaml`),autosize:{minRows:8,maxRows:18},style:{marginTop:4}})]})]})})}function je({visible:e,initialEntry:t,onCancel:n,onPlanReady:r,onCatalogSaved:i}){let a=P(),[o,s]=(0,V.useState)(``),[l,u]=(0,V.useState)(``),[f,g]=(0,V.useState)(!1),[_,v]=(0,V.useState)(null),[y,b]=(0,V.useState)(``),[x,S]=(0,V.useState)(`auto`),[C,w]=(0,V.useState)(`standard`),[T,E]=(0,V.useState)(!1),[D,O]=(0,V.useState)(!1);(0,V.useEffect)(()=>{e&&t?.repository&&(s(t.repository),u(t.revision||``),v(null),b(``))},[e,t]);let k=async()=>{if(o.trim()){g(!0),v(null);try{let e=await W.inspectGit(o,l);v(e),e?.inspection?.manifest?b(JSON.stringify(e.inspection.manifest,null,2)):b(Te(e?.inspection)),B(a(`pluginHub.inspectSucceeded`,null,`仓库只读探测完成`))}catch(e){L(H(a,e,a(`pluginHub.inspectFailed`,null,`探测仓库失败`)))}finally{g(!1)}}},ee=async()=>{if(!_?.id)return;let e;try{e=JSON.parse(y)}catch{L(a(`pluginHub.manifestJsonInvalid`,null,`Manifest 草案需为合法 JSON 格式`));return}E(!0);try{let t=await W.createPlan({inspection_id:_.id,manifest:e,driver:x,isolation:C});r?.(t)}catch(e){L(H(a,e,a(`pluginHub.createPlanFailed`,null,`生成锁定安装计划失败`)))}finally{E(!1)}},A=async()=>{if(_?.inspection){O(!0);try{await W.saveCatalog({repository:_.inspection.repository||o.trim(),revision:l.trim(),manifest:y.trim()}),B(a(`pluginHub.catalogSaved`,null,`已保存到能力市场`)),i?.()}catch(e){L(H(a,e,a(`pluginHub.catalogSaveFailed`,null,`保存到能力市场失败`)))}finally{O(!1)}}},j=_?.inspection;return(0,G.jsx)(le,{title:a(`pluginHub.importTitle`,null,`手工导入 Git 仓库插件`),visible:e,onCancel:n,width:720,footer:(0,G.jsxs)(c,{children:[(0,G.jsx)(p,{onClick:n,children:a(`common.cancel`,null,`取消`)}),(0,G.jsx)(p,{loading:D,disabled:!_?.inspection||!y.trim(),onClick:A,children:a(`pluginHub.saveToMarket`,null,`保存到能力市场`)}),(0,G.jsx)(p,{theme:`solid`,type:`primary`,loading:T,disabled:!_?.id||!y.trim(),onClick:ee,children:a(`pluginHub.generatePlan`,null,`生成锁定安装计划`)})]}),children:(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,children:[(0,G.jsx)(q,{type:`tertiary`,style:{margin:0},children:a(`pluginHub.importDesc`,null,`输入公开 GitHub HTTPS 仓库地址后,CSAI 会以只读方式解析 Commit、根目录 csai-plugin.yaml 及构建/容器线索,不会执行任何第三方代码。`)}),(0,G.jsxs)(c,{style:{width:`100%`},align:`end`,wrap:!0,children:[(0,G.jsxs)(`div`,{style:{flex:2,minWidth:280},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:a(`pluginHub.repositoryURL`,null,`GitHub 仓库地址`)}),(0,G.jsx)(h,{value:o,onChange:s,placeholder:`https://github.com/owner/repo`,style:{marginTop:4}})]}),(0,G.jsxs)(`div`,{style:{flex:1,minWidth:140},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:a(`pluginHub.revisionOptional`,null,`分支 / Tag / Commit(可选)`)}),(0,G.jsx)(h,{value:l,onChange:u,placeholder:`main / v1.0.0`,style:{marginTop:4}})]}),(0,G.jsx)(p,{theme:`solid`,type:`primary`,loading:f,onClick:k,children:a(`pluginHub.inspectRepo`,null,`只读探测`)})]}),j&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsx)(R,{columns:2,items:[{label:a(`pluginHub.repository`,null,`标准化仓库`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:j.repository})},{label:a(`pluginHub.resolvedRef`,null,`解析引用`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:j.resolved_ref})},{label:`Commit`,value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:j.commit})},{label:a(`pluginHub.detectedCandidates`,null,`候选驱动`),value:(j.candidates||[]).map(e=>(0,G.jsx)(d,{size:`small`,style:{marginInlineEnd:4},children:e},e))}]}),j.evidence?.length>0&&(0,G.jsxs)(c,{wrap:!0,style:{marginTop:6},children:[(0,G.jsxs)(K,{size:`small`,type:`tertiary`,children:[a(`pluginHub.detectedFiles`,null,`检测到文件`),`:`]}),j.evidence.map(e=>(0,G.jsx)(d,{size:`small`,color:`cyan`,children:e},e))]}),j.release?.tag&&(0,G.jsxs)(K,{size:`small`,type:`tertiary`,children:[`Release `,j.release.tag,`: `,(j.release.assets||[]).slice(0,6).join(`, `)||`—`]})]}),(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:a(`pluginHub.driver`,null,`安装驱动`)}),(0,G.jsx)(ie,{value:x,onChange:S,style:{width:240,display:`block`,marginTop:4},optionList:[{value:`auto`,label:U(a,`auto`)},{value:`release`,label:U(a,`release`)},{value:`git`,label:U(a,`git`)},{value:`container`,label:U(a,`container`)}]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:a(`pluginHub.isolation`,null,`隔离档位`)}),(0,G.jsx)(ie,{value:C,onChange:w,style:{width:200,display:`block`,marginTop:4},optionList:[{value:`standard`,label:a(`pluginHub.isolationStandard`,null,`standard(非 root 单机默认)`)},{value:`strict`,label:a(`pluginHub.isolationStrict`,null,`strict(强制容器隔离)`)}]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(c,{style:{justifyContent:`space-between`,width:`100%`,marginBottom:4},children:(0,G.jsx)(K,{strong:!0,size:`small`,children:j.manifest?a(`pluginHub.manifestFromRepo`,null,`已从仓库读取 csai-plugin.yaml(可审阅)`):a(`pluginHub.manifestDraftLabel`,null,`仓库无自带 Manifest,请编辑以下接入草案(JSON)`)})}),(0,G.jsx)(m,{className:`cs-ph-code-editor`,value:y,onChange:b,autosize:{minRows:12,maxRows:22}})]})]})]})})}function Me({installId:e,initialTab:t=`overview`,visible:n,canManage:r,canUseAgent:i,channels:o,onCancel:s,onRestartRequested:l,onChanged:u,onAskAgentTroubleshoot:f}){let m=P(),[h,g]=(0,V.useState)(t),[_,y]=(0,V.useState)(null),[x,S]=(0,V.useState)(!1),[T,D]=(0,V.useState)(`follow_default`),[O,k]=(0,V.useState)(``),[ee,A]=(0,V.useState)(4),[j,te]=(0,V.useState)(60),[ne,N]=(0,V.useState)(2e6),[ae,oe]=(0,V.useState)(!1),[se,F]=(0,V.useState)(!1),[ce,I]=(0,V.useState)([]),[ue,de]=(0,V.useState)(!1),pe=(0,V.useRef)(null),z=(0,V.useRef)(null);(0,V.useEffect)(()=>{n&&g(t||`overview`)},[n,t,e]);let me=async()=>{if(e){S(!0);try{let t=await W.getInstall(e);y(t);let n=Array.isArray(t?.llm_bindings)?t.llm_bindings[0]:null;n?(D(n.mode||`follow_default`),k(n.channel_id||``),A(n.concurrency||4),te(n.rpm||60),N(n.token_budget||2e6)):(D(`follow_default`),k(``)),F(!1)}catch(e){L(H(m,e))}finally{S(!1)}}};(0,V.useEffect)(()=>{n&&e&&me()},[n,e]),(0,V.useEffect)(()=>{if(!n||!e||h!==`logs`||!r){z.current?.(),z.current=null,de(!1);return}let t=!0;return I([]),(async()=>{try{let n=await W.readLogs(e,0,200);if(!t)return;let r=Array.isArray(n?.items)?n.items:[];I(r),de(!0),z.current=we(e,{after:n?.next_cursor||0,onEntry:e=>{I(t=>[...t.slice(-499),e])},onClose:()=>de(!1),onError:()=>de(!1)})}catch(e){t&&L(H(m,e))}})(),()=>{t=!1,z.current?.(),z.current=null,de(!1)}},[n,e,h,r]),(0,V.useEffect)(()=>{pe.current&&(pe.current.scrollTop=pe.current.scrollHeight)},[ce]);let he=async()=>{if(e){oe(!0);try{let t={mode:T,channel_id:T===`channel`?O:``,limits:{concurrency:Number(ee)||4,rpm:Number(j)||60,token_budget:Number(ne)||2e6}},n=await W.patchLLM(e,t);B(m(`pluginHub.llmSaved`,null,`模型通道绑定已更新`)),F(!!n?.restart_required),await me(),u?.()}catch(e){L(H(m,e,m(`pluginHub.llmSaveFailed`,null,`保存模型配置失败`)))}finally{oe(!1)}}},ge=(0,V.useMemo)(()=>new Set((_?.llm_declared?.bindings||[]).map(e=>e.protocol)),[_]),_e=(0,V.useMemo)(()=>(o||[]).filter(e=>ge.size===0||ge.has(e.protocol)),[o,ge]),ve=(0,V.useMemo)(()=>ce.map(e=>`[${e.created_at||``}] ${e.line}`).join(`
+`),[ce]);return(0,G.jsxs)(le,{title:_?.title||_?.plugin_id||m(`pluginHub.detailTitle`,null,`插件详情`),visible:n,onCancel:s,width:760,children:[(0,G.jsxs)(b,{activeKey:h,onChange:g,children:[(0,G.jsx)(w,{tab:m(`pluginHub.tabOverview`,null,`概览与权限`),itemKey:`overview`,children:_&&(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,style:{marginTop:12},children:[(_.observed_state===`failed`||_.observed_state===`degraded`)&&(0,G.jsx)(a,{type:`danger`,bordered:!0,closeIcon:null,title:H(m,_.last_error_code,m(`pluginHub.errorInstallFailed`,null,`插件安装或运行异常`)),description:(0,G.jsxs)(c,{wrap:!0,style:{marginTop:4},children:[i&&f&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,icon:(0,G.jsx)(v,{}),onClick:()=>f(_),children:m(`pluginHub.askAgentTroubleshoot`,null,`交给 CSAI Agent 排错并修复`)}),r&&(0,G.jsx)(p,{size:`small`,onClick:()=>g(`logs`),children:m(`pluginHub.viewLogs`,null,`查看运行日志`)})]})}),(0,G.jsx)(R,{columns:2,items:[{label:m(`pluginHub.installId`,null,`实例 ID`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:_.id})},{label:m(`pluginHub.pluginId`,null,`插件标识`),value:_.plugin_id},{label:m(`pluginHub.version`,null,`版本`),value:_.version||`—`},{label:m(`pluginHub.driver`,null,`驱动`),value:U(m,_.driver)},{label:m(`pluginHub.observedState`,null,`运行状态`),value:(0,G.jsx)(d,{color:Se(_.observed_state),children:Ce(m,_.observed_state)})},{label:m(`pluginHub.proxyMode`,null,`代理隔离模式`),value:_.proxy_mode||`port`},{label:m(`pluginHub.repository`,null,`源码仓库`),value:_.repository?(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:_.repository}):`—`},{label:m(`pluginHub.lastError`,null,`最近错误`),value:_.last_error_code||`—`}]}),_.summary&&(0,G.jsx)(q,{type:`tertiary`,children:_.summary}),_.permissions&&(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsx)(K,{strong:!0,children:m(`pluginHub.declaredPermissions`,null,`声明权限`)}),(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsxs)(d,{children:[m(`pluginHub.permPersistentData`,null,`持久化数据卷`),`: `,_.permissions.persistentData?`Yes`:`No`]}),(0,G.jsxs)(d,{children:[m(`pluginHub.permModelGateway`,null,`CSAI 模型网关`),`: `,_.permissions.modelGateway?`Yes`:`No`]}),(_.permissions.egress||[]).map(e=>(0,G.jsx)(d,{color:`purple`,children:e},e))]})]}),_.extensions?.capabilities?.length>0&&(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsx)(K,{strong:!0,children:m(`pluginHub.declaredExtensions`,null,`声明的扩展能力(MCP / OpenAPI 预留)`)}),(0,G.jsx)(c,{wrap:!0,children:_.extensions.capabilities.map(e=>(0,G.jsxs)(d,{color:`cyan`,children:[e.id,` (`,e.transport,` `,e.path,`)`]},e.id))})]})]})}),_?.llm_declared&&(0,G.jsx)(w,{tab:m(`pluginHub.tabLLM`,null,`CSAI 模型绑定`),itemKey:`llm`,children:(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,style:{marginTop:12},children:[se&&(0,G.jsx)(a,{type:`info`,bordered:!0,closeIcon:null,description:(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsx)(`span`,{children:m(`pluginHub.restartRequiredForLLM`,null,`模型绑定已更新,重启插件后将立即注入新的 CSAI 网关凭据。`)}),r&&l&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,onClick:()=>l(_),children:m(`pluginHub.restartNow`,null,`立即重启生效`)})]})}),(0,G.jsx)(q,{type:`tertiary`,style:{margin:0},children:m(`pluginHub.llmBindingDesc`,null,`CSAI 通过本地模型网关向插件注入隔离 Token 与通道配置,插件无法接触您的真实上游 API Key。`)}),(0,G.jsxs)(C,{value:T,onChange:e=>D(e.target.value),disabled:!r,children:[(0,G.jsx)(E,{value:`follow_default`,children:m(`pluginHub.llmModeFollowDefault`,null,`跟随 CSAI 默认模型通道`)}),(0,G.jsx)(E,{value:`channel`,children:m(`pluginHub.llmModeChannel`,null,`指定 CSAI 模型通道`)}),(0,G.jsx)(E,{value:`disabled`,children:m(`pluginHub.llmModeDisabled`,null,`关闭模型托管`)})]}),T===`channel`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:m(`pluginHub.selectChannel`,null,`选择兼容通道`)}),(0,G.jsx)(ie,{value:O,onChange:k,disabled:!r,style:{width:`100%`,marginTop:4},placeholder:m(`pluginHub.selectChannelPlaceholder`,null,`请选择在 CSAI 系统设置中配置的模型通道`),optionList:_e.map(e=>({value:e.id,label:`${e.name} (${e.model} · ${e.provider})${e.is_default?` [Default]`:``}`}))})]}),T!==`disabled`&&(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{size:`small`,type:`tertiary`,children:m(`pluginHub.limitConcurrency`,null,`并发上限`)}),(0,G.jsx)(re,{value:ee,onChange:A,min:1,max:32,disabled:!r,style:{display:`block`,marginTop:4}})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{size:`small`,type:`tertiary`,children:m(`pluginHub.limitRPM`,null,`每分钟请求 (RPM)`)}),(0,G.jsx)(re,{value:j,onChange:te,min:1,max:1e3,disabled:!r,style:{display:`block`,marginTop:4}})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{size:`small`,type:`tertiary`,children:m(`pluginHub.limitTokenBudget`,null,`每日 Token 预算`)}),(0,G.jsx)(re,{value:ne,onChange:N,min:1e3,step:1e5,disabled:!r,style:{display:`block`,marginTop:4,width:180}})]})]}),r&&(0,G.jsx)(`div`,{children:(0,G.jsx)(p,{theme:`solid`,type:`primary`,loading:ae,onClick:he,children:m(`pluginHub.saveLLM`,null,`保存模型配置`)})})]})}),r&&(0,G.jsx)(w,{tab:m(`pluginHub.logs`,null,`运行日志`),itemKey:`logs`,children:(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,style:{marginTop:12},children:[(0,G.jsxs)(c,{style:{justifyContent:`space-between`,width:`100%`},children:[(0,G.jsxs)(c,{children:[(0,G.jsx)(d,{color:ue?`green`:`grey`,children:ue?m(`pluginHub.logStreaming`,null,`SSE 实时追踪中`):m(`pluginHub.logPaused`,null,`已停止追踪`)}),(0,G.jsxs)(K,{size:`small`,type:`tertiary`,children:[ce.length,` lines`]})]}),(0,G.jsxs)(c,{children:[(0,G.jsx)(fe,{text:ve,label:m(`common.copy`,null,`复制`)}),(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(M,{}),onClick:()=>g(`overview`)||setTimeout(()=>g(`logs`),0),children:m(`common.refresh`,null,`刷新`)})]})]}),(0,G.jsx)(`pre`,{ref:pe,className:`cs-ph-log-box`,children:ve||m(`pluginHub.noLogs`,null,`暂无运行日志`)})]})})]}),x&&!_&&(0,G.jsx)(K,{type:`tertiary`,children:m(`common.loading`,null,`加载中…`)})]})}function Ne({visible:e,canUseAgent:t,onCancel:n,onAskAgentDriverFix:r}){let i=P(),[o,s]=(0,V.useState)(`standard`),[l,f]=(0,V.useState)(null),[m,h]=(0,V.useState)(!1),g=async(e=o)=>{h(!0);try{let t=await W.probes(e);f(t)}catch(e){L(H(i,e))}finally{h(!1)}};return(0,V.useEffect)(()=>{e&&g(o)},[e,o]),(0,G.jsx)(le,{title:i(`pluginHub.runtimeProbesTitle`,null,`宿主运行环境与驱动预检`),visible:e,onCancel:n,width:660,children:(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,children:[(0,G.jsxs)(c,{style:{justifyContent:`space-between`,width:`100%`},wrap:!0,children:[(0,G.jsxs)(C,{type:`button`,value:o,onChange:e=>s(e.target.value),children:[(0,G.jsx)(E,{value:`standard`,children:`standard`}),(0,G.jsx)(E,{value:`strict`,children:`strict`})]}),(0,G.jsx)(p,{icon:(0,G.jsx)(M,{}),loading:m,onClick:()=>g(o),children:i(`common.refresh`,null,`重新检测`)})]}),l&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(R,{columns:2,items:[{label:i(`pluginHub.hostPlatform`,null,`宿主平台`),value:`${l.os}/${l.arch}`},{label:i(`pluginHub.workerReady`,null,`运行调度器`),value:(0,G.jsx)(d,{color:l.execution_enabled?`green`:`amber`,children:l.execution_enabled?i(`pluginHub.ready`,null,`就绪`):i(`pluginHub.notReady`,null,`未就绪`)})}]}),Object.entries(l.drivers||{}).map(([e,n])=>(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsxs)(c,{style:{justifyContent:`space-between`,width:`100%`},children:[(0,G.jsx)(K,{strong:!0,children:U(i,e)}),(0,G.jsx)(d,{color:n.available?`green`:`red`,prefixIcon:n.available?(0,G.jsx)(A,{}):(0,G.jsx)(te,{}),children:n.available?i(`pluginHub.available`,null,`可用`):n.code||i(`pluginHub.unavailable`,null,`不可用`)})]}),!n.available&&n.code&&(0,G.jsx)(K,{type:`danger`,size:`small`,children:H(i,n.code,n.guidance)}),n.guidance&&(0,G.jsx)(K,{type:`tertiary`,size:`small`,children:n.guidance}),!n.available&&n.install_command&&(0,G.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,flexWrap:`wrap`,marginTop:4},children:[(0,G.jsx)(`code`,{className:`cs-ph-mono`,style:{fontSize:12,padding:`4px 8px`,borderRadius:4,background:`var(--semi-color-fill-1)`,wordBreak:`break-all`},children:n.install_command}),(0,G.jsx)(fe,{text:n.install_command,label:i(`common.copy`,null,`复制`)})]}),!n.available&&(t||n.download_url)&&(0,G.jsxs)(c,{wrap:!0,style:{marginTop:6},children:[t&&r&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,icon:(0,G.jsx)(v,{}),onClick:()=>r({driver:e,probe:n,hostOS:l.os,hostArch:l.arch}),children:i(`pluginHub.askAgentInstallDriver`,null,`交给 CSAI Agent 自动安装配置`)}),n.download_url&&(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(u,{}),onClick:()=>window.open(n.download_url,`_blank`,`noopener,noreferrer`),children:i(`pluginHub.officialDownload`,null,`官方下载`)})]})]},e)),l.drivers?.container&&!l.drivers.container.available&&(0,G.jsx)(a,{type:`info`,bordered:!0,closeIcon:null,description:l.os===`linux`?i(`pluginHub.dockerInstallLinuxHint`,null,`Linux / Kali 宿主可直接点击上方「交给 CSAI Agent 自动安装配置」,或手动安装 docker.io 与 docker-compose-plugin 并启动 dockerd,完成后点击「重新检测」。`):i(`pluginHub.dockerInstallDesktopHint`,null,`macOS / Windows 可点击「官方下载」安装并启动 Docker Desktop(或交给 Agent 通过 Homebrew/winget 协助安装),也可优先选择 Release / Git 原生驱动。`)})]})]})})}var{Text:J,Paragraph:Pe}=s;function Y(){let e=P(),t=n(),{hasPermission:r}=se(),s=r(`plugins:manage`),m=r(`plugins:use`),g=r(`chat:write`)&&r(`agent:execute`),[_,y]=i(),C=_.get(`app`)||``,E=_.get(`tab`)||`installed`,[A,re]=(0,V.useState)(``),[ie,N]=(0,V.useState)(!1),[ae,F]=(0,V.useState)(null),[le,R]=(0,V.useState)(!1),[fe,he]=(0,V.useState)(!1),[ve,ye]=(0,V.useState)(!1),[we,Te]=(0,V.useState)(null),[Ee,De]=(0,V.useState)(``),[K,q]=(0,V.useState)(null),[Y,Fe]=(0,V.useState)(null),[Ie,Le]=(0,V.useState)(``),X=I(()=>W.listInstalls(),[]),Z=I(()=>W.listCatalog(),[]),Re=I(()=>W.listLLMChannels(),[]),Q=I(()=>W.probes(`standard`),[],{skip:!s}),$=Array.isArray(X.data?.items)?X.data.items:[],ze=Array.isArray(Z.data?.items)?Z.data.items:[],Be=Number(Z.data?.hidden_builtins||0),Ve=Array.isArray(Re.data?.channels)?Re.data.channels:[],He=(0,V.useMemo)(()=>$.find(e=>e.id===C)||null,[$,C]),Ue=e=>{let t=new URLSearchParams(_);t.set(`tab`,e),t.delete(`app`),y(t,{replace:!0})},We=e=>{let t=new URLSearchParams(_);t.set(`tab`,`installed`),t.set(`app`,e.id),y(t)},Ge=()=>{let e=new URLSearchParams(_);e.delete(`app`),y(e,{replace:!0})},Ke=(0,V.useCallback)(()=>{X.reload({silent:!0}),Z.reload({silent:!0}),Re.reload({silent:!0})},[X,Z,Re]);z(async()=>{if(Y?.id&&s)try{let t=await W.getOperation(Y.id);Fe(t),t.status!==`queued`&&t.status!==`running`&&(X.reload({silent:!0}),t.status===`succeeded`?B(e(`pluginHub.opSucceeded`,{kind:t.kind},`操作 ${t.kind} 已完成`)):t.status===`failed`&&L(e(`pluginHub.opFailed`,{kind:t.kind},`操作 ${t.kind} 失败,请查看插件日志`)))}catch{}},Y&&(Y.status===`queued`||Y.status===`running`)?1500:null);let qe=$.some(e=>[`installing`,`starting`,`stopping`].includes(e.observed_state));z(()=>{X.reload({silent:!0})},qe?3e3:null);let Je=async t=>{if(t.availability!==`plan_available`)F({repository:t.repository,revision:t.revision||``}),N(!0);else{De(t.id);try{let e=await W.createPlan({catalog_id:t.id,driver:`auto`,isolation:`standard`});Te(e)}catch(t){L(H(e,t,e(`pluginHub.createPlanFailed`,null,`生成安装计划失败`)))}finally{De(``)}}},Ye=t=>{ge({title:e(`pluginHub.confirmDeleteCatalogTitle`,{name:t.title||t.id},`从能力市场移除「${t.title||t.id}」?`),content:(0,G.jsx)(J,{type:`tertiary`,children:t.builtin?e(`pluginHub.confirmHideBuiltinDesc`,null,`该条目为内置精选目录项,移除后将在市场中隐藏,可随时通过「恢复默认精选」找回;不会影响已安装的实例。`):e(`pluginHub.confirmDeleteCustomDesc`,null,`将从能力市场永久删除该自定义条目,不会影响已安装的插件实例。`)}),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await W.deleteCatalog(t.id),B(e(`pluginHub.catalogDeleted`,null,`已从能力市场移除`)),Z.reload({silent:!0})}catch(t){L(H(e,t,e(`pluginHub.catalogDeleteFailed`,null,`删除市场条目失败`)))}}})},Xe=async()=>{he(!0);try{await W.restoreCatalog(),B(e(`pluginHub.catalogRestored`,null,`已恢复全部默认精选目录`)),Z.reload({silent:!0})}catch(t){L(H(e,t,e(`pluginHub.catalogRestoreFailed`,null,`恢复默认精选失败`)))}finally{he(!1)}},Ze=(0,V.useCallback)(({driver:n,probe:r,hostOS:i,hostArch:a,pluginTitle:o})=>{let s=be({driver:n,probe:r,hostOS:i||Q.data?.os,hostArch:a||Q.data?.arch,pluginTitle:o});_e({prompt:s,autoSend:!0}),ye(!1),Te(null),B(e(`pluginHub.handoffToAgent`,null,`已将安装任务交给 CSAI Agent,正在跳转对话工作台…`)),t(`/chat`)},[t,Q.data?.arch,Q.data?.os,e]),Qe=(0,V.useCallback)(async n=>{let r=[];try{let e=await W.readLogs(n.id,0,50);r=Array.isArray(e?.items)?e.items:[]}catch{}let i=xe({install:n,logs:r,hostOS:Q.data?.os,hostArch:Q.data?.arch});_e({prompt:i,autoSend:!0}),q(null),B(e(`pluginHub.handoffTroubleshoot`,null,`已将排错与修复任务交给 CSAI Agent,正在跳转对话工作台…`)),t(`/chat`)},[t,Q.data?.arch,Q.data?.os,e]),$e=async(t,n,r={})=>{Le(t.id);try{let i=await W.operate(t.id,n,r);Fe(i),B(e(`pluginHub.opQueued`,{kind:n},`已提交 ${n} 任务`)),X.reload({silent:!0})}catch(t){L(H(e,t))}finally{Le(``)}},et=t=>{let n=!1;ge({title:e(`pluginHub.confirmUninstallTitle`,{name:t.title||t.plugin_id},`卸载插件「${t.title||t.plugin_id}」?`),content:(0,G.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,G.jsx)(J,{type:`tertiary`,children:e(`pluginHub.confirmUninstallDesc`,null,`将停止插件进程/容器、撤销代理会话与模型网关 Token,并退役隔离端口。`)}),(0,G.jsx)(f,{onChange:e=>{n=!!e.target.checked},children:e(`pluginHub.purgeDataOption`,null,`同时删除持久化运行数据与卷(默认保留数据)`)})]}),okText:e(`pluginHub.uninstall`,null,`卸载`),onOk:()=>$e(t,`uninstall`,{purge_data:n})})},tt=(0,V.useMemo)(()=>{let e=A.trim().toLowerCase();return e?$.filter(t=>String(t.title||``).toLowerCase().includes(e)||String(t.plugin_id||``).toLowerCase().includes(e)||String(t.driver||``).toLowerCase().includes(e)):$},[$,A]),nt=(0,V.useMemo)(()=>{let e=A.trim().toLowerCase();return e?ze.filter(t=>String(t.title||``).toLowerCase().includes(e)||String(t.id||``).toLowerCase().includes(e)||String(t.summary||``).toLowerCase().includes(e)):ze},[ze,A]),rt=$.filter(e=>e.observed_state===`healthy`).length,it=Q.data?.drivers||{},at=Object.entries(it).filter(([,e])=>e?.available).map(([e])=>e);if(C&&He)return(0,G.jsxs)(`div`,{className:`cs-ph-root`,children:[(0,G.jsx)(Oe,{install:He,canManage:s,onBack:Ge,onOpenDetail:()=>q({id:He.id,tab:`overview`}),onOpenLogs:()=>q({id:He.id,tab:`logs`})}),(0,G.jsx)(Me,{installId:K?.id,initialTab:K?.tab,visible:!!K,canManage:s,canUseAgent:g,channels:Ve,onCancel:()=>q(null),onRestartRequested:e=>$e(e,`restart`),onAskAgentTroubleshoot:Qe,onChanged:Ke})]});let ot=[{title:e(`pluginHub.pluginTitle`,null,`插件应用`),dataIndex:`title`,render:(t,n)=>(0,G.jsxs)(c,{vertical:!0,spacing:2,align:`start`,children:[(0,G.jsxs)(c,{spacing:6,children:[(0,G.jsx)(J,{strong:!0,children:t||n.plugin_id}),(0,G.jsx)(d,{size:`small`,color:`grey`,children:n.plugin_id})]}),n.last_error_code&&(0,G.jsx)(J,{type:`danger`,size:`small`,children:H(e,n.last_error_code,n.last_error_code)})]})},{title:e(`pluginHub.observedState`,null,`运行状态`),dataIndex:`observed_state`,width:130,render:t=>(0,G.jsx)(d,{color:Se(t),shape:`square`,children:Ce(e,t)})},{title:e(`pluginHub.driver`,null,`驱动`),dataIndex:`driver`,width:160,render:t=>U(e,t)},{title:e(`pluginHub.updatedAt`,null,`更新时间`),dataIndex:`updated_at`,width:170,render:e=>oe(e)},{title:e(`common.actions`,null,`操作`),width:300,render:(t,n)=>{let r=n.observed_state===`healthy`,i=Ie===n.id||[`installing`,`starting`,`stopping`].includes(n.observed_state);return(0,G.jsxs)(c,{spacing:4,wrap:!0,children:[m&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,icon:(0,G.jsx)(u,{}),disabled:!r,onClick:()=>We(n),children:e(`pluginHub.openWorkspace`,null,`打开应用`)}),s&&!r&&(0,G.jsx)(D,{content:n.observed_state===`failed`?e(`pluginHub.retryInstallOrStart`,null,`重试安装 / 启动`):e(`pluginHub.start`,null,`启动`),children:(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(k,{}),loading:i,onClick:()=>$e(n,`start`)})}),g&&(n.observed_state===`failed`||n.observed_state===`degraded`)&&(0,G.jsx)(p,{size:`small`,theme:`light`,type:`warning`,icon:(0,G.jsx)(v,{}),onClick:()=>Qe(n),children:e(`pluginHub.agentFixBtn`,null,`Agent 排错`)}),s&&r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(D,{content:e(`pluginHub.restart`,null,`重启`),children:(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(ne,{}),loading:i,onClick:()=>$e(n,`restart`)})}),(0,G.jsx)(D,{content:e(`pluginHub.stop`,null,`停止`),children:(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(te,{}),loading:i,onClick:()=>$e(n,`stop`)})})]}),s&&(0,G.jsx)(D,{content:e(`pluginHub.logs`,null,`实时日志`),children:(0,G.jsx)(p,{size:`small`,theme:`borderless`,icon:(0,G.jsx)(x,{}),onClick:()=>q({id:n.id,tab:`logs`})})}),(0,G.jsx)(D,{content:e(`pluginHub.settingsAndDetail`,null,`详情与模型绑定`),children:(0,G.jsx)(p,{size:`small`,theme:`borderless`,icon:(0,G.jsx)(O,{}),onClick:()=>q({id:n.id,tab:`overview`})})}),s&&(0,G.jsx)(D,{content:e(`pluginHub.uninstall`,null,`卸载`),children:(0,G.jsx)(p,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,G.jsx)(l,{}),onClick:()=>et(n)})})]})}}];return(0,G.jsxs)(`div`,{className:`cs-ph-root`,children:[(0,G.jsx)(pe,{title:e(`pluginHub.title`,null,`插件化能力平台`),description:e(`pluginHub.subtitle`,null,`按需拉取独立红队与安全开源项目,保留原作者仓库隔离,支持页面无缝内嵌与 CSAI 模型通道统一复用。`),extra:(0,G.jsxs)(c,{wrap:!0,children:[s&&(0,G.jsx)(p,{icon:(0,G.jsx)(ee,{}),onClick:()=>ye(!0),children:e(`pluginHub.runtimeProbes`,null,`运行环境预检`)}),s&&(0,G.jsx)(p,{theme:`solid`,type:`primary`,icon:(0,G.jsx)(S,{}),onClick:()=>N(!0),children:e(`pluginHub.importGit`,null,`手工导入 Git 仓库`)}),(0,G.jsx)(p,{icon:(0,G.jsx)(M,{}),onClick:Ke,loading:X.loading||Z.loading,children:e(`common.refresh`,null,`刷新`)})]})}),(0,G.jsx)(ce,{columns:4,metrics:[{id:`installed`,label:e(`pluginHub.statInstalled`,null,`已安装插件`),value:$.length,icon:(0,G.jsx)(j,{}),onClick:()=>Ue(`installed`)},{id:`healthy`,label:e(`pluginHub.statRunning`,null,`运行中应用`),value:rt,tone:rt>0?`success`:void 0,icon:(0,G.jsx)(k,{}),onClick:()=>Ue(`installed`)},{id:`catalog`,label:e(`pluginHub.statCatalog`,null,`官方精选目录`),value:ze.length,icon:(0,G.jsx)(o,{}),onClick:()=>Ue(`market`)},{id:`drivers`,label:e(`pluginHub.statDrivers`,null,`宿主可用驱动`),value:s&&at.length?at.join(` / `):`—`,detail:Q.data?`${Q.data.os}/${Q.data.arch}`:void 0,icon:(0,G.jsx)(v,{}),onClick:s?()=>ye(!0):void 0}]}),Y&&(0,G.jsx)(a,{type:Y.status===`failed`?`danger`:Y.status===`succeeded`?`success`:`info`,bordered:!0,onClose:()=>Fe(null),description:(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsxs)(J,{strong:!0,children:[e(`pluginHub.latestOperation`,null,`最近任务`),`: `,Y.kind]}),(0,G.jsx)(d,{size:`small`,color:Y.status===`succeeded`?`green`:Y.status===`failed`?`red`:`blue`,children:Y.status}),s&&Y.install_id&&(0,G.jsx)(p,{size:`small`,theme:`borderless`,onClick:()=>q({id:Y.install_id,tab:`logs`}),children:e(`pluginHub.viewLogs`,null,`查看日志`)})]})}),(0,G.jsxs)(de,{children:[(0,G.jsx)(ue,{error:X.error||Z.error,onRetry:Ke}),(0,G.jsxs)(b,{activeKey:E,onChange:Ue,tabBarExtraContent:(0,G.jsx)(h,{prefix:(0,G.jsx)(T,{}),value:A,onChange:re,placeholder:e(`pluginHub.searchPlaceholder`,null,`搜索插件名称或描述`),style:{width:260},showClear:!0}),children:[(0,G.jsx)(w,{tab:`${e(`pluginHub.tabInstalled`,null,`已安装应用`)} (${$.length})`,itemKey:`installed`,children:(0,G.jsx)(`div`,{style:{marginTop:12},children:(0,G.jsx)(me,{columns:ot,dataSource:tt,loading:X.loading,emptyText:e(`pluginHub.emptyInstalled`,null,`暂未安装插件,可切换到「能力市场」一键下载或手工导入 Git 仓库`)})})}),(0,G.jsxs)(w,{tab:`${e(`pluginHub.marketTitle`,null,`能力市场`)} (${ze.length})`,itemKey:`market`,children:[s&&(0,G.jsxs)(c,{style:{justifyContent:`space-between`,width:`100%`,marginTop:12},wrap:!0,children:[(0,G.jsx)(J,{type:`tertiary`,size:`small`,children:e(`pluginHub.marketManageHint`,null,`支持自由新增开源仓库或删除/隐藏条目;已安装的插件不受市场目录变更影响。`)}),(0,G.jsxs)(c,{wrap:!0,children:[Be>0&&(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(M,{}),loading:fe,onClick:Xe,children:e(`pluginHub.restoreBuiltins`,{count:Be},`恢复默认精选 (${Be})`)}),(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,icon:(0,G.jsx)(S,{}),onClick:()=>R(!0),children:e(`pluginHub.addCatalogBtn`,null,`新增市场插件`)})]})]}),(0,G.jsx)(`div`,{className:`cs-ph-catalog-grid`,style:{marginTop:14},children:nt.length===0?(0,G.jsx)(J,{type:`tertiary`,style:{padding:`16px 0`},children:e(`pluginHub.emptyMarket`,null,`当前能力市场暂无匹配条目,可点击「新增市场插件」添加。`)}):nt.map(t=>{let n=$.find(e=>e.plugin_id===t.id),r=t.availability===`plan_available`;return(0,G.jsxs)(`div`,{className:`cs-ph-card`,children:[(0,G.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,G.jsxs)(`div`,{className:`cs-ph-card-head`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(c,{spacing:6,children:[(0,G.jsx)(J,{strong:!0,size:`normal`,children:t.title}),!t.builtin&&(0,G.jsx)(d,{size:`small`,color:`violet`,children:e(`pluginHub.catalogCustomBadge`,null,`自定义`)})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(J,{type:`tertiary`,size:`small`,className:`cs-ph-mono`,children:t.id})})]}),(0,G.jsx)(d,{size:`small`,color:r?`green`:`blue`,children:r?e(`pluginHub.catalogOneClick`,null,`支持一键安装`):e(`pluginHub.catalogInspectOnly`,null,`支持探测导入`)})]}),(0,G.jsx)(Pe,{type:`tertiary`,size:`small`,style:{margin:0},children:t.summary||e(`pluginHub.noSummary`,null,`暂无简介`)}),(0,G.jsx)(`div`,{className:`cs-ph-card-meta`,children:(0,G.jsx)(`a`,{href:t.repository,target:`_blank`,rel:`noreferrer`,style:{fontSize:12},children:t.repository.replace(`https://github.com/`,`github.com/`)})})]}),(0,G.jsxs)(`div`,{className:`cs-ph-card-footer`,children:[n?(0,G.jsxs)(d,{color:Se(n.observed_state),children:[e(`pluginHub.installedBadge`,null,`已安装`),` · `,Ce(e,n.observed_state)]}):(0,G.jsx)(J,{type:`tertiary`,size:`small`,children:e(`pluginHub.externalRepoHint`,null,`代码保留在原作者仓库`)}),(0,G.jsxs)(c,{spacing:6,children:[s&&(0,G.jsx)(D,{content:t.builtin?e(`pluginHub.hideBuiltinTooltip`,null,`从市场隐藏`):e(`common.delete`,null,`删除`),children:(0,G.jsx)(p,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,G.jsx)(l,{}),onClick:()=>Ye(t)})}),n&&m&&n.observed_state===`healthy`&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,onClick:()=>We(n),children:e(`pluginHub.openWorkspace`,null,`打开应用`)}),!n&&s&&(0,G.jsx)(p,{size:`small`,theme:r?`solid`:`light`,type:`primary`,icon:(0,G.jsx)(o,{}),loading:Ee===t.id,onClick:()=>Je(t),children:r?e(`pluginHub.oneClickInstall`,null,`一键下载安装`):e(`pluginHub.inspectAndImport`,null,`探测并导入`)})]})]})]},t.id)})})]})]})]}),(0,G.jsx)(Ae,{visible:le,onCancel:()=>R(!1),onSaved:()=>{R(!1),Z.reload({silent:!0})}}),(0,G.jsx)(je,{visible:ie,initialEntry:ae,onCancel:()=>{N(!1),F(null)},onCatalogSaved:()=>Z.reload({silent:!0}),onPlanReady:e=>{N(!1),F(null),Te(e)}}),(0,G.jsx)(ke,{planResponse:we,channels:Ve,visible:!!we,canUseAgent:g,onCancel:()=>Te(null),onAskAgentDriverFix:Ze,onConfirmed:e=>{Te(null),Fe(e),Ue(`installed`),X.reload({silent:!0})}}),(0,G.jsx)(Me,{installId:K?.id,initialTab:K?.tab,visible:!!K,canManage:s,canUseAgent:g,channels:Ve,onCancel:()=>q(null),onRestartRequested:e=>$e(e,`restart`),onAskAgentTroubleshoot:Qe,onChanged:Ke}),(0,G.jsx)(Ne,{visible:ve,canUseAgent:g,onCancel:()=>ye(!1),onAskAgentDriverFix:Ze})]})}export{Y as default};
\ No newline at end of file
diff --git a/web/static/app/assets/plugin-hub-CksKkMqp.js b/web/static/app/assets/plugin-hub-CksKkMqp.js
deleted file mode 100644
index e1ef3af3..00000000
--- a/web/static/app/assets/plugin-hub-CksKkMqp.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{B as a,Ft as o,G as s,I as c,Lt as l,Mt as u,N as d,P as f,R as p,S as m,U as h,W as g,Wt as _,Zt as v,_t as y,c as b,et as x,ft as S,h as C,l as w,lt as T,m as E,on as D,ot as O,pt as k,q as ee,qt as A,rn as j,rt as te,tt as ne,ut as re,x as ie,y as ae,yt as M}from"./semi-65W_4I1v.js";import{E as oe,F as se,I as N,P,_ as ce,a as F,b as I,c as L,d as R,l as le,m as ue,o as z,p as de,r as fe,s as pe,u as me,x as B,y as he,z as ge}from"./index-BdnarFZR.js";import{r as _e}from"./agent-handoff-DzQOcr38.js";var V=e(t(),1);function ve(e=`op`){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`${e}-${crypto.randomUUID()}`:`${e}-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}var ye={plugin_bearer_required:[`pluginHub.errorBearerRequired`,`需要 Bearer 登录凭据才能访问插件平台`],plugin_invalid_request:[`pluginHub.errorInvalidRequest`,`请求参数不合法,请检查插件 ID(仅限小写字母、数字和连字符)、标题与仓库地址`],plugin_invalid_source:[`pluginHub.errorInvalidSource`,`仅支持公开的 GitHub HTTPS 仓库地址及合法分支/Tag/Commit`],plugin_ambiguous_git_ref:[`pluginHub.errorAmbiguousRef`,`分支与 Tag 同名,请填写完整引用(如 refs/tags/xxx 或 refs/heads/xxx)`],plugin_source_not_found:[`pluginHub.errorSourceNotFound`,`未找到目标仓库或指定版本`],plugin_invalid_manifest:[`pluginHub.errorInvalidManifest`,`插件 Manifest 格式或字段校验未通过`],plugin_github_rate_limited:[`pluginHub.errorRateLimited`,`GitHub API 触发限流,建议配置 plugins.egress.github_token_env 后重试`],plugin_source_unavailable:[`pluginHub.errorSourceUnavailable`,`无法连接上游仓库,请检查网络或插件代理配置`],plugin_manifest_required:[`pluginHub.errorManifestRequired`,`该仓库未自带 csai-plugin.yaml,请先补全 Manifest 草案`],plugin_manifest_source_mismatch:[`pluginHub.errorSourceMismatch`,`Manifest 中的仓库地址或版本与探测结果不一致`],plugin_artifact_not_approved:[`pluginHub.errorArtifactNotApproved`,`当前宿主策略未批准该制品摘要,请联系管理员或核对批准策略`],plugin_operation_conflict:[`pluginHub.errorOperationConflict`,`该插件已有正在执行的变更任务,请等待当前操作完成`],plugin_plan_stale:[`pluginHub.errorPlanStale`,`安装计划已过期或已被消费,请重新生成锁定计划`],plugin_runtime_unavailable:[`pluginHub.errorRuntimeUnavailable`,`插件运行调度器尚未就绪,请稍后重试`],plugin_artifact_unavailable:[`pluginHub.errorArtifactUnavailable`,`未找到适配当前系统架构的可安装制品或镜像`],plugin_llm_binding_invalid:[`pluginHub.errorLLMBindingInvalid`,`所选模型通道无效或与该插件声明的协议不兼容`],plugin_llm_gateway_unavailable:[`pluginHub.errorLLMGatewayUnavailable`,`CSAI 插件模型网关未就绪`],plugin_web_unavailable:[`pluginHub.errorWebUnavailable`,`插件 WebUI 代理未就绪或应用尚未健康启动`],plugin_embed_origin_or_permission_rejected:[`pluginHub.errorEmbedRejected`,`无权访问该插件工作区或请求来源校验未通过`],plugin_record_not_found:[`pluginHub.errorNotFound`,`未找到对应的插件记录或计划已过期`],docker_cli_missing:[`pluginHub.errorDockerCliMissing`,`宿主未安装 Docker CLI / Engine,容器类插件无法启动`],docker_daemon_unavailable:[`pluginHub.errorDockerDaemonUnavailable`,`宿主 Docker 服务未启动,或当前运行用户无权访问 docker.sock`],docker_compose_missing:[`pluginHub.errorDockerComposeMissing`,`宿主缺少 Docker Compose v2 插件`],docker_engine_unsupported:[`pluginHub.errorDockerEngineUnsupported`,`宿主 Docker Engine 版本过低或不满足隔离档位要求`],docker_socket_missing:[`pluginHub.errorDockerSocketMissing`,`容器内未挂载 /var/run/docker.sock`],git_missing:[`pluginHub.errorGitMissing`,`宿主未安装 Git 工具`],plugin_install_failed:[`pluginHub.errorInstallFailed`,`插件安装失败,请查看运行日志或交给 Agent 排错修复`]};function H(e,t,n){let r=ye[typeof t==`string`?t:t?.payload?.error||(typeof t?.message==`string`?t.message:``)];return r?e(r[0],null,r[1]):(typeof t==`string`?t:t?.message)||n||e(`common.loadFailed`,null,`操作失败`)}function be({driver:e,probe:t,hostOS:n,hostArch:r,pluginTitle:i}){return[`请帮我在当前 CyberStrikeAI 宿主机上安装并配置插件平台缺少的运行驱动「${e}」。`,``,`### 当前诊断信息`,`- 宿主机平台:${n||`unknown`}/${r||`unknown`}`,`- 缺少驱动:${e}`,`- 预检错误码:${t?.code||`unavailable`}`,t?.guidance?`- 官方提示:${t.guidance}`:``,t?.install_command?`- 参考安装命令:\`${t.install_command}\``:``,i?`- 待安装插件:${i}`:``,``,`### 请按以下步骤协助完成`,`1. 先检查当前宿主机系统发行版、当前运行用户、包管理器以及目标依赖(如 Docker / Docker Compose / Git)与服务/权限状态;`,`2. 使用官方软件源或受信任方式安装并启动缺少的依赖(涉及 sudo 或系统变更时请清晰说明并走审批确认);`,"3. 如果安装了 Docker,请同时确认 `dockerd` 已开机自启、Compose v2 可用,并检查当前运行 CyberStrikeAI 的用户是否有权限访问 `/var/run/docker.sock`;","4. 执行验证命令确认驱动已正常可用(例如 `docker version && docker compose version` 或 `git --version`);","5. 完成后告诉我是否需要重启 CyberStrikeAI 服务(例如新增 `docker` 用户组后),以便我回到「能力平台」继续一键安装插件。"].filter(Boolean).join(`
-`)}function xe({install:e,logs:t,hostOS:n,hostArch:r}){let i=(Array.isArray(t)?t:[]).slice(-40).map(e=>`[${e.created_at||``}] ${e.line}`).join(`
-`);return[`我在 CyberStrikeAI 插件化能力平台中安装/运行插件「${e?.title||e?.plugin_id||`未知插件`}」失败,请帮我排查根因并直接在宿主机上修复缺少的运行环境或依赖。`,``,`### 插件状态与诊断信息`,`- 插件名称:${e?.title||`—`} (${e?.plugin_id||`—`})`,`- 实例 ID:${e?.id||`—`}`,`- 运行驱动:${e?.driver||`—`}`,`- 当前状态:${e?.observed_state||`failed`}`,`- 最近错误码:${e?.last_error_code||`plugin_install_failed`}`,e?.repository?`- 源码仓库:${e.repository}`:``,n?`- 宿主机平台:${n}/${r||``}`:``,``,`### 最近插件脱敏日志`,"```text",i||`(暂无日志输出,请直接检查对应驱动的宿主机运行环境)`,"```",``,`### 请协助完成`,`1. 根据错误码和日志定位失败根因(例如缺少 Docker / Compose / Git / Go / Node.js、dockerd 未启动、docker.sock 权限不足、端口或网络问题等);`,`2. 如果缺少运行环境或依赖,请直接帮我在宿主机上安装并配置就绪(涉及提权或系统改动时按审批确认);`,`3. 验证宿主机依赖已恢复正常,并告诉我接下来回到「能力平台」直接点击重试/启动即可。`].filter(Boolean).join(`
-`)}function Se(e){switch(String(e||``).toLowerCase()){case`healthy`:return`green`;case`starting`:case`installing`:case`stopping`:return`blue`;case`degraded`:case`cleanup_pending`:return`amber`;case`failed`:return`red`;default:return`grey`}}function Ce(e,t){let n={healthy:[`pluginHub.stateHealthy`,`运行中`],starting:[`pluginHub.stateStarting`,`启动中`],installing:[`pluginHub.stateInstalling`,`安装中`],stopping:[`pluginHub.stateStopping`,`停止中`],stopped:[`pluginHub.stateStopped`,`已停止`],degraded:[`pluginHub.stateDegraded`,`状态异常`],failed:[`pluginHub.stateFailed`,`失败`],cleanup_pending:[`pluginHub.stateCleanupPending`,`待清理`],removed:[`pluginHub.stateRemoved`,`已卸载`]}[String(t||``).toLowerCase()];return n?e(n[0],null,n[1]):t||`—`}function U(e,t){let n={auto:[`pluginHub.driverAuto`,`自动择优(Release → Git → 容器)`],release:[`pluginHub.driverRelease`,`Release 预编译包`],git:[`pluginHub.driverGit`,`Git 源码构建`],container:[`pluginHub.driverContainer`,`Docker / Compose 容器`],compose:[`pluginHub.driverCompose`,`Docker Compose`]}[String(t||``).toLowerCase()];return n?e(n[0],null,n[1]):t||`—`}var W={listCatalog:()=>N.get(`/plugins/catalog`),saveCatalog:e=>N.post(`/plugins/catalog`,e),deleteCatalog:e=>N.del(`/plugins/catalog/${encodeURIComponent(e)}`),restoreCatalog:()=>N.post(`/plugins/catalog/restore`,{}),listInstalls:()=>N.get(`/plugins/installs`),getInstall:e=>N.get(`/plugins/installs/${encodeURIComponent(e)}`),listLLMChannels:()=>N.get(`/plugins/llm/channels`),probes:(e=`standard`)=>N.get(`/plugins/runtime/probes`,{isolation:e}),inspectGit:(e,t)=>N.post(`/plugins/imports/inspect`,{repository:e.trim(),revision:(t||``).trim()}),createPlan:e=>N.post(`/plugins/install-plans`,e),install:({planId:e,planDigest:t,autoBindLLM:n})=>N.post(`/plugins/installs`,{kind:`install`,plan_id:e,plan_digest:t,idempotency_key:ve(`install`),auto_bind_llm:n}),operate:(e,t,n={})=>N.post(`/plugins/installs/${encodeURIComponent(e)}/operations`,{kind:t,idempotency_key:ve(t),...n}),getOperation:e=>N.get(`/plugins/operations/${encodeURIComponent(e)}`),readLogs:(e,t=0,n=100)=>N.get(`/plugins/installs/${encodeURIComponent(e)}/logs`,{after:t,limit:n}),issueEmbedSession:e=>N.post(`/plugins/installs/${encodeURIComponent(e)}/embed-sessions`,{}),patchLLM:(e,t)=>N.patch(`/plugins/installs/${encodeURIComponent(e)}/llm`,t)};function we(e,{after:t=0,onEntry:n,onError:r,onClose:i}={}){let a=new AbortController,o=ge(),s={Accept:`text/event-stream`};o&&(s.Authorization=`Bearer ${o}`);let c=`/api/plugins/installs/${encodeURIComponent(e)}/logs?after=${encodeURIComponent(String(t))}`;return(async()=>{try{let e=await fetch(c,{method:`GET`,headers:s,signal:a.signal});if(e.status===401&&window.dispatchEvent(new CustomEvent(`csai:unauthorized`)),!e.ok||!e.body)throw Error(`HTTP ${e.status}`);let t=e.body.getReader(),r=new TextDecoder,o=``;for(;;){let{done:e,value:i}=await t.read();if(e)break;o+=r.decode(i,{stream:!0});let a;for(;(a=o.indexOf(`
-`))>=0;){let e=o.slice(0,a).replace(/\r$/,``);if(o=o.slice(a+1),!e.startsWith(`data:`))continue;let t=e.slice(5).trim();if(t)try{n?.(JSON.parse(t))}catch{}}}i?.()}catch(e){if(e?.name===`AbortError`){i?.();return}r?.(e)}})(),()=>a.abort()}function Te(e){let t=e?.repository||`https://github.com/owner/repo`,n=t.split(`/`).pop()||`my-plugin`,r=n.toLowerCase().replace(/[^a-z0-9-]+/g,`-`).replace(/^-+|-+$/g,``)||`my-plugin`;return(e?.candidates||[]).includes(`container`)?JSON.stringify({apiVersion:`plugins.csai.io/v1`,kind:`WebPlugin`,metadata:{id:r,title:n,summary:`Imported container WebUI plugin`,version:`1.0.0`,repository:t},distribution:[{type:`container`,mode:`docker`,services:[{name:`web`,role:`web`,image:`ghcr.io/${t.replace(`https://github.com/`,``).toLowerCase()}:latest`,containerPort:8080,resources:{memoryMiB:512,pids:128}}]}],web:{route:`root`,entryPath:`/`,healthPath:`/`,allowHealthRedirect:!0},access:{mode:`plugin_login`},permissions:{persistentData:!1,modelGateway:!1,egress:[]}},null,2):JSON.stringify({apiVersion:`plugins.csai.io/v1`,kind:`WebPlugin`,metadata:{id:r,title:n,summary:`Imported Git WebUI plugin`,version:`1.0.0`,repository:t},distribution:[{type:`git`,url:t,revision:e?.resolved_ref||e?.commit||`main`,dependencies:[{name:`git`,minVersion:`2.30`},{name:`go`,minVersion:`1.22`}],build:[{program:`go`,args:[`build`,`-o`,`dist/app`,`.`]}],outputRoot:`dist`}],launch:{entrypoint:`app`,env:{PORT:`listen_port`,HOST:`listen_host`}},web:{route:`root`,entryPath:`/`,healthPath:`/`,allowHealthRedirect:!0},access:{mode:`platform`},permissions:{persistentData:!1,modelGateway:!1,egress:[]}},null,2)}var G=e(r(),1),{Text:Ee}=s;function De(e,t,n){let r=document.createElement(`form`);r.method=`POST`,r.action=e,r.target=n,r.style.display=`none`;let i=document.createElement(`input`);i.type=`hidden`,i.name=`ticket`,i.value=t,r.appendChild(i),document.body.appendChild(r),r.submit(),r.remove()}function Oe({install:e,canManage:t,onBack:n,onOpenDetail:r,onOpenLogs:i}){let a=P(),o=`csai-plugin-frame-${(0,V.useId)().replace(/[^a-zA-Z0-9_-]/g,``)}`,s=(0,V.useRef)(null),[l,f]=(0,V.useState)(!0),[m,h]=(0,V.useState)(``),[v,b]=(0,V.useState)(null),[S,C]=(0,V.useState)(!1),w=(0,V.useCallback)(async()=>{if(e?.id){f(!0),h(``);try{let t=await W.issueEmbedSession(e.id);b(t),requestAnimationFrame(()=>{De(t.action,t.ticket,o)})}catch(e){h(H(a,e,a(`pluginHub.embedInitFailed`,null,`无法建立插件工作区会话`))),f(!1)}}},[e?.id,o,a]);(0,V.useEffect)(()=>{w()},[w]);let T=async()=>{try{let t=await W.issueEmbedSession(e.id),n=`csai-plugin-standalone-${Date.now()}`;window.open(`about:blank`,n,`noopener`),De(t.action,t.ticket,n)}catch(e){I(H(a,e,a(`pluginHub.embedInitFailed`,null,`无法打开独立窗口`)))}};return(0,V.useEffect)(()=>{let e=()=>{document.fullscreenElement||C(!1)};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]),(0,G.jsxs)(`div`,{ref:s,className:`cs-ph-workspace ${S?`is-expanded`:``}`,children:[(0,G.jsxs)(`div`,{className:`cs-ph-workspace-bar`,children:[(0,G.jsxs)(`div`,{className:`cs-ph-workspace-title`,children:[(0,G.jsx)(p,{size:`small`,theme:`borderless`,icon:(0,G.jsx)(_,{}),onClick:n,children:a(`pluginHub.backToHub`,null,`返回能力平台`)}),(0,G.jsx)(Ee,{strong:!0,ellipsis:!0,style:{maxWidth:260},children:e.title||e.plugin_id}),(0,G.jsx)(d,{size:`small`,color:Se(e.observed_state),shape:`square`,children:Ce(a,e.observed_state)}),v?.origin&&(0,G.jsx)(Ee,{type:`tertiary`,size:`small`,className:`cs-ph-mono`,ellipsis:!0,style:{maxWidth:260},children:v.origin})]}),(0,G.jsxs)(c,{spacing:6,wrap:!0,children:[(0,G.jsx)(D,{content:a(`pluginHub.reconnectSession`,null,`刷新 / 重新建立隔离会话`),children:(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(re,{}),onClick:w,loading:l,children:a(`common.refresh`,null,`刷新`)})}),(0,G.jsx)(D,{content:a(`pluginHub.openFirstPartyTip`,null,`若浏览器严格拦截跨站 Cookie,可在独立首方窗口中打开`),children:(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(u,{}),onClick:T,children:a(`pluginHub.openStandalone`,null,`独立窗口`)})}),t&&(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(x,{}),onClick:i,children:a(`pluginHub.logs`,null,`日志`)}),(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(O,{}),onClick:r,children:a(`pluginHub.settingsAndDetail`,null,`详情与模型`)}),(0,G.jsx)(p,{size:`small`,icon:S?(0,G.jsx)(y,{}):(0,G.jsx)(M,{}),onClick:async()=>{let e=s.current;if(e){if(document.fullscreenElement){try{await document.exitFullscreen()}catch{}C(!1)}else{if(e.requestFullscreen)try{await e.requestFullscreen(),C(!0);return}catch{}C(e=>!e)}}},children:S?a(`pluginHub.exitFullscreen`,null,`退出全屏`):a(`mobile.fullscreen`,null,`全屏`)})]})]}),(0,G.jsxs)(`div`,{className:`cs-ph-workspace-frame-wrap`,children:[(0,G.jsx)(`iframe`,{name:o,title:e.title||e.plugin_id,className:`cs-ph-workspace-iframe`,sandbox:`allow-scripts allow-same-origin allow-forms allow-downloads`,allow:`clipboard-read; clipboard-write`,onLoad:()=>f(!1)}),l&&!m&&(0,G.jsxs)(`div`,{className:`cs-ph-workspace-overlay`,children:[(0,G.jsx)(g,{size:`large`}),(0,G.jsx)(Ee,{type:`tertiary`,children:a(`pluginHub.connectingWorkspace`,null,`正在建立隔离代理会话并加载插件页面…`)})]}),m&&(0,G.jsxs)(`div`,{className:`cs-ph-workspace-overlay`,children:[(0,G.jsx)(Ee,{type:`danger`,strong:!0,children:m}),(0,G.jsx)(Ee,{type:`tertiary`,size:`small`,children:a(`pluginHub.embedTroubleshooting`,null,`请确认插件处于运行中状态;若浏览器限制跨站 Cookie,可点击上方「独立窗口」以首方会话打开。`)}),(0,G.jsxs)(c,{children:[(0,G.jsx)(p,{theme:`solid`,type:`primary`,onClick:w,children:a(`pluginHub.retryConnect`,null,`重试连接`)}),(0,G.jsx)(p,{icon:(0,G.jsx)(u,{}),onClick:T,children:a(`pluginHub.openStandalone`,null,`独立窗口`)})]})]})]})]})}var{Text:K,Paragraph:q}=s;function ke({planResponse:e,channels:t,visible:n,canUseAgent:r,onCancel:i,onConfirmed:o,onAskAgentDriverFix:s}){let l=P(),[m,h]=(0,V.useState)(!0),[g,_]=(0,V.useState)(!1),[y,b]=(0,V.useState)(null),[x,S]=(0,V.useState)(!1);(0,V.useEffect)(()=>{n&&(h(!0),b(e?.driver_probe||null))},[n,e?.plan?.id,e?.driver_probe]);let C=e?.plan,w=e?.manifest,T=C?.artifact,E=y||e?.driver_probe||null,D=!(!E||E.available),O=!!w?.llm?.bindings?.length,k=(0,V.useMemo)(()=>(t||[]).find(e=>e.is_default)||(t||[])[0]||null,[t]),ee=(0,V.useMemo)(()=>!O||!k?!1:w.llm.bindings.some(e=>e.protocol===k.protocol),[O,k,w]);return(0,G.jsx)(L,{title:l(`pluginHub.planApprovalTitle`,null,`确认插件安装计划`),visible:n,onCancel:i,width:680,footer:(0,G.jsxs)(c,{children:[(0,G.jsx)(p,{onClick:i,children:l(`common.cancel`,null,`取消`)}),(0,G.jsx)(p,{theme:`solid`,type:`primary`,loading:g,disabled:!e?.can_confirm||D,onClick:async()=>{if(C&&e?.plan_digest){_(!0);try{let t=await W.install({planId:C.id,planDigest:e.plan_digest,autoBindLLM:O?m:void 0});B(l(`pluginHub.installQueued`,null,`安装任务已提交,正在后台准备并启动`)),o?.(t)}catch(e){I(H(l,e,l(`pluginHub.installFailed`,null,`提交安装失败`)))}finally{_(!1)}}},children:D?l(`pluginHub.driverMissingBtn`,null,`缺少运行驱动,请先安装依赖`):l(`pluginHub.confirmInstall`,null,`确认并一键安装`)})]}),children:C&&w&&(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,children:[D&&(0,G.jsx)(a,{type:`danger`,bordered:!0,closeIcon:null,title:l(`pluginHub.driverMissingTitle`,{driver:U(l,T?.driver)},`当前宿主机缺少所需驱动:${U(l,T?.driver)}`),description:(0,G.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8,marginTop:4},children:[(0,G.jsx)(K,{size:`small`,children:H(l,E.code,E.guidance)}),E.install_command&&(0,G.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,flexWrap:`wrap`},children:[(0,G.jsx)(`code`,{className:`cs-ph-mono`,style:{fontSize:12,padding:`4px 8px`,borderRadius:4,background:`var(--semi-color-fill-1)`,wordBreak:`break-all`},children:E.install_command}),(0,G.jsx)(z,{text:E.install_command,label:l(`common.copy`,null,`复制`)})]}),(0,G.jsxs)(c,{wrap:!0,children:[r&&s&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,icon:(0,G.jsx)(v,{}),onClick:()=>s({driver:T?.driver,probe:E,hostOS:e.host_os,hostArch:e.host_arch,pluginTitle:w.metadata?.title||w.metadata?.id}),children:l(`pluginHub.askAgentInstallDriver`,null,`交给 CSAI Agent 自动安装配置`)}),E.download_url&&(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(u,{}),onClick:()=>window.open(E.download_url,`_blank`,`noopener,noreferrer`),children:l(`pluginHub.officialDownload`,null,`官方下载`)}),(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(re,{}),loading:x,onClick:async()=>{if(C&&T?.driver){S(!0);try{let e=await W.probes(C.isolation||`standard`),t=(w?.distribution||[]).some(e=>e.type===T.driver&&e.mode===`compose`),n=T.driver===`container`&&t?`compose`:T.driver,r=e?.drivers?.[n]||e?.drivers?.[T.driver];r&&(b(r),r.available&&B(l(`pluginHub.driverNowReady`,null,`运行驱动已就绪,可以继续一键安装`)))}catch(e){I(H(l,e))}finally{S(!1)}}},children:l(`pluginHub.recheckDriver`,null,`重新检测`)})]})]})}),!e.can_confirm&&(0,G.jsx)(a,{type:`warning`,bordered:!0,closeIcon:null,description:l(`pluginHub.hostApprovalRequiredBanner`,null,`当前宿主开启了 host_config_only 策略,需要先将下方 Manifest 与制品摘要写入 config.yaml 的 plugins.approved_artifacts 后方可安装。`)}),(0,G.jsx)(R,{columns:2,items:[{label:l(`pluginHub.pluginTitle`,null,`插件名称`),value:`${w.metadata?.title||w.metadata?.id} (${w.metadata?.version||`—`})`},{label:l(`pluginHub.repository`,null,`原作者仓库`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:w.metadata?.repository})},{label:l(`pluginHub.driver`,null,`运行驱动`),value:U(l,T?.driver)},{label:l(`pluginHub.isolation`,null,`隔离档位`),value:C.isolation},{label:l(`pluginHub.platform`,null,`目标平台`),value:`${C.platform?.os}/${C.platform?.arch}`},{label:l(`pluginHub.approvalPolicy`,null,`审批策略`),value:e.approval_policy||`admin_confirm`},{label:`Manifest SHA-256`,value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:C.manifestSha256})},{label:l(`pluginHub.artifactDigest`,null,`锁定制品摘要`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:e.artifact_digest})}]}),T?.driver===`git`&&(0,G.jsx)(R,{columns:1,items:[{label:l(`pluginHub.lockedCommit`,null,`锁定 Git Commit`),value:(0,G.jsxs)(`span`,{className:`cs-ph-mono`,children:[T.commit,` (`,T.requestedRef,`)`]})}]}),T?.driver===`release`&&(0,G.jsx)(R,{columns:1,items:[{label:l(`pluginHub.lockedReleaseAsset`,null,`锁定 Release 制品`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:T.assetURL})},{label:`SHA-256`,value:(0,G.jsxs)(`span`,{className:`cs-ph-mono`,children:[T.sha256,` (`,T.verification,`)`]})}]}),T?.driver===`container`&&Array.isArray(T.services)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,children:l(`pluginHub.lockedImages`,null,`锁定容器镜像 Digest`)}),(0,G.jsx)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6,marginTop:6},children:T.services.map(e=>(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsxs)(c,{children:[(0,G.jsx)(d,{color:`blue`,size:`small`,children:e.name}),(0,G.jsx)(K,{size:`small`,className:`cs-ph-mono`,children:e.requestedImage})]}),(0,G.jsxs)(K,{type:`tertiary`,size:`small`,className:`cs-ph-mono`,children:[e.repository,`@`,e.manifestDigest]})]},e.name))})]}),(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsx)(K,{strong:!0,children:l(`pluginHub.declaredPermissions`,null,`声明权限摘要`)}),(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsxs)(d,{color:w.permissions?.persistentData?`amber`:`grey`,children:[l(`pluginHub.permPersistentData`,null,`持久化数据卷`),`: `,w.permissions?.persistentData?`Yes`:`No`]}),(0,G.jsxs)(d,{color:w.permissions?.modelGateway?`blue`:`grey`,children:[l(`pluginHub.permModelGateway`,null,`CSAI 模型网关`),`: `,w.permissions?.modelGateway?`Yes`:`No`]}),(w.permissions?.egress||[]).map(e=>(0,G.jsx)(d,{color:`purple`,children:e},e))]})]}),O&&(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsx)(f,{checked:m,onChange:e=>h(!!e.target.checked),children:l(`pluginHub.autoBindDefaultLLM`,null,`安装时自动复用 CSAI 默认模型通道(开箱即用,不泄露真实上游 API Key)`)}),k?(0,G.jsx)(K,{type:`tertiary`,size:`small`,children:ee?l(`pluginHub.defaultChannelMatch`,{name:`${k.name} (${k.model})`},`当前默认通道:${k.name} (${k.model}),协议匹配,启动即自动注入。`):l(`pluginHub.defaultChannelMismatch`,{name:`${k.name} (${k.protocol})`},`当前默认通道 ${k.name} (${k.protocol}) 与该插件声明协议不同,安装后可在插件设置中指定通道。`)}):(0,G.jsx)(K,{type:`tertiary`,size:`small`,children:l(`pluginHub.noDefaultChannelHint`,null,`尚未在 CSAI 系统设置中配置模型通道,安装后可随时在插件详情中绑定模型。`)})]}),(0,G.jsx)(me,{value:w,collapsed:!0,title:`Manifest`})]})})}function Ae({visible:e,onCancel:t,onSaved:n}){let r=P(),[i,a]=(0,V.useState)(``),[o,s]=(0,V.useState)(``),[l,u]=(0,V.useState)(``),[d,f]=(0,V.useState)(``),[g,_]=(0,V.useState)(``),[v,y]=(0,V.useState)(``),[b,x]=(0,V.useState)(!1),[S,C]=(0,V.useState)(!1);(0,V.useEffect)(()=>{e&&(a(``),s(``),u(``),f(``),_(``),y(``))},[e]);let w=e=>{let t=String(e||``).trim().replace(/\.git$/i,``).replace(/\/+$/,``).split(`/`).pop()||``;return{seg:t,slug:t.toLowerCase().replace(/[^a-z0-9-]+/g,`-`).replace(/^-+|-+$/g,``)}};return(0,G.jsx)(L,{title:r(`pluginHub.addCatalogTitle`,null,`新增能力市场插件`),visible:e,onCancel:t,width:680,footer:(0,G.jsxs)(c,{children:[(0,G.jsx)(p,{onClick:t,children:r(`common.cancel`,null,`取消`)}),(0,G.jsx)(p,{theme:`solid`,type:`primary`,loading:S,onClick:async()=>{if(!i.trim()&&!v.trim())I(r(`pluginHub.catalogRepoRequired`,null,`请填写 GitHub 仓库地址或提供 Manifest`));else{C(!0);try{let e=await W.saveCatalog({id:l.trim(),title:d.trim(),repository:i.trim(),revision:o.trim(),summary:g.trim(),manifest:v.trim()});B(r(`pluginHub.catalogSaved`,null,`已保存到能力市场`)),n?.(e?.item)}catch(e){I(H(r,e,r(`pluginHub.catalogSaveFailed`,null,`保存到能力市场失败`)))}finally{C(!1)}}},children:r(`pluginHub.saveToMarket`,null,`保存到能力市场`)})]}),children:(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,children:[(0,G.jsx)(q,{type:`tertiary`,style:{margin:0},children:r(`pluginHub.addCatalogDesc`,null,`将公开 GitHub 仓库收录到本机能力市场。留空 Manifest 将以「支持探测导入」模式展示;提供合法 YAML/JSON Manifest 后将直接支持「一键下载安装」。`)}),(0,G.jsxs)(c,{style:{width:`100%`},align:`end`,wrap:!0,children:[(0,G.jsxs)(`div`,{style:{flex:2,minWidth:260},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.repositoryURL`,null,`GitHub 仓库地址`)}),(0,G.jsx)(h,{value:i,onChange:e=>{a(e);let{seg:t,slug:n}=w(e);!l&&n&&/^[a-z]/.test(n)&&u(n),!d&&t&&f(t)},placeholder:`https://github.com/owner/repo`,style:{marginTop:4}})]}),(0,G.jsxs)(`div`,{style:{flex:1,minWidth:130},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.revisionOptional`,null,`分支 / Tag(可选)`)}),(0,G.jsx)(h,{value:o,onChange:s,placeholder:`main / v1.0.0`,style:{marginTop:4}})]}),(0,G.jsx)(p,{loading:b,onClick:async()=>{if(i.trim()){x(!0);try{let e=(await W.inspectGit(i,o))?.inspection;if(e?.repository&&a(e.repository),e?.manifest){let t=e.manifest;t.metadata?.id&&u(t.metadata.id),t.metadata?.title&&f(t.metadata.title),t.metadata?.summary&&_(t.metadata.summary),y(JSON.stringify(t,null,2)),B(r(`pluginHub.catalogProbeWithManifest`,null,`已探测到仓库自带 Manifest,保存后支持一键安装`))}else{let{seg:t,slug:n}=w(e?.repository||i);!l&&n&&/^[a-z]/.test(n)&&u(n),!d&&t&&f(t),B(r(`pluginHub.catalogProbeSuccess`,null,`仓库只读探测完成,已自动填充基础信息`))}}catch(e){I(H(r,e,r(`pluginHub.inspectFailed`,null,`探测仓库失败`)))}finally{x(!1)}}},disabled:!i.trim(),children:r(`pluginHub.probeAndFill`,null,`探测并自动填充`)})]}),(0,G.jsxs)(c,{style:{width:`100%`},wrap:!0,children:[(0,G.jsxs)(`div`,{style:{flex:1,minWidth:220},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.pluginId`,null,`插件标识 ID`)}),(0,G.jsx)(h,{value:l,onChange:u,placeholder:`my-security-tool`,style:{marginTop:4}})]}),(0,G.jsxs)(`div`,{style:{flex:1,minWidth:220},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.pluginTitle`,null,`显示名称`)}),(0,G.jsx)(h,{value:d,onChange:f,placeholder:`My Security Tool`,style:{marginTop:4}})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.catalogSummaryLabel`,null,`功能简介`)}),(0,G.jsx)(h,{value:g,onChange:_,placeholder:r(`pluginHub.catalogSummaryPlaceholder`,null,`简述该开源安全工具的用途、架构或特性`),style:{marginTop:4}})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:r(`pluginHub.catalogManifestOptional`,null,`插件 Manifest(可选,支持 YAML 或 JSON)`)}),(0,G.jsx)(m,{className:`cs-ph-code-editor`,value:v,onChange:y,placeholder:r(`pluginHub.catalogManifestPlaceholder`,null,`可选:粘贴 csai-plugin.yaml 或 JSON 声明;点击上方「探测并自动填充」可自动抓取仓库根目录的 csai-plugin.yaml`),autosize:{minRows:8,maxRows:18},style:{marginTop:4}})]})]})})}function je({visible:e,initialEntry:t,onCancel:n,onPlanReady:r,onCatalogSaved:i}){let a=P(),[o,s]=(0,V.useState)(``),[l,u]=(0,V.useState)(``),[f,g]=(0,V.useState)(!1),[_,v]=(0,V.useState)(null),[y,b]=(0,V.useState)(``),[x,S]=(0,V.useState)(`auto`),[C,w]=(0,V.useState)(`standard`),[T,E]=(0,V.useState)(!1),[D,O]=(0,V.useState)(!1);(0,V.useEffect)(()=>{e&&t?.repository&&(s(t.repository),u(t.revision||``),v(null),b(``))},[e,t]);let k=async()=>{if(o.trim()){g(!0),v(null);try{let e=await W.inspectGit(o,l);v(e),e?.inspection?.manifest?b(JSON.stringify(e.inspection.manifest,null,2)):b(Te(e?.inspection)),B(a(`pluginHub.inspectSucceeded`,null,`仓库只读探测完成`))}catch(e){I(H(a,e,a(`pluginHub.inspectFailed`,null,`探测仓库失败`)))}finally{g(!1)}}},ee=async()=>{if(!_?.id)return;let e;try{e=JSON.parse(y)}catch{I(a(`pluginHub.manifestJsonInvalid`,null,`Manifest 草案需为合法 JSON 格式`));return}E(!0);try{let t=await W.createPlan({inspection_id:_.id,manifest:e,driver:x,isolation:C});r?.(t)}catch(e){I(H(a,e,a(`pluginHub.createPlanFailed`,null,`生成锁定安装计划失败`)))}finally{E(!1)}},A=async()=>{if(_?.inspection){O(!0);try{await W.saveCatalog({repository:_.inspection.repository||o.trim(),revision:l.trim(),manifest:y.trim()}),B(a(`pluginHub.catalogSaved`,null,`已保存到能力市场`)),i?.()}catch(e){I(H(a,e,a(`pluginHub.catalogSaveFailed`,null,`保存到能力市场失败`)))}finally{O(!1)}}},j=_?.inspection;return(0,G.jsx)(L,{title:a(`pluginHub.importTitle`,null,`手工导入 Git 仓库插件`),visible:e,onCancel:n,width:720,footer:(0,G.jsxs)(c,{children:[(0,G.jsx)(p,{onClick:n,children:a(`common.cancel`,null,`取消`)}),(0,G.jsx)(p,{loading:D,disabled:!_?.inspection||!y.trim(),onClick:A,children:a(`pluginHub.saveToMarket`,null,`保存到能力市场`)}),(0,G.jsx)(p,{theme:`solid`,type:`primary`,loading:T,disabled:!_?.id||!y.trim(),onClick:ee,children:a(`pluginHub.generatePlan`,null,`生成锁定安装计划`)})]}),children:(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,children:[(0,G.jsx)(q,{type:`tertiary`,style:{margin:0},children:a(`pluginHub.importDesc`,null,`输入公开 GitHub HTTPS 仓库地址后,CSAI 会以只读方式解析 Commit、根目录 csai-plugin.yaml 及构建/容器线索,不会执行任何第三方代码。`)}),(0,G.jsxs)(c,{style:{width:`100%`},align:`end`,wrap:!0,children:[(0,G.jsxs)(`div`,{style:{flex:2,minWidth:280},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:a(`pluginHub.repositoryURL`,null,`GitHub 仓库地址`)}),(0,G.jsx)(h,{value:o,onChange:s,placeholder:`https://github.com/owner/repo`,style:{marginTop:4}})]}),(0,G.jsxs)(`div`,{style:{flex:1,minWidth:140},children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:a(`pluginHub.revisionOptional`,null,`分支 / Tag / Commit(可选)`)}),(0,G.jsx)(h,{value:l,onChange:u,placeholder:`main / v1.0.0`,style:{marginTop:4}})]}),(0,G.jsx)(p,{theme:`solid`,type:`primary`,loading:f,onClick:k,children:a(`pluginHub.inspectRepo`,null,`只读探测`)})]}),j&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsx)(R,{columns:2,items:[{label:a(`pluginHub.repository`,null,`标准化仓库`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:j.repository})},{label:a(`pluginHub.resolvedRef`,null,`解析引用`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:j.resolved_ref})},{label:`Commit`,value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:j.commit})},{label:a(`pluginHub.detectedCandidates`,null,`候选驱动`),value:(j.candidates||[]).map(e=>(0,G.jsx)(d,{size:`small`,style:{marginInlineEnd:4},children:e},e))}]}),j.evidence?.length>0&&(0,G.jsxs)(c,{wrap:!0,style:{marginTop:6},children:[(0,G.jsxs)(K,{size:`small`,type:`tertiary`,children:[a(`pluginHub.detectedFiles`,null,`检测到文件`),`:`]}),j.evidence.map(e=>(0,G.jsx)(d,{size:`small`,color:`cyan`,children:e},e))]}),j.release?.tag&&(0,G.jsxs)(K,{size:`small`,type:`tertiary`,children:[`Release `,j.release.tag,`: `,(j.release.assets||[]).slice(0,6).join(`, `)||`—`]})]}),(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:a(`pluginHub.driver`,null,`安装驱动`)}),(0,G.jsx)(ae,{value:x,onChange:S,style:{width:240,display:`block`,marginTop:4},optionList:[{value:`auto`,label:U(a,`auto`)},{value:`release`,label:U(a,`release`)},{value:`git`,label:U(a,`git`)},{value:`container`,label:U(a,`container`)}]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:a(`pluginHub.isolation`,null,`隔离档位`)}),(0,G.jsx)(ae,{value:C,onChange:w,style:{width:200,display:`block`,marginTop:4},optionList:[{value:`standard`,label:a(`pluginHub.isolationStandard`,null,`standard(非 root 单机默认)`)},{value:`strict`,label:a(`pluginHub.isolationStrict`,null,`strict(强制容器隔离)`)}]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(c,{style:{justifyContent:`space-between`,width:`100%`,marginBottom:4},children:(0,G.jsx)(K,{strong:!0,size:`small`,children:j.manifest?a(`pluginHub.manifestFromRepo`,null,`已从仓库读取 csai-plugin.yaml(可审阅)`):a(`pluginHub.manifestDraftLabel`,null,`仓库无自带 Manifest,请编辑以下接入草案(JSON)`)})}),(0,G.jsx)(m,{className:`cs-ph-code-editor`,value:y,onChange:b,autosize:{minRows:12,maxRows:22}})]})]})]})})}function Me({installId:e,initialTab:t=`overview`,visible:n,canManage:r,canUseAgent:i,channels:o,onCancel:s,onRestartRequested:l,onChanged:u,onAskAgentTroubleshoot:f}){let m=P(),[h,g]=(0,V.useState)(t),[_,y]=(0,V.useState)(null),[x,S]=(0,V.useState)(!1),[T,D]=(0,V.useState)(`follow_default`),[O,k]=(0,V.useState)(``),[ee,A]=(0,V.useState)(4),[j,te]=(0,V.useState)(60),[ne,M]=(0,V.useState)(2e6),[oe,se]=(0,V.useState)(!1),[N,ce]=(0,V.useState)(!1),[F,le]=(0,V.useState)([]),[ue,de]=(0,V.useState)(!1),fe=(0,V.useRef)(null),pe=(0,V.useRef)(null);(0,V.useEffect)(()=>{n&&g(t||`overview`)},[n,t,e]);let me=async()=>{if(e){S(!0);try{let t=await W.getInstall(e);y(t);let n=Array.isArray(t?.llm_bindings)?t.llm_bindings[0]:null;n?(D(n.mode||`follow_default`),k(n.channel_id||``),A(n.concurrency||4),te(n.rpm||60),M(n.token_budget||2e6)):(D(`follow_default`),k(``)),ce(!1)}catch(e){I(H(m,e))}finally{S(!1)}}};(0,V.useEffect)(()=>{n&&e&&me()},[n,e]),(0,V.useEffect)(()=>{if(!n||!e||h!==`logs`||!r){pe.current?.(),pe.current=null,de(!1);return}let t=!0;return le([]),(async()=>{try{let n=await W.readLogs(e,0,200);if(!t)return;let r=Array.isArray(n?.items)?n.items:[];le(r),de(!0),pe.current=we(e,{after:n?.next_cursor||0,onEntry:e=>{le(t=>[...t.slice(-499),e])},onClose:()=>de(!1),onError:()=>de(!1)})}catch(e){t&&I(H(m,e))}})(),()=>{t=!1,pe.current?.(),pe.current=null,de(!1)}},[n,e,h,r]),(0,V.useEffect)(()=>{fe.current&&(fe.current.scrollTop=fe.current.scrollHeight)},[F]);let he=async()=>{if(e){se(!0);try{let t={mode:T,channel_id:T===`channel`?O:``,limits:{concurrency:Number(ee)||4,rpm:Number(j)||60,token_budget:Number(ne)||2e6}},n=await W.patchLLM(e,t);B(m(`pluginHub.llmSaved`,null,`模型通道绑定已更新`)),ce(!!n?.restart_required),await me(),u?.()}catch(e){I(H(m,e,m(`pluginHub.llmSaveFailed`,null,`保存模型配置失败`)))}finally{se(!1)}}},ge=(0,V.useMemo)(()=>new Set((_?.llm_declared?.bindings||[]).map(e=>e.protocol)),[_]),_e=(0,V.useMemo)(()=>(o||[]).filter(e=>ge.size===0||ge.has(e.protocol)),[o,ge]),ve=(0,V.useMemo)(()=>F.map(e=>`[${e.created_at||``}] ${e.line}`).join(`
-`),[F]);return(0,G.jsxs)(L,{title:_?.title||_?.plugin_id||m(`pluginHub.detailTitle`,null,`插件详情`),visible:n,onCancel:s,width:760,children:[(0,G.jsxs)(b,{activeKey:h,onChange:g,children:[(0,G.jsx)(w,{tab:m(`pluginHub.tabOverview`,null,`概览与权限`),itemKey:`overview`,children:_&&(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,style:{marginTop:12},children:[(_.observed_state===`failed`||_.observed_state===`degraded`)&&(0,G.jsx)(a,{type:`danger`,bordered:!0,closeIcon:null,title:H(m,_.last_error_code,m(`pluginHub.errorInstallFailed`,null,`插件安装或运行异常`)),description:(0,G.jsxs)(c,{wrap:!0,style:{marginTop:4},children:[i&&f&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,icon:(0,G.jsx)(v,{}),onClick:()=>f(_),children:m(`pluginHub.askAgentTroubleshoot`,null,`交给 CSAI Agent 排错并修复`)}),r&&(0,G.jsx)(p,{size:`small`,onClick:()=>g(`logs`),children:m(`pluginHub.viewLogs`,null,`查看运行日志`)})]})}),(0,G.jsx)(R,{columns:2,items:[{label:m(`pluginHub.installId`,null,`实例 ID`),value:(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:_.id})},{label:m(`pluginHub.pluginId`,null,`插件标识`),value:_.plugin_id},{label:m(`pluginHub.version`,null,`版本`),value:_.version||`—`},{label:m(`pluginHub.driver`,null,`驱动`),value:U(m,_.driver)},{label:m(`pluginHub.observedState`,null,`运行状态`),value:(0,G.jsx)(d,{color:Se(_.observed_state),children:Ce(m,_.observed_state)})},{label:m(`pluginHub.proxyMode`,null,`代理隔离模式`),value:_.proxy_mode||`port`},{label:m(`pluginHub.repository`,null,`源码仓库`),value:_.repository?(0,G.jsx)(`span`,{className:`cs-ph-mono`,children:_.repository}):`—`},{label:m(`pluginHub.lastError`,null,`最近错误`),value:_.last_error_code||`—`}]}),_.summary&&(0,G.jsx)(q,{type:`tertiary`,children:_.summary}),_.permissions&&(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsx)(K,{strong:!0,children:m(`pluginHub.declaredPermissions`,null,`声明权限`)}),(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsxs)(d,{children:[m(`pluginHub.permPersistentData`,null,`持久化数据卷`),`: `,_.permissions.persistentData?`Yes`:`No`]}),(0,G.jsxs)(d,{children:[m(`pluginHub.permModelGateway`,null,`CSAI 模型网关`),`: `,_.permissions.modelGateway?`Yes`:`No`]}),(_.permissions.egress||[]).map(e=>(0,G.jsx)(d,{color:`purple`,children:e},e))]})]}),_.extensions?.capabilities?.length>0&&(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsx)(K,{strong:!0,children:m(`pluginHub.declaredExtensions`,null,`声明的扩展能力(MCP / OpenAPI 预留)`)}),(0,G.jsx)(c,{wrap:!0,children:_.extensions.capabilities.map(e=>(0,G.jsxs)(d,{color:`cyan`,children:[e.id,` (`,e.transport,` `,e.path,`)`]},e.id))})]})]})}),_?.llm_declared&&(0,G.jsx)(w,{tab:m(`pluginHub.tabLLM`,null,`CSAI 模型绑定`),itemKey:`llm`,children:(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,style:{marginTop:12},children:[N&&(0,G.jsx)(a,{type:`info`,bordered:!0,closeIcon:null,description:(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsx)(`span`,{children:m(`pluginHub.restartRequiredForLLM`,null,`模型绑定已更新,重启插件后将立即注入新的 CSAI 网关凭据。`)}),r&&l&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,onClick:()=>l(_),children:m(`pluginHub.restartNow`,null,`立即重启生效`)})]})}),(0,G.jsx)(q,{type:`tertiary`,style:{margin:0},children:m(`pluginHub.llmBindingDesc`,null,`CSAI 通过本地模型网关向插件注入隔离 Token 与通道配置,插件无法接触您的真实上游 API Key。`)}),(0,G.jsxs)(C,{value:T,onChange:e=>D(e.target.value),disabled:!r,children:[(0,G.jsx)(E,{value:`follow_default`,children:m(`pluginHub.llmModeFollowDefault`,null,`跟随 CSAI 默认模型通道`)}),(0,G.jsx)(E,{value:`channel`,children:m(`pluginHub.llmModeChannel`,null,`指定 CSAI 模型通道`)}),(0,G.jsx)(E,{value:`disabled`,children:m(`pluginHub.llmModeDisabled`,null,`关闭模型托管`)})]}),T===`channel`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{strong:!0,size:`small`,children:m(`pluginHub.selectChannel`,null,`选择兼容通道`)}),(0,G.jsx)(ae,{value:O,onChange:k,disabled:!r,style:{width:`100%`,marginTop:4},placeholder:m(`pluginHub.selectChannelPlaceholder`,null,`请选择在 CSAI 系统设置中配置的模型通道`),optionList:_e.map(e=>({value:e.id,label:`${e.name} (${e.model} · ${e.provider})${e.is_default?` [Default]`:``}`}))})]}),T!==`disabled`&&(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{size:`small`,type:`tertiary`,children:m(`pluginHub.limitConcurrency`,null,`并发上限`)}),(0,G.jsx)(ie,{value:ee,onChange:A,min:1,max:32,disabled:!r,style:{display:`block`,marginTop:4}})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{size:`small`,type:`tertiary`,children:m(`pluginHub.limitRPM`,null,`每分钟请求 (RPM)`)}),(0,G.jsx)(ie,{value:j,onChange:te,min:1,max:1e3,disabled:!r,style:{display:`block`,marginTop:4}})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(K,{size:`small`,type:`tertiary`,children:m(`pluginHub.limitTokenBudget`,null,`每日 Token 预算`)}),(0,G.jsx)(ie,{value:ne,onChange:M,min:1e3,step:1e5,disabled:!r,style:{display:`block`,marginTop:4,width:180}})]})]}),r&&(0,G.jsx)(`div`,{children:(0,G.jsx)(p,{theme:`solid`,type:`primary`,loading:oe,onClick:he,children:m(`pluginHub.saveLLM`,null,`保存模型配置`)})})]})}),r&&(0,G.jsx)(w,{tab:m(`pluginHub.logs`,null,`运行日志`),itemKey:`logs`,children:(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,style:{marginTop:12},children:[(0,G.jsxs)(c,{style:{justifyContent:`space-between`,width:`100%`},children:[(0,G.jsxs)(c,{children:[(0,G.jsx)(d,{color:ue?`green`:`grey`,children:ue?m(`pluginHub.logStreaming`,null,`SSE 实时追踪中`):m(`pluginHub.logPaused`,null,`已停止追踪`)}),(0,G.jsxs)(K,{size:`small`,type:`tertiary`,children:[F.length,` lines`]})]}),(0,G.jsxs)(c,{children:[(0,G.jsx)(z,{text:ve,label:m(`common.copy`,null,`复制`)}),(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(re,{}),onClick:()=>g(`overview`)||setTimeout(()=>g(`logs`),0),children:m(`common.refresh`,null,`刷新`)})]})]}),(0,G.jsx)(`pre`,{ref:fe,className:`cs-ph-log-box`,children:ve||m(`pluginHub.noLogs`,null,`暂无运行日志`)})]})})]}),x&&!_&&(0,G.jsx)(K,{type:`tertiary`,children:m(`common.loading`,null,`加载中…`)})]})}function Ne({visible:e,canUseAgent:t,onCancel:n,onAskAgentDriverFix:r}){let i=P(),[o,s]=(0,V.useState)(`standard`),[l,f]=(0,V.useState)(null),[m,h]=(0,V.useState)(!1),g=async(e=o)=>{h(!0);try{let t=await W.probes(e);f(t)}catch(e){I(H(i,e))}finally{h(!1)}};return(0,V.useEffect)(()=>{e&&g(o)},[e,o]),(0,G.jsx)(L,{title:i(`pluginHub.runtimeProbesTitle`,null,`宿主运行环境与驱动预检`),visible:e,onCancel:n,width:660,children:(0,G.jsxs)(`div`,{className:`cs-ph-drawer-stack`,children:[(0,G.jsxs)(c,{style:{justifyContent:`space-between`,width:`100%`},wrap:!0,children:[(0,G.jsxs)(C,{type:`button`,value:o,onChange:e=>s(e.target.value),children:[(0,G.jsx)(E,{value:`standard`,children:`standard`}),(0,G.jsx)(E,{value:`strict`,children:`strict`})]}),(0,G.jsx)(p,{icon:(0,G.jsx)(re,{}),loading:m,onClick:()=>g(o),children:i(`common.refresh`,null,`重新检测`)})]}),l&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(R,{columns:2,items:[{label:i(`pluginHub.hostPlatform`,null,`宿主平台`),value:`${l.os}/${l.arch}`},{label:i(`pluginHub.workerReady`,null,`运行调度器`),value:(0,G.jsx)(d,{color:l.execution_enabled?`green`:`amber`,children:l.execution_enabled?i(`pluginHub.ready`,null,`就绪`):i(`pluginHub.notReady`,null,`未就绪`)})}]}),Object.entries(l.drivers||{}).map(([e,n])=>(0,G.jsxs)(`div`,{className:`cs-ph-probe-card`,children:[(0,G.jsxs)(c,{style:{justifyContent:`space-between`,width:`100%`},children:[(0,G.jsx)(K,{strong:!0,children:U(i,e)}),(0,G.jsx)(d,{color:n.available?`green`:`red`,prefixIcon:n.available?(0,G.jsx)(A,{}):(0,G.jsx)(te,{}),children:n.available?i(`pluginHub.available`,null,`可用`):n.code||i(`pluginHub.unavailable`,null,`不可用`)})]}),!n.available&&n.code&&(0,G.jsx)(K,{type:`danger`,size:`small`,children:H(i,n.code,n.guidance)}),n.guidance&&(0,G.jsx)(K,{type:`tertiary`,size:`small`,children:n.guidance}),!n.available&&n.install_command&&(0,G.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,flexWrap:`wrap`,marginTop:4},children:[(0,G.jsx)(`code`,{className:`cs-ph-mono`,style:{fontSize:12,padding:`4px 8px`,borderRadius:4,background:`var(--semi-color-fill-1)`,wordBreak:`break-all`},children:n.install_command}),(0,G.jsx)(z,{text:n.install_command,label:i(`common.copy`,null,`复制`)})]}),!n.available&&(t||n.download_url)&&(0,G.jsxs)(c,{wrap:!0,style:{marginTop:6},children:[t&&r&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,icon:(0,G.jsx)(v,{}),onClick:()=>r({driver:e,probe:n,hostOS:l.os,hostArch:l.arch}),children:i(`pluginHub.askAgentInstallDriver`,null,`交给 CSAI Agent 自动安装配置`)}),n.download_url&&(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(u,{}),onClick:()=>window.open(n.download_url,`_blank`,`noopener,noreferrer`),children:i(`pluginHub.officialDownload`,null,`官方下载`)})]})]},e)),l.drivers?.container&&!l.drivers.container.available&&(0,G.jsx)(a,{type:`info`,bordered:!0,closeIcon:null,description:l.os===`linux`?i(`pluginHub.dockerInstallLinuxHint`,null,`Linux / Kali 宿主可直接点击上方「交给 CSAI Agent 自动安装配置」,或手动安装 docker.io 与 docker-compose-plugin 并启动 dockerd,完成后点击「重新检测」。`):i(`pluginHub.dockerInstallDesktopHint`,null,`macOS / Windows 可点击「官方下载」安装并启动 Docker Desktop(或交给 Agent 通过 Homebrew/winget 协助安装),也可优先选择 Release / Git 原生驱动。`)})]})]})})}var{Text:J,Paragraph:Pe}=s;function Y(){let e=P(),t=n(),{hasPermission:r}=se(),s=r(`plugins:manage`),m=r(`plugins:use`),g=r(`chat:write`)&&r(`agent:execute`),[_,y]=i(),C=_.get(`app`)||``,E=_.get(`tab`)||`installed`,[A,ie]=(0,V.useState)(``),[ae,M]=(0,V.useState)(!1),[N,L]=(0,V.useState)(null),[R,z]=(0,V.useState)(!1),[me,ge]=(0,V.useState)(!1),[ve,ye]=(0,V.useState)(!1),[we,Te]=(0,V.useState)(null),[Ee,De]=(0,V.useState)(``),[K,q]=(0,V.useState)(null),[Y,Fe]=(0,V.useState)(null),[Ie,Le]=(0,V.useState)(``),X=F(()=>W.listInstalls(),[]),Z=F(()=>W.listCatalog(),[]),Re=F(()=>W.listLLMChannels(),[]),Q=F(()=>W.probes(`standard`),[],{skip:!s}),$=Array.isArray(X.data?.items)?X.data.items:[],ze=Array.isArray(Z.data?.items)?Z.data.items:[],Be=Number(Z.data?.hidden_builtins||0),Ve=Array.isArray(Re.data?.channels)?Re.data.channels:[],He=(0,V.useMemo)(()=>$.find(e=>e.id===C)||null,[$,C]),Ue=e=>{let t=new URLSearchParams(_);t.set(`tab`,e),t.delete(`app`),y(t,{replace:!0})},We=e=>{let t=new URLSearchParams(_);t.set(`tab`,`installed`),t.set(`app`,e.id),y(t)},Ge=()=>{let e=new URLSearchParams(_);e.delete(`app`),y(e,{replace:!0})},Ke=(0,V.useCallback)(()=>{X.reload({silent:!0}),Z.reload({silent:!0}),Re.reload({silent:!0})},[X,Z,Re]);fe(async()=>{if(Y?.id&&s)try{let t=await W.getOperation(Y.id);Fe(t),t.status!==`queued`&&t.status!==`running`&&(X.reload({silent:!0}),t.status===`succeeded`?B(e(`pluginHub.opSucceeded`,{kind:t.kind},`操作 ${t.kind} 已完成`)):t.status===`failed`&&I(e(`pluginHub.opFailed`,{kind:t.kind},`操作 ${t.kind} 失败,请查看插件日志`)))}catch{}},Y&&(Y.status===`queued`||Y.status===`running`)?1500:null);let qe=$.some(e=>[`installing`,`starting`,`stopping`].includes(e.observed_state));fe(()=>{X.reload({silent:!0})},qe?3e3:null);let Je=async t=>{if(t.availability!==`plan_available`)L({repository:t.repository,revision:t.revision||``}),M(!0);else{De(t.id);try{let e=await W.createPlan({catalog_id:t.id,driver:`auto`,isolation:`standard`});Te(e)}catch(t){I(H(e,t,e(`pluginHub.createPlanFailed`,null,`生成安装计划失败`)))}finally{De(``)}}},Ye=t=>{he({title:e(`pluginHub.confirmDeleteCatalogTitle`,{name:t.title||t.id},`从能力市场移除「${t.title||t.id}」?`),content:(0,G.jsx)(J,{type:`tertiary`,children:t.builtin?e(`pluginHub.confirmHideBuiltinDesc`,null,`该条目为内置精选目录项,移除后将在市场中隐藏,可随时通过「恢复默认精选」找回;不会影响已安装的实例。`):e(`pluginHub.confirmDeleteCustomDesc`,null,`将从能力市场永久删除该自定义条目,不会影响已安装的插件实例。`)}),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await W.deleteCatalog(t.id),B(e(`pluginHub.catalogDeleted`,null,`已从能力市场移除`)),Z.reload({silent:!0})}catch(t){I(H(e,t,e(`pluginHub.catalogDeleteFailed`,null,`删除市场条目失败`)))}}})},Xe=async()=>{ge(!0);try{await W.restoreCatalog(),B(e(`pluginHub.catalogRestored`,null,`已恢复全部默认精选目录`)),Z.reload({silent:!0})}catch(t){I(H(e,t,e(`pluginHub.catalogRestoreFailed`,null,`恢复默认精选失败`)))}finally{ge(!1)}},Ze=(0,V.useCallback)(({driver:n,probe:r,hostOS:i,hostArch:a,pluginTitle:o})=>{let s=be({driver:n,probe:r,hostOS:i||Q.data?.os,hostArch:a||Q.data?.arch,pluginTitle:o});_e({prompt:s,autoSend:!0}),ye(!1),Te(null),B(e(`pluginHub.handoffToAgent`,null,`已将安装任务交给 CSAI Agent,正在跳转对话工作台…`)),t(`/chat`)},[t,Q.data?.arch,Q.data?.os,e]),Qe=(0,V.useCallback)(async n=>{let r=[];try{let e=await W.readLogs(n.id,0,50);r=Array.isArray(e?.items)?e.items:[]}catch{}let i=xe({install:n,logs:r,hostOS:Q.data?.os,hostArch:Q.data?.arch});_e({prompt:i,autoSend:!0}),q(null),B(e(`pluginHub.handoffTroubleshoot`,null,`已将排错与修复任务交给 CSAI Agent,正在跳转对话工作台…`)),t(`/chat`)},[t,Q.data?.arch,Q.data?.os,e]),$e=async(t,n,r={})=>{Le(t.id);try{let i=await W.operate(t.id,n,r);Fe(i),B(e(`pluginHub.opQueued`,{kind:n},`已提交 ${n} 任务`)),X.reload({silent:!0})}catch(t){I(H(e,t))}finally{Le(``)}},et=t=>{let n=!1;he({title:e(`pluginHub.confirmUninstallTitle`,{name:t.title||t.plugin_id},`卸载插件「${t.title||t.plugin_id}」?`),content:(0,G.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,G.jsx)(J,{type:`tertiary`,children:e(`pluginHub.confirmUninstallDesc`,null,`将停止插件进程/容器、撤销代理会话与模型网关 Token,并退役隔离端口。`)}),(0,G.jsx)(f,{onChange:e=>{n=!!e.target.checked},children:e(`pluginHub.purgeDataOption`,null,`同时删除持久化运行数据与卷(默认保留数据)`)})]}),okText:e(`pluginHub.uninstall`,null,`卸载`),onOk:()=>$e(t,`uninstall`,{purge_data:n})})},tt=(0,V.useMemo)(()=>{let e=A.trim().toLowerCase();return e?$.filter(t=>String(t.title||``).toLowerCase().includes(e)||String(t.plugin_id||``).toLowerCase().includes(e)||String(t.driver||``).toLowerCase().includes(e)):$},[$,A]),nt=(0,V.useMemo)(()=>{let e=A.trim().toLowerCase();return e?ze.filter(t=>String(t.title||``).toLowerCase().includes(e)||String(t.id||``).toLowerCase().includes(e)||String(t.summary||``).toLowerCase().includes(e)):ze},[ze,A]),rt=$.filter(e=>e.observed_state===`healthy`).length,it=Q.data?.drivers||{},at=Object.entries(it).filter(([,e])=>e?.available).map(([e])=>e);if(C&&He)return(0,G.jsxs)(`div`,{className:`cs-ph-root`,children:[(0,G.jsx)(Oe,{install:He,canManage:s,onBack:Ge,onOpenDetail:()=>q({id:He.id,tab:`overview`}),onOpenLogs:()=>q({id:He.id,tab:`logs`})}),(0,G.jsx)(Me,{installId:K?.id,initialTab:K?.tab,visible:!!K,canManage:s,canUseAgent:g,channels:Ve,onCancel:()=>q(null),onRestartRequested:e=>$e(e,`restart`),onAskAgentTroubleshoot:Qe,onChanged:Ke})]});let ot=[{title:e(`pluginHub.pluginTitle`,null,`插件应用`),dataIndex:`title`,render:(t,n)=>(0,G.jsxs)(c,{vertical:!0,spacing:2,align:`start`,children:[(0,G.jsxs)(c,{spacing:6,children:[(0,G.jsx)(J,{strong:!0,children:t||n.plugin_id}),(0,G.jsx)(d,{size:`small`,color:`grey`,children:n.plugin_id})]}),n.last_error_code&&(0,G.jsx)(J,{type:`danger`,size:`small`,children:H(e,n.last_error_code,n.last_error_code)})]})},{title:e(`pluginHub.observedState`,null,`运行状态`),dataIndex:`observed_state`,width:130,render:t=>(0,G.jsx)(d,{color:Se(t),shape:`square`,children:Ce(e,t)})},{title:e(`pluginHub.driver`,null,`驱动`),dataIndex:`driver`,width:160,render:t=>U(e,t)},{title:e(`pluginHub.updatedAt`,null,`更新时间`),dataIndex:`updated_at`,width:170,render:e=>oe(e)},{title:e(`common.actions`,null,`操作`),width:300,render:(t,n)=>{let r=n.observed_state===`healthy`,i=Ie===n.id||[`installing`,`starting`,`stopping`].includes(n.observed_state);return(0,G.jsxs)(c,{spacing:4,wrap:!0,children:[m&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,icon:(0,G.jsx)(u,{}),disabled:!r,onClick:()=>We(n),children:e(`pluginHub.openWorkspace`,null,`打开应用`)}),s&&!r&&(0,G.jsx)(D,{content:n.observed_state===`failed`?e(`pluginHub.retryInstallOrStart`,null,`重试安装 / 启动`):e(`pluginHub.start`,null,`启动`),children:(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(k,{}),loading:i,onClick:()=>$e(n,`start`)})}),g&&(n.observed_state===`failed`||n.observed_state===`degraded`)&&(0,G.jsx)(p,{size:`small`,theme:`light`,type:`warning`,icon:(0,G.jsx)(v,{}),onClick:()=>Qe(n),children:e(`pluginHub.agentFixBtn`,null,`Agent 排错`)}),s&&r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(D,{content:e(`pluginHub.restart`,null,`重启`),children:(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(ne,{}),loading:i,onClick:()=>$e(n,`restart`)})}),(0,G.jsx)(D,{content:e(`pluginHub.stop`,null,`停止`),children:(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(te,{}),loading:i,onClick:()=>$e(n,`stop`)})})]}),s&&(0,G.jsx)(D,{content:e(`pluginHub.logs`,null,`实时日志`),children:(0,G.jsx)(p,{size:`small`,theme:`borderless`,icon:(0,G.jsx)(x,{}),onClick:()=>q({id:n.id,tab:`logs`})})}),(0,G.jsx)(D,{content:e(`pluginHub.settingsAndDetail`,null,`详情与模型绑定`),children:(0,G.jsx)(p,{size:`small`,theme:`borderless`,icon:(0,G.jsx)(O,{}),onClick:()=>q({id:n.id,tab:`overview`})})}),s&&(0,G.jsx)(D,{content:e(`pluginHub.uninstall`,null,`卸载`),children:(0,G.jsx)(p,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,G.jsx)(l,{}),onClick:()=>et(n)})})]})}}];return(0,G.jsxs)(`div`,{className:`cs-ph-root`,children:[(0,G.jsx)(de,{title:e(`pluginHub.title`,null,`插件化能力平台`),description:e(`pluginHub.subtitle`,null,`按需拉取独立红队与安全开源项目,保留原作者仓库隔离,支持页面无缝内嵌与 CSAI 模型通道统一复用。`),extra:(0,G.jsxs)(c,{wrap:!0,children:[s&&(0,G.jsx)(p,{icon:(0,G.jsx)(ee,{}),onClick:()=>ye(!0),children:e(`pluginHub.runtimeProbes`,null,`运行环境预检`)}),s&&(0,G.jsx)(p,{theme:`solid`,type:`primary`,icon:(0,G.jsx)(S,{}),onClick:()=>M(!0),children:e(`pluginHub.importGit`,null,`手工导入 Git 仓库`)}),(0,G.jsx)(p,{icon:(0,G.jsx)(re,{}),onClick:Ke,loading:X.loading||Z.loading,children:e(`common.refresh`,null,`刷新`)})]})}),(0,G.jsx)(ce,{columns:4,metrics:[{id:`installed`,label:e(`pluginHub.statInstalled`,null,`已安装插件`),value:$.length,icon:(0,G.jsx)(j,{}),onClick:()=>Ue(`installed`)},{id:`healthy`,label:e(`pluginHub.statRunning`,null,`运行中应用`),value:rt,tone:rt>0?`success`:void 0,icon:(0,G.jsx)(k,{}),onClick:()=>Ue(`installed`)},{id:`catalog`,label:e(`pluginHub.statCatalog`,null,`官方精选目录`),value:ze.length,icon:(0,G.jsx)(o,{}),onClick:()=>Ue(`market`)},{id:`drivers`,label:e(`pluginHub.statDrivers`,null,`宿主可用驱动`),value:s&&at.length?at.join(` / `):`—`,detail:Q.data?`${Q.data.os}/${Q.data.arch}`:void 0,icon:(0,G.jsx)(v,{}),onClick:s?()=>ye(!0):void 0}]}),Y&&(0,G.jsx)(a,{type:Y.status===`failed`?`danger`:Y.status===`succeeded`?`success`:`info`,bordered:!0,onClose:()=>Fe(null),description:(0,G.jsxs)(c,{wrap:!0,children:[(0,G.jsxs)(J,{strong:!0,children:[e(`pluginHub.latestOperation`,null,`最近任务`),`: `,Y.kind]}),(0,G.jsx)(d,{size:`small`,color:Y.status===`succeeded`?`green`:Y.status===`failed`?`red`:`blue`,children:Y.status}),s&&Y.install_id&&(0,G.jsx)(p,{size:`small`,theme:`borderless`,onClick:()=>q({id:Y.install_id,tab:`logs`}),children:e(`pluginHub.viewLogs`,null,`查看日志`)})]})}),(0,G.jsxs)(ue,{children:[(0,G.jsx)(le,{error:X.error||Z.error,onRetry:Ke}),(0,G.jsxs)(b,{activeKey:E,onChange:Ue,tabBarExtraContent:(0,G.jsx)(h,{prefix:(0,G.jsx)(T,{}),value:A,onChange:ie,placeholder:e(`pluginHub.searchPlaceholder`,null,`搜索插件名称或描述`),style:{width:260},showClear:!0}),children:[(0,G.jsx)(w,{tab:`${e(`pluginHub.tabInstalled`,null,`已安装应用`)} (${$.length})`,itemKey:`installed`,children:(0,G.jsx)(`div`,{style:{marginTop:12},children:(0,G.jsx)(pe,{columns:ot,dataSource:tt,loading:X.loading,emptyText:e(`pluginHub.emptyInstalled`,null,`暂未安装插件,可切换到「能力市场」一键下载或手工导入 Git 仓库`)})})}),(0,G.jsxs)(w,{tab:`${e(`pluginHub.marketTitle`,null,`能力市场`)} (${ze.length})`,itemKey:`market`,children:[s&&(0,G.jsxs)(c,{style:{justifyContent:`space-between`,width:`100%`,marginTop:12},wrap:!0,children:[(0,G.jsx)(J,{type:`tertiary`,size:`small`,children:e(`pluginHub.marketManageHint`,null,`支持自由新增开源仓库或删除/隐藏条目;已安装的插件不受市场目录变更影响。`)}),(0,G.jsxs)(c,{wrap:!0,children:[Be>0&&(0,G.jsx)(p,{size:`small`,icon:(0,G.jsx)(re,{}),loading:me,onClick:Xe,children:e(`pluginHub.restoreBuiltins`,{count:Be},`恢复默认精选 (${Be})`)}),(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,icon:(0,G.jsx)(S,{}),onClick:()=>z(!0),children:e(`pluginHub.addCatalogBtn`,null,`新增市场插件`)})]})]}),(0,G.jsx)(`div`,{className:`cs-ph-catalog-grid`,style:{marginTop:14},children:nt.length===0?(0,G.jsx)(J,{type:`tertiary`,style:{padding:`16px 0`},children:e(`pluginHub.emptyMarket`,null,`当前能力市场暂无匹配条目,可点击「新增市场插件」添加。`)}):nt.map(t=>{let n=$.find(e=>e.plugin_id===t.id),r=t.availability===`plan_available`;return(0,G.jsxs)(`div`,{className:`cs-ph-card`,children:[(0,G.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,G.jsxs)(`div`,{className:`cs-ph-card-head`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(c,{spacing:6,children:[(0,G.jsx)(J,{strong:!0,size:`normal`,children:t.title}),!t.builtin&&(0,G.jsx)(d,{size:`small`,color:`violet`,children:e(`pluginHub.catalogCustomBadge`,null,`自定义`)})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(J,{type:`tertiary`,size:`small`,className:`cs-ph-mono`,children:t.id})})]}),(0,G.jsx)(d,{size:`small`,color:r?`green`:`blue`,children:r?e(`pluginHub.catalogOneClick`,null,`支持一键安装`):e(`pluginHub.catalogInspectOnly`,null,`支持探测导入`)})]}),(0,G.jsx)(Pe,{type:`tertiary`,size:`small`,style:{margin:0},children:t.summary||e(`pluginHub.noSummary`,null,`暂无简介`)}),(0,G.jsx)(`div`,{className:`cs-ph-card-meta`,children:(0,G.jsx)(`a`,{href:t.repository,target:`_blank`,rel:`noreferrer`,style:{fontSize:12},children:t.repository.replace(`https://github.com/`,`github.com/`)})})]}),(0,G.jsxs)(`div`,{className:`cs-ph-card-footer`,children:[n?(0,G.jsxs)(d,{color:Se(n.observed_state),children:[e(`pluginHub.installedBadge`,null,`已安装`),` · `,Ce(e,n.observed_state)]}):(0,G.jsx)(J,{type:`tertiary`,size:`small`,children:e(`pluginHub.externalRepoHint`,null,`代码保留在原作者仓库`)}),(0,G.jsxs)(c,{spacing:6,children:[s&&(0,G.jsx)(D,{content:t.builtin?e(`pluginHub.hideBuiltinTooltip`,null,`从市场隐藏`):e(`common.delete`,null,`删除`),children:(0,G.jsx)(p,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,G.jsx)(l,{}),onClick:()=>Ye(t)})}),n&&m&&n.observed_state===`healthy`&&(0,G.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,onClick:()=>We(n),children:e(`pluginHub.openWorkspace`,null,`打开应用`)}),!n&&s&&(0,G.jsx)(p,{size:`small`,theme:r?`solid`:`light`,type:`primary`,icon:(0,G.jsx)(o,{}),loading:Ee===t.id,onClick:()=>Je(t),children:r?e(`pluginHub.oneClickInstall`,null,`一键下载安装`):e(`pluginHub.inspectAndImport`,null,`探测并导入`)})]})]})]},t.id)})})]})]})]}),(0,G.jsx)(Ae,{visible:R,onCancel:()=>z(!1),onSaved:()=>{z(!1),Z.reload({silent:!0})}}),(0,G.jsx)(je,{visible:ae,initialEntry:N,onCancel:()=>{M(!1),L(null)},onCatalogSaved:()=>Z.reload({silent:!0}),onPlanReady:e=>{M(!1),L(null),Te(e)}}),(0,G.jsx)(ke,{planResponse:we,channels:Ve,visible:!!we,canUseAgent:g,onCancel:()=>Te(null),onAskAgentDriverFix:Ze,onConfirmed:e=>{Te(null),Fe(e),Ue(`installed`),X.reload({silent:!0})}}),(0,G.jsx)(Me,{installId:K?.id,initialTab:K?.tab,visible:!!K,canManage:s,canUseAgent:g,channels:Ve,onCancel:()=>q(null),onRestartRequested:e=>$e(e,`restart`),onAskAgentTroubleshoot:Qe,onChanged:Ke}),(0,G.jsx)(Ne,{visible:ve,canUseAgent:g,onCancel:()=>ye(!1),onAskAgentDriverFix:Ze})]})}export{Y as default};
\ No newline at end of file
diff --git a/web/static/app/assets/project-form-EwCREgUA.js b/web/static/app/assets/project-form-Dt6NB8i_.js
similarity index 82%
rename from web/static/app/assets/project-form-EwCREgUA.js
rename to web/static/app/assets/project-form-Dt6NB8i_.js
index da9bff2e..9ea5d860 100644
--- a/web/static/app/assets/project-form-EwCREgUA.js
+++ b/web/static/app/assets/project-form-Dt6NB8i_.js
@@ -1 +1 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,i}from"./semi-65W_4I1v.js";import{I as a,P as o,c as s,l as c,x as l}from"./index-BdnarFZR.js";var u=e(t(),1),d=e(n(),1),{Text:f}=r,p=120,m=4e3;function h({visible:e,project:t,onCancel:n,onSaved:r}){let h=o(),g=(0,u.useId)(),[_,v]=(0,u.useState)(!1),[y,b]=(0,u.useState)(null),x=!!t?.id;return(0,u.useEffect)(()=>{b(null)},[e,t?.id]),(0,d.jsxs)(s,{visible:e,width:560,closable:!_,closeOnEsc:!_,onCancel:n,cancelButtonProps:{disabled:_},title:x?h(`projects.modalEditTitle`,null,`编辑项目`):h(`projects.modalNewTitle`,null,`新建项目`),formId:g,okText:x?h(`projects.saveChanges`,null,`保存修改`):h(`projects.createProject`,null,`创建项目`),confirmLoading:_,children:[(0,d.jsx)(f,{type:`tertiary`,size:`small`,children:x?h(`projects.modalEditSubtitle`,null,`修改项目名称与描述`):h(`projects.modalNewSubtitle`,null,`创建后可绑定对话,跨会话共享事实黑板`)}),(0,d.jsxs)(i,{id:g,onSubmit:async e=>{if(!_){v(!0),b(null);try{let n={name:e.name.trim(),description:(e.description||``).slice(0,m)},i=x?await a.put(`/projects/${t.id}`,n):await a.post(`/projects`,n);l(x?h(`projects.saved`,null,`已保存`):h(`projects.createProject`,null,`创建项目`)),r?.(i)}catch(e){b(e)}finally{v(!1)}}},initValues:{name:t?.name||``,description:t?.description||``},children:[(0,d.jsx)(i.Input,{id:`${g}-name`,field:`name`,maxLength:p,label:h(`projects.projectName`,null,`项目名称`),placeholder:h(`projects.projectNamePlaceholder`,null,`例如:某客户 Web 渗透`),rules:[{required:!0,whitespace:!0,message:h(`projects.enterProjectName`,null,`请输入项目名称`)}]}),(0,d.jsx)(i.TextArea,{id:`${g}-description`,field:`description`,rows:4,maxCount:m,label:h(`projects.projectDescription`,null,`项目描述`),placeholder:h(`projects.projectDescriptionPlaceholder`,null,`客户/任务备注、协作说明…`),extraText:h(`projects.descriptionLengthHint`,null,`仅供团队成员查阅,Agent 不会读取;需让 Agent 知晓的内容请写入事实黑板`)}),(0,d.jsx)(c,{error:y})]},`${e}-${t?.id||`new`}`)]})}export{h as t};
\ No newline at end of file
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,i}from"./semi-65W_4I1v.js";import{F as a,L as o,c as s,l as c,x as l}from"./index-_8d9XBPJ.js";var u=e(t(),1),d=e(n(),1),{Text:f}=r,p=120,m=4e3;function h({visible:e,project:t,onCancel:n,onSaved:r}){let h=a(),g=(0,u.useId)(),[_,v]=(0,u.useState)(!1),[y,b]=(0,u.useState)(null),x=!!t?.id;return(0,u.useEffect)(()=>{b(null)},[e,t?.id]),(0,d.jsxs)(s,{visible:e,width:560,closable:!_,closeOnEsc:!_,onCancel:n,cancelButtonProps:{disabled:_},title:x?h(`projects.modalEditTitle`,null,`编辑项目`):h(`projects.modalNewTitle`,null,`新建项目`),formId:g,okText:x?h(`projects.saveChanges`,null,`保存修改`):h(`projects.createProject`,null,`创建项目`),confirmLoading:_,children:[(0,d.jsx)(f,{type:`tertiary`,size:`small`,children:x?h(`projects.modalEditSubtitle`,null,`修改项目名称与描述`):h(`projects.modalNewSubtitle`,null,`创建后可绑定对话,跨会话共享事实黑板`)}),(0,d.jsxs)(i,{id:g,onSubmit:async e=>{if(!_){v(!0),b(null);try{let n={name:e.name.trim(),description:(e.description||``).slice(0,m)},i=x?await o.put(`/projects/${t.id}`,n):await o.post(`/projects`,n);l(x?h(`projects.saved`,null,`已保存`):h(`projects.createProject`,null,`创建项目`)),r?.(i)}catch(e){b(e)}finally{v(!1)}}},initValues:{name:t?.name||``,description:t?.description||``},children:[(0,d.jsx)(i.Input,{id:`${g}-name`,field:`name`,maxLength:p,label:h(`projects.projectName`,null,`项目名称`),placeholder:h(`projects.projectNamePlaceholder`,null,`例如:某客户 Web 渗透`),rules:[{required:!0,whitespace:!0,message:h(`projects.enterProjectName`,null,`请输入项目名称`)}]}),(0,d.jsx)(i.TextArea,{id:`${g}-description`,field:`description`,rows:4,maxCount:m,label:h(`projects.projectDescription`,null,`项目描述`),placeholder:h(`projects.projectDescriptionPlaceholder`,null,`客户/任务备注、协作说明…`),extraText:h(`projects.descriptionLengthHint`,null,`仅供团队成员查阅,Agent 不会读取;需让 Agent 知晓的内容请写入事实黑板`)}),(0,d.jsx)(c,{error:y})]},`${e}-${t?.id||`new`}`)]})}export{h as t};
\ No newline at end of file
diff --git a/web/static/app/assets/projects-BDK_5JF_.js b/web/static/app/assets/projects-B6zINg50.js
similarity index 95%
rename from web/static/app/assets/projects-BDK_5JF_.js
rename to web/static/app/assets/projects-B6zINg50.js
index c1bd7cd8..33a1b2e7 100644
--- a/web/static/app/assets/projects-BDK_5JF_.js
+++ b/web/static/app/assets/projects-B6zINg50.js
@@ -1,4 +1,4 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{D as a,E as o,G as s,I as c,N as l,P as u,R as d,S as f,U as p,W as m,_ as h,c as g,d as _,ft as v,gt as y,h as b,lt as x,m as S,p as C,ut as w,v as T,y as E}from"./semi-65W_4I1v.js";import{E as D,F as O,I as k,P as A,_ as ee,a as j,b as M,c as N,d as P,f as F,l as te,m as I,n as L,p as R,s as z,t as B,x as V,y as H}from"./index-BdnarFZR.js";import{t as U}from"./project-form-EwCREgUA.js";import{a as W,i as ne,n as G,o as K,r as re,t as ie}from"./graph-parents-i1hc3RVG.js";import{t as ae}from"./AssetEditorModal-NbuAwvg-.js";var q=e(t(),1),oe=[{value:`target`,label:`target(目标)`},{value:`auth`,label:`auth(认证)`},{value:`infra`,label:`infra(基础设施)`},{value:`business`,label:`business(业务)`},{value:`finding`,label:`finding(发现)`},{value:`chain`,label:`chain(攻击链)`},{value:`exploit`,label:`exploit(利用)`},{value:`poc`,label:`poc(POC)`},{value:`note`,label:`note(备注)`}],se={target:`目标`,auth:`认证`,infra:`基础设施`,business:`业务`,finding:`发现`,chain:`攻击链`,exploit:`利用`,poc:`POC`,note:`备注`,vuln:`漏洞`,missing:`缺失`},ce=[{value:`tentative`,label:`待确认`},{value:`confirmed`,label:`已确认`},{value:`deprecated`,label:`已废弃`}],le={confirmed:{label:`已确认`,color:`green`},tentative:{label:`待确认`,color:`amber`},deprecated:{label:`已废弃`,color:`grey`}},ue=[{value:`active`,label:`进行中`},{value:`archived`,label:`已归档`}],J={target:`#2563eb`,auth:`#0891b2`,infra:`#0d9488`,finding:`#d97706`,chain:`#db2777`,exploit:`#7c3aed`,poc:`#7c3aed`,vulnerability:`#dc2626`,note:`#64748b`,missing:`#94a3b8`},de={target:`TARGET · 目标`,auth:`AUTH · 认证`,infra:`INFRA · 基础设施`,finding:`FINDING · 发现`,chain:`CHAIN · 攻击链`,exploit:`EXPLOIT · 利用`,poc:`POC · 验证`,vulnerability:`VULN · 漏洞`,note:`NOTE · 备注`,missing:`MISSING · 缺失`},fe=[`discovered_on`,`depends_on`,`leads_to`,`enables`,`exploits`];function Y(e,t=`操作失败`){if(!e)return t;if(typeof e==`string`)return e;let n=e.payload;if(n&&typeof n==`object`){let e=n.error;if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=typeof e.message==`string`?e.message:``,n=typeof e.code==`string`?e.code:``;if(t)return n?`${t}(${n})`:t}if(typeof n.message==`string`&&n.message)return n.message}return typeof e.message==`string`&&e.message&&e.message!==`[object Object]`?e.message:t}function pe(e,t=`加载失败`){return e?{message:Y(e,t)}:null}function me(e){return!Array.isArray(e)||!e.length?``:e.map(e=>`${e.edge_type||e.type||``}: ${e.source_fact_key||e.from||``}`.trim()).join(`
-`)}var X=e(r(),1),{Text:he}=s;function ge({value:e}){let t=le[String(e||``).toLowerCase()]||{label:e||`—`,color:`grey`};return(0,X.jsx)(l,{size:`small`,color:t.color,children:t.label})}function _e({projectId:e,canWrite:t,revision:r=0,onAddFact:i,onEditFact:a,onViewFact:o,onMutated:s}){let f=A(),m=n(),[g,_]=(0,q.useState)(``),y=L(g,300),[b,S]=(0,q.useState)(`all`),[C,T]=(0,q.useState)(`all`),[O,ee]=(0,q.useState)(!0),[N,P]=(0,q.useState)(!1),F=j(()=>k.get(`/projects/${e}/facts`,{limit:200,include_link_counts:`true`,exclude_deprecated:O?`true`:void 0,search:y.trim()||void 0,category:b===`all`?void 0:b,confidence:C===`all`?void 0:C,sparse_only:N?`true`:void 0}),[e,y,b,C,O,N,r]),R=(0,q.useMemo)(()=>Array.isArray(F.data)?F.data:[],[F.data]),B=async t=>{try{await k.post(`/projects/${e}/facts/deprecate`,{fact_key:t.fact_key}),V(f(`projects.saved`,null,`已保存`)),s?s():F.reload({silent:!0})}catch(e){M(Y(e,f(`projects.operationFailed`,null,`操作失败`)))}},U=async t=>{try{await k.post(`/projects/${e}/facts/restore`,{fact_key:t.fact_key,confidence:`tentative`}),V(f(`projects.saved`,null,`已保存`)),s?s():F.reload({silent:!0})}catch(e){M(Y(e,f(`projects.operationFailed`,null,`操作失败`)))}},W=t=>{H({title:f(`projects.deleteForeverTitle`,null,`永久删除`),content:f(`projects.confirmDeleteFact`,null,`删除该事实?`),okText:f(`common.delete`,null,`删除`),onOk:async()=>{try{await k.del(`/projects/${e}/facts/${t.id}`),V(f(`common.delete`,null,`删除`)),s?s():F.reload({silent:!0})}catch(e){M(Y(e,f(`projects.operationFailed`,null,`操作失败`)))}}})},ne=[{title:`fact_key`,dataIndex:`fact_key`,width:230,render:(e,t)=>(0,X.jsxs)(`div`,{className:`project-fact-key`,children:[(0,X.jsx)(`code`,{className:`project-fact-key-chip`,title:e,children:e}),(0,X.jsxs)(`div`,{className:`project-fact-key-meta`,children:[t.pinned&&(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:f(`projects.pinned`,null,`置顶`)}),t.related_vulnerability_id&&(0,X.jsx)(l,{size:`small`,color:`violet`,type:`light`,title:t.related_vulnerability_id,children:f(`projects.relatedVulnIdTitle`,null,`关联漏洞 ID`)})]})]})},{title:f(`projects.category`,null,`分类`),dataIndex:`category`,width:108,render:e=>(0,X.jsx)(l,{size:`small`,color:`cyan`,type:`light`,children:se[String(e||``).toLowerCase()]||e||`—`})},{title:f(`projects.summary`,null,`摘要`),dataIndex:`summary`,render:(e,t)=>(0,X.jsx)(`button`,{type:`button`,className:`project-cell-ellipsis project-link-button`,title:e,onClick:()=>o?.(t.fact_key),children:e||`—`})},{title:f(`projects.linksColumn`,null,`关系`),dataIndex:`link_counts`,width:92,render:e=>{let t=e?.outgoing||0,n=e?.incoming||0;return!t&&!n?(0,X.jsx)(he,{type:`tertiary`,children:`—`}):(0,X.jsxs)(`span`,{className:`project-link-counts`,title:f(`projects.linkCountsTitle`,null,`出边数 / 入边数`),children:[`↑`,t,` ↓`,n]})}},{title:f(`projects.confidence`,null,`置信度`),dataIndex:`confidence`,width:92,render:e=>(0,X.jsx)(ge,{value:e})},{title:f(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:158,render:e=>(0,X.jsx)(he,{size:`small`,children:D(e)})},{title:f(`common.actions`,null,`操作`),dataIndex:`id`,width:224,render:(e,n)=>{let r=String(n.confidence||``).toLowerCase()===`deprecated`;return(0,X.jsxs)(c,{spacing:2,wrap:!0,children:[(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>o?.(n.fact_key),children:f(`projects.details`,null,`详情`)}),n.source_conversation_id?(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>m(`/chat?conversation=${encodeURIComponent(n.source_conversation_id)}`),children:`会话`}):null,(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>a?.(n.fact_key),children:f(`common.edit`,null,`编辑`)}),r?(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>U(n),children:f(`projects.restore`,null,`恢复`)}):(0,X.jsx)(h,{title:f(`projects.confirmDeprecateFact`,{factKey:n.fact_key},`将事实 ${n.fact_key} 标记为已废弃?`),onConfirm:()=>B(n),disabled:!t,children:(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,title:f(`projects.deprecateTitle`,null,`标记为已废弃`),children:f(`projects.deprecate`,null,`废弃`)})}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>W(n),children:f(`common.delete`,null,`删除`)})]})}}];return(0,X.jsxs)(I,{title:f(`projects.tabFacts`,null,`事实黑板`),description:f(`projects.factToolbarHint`,null,`索引仅含 key 与摘要;攻击链 / POC 写在 body,Agent 通过 get_project_fact 复现`),extra:(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),theme:`borderless`,loading:F.loading,onClick:()=>{s?s():F.reload()}}),(0,X.jsx)(d,{type:`primary`,icon:(0,X.jsx)(v,{}),disabled:!t,onClick:i,children:f(`projects.addFact`,null,`添加事实`)})]}),children:[(0,X.jsx)(te,{error:pe(F.error),onRetry:F.reload}),(0,X.jsxs)(`div`,{className:`project-toolbar`,children:[(0,X.jsx)(p,{prefix:(0,X.jsx)(x,{}),value:g,showClear:!0,"aria-label":f(`projects.searchFactsSr`,null,`搜索事实`),placeholder:f(`projects.searchFactsPlaceholder`,null,`搜索 key、摘要、body…`),onChange:e=>_(e),style:{width:260}}),(0,X.jsx)(E,{value:b,onChange:S,style:{width:146},optionList:[{value:`all`,label:f(`projects.all`,null,`全部`)},...oe]}),(0,X.jsx)(E,{value:C,onChange:T,style:{width:128},optionList:[{value:`all`,label:f(`projects.all`,null,`全部`)},...ce]}),(0,X.jsx)(u,{checked:O,onChange:e=>ee(e.target.checked),children:f(`projects.hideDeprecated`,null,`隐藏废弃`)}),(0,X.jsx)(u,{checked:N,onChange:e=>P(e.target.checked),children:f(`projects.sparseOnly`,null,`仅待补全`)})]}),(0,X.jsx)(z,{columns:ne,dataSource:R,rowKey:`id`,loading:F.loading,pagination:{pageSize:20},emptyText:g||b!==`all`||C!==`all`?f(`projects.noMatchingFacts`,null,`无匹配事实,请调整筛选条件`):f(`projects.noFacts`,null,`暂无事实,点击「添加事实」或由 Agent 自动写入`)})]})}var ve={target:0,infra:1,auth:1,finding:2,chain:3,exploit:3,poc:3,vulnerability:4};function ye(e,t,n,r,i){let a=e=>ve[e.type]??5,o=new Map(e.map(e=>[e.id,e])),s=new Set(t.flatMap(e=>[e.source,e.target])),c=[...e].sort((e,t)=>Number(s.has(t.id))-Number(s.has(e.id))||a(e)-a(t)||e.id.localeCompare(t.id)),l,u;if(n){let e=new Set(t.filter(e=>e.source===n).map(e=>e.target));l=[c.filter(t=>t.id!==n&&!e.has(t.id)),[o.get(n)],c.filter(t=>t.id!==n&&e.has(t.id))],u=new Set(t)}else{let n=e=>{let t=a(o.get(e.source)),n=a(o.get(e.target));return 4*Number(t>n)+2*Number(t!==0)+Number(e.confidence===`tentative`)},r=[...t].sort((e,t)=>n(e)-n(t)||e.source.localeCompare(t.source)||e.target.localeCompare(t.target)||(e.type||``).localeCompare(t.type||``)||(e.id||``).localeCompare(t.id||``)),i=ie(r,e=>o.get(e).type===`target`);u=i.parentEdges;let s=new Map(e.map(e=>[e.id,[]]));for(let e of c){let t=i.parents.get(e.id);t&&s.get(t).push(e)}l=[c.filter(e=>!i.parents.has(e.id))];for(let e of l){let t=e.flatMap(e=>s.get(e.id));t.length&&l.push(t)}}let d=new Map,f=Math.max(5,Math.min(23,Math.ceil(Math.sqrt(e.length)*1.18))),p=0;for(let e of l){if(!e.length)continue;let t=Math.ceil(e.length/Math.ceil(e.length/f));for(let n=0;nd.set(e.id,{x:p,y:(t-(a.length-1)/2)*(i+23)})),p+=r+62}p+=22}return{positions:d,parentEdges:u}}var be=.78,xe=340;function Se(e){let t=e.fact_key||e.id;return{key:t,title:(e.summary||e.label!==`—`&&e.label||t).replace(/\s+/g,` `).trim()||t}}function Ce(e,t,n){let r=e.width(),i=e.height(),a=e.nodes(),o=e.elements(),s=e.getFitViewport(o,Math.min(36,r/10,i/10));if(!s)return null;if(s.zoom>1)return{zoom:1,pan:e.getCenterPan(o,1),view:n===`overview`?n:`fitted`};if(n===`overview`||s.zoom>=be)return{...s,view:n===`overview`?n:`fitted`};let{x:c,y:l}=(t?e.$id(t):a.reduce((e,t)=>{let n=t.position(),r=e.position();return n.xMath.max(8,Math.min(e,s));return{width:i,left:a,...r<=e.height()/2?{top:c(r+o)}:{bottom:c(e.height()-r+o)}}}var Te=[{selector:`node`,style:{shape:`round-rectangle`,width:216,height:98,"background-color":`data(color)`,"background-opacity":.13,"border-color":`data(color)`,"border-opacity":.42,"border-width":1.2}},{selector:`node.current`,style:{"background-opacity":.85}},{selector:`edge`,style:{width:2.15,"line-color":`#8197b6`,"target-arrow-color":`#8197b6`,"target-arrow-shape":`triangle`,"arrow-scale":.85,"curve-style":`bezier`,opacity:.73}},{selector:`edge.forward`,style:{"source-endpoint":`50% 0px`,"target-endpoint":`-50% 0px`}},{selector:`edge.backward`,style:{"source-endpoint":`-50% 0px`,"target-endpoint":`50% 0px`}},{selector:`edge.curved`,style:{"curve-style":`unbundled-bezier`,"edge-distances":`endpoints`,"control-point-weights":`0.30 0.70`,"control-point-distances":`data(bend)`}},{selector:`edge.cross-link`,style:{opacity:.28}},{selector:`edge.focused`,style:{width:2.3,opacity:.96}},{selector:`edge[type = "links_vuln"]`,style:{"line-color":`#c96b81`,"target-arrow-color":`#c96b81`}},{selector:`edge[confidence = "tentative"]`,style:{"line-style":`dashed`,"line-dash-pattern":[5,4]}}];function Ee(e,t,n){let{positions:r,parentEdges:i}=ye(e,t,n,216,98),a=new Map(e.map(e=>[e.id,new Set])),o=e=>JSON.stringify([e.source,e.target].sort()),s=new Map;for(let e of t){let t=o(e);s.set(t,(s.get(t)||0)+1)}let c=t.map((e,t)=>{let c=r.get(e.source),l=r.get(e.target),u=l.x-c.x,d=l.y-c.y,f=[];if(n?f.push(`focused`):i.has(e)||f.push(`cross-link`),u!==0){let t=u>0;f.push(t?`forward`:`backward`),a.get(e.source).add(t?`right`:`left`),a.get(e.target).add(t?`left`:`right`),s.get(o(e))===1&&f.push(`curved`)}let p=Math.sign(d*u)*Math.min(Math.abs(d)*.3,60);return{group:`edges`,classes:f.join(` `),data:{...e,id:`edge|${t}|${e.id||``}`,bend:[-p,p]}}});return{ports:a,elements:[...e.map(e=>({group:`nodes`,data:{id:e.id,type:e.type||`note`,color:J[e.type]||J.missing},position:r.get(e.id),classes:e.id===n?`current`:``})),...c]}}function De({nodes:e,edges:t,selectedId:n,onSelect:r,chartRef:i,label:a,errorText:o,typeLabel:s,onFitChange:c}){let l=(0,q.useRef)(null),u=(0,q.useRef)(null),[d,f]=(0,q.useState)([]),[p,m]=(0,q.useState)(null),[h,g]=(0,q.useState)(!1),_=(0,q.useMemo)(()=>new Map(e.map(e=>[e.id,e])),[e]),v=(e,t)=>i.current?.inspect(e,t);(0,q.useEffect)(()=>{let a=l.current,o=u.current,s=!1,d,p,h,_,v=`reading`,y=!1;return f([]),m(null),g(!1),B(async()=>{let{default:e}=await import(`./cytoscape.esm-BPjn7guX.js`);return{default:e}},[]).then(({default:l})=>{if(s)return;let{ports:u,elements:g}=Ee(e,t,n);d=l({container:a,elements:g,style:Te,layout:{name:`preset`,fit:!1},minZoom:.006,maxZoom:3,wheelSensitivity:.2,boxSelectionEnabled:!1,autounselectify:!0,autoungrabify:!0});let b=()=>{cancelAnimationFrame(h),h=requestAnimationFrame(()=>{let t=W(d,{allowCompact:t=>n||e.length<=24||[`target`,`chain`].includes(t.data(`type`))});f(t.map(e=>({...e,ports:u.get(e.id)})))})},x=(e=`reading`)=>{let t=Ce(d,n,e);t&&(y=!0,v=e,m(null),d.viewport({zoom:t.zoom,pan:t.pan}),c(t.view),y=!1,b())},S=(e,t)=>{let n=d.$id(e);t&&n.nonempty()?m({id:e,box:we(d,n)}):t||m(t=>t?.id===e?null:t)};i.current={fit:()=>x(),overview:()=>x(`overview`),zoom:e=>K(d,e),inspect:S},_=ne(o,d),d.on(`viewport`,()=>{y||(v=null),m(null),b()}),d.on(`zoom`,()=>{y||c(`manual`)}),d.on(`mouseover`,`node`,e=>S(e.target.id(),!0)),d.on(`mouseout`,`node`,e=>S(e.target.id(),!1)),d.on(`tap`,`node`,e=>r(e.target.id()));let C=d.width(),w=d.height();p=new ResizeObserver(()=>{d.resize();let e=d.width(),t=d.height();(C!==e||w!==t)&&(v?x(v):d.panBy({x:(e-C)/2,y:(t-w)/2}),C=e,w=t)}),p.observe(a),x()}).catch(()=>{s||g(!0)}),()=>{s=!0,cancelAnimationFrame(h),p?.disconnect(),_?.(),d?.destroy(),i.current=null}},[e,t,n,r,i,c]);let y=p&&_.get(p.id),b=y&&Se(y);return(0,X.jsxs)(`div`,{className:`project-graph-canvas-wrap`,role:`group`,"aria-label":a,children:[(0,X.jsx)(`div`,{ref:l,className:`project-graph-canvas`}),(0,X.jsx)(`div`,{ref:u,className:`graph-node-layer`,children:d.map(e=>{let t=_.get(e.id);if(!t)return null;let{key:i,title:a}=Se(t);return(0,X.jsx)(G,{card:e,id:t.id,title:a,type:t.type,category:s(t.type||`note`),color:J[t.type]||J.missing,factKey:i,ports:e.ports,selected:t.id===n,onSelect:r,onPreview:v},t.id)})}),y&&(0,X.jsxs)(`div`,{className:`project-graph-node-preview`,role:`tooltip`,style:{...p.box,"--graph-node-color":J[y.type]||J.missing},children:[(0,X.jsxs)(`span`,{className:`project-graph-preview-type`,children:[(0,X.jsx)(re,{type:y.type}),s(y.type||`note`)]}),(0,X.jsx)(`strong`,{dir:`auto`,children:b.title}),(0,X.jsx)(`code`,{dir:`auto`,children:b.key})]}),h&&(0,X.jsx)(`div`,{className:`project-graph-overlay`,role:`alert`,children:o})]})}var{Text:Z}=s,Oe=[],ke=e=>e.summary||e.label||e.fact_key||e.id;function Ae({nodes:e,onSelect:t,t:n}){let[r,i]=(0,q.useState)(``),[a,o]=(0,q.useState)(!1),s=(0,q.useId)(),c=r.trim().toLowerCase(),l=(0,q.useMemo)(()=>[...e].sort((e,t)=>(e.fact_key||e.id).localeCompare(t.fact_key||t.id)),[e]),u=(0,q.useMemo)(()=>{if(!c)return l;let e=l.filter(e=>[e.fact_key,e.label,e.summary,e.category].join(` `).toLowerCase().includes(c)),t=e.findIndex(e=>(e.fact_key||e.id).toLowerCase()===c);return t>0&&e.unshift(...e.splice(t,1)),e},[l,c]),d=e=>{t(e),o(!1),i(``)};return(0,X.jsxs)(`div`,{className:`project-graph-search`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||o(!1)},children:[(0,X.jsx)(p,{prefix:(0,X.jsx)(x,{}),value:r,showClear:!0,placeholder:n(`projects.graphSearchPlaceholder`,null,`搜索节点…`),"aria-label":n(`projects.graphSearchSr`,null,`搜索节点`),"aria-controls":a?s:void 0,onChange:e=>{i(e),o(!0)},onFocus:()=>o(!0),onClick:()=>o(!0),onKeyDown:e=>{e.key===`Escape`&&a&&o(!1),e.key===`Enter`&&a&&u.length&&!e.nativeEvent.isComposing&&(e.preventDefault(),d(u[0].id))}}),a&&(0,X.jsxs)(`div`,{className:`project-graph-search-results`,id:s,children:[(0,X.jsx)(`div`,{className:`project-graph-search-count`,role:`status`,children:u.length?n(`projects.graphSearchCount`,{count:u.length},`${u.length} 个节点`):n(`projects.graphNoMatches`,null,`未找到匹配节点`)}),u.length>0&&(0,X.jsx)(`ul`,{className:`project-graph-search-list`,children:u.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{className:`project-graph-search-hit`,type:`button`,onClick:()=>d(e.id),children:[(0,X.jsx)(`span`,{title:ke(e),children:ke(e)}),(0,X.jsx)(`code`,{dir:`auto`,children:e.fact_key||e.id})]})},e.id))})]})]})}function je({projectId:e,canWrite:t,revision:n=0,onOpenFact:r,onEditFact:i,onAddFact:a,onChanged:s}){let f=A(),[p,h]=(0,q.useState)(`path`),[g,_]=(0,q.useState)(!0),[b,x]=(0,q.useState)(``),[S,C]=(0,q.useState)(!1),[T,D]=(0,q.useState)(`fitted`),O=(0,q.useRef)(null),ee=(0,q.useRef)(null),N=`${p}:${g}`,P=j(async()=>({scope:N,data:await k.get(`/projects/${e}/fact-graph`,{view:p,exclude_deprecated:g?`1`:`0`})}),[e,N,n]),F=P.data?.scope===N?P.data.data:null,L=F?.nodes||Oe,R=(0,q.useMemo)(()=>new Map(L.map(e=>[e.id,e])),[L]),z=(0,q.useMemo)(()=>(F?.edges||Oe).filter(e=>R.has(e.source)&&R.has(e.target)),[F,R]),B=R.get(b);(0,q.useEffect)(()=>{ee.current&&(ee.current.scrollTop=0)},[B?.id]);let U=(0,q.useMemo)(()=>B?z.filter(e=>e.source===B.id||e.target===B.id):z,[z,B]),W=(0,q.useMemo)(()=>{if(!B)return L;let e=new Set([B.id]);for(let t of U)e.add(t.source),e.add(t.target);return L.filter(t=>e.has(t.id))},[L,B,U]),ne=Object.keys(J).filter(e=>W.some(t=>t.type===e)),G=e=>f(`projects.graphNodeTypes.${e}`,null,de[e]||e),K=(0,q.useCallback)(e=>x(e),[]),ie=j(()=>S?k.get(`/projects/${e}/fact-edges`):Promise.resolve(null),[e,S,n]),ae=()=>{s?s():(P.reload(),S&&ie.reload())},oe=t=>{H({title:f(`projects.graphDeleteEdge`,null,`删边`),content:f(`projects.confirmDeleteGraphEdge`,null,`确定删除此关系边?`),okText:f(`common.delete`,null,`删除`),onOk:async()=>{try{await k.del(`/projects/${e}/fact-edges/${t.id}`),V(f(`projects.graphEdgeDeleteSuccess`,null,`边已删除`)),ae()}catch(e){M(Y(e,f(`projects.graphEdgeDeleteFailed`,null,`删除边失败`)))}}})},se=(e,t)=>f(`projects.graphStats`,{nodes:e,edges:t},`${e} 个节点 · ${t} 条关系`),ce=f(`projects.tabGraph`,null,`攻击路径`),ue={reading:f(`projects.graphReadingHint`,null,`已保留可读字号,拖动画布浏览其他节点。`),overview:f(`projects.graphFullOverviewHint`,null,`悬停预览节点摘要,点选查看详情。`)}[T],fe=B&&B.type!==`missing`&&!B.id.startsWith(`vuln:`);return(0,X.jsxs)(I,{title:ce,className:`project-graph-card`,extra:(0,X.jsxs)(c,{children:[(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:se(L.length,z.length)}),(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),"aria-label":f(`common.refresh`,null,`刷新`),theme:`borderless`,loading:P.loading,onClick:ae})]}),children:[(0,X.jsx)(te,{error:pe(P.error),onRetry:P.reload}),(0,X.jsxs)(`div`,{className:`project-toolbar project-graph-toolbar`,children:[(0,X.jsx)(E,{value:p,"aria-label":f(`projects.graphScope`,null,`关系范围`),onChange:e=>{x(``),h(e)},style:{width:134},optionList:[{value:`path`,label:f(`projects.graphViewPath`,null,`攻击路径`)},{value:`full`,label:f(`projects.graphViewFull`,null,`完整关系`)}]}),(0,X.jsx)(Ae,{nodes:L,onSelect:K,t:f}),(0,X.jsx)(u,{checked:g,onChange:e=>{x(``),_(e.target.checked)},children:f(`projects.hideDeprecated`,null,`隐藏废弃`)}),(0,X.jsx)(d,{className:`project-graph-edges-toggle`,"aria-expanded":S,onClick:()=>C(e=>!e),children:f(`projects.graphEdgesTitle`,null,`关系边`)})]}),L.length>0?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`project-graph-status`,children:[B?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(d,{size:`small`,theme:`light`,type:`primary`,onClick:()=>x(``),children:f(`projects.graphBackToOverview`,null,`返回全图`)}),(0,X.jsx)(Z,{size:`small`,"aria-live":`polite`,children:f(`projects.graphFocus`,{stats:se(W.length,U.length)},`聚焦直接关系 · ${se(W.length,U.length)}`)})]}):null,(!B||ue)&&(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:ue||f(`projects.graphOverviewHint`,null,`点选节点查看直接关系和摘要。`)})]}),(0,X.jsxs)(`div`,{className:`project-graph-layout${B&&W.length<=6?` is-compact`:``}`,children:[(0,X.jsxs)(`div`,{className:`project-graph-viewport`,children:[(0,X.jsx)(De,{nodes:W,edges:U,selectedId:B?.id,onSelect:K,chartRef:O,typeLabel:G,onFitChange:D,label:f(`projects.graphCanvas`,null,`攻击路径画布`),errorText:f(`projects.graphRenderError`,null,`图谱加载失败,请刷新重试。`)}),(0,X.jsxs)(`div`,{className:`project-graph-footer`,children:[(0,X.jsxs)(`div`,{className:`project-graph-legend`,children:[ne.map(e=>(0,X.jsxs)(`span`,{style:{"--graph-node-color":J[e]},children:[(0,X.jsx)(re,{type:e}),G(e)]},e)),U.some(e=>e.confidence===`tentative`)&&(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`i`,{className:`project-graph-legend-dash`,"aria-hidden":`true`}),f(`projects.graphTentativeEdge`,null,`待确认关系`)]})]}),(0,X.jsxs)(c,{spacing:4,wrap:!0,children:[(0,X.jsx)(d,{size:`small`,icon:(0,X.jsx)(y,{}),"aria-label":f(`projects.graphZoomOut`,null,`缩小`),onClick:()=>O.current?.zoom(1/1.3)}),(0,X.jsx)(d,{size:`small`,icon:(0,X.jsx)(v,{}),"aria-label":f(`projects.graphZoomIn`,null,`放大`),onClick:()=>O.current?.zoom(1.3)}),(0,X.jsx)(d,{size:`small`,"aria-pressed":T===`fitted`||T===`reading`,onClick:()=>O.current?.fit(),children:f(`projects.graphFit`,null,`适合画布`)}),(0,X.jsx)(d,{size:`small`,"aria-pressed":T===`overview`,onClick:()=>O.current?.overview(),children:f(`projects.graphFullOverview`,null,`全图总览`)})]})]})]}),B&&(0,X.jsx)(`aside`,{ref:ee,className:`project-graph-side`,"aria-label":f(`projects.graphNodeDetails`,null,`节点详情`),children:(0,X.jsxs)(`div`,{className:`project-detail-stack`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(Z,{strong:!0,children:ke(B)}),(0,X.jsx)(`code`,{className:`project-graph-node-key`,dir:`auto`,children:B.fact_key||B.id}),(0,X.jsxs)(`div`,{className:`project-graph-side-tags`,children:[(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:G(B.type)}),(0,X.jsx)(l,{size:`small`,color:le[B.confidence]?.color||`grey`,children:le[B.confidence]?f(`projects.graphConfidence.${B.confidence}`,null,le[B.confidence].label):B.confidence||`—`})]})]}),fe&&(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{size:`small`,onClick:()=>r(B.fact_key),children:f(`projects.details`,null,`详情`)}),(0,X.jsx)(d,{size:`small`,disabled:!t,onClick:()=>i(B.fact_key),children:f(`common.edit`,null,`编辑`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(Z,{strong:!0,size:`small`,children:[f(`projects.graphDirectLinks`,null,`直接关系`),` · `,U.length]}),U.length?(0,X.jsx)(`ul`,{className:`project-graph-neighbors`,children:U.map((e,t)=>{let n=e.source===B.id,r=R.get(n?e.target:e.source);return(0,X.jsxs)(`li`,{children:[(0,X.jsxs)(`div`,{className:`project-graph-edge-meta`,children:[(0,X.jsxs)(`span`,{children:[n?`→`:`←`,` `,n?f(`projects.graphEdgeOutgoing`,null,`出边`):f(`projects.graphEdgeIncoming`,null,`入边`)]}),(0,X.jsx)(`code`,{children:e.type}),e.confidence===`tentative`&&(0,X.jsx)(`span`,{children:f(`projects.graphConfidence.tentative`,null,`待确认`)})]}),(0,X.jsx)(`button`,{type:`button`,className:`project-graph-peer project-link-button`,onClick:()=>K(r.id),title:r.fact_key,children:ke(r)})]},e.id||t)})}):(0,X.jsx)(`div`,{children:(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:f(`projects.graphEdgesEmpty`,null,`暂无关系边`)})})]})]})})]})]}):P.loading?(0,X.jsx)(`div`,{className:`project-graph-loading`,children:(0,X.jsx)(m,{})}):F&&!P.error?(0,X.jsxs)(o,{title:f(`projects.graphEmptyTitle`,null,`构建攻击路径图`),description:f(`projects.graphEmpty`,null,`暂无路径图数据。为 finding/exploit 类事实添加关系边(discovered_on → target/*)后将在此展示。`),style:{padding:40},children:[(0,X.jsxs)(`div`,{className:`project-graph-empty-steps`,children:[(0,X.jsx)(Z,{type:`tertiary`,children:f(`projects.graphEmptyStep1`,null,`添加 target 类事实(目标、域名、入口)`)}),(0,X.jsx)(Z,{type:`tertiary`,children:f(`projects.graphEmptyStep2`,null,`记录 finding / exploit 并在 links 中连边`)}),(0,X.jsx)(Z,{type:`tertiary`,children:f(`projects.graphEmptyStep3`,null,`使用「连边」模式或编辑事实手动补关系`)})]}),(0,X.jsx)(d,{type:`primary`,disabled:!t,onClick:a,children:f(`projects.graphEmptyCta`,null,`添加第一条事实`)})]}):null,S?(0,X.jsxs)(`div`,{className:`project-edge-table`,children:[(0,X.jsx)(te,{error:pe(ie.error),onRetry:()=>ie.reload()}),(ie.data||[]).length?(0,X.jsx)(`ul`,{className:`project-edge-rows`,children:ie.data.map(e=>(0,X.jsxs)(`li`,{className:`project-edge-row`,children:[(0,X.jsx)(`code`,{children:e.source_fact_key}),(0,X.jsx)(`span`,{className:`project-edge-type`,children:e.edge_type}),(0,X.jsx)(`span`,{className:`project-edge-arrow`,children:`→`}),(0,X.jsx)(`code`,{children:e.target_fact_key}),(0,X.jsx)(l,{size:`small`,color:e.confidence===`tentative`?`amber`:`green`,children:(le[e.confidence]||{}).label||e.confidence||`—`}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>oe(e),children:f(`projects.graphDeleteEdge`,null,`删边`)})]},e.id))}):(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:f(`projects.graphEdgesEmpty`,null,`暂无关系边`)})]}):null]})}var{Text:Me}=s;function Ne({projectId:e,canWrite:t,onChanged:r}){let i=A(),a=n(),{hasPermission:o}=O(),s=o(`chat:write`),u=j(()=>k.get(`/projects/${e}/conversations`,{limit:100}),[e]),f=u.data?.conversations||[],p=t=>{H({title:i(`projects.promoteAttackChain`,null,`沉淀攻击链`),content:i(`projects.confirmPromoteAttackChain`,null,`将该对话的攻击链沉淀到本项目?会创建/更新事实与关系边。`),okText:i(`projects.promoteAttackChain`,null,`沉淀攻击链`),danger:!1,onOk:async()=>{try{let n=await k.post(`/projects/${e}/promote-attack-chain/${t.id}`);V(i(`projects.promoteAttackChainSuccess`,{facts_created:n?.facts_created||0,facts_updated:n?.facts_updated||0,edges_created:n?.edges_created||0},`已沉淀:新建 ${n?.facts_created||0} / 更新 ${n?.facts_updated||0} / 边 ${n?.edges_created||0}`)),u.reload({silent:!0}),r?.()}catch(e){M(Y(e,i(`projects.promoteAttackChainFailed`,null,`沉淀失败`)))}}})},m=e=>{H({title:i(`projects.unbind`,null,`解绑`),content:i(`projects.confirmUnbindConversation`,null,`解除该对话与当前项目的绑定?`),okText:i(`projects.unbind`,null,`解绑`),onOk:async()=>{try{await k.put(`/conversations/${e.id}/project`,{projectId:``}),V(i(`projects.projectUnbound`,null,`已解除项目绑定`)),u.reload({silent:!0}),r?.()}catch(e){M(Y(e,i(`projects.unbindFailed`,null,`解绑失败`)))}}})},h=[{title:i(`projects.titleLabel`,null,`标题`),dataIndex:`title`,render:(e,t)=>(0,X.jsx)(`button`,{type:`button`,className:`project-link-button`,onClick:()=>a(`/chat?conversation=${encodeURIComponent(t.id)}`),title:e||t.id,children:e||i(`projects.untitledConversation`,null,`未命名对话`)})},{title:`ID`,dataIndex:`id`,width:240,render:e=>(0,X.jsx)(Me,{type:`tertiary`,size:`small`,children:(0,X.jsx)(`code`,{children:e})})},{title:i(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:170,render:(e,t)=>(0,X.jsx)(Me,{size:`small`,children:D(e||t.updatedAt||t.created_at||t.createdAt)})},{title:i(`common.actions`,null,`操作`),dataIndex:`id`,width:280,render:(e,n)=>(0,X.jsxs)(c,{spacing:2,wrap:!0,children:[(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>a(`/chat?conversation=${encodeURIComponent(n.id)}`),children:i(`projects.open`,null,`打开`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,title:i(`projects.promoteAttackChainTitle`,null,`将对话攻击链沉淀为项目事实与边`),onClick:()=>p(n),children:i(`projects.promoteAttackChain`,null,`沉淀攻击链`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!s,title:i(`projects.unbindProjectTitle`,null,`解除项目绑定`),onClick:()=>m(n),children:i(`projects.unbind`,null,`解绑`)})]})}];return(0,X.jsxs)(I,{title:i(`projects.tabConversations`,null,`关联对话`),description:i(`projects.boundConversationsHint`,null,`绑定到本项目的对话;点击可打开会话`),extra:(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:f.length}),children:[(0,X.jsx)(te,{error:pe(u.error),onRetry:u.reload}),(0,X.jsx)(z,{columns:h,dataSource:f,rowKey:`id`,loading:u.loading,pagination:{pageSize:10},emptyText:i(`projects.noBoundConversations`,null,`暂无绑定对话;在对话页选择本项目即可关联`),onRefresh:()=>u.reload()})]})}var{Text:Q}=s,Pe={targets:[`https://example.com`],exclude:[`*.cdn.example.com`],notes:`仅授权 Web 应用层测试`};function Fe(e){try{let t=e.trim()?JSON.parse(e):{};return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}function Ie({project:e,canWrite:t,canDelete:n,onChanged:r,onDeleted:i}){let o=A(),s=(0,q.useId)(),[l,u]=(0,q.useState)({name:``,description:``,scope_json:``,lessons_mode:`off`,status:`active`,pinned:!1}),[m,h]=(0,q.useState)(!1);(0,q.useEffect)(()=>{e&&u({name:e.name||``,description:e.description||``,scope_json:e.scope_json||``,lessons_mode:e.lessons_mode||`off`,status:e.status||`active`,pinned:!!e.pinned})},[e]);let g=e=>u(t=>({...t,...e})),v=Fe(l.scope_json),y=v?.constraints??[],x=Array.isArray(y)&&y.every(e=>e&&typeof e==`object`&&!Array.isArray(e)),C=e=>u(t=>{let n=Fe(t.scope_json);return n?{...t,scope_json:JSON.stringify({...n,...e},null,2)}:t}),w=(e,t)=>C({constraints:y.map((n,r)=>r===e?{...n,...t}:n)}),T=[{value:`off`,label:o(`projects.noiseOff`,null,`关闭`)},{value:`quiet`,label:o(`projects.noiseQuiet`,null,`低噪音`)},{value:`balanced`,label:o(`projects.noiseBalanced`,null,`均衡`)},{value:`aggressive`,label:o(`projects.noiseAggressive`,null,`维护窗口`)}],D=[{value:`allow`,label:o(`projects.constraintAllow`,null,`允许`)},{value:`deny`,label:o(`projects.constraintDeny`,null,`禁止`)}],O=()=>{let e=l.scope_json.trim();if(e)try{g({scope_json:JSON.stringify(JSON.parse(e),null,2)})}catch(e){M(o(`projects.invalidJson`,null,`JSON 格式无效`)+`:`+Y(e,``))}},ee=()=>g({scope_json:JSON.stringify(Pe,null,2)}),j=async()=>{let t=l.name.trim();if(!t){M(o(`projects.enterProjectName`,null,`请输入项目名称`));return}let n=l.scope_json.trim();if(n)try{JSON.parse(n)}catch{M(o(`projects.invalidScopeJson`,null,`测试范围 JSON 无效,请先修正或点击「格式化」`));return}h(!0);try{await k.put(`/projects/${e.id}`,{name:t,description:l.description,scope_json:n,...l.lessons_mode===(e.lessons_mode||`off`)?{}:{lessons_mode:l.lessons_mode},...l.status===(e.status||`active`)?{}:{status:l.status},pinned:!!l.pinned}),V(o(`projects.saved`,null,`已保存`)),r?.()}catch(e){M(Y(e,o(`projects.saveFailed`,null,`保存失败`)))}finally{h(!1)}},N=(e?.status||`active`)===`archived`;return e?(0,X.jsxs)(I,{title:o(`projects.settingsIntroTitle`,null,`项目设置`),description:o(`projects.settingsIntroHint`,null,`配置项目元数据与 Agent 授权边界,保存后即时生效于绑定对话。`),extra:(0,X.jsx)(d,{type:`primary`,loading:m,disabled:!t,onClick:j,children:o(`projects.saveSettings`,null,`保存更改`)}),children:[(0,X.jsxs)(`div`,{className:`project-form-grid`,children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.projectName`,null,`项目名称`)}),(0,X.jsx)(p,{value:l.name,disabled:!t,onChange:e=>g({name:e})}),(0,X.jsx)(Q,{type:`tertiary`,size:`small`,children:o(`projects.saveChangesHint`,null,`修改后请点击保存以同步到服务器`)})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.status`,null,`状态`)}),(0,X.jsx)(E,{value:l.status,disabled:!t,optionList:ue,onChange:e=>g({status:e}),style:{width:`100%`}}),(0,X.jsxs)(`div`,{className:`project-switch-row`,children:[(0,X.jsx)(_,{checked:l.pinned,disabled:!t,onChange:e=>g({pinned:e})}),(0,X.jsx)(Q,{size:`small`,children:o(`projects.pinProject`,null,`置顶项目(列表优先显示)`)})]})]})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.projectDescription`,null,`项目描述`)}),(0,X.jsx)(f,{value:l.description,rows:3,maxCount:4e3,disabled:!t,placeholder:o(`projects.editDescriptionPlaceholder`,null,`客户/任务备注、协作说明、联系人…`),onChange:e=>g({description:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsxs)(c,{children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.scopeJsonLabel`,null,`范围 JSON`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:O,children:o(`projects.formatJson`,null,`格式化`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:ee,children:o(`projects.example`,null,`示例`)})]}),(0,X.jsx)(f,{value:l.scope_json,rows:8,disabled:!t,placeholder:`{
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{D as a,E as o,G as s,I as c,N as l,P as u,R as d,S as f,U as p,W as m,_ as h,c as g,d as _,ft as v,gt as y,h as b,lt as x,m as S,p as C,ut as w,v as T,y as E}from"./semi-65W_4I1v.js";import{E as D,F as O,I as k,L as A,_ as ee,a as j,b as M,c as N,d as P,f as F,l as te,m as I,n as L,p as R,s as z,t as B,x as V,y as H}from"./index-_8d9XBPJ.js";import{t as U}from"./project-form-Dt6NB8i_.js";import{a as W,i as ne,n as G,o as K,r as re,t as ie}from"./graph-parents-i1hc3RVG.js";import{t as ae}from"./AssetEditorModal-DrEuccaT.js";var q=e(t(),1),oe=[{value:`target`,label:`target(目标)`},{value:`auth`,label:`auth(认证)`},{value:`infra`,label:`infra(基础设施)`},{value:`business`,label:`business(业务)`},{value:`finding`,label:`finding(发现)`},{value:`chain`,label:`chain(攻击链)`},{value:`exploit`,label:`exploit(利用)`},{value:`poc`,label:`poc(POC)`},{value:`note`,label:`note(备注)`}],se={target:`目标`,auth:`认证`,infra:`基础设施`,business:`业务`,finding:`发现`,chain:`攻击链`,exploit:`利用`,poc:`POC`,note:`备注`,vuln:`漏洞`,missing:`缺失`},ce=[{value:`tentative`,label:`待确认`},{value:`confirmed`,label:`已确认`},{value:`deprecated`,label:`已废弃`}],le={confirmed:{label:`已确认`,color:`green`},tentative:{label:`待确认`,color:`amber`},deprecated:{label:`已废弃`,color:`grey`}},ue=[{value:`active`,label:`进行中`},{value:`archived`,label:`已归档`}],J={target:`#2563eb`,auth:`#0891b2`,infra:`#0d9488`,finding:`#d97706`,chain:`#db2777`,exploit:`#7c3aed`,poc:`#7c3aed`,vulnerability:`#dc2626`,note:`#64748b`,missing:`#94a3b8`},de={target:`TARGET · 目标`,auth:`AUTH · 认证`,infra:`INFRA · 基础设施`,finding:`FINDING · 发现`,chain:`CHAIN · 攻击链`,exploit:`EXPLOIT · 利用`,poc:`POC · 验证`,vulnerability:`VULN · 漏洞`,note:`NOTE · 备注`,missing:`MISSING · 缺失`},fe=[`discovered_on`,`depends_on`,`leads_to`,`enables`,`exploits`];function Y(e,t=`操作失败`){if(!e)return t;if(typeof e==`string`)return e;let n=e.payload;if(n&&typeof n==`object`){let e=n.error;if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=typeof e.message==`string`?e.message:``,n=typeof e.code==`string`?e.code:``;if(t)return n?`${t}(${n})`:t}if(typeof n.message==`string`&&n.message)return n.message}return typeof e.message==`string`&&e.message&&e.message!==`[object Object]`?e.message:t}function pe(e,t=`加载失败`){return e?{message:Y(e,t)}:null}function me(e){return!Array.isArray(e)||!e.length?``:e.map(e=>`${e.edge_type||e.type||``}: ${e.source_fact_key||e.from||``}`.trim()).join(`
+`)}var X=e(r(),1),{Text:he}=s;function ge({value:e}){let t=le[String(e||``).toLowerCase()]||{label:e||`—`,color:`grey`};return(0,X.jsx)(l,{size:`small`,color:t.color,children:t.label})}function _e({projectId:e,canWrite:t,revision:r=0,onAddFact:i,onEditFact:a,onViewFact:o,onMutated:s}){let f=O(),m=n(),[g,_]=(0,q.useState)(``),y=L(g,300),[b,S]=(0,q.useState)(`all`),[C,T]=(0,q.useState)(`all`),[k,ee]=(0,q.useState)(!0),[N,P]=(0,q.useState)(!1),F=j(()=>A.get(`/projects/${e}/facts`,{limit:200,include_link_counts:`true`,exclude_deprecated:k?`true`:void 0,search:y.trim()||void 0,category:b===`all`?void 0:b,confidence:C===`all`?void 0:C,sparse_only:N?`true`:void 0}),[e,y,b,C,k,N,r]),R=(0,q.useMemo)(()=>Array.isArray(F.data)?F.data:[],[F.data]),B=async t=>{try{await A.post(`/projects/${e}/facts/deprecate`,{fact_key:t.fact_key}),V(f(`projects.saved`,null,`已保存`)),s?s():F.reload({silent:!0})}catch(e){M(Y(e,f(`projects.operationFailed`,null,`操作失败`)))}},U=async t=>{try{await A.post(`/projects/${e}/facts/restore`,{fact_key:t.fact_key,confidence:`tentative`}),V(f(`projects.saved`,null,`已保存`)),s?s():F.reload({silent:!0})}catch(e){M(Y(e,f(`projects.operationFailed`,null,`操作失败`)))}},W=t=>{H({title:f(`projects.deleteForeverTitle`,null,`永久删除`),content:f(`projects.confirmDeleteFact`,null,`删除该事实?`),okText:f(`common.delete`,null,`删除`),onOk:async()=>{try{await A.del(`/projects/${e}/facts/${t.id}`),V(f(`common.delete`,null,`删除`)),s?s():F.reload({silent:!0})}catch(e){M(Y(e,f(`projects.operationFailed`,null,`操作失败`)))}}})},ne=[{title:`fact_key`,dataIndex:`fact_key`,width:230,render:(e,t)=>(0,X.jsxs)(`div`,{className:`project-fact-key`,children:[(0,X.jsx)(`code`,{className:`project-fact-key-chip`,title:e,children:e}),(0,X.jsxs)(`div`,{className:`project-fact-key-meta`,children:[t.pinned&&(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:f(`projects.pinned`,null,`置顶`)}),t.related_vulnerability_id&&(0,X.jsx)(l,{size:`small`,color:`violet`,type:`light`,title:t.related_vulnerability_id,children:f(`projects.relatedVulnIdTitle`,null,`关联漏洞 ID`)})]})]})},{title:f(`projects.category`,null,`分类`),dataIndex:`category`,width:108,render:e=>(0,X.jsx)(l,{size:`small`,color:`cyan`,type:`light`,children:se[String(e||``).toLowerCase()]||e||`—`})},{title:f(`projects.summary`,null,`摘要`),dataIndex:`summary`,render:(e,t)=>(0,X.jsx)(`button`,{type:`button`,className:`project-cell-ellipsis project-link-button`,title:e,onClick:()=>o?.(t.fact_key),children:e||`—`})},{title:f(`projects.linksColumn`,null,`关系`),dataIndex:`link_counts`,width:92,render:e=>{let t=e?.outgoing||0,n=e?.incoming||0;return!t&&!n?(0,X.jsx)(he,{type:`tertiary`,children:`—`}):(0,X.jsxs)(`span`,{className:`project-link-counts`,title:f(`projects.linkCountsTitle`,null,`出边数 / 入边数`),children:[`↑`,t,` ↓`,n]})}},{title:f(`projects.confidence`,null,`置信度`),dataIndex:`confidence`,width:92,render:e=>(0,X.jsx)(ge,{value:e})},{title:f(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:158,render:e=>(0,X.jsx)(he,{size:`small`,children:D(e)})},{title:f(`common.actions`,null,`操作`),dataIndex:`id`,width:224,render:(e,n)=>{let r=String(n.confidence||``).toLowerCase()===`deprecated`;return(0,X.jsxs)(c,{spacing:2,wrap:!0,children:[(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>o?.(n.fact_key),children:f(`projects.details`,null,`详情`)}),n.source_conversation_id?(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>m(`/chat?conversation=${encodeURIComponent(n.source_conversation_id)}`),children:`会话`}):null,(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>a?.(n.fact_key),children:f(`common.edit`,null,`编辑`)}),r?(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>U(n),children:f(`projects.restore`,null,`恢复`)}):(0,X.jsx)(h,{title:f(`projects.confirmDeprecateFact`,{factKey:n.fact_key},`将事实 ${n.fact_key} 标记为已废弃?`),onConfirm:()=>B(n),disabled:!t,children:(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,title:f(`projects.deprecateTitle`,null,`标记为已废弃`),children:f(`projects.deprecate`,null,`废弃`)})}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>W(n),children:f(`common.delete`,null,`删除`)})]})}}];return(0,X.jsxs)(I,{title:f(`projects.tabFacts`,null,`事实黑板`),description:f(`projects.factToolbarHint`,null,`索引仅含 key 与摘要;攻击链 / POC 写在 body,Agent 通过 get_project_fact 复现`),extra:(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),theme:`borderless`,loading:F.loading,onClick:()=>{s?s():F.reload()}}),(0,X.jsx)(d,{type:`primary`,icon:(0,X.jsx)(v,{}),disabled:!t,onClick:i,children:f(`projects.addFact`,null,`添加事实`)})]}),children:[(0,X.jsx)(te,{error:pe(F.error),onRetry:F.reload}),(0,X.jsxs)(`div`,{className:`project-toolbar`,children:[(0,X.jsx)(p,{prefix:(0,X.jsx)(x,{}),value:g,showClear:!0,"aria-label":f(`projects.searchFactsSr`,null,`搜索事实`),placeholder:f(`projects.searchFactsPlaceholder`,null,`搜索 key、摘要、body…`),onChange:e=>_(e),style:{width:260}}),(0,X.jsx)(E,{value:b,onChange:S,style:{width:146},optionList:[{value:`all`,label:f(`projects.all`,null,`全部`)},...oe]}),(0,X.jsx)(E,{value:C,onChange:T,style:{width:128},optionList:[{value:`all`,label:f(`projects.all`,null,`全部`)},...ce]}),(0,X.jsx)(u,{checked:k,onChange:e=>ee(e.target.checked),children:f(`projects.hideDeprecated`,null,`隐藏废弃`)}),(0,X.jsx)(u,{checked:N,onChange:e=>P(e.target.checked),children:f(`projects.sparseOnly`,null,`仅待补全`)})]}),(0,X.jsx)(z,{columns:ne,dataSource:R,rowKey:`id`,loading:F.loading,pagination:{pageSize:20},emptyText:g||b!==`all`||C!==`all`?f(`projects.noMatchingFacts`,null,`无匹配事实,请调整筛选条件`):f(`projects.noFacts`,null,`暂无事实,点击「添加事实」或由 Agent 自动写入`)})]})}var ve={target:0,infra:1,auth:1,finding:2,chain:3,exploit:3,poc:3,vulnerability:4};function ye(e,t,n,r,i){let a=e=>ve[e.type]??5,o=new Map(e.map(e=>[e.id,e])),s=new Set(t.flatMap(e=>[e.source,e.target])),c=[...e].sort((e,t)=>Number(s.has(t.id))-Number(s.has(e.id))||a(e)-a(t)||e.id.localeCompare(t.id)),l,u;if(n){let e=new Set(t.filter(e=>e.source===n).map(e=>e.target));l=[c.filter(t=>t.id!==n&&!e.has(t.id)),[o.get(n)],c.filter(t=>t.id!==n&&e.has(t.id))],u=new Set(t)}else{let n=e=>{let t=a(o.get(e.source)),n=a(o.get(e.target));return 4*Number(t>n)+2*Number(t!==0)+Number(e.confidence===`tentative`)},r=[...t].sort((e,t)=>n(e)-n(t)||e.source.localeCompare(t.source)||e.target.localeCompare(t.target)||(e.type||``).localeCompare(t.type||``)||(e.id||``).localeCompare(t.id||``)),i=ie(r,e=>o.get(e).type===`target`);u=i.parentEdges;let s=new Map(e.map(e=>[e.id,[]]));for(let e of c){let t=i.parents.get(e.id);t&&s.get(t).push(e)}l=[c.filter(e=>!i.parents.has(e.id))];for(let e of l){let t=e.flatMap(e=>s.get(e.id));t.length&&l.push(t)}}let d=new Map,f=Math.max(5,Math.min(23,Math.ceil(Math.sqrt(e.length)*1.18))),p=0;for(let e of l){if(!e.length)continue;let t=Math.ceil(e.length/Math.ceil(e.length/f));for(let n=0;nd.set(e.id,{x:p,y:(t-(a.length-1)/2)*(i+23)})),p+=r+62}p+=22}return{positions:d,parentEdges:u}}var be=.78,xe=340;function Se(e){let t=e.fact_key||e.id;return{key:t,title:(e.summary||e.label!==`—`&&e.label||t).replace(/\s+/g,` `).trim()||t}}function Ce(e,t,n){let r=e.width(),i=e.height(),a=e.nodes(),o=e.elements(),s=e.getFitViewport(o,Math.min(36,r/10,i/10));if(!s)return null;if(s.zoom>1)return{zoom:1,pan:e.getCenterPan(o,1),view:n===`overview`?n:`fitted`};if(n===`overview`||s.zoom>=be)return{...s,view:n===`overview`?n:`fitted`};let{x:c,y:l}=(t?e.$id(t):a.reduce((e,t)=>{let n=t.position(),r=e.position();return n.xMath.max(8,Math.min(e,s));return{width:i,left:a,...r<=e.height()/2?{top:c(r+o)}:{bottom:c(e.height()-r+o)}}}var Te=[{selector:`node`,style:{shape:`round-rectangle`,width:216,height:98,"background-color":`data(color)`,"background-opacity":.13,"border-color":`data(color)`,"border-opacity":.42,"border-width":1.2}},{selector:`node.current`,style:{"background-opacity":.85}},{selector:`edge`,style:{width:2.15,"line-color":`#8197b6`,"target-arrow-color":`#8197b6`,"target-arrow-shape":`triangle`,"arrow-scale":.85,"curve-style":`bezier`,opacity:.73}},{selector:`edge.forward`,style:{"source-endpoint":`50% 0px`,"target-endpoint":`-50% 0px`}},{selector:`edge.backward`,style:{"source-endpoint":`-50% 0px`,"target-endpoint":`50% 0px`}},{selector:`edge.curved`,style:{"curve-style":`unbundled-bezier`,"edge-distances":`endpoints`,"control-point-weights":`0.30 0.70`,"control-point-distances":`data(bend)`}},{selector:`edge.cross-link`,style:{opacity:.28}},{selector:`edge.focused`,style:{width:2.3,opacity:.96}},{selector:`edge[type = "links_vuln"]`,style:{"line-color":`#c96b81`,"target-arrow-color":`#c96b81`}},{selector:`edge[confidence = "tentative"]`,style:{"line-style":`dashed`,"line-dash-pattern":[5,4]}}];function Ee(e,t,n){let{positions:r,parentEdges:i}=ye(e,t,n,216,98),a=new Map(e.map(e=>[e.id,new Set])),o=e=>JSON.stringify([e.source,e.target].sort()),s=new Map;for(let e of t){let t=o(e);s.set(t,(s.get(t)||0)+1)}let c=t.map((e,t)=>{let c=r.get(e.source),l=r.get(e.target),u=l.x-c.x,d=l.y-c.y,f=[];if(n?f.push(`focused`):i.has(e)||f.push(`cross-link`),u!==0){let t=u>0;f.push(t?`forward`:`backward`),a.get(e.source).add(t?`right`:`left`),a.get(e.target).add(t?`left`:`right`),s.get(o(e))===1&&f.push(`curved`)}let p=Math.sign(d*u)*Math.min(Math.abs(d)*.3,60);return{group:`edges`,classes:f.join(` `),data:{...e,id:`edge|${t}|${e.id||``}`,bend:[-p,p]}}});return{ports:a,elements:[...e.map(e=>({group:`nodes`,data:{id:e.id,type:e.type||`note`,color:J[e.type]||J.missing},position:r.get(e.id),classes:e.id===n?`current`:``})),...c]}}function De({nodes:e,edges:t,selectedId:n,onSelect:r,chartRef:i,label:a,errorText:o,typeLabel:s,onFitChange:c}){let l=(0,q.useRef)(null),u=(0,q.useRef)(null),[d,f]=(0,q.useState)([]),[p,m]=(0,q.useState)(null),[h,g]=(0,q.useState)(!1),_=(0,q.useMemo)(()=>new Map(e.map(e=>[e.id,e])),[e]),v=(e,t)=>i.current?.inspect(e,t);(0,q.useEffect)(()=>{let a=l.current,o=u.current,s=!1,d,p,h,_,v=`reading`,y=!1;return f([]),m(null),g(!1),B(async()=>{let{default:e}=await import(`./cytoscape.esm-BPjn7guX.js`);return{default:e}},[]).then(({default:l})=>{if(s)return;let{ports:u,elements:g}=Ee(e,t,n);d=l({container:a,elements:g,style:Te,layout:{name:`preset`,fit:!1},minZoom:.006,maxZoom:3,wheelSensitivity:.2,boxSelectionEnabled:!1,autounselectify:!0,autoungrabify:!0});let b=()=>{cancelAnimationFrame(h),h=requestAnimationFrame(()=>{let t=W(d,{allowCompact:t=>n||e.length<=24||[`target`,`chain`].includes(t.data(`type`))});f(t.map(e=>({...e,ports:u.get(e.id)})))})},x=(e=`reading`)=>{let t=Ce(d,n,e);t&&(y=!0,v=e,m(null),d.viewport({zoom:t.zoom,pan:t.pan}),c(t.view),y=!1,b())},S=(e,t)=>{let n=d.$id(e);t&&n.nonempty()?m({id:e,box:we(d,n)}):t||m(t=>t?.id===e?null:t)};i.current={fit:()=>x(),overview:()=>x(`overview`),zoom:e=>K(d,e),inspect:S},_=ne(o,d),d.on(`viewport`,()=>{y||(v=null),m(null),b()}),d.on(`zoom`,()=>{y||c(`manual`)}),d.on(`mouseover`,`node`,e=>S(e.target.id(),!0)),d.on(`mouseout`,`node`,e=>S(e.target.id(),!1)),d.on(`tap`,`node`,e=>r(e.target.id()));let C=d.width(),w=d.height();p=new ResizeObserver(()=>{d.resize();let e=d.width(),t=d.height();(C!==e||w!==t)&&(v?x(v):d.panBy({x:(e-C)/2,y:(t-w)/2}),C=e,w=t)}),p.observe(a),x()}).catch(()=>{s||g(!0)}),()=>{s=!0,cancelAnimationFrame(h),p?.disconnect(),_?.(),d?.destroy(),i.current=null}},[e,t,n,r,i,c]);let y=p&&_.get(p.id),b=y&&Se(y);return(0,X.jsxs)(`div`,{className:`project-graph-canvas-wrap`,role:`group`,"aria-label":a,children:[(0,X.jsx)(`div`,{ref:l,className:`project-graph-canvas`}),(0,X.jsx)(`div`,{ref:u,className:`graph-node-layer`,children:d.map(e=>{let t=_.get(e.id);if(!t)return null;let{key:i,title:a}=Se(t);return(0,X.jsx)(G,{card:e,id:t.id,title:a,type:t.type,category:s(t.type||`note`),color:J[t.type]||J.missing,factKey:i,ports:e.ports,selected:t.id===n,onSelect:r,onPreview:v},t.id)})}),y&&(0,X.jsxs)(`div`,{className:`project-graph-node-preview`,role:`tooltip`,style:{...p.box,"--graph-node-color":J[y.type]||J.missing},children:[(0,X.jsxs)(`span`,{className:`project-graph-preview-type`,children:[(0,X.jsx)(re,{type:y.type}),s(y.type||`note`)]}),(0,X.jsx)(`strong`,{dir:`auto`,children:b.title}),(0,X.jsx)(`code`,{dir:`auto`,children:b.key})]}),h&&(0,X.jsx)(`div`,{className:`project-graph-overlay`,role:`alert`,children:o})]})}var{Text:Z}=s,Oe=[],ke=e=>e.summary||e.label||e.fact_key||e.id;function Ae({nodes:e,onSelect:t,t:n}){let[r,i]=(0,q.useState)(``),[a,o]=(0,q.useState)(!1),s=(0,q.useId)(),c=r.trim().toLowerCase(),l=(0,q.useMemo)(()=>[...e].sort((e,t)=>(e.fact_key||e.id).localeCompare(t.fact_key||t.id)),[e]),u=(0,q.useMemo)(()=>{if(!c)return l;let e=l.filter(e=>[e.fact_key,e.label,e.summary,e.category].join(` `).toLowerCase().includes(c)),t=e.findIndex(e=>(e.fact_key||e.id).toLowerCase()===c);return t>0&&e.unshift(...e.splice(t,1)),e},[l,c]),d=e=>{t(e),o(!1),i(``)};return(0,X.jsxs)(`div`,{className:`project-graph-search`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||o(!1)},children:[(0,X.jsx)(p,{prefix:(0,X.jsx)(x,{}),value:r,showClear:!0,placeholder:n(`projects.graphSearchPlaceholder`,null,`搜索节点…`),"aria-label":n(`projects.graphSearchSr`,null,`搜索节点`),"aria-controls":a?s:void 0,onChange:e=>{i(e),o(!0)},onFocus:()=>o(!0),onClick:()=>o(!0),onKeyDown:e=>{e.key===`Escape`&&a&&o(!1),e.key===`Enter`&&a&&u.length&&!e.nativeEvent.isComposing&&(e.preventDefault(),d(u[0].id))}}),a&&(0,X.jsxs)(`div`,{className:`project-graph-search-results`,id:s,children:[(0,X.jsx)(`div`,{className:`project-graph-search-count`,role:`status`,children:u.length?n(`projects.graphSearchCount`,{count:u.length},`${u.length} 个节点`):n(`projects.graphNoMatches`,null,`未找到匹配节点`)}),u.length>0&&(0,X.jsx)(`ul`,{className:`project-graph-search-list`,children:u.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{className:`project-graph-search-hit`,type:`button`,onClick:()=>d(e.id),children:[(0,X.jsx)(`span`,{title:ke(e),children:ke(e)}),(0,X.jsx)(`code`,{dir:`auto`,children:e.fact_key||e.id})]})},e.id))})]})]})}function je({projectId:e,canWrite:t,revision:n=0,onOpenFact:r,onEditFact:i,onAddFact:a,onChanged:s}){let f=O(),[p,h]=(0,q.useState)(`path`),[g,_]=(0,q.useState)(!0),[b,x]=(0,q.useState)(``),[S,C]=(0,q.useState)(!1),[T,D]=(0,q.useState)(`fitted`),k=(0,q.useRef)(null),ee=(0,q.useRef)(null),N=`${p}:${g}`,P=j(async()=>({scope:N,data:await A.get(`/projects/${e}/fact-graph`,{view:p,exclude_deprecated:g?`1`:`0`})}),[e,N,n]),F=P.data?.scope===N?P.data.data:null,L=F?.nodes||Oe,R=(0,q.useMemo)(()=>new Map(L.map(e=>[e.id,e])),[L]),z=(0,q.useMemo)(()=>(F?.edges||Oe).filter(e=>R.has(e.source)&&R.has(e.target)),[F,R]),B=R.get(b);(0,q.useEffect)(()=>{ee.current&&(ee.current.scrollTop=0)},[B?.id]);let U=(0,q.useMemo)(()=>B?z.filter(e=>e.source===B.id||e.target===B.id):z,[z,B]),W=(0,q.useMemo)(()=>{if(!B)return L;let e=new Set([B.id]);for(let t of U)e.add(t.source),e.add(t.target);return L.filter(t=>e.has(t.id))},[L,B,U]),ne=Object.keys(J).filter(e=>W.some(t=>t.type===e)),G=e=>f(`projects.graphNodeTypes.${e}`,null,de[e]||e),K=(0,q.useCallback)(e=>x(e),[]),ie=j(()=>S?A.get(`/projects/${e}/fact-edges`):Promise.resolve(null),[e,S,n]),ae=()=>{s?s():(P.reload(),S&&ie.reload())},oe=t=>{H({title:f(`projects.graphDeleteEdge`,null,`删边`),content:f(`projects.confirmDeleteGraphEdge`,null,`确定删除此关系边?`),okText:f(`common.delete`,null,`删除`),onOk:async()=>{try{await A.del(`/projects/${e}/fact-edges/${t.id}`),V(f(`projects.graphEdgeDeleteSuccess`,null,`边已删除`)),ae()}catch(e){M(Y(e,f(`projects.graphEdgeDeleteFailed`,null,`删除边失败`)))}}})},se=(e,t)=>f(`projects.graphStats`,{nodes:e,edges:t},`${e} 个节点 · ${t} 条关系`),ce=f(`projects.tabGraph`,null,`攻击路径`),ue={reading:f(`projects.graphReadingHint`,null,`已保留可读字号,拖动画布浏览其他节点。`),overview:f(`projects.graphFullOverviewHint`,null,`悬停预览节点摘要,点选查看详情。`)}[T],fe=B&&B.type!==`missing`&&!B.id.startsWith(`vuln:`);return(0,X.jsxs)(I,{title:ce,className:`project-graph-card`,extra:(0,X.jsxs)(c,{children:[(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:se(L.length,z.length)}),(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),"aria-label":f(`common.refresh`,null,`刷新`),theme:`borderless`,loading:P.loading,onClick:ae})]}),children:[(0,X.jsx)(te,{error:pe(P.error),onRetry:P.reload}),(0,X.jsxs)(`div`,{className:`project-toolbar project-graph-toolbar`,children:[(0,X.jsx)(E,{value:p,"aria-label":f(`projects.graphScope`,null,`关系范围`),onChange:e=>{x(``),h(e)},style:{width:134},optionList:[{value:`path`,label:f(`projects.graphViewPath`,null,`攻击路径`)},{value:`full`,label:f(`projects.graphViewFull`,null,`完整关系`)}]}),(0,X.jsx)(Ae,{nodes:L,onSelect:K,t:f}),(0,X.jsx)(u,{checked:g,onChange:e=>{x(``),_(e.target.checked)},children:f(`projects.hideDeprecated`,null,`隐藏废弃`)}),(0,X.jsx)(d,{className:`project-graph-edges-toggle`,"aria-expanded":S,onClick:()=>C(e=>!e),children:f(`projects.graphEdgesTitle`,null,`关系边`)})]}),L.length>0?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`project-graph-status`,children:[B?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(d,{size:`small`,theme:`light`,type:`primary`,onClick:()=>x(``),children:f(`projects.graphBackToOverview`,null,`返回全图`)}),(0,X.jsx)(Z,{size:`small`,"aria-live":`polite`,children:f(`projects.graphFocus`,{stats:se(W.length,U.length)},`聚焦直接关系 · ${se(W.length,U.length)}`)})]}):null,(!B||ue)&&(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:ue||f(`projects.graphOverviewHint`,null,`点选节点查看直接关系和摘要。`)})]}),(0,X.jsxs)(`div`,{className:`project-graph-layout${B&&W.length<=6?` is-compact`:``}`,children:[(0,X.jsxs)(`div`,{className:`project-graph-viewport`,children:[(0,X.jsx)(De,{nodes:W,edges:U,selectedId:B?.id,onSelect:K,chartRef:k,typeLabel:G,onFitChange:D,label:f(`projects.graphCanvas`,null,`攻击路径画布`),errorText:f(`projects.graphRenderError`,null,`图谱加载失败,请刷新重试。`)}),(0,X.jsxs)(`div`,{className:`project-graph-footer`,children:[(0,X.jsxs)(`div`,{className:`project-graph-legend`,children:[ne.map(e=>(0,X.jsxs)(`span`,{style:{"--graph-node-color":J[e]},children:[(0,X.jsx)(re,{type:e}),G(e)]},e)),U.some(e=>e.confidence===`tentative`)&&(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`i`,{className:`project-graph-legend-dash`,"aria-hidden":`true`}),f(`projects.graphTentativeEdge`,null,`待确认关系`)]})]}),(0,X.jsxs)(c,{spacing:4,wrap:!0,children:[(0,X.jsx)(d,{size:`small`,icon:(0,X.jsx)(y,{}),"aria-label":f(`projects.graphZoomOut`,null,`缩小`),onClick:()=>k.current?.zoom(1/1.3)}),(0,X.jsx)(d,{size:`small`,icon:(0,X.jsx)(v,{}),"aria-label":f(`projects.graphZoomIn`,null,`放大`),onClick:()=>k.current?.zoom(1.3)}),(0,X.jsx)(d,{size:`small`,"aria-pressed":T===`fitted`||T===`reading`,onClick:()=>k.current?.fit(),children:f(`projects.graphFit`,null,`适合画布`)}),(0,X.jsx)(d,{size:`small`,"aria-pressed":T===`overview`,onClick:()=>k.current?.overview(),children:f(`projects.graphFullOverview`,null,`全图总览`)})]})]})]}),B&&(0,X.jsx)(`aside`,{ref:ee,className:`project-graph-side`,"aria-label":f(`projects.graphNodeDetails`,null,`节点详情`),children:(0,X.jsxs)(`div`,{className:`project-detail-stack`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(Z,{strong:!0,children:ke(B)}),(0,X.jsx)(`code`,{className:`project-graph-node-key`,dir:`auto`,children:B.fact_key||B.id}),(0,X.jsxs)(`div`,{className:`project-graph-side-tags`,children:[(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:G(B.type)}),(0,X.jsx)(l,{size:`small`,color:le[B.confidence]?.color||`grey`,children:le[B.confidence]?f(`projects.graphConfidence.${B.confidence}`,null,le[B.confidence].label):B.confidence||`—`})]})]}),fe&&(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{size:`small`,onClick:()=>r(B.fact_key),children:f(`projects.details`,null,`详情`)}),(0,X.jsx)(d,{size:`small`,disabled:!t,onClick:()=>i(B.fact_key),children:f(`common.edit`,null,`编辑`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(Z,{strong:!0,size:`small`,children:[f(`projects.graphDirectLinks`,null,`直接关系`),` · `,U.length]}),U.length?(0,X.jsx)(`ul`,{className:`project-graph-neighbors`,children:U.map((e,t)=>{let n=e.source===B.id,r=R.get(n?e.target:e.source);return(0,X.jsxs)(`li`,{children:[(0,X.jsxs)(`div`,{className:`project-graph-edge-meta`,children:[(0,X.jsxs)(`span`,{children:[n?`→`:`←`,` `,n?f(`projects.graphEdgeOutgoing`,null,`出边`):f(`projects.graphEdgeIncoming`,null,`入边`)]}),(0,X.jsx)(`code`,{children:e.type}),e.confidence===`tentative`&&(0,X.jsx)(`span`,{children:f(`projects.graphConfidence.tentative`,null,`待确认`)})]}),(0,X.jsx)(`button`,{type:`button`,className:`project-graph-peer project-link-button`,onClick:()=>K(r.id),title:r.fact_key,children:ke(r)})]},e.id||t)})}):(0,X.jsx)(`div`,{children:(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:f(`projects.graphEdgesEmpty`,null,`暂无关系边`)})})]})]})})]})]}):P.loading?(0,X.jsx)(`div`,{className:`project-graph-loading`,children:(0,X.jsx)(m,{})}):F&&!P.error?(0,X.jsxs)(o,{title:f(`projects.graphEmptyTitle`,null,`构建攻击路径图`),description:f(`projects.graphEmpty`,null,`暂无路径图数据。为 finding/exploit 类事实添加关系边(discovered_on → target/*)后将在此展示。`),style:{padding:40},children:[(0,X.jsxs)(`div`,{className:`project-graph-empty-steps`,children:[(0,X.jsx)(Z,{type:`tertiary`,children:f(`projects.graphEmptyStep1`,null,`添加 target 类事实(目标、域名、入口)`)}),(0,X.jsx)(Z,{type:`tertiary`,children:f(`projects.graphEmptyStep2`,null,`记录 finding / exploit 并在 links 中连边`)}),(0,X.jsx)(Z,{type:`tertiary`,children:f(`projects.graphEmptyStep3`,null,`使用「连边」模式或编辑事实手动补关系`)})]}),(0,X.jsx)(d,{type:`primary`,disabled:!t,onClick:a,children:f(`projects.graphEmptyCta`,null,`添加第一条事实`)})]}):null,S?(0,X.jsxs)(`div`,{className:`project-edge-table`,children:[(0,X.jsx)(te,{error:pe(ie.error),onRetry:()=>ie.reload()}),(ie.data||[]).length?(0,X.jsx)(`ul`,{className:`project-edge-rows`,children:ie.data.map(e=>(0,X.jsxs)(`li`,{className:`project-edge-row`,children:[(0,X.jsx)(`code`,{children:e.source_fact_key}),(0,X.jsx)(`span`,{className:`project-edge-type`,children:e.edge_type}),(0,X.jsx)(`span`,{className:`project-edge-arrow`,children:`→`}),(0,X.jsx)(`code`,{children:e.target_fact_key}),(0,X.jsx)(l,{size:`small`,color:e.confidence===`tentative`?`amber`:`green`,children:(le[e.confidence]||{}).label||e.confidence||`—`}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>oe(e),children:f(`projects.graphDeleteEdge`,null,`删边`)})]},e.id))}):(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:f(`projects.graphEdgesEmpty`,null,`暂无关系边`)})]}):null]})}var{Text:Me}=s;function Ne({projectId:e,canWrite:t,onChanged:r}){let i=O(),a=n(),{hasPermission:o}=k(),s=o(`chat:write`),u=j(()=>A.get(`/projects/${e}/conversations`,{limit:100}),[e]),f=u.data?.conversations||[],p=t=>{H({title:i(`projects.promoteAttackChain`,null,`沉淀攻击链`),content:i(`projects.confirmPromoteAttackChain`,null,`将该对话的攻击链沉淀到本项目?会创建/更新事实与关系边。`),okText:i(`projects.promoteAttackChain`,null,`沉淀攻击链`),danger:!1,onOk:async()=>{try{let n=await A.post(`/projects/${e}/promote-attack-chain/${t.id}`);V(i(`projects.promoteAttackChainSuccess`,{facts_created:n?.facts_created||0,facts_updated:n?.facts_updated||0,edges_created:n?.edges_created||0},`已沉淀:新建 ${n?.facts_created||0} / 更新 ${n?.facts_updated||0} / 边 ${n?.edges_created||0}`)),u.reload({silent:!0}),r?.()}catch(e){M(Y(e,i(`projects.promoteAttackChainFailed`,null,`沉淀失败`)))}}})},m=e=>{H({title:i(`projects.unbind`,null,`解绑`),content:i(`projects.confirmUnbindConversation`,null,`解除该对话与当前项目的绑定?`),okText:i(`projects.unbind`,null,`解绑`),onOk:async()=>{try{await A.put(`/conversations/${e.id}/project`,{projectId:``}),V(i(`projects.projectUnbound`,null,`已解除项目绑定`)),u.reload({silent:!0}),r?.()}catch(e){M(Y(e,i(`projects.unbindFailed`,null,`解绑失败`)))}}})},h=[{title:i(`projects.titleLabel`,null,`标题`),dataIndex:`title`,render:(e,t)=>(0,X.jsx)(`button`,{type:`button`,className:`project-link-button`,onClick:()=>a(`/chat?conversation=${encodeURIComponent(t.id)}`),title:e||t.id,children:e||i(`projects.untitledConversation`,null,`未命名对话`)})},{title:`ID`,dataIndex:`id`,width:240,render:e=>(0,X.jsx)(Me,{type:`tertiary`,size:`small`,children:(0,X.jsx)(`code`,{children:e})})},{title:i(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:170,render:(e,t)=>(0,X.jsx)(Me,{size:`small`,children:D(e||t.updatedAt||t.created_at||t.createdAt)})},{title:i(`common.actions`,null,`操作`),dataIndex:`id`,width:280,render:(e,n)=>(0,X.jsxs)(c,{spacing:2,wrap:!0,children:[(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>a(`/chat?conversation=${encodeURIComponent(n.id)}`),children:i(`projects.open`,null,`打开`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,title:i(`projects.promoteAttackChainTitle`,null,`将对话攻击链沉淀为项目事实与边`),onClick:()=>p(n),children:i(`projects.promoteAttackChain`,null,`沉淀攻击链`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!s,title:i(`projects.unbindProjectTitle`,null,`解除项目绑定`),onClick:()=>m(n),children:i(`projects.unbind`,null,`解绑`)})]})}];return(0,X.jsxs)(I,{title:i(`projects.tabConversations`,null,`关联对话`),description:i(`projects.boundConversationsHint`,null,`绑定到本项目的对话;点击可打开会话`),extra:(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:f.length}),children:[(0,X.jsx)(te,{error:pe(u.error),onRetry:u.reload}),(0,X.jsx)(z,{columns:h,dataSource:f,rowKey:`id`,loading:u.loading,pagination:{pageSize:10},emptyText:i(`projects.noBoundConversations`,null,`暂无绑定对话;在对话页选择本项目即可关联`),onRefresh:()=>u.reload()})]})}var{Text:Q}=s,Pe={targets:[`https://example.com`],exclude:[`*.cdn.example.com`],notes:`仅授权 Web 应用层测试`};function Fe(e){try{let t=e.trim()?JSON.parse(e):{};return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}function Ie({project:e,canWrite:t,canDelete:n,onChanged:r,onDeleted:i}){let o=O(),s=(0,q.useId)(),[l,u]=(0,q.useState)({name:``,description:``,scope_json:``,lessons_mode:`off`,status:`active`,pinned:!1}),[m,h]=(0,q.useState)(!1);(0,q.useEffect)(()=>{e&&u({name:e.name||``,description:e.description||``,scope_json:e.scope_json||``,lessons_mode:e.lessons_mode||`off`,status:e.status||`active`,pinned:!!e.pinned})},[e]);let g=e=>u(t=>({...t,...e})),v=Fe(l.scope_json),y=v?.constraints??[],x=Array.isArray(y)&&y.every(e=>e&&typeof e==`object`&&!Array.isArray(e)),C=e=>u(t=>{let n=Fe(t.scope_json);return n?{...t,scope_json:JSON.stringify({...n,...e},null,2)}:t}),w=(e,t)=>C({constraints:y.map((n,r)=>r===e?{...n,...t}:n)}),T=[{value:`off`,label:o(`projects.noiseOff`,null,`关闭`)},{value:`quiet`,label:o(`projects.noiseQuiet`,null,`低噪音`)},{value:`balanced`,label:o(`projects.noiseBalanced`,null,`均衡`)},{value:`aggressive`,label:o(`projects.noiseAggressive`,null,`维护窗口`)}],D=[{value:`allow`,label:o(`projects.constraintAllow`,null,`允许`)},{value:`deny`,label:o(`projects.constraintDeny`,null,`禁止`)}],k=()=>{let e=l.scope_json.trim();if(e)try{g({scope_json:JSON.stringify(JSON.parse(e),null,2)})}catch(e){M(o(`projects.invalidJson`,null,`JSON 格式无效`)+`:`+Y(e,``))}},ee=()=>g({scope_json:JSON.stringify(Pe,null,2)}),j=async()=>{let t=l.name.trim();if(!t){M(o(`projects.enterProjectName`,null,`请输入项目名称`));return}let n=l.scope_json.trim();if(n)try{JSON.parse(n)}catch{M(o(`projects.invalidScopeJson`,null,`测试范围 JSON 无效,请先修正或点击「格式化」`));return}h(!0);try{await A.put(`/projects/${e.id}`,{name:t,description:l.description,scope_json:n,...l.lessons_mode===(e.lessons_mode||`off`)?{}:{lessons_mode:l.lessons_mode},...l.status===(e.status||`active`)?{}:{status:l.status},pinned:!!l.pinned}),V(o(`projects.saved`,null,`已保存`)),r?.()}catch(e){M(Y(e,o(`projects.saveFailed`,null,`保存失败`)))}finally{h(!1)}},N=(e?.status||`active`)===`archived`;return e?(0,X.jsxs)(I,{title:o(`projects.settingsIntroTitle`,null,`项目设置`),description:o(`projects.settingsIntroHint`,null,`配置项目元数据与 Agent 授权边界,保存后即时生效于绑定对话。`),extra:(0,X.jsx)(d,{type:`primary`,loading:m,disabled:!t,onClick:j,children:o(`projects.saveSettings`,null,`保存更改`)}),children:[(0,X.jsxs)(`div`,{className:`project-form-grid`,children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.projectName`,null,`项目名称`)}),(0,X.jsx)(p,{value:l.name,disabled:!t,onChange:e=>g({name:e})}),(0,X.jsx)(Q,{type:`tertiary`,size:`small`,children:o(`projects.saveChangesHint`,null,`修改后请点击保存以同步到服务器`)})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.status`,null,`状态`)}),(0,X.jsx)(E,{value:l.status,disabled:!t,optionList:ue,onChange:e=>g({status:e}),style:{width:`100%`}}),(0,X.jsxs)(`div`,{className:`project-switch-row`,children:[(0,X.jsx)(_,{checked:l.pinned,disabled:!t,onChange:e=>g({pinned:e})}),(0,X.jsx)(Q,{size:`small`,children:o(`projects.pinProject`,null,`置顶项目(列表优先显示)`)})]})]})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.projectDescription`,null,`项目描述`)}),(0,X.jsx)(f,{value:l.description,rows:3,maxCount:4e3,disabled:!t,placeholder:o(`projects.editDescriptionPlaceholder`,null,`客户/任务备注、协作说明、联系人…`),onChange:e=>g({description:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsxs)(c,{children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.scopeJsonLabel`,null,`范围 JSON`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:k,children:o(`projects.formatJson`,null,`格式化`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:ee,children:o(`projects.example`,null,`示例`)})]}),(0,X.jsx)(f,{value:l.scope_json,rows:8,disabled:!t,placeholder:`{
"targets": ["https://example.com"]
-}`,onChange:e=>g({scope_json:e})}),(0,X.jsx)(Q,{type:`tertiary`,size:`small`,children:o(`projects.scopeStructuredHint`,null,`范围、排除项和操作约束保存在同一份 JSON。新增目标需明确授权。`)}),!v||!x?(0,X.jsx)(Q,{type:`warning`,size:`small`,children:o(`projects.scopeStructuredInvalid`,null,`请在 JSON 中修正范围对象和操作约束列表。`)}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.scopeConstraints`,null,`操作约束`)}),y.map((e,n)=>(0,X.jsxs)(c,{wrap:!0,children:[(0,X.jsx)(Q,{size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-constraint-${n}`,children:o(`projects.constraintKind`,null,`约束类型`)})}),(0,X.jsx)(b,{type:`button`,"aria-labelledby":`${s}-constraint-${n}`,disabled:!t,value:e.kind,onChange:e=>w(n,{kind:e.target.value}),children:D.map(({value:e,label:t})=>(0,X.jsx)(S,{value:e,children:t},e))}),(0,X.jsx)(p,{"aria-label":o(`projects.constraintText`,null,`约束内容`),value:typeof e.text==`string`?e.text:``,disabled:!t,onChange:e=>w(n,{text:e})}),(0,X.jsx)(Q,{size:`small`,children:e.origin===`goals`?o(`projects.constraintGoals`,null,`目标建议,待人工确认`):o(`projects.constraintHuman`,null,`人工`)}),(0,X.jsx)(d,{size:`small`,disabled:!t,onClick:()=>C({constraints:y.filter((e,t)=>t!==n)}),children:o(`common.delete`,null,`删除`)})]},n)),(0,X.jsx)(d,{size:`small`,disabled:!t,onClick:()=>C({constraints:[...y,{kind:`deny`,text:``,origin:`human`}]}),children:o(`projects.addScopeConstraint`,null,`添加约束`)})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-noise`,children:o(`projects.noiseProfile`,null,`噪音档位`)})}),(0,X.jsx)(b,{type:`button`,"aria-labelledby":`${s}-noise`,disabled:!t,value:v.noise_profile||`off`,onChange:e=>C({noise_profile:e.target.value}),children:T.map(({value:e,label:t})=>(0,X.jsx)(S,{value:e,children:t},e))})]})]})]}),(0,X.jsxs)(`div`,{className:`project-switch-row`,children:[(0,X.jsx)(_,{"aria-labelledby":`${s}-lessons`,checked:l.lessons_mode===`shadow`||l.lessons_mode===`inject`,disabled:!t,onChange:e=>g({lessons_mode:e?`shadow`:`off`})}),(0,X.jsx)(Q,{size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-lessons`,children:o(`projects.lessonsMode`,null,`处置经验影子审计`)})}),l.lessons_mode===`shadow`||l.lessons_mode===`inject`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_,{"aria-labelledby":`${s}-lessons-inject`,checked:l.lessons_mode===`inject`,disabled:!t,onChange:e=>g({lessons_mode:e?`inject`:`shadow`})}),(0,X.jsx)(Q,{size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-lessons-inject`,children:o(`projects.lessonsInject`,null,`注入活跃经验到上下文`)})})]}):null]}),(0,X.jsx)(a,{margin:`12px`}),(0,X.jsxs)(`div`,{className:`project-danger-zone`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(Q,{strong:!0,children:o(`projects.dangerZoneTitle`,null,`危险操作`)}),(0,X.jsx)(`div`,{children:(0,X.jsx)(Q,{type:`tertiary`,size:`small`,children:o(`projects.dangerZoneHint`,null,`在项目列表选择「已归档」可查看归档项目。删除项目会永久删除项目记忆。`)})})]}),(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{disabled:!t,onClick:()=>{H({title:N?o(`projects.restoreProjectActive`,null,`恢复为进行中`):o(`projects.archiveProject`,null,`归档`),content:N?o(`projects.confirmRestoreProjectActive`,null,`恢复后,项目记忆与随项目归档的漏洞将重新启用。单独归档的漏洞仍保留在归档列表。`):o(`projects.confirmArchiveProject`,null,`项目记忆和关联漏洞将随项目归档,可从已归档项目中查阅。是否继续?`),okText:o(`common.confirm`,null,`确认`),danger:!N,onOk:async()=>{try{await k.put(`/projects/${e.id}`,{status:N?`active`:`archived`}),V(o(`projects.saved`,null,`已保存`)),r?.()}catch(e){M(Y(e,o(`projects.operationFailed`,null,`操作失败`)))}}})},children:N?o(`projects.restoreProjectActive`,null,`恢复为进行中`):o(`projects.archiveProject`,null,`归档`)}),(0,X.jsx)(d,{type:`danger`,disabled:!n,onClick:()=>{H({title:o(`projects.deleteProject`,null,`删除项目`),content:o(`projects.confirmDeleteProject`,null,`确定删除该项目?事实将一并删除,对话将解除绑定。`),okText:o(`common.delete`,null,`删除`),onOk:async()=>{try{await k.del(`/projects/${e.id}`),V(o(`projects.deleteProject`,null,`删除项目`)),i?.(e.id)}catch(e){M(Y(e,o(`projects.deleteFailed`,null,`删除失败`)))}}})},children:o(`projects.deleteProject`,null,`删除项目`)})]})]})]}):(0,X.jsx)(I,{title:o(`projects.tabSettings`,null,`设置`),children:(0,X.jsx)(Q,{type:`tertiary`,children:o(`projects.selectOrCreateTitle`,null,`选择或创建项目`)})})}var{Text:$}=s,Le={fact_key:``,category:`note`,summary:``,body:``,confidence:`tentative`,pinned:!1,related_vulnerability_id:``,confirmation_note:``,links_text:``};function Re({visible:e,projectId:t,factKey:n,onCancel:r,onSaved:i}){let a=A(),[o,s]=(0,q.useState)(Le),[c,l]=(0,q.useState)(oe),[d,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(``),y=!!n;(0,q.useEffect)(()=>{if(!e||(s(Le),l(oe),v(``),m(!1),g(!1),!n))return;let r=!1;return m(!0),k.get(`/projects/${t}/facts`,{fact_key:n,include_links:`true`}).then(e=>{if(r||!e)return;let t=e.category||`note`;oe.some(e=>e.value===t)||l([...oe,{value:t,label:`${t}(自定义)`}]),v(e.id||``),s({fact_key:e.fact_key||n,category:t,summary:e.summary||``,body:e.body||``,confidence:(e.confidence||`tentative`).toLowerCase(),pinned:!!e.pinned,related_vulnerability_id:e.related_vulnerability_id||``,confirmation_note:e.confirmation_note||``,links_text:me(e.incoming_links)})}).catch(e=>{r||M(Y(e,a(`projects.loadFactFailed`,null,`加载事实失败`)))}).finally(()=>{r||m(!1)}),()=>{r=!0}},[e,t,n]);let b=e=>s(t=>({...t,...e})),x=(0,q.useMemo)(()=>fe.join(`、`),[]);return(0,X.jsxs)(N,{visible:e,title:y?a(`projects.editFact`,null,`编辑事实`):a(`projects.addFact`,null,`添加事实`),onCancel:r,onOk:async()=>{let e=o.fact_key.trim(),n=o.summary.trim(),r=o.confirmation_note.trim();if(!e||!n){M(a(`projects.factKeySummaryRequired`,null,`fact_key 与 summary 必填`));return}if((o.confidence||`tentative`)===`confirmed`&&!r){M(a(`projects.confirmationNoteRequired`,null,`升级为已确认需要审核说明`));return}let s={fact_key:e,category:o.category||`note`,summary:n,body:o.body,confidence:o.confidence||`tentative`,pinned:!!o.pinned,related_vulnerability_id:o.related_vulnerability_id.trim(),confirmation_note:r,links_text:o.links_text};if(y&&!_)M(a(`projects.loadFactFailed`,null,`加载事实失败`));else{g(!0);try{y&&_?await k.put(`/projects/${t}/facts/${_}`,s):await k.post(`/projects/${t}/facts`,s),V(a(`projects.saved`,null,`已保存`)),i?.()}catch(e){M(Y(e,a(`projects.saveFailed`,null,`保存失败`)))}finally{g(!1)}}},okText:y?a(`projects.saveChanges`,null,`保存修改`):a(`projects.saveFact`,null,`保存事实`),cancelText:a(`common.cancel`,null,`取消`),confirmLoading:h,width:720,maskClosable:!1,children:[(0,X.jsx)($,{type:`tertiary`,size:`small`,children:a(`projects.factModalSubtitle`,null,`摘要注入黑板索引;body 沉淀攻击链与 POC,供审计复现(与漏洞记录分工)`)}),(0,X.jsxs)(`div`,{className:`project-form-grid`,children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:`fact_key`}),(0,X.jsx)(p,{value:o.fact_key,disabled:d,placeholder:`target/primary_domain`,onChange:e=>b({fact_key:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.category`,null,`分类`)}),(0,X.jsx)(E,{value:o.category,optionList:c,onChange:e=>b({category:e}),style:{width:`100%`}})]})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.summary`,null,`摘要`)}),(0,X.jsx)(p,{value:o.summary,placeholder:a(`projects.summary`,null,`摘要`)+`:什么 + 在哪 + 如何验证`,onChange:e=>b({summary:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-grid`,children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.confidence`,null,`置信度`)}),(0,X.jsx)(E,{value:o.confidence,optionList:ce,onChange:e=>b({confidence:e}),style:{width:`100%`}})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.relatedVulnIdLabel`,null,`关联漏洞 ID`)}),(0,X.jsx)(p,{value:o.related_vulnerability_id,placeholder:a(`projects.optional`,null,`可选`),onChange:e=>b({related_vulnerability_id:e})})]})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.confirmationNote`,null,`审核说明`)}),(0,X.jsx)(f,{value:o.confirmation_note,rows:3,disabled:o.confidence!==`confirmed`,placeholder:a(`projects.confirmationNotePlaceholder`,null,`说明为何把这条事实标为已确认`),onChange:e=>b({confirmation_note:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:`body`}),(0,X.jsx)(f,{value:o.body,rows:10,placeholder:"## 验证步骤\n1. …\n\n```http\nGET /path HTTP/1.1\n```",onChange:e=>b({body:e})}),(0,X.jsx)($,{type:`tertiary`,size:`small`,children:a(`projects.factBodyRelationsHint`,null,`正文中的 discovered_on 等关系请填写到下方“关系边”字段,才能生成图谱连线。`)})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.factLinksLabel`,null,`关系边(from → 本事实)`)}),(0,X.jsx)(f,{value:o.links_text,rows:3,placeholder:a(`projects.factLinksPlaceholder`,null,`discovered_on: target/primary_domain`),onChange:e=>b({links_text:e})}),(0,X.jsxs)($,{type:`tertiary`,size:`small`,children:[a(`projects.factLinksHint`,null,`每行一条:type: source_fact_key(来源 → 当前事实)。`),` `,`常用 type:`,x,`。`]})]}),(0,X.jsx)(u,{checked:o.pinned,onChange:e=>b({pinned:e.target.checked}),children:a(`projects.pinFact`,null,`置顶事实(列表与黑板索引优先)`)})]})}var{Text:ze,Paragraph:Be}=s;function Ve({value:e}){let t=le[String(e||``).toLowerCase()]||{label:e||`—`,color:`grey`};return(0,X.jsx)(l,{size:`small`,color:t.color,children:t.label})}function He({projectId:e,factKey:t,visible:n,canWrite:r,revision:i=0,onClose:a,onEdit:s}){let u=A(),f=j(()=>t?k.get(`/projects/${e}/facts`,{fact_key:t,include_links:`true`}):Promise.resolve(null),[e,t,i]),p=f.data;return(0,X.jsxs)(C,{visible:n,width:640,title:u(`projects.factDetails`,null,`事实详情`),onCancel:a,footer:(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{disabled:!r||!p,onClick:()=>s?.(t),children:u(`common.edit`,null,`编辑`)}),(0,X.jsx)(d,{onClick:a,children:u(`common.close`,null,`关闭`)})]}),children:[(0,X.jsx)(te,{error:pe(f.error),onRetry:f.reload}),p?(0,X.jsxs)(`div`,{className:`project-detail-stack`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:p.fact_key}),(0,X.jsxs)(`div`,{className:`project-graph-side-tags`,children:[(0,X.jsx)(l,{size:`small`,color:`cyan`,type:`light`,children:se[String(p.category||``).toLowerCase()]||p.category||`—`}),(0,X.jsx)(Ve,{value:p.confidence}),p.pinned?(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:u(`projects.pinned`,null,`置顶`)}):null]})]}),(0,X.jsx)(P,{items:[{label:u(`projects.updated`,null,`更新`),value:D(p.updated_at)},{label:u(`projects.confidence`,null,`置信度`),value:(0,X.jsx)(Ve,{value:p.confidence})},p.related_vulnerability_id?{label:u(`projects.relatedVulnIdTitle`,null,`关联漏洞 ID`),value:p.related_vulnerability_id}:null,p.confirmation_note?{label:u(`projects.confirmationNote`,null,`审核说明`),value:p.confirmation_note}:null,p.source_conversation_id?{label:u(`projects.factMetaSourceConversation`,{value:``},`来源对话`),value:p.source_conversation_id}:null]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:u(`projects.summary`,null,`摘要`)}),(0,X.jsx)(Be,{className:`project-fact-summary`,children:p.summary||`—`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:`body`}),p.body?(0,X.jsx)(F,{content:p.body}):(0,X.jsx)(ze,{type:`tertiary`,children:u(`projects.emptyBody`,null,`(无 body)`)})]}),(p.incoming_links||[]).length>0&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:u(`projects.factIncomingLinksLabel`,null,`入边(只读)`)}),(0,X.jsx)(`ul`,{className:`project-link-list`,children:p.incoming_links.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`code`,{children:e.edge_type}),` ← `,(0,X.jsx)(`code`,{children:e.source_fact_key})]},e.id))})]}),(p.outgoing_links||[]).length>0&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:u(`projects.graphEdgeFromSelf`,null,`本节点指出`)}),(0,X.jsx)(`ul`,{className:`project-link-list`,children:p.outgoing_links.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`code`,{children:e.edge_type}),` → `,(0,X.jsx)(`code`,{children:e.target_fact_key})]},e.id))})]})]}):!f.loading&&!f.error?(0,X.jsx)(o,{title:u(`projects.noFacts`,null,`暂无事实`)}):null]})}var{Title:Ue,Text:We,Paragraph:Ge}=s;function Ke({projectId:e,tab:t,refreshToken:r=0,onTabChange:i,onChanged:a,onDeleted:o}){let s=A(),u=n(),{hasPermission:f}=O(),p=f(`project:write`),m=f(`project:delete`),[h,_]=(0,q.useState)(0),[v,y]=(0,q.useState)({visible:!1,factKey:``}),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(``),T=j(()=>k.get(`/projects/${e}`),[e,h,r]),E=j(()=>k.get(`/projects/${e}/stats`),[e,h,r]),M=(0,q.useCallback)(()=>{_(e=>e+1),a?.()},[a]),N=(0,q.useCallback)(e=>y({visible:!0,factKey:e||``}),[]),P=(0,q.useCallback)(e=>C(e||``),[]),F=(0,q.useMemo)(()=>[{itemKey:`facts`,tab:s(`projects.tabFacts`,null,`事实黑板`)},{itemKey:`graph`,tab:s(`projects.tabGraph`,null,`攻击路径`)},{itemKey:`conversations`,tab:s(`projects.tabConversations`,null,`关联对话`)},{itemKey:`settings`,tab:s(`projects.tabSettings`,null,`设置`)}],[s]),L=[{id:`facts`,label:s(`projects.facts`,null,`事实`),value:E.data?.fact_count??`—`,loading:E.loading},{id:`vulns`,label:s(`projects.vulnerabilityManagement`,null,`漏洞`),value:E.data?.vuln_count??`—`,loading:E.loading},{id:`conversations`,label:s(`projects.tabConversations`,null,`关联对话`),value:E.data?.conversation_count??`—`,loading:E.loading},{id:`sparse`,label:s(`projects.factBodySparse`,null,`待补全`),value:E.data?.sparse_fact_count??`—`,tone:(E.data?.sparse_fact_count||0)>0?`warning`:void 0,loading:E.loading}],R=T.data,z=R?.status===`archived`;return(0,X.jsxs)(`div`,{className:`project-detail`,children:[(0,X.jsxs)(`div`,{className:`project-detail-summary`,children:[(0,X.jsx)(te,{error:pe(T.error),onRetry:T.reload}),(0,X.jsxs)(I,{className:`project-detail-head`,children:[(0,X.jsxs)(`div`,{className:`project-detail-head-main`,children:[(0,X.jsxs)(`div`,{className:`project-detail-title-row`,children:[(0,X.jsx)(Ue,{heading:4,className:`project-detail-title`,children:R?.name||s(`projects.projectNotFound`,null,`项目不存在`)}),R?.pinned?(0,X.jsx)(l,{size:`small`,color:`blue`,children:s(`projects.pinned`,null,`置顶`)}):null,(0,X.jsx)(l,{size:`small`,color:z?`grey`:`green`,children:z?s(`projects.statusArchived`,null,`已归档`):s(`projects.statusActive`,null,`进行中`)})]}),R?.description?(0,X.jsx)(Ge,{className:`project-detail-desc`,children:R.description}):(0,X.jsx)(We,{type:`tertiary`,size:`small`,children:s(`projects.noProjectDescription`,null,`暂无项目描述`)}),(0,X.jsxs)(We,{type:`tertiary`,size:`small`,children:[s(`projects.updatedPrefix`,{time:D(R?.updated_at)},`更新于 ${D(R?.updated_at)}`),` · `,`ID: `,(0,X.jsx)(`code`,{children:e})]})]}),(0,X.jsxs)(c,{wrap:!0,children:[R&&f(`vulnerability:read`)&&(0,X.jsx)(d,{onClick:()=>u(`/vulnerabilities?project_id=${encodeURIComponent(e)}&archived=${z?`true`:`all`}`),children:s(`projects.projectVulnerabilities`,null,`项目漏洞`)}),R&&f(`asset:write`)&&(0,X.jsx)(d,{onClick:()=>x(!0),children:s(`assets.addAsset`,null,`新增资产`)}),R&&f(`asset:read`)&&(0,X.jsx)(d,{onClick:()=>u(`/asset-library?project_id=${encodeURIComponent(e)}`),children:s(`assets.projectAssets`,null,`项目资产`)}),(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),theme:`borderless`,loading:T.loading||E.loading,onClick:()=>{T.reload(),E.reload()}}),(0,X.jsx)(d,{type:`primary`,disabled:!p,onClick:()=>N(``),children:s(`projects.addFactCta`,null,`+ 添加事实`)})]})]}),(0,X.jsx)(ee,{metrics:L,columns:4}),(0,X.jsx)(g,{type:`line`,tabList:F,activeKey:t||`facts`,onChange:e=>i?.(e),className:`project-tabs`})]}),(!t||t===`facts`)&&(0,X.jsx)(_e,{projectId:e,canWrite:p,revision:h,onAddFact:()=>N(``),onEditFact:N,onViewFact:P,onMutated:M}),t===`graph`&&(0,X.jsx)(je,{projectId:e,canWrite:p,revision:h,onOpenFact:P,onEditFact:N,onAddFact:()=>N(``),onChanged:M}),t===`conversations`&&(0,X.jsx)(Ne,{projectId:e,canWrite:p,onChanged:M}),t===`settings`&&(0,X.jsx)(Ie,{project:R,canWrite:p,canDelete:m,onChanged:M,onDeleted:e=>o?.(e)}),b&&R&&f(`asset:write`)&&(0,X.jsx)(ae,{visible:!0,defaultProjectId:e,fixedProject:!0,projects:[R],onClose:()=>x(!1)}),(0,X.jsx)(Re,{visible:v.visible,projectId:e,factKey:v.factKey,onCancel:()=>y({visible:!1,factKey:``}),onSaved:()=>{y({visible:!1,factKey:``}),M()}}),(0,X.jsx)(He,{projectId:e,factKey:S,visible:!!S,canWrite:p,revision:h,onClose:()=>C(``),onEdit:e=>{C(``),N(e)}})]})}var{Text:qe}=s,Je=10;async function Ye(){let[e,t]=await Promise.all([k.get(`/projects`,{limit:500}),k.get(`/projects/dashboard-summary`,{fact_limit:6}).catch(()=>null)]);return{projects:Array.isArray(e?.projects)?e.projects:[],total:e?.total??0,summary:t}}function Xe(){let e=A(),{hasPermission:t}=O(),n=t(`project:write`),r=t(`project:delete`),[a,s]=i(),u=a.get(`id`)||``,f=a.get(`tab`)||`facts`,[m,h]=(0,q.useState)(``),g=L(m,250),[_,y]=(0,q.useState)(`active`),[b,S]=(0,q.useState)(1),[C,N]=(0,q.useState)({visible:!1,project:null}),[P,F]=(0,q.useState)(0),B=j(Ye,[]),W=B.data?.projects||[],ne=B.data?.summary,G=(0,q.useCallback)((e,t)=>{let n=new URLSearchParams(a);e?n.set(`id`,e):n.delete(`id`),t?n.set(`tab`,t):n.delete(`tab`),s(n,{replace:!!e})},[a,s]),K=(0,q.useMemo)(()=>{let e=g.trim().toLowerCase();return W.filter(t=>{let n=t.status||`active`;return _!==`all`&&n!==_?!1:!e||[t.name,t.description,t.id].join(` `).toLowerCase().includes(e)})},[W,g,_]),re=Math.min(b,Math.max(1,Math.ceil(K.length/Je))),ie=K.slice((re-1)*Je,re*Je);(0,q.useEffect)(()=>{!u&&K.length&&G(K[0].id,f)},[u,K,f,G]);let ae=(0,q.useMemo)(()=>W.filter(e=>(e.status||`active`)===`archived`).length,[W]),oe=[{id:`active`,label:e(`projects.statusActive`,null,`进行中`),value:ne?.totals?.active_projects??W.filter(e=>(e.status||`active`)===`active`).length,loading:B.loading},{id:`facts`,label:e(`projects.facts`,null,`事实`),value:ne?.totals?.total_facts??`—`,detail:e(`projects.sharedFactBoard`,null,`共享事实黑板`),loading:B.loading},{id:`total`,label:e(`projects.projectList`,null,`项目列表`),value:B.data?.total??W.length,loading:B.loading},{id:`archived`,label:e(`projects.statusArchived`,null,`已归档`),value:ae,loading:B.loading}],se=t=>{H({title:e(`projects.deleteProject`,null,`删除项目`),content:e(`projects.confirmDeleteProject`,null,`确定删除该项目?事实将一并删除,对话将解除绑定。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await k.del(`/projects/${t.id}`),V(e(`projects.deleteProject`,null,`删除项目`)),u===t.id&&G(``),B.reload({silent:!0}),F(e=>e+1)}catch(t){M(Y(t,e(`projects.deleteFailed`,null,`删除失败`)))}}})},ce=t=>{let n=(t.status||`active`)===`archived`;H({title:n?e(`projects.restoreProjectActive`,null,`恢复为进行中`):e(`projects.archiveProject`,null,`归档`),content:n?e(`projects.confirmRestoreProjectActive`,null,`恢复后,项目记忆与随项目归档的漏洞将重新启用。单独归档的漏洞仍保留在归档列表。`):e(`projects.confirmArchiveProject`,null,`项目记忆和关联漏洞将随项目归档,可从已归档项目中查阅。是否继续?`),okText:e(`common.confirm`,null,`确认`),danger:!n,onOk:async()=>{try{await k.put(`/projects/${t.id}`,{status:n?`active`:`archived`}),V(e(`projects.saved`,null,`已保存`)),B.reload({silent:!0}),F(e=>e+1)}catch(t){M(Y(t,e(`projects.operationFailed`,null,`操作失败`)))}}})},le=[{title:e(`projects.projectName`,null,`项目名称`),dataIndex:`name`,render:(t,n)=>(0,X.jsxs)(`div`,{className:`project-list-name`,children:[(0,X.jsxs)(`div`,{className:`project-list-name-row`,children:[(0,X.jsx)(`span`,{className:`project-list-name-text${n.id===u?` is-active`:``}`,children:t||n.id}),n.pinned?(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:e(`projects.pinned`,null,`置顶`)}):null]}),n.description?(0,X.jsx)(qe,{type:`tertiary`,size:`small`,className:`project-list-desc`,children:n.description}):null]})},{title:e(`projects.status`,null,`状态`),dataIndex:`status`,width:92,render:t=>{let n=(t||`active`)===`archived`;return(0,X.jsx)(l,{size:`small`,color:n?`grey`:`green`,children:n?e(`projects.statusArchived`,null,`已归档`):e(`projects.statusActive`,null,`进行中`)})}},{title:e(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:150,render:e=>(0,X.jsx)(qe,{type:`tertiary`,size:`small`,children:D(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:176,render:(t,i)=>(0,X.jsxs)(c,{spacing:2,onClick:e=>e.stopPropagation(),children:[(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>N({visible:!0,project:i}),disabled:!n,children:e(`common.edit`,null,`编辑`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>ce(i),disabled:!n,children:(i.status||`active`)===`archived`?e(`projects.restore`,null,`恢复`):e(`projects.archiveProject`,null,`归档`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,onClick:()=>se(i),disabled:!r,children:e(`common.delete`,null,`删除`)})]})}];return(0,X.jsxs)(`div`,{className:`project-page`,children:[(0,X.jsx)(R,{title:e(`projects.title`,null,`项目管理`),description:e(`projects.selectOrCreateHint`,null,`项目用于跨对话共享「事实黑板」:目标、环境、认证等信息会在绑定项目的对话中自动注入。`),extra:(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),theme:`borderless`,loading:B.loading,onClick:()=>B.reload(),children:e(`common.refresh`,null,`刷新`)}),(0,X.jsx)(d,{type:`primary`,icon:(0,X.jsx)(v,{}),disabled:!n,onClick:()=>N({visible:!0,project:null}),children:e(`projects.newProjectCta`,null,`+ 新建项目`)})]})}),(0,X.jsx)(te,{error:pe(B.error),onRetry:B.reload}),(0,X.jsx)(ee,{metrics:oe,columns:4}),(0,X.jsxs)(`div`,{className:`project-layout${u&&f===`graph`?` project-layout--graph`:``}`,children:[(0,X.jsxs)(I,{title:e(`projects.projectList`,null,`项目列表`),className:`project-list-card`,bodyClassName:`project-list-body`,extra:(0,X.jsxs)(qe,{type:`tertiary`,size:`small`,children:[K.length,` / `,W.length]}),children:[(0,X.jsxs)(`div`,{className:`project-toolbar project-toolbar--stack`,children:[(0,X.jsx)(p,{prefix:(0,X.jsx)(x,{}),value:m,showClear:!0,placeholder:e(`projects.searchProjectsPlaceholder`,null,`搜索项目…`),onChange:e=>{h(e),S(1)},style:{width:`100%`}}),(0,X.jsx)(E,{value:_,onChange:e=>{y(e),S(1)},style:{width:`100%`},optionList:[{value:`all`,label:e(`projects.all`,null,`全部`)},{value:`active`,label:e(`projects.statusActive`,null,`进行中`)},{value:`archived`,label:e(`projects.statusArchived`,null,`已归档`)}]})]}),(0,X.jsx)(z,{columns:le,dataSource:ie,rowKey:`id`,loading:B.loading,pagination:!1,emptyText:m||W.length>0?e(`projects.noMatchingProjects`,null,`无匹配项目`):e(`projects.noProjects`,null,`暂无项目`),onRow:e=>({onClick:()=>G(e.id,f),style:{cursor:`pointer`}})}),K.length>0&&(0,X.jsx)(`div`,{className:`project-list-pagination`,children:(0,X.jsx)(T,{size:`small`,currentPage:re,pageSize:Je,total:K.length,onPageChange:S})})]}),(0,X.jsx)(`div`,{className:`project-detail-col`,children:u?(0,X.jsx)(Ke,{projectId:u,tab:f,refreshToken:P,onTabChange:e=>G(u,e),onChanged:()=>B.reload({silent:!0}),onDeleted:()=>{G(``),B.reload({silent:!0})}},u):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{title:e(`projects.selectOrCreateTitle`,null,`选择或创建项目`),extra:n?null:(0,X.jsx)(qe,{type:`tertiary`,size:`small`,children:e(`projects.writePermissionDenied`,null,`当前账号仅有只读权限,无法创建或修改项目`)}),children:(0,X.jsx)(`div`,{className:`project-empty-state`,children:(0,X.jsx)(o,{title:e(`projects.noProjectsClickCreate`,null,`暂无项目,点击下方「新建项目」`),description:e(`projects.selectOrCreateHint`,null,`项目用于跨对话共享「事实黑板」:目标、环境、认证等信息会在绑定项目的对话中自动注入。`),style:{padding:24},children:(0,X.jsx)(d,{type:`primary`,disabled:!n,onClick:()=>N({visible:!0,project:null}),children:e(`projects.createFirstProject`,null,`创建第一个项目`)})})})}),(0,X.jsx)(I,{title:e(`projects.sharedFactBoard`,null,`共享事实黑板`),description:e(`projects.factToolbarHint`,null,`索引仅含 key 与摘要;攻击链 / POC 写在 body,Agent 通过 get_project_fact 复现`),children:(ne?.recent_facts||[]).length?(0,X.jsx)(`ul`,{className:`project-recent-facts`,children:ne.recent_facts.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`project-recent-fact`,onClick:()=>G(e.project_id,`facts`),children:[(0,X.jsxs)(`span`,{className:`project-recent-fact-key`,children:[(0,X.jsx)(`code`,{children:e.fact_key}),(0,X.jsx)(l,{size:`small`,color:`cyan`,type:`light`,children:e.project_name||e.project_id})]}),(0,X.jsx)(`span`,{className:`project-recent-fact-summary`,title:e.summary,children:e.summary}),(0,X.jsx)(`span`,{className:`project-recent-fact-time`,children:D(e.updated_at)})]})},e.id))}):(0,X.jsx)(qe,{type:`tertiary`,children:e(`projects.noFacts`,null,`暂无事实`)})})]})})]}),(0,X.jsx)(U,{visible:C.visible,project:C.project,onCancel:()=>N({visible:!1,project:null}),onSaved:e=>{let t=!!C.project;N({visible:!1,project:null}),B.reload({silent:!0}),F(e=>e+1),e?.id&&!t&&G(e.id,`facts`)}})]})}export{Xe as default};
\ No newline at end of file
+}`,onChange:e=>g({scope_json:e})}),(0,X.jsx)(Q,{type:`tertiary`,size:`small`,children:o(`projects.scopeStructuredHint`,null,`范围、排除项和操作约束保存在同一份 JSON。新增目标需明确授权。`)}),!v||!x?(0,X.jsx)(Q,{type:`warning`,size:`small`,children:o(`projects.scopeStructuredInvalid`,null,`请在 JSON 中修正范围对象和操作约束列表。`)}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.scopeConstraints`,null,`操作约束`)}),y.map((e,n)=>(0,X.jsxs)(c,{wrap:!0,children:[(0,X.jsx)(Q,{size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-constraint-${n}`,children:o(`projects.constraintKind`,null,`约束类型`)})}),(0,X.jsx)(b,{type:`button`,"aria-labelledby":`${s}-constraint-${n}`,disabled:!t,value:e.kind,onChange:e=>w(n,{kind:e.target.value}),children:D.map(({value:e,label:t})=>(0,X.jsx)(S,{value:e,children:t},e))}),(0,X.jsx)(p,{"aria-label":o(`projects.constraintText`,null,`约束内容`),value:typeof e.text==`string`?e.text:``,disabled:!t,onChange:e=>w(n,{text:e})}),(0,X.jsx)(Q,{size:`small`,children:e.origin===`goals`?o(`projects.constraintGoals`,null,`目标建议,待人工确认`):o(`projects.constraintHuman`,null,`人工`)}),(0,X.jsx)(d,{size:`small`,disabled:!t,onClick:()=>C({constraints:y.filter((e,t)=>t!==n)}),children:o(`common.delete`,null,`删除`)})]},n)),(0,X.jsx)(d,{size:`small`,disabled:!t,onClick:()=>C({constraints:[...y,{kind:`deny`,text:``,origin:`human`}]}),children:o(`projects.addScopeConstraint`,null,`添加约束`)})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-noise`,children:o(`projects.noiseProfile`,null,`噪音档位`)})}),(0,X.jsx)(b,{type:`button`,"aria-labelledby":`${s}-noise`,disabled:!t,value:v.noise_profile||`off`,onChange:e=>C({noise_profile:e.target.value}),children:T.map(({value:e,label:t})=>(0,X.jsx)(S,{value:e,children:t},e))})]})]})]}),(0,X.jsxs)(`div`,{className:`project-switch-row`,children:[(0,X.jsx)(_,{"aria-labelledby":`${s}-lessons`,checked:l.lessons_mode===`shadow`||l.lessons_mode===`inject`,disabled:!t,onChange:e=>g({lessons_mode:e?`shadow`:`off`})}),(0,X.jsx)(Q,{size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-lessons`,children:o(`projects.lessonsMode`,null,`处置经验影子审计`)})}),l.lessons_mode===`shadow`||l.lessons_mode===`inject`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_,{"aria-labelledby":`${s}-lessons-inject`,checked:l.lessons_mode===`inject`,disabled:!t,onChange:e=>g({lessons_mode:e?`inject`:`shadow`})}),(0,X.jsx)(Q,{size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-lessons-inject`,children:o(`projects.lessonsInject`,null,`注入活跃经验到上下文`)})})]}):null]}),(0,X.jsx)(a,{margin:`12px`}),(0,X.jsxs)(`div`,{className:`project-danger-zone`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(Q,{strong:!0,children:o(`projects.dangerZoneTitle`,null,`危险操作`)}),(0,X.jsx)(`div`,{children:(0,X.jsx)(Q,{type:`tertiary`,size:`small`,children:o(`projects.dangerZoneHint`,null,`在项目列表选择「已归档」可查看归档项目。删除项目会永久删除项目记忆。`)})})]}),(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{disabled:!t,onClick:()=>{H({title:N?o(`projects.restoreProjectActive`,null,`恢复为进行中`):o(`projects.archiveProject`,null,`归档`),content:N?o(`projects.confirmRestoreProjectActive`,null,`恢复后,项目记忆与随项目归档的漏洞将重新启用。单独归档的漏洞仍保留在归档列表。`):o(`projects.confirmArchiveProject`,null,`项目记忆和关联漏洞将随项目归档,可从已归档项目中查阅。是否继续?`),okText:o(`common.confirm`,null,`确认`),danger:!N,onOk:async()=>{try{await A.put(`/projects/${e.id}`,{status:N?`active`:`archived`}),V(o(`projects.saved`,null,`已保存`)),r?.()}catch(e){M(Y(e,o(`projects.operationFailed`,null,`操作失败`)))}}})},children:N?o(`projects.restoreProjectActive`,null,`恢复为进行中`):o(`projects.archiveProject`,null,`归档`)}),(0,X.jsx)(d,{type:`danger`,disabled:!n,onClick:()=>{H({title:o(`projects.deleteProject`,null,`删除项目`),content:o(`projects.confirmDeleteProject`,null,`确定删除该项目?事实将一并删除,对话将解除绑定。`),okText:o(`common.delete`,null,`删除`),onOk:async()=>{try{await A.del(`/projects/${e.id}`),V(o(`projects.deleteProject`,null,`删除项目`)),i?.(e.id)}catch(e){M(Y(e,o(`projects.deleteFailed`,null,`删除失败`)))}}})},children:o(`projects.deleteProject`,null,`删除项目`)})]})]})]}):(0,X.jsx)(I,{title:o(`projects.tabSettings`,null,`设置`),children:(0,X.jsx)(Q,{type:`tertiary`,children:o(`projects.selectOrCreateTitle`,null,`选择或创建项目`)})})}var{Text:$}=s,Le={fact_key:``,category:`note`,summary:``,body:``,confidence:`tentative`,pinned:!1,related_vulnerability_id:``,confirmation_note:``,links_text:``};function Re({visible:e,projectId:t,factKey:n,onCancel:r,onSaved:i}){let a=O(),[o,s]=(0,q.useState)(Le),[c,l]=(0,q.useState)(oe),[d,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(``),y=!!n;(0,q.useEffect)(()=>{if(!e||(s(Le),l(oe),v(``),m(!1),g(!1),!n))return;let r=!1;return m(!0),A.get(`/projects/${t}/facts`,{fact_key:n,include_links:`true`}).then(e=>{if(r||!e)return;let t=e.category||`note`;oe.some(e=>e.value===t)||l([...oe,{value:t,label:`${t}(自定义)`}]),v(e.id||``),s({fact_key:e.fact_key||n,category:t,summary:e.summary||``,body:e.body||``,confidence:(e.confidence||`tentative`).toLowerCase(),pinned:!!e.pinned,related_vulnerability_id:e.related_vulnerability_id||``,confirmation_note:e.confirmation_note||``,links_text:me(e.incoming_links)})}).catch(e=>{r||M(Y(e,a(`projects.loadFactFailed`,null,`加载事实失败`)))}).finally(()=>{r||m(!1)}),()=>{r=!0}},[e,t,n]);let b=e=>s(t=>({...t,...e})),x=(0,q.useMemo)(()=>fe.join(`、`),[]);return(0,X.jsxs)(N,{visible:e,title:y?a(`projects.editFact`,null,`编辑事实`):a(`projects.addFact`,null,`添加事实`),onCancel:r,onOk:async()=>{let e=o.fact_key.trim(),n=o.summary.trim(),r=o.confirmation_note.trim();if(!e||!n){M(a(`projects.factKeySummaryRequired`,null,`fact_key 与 summary 必填`));return}if((o.confidence||`tentative`)===`confirmed`&&!r){M(a(`projects.confirmationNoteRequired`,null,`升级为已确认需要审核说明`));return}let s={fact_key:e,category:o.category||`note`,summary:n,body:o.body,confidence:o.confidence||`tentative`,pinned:!!o.pinned,related_vulnerability_id:o.related_vulnerability_id.trim(),confirmation_note:r,links_text:o.links_text};if(y&&!_)M(a(`projects.loadFactFailed`,null,`加载事实失败`));else{g(!0);try{y&&_?await A.put(`/projects/${t}/facts/${_}`,s):await A.post(`/projects/${t}/facts`,s),V(a(`projects.saved`,null,`已保存`)),i?.()}catch(e){M(Y(e,a(`projects.saveFailed`,null,`保存失败`)))}finally{g(!1)}}},okText:y?a(`projects.saveChanges`,null,`保存修改`):a(`projects.saveFact`,null,`保存事实`),cancelText:a(`common.cancel`,null,`取消`),confirmLoading:h,width:720,maskClosable:!1,children:[(0,X.jsx)($,{type:`tertiary`,size:`small`,children:a(`projects.factModalSubtitle`,null,`摘要注入黑板索引;body 沉淀攻击链与 POC,供审计复现(与漏洞记录分工)`)}),(0,X.jsxs)(`div`,{className:`project-form-grid`,children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:`fact_key`}),(0,X.jsx)(p,{value:o.fact_key,disabled:d,placeholder:`target/primary_domain`,onChange:e=>b({fact_key:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.category`,null,`分类`)}),(0,X.jsx)(E,{value:o.category,optionList:c,onChange:e=>b({category:e}),style:{width:`100%`}})]})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.summary`,null,`摘要`)}),(0,X.jsx)(p,{value:o.summary,placeholder:a(`projects.summary`,null,`摘要`)+`:什么 + 在哪 + 如何验证`,onChange:e=>b({summary:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-grid`,children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.confidence`,null,`置信度`)}),(0,X.jsx)(E,{value:o.confidence,optionList:ce,onChange:e=>b({confidence:e}),style:{width:`100%`}})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.relatedVulnIdLabel`,null,`关联漏洞 ID`)}),(0,X.jsx)(p,{value:o.related_vulnerability_id,placeholder:a(`projects.optional`,null,`可选`),onChange:e=>b({related_vulnerability_id:e})})]})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.confirmationNote`,null,`审核说明`)}),(0,X.jsx)(f,{value:o.confirmation_note,rows:3,disabled:o.confidence!==`confirmed`,placeholder:a(`projects.confirmationNotePlaceholder`,null,`说明为何把这条事实标为已确认`),onChange:e=>b({confirmation_note:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:`body`}),(0,X.jsx)(f,{value:o.body,rows:10,placeholder:"## 验证步骤\n1. …\n\n```http\nGET /path HTTP/1.1\n```",onChange:e=>b({body:e})}),(0,X.jsx)($,{type:`tertiary`,size:`small`,children:a(`projects.factBodyRelationsHint`,null,`正文中的 discovered_on 等关系请填写到下方“关系边”字段,才能生成图谱连线。`)})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.factLinksLabel`,null,`关系边(from → 本事实)`)}),(0,X.jsx)(f,{value:o.links_text,rows:3,placeholder:a(`projects.factLinksPlaceholder`,null,`discovered_on: target/primary_domain`),onChange:e=>b({links_text:e})}),(0,X.jsxs)($,{type:`tertiary`,size:`small`,children:[a(`projects.factLinksHint`,null,`每行一条:type: source_fact_key(来源 → 当前事实)。`),` `,`常用 type:`,x,`。`]})]}),(0,X.jsx)(u,{checked:o.pinned,onChange:e=>b({pinned:e.target.checked}),children:a(`projects.pinFact`,null,`置顶事实(列表与黑板索引优先)`)})]})}var{Text:ze,Paragraph:Be}=s;function Ve({value:e}){let t=le[String(e||``).toLowerCase()]||{label:e||`—`,color:`grey`};return(0,X.jsx)(l,{size:`small`,color:t.color,children:t.label})}function He({projectId:e,factKey:t,visible:n,canWrite:r,revision:i=0,onClose:a,onEdit:s}){let u=O(),f=j(()=>t?A.get(`/projects/${e}/facts`,{fact_key:t,include_links:`true`}):Promise.resolve(null),[e,t,i]),p=f.data;return(0,X.jsxs)(C,{visible:n,width:640,title:u(`projects.factDetails`,null,`事实详情`),onCancel:a,footer:(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{disabled:!r||!p,onClick:()=>s?.(t),children:u(`common.edit`,null,`编辑`)}),(0,X.jsx)(d,{onClick:a,children:u(`common.close`,null,`关闭`)})]}),children:[(0,X.jsx)(te,{error:pe(f.error),onRetry:f.reload}),p?(0,X.jsxs)(`div`,{className:`project-detail-stack`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:p.fact_key}),(0,X.jsxs)(`div`,{className:`project-graph-side-tags`,children:[(0,X.jsx)(l,{size:`small`,color:`cyan`,type:`light`,children:se[String(p.category||``).toLowerCase()]||p.category||`—`}),(0,X.jsx)(Ve,{value:p.confidence}),p.pinned?(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:u(`projects.pinned`,null,`置顶`)}):null]})]}),(0,X.jsx)(P,{items:[{label:u(`projects.updated`,null,`更新`),value:D(p.updated_at)},{label:u(`projects.confidence`,null,`置信度`),value:(0,X.jsx)(Ve,{value:p.confidence})},p.related_vulnerability_id?{label:u(`projects.relatedVulnIdTitle`,null,`关联漏洞 ID`),value:p.related_vulnerability_id}:null,p.confirmation_note?{label:u(`projects.confirmationNote`,null,`审核说明`),value:p.confirmation_note}:null,p.source_conversation_id?{label:u(`projects.factMetaSourceConversation`,{value:``},`来源对话`),value:p.source_conversation_id}:null]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:u(`projects.summary`,null,`摘要`)}),(0,X.jsx)(Be,{className:`project-fact-summary`,children:p.summary||`—`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:`body`}),p.body?(0,X.jsx)(F,{content:p.body}):(0,X.jsx)(ze,{type:`tertiary`,children:u(`projects.emptyBody`,null,`(无 body)`)})]}),(p.incoming_links||[]).length>0&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:u(`projects.factIncomingLinksLabel`,null,`入边(只读)`)}),(0,X.jsx)(`ul`,{className:`project-link-list`,children:p.incoming_links.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`code`,{children:e.edge_type}),` ← `,(0,X.jsx)(`code`,{children:e.source_fact_key})]},e.id))})]}),(p.outgoing_links||[]).length>0&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:u(`projects.graphEdgeFromSelf`,null,`本节点指出`)}),(0,X.jsx)(`ul`,{className:`project-link-list`,children:p.outgoing_links.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`code`,{children:e.edge_type}),` → `,(0,X.jsx)(`code`,{children:e.target_fact_key})]},e.id))})]})]}):!f.loading&&!f.error?(0,X.jsx)(o,{title:u(`projects.noFacts`,null,`暂无事实`)}):null]})}var{Title:Ue,Text:We,Paragraph:Ge}=s;function Ke({projectId:e,tab:t,refreshToken:r=0,onTabChange:i,onChanged:a,onDeleted:o}){let s=O(),u=n(),{hasPermission:f}=k(),p=f(`project:write`),m=f(`project:delete`),[h,_]=(0,q.useState)(0),[v,y]=(0,q.useState)({visible:!1,factKey:``}),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(``),T=j(()=>A.get(`/projects/${e}`),[e,h,r]),E=j(()=>A.get(`/projects/${e}/stats`),[e,h,r]),M=(0,q.useCallback)(()=>{_(e=>e+1),a?.()},[a]),N=(0,q.useCallback)(e=>y({visible:!0,factKey:e||``}),[]),P=(0,q.useCallback)(e=>C(e||``),[]),F=(0,q.useMemo)(()=>[{itemKey:`facts`,tab:s(`projects.tabFacts`,null,`事实黑板`)},{itemKey:`graph`,tab:s(`projects.tabGraph`,null,`攻击路径`)},{itemKey:`conversations`,tab:s(`projects.tabConversations`,null,`关联对话`)},{itemKey:`settings`,tab:s(`projects.tabSettings`,null,`设置`)}],[s]),L=[{id:`facts`,label:s(`projects.facts`,null,`事实`),value:E.data?.fact_count??`—`,loading:E.loading},{id:`vulns`,label:s(`projects.vulnerabilityManagement`,null,`漏洞`),value:E.data?.vuln_count??`—`,loading:E.loading},{id:`conversations`,label:s(`projects.tabConversations`,null,`关联对话`),value:E.data?.conversation_count??`—`,loading:E.loading},{id:`sparse`,label:s(`projects.factBodySparse`,null,`待补全`),value:E.data?.sparse_fact_count??`—`,tone:(E.data?.sparse_fact_count||0)>0?`warning`:void 0,loading:E.loading}],R=T.data,z=R?.status===`archived`;return(0,X.jsxs)(`div`,{className:`project-detail`,children:[(0,X.jsxs)(`div`,{className:`project-detail-summary`,children:[(0,X.jsx)(te,{error:pe(T.error),onRetry:T.reload}),(0,X.jsxs)(I,{className:`project-detail-head`,children:[(0,X.jsxs)(`div`,{className:`project-detail-head-main`,children:[(0,X.jsxs)(`div`,{className:`project-detail-title-row`,children:[(0,X.jsx)(Ue,{heading:4,className:`project-detail-title`,children:R?.name||s(`projects.projectNotFound`,null,`项目不存在`)}),R?.pinned?(0,X.jsx)(l,{size:`small`,color:`blue`,children:s(`projects.pinned`,null,`置顶`)}):null,(0,X.jsx)(l,{size:`small`,color:z?`grey`:`green`,children:z?s(`projects.statusArchived`,null,`已归档`):s(`projects.statusActive`,null,`进行中`)})]}),R?.description?(0,X.jsx)(Ge,{className:`project-detail-desc`,children:R.description}):(0,X.jsx)(We,{type:`tertiary`,size:`small`,children:s(`projects.noProjectDescription`,null,`暂无项目描述`)}),(0,X.jsxs)(We,{type:`tertiary`,size:`small`,children:[s(`projects.updatedPrefix`,{time:D(R?.updated_at)},`更新于 ${D(R?.updated_at)}`),` · `,`ID: `,(0,X.jsx)(`code`,{children:e})]})]}),(0,X.jsxs)(c,{wrap:!0,children:[R&&f(`vulnerability:read`)&&(0,X.jsx)(d,{onClick:()=>u(`/vulnerabilities?project_id=${encodeURIComponent(e)}&archived=${z?`true`:`all`}`),children:s(`projects.projectVulnerabilities`,null,`项目漏洞`)}),R&&f(`asset:write`)&&(0,X.jsx)(d,{onClick:()=>x(!0),children:s(`assets.addAsset`,null,`新增资产`)}),R&&f(`asset:read`)&&(0,X.jsx)(d,{onClick:()=>u(`/asset-library?project_id=${encodeURIComponent(e)}`),children:s(`assets.projectAssets`,null,`项目资产`)}),(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),theme:`borderless`,loading:T.loading||E.loading,onClick:()=>{T.reload(),E.reload()}}),(0,X.jsx)(d,{type:`primary`,disabled:!p,onClick:()=>N(``),children:s(`projects.addFactCta`,null,`+ 添加事实`)})]})]}),(0,X.jsx)(ee,{metrics:L,columns:4}),(0,X.jsx)(g,{type:`line`,tabList:F,activeKey:t||`facts`,onChange:e=>i?.(e),className:`project-tabs`})]}),(!t||t===`facts`)&&(0,X.jsx)(_e,{projectId:e,canWrite:p,revision:h,onAddFact:()=>N(``),onEditFact:N,onViewFact:P,onMutated:M}),t===`graph`&&(0,X.jsx)(je,{projectId:e,canWrite:p,revision:h,onOpenFact:P,onEditFact:N,onAddFact:()=>N(``),onChanged:M}),t===`conversations`&&(0,X.jsx)(Ne,{projectId:e,canWrite:p,onChanged:M}),t===`settings`&&(0,X.jsx)(Ie,{project:R,canWrite:p,canDelete:m,onChanged:M,onDeleted:e=>o?.(e)}),b&&R&&f(`asset:write`)&&(0,X.jsx)(ae,{visible:!0,defaultProjectId:e,fixedProject:!0,projects:[R],onClose:()=>x(!1)}),(0,X.jsx)(Re,{visible:v.visible,projectId:e,factKey:v.factKey,onCancel:()=>y({visible:!1,factKey:``}),onSaved:()=>{y({visible:!1,factKey:``}),M()}}),(0,X.jsx)(He,{projectId:e,factKey:S,visible:!!S,canWrite:p,revision:h,onClose:()=>C(``),onEdit:e=>{C(``),N(e)}})]})}var{Text:qe}=s,Je=10;async function Ye(){let[e,t]=await Promise.all([A.get(`/projects`,{limit:500}),A.get(`/projects/dashboard-summary`,{fact_limit:6}).catch(()=>null)]);return{projects:Array.isArray(e?.projects)?e.projects:[],total:e?.total??0,summary:t}}function Xe(){let e=O(),{hasPermission:t}=k(),n=t(`project:write`),r=t(`project:delete`),[a,s]=i(),u=a.get(`id`)||``,f=a.get(`tab`)||`facts`,[m,h]=(0,q.useState)(``),g=L(m,250),[_,y]=(0,q.useState)(`active`),[b,S]=(0,q.useState)(1),[C,N]=(0,q.useState)({visible:!1,project:null}),[P,F]=(0,q.useState)(0),B=j(Ye,[]),W=B.data?.projects||[],ne=B.data?.summary,G=(0,q.useCallback)((e,t)=>{let n=new URLSearchParams(a);e?n.set(`id`,e):n.delete(`id`),t?n.set(`tab`,t):n.delete(`tab`),s(n,{replace:!!e})},[a,s]),K=(0,q.useMemo)(()=>{let e=g.trim().toLowerCase();return W.filter(t=>{let n=t.status||`active`;return _!==`all`&&n!==_?!1:!e||[t.name,t.description,t.id].join(` `).toLowerCase().includes(e)})},[W,g,_]),re=Math.min(b,Math.max(1,Math.ceil(K.length/Je))),ie=K.slice((re-1)*Je,re*Je);(0,q.useEffect)(()=>{!u&&K.length&&G(K[0].id,f)},[u,K,f,G]);let ae=(0,q.useMemo)(()=>W.filter(e=>(e.status||`active`)===`archived`).length,[W]),oe=[{id:`active`,label:e(`projects.statusActive`,null,`进行中`),value:ne?.totals?.active_projects??W.filter(e=>(e.status||`active`)===`active`).length,loading:B.loading},{id:`facts`,label:e(`projects.facts`,null,`事实`),value:ne?.totals?.total_facts??`—`,detail:e(`projects.sharedFactBoard`,null,`共享事实黑板`),loading:B.loading},{id:`total`,label:e(`projects.projectList`,null,`项目列表`),value:B.data?.total??W.length,loading:B.loading},{id:`archived`,label:e(`projects.statusArchived`,null,`已归档`),value:ae,loading:B.loading}],se=t=>{H({title:e(`projects.deleteProject`,null,`删除项目`),content:e(`projects.confirmDeleteProject`,null,`确定删除该项目?事实将一并删除,对话将解除绑定。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await A.del(`/projects/${t.id}`),V(e(`projects.deleteProject`,null,`删除项目`)),u===t.id&&G(``),B.reload({silent:!0}),F(e=>e+1)}catch(t){M(Y(t,e(`projects.deleteFailed`,null,`删除失败`)))}}})},ce=t=>{let n=(t.status||`active`)===`archived`;H({title:n?e(`projects.restoreProjectActive`,null,`恢复为进行中`):e(`projects.archiveProject`,null,`归档`),content:n?e(`projects.confirmRestoreProjectActive`,null,`恢复后,项目记忆与随项目归档的漏洞将重新启用。单独归档的漏洞仍保留在归档列表。`):e(`projects.confirmArchiveProject`,null,`项目记忆和关联漏洞将随项目归档,可从已归档项目中查阅。是否继续?`),okText:e(`common.confirm`,null,`确认`),danger:!n,onOk:async()=>{try{await A.put(`/projects/${t.id}`,{status:n?`active`:`archived`}),V(e(`projects.saved`,null,`已保存`)),B.reload({silent:!0}),F(e=>e+1)}catch(t){M(Y(t,e(`projects.operationFailed`,null,`操作失败`)))}}})},le=[{title:e(`projects.projectName`,null,`项目名称`),dataIndex:`name`,render:(t,n)=>(0,X.jsxs)(`div`,{className:`project-list-name`,children:[(0,X.jsxs)(`div`,{className:`project-list-name-row`,children:[(0,X.jsx)(`span`,{className:`project-list-name-text${n.id===u?` is-active`:``}`,children:t||n.id}),n.pinned?(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:e(`projects.pinned`,null,`置顶`)}):null]}),n.description?(0,X.jsx)(qe,{type:`tertiary`,size:`small`,className:`project-list-desc`,children:n.description}):null]})},{title:e(`projects.status`,null,`状态`),dataIndex:`status`,width:92,render:t=>{let n=(t||`active`)===`archived`;return(0,X.jsx)(l,{size:`small`,color:n?`grey`:`green`,children:n?e(`projects.statusArchived`,null,`已归档`):e(`projects.statusActive`,null,`进行中`)})}},{title:e(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:150,render:e=>(0,X.jsx)(qe,{type:`tertiary`,size:`small`,children:D(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:176,render:(t,i)=>(0,X.jsxs)(c,{spacing:2,onClick:e=>e.stopPropagation(),children:[(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>N({visible:!0,project:i}),disabled:!n,children:e(`common.edit`,null,`编辑`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>ce(i),disabled:!n,children:(i.status||`active`)===`archived`?e(`projects.restore`,null,`恢复`):e(`projects.archiveProject`,null,`归档`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,onClick:()=>se(i),disabled:!r,children:e(`common.delete`,null,`删除`)})]})}];return(0,X.jsxs)(`div`,{className:`project-page`,children:[(0,X.jsx)(R,{title:e(`projects.title`,null,`项目管理`),description:e(`projects.selectOrCreateHint`,null,`项目用于跨对话共享「事实黑板」:目标、环境、认证等信息会在绑定项目的对话中自动注入。`),extra:(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),theme:`borderless`,loading:B.loading,onClick:()=>B.reload(),children:e(`common.refresh`,null,`刷新`)}),(0,X.jsx)(d,{type:`primary`,icon:(0,X.jsx)(v,{}),disabled:!n,onClick:()=>N({visible:!0,project:null}),children:e(`projects.newProjectCta`,null,`+ 新建项目`)})]})}),(0,X.jsx)(te,{error:pe(B.error),onRetry:B.reload}),(0,X.jsx)(ee,{metrics:oe,columns:4}),(0,X.jsxs)(`div`,{className:`project-layout${u&&f===`graph`?` project-layout--graph`:``}`,children:[(0,X.jsxs)(I,{title:e(`projects.projectList`,null,`项目列表`),className:`project-list-card`,bodyClassName:`project-list-body`,extra:(0,X.jsxs)(qe,{type:`tertiary`,size:`small`,children:[K.length,` / `,W.length]}),children:[(0,X.jsxs)(`div`,{className:`project-toolbar project-toolbar--stack`,children:[(0,X.jsx)(p,{prefix:(0,X.jsx)(x,{}),value:m,showClear:!0,placeholder:e(`projects.searchProjectsPlaceholder`,null,`搜索项目…`),onChange:e=>{h(e),S(1)},style:{width:`100%`}}),(0,X.jsx)(E,{value:_,onChange:e=>{y(e),S(1)},style:{width:`100%`},optionList:[{value:`all`,label:e(`projects.all`,null,`全部`)},{value:`active`,label:e(`projects.statusActive`,null,`进行中`)},{value:`archived`,label:e(`projects.statusArchived`,null,`已归档`)}]})]}),(0,X.jsx)(z,{columns:le,dataSource:ie,rowKey:`id`,loading:B.loading,pagination:!1,emptyText:m||W.length>0?e(`projects.noMatchingProjects`,null,`无匹配项目`):e(`projects.noProjects`,null,`暂无项目`),onRow:e=>({onClick:()=>G(e.id,f),style:{cursor:`pointer`}})}),K.length>0&&(0,X.jsx)(`div`,{className:`project-list-pagination`,children:(0,X.jsx)(T,{size:`small`,currentPage:re,pageSize:Je,total:K.length,onPageChange:S})})]}),(0,X.jsx)(`div`,{className:`project-detail-col`,children:u?(0,X.jsx)(Ke,{projectId:u,tab:f,refreshToken:P,onTabChange:e=>G(u,e),onChanged:()=>B.reload({silent:!0}),onDeleted:()=>{G(``),B.reload({silent:!0})}},u):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{title:e(`projects.selectOrCreateTitle`,null,`选择或创建项目`),extra:n?null:(0,X.jsx)(qe,{type:`tertiary`,size:`small`,children:e(`projects.writePermissionDenied`,null,`当前账号仅有只读权限,无法创建或修改项目`)}),children:(0,X.jsx)(`div`,{className:`project-empty-state`,children:(0,X.jsx)(o,{title:e(`projects.noProjectsClickCreate`,null,`暂无项目,点击下方「新建项目」`),description:e(`projects.selectOrCreateHint`,null,`项目用于跨对话共享「事实黑板」:目标、环境、认证等信息会在绑定项目的对话中自动注入。`),style:{padding:24},children:(0,X.jsx)(d,{type:`primary`,disabled:!n,onClick:()=>N({visible:!0,project:null}),children:e(`projects.createFirstProject`,null,`创建第一个项目`)})})})}),(0,X.jsx)(I,{title:e(`projects.sharedFactBoard`,null,`共享事实黑板`),description:e(`projects.factToolbarHint`,null,`索引仅含 key 与摘要;攻击链 / POC 写在 body,Agent 通过 get_project_fact 复现`),children:(ne?.recent_facts||[]).length?(0,X.jsx)(`ul`,{className:`project-recent-facts`,children:ne.recent_facts.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`project-recent-fact`,onClick:()=>G(e.project_id,`facts`),children:[(0,X.jsxs)(`span`,{className:`project-recent-fact-key`,children:[(0,X.jsx)(`code`,{children:e.fact_key}),(0,X.jsx)(l,{size:`small`,color:`cyan`,type:`light`,children:e.project_name||e.project_id})]}),(0,X.jsx)(`span`,{className:`project-recent-fact-summary`,title:e.summary,children:e.summary}),(0,X.jsx)(`span`,{className:`project-recent-fact-time`,children:D(e.updated_at)})]})},e.id))}):(0,X.jsx)(qe,{type:`tertiary`,children:e(`projects.noFacts`,null,`暂无事实`)})})]})})]}),(0,X.jsx)(U,{visible:C.visible,project:C.project,onCancel:()=>N({visible:!1,project:null}),onSaved:e=>{let t=!!C.project;N({visible:!1,project:null}),B.reload({silent:!0}),F(e=>e+1),e?.id&&!t&&G(e.id,`facts`)}})]})}export{Xe as default};
\ No newline at end of file
diff --git a/web/static/app/assets/roles-management-Dj76kdoF.js b/web/static/app/assets/roles-management-Cc2pBLLE.js
similarity index 91%
rename from web/static/app/assets/roles-management-Dj76kdoF.js
rename to web/static/app/assets/roles-management-Cc2pBLLE.js
index 5682f18f..c45037df 100644
--- a/web/static/app/assets/roles-management-Dj76kdoF.js
+++ b/web/static/app/assets/roles-management-Cc2pBLLE.js
@@ -1 +1 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,E as i,G as a,I as o,Lt as s,N as c,P as l,Pt as u,R as d,S as f,U as p,W as m,d as h,ft as g,h as ee,lt as te,m as _,ut as v,v as ne,y as re}from"./semi-65W_4I1v.js";import{F as ie,I as y,P as b,a as x,b as ae,c as oe,l as S,m as C,n as se,p as w,s as T,x as ce,y as E}from"./index-BdnarFZR.js";var D=e(t(),1),O=e(n(),1),{Text:k}=a,A=`默认`;function j(e){if(!e||typeof e!=`string`)return``;let t=e.trim(),n=t.match(/^"?\\U([0-9A-F]{8})"?$/i);if(n)try{return String.fromCodePoint(parseInt(n[1],16))}catch{return t}return t}function M(e){return e?.is_external&&e?.external_mcp?`${e.external_mcp}::${e.name}`:e?.name||``}function N(e){if(!Array.isArray(e))return[];let t=new Set,n=[];for(let r of e){let e=String(r||``).trim();e&&!t.has(e)&&(t.add(e),n.push(e))}return n}var P=20;function F({visible:e,role:t,onCancel:n,onSaved:a}){let{hasPermission:s}=ie(),u=s(`mcp:read`)||s(`config:read`),g=s(`workflow:read`),v=!!t,b=t?.name===A,[x,S]=(0,D.useState)(``),[C,w]=(0,D.useState)(``),[T,E]=(0,D.useState)(``),[F,I]=(0,D.useState)(``),[L,R]=(0,D.useState)(``),[z,B]=(0,D.useState)(`auto`),[le,ue]=(0,D.useState)(!0),[V,H]=(0,D.useState)([]),[de,fe]=(0,D.useState)(``),[U,W]=(0,D.useState)(``),[pe,G]=(0,D.useState)(!1),[me,he]=(0,D.useState)([]),[ge,_e]=(0,D.useState)(!1),[K,ve]=(0,D.useState)(``),q=se(K,250),[J,ye]=(0,D.useState)(`all`),[Y,X]=(0,D.useState)(1),[Z,be]=(0,D.useState)([]),[Q,xe]=(0,D.useState)(0),[Se,Ce]=(0,D.useState)(!1),[we,Te]=(0,D.useState)(null);(0,D.useEffect)(()=>{if(!e)return;S(t?.name||``),w(j(t?.icon)),E(t?.description||``),I(t?.user_prompt||``),R(t?.workflow_id||``),B(t?.workflow_policy||`auto`),ue(!t||t.enabled!==!1);let n=N(t?.tools);H(n),fe(n.join(`, `)),W(``),ve(``),ye(`all`),X(1)},[e,t]),(0,D.useEffect)(()=>{if(!e||!g)return;let t=!1;return _e(!0),y.get(`/workflows`,{includeDisabled:`true`}).then(e=>{t||he(Array.isArray(e?.workflows)?e.workflows:[])}).catch(()=>{t||he([])}).finally(()=>{t||_e(!1)}),()=>{t=!0}},[e,g]),(0,D.useEffect)(()=>{X(1)},[q]),(0,D.useEffect)(()=>{if(!e||b||!u||J!==`all`)return;let t=!1;return Ce(!0),Te(null),y.get(`/config/tools`,{page:Y,page_size:P,search:q.trim()||void 0}).then(e=>{t||(be(Array.isArray(e?.tools)?e.tools:[]),xe(Number(e?.total)||0))}).catch(e=>{t||(Te(e),be([]),xe(0))}).finally(()=>{t||Ce(!1)}),()=>{t=!0}},[e,b,u,J,Y,q]);let Ee=(0,D.useMemo)(()=>new Set(V),[V]),De=(0,D.useMemo)(()=>{let e=K.trim().toLowerCase();return e?V.filter(t=>t.toLowerCase().includes(e)):V},[V,K]),Oe=(0,D.useMemo)(()=>{let e=me.map(e=>({value:e.id,label:e.name?`${e.name} (${e.id})`:e.id}));return L&&!e.some(e=>e.value===L)&&e.unshift({value:L,label:L}),e},[me,L]),$=e=>{e&&H(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},ke=()=>{let e=Z.map(M).filter(Boolean);H(t=>N([...t,...e]))},Ae=()=>{let e=new Set(Z.map(M).filter(Boolean));H(t=>t.filter(t=>!e.has(t)))},je=async()=>{let e=x.trim();if(!e)W(`请输入角色名称`);else{W(``),G(!0);try{let n=b?[]:u?V:N(de.split(`,`)),r=String(L||``).trim(),i={name:b?A:e,description:T.trim(),user_prompt:F,icon:C.trim(),tools:n,enabled:!!le};r&&(i.workflow_id=r,i.workflow_policy=z||`auto`,t?.workflow_id===r&&t?.workflow_version&&(i.workflow_version=t.workflow_version)),v?await y.put(`/roles/${encodeURIComponent(t.name)}`,i):await y.post(`/roles`,i),ce(`角色已保存`),a?.()}catch(e){ae(e,`保存角色失败`)}finally{G(!1)}}},Me=j(C)||(b?`🔵`:`👤`);return(0,O.jsx)(oe,{title:v?`编辑角色:${t.name}`:`新建角色`,visible:e,onCancel:n,onOk:je,okText:`保存`,confirmLoading:pe,width:760,children:(0,O.jsxs)(`div`,{className:`cs-role-editor-form`,children:[(0,O.jsxs)(`div`,{className:`cs-role-editor-grid`,children:[(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-name-input`,children:(0,O.jsx)(`span`,{className:`cs-role-field-required`,children:`角色名称`})}),(0,O.jsx)(p,{id:`cs-role-name-input`,value:x,onChange:e=>{S(e),U&&W(``)},disabled:b,placeholder:`例如:Web应用扫描`,validateStatus:U?`error`:`default`}),U&&(0,O.jsx)(k,{type:`danger`,size:`small`,children:U}),b&&(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`默认角色名称不可修改。`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-icon-input`,children:`角色图标`}),(0,O.jsxs)(`div`,{className:`cs-role-icon-input-row`,children:[(0,O.jsx)(`span`,{className:`cs-role-icon-badge`,"aria-hidden":`true`,children:Me}),(0,O.jsx)(p,{id:`cs-role-icon-input`,value:C,onChange:w,placeholder:`Emoji,如 🔍`})]})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-desc-input`,children:`角色描述`}),(0,O.jsx)(p,{id:`cs-role-desc-input`,value:T,onChange:E,placeholder:`简要说明该角色的职责与适用场景`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-prompt-input`,children:`用户提示词`}),(0,O.jsx)(f,{id:`cs-role-prompt-input`,value:F,onChange:I,autosize:{minRows:5,maxRows:14},placeholder:`追加到用户消息前的角色提示词(留空则不额外追加)`})]}),(0,O.jsxs)(`div`,{className:`cs-role-editor-workflow-grid`,children:[(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`绑定工作流`}),g?(0,O.jsx)(re,{value:L||void 0,onChange:e=>{let t=e||``;R(t),t&&!z&&B(`auto`)},optionList:Oe,loading:ge,filter:!0,showClear:!0,placeholder:`不绑定工作流`,style:{width:`100%`}}):(0,O.jsx)(p,{value:L,onChange:R,placeholder:`不绑定工作流(缺少 workflow:read 权限,可手动输入 ID 或留空)`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`工作流策略`}),(0,O.jsx)(re,{value:z||`auto`,onChange:e=>B(e||`auto`),disabled:!L,optionList:[{value:`auto`,label:`自动触发(默认)`},{value:`off`,label:`关闭自动触发`}],style:{width:`100%`}})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`关联工具`}),b?(0,O.jsx)(r,{type:`info`,fullMode:!1,closeIcon:null,title:`默认角色使用所有工具`,description:`默认角色会自动使用 MCP 管理中启用的所有工具,无需单独配置。`}):u?(0,O.jsxs)(`div`,{className:`cs-role-tools-panel`,children:[(0,O.jsxs)(`div`,{className:`cs-role-tools-header`,children:[(0,O.jsx)(o,{wrap:!0,children:V.length>0?(0,O.jsxs)(c,{color:`blue`,children:[`已勾选 `,V.length,` 个工具`]}):(0,O.jsx)(c,{color:`grey`,children:`未限制(默认使用全部已启用工具)`})}),V.length>0&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,onClick:()=>H([]),children:`清空(使用全部)`})]}),V.length>0&&(0,O.jsx)(`div`,{className:`cs-role-tools-selected`,"aria-label":`已勾选工具列表`,children:V.map(e=>(0,O.jsx)(c,{size:`small`,closable:!0,onClose:()=>$(e),children:e},e))}),(0,O.jsxs)(`div`,{className:`cs-role-tools-toolbar`,children:[(0,O.jsx)(p,{prefix:(0,O.jsx)(te,{}),value:K,onChange:ve,placeholder:`搜索工具名称或描述`,showClear:!0,style:{width:240}}),(0,O.jsxs)(o,{wrap:!0,children:[(0,O.jsxs)(ee,{type:`button`,buttonSize:`small`,value:J,onChange:e=>ye(e.target.value),children:[(0,O.jsx)(_,{value:`all`,children:`全部工具`}),(0,O.jsxs)(_,{value:`selected`,children:[`仅已勾选 (`,V.length,`)`]})]}),J===`all`&&Z.length>0&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(d,{size:`small`,onClick:ke,children:`全选本页`}),(0,O.jsx)(d,{size:`small`,onClick:Ae,children:`取消本页`})]})]})]}),J===`all`?(0,O.jsxs)(O.Fragment,{children:[we&&(0,O.jsx)(r,{type:`warning`,fullMode:!1,closeIcon:null,description:`加载工具列表失败,请稍后重试。`}),(0,O.jsx)(m,{spinning:Se,children:(0,O.jsx)(`div`,{className:`cs-role-tools-list`,children:Z.length===0&&!Se?(0,O.jsx)(i,{description:`没有匹配的工具`,style:{padding:24}}):Z.map(e=>{let t=M(e),n=Ee.has(t);return(0,O.jsxs)(`div`,{className:`cs-role-tool-item`,onClick:()=>$(t),children:[(0,O.jsx)(l,{checked:n,onChange:()=>{},onClick:e=>{e.stopPropagation(),$(t)},"aria-label":t}),(0,O.jsxs)(`div`,{className:`cs-role-tool-meta`,children:[(0,O.jsxs)(`div`,{className:`cs-role-tool-head`,children:[(0,O.jsx)(k,{strong:!0,size:`small`,children:e.name}),e.is_external&&e.external_mcp&&(0,O.jsx)(c,{size:`small`,color:`cyan`,children:e.external_mcp}),e.enabled===!1&&(0,O.jsx)(c,{size:`small`,color:`orange`,children:`MCP 未启用`})]}),e.description&&(0,O.jsx)(`span`,{className:`cs-role-tool-desc`,title:e.description,children:e.description})]})]},t)})})}),Q>P&&(0,O.jsxs)(`div`,{className:`cs-role-tools-footer`,children:[(0,O.jsxs)(k,{type:`tertiary`,size:`small`,children:[`共 `,Q,` 个工具`]}),(0,O.jsx)(ne,{size:`small`,total:Q,pageSize:P,currentPage:Y,onPageChange:X})]})]}):(0,O.jsx)(`div`,{className:`cs-role-tools-list`,children:De.length===0?(0,O.jsx)(i,{description:`暂无已勾选工具`,style:{padding:24}}):De.map(e=>(0,O.jsxs)(`div`,{className:`cs-role-tool-item`,onClick:()=>$(e),children:[(0,O.jsx)(l,{checked:!0,onChange:()=>{},onClick:t=>{t.stopPropagation(),$(e)},"aria-label":e}),(0,O.jsx)(`div`,{className:`cs-role-tool-meta`,children:(0,O.jsx)(k,{strong:!0,size:`small`,children:e})})]},e))}),(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`留空工具列表表示不限制(使用 MCP 管理中全部已启用工具);MCP 全局开关请在 MCP 管理中调整。`})]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(p,{value:de,onChange:fe,placeholder:`toolName, mcpName::toolName(留空表示不限制)`}),(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`当前账号缺少工具列表读取权限,可直接按逗号分隔填写工具 key。`})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-switch-row`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(k,{strong:!0,children:`启用此角色`}),(0,O.jsx)(`div`,{className:`cs-role-field-hint`,children:`停用后该角色不会出现在对话角色选择器中。`})]}),(0,O.jsx)(h,{checked:le,onChange:ue,"aria-label":`启用此角色`})]})]})})}var{Text:I}=a;function L(e){return[...e].sort((e,t)=>e?.name===`默认`&&t?.name!==`默认`?-1:t?.name===`默认`&&e?.name!==`默认`?1:String(e?.name||``).localeCompare(String(t?.name||``),`zh-CN`))}function R(){let e=b(),{hasPermission:t}=ie(),n=t(`roles:write`),r=t(`roles:delete`),[i,a]=(0,D.useState)(``),[l,f]=(0,D.useState)(null),m=x(()=>y.get(`/roles`),[]),h=(0,D.useMemo)(()=>{let e=Array.isArray(m.data?.roles)?L(m.data.roles):[];if(!i.trim())return e;let t=i.trim().toLowerCase();return e.filter(e=>[e.name,e.description,e.workflow_id].some(e=>String(e||``).toLowerCase().includes(t)))},[m.data,i]),ee=e=>E({title:`删除角色「${e.name}」?`,content:`已绑定该角色的对话将失去对应提示词与工具配置。`,onOk:async()=>{try{await y.del(`/roles/${encodeURIComponent(e.name)}`),ce(`已删除`),m.reload()}catch(e){ae(e,`删除角色失败`)}}}),_=[{title:`角色`,dataIndex:`name`,render:(e,t)=>{let n=e===A,r=j(t.icon)||(n?`🔵`:`👤`);return(0,O.jsxs)(`div`,{className:`cs-role-name-cell`,children:[(0,O.jsx)(`span`,{className:`cs-role-icon-badge`,"aria-hidden":`true`,children:r}),(0,O.jsxs)(o,{vertical:!0,spacing:0,align:`start`,children:[(0,O.jsxs)(o,{spacing:6,children:[(0,O.jsx)(I,{strong:!0,children:e}),n&&(0,O.jsx)(c,{size:`small`,color:`blue`,children:`默认`}),t.enabled===!1&&(0,O.jsx)(c,{size:`small`,color:`grey`,children:`已停用`})]}),(0,O.jsx)(I,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:460},children:t.description||`—`})]})]})}},{title:`工具`,dataIndex:`tools`,width:260,render:(e,t)=>t.name===`默认`?(0,O.jsx)(I,{type:`tertiary`,children:`全部工具`}):Array.isArray(e)&&e.length?(0,O.jsxs)(o,{wrap:!0,spacing:4,children:[e.slice(0,4).map(e=>(0,O.jsx)(c,{size:`small`,children:e},e)),e.length>4&&(0,O.jsxs)(I,{type:`tertiary`,children:[`+`,e.length-4]})]}):(0,O.jsx)(I,{type:`tertiary`,children:`全部工具`})},{title:`工作流`,dataIndex:`workflow_id`,width:180,render:(e,t)=>e?(0,O.jsxs)(o,{spacing:4,wrap:!0,children:[(0,O.jsx)(I,{children:e}),t.workflow_policy===`off`&&(0,O.jsx)(c,{size:`small`,color:`grey`,children:`关闭自动`})]}):`—`}];return(n||r)&&_.push({title:`操作`,width:150,render:(e,t)=>(0,O.jsxs)(o,{children:[n&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,icon:(0,O.jsx)(u,{}),onClick:()=>f({role:t}),children:`编辑`}),r&&t.name!==`默认`&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,O.jsx)(s,{}),"aria-label":`删除 ${t.name}`,onClick:()=>ee(t)})]})}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(w,{title:e(`roles.title`,null,`角色管理`),description:`角色定义对话的系统提示词、可用工具与绑定工作流。`,extra:(0,O.jsxs)(o,{children:[(0,O.jsx)(d,{icon:(0,O.jsx)(v,{}),onClick:()=>m.reload(),loading:m.loading,children:`刷新`}),n&&(0,O.jsx)(d,{theme:`solid`,type:`primary`,icon:(0,O.jsx)(g,{}),onClick:()=>f({role:null}),children:`新建角色`})]})}),(0,O.jsxs)(C,{title:`角色(${h.length})`,children:[(0,O.jsx)(S,{error:m.error,onRetry:()=>m.reload()}),(0,O.jsx)(T,{columns:_,dataSource:h,rowKey:`name`,loading:m.loading,pagination:{pageSize:20},toolbar:(0,O.jsx)(p,{prefix:(0,O.jsx)(te,{}),value:i,onChange:a,placeholder:`搜索角色名称`,showClear:!0,style:{width:260}})})]}),(0,O.jsx)(F,{visible:!!l,role:l?.role||null,onCancel:()=>f(null),onSaved:()=>{f(null),m.reload()}})]})}export{R as default};
\ No newline at end of file
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,E as i,G as a,I as o,Lt as s,N as c,P as l,Pt as u,R as d,S as f,U as p,W as m,d as h,ft as g,h as ee,lt as te,m as _,ut as v,v as ne,y as re}from"./semi-65W_4I1v.js";import{F as y,I as ie,L as b,a as x,b as ae,c as oe,l as S,m as C,n as se,p as w,s as T,x as ce,y as E}from"./index-_8d9XBPJ.js";var D=e(t(),1),O=e(n(),1),{Text:k}=a,A=`默认`;function j(e){if(!e||typeof e!=`string`)return``;let t=e.trim(),n=t.match(/^"?\\U([0-9A-F]{8})"?$/i);if(n)try{return String.fromCodePoint(parseInt(n[1],16))}catch{return t}return t}function M(e){return e?.is_external&&e?.external_mcp?`${e.external_mcp}::${e.name}`:e?.name||``}function N(e){if(!Array.isArray(e))return[];let t=new Set,n=[];for(let r of e){let e=String(r||``).trim();e&&!t.has(e)&&(t.add(e),n.push(e))}return n}var P=20;function F({visible:e,role:t,onCancel:n,onSaved:a}){let{hasPermission:s}=ie(),u=s(`mcp:read`)||s(`config:read`),g=s(`workflow:read`),v=!!t,y=t?.name===A,[x,S]=(0,D.useState)(``),[C,w]=(0,D.useState)(``),[T,E]=(0,D.useState)(``),[F,I]=(0,D.useState)(``),[L,R]=(0,D.useState)(``),[z,B]=(0,D.useState)(`auto`),[le,ue]=(0,D.useState)(!0),[V,H]=(0,D.useState)([]),[de,fe]=(0,D.useState)(``),[U,W]=(0,D.useState)(``),[pe,G]=(0,D.useState)(!1),[me,he]=(0,D.useState)([]),[ge,_e]=(0,D.useState)(!1),[K,ve]=(0,D.useState)(``),q=se(K,250),[J,ye]=(0,D.useState)(`all`),[Y,X]=(0,D.useState)(1),[Z,be]=(0,D.useState)([]),[Q,xe]=(0,D.useState)(0),[Se,Ce]=(0,D.useState)(!1),[we,Te]=(0,D.useState)(null);(0,D.useEffect)(()=>{if(!e)return;S(t?.name||``),w(j(t?.icon)),E(t?.description||``),I(t?.user_prompt||``),R(t?.workflow_id||``),B(t?.workflow_policy||`auto`),ue(!t||t.enabled!==!1);let n=N(t?.tools);H(n),fe(n.join(`, `)),W(``),ve(``),ye(`all`),X(1)},[e,t]),(0,D.useEffect)(()=>{if(!e||!g)return;let t=!1;return _e(!0),b.get(`/workflows`,{includeDisabled:`true`}).then(e=>{t||he(Array.isArray(e?.workflows)?e.workflows:[])}).catch(()=>{t||he([])}).finally(()=>{t||_e(!1)}),()=>{t=!0}},[e,g]),(0,D.useEffect)(()=>{X(1)},[q]),(0,D.useEffect)(()=>{if(!e||y||!u||J!==`all`)return;let t=!1;return Ce(!0),Te(null),b.get(`/config/tools`,{page:Y,page_size:P,search:q.trim()||void 0}).then(e=>{t||(be(Array.isArray(e?.tools)?e.tools:[]),xe(Number(e?.total)||0))}).catch(e=>{t||(Te(e),be([]),xe(0))}).finally(()=>{t||Ce(!1)}),()=>{t=!0}},[e,y,u,J,Y,q]);let Ee=(0,D.useMemo)(()=>new Set(V),[V]),De=(0,D.useMemo)(()=>{let e=K.trim().toLowerCase();return e?V.filter(t=>t.toLowerCase().includes(e)):V},[V,K]),Oe=(0,D.useMemo)(()=>{let e=me.map(e=>({value:e.id,label:e.name?`${e.name} (${e.id})`:e.id}));return L&&!e.some(e=>e.value===L)&&e.unshift({value:L,label:L}),e},[me,L]),$=e=>{e&&H(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},ke=()=>{let e=Z.map(M).filter(Boolean);H(t=>N([...t,...e]))},Ae=()=>{let e=new Set(Z.map(M).filter(Boolean));H(t=>t.filter(t=>!e.has(t)))},je=async()=>{let e=x.trim();if(!e)W(`请输入角色名称`);else{W(``),G(!0);try{let n=y?[]:u?V:N(de.split(`,`)),r=String(L||``).trim(),i={name:y?A:e,description:T.trim(),user_prompt:F,icon:C.trim(),tools:n,enabled:!!le};r&&(i.workflow_id=r,i.workflow_policy=z||`auto`,t?.workflow_id===r&&t?.workflow_version&&(i.workflow_version=t.workflow_version)),v?await b.put(`/roles/${encodeURIComponent(t.name)}`,i):await b.post(`/roles`,i),ce(`角色已保存`),a?.()}catch(e){ae(e,`保存角色失败`)}finally{G(!1)}}},Me=j(C)||(y?`🔵`:`👤`);return(0,O.jsx)(oe,{title:v?`编辑角色:${t.name}`:`新建角色`,visible:e,onCancel:n,onOk:je,okText:`保存`,confirmLoading:pe,width:760,children:(0,O.jsxs)(`div`,{className:`cs-role-editor-form`,children:[(0,O.jsxs)(`div`,{className:`cs-role-editor-grid`,children:[(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-name-input`,children:(0,O.jsx)(`span`,{className:`cs-role-field-required`,children:`角色名称`})}),(0,O.jsx)(p,{id:`cs-role-name-input`,value:x,onChange:e=>{S(e),U&&W(``)},disabled:y,placeholder:`例如:Web应用扫描`,validateStatus:U?`error`:`default`}),U&&(0,O.jsx)(k,{type:`danger`,size:`small`,children:U}),y&&(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`默认角色名称不可修改。`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-icon-input`,children:`角色图标`}),(0,O.jsxs)(`div`,{className:`cs-role-icon-input-row`,children:[(0,O.jsx)(`span`,{className:`cs-role-icon-badge`,"aria-hidden":`true`,children:Me}),(0,O.jsx)(p,{id:`cs-role-icon-input`,value:C,onChange:w,placeholder:`Emoji,如 🔍`})]})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-desc-input`,children:`角色描述`}),(0,O.jsx)(p,{id:`cs-role-desc-input`,value:T,onChange:E,placeholder:`简要说明该角色的职责与适用场景`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-prompt-input`,children:`用户提示词`}),(0,O.jsx)(f,{id:`cs-role-prompt-input`,value:F,onChange:I,autosize:{minRows:5,maxRows:14},placeholder:`追加到用户消息前的角色提示词(留空则不额外追加)`})]}),(0,O.jsxs)(`div`,{className:`cs-role-editor-workflow-grid`,children:[(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`绑定工作流`}),g?(0,O.jsx)(re,{value:L||void 0,onChange:e=>{let t=e||``;R(t),t&&!z&&B(`auto`)},optionList:Oe,loading:ge,filter:!0,showClear:!0,placeholder:`不绑定工作流`,style:{width:`100%`}}):(0,O.jsx)(p,{value:L,onChange:R,placeholder:`不绑定工作流(缺少 workflow:read 权限,可手动输入 ID 或留空)`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`工作流策略`}),(0,O.jsx)(re,{value:z||`auto`,onChange:e=>B(e||`auto`),disabled:!L,optionList:[{value:`auto`,label:`自动触发(默认)`},{value:`off`,label:`关闭自动触发`}],style:{width:`100%`}})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`关联工具`}),y?(0,O.jsx)(r,{type:`info`,fullMode:!1,closeIcon:null,title:`默认角色使用所有工具`,description:`默认角色会自动使用 MCP 管理中启用的所有工具,无需单独配置。`}):u?(0,O.jsxs)(`div`,{className:`cs-role-tools-panel`,children:[(0,O.jsxs)(`div`,{className:`cs-role-tools-header`,children:[(0,O.jsx)(o,{wrap:!0,children:V.length>0?(0,O.jsxs)(c,{color:`blue`,children:[`已勾选 `,V.length,` 个工具`]}):(0,O.jsx)(c,{color:`grey`,children:`未限制(默认使用全部已启用工具)`})}),V.length>0&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,onClick:()=>H([]),children:`清空(使用全部)`})]}),V.length>0&&(0,O.jsx)(`div`,{className:`cs-role-tools-selected`,"aria-label":`已勾选工具列表`,children:V.map(e=>(0,O.jsx)(c,{size:`small`,closable:!0,onClose:()=>$(e),children:e},e))}),(0,O.jsxs)(`div`,{className:`cs-role-tools-toolbar`,children:[(0,O.jsx)(p,{prefix:(0,O.jsx)(te,{}),value:K,onChange:ve,placeholder:`搜索工具名称或描述`,showClear:!0,style:{width:240}}),(0,O.jsxs)(o,{wrap:!0,children:[(0,O.jsxs)(ee,{type:`button`,buttonSize:`small`,value:J,onChange:e=>ye(e.target.value),children:[(0,O.jsx)(_,{value:`all`,children:`全部工具`}),(0,O.jsxs)(_,{value:`selected`,children:[`仅已勾选 (`,V.length,`)`]})]}),J===`all`&&Z.length>0&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(d,{size:`small`,onClick:ke,children:`全选本页`}),(0,O.jsx)(d,{size:`small`,onClick:Ae,children:`取消本页`})]})]})]}),J===`all`?(0,O.jsxs)(O.Fragment,{children:[we&&(0,O.jsx)(r,{type:`warning`,fullMode:!1,closeIcon:null,description:`加载工具列表失败,请稍后重试。`}),(0,O.jsx)(m,{spinning:Se,children:(0,O.jsx)(`div`,{className:`cs-role-tools-list`,children:Z.length===0&&!Se?(0,O.jsx)(i,{description:`没有匹配的工具`,style:{padding:24}}):Z.map(e=>{let t=M(e),n=Ee.has(t);return(0,O.jsxs)(`div`,{className:`cs-role-tool-item`,onClick:()=>$(t),children:[(0,O.jsx)(l,{checked:n,onChange:()=>{},onClick:e=>{e.stopPropagation(),$(t)},"aria-label":t}),(0,O.jsxs)(`div`,{className:`cs-role-tool-meta`,children:[(0,O.jsxs)(`div`,{className:`cs-role-tool-head`,children:[(0,O.jsx)(k,{strong:!0,size:`small`,children:e.name}),e.is_external&&e.external_mcp&&(0,O.jsx)(c,{size:`small`,color:`cyan`,children:e.external_mcp}),e.enabled===!1&&(0,O.jsx)(c,{size:`small`,color:`orange`,children:`MCP 未启用`})]}),e.description&&(0,O.jsx)(`span`,{className:`cs-role-tool-desc`,title:e.description,children:e.description})]})]},t)})})}),Q>P&&(0,O.jsxs)(`div`,{className:`cs-role-tools-footer`,children:[(0,O.jsxs)(k,{type:`tertiary`,size:`small`,children:[`共 `,Q,` 个工具`]}),(0,O.jsx)(ne,{size:`small`,total:Q,pageSize:P,currentPage:Y,onPageChange:X})]})]}):(0,O.jsx)(`div`,{className:`cs-role-tools-list`,children:De.length===0?(0,O.jsx)(i,{description:`暂无已勾选工具`,style:{padding:24}}):De.map(e=>(0,O.jsxs)(`div`,{className:`cs-role-tool-item`,onClick:()=>$(e),children:[(0,O.jsx)(l,{checked:!0,onChange:()=>{},onClick:t=>{t.stopPropagation(),$(e)},"aria-label":e}),(0,O.jsx)(`div`,{className:`cs-role-tool-meta`,children:(0,O.jsx)(k,{strong:!0,size:`small`,children:e})})]},e))}),(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`留空工具列表表示不限制(使用 MCP 管理中全部已启用工具);MCP 全局开关请在 MCP 管理中调整。`})]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(p,{value:de,onChange:fe,placeholder:`toolName, mcpName::toolName(留空表示不限制)`}),(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`当前账号缺少工具列表读取权限,可直接按逗号分隔填写工具 key。`})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-switch-row`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(k,{strong:!0,children:`启用此角色`}),(0,O.jsx)(`div`,{className:`cs-role-field-hint`,children:`停用后该角色不会出现在对话角色选择器中。`})]}),(0,O.jsx)(h,{checked:le,onChange:ue,"aria-label":`启用此角色`})]})]})})}var{Text:I}=a;function L(e){return[...e].sort((e,t)=>e?.name===`默认`&&t?.name!==`默认`?-1:t?.name===`默认`&&e?.name!==`默认`?1:String(e?.name||``).localeCompare(String(t?.name||``),`zh-CN`))}function R(){let e=y(),{hasPermission:t}=ie(),n=t(`roles:write`),r=t(`roles:delete`),[i,a]=(0,D.useState)(``),[l,f]=(0,D.useState)(null),m=x(()=>b.get(`/roles`),[]),h=(0,D.useMemo)(()=>{let e=Array.isArray(m.data?.roles)?L(m.data.roles):[];if(!i.trim())return e;let t=i.trim().toLowerCase();return e.filter(e=>[e.name,e.description,e.workflow_id].some(e=>String(e||``).toLowerCase().includes(t)))},[m.data,i]),ee=e=>E({title:`删除角色「${e.name}」?`,content:`已绑定该角色的对话将失去对应提示词与工具配置。`,onOk:async()=>{try{await b.del(`/roles/${encodeURIComponent(e.name)}`),ce(`已删除`),m.reload()}catch(e){ae(e,`删除角色失败`)}}}),_=[{title:`角色`,dataIndex:`name`,render:(e,t)=>{let n=e===A,r=j(t.icon)||(n?`🔵`:`👤`);return(0,O.jsxs)(`div`,{className:`cs-role-name-cell`,children:[(0,O.jsx)(`span`,{className:`cs-role-icon-badge`,"aria-hidden":`true`,children:r}),(0,O.jsxs)(o,{vertical:!0,spacing:0,align:`start`,children:[(0,O.jsxs)(o,{spacing:6,children:[(0,O.jsx)(I,{strong:!0,children:e}),n&&(0,O.jsx)(c,{size:`small`,color:`blue`,children:`默认`}),t.enabled===!1&&(0,O.jsx)(c,{size:`small`,color:`grey`,children:`已停用`})]}),(0,O.jsx)(I,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:460},children:t.description||`—`})]})]})}},{title:`工具`,dataIndex:`tools`,width:260,render:(e,t)=>t.name===`默认`?(0,O.jsx)(I,{type:`tertiary`,children:`全部工具`}):Array.isArray(e)&&e.length?(0,O.jsxs)(o,{wrap:!0,spacing:4,children:[e.slice(0,4).map(e=>(0,O.jsx)(c,{size:`small`,children:e},e)),e.length>4&&(0,O.jsxs)(I,{type:`tertiary`,children:[`+`,e.length-4]})]}):(0,O.jsx)(I,{type:`tertiary`,children:`全部工具`})},{title:`工作流`,dataIndex:`workflow_id`,width:180,render:(e,t)=>e?(0,O.jsxs)(o,{spacing:4,wrap:!0,children:[(0,O.jsx)(I,{children:e}),t.workflow_policy===`off`&&(0,O.jsx)(c,{size:`small`,color:`grey`,children:`关闭自动`})]}):`—`}];return(n||r)&&_.push({title:`操作`,width:150,render:(e,t)=>(0,O.jsxs)(o,{children:[n&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,icon:(0,O.jsx)(u,{}),onClick:()=>f({role:t}),children:`编辑`}),r&&t.name!==`默认`&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,O.jsx)(s,{}),"aria-label":`删除 ${t.name}`,onClick:()=>ee(t)})]})}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(w,{title:e(`roles.title`,null,`角色管理`),description:`角色定义对话的系统提示词、可用工具与绑定工作流。`,extra:(0,O.jsxs)(o,{children:[(0,O.jsx)(d,{icon:(0,O.jsx)(v,{}),onClick:()=>m.reload(),loading:m.loading,children:`刷新`}),n&&(0,O.jsx)(d,{theme:`solid`,type:`primary`,icon:(0,O.jsx)(g,{}),onClick:()=>f({role:null}),children:`新建角色`})]})}),(0,O.jsxs)(C,{title:`角色(${h.length})`,children:[(0,O.jsx)(S,{error:m.error,onRetry:()=>m.reload()}),(0,O.jsx)(T,{columns:_,dataSource:h,rowKey:`name`,loading:m.loading,pagination:{pageSize:20},toolbar:(0,O.jsx)(p,{prefix:(0,O.jsx)(te,{}),value:i,onChange:a,placeholder:`搜索角色名称`,showClear:!0,style:{width:260}})})]}),(0,O.jsx)(F,{visible:!!l,role:l?.role||null,onCancel:()=>f(null),onSaved:()=>{f(null),m.reload()}})]})}export{R as default};
\ No newline at end of file
diff --git a/web/static/app/assets/settings-1TCOaSN2.js b/web/static/app/assets/settings-1TCOaSN2.js
deleted file mode 100644
index ab857f49..00000000
--- a/web/static/app/assets/settings-1TCOaSN2.js
+++ /dev/null
@@ -1,21 +0,0 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,_ as n,g as r,t as i,y as a}from"./react-QV7DAAIx.js";import{$ as o,B as s,Ft as c,G as l,I as u,L as d,N as f,R as p,S as m,U as h,c as g,d as _,g as v,h as y,j as b,k as ee,lt as x,m as S,on as C,p as w,s as T,ut as E,y as D}from"./semi-65W_4I1v.js";import{A as O,D as k,E as A,F as j,I as M,L as N,M as P,N as F,P as te,R as I,S as L,T as R,_ as ne,a as re,b as z,d as B,j as V,l as H,m as U,n as W,o as G,p as ie,s as ae,u as oe,x as se,y as K}from"./index-BdnarFZR.js";import{n as ce,r as le,t as ue}from"./model-channel-mQ6lfvSO.js";var q=e(t(),1),J=class extends Error{constructor(e,t){super(t?`第 ${t} 行:${e}`:e),this.name=`YamlError`,this.line=t||0}},de=/^(?:[-?:,\[\]{}#&*!|>'"%@`]|.*[:\s]$|.*\s#|.*[\n\r\t])/,fe=/^(?:true|false|null|~|yes|no|on|off|[-+]?(?:\d+|\d*\.\d+)(?:[eE][-+]?\d+)?)$/i;function pe(e){let t=String(e);return!(t===``||fe.test(t)||/^[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?$/.test(t)||de.test(t)||/^(?:\s)|:(?:\s|$)|[\r\n\t]/.test(t)||/[,[\]{}]/.test(t)||/^[!&*|>@`]/.test(t))}function Y(e){return JSON.stringify(String(e))}function me(e){let t=String(e);return pe(t)?t:Y(t)}function he(e){if(e==null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return Number.isFinite(e)?String(e):Y(String(e));let t=String(e);return pe(t)?t:Y(t)}function ge(e){return e==null||[`string`,`number`,`boolean`].includes(typeof e)}function _e(e,t,n,r){let i=` `.repeat(n),a=me(e);if(ge(t))r.push(`${i}${a}: ${he(t)}`);else if(Array.isArray(t)){if(!t.length){r.push(`${i}${a}: []`);return}r.push(`${i}${a}:`),be(t,n+2,r)}else Object.entries(t).length?(r.push(`${i}${a}:`),ve(t,n+2,r)):r.push(`${i}${a}: {}`)}function ve(e,t,n){for(let[r,i]of Object.entries(e))_e(r,i,t,n)}function ye(e,t,n){let r=` `.repeat(t);if(ge(e)){n.push(`${r}- ${he(e)}`);return}if(Array.isArray(e)){if(!e.length){n.push(`${r}- []`);return}n.push(`${r}-`),be(e,t+2,n);return}let i=Object.entries(e);if(!i.length){n.push(`${r}- {}`);return}let[a,o]=i[0],s=i.slice(1);ge(o)?n.push(`${r}- ${me(a)}: ${he(o)}`):(n.push(`${r}-`),_e(a,o,t+2,n));for(let[e,r]of s)_e(e,r,t+2,n)}function be(e,t,n){for(let r of e)ye(r,t,n)}function xe(e,{header:t}={}){let n=[];if(t){for(let e of String(t).replace(/\r\n?/g,`
-`).split(`
-`))n.push(`# ${e}`.trimEnd());n.length&&n.push(``)}return ge(e)?(n.push(he(e)),`${n.join(`
-`)}\n`):Array.isArray(e)?(e.length?be(e,0,n):n.push(`[]`),`${n.join(`
-`)}\n`):!e||!Object.keys(e).length?(n.push(`{}`),`${n.join(`
-`)}\n`):(ve(e,0,n),`${n.join(`
-`)}\n`)}function X(e){let t=``;for(let n=0;n=n.length||/\s/.test(n[e+1]))){let r=n.slice(0,e).trim();if(!r)throw new J(`键名为空`,t);if(/^[&*!|>@`]/.test(r))throw new J(`不支持的键名写法:${r}`,t);return{key:r,rest:X(n.slice(e+1).trim())}}throw new J(`缺少冒号,无法识别为键值`,t)}function we(e,t){if(e.startsWith(`"`)||e.startsWith(`'`)){let{end:n}=Se(e,0,t);return e.slice(n).trimStart().startsWith(`:`)}if(/^[\[{]/.test(e))return!1;for(let t=0;t=e.length||/\s/.test(e[t+1])))return!0;return!1}function Te(e){let t=e.trim();return t===``||t===`~`||/^null$/i.test(t)?null:/^true$/i.test(t)?!0:/^false$/i.test(t)?!1:/^[-+]?\d+$/.test(t)&&t.length<16||/^[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?$/.test(t)?Number(t):t}function Ee(e,t,n){let r=t,i=()=>{for(;r{i();let t=e[r];if(t===`[`||t===`{`){let o=t,s=o===`[`?`]`:`}`;r+=1;let c=o===`[`,l=c?[]:{};for(;;){if(i(),r>=e.length)throw new J(`行内集合未闭合`,n);if(e[r]===s)return r+=1,l;if(c)l.push(a());else{let t=a();if(i(),e[r]!==`:`)throw new J(`行内对象缺少冒号`,n);r+=1,l[String(t)]=a()}if(i(),e[r]===`,`)r+=1;else{if(e[r]===s)return r+=1,l;throw new J(`行内集合分隔符不正确`,n)}}}if(t===`"`||t===`'`){let t=Se(e,r,n);return r=t.end,t.value}let o=r;for(;o][-+0-9]*$/.test(e.trim())}function ke(e,t,n,r){let i=n.trim()[0],a=n.includes(`-`)?`strip`:n.includes(`+`)?`keep`:`clip`,o=e.rawLines,s=[],c=null,l=r;for(let e=r;et)throw new J(`缩进层级不一致`,n.line);if(n.content===`-`||n.content.startsWith(`- `))throw new J(`同一层级不能混用列表与键值`,n.line);let i=Ce(n.content,n.line);e.i+=1,r[i.key]=Me(e,t,i.rest,n.line)}return r}function Me(e,t,n,r){if(n===``){let n=e.lines[e.i];return n&&n.indent>t?Ae(e,n.indent):null}return Oe(n)?ke(e,t,n,r):De(n,r)}function Ne(e,t){let n=[];for(;e.it)throw new J(`缩进层级不一致`,r.line);break}if(!(r.content===`-`||r.content.startsWith(`- `)))break;let i=r.content===`-`?``:r.content.slice(1).trimStart(),a=t+(r.content.length-i.length);if(e.i+=1,i===``){let r=e.lines[e.i];r&&r.indent>t?n.push(Ae(e,r.indent)):n.push(null)}else if(we(i,r.line)&&!/^[\[{]/.test(i)){let t=Ce(i,r.line),o={};o[t.key]=Me(e,a,t.rest,r.line),je(e,a,o),n.push(o)}else Oe(i)?n.push(ke(e,t,i,r.line)):n.push(De(i,r.line))}return n}function Pe(e){let t=String(e??``).replace(/\r\n?/g,`
-`).split(`
-`),n=[];if(t.forEach((e,t)=>{if(/^\s*$/.test(e)||/^\s*#/.test(e)||/^\s*(---|\.\.\.)\s*(#.*)?$/.test(e))return;let r=/^[ \t]*/.exec(e)[0];if(r.includes(` `))throw new J(`缩进不能使用制表符`,t+1);n.push({indent:r.length,content:e.slice(r.length),line:t+1})}),!n.length)return null;let r={lines:n,rawLines:t,i:0},i=Ae(r,n[0].indent);if(r.i({name:e.name,enabled:!!e.enabled,is_external:!!e.is_external,external_mcp:e.external_mcp||void 0}))}function Ue({active:e=!0}){let t=te(),n=r(),{hasPermission:i}=j(),a=i(`config:read`),c=i(`config:write`),l=(0,q.useCallback)(({signal:e}={})=>M.get(`/config`,null,{signal:e}),[]),d=re(l,[a],{skip:!a}),h=(0,q.useRef)(e),[g,_]=(0,q.useState)(``),[v,y]=(0,q.useState)(``),[ee,x]=(0,q.useState)(``),[S,C]=(0,q.useState)(null),[w,T]=(0,q.useState)(``),[D,O]=(0,q.useState)(`idle`);(0,q.useEffect)(()=>{if(!d.data)return;let{context_window_defaults:e,image_input_defaults:t,...n}=d.data,r=xe(n,{header:Ve});_(r),y(r),x(``)},[d.data]);let A=v!==``&&g!==v,N=D!==`idle`;(0,q.useEffect)(()=>{e&&!h.current&&a&&!A&&!N&&d.reload({silent:!0}),h.current=e},[e,N,a,d.reload,A]);let P=(0,q.useMemo)(()=>{let e=d.data;if(!e)return[];let r=e.ai?.channels||{},i=Object.entries(r).map(([e,t])=>ue(e,t)),a=e.ai?.default_channel,o=Array.isArray(e.tools)?e.tools:[],s=o.filter(e=>e.enabled).length,c=!!(e.vision?.enabled&&String(e.vision?.model||``).trim()),l=!!e.knowledge?.enabled;return[{label:t(`settings.defaultChannel`,null,`默认 AI 通道`),value:a?ue(a,r[a]):`—`},{label:t(`settingsBasic.aiChannelSavedList`,null,`已保存通道`),value:`${k(i.length)}${i.length?`(${i.slice(0,4).join(`、`)})`:``}`},{label:t(`settings.toolsEnabled`,null,`已启用工具`),value:`${k(s)} / ${k(o.length)}`},{label:t(`settings.visionLabel`,null,`视觉模型`),value:(0,Z.jsxs)(`span`,{className:`settings-overview-inline`,children:[(0,Z.jsx)(`span`,{children:e.vision?.enabled?e.vision.model||`已启用`:`未启用`}),(0,Z.jsx)(p,{size:`small`,theme:`borderless`,type:`primary`,className:`settings-overview-link`,onClick:()=>n(`/settings?section=models&focus=vision`),children:c?`配置`:`去启用`})]})},{label:t(`settings.knowledge.title`,null,`知识库设置`),value:(0,Z.jsxs)(`span`,{className:`settings-overview-inline`,children:[(0,Z.jsx)(`span`,{children:l?`已启用`:`未启用`}),(0,Z.jsx)(p,{size:`small`,theme:`borderless`,type:`primary`,className:`settings-overview-link`,onClick:()=>n(`/settings?section=knowledge`),children:l?`配置`:`去启用`})]})},{label:`C2`,value:e.c2?.enabled?`已启用`:`未启用`}]},[d.data,n,t]),F=(0,q.useCallback)(async()=>{C(null),T(``),await d.reload()},[d.reload]),R=(0,q.useCallback)(()=>{A?K({title:`重新加载配置`,content:`当前有未保存修改,重新加载会丢弃这些修改。确认继续?`,okText:`确定`,onOk:F}):F()},[F,A]);return a?d.loading&&!d.data?(0,Z.jsx)(Le,{rows:8}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(H,{error:d.error,onRetry:R}),d.data&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(U,{title:t(`settings.overviewTitle`,null,`当前配置概览`),children:(0,Z.jsx)(B,{items:P,columns:3})}),(0,Z.jsxs)(U,{title:t(`settings.rawTitle`,null,`原始 YAML 配置`),description:t(`settingsDisplay.rawYamlHelp`,null,`查看或批量修改服务端高级配置。保存会写入支持的改动并尝试应用。`),extra:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(f,{color:A?`amber`:`green`,size:`small`,children:A?t(`settings.unsaved`,null,`有未保存修改`):t(`settings.savedState`,null,`已与服务端同步`)}),(0,Z.jsx)(G,{text:g,label:t(`common.copy`,null,`复制`)})]}),children:[w&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,className:`settings-yaml-notice`,description:w}),ee&&(0,Z.jsx)(H,{error:ee}),(0,Z.jsx)(H,{error:S,onRetry:R}),(0,Z.jsxs)(`div`,{className:`settings-yaml-toolbar`,children:[(0,Z.jsxs)(u,{children:[(0,Z.jsx)(p,{theme:`solid`,type:`primary`,icon:(0,Z.jsx)(o,{}),loading:N,disabled:!c||!A,onClick:async()=>{let e;try{e=Pe(g)}catch(e){x(I(e,`YAML 解析失败`));return}if(!e||typeof e!=`object`||Array.isArray(e)){x(`顶层必须是键值映射(key: value),不能是列表或标量。`);return}x(``),C(null),T(``);let n=Object.keys(e).filter(e=>!Be.includes(e)),r={};for(let t of Be)e[t]!==void 0&&JSON.stringify(e[t])!==JSON.stringify(d.data?.[t])&&(r[t]=e[t]);if(r.tools&&(r.tools=He(r.tools)),!Object.keys(r).length){T(`没有需要保存的配置修改。`),n.length&&L(`已忽略不支持的字段:${n.join(`、`)}`);return}O(`saving`);try{await M.put(`/config`,r)}catch(e){O(`idle`),C(e),z(e,t(`settings.apply.applyFailed`,null,`保存配置失败`));return}let i=null;O(`applying`);try{await M.post(`/config/apply`)}catch(e){i=e}O(`idle`),i?(C(i),T(t(`settings.apply.appliedWithError`,null,`配置已写入 config.yaml,但应用失败;部分改动需要重启后才能生效。`)),L(t(`settings.apply.appliedWithError`,null,`配置已写入,但应用失败`))):se(t(`settings.apply.applySuccess`,null,`配置已成功应用`)),n.length&&L(t(`settings.apply.ignoredSections`,{list:n.join(`、`)},`已忽略后端不接收的字段:${n.join(`、`)}`)),await d.reload()},children:D===`applying`?t(`settings.applying`,null,`正在应用…`):t(`settings.saveAndApply`,null,`保存并应用`)}),(0,Z.jsx)(p,{onClick:()=>{try{let e=Pe(g);if(!e||typeof e!=`object`||Array.isArray(e)){x(`顶层必须是键值映射(key: value),不能是列表或标量。`);return}_(xe(e,{header:Ve})),x(``)}catch(e){x(I(e,`YAML 解析失败`))}},disabled:N,children:t(`settings.formatAndValidate`,null,`格式化并校验`)}),(0,Z.jsx)(p,{onClick:()=>{_(v),x(``),T(``)},disabled:!A||N,children:t(`toolGuard.reset`,null,`撤销修改`)}),(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),onClick:R,loading:d.loading,disabled:N,children:t(`common.refresh`,null,`刷新`)})]}),(0,Z.jsx)(Q,{children:t(`settings.lineCount`,{count:g.split(`
-`).length},`${g.split(`
-`).length} 行`)})]}),!c&&(0,Z.jsx)(ze,{type:`tertiary`,size:`small`,className:`settings-hint`,children:t(`settings.readOnlyHint`,null,`当前账号没有 config:write 权限,只能查看配置,无法保存。`)}),(0,Z.jsx)(m,{className:`settings-yaml-input`,value:g,onChange:e=>{_(e),T(``)},readOnly:!c||N,spellCheck:!1,autosize:!1,rows:24})]}),(0,Z.jsx)(U,{title:t(`settings.jsonTitle`,null,`只读参考`),children:(0,Z.jsx)(b,{children:(0,Z.jsx)(b.Panel,{header:t(`settings.jsonPanel`,null,`GET /config 原始响应(JSON,便于核对字段名)`),itemKey:`json`,children:(0,Z.jsx)(oe,{value:d.data,collapsed:!0,title:`GET /config`})})})})]})]}):(0,Z.jsx)(Ie,{permission:`config:read`,label:t(`settings.nav.basic`,null,`读取基础配置`)})}var{Text:We}=l,Ge=`__main__`,Ke={},qe=1048576,Je=[{value:`openai_compatible`,key:`settingsProbe.compatible`,fallback:`兼容 OpenAI 的接口`},{value:`claude`,key:`settingsBasic.providerClaude`,fallback:`Claude(Anthropic Messages)`}],Ye=[{value:`openai`,key:`settingsProbe.auditBackendChat`,fallback:`对话模型`},{value:`typesafe`,key:`settingsProbe.auditBackendTypeSafe`,fallback:`TypeSafe / Jev`}],Xe=[``,`auto`,`local_auto`,`local`,`economy`,`custom`],Ze=[[`context_window`,`settingsBasic.contextWindow`,`模型上下文窗口(Token)`],[`max_total_tokens`,`settingsBasic.maxTotalTokens`,`最大上下文令牌数`],[`max_completion_tokens`,`settingsBasic.maxCompletionTokens`,`最大输出令牌数`]],Qe={key:``,payload:null,error:null},$e={context_window_unknown:`contextWarnUnknown`,context_runtime_unknown:`contextWarnRuntimeUnknown`,local_context_window_unknown:`contextWarnWindowUnknown`,local_context_window_small:`contextWarnWindowSmall`,max_total_tokens_clamped:`contextWarnBudgetClamped`,max_completion_tokens_clamped:`contextWarnCompletionClamped`,configured_budget_exceeds_context_window:`contextWarnBudgetExceedsWindow`,ollama_v1_ignores_num_ctx:`contextWarnOllamaV1`,ollama_runtime_context_unknown:`contextWarnOllamaRuntime`,llamacpp_parallel_slots:`contextWarnLlamaCppSlots`},et={ollama:`Ollama`,llamacpp:`llama.cpp`,lmstudio:`LM Studio`,omlx:`oMLX`,vllm:`vLLM`};function tt(e,t){return e(`settingsProbe.profiles.`+(t||`default`),null,t||`使用默认设置`)}function nt(e){let t=Number(e);return Number.isSafeInteger(t)&&t>=0?t:0}function rt(e){let t=(e||``).trim(),n=t.toLowerCase();return n?n===`openai`||n===`openai_compatible`?`openai_compatible`:n===`claude`||n===`anthropic`?`claude`:t:``}function it(e){let t=e.provider||`openai_compatible`;return t===`openai`&&(t=`openai_compatible`),t===`anthropic`&&(t=`claude`),{name:e.name||``,provider:t,base_url:e.base_url||``,api_key:e.api_key||``,model:e.model||``,image_input:e.image_input||``,context_profile:e.context_profile||``,context_window:e.context_window>0?String(e.context_window):``,max_total_tokens:e.max_total_tokens||0,max_completion_tokens:e.max_completion_tokens||0,headers:e.headers||void 0}}function at(e,t){return[{label:e(`settingsProbe.result`,null,`测试结果`),value:(0,Z.jsx)(f,{color:`green`,children:e(`settingsBasic.testSuccess`,null,`连接成功`)})},{label:e(`settingsBasic.model`,null,`模型`),value:t.model||`—`},{label:e(`settingsProbe.latency`,null,`响应耗时`),value:t.latency_ms==null?`—`:e(`settingsProbe.milliseconds`,{value:t.latency_ms},`${t.latency_ms} 毫秒`)}]}function ot(e,t,n,r){let i=t.context_source,a=i?.replace(/^omlx_models_(?=max_model_len|context_length|max_context_length|context_window)/,`openai_models_`),o=t.context_backend,s=r===`configured`?e(`settingsProbe.windowConfigured`,null,`手动配置`):e(`settingsProbe.windowDefault`,null,`默认值`);return[...at(e,t),{label:e(`settingsProbe.window`,null,`上下文窗口`),value:t.context_window||n||`—`},{label:e(`settingsProbe.backend`,null,`模型接口类型`),value:o===`openai_compatible`?e(`settingsProbe.compatible`,null,`兼容 OpenAI 的接口`):et[o]||o||`—`},{label:e(`settingsProbe.source`,null,`窗口信息来源`),value:n?s:i?e(`settingsProbe.sources.`+a,null,i):`—`},{label:e(`settingsProbe.profile`,null,`上下文配置`),value:tt(e,t.context_profile)},{label:e(`settingsProbe.effectiveBudget`,null,`实际可用上下文令牌数`),value:t.effective_max_total_tokens??`—`}]}function st({state:e,defaultWindow:t,defaultWindowSource:n,model:r,onModelChange:i,disabled:a}){let o=te(),c=(0,q.useId)(),{key:l,payload:d,error:f}=e;if(f)return(0,Z.jsx)(H,{error:f});if(!d)return null;if(l===`list`){if(!d.success)return(0,Z.jsx)(s,{type:d.supported===!1?`info`:`danger`,bordered:!0,closeIcon:null,description:d.error||o(`settingsBasic.modelsListFailed`,null,`获取模型列表失败`)});let e=Array.isArray(d.models)?d.models:[],t=o(`settingsBasic.modelsListSelectPlaceholder`,null,`请选择模型`);return(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)(We,{children:o(`settingsBasic.modelsListSuccess`,{count:d.count??e.length},`已获取 ${d.count??e.length} 个模型`)}),(0,Z.jsx)(`span`,{id:c,hidden:!0,children:t}),e.length>0&&(0,Z.jsx)(D,{filter:!0,"aria-labelledby":c,placeholder:t,value:e.includes(r)?r:void 0,optionList:e.map(e=>({value:e,label:e})),onChange:i,disabled:a,className:`settings-model-picker`})]})})}if(l===`audit`)return(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:d.success?(0,Z.jsx)(B,{columns:3,items:at(o,d)}):(0,Z.jsx)(s,{type:`danger`,bordered:!0,closeIcon:null,description:d.error||o(`settingsBasic.testFailed`,null,`连接失败`)})});if(!d.success)return(0,Z.jsx)(s,{type:`danger`,bordered:!0,closeIcon:null,description:d.error||o(`settingsBasic.testFailed`,null,`连接失败`)});let p=!d.context_window&&!d.context_runtime_unknown?t:0,m=(Array.isArray(d.context_warnings)?d.context_warnings:[]).filter(e=>!p||e!==`context_window_unknown`);return(0,Z.jsxs)(`div`,{className:`settings-probe-result`,children:[(0,Z.jsx)(B,{columns:3,items:ot(o,d,p,n)}),m.length>0&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(We,{strong:!0,children:o(`settingsProbe.warnings`,null,`上下文提示`)}),(0,Z.jsx)(`ul`,{children:[...new Set(m)].map(e=>(0,Z.jsx)(`li`,{children:Object.hasOwn($e,e)?o(`settingsBasic.`+$e[e],null,e):o(`settingsProbe.unknownWarning`,{code:e},`收到未识别的上下文提示(${e})`)},e))})]})})]})}function ct({config:e,canWrite:t,reloadConfig:n}){let r=te(),i=(0,q.useId)(),a=(0,q.useId)(),o=e.ai?.channels||Ke,c=Object.keys(o),l=e.ai?.default_channel,[d,m]=(0,q.useState)(``),g=[d,l].find(e=>Object.hasOwn(o,e))||c[0]||Ge,_=g===Ge,v=it((_?e.openai:o[g])||{}),[y,ee]=(0,q.useState)({}),x=y[g]||{},S={...v,...x},[C,w]=(0,q.useState)(null),T=C&&Object.hasOwn(C,S.model)?C[S.model]:void 0,E=[`model`,`base_url`,`provider`].every(e=>S[e]===v[e]),O=x.image_input??(E?v.image_input:``),k=E?e.image_input_defaults?.[_?``:g]:T?.image_input,A=O===`enabled`||O!==`disabled`&&k===!0,j=E&&S.context_profile===v.context_profile?e.context_window_defaults?.[_?``:g]:T?.context_window,N=[`local`,`local_auto`].includes(String(S.context_profile||``).trim().toLowerCase()),P=!!S.model.trim()&&!S.context_window,F=P&&!Object.hasOwn(x,`context_window`),I=nt(S.context_window),L=I>0?I:F?N?j||0:j||qe:0,R=I>0?`configured`:L>0?`default`:``,ne=j===qe,re=Object.keys(x).length>0,[z,B]=(0,q.useState)(``),[V,W]=(0,q.useState)(Qe),[G,ie]=(0,q.useState)(!1),[ae,oe]=(0,q.useState)(null),[K,ue]=(0,q.useState)(!1),J=!t||G||z===`list`,de=_?[{value:Ge,label:r(`settingsProbe.mainChannel`,null,`主模型通道`)}]:ce(Object.entries(o)),fe=Je.map(({value:e,key:t,fallback:n})=>({value:e,label:r(t,null,n)}));fe.some(e=>e.value===S.provider)||fe.push({value:S.provider,label:S.provider});let pe=()=>{ee(e=>{let t={...e};return delete t[g],t})},Y=(e,t)=>{let n=[`provider`,`base_url`,`api_key`,`context_profile`].includes(e);n&&w(null),(V.key!==`list`||!V.payload?.success||n)&&W(Qe),ee(n=>{let r={...n[g]};[`model`,`base_url`,`provider`].includes(e)&&t!==S[e]&&delete r.image_input;let i=e===`image_input`&&!E?``:v[e];return t===String(i)?delete r[e]:r[e]=t,{...n,[g]:r}})},me=e=>{w(null),m(e),W(Qe),K||oe(null)},he=()=>{w(null),pe(),W(Qe),K||oe(null)},ge=async e=>{try{await M.post(`/config/apply`),ue(!1),se(e)}catch(e){ue(!0),oe(e)}},_e=async(e=!1)=>{if(J||z||!re&&!e)return;oe(null);let t=Ze.find(([e])=>!/^\d*$/.test(String(S[e]).trim())||!Number.isSafeInteger(Number(S[e])));if(t){let[,e,n]=t;oe(Error(r(`settingsProbe.invalidLimit`,{field:r(e,null,n)},`请输入非负整数`)));return}let i={...x};for(let[e]of Ze)Object.hasOwn(i,e)&&(i[e]=nt(S[e]));re&&P&&!ne&&(i.context_window=qe),ie(!0);try{await M.put(`/config`,{ai_channel:{channel_id:_?``:g,make_default:e,...i}}),pe(),await ge(e?r(`settingsBasic.aiChannelDefaultSaved`,null,`已设为默认通道`):r(`settingsBasic.aiChannelSaved`,null,`通道已保存`)),await n({silent:!0})}catch(e){oe(e)}finally{ie(!1)}},ve=async()=>{if(!J&&K){ie(!0),oe(null);try{await ge(r(`settings.apply.applySuccess`,null,`配置已成功应用`))}finally{ie(!1)}}},ye=async(e,t,n)=>{if(!(J||z)){B(e),e===`list`&&w(null),W(Qe);try{let r=await M.post(t,n);e===`list`&&r.success&&w(r.model_defaults||null);let i=r.context_window;if((e===`context`||e===`test`&&[``,`0`].includes(S.context_window.trim()))&&r.success&&Number.isSafeInteger(i)&&i>0&&!r.context_runtime_unknown&&!(F&&ne&&i===j)){let e=String(i);ee(t=>{let n={...t[g]};return[`provider`,`base_url`,`api_key`,`model`,`context_window`].some(e=>n[e]!==x[e])?t:(e===v.context_window?delete n.context_window:n.context_window=e,{...t,[g]:n})})}W({key:e,payload:r,error:null})}catch(t){W({key:e,payload:null,error:t})}finally{B(``)}}},be=()=>({provider:S.provider,channel_id:_?void 0:g,credential_scope:_?`openai`:void 0,base_url:S.base_url,api_key:S.api_key,model:S.model,headers:S.headers,context_window:L||void 0,max_total_tokens:nt(S.max_total_tokens),max_completion_tokens:nt(S.max_completion_tokens),context_profile:S.context_profile}),xe=(0,q.useId)(),X=(0,q.useId)(),Se=e.hitl?.audit_model||{},Ce=(e.hitl?.audit_backend||``).trim().toLowerCase(),we=[`typesafe`,`jev`,`type-safe`,`typesafe-ai`].includes(Ce),Te={audit_backend:we?`typesafe`:`openai`,provider:rt(Se.provider),base_url:Se.base_url||``,api_key:Se.api_key||``,model:Se.model||``},[Ee,De]=(0,q.useState)({}),Oe={...Te,...Ee},ke=Object.keys(Ee).length>0,Ae=Oe.audit_backend===`typesafe`,je=Oe.provider||e.openai?.provider||`openai`,Me=[`claude`,`anthropic`].includes(je.toLowerCase()),Ne=Ae?`TypeSafe / Jev`:Me?`Claude (Anthropic Messages)`:r(`settingsProbe.compatible`,null,`兼容 OpenAI 的接口`),Pe=Se.provider?.trim()||e.openai?.provider||`openai`,Fe=we?`TypeSafe / Jev`:[`claude`,`anthropic`].includes(Pe.toLowerCase())?`Claude (Anthropic Messages)`:r(`settingsProbe.compatible`,null,`兼容 OpenAI 的接口`),Ie=we||[`provider`,`base_url`,`api_key`,`model`].some(e=>Se[e])?Se.model||Fe:r(`settingsProbe.auditInherit`,null,`继承主模型`),Le=Ae?`https://api.typesafe.ai`:e.openai?.base_url||(Me?`https://api.anthropic.com`:`https://api.openai.com/v1`),Re=Ye.map(({value:e,key:t,fallback:n})=>({value:e,label:r(t,null,n)})),ze=[{value:``,label:r(`settingsProbe.auditInherit`,null,`继承主模型`)},...Je.map(({value:e,key:t,fallback:n})=>({value:e,label:r(t,null,n)}))];Oe.provider&&!ze.some(e=>e.value===Oe.provider)&&ze.push({value:Oe.provider,label:Oe.provider});let[Be,Ve]=(0,q.useState)(Qe),[He,Ue]=(0,q.useState)(!1),[$e,et]=(0,q.useState)(!1),[at,ot]=(0,q.useState)(null),[ct,lt]=(0,q.useState)(!1),ut=!t||$e||He;(0,q.useEffect)(()=>{De({}),Ve(Qe)},[Te.audit_backend,Te.provider,Te.base_url,Te.api_key,Te.model]);let dt=(e,t)=>{Ve(Qe),ct||ot(null),De(n=>{let r={...n};return t===Te[e]?delete r[e]:r[e]=t,r})},ft=()=>{De({}),Ve(Qe),ct||ot(null)},pt=async e=>{try{await M.post(`/config/apply`),lt(!1),se(e)}catch(e){lt(!0),ot(e)}},mt=async()=>{if(!(ut||G||z||!ke)){ot(null),et(!0);try{await M.put(`/config`,{hitl_audit_model:Ee}),De({}),await pt(r(`settingsProbe.auditModelSaved`,null,`审计模型已保存`)),await n({silent:!0})}catch(e){ot(e)}finally{et(!1)}}},ht=async()=>{if(!(ut||G||z||!ct)){et(!0),ot(null);try{await pt(r(`settings.apply.applySuccess`,null,`配置已成功应用`))}finally{et(!1)}}},gt=async()=>{if(ut)return;Ue(!0),Ve({key:`audit`,payload:null,error:null});let e={base_url:Oe.base_url,api_key:Oe.api_key,model:Oe.model,...Object.hasOwn(Ee,`audit_backend`)?{audit_backend:Oe.audit_backend}:{},...Object.hasOwn(Ee,`provider`)?{provider:Oe.provider}:{},...Te.api_key!==``&&Oe.api_key===``?{clear_api_key:!0}:{}};try{let t=await M.post(`/config/test-audit-model`,e);Ve({key:`audit`,payload:t,error:null})}catch(e){Ve({key:`audit`,payload:null,error:e})}finally{Ue(!1)}};return(0,Z.jsxs)(U,{title:r(`settingsProbe.channelTitle`,null,`模型通道与连接测试`),description:r(`settingsProbe.channelHelp`,null,`保存后应用所选通道的设置。显示 ******** 时沿用已保存的密钥。`),className:`settings-channel-panel`,extra:t?(0,Z.jsxs)(u,{wrap:!0,children:[re&&(0,Z.jsx)(p,{disabled:G||!!z,onClick:he,children:r(`toolGuard.reset`,null,`撤销修改`)}),!_&&g!==l&&(0,Z.jsx)(p,{disabled:G||!!z,onClick:()=>_e(!0),children:r(`settingsBasic.aiChannelSetDefault`,null,`设为默认`)}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,loading:G,disabled:!re||!!z,onClick:()=>_e(),children:r(`settingsProbe.saveChannel`,null,`保存通道`)})]}):(0,Z.jsx)(f,{color:`grey`,size:`small`,children:r(`settingsProbe.channelReadOnly`,null,`只读`)}),children:[(0,Z.jsxs)(`div`,{className:`settings-probe-form`,children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(We,{id:i,type:`tertiary`,size:`small`,children:r(`settings.checkChannel`,null,`通道`)}),(0,Z.jsx)(D,{value:g,onChange:me,optionList:de,renderSelectedItem:le,"aria-labelledby":i,disabled:G||!!z,style:{width:`100%`}})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.apiProvider`,null,`API 提供商`)}),(0,Z.jsx)(D,{value:S.provider,onChange:e=>Y(`provider`,e),optionList:fe,disabled:J,style:{width:`100%`}})]}),(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.baseUrl`,null,`API 地址`)}),(0,Z.jsx)(h,{value:S.base_url,onChange:e=>Y(`base_url`,e),readOnly:J,placeholder:`https://api.openai.com/v1`})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsxs)(u,{spacing:6,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.model`,null,`模型`)}),A&&(0,Z.jsx)(f,{size:`small`,color:`green`,children:r(`settingsProbe.imageInputSupported`,null,`支持图片`)})]}),(0,Z.jsx)(h,{value:S.model,onChange:e=>Y(`model`,e),readOnly:J,placeholder:`gpt-4o-mini`})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.aiChannelName`,null,`通道名称`)}),(0,Z.jsx)(h,{value:S.name,onChange:e=>Y(`name`,e),readOnly:J,placeholder:_?``:g})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.apiKey`,null,`API 密钥`)}),(0,Z.jsx)(h,{mode:`password`,autoComplete:`new-password`,value:S.api_key,onChange:e=>Y(`api_key`,e),readOnly:J})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsProbe.profile`,null,`上下文配置`)}),(0,Z.jsx)(D,{value:S.context_profile||``,onChange:e=>Y(`context_profile`,e),disabled:J,optionList:[...new Set([...Xe,S.context_profile||``])].map(e=>({value:e,label:tt(r,e)})),style:{width:`100%`}})]}),(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(We,{id:a,type:`tertiary`,size:`small`,children:`图片输入能力`}),(0,Z.jsx)(D,{value:O||``,onChange:e=>Y(`image_input`,e),disabled:J,"aria-labelledby":a,optionList:[{value:``,label:k===!0?`自动识别(支持图片)`:k===!1?`自动识别(仅文本)`:`自动识别`},{value:`enabled`,label:`启用(该模型原生支持识图)`},{value:`disabled`,label:`禁用(仅文本 / 走下方独立视觉模型)`}],style:{width:`100%`}})]}),Ze.map(([e,t,n])=>{let a=e===`context_window`,o=a&&F,s=`${i}-${e}`;return(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{id:s,type:`tertiary`,size:`small`,children:r(t,null,n)}),(0,Z.jsx)(h,{"aria-labelledby":s,value:String(o?qe:S[e]),onChange:t=>Y(e,t),inputMode:`numeric`,readOnly:J,placeholder:a?r(`settingsProbe.windowExample`,{value:r(`settingsBasic.contextWindowPlaceholder`,null,`131072`)},`例如 131072`):`0`})]},e)})]}),(K||ae)&&(0,Z.jsxs)(`div`,{className:`settings-channel-notices`,children:[K&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(u,{wrap:!0,children:[r(`settingsProbe.savedApplyFailed`,null,`通道已写入配置,应用失败。`),(0,Z.jsx)(p,{size:`small`,disabled:J||!!z,onClick:ve,children:r(`settingsProbe.retryApply`,null,`重试应用`)})]})}),(0,Z.jsx)(H,{error:ae})]}),(0,Z.jsxs)(u,{wrap:!0,className:`settings-probe-actions`,children:[(0,Z.jsx)(p,{loading:z===`test`,disabled:J||!!z,onClick:()=>ye(`test`,`/config/test-openai`,be()),children:r(`settingsBasic.test`,null,`测试连接`)}),(0,Z.jsx)(p,{loading:z===`context`,disabled:J||!!z,onClick:()=>ye(`context`,`/config/detect-context`,be()),children:r(`settingsBasic.detectContext`,null,`探测上下文窗口`)}),(0,Z.jsx)(p,{loading:z===`list`,disabled:J||!!z,onClick:()=>ye(`list`,`/config/list-models`,{context_profile:S.context_profile,provider:S.provider,channel_id:_?void 0:g,credential_scope:_?`openai`:void 0,base_url:S.base_url,api_key:S.api_key}),children:r(`settingsBasic.modelsList`,null,`获取模型列表`)})]}),(0,Z.jsx)(st,{state:V,defaultWindow:L,defaultWindowSource:R,model:S.model,onModelChange:e=>Y(`model`,e),disabled:J}),!A&&(0,Z.jsx)(`div`,{className:`settings-image-fallback-tip`,children:(0,Z.jsx)(Q,{children:`当前通道未启用原生图片输入。若所选模型本身不支持识图,可开启下方「视觉分析(analyze_image)」由独立视觉模型代为识别截图与验证码;若模型通过中转接口实际支持识图,可将「图片输入能力」切换为「启用」。`})}),(0,Z.jsx)(b,{className:`settings-audit-model`,children:(0,Z.jsx)(b.Panel,{itemKey:`audit-model`,header:(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)(We,{strong:!0,children:r(`settingsProbe.auditModelTitle`,null,`审计模型`)}),(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:Ie}),ke&&(0,Z.jsx)(f,{size:`small`,color:`amber`,children:r(`settings.unsaved`,null,`有未保存修改`)})]}),children:(0,Z.jsxs)(`div`,{className:`settings-probe-card`,children:[!Ae&&!Oe.provider&&(0,Z.jsx)(`div`,{children:(0,Z.jsx)(f,{size:`small`,children:Ne})}),(0,Z.jsx)(Q,{children:Ae?r(`settingsProbe.auditTypeSafeHint`,null,`点击「保存审计模型」后生效。地址和模型留空使用 Jev 默认值;密钥必须独立配置,不继承主模型。`):r(`settingsProbe.auditChatHint`,null,`点击「保存审计模型」后生效。地址、提供商和模型留空继承主模型;密钥显示 ******** 时沿用已保存的审计密钥,留空则继承主模型。`)}),(0,Z.jsxs)(`div`,{className:`settings-probe-inline`,children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(We,{id:xe,type:`tertiary`,size:`small`,children:r(`settingsProbe.auditBackendLabel`,null,`审计后端`)}),(0,Z.jsx)(D,{value:Oe.audit_backend,onChange:e=>dt(`audit_backend`,e),optionList:Re,"aria-labelledby":xe,disabled:ut,style:{width:`100%`}})]}),!Ae&&(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(We,{id:X,type:`tertiary`,size:`small`,children:r(`settingsBasic.apiProvider`,null,`API 提供商`)}),(0,Z.jsx)(D,{value:Oe.provider,onChange:e=>dt(`provider`,e),optionList:ze,"aria-labelledby":X,disabled:ut,style:{width:`100%`}})]}),[[`base_url`,`baseUrl`,`API 地址`,Le],[`api_key`,`apiKey`,`API 密钥`,Ae?r(`settingsProbe.auditKeyRequiredPlaceholder`,null,`必填,不继承主模型`):r(`settingsProbe.auditKeyInheritPlaceholder`,null,`留空继承主模型`)],[`model`,`model`,`模型`,Ae?`jev-latest`:e.openai?.model||``]].map(([e,t,n,i])=>(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.`+t,null,n)}),(0,Z.jsx)(h,{value:Oe[e],onChange:t=>dt(e,t),placeholder:i,readOnly:ut,mode:e===`api_key`?`password`:void 0,autoComplete:e===`api_key`?`new-password`:void 0})]},e))]}),(ct||at)&&(0,Z.jsxs)(`div`,{className:`settings-channel-notices`,children:[ct&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(u,{wrap:!0,children:[r(`settingsProbe.auditSavedApplyFailed`,null,`审计模型已写入配置,应用失败。`),(0,Z.jsx)(p,{size:`small`,disabled:ut||G||!!z,onClick:ht,children:r(`settingsProbe.retryApply`,null,`重试应用`)})]})}),(0,Z.jsx)(H,{error:at})]}),(0,Z.jsxs)(u,{wrap:!0,children:[t&&(0,Z.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,loading:$e,disabled:!ke||He||G||!!z,onClick:mt,children:r(`settingsProbe.saveAuditModel`,null,`保存审计模型`)}),(0,Z.jsx)(p,{size:`small`,loading:He,disabled:!t||$e,onClick:gt,children:r(`settingsProbe.testAuditModel`,null,`测试审计模型`)}),t&&ke&&(0,Z.jsx)(p,{size:`small`,disabled:$e||He,onClick:ft,children:r(`toolGuard.reset`,null,`撤销修改`)})]}),(0,Z.jsx)(st,{state:Be})]})})})]})}var{Text:lt}=l,ut={key:``,payload:null,error:null};function dt(e){let t=String(e||``).trim(),n=t.toLowerCase();return n?n===`openai`||n===`openai_compatible`?`openai_compatible`:n===`claude`||n===`anthropic`?`claude`:t:``}function ft(e={}){return{enabled:!!e.enabled,provider:dt(e.provider),base_url:e.base_url||``,api_key:e.api_key||``,model:e.model||``,detail:e.detail||``,timeout_seconds:e.timeout_seconds>0?String(e.timeout_seconds):``,max_image_bytes:e.max_image_bytes>0?String(e.max_image_bytes):``,max_dimension:e.max_dimension>0?String(e.max_dimension):``,jpeg_quality:e.jpeg_quality>0?String(e.jpeg_quality):``,max_payload_bytes:e.max_payload_bytes>0?String(e.max_payload_bytes):``,skip_preprocess_below_bytes:e.skip_preprocess_below_bytes!=null&&e.skip_preprocess_below_bytes!==0?String(e.skip_preprocess_below_bytes):e.skip_preprocess_below_bytes===0&&Object.hasOwn(e,`skip_preprocess_below_bytes`)?`0`:``}}function pt(e){let t=String(e??``).trim();if(!t)return 0;if(!/^\d+$/.test(t))return null;let n=Number(t);return Number.isSafeInteger(n)&&n>=0?n:null}function mt(e){let t=e?.ai?.channels||{},n=e?.ai?.default_channel||``;if(n&&t[n]){let e=t[n];return{channelId:n,displayName:ue(n,e),openai:{provider:e.provider||`openai_compatible`,base_url:e.base_url||``,api_key:e.api_key||``,model:e.model||``}}}let r=e?.openai||{};return{channelId:``,displayName:r.model||``,openai:{provider:r.provider||`openai_compatible`,base_url:r.base_url||``,api_key:r.api_key||``,model:r.model||``}}}function ht({config:e,canWrite:t,reloadConfig:n,focused:r}){let i=te(),a=(0,q.useRef)(null),o=(0,q.useId)(),c=(0,q.useId)(),l=(0,q.useId)(),d=ft(e.vision),m=JSON.stringify(d),[g,v]=(0,q.useState)({}),y={...d,...g},ee=Object.keys(g).length>0,[x,S]=(0,q.useState)(``),[C,w]=(0,q.useState)(!1),[T,E]=(0,q.useState)(null),[O,k]=(0,q.useState)(!1),[A,j]=(0,q.useState)(ut);(0,q.useEffect)(()=>{v({}),j(ut)},[m]),(0,q.useEffect)(()=>{r&&a.current&&a.current.scrollIntoView({behavior:`smooth`,block:`start`})},[r]);let N=!t||C||!!x,P=mt(e),F=y.provider||dt(P.openai.provider)||`openai_compatible`,I=y.base_url.trim()||P.openai.base_url||(F===`claude`?`https://api.anthropic.com`:`https://api.openai.com/v1`),L=[{value:``,label:P.displayName?`${i(`settingsBasic.visionProviderReuseOpenAI`,null,`默认 AI 通道(留空复用)`)} · ${P.displayName}`:i(`settingsBasic.visionProviderReuseOpenAI`,null,`默认 AI 通道(留空复用)`)},{value:`openai_compatible`,label:i(`settingsProbe.compatible`,null,`兼容 OpenAI 的接口`)},{value:`claude`,label:i(`settingsBasic.providerClaude`,null,`Claude(Anthropic Messages)`)}];y.provider&&!L.some(e=>e.value===y.provider)&&L.push({value:y.provider,label:y.provider});let R=[{value:``,label:`默认(low)`},{value:`auto`,label:`auto(自动)`},{value:`low`,label:`low(省流快速)`},{value:`high`,label:`high(高清细节)`}],ne=(e,t)=>{(A.key!==`list`||[`provider`,`base_url`,`api_key`].includes(e))&&j(ut),O||E(null),v(n=>{let r={...n};return t===d[e]?delete r[e]:r[e]=t,r})},re=()=>{v({}),j(ut),O||E(null)},z=()=>{let e=[[`timeout_seconds`,i(`settingsBasic.visionTimeout`,null,`超时(秒)`)],[`max_image_bytes`,i(`settingsBasic.visionMaxImageBytes`,null,`原始文件上限(字节)`)],[`max_dimension`,i(`settingsBasic.visionMaxDimension`,null,`长边缩放像素`)],[`jpeg_quality`,i(`settingsBasic.visionJpegQuality`,null,`JPEG 质量`)],[`max_payload_bytes`,i(`settingsBasic.visionMaxPayloadBytes`,null,`送 API 体积上限(字节)`)],[`skip_preprocess_below_bytes`,i(`settingsBasic.visionSkipPreprocessBytes`,null,`低于该字节可原图直传`)]],t={};for(let[n,r]of e){let e=pt(y[n]);if(e===null)throw Error(i(`settingsProbe.invalidLimit`,{field:r},`${r}请输入非负整数`));t[n]=e}if(t.jpeg_quality>100)throw Error(`JPEG 质量需在 1 ~ 100 之间(留空或 0 使用默认 82)`);return{enabled:!!y.enabled,provider:y.provider.trim(),base_url:y.base_url.trim(),api_key:y.api_key,model:y.model.trim(),detail:y.detail.trim(),...t}},V=async e=>{try{await M.post(`/config/apply`),k(!1),se(e)}catch(e){k(!0),E(e)}},W=async()=>{if(N||!ee)return;if(E(null),y.enabled&&!y.model.trim()){E(Error(i(`settingsBasic.visionModelRequired`,null,`启用视觉分析时请填写视觉模型名称`)));return}let e;try{e=z()}catch(e){E(e);return}w(!0);try{await M.put(`/config`,{vision:e}),v({}),await V(i(`settingsProbe.visionSaved`,null,`视觉模型配置已保存并应用`)),await n({silent:!0})}catch(e){E(e)}finally{w(!1)}},G=async()=>{if(!N&&O){w(!0),E(null);try{await V(i(`settings.apply.applySuccess`,null,`配置已成功应用`))}finally{w(!1)}}},ie=async()=>{if(!N){if(!y.model.trim())j({key:`vision`,payload:null,error:Error(i(`settingsBasic.visionTestFillRequired`,null,`请填写视觉模型,并确保 API Key 可用(可复用 OpenAI)`))});else{S(`vision`),j(ut);try{let e=z(),t=await M.post(`/config/test-vision`,{channel_id:P.channelId||void 0,vision:e,openai:P.openai});j({key:`vision`,payload:t,error:null})}catch(e){j({key:`vision`,payload:null,error:e})}finally{S(``)}}}},ae=async()=>{if(N)return;S(`list`),j(ut);let e=!!y.api_key;try{let t=await M.post(`/config/list-models`,{provider:F,credential_scope:e?`vision`:P.channelId?void 0:`openai`,channel_id:!e&&P.channelId?P.channelId:void 0,base_url:I,api_key:e?y.api_key:P.openai.api_key});j({key:`list`,payload:t,error:null})}catch(e){j({key:`list`,payload:null,error:e})}finally{S(``)}},oe=y.enabled?y.model.trim()?(0,Z.jsx)(f,{color:`green`,size:`small`,children:`${i(`common.enabled`,null,`已启用`)} · ${y.model.trim()}`}):(0,Z.jsx)(f,{color:`amber`,size:`small`,children:`待填写模型`}):(0,Z.jsx)(f,{color:`grey`,size:`small`,children:i(`common.disabled`,null,`未启用`)}),K=A.key===`list`&&Array.isArray(A.payload?.models)?A.payload.models:[];return(0,Z.jsx)(`div`,{id:`settings-vision-panel`,ref:a,className:r?`settings-focus-ring`:void 0,children:(0,Z.jsxs)(U,{title:(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)(`span`,{children:i(`settingsBasic.visionConfig`,null,`视觉分析(analyze_image)`)}),oe,ee&&(0,Z.jsx)(f,{color:`amber`,size:`small`,children:i(`settings.unsaved`,null,`有未保存修改`)})]}),description:`当主对话模型不支持图片识别(如纯文本推理模型),或安全测试中需要识别本地截图、验证码图片时,开启后将挂载 analyze_image 工具,由独立视觉模型代为识图并仅向主模型返回文字摘要。`,className:`settings-vision-panel`,extra:t?(0,Z.jsxs)(u,{wrap:!0,children:[ee&&(0,Z.jsx)(p,{disabled:C||!!x,onClick:re,children:i(`toolGuard.reset`,null,`撤销修改`)}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,loading:C,disabled:!ee||!!x,onClick:W,children:`保存视觉模型`})]}):(0,Z.jsx)(f,{color:`grey`,size:`small`,children:i(`settingsProbe.channelReadOnly`,null,`只读`)}),children:[(0,Z.jsxs)(`div`,{className:`settings-switch-row`,children:[(0,Z.jsx)(_,{checked:y.enabled,disabled:N,onChange:e=>ne(`enabled`,e),"aria-label":i(`settingsBasic.visionEnabled`,null,`启用视觉分析工具 analyze_image`)}),(0,Z.jsxs)(`div`,{className:`settings-switch-copy`,children:[(0,Z.jsx)(lt,{strong:!0,children:i(`settingsBasic.visionEnabled`,null,`启用视觉分析工具 analyze_image`)}),(0,Z.jsx)(Q,{children:i(`settingsBasic.visionEnabledHint`,null,`启用后注册 MCP 工具;图片仅在单次 VL 调用中出现,Agent 上下文只保留文字摘要。保存并应用后生效。`)})]})]}),(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,children:[(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(lt,{type:`tertiary`,size:`small`,children:i(`settingsBasic.visionModel`,null,`视觉模型`)}),(0,Z.jsx)(h,{value:y.model,onChange:e=>ne(`model`,e),readOnly:N,placeholder:i(`settingsBasic.visionModelPlaceholder`,null,`qwen-vl-max`)})]}),(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(lt,{id:o,type:`tertiary`,size:`small`,children:i(`settingsBasic.apiProvider`,null,`API 提供商`)}),(0,Z.jsx)(D,{value:y.provider,onChange:e=>ne(`provider`,e),optionList:L,"aria-labelledby":o,disabled:N,style:{width:`100%`}})]}),(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)(lt,{type:`tertiary`,size:`small`,children:i(`settingsBasic.baseUrl`,null,`API 地址`)}),(0,Z.jsx)(h,{value:y.base_url,onChange:e=>ne(`base_url`,e),readOnly:N,placeholder:P.openai.base_url?`留空复用默认通道(${P.openai.base_url})`:i(`settingsBasic.visionBaseUrlPlaceholder`,null,`留空则复用 OpenAI Base URL`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(lt,{type:`tertiary`,size:`small`,children:i(`settingsBasic.apiKey`,null,`API 密钥`)}),(0,Z.jsx)(h,{mode:`password`,autoComplete:`new-password`,value:y.api_key,onChange:e=>ne(`api_key`,e),readOnly:N,placeholder:i(`settingsBasic.visionApiKeyPlaceholder`,null,`留空则复用 OpenAI API Key`)})]})]}),(O||T)&&(0,Z.jsxs)(`div`,{className:`settings-channel-notices`,children:[O&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(u,{wrap:!0,children:[(0,Z.jsx)(`span`,{children:`视觉模型配置已写入,但应用失败。`}),(0,Z.jsx)(p,{size:`small`,disabled:N,onClick:G,children:i(`settingsProbe.retryApply`,null,`重试应用`)})]})}),(0,Z.jsx)(H,{error:T})]}),(0,Z.jsxs)(u,{wrap:!0,className:`settings-probe-actions`,children:[(0,Z.jsx)(p,{loading:x===`vision`,disabled:!t||C||!!x&&x!==`vision`,onClick:ie,children:i(`settingsProbe.testVision`,null,`测试视觉模型`)}),(0,Z.jsx)(p,{loading:x===`list`,disabled:!t||C||!!x&&x!==`list`,onClick:ae,children:i(`settingsBasic.modelsList`,null,`获取模型列表`)})]}),A.error&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:(0,Z.jsx)(H,{error:A.error})}),A.key===`vision`&&A.payload&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:A.payload.success?(0,Z.jsx)(B,{columns:3,items:[{label:i(`settingsProbe.result`,null,`测试结果`),value:(0,Z.jsx)(f,{color:`green`,children:i(`settingsBasic.testSuccess`,null,`连接成功`)})},{label:i(`settingsBasic.visionModel`,null,`视觉模型`),value:A.payload.model||y.model||`—`},{label:i(`settingsProbe.latency`,null,`响应耗时`),value:A.payload.latency_ms==null?`—`:i(`settingsProbe.milliseconds`,{value:A.payload.latency_ms},`${A.payload.latency_ms} 毫秒`)}]}):(0,Z.jsx)(s,{type:`danger`,bordered:!0,closeIcon:null,description:A.payload.error||i(`settingsBasic.testFailed`,null,`连接失败`)})}),A.key===`list`&&A.payload&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:A.payload.success?(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)(lt,{children:i(`settingsBasic.modelsListSuccess`,{count:A.payload.count??K.length},`已获取 ${A.payload.count??K.length} 个模型`)}),(0,Z.jsx)(`span`,{id:l,hidden:!0,children:i(`settingsBasic.modelsListSelectPlaceholder`,null,`请选择视觉模型`)}),K.length>0&&(0,Z.jsx)(D,{filter:!0,"aria-labelledby":l,placeholder:i(`settingsBasic.modelsListSelectPlaceholder`,null,`请选择模型`),value:K.includes(y.model)?y.model:void 0,optionList:K.map(e=>({value:e,label:e})),onChange:e=>ne(`model`,e),disabled:N,className:`settings-model-picker`})]}):(0,Z.jsx)(s,{type:A.payload.supported===!1?`info`:`danger`,bordered:!0,closeIcon:null,description:A.payload.error||i(`settingsBasic.modelsListFailed`,null,`获取模型列表失败`)})}),(0,Z.jsx)(b,{className:`settings-audit-model`,children:(0,Z.jsxs)(b.Panel,{itemKey:`vision-advanced`,header:(0,Z.jsx)(lt,{strong:!0,children:i(`settingsBasic.visionAdvanced`,null,`高级:预处理与限制`)}),children:[(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(lt,{id:c,type:`tertiary`,size:`small`,children:i(`settingsBasic.visionDetail`,null,`图片精度(Detail)`)}),(0,Z.jsx)(D,{value:y.detail,onChange:e=>ne(`detail`,e),optionList:R,"aria-labelledby":c,disabled:N,style:{width:`100%`}})]}),[[`timeout_seconds`,`visionTimeout`,`超时(秒)`,`60`],[`max_image_bytes`,`visionMaxImageBytes`,`原始文件上限(字节)`,`5242880`],[`max_dimension`,`visionMaxDimension`,`长边缩放像素`,`2048`],[`jpeg_quality`,`visionJpegQuality`,`JPEG 质量`,`82`],[`max_payload_bytes`,`visionMaxPayloadBytes`,`送 API 体积上限(字节)`,`524288`],[`skip_preprocess_below_bytes`,`visionSkipPreprocessBytes`,`低于该字节可原图直传`,`2097152`]].map(([e,t,n,r])=>(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(lt,{type:`tertiary`,size:`small`,children:i(`settingsBasic.`+t,null,n)}),(0,Z.jsx)(h,{value:y[e],onChange:t=>ne(e,t),inputMode:`numeric`,readOnly:N,placeholder:r})]},e))]}),(0,Z.jsx)(Q,{children:i(`settingsBasic.visionSkipPreprocessHint`,null,`0 表示始终 JPEG 压缩;需同时满足长边与 payload 限制。留空使用系统默认值。`)})]})})]})})}var{Text:gt}=l;function _t(e){return e.is_external&&e.external_mcp?`${e.external_mcp}::${e.name}`:e.name}function vt(e){let t=e&&typeof e==`object`&&e.properties||{},n=Array.isArray(e?.required)?e.required:[];return Object.entries(t).map(([e,t])=>({name:e,type:t?.type||(t?.enum?`enum`:`—`),required:n.includes(e),description:t?.description||``}))}function yt(){let e=te(),{hasPermission:t}=j(),n=t(`config:read`)||t(`mcp:read`),r=t(`config:write`),[i,a]=(0,q.useState)(1),[o,s]=(0,q.useState)(20),[c,l]=(0,q.useState)(``),d=W(c,350),[m,g]=(0,q.useState)(`all`),[v,y]=(0,q.useState)({}),[b,ee]=(0,q.useState)(!1),[S,T]=(0,q.useState)(null),[k,A]=(0,q.useState)(null),N=[i,o,d,m],P=(0,q.useCallback)(()=>M.get(`/config/tools`,{page:i,page_size:o,search:d||void 0,tool_filter:m===`on`?`on`:m===`off`?`off`:void 0}),N),F=re(P,[...N,n],{skip:!n});(0,q.useEffect)(()=>{a(1)},[d,m,o]);let I=(0,q.useMemo)(()=>(Array.isArray(F.data?.tools)?F.data.tools:[]).map(e=>{let t=_t(e),n=v[t],r=!!e.enabled;return{...e,key:t,serverEnabled:r,enabled:n?n.enabled:r,dirty:!!n}}),[F.data,v]),L=Object.keys(v).length,R=(e,t)=>{r&&y(n=>{let r={...n},i=e.key;return t===e.serverEnabled?delete r[i]:r[i]={name:e.name,enabled:t,is_external:!!e.is_external,external_mcp:e.external_mcp||void 0},r})},ne=async()=>{if(!r||!L)return;let t=Object.values(v).map(e=>({...e}));ee(!0),T(null);try{await M.put(`/config`,{tools:t}),await M.post(`/config/apply`),se(e(`settings.apply.applySuccess`,null,`配置已成功应用`)),y({}),await F.reload()}catch(t){T(t),z(t,e(`settings.apply.applyFailed`,null,`保存工具开关失败`))}finally{ee(!1)}};if(!n)return(0,Z.jsx)(Ie,{permission:`config:read`,label:e(`settings.toolsTitle`,null,`读取工具列表`)});let B=[{title:e(`settings.toolName`,null,`工具`),dataIndex:`name`,width:260,render:(t,n)=>(0,Z.jsxs)(u,{vertical:!0,spacing:2,align:`start`,children:[(0,Z.jsx)(gt,{strong:!0,children:t}),(0,Z.jsxs)(u,{spacing:4,children:[n.is_external?(0,Z.jsx)(f,{size:`small`,color:`violet`,children:`MCP · ${n.external_mcp}`}):(0,Z.jsx)(f,{size:`small`,color:`grey`,children:e(`settings.toolInternal`,null,`内置`)}),n.role_enabled===!1&&(0,Z.jsx)(f,{size:`small`,color:`orange`,children:e(`settings.toolRoleOff`,null,`当前角色未启用`)})]})]})},{title:e(`settings.toolDescription`,null,`说明`),dataIndex:`description`,render:e=>(0,Z.jsx)(C,{content:e||`—`,position:`topLeft`,children:(0,Z.jsx)(gt,{type:`tertiary`,children:O(e||`—`,90)})})},{title:e(`settings.toolStatus`,null,`启用`),dataIndex:`enabled`,width:160,render:(t,n)=>(0,Z.jsxs)(u,{spacing:6,children:[(0,Z.jsx)(_,{size:`small`,checked:t,disabled:!r||b,onChange:e=>R(n,e),"aria-label":e(`settings.toolStatus`,null,`启用`)}),n.dirty&&(0,Z.jsx)(f,{size:`small`,color:`amber`,children:e(`settings.unsavedShort`,null,`未保存`)})]})},{title:e(`common.actions`,null,`操作`),width:110,render:(t,n)=>(0,Z.jsx)(p,{size:`small`,theme:`borderless`,onClick:()=>A(n),children:e(`settings.toolSchema`,null,`参数`)})}];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(U,{title:e(`settings.toolsTitle`,null,`工具开关`),description:e(`settings.toolsDesc`,null,`开关按工具名写入 config.security.tools;外部 MCP 工具的状态写回对应 MCP 配置。保存后立即应用。`),extra:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(p,{onClick:()=>y({}),disabled:!L||b,children:e(`toolGuard.reset`,null,`撤销修改`)}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,loading:b,disabled:!r||!L,onClick:ne,children:e(`settings.saveTools`,{count:L},`保存工具开关${L?`(${L})`:``}`)})]}),children:[(0,Z.jsx)(H,{error:S}),(0,Z.jsx)(H,{error:F.error,onRetry:F.reload}),(0,Z.jsx)(ae,{columns:B,dataSource:I,rowKey:`key`,loading:F.loading,emptyText:e(`settings.toolsEmpty`,null,`没有匹配的工具`),toolbar:(0,Z.jsxs)(u,{wrap:!0,children:[(0,Z.jsx)(h,{prefix:(0,Z.jsx)(x,{}),value:c,onChange:e=>l(e),placeholder:e(`settings.toolSearch`,null,`按工具名或说明搜索`),style:{width:240},showClear:!0}),(0,Z.jsx)(D,{value:m,onChange:e=>g(e),style:{width:140},optionList:[{value:`all`,label:e(`settings.filterAll`,null,`全部状态`)},{value:`on`,label:e(`settings.filterOn`,null,`仅已启用`)},{value:`off`,label:e(`settings.filterOff`,null,`仅已停用`)}]}),(0,Z.jsx)(f,{size:`small`,color:`blue`,children:e(`settings.toolsTotal`,{total:F.data?.total??0,enabled:F.data?.total_enabled??0},`共 ${F.data?.total??0} 个,已启用 ${F.data?.total_enabled??0} 个`)}),(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),theme:`borderless`,onClick:F.reload,loading:F.loading,children:e(`common.refresh`,null,`刷新`)})]}),pagination:{currentPage:i,pageSize:o,total:F.data?.total||0,showSizeChanger:!0,pageSizeOpts:[10,20,50,100],onPageChange:e=>a(e),onPageSizeChange:e=>{s(e),a(1)}}})]}),(0,Z.jsx)(w,{title:k?e(`settings.toolSchemaTitle`,{name:k.name},`参数定义 · ${k.name}`):``,visible:!!k,onCancel:()=>A(null),width:620,placement:`right`,children:k&&(0,Z.jsx)(bt,{tool:k})})]})}function bt({tool:e}){let t=te(),[n,r]=(0,q.useState)({loading:!0,error:null,schema:null});if((0,q.useEffect)(()=>{let t=!1;return r({loading:!0,error:null,schema:null}),M.get(`/config/tools/${encodeURIComponent(e.name)}/schema`,{external_mcp:e.external_mcp||void 0}).then(e=>{t||r({loading:!1,error:null,schema:e?.input_schema||null})}).catch(e=>{t||r({loading:!1,error:e,schema:null})}),()=>{t=!0}},[e.name,e.external_mcp]),n.loading)return(0,Z.jsx)(Le,{rows:5});if(n.error)return(0,Z.jsx)(H,{error:n.error});if(!n.schema)return(0,Z.jsx)(gt,{type:`tertiary`,children:t(`settings.toolNoSchema`,null,`该工具没有声明参数(无参数 Schema)。`)});let i=vt(n.schema);return(0,Z.jsxs)(`div`,{className:`settings-schema`,children:[i.length>0&&(0,Z.jsxs)(`table`,{className:`settings-schema-table`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{children:t(`settings.paramName`,null,`参数`)}),(0,Z.jsx)(`th`,{children:t(`settings.paramType`,null,`类型`)}),(0,Z.jsx)(`th`,{children:t(`settings.paramRequired`,null,`必填`)}),(0,Z.jsx)(`th`,{children:t(`settings.paramDesc`,null,`说明`)})]})}),(0,Z.jsx)(`tbody`,{children:i.map(e=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{children:(0,Z.jsx)(Re,{children:e.name})}),(0,Z.jsx)(`td`,{children:e.type}),(0,Z.jsx)(`td`,{children:e.required?(0,Z.jsx)(f,{size:`small`,color:`red`,children:`是`}):(0,Z.jsx)(gt,{type:`tertiary`,children:`否`})}),(0,Z.jsx)(`td`,{children:e.description||`—`})]},e.name))})]}),(0,Z.jsx)(oe,{value:n.schema,collapsed:!0,title:t(`settings.toolSchemaJson`,null,`JSON Schema`)})]})}function xt(){let e=te(),[t]=a(),{hasPermission:n}=j(),r=n(`config:read`),i=n(`config:write`),o=(0,q.useCallback)(({signal:e}={})=>M.get(`/config`,{include_tools:0},{signal:e}),[]),s=re(o,[r],{skip:!r});return r?(0,Z.jsxs)(Z.Fragment,{children:[s.loading&&!s.data?(0,Z.jsx)(Le,{rows:6}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(H,{error:s.error,onRetry:s.reload}),s.data&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ct,{config:s.data,canWrite:i,reloadConfig:s.reload}),(0,Z.jsx)(ht,{config:s.data,canWrite:i,reloadConfig:s.reload,focused:t.get(`focus`)===`vision`})]})]}),(0,Z.jsx)(yt,{})]}):(0,Z.jsx)(Ie,{permission:`config:read`,label:e(`settings.nav.models`,null,`读取模型与工具配置`)})}var{Text:$}=l,St={key:``,payload:null,error:null};function Ct(e){return e!=null&&e!==``&&Number(e)!==0?String(e):e===0?`0`:``}function wt(e={}){let t=e.embedding||{},n=e.retrieval||{},r=n.multi_query||{},i=n.rerank||{},a=n.post_retrieve||{},o=e.indexing||{};return{enabled:!!e.enabled,base_path:e.base_path||`knowledge_base`,embedding_provider:t.provider||`openai`,embedding_model:t.model||``,embedding_base_url:t.base_url||``,embedding_api_key:t.api_key||``,top_k:n.top_k>0?String(n.top_k):`5`,similarity_threshold:n.similarity_threshold>0?String(n.similarity_threshold):`0.4`,sub_index_filter:n.sub_index_filter||``,multi_query_max_queries:r.max_queries>0?String(r.max_queries):``,rerank_provider:i.provider||``,rerank_model:i.model||``,rerank_base_url:i.base_url||``,rerank_api_key:i.api_key||``,prefetch_top_k:Ct(a.prefetch_top_k),max_context_chars:Ct(a.max_context_chars),max_context_tokens:Ct(a.max_context_tokens),chunk_strategy:o.chunk_strategy||``,chunk_size:o.chunk_size>0?String(o.chunk_size):``,chunk_overlap:o.chunk_overlap>0?String(o.chunk_overlap):``,max_chunks_per_item:Ct(o.max_chunks_per_item),batch_size:o.batch_size>0?String(o.batch_size):``,request_timeout_seconds:o.request_timeout_seconds>0?String(o.request_timeout_seconds):``,max_rpm:Ct(o.max_rpm),rate_limit_delay_ms:Ct(o.rate_limit_delay_ms),max_retries:o.max_retries>0?String(o.max_retries):``,retry_delay_ms:o.retry_delay_ms>0?String(o.retry_delay_ms):``,prefer_source_file:!!o.prefer_source_file,sub_indexes:Array.isArray(o.sub_indexes)?o.sub_indexes.join(`, `):``}}function Tt(e,t){let n=String(e??``).trim();if(!n)return 0;if(!/^\d+$/.test(n))throw Error(`${t}请输入非负整数`);let r=Number(n);if(!Number.isSafeInteger(r)||r<0)throw Error(`${t}请输入有效的非负整数`);return r}function Et(e){let t=e?.ai?.channels||{},n=e?.ai?.default_channel||``;if(n&&t[n]){let e=t[n];return{channelId:n,displayName:ue(n,e),openai:{provider:e.provider||`openai_compatible`,base_url:e.base_url||``,api_key:e.api_key||``,model:e.model||``}}}let r=e?.openai||{};return{channelId:``,displayName:r.model||``,openai:{provider:r.provider||`openai_compatible`,base_url:r.base_url||``,api_key:r.api_key||``,model:r.model||``}}}function Dt(){let e=te(),t=r(),{hasPermission:n}=j(),i=n(`config:read`),a=n(`config:write`),o=(0,q.useCallback)(({signal:e}={})=>M.get(`/config`,{include_tools:0},{signal:e}),[]),c=re(o,[i],{skip:!i}),l=(0,q.useId)(),d=(0,q.useId)(),m=(0,q.useId)(),g=(0,q.useId)(),v=(0,q.useMemo)(()=>wt(c.data?.knowledge),[c.data?.knowledge]),y=JSON.stringify(v),[ee,x]=(0,q.useState)({}),S={...v,...ee},C=Object.keys(ee).length>0,[w,T]=(0,q.useState)(``),[E,O]=(0,q.useState)(!1),[k,A]=(0,q.useState)(null),[N,P]=(0,q.useState)(!1),[F,I]=(0,q.useState)(St);if((0,q.useEffect)(()=>{x({}),I(St)},[y]),!i)return(0,Z.jsx)(Ie,{permission:`config:read`,label:e(`settings.nav.knowledge`,null,`读取知识库配置`)});if(c.loading&&!c.data)return(0,Z.jsx)(Le,{rows:6});let L=!a||E||!!w,R=Et(c.data),ne=/api\.deepseek\.com/i.test(R.openai.base_url||``),z=[`claude`,`anthropic`].includes(String(R.openai.provider||``).toLowerCase()),V=!S.embedding_base_url.trim()&&(ne||z),W=(e,t)=>{(F.key!==`list`||[`embedding_provider`,`embedding_base_url`,`embedding_api_key`].includes(e))&&I(St),N||A(null),x(n=>{let r={...n};return t===v[e]?delete r[e]:r[e]=t,r})},G=()=>{x({}),I(St),N||A(null)},ie=()=>{let t=Tt(S.top_k,e(`settingsBasic.topK`,null,`Top-K 结果数量`))||5,n=String(S.similarity_threshold??``).trim(),r=n===``?.4:Number(n);if(!Number.isFinite(r)||r<0||r>1)throw Error(`相似度阈值请输入 0 到 1 之间的数值(例如 0.4)`);let i=Tt(S.multi_query_max_queries,e(`settingsBasic.multiQueryMaxQueries`,null,`MultiQuery 改写变体上限`));if(i>8)throw Error(`MultiQuery 改写变体上限最大为 8(留空使用默认 4,填 1 跳过改写)`);let a=String(S.sub_indexes||``).split(/[,\n\r]+/).map(e=>e.trim()).filter(Boolean);return{enabled:!!S.enabled,base_path:S.base_path.trim()||`knowledge_base`,embedding:{provider:S.embedding_provider.trim()||`openai`,model:S.embedding_model.trim()||`text-embedding-3-small`,base_url:S.embedding_base_url.trim(),api_key:S.embedding_api_key},retrieval:{top_k:t,similarity_threshold:r,sub_index_filter:S.sub_index_filter.trim(),multi_query:{max_queries:i},rerank:{provider:S.rerank_provider.trim(),model:S.rerank_model.trim(),base_url:S.rerank_base_url.trim(),api_key:S.rerank_api_key},post_retrieve:{prefetch_top_k:Tt(S.prefetch_top_k,e(`settingsBasic.prefetchTopK`,null,`预取候选数`)),max_context_chars:Tt(S.max_context_chars,e(`settingsBasic.maxContextChars`,null,`返回内容最大字符数`)),max_context_tokens:Tt(S.max_context_tokens,e(`settingsBasic.maxContextTokens`,null,`返回内容最大 Token 数`))}},indexing:{chunk_strategy:S.chunk_strategy.trim(),chunk_size:Tt(S.chunk_size,e(`settingsBasic.chunkSize`,null,`分块大小`)),chunk_overlap:Tt(S.chunk_overlap,e(`settingsBasic.chunkOverlap`,null,`分块重叠`)),max_chunks_per_item:Tt(S.max_chunks_per_item,e(`settingsBasic.maxChunksPerItem`,null,`单个知识项最大块数`)),batch_size:Tt(S.batch_size,e(`settingsBasic.batchSize`,null,`嵌入批大小`)),request_timeout_seconds:Tt(S.request_timeout_seconds,e(`settingsBasic.requestTimeoutSeconds`,null,`嵌入 HTTP 超时`)),max_rpm:Tt(S.max_rpm,e(`settingsBasic.maxRpm`,null,`每分钟最大请求数`)),rate_limit_delay_ms:Tt(S.rate_limit_delay_ms,e(`settingsBasic.rateLimitDelay`,null,`请求间隔延迟`)),max_retries:Tt(S.max_retries,e(`settingsBasic.maxRetries`,null,`最大重试次数`)),retry_delay_ms:Tt(S.retry_delay_ms,e(`settingsBasic.retryDelay`,null,`重试间隔`)),prefer_source_file:!!S.prefer_source_file,sub_indexes:a}}},ae=async e=>{try{await M.post(`/config/apply`),P(!1),se(e)}catch(e){P(!0),A(e)}},oe=async()=>{if(L||!C)return;if(A(null),S.enabled&&!S.embedding_model.trim()){A(Error(`启用知识库时请填写嵌入模型名称(例如 text-embedding-v4 或 text-embedding-3-small)`));return}let e;try{e=ie()}catch(e){A(e);return}O(!0);try{await M.put(`/config`,{knowledge:e}),x({}),await ae(`知识库配置已保存并应用`),await c.reload({silent:!0})}catch(e){A(e)}finally{O(!1)}},K=async()=>{if(!L&&N){O(!0),A(null);try{await ae(e(`settings.apply.applySuccess`,null,`配置已成功应用`))}finally{O(!1)}}},ce=async()=>{if(!L){if(!S.embedding_model.trim())I({key:`embedding`,payload:null,error:Error(`请先填写嵌入模型名称`)});else{T(`embedding`),I(St);try{let e=await M.post(`/config/test-embedding`,{channel_id:R.channelId||void 0,embedding:{provider:S.embedding_provider.trim()||`openai`,model:S.embedding_model.trim(),base_url:S.embedding_base_url.trim(),api_key:S.embedding_api_key},openai:R.openai});I({key:`embedding`,payload:e,error:null})}catch(e){I({key:`embedding`,payload:null,error:e})}finally{T(``)}}}},le=async()=>{if(L)return;T(`list`),I(St);let e=!!S.embedding_api_key,t=S.embedding_base_url.trim()||(z?``:R.openai.base_url)||`https://api.openai.com/v1`;try{let n=await M.post(`/config/list-models`,{provider:`openai_compatible`,credential_scope:e?`knowledgeEmbedding`:R.channelId?void 0:`openai`,channel_id:!e&&R.channelId?R.channelId:void 0,base_url:t,api_key:e?S.embedding_api_key:R.openai.api_key});I({key:`list`,payload:n,error:null})}catch(e){I({key:`list`,payload:null,error:e})}finally{T(``)}},ue=F.key===`list`&&Array.isArray(F.payload?.models)?F.payload.models:[];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(H,{error:c.error,onRetry:c.reload}),c.data&&(0,Z.jsxs)(U,{title:(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)(`span`,{children:e(`settings.knowledge.title`,null,`知识库设置`)}),(0,Z.jsx)(f,{color:S.enabled?`green`:`grey`,size:`small`,children:S.enabled?e(`common.enabled`,null,`已启用`):e(`common.disabled`,null,`未启用`)}),C&&(0,Z.jsx)(f,{color:`amber`,size:`small`,children:e(`settings.unsaved`,null,`有未保存修改`)})]}),description:`开启后将自动初始化向量知识库并向智能体挂载 search_knowledge_base 检索工具。启用保存后,可前往「知识管理」新增知识条目并构建索引。`,className:`settings-knowledge-panel`,extra:(0,Z.jsxs)(u,{wrap:!0,children:[(0,Z.jsx)(p,{onClick:()=>t(`/knowledge-management`),children:`前往知识管理`}),a?(0,Z.jsxs)(Z.Fragment,{children:[C&&(0,Z.jsx)(p,{disabled:E||!!w,onClick:G,children:e(`toolGuard.reset`,null,`撤销修改`)}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,loading:E,disabled:!C||!!w,onClick:oe,children:e(`settings.saveAndApply`,null,`保存并应用`)})]}):(0,Z.jsx)(f,{color:`grey`,size:`small`,children:e(`settingsProbe.channelReadOnly`,null,`只读`)})]}),children:[(0,Z.jsxs)(`div`,{className:`settings-switch-row`,children:[(0,Z.jsx)(_,{checked:S.enabled,disabled:L,onChange:e=>W(`enabled`,e),"aria-label":e(`settingsBasic.enableKnowledge`,null,`启用知识检索功能`)}),(0,Z.jsxs)(`div`,{className:`settings-switch-copy`,children:[(0,Z.jsx)($,{strong:!0,children:e(`settingsBasic.enableKnowledge`,null,`启用知识检索功能`)}),(0,Z.jsx)(Q,{children:`保存并应用后立即在线生效,无需重启服务。`})]})]}),(0,Z.jsx)(`div`,{className:`settings-vision-grid`,children:(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.knowledgeBasePath`,null,`知识库路径`)}),(0,Z.jsx)(h,{value:S.base_path,onChange:e=>W(`base_path`,e),readOnly:L,placeholder:e(`settingsBasic.knowledgeBasePathPlaceholder`,null,`knowledge_base`)}),(0,Z.jsx)(Q,{children:e(`settingsBasic.knowledgeBasePathHint`,null,`相对于配置文件所在目录的路径`)})]})}),(0,Z.jsxs)(`div`,{className:`settings-subsection`,children:[(0,Z.jsx)($,{strong:!0,className:`settings-subsection-title`,children:e(`settingsBasic.embeddingConfig`,null,`嵌入模型配置`)}),V&&(0,Z.jsx)(s,{type:`info`,bordered:!0,closeIcon:null,description:`提示:当前默认 AI 通道(如 DeepSeek 官方或 Claude 接口)通常不提供 OpenAI 兼容的 /embeddings 向量接口。启用知识库时,请在此处填写独立的向量服务地址与密钥(如阿里云百炼 DashScope、OpenAI、SiliconFlow 或本地 Ollama / vLLM)。`}),(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)($,{id:l,type:`tertiary`,size:`small`,children:e(`settingsBasic.provider`,null,`提供商`)}),(0,Z.jsx)(D,{value:S.embedding_provider||`openai`,onChange:e=>W(`embedding_provider`,e),optionList:[{value:`openai`,label:e(`settingsProbe.compatible`,null,`兼容 OpenAI 的接口`)}],"aria-labelledby":l,disabled:L,style:{width:`100%`}})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.modelName`,null,`模型名称`)}),(0,Z.jsx)(h,{value:S.embedding_model,onChange:e=>W(`embedding_model`,e),readOnly:L,placeholder:e(`settingsBasic.embeddingModelPlaceholder`,null,`text-embedding-v4`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.baseUrl`,null,`API 地址`)}),(0,Z.jsx)(h,{value:S.embedding_base_url,onChange:e=>W(`embedding_base_url`,e),readOnly:L,placeholder:!z&&R.openai.base_url?`留空复用默认通道(${R.openai.base_url})`:`例如 https://dashscope.aliyuncs.com/compatible-mode/v1`})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.apiKey`,null,`API 密钥`)}),(0,Z.jsx)(h,{mode:`password`,autoComplete:`new-password`,value:S.embedding_api_key,onChange:e=>W(`embedding_api_key`,e),readOnly:L,placeholder:e(`settingsBasic.embeddingApiKeyPlaceholder`,null,`留空则使用默认通道 API Key`)})]})]}),(0,Z.jsxs)(u,{wrap:!0,className:`settings-probe-actions`,children:[(0,Z.jsx)(p,{loading:w===`embedding`,disabled:!a||E||!!w&&w!==`embedding`,onClick:ce,children:`测试嵌入模型`}),(0,Z.jsx)(p,{loading:w===`list`,disabled:!a||E||!!w&&w!==`list`,onClick:le,children:e(`settingsBasic.modelsList`,null,`获取模型列表`)})]}),F.error&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:(0,Z.jsx)(H,{error:F.error})}),F.key===`embedding`&&F.payload&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:F.payload.success?(0,Z.jsx)(B,{columns:4,items:[{label:e(`settingsProbe.result`,null,`测试结果`),value:(0,Z.jsx)(f,{color:`green`,children:e(`settingsBasic.testSuccess`,null,`连接成功`)})},{label:e(`settingsBasic.modelName`,null,`模型名称`),value:F.payload.model||S.embedding_model||`—`},{label:`向量维度`,value:F.payload.dimensions?`${F.payload.dimensions} 维`:`—`},{label:e(`settingsProbe.latency`,null,`响应耗时`),value:F.payload.latency_ms==null?`—`:e(`settingsProbe.milliseconds`,{value:F.payload.latency_ms},`${F.payload.latency_ms} 毫秒`)}]}):(0,Z.jsx)(s,{type:`danger`,bordered:!0,closeIcon:null,description:F.payload.error||e(`settingsBasic.testFailed`,null,`连接失败`)})}),F.key===`list`&&F.payload&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:F.payload.success?(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)($,{children:e(`settingsBasic.modelsListSuccess`,{count:F.payload.count??ue.length},`已获取 ${F.payload.count??ue.length} 个模型`)}),(0,Z.jsx)(`span`,{id:g,hidden:!0,children:e(`settingsBasic.modelsListSelectPlaceholder`,null,`请选择嵌入模型`)}),ue.length>0&&(0,Z.jsx)(D,{filter:!0,"aria-labelledby":g,placeholder:e(`settingsBasic.modelsListSelectPlaceholder`,null,`请选择模型`),value:ue.includes(S.embedding_model)?S.embedding_model:void 0,optionList:ue.map(e=>({value:e,label:e})),onChange:e=>W(`embedding_model`,e),disabled:L,className:`settings-model-picker`})]}):(0,Z.jsx)(s,{type:F.payload.supported===!1?`info`:`danger`,bordered:!0,closeIcon:null,description:F.payload.error||e(`settingsBasic.modelsListFailed`,null,`获取模型列表失败`)})})]}),(0,Z.jsxs)(`div`,{className:`settings-subsection`,children:[(0,Z.jsx)($,{strong:!0,className:`settings-subsection-title`,children:e(`settingsBasic.retrievalConfig`,null,`检索配置`)}),(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,children:[(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.topK`,null,`Top-K 结果数量`)}),(0,Z.jsx)(h,{value:S.top_k,onChange:e=>W(`top_k`,e),inputMode:`numeric`,readOnly:L,placeholder:e(`settingsBasic.topKPlaceholder`,null,`5`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.similarityThreshold`,null,`相似度阈值(0 ~ 1)`)}),(0,Z.jsx)(h,{value:S.similarity_threshold,onChange:e=>W(`similarity_threshold`,e),readOnly:L,placeholder:`0.4`})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.multiQueryMaxQueries`,null,`MultiQuery 改写变体上限`)}),(0,Z.jsx)(h,{value:S.multi_query_max_queries,onChange:e=>W(`multi_query_max_queries`,e),inputMode:`numeric`,readOnly:L,placeholder:e(`settingsBasic.multiQueryMaxQueriesPlaceholder`,null,`4`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.subIndexFilter`,null,`子索引过滤(可选)`)}),(0,Z.jsx)(h,{value:S.sub_index_filter,onChange:e=>W(`sub_index_filter`,e),readOnly:L,placeholder:e(`settingsBasic.subIndexFilterPlaceholder`,null,`如 prod,与索引 sub_indexes 一致`)})]})]}),(0,Z.jsx)(Q,{children:e(`settingsBasic.similarityHint`,null,`低于相似度阈值的结果将被过滤;MultiQuery 设为 1 时跳过 LLM 改写直接做向量检索。`)})]}),(N||k)&&(0,Z.jsxs)(`div`,{className:`settings-channel-notices`,children:[N&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(u,{wrap:!0,children:[(0,Z.jsx)(`span`,{children:`知识库配置已写入 config.yaml,但动态应用失败(请检查嵌入模型配置或密钥)。`}),(0,Z.jsx)(p,{size:`small`,disabled:L,onClick:K,children:e(`settingsProbe.retryApply`,null,`重试应用`)})]})}),(0,Z.jsx)(H,{error:k})]}),(0,Z.jsxs)(b,{className:`settings-audit-model`,children:[(0,Z.jsxs)(b.Panel,{itemKey:`knowledge-rerank`,header:(0,Z.jsx)($,{strong:!0,children:e(`settingsBasic.ragPipelineHeader`,null,`高级:精排(Rerank)与检索后处理`)}),children:[(0,Z.jsx)(Q,{children:e(`settingsBasic.ragPipelineHint`,null,`精排失败时会自动降级为融合排序,不影响基础检索可用性。`)}),(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,style:{marginTop:8},children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)($,{id:d,type:`tertiary`,size:`small`,children:e(`settingsBasic.rerankProvider`,null,`精排提供商`)}),(0,Z.jsx)(D,{value:S.rerank_provider,onChange:e=>W(`rerank_provider`,e),optionList:[{value:``,label:e(`settingsBasic.rerankProviderAuto`,null,`自动(按 Base URL 推断)`)},{value:`dashscope`,label:`DashScope(gte-rerank)`},{value:`cohere`,label:e(`settingsBasic.rerankProviderCohere`,null,`Cohere / /v1/rerank 兼容接口`)}],"aria-labelledby":d,disabled:L,style:{width:`100%`}})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.rerankModel`,null,`精排模型(可选)`)}),(0,Z.jsx)(h,{value:S.rerank_model,onChange:e=>W(`rerank_model`,e),readOnly:L,placeholder:e(`settingsBasic.rerankModelPlaceholder`,null,`留空按提供商自动选择`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.rerankBaseUrl`,null,`精排 Base URL(可选)`)}),(0,Z.jsx)(h,{value:S.rerank_base_url,onChange:e=>W(`rerank_base_url`,e),readOnly:L,placeholder:e(`settingsBasic.rerankBaseUrlPlaceholder`,null,`留空则复用嵌入 / OpenAI 的 base_url`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.rerankApiKey`,null,`精排 API Key(可选)`)}),(0,Z.jsx)(h,{mode:`password`,autoComplete:`new-password`,value:S.rerank_api_key,onChange:e=>W(`rerank_api_key`,e),readOnly:L,placeholder:e(`settingsBasic.rerankApiKeyPlaceholder`,null,`留空则复用嵌入 / OpenAI 的 api_key`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.prefetchTopK`,null,`预取候选数`)}),(0,Z.jsx)(h,{value:S.prefetch_top_k,onChange:e=>W(`prefetch_top_k`,e),inputMode:`numeric`,readOnly:L,placeholder:e(`settingsBasic.prefetchTopKPlaceholder`,null,`20`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.maxContextChars`,null,`返回内容最大字符数`)}),(0,Z.jsx)(h,{value:S.max_context_chars,onChange:e=>W(`max_context_chars`,e),inputMode:`numeric`,readOnly:L,placeholder:`0`})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.maxContextTokens`,null,`返回内容最大 Token 数`)}),(0,Z.jsx)(h,{value:S.max_context_tokens,onChange:e=>W(`max_context_tokens`,e),inputMode:`numeric`,readOnly:L,placeholder:`0`})]})]})]}),(0,Z.jsx)(b.Panel,{itemKey:`knowledge-indexing`,header:(0,Z.jsx)($,{strong:!0,children:e(`settingsBasic.indexConfig`,null,`高级:索引分块与限流配置`)}),children:(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)($,{id:m,type:`tertiary`,size:`small`,children:e(`settingsBasic.chunkStrategy`,null,`分块策略`)}),(0,Z.jsx)(D,{value:S.chunk_strategy,onChange:e=>W(`chunk_strategy`,e),optionList:[{value:``,label:e(`settingsBasic.chunkStrategyMarkdownRecursive`,null,`Markdown 标题切分后递归(默认推荐)`)},{value:`markdown_then_recursive`,label:e(`settingsBasic.chunkStrategyMarkdownRecursive`,null,`Markdown 标题切分后递归`)},{value:`recursive`,label:e(`settingsBasic.chunkStrategyRecursive`,null,`仅递归切分`)}],"aria-labelledby":m,disabled:L,style:{width:`100%`}})]}),[[`chunk_size`,`chunkSize`,`分块大小(Chunk Size)`,`512`],[`chunk_overlap`,`chunkOverlap`,`分块重叠(Chunk Overlap)`,`50`],[`max_chunks_per_item`,`maxChunksPerItem`,`单个知识项最大块数`,`0`],[`batch_size`,`batchSize`,`嵌入批大小`,`64`],[`request_timeout_seconds`,`requestTimeoutSeconds`,`嵌入 HTTP 超时(秒)`,`120`],[`max_rpm`,`maxRpm`,`每分钟最大请求数(Max RPM)`,`0`],[`rate_limit_delay_ms`,`rateLimitDelay`,`请求间隔延迟(毫秒)`,`0`],[`max_retries`,`maxRetries`,`最大重试次数`,`3`],[`retry_delay_ms`,`retryDelay`,`重试间隔(毫秒)`,`1000`]].map(([t,n,r,i])=>(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.`+n,null,r)}),(0,Z.jsx)(h,{value:S[t],onChange:e=>W(t,e),inputMode:`numeric`,readOnly:L,placeholder:i})]},t)),(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.subIndexes`,null,`子索引标签(逗号分隔)`)}),(0,Z.jsx)(h,{value:S.sub_indexes,onChange:e=>W(`sub_indexes`,e),readOnly:L,placeholder:e(`settingsBasic.subIndexesPlaceholder`,null,`例如: prod, knowledge`)})]}),(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.preferSourceFile`,null,`优先从磁盘源文件读取`)}),(0,Z.jsx)(_,{checked:S.prefer_source_file,disabled:L,onChange:e=>W(`prefer_source_file`,e),"aria-label":e(`settingsBasic.preferSourceFile`,null,`优先从磁盘源文件读取`)})]})]})})]})]})]})}var{Text:Ot}=l;function kt(e){let t=Number(e);return Number.isFinite(t)&&t>0?Math.trunc(t):0}function At(e){let t=kt(e?.promptTokens),n=kt(e?.cachedTokens);return t?`${(Math.min(n,t)/t*100).toFixed(1)}%`:`—`}var jt=[[`events`,`settingsDisplay.events`,`记录数`],[`modelCalls`,`dashboard.usageCalls`,`模型调用`],[`promptTokens`,`dashboard.usageInput`,`输入令牌`],[`completionTokens`,`dashboard.usageOutput`,`输出令牌`],[`totalTokens`,`dashboard.usageTotal`,`总令牌数`],[`cachedTokens`,`dashboard.usageCacheRead`,`缓存读取`]];function Mt(e,t){return[{title:t,dataIndex:`key`,render:(e,t)=>(0,Z.jsx)(Ot,{strong:!0,children:t.label||e||`—`})},...jt.map(([t,n,r])=>({title:e(n,null,r),dataIndex:t,align:`right`,render:e=>k(kt(e))}))]}function Nt(){let e=te(),{hasPermission:t}=j(),n=t(`dashboard:read`),r=t(`chat:read`),i=(0,q.useId)(),[a,o]=(0,q.useState)(7),[s,c]=(0,q.useState)(365),[l,d]=(0,q.useState)(20),[m,g]=(0,q.useState)(``),_=W(m.trim(),400),[v,y]=(0,q.useState)(null),[b,ee]=(0,q.useState)(!1),[x,S]=(0,q.useState)(``),C=W(x.trim(),300),w=r?v?.value:void 0,T=w?s:a,N=!!w||n,P=r&&b,F=re(async()=>((await M.get(`/conversations`,{search:C||void 0,limit:50}))?.conversations||[]).map(t=>({value:t.id,label:[t.title||e(`chat.untitled`,null,`未命名对话`),A(t.updatedAt||t.createdAt)].join(` · `)})),[P,C,e],{skip:!P}),I=F.data||[],L=v&&!I.some(e=>e.value===v.value)?[v,...I]:I,R=w?void 0:_||void 0,z=w?[`conversation`,w].join(`:`):R||``,B=(0,q.useCallback)(async()=>({scopeKey:z,result:w?await M.get(`/conversations/${encodeURIComponent(w)}/token-usage`,{days:T,limit:l}):await M.get(`/usage/tokens`,{days:T,limit:l,project_id:R})}),[w,T,l,z,R]),V=re(B,[B,N],{skip:!N}),G=N&&z===V.data?.scopeKey?V.data.result:null,ie=G?.summary||{},oe=(0,q.useMemo)(()=>[{id:`total`,label:e(`tokenUsageUI.usageTotal`,null,`总 Token`),value:k(kt(ie.totalTokens))},{id:`input`,label:e(`tokenUsageUI.usageInput`,null,`输入 Token`),value:k(kt(ie.promptTokens))},{id:`output`,label:e(`tokenUsageUI.usageOutput`,null,`输出 Token`),value:k(kt(ie.completionTokens))},{id:`cache`,label:e(`tokenUsageUI.usageCacheRead`,null,`缓存读取`),value:k(kt(ie.cachedTokens))},{id:`cacheWrite`,label:e(`tokenUsageUI.usageCacheWrite`,null,`缓存写入`),value:k(kt(ie.cacheWriteTokens))},{id:`reasoning`,label:e(`tokenUsageUI.usageReasoning`,null,`推理 Token`),value:k(kt(ie.reasoningTokens))},{id:`calls`,label:e(`tokenUsageUI.usageCalls`,null,`模型调用`),value:k(kt(ie.modelCalls))},{id:`rate`,label:e(`tokenUsageUI.usageCacheRate`,null,`缓存命中率`),value:At(ie),detail:e(`tokenUsageUI.cacheNote`,null,`缓存读取是输入的一部分,不重复计入总量`)}],[ie,e]);if(!n&&!r)return(0,Z.jsx)(Ie,{permission:`dashboard:read`,label:e(`settings.nav.tokenUsage`,null,`读取 Token 用量`)});let se=Array.isArray(G?.byDay)?G.byDay:[],K=Array.isArray(G?.byModel)?G.byModel:[],ce=Array.isArray(G?.recent)?G.recent:[],le=G?.today||{},ue=e(`tokenUsageUI.selectConversation`,null,`搜索并选择会话`);return(0,Z.jsxs)(Z.Fragment,{children:[N&&(0,Z.jsx)(H,{error:V.error,onRetry:V.reload}),(0,Z.jsxs)(U,{title:e(`settings.nav.tokenUsage`,null,`Token 用量`),children:[(0,Z.jsxs)(`div`,{className:`settings-token-filters`,children:[r&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{id:i+`-conversation`,hidden:!0,children:ue}),(0,Z.jsx)(D,{className:`settings-token-conversation`,"aria-labelledby":i+`-conversation`,placeholder:ue,value:w,optionList:L,filter:!0,remote:!0,showClear:!0,loading:F.loading,onSearch:S,onDropdownVisibleChange:e=>{ee(e),e||S(``)},onChange:e=>y(L.find(t=>t.value===e)||null)})]}),(0,Z.jsx)(`span`,{id:i+`-days`,hidden:!0,children:e(`settings.usageDays`,null,`时间范围`)}),(0,Z.jsx)(D,{"aria-labelledby":i+`-days`,value:T,onChange:e=>(w?c:o)(Number(e)),style:{width:120},optionList:[7,30,90,365].map(t=>({value:t,label:e(`tokenUsageUI.periodDays`,{count:t},`${t} 天`)}))}),(0,Z.jsx)(`span`,{id:i+`-limit`,hidden:!0,children:e(`tokenUsageUI.recentTitle`,null,`最近记录`)}),(0,Z.jsx)(D,{"aria-labelledby":i+`-limit`,value:l,onChange:e=>d(Number(e)),style:{width:130},optionList:[20,50,100,200].map(t=>({value:t,label:e(`tokenUsageUI.recentLimit`,{count:t},`最近 ${t} 条`)}))}),n&&!w&&(0,Z.jsx)(h,{value:m,onChange:e=>g(e),placeholder:e(`settingsDisplay.projectIdOptional`,null,`项目 ID(可选)`),style:{width:180},showClear:!0}),(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),onClick:V.reload,loading:V.loading,disabled:!N,children:e(`common.refresh`,null,`刷新`)})]}),r&&(0,Z.jsx)(H,{error:F.error,onRetry:F.reload}),N&&(V.loading||!V.error)&&!G&&(0,Z.jsx)(Le,{rows:3}),G&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ne,{metrics:oe,columns:4}),(0,Z.jsxs)(u,{spacing:8,wrap:!0,children:[(0,Z.jsx)(f,{size:`small`,color:`blue`,children:e(`tokenUsageUI.todayTotal`,{total:k(kt(le.totalTokens))},`今日 ${k(kt(le.totalTokens))} tokens`)}),(0,Z.jsx)(f,{size:`small`,color:`grey`,children:e(`tokenUsageUI.todayCalls`,{calls:k(kt(le.modelCalls))},`今日 ${k(kt(le.modelCalls))} 次模型调用`)}),(0,Z.jsx)(f,{size:`small`,color:`green`,children:e(`tokenUsageUI.todayCache`,{rate:At(le)},`今日缓存命中 ${At(le)}`)})]})]})]}),G&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(U,{title:e(`tokenUsageUI.trendTitle`,null,`每日用量`),children:(0,Z.jsx)(ae,{columns:Mt(e,e(`tokenUsageUI.colDay`,null,`日期`)),dataSource:se,rowKey:`key`,loading:V.loading,pagination:!1,emptyText:e(`tokenUsageUI.noDailyData`,null,`暂无每日用量记录`)})}),(0,Z.jsx)(U,{title:e(`tokenUsageUI.modelTitle`,null,`按模型`),children:(0,Z.jsx)(ae,{columns:Mt(e,e(`tokenUsageUI.colModel`,null,`模型`)),dataSource:K,rowKey:`key`,loading:V.loading,pagination:!1,emptyText:e(`common.noData`,null,`暂无数据`)})}),(0,Z.jsx)(U,{title:e(`tokenUsageUI.recentTitle`,null,`最近记录`),children:(0,Z.jsx)(ae,{columns:[{title:e(`tokenUsageUI.colTime`,null,`时间`),dataIndex:`createdAt`,width:180,render:e=>A(e)},{title:e(`tokenUsageUI.colModel`,null,`模型`),dataIndex:`model`,render:e=>e||`—`},{title:e(`settingsDisplay.usageSource`,null,`用量来源`),dataIndex:`source`,render:e=>e||`—`},{title:e(`settingsDisplay.orchestration`,null,`协作方式`),dataIndex:`orchestration`,render:e=>e||`—`},{title:e(`settingsDisplay.tokensBreakdown`,null,`输入 / 输出 / 总令牌数`),align:`right`,render:(e,t)=>`${k(kt(t.promptTokens))} / ${k(kt(t.completionTokens))} / ${k(kt(t.totalTokens))}`},{title:e(`settingsDisplay.conversation`,null,`对话`),dataIndex:`conversationId`,width:200,render:e=>(0,Z.jsx)(Ot,{type:`tertiary`,children:O(e||`—`,18)})}],dataSource:ce,rowKey:`id`,loading:V.loading,pagination:{pageSize:10,showSizeChanger:!1},emptyText:e(`common.noData`,null,`暂无数据`)})})]})]})}var{Text:Pt}=l;function Ft(e,t){let n=parseInt(e,10);return Number.isFinite(n)&&n>=0?n:t}function It(e,t){return e(`settingsStorage.cat.${t.key}`,null,t.label||t.key)}function Lt(e,t){return e(`settingsStorage.catHint.${t.key}`,null,t.hint||``)}function Rt(){let e=te(),{hasPermission:t}=j(),n=t(`storage:read`),r=t(`storage:write`),i=t(`config:write`),a=re(()=>M.get(`/storage/meta`),[n],{skip:!n}),o=re(()=>M.get(`/storage/status`),[n],{skip:!n}),[c,l]=(0,q.useState)(null),[d,f]=(0,q.useState)(``),[m,g]=(0,q.useState)(null),[y,b]=(0,q.useState)(null);(0,q.useEffect)(()=>{if(!a.data)return;let e={};for(let t of a.data.categories||[])e[t.key]={enabled:!!t.enabled,retention_days:Number(t.retention_days)||0};l({auto_clean:!!a.data.auto_clean,interval_minutes:Number(a.data.interval_minutes)||0,orphan_grace_days:Number(a.data.orphan_grace_days)||0,active_grace_hours:Number(a.data.active_grace_hours)||0,categories:e})},[a.data]);let ee=(0,q.useCallback)(async()=>{if(n){f(`status`),g(null);try{let e=await M.get(`/storage/status`,{refresh:1});o.setData(e)}catch(e){g(e)}finally{f(``)}}},[n,o.setData]),x=async()=>{if(!i||!c)return;f(`policy`),g(null);let t={};for(let[e,n]of Object.entries(c.categories||{}))t[e]={enabled:!!n.enabled,retention_days:Ft(n.retention_days,0)};let n={auto_clean:!!c.auto_clean,interval_minutes:Ft(c.interval_minutes,5),orphan_grace_days:Ft(c.orphan_grace_days,0),active_grace_hours:Ft(c.active_grace_hours,1),categories:t};try{await M.put(`/config`,{storage:n}),se(e(`settingsStorage.saved`,null,`清理策略已保存`)),await a.reload()}catch(t){g(t),z(t,e(`settingsStorage.saveFailed`,null,`保存失败`))}finally{f(``)}},S=async t=>{if(r){f(t?`preview`:`clean`),g(null);try{let n=t?await M.post(`/storage/cleanup`,{dry_run:!0}):await M.post(`/storage/cleanup`,{dry_run:!1,confirm:!0});if(b(n),t)se(e(`settingsStorage.previewTitle`,null,`预览完成(未删除任何文件)`));else{se(e(`settingsStorage.cleanDone`,null,`清理完成`));let t=await M.get(`/storage/status`,{refresh:1});o.setData(t)}}catch(t){g(t),z(t,e(`settingsStorage.cleanupFailed`,null,`清理请求失败`))}finally{f(``)}}},w=o.data?.totals||{},T=o.data?.filesystem||{},D=(0,q.useMemo)(()=>[{label:e(`settingsStorage.diskUsed`,null,`磁盘已用`),value:T.available?R(T.used_bytes):e(`settingsStorage.unavailable`,null,`不可用`)},{label:e(`settingsStorage.runtimeTotal`,null,`运行空间占用`),value:`${R(w.bytes)}(${k(w.units)} ${e(`settingsStorage.itemsUnit`,null,`项`)})`},{label:e(`settingsStorage.reclaimable`,null,`可回收`),value:`${R(w.reclaimable_bytes)}(${k(w.reclaimable_units)} ${e(`settingsStorage.itemsUnit`,null,`项`)})`},{label:e(`settingsStorage.inodes`,null,`inode 使用`),value:T.available&&T.inodes_total>0?`${k(T.inodes_total-T.inodes_free)} / ${k(T.inodes_total)}`:e(`settingsStorage.unavailable`,null,`不可用`)}],[T,w,e]);if(!n)return(0,Z.jsx)(Ie,{permission:`storage:read`,label:e(`settings.nav.storage`,null,`读取存储状态`)});if(a.loading&&!a.data||o.loading&&!o.data)return(0,Z.jsx)(Le,{rows:6});let O=(a.data?.categories||[]).map(e=>{let t=(o.data?.categories||[]).find(t=>t.key===e.key)||{};return{...e,stat:t,key:e.key}}),N=[{title:e(`settingsStorage.colCategory`,null,`类别`),dataIndex:`label`,width:200,render:(t,n)=>(0,Z.jsx)(C,{content:Lt(e,n),position:`topLeft`,children:(0,Z.jsxs)(u,{vertical:!0,spacing:2,align:`start`,children:[(0,Z.jsx)(Pt,{strong:!0,children:It(e,n)}),n.stat.missing&&(0,Z.jsx)(Pt,{type:`tertiary`,size:`small`,children:e(`settingsStorage.unused`,null,`未使用`)})]})})},{title:e(`settingsStorage.colRoot`,null,`目录`),dataIndex:`key`,render:(e,t)=>(0,Z.jsx)(C,{content:t.stat.root||``,position:`topLeft`,children:(0,Z.jsx)(Re,{children:t.stat.missing?`—`:t.stat.root||`—`})})},{title:e(`settingsStorage.colUnits`,null,`项目数`),align:`right`,width:100,render:(e,t)=>t.stat.missing?`—`:k(t.stat.units)},{title:e(`settingsStorage.colSize`,null,`占用`),align:`right`,width:110,render:(e,t)=>t.stat.missing?`—`:R(t.stat.bytes)},{title:e(`settingsStorage.colReclaimable`,null,`可回收`),align:`right`,width:190,render:(t,n)=>n.stat.missing?`—`:(0,Z.jsxs)(u,{vertical:!0,spacing:2,align:`end`,children:[(0,Z.jsx)(Pt,{strong:!0,children:R(n.stat.reclaimable_bytes)}),(0,Z.jsxs)(Pt,{type:`tertiary`,size:`small`,children:[`${k(n.stat.reclaimable_units)} ${e(`settingsStorage.itemsUnit`,null,`项`)}`,n.stat.orphan_units?` · ${e(`settingsStorage.orphanSuffix`,null,`含孤儿`)} ${n.stat.orphan_units}`:``,n.stat.skipped_active?` · ${e(`settingsStorage.skippedActive`,null,`跳过活跃`)} ${n.stat.skipped_active}`:``]})]})},{title:e(`settingsStorage.colRetention`,null,`保留天数`),width:130,render:(e,t)=>(0,Z.jsx)(h,{value:String(c?.categories?.[t.key]?.retention_days??0),disabled:!i||d===`policy`,onChange:e=>l(n=>n&&{...n,categories:{...n.categories,[t.key]:{...n.categories[t.key]||{},retention_days:e===``?``:Ft(e,0)}}}),style:{width:96}})},{title:e(`settingsStorage.colEnabled`,null,`启用`),width:90,render:(t,n)=>(0,Z.jsx)(_,{size:`small`,checked:!!c?.categories?.[n.key]?.enabled,disabled:!i||d===`policy`,onChange:e=>l(t=>t&&{...t,categories:{...t.categories,[n.key]:{...t.categories[n.key]||{},enabled:e}}}),"aria-label":e(`settingsStorage.colEnabled`,null,`启用`)})}];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(H,{error:a.error,onRetry:a.reload}),(0,Z.jsx)(H,{error:o.error,onRetry:o.reload}),(0,Z.jsx)(H,{error:m}),(0,Z.jsxs)(U,{title:e(`settingsStorage.title`,null,`存储清理`),description:e(`settingsStorage.subtitle`,null,`统计并清理运行期间产生的磁盘垃圾。删除不可逆,建议先预览再执行。`),extra:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),loading:d===`status`,onClick:ee,children:e(`settingsStorage.refresh`,null,`重新扫描`)}),(0,Z.jsx)(p,{loading:d===`preview`,disabled:!r,onClick:()=>S(!0),children:e(`settingsStorage.preview`,null,`预览可清理项`)}),(0,Z.jsx)(p,{type:`danger`,theme:`light`,loading:d===`clean`,disabled:!r,onClick:()=>K({title:e(`settingsStorage.cleanNow`,null,`立即清理`),content:e(`settingsStorage.confirmClean`,{size:R(w.reclaimable_bytes),count:k(w.reclaimable_units)},`将永久删除约 ${R(w.reclaimable_bytes)}(${k(w.reclaimable_units)} 项)运行空间文件,无法恢复。确认继续?`),okText:e(`settingsStorage.cleanNow`,null,`立即清理`),onOk:()=>S(!1)}),children:e(`settingsStorage.cleanNow`,null,`立即清理`)})]}),children:[T.available&&(0,Z.jsxs)(`div`,{className:`settings-disk`,children:[(0,Z.jsx)(v,{percent:Math.max(0,Math.min(100,Number(T.used_percent)||0)),stroke:Number(T.used_percent)>=85?`var(--semi-color-danger)`:void 0,showInfo:!0}),(0,Z.jsxs)(Q,{children:[`${R(T.free_bytes)} ${e(`settingsStorage.free`,null,`可用`)} / ${R(T.total_bytes)}`,o.data?.scanned_at?` · ${e(`settingsStorage.scannedAt`,null,`扫描于`)} ${A(o.data.scanned_at)}`:``]})]}),(0,Z.jsx)(B,{items:D,columns:4})]}),(0,Z.jsxs)(U,{title:e(`settingsStorage.policyTitle`,null,`自动清理策略`),extra:(0,Z.jsx)(p,{theme:`solid`,type:`primary`,loading:d===`policy`,disabled:!i||!c,onClick:x,children:e(`settingsStorage.save`,null,`保存策略`)}),children:[(0,Z.jsxs)(`div`,{className:`settings-policy-grid`,children:[(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(Pt,{type:`tertiary`,size:`small`,children:e(`settingsStorage.autoClean`,null,`开启后台定时清理`)}),(0,Z.jsx)(_,{checked:!!c?.auto_clean,disabled:!i,onChange:e=>l(t=>t&&{...t,auto_clean:e})})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(Pt,{type:`tertiary`,size:`small`,children:e(`settingsStorage.intervalMinutes`,null,`清理间隔(分钟)`)}),(0,Z.jsx)(h,{value:String(c?.interval_minutes??``),disabled:!i,onChange:e=>l(t=>t&&{...t,interval_minutes:e===``?``:Ft(e,5)})})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(Pt,{type:`tertiary`,size:`small`,children:e(`settingsStorage.orphanGraceDays`,null,`孤儿目录宽限(天)`)}),(0,Z.jsx)(h,{value:String(c?.orphan_grace_days??``),disabled:!i,onChange:e=>l(t=>t&&{...t,orphan_grace_days:e===``?``:Ft(e,0)})})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(Pt,{type:`tertiary`,size:`small`,children:e(`settingsStorage.activeGraceHours`,null,`活跃会话保护(小时)`)}),(0,Z.jsx)(h,{value:String(c?.active_grace_hours??``),disabled:!i,onChange:e=>l(t=>t&&{...t,active_grace_hours:e===``?``:Ft(e,1)})})]})]}),(0,Z.jsx)(Q,{children:e(`settingsStorage.policyHint`,null,`保留天数为 0 表示不按保留期清理,但孤儿目录仍会回收;最近有活动的会话不会被清理。`)})]}),(0,Z.jsx)(U,{title:e(`settingsStorage.categoriesTitle`,null,`分类占用与保留策略`),children:(0,Z.jsx)(ae,{columns:N,dataSource:O,rowKey:`key`,loading:o.loading||a.loading,pagination:!1,emptyText:e(`settingsStorage.noCategories`,null,`暂无可清理类别`)})}),y&&(0,Z.jsxs)(U,{title:y.dry_run?e(`settingsStorage.previewTitle`,null,`预览结果(未删除任何文件)`):e(`settingsStorage.cleanDone`,null,`清理完成`),children:[(0,Z.jsx)(B,{columns:3,items:[{label:e(`settingsStorage.colUnits`,null,`项目数`),value:k(y.dry_run?y.totals?.reclaimable_units:y.totals?.removed_units)},{label:y.dry_run?e(`settingsStorage.reclaimable`,null,`可回收`):e(`settingsDisplay.freed`,null,`已释放空间`),value:R(y.dry_run?y.totals?.reclaimable_bytes:y.totals?.freed_bytes)},{label:e(`settingsDisplay.errors`,null,`错误数`),value:k(y.totals?.errors)},{label:e(`settingsStorage.skippedActive`,null,`跳过活跃`),value:k(y.totals?.skipped_active)},{label:e(`settingsDisplay.cleanupDuration`,null,`清理耗时`),value:e(`settingsProbe.milliseconds`,{value:k(y.duration_ms??0)},`${k(y.duration_ms??0)} 毫秒`)}]}),(y.categories||[]).filter(e=>e.errors?.length).length>0&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(y.categories||[]).filter(e=>e.errors?.length).map(t=>`${It(e,t)}:${t.errors.slice(0,3).join(`;`)}`).join(` / `)})]})]})}var{Text:zt}=l;function Bt(e){let t=String(e||``);return t?t.slice(0,12):`—`}function Vt(e,t){return t?(0,Z.jsx)(f,{size:`small`,color:`green`,children:e(`common.yes`,null,`是`)}):(0,Z.jsx)(f,{size:`small`,color:`grey`,children:e(`common.no`,null,`否`)})}function Ht(e,t){return t===`running`?e(`update.stateRunning`,null,`进行中`):t===`succeeded`?e(`update.stateSucceeded`,null,`已完成`):t===`failed`?e(`update.stateFailed`,null,`失败`):e(`update.stateUnknown`,null,`未知状态`)}function Ut(e){return e===`succeeded`?`green`:e===`failed`?`red`:e===`running`?`blue`:`grey`}function Wt(e,t){return t.installed?t.diverged?e(`update.blockedDiverged`,{ahead:t.ahead,behind:t.behind}):!t.updateAvailable&&!t.buildPending?``:t.rollbackPending?e(`updateUi.rollbackPending`):t.blockingChanges?.length?e(`update.blockedLocalEdits`,{n:t.blockingChanges.length}):``:e(`update.blockedNotGitTree`)}function Gt(){let e=te(),{hasPermission:t}=j(),n=t(`update:read`),r=t(`update:apply`),i=re(()=>M.get(`/system/update`),[n],{skip:!n}),[a,o]=(0,q.useState)(null),[l,d]=(0,q.useState)(``),[m,g]=(0,q.useState)(null),[_,v]=(0,q.useState)(null),[y,b]=(0,q.useState)(null),[ee,x]=(0,q.useState)(null),[S,C]=(0,q.useState)(null),[w,N]=(0,q.useState)(``),[P,F]=(0,q.useState)([]),[R,ne]=(0,q.useState)(``),[z,V]=(0,q.useState)(!1),[W,G]=(0,q.useState)(!1),[ie,ae]=(0,q.useState)(null);(0,q.useEffect)(()=>{i.data&&o(i.data.job||null)},[i.data]);let oe=a?.state===`running`,K=a?.state===`succeeded`&&a.restartRequested,ce=oe||K?a.id:null,le=y||i.data?.bootID,ue=a?.result?.toCommit,J=i.reload,de=i.data?.needsRestart,fe=i.data?.source,pe=fe?.repo||``,Y=fe?.branch||``,me=ee??pe,he=S??Y,ge=me.trim()!==pe||he.trim()!==Y,_e=!!(l||oe||K),ve=W||_e||i.loading;(0,q.useEffect)(()=>{if(!ce)return;let t=!1,n,r=async()=>{try{let{job:n}=await M.get(`/system/update/job`,void 0,{timeout:5e3});if(t)return;if(n?.id===ce){if(o(n),n.state!==`running`&&!n.restartRequested){g(null),n.state===`succeeded`&&(n.result?.needsRestart?L(e(`update.needsRestartToast`)):se(e(`update.jobDoneToast`))),J({silent:!0});return}}else{let e=await M.get(`/system/update`,void 0,{timeout:5e3});if(t)return;let n=le&&e.bootID&&e.bootID!==le,r=!ue||!e.buildRevision||e.buildRevision.startsWith(ue);if(n&&r&&!e.needsRestart){window.location.reload();return}}}catch{}t||(n=setTimeout(r,2e3))};return r(),()=>{t=!0,clearTimeout(n)}},[ce,le,ue,J,e]);let ye=async()=>{if(!r||ve||ge)return;d(`checking`),v(null),g(null);let t=!1;try{let{status:n}=await M.post(`/system/update/check`,{});if(!n)throw Error(e(`updateUi.statusMissing`));if(g(n),n.checkError)return;let r=Wt(e,n);if(r){v(Error(r));return}if(!n.updateAvailable&&!n.buildPending){de?L(e(`update.needsRestartToast`)):n.ahead>0?se(e(`updateUi.noNewerVersion`)):se(e(`updateUi.currentVersion`));return}t=!0,d(`starting`);let a=!!(i.data?.autoRestart??i.data?.canRestart),s=await M.post(`/system/update/apply`,{restart:a});if(!s?.job_id)throw Error(e(`updateUi.jobMissing`));b(s.bootID||null),o({id:s.job_id,kind:`apply`,state:s.state||`running`,restartRequested:a})}catch(n){let r=n.status===409&&n.payload?.job;if(t&&r?.id){b(n.payload.bootID||null),o(r);return}v(Error(e(t?`update.applyFailed`:`update.checkFailed`,{reason:I(n)}))),t&&J({silent:!0})}finally{d(``)}},be=async()=>{V(!0),ae(null);try{let t=me.trim(),n=await M.get(`/system/update/branches`,t?{repo:t}:void 0),r=Array.isArray(n?.branches)?n.branches:[];F(r),ne(n?.defaultBranch||``),se(e(`updateUi.branchesLoaded`,{n:r.length},`已获取 ${r.length} 个远端分支`))}catch(e){ae(e)}finally{V(!1)}},xe=async t=>{if(t.preventDefault(),fe&&r&&ge&&!ve){G(!0),ae(null);try{let t=await M.post(`/system/update/source`,{repo:me.trim(),branch:he.trim()});if(!t?.source||typeof t.source.repo!=`string`)throw Error(e(`updateUi.sourceResponseMissing`,null,`服务端未返回更新源,刷新后可核对配置。`));i.setData(e=>({...e,source:t.source})),x(null),C(null),g(null),v(null),se(e(`update.sourceSaveOk`,null,`更新源已保存`))}catch(e){ae(e)}finally{G(!1)}}};if(!n)return(0,Z.jsx)(Ie,{permission:`update:read`,label:e(`settings.nav.update`,null,`读取安装树版本`)});if(i.loading&&!i.data)return(0,Z.jsx)(Le,{rows:6});let X=m||i.data?.status||{},Se=i.data?.binaryBuiltAt,Ce=[{label:e(`update.root`,null,`安装目录`),value:(0,Z.jsx)(Re,{children:X.root||`—`})},{label:e(`update.gitTree`,null,`Git 安装树`),value:Vt(e,X.installed)},{label:e(`update.branch`,null,`当前分支`),value:X.branch||`—`},{label:e(`updateUi.targetBranch`,null,`目标分支`),value:Y?(0,Z.jsxs)(u,{spacing:4,children:[(0,Z.jsx)(Re,{children:Y}),X.branch&&Y!==X.branch&&(0,Z.jsx)(f,{size:`small`,color:`amber`,children:e(`updateUi.branchSwitchPending`,null,`待切换`)})]}):(0,Z.jsx)(zt,{type:`tertiary`,children:e(`updateUi.followDefaultBranch`,null,`跟随仓库默认分支`)})},{label:e(`updateUi.repo`,null,`更新源仓库`),value:(0,Z.jsx)(Re,{children:fe?.repo||fe?.defaultRepo||X.repo||`—`})},{label:e(`update.commit`,null,`当前提交`),value:(0,Z.jsx)(Re,{children:Bt(X.commit)})},{label:e(`update.subject`,null,`提交说明`),value:O(X.subject||`—`,80)},{label:e(`update.committedAt`,null,`提交时间`),value:X.committedAt?A(X.committedAt):`—`},{label:e(`update.runningBuild`,null,`运行构建`),value:i.data?.buildRevision?Bt(i.data.buildRevision):`—`},{label:e(`update.toolchainFound`,null,`Go 工具链`),value:Vt(e,X.canBuild)},{label:e(`update.binaryPresent`,null,`已构建二进制`),value:Vt(e,X.hasBinary)},{label:e(`updateUi.buildPending`,null,`待编译`),value:Vt(e,X.buildPending)},{label:e(`update.restartPending`,null,`需重启激活`),value:de?(0,Z.jsxs)(u,{spacing:4,children:[(0,Z.jsx)(f,{size:`small`,color:`amber`,children:e(`common.yes`,null,`是`)}),Se&&(0,Z.jsx)(zt,{type:`tertiary`,size:`small`,children:A(Se)})]}):(0,Z.jsx)(f,{size:`small`,color:`green`,children:e(`common.no`,null,`否`)})},{label:e(`updateUi.localChanges`,null,`本机改动文件数`),value:k((X.localChanges||[]).length)},{label:e(`updateUi.blockingChanges`,null,`阻止更新的文件数`),value:k((X.blockingChanges||[]).length)}],we=Array.isArray(m?.incoming)?m.incoming:[];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(H,{error:i.error,onRetry:i.reload}),(0,Z.jsxs)(U,{title:e(`update.installTitle`,null,`安装信息`),description:e(`updateUi.pageHint`),extra:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),onClick:()=>J(),loading:i.loading,disabled:W||_e,children:e(`common.refresh`,null,`刷新`)}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,icon:(0,Z.jsx)(c,{"aria-hidden":`true`}),loading:!!l,disabled:!r||ve||ge,onClick:ye,children:e(l===`checking`?`update.checking`:l===`starting`?`updateUi.starting`:`updateUi.updateButton`)})]}),children:[!r&&(0,Z.jsx)(Q,{children:e(`updateUi.updatePermission`)}),ge&&(0,Z.jsx)(Q,{children:e(`updateUi.saveSourceFirst`)}),(0,Z.jsx)(B,{items:Ce,columns:3}),X.goToolchain&&(0,Z.jsxs)(Q,{children:[e(`updateUi.toolchainPath`,null,`Go 工具链路径`),` `,(0,Z.jsx)(Re,{children:X.goToolchain})]})]}),fe&&(0,Z.jsx)(U,{title:e(`update.sourceTitle`,null,`更新源`),children:(0,Z.jsxs)(`form`,{className:`settings-update-source-form`,onSubmit:xe,children:[(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(zt,{size:`small`,type:`tertiary`,children:e(`update.sourceUrlLabel`,null,`更新源仓库地址`)}),(0,Z.jsx)(h,{value:me,onChange:e=>{x(e),F([]),ae(null)},placeholder:fe.defaultRepo,readOnly:!r,disabled:W})]}),(0,Z.jsxs)(`div`,{className:`settings-field`,style:{marginTop:12},children:[(0,Z.jsx)(zt,{size:`small`,type:`tertiary`,children:e(`updateUi.targetBranchLabel`,null,`目标分支(留空 = 跟随仓库默认分支)`)}),(0,Z.jsxs)(u,{style:{width:`100%`},wrap:!0,children:[(0,Z.jsx)(D,{value:he||void 0,onChange:e=>{C(e||``),N(``),ae(null)},onSearch:e=>N(String(e||``)),onDropdownVisibleChange:e=>{e&&P.length===0&&!z&&be()},placeholder:e(`updateUi.targetBranchPlaceholder`,null,`留空跟随默认分支,或选择/输入分支名`),filter:!0,showClear:!0,loading:z,disabled:!r||W,style:{width:340,maxWidth:`100%`},optionList:[...new Set([...P||[],...Y?[Y]:[],...he&&he.trim()?[he.trim()]:[],...w.trim()?[w.trim()]:[]])].map(t=>({value:t,label:t===R?`${t} (${e(`updateUi.defaultBranchTag`,null,`默认`)})`:t}))}),(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),loading:z,disabled:W,onClick:be,children:e(`updateUi.fetchBranches`,null,`获取远端分支`)})]})]}),r?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Q,{children:e(`update.sourceRepoHint`,null,`留空即使用官方仓库;分支留空即跟随默认分支。`)}),(0,Z.jsx)(Q,{children:e(`updateUi.sourceSaveBranchHint`,null,`保存会修改配置文件中的 update.repo 与 update.branch,下次点击「更新」时自动拉取并切换至该分支。`)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(p,{htmlType:`submit`,theme:`solid`,loading:W,disabled:!ge||ve,children:e(`update.sourceSaveBtn`,null,`保存更新源`)})}),oe&&(0,Z.jsx)(Q,{children:e(`update.blockedJobRunning`,null,`已有更新在进行中,请等它结束。`)})]}):(0,Z.jsx)(Q,{children:e(`updateUi.sourcePermission`,null,`需要更新管理权限才能在这里保存地址。`)}),(0,Z.jsx)(H,{error:ie})]})}),(0,Z.jsxs)(U,{title:e(`update.remoteTitle`,null,`远端版本`),children:[(0,Z.jsx)(H,{error:_,onRetry:r&&!ve&&!ge?ye:void 0}),!m&&!_&&(0,Z.jsx)(zt,{type:`tertiary`,children:e(`updateUi.versionUnchecked`,null,`尚未检查远端版本。`)}),m&&(0,Z.jsxs)(Z.Fragment,{children:[m.checkError?(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:e(`update.checkFailed`,{reason:m.checkError},`检查失败:${m.checkError}`)}):(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[m.installed&&(0,Z.jsx)(f,{size:`small`,color:m.updateAvailable||m.buildPending||de?`amber`:`green`,children:m.branchSwitch?e(`updateUi.branchSwitchTag`,{from:m.branch,to:m.targetBranch},`切换分支:${m.branch} → ${m.targetBranch}`):m.updateAvailable?e(`update.behindCount`,{n:m.behind}):m.buildPending?e(`updateUi.buildPending`):e(de?`update.restartNeeded`:m.ahead>0?`updateUi.noNewerVersion`:`updateUi.currentVersion`)}),m.ahead>0&&(0,Z.jsx)(f,{size:`small`,color:`blue`,children:e(`update.aheadCount`,{n:m.ahead},`领先 ${m.ahead} 个提交`)}),m.diverged&&(0,Z.jsx)(f,{size:`small`,color:`red`,children:e(`updateUi.diverged`,null,`本机与远端提交历史已分叉`)}),(0,Z.jsxs)(zt,{type:`tertiary`,children:[e(`update.remoteHead`,null,`远端 HEAD`),`:`,(0,Z.jsx)(Re,{children:Bt(m.remoteCommit)}),m.targetBranch?`(${m.targetBranch})`:``]})]}),(m.remoteSubject||we.length>0)&&(0,Z.jsxs)(`div`,{className:`settings-incoming`,children:[(0,Z.jsx)(zt,{type:`tertiary`,size:`small`,children:e(`update.incomingTitle`,null,`待合入提交`)}),(0,Z.jsx)(`ul`,{children:we.slice(0,10).map((e,t)=>(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(Re,{children:Bt(e.commit)}),` `,O(e.subject||``,90)]},`${e.commit||`commit`}-${t}`))}),m.incomingTotal>Math.min(10,we.length)&&(0,Z.jsx)(Q,{children:e(`update.incomingTruncated`,{total:m.incomingTotal,shown:Math.min(10,we.length)})})]})]})]}),(0,Z.jsxs)(U,{title:e(`update.jobTitle`,null,`更新任务进度`),extra:a?(0,Z.jsx)(f,{size:`small`,color:Ut(a.state),children:Ht(e,a.state)}):null,children:[K&&(0,Z.jsx)(Q,{children:e(`update.restartRequestedToast`)}),de&&!_e&&(0,Z.jsx)(Q,{children:e(`update.needsRestartToast`)}),X.buildPending&&!_e&&(0,Z.jsx)(Q,{children:e(`updateUi.resumeBuild`)}),!a&&(0,Z.jsx)(zt,{type:`tertiary`,children:e(`update.noJob`,null,`暂无更新任务记录。`)}),a&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(B,{columns:3,items:[{label:e(`updateUi.taskId`,null,`任务编号`),value:(0,Z.jsx)(Re,{children:Bt(a.id)})},{label:e(`updateUi.kind`,null,`任务类型`),value:a.kind?e(`updateUi.kinds.`+a.kind,null,a.kind):`—`},{label:e(`updateUi.started`,null,`开始时间`),value:a.started?A(a.started):`—`},{label:e(`updateUi.finished`,null,`结束时间`),value:a.finished?A(a.finished):`—`},{label:e(`updateUi.restartRequested`,null,`已请求重启`),value:Vt(e,a.restartRequested)},{label:e(`updateUi.restartError`,null,`重启错误`),value:a.restartError||`—`}]}),Array.isArray(a.steps)&&a.steps.length>0&&(0,Z.jsx)(T,{className:`settings-update-steps`,children:a.steps.map((t,n)=>(0,Z.jsxs)(T.Item,{children:[(0,Z.jsx)(zt,{strong:!0,children:e(`updateUi.phases.`+t.phase,null,t.phase)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(zt,{type:`tertiary`,size:`small`,children:O(t.message||``,160)})}),(0,Z.jsx)(zt,{type:`tertiary`,size:`small`,children:t.at?A(t.at):``})]},`${t.phase}-${n}`))}),a.result&&(0,Z.jsx)(B,{columns:3,items:[{label:e(`updateUi.fromCommit`,null,`更新前提交`),value:(0,Z.jsx)(Re,{children:Bt(a.result.fromCommit)})},{label:e(`updateUi.toCommit`,null,`更新后提交`),value:(0,Z.jsx)(Re,{children:Bt(a.result.toCommit)})},{label:e(`update.resultCommits`,null,`并入提交数`),value:k(a.result.commits)},{label:e(`update.resultFiles`,null,`改动文件数`),value:k(a.result.filesTouched)},{label:e(`updateUi.keptContent`,null,`保留的本机文件数`),value:k((a.result.keptContent||[]).length)},{label:e(`updateUi.overwritten`,null,`覆盖的文件数`),value:k((a.result.overwritten||[]).length)}]}),a.failure&&(0,Z.jsx)(s,{type:`danger`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{children:a.failure.message||a.failure.reason}),(a.failure.items||[]).length>0&&(0,Z.jsx)(`ul`,{children:a.failure.items.slice(0,6).map(e=>(0,Z.jsx)(`li`,{children:e},e))})]})})]})]})]})}var{Text:Kt}=l,qt={auth:[`login`,`logout`,`change_password`],config:[`apply`,`update`],c2:[`listener_create`,`listener_delete`,`listener_start`,`listener_stop`,`session_delete`,`task_create`,`task_cancel`,`task_delete`],webshell:[`connection_create`,`connection_delete`],knowledge:[`item_delete`,`index_build`,`index_rebuild_full`],conversation:[`create`,`delete`,`delete_turn`],vulnerability:[`create`,`update`,`delete`],external_mcp:[`upsert`,`delete`],task:[`create_queue`,`start_queue`,`delete_queue`,`pause_queue`,`rerun_queue`,`delete_batch_task`],tool:[`execution_delete`,`execution_delete_batch`],file:[`upload`,`delete`],hitl:[`decision`,`audit_strategy_update`],role:[`create`,`update`,`delete`],skill:[`create`,`update`,`delete`],agent:[`markdown_create`,`markdown_update`,`markdown_delete`]},Jt={category:``,action:``,result:``,q:``,since:null,until:null};function Yt(e){return e===`external_mcp`?`externalMcp`:e}function Xt(e){let t={};return e.category&&(t.category=e.category),e.action&&(t.action=e.action),e.result&&(t.result=e.result),e.q&&(t.q=e.q),e.since&&(t.since=e.since.toISOString()),e.until&&(t.until=e.until.toISOString()),t}function Zt({result:e,label:t}){let n=String(e||``).toLowerCase();return(0,Z.jsx)(f,{size:`small`,color:n===`failure`||n===`failed`||n===`error`?`red`:n===`success`?`green`:`grey`,children:t||e||`—`})}function Qt(){let e=te(),{hasPermission:t}=j(),n=t(`audit:read`),r=re(()=>M.get(`/audit/meta`),[n],{skip:!n}),[i,a]=(0,q.useState)(Jt),[o,c]=(0,q.useState)(Jt),[l,d]=(0,q.useState)(1),[m,g]=(0,q.useState)(20),[_,v]=(0,q.useState)(``),[y,b]=(0,q.useState)(``),S=(0,q.useMemo)(()=>Xt(o),[o]),T=(0,q.useCallback)(()=>M.get(`/audit/summary`,S),[S]),P=re(T,[S,n],{skip:!n}),F=(0,q.useCallback)(()=>M.get(`/audit/logs`,{...S,page:l,page_size:m}),[S,l,m]),I=re(F,[S,l,m,n],{skip:!n}),L=(0,q.useCallback)(t=>t?e(`settingsAudit.cat.${Yt(t)}`,null,t):`—`,[e]),R=(0,q.useCallback)(t=>t?e(`settingsAudit.act.${t}`,null,t):`—`,[e]),B=(0,q.useCallback)(t=>t?e(`settingsAudit.result.${t}`,null,t):`—`,[e]),V=(0,q.useMemo)(()=>[{value:``,label:e(`settingsAudit.filterAllCategories`,null,`全部类别`)},...Object.keys(qt).map(e=>({value:e,label:L(e)}))],[L,e]),W=(0,q.useMemo)(()=>{let t=i.category&&qt[i.category]||[];return[{value:``,label:e(`settingsAudit.filterAllActions`,null,`全部操作`)},...t.map(e=>({value:e,label:R(e)}))]},[R,i.category,e]),G=()=>{let e={...i};e.category||(e.action=``),c(e),d(1)},ie=()=>{a(Jt),c(Jt),d(1)},oe=()=>{P.reload(),I.reload()},K=async t=>{if(n){b(t);try{let n=`audit-logs-${new Date().toISOString().slice(0,10)}.${t===`csv`?`csv`:`json`}`;await N(`/audit/logs/export`,{query:{...S,format:t===`csv`?`csv`:void 0},filename:n}),se(e(`settingsAudit.exportDone`,null,`导出完成`))}catch(t){z(t,e(`common.downloadFailed`,null,`导出失败`))}finally{b(``)}}};if(!n)return(0,Z.jsx)(Ie,{permission:`audit:read`,label:e(`settings.nav.audit`,null,`读取审计日志`)});if(r.loading&&!r.data)return(0,Z.jsx)(Le,{rows:6});let ce=Number(P.data?.total)||0,le=Number(P.data?.failures)||0,ue=Number(P.data?.recent_7d)||0,J=[{title:e(`settingsAudit.colTime`,null,`时间`),dataIndex:`createdAt`,width:180,render:e=>A(e)},{title:e(`settingsAudit.colMessage`,null,`说明`),dataIndex:`message`,render:(e,t)=>(0,Z.jsx)(C,{content:e||`—`,position:`topLeft`,children:(0,Z.jsxs)(u,{spacing:6,children:[t.level&&t.level!==`info`&&(0,Z.jsx)(f,{size:`small`,color:t.level===`error`?`red`:`amber`,children:t.level}),(0,Z.jsx)(Kt,{children:O(e||`—`,68)})]})})},{title:e(`settingsAudit.colCategory`,null,`类别`),dataIndex:`category`,width:120,render:e=>(0,Z.jsx)(f,{size:`small`,color:`blue`,children:L(e)})},{title:e(`settingsAudit.colAction`,null,`操作`),dataIndex:`action`,width:170,render:e=>(0,Z.jsx)(Kt,{type:`tertiary`,children:R(e)})},{title:e(`settingsAudit.colResult`,null,`结果`),dataIndex:`result`,width:100,render:e=>(0,Z.jsx)(Zt,{result:e,label:B(e)})},{title:e(`settingsAudit.colIp`,null,`IP`),dataIndex:`clientIp`,width:140,render:e=>(0,Z.jsx)(Re,{children:e||`—`})},{title:e(`settingsAudit.colResource`,null,`资源 ID`),dataIndex:`resourceId`,width:200,render:(e,t)=>(0,Z.jsx)(C,{content:[t.resourceType,e].filter(Boolean).join(` · `)||`—`,position:`topLeft`,children:(0,Z.jsx)(Kt,{type:`tertiary`,children:O(e||`—`,22)})})}];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(H,{error:r.error,onRetry:r.reload}),r.data?.enabled===!1&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,className:`settings-audit-banner`,description:e(`settingsAudit.disabledHint`,null,`审计功能已关闭,新操作不会写入审计表。`)}),(0,Z.jsx)(ne,{columns:4,metrics:[{id:`total`,label:e(`settingsAudit.statTotal`,null,`当前筛选`),value:k(ce)},{id:`ok`,label:e(`settingsAudit.statSuccess`,null,`成功`),value:k(Math.max(0,ce-le))},{id:`fail`,label:e(`settingsAudit.statFailures`,null,`失败`),value:k(le),tone:le?`danger`:void 0},{id:`recent`,label:e(`settingsAudit.statRecent7d`,null,`近 7 天`),value:k(ue)}]}),(0,Z.jsx)(H,{error:P.error,onRetry:P.reload}),(0,Z.jsxs)(U,{title:e(`settingsAudit.title`,null,`日志审计`),description:e(`settingsAudit.description`,null,`记录平台管理类操作(登录、配置、删除等),不记录对话正文与每次工具调用。`),extra:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(f,{size:`small`,color:`grey`,children:e(`settingsAudit.retentionHint`,{days:r.data?.retention_days??0},`审计记录保留 ${r.data?.retention_days??0} 天`)}),(0,Z.jsx)(p,{loading:y===`json`,onClick:()=>K(`json`),children:e(`settingsAudit.exportJson`,null,`导出 JSON`)}),(0,Z.jsx)(p,{loading:y===`csv`,onClick:()=>K(`csv`),children:e(`settingsAudit.exportCsv`,null,`导出 CSV`)})]}),children:[(0,Z.jsxs)(`div`,{className:`settings-audit-filters`,children:[(0,Z.jsx)(D,{value:i.category,onChange:e=>a(t=>({...t,category:e,action:``})),optionList:V,style:{width:150}}),(0,Z.jsx)(D,{value:i.action,onChange:e=>a(t=>({...t,action:e})),optionList:W,disabled:!i.category,placeholder:i.category?e(`settingsAudit.filterAllActions`,null,`全部操作`):e(`settingsAudit.filterCascadeHint`,null,`选择类别后可筛选具体操作`),style:{width:170}}),(0,Z.jsx)(D,{value:i.result,onChange:e=>a(t=>({...t,result:e})),style:{width:130},optionList:[{value:``,label:e(`settingsAudit.filterAll`,null,`全部`)},{value:`success`,label:e(`settingsAudit.result.success`,null,`成功`)},{value:`failure`,label:e(`settingsAudit.result.failure`,null,`失败`)}]}),(0,Z.jsx)(h,{prefix:(0,Z.jsx)(x,{}),value:i.q,onChange:e=>a(t=>({...t,q:e})),placeholder:e(`settingsAudit.filterQueryPlaceholder`,null,`消息 / 资源 ID / 操作名`),style:{width:240},showClear:!0}),(0,Z.jsx)(ee,{type:`dateTime`,value:i.since||void 0,onChange:e=>a(t=>({...t,since:e||null})),placeholder:e(`settingsAudit.filterSince`,null,`开始时间`),style:{width:200}}),(0,Z.jsx)(ee,{type:`dateTime`,value:i.until||void 0,onChange:e=>a(t=>({...t,until:e||null})),placeholder:e(`settingsAudit.filterUntil`,null,`结束时间`),style:{width:200}}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,onClick:G,children:e(`settingsAudit.filterBtn`,null,`筛选`)}),(0,Z.jsx)(p,{onClick:ie,children:e(`settingsAudit.resetBtn`,null,`重置`)}),(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),theme:`borderless`,onClick:oe,loading:I.loading||P.loading,children:e(`common.refresh`,null,`刷新`)})]}),(0,Z.jsx)(H,{error:I.error,onRetry:I.reload}),(0,Z.jsx)(ae,{columns:J,dataSource:Array.isArray(I.data?.logs)?I.data.logs:[],rowKey:`id`,loading:I.loading,emptyText:e(`settingsAudit.empty`,null,`暂无审计记录`),onRow:e=>({onClick:()=>v(e.id),style:{cursor:`pointer`}}),pagination:{currentPage:l,pageSize:m,total:Number(I.data?.total)||0,showSizeChanger:!0,pageSizeOpts:[10,20,50,100],onPageChange:e=>d(e),onPageSizeChange:e=>{g(e),d(1)}}})]}),(0,Z.jsx)(w,{title:e(`settingsAudit.detailTitle`,null,`审计详情`),visible:!!_,onCancel:()=>v(``),width:640,placement:`right`,children:_&&(0,Z.jsx)($t,{id:_,categoryLabel:L,actionLabel:R,resultLabel:B})})]})}function $t({id:e,categoryLabel:t,actionLabel:n,resultLabel:r}){let i=te(),[a,o]=(0,q.useState)({loading:!0,error:null,log:null});if((0,q.useEffect)(()=>{let t=!1;return o({loading:!0,error:null,log:null}),M.get(`/audit/logs/${encodeURIComponent(e)}`).then(e=>{t||o({loading:!1,error:null,log:e?.log||null})}).catch(e=>{t||o({loading:!1,error:e,log:null})}),()=>{t=!0}},[e]),a.loading)return(0,Z.jsx)(Le,{rows:6});if(a.error)return(0,Z.jsx)(H,{error:a.error});let s=a.log;return s?(0,Z.jsxs)(`div`,{className:`settings-audit-detail`,children:[(0,Z.jsx)(B,{columns:2,items:[{label:i(`settingsAudit.detailTime`,null,`时间`),value:A(s.createdAt)},{label:i(`settingsAudit.detailResult`,null,`结果`),value:(0,Z.jsx)(Zt,{result:s.result,label:r(s.result)})},{label:i(`settingsAudit.detailCategory`,null,`类别`),value:t(s.category)},{label:i(`settingsAudit.colAction`,null,`操作`),value:n(s.action)},{label:i(`settingsDisplay.actor`,null,`操作者`),value:s.actor||`—`},{label:i(`settingsAudit.colIp`,null,`IP`),value:(0,Z.jsx)(Re,{children:s.clientIp||`—`})},{label:i(`settingsDisplay.level`,null,`日志级别`),value:s.level||`—`},{label:i(`settingsDisplay.resourceType`,null,`资源类型`),value:s.resourceType||`—`},{label:i(`settingsAudit.resourceIdLabel`,null,`资源 ID`),value:(0,Z.jsx)(Re,{children:s.resourceId||`—`})},{label:i(`settingsDisplay.resourceAvailable`,null,`资源是否可访问`),value:s.resourceAvailable==null?`—`:s.resourceAvailable?i(`common.yes`,null,`是`):i(`common.no`,null,`否`)},{label:i(`settingsDisplay.session`,null,`会话标识`),value:(0,Z.jsx)(Re,{children:s.sessionHint||`—`})},{label:i(`settingsDisplay.userAgent`,null,`客户端标识`),value:O(s.userAgent||`—`,80)}]}),(0,Z.jsxs)(`div`,{className:`settings-audit-message-block`,children:[(0,Z.jsx)(Kt,{type:`tertiary`,size:`small`,children:i(`settingsAudit.detailMessage`,null,`说明`)}),(0,Z.jsx)(Kt,{children:s.message||`—`})]}),s.detail&&(0,Z.jsx)(oe,{value:s.detail,collapsed:!0,title:i(`settingsDisplay.details`,null,`详情`)})]}):(0,Z.jsx)(Kt,{type:`tertiary`,children:i(`settingsAudit.empty`,null,`暂无审计记录`)})}var{Text:en}=l;function tn(){let e=te(),{preference:t,theme:n,setPreference:r}=V(),{lang:i,setLanguage:a}=F();return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(U,{title:e(`theme.titleSystem`,null,`外观主题`),description:e(`settings.appearanceThemeDesc`,null,`主题与语言只保存在当前浏览器(localStorage),不会写入服务端配置。`),children:[(0,Z.jsxs)(y,{value:t,onChange:e=>r(e.target.value),direction:`horizontal`,children:[(0,Z.jsx)(S,{value:`system`,children:e(`theme.system`,null,`跟随系统`)}),(0,Z.jsx)(S,{value:`light`,children:e(`theme.light`,null,`浅色`)}),(0,Z.jsx)(S,{value:`dark`,children:e(`theme.dark`,null,`暗色`)})]}),(0,Z.jsxs)(u,{spacing:8,className:`settings-appearance-status`,children:[(0,Z.jsxs)(f,{size:`small`,color:`blue`,children:[e(`settings.currentTheme`,null,`当前生效`),`:`,n===`dark`?e(`theme.dark`,null,`暗色`):e(`theme.light`,null,`浅色`)]}),(0,Z.jsx)(Q,{children:`preference = ${t}`})]})]}),(0,Z.jsx)(U,{title:e(`settings.languageTitle`,null,`界面语言`),description:e(`settings.languageDesc`,null,`切换到独立语言包;缺失词条回落到中文。`),children:(0,Z.jsxs)(u,{spacing:12,align:`center`,children:[(0,Z.jsx)(D,{value:i,onChange:e=>a(e),optionList:P.map(e=>({value:e.id,label:e.label})),style:{width:220}}),(0,Z.jsx)(en,{type:`tertiary`,children:i})]})})]})}var nn=[`basic`,`models`,`knowledge`,`token-usage`,`storage`,`update`,`audit`,`appearance`];function rn(){let e=te(),{mobile:t}=n(),[r,i]=a(),o=r.get(`section`),s=(0,q.useMemo)(()=>nn.includes(o)?o:`basic`,[o]);return(0,Z.jsxs)(`div`,{className:`settings-page`,children:[(0,Z.jsx)(ie,{title:e(`settings.title`,null,`系统设置`),description:e(`settings.pageDesc`,null,`配置、模型探测、Token 用量、存储清理、审计日志与界面偏好;每个分区独立加载,单区失败不影响其他分区。`)}),(0,Z.jsxs)(g,{type:`line`,tabPosition:t?`top`:`left`,collapsible:t,lazyRender:!0,activeKey:s,onChange:e=>{let t=new URLSearchParams(r);t.set(`section`,e),t.delete(`focus`),i(t,{replace:!0})},className:`settings-tabs`,children:[(0,Z.jsx)(g.TabPane,{itemKey:`basic`,tab:e(`settings.nav.basic`,null,`基础配置`),children:(0,Z.jsx)(Ue,{active:s===`basic`})}),(0,Z.jsx)(g.TabPane,{itemKey:`models`,tab:e(`settings.nav.models`,null,`模型与工具`),children:(0,Z.jsx)(xt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`knowledge`,tab:e(`settings.nav.knowledge`,null,`知识库`),children:(0,Z.jsx)(Dt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`token-usage`,tab:e(`settings.nav.tokenUsage`,null,`Token 用量`),children:(0,Z.jsx)(Nt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`storage`,tab:e(`settings.nav.storage`,null,`存储清理`),children:(0,Z.jsx)(Rt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`update`,tab:e(`settings.nav.update`,null,`更新状态`),children:(0,Z.jsx)(Gt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`audit`,tab:e(`settings.nav.audit`,null,`审计日志`),children:(0,Z.jsx)(Qt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`appearance`,tab:e(`settings.nav.appearance`,null,`外观`),children:(0,Z.jsx)(tn,{})})]})]})}export{rn as default};
\ No newline at end of file
diff --git a/web/static/app/assets/settings-C_ZMENXl.js b/web/static/app/assets/settings-C_ZMENXl.js
new file mode 100644
index 00000000..8b597ffd
--- /dev/null
+++ b/web/static/app/assets/settings-C_ZMENXl.js
@@ -0,0 +1,21 @@
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,_ as n,g as r,t as i,y as a}from"./react-QV7DAAIx.js";import{$ as o,B as s,Ft as c,G as l,I as u,L as d,N as f,R as p,S as m,U as h,c as g,d as _,g as v,h as y,j as ee,k as b,lt as x,m as S,on as C,p as w,s as T,ut as E,y as D}from"./semi-65W_4I1v.js";import{D as O,E as k,F as te,I as A,L as j,M,N,P,R as F,S as I,T as L,_ as R,a as z,b as ne,d as B,j as re,l as V,m as H,n as ie,o as U,p as W,s as G,u as K,x as ae,y as oe,z as se}from"./index-_8d9XBPJ.js";import{n as ce,r as le,t as ue}from"./model-channel-mQ6lfvSO.js";var q=e(t(),1),J=class extends Error{constructor(e,t){super(t?`第 ${t} 行:${e}`:e),this.name=`YamlError`,this.line=t||0}},de=/^(?:[-?:,\[\]{}#&*!|>'"%@`]|.*[:\s]$|.*\s#|.*[\n\r\t])/,fe=/^(?:true|false|null|~|yes|no|on|off|[-+]?(?:\d+|\d*\.\d+)(?:[eE][-+]?\d+)?)$/i;function pe(e){let t=String(e);return!(t===``||fe.test(t)||/^[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?$/.test(t)||de.test(t)||/^(?:\s)|:(?:\s|$)|[\r\n\t]/.test(t)||/[,[\]{}]/.test(t)||/^[!&*|>@`]/.test(t))}function Y(e){return JSON.stringify(String(e))}function me(e){let t=String(e);return pe(t)?t:Y(t)}function he(e){if(e==null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return Number.isFinite(e)?String(e):Y(String(e));let t=String(e);return pe(t)?t:Y(t)}function ge(e){return e==null||[`string`,`number`,`boolean`].includes(typeof e)}function _e(e,t,n,r){let i=` `.repeat(n),a=me(e);if(ge(t))r.push(`${i}${a}: ${he(t)}`);else if(Array.isArray(t)){if(!t.length){r.push(`${i}${a}: []`);return}r.push(`${i}${a}:`),be(t,n+2,r)}else Object.entries(t).length?(r.push(`${i}${a}:`),ve(t,n+2,r)):r.push(`${i}${a}: {}`)}function ve(e,t,n){for(let[r,i]of Object.entries(e))_e(r,i,t,n)}function ye(e,t,n){let r=` `.repeat(t);if(ge(e)){n.push(`${r}- ${he(e)}`);return}if(Array.isArray(e)){if(!e.length){n.push(`${r}- []`);return}n.push(`${r}-`),be(e,t+2,n);return}let i=Object.entries(e);if(!i.length){n.push(`${r}- {}`);return}let[a,o]=i[0],s=i.slice(1);ge(o)?n.push(`${r}- ${me(a)}: ${he(o)}`):(n.push(`${r}-`),_e(a,o,t+2,n));for(let[e,r]of s)_e(e,r,t+2,n)}function be(e,t,n){for(let r of e)ye(r,t,n)}function xe(e,{header:t}={}){let n=[];if(t){for(let e of String(t).replace(/\r\n?/g,`
+`).split(`
+`))n.push(`# ${e}`.trimEnd());n.length&&n.push(``)}return ge(e)?(n.push(he(e)),`${n.join(`
+`)}\n`):Array.isArray(e)?(e.length?be(e,0,n):n.push(`[]`),`${n.join(`
+`)}\n`):!e||!Object.keys(e).length?(n.push(`{}`),`${n.join(`
+`)}\n`):(ve(e,0,n),`${n.join(`
+`)}\n`)}function X(e){let t=``;for(let n=0;n=n.length||/\s/.test(n[e+1]))){let r=n.slice(0,e).trim();if(!r)throw new J(`键名为空`,t);if(/^[&*!|>@`]/.test(r))throw new J(`不支持的键名写法:${r}`,t);return{key:r,rest:X(n.slice(e+1).trim())}}throw new J(`缺少冒号,无法识别为键值`,t)}function we(e,t){if(e.startsWith(`"`)||e.startsWith(`'`)){let{end:n}=Se(e,0,t);return e.slice(n).trimStart().startsWith(`:`)}if(/^[\[{]/.test(e))return!1;for(let t=0;t=e.length||/\s/.test(e[t+1])))return!0;return!1}function Te(e){let t=e.trim();return t===``||t===`~`||/^null$/i.test(t)?null:/^true$/i.test(t)?!0:/^false$/i.test(t)?!1:/^[-+]?\d+$/.test(t)&&t.length<16||/^[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?$/.test(t)?Number(t):t}function Ee(e,t,n){let r=t,i=()=>{for(;r{i();let t=e[r];if(t===`[`||t===`{`){let o=t,s=o===`[`?`]`:`}`;r+=1;let c=o===`[`,l=c?[]:{};for(;;){if(i(),r>=e.length)throw new J(`行内集合未闭合`,n);if(e[r]===s)return r+=1,l;if(c)l.push(a());else{let t=a();if(i(),e[r]!==`:`)throw new J(`行内对象缺少冒号`,n);r+=1,l[String(t)]=a()}if(i(),e[r]===`,`)r+=1;else{if(e[r]===s)return r+=1,l;throw new J(`行内集合分隔符不正确`,n)}}}if(t===`"`||t===`'`){let t=Se(e,r,n);return r=t.end,t.value}let o=r;for(;o][-+0-9]*$/.test(e.trim())}function ke(e,t,n,r){let i=n.trim()[0],a=n.includes(`-`)?`strip`:n.includes(`+`)?`keep`:`clip`,o=e.rawLines,s=[],c=null,l=r;for(let e=r;et)throw new J(`缩进层级不一致`,n.line);if(n.content===`-`||n.content.startsWith(`- `))throw new J(`同一层级不能混用列表与键值`,n.line);let i=Ce(n.content,n.line);e.i+=1,r[i.key]=Me(e,t,i.rest,n.line)}return r}function Me(e,t,n,r){if(n===``){let n=e.lines[e.i];return n&&n.indent>t?Ae(e,n.indent):null}return Oe(n)?ke(e,t,n,r):De(n,r)}function Ne(e,t){let n=[];for(;e.it)throw new J(`缩进层级不一致`,r.line);break}if(!(r.content===`-`||r.content.startsWith(`- `)))break;let i=r.content===`-`?``:r.content.slice(1).trimStart(),a=t+(r.content.length-i.length);if(e.i+=1,i===``){let r=e.lines[e.i];r&&r.indent>t?n.push(Ae(e,r.indent)):n.push(null)}else if(we(i,r.line)&&!/^[\[{]/.test(i)){let t=Ce(i,r.line),o={};o[t.key]=Me(e,a,t.rest,r.line),je(e,a,o),n.push(o)}else Oe(i)?n.push(ke(e,t,i,r.line)):n.push(De(i,r.line))}return n}function Pe(e){let t=String(e??``).replace(/\r\n?/g,`
+`).split(`
+`),n=[];if(t.forEach((e,t)=>{if(/^\s*$/.test(e)||/^\s*#/.test(e)||/^\s*(---|\.\.\.)\s*(#.*)?$/.test(e))return;let r=/^[ \t]*/.exec(e)[0];if(r.includes(` `))throw new J(`缩进不能使用制表符`,t+1);n.push({indent:r.length,content:e.slice(r.length),line:t+1})}),!n.length)return null;let r={lines:n,rawLines:t,i:0},i=Ae(r,n[0].indent);if(r.i({name:e.name,enabled:!!e.enabled,is_external:!!e.is_external,external_mcp:e.external_mcp||void 0}))}function Ue({active:e=!0}){let t=te(),n=r(),{hasPermission:i}=A(),a=i(`config:read`),c=i(`config:write`),l=(0,q.useCallback)(({signal:e}={})=>j.get(`/config`,null,{signal:e}),[]),d=z(l,[a],{skip:!a}),h=(0,q.useRef)(e),[g,_]=(0,q.useState)(``),[v,y]=(0,q.useState)(``),[b,x]=(0,q.useState)(``),[S,C]=(0,q.useState)(null),[w,T]=(0,q.useState)(``),[D,k]=(0,q.useState)(`idle`);(0,q.useEffect)(()=>{if(!d.data)return;let{context_window_defaults:e,image_input_defaults:t,...n}=d.data,r=xe(n,{header:Ve});_(r),y(r),x(``)},[d.data]);let M=v!==``&&g!==v,N=D!==`idle`;(0,q.useEffect)(()=>{e&&!h.current&&a&&!M&&!N&&d.reload({silent:!0}),h.current=e},[e,N,a,d.reload,M]);let P=(0,q.useMemo)(()=>{let e=d.data;if(!e)return[];let r=e.ai?.channels||{},i=Object.entries(r).map(([e,t])=>ue(e,t)),a=e.ai?.default_channel,o=Array.isArray(e.tools)?e.tools:[],s=o.filter(e=>e.enabled).length,c=!!(e.vision?.enabled&&String(e.vision?.model||``).trim()),l=!!e.knowledge?.enabled;return[{label:t(`settings.defaultChannel`,null,`默认 AI 通道`),value:a?ue(a,r[a]):`—`},{label:t(`settingsBasic.aiChannelSavedList`,null,`已保存通道`),value:`${O(i.length)}${i.length?`(${i.slice(0,4).join(`、`)})`:``}`},{label:t(`settings.toolsEnabled`,null,`已启用工具`),value:`${O(s)} / ${O(o.length)}`},{label:t(`settings.visionLabel`,null,`视觉模型`),value:(0,Z.jsxs)(`span`,{className:`settings-overview-inline`,children:[(0,Z.jsx)(`span`,{children:e.vision?.enabled?e.vision.model||`已启用`:`未启用`}),(0,Z.jsx)(p,{size:`small`,theme:`borderless`,type:`primary`,className:`settings-overview-link`,onClick:()=>n(`/settings?section=models&focus=vision`),children:c?`配置`:`去启用`})]})},{label:t(`settings.knowledge.title`,null,`知识库设置`),value:(0,Z.jsxs)(`span`,{className:`settings-overview-inline`,children:[(0,Z.jsx)(`span`,{children:l?`已启用`:`未启用`}),(0,Z.jsx)(p,{size:`small`,theme:`borderless`,type:`primary`,className:`settings-overview-link`,onClick:()=>n(`/settings?section=knowledge`),children:l?`配置`:`去启用`})]})},{label:`C2`,value:e.c2?.enabled?`已启用`:`未启用`}]},[d.data,n,t]),F=(0,q.useCallback)(async()=>{C(null),T(``),await d.reload()},[d.reload]),L=(0,q.useCallback)(()=>{M?oe({title:`重新加载配置`,content:`当前有未保存修改,重新加载会丢弃这些修改。确认继续?`,okText:`确定`,onOk:F}):F()},[F,M]);return a?d.loading&&!d.data?(0,Z.jsx)(Le,{rows:8}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V,{error:d.error,onRetry:L}),d.data&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(H,{title:t(`settings.overviewTitle`,null,`当前配置概览`),children:(0,Z.jsx)(B,{items:P,columns:3})}),(0,Z.jsxs)(H,{title:t(`settings.rawTitle`,null,`原始 YAML 配置`),description:t(`settingsDisplay.rawYamlHelp`,null,`查看或批量修改服务端高级配置。保存会写入支持的改动并尝试应用。`),extra:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(f,{color:M?`amber`:`green`,size:`small`,children:M?t(`settings.unsaved`,null,`有未保存修改`):t(`settings.savedState`,null,`已与服务端同步`)}),(0,Z.jsx)(U,{text:g,label:t(`common.copy`,null,`复制`)})]}),children:[w&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,className:`settings-yaml-notice`,description:w}),b&&(0,Z.jsx)(V,{error:b}),(0,Z.jsx)(V,{error:S,onRetry:L}),(0,Z.jsxs)(`div`,{className:`settings-yaml-toolbar`,children:[(0,Z.jsxs)(u,{children:[(0,Z.jsx)(p,{theme:`solid`,type:`primary`,icon:(0,Z.jsx)(o,{}),loading:N,disabled:!c||!M,onClick:async()=>{let e;try{e=Pe(g)}catch(e){x(se(e,`YAML 解析失败`));return}if(!e||typeof e!=`object`||Array.isArray(e)){x(`顶层必须是键值映射(key: value),不能是列表或标量。`);return}x(``),C(null),T(``);let n=Object.keys(e).filter(e=>!Be.includes(e)),r={};for(let t of Be)e[t]!==void 0&&JSON.stringify(e[t])!==JSON.stringify(d.data?.[t])&&(r[t]=e[t]);if(r.tools&&(r.tools=He(r.tools)),!Object.keys(r).length){T(`没有需要保存的配置修改。`),n.length&&I(`已忽略不支持的字段:${n.join(`、`)}`);return}k(`saving`);try{await j.put(`/config`,r)}catch(e){k(`idle`),C(e),ne(e,t(`settings.apply.applyFailed`,null,`保存配置失败`));return}let i=null;k(`applying`);try{await j.post(`/config/apply`)}catch(e){i=e}k(`idle`),i?(C(i),T(t(`settings.apply.appliedWithError`,null,`配置已写入 config.yaml,但应用失败;部分改动需要重启后才能生效。`)),I(t(`settings.apply.appliedWithError`,null,`配置已写入,但应用失败`))):ae(t(`settings.apply.applySuccess`,null,`配置已成功应用`)),n.length&&I(t(`settings.apply.ignoredSections`,{list:n.join(`、`)},`已忽略后端不接收的字段:${n.join(`、`)}`)),await d.reload()},children:D===`applying`?t(`settings.applying`,null,`正在应用…`):t(`settings.saveAndApply`,null,`保存并应用`)}),(0,Z.jsx)(p,{onClick:()=>{try{let e=Pe(g);if(!e||typeof e!=`object`||Array.isArray(e)){x(`顶层必须是键值映射(key: value),不能是列表或标量。`);return}_(xe(e,{header:Ve})),x(``)}catch(e){x(se(e,`YAML 解析失败`))}},disabled:N,children:t(`settings.formatAndValidate`,null,`格式化并校验`)}),(0,Z.jsx)(p,{onClick:()=>{_(v),x(``),T(``)},disabled:!M||N,children:t(`toolGuard.reset`,null,`撤销修改`)}),(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),onClick:L,loading:d.loading,disabled:N,children:t(`common.refresh`,null,`刷新`)})]}),(0,Z.jsx)(Q,{children:t(`settings.lineCount`,{count:g.split(`
+`).length},`${g.split(`
+`).length} 行`)})]}),!c&&(0,Z.jsx)(ze,{type:`tertiary`,size:`small`,className:`settings-hint`,children:t(`settings.readOnlyHint`,null,`当前账号没有 config:write 权限,只能查看配置,无法保存。`)}),(0,Z.jsx)(m,{className:`settings-yaml-input`,value:g,onChange:e=>{_(e),T(``)},readOnly:!c||N,spellCheck:!1,autosize:!1,rows:24})]}),(0,Z.jsx)(H,{title:t(`settings.jsonTitle`,null,`只读参考`),children:(0,Z.jsx)(ee,{children:(0,Z.jsx)(ee.Panel,{header:t(`settings.jsonPanel`,null,`GET /config 原始响应(JSON,便于核对字段名)`),itemKey:`json`,children:(0,Z.jsx)(K,{value:d.data,collapsed:!0,title:`GET /config`})})})})]})]}):(0,Z.jsx)(Ie,{permission:`config:read`,label:t(`settings.nav.basic`,null,`读取基础配置`)})}var{Text:We}=l,Ge=`__main__`,Ke={},qe=1048576,Je=[{value:`openai_compatible`,key:`settingsProbe.compatible`,fallback:`兼容 OpenAI 的接口`},{value:`claude`,key:`settingsBasic.providerClaude`,fallback:`Claude(Anthropic Messages)`}],Ye=[{value:`openai`,key:`settingsProbe.auditBackendChat`,fallback:`对话模型`},{value:`typesafe`,key:`settingsProbe.auditBackendTypeSafe`,fallback:`TypeSafe / Jev`}],Xe=[``,`auto`,`local_auto`,`local`,`economy`,`custom`],Ze=[[`context_window`,`settingsBasic.contextWindow`,`模型上下文窗口(Token)`],[`max_total_tokens`,`settingsBasic.maxTotalTokens`,`最大上下文令牌数`],[`max_completion_tokens`,`settingsBasic.maxCompletionTokens`,`最大输出令牌数`]],Qe={key:``,payload:null,error:null},$e={context_window_unknown:`contextWarnUnknown`,context_runtime_unknown:`contextWarnRuntimeUnknown`,local_context_window_unknown:`contextWarnWindowUnknown`,local_context_window_small:`contextWarnWindowSmall`,max_total_tokens_clamped:`contextWarnBudgetClamped`,max_completion_tokens_clamped:`contextWarnCompletionClamped`,configured_budget_exceeds_context_window:`contextWarnBudgetExceedsWindow`,ollama_v1_ignores_num_ctx:`contextWarnOllamaV1`,ollama_runtime_context_unknown:`contextWarnOllamaRuntime`,llamacpp_parallel_slots:`contextWarnLlamaCppSlots`},et={ollama:`Ollama`,llamacpp:`llama.cpp`,lmstudio:`LM Studio`,omlx:`oMLX`,vllm:`vLLM`};function tt(e,t){return e(`settingsProbe.profiles.`+(t||`default`),null,t||`使用默认设置`)}function nt(e){let t=Number(e);return Number.isSafeInteger(t)&&t>=0?t:0}function rt(e){let t=(e||``).trim(),n=t.toLowerCase();return n?n===`openai`||n===`openai_compatible`?`openai_compatible`:n===`claude`||n===`anthropic`?`claude`:t:``}function it(e){let t=e.provider||`openai_compatible`;return t===`openai`&&(t=`openai_compatible`),t===`anthropic`&&(t=`claude`),{name:e.name||``,provider:t,base_url:e.base_url||``,api_key:e.api_key||``,model:e.model||``,image_input:e.image_input||``,context_profile:e.context_profile||``,context_window:e.context_window>0?String(e.context_window):``,max_total_tokens:e.max_total_tokens||0,max_completion_tokens:e.max_completion_tokens||0,headers:e.headers||void 0}}function at(e,t){return[{label:e(`settingsProbe.result`,null,`测试结果`),value:(0,Z.jsx)(f,{color:`green`,children:e(`settingsBasic.testSuccess`,null,`连接成功`)})},{label:e(`settingsBasic.model`,null,`模型`),value:t.model||`—`},{label:e(`settingsProbe.latency`,null,`响应耗时`),value:t.latency_ms==null?`—`:e(`settingsProbe.milliseconds`,{value:t.latency_ms},`${t.latency_ms} 毫秒`)}]}function ot(e,t,n,r){let i=t.context_source,a=i?.replace(/^omlx_models_(?=max_model_len|context_length|max_context_length|context_window)/,`openai_models_`),o=t.context_backend,s=r===`configured`?e(`settingsProbe.windowConfigured`,null,`手动配置`):e(`settingsProbe.windowDefault`,null,`默认值`);return[...at(e,t),{label:e(`settingsProbe.window`,null,`上下文窗口`),value:t.context_window||n||`—`},{label:e(`settingsProbe.backend`,null,`模型接口类型`),value:o===`openai_compatible`?e(`settingsProbe.compatible`,null,`兼容 OpenAI 的接口`):et[o]||o||`—`},{label:e(`settingsProbe.source`,null,`窗口信息来源`),value:n?s:i?e(`settingsProbe.sources.`+a,null,i):`—`},{label:e(`settingsProbe.profile`,null,`上下文配置`),value:tt(e,t.context_profile)},{label:e(`settingsProbe.effectiveBudget`,null,`实际可用上下文令牌数`),value:t.effective_max_total_tokens??`—`}]}function st({state:e,defaultWindow:t,defaultWindowSource:n,model:r,onModelChange:i,disabled:a}){let o=te(),c=(0,q.useId)(),{key:l,payload:d,error:f}=e;if(f)return(0,Z.jsx)(V,{error:f});if(!d)return null;if(l===`list`){if(!d.success)return(0,Z.jsx)(s,{type:d.supported===!1?`info`:`danger`,bordered:!0,closeIcon:null,description:d.error||o(`settingsBasic.modelsListFailed`,null,`获取模型列表失败`)});let e=Array.isArray(d.models)?d.models:[],t=o(`settingsBasic.modelsListSelectPlaceholder`,null,`请选择模型`);return(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)(We,{children:o(`settingsBasic.modelsListSuccess`,{count:d.count??e.length},`已获取 ${d.count??e.length} 个模型`)}),(0,Z.jsx)(`span`,{id:c,hidden:!0,children:t}),e.length>0&&(0,Z.jsx)(D,{filter:!0,"aria-labelledby":c,placeholder:t,value:e.includes(r)?r:void 0,optionList:e.map(e=>({value:e,label:e})),onChange:i,disabled:a,className:`settings-model-picker`})]})})}if(l===`audit`)return(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:d.success?(0,Z.jsx)(B,{columns:3,items:at(o,d)}):(0,Z.jsx)(s,{type:`danger`,bordered:!0,closeIcon:null,description:d.error||o(`settingsBasic.testFailed`,null,`连接失败`)})});if(!d.success)return(0,Z.jsx)(s,{type:`danger`,bordered:!0,closeIcon:null,description:d.error||o(`settingsBasic.testFailed`,null,`连接失败`)});let p=!d.context_window&&!d.context_runtime_unknown?t:0,m=(Array.isArray(d.context_warnings)?d.context_warnings:[]).filter(e=>!p||e!==`context_window_unknown`);return(0,Z.jsxs)(`div`,{className:`settings-probe-result`,children:[(0,Z.jsx)(B,{columns:3,items:ot(o,d,p,n)}),m.length>0&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(We,{strong:!0,children:o(`settingsProbe.warnings`,null,`上下文提示`)}),(0,Z.jsx)(`ul`,{children:[...new Set(m)].map(e=>(0,Z.jsx)(`li`,{children:Object.hasOwn($e,e)?o(`settingsBasic.`+$e[e],null,e):o(`settingsProbe.unknownWarning`,{code:e},`收到未识别的上下文提示(${e})`)},e))})]})})]})}function ct({config:e,canWrite:t,reloadConfig:n}){let r=te(),i=(0,q.useId)(),a=(0,q.useId)(),o=e.ai?.channels||Ke,c=Object.keys(o),l=e.ai?.default_channel,[d,m]=(0,q.useState)(``),g=[d,l].find(e=>Object.hasOwn(o,e))||c[0]||Ge,_=g===Ge,v=it((_?e.openai:o[g])||{}),[y,b]=(0,q.useState)({}),x=y[g]||{},S={...v,...x},[C,w]=(0,q.useState)(null),T=C&&Object.hasOwn(C,S.model)?C[S.model]:void 0,E=[`model`,`base_url`,`provider`].every(e=>S[e]===v[e]),O=x.image_input??(E?v.image_input:``),k=E?e.image_input_defaults?.[_?``:g]:T?.image_input,A=O===`enabled`||O!==`disabled`&&k===!0,M=E&&S.context_profile===v.context_profile?e.context_window_defaults?.[_?``:g]:T?.context_window,N=[`local`,`local_auto`].includes(String(S.context_profile||``).trim().toLowerCase()),P=!!S.model.trim()&&!S.context_window,F=P&&!Object.hasOwn(x,`context_window`),I=nt(S.context_window),L=I>0?I:F?N?M||0:M||qe:0,R=I>0?`configured`:L>0?`default`:``,z=M===qe,ne=Object.keys(x).length>0,[B,re]=(0,q.useState)(``),[ie,U]=(0,q.useState)(Qe),[W,G]=(0,q.useState)(!1),[K,oe]=(0,q.useState)(null),[se,ue]=(0,q.useState)(!1),J=!t||W||B===`list`,de=_?[{value:Ge,label:r(`settingsProbe.mainChannel`,null,`主模型通道`)}]:ce(Object.entries(o)),fe=Je.map(({value:e,key:t,fallback:n})=>({value:e,label:r(t,null,n)}));fe.some(e=>e.value===S.provider)||fe.push({value:S.provider,label:S.provider});let pe=()=>{b(e=>{let t={...e};return delete t[g],t})},Y=(e,t)=>{let n=[`provider`,`base_url`,`api_key`,`context_profile`].includes(e);n&&w(null),(ie.key!==`list`||!ie.payload?.success||n)&&U(Qe),b(n=>{let r={...n[g]};[`model`,`base_url`,`provider`].includes(e)&&t!==S[e]&&delete r.image_input;let i=e===`image_input`&&!E?``:v[e];return t===String(i)?delete r[e]:r[e]=t,{...n,[g]:r}})},me=e=>{w(null),m(e),U(Qe),se||oe(null)},he=()=>{w(null),pe(),U(Qe),se||oe(null)},ge=async e=>{try{await j.post(`/config/apply`),ue(!1),ae(e)}catch(e){ue(!0),oe(e)}},_e=async(e=!1)=>{if(J||B||!ne&&!e)return;oe(null);let t=Ze.find(([e])=>!/^\d*$/.test(String(S[e]).trim())||!Number.isSafeInteger(Number(S[e])));if(t){let[,e,n]=t;oe(Error(r(`settingsProbe.invalidLimit`,{field:r(e,null,n)},`请输入非负整数`)));return}let i={...x};for(let[e]of Ze)Object.hasOwn(i,e)&&(i[e]=nt(S[e]));ne&&P&&!z&&(i.context_window=qe),G(!0);try{await j.put(`/config`,{ai_channel:{channel_id:_?``:g,make_default:e,...i}}),pe(),await ge(e?r(`settingsBasic.aiChannelDefaultSaved`,null,`已设为默认通道`):r(`settingsBasic.aiChannelSaved`,null,`通道已保存`)),await n({silent:!0})}catch(e){oe(e)}finally{G(!1)}},ve=async()=>{if(!J&&se){G(!0),oe(null);try{await ge(r(`settings.apply.applySuccess`,null,`配置已成功应用`))}finally{G(!1)}}},ye=async(e,t,n)=>{if(!(J||B)){re(e),e===`list`&&w(null),U(Qe);try{let r=await j.post(t,n);e===`list`&&r.success&&w(r.model_defaults||null);let i=r.context_window;if((e===`context`||e===`test`&&[``,`0`].includes(S.context_window.trim()))&&r.success&&Number.isSafeInteger(i)&&i>0&&!r.context_runtime_unknown&&!(F&&z&&i===M)){let e=String(i);b(t=>{let n={...t[g]};return[`provider`,`base_url`,`api_key`,`model`,`context_window`].some(e=>n[e]!==x[e])?t:(e===v.context_window?delete n.context_window:n.context_window=e,{...t,[g]:n})})}U({key:e,payload:r,error:null})}catch(t){U({key:e,payload:null,error:t})}finally{re(``)}}},be=()=>({provider:S.provider,channel_id:_?void 0:g,credential_scope:_?`openai`:void 0,base_url:S.base_url,api_key:S.api_key,model:S.model,headers:S.headers,context_window:L||void 0,max_total_tokens:nt(S.max_total_tokens),max_completion_tokens:nt(S.max_completion_tokens),context_profile:S.context_profile}),xe=(0,q.useId)(),X=(0,q.useId)(),Se=e.hitl?.audit_model||{},Ce=(e.hitl?.audit_backend||``).trim().toLowerCase(),we=[`typesafe`,`jev`,`type-safe`,`typesafe-ai`].includes(Ce),Te={audit_backend:we?`typesafe`:`openai`,provider:rt(Se.provider),base_url:Se.base_url||``,api_key:Se.api_key||``,model:Se.model||``},[Ee,De]=(0,q.useState)({}),Oe={...Te,...Ee},ke=Object.keys(Ee).length>0,Ae=Oe.audit_backend===`typesafe`,je=Oe.provider||e.openai?.provider||`openai`,Me=[`claude`,`anthropic`].includes(je.toLowerCase()),Ne=Ae?`TypeSafe / Jev`:Me?`Claude (Anthropic Messages)`:r(`settingsProbe.compatible`,null,`兼容 OpenAI 的接口`),Pe=Se.provider?.trim()||e.openai?.provider||`openai`,Fe=we?`TypeSafe / Jev`:[`claude`,`anthropic`].includes(Pe.toLowerCase())?`Claude (Anthropic Messages)`:r(`settingsProbe.compatible`,null,`兼容 OpenAI 的接口`),Ie=we||[`provider`,`base_url`,`api_key`,`model`].some(e=>Se[e])?Se.model||Fe:r(`settingsProbe.auditInherit`,null,`继承主模型`),Le=Ae?`https://api.typesafe.ai`:e.openai?.base_url||(Me?`https://api.anthropic.com`:`https://api.openai.com/v1`),Re=Ye.map(({value:e,key:t,fallback:n})=>({value:e,label:r(t,null,n)})),ze=[{value:``,label:r(`settingsProbe.auditInherit`,null,`继承主模型`)},...Je.map(({value:e,key:t,fallback:n})=>({value:e,label:r(t,null,n)}))];Oe.provider&&!ze.some(e=>e.value===Oe.provider)&&ze.push({value:Oe.provider,label:Oe.provider});let[Be,Ve]=(0,q.useState)(Qe),[He,Ue]=(0,q.useState)(!1),[$e,et]=(0,q.useState)(!1),[at,ot]=(0,q.useState)(null),[ct,lt]=(0,q.useState)(!1),ut=!t||$e||He;(0,q.useEffect)(()=>{De({}),Ve(Qe)},[Te.audit_backend,Te.provider,Te.base_url,Te.api_key,Te.model]);let dt=(e,t)=>{Ve(Qe),ct||ot(null),De(n=>{let r={...n};return t===Te[e]?delete r[e]:r[e]=t,r})},ft=()=>{De({}),Ve(Qe),ct||ot(null)},pt=async e=>{try{await j.post(`/config/apply`),lt(!1),ae(e)}catch(e){lt(!0),ot(e)}},mt=async()=>{if(!(ut||W||B||!ke)){ot(null),et(!0);try{await j.put(`/config`,{hitl_audit_model:Ee}),De({}),await pt(r(`settingsProbe.auditModelSaved`,null,`审计模型已保存`)),await n({silent:!0})}catch(e){ot(e)}finally{et(!1)}}},ht=async()=>{if(!(ut||W||B||!ct)){et(!0),ot(null);try{await pt(r(`settings.apply.applySuccess`,null,`配置已成功应用`))}finally{et(!1)}}},gt=async()=>{if(ut)return;Ue(!0),Ve({key:`audit`,payload:null,error:null});let e={base_url:Oe.base_url,api_key:Oe.api_key,model:Oe.model,...Object.hasOwn(Ee,`audit_backend`)?{audit_backend:Oe.audit_backend}:{},...Object.hasOwn(Ee,`provider`)?{provider:Oe.provider}:{},...Te.api_key!==``&&Oe.api_key===``?{clear_api_key:!0}:{}};try{let t=await j.post(`/config/test-audit-model`,e);Ve({key:`audit`,payload:t,error:null})}catch(e){Ve({key:`audit`,payload:null,error:e})}finally{Ue(!1)}};return(0,Z.jsxs)(H,{title:r(`settingsProbe.channelTitle`,null,`模型通道与连接测试`),description:r(`settingsProbe.channelHelp`,null,`保存后应用所选通道的设置。显示 ******** 时沿用已保存的密钥。`),className:`settings-channel-panel`,extra:t?(0,Z.jsxs)(u,{wrap:!0,children:[ne&&(0,Z.jsx)(p,{disabled:W||!!B,onClick:he,children:r(`toolGuard.reset`,null,`撤销修改`)}),!_&&g!==l&&(0,Z.jsx)(p,{disabled:W||!!B,onClick:()=>_e(!0),children:r(`settingsBasic.aiChannelSetDefault`,null,`设为默认`)}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,loading:W,disabled:!ne||!!B,onClick:()=>_e(),children:r(`settingsProbe.saveChannel`,null,`保存通道`)})]}):(0,Z.jsx)(f,{color:`grey`,size:`small`,children:r(`settingsProbe.channelReadOnly`,null,`只读`)}),children:[(0,Z.jsxs)(`div`,{className:`settings-probe-form`,children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(We,{id:i,type:`tertiary`,size:`small`,children:r(`settings.checkChannel`,null,`通道`)}),(0,Z.jsx)(D,{value:g,onChange:me,optionList:de,renderSelectedItem:le,"aria-labelledby":i,disabled:W||!!B,style:{width:`100%`}})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.apiProvider`,null,`API 提供商`)}),(0,Z.jsx)(D,{value:S.provider,onChange:e=>Y(`provider`,e),optionList:fe,disabled:J,style:{width:`100%`}})]}),(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.baseUrl`,null,`API 地址`)}),(0,Z.jsx)(h,{value:S.base_url,onChange:e=>Y(`base_url`,e),readOnly:J,placeholder:`https://api.openai.com/v1`})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsxs)(u,{spacing:6,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.model`,null,`模型`)}),A&&(0,Z.jsx)(f,{size:`small`,color:`green`,children:r(`settingsProbe.imageInputSupported`,null,`支持图片`)})]}),(0,Z.jsx)(h,{value:S.model,onChange:e=>Y(`model`,e),readOnly:J,placeholder:`gpt-4o-mini`})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.aiChannelName`,null,`通道名称`)}),(0,Z.jsx)(h,{value:S.name,onChange:e=>Y(`name`,e),readOnly:J,placeholder:_?``:g})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.apiKey`,null,`API 密钥`)}),(0,Z.jsx)(h,{mode:`password`,autoComplete:`new-password`,value:S.api_key,onChange:e=>Y(`api_key`,e),readOnly:J})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsProbe.profile`,null,`上下文配置`)}),(0,Z.jsx)(D,{value:S.context_profile||``,onChange:e=>Y(`context_profile`,e),disabled:J,optionList:[...new Set([...Xe,S.context_profile||``])].map(e=>({value:e,label:tt(r,e)})),style:{width:`100%`}})]}),(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(We,{id:a,type:`tertiary`,size:`small`,children:`图片输入能力`}),(0,Z.jsx)(D,{value:O||``,onChange:e=>Y(`image_input`,e),disabled:J,"aria-labelledby":a,optionList:[{value:``,label:k===!0?`自动识别(支持图片)`:k===!1?`自动识别(仅文本)`:`自动识别`},{value:`enabled`,label:`启用(该模型原生支持识图)`},{value:`disabled`,label:`禁用(仅文本 / 走下方独立视觉模型)`}],style:{width:`100%`}})]}),Ze.map(([e,t,n])=>{let a=e===`context_window`,o=a&&F,s=`${i}-${e}`;return(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{id:s,type:`tertiary`,size:`small`,children:r(t,null,n)}),(0,Z.jsx)(h,{"aria-labelledby":s,value:String(o?qe:S[e]),onChange:t=>Y(e,t),inputMode:`numeric`,readOnly:J,placeholder:a?r(`settingsProbe.windowExample`,{value:r(`settingsBasic.contextWindowPlaceholder`,null,`131072`)},`例如 131072`):`0`})]},e)})]}),(se||K)&&(0,Z.jsxs)(`div`,{className:`settings-channel-notices`,children:[se&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(u,{wrap:!0,children:[r(`settingsProbe.savedApplyFailed`,null,`通道已写入配置,应用失败。`),(0,Z.jsx)(p,{size:`small`,disabled:J||!!B,onClick:ve,children:r(`settingsProbe.retryApply`,null,`重试应用`)})]})}),(0,Z.jsx)(V,{error:K})]}),(0,Z.jsxs)(u,{wrap:!0,className:`settings-probe-actions`,children:[(0,Z.jsx)(p,{loading:B===`test`,disabled:J||!!B,onClick:()=>ye(`test`,`/config/test-openai`,be()),children:r(`settingsBasic.test`,null,`测试连接`)}),(0,Z.jsx)(p,{loading:B===`context`,disabled:J||!!B,onClick:()=>ye(`context`,`/config/detect-context`,be()),children:r(`settingsBasic.detectContext`,null,`探测上下文窗口`)}),(0,Z.jsx)(p,{loading:B===`list`,disabled:J||!!B,onClick:()=>ye(`list`,`/config/list-models`,{context_profile:S.context_profile,provider:S.provider,channel_id:_?void 0:g,credential_scope:_?`openai`:void 0,base_url:S.base_url,api_key:S.api_key}),children:r(`settingsBasic.modelsList`,null,`获取模型列表`)})]}),(0,Z.jsx)(st,{state:ie,defaultWindow:L,defaultWindowSource:R,model:S.model,onModelChange:e=>Y(`model`,e),disabled:J}),!A&&(0,Z.jsx)(`div`,{className:`settings-image-fallback-tip`,children:(0,Z.jsx)(Q,{children:`当前通道未启用原生图片输入。若所选模型本身不支持识图,可开启下方「视觉分析(analyze_image)」由独立视觉模型代为识别截图与验证码;若模型通过中转接口实际支持识图,可将「图片输入能力」切换为「启用」。`})}),(0,Z.jsx)(ee,{className:`settings-audit-model`,children:(0,Z.jsx)(ee.Panel,{itemKey:`audit-model`,header:(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)(We,{strong:!0,children:r(`settingsProbe.auditModelTitle`,null,`审计模型`)}),(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:Ie}),ke&&(0,Z.jsx)(f,{size:`small`,color:`amber`,children:r(`settings.unsaved`,null,`有未保存修改`)})]}),children:(0,Z.jsxs)(`div`,{className:`settings-probe-card`,children:[!Ae&&!Oe.provider&&(0,Z.jsx)(`div`,{children:(0,Z.jsx)(f,{size:`small`,children:Ne})}),(0,Z.jsx)(Q,{children:Ae?r(`settingsProbe.auditTypeSafeHint`,null,`点击「保存审计模型」后生效。地址和模型留空使用 Jev 默认值;密钥必须独立配置,不继承主模型。`):r(`settingsProbe.auditChatHint`,null,`点击「保存审计模型」后生效。地址、提供商和模型留空继承主模型;密钥显示 ******** 时沿用已保存的审计密钥,留空则继承主模型。`)}),(0,Z.jsxs)(`div`,{className:`settings-probe-inline`,children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(We,{id:xe,type:`tertiary`,size:`small`,children:r(`settingsProbe.auditBackendLabel`,null,`审计后端`)}),(0,Z.jsx)(D,{value:Oe.audit_backend,onChange:e=>dt(`audit_backend`,e),optionList:Re,"aria-labelledby":xe,disabled:ut,style:{width:`100%`}})]}),!Ae&&(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(We,{id:X,type:`tertiary`,size:`small`,children:r(`settingsBasic.apiProvider`,null,`API 提供商`)}),(0,Z.jsx)(D,{value:Oe.provider,onChange:e=>dt(`provider`,e),optionList:ze,"aria-labelledby":X,disabled:ut,style:{width:`100%`}})]}),[[`base_url`,`baseUrl`,`API 地址`,Le],[`api_key`,`apiKey`,`API 密钥`,Ae?r(`settingsProbe.auditKeyRequiredPlaceholder`,null,`必填,不继承主模型`):r(`settingsProbe.auditKeyInheritPlaceholder`,null,`留空继承主模型`)],[`model`,`model`,`模型`,Ae?`jev-latest`:e.openai?.model||``]].map(([e,t,n,i])=>(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(We,{type:`tertiary`,size:`small`,children:r(`settingsBasic.`+t,null,n)}),(0,Z.jsx)(h,{value:Oe[e],onChange:t=>dt(e,t),placeholder:i,readOnly:ut,mode:e===`api_key`?`password`:void 0,autoComplete:e===`api_key`?`new-password`:void 0})]},e))]}),(ct||at)&&(0,Z.jsxs)(`div`,{className:`settings-channel-notices`,children:[ct&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(u,{wrap:!0,children:[r(`settingsProbe.auditSavedApplyFailed`,null,`审计模型已写入配置,应用失败。`),(0,Z.jsx)(p,{size:`small`,disabled:ut||W||!!B,onClick:ht,children:r(`settingsProbe.retryApply`,null,`重试应用`)})]})}),(0,Z.jsx)(V,{error:at})]}),(0,Z.jsxs)(u,{wrap:!0,children:[t&&(0,Z.jsx)(p,{size:`small`,theme:`solid`,type:`primary`,loading:$e,disabled:!ke||He||W||!!B,onClick:mt,children:r(`settingsProbe.saveAuditModel`,null,`保存审计模型`)}),(0,Z.jsx)(p,{size:`small`,loading:He,disabled:!t||$e,onClick:gt,children:r(`settingsProbe.testAuditModel`,null,`测试审计模型`)}),t&&ke&&(0,Z.jsx)(p,{size:`small`,disabled:$e||He,onClick:ft,children:r(`toolGuard.reset`,null,`撤销修改`)})]}),(0,Z.jsx)(st,{state:Be})]})})})]})}var{Text:lt}=l,ut={key:``,payload:null,error:null};function dt(e){let t=String(e||``).trim(),n=t.toLowerCase();return n?n===`openai`||n===`openai_compatible`?`openai_compatible`:n===`claude`||n===`anthropic`?`claude`:t:``}function ft(e={}){return{enabled:!!e.enabled,provider:dt(e.provider),base_url:e.base_url||``,api_key:e.api_key||``,model:e.model||``,detail:e.detail||``,timeout_seconds:e.timeout_seconds>0?String(e.timeout_seconds):``,max_image_bytes:e.max_image_bytes>0?String(e.max_image_bytes):``,max_dimension:e.max_dimension>0?String(e.max_dimension):``,jpeg_quality:e.jpeg_quality>0?String(e.jpeg_quality):``,max_payload_bytes:e.max_payload_bytes>0?String(e.max_payload_bytes):``,skip_preprocess_below_bytes:e.skip_preprocess_below_bytes!=null&&e.skip_preprocess_below_bytes!==0?String(e.skip_preprocess_below_bytes):e.skip_preprocess_below_bytes===0&&Object.hasOwn(e,`skip_preprocess_below_bytes`)?`0`:``}}function pt(e){let t=String(e??``).trim();if(!t)return 0;if(!/^\d+$/.test(t))return null;let n=Number(t);return Number.isSafeInteger(n)&&n>=0?n:null}function mt(e){let t=e?.ai?.channels||{},n=e?.ai?.default_channel||``;if(n&&t[n]){let e=t[n];return{channelId:n,displayName:ue(n,e),openai:{provider:e.provider||`openai_compatible`,base_url:e.base_url||``,api_key:e.api_key||``,model:e.model||``}}}let r=e?.openai||{};return{channelId:``,displayName:r.model||``,openai:{provider:r.provider||`openai_compatible`,base_url:r.base_url||``,api_key:r.api_key||``,model:r.model||``}}}function ht({config:e,canWrite:t,reloadConfig:n,focused:r}){let i=te(),a=(0,q.useRef)(null),o=(0,q.useId)(),c=(0,q.useId)(),l=(0,q.useId)(),d=ft(e.vision),m=JSON.stringify(d),[g,v]=(0,q.useState)({}),y={...d,...g},b=Object.keys(g).length>0,[x,S]=(0,q.useState)(``),[C,w]=(0,q.useState)(!1),[T,E]=(0,q.useState)(null),[O,k]=(0,q.useState)(!1),[A,M]=(0,q.useState)(ut);(0,q.useEffect)(()=>{v({}),M(ut)},[m]),(0,q.useEffect)(()=>{r&&a.current&&a.current.scrollIntoView({behavior:`smooth`,block:`start`})},[r]);let N=!t||C||!!x,P=mt(e),F=y.provider||dt(P.openai.provider)||`openai_compatible`,I=y.base_url.trim()||P.openai.base_url||(F===`claude`?`https://api.anthropic.com`:`https://api.openai.com/v1`),L=[{value:``,label:P.displayName?`${i(`settingsBasic.visionProviderReuseOpenAI`,null,`默认 AI 通道(留空复用)`)} · ${P.displayName}`:i(`settingsBasic.visionProviderReuseOpenAI`,null,`默认 AI 通道(留空复用)`)},{value:`openai_compatible`,label:i(`settingsProbe.compatible`,null,`兼容 OpenAI 的接口`)},{value:`claude`,label:i(`settingsBasic.providerClaude`,null,`Claude(Anthropic Messages)`)}];y.provider&&!L.some(e=>e.value===y.provider)&&L.push({value:y.provider,label:y.provider});let R=[{value:``,label:`默认(low)`},{value:`auto`,label:`auto(自动)`},{value:`low`,label:`low(省流快速)`},{value:`high`,label:`high(高清细节)`}],z=(e,t)=>{(A.key!==`list`||[`provider`,`base_url`,`api_key`].includes(e))&&M(ut),O||E(null),v(n=>{let r={...n};return t===d[e]?delete r[e]:r[e]=t,r})},ne=()=>{v({}),M(ut),O||E(null)},re=()=>{let e=[[`timeout_seconds`,i(`settingsBasic.visionTimeout`,null,`超时(秒)`)],[`max_image_bytes`,i(`settingsBasic.visionMaxImageBytes`,null,`原始文件上限(字节)`)],[`max_dimension`,i(`settingsBasic.visionMaxDimension`,null,`长边缩放像素`)],[`jpeg_quality`,i(`settingsBasic.visionJpegQuality`,null,`JPEG 质量`)],[`max_payload_bytes`,i(`settingsBasic.visionMaxPayloadBytes`,null,`送 API 体积上限(字节)`)],[`skip_preprocess_below_bytes`,i(`settingsBasic.visionSkipPreprocessBytes`,null,`低于该字节可原图直传`)]],t={};for(let[n,r]of e){let e=pt(y[n]);if(e===null)throw Error(i(`settingsProbe.invalidLimit`,{field:r},`${r}请输入非负整数`));t[n]=e}if(t.jpeg_quality>100)throw Error(`JPEG 质量需在 1 ~ 100 之间(留空或 0 使用默认 82)`);return{enabled:!!y.enabled,provider:y.provider.trim(),base_url:y.base_url.trim(),api_key:y.api_key,model:y.model.trim(),detail:y.detail.trim(),...t}},ie=async e=>{try{await j.post(`/config/apply`),k(!1),ae(e)}catch(e){k(!0),E(e)}},U=async()=>{if(N||!b)return;if(E(null),y.enabled&&!y.model.trim()){E(Error(i(`settingsBasic.visionModelRequired`,null,`启用视觉分析时请填写视觉模型名称`)));return}let e;try{e=re()}catch(e){E(e);return}w(!0);try{await j.put(`/config`,{vision:e}),v({}),await ie(i(`settingsProbe.visionSaved`,null,`视觉模型配置已保存并应用`)),await n({silent:!0})}catch(e){E(e)}finally{w(!1)}},W=async()=>{if(!N&&O){w(!0),E(null);try{await ie(i(`settings.apply.applySuccess`,null,`配置已成功应用`))}finally{w(!1)}}},G=async()=>{if(!N){if(!y.model.trim())M({key:`vision`,payload:null,error:Error(i(`settingsBasic.visionTestFillRequired`,null,`请填写视觉模型,并确保 API Key 可用(可复用 OpenAI)`))});else{S(`vision`),M(ut);try{let e=re(),t=await j.post(`/config/test-vision`,{channel_id:P.channelId||void 0,vision:e,openai:P.openai});M({key:`vision`,payload:t,error:null})}catch(e){M({key:`vision`,payload:null,error:e})}finally{S(``)}}}},K=async()=>{if(N)return;S(`list`),M(ut);let e=!!y.api_key;try{let t=await j.post(`/config/list-models`,{provider:F,credential_scope:e?`vision`:P.channelId?void 0:`openai`,channel_id:!e&&P.channelId?P.channelId:void 0,base_url:I,api_key:e?y.api_key:P.openai.api_key});M({key:`list`,payload:t,error:null})}catch(e){M({key:`list`,payload:null,error:e})}finally{S(``)}},oe=y.enabled?y.model.trim()?(0,Z.jsx)(f,{color:`green`,size:`small`,children:`${i(`common.enabled`,null,`已启用`)} · ${y.model.trim()}`}):(0,Z.jsx)(f,{color:`amber`,size:`small`,children:`待填写模型`}):(0,Z.jsx)(f,{color:`grey`,size:`small`,children:i(`common.disabled`,null,`未启用`)}),se=A.key===`list`&&Array.isArray(A.payload?.models)?A.payload.models:[];return(0,Z.jsx)(`div`,{id:`settings-vision-panel`,ref:a,className:r?`settings-focus-ring`:void 0,children:(0,Z.jsxs)(H,{title:(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)(`span`,{children:i(`settingsBasic.visionConfig`,null,`视觉分析(analyze_image)`)}),oe,b&&(0,Z.jsx)(f,{color:`amber`,size:`small`,children:i(`settings.unsaved`,null,`有未保存修改`)})]}),description:`当主对话模型不支持图片识别(如纯文本推理模型),或安全测试中需要识别本地截图、验证码图片时,开启后将挂载 analyze_image 工具,由独立视觉模型代为识图并仅向主模型返回文字摘要。`,className:`settings-vision-panel`,extra:t?(0,Z.jsxs)(u,{wrap:!0,children:[b&&(0,Z.jsx)(p,{disabled:C||!!x,onClick:ne,children:i(`toolGuard.reset`,null,`撤销修改`)}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,loading:C,disabled:!b||!!x,onClick:U,children:`保存视觉模型`})]}):(0,Z.jsx)(f,{color:`grey`,size:`small`,children:i(`settingsProbe.channelReadOnly`,null,`只读`)}),children:[(0,Z.jsxs)(`div`,{className:`settings-switch-row`,children:[(0,Z.jsx)(_,{checked:y.enabled,disabled:N,onChange:e=>z(`enabled`,e),"aria-label":i(`settingsBasic.visionEnabled`,null,`启用视觉分析工具 analyze_image`)}),(0,Z.jsxs)(`div`,{className:`settings-switch-copy`,children:[(0,Z.jsx)(lt,{strong:!0,children:i(`settingsBasic.visionEnabled`,null,`启用视觉分析工具 analyze_image`)}),(0,Z.jsx)(Q,{children:i(`settingsBasic.visionEnabledHint`,null,`启用后注册 MCP 工具;图片仅在单次 VL 调用中出现,Agent 上下文只保留文字摘要。保存并应用后生效。`)})]})]}),(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,children:[(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(lt,{type:`tertiary`,size:`small`,children:i(`settingsBasic.visionModel`,null,`视觉模型`)}),(0,Z.jsx)(h,{value:y.model,onChange:e=>z(`model`,e),readOnly:N,placeholder:i(`settingsBasic.visionModelPlaceholder`,null,`qwen-vl-max`)})]}),(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(lt,{id:o,type:`tertiary`,size:`small`,children:i(`settingsBasic.apiProvider`,null,`API 提供商`)}),(0,Z.jsx)(D,{value:y.provider,onChange:e=>z(`provider`,e),optionList:L,"aria-labelledby":o,disabled:N,style:{width:`100%`}})]}),(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)(lt,{type:`tertiary`,size:`small`,children:i(`settingsBasic.baseUrl`,null,`API 地址`)}),(0,Z.jsx)(h,{value:y.base_url,onChange:e=>z(`base_url`,e),readOnly:N,placeholder:P.openai.base_url?`留空复用默认通道(${P.openai.base_url})`:i(`settingsBasic.visionBaseUrlPlaceholder`,null,`留空则复用 OpenAI Base URL`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(lt,{type:`tertiary`,size:`small`,children:i(`settingsBasic.apiKey`,null,`API 密钥`)}),(0,Z.jsx)(h,{mode:`password`,autoComplete:`new-password`,value:y.api_key,onChange:e=>z(`api_key`,e),readOnly:N,placeholder:i(`settingsBasic.visionApiKeyPlaceholder`,null,`留空则复用 OpenAI API Key`)})]})]}),(O||T)&&(0,Z.jsxs)(`div`,{className:`settings-channel-notices`,children:[O&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(u,{wrap:!0,children:[(0,Z.jsx)(`span`,{children:`视觉模型配置已写入,但应用失败。`}),(0,Z.jsx)(p,{size:`small`,disabled:N,onClick:W,children:i(`settingsProbe.retryApply`,null,`重试应用`)})]})}),(0,Z.jsx)(V,{error:T})]}),(0,Z.jsxs)(u,{wrap:!0,className:`settings-probe-actions`,children:[(0,Z.jsx)(p,{loading:x===`vision`,disabled:!t||C||!!x&&x!==`vision`,onClick:G,children:i(`settingsProbe.testVision`,null,`测试视觉模型`)}),(0,Z.jsx)(p,{loading:x===`list`,disabled:!t||C||!!x&&x!==`list`,onClick:K,children:i(`settingsBasic.modelsList`,null,`获取模型列表`)})]}),A.error&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:(0,Z.jsx)(V,{error:A.error})}),A.key===`vision`&&A.payload&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:A.payload.success?(0,Z.jsx)(B,{columns:3,items:[{label:i(`settingsProbe.result`,null,`测试结果`),value:(0,Z.jsx)(f,{color:`green`,children:i(`settingsBasic.testSuccess`,null,`连接成功`)})},{label:i(`settingsBasic.visionModel`,null,`视觉模型`),value:A.payload.model||y.model||`—`},{label:i(`settingsProbe.latency`,null,`响应耗时`),value:A.payload.latency_ms==null?`—`:i(`settingsProbe.milliseconds`,{value:A.payload.latency_ms},`${A.payload.latency_ms} 毫秒`)}]}):(0,Z.jsx)(s,{type:`danger`,bordered:!0,closeIcon:null,description:A.payload.error||i(`settingsBasic.testFailed`,null,`连接失败`)})}),A.key===`list`&&A.payload&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:A.payload.success?(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)(lt,{children:i(`settingsBasic.modelsListSuccess`,{count:A.payload.count??se.length},`已获取 ${A.payload.count??se.length} 个模型`)}),(0,Z.jsx)(`span`,{id:l,hidden:!0,children:i(`settingsBasic.modelsListSelectPlaceholder`,null,`请选择视觉模型`)}),se.length>0&&(0,Z.jsx)(D,{filter:!0,"aria-labelledby":l,placeholder:i(`settingsBasic.modelsListSelectPlaceholder`,null,`请选择模型`),value:se.includes(y.model)?y.model:void 0,optionList:se.map(e=>({value:e,label:e})),onChange:e=>z(`model`,e),disabled:N,className:`settings-model-picker`})]}):(0,Z.jsx)(s,{type:A.payload.supported===!1?`info`:`danger`,bordered:!0,closeIcon:null,description:A.payload.error||i(`settingsBasic.modelsListFailed`,null,`获取模型列表失败`)})}),(0,Z.jsx)(ee,{className:`settings-audit-model`,children:(0,Z.jsxs)(ee.Panel,{itemKey:`vision-advanced`,header:(0,Z.jsx)(lt,{strong:!0,children:i(`settingsBasic.visionAdvanced`,null,`高级:预处理与限制`)}),children:[(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)(lt,{id:c,type:`tertiary`,size:`small`,children:i(`settingsBasic.visionDetail`,null,`图片精度(Detail)`)}),(0,Z.jsx)(D,{value:y.detail,onChange:e=>z(`detail`,e),optionList:R,"aria-labelledby":c,disabled:N,style:{width:`100%`}})]}),[[`timeout_seconds`,`visionTimeout`,`超时(秒)`,`60`],[`max_image_bytes`,`visionMaxImageBytes`,`原始文件上限(字节)`,`5242880`],[`max_dimension`,`visionMaxDimension`,`长边缩放像素`,`2048`],[`jpeg_quality`,`visionJpegQuality`,`JPEG 质量`,`82`],[`max_payload_bytes`,`visionMaxPayloadBytes`,`送 API 体积上限(字节)`,`524288`],[`skip_preprocess_below_bytes`,`visionSkipPreprocessBytes`,`低于该字节可原图直传`,`2097152`]].map(([e,t,n,r])=>(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(lt,{type:`tertiary`,size:`small`,children:i(`settingsBasic.`+t,null,n)}),(0,Z.jsx)(h,{value:y[e],onChange:t=>z(e,t),inputMode:`numeric`,readOnly:N,placeholder:r})]},e))]}),(0,Z.jsx)(Q,{children:i(`settingsBasic.visionSkipPreprocessHint`,null,`0 表示始终 JPEG 压缩;需同时满足长边与 payload 限制。留空使用系统默认值。`)})]})})]})})}var{Text:gt}=l;function _t(e){return e.is_external&&e.external_mcp?`${e.external_mcp}::${e.name}`:e.name}function vt(e){let t=e&&typeof e==`object`&&e.properties||{},n=Array.isArray(e?.required)?e.required:[];return Object.entries(t).map(([e,t])=>({name:e,type:t?.type||(t?.enum?`enum`:`—`),required:n.includes(e),description:t?.description||``}))}function yt(){let e=te(),{hasPermission:t}=A(),n=t(`config:read`)||t(`mcp:read`),r=t(`config:write`),[i,a]=(0,q.useState)(1),[o,s]=(0,q.useState)(20),[c,l]=(0,q.useState)(``),d=ie(c,350),[m,g]=(0,q.useState)(`all`),[v,y]=(0,q.useState)({}),[ee,b]=(0,q.useState)(!1),[S,T]=(0,q.useState)(null),[O,k]=(0,q.useState)(null),M=[i,o,d,m],N=(0,q.useCallback)(()=>j.get(`/config/tools`,{page:i,page_size:o,search:d||void 0,tool_filter:m===`on`?`on`:m===`off`?`off`:void 0}),M),P=z(N,[...M,n],{skip:!n});(0,q.useEffect)(()=>{a(1)},[d,m,o]);let F=(0,q.useMemo)(()=>(Array.isArray(P.data?.tools)?P.data.tools:[]).map(e=>{let t=_t(e),n=v[t],r=!!e.enabled;return{...e,key:t,serverEnabled:r,enabled:n?n.enabled:r,dirty:!!n}}),[P.data,v]),I=Object.keys(v).length,L=(e,t)=>{r&&y(n=>{let r={...n},i=e.key;return t===e.serverEnabled?delete r[i]:r[i]={name:e.name,enabled:t,is_external:!!e.is_external,external_mcp:e.external_mcp||void 0},r})},R=async()=>{if(!r||!I)return;let t=Object.values(v).map(e=>({...e}));b(!0),T(null);try{await j.put(`/config`,{tools:t}),await j.post(`/config/apply`),ae(e(`settings.apply.applySuccess`,null,`配置已成功应用`)),y({}),await P.reload()}catch(t){T(t),ne(t,e(`settings.apply.applyFailed`,null,`保存工具开关失败`))}finally{b(!1)}};if(!n)return(0,Z.jsx)(Ie,{permission:`config:read`,label:e(`settings.toolsTitle`,null,`读取工具列表`)});let B=[{title:e(`settings.toolName`,null,`工具`),dataIndex:`name`,width:260,render:(t,n)=>(0,Z.jsxs)(u,{vertical:!0,spacing:2,align:`start`,children:[(0,Z.jsx)(gt,{strong:!0,children:t}),(0,Z.jsxs)(u,{spacing:4,children:[n.is_external?(0,Z.jsx)(f,{size:`small`,color:`violet`,children:`MCP · ${n.external_mcp}`}):(0,Z.jsx)(f,{size:`small`,color:`grey`,children:e(`settings.toolInternal`,null,`内置`)}),n.role_enabled===!1&&(0,Z.jsx)(f,{size:`small`,color:`orange`,children:e(`settings.toolRoleOff`,null,`当前角色未启用`)})]})]})},{title:e(`settings.toolDescription`,null,`说明`),dataIndex:`description`,render:e=>(0,Z.jsx)(C,{content:e||`—`,position:`topLeft`,children:(0,Z.jsx)(gt,{type:`tertiary`,children:re(e||`—`,90)})})},{title:e(`settings.toolStatus`,null,`启用`),dataIndex:`enabled`,width:160,render:(t,n)=>(0,Z.jsxs)(u,{spacing:6,children:[(0,Z.jsx)(_,{size:`small`,checked:t,disabled:!r||ee,onChange:e=>L(n,e),"aria-label":e(`settings.toolStatus`,null,`启用`)}),n.dirty&&(0,Z.jsx)(f,{size:`small`,color:`amber`,children:e(`settings.unsavedShort`,null,`未保存`)})]})},{title:e(`common.actions`,null,`操作`),width:110,render:(t,n)=>(0,Z.jsx)(p,{size:`small`,theme:`borderless`,onClick:()=>k(n),children:e(`settings.toolSchema`,null,`参数`)})}];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(H,{title:e(`settings.toolsTitle`,null,`工具开关`),description:e(`settings.toolsDesc`,null,`开关按工具名写入 config.security.tools;外部 MCP 工具的状态写回对应 MCP 配置。保存后立即应用。`),extra:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(p,{onClick:()=>y({}),disabled:!I||ee,children:e(`toolGuard.reset`,null,`撤销修改`)}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,loading:ee,disabled:!r||!I,onClick:R,children:e(`settings.saveTools`,{count:I},`保存工具开关${I?`(${I})`:``}`)})]}),children:[(0,Z.jsx)(V,{error:S}),(0,Z.jsx)(V,{error:P.error,onRetry:P.reload}),(0,Z.jsx)(G,{columns:B,dataSource:F,rowKey:`key`,loading:P.loading,emptyText:e(`settings.toolsEmpty`,null,`没有匹配的工具`),toolbar:(0,Z.jsxs)(u,{wrap:!0,children:[(0,Z.jsx)(h,{prefix:(0,Z.jsx)(x,{}),value:c,onChange:e=>l(e),placeholder:e(`settings.toolSearch`,null,`按工具名或说明搜索`),style:{width:240},showClear:!0}),(0,Z.jsx)(D,{value:m,onChange:e=>g(e),style:{width:140},optionList:[{value:`all`,label:e(`settings.filterAll`,null,`全部状态`)},{value:`on`,label:e(`settings.filterOn`,null,`仅已启用`)},{value:`off`,label:e(`settings.filterOff`,null,`仅已停用`)}]}),(0,Z.jsx)(f,{size:`small`,color:`blue`,children:e(`settings.toolsTotal`,{total:P.data?.total??0,enabled:P.data?.total_enabled??0},`共 ${P.data?.total??0} 个,已启用 ${P.data?.total_enabled??0} 个`)}),(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),theme:`borderless`,onClick:P.reload,loading:P.loading,children:e(`common.refresh`,null,`刷新`)})]}),pagination:{currentPage:i,pageSize:o,total:P.data?.total||0,showSizeChanger:!0,pageSizeOpts:[10,20,50,100],onPageChange:e=>a(e),onPageSizeChange:e=>{s(e),a(1)}}})]}),(0,Z.jsx)(w,{title:O?e(`settings.toolSchemaTitle`,{name:O.name},`参数定义 · ${O.name}`):``,visible:!!O,onCancel:()=>k(null),width:620,placement:`right`,children:O&&(0,Z.jsx)(bt,{tool:O})})]})}function bt({tool:e}){let t=te(),[n,r]=(0,q.useState)({loading:!0,error:null,schema:null});if((0,q.useEffect)(()=>{let t=!1;return r({loading:!0,error:null,schema:null}),j.get(`/config/tools/${encodeURIComponent(e.name)}/schema`,{external_mcp:e.external_mcp||void 0}).then(e=>{t||r({loading:!1,error:null,schema:e?.input_schema||null})}).catch(e=>{t||r({loading:!1,error:e,schema:null})}),()=>{t=!0}},[e.name,e.external_mcp]),n.loading)return(0,Z.jsx)(Le,{rows:5});if(n.error)return(0,Z.jsx)(V,{error:n.error});if(!n.schema)return(0,Z.jsx)(gt,{type:`tertiary`,children:t(`settings.toolNoSchema`,null,`该工具没有声明参数(无参数 Schema)。`)});let i=vt(n.schema);return(0,Z.jsxs)(`div`,{className:`settings-schema`,children:[i.length>0&&(0,Z.jsxs)(`table`,{className:`settings-schema-table`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`th`,{children:t(`settings.paramName`,null,`参数`)}),(0,Z.jsx)(`th`,{children:t(`settings.paramType`,null,`类型`)}),(0,Z.jsx)(`th`,{children:t(`settings.paramRequired`,null,`必填`)}),(0,Z.jsx)(`th`,{children:t(`settings.paramDesc`,null,`说明`)})]})}),(0,Z.jsx)(`tbody`,{children:i.map(e=>(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{children:(0,Z.jsx)(Re,{children:e.name})}),(0,Z.jsx)(`td`,{children:e.type}),(0,Z.jsx)(`td`,{children:e.required?(0,Z.jsx)(f,{size:`small`,color:`red`,children:`是`}):(0,Z.jsx)(gt,{type:`tertiary`,children:`否`})}),(0,Z.jsx)(`td`,{children:e.description||`—`})]},e.name))})]}),(0,Z.jsx)(K,{value:n.schema,collapsed:!0,title:t(`settings.toolSchemaJson`,null,`JSON Schema`)})]})}function xt(){let e=te(),[t]=a(),{hasPermission:n}=A(),r=n(`config:read`),i=n(`config:write`),o=(0,q.useCallback)(({signal:e}={})=>j.get(`/config`,{include_tools:0},{signal:e}),[]),s=z(o,[r],{skip:!r});return r?(0,Z.jsxs)(Z.Fragment,{children:[s.loading&&!s.data?(0,Z.jsx)(Le,{rows:6}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V,{error:s.error,onRetry:s.reload}),s.data&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ct,{config:s.data,canWrite:i,reloadConfig:s.reload}),(0,Z.jsx)(ht,{config:s.data,canWrite:i,reloadConfig:s.reload,focused:t.get(`focus`)===`vision`})]})]}),(0,Z.jsx)(yt,{})]}):(0,Z.jsx)(Ie,{permission:`config:read`,label:e(`settings.nav.models`,null,`读取模型与工具配置`)})}var{Text:$}=l,St={key:``,payload:null,error:null};function Ct(e){return e!=null&&e!==``&&Number(e)!==0?String(e):e===0?`0`:``}function wt(e={}){let t=e.embedding||{},n=e.retrieval||{},r=n.multi_query||{},i=n.rerank||{},a=n.post_retrieve||{},o=e.indexing||{};return{enabled:!!e.enabled,base_path:e.base_path||`knowledge_base`,embedding_provider:t.provider||`openai`,embedding_model:t.model||``,embedding_base_url:t.base_url||``,embedding_api_key:t.api_key||``,top_k:n.top_k>0?String(n.top_k):`5`,similarity_threshold:n.similarity_threshold>0?String(n.similarity_threshold):`0.4`,sub_index_filter:n.sub_index_filter||``,multi_query_max_queries:r.max_queries>0?String(r.max_queries):``,rerank_provider:i.provider||``,rerank_model:i.model||``,rerank_base_url:i.base_url||``,rerank_api_key:i.api_key||``,prefetch_top_k:Ct(a.prefetch_top_k),max_context_chars:Ct(a.max_context_chars),max_context_tokens:Ct(a.max_context_tokens),chunk_strategy:o.chunk_strategy||``,chunk_size:o.chunk_size>0?String(o.chunk_size):``,chunk_overlap:o.chunk_overlap>0?String(o.chunk_overlap):``,max_chunks_per_item:Ct(o.max_chunks_per_item),batch_size:o.batch_size>0?String(o.batch_size):``,request_timeout_seconds:o.request_timeout_seconds>0?String(o.request_timeout_seconds):``,max_rpm:Ct(o.max_rpm),rate_limit_delay_ms:Ct(o.rate_limit_delay_ms),max_retries:o.max_retries>0?String(o.max_retries):``,retry_delay_ms:o.retry_delay_ms>0?String(o.retry_delay_ms):``,prefer_source_file:!!o.prefer_source_file,sub_indexes:Array.isArray(o.sub_indexes)?o.sub_indexes.join(`, `):``}}function Tt(e,t){let n=String(e??``).trim();if(!n)return 0;if(!/^\d+$/.test(n))throw Error(`${t}请输入非负整数`);let r=Number(n);if(!Number.isSafeInteger(r)||r<0)throw Error(`${t}请输入有效的非负整数`);return r}function Et(e){let t=e?.ai?.channels||{},n=e?.ai?.default_channel||``;if(n&&t[n]){let e=t[n];return{channelId:n,displayName:ue(n,e),openai:{provider:e.provider||`openai_compatible`,base_url:e.base_url||``,api_key:e.api_key||``,model:e.model||``}}}let r=e?.openai||{};return{channelId:``,displayName:r.model||``,openai:{provider:r.provider||`openai_compatible`,base_url:r.base_url||``,api_key:r.api_key||``,model:r.model||``}}}function Dt(){let e=te(),t=r(),{hasPermission:n}=A(),i=n(`config:read`),a=n(`config:write`),o=(0,q.useCallback)(({signal:e}={})=>j.get(`/config`,{include_tools:0},{signal:e}),[]),c=z(o,[i],{skip:!i}),l=(0,q.useId)(),d=(0,q.useId)(),m=(0,q.useId)(),g=(0,q.useId)(),v=(0,q.useMemo)(()=>wt(c.data?.knowledge),[c.data?.knowledge]),y=JSON.stringify(v),[b,x]=(0,q.useState)({}),S={...v,...b},C=Object.keys(b).length>0,[w,T]=(0,q.useState)(``),[E,O]=(0,q.useState)(!1),[k,M]=(0,q.useState)(null),[N,P]=(0,q.useState)(!1),[F,I]=(0,q.useState)(St);if((0,q.useEffect)(()=>{x({}),I(St)},[y]),!i)return(0,Z.jsx)(Ie,{permission:`config:read`,label:e(`settings.nav.knowledge`,null,`读取知识库配置`)});if(c.loading&&!c.data)return(0,Z.jsx)(Le,{rows:6});let L=!a||E||!!w,R=Et(c.data),ne=/api\.deepseek\.com/i.test(R.openai.base_url||``),re=[`claude`,`anthropic`].includes(String(R.openai.provider||``).toLowerCase()),ie=!S.embedding_base_url.trim()&&(ne||re),U=(e,t)=>{(F.key!==`list`||[`embedding_provider`,`embedding_base_url`,`embedding_api_key`].includes(e))&&I(St),N||M(null),x(n=>{let r={...n};return t===v[e]?delete r[e]:r[e]=t,r})},W=()=>{x({}),I(St),N||M(null)},G=()=>{let t=Tt(S.top_k,e(`settingsBasic.topK`,null,`Top-K 结果数量`))||5,n=String(S.similarity_threshold??``).trim(),r=n===``?.4:Number(n);if(!Number.isFinite(r)||r<0||r>1)throw Error(`相似度阈值请输入 0 到 1 之间的数值(例如 0.4)`);let i=Tt(S.multi_query_max_queries,e(`settingsBasic.multiQueryMaxQueries`,null,`MultiQuery 改写变体上限`));if(i>8)throw Error(`MultiQuery 改写变体上限最大为 8(留空使用默认 4,填 1 跳过改写)`);let a=String(S.sub_indexes||``).split(/[,\n\r]+/).map(e=>e.trim()).filter(Boolean);return{enabled:!!S.enabled,base_path:S.base_path.trim()||`knowledge_base`,embedding:{provider:S.embedding_provider.trim()||`openai`,model:S.embedding_model.trim()||`text-embedding-3-small`,base_url:S.embedding_base_url.trim(),api_key:S.embedding_api_key},retrieval:{top_k:t,similarity_threshold:r,sub_index_filter:S.sub_index_filter.trim(),multi_query:{max_queries:i},rerank:{provider:S.rerank_provider.trim(),model:S.rerank_model.trim(),base_url:S.rerank_base_url.trim(),api_key:S.rerank_api_key},post_retrieve:{prefetch_top_k:Tt(S.prefetch_top_k,e(`settingsBasic.prefetchTopK`,null,`预取候选数`)),max_context_chars:Tt(S.max_context_chars,e(`settingsBasic.maxContextChars`,null,`返回内容最大字符数`)),max_context_tokens:Tt(S.max_context_tokens,e(`settingsBasic.maxContextTokens`,null,`返回内容最大 Token 数`))}},indexing:{chunk_strategy:S.chunk_strategy.trim(),chunk_size:Tt(S.chunk_size,e(`settingsBasic.chunkSize`,null,`分块大小`)),chunk_overlap:Tt(S.chunk_overlap,e(`settingsBasic.chunkOverlap`,null,`分块重叠`)),max_chunks_per_item:Tt(S.max_chunks_per_item,e(`settingsBasic.maxChunksPerItem`,null,`单个知识项最大块数`)),batch_size:Tt(S.batch_size,e(`settingsBasic.batchSize`,null,`嵌入批大小`)),request_timeout_seconds:Tt(S.request_timeout_seconds,e(`settingsBasic.requestTimeoutSeconds`,null,`嵌入 HTTP 超时`)),max_rpm:Tt(S.max_rpm,e(`settingsBasic.maxRpm`,null,`每分钟最大请求数`)),rate_limit_delay_ms:Tt(S.rate_limit_delay_ms,e(`settingsBasic.rateLimitDelay`,null,`请求间隔延迟`)),max_retries:Tt(S.max_retries,e(`settingsBasic.maxRetries`,null,`最大重试次数`)),retry_delay_ms:Tt(S.retry_delay_ms,e(`settingsBasic.retryDelay`,null,`重试间隔`)),prefer_source_file:!!S.prefer_source_file,sub_indexes:a}}},K=async e=>{try{await j.post(`/config/apply`),P(!1),ae(e)}catch(e){P(!0),M(e)}},oe=async()=>{if(L||!C)return;if(M(null),S.enabled&&!S.embedding_model.trim()){M(Error(`启用知识库时请填写嵌入模型名称(例如 text-embedding-v4 或 text-embedding-3-small)`));return}let e;try{e=G()}catch(e){M(e);return}O(!0);try{await j.put(`/config`,{knowledge:e}),x({}),await K(`知识库配置已保存并应用`),await c.reload({silent:!0})}catch(e){M(e)}finally{O(!1)}},se=async()=>{if(!L&&N){O(!0),M(null);try{await K(e(`settings.apply.applySuccess`,null,`配置已成功应用`))}finally{O(!1)}}},ce=async()=>{if(!L){if(!S.embedding_model.trim())I({key:`embedding`,payload:null,error:Error(`请先填写嵌入模型名称`)});else{T(`embedding`),I(St);try{let e=await j.post(`/config/test-embedding`,{channel_id:R.channelId||void 0,embedding:{provider:S.embedding_provider.trim()||`openai`,model:S.embedding_model.trim(),base_url:S.embedding_base_url.trim(),api_key:S.embedding_api_key},openai:R.openai});I({key:`embedding`,payload:e,error:null})}catch(e){I({key:`embedding`,payload:null,error:e})}finally{T(``)}}}},le=async()=>{if(L)return;T(`list`),I(St);let e=!!S.embedding_api_key,t=S.embedding_base_url.trim()||(re?``:R.openai.base_url)||`https://api.openai.com/v1`;try{let n=await j.post(`/config/list-models`,{provider:`openai_compatible`,credential_scope:e?`knowledgeEmbedding`:R.channelId?void 0:`openai`,channel_id:!e&&R.channelId?R.channelId:void 0,base_url:t,api_key:e?S.embedding_api_key:R.openai.api_key});I({key:`list`,payload:n,error:null})}catch(e){I({key:`list`,payload:null,error:e})}finally{T(``)}},ue=F.key===`list`&&Array.isArray(F.payload?.models)?F.payload.models:[];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V,{error:c.error,onRetry:c.reload}),c.data&&(0,Z.jsxs)(H,{title:(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)(`span`,{children:e(`settings.knowledge.title`,null,`知识库设置`)}),(0,Z.jsx)(f,{color:S.enabled?`green`:`grey`,size:`small`,children:S.enabled?e(`common.enabled`,null,`已启用`):e(`common.disabled`,null,`未启用`)}),C&&(0,Z.jsx)(f,{color:`amber`,size:`small`,children:e(`settings.unsaved`,null,`有未保存修改`)})]}),description:`开启后将自动初始化向量知识库并向智能体挂载 search_knowledge_base 检索工具。启用保存后,可前往「知识管理」新增知识条目并构建索引。`,className:`settings-knowledge-panel`,extra:(0,Z.jsxs)(u,{wrap:!0,children:[(0,Z.jsx)(p,{onClick:()=>t(`/knowledge-management`),children:`前往知识管理`}),a?(0,Z.jsxs)(Z.Fragment,{children:[C&&(0,Z.jsx)(p,{disabled:E||!!w,onClick:W,children:e(`toolGuard.reset`,null,`撤销修改`)}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,loading:E,disabled:!C||!!w,onClick:oe,children:e(`settings.saveAndApply`,null,`保存并应用`)})]}):(0,Z.jsx)(f,{color:`grey`,size:`small`,children:e(`settingsProbe.channelReadOnly`,null,`只读`)})]}),children:[(0,Z.jsxs)(`div`,{className:`settings-switch-row`,children:[(0,Z.jsx)(_,{checked:S.enabled,disabled:L,onChange:e=>U(`enabled`,e),"aria-label":e(`settingsBasic.enableKnowledge`,null,`启用知识检索功能`)}),(0,Z.jsxs)(`div`,{className:`settings-switch-copy`,children:[(0,Z.jsx)($,{strong:!0,children:e(`settingsBasic.enableKnowledge`,null,`启用知识检索功能`)}),(0,Z.jsx)(Q,{children:`保存并应用后立即在线生效,无需重启服务。`})]})]}),(0,Z.jsx)(`div`,{className:`settings-vision-grid`,children:(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.knowledgeBasePath`,null,`知识库路径`)}),(0,Z.jsx)(h,{value:S.base_path,onChange:e=>U(`base_path`,e),readOnly:L,placeholder:e(`settingsBasic.knowledgeBasePathPlaceholder`,null,`knowledge_base`)}),(0,Z.jsx)(Q,{children:e(`settingsBasic.knowledgeBasePathHint`,null,`相对于配置文件所在目录的路径`)})]})}),(0,Z.jsxs)(`div`,{className:`settings-subsection`,children:[(0,Z.jsx)($,{strong:!0,className:`settings-subsection-title`,children:e(`settingsBasic.embeddingConfig`,null,`嵌入模型配置`)}),ie&&(0,Z.jsx)(s,{type:`info`,bordered:!0,closeIcon:null,description:`提示:当前默认 AI 通道(如 DeepSeek 官方或 Claude 接口)通常不提供 OpenAI 兼容的 /embeddings 向量接口。启用知识库时,请在此处填写独立的向量服务地址与密钥(如阿里云百炼 DashScope、OpenAI、SiliconFlow 或本地 Ollama / vLLM)。`}),(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)($,{id:l,type:`tertiary`,size:`small`,children:e(`settingsBasic.provider`,null,`提供商`)}),(0,Z.jsx)(D,{value:S.embedding_provider||`openai`,onChange:e=>U(`embedding_provider`,e),optionList:[{value:`openai`,label:e(`settingsProbe.compatible`,null,`兼容 OpenAI 的接口`)}],"aria-labelledby":l,disabled:L,style:{width:`100%`}})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.modelName`,null,`模型名称`)}),(0,Z.jsx)(h,{value:S.embedding_model,onChange:e=>U(`embedding_model`,e),readOnly:L,placeholder:e(`settingsBasic.embeddingModelPlaceholder`,null,`text-embedding-v4`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.baseUrl`,null,`API 地址`)}),(0,Z.jsx)(h,{value:S.embedding_base_url,onChange:e=>U(`embedding_base_url`,e),readOnly:L,placeholder:!re&&R.openai.base_url?`留空复用默认通道(${R.openai.base_url})`:`例如 https://dashscope.aliyuncs.com/compatible-mode/v1`})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.apiKey`,null,`API 密钥`)}),(0,Z.jsx)(h,{mode:`password`,autoComplete:`new-password`,value:S.embedding_api_key,onChange:e=>U(`embedding_api_key`,e),readOnly:L,placeholder:e(`settingsBasic.embeddingApiKeyPlaceholder`,null,`留空则使用默认通道 API Key`)})]})]}),(0,Z.jsxs)(u,{wrap:!0,className:`settings-probe-actions`,children:[(0,Z.jsx)(p,{loading:w===`embedding`,disabled:!a||E||!!w&&w!==`embedding`,onClick:ce,children:`测试嵌入模型`}),(0,Z.jsx)(p,{loading:w===`list`,disabled:!a||E||!!w&&w!==`list`,onClick:le,children:e(`settingsBasic.modelsList`,null,`获取模型列表`)})]}),F.error&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:(0,Z.jsx)(V,{error:F.error})}),F.key===`embedding`&&F.payload&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:F.payload.success?(0,Z.jsx)(B,{columns:4,items:[{label:e(`settingsProbe.result`,null,`测试结果`),value:(0,Z.jsx)(f,{color:`green`,children:e(`settingsBasic.testSuccess`,null,`连接成功`)})},{label:e(`settingsBasic.modelName`,null,`模型名称`),value:F.payload.model||S.embedding_model||`—`},{label:`向量维度`,value:F.payload.dimensions?`${F.payload.dimensions} 维`:`—`},{label:e(`settingsProbe.latency`,null,`响应耗时`),value:F.payload.latency_ms==null?`—`:e(`settingsProbe.milliseconds`,{value:F.payload.latency_ms},`${F.payload.latency_ms} 毫秒`)}]}):(0,Z.jsx)(s,{type:`danger`,bordered:!0,closeIcon:null,description:F.payload.error||e(`settingsBasic.testFailed`,null,`连接失败`)})}),F.key===`list`&&F.payload&&(0,Z.jsx)(`div`,{className:`settings-probe-result`,children:F.payload.success?(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[(0,Z.jsx)($,{children:e(`settingsBasic.modelsListSuccess`,{count:F.payload.count??ue.length},`已获取 ${F.payload.count??ue.length} 个模型`)}),(0,Z.jsx)(`span`,{id:g,hidden:!0,children:e(`settingsBasic.modelsListSelectPlaceholder`,null,`请选择嵌入模型`)}),ue.length>0&&(0,Z.jsx)(D,{filter:!0,"aria-labelledby":g,placeholder:e(`settingsBasic.modelsListSelectPlaceholder`,null,`请选择模型`),value:ue.includes(S.embedding_model)?S.embedding_model:void 0,optionList:ue.map(e=>({value:e,label:e})),onChange:e=>U(`embedding_model`,e),disabled:L,className:`settings-model-picker`})]}):(0,Z.jsx)(s,{type:F.payload.supported===!1?`info`:`danger`,bordered:!0,closeIcon:null,description:F.payload.error||e(`settingsBasic.modelsListFailed`,null,`获取模型列表失败`)})})]}),(0,Z.jsxs)(`div`,{className:`settings-subsection`,children:[(0,Z.jsx)($,{strong:!0,className:`settings-subsection-title`,children:e(`settingsBasic.retrievalConfig`,null,`检索配置`)}),(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,children:[(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.topK`,null,`Top-K 结果数量`)}),(0,Z.jsx)(h,{value:S.top_k,onChange:e=>U(`top_k`,e),inputMode:`numeric`,readOnly:L,placeholder:e(`settingsBasic.topKPlaceholder`,null,`5`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.similarityThreshold`,null,`相似度阈值(0 ~ 1)`)}),(0,Z.jsx)(h,{value:S.similarity_threshold,onChange:e=>U(`similarity_threshold`,e),readOnly:L,placeholder:`0.4`})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.multiQueryMaxQueries`,null,`MultiQuery 改写变体上限`)}),(0,Z.jsx)(h,{value:S.multi_query_max_queries,onChange:e=>U(`multi_query_max_queries`,e),inputMode:`numeric`,readOnly:L,placeholder:e(`settingsBasic.multiQueryMaxQueriesPlaceholder`,null,`4`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.subIndexFilter`,null,`子索引过滤(可选)`)}),(0,Z.jsx)(h,{value:S.sub_index_filter,onChange:e=>U(`sub_index_filter`,e),readOnly:L,placeholder:e(`settingsBasic.subIndexFilterPlaceholder`,null,`如 prod,与索引 sub_indexes 一致`)})]})]}),(0,Z.jsx)(Q,{children:e(`settingsBasic.similarityHint`,null,`低于相似度阈值的结果将被过滤;MultiQuery 设为 1 时跳过 LLM 改写直接做向量检索。`)})]}),(N||k)&&(0,Z.jsxs)(`div`,{className:`settings-channel-notices`,children:[N&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(u,{wrap:!0,children:[(0,Z.jsx)(`span`,{children:`知识库配置已写入 config.yaml,但动态应用失败(请检查嵌入模型配置或密钥)。`}),(0,Z.jsx)(p,{size:`small`,disabled:L,onClick:se,children:e(`settingsProbe.retryApply`,null,`重试应用`)})]})}),(0,Z.jsx)(V,{error:k})]}),(0,Z.jsxs)(ee,{className:`settings-audit-model`,children:[(0,Z.jsxs)(ee.Panel,{itemKey:`knowledge-rerank`,header:(0,Z.jsx)($,{strong:!0,children:e(`settingsBasic.ragPipelineHeader`,null,`高级:精排(Rerank)与检索后处理`)}),children:[(0,Z.jsx)(Q,{children:e(`settingsBasic.ragPipelineHint`,null,`精排失败时会自动降级为融合排序,不影响基础检索可用性。`)}),(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,style:{marginTop:8},children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)($,{id:d,type:`tertiary`,size:`small`,children:e(`settingsBasic.rerankProvider`,null,`精排提供商`)}),(0,Z.jsx)(D,{value:S.rerank_provider,onChange:e=>U(`rerank_provider`,e),optionList:[{value:``,label:e(`settingsBasic.rerankProviderAuto`,null,`自动(按 Base URL 推断)`)},{value:`dashscope`,label:`DashScope(gte-rerank)`},{value:`cohere`,label:e(`settingsBasic.rerankProviderCohere`,null,`Cohere / /v1/rerank 兼容接口`)}],"aria-labelledby":d,disabled:L,style:{width:`100%`}})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.rerankModel`,null,`精排模型(可选)`)}),(0,Z.jsx)(h,{value:S.rerank_model,onChange:e=>U(`rerank_model`,e),readOnly:L,placeholder:e(`settingsBasic.rerankModelPlaceholder`,null,`留空按提供商自动选择`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.rerankBaseUrl`,null,`精排 Base URL(可选)`)}),(0,Z.jsx)(h,{value:S.rerank_base_url,onChange:e=>U(`rerank_base_url`,e),readOnly:L,placeholder:e(`settingsBasic.rerankBaseUrlPlaceholder`,null,`留空则复用嵌入 / OpenAI 的 base_url`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.rerankApiKey`,null,`精排 API Key(可选)`)}),(0,Z.jsx)(h,{mode:`password`,autoComplete:`new-password`,value:S.rerank_api_key,onChange:e=>U(`rerank_api_key`,e),readOnly:L,placeholder:e(`settingsBasic.rerankApiKeyPlaceholder`,null,`留空则复用嵌入 / OpenAI 的 api_key`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.prefetchTopK`,null,`预取候选数`)}),(0,Z.jsx)(h,{value:S.prefetch_top_k,onChange:e=>U(`prefetch_top_k`,e),inputMode:`numeric`,readOnly:L,placeholder:e(`settingsBasic.prefetchTopKPlaceholder`,null,`20`)})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.maxContextChars`,null,`返回内容最大字符数`)}),(0,Z.jsx)(h,{value:S.max_context_chars,onChange:e=>U(`max_context_chars`,e),inputMode:`numeric`,readOnly:L,placeholder:`0`})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.maxContextTokens`,null,`返回内容最大 Token 数`)}),(0,Z.jsx)(h,{value:S.max_context_tokens,onChange:e=>U(`max_context_tokens`,e),inputMode:`numeric`,readOnly:L,placeholder:`0`})]})]})]}),(0,Z.jsx)(ee.Panel,{itemKey:`knowledge-indexing`,header:(0,Z.jsx)($,{strong:!0,children:e(`settingsBasic.indexConfig`,null,`高级:索引分块与限流配置`)}),children:(0,Z.jsxs)(`div`,{className:`settings-vision-grid`,children:[(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)($,{id:m,type:`tertiary`,size:`small`,children:e(`settingsBasic.chunkStrategy`,null,`分块策略`)}),(0,Z.jsx)(D,{value:S.chunk_strategy,onChange:e=>U(`chunk_strategy`,e),optionList:[{value:``,label:e(`settingsBasic.chunkStrategyMarkdownRecursive`,null,`Markdown 标题切分后递归(默认推荐)`)},{value:`markdown_then_recursive`,label:e(`settingsBasic.chunkStrategyMarkdownRecursive`,null,`Markdown 标题切分后递归`)},{value:`recursive`,label:e(`settingsBasic.chunkStrategyRecursive`,null,`仅递归切分`)}],"aria-labelledby":m,disabled:L,style:{width:`100%`}})]}),[[`chunk_size`,`chunkSize`,`分块大小(Chunk Size)`,`512`],[`chunk_overlap`,`chunkOverlap`,`分块重叠(Chunk Overlap)`,`50`],[`max_chunks_per_item`,`maxChunksPerItem`,`单个知识项最大块数`,`0`],[`batch_size`,`batchSize`,`嵌入批大小`,`64`],[`request_timeout_seconds`,`requestTimeoutSeconds`,`嵌入 HTTP 超时(秒)`,`120`],[`max_rpm`,`maxRpm`,`每分钟最大请求数(Max RPM)`,`0`],[`rate_limit_delay_ms`,`rateLimitDelay`,`请求间隔延迟(毫秒)`,`0`],[`max_retries`,`maxRetries`,`最大重试次数`,`3`],[`retry_delay_ms`,`retryDelay`,`重试间隔(毫秒)`,`1000`]].map(([t,n,r,i])=>(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.`+n,null,r)}),(0,Z.jsx)(h,{value:S[t],onChange:e=>U(t,e),inputMode:`numeric`,readOnly:L,placeholder:i})]},t)),(0,Z.jsxs)(`label`,{className:`settings-field settings-field-wide`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.subIndexes`,null,`子索引标签(逗号分隔)`)}),(0,Z.jsx)(h,{value:S.sub_indexes,onChange:e=>U(`sub_indexes`,e),readOnly:L,placeholder:e(`settingsBasic.subIndexesPlaceholder`,null,`例如: prod, knowledge`)})]}),(0,Z.jsxs)(`div`,{className:`settings-field`,children:[(0,Z.jsx)($,{type:`tertiary`,size:`small`,children:e(`settingsBasic.preferSourceFile`,null,`优先从磁盘源文件读取`)}),(0,Z.jsx)(_,{checked:S.prefer_source_file,disabled:L,onChange:e=>U(`prefer_source_file`,e),"aria-label":e(`settingsBasic.preferSourceFile`,null,`优先从磁盘源文件读取`)})]})]})})]})]})]})}var{Text:Ot}=l;function kt(e){let t=Number(e);return Number.isFinite(t)&&t>0?Math.trunc(t):0}function At(e){let t=kt(e?.promptTokens),n=kt(e?.cachedTokens);return t?`${(Math.min(n,t)/t*100).toFixed(1)}%`:`—`}var jt=[[`events`,`settingsDisplay.events`,`记录数`],[`modelCalls`,`dashboard.usageCalls`,`模型调用`],[`promptTokens`,`dashboard.usageInput`,`输入令牌`],[`completionTokens`,`dashboard.usageOutput`,`输出令牌`],[`totalTokens`,`dashboard.usageTotal`,`总令牌数`],[`cachedTokens`,`dashboard.usageCacheRead`,`缓存读取`]];function Mt(e,t){return[{title:t,dataIndex:`key`,render:(e,t)=>(0,Z.jsx)(Ot,{strong:!0,children:t.label||e||`—`})},...jt.map(([t,n,r])=>({title:e(n,null,r),dataIndex:t,align:`right`,render:e=>O(kt(e))}))]}function Nt(){let e=te(),{hasPermission:t}=A(),n=t(`dashboard:read`),r=t(`chat:read`),i=(0,q.useId)(),[a,o]=(0,q.useState)(7),[s,c]=(0,q.useState)(365),[l,d]=(0,q.useState)(20),[m,g]=(0,q.useState)(``),_=ie(m.trim(),400),[v,y]=(0,q.useState)(null),[ee,b]=(0,q.useState)(!1),[x,S]=(0,q.useState)(``),C=ie(x.trim(),300),w=r?v?.value:void 0,T=w?s:a,M=!!w||n,N=r&&ee,P=z(async()=>((await j.get(`/conversations`,{search:C||void 0,limit:50}))?.conversations||[]).map(t=>({value:t.id,label:[t.title||e(`chat.untitled`,null,`未命名对话`),k(t.updatedAt||t.createdAt)].join(` · `)})),[N,C,e],{skip:!N}),F=P.data||[],I=v&&!F.some(e=>e.value===v.value)?[v,...F]:F,L=w?void 0:_||void 0,ne=w?[`conversation`,w].join(`:`):L||``,B=(0,q.useCallback)(async()=>({scopeKey:ne,result:w?await j.get(`/conversations/${encodeURIComponent(w)}/token-usage`,{days:T,limit:l}):await j.get(`/usage/tokens`,{days:T,limit:l,project_id:L})}),[w,T,l,ne,L]),U=z(B,[B,M],{skip:!M}),W=M&&ne===U.data?.scopeKey?U.data.result:null,K=W?.summary||{},ae=(0,q.useMemo)(()=>[{id:`total`,label:e(`tokenUsageUI.usageTotal`,null,`总 Token`),value:O(kt(K.totalTokens))},{id:`input`,label:e(`tokenUsageUI.usageInput`,null,`输入 Token`),value:O(kt(K.promptTokens))},{id:`output`,label:e(`tokenUsageUI.usageOutput`,null,`输出 Token`),value:O(kt(K.completionTokens))},{id:`cache`,label:e(`tokenUsageUI.usageCacheRead`,null,`缓存读取`),value:O(kt(K.cachedTokens))},{id:`cacheWrite`,label:e(`tokenUsageUI.usageCacheWrite`,null,`缓存写入`),value:O(kt(K.cacheWriteTokens))},{id:`reasoning`,label:e(`tokenUsageUI.usageReasoning`,null,`推理 Token`),value:O(kt(K.reasoningTokens))},{id:`calls`,label:e(`tokenUsageUI.usageCalls`,null,`模型调用`),value:O(kt(K.modelCalls))},{id:`rate`,label:e(`tokenUsageUI.usageCacheRate`,null,`缓存命中率`),value:At(K),detail:e(`tokenUsageUI.cacheNote`,null,`缓存读取是输入的一部分,不重复计入总量`)}],[K,e]);if(!n&&!r)return(0,Z.jsx)(Ie,{permission:`dashboard:read`,label:e(`settings.nav.tokenUsage`,null,`读取 Token 用量`)});let oe=Array.isArray(W?.byDay)?W.byDay:[],se=Array.isArray(W?.byModel)?W.byModel:[],ce=Array.isArray(W?.recent)?W.recent:[],le=W?.today||{},ue=e(`tokenUsageUI.selectConversation`,null,`搜索并选择会话`);return(0,Z.jsxs)(Z.Fragment,{children:[M&&(0,Z.jsx)(V,{error:U.error,onRetry:U.reload}),(0,Z.jsxs)(H,{title:e(`settings.nav.tokenUsage`,null,`Token 用量`),children:[(0,Z.jsxs)(`div`,{className:`settings-token-filters`,children:[r&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{id:i+`-conversation`,hidden:!0,children:ue}),(0,Z.jsx)(D,{className:`settings-token-conversation`,"aria-labelledby":i+`-conversation`,placeholder:ue,value:w,optionList:I,filter:!0,remote:!0,showClear:!0,loading:P.loading,onSearch:S,onDropdownVisibleChange:e=>{b(e),e||S(``)},onChange:e=>y(I.find(t=>t.value===e)||null)})]}),(0,Z.jsx)(`span`,{id:i+`-days`,hidden:!0,children:e(`settings.usageDays`,null,`时间范围`)}),(0,Z.jsx)(D,{"aria-labelledby":i+`-days`,value:T,onChange:e=>(w?c:o)(Number(e)),style:{width:120},optionList:[7,30,90,365].map(t=>({value:t,label:e(`tokenUsageUI.periodDays`,{count:t},`${t} 天`)}))}),(0,Z.jsx)(`span`,{id:i+`-limit`,hidden:!0,children:e(`tokenUsageUI.recentTitle`,null,`最近记录`)}),(0,Z.jsx)(D,{"aria-labelledby":i+`-limit`,value:l,onChange:e=>d(Number(e)),style:{width:130},optionList:[20,50,100,200].map(t=>({value:t,label:e(`tokenUsageUI.recentLimit`,{count:t},`最近 ${t} 条`)}))}),n&&!w&&(0,Z.jsx)(h,{value:m,onChange:e=>g(e),placeholder:e(`settingsDisplay.projectIdOptional`,null,`项目 ID(可选)`),style:{width:180},showClear:!0}),(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),onClick:U.reload,loading:U.loading,disabled:!M,children:e(`common.refresh`,null,`刷新`)})]}),r&&(0,Z.jsx)(V,{error:P.error,onRetry:P.reload}),M&&(U.loading||!U.error)&&!W&&(0,Z.jsx)(Le,{rows:3}),W&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(R,{metrics:ae,columns:4}),(0,Z.jsxs)(u,{spacing:8,wrap:!0,children:[(0,Z.jsx)(f,{size:`small`,color:`blue`,children:e(`tokenUsageUI.todayTotal`,{total:O(kt(le.totalTokens))},`今日 ${O(kt(le.totalTokens))} tokens`)}),(0,Z.jsx)(f,{size:`small`,color:`grey`,children:e(`tokenUsageUI.todayCalls`,{calls:O(kt(le.modelCalls))},`今日 ${O(kt(le.modelCalls))} 次模型调用`)}),(0,Z.jsx)(f,{size:`small`,color:`green`,children:e(`tokenUsageUI.todayCache`,{rate:At(le)},`今日缓存命中 ${At(le)}`)})]})]})]}),W&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(H,{title:e(`tokenUsageUI.trendTitle`,null,`每日用量`),children:(0,Z.jsx)(G,{columns:Mt(e,e(`tokenUsageUI.colDay`,null,`日期`)),dataSource:oe,rowKey:`key`,loading:U.loading,pagination:!1,emptyText:e(`tokenUsageUI.noDailyData`,null,`暂无每日用量记录`)})}),(0,Z.jsx)(H,{title:e(`tokenUsageUI.modelTitle`,null,`按模型`),children:(0,Z.jsx)(G,{columns:Mt(e,e(`tokenUsageUI.colModel`,null,`模型`)),dataSource:se,rowKey:`key`,loading:U.loading,pagination:!1,emptyText:e(`common.noData`,null,`暂无数据`)})}),(0,Z.jsx)(H,{title:e(`tokenUsageUI.recentTitle`,null,`最近记录`),children:(0,Z.jsx)(G,{columns:[{title:e(`tokenUsageUI.colTime`,null,`时间`),dataIndex:`createdAt`,width:180,render:e=>k(e)},{title:e(`tokenUsageUI.colModel`,null,`模型`),dataIndex:`model`,render:e=>e||`—`},{title:e(`settingsDisplay.usageSource`,null,`用量来源`),dataIndex:`source`,render:e=>e||`—`},{title:e(`settingsDisplay.orchestration`,null,`协作方式`),dataIndex:`orchestration`,render:e=>e||`—`},{title:e(`settingsDisplay.tokensBreakdown`,null,`输入 / 输出 / 总令牌数`),align:`right`,render:(e,t)=>`${O(kt(t.promptTokens))} / ${O(kt(t.completionTokens))} / ${O(kt(t.totalTokens))}`},{title:e(`settingsDisplay.conversation`,null,`对话`),dataIndex:`conversationId`,width:200,render:e=>(0,Z.jsx)(Ot,{type:`tertiary`,children:re(e||`—`,18)})}],dataSource:ce,rowKey:`id`,loading:U.loading,pagination:{pageSize:10,showSizeChanger:!1},emptyText:e(`common.noData`,null,`暂无数据`)})})]})]})}var{Text:Pt}=l;function Ft(e,t){let n=parseInt(e,10);return Number.isFinite(n)&&n>=0?n:t}function It(e,t){return e(`settingsStorage.cat.${t.key}`,null,t.label||t.key)}function Lt(e,t){return e(`settingsStorage.catHint.${t.key}`,null,t.hint||``)}function Rt(){let e=te(),{hasPermission:t}=A(),n=t(`storage:read`),r=t(`storage:write`),i=t(`config:write`),a=z(()=>j.get(`/storage/meta`),[n],{skip:!n}),o=z(()=>j.get(`/storage/status`),[n],{skip:!n}),[c,l]=(0,q.useState)(null),[d,f]=(0,q.useState)(``),[m,g]=(0,q.useState)(null),[y,ee]=(0,q.useState)(null);(0,q.useEffect)(()=>{if(!a.data)return;let e={};for(let t of a.data.categories||[])e[t.key]={enabled:!!t.enabled,retention_days:Number(t.retention_days)||0};l({auto_clean:!!a.data.auto_clean,interval_minutes:Number(a.data.interval_minutes)||0,orphan_grace_days:Number(a.data.orphan_grace_days)||0,active_grace_hours:Number(a.data.active_grace_hours)||0,categories:e})},[a.data]);let b=(0,q.useCallback)(async()=>{if(n){f(`status`),g(null);try{let e=await j.get(`/storage/status`,{refresh:1});o.setData(e)}catch(e){g(e)}finally{f(``)}}},[n,o.setData]),x=async()=>{if(!i||!c)return;f(`policy`),g(null);let t={};for(let[e,n]of Object.entries(c.categories||{}))t[e]={enabled:!!n.enabled,retention_days:Ft(n.retention_days,0)};let n={auto_clean:!!c.auto_clean,interval_minutes:Ft(c.interval_minutes,5),orphan_grace_days:Ft(c.orphan_grace_days,0),active_grace_hours:Ft(c.active_grace_hours,1),categories:t};try{await j.put(`/config`,{storage:n}),ae(e(`settingsStorage.saved`,null,`清理策略已保存`)),await a.reload()}catch(t){g(t),ne(t,e(`settingsStorage.saveFailed`,null,`保存失败`))}finally{f(``)}},S=async t=>{if(r){f(t?`preview`:`clean`),g(null);try{let n=t?await j.post(`/storage/cleanup`,{dry_run:!0}):await j.post(`/storage/cleanup`,{dry_run:!1,confirm:!0});if(ee(n),t)ae(e(`settingsStorage.previewTitle`,null,`预览完成(未删除任何文件)`));else{ae(e(`settingsStorage.cleanDone`,null,`清理完成`));let t=await j.get(`/storage/status`,{refresh:1});o.setData(t)}}catch(t){g(t),ne(t,e(`settingsStorage.cleanupFailed`,null,`清理请求失败`))}finally{f(``)}}},w=o.data?.totals||{},T=o.data?.filesystem||{},D=(0,q.useMemo)(()=>[{label:e(`settingsStorage.diskUsed`,null,`磁盘已用`),value:T.available?L(T.used_bytes):e(`settingsStorage.unavailable`,null,`不可用`)},{label:e(`settingsStorage.runtimeTotal`,null,`运行空间占用`),value:`${L(w.bytes)}(${O(w.units)} ${e(`settingsStorage.itemsUnit`,null,`项`)})`},{label:e(`settingsStorage.reclaimable`,null,`可回收`),value:`${L(w.reclaimable_bytes)}(${O(w.reclaimable_units)} ${e(`settingsStorage.itemsUnit`,null,`项`)})`},{label:e(`settingsStorage.inodes`,null,`inode 使用`),value:T.available&&T.inodes_total>0?`${O(T.inodes_total-T.inodes_free)} / ${O(T.inodes_total)}`:e(`settingsStorage.unavailable`,null,`不可用`)}],[T,w,e]);if(!n)return(0,Z.jsx)(Ie,{permission:`storage:read`,label:e(`settings.nav.storage`,null,`读取存储状态`)});if(a.loading&&!a.data||o.loading&&!o.data)return(0,Z.jsx)(Le,{rows:6});let M=(a.data?.categories||[]).map(e=>{let t=(o.data?.categories||[]).find(t=>t.key===e.key)||{};return{...e,stat:t,key:e.key}}),N=[{title:e(`settingsStorage.colCategory`,null,`类别`),dataIndex:`label`,width:200,render:(t,n)=>(0,Z.jsx)(C,{content:Lt(e,n),position:`topLeft`,children:(0,Z.jsxs)(u,{vertical:!0,spacing:2,align:`start`,children:[(0,Z.jsx)(Pt,{strong:!0,children:It(e,n)}),n.stat.missing&&(0,Z.jsx)(Pt,{type:`tertiary`,size:`small`,children:e(`settingsStorage.unused`,null,`未使用`)})]})})},{title:e(`settingsStorage.colRoot`,null,`目录`),dataIndex:`key`,render:(e,t)=>(0,Z.jsx)(C,{content:t.stat.root||``,position:`topLeft`,children:(0,Z.jsx)(Re,{children:t.stat.missing?`—`:t.stat.root||`—`})})},{title:e(`settingsStorage.colUnits`,null,`项目数`),align:`right`,width:100,render:(e,t)=>t.stat.missing?`—`:O(t.stat.units)},{title:e(`settingsStorage.colSize`,null,`占用`),align:`right`,width:110,render:(e,t)=>t.stat.missing?`—`:L(t.stat.bytes)},{title:e(`settingsStorage.colReclaimable`,null,`可回收`),align:`right`,width:190,render:(t,n)=>n.stat.missing?`—`:(0,Z.jsxs)(u,{vertical:!0,spacing:2,align:`end`,children:[(0,Z.jsx)(Pt,{strong:!0,children:L(n.stat.reclaimable_bytes)}),(0,Z.jsxs)(Pt,{type:`tertiary`,size:`small`,children:[`${O(n.stat.reclaimable_units)} ${e(`settingsStorage.itemsUnit`,null,`项`)}`,n.stat.orphan_units?` · ${e(`settingsStorage.orphanSuffix`,null,`含孤儿`)} ${n.stat.orphan_units}`:``,n.stat.skipped_active?` · ${e(`settingsStorage.skippedActive`,null,`跳过活跃`)} ${n.stat.skipped_active}`:``]})]})},{title:e(`settingsStorage.colRetention`,null,`保留天数`),width:130,render:(e,t)=>(0,Z.jsx)(h,{value:String(c?.categories?.[t.key]?.retention_days??0),disabled:!i||d===`policy`,onChange:e=>l(n=>n&&{...n,categories:{...n.categories,[t.key]:{...n.categories[t.key]||{},retention_days:e===``?``:Ft(e,0)}}}),style:{width:96}})},{title:e(`settingsStorage.colEnabled`,null,`启用`),width:90,render:(t,n)=>(0,Z.jsx)(_,{size:`small`,checked:!!c?.categories?.[n.key]?.enabled,disabled:!i||d===`policy`,onChange:e=>l(t=>t&&{...t,categories:{...t.categories,[n.key]:{...t.categories[n.key]||{},enabled:e}}}),"aria-label":e(`settingsStorage.colEnabled`,null,`启用`)})}];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V,{error:a.error,onRetry:a.reload}),(0,Z.jsx)(V,{error:o.error,onRetry:o.reload}),(0,Z.jsx)(V,{error:m}),(0,Z.jsxs)(H,{title:e(`settingsStorage.title`,null,`存储清理`),description:e(`settingsStorage.subtitle`,null,`统计并清理运行期间产生的磁盘垃圾。删除不可逆,建议先预览再执行。`),extra:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),loading:d===`status`,onClick:b,children:e(`settingsStorage.refresh`,null,`重新扫描`)}),(0,Z.jsx)(p,{loading:d===`preview`,disabled:!r,onClick:()=>S(!0),children:e(`settingsStorage.preview`,null,`预览可清理项`)}),(0,Z.jsx)(p,{type:`danger`,theme:`light`,loading:d===`clean`,disabled:!r,onClick:()=>oe({title:e(`settingsStorage.cleanNow`,null,`立即清理`),content:e(`settingsStorage.confirmClean`,{size:L(w.reclaimable_bytes),count:O(w.reclaimable_units)},`将永久删除约 ${L(w.reclaimable_bytes)}(${O(w.reclaimable_units)} 项)运行空间文件,无法恢复。确认继续?`),okText:e(`settingsStorage.cleanNow`,null,`立即清理`),onOk:()=>S(!1)}),children:e(`settingsStorage.cleanNow`,null,`立即清理`)})]}),children:[T.available&&(0,Z.jsxs)(`div`,{className:`settings-disk`,children:[(0,Z.jsx)(v,{percent:Math.max(0,Math.min(100,Number(T.used_percent)||0)),stroke:Number(T.used_percent)>=85?`var(--semi-color-danger)`:void 0,showInfo:!0}),(0,Z.jsxs)(Q,{children:[`${L(T.free_bytes)} ${e(`settingsStorage.free`,null,`可用`)} / ${L(T.total_bytes)}`,o.data?.scanned_at?` · ${e(`settingsStorage.scannedAt`,null,`扫描于`)} ${k(o.data.scanned_at)}`:``]})]}),(0,Z.jsx)(B,{items:D,columns:4})]}),(0,Z.jsxs)(H,{title:e(`settingsStorage.policyTitle`,null,`自动清理策略`),extra:(0,Z.jsx)(p,{theme:`solid`,type:`primary`,loading:d===`policy`,disabled:!i||!c,onClick:x,children:e(`settingsStorage.save`,null,`保存策略`)}),children:[(0,Z.jsxs)(`div`,{className:`settings-policy-grid`,children:[(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(Pt,{type:`tertiary`,size:`small`,children:e(`settingsStorage.autoClean`,null,`开启后台定时清理`)}),(0,Z.jsx)(_,{checked:!!c?.auto_clean,disabled:!i,onChange:e=>l(t=>t&&{...t,auto_clean:e})})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(Pt,{type:`tertiary`,size:`small`,children:e(`settingsStorage.intervalMinutes`,null,`清理间隔(分钟)`)}),(0,Z.jsx)(h,{value:String(c?.interval_minutes??``),disabled:!i,onChange:e=>l(t=>t&&{...t,interval_minutes:e===``?``:Ft(e,5)})})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(Pt,{type:`tertiary`,size:`small`,children:e(`settingsStorage.orphanGraceDays`,null,`孤儿目录宽限(天)`)}),(0,Z.jsx)(h,{value:String(c?.orphan_grace_days??``),disabled:!i,onChange:e=>l(t=>t&&{...t,orphan_grace_days:e===``?``:Ft(e,0)})})]}),(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(Pt,{type:`tertiary`,size:`small`,children:e(`settingsStorage.activeGraceHours`,null,`活跃会话保护(小时)`)}),(0,Z.jsx)(h,{value:String(c?.active_grace_hours??``),disabled:!i,onChange:e=>l(t=>t&&{...t,active_grace_hours:e===``?``:Ft(e,1)})})]})]}),(0,Z.jsx)(Q,{children:e(`settingsStorage.policyHint`,null,`保留天数为 0 表示不按保留期清理,但孤儿目录仍会回收;最近有活动的会话不会被清理。`)})]}),(0,Z.jsx)(H,{title:e(`settingsStorage.categoriesTitle`,null,`分类占用与保留策略`),children:(0,Z.jsx)(G,{columns:N,dataSource:M,rowKey:`key`,loading:o.loading||a.loading,pagination:!1,emptyText:e(`settingsStorage.noCategories`,null,`暂无可清理类别`)})}),y&&(0,Z.jsxs)(H,{title:y.dry_run?e(`settingsStorage.previewTitle`,null,`预览结果(未删除任何文件)`):e(`settingsStorage.cleanDone`,null,`清理完成`),children:[(0,Z.jsx)(B,{columns:3,items:[{label:e(`settingsStorage.colUnits`,null,`项目数`),value:O(y.dry_run?y.totals?.reclaimable_units:y.totals?.removed_units)},{label:y.dry_run?e(`settingsStorage.reclaimable`,null,`可回收`):e(`settingsDisplay.freed`,null,`已释放空间`),value:L(y.dry_run?y.totals?.reclaimable_bytes:y.totals?.freed_bytes)},{label:e(`settingsDisplay.errors`,null,`错误数`),value:O(y.totals?.errors)},{label:e(`settingsStorage.skippedActive`,null,`跳过活跃`),value:O(y.totals?.skipped_active)},{label:e(`settingsDisplay.cleanupDuration`,null,`清理耗时`),value:e(`settingsProbe.milliseconds`,{value:O(y.duration_ms??0)},`${O(y.duration_ms??0)} 毫秒`)}]}),(y.categories||[]).filter(e=>e.errors?.length).length>0&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:(y.categories||[]).filter(e=>e.errors?.length).map(t=>`${It(e,t)}:${t.errors.slice(0,3).join(`;`)}`).join(` / `)})]})]})}var{Text:zt}=l;function Bt(e){let t=String(e||``);return t?t.slice(0,12):`—`}function Vt(e,t){return t?(0,Z.jsx)(f,{size:`small`,color:`green`,children:e(`common.yes`,null,`是`)}):(0,Z.jsx)(f,{size:`small`,color:`grey`,children:e(`common.no`,null,`否`)})}function Ht(e,t){return t===`running`?e(`update.stateRunning`,null,`进行中`):t===`succeeded`?e(`update.stateSucceeded`,null,`已完成`):t===`failed`?e(`update.stateFailed`,null,`失败`):e(`update.stateUnknown`,null,`未知状态`)}function Ut(e){return e===`succeeded`?`green`:e===`failed`?`red`:e===`running`?`blue`:`grey`}function Wt(e,t){return t.installed?t.diverged?e(`update.blockedDiverged`,{ahead:t.ahead,behind:t.behind}):!t.updateAvailable&&!t.buildPending?``:t.rollbackPending?e(`updateUi.rollbackPending`):t.blockingChanges?.length?e(`update.blockedLocalEdits`,{n:t.blockingChanges.length}):``:e(`update.blockedNotGitTree`)}function Gt(){let e=te(),{hasPermission:t}=A(),n=t(`update:read`),r=t(`update:apply`),i=z(()=>j.get(`/system/update`),[n],{skip:!n}),[a,o]=(0,q.useState)(null),[l,d]=(0,q.useState)(``),[m,g]=(0,q.useState)(null),[_,v]=(0,q.useState)(null),[y,ee]=(0,q.useState)(null),[b,x]=(0,q.useState)(null),[S,C]=(0,q.useState)(null),[w,M]=(0,q.useState)(``),[N,P]=(0,q.useState)([]),[F,L]=(0,q.useState)(``),[R,ne]=(0,q.useState)(!1),[ie,U]=(0,q.useState)(!1),[W,G]=(0,q.useState)(null);(0,q.useEffect)(()=>{i.data&&o(i.data.job||null)},[i.data]);let K=a?.state===`running`,oe=a?.state===`succeeded`&&a.restartRequested,ce=K||oe?a.id:null,le=y||i.data?.bootID,ue=a?.result?.toCommit,J=i.reload,de=i.data?.needsRestart,fe=i.data?.source,pe=fe?.repo||``,Y=fe?.branch||``,me=b??pe,he=S??Y,ge=me.trim()!==pe||he.trim()!==Y,_e=!!(l||K||oe),ve=ie||_e||i.loading;(0,q.useEffect)(()=>{if(!ce)return;let t=!1,n,r=async()=>{try{let{job:n}=await j.get(`/system/update/job`,void 0,{timeout:5e3});if(t)return;if(n?.id===ce){if(o(n),n.state!==`running`&&!n.restartRequested){g(null),n.state===`succeeded`&&(n.result?.needsRestart?I(e(`update.needsRestartToast`)):ae(e(`update.jobDoneToast`))),J({silent:!0});return}}else{let e=await j.get(`/system/update`,void 0,{timeout:5e3});if(t)return;let n=le&&e.bootID&&e.bootID!==le,r=!ue||!e.buildRevision||e.buildRevision.startsWith(ue);if(n&&r&&!e.needsRestart){window.location.reload();return}}}catch{}t||(n=setTimeout(r,2e3))};return r(),()=>{t=!0,clearTimeout(n)}},[ce,le,ue,J,e]);let ye=async()=>{if(!r||ve||ge)return;d(`checking`),v(null),g(null);let t=!1;try{let{status:n}=await j.post(`/system/update/check`,{});if(!n)throw Error(e(`updateUi.statusMissing`));if(g(n),n.checkError)return;let r=Wt(e,n);if(r){v(Error(r));return}if(!n.updateAvailable&&!n.buildPending){de?I(e(`update.needsRestartToast`)):n.ahead>0?ae(e(`updateUi.noNewerVersion`)):ae(e(`updateUi.currentVersion`));return}t=!0,d(`starting`);let a=!!(i.data?.autoRestart??i.data?.canRestart),s=await j.post(`/system/update/apply`,{restart:a});if(!s?.job_id)throw Error(e(`updateUi.jobMissing`));ee(s.bootID||null),o({id:s.job_id,kind:`apply`,state:s.state||`running`,restartRequested:a})}catch(n){let r=n.status===409&&n.payload?.job;if(t&&r?.id){ee(n.payload.bootID||null),o(r);return}v(Error(e(t?`update.applyFailed`:`update.checkFailed`,{reason:se(n)}))),t&&J({silent:!0})}finally{d(``)}},be=async()=>{ne(!0),G(null);try{let t=me.trim(),n=await j.get(`/system/update/branches`,t?{repo:t}:void 0),r=Array.isArray(n?.branches)?n.branches:[];P(r),L(n?.defaultBranch||``),ae(e(`updateUi.branchesLoaded`,{n:r.length},`已获取 ${r.length} 个远端分支`))}catch(e){G(e)}finally{ne(!1)}},xe=async t=>{if(t.preventDefault(),fe&&r&&ge&&!ve){U(!0),G(null);try{let t=await j.post(`/system/update/source`,{repo:me.trim(),branch:he.trim()});if(!t?.source||typeof t.source.repo!=`string`)throw Error(e(`updateUi.sourceResponseMissing`,null,`服务端未返回更新源,刷新后可核对配置。`));i.setData(e=>({...e,source:t.source})),x(null),C(null),g(null),v(null),ae(e(`update.sourceSaveOk`,null,`更新源已保存`))}catch(e){G(e)}finally{U(!1)}}};if(!n)return(0,Z.jsx)(Ie,{permission:`update:read`,label:e(`settings.nav.update`,null,`读取安装树版本`)});if(i.loading&&!i.data)return(0,Z.jsx)(Le,{rows:6});let X=m||i.data?.status||{},Se=i.data?.binaryBuiltAt,Ce=[{label:e(`update.root`,null,`安装目录`),value:(0,Z.jsx)(Re,{children:X.root||`—`})},{label:e(`update.gitTree`,null,`Git 安装树`),value:Vt(e,X.installed)},{label:e(`update.branch`,null,`当前分支`),value:X.branch||`—`},{label:e(`updateUi.targetBranch`,null,`目标分支`),value:Y?(0,Z.jsxs)(u,{spacing:4,children:[(0,Z.jsx)(Re,{children:Y}),X.branch&&Y!==X.branch&&(0,Z.jsx)(f,{size:`small`,color:`amber`,children:e(`updateUi.branchSwitchPending`,null,`待切换`)})]}):(0,Z.jsx)(zt,{type:`tertiary`,children:e(`updateUi.followDefaultBranch`,null,`跟随仓库默认分支`)})},{label:e(`updateUi.repo`,null,`更新源仓库`),value:(0,Z.jsx)(Re,{children:fe?.repo||fe?.defaultRepo||X.repo||`—`})},{label:e(`update.commit`,null,`当前提交`),value:(0,Z.jsx)(Re,{children:Bt(X.commit)})},{label:e(`update.subject`,null,`提交说明`),value:re(X.subject||`—`,80)},{label:e(`update.committedAt`,null,`提交时间`),value:X.committedAt?k(X.committedAt):`—`},{label:e(`update.runningBuild`,null,`运行构建`),value:i.data?.buildRevision?Bt(i.data.buildRevision):`—`},{label:e(`update.toolchainFound`,null,`Go 工具链`),value:Vt(e,X.canBuild)},{label:e(`update.binaryPresent`,null,`已构建二进制`),value:Vt(e,X.hasBinary)},{label:e(`updateUi.buildPending`,null,`待编译`),value:Vt(e,X.buildPending)},{label:e(`update.restartPending`,null,`需重启激活`),value:de?(0,Z.jsxs)(u,{spacing:4,children:[(0,Z.jsx)(f,{size:`small`,color:`amber`,children:e(`common.yes`,null,`是`)}),Se&&(0,Z.jsx)(zt,{type:`tertiary`,size:`small`,children:k(Se)})]}):(0,Z.jsx)(f,{size:`small`,color:`green`,children:e(`common.no`,null,`否`)})},{label:e(`updateUi.localChanges`,null,`本机改动文件数`),value:O((X.localChanges||[]).length)},{label:e(`updateUi.blockingChanges`,null,`阻止更新的文件数`),value:O((X.blockingChanges||[]).length)}],we=Array.isArray(m?.incoming)?m.incoming:[];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V,{error:i.error,onRetry:i.reload}),(0,Z.jsxs)(H,{title:e(`update.installTitle`,null,`安装信息`),description:e(`updateUi.pageHint`),extra:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),onClick:()=>J(),loading:i.loading,disabled:ie||_e,children:e(`common.refresh`,null,`刷新`)}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,icon:(0,Z.jsx)(c,{"aria-hidden":`true`}),loading:!!l,disabled:!r||ve||ge,onClick:ye,children:e(l===`checking`?`update.checking`:l===`starting`?`updateUi.starting`:`updateUi.updateButton`)})]}),children:[!r&&(0,Z.jsx)(Q,{children:e(`updateUi.updatePermission`)}),ge&&(0,Z.jsx)(Q,{children:e(`updateUi.saveSourceFirst`)}),(0,Z.jsx)(B,{items:Ce,columns:3}),X.goToolchain&&(0,Z.jsxs)(Q,{children:[e(`updateUi.toolchainPath`,null,`Go 工具链路径`),` `,(0,Z.jsx)(Re,{children:X.goToolchain})]})]}),fe&&(0,Z.jsx)(H,{title:e(`update.sourceTitle`,null,`更新源`),children:(0,Z.jsxs)(`form`,{className:`settings-update-source-form`,onSubmit:xe,children:[(0,Z.jsxs)(`label`,{className:`settings-field`,children:[(0,Z.jsx)(zt,{size:`small`,type:`tertiary`,children:e(`update.sourceUrlLabel`,null,`更新源仓库地址`)}),(0,Z.jsx)(h,{value:me,onChange:e=>{x(e),P([]),G(null)},placeholder:fe.defaultRepo,readOnly:!r,disabled:ie})]}),(0,Z.jsxs)(`div`,{className:`settings-field`,style:{marginTop:12},children:[(0,Z.jsx)(zt,{size:`small`,type:`tertiary`,children:e(`updateUi.targetBranchLabel`,null,`目标分支(留空 = 跟随仓库默认分支)`)}),(0,Z.jsxs)(u,{style:{width:`100%`},wrap:!0,children:[(0,Z.jsx)(D,{value:he||void 0,onChange:e=>{C(e||``),M(``),G(null)},onSearch:e=>M(String(e||``)),onDropdownVisibleChange:e=>{e&&N.length===0&&!R&&be()},placeholder:e(`updateUi.targetBranchPlaceholder`,null,`留空跟随默认分支,或选择/输入分支名`),filter:!0,showClear:!0,loading:R,disabled:!r||ie,style:{width:340,maxWidth:`100%`},optionList:[...new Set([...N||[],...Y?[Y]:[],...he&&he.trim()?[he.trim()]:[],...w.trim()?[w.trim()]:[]])].map(t=>({value:t,label:t===F?`${t} (${e(`updateUi.defaultBranchTag`,null,`默认`)})`:t}))}),(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),loading:R,disabled:ie,onClick:be,children:e(`updateUi.fetchBranches`,null,`获取远端分支`)})]})]}),r?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Q,{children:e(`update.sourceRepoHint`,null,`留空即使用官方仓库;分支留空即跟随默认分支。`)}),(0,Z.jsx)(Q,{children:e(`updateUi.sourceSaveBranchHint`,null,`保存会修改配置文件中的 update.repo 与 update.branch,下次点击「更新」时自动拉取并切换至该分支。`)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(p,{htmlType:`submit`,theme:`solid`,loading:ie,disabled:!ge||ve,children:e(`update.sourceSaveBtn`,null,`保存更新源`)})}),K&&(0,Z.jsx)(Q,{children:e(`update.blockedJobRunning`,null,`已有更新在进行中,请等它结束。`)})]}):(0,Z.jsx)(Q,{children:e(`updateUi.sourcePermission`,null,`需要更新管理权限才能在这里保存地址。`)}),(0,Z.jsx)(V,{error:W})]})}),(0,Z.jsxs)(H,{title:e(`update.remoteTitle`,null,`远端版本`),children:[(0,Z.jsx)(V,{error:_,onRetry:r&&!ve&&!ge?ye:void 0}),!m&&!_&&(0,Z.jsx)(zt,{type:`tertiary`,children:e(`updateUi.versionUnchecked`,null,`尚未检查远端版本。`)}),m&&(0,Z.jsxs)(Z.Fragment,{children:[m.checkError?(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,description:e(`update.checkFailed`,{reason:m.checkError},`检查失败:${m.checkError}`)}):(0,Z.jsxs)(u,{wrap:!0,spacing:8,children:[m.installed&&(0,Z.jsx)(f,{size:`small`,color:m.updateAvailable||m.buildPending||de?`amber`:`green`,children:m.branchSwitch?e(`updateUi.branchSwitchTag`,{from:m.branch,to:m.targetBranch},`切换分支:${m.branch} → ${m.targetBranch}`):m.updateAvailable?e(`update.behindCount`,{n:m.behind}):m.buildPending?e(`updateUi.buildPending`):e(de?`update.restartNeeded`:m.ahead>0?`updateUi.noNewerVersion`:`updateUi.currentVersion`)}),m.ahead>0&&(0,Z.jsx)(f,{size:`small`,color:`blue`,children:e(`update.aheadCount`,{n:m.ahead},`领先 ${m.ahead} 个提交`)}),m.diverged&&(0,Z.jsx)(f,{size:`small`,color:`red`,children:e(`updateUi.diverged`,null,`本机与远端提交历史已分叉`)}),(0,Z.jsxs)(zt,{type:`tertiary`,children:[e(`update.remoteHead`,null,`远端 HEAD`),`:`,(0,Z.jsx)(Re,{children:Bt(m.remoteCommit)}),m.targetBranch?`(${m.targetBranch})`:``]})]}),(m.remoteSubject||we.length>0)&&(0,Z.jsxs)(`div`,{className:`settings-incoming`,children:[(0,Z.jsx)(zt,{type:`tertiary`,size:`small`,children:e(`update.incomingTitle`,null,`待合入提交`)}),(0,Z.jsx)(`ul`,{children:we.slice(0,10).map((e,t)=>(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(Re,{children:Bt(e.commit)}),` `,re(e.subject||``,90)]},`${e.commit||`commit`}-${t}`))}),m.incomingTotal>Math.min(10,we.length)&&(0,Z.jsx)(Q,{children:e(`update.incomingTruncated`,{total:m.incomingTotal,shown:Math.min(10,we.length)})})]})]})]}),(0,Z.jsxs)(H,{title:e(`update.jobTitle`,null,`更新任务进度`),extra:a?(0,Z.jsx)(f,{size:`small`,color:Ut(a.state),children:Ht(e,a.state)}):null,children:[oe&&(0,Z.jsx)(Q,{children:e(`update.restartRequestedToast`)}),de&&!_e&&(0,Z.jsx)(Q,{children:e(`update.needsRestartToast`)}),X.buildPending&&!_e&&(0,Z.jsx)(Q,{children:e(`updateUi.resumeBuild`)}),!a&&(0,Z.jsx)(zt,{type:`tertiary`,children:e(`update.noJob`,null,`暂无更新任务记录。`)}),a&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(B,{columns:3,items:[{label:e(`updateUi.taskId`,null,`任务编号`),value:(0,Z.jsx)(Re,{children:Bt(a.id)})},{label:e(`updateUi.kind`,null,`任务类型`),value:a.kind?e(`updateUi.kinds.`+a.kind,null,a.kind):`—`},{label:e(`updateUi.started`,null,`开始时间`),value:a.started?k(a.started):`—`},{label:e(`updateUi.finished`,null,`结束时间`),value:a.finished?k(a.finished):`—`},{label:e(`updateUi.restartRequested`,null,`已请求重启`),value:Vt(e,a.restartRequested)},{label:e(`updateUi.restartError`,null,`重启错误`),value:a.restartError||`—`}]}),Array.isArray(a.steps)&&a.steps.length>0&&(0,Z.jsx)(T,{className:`settings-update-steps`,children:a.steps.map((t,n)=>(0,Z.jsxs)(T.Item,{children:[(0,Z.jsx)(zt,{strong:!0,children:e(`updateUi.phases.`+t.phase,null,t.phase)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(zt,{type:`tertiary`,size:`small`,children:re(t.message||``,160)})}),(0,Z.jsx)(zt,{type:`tertiary`,size:`small`,children:t.at?k(t.at):``})]},`${t.phase}-${n}`))}),a.result&&(0,Z.jsx)(B,{columns:3,items:[{label:e(`updateUi.fromCommit`,null,`更新前提交`),value:(0,Z.jsx)(Re,{children:Bt(a.result.fromCommit)})},{label:e(`updateUi.toCommit`,null,`更新后提交`),value:(0,Z.jsx)(Re,{children:Bt(a.result.toCommit)})},{label:e(`update.resultCommits`,null,`并入提交数`),value:O(a.result.commits)},{label:e(`update.resultFiles`,null,`改动文件数`),value:O(a.result.filesTouched)},{label:e(`updateUi.keptContent`,null,`保留的本机文件数`),value:O((a.result.keptContent||[]).length)},{label:e(`updateUi.overwritten`,null,`覆盖的文件数`),value:O((a.result.overwritten||[]).length)}]}),a.failure&&(0,Z.jsx)(s,{type:`danger`,bordered:!0,closeIcon:null,description:(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{children:a.failure.message||a.failure.reason}),(a.failure.items||[]).length>0&&(0,Z.jsx)(`ul`,{children:a.failure.items.slice(0,6).map(e=>(0,Z.jsx)(`li`,{children:e},e))})]})})]})]})]})}var{Text:Kt}=l,qt={auth:[`login`,`logout`,`change_password`],config:[`apply`,`update`],c2:[`listener_create`,`listener_delete`,`listener_start`,`listener_stop`,`session_delete`,`task_create`,`task_cancel`,`task_delete`],webshell:[`connection_create`,`connection_delete`],knowledge:[`item_delete`,`index_build`,`index_rebuild_full`],conversation:[`create`,`delete`,`delete_turn`],vulnerability:[`create`,`update`,`delete`],external_mcp:[`upsert`,`delete`],task:[`create_queue`,`start_queue`,`delete_queue`,`pause_queue`,`rerun_queue`,`delete_batch_task`],tool:[`execution_delete`,`execution_delete_batch`],file:[`upload`,`delete`],hitl:[`decision`,`audit_strategy_update`],role:[`create`,`update`,`delete`],skill:[`create`,`update`,`delete`],agent:[`markdown_create`,`markdown_update`,`markdown_delete`]},Jt={category:``,action:``,result:``,q:``,since:null,until:null};function Yt(e){return e===`external_mcp`?`externalMcp`:e}function Xt(e){let t={};return e.category&&(t.category=e.category),e.action&&(t.action=e.action),e.result&&(t.result=e.result),e.q&&(t.q=e.q),e.since&&(t.since=e.since.toISOString()),e.until&&(t.until=e.until.toISOString()),t}function Zt({result:e,label:t}){let n=String(e||``).toLowerCase();return(0,Z.jsx)(f,{size:`small`,color:n===`failure`||n===`failed`||n===`error`?`red`:n===`success`?`green`:`grey`,children:t||e||`—`})}function Qt(){let e=te(),{hasPermission:t}=A(),n=t(`audit:read`),r=z(()=>j.get(`/audit/meta`),[n],{skip:!n}),[i,a]=(0,q.useState)(Jt),[o,c]=(0,q.useState)(Jt),[l,d]=(0,q.useState)(1),[m,g]=(0,q.useState)(20),[_,v]=(0,q.useState)(``),[y,ee]=(0,q.useState)(``),S=(0,q.useMemo)(()=>Xt(o),[o]),T=(0,q.useCallback)(()=>j.get(`/audit/summary`,S),[S]),M=z(T,[S,n],{skip:!n}),N=(0,q.useCallback)(()=>j.get(`/audit/logs`,{...S,page:l,page_size:m}),[S,l,m]),P=z(N,[S,l,m,n],{skip:!n}),I=(0,q.useCallback)(t=>t?e(`settingsAudit.cat.${Yt(t)}`,null,t):`—`,[e]),L=(0,q.useCallback)(t=>t?e(`settingsAudit.act.${t}`,null,t):`—`,[e]),B=(0,q.useCallback)(t=>t?e(`settingsAudit.result.${t}`,null,t):`—`,[e]),ie=(0,q.useMemo)(()=>[{value:``,label:e(`settingsAudit.filterAllCategories`,null,`全部类别`)},...Object.keys(qt).map(e=>({value:e,label:I(e)}))],[I,e]),U=(0,q.useMemo)(()=>{let t=i.category&&qt[i.category]||[];return[{value:``,label:e(`settingsAudit.filterAllActions`,null,`全部操作`)},...t.map(e=>({value:e,label:L(e)}))]},[L,i.category,e]),W=()=>{let e={...i};e.category||(e.action=``),c(e),d(1)},K=()=>{a(Jt),c(Jt),d(1)},oe=()=>{M.reload(),P.reload()},se=async t=>{if(n){ee(t);try{let n=`audit-logs-${new Date().toISOString().slice(0,10)}.${t===`csv`?`csv`:`json`}`;await F(`/audit/logs/export`,{query:{...S,format:t===`csv`?`csv`:void 0},filename:n}),ae(e(`settingsAudit.exportDone`,null,`导出完成`))}catch(t){ne(t,e(`common.downloadFailed`,null,`导出失败`))}finally{ee(``)}}};if(!n)return(0,Z.jsx)(Ie,{permission:`audit:read`,label:e(`settings.nav.audit`,null,`读取审计日志`)});if(r.loading&&!r.data)return(0,Z.jsx)(Le,{rows:6});let ce=Number(M.data?.total)||0,le=Number(M.data?.failures)||0,ue=Number(M.data?.recent_7d)||0,J=[{title:e(`settingsAudit.colTime`,null,`时间`),dataIndex:`createdAt`,width:180,render:e=>k(e)},{title:e(`settingsAudit.colMessage`,null,`说明`),dataIndex:`message`,render:(e,t)=>(0,Z.jsx)(C,{content:e||`—`,position:`topLeft`,children:(0,Z.jsxs)(u,{spacing:6,children:[t.level&&t.level!==`info`&&(0,Z.jsx)(f,{size:`small`,color:t.level===`error`?`red`:`amber`,children:t.level}),(0,Z.jsx)(Kt,{children:re(e||`—`,68)})]})})},{title:e(`settingsAudit.colCategory`,null,`类别`),dataIndex:`category`,width:120,render:e=>(0,Z.jsx)(f,{size:`small`,color:`blue`,children:I(e)})},{title:e(`settingsAudit.colAction`,null,`操作`),dataIndex:`action`,width:170,render:e=>(0,Z.jsx)(Kt,{type:`tertiary`,children:L(e)})},{title:e(`settingsAudit.colResult`,null,`结果`),dataIndex:`result`,width:100,render:e=>(0,Z.jsx)(Zt,{result:e,label:B(e)})},{title:e(`settingsAudit.colIp`,null,`IP`),dataIndex:`clientIp`,width:140,render:e=>(0,Z.jsx)(Re,{children:e||`—`})},{title:e(`settingsAudit.colResource`,null,`资源 ID`),dataIndex:`resourceId`,width:200,render:(e,t)=>(0,Z.jsx)(C,{content:[t.resourceType,e].filter(Boolean).join(` · `)||`—`,position:`topLeft`,children:(0,Z.jsx)(Kt,{type:`tertiary`,children:re(e||`—`,22)})})}];return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V,{error:r.error,onRetry:r.reload}),r.data?.enabled===!1&&(0,Z.jsx)(s,{type:`warning`,bordered:!0,closeIcon:null,className:`settings-audit-banner`,description:e(`settingsAudit.disabledHint`,null,`审计功能已关闭,新操作不会写入审计表。`)}),(0,Z.jsx)(R,{columns:4,metrics:[{id:`total`,label:e(`settingsAudit.statTotal`,null,`当前筛选`),value:O(ce)},{id:`ok`,label:e(`settingsAudit.statSuccess`,null,`成功`),value:O(Math.max(0,ce-le))},{id:`fail`,label:e(`settingsAudit.statFailures`,null,`失败`),value:O(le),tone:le?`danger`:void 0},{id:`recent`,label:e(`settingsAudit.statRecent7d`,null,`近 7 天`),value:O(ue)}]}),(0,Z.jsx)(V,{error:M.error,onRetry:M.reload}),(0,Z.jsxs)(H,{title:e(`settingsAudit.title`,null,`日志审计`),description:e(`settingsAudit.description`,null,`记录平台管理类操作(登录、配置、删除等),不记录对话正文与每次工具调用。`),extra:(0,Z.jsxs)(u,{children:[(0,Z.jsx)(f,{size:`small`,color:`grey`,children:e(`settingsAudit.retentionHint`,{days:r.data?.retention_days??0},`审计记录保留 ${r.data?.retention_days??0} 天`)}),(0,Z.jsx)(p,{loading:y===`json`,onClick:()=>se(`json`),children:e(`settingsAudit.exportJson`,null,`导出 JSON`)}),(0,Z.jsx)(p,{loading:y===`csv`,onClick:()=>se(`csv`),children:e(`settingsAudit.exportCsv`,null,`导出 CSV`)})]}),children:[(0,Z.jsxs)(`div`,{className:`settings-audit-filters`,children:[(0,Z.jsx)(D,{value:i.category,onChange:e=>a(t=>({...t,category:e,action:``})),optionList:ie,style:{width:150}}),(0,Z.jsx)(D,{value:i.action,onChange:e=>a(t=>({...t,action:e})),optionList:U,disabled:!i.category,placeholder:i.category?e(`settingsAudit.filterAllActions`,null,`全部操作`):e(`settingsAudit.filterCascadeHint`,null,`选择类别后可筛选具体操作`),style:{width:170}}),(0,Z.jsx)(D,{value:i.result,onChange:e=>a(t=>({...t,result:e})),style:{width:130},optionList:[{value:``,label:e(`settingsAudit.filterAll`,null,`全部`)},{value:`success`,label:e(`settingsAudit.result.success`,null,`成功`)},{value:`failure`,label:e(`settingsAudit.result.failure`,null,`失败`)}]}),(0,Z.jsx)(h,{prefix:(0,Z.jsx)(x,{}),value:i.q,onChange:e=>a(t=>({...t,q:e})),placeholder:e(`settingsAudit.filterQueryPlaceholder`,null,`消息 / 资源 ID / 操作名`),style:{width:240},showClear:!0}),(0,Z.jsx)(b,{type:`dateTime`,value:i.since||void 0,onChange:e=>a(t=>({...t,since:e||null})),placeholder:e(`settingsAudit.filterSince`,null,`开始时间`),style:{width:200}}),(0,Z.jsx)(b,{type:`dateTime`,value:i.until||void 0,onChange:e=>a(t=>({...t,until:e||null})),placeholder:e(`settingsAudit.filterUntil`,null,`结束时间`),style:{width:200}}),(0,Z.jsx)(p,{theme:`solid`,type:`primary`,onClick:W,children:e(`settingsAudit.filterBtn`,null,`筛选`)}),(0,Z.jsx)(p,{onClick:K,children:e(`settingsAudit.resetBtn`,null,`重置`)}),(0,Z.jsx)(p,{icon:(0,Z.jsx)(E,{}),theme:`borderless`,onClick:oe,loading:P.loading||M.loading,children:e(`common.refresh`,null,`刷新`)})]}),(0,Z.jsx)(V,{error:P.error,onRetry:P.reload}),(0,Z.jsx)(G,{columns:J,dataSource:Array.isArray(P.data?.logs)?P.data.logs:[],rowKey:`id`,loading:P.loading,emptyText:e(`settingsAudit.empty`,null,`暂无审计记录`),onRow:e=>({onClick:()=>v(e.id),style:{cursor:`pointer`}}),pagination:{currentPage:l,pageSize:m,total:Number(P.data?.total)||0,showSizeChanger:!0,pageSizeOpts:[10,20,50,100],onPageChange:e=>d(e),onPageSizeChange:e=>{g(e),d(1)}}})]}),(0,Z.jsx)(w,{title:e(`settingsAudit.detailTitle`,null,`审计详情`),visible:!!_,onCancel:()=>v(``),width:640,placement:`right`,children:_&&(0,Z.jsx)($t,{id:_,categoryLabel:I,actionLabel:L,resultLabel:B})})]})}function $t({id:e,categoryLabel:t,actionLabel:n,resultLabel:r}){let i=te(),[a,o]=(0,q.useState)({loading:!0,error:null,log:null});if((0,q.useEffect)(()=>{let t=!1;return o({loading:!0,error:null,log:null}),j.get(`/audit/logs/${encodeURIComponent(e)}`).then(e=>{t||o({loading:!1,error:null,log:e?.log||null})}).catch(e=>{t||o({loading:!1,error:e,log:null})}),()=>{t=!0}},[e]),a.loading)return(0,Z.jsx)(Le,{rows:6});if(a.error)return(0,Z.jsx)(V,{error:a.error});let s=a.log;return s?(0,Z.jsxs)(`div`,{className:`settings-audit-detail`,children:[(0,Z.jsx)(B,{columns:2,items:[{label:i(`settingsAudit.detailTime`,null,`时间`),value:k(s.createdAt)},{label:i(`settingsAudit.detailResult`,null,`结果`),value:(0,Z.jsx)(Zt,{result:s.result,label:r(s.result)})},{label:i(`settingsAudit.detailCategory`,null,`类别`),value:t(s.category)},{label:i(`settingsAudit.colAction`,null,`操作`),value:n(s.action)},{label:i(`settingsDisplay.actor`,null,`操作者`),value:s.actor||`—`},{label:i(`settingsAudit.colIp`,null,`IP`),value:(0,Z.jsx)(Re,{children:s.clientIp||`—`})},{label:i(`settingsDisplay.level`,null,`日志级别`),value:s.level||`—`},{label:i(`settingsDisplay.resourceType`,null,`资源类型`),value:s.resourceType||`—`},{label:i(`settingsAudit.resourceIdLabel`,null,`资源 ID`),value:(0,Z.jsx)(Re,{children:s.resourceId||`—`})},{label:i(`settingsDisplay.resourceAvailable`,null,`资源是否可访问`),value:s.resourceAvailable==null?`—`:s.resourceAvailable?i(`common.yes`,null,`是`):i(`common.no`,null,`否`)},{label:i(`settingsDisplay.session`,null,`会话标识`),value:(0,Z.jsx)(Re,{children:s.sessionHint||`—`})},{label:i(`settingsDisplay.userAgent`,null,`客户端标识`),value:re(s.userAgent||`—`,80)}]}),(0,Z.jsxs)(`div`,{className:`settings-audit-message-block`,children:[(0,Z.jsx)(Kt,{type:`tertiary`,size:`small`,children:i(`settingsAudit.detailMessage`,null,`说明`)}),(0,Z.jsx)(Kt,{children:s.message||`—`})]}),s.detail&&(0,Z.jsx)(K,{value:s.detail,collapsed:!0,title:i(`settingsDisplay.details`,null,`详情`)})]}):(0,Z.jsx)(Kt,{type:`tertiary`,children:i(`settingsAudit.empty`,null,`暂无审计记录`)})}var{Text:en}=l;function tn(){let e=te(),{preference:t,theme:n,setPreference:r}=M(),{lang:i,setLanguage:a}=P();return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(H,{title:e(`theme.titleSystem`,null,`外观主题`),description:e(`settings.appearanceThemeDesc`,null,`主题与语言只保存在当前浏览器(localStorage),不会写入服务端配置。`),children:[(0,Z.jsxs)(y,{value:t,onChange:e=>r(e.target.value),direction:`horizontal`,children:[(0,Z.jsx)(S,{value:`system`,children:e(`theme.system`,null,`跟随系统`)}),(0,Z.jsx)(S,{value:`light`,children:e(`theme.light`,null,`浅色`)}),(0,Z.jsx)(S,{value:`dark`,children:e(`theme.dark`,null,`暗色`)})]}),(0,Z.jsxs)(u,{spacing:8,className:`settings-appearance-status`,children:[(0,Z.jsxs)(f,{size:`small`,color:`blue`,children:[e(`settings.currentTheme`,null,`当前生效`),`:`,n===`dark`?e(`theme.dark`,null,`暗色`):e(`theme.light`,null,`浅色`)]}),(0,Z.jsx)(Q,{children:`preference = ${t}`})]})]}),(0,Z.jsx)(H,{title:e(`settings.languageTitle`,null,`界面语言`),description:e(`settings.languageDesc`,null,`切换到独立语言包;缺失词条回落到中文。`),children:(0,Z.jsxs)(u,{spacing:12,align:`center`,children:[(0,Z.jsx)(D,{value:i,onChange:e=>a(e),optionList:N.map(e=>({value:e.id,label:e.label})),style:{width:220}}),(0,Z.jsx)(en,{type:`tertiary`,children:i})]})})]})}var nn=[`basic`,`models`,`knowledge`,`token-usage`,`storage`,`update`,`audit`,`appearance`];function rn(){let e=te(),{mobile:t}=n(),[r,i]=a(),o=r.get(`section`),s=(0,q.useMemo)(()=>nn.includes(o)?o:`basic`,[o]);return(0,Z.jsxs)(`div`,{className:`settings-page`,children:[(0,Z.jsx)(W,{title:e(`settings.title`,null,`系统设置`),description:e(`settings.pageDesc`,null,`配置、模型探测、Token 用量、存储清理、审计日志与界面偏好;每个分区独立加载,单区失败不影响其他分区。`)}),(0,Z.jsxs)(g,{type:`line`,tabPosition:t?`top`:`left`,collapsible:t,lazyRender:!0,activeKey:s,onChange:e=>{let t=new URLSearchParams(r);t.set(`section`,e),t.delete(`focus`),i(t,{replace:!0})},className:`settings-tabs`,children:[(0,Z.jsx)(g.TabPane,{itemKey:`basic`,tab:e(`settings.nav.basic`,null,`基础配置`),children:(0,Z.jsx)(Ue,{active:s===`basic`})}),(0,Z.jsx)(g.TabPane,{itemKey:`models`,tab:e(`settings.nav.models`,null,`模型与工具`),children:(0,Z.jsx)(xt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`knowledge`,tab:e(`settings.nav.knowledge`,null,`知识库`),children:(0,Z.jsx)(Dt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`token-usage`,tab:e(`settings.nav.tokenUsage`,null,`Token 用量`),children:(0,Z.jsx)(Nt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`storage`,tab:e(`settings.nav.storage`,null,`存储清理`),children:(0,Z.jsx)(Rt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`update`,tab:e(`settings.nav.update`,null,`更新状态`),children:(0,Z.jsx)(Gt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`audit`,tab:e(`settings.nav.audit`,null,`审计日志`),children:(0,Z.jsx)(Qt,{})}),(0,Z.jsx)(g.TabPane,{itemKey:`appearance`,tab:e(`settings.nav.appearance`,null,`外观`),children:(0,Z.jsx)(tn,{})})]})]})}export{rn as default};
\ No newline at end of file
diff --git a/web/static/app/assets/skills-management-mXFB_l5H.js b/web/static/app/assets/skills-management-Dy4a2scy.js
similarity index 85%
rename from web/static/app/assets/skills-management-mXFB_l5H.js
rename to web/static/app/assets/skills-management-Dy4a2scy.js
index 32e1322e..88ea0a27 100644
--- a/web/static/app/assets/skills-management-mXFB_l5H.js
+++ b/web/static/app/assets/skills-management-Dy4a2scy.js
@@ -1 +1 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{C as r,G as i,I as a,Lt as o,R as s,S as c,U as l,ft as u,i as d,lt as f,ut as p}from"./semi-65W_4I1v.js";import{E as m,F as h,I as g,P as _,T as v,a as y,b,c as x,d as S,f as C,l as w,m as T,n as E,p as D,s as O,x as k,y as A}from"./index-BdnarFZR.js";var j=e(t(),1),M=e(n(),1),{Text:N}=i;function P(){let e=_(),{hasPermission:t}=h(),n=t(`skills:write`),r=t(`skills:delete`),[i,c]=(0,j.useState)(``),S=E(i,300),[C,P]=(0,j.useState)(1),[I,L]=(0,j.useState)(20),[R,z]=(0,j.useState)(null),[B,V]=(0,j.useState)(null),[H,U]=(0,j.useState)(!1),W=y(()=>g.get(`/skills`,{search:S||void 0,limit:I,offset:(C-1)*I}),[S,C,I]),G=Array.isArray(W.data?.skills)?W.data.skills:[],K=Number(W.data?.total||0),q=async()=>{let e=await B.form.validate();U(!0);try{await g.post(`/skills`,{name:e.name.trim(),description:e.description.trim(),content:e.content}),k(`技能已创建`),V(null),W.reload()}catch(e){b(e,`创建技能失败`)}finally{U(!1)}},J=e=>A({title:`删除技能「${e.name}」?`,content:`该技能目录及其全部文件会被移除。`,onOk:async()=>{await g.del(`/skills/${encodeURIComponent(e.id||e.name)}`),k(`已删除`),W.reload()}});return(0,M.jsxs)(`div`,{children:[(0,M.jsx)(D,{title:e(`skills.managementTitle`,null,`技能管理`),description:`技能以目录形式存放在技能根目录,SKILL.md 描述触发条件与用法。`,extra:(0,M.jsxs)(a,{children:[(0,M.jsx)(s,{icon:(0,M.jsx)(p,{}),onClick:()=>W.reload(),loading:W.loading,children:`刷新`}),n&&(0,M.jsx)(s,{theme:`solid`,type:`primary`,icon:(0,M.jsx)(u,{}),onClick:()=>V({form:{}}),children:`新建技能`})]})}),(0,M.jsxs)(T,{title:`技能(${K})`,children:[(0,M.jsx)(w,{error:W.error,onRetry:()=>W.reload()}),(0,M.jsx)(O,{columns:[{title:`技能`,dataIndex:`name`,render:(e,t)=>(0,M.jsxs)(a,{vertical:!0,spacing:0,align:`start`,children:[(0,M.jsx)(N,{strong:!0,children:e||t.id}),(0,M.jsx)(N,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:420},children:t.description})]})},{title:`版本`,dataIndex:`version`,width:100,render:e=>e||`—`},{title:`文件`,dataIndex:`file_count`,width:80,render:e=>String(e??`—`)},{title:`大小`,dataIndex:`file_size`,width:100,render:e=>v(e)},{title:`更新时间`,dataIndex:`mod_time`,width:170,render:e=>e?m(e):`—`},{title:`操作`,width:140,render:(e,t)=>(0,M.jsxs)(a,{children:[(0,M.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>z(t),children:`详情`}),r&&(0,M.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,M.jsx)(o,{}),onClick:()=>J(t)})]})}],dataSource:G,rowKey:e=>e.id||e.name,loading:W.loading,pagination:{currentPage:C,pageSize:I,total:K,onPageChange:P,onPageSizeChange:e=>{L(e),P(1)}},toolbar:(0,M.jsx)(l,{prefix:(0,M.jsx)(f,{}),value:i,onChange:e=>{c(e),P(1)},placeholder:`搜索技能名称或描述`,style:{width:280}})})]}),(0,M.jsx)(x,{title:`新建技能`,visible:!!B,onCancel:()=>V(null),onOk:q,confirmLoading:H,width:720,children:(0,M.jsxs)(d,{getFormApi:e=>V(t=>t&&{...t,form:e}),children:[(0,M.jsx)(d.Input,{field:`name`,label:`目录名`,placeholder:`小写字母、数字、连字符`,rules:[{required:!0,message:`请输入目录名`},{pattern:/^[a-z0-9-]+$/,message:`只允许小写字母、数字与连字符`}]}),(0,M.jsx)(d.Input,{field:`description`,label:`描述`,rules:[{required:!0,message:`请输入描述`}]}),(0,M.jsx)(d.TextArea,{field:`content`,label:`SKILL.md 正文`,rules:[{required:!0,message:`请输入正文`}],autosize:{minRows:10,maxRows:24}})]})},`new-skill`),(0,M.jsx)(F,{skill:R,onClose:()=>z(null),canWrite:n})]})}function F({skill:e,onClose:t,canWrite:n}){let[i,o]=(0,j.useState)([]),[l,u]=(0,j.useState)(``),[d,f]=(0,j.useState)(``),[p,m]=(0,j.useState)(!1),[h,_]=(0,j.useState)(!1);(0,j.useEffect)(()=>{e&&(o([]),u(``),f(``),g.get(`/skills/${encodeURIComponent(e.id||e.name)}/files`).then(e=>o(Array.isArray(e?.files)?e.files:[])).catch(()=>o([])))},[e]);let v=async t=>{m(!0);try{let n=await g.get(`/skills/${encodeURIComponent(e.id||e.name)}/file`,{path:t});u(t),f(n?.content||``)}catch(e){b(e,`读取文件失败`)}finally{m(!1)}},y=async()=>{_(!0);try{await g.put(`/skills/${encodeURIComponent(e.id||e.name)}/file`,{path:l,content:d}),k(`文件已保存`)}catch(e){b(e,`保存文件失败`)}finally{_(!1)}},w=i.map(e=>typeof e==`string`?e:e.path||e.name);return(0,M.jsx)(x,{title:e?.name||`技能详情`,visible:!!e,onCancel:t,width:860,children:e&&(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,M.jsx)(S,{items:[{label:`目录名`,value:e.id||e.dir_name},{label:`版本`,value:e.version||`—`},{label:`路径`,value:e.path},{label:`文件数`,value:e.file_count},{label:`触发词`,value:Array.isArray(e.triggers)?e.triggers.join(`、`):`—`},{label:`标签`,value:Array.isArray(e.tags)?e.tags.join(`、`):`—`}]}),(0,M.jsx)(N,{type:`tertiary`,children:e.description}),(0,M.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`220px minmax(0, 1fr)`,gap:12},children:[(0,M.jsx)(`div`,{style:{border:`1px solid var(--semi-color-border)`,borderRadius:8,maxHeight:420,overflow:`auto`},children:(0,M.jsx)(r,{dataSource:w,renderItem:e=>(0,M.jsx)(r.Item,{main:(0,M.jsx)(N,{size:`small`,ellipsis:{showTooltip:!0},children:e}),onClick:()=>v(e),style:{cursor:`pointer`,background:e===l?`var(--semi-color-primary-light-default)`:void 0}}),emptyContent:`暂无文件`})}),(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,M.jsxs)(a,{children:[(0,M.jsx)(N,{strong:!0,children:l||`选择左侧文件查看内容`}),n&&l&&(0,M.jsx)(s,{size:`small`,loading:h,onClick:y,children:`保存`})]}),l?(0,M.jsx)(c,{value:d,onChange:f,autosize:{minRows:20,maxRows:30},disabled:!n}):(0,M.jsx)(C,{content:e.description||`—`}),p&&(0,M.jsx)(N,{type:`tertiary`,children:`读取中…`})]})]})]})})}export{P as default};
\ No newline at end of file
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{C as r,G as i,I as a,Lt as o,R as s,S as c,U as l,ft as u,i as d,lt as f,ut as p}from"./semi-65W_4I1v.js";import{E as m,F as h,I as g,L as _,T as v,a as y,b,c as x,d as S,f as C,l as w,m as T,n as E,p as D,s as O,x as k,y as A}from"./index-_8d9XBPJ.js";var j=e(t(),1),M=e(n(),1),{Text:N}=i;function P(){let e=h(),{hasPermission:t}=g(),n=t(`skills:write`),r=t(`skills:delete`),[i,c]=(0,j.useState)(``),S=E(i,300),[C,P]=(0,j.useState)(1),[I,L]=(0,j.useState)(20),[R,z]=(0,j.useState)(null),[B,V]=(0,j.useState)(null),[H,U]=(0,j.useState)(!1),W=y(()=>_.get(`/skills`,{search:S||void 0,limit:I,offset:(C-1)*I}),[S,C,I]),G=Array.isArray(W.data?.skills)?W.data.skills:[],K=Number(W.data?.total||0),q=async()=>{let e=await B.form.validate();U(!0);try{await _.post(`/skills`,{name:e.name.trim(),description:e.description.trim(),content:e.content}),k(`技能已创建`),V(null),W.reload()}catch(e){b(e,`创建技能失败`)}finally{U(!1)}},J=e=>A({title:`删除技能「${e.name}」?`,content:`该技能目录及其全部文件会被移除。`,onOk:async()=>{await _.del(`/skills/${encodeURIComponent(e.id||e.name)}`),k(`已删除`),W.reload()}});return(0,M.jsxs)(`div`,{children:[(0,M.jsx)(D,{title:e(`skills.managementTitle`,null,`技能管理`),description:`技能以目录形式存放在技能根目录,SKILL.md 描述触发条件与用法。`,extra:(0,M.jsxs)(a,{children:[(0,M.jsx)(s,{icon:(0,M.jsx)(p,{}),onClick:()=>W.reload(),loading:W.loading,children:`刷新`}),n&&(0,M.jsx)(s,{theme:`solid`,type:`primary`,icon:(0,M.jsx)(u,{}),onClick:()=>V({form:{}}),children:`新建技能`})]})}),(0,M.jsxs)(T,{title:`技能(${K})`,children:[(0,M.jsx)(w,{error:W.error,onRetry:()=>W.reload()}),(0,M.jsx)(O,{columns:[{title:`技能`,dataIndex:`name`,render:(e,t)=>(0,M.jsxs)(a,{vertical:!0,spacing:0,align:`start`,children:[(0,M.jsx)(N,{strong:!0,children:e||t.id}),(0,M.jsx)(N,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:420},children:t.description})]})},{title:`版本`,dataIndex:`version`,width:100,render:e=>e||`—`},{title:`文件`,dataIndex:`file_count`,width:80,render:e=>String(e??`—`)},{title:`大小`,dataIndex:`file_size`,width:100,render:e=>v(e)},{title:`更新时间`,dataIndex:`mod_time`,width:170,render:e=>e?m(e):`—`},{title:`操作`,width:140,render:(e,t)=>(0,M.jsxs)(a,{children:[(0,M.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>z(t),children:`详情`}),r&&(0,M.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,M.jsx)(o,{}),onClick:()=>J(t)})]})}],dataSource:G,rowKey:e=>e.id||e.name,loading:W.loading,pagination:{currentPage:C,pageSize:I,total:K,onPageChange:P,onPageSizeChange:e=>{L(e),P(1)}},toolbar:(0,M.jsx)(l,{prefix:(0,M.jsx)(f,{}),value:i,onChange:e=>{c(e),P(1)},placeholder:`搜索技能名称或描述`,style:{width:280}})})]}),(0,M.jsx)(x,{title:`新建技能`,visible:!!B,onCancel:()=>V(null),onOk:q,confirmLoading:H,width:720,children:(0,M.jsxs)(d,{getFormApi:e=>V(t=>t&&{...t,form:e}),children:[(0,M.jsx)(d.Input,{field:`name`,label:`目录名`,placeholder:`小写字母、数字、连字符`,rules:[{required:!0,message:`请输入目录名`},{pattern:/^[a-z0-9-]+$/,message:`只允许小写字母、数字与连字符`}]}),(0,M.jsx)(d.Input,{field:`description`,label:`描述`,rules:[{required:!0,message:`请输入描述`}]}),(0,M.jsx)(d.TextArea,{field:`content`,label:`SKILL.md 正文`,rules:[{required:!0,message:`请输入正文`}],autosize:{minRows:10,maxRows:24}})]})},`new-skill`),(0,M.jsx)(F,{skill:R,onClose:()=>z(null),canWrite:n})]})}function F({skill:e,onClose:t,canWrite:n}){let[i,o]=(0,j.useState)([]),[l,u]=(0,j.useState)(``),[d,f]=(0,j.useState)(``),[p,m]=(0,j.useState)(!1),[h,g]=(0,j.useState)(!1);(0,j.useEffect)(()=>{e&&(o([]),u(``),f(``),_.get(`/skills/${encodeURIComponent(e.id||e.name)}/files`).then(e=>o(Array.isArray(e?.files)?e.files:[])).catch(()=>o([])))},[e]);let v=async t=>{m(!0);try{let n=await _.get(`/skills/${encodeURIComponent(e.id||e.name)}/file`,{path:t});u(t),f(n?.content||``)}catch(e){b(e,`读取文件失败`)}finally{m(!1)}},y=async()=>{g(!0);try{await _.put(`/skills/${encodeURIComponent(e.id||e.name)}/file`,{path:l,content:d}),k(`文件已保存`)}catch(e){b(e,`保存文件失败`)}finally{g(!1)}},w=i.map(e=>typeof e==`string`?e:e.path||e.name);return(0,M.jsx)(x,{title:e?.name||`技能详情`,visible:!!e,onCancel:t,width:860,children:e&&(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,M.jsx)(S,{items:[{label:`目录名`,value:e.id||e.dir_name},{label:`版本`,value:e.version||`—`},{label:`路径`,value:e.path},{label:`文件数`,value:e.file_count},{label:`触发词`,value:Array.isArray(e.triggers)?e.triggers.join(`、`):`—`},{label:`标签`,value:Array.isArray(e.tags)?e.tags.join(`、`):`—`}]}),(0,M.jsx)(N,{type:`tertiary`,children:e.description}),(0,M.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`220px minmax(0, 1fr)`,gap:12},children:[(0,M.jsx)(`div`,{style:{border:`1px solid var(--semi-color-border)`,borderRadius:8,maxHeight:420,overflow:`auto`},children:(0,M.jsx)(r,{dataSource:w,renderItem:e=>(0,M.jsx)(r.Item,{main:(0,M.jsx)(N,{size:`small`,ellipsis:{showTooltip:!0},children:e}),onClick:()=>v(e),style:{cursor:`pointer`,background:e===l?`var(--semi-color-primary-light-default)`:void 0}}),emptyContent:`暂无文件`})}),(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,M.jsxs)(a,{children:[(0,M.jsx)(N,{strong:!0,children:l||`选择左侧文件查看内容`}),n&&l&&(0,M.jsx)(s,{size:`small`,loading:h,onClick:y,children:`保存`})]}),l?(0,M.jsx)(c,{value:d,onChange:f,autosize:{minRows:20,maxRows:30},disabled:!n}):(0,M.jsx)(C,{content:e.description||`—`}),p&&(0,M.jsx)(N,{type:`tertiary`,children:`读取中…`})]})]})]})})}export{P as default};
\ No newline at end of file
diff --git a/web/static/app/assets/skills-monitor-B_jKEqI_.js b/web/static/app/assets/skills-monitor-ZMwFvsjS.js
similarity index 83%
rename from web/static/app/assets/skills-monitor-B_jKEqI_.js
rename to web/static/app/assets/skills-monitor-ZMwFvsjS.js
index 0a2f9529..d12e0b7e 100644
--- a/web/static/app/assets/skills-monitor-B_jKEqI_.js
+++ b/web/static/app/assets/skills-monitor-ZMwFvsjS.js
@@ -1 +1 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{G as t,I as n,Lt as r,R as i,ut as a}from"./semi-65W_4I1v.js";import{D as o,F as s,I as c,O as l,P as u,_ as d,a as f,l as p,m,p as h,s as g,x as _,y as v}from"./index-BdnarFZR.js";import{t as y}from"./react-QV7DAAIx.js";var b=e(y(),1),{Text:x}=t;function S(){let e=u(),{hasPermission:t}=s(),y=t(`skills:delete`),S=f(()=>c.get(`/skills/stats`),[]),C=Array.isArray(S.data?.stats)?S.data.stats:[],w=Number(S.data?.total_calls||0),T=Number(S.data?.total_success||0),E=w>0?T/w:null,D=()=>v({title:`清空所有技能调用统计?`,content:`只影响统计计数,不删除技能文件。`,onOk:async()=>{await c.del(`/skills/stats`),_(`统计已清空`),S.reload()}}),O=e=>v({title:`清空「${e}」的统计?`,onOk:async()=>{await c.del(`/skills/${encodeURIComponent(e)}/stats`),_(`已清空`),S.reload()}});return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(h,{title:e(`skills.monitorTitle`,null,`技能状态`),description:S.data?.skills_dir?`技能目录:${S.data.skills_dir}`:`统计技能被调用的次数、成功率与最近使用时间。`,extra:(0,b.jsxs)(n,{children:[(0,b.jsx)(i,{icon:(0,b.jsx)(a,{}),onClick:()=>S.reload(),loading:S.loading,children:`刷新`}),y&&(0,b.jsx)(i,{type:`danger`,theme:`light`,onClick:D,children:`清空全部统计`})]})}),(0,b.jsx)(d,{columns:4,metrics:[{id:`skills`,label:`技能总数`,value:o(S.data?.total_skills||0),loading:S.loading},{id:`calls`,label:`调用总数`,value:o(w),loading:S.loading},{id:`success`,label:`成功次数`,value:o(T),loading:S.loading},{id:`rate`,label:`成功率`,value:E===null?`—`:l(E),tone:E!==null&&E<.8?`warning`:`success`,loading:S.loading}]}),(0,b.jsxs)(m,{title:`按技能统计`,children:[(0,b.jsx)(p,{error:S.error,onRetry:()=>S.reload()}),(0,b.jsx)(g,{columns:[{title:`技能`,dataIndex:`skill_name`,render:e=>(0,b.jsx)(x,{strong:!0,children:e})},{title:`调用次数`,dataIndex:`total_calls`,width:120,render:e=>o(e||0)},{title:`成功`,dataIndex:`success_calls`,width:100,render:e=>o(e||0)},{title:`失败`,dataIndex:`failed_calls`,width:100,render:e=>Number(e)>0?(0,b.jsx)(x,{type:`danger`,children:o(e)}):`0`},{title:`最后调用`,dataIndex:`last_call_time`,width:180,render:e=>e||`—`},{title:`操作`,width:110,render:(e,t)=>y&&Number(t.total_calls)>0?(0,b.jsx)(i,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,b.jsx)(r,{}),onClick:()=>O(t.skill_name),children:`清空`}):null}],dataSource:C,rowKey:`skill_name`,loading:S.loading,pagination:{pageSize:20}})]})]})}export{S as default};
\ No newline at end of file
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{G as t,I as n,Lt as r,R as i,ut as a}from"./semi-65W_4I1v.js";import{D as o,F as s,I as c,L as l,O as u,_ as d,a as f,l as p,m,p as h,s as g,x as _,y as v}from"./index-_8d9XBPJ.js";import{t as y}from"./react-QV7DAAIx.js";var b=e(y(),1),{Text:x}=t;function S(){let e=s(),{hasPermission:t}=c(),y=t(`skills:delete`),S=f(()=>l.get(`/skills/stats`),[]),C=Array.isArray(S.data?.stats)?S.data.stats:[],w=Number(S.data?.total_calls||0),T=Number(S.data?.total_success||0),E=w>0?T/w:null,D=()=>v({title:`清空所有技能调用统计?`,content:`只影响统计计数,不删除技能文件。`,onOk:async()=>{await l.del(`/skills/stats`),_(`统计已清空`),S.reload()}}),O=e=>v({title:`清空「${e}」的统计?`,onOk:async()=>{await l.del(`/skills/${encodeURIComponent(e)}/stats`),_(`已清空`),S.reload()}});return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(h,{title:e(`skills.monitorTitle`,null,`技能状态`),description:S.data?.skills_dir?`技能目录:${S.data.skills_dir}`:`统计技能被调用的次数、成功率与最近使用时间。`,extra:(0,b.jsxs)(n,{children:[(0,b.jsx)(i,{icon:(0,b.jsx)(a,{}),onClick:()=>S.reload(),loading:S.loading,children:`刷新`}),y&&(0,b.jsx)(i,{type:`danger`,theme:`light`,onClick:D,children:`清空全部统计`})]})}),(0,b.jsx)(d,{columns:4,metrics:[{id:`skills`,label:`技能总数`,value:o(S.data?.total_skills||0),loading:S.loading},{id:`calls`,label:`调用总数`,value:o(w),loading:S.loading},{id:`success`,label:`成功次数`,value:o(T),loading:S.loading},{id:`rate`,label:`成功率`,value:E===null?`—`:u(E),tone:E!==null&&E<.8?`warning`:`success`,loading:S.loading}]}),(0,b.jsxs)(m,{title:`按技能统计`,children:[(0,b.jsx)(p,{error:S.error,onRetry:()=>S.reload()}),(0,b.jsx)(g,{columns:[{title:`技能`,dataIndex:`skill_name`,render:e=>(0,b.jsx)(x,{strong:!0,children:e})},{title:`调用次数`,dataIndex:`total_calls`,width:120,render:e=>o(e||0)},{title:`成功`,dataIndex:`success_calls`,width:100,render:e=>o(e||0)},{title:`失败`,dataIndex:`failed_calls`,width:100,render:e=>Number(e)>0?(0,b.jsx)(x,{type:`danger`,children:o(e)}):`0`},{title:`最后调用`,dataIndex:`last_call_time`,width:180,render:e=>e||`—`},{title:`操作`,width:110,render:(e,t)=>y&&Number(t.total_calls)>0?(0,b.jsx)(i,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,b.jsx)(r,{}),onClick:()=>O(t.skill_name),children:`清空`}):null}],dataSource:C,rowKey:`skill_name`,loading:S.loading,pagination:{pageSize:20}})]})]})}export{S as default};
\ No newline at end of file
diff --git a/web/static/app/assets/tasks-B7Ht6Kqu.js b/web/static/app/assets/tasks-B7Ht6Kqu.js
deleted file mode 100644
index 225fb47d..00000000
--- a/web/static/app/assets/tasks-B7Ht6Kqu.js
+++ /dev/null
@@ -1,2 +0,0 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{G as a,I as o,N as s,P as c,R as l,S as u,U as d,c as ee,ft as f,g as p,lt as m,p as h,ut as g,y as _}from"./semi-65W_4I1v.js";import{E as v,F as y,I as b,P as x,_ as S,a as C,b as w,c as T,d as E,f as D,l as te,m as O,n as k,p as A,r as ne,s as re,x as j,y as M}from"./index-BdnarFZR.js";import{t as N}from"./project-options-CMQbwv_U.js";var P=e(t(),1),F={pending:{label:`待执行`,color:`amber`},running:{label:`执行中`,color:`blue`},paused:{label:`已暂停`,color:`grey`},completed:{label:`已完成`,color:`green`},cancelled:{label:`已取消`,color:`grey`}},I={pending:{label:`待执行`,color:`amber`},running:{label:`执行中`,color:`blue`},completed:{label:`已完成`,color:`green`},failed:{label:`失败`,color:`red`},cancelled:{label:`已取消`,color:`grey`},blocked:{label:`受阻`,color:`orange`}},L=[{value:`single`,label:`单代理(Pi SDK)`},{value:`deep`,label:`Deep(DeepAgent)`},{value:`plan_execute`,label:`Plan-Execute`},{value:`supervisor`,label:`Supervisor(专家路由)`}],R=[{value:``,label:`沿用全局设置`},{value:`off`,label:`关闭审批`},{value:`human`,label:`人工审批`},{value:`audit_agent`,label:`Agent 审批`},{value:`review_edit`,label:`Agent 审查编辑`}],ie=[{value:`manual`,label:`手工执行`},{value:`cron`,label:`Cron 调度`}],ae=[{value:`all`,label:`全部状态`},{value:`pending`,label:`待执行`},{value:`running`,label:`执行中`},{value:`paused`,label:`已暂停`},{value:`completed`,label:`已完成`},{value:`cancelled`,label:`已取消`}];function oe(e){let t=Array.isArray(e?.tasks)?e.tasks:[],n=t.length,r=t.filter(e=>e.status===`completed`).length,i=t.filter(e=>e.status===`failed`).length,a=t.filter(e=>e.status===`cancelled`).length,o=t.filter(e=>e.status===`blocked`).length,s=t.filter(e=>e.status===`running`).length,c=t.filter(e=>e.status===`pending`).length,l=r+i+a+o;return{total:n,completed:r,failed:i,cancelled:a,blocked:o,running:s,pending:c,done:l,percent:n?Math.round(l/n*100):0}}function se(e){return(L.find(t=>t.value===String(e||`single`))||L[0]).label}function ce(e){let t=F[String(e?.status||``)]||{label:e?.status||`—`,color:`grey`},n=e?.scheduleMode===`cron`&&e?.scheduleEnabled!==!1,r=e?.nextRunAt?new Date(e.nextRunAt):null,i=r&&Number.isFinite(r.getTime())?r.toLocaleString(`zh-CN`,{hour12:!1}):``,a=oe(e),o=a.blocked>0?e?.lastRunError||`${a.blocked} 项受阻`:``;if(a.blocked>0&&a.completed===0&&a.failed===0)return{...t,label:`受阻(${a.blocked} 项)`,color:`orange`,sublabel:o};if(n&&e?.status===`completed`){let e=a.failed>0||a.blocked>0;return{...t,label:e?`本轮已结束 · 定时循环中`:`本轮已完成 · 定时循环中`,color:a.failed>0?`red`:a.blocked>0?`orange`:t.color,sublabel:o||(i?`下次执行:${i}`:``),note:`定时队列:子任务已跑完,到点将自动下一轮`}}if(n&&e?.status===`pending`&&i)return{...t,sublabel:`Cron 已排程 · 下次 ${i}`};if(e?.status===`completed`&&a.failed>0){let e=a.blocked>0?`,${a.blocked} 项受阻`:``;return{...t,label:`已结束(${a.failed} 项失败${e})`,color:`red`,sublabel:o}}return e?.status===`completed`&&a.blocked>0?{...t,label:`已结束(${a.blocked} 项受阻)`,color:`orange`,sublabel:o}:{...t,sublabel:``}}function z(e,t){if(!e)return`—`;let n=new Date(e).getTime(),r=t?new Date(t).getTime():Date.now();if(!Number.isFinite(n)||!Number.isFinite(r)||r{if(!e)return;o(U),S(!1);let t=!1;return i(`roles:read`)&&b.get(`/roles`).then(e=>{t||l(Array.isArray(e?.roles)?e.roles:[])}).catch(()=>{t||l([])}),i(`project:read`)&&b.get(`/projects`,{limit:500}).then(e=>{t||f(Array.isArray(e?.projects)?e.projects:[])}).catch(()=>{t||f([])}),()=>{t=!0}},[e,i]),(0,P.useEffect)(()=>{if(!e||!a.projectId||!i(`asset:read`)){m([]),g(null);return}let t=!1;return b.get(`/assets/collections`,{project_id:a.projectId}).then(e=>{t||m(Array.isArray(e?.collections)?e.collections:[])}).catch(()=>{t||m([])}),b.get(`/assets`,{project_id:a.projectId,page:1,page_size:1}).then(e=>{t||g(Number.isFinite(Number(e?.total))?Number(e.total):0)}).catch(()=>{t||g(null)}),()=>{t=!0}},[e,a.projectId,i]);let C=e=>o(t=>({...t,...e}));return(0,V.jsxs)(T,{visible:e,title:r(`batchImportModal.title`,null,`新建任务`),onCancel:t,onOk:async()=>{let e=a.tasksText.split(`
-`).map(e=>e.trim()).filter(Boolean);if(!e.length){w(r(`tasks.noValidTask`,null,`没有有效的任务`));return}if(a.scheduleMode===`cron`){if(!a.cronExpr.trim()){w(r(`batchImportModal.cronExprRequired`,null,`请选择 Cron 调度后填写 Cron 表达式`));return}if(!W.test(a.cronExpr.trim())){w(r(`batchImportModal.cronExprInvalid`,null,`Cron 表达式格式错误,需要 5 段(分 时 日 月 周)`));return}}let t=Number(a.concurrency);(!Number.isFinite(t)||t<1)&&(t=1),t>8&&(t=8),S(!0);try{let i=await b.post(`/batch-tasks`,{title:a.title.trim(),tasks:e,role:a.role||``,projectId:a.projectId||``,collectionId:a.collectionId||``,agentMode:a.agentMode||`single`,hitlPolicy:a.hitlPolicy||``,scheduleMode:a.scheduleMode===`cron`?`cron`:`manual`,cronExpr:a.scheduleMode===`cron`?a.cronExpr.trim():``,concurrency:t,executeNow:!!a.executeNow});j(r(`tasks.batchQueueTitle`,null,`批量任务队列`)),n?.(i)}catch(e){w(B(e,r(`tasks.createBatchQueueFailed`,null,`创建批量任务队列失败`)))}finally{S(!1)}},okText:r(`batchImportModal.createQueue`,null,`创建队列`),cancelText:r(`common.cancel`,null,`取消`),confirmLoading:v,width:760,maskClosable:!1,children:[(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.queueTitle`,null,`任务标题`)}),(0,V.jsx)(d,{value:a.title,maxLength:200,placeholder:r(`batchImportModal.queueTitlePlaceholder`,null,`请输入任务标题(可选,用于标识和筛选)`),onChange:e=>C({title:e})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.role`,null,`角色`)}),(0,V.jsx)(_,{value:a.role,style:{width:`100%`},optionList:[{value:``,label:r(`batchImportModal.defaultRole`,null,`默认`)},...s.map(e=>({value:e.name,label:e.name}))],onChange:e=>C({role:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.roleHint`,null,`选择一个角色,所有任务将使用该角色的配置(提示词和工具)执行。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.project`,null,`所属项目`)}),(0,V.jsx)(_,{value:a.projectId,style:{width:`100%`},optionList:[{value:``,label:r(`batchImportModal.projectNone`,null,`(未绑定)`)},...N(ee,r,{currentId:a.projectId})],onChange:e=>C({projectId:e||``,collectionId:``})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.agentMode`,null,`代理模式`)}),(0,V.jsx)(_,{value:a.agentMode,style:{width:`100%`},optionList:L,onChange:e=>C({agentMode:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.agentModeHint`,null,`与对话页一致:Pi 单代理,或 Deep / Plan-Execute / Supervisor(后三种需已启用多代理)。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:`资产范围`}),p.length?(0,V.jsx)(_,{value:a.collectionId,style:{width:`100%`},disabled:!a.projectId,optionList:[{value:``,label:h==null?`资产库中该项目的全部资产`:`资产库中该项目的全部资产(${h})`},...p.map(e=>({value:e.id,label:`${e.name}(${e.member_count||0})`}))],onChange:e=>C({collectionId:e||``})}):(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:a.projectId?h==null?`资产库中该项目的全部资产`:`资产库中该项目的全部资产(${h})`:`选择项目后,使用资产库里该项目的资产。`}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:`与对话、深度测评共用资产库。只有信息收集保存过检索结果时,才需要从中缩小范围。`})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.tasksList`,null,`任务列表(每行一个任务)`)}),(0,V.jsx)(u,{value:a.tasksText,rows:7,placeholder:r(`batchImportModal.tasksListPlaceholderExample`,null,`请输入任务列表,每行一个任务`),onChange:e=>C({tasksText:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.tasksListHint`,null,`每行输入一个任务指令,系统将按并发池执行这些任务。空行会被自动忽略。`)})]}),(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.hitlPolicy`,null,`工具审批`)}),(0,V.jsx)(_,{value:a.hitlPolicy,style:{width:`100%`},optionList:R,onChange:e=>C({hitlPolicy:e})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.concurrency`,null,`并发数`)}),(0,V.jsx)(d,{type:`number`,min:1,max:8,value:String(a.concurrency),onChange:e=>C({concurrency:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.concurrencyHint`,null,`同时执行的子任务数量(1-8)。默认 1 为串行;含扫描类工具时建议 1-2。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.scheduleMode`,null,`调度方式`)}),(0,V.jsx)(_,{value:a.scheduleMode,style:{width:`100%`},optionList:ie,onChange:e=>C({scheduleMode:e})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.cronExpr`,null,`Cron 表达式`)}),(0,V.jsx)(d,{value:a.cronExpr,disabled:a.scheduleMode!==`cron`,placeholder:r(`batchImportModal.cronExprPlaceholder`,null,`例如:0 */2 * * *(每2小时执行一次)`),onChange:e=>C({cronExpr:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.cronExprHint`,null,`采用标准 5 段 Cron:分 时 日 月 周。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(c,{checked:a.executeNow,onChange:e=>C({executeNow:e.target.checked}),children:r(`batchImportModal.executeNow`,null,`创建后立即执行`)}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.executeNowHint`,null,`默认不立即执行;关闭后队列保持待执行,可在需要时手动开始。`)})]})]})}var{Text:G}=a;function K({status:e}){let t=I[String(e||``)]||{label:e||`—`,color:`grey`};return(0,V.jsx)(s,{size:`small`,color:t.color,children:t.label})}function de({queueId:e,visible:t,canWrite:r,canDelete:i,onClose:a,onChanged:c}){let d=x(),ee=n(),[m,_]=(0,P.useState)(0),[y,S]=(0,P.useState)({visible:!1,taskId:``,message:``}),[O,k]=(0,P.useState)({visible:!1,task:null}),A=C(()=>e?b.get(`/batch-tasks/${e}`):Promise.resolve(null),[e,m]),N=A.data?.queue||null,F=(0,P.useMemo)(()=>oe(N),[N]);ne(()=>{t&&N?.status===`running`&&A.reload({silent:!0})},t&&N?.status===`running`?4e3:0),(0,P.useEffect)(()=>{t&&e&&A.reload({silent:!0})},[t,e]),(0,P.useEffect)(()=>{t||(S({visible:!1,taskId:``,message:``}),k({visible:!1,task:null}))},[t]);let I=()=>{_(e=>e+1),c?.()},ie=async(t,n)=>{try{await b.post(`/batch-tasks/${e}/${t}`),j(n),I()}catch(e){w(B(e,n+`失败`))}},ae=()=>ie(`start`,`已开始执行`),se=()=>M({title:d(`tasks.statusPaused`,null,`已暂停`),content:d(`tasks.pauseQueueConfirm`,null,`确定要暂停这个批量任务队列吗?当前正在执行的任务将被停止,后续任务将保留待执行状态。`),okText:d(`common.confirm`,null,`确认`),onOk:async()=>{try{await b.post(`/batch-tasks/${e}/pause`),j(d(`tasks.statusPaused`,null,`已暂停`)),I()}catch(e){w(B(e,d(`tasks.pauseQueueFailed`,null,`暂停批量任务失败`)))}}}),H=()=>M({title:d(`tasks.retry`,null,`重试`),content:d(`tasks.rerunQueueConfirm`,null,`确定要重跑一轮吗?所有子任务将被重置为待执行状态并重新开始执行。`),okText:d(`common.confirm`,null,`确认`),onOk:async()=>{try{await b.post(`/batch-tasks/${e}/rerun`),j(d(`tasks.statusRunning`,null,`执行中`)),I()}catch(e){w(B(e,d(`tasks.rerunQueueFailed`,null,`重跑批量任务失败`)))}}}),U=()=>M({title:d(`tasks.deleteQueue`,null,`删除队列`),content:d(`tasks.deleteQueueConfirm`,null,`确定要删除这个批量任务队列吗?此操作不可恢复。`),okText:d(`common.delete`,null,`删除`),onOk:async()=>{try{await b.del(`/batch-tasks/${e}`),j(d(`tasks.deleteQueue`,null,`删除队列`)),c?.(),a?.()}catch(e){w(B(e,d(`tasks.deleteQueueFailed`,null,`删除批量任务队列失败`)))}}}),W=e=>S({visible:!0,taskId:e?.id||``,message:e?.message||``}),ue=async()=>{let t=y.message.trim();if(!t)w(d(`tasks.taskMessageRequired`,null,`任务消息不能为空`));else try{y.taskId?await b.put(`/batch-tasks/${e}/tasks/${y.taskId}`,{message:t}):await b.post(`/batch-tasks/${e}/tasks`,{message:t}),j(d(`common.save`,null,`保存`)),S({visible:!1,taskId:``,message:``}),I()}catch(e){w(B(e,y.taskId?d(`tasks.saveTaskFailed`,null,`保存任务失败`):d(`tasks.addTaskFailed`,null,`添加任务失败`)))}},de=t=>M({title:d(`tasks.runSingleTask`,null,`单条执行`),content:d(`tasks.confirmRunSingleTask`,null,`确定执行该任务?仅运行这一条,完成后队列会自动暂停,不会继续执行其他待执行项。`),okText:d(`common.confirm`,null,`确认`),danger:!1,onOk:async()=>{try{await b.post(`/batch-tasks/${e}/tasks/${t.id}/run`),j(d(`tasks.runSingleTask`,null,`单条执行`)),I()}catch(e){w(B(e,d(`tasks.runSingleTaskFailed`,null,`单条执行失败`)))}}}),q=t=>M({title:d(`common.delete`,null,`删除`),content:d(`tasks.confirmDeleteTask`,null,`确定要删除这个任务吗?`),okText:d(`common.delete`,null,`删除`),onOk:async()=>{try{await b.del(`/batch-tasks/${e}/tasks/${t.id}`),j(d(`common.delete`,null,`删除`)),I()}catch(e){w(B(e,d(`tasks.deleteTaskFailed`,null,`删除任务失败`)))}}}),J=e=>!!(r&&N&&e.status!==`running`&&N.status!==`running`&&[`pending`,`paused`,`completed`,`cancelled`].includes(N.status)),fe=[{title:`#`,dataIndex:`id`,width:58,render:(e,t)=>{let n=(N?.tasks||[]).findIndex(e=>e.id===t.id);return(0,V.jsx)(G,{type:`tertiary`,size:`small`,children:n+1})}},{title:d(`tasks.title`,null,`任务`),dataIndex:`message`,render:(e,t)=>(0,V.jsx)(`span`,{className:`task-cell-message`,title:e,children:e||d(`tasks.taskIncomplete`,null,`任务信息不完整`)})},{title:d(`projects.status`,null,`状态`),dataIndex:`status`,width:96,render:e=>(0,V.jsx)(K,{status:e})},{title:d(`tasks.duration`,null,`执行时长`),dataIndex:`startedAt`,width:110,render:(e,t)=>(0,V.jsx)(G,{size:`small`,children:e?z(e,t.completedAt):`—`})},{title:d(`common.actions`,null,`操作`),dataIndex:`id`,width:210,render:(e,t)=>(0,V.jsxs)(o,{spacing:2,wrap:!0,children:[(0,V.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>k({visible:!0,task:t}),children:`结果`}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!r,onClick:()=>W(t),children:d(`common.edit`,null,`编辑`)}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!J(t),title:d(`tasks.runSingleTaskUnavailable`,null,`队列或任务执行中,暂无法单条执行`),onClick:()=>de(t),children:d(`tasks.runSingleTask`,null,`单条执行`)}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!i,onClick:()=>q(t),children:d(`common.delete`,null,`删除`)})]})}],Y=ce(N),X=N?.scheduleMode===`cron`&&N?.scheduleEnabled!==!1;return(0,V.jsxs)(h,{visible:t,width:900,title:N?N.title||N.id:d(`tasks.batchQueueTitle`,null,`批量任务队列`),onCancel:a,children:[(0,V.jsx)(te,{error:le(A.error),onRetry:()=>A.reload()}),N?(0,V.jsxs)(`div`,{className:`task-detail-stack`,children:[(0,V.jsxs)(`div`,{className:`task-detail-actions`,children:[(0,V.jsxs)(o,{wrap:!0,children:[(0,V.jsx)(l,{type:`primary`,disabled:!r||N.status===`running`,onClick:ae,children:`开始执行`}),(0,V.jsx)(l,{disabled:!r||N.status!==`running`,onClick:se,children:`暂停`}),(0,V.jsx)(l,{disabled:!r||![`completed`,`cancelled`].includes(N.status),onClick:H,children:d(`tasks.retry`,null,`重试`)}),(0,V.jsx)(l,{icon:(0,V.jsx)(g,{}),theme:`borderless`,onClick:()=>A.reload()})]}),(0,V.jsxs)(o,{children:[(0,V.jsx)(l,{icon:(0,V.jsx)(f,{}),disabled:!r,onClick:()=>W(null),children:`添加任务`}),(0,V.jsx)(l,{type:`danger`,disabled:!i,onClick:U,children:d(`tasks.deleteQueue`,null,`删除队列`)})]})]}),(0,V.jsxs)(`div`,{className:`task-progress-block`,children:[(0,V.jsxs)(`div`,{className:`task-progress-head`,children:[(0,V.jsx)(s,{size:`small`,color:Y.color,children:Y.label}),Y.sublabel?(0,V.jsx)(G,{type:`tertiary`,size:`small`,children:Y.sublabel}):null]}),(0,V.jsx)(p,{percent:F.percent,showInfo:!0,stroke:`var(--semi-color-primary)`}),(0,V.jsxs)(`div`,{className:`task-progress-legend`,children:[(0,V.jsxs)(`span`,{children:[d(`tasks.totalLabel`,null,`总计`),` `,F.total]}),(0,V.jsxs)(`span`,{children:[d(`tasks.pendingLabel`,null,`待执行`),` `,F.pending]}),(0,V.jsxs)(`span`,{children:[d(`tasks.runningLabel`,null,`执行中`),` `,F.running]}),(0,V.jsxs)(`span`,{children:[d(`tasks.completedLabel`,null,`已完成`),` `,F.completed]}),(0,V.jsxs)(`span`,{children:[d(`tasks.failedLabel`,null,`失败`),` `,F.failed]}),(0,V.jsxs)(`span`,{children:[d(`tasks.cancelledLabel`,null,`已取消`),` `,F.cancelled]}),(0,V.jsxs)(`span`,{children:[`受阻 `,F.blocked]})]}),(0,V.jsx)(G,{type:`tertiary`,size:`small`,children:X?d(`tasks.cronRunningProgressHint`,null,`本轮执行中;下一整轮仍按 Cron 与「下次执行时间」排程`):d(`tasks.finishedProgressHint`,null,`进度表示已结束的任务比例,包含失败和取消,不表示成功率。`)})]}),(0,V.jsx)(E,{columns:3,items:[{label:d(`tasks.queueIdLabel`,null,`队列ID`),value:(0,V.jsx)(`code`,{children:N.id})},{label:d(`tasks.createdTimeLabel`,null,`创建时间`),value:v(N.createdAt)},{label:`Agent 模式`,value:(L.find(e=>e.value===N.agentMode)||L[0]).label},{label:`角色`,value:N.role||d(`batchImportModal.defaultRole`,null,`默认`)},{label:`项目`,value:N.projectId||`—`},{label:d(`batchImportModal.hitlPolicy`,null,`工具审批`),value:(R.find(e=>e.value===(N.hitlPolicy||``))||R[0]).label},{label:d(`batchImportModal.concurrency`,null,`并发数`),value:N.concurrency||1},{label:d(`batchImportModal.scheduleMode`,null,`调度方式`),value:N.scheduleMode===`cron`?`Cron ${N.cronExpr||``}${X?``:`(已关闭)`}`:d(`batchImportModal.scheduleModeManual`,null,`手工执行`)},{label:`下一次执行`,value:N.nextRunAt?v(N.nextRunAt):`—`},N.lastRunError?{label:`最近错误`,value:(0,V.jsx)(G,{type:`danger`,size:`small`,children:N.lastRunError})}:null]}),(0,V.jsx)(re,{columns:fe,dataSource:N.tasks||[],rowKey:`id`,size:`small`,pagination:{pageSize:10},emptyText:d(`tasks.noValidTask`,null,`没有有效的任务`)})]}):null,(0,V.jsx)(T,{visible:y.visible,title:y.taskId?d(`common.edit`,null,`编辑`):`添加任务`,onCancel:()=>S({visible:!1,taskId:``,message:``}),onOk:ue,okText:d(`common.save`,null,`保存`),cancelText:d(`common.cancel`,null,`取消`),width:620,children:(0,V.jsx)(u,{value:y.message,rows:5,placeholder:d(`batchImportModal.tasksListPlaceholder`,null,`请输入任务列表,每行一个任务`),onChange:e=>S(t=>({...t,message:e}))})}),(0,V.jsx)(T,{visible:O.visible,title:O.task?O.task.message:`结果`,onCancel:()=>k({visible:!1,task:null}),footer:(0,V.jsxs)(o,{children:[O.task?.conversationId?(0,V.jsx)(l,{onClick:()=>{let e=O.task.conversationId;k({visible:!1,task:null}),a?.(),ee(`/chat?conversation=${encodeURIComponent(e)}`)},children:d(`tasks.viewConversation`,null,`查看对话`)}):null,(0,V.jsx)(l,{onClick:()=>k({visible:!1,task:null}),children:d(`common.close`,null,`关闭`)})]}),width:720,children:(0,V.jsxs)(`div`,{className:`task-detail-stack`,children:[(0,V.jsx)(E,{columns:2,items:[{label:d(`projects.status`,null,`状态`),value:(0,V.jsx)(K,{status:O.task?.status})},{label:d(`tasks.startedAt`,null,`开始时间`),value:v(O.task?.startedAt)},{label:d(`tasks.completedAt`,null,`完成时间`),value:v(O.task?.completedAt)},{label:d(`tasks.duration`,null,`执行时长`),value:z(O.task?.startedAt,O.task?.completedAt)},O.task?.conversationId?{label:d(`tasks.conversationIdLabel`,null,`对话ID`),value:(0,V.jsx)(`code`,{children:O.task.conversationId})}:null]}),O.task?.error?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(G,{strong:!0,type:`danger`,children:O.task.status===`blocked`?`受阻原因`:d(`tasks.statusFailed`,null,`执行失败`)}),(0,V.jsx)(`pre`,{className:`task-result-pre`,children:O.task.error})]}):null,O.task?.result?(0,V.jsx)(D,{content:O.task.result}):(0,V.jsx)(G,{type:`tertiary`,children:`暂无结果`})]})})]})}var{Text:q}=a,J={running:{label:`执行中`,color:`blue`},cancelling:{label:`取消中`,color:`amber`},cleaning:{label:`清理中`,color:`amber`}};function fe(){let e=x(),t=n(),r=C(()=>b.get(`/agent-loop/tasks`),[]);ne(()=>r.reload({silent:!0}),6e3);let i=Array.isArray(r.data?.tasks)?r.data.tasks:[],a=[{title:e(`tasks.title`,null,`任务`),dataIndex:`title`,render:(t,n)=>(0,V.jsxs)(`div`,{className:`task-live-title`,children:[(0,V.jsx)(`span`,{className:`task-cell-message`,title:t||n.message,children:t||n.message||e(`tasks.unnamedTask`,null,`未命名任务`)}),(0,V.jsx)(q,{type:`tertiary`,size:`small`,children:(0,V.jsx)(`code`,{children:n.runId||`—`})})]})},{title:e(`projects.status`,null,`状态`),dataIndex:`status`,width:110,render:e=>{let t=J[String(e||``)]||{label:e||`—`,color:`blue`};return(0,V.jsx)(s,{size:`small`,color:t.color,children:t.label})}},{title:e(`tasks.conversationIdLabel`,null,`对话ID`),dataIndex:`conversationId`,width:230,render:e=>(0,V.jsx)(q,{type:`tertiary`,size:`small`,children:(0,V.jsx)(`code`,{children:e||`—`})})},{title:e(`tasks.startedAt`,null,`开始时间`),dataIndex:`startedAt`,width:165,render:e=>(0,V.jsx)(q,{size:`small`,children:v(e)})},{title:e(`tasks.duration`,null,`执行时长`),dataIndex:`startedAt`,width:110,render:e=>(0,V.jsx)(q,{size:`small`,children:z(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`conversationId`,width:110,render:n=>(0,V.jsx)(o,{children:(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>t(`/chat?conversation=${encodeURIComponent(n)}`),children:e(`tasks.viewConversation`,null,`查看对话`)})})}];return(0,V.jsxs)(O,{title:`${e(`tasks.runningLabel`,null,`执行中`)}任务(Agent Loop)`,description:`当前进程中正在执行的 Agent 任务;每 6 秒自动刷新。`,extra:(0,V.jsx)(l,{icon:(0,V.jsx)(g,{}),theme:`borderless`,loading:r.loading,onClick:()=>r.reload(),children:e(`common.refresh`,null,`刷新`)}),children:[(0,V.jsx)(te,{error:le(r.error),onRetry:()=>r.reload()}),(0,V.jsx)(re,{columns:a,dataSource:i,rowKey:e=>e.runId||e.conversationId||`unknown-task`,loading:r.loading,pagination:{pageSize:10},emptyText:e(`tasks.noMatchingTasks`,null,`当前没有符合条件的任务`)})]})}var{Text:Y}=a;function X(){let e=x(),{hasPermission:t}=y(),n=t(`tasks:write`),r=t(`tasks:delete`),[a,c]=i(),u=a.get(`id`)||``,h=a.get(`tab`)||`queues`,[T,E]=(0,P.useState)(1),[D,N]=(0,P.useState)(10),[F,I]=(0,P.useState)(`all`),[L,R]=(0,P.useState)(``),ie=k(L,300),[z,H]=(0,P.useState)(!1),[U,W]=(0,P.useState)(0),G=C(()=>b.get(`/batch-tasks`,{limit:100,page:1}),[U]),K=C(()=>b.get(`/batch-tasks`,{limit:D,page:T,status:F===`all`?void 0:F,keyword:ie.trim()||void 0}),[T,D,F,ie,U]),q=Array.isArray(K.data?.queues)?K.data.queues:[],J=K.data?.total??0,X=(0,P.useMemo)(()=>(G.data?.queues||[]).some(e=>e.status===`running`),[G.data]);ne(()=>{X&&(G.reload({silent:!0}),K.reload({silent:!0}))},X?5e3:0);let Z=(0,P.useCallback)((e,t)=>{let n=new URLSearchParams(a);e?n.set(`id`,e):n.delete(`id`),t?n.set(`tab`,t):n.delete(`tab`),c(n,{replace:!!e})},[a,c]);(0,P.useEffect)(()=>{h!==`queues`&&h!==`live`&&Z(void 0,`queues`)},[h,Z]);let Q=()=>W(e=>e+1),pe=G.data?.queues||[],$=(0,P.useMemo)(()=>{let e=pe.map(oe);return{queues:G.data?.total??pe.length,running:pe.filter(e=>e.status===`running`).length,pendingTasks:e.reduce((e,t)=>e+t.pending,0),failedTasks:e.reduce((e,t)=>e+t.failed,0)}},[pe,G.data]),me=async t=>{try{await b.post(`/batch-tasks/${t.id}/start`),j(`已开始执行`),Q()}catch(t){w(B(t,e(`tasks.startBatchQueueFailed`,null,`启动批量任务失败`)))}},he=t=>M({title:e(`tasks.statusPaused`,null,`已暂停`),content:e(`tasks.pauseQueueConfirm`,null,`确定要暂停这个批量任务队列吗?当前正在执行的任务将被停止,后续任务将保留待执行状态。`),okText:e(`common.confirm`,null,`确认`),onOk:async()=>{try{await b.post(`/batch-tasks/${t.id}/pause`),j(e(`tasks.statusPaused`,null,`已暂停`)),Q()}catch(t){w(B(t,e(`tasks.pauseQueueFailed`,null,`暂停批量任务失败`)))}}}),ge=t=>M({title:e(`tasks.retry`,null,`重试`),content:e(`tasks.rerunQueueConfirm`,null,`确定要重跑一轮吗?所有子任务将被重置为待执行状态并重新开始执行。`),okText:e(`common.confirm`,null,`确认`),onOk:async()=>{try{await b.post(`/batch-tasks/${t.id}/rerun`),j(`已开始重跑`),Q()}catch(t){w(B(t,e(`tasks.rerunQueueFailed`,null,`重跑批量任务失败`)))}}}),_e=t=>M({title:e(`tasks.deleteQueue`,null,`删除队列`),content:e(`tasks.deleteQueueConfirm`,null,`确定要删除这个批量任务队列吗?此操作不可恢复。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await b.del(`/batch-tasks/${t.id}`),j(e(`tasks.deleteQueue`,null,`删除队列`)),u===t.id&&Z(void 0,h),Q()}catch(t){w(B(t,e(`tasks.deleteQueueFailed`,null,`删除批量任务队列失败`)))}}}),ve=[{id:`queues`,label:e(`tasks.batchQueueTitle`,null,`批量任务队列`),value:$.queues,loading:G.loading},{id:`running`,label:e(`tasks.runningLabel`,null,`执行中`),value:$.running,tone:$.running?`success`:void 0,loading:G.loading},{id:`pending`,label:e(`tasks.pendingLabel`,null,`待执行`),value:$.pendingTasks,loading:G.loading},{id:`failed`,label:e(`tasks.failedLabel`,null,`失败`),value:$.failedTasks,tone:$.failedTasks?`danger`:void 0,loading:G.loading}],ye=[{title:e(`batchImportModal.queueTitle`,null,`任务标题`),dataIndex:`title`,render:(t,n)=>{let r=ce(n);return(0,V.jsxs)(`button`,{type:`button`,className:`task-queue-name`,onClick:()=>Z(n.id,`queues`),title:n.id,children:[(0,V.jsx)(`span`,{className:`task-queue-title`,children:t||e(`tasks.batchQueueUntitled`,null,`未命名队列`)}),r.sublabel?(0,V.jsx)(`span`,{className:`task-queue-sub`,children:r.sublabel}):null]})}},{title:e(`projects.status`,null,`状态`),dataIndex:`status`,width:170,render:(e,t)=>{let n=ce(t);return(0,V.jsx)(s,{size:`small`,color:n.color,children:n.label})}},{title:`进度`,dataIndex:`progress`,width:190,render:(e,t)=>{let n=oe(t);return(0,V.jsxs)(`div`,{className:`task-queue-progress`,children:[(0,V.jsx)(p,{percent:n.percent,showInfo:!1,size:`small`}),(0,V.jsxs)(Y,{type:`tertiary`,size:`small`,children:[n.percent,`%(`,n.done,`/`,n.total,`)`]})]})}},{title:e(`batchImportModal.agentMode`,null,`代理模式`),dataIndex:`agentMode`,width:150,render:e=>(0,V.jsx)(Y,{size:`small`,children:se(e)})},{title:e(`batchImportModal.scheduleMode`,null,`调度方式`),dataIndex:`scheduleMode`,width:128,render:(t,n)=>(0,V.jsx)(Y,{size:`small`,children:t===`cron`?`Cron · ${n.cronExpr||``}`:e(`batchImportModal.scheduleModeManual`,null,`手工执行`)})},{title:e(`tasks.createdTimeLabel`,null,`创建时间`),dataIndex:`createdAt`,width:160,render:e=>(0,V.jsx)(Y,{type:`tertiary`,size:`small`,children:v(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:250,render:(t,i)=>(0,V.jsxs)(o,{spacing:2,wrap:!0,children:[(0,V.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>Z(i.id,`queues`),children:e(`projects.details`,null,`详情`)}),i.status===`running`?(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>he(i),children:e(`tasks.statusPaused`,null,`已暂停`)}):(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>me(i),children:`开始执行`}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n||![`completed`,`cancelled`].includes(i.status),onClick:()=>ge(i),children:e(`tasks.retry`,null,`重试`)}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!r,onClick:()=>_e(i),children:e(`common.delete`,null,`删除`)})]})}];return(0,V.jsxs)(`div`,{className:`task-page`,children:[(0,V.jsx)(A,{title:e(`tasks.title`,null,`任务管理`),description:e(`tasks.pageDesc`,null,`批量任务队列按并发池执行子任务;队列详情可查看进度、单条执行与结果。`),extra:(0,V.jsxs)(o,{children:[(0,V.jsx)(l,{icon:(0,V.jsx)(g,{}),theme:`borderless`,loading:K.loading,onClick:Q,children:e(`common.refresh`,null,`刷新`)}),(0,V.jsx)(l,{type:`primary`,icon:(0,V.jsx)(f,{}),disabled:!n,onClick:()=>H(!0),children:e(`batchImportModal.title`,null,`新建任务`)})]})}),(0,V.jsx)(te,{error:le(G.error||K.error),onRetry:Q}),(0,V.jsx)(S,{metrics:ve,columns:4}),(0,V.jsx)(ee,{type:`line`,activeKey:h,onChange:e=>Z(void 0,e),tabList:[{itemKey:`queues`,tab:e(`tasks.batchQueueTitle`,null,`批量任务队列`)},{itemKey:`live`,tab:`${e(`tasks.runningLabel`,null,`执行中`)}任务`}],className:`task-tabs`}),h===`live`?(0,V.jsx)(fe,{}):(0,V.jsxs)(O,{title:e(`tasks.batchQueueTitle`,null,`批量任务队列`),description:e(`tasks.finishedProgressHint`,null,`进度表示已结束的任务比例,包含失败和取消,不表示成功率。`),extra:(0,V.jsx)(Y,{type:`tertiary`,size:`small`,children:e(`tasks.taskCount`,{count:J},`共 ${J} 个任务`)}),children:[(0,V.jsxs)(`div`,{className:`task-toolbar`,children:[(0,V.jsx)(d,{prefix:(0,V.jsx)(m,{}),value:L,showClear:!0,placeholder:e(`batchImportModal.queueTitlePlaceholder`,null,`请输入任务标题(可选,用于标识和筛选)`),onChange:e=>{R(e),E(1)},style:{width:280}}),(0,V.jsx)(_,{value:F,onChange:e=>{I(e),E(1)},style:{width:150},optionList:ae})]}),(0,V.jsx)(re,{columns:ye,dataSource:q,rowKey:`id`,loading:K.loading,emptyText:F!==`all`||L?e(`tasks.noMatchingTasks`,null,`当前没有符合条件的任务`):e(`tasks.noBatchQueues`,null,`当前没有批量任务队列`),pagination:{currentPage:T,pageSize:D,total:J,onPageChange:e=>E(e),onPageSizeChange:e=>{N(e),E(1)}}})]}),(0,V.jsx)(ue,{visible:z,onCancel:()=>H(!1),onCreated:e=>{H(!1),Q(),e?.queueId&&Z(e.queueId,`queues`)}}),(0,V.jsx)(de,{queueId:u,visible:!!u,canWrite:n,canDelete:r,onClose:()=>Z(void 0,h),onChanged:Q})]})}export{X as default};
\ No newline at end of file
diff --git a/web/static/app/assets/tasks-C-O0ZxhT.js b/web/static/app/assets/tasks-C-O0ZxhT.js
new file mode 100644
index 00000000..ffc02d14
--- /dev/null
+++ b/web/static/app/assets/tasks-C-O0ZxhT.js
@@ -0,0 +1,2 @@
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{G as a,I as o,N as s,P as c,R as l,S as u,U as d,c as ee,ft as f,g as p,lt as m,p as h,ut as g,y as _}from"./semi-65W_4I1v.js";import{E as v,F as y,I as b,L as x,_ as S,a as C,b as w,c as T,d as E,f as te,l as ne,m as D,n as O,p as k,r as re,s as ie,x as A,y as j}from"./index-_8d9XBPJ.js";import{t as M}from"./project-options-CMQbwv_U.js";var N=e(t(),1),P={pending:{label:`待执行`,color:`amber`},running:{label:`执行中`,color:`blue`},paused:{label:`已暂停`,color:`grey`},completed:{label:`已完成`,color:`green`},cancelled:{label:`已取消`,color:`grey`}},F={pending:{label:`待执行`,color:`amber`},running:{label:`执行中`,color:`blue`},completed:{label:`已完成`,color:`green`},failed:{label:`失败`,color:`red`},cancelled:{label:`已取消`,color:`grey`},blocked:{label:`受阻`,color:`orange`}},I=[{value:`single`,label:`单代理(Pi SDK)`},{value:`deep`,label:`Deep(DeepAgent)`},{value:`plan_execute`,label:`Plan-Execute`},{value:`supervisor`,label:`Supervisor(专家路由)`}],ae=[{value:``,label:`沿用全局设置`},{value:`off`,label:`关闭审批`},{value:`human`,label:`人工审批`},{value:`audit_agent`,label:`Agent 审批`},{value:`review_edit`,label:`Agent 审查编辑`}],L=[{value:`manual`,label:`手工执行`},{value:`cron`,label:`Cron 调度`}],oe=[{value:`all`,label:`全部状态`},{value:`pending`,label:`待执行`},{value:`running`,label:`执行中`},{value:`paused`,label:`已暂停`},{value:`completed`,label:`已完成`},{value:`cancelled`,label:`已取消`}];function R(e){let t=Array.isArray(e?.tasks)?e.tasks:[],n=t.length,r=t.filter(e=>e.status===`completed`).length,i=t.filter(e=>e.status===`failed`).length,a=t.filter(e=>e.status===`cancelled`).length,o=t.filter(e=>e.status===`blocked`).length,s=t.filter(e=>e.status===`running`).length,c=t.filter(e=>e.status===`pending`).length,l=r+i+a+o;return{total:n,completed:r,failed:i,cancelled:a,blocked:o,running:s,pending:c,done:l,percent:n?Math.round(l/n*100):0}}function se(e){return(I.find(t=>t.value===String(e||`single`))||I[0]).label}function ce(e){let t=P[String(e?.status||``)]||{label:e?.status||`—`,color:`grey`},n=e?.scheduleMode===`cron`&&e?.scheduleEnabled!==!1,r=e?.nextRunAt?new Date(e.nextRunAt):null,i=r&&Number.isFinite(r.getTime())?r.toLocaleString(`zh-CN`,{hour12:!1}):``,a=R(e),o=a.blocked>0?e?.lastRunError||`${a.blocked} 项受阻`:``;if(a.blocked>0&&a.completed===0&&a.failed===0)return{...t,label:`受阻(${a.blocked} 项)`,color:`orange`,sublabel:o};if(n&&e?.status===`completed`){let e=a.failed>0||a.blocked>0;return{...t,label:e?`本轮已结束 · 定时循环中`:`本轮已完成 · 定时循环中`,color:a.failed>0?`red`:a.blocked>0?`orange`:t.color,sublabel:o||(i?`下次执行:${i}`:``),note:`定时队列:子任务已跑完,到点将自动下一轮`}}if(n&&e?.status===`pending`&&i)return{...t,sublabel:`Cron 已排程 · 下次 ${i}`};if(e?.status===`completed`&&a.failed>0){let e=a.blocked>0?`,${a.blocked} 项受阻`:``;return{...t,label:`已结束(${a.failed} 项失败${e})`,color:`red`,sublabel:o}}return e?.status===`completed`&&a.blocked>0?{...t,label:`已结束(${a.blocked} 项受阻)`,color:`orange`,sublabel:o}:{...t,sublabel:``}}function z(e,t){if(!e)return`—`;let n=new Date(e).getTime(),r=t?new Date(t).getTime():Date.now();if(!Number.isFinite(n)||!Number.isFinite(r)||r{if(!e)return;o(U),S(!1);let t=!1;return i(`roles:read`)&&x.get(`/roles`).then(e=>{t||l(Array.isArray(e?.roles)?e.roles:[])}).catch(()=>{t||l([])}),i(`project:read`)&&x.get(`/projects`,{limit:500}).then(e=>{t||f(Array.isArray(e?.projects)?e.projects:[])}).catch(()=>{t||f([])}),()=>{t=!0}},[e,i]),(0,N.useEffect)(()=>{if(!e||!a.projectId||!i(`asset:read`)){m([]),g(null);return}let t=!1;return x.get(`/assets/collections`,{project_id:a.projectId}).then(e=>{t||m(Array.isArray(e?.collections)?e.collections:[])}).catch(()=>{t||m([])}),x.get(`/assets`,{project_id:a.projectId,page:1,page_size:1}).then(e=>{t||g(Number.isFinite(Number(e?.total))?Number(e.total):0)}).catch(()=>{t||g(null)}),()=>{t=!0}},[e,a.projectId,i]);let C=e=>o(t=>({...t,...e}));return(0,V.jsxs)(T,{visible:e,title:r(`batchImportModal.title`,null,`新建任务`),onCancel:t,onOk:async()=>{let e=a.tasksText.split(`
+`).map(e=>e.trim()).filter(Boolean);if(!e.length){w(r(`tasks.noValidTask`,null,`没有有效的任务`));return}if(a.scheduleMode===`cron`){if(!a.cronExpr.trim()){w(r(`batchImportModal.cronExprRequired`,null,`请选择 Cron 调度后填写 Cron 表达式`));return}if(!W.test(a.cronExpr.trim())){w(r(`batchImportModal.cronExprInvalid`,null,`Cron 表达式格式错误,需要 5 段(分 时 日 月 周)`));return}}let t=Number(a.concurrency);(!Number.isFinite(t)||t<1)&&(t=1),t>8&&(t=8),S(!0);try{let i=await x.post(`/batch-tasks`,{title:a.title.trim(),tasks:e,role:a.role||``,projectId:a.projectId||``,collectionId:a.collectionId||``,agentMode:a.agentMode||`single`,hitlPolicy:a.hitlPolicy||``,scheduleMode:a.scheduleMode===`cron`?`cron`:`manual`,cronExpr:a.scheduleMode===`cron`?a.cronExpr.trim():``,concurrency:t,executeNow:!!a.executeNow});A(r(`tasks.batchQueueTitle`,null,`批量任务队列`)),n?.(i)}catch(e){w(B(e,r(`tasks.createBatchQueueFailed`,null,`创建批量任务队列失败`)))}finally{S(!1)}},okText:r(`batchImportModal.createQueue`,null,`创建队列`),cancelText:r(`common.cancel`,null,`取消`),confirmLoading:v,width:760,maskClosable:!1,children:[(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.queueTitle`,null,`任务标题`)}),(0,V.jsx)(d,{value:a.title,maxLength:200,placeholder:r(`batchImportModal.queueTitlePlaceholder`,null,`请输入任务标题(可选,用于标识和筛选)`),onChange:e=>C({title:e})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.role`,null,`角色`)}),(0,V.jsx)(_,{value:a.role,style:{width:`100%`},optionList:[{value:``,label:r(`batchImportModal.defaultRole`,null,`默认`)},...s.map(e=>({value:e.name,label:e.name}))],onChange:e=>C({role:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.roleHint`,null,`选择一个角色,所有任务将使用该角色的配置(提示词和工具)执行。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.project`,null,`所属项目`)}),(0,V.jsx)(_,{value:a.projectId,style:{width:`100%`},optionList:[{value:``,label:r(`batchImportModal.projectNone`,null,`(未绑定)`)},...M(ee,r,{currentId:a.projectId})],onChange:e=>C({projectId:e||``,collectionId:``})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.agentMode`,null,`代理模式`)}),(0,V.jsx)(_,{value:a.agentMode,style:{width:`100%`},optionList:I,onChange:e=>C({agentMode:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.agentModeHint`,null,`与对话页一致:Pi 单代理,或 Deep / Plan-Execute / Supervisor(后三种需已启用多代理)。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:`资产范围`}),p.length?(0,V.jsx)(_,{value:a.collectionId,style:{width:`100%`},disabled:!a.projectId,optionList:[{value:``,label:h==null?`资产库中该项目的全部资产`:`资产库中该项目的全部资产(${h})`},...p.map(e=>({value:e.id,label:`${e.name}(${e.member_count||0})`}))],onChange:e=>C({collectionId:e||``})}):(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:a.projectId?h==null?`资产库中该项目的全部资产`:`资产库中该项目的全部资产(${h})`:`选择项目后,使用资产库里该项目的资产。`}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:`与对话、深度测评共用资产库。只有信息收集保存过检索结果时,才需要从中缩小范围。`})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.tasksList`,null,`任务列表(每行一个任务)`)}),(0,V.jsx)(u,{value:a.tasksText,rows:7,placeholder:r(`batchImportModal.tasksListPlaceholderExample`,null,`请输入任务列表,每行一个任务`),onChange:e=>C({tasksText:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.tasksListHint`,null,`每行输入一个任务指令,系统将按并发池执行这些任务。空行会被自动忽略。`)})]}),(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.hitlPolicy`,null,`工具审批`)}),(0,V.jsx)(_,{value:a.hitlPolicy,style:{width:`100%`},optionList:ae,onChange:e=>C({hitlPolicy:e})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.concurrency`,null,`并发数`)}),(0,V.jsx)(d,{type:`number`,min:1,max:8,value:String(a.concurrency),onChange:e=>C({concurrency:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.concurrencyHint`,null,`同时执行的子任务数量(1-8)。默认 1 为串行;含扫描类工具时建议 1-2。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.scheduleMode`,null,`调度方式`)}),(0,V.jsx)(_,{value:a.scheduleMode,style:{width:`100%`},optionList:L,onChange:e=>C({scheduleMode:e})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.cronExpr`,null,`Cron 表达式`)}),(0,V.jsx)(d,{value:a.cronExpr,disabled:a.scheduleMode!==`cron`,placeholder:r(`batchImportModal.cronExprPlaceholder`,null,`例如:0 */2 * * *(每2小时执行一次)`),onChange:e=>C({cronExpr:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.cronExprHint`,null,`采用标准 5 段 Cron:分 时 日 月 周。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(c,{checked:a.executeNow,onChange:e=>C({executeNow:e.target.checked}),children:r(`batchImportModal.executeNow`,null,`创建后立即执行`)}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.executeNowHint`,null,`默认不立即执行;关闭后队列保持待执行,可在需要时手动开始。`)})]})]})}var{Text:G}=a;function K({status:e}){let t=F[String(e||``)]||{label:e||`—`,color:`grey`};return(0,V.jsx)(s,{size:`small`,color:t.color,children:t.label})}function de({queueId:e,visible:t,canWrite:r,canDelete:i,onClose:a,onChanged:c}){let d=y(),ee=n(),[m,_]=(0,N.useState)(0),[b,S]=(0,N.useState)({visible:!1,taskId:``,message:``}),[D,O]=(0,N.useState)({visible:!1,task:null}),k=C(()=>e?x.get(`/batch-tasks/${e}`):Promise.resolve(null),[e,m]),M=k.data?.queue||null,P=(0,N.useMemo)(()=>R(M),[M]);re(()=>{t&&M?.status===`running`&&k.reload({silent:!0})},t&&M?.status===`running`?4e3:0),(0,N.useEffect)(()=>{t&&e&&k.reload({silent:!0})},[t,e]),(0,N.useEffect)(()=>{t||(S({visible:!1,taskId:``,message:``}),O({visible:!1,task:null}))},[t]);let F=()=>{_(e=>e+1),c?.()},L=async(t,n)=>{try{await x.post(`/batch-tasks/${e}/${t}`),A(n),F()}catch(e){w(B(e,n+`失败`))}},oe=()=>L(`start`,`已开始执行`),se=()=>j({title:d(`tasks.statusPaused`,null,`已暂停`),content:d(`tasks.pauseQueueConfirm`,null,`确定要暂停这个批量任务队列吗?当前正在执行的任务将被停止,后续任务将保留待执行状态。`),okText:d(`common.confirm`,null,`确认`),onOk:async()=>{try{await x.post(`/batch-tasks/${e}/pause`),A(d(`tasks.statusPaused`,null,`已暂停`)),F()}catch(e){w(B(e,d(`tasks.pauseQueueFailed`,null,`暂停批量任务失败`)))}}}),H=()=>j({title:d(`tasks.retry`,null,`重试`),content:d(`tasks.rerunQueueConfirm`,null,`确定要重跑一轮吗?所有子任务将被重置为待执行状态并重新开始执行。`),okText:d(`common.confirm`,null,`确认`),onOk:async()=>{try{await x.post(`/batch-tasks/${e}/rerun`),A(d(`tasks.statusRunning`,null,`执行中`)),F()}catch(e){w(B(e,d(`tasks.rerunQueueFailed`,null,`重跑批量任务失败`)))}}}),U=()=>j({title:d(`tasks.deleteQueue`,null,`删除队列`),content:d(`tasks.deleteQueueConfirm`,null,`确定要删除这个批量任务队列吗?此操作不可恢复。`),okText:d(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/batch-tasks/${e}`),A(d(`tasks.deleteQueue`,null,`删除队列`)),c?.(),a?.()}catch(e){w(B(e,d(`tasks.deleteQueueFailed`,null,`删除批量任务队列失败`)))}}}),W=e=>S({visible:!0,taskId:e?.id||``,message:e?.message||``}),ue=async()=>{let t=b.message.trim();if(!t)w(d(`tasks.taskMessageRequired`,null,`任务消息不能为空`));else try{b.taskId?await x.put(`/batch-tasks/${e}/tasks/${b.taskId}`,{message:t}):await x.post(`/batch-tasks/${e}/tasks`,{message:t}),A(d(`common.save`,null,`保存`)),S({visible:!1,taskId:``,message:``}),F()}catch(e){w(B(e,b.taskId?d(`tasks.saveTaskFailed`,null,`保存任务失败`):d(`tasks.addTaskFailed`,null,`添加任务失败`)))}},de=t=>j({title:d(`tasks.runSingleTask`,null,`单条执行`),content:d(`tasks.confirmRunSingleTask`,null,`确定执行该任务?仅运行这一条,完成后队列会自动暂停,不会继续执行其他待执行项。`),okText:d(`common.confirm`,null,`确认`),danger:!1,onOk:async()=>{try{await x.post(`/batch-tasks/${e}/tasks/${t.id}/run`),A(d(`tasks.runSingleTask`,null,`单条执行`)),F()}catch(e){w(B(e,d(`tasks.runSingleTaskFailed`,null,`单条执行失败`)))}}}),q=t=>j({title:d(`common.delete`,null,`删除`),content:d(`tasks.confirmDeleteTask`,null,`确定要删除这个任务吗?`),okText:d(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/batch-tasks/${e}/tasks/${t.id}`),A(d(`common.delete`,null,`删除`)),F()}catch(e){w(B(e,d(`tasks.deleteTaskFailed`,null,`删除任务失败`)))}}}),J=e=>!!(r&&M&&e.status!==`running`&&M.status!==`running`&&[`pending`,`paused`,`completed`,`cancelled`].includes(M.status)),fe=[{title:`#`,dataIndex:`id`,width:58,render:(e,t)=>{let n=(M?.tasks||[]).findIndex(e=>e.id===t.id);return(0,V.jsx)(G,{type:`tertiary`,size:`small`,children:n+1})}},{title:d(`tasks.title`,null,`任务`),dataIndex:`message`,render:(e,t)=>(0,V.jsx)(`span`,{className:`task-cell-message`,title:e,children:e||d(`tasks.taskIncomplete`,null,`任务信息不完整`)})},{title:d(`projects.status`,null,`状态`),dataIndex:`status`,width:96,render:e=>(0,V.jsx)(K,{status:e})},{title:d(`tasks.duration`,null,`执行时长`),dataIndex:`startedAt`,width:110,render:(e,t)=>(0,V.jsx)(G,{size:`small`,children:e?z(e,t.completedAt):`—`})},{title:d(`common.actions`,null,`操作`),dataIndex:`id`,width:210,render:(e,t)=>(0,V.jsxs)(o,{spacing:2,wrap:!0,children:[(0,V.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>O({visible:!0,task:t}),children:`结果`}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!r,onClick:()=>W(t),children:d(`common.edit`,null,`编辑`)}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!J(t),title:d(`tasks.runSingleTaskUnavailable`,null,`队列或任务执行中,暂无法单条执行`),onClick:()=>de(t),children:d(`tasks.runSingleTask`,null,`单条执行`)}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!i,onClick:()=>q(t),children:d(`common.delete`,null,`删除`)})]})}],Y=ce(M),X=M?.scheduleMode===`cron`&&M?.scheduleEnabled!==!1;return(0,V.jsxs)(h,{visible:t,width:900,title:M?M.title||M.id:d(`tasks.batchQueueTitle`,null,`批量任务队列`),onCancel:a,children:[(0,V.jsx)(ne,{error:le(k.error),onRetry:()=>k.reload()}),M?(0,V.jsxs)(`div`,{className:`task-detail-stack`,children:[(0,V.jsxs)(`div`,{className:`task-detail-actions`,children:[(0,V.jsxs)(o,{wrap:!0,children:[(0,V.jsx)(l,{type:`primary`,disabled:!r||M.status===`running`,onClick:oe,children:`开始执行`}),(0,V.jsx)(l,{disabled:!r||M.status!==`running`,onClick:se,children:`暂停`}),(0,V.jsx)(l,{disabled:!r||![`completed`,`cancelled`].includes(M.status),onClick:H,children:d(`tasks.retry`,null,`重试`)}),(0,V.jsx)(l,{icon:(0,V.jsx)(g,{}),theme:`borderless`,onClick:()=>k.reload()})]}),(0,V.jsxs)(o,{children:[(0,V.jsx)(l,{icon:(0,V.jsx)(f,{}),disabled:!r,onClick:()=>W(null),children:`添加任务`}),(0,V.jsx)(l,{type:`danger`,disabled:!i,onClick:U,children:d(`tasks.deleteQueue`,null,`删除队列`)})]})]}),(0,V.jsxs)(`div`,{className:`task-progress-block`,children:[(0,V.jsxs)(`div`,{className:`task-progress-head`,children:[(0,V.jsx)(s,{size:`small`,color:Y.color,children:Y.label}),Y.sublabel?(0,V.jsx)(G,{type:`tertiary`,size:`small`,children:Y.sublabel}):null]}),(0,V.jsx)(p,{percent:P.percent,showInfo:!0,stroke:`var(--semi-color-primary)`}),(0,V.jsxs)(`div`,{className:`task-progress-legend`,children:[(0,V.jsxs)(`span`,{children:[d(`tasks.totalLabel`,null,`总计`),` `,P.total]}),(0,V.jsxs)(`span`,{children:[d(`tasks.pendingLabel`,null,`待执行`),` `,P.pending]}),(0,V.jsxs)(`span`,{children:[d(`tasks.runningLabel`,null,`执行中`),` `,P.running]}),(0,V.jsxs)(`span`,{children:[d(`tasks.completedLabel`,null,`已完成`),` `,P.completed]}),(0,V.jsxs)(`span`,{children:[d(`tasks.failedLabel`,null,`失败`),` `,P.failed]}),(0,V.jsxs)(`span`,{children:[d(`tasks.cancelledLabel`,null,`已取消`),` `,P.cancelled]}),(0,V.jsxs)(`span`,{children:[`受阻 `,P.blocked]})]}),(0,V.jsx)(G,{type:`tertiary`,size:`small`,children:X?d(`tasks.cronRunningProgressHint`,null,`本轮执行中;下一整轮仍按 Cron 与「下次执行时间」排程`):d(`tasks.finishedProgressHint`,null,`进度表示已结束的任务比例,包含失败和取消,不表示成功率。`)})]}),(0,V.jsx)(E,{columns:3,items:[{label:d(`tasks.queueIdLabel`,null,`队列ID`),value:(0,V.jsx)(`code`,{children:M.id})},{label:d(`tasks.createdTimeLabel`,null,`创建时间`),value:v(M.createdAt)},{label:`Agent 模式`,value:(I.find(e=>e.value===M.agentMode)||I[0]).label},{label:`角色`,value:M.role||d(`batchImportModal.defaultRole`,null,`默认`)},{label:`项目`,value:M.projectId||`—`},{label:d(`batchImportModal.hitlPolicy`,null,`工具审批`),value:(ae.find(e=>e.value===(M.hitlPolicy||``))||ae[0]).label},{label:d(`batchImportModal.concurrency`,null,`并发数`),value:M.concurrency||1},{label:d(`batchImportModal.scheduleMode`,null,`调度方式`),value:M.scheduleMode===`cron`?`Cron ${M.cronExpr||``}${X?``:`(已关闭)`}`:d(`batchImportModal.scheduleModeManual`,null,`手工执行`)},{label:`下一次执行`,value:M.nextRunAt?v(M.nextRunAt):`—`},M.lastRunError?{label:`最近错误`,value:(0,V.jsx)(G,{type:`danger`,size:`small`,children:M.lastRunError})}:null]}),(0,V.jsx)(ie,{columns:fe,dataSource:M.tasks||[],rowKey:`id`,size:`small`,pagination:{pageSize:10},emptyText:d(`tasks.noValidTask`,null,`没有有效的任务`)})]}):null,(0,V.jsx)(T,{visible:b.visible,title:b.taskId?d(`common.edit`,null,`编辑`):`添加任务`,onCancel:()=>S({visible:!1,taskId:``,message:``}),onOk:ue,okText:d(`common.save`,null,`保存`),cancelText:d(`common.cancel`,null,`取消`),width:620,children:(0,V.jsx)(u,{value:b.message,rows:5,placeholder:d(`batchImportModal.tasksListPlaceholder`,null,`请输入任务列表,每行一个任务`),onChange:e=>S(t=>({...t,message:e}))})}),(0,V.jsx)(T,{visible:D.visible,title:D.task?D.task.message:`结果`,onCancel:()=>O({visible:!1,task:null}),footer:(0,V.jsxs)(o,{children:[D.task?.conversationId?(0,V.jsx)(l,{onClick:()=>{let e=D.task.conversationId;O({visible:!1,task:null}),a?.(),ee(`/chat?conversation=${encodeURIComponent(e)}`)},children:d(`tasks.viewConversation`,null,`查看对话`)}):null,(0,V.jsx)(l,{onClick:()=>O({visible:!1,task:null}),children:d(`common.close`,null,`关闭`)})]}),width:720,children:(0,V.jsxs)(`div`,{className:`task-detail-stack`,children:[(0,V.jsx)(E,{columns:2,items:[{label:d(`projects.status`,null,`状态`),value:(0,V.jsx)(K,{status:D.task?.status})},{label:d(`tasks.startedAt`,null,`开始时间`),value:v(D.task?.startedAt)},{label:d(`tasks.completedAt`,null,`完成时间`),value:v(D.task?.completedAt)},{label:d(`tasks.duration`,null,`执行时长`),value:z(D.task?.startedAt,D.task?.completedAt)},D.task?.conversationId?{label:d(`tasks.conversationIdLabel`,null,`对话ID`),value:(0,V.jsx)(`code`,{children:D.task.conversationId})}:null]}),D.task?.error?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(G,{strong:!0,type:`danger`,children:D.task.status===`blocked`?`受阻原因`:d(`tasks.statusFailed`,null,`执行失败`)}),(0,V.jsx)(`pre`,{className:`task-result-pre`,children:D.task.error})]}):null,D.task?.result?(0,V.jsx)(te,{content:D.task.result}):(0,V.jsx)(G,{type:`tertiary`,children:`暂无结果`})]})})]})}var{Text:q}=a,J={running:{label:`执行中`,color:`blue`},cancelling:{label:`取消中`,color:`amber`},cleaning:{label:`清理中`,color:`amber`}};function fe(){let e=y(),t=n(),r=C(()=>x.get(`/agent-loop/tasks`),[]);re(()=>r.reload({silent:!0}),6e3);let i=Array.isArray(r.data?.tasks)?r.data.tasks:[],a=[{title:e(`tasks.title`,null,`任务`),dataIndex:`title`,render:(t,n)=>(0,V.jsxs)(`div`,{className:`task-live-title`,children:[(0,V.jsx)(`span`,{className:`task-cell-message`,title:t||n.message,children:t||n.message||e(`tasks.unnamedTask`,null,`未命名任务`)}),(0,V.jsx)(q,{type:`tertiary`,size:`small`,children:(0,V.jsx)(`code`,{children:n.runId||`—`})})]})},{title:e(`projects.status`,null,`状态`),dataIndex:`status`,width:110,render:e=>{let t=J[String(e||``)]||{label:e||`—`,color:`blue`};return(0,V.jsx)(s,{size:`small`,color:t.color,children:t.label})}},{title:e(`tasks.conversationIdLabel`,null,`对话ID`),dataIndex:`conversationId`,width:230,render:e=>(0,V.jsx)(q,{type:`tertiary`,size:`small`,children:(0,V.jsx)(`code`,{children:e||`—`})})},{title:e(`tasks.startedAt`,null,`开始时间`),dataIndex:`startedAt`,width:165,render:e=>(0,V.jsx)(q,{size:`small`,children:v(e)})},{title:e(`tasks.duration`,null,`执行时长`),dataIndex:`startedAt`,width:110,render:e=>(0,V.jsx)(q,{size:`small`,children:z(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`conversationId`,width:110,render:n=>(0,V.jsx)(o,{children:(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>t(`/chat?conversation=${encodeURIComponent(n)}`),children:e(`tasks.viewConversation`,null,`查看对话`)})})}];return(0,V.jsxs)(D,{title:`${e(`tasks.runningLabel`,null,`执行中`)}任务(Agent Loop)`,description:`当前进程中正在执行的 Agent 任务;每 6 秒自动刷新。`,extra:(0,V.jsx)(l,{icon:(0,V.jsx)(g,{}),theme:`borderless`,loading:r.loading,onClick:()=>r.reload(),children:e(`common.refresh`,null,`刷新`)}),children:[(0,V.jsx)(ne,{error:le(r.error),onRetry:()=>r.reload()}),(0,V.jsx)(ie,{columns:a,dataSource:i,rowKey:e=>e.runId||e.conversationId||`unknown-task`,loading:r.loading,pagination:{pageSize:10},emptyText:e(`tasks.noMatchingTasks`,null,`当前没有符合条件的任务`)})]})}var{Text:Y}=a;function X(){let e=y(),{hasPermission:t}=b(),n=t(`tasks:write`),r=t(`tasks:delete`),[a,c]=i(),u=a.get(`id`)||``,h=a.get(`tab`)||`queues`,[T,E]=(0,N.useState)(1),[te,M]=(0,N.useState)(10),[P,F]=(0,N.useState)(`all`),[I,ae]=(0,N.useState)(``),L=O(I,300),[z,H]=(0,N.useState)(!1),[U,W]=(0,N.useState)(0),G=C(()=>x.get(`/batch-tasks`,{limit:100,page:1}),[U]),K=C(()=>x.get(`/batch-tasks`,{limit:te,page:T,status:P===`all`?void 0:P,keyword:L.trim()||void 0}),[T,te,P,L,U]),q=Array.isArray(K.data?.queues)?K.data.queues:[],J=K.data?.total??0,X=(0,N.useMemo)(()=>(G.data?.queues||[]).some(e=>e.status===`running`),[G.data]);re(()=>{X&&(G.reload({silent:!0}),K.reload({silent:!0}))},X?5e3:0);let Z=(0,N.useCallback)((e,t)=>{let n=new URLSearchParams(a);e?n.set(`id`,e):n.delete(`id`),t?n.set(`tab`,t):n.delete(`tab`),c(n,{replace:!!e})},[a,c]);(0,N.useEffect)(()=>{h!==`queues`&&h!==`live`&&Z(void 0,`queues`)},[h,Z]);let Q=()=>W(e=>e+1),pe=G.data?.queues||[],$=(0,N.useMemo)(()=>{let e=pe.map(R);return{queues:G.data?.total??pe.length,running:pe.filter(e=>e.status===`running`).length,pendingTasks:e.reduce((e,t)=>e+t.pending,0),failedTasks:e.reduce((e,t)=>e+t.failed,0)}},[pe,G.data]),me=async t=>{try{await x.post(`/batch-tasks/${t.id}/start`),A(`已开始执行`),Q()}catch(t){w(B(t,e(`tasks.startBatchQueueFailed`,null,`启动批量任务失败`)))}},he=t=>j({title:e(`tasks.statusPaused`,null,`已暂停`),content:e(`tasks.pauseQueueConfirm`,null,`确定要暂停这个批量任务队列吗?当前正在执行的任务将被停止,后续任务将保留待执行状态。`),okText:e(`common.confirm`,null,`确认`),onOk:async()=>{try{await x.post(`/batch-tasks/${t.id}/pause`),A(e(`tasks.statusPaused`,null,`已暂停`)),Q()}catch(t){w(B(t,e(`tasks.pauseQueueFailed`,null,`暂停批量任务失败`)))}}}),ge=t=>j({title:e(`tasks.retry`,null,`重试`),content:e(`tasks.rerunQueueConfirm`,null,`确定要重跑一轮吗?所有子任务将被重置为待执行状态并重新开始执行。`),okText:e(`common.confirm`,null,`确认`),onOk:async()=>{try{await x.post(`/batch-tasks/${t.id}/rerun`),A(`已开始重跑`),Q()}catch(t){w(B(t,e(`tasks.rerunQueueFailed`,null,`重跑批量任务失败`)))}}}),_e=t=>j({title:e(`tasks.deleteQueue`,null,`删除队列`),content:e(`tasks.deleteQueueConfirm`,null,`确定要删除这个批量任务队列吗?此操作不可恢复。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/batch-tasks/${t.id}`),A(e(`tasks.deleteQueue`,null,`删除队列`)),u===t.id&&Z(void 0,h),Q()}catch(t){w(B(t,e(`tasks.deleteQueueFailed`,null,`删除批量任务队列失败`)))}}}),ve=[{id:`queues`,label:e(`tasks.batchQueueTitle`,null,`批量任务队列`),value:$.queues,loading:G.loading},{id:`running`,label:e(`tasks.runningLabel`,null,`执行中`),value:$.running,tone:$.running?`success`:void 0,loading:G.loading},{id:`pending`,label:e(`tasks.pendingLabel`,null,`待执行`),value:$.pendingTasks,loading:G.loading},{id:`failed`,label:e(`tasks.failedLabel`,null,`失败`),value:$.failedTasks,tone:$.failedTasks?`danger`:void 0,loading:G.loading}],ye=[{title:e(`batchImportModal.queueTitle`,null,`任务标题`),dataIndex:`title`,render:(t,n)=>{let r=ce(n);return(0,V.jsxs)(`button`,{type:`button`,className:`task-queue-name`,onClick:()=>Z(n.id,`queues`),title:n.id,children:[(0,V.jsx)(`span`,{className:`task-queue-title`,children:t||e(`tasks.batchQueueUntitled`,null,`未命名队列`)}),r.sublabel?(0,V.jsx)(`span`,{className:`task-queue-sub`,children:r.sublabel}):null]})}},{title:e(`projects.status`,null,`状态`),dataIndex:`status`,width:170,render:(e,t)=>{let n=ce(t);return(0,V.jsx)(s,{size:`small`,color:n.color,children:n.label})}},{title:`进度`,dataIndex:`progress`,width:190,render:(e,t)=>{let n=R(t);return(0,V.jsxs)(`div`,{className:`task-queue-progress`,children:[(0,V.jsx)(p,{percent:n.percent,showInfo:!1,size:`small`}),(0,V.jsxs)(Y,{type:`tertiary`,size:`small`,children:[n.percent,`%(`,n.done,`/`,n.total,`)`]})]})}},{title:e(`batchImportModal.agentMode`,null,`代理模式`),dataIndex:`agentMode`,width:150,render:e=>(0,V.jsx)(Y,{size:`small`,children:se(e)})},{title:e(`batchImportModal.scheduleMode`,null,`调度方式`),dataIndex:`scheduleMode`,width:128,render:(t,n)=>(0,V.jsx)(Y,{size:`small`,children:t===`cron`?`Cron · ${n.cronExpr||``}`:e(`batchImportModal.scheduleModeManual`,null,`手工执行`)})},{title:e(`tasks.createdTimeLabel`,null,`创建时间`),dataIndex:`createdAt`,width:160,render:e=>(0,V.jsx)(Y,{type:`tertiary`,size:`small`,children:v(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:250,render:(t,i)=>(0,V.jsxs)(o,{spacing:2,wrap:!0,children:[(0,V.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>Z(i.id,`queues`),children:e(`projects.details`,null,`详情`)}),i.status===`running`?(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>he(i),children:e(`tasks.statusPaused`,null,`已暂停`)}):(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>me(i),children:`开始执行`}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n||![`completed`,`cancelled`].includes(i.status),onClick:()=>ge(i),children:e(`tasks.retry`,null,`重试`)}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!r,onClick:()=>_e(i),children:e(`common.delete`,null,`删除`)})]})}];return(0,V.jsxs)(`div`,{className:`task-page`,children:[(0,V.jsx)(k,{title:e(`tasks.title`,null,`任务管理`),description:e(`tasks.pageDesc`,null,`批量任务队列按并发池执行子任务;队列详情可查看进度、单条执行与结果。`),extra:(0,V.jsxs)(o,{children:[(0,V.jsx)(l,{icon:(0,V.jsx)(g,{}),theme:`borderless`,loading:K.loading,onClick:Q,children:e(`common.refresh`,null,`刷新`)}),(0,V.jsx)(l,{type:`primary`,icon:(0,V.jsx)(f,{}),disabled:!n,onClick:()=>H(!0),children:e(`batchImportModal.title`,null,`新建任务`)})]})}),(0,V.jsx)(ne,{error:le(G.error||K.error),onRetry:Q}),(0,V.jsx)(S,{metrics:ve,columns:4}),(0,V.jsx)(ee,{type:`line`,activeKey:h,onChange:e=>Z(void 0,e),tabList:[{itemKey:`queues`,tab:e(`tasks.batchQueueTitle`,null,`批量任务队列`)},{itemKey:`live`,tab:`${e(`tasks.runningLabel`,null,`执行中`)}任务`}],className:`task-tabs`}),h===`live`?(0,V.jsx)(fe,{}):(0,V.jsxs)(D,{title:e(`tasks.batchQueueTitle`,null,`批量任务队列`),description:e(`tasks.finishedProgressHint`,null,`进度表示已结束的任务比例,包含失败和取消,不表示成功率。`),extra:(0,V.jsx)(Y,{type:`tertiary`,size:`small`,children:e(`tasks.taskCount`,{count:J},`共 ${J} 个任务`)}),children:[(0,V.jsxs)(`div`,{className:`task-toolbar`,children:[(0,V.jsx)(d,{prefix:(0,V.jsx)(m,{}),value:I,showClear:!0,placeholder:e(`batchImportModal.queueTitlePlaceholder`,null,`请输入任务标题(可选,用于标识和筛选)`),onChange:e=>{ae(e),E(1)},style:{width:280}}),(0,V.jsx)(_,{value:P,onChange:e=>{F(e),E(1)},style:{width:150},optionList:oe})]}),(0,V.jsx)(ie,{columns:ye,dataSource:q,rowKey:`id`,loading:K.loading,emptyText:P!==`all`||I?e(`tasks.noMatchingTasks`,null,`当前没有符合条件的任务`):e(`tasks.noBatchQueues`,null,`当前没有批量任务队列`),pagination:{currentPage:T,pageSize:te,total:J,onPageChange:e=>E(e),onPageSizeChange:e=>{M(e),E(1)}}})]}),(0,V.jsx)(ue,{visible:z,onCancel:()=>H(!1),onCreated:e=>{H(!1),Q(),e?.queueId&&Z(e.queueId,`queues`)}}),(0,V.jsx)(de,{queueId:u,visible:!!u,canWrite:n,canDelete:r,onClose:()=>Z(void 0,h),onChanged:Q})]})}export{X as default};
\ No newline at end of file
diff --git a/web/static/app/assets/tool-guard-CjP9k4xW.js b/web/static/app/assets/tool-guard-Dk4HsC4O.js
similarity index 94%
rename from web/static/app/assets/tool-guard-CjP9k4xW.js
rename to web/static/app/assets/tool-guard-Dk4HsC4O.js
index f7f47643..2b2fed54 100644
--- a/web/static/app/assets/tool-guard-CjP9k4xW.js
+++ b/web/static/app/assets/tool-guard-Dk4HsC4O.js
@@ -1 +1 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{$ as r,B as i,G as a,I as o,Lt as s,N as c,R as l,S as u,U as d,d as f,en as p,ft as m,j as h,nn as g,ut as _}from"./semi-65W_4I1v.js";import{F as v,I as y,P as b,b as x,l as S,m as C,p as w,x as T,y as E}from"./index-BdnarFZR.js";var D=e(t(),1),O=200,k=4096;function A(e){return JSON.parse(JSON.stringify(e))}function j(e){if(!e||typeof e.enabled!=`boolean`||e.rules!=null&&!Array.isArray(e.rules))throw Error(`服务端返回的配置格式不正确`);return{enabled:e.enabled,rules:(e.rules||[]).map(e=>({id:String(e.id||``),name:String(e.name||``),enabled:!!e.enabled,pattern:String(e.pattern||``),message:String(e.message||``)}))}}function M(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`rule-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function N(e){return new TextEncoder().encode(String(e||``)).length}function P(e){if(!e)return{index:-1,field:``,message:`请先加载拦截配置`};if(e.rules.length>100)return{index:-1,field:``,message:`最多可配置 100 条拦截规则`};for(let t=0;tO)return{index:t,field:`name`,message:`第 ${t+1} 条规则名称超过 ${O} 字节`};if(N(n.pattern)>k)return{index:t,field:`pattern`,message:`第 ${t+1} 条规则正则超过 ${k} 字节`};if(N(n.message)>k)return{index:t,field:`message`,message:`第 ${t+1} 条规则提醒超过 ${k} 字节`}}return null}function ee(e,t){return!e||!t?!1:JSON.stringify(e)!==JSON.stringify(t)}function F(e){return{enabled:!!e?.enabled,rules:(e?.rules||[]).map(e=>({id:e.id,name:e.name,enabled:!!e.enabled,pattern:e.pattern,message:e.message}))}}function I(e){return{enabled:!0,rules:[{id:e.id,name:e.name,enabled:!0,pattern:e.pattern,message:e.message}]}}var L=e(n(),1),{Text:R}=a,z=`http_request`,B=`{"url": "https://example.gov.cn"}`;function V({config:e,rule:t=null,disabled:n=!1,compact:r=!1}){let a=b(),s=!!t,[f,p]=(0,D.useState)(z),[m,h]=(0,D.useState)(B),[g,_]=(0,D.useState)(!1),[v,x]=(0,D.useState)(null),[C,w]=(0,D.useState)(null),T=async()=>{if(n||g)return;if(w(null),x(null),!s&&!e){w(Error(a(`toolGuard.loadFirst`,null,`请先加载拦截配置`)));return}if(!f.trim()){w(Error(a(`toolGuard.toolRequired`,null,`请填写测试工具名称`)));return}let r;try{if(r=JSON.parse(m),!r||Array.isArray(r)||typeof r!=`object`)throw Error(`not an object`)}catch{w(Error(a(`toolGuard.invalidArguments`,null,`工具参数必须是有效的 JSON 对象`)));return}_(!0);try{let n={config:s?I(t):F(e),toolName:f.trim(),arguments:r},i=await y.post(`/tool-guard/test`,n);if(!i||typeof i.blocked!=`boolean`)throw Error(a(`toolGuard.invalidTestResponse`,null,`服务端返回的测试结果格式不正确`));x(i)}catch(e){w(e)}finally{_(!1)}},E=v?.blocked,O=v?.match,k=!s&&e&&e.enabled===!1;return(0,L.jsxs)(`div`,{className:r?`tool-guard-test tool-guard-test-compact`:`tool-guard-test`,children:[(0,L.jsxs)(o,{vertical:!0,spacing:6,align:`start`,children:[(0,L.jsx)(R,{strong:!0,children:s?a(`toolGuard.testScopeSingle`,{name:t.name||a(`toolGuard.unnamedRule`,null,`未命名规则`)},`单条验证:${t.name||`未命名规则`}`):a(`toolGuard.testScopeAll`,null,`全部规则验证`)}),(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:s?a(`toolGuard.testSingleHint`,null,`仅验证本条规则,忽略总开关和规则启停;不保存、不执行工具。`):a(`toolGuard.testAllHint`,null,`按当前顺序与启停状态验证全部规则,不保存、不执行工具。`)})]}),(0,L.jsxs)(`div`,{className:`tool-guard-test-form`,children:[(0,L.jsxs)(`label`,{className:`tool-guard-field`,children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testTool`,null,`工具名称`)}),(0,L.jsx)(d,{value:f,onChange:e=>{p(e),x(null)},placeholder:`http_request`})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testArguments`,null,`工具参数(JSON 对象)`)}),(0,L.jsx)(u,{value:m,onChange:e=>{h(e),x(null)},rows:3,spellCheck:!1,className:`tool-guard-args`})]})]}),(0,L.jsx)(l,{theme:`solid`,type:`primary`,loading:g,disabled:n,onClick:T,className:`tool-guard-test-run`,children:g?a(`toolGuard.testing`,null,`验证中…`):a(`toolGuard.test`,null,`测试匹配`)}),(0,L.jsx)(S,{error:C}),v&&(0,L.jsxs)(`div`,{className:`tool-guard-test-result ${E?`is-blocked`:`is-pass`}`,children:[(0,L.jsxs)(o,{spacing:8,wrap:!0,children:[(0,L.jsx)(c,{color:E?`red`:k?`grey`:`green`,size:`small`,children:E?`blocked`:`passed`}),(0,L.jsx)(R,{strong:!0,children:s?E?a(`toolGuard.singleMatched`,null,`本条规则匹配成功`):a(`toolGuard.singleNotMatched`,null,`本条规则未匹配`):E?a(`toolGuard.blocked`,null,`已命中规则:将阻止调用`):k?a(`toolGuard.disabledResult`,null,`调用拦截已关闭:此配置不会阻止调用`):a(`toolGuard.notBlocked`,null,`未命中已启用的规则`)})]}),s&&(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.singleResultHint`,null,`这是单条规则验证结果,实际拦截还取决于总开关、规则启停和匹配顺序。`)}),E&&O&&(0,L.jsxs)(`div`,{className:`tool-guard-match`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedRule`,null,`命中规则`)}),(0,L.jsx)(`div`,{children:O.ruleName||O.ruleId||`—`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedText`,null,`匹配文本`)}),(0,L.jsx)(`pre`,{children:O.matchedText||`—`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedMessage`,null,`返回的拦截提醒`)}),(0,L.jsx)(`div`,{children:O.message||`—`})]})]})]}),!v&&!C&&(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testReadyHint`,null,`点击「测试匹配」,在这里查看验证结果。`)}),s===!1&&!v&&!C&&k&&(0,L.jsx)(i,{type:`info`,bordered:!0,closeIcon:null,description:a(`toolGuard.disabledResult`,null,`调用拦截已关闭:此配置不会阻止调用`)})]})}var{Text:H}=a;function U({rule:e,index:t,total:n,canWrite:r,canTest:i,onChange:a,onDelete:c,onMove:m}){let h=b();return(0,L.jsxs)(`div`,{className:`tool-guard-rule-body`,children:[(0,L.jsxs)(`div`,{className:`tool-guard-rule-toolbar`,children:[(0,L.jsxs)(o,{spacing:8,children:[(0,L.jsx)(f,{size:`small`,checked:e.enabled,disabled:!r,onChange:e=>a({enabled:e}),"aria-label":h(`toolGuard.ruleEnabled`,null,`启用`)}),(0,L.jsx)(H,{size:`small`,type:`tertiary`,children:e.enabled?h(`toolGuard.ruleOn`,null,`已启用`):h(`toolGuard.ruleOff`,null,`已停用`)})]}),(0,L.jsxs)(o,{spacing:6,children:[(0,L.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,L.jsx)(p,{}),disabled:!r||t===0,onClick:()=>m(-1),children:h(`toolGuard.moveUp`,null,`上移`)}),(0,L.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,L.jsx)(g,{}),disabled:!r||t===n-1,onClick:()=>m(1),children:h(`toolGuard.moveDown`,null,`下移`)}),(0,L.jsx)(l,{size:`small`,type:`danger`,theme:`borderless`,icon:(0,L.jsx)(s,{}),disabled:!r,onClick:c,children:h(`toolGuard.deleteRule`,null,`删除`)})]})]}),(0,L.jsxs)(`div`,{className:`tool-guard-editor-grid`,children:[(0,L.jsxs)(`label`,{className:`tool-guard-field`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.ruleName`,null,`规则名称`)}),(0,L.jsx)(d,{value:e.name,maxLength:200,disabled:!r,onChange:e=>a({name:e}),placeholder:h(`toolGuard.ruleName`,null,`规则名称`)})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.pattern`,null,`匹配正则(RE2)`)}),(0,L.jsx)(u,{value:e.pattern,rows:3,spellCheck:!1,disabled:!r,onChange:e=>a({pattern:e}),className:`tool-guard-mono`,placeholder:`(?i)(169\\\\.254\\\\.169\\\\.254|metadata\\\\.google\\\\.internal)`})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.message`,null,`拦截提醒`)}),(0,L.jsx)(u,{value:e.message,rows:2,disabled:!r,onChange:e=>a({message:e}),placeholder:h(`toolGuard.defaultPreview`,null,`命中后使用默认拦截提醒`)}),(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.messageHint`,null,`拦截提醒可使用 {match}(匹配文本)、{tool}(工具名称)、{rule}(规则名称)。`)})]})]}),(0,L.jsx)(V,{config:null,rule:e,compact:!0,disabled:!i})]})}var{Text:W}=a;function G(){let e=b(),{hasPermission:t}=v(),n=t(`config:read`),i=t(`config:write`),[a,s]=(0,D.useState)(null),[u,d]=(0,D.useState)(null),[p,g]=(0,D.useState)(``),[O,k]=(0,D.useState)(n),[N,I]=(0,D.useState)(null),[R,z]=(0,D.useState)(null),[B,H]=(0,D.useState)(!1),[G,K]=(0,D.useState)(!1),[q,J]=(0,D.useState)([]),Y=(0,D.useCallback)(async()=>{if(n){k(!0),I(null),K(!1);try{let e=await y.raw(`/tool-guard`),t=e.headers.get(`ETag`)||``,n=j(await e.json());s(n),d(A(n)),g(t)}catch(e){I(e)}finally{k(!1)}}},[n]);(0,D.useEffect)(()=>{Y()},[Y]);let X=(0,D.useMemo)(()=>ee(a,u),[a,u]),Z=a?.rules?.length||0,Q=a?.rules?.filter(e=>e.enabled).length||0,$=()=>{X?E({title:e(`toolGuard.reloadTitle`,null,`重新加载拦截配置`),content:e(`toolGuard.reloadConfirm`,null,`当前有未保存修改,重新加载会丢弃这些修改。确认继续?`),okText:e(`common.confirm`,null,`确定`),onOk:Y}):Y()},te=(e,t)=>{i&&(s(n=>({...n,rules:n.rules.map((n,r)=>r===e?{...n,...t}:n)})),z(null))},ne=()=>{if(!i||!a)return;if(a.rules.length>=100){x(e(`toolGuard.tooManyRules`,null,`最多可配置 100 条拦截规则`));return}let t=M();s(n=>({...n,rules:[...n.rules,{id:t,name:``,enabled:!0,pattern:``,message:e(`toolGuard.defaultMessage`,null,`识别到 {match},调用被规则「{rule}」拦截。请检查目标与操作后重试。`)}]})),J(e=>[...e,t]),z(null)},re=e=>{i&&a&&(s(t=>({...t,rules:t.rules.filter((t,n)=>n!==e)})),z(null))},ie=(e,t)=>{if(!i||!a)return;let n=e+t;n<0||n>=a.rules.length||(s(t=>{let r=[...t.rules],[i]=r.splice(e,1);return r.splice(n,0,i),{...t,rules:r}}),z(null))};return n?(0,L.jsxs)(`div`,{className:`tool-guard-page`,children:[(0,L.jsx)(w,{title:e(`toolGuard.title`,null,`调用拦截`),description:e(`toolGuard.description`,null,`在 MCP 工具执行前检查工具名称和参数,命中规则立即阻止调用。人机协同审批和工具白名单不会跳过此检查。`),extra:(0,L.jsxs)(o,{children:[(0,L.jsx)(c,{size:`small`,color:X?`amber`:`green`,children:B?e(`toolGuard.loading`,null,`处理中…`):X?e(`toolGuard.unsaved`,null,`有未保存修改`):e(`toolGuard.savedState`,null,`已与服务端同步`)}),(0,L.jsx)(l,{onClick:()=>{i&&u&&(s(A(u)),z(null),K(!1))},disabled:!i||!X||B,children:e(`toolGuard.reset`,null,`撤销修改`)}),(0,L.jsx)(l,{icon:(0,L.jsx)(_,{}),onClick:$,loading:O,disabled:B,children:e(`common.refresh`,null,`刷新`)}),(0,L.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,L.jsx)(r,{}),loading:B,disabled:!i||!X,onClick:async()=>{if(!i||!a||!X)return;let t=P(a);if(t){if(z(Error(t.message)),t.index>=0){let e=a.rules[t.index];e&&J(t=>t.includes(e.id)?t:[...t,e.id])}}else if(!p)z(Error(e(`toolGuard.versionRequired`,null,`缺少调用拦截配置版本,请刷新页面后重试。`)));else{H(!0),z(null),K(!1);try{let t=await y.raw(`/tool-guard`,{method:`PUT`,body:F(a),headers:{"If-Match":p}}),n=t.headers.get(`ETag`)||p,r=j(await t.json());s(r),d(A(r)),g(n),T(e(`toolGuard.saveSuccess`,null,`调用拦截配置已保存,后续工具调用将使用新配置。`))}catch(t){let n=t?.payload?.code;n===`tool_guard_conflict`||n===`tool_guard_version_required`?(K(!0),z(Error(t.message))):z(t),x(t,e(`toolGuard.saveFailed`,null,`保存失败`))}finally{H(!1)}}},children:e(`toolGuard.save`,null,`保存并生效`)})]})}),O&&!a&&(0,L.jsx)(C,{title:e(`toolGuard.loading`,null,`处理中…`),children:(0,L.jsx)(W,{type:`tertiary`,children:`…`})}),(0,L.jsx)(S,{error:N,onRetry:Y}),(0,L.jsx)(S,{error:R,onRetry:G?$:void 0}),a&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(C,{title:e(`toolGuard.policyTitle`,null,`拦截策略`),description:e(`toolGuard.enableHint`,null,`在工具执行前检查风险,修改后保存生效。`),children:(0,L.jsxs)(`div`,{className:`tool-guard-policy`,children:[(0,L.jsxs)(o,{spacing:10,align:`center`,children:[(0,L.jsx)(f,{checked:a.enabled,disabled:!i||B,onChange:e=>{s(t=>({...t,enabled:e})),z(null)},"aria-label":e(`toolGuard.enabled`,null,`启用调用拦截`)}),(0,L.jsx)(W,{strong:!0,children:e(`toolGuard.enabled`,null,`启用调用拦截`)}),(0,L.jsx)(c,{size:`small`,color:a.enabled?`green`:`grey`,children:a.enabled?e(`toolGuard.protectionOn`,null,`调用拦截已开启`):e(`toolGuard.protectionOff`,null,`调用拦截已关闭`)}),(0,L.jsx)(c,{size:`small`,color:`blue`,children:e(`toolGuard.ruleCount`,{enabled:Q,total:Z},`${Q} / ${Z} 条规则已启用`)})]}),(0,L.jsx)(W,{type:`tertiary`,size:`small`,children:e(`toolGuard.scopeHint`,null,`正则仅检查调用中可见的文本;不会解析 IP 归属、重定向目标或工具读取的文件内容。`)})]})}),(0,L.jsxs)(C,{title:e(`toolGuard.rulesTitle`,null,`拦截规则`),description:e(`toolGuard.rulesHint`,null,`按顺序匹配已启用的规则,使用首条命中规则的提醒。正则采用 RE2 语法,保存和试运行时由服务端校验。`),extra:(0,L.jsx)(l,{icon:(0,L.jsx)(m,{}),disabled:!i||B||Z>=100,onClick:ne,children:e(`toolGuard.addRule`,null,`添加规则`)}),children:[Z===0&&(0,L.jsx)(W,{type:`tertiary`,children:e(`toolGuard.emptyRules`,null,`暂无规则。添加规则后保存,即可启用对应的拦截措施。`)}),Z>0&&(0,L.jsx)(h,{activeKey:q,onChange:e=>J([].concat(e)),keepDOM:!1,children:a.rules.map((t,n)=>(0,L.jsx)(h.Panel,{itemKey:t.id,header:(0,L.jsxs)(o,{spacing:8,align:`center`,children:[(0,L.jsx)(`span`,{className:`tool-guard-rule-number`,children:String(n+1).padStart(2,`0`)}),(0,L.jsx)(W,{strong:!0,children:t.name.trim()||e(`toolGuard.unnamedRule`,null,`未命名规则`)}),(0,L.jsx)(c,{size:`small`,color:t.enabled?`green`:`grey`,children:t.enabled?e(`toolGuard.ruleOn`,null,`已启用`):e(`toolGuard.ruleOff`,null,`已停用`)}),(()=>{let n=u?.rules?.find(e=>e.id===t.id);return n?JSON.stringify(n)===JSON.stringify(t)?null:(0,L.jsx)(c,{size:`small`,color:`amber`,children:e(`toolGuard.ruleModified`,null,`已修改`)}):(0,L.jsx)(c,{size:`small`,color:`blue`,children:e(`toolGuard.ruleNew`,null,`新增`)})})()]}),children:(0,L.jsx)(U,{rule:t,index:n,total:Z,canWrite:i&&!B,canTest:!B,onChange:e=>te(n,e),onDelete:()=>re(n),onMove:e=>ie(n,e)})},t.id))}),(0,L.jsx)(W,{type:`tertiary`,size:`small`,children:e(`toolGuard.listHint`,null,`点击规则查看和编辑,按列表顺序匹配。`)})]}),(0,L.jsx)(C,{title:e(`toolGuard.testTitle`,null,`全部规则验证`),description:e(`toolGuard.testHint`,null,`使用页面上的当前配置(包括未保存修改),仅检查匹配结果,不执行任何工具。`),children:(0,L.jsx)(V,{config:a,disabled:B})})]})]}):(0,L.jsxs)(`div`,{className:`tool-guard-page`,children:[(0,L.jsx)(w,{title:e(`toolGuard.title`,null,`调用拦截`)}),(0,L.jsx)(S,{error:Error(e(`toolGuard.noPermission`,null,`当前账号缺少 config:read 权限,无法读取拦截配置。`))})]})}export{G as default};
\ No newline at end of file
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{$ as r,B as i,G as a,I as o,Lt as s,N as c,R as l,S as u,U as d,d as f,en as p,ft as m,j as h,nn as g,ut as _}from"./semi-65W_4I1v.js";import{F as v,I as y,L as b,b as x,l as S,m as C,p as w,x as T,y as E}from"./index-_8d9XBPJ.js";var D=e(t(),1),O=200,k=4096;function A(e){return JSON.parse(JSON.stringify(e))}function j(e){if(!e||typeof e.enabled!=`boolean`||e.rules!=null&&!Array.isArray(e.rules))throw Error(`服务端返回的配置格式不正确`);return{enabled:e.enabled,rules:(e.rules||[]).map(e=>({id:String(e.id||``),name:String(e.name||``),enabled:!!e.enabled,pattern:String(e.pattern||``),message:String(e.message||``)}))}}function M(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`rule-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function N(e){return new TextEncoder().encode(String(e||``)).length}function P(e){if(!e)return{index:-1,field:``,message:`请先加载拦截配置`};if(e.rules.length>100)return{index:-1,field:``,message:`最多可配置 100 条拦截规则`};for(let t=0;tO)return{index:t,field:`name`,message:`第 ${t+1} 条规则名称超过 ${O} 字节`};if(N(n.pattern)>k)return{index:t,field:`pattern`,message:`第 ${t+1} 条规则正则超过 ${k} 字节`};if(N(n.message)>k)return{index:t,field:`message`,message:`第 ${t+1} 条规则提醒超过 ${k} 字节`}}return null}function ee(e,t){return!e||!t?!1:JSON.stringify(e)!==JSON.stringify(t)}function F(e){return{enabled:!!e?.enabled,rules:(e?.rules||[]).map(e=>({id:e.id,name:e.name,enabled:!!e.enabled,pattern:e.pattern,message:e.message}))}}function I(e){return{enabled:!0,rules:[{id:e.id,name:e.name,enabled:!0,pattern:e.pattern,message:e.message}]}}var L=e(n(),1),{Text:R}=a,z=`http_request`,B=`{"url": "https://example.gov.cn"}`;function V({config:e,rule:t=null,disabled:n=!1,compact:r=!1}){let a=v(),s=!!t,[f,p]=(0,D.useState)(z),[m,h]=(0,D.useState)(B),[g,_]=(0,D.useState)(!1),[y,x]=(0,D.useState)(null),[C,w]=(0,D.useState)(null),T=async()=>{if(n||g)return;if(w(null),x(null),!s&&!e){w(Error(a(`toolGuard.loadFirst`,null,`请先加载拦截配置`)));return}if(!f.trim()){w(Error(a(`toolGuard.toolRequired`,null,`请填写测试工具名称`)));return}let r;try{if(r=JSON.parse(m),!r||Array.isArray(r)||typeof r!=`object`)throw Error(`not an object`)}catch{w(Error(a(`toolGuard.invalidArguments`,null,`工具参数必须是有效的 JSON 对象`)));return}_(!0);try{let n={config:s?I(t):F(e),toolName:f.trim(),arguments:r},i=await b.post(`/tool-guard/test`,n);if(!i||typeof i.blocked!=`boolean`)throw Error(a(`toolGuard.invalidTestResponse`,null,`服务端返回的测试结果格式不正确`));x(i)}catch(e){w(e)}finally{_(!1)}},E=y?.blocked,O=y?.match,k=!s&&e&&e.enabled===!1;return(0,L.jsxs)(`div`,{className:r?`tool-guard-test tool-guard-test-compact`:`tool-guard-test`,children:[(0,L.jsxs)(o,{vertical:!0,spacing:6,align:`start`,children:[(0,L.jsx)(R,{strong:!0,children:s?a(`toolGuard.testScopeSingle`,{name:t.name||a(`toolGuard.unnamedRule`,null,`未命名规则`)},`单条验证:${t.name||`未命名规则`}`):a(`toolGuard.testScopeAll`,null,`全部规则验证`)}),(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:s?a(`toolGuard.testSingleHint`,null,`仅验证本条规则,忽略总开关和规则启停;不保存、不执行工具。`):a(`toolGuard.testAllHint`,null,`按当前顺序与启停状态验证全部规则,不保存、不执行工具。`)})]}),(0,L.jsxs)(`div`,{className:`tool-guard-test-form`,children:[(0,L.jsxs)(`label`,{className:`tool-guard-field`,children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testTool`,null,`工具名称`)}),(0,L.jsx)(d,{value:f,onChange:e=>{p(e),x(null)},placeholder:`http_request`})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testArguments`,null,`工具参数(JSON 对象)`)}),(0,L.jsx)(u,{value:m,onChange:e=>{h(e),x(null)},rows:3,spellCheck:!1,className:`tool-guard-args`})]})]}),(0,L.jsx)(l,{theme:`solid`,type:`primary`,loading:g,disabled:n,onClick:T,className:`tool-guard-test-run`,children:g?a(`toolGuard.testing`,null,`验证中…`):a(`toolGuard.test`,null,`测试匹配`)}),(0,L.jsx)(S,{error:C}),y&&(0,L.jsxs)(`div`,{className:`tool-guard-test-result ${E?`is-blocked`:`is-pass`}`,children:[(0,L.jsxs)(o,{spacing:8,wrap:!0,children:[(0,L.jsx)(c,{color:E?`red`:k?`grey`:`green`,size:`small`,children:E?`blocked`:`passed`}),(0,L.jsx)(R,{strong:!0,children:s?E?a(`toolGuard.singleMatched`,null,`本条规则匹配成功`):a(`toolGuard.singleNotMatched`,null,`本条规则未匹配`):E?a(`toolGuard.blocked`,null,`已命中规则:将阻止调用`):k?a(`toolGuard.disabledResult`,null,`调用拦截已关闭:此配置不会阻止调用`):a(`toolGuard.notBlocked`,null,`未命中已启用的规则`)})]}),s&&(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.singleResultHint`,null,`这是单条规则验证结果,实际拦截还取决于总开关、规则启停和匹配顺序。`)}),E&&O&&(0,L.jsxs)(`div`,{className:`tool-guard-match`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedRule`,null,`命中规则`)}),(0,L.jsx)(`div`,{children:O.ruleName||O.ruleId||`—`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedText`,null,`匹配文本`)}),(0,L.jsx)(`pre`,{children:O.matchedText||`—`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedMessage`,null,`返回的拦截提醒`)}),(0,L.jsx)(`div`,{children:O.message||`—`})]})]})]}),!y&&!C&&(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testReadyHint`,null,`点击「测试匹配」,在这里查看验证结果。`)}),s===!1&&!y&&!C&&k&&(0,L.jsx)(i,{type:`info`,bordered:!0,closeIcon:null,description:a(`toolGuard.disabledResult`,null,`调用拦截已关闭:此配置不会阻止调用`)})]})}var{Text:H}=a;function U({rule:e,index:t,total:n,canWrite:r,canTest:i,onChange:a,onDelete:c,onMove:m}){let h=v();return(0,L.jsxs)(`div`,{className:`tool-guard-rule-body`,children:[(0,L.jsxs)(`div`,{className:`tool-guard-rule-toolbar`,children:[(0,L.jsxs)(o,{spacing:8,children:[(0,L.jsx)(f,{size:`small`,checked:e.enabled,disabled:!r,onChange:e=>a({enabled:e}),"aria-label":h(`toolGuard.ruleEnabled`,null,`启用`)}),(0,L.jsx)(H,{size:`small`,type:`tertiary`,children:e.enabled?h(`toolGuard.ruleOn`,null,`已启用`):h(`toolGuard.ruleOff`,null,`已停用`)})]}),(0,L.jsxs)(o,{spacing:6,children:[(0,L.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,L.jsx)(p,{}),disabled:!r||t===0,onClick:()=>m(-1),children:h(`toolGuard.moveUp`,null,`上移`)}),(0,L.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,L.jsx)(g,{}),disabled:!r||t===n-1,onClick:()=>m(1),children:h(`toolGuard.moveDown`,null,`下移`)}),(0,L.jsx)(l,{size:`small`,type:`danger`,theme:`borderless`,icon:(0,L.jsx)(s,{}),disabled:!r,onClick:c,children:h(`toolGuard.deleteRule`,null,`删除`)})]})]}),(0,L.jsxs)(`div`,{className:`tool-guard-editor-grid`,children:[(0,L.jsxs)(`label`,{className:`tool-guard-field`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.ruleName`,null,`规则名称`)}),(0,L.jsx)(d,{value:e.name,maxLength:200,disabled:!r,onChange:e=>a({name:e}),placeholder:h(`toolGuard.ruleName`,null,`规则名称`)})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.pattern`,null,`匹配正则(RE2)`)}),(0,L.jsx)(u,{value:e.pattern,rows:3,spellCheck:!1,disabled:!r,onChange:e=>a({pattern:e}),className:`tool-guard-mono`,placeholder:`(?i)(169\\\\.254\\\\.169\\\\.254|metadata\\\\.google\\\\.internal)`})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.message`,null,`拦截提醒`)}),(0,L.jsx)(u,{value:e.message,rows:2,disabled:!r,onChange:e=>a({message:e}),placeholder:h(`toolGuard.defaultPreview`,null,`命中后使用默认拦截提醒`)}),(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.messageHint`,null,`拦截提醒可使用 {match}(匹配文本)、{tool}(工具名称)、{rule}(规则名称)。`)})]})]}),(0,L.jsx)(V,{config:null,rule:e,compact:!0,disabled:!i})]})}var{Text:W}=a;function G(){let e=v(),{hasPermission:t}=y(),n=t(`config:read`),i=t(`config:write`),[a,s]=(0,D.useState)(null),[u,d]=(0,D.useState)(null),[p,g]=(0,D.useState)(``),[O,k]=(0,D.useState)(n),[N,I]=(0,D.useState)(null),[R,z]=(0,D.useState)(null),[B,H]=(0,D.useState)(!1),[G,K]=(0,D.useState)(!1),[q,J]=(0,D.useState)([]),Y=(0,D.useCallback)(async()=>{if(n){k(!0),I(null),K(!1);try{let e=await b.raw(`/tool-guard`),t=e.headers.get(`ETag`)||``,n=j(await e.json());s(n),d(A(n)),g(t)}catch(e){I(e)}finally{k(!1)}}},[n]);(0,D.useEffect)(()=>{Y()},[Y]);let X=(0,D.useMemo)(()=>ee(a,u),[a,u]),Z=a?.rules?.length||0,Q=a?.rules?.filter(e=>e.enabled).length||0,$=()=>{X?E({title:e(`toolGuard.reloadTitle`,null,`重新加载拦截配置`),content:e(`toolGuard.reloadConfirm`,null,`当前有未保存修改,重新加载会丢弃这些修改。确认继续?`),okText:e(`common.confirm`,null,`确定`),onOk:Y}):Y()},te=(e,t)=>{i&&(s(n=>({...n,rules:n.rules.map((n,r)=>r===e?{...n,...t}:n)})),z(null))},ne=()=>{if(!i||!a)return;if(a.rules.length>=100){x(e(`toolGuard.tooManyRules`,null,`最多可配置 100 条拦截规则`));return}let t=M();s(n=>({...n,rules:[...n.rules,{id:t,name:``,enabled:!0,pattern:``,message:e(`toolGuard.defaultMessage`,null,`识别到 {match},调用被规则「{rule}」拦截。请检查目标与操作后重试。`)}]})),J(e=>[...e,t]),z(null)},re=e=>{i&&a&&(s(t=>({...t,rules:t.rules.filter((t,n)=>n!==e)})),z(null))},ie=(e,t)=>{if(!i||!a)return;let n=e+t;n<0||n>=a.rules.length||(s(t=>{let r=[...t.rules],[i]=r.splice(e,1);return r.splice(n,0,i),{...t,rules:r}}),z(null))};return n?(0,L.jsxs)(`div`,{className:`tool-guard-page`,children:[(0,L.jsx)(w,{title:e(`toolGuard.title`,null,`调用拦截`),description:e(`toolGuard.description`,null,`在 MCP 工具执行前检查工具名称和参数,命中规则立即阻止调用。人机协同审批和工具白名单不会跳过此检查。`),extra:(0,L.jsxs)(o,{children:[(0,L.jsx)(c,{size:`small`,color:X?`amber`:`green`,children:B?e(`toolGuard.loading`,null,`处理中…`):X?e(`toolGuard.unsaved`,null,`有未保存修改`):e(`toolGuard.savedState`,null,`已与服务端同步`)}),(0,L.jsx)(l,{onClick:()=>{i&&u&&(s(A(u)),z(null),K(!1))},disabled:!i||!X||B,children:e(`toolGuard.reset`,null,`撤销修改`)}),(0,L.jsx)(l,{icon:(0,L.jsx)(_,{}),onClick:$,loading:O,disabled:B,children:e(`common.refresh`,null,`刷新`)}),(0,L.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,L.jsx)(r,{}),loading:B,disabled:!i||!X,onClick:async()=>{if(!i||!a||!X)return;let t=P(a);if(t){if(z(Error(t.message)),t.index>=0){let e=a.rules[t.index];e&&J(t=>t.includes(e.id)?t:[...t,e.id])}}else if(!p)z(Error(e(`toolGuard.versionRequired`,null,`缺少调用拦截配置版本,请刷新页面后重试。`)));else{H(!0),z(null),K(!1);try{let t=await b.raw(`/tool-guard`,{method:`PUT`,body:F(a),headers:{"If-Match":p}}),n=t.headers.get(`ETag`)||p,r=j(await t.json());s(r),d(A(r)),g(n),T(e(`toolGuard.saveSuccess`,null,`调用拦截配置已保存,后续工具调用将使用新配置。`))}catch(t){let n=t?.payload?.code;n===`tool_guard_conflict`||n===`tool_guard_version_required`?(K(!0),z(Error(t.message))):z(t),x(t,e(`toolGuard.saveFailed`,null,`保存失败`))}finally{H(!1)}}},children:e(`toolGuard.save`,null,`保存并生效`)})]})}),O&&!a&&(0,L.jsx)(C,{title:e(`toolGuard.loading`,null,`处理中…`),children:(0,L.jsx)(W,{type:`tertiary`,children:`…`})}),(0,L.jsx)(S,{error:N,onRetry:Y}),(0,L.jsx)(S,{error:R,onRetry:G?$:void 0}),a&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(C,{title:e(`toolGuard.policyTitle`,null,`拦截策略`),description:e(`toolGuard.enableHint`,null,`在工具执行前检查风险,修改后保存生效。`),children:(0,L.jsxs)(`div`,{className:`tool-guard-policy`,children:[(0,L.jsxs)(o,{spacing:10,align:`center`,children:[(0,L.jsx)(f,{checked:a.enabled,disabled:!i||B,onChange:e=>{s(t=>({...t,enabled:e})),z(null)},"aria-label":e(`toolGuard.enabled`,null,`启用调用拦截`)}),(0,L.jsx)(W,{strong:!0,children:e(`toolGuard.enabled`,null,`启用调用拦截`)}),(0,L.jsx)(c,{size:`small`,color:a.enabled?`green`:`grey`,children:a.enabled?e(`toolGuard.protectionOn`,null,`调用拦截已开启`):e(`toolGuard.protectionOff`,null,`调用拦截已关闭`)}),(0,L.jsx)(c,{size:`small`,color:`blue`,children:e(`toolGuard.ruleCount`,{enabled:Q,total:Z},`${Q} / ${Z} 条规则已启用`)})]}),(0,L.jsx)(W,{type:`tertiary`,size:`small`,children:e(`toolGuard.scopeHint`,null,`正则仅检查调用中可见的文本;不会解析 IP 归属、重定向目标或工具读取的文件内容。`)})]})}),(0,L.jsxs)(C,{title:e(`toolGuard.rulesTitle`,null,`拦截规则`),description:e(`toolGuard.rulesHint`,null,`按顺序匹配已启用的规则,使用首条命中规则的提醒。正则采用 RE2 语法,保存和试运行时由服务端校验。`),extra:(0,L.jsx)(l,{icon:(0,L.jsx)(m,{}),disabled:!i||B||Z>=100,onClick:ne,children:e(`toolGuard.addRule`,null,`添加规则`)}),children:[Z===0&&(0,L.jsx)(W,{type:`tertiary`,children:e(`toolGuard.emptyRules`,null,`暂无规则。添加规则后保存,即可启用对应的拦截措施。`)}),Z>0&&(0,L.jsx)(h,{activeKey:q,onChange:e=>J([].concat(e)),keepDOM:!1,children:a.rules.map((t,n)=>(0,L.jsx)(h.Panel,{itemKey:t.id,header:(0,L.jsxs)(o,{spacing:8,align:`center`,children:[(0,L.jsx)(`span`,{className:`tool-guard-rule-number`,children:String(n+1).padStart(2,`0`)}),(0,L.jsx)(W,{strong:!0,children:t.name.trim()||e(`toolGuard.unnamedRule`,null,`未命名规则`)}),(0,L.jsx)(c,{size:`small`,color:t.enabled?`green`:`grey`,children:t.enabled?e(`toolGuard.ruleOn`,null,`已启用`):e(`toolGuard.ruleOff`,null,`已停用`)}),(()=>{let n=u?.rules?.find(e=>e.id===t.id);return n?JSON.stringify(n)===JSON.stringify(t)?null:(0,L.jsx)(c,{size:`small`,color:`amber`,children:e(`toolGuard.ruleModified`,null,`已修改`)}):(0,L.jsx)(c,{size:`small`,color:`blue`,children:e(`toolGuard.ruleNew`,null,`新增`)})})()]}),children:(0,L.jsx)(U,{rule:t,index:n,total:Z,canWrite:i&&!B,canTest:!B,onChange:e=>te(n,e),onDelete:()=>re(n),onMove:e=>ie(n,e)})},t.id))}),(0,L.jsx)(W,{type:`tertiary`,size:`small`,children:e(`toolGuard.listHint`,null,`点击规则查看和编辑,按列表顺序匹配。`)})]}),(0,L.jsx)(C,{title:e(`toolGuard.testTitle`,null,`全部规则验证`),description:e(`toolGuard.testHint`,null,`使用页面上的当前配置(包括未保存修改),仅检查匹配结果,不执行任何工具。`),children:(0,L.jsx)(V,{config:a,disabled:B})})]})]}):(0,L.jsxs)(`div`,{className:`tool-guard-page`,children:[(0,L.jsx)(w,{title:e(`toolGuard.title`,null,`调用拦截`)}),(0,L.jsx)(S,{error:Error(e(`toolGuard.noPermission`,null,`当前账号缺少 config:read 权限,无法读取拦截配置。`))})]})}export{G as default};
\ No newline at end of file
diff --git a/web/static/app/assets/vulnerabilities-BDm_fRci.js b/web/static/app/assets/vulnerabilities-BDm_fRci.js
new file mode 100644
index 00000000..d7154221
--- /dev/null
+++ b/web/static/app/assets/vulnerabilities-BDm_fRci.js
@@ -0,0 +1,2 @@
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{G as a,I as o,Lt as s,N as c,Ot as l,Pt as u,R as d,U as f,W as p,a as m,c as h,ft as g,h as _,i as v,j as y,lt as b,m as x,p as ee,pt as te,s as ne,ut as re,y as S}from"./semi-65W_4I1v.js";import{C as ie,E as C,F as ae,I as oe,L as w,R as se,S as ce,_ as le,a as ue,b as T,c as E,d as de,f as D,h as O,l as fe,m as pe,n as me,o as k,p as A,s as j,v as he,x as M,y as ge,z as N}from"./index-_8d9XBPJ.js";import{r as _e}from"./retest-EzTZPjnQ.js";import{t as P}from"./project-options-CMQbwv_U.js";var F=e(t(),1),ve=[`critical`,`high`,`medium`,`low`,`info`],I=[`open`,`confirmed`,`fixed`,`ignored`,`false_positive`],ye=[`q`,`severity`,`status`,`archived`,`project_id`,`conversation_tag`,`task_tag`,`assessment_id`],be=[10,20,50,100],xe={critical:`dashboard.severityCritical`,high:`dashboard.severityHigh`,medium:`dashboard.severityMedium`,low:`dashboard.severityLow`,info:`dashboard.severityInfo`},Se={open:`vulnerabilityPage.statusOpen`,confirmed:`vulnerabilityPage.statusConfirmed`,fixed:`vulnerabilityPage.statusFixed`,ignored:`vulnerabilityPage.statusIgnored`,false_positive:`vulnerabilityPage.statusFalsePositive`},Ce={open:`待处理`,confirmed:`已确认`,fixed:`已修复`,ignored:`已忽略`,false_positive:`误报`},L={retest:`复测结果`,retest_started:`复测分支已创建`,merge:`归并上报`,split:`拆分归并组`,detach:`解除关联`},R=[{value:``,key:`vulnerabilityPage.sortDefault`,fallback:`默认顺序`},{value:`severity`,key:`vulnerabilityPage.sortSeverity`,fallback:`高危优先`},{value:`latest`,key:`vulnerabilityPage.sortLatest`,fallback:`创建时间:最新优先`},{value:`oldest`,key:`vulnerabilityPage.sortOldest`,fallback:`创建时间:最早优先`}];function we(e,t){if(!t)return`—`;let n=xe[t];return n?e(n,null,ie[t]||t):String(t)}function z(e,t){if(!t)return`—`;let n=Se[t];return n?e(n,null,Ce[t]||t):String(t)}function Te(e,t){return t?e(`vulnerabilityPage.history_${t}`,null,L[t]||t):`—`}function Ee(e){return ve.map(t=>({value:t,label:we(e,t)}))}function B(e){return I.map(t=>({value:t,label:z(e,t)}))}function De(e){return R.map(t=>({value:t.value,label:e(t.key,null,t.fallback)}))}function Oe(e){let t={};return ye.forEach(n=>{let r=String(e?.[n]??``).trim();r&&(t[n]=r)}),t}function ke(e){let t=Oe(e);return delete t.severity,t}function Ae(e){return ye.some(t=>String(e?.[t]??``).trim()!==``)}function je(e,t){let n=Number(e)||0,r=Number(t)||0;return r>0?Math.round(n/r*100):0}function Me(e){return String(e?.target||``).trim()}function V(e){return(Array.isArray(e?.targets)?e.targets:[]).map(e=>e?.host).find(Boolean)||e?.target_host||e?.target_domain||``}function H(e){if(!e)return`—`;let t=e.host||e.id||`—`;return e.port?`${t}:${e.port}`:t}function U(e,t=8){let n=String(e||``);return n.length>t?`${n.slice(0,t)}…`:n}function Ne(e,t){let n=new Blob([t],{type:`text/markdown;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);return i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3),e}var W=e(r(),1);function G(e,t){return[{value:``,label:e},...t]}function Pe({t:e,filters:t,options:n,projectOptions:r,hasGroupFilters:i,onChange:a,onReset:o}){let s=(0,F.useId)(),[c,l]=(0,F.useState)(t.q),u=me(c,380),p=(0,F.useRef)(t.q);(0,F.useEffect)(()=>{u!==p.current&&(p.current=u,a(`q`,u))},[u,a]),(0,F.useEffect)(()=>{t.q!==p.current&&(p.current=t.q,l(t.q))},[t.q]);let m=Array.isArray(n?.conversation_tags)?n.conversation_tags:[],h=Array.isArray(n?.task_tags)?n.task_tags:[],g=Array.isArray(n?.assessment_ids)?n.assessment_ids:[];return(0,W.jsxs)(`div`,{className:`vulnerability-filter-bar`,children:[(0,W.jsx)(f,{className:`vulnerability-filter-search`,prefix:(0,W.jsx)(b,{}),value:c,showClear:!0,placeholder:e(`vulnerabilityPage.searchKeyword`,null,`搜索标题、描述、类型、目标…`),"aria-label":e(`vulnerabilityPage.searchKeyword`,null,`搜索标题、描述、类型、目标…`),onChange:e=>l(e)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.severity,placeholder:e(`vulnerabilityPage.severity`,null,`严重程度`),optionList:G(e(`vulnerabilityPage.allSeverities`,null,`全部级别`),Ee(e)),onChange:e=>a(`severity`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.status,placeholder:e(`vulnerabilityPage.status`,null,`状态`),optionList:G(e(`dashboard.allStatuses`,null,`全部状态`),B(e)),onChange:e=>a(`status`,e||``)}),(0,W.jsx)(`span`,{id:s,hidden:!0,children:e(`vulnerabilityPage.archiveStatus`,null,`归档状态`)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.archived,"aria-labelledby":s,optionList:[{value:``,label:e(`vulnerabilityPage.unarchived`,null,`未归档`)},{value:`true`,label:e(`projects.statusArchived`,null,`已归档`)},{value:`all`,label:e(`vulnerabilityPage.allArchiveStates`,null,`全部归档状态`)}],onChange:e=>a(`archived`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select vulnerability-filter-select--wide`,value:t.project_id,placeholder:e(`vulnerabilityPage.detailProject`,null,`所属项目`),filter:!0,optionList:G(e(`vulnerabilityPage.allProjects`,null,`全部项目`),r),onChange:e=>a(`project_id`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.conversation_tag,placeholder:e(`vulnerabilityPage.conversationTag`,null,`来源(对话标签)`),filter:!0,optionList:G(e(`vulnerabilityPage.allSources`,null,`全部来源`),m.map(e=>({value:e,label:e}))),onChange:e=>a(`conversation_tag`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.task_tag,placeholder:e(`vulnerabilityPage.taskTag`,null,`任务标签`),filter:!0,optionList:G(e(`vulnerabilityPage.allTaskTags`,null,`全部任务标签`),h.map(e=>({value:e,label:e}))),onChange:e=>a(`task_tag`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.assessment_id,placeholder:e(`vulnerabilityPage.assessmentTask`,null,`深度测评`),filter:!0,optionList:G(e(`vulnerabilityPage.allAssessments`,null,`全部测评`),g.map(e=>({value:e,label:U(e,12)}))),onChange:e=>a(`assessment_id`,e||``)}),(0,W.jsx)(`div`,{className:`vulnerability-filter-actions`,children:(0,W.jsx)(d,{icon:(0,W.jsx)(re,{}),theme:`borderless`,disabled:!Ae(t)&&!t.sort&&!i,onClick:o,children:e(`vulnerabilityPage.clearAll`,null,`重置全部`)})})]})}var{Text:K}=a,Fe={critical:`red`,high:`orange`,medium:`amber`,low:`blue`,info:`grey`};function Ie(e,t){return t.key.startsWith(`task:`)?e(`vulnerabilityPage.viewTaskGroup`,{id:t.label||t.key.slice(5)}):t.label?t.label:t.key.startsWith(`host:`)?e(`vulnerabilityPage.unknownHost`):t.key.startsWith(`queue:`)?e(`vulnerabilityPage.taskQueueGroup`,{id:t.key.slice(6)}):t.key.startsWith(`assessment:`)?t.key.slice(11):e(`vulnerabilityPage.viewNoTask`)}function Le(e,t){let n=Ie(e,t),r=!!t.children?.length;return{key:t.key,value:t.key,label:(0,W.jsxs)(`span`,{className:`vulnerability-group-node`,children:[(0,W.jsx)(`span`,{className:r?`vulnerability-group-name vulnerability-group-name--parent`:`vulnerability-group-name`,title:n,children:n}),(0,W.jsx)(c,{size:`small`,color:`grey`,children:t.count})]}),children:t.children?.map(t=>Le(e,t))}}function Re({t:e,mode:t,groups:n,selection:r,loading:i,search:a,onSearch:o,onSelect:s}){let[c,u]=(0,F.useState)(a),d=t===`task`,h=e(d?`vulnerabilityPage.viewTask`:`vulnerabilityPage.viewHost`),g=e(d?`vulnerabilityPage.taskSearch`:`vulnerabilityPage.hostSearch`),{treeData:_,expandedKeys:v}=(0,F.useMemo)(()=>({treeData:[{key:`all`,value:`all`,label:e(d?`vulnerabilityPage.allTasks`:`vulnerabilityPage.allHosts`)},...n.map(t=>Le(e,t))],expandedKeys:n.filter(e=>e.children?.length).map(e=>e.key)}),[e,n,d]);return(0,F.useEffect)(()=>u(a),[a]),(0,F.useEffect)(()=>{if(c.trim()===a)return;let e=setTimeout(()=>o(c.trim()),350);return()=>clearTimeout(e)},[c,a,o]),(0,W.jsxs)(`aside`,{className:`vulnerability-group-sidebar`,"aria-label":h,children:[(0,W.jsx)(K,{strong:!0,children:h}),(0,W.jsx)(f,{prefix:(0,W.jsx)(b,{}),"aria-label":g,placeholder:g,value:c,showClear:!0,onChange:u}),(0,W.jsxs)(p,{spinning:i,wrapperClassName:`vulnerability-group-scroll`,children:[(0,W.jsx)(m,{"aria-label":h,treeData:_,value:r||`all`,onSelect:e=>s(e===`all`?``:e),expandedKeys:v,expandIcon:({className:e})=>(0,W.jsx)(`span`,{className:e,"aria-hidden":`true`,children:(0,W.jsx)(l,{size:`small`})}),expandAction:!1,blockNode:!0}),!n.length&&!i&&(0,W.jsx)(K,{className:`vulnerability-group-empty`,type:`tertiary`,size:`small`,children:e(`vulnerabilityPage.noMatchingGroups`)})]})]})}function ze({t:e,group:t}){return(0,W.jsxs)(`div`,{className:`vulnerability-group-overview`,children:[(0,W.jsx)(K,{strong:!0,className:`vulnerability-group-name`,children:Ie(e,t)}),(0,W.jsxs)(`div`,{className:`vulnerability-group-badges`,children:[ve.filter(e=>t.severities?.[e]).map(n=>(0,W.jsxs)(c,{color:Fe[n],children:[we(e,n),` `,t.severities[n]]},n)),(0,W.jsx)(c,{color:`grey`,children:e(`vulnerabilityPage.groupPending`,{count:t.pending})})]})]})}var{Text:Be}=a;function Ve({record:e}){let t=[e.conversation_tag,e.task_tag].filter(Boolean);return t.length?(0,W.jsx)(`span`,{className:`vulnerability-source-tags`,children:t.map(e=>(0,W.jsx)(c,{size:`small`,color:`blue`,type:`light`,children:e},e))}):e.conversation_id?(0,W.jsx)(Be,{type:`tertiary`,className:`vulnerability-inline-code`,title:e.conversation_id,children:U(e.conversation_id,10)}):(0,W.jsx)(Be,{type:`tertiary`,children:`—`})}function He({t:e,data:t,loading:n,page:r,pageSize:i,total:a,selection:o,onSelectionChange:s,onOpen:c,onEdit:l,onArchive:u,onDelete:f,onDownload:p,sort:m,onSort:h,canWrite:g,canDelete:_,onPageChange:v,onPageSizeChange:y,toolbar:b,onRefresh:x}){let ee=[{title:e(`vulnerabilityPage.tableTitle`,null,`漏洞名称`),dataIndex:`title`,render:(t,n)=>(0,W.jsxs)(`div`,{className:`vulnerability-title-cell`,children:[(0,W.jsx)(`span`,{className:`vulnerability-title-text`,title:n.title,children:n.title||`—`}),(0,W.jsxs)(`span`,{className:`vulnerability-title-meta`,children:[n.type||`—`,n.case_id?` · ${e(`vulnerabilityPage.mergedRecord`,null,`已归并`)}`:``,n.assessment_id?` · ${e(`vulnerabilityPage.assessmentTask`,null,`深度测评`)}`:``,n.archived?` · ${e(`projects.statusArchived`,null,`已归档`)}`:``]})]})},{title:e(`vulnerabilityPage.tableSeverity`,null,`严重度`),dataIndex:`severity`,width:92,render:e=>(0,W.jsx)(O,{severity:e})},{title:e(`vulnerabilityPage.tableStatus`,null,`状态`),dataIndex:`status`,width:100,render:t=>(0,W.jsx)(he,{status:t,label:z(e,t)})},{title:e(`vulnerabilityPage.detailTarget`,null,`目标 / 宿主`),dataIndex:`target`,width:220,render:(e,t)=>{let n=Me(t),r=Array.isArray(t.targets)&&t.targets.length?t.targets.map(e=>e?.host).filter(Boolean).join(`, `):``;return(0,W.jsxs)(`div`,{className:`vulnerability-target-cell`,children:[(0,W.jsx)(`span`,{className:`vulnerability-target-text`,title:n||r,children:n||r||`—`}),n&&r&&r!==n?(0,W.jsx)(`span`,{className:`vulnerability-target-host`,title:r,children:r}):null]})}},{title:e(`vulnerabilityPage.tableSource`,null,`来源`),dataIndex:`conversation_tag`,width:170,render:(e,t)=>(0,W.jsx)(Ve,{record:t})},{title:e(`vulnerabilityPage.tableDate`,null,`创建时间`),dataIndex:`created_at`,width:180,render:e=>(0,W.jsx)(`span`,{className:`vulnerability-time`,children:C(e)})},{title:e(`vulnerabilityPage.tableActions`,null,`操作`),dataIndex:`id`,width:g?250:200,render:(t,n)=>(0,W.jsxs)(`div`,{className:`vulnerability-row-actions`,children:[(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),c(n.id)},children:e(`vulnerabilityPage.rowView`,null,`详情`)}),(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),p(n)},children:e(`vulnerabilityPage.tableDownload`,null,`下载`)}),g&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),l(n)},children:e(`common.edit`,null,`编辑`)}),g&&!n.project_archived&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),u(n)},children:n.archived?e(`projects.restore`,null,`恢复`):e(`projects.archiveProject`,null,`归档`)}),_&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,onClick:e=>{e.stopPropagation(),f(n)},children:e(`common.delete`,null,`删除`)})]})}],te=b?(0,W.jsxs)(`div`,{className:`vulnerability-table-toolbar`,children:[b,(0,W.jsx)(S,{className:`vulnerability-sort-select`,size:`small`,value:m,optionList:De(e),onChange:e=>h(e||``)})]}):null;return(0,W.jsx)(j,{columns:ee,dataSource:Array.isArray(t)?t:[],loading:n,rowKey:`id`,toolbar:te,onRefresh:x,emptyText:e(`vulnerabilityPage.noRecords`,null,`暂无漏洞记录`),scroll:{x:1200},rowSelection:_?{selectedRowKeys:o,onChange:e=>s(Array.isArray(e)?e:[])}:void 0,onRow:e=>({onClick:t=>{t.target?.closest?.(`button, a, input, label, .semi-checkbox`)||c(e.id)}}),pagination:{currentPage:r,pageSize:i,total:Number(a)||0,showSizeChanger:!0,pageSizeOpts:be,onPageChange:e=>v(Number(e)),onPageSizeChange:e=>y(Number(e))}})}var{Text:Ue}=a,We=2e4;function Ge(e,t){let n=t(`vulnerabilityRetest.defaultPrompt`,null,`请帮我对漏洞 {{vulnerability_id}} 进行验证,确认是否已修复。完成后更新该漏洞状态。`),r=String(e?.retest_notes||``).trim();return r?`${n}\n\n${t(`vulnerabilityRetest.guidanceHeading`,null,`验证方式(来自漏洞记录的复测方式):`)}\n${r}`:n}function Ke({visible:e,vuln:t,onClose:r}){let i=ae(),a=n(),o=(0,F.useId)(),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(null);return(0,F.useEffect)(()=>{u(null)},[e,t?.id]),(0,W.jsxs)(E,{visible:e,width:640,closable:!s,closeOnEsc:!s,onCancel:s?void 0:r,cancelButtonProps:{disabled:s},title:i(`vulnerabilityRetest.title`,null,`复测漏洞`),formId:o,okText:i(`vulnerabilityRetest.confirm`,null,`确认并开始复测`),confirmLoading:s,children:[(0,W.jsx)(Ue,{strong:!0,children:t?.title}),(0,W.jsx)(Ue,{type:`tertiary`,size:`small`,children:i(`vulnerabilityRetest.hint`,null,`每次确认都会从原始对话创建独立分支,继承原项目和历史,可继续多轮验证。`)}),(0,W.jsxs)(v,{id:o,onSubmit:async e=>{if(!s&&t?.id){c(!0),u(null);try{let n=await w.post(`/vulnerabilities/${encodeURIComponent(t.id)}/retest`,{prompt:String(e.prompt||``).trim()});_e(n.conversation.id,n.prompt),r?.(),a(`/chat?conversation=${encodeURIComponent(n.conversation.id)}`)}catch(e){u(e)}finally{c(!1)}}},initValues:{prompt:Ge(t,i)},children:[(0,W.jsx)(v.TextArea,{id:`${o}-prompt`,field:`prompt`,rows:8,maxCount:We,autosize:!0,label:i(`vulnerabilityRetest.promptLabel`,null,`复测提示词`),extraText:i(`vulnerabilityRetest.placeholderHint`,null,`占位符发送时自动替换,也支持在后续对话中手动输入。`),rules:[{required:!0,whitespace:!0,message:i(`vulnerabilityRetest.promptRequired`,null,`请输入复测提示词。`)}]}),(0,W.jsx)(fe,{error:l})]},`${e}-${t?.id||``}`)]})}var{Text:q,Paragraph:J}=a;function Y({title:e,extra:t,children:n}){return(0,W.jsxs)(`section`,{className:`vulnerability-section`,children:[(0,W.jsxs)(`div`,{className:`vulnerability-section-head`,children:[(0,W.jsx)(`span`,{className:`vulnerability-section-title`,children:e}),t]}),(0,W.jsx)(`div`,{className:`vulnerability-section-body`,children:n})]})}function X({vulnerability:e}){let t=n(),[r,i]=(0,F.useState)([]);return(0,F.useEffect)(()=>{if(!e?.project_id||!e?.id){i([]);return}let t=!1;return w.get(`/projects/${e.project_id}/facts`,{related_vulnerability_id:e.id,limit:20}).then(e=>{t||i(Array.isArray(e)?e:[])}).catch(()=>{t||i([])}),()=>{t=!0}},[e?.project_id,e?.id]),r.length?(0,W.jsx)(Y,{title:`同一项目事实`,children:r.map(e=>(0,W.jsxs)(`div`,{className:`vulnerability-history-item`,children:[(0,W.jsx)(q,{children:e.summary||e.fact_key}),e.source_conversation_id?(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>t(`/chat?conversation=${encodeURIComponent(e.source_conversation_id)}`),children:`打开来源会话`}):null]},e.id))}):null}function Z({title:e,content:t,code:n}){let r=String(t??``).trim();return r?n?(0,W.jsx)(Y,{title:e,extra:(0,W.jsx)(k,{text:r,size:`small`}),children:(0,W.jsx)(`pre`,{className:`vulnerability-code`,children:r})}):(0,W.jsx)(Y,{title:e,children:(0,W.jsx)(D,{content:r})}):null}function qe({visible:e,vulnId:t,refreshKey:r,onClose:i,onEdit:a,onArchive:l,onDelete:f,onOpenVuln:m,canWrite:g,canDelete:v,t:b,projectNames:S}){let ie=n(),[ae,oe]=(0,F.useState)(`overview`),[ce,le]=(0,F.useState)(`docx`),[E,D]=(0,F.useState)(!1),[pe,me]=(0,F.useState)(!1),k=ue(()=>w.get(`/vulnerabilities/${encodeURIComponent(t)}/context`),[t,r,e],{skip:!e||!t});(0,F.useEffect)(()=>{oe(`overview`),le(`docx`)},[t]);let A=k.data?.vulnerability?.id===t?k.data:null,j=A?.vulnerability||null,ge=Array.isArray(A?.history)?A.history:[],N=Array.isArray(A?.members)?A.members:[],_e=Array.isArray(A?.assets)?A.assets:[],P=j?.project_id?S?.[j.project_id]||j.project_id:``,ve=e=>{e&&ie(`/chat?conversation=${encodeURIComponent(e)}`)},I=async()=>{if(j&&!E){D(!0);try{let e=await se(`/vulnerabilities/${encodeURIComponent(j.id)}/download`,{query:{format:ce}});M(`${b(`vulnerabilityPage.downloadOkTitle`,null,`下载成功`)}${e?` · ${e}`:``}`)}catch(e){T(e,b(`vulnerabilityPage.downloadFailed`,null,`下载失败`))}finally{D(!1)}}},ye=j?[{label:b(`vulnerabilityPage.detailVulnId`,null,`漏洞ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.id})},{label:b(`vulnerabilityPage.tableSeverity`,null,`严重度`),value:(0,W.jsx)(O,{severity:j.severity})},{label:b(`vulnerabilityPage.status`,null,`状态`),value:(0,W.jsx)(he,{status:j.status,label:z(b,j.status)})},j.type?{label:b(`vulnerabilityPage.detailType`,null,`类型`),value:j.type}:null,j.target?{label:b(`vulnerabilityPage.detailTarget`,null,`目标`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.target})}:null,V(j)&&V(j)!==j.target?{label:b(`vulnerabilityPage.detailHost`,null,`宿主`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:V(j)})}:null,{label:b(`vulnerabilityPage.detailProject`,null,`所属项目`),value:P||b(`vulnerabilityPage.projectUnbound`,null,`未绑定项目`)},j.conversation_tag?{label:b(`vulnerabilityPage.detailConversationTag`,null,`对话标签`),value:j.conversation_tag}:null,j.conversation_id?{label:b(`vulnerabilityPage.detailConversationId`,null,`会话ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.conversation_id})}:null,j.task_tag?{label:b(`vulnerabilityPage.detailTaskTag`,null,`任务标签`),value:j.task_tag}:null,j.task_id?{label:b(`vulnerabilityPage.detailTaskId`,null,`任务ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.task_id})}:null,j.task_queue_id?{label:b(`vulnerabilityPage.detailTaskQueueId`,null,`任务队列ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.task_queue_id})}:null,j.case_id?{label:b(`vulnerabilityPage.mergedRecord`,null,`已归并`),value:j.case_title||U(j.case_id,12)}:null,j.assessment_id?{label:b(`vulnerabilityPage.assessmentTask`,null,`深度测评`),value:j.assessment_name||U(j.assessment_id,12)}:null,{label:b(`vulnerabilityMd.labelCreated`,null,`创建时间`),value:C(j.created_at)},{label:b(`vulnerabilityMd.labelUpdated`,null,`更新时间`),value:C(j.updated_at)}].filter(Boolean):[],be=Array.isArray(j?.targets)?j.targets:[];return(0,W.jsxs)(ee,{className:`vulnerability-detail-drawer`,visible:e,onCancel:i,width:720,title:(0,W.jsxs)(`div`,{className:`vulnerability-drawer-title`,children:[(0,W.jsx)(`span`,{className:`vulnerability-drawer-title-text`,title:j?.title,children:j?.title||b(`vulnerabilityPage.inspectorTitle`,null,`漏洞工作台`)}),j&&(0,W.jsxs)(`span`,{className:`vulnerability-drawer-meta`,children:[(0,W.jsx)(O,{severity:j.severity}),(0,W.jsx)(he,{status:j.status,label:z(b,j.status)}),j.archived&&(0,W.jsx)(c,{size:`small`,color:`grey`,children:j.project_archived?b(`vulnerabilityPage.archivedWithProject`,null,`随项目归档`):b(`projects.statusArchived`,null,`已归档`)}),j.type?(0,W.jsx)(q,{type:`tertiary`,children:j.type}):null]})]}),footer:(0,W.jsxs)(o,{wrap:!0,children:[(0,W.jsx)(d,{onClick:i,children:b(`common.close`,null,`关闭`)}),(0,W.jsx)(d,{icon:(0,W.jsx)(re,{}),onClick:()=>k.reload(),loading:k.loading,children:b(`common.refresh`,null,`刷新`)}),g&&(0,W.jsx)(d,{theme:`solid`,type:`primary`,icon:(0,W.jsx)(te,{}),disabled:!j||!j.conversation_id,onClick:()=>me(!0),children:b(`vulnerabilityRetest.button`,null,`复测`)}),g&&(0,W.jsx)(d,{icon:(0,W.jsx)(u,{}),disabled:!j,onClick:()=>a(j),children:b(`common.edit`,null,`编辑`)}),g&&j&&!j.project_archived&&(0,W.jsx)(d,{onClick:()=>l(j),children:j.archived?b(`projects.restore`,null,`恢复`):b(`projects.archiveProject`,null,`归档`)}),v&&(0,W.jsx)(d,{type:`danger`,icon:(0,W.jsx)(s,{}),disabled:!j,onClick:()=>f(j),children:b(`common.delete`,null,`删除`)})]}),children:[(0,W.jsx)(fe,{error:k.error,onRetry:k.reload}),!k.error&&!j&&(0,W.jsx)(`div`,{className:`vulnerability-drawer-loading`,children:(0,W.jsx)(p,{size:`large`})}),j&&(0,W.jsxs)(h,{type:`line`,activeKey:ae,onChange:e=>oe(e),children:[(0,W.jsxs)(h.TabPane,{tab:b(`vulnerabilityPage.inspector_overview`,null,`概览`),itemKey:`overview`,children:[(0,W.jsx)(de,{items:ye,columns:2}),j.fingerprint?(0,W.jsx)(Z,{title:b(`vulnerabilityPage.fingerprint`,null,`确定性指纹`),content:j.fingerprint,code:!0}):null,j.quality?(0,W.jsx)(Z,{title:b(`vulnerabilityPage.qualityReview`,null,`五维对抗复核`),content:[`可达性:${j.quality.reachability||`—`}`,`前置条件:${j.quality.preconditions||`—`}`,`可复现性:${j.quality.reproducibility||`—`}`,`范围:${j.quality.scope||`—`}`,`影响:${j.quality.impact||`—`}`,`对照组可达:${j.quality.control_reachable?`是`:`否`}`,`机理已失效:${j.quality.mechanism_invalid?`是`:`否`}`,j.quality.blocked_by?`受阻:${j.quality.blocked_by}`:``].filter(Boolean).join(`
+`)}):null,(0,W.jsx)(Z,{title:b(`vulnerabilityMd.headingDescription`,null,`描述`),content:j.description}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailImpact`,null,`影响`),content:j.impact}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailRecommendation`,null,`修复建议`),content:j.recommendation})]}),(0,W.jsxs)(h.TabPane,{tab:b(`vulnerabilityPage.inspector_evidence`,null,`复现与证据`),itemKey:`evidence`,children:[(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailPreconditions`,null,`前置条件`),content:j.preconditions}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailReproductionSteps`,null,`复现步骤`),content:j.reproduction_steps}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailEvidence`,null,`证据 / POC`),content:j.evidence,code:!0}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailRetestNotes`,null,`复测方式`),content:j.retest_notes}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailRetestLog`,null,`复测记录`),content:j.retest_log,code:!0}),(0,W.jsx)(X,{vulnerability:j}),(0,W.jsx)(Y,{title:b(`vulnerabilityPage.inspector_history`,null,`处置历史`),children:ge.length?(0,W.jsx)(ne,{children:ge.map((e,t)=>(0,W.jsx)(ne.Item,{time:C(e.created_at),type:e.kind===`retest`?`success`:`default`,children:(0,W.jsxs)(`div`,{className:`vulnerability-history-item`,children:[(0,W.jsxs)(`div`,{className:`vulnerability-history-head`,children:[(0,W.jsx)(q,{strong:!0,children:Te(b,e.kind)}),e.status?(0,W.jsx)(he,{status:e.status,label:z(b,e.status)}):null,e.actor?(0,W.jsx)(q,{type:`tertiary`,children:e.actor}):null]}),e.evidence?(0,W.jsx)(`pre`,{className:`vulnerability-code`,children:e.evidence}):null,e.snapshot?(0,W.jsx)(y,{className:`vulnerability-snapshot`,children:(0,W.jsxs)(y.Panel,{header:b(`vulnerabilityPage.retestSnapshot`,null,`复测时的证据快照`),itemKey:`snapshot`,children:[(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailReproductionSteps`,null,`复现步骤`),content:e.snapshot.reproduction_steps}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailEvidence`,null,`证据 / POC`),content:e.snapshot.evidence,code:!0})]})}):null,e.conversation_id?(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>ve(e.conversation_id),children:b(`vulnerabilityPage.openRetestChat`,null,`打开复测对话`)}):null]})},`${e.kind}-${e.created_at}-${t}`))}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.noHistory`,null,`暂无结构化处置记录`)})})]}),(0,W.jsxs)(h.TabPane,{tab:b(`vulnerabilityPage.detailRelations`,null,`关联`),itemKey:`relations`,children:[(0,W.jsx)(Y,{title:b(`vulnerabilityPage.detailProject`,null,`所属项目`),children:j.project_id?(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(q,{children:P}),(0,W.jsx)(q,{type:`tertiary`,className:`vulnerability-inline-code`,children:j.project_id})]}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.projectUnbound`,null,`未绑定项目`)})}),(0,W.jsx)(Y,{title:b(`vulnerabilityPage.affectedTargets`,null,`受影响目标`),children:be.length?(0,W.jsx)(`ul`,{className:`vulnerability-related-list`,children:be.map(e=>(0,W.jsxs)(`li`,{className:`vulnerability-related-item`,children:[(0,W.jsx)(q,{strong:!0,children:e.host||e.domain||e.raw}),e.raw&&e.raw!==e.host?(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:e.raw}):null]},`${e.raw}-${e.host}`))}):(0,W.jsx)(J,{type:`tertiary`,children:j.target||`—`})}),(0,W.jsx)(Y,{title:b(`vulnerabilityPage.linkedAssets`,null,`资产库匹配`),children:_e.length?(0,W.jsx)(`ul`,{className:`vulnerability-related-list`,children:_e.map(e=>(0,W.jsxs)(`li`,{className:`vulnerability-related-item`,children:[(0,W.jsx)(q,{strong:!0,children:H(e)}),(0,W.jsx)(q,{type:`tertiary`,className:`vulnerability-inline-code`,children:U(e.id,12)})]},e.id||`${e.host}-${e.port}`))}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.noLinkedAssets`,null,`未匹配到资产库记录`)})}),(0,W.jsxs)(Y,{title:b(`vulnerabilityPage.detailConversationId`,null,`会话`),children:[j.conversation_id?(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.conversation_id}),(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>ve(j.conversation_id),children:b(`vulnerabilityPage.openConversation`,null,`查看对话`)})]}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.standaloneRecord`,null,`独立记录(无关联会话)`)}),j.task_id||j.task_queue_id?(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(q,{type:`tertiary`,children:b(`vulnerabilityPage.detailTaskId`,null,`任务ID`)}),(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.task_id||j.task_queue_id})]}):null]}),j.assessment_id?(0,W.jsx)(Y,{title:b(`vulnerabilityPage.assessmentTask`,null,`深度测评`),children:(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(q,{children:j.assessment_name||U(j.assessment_id,12)}),j.assessment_step_title?(0,W.jsx)(q,{type:`tertiary`,children:j.assessment_step_title}):null]})}):null,N.length?(0,W.jsx)(Y,{title:j.case_title||b(`vulnerabilityPage.mergedRecord`,null,`已归并`),children:(0,W.jsx)(`div`,{className:`vulnerability-member-list`,children:N.map(e=>(0,W.jsxs)(d,{size:`small`,theme:`borderless`,disabled:e.id===j.id,onClick:()=>m(e.id),children:[e.title,` · `,z(b,e.status)]},e.id))})}):null]}),(0,W.jsx)(h.TabPane,{tab:b(`vulnerabilityDownload.title`,null,`下载报告`),itemKey:`download`,children:(0,W.jsxs)(`div`,{className:`vulnerability-download-panel`,children:[(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityDownload.hint`,null,`请选择下载格式`)}),(0,W.jsxs)(_,{value:ce,onChange:e=>le(e.target.value),children:[(0,W.jsx)(x,{value:`docx`,children:b(`vulnerabilityDownload.word`,null,`Word(.docx)`)}),(0,W.jsx)(x,{value:`md`,children:b(`vulnerabilityDownload.markdown`,null,`Markdown(.md)`)})]}),(0,W.jsx)(d,{theme:`solid`,type:`primary`,loading:E,onClick:I,children:b(`vulnerabilityDownload.download`,null,`下载漏洞报告`)}),(0,W.jsx)(q,{type:`tertiary`,children:b(`vulnerabilityPage.downloadHint`,null,`报告由服务端按当前记录生成,包含描述、证据与修复建议。`)})]})})]}),(0,W.jsx)(Ke,{visible:pe,vuln:j,onClose:()=>me(!1)})]})}var{Text:Q}=a,Je={title:``,severity:``,status:`open`,type:``,target:``,project_id:``,conversation_id:``,conversation_tag:``,task_tag:``,description:``,preconditions:``,reproduction_steps:``,evidence:``,impact:``,recommendation:``,retest_notes:``};function Ye(e){return e?{title:e.title||``,severity:e.severity||``,status:e.status||`open`,type:e.type||``,target:e.target||``,project_id:e.project_id||``,conversation_id:e.conversation_id||``,conversation_tag:e.conversation_tag||``,task_tag:e.task_tag||``,description:e.description||``,preconditions:e.preconditions||``,reproduction_steps:e.reproduction_steps||``,evidence:e.evidence||``,impact:e.impact||``,recommendation:e.recommendation||``,retest_notes:e.retest_notes||``}:{...Je}}function $(e){return String(e??``).trim()}function Xe({visible:e,vulnId:t,t:n,projects:r,onClose:i,onSaved:a}){let o=!!t,[s,c]=(0,F.useState)(null),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(null),[m,h]=(0,F.useState)({...Je}),[g,_]=(0,F.useState)(``);(0,F.useEffect)(()=>{if(!e)return;if(f(null),!t){_(``);return}let n=!1;return w.get(`/vulnerabilities/${encodeURIComponent(t)}`).then(e=>{n||(h(Ye(e)),_(t))}).catch(e=>{n||f(e)}),()=>{n=!0}},[e,t]);let y=!o||g===t,b=o?m:{...Je},x=P(r,n,{currentId:b.project_id}),ee=async()=>{if(!s||l)return;let e;try{e=await s.validate()}catch{return}let r={title:$(e.title),severity:e.severity,status:e.status||`open`,type:$(e.type),target:$(e.target),description:e.description||``,preconditions:e.preconditions||``,reproduction_steps:e.reproduction_steps||``,evidence:e.evidence||``,impact:e.impact||``,recommendation:e.recommendation||``,retest_notes:e.retest_notes||``,project_id:$(e.project_id),conversation_tag:$(e.conversation_tag),task_tag:$(e.task_tag)};o||(r.conversation_id=$(e.conversation_id)),u(!0);try{let e=o?await w.put(`/vulnerabilities/${encodeURIComponent(t)}`,r):await w.post(`/vulnerabilities`,r);a?.(e)}catch(e){T(e,n(`vulnerabilityPage.saveFailed`,null,`保存失败`))}finally{u(!1)}};return(0,W.jsx)(E,{title:o?n(`vulnerability.editVuln`,null,`编辑漏洞`):n(`vulnerability.addVuln`,null,`添加漏洞`),visible:e,onCancel:i,onOk:ee,confirmLoading:l,okText:n(`common.save`,null,`保存`),cancelText:n(`common.cancel`,null,`取消`),width:780,children:e?d?(0,W.jsx)(Q,{type:`danger`,children:N(d,n(`vulnerabilityPage.fetchFailed`,null,`获取漏洞失败`))}):y?(0,W.jsx)(v,{initValues:b,getFormApi:c,labelPosition:`top`,onSubmit:ee,children:(0,W.jsxs)(`div`,{className:`vulnerability-form-grid`,children:[(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.Input,{field:`title`,label:n(`vulnerabilityModal.title`,null,`标题`),placeholder:n(`vulnerabilityModal.titlePlaceholder`,null,`/api/login 存在 SQL 注入`),rules:[{required:!0,message:n(`vulnerabilityModal.titleRequired`,null,`请填写漏洞标题`)}],maxLength:500})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Select,{field:`severity`,label:n(`vulnerabilityModal.severity`,null,`严重程度`),placeholder:n(`vulnerabilityModal.pleaseSelect`,null,`请选择`),style:{width:`100%`},optionList:Ee(n),rules:[{required:!0,message:n(`vulnerabilityModal.severityRequired`,null,`请选择严重程度`)}]})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Select,{field:`status`,label:n(`vulnerabilityModal.status`,null,`状态`),style:{width:`100%`},optionList:B(n)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`target`,label:n(`vulnerabilityModal.target`,null,`目标`),placeholder:n(`vulnerabilityModal.targetPlaceholder`,null,`精确到 URL/IP:端口/接口路径/参数名`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`type`,label:n(`vulnerabilityModal.type`,null,`漏洞类型`),placeholder:n(`vulnerabilityModal.typePlaceholder`,null,`如:SQL注入、XSS、CSRF等`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Select,{field:`project_id`,label:n(`vulnerabilityModal.project`,null,`所属项目`),placeholder:n(`vulnerabilityModal.projectNone`,null,`(未绑定)`),style:{width:`100%`},filter:!0,optionList:[{value:``,label:n(`vulnerabilityModal.projectNone`,null,`(未绑定)`)},...x]})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`conversation_id`,label:n(`vulnerabilityModal.conversationId`,null,`会话ID`),placeholder:n(`vulnerabilityModal.conversationIdPlaceholder`,null,`可选:输入已有会话ID,留空可独立添加漏洞`),disabled:o})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`conversation_tag`,label:n(`vulnerabilityModal.conversationTag`,null,`对话标签`),placeholder:n(`vulnerabilityModal.conversationTagPlaceholder`,null,`如:红队演练A、客户A周报`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`task_tag`,label:n(`vulnerabilityModal.taskTag`,null,`任务标签`),placeholder:n(`vulnerabilityModal.taskTagPlaceholder`,null,`如:批量扫描Q2、专项复测`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`description`,label:n(`vulnerabilityModal.description`,null,`描述`),placeholder:n(`vulnerabilityModal.descriptionPlaceholder`,null,`说明漏洞摘要、触发点、异常现象和为什么可被利用。`),autosize:{minRows:3,maxRows:8}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`preconditions`,label:n(`vulnerabilityModal.preconditions`,null,`前置条件`),placeholder:n(`vulnerabilityModal.preconditionsPlaceholder`,null,`登录状态、权限、账号、Header/Cookie、特定数据、环境/版本;无则写无。`),autosize:{minRows:2,maxRows:6}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`reproduction_steps`,label:n(`vulnerabilityModal.reproductionSteps`,null,`复现步骤`),placeholder:n(`vulnerabilityModal.reproductionStepsPlaceholder`,null,`按 1/2/3 编号,写清入口、参数、payload、执行命令、观察点。`),autosize:{minRows:3,maxRows:10}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`evidence`,label:n(`vulnerabilityModal.evidence`,null,`证据 / POC`),placeholder:n(`vulnerabilityModal.evidencePlaceholder`,null,`原始请求/响应、curl/工具命令、截图说明、日志、回连记录等。`),autosize:{minRows:3,maxRows:10}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`impact`,label:n(`vulnerabilityModal.impact`,null,`影响`),placeholder:n(`vulnerabilityModal.impactPlaceholder`,null,`结合已验证事实说明实际影响,例如越权读取哪些数据。`),autosize:{minRows:2,maxRows:6}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`recommendation`,label:n(`vulnerabilityModal.recommendation`,null,`修复建议`),placeholder:n(`vulnerabilityModal.recommendationPlaceholder`,null,`写具体修复点和复测标准。`),autosize:{minRows:2,maxRows:8}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`retest_notes`,label:n(`vulnerabilityModal.retestNotes`,null,`复测方式`),placeholder:n(`vulnerabilityModal.retestNotesPlaceholder`,null,`修复后如何验证漏洞已关闭,包括应返回的状态码、错误信息或访问控制结果。`),autosize:{minRows:2,maxRows:6}})})]})},o?`${t}-${g}`:`new`):(0,W.jsx)(`div`,{className:`vulnerability-modal-loading`,children:(0,W.jsx)(p,{size:`large`})}):null})}var{Text:Ze}=a,Qe={none:`viewList`,host:`viewHost`,task:`viewTask`},$e=[];function et(){let e=ae(),{hasPermission:t}=oe(),[n,r]=i(),a=(0,F.useMemo)(()=>({q:n.get(`q`)||``,severity:n.get(`severity`)||``,status:n.get(`status`)||``,archived:[`true`,`all`].includes(n.get(`archived`))?n.get(`archived`):``,project_id:n.get(`project_id`)||``,conversation_tag:n.get(`conversation_tag`)||``,task_tag:n.get(`task_tag`)||``,assessment_id:n.get(`assessment_id`)||``,sort:[`severity`,`latest`,`oldest`].includes(n.get(`sort`))?n.get(`sort`):``}),[n]),o=Math.max(1,Number.parseInt(n.get(`page`)||`1`,10)||1),s=be.includes(Number(n.get(`page_size`)))?Number(n.get(`page_size`)):20,c=(n.get(`id`)||``).trim(),l=n.get(`group_by`),u=l===`host`||l===`task`?l:``,f=u&&n.get(`selection`)||``,p=u===`task`?`task_q`:`host_q`,m=u&&n.get(p)||``,h=m?{[p]:m}:{},v=t(`vulnerability:write`),y=t(`vulnerability:delete`)||v,b=(0,F.useCallback)((e,t={})=>{r(n=>{let r=new URLSearchParams(n);return Object.entries(e).forEach(([e,t])=>{t==null||t===``?r.delete(e):r.set(e,String(t))}),t.resetPage&&r.delete(`page`),r.toString()===n.toString()?n:r},{replace:!0})},[r]),x=(0,F.useCallback)((e,t)=>{b({[e]:t},{resetPage:!0})},[b]),ee=(0,F.useCallback)(()=>{let e={sort:void 0,selection:void 0,host_q:void 0,task_q:void 0};ye.forEach(t=>{e[t]=void 0}),b(e,{resetPage:!0})},[b]),te=(0,F.useCallback)(e=>{b({group_by:e===`none`?void 0:e,selection:void 0,host_q:void 0,task_q:void 0},{resetPage:!0})},[b]),ne=(0,F.useCallback)(e=>{b({selection:e},{resetPage:!0})},[b]),S=(0,F.useCallback)(e=>{b({[p]:e,selection:void 0},{resetPage:!0})},[p,b]),ie=(0,F.useCallback)(e=>b({id:e}),[b]),C=(0,F.useCallback)(()=>b({id:void 0}),[b]),E={...Oe(a),...h,...u?{group_by:u,pagination:`records`,selection:f}:{},...a.sort?{sort:a.sort}:{},summary:`true`,page:o,limit:s},de=JSON.stringify(E),D=ue(async()=>({...await w.get(`/vulnerabilities`,E)||{},__requestKey:de,__groupView:u}),[de]),O=D.data?.__requestKey===de?D.data:null,me=D.data?.__groupView===u&&D.data?.navigation||$e,k=O?.selection?me.flatMap(e=>[e,...e.children||[]]).find(e=>e.key===O.selection):null,j=(0,F.useMemo)(()=>ke(a),[a]),he=JSON.stringify(j),N=ue(()=>w.get(`/vulnerabilities/stats`,j),[he]),[_e,P]=(0,F.useState)(0),I=ue(()=>w.get(`/vulnerabilities/filter-options`,a.archived?{archived:a.archived}:{}),[_e,a.archived]),xe=ue(async()=>{try{let e=await w.get(`/projects`,{limit:500});return Array.isArray(e?.projects)?e.projects:[]}catch{return[]}},[]),Se=(0,F.useMemo)(()=>{let e={};return(xe.data||[]).forEach(t=>{t?.id&&(e[t.id]=t.name||t.id)}),e},[xe.data]),Ce=(0,F.useMemo)(()=>{let e=new Map;return(I.data?.project_ids||[]).forEach(t=>{t&&e.set(t,Se[t]||t)}),a.project_id&&!e.has(a.project_id)&&e.set(a.project_id,Se[a.project_id]||a.project_id),[...e.entries()].map(([e,t])=>({value:e,label:t}))},[I.data,Se,a.project_id]),[L,R]=(0,F.useState)([]),[z,Te]=(0,F.useState)({visible:!1,id:``}),[Ee,B]=(0,F.useState)(0),[De,Me]=(0,F.useState)(!1);(0,F.useEffect)(()=>{R([])},[de]),(0,F.useEffect)(()=>{if(!O)return;let e={},t=Number(O.page);t&&t!==o&&(e.page=t),f&&!O.selection&&(e.selection=void 0),Object.keys(e).length&&b(e)},[O,f,o,b]);let V=D.reload,H=N.reload,U=I.reload,G=(0,F.useCallback)(()=>{V(),H(),U({silent:!0})},[V,H,U]),K=(0,F.useCallback)(e=>{Te({visible:!0,id:e?.id||``})},[]),Fe=(0,F.useCallback)(()=>{Te({visible:!1,id:``}),M(e(`vulnerabilityPage.saveSuccess`,null,`已保存`)),B(e=>e+1),P(e=>e+1),V({silent:!0}),H({silent:!0})},[V,H,e]),Ie=(0,F.useCallback)(async t=>{try{await w.put(`/vulnerabilities/${encodeURIComponent(t.id)}/archive`,{archived:!t.archived}),M(e(`vulnerabilityPage.saveSuccess`,null,`已保存`)),R(e=>e.filter(e=>e!==t.id)),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}catch(t){T(t,e(`vulnerabilityPage.archiveFailed`,null,`更新归档状态失败`))}},[V,H,e]),Le=(0,F.useCallback)(t=>{t?.id&&ge({title:e(`vulnerabilityPage.deleteTitle`,null,`删除漏洞`),content:`${e(`vulnerability.deleteConfirm`,null,`确定要删除此漏洞吗?`)}${t.title?` ${t.title}`:``}`,okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await w.del(`/vulnerabilities/${encodeURIComponent(t.id)}`),M(e(`vulnerabilityPage.deleteSuccess`,null,`已删除`)),c===t.id&&C(),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}catch(t){T(t,e(`vulnerabilityPage.deleteFailed`,null,`删除失败`))}}})},[c,C,V,H,e]),Be=(0,F.useCallback)(()=>{if(!L.length)return;let t=[...L];ge({title:e(`vulnerabilityPage.batchDelete`,null,`批量删除`),content:e(`vulnerabilityPage.batchDeleteConfirm`,{count:t.length},`确定要删除选中的 ${t.length} 条漏洞吗?此操作不可恢复。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{let n=0,r=0;for(let e of t)try{await w.del(`/vulnerabilities/${encodeURIComponent(e)}`),n+=1}catch{r+=1}r?ce(e(`vulnerabilityPage.batchDeletePartial`,{deleted:n,failed:r},`已删除 ${n} 条,${r} 条失败`)):M(e(`vulnerabilityPage.batchDeleteSuccess`,{count:n},`成功删除 ${n} 条漏洞`)),R([]),t.includes(c)&&C(),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}})},[L,c,C,V,H,e]),Ve=(0,F.useCallback)(async()=>{let t=Oe(a);try{let n=await w.get(`/vulnerabilities`,{...t,page:1,limit:1}),r=Number(n?.total)||0;if(!r){ce(e(`vulnerabilityPage.batchDeleteNoResults`,null,`当前筛选条件下没有可删除的漏洞`));return}ge({title:e(`vulnerabilityPage.deleteFilteredTitle`,null,`删除当前筛选结果`),content:e(`vulnerabilityPage.batchDeleteConfirm`,{count:r},`确定要删除当前筛选条件下的 ${r} 条漏洞吗?此操作不可恢复。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{let n=await w.del(`/vulnerabilities/batch`,{query:t}),i=Number(n?.deleted)||r;M(e(`vulnerabilityPage.batchDeleteSuccess`,{count:i},`成功删除 ${i} 条漏洞`)),R([]),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}catch(t){T(t,e(`vulnerabilityPage.batchDeleteFailed`,null,`批量删除失败`))}}})}catch(t){T(t,e(`vulnerabilityPage.fetchFailed`,null,`获取漏洞失败`))}},[a,V,H,e]),Ue=(0,F.useCallback)(async()=>{if(!De){Me(!0);try{let t=await w.get(`/vulnerabilities/export`,{...Oe(a),...h,mode:`summary`,group_by:`conversation`}),n=Array.isArray(t?.files)?t.files:[];if(!n.length){ce(e(`vulnerabilityPage.exportNoResults`,null,`当前筛选条件下无可导出漏洞`));return}n.forEach((e,t)=>{setTimeout(()=>Ne(e.filename||`vulnerability-export-${t+1}.md`,e.content||``),t*120)}),M(n.length>1?e(`vulnerabilityPage.exportStarted`,{count:n.length},`已开始下载 ${n.length} 份报告`):e(`vulnerabilityPage.exportSuccess`,null,`报告已开始下载`))}catch(t){T(t,e(`vulnerabilityPage.exportFailed`,null,`导出失败`))}finally{Me(!1)}}},[De,a,h,e]),We=(0,F.useCallback)(async t=>{try{let n=await se(`/vulnerabilities/${encodeURIComponent(t.id)}/download`,{query:{format:`docx`}});M(`${e(`vulnerabilityPage.downloadOkTitle`,null,`下载成功`)}${n?` · ${n}`:``}`)}catch(t){T(t,e(`vulnerabilityPage.downloadFailed`,null,`下载失败`))}},[e]),Ge=(0,F.useCallback)(e=>{b({page:String(e)})},[b]),Ke=(0,F.useCallback)(e=>{if(!e||e===s)return;let t=Math.max(1,Math.floor((o-1)*s/e)+1);b({page_size:String(e),page:String(t)})},[o,s,b]),q=N.data||{},J=q.by_severity||{},Y=Number(q.total)||0,X=Number(q.distinct)||0,Z=(0,F.useMemo)(()=>[{id:`total`,label:e(`vulnerabilityPage.statTotal`,null,`总漏洞数`),value:Y,detail:X&&X!==Y?e(`vulnerabilityPage.distinctCount`,{count:X},`${X} 个独立漏洞`):void 0,loading:N.loading,onClick:()=>x(`severity`,``)},...ve.map(t=>{let n=Number(J[t])||0,r=je(n,Y),i=a.severity===t;return{id:t,label:we(e,t),value:n,severity:t,pressed:i,detail:i?`${e(`vulnerabilityPage.filterActive`,null,`已筛选`)} · ${r}%`:`${r}%`,loading:N.loading,onClick:()=>x(`severity`,i?``:t)}})],[e,Y,X,J,N.loading,a.severity,x]),Q=Number(O?.total)||0,Je=Q?(o-1)*s+1:0,Ye=Q?Math.min(o*s,Q):0,$=Q?e(`vulnerabilityPage.recordPagination`,{start:Je,end:Ye,total:Q},`显示 ${Je}–${Ye} / 共 ${Q} 条漏洞`):e(`vulnerabilityPage.noRecords`,null,`暂无漏洞记录`),et=D.error||N.error||I.error,tt=(0,W.jsxs)(`div`,{className:`vulnerability-toolbar-left`,children:[(0,W.jsx)(Ze,{type:`tertiary`,children:O&&L.length?e(`vulnerabilityPage.selectedCount`,{count:L.length},`已选 ${L.length} 项`):$}),y&&(0,W.jsx)(d,{size:`small`,type:`danger`,theme:`light`,disabled:!O||!L.length,onClick:Be,children:e(`vulnerabilityPage.batchDelete`,null,`批量删除`)}),y&&!f&&!m&&Ae(a)&&(0,W.jsx)(d,{size:`small`,type:`danger`,theme:`borderless`,onClick:Ve,children:e(`vulnerabilityPage.deleteFiltered`,null,`删除筛选结果`)})]});return(0,W.jsxs)(`div`,{className:`vulnerability-page`,children:[(0,W.jsx)(A,{title:e(`vulnerability.title`,null,`漏洞管理`),description:e(`vulnerabilityPage.workspaceSubtitle`,null,`资产、上报与处置进展`),extra:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(d,{icon:(0,W.jsx)(re,{}),onClick:G,loading:D.loading,children:e(`common.refresh`,null,`刷新`)}),(0,W.jsx)(d,{onClick:Ue,loading:De,children:e(f?`vulnerabilityPage.exportAllGroups`:`vulnerabilityPage.batchExport`)}),v&&(0,W.jsx)(d,{theme:`solid`,type:`primary`,icon:(0,W.jsx)(g,{}),onClick:()=>K(null),children:e(`vulnerability.addVuln`,null,`添加漏洞`)})]})}),(0,W.jsx)(le,{metrics:Z,columns:6}),(0,W.jsx)(fe,{error:et,onRetry:G}),(0,W.jsxs)(pe,{className:`vulnerability-list-card`,title:e(`vulnerabilityPage.listTitle`,null,`漏洞记录`),extra:(0,W.jsx)(_,{"aria-label":e(`vulnerabilityPage.viewLabel`),type:`button`,value:u||`none`,options:Object.entries(Qe).map(([t,n])=>({value:t,label:e(`vulnerabilityPage.${n}`)})),onChange:e=>te(e.target.value)}),children:[(0,W.jsx)(Pe,{t:e,filters:a,options:I.data,projectOptions:Ce,hasGroupFilters:!!(f||m),onChange:x,onReset:ee}),(0,W.jsxs)(`div`,{className:u?`vulnerability-group-layout`:void 0,children:[u&&(0,W.jsx)(Re,{t:e,mode:u,groups:me,selection:f,search:m,loading:D.loading,onSearch:S,onSelect:ne},u),(0,W.jsxs)(`div`,{className:`vulnerability-group-results`,children:[k&&(0,W.jsx)(ze,{t:e,group:k}),(0,W.jsx)(He,{t:e,data:O?.vulnerabilities,loading:D.loading,page:o,pageSize:s,total:Q,selection:O?L:[],onSelectionChange:R,onOpen:ie,onEdit:K,onArchive:Ie,onDelete:Le,onDownload:We,sort:a.sort,onSort:e=>x(`sort`,e),canWrite:v,canDelete:y,onPageChange:Ge,onPageSizeChange:Ke,toolbar:tt,onRefresh:G})]})]})]}),(0,W.jsx)(qe,{visible:!!c,vulnId:c,refreshKey:Ee,onClose:C,onOpenVuln:ie,onEdit:K,onArchive:Ie,onDelete:Le,canWrite:v,canDelete:y,t:e,projectNames:Se}),(0,W.jsx)(Xe,{visible:z.visible,vulnId:z.id,t:e,projects:xe.data,onClose:()=>Te({visible:!1,id:``}),onSaved:Fe})]})}export{et as default};
\ No newline at end of file
diff --git a/web/static/app/assets/vulnerabilities-Cp2H761l.js b/web/static/app/assets/vulnerabilities-Cp2H761l.js
deleted file mode 100644
index 15704410..00000000
--- a/web/static/app/assets/vulnerabilities-Cp2H761l.js
+++ /dev/null
@@ -1,2 +0,0 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{G as a,I as o,Lt as s,N as c,Ot as l,Pt as u,R as d,U as f,W as p,a as m,c as h,ft as g,h as _,i as v,j as y,lt as b,m as x,p as ee,pt as te,s as ne,ut as re,y as S}from"./semi-65W_4I1v.js";import{C as ie,E as C,F as ae,I as w,L as oe,P as se,R as ce,S as le,_ as ue,a as de,b as T,c as E,d as D,f as O,h as fe,l as pe,m as me,n as k,o as A,p as j,s as he,v as M,x as N,y as ge}from"./index-BdnarFZR.js";import{r as _e}from"./retest-EzTZPjnQ.js";import{t as P}from"./project-options-CMQbwv_U.js";var F=e(t(),1),ve=[`critical`,`high`,`medium`,`low`,`info`],I=[`open`,`confirmed`,`fixed`,`ignored`,`false_positive`],ye=[`q`,`severity`,`status`,`archived`,`project_id`,`conversation_tag`,`task_tag`,`assessment_id`],be=[10,20,50,100],xe={critical:`dashboard.severityCritical`,high:`dashboard.severityHigh`,medium:`dashboard.severityMedium`,low:`dashboard.severityLow`,info:`dashboard.severityInfo`},Se={open:`vulnerabilityPage.statusOpen`,confirmed:`vulnerabilityPage.statusConfirmed`,fixed:`vulnerabilityPage.statusFixed`,ignored:`vulnerabilityPage.statusIgnored`,false_positive:`vulnerabilityPage.statusFalsePositive`},Ce={open:`待处理`,confirmed:`已确认`,fixed:`已修复`,ignored:`已忽略`,false_positive:`误报`},L={retest:`复测结果`,retest_started:`复测分支已创建`,merge:`归并上报`,split:`拆分归并组`,detach:`解除关联`},R=[{value:``,key:`vulnerabilityPage.sortDefault`,fallback:`默认顺序`},{value:`severity`,key:`vulnerabilityPage.sortSeverity`,fallback:`高危优先`},{value:`latest`,key:`vulnerabilityPage.sortLatest`,fallback:`创建时间:最新优先`},{value:`oldest`,key:`vulnerabilityPage.sortOldest`,fallback:`创建时间:最早优先`}];function we(e,t){if(!t)return`—`;let n=xe[t];return n?e(n,null,ie[t]||t):String(t)}function z(e,t){if(!t)return`—`;let n=Se[t];return n?e(n,null,Ce[t]||t):String(t)}function Te(e,t){return t?e(`vulnerabilityPage.history_${t}`,null,L[t]||t):`—`}function Ee(e){return ve.map(t=>({value:t,label:we(e,t)}))}function B(e){return I.map(t=>({value:t,label:z(e,t)}))}function De(e){return R.map(t=>({value:t.value,label:e(t.key,null,t.fallback)}))}function Oe(e){let t={};return ye.forEach(n=>{let r=String(e?.[n]??``).trim();r&&(t[n]=r)}),t}function ke(e){let t=Oe(e);return delete t.severity,t}function Ae(e){return ye.some(t=>String(e?.[t]??``).trim()!==``)}function je(e,t){let n=Number(e)||0,r=Number(t)||0;return r>0?Math.round(n/r*100):0}function Me(e){return String(e?.target||``).trim()}function V(e){return(Array.isArray(e?.targets)?e.targets:[]).map(e=>e?.host).find(Boolean)||e?.target_host||e?.target_domain||``}function H(e){if(!e)return`—`;let t=e.host||e.id||`—`;return e.port?`${t}:${e.port}`:t}function U(e,t=8){let n=String(e||``);return n.length>t?`${n.slice(0,t)}…`:n}function Ne(e,t){let n=new Blob([t],{type:`text/markdown;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);return i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3),e}var W=e(r(),1);function G(e,t){return[{value:``,label:e},...t]}function Pe({t:e,filters:t,options:n,projectOptions:r,hasGroupFilters:i,onChange:a,onReset:o}){let s=(0,F.useId)(),[c,l]=(0,F.useState)(t.q),u=k(c,380),p=(0,F.useRef)(t.q);(0,F.useEffect)(()=>{u!==p.current&&(p.current=u,a(`q`,u))},[u,a]),(0,F.useEffect)(()=>{t.q!==p.current&&(p.current=t.q,l(t.q))},[t.q]);let m=Array.isArray(n?.conversation_tags)?n.conversation_tags:[],h=Array.isArray(n?.task_tags)?n.task_tags:[],g=Array.isArray(n?.assessment_ids)?n.assessment_ids:[];return(0,W.jsxs)(`div`,{className:`vulnerability-filter-bar`,children:[(0,W.jsx)(f,{className:`vulnerability-filter-search`,prefix:(0,W.jsx)(b,{}),value:c,showClear:!0,placeholder:e(`vulnerabilityPage.searchKeyword`,null,`搜索标题、描述、类型、目标…`),"aria-label":e(`vulnerabilityPage.searchKeyword`,null,`搜索标题、描述、类型、目标…`),onChange:e=>l(e)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.severity,placeholder:e(`vulnerabilityPage.severity`,null,`严重程度`),optionList:G(e(`vulnerabilityPage.allSeverities`,null,`全部级别`),Ee(e)),onChange:e=>a(`severity`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.status,placeholder:e(`vulnerabilityPage.status`,null,`状态`),optionList:G(e(`dashboard.allStatuses`,null,`全部状态`),B(e)),onChange:e=>a(`status`,e||``)}),(0,W.jsx)(`span`,{id:s,hidden:!0,children:e(`vulnerabilityPage.archiveStatus`,null,`归档状态`)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.archived,"aria-labelledby":s,optionList:[{value:``,label:e(`vulnerabilityPage.unarchived`,null,`未归档`)},{value:`true`,label:e(`projects.statusArchived`,null,`已归档`)},{value:`all`,label:e(`vulnerabilityPage.allArchiveStates`,null,`全部归档状态`)}],onChange:e=>a(`archived`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select vulnerability-filter-select--wide`,value:t.project_id,placeholder:e(`vulnerabilityPage.detailProject`,null,`所属项目`),filter:!0,optionList:G(e(`vulnerabilityPage.allProjects`,null,`全部项目`),r),onChange:e=>a(`project_id`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.conversation_tag,placeholder:e(`vulnerabilityPage.conversationTag`,null,`来源(对话标签)`),filter:!0,optionList:G(e(`vulnerabilityPage.allSources`,null,`全部来源`),m.map(e=>({value:e,label:e}))),onChange:e=>a(`conversation_tag`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.task_tag,placeholder:e(`vulnerabilityPage.taskTag`,null,`任务标签`),filter:!0,optionList:G(e(`vulnerabilityPage.allTaskTags`,null,`全部任务标签`),h.map(e=>({value:e,label:e}))),onChange:e=>a(`task_tag`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.assessment_id,placeholder:e(`vulnerabilityPage.assessmentTask`,null,`深度测评`),filter:!0,optionList:G(e(`vulnerabilityPage.allAssessments`,null,`全部测评`),g.map(e=>({value:e,label:U(e,12)}))),onChange:e=>a(`assessment_id`,e||``)}),(0,W.jsx)(`div`,{className:`vulnerability-filter-actions`,children:(0,W.jsx)(d,{icon:(0,W.jsx)(re,{}),theme:`borderless`,disabled:!Ae(t)&&!t.sort&&!i,onClick:o,children:e(`vulnerabilityPage.clearAll`,null,`重置全部`)})})]})}var{Text:K}=a,Fe={critical:`red`,high:`orange`,medium:`amber`,low:`blue`,info:`grey`};function Ie(e,t){return t.key.startsWith(`task:`)?e(`vulnerabilityPage.viewTaskGroup`,{id:t.label||t.key.slice(5)}):t.label?t.label:t.key.startsWith(`host:`)?e(`vulnerabilityPage.unknownHost`):t.key.startsWith(`queue:`)?e(`vulnerabilityPage.taskQueueGroup`,{id:t.key.slice(6)}):t.key.startsWith(`assessment:`)?t.key.slice(11):e(`vulnerabilityPage.viewNoTask`)}function Le(e,t){let n=Ie(e,t),r=!!t.children?.length;return{key:t.key,value:t.key,label:(0,W.jsxs)(`span`,{className:`vulnerability-group-node`,children:[(0,W.jsx)(`span`,{className:r?`vulnerability-group-name vulnerability-group-name--parent`:`vulnerability-group-name`,title:n,children:n}),(0,W.jsx)(c,{size:`small`,color:`grey`,children:t.count})]}),children:t.children?.map(t=>Le(e,t))}}function Re({t:e,mode:t,groups:n,selection:r,loading:i,search:a,onSearch:o,onSelect:s}){let[c,u]=(0,F.useState)(a),d=t===`task`,h=e(d?`vulnerabilityPage.viewTask`:`vulnerabilityPage.viewHost`),g=e(d?`vulnerabilityPage.taskSearch`:`vulnerabilityPage.hostSearch`),{treeData:_,expandedKeys:v}=(0,F.useMemo)(()=>({treeData:[{key:`all`,value:`all`,label:e(d?`vulnerabilityPage.allTasks`:`vulnerabilityPage.allHosts`)},...n.map(t=>Le(e,t))],expandedKeys:n.filter(e=>e.children?.length).map(e=>e.key)}),[e,n,d]);return(0,F.useEffect)(()=>u(a),[a]),(0,F.useEffect)(()=>{if(c.trim()===a)return;let e=setTimeout(()=>o(c.trim()),350);return()=>clearTimeout(e)},[c,a,o]),(0,W.jsxs)(`aside`,{className:`vulnerability-group-sidebar`,"aria-label":h,children:[(0,W.jsx)(K,{strong:!0,children:h}),(0,W.jsx)(f,{prefix:(0,W.jsx)(b,{}),"aria-label":g,placeholder:g,value:c,showClear:!0,onChange:u}),(0,W.jsxs)(p,{spinning:i,wrapperClassName:`vulnerability-group-scroll`,children:[(0,W.jsx)(m,{"aria-label":h,treeData:_,value:r||`all`,onSelect:e=>s(e===`all`?``:e),expandedKeys:v,expandIcon:({className:e})=>(0,W.jsx)(`span`,{className:e,"aria-hidden":`true`,children:(0,W.jsx)(l,{size:`small`})}),expandAction:!1,blockNode:!0}),!n.length&&!i&&(0,W.jsx)(K,{className:`vulnerability-group-empty`,type:`tertiary`,size:`small`,children:e(`vulnerabilityPage.noMatchingGroups`)})]})]})}function ze({t:e,group:t}){return(0,W.jsxs)(`div`,{className:`vulnerability-group-overview`,children:[(0,W.jsx)(K,{strong:!0,className:`vulnerability-group-name`,children:Ie(e,t)}),(0,W.jsxs)(`div`,{className:`vulnerability-group-badges`,children:[ve.filter(e=>t.severities?.[e]).map(n=>(0,W.jsxs)(c,{color:Fe[n],children:[we(e,n),` `,t.severities[n]]},n)),(0,W.jsx)(c,{color:`grey`,children:e(`vulnerabilityPage.groupPending`,{count:t.pending})})]})]})}var{Text:Be}=a;function Ve({record:e}){let t=[e.conversation_tag,e.task_tag].filter(Boolean);return t.length?(0,W.jsx)(`span`,{className:`vulnerability-source-tags`,children:t.map(e=>(0,W.jsx)(c,{size:`small`,color:`blue`,type:`light`,children:e},e))}):e.conversation_id?(0,W.jsx)(Be,{type:`tertiary`,className:`vulnerability-inline-code`,title:e.conversation_id,children:U(e.conversation_id,10)}):(0,W.jsx)(Be,{type:`tertiary`,children:`—`})}function He({t:e,data:t,loading:n,page:r,pageSize:i,total:a,selection:o,onSelectionChange:s,onOpen:c,onEdit:l,onArchive:u,onDelete:f,onDownload:p,sort:m,onSort:h,canWrite:g,canDelete:_,onPageChange:v,onPageSizeChange:y,toolbar:b,onRefresh:x}){let ee=[{title:e(`vulnerabilityPage.tableTitle`,null,`漏洞名称`),dataIndex:`title`,render:(t,n)=>(0,W.jsxs)(`div`,{className:`vulnerability-title-cell`,children:[(0,W.jsx)(`span`,{className:`vulnerability-title-text`,title:n.title,children:n.title||`—`}),(0,W.jsxs)(`span`,{className:`vulnerability-title-meta`,children:[n.type||`—`,n.case_id?` · ${e(`vulnerabilityPage.mergedRecord`,null,`已归并`)}`:``,n.assessment_id?` · ${e(`vulnerabilityPage.assessmentTask`,null,`深度测评`)}`:``,n.archived?` · ${e(`projects.statusArchived`,null,`已归档`)}`:``]})]})},{title:e(`vulnerabilityPage.tableSeverity`,null,`严重度`),dataIndex:`severity`,width:92,render:e=>(0,W.jsx)(fe,{severity:e})},{title:e(`vulnerabilityPage.tableStatus`,null,`状态`),dataIndex:`status`,width:100,render:t=>(0,W.jsx)(M,{status:t,label:z(e,t)})},{title:e(`vulnerabilityPage.detailTarget`,null,`目标 / 宿主`),dataIndex:`target`,width:220,render:(e,t)=>{let n=Me(t),r=Array.isArray(t.targets)&&t.targets.length?t.targets.map(e=>e?.host).filter(Boolean).join(`, `):``;return(0,W.jsxs)(`div`,{className:`vulnerability-target-cell`,children:[(0,W.jsx)(`span`,{className:`vulnerability-target-text`,title:n||r,children:n||r||`—`}),n&&r&&r!==n?(0,W.jsx)(`span`,{className:`vulnerability-target-host`,title:r,children:r}):null]})}},{title:e(`vulnerabilityPage.tableSource`,null,`来源`),dataIndex:`conversation_tag`,width:170,render:(e,t)=>(0,W.jsx)(Ve,{record:t})},{title:e(`vulnerabilityPage.tableDate`,null,`创建时间`),dataIndex:`created_at`,width:180,render:e=>(0,W.jsx)(`span`,{className:`vulnerability-time`,children:C(e)})},{title:e(`vulnerabilityPage.tableActions`,null,`操作`),dataIndex:`id`,width:g?250:200,render:(t,n)=>(0,W.jsxs)(`div`,{className:`vulnerability-row-actions`,children:[(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),c(n.id)},children:e(`vulnerabilityPage.rowView`,null,`详情`)}),(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),p(n)},children:e(`vulnerabilityPage.tableDownload`,null,`下载`)}),g&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),l(n)},children:e(`common.edit`,null,`编辑`)}),g&&!n.project_archived&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),u(n)},children:n.archived?e(`projects.restore`,null,`恢复`):e(`projects.archiveProject`,null,`归档`)}),_&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,onClick:e=>{e.stopPropagation(),f(n)},children:e(`common.delete`,null,`删除`)})]})}],te=b?(0,W.jsxs)(`div`,{className:`vulnerability-table-toolbar`,children:[b,(0,W.jsx)(S,{className:`vulnerability-sort-select`,size:`small`,value:m,optionList:De(e),onChange:e=>h(e||``)})]}):null;return(0,W.jsx)(he,{columns:ee,dataSource:Array.isArray(t)?t:[],loading:n,rowKey:`id`,toolbar:te,onRefresh:x,emptyText:e(`vulnerabilityPage.noRecords`,null,`暂无漏洞记录`),scroll:{x:1200},rowSelection:_?{selectedRowKeys:o,onChange:e=>s(Array.isArray(e)?e:[])}:void 0,onRow:e=>({onClick:t=>{t.target?.closest?.(`button, a, input, label, .semi-checkbox`)||c(e.id)}}),pagination:{currentPage:r,pageSize:i,total:Number(a)||0,showSizeChanger:!0,pageSizeOpts:be,onPageChange:e=>v(Number(e)),onPageSizeChange:e=>y(Number(e))}})}var{Text:Ue}=a,We=2e4;function Ge(e,t){let n=t(`vulnerabilityRetest.defaultPrompt`,null,`请帮我对漏洞 {{vulnerability_id}} 进行验证,确认是否已修复。完成后更新该漏洞状态。`),r=String(e?.retest_notes||``).trim();return r?`${n}\n\n${t(`vulnerabilityRetest.guidanceHeading`,null,`验证方式(来自漏洞记录的复测方式):`)}\n${r}`:n}function Ke({visible:e,vuln:t,onClose:r}){let i=se(),a=n(),o=(0,F.useId)(),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(null);return(0,F.useEffect)(()=>{u(null)},[e,t?.id]),(0,W.jsxs)(E,{visible:e,width:640,closable:!s,closeOnEsc:!s,onCancel:s?void 0:r,cancelButtonProps:{disabled:s},title:i(`vulnerabilityRetest.title`,null,`复测漏洞`),formId:o,okText:i(`vulnerabilityRetest.confirm`,null,`确认并开始复测`),confirmLoading:s,children:[(0,W.jsx)(Ue,{strong:!0,children:t?.title}),(0,W.jsx)(Ue,{type:`tertiary`,size:`small`,children:i(`vulnerabilityRetest.hint`,null,`每次确认都会从原始对话创建独立分支,继承原项目和历史,可继续多轮验证。`)}),(0,W.jsxs)(v,{id:o,onSubmit:async e=>{if(!s&&t?.id){c(!0),u(null);try{let n=await w.post(`/vulnerabilities/${encodeURIComponent(t.id)}/retest`,{prompt:String(e.prompt||``).trim()});_e(n.conversation.id,n.prompt),r?.(),a(`/chat?conversation=${encodeURIComponent(n.conversation.id)}`)}catch(e){u(e)}finally{c(!1)}}},initValues:{prompt:Ge(t,i)},children:[(0,W.jsx)(v.TextArea,{id:`${o}-prompt`,field:`prompt`,rows:8,maxCount:We,autosize:!0,label:i(`vulnerabilityRetest.promptLabel`,null,`复测提示词`),extraText:i(`vulnerabilityRetest.placeholderHint`,null,`占位符发送时自动替换,也支持在后续对话中手动输入。`),rules:[{required:!0,whitespace:!0,message:i(`vulnerabilityRetest.promptRequired`,null,`请输入复测提示词。`)}]}),(0,W.jsx)(pe,{error:l})]},`${e}-${t?.id||``}`)]})}var{Text:q,Paragraph:J}=a;function Y({title:e,extra:t,children:n}){return(0,W.jsxs)(`section`,{className:`vulnerability-section`,children:[(0,W.jsxs)(`div`,{className:`vulnerability-section-head`,children:[(0,W.jsx)(`span`,{className:`vulnerability-section-title`,children:e}),t]}),(0,W.jsx)(`div`,{className:`vulnerability-section-body`,children:n})]})}function X({vulnerability:e}){let t=n(),[r,i]=(0,F.useState)([]);return(0,F.useEffect)(()=>{if(!e?.project_id||!e?.id){i([]);return}let t=!1;return w.get(`/projects/${e.project_id}/facts`,{related_vulnerability_id:e.id,limit:20}).then(e=>{t||i(Array.isArray(e)?e:[])}).catch(()=>{t||i([])}),()=>{t=!0}},[e?.project_id,e?.id]),r.length?(0,W.jsx)(Y,{title:`同一项目事实`,children:r.map(e=>(0,W.jsxs)(`div`,{className:`vulnerability-history-item`,children:[(0,W.jsx)(q,{children:e.summary||e.fact_key}),e.source_conversation_id?(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>t(`/chat?conversation=${encodeURIComponent(e.source_conversation_id)}`),children:`打开来源会话`}):null]},e.id))}):null}function Z({title:e,content:t,code:n}){let r=String(t??``).trim();return r?n?(0,W.jsx)(Y,{title:e,extra:(0,W.jsx)(A,{text:r,size:`small`}),children:(0,W.jsx)(`pre`,{className:`vulnerability-code`,children:r})}):(0,W.jsx)(Y,{title:e,children:(0,W.jsx)(O,{content:r})}):null}function qe({visible:e,vulnId:t,refreshKey:r,onClose:i,onEdit:a,onArchive:l,onDelete:f,onOpenVuln:m,canWrite:g,canDelete:v,t:b,projectNames:S}){let ie=n(),[ae,se]=(0,F.useState)(`overview`),[ce,le]=(0,F.useState)(`docx`),[ue,E]=(0,F.useState)(!1),[O,me]=(0,F.useState)(!1),k=de(()=>w.get(`/vulnerabilities/${encodeURIComponent(t)}/context`),[t,r,e],{skip:!e||!t});(0,F.useEffect)(()=>{se(`overview`),le(`docx`)},[t]);let A=k.data?.vulnerability?.id===t?k.data:null,j=A?.vulnerability||null,he=Array.isArray(A?.history)?A.history:[],ge=Array.isArray(A?.members)?A.members:[],_e=Array.isArray(A?.assets)?A.assets:[],P=j?.project_id?S?.[j.project_id]||j.project_id:``,ve=e=>{e&&ie(`/chat?conversation=${encodeURIComponent(e)}`)},I=async()=>{if(j&&!ue){E(!0);try{let e=await oe(`/vulnerabilities/${encodeURIComponent(j.id)}/download`,{query:{format:ce}});N(`${b(`vulnerabilityPage.downloadOkTitle`,null,`下载成功`)}${e?` · ${e}`:``}`)}catch(e){T(e,b(`vulnerabilityPage.downloadFailed`,null,`下载失败`))}finally{E(!1)}}},ye=j?[{label:b(`vulnerabilityPage.detailVulnId`,null,`漏洞ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.id})},{label:b(`vulnerabilityPage.tableSeverity`,null,`严重度`),value:(0,W.jsx)(fe,{severity:j.severity})},{label:b(`vulnerabilityPage.status`,null,`状态`),value:(0,W.jsx)(M,{status:j.status,label:z(b,j.status)})},j.type?{label:b(`vulnerabilityPage.detailType`,null,`类型`),value:j.type}:null,j.target?{label:b(`vulnerabilityPage.detailTarget`,null,`目标`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.target})}:null,V(j)&&V(j)!==j.target?{label:b(`vulnerabilityPage.detailHost`,null,`宿主`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:V(j)})}:null,{label:b(`vulnerabilityPage.detailProject`,null,`所属项目`),value:P||b(`vulnerabilityPage.projectUnbound`,null,`未绑定项目`)},j.conversation_tag?{label:b(`vulnerabilityPage.detailConversationTag`,null,`对话标签`),value:j.conversation_tag}:null,j.conversation_id?{label:b(`vulnerabilityPage.detailConversationId`,null,`会话ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.conversation_id})}:null,j.task_tag?{label:b(`vulnerabilityPage.detailTaskTag`,null,`任务标签`),value:j.task_tag}:null,j.task_id?{label:b(`vulnerabilityPage.detailTaskId`,null,`任务ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.task_id})}:null,j.task_queue_id?{label:b(`vulnerabilityPage.detailTaskQueueId`,null,`任务队列ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.task_queue_id})}:null,j.case_id?{label:b(`vulnerabilityPage.mergedRecord`,null,`已归并`),value:j.case_title||U(j.case_id,12)}:null,j.assessment_id?{label:b(`vulnerabilityPage.assessmentTask`,null,`深度测评`),value:j.assessment_name||U(j.assessment_id,12)}:null,{label:b(`vulnerabilityMd.labelCreated`,null,`创建时间`),value:C(j.created_at)},{label:b(`vulnerabilityMd.labelUpdated`,null,`更新时间`),value:C(j.updated_at)}].filter(Boolean):[],be=Array.isArray(j?.targets)?j.targets:[];return(0,W.jsxs)(ee,{className:`vulnerability-detail-drawer`,visible:e,onCancel:i,width:720,title:(0,W.jsxs)(`div`,{className:`vulnerability-drawer-title`,children:[(0,W.jsx)(`span`,{className:`vulnerability-drawer-title-text`,title:j?.title,children:j?.title||b(`vulnerabilityPage.inspectorTitle`,null,`漏洞工作台`)}),j&&(0,W.jsxs)(`span`,{className:`vulnerability-drawer-meta`,children:[(0,W.jsx)(fe,{severity:j.severity}),(0,W.jsx)(M,{status:j.status,label:z(b,j.status)}),j.archived&&(0,W.jsx)(c,{size:`small`,color:`grey`,children:j.project_archived?b(`vulnerabilityPage.archivedWithProject`,null,`随项目归档`):b(`projects.statusArchived`,null,`已归档`)}),j.type?(0,W.jsx)(q,{type:`tertiary`,children:j.type}):null]})]}),footer:(0,W.jsxs)(o,{wrap:!0,children:[(0,W.jsx)(d,{onClick:i,children:b(`common.close`,null,`关闭`)}),(0,W.jsx)(d,{icon:(0,W.jsx)(re,{}),onClick:()=>k.reload(),loading:k.loading,children:b(`common.refresh`,null,`刷新`)}),g&&(0,W.jsx)(d,{theme:`solid`,type:`primary`,icon:(0,W.jsx)(te,{}),disabled:!j||!j.conversation_id,onClick:()=>me(!0),children:b(`vulnerabilityRetest.button`,null,`复测`)}),g&&(0,W.jsx)(d,{icon:(0,W.jsx)(u,{}),disabled:!j,onClick:()=>a(j),children:b(`common.edit`,null,`编辑`)}),g&&j&&!j.project_archived&&(0,W.jsx)(d,{onClick:()=>l(j),children:j.archived?b(`projects.restore`,null,`恢复`):b(`projects.archiveProject`,null,`归档`)}),v&&(0,W.jsx)(d,{type:`danger`,icon:(0,W.jsx)(s,{}),disabled:!j,onClick:()=>f(j),children:b(`common.delete`,null,`删除`)})]}),children:[(0,W.jsx)(pe,{error:k.error,onRetry:k.reload}),!k.error&&!j&&(0,W.jsx)(`div`,{className:`vulnerability-drawer-loading`,children:(0,W.jsx)(p,{size:`large`})}),j&&(0,W.jsxs)(h,{type:`line`,activeKey:ae,onChange:e=>se(e),children:[(0,W.jsxs)(h.TabPane,{tab:b(`vulnerabilityPage.inspector_overview`,null,`概览`),itemKey:`overview`,children:[(0,W.jsx)(D,{items:ye,columns:2}),j.fingerprint?(0,W.jsx)(Z,{title:b(`vulnerabilityPage.fingerprint`,null,`确定性指纹`),content:j.fingerprint,code:!0}):null,j.quality?(0,W.jsx)(Z,{title:b(`vulnerabilityPage.qualityReview`,null,`五维对抗复核`),content:[`可达性:${j.quality.reachability||`—`}`,`前置条件:${j.quality.preconditions||`—`}`,`可复现性:${j.quality.reproducibility||`—`}`,`范围:${j.quality.scope||`—`}`,`影响:${j.quality.impact||`—`}`,`对照组可达:${j.quality.control_reachable?`是`:`否`}`,`机理已失效:${j.quality.mechanism_invalid?`是`:`否`}`,j.quality.blocked_by?`受阻:${j.quality.blocked_by}`:``].filter(Boolean).join(`
-`)}):null,(0,W.jsx)(Z,{title:b(`vulnerabilityMd.headingDescription`,null,`描述`),content:j.description}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailImpact`,null,`影响`),content:j.impact}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailRecommendation`,null,`修复建议`),content:j.recommendation})]}),(0,W.jsxs)(h.TabPane,{tab:b(`vulnerabilityPage.inspector_evidence`,null,`复现与证据`),itemKey:`evidence`,children:[(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailPreconditions`,null,`前置条件`),content:j.preconditions}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailReproductionSteps`,null,`复现步骤`),content:j.reproduction_steps}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailEvidence`,null,`证据 / POC`),content:j.evidence,code:!0}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailRetestNotes`,null,`复测方式`),content:j.retest_notes}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailRetestLog`,null,`复测记录`),content:j.retest_log,code:!0}),(0,W.jsx)(X,{vulnerability:j}),(0,W.jsx)(Y,{title:b(`vulnerabilityPage.inspector_history`,null,`处置历史`),children:he.length?(0,W.jsx)(ne,{children:he.map((e,t)=>(0,W.jsx)(ne.Item,{time:C(e.created_at),type:e.kind===`retest`?`success`:`default`,children:(0,W.jsxs)(`div`,{className:`vulnerability-history-item`,children:[(0,W.jsxs)(`div`,{className:`vulnerability-history-head`,children:[(0,W.jsx)(q,{strong:!0,children:Te(b,e.kind)}),e.status?(0,W.jsx)(M,{status:e.status,label:z(b,e.status)}):null,e.actor?(0,W.jsx)(q,{type:`tertiary`,children:e.actor}):null]}),e.evidence?(0,W.jsx)(`pre`,{className:`vulnerability-code`,children:e.evidence}):null,e.snapshot?(0,W.jsx)(y,{className:`vulnerability-snapshot`,children:(0,W.jsxs)(y.Panel,{header:b(`vulnerabilityPage.retestSnapshot`,null,`复测时的证据快照`),itemKey:`snapshot`,children:[(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailReproductionSteps`,null,`复现步骤`),content:e.snapshot.reproduction_steps}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailEvidence`,null,`证据 / POC`),content:e.snapshot.evidence,code:!0})]})}):null,e.conversation_id?(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>ve(e.conversation_id),children:b(`vulnerabilityPage.openRetestChat`,null,`打开复测对话`)}):null]})},`${e.kind}-${e.created_at}-${t}`))}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.noHistory`,null,`暂无结构化处置记录`)})})]}),(0,W.jsxs)(h.TabPane,{tab:b(`vulnerabilityPage.detailRelations`,null,`关联`),itemKey:`relations`,children:[(0,W.jsx)(Y,{title:b(`vulnerabilityPage.detailProject`,null,`所属项目`),children:j.project_id?(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(q,{children:P}),(0,W.jsx)(q,{type:`tertiary`,className:`vulnerability-inline-code`,children:j.project_id})]}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.projectUnbound`,null,`未绑定项目`)})}),(0,W.jsx)(Y,{title:b(`vulnerabilityPage.affectedTargets`,null,`受影响目标`),children:be.length?(0,W.jsx)(`ul`,{className:`vulnerability-related-list`,children:be.map(e=>(0,W.jsxs)(`li`,{className:`vulnerability-related-item`,children:[(0,W.jsx)(q,{strong:!0,children:e.host||e.domain||e.raw}),e.raw&&e.raw!==e.host?(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:e.raw}):null]},`${e.raw}-${e.host}`))}):(0,W.jsx)(J,{type:`tertiary`,children:j.target||`—`})}),(0,W.jsx)(Y,{title:b(`vulnerabilityPage.linkedAssets`,null,`资产库匹配`),children:_e.length?(0,W.jsx)(`ul`,{className:`vulnerability-related-list`,children:_e.map(e=>(0,W.jsxs)(`li`,{className:`vulnerability-related-item`,children:[(0,W.jsx)(q,{strong:!0,children:H(e)}),(0,W.jsx)(q,{type:`tertiary`,className:`vulnerability-inline-code`,children:U(e.id,12)})]},e.id||`${e.host}-${e.port}`))}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.noLinkedAssets`,null,`未匹配到资产库记录`)})}),(0,W.jsxs)(Y,{title:b(`vulnerabilityPage.detailConversationId`,null,`会话`),children:[j.conversation_id?(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.conversation_id}),(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>ve(j.conversation_id),children:b(`vulnerabilityPage.openConversation`,null,`查看对话`)})]}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.standaloneRecord`,null,`独立记录(无关联会话)`)}),j.task_id||j.task_queue_id?(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(q,{type:`tertiary`,children:b(`vulnerabilityPage.detailTaskId`,null,`任务ID`)}),(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.task_id||j.task_queue_id})]}):null]}),j.assessment_id?(0,W.jsx)(Y,{title:b(`vulnerabilityPage.assessmentTask`,null,`深度测评`),children:(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(q,{children:j.assessment_name||U(j.assessment_id,12)}),j.assessment_step_title?(0,W.jsx)(q,{type:`tertiary`,children:j.assessment_step_title}):null]})}):null,ge.length?(0,W.jsx)(Y,{title:j.case_title||b(`vulnerabilityPage.mergedRecord`,null,`已归并`),children:(0,W.jsx)(`div`,{className:`vulnerability-member-list`,children:ge.map(e=>(0,W.jsxs)(d,{size:`small`,theme:`borderless`,disabled:e.id===j.id,onClick:()=>m(e.id),children:[e.title,` · `,z(b,e.status)]},e.id))})}):null]}),(0,W.jsx)(h.TabPane,{tab:b(`vulnerabilityDownload.title`,null,`下载报告`),itemKey:`download`,children:(0,W.jsxs)(`div`,{className:`vulnerability-download-panel`,children:[(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityDownload.hint`,null,`请选择下载格式`)}),(0,W.jsxs)(_,{value:ce,onChange:e=>le(e.target.value),children:[(0,W.jsx)(x,{value:`docx`,children:b(`vulnerabilityDownload.word`,null,`Word(.docx)`)}),(0,W.jsx)(x,{value:`md`,children:b(`vulnerabilityDownload.markdown`,null,`Markdown(.md)`)})]}),(0,W.jsx)(d,{theme:`solid`,type:`primary`,loading:ue,onClick:I,children:b(`vulnerabilityDownload.download`,null,`下载漏洞报告`)}),(0,W.jsx)(q,{type:`tertiary`,children:b(`vulnerabilityPage.downloadHint`,null,`报告由服务端按当前记录生成,包含描述、证据与修复建议。`)})]})})]}),(0,W.jsx)(Ke,{visible:O,vuln:j,onClose:()=>me(!1)})]})}var{Text:Q}=a,Je={title:``,severity:``,status:`open`,type:``,target:``,project_id:``,conversation_id:``,conversation_tag:``,task_tag:``,description:``,preconditions:``,reproduction_steps:``,evidence:``,impact:``,recommendation:``,retest_notes:``};function Ye(e){return e?{title:e.title||``,severity:e.severity||``,status:e.status||`open`,type:e.type||``,target:e.target||``,project_id:e.project_id||``,conversation_id:e.conversation_id||``,conversation_tag:e.conversation_tag||``,task_tag:e.task_tag||``,description:e.description||``,preconditions:e.preconditions||``,reproduction_steps:e.reproduction_steps||``,evidence:e.evidence||``,impact:e.impact||``,recommendation:e.recommendation||``,retest_notes:e.retest_notes||``}:{...Je}}function $(e){return String(e??``).trim()}function Xe({visible:e,vulnId:t,t:n,projects:r,onClose:i,onSaved:a}){let o=!!t,[s,c]=(0,F.useState)(null),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(null),[m,h]=(0,F.useState)({...Je}),[g,_]=(0,F.useState)(``);(0,F.useEffect)(()=>{if(!e)return;if(f(null),!t){_(``);return}let n=!1;return w.get(`/vulnerabilities/${encodeURIComponent(t)}`).then(e=>{n||(h(Ye(e)),_(t))}).catch(e=>{n||f(e)}),()=>{n=!0}},[e,t]);let y=!o||g===t,b=o?m:{...Je},x=P(r,n,{currentId:b.project_id}),ee=async()=>{if(!s||l)return;let e;try{e=await s.validate()}catch{return}let r={title:$(e.title),severity:e.severity,status:e.status||`open`,type:$(e.type),target:$(e.target),description:e.description||``,preconditions:e.preconditions||``,reproduction_steps:e.reproduction_steps||``,evidence:e.evidence||``,impact:e.impact||``,recommendation:e.recommendation||``,retest_notes:e.retest_notes||``,project_id:$(e.project_id),conversation_tag:$(e.conversation_tag),task_tag:$(e.task_tag)};o||(r.conversation_id=$(e.conversation_id)),u(!0);try{let e=o?await w.put(`/vulnerabilities/${encodeURIComponent(t)}`,r):await w.post(`/vulnerabilities`,r);a?.(e)}catch(e){T(e,n(`vulnerabilityPage.saveFailed`,null,`保存失败`))}finally{u(!1)}};return(0,W.jsx)(E,{title:o?n(`vulnerability.editVuln`,null,`编辑漏洞`):n(`vulnerability.addVuln`,null,`添加漏洞`),visible:e,onCancel:i,onOk:ee,confirmLoading:l,okText:n(`common.save`,null,`保存`),cancelText:n(`common.cancel`,null,`取消`),width:780,children:e?d?(0,W.jsx)(Q,{type:`danger`,children:ce(d,n(`vulnerabilityPage.fetchFailed`,null,`获取漏洞失败`))}):y?(0,W.jsx)(v,{initValues:b,getFormApi:c,labelPosition:`top`,onSubmit:ee,children:(0,W.jsxs)(`div`,{className:`vulnerability-form-grid`,children:[(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.Input,{field:`title`,label:n(`vulnerabilityModal.title`,null,`标题`),placeholder:n(`vulnerabilityModal.titlePlaceholder`,null,`/api/login 存在 SQL 注入`),rules:[{required:!0,message:n(`vulnerabilityModal.titleRequired`,null,`请填写漏洞标题`)}],maxLength:500})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Select,{field:`severity`,label:n(`vulnerabilityModal.severity`,null,`严重程度`),placeholder:n(`vulnerabilityModal.pleaseSelect`,null,`请选择`),style:{width:`100%`},optionList:Ee(n),rules:[{required:!0,message:n(`vulnerabilityModal.severityRequired`,null,`请选择严重程度`)}]})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Select,{field:`status`,label:n(`vulnerabilityModal.status`,null,`状态`),style:{width:`100%`},optionList:B(n)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`target`,label:n(`vulnerabilityModal.target`,null,`目标`),placeholder:n(`vulnerabilityModal.targetPlaceholder`,null,`精确到 URL/IP:端口/接口路径/参数名`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`type`,label:n(`vulnerabilityModal.type`,null,`漏洞类型`),placeholder:n(`vulnerabilityModal.typePlaceholder`,null,`如:SQL注入、XSS、CSRF等`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Select,{field:`project_id`,label:n(`vulnerabilityModal.project`,null,`所属项目`),placeholder:n(`vulnerabilityModal.projectNone`,null,`(未绑定)`),style:{width:`100%`},filter:!0,optionList:[{value:``,label:n(`vulnerabilityModal.projectNone`,null,`(未绑定)`)},...x]})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`conversation_id`,label:n(`vulnerabilityModal.conversationId`,null,`会话ID`),placeholder:n(`vulnerabilityModal.conversationIdPlaceholder`,null,`可选:输入已有会话ID,留空可独立添加漏洞`),disabled:o})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`conversation_tag`,label:n(`vulnerabilityModal.conversationTag`,null,`对话标签`),placeholder:n(`vulnerabilityModal.conversationTagPlaceholder`,null,`如:红队演练A、客户A周报`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`task_tag`,label:n(`vulnerabilityModal.taskTag`,null,`任务标签`),placeholder:n(`vulnerabilityModal.taskTagPlaceholder`,null,`如:批量扫描Q2、专项复测`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`description`,label:n(`vulnerabilityModal.description`,null,`描述`),placeholder:n(`vulnerabilityModal.descriptionPlaceholder`,null,`说明漏洞摘要、触发点、异常现象和为什么可被利用。`),autosize:{minRows:3,maxRows:8}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`preconditions`,label:n(`vulnerabilityModal.preconditions`,null,`前置条件`),placeholder:n(`vulnerabilityModal.preconditionsPlaceholder`,null,`登录状态、权限、账号、Header/Cookie、特定数据、环境/版本;无则写无。`),autosize:{minRows:2,maxRows:6}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`reproduction_steps`,label:n(`vulnerabilityModal.reproductionSteps`,null,`复现步骤`),placeholder:n(`vulnerabilityModal.reproductionStepsPlaceholder`,null,`按 1/2/3 编号,写清入口、参数、payload、执行命令、观察点。`),autosize:{minRows:3,maxRows:10}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`evidence`,label:n(`vulnerabilityModal.evidence`,null,`证据 / POC`),placeholder:n(`vulnerabilityModal.evidencePlaceholder`,null,`原始请求/响应、curl/工具命令、截图说明、日志、回连记录等。`),autosize:{minRows:3,maxRows:10}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`impact`,label:n(`vulnerabilityModal.impact`,null,`影响`),placeholder:n(`vulnerabilityModal.impactPlaceholder`,null,`结合已验证事实说明实际影响,例如越权读取哪些数据。`),autosize:{minRows:2,maxRows:6}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`recommendation`,label:n(`vulnerabilityModal.recommendation`,null,`修复建议`),placeholder:n(`vulnerabilityModal.recommendationPlaceholder`,null,`写具体修复点和复测标准。`),autosize:{minRows:2,maxRows:8}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`retest_notes`,label:n(`vulnerabilityModal.retestNotes`,null,`复测方式`),placeholder:n(`vulnerabilityModal.retestNotesPlaceholder`,null,`修复后如何验证漏洞已关闭,包括应返回的状态码、错误信息或访问控制结果。`),autosize:{minRows:2,maxRows:6}})})]})},o?`${t}-${g}`:`new`):(0,W.jsx)(`div`,{className:`vulnerability-modal-loading`,children:(0,W.jsx)(p,{size:`large`})}):null})}var{Text:Ze}=a,Qe={none:`viewList`,host:`viewHost`,task:`viewTask`},$e=[];function et(){let e=se(),{hasPermission:t}=ae(),[n,r]=i(),a=(0,F.useMemo)(()=>({q:n.get(`q`)||``,severity:n.get(`severity`)||``,status:n.get(`status`)||``,archived:[`true`,`all`].includes(n.get(`archived`))?n.get(`archived`):``,project_id:n.get(`project_id`)||``,conversation_tag:n.get(`conversation_tag`)||``,task_tag:n.get(`task_tag`)||``,assessment_id:n.get(`assessment_id`)||``,sort:[`severity`,`latest`,`oldest`].includes(n.get(`sort`))?n.get(`sort`):``}),[n]),o=Math.max(1,Number.parseInt(n.get(`page`)||`1`,10)||1),s=be.includes(Number(n.get(`page_size`)))?Number(n.get(`page_size`)):20,c=(n.get(`id`)||``).trim(),l=n.get(`group_by`),u=l===`host`||l===`task`?l:``,f=u&&n.get(`selection`)||``,p=u===`task`?`task_q`:`host_q`,m=u&&n.get(p)||``,h=m?{[p]:m}:{},v=t(`vulnerability:write`),y=t(`vulnerability:delete`)||v,b=(0,F.useCallback)((e,t={})=>{r(n=>{let r=new URLSearchParams(n);return Object.entries(e).forEach(([e,t])=>{t==null||t===``?r.delete(e):r.set(e,String(t))}),t.resetPage&&r.delete(`page`),r.toString()===n.toString()?n:r},{replace:!0})},[r]),x=(0,F.useCallback)((e,t)=>{b({[e]:t},{resetPage:!0})},[b]),ee=(0,F.useCallback)(()=>{let e={sort:void 0,selection:void 0,host_q:void 0,task_q:void 0};ye.forEach(t=>{e[t]=void 0}),b(e,{resetPage:!0})},[b]),te=(0,F.useCallback)(e=>{b({group_by:e===`none`?void 0:e,selection:void 0,host_q:void 0,task_q:void 0},{resetPage:!0})},[b]),ne=(0,F.useCallback)(e=>{b({selection:e},{resetPage:!0})},[b]),S=(0,F.useCallback)(e=>{b({[p]:e,selection:void 0},{resetPage:!0})},[p,b]),ie=(0,F.useCallback)(e=>b({id:e}),[b]),C=(0,F.useCallback)(()=>b({id:void 0}),[b]),ce={...Oe(a),...h,...u?{group_by:u,pagination:`records`,selection:f}:{},...a.sort?{sort:a.sort}:{},summary:`true`,page:o,limit:s},E=JSON.stringify(ce),D=de(async()=>({...await w.get(`/vulnerabilities`,ce)||{},__requestKey:E,__groupView:u}),[E]),O=D.data?.__requestKey===E?D.data:null,fe=D.data?.__groupView===u&&D.data?.navigation||$e,k=O?.selection?fe.flatMap(e=>[e,...e.children||[]]).find(e=>e.key===O.selection):null,A=(0,F.useMemo)(()=>ke(a),[a]),he=JSON.stringify(A),M=de(()=>w.get(`/vulnerabilities/stats`,A),[he]),[_e,P]=(0,F.useState)(0),I=de(()=>w.get(`/vulnerabilities/filter-options`,a.archived?{archived:a.archived}:{}),[_e,a.archived]),xe=de(async()=>{try{let e=await w.get(`/projects`,{limit:500});return Array.isArray(e?.projects)?e.projects:[]}catch{return[]}},[]),Se=(0,F.useMemo)(()=>{let e={};return(xe.data||[]).forEach(t=>{t?.id&&(e[t.id]=t.name||t.id)}),e},[xe.data]),Ce=(0,F.useMemo)(()=>{let e=new Map;return(I.data?.project_ids||[]).forEach(t=>{t&&e.set(t,Se[t]||t)}),a.project_id&&!e.has(a.project_id)&&e.set(a.project_id,Se[a.project_id]||a.project_id),[...e.entries()].map(([e,t])=>({value:e,label:t}))},[I.data,Se,a.project_id]),[L,R]=(0,F.useState)([]),[z,Te]=(0,F.useState)({visible:!1,id:``}),[Ee,B]=(0,F.useState)(0),[De,Me]=(0,F.useState)(!1);(0,F.useEffect)(()=>{R([])},[E]),(0,F.useEffect)(()=>{if(!O)return;let e={},t=Number(O.page);t&&t!==o&&(e.page=t),f&&!O.selection&&(e.selection=void 0),Object.keys(e).length&&b(e)},[O,f,o,b]);let V=D.reload,H=M.reload,U=I.reload,G=(0,F.useCallback)(()=>{V(),H(),U({silent:!0})},[V,H,U]),K=(0,F.useCallback)(e=>{Te({visible:!0,id:e?.id||``})},[]),Fe=(0,F.useCallback)(()=>{Te({visible:!1,id:``}),N(e(`vulnerabilityPage.saveSuccess`,null,`已保存`)),B(e=>e+1),P(e=>e+1),V({silent:!0}),H({silent:!0})},[V,H,e]),Ie=(0,F.useCallback)(async t=>{try{await w.put(`/vulnerabilities/${encodeURIComponent(t.id)}/archive`,{archived:!t.archived}),N(e(`vulnerabilityPage.saveSuccess`,null,`已保存`)),R(e=>e.filter(e=>e!==t.id)),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}catch(t){T(t,e(`vulnerabilityPage.archiveFailed`,null,`更新归档状态失败`))}},[V,H,e]),Le=(0,F.useCallback)(t=>{t?.id&&ge({title:e(`vulnerabilityPage.deleteTitle`,null,`删除漏洞`),content:`${e(`vulnerability.deleteConfirm`,null,`确定要删除此漏洞吗?`)}${t.title?` ${t.title}`:``}`,okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await w.del(`/vulnerabilities/${encodeURIComponent(t.id)}`),N(e(`vulnerabilityPage.deleteSuccess`,null,`已删除`)),c===t.id&&C(),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}catch(t){T(t,e(`vulnerabilityPage.deleteFailed`,null,`删除失败`))}}})},[c,C,V,H,e]),Be=(0,F.useCallback)(()=>{if(!L.length)return;let t=[...L];ge({title:e(`vulnerabilityPage.batchDelete`,null,`批量删除`),content:e(`vulnerabilityPage.batchDeleteConfirm`,{count:t.length},`确定要删除选中的 ${t.length} 条漏洞吗?此操作不可恢复。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{let n=0,r=0;for(let e of t)try{await w.del(`/vulnerabilities/${encodeURIComponent(e)}`),n+=1}catch{r+=1}r?le(e(`vulnerabilityPage.batchDeletePartial`,{deleted:n,failed:r},`已删除 ${n} 条,${r} 条失败`)):N(e(`vulnerabilityPage.batchDeleteSuccess`,{count:n},`成功删除 ${n} 条漏洞`)),R([]),t.includes(c)&&C(),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}})},[L,c,C,V,H,e]),Ve=(0,F.useCallback)(async()=>{let t=Oe(a);try{let n=await w.get(`/vulnerabilities`,{...t,page:1,limit:1}),r=Number(n?.total)||0;if(!r){le(e(`vulnerabilityPage.batchDeleteNoResults`,null,`当前筛选条件下没有可删除的漏洞`));return}ge({title:e(`vulnerabilityPage.deleteFilteredTitle`,null,`删除当前筛选结果`),content:e(`vulnerabilityPage.batchDeleteConfirm`,{count:r},`确定要删除当前筛选条件下的 ${r} 条漏洞吗?此操作不可恢复。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{let n=await w.del(`/vulnerabilities/batch`,{query:t}),i=Number(n?.deleted)||r;N(e(`vulnerabilityPage.batchDeleteSuccess`,{count:i},`成功删除 ${i} 条漏洞`)),R([]),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}catch(t){T(t,e(`vulnerabilityPage.batchDeleteFailed`,null,`批量删除失败`))}}})}catch(t){T(t,e(`vulnerabilityPage.fetchFailed`,null,`获取漏洞失败`))}},[a,V,H,e]),Ue=(0,F.useCallback)(async()=>{if(!De){Me(!0);try{let t=await w.get(`/vulnerabilities/export`,{...Oe(a),...h,mode:`summary`,group_by:`conversation`}),n=Array.isArray(t?.files)?t.files:[];if(!n.length){le(e(`vulnerabilityPage.exportNoResults`,null,`当前筛选条件下无可导出漏洞`));return}n.forEach((e,t)=>{setTimeout(()=>Ne(e.filename||`vulnerability-export-${t+1}.md`,e.content||``),t*120)}),N(n.length>1?e(`vulnerabilityPage.exportStarted`,{count:n.length},`已开始下载 ${n.length} 份报告`):e(`vulnerabilityPage.exportSuccess`,null,`报告已开始下载`))}catch(t){T(t,e(`vulnerabilityPage.exportFailed`,null,`导出失败`))}finally{Me(!1)}}},[De,a,h,e]),We=(0,F.useCallback)(async t=>{try{let n=await oe(`/vulnerabilities/${encodeURIComponent(t.id)}/download`,{query:{format:`docx`}});N(`${e(`vulnerabilityPage.downloadOkTitle`,null,`下载成功`)}${n?` · ${n}`:``}`)}catch(t){T(t,e(`vulnerabilityPage.downloadFailed`,null,`下载失败`))}},[e]),Ge=(0,F.useCallback)(e=>{b({page:String(e)})},[b]),Ke=(0,F.useCallback)(e=>{if(!e||e===s)return;let t=Math.max(1,Math.floor((o-1)*s/e)+1);b({page_size:String(e),page:String(t)})},[o,s,b]),q=M.data||{},J=q.by_severity||{},Y=Number(q.total)||0,X=Number(q.distinct)||0,Z=(0,F.useMemo)(()=>[{id:`total`,label:e(`vulnerabilityPage.statTotal`,null,`总漏洞数`),value:Y,detail:X&&X!==Y?e(`vulnerabilityPage.distinctCount`,{count:X},`${X} 个独立漏洞`):void 0,loading:M.loading,onClick:()=>x(`severity`,``)},...ve.map(t=>{let n=Number(J[t])||0,r=je(n,Y),i=a.severity===t;return{id:t,label:we(e,t),value:n,severity:t,pressed:i,detail:i?`${e(`vulnerabilityPage.filterActive`,null,`已筛选`)} · ${r}%`:`${r}%`,loading:M.loading,onClick:()=>x(`severity`,i?``:t)}})],[e,Y,X,J,M.loading,a.severity,x]),Q=Number(O?.total)||0,Je=Q?(o-1)*s+1:0,Ye=Q?Math.min(o*s,Q):0,$=Q?e(`vulnerabilityPage.recordPagination`,{start:Je,end:Ye,total:Q},`显示 ${Je}–${Ye} / 共 ${Q} 条漏洞`):e(`vulnerabilityPage.noRecords`,null,`暂无漏洞记录`),et=D.error||M.error||I.error,tt=(0,W.jsxs)(`div`,{className:`vulnerability-toolbar-left`,children:[(0,W.jsx)(Ze,{type:`tertiary`,children:O&&L.length?e(`vulnerabilityPage.selectedCount`,{count:L.length},`已选 ${L.length} 项`):$}),y&&(0,W.jsx)(d,{size:`small`,type:`danger`,theme:`light`,disabled:!O||!L.length,onClick:Be,children:e(`vulnerabilityPage.batchDelete`,null,`批量删除`)}),y&&!f&&!m&&Ae(a)&&(0,W.jsx)(d,{size:`small`,type:`danger`,theme:`borderless`,onClick:Ve,children:e(`vulnerabilityPage.deleteFiltered`,null,`删除筛选结果`)})]});return(0,W.jsxs)(`div`,{className:`vulnerability-page`,children:[(0,W.jsx)(j,{title:e(`vulnerability.title`,null,`漏洞管理`),description:e(`vulnerabilityPage.workspaceSubtitle`,null,`资产、上报与处置进展`),extra:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(d,{icon:(0,W.jsx)(re,{}),onClick:G,loading:D.loading,children:e(`common.refresh`,null,`刷新`)}),(0,W.jsx)(d,{onClick:Ue,loading:De,children:e(f?`vulnerabilityPage.exportAllGroups`:`vulnerabilityPage.batchExport`)}),v&&(0,W.jsx)(d,{theme:`solid`,type:`primary`,icon:(0,W.jsx)(g,{}),onClick:()=>K(null),children:e(`vulnerability.addVuln`,null,`添加漏洞`)})]})}),(0,W.jsx)(ue,{metrics:Z,columns:6}),(0,W.jsx)(pe,{error:et,onRetry:G}),(0,W.jsxs)(me,{className:`vulnerability-list-card`,title:e(`vulnerabilityPage.listTitle`,null,`漏洞记录`),extra:(0,W.jsx)(_,{"aria-label":e(`vulnerabilityPage.viewLabel`),type:`button`,value:u||`none`,options:Object.entries(Qe).map(([t,n])=>({value:t,label:e(`vulnerabilityPage.${n}`)})),onChange:e=>te(e.target.value)}),children:[(0,W.jsx)(Pe,{t:e,filters:a,options:I.data,projectOptions:Ce,hasGroupFilters:!!(f||m),onChange:x,onReset:ee}),(0,W.jsxs)(`div`,{className:u?`vulnerability-group-layout`:void 0,children:[u&&(0,W.jsx)(Re,{t:e,mode:u,groups:fe,selection:f,search:m,loading:D.loading,onSearch:S,onSelect:ne},u),(0,W.jsxs)(`div`,{className:`vulnerability-group-results`,children:[k&&(0,W.jsx)(ze,{t:e,group:k}),(0,W.jsx)(He,{t:e,data:O?.vulnerabilities,loading:D.loading,page:o,pageSize:s,total:Q,selection:O?L:[],onSelectionChange:R,onOpen:ie,onEdit:K,onArchive:Ie,onDelete:Le,onDownload:We,sort:a.sort,onSort:e=>x(`sort`,e),canWrite:v,canDelete:y,onPageChange:Ge,onPageSizeChange:Ke,toolbar:tt,onRefresh:G})]})]})]}),(0,W.jsx)(qe,{visible:!!c,vulnId:c,refreshKey:Ee,onClose:C,onOpenVuln:ie,onEdit:K,onArchive:Ie,onDelete:Le,canWrite:v,canDelete:y,t:e,projectNames:Se}),(0,W.jsx)(Xe,{visible:z.visible,vulnId:z.id,t:e,projects:xe.data,onClose:()=>Te({visible:!1,id:``}),onSaved:Fe})]})}export{et as default};
\ No newline at end of file
diff --git a/web/static/app/assets/webshell-DwxDKO10.js b/web/static/app/assets/webshell-i057Xx9K.js
similarity index 93%
rename from web/static/app/assets/webshell-DwxDKO10.js
rename to web/static/app/assets/webshell-i057Xx9K.js
index 2cb1164a..a115f2b6 100644
--- a/web/static/app/assets/webshell-DwxDKO10.js
+++ b/web/static/app/assets/webshell-i057Xx9K.js
@@ -1,2 +1,2 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{E as i,G as a,I as o,N as s,R as c,S as l,U as u,W as d,c as f,ct as p,ft as m,i as h,lt as g,ut as _}from"./semi-65W_4I1v.js";import{E as v,F as y,I as b,P as x,S,a as C,b as w,c as T,f as E,l as ee,n as te,o as D,p as O,s as k,u as ne,x as A,y as j}from"./index-BdnarFZR.js";import{t as M}from"./project-options-CMQbwv_U.js";var N=e(t(),1);function P(e){return b.get(`/webshell/connections`,e)}function F(e){return b.post(`/webshell/connections`,e)}function re(e,t){return b.put(`/webshell/connections/${encodeURIComponent(e)}`,t)}function ie(e){return b.del(`/webshell/connections/${encodeURIComponent(e)}`)}function ae(e){return b.get(`/webshell/connections/${encodeURIComponent(e)}/state`)}function oe(e,t){return b.put(`/webshell/connections/${encodeURIComponent(e)}/state`,{state:t})}function I({connection:e,command:t}){return b.post(`/webshell/exec`,{connection_id:e.id,url:e.url,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,command:t})}function L({connection:e,action:t,path:n,targetPath:r,content:i,chunkIndex:a}){let o={connection_id:e.id,url:e.url,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,action:t};return n!==void 0&&(o.path=n),r!==void 0&&(o.target_path=r),i!==void 0&&(o.content=i),a!==void 0&&(o.chunk_index=a),b.post(`/webshell/file`,o)}function se(e){return b.get(`/webshell/connections/${encodeURIComponent(e)}/ai-conversations`)}function R(e){return b.get(`/webshell/connections/${encodeURIComponent(e)}/ai-history`)}function z(e){return b.get(`/conversations/${encodeURIComponent(e)}`,{include_process_details:0})}async function ce(){try{let e=await b.get(`/projects`,{limit:200});return Array.isArray(e?.projects)?e.projects:[]}catch{return[]}}function le(){return`__CSAI_PROBE_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}__`}async function ue(e){let t=le(),n=await I({connection:e,command:`echo ${t}`});return{ok:!!n?.ok&&String(n?.output||``).includes(t),output:n?.output||``,error:n?.error||``}}var B=e(n(),1),{Text:V}=a,H=[{value:`php`,label:`PHP`},{value:`asp`,label:`ASP`},{value:`aspx`,label:`ASPX`},{value:`jsp`,label:`JSP`},{value:`custom`,label:`自定义`}],U=[{value:`post`,label:`POST`},{value:`get`,label:`GET`}],W=[{value:`auto`,label:`自动检测`},{value:`utf-8`,label:`UTF-8`},{value:`gbk`,label:`GBK(中文 Windows)`},{value:`gb18030`,label:`GB18030`}],G=[{value:`auto`,label:`自动(按 Shell 类型推断)`},{value:`linux`,label:`Linux / Unix`},{value:`windows`,label:`Windows`}];function K(e){return e?{url:e.url||``,password:e.password||``,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,remark:e.remark||``,project_id:e.project_id||``}:{url:``,password:``,type:`php`,method:`post`,cmd_param:``,encoding:`auto`,os:`auto`,remark:``,project_id:``}}function de({visible:e,record:t,projects:n,submitting:r,onCancel:i,onSubmit:a}){let s=x(),[l,u]=(0,N.useState)(null),[d,f]=(0,N.useState)(!1);return(0,B.jsx)(T,{visible:e,title:t?s(`webshell.editConnectionTitle`,null,`编辑连接`):s(`webshell.addConnection`,null,`添加连接`),footer:(0,B.jsxs)(o,{children:[(0,B.jsx)(c,{onClick:async()=>{let e=l?.getValues?.()||{},n=String(e.url||``).trim();if(!n)S(s(`webshell.url`,null,`请填写 Shell 地址`));else if(e.password===`********`)S(s(`webshell.testNoExpectedOutput`,null,`已保存口令不可用于新建测试,请填写口令`));else{f(!0);try{let r=await ue({id:t?.id||``,url:n,password:e.password||``,type:e.type||`php`,method:e.method||`post`,cmdParam:e.cmd_param||``,encoding:e.encoding||`auto`,os:e.os||`auto`});r.ok?A(s(`webshell.testSuccess`,null,`连通性正常,Shell 可访问`)):w(r.error||s(`webshell.testFailed`,null,`连通性测试失败`))}catch(e){w(e,s(`webshell.testFailed`,null,`连通性测试失败`))}finally{f(!1)}}},loading:d,children:s(`webshell.testConnectivity`,null,`测试连通性`)}),(0,B.jsx)(c,{onClick:i,children:s(`webshell.cancelEdit`,null,`取消`)}),(0,B.jsx)(c,{theme:`solid`,type:`primary`,loading:r,onClick:()=>l?.submitForm(),children:t?s(`webshell.saveFile`,null,`保存`):s(`webshell.addConnection`,null,`添加连接`)})]}),width:600,onCancel:i,children:(0,B.jsxs)(h,{initValues:K(t),onSubmit:e=>{a({url:String(e.url||``).trim(),password:e.password||``,type:e.type||`php`,method:e.method||`post`,cmd_param:String(e.cmd_param||``).trim(),encoding:e.encoding||`auto`,os:e.os||`auto`,remark:String(e.remark||``).trim(),project_id:e.project_id||``})},getFormApi:u,labelPosition:`top`,children:[(0,B.jsx)(h.Input,{field:`url`,label:s(`webshell.url`,null,`Shell 地址`),placeholder:`http(s)://target.com/shell.php`,rules:[{required:!0,message:s(`webshell.url`,null,`请填写 Shell 地址`)}]}),(0,B.jsx)(h.Input,{field:`password`,label:s(`webshell.password`,null,`连接密码/密钥`),placeholder:s(`webshell.passwordPlaceholder`,null,`如冰蝎/蚁剑的连接密码`)}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Select,{field:`type`,label:s(`webshell.type`,null,`Shell 类型`),optionList:H,style:{width:`100%`}}),(0,B.jsx)(h.Select,{field:`method`,label:s(`webshell.method`,null,`请求方式`),optionList:U,style:{width:`100%`}})]}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Input,{field:`cmd_param`,label:s(`webshell.cmdParam`,null,`命令参数名`),placeholder:`cmd`}),(0,B.jsx)(h.Select,{field:`encoding`,label:s(`webshell.encoding`,null,`响应编码`),optionList:W,style:{width:`100%`}})]}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Select,{field:`os`,label:s(`webshell.os`,null,`目标系统`),optionList:G,style:{width:`100%`}}),(0,B.jsx)(h.Select,{field:`project_id`,label:s(`webshell.project`,null,`所属项目`),optionList:M(n,s,{currentId:t?.project_id||``}),showClear:!0,style:{width:`100%`},placeholder:`可选`})]}),(0,B.jsx)(h.Input,{field:`remark`,label:s(`webshell.remark`,null,`备注`),placeholder:s(`webshell.remarkPlaceholder`,null,`便于识别的备注名`)}),(0,B.jsx)(V,{type:`tertiary`,size:`small`,children:s(`webshell.encodingHint`,null,`中文 Windows 目标若出现乱码,请切换为 GBK 或 GB18030`)})]},t?.id||`new`)})}var q={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11};function fe(e,t,n){if(!e||!t||!n)return``;let r=String(n).trim();if(/^\d{4}$/.test(r))return`${r} ${e} ${t}`;let i=new Date,a=i.getFullYear();if(/^\d{1,2}:\d{2}$/.test(r)){let n=q[e],o=parseInt(t,10);return n!=null&&!Number.isNaN(o)&&new Date(a,n,o).getTime()>i.getTime()&&--a,`${a} ${e} ${t} ${r}`}return`${e} ${t} ${r}`}function J(e){if(!e)return``;let t=e.charAt(0);return{d:`dir`,"-":`file`,l:`link`,c:`char`,b:`block`,s:`socket`,p:`pipe`}[t]||t}function Y(e){let t=String(e||``).match(/^(\d{4}[/-]\d{1,2}[/-]\d{1,2})\s+(\d{1,2}:\d{2})(?:\s*(AM|PM))?\s+(<[^>]+>|[\d,]+)\s+(.+?)\s*$/i);if(!t)return null;let n=(t[4]||``).trim(),r=(t[5]||``).trim();if(!r||r===`.`||r===`..`)return null;let i=/^<(dir|junction|symlinkd)>$/i.test(n);return{name:r,isDir:i,size:i?``:n.replace(/,/g,``),mtime:`${t[1]} ${t[2]}${t[3]?` ${t[3].toUpperCase()}`:``}`.trim(),mode:i?`d`:`-`,owner:``,group:``,type:i?`dir`:`file`}}var X=[/^(total|总计)\s+\d+$/i,/^(驱动器|卷的序列号是|volume in drive|volume serial number is|directory of)/i,/^[A-Za-z]:\\.*\s+的目录$/i,/^\d+\s+(个文件|file\(s\))\s+[\d,]+\s+(字节|bytes?)$/i,/^\d+\s+(个目录|dir\(s\))\s+[\d,]+\s+(可用字节|bytes free)$/i,/^[^>\n]*>\s*dir(?:\s|$)/i];function pe(e){let t=String(e||``).split(/\n/).filter(e=>e.trim()),n=[];for(let e of t){let t=e.trim();if(X.some(e=>e.test(t)))continue;let r=e.match(/^(\S+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d+)\s+([A-Za-z]{3})\s+(\d{1,2})\s+(\S+)\s+(.+)$/);if(r){let t=(r[9]||``).trim();if(t===`.`||t===`..`)continue;n.push({name:t,isDir:r[1].startsWith(`d`),size:r[5],mode:r[1],mtime:fe(r[6],r[7],r[8]),owner:r[3],group:r[4],type:J(r[1]),line:e});continue}let i=Y(e);if(i){n.push({...i,line:e});continue}if(!/^[bcdlps-][rwxStTs-]{9}[+.@]?\s/.test(e))continue;let a=t.split(/\s+/),o=(a.length>=9?a.slice(8).join(` `):a[a.length-1]||``).trim();o&&o!==`.`&&o!==`..`&&n.push({name:o,isDir:e.startsWith(`d`),size:a[4]||``,mode:a[0]||``,owner:a[2]||``,group:a[3]||``,mtime:a[5]&&/^[A-Za-z]{3}$/.test(a[5])?fe(a[5],a[6],a[7]):``,type:J(a[0]),line:e})}return n}function Z(e){let t=String(e??``).trim();return t?(t=t.replace(/\\/g,`/`).replace(/\/{2,}/g,`/`),t.length>1&&(t=t.replace(/\/+$/,``)),/^[A-Za-z]:$/.test(t)?`${t}/`:t||`.`):`.`}function Q(e,t){let n=Z(e);return t?t.startsWith(`/`)||/^[A-Za-z]:/.test(t)||n===`.`?Z(t):Z(n===`/`?`/${t}`:`${n}/${t}`):n}function me(e){let t=Z(e);if(t===`.`||t===`/`||/^[A-Za-z]:\/$/.test(t))return t;let n=t.lastIndexOf(`/`);if(n<0)return`.`;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r}function he(e){let t=Z(e),n=/^[A-Za-z]:/.test(t),r=!n&&t.startsWith(`/`),i=n?t.replace(/^[A-Za-z]:\/?/,``):t.replace(/^\//,``),a=t===`.`||t===`/`||!i?[]:i.split(`/`),o=[{label:n?t.slice(0,2)+`/`:r?`/`:`.`,path:n?`${t.slice(0,2)}/`:r?`/`:`.`}];return a.forEach((e,i)=>{let s=a.slice(0,i+1).join(`/`);o.push({label:e,path:n?`${t.slice(0,2)}/${s}`:r?`/${s}`:s})}),o}var{Text:ge}=a;function _e(e,t){let n=new Blob([t],{type:`application/octet-stream`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e||`download.bin`,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function ve({connection:e,canWrite:t}){let n=x(),[r,i]=(0,N.useState)(`.`),[a,d]=(0,N.useState)(`.`),[f,p]=(0,N.useState)(``),[m,h]=(0,N.useState)([]),[v,y]=(0,N.useState)(!1),[b,C]=(0,N.useState)(null),[E,te]=(0,N.useState)(``),[D,O]=(0,N.useState)({visible:!1,mode:`read`,path:``,content:``,loading:!1}),[M,P]=(0,N.useState)({visible:!1,mode:`mkdir`,title:``,value:``,target:``}),F=(0,N.useCallback)(async t=>{if(!e?.id)return;let n=Z(t??r);y(!0),C(null);try{let t=await L({connection:e,action:`list`,path:n});if(!t?.ok&&t?.error){C(t.error),h([]),p(t.output||``);return}p(t?.output||``),h(pe(t?.output||``)),i(n),d(n)}catch(e){C(e),h([])}finally{y(!1)}},[e,r]);(0,N.useEffect)(()=>{i(`.`),d(`.`),h([]),p(``),F(`.`)},[e?.id]);let re=async t=>{try{let n=await L({connection:e,action:`read`,path:t});return n?.error&&!n?.ok?(w(n.error),null):n?.output??``}catch(e){return w(e),null}},ie=async(e,t)=>{O({visible:!0,mode:t,path:e,content:``,loading:!0});let n=await re(e);O(e=>({...e,content:n??``,loading:!1}))},ae=async()=>{try{let t=await L({connection:e,action:`write`,path:D.path,content:D.content});if(t?.error&&!t?.ok){w(t.error);return}A(n(`webshell.saveFile`,null,`已保存`)),O(e=>({...e,visible:!1})),F(r)}catch(e){w(e)}},oe=async(e,t)=>{let n=await re(e);n!==null&&_e(t,n)},I=t=>{j({title:n(`webshell.deleteFile`,null,`删除文件`),content:t,onOk:async()=>{try{let i=await L({connection:e,action:`delete`,path:t});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.deleteFile`,null,`已删除`)),F(r)}catch(e){w(e)}}})},se=async()=>{let t=String(M.value||``).trim();if(!t)S(n(`webshell.filePath`,null,`请填写路径`));else try{if(M.mode===`mkdir`){let i=await L({connection:e,action:`mkdir`,path:Q(r,t)});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.newDir`,null,`目录已创建`))}else if(M.mode===`create`){let i=await L({connection:e,action:`write`,path:Q(r,t),content:``});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.newFile`,null,`文件已创建`))}else if(M.mode===`rename`){let r=await L({connection:e,action:`rename`,path:M.target,targetPath:Q(me(M.target),t)});if(r?.error&&!r?.ok){w(r.error);return}A(n(`webshell.rename`,null,`已重命名`))}P(e=>({...e,visible:!1})),F(r)}catch(e){w(e)}},R=(0,N.useMemo)(()=>{let e=E.trim().toLowerCase();return e?m.filter(t=>t.name.toLowerCase().includes(e)):m},[m,E]),z=(0,N.useMemo)(()=>he(r),[r]),ce=[{title:n(`webshell.colName`,null,`名称`),dataIndex:`name`,render:(e,t)=>(0,B.jsxs)(`button`,{type:`button`,className:`webshell-file-name ${t.isDir?`is-dir`:`is-file`}`,onClick:()=>t.isDir?F(Q(r,e)):ie(Q(r,e),`read`),title:e,children:[e,t.isDir?`/`:``]})},{title:n(`webshell.colType`,null,`类型`),dataIndex:`type`,width:90},{title:n(`webshell.colSize`,null,`大小`),dataIndex:`size`,width:110},{title:n(`webshell.colModifiedAt`,null,`修改时间`),dataIndex:`mtime`,width:170},{title:n(`webshell.colOwner`,null,`所有者`),dataIndex:`owner`,width:120},{title:n(`webshell.colPerms`,null,`权限`),dataIndex:`mode`,width:130},{title:n(`webshell.moreActions`,null,`操作`),dataIndex:`ops`,width:240,render:(e,i)=>{let a=Q(r,i.name);return(0,B.jsxs)(o,{spacing:4,wrap:!0,children:[i.isDir?(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>F(a),children:n(`webshell.listDir`,null,`打开`)}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>ie(a,`read`),children:n(`webshell.readFile`,null,`读取`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>ie(a,`write`),children:n(`webshell.editFile`,null,`编辑`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>oe(a,i.name),children:n(`webshell.downloadFile`,null,`下载`)})]}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>P({visible:!0,mode:`rename`,title:n(`webshell.rename`,null,`重命名`),value:i.name,target:a}),children:n(`webshell.rename`,null,`重命名`)}),!i.isDir&&(0,B.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>I(a),children:n(`webshell.deleteFile`,null,`删除`)})]})}}];return(0,B.jsxs)(`div`,{className:`webshell-files`,children:[(0,B.jsx)(`div`,{className:`webshell-file-toolbar`,children:(0,B.jsxs)(o,{spacing:8,wrap:!0,children:[(0,B.jsx)(c,{size:`small`,onClick:()=>F(me(r)),children:n(`webshell.parentDir`,null,`上级目录`)}),(0,B.jsx)(c,{size:`small`,icon:(0,B.jsx)(_,{}),onClick:()=>F(r),loading:v,children:n(`webshell.refresh`,null,`刷新`)}),(0,B.jsx)(c,{size:`small`,disabled:!t,onClick:()=>P({visible:!0,mode:`mkdir`,title:n(`webshell.newDir`,null,`新建目录`),value:``,target:``}),children:n(`webshell.newDir`,null,`新建目录`)}),(0,B.jsx)(c,{size:`small`,disabled:!t,onClick:()=>P({visible:!0,mode:`create`,title:n(`webshell.newFile`,null,`新建文件`),value:``,target:``}),children:n(`webshell.newFile`,null,`新建文件`)})]})}),(0,B.jsxs)(`div`,{className:`webshell-file-pathbar`,children:[(0,B.jsx)(ge,{type:`tertiary`,children:n(`webshell.filePath`,null,`当前路径`)}),(0,B.jsx)(u,{value:a,onChange:d,onEnterPress:()=>F(a),size:`small`,className:`webshell-file-path-input`}),(0,B.jsx)(c,{size:`small`,icon:(0,B.jsx)(g,{}),onClick:()=>F(a),children:n(`webshell.listDir`,null,`列出目录`)}),(0,B.jsx)(u,{value:E,onChange:te,placeholder:n(`webshell.filterPlaceholder`,null,`过滤文件名`),size:`small`,className:`webshell-file-filter`})]}),(0,B.jsx)(`nav`,{className:`webshell-breadcrumb`,"aria-label":`breadcrumb`,children:z.map((e,t)=>(0,B.jsxs)(`span`,{className:`webshell-breadcrumb-item`,children:[t>0&&(0,B.jsx)(`span`,{className:`webshell-breadcrumb-sep`,children:`/`}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>F(e.path),title:e.path,children:t===0?n(`webshell.breadcrumbHome`,null,`根`):e.label})]},e.path))}),(0,B.jsx)(ee,{error:b,onRetry:()=>F(r)}),m.length===0&&f.trim()&&!v?(0,B.jsx)(ne,{title:n(`webshell.filePath`,null,`原始输出`),value:f}):(0,B.jsx)(k,{columns:ce,dataSource:R,rowKey:`name`,loading:v,pagination:{pageSize:20},emptyText:n(`webshell.emptyDir`,null,`目录为空`)}),(0,B.jsxs)(T,{visible:D.visible,title:D.mode===`write`?n(`webshell.editFile`,null,`编辑文件`):n(`webshell.readFile`,null,`读取文件`),width:760,onCancel:()=>O(e=>({...e,visible:!1})),footer:(0,B.jsxs)(o,{children:[(0,B.jsx)(c,{onClick:()=>O(e=>({...e,visible:!1})),children:n(`webshell.cancelEdit`,null,`关闭`)}),D.mode===`write`&&(0,B.jsx)(c,{theme:`solid`,type:`primary`,disabled:!t,onClick:ae,children:n(`webshell.saveFile`,null,`保存`)})]}),children:[(0,B.jsx)(`div`,{className:`webshell-editor-path`,children:(0,B.jsx)(s,{size:`small`,children:D.path})}),(0,B.jsx)(l,{value:D.content,onChange:e=>O(t=>({...t,content:e})),autosize:{minRows:12,maxRows:24},disabled:D.mode!==`write`,className:`webshell-editor-area`})]}),(0,B.jsx)(T,{visible:M.visible,title:M.title,width:420,onCancel:()=>P(e=>({...e,visible:!1})),onOk:se,children:(0,B.jsx)(u,{value:M.value,onChange:e=>P(t=>({...t,value:e})),placeholder:M.mode===`rename`?n(`webshell.rename`,null,`新名称`):n(`webshell.filePath`,null,`名称或路径`)})})]})}var ye=0,be=()=>(ye+=1,ye);function xe({connection:e,canWrite:t,onRecordCommand:n}){let r=x(),[i,a]=(0,N.useState)([]),[l,d]=(0,N.useState)(``),[f,m]=(0,N.useState)(!1),h=(0,N.useRef)(null),g=(0,N.useCallback)(e=>{a(t=>[...t,{id:be(),...e}])},[]);(0,N.useEffect)(()=>{a([]),d(``)},[e?.id]),(0,N.useEffect)(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let _=async i=>{let a=String(i??l).trim();if(a){if(!t)S(r(`webshell.webshellWriteRequired`,null,`当前账号没有执行权限`));else{d(``),g({kind:`cmd`,text:a}),n?.(a),m(!0);try{let t=await I({connection:e,command:a});t?.output&&g({kind:`out`,text:t.output}),t?.error&&g({kind:`err`,text:t.error}),!t?.ok&&!t?.error&&g({kind:`err`,text:r(`webshell.execError`,null,`执行失败`)})}catch(e){g({kind:`err`,text:e?.message||r(`webshell.execError`,null,`执行失败`)}),w(e)}finally{m(!1)}}}};return(0,B.jsxs)(`div`,{className:`webshell-terminal`,children:[(0,B.jsx)(`div`,{className:`webshell-terminal-bar`,children:(0,B.jsxs)(o,{spacing:8,children:[(0,B.jsx)(s,{size:`small`,color:f?`amber`:`green`,children:f?r(`webshell.terminalRunning`,null,`执行中`):r(`webshell.terminalIdle`,null,`空闲`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>a([]),children:r(`webshell.clearScreen`,null,`清屏`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:async()=>{let e=i.map(e=>e.kind===`cmd`?`$ ${e.text}`:e.text).join(`
-`);try{await navigator.clipboard.writeText(e),A(r(`webshell.terminalCopyOk`,null,`日志已复制`))}catch(e){w(e,r(`webshell.terminalCopyFail`,null,`复制失败`))}},children:r(`webshell.copyTerminalLog`,null,`复制日志`)})]})}),(0,B.jsxs)(`div`,{className:`webshell-terminal-log`,ref:h,children:[(0,B.jsx)(`div`,{className:`webshell-terminal-welcome`,children:r(`webshell.terminalWelcome`,null,`WebShell 虚拟终端 — 输入命令后按回车执行(Ctrl+L 清屏)`)}),i.map(e=>(0,B.jsx)(`pre`,{className:`webshell-terminal-line kind-${e.kind}`,children:e.kind===`cmd`?`$ ${e.text}`:e.text},e.id)),f&&(0,B.jsx)(`div`,{className:`webshell-terminal-pending`,children:r(`webshell.running`,null,`执行中…`)})]}),(0,B.jsxs)(`div`,{className:`webshell-terminal-input`,children:[(0,B.jsx)(u,{value:l,onChange:d,onEnterPress:()=>f?S(r(`webshell.waitFinish`,null,`请等待当前命令执行完成`)):_(),onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`l`&&(e.preventDefault(),a([]))},placeholder:r(`webshell.commandPlaceholder`,null,`输入命令后回车执行`),disabled:f||!t,prefix:`$`}),(0,B.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,B.jsx)(p,{}),loading:f,disabled:!t,onClick:()=>_(),children:r(`webshell.runCommand`,null,`执行`)})]})]})}var{Text:Se}=a;function Ce({history:e,onClear:t,onRemove:n,onRun:r}){let i=x(),a=e.map((e,t)=>({...e,rowId:`${t}-${e.at}`})),s=[{title:i(`webshell.colCommand`,null,`命令`),dataIndex:`command`,render:e=>(0,B.jsx)(`code`,{className:`webshell-history-cmd`,children:e})},{title:i(`webshell.colExecutedAt`,null,`执行时间`),dataIndex:`at`,width:200,render:e=>v(e)},{title:i(`webshell.moreActions`,null,`操作`),dataIndex:`ops`,width:220,render:(e,t)=>(0,B.jsxs)(o,{spacing:4,children:[(0,B.jsx)(D,{text:t.command,label:i(`common.copied`,null,`复制`),size:`small`}),r&&(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>r(t.command),children:i(`webshell.rerun`,null,`再执行`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,onClick:()=>j({title:i(`webshell.deleteHistory`,null,`删除该条历史`),content:t.command,onOk:()=>n(t.rowId)}),children:i(`webshell.deleteFile`,null,`删除`)})]})}];return(0,B.jsxs)(`div`,{className:`webshell-history`,children:[(0,B.jsxs)(`div`,{className:`webshell-history-toolbar`,children:[(0,B.jsx)(Se,{type:`tertiary`,children:i(`webshell.historyHint`,null,`仅记录本连接在当前浏览器执行过的命令`)}),(0,B.jsx)(o,{spacing:8,children:t&&(0,B.jsx)(c,{size:`small`,disabled:!a.length,onClick:()=>t(),children:i(`webshell.clearHistory`,null,`清空历史`)})})]}),(0,B.jsx)(k,{columns:s,dataSource:a,rowKey:`rowId`,pagination:{pageSize:15},emptyText:i(`webshell.noHistory`,null,`暂无命令历史`)})]})}var{Text:we}=a,Te={user:`blue`,assistant:`green`,system:`grey`,tool:`violet`};function Ee({connection:e}){let t=x(),[n,r]=(0,N.useState)([]),[a,o]=(0,N.useState)(``),[l,u]=(0,N.useState)([]),[f,p]=(0,N.useState)(!1),[m,h]=(0,N.useState)(null),g=(0,N.useCallback)(async()=>{if(e?.id){p(!0),h(null);try{let[t,n]=await Promise.all([se(e.id).catch(()=>[]),R(e.id).catch(()=>null)]),i=Array.isArray(t)?t:[];r(i);let a=n?.conversationId||i[0]?.id||``;if(o(a),n?.conversationId)u(Array.isArray(n.messages)?n.messages:[]);else if(a){let e=await z(a).catch(()=>null);u(Array.isArray(e?.messages)?e.messages:[])}else u([])}catch(e){h(e)}finally{p(!1)}}},[e?.id]);(0,N.useEffect)(()=>{g()},[g]);let y=async e=>{if(e){o(e),p(!0);try{let t=await z(e);u(Array.isArray(t?.messages)?t.messages:[])}catch(e){h(e),u([])}finally{p(!1)}}};return(0,B.jsxs)(`div`,{className:`webshell-ai`,children:[(0,B.jsxs)(`div`,{className:`webshell-ai-sidebar`,children:[(0,B.jsxs)(`div`,{className:`webshell-ai-sidebar-head`,children:[(0,B.jsx)(we,{strong:!0,children:t(`webshell.aiPreviousConversation`,null,`之前的对话`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,icon:(0,B.jsx)(_,{}),onClick:g,loading:f})]}),n.length===0?(0,B.jsx)(i,{title:t(`webshell.aiNoConversation`,null,`暂无 AI 会话`),description:null,style:{padding:24}}):(0,B.jsx)(`ul`,{className:`webshell-ai-list`,children:n.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`button`,{type:`button`,className:`webshell-ai-item ${e.id===a?`is-active`:``}`,onClick:()=>y(e.id),children:[(0,B.jsx)(`span`,{className:`webshell-ai-title`,children:e.title||e.id}),(0,B.jsx)(`span`,{className:`webshell-ai-time`,children:v(e.updatedAt)})]})},e.id))})]}),(0,B.jsxs)(`div`,{className:`webshell-ai-main`,children:[(0,B.jsx)(ee,{error:m,onRetry:g}),f&&(0,B.jsx)(`div`,{className:`webshell-ai-loading`,children:(0,B.jsx)(d,{})}),!f&&l.length===0&&(0,B.jsx)(i,{title:t(`webshell.aiNoMessage`,null,`暂无对话消息`),description:null,style:{padding:48}}),!f&&l.map(e=>(0,B.jsxs)(`div`,{className:`webshell-ai-message`,children:[(0,B.jsxs)(`div`,{className:`webshell-ai-message-head`,children:[(0,B.jsx)(s,{size:`small`,color:Te[e.role]||`grey`,children:e.role||`message`}),(0,B.jsx)(we,{type:`tertiary`,size:`small`,children:v(e.createdAt)})]}),(0,B.jsx)(E,{content:e.content||``})]},e.id||`${e.role}-${e.createdAt}`))]})]})}var{Text:$}=a,De={auto:`自动`,"utf-8":`UTF-8`,gbk:`GBK`,gb18030:`GB18030`};function Oe(e){return e===`online`?`green`:e===`probing`?`amber`:e===`offline`?`red`:`grey`}function ke(){let e=x(),{hasPermission:t}=y(),n=t(`webshell:write`),a=t(`webshell:delete`)||n,[p,h]=r(),v=p.get(`id`)||``,[b,T]=(0,N.useState)(``),E=te(b,250),[D,k]=(0,N.useState)({}),[ne,M]=(0,N.useState)(!1),[I,L]=(0,N.useState)({visible:!1,record:null}),[se,R]=(0,N.useState)(!1),[z,le]=(0,N.useState)([]),[V,H]=(0,N.useState)(``),[U,W]=(0,N.useState)([]),G=(0,N.useRef)(null),{data:K,loading:q,error:fe,reload:J}=C(()=>P(),[]),Y=(0,N.useMemo)(()=>Array.isArray(K)?K:[],[K]);(0,N.useEffect)(()=>{ce().then(le)},[]);let X=(0,N.useMemo)(()=>Y.find(e=>e.id===v)||null,[Y,v]),pe=e=>{let t=new URLSearchParams(p);e?t.set(`id`,e):t.delete(`id`),h(t,{replace:!0})},Z=(0,N.useCallback)(e=>{n&&v&&(G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{oe(v,e).catch(()=>{})},700))},[n,v]);(0,N.useEffect)(()=>{let e=!1;return H(``),W([]),v&&ae(v).then(t=>{if(e)return;let n=t?.state||{};H(typeof n.memo==`string`?n.memo:``),W(Array.isArray(n.commands)?n.commands:[])}).catch(()=>{}),()=>{e=!0}},[v]);let Q=e=>{H(e),Z({memo:e,commands:U})},me=e=>{let t=[...U,{command:e,at:new Date().toISOString()}].slice(-200);W(t),Z({memo:V,commands:t})},he=e=>{let t=U.filter((t,n)=>`${n}-${t.at}`!==e);W(t),Z({memo:V,commands:t})},ge=()=>{j({title:e(`webshell.clearHistory`,null,`清空历史`),content:e(`webshell.clearHistoryConfirm`,null,`确定清空该连接的命令历史?`),onOk:()=>{W([]),Z({memo:V,commands:[]})}})},_e=async e=>{k(t=>({...t,[e.id]:`probing`}));try{let t=await ue(e);return k(n=>({...n,[e.id]:t.ok?`online`:`offline`})),t.ok}catch{return k(t=>({...t,[e.id]:`offline`})),!1}},ye=async()=>{if(!Y.length)S(e(`webshell.probeNoConnections`,null,`暂无可探活连接`));else{M(!0);for(let e of Y)await _e(e);M(!1)}},be=async t=>{R(!0);try{if(I.record?.id)await re(I.record.id,t),A(e(`webshell.toastUpdated`,null,`连接已更新`));else{let n=await F(t);A(e(`webshell.toastCreated`,null,`连接已创建`)),n?.id&&pe(n.id)}L({visible:!1,record:null}),J()}catch(t){w(t,e(`webshell.saveFailed`,null,`保存失败`))}finally{R(!1)}},Se=t=>{j({title:e(`webshell.deleteConfirm`,null,`确定要删除该连接吗?`),content:t.url,onOk:async()=>{try{await ie(t.id),A(e(`webshell.toastDeleted`,null,`连接已删除`)),t.id===v&&pe(``),J()}catch(e){w(e)}}})},we=(0,N.useMemo)(()=>{let e=E.trim().toLowerCase();return e?Y.filter(t=>[t.url,t.remark,t.type,t.id].filter(Boolean).some(t=>String(t).toLowerCase().includes(e))):Y},[Y,E]),Te=[{tab:e(`webshell.tabTerminal`,null,`虚拟终端`),itemKey:`terminal`,children:X?(0,B.jsx)(xe,{connection:X,canWrite:n,onRecordCommand:me}):null},{tab:e(`webshell.tabFileManager`,null,`文件管理`),itemKey:`files`,children:X?(0,B.jsx)(ve,{connection:X,canWrite:n}):null},{tab:e(`webshell.tabHistory`,null,`命令历史`),itemKey:`history`,children:(0,B.jsx)(Ce,{history:U,onRemove:he,onClear:n?ge:null,onRun:e=>X?me(e):null})},{tab:e(`webshell.tabAiSessions`,null,`AI 会话`),itemKey:`ai`,children:X?(0,B.jsx)(Ee,{connection:X}):null},{tab:e(`webshell.tabMemo`,null,`备忘录`),itemKey:`memo`,children:(0,B.jsx)(l,{value:V,onChange:Q,autosize:{minRows:10,maxRows:20},placeholder:e(`webshell.aiMemoPlaceholder`,null,`记录关键命令、测试思路、复现步骤...`),disabled:!n})}];return(0,B.jsxs)(`div`,{className:`webshell-page`,id:`page-webshell`,children:[(0,B.jsx)(O,{title:e(`webshell.title`,null,`WebShell 管理`),description:e(`webshell.pageDesc`,null,`统一管理 WebShell 连接,代理执行命令并浏览目标文件`),extra:[(0,B.jsx)(c,{icon:(0,B.jsx)(_,{}),onClick:J,loading:q,children:e(`webshell.refresh`,null,`刷新`)},`refresh`),(0,B.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,B.jsx)(m,{}),disabled:!n,onClick:()=>L({visible:!0,record:null}),children:e(`webshell.addConnection`,null,`添加连接`)},`add`)]}),(0,B.jsx)(ee,{error:fe,onRetry:J}),(0,B.jsxs)(`div`,{className:`webshell-layout`,children:[(0,B.jsxs)(`aside`,{className:`webshell-sidebar`,children:[(0,B.jsxs)(`div`,{className:`webshell-sidebar-head`,children:[(0,B.jsx)($,{strong:!0,children:e(`webshell.connections`,null,`连接列表`)}),(0,B.jsx)(s,{size:`small`,children:Y.length})]}),(0,B.jsx)(u,{value:b,onChange:T,prefix:(0,B.jsx)(g,{}),placeholder:e(`webshell.searchPlaceholder`,null,`搜索连接...`),size:`small`}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,loading:ne,onClick:ye,disabled:!Y.length,children:e(`webshell.batchProbe`,null,`一键批量探活`)}),(0,B.jsxs)(`div`,{className:`webshell-conn-list`,children:[q&&!Y.length&&(0,B.jsx)(`div`,{className:`webshell-conn-loading`,children:(0,B.jsx)(d,{})}),!q&&we.length===0&&(0,B.jsx)($,{type:`tertiary`,className:`webshell-conn-empty`,children:Y.length?e(`webshell.noMatchConnections`,null,`暂无匹配连接`):e(`webshell.noConnections`,null,`暂无连接,请点击「添加连接」`)}),we.map(t=>(0,B.jsxs)(`button`,{type:`button`,className:`webshell-conn-item ${t.id===v?`is-active`:``}`,onClick:()=>pe(t.id),children:[(0,B.jsx)(`span`,{className:`webshell-conn-url`,title:t.url,children:t.remark||t.url}),(0,B.jsxs)(`span`,{className:`webshell-conn-meta`,children:[(0,B.jsx)(s,{size:`small`,color:`blue`,children:String(t.type||`php`).toUpperCase()}),D[t.id]&&(0,B.jsx)(s,{size:`small`,color:Oe(D[t.id]),children:D[t.id]===`online`?e(`webshell.probeOnline`,null,`在线`):D[t.id]===`probing`?e(`webshell.probeRunning`,null,`探活中`):e(`webshell.probeOffline`,null,`离线`)})]})]},t.id))]})]}),(0,B.jsx)(`section`,{className:`webshell-main`,children:X?(0,B.jsxs)(`div`,{className:`webshell-workspace`,children:[(0,B.jsxs)(`div`,{className:`webshell-workspace-head`,children:[(0,B.jsxs)(`div`,{className:`webshell-workspace-title`,children:[(0,B.jsx)($,{strong:!0,ellipsis:{showTooltip:!0},className:`webshell-workspace-url`,children:X.url}),(0,B.jsxs)(o,{spacing:6,wrap:!0,children:[(0,B.jsx)(s,{size:`small`,color:`blue`,children:String(X.type||`php`).toUpperCase()}),(0,B.jsx)(s,{size:`small`,children:String(X.method||`post`).toUpperCase()}),(0,B.jsx)(s,{size:`small`,children:De[X.encoding]||`自动`}),(0,B.jsx)(s,{size:`small`,children:X.os===`windows`?`Windows`:X.os===`linux`?`Linux`:`OS 自动`}),X.remark&&(0,B.jsx)($,{type:`tertiary`,size:`small`,children:X.remark})]})]}),(0,B.jsxs)(o,{spacing:8,children:[(0,B.jsx)(c,{size:`small`,loading:D[X.id]===`probing`,onClick:()=>_e(X),children:e(`webshell.testConnectivity`,null,`测试连通性`)}),(0,B.jsx)(c,{size:`small`,disabled:!n,onClick:()=>L({visible:!0,record:X}),children:e(`webshell.editConnection`,null,`编辑`)}),(0,B.jsx)(c,{size:`small`,type:`danger`,disabled:!a,onClick:()=>Se(X),children:e(`webshell.deleteFile`,null,`删除`)})]})]}),(0,B.jsx)(f,{type:`line`,defaultActiveKey:`terminal`,className:`webshell-tabs`,items:Te},X.id)]}):(0,B.jsx)(i,{title:e(`webshell.selectOrAdd`,null,`请从左侧选择连接,或添加新的 WebShell 连接`),description:null,style:{padding:64}})})]}),(0,B.jsx)(de,{visible:I.visible,record:I.record,projects:z,submitting:se,onCancel:()=>L({visible:!1,record:null}),onSubmit:be})]})}export{ke as default};
\ No newline at end of file
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{E as i,G as a,I as o,N as s,R as c,S as l,U as u,W as d,c as f,ct as p,ft as m,i as h,lt as g,ut as _}from"./semi-65W_4I1v.js";import{E as v,F as y,I as b,L as x,S,a as C,b as w,c as T,f as E,l as ee,n as te,o as D,p as O,s as k,u as ne,x as A,y as j}from"./index-_8d9XBPJ.js";import{t as M}from"./project-options-CMQbwv_U.js";var N=e(t(),1);function P(e){return x.get(`/webshell/connections`,e)}function F(e){return x.post(`/webshell/connections`,e)}function re(e,t){return x.put(`/webshell/connections/${encodeURIComponent(e)}`,t)}function ie(e){return x.del(`/webshell/connections/${encodeURIComponent(e)}`)}function ae(e){return x.get(`/webshell/connections/${encodeURIComponent(e)}/state`)}function oe(e,t){return x.put(`/webshell/connections/${encodeURIComponent(e)}/state`,{state:t})}function I({connection:e,command:t}){return x.post(`/webshell/exec`,{connection_id:e.id,url:e.url,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,command:t})}function L({connection:e,action:t,path:n,targetPath:r,content:i,chunkIndex:a}){let o={connection_id:e.id,url:e.url,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,action:t};return n!==void 0&&(o.path=n),r!==void 0&&(o.target_path=r),i!==void 0&&(o.content=i),a!==void 0&&(o.chunk_index=a),x.post(`/webshell/file`,o)}function se(e){return x.get(`/webshell/connections/${encodeURIComponent(e)}/ai-conversations`)}function R(e){return x.get(`/webshell/connections/${encodeURIComponent(e)}/ai-history`)}function z(e){return x.get(`/conversations/${encodeURIComponent(e)}`,{include_process_details:0})}async function ce(){try{let e=await x.get(`/projects`,{limit:200});return Array.isArray(e?.projects)?e.projects:[]}catch{return[]}}function le(){return`__CSAI_PROBE_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}__`}async function ue(e){let t=le(),n=await I({connection:e,command:`echo ${t}`});return{ok:!!n?.ok&&String(n?.output||``).includes(t),output:n?.output||``,error:n?.error||``}}var B=e(n(),1),{Text:V}=a,H=[{value:`php`,label:`PHP`},{value:`asp`,label:`ASP`},{value:`aspx`,label:`ASPX`},{value:`jsp`,label:`JSP`},{value:`custom`,label:`自定义`}],U=[{value:`post`,label:`POST`},{value:`get`,label:`GET`}],W=[{value:`auto`,label:`自动检测`},{value:`utf-8`,label:`UTF-8`},{value:`gbk`,label:`GBK(中文 Windows)`},{value:`gb18030`,label:`GB18030`}],G=[{value:`auto`,label:`自动(按 Shell 类型推断)`},{value:`linux`,label:`Linux / Unix`},{value:`windows`,label:`Windows`}];function K(e){return e?{url:e.url||``,password:e.password||``,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,remark:e.remark||``,project_id:e.project_id||``}:{url:``,password:``,type:`php`,method:`post`,cmd_param:``,encoding:`auto`,os:`auto`,remark:``,project_id:``}}function de({visible:e,record:t,projects:n,submitting:r,onCancel:i,onSubmit:a}){let s=y(),[l,u]=(0,N.useState)(null),[d,f]=(0,N.useState)(!1);return(0,B.jsx)(T,{visible:e,title:t?s(`webshell.editConnectionTitle`,null,`编辑连接`):s(`webshell.addConnection`,null,`添加连接`),footer:(0,B.jsxs)(o,{children:[(0,B.jsx)(c,{onClick:async()=>{let e=l?.getValues?.()||{},n=String(e.url||``).trim();if(!n)S(s(`webshell.url`,null,`请填写 Shell 地址`));else if(e.password===`********`)S(s(`webshell.testNoExpectedOutput`,null,`已保存口令不可用于新建测试,请填写口令`));else{f(!0);try{let r=await ue({id:t?.id||``,url:n,password:e.password||``,type:e.type||`php`,method:e.method||`post`,cmdParam:e.cmd_param||``,encoding:e.encoding||`auto`,os:e.os||`auto`});r.ok?A(s(`webshell.testSuccess`,null,`连通性正常,Shell 可访问`)):w(r.error||s(`webshell.testFailed`,null,`连通性测试失败`))}catch(e){w(e,s(`webshell.testFailed`,null,`连通性测试失败`))}finally{f(!1)}}},loading:d,children:s(`webshell.testConnectivity`,null,`测试连通性`)}),(0,B.jsx)(c,{onClick:i,children:s(`webshell.cancelEdit`,null,`取消`)}),(0,B.jsx)(c,{theme:`solid`,type:`primary`,loading:r,onClick:()=>l?.submitForm(),children:t?s(`webshell.saveFile`,null,`保存`):s(`webshell.addConnection`,null,`添加连接`)})]}),width:600,onCancel:i,children:(0,B.jsxs)(h,{initValues:K(t),onSubmit:e=>{a({url:String(e.url||``).trim(),password:e.password||``,type:e.type||`php`,method:e.method||`post`,cmd_param:String(e.cmd_param||``).trim(),encoding:e.encoding||`auto`,os:e.os||`auto`,remark:String(e.remark||``).trim(),project_id:e.project_id||``})},getFormApi:u,labelPosition:`top`,children:[(0,B.jsx)(h.Input,{field:`url`,label:s(`webshell.url`,null,`Shell 地址`),placeholder:`http(s)://target.com/shell.php`,rules:[{required:!0,message:s(`webshell.url`,null,`请填写 Shell 地址`)}]}),(0,B.jsx)(h.Input,{field:`password`,label:s(`webshell.password`,null,`连接密码/密钥`),placeholder:s(`webshell.passwordPlaceholder`,null,`如冰蝎/蚁剑的连接密码`)}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Select,{field:`type`,label:s(`webshell.type`,null,`Shell 类型`),optionList:H,style:{width:`100%`}}),(0,B.jsx)(h.Select,{field:`method`,label:s(`webshell.method`,null,`请求方式`),optionList:U,style:{width:`100%`}})]}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Input,{field:`cmd_param`,label:s(`webshell.cmdParam`,null,`命令参数名`),placeholder:`cmd`}),(0,B.jsx)(h.Select,{field:`encoding`,label:s(`webshell.encoding`,null,`响应编码`),optionList:W,style:{width:`100%`}})]}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Select,{field:`os`,label:s(`webshell.os`,null,`目标系统`),optionList:G,style:{width:`100%`}}),(0,B.jsx)(h.Select,{field:`project_id`,label:s(`webshell.project`,null,`所属项目`),optionList:M(n,s,{currentId:t?.project_id||``}),showClear:!0,style:{width:`100%`},placeholder:`可选`})]}),(0,B.jsx)(h.Input,{field:`remark`,label:s(`webshell.remark`,null,`备注`),placeholder:s(`webshell.remarkPlaceholder`,null,`便于识别的备注名`)}),(0,B.jsx)(V,{type:`tertiary`,size:`small`,children:s(`webshell.encodingHint`,null,`中文 Windows 目标若出现乱码,请切换为 GBK 或 GB18030`)})]},t?.id||`new`)})}var q={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11};function fe(e,t,n){if(!e||!t||!n)return``;let r=String(n).trim();if(/^\d{4}$/.test(r))return`${r} ${e} ${t}`;let i=new Date,a=i.getFullYear();if(/^\d{1,2}:\d{2}$/.test(r)){let n=q[e],o=parseInt(t,10);return n!=null&&!Number.isNaN(o)&&new Date(a,n,o).getTime()>i.getTime()&&--a,`${a} ${e} ${t} ${r}`}return`${e} ${t} ${r}`}function J(e){if(!e)return``;let t=e.charAt(0);return{d:`dir`,"-":`file`,l:`link`,c:`char`,b:`block`,s:`socket`,p:`pipe`}[t]||t}function Y(e){let t=String(e||``).match(/^(\d{4}[/-]\d{1,2}[/-]\d{1,2})\s+(\d{1,2}:\d{2})(?:\s*(AM|PM))?\s+(<[^>]+>|[\d,]+)\s+(.+?)\s*$/i);if(!t)return null;let n=(t[4]||``).trim(),r=(t[5]||``).trim();if(!r||r===`.`||r===`..`)return null;let i=/^<(dir|junction|symlinkd)>$/i.test(n);return{name:r,isDir:i,size:i?``:n.replace(/,/g,``),mtime:`${t[1]} ${t[2]}${t[3]?` ${t[3].toUpperCase()}`:``}`.trim(),mode:i?`d`:`-`,owner:``,group:``,type:i?`dir`:`file`}}var X=[/^(total|总计)\s+\d+$/i,/^(驱动器|卷的序列号是|volume in drive|volume serial number is|directory of)/i,/^[A-Za-z]:\\.*\s+的目录$/i,/^\d+\s+(个文件|file\(s\))\s+[\d,]+\s+(字节|bytes?)$/i,/^\d+\s+(个目录|dir\(s\))\s+[\d,]+\s+(可用字节|bytes free)$/i,/^[^>\n]*>\s*dir(?:\s|$)/i];function pe(e){let t=String(e||``).split(/\n/).filter(e=>e.trim()),n=[];for(let e of t){let t=e.trim();if(X.some(e=>e.test(t)))continue;let r=e.match(/^(\S+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d+)\s+([A-Za-z]{3})\s+(\d{1,2})\s+(\S+)\s+(.+)$/);if(r){let t=(r[9]||``).trim();if(t===`.`||t===`..`)continue;n.push({name:t,isDir:r[1].startsWith(`d`),size:r[5],mode:r[1],mtime:fe(r[6],r[7],r[8]),owner:r[3],group:r[4],type:J(r[1]),line:e});continue}let i=Y(e);if(i){n.push({...i,line:e});continue}if(!/^[bcdlps-][rwxStTs-]{9}[+.@]?\s/.test(e))continue;let a=t.split(/\s+/),o=(a.length>=9?a.slice(8).join(` `):a[a.length-1]||``).trim();o&&o!==`.`&&o!==`..`&&n.push({name:o,isDir:e.startsWith(`d`),size:a[4]||``,mode:a[0]||``,owner:a[2]||``,group:a[3]||``,mtime:a[5]&&/^[A-Za-z]{3}$/.test(a[5])?fe(a[5],a[6],a[7]):``,type:J(a[0]),line:e})}return n}function Z(e){let t=String(e??``).trim();return t?(t=t.replace(/\\/g,`/`).replace(/\/{2,}/g,`/`),t.length>1&&(t=t.replace(/\/+$/,``)),/^[A-Za-z]:$/.test(t)?`${t}/`:t||`.`):`.`}function Q(e,t){let n=Z(e);return t?t.startsWith(`/`)||/^[A-Za-z]:/.test(t)||n===`.`?Z(t):Z(n===`/`?`/${t}`:`${n}/${t}`):n}function me(e){let t=Z(e);if(t===`.`||t===`/`||/^[A-Za-z]:\/$/.test(t))return t;let n=t.lastIndexOf(`/`);if(n<0)return`.`;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r}function he(e){let t=Z(e),n=/^[A-Za-z]:/.test(t),r=!n&&t.startsWith(`/`),i=n?t.replace(/^[A-Za-z]:\/?/,``):t.replace(/^\//,``),a=t===`.`||t===`/`||!i?[]:i.split(`/`),o=[{label:n?t.slice(0,2)+`/`:r?`/`:`.`,path:n?`${t.slice(0,2)}/`:r?`/`:`.`}];return a.forEach((e,i)=>{let s=a.slice(0,i+1).join(`/`);o.push({label:e,path:n?`${t.slice(0,2)}/${s}`:r?`/${s}`:s})}),o}var{Text:ge}=a;function _e(e,t){let n=new Blob([t],{type:`application/octet-stream`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e||`download.bin`,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function ve({connection:e,canWrite:t}){let n=y(),[r,i]=(0,N.useState)(`.`),[a,d]=(0,N.useState)(`.`),[f,p]=(0,N.useState)(``),[m,h]=(0,N.useState)([]),[v,b]=(0,N.useState)(!1),[x,C]=(0,N.useState)(null),[E,te]=(0,N.useState)(``),[D,O]=(0,N.useState)({visible:!1,mode:`read`,path:``,content:``,loading:!1}),[M,P]=(0,N.useState)({visible:!1,mode:`mkdir`,title:``,value:``,target:``}),F=(0,N.useCallback)(async t=>{if(!e?.id)return;let n=Z(t??r);b(!0),C(null);try{let t=await L({connection:e,action:`list`,path:n});if(!t?.ok&&t?.error){C(t.error),h([]),p(t.output||``);return}p(t?.output||``),h(pe(t?.output||``)),i(n),d(n)}catch(e){C(e),h([])}finally{b(!1)}},[e,r]);(0,N.useEffect)(()=>{i(`.`),d(`.`),h([]),p(``),F(`.`)},[e?.id]);let re=async t=>{try{let n=await L({connection:e,action:`read`,path:t});return n?.error&&!n?.ok?(w(n.error),null):n?.output??``}catch(e){return w(e),null}},ie=async(e,t)=>{O({visible:!0,mode:t,path:e,content:``,loading:!0});let n=await re(e);O(e=>({...e,content:n??``,loading:!1}))},ae=async()=>{try{let t=await L({connection:e,action:`write`,path:D.path,content:D.content});if(t?.error&&!t?.ok){w(t.error);return}A(n(`webshell.saveFile`,null,`已保存`)),O(e=>({...e,visible:!1})),F(r)}catch(e){w(e)}},oe=async(e,t)=>{let n=await re(e);n!==null&&_e(t,n)},I=t=>{j({title:n(`webshell.deleteFile`,null,`删除文件`),content:t,onOk:async()=>{try{let i=await L({connection:e,action:`delete`,path:t});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.deleteFile`,null,`已删除`)),F(r)}catch(e){w(e)}}})},se=async()=>{let t=String(M.value||``).trim();if(!t)S(n(`webshell.filePath`,null,`请填写路径`));else try{if(M.mode===`mkdir`){let i=await L({connection:e,action:`mkdir`,path:Q(r,t)});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.newDir`,null,`目录已创建`))}else if(M.mode===`create`){let i=await L({connection:e,action:`write`,path:Q(r,t),content:``});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.newFile`,null,`文件已创建`))}else if(M.mode===`rename`){let r=await L({connection:e,action:`rename`,path:M.target,targetPath:Q(me(M.target),t)});if(r?.error&&!r?.ok){w(r.error);return}A(n(`webshell.rename`,null,`已重命名`))}P(e=>({...e,visible:!1})),F(r)}catch(e){w(e)}},R=(0,N.useMemo)(()=>{let e=E.trim().toLowerCase();return e?m.filter(t=>t.name.toLowerCase().includes(e)):m},[m,E]),z=(0,N.useMemo)(()=>he(r),[r]),ce=[{title:n(`webshell.colName`,null,`名称`),dataIndex:`name`,render:(e,t)=>(0,B.jsxs)(`button`,{type:`button`,className:`webshell-file-name ${t.isDir?`is-dir`:`is-file`}`,onClick:()=>t.isDir?F(Q(r,e)):ie(Q(r,e),`read`),title:e,children:[e,t.isDir?`/`:``]})},{title:n(`webshell.colType`,null,`类型`),dataIndex:`type`,width:90},{title:n(`webshell.colSize`,null,`大小`),dataIndex:`size`,width:110},{title:n(`webshell.colModifiedAt`,null,`修改时间`),dataIndex:`mtime`,width:170},{title:n(`webshell.colOwner`,null,`所有者`),dataIndex:`owner`,width:120},{title:n(`webshell.colPerms`,null,`权限`),dataIndex:`mode`,width:130},{title:n(`webshell.moreActions`,null,`操作`),dataIndex:`ops`,width:240,render:(e,i)=>{let a=Q(r,i.name);return(0,B.jsxs)(o,{spacing:4,wrap:!0,children:[i.isDir?(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>F(a),children:n(`webshell.listDir`,null,`打开`)}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>ie(a,`read`),children:n(`webshell.readFile`,null,`读取`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>ie(a,`write`),children:n(`webshell.editFile`,null,`编辑`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>oe(a,i.name),children:n(`webshell.downloadFile`,null,`下载`)})]}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>P({visible:!0,mode:`rename`,title:n(`webshell.rename`,null,`重命名`),value:i.name,target:a}),children:n(`webshell.rename`,null,`重命名`)}),!i.isDir&&(0,B.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>I(a),children:n(`webshell.deleteFile`,null,`删除`)})]})}}];return(0,B.jsxs)(`div`,{className:`webshell-files`,children:[(0,B.jsx)(`div`,{className:`webshell-file-toolbar`,children:(0,B.jsxs)(o,{spacing:8,wrap:!0,children:[(0,B.jsx)(c,{size:`small`,onClick:()=>F(me(r)),children:n(`webshell.parentDir`,null,`上级目录`)}),(0,B.jsx)(c,{size:`small`,icon:(0,B.jsx)(_,{}),onClick:()=>F(r),loading:v,children:n(`webshell.refresh`,null,`刷新`)}),(0,B.jsx)(c,{size:`small`,disabled:!t,onClick:()=>P({visible:!0,mode:`mkdir`,title:n(`webshell.newDir`,null,`新建目录`),value:``,target:``}),children:n(`webshell.newDir`,null,`新建目录`)}),(0,B.jsx)(c,{size:`small`,disabled:!t,onClick:()=>P({visible:!0,mode:`create`,title:n(`webshell.newFile`,null,`新建文件`),value:``,target:``}),children:n(`webshell.newFile`,null,`新建文件`)})]})}),(0,B.jsxs)(`div`,{className:`webshell-file-pathbar`,children:[(0,B.jsx)(ge,{type:`tertiary`,children:n(`webshell.filePath`,null,`当前路径`)}),(0,B.jsx)(u,{value:a,onChange:d,onEnterPress:()=>F(a),size:`small`,className:`webshell-file-path-input`}),(0,B.jsx)(c,{size:`small`,icon:(0,B.jsx)(g,{}),onClick:()=>F(a),children:n(`webshell.listDir`,null,`列出目录`)}),(0,B.jsx)(u,{value:E,onChange:te,placeholder:n(`webshell.filterPlaceholder`,null,`过滤文件名`),size:`small`,className:`webshell-file-filter`})]}),(0,B.jsx)(`nav`,{className:`webshell-breadcrumb`,"aria-label":`breadcrumb`,children:z.map((e,t)=>(0,B.jsxs)(`span`,{className:`webshell-breadcrumb-item`,children:[t>0&&(0,B.jsx)(`span`,{className:`webshell-breadcrumb-sep`,children:`/`}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>F(e.path),title:e.path,children:t===0?n(`webshell.breadcrumbHome`,null,`根`):e.label})]},e.path))}),(0,B.jsx)(ee,{error:x,onRetry:()=>F(r)}),m.length===0&&f.trim()&&!v?(0,B.jsx)(ne,{title:n(`webshell.filePath`,null,`原始输出`),value:f}):(0,B.jsx)(k,{columns:ce,dataSource:R,rowKey:`name`,loading:v,pagination:{pageSize:20},emptyText:n(`webshell.emptyDir`,null,`目录为空`)}),(0,B.jsxs)(T,{visible:D.visible,title:D.mode===`write`?n(`webshell.editFile`,null,`编辑文件`):n(`webshell.readFile`,null,`读取文件`),width:760,onCancel:()=>O(e=>({...e,visible:!1})),footer:(0,B.jsxs)(o,{children:[(0,B.jsx)(c,{onClick:()=>O(e=>({...e,visible:!1})),children:n(`webshell.cancelEdit`,null,`关闭`)}),D.mode===`write`&&(0,B.jsx)(c,{theme:`solid`,type:`primary`,disabled:!t,onClick:ae,children:n(`webshell.saveFile`,null,`保存`)})]}),children:[(0,B.jsx)(`div`,{className:`webshell-editor-path`,children:(0,B.jsx)(s,{size:`small`,children:D.path})}),(0,B.jsx)(l,{value:D.content,onChange:e=>O(t=>({...t,content:e})),autosize:{minRows:12,maxRows:24},disabled:D.mode!==`write`,className:`webshell-editor-area`})]}),(0,B.jsx)(T,{visible:M.visible,title:M.title,width:420,onCancel:()=>P(e=>({...e,visible:!1})),onOk:se,children:(0,B.jsx)(u,{value:M.value,onChange:e=>P(t=>({...t,value:e})),placeholder:M.mode===`rename`?n(`webshell.rename`,null,`新名称`):n(`webshell.filePath`,null,`名称或路径`)})})]})}var ye=0,be=()=>(ye+=1,ye);function xe({connection:e,canWrite:t,onRecordCommand:n}){let r=y(),[i,a]=(0,N.useState)([]),[l,d]=(0,N.useState)(``),[f,m]=(0,N.useState)(!1),h=(0,N.useRef)(null),g=(0,N.useCallback)(e=>{a(t=>[...t,{id:be(),...e}])},[]);(0,N.useEffect)(()=>{a([]),d(``)},[e?.id]),(0,N.useEffect)(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let _=async i=>{let a=String(i??l).trim();if(a){if(!t)S(r(`webshell.webshellWriteRequired`,null,`当前账号没有执行权限`));else{d(``),g({kind:`cmd`,text:a}),n?.(a),m(!0);try{let t=await I({connection:e,command:a});t?.output&&g({kind:`out`,text:t.output}),t?.error&&g({kind:`err`,text:t.error}),!t?.ok&&!t?.error&&g({kind:`err`,text:r(`webshell.execError`,null,`执行失败`)})}catch(e){g({kind:`err`,text:e?.message||r(`webshell.execError`,null,`执行失败`)}),w(e)}finally{m(!1)}}}};return(0,B.jsxs)(`div`,{className:`webshell-terminal`,children:[(0,B.jsx)(`div`,{className:`webshell-terminal-bar`,children:(0,B.jsxs)(o,{spacing:8,children:[(0,B.jsx)(s,{size:`small`,color:f?`amber`:`green`,children:f?r(`webshell.terminalRunning`,null,`执行中`):r(`webshell.terminalIdle`,null,`空闲`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>a([]),children:r(`webshell.clearScreen`,null,`清屏`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:async()=>{let e=i.map(e=>e.kind===`cmd`?`$ ${e.text}`:e.text).join(`
+`);try{await navigator.clipboard.writeText(e),A(r(`webshell.terminalCopyOk`,null,`日志已复制`))}catch(e){w(e,r(`webshell.terminalCopyFail`,null,`复制失败`))}},children:r(`webshell.copyTerminalLog`,null,`复制日志`)})]})}),(0,B.jsxs)(`div`,{className:`webshell-terminal-log`,ref:h,children:[(0,B.jsx)(`div`,{className:`webshell-terminal-welcome`,children:r(`webshell.terminalWelcome`,null,`WebShell 虚拟终端 — 输入命令后按回车执行(Ctrl+L 清屏)`)}),i.map(e=>(0,B.jsx)(`pre`,{className:`webshell-terminal-line kind-${e.kind}`,children:e.kind===`cmd`?`$ ${e.text}`:e.text},e.id)),f&&(0,B.jsx)(`div`,{className:`webshell-terminal-pending`,children:r(`webshell.running`,null,`执行中…`)})]}),(0,B.jsxs)(`div`,{className:`webshell-terminal-input`,children:[(0,B.jsx)(u,{value:l,onChange:d,onEnterPress:()=>f?S(r(`webshell.waitFinish`,null,`请等待当前命令执行完成`)):_(),onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`l`&&(e.preventDefault(),a([]))},placeholder:r(`webshell.commandPlaceholder`,null,`输入命令后回车执行`),disabled:f||!t,prefix:`$`}),(0,B.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,B.jsx)(p,{}),loading:f,disabled:!t,onClick:()=>_(),children:r(`webshell.runCommand`,null,`执行`)})]})]})}var{Text:Se}=a;function Ce({history:e,onClear:t,onRemove:n,onRun:r}){let i=y(),a=e.map((e,t)=>({...e,rowId:`${t}-${e.at}`})),s=[{title:i(`webshell.colCommand`,null,`命令`),dataIndex:`command`,render:e=>(0,B.jsx)(`code`,{className:`webshell-history-cmd`,children:e})},{title:i(`webshell.colExecutedAt`,null,`执行时间`),dataIndex:`at`,width:200,render:e=>v(e)},{title:i(`webshell.moreActions`,null,`操作`),dataIndex:`ops`,width:220,render:(e,t)=>(0,B.jsxs)(o,{spacing:4,children:[(0,B.jsx)(D,{text:t.command,label:i(`common.copied`,null,`复制`),size:`small`}),r&&(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>r(t.command),children:i(`webshell.rerun`,null,`再执行`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,onClick:()=>j({title:i(`webshell.deleteHistory`,null,`删除该条历史`),content:t.command,onOk:()=>n(t.rowId)}),children:i(`webshell.deleteFile`,null,`删除`)})]})}];return(0,B.jsxs)(`div`,{className:`webshell-history`,children:[(0,B.jsxs)(`div`,{className:`webshell-history-toolbar`,children:[(0,B.jsx)(Se,{type:`tertiary`,children:i(`webshell.historyHint`,null,`仅记录本连接在当前浏览器执行过的命令`)}),(0,B.jsx)(o,{spacing:8,children:t&&(0,B.jsx)(c,{size:`small`,disabled:!a.length,onClick:()=>t(),children:i(`webshell.clearHistory`,null,`清空历史`)})})]}),(0,B.jsx)(k,{columns:s,dataSource:a,rowKey:`rowId`,pagination:{pageSize:15},emptyText:i(`webshell.noHistory`,null,`暂无命令历史`)})]})}var{Text:we}=a,Te={user:`blue`,assistant:`green`,system:`grey`,tool:`violet`};function Ee({connection:e}){let t=y(),[n,r]=(0,N.useState)([]),[a,o]=(0,N.useState)(``),[l,u]=(0,N.useState)([]),[f,p]=(0,N.useState)(!1),[m,h]=(0,N.useState)(null),g=(0,N.useCallback)(async()=>{if(e?.id){p(!0),h(null);try{let[t,n]=await Promise.all([se(e.id).catch(()=>[]),R(e.id).catch(()=>null)]),i=Array.isArray(t)?t:[];r(i);let a=n?.conversationId||i[0]?.id||``;if(o(a),n?.conversationId)u(Array.isArray(n.messages)?n.messages:[]);else if(a){let e=await z(a).catch(()=>null);u(Array.isArray(e?.messages)?e.messages:[])}else u([])}catch(e){h(e)}finally{p(!1)}}},[e?.id]);(0,N.useEffect)(()=>{g()},[g]);let b=async e=>{if(e){o(e),p(!0);try{let t=await z(e);u(Array.isArray(t?.messages)?t.messages:[])}catch(e){h(e),u([])}finally{p(!1)}}};return(0,B.jsxs)(`div`,{className:`webshell-ai`,children:[(0,B.jsxs)(`div`,{className:`webshell-ai-sidebar`,children:[(0,B.jsxs)(`div`,{className:`webshell-ai-sidebar-head`,children:[(0,B.jsx)(we,{strong:!0,children:t(`webshell.aiPreviousConversation`,null,`之前的对话`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,icon:(0,B.jsx)(_,{}),onClick:g,loading:f})]}),n.length===0?(0,B.jsx)(i,{title:t(`webshell.aiNoConversation`,null,`暂无 AI 会话`),description:null,style:{padding:24}}):(0,B.jsx)(`ul`,{className:`webshell-ai-list`,children:n.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`button`,{type:`button`,className:`webshell-ai-item ${e.id===a?`is-active`:``}`,onClick:()=>b(e.id),children:[(0,B.jsx)(`span`,{className:`webshell-ai-title`,children:e.title||e.id}),(0,B.jsx)(`span`,{className:`webshell-ai-time`,children:v(e.updatedAt)})]})},e.id))})]}),(0,B.jsxs)(`div`,{className:`webshell-ai-main`,children:[(0,B.jsx)(ee,{error:m,onRetry:g}),f&&(0,B.jsx)(`div`,{className:`webshell-ai-loading`,children:(0,B.jsx)(d,{})}),!f&&l.length===0&&(0,B.jsx)(i,{title:t(`webshell.aiNoMessage`,null,`暂无对话消息`),description:null,style:{padding:48}}),!f&&l.map(e=>(0,B.jsxs)(`div`,{className:`webshell-ai-message`,children:[(0,B.jsxs)(`div`,{className:`webshell-ai-message-head`,children:[(0,B.jsx)(s,{size:`small`,color:Te[e.role]||`grey`,children:e.role||`message`}),(0,B.jsx)(we,{type:`tertiary`,size:`small`,children:v(e.createdAt)})]}),(0,B.jsx)(E,{content:e.content||``})]},e.id||`${e.role}-${e.createdAt}`))]})]})}var{Text:$}=a,De={auto:`自动`,"utf-8":`UTF-8`,gbk:`GBK`,gb18030:`GB18030`};function Oe(e){return e===`online`?`green`:e===`probing`?`amber`:e===`offline`?`red`:`grey`}function ke(){let e=y(),{hasPermission:t}=b(),n=t(`webshell:write`),a=t(`webshell:delete`)||n,[p,h]=r(),v=p.get(`id`)||``,[x,T]=(0,N.useState)(``),E=te(x,250),[D,k]=(0,N.useState)({}),[ne,M]=(0,N.useState)(!1),[I,L]=(0,N.useState)({visible:!1,record:null}),[se,R]=(0,N.useState)(!1),[z,le]=(0,N.useState)([]),[V,H]=(0,N.useState)(``),[U,W]=(0,N.useState)([]),G=(0,N.useRef)(null),{data:K,loading:q,error:fe,reload:J}=C(()=>P(),[]),Y=(0,N.useMemo)(()=>Array.isArray(K)?K:[],[K]);(0,N.useEffect)(()=>{ce().then(le)},[]);let X=(0,N.useMemo)(()=>Y.find(e=>e.id===v)||null,[Y,v]),pe=e=>{let t=new URLSearchParams(p);e?t.set(`id`,e):t.delete(`id`),h(t,{replace:!0})},Z=(0,N.useCallback)(e=>{n&&v&&(G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{oe(v,e).catch(()=>{})},700))},[n,v]);(0,N.useEffect)(()=>{let e=!1;return H(``),W([]),v&&ae(v).then(t=>{if(e)return;let n=t?.state||{};H(typeof n.memo==`string`?n.memo:``),W(Array.isArray(n.commands)?n.commands:[])}).catch(()=>{}),()=>{e=!0}},[v]);let Q=e=>{H(e),Z({memo:e,commands:U})},me=e=>{let t=[...U,{command:e,at:new Date().toISOString()}].slice(-200);W(t),Z({memo:V,commands:t})},he=e=>{let t=U.filter((t,n)=>`${n}-${t.at}`!==e);W(t),Z({memo:V,commands:t})},ge=()=>{j({title:e(`webshell.clearHistory`,null,`清空历史`),content:e(`webshell.clearHistoryConfirm`,null,`确定清空该连接的命令历史?`),onOk:()=>{W([]),Z({memo:V,commands:[]})}})},_e=async e=>{k(t=>({...t,[e.id]:`probing`}));try{let t=await ue(e);return k(n=>({...n,[e.id]:t.ok?`online`:`offline`})),t.ok}catch{return k(t=>({...t,[e.id]:`offline`})),!1}},ye=async()=>{if(!Y.length)S(e(`webshell.probeNoConnections`,null,`暂无可探活连接`));else{M(!0);for(let e of Y)await _e(e);M(!1)}},be=async t=>{R(!0);try{if(I.record?.id)await re(I.record.id,t),A(e(`webshell.toastUpdated`,null,`连接已更新`));else{let n=await F(t);A(e(`webshell.toastCreated`,null,`连接已创建`)),n?.id&&pe(n.id)}L({visible:!1,record:null}),J()}catch(t){w(t,e(`webshell.saveFailed`,null,`保存失败`))}finally{R(!1)}},Se=t=>{j({title:e(`webshell.deleteConfirm`,null,`确定要删除该连接吗?`),content:t.url,onOk:async()=>{try{await ie(t.id),A(e(`webshell.toastDeleted`,null,`连接已删除`)),t.id===v&&pe(``),J()}catch(e){w(e)}}})},we=(0,N.useMemo)(()=>{let e=E.trim().toLowerCase();return e?Y.filter(t=>[t.url,t.remark,t.type,t.id].filter(Boolean).some(t=>String(t).toLowerCase().includes(e))):Y},[Y,E]),Te=[{tab:e(`webshell.tabTerminal`,null,`虚拟终端`),itemKey:`terminal`,children:X?(0,B.jsx)(xe,{connection:X,canWrite:n,onRecordCommand:me}):null},{tab:e(`webshell.tabFileManager`,null,`文件管理`),itemKey:`files`,children:X?(0,B.jsx)(ve,{connection:X,canWrite:n}):null},{tab:e(`webshell.tabHistory`,null,`命令历史`),itemKey:`history`,children:(0,B.jsx)(Ce,{history:U,onRemove:he,onClear:n?ge:null,onRun:e=>X?me(e):null})},{tab:e(`webshell.tabAiSessions`,null,`AI 会话`),itemKey:`ai`,children:X?(0,B.jsx)(Ee,{connection:X}):null},{tab:e(`webshell.tabMemo`,null,`备忘录`),itemKey:`memo`,children:(0,B.jsx)(l,{value:V,onChange:Q,autosize:{minRows:10,maxRows:20},placeholder:e(`webshell.aiMemoPlaceholder`,null,`记录关键命令、测试思路、复现步骤...`),disabled:!n})}];return(0,B.jsxs)(`div`,{className:`webshell-page`,id:`page-webshell`,children:[(0,B.jsx)(O,{title:e(`webshell.title`,null,`WebShell 管理`),description:e(`webshell.pageDesc`,null,`统一管理 WebShell 连接,代理执行命令并浏览目标文件`),extra:[(0,B.jsx)(c,{icon:(0,B.jsx)(_,{}),onClick:J,loading:q,children:e(`webshell.refresh`,null,`刷新`)},`refresh`),(0,B.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,B.jsx)(m,{}),disabled:!n,onClick:()=>L({visible:!0,record:null}),children:e(`webshell.addConnection`,null,`添加连接`)},`add`)]}),(0,B.jsx)(ee,{error:fe,onRetry:J}),(0,B.jsxs)(`div`,{className:`webshell-layout`,children:[(0,B.jsxs)(`aside`,{className:`webshell-sidebar`,children:[(0,B.jsxs)(`div`,{className:`webshell-sidebar-head`,children:[(0,B.jsx)($,{strong:!0,children:e(`webshell.connections`,null,`连接列表`)}),(0,B.jsx)(s,{size:`small`,children:Y.length})]}),(0,B.jsx)(u,{value:x,onChange:T,prefix:(0,B.jsx)(g,{}),placeholder:e(`webshell.searchPlaceholder`,null,`搜索连接...`),size:`small`}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,loading:ne,onClick:ye,disabled:!Y.length,children:e(`webshell.batchProbe`,null,`一键批量探活`)}),(0,B.jsxs)(`div`,{className:`webshell-conn-list`,children:[q&&!Y.length&&(0,B.jsx)(`div`,{className:`webshell-conn-loading`,children:(0,B.jsx)(d,{})}),!q&&we.length===0&&(0,B.jsx)($,{type:`tertiary`,className:`webshell-conn-empty`,children:Y.length?e(`webshell.noMatchConnections`,null,`暂无匹配连接`):e(`webshell.noConnections`,null,`暂无连接,请点击「添加连接」`)}),we.map(t=>(0,B.jsxs)(`button`,{type:`button`,className:`webshell-conn-item ${t.id===v?`is-active`:``}`,onClick:()=>pe(t.id),children:[(0,B.jsx)(`span`,{className:`webshell-conn-url`,title:t.url,children:t.remark||t.url}),(0,B.jsxs)(`span`,{className:`webshell-conn-meta`,children:[(0,B.jsx)(s,{size:`small`,color:`blue`,children:String(t.type||`php`).toUpperCase()}),D[t.id]&&(0,B.jsx)(s,{size:`small`,color:Oe(D[t.id]),children:D[t.id]===`online`?e(`webshell.probeOnline`,null,`在线`):D[t.id]===`probing`?e(`webshell.probeRunning`,null,`探活中`):e(`webshell.probeOffline`,null,`离线`)})]})]},t.id))]})]}),(0,B.jsx)(`section`,{className:`webshell-main`,children:X?(0,B.jsxs)(`div`,{className:`webshell-workspace`,children:[(0,B.jsxs)(`div`,{className:`webshell-workspace-head`,children:[(0,B.jsxs)(`div`,{className:`webshell-workspace-title`,children:[(0,B.jsx)($,{strong:!0,ellipsis:{showTooltip:!0},className:`webshell-workspace-url`,children:X.url}),(0,B.jsxs)(o,{spacing:6,wrap:!0,children:[(0,B.jsx)(s,{size:`small`,color:`blue`,children:String(X.type||`php`).toUpperCase()}),(0,B.jsx)(s,{size:`small`,children:String(X.method||`post`).toUpperCase()}),(0,B.jsx)(s,{size:`small`,children:De[X.encoding]||`自动`}),(0,B.jsx)(s,{size:`small`,children:X.os===`windows`?`Windows`:X.os===`linux`?`Linux`:`OS 自动`}),X.remark&&(0,B.jsx)($,{type:`tertiary`,size:`small`,children:X.remark})]})]}),(0,B.jsxs)(o,{spacing:8,children:[(0,B.jsx)(c,{size:`small`,loading:D[X.id]===`probing`,onClick:()=>_e(X),children:e(`webshell.testConnectivity`,null,`测试连通性`)}),(0,B.jsx)(c,{size:`small`,disabled:!n,onClick:()=>L({visible:!0,record:X}),children:e(`webshell.editConnection`,null,`编辑`)}),(0,B.jsx)(c,{size:`small`,type:`danger`,disabled:!a,onClick:()=>Se(X),children:e(`webshell.deleteFile`,null,`删除`)})]})]}),(0,B.jsx)(f,{type:`line`,defaultActiveKey:`terminal`,className:`webshell-tabs`,items:Te},X.id)]}):(0,B.jsx)(i,{title:e(`webshell.selectOrAdd`,null,`请从左侧选择连接,或添加新的 WebShell 连接`),description:null,style:{padding:64}})})]}),(0,B.jsx)(de,{visible:I.visible,record:I.record,projects:z,submitting:se,onCancel:()=>L({visible:!1,record:null}),onSubmit:be})]})}export{ke as default};
\ No newline at end of file
diff --git a/web/static/app/assets/workflows-BE-p3Qg8.js b/web/static/app/assets/workflows-DDqn8hp2.js
similarity index 93%
rename from web/static/app/assets/workflows-BE-p3Qg8.js
rename to web/static/app/assets/workflows-DDqn8hp2.js
index 8e93fc41..3badcb0d 100644
--- a/web/static/app/assets/workflows-BE-p3Qg8.js
+++ b/web/static/app/assets/workflows-DDqn8hp2.js
@@ -1 +1 @@
-import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{B as i,G as a,I as o,N as s,P as c,R as l,S as u,U as d,c as f,d as p,ft as m,h,lt as g,m as _,p as v,s as y,u as b,ut as x,x as S}from"./semi-65W_4I1v.js";import{E as C,F as w,I as T,L as E,P as D,_ as ee,a as O,b as k,c as te,d as A,l as j,m as M,n as ne,p as re,r as N,s as P,u as F,x as I,y as L}from"./index-BdnarFZR.js";var R=e(t(),1),z=[{value:`start`,label:`开始`},{value:`tool`,label:`工具`},{value:`agent`,label:`Agent`},{value:`condition`,label:`条件`},{value:`hitl`,label:`审批`},{value:`output`,label:`输出`},{value:`end`,label:`结束`}],ie=Object.fromEntries(z.map(e=>[e.value,e.label])),B={running:{label:`执行中`,color:`blue`},awaiting_hitl:{label:`等待审批`,color:`amber`},completed:{label:`已完成`,color:`green`},failed:{label:`失败`,color:`red`},cancelled:{label:`已取消`,color:`grey`},pending:{label:`待执行`,color:`amber`}},V={nodes:[{id:`start`,type:`start`,label:`开始`,position:{x:80,y:140},config:{}},{id:`out`,type:`output`,label:`输出`,position:{x:380,y:140},config:{output_key:`result`}}],edges:[{id:`e1`,source:`start`,target:`out`,label:``}],config:{}},H={WFPKG_FILE_REQUIRED:`workflows.package.errors.fileRequired`,WFPKG_FILE_TOO_LARGE:`workflows.package.errors.fileTooLarge`,WFPKG_UNSUPPORTED_FORMAT:`workflows.package.errors.unsupportedFormat`,WFPKG_INVALID_ARCHIVE:`workflows.package.errors.invalidArchive`,WFPKG_INVALID_MANIFEST:`workflows.package.errors.invalidManifest`,WFPKG_CHECKSUM_MISMATCH:`workflows.package.errors.checksumMismatch`,WFPKG_MULTIPLE_WORKFLOWS:`workflows.package.errors.multipleWorkflows`,WFPKG_WORKFLOW_INVALID:`workflows.package.errors.workflowInvalid`,WFPKG_INSPECTION_NOT_FOUND:`workflows.package.errors.inspectionNotFound`,WFPKG_INSPECTION_EXPIRED:`workflows.package.errors.inspectionExpired`,WFPKG_INSPECTION_CONSUMED:`workflows.package.errors.inspectionConsumed`,WFPKG_CONFLICT_CHANGED:`workflows.package.errors.conflictChanged`,WFPKG_ID_CONFLICT:`workflows.package.errors.idConflict`,WFPKG_INVALID_ACTION:`workflows.package.errors.invalidAction`,WFPKG_INVALID_RENAME_ID:`workflows.package.errors.invalidRenameId`,WFPKG_OVERWRITE_CONFIRMATION_REQUIRED:`workflows.package.errors.overwriteConfirmationRequired`,WFPKG_IDEMPOTENCY_KEY_REQUIRED:`workflows.package.errors.idempotencyKeyRequired`,WFPKG_IDEMPOTENCY_KEY_REUSED:`workflows.package.errors.idempotencyKeyReused`,WFPKG_IMPORT_FAILED:`workflows.package.errors.importFailed`},U={create:{label:`创建导入`,hint:`导入后会创建一个新的本地工作流。`},keep_existing:{label:`保留本地版本`,hint:`不修改当前本地工作流;导入记录会保留。`},overwrite:{label:`覆盖本地版本`,hint:`替换名称、描述、图定义和启用状态;需要再次确认。`},rename:{label:`另存为新 ID`,hint:`保留当前本地工作流,并以新的 ID 创建副本。`}},W={none:[`create`],identical:[`keep_existing`],id_conflict:[`keep_existing`,`overwrite`,`rename`]};function G(e){return(W[e]||[]).slice()}function K(e){if(!e||!String(e).trim())return{graph:null,error:`图定义不能为空`};try{let t=JSON.parse(e);return!t||typeof t!=`object`?{graph:null,error:`图定义必须是 JSON 对象`}:{graph:{nodes:Array.isArray(t.nodes)?t.nodes:[],edges:Array.isArray(t.edges)?t.edges:[],config:t.config||{}},error:null}}catch(e){return{graph:null,error:e.message||`JSON 解析失败`}}}function ae(e){let{graph:t,error:n}=K(e);return t?{nodes:t.nodes,edges:t.edges,error:null}:{nodes:[],edges:[],error:n}}function q(e,t=12){let n=String(e||``);if(!n)return`—`;let r=n.startsWith(`sha256:`)?n.slice(7):n;return r.length>t?`${r.slice(0,t)}…`:r}function J(e,t=`操作失败`){if(!e)return t;if(typeof e==`string`)return e;let n=e.payload;if(n&&typeof n==`object`){let e=n.error;if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=typeof e.message==`string`?e.message:``,n=typeof e.code==`string`?e.code:``;if(t)return n?`${t}(${n})`:t}if(typeof n.message==`string`&&n.message)return n.message}return typeof e.message==`string`&&e.message&&e.message!==`[object Object]`?e.message:t}function oe(e,t=`加载失败`){return e?{message:J(e,t)}:null}function se(e){let t=e?.payload?.error;return t&&typeof t==`object`&&typeof t.code==`string`?t.code:``}function ce(e,t){let n=se(e);if(n&&H[n]){let e=t?.(H[n],null,``);if(e)return e}return J(e,`操作未完成,请稍后重试。`)}function le(){let e=typeof globalThis<`u`?globalThis.crypto:null;return!e||typeof e.randomUUID!=`function`?``:e.randomUUID()}var Y=e(n(),1),{Text:X}=a,ue=/^[A-Za-z0-9][A-Za-z0-9_-]*$/,de={id:``,name:``,description:``,version:1,enabled:!0,graph:``};function fe({visible:e,workflow:t,onCancel:n,onSaved:r}){let a=D(),{hasPermission:s}=w(),f=s(`workflow:execute`),[p,m]=(0,R.useState)(de),[h,g]=(0,R.useState)(!1),[_,v]=(0,R.useState)(!1),[y,b]=(0,R.useState)(null),x=!!t?.id;(0,R.useEffect)(()=>{if(e){if(b(null),g(!1),t){let e=t.graph_json||``;try{e=JSON.stringify(JSON.parse(e),null,2)}catch{}m({id:t.id||``,name:t.name||``,description:t.description||``,version:t.version||1,enabled:t.enabled!==!1,graph:e})}else m({...de,graph:JSON.stringify(V,null,2)})}},[e,t]);let C=e=>m(t=>({...t,...e})),E=(0,R.useMemo)(()=>ae(p.graph),[p.graph]);return(0,Y.jsxs)(te,{visible:e,title:x?a(`workflows.metaModalTitle`,null,`工作流信息`):a(`workflows.newGraph`,null,`新建工作流`),onCancel:n,onOk:async()=>{let e=(x?t.id:p.id).trim(),n=p.name.trim();if(!e||!n)k(a(`workflows.idNameRequired`,null,`工作流 ID 和名称不能为空`));else if(!x&&!ue.test(e))k(`工作流 ID 必须以字母或数字开头,仅含字母、数字、下划线、连字符`);else{if(p.graph.trim())try{JSON.parse(p.graph)}catch(e){k(`graph 必须是合法 JSON:${J(e,``)}`);return}g(!0);try{let t={id:e,name:n,description:p.description,version:Number(p.version)||0,enabled:!!p.enabled,graph:p.graph.trim()?JSON.parse(p.graph):void 0},i=x?await T.put(`/workflows/${encodeURIComponent(e)}`,t):await T.post(`/workflows`,t);I(a(`workflows.saved`,null,`工作流已保存`)),r?.(i?.workflow||null)}catch(e){k(J(e,a(`workflows.saveFailed`,null,`保存工作流失败`)))}finally{g(!1)}}},okText:a(`common.save`,null,`保存`),cancelText:a(`common.cancel`,null,`取消`),confirmLoading:h,width:860,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-grid`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaId`,null,`ID`)}),(0,Y.jsx)(d,{value:p.id,disabled:x,placeholder:`web-scan-basic`,onChange:e=>C({id:e})}),(0,Y.jsx)(X,{type:`tertiary`,size:`small`,children:a(`workflows.metaIdHint`,null,`创建后不可修改,用于 API 与角色绑定`)})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaName`,null,`名称`)}),(0,Y.jsx)(d,{value:p.name,placeholder:a(`workflows.namePlaceholder`,null,`基础 Web 扫描`),onChange:e=>C({name:e})})]})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-grid`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaDescription`,null,`描述`)}),(0,Y.jsx)(d,{value:p.description,placeholder:a(`workflows.descriptionPlaceholder`,null,`可选`),onChange:e=>C({description:e})})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-grid workflow-form-grid--tight`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:`版本`}),(0,Y.jsx)(S,{value:p.version,min:0,style:{width:`100%`},onChange:e=>C({version:e||0})})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaEnabled`,null,`启用`)}),(0,Y.jsx)(c,{checked:p.enabled,onChange:e=>C({enabled:e.target.checked}),children:a(`workflows.metaEnabledHint`,null,`禁用后无法被角色自动触发`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsxs)(o,{children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:`graph JSON`}),(0,Y.jsx)(X,{type:`tertiary`,size:`small`,children:E.error?`解析失败:${E.error}`:`${E.nodes.length} 个节点 · ${E.edges.length} 条连线`})]}),(0,Y.jsx)(u,{value:p.graph,rows:16,spellCheck:!1,className:`workflow-graph-input`,placeholder:`{"nodes":[],"edges":[],"config":{}}`,onChange:e=>{C({graph:e}),b(null)}}),(0,Y.jsxs)(o,{wrap:!0,children:[(0,Y.jsx)(l,{size:`small`,onClick:()=>{try{C({graph:JSON.stringify(JSON.parse(p.graph),null,2)}),b(null)}catch(e){k(`${a(`projects.invalidJson`,null,`JSON 格式无效`)}:${J(e,``)}`)}},children:a(`projects.formatJson`,null,`格式化`)}),(0,Y.jsx)(l,{size:`small`,onClick:()=>{C({graph:JSON.stringify(V,null,2)}),b(null)},children:`插入最小模板`}),(0,Y.jsx)(l,{size:`small`,loading:_,disabled:!f,title:f?``:`需要 workflow:execute 权限`,onClick:async()=>{if(!p.graph.trim()){b({type:`danger`,text:a(`workflows.validation.serverFailed`,null,`图定义不能为空`)});return}let e;try{e=JSON.parse(p.graph)}catch(e){b({type:`danger`,text:`JSON 解析失败:${J(e,``)}`});return}v(!0),b(null);try{await T.post(`/workflows/validate`,{graph:e}),b({type:`success`,text:`结构校验通过`})}catch(e){b({type:`danger`,text:J(e,a(`workflows.validation.serverFailed`,null,`后端图校验失败`))})}finally{v(!1)}},children:a(`workflows.validate`,null,`校验图定义`)}),(0,Y.jsxs)(X,{type:`tertiary`,size:`small`,children:[`节点类型:`,z.map(e=>e.label).join(` / `)]})]})]}),y?(0,Y.jsx)(i,{type:y.type,bordered:!0,closeIcon:null,description:y.text,style:{marginTop:12}}):null]})}var{Text:Z}=a;function pe({raw:e}){let t=(0,R.useMemo)(()=>ae(e),[e]);if(t.error)return(0,Y.jsxs)(Z,{type:`danger`,size:`small`,children:[`graph 解析失败:`,t.error]});let n=t.nodes.map(e=>({id:e.id,type:e.type||`tool`,label:e.label||``,config:e.config||{}}));return(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsx)(b,{columns:[{title:`节点`,dataIndex:`id`,width:160,render:e=>(0,Y.jsx)(`code`,{children:e})},{title:`类型`,dataIndex:`type`,width:90,render:e=>(0,Y.jsx)(s,{size:`small`,color:`blue`,type:`light`,children:ie[e]||e})},{title:`名称`,dataIndex:`label`,render:(e,t)=>(0,Y.jsx)(`span`,{className:`workflow-cell-ellipsis`,title:e||t.id,children:e||`—`})}],dataSource:n,rowKey:`id`,size:`small`,pagination:!1,empty:(0,Y.jsx)(Z,{type:`tertiary`,size:`small`,children:`图内没有节点`})}),(0,Y.jsxs)(`div`,{className:`workflow-edge-list`,children:[(0,Y.jsxs)(Z,{strong:!0,size:`small`,children:[`连线(`,t.edges.length,`)`]}),t.edges.length?(0,Y.jsx)(`ul`,{className:`workflow-link-list`,children:t.edges.map((e,t)=>(0,Y.jsxs)(`li`,{children:[(0,Y.jsx)(`code`,{children:e.source}),` → `,(0,Y.jsx)(`code`,{children:e.target}),e.label?(0,Y.jsx)(`span`,{className:`workflow-edge-label`,children:e.label}):null]},e.id||`${e.source}-${e.target}-${t}`))}):(0,Y.jsx)(Z,{type:`tertiary`,size:`small`,children:`暂无连线`})]})]})}function me({workflowId:e,visible:t,canWrite:n,canDelete:r,onClose:i,onEdit:a,onDeleted:c}){let u=D(),[d,f]=(0,R.useState)(!1),p=O(()=>e?T.get(`/workflows/${encodeURIComponent(e)}`):Promise.resolve(null),[e]),m=p.data?.workflow||null;return(0,R.useEffect)(()=>{t&&e&&p.reload({silent:!0})},[t,e]),(0,Y.jsxs)(v,{visible:t,width:760,title:m?m.name||m.id:u(`workflows.metaModalTitle`,null,`工作流信息`),onCancel:i,footer:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{disabled:!n||!m,onClick:()=>a?.(m),children:u(`common.edit`,null,`编辑`)}),(0,Y.jsx)(l,{loading:d,disabled:!m,onClick:async()=>{if(m){f(!0);try{await E(`/workflows/${encodeURIComponent(m.id)}/package`,{filename:`${m.id}.csapkg.zip`}),I(u(`workflows.package.export`,null,`导出`))}catch(e){k(J(e,u(`workflows.package.errors.exportFailed`,null,`导出失败,请稍后重试。`)))}finally{f(!1)}}},children:u(`workflows.package.export`,null,`导出`)}),(0,Y.jsx)(l,{type:`danger`,disabled:!r||!m,onClick:()=>L({title:u(`workflows.deleteWorkflow`,null,`删除工作流`),content:u(`workflows.confirmDelete`,{id:m?.id},`确定删除工作流 ${m?.id}?`),okText:u(`common.delete`,null,`删除`),onOk:async()=>{try{await T.del(`/workflows/${encodeURIComponent(m.id)}`),I(u(`workflows.deleted`,null,`工作流已删除`)),c?.(m.id)}catch(e){k(J(e,u(`workflows.deleteFailed`,null,`删除工作流失败`)))}}}),children:u(`workflows.deleteWorkflow`,null,`删除工作流`)}),(0,Y.jsx)(l,{onClick:i,children:u(`common.close`,null,`关闭`)})]}),children:[(0,Y.jsx)(j,{error:oe(p.error),onRetry:()=>p.reload()}),m?(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsxs)(`div`,{className:`workflow-detail-tags`,children:[(0,Y.jsx)(s,{size:`small`,color:m.enabled?`green`:`grey`,children:m.enabled?u(`workflows.statusEnabled`,null,`启用`):u(`workflows.statusDisabled`,null,`禁用`)}),m.validation_error?(0,Y.jsx)(s,{size:`small`,color:`red`,children:u(`workflows.statusInvalid`,null,`校验未通过`)}):(0,Y.jsx)(s,{size:`small`,color:`green`,type:`light`,children:`结构有效`}),(0,Y.jsxs)(Z,{type:`tertiary`,size:`small`,children:[`版本 `,m.version||0]})]}),m.validation_error?(0,Y.jsx)(j,{error:{message:m.validation_error}}):null,(0,Y.jsx)(A,{columns:2,items:[{label:u(`workflows.metaId`,null,`ID`),value:(0,Y.jsx)(`code`,{children:m.id})},{label:u(`workflows.metaName`,null,`名称`),value:m.name||`—`},{label:u(`workflows.updated`,null,`更新`),value:C(m.updated_at)},{label:`创建`,value:C(m.created_at)},{label:u(`workflows.metaDescription`,null,`描述`),value:m.description||`—`}]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(Z,{strong:!0,children:u(`workflows.nodeProperties`,null,`节点属性`)}),(0,Y.jsx)(pe,{raw:m.graph_json})]}),(0,Y.jsx)(F,{value:m.graph_json?he(m.graph_json):{},title:`graph JSON`,collapsed:!0})]}):null]})}function he(e){try{return JSON.parse(e)}catch{return{raw:e}}}var{Text:Q}=a;function ge(e){let t=B[String(e||``)]||{label:e||`—`,color:`grey`};return(0,Y.jsx)(s,{size:`small`,color:t.color,children:t.label})}function _e({runId:e,visible:t,canExecute:n,onClose:r,onChanged:i}){let a=D(),[s,c]=(0,R.useState)(``),[d,f]=(0,R.useState)(!1),p=O(()=>e?T.get(`/workflows/runs/${encodeURIComponent(e)}`):Promise.resolve(null),[e]),m=O(()=>e?T.get(`/workflows/runs/${encodeURIComponent(e)}/replay`):Promise.resolve(null),[e]),h=p.data?.run||null;(0,R.useEffect)(()=>{t&&e&&(p.reload({silent:!0}),m.reload({silent:!0}))},[t,e]);let g=p.data?.nodeRuns||[],_=m.data?.steps||[],b=t=>L({title:t?`通过审批`:`拒绝审批`,content:t?`确认通过该工作流的审批节点并继续执行?`:`确认拒绝该工作流的审批节点?运行将以失败结束。`,okText:a(`common.confirm`,null,`确认`),danger:!t,onOk:async()=>{f(!0);try{await T.post(`/workflows/runs/${encodeURIComponent(e)}/resume`,{approved:t,comment:s}),I(t?`已通过审批`:`已拒绝审批`),c(``),p.reload({silent:!0}),m.reload({silent:!0}),i?.()}catch(e){k(J(e,`审批提交失败`))}finally{f(!1)}}});return(0,Y.jsxs)(v,{visible:t,width:820,title:a(`workflows.dryRunTrace`,null,`运行轨迹`),onCancel:r,footer:(0,Y.jsxs)(o,{children:[h?.status===`awaiting_hitl`&&n?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(u,{value:s,rows:1,placeholder:`审批备注(可选)`,onChange:e=>c(e),style:{width:240}}),(0,Y.jsx)(l,{type:`primary`,loading:d,onClick:()=>b(!0),children:`通过`}),(0,Y.jsx)(l,{type:`danger`,loading:d,onClick:()=>b(!1),children:`拒绝`})]}):null,(0,Y.jsx)(l,{onClick:r,children:a(`common.close`,null,`关闭`)})]}),children:[(0,Y.jsx)(j,{error:oe(p.error),onRetry:()=>p.reload()}),h?(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsxs)(`div`,{className:`workflow-detail-tags`,children:[ge(h.status),(0,Y.jsxs)(Q,{type:`tertiary`,size:`small`,children:[`运行 `,(0,Y.jsx)(`code`,{children:q(h.id,16)})]})]}),(0,Y.jsx)(A,{columns:2,items:[{label:`工作流`,value:(0,Y.jsx)(`code`,{children:h.workflow_id})},{label:`版本`,value:h.workflow_version??`—`},{label:`会话`,value:h.conversation_id||`—`},{label:`项目`,value:h.project_id||`—`},{label:`开始时间`,value:C(h.started_at)},{label:`结束时间`,value:C(h.finished_at)},h.pending_hitl_node_id?{label:`待审批节点`,value:(0,Y.jsx)(`code`,{children:h.pending_hitl_node_id})}:null,h.error?{label:`错误`,value:(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:h.error})}:null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,children:[`节点执行记录(`,g.length,`)`]}),(0,Y.jsx)(y,{className:`workflow-timeline`,children:g.length?g.map(e=>(0,Y.jsx)(y.Item,{time:C(e.started_at),type:e.status===`failed`?`error`:e.status===`completed`?`success`:`ongoing`,children:(0,Y.jsxs)(`div`,{className:`workflow-timeline-item`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`code`,{children:e.node_id}),` `,ge(e.status)]}),e.error?(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:e.error}):null,e.output_json?(0,Y.jsx)(F,{value:ve(e.output_json),title:`output`,collapsed:!0}):null]})},e.id)):(0,Y.jsx)(Q,{type:`tertiary`,size:`small`,children:`暂无节点执行记录`})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,children:[a(`workflows.dryRunTrace`,null,`回放轨迹`),`(`,_.length,` 步)`]}),(0,Y.jsx)(y,{className:`workflow-timeline`,children:_.length?_.map(e=>(0,Y.jsx)(y.Item,{time:C(e.startedAt),type:e.status===`failed`?`error`:e.status===`completed`?`success`:`ongoing`,children:(0,Y.jsxs)(`div`,{className:`workflow-timeline-item`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,size:`small`,children:[`#`,e.step]}),` `,(0,Y.jsx)(`code`,{children:e.nodeId}),` `,ge(e.status)]}),e.error?(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:e.error}):null,(0,Y.jsx)(F,{value:{input:e.input,output:e.output},title:`step`,collapsed:!0})]})},e.nodeRunId||`${e.step}-${e.nodeId}`)):(0,Y.jsx)(Q,{type:`tertiary`,size:`small`,children:a(`workflows.dryRunNoTrace`,null,`暂无轨迹`)})})]}),(0,Y.jsx)(F,{value:h,title:`run`,collapsed:!0})]}):null]})}function ve(e){try{return JSON.parse(e)}catch{return{raw:e}}}var{Text:ye}=a;function be({canExecute:e}){let t=D(),[n,i]=r(),a=n.get(`run`)||``,c=O(()=>T.get(`/workflows/runs/pending`),[]);N(()=>c.reload({silent:!0}),15e3);let u=Array.isArray(c.data?.runs)?c.data.runs:[],d=e=>{let t=new URLSearchParams(n);e?t.set(`run`,e):t.delete(`run`),i(t,{replace:!0})},f=[{title:`运行`,dataIndex:`id`,width:190,render:e=>(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>d(e),children:(0,Y.jsx)(`code`,{children:q(e,14)})})},{title:`工作流`,dataIndex:`workflow_id`,width:200,render:e=>(0,Y.jsx)(ye,{size:`small`,children:(0,Y.jsx)(`code`,{children:e})})},{title:`会话`,dataIndex:`conversation_id`,width:220,render:e=>(0,Y.jsx)(ye,{type:`tertiary`,size:`small`,children:(0,Y.jsx)(`code`,{children:e||`—`})})},{title:t(`projects.status`,null,`状态`),dataIndex:`status`,width:110,render:e=>{let t=B[String(e||``)]||{label:e||`—`,color:`grey`};return(0,Y.jsx)(s,{size:`small`,color:t.color,children:t.label})}},{title:`待审批节点`,dataIndex:`pending_hitl_node_id`,width:160,render:e=>e?(0,Y.jsx)(`code`,{children:e}):(0,Y.jsx)(ye,{type:`tertiary`,children:`—`})},{title:`开始时间`,dataIndex:`started_at`,width:165,render:e=>(0,Y.jsx)(ye,{size:`small`,children:C(e)})},{title:t(`common.actions`,null,`操作`),dataIndex:`id`,width:120,render:e=>(0,Y.jsx)(o,{children:(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>d(e),children:t(`projects.details`,null,`详情`)})})}];return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(M,{title:t(`workflows.runsPending`,null,`待审批运行`),description:`等待审批(awaiting_hitl)的工作流运行,每 15 秒自动刷新。${e?` 可直接在此通过或拒绝。`:``}`,extra:(0,Y.jsx)(l,{icon:(0,Y.jsx)(x,{}),theme:`borderless`,loading:c.loading,onClick:()=>c.reload(),children:t(`common.refresh`,null,`刷新`)}),children:[(0,Y.jsx)(j,{error:oe(c.error),onRetry:()=>c.reload()}),(0,Y.jsx)(P,{columns:f,dataSource:u,rowKey:`id`,loading:c.loading,pagination:{pageSize:10},emptyText:`当前没有等待审批的工作流运行`})]}),(0,Y.jsx)(_e,{runId:a,visible:!!a,canExecute:e,onClose:()=>d(``),onChanged:()=>c.reload({silent:!0})})]})}var{Text:$,Paragraph:xe}=a,Se=10485760;function Ce(e){let t=String(e||``).replace(/^data:[^;]+;base64,/,``).replace(/\s+/g,``);if(!t)throw Error(`粘贴内容为空`);let n=atob(t),r=new Uint8Array(n.length);for(let e=0;e{e||(f(null),m(``),v(``),b(null),S(``),E(``),O(!1),N(``),F(null),j(!1),ne(!1))},[e]);let L=y?.conflict?.state||``,z=(0,R.useMemo)(()=>G(L),[L]),ie=()=>{v(``);try{let e=Ce(p);if(e.size>Se){v(r(`workflows.package.errors.fileTooLarge`,null,`文件超过 10 MiB 限制,请选择更小的本地包。`));return}f(e),b(null),F(null)}catch(e){v(`Base64 解码失败:${J(e,``)}`)}},B=e=>{let t=e.target.files&&e.target.files[0];v(``),N(``),F(null),b(null),t?t.size>Se?(v(r(`workflows.package.errors.fileTooLarge`,null,`文件超过 10 MiB 限制,请选择更小的本地包。`)),f(null)):f(t):f(null)},V=async()=>{if(!a)v(r(`workflows.package.errors.fileRequired`,null,`请选择本地工作流包后再预检。`));else{j(!0),N(``),F(null);try{let e=new FormData;e.append(`file`,a,a.name||`workflow.csapkg.zip`);let t=(await T.post(`/workflow-package-inspections`,e))?.inspection||null;b(t);let n=G(t?.conflict?.state||``);S(n[0]||``),E(``),O(!1)}catch(e){N(ce(e,r))}finally{j(!1)}}},H=async()=>{if(!y?.id){N(r(`workflows.package.resolution.needInspection`,null,`请先选择本地包并完成预检。`));return}if(!x){N(r(`workflows.package.errors.invalidAction`,null,`导入处理方式无效,请重新选择。`));return}if(x===`rename`&&!w.trim()){N(r(`workflows.package.errors.invalidRenameId`,null,`请输入可用的新工作流 ID。`));return}if(x===`overwrite`&&!ee){N(r(`workflows.package.errors.overwriteConfirmationRequired`,null,`请勾选确认后再覆盖本地工作流。`));return}let e=le();if(!e)N(r(`workflows.package.errors.idempotencyKeyRequired`,null,`浏览器无法生成导入请求标识,请刷新页面后重试。`));else{ne(!0),N(``);try{let t=await T.post(`/workflow-package-imports`,{inspection_id:y.id,resolution:{action:x,new_workflow_id:x===`rename`?w.trim():``},confirm_overwrite:x===`overwrite`},{headers:{"Idempotency-Key":e}});F(t?.import||null),I(r(`workflows.package.result.complete`,null,`导入已完成。`)),n?.(t?.import||null)}catch(e){N(ce(e,r))}finally{ne(!1)}}},W=L===`identical`?r(`workflows.package.conflict.identical`,null,`检测到同 ID 且内容相同的本地工作流;本次将跳过导入。`):L===`id_conflict`?r(`workflows.package.conflict.idConflict`,null,`检测到同 ID 但内容不同的本地工作流。默认保留本地版本。`):L===`none`?r(`workflows.package.conflict.none`,null,`未发现同 ID 的本地工作流,可创建导入。`):``,K=y?.workflow;return(0,Y.jsxs)(te,{visible:e,title:r(`workflows.package.title`,null,`导入本地包`),onCancel:t,width:760,maskClosable:!k&&!M,footer:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{onClick:t,children:r(`common.close`,null,`关闭`)}),(0,Y.jsx)(l,{type:`primary`,loading:k,disabled:!!P,onClick:V,children:k?r(`workflows.package.inspecting`,null,`正在安全预检…`):r(`workflows.package.inspect`,null,`上传并预检`)}),(0,Y.jsx)(l,{type:`primary`,loading:M,disabled:!y||!!P||!x,onClick:H,children:r(`workflows.package.confirmImport`,null,`确认导入`)})]}),children:[(0,Y.jsxs)(xe,{type:`tertiary`,size:`small`,children:[r(`workflows.package.preflightHint`,null,`先检查包内容与冲突,再由你确认是否导入`),` · `,r(`workflows.package.fileHint`,null,`仅支持单个 .csapkg.zip,文件不得超过 10 MiB。`)]}),(0,Y.jsxs)(`div`,{className:`workflow-package-block`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.stepInspection`,null,`上传与预检`)}),(0,Y.jsxs)(`div`,{className:`workflow-package-file-row`,children:[(0,Y.jsx)(`input`,{type:`file`,accept:`.zip,application/zip`,className:`workflow-file-input`,onChange:B,"aria-label":r(`workflows.package.selectFile`,null,`选择本地包`)}),(0,Y.jsx)($,{type:`tertiary`,size:`small`,children:a?`${a.name} · ${(a.size/1024).toFixed(1)} KiB`:r(`workflows.package.noFile`,null,`未选择文件`)}),a?(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>{f(null),b(null),F(null)},children:r(`workflows.package.removeFile`,null,`移除文件`)}):null]}),(0,Y.jsx)(u,{value:p,rows:3,placeholder:`或粘贴工作流包 base64(.csapkg.zip)`,onChange:e=>m(e)}),(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{size:`small`,onClick:ie,disabled:!p.trim(),children:`使用粘贴内容`}),g?(0,Y.jsx)($,{type:`danger`,size:`small`,children:g}):null]})]}),re?(0,Y.jsx)(i,{type:`danger`,bordered:!0,closeIcon:null,description:re,className:`workflow-package-banner`}):null,y?(0,Y.jsxs)(`div`,{className:`workflow-package-block`,children:[(0,Y.jsxs)(`div`,{className:`workflow-package-summary-head`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.summary.title`,null,`预检结果`)}),(0,Y.jsx)(s,{size:`small`,color:`green`,children:r(`workflows.package.summary.passed`,null,`校验通过`)})]}),(0,Y.jsx)(i,{type:L===`id_conflict`?`warning`:`success`,bordered:!0,closeIcon:null,description:W,className:`workflow-package-banner`}),(0,Y.jsx)(A,{columns:2,items:[{label:r(`workflows.package.summary.workflowName`,null,`工作流名称`),value:K?.name||`—`},{label:r(`workflows.package.summary.sourceId`,null,`源工作流 ID`),value:(0,Y.jsx)(`code`,{children:K?.source_id||`—`})},{label:r(`workflows.package.summary.sourceRevision`,null,`源版本`),value:K?.source_revision??`—`},{label:r(`workflows.package.summary.graphSize`,null,`图规模`),value:`${K?.node_count||0} 节点 · ${K?.edge_count||0} 连线`},{label:r(`workflows.package.summary.contentHash`,null,`内容摘要`),value:q(K?.content_hash)},{label:r(`workflows.package.summary.expiresAt`,null,`预检有效期`),value:C(y.expires_at)}]}),(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.resolutionTitle`,null,`处理方式`)}),(0,Y.jsx)(h,{value:x,onChange:e=>{S(e.target.value),O(!1)},direction:`vertical`,children:z.map(e=>(0,Y.jsx)(_,{value:e,children:(0,Y.jsxs)(`span`,{className:`workflow-package-action`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:U[e]?.label||e}),(0,Y.jsx)($,{type:`tertiary`,size:`small`,children:U[e]?.hint||``})]})},e))}),x===`rename`?(0,Y.jsx)(d,{value:w,placeholder:r(`workflows.package.resolution.newWorkflowIdPlaceholder`,null,`例如:web-scan-basic-copy`),onChange:e=>E(e)}):null,x===`overwrite`?(0,Y.jsxs)(`div`,{className:`workflow-package-overwrite`,children:[(0,Y.jsx)(i,{type:`warning`,bordered:!0,closeIcon:null,description:r(`workflows.package.overwriteWarning`,null,`覆盖将替换名称、描述、图定义和启用状态。本期不提供回滚。`)}),(0,Y.jsx)(c,{checked:ee,onChange:e=>O(e.target.checked),children:r(`workflows.package.overwriteCheck`,null,`我已确认覆盖当前本地工作流`)})]}):null]}):null,P?(0,Y.jsx)(i,{type:`success`,bordered:!0,closeIcon:null,className:`workflow-package-banner`,description:r(we[P.result]||`workflows.package.result.complete`,null,`导入已完成。`)}):null]})}var{Text:Ee}=a;async function De(){let[e,t]=await Promise.all([T.get(`/workflows`,{includeDisabled:`true`}),T.get(`/workflows/runs/pending`).catch(()=>null)]);return{workflows:Array.isArray(e?.workflows)?e.workflows:[],pendingRuns:Array.isArray(t?.runs)?t.runs:[]}}function Oe(){let e=D(),{hasPermission:t}=w(),n=t(`workflow:write`),i=t(`workflow:delete`),a=t(`workflow:execute`),[c,u]=r(),h=c.get(`id`)||``,_=c.get(`tab`)||`list`,[v,y]=(0,R.useState)(``),b=ne(v,250),[S,te]=(0,R.useState)(!0),[A,N]=(0,R.useState)({visible:!1,workflow:null}),[F,z]=(0,R.useState)(!1),[ie,B]=(0,R.useState)(0),V=O(De,[ie]),H=V.data?.workflows||[],U=V.data?.pendingRuns||[],W=(0,R.useCallback)((e,t)=>{let n=new URLSearchParams(c);e?n.set(`id`,e):n.delete(`id`),t?n.set(`tab`,t):n.delete(`tab`),t&&t!==`runs`&&n.delete(`run`),u(n,{replace:!!e})},[c,u]),G=()=>B(e=>e+1),K=(0,R.useMemo)(()=>{let e=b.trim().toLowerCase();return H.filter(t=>!S&&t.enabled===!1?!1:!e||[t.id,t.name,t.description].join(` `).toLowerCase().includes(e))},[H,b,S]),q=H.filter(e=>!!e.validation_error).length,se=H.filter(e=>e.enabled).length,ce=[{id:`total`,label:e(`workflows.processLibrary`,null,`工作流列表`),value:H.length,loading:V.loading},{id:`enabled`,label:e(`workflows.statusEnabled`,null,`启用`),value:se,tone:`success`,loading:V.loading},{id:`invalid`,label:e(`workflows.statusInvalid`,null,`校验未通过`),value:q,tone:q?`danger`:void 0,loading:V.loading},{id:`pending`,label:e(`workflows.runsPending`,null,`待审批运行`),value:U.length,tone:U.length?`warning`:void 0,loading:V.loading}],le=async t=>{try{await E(`/workflows/${encodeURIComponent(t.id)}/package`,{filename:`${t.id}.csapkg.zip`}),I(e(`workflows.package.export`,null,`导出`))}catch(t){k(J(t,e(`workflows.package.errors.exportFailed`,null,`导出失败,请稍后重试。`)))}},X=t=>L({title:e(`workflows.deleteWorkflow`,null,`删除工作流`),content:e(`workflows.confirmDelete`,{id:t.id},`确定删除工作流 ${t.id}?`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await T.del(`/workflows/${encodeURIComponent(t.id)}`),I(e(`workflows.deleted`,null,`工作流已删除`)),h===t.id&&W(void 0,_),G()}catch(t){k(J(t,e(`workflows.deleteFailed`,null,`删除工作流失败`)))}}}),ue=[{title:e(`workflows.metaName`,null,`名称`),dataIndex:`name`,render:(t,n)=>{let r=ae(n.graph_json);return(0,Y.jsxs)(`button`,{type:`button`,className:`workflow-name-button`,onClick:()=>W(n.id,`list`),title:n.id,children:[(0,Y.jsx)(`span`,{className:`workflow-name-text`,children:t||e(`workflows.untitled`,null,`未命名工作流`)}),(0,Y.jsxs)(`span`,{className:`workflow-name-sub`,children:[(0,Y.jsx)(`code`,{children:n.id}),` · `,r.error?`图解析失败`:`${r.nodes.length} 节点 / ${r.edges.length} 连线`]})]})}},{title:e(`projects.status`,null,`状态`),dataIndex:`enabled`,width:150,render:(t,n)=>(0,Y.jsxs)(o,{spacing:4,wrap:!0,children:[(0,Y.jsx)(s,{size:`small`,color:t?`green`:`grey`,children:t?e(`workflows.statusEnabled`,null,`启用`):e(`workflows.statusDisabled`,null,`禁用`)}),n.validation_error?(0,Y.jsx)(s,{size:`small`,color:`red`,children:e(`workflows.statusInvalid`,null,`校验未通过`)}):null]})},{title:`版本`,dataIndex:`version`,width:80,render:e=>(0,Y.jsxs)(Ee,{size:`small`,children:[`v`,e??0]})},{title:e(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:165,render:e=>(0,Y.jsx)(Ee,{type:`tertiary`,size:`small`,children:C(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:260,render:(t,r)=>(0,Y.jsxs)(o,{spacing:2,wrap:!0,children:[(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>W(r.id,`list`),children:e(`projects.details`,null,`详情`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>N({visible:!0,workflow:r}),children:e(`common.edit`,null,`编辑`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>le(r),children:e(`workflows.package.export`,null,`导出`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!i,onClick:()=>X(r),children:e(`common.delete`,null,`删除`)})]})}];return(0,Y.jsxs)(`div`,{className:`workflow-page`,children:[(0,Y.jsx)(re,{title:e(`workflows.title`,null,`工作流`),description:e(`workflows.processLibraryHint`,null,`工作流定义由节点与连线组成,可被角色或对话按需触发。`),extra:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{icon:(0,Y.jsx)(x,{}),theme:`borderless`,loading:V.loading,onClick:G,children:e(`common.refresh`,null,`刷新`)}),(0,Y.jsx)(l,{disabled:!n,onClick:()=>z(!0),children:e(`workflows.package.importLocal`,null,`导入本地包`)}),(0,Y.jsx)(l,{type:`primary`,icon:(0,Y.jsx)(m,{}),disabled:!n,onClick:()=>N({visible:!0,workflow:null}),children:e(`workflows.newGraph`,null,`新建工作流`)})]})}),(0,Y.jsx)(j,{error:oe(V.error),onRetry:G}),(0,Y.jsx)(ee,{metrics:ce,columns:4}),(0,Y.jsx)(f,{type:`line`,activeKey:_,onChange:e=>W(void 0,e),tabList:[{itemKey:`list`,tab:e(`workflows.processLibrary`,null,`工作流列表`)},{itemKey:`runs`,tab:e(`workflows.runsPending`,null,`运行历史`)}],className:`workflow-tabs`}),_===`runs`?(0,Y.jsx)(be,{canExecute:a}):(0,Y.jsxs)(M,{title:e(`workflows.processLibrary`,null,`工作流列表`),description:e(`workflows.metaIdHint`,null,`创建后不可修改,用于 API 与角色绑定`),extra:(0,Y.jsxs)(Ee,{type:`tertiary`,size:`small`,children:[K.length,` / `,H.length]}),children:[(0,Y.jsxs)(`div`,{className:`workflow-toolbar`,children:[(0,Y.jsx)(d,{prefix:(0,Y.jsx)(g,{}),value:v,showClear:!0,placeholder:e(`workflows.searchPlaceholder`,null,`搜索工作流…`),onChange:e=>y(e),style:{width:260}}),(0,Y.jsxs)(o,{spacing:6,children:[(0,Y.jsx)(p,{checked:S,onChange:te,size:`small`}),(0,Y.jsx)(Ee,{size:`small`,children:`显示已禁用`})]})]}),(0,Y.jsx)(P,{columns:ue,dataSource:K,rowKey:`id`,loading:V.loading,pagination:{pageSize:10},emptyText:e(`workflows.emptyList`,null,`暂无工作流`)})]}),(0,Y.jsx)(fe,{visible:A.visible,workflow:A.workflow,onCancel:()=>N({visible:!1,workflow:null}),onSaved:e=>{N({visible:!1,workflow:null}),G(),e?.id&&W(e.id,`list`)}}),(0,Y.jsx)(me,{workflowId:h,visible:!!h,canWrite:n,canDelete:i,onClose:()=>W(void 0,_),onEdit:e=>{e&&(W(void 0,_),N({visible:!0,workflow:e}))},onDeleted:()=>{W(void 0,_),G()}}),(0,Y.jsx)(Te,{visible:F,onCancel:()=>z(!1),onImported:()=>G()})]})}export{Oe as default};
\ No newline at end of file
+import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{B as i,G as a,I as o,N as s,P as c,R as l,S as u,U as d,c as f,d as p,ft as m,h,lt as g,m as _,p as v,s as y,u as b,ut as x,x as S}from"./semi-65W_4I1v.js";import{E as C,F as w,I as T,L as E,R as D,_ as ee,a as O,b as k,c as te,d as A,l as j,m as M,n as ne,p as re,r as N,s as P,u as F,x as I,y as L}from"./index-_8d9XBPJ.js";var R=e(t(),1),z=[{value:`start`,label:`开始`},{value:`tool`,label:`工具`},{value:`agent`,label:`Agent`},{value:`condition`,label:`条件`},{value:`hitl`,label:`审批`},{value:`output`,label:`输出`},{value:`end`,label:`结束`}],ie=Object.fromEntries(z.map(e=>[e.value,e.label])),B={running:{label:`执行中`,color:`blue`},awaiting_hitl:{label:`等待审批`,color:`amber`},completed:{label:`已完成`,color:`green`},failed:{label:`失败`,color:`red`},cancelled:{label:`已取消`,color:`grey`},pending:{label:`待执行`,color:`amber`}},V={nodes:[{id:`start`,type:`start`,label:`开始`,position:{x:80,y:140},config:{}},{id:`out`,type:`output`,label:`输出`,position:{x:380,y:140},config:{output_key:`result`}}],edges:[{id:`e1`,source:`start`,target:`out`,label:``}],config:{}},H={WFPKG_FILE_REQUIRED:`workflows.package.errors.fileRequired`,WFPKG_FILE_TOO_LARGE:`workflows.package.errors.fileTooLarge`,WFPKG_UNSUPPORTED_FORMAT:`workflows.package.errors.unsupportedFormat`,WFPKG_INVALID_ARCHIVE:`workflows.package.errors.invalidArchive`,WFPKG_INVALID_MANIFEST:`workflows.package.errors.invalidManifest`,WFPKG_CHECKSUM_MISMATCH:`workflows.package.errors.checksumMismatch`,WFPKG_MULTIPLE_WORKFLOWS:`workflows.package.errors.multipleWorkflows`,WFPKG_WORKFLOW_INVALID:`workflows.package.errors.workflowInvalid`,WFPKG_INSPECTION_NOT_FOUND:`workflows.package.errors.inspectionNotFound`,WFPKG_INSPECTION_EXPIRED:`workflows.package.errors.inspectionExpired`,WFPKG_INSPECTION_CONSUMED:`workflows.package.errors.inspectionConsumed`,WFPKG_CONFLICT_CHANGED:`workflows.package.errors.conflictChanged`,WFPKG_ID_CONFLICT:`workflows.package.errors.idConflict`,WFPKG_INVALID_ACTION:`workflows.package.errors.invalidAction`,WFPKG_INVALID_RENAME_ID:`workflows.package.errors.invalidRenameId`,WFPKG_OVERWRITE_CONFIRMATION_REQUIRED:`workflows.package.errors.overwriteConfirmationRequired`,WFPKG_IDEMPOTENCY_KEY_REQUIRED:`workflows.package.errors.idempotencyKeyRequired`,WFPKG_IDEMPOTENCY_KEY_REUSED:`workflows.package.errors.idempotencyKeyReused`,WFPKG_IMPORT_FAILED:`workflows.package.errors.importFailed`},U={create:{label:`创建导入`,hint:`导入后会创建一个新的本地工作流。`},keep_existing:{label:`保留本地版本`,hint:`不修改当前本地工作流;导入记录会保留。`},overwrite:{label:`覆盖本地版本`,hint:`替换名称、描述、图定义和启用状态;需要再次确认。`},rename:{label:`另存为新 ID`,hint:`保留当前本地工作流,并以新的 ID 创建副本。`}},W={none:[`create`],identical:[`keep_existing`],id_conflict:[`keep_existing`,`overwrite`,`rename`]};function G(e){return(W[e]||[]).slice()}function K(e){if(!e||!String(e).trim())return{graph:null,error:`图定义不能为空`};try{let t=JSON.parse(e);return!t||typeof t!=`object`?{graph:null,error:`图定义必须是 JSON 对象`}:{graph:{nodes:Array.isArray(t.nodes)?t.nodes:[],edges:Array.isArray(t.edges)?t.edges:[],config:t.config||{}},error:null}}catch(e){return{graph:null,error:e.message||`JSON 解析失败`}}}function ae(e){let{graph:t,error:n}=K(e);return t?{nodes:t.nodes,edges:t.edges,error:null}:{nodes:[],edges:[],error:n}}function q(e,t=12){let n=String(e||``);if(!n)return`—`;let r=n.startsWith(`sha256:`)?n.slice(7):n;return r.length>t?`${r.slice(0,t)}…`:r}function J(e,t=`操作失败`){if(!e)return t;if(typeof e==`string`)return e;let n=e.payload;if(n&&typeof n==`object`){let e=n.error;if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=typeof e.message==`string`?e.message:``,n=typeof e.code==`string`?e.code:``;if(t)return n?`${t}(${n})`:t}if(typeof n.message==`string`&&n.message)return n.message}return typeof e.message==`string`&&e.message&&e.message!==`[object Object]`?e.message:t}function oe(e,t=`加载失败`){return e?{message:J(e,t)}:null}function se(e){let t=e?.payload?.error;return t&&typeof t==`object`&&typeof t.code==`string`?t.code:``}function ce(e,t){let n=se(e);if(n&&H[n]){let e=t?.(H[n],null,``);if(e)return e}return J(e,`操作未完成,请稍后重试。`)}function le(){let e=typeof globalThis<`u`?globalThis.crypto:null;return!e||typeof e.randomUUID!=`function`?``:e.randomUUID()}var Y=e(n(),1),{Text:X}=a,ue=/^[A-Za-z0-9][A-Za-z0-9_-]*$/,de={id:``,name:``,description:``,version:1,enabled:!0,graph:``};function fe({visible:e,workflow:t,onCancel:n,onSaved:r}){let a=w(),{hasPermission:s}=T(),f=s(`workflow:execute`),[p,m]=(0,R.useState)(de),[h,g]=(0,R.useState)(!1),[_,v]=(0,R.useState)(!1),[y,b]=(0,R.useState)(null),x=!!t?.id;(0,R.useEffect)(()=>{if(e){if(b(null),g(!1),t){let e=t.graph_json||``;try{e=JSON.stringify(JSON.parse(e),null,2)}catch{}m({id:t.id||``,name:t.name||``,description:t.description||``,version:t.version||1,enabled:t.enabled!==!1,graph:e})}else m({...de,graph:JSON.stringify(V,null,2)})}},[e,t]);let C=e=>m(t=>({...t,...e})),D=(0,R.useMemo)(()=>ae(p.graph),[p.graph]);return(0,Y.jsxs)(te,{visible:e,title:x?a(`workflows.metaModalTitle`,null,`工作流信息`):a(`workflows.newGraph`,null,`新建工作流`),onCancel:n,onOk:async()=>{let e=(x?t.id:p.id).trim(),n=p.name.trim();if(!e||!n)k(a(`workflows.idNameRequired`,null,`工作流 ID 和名称不能为空`));else if(!x&&!ue.test(e))k(`工作流 ID 必须以字母或数字开头,仅含字母、数字、下划线、连字符`);else{if(p.graph.trim())try{JSON.parse(p.graph)}catch(e){k(`graph 必须是合法 JSON:${J(e,``)}`);return}g(!0);try{let t={id:e,name:n,description:p.description,version:Number(p.version)||0,enabled:!!p.enabled,graph:p.graph.trim()?JSON.parse(p.graph):void 0},i=x?await E.put(`/workflows/${encodeURIComponent(e)}`,t):await E.post(`/workflows`,t);I(a(`workflows.saved`,null,`工作流已保存`)),r?.(i?.workflow||null)}catch(e){k(J(e,a(`workflows.saveFailed`,null,`保存工作流失败`)))}finally{g(!1)}}},okText:a(`common.save`,null,`保存`),cancelText:a(`common.cancel`,null,`取消`),confirmLoading:h,width:860,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-grid`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaId`,null,`ID`)}),(0,Y.jsx)(d,{value:p.id,disabled:x,placeholder:`web-scan-basic`,onChange:e=>C({id:e})}),(0,Y.jsx)(X,{type:`tertiary`,size:`small`,children:a(`workflows.metaIdHint`,null,`创建后不可修改,用于 API 与角色绑定`)})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaName`,null,`名称`)}),(0,Y.jsx)(d,{value:p.name,placeholder:a(`workflows.namePlaceholder`,null,`基础 Web 扫描`),onChange:e=>C({name:e})})]})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-grid`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaDescription`,null,`描述`)}),(0,Y.jsx)(d,{value:p.description,placeholder:a(`workflows.descriptionPlaceholder`,null,`可选`),onChange:e=>C({description:e})})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-grid workflow-form-grid--tight`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:`版本`}),(0,Y.jsx)(S,{value:p.version,min:0,style:{width:`100%`},onChange:e=>C({version:e||0})})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaEnabled`,null,`启用`)}),(0,Y.jsx)(c,{checked:p.enabled,onChange:e=>C({enabled:e.target.checked}),children:a(`workflows.metaEnabledHint`,null,`禁用后无法被角色自动触发`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsxs)(o,{children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:`graph JSON`}),(0,Y.jsx)(X,{type:`tertiary`,size:`small`,children:D.error?`解析失败:${D.error}`:`${D.nodes.length} 个节点 · ${D.edges.length} 条连线`})]}),(0,Y.jsx)(u,{value:p.graph,rows:16,spellCheck:!1,className:`workflow-graph-input`,placeholder:`{"nodes":[],"edges":[],"config":{}}`,onChange:e=>{C({graph:e}),b(null)}}),(0,Y.jsxs)(o,{wrap:!0,children:[(0,Y.jsx)(l,{size:`small`,onClick:()=>{try{C({graph:JSON.stringify(JSON.parse(p.graph),null,2)}),b(null)}catch(e){k(`${a(`projects.invalidJson`,null,`JSON 格式无效`)}:${J(e,``)}`)}},children:a(`projects.formatJson`,null,`格式化`)}),(0,Y.jsx)(l,{size:`small`,onClick:()=>{C({graph:JSON.stringify(V,null,2)}),b(null)},children:`插入最小模板`}),(0,Y.jsx)(l,{size:`small`,loading:_,disabled:!f,title:f?``:`需要 workflow:execute 权限`,onClick:async()=>{if(!p.graph.trim()){b({type:`danger`,text:a(`workflows.validation.serverFailed`,null,`图定义不能为空`)});return}let e;try{e=JSON.parse(p.graph)}catch(e){b({type:`danger`,text:`JSON 解析失败:${J(e,``)}`});return}v(!0),b(null);try{await E.post(`/workflows/validate`,{graph:e}),b({type:`success`,text:`结构校验通过`})}catch(e){b({type:`danger`,text:J(e,a(`workflows.validation.serverFailed`,null,`后端图校验失败`))})}finally{v(!1)}},children:a(`workflows.validate`,null,`校验图定义`)}),(0,Y.jsxs)(X,{type:`tertiary`,size:`small`,children:[`节点类型:`,z.map(e=>e.label).join(` / `)]})]})]}),y?(0,Y.jsx)(i,{type:y.type,bordered:!0,closeIcon:null,description:y.text,style:{marginTop:12}}):null]})}var{Text:Z}=a;function pe({raw:e}){let t=(0,R.useMemo)(()=>ae(e),[e]);if(t.error)return(0,Y.jsxs)(Z,{type:`danger`,size:`small`,children:[`graph 解析失败:`,t.error]});let n=t.nodes.map(e=>({id:e.id,type:e.type||`tool`,label:e.label||``,config:e.config||{}}));return(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsx)(b,{columns:[{title:`节点`,dataIndex:`id`,width:160,render:e=>(0,Y.jsx)(`code`,{children:e})},{title:`类型`,dataIndex:`type`,width:90,render:e=>(0,Y.jsx)(s,{size:`small`,color:`blue`,type:`light`,children:ie[e]||e})},{title:`名称`,dataIndex:`label`,render:(e,t)=>(0,Y.jsx)(`span`,{className:`workflow-cell-ellipsis`,title:e||t.id,children:e||`—`})}],dataSource:n,rowKey:`id`,size:`small`,pagination:!1,empty:(0,Y.jsx)(Z,{type:`tertiary`,size:`small`,children:`图内没有节点`})}),(0,Y.jsxs)(`div`,{className:`workflow-edge-list`,children:[(0,Y.jsxs)(Z,{strong:!0,size:`small`,children:[`连线(`,t.edges.length,`)`]}),t.edges.length?(0,Y.jsx)(`ul`,{className:`workflow-link-list`,children:t.edges.map((e,t)=>(0,Y.jsxs)(`li`,{children:[(0,Y.jsx)(`code`,{children:e.source}),` → `,(0,Y.jsx)(`code`,{children:e.target}),e.label?(0,Y.jsx)(`span`,{className:`workflow-edge-label`,children:e.label}):null]},e.id||`${e.source}-${e.target}-${t}`))}):(0,Y.jsx)(Z,{type:`tertiary`,size:`small`,children:`暂无连线`})]})]})}function me({workflowId:e,visible:t,canWrite:n,canDelete:r,onClose:i,onEdit:a,onDeleted:c}){let u=w(),[d,f]=(0,R.useState)(!1),p=O(()=>e?E.get(`/workflows/${encodeURIComponent(e)}`):Promise.resolve(null),[e]),m=p.data?.workflow||null;return(0,R.useEffect)(()=>{t&&e&&p.reload({silent:!0})},[t,e]),(0,Y.jsxs)(v,{visible:t,width:760,title:m?m.name||m.id:u(`workflows.metaModalTitle`,null,`工作流信息`),onCancel:i,footer:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{disabled:!n||!m,onClick:()=>a?.(m),children:u(`common.edit`,null,`编辑`)}),(0,Y.jsx)(l,{loading:d,disabled:!m,onClick:async()=>{if(m){f(!0);try{await D(`/workflows/${encodeURIComponent(m.id)}/package`,{filename:`${m.id}.csapkg.zip`}),I(u(`workflows.package.export`,null,`导出`))}catch(e){k(J(e,u(`workflows.package.errors.exportFailed`,null,`导出失败,请稍后重试。`)))}finally{f(!1)}}},children:u(`workflows.package.export`,null,`导出`)}),(0,Y.jsx)(l,{type:`danger`,disabled:!r||!m,onClick:()=>L({title:u(`workflows.deleteWorkflow`,null,`删除工作流`),content:u(`workflows.confirmDelete`,{id:m?.id},`确定删除工作流 ${m?.id}?`),okText:u(`common.delete`,null,`删除`),onOk:async()=>{try{await E.del(`/workflows/${encodeURIComponent(m.id)}`),I(u(`workflows.deleted`,null,`工作流已删除`)),c?.(m.id)}catch(e){k(J(e,u(`workflows.deleteFailed`,null,`删除工作流失败`)))}}}),children:u(`workflows.deleteWorkflow`,null,`删除工作流`)}),(0,Y.jsx)(l,{onClick:i,children:u(`common.close`,null,`关闭`)})]}),children:[(0,Y.jsx)(j,{error:oe(p.error),onRetry:()=>p.reload()}),m?(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsxs)(`div`,{className:`workflow-detail-tags`,children:[(0,Y.jsx)(s,{size:`small`,color:m.enabled?`green`:`grey`,children:m.enabled?u(`workflows.statusEnabled`,null,`启用`):u(`workflows.statusDisabled`,null,`禁用`)}),m.validation_error?(0,Y.jsx)(s,{size:`small`,color:`red`,children:u(`workflows.statusInvalid`,null,`校验未通过`)}):(0,Y.jsx)(s,{size:`small`,color:`green`,type:`light`,children:`结构有效`}),(0,Y.jsxs)(Z,{type:`tertiary`,size:`small`,children:[`版本 `,m.version||0]})]}),m.validation_error?(0,Y.jsx)(j,{error:{message:m.validation_error}}):null,(0,Y.jsx)(A,{columns:2,items:[{label:u(`workflows.metaId`,null,`ID`),value:(0,Y.jsx)(`code`,{children:m.id})},{label:u(`workflows.metaName`,null,`名称`),value:m.name||`—`},{label:u(`workflows.updated`,null,`更新`),value:C(m.updated_at)},{label:`创建`,value:C(m.created_at)},{label:u(`workflows.metaDescription`,null,`描述`),value:m.description||`—`}]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(Z,{strong:!0,children:u(`workflows.nodeProperties`,null,`节点属性`)}),(0,Y.jsx)(pe,{raw:m.graph_json})]}),(0,Y.jsx)(F,{value:m.graph_json?he(m.graph_json):{},title:`graph JSON`,collapsed:!0})]}):null]})}function he(e){try{return JSON.parse(e)}catch{return{raw:e}}}var{Text:Q}=a;function ge(e){let t=B[String(e||``)]||{label:e||`—`,color:`grey`};return(0,Y.jsx)(s,{size:`small`,color:t.color,children:t.label})}function _e({runId:e,visible:t,canExecute:n,onClose:r,onChanged:i}){let a=w(),[s,c]=(0,R.useState)(``),[d,f]=(0,R.useState)(!1),p=O(()=>e?E.get(`/workflows/runs/${encodeURIComponent(e)}`):Promise.resolve(null),[e]),m=O(()=>e?E.get(`/workflows/runs/${encodeURIComponent(e)}/replay`):Promise.resolve(null),[e]),h=p.data?.run||null;(0,R.useEffect)(()=>{t&&e&&(p.reload({silent:!0}),m.reload({silent:!0}))},[t,e]);let g=p.data?.nodeRuns||[],_=m.data?.steps||[],b=t=>L({title:t?`通过审批`:`拒绝审批`,content:t?`确认通过该工作流的审批节点并继续执行?`:`确认拒绝该工作流的审批节点?运行将以失败结束。`,okText:a(`common.confirm`,null,`确认`),danger:!t,onOk:async()=>{f(!0);try{await E.post(`/workflows/runs/${encodeURIComponent(e)}/resume`,{approved:t,comment:s}),I(t?`已通过审批`:`已拒绝审批`),c(``),p.reload({silent:!0}),m.reload({silent:!0}),i?.()}catch(e){k(J(e,`审批提交失败`))}finally{f(!1)}}});return(0,Y.jsxs)(v,{visible:t,width:820,title:a(`workflows.dryRunTrace`,null,`运行轨迹`),onCancel:r,footer:(0,Y.jsxs)(o,{children:[h?.status===`awaiting_hitl`&&n?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(u,{value:s,rows:1,placeholder:`审批备注(可选)`,onChange:e=>c(e),style:{width:240}}),(0,Y.jsx)(l,{type:`primary`,loading:d,onClick:()=>b(!0),children:`通过`}),(0,Y.jsx)(l,{type:`danger`,loading:d,onClick:()=>b(!1),children:`拒绝`})]}):null,(0,Y.jsx)(l,{onClick:r,children:a(`common.close`,null,`关闭`)})]}),children:[(0,Y.jsx)(j,{error:oe(p.error),onRetry:()=>p.reload()}),h?(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsxs)(`div`,{className:`workflow-detail-tags`,children:[ge(h.status),(0,Y.jsxs)(Q,{type:`tertiary`,size:`small`,children:[`运行 `,(0,Y.jsx)(`code`,{children:q(h.id,16)})]})]}),(0,Y.jsx)(A,{columns:2,items:[{label:`工作流`,value:(0,Y.jsx)(`code`,{children:h.workflow_id})},{label:`版本`,value:h.workflow_version??`—`},{label:`会话`,value:h.conversation_id||`—`},{label:`项目`,value:h.project_id||`—`},{label:`开始时间`,value:C(h.started_at)},{label:`结束时间`,value:C(h.finished_at)},h.pending_hitl_node_id?{label:`待审批节点`,value:(0,Y.jsx)(`code`,{children:h.pending_hitl_node_id})}:null,h.error?{label:`错误`,value:(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:h.error})}:null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,children:[`节点执行记录(`,g.length,`)`]}),(0,Y.jsx)(y,{className:`workflow-timeline`,children:g.length?g.map(e=>(0,Y.jsx)(y.Item,{time:C(e.started_at),type:e.status===`failed`?`error`:e.status===`completed`?`success`:`ongoing`,children:(0,Y.jsxs)(`div`,{className:`workflow-timeline-item`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`code`,{children:e.node_id}),` `,ge(e.status)]}),e.error?(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:e.error}):null,e.output_json?(0,Y.jsx)(F,{value:ve(e.output_json),title:`output`,collapsed:!0}):null]})},e.id)):(0,Y.jsx)(Q,{type:`tertiary`,size:`small`,children:`暂无节点执行记录`})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,children:[a(`workflows.dryRunTrace`,null,`回放轨迹`),`(`,_.length,` 步)`]}),(0,Y.jsx)(y,{className:`workflow-timeline`,children:_.length?_.map(e=>(0,Y.jsx)(y.Item,{time:C(e.startedAt),type:e.status===`failed`?`error`:e.status===`completed`?`success`:`ongoing`,children:(0,Y.jsxs)(`div`,{className:`workflow-timeline-item`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,size:`small`,children:[`#`,e.step]}),` `,(0,Y.jsx)(`code`,{children:e.nodeId}),` `,ge(e.status)]}),e.error?(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:e.error}):null,(0,Y.jsx)(F,{value:{input:e.input,output:e.output},title:`step`,collapsed:!0})]})},e.nodeRunId||`${e.step}-${e.nodeId}`)):(0,Y.jsx)(Q,{type:`tertiary`,size:`small`,children:a(`workflows.dryRunNoTrace`,null,`暂无轨迹`)})})]}),(0,Y.jsx)(F,{value:h,title:`run`,collapsed:!0})]}):null]})}function ve(e){try{return JSON.parse(e)}catch{return{raw:e}}}var{Text:ye}=a;function be({canExecute:e}){let t=w(),[n,i]=r(),a=n.get(`run`)||``,c=O(()=>E.get(`/workflows/runs/pending`),[]);N(()=>c.reload({silent:!0}),15e3);let u=Array.isArray(c.data?.runs)?c.data.runs:[],d=e=>{let t=new URLSearchParams(n);e?t.set(`run`,e):t.delete(`run`),i(t,{replace:!0})},f=[{title:`运行`,dataIndex:`id`,width:190,render:e=>(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>d(e),children:(0,Y.jsx)(`code`,{children:q(e,14)})})},{title:`工作流`,dataIndex:`workflow_id`,width:200,render:e=>(0,Y.jsx)(ye,{size:`small`,children:(0,Y.jsx)(`code`,{children:e})})},{title:`会话`,dataIndex:`conversation_id`,width:220,render:e=>(0,Y.jsx)(ye,{type:`tertiary`,size:`small`,children:(0,Y.jsx)(`code`,{children:e||`—`})})},{title:t(`projects.status`,null,`状态`),dataIndex:`status`,width:110,render:e=>{let t=B[String(e||``)]||{label:e||`—`,color:`grey`};return(0,Y.jsx)(s,{size:`small`,color:t.color,children:t.label})}},{title:`待审批节点`,dataIndex:`pending_hitl_node_id`,width:160,render:e=>e?(0,Y.jsx)(`code`,{children:e}):(0,Y.jsx)(ye,{type:`tertiary`,children:`—`})},{title:`开始时间`,dataIndex:`started_at`,width:165,render:e=>(0,Y.jsx)(ye,{size:`small`,children:C(e)})},{title:t(`common.actions`,null,`操作`),dataIndex:`id`,width:120,render:e=>(0,Y.jsx)(o,{children:(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>d(e),children:t(`projects.details`,null,`详情`)})})}];return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(M,{title:t(`workflows.runsPending`,null,`待审批运行`),description:`等待审批(awaiting_hitl)的工作流运行,每 15 秒自动刷新。${e?` 可直接在此通过或拒绝。`:``}`,extra:(0,Y.jsx)(l,{icon:(0,Y.jsx)(x,{}),theme:`borderless`,loading:c.loading,onClick:()=>c.reload(),children:t(`common.refresh`,null,`刷新`)}),children:[(0,Y.jsx)(j,{error:oe(c.error),onRetry:()=>c.reload()}),(0,Y.jsx)(P,{columns:f,dataSource:u,rowKey:`id`,loading:c.loading,pagination:{pageSize:10},emptyText:`当前没有等待审批的工作流运行`})]}),(0,Y.jsx)(_e,{runId:a,visible:!!a,canExecute:e,onClose:()=>d(``),onChanged:()=>c.reload({silent:!0})})]})}var{Text:$,Paragraph:xe}=a,Se=10485760;function Ce(e){let t=String(e||``).replace(/^data:[^;]+;base64,/,``).replace(/\s+/g,``);if(!t)throw Error(`粘贴内容为空`);let n=atob(t),r=new Uint8Array(n.length);for(let e=0;e{e||(f(null),m(``),v(``),b(null),S(``),D(``),O(!1),N(``),F(null),j(!1),ne(!1))},[e]);let L=y?.conflict?.state||``,z=(0,R.useMemo)(()=>G(L),[L]),ie=()=>{v(``);try{let e=Ce(p);if(e.size>Se){v(r(`workflows.package.errors.fileTooLarge`,null,`文件超过 10 MiB 限制,请选择更小的本地包。`));return}f(e),b(null),F(null)}catch(e){v(`Base64 解码失败:${J(e,``)}`)}},B=e=>{let t=e.target.files&&e.target.files[0];v(``),N(``),F(null),b(null),t?t.size>Se?(v(r(`workflows.package.errors.fileTooLarge`,null,`文件超过 10 MiB 限制,请选择更小的本地包。`)),f(null)):f(t):f(null)},V=async()=>{if(!a)v(r(`workflows.package.errors.fileRequired`,null,`请选择本地工作流包后再预检。`));else{j(!0),N(``),F(null);try{let e=new FormData;e.append(`file`,a,a.name||`workflow.csapkg.zip`);let t=(await E.post(`/workflow-package-inspections`,e))?.inspection||null;b(t);let n=G(t?.conflict?.state||``);S(n[0]||``),D(``),O(!1)}catch(e){N(ce(e,r))}finally{j(!1)}}},H=async()=>{if(!y?.id){N(r(`workflows.package.resolution.needInspection`,null,`请先选择本地包并完成预检。`));return}if(!x){N(r(`workflows.package.errors.invalidAction`,null,`导入处理方式无效,请重新选择。`));return}if(x===`rename`&&!T.trim()){N(r(`workflows.package.errors.invalidRenameId`,null,`请输入可用的新工作流 ID。`));return}if(x===`overwrite`&&!ee){N(r(`workflows.package.errors.overwriteConfirmationRequired`,null,`请勾选确认后再覆盖本地工作流。`));return}let e=le();if(!e)N(r(`workflows.package.errors.idempotencyKeyRequired`,null,`浏览器无法生成导入请求标识,请刷新页面后重试。`));else{ne(!0),N(``);try{let t=await E.post(`/workflow-package-imports`,{inspection_id:y.id,resolution:{action:x,new_workflow_id:x===`rename`?T.trim():``},confirm_overwrite:x===`overwrite`},{headers:{"Idempotency-Key":e}});F(t?.import||null),I(r(`workflows.package.result.complete`,null,`导入已完成。`)),n?.(t?.import||null)}catch(e){N(ce(e,r))}finally{ne(!1)}}},W=L===`identical`?r(`workflows.package.conflict.identical`,null,`检测到同 ID 且内容相同的本地工作流;本次将跳过导入。`):L===`id_conflict`?r(`workflows.package.conflict.idConflict`,null,`检测到同 ID 但内容不同的本地工作流。默认保留本地版本。`):L===`none`?r(`workflows.package.conflict.none`,null,`未发现同 ID 的本地工作流,可创建导入。`):``,K=y?.workflow;return(0,Y.jsxs)(te,{visible:e,title:r(`workflows.package.title`,null,`导入本地包`),onCancel:t,width:760,maskClosable:!k&&!M,footer:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{onClick:t,children:r(`common.close`,null,`关闭`)}),(0,Y.jsx)(l,{type:`primary`,loading:k,disabled:!!P,onClick:V,children:k?r(`workflows.package.inspecting`,null,`正在安全预检…`):r(`workflows.package.inspect`,null,`上传并预检`)}),(0,Y.jsx)(l,{type:`primary`,loading:M,disabled:!y||!!P||!x,onClick:H,children:r(`workflows.package.confirmImport`,null,`确认导入`)})]}),children:[(0,Y.jsxs)(xe,{type:`tertiary`,size:`small`,children:[r(`workflows.package.preflightHint`,null,`先检查包内容与冲突,再由你确认是否导入`),` · `,r(`workflows.package.fileHint`,null,`仅支持单个 .csapkg.zip,文件不得超过 10 MiB。`)]}),(0,Y.jsxs)(`div`,{className:`workflow-package-block`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.stepInspection`,null,`上传与预检`)}),(0,Y.jsxs)(`div`,{className:`workflow-package-file-row`,children:[(0,Y.jsx)(`input`,{type:`file`,accept:`.zip,application/zip`,className:`workflow-file-input`,onChange:B,"aria-label":r(`workflows.package.selectFile`,null,`选择本地包`)}),(0,Y.jsx)($,{type:`tertiary`,size:`small`,children:a?`${a.name} · ${(a.size/1024).toFixed(1)} KiB`:r(`workflows.package.noFile`,null,`未选择文件`)}),a?(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>{f(null),b(null),F(null)},children:r(`workflows.package.removeFile`,null,`移除文件`)}):null]}),(0,Y.jsx)(u,{value:p,rows:3,placeholder:`或粘贴工作流包 base64(.csapkg.zip)`,onChange:e=>m(e)}),(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{size:`small`,onClick:ie,disabled:!p.trim(),children:`使用粘贴内容`}),g?(0,Y.jsx)($,{type:`danger`,size:`small`,children:g}):null]})]}),re?(0,Y.jsx)(i,{type:`danger`,bordered:!0,closeIcon:null,description:re,className:`workflow-package-banner`}):null,y?(0,Y.jsxs)(`div`,{className:`workflow-package-block`,children:[(0,Y.jsxs)(`div`,{className:`workflow-package-summary-head`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.summary.title`,null,`预检结果`)}),(0,Y.jsx)(s,{size:`small`,color:`green`,children:r(`workflows.package.summary.passed`,null,`校验通过`)})]}),(0,Y.jsx)(i,{type:L===`id_conflict`?`warning`:`success`,bordered:!0,closeIcon:null,description:W,className:`workflow-package-banner`}),(0,Y.jsx)(A,{columns:2,items:[{label:r(`workflows.package.summary.workflowName`,null,`工作流名称`),value:K?.name||`—`},{label:r(`workflows.package.summary.sourceId`,null,`源工作流 ID`),value:(0,Y.jsx)(`code`,{children:K?.source_id||`—`})},{label:r(`workflows.package.summary.sourceRevision`,null,`源版本`),value:K?.source_revision??`—`},{label:r(`workflows.package.summary.graphSize`,null,`图规模`),value:`${K?.node_count||0} 节点 · ${K?.edge_count||0} 连线`},{label:r(`workflows.package.summary.contentHash`,null,`内容摘要`),value:q(K?.content_hash)},{label:r(`workflows.package.summary.expiresAt`,null,`预检有效期`),value:C(y.expires_at)}]}),(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.resolutionTitle`,null,`处理方式`)}),(0,Y.jsx)(h,{value:x,onChange:e=>{S(e.target.value),O(!1)},direction:`vertical`,children:z.map(e=>(0,Y.jsx)(_,{value:e,children:(0,Y.jsxs)(`span`,{className:`workflow-package-action`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:U[e]?.label||e}),(0,Y.jsx)($,{type:`tertiary`,size:`small`,children:U[e]?.hint||``})]})},e))}),x===`rename`?(0,Y.jsx)(d,{value:T,placeholder:r(`workflows.package.resolution.newWorkflowIdPlaceholder`,null,`例如:web-scan-basic-copy`),onChange:e=>D(e)}):null,x===`overwrite`?(0,Y.jsxs)(`div`,{className:`workflow-package-overwrite`,children:[(0,Y.jsx)(i,{type:`warning`,bordered:!0,closeIcon:null,description:r(`workflows.package.overwriteWarning`,null,`覆盖将替换名称、描述、图定义和启用状态。本期不提供回滚。`)}),(0,Y.jsx)(c,{checked:ee,onChange:e=>O(e.target.checked),children:r(`workflows.package.overwriteCheck`,null,`我已确认覆盖当前本地工作流`)})]}):null]}):null,P?(0,Y.jsx)(i,{type:`success`,bordered:!0,closeIcon:null,className:`workflow-package-banner`,description:r(we[P.result]||`workflows.package.result.complete`,null,`导入已完成。`)}):null]})}var{Text:Ee}=a;async function De(){let[e,t]=await Promise.all([E.get(`/workflows`,{includeDisabled:`true`}),E.get(`/workflows/runs/pending`).catch(()=>null)]);return{workflows:Array.isArray(e?.workflows)?e.workflows:[],pendingRuns:Array.isArray(t?.runs)?t.runs:[]}}function Oe(){let e=w(),{hasPermission:t}=T(),n=t(`workflow:write`),i=t(`workflow:delete`),a=t(`workflow:execute`),[c,u]=r(),h=c.get(`id`)||``,_=c.get(`tab`)||`list`,[v,y]=(0,R.useState)(``),b=ne(v,250),[S,te]=(0,R.useState)(!0),[A,N]=(0,R.useState)({visible:!1,workflow:null}),[F,z]=(0,R.useState)(!1),[ie,B]=(0,R.useState)(0),V=O(De,[ie]),H=V.data?.workflows||[],U=V.data?.pendingRuns||[],W=(0,R.useCallback)((e,t)=>{let n=new URLSearchParams(c);e?n.set(`id`,e):n.delete(`id`),t?n.set(`tab`,t):n.delete(`tab`),t&&t!==`runs`&&n.delete(`run`),u(n,{replace:!!e})},[c,u]),G=()=>B(e=>e+1),K=(0,R.useMemo)(()=>{let e=b.trim().toLowerCase();return H.filter(t=>!S&&t.enabled===!1?!1:!e||[t.id,t.name,t.description].join(` `).toLowerCase().includes(e))},[H,b,S]),q=H.filter(e=>!!e.validation_error).length,se=H.filter(e=>e.enabled).length,ce=[{id:`total`,label:e(`workflows.processLibrary`,null,`工作流列表`),value:H.length,loading:V.loading},{id:`enabled`,label:e(`workflows.statusEnabled`,null,`启用`),value:se,tone:`success`,loading:V.loading},{id:`invalid`,label:e(`workflows.statusInvalid`,null,`校验未通过`),value:q,tone:q?`danger`:void 0,loading:V.loading},{id:`pending`,label:e(`workflows.runsPending`,null,`待审批运行`),value:U.length,tone:U.length?`warning`:void 0,loading:V.loading}],le=async t=>{try{await D(`/workflows/${encodeURIComponent(t.id)}/package`,{filename:`${t.id}.csapkg.zip`}),I(e(`workflows.package.export`,null,`导出`))}catch(t){k(J(t,e(`workflows.package.errors.exportFailed`,null,`导出失败,请稍后重试。`)))}},X=t=>L({title:e(`workflows.deleteWorkflow`,null,`删除工作流`),content:e(`workflows.confirmDelete`,{id:t.id},`确定删除工作流 ${t.id}?`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await E.del(`/workflows/${encodeURIComponent(t.id)}`),I(e(`workflows.deleted`,null,`工作流已删除`)),h===t.id&&W(void 0,_),G()}catch(t){k(J(t,e(`workflows.deleteFailed`,null,`删除工作流失败`)))}}}),ue=[{title:e(`workflows.metaName`,null,`名称`),dataIndex:`name`,render:(t,n)=>{let r=ae(n.graph_json);return(0,Y.jsxs)(`button`,{type:`button`,className:`workflow-name-button`,onClick:()=>W(n.id,`list`),title:n.id,children:[(0,Y.jsx)(`span`,{className:`workflow-name-text`,children:t||e(`workflows.untitled`,null,`未命名工作流`)}),(0,Y.jsxs)(`span`,{className:`workflow-name-sub`,children:[(0,Y.jsx)(`code`,{children:n.id}),` · `,r.error?`图解析失败`:`${r.nodes.length} 节点 / ${r.edges.length} 连线`]})]})}},{title:e(`projects.status`,null,`状态`),dataIndex:`enabled`,width:150,render:(t,n)=>(0,Y.jsxs)(o,{spacing:4,wrap:!0,children:[(0,Y.jsx)(s,{size:`small`,color:t?`green`:`grey`,children:t?e(`workflows.statusEnabled`,null,`启用`):e(`workflows.statusDisabled`,null,`禁用`)}),n.validation_error?(0,Y.jsx)(s,{size:`small`,color:`red`,children:e(`workflows.statusInvalid`,null,`校验未通过`)}):null]})},{title:`版本`,dataIndex:`version`,width:80,render:e=>(0,Y.jsxs)(Ee,{size:`small`,children:[`v`,e??0]})},{title:e(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:165,render:e=>(0,Y.jsx)(Ee,{type:`tertiary`,size:`small`,children:C(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:260,render:(t,r)=>(0,Y.jsxs)(o,{spacing:2,wrap:!0,children:[(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>W(r.id,`list`),children:e(`projects.details`,null,`详情`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>N({visible:!0,workflow:r}),children:e(`common.edit`,null,`编辑`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>le(r),children:e(`workflows.package.export`,null,`导出`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!i,onClick:()=>X(r),children:e(`common.delete`,null,`删除`)})]})}];return(0,Y.jsxs)(`div`,{className:`workflow-page`,children:[(0,Y.jsx)(re,{title:e(`workflows.title`,null,`工作流`),description:e(`workflows.processLibraryHint`,null,`工作流定义由节点与连线组成,可被角色或对话按需触发。`),extra:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{icon:(0,Y.jsx)(x,{}),theme:`borderless`,loading:V.loading,onClick:G,children:e(`common.refresh`,null,`刷新`)}),(0,Y.jsx)(l,{disabled:!n,onClick:()=>z(!0),children:e(`workflows.package.importLocal`,null,`导入本地包`)}),(0,Y.jsx)(l,{type:`primary`,icon:(0,Y.jsx)(m,{}),disabled:!n,onClick:()=>N({visible:!0,workflow:null}),children:e(`workflows.newGraph`,null,`新建工作流`)})]})}),(0,Y.jsx)(j,{error:oe(V.error),onRetry:G}),(0,Y.jsx)(ee,{metrics:ce,columns:4}),(0,Y.jsx)(f,{type:`line`,activeKey:_,onChange:e=>W(void 0,e),tabList:[{itemKey:`list`,tab:e(`workflows.processLibrary`,null,`工作流列表`)},{itemKey:`runs`,tab:e(`workflows.runsPending`,null,`运行历史`)}],className:`workflow-tabs`}),_===`runs`?(0,Y.jsx)(be,{canExecute:a}):(0,Y.jsxs)(M,{title:e(`workflows.processLibrary`,null,`工作流列表`),description:e(`workflows.metaIdHint`,null,`创建后不可修改,用于 API 与角色绑定`),extra:(0,Y.jsxs)(Ee,{type:`tertiary`,size:`small`,children:[K.length,` / `,H.length]}),children:[(0,Y.jsxs)(`div`,{className:`workflow-toolbar`,children:[(0,Y.jsx)(d,{prefix:(0,Y.jsx)(g,{}),value:v,showClear:!0,placeholder:e(`workflows.searchPlaceholder`,null,`搜索工作流…`),onChange:e=>y(e),style:{width:260}}),(0,Y.jsxs)(o,{spacing:6,children:[(0,Y.jsx)(p,{checked:S,onChange:te,size:`small`}),(0,Y.jsx)(Ee,{size:`small`,children:`显示已禁用`})]})]}),(0,Y.jsx)(P,{columns:ue,dataSource:K,rowKey:`id`,loading:V.loading,pagination:{pageSize:10},emptyText:e(`workflows.emptyList`,null,`暂无工作流`)})]}),(0,Y.jsx)(fe,{visible:A.visible,workflow:A.workflow,onCancel:()=>N({visible:!1,workflow:null}),onSaved:e=>{N({visible:!1,workflow:null}),G(),e?.id&&W(e.id,`list`)}}),(0,Y.jsx)(me,{workflowId:h,visible:!!h,canWrite:n,canDelete:i,onClose:()=>W(void 0,_),onEdit:e=>{e&&(W(void 0,_),N({visible:!0,workflow:e}))},onDeleted:()=>{W(void 0,_),G()}}),(0,Y.jsx)(Te,{visible:F,onCancel:()=>z(!1),onImported:()=>G()})]})}export{Oe as default};
\ No newline at end of file
diff --git a/web/static/app/index.html b/web/static/app/index.html
index dd6ef9d0..77b05453 100644
--- a/web/static/app/index.html
+++ b/web/static/app/index.html
@@ -18,7 +18,7 @@
} catch (error) { /* first paint fallback */ }
})();
-
+