import{r as m,j as e,L as br,e as ua,R as Ts,b as Ky,f as Qy,g as Yy,h as Jy,k as Ws,l as Xy,m as Zy,O as vg,n as Wy}from"./router-Bz250laD.js";import{a as e0,b as s0,g as t0}from"./react-vendor-BmxF9s7Q.js";import{N as a0,c as l0,O as Ar,P as n0,g as lm}from"./utils-BXc2jIuz.js";import{L as Ng,T as bg,C as yg,R as r0,a as wg,V as i0,b as c0,S as _g,c as o0,d as Sg,I as d0,e as Cg,f as u0,g as kg,h as m0,i as x0,j as h0,O as Tg,P as f0,k as Eg,l as Mg,D as Ag,A as zg,m as Dg,n as p0,o as g0,p as Og,q as j0,r as Rg,s as v0,t as N0,u as Lg,v as b0,w as y0,x as Ug,y as Bg,F as $g,z as Hg,B as w0,E as _0,G as Ig,H as S0,J as C0,K as k0,M as T0,N as E0,Q as M0,U as A0,W as z0,X as D0,Y as O0,Z as R0,_ as L0,$ as U0,a0 as B0,a1 as $0,a2 as Pg,a3 as H0,a4 as I0}from"./radix-extra-Dp24oM_w.js";import{R as P0,T as G0,L as q0,g as F0,C as uo,X as mo,Y as Ci,h as V0,B as nm,j as xo,P as K0,k as Q0,l as Y0}from"./charts-DbiuC1q1.js";import{S as J0,H as Gg,O as qg,o as X0,C as Fg,p as Z0,T as Vg,D as Kg,R as W0,q as ew,I as Qg,J as sw,K as Yg,L as Jg,M as tw,N as Xg,V as aw,Q as Zg,U as Wg,X as lw,Y as nw,Z as ej,_ as rw,$ as iw,a0 as sj,a1 as cw,e as tj,f as zo,c as Do,P as An,d as Oo,b as Zl,h as ow,l as dw,m as uw,u as wm,r as mw,a as xw,a2 as hw,a3 as aj,a4 as fw,a5 as pw,a6 as gw,a7 as lj,a8 as nj,a9 as rj,aa as ij,ab as cj,ac as oj,ad as jw}from"./radix-core-C_kRl1e_.js";import{R as zt,a as Ui,C as Dt,b as oa,L as Js,P as Vi,Z as Sn,F as Ha,c as vw,S as zn,d as Nw,M as Wl,A as bw,D as yw,e as Cr,f as Nl,T as ww,X as Da,g as _w,h as Sw,I as Jt,i as Qt,j as _t,k as _o,E as Bi,l as Xt,m as dj,H as Cw,n as ns,o as Yt,U as $i,p as uj,q as mj,r as Pp,K as Am,s as xj,t as kw,u as vo,v as Tw,B as Mi,w as kr,x as zm,y as Ew,z as Mw,G as Vt,J as Ro,N as en,O as lt,Q as Oa,V as Tr,W as Dm,Y as hj,_ as Ki,$ as fj,a0 as pj,a1 as Cn,a2 as zr,a3 as Wa,a4 as ba,a5 as Dr,a6 as Om,a7 as gj,a8 as ca,a9 as yl,aa as kn,ab as Tn,ac as Rm,ad as Aw,ae as zw,af as Dw,ag as jj,ah as No,ai as En,aj as Ow,ak as Er,al as Rw,am as _m,an as Sm,ao as vj,ap as Lw,aq as Uw,ar as Gp,as as Bw,at as vl,au as rm,av as qp,aw as Nj,ax as $w,ay as bj,az as im,aA as Hw,aB as Iw,aC as Pw,aD as Gw,aE as yj,aF as wj,aG as So,aH as qw,aI as _j,aJ as Sj,aK as Fw,aL as Vw,aM as Fp,aN as Kw,aO as Qw,aP as Yw,aQ as Jw}from"./icons-1LFGNRso.js";import{S as Xw,p as Zw,j as Ww,a as e1,E as Vp,R as s1,o as t1}from"./codemirror-BEE0n9kQ.js";import{u as Cj,a as Co,s as kj,K as Tj,P as Ej,b as Mj,D as Aj,c as zj,S as Dj,v as a1,d as Oj,C as Rj,h as l1}from"./dnd-B_gmzEl7.js";import{_ as ma,c as n1,g as Lj,D as r1,z as ho}from"./misc-ChwNwoVu.js";import{D as i1,U as c1}from"./uppy-CcUbCiwl.js";import{M as o1,r as d1,a as u1,b as m1}from"./markdown-kUhwkcQP.js";import{c as x1,H as ko,P as To,u as h1,d as f1,R as p1,B as g1,e as j1,C as v1,M as N1,f as b1}from"./reactflow-DLoXAt4c.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const u of document.querySelectorAll('link[rel="modulepreload"]'))c(u);new MutationObserver(u=>{for(const x of u)if(x.type==="childList")for(const h of x.addedNodes)h.tagName==="LINK"&&h.rel==="modulepreload"&&c(h)}).observe(document,{childList:!0,subtree:!0});function i(u){const x={};return u.integrity&&(x.integrity=u.integrity),u.referrerPolicy&&(x.referrerPolicy=u.referrerPolicy),u.crossOrigin==="use-credentials"?x.credentials="include":u.crossOrigin==="anonymous"?x.credentials="omit":x.credentials="same-origin",x}function c(u){if(u.ep)return;u.ep=!0;const x=i(u);fetch(u.href,x)}})();var cm={exports:{}},ki={},om={exports:{}},dm={};var Kp;function y1(){return Kp||(Kp=1,(function(l){function n(A,Y){var H=A.length;A.push(Y);e:for(;0>>1,$=A[U];if(0>>1;U<_e;){var Ne=2*(U+1)-1,Se=A[Ne],V=Ne+1,ye=A[V];if(0>u(Se,H))V<$&&0>u(ye,Se)?(A[U]=ye,A[V]=H,U=V):(A[U]=Se,A[Ne]=H,U=Ne);else if(V<$&&0>u(ye,H))A[U]=ye,A[V]=H,U=V;else break e}}return Y}function u(A,Y){var H=A.sortIndex-Y.sortIndex;return H!==0?H:A.id-Y.id}if(l.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var x=performance;l.unstable_now=function(){return x.now()}}else{var h=Date,f=h.now();l.unstable_now=function(){return h.now()-f}}var p=[],g=[],v=1,N=null,y=3,w=!1,b=!1,L=!1,D=!1,T=typeof setTimeout=="function"?setTimeout:null,F=typeof clearTimeout=="function"?clearTimeout:null,O=typeof setImmediate<"u"?setImmediate:null;function S(A){for(var Y=i(g);Y!==null;){if(Y.callback===null)c(g);else if(Y.startTime<=A)c(g),Y.sortIndex=Y.expirationTime,n(p,Y);else break;Y=i(g)}}function C(A){if(L=!1,S(A),!b)if(i(p)!==null)b=!0,P||(P=!0,be());else{var Y=i(g);Y!==null&&je(C,Y.startTime-A)}}var P=!1,M=-1,Z=5,G=-1;function ce(){return D?!0:!(l.unstable_now()-GA&&ce());){var U=N.callback;if(typeof U=="function"){N.callback=null,y=N.priorityLevel;var $=U(N.expirationTime<=A);if(A=l.unstable_now(),typeof $=="function"){N.callback=$,S(A),Y=!0;break s}N===i(p)&&c(p),S(A)}else c(p);N=i(p)}if(N!==null)Y=!0;else{var _e=i(g);_e!==null&&je(C,_e.startTime-A),Y=!1}}break e}finally{N=null,y=H,w=!1}Y=void 0}}finally{Y?be():P=!1}}}var be;if(typeof O=="function")be=function(){O(de)};else if(typeof MessageChannel<"u"){var me=new MessageChannel,pe=me.port2;me.port1.onmessage=de,be=function(){pe.postMessage(null)}}else be=function(){T(de,0)};function je(A,Y){M=T(function(){A(l.unstable_now())},Y)}l.unstable_IdlePriority=5,l.unstable_ImmediatePriority=1,l.unstable_LowPriority=4,l.unstable_NormalPriority=3,l.unstable_Profiling=null,l.unstable_UserBlockingPriority=2,l.unstable_cancelCallback=function(A){A.callback=null},l.unstable_forceFrameRate=function(A){0>A||125U?(A.sortIndex=H,n(g,A),i(p)===null&&A===i(g)&&(L?(F(M),M=-1):L=!0,je(C,H-U))):(A.sortIndex=$,n(p,A),b||w||(b=!0,P||(P=!0,be()))),A},l.unstable_shouldYield=ce,l.unstable_wrapCallback=function(A){var Y=y;return function(){var H=y;y=Y;try{return A.apply(this,arguments)}finally{y=H}}}})(dm)),dm}var Qp;function w1(){return Qp||(Qp=1,om.exports=y1()),om.exports}var Yp;function _1(){if(Yp)return ki;Yp=1;var l=w1(),n=e0(),i=s0();function c(s){var t="https://react.dev/errors/"+s;if(1$||(s.current=U[$],U[$]=null,$--)}function Se(s,t){$++,U[$]=s.current,s.current=t}var V=_e(null),ye=_e(null),W=_e(null),ue=_e(null);function ke(s,t){switch(Se(W,t),Se(ye,s),Se(V,null),t.nodeType){case 9:case 11:s=(s=t.documentElement)&&(s=s.namespaceURI)?up(s):0;break;default:if(s=t.tagName,t=t.namespaceURI)t=up(t),s=mp(t,s);else switch(s){case"svg":s=1;break;case"math":s=2;break;default:s=0}}Ne(V),Se(V,s)}function J(){Ne(V),Ne(ye),Ne(W)}function ee(s){s.memoizedState!==null&&Se(ue,s);var t=V.current,a=mp(t,s.type);t!==a&&(Se(ye,s),Se(V,a))}function De(s){ye.current===s&&(Ne(V),Ne(ye)),ue.current===s&&(Ne(ue),yi._currentValue=H)}var Fe,ge;function as(s){if(Fe===void 0)try{throw Error()}catch(a){var t=a.stack.trim().match(/\n( *(at )?)/);Fe=t&&t[1]||"",ge=-1)":-1o||R[r]!==te[o]){var xe=` `+R[r].replace(" at new "," at ");return s.displayName&&xe.includes("")&&(xe=xe.replace("",s.displayName)),xe}while(1<=r&&0<=o);break}}}finally{ae=!1,Error.prepareStackTrace=a}return(a=s?s.displayName||s.name:"")?as(a):""}function ie(s,t){switch(s.tag){case 26:case 27:case 5:return as(s.type);case 16:return as("Lazy");case 13:return s.child!==t&&t!==null?as("Suspense Fallback"):as("Suspense");case 19:return as("SuspenseList");case 0:case 15:return Ee(s.type,!1);case 11:return Ee(s.type.render,!1);case 1:return Ee(s.type,!0);case 31:return as("Activity");default:return""}}function ve(s){try{var t="",a=null;do t+=ie(s,a),a=s,s=s.return;while(s);return t}catch(r){return` Error generating stack: `+r.message+` `+r.stack}}var Me=Object.prototype.hasOwnProperty,Ze=l.unstable_scheduleCallback,js=l.unstable_cancelCallback,Ot=l.unstable_shouldYield,rs=l.unstable_requestPaint,Ps=l.unstable_now,Q=l.unstable_getCurrentPriorityLevel,Ge=l.unstable_ImmediatePriority,He=l.unstable_UserBlockingPriority,Ve=l.unstable_NormalPriority,Bs=l.unstable_LowPriority,Ce=l.unstable_IdlePriority,cs=l.log,Es=l.unstable_setDisableYieldValue,zs=null,es=null;function We(s){if(typeof cs=="function"&&Es(s),es&&typeof es.setStrictMode=="function")try{es.setStrictMode(zs,s)}catch{}}var vs=Math.clz32?Math.clz32:it,mt=Math.log,Rt=Math.LN2;function it(s){return s>>>=0,s===0?32:31-(mt(s)/Rt|0)|0}var ss=256,St=262144,$t=4194304;function Mt(s){var t=s&42;if(t!==0)return t;switch(s&-s){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return s&261888;case 262144:case 524288:case 1048576:case 2097152:return s&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return s&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return s}}function Ga(s,t,a){var r=s.pendingLanes;if(r===0)return 0;var o=0,d=s.suspendedLanes,j=s.pingedLanes;s=s.warmLanes;var _=r&134217727;return _!==0?(r=_&~d,r!==0?o=Mt(r):(j&=_,j!==0?o=Mt(j):a||(a=_&~s,a!==0&&(o=Mt(a))))):(_=r&~d,_!==0?o=Mt(_):j!==0?o=Mt(j):a||(a=r&~s,a!==0&&(o=Mt(a)))),o===0?0:t!==0&&t!==o&&(t&d)===0&&(d=o&-o,a=t&-t,d>=a||d===32&&(a&4194048)!==0)?t:o}function qa(s,t){return(s.pendingLanes&~(s.suspendedLanes&~s.pingedLanes)&t)===0}function Rn(s,t){switch(s){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function X(){var s=$t;return $t<<=1,($t&62914560)===0&&($t=4194304),s}function z(s){for(var t=[],a=0;31>a;a++)t.push(s);return t}function q(s,t){s.pendingLanes|=t,t!==268435456&&(s.suspendedLanes=0,s.pingedLanes=0,s.warmLanes=0)}function Be(s,t,a,r,o,d){var j=s.pendingLanes;s.pendingLanes=a,s.suspendedLanes=0,s.pingedLanes=0,s.warmLanes=0,s.expiredLanes&=a,s.entangledLanes&=a,s.errorRecoveryDisabledLanes&=a,s.shellSuspendCounter=0;var _=s.entanglements,R=s.expirationTimes,te=s.hiddenUpdates;for(a=j&~a;0"u")return null;try{return s.activeElement||s.body}catch{return s.body}}var IN=/[\n"\\]/g;function wa(s){return s.replace(IN,function(t){return"\\"+t.charCodeAt(0).toString(16)+" "})}function Zo(s,t,a,r,o,d,j,_){s.name="",j!=null&&typeof j!="function"&&typeof j!="symbol"&&typeof j!="boolean"?s.type=j:s.removeAttribute("type"),t!=null?j==="number"?(t===0&&s.value===""||s.value!=t)&&(s.value=""+ya(t)):s.value!==""+ya(t)&&(s.value=""+ya(t)):j!=="submit"&&j!=="reset"||s.removeAttribute("value"),t!=null?Wo(s,j,ya(t)):a!=null?Wo(s,j,ya(a)):r!=null&&s.removeAttribute("value"),o==null&&d!=null&&(s.defaultChecked=!!d),o!=null&&(s.checked=o&&typeof o!="function"&&typeof o!="symbol"),_!=null&&typeof _!="function"&&typeof _!="symbol"&&typeof _!="boolean"?s.name=""+ya(_):s.removeAttribute("name")}function lx(s,t,a,r,o,d,j,_){if(d!=null&&typeof d!="function"&&typeof d!="symbol"&&typeof d!="boolean"&&(s.type=d),t!=null||a!=null){if(!(d!=="submit"&&d!=="reset"||t!=null)){Xo(s);return}a=a!=null?""+ya(a):"",t=t!=null?""+ya(t):a,_||t===s.value||(s.value=t),s.defaultValue=t}r=r??o,r=typeof r!="function"&&typeof r!="symbol"&&!!r,s.checked=_?s.checked:!!r,s.defaultChecked=!!r,j!=null&&typeof j!="function"&&typeof j!="symbol"&&typeof j!="boolean"&&(s.name=j),Xo(s)}function Wo(s,t,a){t==="number"&&ec(s.ownerDocument)===s||s.defaultValue===""+a||(s.defaultValue=""+a)}function In(s,t,a,r){if(s=s.options,t){t={};for(var o=0;o"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),ld=!1;if(tl)try{var Hr={};Object.defineProperty(Hr,"passive",{get:function(){ld=!0}}),window.addEventListener("test",Hr,Hr),window.removeEventListener("test",Hr,Hr)}catch{ld=!1}var Tl=null,nd=null,tc=null;function ux(){if(tc)return tc;var s,t=nd,a=t.length,r,o="value"in Tl?Tl.value:Tl.textContent,d=o.length;for(s=0;s=Gr),gx=" ",jx=!1;function vx(s,t){switch(s){case"keyup":return fb.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Nx(s){return s=s.detail,typeof s=="object"&&"data"in s?s.data:null}var Fn=!1;function gb(s,t){switch(s){case"compositionend":return Nx(t);case"keypress":return t.which!==32?null:(jx=!0,gx);case"textInput":return s=t.data,s===gx&&jx?null:s;default:return null}}function jb(s,t){if(Fn)return s==="compositionend"||!dd&&vx(s,t)?(s=ux(),tc=nd=Tl=null,Fn=!1,s):null;switch(s){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:a,offset:t-s};s=r}e:{for(;a;){if(a.nextSibling){a=a.nextSibling;break e}a=a.parentNode}a=void 0}a=Tx(a)}}function Mx(s,t){return s&&t?s===t?!0:s&&s.nodeType===3?!1:t&&t.nodeType===3?Mx(s,t.parentNode):"contains"in s?s.contains(t):s.compareDocumentPosition?!!(s.compareDocumentPosition(t)&16):!1:!1}function Ax(s){s=s!=null&&s.ownerDocument!=null&&s.ownerDocument.defaultView!=null?s.ownerDocument.defaultView:window;for(var t=ec(s.document);t instanceof s.HTMLIFrameElement;){try{var a=typeof t.contentWindow.location.href=="string"}catch{a=!1}if(a)s=t.contentWindow;else break;t=ec(s.document)}return t}function xd(s){var t=s&&s.nodeName&&s.nodeName.toLowerCase();return t&&(t==="input"&&(s.type==="text"||s.type==="search"||s.type==="tel"||s.type==="url"||s.type==="password")||t==="textarea"||s.contentEditable==="true")}var Cb=tl&&"documentMode"in document&&11>=document.documentMode,Vn=null,hd=null,Kr=null,fd=!1;function zx(s,t,a){var r=a.window===a?a.document:a.nodeType===9?a:a.ownerDocument;fd||Vn==null||Vn!==ec(r)||(r=Vn,"selectionStart"in r&&xd(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Kr&&Vr(Kr,r)||(Kr=r,r=Yc(hd,"onSelect"),0>=j,o-=j,Fa=1<<32-vs(t)+o|a<os?(Cs=$e,$e=null):Cs=$e.sibling;var As=ne(K,$e,se[os],he);if(As===null){$e===null&&($e=Cs);break}s&&$e&&As.alternate===null&&t(K,$e),I=d(As,I,os),Ms===null?qe=As:Ms.sibling=As,Ms=As,$e=Cs}if(os===se.length)return a(K,$e),ks&&ll(K,os),qe;if($e===null){for(;osos?(Cs=$e,$e=null):Cs=$e.sibling;var Jl=ne(K,$e,As.value,he);if(Jl===null){$e===null&&($e=Cs);break}s&&$e&&Jl.alternate===null&&t(K,$e),I=d(Jl,I,os),Ms===null?qe=Jl:Ms.sibling=Jl,Ms=Jl,$e=Cs}if(As.done)return a(K,$e),ks&&ll(K,os),qe;if($e===null){for(;!As.done;os++,As=se.next())As=fe(K,As.value,he),As!==null&&(I=d(As,I,os),Ms===null?qe=As:Ms.sibling=As,Ms=As);return ks&&ll(K,os),qe}for($e=r($e);!As.done;os++,As=se.next())As=oe($e,K,os,As.value,he),As!==null&&(s&&As.alternate!==null&&$e.delete(As.key===null?os:As.key),I=d(As,I,os),Ms===null?qe=As:Ms.sibling=As,Ms=As);return s&&$e.forEach(function(Vy){return t(K,Vy)}),ks&&ll(K,os),qe}function Fs(K,I,se,he){if(typeof se=="object"&&se!==null&&se.type===L&&se.key===null&&(se=se.props.children),typeof se=="object"&&se!==null){switch(se.$$typeof){case w:e:{for(var qe=se.key;I!==null;){if(I.key===qe){if(qe=se.type,qe===L){if(I.tag===7){a(K,I.sibling),he=o(I,se.props.children),he.return=K,K=he;break e}}else if(I.elementType===qe||typeof qe=="object"&&qe!==null&&qe.$$typeof===Z&&pn(qe)===I.type){a(K,I.sibling),he=o(I,se.props),Wr(he,se),he.return=K,K=he;break e}a(K,I);break}else t(K,I);I=I.sibling}se.type===L?(he=un(se.props.children,K.mode,he,se.key),he.return=K,K=he):(he=mc(se.type,se.key,se.props,null,K.mode,he),Wr(he,se),he.return=K,K=he)}return j(K);case b:e:{for(qe=se.key;I!==null;){if(I.key===qe)if(I.tag===4&&I.stateNode.containerInfo===se.containerInfo&&I.stateNode.implementation===se.implementation){a(K,I.sibling),he=o(I,se.children||[]),he.return=K,K=he;break e}else{a(K,I);break}else t(K,I);I=I.sibling}he=yd(se,K.mode,he),he.return=K,K=he}return j(K);case Z:return se=pn(se),Fs(K,I,se,he)}if(je(se))return Ae(K,I,se,he);if(be(se)){if(qe=be(se),typeof qe!="function")throw Error(c(150));return se=qe.call(se),Ke(K,I,se,he)}if(typeof se.then=="function")return Fs(K,I,vc(se),he);if(se.$$typeof===O)return Fs(K,I,fc(K,se),he);Nc(K,se)}return typeof se=="string"&&se!==""||typeof se=="number"||typeof se=="bigint"?(se=""+se,I!==null&&I.tag===6?(a(K,I.sibling),he=o(I,se),he.return=K,K=he):(a(K,I),he=bd(se,K.mode,he),he.return=K,K=he),j(K)):a(K,I)}return function(K,I,se,he){try{Zr=0;var qe=Fs(K,I,se,he);return ar=null,qe}catch($e){if($e===tr||$e===gc)throw $e;var Ms=ha(29,$e,null,K.mode);return Ms.lanes=he,Ms.return=K,Ms}finally{}}}var jn=sh(!0),th=sh(!1),Dl=!1;function Od(s){s.updateQueue={baseState:s.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Rd(s,t){s=s.updateQueue,t.updateQueue===s&&(t.updateQueue={baseState:s.baseState,firstBaseUpdate:s.firstBaseUpdate,lastBaseUpdate:s.lastBaseUpdate,shared:s.shared,callbacks:null})}function Ol(s){return{lane:s,tag:0,payload:null,callback:null,next:null}}function Rl(s,t,a){var r=s.updateQueue;if(r===null)return null;if(r=r.shared,(Ds&2)!==0){var o=r.pending;return o===null?t.next=t:(t.next=o.next,o.next=t),r.pending=t,t=uc(s),$x(s,null,a),t}return dc(s,r,t,a),uc(s)}function ei(s,t,a){if(t=t.updateQueue,t!==null&&(t=t.shared,(a&4194048)!==0)){var r=t.lanes;r&=s.pendingLanes,a|=r,t.lanes=a,_s(s,a)}}function Ld(s,t){var a=s.updateQueue,r=s.alternate;if(r!==null&&(r=r.updateQueue,a===r)){var o=null,d=null;if(a=a.firstBaseUpdate,a!==null){do{var j={lane:a.lane,tag:a.tag,payload:a.payload,callback:null,next:null};d===null?o=d=j:d=d.next=j,a=a.next}while(a!==null);d===null?o=d=t:d=d.next=t}else o=d=t;a={baseState:r.baseState,firstBaseUpdate:o,lastBaseUpdate:d,shared:r.shared,callbacks:r.callbacks},s.updateQueue=a;return}s=a.lastBaseUpdate,s===null?a.firstBaseUpdate=t:s.next=t,a.lastBaseUpdate=t}var Ud=!1;function si(){if(Ud){var s=sr;if(s!==null)throw s}}function ti(s,t,a,r){Ud=!1;var o=s.updateQueue;Dl=!1;var d=o.firstBaseUpdate,j=o.lastBaseUpdate,_=o.shared.pending;if(_!==null){o.shared.pending=null;var R=_,te=R.next;R.next=null,j===null?d=te:j.next=te,j=R;var xe=s.alternate;xe!==null&&(xe=xe.updateQueue,_=xe.lastBaseUpdate,_!==j&&(_===null?xe.firstBaseUpdate=te:_.next=te,xe.lastBaseUpdate=R))}if(d!==null){var fe=o.baseState;j=0,xe=te=R=null,_=d;do{var ne=_.lane&-536870913,oe=ne!==_.lane;if(oe?(Ss&ne)===ne:(r&ne)===ne){ne!==0&&ne===er&&(Ud=!0),xe!==null&&(xe=xe.next={lane:0,tag:_.tag,payload:_.payload,callback:null,next:null});e:{var Ae=s,Ke=_;ne=t;var Fs=a;switch(Ke.tag){case 1:if(Ae=Ke.payload,typeof Ae=="function"){fe=Ae.call(Fs,fe,ne);break e}fe=Ae;break e;case 3:Ae.flags=Ae.flags&-65537|128;case 0:if(Ae=Ke.payload,ne=typeof Ae=="function"?Ae.call(Fs,fe,ne):Ae,ne==null)break e;fe=N({},fe,ne);break e;case 2:Dl=!0}}ne=_.callback,ne!==null&&(s.flags|=64,oe&&(s.flags|=8192),oe=o.callbacks,oe===null?o.callbacks=[ne]:oe.push(ne))}else oe={lane:ne,tag:_.tag,payload:_.payload,callback:_.callback,next:null},xe===null?(te=xe=oe,R=fe):xe=xe.next=oe,j|=ne;if(_=_.next,_===null){if(_=o.shared.pending,_===null)break;oe=_,_=oe.next,oe.next=null,o.lastBaseUpdate=oe,o.shared.pending=null}}while(!0);xe===null&&(R=fe),o.baseState=R,o.firstBaseUpdate=te,o.lastBaseUpdate=xe,d===null&&(o.shared.lanes=0),Hl|=j,s.lanes=j,s.memoizedState=fe}}function ah(s,t){if(typeof s!="function")throw Error(c(191,s));s.call(t)}function lh(s,t){var a=s.callbacks;if(a!==null)for(s.callbacks=null,s=0;sd?d:8;var j=A.T,_={};A.T=_,tu(s,!1,t,a);try{var R=o(),te=A.S;if(te!==null&&te(_,R),R!==null&&typeof R=="object"&&typeof R.then=="function"){var xe=Rb(R,r);ni(s,t,xe,va(s))}else ni(s,t,r,va(s))}catch(fe){ni(s,t,{then:function(){},status:"rejected",reason:fe},va())}finally{Y.p=d,j!==null&&_.types!==null&&(j.types=_.types),A.T=j}}function Ib(){}function eu(s,t,a,r){if(s.tag!==5)throw Error(c(476));var o=Lh(s).queue;Rh(s,o,t,H,a===null?Ib:function(){return Uh(s),a(r)})}function Lh(s){var t=s.memoizedState;if(t!==null)return t;t={memoizedState:H,baseState:H,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:cl,lastRenderedState:H},next:null};var a={};return t.next={memoizedState:a,baseState:a,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:cl,lastRenderedState:a},next:null},s.memoizedState=t,s=s.alternate,s!==null&&(s.memoizedState=t),t}function Uh(s){var t=Lh(s);t.next===null&&(t=s.alternate.memoizedState),ni(s,t.next.queue,{},va())}function su(){return Pt(yi)}function Bh(){return wt().memoizedState}function $h(){return wt().memoizedState}function Pb(s){for(var t=s.return;t!==null;){switch(t.tag){case 24:case 3:var a=va();s=Ol(a);var r=Rl(t,s,a);r!==null&&(ra(r,t,a),ei(r,t,a)),t={cache:Md()},s.payload=t;return}t=t.return}}function Gb(s,t,a){var r=va();a={lane:r,revertLane:0,gesture:null,action:a,hasEagerState:!1,eagerState:null,next:null},Mc(s)?Ih(t,a):(a=vd(s,t,a,r),a!==null&&(ra(a,s,r),Ph(a,t,r)))}function Hh(s,t,a){var r=va();ni(s,t,a,r)}function ni(s,t,a,r){var o={lane:r,revertLane:0,gesture:null,action:a,hasEagerState:!1,eagerState:null,next:null};if(Mc(s))Ih(t,o);else{var d=s.alternate;if(s.lanes===0&&(d===null||d.lanes===0)&&(d=t.lastRenderedReducer,d!==null))try{var j=t.lastRenderedState,_=d(j,a);if(o.hasEagerState=!0,o.eagerState=_,xa(_,j))return dc(s,t,o,0),Ks===null&&oc(),!1}catch{}finally{}if(a=vd(s,t,o,r),a!==null)return ra(a,s,r),Ph(a,t,r),!0}return!1}function tu(s,t,a,r){if(r={lane:2,revertLane:Ou(),gesture:null,action:r,hasEagerState:!1,eagerState:null,next:null},Mc(s)){if(t)throw Error(c(479))}else t=vd(s,a,r,2),t!==null&&ra(t,s,2)}function Mc(s){var t=s.alternate;return s===is||t!==null&&t===is}function Ih(s,t){nr=wc=!0;var a=s.pending;a===null?t.next=t:(t.next=a.next,a.next=t),s.pending=t}function Ph(s,t,a){if((a&4194048)!==0){var r=t.lanes;r&=s.pendingLanes,a|=r,t.lanes=a,_s(s,a)}}var ri={readContext:Pt,use:Cc,useCallback:xt,useContext:xt,useEffect:xt,useImperativeHandle:xt,useLayoutEffect:xt,useInsertionEffect:xt,useMemo:xt,useReducer:xt,useRef:xt,useState:xt,useDebugValue:xt,useDeferredValue:xt,useTransition:xt,useSyncExternalStore:xt,useId:xt,useHostTransitionStatus:xt,useFormState:xt,useActionState:xt,useOptimistic:xt,useMemoCache:xt,useCacheRefresh:xt};ri.useEffectEvent=xt;var Gh={readContext:Pt,use:Cc,useCallback:function(s,t){return Kt().memoizedState=[s,t===void 0?null:t],s},useContext:Pt,useEffect:Ch,useImperativeHandle:function(s,t,a){a=a!=null?a.concat([s]):null,Tc(4194308,4,Mh.bind(null,t,s),a)},useLayoutEffect:function(s,t){return Tc(4194308,4,s,t)},useInsertionEffect:function(s,t){Tc(4,2,s,t)},useMemo:function(s,t){var a=Kt();t=t===void 0?null:t;var r=s();if(vn){We(!0);try{s()}finally{We(!1)}}return a.memoizedState=[r,t],r},useReducer:function(s,t,a){var r=Kt();if(a!==void 0){var o=a(t);if(vn){We(!0);try{a(t)}finally{We(!1)}}}else o=t;return r.memoizedState=r.baseState=o,s={pending:null,lanes:0,dispatch:null,lastRenderedReducer:s,lastRenderedState:o},r.queue=s,s=s.dispatch=Gb.bind(null,is,s),[r.memoizedState,s]},useRef:function(s){var t=Kt();return s={current:s},t.memoizedState=s},useState:function(s){s=Yd(s);var t=s.queue,a=Hh.bind(null,is,t);return t.dispatch=a,[s.memoizedState,a]},useDebugValue:Zd,useDeferredValue:function(s,t){var a=Kt();return Wd(a,s,t)},useTransition:function(){var s=Yd(!1);return s=Rh.bind(null,is,s.queue,!0,!1),Kt().memoizedState=s,[!1,s]},useSyncExternalStore:function(s,t,a){var r=is,o=Kt();if(ks){if(a===void 0)throw Error(c(407));a=a()}else{if(a=t(),Ks===null)throw Error(c(349));(Ss&127)!==0||dh(r,t,a)}o.memoizedState=a;var d={value:a,getSnapshot:t};return o.queue=d,Ch(mh.bind(null,r,d,s),[s]),r.flags|=2048,ir(9,{destroy:void 0},uh.bind(null,r,d,a,t),null),a},useId:function(){var s=Kt(),t=Ks.identifierPrefix;if(ks){var a=Va,r=Fa;a=(r&~(1<<32-vs(r)-1)).toString(32)+a,t="_"+t+"R_"+a,a=_c++,0<\/script>",d=d.removeChild(d.firstChild);break;case"select":d=typeof r.is=="string"?j.createElement("select",{is:r.is}):j.createElement("select"),r.multiple?d.multiple=!0:r.size&&(d.size=r.size);break;default:d=typeof r.is=="string"?j.createElement(o,{is:r.is}):j.createElement(o)}}d[Ht]=t,d[ea]=r;e:for(j=t.child;j!==null;){if(j.tag===5||j.tag===6)d.appendChild(j.stateNode);else if(j.tag!==4&&j.tag!==27&&j.child!==null){j.child.return=j,j=j.child;continue}if(j===t)break e;for(;j.sibling===null;){if(j.return===null||j.return===t)break e;j=j.return}j.sibling.return=j.return,j=j.sibling}t.stateNode=d;e:switch(qt(d,o,r),o){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}r&&dl(t)}}return at(t),pu(t,t.type,s===null?null:s.memoizedProps,t.pendingProps,a),null;case 6:if(s&&t.stateNode!=null)s.memoizedProps!==r&&dl(t);else{if(typeof r!="string"&&t.stateNode===null)throw Error(c(166));if(s=W.current,Zn(t)){if(s=t.stateNode,a=t.memoizedProps,r=null,o=It,o!==null)switch(o.tag){case 27:case 5:r=o.memoizedProps}s[Ht]=t,s=!!(s.nodeValue===a||r!==null&&r.suppressHydrationWarning===!0||op(s.nodeValue,a)),s||Al(t,!0)}else s=Jc(s).createTextNode(r),s[Ht]=t,t.stateNode=s}return at(t),null;case 31:if(a=t.memoizedState,s===null||s.memoizedState!==null){if(r=Zn(t),a!==null){if(s===null){if(!r)throw Error(c(318));if(s=t.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(c(557));s[Ht]=t}else mn(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;at(t),s=!1}else a=Cd(),s!==null&&s.memoizedState!==null&&(s.memoizedState.hydrationErrors=a),s=!0;if(!s)return t.flags&256?(pa(t),t):(pa(t),null);if((t.flags&128)!==0)throw Error(c(558))}return at(t),null;case 13:if(r=t.memoizedState,s===null||s.memoizedState!==null&&s.memoizedState.dehydrated!==null){if(o=Zn(t),r!==null&&r.dehydrated!==null){if(s===null){if(!o)throw Error(c(318));if(o=t.memoizedState,o=o!==null?o.dehydrated:null,!o)throw Error(c(317));o[Ht]=t}else mn(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;at(t),o=!1}else o=Cd(),s!==null&&s.memoizedState!==null&&(s.memoizedState.hydrationErrors=o),o=!0;if(!o)return t.flags&256?(pa(t),t):(pa(t),null)}return pa(t),(t.flags&128)!==0?(t.lanes=a,t):(a=r!==null,s=s!==null&&s.memoizedState!==null,a&&(r=t.child,o=null,r.alternate!==null&&r.alternate.memoizedState!==null&&r.alternate.memoizedState.cachePool!==null&&(o=r.alternate.memoizedState.cachePool.pool),d=null,r.memoizedState!==null&&r.memoizedState.cachePool!==null&&(d=r.memoizedState.cachePool.pool),d!==o&&(r.flags|=2048)),a!==s&&a&&(t.child.flags|=8192),Rc(t,t.updateQueue),at(t),null);case 4:return J(),s===null&&Bu(t.stateNode.containerInfo),at(t),null;case 10:return rl(t.type),at(t),null;case 19:if(Ne(yt),r=t.memoizedState,r===null)return at(t),null;if(o=(t.flags&128)!==0,d=r.rendering,d===null)if(o)ci(r,!1);else{if(ht!==0||s!==null&&(s.flags&128)!==0)for(s=t.child;s!==null;){if(d=yc(s),d!==null){for(t.flags|=128,ci(r,!1),s=d.updateQueue,t.updateQueue=s,Rc(t,s),t.subtreeFlags=0,s=a,a=t.child;a!==null;)Hx(a,s),a=a.sibling;return Se(yt,yt.current&1|2),ks&&ll(t,r.treeForkCount),t.child}s=s.sibling}r.tail!==null&&Ps()>Hc&&(t.flags|=128,o=!0,ci(r,!1),t.lanes=4194304)}else{if(!o)if(s=yc(d),s!==null){if(t.flags|=128,o=!0,s=s.updateQueue,t.updateQueue=s,Rc(t,s),ci(r,!0),r.tail===null&&r.tailMode==="hidden"&&!d.alternate&&!ks)return at(t),null}else 2*Ps()-r.renderingStartTime>Hc&&a!==536870912&&(t.flags|=128,o=!0,ci(r,!1),t.lanes=4194304);r.isBackwards?(d.sibling=t.child,t.child=d):(s=r.last,s!==null?s.sibling=d:t.child=d,r.last=d)}return r.tail!==null?(s=r.tail,r.rendering=s,r.tail=s.sibling,r.renderingStartTime=Ps(),s.sibling=null,a=yt.current,Se(yt,o?a&1|2:a&1),ks&&ll(t,r.treeForkCount),s):(at(t),null);case 22:case 23:return pa(t),$d(),r=t.memoizedState!==null,s!==null?s.memoizedState!==null!==r&&(t.flags|=8192):r&&(t.flags|=8192),r?(a&536870912)!==0&&(t.flags&128)===0&&(at(t),t.subtreeFlags&6&&(t.flags|=8192)):at(t),a=t.updateQueue,a!==null&&Rc(t,a.retryQueue),a=null,s!==null&&s.memoizedState!==null&&s.memoizedState.cachePool!==null&&(a=s.memoizedState.cachePool.pool),r=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(r=t.memoizedState.cachePool.pool),r!==a&&(t.flags|=2048),s!==null&&Ne(fn),null;case 24:return a=null,s!==null&&(a=s.memoizedState.cache),t.memoizedState.cache!==a&&(t.flags|=2048),rl(Ct),at(t),null;case 25:return null;case 30:return null}throw Error(c(156,t.tag))}function Qb(s,t){switch(_d(t),t.tag){case 1:return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 3:return rl(Ct),J(),s=t.flags,(s&65536)!==0&&(s&128)===0?(t.flags=s&-65537|128,t):null;case 26:case 27:case 5:return De(t),null;case 31:if(t.memoizedState!==null){if(pa(t),t.alternate===null)throw Error(c(340));mn()}return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 13:if(pa(t),s=t.memoizedState,s!==null&&s.dehydrated!==null){if(t.alternate===null)throw Error(c(340));mn()}return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 19:return Ne(yt),null;case 4:return J(),null;case 10:return rl(t.type),null;case 22:case 23:return pa(t),$d(),s!==null&&Ne(fn),s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 24:return rl(Ct),null;case 25:return null;default:return null}}function hf(s,t){switch(_d(t),t.tag){case 3:rl(Ct),J();break;case 26:case 27:case 5:De(t);break;case 4:J();break;case 31:t.memoizedState!==null&&pa(t);break;case 13:pa(t);break;case 19:Ne(yt);break;case 10:rl(t.type);break;case 22:case 23:pa(t),$d(),s!==null&&Ne(fn);break;case 24:rl(Ct)}}function oi(s,t){try{var a=t.updateQueue,r=a!==null?a.lastEffect:null;if(r!==null){var o=r.next;a=o;do{if((a.tag&s)===s){r=void 0;var d=a.create,j=a.inst;r=d(),j.destroy=r}a=a.next}while(a!==o)}}catch(_){Hs(t,t.return,_)}}function Bl(s,t,a){try{var r=t.updateQueue,o=r!==null?r.lastEffect:null;if(o!==null){var d=o.next;r=d;do{if((r.tag&s)===s){var j=r.inst,_=j.destroy;if(_!==void 0){j.destroy=void 0,o=t;var R=a,te=_;try{te()}catch(xe){Hs(o,R,xe)}}}r=r.next}while(r!==d)}}catch(xe){Hs(t,t.return,xe)}}function ff(s){var t=s.updateQueue;if(t!==null){var a=s.stateNode;try{lh(t,a)}catch(r){Hs(s,s.return,r)}}}function pf(s,t,a){a.props=Nn(s.type,s.memoizedProps),a.state=s.memoizedState;try{a.componentWillUnmount()}catch(r){Hs(s,t,r)}}function di(s,t){try{var a=s.ref;if(a!==null){switch(s.tag){case 26:case 27:case 5:var r=s.stateNode;break;case 30:r=s.stateNode;break;default:r=s.stateNode}typeof a=="function"?s.refCleanup=a(r):a.current=r}}catch(o){Hs(s,t,o)}}function Ka(s,t){var a=s.ref,r=s.refCleanup;if(a!==null)if(typeof r=="function")try{r()}catch(o){Hs(s,t,o)}finally{s.refCleanup=null,s=s.alternate,s!=null&&(s.refCleanup=null)}else if(typeof a=="function")try{a(null)}catch(o){Hs(s,t,o)}else a.current=null}function gf(s){var t=s.type,a=s.memoizedProps,r=s.stateNode;try{e:switch(t){case"button":case"input":case"select":case"textarea":a.autoFocus&&r.focus();break e;case"img":a.src?r.src=a.src:a.srcSet&&(r.srcset=a.srcSet)}}catch(o){Hs(s,s.return,o)}}function gu(s,t,a){try{var r=s.stateNode;py(r,s.type,a,t),r[ea]=t}catch(o){Hs(s,s.return,o)}}function jf(s){return s.tag===5||s.tag===3||s.tag===26||s.tag===27&&Fl(s.type)||s.tag===4}function ju(s){e:for(;;){for(;s.sibling===null;){if(s.return===null||jf(s.return))return null;s=s.return}for(s.sibling.return=s.return,s=s.sibling;s.tag!==5&&s.tag!==6&&s.tag!==18;){if(s.tag===27&&Fl(s.type)||s.flags&2||s.child===null||s.tag===4)continue e;s.child.return=s,s=s.child}if(!(s.flags&2))return s.stateNode}}function vu(s,t,a){var r=s.tag;if(r===5||r===6)s=s.stateNode,t?(a.nodeType===9?a.body:a.nodeName==="HTML"?a.ownerDocument.body:a).insertBefore(s,t):(t=a.nodeType===9?a.body:a.nodeName==="HTML"?a.ownerDocument.body:a,t.appendChild(s),a=a._reactRootContainer,a!=null||t.onclick!==null||(t.onclick=sl));else if(r!==4&&(r===27&&Fl(s.type)&&(a=s.stateNode,t=null),s=s.child,s!==null))for(vu(s,t,a),s=s.sibling;s!==null;)vu(s,t,a),s=s.sibling}function Lc(s,t,a){var r=s.tag;if(r===5||r===6)s=s.stateNode,t?a.insertBefore(s,t):a.appendChild(s);else if(r!==4&&(r===27&&Fl(s.type)&&(a=s.stateNode),s=s.child,s!==null))for(Lc(s,t,a),s=s.sibling;s!==null;)Lc(s,t,a),s=s.sibling}function vf(s){var t=s.stateNode,a=s.memoizedProps;try{for(var r=s.type,o=t.attributes;o.length;)t.removeAttributeNode(o[0]);qt(t,r,a),t[Ht]=s,t[ea]=a}catch(d){Hs(s,s.return,d)}}var ul=!1,Et=!1,Nu=!1,Nf=typeof WeakSet=="function"?WeakSet:Set,Ut=null;function Yb(s,t){if(s=s.containerInfo,Iu=ao,s=Ax(s),xd(s)){if("selectionStart"in s)var a={start:s.selectionStart,end:s.selectionEnd};else e:{a=(a=s.ownerDocument)&&a.defaultView||window;var r=a.getSelection&&a.getSelection();if(r&&r.rangeCount!==0){a=r.anchorNode;var o=r.anchorOffset,d=r.focusNode;r=r.focusOffset;try{a.nodeType,d.nodeType}catch{a=null;break e}var j=0,_=-1,R=-1,te=0,xe=0,fe=s,ne=null;s:for(;;){for(var oe;fe!==a||o!==0&&fe.nodeType!==3||(_=j+o),fe!==d||r!==0&&fe.nodeType!==3||(R=j+r),fe.nodeType===3&&(j+=fe.nodeValue.length),(oe=fe.firstChild)!==null;)ne=fe,fe=oe;for(;;){if(fe===s)break s;if(ne===a&&++te===o&&(_=j),ne===d&&++xe===r&&(R=j),(oe=fe.nextSibling)!==null)break;fe=ne,ne=fe.parentNode}fe=oe}a=_===-1||R===-1?null:{start:_,end:R}}else a=null}a=a||{start:0,end:0}}else a=null;for(Pu={focusedElem:s,selectionRange:a},ao=!1,Ut=t;Ut!==null;)if(t=Ut,s=t.child,(t.subtreeFlags&1028)!==0&&s!==null)s.return=t,Ut=s;else for(;Ut!==null;){switch(t=Ut,d=t.alternate,s=t.flags,t.tag){case 0:if((s&4)!==0&&(s=t.updateQueue,s=s!==null?s.events:null,s!==null))for(a=0;a title"))),qt(d,r,a),d[Ht]=s,Lt(d),r=d;break e;case"link":var j=Cp("link","href",o).get(r+(a.href||""));if(j){for(var _=0;_Fs&&(j=Fs,Fs=Ke,Ke=j);var K=Ex(_,Ke),I=Ex(_,Fs);if(K&&I&&(oe.rangeCount!==1||oe.anchorNode!==K.node||oe.anchorOffset!==K.offset||oe.focusNode!==I.node||oe.focusOffset!==I.offset)){var se=fe.createRange();se.setStart(K.node,K.offset),oe.removeAllRanges(),Ke>Fs?(oe.addRange(se),oe.extend(I.node,I.offset)):(se.setEnd(I.node,I.offset),oe.addRange(se))}}}}for(fe=[],oe=_;oe=oe.parentNode;)oe.nodeType===1&&fe.push({element:oe,left:oe.scrollLeft,top:oe.scrollTop});for(typeof _.focus=="function"&&_.focus(),_=0;_a?32:a,A.T=null,a=ku,ku=null;var d=Pl,j=pl;if(At=0,mr=Pl=null,pl=0,(Ds&6)!==0)throw Error(c(331));var _=Ds;if(Ds|=4,Af(d.current),Tf(d,d.current,j,a),Ds=_,pi(0,!1),es&&typeof es.onPostCommitFiberRoot=="function")try{es.onPostCommitFiberRoot(zs,d)}catch{}return!0}finally{Y.p=o,A.T=r,Yf(s,t)}}function Xf(s,t,a){t=Sa(a,t),t=ru(s.stateNode,t,2),s=Rl(s,t,2),s!==null&&(q(s,2),Qa(s))}function Hs(s,t,a){if(s.tag===3)Xf(s,s,a);else for(;t!==null;){if(t.tag===3){Xf(t,s,a);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Il===null||!Il.has(r))){s=Sa(a,s),a=Xh(2),r=Rl(t,a,2),r!==null&&(Zh(a,r,t,s),q(r,2),Qa(r));break}}t=t.return}}function Au(s,t,a){var r=s.pingCache;if(r===null){r=s.pingCache=new Zb;var o=new Set;r.set(t,o)}else o=r.get(t),o===void 0&&(o=new Set,r.set(t,o));o.has(a)||(wu=!0,o.add(a),s=ay.bind(null,s,t,a),t.then(s,s))}function ay(s,t,a){var r=s.pingCache;r!==null&&r.delete(t),s.pingedLanes|=s.suspendedLanes&a,s.warmLanes&=~a,Ks===s&&(Ss&a)===a&&(ht===4||ht===3&&(Ss&62914560)===Ss&&300>Ps()-$c?(Ds&2)===0&&xr(s,0):_u|=a,ur===Ss&&(ur=0)),Qa(s)}function Zf(s,t){t===0&&(t=X()),s=dn(s,t),s!==null&&(q(s,t),Qa(s))}function ly(s){var t=s.memoizedState,a=0;t!==null&&(a=t.retryLane),Zf(s,a)}function ny(s,t){var a=0;switch(s.tag){case 31:case 13:var r=s.stateNode,o=s.memoizedState;o!==null&&(a=o.retryLane);break;case 19:r=s.stateNode;break;case 22:r=s.stateNode._retryCache;break;default:throw Error(c(314))}r!==null&&r.delete(t),Zf(s,a)}function ry(s,t){return Ze(s,t)}var Vc=null,fr=null,zu=!1,Kc=!1,Du=!1,ql=0;function Qa(s){s!==fr&&s.next===null&&(fr===null?Vc=fr=s:fr=fr.next=s),Kc=!0,zu||(zu=!0,cy())}function pi(s,t){if(!Du&&Kc){Du=!0;do for(var a=!1,r=Vc;r!==null;){if(s!==0){var o=r.pendingLanes;if(o===0)var d=0;else{var j=r.suspendedLanes,_=r.pingedLanes;d=(1<<31-vs(42|s)+1)-1,d&=o&~(j&~_),d=d&201326741?d&201326741|1:d?d|2:0}d!==0&&(a=!0,tp(r,d))}else d=Ss,d=Ga(r,r===Ks?d:0,r.cancelPendingCommit!==null||r.timeoutHandle!==-1),(d&3)===0||qa(r,d)||(a=!0,tp(r,d));r=r.next}while(a);Du=!1}}function iy(){Wf()}function Wf(){Kc=zu=!1;var s=0;ql!==0&&jy()&&(s=ql);for(var t=Ps(),a=null,r=Vc;r!==null;){var o=r.next,d=ep(r,t);d===0?(r.next=null,a===null?Vc=o:a.next=o,o===null&&(fr=a)):(a=r,(s!==0||(d&3)!==0)&&(Kc=!0)),r=o}At!==0&&At!==5||pi(s),ql!==0&&(ql=0)}function ep(s,t){for(var a=s.suspendedLanes,r=s.pingedLanes,o=s.expirationTimes,d=s.pendingLanes&-62914561;0_)break;var xe=R.transferSize,fe=R.initiatorType;xe&&dp(fe)&&(R=R.responseEnd,j+=xe*(R<_?1:(_-te)/(R-te)))}if(--r,t+=8*(d+j)/(o.duration/1e3),s++,10"u"?null:document;function yp(s,t,a){var r=pr;if(r&&typeof t=="string"&&t){var o=wa(t);o='link[rel="'+s+'"][href="'+o+'"]',typeof a=="string"&&(o+='[crossorigin="'+a+'"]'),bp.has(o)||(bp.add(o),s={rel:s,crossOrigin:a,href:t},r.querySelector(o)===null&&(t=r.createElement("link"),qt(t,"link",s),Lt(t),r.head.appendChild(t)))}}function ky(s){gl.D(s),yp("dns-prefetch",s,null)}function Ty(s,t){gl.C(s,t),yp("preconnect",s,t)}function Ey(s,t,a){gl.L(s,t,a);var r=pr;if(r&&s&&t){var o='link[rel="preload"][as="'+wa(t)+'"]';t==="image"&&a&&a.imageSrcSet?(o+='[imagesrcset="'+wa(a.imageSrcSet)+'"]',typeof a.imageSizes=="string"&&(o+='[imagesizes="'+wa(a.imageSizes)+'"]')):o+='[href="'+wa(s)+'"]';var d=o;switch(t){case"style":d=gr(s);break;case"script":d=jr(s)}Aa.has(d)||(s=N({rel:"preload",href:t==="image"&&a&&a.imageSrcSet?void 0:s,as:t},a),Aa.set(d,s),r.querySelector(o)!==null||t==="style"&&r.querySelector(Ni(d))||t==="script"&&r.querySelector(bi(d))||(t=r.createElement("link"),qt(t,"link",s),Lt(t),r.head.appendChild(t)))}}function My(s,t){gl.m(s,t);var a=pr;if(a&&s){var r=t&&typeof t.as=="string"?t.as:"script",o='link[rel="modulepreload"][as="'+wa(r)+'"][href="'+wa(s)+'"]',d=o;switch(r){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":d=jr(s)}if(!Aa.has(d)&&(s=N({rel:"modulepreload",href:s},t),Aa.set(d,s),a.querySelector(o)===null)){switch(r){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(a.querySelector(bi(d)))return}r=a.createElement("link"),qt(r,"link",s),Lt(r),a.head.appendChild(r)}}}function Ay(s,t,a){gl.S(s,t,a);var r=pr;if(r&&s){var o=$n(r).hoistableStyles,d=gr(s);t=t||"default";var j=o.get(d);if(!j){var _={loading:0,preload:null};if(j=r.querySelector(Ni(d)))_.loading=5;else{s=N({rel:"stylesheet",href:s,"data-precedence":t},a),(a=Aa.get(d))&&Yu(s,a);var R=j=r.createElement("link");Lt(R),qt(R,"link",s),R._p=new Promise(function(te,xe){R.onload=te,R.onerror=xe}),R.addEventListener("load",function(){_.loading|=1}),R.addEventListener("error",function(){_.loading|=2}),_.loading|=4,Zc(j,t,r)}j={type:"stylesheet",instance:j,count:1,state:_},o.set(d,j)}}}function zy(s,t){gl.X(s,t);var a=pr;if(a&&s){var r=$n(a).hoistableScripts,o=jr(s),d=r.get(o);d||(d=a.querySelector(bi(o)),d||(s=N({src:s,async:!0},t),(t=Aa.get(o))&&Ju(s,t),d=a.createElement("script"),Lt(d),qt(d,"link",s),a.head.appendChild(d)),d={type:"script",instance:d,count:1,state:null},r.set(o,d))}}function Dy(s,t){gl.M(s,t);var a=pr;if(a&&s){var r=$n(a).hoistableScripts,o=jr(s),d=r.get(o);d||(d=a.querySelector(bi(o)),d||(s=N({src:s,async:!0,type:"module"},t),(t=Aa.get(o))&&Ju(s,t),d=a.createElement("script"),Lt(d),qt(d,"link",s),a.head.appendChild(d)),d={type:"script",instance:d,count:1,state:null},r.set(o,d))}}function wp(s,t,a,r){var o=(o=W.current)?Xc(o):null;if(!o)throw Error(c(446));switch(s){case"meta":case"title":return null;case"style":return typeof a.precedence=="string"&&typeof a.href=="string"?(t=gr(a.href),a=$n(o).hoistableStyles,r=a.get(t),r||(r={type:"style",instance:null,count:0,state:null},a.set(t,r)),r):{type:"void",instance:null,count:0,state:null};case"link":if(a.rel==="stylesheet"&&typeof a.href=="string"&&typeof a.precedence=="string"){s=gr(a.href);var d=$n(o).hoistableStyles,j=d.get(s);if(j||(o=o.ownerDocument||o,j={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},d.set(s,j),(d=o.querySelector(Ni(s)))&&!d._p&&(j.instance=d,j.state.loading=5),Aa.has(s)||(a={rel:"preload",as:"style",href:a.href,crossOrigin:a.crossOrigin,integrity:a.integrity,media:a.media,hrefLang:a.hrefLang,referrerPolicy:a.referrerPolicy},Aa.set(s,a),d||Oy(o,s,a,j.state))),t&&r===null)throw Error(c(528,""));return j}if(t&&r!==null)throw Error(c(529,""));return null;case"script":return t=a.async,a=a.src,typeof a=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=jr(a),a=$n(o).hoistableScripts,r=a.get(t),r||(r={type:"script",instance:null,count:0,state:null},a.set(t,r)),r):{type:"void",instance:null,count:0,state:null};default:throw Error(c(444,s))}}function gr(s){return'href="'+wa(s)+'"'}function Ni(s){return'link[rel="stylesheet"]['+s+"]"}function _p(s){return N({},s,{"data-precedence":s.precedence,precedence:null})}function Oy(s,t,a,r){s.querySelector('link[rel="preload"][as="style"]['+t+"]")?r.loading=1:(t=s.createElement("link"),r.preload=t,t.addEventListener("load",function(){return r.loading|=1}),t.addEventListener("error",function(){return r.loading|=2}),qt(t,"link",a),Lt(t),s.head.appendChild(t))}function jr(s){return'[src="'+wa(s)+'"]'}function bi(s){return"script[async]"+s}function Sp(s,t,a){if(t.count++,t.instance===null)switch(t.type){case"style":var r=s.querySelector('style[data-href~="'+wa(a.href)+'"]');if(r)return t.instance=r,Lt(r),r;var o=N({},a,{"data-href":a.href,"data-precedence":a.precedence,href:null,precedence:null});return r=(s.ownerDocument||s).createElement("style"),Lt(r),qt(r,"style",o),Zc(r,a.precedence,s),t.instance=r;case"stylesheet":o=gr(a.href);var d=s.querySelector(Ni(o));if(d)return t.state.loading|=4,t.instance=d,Lt(d),d;r=_p(a),(o=Aa.get(o))&&Yu(r,o),d=(s.ownerDocument||s).createElement("link"),Lt(d);var j=d;return j._p=new Promise(function(_,R){j.onload=_,j.onerror=R}),qt(d,"link",r),t.state.loading|=4,Zc(d,a.precedence,s),t.instance=d;case"script":return d=jr(a.src),(o=s.querySelector(bi(d)))?(t.instance=o,Lt(o),o):(r=a,(o=Aa.get(d))&&(r=N({},a),Ju(r,o)),s=s.ownerDocument||s,o=s.createElement("script"),Lt(o),qt(o,"link",r),s.head.appendChild(o),t.instance=o);case"void":return null;default:throw Error(c(443,t.type))}else t.type==="stylesheet"&&(t.state.loading&4)===0&&(r=t.instance,t.state.loading|=4,Zc(r,a.precedence,s));return t.instance}function Zc(s,t,a){for(var r=a.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),o=r.length?r[r.length-1]:null,d=o,j=0;j title"):null)}function Ry(s,t,a){if(a===1||t.itemProp!=null)return!1;switch(s){case"meta":case"title":return!0;case"style":if(typeof t.precedence!="string"||typeof t.href!="string"||t.href==="")break;return!0;case"link":if(typeof t.rel!="string"||typeof t.href!="string"||t.href===""||t.onLoad||t.onError)break;switch(t.rel){case"stylesheet":return s=t.disabled,typeof t.precedence=="string"&&s==null;default:return!0}case"script":if(t.async&&typeof t.async!="function"&&typeof t.async!="symbol"&&!t.onLoad&&!t.onError&&t.src&&typeof t.src=="string")return!0}return!1}function Tp(s){return!(s.type==="stylesheet"&&(s.state.loading&3)===0)}function Ly(s,t,a,r){if(a.type==="stylesheet"&&(typeof r.media!="string"||matchMedia(r.media).matches!==!1)&&(a.state.loading&4)===0){if(a.instance===null){var o=gr(r.href),d=t.querySelector(Ni(o));if(d){t=d._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(s.count++,s=eo.bind(s),t.then(s,s)),a.state.loading|=4,a.instance=d,Lt(d);return}d=t.ownerDocument||t,r=_p(r),(o=Aa.get(o))&&Yu(r,o),d=d.createElement("link"),Lt(d);var j=d;j._p=new Promise(function(_,R){j.onload=_,j.onerror=R}),qt(d,"link",r),a.instance=d}s.stylesheets===null&&(s.stylesheets=new Map),s.stylesheets.set(a,t),(t=a.state.preload)&&(a.state.loading&3)===0&&(s.count++,a=eo.bind(s),t.addEventListener("load",a),t.addEventListener("error",a))}}var Xu=0;function Uy(s,t){return s.stylesheets&&s.count===0&&to(s,s.stylesheets),0Xu?50:800)+t);return s.unsuspend=a,function(){s.unsuspend=null,clearTimeout(r),clearTimeout(o)}}:null}function eo(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)to(this,this.stylesheets);else if(this.unsuspend){var s=this.unsuspend;this.unsuspend=null,s()}}}var so=null;function to(s,t){s.stylesheets=null,s.unsuspend!==null&&(s.count++,so=new Map,t.forEach(By,s),so=null,eo.call(s))}function By(s,t){if(!(t.state.loading&4)){var a=so.get(s);if(a)var r=a.get(null);else{a=new Map,so.set(s,a);for(var o=s.querySelectorAll("link[data-precedence],style[data-precedence]"),d=0;d"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(l)}catch(n){console.error(n)}}return l(),cm.exports=_1(),cm.exports}var C1=S1();function B(...l){return a0(l0(l))}const ze=m.forwardRef(({className:l,...n},i)=>e.jsx("div",{ref:i,className:B("rounded-xl border bg-card text-card-foreground shadow",l),...n}));ze.displayName="Card";const ts=m.forwardRef(({className:l,...n},i)=>e.jsx("div",{ref:i,className:B("flex flex-col space-y-1.5 p-6",l),...n}));ts.displayName="CardHeader";const ls=m.forwardRef(({className:l,...n},i)=>e.jsx("div",{ref:i,className:B("font-semibold leading-none tracking-tight",l),...n}));ls.displayName="CardTitle";const Vs=m.forwardRef(({className:l,...n},i)=>e.jsx("div",{ref:i,className:B("text-sm text-muted-foreground",l),...n}));Vs.displayName="CardDescription";const Ye=m.forwardRef(({className:l,...n},i)=>e.jsx("div",{ref:i,className:B("p-6 pt-0",l),...n}));Ye.displayName="CardContent";const Lo=m.forwardRef(({className:l,...n},i)=>e.jsx("div",{ref:i,className:B("flex items-center p-6 pt-0",l),...n}));Lo.displayName="CardFooter";const da=r0,Zt=m.forwardRef(({className:l,...n},i)=>e.jsx(Ng,{ref:i,className:B("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",l),...n}));Zt.displayName=Ng.displayName;const Xe=m.forwardRef(({className:l,...n},i)=>e.jsx(bg,{ref:i,className:B("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all duration-300 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",l),...n}));Xe.displayName=bg.displayName;const ys=m.forwardRef(({className:l,...n},i)=>e.jsx(yg,{ref:i,className:B("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 data-[state=active]:animate-in data-[state=active]:fade-in data-[state=active]:duration-300",l),...n}));ys.displayName=yg.displayName;const Je=m.forwardRef(({className:l,children:n,viewportRef:i,...c},u)=>e.jsxs(wg,{ref:u,className:B("relative overflow-hidden",l),...c,children:[e.jsx(i0,{ref:i,className:"h-full w-full rounded-[inherit]",children:n}),e.jsx(Cm,{}),e.jsx(Cm,{orientation:"horizontal"}),e.jsx(c0,{})]}));Je.displayName=wg.displayName;const Cm=m.forwardRef(({className:l,orientation:n="vertical",...i},c)=>e.jsx(_g,{ref:c,orientation:n,className:B("flex touch-none select-none transition-colors",n==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",n==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",l),...i,children:e.jsx(o0,{className:"relative flex-1 rounded-full bg-border"})}));Cm.displayName=_g.displayName;function Qs({className:l,...n}){return e.jsx("div",{className:B("animate-pulse rounded-md bg-primary/10",l),...n})}const Mn=m.forwardRef(({className:l,value:n,...i},c)=>e.jsx(Sg,{ref:c,className:B("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",l),...i,children:e.jsx(d0,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(n||0)}%)`}})}));Mn.displayName=Sg.displayName;async function we(l,n){const c=n?.body instanceof FormData?{...n?.headers}:{"Content-Type":"application/json",...n?.headers},u={...n,credentials:"include",headers:c},x=await fetch(l,u);if(x.status===401)throw window.location.href="/auth",new Error("认证失败,请重新登录");return x}function Os(){return{"Content-Type":"application/json"}}async function k1(){try{await fetch("/api/webui/auth/logout",{method:"POST",credentials:"include"})}catch(l){console.error("登出请求失败:",l)}window.location.href="/auth"}async function Hi(){try{return(await(await fetch("/api/webui/auth/check",{method:"GET",credentials:"include"})).json()).authenticated===!0}catch{return!1}}const T1={light:"",dark:".dark"},Uj=m.createContext(null);function Bj(){const l=m.useContext(Uj);if(!l)throw new Error("useChart must be used within a ");return l}const yr=m.forwardRef(({id:l,className:n,children:i,config:c,...u},x)=>{const h=m.useId(),f=`chart-${l||h.replace(/:/g,"")}`;return e.jsx(Uj.Provider,{value:{config:c},children:e.jsxs("div",{"data-chart":f,ref:x,className:B("flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",n),...u,children:[e.jsx(E1,{id:f,config:c}),e.jsx(P0,{children:i})]})})});yr.displayName="Chart";const E1=({id:l,config:n})=>{const i=Object.entries(n).filter(([,c])=>c.theme||c.color);return i.length?e.jsx("style",{dangerouslySetInnerHTML:{__html:Object.entries(T1).map(([c,u])=>` ${u} [data-chart=${l}] { ${i.map(([x,h])=>{const f=h.theme?.[c]||h.color;return f?` --color-${x}: ${f};`:null}).join(` `)} } `).join(` `)}}):null},Ti=G0,wr=m.forwardRef(({active:l,payload:n,className:i,indicator:c="dot",hideLabel:u=!1,hideIndicator:x=!1,label:h,labelFormatter:f,labelClassName:p,formatter:g,color:v,nameKey:N,labelKey:y},w)=>{const{config:b}=Bj(),L=m.useMemo(()=>{if(u||!n?.length)return null;const[T]=n,F=`${y||T?.dataKey||T?.name||"value"}`,O=km(b,T,F),S=!y&&typeof h=="string"?b[h]?.label||h:O?.label;return f?e.jsx("div",{className:B("font-medium",p),children:f(S,n)}):S?e.jsx("div",{className:B("font-medium",p),children:S}):null},[h,f,n,u,p,b,y]);if(!l||!n?.length)return null;const D=n.length===1&&c!=="dot";return e.jsxs("div",{ref:w,className:B("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",i),children:[D?null:L,e.jsx("div",{className:"grid gap-1.5",children:n.filter(T=>T.type!=="none").map((T,F)=>{const O=`${N||T.name||T.dataKey||"value"}`,S=km(b,T,O),C=v||T.payload.fill||T.color;return e.jsx("div",{className:B("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",c==="dot"&&"items-center"),children:g&&T?.value!==void 0&&T.name?g(T.value,T.name,T,F,T.payload):e.jsxs(e.Fragment,{children:[S?.icon?e.jsx(S.icon,{}):!x&&e.jsx("div",{className:B("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":c==="dot","w-1":c==="line","w-0 border-[1.5px] border-dashed bg-transparent":c==="dashed","my-0.5":D&&c==="dashed"}),style:{"--color-bg":C,"--color-border":C}}),e.jsxs("div",{className:B("flex flex-1 justify-between leading-none",D?"items-end":"items-center"),children:[e.jsxs("div",{className:"grid gap-1.5",children:[D?L:null,e.jsx("span",{className:"text-muted-foreground",children:S?.label||T.name})]}),T.value&&e.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:T.value.toLocaleString()})]})]})},T.dataKey)})})]})});wr.displayName="ChartTooltip";const M1=q0,$j=m.forwardRef(({className:l,hideIcon:n=!1,payload:i,verticalAlign:c="bottom",nameKey:u},x)=>{const{config:h}=Bj();return i?.length?e.jsx("div",{ref:x,className:B("flex items-center justify-center gap-4",c==="top"?"pb-3":"pt-3",l),children:i.filter(f=>f.type!=="none").map(f=>{const p=`${u||f.dataKey||"value"}`,g=km(h,f,p);return e.jsxs("div",{className:B("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[g?.icon&&!n?e.jsx(g.icon,{}):e.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:f.color}}),g?.label]},f.value)})}):null});$j.displayName="ChartLegend";function km(l,n,i){if(typeof n!="object"||n===null)return;const c="payload"in n&&typeof n.payload=="object"&&n.payload!==null?n.payload:void 0;let u=i;return i in n&&typeof n[i]=="string"?u=n[i]:c&&i in c&&typeof c[i]=="string"&&(u=c[i]),u in l?l[u]:l[i]}const Mr=Ar("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),k=m.forwardRef(({className:l,variant:n,size:i,asChild:c=!1,...u},x)=>{const h=c?J0:"button";return e.jsx(h,{className:B(Mr({variant:n,size:i,className:l})),ref:x,...u})});k.displayName="Button";const A1=Ar("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Te({className:l,variant:n,...i}){return e.jsx("div",{className:B(A1({variant:n}),l),...i})}async function z1(){const l=await we("/api/webui/system/restart",{method:"POST",headers:Os()});if(!l.ok){const n=await l.json();throw new Error(n.detail||"重启失败")}return await l.json()}async function D1(){const l=await we("/api/webui/system/status",{method:"GET",headers:Os()});if(!l.ok){const n=await l.json();throw new Error(n.detail||"获取状态失败")}return await l.json()}const Nr={INITIAL_DELAY:3e3,CHECK_INTERVAL:2e3,CHECK_TIMEOUT:3e3,MAX_ATTEMPTS:60,PROGRESS_INTERVAL:200,SUCCESS_REDIRECT_DELAY:1500},Hj=m.createContext(null);function Dn({children:l,onRestartComplete:n,onRestartFailed:i,healthCheckUrl:c="/api/webui/system/status",maxAttempts:u=Nr.MAX_ATTEMPTS}){const[x,h]=m.useState({status:"idle",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:u}),[f,p]=m.useState({}),g=m.useCallback(()=>{f.progress&&clearInterval(f.progress),f.elapsed&&clearInterval(f.elapsed),f.check&&clearTimeout(f.check),p({})},[f]),v=m.useCallback(()=>{g(),h({status:"idle",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:u})},[g,u]),N=m.useCallback(async()=>{try{const D=new AbortController,T=setTimeout(()=>D.abort(),Nr.CHECK_TIMEOUT),F=await fetch(c,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"include",signal:D.signal});return clearTimeout(T),F.ok}catch{return!1}},[c]),y=m.useCallback(()=>{let D=0;const T=async()=>{if(D++,h(O=>({...O,status:"checking",checkAttempts:D})),await N())g(),h(O=>({...O,status:"success",progress:100})),setTimeout(()=>{n?.(),window.location.href="/auth"},Nr.SUCCESS_REDIRECT_DELAY);else if(D>=u){g();const O=`健康检查超时 (${D}/${u})`;h(S=>({...S,status:"failed",error:O})),i?.(O)}else{const O=setTimeout(T,Nr.CHECK_INTERVAL);p(S=>({...S,check:O}))}};T()},[N,g,u,n,i]),w=m.useCallback(()=>{h(D=>({...D,status:"checking",checkAttempts:0,error:void 0})),y()},[y]),b=m.useCallback(async D=>{const{delay:T=0,skipApiCall:F=!1}=D??{};if(x.status!=="idle"&&x.status!=="failed")return;if(g(),h({status:"requesting",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:u}),T>0&&await new Promise(C=>setTimeout(C,T)),F)h(C=>({...C,status:"restarting"}));else try{h(C=>({...C,status:"restarting"})),await Promise.race([z1(),new Promise(C=>setTimeout(C,5e3))])}catch{}const O=setInterval(()=>{h(C=>({...C,progress:C.progress>=90?C.progress:C.progress+1}))},Nr.PROGRESS_INTERVAL),S=setInterval(()=>{h(C=>({...C,elapsedTime:C.elapsedTime+1}))},1e3);p({progress:O,elapsed:S}),setTimeout(()=>{y()},Nr.INITIAL_DELAY)},[x.status,g,u,y]),L={state:x,isRestarting:x.status!=="idle",triggerRestart:b,resetState:v,retryHealthCheck:w};return e.jsx(Hj.Provider,{value:L,children:l})}function sn(){const l=m.useContext(Hj);if(!l)throw new Error("useRestart must be used within a RestartProvider");return l}function O1(){try{return sn()}catch{return null}}const R1=(l,n,i,c,u)=>({idle:{icon:null,title:"",description:"",tip:""},requesting:{icon:e.jsx(Js,{className:"h-16 w-16 text-primary animate-spin"}),title:c??"准备重启",description:u??"正在发送重启请求...",tip:"🔄 正在准备重启麦麦..."},restarting:{icon:e.jsx(Js,{className:"h-16 w-16 text-primary animate-spin"}),title:c??"正在重启麦麦",description:u??"请稍候,麦麦正在重启中...",tip:"🔄 配置已保存,正在重启主程序..."},checking:{icon:e.jsx(Js,{className:"h-16 w-16 text-primary animate-spin"}),title:"检查服务状态",description:`等待服务恢复... (${n}/${i})`,tip:"⏳ 正在等待服务恢复,请勿关闭页面..."},success:{icon:e.jsx(oa,{className:"h-16 w-16 text-green-500"}),title:"重启成功",description:"正在跳转到登录页面...",tip:"✅ 配置已生效,服务运行正常"},failed:{icon:e.jsx(Dt,{className:"h-16 w-16 text-destructive"}),title:"重启超时",description:"服务未能在预期时间内恢复",tip:"⚠️ 如果长时间无响应,请尝试手动重启"}})[l];function On({visible:l,onComplete:n,onFailed:i,title:c,description:u,showAnimation:x=!0,className:h}){const f=O1();return(f?f.isRestarting:l)?f?e.jsx(Ij,{state:f.state,onRetry:f.retryHealthCheck,onComplete:n,onFailed:i,title:c,description:u,showAnimation:x,className:h}):e.jsx(L1,{onComplete:n,onFailed:i,title:c,description:u,showAnimation:x,className:h}):null}function Ij({state:l,onRetry:n,onComplete:i,onFailed:c,title:u,description:x,showAnimation:h,className:f}){const{status:p,progress:g,elapsedTime:v,checkAttempts:N,maxAttempts:y}=l;m.useEffect(()=>{p==="success"&&i?i():p==="failed"&&c&&c()},[p,i,c]);const w=R1(p,N,y,u,x),b=L=>{const D=Math.floor(L/60),T=L%60;return`${D}:${T.toString().padStart(2,"0")}`};return e.jsxs("div",{className:B("fixed inset-0 bg-background/95 backdrop-blur-sm z-50 flex items-center justify-center",f),children:[h&&e.jsx(U1,{}),e.jsxs("div",{className:"max-w-md w-full mx-4 space-y-8 relative z-10",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsxs("div",{className:"relative",children:[w.icon,(p==="restarting"||p==="checking")&&e.jsx("div",{className:"absolute inset-0 rounded-full bg-primary/20 animate-ping"})]}),e.jsx("h2",{className:"text-2xl font-bold",children:w.title}),e.jsx("p",{className:"text-muted-foreground text-center",children:w.description})]}),p!=="failed"&&p!=="idle"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Mn,{value:g,className:"h-2"}),e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:[g,"%"]}),e.jsxs("span",{children:["已用时: ",b(v)]})]})]}),e.jsx("div",{className:"bg-muted/50 rounded-lg p-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:w.tip})}),p==="failed"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(k,{onClick:()=>window.location.reload(),variant:"default",className:"flex-1",children:[e.jsx(zt,{className:"mr-2 h-4 w-4"}),"刷新页面"]}),e.jsxs(k,{onClick:n,variant:"secondary",className:"flex-1",children:[e.jsx(Ui,{className:"mr-2 h-4 w-4"}),"重试检测"]})]})]})]})}function L1({onComplete:l,onFailed:n,title:i,description:c,showAnimation:u,className:x}){const[h,f]=m.useState({status:"restarting",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:60}),p=m.useCallback(()=>{let g=0;const v=60,N=async()=>{g++,f(y=>({...y,status:"checking",checkAttempts:g}));try{if((await fetch("/api/webui/system/status",{method:"GET",signal:AbortSignal.timeout(3e3)})).ok){f(w=>({...w,status:"success",progress:100})),setTimeout(()=>{l?.(),window.location.href="/auth"},1500);return}}catch{}g>=v?(f(y=>({...y,status:"failed"})),n?.()):setTimeout(N,2e3)};N()},[l,n]);return m.useEffect(()=>{const g=setInterval(()=>{f(y=>({...y,progress:y.progress>=90?y.progress:y.progress+1}))},200),v=setInterval(()=>{f(y=>({...y,elapsedTime:y.elapsedTime+1}))},1e3),N=setTimeout(()=>{p()},3e3);return()=>{clearInterval(g),clearInterval(v),clearTimeout(N)}},[p]),e.jsx(Ij,{state:h,onRetry:p,onComplete:l,onFailed:n,title:i,description:c,showAnimation:u,className:x})}function U1(){return e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsxs("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[600px] h-[600px]",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border border-primary/10 animate-[ping_3s_ease-in-out_infinite]"}),e.jsx("div",{className:"absolute inset-8 rounded-full border border-primary/10 animate-[ping_3s_ease-in-out_infinite_0.5s]"}),e.jsx("div",{className:"absolute inset-16 rounded-full border border-primary/10 animate-[ping_3s_ease-in-out_infinite_1s]"})]}),e.jsx("div",{className:"absolute top-1/4 left-1/4 w-2 h-2 bg-primary/20 rounded-full animate-bounce"}),e.jsx("div",{className:"absolute top-3/4 right-1/4 w-3 h-3 bg-primary/15 rounded-full animate-bounce delay-150"}),e.jsx("div",{className:"absolute top-1/2 right-1/3 w-2 h-2 bg-primary/20 rounded-full animate-bounce delay-300"})]})}function B1(){return e.jsx(Dn,{children:e.jsx(H1,{})})}const $1=l=>{const n=[];for(let i=0;i{try{w(!0);const U=await n0.get("https://v1.hitokoto.cn/?c=a&c=b&c=c&c=d&c=h&c=i&c=k");N({hitokoto:U.data.hitokoto,from:U.data.from||U.data.from_who||"未知"})}catch(U){console.error("获取一言失败:",U),N({hitokoto:"人生就像一盒巧克力,你永远不知道下一颗是什么味道。",from:"阿甘正传"})}finally{w(!1)}},[]),O=m.useCallback(async()=>{try{const U=await we("/api/webui/system/status");if(U.ok){const $=await U.json();L($)}else L(null)}catch(U){console.error("获取机器人状态失败:",U),L(null)}},[]),S=async()=>{await D()},C=m.useCallback(async()=>{try{const U=await we(`/api/webui/statistics/dashboard?hours=${h}`);if(U.ok){const $=await U.json();n($)}c(!1),x(100)}catch(U){console.error("Failed to fetch dashboard data:",U),c(!1),x(100)}},[h]);if(m.useEffect(()=>{if(!i)return;x(0);const U=setTimeout(()=>x(15),200),$=setTimeout(()=>x(30),800),_e=setTimeout(()=>x(45),2e3),Ne=setTimeout(()=>x(60),4e3),Se=setTimeout(()=>x(75),6500),V=setTimeout(()=>x(85),9e3),ye=setTimeout(()=>x(92),11e3);return()=>{clearTimeout(U),clearTimeout($),clearTimeout(_e),clearTimeout(Ne),clearTimeout(Se),clearTimeout(V),clearTimeout(ye)}},[i]),m.useEffect(()=>{C(),F(),O()},[C,F,O]),m.useEffect(()=>{if(!p)return;const U=setInterval(()=>{C(),O()},3e4);return()=>clearInterval(U)},[p,C,O]),i||!l)return e.jsx("div",{className:"flex items-center justify-center h-[calc(100vh-200px)]",children:e.jsxs("div",{className:"text-center space-y-6 w-full max-w-md px-4",children:[e.jsx(zt,{className:"h-12 w-12 animate-spin mx-auto text-primary"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-lg font-medium",children:"加载统计数据中..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"正在获取麦麦运行数据"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Mn,{value:u,className:"h-2"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[u,"%"]})]})]})});const{summary:P,model_stats:M=[],hourly_data:Z=[],daily_data:G=[],recent_activity:ce=[]}=l,de=P??{total_requests:0,total_cost:0,total_tokens:0,online_time:0,total_messages:0,total_replies:0,avg_response_time:0,cost_per_hour:0,tokens_per_hour:0},be=U=>{const $=Math.floor(U/3600),_e=Math.floor(U%3600/60);return`${$}小时${_e}分钟`},me=U=>{const $=U.toLocaleString("zh-CN");return U>=1e9?{display:`${(U/1e9).toFixed(2)}B`,exact:$,needsExact:!0}:U>=1e6?{display:`${(U/1e6).toFixed(2)}M`,exact:$,needsExact:!0}:U>=1e4?{display:`${(U/1e3).toFixed(1)}K`,exact:$,needsExact:!0}:U>=1e3?{display:`${(U/1e3).toFixed(2)}K`,exact:$,needsExact:!0}:{display:$,exact:$,needsExact:!1}},pe=U=>{const $=`¥${U.toLocaleString("zh-CN",{minimumFractionDigits:2,maximumFractionDigits:2})}`;return U>=1e6?{display:`¥${(U/1e6).toFixed(2)}M`,exact:$,needsExact:!0}:U>=1e4?{display:`¥${(U/1e3).toFixed(1)}K`,exact:$,needsExact:!0}:U>=1e3?{display:`¥${(U/1e3).toFixed(2)}K`,exact:$,needsExact:!0}:{display:$,exact:$,needsExact:!1}},je=U=>new Date(U).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),A=$1(M.length),Y=M.map((U,$)=>({name:U.model_name,value:U.request_count,fill:A[$]})),H={requests:{label:"请求数",color:"hsl(var(--chart-1))"},cost:{label:"花费(¥)",color:"hsl(var(--chart-2))"},tokens:{label:"Tokens",color:"hsl(var(--chart-3))"}};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"实时监控面板"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"麦麦运行状态和统计数据一览"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(da,{value:h.toString(),onValueChange:U=>f(Number(U)),children:e.jsxs(Zt,{className:"grid grid-cols-3 w-full sm:w-auto",children:[e.jsx(Xe,{value:"24",children:"24小时"}),e.jsx(Xe,{value:"168",children:"7天"}),e.jsx(Xe,{value:"720",children:"30天"})]})}),e.jsxs(k,{variant:p?"default":"outline",size:"sm",onClick:()=>g(!p),className:"gap-2",children:[e.jsx(zt,{className:`h-4 w-4 ${p?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"自动刷新"})]}),e.jsx(k,{variant:"outline",size:"sm",onClick:C,children:e.jsx(zt,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 rounded-lg border border-dashed border-muted-foreground/30 bg-muted/20",children:[y?e.jsx(Qs,{className:"h-5 flex-1"}):v?e.jsxs("p",{className:"flex-1 text-sm text-muted-foreground italic truncate",children:['"',v.hitokoto,'" —— ',v.from]}):null,e.jsx(k,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:F,disabled:y,children:e.jsx(zt,{className:`h-3.5 w-3.5 ${y?"animate-spin":""}`})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-3",children:[e.jsxs(ze,{className:"lg:col-span-1",children:[e.jsx(ts,{className:"pb-3",children:e.jsxs(ls,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Vi,{className:"h-4 w-4"}),"麦麦状态"]})}),e.jsx(Ye,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:b?.running?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-3 w-3 rounded-full bg-green-500 animate-pulse"}),e.jsxs(Te,{variant:"outline",className:"text-green-600 border-green-300 bg-green-50",children:[e.jsx(oa,{className:"h-3 w-3 mr-1"}),"运行中"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-3 w-3 rounded-full bg-red-500"}),e.jsxs(Te,{variant:"outline",className:"text-red-600 border-red-300 bg-red-50",children:[e.jsx(Dt,{className:"h-3 w-3 mr-1"}),"已停止"]})]})}),b&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("span",{children:["v",b.version]}),e.jsx("span",{className:"mx-2",children:"|"}),e.jsxs("span",{children:["运行 ",be(b.uptime)]})]})]})})]}),e.jsxs(ze,{children:[e.jsx(ts,{className:"pb-3",children:e.jsxs(ls,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Sn,{className:"h-4 w-4"}),"快速操作"]})}),e.jsx(Ye,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(k,{variant:"outline",size:"sm",onClick:S,disabled:T,className:"gap-2",children:[e.jsx(Ui,{className:`h-4 w-4 ${T?"animate-spin":""}`}),T?"重启中...":"重启麦麦"]}),e.jsx(k,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(br,{to:"/logs",children:[e.jsx(Ha,{className:"h-4 w-4"}),"查看日志"]})}),e.jsx(k,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(br,{to:"/plugins",children:[e.jsx(vw,{className:"h-4 w-4"}),"插件管理"]})}),e.jsx(k,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(br,{to:"/settings",children:[e.jsx(zn,{className:"h-4 w-4"}),"系统设置"]})})]})})]}),e.jsxs(ze,{children:[e.jsxs(ts,{className:"pb-3",children:[e.jsxs(ls,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Nw,{className:"h-4 w-4"}),"反馈问卷"]}),e.jsx(Vs,{className:"text-xs",children:"帮助我们改进产品体验"})]}),e.jsx(Ye,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(k,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(br,{to:"/survey/webui-feedback",children:[e.jsx(Ha,{className:"h-4 w-4"}),"WebUI 反馈"]})}),e.jsx(k,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(br,{to:"/survey/maibot-feedback",children:[e.jsx(Wl,{className:"h-4 w-4"}),"麦麦反馈"]})})]})})]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 xs:grid-cols-2 lg:grid-cols-4",children:[e.jsxs(ze,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ls,{className:"text-sm font-medium",children:"总请求数"}),e.jsx(bw,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ye,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[me(de.total_requests).display,me(de.total_requests).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",me(de.total_requests).exact,")"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["最近",h<48?h+"小时":Math.floor(h/24)+"天"]})]})]}),e.jsxs(ze,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ls,{className:"text-sm font-medium",children:"总花费"}),e.jsx(yw,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ye,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[pe(de.total_cost).display,pe(de.total_cost).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",pe(de.total_cost).exact,")"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:de.cost_per_hour>0?`¥${de.cost_per_hour.toFixed(2)}/小时`:"暂无数据"})]})]}),e.jsxs(ze,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ls,{className:"text-sm font-medium",children:"Token消耗"}),e.jsx(Cr,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ye,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[me(de.total_tokens).display,me(de.total_tokens).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",me(de.total_tokens).exact,")"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:de.tokens_per_hour>0?`${me(de.tokens_per_hour).display}/小时`:"暂无数据"})]})]}),e.jsxs(ze,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ls,{className:"text-sm font-medium",children:"平均响应"}),e.jsx(Sn,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ye,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[de.avg_response_time.toFixed(2),"s"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"API平均耗时"})]})]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 sm:grid-cols-3",children:[e.jsxs(ze,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ls,{className:"text-sm font-medium",children:"在线时长"}),e.jsx(Nl,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Ye,{children:e.jsxs("div",{className:"text-xl font-bold",children:[be(de.online_time),e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",de.online_time.toLocaleString(),"秒)"]})]})})]}),e.jsxs(ze,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ls,{className:"text-sm font-medium",children:"消息处理"}),e.jsx(Wl,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ye,{children:[e.jsxs("div",{className:"text-xl font-bold",children:[me(de.total_messages).display,me(de.total_messages).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",me(de.total_messages).exact,")"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["回复 ",me(de.total_replies).display,me(de.total_replies).needsExact&&e.jsxs("span",{children:["(",me(de.total_replies).exact,")"]})," 条"]})]})]}),e.jsxs(ze,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ls,{className:"text-sm font-medium",children:"成本效率"}),e.jsx(ww,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ye,{children:[e.jsx("div",{className:"text-xl font-bold",children:de.total_messages>0?`¥${(de.total_cost/de.total_messages*100).toFixed(2)}`:"¥0.00"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"每100条消息"})]})]})]}),e.jsxs(da,{defaultValue:"trends",className:"space-y-4",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2 sm:grid-cols-4",children:[e.jsx(Xe,{value:"trends",children:"趋势"}),e.jsx(Xe,{value:"models",children:"模型"}),e.jsx(Xe,{value:"activity",children:"活动"}),e.jsx(Xe,{value:"daily",children:"日统计"})]}),e.jsxs(ys,{value:"trends",className:"space-y-4",children:[e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"请求趋势"}),e.jsxs(Vs,{children:["最近",h,"小时的请求量变化"]})]}),e.jsx(Ye,{children:e.jsx(yr,{config:H,className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(F0,{data:Z,children:[e.jsx(uo,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(mo,{dataKey:"timestamp",tickFormatter:U=>je(U),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ci,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ti,{content:e.jsx(wr,{labelFormatter:U=>je(U)})}),e.jsx(V0,{type:"monotone",dataKey:"requests",stroke:"var(--color-requests)",strokeWidth:2})]})})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"花费趋势"}),e.jsx(Vs,{children:"API调用成本变化"})]}),e.jsx(Ye,{children:e.jsx(yr,{config:H,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(nm,{data:Z,children:[e.jsx(uo,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(mo,{dataKey:"timestamp",tickFormatter:U=>je(U),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ci,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ti,{content:e.jsx(wr,{labelFormatter:U=>je(U)})}),e.jsx(xo,{dataKey:"cost",fill:"var(--color-cost)"})]})})})]}),e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"Token消耗"}),e.jsx(Vs,{children:"Token使用量变化"})]}),e.jsx(Ye,{children:e.jsx(yr,{config:H,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(nm,{data:Z,children:[e.jsx(uo,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(mo,{dataKey:"timestamp",tickFormatter:U=>je(U),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ci,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ti,{content:e.jsx(wr,{labelFormatter:U=>je(U)})}),e.jsx(xo,{dataKey:"tokens",fill:"var(--color-tokens)"})]})})})]})]})]}),e.jsx(ys,{value:"models",className:"space-y-4",children:e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"模型请求分布"}),e.jsxs(Vs,{children:["各模型使用占比 (共 ",M.length," 个模型)"]})]}),e.jsx(Ye,{children:e.jsx(yr,{config:Object.fromEntries(M.map((U,$)=>[U.model_name,{label:U.model_name,color:A[$]}])),className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(K0,{children:[e.jsx(Ti,{content:e.jsx(wr,{})}),e.jsx(Q0,{data:Y,cx:"50%",cy:"50%",labelLine:!1,label:({name:U,percent:$})=>$&&$<.05?"":`${U} ${$?($*100).toFixed(0):0}%`,outerRadius:100,dataKey:"value",children:Y.map((U,$)=>e.jsx(Y0,{fill:U.fill},`cell-${$}`))})]})})})]}),e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"模型详细统计"}),e.jsx(Vs,{children:"请求数、花费和性能"})]}),e.jsx(Ye,{children:e.jsx(Je,{className:"h-[300px] sm:h-[400px]",children:e.jsx("div",{className:"space-y-3",children:M.map((U,$)=>e.jsxs("div",{className:"p-4 rounded-lg border bg-card hover:bg-accent/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h4",{className:"font-semibold text-sm truncate flex-1 min-w-0",children:U.model_name}),e.jsx("div",{className:"w-3 h-3 rounded-full ml-2 flex-shrink-0",style:{backgroundColor:`hsl(var(--chart-${$%5+1}))`}})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"请求数:"}),e.jsx("span",{className:"ml-1 font-medium",children:U.request_count.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1 font-medium",children:["¥",U.total_cost.toFixed(2)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Tokens:"}),e.jsxs("span",{className:"ml-1 font-medium",children:[(U.total_tokens/1e3).toFixed(1),"K"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"平均耗时:"}),e.jsxs("span",{className:"ml-1 font-medium",children:[U.avg_response_time.toFixed(2),"s"]})]})]})]},$))})})})]})]})}),e.jsx(ys,{value:"activity",children:e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"最近活动"}),e.jsx(Vs,{children:"最新的API调用记录"})]}),e.jsx(Ye,{children:e.jsx(Je,{className:"h-[400px] sm:h-[500px]",children:e.jsx("div",{className:"space-y-2",children:ce.map((U,$)=>e.jsxs("div",{className:"p-3 sm:p-4 rounded-lg border bg-card hover:bg-accent/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:U.model}),e.jsx("div",{className:"text-xs text-muted-foreground",children:U.request_type})]}),e.jsx("div",{className:"text-xs text-muted-foreground flex-shrink-0",children:je(U.timestamp)})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Tokens:"}),e.jsx("span",{className:"ml-1",children:U.tokens})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1",children:["¥",U.cost.toFixed(4)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"耗时:"}),e.jsxs("span",{className:"ml-1",children:[U.time_cost.toFixed(2),"s"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"状态:"}),e.jsx("span",{className:`ml-1 ${U.status==="success"?"text-green-600":"text-red-600"}`,children:U.status})]})]})]},$))})})})]})}),e.jsx(ys,{value:"daily",children:e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"每日统计"}),e.jsx(Vs,{children:"最近7天的数据汇总"})]}),e.jsx(Ye,{children:e.jsx(yr,{config:{requests:{label:"请求数",color:"hsl(var(--chart-1))"},cost:{label:"花费(¥)",color:"hsl(var(--chart-2))"}},className:"h-[400px] sm:h-[500px] w-full aspect-auto",children:e.jsxs(nm,{data:G,children:[e.jsx(uo,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(mo,{dataKey:"timestamp",tickFormatter:U=>{const $=new Date(U);return`${$.getMonth()+1}/${$.getDate()}`},stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ci,{yAxisId:"left",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ci,{yAxisId:"right",orientation:"right",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ti,{content:e.jsx(wr,{labelFormatter:U=>new Date(U).toLocaleDateString("zh-CN")})}),e.jsx(M1,{content:e.jsx($j,{})}),e.jsx(xo,{yAxisId:"left",dataKey:"requests",fill:"var(--color-requests)"}),e.jsx(xo,{yAxisId:"right",dataKey:"cost",fill:"var(--color-cost)"})]})})})]})})]}),e.jsx(On,{})]})})}const I1={theme:"system",setTheme:()=>null},Pj=m.createContext(I1),Lm=()=>{const l=m.useContext(Pj);if(l===void 0)throw new Error("useTheme must be used within a ThemeProvider");return l},P1=(l,n,i)=>{const c=document.documentElement.classList.contains("no-animations");if(!document.startViewTransition||c){n(l);return}const u=i.clientX,x=i.clientY,h=Math.hypot(Math.max(u,innerWidth-u),Math.max(x,innerHeight-x));document.startViewTransition(()=>{n(l)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${u}px ${x}px)`,`circle(${h}px at ${u}px ${x}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},Gj=m.createContext(void 0),qj=()=>{const l=m.useContext(Gj);if(l===void 0)throw new Error("useAnimation must be used within an AnimationProvider");return l},Pe=m.forwardRef(({className:l,...n},i)=>e.jsx(Cg,{className:B("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",l),...n,ref:i,children:e.jsx(u0,{className:B("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));Pe.displayName=Cg.displayName;const G1=Ar("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),E=m.forwardRef(({className:l,...n},i)=>e.jsx(Gg,{ref:i,className:B(G1(),l),...n}));E.displayName=Gg.displayName;const re=m.forwardRef(({className:l,type:n,...i},c)=>e.jsx("input",{type:n,className:B("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",l),ref:c,...i}));re.displayName="Input";const q1=5,F1=5e3;let um=0;function V1(){return um=(um+1)%Number.MAX_SAFE_INTEGER,um.toString()}const mm=new Map,Xp=l=>{if(mm.has(l))return;const n=setTimeout(()=>{mm.delete(l),Ri({type:"REMOVE_TOAST",toastId:l})},F1);mm.set(l,n)},K1=(l,n)=>{switch(n.type){case"ADD_TOAST":return{...l,toasts:[n.toast,...l.toasts].slice(0,q1)};case"UPDATE_TOAST":return{...l,toasts:l.toasts.map(i=>i.id===n.toast.id?{...i,...n.toast}:i)};case"DISMISS_TOAST":{const{toastId:i}=n;return i?Xp(i):l.toasts.forEach(c=>{Xp(c.id)}),{...l,toasts:l.toasts.map(c=>c.id===i||i===void 0?{...c,open:!1}:c)}}case"REMOVE_TOAST":return n.toastId===void 0?{...l,toasts:[]}:{...l,toasts:l.toasts.filter(i=>i.id!==n.toastId)}}},bo=[];let yo={toasts:[]};function Ri(l){yo=K1(yo,l),bo.forEach(n=>{n(yo)})}function Ft({...l}){const n=V1(),i=u=>Ri({type:"UPDATE_TOAST",toast:{...u,id:n}}),c=()=>Ri({type:"DISMISS_TOAST",toastId:n});return Ri({type:"ADD_TOAST",toast:{...l,id:n,open:!0,onOpenChange:u=>{u||c()}}}),{id:n,dismiss:c,update:i}}function et(){const[l,n]=m.useState(yo);return m.useEffect(()=>(bo.push(n),()=>{const i=bo.indexOf(n);i>-1&&bo.splice(i,1)}),[l]),{...l,toast:Ft,dismiss:i=>Ri({type:"DISMISS_TOAST",toastId:i})}}const Q1=[{id:"minLength",label:"长度至少 10 位",description:"Token 长度必须大于等于 10 个字符",validate:l=>l.length>=10},{id:"hasUppercase",label:"包含大写字母",description:"至少包含一个大写字母 (A-Z)",validate:l=>/[A-Z]/.test(l)},{id:"hasLowercase",label:"包含小写字母",description:"至少包含一个小写字母 (a-z)",validate:l=>/[a-z]/.test(l)},{id:"hasSpecialChar",label:"包含特殊符号",description:"至少包含一个特殊符号 (!@#$%^&*()_+-=[]{}|;:,.<>?/)",validate:l=>/[!@#$%^&*()_+\-=[\]{}|;:,.<>?/]/.test(l)}];function Y1(l){const n=Q1.map(c=>({id:c.id,label:c.label,description:c.description,passed:c.validate(l)}));return{isValid:n.every(c=>c.passed),rules:n}}const Uo="0.12.0",Um="MaiBot Dashboard",J1=`${Um} v${Uo}`,X1=(l="v")=>`${l}${Uo}`,ia={THEME:"maibot-ui-theme",ACCENT_COLOR:"accent-color",ENABLE_ANIMATIONS:"maibot-animations",ENABLE_WAVES_BACKGROUND:"maibot-waves-background",LOG_CACHE_SIZE:"maibot-log-cache-size",LOG_AUTO_SCROLL:"maibot-log-auto-scroll",LOG_FONT_SIZE:"maibot-log-font-size",LOG_LINE_SPACING:"maibot-log-line-spacing",DATA_SYNC_INTERVAL:"maibot-data-sync-interval",WS_RECONNECT_INTERVAL:"maibot-ws-reconnect-interval",WS_MAX_RECONNECT_ATTEMPTS:"maibot-ws-max-reconnect-attempts",COMPLETED_TOURS:"maibot-completed-tours"},Ja={theme:"system",accentColor:"blue",enableAnimations:!0,enableWavesBackground:!0,logCacheSize:1e3,logAutoScroll:!0,logFontSize:"xs",logLineSpacing:4,dataSyncInterval:30,wsReconnectInterval:3e3,wsMaxReconnectAttempts:10};function pt(l){const n=Fj(l),i=localStorage.getItem(n);if(i===null)return Ja[l];const c=Ja[l];if(typeof c=="boolean")return i==="true";if(typeof c=="number"){const u=parseFloat(i);return isNaN(u)?c:u}return i}function _r(l,n){const i=Fj(l);localStorage.setItem(i,String(n)),window.dispatchEvent(new CustomEvent("maibot-settings-change",{detail:{key:l,value:n}}))}function Z1(){return{theme:pt("theme"),accentColor:pt("accentColor"),enableAnimations:pt("enableAnimations"),enableWavesBackground:pt("enableWavesBackground"),logCacheSize:pt("logCacheSize"),logAutoScroll:pt("logAutoScroll"),logFontSize:pt("logFontSize"),logLineSpacing:pt("logLineSpacing"),dataSyncInterval:pt("dataSyncInterval"),wsReconnectInterval:pt("wsReconnectInterval"),wsMaxReconnectAttempts:pt("wsMaxReconnectAttempts")}}function W1(){const l=Z1(),n=localStorage.getItem(ia.COMPLETED_TOURS),i=n?JSON.parse(n):[];return{...l,completedTours:i}}function e2(l){const n=[],i=[];for(const[c,u]of Object.entries(l)){if(c==="completedTours"){Array.isArray(u)?(localStorage.setItem(ia.COMPLETED_TOURS,JSON.stringify(u)),n.push("completedTours")):i.push("completedTours");continue}if(c in Ja){const x=c,h=Ja[x];if(typeof u==typeof h){if(x==="theme"&&!["light","dark","system"].includes(u)){i.push(c);continue}if(x==="logFontSize"&&!["xs","sm","base"].includes(u)){i.push(c);continue}_r(x,u),n.push(c)}else i.push(c)}else i.push(c)}return{success:n.length>0,imported:n,skipped:i}}function s2(){for(const l of Object.keys(Ja))_r(l,Ja[l]);localStorage.removeItem(ia.COMPLETED_TOURS),window.dispatchEvent(new CustomEvent("maibot-settings-reset"))}function t2(){const l=[],n=[],i=[];for(let c=0;cc.size-i.size),{used:l,items:localStorage.length,details:n}}function a2(l){if(l===0)return"0 B";const n=1024,i=["B","KB","MB"],c=Math.floor(Math.log(l)/Math.log(n));return parseFloat((l/Math.pow(n,c)).toFixed(2))+" "+i[c]}function Fj(l){return{theme:ia.THEME,accentColor:ia.ACCENT_COLOR,enableAnimations:ia.ENABLE_ANIMATIONS,enableWavesBackground:ia.ENABLE_WAVES_BACKGROUND,logCacheSize:ia.LOG_CACHE_SIZE,logAutoScroll:ia.LOG_AUTO_SCROLL,logFontSize:ia.LOG_FONT_SIZE,logLineSpacing:ia.LOG_LINE_SPACING,dataSyncInterval:ia.DATA_SYNC_INTERVAL,wsReconnectInterval:ia.WS_RECONNECT_INTERVAL,wsMaxReconnectAttempts:ia.WS_MAX_RECONNECT_ATTEMPTS}[l]}const Na=m.forwardRef(({className:l,...n},i)=>e.jsxs(kg,{ref:i,className:B("relative flex w-full touch-none select-none items-center",l),...n,children:[e.jsx(m0,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(x0,{className:"absolute h-full bg-primary"})}),e.jsx(h0,{className:"block h-4 w-4 rounded-full border border-primary/50 bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"})]}));Na.displayName=kg.displayName;class l2{ws=null;reconnectTimeout=null;reconnectAttempts=0;heartbeatInterval=null;logCallbacks=new Set;connectionCallbacks=new Set;isConnected=!1;logCache=[];getMaxCacheSize(){return pt("logCacheSize")}getMaxReconnectAttempts(){return pt("wsMaxReconnectAttempts")}getReconnectInterval(){return pt("wsReconnectInterval")}getWebSocketUrl(n){let i;{const c=window.location.protocol==="https:"?"wss:":"ws:",u=window.location.host;i=`${c}//${u}/ws/logs`}return n?`${i}?token=${encodeURIComponent(n)}`:i}async getWsToken(){try{const n=await we("/api/webui/ws-token",{method:"GET",credentials:"include"});if(!n.ok)return console.error("获取 WebSocket token 失败:",n.status),null;const i=await n.json();return i.success&&i.token?i.token:null}catch(n){return console.error("获取 WebSocket token 失败:",n),null}}async connect(){if(this.ws?.readyState===WebSocket.OPEN||this.ws?.readyState===WebSocket.CONNECTING)return;if(window.location.pathname==="/auth"){console.log("📡 在登录页面,跳过 WebSocket 连接");return}if(!await Hi()){console.log("📡 未登录,跳过 WebSocket 连接");return}const i=await this.getWsToken();if(!i){console.log("📡 无法获取 WebSocket token,跳过连接");return}const c=this.getWebSocketUrl(i);try{this.ws=new WebSocket(c),this.ws.onopen=()=>{this.isConnected=!0,this.reconnectAttempts=0,this.notifyConnection(!0),this.startHeartbeat()},this.ws.onmessage=u=>{try{if(u.data==="pong")return;const x=JSON.parse(u.data);this.notifyLog(x)}catch(x){console.error("解析日志消息失败:",x)}},this.ws.onerror=u=>{console.error("❌ WebSocket 错误:",u),this.isConnected=!1,this.notifyConnection(!1)},this.ws.onclose=()=>{this.isConnected=!1,this.notifyConnection(!1),this.stopHeartbeat(),this.attemptReconnect()}}catch(u){console.error("创建 WebSocket 连接失败:",u),this.attemptReconnect()}}attemptReconnect(){const n=this.getMaxReconnectAttempts();if(this.reconnectAttempts>=n)return;this.reconnectAttempts+=1;const i=this.getReconnectInterval(),c=Math.min(i*this.reconnectAttempts,3e4);this.reconnectTimeout=window.setTimeout(()=>{this.connect()},c)}startHeartbeat(){this.heartbeatInterval=window.setInterval(()=>{this.ws?.readyState===WebSocket.OPEN&&this.ws.send("ping")},3e4)}stopHeartbeat(){this.heartbeatInterval!==null&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null)}disconnect(){this.reconnectTimeout!==null&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.stopHeartbeat(),this.ws&&(this.ws.close(),this.ws=null),this.isConnected=!1,this.reconnectAttempts=0}onLog(n){return this.logCallbacks.add(n),()=>this.logCallbacks.delete(n)}onConnectionChange(n){return this.connectionCallbacks.add(n),n(this.isConnected),()=>this.connectionCallbacks.delete(n)}notifyLog(n){if(!this.logCache.some(c=>c.id===n.id)){this.logCache.push(n);const c=this.getMaxCacheSize();this.logCache.length>c&&(this.logCache=this.logCache.slice(-c)),this.logCallbacks.forEach(u=>{try{u(n)}catch(x){console.error("日志回调执行失败:",x)}})}}notifyConnection(n){this.connectionCallbacks.forEach(i=>{try{i(n)}catch(c){console.error("连接状态回调执行失败:",c)}})}getAllLogs(){return[...this.logCache]}clearLogs(){this.logCache=[]}getConnectionStatus(){return this.isConnected}}const wn=new l2;typeof window<"u"&&setTimeout(()=>{wn.connect()},100);const Is=W0,Bo=ew,n2=X0,Vj=m.forwardRef(({className:l,...n},i)=>e.jsx(qg,{ref:i,className:B("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",l),...n}));Vj.displayName=qg.displayName;const Rs=m.forwardRef(({className:l,children:n,preventOutsideClose:i=!1,...c},u)=>e.jsxs(n2,{children:[e.jsx(Vj,{}),e.jsxs(Fg,{ref:u,className:B("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",l),onPointerDownOutside:i?x=>x.preventDefault():void 0,onInteractOutside:i?x=>x.preventDefault():void 0,...c,children:[n,e.jsxs(Z0,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Rs.displayName=Fg.displayName;const Ls=({className:l,...n})=>e.jsx("div",{className:B("flex flex-col space-y-1.5 text-center sm:text-left",l),...n});Ls.displayName="DialogHeader";const rt=({className:l,...n})=>e.jsx("div",{className:B("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",l),...n});rt.displayName="DialogFooter";const Us=m.forwardRef(({className:l,...n},i)=>e.jsx(Vg,{ref:i,className:B("text-lg font-semibold leading-none tracking-tight",l),...n}));Us.displayName=Vg.displayName;const Zs=m.forwardRef(({className:l,...n},i)=>e.jsx(Kg,{ref:i,className:B("text-sm text-muted-foreground",l),...n}));Zs.displayName=Kg.displayName;const gs=p0,vt=g0,r2=f0,Kj=m.forwardRef(({className:l,...n},i)=>e.jsx(Tg,{className:B("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",l),...n,ref:i}));Kj.displayName=Tg.displayName;const ds=m.forwardRef(({className:l,...n},i)=>e.jsxs(r2,{children:[e.jsx(Kj,{}),e.jsx(Eg,{ref:i,className:B("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",l),...n})]}));ds.displayName=Eg.displayName;const us=({className:l,...n})=>e.jsx("div",{className:B("flex flex-col space-y-2 text-center sm:text-left",l),...n});us.displayName="AlertDialogHeader";const ms=({className:l,...n})=>e.jsx("div",{className:B("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",l),...n});ms.displayName="AlertDialogFooter";const xs=m.forwardRef(({className:l,...n},i)=>e.jsx(Mg,{ref:i,className:B("text-lg font-semibold",l),...n}));xs.displayName=Mg.displayName;const hs=m.forwardRef(({className:l,...n},i)=>e.jsx(Ag,{ref:i,className:B("text-sm text-muted-foreground",l),...n}));hs.displayName=Ag.displayName;const fs=m.forwardRef(({className:l,variant:n,...i},c)=>e.jsx(zg,{ref:c,className:B(Mr({variant:n}),l),...i}));fs.displayName=zg.displayName;const ps=m.forwardRef(({className:l,...n},i)=>e.jsx(Dg,{ref:i,className:B(Mr({variant:"outline"}),"mt-2 sm:mt-0",l),...n}));ps.displayName=Dg.displayName;function i2(){return e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"系统设置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理您的应用偏好设置"})]})}),e.jsxs(da,{defaultValue:"appearance",className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2 sm:grid-cols-4 gap-0.5 sm:gap-1 h-auto p-1",children:[e.jsxs(Xe,{value:"appearance",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(_w,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"外观"})]}),e.jsxs(Xe,{value:"security",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(Sw,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"安全"})]}),e.jsxs(Xe,{value:"other",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(zn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"其他"})]}),e.jsxs(Xe,{value:"about",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(Jt,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"关于"})]})]}),e.jsxs(Je,{className:"h-[calc(100vh-240px)] sm:h-[calc(100vh-280px)] mt-4 sm:mt-6",children:[e.jsx(ys,{value:"appearance",className:"mt-0",children:e.jsx(c2,{})}),e.jsx(ys,{value:"security",className:"mt-0",children:e.jsx(o2,{})}),e.jsx(ys,{value:"other",className:"mt-0",children:e.jsx(d2,{})}),e.jsx(ys,{value:"about",className:"mt-0",children:e.jsx(u2,{})})]})]})]})}function Wp(l){const n=document.documentElement,c={blue:{hsl:"221.2 83.2% 53.3%",darkHsl:"217.2 91.2% 59.8%",gradient:null},purple:{hsl:"271 91% 65%",darkHsl:"270 95% 75%",gradient:null},green:{hsl:"142 71% 45%",darkHsl:"142 76% 36%",gradient:null},orange:{hsl:"25 95% 53%",darkHsl:"20 90% 48%",gradient:null},pink:{hsl:"330 81% 60%",darkHsl:"330 85% 70%",gradient:null},red:{hsl:"0 84% 60%",darkHsl:"0 90% 70%",gradient:null},"gradient-sunset":{hsl:"15 95% 60%",darkHsl:"15 95% 65%",gradient:"linear-gradient(135deg, hsl(25 95% 53%) 0%, hsl(330 81% 60%) 100%)"},"gradient-ocean":{hsl:"200 90% 55%",darkHsl:"200 90% 60%",gradient:"linear-gradient(135deg, hsl(221.2 83.2% 53.3%) 0%, hsl(189 94% 43%) 100%)"},"gradient-forest":{hsl:"150 70% 45%",darkHsl:"150 75% 40%",gradient:"linear-gradient(135deg, hsl(142 71% 45%) 0%, hsl(158 64% 52%) 100%)"},"gradient-aurora":{hsl:"310 85% 65%",darkHsl:"310 90% 70%",gradient:"linear-gradient(135deg, hsl(271 91% 65%) 0%, hsl(330 81% 60%) 100%)"},"gradient-fire":{hsl:"15 95% 55%",darkHsl:"15 95% 60%",gradient:"linear-gradient(135deg, hsl(0 84% 60%) 0%, hsl(25 95% 53%) 100%)"},"gradient-twilight":{hsl:"250 90% 60%",darkHsl:"250 95% 65%",gradient:"linear-gradient(135deg, hsl(239 84% 67%) 0%, hsl(271 91% 65%) 100%)"}}[l];if(c)n.style.setProperty("--primary",c.hsl),c.gradient?(n.style.setProperty("--primary-gradient",c.gradient),n.classList.add("has-gradient")):(n.style.removeProperty("--primary-gradient"),n.classList.remove("has-gradient"));else if(l.startsWith("#")){const u=x=>{x=x.replace("#","");const h=parseInt(x.substring(0,2),16)/255,f=parseInt(x.substring(2,4),16)/255,p=parseInt(x.substring(4,6),16)/255,g=Math.max(h,f,p),v=Math.min(h,f,p);let N=0,y=0;const w=(g+v)/2;if(g!==v){const b=g-v;switch(y=w>.5?b/(2-g-v):b/(g+v),g){case h:N=((f-p)/b+(flocalStorage.getItem("accent-color")||"blue");m.useEffect(()=>{const g=localStorage.getItem("accent-color")||"blue";Wp(g)},[]);const p=g=>{f(g),localStorage.setItem("accent-color",g),Wp(g)};return e.jsxs("div",{className:"space-y-6 sm:space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题模式"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4",children:[e.jsx(xm,{value:"light",current:l,onChange:n,label:"浅色",description:"始终使用浅色主题"}),e.jsx(xm,{value:"dark",current:l,onChange:n,label:"深色",description:"始终使用深色主题"}),e.jsx(xm,{value:"system",current:l,onChange:n,label:"跟随系统",description:"根据系统设置自动切换"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题色"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"单色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(za,{value:"blue",current:h,onChange:p,label:"蓝色",colorClass:"bg-blue-500"}),e.jsx(za,{value:"purple",current:h,onChange:p,label:"紫色",colorClass:"bg-purple-500"}),e.jsx(za,{value:"green",current:h,onChange:p,label:"绿色",colorClass:"bg-green-500"}),e.jsx(za,{value:"orange",current:h,onChange:p,label:"橙色",colorClass:"bg-orange-500"}),e.jsx(za,{value:"pink",current:h,onChange:p,label:"粉色",colorClass:"bg-pink-500"}),e.jsx(za,{value:"red",current:h,onChange:p,label:"红色",colorClass:"bg-red-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"渐变色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(za,{value:"gradient-sunset",current:h,onChange:p,label:"日落",colorClass:"bg-gradient-to-r from-orange-500 to-pink-500"}),e.jsx(za,{value:"gradient-ocean",current:h,onChange:p,label:"海洋",colorClass:"bg-gradient-to-r from-blue-500 to-cyan-500"}),e.jsx(za,{value:"gradient-forest",current:h,onChange:p,label:"森林",colorClass:"bg-gradient-to-r from-green-500 to-emerald-500"}),e.jsx(za,{value:"gradient-aurora",current:h,onChange:p,label:"极光",colorClass:"bg-gradient-to-r from-purple-500 to-pink-500"}),e.jsx(za,{value:"gradient-fire",current:h,onChange:p,label:"烈焰",colorClass:"bg-gradient-to-r from-red-500 to-orange-500"}),e.jsx(za,{value:"gradient-twilight",current:h,onChange:p,label:"暮光",colorClass:"bg-gradient-to-r from-indigo-500 to-purple-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"自定义颜色"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 sm:gap-4",children:[e.jsx("div",{className:"flex-1",children:e.jsx("input",{type:"color",value:h.startsWith("#")?h:"#3b82f6",onChange:g=>p(g.target.value),className:"h-10 sm:h-12 w-full rounded-lg border-2 border-border cursor-pointer",title:"选择自定义颜色"})}),e.jsx("div",{className:"flex-1",children:e.jsx(re,{type:"text",value:h,onChange:g=>p(g.target.value),placeholder:"#3b82f6",className:"font-mono text-sm"})})]}),e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground mt-2",children:"点击色块选择颜色,或手动输入 HEX 颜色代码"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"动画效果"}),e.jsxs("div",{className:"space-y-2 sm:space-y-3",children:[e.jsx("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(E,{htmlFor:"animations",className:"text-base font-medium cursor-pointer",children:"启用动画效果"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后将禁用所有过渡动画和特效,提升性能"})]}),e.jsx(Pe,{id:"animations",checked:i,onCheckedChange:c})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(E,{htmlFor:"waves-background",className:"text-base font-medium cursor-pointer",children:"登录页波浪背景"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后登录页将使用纯色背景,适合低性能设备"})]}),e.jsx(Pe,{id:"waves-background",checked:u,onCheckedChange:x})]})})]})]})]})}function o2(){const l=ua(),[n,i]=m.useState(""),[c,u]=m.useState(""),[x,h]=m.useState(!1),[f,p]=m.useState(!1),[g,v]=m.useState(!1),[N,y]=m.useState(!1),[w,b]=m.useState(!1),[L,D]=m.useState(!1),[T,F]=m.useState(""),[O,S]=m.useState(!1),{toast:C}=et(),P=m.useMemo(()=>Y1(c),[c]),M=async me=>{if(!n){C({title:"无法复制",description:"Token 存储在安全 Cookie 中,请重新生成以获取新 Token",variant:"destructive"});return}try{await navigator.clipboard.writeText(me),b(!0),C({title:"复制成功",description:"Token 已复制到剪贴板"}),setTimeout(()=>b(!1),2e3)}catch{C({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},Z=async()=>{if(!c.trim()){C({title:"输入错误",description:"请输入新的 Token",variant:"destructive"});return}if(!P.isValid){const me=P.rules.filter(pe=>!pe.passed).map(pe=>pe.label).join(", ");C({title:"格式错误",description:`Token 不符合要求: ${me}`,variant:"destructive"});return}v(!0);try{const me=await fetch("/api/webui/auth/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({new_token:c.trim()})}),pe=await me.json();me.ok&&pe.success?(u(""),i(c.trim()),C({title:"更新成功",description:"Access Token 已更新,即将跳转到登录页"}),setTimeout(()=>{l({to:"/auth"})},1500)):C({title:"更新失败",description:pe.message||"无法更新 Token",variant:"destructive"})}catch(me){console.error("更新 Token 错误:",me),C({title:"更新失败",description:"连接服务器失败",variant:"destructive"})}finally{v(!1)}},G=async()=>{y(!0);try{const me=await fetch("/api/webui/auth/regenerate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"}),pe=await me.json();me.ok&&pe.success?(i(pe.token),F(pe.token),D(!0),S(!1),C({title:"生成成功",description:"新的 Access Token 已生成,请及时保存"})):C({title:"生成失败",description:pe.message||"无法生成新 Token",variant:"destructive"})}catch(me){console.error("生成 Token 错误:",me),C({title:"生成失败",description:"连接服务器失败",variant:"destructive"})}finally{y(!1)}},ce=async()=>{try{await navigator.clipboard.writeText(T),S(!0),C({title:"复制成功",description:"Token 已复制到剪贴板"})}catch{C({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},de=()=>{D(!1),setTimeout(()=>{F(""),S(!1)},300),setTimeout(()=>{l({to:"/auth"})},500)},be=me=>{me||de()};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(Is,{open:L,onOpenChange:be,children:e.jsxs(Rs,{className:"sm:max-w-md",children:[e.jsxs(Ls,{children:[e.jsxs(Us,{className:"flex items-center gap-2",children:[e.jsx(Qt,{className:"h-5 w-5 text-yellow-500"}),"新的 Access Token"]}),e.jsx(Zs,{children:"这是您的新 Token,请立即保存。关闭此窗口后将跳转到登录页面。"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border-2 border-primary/20 bg-primary/5 p-4",children:[e.jsx(E,{className:"text-xs text-muted-foreground mb-2 block",children:"您的新 Token (64位安全令牌)"}),e.jsx("div",{className:"font-mono text-sm break-all select-all bg-background p-3 rounded border",children:T})]}),e.jsx("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Qt,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-yellow-800 dark:text-yellow-300 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"重要提示"}),e.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-xs",children:[e.jsx("li",{children:"此 Token 仅显示一次,关闭后无法再查看"}),e.jsx("li",{children:"请立即复制并保存到安全的位置"}),e.jsx("li",{children:"关闭窗口后将自动跳转到登录页面"}),e.jsx("li",{children:"请使用新 Token 重新登录系统"})]})]})]})})]}),e.jsxs(rt,{className:"gap-2 sm:gap-0",children:[e.jsx(k,{variant:"outline",onClick:ce,className:"gap-2",children:O?e.jsxs(e.Fragment,{children:[e.jsx(_t,{className:"h-4 w-4 text-green-500"}),"已复制"]}):e.jsxs(e.Fragment,{children:[e.jsx(_o,{className:"h-4 w-4"}),"复制 Token"]})}),e.jsx(k,{onClick:de,children:"我已保存,关闭"})]})]})}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"当前 Access Token"}),e.jsx("div",{className:"space-y-3 sm:space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"current-token",className:"text-sm",children:"您的访问令牌"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(re,{id:"current-token",type:x?"text":"password",value:n||"••••••••••••••••••••••••••••••••",readOnly:!0,className:"pr-10 font-mono text-sm",placeholder:"Token 存储在安全 Cookie 中"}),e.jsx("button",{onClick:()=>{n?h(!x):C({title:"无法查看",description:'Token 存储在安全 Cookie 中,如需新 Token 请点击"重新生成"'})},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:x?"隐藏":"显示",children:x?e.jsx(Bi,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Xt,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(k,{variant:"outline",size:"icon",onClick:()=>M(n),title:"复制到剪贴板",className:"flex-shrink-0",disabled:!n,children:w?e.jsx(_t,{className:"h-4 w-4 text-green-500"}):e.jsx(_o,{className:"h-4 w-4"})}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsxs(k,{variant:"outline",disabled:N,className:"gap-2 flex-1 sm:flex-none",children:[e.jsx(zt,{className:B("h-4 w-4",N&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:"重新生成"}),e.jsx("span",{className:"sm:hidden",children:"生成"})]})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认重新生成 Token"}),e.jsx(hs,{children:"这将生成一个新的 64 位安全令牌,并使当前 Token 立即失效。 您需要使用新 Token 重新登录系统。此操作不可撤销,确定要继续吗?"})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:G,children:"确认生成"})]})]})]})]})]}),e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground",children:"请妥善保管您的 Access Token,不要泄露给他人"})]})})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"自定义 Access Token"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"new-token",className:"text-sm",children:"新的访问令牌"}),e.jsxs("div",{className:"relative",children:[e.jsx(re,{id:"new-token",type:f?"text":"password",value:c,onChange:me=>u(me.target.value),className:"pr-10 font-mono text-sm",placeholder:"输入自定义 Token"}),e.jsx("button",{onClick:()=>p(!f),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:f?"隐藏":"显示",children:f?e.jsx(Bi,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Xt,{className:"h-4 w-4 text-muted-foreground"})})]}),c&&e.jsxs("div",{className:"mt-3 space-y-2 p-3 rounded-lg bg-muted/50",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Token 安全要求:"}),e.jsx("div",{className:"space-y-1.5",children:P.rules.map(me=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[me.passed?e.jsx(oa,{className:"h-4 w-4 text-green-500 flex-shrink-0"}):e.jsx(dj,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:B(me.passed?"text-green-600 dark:text-green-400":"text-muted-foreground"),children:me.label})]},me.id))}),P.isValid&&e.jsx("div",{className:"mt-2 pt-2 border-t border-border",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:"Token 格式正确,可以使用"})]})})]})]}),e.jsx(k,{onClick:Z,disabled:g||!P.isValid||!c,className:"w-full sm:w-auto",children:g?"更新中...":"更新自定义 Token"})]})]}),e.jsxs("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3 sm:p-4",children:[e.jsx("h4",{className:"text-sm sm:text-base font-semibold text-yellow-900 dark:text-yellow-200 mb-2",children:"安全提示"}),e.jsxs("ul",{className:"text-xs sm:text-sm text-yellow-800 dark:text-yellow-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"重新生成 Token 会创建系统随机生成的 64 位安全令牌"}),e.jsx("li",{children:"自定义 Token 必须满足所有安全要求才能使用"}),e.jsx("li",{children:"更新 Token 后,旧的 Token 将立即失效"}),e.jsx("li",{children:"请在安全的环境下查看和复制 Token"}),e.jsx("li",{children:"如果怀疑 Token 泄露,请立即重新生成或更新"}),e.jsx("li",{children:"建议使用系统生成的 Token 以获得最高安全性"})]})]})]})}function d2(){const l=ua(),{toast:n}=et(),[i,c]=m.useState(!1),[u,x]=m.useState(!1),[h,f]=m.useState(()=>pt("logCacheSize")),[p,g]=m.useState(()=>pt("wsReconnectInterval")),[v,N]=m.useState(()=>pt("wsMaxReconnectAttempts")),[y,w]=m.useState(()=>pt("dataSyncInterval")),[b,L]=m.useState(()=>Zp()),[D,T]=m.useState(!1),[F,O]=m.useState(!1),S=m.useRef(null);if(u)throw new Error("这是一个手动触发的测试错误,用于验证错误边界组件是否正常工作。");const C=()=>{L(Zp())},P=A=>{const Y=A[0];f(Y),_r("logCacheSize",Y)},M=A=>{const Y=A[0];g(Y),_r("wsReconnectInterval",Y)},Z=A=>{const Y=A[0];N(Y),_r("wsMaxReconnectAttempts",Y)},G=A=>{const Y=A[0];w(Y),_r("dataSyncInterval",Y)},ce=()=>{wn.clearLogs(),n({title:"日志已清除",description:"日志缓存已清空"})},de=()=>{const A=t2();C(),n({title:"缓存已清除",description:`已清除 ${A.clearedKeys.length} 项缓存数据`})},be=()=>{T(!0);try{const A=W1(),Y=JSON.stringify(A,null,2),H=new Blob([Y],{type:"application/json"}),U=URL.createObjectURL(H),$=document.createElement("a");$.href=U,$.download=`maibot-webui-settings-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild($),$.click(),document.body.removeChild($),URL.revokeObjectURL(U),n({title:"导出成功",description:"设置已导出为 JSON 文件"})}catch(A){console.error("导出设置失败:",A),n({title:"导出失败",description:"无法导出设置",variant:"destructive"})}finally{T(!1)}},me=A=>{const Y=A.target.files?.[0];if(!Y)return;O(!0);const H=new FileReader;H.onload=U=>{try{const $=U.target?.result,_e=JSON.parse($),Ne=e2(_e);Ne.success?(f(pt("logCacheSize")),g(pt("wsReconnectInterval")),N(pt("wsMaxReconnectAttempts")),w(pt("dataSyncInterval")),C(),n({title:"导入成功",description:`成功导入 ${Ne.imported.length} 项设置${Ne.skipped.length>0?`,跳过 ${Ne.skipped.length} 项`:""}`}),(Ne.imported.includes("theme")||Ne.imported.includes("accentColor"))&&n({title:"提示",description:"部分设置需要刷新页面才能完全生效"})):n({title:"导入失败",description:"没有有效的设置项可导入",variant:"destructive"})}catch($){console.error("导入设置失败:",$),n({title:"导入失败",description:"文件格式无效",variant:"destructive"})}finally{O(!1),S.current&&(S.current.value="")}},H.readAsText(Y)},pe=()=>{s2(),f(Ja.logCacheSize),g(Ja.wsReconnectInterval),N(Ja.wsMaxReconnectAttempts),w(Ja.dataSyncInterval),C(),n({title:"已重置",description:"所有设置已恢复为默认值,刷新页面以应用更改"})},je=async()=>{c(!0);try{const A=await we("/api/webui/setup/reset",{method:"POST"}),Y=await A.json();A.ok&&Y.success?(n({title:"重置成功",description:"即将进入初次配置向导"}),setTimeout(()=>{l({to:"/setup"})},1e3)):n({title:"重置失败",description:Y.message||"无法重置配置状态",variant:"destructive"})}catch(A){console.error("重置配置状态错误:",A),n({title:"重置失败",description:"连接服务器失败",variant:"destructive"})}finally{c(!1)}};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(Cr,{className:"h-5 w-5"}),"性能与存储"]}),e.jsxs("div",{className:"space-y-4 sm:space-y-5",children:[e.jsxs("div",{className:"rounded-lg bg-muted/50 p-3 sm:p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Cw,{className:"h-4 w-4"}),"本地存储使用"]}),e.jsx(k,{variant:"ghost",size:"sm",onClick:C,className:"h-7 px-2",children:e.jsx(zt,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:a2(b.used)}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[b.items," 个存储项"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{className:"text-sm font-medium",children:"日志缓存大小"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h," 条"]})]}),e.jsx(Na,{value:[h],onValueChange:P,min:100,max:5e3,step:100,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"控制日志查看器最多缓存的日志条数,较大的值会占用更多内存"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{className:"text-sm font-medium",children:"首页数据刷新间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[y," 秒"]})]}),e.jsx(Na,{value:[y],onValueChange:G,min:10,max:120,step:5,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"控制首页统计数据的自动刷新间隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{className:"text-sm font-medium",children:"WebSocket 重连间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[p/1e3," 秒"]})]}),e.jsx(Na,{value:[p],onValueChange:M,min:1e3,max:1e4,step:500,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"日志 WebSocket 连接断开后的重连基础间隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{className:"text-sm font-medium",children:"WebSocket 最大重连次数"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[v," 次"]})]}),e.jsx(Na,{value:[v],onValueChange:Z,min:3,max:30,step:1,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"连接失败后的最大重连尝试次数"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-2",children:[e.jsxs(k,{variant:"outline",size:"sm",onClick:ce,className:"gap-2",children:[e.jsx(ns,{className:"h-4 w-4"}),"清除日志缓存"]}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(ns,{className:"h-4 w-4"}),"清除本地缓存"]})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认清除本地缓存"}),e.jsx(hs,{children:"这将清除所有本地缓存的设置和数据(不包括登录凭证)。 您可能需要重新配置部分偏好设置。确定要继续吗?"})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:de,children:"确认清除"})]})]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(Yt,{className:"h-5 w-5"}),"导入/导出设置"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"导出当前的界面设置以便备份,或从之前导出的文件中恢复设置。"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(k,{variant:"outline",onClick:be,disabled:D,className:"gap-2",children:[e.jsx(Yt,{className:"h-4 w-4"}),D?"导出中...":"导出设置"]}),e.jsx("input",{ref:S,type:"file",accept:".json",onChange:me,className:"hidden"}),e.jsxs(k,{variant:"outline",onClick:()=>S.current?.click(),disabled:F,className:"gap-2",children:[e.jsx($i,{className:"h-4 w-4"}),F?"导入中...":"导入设置"]})]}),e.jsx("div",{className:"pt-2 border-t",children:e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",className:"gap-2 text-destructive hover:text-destructive",children:[e.jsx(Ui,{className:"h-4 w-4"}),"重置所有设置为默认值"]})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认重置所有设置"}),e.jsx(hs,{children:"这将把所有界面设置恢复为默认值,包括主题、颜色、动画等偏好设置。 此操作不会影响您的登录状态。确定要继续吗?"})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:pe,children:"确认重置"})]})]})]})})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"配置向导"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"重新进行初次配置向导,可以帮助您重新设置系统的基础配置。"})}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsxs(k,{variant:"outline",disabled:i,className:"gap-2",children:[e.jsx(Ui,{className:B("h-4 w-4",i&&"animate-spin")}),"重新进行初次配置"]})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认重新配置"}),e.jsx(hs,{children:"这将带您重新进入初次配置向导。您可以重新设置系统的基础配置项。确定要继续吗?"})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:je,children:"确认重置"})]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-dashed border-yellow-500/50 bg-yellow-500/5 p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(Qt,{className:"h-5 w-5 text-yellow-500"}),"开发者工具"]}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"以下功能仅供开发调试使用,可能会导致页面崩溃或异常。"})}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsxs(k,{variant:"destructive",className:"gap-2",children:[e.jsx(Qt,{className:"h-4 w-4"}),"触发测试错误"]})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认触发错误"}),e.jsx(hs,{children:"这将手动触发一个 React 错误,用于测试错误边界组件的显示效果。 页面将显示错误界面,您可以通过刷新页面或点击返回首页来恢复。"})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>x(!0),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认触发"})]})]})]})]})]})]})}function u2(){return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx("div",{className:"rounded-lg border-2 border-primary/30 bg-gradient-to-r from-primary/5 to-primary/10 p-4 sm:p-6",children:e.jsxs("div",{className:"flex items-start gap-3 sm:gap-4",children:[e.jsx("div",{className:"flex-shrink-0 rounded-lg bg-primary/10 p-2 sm:p-3",children:e.jsx("svg",{className:"h-6 w-6 sm:h-8 sm:w-8 text-primary",fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-lg sm:text-xl font-bold text-foreground mb-2",children:"开源项目"}),e.jsx("p",{className:"text-sm sm:text-base text-muted-foreground mb-3",children:"本项目在 GitHub 开源,欢迎 Star ⭐ 支持!"}),e.jsxs("a",{href:"https://github.com/Mai-with-u/MaiBot-Dashboard",target:"_blank",rel:"noopener noreferrer",className:B("inline-flex items-center gap-2 px-4 py-2 rounded-lg","bg-primary text-primary-foreground font-medium text-sm","hover:bg-primary/90 transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"),children:[e.jsx("svg",{className:"h-4 w-4",fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z",clipRule:"evenodd"})}),"前往 GitHub",e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]})}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:["关于 ",Um]}),e.jsxs("div",{className:"space-y-2 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("p",{children:["版本: ",Uo]}),e.jsx("p",{children:"麦麦(MaiBot)的现代化 Web 管理界面"})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"作者"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"MaiBot 核心"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"Mai-with-u"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"WebUI"}),e.jsxs("p",{className:"text-xs sm:text-sm text-muted-foreground",children:["Mai-with-u ",e.jsx("a",{href:"https://github.com/DrSmoothl",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"@MotricSeven"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"技术栈"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"前端框架"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"React 19.2.0"}),e.jsx("li",{children:"TypeScript 5.7.2"}),e.jsx("li",{children:"Vite 6.0.7"}),e.jsx("li",{children:"TanStack Router 1.94.2"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"UI 组件"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"shadcn/ui"}),e.jsx("li",{children:"Radix UI"}),e.jsx("li",{children:"Tailwind CSS 3.4.17"}),e.jsx("li",{children:"Lucide Icons"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"后端"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Python 3.12+"}),e.jsx("li",{children:"FastAPI"}),e.jsx("li",{children:"Uvicorn"}),e.jsx("li",{children:"WebSocket"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"构建工具"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Bun / npm"}),e.jsx("li",{children:"ESLint 9.17.0"}),e.jsx("li",{children:"PostCSS"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"开源库感谢"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mb-3",children:"本项目使用了以下优秀的开源库,感谢他们的贡献:"}),e.jsx(Je,{className:"h-[300px] sm:h-[400px]",children:e.jsxs("div",{className:"space-y-4 pr-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"UI 框架与组件"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(dt,{name:"React",description:"用户界面构建库",license:"MIT"}),e.jsx(dt,{name:"shadcn/ui",description:"优雅的 React 组件库",license:"MIT"}),e.jsx(dt,{name:"Radix UI",description:"无样式的可访问组件库",license:"MIT"}),e.jsx(dt,{name:"Tailwind CSS",description:"实用优先的 CSS 框架",license:"MIT"}),e.jsx(dt,{name:"Lucide React",description:"精美的图标库",license:"ISC"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"路由与状态管理"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(dt,{name:"TanStack Router",description:"类型安全的路由库",license:"MIT"}),e.jsx(dt,{name:"Zustand",description:"轻量级状态管理",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"表单处理"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(dt,{name:"React Hook Form",description:"高性能表单库",license:"MIT"}),e.jsx(dt,{name:"Zod",description:"TypeScript 优先的 schema 验证",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"工具库"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(dt,{name:"clsx",description:"条件 className 构建工具",license:"MIT"}),e.jsx(dt,{name:"tailwind-merge",description:"Tailwind 类名合并工具",license:"MIT"}),e.jsx(dt,{name:"class-variance-authority",description:"组件变体管理",license:"Apache-2.0"}),e.jsx(dt,{name:"date-fns",description:"现代化日期处理库",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"动画效果"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(dt,{name:"Framer Motion",description:"React 动画库",license:"MIT"}),e.jsx(dt,{name:"vaul",description:"抽屉组件动画",license:"MIT"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"后端框架"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(dt,{name:"FastAPI",description:"现代化 Python Web 框架",license:"MIT"}),e.jsx(dt,{name:"Uvicorn",description:"ASGI 服务器",license:"BSD-3-Clause"}),e.jsx(dt,{name:"Pydantic",description:"数据验证库",license:"MIT"}),e.jsx(dt,{name:"python-multipart",description:"文件上传支持",license:"Apache-2.0"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"开发工具"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(dt,{name:"TypeScript",description:"JavaScript 的超集",license:"Apache-2.0"}),e.jsx(dt,{name:"Vite",description:"下一代前端构建工具",license:"MIT"}),e.jsx(dt,{name:"ESLint",description:"JavaScript 代码检查工具",license:"MIT"}),e.jsx(dt,{name:"PostCSS",description:"CSS 转换工具",license:"MIT"})]})]})]})})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"开源许可"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"rounded-lg bg-primary/5 border border-primary/20 p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-start gap-2 sm:gap-3",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("div",{className:"rounded-md bg-primary/10 px-2 py-1",children:e.jsx("span",{className:"text-xs sm:text-sm font-bold text-primary",children:"GPLv3"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm sm:text-base font-semibold text-foreground mb-1",children:"MaiBot WebUI"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"本项目采用 GNU General Public License v3.0 开源许可证。 您可以自由地使用、修改和分发本软件,但必须保持相同的开源许可。"})]})]})}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"本项目依赖的所有开源库均遵循各自的开源许可证(MIT、Apache-2.0、BSD 等)。 感谢所有开源贡献者的无私奉献。"})]})]})]})}function dt({name:l,description:n,license:i}){return e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg border bg-muted/30 p-2.5 sm:p-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-foreground truncate",children:l}),e.jsx("p",{className:"text-muted-foreground text-xs mt-0.5",children:n})]}),e.jsx("span",{className:"inline-flex items-center rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary flex-shrink-0",children:i})]})}function xm({value:l,current:n,onChange:i,label:c,description:u}){const x=n===l;return e.jsxs("button",{onClick:()=>i(l),className:B("relative rounded-lg border-2 p-3 sm:p-4 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",x?"border-primary bg-accent":"border-border"),children:[x&&e.jsx("div",{className:"absolute top-2 right-2 sm:top-3 sm:right-3 h-2 w-2 rounded-full bg-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm sm:text-base font-medium",children:c}),e.jsx("div",{className:"text-[10px] sm:text-xs text-muted-foreground",children:u})]}),e.jsxs("div",{className:"mt-2 sm:mt-3 flex gap-1",children:[l==="light"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-200"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-300"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-400"})]}),l==="dark"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-700"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-800"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-900"})]}),l==="system"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-200 to-slate-700"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-300 to-slate-800"}),e.jsx("div",{className:"h-2 w-2 rounded-full bg-gradient-to-r from-slate-400 to-slate-900"})]})]})]})}function za({value:l,current:n,onChange:i,label:c,colorClass:u}){const x=n===l;return e.jsxs("button",{onClick:()=>i(l),className:B("relative rounded-lg border-2 p-2 sm:p-3 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",x?"border-primary bg-accent":"border-border"),children:[x&&e.jsx("div",{className:"absolute top-1.5 right-1.5 sm:top-2 sm:right-2 h-1.5 w-1.5 sm:h-2 sm:w-2 rounded-full bg-primary"}),e.jsxs("div",{className:"flex flex-col items-center gap-1.5 sm:gap-2",children:[e.jsx("div",{className:B("h-8 w-8 sm:h-10 sm:w-10 rounded-full",u)}),e.jsx("div",{className:"text-[10px] sm:text-xs font-medium text-center",children:c})]})]})}const m2=Date.now()%1e6;class x2{grad3;p;perm;constructor(n=0){this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.p=[];for(let i=0;i<256;i++)this.p[i]=Math.floor(Math.random()*256);this.perm=[];for(let i=0;i<512;i++)this.perm[i]=this.p[i&255]}dot(n,i,c){return n[0]*i+n[1]*c}mix(n,i,c){return(1-c)*n+c*i}fade(n){return n*n*n*(n*(n*6-15)+10)}perlin2(n,i){const c=Math.floor(n)&255,u=Math.floor(i)&255;n-=Math.floor(n),i-=Math.floor(i);const x=this.fade(n),h=this.fade(i),f=this.perm[c]+u,p=this.perm[f],g=this.perm[f+1],v=this.perm[c+1]+u,N=this.perm[v],y=this.perm[v+1];return this.mix(this.mix(this.dot(this.grad3[p%12],n,i),this.dot(this.grad3[N%12],n-1,i),x),this.mix(this.dot(this.grad3[g%12],n,i-1),this.dot(this.grad3[y%12],n-1,i-1),x),h)}}function eg(){const l=m.useRef(null),n=m.useRef(null),i=m.useRef(void 0),[c]=m.useState(()=>new x2(m2)),u=m.useRef({mouse:{x:-10,y:0,lx:0,ly:0,sx:0,sy:0,v:0,vs:0,a:0,set:!1},lines:[],paths:[],noise:c,bounding:null});return m.useEffect(()=>{const x=n.current,h=l.current;if(!x||!h)return;const f=u.current;f.noise=c;const p=()=>{const D=x.getBoundingClientRect();f.bounding=D,h.style.width=`${D.width}px`,h.style.height=`${D.height}px`},g=()=>{if(!f.bounding)return;const{width:D,height:T}=f.bounding;f.lines=[],f.paths.forEach(ce=>ce.remove()),f.paths=[];const F=10,O=32,S=D+200,C=T+30,P=Math.ceil(S/F),M=Math.ceil(C/O),Z=(D-F*P)/2,G=(T-O*M)/2;for(let ce=0;ce<=P;ce++){const de=[];for(let me=0;me<=M;me++){const pe={x:Z+F*ce,y:G+O*me,wave:{x:0,y:0},cursor:{x:0,y:0,vx:0,vy:0}};de.push(pe)}const be=document.createElementNS("http://www.w3.org/2000/svg","path");h.appendChild(be),f.paths.push(be),f.lines.push(de)}},v=D=>{const{lines:T,mouse:F,noise:O}=f;T.forEach(S=>{S.forEach(C=>{const P=O.perlin2((C.x+D*.0125)*.002,(C.y+D*.005)*.0015)*12;C.wave.x=Math.cos(P)*32,C.wave.y=Math.sin(P)*16;const M=C.x-F.sx,Z=C.y-F.sy,G=Math.hypot(M,Z),ce=Math.max(175,F.vs);if(G{const F={x:D.x+D.wave.x+(T?D.cursor.x:0),y:D.y+D.wave.y+(T?D.cursor.y:0)};return F.x=Math.round(F.x*10)/10,F.y=Math.round(F.y*10)/10,F},y=()=>{const{lines:D,paths:T}=f;D.forEach((F,O)=>{let S=N(F[0],!1),C=`M ${S.x} ${S.y}`;F.forEach((P,M)=>{const Z=M===F.length-1;S=N(P,!Z),C+=`L ${S.x} ${S.y}`}),T[O].setAttribute("d",C)})},w=D=>{const{mouse:T}=f;T.sx+=(T.x-T.sx)*.1,T.sy+=(T.y-T.sy)*.1;const F=T.x-T.lx,O=T.y-T.ly,S=Math.hypot(F,O);T.v=S,T.vs+=(S-T.vs)*.1,T.vs=Math.min(100,T.vs),T.lx=T.x,T.ly=T.y,T.a=Math.atan2(O,F),x&&(x.style.setProperty("--x",`${T.sx}px`),x.style.setProperty("--y",`${T.sy}px`)),v(D),y(),i.current=requestAnimationFrame(w)},b=D=>{if(!f.bounding)return;const{mouse:T}=f;T.x=D.pageX-f.bounding.left,T.y=D.pageY-f.bounding.top+window.scrollY,T.set||(T.sx=T.x,T.sy=T.y,T.lx=T.x,T.ly=T.y,T.set=!0)},L=()=>{p(),g()};return p(),g(),window.addEventListener("resize",L),window.addEventListener("mousemove",b),i.current=requestAnimationFrame(w),()=>{window.removeEventListener("resize",L),window.removeEventListener("mousemove",b),i.current&&cancelAnimationFrame(i.current)}},[c]),e.jsxs("div",{ref:n,className:"waves-background",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden",pointerEvents:"none"},children:[e.jsx("div",{className:"waves-cursor",style:{position:"absolute",top:0,left:0,width:"0.5rem",height:"0.5rem",background:"hsl(var(--primary) / 0.3)",borderRadius:"50%",transform:"translate3d(calc(var(--x, -0.5rem) - 50%), calc(var(--y, 50%) - 50%), 0)",willChange:"transform",pointerEvents:"none"}}),e.jsx("svg",{ref:l,style:{display:"block",width:"100%",height:"100%"},children:e.jsx("style",{children:` path { fill: none; stroke: hsl(var(--primary) / 0.20); stroke-width: 1px; } `})})]})}function h2(){const[l,n]=m.useState(""),[i,c]=m.useState(!1),[u,x]=m.useState(""),[h,f]=m.useState(!0),p=ua(),{enableWavesBackground:g,setEnableWavesBackground:v}=qj(),{theme:N,setTheme:y}=Lm();m.useEffect(()=>{(async()=>{try{await Hi()&&p({to:"/"})}catch{}finally{f(!1)}})()},[p]);const b=N==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":N,L=()=>{y(b==="dark"?"light":"dark")},D=async T=>{if(T.preventDefault(),x(""),!l.trim()){x("请输入 Access Token");return}c(!0),console.log("开始验证 token...");try{const F=await fetch("/api/webui/auth/verify",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({token:l.trim()})});console.log("Token 验证响应状态:",F.status);const O=await F.json();if(console.log("Token 验证响应数据:",O),F.ok&&O.valid){console.log("Token 验证成功,准备跳转..."),console.log("is_first_setup:",O.is_first_setup),await new Promise(C=>setTimeout(C,100));const S=await Hi();console.log("跳转前认证状态检查:",S),O.is_first_setup?(console.log("跳转到首次配置页面"),p({to:"/setup"})):(console.log("跳转到首页"),p({to:"/"}))}else console.error("Token 验证失败:",O.message),x(O.message||"Token 验证失败,请检查后重试")}catch(F){console.error("Token 验证错误:",F),x("连接服务器失败,请检查网络连接")}finally{c(!1)}};return h?e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[g&&e.jsx(eg,{}),e.jsx("div",{className:"text-muted-foreground",children:"正在检查登录状态..."})]}):e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[g&&e.jsx(eg,{}),e.jsxs(ze,{className:"relative z-10 w-full max-w-md shadow-2xl backdrop-blur-xl bg-card/80 border-border/50",children:[e.jsx("button",{onClick:L,className:"absolute right-4 top-4 rounded-lg p-2 hover:bg-accent transition-colors z-10 text-foreground",title:b==="dark"?"切换到浅色模式":"切换到深色模式",children:b==="dark"?e.jsx(uj,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"}):e.jsx(mj,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"})}),e.jsxs(ts,{className:"space-y-4 text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-2xl bg-primary/10",children:e.jsx(Pp,{className:"h-8 w-8 text-primary",strokeWidth:2,fill:"none"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ls,{className:"text-2xl font-bold",children:"欢迎使用 MaiBot"}),e.jsx(Vs,{className:"text-base",children:"请输入您的 Access Token 以继续访问系统"})]})]}),e.jsx(Ye,{children:e.jsxs("form",{onSubmit:D,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"token",className:"text-sm font-medium",children:"Access Token"}),e.jsxs("div",{className:"relative",children:[e.jsx(Am,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground",strokeWidth:2,fill:"none"}),e.jsx(re,{id:"token",type:"password",placeholder:"请输入您的 Access Token",value:l,onChange:T=>n(T.target.value),className:B("pl-10",u&&"border-red-500 focus-visible:ring-red-500"),disabled:i,autoFocus:!0,autoComplete:"off"})]})]}),u&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-red-50 p-3 text-sm text-red-600 dark:bg-red-950/50 dark:text-red-400",children:[e.jsx(Dt,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{children:u})]}),e.jsx(k,{type:"submit",className:"w-full",disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"验证中..."]}):"验证并进入"}),e.jsxs(Is,{children:[e.jsx(Bo,{asChild:!0,children:e.jsxs("button",{className:"w-full text-center text-sm text-primary hover:text-primary/80 transition-colors underline-offset-4 hover:underline flex items-center justify-center gap-1",children:[e.jsx(xj,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我没有 Token,我该去哪里获得 Token?"]})}),e.jsxs(Rs,{className:"sm:max-w-md",children:[e.jsxs(Ls,{children:[e.jsxs(Us,{className:"flex items-center gap-2",children:[e.jsx(Pp,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"如何获取 Access Token"]}),e.jsx(Zs,{children:"Access Token 是访问 MaiBot WebUI 的唯一凭证,请按以下方式获取"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4 space-y-2",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(kw,{className:"h-5 w-5 text-primary flex-shrink-0 mt-0.5",strokeWidth:2,fill:"none"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("h4",{className:"font-semibold text-sm",children:"方式一:查看启动日志"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"在 MaiBot 启动时,控制台会显示 WebUI Access Token。"}),e.jsxs("div",{className:"rounded bg-background p-2 font-mono text-xs",children:[e.jsx("p",{className:"text-muted-foreground",children:"🔑 WebUI Access Token: abc123..."}),e.jsx("p",{className:"text-muted-foreground",children:"💡 请使用此 Token 登录 WebUI"})]})]})]})}),e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4 space-y-2",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ha,{className:"h-5 w-5 text-primary flex-shrink-0 mt-0.5",strokeWidth:2,fill:"none"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("h4",{className:"font-semibold text-sm",children:"方式二:查看配置文件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Token 保存在项目根目录的配置文件中:"}),e.jsx("div",{className:"rounded bg-background p-2 font-mono text-xs break-all",children:e.jsx("code",{className:"text-primary",children:"data/webui.json"})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["打开此文件,复制 ",e.jsx("code",{className:"px-1 py-0.5 bg-background rounded",children:"access_token"})," 字段的值"]})]})]})}),e.jsx("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Dt,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-500 flex-shrink-0 mt-0.5",strokeWidth:2,fill:"none"}),e.jsxs("div",{className:"text-sm text-yellow-800 dark:text-yellow-300 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"安全提示"}),e.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-xs",children:[e.jsx("li",{children:"请妥善保管您的 Token,不要泄露给他人"}),e.jsx("li",{children:"如需重置 Token,请在登录后前往系统设置"})]})]})]})})]})]})]}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsxs("button",{className:"w-full text-center text-sm text-muted-foreground hover:text-foreground transition-colors underline-offset-4 hover:underline flex items-center justify-center gap-1",children:[e.jsx(Sn,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我觉得这个界面很卡怎么办?"]})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsxs(xs,{className:"flex items-center gap-2",children:[e.jsx(Sn,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"关闭背景动画"]}),e.jsx(hs,{children:"背景动画可能会在低性能设备上造成卡顿。关闭动画可以显著提升界面流畅度。"})]}),e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4 space-y-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭动画后,背景将变为纯色,但不影响任何功能的使用。您可以随时在系统设置中重新开启动画。"})}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>v(!1),children:"关闭动画"})]})]})]})]})})]}),e.jsx("div",{className:"absolute bottom-4 left-0 right-0 text-center text-xs text-muted-foreground",children:e.jsx("p",{children:J1})})]})}const Ys=m.forwardRef(({className:l,...n},i)=>e.jsx("textarea",{className:B("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",l),ref:i,...n}));Ys.displayName="Textarea";const Or=m.forwardRef(({className:l,orientation:n="horizontal",decorative:i=!0,...c},u)=>e.jsx(Og,{ref:u,decorative:i,orientation:n,className:B("shrink-0 bg-border",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",l),...c}));Or.displayName=Og.displayName;function f2({config:l,onChange:n}){const i=u=>{u.trim()&&!l.alias_names.includes(u.trim())&&n({...l,alias_names:[...l.alias_names,u.trim()]})},c=u=>{n({...l,alias_names:l.alias_names.filter((x,h)=>h!==u)})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{htmlFor:"qq_account",children:"QQ账号 *"}),e.jsx(re,{id:"qq_account",type:"number",placeholder:"请输入机器人的QQ账号",value:l.qq_account||"",onChange:u=>n({...l,qq_account:Number(u.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人登录使用的QQ账号"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{htmlFor:"nickname",children:"昵称 *"}),e.jsx(re,{id:"nickname",placeholder:"请输入机器人的昵称",value:l.nickname,onChange:u=>n({...l,nickname:u.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人的主要称呼名称"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{children:"别名"}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:l.alias_names.map((u,x)=>e.jsxs(Te,{variant:"secondary",className:"gap-1",children:[u,e.jsx("button",{type:"button",onClick:()=>c(x),className:"ml-1 hover:text-destructive",children:e.jsx(Da,{className:"h-3 w-3"})})]},x))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(re,{id:"alias_input",placeholder:"输入别名后按回车添加",onKeyPress:u=>{u.key==="Enter"&&(i(u.target.value),u.target.value="")}}),e.jsx(k,{type:"button",variant:"outline",onClick:()=>{const u=document.getElementById("alias_input");u&&(i(u.value),u.value="")},children:"添加"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人的其他称呼,可以添加多个"})]})]})}function p2({config:l,onChange:n}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{htmlFor:"personality",children:"人格特征 *"}),e.jsx(Ys,{id:"personality",placeholder:"描述机器人的人格特质和身份特征(建议120字以内)",value:l.personality,onChange:i=>n({...l,personality:i.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:是一个女大学生,现在在读大二,会刷贴吧"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{htmlFor:"reply_style",children:"表达风格 *"}),e.jsx(Ys,{id:"reply_style",placeholder:"描述机器人说话的表达风格、表达习惯",value:l.reply_style,onChange:i=>n({...l,reply_style:i.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:回复平淡一些,简短一些,说中文,参考贴吧、知乎和微博的回复风格"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{htmlFor:"interest",children:"兴趣 *"}),e.jsx(Ys,{id:"interest",placeholder:"描述机器人感兴趣的话题",value:l.interest,onChange:i=>n({...l,interest:i.target.value}),rows:2}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"会影响机器人对什么话题进行回复"})]}),e.jsx(Or,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{htmlFor:"plan_style",children:"群聊说话规则 *"}),e.jsx(Ys,{id:"plan_style",placeholder:"机器人在群聊中的行为风格和规则",value:l.plan_style,onChange:i=>n({...l,plan_style:i.target.value}),rows:4}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在群聊中如何行动,例如回复频率、条件等"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{htmlFor:"private_plan_style",children:"私聊说话规则 *"}),e.jsx(Ys,{id:"private_plan_style",placeholder:"机器人在私聊中的行为风格和规则",value:l.private_plan_style,onChange:i=>n({...l,private_plan_style:i.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在私聊中的行为方式"})]})]})}function g2({config:l,onChange:n}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(l.emoji_chance*100).toFixed(0),"%"]})]}),e.jsx(re,{id:"emoji_chance",type:"range",min:"0",max:"1",step:"0.1",value:l.emoji_chance,onChange:i=>n({...l,emoji_chance:Number(i.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人发送表情包的概率"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{htmlFor:"max_reg_num",children:"最大表情包数量"}),e.jsx(re,{id:"max_reg_num",type:"number",min:"1",max:"200",value:l.max_reg_num,onChange:i=>n({...l,max_reg_num:Number(i.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人最多保存的表情包数量"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:"do_replace",children:"达到最大数量时替换"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"开启后会删除旧表情包,关闭则不再收集新表情包"})]}),e.jsx(Pe,{id:"do_replace",checked:l.do_replace,onCheckedChange:i=>n({...l,do_replace:i})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(re,{id:"check_interval",type:"number",min:"1",max:"120",value:l.check_interval,onChange:i=>n({...l,check_interval:Number(i.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"检查表情包注册、破损、删除的时间间隔"})]}),e.jsx(Or,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:"steal_emoji",children:"偷取表情包"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人将一些表情包据为己有"})]}),e.jsx(Pe,{id:"steal_emoji",checked:l.steal_emoji,onCheckedChange:i=>n({...l,steal_emoji:i})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:"content_filtration",children:"启用表情包过滤"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只保存符合要求的表情包"})]}),e.jsx(Pe,{id:"content_filtration",checked:l.content_filtration,onCheckedChange:i=>n({...l,content_filtration:i})})]}),l.content_filtration&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(re,{id:"filtration_prompt",placeholder:"例如:符合公序良俗",value:l.filtration_prompt,onChange:i=>n({...l,filtration_prompt:i.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"描述表情包应该符合的要求"})]})]})}function j2({config:l,onChange:n}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:"enable_tool",children:"启用工具系统"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人使用各种工具增强功能"})]}),e.jsx(Pe,{id:"enable_tool",checked:l.enable_tool,onCheckedChange:i=>n({...l,enable_tool:i})})]}),e.jsx(Or,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{htmlFor:"all_global",children:"启用全局黑话模式"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人学习和使用群组黑话"})]}),e.jsx(Pe,{id:"all_global",checked:l.all_global,onCheckedChange:i=>n({...l,all_global:i})})]})]})}function v2({config:l,onChange:n}){const[i,c]=m.useState(!1);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"rounded-lg bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5",children:e.jsx("svg",{className:"h-5 w-5 text-blue-600 dark:text-blue-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsxs("div",{className:"flex-1 text-sm",children:[e.jsx("p",{className:"font-medium text-blue-900 dark:text-blue-100 mb-1",children:"关于硅基流动 (SiliconFlow)"}),e.jsx("p",{className:"text-blue-700 dark:text-blue-300 mb-2",children:"硅基流动提供了完整的模型覆盖,包括 DeepSeek V3、Qwen、视觉模型、语音识别和嵌入模型。 只需一个 API Key 即可使用麦麦的所有功能!"}),e.jsxs("a",{href:"https://cloud.siliconflow.cn",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-blue-600 dark:text-blue-400 hover:underline font-medium",children:["前往硅基流动获取 API Key",e.jsx(vo,{className:"h-3 w-3"})]})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{htmlFor:"siliconflow_api_key",children:"SiliconFlow API Key *"}),e.jsxs("div",{className:"relative",children:[e.jsx(re,{id:"siliconflow_api_key",type:i?"text":"password",placeholder:"sk-...",value:l.api_key,onChange:u=>n({api_key:u.target.value}),className:"font-mono pr-10"}),e.jsx(k,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",onClick:()=>c(!i),children:i?e.jsx(Bi,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Xt,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"请输入您的硅基流动 API 密钥。获取后,麦麦将自动配置所有必需的模型。"})]}),e.jsxs("div",{className:"rounded-lg bg-muted/50 p-4 text-sm space-y-2",children:[e.jsx("p",{className:"font-medium",children:"将自动配置以下模型:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-muted-foreground ml-2",children:[e.jsx("li",{children:"DeepSeek V3 - 主要对话和工具模型"}),e.jsx("li",{children:"Qwen3 30B - 高频小任务和工具调用"}),e.jsx("li",{children:"Qwen3 VL 30B - 图像识别"}),e.jsx("li",{children:"SenseVoice - 语音识别"}),e.jsx("li",{children:"BGE-M3 - 文本嵌入"}),e.jsx("li",{children:"知识库相关模型 (LPMM)"})]})]}),e.jsx("div",{className:"rounded-lg border border-amber-200 dark:border-amber-800 bg-amber-50 dark:bg-amber-950/30 p-4",children:e.jsxs("p",{className:"text-sm text-amber-900 dark:text-amber-100",children:[e.jsx("span",{className:"font-medium",children:"💡 提示:"}),'完成向导后,您可以在"系统设置 → 模型配置"中添加更多 API 提供商和模型。']})})]})}async function N2(){const l=await we("/api/webui/config/bot",{method:"GET",headers:Os()});if(!l.ok)throw new Error("读取Bot配置失败");const i=(await l.json()).config.bot||{};return{qq_account:i.qq_account||0,nickname:i.nickname||"",alias_names:i.alias_names||[]}}async function b2(){const l=await we("/api/webui/config/bot",{method:"GET",headers:Os()});if(!l.ok)throw new Error("读取人格配置失败");const i=(await l.json()).config.personality||{};return{personality:i.personality||"",reply_style:i.reply_style||"",interest:i.interest||"",plan_style:i.plan_style||"",private_plan_style:i.private_plan_style||""}}async function y2(){const l=await we("/api/webui/config/bot",{method:"GET",headers:Os()});if(!l.ok)throw new Error("读取表情包配置失败");const i=(await l.json()).config.emoji||{};return{emoji_chance:i.emoji_chance??.4,max_reg_num:i.max_reg_num??40,do_replace:i.do_replace??!0,check_interval:i.check_interval??10,steal_emoji:i.steal_emoji??!0,content_filtration:i.content_filtration??!1,filtration_prompt:i.filtration_prompt||""}}async function w2(){const l=await we("/api/webui/config/bot",{method:"GET",headers:Os()});if(!l.ok)throw new Error("读取其他配置失败");const i=(await l.json()).config,c=i.tool||{},u=i.expression||{};return{enable_tool:c.enable_tool??!0,all_global:u.all_global_jargon??!0}}async function _2(){const l=await we("/api/webui/config/model",{method:"GET",headers:Os()});if(!l.ok)throw new Error("读取模型配置失败");return{api_key:((await l.json()).config.api_providers||[]).find(x=>x.name==="SiliconFlow")?.api_key||""}}async function S2(l){const n=await we("/api/webui/config/bot/section/bot",{method:"POST",headers:Os(),body:JSON.stringify(l)});if(!n.ok){const i=await n.json();throw new Error(i.detail||"保存Bot基础配置失败")}return await n.json()}async function C2(l){const n=await we("/api/webui/config/bot/section/personality",{method:"POST",headers:Os(),body:JSON.stringify(l)});if(!n.ok){const i=await n.json();throw new Error(i.detail||"保存人格配置失败")}return await n.json()}async function k2(l){const n=await we("/api/webui/config/bot/section/emoji",{method:"POST",headers:Os(),body:JSON.stringify(l)});if(!n.ok){const i=await n.json();throw new Error(i.detail||"保存表情包配置失败")}return await n.json()}async function T2(l){const n=[];n.push(we("/api/webui/config/bot/section/tool",{method:"POST",headers:Os(),body:JSON.stringify({enable_tool:l.enable_tool})})),n.push(we("/api/webui/config/bot/section/expression",{method:"POST",headers:Os(),body:JSON.stringify({all_global_jargon:l.all_global})}));const i=await Promise.all(n);for(const c of i)if(!c.ok){const u=await c.json();throw new Error(u.detail||"保存其他配置失败")}return{success:!0}}async function E2(l){const n=await we("/api/webui/config/model",{method:"GET",headers:Os()});if(!n.ok)throw new Error("读取模型配置失败");const c=(await n.json()).config,u=c.api_providers||[],x=u.findIndex(p=>p.name==="SiliconFlow");x>=0?u[x]={...u[x],api_key:l.api_key}:u.push({name:"SiliconFlow",base_url:"https://api.siliconflow.cn/v1",api_key:l.api_key,client_type:"openai",max_retry:3,timeout:120,retry_interval:5});const h={...c,api_providers:u},f=await we("/api/webui/config/model",{method:"POST",headers:Os(),body:JSON.stringify(h)});if(!f.ok){const p=await f.json();throw new Error(p.detail||"保存模型配置失败")}return await f.json()}async function sg(){const l=await we("/api/webui/setup/complete",{method:"POST"});if(!l.ok){const n=await l.json();throw new Error(n.message||"标记配置完成失败")}return await l.json()}function M2(){return e.jsx(Dn,{children:e.jsx(A2,{})})}function A2(){const l=ua(),{toast:n}=et(),{triggerRestart:i}=sn(),[c,u]=m.useState(0),[x,h]=m.useState(!1),[f,p]=m.useState(!1),[g,v]=m.useState(!0),[N,y]=m.useState({qq_account:0,nickname:"",alias_names:[]}),[w,b]=m.useState({personality:"是一个女大学生,现在在读大二,会刷贴吧。",reply_style:"请回复的平淡一些,简短一些,说中文,不要刻意突出自身学科背景。可以参考贴吧,知乎和微博的回复风格。",interest:"对技术相关话题,游戏和动漫相关话题感兴趣,也对日常话题感兴趣,不喜欢太过沉重严肃的话题",plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 2.如果相同的内容已经被执行,请不要重复执行 3.请控制你的发言频率,不要太过频繁的发言 4.如果有人对你感到厌烦,请减少回复 5.如果有人对你进行攻击,或者情绪激动,请你以合适的方法应对`,private_plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 2.如果相同的内容已经被执行,请不要重复执行 3.某句话如果已经被回复过,不要重复回复`}),[L,D]=m.useState({emoji_chance:.4,max_reg_num:40,do_replace:!0,check_interval:10,steal_emoji:!0,content_filtration:!1,filtration_prompt:"符合公序良俗"}),[T,F]=m.useState({enable_tool:!0,all_global:!0}),[O,S]=m.useState({api_key:""}),C=[{id:"bot-basic",title:"Bot基础",description:"配置机器人的基本信息",icon:Mi},{id:"personality",title:"人格配置",description:"定义机器人的性格和说话风格",icon:kr},{id:"emoji",title:"表情包",description:"配置表情包相关设置",icon:zm},{id:"other",title:"其他设置",description:"工具、情绪系统等配置",icon:zn},{id:"siliconflow",title:"API配置",description:"配置硅基流动API密钥",icon:Am}],P=(c+1)/C.length*100;m.useEffect(()=>{(async()=>{try{v(!0);const[pe,je,A,Y,H]=await Promise.all([N2(),b2(),y2(),w2(),_2()]);y(pe),b(je),D(A),F(Y),S(H)}catch(pe){n({title:"加载配置失败",description:pe instanceof Error?pe.message:"无法加载现有配置,将使用默认值",variant:"destructive"})}finally{v(!1)}})()},[n]);const M=async()=>{p(!0);try{switch(c){case 0:await S2(N);break;case 1:await C2(w);break;case 2:await k2(L);break;case 3:await T2(T);break;case 4:await E2(O);break}return n({title:"保存成功",description:`${C[c].title}配置已保存`}),!0}catch(me){return n({title:"保存失败",description:me instanceof Error?me.message:"未知错误",variant:"destructive"}),!1}finally{p(!1)}},Z=async()=>{await M()&&c{c>0&&u(c-1)},ce=async()=>{h(!0);try{if(!await M()){h(!1);return}await sg(),n({title:"配置完成",description:"麦麦正在重启以应用新配置..."}),await i()}catch(me){n({title:"配置失败",description:me instanceof Error?me.message:"未知错误",variant:"destructive"})}finally{h(!1)}},de=async()=>{try{await sg(),l({to:"/"})}catch(me){n({title:"跳过失败",description:me instanceof Error?me.message:"未知错误",variant:"destructive"})}},be=()=>{switch(c){case 0:return e.jsx(f2,{config:N,onChange:y});case 1:return e.jsx(p2,{config:w,onChange:b});case 2:return e.jsx(g2,{config:L,onChange:D});case 3:return e.jsx(j2,{config:T,onChange:F});case 4:return e.jsx(v2,{config:O,onChange:S});default:return null}};return e.jsxs("div",{className:"relative flex min-h-screen flex-col items-center justify-center overflow-hidden bg-gradient-to-br from-primary/5 via-background to-secondary/5 p-4 md:p-6",children:[e.jsx(On,{}),e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute left-1/4 top-1/4 h-64 w-64 md:h-96 md:w-96 rounded-full bg-primary/5 blur-3xl"}),e.jsx("div",{className:"absolute right-1/4 bottom-1/4 h-64 w-64 md:h-96 md:w-96 rounded-full bg-secondary/5 blur-3xl"})]}),g?e.jsxs("div",{className:"relative z-10 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center",children:e.jsx("div",{className:"h-12 w-12 animate-spin rounded-full border-4 border-primary border-t-transparent"})}),e.jsx("p",{className:"text-lg font-medium",children:"加载配置中..."}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"正在读取现有配置"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative z-10 w-full max-w-4xl",children:[e.jsxs("div",{className:"mb-6 md:mb-8 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 md:h-16 md:w-16 items-center justify-center rounded-2xl bg-primary/10",children:e.jsx(Tw,{className:"h-6 w-6 md:h-8 md:w-8 text-primary",strokeWidth:2,fill:"none"})}),e.jsx("h1",{className:"mb-2 text-2xl md:text-3xl font-bold",children:"首次配置向导"}),e.jsxs("p",{className:"text-sm md:text-base text-muted-foreground",children:["让我们一起完成 ",Um," 的初始配置"]})]}),e.jsxs("div",{className:"mb-6 md:mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between text-xs md:text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["步骤 ",c+1," / ",C.length]}),e.jsxs("span",{className:"font-medium text-primary",children:[Math.round(P),"%"]})]}),e.jsx(Mn,{value:P,className:"h-2"})]}),e.jsx("div",{className:"mb-6 md:mb-8 flex justify-between",children:C.map((me,pe)=>{const je=me.icon;return e.jsxs("div",{className:B("flex flex-1 flex-col items-center gap-1 md:gap-2",pel({to:"/"}),className:"gap-2 w-full sm:w-auto",children:[e.jsx(Ro,{className:"h-4 w-4"}),"返回首页"]}),e.jsxs(k,{size:"lg",variant:"outline",onClick:()=>window.history.back(),className:"gap-2 w-full sm:w-auto",children:[e.jsx(en,{className:"h-4 w-4"}),"返回上一页"]})]}),e.jsx("div",{className:"mt-12 pt-8 border-t border-border",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"如果您认为这是一个错误,请联系系统管理员"})})]})})}const z2=Ts.memo(function({config:n,onChange:i}){const c=()=>{i({...n,platforms:[...n.platforms,""]})},u=g=>{i({...n,platforms:n.platforms.filter((v,N)=>N!==g)})},x=(g,v)=>{const N=[...n.platforms];N[g]=v,i({...n,platforms:N})},h=()=>{i({...n,alias_names:[...n.alias_names,""]})},f=g=>{i({...n,alias_names:n.alias_names.filter((v,N)=>N!==g)})},p=(g,v)=>{const N=[...n.alias_names];N[g]=v,i({...n,alias_names:N})};return e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"基本信息"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"platform",children:"平台"}),e.jsx(re,{id:"platform",value:n.platform,onChange:g=>i({...n,platform:g.target.value}),placeholder:"qq"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"qq_account",children:"QQ账号"}),e.jsx(re,{id:"qq_account",value:n.qq_account,onChange:g=>i({...n,qq_account:g.target.value}),placeholder:"123456789"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"nickname",children:"昵称"}),e.jsx(re,{id:"nickname",value:n.nickname,onChange:g=>i({...n,nickname:g.target.value}),placeholder:"麦麦"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{children:"其他平台账号"}),e.jsxs(k,{onClick:c,size:"sm",variant:"outline",children:[e.jsx(lt,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[n.platforms.map((g,v)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(re,{value:g,onChange:N=>x(v,N.target.value),placeholder:"wx:114514"}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:['确定要删除平台账号 "',g||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>u(v),children:"删除"})]})]})]})]},v)),n.platforms.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无其他平台账号"})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{children:"别名"}),e.jsxs(k,{onClick:h,size:"sm",variant:"outline",children:[e.jsx(lt,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[n.alias_names.map((g,v)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(re,{value:g,onChange:N=>p(v,N.target.value),placeholder:"小麦"}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:['确定要删除别名 "',g||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>f(v),children:"删除"})]})]})]})]},v)),n.alias_names.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无别名"})]})]})]})]})})}),D2=Ts.memo(function({config:n,onChange:i}){const c=()=>{i({...n,states:[...n.states,""]})},u=h=>{i({...n,states:n.states.filter((f,p)=>p!==h)})},x=(h,f)=>{const p=[...n.states];p[h]=f,i({...n,states:p})};return e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"人格设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"personality",children:"人格特质"}),e.jsx(Ys,{id:"personality",value:n.personality,onChange:h=>i({...n,personality:h.target.value}),placeholder:"描述人格特质和身份特征(建议120字以内)",rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"建议120字以内,描述人格特质和身份特征"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"reply_style",children:"表达风格"}),e.jsx(Ys,{id:"reply_style",value:n.reply_style,onChange:h=>i({...n,reply_style:h.target.value}),placeholder:"描述说话的表达风格和习惯",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"interest",children:"兴趣"}),e.jsx(Ys,{id:"interest",value:n.interest,onChange:h=>i({...n,interest:h.target.value}),placeholder:"会影响麦麦对什么话题进行回复",rows:2})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"plan_style",children:"说话规则与行为风格"}),e.jsx(Ys,{id:"plan_style",value:n.plan_style,onChange:h=>i({...n,plan_style:h.target.value}),placeholder:"麦麦的说话规则和行为风格",rows:5})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"visual_style",children:"识图规则"}),e.jsx(Ys,{id:"visual_style",value:n.visual_style,onChange:h=>i({...n,visual_style:h.target.value}),placeholder:"识图时的处理规则",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"private_plan_style",children:"私聊规则"}),e.jsx(Ys,{id:"private_plan_style",value:n.private_plan_style,onChange:h=>i({...n,private_plan_style:h.target.value}),placeholder:"私聊的说话规则和行为风格",rows:4})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{children:"状态列表(人格多样性)"}),e.jsxs(k,{onClick:c,size:"sm",variant:"outline",children:[e.jsx(lt,{className:"h-4 w-4 mr-1"}),"添加状态"]})]}),e.jsx("div",{className:"space-y-2",children:n.states.map((h,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ys,{value:h,onChange:p=>x(f,p.target.value),placeholder:"描述一个人格状态",rows:2}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsx(hs,{children:"确定要删除这个人格状态吗?此操作无法撤销。"})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>u(f),children:"删除"})]})]})]})]},f))})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"state_probability",children:"状态替换概率"}),e.jsx(re,{id:"state_probability",type:"number",step:"0.1",min:"0",max:"1",value:n.state_probability,onChange:h=>i({...n,state_probability:parseFloat(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"每次构建人格时替换 personality 的概率(0.0-1.0)"})]})]})]})})}),Le=rw,Ue=iw,Oe=m.forwardRef(({className:l,children:n,...i},c)=>e.jsxs(Qg,{ref:c,className:B("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",l),...i,children:[n,e.jsx(sw,{asChild:!0,children:e.jsx(Oa,{className:"h-4 w-4 opacity-50"})})]}));Oe.displayName=Qg.displayName;const Yj=m.forwardRef(({className:l,...n},i)=>e.jsx(Yg,{ref:i,className:B("flex cursor-default items-center justify-center py-1",l),...n,children:e.jsx(Tr,{className:"h-4 w-4"})}));Yj.displayName=Yg.displayName;const Jj=m.forwardRef(({className:l,...n},i)=>e.jsx(Jg,{ref:i,className:B("flex cursor-default items-center justify-center py-1",l),...n,children:e.jsx(Oa,{className:"h-4 w-4"})}));Jj.displayName=Jg.displayName;const Re=m.forwardRef(({className:l,children:n,position:i="popper",...c},u)=>e.jsx(tw,{children:e.jsxs(Xg,{ref:u,className:B("relative z-[100] max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-hidden rounded-md border border-border bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",i==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",l),position:i,...c,children:[e.jsx(Yj,{}),e.jsx(aw,{className:B("p-1",i==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),e.jsx(Jj,{})]})}));Re.displayName=Xg.displayName;const O2=m.forwardRef(({className:l,...n},i)=>e.jsx(Zg,{ref:i,className:B("px-2 py-1.5 text-sm font-semibold",l),...n}));O2.displayName=Zg.displayName;const le=m.forwardRef(({className:l,children:n,...i},c)=>e.jsxs(Wg,{ref:c,className:B("relative flex w-full cursor-default select-none items-center rounded-sm py-2 pl-2 pr-8 text-sm outline-none bg-white dark:bg-gray-900 hover:bg-gray-100 dark:hover:bg-gray-800 focus:bg-gray-100 dark:focus:bg-gray-800 data-[disabled]:pointer-events-none data-[disabled]:opacity-50",l),...i,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(lw,{children:e.jsx(_t,{className:"h-4 w-4"})})}),e.jsx(nw,{children:n})]}));le.displayName=Wg.displayName;const R2=m.forwardRef(({className:l,...n},i)=>e.jsx(ej,{ref:i,className:B("-mx-1 my-1 h-px bg-muted",l),...n}));R2.displayName=ej.displayName;const Xa=v0,Za=N0,Ia=m.forwardRef(({className:l,align:n="center",sideOffset:i=4,...c},u)=>e.jsx(j0,{children:e.jsx(Rg,{ref:u,align:n,sideOffset:i,className:B("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-popover-content-transform-origin]",l),...c})}));Ia.displayName=Rg.displayName;const L2=Ts.memo(function({value:n,onChange:i}){const c=m.useMemo(()=>{const w=n.split("-");if(w.length===2){const[b,L]=w,[D,T]=b.split(":"),[F,O]=L.split(":");return{startHour:D?D.padStart(2,"0"):"00",startMinute:T?T.padStart(2,"0"):"00",endHour:F?F.padStart(2,"0"):"23",endMinute:O?O.padStart(2,"0"):"59"}}return{startHour:"00",startMinute:"00",endHour:"23",endMinute:"59"}},[n]),[u,x]=m.useState(c.startHour),[h,f]=m.useState(c.startMinute),[p,g]=m.useState(c.endHour),[v,N]=m.useState(c.endMinute);m.useEffect(()=>{x(c.startHour),f(c.startMinute),g(c.endHour),N(c.endMinute)},[c]);const y=(w,b,L,D)=>{const T=`${w}:${b}-${L}:${D}`;i(T)};return e.jsxs(Xa,{children:[e.jsx(Za,{asChild:!0,children:e.jsxs(k,{variant:"outline",className:"w-full justify-start font-mono text-sm",children:[e.jsx(Nl,{className:"h-4 w-4 mr-2"}),n||"选择时间段"]})}),e.jsx(Ia,{className:"w-72 sm:w-80",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm mb-3",children:"开始时间"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:gap-3",children:[e.jsxs("div",{children:[e.jsx(E,{className:"text-xs",children:"小时"}),e.jsxs(Le,{value:u,onValueChange:w=>{x(w),y(w,h,p,v)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsx(Re,{children:Array.from({length:24},(w,b)=>b).map(w=>e.jsx(le,{value:w.toString().padStart(2,"0"),children:w.toString().padStart(2,"0")},w))})]})]}),e.jsxs("div",{children:[e.jsx(E,{className:"text-xs",children:"分钟"}),e.jsxs(Le,{value:h,onValueChange:w=>{f(w),y(u,w,p,v)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsx(Re,{children:Array.from({length:60},(w,b)=>b).map(w=>e.jsx(le,{value:w.toString().padStart(2,"0"),children:w.toString().padStart(2,"0")},w))})]})]})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm mb-3",children:"结束时间"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:gap-3",children:[e.jsxs("div",{children:[e.jsx(E,{className:"text-xs",children:"小时"}),e.jsxs(Le,{value:p,onValueChange:w=>{g(w),y(u,h,w,v)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsx(Re,{children:Array.from({length:24},(w,b)=>b).map(w=>e.jsx(le,{value:w.toString().padStart(2,"0"),children:w.toString().padStart(2,"0")},w))})]})]}),e.jsxs("div",{children:[e.jsx(E,{className:"text-xs",children:"分钟"}),e.jsxs(Le,{value:v,onValueChange:w=>{N(w),y(u,h,p,w)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsx(Re,{children:Array.from({length:60},(w,b)=>b).map(w=>e.jsx(le,{value:w.toString().padStart(2,"0"),children:w.toString().padStart(2,"0")},w))})]})]})]})]})]})})]})}),U2=Ts.memo(function({rule:n}){const i=`{ target = "${n.target}", time = "${n.time}", value = ${n.value.toFixed(1)} }`;return e.jsxs(Xa,{children:[e.jsx(Za,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",children:[e.jsx(Xt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(Ia,{className:"w-80 sm:w-96",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:i}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})}),B2=Ts.memo(function({config:n,onChange:i}){const c=()=>{i({...n,talk_value_rules:[...n.talk_value_rules,{target:"",time:"00:00-23:59",value:1}]})},u=h=>{i({...n,talk_value_rules:n.talk_value_rules.filter((f,p)=>p!==h)})},x=(h,f,p)=>{const g=[...n.talk_value_rules];g[h]={...g[h],[f]:p},i({...n,talk_value_rules:g})};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"聊天设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"talk_value",children:"聊天频率(基础值)"}),e.jsx(re,{id:"talk_value",type:"number",step:"0.1",min:"0",max:"1",value:n.talk_value,onChange:h=>i({...n,talk_value:parseFloat(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"越小越沉默,范围 0-1"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"mentioned_bot_reply",checked:n.mentioned_bot_reply,onCheckedChange:h=>i({...n,mentioned_bot_reply:h})}),e.jsx(E,{htmlFor:"mentioned_bot_reply",className:"cursor-pointer",children:"启用提及必回复"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"max_context_size",children:"上下文长度"}),e.jsx(re,{id:"max_context_size",type:"number",min:"1",value:n.max_context_size,onChange:h=>i({...n,max_context_size:parseInt(h.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"planner_smooth",children:"规划器平滑"}),e.jsx(re,{id:"planner_smooth",type:"number",step:"1",min:"0",value:n.planner_smooth,onChange:h=>i({...n,planner_smooth:parseFloat(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"增大数值会减小 planner 负荷,推荐 1-5,0 为关闭"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"enable_talk_value_rules",checked:n.enable_talk_value_rules,onCheckedChange:h=>i({...n,enable_talk_value_rules:h})}),e.jsx(E,{htmlFor:"enable_talk_value_rules",className:"cursor-pointer",children:"启用动态发言频率规则"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"include_planner_reasoning",checked:n.include_planner_reasoning,onCheckedChange:h=>i({...n,include_planner_reasoning:h})}),e.jsx(E,{htmlFor:"include_planner_reasoning",className:"cursor-pointer",children:"将 planner 推理加入 replyer"})]})]})]}),n.enable_talk_value_rules&&e.jsxs("div",{className:"border-t pt-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-semibold",children:"动态发言频率规则"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"按时段或聊天流ID调整发言频率,优先匹配具体聊天,再匹配全局规则"})]}),e.jsxs(k,{onClick:c,size:"sm",children:[e.jsx(lt,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),n.talk_value_rules&&n.talk_value_rules.length>0?e.jsx("div",{className:"space-y-4",children:n.talk_value_rules.map((h,f)=>e.jsxs("div",{className:"rounded-lg border p-4 bg-muted/50 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:["规则 #",f+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U2,{rule:h}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"sm",children:e.jsx(ns,{className:"h-4 w-4 text-destructive"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:["确定要删除规则 #",f+1," 吗?此操作无法撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>u(f),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(Le,{value:h.target===""?"global":"specific",onValueChange:p=>{p==="global"?x(f,"target",""):x(f,"target","qq::group")},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"global",children:"全局配置"}),e.jsx(le,{value:"specific",children:"详细配置"})]})]})]}),h.target!==""&&(()=>{const p=h.target.split(":"),g=p[0]||"qq",v=p[1]||"",N=p[2]||"group";return e.jsxs("div",{className:"grid gap-4 p-3 sm:p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Le,{value:g,onValueChange:y=>{x(f,"target",`${y}:${v}:${N}`)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"qq",children:"QQ"}),e.jsx(le,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(re,{value:v,onChange:y=>{x(f,"target",`${g}:${y.target.value}:${N}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Le,{value:N,onValueChange:y=>{x(f,"target",`${g}:${v}:${y}`)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"group",children:"群组(group)"}),e.jsx(le,{value:"private",children:"私聊(private)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前聊天流 ID:",h.target||"(未设置)"]})]})})(),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"时间段 (Time)"}),e.jsx(L2,{value:h.time,onChange:p=>x(f,"time",p)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"支持跨夜区间,例如 23:00-02:00"})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{htmlFor:`rule-value-${f}`,className:"text-xs font-medium",children:"发言频率值 (Value)"}),e.jsx(re,{id:`rule-value-${f}`,type:"number",step:"0.01",min:"0.01",max:"1",value:h.value,onChange:p=>{const g=parseFloat(p.target.value);isNaN(g)||x(f,"value",Math.max(.01,Math.min(1,g)))},className:"w-20 h-8 text-xs"})]}),e.jsx(Na,{value:[h.value],onValueChange:p=>x(f,"value",p[0]),min:.01,max:1,step:.01,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"0.01 (极少发言)"}),e.jsx("span",{children:"0.5"}),e.jsx("span",{children:"1.0 (正常)"})]})]})]})]},f))}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:e.jsx("p",{className:"text-sm",children:'暂无规则,点击"添加规则"按钮创建'})}),e.jsxs("div",{className:"mt-4 p-4 bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800 rounded-lg",children:[e.jsx("h5",{className:"text-sm font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"📝 规则说明"}),e.jsxs("ul",{className:"text-xs text-blue-800 dark:text-blue-200 space-y-1",children:[e.jsxs("li",{children:["• ",e.jsx("strong",{children:"Target 为空"}),":全局规则,对所有聊天生效"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"Target 指定"}),":仅对特定聊天流生效(格式:platform:id:type)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"优先级"}),":先匹配具体聊天流规则,再匹配全局规则"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"时间支持跨夜"}),":例如 23:00-02:00 表示晚上11点到次日凌晨2点"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"数值范围"}),":建议 0-1,0 表示完全沉默,1 表示正常发言"]})]})]})]})]})}),$2=Ts.memo(function({config:n,onChange:i}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"语音设置"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{checked:n.enable_asr,onCheckedChange:c=>i({...n,enable_asr:c})}),e.jsx(E,{className:"cursor-pointer",children:"启用语音识别"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后麦麦可以识别语音消息,需要配置语音识别模型"})]})}),H2=Ts.memo(function({config:n,onChange:i}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{checked:n.enable,onCheckedChange:c=>i({...n,enable:c})}),e.jsx(E,{className:"cursor-pointer",children:"启用 LPMM 知识库"})]}),n.enable&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"LPMM 模式"}),e.jsxs(Le,{value:n.lpmm_mode,onValueChange:c=>i({...n,lpmm_mode:c}),children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:"选择 LPMM 模式"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"classic",children:"经典模式"}),e.jsx(le,{value:"agent",children:"Agent 模式"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"同义词搜索 TopK"}),e.jsx(re,{type:"number",min:"1",value:n.rag_synonym_search_top_k,onChange:c=>i({...n,rag_synonym_search_top_k:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"同义词阈值"}),e.jsx(re,{type:"number",step:"0.1",min:"0",max:"1",value:n.rag_synonym_threshold,onChange:c=>i({...n,rag_synonym_threshold:parseFloat(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"实体提取线程数"}),e.jsx(re,{type:"number",min:"1",value:n.info_extraction_workers,onChange:c=>i({...n,info_extraction_workers:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"嵌入向量维度"}),e.jsx(re,{type:"number",min:"1",value:n.embedding_dimension,onChange:c=>i({...n,embedding_dimension:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"嵌入并发线程数"}),e.jsx(re,{type:"number",min:"1",value:n.max_embedding_workers,onChange:c=>i({...n,max_embedding_workers:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"每批嵌入条数"}),e.jsx(re,{type:"number",min:"1",value:n.embedding_chunk_size,onChange:c=>i({...n,embedding_chunk_size:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"同义实体数上限"}),e.jsx(re,{type:"number",min:"1",value:n.max_synonym_entities,onChange:c=>i({...n,max_synonym_entities:parseInt(c.target.value)})})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{checked:n.enable_ppr,onCheckedChange:c=>i({...n,enable_ppr:c})}),e.jsx(E,{className:"cursor-pointer",children:"启用 PPR (低配机器可关闭)"})]})]})]})]})}),I2=Ts.memo(function({config:n,onChange:i}){const[c,u]=m.useState(""),[x,h]=m.useState("WARNING"),f=()=>{c&&!n.suppress_libraries.includes(c)&&(i({...n,suppress_libraries:[...n.suppress_libraries,c]}),u(""))},p=b=>{i({...n,suppress_libraries:n.suppress_libraries.filter(L=>L!==b)})},g=()=>{c&&!n.library_log_levels[c]&&(i({...n,library_log_levels:{...n.library_log_levels,[c]:x}}),u(""),h("WARNING"))},v=b=>{const L={...n.library_log_levels};delete L[b],i({...n,library_log_levels:L})},N=["DEBUG","INFO","WARNING","ERROR","CRITICAL"],y=["FULL","compact","lite"],w=["none","title","full"];return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"日志配置"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"日期格式"}),e.jsx(re,{value:n.date_style,onChange:b=>i({...n,date_style:b.target.value}),placeholder:"例如: m-d H:i:s"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"m=月, d=日, H=时, i=分, s=秒"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"日志级别样式"}),e.jsxs(Le,{value:n.log_level_style,onValueChange:b=>i({...n,log_level_style:b}),children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsx(Re,{children:y.map(b=>e.jsx(le,{value:b,children:b},b))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"日志文本颜色"}),e.jsxs(Le,{value:n.color_text,onValueChange:b=>i({...n,color_text:b}),children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsx(Re,{children:w.map(b=>e.jsx(le,{value:b,children:b},b))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"全局日志级别"}),e.jsxs(Le,{value:n.log_level,onValueChange:b=>i({...n,log_level:b}),children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsx(Re,{children:N.map(b=>e.jsx(le,{value:b,children:b},b))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"控制台日志级别"}),e.jsxs(Le,{value:n.console_log_level,onValueChange:b=>i({...n,console_log_level:b}),children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsx(Re,{children:N.map(b=>e.jsx(le,{value:b,children:b},b))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"文件日志级别"}),e.jsxs(Le,{value:n.file_log_level,onValueChange:b=>i({...n,file_log_level:b}),children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsx(Re,{children:N.map(b=>e.jsx(le,{value:b,children:b},b))})]})]})]})]}),e.jsxs("div",{children:[e.jsx(E,{className:"mb-2 block",children:"完全屏蔽的库"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(re,{value:c,onChange:b=>u(b.target.value),placeholder:"输入库名",className:"flex-1",onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),f())}}),e.jsx(k,{onClick:f,size:"sm",className:"flex-shrink-0",children:e.jsx(lt,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:n.suppress_libraries.map(b=>e.jsxs("div",{className:"flex items-center gap-1 bg-secondary px-3 py-1 rounded-md",children:[e.jsx("span",{className:"text-sm",children:b}),e.jsx(k,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0",onClick:()=>p(b),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},b))})]}),e.jsxs("div",{children:[e.jsx(E,{className:"mb-2 block",children:"特定库的日志级别"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(re,{value:c,onChange:b=>u(b.target.value),placeholder:"输入库名",className:"flex-1"}),e.jsxs(Le,{value:x,onValueChange:h,children:[e.jsx(Oe,{className:"w-32",children:e.jsx(Ue,{})}),e.jsx(Re,{children:N.map(b=>e.jsx(le,{value:b,children:b},b))})]}),e.jsx(k,{onClick:g,size:"sm",children:e.jsx(lt,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:Object.entries(n.library_log_levels).map(([b,L])=>e.jsxs("div",{className:"flex items-center justify-between bg-secondary px-3 py-2 rounded-md",children:[e.jsx("span",{className:"text-sm font-medium",children:b}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:L}),e.jsx(k,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>v(b),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]})]},b))})]})]})}),P2=Ts.memo(function({config:n,onChange:i}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"调试配置"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{children:"显示 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否在日志中显示提示词"})]}),e.jsx(Pe,{checked:n.show_prompt,onCheckedChange:c=>i({...n,show_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{children:"显示回复器 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的提示词"})]}),e.jsx(Pe,{checked:n.show_replyer_prompt,onCheckedChange:c=>i({...n,show_replyer_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{children:"显示回复器推理"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的推理过程"})]}),e.jsx(Pe,{checked:n.show_replyer_reasoning,onCheckedChange:c=>i({...n,show_replyer_reasoning:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{children:"显示 Jargon Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示术语相关的提示词"})]}),e.jsx(Pe,{checked:n.show_jargon_prompt,onCheckedChange:c=>i({...n,show_jargon_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{children:"显示记忆检索 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示记忆检索相关的提示词"})]}),e.jsx(Pe,{checked:n.show_memory_prompt,onCheckedChange:c=>i({...n,show_memory_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{children:"显示 Planner Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 Planner 的提示词和原始返回结果"})]}),e.jsx(Pe,{checked:n.show_planner_prompt,onCheckedChange:c=>i({...n,show_planner_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{children:"显示 LPMM 相关文段"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 LPMM 知识库找到的相关文段日志"})]}),e.jsx(Pe,{checked:n.show_lpmm_paragraph,onCheckedChange:c=>i({...n,show_lpmm_paragraph:c})})]})]})]})}),G2=Ts.memo(function({config:n,onChange:i}){const[c,u]=m.useState(""),[x,h]=m.useState(""),f=()=>{c&&!n.auth_token.includes(c)&&(i({...n,auth_token:[...n.auth_token,c]}),u(""))},p=N=>{i({...n,auth_token:n.auth_token.filter((y,w)=>w!==N)})},g=()=>{x&&!n.api_server_allowed_api_keys.includes(x)&&(i({...n,api_server_allowed_api_keys:[...n.api_server_allowed_api_keys,x]}),h(""))},v=N=>{i({...n,api_server_allowed_api_keys:n.api_server_allowed_api_keys.filter((y,w)=>w!==N)})};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"旧版 API 认证令牌"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"用于旧版 API 验证,为空则不启用验证"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(re,{value:c,onChange:N=>u(N.target.value),placeholder:"输入认证令牌",onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),f())}}),e.jsx(k,{onClick:f,size:"sm",children:e.jsx(lt,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:n.auth_token.map((N,y)=>e.jsxs("div",{className:"flex items-center justify-between bg-secondary px-3 py-2 rounded-md",children:[e.jsx("span",{className:"text-sm font-mono",children:N}),e.jsx(k,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>p(y),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},y))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"新版 API Server 配置"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{children:"启用新版 API Server"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否启用额外的新版 API Server(额外监听端口)"})]}),e.jsx(Pe,{checked:n.enable_api_server,onCheckedChange:N=>i({...n,enable_api_server:N})})]}),n.enable_api_server&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"主机地址"}),e.jsx(re,{value:n.api_server_host,onChange:N=>i({...n,api_server_host:N.target.value}),placeholder:"0.0.0.0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"端口号"}),e.jsx(re,{type:"number",value:n.api_server_port,onChange:N=>i({...n,api_server_port:parseInt(N.target.value)}),placeholder:"8090"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{checked:n.api_server_use_wss,onCheckedChange:N=>i({...n,api_server_use_wss:N})}),e.jsx(E,{children:"启用 WSS 安全连接"})]}),n.api_server_use_wss&&e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"SSL 证书文件路径"}),e.jsx(re,{value:n.api_server_cert_file,onChange:N=>i({...n,api_server_cert_file:N.target.value}),placeholder:"cert.pem"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"SSL 密钥文件路径"}),e.jsx(re,{value:n.api_server_key_file,onChange:N=>i({...n,api_server_key_file:N.target.value}),placeholder:"key.pem"})]})]}),e.jsxs("div",{children:[e.jsx(E,{className:"mb-2 block",children:"允许的 API Key 列表"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"为空则允许所有连接"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(re,{value:x,onChange:N=>h(N.target.value),placeholder:"输入 API Key",onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),g())}}),e.jsx(k,{onClick:g,size:"sm",children:e.jsx(lt,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:n.api_server_allowed_api_keys.map((N,y)=>e.jsxs("div",{className:"flex items-center justify-between bg-secondary px-3 py-2 rounded-md",children:[e.jsx("span",{className:"text-sm font-mono",children:N}),e.jsx(k,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>v(y),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},y))})]})]})]})]})]})}),q2=Ts.memo(function({config:n,onChange:i}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"统计信息"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{children:"启用统计信息发送"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"发送匿名统计信息,帮助我们了解全球有多少只麦麦在运行"})]}),e.jsx(Pe,{checked:n.enable,onCheckedChange:c=>i({...n,enable:c})})]})]})}),F2=Ts.memo(function({emojiConfig:n,memoryConfig:i,toolConfig:c,onEmojiChange:u,onMemoryChange:x,onToolChange:h}){return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"工具设置"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"enable_tool",checked:c.enable_tool,onCheckedChange:f=>h({...c,enable_tool:f})}),e.jsx(E,{htmlFor:"enable_tool",className:"cursor-pointer",children:"启用工具系统"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"允许麦麦使用各种工具来增强功能"})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"记忆设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"max_agent_iterations",children:"记忆思考深度"}),e.jsx(re,{id:"max_agent_iterations",type:"number",min:"1",value:i.max_agent_iterations,onChange:f=>x({...i,max_agent_iterations:parseInt(f.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"最低为 1(不深入思考)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"agent_timeout_seconds",children:"最长回忆时间(秒)"}),e.jsx(re,{id:"agent_timeout_seconds",type:"number",min:"1",step:"0.1",value:i.agent_timeout_seconds??120,onChange:f=>x({...i,agent_timeout_seconds:parseFloat(f.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"记忆检索的超时时间,避免过长的等待"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"enable_jargon_detection",checked:i.enable_jargon_detection??!0,onCheckedChange:f=>x({...i,enable_jargon_detection:f})}),e.jsx(E,{htmlFor:"enable_jargon_detection",className:"cursor-pointer",children:"启用黑话识别"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"记忆检索过程中是否启用黑话识别"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"global_memory",checked:i.global_memory??!1,onCheckedChange:f=>x({...i,global_memory:f})}),e.jsx(E,{htmlFor:"global_memory",className:"cursor-pointer",children:"全局记忆查询"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"允许记忆检索在所有聊天记录中进行全局查询(忽略当前聊天流)"})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"表情包设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsx(re,{id:"emoji_chance",type:"number",step:"0.1",min:"0",max:"1",value:n.emoji_chance,onChange:f=>u({...n,emoji_chance:parseFloat(f.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"范围 0-1,越大越容易发送表情包"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"max_reg_num",children:"最大注册数量"}),e.jsx(re,{id:"max_reg_num",type:"number",min:"1",value:n.max_reg_num,onChange:f=>u({...n,max_reg_num:parseInt(f.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦最多可以注册的表情包数量"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(re,{id:"check_interval",type:"number",min:"1",value:n.check_interval,onChange:f=>u({...n,check_interval:parseInt(f.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"检查表情包(注册、破损、删除)的时间间隔"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"do_replace",checked:n.do_replace,onCheckedChange:f=>u({...n,do_replace:f})}),e.jsx(E,{htmlFor:"do_replace",className:"cursor-pointer",children:"达到最大数量时替换表情包"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"steal_emoji",checked:n.steal_emoji,onCheckedChange:f=>u({...n,steal_emoji:f})}),e.jsx(E,{htmlFor:"steal_emoji",className:"cursor-pointer",children:"偷取表情包"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"允许麦麦将看到的表情包据为己有"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"content_filtration",checked:n.content_filtration,onCheckedChange:f=>u({...n,content_filtration:f})}),e.jsx(E,{htmlFor:"content_filtration",className:"cursor-pointer",children:"启用表情包过滤"})]}),n.content_filtration&&e.jsxs("div",{className:"grid gap-2 pl-6 border-l-2 border-primary/20",children:[e.jsx(E,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(re,{id:"filtration_prompt",value:n.filtration_prompt,onChange:f=>u({...n,filtration_prompt:f.target.value}),placeholder:"符合公序良俗"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只有符合此要求的表情包才会被保存"})]})]})]})})]})}),V2=Ts.memo(function({member:n,groupIndex:i,memberIndex:c,availableChatIds:u,onUpdate:x,onRemove:h}){const f=u.includes(n)||n==="*",[p,g]=m.useState(!f);return e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 flex gap-2",children:p?e.jsxs(e.Fragment,{children:[e.jsx(re,{value:n,onChange:v=>x(i,c,v.target.value),placeholder:'输入 "*" 或 "qq:123456:group"',className:"flex-1"}),u.length>0&&e.jsx(k,{size:"sm",variant:"outline",onClick:()=>g(!1),title:"切换到下拉选择",children:"下拉"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Le,{value:n,onValueChange:v=>x(i,c,v),children:[e.jsx(Oe,{className:"flex-1",children:e.jsx(Ue,{placeholder:"选择聊天流"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"*",children:"* (全局共享)"}),u.map((v,N)=>e.jsx(le,{value:v,children:v},N))]})]}),e.jsx(k,{size:"sm",variant:"outline",onClick:()=>g(!0),title:"切换到手动输入",children:"输入"})]})}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:['确定要删除组成员 "',n||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>h(i,c),children:"删除"})]})]})]})]})}),K2=Ts.memo(function({config:n,onChange:i}){const c=()=>{i({...n,learning_list:[...n.learning_list,["","enable","enable","1.0"]]})},u=y=>{i({...n,learning_list:n.learning_list.filter((w,b)=>b!==y)})},x=(y,w,b)=>{const L=[...n.learning_list];L[y][w]=b,i({...n,learning_list:L})},h=({rule:y})=>{const w=`["${y[0]}", "${y[1]}", "${y[2]}", "${y[3]}"]`;return e.jsxs(Xa,{children:[e.jsx(Za,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",children:[e.jsx(Xt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(Ia,{className:"w-80 sm:w-96",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:w}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},f=()=>{i({...n,expression_groups:[...n.expression_groups,[]]})},p=y=>{i({...n,expression_groups:n.expression_groups.filter((w,b)=>b!==y)})},g=y=>{const w=[...n.expression_groups];w[y]=[...w[y],""],i({...n,expression_groups:w})},v=(y,w)=>{const b=[...n.expression_groups];b[y]=b[y].filter((L,D)=>D!==w),i({...n,expression_groups:b})},N=(y,w,b)=>{const L=[...n.expression_groups];L[y][w]=b,i({...n,expression_groups:L})};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"表达学习配置"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"配置麦麦如何学习和使用表达方式"})]}),e.jsxs(k,{onClick:c,size:"sm",variant:"outline",children:[e.jsx(lt,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),e.jsxs("div",{className:"space-y-4",children:[n.learning_list.map((y,w)=>{const b=n.learning_list.some((S,C)=>C!==w&&S[0]===""),L=y[0]==="",D=y[0].split(":"),T=D[0]||"qq",F=D[1]||"",O=D[2]||"group";return e.jsxs("div",{className:"rounded-lg border p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["规则 ",w+1," ",L&&"(全局配置)"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{rule:y}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:["确定要删除学习规则 ",w+1," 吗?此操作无法撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>u(w),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(Le,{value:L?"global":"specific",onValueChange:S=>{S==="global"?x(w,0,""):x(w,0,"qq::group")},disabled:b&&!L,children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"global",children:"全局配置"}),e.jsx(le,{value:"specific",disabled:b&&!L,children:"详细配置"})]})]}),b&&!L&&e.jsx("p",{className:"text-xs text-amber-600",children:"已存在全局配置,无法创建新的全局配置"})]}),!L&&e.jsxs("div",{className:"grid gap-4 p-3 sm:p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Le,{value:T,onValueChange:S=>{x(w,0,`${S}:${F}:${O}`)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"qq",children:"QQ"}),e.jsx(le,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(re,{value:F,onChange:S=>{x(w,0,`${T}:${S.target.value}:${O}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Le,{value:O,onValueChange:S=>{x(w,0,`${T}:${F}:${S}`)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"group",children:"群组(group)"}),e.jsx(le,{value:"private",children:"私聊(private)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前聊天流 ID:",y[0]||"(未设置)"]})]}),e.jsx("div",{className:"grid gap-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(E,{className:"text-xs font-medium",children:"使用学到的表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦使用从聊天中学到的表达方式"})]}),e.jsx(Pe,{checked:y[1]==="enable",onCheckedChange:S=>x(w,1,S?"enable":"disable")})]})}),e.jsx("div",{className:"grid gap-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(E,{className:"text-xs font-medium",children:"学习表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦从聊天中学习新的表达方式"})]}),e.jsx(Pe,{checked:y[2]==="enable",onCheckedChange:S=>x(w,2,S?"enable":"disable")})]})}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{className:"text-xs font-medium",children:"学习强度"}),e.jsx(re,{type:"number",step:"0.1",min:"0",max:"5",value:y[3],onChange:S=>{const C=parseFloat(S.target.value);isNaN(C)||x(w,3,Math.max(0,Math.min(5,C)).toFixed(1))},className:"w-20 h-8 text-xs"})]}),e.jsx(Na,{value:[parseFloat(y[3])||1],onValueChange:S=>x(w,3,S[0].toFixed(1)),min:0,max:5,step:.1,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"0 (不学习)"}),e.jsx("span",{children:"2.5"}),e.jsx("span",{children:"5.0 (快速学习)"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"影响学习频率,最短学习间隔 = 300/学习强度(秒)"})]})]})]},w)}),n.learning_list.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无学习规则,点击"添加规则"开始配置'})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"表达反思配置"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"配置麦麦主动向管理员询问表达方式是否合适的功能"})]}),e.jsx(Pe,{checked:n.reflect,onCheckedChange:y=>i({...n,reflect:y})})]}),n.reflect&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4 space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("span",{className:"text-sm font-medium",children:"反思操作员"})}),e.jsx("div",{className:"space-y-4",children:(()=>{const w=(n.reflect_operator_id||"").split(":"),b=w[0]||"qq",L=w[1]||"",D=w[2]||"private";return e.jsxs("div",{className:"grid gap-4 p-3 sm:p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Le,{value:b,onValueChange:T=>{i({...n,reflect_operator_id:`${T}:${L}:${D}`})},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"qq",children:"QQ"}),e.jsx(le,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"用户/群 ID"}),e.jsx(re,{value:L,onChange:T=>{i({...n,reflect_operator_id:`${b}:${T.target.value}:${D}`})},placeholder:"输入 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Le,{value:D,onValueChange:T=>{i({...n,reflect_operator_id:`${b}:${L}:${T}`})},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"private",children:"私聊(private)"}),e.jsx(le,{value:"group",children:"群组(group)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前操作员 ID:",n.reflect_operator_id||"(未设置)"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦会向此操作员询问表达方式是否合适"})]})})()})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"允许反思的聊天流"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"只有在此列表中的聊天流才会提出问题并跟踪。如果列表为空,则所有聊天流都可以进行表达反思"})]}),e.jsxs(k,{onClick:()=>{i({...n,allow_reflect:[...n.allow_reflect||[],"qq::group"]})},size:"sm",variant:"outline",children:[e.jsx(lt,{className:"h-4 w-4 mr-1"}),"添加聊天流"]})]}),e.jsxs("div",{className:"space-y-2",children:[(n.allow_reflect||[]).map((y,w)=>{const b=y.split(":"),L=b[0]||"qq",D=b[1]||"",T=b[2]||"group";return e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-muted/50",children:[e.jsxs(Le,{value:L,onValueChange:F=>{const O=[...n.allow_reflect];O[w]=`${F}:${D}:${T}`,i({...n,allow_reflect:O})},children:[e.jsx(Oe,{className:"w-24",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"qq",children:"QQ"}),e.jsx(le,{value:"wx",children:"微信"})]})]}),e.jsx(re,{value:D,onChange:F=>{const O=[...n.allow_reflect];O[w]=`${L}:${F.target.value}:${T}`,i({...n,allow_reflect:O})},placeholder:"ID",className:"flex-1 font-mono text-sm"}),e.jsxs(Le,{value:T,onValueChange:F=>{const O=[...n.allow_reflect];O[w]=`${L}:${D}:${F}`,i({...n,allow_reflect:O})},children:[e.jsx(Oe,{className:"w-32",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"group",children:"群组"}),e.jsx(le,{value:"private",children:"私聊"})]})]}),e.jsx(k,{onClick:()=>{i({...n,allow_reflect:n.allow_reflect.filter((F,O)=>O!==w)})},size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})]},w)}),(!n.allow_reflect||n.allow_reflect.length===0)&&e.jsx("div",{className:"text-center py-4 text-muted-foreground text-sm",children:"列表为空,所有聊天流都可以进行表达反思"})]})]})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"表达共享组配置"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"配置不同聊天流之间如何共享学到的表达方式"})]}),e.jsxs(k,{onClick:f,size:"sm",variant:"outline",children:[e.jsx(lt,{className:"h-4 w-4 mr-1"}),"添加共享组"]})]}),e.jsxs("div",{className:"space-y-4",children:[n.expression_groups.map((y,w)=>{const b=n.learning_list.map(L=>L[0]).filter(L=>L!=="");return e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["共享组 ",w+1,y.length===1&&y[0]==="*"&&"(全局共享)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{onClick:()=>g(w),size:"sm",variant:"outline",children:e.jsx(lt,{className:"h-4 w-4"})}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:["确定要删除共享组 ",w+1," 吗?此操作无法撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>p(w),children:"删除"})]})]})]})]})]}),e.jsx("div",{className:"space-y-2",children:y.map((L,D)=>e.jsx(V2,{member:L,groupIndex:w,memberIndex:D,availableChatIds:b,onUpdate:N,onRemove:v},`${w}-${D}`))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'提示:可以从下拉框选择已配置的聊天流,或手动输入。输入 "*" 启用全局共享'})]},w)}),n.expression_groups.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无共享组,点击"添加共享组"开始配置'})]})]})}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"黑话设置"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"all_global_jargon",checked:n.all_global_jargon??!1,onCheckedChange:y=>i({...n,all_global_jargon:y})}),e.jsx(E,{htmlFor:"all_global_jargon",className:"cursor-pointer",children:"全局黑话模式"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"开启后,新增的黑话将默认设为全局(所有聊天流共享)。关闭后,已记录的全局黑话不会改变,需要手动删除。"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"enable_jargon_explanation",checked:n.enable_jargon_explanation??!0,onCheckedChange:y=>i({...n,enable_jargon_explanation:y})}),e.jsx(E,{htmlFor:"enable_jargon_explanation",className:"cursor-pointer",children:"启用黑话解释"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"在回复前尝试对上下文中的黑话进行解释。关闭可减少一次LLM调用,仅影响回复前的黑话匹配与解释,不影响黑话学习。"})]}),e.jsxs("div",{children:[e.jsx(E,{htmlFor:"jargon_mode",children:"黑话解释来源模式"}),e.jsxs(Le,{value:n.jargon_mode??"context",onValueChange:y=>i({...n,jargon_mode:y}),children:[e.jsx(Oe,{id:"jargon_mode",className:"mt-2",children:e.jsx(Ue,{placeholder:"选择黑话解释来源"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"context",children:"上下文模式(自动匹配黑话)"}),e.jsx(le,{value:"planner",children:"Planner模式(使用unknown_words列表)"})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["上下文模式:使用上下文自动匹配黑话并解释",e.jsx("br",{}),"Planner模式:仅使用Planner在reply动作中给出的unknown_words列表进行黑话检索"]})]})]})]})});function Q2({regex:l,reaction:n,onRegexChange:i,onReactionChange:c}){const[u,x]=m.useState(!1),[h,f]=m.useState(""),[p,g]=m.useState(null),[v,N]=m.useState(""),[y,w]=m.useState({}),[b,L]=m.useState(""),D=m.useRef(null),[T,F]=m.useState("build"),O=M=>M.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),S=(M,Z=0)=>{const G=D.current;if(!G)return;const ce=G.selectionStart||0,de=G.selectionEnd||0,be=l.substring(0,ce)+M+l.substring(de);i(be),setTimeout(()=>{const me=ce+M.length+Z;G.setSelectionRange(me,me),G.focus()},0)};m.useEffect(()=>{if(!l||!h){p!==null&&g(null),Object.keys(y).length>0&&w({}),b!==n&&L(n),v!==""&&N("");return}try{const M=O(l),Z=new RegExp(M,"g"),G=h.match(Z);g(G),N("");const de=new RegExp(M).exec(h);if(de&&de.groups){w(de.groups);let be=n;Object.entries(de.groups).forEach(([me,pe])=>{be=be.replace(new RegExp(`\\[${me}\\]`,"g"),pe||"")}),L(be)}else w({}),L(n)}catch(M){N(M.message),g(null),w({}),L(n)}},[l,h,n,p,y,b,v]);const C=()=>{if(!h||!p||p.length===0)return e.jsx("span",{className:"text-muted-foreground",children:h||"请输入测试文本"});try{const M=O(l),Z=new RegExp(M,"g");let G=0;const ce=[];let de;for(;(de=Z.exec(h))!==null;)de.index>G&&ce.push(e.jsx("span",{children:h.substring(G,de.index)},`text-${G}`)),ce.push(e.jsx("span",{className:"bg-yellow-200 dark:bg-yellow-900 font-semibold",children:de[0]},`match-${de.index}`)),G=de.index+de[0].length;return G)",desc:"Python风格命名捕获组",moveCursor:-1},{label:"非捕获组",pattern:"(?:)",desc:"分组但不保存匹配结果",moveCursor:-1}]},{category:"字符类",items:[{label:"字符集",pattern:"[]",desc:"匹配括号内的任意字符",moveCursor:-1},{label:"排除字符",pattern:"[^]",desc:"匹配不在括号内的字符",moveCursor:-1},{label:"范围",pattern:"[a-z]",desc:"匹配a到z的字符"},{label:"中文字符",pattern:"[\\u4e00-\\u9fa5]",desc:"匹配中文汉字"}]},{category:"常用模板",items:[{label:"捕获词语",pattern:"(?P\\S+)",desc:"捕获一个词语"},{label:"捕获句子",pattern:"(?P.+)",desc:"捕获整个句子"},{label:"捕获数字",pattern:"(?P\\d+)",desc:"捕获一个或多个数字"},{label:"可选词语",pattern:"(?:词语1|词语2)",desc:"匹配多个可选项之一"}]}];return e.jsxs(Is,{open:u,onOpenChange:x,children:[e.jsx(Bo,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",children:[e.jsx(Dm,{className:"h-4 w-4 mr-1"}),"正则编辑器"]})}),e.jsxs(Rs,{className:"max-w-[95vw] sm:max-w-[900px] max-h-[90vh]",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"正则表达式编辑器"}),e.jsx(Zs,{className:"text-sm",children:"使用可视化工具构建正则表达式,并实时测试效果"})]}),e.jsx(Je,{className:"max-h-[calc(90vh-120px)]",children:e.jsxs(da,{value:T,onValueChange:M=>F(M),className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2",children:[e.jsx(Xe,{value:"build",children:"🔧 构建器"}),e.jsx(Xe,{value:"test",children:"🧪 测试器"})]}),e.jsxs(ys,{value:"build",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"text-sm font-medium",children:"正则表达式"}),e.jsx(re,{ref:D,value:l,onChange:M=>i(M.target.value),className:"font-mono text-sm",placeholder:"点击下方按钮构建正则表达式..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"text-sm font-medium",children:"Reaction 内容"}),e.jsx(Ys,{value:n,onChange:M=>c(M.target.value),placeholder:"使用 [捕获组名] 引用捕获的内容...",rows:3,className:"text-sm"})]}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[P.map(M=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-xs font-semibold text-primary",children:M.category}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:M.items.map(Z=>e.jsx(k,{variant:"outline",size:"sm",className:"justify-start h-auto py-2 px-3",onClick:()=>S(Z.pattern,Z.moveCursor||0),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsx("span",{className:"text-xs font-medium",children:Z.label}),e.jsx("code",{className:"ml-auto text-xs bg-muted px-1.5 py-0.5 rounded font-mono",children:Z.pattern})]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-0.5",children:Z.desc})]})},Z.label))})]},M.category)),e.jsxs("div",{className:"space-y-2 border-t pt-4",children:[e.jsx("h5",{className:"text-xs font-semibold text-primary",children:"完整示例模板"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>i("^(?P\\S{1,20})是这样的$"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsxs("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:["^(?P\\S","{1,20}",")是这样的$"]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"匹配「某事物是这样的」并捕获事物名称"})]})}),e.jsx(k,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>i("(?:[^,。.\\s]+,\\s*)?我(?:也)?[没沒]要求你\\s*(?P.+?)[.。,,]?$"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsx("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:"(?:[^,。.\\s]+,\\s*)?我(?:也)?[没沒]要求你\\s*(?P.+?)[.。,,]?$"}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"匹配「我没要求你做某事」并捕获具体行为"})]})}),e.jsx(k,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>i("(?P.+?)(?:是|为什么|怎么)"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsx("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:"(?P.+?)(?:是|为什么|怎么)"}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"捕获问题主题词"})]})})]})]})]}),e.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3 space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-blue-900 dark:text-blue-100",children:"💡 使用提示"}),e.jsxs("ul",{className:"text-xs text-blue-700 dark:text-blue-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"点击输入框设置光标位置,然后点击按钮插入模式"}),e.jsxs("li",{children:["命名捕获组格式:",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"(?P<名称>模式)"})]}),e.jsxs("li",{children:["在 reaction 中使用 ",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"[名称]"})," 引用捕获的内容"]}),e.jsx("li",{children:"切换到测试器标签页验证正则表达式效果"})]})]})]}),e.jsxs(ys,{value:"test",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"text-sm font-medium",children:"当前正则表达式"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:l||"(未设置)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"test-text",className:"text-sm font-medium",children:"测试文本"}),e.jsx(Ys,{id:"test-text",value:h,onChange:M=>f(M.target.value),placeholder:`在此输入要测试的文本... 例如:打游戏是这样的`,className:"min-h-[100px] text-sm"})]}),v&&e.jsxs("div",{className:"rounded-md bg-destructive/10 border border-destructive/20 p-3",children:[e.jsx("p",{className:"text-sm text-destructive font-medium",children:"正则表达式错误"}),e.jsx("p",{className:"text-xs text-destructive/80 mt-1",children:v})]}),!v&&h&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:p&&p.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-green-500"}),e.jsxs("span",{className:"text-sm font-medium text-green-600 dark:text-green-400",children:["匹配成功 (",p.length," 处)"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-gray-400"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"无匹配"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"text-sm font-medium",children:"匹配高亮"}),e.jsx(Je,{className:"h-40 rounded-md bg-muted p-3",children:e.jsx("div",{className:"text-sm break-words",children:C()})})]}),Object.keys(y).length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"text-sm font-medium",children:"命名捕获组"}),e.jsx(Je,{className:"h-32 rounded-md border p-3",children:e.jsx("div",{className:"space-y-2",children:Object.entries(y).map(([M,Z])=>e.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[e.jsxs("span",{className:"font-mono font-semibold text-primary min-w-[80px]",children:["[",M,"]"]}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("span",{className:"font-mono bg-muted px-2 py-0.5 rounded",children:Z})]},M))})})]}),Object.keys(y).length>0&&n&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"text-sm font-medium",children:"Reaction 替换预览"}),e.jsx(Je,{className:"h-48 rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3",children:e.jsx("div",{className:"text-sm break-words",children:b})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"reaction 中的 [name] 已被替换为对应的捕获组值"})]})]}),e.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3 space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-blue-900 dark:text-blue-100",children:"💡 测试说明"}),e.jsxs("ul",{className:"text-xs text-blue-700 dark:text-blue-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"匹配的文本会以黄色背景高亮显示"}),e.jsx("li",{children:"命名捕获组的值会显示在下方列表中"}),e.jsx("li",{children:"Reaction 替换预览显示最终生成的反应内容"}),e.jsx("li",{children:"如需修改正则,切换回构建器标签页"})]})]})]})]})})]})]})}const Y2=Ts.memo(function({keywordReactionConfig:n,responsePostProcessConfig:i,chineseTypoConfig:c,responseSplitterConfig:u,onKeywordReactionChange:x,onResponsePostProcessChange:h,onChineseTypoChange:f,onResponseSplitterChange:p}){const g=()=>{x({...n,regex_rules:[...n.regex_rules,{regex:[""],reaction:""}]})},v=S=>{x({...n,regex_rules:n.regex_rules.filter((C,P)=>P!==S)})},N=(S,C,P)=>{const M=[...n.regex_rules];C==="regex"&&typeof P=="string"?M[S]={...M[S],regex:[P]}:C==="reaction"&&typeof P=="string"&&(M[S]={...M[S],reaction:P}),x({...n,regex_rules:M})},y=()=>{x({...n,keyword_rules:[...n.keyword_rules,{keywords:[],reaction:""}]})},w=S=>{x({...n,keyword_rules:n.keyword_rules.filter((C,P)=>P!==S)})},b=(S,C,P)=>{const M=[...n.keyword_rules];typeof P=="string"&&(M[S]={...M[S],reaction:P}),x({...n,keyword_rules:M})},L=S=>{const C=[...n.keyword_rules];C[S]={...C[S],keywords:[...C[S].keywords||[],""]},x({...n,keyword_rules:C})},D=(S,C)=>{const P=[...n.keyword_rules];P[S]={...P[S],keywords:(P[S].keywords||[]).filter((M,Z)=>Z!==C)},x({...n,keyword_rules:P})},T=(S,C,P)=>{const M=[...n.keyword_rules],Z=[...M[S].keywords||[]];Z[C]=P,M[S]={...M[S],keywords:Z},x({...n,keyword_rules:M})},F=({rule:S})=>{const C=`{ regex = [${(S.regex||[]).map(P=>`"${P}"`).join(", ")}], reaction = "${S.reaction}" }`;return e.jsxs(Xa,{children:[e.jsx(Za,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",children:[e.jsx(Xt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(Ia,{className:"w-[95vw] sm:w-[500px]",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx(Je,{className:"h-60 rounded-md bg-muted p-3",children:e.jsx("pre",{className:"font-mono text-xs break-all",children:C})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},O=({rule:S})=>{const C=`[[keyword_reaction.keyword_rules]] keywords = [${(S.keywords||[]).map(P=>`"${P}"`).join(", ")}] reaction = "${S.reaction}"`;return e.jsxs(Xa,{children:[e.jsx(Za,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",children:[e.jsx(Xt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(Ia,{className:"w-[95vw] sm:w-[500px]",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx(Je,{className:"h-60 rounded-md bg-muted p-3",children:e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all",children:C})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"关键词反应配置"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"配置触发特定反应的关键词和正则表达式规则"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-semibold",children:"正则表达式规则"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"使用正则表达式匹配消息内容"})]}),e.jsxs(k,{onClick:g,size:"sm",variant:"outline",children:[e.jsx(lt,{className:"h-4 w-4 mr-1"}),"添加正则规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[n.regex_rules.map((S,C)=>e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["正则规则 ",C+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q2,{regex:S.regex&&S.regex[0]||"",reaction:S.reaction,onRegexChange:P=>N(C,"regex",P),onReactionChange:P=>N(C,"reaction",P)}),e.jsx(F,{rule:S}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:["确定要删除正则规则 ",C+1," 吗?此操作无法撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>v(C),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"正则表达式(Python 语法)"}),e.jsx(re,{value:S.regex&&S.regex[0]||"",onChange:P=>N(C,"regex",P.target.value),placeholder:"例如:^(?P\\\\S{1,20})是这样的$ (点击正则编辑器按钮可视化构建)",className:"font-mono text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'支持命名捕获组 (?Ppattern),可在 reaction 中使用 [name] 引用。点击"正则编辑器"可视化构建和测试!'})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(Ys,{value:S.reaction,onChange:P=>N(C,"reaction",P.target.value),placeholder:`触发后麦麦的反应... 可以使用 [捕获组名] 来引用正则表达式中的内容`,rows:3,className:"text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"使用 [捕获组名] 引用正则表达式中的命名捕获组,例如 [n] 会被替换为捕获的内容"})]})]})]},C)),n.regex_rules.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无正则规则,点击"添加正则规则"开始配置'})]})]}),e.jsxs("div",{className:"space-y-4 border-t pt-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-semibold",children:"关键词规则"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"使用关键词列表匹配消息内容"})]}),e.jsxs(k,{onClick:y,size:"sm",variant:"outline",children:[e.jsx(lt,{className:"h-4 w-4 mr-1"}),"添加关键词规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[n.keyword_rules.map((S,C)=>e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["关键词规则 ",C+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{rule:S}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:["确定要删除关键词规则 ",C+1," 吗?此操作无法撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>w(C),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{className:"text-xs font-medium",children:"关键词列表"}),e.jsxs(k,{onClick:()=>L(C),size:"sm",variant:"ghost",children:[e.jsx(lt,{className:"h-3 w-3 mr-1"}),"添加关键词"]})]}),e.jsxs("div",{className:"space-y-2",children:[(S.keywords||[]).map((P,M)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{value:P,onChange:Z=>T(C,M,Z.target.value),placeholder:"关键词",className:"flex-1"}),e.jsx(k,{onClick:()=>D(C,M),size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})]},M)),(!S.keywords||S.keywords.length===0)&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-2",children:'暂无关键词,点击"添加关键词"开始配置'})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(Ys,{value:S.reaction,onChange:P=>b(C,"reaction",P.target.value),placeholder:"触发后麦麦的反应...",rows:3,className:"text-sm"})]})]})]},C)),n.keyword_rules.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无关键词规则,点击"添加关键词规则"开始配置'})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"回复后处理配置"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"enable_response_post_process",checked:i.enable_response_post_process,onCheckedChange:S=>h({...i,enable_response_post_process:S})}),e.jsx(E,{htmlFor:"enable_response_post_process",className:"cursor-pointer",children:"启用回复后处理"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"包括错别字生成器和回复分割器"})]}),i.enable_response_post_process&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t pt-6 space-y-4",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-4",children:[e.jsx(Pe,{id:"enable_chinese_typo",checked:c.enable,onCheckedChange:S=>f({...c,enable:S})}),e.jsx(E,{htmlFor:"enable_chinese_typo",className:"cursor-pointer font-semibold",children:"中文错别字生成器"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"为回复添加随机错别字,让麦麦的回复更自然"}),c.enable&&e.jsxs("div",{className:"grid gap-4 pl-6 border-l-2 border-primary/20",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"error_rate",className:"text-xs font-medium",children:"单字替换概率"}),e.jsx(re,{id:"error_rate",type:"number",step:"0.001",min:"0",max:"1",value:c.error_rate,onChange:S=>f({...c,error_rate:parseFloat(S.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"min_freq",className:"text-xs font-medium",children:"最小字频阈值"}),e.jsx(re,{id:"min_freq",type:"number",min:"0",value:c.min_freq,onChange:S=>f({...c,min_freq:parseInt(S.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"tone_error_rate",className:"text-xs font-medium",children:"声调错误概率"}),e.jsx(re,{id:"tone_error_rate",type:"number",step:"0.01",min:"0",max:"1",value:c.tone_error_rate,onChange:S=>f({...c,tone_error_rate:parseFloat(S.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"word_replace_rate",className:"text-xs font-medium",children:"整词替换概率"}),e.jsx(re,{id:"word_replace_rate",type:"number",step:"0.001",min:"0",max:"1",value:c.word_replace_rate,onChange:S=>f({...c,word_replace_rate:parseFloat(S.target.value)})})]})]})]})}),e.jsx("div",{className:"border-t pt-6 space-y-4",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-4",children:[e.jsx(Pe,{id:"enable_response_splitter",checked:u.enable,onCheckedChange:S=>p({...u,enable:S})}),e.jsx(E,{htmlFor:"enable_response_splitter",className:"cursor-pointer font-semibold",children:"回复分割器"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"控制回复的长度和句子数量"}),u.enable&&e.jsxs("div",{className:"grid gap-4 pl-6 border-l-2 border-primary/20",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"max_length",className:"text-xs font-medium",children:"最大长度"}),e.jsx(re,{id:"max_length",type:"number",min:"1",value:u.max_length,onChange:S=>p({...u,max_length:parseInt(S.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"回复允许的最大字符数"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"max_sentence_num",className:"text-xs font-medium",children:"最大句子数"}),e.jsx(re,{id:"max_sentence_num",type:"number",min:"1",value:u.max_sentence_num,onChange:S=>p({...u,max_sentence_num:parseInt(S.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"回复允许的最大句子数量"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"enable_kaomoji_protection",checked:u.enable_kaomoji_protection,onCheckedChange:S=>p({...u,enable_kaomoji_protection:S})}),e.jsx(E,{htmlFor:"enable_kaomoji_protection",className:"cursor-pointer",children:"启用颜文字保护"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"enable_overflow_return_all",checked:u.enable_overflow_return_all,onCheckedChange:S=>p({...u,enable_overflow_return_all:S})}),e.jsx(E,{htmlFor:"enable_overflow_return_all",className:"cursor-pointer",children:"超出时一次性返回全部"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"当句子数量超出限制时,合并后一次性返回所有内容"})]})]})})]})]})]})}),J2=Ts.memo(function({config:n,onChange:i}){const[c,u]=m.useState(""),[x,h]=m.useState(""),[f,p]=m.useState(!1),g=n.allowed_ips?n.allowed_ips.split(",").map(T=>T.trim()).filter(T=>T):[],v=n.trusted_proxies?n.trusted_proxies.split(",").map(T=>T.trim()).filter(T=>T):[],N=()=>{if(!c.trim())return;const T=[...g,c.trim()];i({...n,allowed_ips:T.join(",")}),u("")},y=T=>{const F=g.filter((O,S)=>S!==T);i({...n,allowed_ips:F.join(",")})},w=()=>{if(!x.trim())return;const T=[...v,x.trim()];i({...n,trusted_proxies:T.join(",")}),h("")},b=T=>{const F=v.filter((O,S)=>S!==T);i({...n,trusted_proxies:F.join(",")})},L=T=>{!T&&n.enabled?p(!0):i({...n,enabled:T})},D=()=>{i({...n,enabled:!1}),p(!1)};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"WebUI 服务配置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{checked:n.enabled,onCheckedChange:L}),e.jsx(E,{className:"cursor-pointer",children:"启用 WebUI"})]}),n.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"运行模式"}),e.jsxs(Le,{value:n.mode,onValueChange:T=>i({...n,mode:T}),children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:"选择运行模式"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"development",children:"开发模式"}),e.jsx(le,{value:"production",children:"生产模式"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"监听地址"}),e.jsx(re,{value:n.host,onChange:T=>i({...n,host:T.target.value}),placeholder:"0.0.0.0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"端口号"}),e.jsx(re,{type:"number",value:n.port,onChange:T=>i({...n,port:parseInt(T.target.value)}),placeholder:"8001"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"防爬虫模式"}),e.jsxs(Le,{value:n.anti_crawler_mode,onValueChange:T=>i({...n,anti_crawler_mode:T}),children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:"选择防爬虫模式"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"false",children:"禁用"}),e.jsx(le,{value:"basic",children:"基础(只记录不阻止)"}),e.jsx(le,{value:"loose",children:"宽松"}),e.jsx(le,{value:"strict",children:"严格"})]})]})]}),e.jsxs("div",{className:"grid gap-2 sm:col-span-2",children:[e.jsx(E,{children:"IP 白名单"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(re,{value:c,onChange:T=>u(T.target.value),onKeyDown:T=>{T.key==="Enter"&&(T.preventDefault(),N())},placeholder:"输入IP地址后按回车或点击添加"}),e.jsx(k,{type:"button",size:"sm",onClick:N,disabled:!c.trim(),children:e.jsx(lt,{className:"h-4 w-4"})})]}),g.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:g.map((T,F)=>e.jsxs(Te,{variant:"secondary",className:"flex items-center gap-1",children:[T,e.jsx("button",{type:"button",onClick:()=>y(F),className:"ml-1 hover:bg-destructive/20 rounded-full p-0.5",children:e.jsx(Da,{className:"h-3 w-3"})})]},F))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"支持精确IP、CIDR格式和通配符(如:127.0.0.1、192.168.1.0/24)"})]}),e.jsxs("div",{className:"grid gap-2 sm:col-span-2",children:[e.jsx(E,{children:"信任的代理 IP"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(re,{value:x,onChange:T=>h(T.target.value),onKeyDown:T=>{T.key==="Enter"&&(T.preventDefault(),w())},placeholder:"输入代理IP后按回车或点击添加"}),e.jsx(k,{type:"button",size:"sm",onClick:w,disabled:!x.trim(),children:e.jsx(lt,{className:"h-4 w-4"})})]}),v.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:v.map((T,F)=>e.jsxs(Te,{variant:"secondary",className:"flex items-center gap-1",children:[T,e.jsx("button",{type:"button",onClick:()=>b(F),className:"ml-1 hover:bg-destructive/20 rounded-full p-0.5",children:e.jsx(Da,{className:"h-3 w-3"})})]},F))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只有来自这些IP的X-Forwarded-For头才被信任"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{checked:n.trust_xff,onCheckedChange:T=>i({...n,trust_xff:T})}),e.jsx(E,{className:"cursor-pointer",children:"启用 X-Forwarded-For 代理解析"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{checked:n.secure_cookie,onCheckedChange:T=>i({...n,secure_cookie:T})}),e.jsx(E,{className:"cursor-pointer",children:"启用安全 Cookie(仅 HTTPS)"})]})]})]}),e.jsx(gs,{open:f,onOpenChange:p,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"警告:即将关闭 WebUI"}),e.jsxs(hs,{children:["关闭 WebUI 后,在您下次重启麦麦之前,WebUI 界面将无法访问。",e.jsx("br",{}),e.jsx("br",{}),"您需要通过修改配置文件或命令行重新启用 WebUI 才能再次访问此界面。",e.jsx("br",{}),e.jsx("br",{}),"确定要关闭 WebUI 吗?"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{variant:"destructive",onClick:D,children:"确认关闭"})]})]})})]})}),tn="/api/webui/config";async function tg(){const n=await(await we(`${tn}/bot`)).json();if(!n.success)throw new Error("获取配置数据失败");return n.config}async function Xl(){const n=await(await we(`${tn}/model`)).json();if(!n.success)throw new Error("获取模型配置数据失败");return n.config}async function ag(l){const i=await(await we(`${tn}/bot`,{method:"POST",body:JSON.stringify(l)})).json();if(!i.success)throw new Error(i.message||"保存配置失败")}async function X2(){const n=await(await we(`${tn}/bot/raw`)).json();if(!n.success)throw new Error("获取配置源代码失败");return n.content}async function Z2(l){const i=await(await we(`${tn}/bot/raw`,{method:"POST",body:JSON.stringify({raw_content:l})})).json();if(!i.success)throw new Error(i.message||"保存配置失败")}async function Li(l){const i=await(await we(`${tn}/model`,{method:"POST",body:JSON.stringify(l)})).json();if(!i.success)throw new Error(i.message||"保存配置失败")}async function W2(l,n){const c=await(await we(`${tn}/bot/section/${l}`,{method:"POST",body:JSON.stringify(n)})).json();if(!c.success)throw new Error(c.message||`保存配置节 ${l} 失败`)}async function Tm(l,n){const c=await(await we(`${tn}/model/section/${l}`,{method:"POST",body:JSON.stringify(n)})).json();if(!c.success)throw new Error(c.message||`保存配置节 ${l} 失败`)}async function e_(l,n="openai",i="/models"){const c=new URLSearchParams({provider_name:l,parser:n,endpoint:i}),u=await we(`/api/webui/models/list?${c}`);if(!u.ok){const h=await u.json().catch(()=>({}));throw new Error(h.detail||`获取模型列表失败 (${u.status})`)}const x=await u.json();if(!x.success)throw new Error("获取模型列表失败");return x.models}async function s_(l){const n=new URLSearchParams({provider_name:l}),i=await we(`/api/webui/models/test-connection-by-name?${n}`,{method:"POST"});if(!i.ok){const c=await i.json().catch(()=>({}));throw new Error(c.detail||`测试连接失败 (${i.status})`)}return await i.json()}const t_=Ar("relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),gt=m.forwardRef(({className:l,variant:n,...i},c)=>e.jsx("div",{ref:c,role:"alert",className:B(t_({variant:n}),l),...i}));gt.displayName="Alert";const _n=m.forwardRef(({className:l,...n},i)=>e.jsx("h5",{ref:i,className:B("mb-1 font-medium leading-none tracking-tight",l),...n}));_n.displayName="AlertTitle";const jt=m.forwardRef(({className:l,...n},i)=>e.jsx("div",{ref:i,className:B("text-sm [&_p]:leading-relaxed",l),...n}));jt.displayName="AlertDescription";const a_={name:"toml",startState:function(){return{inString:!1,stringType:"",lhs:!0,inArray:0}},token:function(l,n){let i;if(!n.inString&&(i=l.match(/^('''|"""|'|")/))&&(n.stringType=i[0],n.inString=!0),l.sol()&&!n.inString&&n.inArray===0&&(n.lhs=!0),n.inString){for(;n.inString;)if(l.match(n.stringType))n.inString=!1;else if(l.peek()==="\\")l.next(),l.next();else{if(l.eol())break;l.match(/^.[^\\\"\']*/)}return n.lhs?"property":"string"}else{if(n.inArray&&l.peek()==="]")return l.next(),n.inArray--,"bracket";if(n.lhs&&l.peek()==="["&&l.skipTo("]"))return l.next(),l.peek()==="]"&&l.next(),"atom";if(l.peek()==="#")return l.skipToEnd(),"comment";if(l.eatSpace())return null;if(n.lhs&&l.eatWhile(function(c){return c!="="&&c!=" "}))return"property";if(n.lhs&&l.peek()==="=")return l.next(),n.lhs=!1,null;if(!n.lhs&&l.match(/^\d\d\d\d[\d\-\:\.T]*Z/))return"atom";if(!n.lhs&&(l.match("true")||l.match("false")))return"atom";if(!n.lhs&&l.peek()==="[")return n.inArray++,l.next(),"bracket";if(!n.lhs&&l.match(/^\-?\d+(?:\.\d+)?/))return"number";l.eatSpace()||l.next()}return null},languageData:{commentTokens:{line:"#"}}},l_={python:[Zw()],json:[Ww(),e1()],toml:[Xw.define(a_)],text:[]};function Xj({value:l,onChange:n,language:i="text",readOnly:c=!1,height:u="400px",minHeight:x,maxHeight:h,placeholder:f,theme:p="dark",className:g=""}){const[v,N]=m.useState(!1);if(m.useEffect(()=>{N(!0)},[]),!v)return e.jsx("div",{className:`rounded-md border bg-muted animate-pulse ${g}`,style:{height:u,minHeight:x,maxHeight:h}});const y=[...l_[i]||[],Vp.lineWrapping];return c&&y.push(Vp.editable.of(!1)),e.jsx("div",{className:`rounded-md overflow-hidden border ${g}`,children:e.jsx(s1,{value:l,height:u,minHeight:x,maxHeight:h,theme:p==="dark"?t1:void 0,extensions:y,onChange:n,placeholder:f,basicSetup:{lineNumbers:!0,highlightActiveLineGutter:!0,highlightSpecialChars:!0,history:!0,foldGutter:!0,drawSelection:!0,dropCursor:!0,allowMultipleSelections:!0,indentOnInput:!0,syntaxHighlighting:!0,bracketMatching:!0,closeBrackets:!0,autocompletion:!0,rectangularSelection:!0,crosshairCursor:!0,highlightActiveLine:!0,highlightSelectionMatches:!0,closeBracketsKeymap:!0,defaultKeymap:!0,searchKeymap:!0,historyKeymap:!0,foldKeymap:!0,completionKeymap:!0,lintKeymap:!0}})})}function n_({id:l,index:n,itemType:i,itemFields:c,value:u,onChange:x,onRemove:h,disabled:f,canRemove:p,placeholder:g}){const{attributes:v,listeners:N,setNodeRef:y,transform:w,transition:b,isDragging:L}=Oj({id:l,disabled:f}),D={transform:Rj.Transform.toString(w),transition:b};return e.jsxs("div",{ref:y,style:D,className:B("flex items-start gap-2 group",L&&"opacity-50 z-50"),children:[e.jsx("button",{type:"button",className:B("flex-shrink-0 p-2 cursor-grab active:cursor-grabbing","text-muted-foreground hover:text-foreground transition-colors","opacity-0 group-hover:opacity-100 focus:opacity-100",f&&"cursor-not-allowed opacity-30"),...v,...N,children:e.jsx(hj,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1 min-w-0",children:i==="object"&&c?e.jsx(r_,{value:u,onChange:x,fields:c,disabled:f}):i==="number"?e.jsx(re,{type:"number",value:u??"",onChange:T=>x(parseFloat(T.target.value)||0),placeholder:g??`第 ${n+1} 项`,disabled:f,className:"font-mono"}):e.jsx(re,{type:"text",value:u??"",onChange:T=>x(T.target.value),placeholder:g??`第 ${n+1} 项`,disabled:f})}),e.jsx(k,{type:"button",variant:"ghost",size:"icon",onClick:h,disabled:f||!p,className:B("flex-shrink-0 text-muted-foreground hover:text-destructive","opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity"),children:e.jsx(ns,{className:"h-4 w-4"})})]})}function r_({value:l,onChange:n,fields:i,disabled:c}){const u=m.useCallback((h,f)=>{n({...l,[h]:f})},[l,n]),x=(h,f)=>{const p=l?.[h];if(f.type==="boolean"||f.type==="switch")return e.jsxs("div",{className:"flex items-center justify-between py-1",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(Pe,{checked:!!(p??f.default),onCheckedChange:g=>u(h,g),disabled:c})]});if(f.type==="slider"||f.type==="number"&&f.min!=null&&f.max!=null){const g=p??f.default??f.min??0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx("span",{className:"text-xs text-muted-foreground",children:g})]}),e.jsx(Na,{value:[g],onValueChange:v=>u(h,v[0]),min:f.min??0,max:f.max??100,step:f.step??1,disabled:c,className:"py-1"})]})}return f.type==="select"&&f.choices?e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsxs(Le,{value:String(p??f.default??""),onValueChange:g=>u(h,g),disabled:c,children:[e.jsx(Oe,{className:"h-8 text-sm",children:e.jsx(Ue,{placeholder:f.placeholder??"请选择"})}),e.jsx(Re,{children:f.choices.map(g=>e.jsx(le,{value:String(g),children:String(g)},String(g)))})]})]}):f.type==="number"?e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(re,{type:"number",value:p??f.default??"",onChange:g=>u(h,parseFloat(g.target.value)||0),placeholder:f.placeholder,disabled:c,className:"h-8 text-sm"})]}):e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(re,{type:"text",value:p??f.default??"",onChange:g=>u(h,g.target.value),placeholder:f.placeholder,disabled:c,className:"h-8 text-sm"})]})};return e.jsx(ze,{className:"p-3 space-y-2 bg-muted/30",children:Object.entries(i).map(([h,f])=>e.jsx("div",{children:x(h,f)},h))})}function i_({value:l,onChange:n,itemType:i="string",itemFields:c,minItems:u,maxItems:x,disabled:h,placeholder:f}){const p=m.useMemo(()=>Array.isArray(l)?l:typeof l=="string"&&l.trim()?l.split(",").map(O=>O.trim()):[],[l]),[g]=m.useState(()=>new Map),v=m.useCallback(O=>(g.has(O)||g.set(O,`item-${Date.now()}-${O}-${Math.random().toString(36).slice(2)}`),g.get(O)),[g]),N=m.useMemo(()=>{const O=[];for(let S=0;S{const{active:S,over:C}=O;if(C&&S.id!==C.id){const P=N.indexOf(S.id),M=N.indexOf(C.id),Z=Mj(p,P,M);n(Z)}},[p,N,n]),b=m.useCallback(()=>{if(x!=null&&p.length>=x)return;let O;i==="object"&&c?O=Object.fromEntries(Object.entries(c).map(([S,C])=>[S,C.default??""])):i==="number"?O=0:O="",n([...p,O])},[p,x,i,c,n]),L=m.useCallback((O,S)=>{const C=[...p];C[O]=S,n(C)},[p,n]),D=m.useCallback(O=>{if(u!=null&&p.length<=u)return;const S=p.filter((C,P)=>P!==O);g.delete(O),n(S)},[p,u,g,n]),T=x==null||p.lengthu;return e.jsxs("div",{className:"space-y-2",children:[p.length===0?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-4 justify-center border border-dashed rounded-md",children:[e.jsx(Dt,{className:"h-4 w-4"}),e.jsx("span",{children:"暂无数据,点击下方按钮添加"})]}):e.jsx(Aj,{sensors:y,collisionDetection:zj,onDragEnd:w,children:e.jsx(Dj,{items:N,strategy:a1,children:e.jsx("div",{className:"space-y-2",children:p.map((O,S)=>e.jsx(n_,{id:N[S],index:S,itemType:i,itemFields:c,value:O,onChange:C=>L(S,C),onRemove:()=>D(S),disabled:h,canRemove:F,placeholder:f},N[S]))})})}),e.jsxs(k,{type:"button",variant:"outline",size:"sm",onClick:b,disabled:h||!T,className:"w-full",children:[e.jsx(lt,{className:"h-4 w-4 mr-1"}),"添加项目",x!==void 0&&e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",p.length,"/",x,")"]})]}),(u!=null||x!=null)&&(u!==null||x!==null)&&e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:u!=null&&x!=null?`允许 ${u} - ${x} 项`:u!=null?`至少 ${u} 项`:`最多 ${x} 项`})]})}function c_(l,n,i,c={}){const{debounceMs:u=2e3,onSaveSuccess:x,onSaveError:h}=c,f=m.useRef(null),p=m.useCallback(async(y,w)=>{try{n(!0),await W2(y,w),i(!1),x?.()}catch(b){console.error(`自动保存 ${y} 失败:`,b),i(!0),h?.(b instanceof Error?b:new Error(String(b)))}finally{n(!1)}},[n,i,x,h]),g=m.useCallback((y,w)=>{l||(i(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{p(y,w)},u))},[l,i,p,u]),v=m.useCallback(async(y,w)=>{f.current&&(clearTimeout(f.current),f.current=null),await p(y,w)},[p]),N=m.useCallback(()=>{f.current&&(clearTimeout(f.current),f.current=null)},[]);return m.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]),{triggerAutoSave:g,saveNow:v,cancelPendingAutoSave:N}}function Bt(l,n,i,c){m.useEffect(()=>{l&&!i&&c(n,l)},[l])}const o_=500;function d_(){return e.jsx(Dn,{children:e.jsx(u_,{})})}function u_(){const[l,n]=m.useState(!0),[i,c]=m.useState(!1),[u,x]=m.useState(!1),[h,f]=m.useState(!1),[p,g]=m.useState("visual"),[v,N]=m.useState(""),[y,w]=m.useState(!1),{toast:b}=et(),{triggerRestart:L,isRestarting:D}=sn(),[T,F]=m.useState(null),[O,S]=m.useState(null),[C,P]=m.useState(null),[M,Z]=m.useState(null),[G,ce]=m.useState(null),[de,be]=m.useState(null),[me,pe]=m.useState(null),[je,A]=m.useState(null),[Y,H]=m.useState(null),[U,$]=m.useState(null),[_e,Ne]=m.useState(null),[Se,V]=m.useState(null),[ye,W]=m.useState(null),[ue,ke]=m.useState(null),[J,ee]=m.useState(null),[De,Fe]=m.useState(null),[ge,as]=m.useState(null),[ae,Ee]=m.useState(null),ie=m.useRef(!0),ve=m.useRef({}),Me=m.useCallback(Ce=>{ve.current=Ce,F(Ce.bot),S(Ce.personality);const cs=Ce.chat;cs.talk_value_rules||(cs.talk_value_rules=[]),P(cs),Z(Ce.expression),ce(Ce.emoji),be(Ce.memory),pe(Ce.tool),A(Ce.voice),H(Ce.lpmm_knowledge),$(Ce.keyword_reaction),Ne(Ce.response_post_process),V(Ce.chinese_typo),W(Ce.response_splitter),ke(Ce.log),ee(Ce.debug),Fe(Ce.maim_message),as(Ce.telemetry),Ee(Ce.webui)},[]),Ze=m.useCallback(()=>({...ve.current,bot:T,personality:O,chat:C,expression:M,emoji:G,memory:de,tool:me,voice:je,lpmm_knowledge:Y,keyword_reaction:U,response_post_process:_e,chinese_typo:Se,response_splitter:ye,log:ue,debug:J,maim_message:De,telemetry:ge,webui:ae}),[T,O,C,M,G,de,me,je,Y,U,_e,Se,ye,ue,J,De,ge,ae]),js=m.useCallback(async()=>{try{const cs=(await X2()).replace(/"([^"]*)"/g,(Es,zs)=>`"${zs.replace(/\\n/g,` `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}"`);N(cs),w(!1)}catch(Ce){b({variant:"destructive",title:"加载失败",description:Ce instanceof Error?Ce.message:"加载源代码失败"})}},[b]),Ot=m.useCallback(async()=>{try{n(!0);const Ce=await tg();Me(Ce),f(!1),ie.current=!1,await js()}catch(Ce){console.error("加载配置失败:",Ce),b({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}finally{n(!1)}},[b,js,Me]);m.useEffect(()=>{Ot()},[Ot]);const{triggerAutoSave:rs,cancelPendingAutoSave:Ps}=c_(ie.current,x,f);Bt(T,"bot",ie.current,rs),Bt(O,"personality",ie.current,rs),Bt(C,"chat",ie.current,rs),Bt(M,"expression",ie.current,rs),Bt(G,"emoji",ie.current,rs),Bt(de,"memory",ie.current,rs),Bt(me,"tool",ie.current,rs),Bt(je,"voice",ie.current,rs),Bt(Y,"lpmm_knowledge",ie.current,rs),Bt(U,"keyword_reaction",ie.current,rs),Bt(_e,"response_post_process",ie.current,rs),Bt(Se,"chinese_typo",ie.current,rs),Bt(ye,"response_splitter",ie.current,rs),Bt(ue,"log",ie.current,rs),Bt(J,"debug",ie.current,rs),Bt(De,"maim_message",ie.current,rs),Bt(ge,"telemetry",ie.current,rs),Bt(ae,"webui",ie.current,rs);const Q=async()=>{try{c(!0);const Ce=v.replace(/"([^"]*)"/g,(cs,Es)=>`"${Es.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")}"`);await Z2(Ce),f(!1),w(!1),b({title:"保存成功",description:"配置已保存"}),await Ot()}catch(Ce){w(!0),b({variant:"destructive",title:"保存失败",description:Ce instanceof Error?Ce.message:"保存配置失败"})}finally{c(!1)}},Ge=async Ce=>{if(h){b({variant:"destructive",title:"切换失败",description:"请先保存当前更改"});return}if(g(Ce),Ce==="source")await js();else try{const cs=await tg();Me(cs),f(!1)}catch(cs){console.error("加载配置失败:",cs),b({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}},He=async()=>{try{c(!0),Ps(),await ag(Ze()),f(!1),b({title:"保存成功",description:"麦麦主程序配置已保存"})}catch(Ce){console.error("保存配置失败:",Ce),b({title:"保存失败",description:Ce.message,variant:"destructive"})}finally{c(!1)}},Ve=async()=>{await L()},Bs=async()=>{try{c(!0),Ps(),await ag(Ze()),f(!1),b({title:"保存成功",description:"配置已保存,即将重启麦麦..."}),await new Promise(Ce=>setTimeout(Ce,o_)),await Ve()}catch(Ce){console.error("保存失败:",Ce),b({title:"保存失败",description:Ce.message,variant:"destructive"})}finally{c(!1)}};return l?e.jsx(Je,{className:"h-full",children:e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})})}):e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:gap-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl sm:text-2xl md:text-3xl font-bold",children:"麦麦主程序配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-xs sm:text-sm",children:"管理麦麦的核心功能和行为设置"})]}),e.jsxs("div",{className:"flex gap-2 flex-shrink-0",children:[e.jsxs(k,{onClick:p==="visual"?He:Q,disabled:i||u||!h||D,size:"sm",variant:"outline",className:"w-20 sm:w-24",children:[e.jsx(Ki,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{className:"ml-1 truncate text-xs sm:text-sm",children:i?"保存中":u?"自动":h?"保存":"已保存"})]}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsxs(k,{disabled:i||u||D,size:"sm",className:"w-20 sm:w-28",children:[e.jsx(Vi,{className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"ml-1 truncate text-xs sm:text-sm",children:D?"重启中":h?"保存重启":"重启"})]})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认重启麦麦?"}),e.jsx(hs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:h?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:h?Bs:Ve,children:h?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsx("div",{className:"flex",children:e.jsx(da,{value:p,onValueChange:Ce=>Ge(Ce),className:"w-full",children:e.jsxs(Zt,{className:"h-8 sm:h-9 w-full grid grid-cols-2",children:[e.jsxs(Xe,{value:"visual",className:"text-xs sm:text-sm",children:[e.jsx(fj,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"可视化编辑"]}),e.jsxs(Xe,{value:"source",className:"text-xs sm:text-sm",children:[e.jsx(pj,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"源代码编辑"]})]})})})]}),e.jsxs(gt,{children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(jt,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),p==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(gt,{children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(jt,{children:[e.jsx("strong",{children:"源代码模式(高级功能):"}),"直接编辑 TOML 配置文件。此功能仅适用于熟悉 TOML 语法的高级用户。保存时会在后端验证格式,只有格式完全正确才能保存。",y&&e.jsx("span",{className:"text-destructive font-semibold ml-2",children:"⚠️ 上次保存失败,请检查 TOML 格式"})]})]}),e.jsx(Xj,{value:v,onChange:Ce=>{N(Ce),f(!0),y&&w(!1)},language:"toml",theme:"dark",height:"calc(100vh - 280px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),p==="visual"&&e.jsx(e.Fragment,{children:e.jsxs(da,{defaultValue:"bot",className:"w-full",children:[e.jsxs(Zt,{className:"flex flex-wrap h-auto gap-1 p-1 sm:grid sm:grid-cols-5 lg:grid-cols-10",children:[e.jsx(Xe,{value:"bot",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"基本信息"}),e.jsx(Xe,{value:"personality",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"人格"}),e.jsx(Xe,{value:"chat",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"聊天"}),e.jsx(Xe,{value:"expression",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"表达"}),e.jsx(Xe,{value:"features",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"功能"}),e.jsx(Xe,{value:"processing",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"处理"}),e.jsx(Xe,{value:"voice",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"语音"}),e.jsx(Xe,{value:"lpmm",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"知识库"}),e.jsx(Xe,{value:"webui",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"WebUI"}),e.jsx(Xe,{value:"other",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"其他"})]}),e.jsx(ys,{value:"bot",className:"space-y-4",children:T&&e.jsx(z2,{config:T,onChange:F})}),e.jsx(ys,{value:"personality",className:"space-y-4",children:O&&e.jsx(D2,{config:O,onChange:S})}),e.jsx(ys,{value:"chat",className:"space-y-4",children:C&&e.jsx(B2,{config:C,onChange:P})}),e.jsx(ys,{value:"expression",className:"space-y-4",children:M&&e.jsx(K2,{config:M,onChange:Z})}),e.jsx(ys,{value:"features",className:"space-y-4",children:G&&de&&me&&e.jsx(F2,{emojiConfig:G,memoryConfig:de,toolConfig:me,onEmojiChange:ce,onMemoryChange:be,onToolChange:pe})}),e.jsx(ys,{value:"processing",className:"space-y-4",children:U&&_e&&Se&&ye&&e.jsx(Y2,{keywordReactionConfig:U,responsePostProcessConfig:_e,chineseTypoConfig:Se,responseSplitterConfig:ye,onKeywordReactionChange:$,onResponsePostProcessChange:Ne,onChineseTypoChange:V,onResponseSplitterChange:W})}),e.jsx(ys,{value:"voice",className:"space-y-4",children:je&&e.jsx($2,{config:je,onChange:A})}),e.jsx(ys,{value:"lpmm",className:"space-y-4",children:Y&&e.jsx(H2,{config:Y,onChange:H})}),e.jsx(ys,{value:"webui",className:"space-y-4",children:ae&&e.jsx(J2,{config:ae,onChange:Ee})}),e.jsxs(ys,{value:"other",className:"space-y-4",children:[ue&&e.jsx(I2,{config:ue,onChange:ke}),J&&e.jsx(P2,{config:J,onChange:ee}),De&&e.jsx(G2,{config:De,onChange:Fe}),ge&&e.jsx(q2,{config:ge,onChange:as})]})]})}),e.jsx(On,{})]})})}const wl=m.forwardRef(({className:l,...n},i)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:i,className:B("w-full caption-bottom text-sm",l),...n})}));wl.displayName="Table";const _l=m.forwardRef(({className:l,...n},i)=>e.jsx("thead",{ref:i,className:B("[&_tr]:border-b",l),...n}));_l.displayName="TableHeader";const Sl=m.forwardRef(({className:l,...n},i)=>e.jsx("tbody",{ref:i,className:B("[&_tr:last-child]:border-0",l),...n}));Sl.displayName="TableBody";const m_=m.forwardRef(({className:l,...n},i)=>e.jsx("tfoot",{ref:i,className:B("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",l),...n}));m_.displayName="TableFooter";const nt=m.forwardRef(({className:l,...n},i)=>e.jsx("tr",{ref:i,className:B("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",l),...n}));nt.displayName="TableRow";const Qe=m.forwardRef(({className:l,...n},i)=>e.jsx("th",{ref:i,className:B("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",l),...n}));Qe.displayName="TableHead";const Ie=m.forwardRef(({className:l,...n},i)=>e.jsx("td",{ref:i,className:B("px-4 py-3 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",l),...n}));Ie.displayName="TableCell";const x_=m.forwardRef(({className:l,...n},i)=>e.jsx("caption",{ref:i,className:B("mt-4 text-sm text-muted-foreground",l),...n}));x_.displayName="TableCaption";const $o=m.forwardRef(({className:l,...n},i)=>e.jsx(ma,{ref:i,className:B("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",l),...n}));$o.displayName=ma.displayName;const Ho=m.forwardRef(({className:l,...n},i)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(Vt,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(ma.Input,{ref:i,className:B("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",l),...n})]}));Ho.displayName=ma.Input.displayName;const Io=m.forwardRef(({className:l,...n},i)=>e.jsx(ma.List,{ref:i,className:B("max-h-[300px] overflow-y-auto overflow-x-hidden",l),...n}));Io.displayName=ma.List.displayName;const Po=m.forwardRef((l,n)=>e.jsx(ma.Empty,{ref:n,className:"py-6 text-center text-sm",...l}));Po.displayName=ma.Empty.displayName;const Ii=m.forwardRef(({className:l,...n},i)=>e.jsx(ma.Group,{ref:i,className:B("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",l),...n}));Ii.displayName=ma.Group.displayName;const h_=m.forwardRef(({className:l,...n},i)=>e.jsx(ma.Separator,{ref:i,className:B("-mx-1 h-px bg-border",l),...n}));h_.displayName=ma.Separator.displayName;const Pi=m.forwardRef(({className:l,...n},i)=>e.jsx(ma.Item,{ref:i,className:B("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",l),...n}));Pi.displayName=ma.Item.displayName;const Xs=m.forwardRef(({className:l,...n},i)=>e.jsx(sj,{ref:i,className:B("grid place-content-center peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",l),...n,children:e.jsx(cw,{className:B("grid place-content-center text-current"),children:e.jsx(_t,{className:"h-4 w-4"})})}));Xs.displayName=sj.displayName;const Zj=m.createContext(null),Wj="maibot-completed-tours";function f_(){try{const l=localStorage.getItem(Wj);return l?new Set(JSON.parse(l)):new Set}catch{return new Set}}function lg(l){localStorage.setItem(Wj,JSON.stringify([...l]))}function p_({children:l}){const[n,i]=m.useState({activeTourId:null,stepIndex:0,isRunning:!1}),[c]=m.useState(()=>new Map),[u,x]=m.useState(f_),[,h]=m.useState(0),f=m.useCallback((O,S)=>{c.set(O,S),h(C=>C+1)},[c]),p=m.useCallback(O=>{c.delete(O),i(S=>S.activeTourId===O?{...S,activeTourId:null,isRunning:!1,stepIndex:0}:S)},[c]),g=m.useCallback((O,S=0)=>{c.has(O)&&i({activeTourId:O,stepIndex:S,isRunning:!0})},[c]),v=m.useCallback(()=>{i(O=>({...O,isRunning:!1}))},[]),N=m.useCallback(O=>{i(S=>({...S,stepIndex:O}))},[]),y=m.useCallback(()=>{i(O=>({...O,stepIndex:O.stepIndex+1}))},[]),w=m.useCallback(()=>{i(O=>({...O,stepIndex:Math.max(0,O.stepIndex-1)}))},[]),b=m.useCallback(()=>n.activeTourId?c.get(n.activeTourId)||[]:[],[n.activeTourId,c]),L=m.useCallback(O=>{x(S=>{const C=new Set(S);return C.add(O),lg(C),C})},[]),D=m.useCallback(O=>{const{action:S,index:C,status:P,type:M}=O,Z=["finished","skipped"];if(S==="close"){i(G=>({...G,isRunning:!1,stepIndex:0}));return}Z.includes(P)?i(G=>(P==="finished"&&G.activeTourId&&setTimeout(()=>L(G.activeTourId),0),{...G,isRunning:!1,stepIndex:0})):M==="step:after"&&(S==="next"?i(G=>({...G,stepIndex:C+1})):S==="prev"&&i(G=>({...G,stepIndex:C-1})))},[L]),T=m.useCallback(O=>u.has(O),[u]),F=m.useCallback(O=>{x(S=>{const C=new Set(S);return C.delete(O),lg(C),C})},[]);return e.jsx(Zj.Provider,{value:{state:n,tours:c,registerTour:f,unregisterTour:p,startTour:g,stopTour:v,goToStep:N,nextStep:y,prevStep:w,getCurrentSteps:b,handleJoyrideCallback:D,isTourCompleted:T,markTourCompleted:L,resetTourCompleted:F},children:l})}function Bm(){const l=m.useContext(Zj);if(!l)throw new Error("useTour must be used within a TourProvider");return l}const g_={options:{zIndex:1e4,primaryColor:"hsl(var(--primary))",textColor:"hsl(var(--foreground))",backgroundColor:"hsl(var(--background))",arrowColor:"hsl(var(--background))",overlayColor:"rgba(0, 0, 0, 0.5)"},tooltip:{borderRadius:"var(--radius)",padding:"1rem"},tooltipContainer:{textAlign:"left"},tooltipTitle:{fontSize:"1rem",fontWeight:600,marginBottom:"0.5rem"},tooltipContent:{fontSize:"0.875rem",padding:"0.5rem 0"},buttonNext:{backgroundColor:"hsl(var(--primary))",color:"hsl(var(--primary-foreground))",borderRadius:"calc(var(--radius) - 2px)",fontSize:"0.875rem",padding:"0.5rem 1rem"},buttonBack:{color:"hsl(var(--muted-foreground))",fontSize:"0.875rem",marginRight:"0.5rem"},buttonSkip:{color:"hsl(var(--muted-foreground))",fontSize:"0.875rem"},buttonClose:{color:"hsl(var(--muted-foreground))"},spotlight:{borderRadius:"var(--radius)"}},j_={back:"上一步",close:"关闭",last:"完成",next:"下一步",nextLabelWithProgress:"下一步 ({step}/{steps})",open:"打开对话框",skip:"跳过"};function v_(){const{state:l,getCurrentSteps:n,handleJoyrideCallback:i}=Bm(),c=n(),[u,x]=m.useState(!1),h=m.useRef(l.stepIndex),f=m.useRef(null);m.useEffect(()=>{h.current!==l.stepIndex&&(x(!1),h.current=l.stepIndex)},[l.stepIndex]),m.useEffect(()=>{if(!l.isRunning||c.length===0){x(!1);return}const N=c[l.stepIndex];if(!N){x(!1);return}const y=N.target;if(y==="body"){x(!0);return}x(!1);const w=setTimeout(()=>{const b=()=>{const F=document.querySelector(y);if(F){const O=F.getBoundingClientRect();if(O.width>0&&O.height>0)return!0}return!1};if(b()){setTimeout(()=>x(!0),100);return}const L=setInterval(()=>{b()&&(clearInterval(L),setTimeout(()=>x(!0),100))},100),D=setTimeout(()=>{clearInterval(L),x(!0)},5e3),T=()=>{clearInterval(L),clearTimeout(D)};f.current=T},150);return()=>{clearTimeout(w),f.current&&(f.current(),f.current=null)}},[l.isRunning,l.stepIndex,c]);const[p,g]=m.useState(null);if(m.useEffect(()=>{let N=document.getElementById("tour-portal-container");return N||(N=document.createElement("div"),N.id="tour-portal-container",N.style.cssText="position: fixed; top: 0; left: 0; z-index: 99999; pointer-events: none;",document.body.appendChild(N)),g(N),()=>{}},[]),!l.isRunning||c.length===0||!u)return null;const v=e.jsx(n1,{steps:c,stepIndex:l.stepIndex,run:l.isRunning,continuous:!0,showSkipButton:!0,showProgress:!0,disableOverlayClose:!0,disableScrolling:!1,disableScrollParentFix:!1,callback:i,styles:g_,locale:j_,scrollOffset:80,scrollToFirstStep:!0,floaterProps:{styles:{floater:{zIndex:99999}},disableAnimation:!0}},`tour-step-${l.stepIndex}`);return p?Ky.createPortal(v,p):v}const Ya="model-assignment-tour",ev=[{target:"body",content:"本引导旨在帮助你配置模型提供商和对应的模型,并为麦麦的各个组件分配合适的模型。",placement:"center",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="sidebar-model-provider"]',content:'第一步,你需要配置模型提供商。模型提供商决定了你要使用谁家的模型,无论是单一厂商(如 DeepSeek),还是模型平台(如 Siliconflow),都可以在这里进行配置。点击"下一步"进入配置页面。',placement:"right",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="add-provider-button"]',content:'点击"添加提供商"按钮,开始配置你的模型提供商。',placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!0,hideFooter:!0},{target:'[data-tour="provider-dialog"]',content:"在这里,你可以选择你想要配置的模型提供商,填写相关信息后保存即可。",placement:"left",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-name-input"]',content:"这里的名称是你为这个模型提供商起的一个名字,方便你在后续使用时识别它。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-apikey-input"]',content:"这里需要填写你从模型提供商那里获取的 API 密钥,用于验证和调用模型服务。对于不同的提供商,获取 API 密钥的方式可能有所不同,请参考对应提供商的文档。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-url-input"]',content:"这里需要填写模型提供商的 API 访问地址,确保填写正确以便系统能够连接到模型服务。对于不同的提供商,API 地址可能有所不同,请参考对应提供商的文档。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-template-select"]',content:"当然,如果你不知道如何填写这些信息,很多模型提供商在这里都提供了预设的模板供你选择,选择对应的模板后,相关信息会自动填充。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-save-button"]',content:"填写完所有信息后,点击保存按钮,模型提供商就配置完成了。",placement:"top",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="provider-cancel-button"]',content:"因为这次咱们什么都没有填写,所以点击取消按钮退出吧。",placement:"top",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!0,hideFooter:!0},{target:'[data-tour="sidebar-model-management"]',content:'配置好模型提供商后,接下来我们需要为麦麦添加模型并分配功能。点击"下一步"进入模型管理页面。',placement:"right",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="add-model-button"]',content:'在为麦麦的组件分配模型之前,首先需要添加你想要分配的模型,点击"添加模型"按钮开始添加。',placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!0,hideFooter:!0},{target:'[data-tour="model-dialog"]',content:"在这里,你可以选择你之前配置好的模型提供商,然后选择对应的模型来添加。",placement:"left",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="model-name-input"]',content:"这里的模型名称是你为这个模型起的一个名字,方便你在后续使用时识别它。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="model-provider-select"]',content:"在这里选择你之前配置好的模型提供商,这样系统才能知道你要添加哪个提供商的模型。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="model-identifier-input"]',content:"这里需要填写你想要添加的模型的标识符,不同的模型提供商可能有不同的标识符格式,请参考对应提供商的文档。",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="model-save-button"]',content:"填写完所有信息后,点击保存按钮,模型就添加完成了。",placement:"top",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1},{target:'[data-tour="model-cancel-button"]',content:"当然,因为这次咱们什么都没有填写,所以直接点击取消按钮退出吧,等你准备好了再来添加模型。",placement:"top",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!0,hideFooter:!0},{target:'[data-tour="tasks-tab-trigger"]',content:'最后一步,添加好模型后,切换到"为模型分配功能"标签页,为麦麦的各个组件分配合适的模型。',placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!0,hideFooter:!0},{target:'[data-tour="task-model-select"]',content:"在这里,你可以为每个组件选择一个或多个合适的模型,选择完成后配置会自动保存。恭喜你完成了模型配置的学习!",placement:"bottom",disableBeacon:!0,disableOverlayClose:!0,hideCloseButton:!1,spotlightClicks:!1}],sv={0:"/config/model",1:"/config/model",2:"/config/modelProvider",3:"/config/modelProvider",4:"/config/modelProvider",5:"/config/modelProvider",6:"/config/modelProvider",7:"/config/modelProvider",8:"/config/modelProvider",9:"/config/modelProvider",10:"/config/modelProvider",11:"/config/model",12:"/config/model",13:"/config/model",14:"/config/model",15:"/config/model",16:"/config/model",17:"/config/model",18:"/config/model",19:"/config/model"},Ai=[{id:"siliconflow",name:"SiliconFlow",base_url:"https://api.siliconflow.cn/v1",client_type:"openai",display_name:"硅基流动 (SiliconFlow)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"deepseek",name:"DeepSeek",base_url:"https://api.deepseek.com",client_type:"openai",display_name:"DeepSeek",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"rinkoai",name:"RinkoAI",base_url:"https://rinkoai.com/v1",client_type:"openai",display_name:"RinkoAI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"zhipu",name:"ZhipuAI",base_url:"https://open.bigmodel.cn/api/paas/v4",client_type:"openai",display_name:"智谱 AI (ZhipuAI / GLM)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"moonshot",name:"Moonshot",base_url:"https://api.moonshot.cn/v1",client_type:"openai",display_name:"月之暗面 (Moonshot / Kimi)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"doubao",name:"Doubao",base_url:"https://ark.cn-beijing.volces.com/api/v3",client_type:"openai",display_name:"字节豆包 (Doubao)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"alibaba",name:"Alibaba",base_url:"https://dashscope.aliyuncs.com/compatible-mode/v1",client_type:"openai",display_name:"阿里云百炼 (Alibaba Qwen)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"baichuan",name:"Baichuan",base_url:"https://api.baichuan-ai.com/v1",client_type:"openai",display_name:"百川智能 (Baichuan)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"minimax",name:"MiniMax",base_url:"https://api.minimax.chat/v1",client_type:"openai",display_name:"MiniMax (海螺 AI)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"stepfun",name:"StepFun",base_url:"https://api.stepfun.com/v1",client_type:"openai",display_name:"阶跃星辰 (StepFun)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"lingyi",name:"Lingyi",base_url:"https://api.lingyiwanwu.com/v1",client_type:"openai",display_name:"零一万物 (Lingyi / Yi)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"openai",name:"OpenAI",base_url:"https://api.openai.com/v1",client_type:"openai",display_name:"OpenAI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"xai",name:"xAI",base_url:"https://api.x.ai/v1",client_type:"openai",display_name:"xAI (Grok)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"anthropic",name:"Anthropic",base_url:"https://api.anthropic.com/v1",client_type:"openai",display_name:"Anthropic (Claude)"},{id:"gemini",name:"Gemini",base_url:"https://generativelanguage.googleapis.com/v1beta",client_type:"gemini",display_name:"Google Gemini",modelFetcher:{endpoint:"/models",parser:"gemini"}},{id:"cohere",name:"Cohere",base_url:"https://api.cohere.ai/v1",client_type:"openai",display_name:"Cohere"},{id:"groq",name:"Groq",base_url:"https://api.groq.com/openai/v1",client_type:"openai",display_name:"Groq",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"together",name:"Together AI",base_url:"https://api.together.xyz/v1",client_type:"openai",display_name:"Together AI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"fireworks",name:"Fireworks",base_url:"https://api.fireworks.ai/inference/v1",client_type:"openai",display_name:"Fireworks AI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"mistral",name:"Mistral",base_url:"https://api.mistral.ai/v1",client_type:"openai",display_name:"Mistral AI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"perplexity",name:"Perplexity",base_url:"https://api.perplexity.ai",client_type:"openai",display_name:"Perplexity AI"},{id:"custom",name:"",base_url:"",client_type:"openai",display_name:"自定义"}];function ng(l){return l?l.replace(/\/+$/,"").toLowerCase():""}function N_(l){if(!l)return null;const n=ng(l);return Ai.find(i=>i.id!=="custom"&&ng(i.base_url)===n)||null}const fo=l=>({...l,max_retry:l.max_retry??2,timeout:l.timeout??30,retry_interval:l.retry_interval??10}),b_=l=>{const n={};return l?(l.name?.trim()||(n.name="请输入提供商名称"),l.base_url?.trim()||(n.base_url="请输入基础 URL"),l.api_key?.trim()||(n.api_key="请输入 API Key"),{isValid:Object.keys(n).length===0,errors:n}):{isValid:!1,errors:{name:"提供商数据为空"}}};function y_(){return e.jsx(Dn,{children:e.jsx(w_,{})})}function w_(){const[l,n]=m.useState([]),[i,c]=m.useState(!0),[u,x]=m.useState(!1),[h,f]=m.useState(!1),[p,g]=m.useState(!1),[v,N]=m.useState(!1),[y,w]=m.useState(null),[b,L]=m.useState(null),[D,T]=m.useState("custom"),[F,O]=m.useState(!1),[S,C]=m.useState(!1),[P,M]=m.useState(null),[Z,G]=m.useState(!1),[ce,de]=m.useState(""),[be,me]=m.useState(new Set),[pe,je]=m.useState(!1),[A,Y]=m.useState(1),[H,U]=m.useState(20),[$,_e]=m.useState(""),[Ne,Se]=m.useState({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),[V,ye]=m.useState({}),[W,ue]=m.useState(new Set),[ke,J]=m.useState(new Map),{toast:ee}=et(),De=ua(),{state:Fe,goToStep:ge,registerTour:as}=Bm(),{triggerRestart:ae,isRestarting:Ee}=sn(),ie=m.useRef(null),ve=m.useRef(!0);m.useEffect(()=>{as(Ya,ev)},[as]),m.useEffect(()=>{if(Fe.activeTourId===Ya&&Fe.isRunning){const X=sv[Fe.stepIndex];X&&!window.location.pathname.endsWith(X.replace("/config/",""))&&De({to:X})}},[Fe.stepIndex,Fe.activeTourId,Fe.isRunning,De]);const Me=m.useRef(Fe.stepIndex);m.useEffect(()=>{if(Fe.activeTourId===Ya&&Fe.isRunning){const X=Me.current,z=Fe.stepIndex;X>=3&&X<=9&&z<3&&N(!1),X>=10&&z>=3&&z<=9&&(ye({}),T("custom"),w({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10}),L(null),G(!1),N(!0)),Me.current=z}},[Fe.stepIndex,Fe.activeTourId,Fe.isRunning]),m.useEffect(()=>{if(Fe.activeTourId!==Ya||!Fe.isRunning)return;const X=z=>{const q=z.target,Be=Fe.stepIndex;Be===2&&q.closest('[data-tour="add-provider-button"]')?setTimeout(()=>ge(3),300):Be===9&&q.closest('[data-tour="provider-cancel-button"]')&&setTimeout(()=>ge(10),300)};return document.addEventListener("click",X,!0),()=>document.removeEventListener("click",X,!0)},[Fe,ge]),m.useEffect(()=>{Ze()},[]);const Ze=async()=>{try{c(!0);const X=await Xl();n(X.api_providers||[]),g(!1),ve.current=!1}catch(X){console.error("加载配置失败:",X)}finally{c(!1)}},js=async()=>{await ae()},Ot=async()=>{try{x(!0),ie.current&&clearTimeout(ie.current);const X=l.map(st=>({...st,max_retry:st.max_retry??2,timeout:st.timeout??30,retry_interval:st.retry_interval??10})),{shouldProceed:z}=await rs(X,"restart");if(!z){x(!1);return}const q=await Xl(),Be=new Set(X.map(st=>st.name)),_s=(q.models||[]).filter(st=>Be.has(st.api_provider));q.api_providers=X,q.models=_s,await Li(q),g(!1),ee({title:"保存成功",description:"正在重启麦麦..."}),await js()}catch(X){console.error("保存配置失败:",X),ee({title:"保存失败",description:X.message,variant:"destructive"}),x(!1)}},rs=m.useCallback(async(X,z="auto")=>{try{const q=await Xl(),Be=new Set(l.map(bt=>bt.name)),ct=new Set(X.map(bt=>bt.name)),_s=Array.from(Be).filter(bt=>!ct.has(bt));if(_s.length===0)return{shouldProceed:!0,providers:X};const Nt=(q.models||[]).filter(bt=>_s.includes(bt.api_provider));return Nt.length===0?{shouldProceed:!0,providers:X}:(Se({isOpen:!0,providersToDelete:_s,affectedModels:Nt,pendingProviders:X,context:z,oldProviders:[...l]}),{shouldProceed:!1,providers:X})}catch(q){return console.error("检查删除影响失败:",q),{shouldProceed:!0,providers:X}}},[l]),Ps=async()=>{try{(Ne.context==="auto"?f:x)(!0),Se(bt=>({...bt,isOpen:!1}));const z=await Xl(),q=Ne.pendingProviders.map(fo),Be=new Set(q.map(bt=>bt.name)),_s=(z.models||[]).filter(bt=>Be.has(bt.api_provider)),st=new Set(Ne.affectedModels.map(bt=>bt.name)),Nt=z.model_task_config;Nt&&Object.keys(Nt).forEach(bt=>{const ln=Nt[bt];ln&&Array.isArray(ln.model_list)&&(ln.model_list=ln.model_list.filter(Xi=>!st.has(Xi)))}),z.api_providers=q,z.models=_s,z.model_task_config=Nt,await Li(z),n(Ne.pendingProviders),g(!1),ee({title:"删除成功",description:`已删除 ${Ne.providersToDelete.length} 个提供商和 ${Ne.affectedModels.length} 个关联模型`}),Se({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),me(new Set),Ne.context==="restart"&&await js()}catch(X){console.error("删除失败:",X),ee({title:"删除失败",description:X.message,variant:"destructive"})}finally{Ne.context==="auto"?f(!1):x(!1)}},Q=()=>{Ne.oldProviders.length>0&&n(Ne.oldProviders),Se({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),g(!1)},Ge=m.useCallback(async X=>{if(ve.current)return;const{shouldProceed:z}=await rs(X,"auto");if(!z){g(!0);return}try{f(!0);const q=X.map(fo);await Tm("api_providers",q),g(!1)}catch(q){console.error("自动保存失败:",q),ee({title:"自动保存失败",description:q.message,variant:"destructive"}),g(!0)}finally{f(!1)}},[l,rs]);m.useEffect(()=>{if(!ve.current)return g(!0),ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>{Ge(l)},2e3),()=>{ie.current&&clearTimeout(ie.current)}},[l,Ge]);const He=async()=>{try{x(!0),ie.current&&clearTimeout(ie.current);const X=l.map(fo),{shouldProceed:z}=await rs(X,"manual");if(!z){x(!1);return}const q=await Xl(),Be=new Set(X.map(st=>st.name)),ct=q.models||[],_s=ct.filter(st=>{const Nt=Be.has(st.api_provider);return Nt||console.warn(`模型 "${st.name}" 引用了已删除的提供商 "${st.api_provider}",将被移除`),Nt});if(ct.length!==_s.length){const st=ct.length-_s.length;ee({title:"注意",description:`已自动移除 ${st} 个引用已删除提供商的模型`,variant:"default"})}console.log("发送的 providers 数据:",X),q.api_providers=X,q.models=_s,console.log("完整配置数据:",q),await Li(q),g(!1),ee({title:"保存成功",description:"模型提供商配置已保存"})}catch(X){console.error("保存配置失败:",X),ee({title:"保存失败",description:X.message,variant:"destructive"})}finally{x(!1)}},Ve=(X,z)=>{if(ye({}),X){const q=Ai.find(Be=>Be.base_url===X.base_url&&Be.client_type===X.client_type);T(q?.id||"custom"),w(X)}else T("custom"),w({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10});L(z),G(!1),N(!0)},Bs=m.useCallback(X=>{T(X),O(!1);const z=Ai.find(q=>q.id===X);z&&z.id!=="custom"?w(q=>({...q,name:z.name,base_url:z.base_url,client_type:z.client_type})):z?.id==="custom"&&w(q=>({...q,name:"",base_url:"",client_type:"openai"}))},[]),Ce=m.useMemo(()=>D!=="custom",[D]),cs=m.useCallback(async()=>{if(y?.api_key)try{await navigator.clipboard.writeText(y.api_key),ee({title:"复制成功",description:"API Key 已复制到剪贴板"})}catch{ee({title:"复制失败",description:"无法访问剪贴板",variant:"destructive"})}},[y?.api_key,ee]),Es=()=>{if(!y)return;const{isValid:X,errors:z}=b_(y);if(!X){ye(z);return}ye({});const q=fo(y);if(b!==null){const Be=[...l];Be[b]=q,n(Be)}else n([...l,q]);N(!1),w(null),L(null)},zs=X=>{if(!X&&y){const z={...y,max_retry:y.max_retry??2,timeout:y.timeout??30,retry_interval:y.retry_interval??10};w(z)}N(X)},es=X=>{M(X),C(!0)},We=async()=>{if(P!==null){const X=l.filter((q,Be)=>Be!==P),{shouldProceed:z}=await rs(X,"manual");z&&(n(X),ee({title:"删除成功",description:"提供商已从列表中移除"}))}C(!1),M(null)},vs=X=>{const z=new Set(be);z.has(X)?z.delete(X):z.add(X),me(z)},mt=()=>{if(be.size===ss.length)me(new Set);else{const X=ss.map((z,q)=>l.findIndex(Be=>Be===ss[q]));me(new Set(X))}},Rt=()=>{if(be.size===0){ee({title:"提示",description:"请先选择要删除的提供商",variant:"default"});return}je(!0)},it=async()=>{const X=l.filter((q,Be)=>!be.has(Be)),{shouldProceed:z}=await rs(X,"manual");z&&(n(X),me(new Set),ee({title:"批量删除成功",description:`已删除 ${be.size} 个提供商`})),je(!1)},ss=m.useMemo(()=>{if(!ce)return l;const X=ce.toLowerCase();return l.filter(z=>z.name.toLowerCase().includes(X)||z.base_url.toLowerCase().includes(X)||z.client_type.toLowerCase().includes(X))},[l,ce]),{totalPages:St,paginatedProviders:$t}=m.useMemo(()=>{const X=Math.ceil(ss.length/H),z=ss.slice((A-1)*H,A*H);return{totalPages:X,paginatedProviders:z}},[ss,A,H]),Mt=m.useCallback(()=>{const X=parseInt($);X>=1&&X<=St&&(Y(X),_e(""))},[$,St]),Ga=async X=>{ue(z=>new Set(z).add(X));try{const z=await s_(X);J(q=>new Map(q).set(X,z)),z.network_ok?z.api_key_valid===!0?ee({title:"连接正常",description:`${X} 网络连接正常,API Key 有效 (${z.latency_ms}ms)`}):z.api_key_valid===!1?ee({title:"连接正常但 Key 无效",description:`${X} 网络连接正常,但 API Key 无效或已过期`,variant:"destructive"}):ee({title:"网络连接正常",description:`${X} 可以访问 (${z.latency_ms}ms)`}):ee({title:"连接失败",description:z.error||"无法连接到提供商",variant:"destructive"})}catch(z){ee({title:"测试失败",description:z.message,variant:"destructive"})}finally{ue(z=>{const q=new Set(z);return q.delete(X),q})}},qa=async()=>{for(const X of l)await Ga(X.name)},Rn=X=>{const z=W.has(X),q=ke.get(X);return z?e.jsxs(Te,{variant:"secondary",className:"gap-1",children:[e.jsx(Js,{className:"h-3 w-3 animate-spin"}),"测试中"]}):q?q.network_ok?q.api_key_valid===!0?e.jsxs(Te,{className:"gap-1 bg-green-600 hover:bg-green-700",children:[e.jsx(oa,{className:"h-3 w-3"}),"正常"]}):q.api_key_valid===!1?e.jsxs(Te,{variant:"destructive",className:"gap-1",children:[e.jsx(Dt,{className:"h-3 w-3"}),"Key无效"]}):e.jsxs(Te,{className:"gap-1 bg-blue-600 hover:bg-blue-700",children:[e.jsx(oa,{className:"h-3 w-3"}),"可访问"]}):e.jsxs(Te,{variant:"destructive",className:"gap-1",children:[e.jsx(dj,{className:"h-3 w-3"}),"离线"]}):null};return i?e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})}):e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"AI模型厂商配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理 AI 模型厂商的 API 配置"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[be.size>0&&e.jsxs(k,{onClick:Rt,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(ns,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",be.size,")"]}),e.jsxs(k,{onClick:qa,size:"sm",variant:"outline",className:"w-full sm:w-auto",disabled:l.length===0||W.size>0,children:[e.jsx(Sn,{className:"mr-2 h-4 w-4"}),W.size>0?`测试中 (${W.size})`:"测试全部"]}),e.jsxs(k,{onClick:()=>Ve(null,null),size:"sm",className:"w-full sm:w-auto","data-tour":"add-provider-button",children:[e.jsx(lt,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"添加提供商"]}),e.jsxs(k,{onClick:He,disabled:u||h||!p||Ee,size:"sm",variant:"outline",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(Ki,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),u?"保存中...":h?"自动保存中...":p?"保存配置":"已保存"]}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsxs(k,{disabled:u||h||Ee,size:"sm",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(Vi,{className:"mr-2 h-4 w-4"}),Ee?"重启中...":p?"保存并重启":"重启麦麦"]})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认重启麦麦?"}),e.jsx(hs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:p?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:p?Ot:js,children:p?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(gt,{children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(jt,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),e.jsxs(Je,{className:"h-[calc(100vh-260px)]",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-2 mb-4",children:[e.jsxs("div",{className:"relative w-full sm:flex-1 sm:max-w-sm",children:[e.jsx(Vt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(re,{placeholder:"搜索提供商名称、URL 或类型...",value:ce,onChange:X=>de(X.target.value),className:"pl-9"})]}),ce&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",ss.length," 个结果"]})]}),e.jsx("div",{className:"md:hidden space-y-3",children:ss.length===0?e.jsx("div",{className:"text-center text-muted-foreground py-8 rounded-lg border bg-card",children:ce?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'}):$t.map((X,z)=>{const q=l.findIndex(Be=>Be===X);return e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"font-semibold text-base truncate",children:X.name}),Rn(X.name)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 break-all",children:X.base_url})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>Ga(X.name),disabled:W.has(X.name),title:"测试连接",children:W.has(X.name)?e.jsx(Js,{className:"h-4 w-4 animate-spin"}):e.jsx(Sn,{className:"h-4 w-4"})}),e.jsx(k,{variant:"default",size:"sm",onClick:()=>Ve(X,q),children:e.jsx(Cn,{className:"h-4 w-4",strokeWidth:2,fill:"none"})}),e.jsx(k,{size:"sm",onClick:()=>es(q),className:"bg-red-600 hover:bg-red-700 text-white",children:e.jsx(ns,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"客户端类型"}),e.jsx("p",{className:"font-medium",children:X.client_type})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"最大重试"}),e.jsx("p",{className:"font-medium",children:X.max_retry})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"超时(秒)"}),e.jsx("p",{className:"font-medium",children:X.timeout})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"重试间隔(秒)"}),e.jsx("p",{className:"font-medium",children:X.retry_interval})]})]})]},z)})}),e.jsx("div",{className:"hidden md:block rounded-lg border bg-card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(wl,{children:[e.jsx(_l,{children:e.jsxs(nt,{children:[e.jsx(Qe,{className:"w-12",children:e.jsx(Xs,{checked:be.size===ss.length&&ss.length>0,onCheckedChange:mt})}),e.jsx(Qe,{children:"状态"}),e.jsx(Qe,{children:"名称"}),e.jsx(Qe,{children:"基础URL"}),e.jsx(Qe,{children:"客户端类型"}),e.jsx(Qe,{className:"text-right",children:"最大重试"}),e.jsx(Qe,{className:"text-right",children:"超时(秒)"}),e.jsx(Qe,{className:"text-right",children:"重试间隔(秒)"}),e.jsx(Qe,{className:"text-right",children:"操作"})]})}),e.jsx(Sl,{children:$t.length===0?e.jsx(nt,{children:e.jsx(Ie,{colSpan:9,className:"text-center text-muted-foreground py-8",children:ce?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'})}):$t.map((X,z)=>{const q=l.findIndex(Be=>Be===X);return e.jsxs(nt,{children:[e.jsx(Ie,{children:e.jsx(Xs,{checked:be.has(q),onCheckedChange:()=>vs(q)})}),e.jsx(Ie,{children:Rn(X.name)||e.jsx(Te,{variant:"outline",className:"text-muted-foreground",children:"未测试"})}),e.jsx(Ie,{className:"font-medium",children:X.name}),e.jsx(Ie,{className:"max-w-xs truncate",title:X.base_url,children:X.base_url}),e.jsx(Ie,{children:X.client_type}),e.jsx(Ie,{className:"text-right",children:X.max_retry}),e.jsx(Ie,{className:"text-right",children:X.timeout}),e.jsx(Ie,{className:"text-right",children:X.retry_interval}),e.jsx(Ie,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>Ga(X.name),disabled:W.has(X.name),title:"测试连接",children:W.has(X.name)?e.jsx(Js,{className:"h-4 w-4 animate-spin"}):e.jsx(Sn,{className:"h-4 w-4"})}),e.jsxs(k,{variant:"default",size:"sm",onClick:()=>Ve(X,q),children:[e.jsx(Cn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(k,{size:"sm",onClick:()=>es(q),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},z)})})]})})}),ss.length>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{htmlFor:"page-size-provider",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Le,{value:H.toString(),onValueChange:X=>{U(parseInt(X)),Y(1),me(new Set)},children:[e.jsx(Oe,{id:"page-size-provider",className:"w-20",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"10",children:"10"}),e.jsx(le,{value:"20",children:"20"}),e.jsx(le,{value:"50",children:"50"}),e.jsx(le,{value:"100",children:"100"})]})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(A-1)*H+1," 到"," ",Math.min(A*H,ss.length)," 条,共 ",ss.length," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>Y(1),disabled:A===1,className:"hidden sm:flex",children:e.jsx(zr,{className:"h-4 w-4"})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>Y(X=>Math.max(1,X-1)),disabled:A===1,children:[e.jsx(Wa,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"上一页"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{type:"number",value:$,onChange:X=>_e(X.target.value),onKeyDown:X=>X.key==="Enter"&&Mt(),placeholder:A.toString(),className:"w-16 h-8 text-center",min:1,max:St}),e.jsx(k,{variant:"outline",size:"sm",onClick:Mt,disabled:!$,className:"h-8",children:"跳转"})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>Y(X=>X+1),disabled:A>=St,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>Y(St),disabled:A>=St,className:"hidden sm:flex",children:e.jsx(Dr,{className:"h-4 w-4"})})]})]})]}),e.jsx(Is,{open:v,onOpenChange:zs,children:e.jsxs(Rs,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"provider-dialog",preventOutsideClose:Fe.isRunning,children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:b!==null?"编辑提供商":"添加提供商"}),e.jsx(Zs,{children:"配置 API 提供商的连接信息和参数"})]}),e.jsxs("form",{onSubmit:X=>{X.preventDefault(),Es()},autoComplete:"off",children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":"provider-template-select",children:[e.jsx(E,{htmlFor:"template",children:"提供商模板"}),e.jsxs(Xa,{open:F,onOpenChange:O,children:[e.jsx(Za,{asChild:!0,children:e.jsxs(k,{variant:"outline",role:"combobox","aria-expanded":F,className:"w-full justify-between",children:[D?Ai.find(X=>X.id===D)?.display_name:"选择提供商模板...",e.jsx(Om,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(Ia,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs($o,{children:[e.jsx(Ho,{placeholder:"搜索提供商模板..."}),e.jsx(Je,{className:"h-[300px]",children:e.jsxs(Io,{className:"max-h-none overflow-visible",children:[e.jsx(Po,{children:"未找到匹配的模板"}),e.jsx(Ii,{children:Ai.map(X=>e.jsxs(Pi,{value:X.display_name,onSelect:()=>Bs(X.id),children:[e.jsx(_t,{className:`mr-2 h-4 w-4 ${D===X.id?"opacity-100":"opacity-0"}`}),X.display_name]},X.id))})]})})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"选择预设模板可自动填充 URL 和客户端类型,支持搜索"})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"provider-name-input",children:[e.jsx(E,{htmlFor:"name",className:V.name?"text-destructive":"",children:"名称 *"}),e.jsx(re,{id:"name",value:y?.name||"",onChange:X=>{w(z=>z?{...z,name:X.target.value}:null),V.name&&ye(z=>({...z,name:void 0}))},placeholder:"例如: DeepSeek, SiliconFlow",className:V.name?"border-destructive focus-visible:ring-destructive":""}),V.name&&e.jsx("p",{className:"text-xs text-destructive",children:V.name})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"provider-url-input",children:[e.jsx(E,{htmlFor:"base_url",className:V.base_url?"text-destructive":"",children:"基础 URL *"}),e.jsx(re,{id:"base_url",value:y?.base_url||"",onChange:X=>{w(z=>z?{...z,base_url:X.target.value}:null),V.base_url&&ye(z=>({...z,base_url:void 0}))},placeholder:"https://api.example.com/v1",disabled:Ce,className:`${Ce?"bg-muted cursor-not-allowed":""} ${V.base_url?"border-destructive focus-visible:ring-destructive":""}`}),V.base_url&&e.jsx("p",{className:"text-xs text-destructive",children:V.base_url}),Ce&&!V.base_url&&e.jsx("p",{className:"text-xs text-muted-foreground",children:'使用模板时 URL 不可编辑,切换到"自定义"以手动配置'})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"provider-apikey-input",children:[e.jsx(E,{htmlFor:"api_key",className:V.api_key?"text-destructive":"",children:"API Key *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(re,{id:"api_key",type:Z?"text":"password",value:y?.api_key||"",onChange:X=>{w(z=>z?{...z,api_key:X.target.value}:null),V.api_key&&ye(z=>({...z,api_key:void 0}))},placeholder:"sk-...",className:`flex-1 ${V.api_key?"border-destructive focus-visible:ring-destructive":""}`}),e.jsx(k,{type:"button",variant:"outline",size:"icon",onClick:()=>G(!Z),title:Z?"隐藏密钥":"显示密钥",children:Z?e.jsx(Bi,{className:"h-4 w-4"}):e.jsx(Xt,{className:"h-4 w-4"})}),e.jsx(k,{type:"button",variant:"outline",size:"icon",onClick:cs,title:"复制密钥",children:e.jsx(_o,{className:"h-4 w-4"})})]}),V.api_key&&e.jsx("p",{className:"text-xs text-destructive",children:V.api_key})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"client_type",children:"客户端类型"}),e.jsxs(Le,{value:y?.client_type||"openai",onValueChange:X=>w(z=>z?{...z,client_type:X}:null),disabled:Ce,children:[e.jsx(Oe,{id:"client_type",className:Ce?"bg-muted cursor-not-allowed":"",children:e.jsx(Ue,{placeholder:"选择客户端类型"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"openai",children:"OpenAI"}),e.jsx(le,{value:"gemini",children:"Gemini"})]})]}),Ce&&e.jsx("p",{className:"text-xs text-muted-foreground",children:'使用模板时客户端类型不可编辑,切换到"自定义"以手动配置'})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"max_retry",children:"最大重试"}),e.jsx(re,{id:"max_retry",type:"number",min:"0",value:y?.max_retry??"",onChange:X=>{const z=X.target.value===""?null:parseInt(X.target.value);w(q=>q?{...q,max_retry:z}:null)},placeholder:"默认: 2"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"timeout",children:"超时(秒)"}),e.jsx(re,{id:"timeout",type:"number",min:"1",value:y?.timeout??"",onChange:X=>{const z=X.target.value===""?null:parseInt(X.target.value);w(q=>q?{...q,timeout:z}:null)},placeholder:"默认: 30"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"retry_interval",children:"重试间隔(秒)"}),e.jsx(re,{id:"retry_interval",type:"number",min:"1",value:y?.retry_interval??"",onChange:X=>{const z=X.target.value===""?null:parseInt(X.target.value);w(q=>q?{...q,retry_interval:z}:null)},placeholder:"默认: 10"})]})]})]}),e.jsxs(rt,{children:[e.jsx(k,{type:"button",variant:"outline",onClick:()=>N(!1),"data-tour":"provider-cancel-button",children:"取消"}),e.jsx(k,{type:"submit","data-tour":"provider-save-button",children:"保存"})]})]})]})}),e.jsx(gs,{open:S,onOpenChange:C,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:['确定要删除提供商 "',P!==null?l[P]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:We,children:"删除"})]})]})}),e.jsx(gs,{open:pe,onOpenChange:je,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认批量删除"}),e.jsxs(hs,{children:["确定要删除选中的 ",be.size," 个提供商吗? 此操作无法撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:it,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),e.jsx(gs,{open:Ne.isOpen,onOpenChange:X=>Se(z=>({...z,isOpen:X})),children:e.jsxs(ds,{className:"max-w-2xl",children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除提供商"}),e.jsx(hs,{asChild:!0,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{children:["您即将删除以下提供商:",e.jsx("strong",{className:"text-foreground ml-1",children:Ne.providersToDelete.join(", ")})]}),e.jsxs("p",{className:"text-yellow-600 dark:text-yellow-500 font-medium",children:["⚠️ 此操作将同时删除 ",Ne.affectedModels.length," 个关联的模型:"]}),e.jsx(Je,{className:"h-32 w-full rounded border p-3",children:e.jsx("div",{className:"space-y-1",children:Ne.affectedModels.map((X,z)=>e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:"•"}),e.jsx("span",{className:"ml-2 font-medium",children:X.name}),e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",X.model_identifier,")"]})]},z))})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"这些模型将从模型列表和所有任务分配中移除。此操作无法撤销。"})]})})]}),e.jsxs(ms,{children:[e.jsx(ps,{onClick:Q,children:"取消"}),e.jsx(fs,{onClick:Ps,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})}),e.jsx(On,{})]})}function tv(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).substring(2,11)}`}function av(l){return typeof l=="boolean"?"boolean":typeof l=="number"?"number":"string"}function __(l,n){switch(n){case"boolean":return l==="true";case"number":{const i=parseFloat(l);return isNaN(i)?0:i}default:return l}}function rg(l){return Object.entries(l).map(([n,i])=>({id:tv(),key:n,value:i,type:av(i)}))}function hm(l){const n={};for(const i of l)i.key.trim()&&(n[i.key.trim()]=i.value);return n}function fm(l){if(!l.trim())return{valid:!0,parsed:{}};try{const n=JSON.parse(l);if(typeof n!="object"||n===null||Array.isArray(n))return{valid:!1,error:"必须是一个 JSON 对象 {}"};for(const[i,c]of Object.entries(n))if(c!==null&&!["string","number","boolean"].includes(typeof c))return{valid:!1,error:`键 "${i}" 的值类型不支持(仅支持 string/number/boolean)`};return{valid:!0,parsed:n}}catch{return{valid:!1,error:"JSON 格式错误"}}}function S_(l){switch(l){case"boolean":return"布尔";case"number":return"数字";default:return"字符串"}}function C_(l){switch(l){case"boolean":return"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400";case"number":return"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400";default:return"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400"}}function k_({value:l,onChange:n,className:i,placeholder:c="添加额外参数..."}){const[u,x]=m.useState("list"),h=m.useMemo(()=>rg(l||{}),[l]),f=m.useMemo(()=>Object.keys(l||{}).length>0?JSON.stringify(l,null,2):"",[l]),[p,g]=m.useState(h),[v,N]=m.useState(f),[y,w]=m.useState(null);m.useEffect(()=>{g(h),N(f)},[h,f]);const b=m.useMemo(()=>{const S=fm(v);return S.valid&&S.parsed?{success:!0,data:S.parsed}:{success:!1,data:{}}},[v]),L=m.useCallback(S=>{const C=S;if(C==="json"&&u==="list"){const P=hm(p);N(Object.keys(P).length>0?JSON.stringify(P,null,2):""),w(null)}else if(C==="list"&&u==="json"){const P=fm(v);P.valid&&P.parsed&&(g(rg(P.parsed)),w(null))}x(C)},[u,p,v]),D=m.useCallback(()=>{const S={id:tv(),key:"",value:"",type:"string"},C=[...p,S];g(C)},[p]),T=m.useCallback(S=>{const C=p.filter(P=>P.id!==S);g(C),n(hm(C))},[p,n]),F=m.useCallback((S,C,P)=>{const M=p.map(Z=>{if(Z.id!==S)return Z;if(C==="type"){const G=P;let ce;return G==="boolean"?ce=Z.value==="true"||Z.value===!0:G==="number"?ce=typeof Z.value=="number"?Z.value:parseFloat(String(Z.value))||0:ce=String(Z.value),{...Z,type:G,value:ce}}else return C==="value"?{...Z,value:__(P,Z.type)}:{...Z,[C]:P}});g(M),n(hm(M))},[p,n]),O=m.useCallback(S=>{N(S);const C=fm(S);C.valid&&C.parsed?(w(null),n(C.parsed)):w(C.error||"JSON 格式错误")},[n]);return e.jsxs("div",{className:B("space-y-3",i),children:[e.jsx(E,{className:"text-sm font-medium",children:"额外参数"}),e.jsxs(da,{value:u,onValueChange:L,className:"w-full",children:[e.jsxs(Zt,{className:"h-8 p-0.5 bg-muted/60",children:[e.jsx(Xe,{value:"list",className:"h-7 px-3 text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"键值对"}),e.jsx(Xe,{value:"json",className:"h-7 px-3 text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"JSON"})]}),e.jsxs(ys,{value:"list",className:"mt-3 space-y-2",children:[p.length===0?e.jsx("div",{className:"text-sm text-muted-foreground text-center py-4 border border-dashed rounded-md",children:c}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_1fr_90px_32px] gap-2 text-xs text-muted-foreground px-1",children:[e.jsx("span",{children:"键名"}),e.jsx("span",{children:"值"}),e.jsx("span",{children:"类型"}),e.jsx("span",{})]}),p.map(S=>e.jsxs("div",{className:"grid grid-cols-[1fr_1fr_90px_32px] gap-2 items-center",children:[e.jsx(re,{value:S.key,onChange:C=>F(S.id,"key",C.target.value),placeholder:"key",className:"h-8 text-sm"}),S.type==="boolean"?e.jsxs("div",{className:"flex items-center h-8 px-3 border rounded-md bg-background",children:[e.jsx(Pe,{checked:S.value===!0,onCheckedChange:C=>F(S.id,"value",String(C))}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:S.value?"true":"false"})]}):e.jsx(re,{type:S.type==="number"?"number":"text",value:S.value,onChange:C=>F(S.id,"value",C.target.value),placeholder:"value",className:"h-8 text-sm",step:S.type==="number"?"any":void 0}),e.jsxs(Le,{value:S.type,onValueChange:C=>F(S.id,"type",C),children:[e.jsx(Oe,{className:"h-8 text-xs",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"string",children:"字符串"}),e.jsx(le,{value:"number",children:"数字"}),e.jsx(le,{value:"boolean",children:"布尔"})]})]}),e.jsx(k,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>T(S.id),children:e.jsx(ns,{className:"h-4 w-4"})})]},S.id))]}),e.jsxs(k,{type:"button",variant:"outline",size:"sm",className:"w-full h-8",onClick:D,children:[e.jsx(lt,{className:"h-4 w-4 mr-1"}),"添加参数"]})]}),e.jsx(ys,{value:"json",className:"mt-3",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"编辑"}),y?e.jsxs("div",{className:"flex items-center gap-1 text-xs text-destructive",children:[e.jsx(Dt,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate max-w-[150px]",children:y})]}):v.trim()&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-green-600 dark:text-green-400",children:[e.jsx(_t,{className:"h-3 w-3"}),e.jsx("span",{children:"有效"})]})]}),e.jsx(Ys,{value:v,onChange:S=>O(S.target.value),placeholder:`{ "key": "value" }`,className:B("font-mono text-sm min-h-[140px] h-[140px] resize-y flex-1",y&&"border-destructive focus-visible:ring-destructive")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"支持 string、number、boolean 类型"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"预览"}),e.jsx("div",{className:"min-h-[140px] h-[140px] flex-1 rounded-md border bg-muted/30 p-3 overflow-auto",children:b.success&&Object.keys(b.data).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(b.data).map(([S,C])=>{const P=av(C);return e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("code",{className:"px-1.5 py-0.5 bg-background rounded text-xs font-medium",children:S}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("span",{className:B("font-mono",P==="boolean"&&(C?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"),P==="number"&&"text-blue-600 dark:text-blue-400",P==="string"&&"text-amber-600 dark:text-amber-400"),children:P==="string"?`"${C}"`:String(C)}),e.jsx(Te,{variant:"secondary",className:B("h-5 text-[10px] px-1.5",C_(P)),children:S_(P)})]},S)})}):b.success?e.jsx("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:"暂无参数"}):e.jsx("div",{className:"flex items-center justify-center h-full text-sm text-destructive",children:"JSON 格式错误"})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"实时预览解析结果"})]})]})})]})]})}const Rr="https://maibot-plugin-stats.maibot-webui.workers.dev";async function T_(l){const n=new URLSearchParams;l?.status&&n.set("status",l.status),l?.page&&n.set("page",l.page.toString()),l?.page_size&&n.set("page_size",l.page_size.toString()),l?.search&&n.set("search",l.search),l?.sort_by&&n.set("sort_by",l.sort_by),l?.sort_order&&n.set("sort_order",l.sort_order);const i=await fetch(`${Rr}/pack?${n.toString()}`);if(!i.ok)throw new Error(`获取 Pack 列表失败: ${i.status}`);return i.json()}async function E_(l){const n=await fetch(`${Rr}/pack/${l}`);if(!n.ok)throw new Error(`获取 Pack 失败: ${n.status}`);const i=await n.json();if(!i.success)throw new Error(i.error||"获取 Pack 失败");return i.pack}async function M_(l){const i=await(await fetch(`${Rr}/pack`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)})).json();if(!i.success)throw new Error(i.error||"创建 Pack 失败");return i}async function A_(l,n){await fetch(`${Rr}/pack/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pack_id:l,user_id:n})})}async function lv(l,n){const c=await(await fetch(`${Rr}/pack/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pack_id:l,user_id:n})})).json();if(!c.success)throw new Error(c.error||"点赞失败");return{likes:c.likes,liked:c.liked}}async function nv(l,n){return(await(await fetch(`${Rr}/pack/like/check?pack_id=${l}&user_id=${n}`)).json()).liked||!1}async function z_(l){const n=await we("/api/webui/config/model");if(!n.ok)throw new Error("获取当前模型配置失败");const i=await n.json(),c=i.config||i;console.log("=== Pack Conflict Detection ==="),console.log("Pack providers:",l.providers),console.log("Local providers:",c.api_providers);const u={existing_providers:[],new_providers:[],conflicting_models:[]},x=c.api_providers||[];for(const f of l.providers){console.log(` Checking pack provider: ${f.name}`),console.log(` Pack URL: ${f.base_url}`),console.log(` Normalized: ${pm(f.base_url)}`);const p=x.filter(g=>{const v=pm(g.base_url),N=pm(f.base_url);return console.log(` Comparing with local "${g.name}": ${g.base_url}`),console.log(` Local normalized: ${v}`),console.log(` Match: ${v===N}`),v===N});p.length>0?(console.log(` ✓ Matched with ${p.length} local provider(s):`,p.map(g=>g.name).join(", ")),u.existing_providers.push({pack_provider:f,local_providers:p.map(g=>({name:g.name,base_url:g.base_url}))})):(console.log(" ✗ No match found - will need API key"),u.new_providers.push(f))}const h=c.models||[];console.log(` === Model Conflict Detection ===`);for(const f of l.models){const p=h.find(g=>g.name===f.name);p&&(console.log(`Model conflict: ${f.name}`),u.conflicting_models.push({pack_model:f.name,local_model:p.name}))}return console.log(` === Detection Summary ===`),console.log(`Existing providers: ${u.existing_providers.length}`),console.log(`New providers: ${u.new_providers.length}`),console.log(`Conflicting models: ${u.conflicting_models.length}`),console.log(`=========================== `),u}async function D_(l,n,i,c){const u=await we("/api/webui/config/model");if(!u.ok)throw new Error("获取当前模型配置失败");const x=await u.json(),h=x.config||x;if(n.apply_providers){const p=n.selected_providers?l.providers.filter(g=>n.selected_providers.includes(g.name)):l.providers;for(const g of p){if(i[g.name])continue;const v=c[g.name];if(!v)throw new Error(`提供商 "${g.name}" 缺少 API Key`);const N={...g,api_key:v},y=h.api_providers.findIndex(w=>w.name===g.name);y>=0?h.api_providers[y]=N:h.api_providers.push(N)}}if(n.apply_models){const p=n.selected_models?l.models.filter(g=>n.selected_models.includes(g.name)):l.models;for(const g of p){const v=i[g.api_provider]||g.api_provider,N={...g,api_provider:v},y=h.models.findIndex(w=>w.name===g.name);y>=0?h.models[y]=N:h.models.push(N)}}if(n.apply_task_config){const p=n.selected_tasks||Object.keys(l.task_config);for(const g of p){const v=l.task_config[g];if(!v)continue;const N=new Set(n.selected_models||l.models.map(b=>b.name)),y=v.model_list.filter(b=>N.has(b));if(y.length===0)continue;const w={...v,model_list:y};if(n.task_mode==="replace")h.model_task_config[g]=w;else{const b=h.model_task_config[g];if(b){const L=[...new Set([...b.model_list,...y])];h.model_task_config[g]={...b,model_list:L}}else h.model_task_config[g]=w}}}if(!(await we("/api/webui/config/model",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)})).ok)throw new Error("保存配置失败")}async function O_(l){const n=await we("/api/webui/config/model");if(!n.ok)throw new Error("获取当前模型配置失败");const i=await n.json();if(!i.success||!i.config)throw new Error("获取配置失败");const c=i.config;let u=(c.api_providers||[]).map(g=>({name:g.name,base_url:g.base_url,client_type:g.client_type,max_retry:g.max_retry,timeout:g.timeout,retry_interval:g.retry_interval}));l.selectedProviders&&(u=u.filter(g=>l.selectedProviders.includes(g.name)));let x=c.models||[];l.selectedModels&&(x=x.filter(g=>l.selectedModels.includes(g.name)));const h={},f=c.model_task_config||{},p=l.selectedTasks||Object.keys(f);for(const g of p)f[g]&&(h[g]=f[g]);return{providers:u,models:x,task_config:h}}function pm(l){try{const n=new URL(l);return`${n.protocol}//${n.host}${n.pathname}`.replace(/\/$/,"").toLowerCase()}catch{return l.toLowerCase().replace(/\/$/,"")}}function rv(){const l="maibot_pack_user_id";let n=localStorage.getItem(l);return n||(n="pack_user_"+Math.random().toString(36).substring(2,15),localStorage.setItem(l,n)),n}const R_={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",lpmm_qa:"问答模型"},L_=["官方推荐","性价比","高性能","免费模型","国内可用","海外模型","OpenAI","Claude","Gemini","国产模型","多模态","轻量级"];function U_({trigger:l}){const[n,i]=m.useState(!1),[c,u]=m.useState(1),[x,h]=m.useState(!1),[f,p]=m.useState(!1),[g,v]=m.useState([]),[N,y]=m.useState([]),[w,b]=m.useState({}),[L,D]=m.useState(new Set),[T,F]=m.useState(new Set),[O,S]=m.useState(new Set),[C,P]=m.useState(""),[M,Z]=m.useState(""),[G,ce]=m.useState(""),[de,be]=m.useState([]);m.useEffect(()=>{n&&c===1&&me()},[n,c]);const me=async()=>{h(!0);try{const V=await O_({name:"",description:"",author:""});v(V.providers),y(V.models),b(V.task_config),D(new Set(V.providers.map(ye=>ye.name))),F(new Set(V.models.map(ye=>ye.name))),S(new Set(Object.keys(V.task_config)))}catch(V){console.error("加载配置失败:",V),Ft({title:"加载当前配置失败",variant:"destructive"})}finally{h(!1)}},pe=V=>{const ye=new Set(L),W=new Set(T),ue=new Set(O);ye.has(V)?(ye.delete(V),N.filter(J=>J.api_provider===V).forEach(J=>W.delete(J.name)),Object.entries(w).forEach(([J,ee])=>{ee.model_list&&(ee.model_list.some(Fe=>W.has(Fe))||ue.delete(J))})):(ye.add(V),N.filter(J=>J.api_provider===V).forEach(J=>W.add(J.name)),Object.entries(w).forEach(([J,ee])=>{ee.model_list&&ee.model_list.some(Fe=>{const ge=N.find(as=>as.name===Fe);return ge&&ge.api_provider===V})&&ue.add(J)})),D(ye),F(W),S(ue)},je=V=>{const ye=new Set(T),W=new Set(O);ye.has(V)?(ye.delete(V),Object.entries(w).forEach(([ue,ke])=>{ke.model_list&&(ke.model_list.some(ee=>ye.has(ee))||W.delete(ue))})):(ye.add(V),Object.entries(w).forEach(([ue,ke])=>{ke.model_list&&ke.model_list.includes(V)&&W.add(ue)})),F(ye),S(W)},A=V=>{const ye=new Set(O);ye.has(V)?ye.delete(V):ye.add(V),S(ye)},Y=V=>{de.includes(V)?be(de.filter(ye=>ye!==V)):de.length<5?be([...de,V]):Ft({title:"最多选择 5 个标签",variant:"destructive"})},H=()=>{L.size===g.length?D(new Set):D(new Set(g.map(V=>V.name)))},U=()=>{T.size===N.length?F(new Set):F(new Set(N.map(V=>V.name)))},$=()=>{const V=Object.keys(w);O.size===V.length?S(new Set):S(new Set(V))},_e=async()=>{if(!C.trim()){Ft({title:"请输入模板名称",variant:"destructive"});return}if(!M.trim()){Ft({title:"请输入模板描述",variant:"destructive"});return}if(!G.trim()){Ft({title:"请输入作者名称",variant:"destructive"});return}if(L.size===0&&T.size===0&&O.size===0){Ft({title:"请至少选择一项配置",variant:"destructive"});return}p(!0);try{const V=g.filter(ue=>L.has(ue.name)),ye=N.filter(ue=>T.has(ue.name)),W={};for(const[ue,ke]of Object.entries(w))O.has(ue)&&(W[ue]=ke);await M_({name:C.trim(),description:M.trim(),author:G.trim(),tags:de,providers:V,models:ye,task_config:W}),Ft({title:"模板已提交审核,审核通过后将显示在市场中"}),i(!1),Ne()}catch(V){console.error("提交失败:",V),Ft({title:V instanceof Error?V.message:"提交失败",variant:"destructive"})}finally{p(!1)}},Ne=()=>{u(1),P(""),Z(""),ce(""),be([]),D(new Set),F(new Set),S(new Set)},Se=2;return e.jsxs(Is,{open:n,onOpenChange:i,children:[e.jsx(Bo,{asChild:!0,children:l||e.jsxs(k,{variant:"outline",children:[e.jsx(gj,{className:"w-4 h-4 mr-2"}),"分享配置"]})}),e.jsxs(Rs,{className:"max-w-2xl max-h-[85vh] flex flex-col",children:[e.jsxs(Ls,{children:[e.jsxs(Us,{className:"flex items-center gap-2",children:[e.jsx(ca,{className:"w-5 h-5"}),"分享配置模板"]}),e.jsxs(Zs,{children:["步骤 ",c," / ",Se,":",c===1&&"选择要分享的配置",c===2&&"填写模板信息"]})]}),e.jsx(Je,{className:"h-[calc(85vh-220px)] pr-4",children:x?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(Js,{className:"w-8 h-8 mx-auto animate-spin text-primary"}),e.jsx("p",{className:"mt-4 text-muted-foreground",children:"正在加载当前配置..."})]}):e.jsxs(e.Fragment,{children:[c===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(gt,{children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsx(_n,{children:"安全提示"}),e.jsxs(jt,{children:["分享的配置将",e.jsx("strong",{children:"不包含"})," API Key,其他用户需要自行配置。"]})]}),e.jsxs(da,{defaultValue:"providers",className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-3",children:[e.jsxs(Xe,{value:"providers",children:[e.jsx(yl,{className:"w-4 h-4 mr-2"}),"API 提供商",e.jsxs(Te,{variant:"secondary",className:"ml-2",children:[L.size,"/",g.length]})]}),e.jsxs(Xe,{value:"models",children:[e.jsx(kn,{className:"w-4 h-4 mr-2"}),"模型配置",e.jsxs(Te,{variant:"secondary",className:"ml-2",children:[T.size,"/",N.length]})]}),e.jsxs(Xe,{value:"tasks",children:[e.jsx(Tn,{className:"w-4 h-4 mr-2"}),"任务配置",e.jsxs(Te,{variant:"secondary",className:"ml-2",children:[O.size,"/",Object.keys(w).length]})]})]}),e.jsx(ys,{value:"providers",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(k,{variant:"ghost",size:"sm",onClick:H,children:L.size===g.length?"取消全选":"全选"})}),g.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无提供商配置"}):g.map(V=>e.jsxs("div",{className:"flex items-center space-x-2 p-2 rounded hover:bg-muted",children:[e.jsx(Xs,{id:`provider-${V.name}`,checked:L.has(V.name),onCheckedChange:()=>pe(V.name)}),e.jsxs(E,{htmlFor:`provider-${V.name}`,className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:V.name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:V.base_url})]}),e.jsx(Te,{variant:"outline",className:"text-xs",children:V.client_type})]},V.name))]})}),e.jsx(ys,{value:"models",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(k,{variant:"ghost",size:"sm",onClick:U,children:T.size===N.length?"取消全选":"全选"})}),N.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无模型配置"}):N.map(V=>e.jsxs("div",{className:"flex items-center space-x-2 p-2 rounded hover:bg-muted",children:[e.jsx(Xs,{id:`model-${V.name}`,checked:T.has(V.name),onCheckedChange:()=>je(V.name)}),e.jsxs(E,{htmlFor:`model-${V.name}`,className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:V.name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:V.model_identifier})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:V.api_provider})]},V.name))]})}),e.jsx(ys,{value:"tasks",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(k,{variant:"ghost",size:"sm",onClick:$,children:O.size===Object.keys(w).length?"取消全选":"全选"})}),Object.keys(w).length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无任务配置"}):Object.entries(w).map(([V,ye])=>e.jsxs("div",{className:"space-y-2 p-2 rounded hover:bg-muted",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xs,{id:`task-${V}`,checked:O.has(V),onCheckedChange:()=>A(V)}),e.jsx(E,{htmlFor:`task-${V}`,className:"flex-1 cursor-pointer",children:e.jsx("span",{className:"font-medium",children:R_[V]||V})}),e.jsxs(Te,{variant:"outline",className:"text-xs",children:[ye.model_list.length," 个模型"]})]}),ye.model_list&&ye.model_list.length>0&&e.jsx("div",{className:"ml-6 flex flex-wrap gap-1",children:ye.model_list.map(W=>{const ue=N.find(J=>J.name===W),ke=T.has(W);return e.jsxs(Te,{variant:ke?"default":"outline",className:"text-xs cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>je(W),children:[W,ue&&e.jsxs("span",{className:"ml-1 opacity-70",children:["(",ue.api_provider,")"]})]},W)})})]},V))]})})]})]}),c===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-4 text-sm p-3 bg-muted rounded-lg",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(yl,{className:"w-4 h-4"}),L.size," 个提供商"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(kn,{className:"w-4 h-4"}),T.size," 个模型"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Tn,{className:"w-4 h-4"}),O.size," 个任务"]})]}),e.jsx(Or,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"pack-name",children:"模板名称 *"}),e.jsx(re,{id:"pack-name",placeholder:"例如:高性价比国产模型配置",value:C,onChange:V=>P(V.target.value),maxLength:50}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[C.length,"/50"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"pack-description",children:"模板描述 *"}),e.jsx(Ys,{id:"pack-description",placeholder:"详细描述这个配置模板的特点、适用场景等...",value:M,onChange:V=>Z(V.target.value),rows:4,maxLength:500}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[M.length,"/500"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"pack-author",children:"作者名称 *"}),e.jsx(re,{id:"pack-author",placeholder:"你的昵称或 ID",value:G,onChange:V=>ce(V.target.value),maxLength:30})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:"标签(可选,最多 5 个)"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:L_.map(V=>e.jsxs(Te,{variant:de.includes(V)?"default":"outline",className:"cursor-pointer transition-colors",onClick:()=>Y(V),children:[de.includes(V)&&e.jsx(_t,{className:"w-3 h-3 mr-1"}),e.jsx(Rm,{className:"w-3 h-3 mr-1"}),V]},V))})]})]}),e.jsxs(gt,{children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsx(_n,{children:"审核说明"}),e.jsx(jt,{children:"提交后需要经过审核才能在市场中展示。审核通常在 1-3 个工作日内完成。"})]})]})]})}),e.jsxs(rt,{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:c>1&&e.jsx(k,{variant:"outline",onClick:()=>u(c-1),disabled:f,children:"上一步"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{variant:"outline",onClick:()=>{i(!1),Ne()},disabled:f,children:"取消"}),cu(c+1),disabled:x||L.size===0&&T.size===0&&O.size===0,children:"下一步"}):e.jsxs(k,{onClick:_e,disabled:f,children:[f&&e.jsx(Js,{className:"w-4 h-4 mr-2 animate-spin"}),"提交审核"]})]})]})]})]})}function B_({value:l,label:n,onRemove:i}){const{attributes:c,listeners:u,setNodeRef:x,transform:h,transition:f,isDragging:p}=Oj({id:l}),g={transform:Rj.Transform.toString(h),transition:f,opacity:p?.5:1},v=y=>{y.preventDefault(),y.stopPropagation(),i(l)},N=y=>{y.stopPropagation()};return e.jsx("div",{ref:x,style:g,className:B("inline-flex items-center gap-1",p&&"shadow-lg"),children:e.jsxs(Te,{variant:"secondary",className:"cursor-move hover:bg-secondary/80 flex items-center gap-1",children:[e.jsx("div",{...c,...u,className:"cursor-grab active:cursor-grabbing flex items-center",children:e.jsx(hj,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx("span",{children:n}),e.jsx("button",{type:"button",className:"ml-1 rounded-sm hover:bg-destructive/20 focus:outline-none focus:ring-1 focus:ring-destructive",onClick:v,onPointerDown:N,onMouseDown:y=>y.stopPropagation(),children:e.jsx(Da,{className:"h-3 w-3 cursor-pointer hover:text-destructive",strokeWidth:2,fill:"none"})})]})})}function $_({options:l,selected:n,onChange:i,placeholder:c="选择选项...",emptyText:u="未找到选项",className:x}){const[h,f]=m.useState(!1),p=Cj(Co(Ej,{activationConstraint:{distance:8}}),Co(Tj,{coordinateGetter:kj})),g=y=>{n.includes(y)?i(n.filter(w=>w!==y)):i([...n,y])},v=y=>{i(n.filter(w=>w!==y))},N=y=>{const{active:w,over:b}=y;if(b&&w.id!==b.id){const L=n.indexOf(w.id),D=n.indexOf(b.id);i(Mj(n,L,D))}};return e.jsxs(Xa,{open:h,onOpenChange:f,children:[e.jsx(Za,{asChild:!0,children:e.jsxs(k,{variant:"outline",role:"combobox","aria-expanded":h,className:B("w-full justify-between min-h-10 h-auto",x),children:[e.jsx(Aj,{sensors:p,collisionDetection:zj,onDragEnd:N,children:e.jsx(Dj,{items:n,strategy:l1,children:e.jsx("div",{className:"flex gap-1 flex-wrap flex-1",children:n.length===0?e.jsx("span",{className:"text-muted-foreground",children:c}):n.map(y=>{const w=l.find(b=>b.value===y);return e.jsx(B_,{value:y,label:w?.label||y,onRemove:v},y)})})})}),e.jsx(Om,{className:"ml-2 h-4 w-4 shrink-0 opacity-50",strokeWidth:2,fill:"none"})]})}),e.jsx(Ia,{className:"w-full p-0",align:"start",children:e.jsxs($o,{children:[e.jsx(Ho,{placeholder:"搜索...",className:"h-9"}),e.jsxs(Io,{children:[e.jsx(Po,{children:u}),e.jsx(Ii,{children:l.map(y=>{const w=n.includes(y.value);return e.jsxs(Pi,{value:y.value,onSelect:()=>g(y.value),children:[e.jsx("div",{className:B("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",w?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(_t,{className:"h-3 w-3",strokeWidth:2,fill:"none"})}),e.jsx("span",{children:y.label})]},y.value)})})]})]})})]})}const $a=Ts.memo(function({title:n,description:i,taskConfig:c,modelNames:u,onChange:x,hideTemperature:h=!1,hideMaxTokens:f=!1,dataTour:p}){const g=v=>{x("model_list",v)};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-base sm:text-lg",children:n}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:i})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":p,children:[e.jsx(E,{children:"模型列表"}),e.jsx($_,{options:u.map(v=>({label:v,value:v})),selected:c.model_list||[],onChange:g,placeholder:"选择模型...",emptyText:"暂无可用模型"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[!h&&e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{children:"温度"}),e.jsx(re,{type:"number",step:"0.1",min:"0",max:"1",value:c.temperature??.3,onChange:v=>{const N=parseFloat(v.target.value);!isNaN(N)&&N>=0&&N<=1&&x("temperature",N)},className:"w-20 h-8 text-sm"})]}),e.jsx(Na,{value:[c.temperature??.3],onValueChange:v=>x("temperature",v[0]),min:0,max:1,step:.1,className:"w-full"})]}),!f&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{children:"最大 Token"}),e.jsx(re,{type:"number",step:"1",min:"1",value:c.max_tokens??1024,onChange:v=>x("max_tokens",parseInt(v.target.value))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{children:"慢请求阈值 (秒)"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"超时警告"})]}),e.jsx(re,{type:"number",step:"1",min:"1",value:c.slow_threshold??15,onChange:v=>{const N=parseInt(v.target.value);!isNaN(N)&&N>=1&&x("slow_threshold",N)},placeholder:"15"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"模型响应时间超过此阈值将输出警告日志"})]})]})]})}),H_=Ts.memo(function({paginatedModels:n,allModels:i,onEdit:c,onDelete:u,isModelUsed:x,searchQuery:h}){return n.length===0?e.jsx("div",{className:"md:hidden text-center text-muted-foreground py-8 rounded-lg border bg-card",children:h?"未找到匹配的模型":"暂无模型配置"}):e.jsx("div",{className:"md:hidden space-y-3",children:n.map((f,p)=>{const g=i.findIndex(N=>N===f),v=x(f.name);return e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold text-base",children:f.name}),e.jsx(Te,{variant:v?"default":"secondary",className:v?"bg-green-600 hover:bg-green-700":"",children:v?"已使用":"未使用"})]}),e.jsx("p",{className:"text-xs text-muted-foreground break-all",title:f.model_identifier,children:f.model_identifier})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs(k,{variant:"default",size:"sm",onClick:()=>c(f,g),children:[e.jsx(Cn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(k,{size:"sm",onClick:()=>u(g),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"提供商"}),e.jsx("p",{className:"font-medium",children:f.api_provider})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"模型温度"}),e.jsx("p",{className:"font-medium",children:f.temperature!=null?f.temperature:e.jsx("span",{className:"text-muted-foreground",children:"默认"})})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输入价格"}),e.jsxs("p",{className:"font-medium",children:["¥",f.price_in,"/M"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输出价格"}),e.jsxs("p",{className:"font-medium",children:["¥",f.price_out,"/M"]})]})]})]},p)})})}),I_=Ts.memo(function({paginatedModels:n,allModels:i,filteredModels:c,selectedModels:u,onEdit:x,onDelete:h,onToggleSelection:f,onToggleSelectAll:p,isModelUsed:g,searchQuery:v}){return e.jsx("div",{className:"hidden md:block rounded-lg border bg-card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(wl,{children:[e.jsx(_l,{children:e.jsxs(nt,{children:[e.jsx(Qe,{className:"w-12",children:e.jsx(Xs,{checked:u.size===c.length&&c.length>0,onCheckedChange:p})}),e.jsx(Qe,{className:"w-24",children:"使用状态"}),e.jsx(Qe,{children:"模型名称"}),e.jsx(Qe,{children:"模型标识符"}),e.jsx(Qe,{children:"提供商"}),e.jsx(Qe,{className:"text-center",children:"温度"}),e.jsx(Qe,{className:"text-right",children:"输入价格"}),e.jsx(Qe,{className:"text-right",children:"输出价格"}),e.jsx(Qe,{className:"text-right",children:"操作"})]})}),e.jsx(Sl,{children:n.length===0?e.jsx(nt,{children:e.jsx(Ie,{colSpan:9,className:"text-center text-muted-foreground py-8",children:v?"未找到匹配的模型":"暂无模型配置"})}):n.map((N,y)=>{const w=i.findIndex(L=>L===N),b=g(N.name);return e.jsxs(nt,{children:[e.jsx(Ie,{children:e.jsx(Xs,{checked:u.has(w),onCheckedChange:()=>f(w)})}),e.jsx(Ie,{children:e.jsx(Te,{variant:b?"default":"secondary",className:b?"bg-green-600 hover:bg-green-700":"",children:b?"已使用":"未使用"})}),e.jsx(Ie,{className:"font-medium",children:N.name}),e.jsx(Ie,{className:"max-w-xs truncate",title:N.model_identifier,children:N.model_identifier}),e.jsx(Ie,{children:N.api_provider}),e.jsx(Ie,{className:"text-center",children:N.temperature!=null?N.temperature:e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsxs(Ie,{className:"text-right",children:["¥",N.price_in,"/M"]}),e.jsxs(Ie,{className:"text-right",children:["¥",N.price_out,"/M"]}),e.jsx(Ie,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(k,{variant:"default",size:"sm",onClick:()=>x(N,w),children:[e.jsx(Cn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(k,{size:"sm",onClick:()=>h(w),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},y)})})]})})})}),P_=300*1e3,ig=new Map,G_=[10,20,50,100],q_=Ts.memo(function({page:n,pageSize:i,totalItems:c,jumpToPage:u,onPageChange:x,onPageSizeChange:h,onJumpToPageChange:f,onJumpToPage:p,onSelectionClear:g}){const v=Math.ceil(c/i),N=w=>{h(parseInt(w)),x(1),g?.()},y=w=>{w.key==="Enter"&&p()};return c===0?null:e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{htmlFor:"page-size-model",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Le,{value:i.toString(),onValueChange:N,children:[e.jsx(Oe,{id:"page-size-model",className:"w-20",children:e.jsx(Ue,{})}),e.jsx(Re,{children:G_.map(w=>e.jsx(le,{value:w.toString(),children:w},w))})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(n-1)*i+1," 到"," ",Math.min(n*i,c)," 条,共 ",c," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>x(1),disabled:n===1,className:"hidden sm:flex",children:e.jsx(zr,{className:"h-4 w-4"})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>x(Math.max(1,n-1)),disabled:n===1,children:[e.jsx(Wa,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"上一页"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{type:"number",value:u,onChange:w=>f(w.target.value),onKeyDown:y,placeholder:n.toString(),className:"w-16 h-8 text-center",min:1,max:v}),e.jsx(k,{variant:"outline",size:"sm",onClick:p,disabled:!u,className:"h-8",children:"跳转"})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>x(n+1),disabled:n>=v,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>x(v),disabled:n>=v,className:"hidden sm:flex",children:e.jsx(Dr,{className:"h-4 w-4"})})]})]})});function F_(l){const{models:n,taskConfig:i,debounceMs:c=2e3,onSavingChange:u,onUnsavedChange:x}=l,h=m.useRef(null),f=m.useRef(null),p=m.useRef(!0),g=m.useCallback(()=>{h.current&&(clearTimeout(h.current),h.current=null),f.current&&(clearTimeout(f.current),f.current=null)},[]),v=m.useCallback(w=>{const b={model_identifier:w.model_identifier,name:w.name,api_provider:w.api_provider,price_in:w.price_in??0,price_out:w.price_out??0,force_stream_mode:w.force_stream_mode??!1,extra_params:w.extra_params??{}};return w.temperature!=null&&(b.temperature=w.temperature),w.max_tokens!=null&&(b.max_tokens=w.max_tokens),b},[]),N=m.useCallback(async w=>{try{u?.(!0);const b=w.map(v);await Tm("models",b),x?.(!1)}catch(b){console.error("自动保存模型列表失败:",b),x?.(!0)}finally{u?.(!1)}},[u,x,v]),y=m.useCallback(async w=>{try{u?.(!0),await Tm("model_task_config",w),x?.(!1)}catch(b){console.error("自动保存任务配置失败:",b),x?.(!0)}finally{u?.(!1)}},[u,x]);return m.useEffect(()=>{if(!p.current)return x?.(!0),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{N(n)},c),()=>{h.current&&clearTimeout(h.current)}},[n,N,c,x]),m.useEffect(()=>{if(!(p.current||!i))return x?.(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{y(i)},c),()=>{f.current&&clearTimeout(f.current)}},[i,y,c,x]),m.useEffect(()=>()=>{g()},[g]),{clearTimers:g,initialLoadRef:p}}function V_(l={}){const{onCloseEditDialog:n}=l,i=ua(),{registerTour:c,startTour:u,state:x,goToStep:h}=Bm(),f=m.useRef(x.stepIndex);return m.useEffect(()=>{c(Ya,ev)},[c]),m.useEffect(()=>{if(x.activeTourId===Ya&&x.isRunning){const g=sv[x.stepIndex];g&&!window.location.pathname.endsWith(g.replace("/config/",""))&&i({to:g})}},[x.stepIndex,x.activeTourId,x.isRunning,i]),m.useEffect(()=>{if(x.activeTourId===Ya&&x.isRunning){const g=f.current,v=x.stepIndex;g>=12&&g<=17&&v<12&&n?.(),f.current=v}},[x.stepIndex,x.activeTourId,x.isRunning,n]),m.useEffect(()=>{if(x.activeTourId!==Ya||!x.isRunning)return;const g=v=>{const N=v.target,y=x.stepIndex;y===2&&N.closest('[data-tour="add-provider-button"]')?setTimeout(()=>h(3),300):y===9&&N.closest('[data-tour="provider-cancel-button"]')?setTimeout(()=>h(10),300):y===11&&N.closest('[data-tour="add-model-button"]')?setTimeout(()=>h(12),300):y===17&&N.closest('[data-tour="model-cancel-button"]')?setTimeout(()=>h(18),300):y===18&&N.closest('[data-tour="tasks-tab-trigger"]')&&setTimeout(()=>h(19),300)};return document.addEventListener("click",g,!0),()=>document.removeEventListener("click",g,!0)},[x,h]),{startTour:m.useCallback(()=>{u(Ya)},[u]),isRunning:x.isRunning&&x.activeTourId===Ya,stepIndex:x.stepIndex}}function K_(l){const{getProviderConfig:n}=l,[i,c]=m.useState([]),[u,x]=m.useState(!1),[h,f]=m.useState(null),[p,g]=m.useState(null),v=m.useCallback(()=>{c([]),f(null),g(null)},[]),N=m.useCallback(async(y,w=!1)=>{const b=n(y);if(!b?.base_url){c([]),g(null),f('提供商配置不完整,请先在"模型提供商配置"中配置');return}if(!b.api_key){c([]),g(null),f('该提供商未配置 API Key,请先在"模型提供商配置"中填写');return}const L=N_(b.base_url);if(g(L),!L?.modelFetcher){c([]),f(null);return}const D=`${y}:${b.base_url}`,T=ig.get(D);if(!w&&T&&Date.now()-T.timestampO(!1)}),{clearTimers:ie,initialLoadRef:ve}=F_({models:l,taskConfig:p,onSavingChange:L,onUnsavedChange:T}),Me=m.useCallback(async()=>{try{N(!0);const z=await Xl(),q=z.models||[];n(q),f(q.map(_s=>_s.name));const Be=z.api_providers||[];c(Be.map(_s=>_s.name)),x(Be),g(z.model_task_config||null);const ct=z.model_task_config?.embedding?.model_list||[];ke.current=[...ct],T(!1),ve.current=!1}catch(z){console.error("加载配置失败:",z)}finally{N(!1)}},[ve]);m.useEffect(()=>{Me()},[Me]);const Ze=m.useCallback(z=>u.find(q=>q.name===z),[u]),{availableModels:js,fetchingModels:Ot,modelFetchError:rs,matchedTemplate:Ps,fetchModelsForProvider:Q,clearModels:Ge}=K_({getProviderConfig:Ze});m.useEffect(()=>{F&&S?.api_provider&&Q(S.api_provider)},[F,S?.api_provider,Q]);const He=async()=>{await ge()},Ve=z=>{const q={model_identifier:z.model_identifier,name:z.name,api_provider:z.api_provider,price_in:z.price_in??0,price_out:z.price_out??0,force_stream_mode:z.force_stream_mode??!1,extra_params:z.extra_params??{}};return z.temperature!=null&&(q.temperature=z.temperature),z.max_tokens!=null&&(q.max_tokens=z.max_tokens),q},Bs=async()=>{try{w(!0),ie();const z=await Xl();z.models=l.map(Ve),z.model_task_config=p,await Li(z),T(!1),Fe({title:"保存成功",description:"正在重启麦麦..."}),await He()}catch(z){console.error("保存配置失败:",z),Fe({title:"保存失败",description:z.message,variant:"destructive"}),w(!1)}},Ce=async()=>{try{w(!0),ie();const z=await Xl();z.models=l.map(Ve),z.model_task_config=p,await Li(z),T(!1),Fe({title:"保存成功",description:"模型配置已保存"}),await Me()}catch(z){console.error("保存配置失败:",z),Fe({title:"保存失败",description:z.message,variant:"destructive"})}finally{w(!1)}},cs=(z,q)=>{De({}),C(z||{model_identifier:"",name:"",api_provider:i[0]||"",price_in:0,price_out:0,temperature:null,max_tokens:null,force_stream_mode:!1,extra_params:{}}),M(q),O(!0)},Es=()=>{if(!S)return;const z={};if(S.name?.trim()||(z.name="请输入模型名称"),S.api_provider?.trim()||(z.api_provider="请选择 API 提供商"),S.model_identifier?.trim()||(z.model_identifier="请输入模型标识符"),Object.keys(z).length>0){De(z);return}De({});const q={model_identifier:S.model_identifier,name:S.name,api_provider:S.api_provider,price_in:S.price_in??0,price_out:S.price_out??0,force_stream_mode:S.force_stream_mode??!1,extra_params:S.extra_params??{}};S.temperature!=null&&(q.temperature=S.temperature),S.max_tokens!=null&&(q.max_tokens=S.max_tokens);let Be,ct=null;if(P!==null?(ct=l[P].name,Be=[...l],Be[P]=q):Be=[...l,q],n(Be),f(Be.map(_s=>_s.name)),ct&&ct!==q.name&&p){const _s=st=>st.map(Nt=>Nt===ct?q.name:Nt);g({...p,utils:{...p.utils,model_list:_s(p.utils?.model_list||[])},utils_small:{...p.utils_small,model_list:_s(p.utils_small?.model_list||[])},tool_use:{...p.tool_use,model_list:_s(p.tool_use?.model_list||[])},replyer:{...p.replyer,model_list:_s(p.replyer?.model_list||[])},planner:{...p.planner,model_list:_s(p.planner?.model_list||[])},vlm:{...p.vlm,model_list:_s(p.vlm?.model_list||[])},voice:{...p.voice,model_list:_s(p.voice?.model_list||[])},embedding:{...p.embedding,model_list:_s(p.embedding?.model_list||[])},lpmm_entity_extract:{...p.lpmm_entity_extract,model_list:_s(p.lpmm_entity_extract?.model_list||[])},lpmm_rdf_build:{...p.lpmm_rdf_build,model_list:_s(p.lpmm_rdf_build?.model_list||[])},lpmm_qa:{...p.lpmm_qa,model_list:_s(p.lpmm_qa?.model_list||[])}})}O(!1),C(null),M(null)},zs=z=>{if(!z&&S){const q={...S,price_in:S.price_in??0,price_out:S.price_out??0};C(q)}O(z)},es=z=>{de(z),G(!0)},We=()=>{if(ce!==null){const z=l.filter((q,Be)=>Be!==ce);n(z),f(z.map(q=>q.name)),Fe({title:"删除成功",description:"模型已从列表中移除"})}G(!1),de(null)},vs=z=>{const q=new Set(pe);q.has(z)?q.delete(z):q.add(z),je(q)},mt=()=>{if(pe.size===Mt.length)je(new Set);else{const z=Mt.map((q,Be)=>l.findIndex(ct=>ct===Mt[Be]));je(new Set(z))}},Rt=()=>{if(pe.size===0){Fe({title:"提示",description:"请先选择要删除的模型",variant:"default"});return}Y(!0)},it=()=>{const z=l.filter((q,Be)=>!pe.has(Be));n(z),f(z.map(q=>q.name)),je(new Set),Y(!1),Fe({title:"批量删除成功",description:`已删除 ${pe.size} 个模型`})},ss=(z,q,Be)=>{if(p){if(z==="embedding"&&q==="model_list"&&Array.isArray(Be)){const ct=ke.current,_s=Be;if((ct.length!==_s.length||ct.some(Nt=>!_s.includes(Nt))||_s.some(Nt=>!ct.includes(Nt)))&&ct.length>0){J.current={field:q,value:Be},ue(!0);return}}g({...p,[z]:{...p[z],[q]:Be}}),z==="embedding"&&q==="model_list"&&Array.isArray(Be)&&(ke.current=[...Be])}},St=()=>{if(!p||!J.current)return;const{field:z,value:q}=J.current;g({...p,embedding:{...p.embedding,[z]:q}}),z==="model_list"&&Array.isArray(q)&&(ke.current=[...q]),J.current=null,ue(!1),Fe({title:"嵌入模型已更新",description:"建议重新生成知识库向量以确保最佳匹配精度"})},$t=()=>{J.current=null,ue(!1)},Mt=l.filter(z=>{if(!be)return!0;const q=be.toLowerCase();return z.name.toLowerCase().includes(q)||z.model_identifier.toLowerCase().includes(q)||z.api_provider.toLowerCase().includes(q)}),Ga=Math.ceil(Mt.length/$),qa=Mt.slice((H-1)*$,H*$),Rn=()=>{const z=parseInt(Ne);z>=1&&z<=Ga&&(U(z),Se(""))},X=z=>p?[p.utils?.model_list||[],p.utils_small?.model_list||[],p.tool_use?.model_list||[],p.replyer?.model_list||[],p.planner?.model_list||[],p.vlm?.model_list||[],p.voice?.model_list||[],p.embedding?.model_list||[],p.lpmm_entity_extract?.model_list||[],p.lpmm_rdf_build?.model_list||[],p.lpmm_qa?.model_list||[]].some(Be=>Be.includes(z)):!1;return v?e.jsx(Je,{className:"h-full",children:e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})})}):e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"模型管理与分配"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"添加模型并为模型分配功能"})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(U_,{trigger:e.jsxs(k,{variant:"outline",size:"sm",className:"flex-1 sm:flex-none",children:[e.jsx(gj,{className:"mr-2 h-4 w-4"}),"分享配置"]})}),e.jsxs(k,{onClick:Ce,disabled:y||b||!D||as,size:"sm",variant:"outline",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(Ki,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),y?"保存中...":b?"自动保存中...":D?"保存配置":"已保存"]}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsxs(k,{disabled:y||b||as,size:"sm",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(Vi,{className:"mr-2 h-4 w-4"}),as?"重启中...":D?"保存并重启":"重启麦麦"]})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认重启麦麦?"}),e.jsx(hs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:D?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:D?Bs:He,children:D?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(gt,{children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(jt,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),e.jsxs(gt,{className:"hidden lg:flex border-primary/30 bg-primary/5 cursor-pointer hover:bg-primary/10 transition-colors",onClick:ae,children:[e.jsx(Aw,{className:"h-4 w-4 text-primary"}),e.jsxs(jt,{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[e.jsx("strong",{className:"text-primary",children:"新手引导:"}),"不知道如何配置模型?点击这里开始学习如何为麦麦的组件分配模型。"]}),e.jsx(k,{variant:"outline",size:"sm",className:"ml-4 shrink-0",children:"开始引导"})]})]}),e.jsxs(da,{defaultValue:"models",className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full max-w-full sm:max-w-md grid-cols-2",children:[e.jsx(Xe,{value:"models",children:"添加模型"}),e.jsx(Xe,{value:"tasks","data-tour":"tasks-tab-trigger",children:"为模型分配功能"})]}),e.jsxs(ys,{value:"models",className:"space-y-4 mt-0",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"配置可用的模型列表"}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[pe.size>0&&e.jsxs(k,{onClick:Rt,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(ns,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",pe.size,")"]}),e.jsxs(k,{onClick:()=>cs(null,null),size:"sm",variant:"outline",className:"w-full sm:w-auto","data-tour":"add-model-button",children:[e.jsx(lt,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"添加模型"]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-2",children:[e.jsxs("div",{className:"relative w-full sm:flex-1 sm:max-w-sm",children:[e.jsx(Vt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(re,{placeholder:"搜索模型名称、标识符或提供商...",value:be,onChange:z=>me(z.target.value),className:"pl-9"})]}),be&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",Mt.length," 个结果"]})]}),e.jsx(H_,{paginatedModels:qa,allModels:l,onEdit:cs,onDelete:es,isModelUsed:X,searchQuery:be}),e.jsx(I_,{paginatedModels:qa,allModels:l,filteredModels:Mt,selectedModels:pe,onEdit:cs,onDelete:es,onToggleSelection:vs,onToggleSelectAll:mt,isModelUsed:X,searchQuery:be}),e.jsx(q_,{page:H,pageSize:$,totalItems:Mt.length,jumpToPage:Ne,onPageChange:U,onPageSizeChange:_e,onJumpToPageChange:Se,onJumpToPage:Rn,onSelectionClear:()=>je(new Set)})]}),e.jsxs(ys,{value:"tasks",className:"space-y-6 mt-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"为不同的任务配置使用的模型和参数"}),p&&e.jsxs("div",{className:"grid gap-4 sm:gap-6",children:[e.jsx($a,{title:"组件模型 (utils)",description:"用于表情包、取名、关系、情绪变化等组件",taskConfig:p.utils,modelNames:h,onChange:(z,q)=>ss("utils",z,q),dataTour:"task-model-select"}),e.jsx($a,{title:"组件小模型 (utils_small)",description:"消耗量较大的组件,建议使用速度较快的小模型",taskConfig:p.utils_small,modelNames:h,onChange:(z,q)=>ss("utils_small",z,q)}),e.jsx($a,{title:"工具调用模型 (tool_use)",description:"需要使用支持工具调用的模型",taskConfig:p.tool_use,modelNames:h,onChange:(z,q)=>ss("tool_use",z,q)}),e.jsx($a,{title:"首要回复模型 (replyer)",description:"用于表达器和表达方式学习",taskConfig:p.replyer,modelNames:h,onChange:(z,q)=>ss("replyer",z,q)}),e.jsx($a,{title:"决策模型 (planner)",description:"负责决定麦麦该什么时候回复",taskConfig:p.planner,modelNames:h,onChange:(z,q)=>ss("planner",z,q)}),e.jsx($a,{title:"图像识别模型 (vlm)",description:"视觉语言模型",taskConfig:p.vlm,modelNames:h,onChange:(z,q)=>ss("vlm",z,q),hideTemperature:!0}),e.jsx($a,{title:"语音识别模型 (voice)",description:"语音转文字",taskConfig:p.voice,modelNames:h,onChange:(z,q)=>ss("voice",z,q),hideTemperature:!0,hideMaxTokens:!0}),e.jsx($a,{title:"嵌入模型 (embedding)",description:"用于向量化",taskConfig:p.embedding,modelNames:h,onChange:(z,q)=>ss("embedding",z,q),hideTemperature:!0,hideMaxTokens:!0}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库模型"}),e.jsx($a,{title:"实体提取模型 (lpmm_entity_extract)",description:"从文本中提取实体",taskConfig:p.lpmm_entity_extract,modelNames:h,onChange:(z,q)=>ss("lpmm_entity_extract",z,q)}),e.jsx($a,{title:"RDF 构建模型 (lpmm_rdf_build)",description:"构建知识图谱",taskConfig:p.lpmm_rdf_build,modelNames:h,onChange:(z,q)=>ss("lpmm_rdf_build",z,q)}),e.jsx($a,{title:"问答模型 (lpmm_qa)",description:"知识库问答",taskConfig:p.lpmm_qa,modelNames:h,onChange:(z,q)=>ss("lpmm_qa",z,q)})]})]})]})]}),e.jsx(Is,{open:F,onOpenChange:zs,children:e.jsxs(Rs,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"model-dialog",preventOutsideClose:Ee,children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:P!==null?"编辑模型":"添加模型"}),e.jsx(Zs,{children:"配置模型的基本信息和参数"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":"model-name-input",children:[e.jsx(E,{htmlFor:"model_name",className:ee.name?"text-destructive":"",children:"模型名称 *"}),e.jsx(re,{id:"model_name",value:S?.name||"",onChange:z=>{C(q=>q?{...q,name:z.target.value}:null),ee.name&&De(q=>({...q,name:void 0}))},placeholder:"例如: qwen3-30b",className:ee.name?"border-destructive focus-visible:ring-destructive":""}),ee.name?e.jsx("p",{className:"text-xs text-destructive",children:ee.name}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于在任务配置中引用此模型"})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-provider-select",children:[e.jsx(E,{htmlFor:"api_provider",className:ee.api_provider?"text-destructive":"",children:"API 提供商 *"}),e.jsxs(Le,{value:S?.api_provider||"",onValueChange:z=>{C(q=>q?{...q,api_provider:z}:null),Ge(),ee.api_provider&&De(q=>({...q,api_provider:void 0}))},children:[e.jsx(Oe,{id:"api_provider",className:ee.api_provider?"border-destructive focus-visible:ring-destructive":"",children:e.jsx(Ue,{placeholder:"选择提供商"})}),e.jsx(Re,{children:i.map(z=>e.jsx(le,{value:z,children:z},z))})]}),ee.api_provider&&e.jsx("p",{className:"text-xs text-destructive",children:ee.api_provider})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-identifier-input",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{htmlFor:"model_identifier",className:ee.model_identifier?"text-destructive":"",children:"模型标识符 *"}),Ps?.modelFetcher&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Te,{variant:"secondary",className:"text-xs",children:Ps.display_name}),e.jsx(k,{variant:"ghost",size:"sm",className:"h-6 px-2",onClick:()=>S?.api_provider&&Q(S.api_provider,!0),disabled:Ot,children:Ot?e.jsx(Js,{className:"h-3 w-3 animate-spin"}):e.jsx(zt,{className:"h-3 w-3"})})]})]}),Ps?.modelFetcher?e.jsxs(Xa,{open:V,onOpenChange:ye,children:[e.jsx(Za,{asChild:!0,children:e.jsxs(k,{variant:"outline",role:"combobox","aria-expanded":V,className:"w-full justify-between font-normal",disabled:Ot||!!rs,children:[Ot?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(Js,{className:"h-4 w-4 animate-spin"}),"正在获取模型列表..."]}):rs?e.jsx("span",{className:"text-muted-foreground text-sm",children:"点击下方输入框手动填写"}):S?.model_identifier?e.jsx("span",{className:"truncate",children:S.model_identifier}):e.jsx("span",{className:"text-muted-foreground",children:"搜索或选择模型..."}),e.jsx(Om,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(Ia,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs($o,{children:[e.jsx(Ho,{placeholder:"搜索模型..."}),e.jsx(Je,{className:"h-[300px]",children:e.jsxs(Io,{className:"max-h-none overflow-visible",children:[e.jsx(Po,{children:rs?e.jsxs("div",{className:"py-4 px-2 text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:rs}),!rs.includes("API Key")&&e.jsx(k,{variant:"link",size:"sm",onClick:()=>S?.api_provider&&Q(S.api_provider,!0),children:"重试"})]}):"未找到匹配的模型"}),e.jsx(Ii,{heading:"可用模型",children:js.map(z=>e.jsxs(Pi,{value:z.id,onSelect:()=>{C(q=>q?{...q,model_identifier:z.id}:null),ye(!1)},children:[e.jsx(_t,{className:`mr-2 h-4 w-4 ${S?.model_identifier===z.id?"opacity-100":"opacity-0"}`}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:z.id}),z.name!==z.id&&e.jsx("span",{className:"text-xs text-muted-foreground",children:z.name})]})]},z.id))}),e.jsx(Ii,{heading:"手动输入",children:e.jsxs(Pi,{value:"__manual_input__",onSelect:()=>{ye(!1)},children:[e.jsx(Cn,{className:"mr-2 h-4 w-4"}),"手动输入模型标识符..."]})})]})})]})})]}):e.jsx(re,{id:"model_identifier",value:S?.model_identifier||"",onChange:z=>{C(q=>q?{...q,model_identifier:z.target.value}:null),ee.model_identifier&&De(q=>({...q,model_identifier:void 0}))},placeholder:"Qwen/Qwen3-30B-A3B-Instruct-2507",className:ee.model_identifier?"border-destructive focus-visible:ring-destructive":""}),ee.model_identifier&&e.jsx("p",{className:"text-xs text-destructive",children:ee.model_identifier}),rs&&Ps?.modelFetcher&&!ee.model_identifier&&e.jsxs(gt,{variant:"destructive",className:"mt-2 py-2",children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsx(jt,{className:"text-xs",children:rs})]}),Ps?.modelFetcher&&e.jsx(re,{value:S?.model_identifier||"",onChange:z=>{C(q=>q?{...q,model_identifier:z.target.value}:null),ee.model_identifier&&De(q=>({...q,model_identifier:void 0}))},placeholder:"或手动输入模型标识符",className:`mt-2 ${ee.model_identifier?"border-destructive focus-visible:ring-destructive":""}`}),!ee.model_identifier&&e.jsx("p",{className:"text-xs text-muted-foreground",children:rs?'请手动输入模型标识符,或前往"模型提供商配置"检查 API Key':Ps?.modelFetcher?`已识别为 ${Ps.display_name},支持自动获取模型列表`:"API 提供商提供的模型 ID"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"price_in",children:"输入价格 (¥/M token)"}),e.jsx(re,{id:"price_in",type:"number",step:"0.1",min:"0",value:S?.price_in??"",onChange:z=>{const q=z.target.value===""?null:parseFloat(z.target.value);C(Be=>Be?{...Be,price_in:q}:null)},placeholder:"默认: 0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"price_out",children:"输出价格 (¥/M token)"}),e.jsx(re,{id:"price_out",type:"number",step:"0.1",min:"0",value:S?.price_out??"",onChange:z=>{const q=z.target.value===""?null:parseFloat(z.target.value);C(Be=>Be?{...Be,price_out:q}:null)},placeholder:"默认: 0"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{htmlFor:"enable_model_temperature",className:"cursor-pointer",children:"自定义模型温度"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务温度配置"})]}),e.jsx(Pe,{id:"enable_model_temperature",checked:S?.temperature!=null,onCheckedChange:z=>{C(z?q=>q?{...q,temperature:.5}:null:q=>q?{...q,temperature:null}:null)}})]}),S?.temperature!=null&&e.jsxs("div",{className:"space-y-2 pt-2 border-t",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{className:"text-sm",children:"温度值"}),e.jsx("span",{className:"text-sm font-medium tabular-nums",children:S.temperature.toFixed(1)})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"0"}),e.jsx(Na,{value:[S.temperature],onValueChange:z=>C(q=>q?{...q,temperature:z[0]}:null),min:0,max:1,step:.1,className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"较低的温度(0.1-0.3)产生更确定的输出,较高的温度(0.7-1.0)产生更多样化的输出"})]})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{htmlFor:"enable_model_max_tokens",className:"cursor-pointer",children:"自定义最大 Token"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务最大 Token 配置"})]}),e.jsx(Pe,{id:"enable_model_max_tokens",checked:S?.max_tokens!=null,onCheckedChange:z=>{C(z?q=>q?{...q,max_tokens:2048}:null:q=>q?{...q,max_tokens:null}:null)}})]}),S?.max_tokens!=null&&e.jsxs("div",{className:"space-y-2 pt-2 border-t",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{className:"text-sm",children:"最大 Token 数"}),e.jsx(re,{type:"number",min:"1",max:"128000",value:S.max_tokens,onChange:z=>{const q=parseInt(z.target.value);!isNaN(q)&&q>=1&&C(Be=>Be?{...Be,max_tokens:q}:null)},className:"w-28 h-8 text-sm"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"限制模型单次输出的最大 token 数量,不同模型支持的上限不同"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"force_stream_mode",checked:S?.force_stream_mode||!1,onCheckedChange:z=>C(q=>q?{...q,force_stream_mode:z}:null)}),e.jsx(E,{htmlFor:"force_stream_mode",className:"cursor-pointer",children:"强制流式输出模式"})]}),e.jsx(k_,{value:S?.extra_params||{},onChange:z=>C(q=>q?{...q,extra_params:z}:null),placeholder:"添加额外参数(如 enable_thinking、top_p 等)..."})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>O(!1),"data-tour":"model-cancel-button",children:"取消"}),e.jsx(k,{onClick:Es,"data-tour":"model-save-button",children:"保存"})]})]})}),e.jsx(gs,{open:Z,onOpenChange:G,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:['确定要删除模型 "',ce!==null?l[ce]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:We,children:"删除"})]})]})}),e.jsx(gs,{open:A,onOpenChange:Y,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认批量删除"}),e.jsxs(hs,{children:["确定要删除选中的 ",pe.size," 个模型吗? 此操作无法撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:it,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),e.jsx(gs,{open:W,onOpenChange:ue,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsxs(xs,{className:"flex items-center gap-2",children:[e.jsx(Qt,{className:"h-5 w-5 text-amber-500"}),"更换嵌入模型警告"]}),e.jsx(hs,{asChild:!0,children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"注意:"}),"更换嵌入模型可能会影响知识库的匹配精度!"]}),e.jsxs("ul",{className:"space-y-2 ml-4 list-disc text-muted-foreground",children:[e.jsx("li",{children:"不同的嵌入模型会产生不同的向量表示"}),e.jsx("li",{children:"这可能导致现有知识库的检索结果不准确"}),e.jsx("li",{children:"建议更换嵌入模型后重新生成所有知识库的向量"})]}),e.jsx("p",{className:"text-foreground font-medium",children:"确定要更换嵌入模型吗?"})]})})]}),e.jsxs(ms,{children:[e.jsx(ps,{onClick:$t,children:"取消"}),e.jsx(fs,{onClick:St,className:"bg-amber-600 hover:bg-amber-700",children:"确认更换"})]})]})}),e.jsx(On,{})]})})}const Gi=Lg,qi=b0,Fi=y0,Go="/api/webui/config";async function J_(){const n=await(await we(`${Go}/adapter-config/path`)).json();return!n.success||!n.path?null:{path:n.path,lastModified:n.lastModified}}async function cg(l){const i=await(await we(`${Go}/adapter-config/path`,{method:"POST",headers:Os(),body:JSON.stringify({path:l})})).json();if(!i.success)throw new Error(i.message||"保存路径失败")}async function og(l){const i=await(await we(`${Go}/adapter-config?path=${encodeURIComponent(l)}`)).json();if(!i.success)throw new Error("读取配置文件失败");return i.content}async function dg(l,n){const c=await(await we(`${Go}/adapter-config`,{method:"POST",headers:Os(),body:JSON.stringify({path:l,content:n})})).json();if(!c.success)throw new Error(c.message||"保存配置失败")}const ft={inner:{version:"0.1.2"},nickname:{nickname:""},napcat_server:{host:"localhost",port:8095,token:"",heartbeat_interval:30},maibot_server:{host:"localhost",port:8e3},chat:{group_list_type:"whitelist",group_list:[],private_list_type:"whitelist",private_list:[],ban_user_id:[],ban_qq_bot:!1,enable_poke:!0},voice:{use_tts:!1},debug:{level:"INFO"}},gm={oneclick:{name:"一键包",description:"使用一键包部署的适配器配置",path:"../MaiBot-Napcat-Adapter/config.toml",icon:ca},docker:{name:"Docker",description:"Docker Compose 部署的适配器配置",path:"/MaiMBot/adapters-config/config.toml",icon:zw}};function X_(l,n){let i=l.slice(0,n).split(/\r\n|\n|\r/g);return[i.length,i.pop().length+1]}function Z_(l,n,i){let c=l.split(/\r\n|\n|\r/g),u="",x=(Math.log10(n+1)|0)+1;for(let h=n-1;h<=n+1;h++){let f=c[h-1];f&&(u+=h.toString().padEnd(x," "),u+=": ",u+=f,u+=` `,h===n&&(u+=" ".repeat(x+i+2),u+=`^ `))}return u}class ws extends Error{line;column;codeblock;constructor(n,i){const[c,u]=X_(i.toml,i.ptr),x=Z_(i.toml,c,u);super(`Invalid TOML document: ${n} ${x}`,i),this.line=c,this.column=u,this.codeblock=x}}function W_(l,n){let i=0;for(;l[n-++i]==="\\";);return--i&&i%2}function Eo(l,n=0,i=l.length){let c=l.indexOf(` `,n);return l[c-1]==="\r"&&c--,c<=i?c:-1}function $m(l,n){for(let i=n;i-1&&i!=="'"&&W_(l,n));return n>-1&&(n+=c.length,c.length>1&&(l[n]===i&&n++,l[n]===i&&n++)),n}let eS=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}:\d{2}(?:\.\d+)?)?(Z|[-+]\d{2}:\d{2})?$/i;class Sr extends Date{#s=!1;#t=!1;#e=null;constructor(n){let i=!0,c=!0,u="Z";if(typeof n=="string"){let x=n.match(eS);x?(x[1]||(i=!1,n=`0000-01-01T${n}`),c=!!x[2],c&&n[10]===" "&&(n=n.replace(" ","T")),x[2]&&+x[2]>23?n="":(u=x[3]||null,n=n.toUpperCase(),!u&&c&&(n+="Z"))):n=""}super(n),isNaN(this.getTime())||(this.#s=i,this.#t=c,this.#e=u)}isDateTime(){return this.#s&&this.#t}isLocal(){return!this.#s||!this.#t||!this.#e}isDate(){return this.#s&&!this.#t}isTime(){return this.#t&&!this.#s}isValid(){return this.#s||this.#t}toISOString(){let n=super.toISOString();if(this.isDate())return n.slice(0,10);if(this.isTime())return n.slice(11,23);if(this.#e===null)return n.slice(0,-1);if(this.#e==="Z")return n;let i=+this.#e.slice(1,3)*60+ +this.#e.slice(4,6);return i=this.#e[0]==="-"?i:-i,new Date(this.getTime()-i*6e4).toISOString().slice(0,-1)+this.#e}static wrapAsOffsetDateTime(n,i="Z"){let c=new Sr(n);return c.#e=i,c}static wrapAsLocalDateTime(n){let i=new Sr(n);return i.#e=null,i}static wrapAsLocalDate(n){let i=new Sr(n);return i.#t=!1,i.#e=null,i}static wrapAsLocalTime(n){let i=new Sr(n);return i.#s=!1,i.#e=null,i}}let sS=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,tS=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,aS=/^[+-]?0[0-9_]/,lS=/^[0-9a-f]{4,8}$/i,mg={b:"\b",t:" ",n:` `,f:"\f",r:"\r",'"':'"',"\\":"\\"};function cv(l,n=0,i=l.length){let c=l[n]==="'",u=l[n++]===l[n]&&l[n]===l[n+1];u&&(i-=2,l[n+=2]==="\r"&&n++,l[n]===` `&&n++);let x=0,h,f="",p=n;for(;n-1&&($m(l,x),u=u.slice(0,x));let h=u.trimEnd();if(!c){let f=u.indexOf(` `,h.length);if(f>-1)throw new ws("newlines are not allowed in inline tables",{toml:l,ptr:n+f})}return[h,x]}function Hm(l,n,i,c,u){if(c===0)throw new ws("document contains excessively nested structures. aborting.",{toml:l,ptr:n});let x=l[n];if(x==="["||x==="{"){let[p,g]=x==="["?oS(l,n,c,u):cS(l,n,c,u),v=i?ug(l,g,",",i):g;if(g-v&&i==="}"){let N=Eo(l,g,v);if(N>-1)throw new ws("newlines are not allowed in inline tables",{toml:l,ptr:N})}return[p,v]}let h;if(x==='"'||x==="'"){h=iv(l,n);let p=cv(l,n,h);if(i){if(h=bl(l,h,i!=="]"),l[h]&&l[h]!==","&&l[h]!==i&&l[h]!==` `&&l[h]!=="\r")throw new ws("unexpected character encountered",{toml:l,ptr:h});h+=+(l[h]===",")}return[p,h]}h=ug(l,n,",",i);let f=rS(l,n,h-+(l[h-1]===","),i==="]");if(!f[0])throw new ws("incomplete key-value declaration: no value specified",{toml:l,ptr:n});return i&&f[1]>-1&&(h=bl(l,n+f[1]),h+=+(l[h]===",")),[nS(f[0],l,n,u),h]}let iS=/^[a-zA-Z0-9-_]+[ \t]*$/;function Em(l,n,i="="){let c=n-1,u=[],x=l.indexOf(i,n);if(x<0)throw new ws("incomplete key-value: cannot find end of key",{toml:l,ptr:n});do{let h=l[n=++c];if(h!==" "&&h!==" ")if(h==='"'||h==="'"){if(h===l[n+1]&&h===l[n+2])throw new ws("multiline strings are not allowed in keys",{toml:l,ptr:n});let f=iv(l,n);if(f<0)throw new ws("unfinished string encountered",{toml:l,ptr:n});c=l.indexOf(".",f);let p=l.slice(f,c<0||c>x?x:c),g=Eo(p);if(g>-1)throw new ws("newlines are not allowed in keys",{toml:l,ptr:n+c+g});if(p.trimStart())throw new ws("found extra tokens after the string part",{toml:l,ptr:f});if(xx?x:c);if(!iS.test(f))throw new ws("only letter, numbers, dashes and underscores are allowed in keys",{toml:l,ptr:n});u.push(f.trimEnd())}}while(c+1&&cu===""||u===null||u===void 0?x:u,i={inner:{version:n(l.inner.version,ft.inner.version)},nickname:{nickname:n(l.nickname.nickname,ft.nickname.nickname)},napcat_server:{host:n(l.napcat_server.host,ft.napcat_server.host),port:n(l.napcat_server.port||0,ft.napcat_server.port),token:n(l.napcat_server.token,ft.napcat_server.token),heartbeat_interval:n(l.napcat_server.heartbeat_interval||0,ft.napcat_server.heartbeat_interval)},maibot_server:{host:n(l.maibot_server.host,ft.maibot_server.host),port:n(l.maibot_server.port||0,ft.maibot_server.port)},chat:{group_list_type:n(l.chat.group_list_type,ft.chat.group_list_type),group_list:l.chat.group_list||[],private_list_type:n(l.chat.private_list_type,ft.chat.private_list_type),private_list:l.chat.private_list||[],ban_user_id:l.chat.ban_user_id||[],ban_qq_bot:l.chat.ban_qq_bot??ft.chat.ban_qq_bot,enable_poke:l.chat.enable_poke??ft.chat.enable_poke},voice:{use_tts:l.voice.use_tts??ft.voice.use_tts},debug:{level:n(l.debug.level,ft.debug.level)}};let c=hS(i);return c=fS(c),c}catch(n){throw console.error("TOML 生成失败:",n),new Error(`无法生成 TOML 文件: ${n instanceof Error?n.message:"未知错误"}`)}}function fS(l){const n=l.split(` `),i=[];for(let c=0;c"|?*\x00-\x1F]/.test(l)?{valid:!1,error:"路径包含非法字符"}:{valid:!0,error:""}}function pS(){const[l,n]=m.useState("upload"),[i,c]=m.useState(null),[u,x]=m.useState(""),[h,f]=m.useState(""),[p,g]=m.useState("oneclick"),[v,N]=m.useState(""),[y,w]=m.useState(!1),[b,L]=m.useState(!1),[D,T]=m.useState(!1),[F,O]=m.useState(!1),[S,C]=m.useState(null),[P,M]=m.useState(!1),Z=m.useRef(null),{toast:G}=et(),ce=m.useRef(null),de=W=>{if(f(W),W.trim()){const ue=Nm(W);N(ue.error)}else N("")},be=m.useCallback(async W=>{const ue=gm[W];L(!0);try{const ke=await og(ue.path),J=jm(ke);c(J),g(W),f(ue.path),await cg(ue.path),G({title:"加载成功",description:`已从${ue.name}预设加载配置`})}catch(ke){console.error("加载预设配置失败:",ke),G({title:"加载失败",description:ke instanceof Error?ke.message:"无法读取预设配置文件",variant:"destructive"})}finally{L(!1)}},[G]),me=m.useCallback(async W=>{const ue=Nm(W);if(!ue.valid){N(ue.error),G({title:"路径无效",description:ue.error,variant:"destructive"});return}N(""),L(!0);try{const ke=await og(W),J=jm(ke);c(J),f(W),await cg(W),G({title:"加载成功",description:"已从配置文件加载"})}catch(ke){console.error("加载配置失败:",ke),G({title:"加载失败",description:ke instanceof Error?ke.message:"无法读取配置文件",variant:"destructive"})}finally{L(!1)}},[G]);m.useEffect(()=>{(async()=>{try{const ue=await J_();if(ue&&ue.path){f(ue.path);const ke=Object.entries(gm).find(([,J])=>J.path===ue.path);ke?(n("preset"),g(ke[0]),await be(ke[0])):(n("path"),await me(ue.path))}}catch(ue){console.error("加载保存的路径失败:",ue)}})()},[me,be]);const pe=m.useCallback(W=>{l!=="path"&&l!=="preset"||!h||(ce.current&&clearTimeout(ce.current),ce.current=setTimeout(async()=>{w(!0);try{const ue=vm(W);await dg(h,ue),G({title:"自动保存成功",description:"配置已保存到文件"})}catch(ue){console.error("自动保存失败:",ue),G({title:"自动保存失败",description:ue instanceof Error?ue.message:"保存配置失败",variant:"destructive"})}finally{w(!1)}},1e3))},[l,h,G]),je=async()=>{if(!i||!h)return;const W=Nm(h);if(!W.valid){G({title:"保存失败",description:W.error,variant:"destructive"});return}w(!0);try{const ue=vm(i);await dg(h,ue),G({title:"保存成功",description:"配置已保存到文件"})}catch(ue){console.error("保存失败:",ue),G({title:"保存失败",description:ue instanceof Error?ue.message:"保存配置失败",variant:"destructive"})}finally{w(!1)}},A=async()=>{h&&await me(h)},Y=W=>{if(W!==l){if(i){C(W),T(!0);return}H(W)}},H=W=>{c(null),x(""),N(""),n(W),W==="preset"&&be("oneclick"),G({title:"已切换模式",description:{upload:"现在可以上传配置文件",path:"现在可以指定配置文件路径",preset:"现在可以使用预设配置"}[W]})},U=()=>{S&&(H(S),C(null)),T(!1)},$=()=>{if(i){O(!0);return}_e()},_e=()=>{f(""),c(null),N(""),G({title:"已清空",description:"路径和配置已清空"})},Ne=()=>{_e(),O(!1)},Se=W=>{const ue=W.target.files?.[0];if(!ue)return;const ke=new FileReader;ke.onload=J=>{try{const ee=J.target?.result,De=jm(ee);c(De),x(ue.name),G({title:"上传成功",description:`已加载配置文件:${ue.name}`})}catch(ee){console.error("解析配置文件失败:",ee),G({title:"解析失败",description:"配置文件格式错误,请检查文件内容",variant:"destructive"})}},ke.readAsText(ue)},V=()=>{if(!i)return;const W=vm(i),ue=new Blob([W],{type:"text/plain;charset=utf-8"}),ke=URL.createObjectURL(ue),J=document.createElement("a");J.href=ke,J.download=u||"config.toml",document.body.appendChild(J),J.click(),document.body.removeChild(J),URL.revokeObjectURL(ke),G({title:"下载成功",description:"配置文件已下载,请手动覆盖并重启适配器"})},ye=()=>{c(JSON.parse(JSON.stringify(ft))),x("config.toml"),G({title:"已加载默认配置",description:"可以开始编辑配置"})};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"麦麦适配器配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理麦麦的 QQ 适配器的配置文件"})]})}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg border border-amber-500/50 bg-amber-500/10 text-amber-700 dark:text-amber-400",children:[e.jsx(Dt,{className:"h-4 w-4 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm",children:"适配器配置保存之后使用 WebUI 的重启功能适配器并不会重启,需要手动重启适配器。"})]}),e.jsx(Gi,{open:P,onOpenChange:M,children:e.jsxs(ze,{children:[e.jsx(ts,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(ls,{children:"工作模式"}),e.jsx(Vs,{children:"选择配置文件的管理方式"})]}),e.jsx(qi,{asChild:!0,children:e.jsxs(k,{variant:"ghost",size:"sm",className:"w-9 p-0",children:[e.jsx(Oa,{className:`h-4 w-4 transition-transform duration-200 ${P?"transform rotate-180":""}`}),e.jsx("span",{className:"sr-only",children:"切换"})]})})]})}),e.jsx(Fi,{children:e.jsxs(Ye,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3 md:gap-4",children:[e.jsx("div",{className:`border-2 rounded-lg p-3 md:p-4 cursor-pointer transition-all ${l==="preset"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>Y("preset"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(ca,{className:"h-4 w-4 md:h-5 md:w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm md:text-base",children:"预设模式"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-1 line-clamp-2",children:"使用预设的部署配置"})]})]})}),e.jsx("div",{className:`border-2 rounded-lg p-3 md:p-4 cursor-pointer transition-all ${l==="upload"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>Y("upload"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx($i,{className:"h-4 w-4 md:h-5 md:w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm md:text-base",children:"上传文件模式"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-1 line-clamp-2",children:"上传配置文件,编辑后下载并手动覆盖"})]})]})}),e.jsx("div",{className:`border-2 rounded-lg p-3 md:p-4 cursor-pointer transition-all ${l==="path"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>Y("path"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(Dw,{className:"h-4 w-4 md:h-5 md:w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm md:text-base",children:"指定路径模式"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-1 line-clamp-2",children:"指定配置文件路径,自动加载和保存"})]})]})})]}),l==="preset"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsx(E,{className:"text-sm md:text-base",children:"选择部署方式"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(gm).map(([W,ue])=>{const ke=ue.icon,J=p===W;return e.jsx("div",{className:`border-2 rounded-lg p-3 cursor-pointer transition-all ${J?"border-primary bg-primary/5":"border-muted hover:border-primary/50"}`,onClick:()=>{g(W),be(W)},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ke,{className:"h-5 w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"font-semibold text-sm",children:ue.name}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:ue.description}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-mono break-all",children:ue.path})]})]})},W)})})]}),l==="path"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"config-path",className:"text-sm md:text-base",children:"配置文件路径"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(re,{id:"config-path",value:h,onChange:W=>de(W.target.value),placeholder:"例: C:\\Adapter\\config.toml",className:`text-sm ${v?"border-destructive":""}`}),v&&e.jsx("p",{className:"text-xs text-destructive",children:v})]}),e.jsx(k,{onClick:()=>me(h),disabled:b||!h||!!v,className:"w-full sm:w-auto",children:b?e.jsxs(e.Fragment,{children:[e.jsx(zt,{className:"h-4 w-4 animate-spin mr-2"}),e.jsx("span",{className:"sm:hidden",children:"加载中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sm:hidden",children:"加载配置"}),e.jsx("span",{className:"hidden sm:inline",children:"加载"})]})})]})]}),e.jsxs("details",{className:"rounded-lg bg-muted/50 p-3 group",children:[e.jsxs("summary",{className:"text-xs font-medium cursor-pointer select-none list-none flex items-center justify-between",children:[e.jsx("span",{children:"路径格式说明"}),e.jsx("svg",{className:"h-4 w-4 transition-transform group-open:rotate-180",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),e.jsxs("div",{className:"mt-2 space-y-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"font-mono bg-background px-1.5 py-0.5 rounded text-[10px] md:text-xs whitespace-nowrap",children:"Windows"})}),e.jsxs("div",{className:"pl-2 space-y-0.5 text-[10px] md:text-xs break-all",children:[e.jsx("div",{children:"C:\\Adapter\\config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"D:\\MaiBot\\adapter\\config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"\\\\server\\share\\config.toml"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"font-mono bg-background px-1.5 py-0.5 rounded text-[10px] md:text-xs whitespace-nowrap",children:"Linux"})}),e.jsxs("div",{className:"pl-2 space-y-0.5 text-[10px] md:text-xs break-all",children:[e.jsx("div",{children:"/opt/adapter/config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"/home/user/adapter/config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"~/adapter/config.toml"})]})]}),e.jsx("p",{className:"pt-1 border-t text-[10px] md:text-xs",children:"💡 配置会自动保存到指定文件,修改后 1 秒自动保存"})]})]})]})]})})]})}),e.jsxs(gt,{children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsx(jt,{children:l==="preset"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"预设模式:"}),"选择预设的部署方式,配置会自动加载,修改后 1 秒自动保存",y&&" (正在保存...)"]}):l==="upload"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"上传文件模式:"}),"上传配置文件 → 在线编辑 → 下载文件 → 手动覆盖并重启适配器"]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"指定路径模式:"}),"指定配置文件路径后,配置会自动加载,修改后 1 秒自动保存",y&&" (正在保存...)"]})})]}),l==="upload"&&!i&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 w-full",children:[e.jsx("input",{ref:Z,type:"file",accept:".toml",className:"hidden",onChange:Se}),e.jsxs(k,{onClick:()=>Z.current?.click(),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx($i,{className:"mr-2 h-4 w-4"}),"上传配置"]}),e.jsxs(k,{onClick:ye,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Ha,{className:"mr-2 h-4 w-4"}),"使用默认配置"]})]}),l==="upload"&&i&&e.jsx("div",{className:"flex gap-2",children:e.jsxs(k,{onClick:V,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Yt,{className:"mr-2 h-4 w-4"}),"下载配置"]})}),(l==="preset"||l==="path")&&i&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs(k,{onClick:je,size:"sm",disabled:y||!!v,className:"w-full sm:w-auto",children:[e.jsx(Ki,{className:"mr-2 h-4 w-4"}),y?"保存中...":"立即保存"]}),e.jsxs(k,{onClick:A,size:"sm",variant:"outline",disabled:b,className:"w-full sm:w-auto",children:[e.jsx(zt,{className:`mr-2 h-4 w-4 ${b?"animate-spin":""}`}),"刷新"]}),l==="path"&&e.jsxs(k,{onClick:$,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(ns,{className:"mr-2 h-4 w-4"}),"清空路径"]})]}),i?e.jsxs(da,{defaultValue:"napcat",className:"w-full",children:[e.jsx("div",{className:"overflow-x-auto -mx-4 px-4 sm:mx-0 sm:px-0",children:e.jsxs(Zt,{className:"inline-flex w-auto min-w-full sm:grid sm:w-full sm:grid-cols-5",children:[e.jsxs(Xe,{value:"napcat",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"Napcat 连接"}),e.jsx("span",{className:"sm:hidden",children:"Napcat"})]}),e.jsxs(Xe,{value:"maibot",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"麦麦连接"}),e.jsx("span",{className:"sm:hidden",children:"麦麦"})]}),e.jsxs(Xe,{value:"chat",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"聊天控制"}),e.jsx("span",{className:"sm:hidden",children:"聊天"})]}),e.jsxs(Xe,{value:"voice",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"语音设置"}),e.jsx("span",{className:"sm:hidden",children:"语音"})]}),e.jsx(Xe,{value:"debug",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:"调试"})]})}),e.jsx(ys,{value:"napcat",className:"space-y-4",children:e.jsx(gS,{config:i,onChange:W=>{c(W),pe(W)}})}),e.jsx(ys,{value:"maibot",className:"space-y-4",children:e.jsx(jS,{config:i,onChange:W=>{c(W),pe(W)}})}),e.jsx(ys,{value:"chat",className:"space-y-4",children:e.jsx(vS,{config:i,onChange:W=>{c(W),pe(W)}})}),e.jsx(ys,{value:"voice",className:"space-y-4",children:e.jsx(NS,{config:i,onChange:W=>{c(W),pe(W)}})}),e.jsx(ys,{value:"debug",className:"space-y-4",children:e.jsx(bS,{config:i,onChange:W=>{c(W),pe(W)}})})]}):e.jsx("div",{className:"rounded-lg border bg-card p-6 md:p-12",children:e.jsxs("div",{className:"text-center space-y-3 md:space-y-4",children:[e.jsx(Ha,{className:"h-12 w-12 md:h-16 md:w-16 mx-auto text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold",children:"尚未加载配置"}),e.jsx("p",{className:"text-xs md:text-sm text-muted-foreground mt-2 px-4",children:l==="preset"?"请选择预设的部署方式":l==="upload"?"请上传现有配置文件,或使用默认配置开始编辑":"请指定配置文件路径并点击加载按钮"})]})]})}),e.jsx(gs,{open:D,onOpenChange:T,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认切换模式"}),e.jsxs(hs,{children:["切换模式将清空当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-destructive font-medium",children:"请确保已保存重要配置"})]})]}),e.jsxs(ms,{children:[e.jsx(ps,{onClick:()=>{T(!1),C(null)},children:"取消"}),e.jsx(fs,{onClick:U,children:"确认切换"})]})]})}),e.jsx(gs,{open:F,onOpenChange:O,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认清空路径"}),e.jsxs(hs,{children:["清空路径将清除当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-muted-foreground text-sm",children:"此操作不会删除配置文件,只是清除界面中的配置"})]})]}),e.jsxs(ms,{children:[e.jsx(ps,{onClick:()=>O(!1),children:"取消"}),e.jsx(fs,{onClick:Ne,className:"bg-destructive hover:bg-destructive/90",children:"确认清空"})]})]})})]})})}function gS({config:l,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"Napcat WebSocket 服务设置"}),e.jsxs("div",{className:"grid gap-3 md:gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"napcat-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(re,{id:"napcat-host",value:l.napcat_server.host,onChange:i=>n({...l,napcat_server:{...l.napcat_server,host:i.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的主机地址"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"napcat-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(re,{id:"napcat-port",type:"number",value:l.napcat_server.port||"",onChange:i=>n({...l,napcat_server:{...l.napcat_server,port:i.target.value?parseInt(i.target.value):0}}),placeholder:"8095",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的端口(留空使用默认值 8095)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"napcat-token",className:"text-sm md:text-base",children:"访问令牌(Token)"}),e.jsx(re,{id:"napcat-token",type:"password",value:l.napcat_server.token,onChange:i=>n({...l,napcat_server:{...l.napcat_server,token:i.target.value}}),placeholder:"留空表示无需令牌",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的访问令牌,若无则留空"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"napcat-heartbeat",className:"text-sm md:text-base",children:"心跳间隔(秒)"}),e.jsx(re,{id:"napcat-heartbeat",type:"number",value:l.napcat_server.heartbeat_interval||"",onChange:i=>n({...l,napcat_server:{...l.napcat_server,heartbeat_interval:i.target.value?parseInt(i.target.value):0}}),placeholder:"30",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"与 Napcat 设置的心跳间隔保持一致(留空使用默认值 30)"})]})]})]})})}function jS({config:l,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"麦麦 WebSocket 服务设置"}),e.jsxs("div",{className:"grid gap-3 md:gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"maibot-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(re,{id:"maibot-host",value:l.maibot_server.host,onChange:i=>n({...l,maibot_server:{...l.maibot_server,host:i.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 HOST 字段"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"maibot-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(re,{id:"maibot-port",type:"number",value:l.maibot_server.port||"",onChange:i=>n({...l,maibot_server:{...l.maibot_server,port:i.target.value?parseInt(i.target.value):0}}),placeholder:"8000",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 PORT 字段(留空使用默认值 8000)"})]})]})]})})}function vS({config:l,onChange:n}){const i=x=>{const h={...l};x==="group"?h.chat.group_list=[...h.chat.group_list,0]:x==="private"?h.chat.private_list=[...h.chat.private_list,0]:h.chat.ban_user_id=[...h.chat.ban_user_id,0],n(h)},c=(x,h)=>{const f={...l};x==="group"?f.chat.group_list=f.chat.group_list.filter((p,g)=>g!==h):x==="private"?f.chat.private_list=f.chat.private_list.filter((p,g)=>g!==h):f.chat.ban_user_id=f.chat.ban_user_id.filter((p,g)=>g!==h),n(f)},u=(x,h,f)=>{const p={...l};x==="group"?p.chat.group_list[h]=f:x==="private"?p.chat.private_list[h]=f:p.chat.ban_user_id[h]=f,n(p)};return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"聊天黑白名单功能"}),e.jsxs("div",{className:"grid gap-4 md:gap-6",children:[e.jsxs("div",{className:"space-y-3 md:space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-sm md:text-base",children:"群组名单类型"}),e.jsxs(Le,{value:l.chat.group_list_type,onValueChange:x=>n({...l,chat:{...l.chat,group_list_type:x}}),children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(le,{value:"blacklist",children:"黑名单(名单内禁止聊天)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-0",children:[e.jsx(E,{className:"text-sm md:text-base",children:"群组列表"}),e.jsxs(k,{onClick:()=>i("group"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ha,{className:"mr-1 h-4 w-4"}),"添加群号"]})]}),l.chat.group_list.map((x,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(re,{type:"number",value:x,onChange:f=>u("group",h,parseInt(f.target.value)||0),placeholder:"输入群号",className:"text-sm md:text-base"}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:["确定要删除群号 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>c("group",h),children:"删除"})]})]})]})]},h)),l.chat.group_list.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无群组"})]})]}),e.jsxs("div",{className:"space-y-3 md:space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-sm md:text-base",children:"私聊名单类型"}),e.jsxs(Le,{value:l.chat.private_list_type,onValueChange:x=>n({...l,chat:{...l.chat,private_list_type:x}}),children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(le,{value:"blacklist",children:"黑名单(名单内禁止聊天)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-0",children:[e.jsx(E,{className:"text-sm md:text-base",children:"私聊列表"}),e.jsxs(k,{onClick:()=>i("private"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ha,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),l.chat.private_list.map((x,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(re,{type:"number",value:x,onChange:f=>u("private",h,parseInt(f.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:["确定要删除用户 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>c("private",h),children:"删除"})]})]})]})]},h)),l.chat.private_list.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无用户"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-0",children:[e.jsxs("div",{children:[e.jsx(E,{className:"text-sm md:text-base",children:"全局禁止名单"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"名单中的用户无法进行任何聊天"})]}),e.jsxs(k,{onClick:()=>i("ban"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ha,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),l.chat.ban_user_id.map((x,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(re,{type:"number",value:x,onChange:f=>u("ban",h,parseInt(f.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(gs,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(k,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:["确定要从全局禁止名单中删除用户 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>c("ban",h),children:"删除"})]})]})]})]},h)),l.chat.ban_user_id.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无禁止用户"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(E,{className:"text-sm md:text-base",children:"屏蔽QQ官方机器人"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否屏蔽来自QQ官方机器人的消息"})]}),e.jsx(Pe,{checked:l.chat.ban_qq_bot,onCheckedChange:x=>n({...l,chat:{...l.chat,ban_qq_bot:x}})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(E,{className:"text-sm md:text-base",children:"启用戳一戳功能"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否响应戳一戳消息"})]}),e.jsx(Pe,{checked:l.chat.enable_poke,onCheckedChange:x=>n({...l,chat:{...l.chat,enable_poke:x}})})]})]})]})})}function NS({config:l,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"发送语音设置"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(E,{className:"text-sm md:text-base",children:"使用 TTS 语音"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"请确保已配置 TTS 并有对应的适配器"})]}),e.jsx(Pe,{checked:l.voice.use_tts,onCheckedChange:i=>n({...l,voice:{use_tts:i}})})]})]})})}function bS({config:l,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"调试设置"}),e.jsx("div",{className:"grid gap-3 md:gap-4",children:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{className:"text-sm md:text-base",children:"日志等级"}),e.jsxs(Le,{value:l.debug.level,onValueChange:i=>n({...l,debug:{level:i}}),children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"DEBUG",children:"DEBUG(调试)"}),e.jsx(le,{value:"INFO",children:"INFO(信息)"}),e.jsx(le,{value:"WARNING",children:"WARNING(警告)"}),e.jsx(le,{value:"ERROR",children:"ERROR(错误)"}),e.jsx(le,{value:"CRITICAL",children:"CRITICAL(严重)"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"设置适配器的日志输出等级"})]})})]})})}const yS=["defaultChecked","defaultValue","suppressContentEditableWarning","suppressHydrationWarning","dangerouslySetInnerHTML","accessKey","className","contentEditable","contextMenu","dir","draggable","hidden","id","lang","placeholder","slot","spellCheck","style","tabIndex","title","translate","radioGroup","role","about","datatype","inlist","prefix","property","resource","typeof","vocab","autoCapitalize","autoCorrect","autoSave","color","itemProp","itemScope","itemType","itemID","itemRef","results","security","unselectable","inputMode","is","onCopy","onCopyCapture","onCut","onCutCapture","onPaste","onPasteCapture","onCompositionEnd","onCompositionEndCapture","onCompositionStart","onCompositionStartCapture","onCompositionUpdate","onCompositionUpdateCapture","onFocus","onFocusCapture","onBlur","onBlurCapture","onChange","onChangeCapture","onBeforeInput","onBeforeInputCapture","onInput","onInputCapture","onReset","onResetCapture","onSubmit","onSubmitCapture","onInvalid","onInvalidCapture","onLoad","onLoadCapture","onError","onErrorCapture","onKeyDown","onKeyDownCapture","onKeyPress","onKeyPressCapture","onKeyUp","onKeyUpCapture","onAbort","onAbortCapture","onCanPlay","onCanPlayCapture","onCanPlayThrough","onCanPlayThroughCapture","onDurationChange","onDurationChangeCapture","onEmptied","onEmptiedCapture","onEncrypted","onEncryptedCapture","onEnded","onEndedCapture","onLoadedData","onLoadedDataCapture","onLoadedMetadata","onLoadedMetadataCapture","onLoadStart","onLoadStartCapture","onPause","onPauseCapture","onPlay","onPlayCapture","onPlaying","onPlayingCapture","onProgress","onProgressCapture","onRateChange","onRateChangeCapture","onSeeked","onSeekedCapture","onSeeking","onSeekingCapture","onStalled","onStalledCapture","onSuspend","onSuspendCapture","onTimeUpdate","onTimeUpdateCapture","onVolumeChange","onVolumeChangeCapture","onWaiting","onWaitingCapture","onAuxClick","onAuxClickCapture","onClick","onClickCapture","onContextMenu","onContextMenuCapture","onDoubleClick","onDoubleClickCapture","onDrag","onDragCapture","onDragEnd","onDragEndCapture","onDragEnter","onDragEnterCapture","onDragExit","onDragExitCapture","onDragLeave","onDragLeaveCapture","onDragOver","onDragOverCapture","onDragStart","onDragStartCapture","onDrop","onDropCapture","onMouseDown","onMouseDownCapture","onMouseEnter","onMouseLeave","onMouseMove","onMouseMoveCapture","onMouseOut","onMouseOutCapture","onMouseOver","onMouseOverCapture","onMouseUp","onMouseUpCapture","onSelect","onSelectCapture","onTouchCancel","onTouchCancelCapture","onTouchEnd","onTouchEndCapture","onTouchMove","onTouchMoveCapture","onTouchStart","onTouchStartCapture","onPointerDown","onPointerDownCapture","onPointerMove","onPointerMoveCapture","onPointerUp","onPointerUpCapture","onPointerCancel","onPointerCancelCapture","onPointerEnter","onPointerEnterCapture","onPointerLeave","onPointerLeaveCapture","onPointerOver","onPointerOverCapture","onPointerOut","onPointerOutCapture","onGotPointerCapture","onGotPointerCaptureCapture","onLostPointerCapture","onLostPointerCaptureCapture","onScroll","onScrollCapture","onWheel","onWheelCapture","onAnimationStart","onAnimationStartCapture","onAnimationEnd","onAnimationEndCapture","onAnimationIteration","onAnimationIterationCapture","onTransitionEnd","onTransitionEndCapture"],wS=/^(aria-|data-)/,uv=l=>Object.fromEntries(Object.entries(l).filter(([n])=>wS.test(n)||yS.includes(n)));function _S(l,n){const i=uv(l);return Object.keys(l).some(c=>!Object.hasOwn(i,c)&&l[c]!==n[c])}class SS extends m.Component{container;plugin;componentDidMount(){this.installPlugin()}componentDidUpdate(n){if(n.uppy!==this.props.uppy)this.uninstallPlugin(n),this.installPlugin();else if(_S(this.props,n)){const{uppy:i,...c}={...this.props,target:this.container};this.plugin.setOptions(c)}}componentWillUnmount(){this.uninstallPlugin()}installPlugin(){const{uppy:n,...i}={id:"Dashboard",...this.props,inline:!0,target:this.container};n.use(i1,i),this.plugin=n.getPlugin(i.id)}uninstallPlugin(n=this.props){const{uppy:i}=n;i.removePlugin(this.plugin)}render(){return m.createElement("div",{className:"uppy-Container",ref:n=>{this.container=n},...uv(this.props)})}}function CS({src:l,alt:n="表情包",className:i,maxRetries:c=5,retryInterval:u=1500}){const[x,h]=m.useState("loading"),[f,p]=m.useState(0),[g,v]=m.useState(null),[N,y]=m.useState(l);l!==N&&(h("loading"),p(0),v(null),y(l));const w=m.useCallback(async()=>{try{const b=await fetch(l,{credentials:"include"});if(b.status===202){h("generating"),f{p(T=>T+1)},u):h("error");return}if(!b.ok){h("error");return}const L=await b.blob(),D=URL.createObjectURL(L);v(D),h("loaded")}catch(b){console.error("加载缩略图失败:",b),h("error")}},[l,f,c,u]);return m.useEffect(()=>{w()},[w]),m.useEffect(()=>()=>{g&&URL.revokeObjectURL(g)},[g]),x==="loading"||x==="generating"?e.jsx(Qs,{className:B("w-full h-full",i)}):x==="error"||!g?e.jsx("div",{className:B("w-full h-full flex items-center justify-center bg-muted",i),children:e.jsx(jj,{className:"h-8 w-8 text-muted-foreground"})}):e.jsx("img",{src:g,alt:n,className:B("w-full h-full object-contain",i)})}function mv({content:l,className:n=""}){return e.jsx("div",{className:`prose prose-sm dark:prose-invert max-w-none ${n}`,children:e.jsx(o1,{remarkPlugins:[u1,m1],rehypePlugins:[d1],components:{code({inline:i,className:c,children:u,...x}){return i?e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-sm font-mono",...x,children:u}):e.jsx("code",{className:`${c} block bg-muted p-4 rounded-lg overflow-x-auto`,...x,children:u})},table({children:i,...c}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{className:"border-collapse border border-border",...c,children:i})})},th({children:i,...c}){return e.jsx("th",{className:"border border-border bg-muted px-4 py-2 text-left font-semibold",...c,children:i})},td({children:i,...c}){return e.jsx("td",{className:"border border-border px-4 py-2",...c,children:i})},a({children:i,...c}){return e.jsx("a",{className:"text-primary hover:underline",target:"_blank",rel:"noopener noreferrer",...c,children:i})},blockquote({children:i,...c}){return e.jsx("blockquote",{className:"border-l-4 border-primary pl-4 italic text-muted-foreground",...c,children:i})},h1({children:i,...c}){return e.jsx("h1",{className:"text-3xl font-bold mt-6 mb-4",...c,children:i})},h2({children:i,...c}){return e.jsx("h2",{className:"text-2xl font-bold mt-5 mb-3",...c,children:i})},h3({children:i,...c}){return e.jsx("h3",{className:"text-xl font-bold mt-4 mb-2",...c,children:i})},h4({children:i,...c}){return e.jsx("h4",{className:"text-lg font-semibold mt-3 mb-2",...c,children:i})},ul({children:i,...c}){return e.jsx("ul",{className:"list-disc list-inside space-y-1 my-2",...c,children:i})},ol({children:i,...c}){return e.jsx("ol",{className:"list-decimal list-inside space-y-1 my-2",...c,children:i})},p({children:i,...c}){return e.jsx("p",{className:"my-2 leading-relaxed",...c,children:i})},hr({...i}){return e.jsx("hr",{className:"my-4 border-border",...i})}},children:l})})}function kS({children:l,className:n}){return e.jsx(mv,{content:l,className:n})}const Ra="/api/webui/emoji";async function TS(l){const n=new URLSearchParams;l.page&&n.append("page",l.page.toString()),l.page_size&&n.append("page_size",l.page_size.toString()),l.search&&n.append("search",l.search),l.is_registered!==void 0&&n.append("is_registered",l.is_registered.toString()),l.is_banned!==void 0&&n.append("is_banned",l.is_banned.toString()),l.format&&n.append("format",l.format),l.sort_by&&n.append("sort_by",l.sort_by),l.sort_order&&n.append("sort_order",l.sort_order);const i=await we(`${Ra}/list?${n}`,{});if(!i.ok)throw new Error(`获取表情包列表失败: ${i.statusText}`);return i.json()}async function ES(l){const n=await we(`${Ra}/${l}`,{});if(!n.ok)throw new Error(`获取表情包详情失败: ${n.statusText}`);return n.json()}async function MS(l,n){const i=await we(`${Ra}/${l}`,{method:"PATCH",body:JSON.stringify(n)});if(!i.ok)throw new Error(`更新表情包失败: ${i.statusText}`);return i.json()}async function AS(l){const n=await we(`${Ra}/${l}`,{method:"DELETE"});if(!n.ok)throw new Error(`删除表情包失败: ${n.statusText}`);return n.json()}async function zS(){const l=await we(`${Ra}/stats/summary`,{});if(!l.ok)throw new Error(`获取统计数据失败: ${l.statusText}`);return l.json()}async function DS(l){const n=await we(`${Ra}/${l}/register`,{method:"POST"});if(!n.ok)throw new Error(`注册表情包失败: ${n.statusText}`);return n.json()}async function OS(l){const n=await we(`${Ra}/${l}/ban`,{method:"POST"});if(!n.ok)throw new Error(`封禁表情包失败: ${n.statusText}`);return n.json()}function RS(l,n=!1){return n?`${Ra}/${l}/thumbnail?original=true`:`${Ra}/${l}/thumbnail`}function LS(l){return`${Ra}/${l}/thumbnail?original=true`}async function US(l){const n=await we(`${Ra}/batch/delete`,{method:"POST",body:JSON.stringify({emoji_ids:l})});if(!n.ok){const i=await n.json();throw new Error(i.detail||"批量删除失败")}return n.json()}function BS(){return`${Ra}/upload`}function $S(){const[l,n]=m.useState([]),[i,c]=m.useState(null),[u,x]=m.useState(!1),[h,f]=m.useState(1),[p,g]=m.useState(0),[v,N]=m.useState(20),[y,w]=m.useState("all"),[b,L]=m.useState("all"),[D,T]=m.useState("all"),[F,O]=m.useState("usage_count"),[S,C]=m.useState("desc"),[P,M]=m.useState(null),[Z,G]=m.useState(!1),[ce,de]=m.useState(!1),[be,me]=m.useState(!1),[pe,je]=m.useState(new Set),[A,Y]=m.useState(!1),[H,U]=m.useState(""),[$,_e]=m.useState("medium"),[Ne,Se]=m.useState(!1),{toast:V}=et(),ye=m.useCallback(async()=>{try{x(!0);const ie=await TS({page:h,page_size:v,is_registered:y==="all"?void 0:y==="registered",is_banned:b==="all"?void 0:b==="banned",format:D==="all"?void 0:D,sort_by:F,sort_order:S});n(ie.data),g(ie.total)}catch(ie){const ve=ie instanceof Error?ie.message:"加载表情包列表失败";V({title:"错误",description:ve,variant:"destructive"})}finally{x(!1)}},[h,v,y,b,D,F,S,V]),W=async()=>{try{const ie=await zS();c(ie.data)}catch(ie){console.error("加载统计数据失败:",ie)}};m.useEffect(()=>{ye()},[ye]),m.useEffect(()=>{W()},[]);const ue=async ie=>{try{const ve=await ES(ie.id);M(ve.data),G(!0)}catch(ve){const Me=ve instanceof Error?ve.message:"加载详情失败";V({title:"错误",description:Me,variant:"destructive"})}},ke=ie=>{M(ie),de(!0)},J=ie=>{M(ie),me(!0)},ee=async()=>{if(P)try{await AS(P.id),V({title:"成功",description:"表情包已删除"}),me(!1),M(null),ye(),W()}catch(ie){const ve=ie instanceof Error?ie.message:"删除失败";V({title:"错误",description:ve,variant:"destructive"})}},De=async ie=>{try{await DS(ie.id),V({title:"成功",description:"表情包已注册"}),ye(),W()}catch(ve){const Me=ve instanceof Error?ve.message:"注册失败";V({title:"错误",description:Me,variant:"destructive"})}},Fe=async ie=>{try{await OS(ie.id),V({title:"成功",description:"表情包已封禁"}),ye(),W()}catch(ve){const Me=ve instanceof Error?ve.message:"封禁失败";V({title:"错误",description:Me,variant:"destructive"})}},ge=ie=>{const ve=new Set(pe);ve.has(ie)?ve.delete(ie):ve.add(ie),je(ve)},as=async()=>{try{const ie=await US(Array.from(pe));V({title:"批量删除完成",description:ie.message}),je(new Set),Y(!1),ye(),W()}catch(ie){V({title:"批量删除失败",description:ie instanceof Error?ie.message:"批量删除失败",variant:"destructive"})}},ae=()=>{const ie=parseInt(H),ve=Math.ceil(p/v);ie>=1&&ie<=ve?(f(ie),U("")):V({title:"无效的页码",description:`请输入1-${ve}之间的页码`,variant:"destructive"})},Ee=i?.formats?Object.keys(i.formats):[];return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"表情包管理"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"管理麦麦的表情包资源"})]}),e.jsxs(k,{onClick:()=>Se(!0),className:"gap-2",children:[e.jsx($i,{className:"h-4 w-4"}),"上传表情包"]})]}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[i&&e.jsxs("div",{className:"grid gap-4 grid-cols-2 lg:grid-cols-4",children:[e.jsx(ze,{children:e.jsxs(ts,{className:"pb-2",children:[e.jsx(Vs,{children:"总数"}),e.jsx(ls,{className:"text-2xl",children:i.total})]})}),e.jsx(ze,{children:e.jsxs(ts,{className:"pb-2",children:[e.jsx(Vs,{children:"已注册"}),e.jsx(ls,{className:"text-2xl text-green-600",children:i.registered})]})}),e.jsx(ze,{children:e.jsxs(ts,{className:"pb-2",children:[e.jsx(Vs,{children:"已封禁"}),e.jsx(ls,{className:"text-2xl text-red-600",children:i.banned})]})}),e.jsx(ze,{children:e.jsxs(ts,{className:"pb-2",children:[e.jsx(Vs,{children:"未注册"}),e.jsx(ls,{className:"text-2xl text-gray-600",children:i.unregistered})]})})]}),e.jsxs(ze,{children:[e.jsx(ts,{children:e.jsxs(ls,{className:"flex items-center gap-2",children:[e.jsx(No,{className:"h-5 w-5"}),"筛选和排序"]})}),e.jsxs(Ye,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:"排序方式"}),e.jsxs(Le,{value:`${F}-${S}`,onValueChange:ie=>{const[ve,Me]=ie.split("-");O(ve),C(Me),f(1)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"usage_count-desc",children:"使用次数 (多→少)"}),e.jsx(le,{value:"usage_count-asc",children:"使用次数 (少→多)"}),e.jsx(le,{value:"register_time-desc",children:"注册时间 (新→旧)"}),e.jsx(le,{value:"register_time-asc",children:"注册时间 (旧→新)"}),e.jsx(le,{value:"record_time-desc",children:"记录时间 (新→旧)"}),e.jsx(le,{value:"record_time-asc",children:"记录时间 (旧→新)"}),e.jsx(le,{value:"last_used_time-desc",children:"最后使用 (新→旧)"}),e.jsx(le,{value:"last_used_time-asc",children:"最后使用 (旧→新)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:"注册状态"}),e.jsxs(Le,{value:y,onValueChange:ie=>{w(ie),f(1)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部"}),e.jsx(le,{value:"registered",children:"已注册"}),e.jsx(le,{value:"unregistered",children:"未注册"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:"封禁状态"}),e.jsxs(Le,{value:b,onValueChange:ie=>{L(ie),f(1)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部"}),e.jsx(le,{value:"banned",children:"已封禁"}),e.jsx(le,{value:"unbanned",children:"未封禁"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:"格式"}),e.jsxs(Le,{value:D,onValueChange:ie=>{T(ie),f(1)},children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部"}),Ee.map(ie=>e.jsxs(le,{value:ie,children:[ie.toUpperCase()," (",i?.formats[ie],")"]},ie))]})]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 pt-4 border-t",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[pe.size>0&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["已选择 ",pe.size," 个表情包"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{className:"text-sm whitespace-nowrap",children:"卡片大小"}),e.jsxs(Le,{value:$,onValueChange:ie=>_e(ie),children:[e.jsx(Oe,{className:"w-24",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"small",children:"小"}),e.jsx(le,{value:"medium",children:"中"}),e.jsx(le,{value:"large",children:"大"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{htmlFor:"emoji-page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Le,{value:v.toString(),onValueChange:ie=>{N(parseInt(ie)),f(1),je(new Set)},children:[e.jsx(Oe,{id:"emoji-page-size",className:"w-20",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"20",children:"20"}),e.jsx(le,{value:"40",children:"40"}),e.jsx(le,{value:"60",children:"60"}),e.jsx(le,{value:"100",children:"100"})]})]}),pe.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>je(new Set),children:"取消选择"}),e.jsxs(k,{variant:"destructive",size:"sm",onClick:()=>Y(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsxs(k,{variant:"outline",size:"sm",onClick:ye,disabled:u,children:[e.jsx(zt,{className:`h-4 w-4 mr-2 ${u?"animate-spin":""}`}),"刷新"]})})]})]}),e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"表情包列表"}),e.jsxs(Vs,{children:["共 ",p," 个表情包,当前第 ",h," 页"]})]}),e.jsxs(Ye,{children:[l.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"暂无数据"}):e.jsx("div",{className:`grid gap-3 ${$==="small"?"grid-cols-3 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10":$==="medium"?"grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-8":"grid-cols-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5"}`,children:l.map(ie=>e.jsxs("div",{className:`group relative rounded-lg border bg-card overflow-hidden hover:ring-2 hover:ring-primary transition-all cursor-pointer ${pe.has(ie.id)?"ring-2 ring-primary bg-primary/5":""}`,onClick:()=>ge(ie.id),children:[e.jsx("div",{className:`absolute top-1 left-1 z-10 transition-opacity ${pe.has(ie.id)?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:e.jsx("div",{className:`w-5 h-5 rounded-full border-2 flex items-center justify-center ${pe.has(ie.id)?"bg-primary border-primary text-primary-foreground":"bg-background/80 border-muted-foreground/50"}`,children:pe.has(ie.id)&&e.jsx(oa,{className:"h-3 w-3"})})}),e.jsxs("div",{className:"absolute top-1 right-1 z-10 flex flex-col gap-0.5",children:[ie.is_registered&&e.jsx(Te,{variant:"default",className:"bg-green-600 text-[10px] px-1 py-0",children:"已注册"}),ie.is_banned&&e.jsx(Te,{variant:"destructive",className:"text-[10px] px-1 py-0",children:"已封禁"})]}),e.jsx("div",{className:`aspect-square bg-muted flex items-center justify-center overflow-hidden ${$==="small"?"p-1":$==="medium"?"p-2":"p-3"}`,children:e.jsx(CS,{src:RS(ie.id),alt:"表情包"})}),e.jsxs("div",{className:`border-t bg-card ${$==="small"?"p-1":"p-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Te,{variant:"outline",className:"text-[10px] px-1 py-0",children:ie.format.toUpperCase()}),e.jsxs("span",{className:"font-mono",children:[ie.usage_count,"次"]})]}),e.jsxs("div",{className:`flex gap-1 justify-center opacity-0 group-hover:opacity-100 transition-opacity ${$==="small"?"flex-wrap":""}`,children:[e.jsx(k,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:ve=>{ve.stopPropagation(),ke(ie)},title:"编辑",children:e.jsx(En,{className:"h-3 w-3"})}),e.jsx(k,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:ve=>{ve.stopPropagation(),ue(ie)},title:"详情",children:e.jsx(Jt,{className:"h-3 w-3"})}),!ie.is_registered&&e.jsx(k,{variant:"ghost",size:"icon",className:"h-6 w-6 text-green-600 hover:text-green-700",onClick:ve=>{ve.stopPropagation(),De(ie)},title:"注册",children:e.jsx(oa,{className:"h-3 w-3"})}),!ie.is_banned&&e.jsx(k,{variant:"ghost",size:"icon",className:"h-6 w-6 text-orange-600 hover:text-orange-700",onClick:ve=>{ve.stopPropagation(),Fe(ie)},title:"封禁",children:e.jsx(Ow,{className:"h-3 w-3"})}),e.jsx(k,{variant:"ghost",size:"icon",className:"h-6 w-6 text-red-600 hover:text-red-700",onClick:ve=>{ve.stopPropagation(),J(ie)},title:"删除",children:e.jsx(ns,{className:"h-3 w-3"})})]})]})]},ie.id))}),p>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["显示 ",(h-1)*v+1," 到"," ",Math.min(h*v,p)," 条,共 ",p," 条"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(zr,{className:"h-4 w-4"})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>f(ie=>Math.max(1,ie-1)),disabled:h===1,children:[e.jsx(Wa,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"上一页"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{type:"number",value:H,onChange:ie=>U(ie.target.value),onKeyDown:ie=>ie.key==="Enter"&&ae(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(p/v)}),e.jsx(k,{variant:"outline",size:"sm",onClick:ae,disabled:!H,className:"h-8",children:"跳转"})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>f(ie=>ie+1),disabled:h>=Math.ceil(p/v),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(p/v)),disabled:h>=Math.ceil(p/v),className:"hidden sm:flex",children:e.jsx(Dr,{className:"h-4 w-4"})})]})]})]})]}),e.jsx(HS,{emoji:P,open:Z,onOpenChange:G}),e.jsx(IS,{emoji:P,open:ce,onOpenChange:de,onSuccess:()=>{ye(),W()}}),e.jsx(PS,{open:Ne,onOpenChange:Se,onSuccess:()=>{ye(),W()}})]})}),e.jsx(gs,{open:A,onOpenChange:Y,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认批量删除"}),e.jsxs(hs,{children:["你确定要删除选中的 ",pe.size," 个表情包吗?此操作不可撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:as,children:"确认删除"})]})]})}),e.jsx(Is,{open:be,onOpenChange:me,children:e.jsxs(Rs,{children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"确认删除"}),e.jsx(Zs,{children:"确定要删除这个表情包吗?此操作无法撤销。"})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>me(!1),children:"取消"}),e.jsx(k,{variant:"destructive",onClick:ee,children:"删除"})]})]})})]})}function HS({emoji:l,open:n,onOpenChange:i}){if(!l)return null;const c=u=>u?new Date(u*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Rs,{className:"max-w-2xl max-h-[90vh]",children:[e.jsx(Ls,{children:e.jsx(Us,{children:"表情包详情"})}),e.jsx(Je,{className:"max-h-[calc(90vh-8rem)] pr-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-32 h-32 bg-muted rounded-lg flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:LS(l.id),alt:l.description||"表情包",className:"w-full h-full object-cover",onError:u=>{const x=u.target;x.style.display="none";const h=x.parentElement;h&&(h.innerHTML='')}})})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(E,{className:"text-muted-foreground",children:"ID"}),e.jsx("div",{className:"mt-1 font-mono",children:l.id})]}),e.jsxs("div",{children:[e.jsx(E,{className:"text-muted-foreground",children:"格式"}),e.jsx("div",{className:"mt-1",children:e.jsx(Te,{variant:"outline",children:l.format.toUpperCase()})})]})]}),e.jsxs("div",{children:[e.jsx(E,{className:"text-muted-foreground",children:"文件路径"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:l.full_path})]}),e.jsxs("div",{children:[e.jsx(E,{className:"text-muted-foreground",children:"哈希值"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:l.emoji_hash})]}),e.jsxs("div",{children:[e.jsx(E,{className:"text-muted-foreground",children:"描述"}),l.description?e.jsx("div",{className:"mt-1 rounded-lg border bg-muted/50 p-3",children:e.jsx(kS,{className:"prose-sm",children:l.description})}):e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"-"})]}),e.jsxs("div",{children:[e.jsx(E,{className:"text-muted-foreground",children:"情绪"}),e.jsx("div",{className:"mt-1",children:l.emotion?e.jsx("span",{className:"text-sm",children:l.emotion}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"-"})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(E,{className:"text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[l.is_registered&&e.jsx(Te,{variant:"default",className:"bg-green-600",children:"已注册"}),l.is_banned&&e.jsx(Te,{variant:"destructive",children:"已封禁"}),!l.is_registered&&!l.is_banned&&e.jsx(Te,{variant:"outline",children:"未注册"})]})]}),e.jsxs("div",{children:[e.jsx(E,{className:"text-muted-foreground",children:"使用次数"}),e.jsx("div",{className:"mt-1 font-mono text-lg",children:l.usage_count})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(E,{className:"text-muted-foreground",children:"记录时间"}),e.jsx("div",{className:"mt-1 text-sm",children:c(l.record_time)})]}),e.jsxs("div",{children:[e.jsx(E,{className:"text-muted-foreground",children:"注册时间"}),e.jsx("div",{className:"mt-1 text-sm",children:c(l.register_time)})]})]}),e.jsxs("div",{children:[e.jsx(E,{className:"text-muted-foreground",children:"最后使用"}),e.jsx("div",{className:"mt-1 text-sm",children:c(l.last_used_time)})]})]})})]})})}function IS({emoji:l,open:n,onOpenChange:i,onSuccess:c}){const[u,x]=m.useState(""),[h,f]=m.useState(!1),[p,g]=m.useState(!1),[v,N]=m.useState(!1),{toast:y}=et();m.useEffect(()=>{l&&(x(l.emotion||""),f(l.is_registered),g(l.is_banned))},[l]);const w=async()=>{if(l)try{N(!0);const b=u.split(/[,,]/).map(L=>L.trim()).filter(Boolean).join(",");await MS(l.id,{emotion:b||void 0,is_registered:h,is_banned:p}),y({title:"成功",description:"表情包信息已更新"}),i(!1),c()}catch(b){const L=b instanceof Error?b.message:"保存失败";y({title:"错误",description:L,variant:"destructive"})}finally{N(!1)}};return l?e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Rs,{className:"max-w-2xl",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"编辑表情包"}),e.jsx(Zs,{children:"修改表情包的情绪和状态信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(E,{children:"情绪"}),e.jsx(Ys,{value:u,onChange:b=>x(b.target.value),placeholder:"输入情绪描述...",rows:2,className:"mt-1"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"输入情绪相关的文本描述"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xs,{id:"is_registered",checked:h,onCheckedChange:b=>{b===!0?(f(!0),g(!1)):f(!1)}}),e.jsx(E,{htmlFor:"is_registered",className:"cursor-pointer",children:"已注册"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xs,{id:"is_banned",checked:p,onCheckedChange:b=>{b===!0?(g(!0),f(!1)):g(!1)}}),e.jsx(E,{htmlFor:"is_banned",className:"cursor-pointer",children:"已封禁"})]})]})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(k,{onClick:w,disabled:v,children:v?"保存中...":"保存"})]})]})}):null}function PS({open:l,onOpenChange:n,onSuccess:i}){const[c,u]=m.useState("select"),[x,h]=m.useState([]),[f,p]=m.useState(null),[g,v]=m.useState(!1),{toast:N}=et(),y=m.useMemo(()=>new c1({id:"emoji-uploader",autoProceed:!1,restrictions:{maxFileSize:10485760,allowedFileTypes:["image/jpeg","image/png","image/gif","image/webp"],maxNumberOfFiles:20},locale:{pluralize:()=>0,strings:{addMoreFiles:"添加更多文件",addingMoreFiles:"正在添加更多文件",allowedFileTypes:"允许的文件类型:%{types}",cancel:"取消",closeModal:"关闭",complete:"完成",connectedToInternet:"已连接到互联网",copyLink:"复制链接",copyLinkToClipboardFallback:"复制下方链接",copyLinkToClipboardSuccess:"链接已复制到剪贴板",dashboardTitle:"选择文件",dashboardWindowTitle:"文件选择窗口(按 ESC 关闭)",done:"完成",dropHereOr:"拖放文件到这里或 %{browse}",dropHint:"将文件拖放到此处",dropPasteFiles:"将文件拖放到这里或 %{browseFiles}",dropPasteFolders:"将文件拖放到这里或 %{browseFolders}",dropPasteBoth:"将文件拖放到这里,%{browseFiles} 或 %{browseFolders}",dropPasteImportFiles:"将文件拖放到这里,%{browseFiles} 或从以下位置导入:",dropPasteImportFolders:"将文件拖放到这里,%{browseFolders} 或从以下位置导入:",dropPasteImportBoth:"将文件拖放到这里,%{browseFiles},%{browseFolders} 或从以下位置导入:",editFile:"编辑文件",editing:"正在编辑 %{file}",emptyFolderAdded:"未从空文件夹添加文件",exceedsSize:"%{file} 超过了最大允许大小 %{size}",failedToUpload:"上传 %{file} 失败",fileSource:"文件来源:%{name}",filesUploadedOfTotal:{0:"已上传 %{complete} / %{smart_count} 个文件",1:"已上传 %{complete} / %{smart_count} 个文件"},filter:"筛选",finishEditingFile:"完成编辑文件",folderAdded:{0:"已从 %{folder} 添加 %{smart_count} 个文件",1:"已从 %{folder} 添加 %{smart_count} 个文件"},generatingThumbnails:"正在生成缩略图...",import:"导入",importFiles:"从以下位置导入文件:",importFrom:"从 %{name} 导入",loading:"加载中...",logOut:"登出",myDevice:"我的设备",noFilesFound:"这里没有文件或文件夹",noInternetConnection:"无网络连接",openFolderNamed:"打开文件夹 %{name}",pause:"暂停",pauseUpload:"暂停上传",paused:"已暂停",poweredBy:"技术支持:%{uppy}",processingXFiles:{0:"正在处理 %{smart_count} 个文件",1:"正在处理 %{smart_count} 个文件"},recording:"录制中",removeFile:"移除文件",resetFilter:"重置筛选",resume:"继续",resumeUpload:"继续上传",retry:"重试",retryUpload:"重试上传",save:"保存",saveChanges:"保存更改",selectFileNamed:"选择文件 %{name}",selectX:{0:"选择 %{smart_count}",1:"选择 %{smart_count}"},smile:"笑一个!",startRecording:"开始录制视频",stopRecording:"停止录制视频",takePicture:"拍照",timedOut:"上传已停滞 %{seconds} 秒,正在中止。",upload:"下一步",uploadComplete:"上传完成",uploadFailed:"上传失败",uploadPaused:"上传已暂停",uploadXFiles:{0:"下一步(%{smart_count} 个文件)",1:"下一步(%{smart_count} 个文件)"},uploadXNewFiles:{0:"下一步(+%{smart_count} 个文件)",1:"下一步(+%{smart_count} 个文件)"},uploading:"正在上传",uploadingXFiles:{0:"正在上传 %{smart_count} 个文件",1:"正在上传 %{smart_count} 个文件"},xFilesSelected:{0:"已选择 %{smart_count} 个文件",1:"已选择 %{smart_count} 个文件"},xMoreFilesAdded:{0:"又添加了 %{smart_count} 个文件",1:"又添加了 %{smart_count} 个文件"},xTimeLeft:"剩余 %{time}",youCanOnlyUploadFileTypes:"您只能上传:%{types}",youCanOnlyUploadX:{0:"您只能上传 %{smart_count} 个文件",1:"您只能上传 %{smart_count} 个文件"},youHaveToAtLeastSelectX:{0:"您至少需要选择 %{smart_count} 个文件",1:"您至少需要选择 %{smart_count} 个文件"},browseFiles:"浏览文件",browseFolders:"浏览文件夹",cancelUpload:"取消上传",addMore:"添加更多",back:"返回",editFileWithFilename:"编辑文件 %{file}"}}}),[]);m.useEffect(()=>{const P=()=>{const M=y.getFiles();if(M.length===0)return;const Z=M.map(G=>({id:G.id,name:G.name,previewUrl:G.preview||URL.createObjectURL(G.data),emotion:"",description:"",isRegistered:!0,file:G.data}));h(Z),M.length===1?(p(Z[0].id),u("edit-single")):u("edit-multiple")};return y.on("upload",P),()=>{y.off("upload",P)}},[y]),m.useEffect(()=>{l||(y.cancelAll(),u("select"),h([]),p(null),v(!1))},[l,y]);const w=m.useCallback((P,M)=>{h(Z=>Z.map(G=>G.id===P?{...G,...M}:G))},[]),b=m.useCallback(P=>P.emotion.trim().length>0,[]),L=m.useMemo(()=>x.length>0&&x.every(b),[x,b]),D=m.useMemo(()=>x.find(P=>P.id===f)||null,[x,f]),T=m.useCallback(()=>{(c==="edit-single"||c==="edit-multiple")&&(u("select"),h([]),p(null))},[c]),F=m.useCallback(async()=>{if(!L){N({title:"请填写必填项",description:"每个表情包的情感标签都是必填的",variant:"destructive"});return}v(!0);let P=0,M=0;try{for(const Z of x){const G=new FormData;G.append("file",Z.file),G.append("emotion",Z.emotion),G.append("description",Z.description),G.append("is_registered",Z.isRegistered.toString());try{(await we(BS(),{method:"POST",body:G})).ok?P++:M++}catch{M++}}M===0?(N({title:"上传成功",description:`成功上传 ${P} 个表情包`}),n(!1),i()):(N({title:"部分上传失败",description:`成功 ${P} 个,失败 ${M} 个`,variant:"destructive"}),i())}finally{v(!1)}},[L,x,N,n,i]),O=()=>e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"border rounded-lg overflow-hidden w-full",children:e.jsx(SS,{uppy:y,proudlyDisplayPoweredByUppy:!1,hideProgressDetails:!0,height:350,width:"100%",theme:"auto",note:"支持 JPG、PNG、GIF、WebP 格式,最多 20 个文件"})})}),S=()=>{const P=x[0];return P?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(k,{variant:"ghost",size:"sm",onClick:T,children:[e.jsx(en,{className:"h-4 w-4 mr-1"}),"返回"]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"编辑表情包信息"})]}),e.jsxs("div",{className:"flex gap-6",children:[e.jsxs("div",{className:"flex-shrink-0",children:[e.jsx("div",{className:"w-32 h-32 rounded-lg border overflow-hidden bg-muted flex items-center justify-center",children:e.jsx("img",{src:P.previewUrl,alt:P.name,className:"max-w-full max-h-full object-contain"})}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2 text-center truncate max-w-32",children:P.name})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(E,{htmlFor:"single-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{id:"single-emotion",value:P.emotion,onChange:M=>w(P.id,{emotion:M.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:P.emotion.trim()?"":"border-destructive"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于情感匹配,多个标签用逗号分隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"single-description",children:"描述"}),e.jsx(re,{id:"single-description",value:P.description,onChange:M=>w(P.id,{description:M.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xs,{id:"single-is-registered",checked:P.isRegistered,onCheckedChange:M=>w(P.id,{isRegistered:M===!0})}),e.jsx(E,{htmlFor:"single-is-registered",className:"cursor-pointer",children:"上传后立即注册(可被麦麦使用)"})]})]})]}),e.jsx(rt,{children:e.jsx(k,{onClick:F,disabled:!L||g,children:g?"上传中...":"上传"})})]}):null},C=()=>{const P=x.filter(b).length,M=x.length;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(k,{variant:"ghost",size:"sm",onClick:T,children:[e.jsx(en,{className:"h-4 w-4 mr-1"}),"返回"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["编辑表情包信息(",P,"/",M," 已完成)"]})]}),e.jsx(Te,{variant:L?"default":"secondary",children:L?e.jsxs(e.Fragment,{children:[e.jsx(_t,{className:"h-3 w-3 mr-1"}),"全部完成"]}):e.jsxs(e.Fragment,{children:[e.jsx(Da,{className:"h-3 w-3 mr-1"}),"未完成"]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Je,{className:"h-[350px] pr-2",children:e.jsx("div",{className:"space-y-2",children:x.map(Z=>{const G=b(Z),ce=f===Z.id;return e.jsxs("div",{onClick:()=>p(Z.id),className:` flex items-center gap-3 p-3 rounded-lg border-2 cursor-pointer transition-all ${ce?"ring-2 ring-primary":""} ${G?"border-green-500 bg-green-50 dark:bg-green-950/20":"border-border hover:border-muted-foreground/50"} `,children:[e.jsx("div",{className:"w-12 h-12 rounded border overflow-hidden bg-muted flex-shrink-0 flex items-center justify-center",children:e.jsx("img",{src:Z.previewUrl,alt:Z.name,className:"max-w-full max-h-full object-contain"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:Z.name}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:Z.emotion||"未填写情感标签"})]}),G?e.jsx(oa,{className:"h-5 w-5 text-green-500 flex-shrink-0"}):e.jsx("div",{className:"h-5 w-5 rounded-full border-2 border-muted-foreground/30 flex-shrink-0"})]},Z.id)})})}),e.jsx("div",{className:"border rounded-lg p-4",children:D?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-16 h-16 rounded border overflow-hidden bg-muted flex items-center justify-center",children:e.jsx("img",{src:D.previewUrl,alt:D.name,className:"max-w-full max-h-full object-contain"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:D.name}),b(D)&&e.jsxs(Te,{variant:"outline",className:"text-green-600 border-green-600",children:[e.jsx(_t,{className:"h-3 w-3 mr-1"}),"已完成"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(E,{htmlFor:"multi-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{id:"multi-emotion",value:D.emotion,onChange:Z=>w(D.id,{emotion:Z.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:D.emotion.trim()?"":"border-destructive"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"multi-description",children:"描述"}),e.jsx(re,{id:"multi-description",value:D.description,onChange:Z=>w(D.id,{description:Z.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xs,{id:"multi-is-registered",checked:D.isRegistered,onCheckedChange:Z=>w(D.id,{isRegistered:Z===!0})}),e.jsx(E,{htmlFor:"multi-is-registered",className:"cursor-pointer text-sm",children:"上传后立即注册"})]})]}):e.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(jj,{className:"h-12 w-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"点击左侧卡片编辑"})]})})})]}),e.jsx(rt,{children:e.jsx(k,{onClick:F,disabled:!L||g,children:g?"上传中...":`上传全部 (${M})`})})]})};return e.jsx(Is,{open:l,onOpenChange:n,children:e.jsxs(Rs,{className:"max-w-3xl max-h-[90vh] overflow-hidden",children:[e.jsxs(Ls,{children:[e.jsxs(Us,{className:"flex items-center gap-2",children:[e.jsx($i,{className:"h-5 w-5"}),c==="select"&&"上传表情包 - 选择文件",c==="edit-single"&&"上传表情包 - 填写信息",c==="edit-multiple"&&"上传表情包 - 批量编辑"]}),e.jsxs(Zs,{children:[c==="select"&&"支持 JPG、PNG、GIF、WebP 格式,单个文件最大 10MB,可同时上传多个文件",c==="edit-single"&&"请填写表情包的情感标签(必填)和描述",c==="edit-multiple"&&"点击左侧卡片编辑每个表情包的信息,情感标签为必填项"]})]}),e.jsxs("div",{className:"overflow-y-auto pr-1",children:[c==="select"&&O(),c==="edit-single"&&S(),c==="edit-multiple"&&C()]})]})})}const an="/api/webui/expression";async function GS(){const l=await we(`${an}/chats`,{});if(!l.ok){const n=await l.json();throw new Error(n.detail||"获取聊天列表失败")}return l.json()}async function qS(l){const n=new URLSearchParams;l.page&&n.append("page",l.page.toString()),l.page_size&&n.append("page_size",l.page_size.toString()),l.search&&n.append("search",l.search),l.chat_id&&n.append("chat_id",l.chat_id);const i=await we(`${an}/list?${n}`,{});if(!i.ok){const c=await i.json();throw new Error(c.detail||"获取表达方式列表失败")}return i.json()}async function FS(l){const n=await we(`${an}/${l}`,{});if(!n.ok){const i=await n.json();throw new Error(i.detail||"获取表达方式详情失败")}return n.json()}async function VS(l){const n=await we(`${an}/`,{method:"POST",body:JSON.stringify(l)});if(!n.ok){const i=await n.json();throw new Error(i.detail||"创建表达方式失败")}return n.json()}async function KS(l,n){const i=await we(`${an}/${l}`,{method:"PATCH",body:JSON.stringify(n)});if(!i.ok){const c=await i.json();throw new Error(c.detail||"更新表达方式失败")}return i.json()}async function QS(l){const n=await we(`${an}/${l}`,{method:"DELETE"});if(!n.ok){const i=await n.json();throw new Error(i.detail||"删除表达方式失败")}return n.json()}async function YS(l){const n=await we(`${an}/batch/delete`,{method:"POST",body:JSON.stringify({ids:l})});if(!n.ok){const i=await n.json();throw new Error(i.detail||"批量删除表达方式失败")}return n.json()}async function JS(){const l=await we(`${an}/stats/summary`,{});if(!l.ok){const n=await l.json();throw new Error(n.detail||"获取统计数据失败")}return l.json()}function XS(){const[l,n]=m.useState([]),[i,c]=m.useState(!0),[u,x]=m.useState(0),[h,f]=m.useState(1),[p,g]=m.useState(20),[v,N]=m.useState(""),[y,w]=m.useState(null),[b,L]=m.useState(!1),[D,T]=m.useState(!1),[F,O]=m.useState(!1),[S,C]=m.useState(null),[P,M]=m.useState(new Set),[Z,G]=m.useState(!1),[ce,de]=m.useState(""),[be,me]=m.useState({total:0,recent_7days:0,chat_count:0,top_chats:{}}),[pe,je]=m.useState([]),[A,Y]=m.useState(new Map),{toast:H}=et(),U=async()=>{try{c(!0);const ee=await qS({page:h,page_size:p,search:v||void 0});n(ee.data),x(ee.total)}catch(ee){H({title:"加载失败",description:ee instanceof Error?ee.message:"无法加载表达方式",variant:"destructive"})}finally{c(!1)}},$=async()=>{try{const ee=await JS();ee?.data&&me(ee.data)}catch(ee){console.error("加载统计数据失败:",ee)}},_e=async()=>{try{const ee=await GS();if(ee?.data){je(ee.data);const De=new Map;ee.data.forEach(Fe=>{De.set(Fe.chat_id,Fe.chat_name)}),Y(De)}}catch(ee){console.error("加载聊天列表失败:",ee)}},Ne=ee=>A.get(ee)||ee;m.useEffect(()=>{U(),$(),_e()},[h,p,v]);const Se=async ee=>{try{const De=await FS(ee.id);w(De.data),L(!0)}catch(De){H({title:"加载详情失败",description:De instanceof Error?De.message:"无法加载表达方式详情",variant:"destructive"})}},V=ee=>{w(ee),T(!0)},ye=async ee=>{try{await QS(ee.id),H({title:"删除成功",description:`已删除表达方式: ${ee.situation}`}),C(null),U(),$()}catch(De){H({title:"删除失败",description:De instanceof Error?De.message:"无法删除表达方式",variant:"destructive"})}},W=ee=>{const De=new Set(P);De.has(ee)?De.delete(ee):De.add(ee),M(De)},ue=()=>{P.size===l.length&&l.length>0?M(new Set):M(new Set(l.map(ee=>ee.id)))},ke=async()=>{try{await YS(Array.from(P)),H({title:"批量删除成功",description:`已删除 ${P.size} 个表达方式`}),M(new Set),G(!1),U(),$()}catch(ee){H({title:"批量删除失败",description:ee instanceof Error?ee.message:"无法批量删除表达方式",variant:"destructive"})}},J=()=>{const ee=parseInt(ce),De=Math.ceil(u/p);ee>=1&&ee<=De?(f(ee),de("")):H({title:"无效的页码",description:`请输入1-${De}之间的页码`,variant:"destructive"})};return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsx("div",{className:"mb-4 sm:mb-6",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(Wl,{className:"h-8 w-8",strokeWidth:2}),"表达方式管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦的表达方式和话术模板"})]}),e.jsxs(k,{onClick:()=>O(!0),className:"gap-2",children:[e.jsx(lt,{className:"h-4 w-4"}),"新增表达方式"]})]})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"总数量"}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:be.total})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"近7天新增"}),e.jsx("div",{className:"text-2xl font-bold mt-1 text-green-600",children:be.recent_7days})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"关联聊天数"}),e.jsx("div",{className:"text-2xl font-bold mt-1 text-blue-600",children:be.chat_count})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx(E,{htmlFor:"search",children:"搜索"}),e.jsx("div",{className:"flex flex-col sm:flex-row gap-2 mt-1.5",children:e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(Vt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(re,{id:"search",placeholder:"搜索情境、风格或上下文...",value:v,onChange:ee=>N(ee.target.value),className:"pl-9"})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 mt-4 pt-4 border-t",children:[e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:P.size>0&&e.jsxs("span",{children:["已选择 ",P.size," 个表达方式"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Le,{value:p.toString(),onValueChange:ee=>{g(parseInt(ee)),f(1),M(new Set)},children:[e.jsx(Oe,{id:"page-size",className:"w-20",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"10",children:"10"}),e.jsx(le,{value:"20",children:"20"}),e.jsx(le,{value:"50",children:"50"}),e.jsx(le,{value:"100",children:"100"})]})]}),P.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>M(new Set),children:"取消选择"}),e.jsxs(k,{variant:"destructive",size:"sm",onClick:()=>G(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(wl,{children:[e.jsx(_l,{children:e.jsxs(nt,{children:[e.jsx(Qe,{className:"w-12",children:e.jsx(Xs,{checked:P.size===l.length&&l.length>0,onCheckedChange:ue})}),e.jsx(Qe,{children:"情境"}),e.jsx(Qe,{children:"风格"}),e.jsx(Qe,{children:"聊天"}),e.jsx(Qe,{className:"text-right",children:"操作"})]})}),e.jsx(Sl,{children:i?e.jsx(nt,{children:e.jsx(Ie,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):l.length===0?e.jsx(nt,{children:e.jsx(Ie,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):l.map(ee=>e.jsxs(nt,{children:[e.jsx(Ie,{children:e.jsx(Xs,{checked:P.has(ee.id),onCheckedChange:()=>W(ee.id)})}),e.jsx(Ie,{className:"font-medium max-w-xs truncate",children:ee.situation}),e.jsx(Ie,{className:"max-w-xs truncate",children:ee.style}),e.jsx(Ie,{className:"max-w-[200px] truncate",title:Ne(ee.chat_id),style:{wordBreak:"keep-all"},children:e.jsx("span",{className:"whitespace-nowrap overflow-hidden text-ellipsis block",children:Ne(ee.chat_id)})}),e.jsx(Ie,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(k,{variant:"default",size:"sm",onClick:()=>V(ee),children:[e.jsx(En,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(k,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>Se(ee),title:"查看详情",children:e.jsx(Xt,{className:"h-4 w-4"})}),e.jsxs(k,{size:"sm",onClick:()=>C(ee),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},ee.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:i?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):l.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):l.map(ee=>e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3 overflow-hidden",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Xs,{checked:P.has(ee.id),onCheckedChange:()=>W(ee.id),className:"mt-1"}),e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden space-y-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"情境"}),e.jsx("h3",{className:"font-semibold text-sm line-clamp-2 w-full break-all",title:ee.situation,children:ee.situation})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"风格"}),e.jsx("p",{className:"text-sm line-clamp-2 w-full break-all",title:ee.style,children:ee.style})]})]})]}),e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"聊天"}),e.jsx("p",{className:"text-sm truncate",title:Ne(ee.chat_id),style:{wordBreak:"keep-all"},children:Ne(ee.chat_id)})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>V(ee),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(En,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>Se(ee),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:e.jsx(Xt,{className:"h-3 w-3"})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>C(ee),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(ns,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},ee.id))}),u>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",u," 条记录,第 ",h," / ",Math.ceil(u/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(zr,{className:"h-4 w-4"})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Wa,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"上一页"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{type:"number",value:ce,onChange:ee=>de(ee.target.value),onKeyDown:ee=>ee.key==="Enter"&&J(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(u/p)}),e.jsx(k,{variant:"outline",size:"sm",onClick:J,disabled:!ce,className:"h-8",children:"跳转"})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(u/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(u/p)),disabled:h>=Math.ceil(u/p),className:"hidden sm:flex",children:e.jsx(Dr,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(ZS,{expression:y,open:b,onOpenChange:L,chatNameMap:A}),e.jsx(WS,{open:F,onOpenChange:O,chatList:pe,onSuccess:()=>{U(),$(),O(!1)}}),e.jsx(e4,{expression:y,open:D,onOpenChange:T,chatList:pe,onSuccess:()=>{U(),$(),T(!1)}}),e.jsx(gs,{open:!!S,onOpenChange:()=>C(null),children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:['确定要删除表达方式 "',S?.situation,'" 吗? 此操作不可撤销。']})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>S&&ye(S),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(s4,{open:Z,onOpenChange:G,onConfirm:ke,count:P.size})]})}function ZS({expression:l,open:n,onOpenChange:i,chatNameMap:c}){if(!l)return null;const u=h=>h?new Date(h*1e3).toLocaleString("zh-CN"):"-",x=h=>c.get(h)||h;return e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Rs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"表达方式详情"}),e.jsx(Zs,{children:"查看表达方式的完整信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ei,{label:"情境",value:l.situation}),e.jsx(Ei,{label:"风格",value:l.style}),e.jsx(Ei,{label:"聊天",value:x(l.chat_id)}),e.jsx(Ei,{icon:Er,label:"记录ID",value:l.id.toString(),mono:!0})]}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsx(Ei,{icon:Nl,label:"创建时间",value:u(l.create_date)})})]}),e.jsx(rt,{children:e.jsx(k,{onClick:()=>i(!1),children:"关闭"})})]})})}function Ei({icon:l,label:n,value:i,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(E,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[l&&e.jsx(l,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:B("text-sm",c&&"font-mono",!i&&"text-muted-foreground"),children:i||"-"})]})}function WS({open:l,onOpenChange:n,chatList:i,onSuccess:c}){const[u,x]=m.useState({situation:"",style:"",chat_id:""}),[h,f]=m.useState(!1),{toast:p}=et(),g=async()=>{if(!u.situation||!u.style||!u.chat_id){p({title:"验证失败",description:"请填写必填字段:情境、风格和聊天",variant:"destructive"});return}try{f(!0),await VS(u),p({title:"创建成功",description:"表达方式已创建"}),x({situation:"",style:"",chat_id:""}),c()}catch(v){p({title:"创建失败",description:v instanceof Error?v.message:"无法创建表达方式",variant:"destructive"})}finally{f(!1)}};return e.jsx(Is,{open:l,onOpenChange:n,children:e.jsxs(Rs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"新增表达方式"}),e.jsx(Zs,{children:"创建新的表达方式记录"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(E,{htmlFor:"situation",children:["情境 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{id:"situation",value:u.situation,onChange:v=>x({...u,situation:v.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(E,{htmlFor:"style",children:["风格 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{id:"style",value:u.style,onChange:v=>x({...u,style:v.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(E,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Le,{value:u.chat_id,onValueChange:v=>x({...u,chat_id:v}),children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:"选择关联的聊天"})}),e.jsx(Re,{children:i.map(v=>e.jsx(le,{value:v.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[v.chat_name,v.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},v.chat_id))})]})]})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>n(!1),children:"取消"}),e.jsx(k,{onClick:g,disabled:h,children:h?"创建中...":"创建"})]})]})})}function e4({expression:l,open:n,onOpenChange:i,chatList:c,onSuccess:u}){const[x,h]=m.useState({}),[f,p]=m.useState(!1),{toast:g}=et();m.useEffect(()=>{l&&h({situation:l.situation,style:l.style,chat_id:l.chat_id})},[l]);const v=async()=>{if(l)try{p(!0),await KS(l.id,x),g({title:"保存成功",description:"表达方式已更新"}),u()}catch(N){g({title:"保存失败",description:N instanceof Error?N.message:"无法更新表达方式",variant:"destructive"})}finally{p(!1)}};return l?e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Rs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"编辑表达方式"}),e.jsx(Zs,{children:"修改表达方式的信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"edit_situation",children:"情境"}),e.jsx(re,{id:"edit_situation",value:x.situation||"",onChange:N=>h({...x,situation:N.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"edit_style",children:"风格"}),e.jsx(re,{id:"edit_style",value:x.style||"",onChange:N=>h({...x,style:N.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Le,{value:x.chat_id||"",onValueChange:N=>h({...x,chat_id:N}),children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:"选择关联的聊天"})}),e.jsx(Re,{children:c.map(N=>e.jsx(le,{value:N.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[N.chat_name,N.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},N.chat_id))})]})]})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(k,{onClick:v,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}function s4({open:l,onOpenChange:n,onConfirm:i,count:c}){return e.jsx(gs,{open:l,onOpenChange:n,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认批量删除"}),e.jsxs(hs,{children:["您即将删除 ",c," 个表达方式,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:i,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})}const Cl="/api/webui/jargon";async function t4(){const l=await we(`${Cl}/chats`,{});if(!l.ok){const n=await l.json();throw new Error(n.detail||"获取聊天列表失败")}return l.json()}async function a4(l){const n=new URLSearchParams;l.page&&n.append("page",l.page.toString()),l.page_size&&n.append("page_size",l.page_size.toString()),l.search&&n.append("search",l.search),l.chat_id&&n.append("chat_id",l.chat_id),l.is_jargon!==void 0&&l.is_jargon!==null&&n.append("is_jargon",l.is_jargon.toString()),l.is_global!==void 0&&n.append("is_global",l.is_global.toString());const i=await we(`${Cl}/list?${n}`,{});if(!i.ok){const c=await i.json();throw new Error(c.detail||"获取黑话列表失败")}return i.json()}async function l4(l){const n=await we(`${Cl}/${l}`,{});if(!n.ok){const i=await n.json();throw new Error(i.detail||"获取黑话详情失败")}return n.json()}async function n4(l){const n=await we(`${Cl}/`,{method:"POST",body:JSON.stringify(l)});if(!n.ok){const i=await n.json();throw new Error(i.detail||"创建黑话失败")}return n.json()}async function r4(l,n){const i=await we(`${Cl}/${l}`,{method:"PATCH",body:JSON.stringify(n)});if(!i.ok){const c=await i.json();throw new Error(c.detail||"更新黑话失败")}return i.json()}async function i4(l){const n=await we(`${Cl}/${l}`,{method:"DELETE"});if(!n.ok){const i=await n.json();throw new Error(i.detail||"删除黑话失败")}return n.json()}async function c4(l){const n=await we(`${Cl}/batch/delete`,{method:"POST",body:JSON.stringify({ids:l})});if(!n.ok){const i=await n.json();throw new Error(i.detail||"批量删除黑话失败")}return n.json()}async function o4(){const l=await we(`${Cl}/stats/summary`,{});if(!l.ok){const n=await l.json();throw new Error(n.detail||"获取黑话统计失败")}return l.json()}async function d4(l,n){const i=new URLSearchParams;l.forEach(u=>i.append("ids",u.toString())),i.append("is_jargon",n.toString());const c=await we(`${Cl}/batch/set-jargon?${i}`,{method:"POST"});if(!c.ok){const u=await c.json();throw new Error(u.detail||"批量设置黑话状态失败")}return c.json()}function u4(){const[l,n]=m.useState([]),[i,c]=m.useState(!0),[u,x]=m.useState(0),[h,f]=m.useState(1),[p,g]=m.useState(20),[v,N]=m.useState(""),[y,w]=m.useState("all"),[b,L]=m.useState("all"),[D,T]=m.useState(null),[F,O]=m.useState(!1),[S,C]=m.useState(!1),[P,M]=m.useState(!1),[Z,G]=m.useState(null),[ce,de]=m.useState(new Set),[be,me]=m.useState(!1),[pe,je]=m.useState(""),[A,Y]=m.useState({total:0,confirmed_jargon:0,confirmed_not_jargon:0,pending:0,global_count:0,complete_count:0,chat_count:0,top_chats:{}}),[H,U]=m.useState([]),{toast:$}=et(),_e=async()=>{try{c(!0);const ge=await a4({page:h,page_size:p,search:v||void 0,chat_id:y==="all"?void 0:y,is_jargon:b==="all"?void 0:b==="true"?!0:b==="false"?!1:void 0});n(ge.data),x(ge.total)}catch(ge){$({title:"加载失败",description:ge instanceof Error?ge.message:"无法加载黑话列表",variant:"destructive"})}finally{c(!1)}},Ne=async()=>{try{const ge=await o4();ge?.data&&Y(ge.data)}catch(ge){console.error("加载统计数据失败:",ge)}},Se=async()=>{try{const ge=await t4();ge?.data&&U(ge.data)}catch(ge){console.error("加载聊天列表失败:",ge)}};m.useEffect(()=>{_e(),Ne(),Se()},[h,p,v,y,b]);const V=async ge=>{try{const as=await l4(ge.id);T(as.data),O(!0)}catch(as){$({title:"加载详情失败",description:as instanceof Error?as.message:"无法加载黑话详情",variant:"destructive"})}},ye=ge=>{T(ge),C(!0)},W=async ge=>{try{await i4(ge.id),$({title:"删除成功",description:`已删除黑话: ${ge.content}`}),G(null),_e(),Ne()}catch(as){$({title:"删除失败",description:as instanceof Error?as.message:"无法删除黑话",variant:"destructive"})}},ue=ge=>{const as=new Set(ce);as.has(ge)?as.delete(ge):as.add(ge),de(as)},ke=()=>{ce.size===l.length&&l.length>0?de(new Set):de(new Set(l.map(ge=>ge.id)))},J=async()=>{try{await c4(Array.from(ce)),$({title:"批量删除成功",description:`已删除 ${ce.size} 个黑话`}),de(new Set),me(!1),_e(),Ne()}catch(ge){$({title:"批量删除失败",description:ge instanceof Error?ge.message:"无法批量删除黑话",variant:"destructive"})}},ee=async ge=>{try{await d4(Array.from(ce),ge),$({title:"操作成功",description:`已将 ${ce.size} 个词条设为${ge?"黑话":"非黑话"}`}),de(new Set),_e(),Ne()}catch(as){$({title:"操作失败",description:as instanceof Error?as.message:"批量设置失败",variant:"destructive"})}},De=()=>{const ge=parseInt(pe),as=Math.ceil(u/p);ge>=1&&ge<=as?(f(ge),je("")):$({title:"无效的页码",description:`请输入1-${as}之间的页码`,variant:"destructive"})},Fe=ge=>ge===!0?e.jsxs(Te,{variant:"default",className:"bg-green-600 hover:bg-green-700",children:[e.jsx(_t,{className:"h-3 w-3 mr-1"}),"是黑话"]}):ge===!1?e.jsxs(Te,{variant:"secondary",children:[e.jsx(Da,{className:"h-3 w-3 mr-1"}),"非黑话"]}):e.jsxs(Te,{variant:"outline",children:[e.jsx(xj,{className:"h-3 w-3 mr-1"}),"未判定"]});return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsx("div",{className:"mb-4 sm:mb-6",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(Rw,{className:"h-8 w-8",strokeWidth:2}),"黑话管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦学习到的黑话和俚语"})]}),e.jsxs(k,{onClick:()=>M(!0),className:"gap-2",children:[e.jsx(lt,{className:"h-4 w-4"}),"新增黑话"]})]})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-7 gap-3",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"总数量"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1",children:A.total})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"已确认黑话"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1 text-green-600",children:A.confirmed_jargon})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"确认非黑话"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1 text-gray-500",children:A.confirmed_not_jargon})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"待判定"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1 text-yellow-600",children:A.pending})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"全局黑话"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1 text-blue-600",children:A.global_count})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"推断完成"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1 text-purple-600",children:A.complete_count})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"关联聊天数"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1",children:A.chat_count})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(E,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx(Vt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(re,{id:"search",placeholder:"搜索内容、含义...",value:v,onChange:ge=>N(ge.target.value),className:"pl-9"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(E,{children:"聊天筛选"}),e.jsxs(Le,{value:y,onValueChange:w,children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:"全部聊天"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部聊天"}),H.map(ge=>e.jsx(le,{value:ge.chat_id,children:ge.chat_name},ge.chat_id))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(E,{children:"状态筛选"}),e.jsxs(Le,{value:b,onValueChange:L,children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:"全部状态"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部状态"}),e.jsx(le,{value:"true",children:"是黑话"}),e.jsx(le,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(E,{htmlFor:"page-size",children:"每页显示"}),e.jsxs(Le,{value:p.toString(),onValueChange:ge=>{g(parseInt(ge)),f(1),de(new Set)},children:[e.jsx(Oe,{id:"page-size",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"10",children:"10"}),e.jsx(le,{value:"20",children:"20"}),e.jsx(le,{value:"50",children:"50"}),e.jsx(le,{value:"100",children:"100"})]})]})]})]}),ce.size>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-4 pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:["已选择 ",ce.size," 个"]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>ee(!0),children:[e.jsx(_t,{className:"h-4 w-4 mr-1"}),"标记为黑话"]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>ee(!1),children:[e.jsx(Da,{className:"h-4 w-4 mr-1"}),"标记为非黑话"]}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>de(new Set),children:"取消选择"}),e.jsxs(k,{variant:"destructive",size:"sm",onClick:()=>me(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(wl,{children:[e.jsx(_l,{children:e.jsxs(nt,{children:[e.jsx(Qe,{className:"w-12",children:e.jsx(Xs,{checked:ce.size===l.length&&l.length>0,onCheckedChange:ke})}),e.jsx(Qe,{children:"内容"}),e.jsx(Qe,{children:"含义"}),e.jsx(Qe,{children:"聊天"}),e.jsx(Qe,{children:"状态"}),e.jsx(Qe,{className:"text-center",children:"次数"}),e.jsx(Qe,{className:"text-right",children:"操作"})]})}),e.jsx(Sl,{children:i?e.jsx(nt,{children:e.jsx(Ie,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):l.length===0?e.jsx(nt,{children:e.jsx(Ie,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):l.map(ge=>e.jsxs(nt,{children:[e.jsx(Ie,{children:e.jsx(Xs,{checked:ce.has(ge.id),onCheckedChange:()=>ue(ge.id)})}),e.jsx(Ie,{className:"font-medium max-w-[200px]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[ge.is_global&&e.jsx("span",{title:"全局黑话",children:e.jsx(_m,{className:"h-4 w-4 text-blue-500 flex-shrink-0"})}),e.jsx("span",{className:"truncate",title:ge.content,children:ge.content})]})}),e.jsx(Ie,{className:"max-w-[200px] truncate",title:ge.meaning||"",children:ge.meaning||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ie,{className:"max-w-[150px] truncate",title:ge.chat_name||ge.chat_id,children:ge.chat_name||ge.chat_id}),e.jsx(Ie,{children:Fe(ge.is_jargon)}),e.jsx(Ie,{className:"text-center",children:ge.count}),e.jsx(Ie,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(k,{variant:"default",size:"sm",onClick:()=>ye(ge),children:[e.jsx(En,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(k,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>V(ge),title:"查看详情",children:e.jsx(Xt,{className:"h-4 w-4"})}),e.jsxs(k,{size:"sm",onClick:()=>G(ge),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},ge.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:i?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):l.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):l.map(ge=>e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Xs,{checked:ce.has(ge.id),onCheckedChange:()=>ue(ge.id),className:"mt-1"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[ge.is_global&&e.jsx(_m,{className:"h-4 w-4 text-blue-500 flex-shrink-0"}),e.jsx("h3",{className:"font-semibold text-sm break-all",children:ge.content})]}),ge.meaning&&e.jsx("p",{className:"text-sm text-muted-foreground break-all",children:ge.meaning}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:[Fe(ge.is_jargon),e.jsxs("span",{className:"text-muted-foreground",children:["次数: ",ge.count]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:["聊天: ",ge.chat_name||ge.chat_id]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t",children:[e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>ye(ge),className:"text-xs px-2 py-1 h-auto",children:[e.jsx(En,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>V(ge),className:"text-xs px-2 py-1 h-auto",children:e.jsx(Xt,{className:"h-3 w-3"})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>G(ge),className:"text-xs px-2 py-1 h-auto text-destructive hover:text-destructive",children:[e.jsx(ns,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},ge.id))}),u>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",u," 条记录,第 ",h," / ",Math.ceil(u/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(zr,{className:"h-4 w-4"})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Wa,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"上一页"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{type:"number",value:pe,onChange:ge=>je(ge.target.value),onKeyDown:ge=>ge.key==="Enter"&&De(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(u/p)}),e.jsx(k,{variant:"outline",size:"sm",onClick:De,disabled:!pe,className:"h-8",children:"跳转"})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(u/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(u/p)),disabled:h>=Math.ceil(u/p),className:"hidden sm:flex",children:e.jsx(Dr,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(m4,{jargon:D,open:F,onOpenChange:O}),e.jsx(x4,{open:P,onOpenChange:M,chatList:H,onSuccess:()=>{_e(),Ne(),M(!1)}}),e.jsx(h4,{jargon:D,open:S,onOpenChange:C,chatList:H,onSuccess:()=>{_e(),Ne(),C(!1)}}),e.jsx(gs,{open:!!Z,onOpenChange:()=>G(null),children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:['确定要删除黑话 "',Z?.content,'" 吗?此操作不可撤销。']})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>Z&&W(Z),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(gs,{open:be,onOpenChange:me,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认批量删除"}),e.jsxs(hs,{children:["您即将删除 ",ce.size," 个黑话,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:J,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})]})}function m4({jargon:l,open:n,onOpenChange:i}){return l?e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Rs,{className:"max-w-2xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"黑话详情"}),e.jsx(Zs,{children:"查看黑话的完整信息"})]}),e.jsx(Je,{className:"h-full pr-4",children:e.jsxs("div",{className:"space-y-4 pb-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(bm,{icon:Er,label:"记录ID",value:l.id.toString(),mono:!0}),e.jsx(bm,{label:"使用次数",value:l.count.toString()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:"内容"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all whitespace-pre-wrap",children:l.content})]}),l.raw_content&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:"原始内容"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:(()=>{try{const c=JSON.parse(l.raw_content);return Array.isArray(c)?c.map((u,x)=>e.jsxs("div",{children:[x>0&&e.jsx("hr",{className:"my-3 border-border"}),e.jsx("div",{className:"whitespace-pre-wrap",children:u})]},x)):e.jsx("div",{className:"whitespace-pre-wrap",children:l.raw_content})}catch{return e.jsx("div",{className:"whitespace-pre-wrap",children:l.raw_content})}})()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:"含义"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:l.meaning?e.jsx(mv,{content:l.meaning}):"-"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(bm,{label:"聊天",value:l.chat_name||l.chat_id}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"flex items-center gap-2",children:[l.is_jargon===!0&&e.jsx(Te,{variant:"default",className:"bg-green-600",children:"是黑话"}),l.is_jargon===!1&&e.jsx(Te,{variant:"secondary",children:"非黑话"}),l.is_jargon===null&&e.jsx(Te,{variant:"outline",children:"未判定"}),l.is_global&&e.jsx(Te,{variant:"outline",className:"border-blue-500 text-blue-500",children:"全局"}),l.is_complete&&e.jsx(Te,{variant:"outline",className:"border-purple-500 text-purple-500",children:"推断完成"})]})]})]}),l.inference_with_context&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:"上下文推断结果"}),e.jsx("div",{className:"p-2 bg-muted rounded break-all whitespace-pre-wrap font-mono text-xs max-h-[200px] overflow-y-auto",children:l.inference_with_context})]}),l.inference_content_only&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:"纯词条推断结果"}),e.jsx("div",{className:"p-2 bg-muted rounded break-all whitespace-pre-wrap font-mono text-xs max-h-[200px] overflow-y-auto",children:l.inference_content_only})]})]})}),e.jsx(rt,{className:"flex-shrink-0",children:e.jsx(k,{onClick:()=>i(!1),children:"关闭"})})]})}):null}function bm({icon:l,label:n,value:i,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(E,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[l&&e.jsx(l,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:B("text-sm",c&&"font-mono",!i&&"text-muted-foreground"),children:i||"-"})]})}function x4({open:l,onOpenChange:n,chatList:i,onSuccess:c}){const[u,x]=m.useState({content:"",meaning:"",chat_id:"",is_global:!1}),[h,f]=m.useState(!1),{toast:p}=et(),g=async()=>{if(!u.content||!u.chat_id){p({title:"验证失败",description:"请填写必填字段:内容和聊天",variant:"destructive"});return}try{f(!0),await n4(u),p({title:"创建成功",description:"黑话已创建"}),x({content:"",meaning:"",chat_id:"",is_global:!1}),c()}catch(v){p({title:"创建失败",description:v instanceof Error?v.message:"无法创建黑话",variant:"destructive"})}finally{f(!1)}};return e.jsx(Is,{open:l,onOpenChange:n,children:e.jsxs(Rs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"新增黑话"}),e.jsx(Zs,{children:"创建新的黑话记录"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(E,{htmlFor:"content",children:["内容 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{id:"content",value:u.content,onChange:v=>x({...u,content:v.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"meaning",children:"含义"}),e.jsx(Ys,{id:"meaning",value:u.meaning||"",onChange:v=>x({...u,meaning:v.target.value}),placeholder:"输入黑话含义(可选)",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(E,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Le,{value:u.chat_id,onValueChange:v=>x({...u,chat_id:v}),children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:"选择关联的聊天"})}),e.jsx(Re,{children:i.map(v=>e.jsx(le,{value:v.chat_id,children:v.chat_name},v.chat_id))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"is_global",checked:u.is_global,onCheckedChange:v=>x({...u,is_global:v})}),e.jsx(E,{htmlFor:"is_global",children:"设为全局黑话"})]})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>n(!1),children:"取消"}),e.jsx(k,{onClick:g,disabled:h,children:h?"创建中...":"创建"})]})]})})}function h4({jargon:l,open:n,onOpenChange:i,chatList:c,onSuccess:u}){const[x,h]=m.useState({}),[f,p]=m.useState(!1),{toast:g}=et();m.useEffect(()=>{l&&h({content:l.content,meaning:l.meaning||"",chat_id:l.stream_id||l.chat_id,is_global:l.is_global,is_jargon:l.is_jargon})},[l]);const v=async()=>{if(l)try{p(!0),await r4(l.id,x),g({title:"保存成功",description:"黑话已更新"}),u()}catch(N){g({title:"保存失败",description:N instanceof Error?N.message:"无法更新黑话",variant:"destructive"})}finally{p(!1)}};return l?e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Rs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"编辑黑话"}),e.jsx(Zs,{children:"修改黑话的信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"edit_content",children:"内容"}),e.jsx(re,{id:"edit_content",value:x.content||"",onChange:N=>h({...x,content:N.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"edit_meaning",children:"含义"}),e.jsx(Ys,{id:"edit_meaning",value:x.meaning||"",onChange:N=>h({...x,meaning:N.target.value}),placeholder:"输入黑话含义",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Le,{value:x.chat_id||"",onValueChange:N=>h({...x,chat_id:N}),children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:"选择关联的聊天"})}),e.jsx(Re,{children:c.map(N=>e.jsx(le,{value:N.chat_id,children:N.chat_name},N.chat_id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:"黑话状态"}),e.jsxs(Le,{value:x.is_jargon===null?"null":x.is_jargon?.toString()||"null",onValueChange:N=>h({...x,is_jargon:N==="null"?null:N==="true"}),children:[e.jsx(Oe,{children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"null",children:"未判定"}),e.jsx(le,{value:"true",children:"是黑话"}),e.jsx(le,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"edit_is_global",checked:x.is_global,onCheckedChange:N=>h({...x,is_global:N})}),e.jsx(E,{htmlFor:"edit_is_global",children:"全局黑话"})]})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(k,{onClick:v,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}const Lr="/api/webui/person";async function f4(l){const n=new URLSearchParams;l.page&&n.append("page",l.page.toString()),l.page_size&&n.append("page_size",l.page_size.toString()),l.search&&n.append("search",l.search),l.is_known!==void 0&&n.append("is_known",l.is_known.toString()),l.platform&&n.append("platform",l.platform);const i=await we(`${Lr}/list?${n}`,{headers:Os()});if(!i.ok){const c=await i.json();throw new Error(c.detail||"获取人物列表失败")}return i.json()}async function p4(l){const n=await we(`${Lr}/${l}`,{headers:Os()});if(!n.ok){const i=await n.json();throw new Error(i.detail||"获取人物详情失败")}return n.json()}async function g4(l,n){const i=await we(`${Lr}/${l}`,{method:"PATCH",headers:Os(),body:JSON.stringify(n)});if(!i.ok){const c=await i.json();throw new Error(c.detail||"更新人物信息失败")}return i.json()}async function j4(l){const n=await we(`${Lr}/${l}`,{method:"DELETE",headers:Os()});if(!n.ok){const i=await n.json();throw new Error(i.detail||"删除人物信息失败")}return n.json()}async function v4(){const l=await we(`${Lr}/stats/summary`,{headers:Os()});if(!l.ok){const n=await l.json();throw new Error(n.detail||"获取统计数据失败")}return l.json()}async function N4(l){const n=await we(`${Lr}/batch/delete`,{method:"POST",headers:Os(),body:JSON.stringify({person_ids:l})});if(!n.ok){const i=await n.json();throw new Error(i.detail||"批量删除失败")}return n.json()}function b4(){const[l,n]=m.useState([]),[i,c]=m.useState(!0),[u,x]=m.useState(0),[h,f]=m.useState(1),[p,g]=m.useState(20),[v,N]=m.useState(""),[y,w]=m.useState(void 0),[b,L]=m.useState(void 0),[D,T]=m.useState(null),[F,O]=m.useState(!1),[S,C]=m.useState(!1),[P,M]=m.useState(null),[Z,G]=m.useState({total:0,known:0,unknown:0,platforms:{}}),[ce,de]=m.useState(new Set),[be,me]=m.useState(!1),[pe,je]=m.useState(""),{toast:A}=et(),Y=async()=>{try{c(!0);const J=await f4({page:h,page_size:p,search:v||void 0,is_known:y,platform:b});n(J.data),x(J.total)}catch(J){A({title:"加载失败",description:J instanceof Error?J.message:"无法加载人物信息",variant:"destructive"})}finally{c(!1)}},H=async()=>{try{const J=await v4();J?.data&&G(J.data)}catch(J){console.error("加载统计数据失败:",J)}};m.useEffect(()=>{Y(),H()},[h,p,v,y,b]);const U=async J=>{try{const ee=await p4(J.person_id);T(ee.data),O(!0)}catch(ee){A({title:"加载详情失败",description:ee instanceof Error?ee.message:"无法加载人物详情",variant:"destructive"})}},$=J=>{T(J),C(!0)},_e=async J=>{try{await j4(J.person_id),A({title:"删除成功",description:`已删除人物信息: ${J.person_name||J.nickname||J.user_id}`}),M(null),Y(),H()}catch(ee){A({title:"删除失败",description:ee instanceof Error?ee.message:"无法删除人物信息",variant:"destructive"})}},Ne=m.useMemo(()=>Object.keys(Z.platforms),[Z.platforms]),Se=J=>{const ee=new Set(ce);ee.has(J)?ee.delete(J):ee.add(J),de(ee)},V=()=>{ce.size===l.length&&l.length>0?de(new Set):de(new Set(l.map(J=>J.person_id)))},ye=()=>{if(ce.size===0){A({title:"未选择任何人物",description:"请先选择要删除的人物",variant:"destructive"});return}me(!0)},W=async()=>{try{const J=await N4(Array.from(ce));A({title:"批量删除完成",description:J.message}),de(new Set),me(!1),Y(),H()}catch(J){A({title:"批量删除失败",description:J instanceof Error?J.message:"批量删除失败",variant:"destructive"})}},ue=()=>{const J=parseInt(pe),ee=Math.ceil(u/p);J>=1&&J<=ee?(f(J),je("")):A({title:"无效的页码",description:`请输入1-${ee}之间的页码`,variant:"destructive"})},ke=J=>J?new Date(J*1e3).toLocaleString("zh-CN"):"-";return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsx("div",{className:"mb-4 sm:mb-6",children:e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(Sm,{className:"h-8 w-8",strokeWidth:2}),"人物信息管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦认识的所有人物信息"})]})})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"总人数"}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:Z.total})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"已认识"}),e.jsx("div",{className:"text-2xl font-bold mt-1 text-green-600",children:Z.known})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"未认识"}),e.jsx("div",{className:"text-2xl font-bold mt-1 text-muted-foreground",children:Z.unknown})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(E,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx(Vt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(re,{id:"search",placeholder:"搜索名称、昵称或用户ID...",value:v,onChange:J=>N(J.target.value),className:"pl-9"})]})]}),e.jsxs("div",{children:[e.jsx(E,{htmlFor:"filter-known",children:"认识状态"}),e.jsxs(Le,{value:y===void 0?"all":y.toString(),onValueChange:J=>{w(J==="all"?void 0:J==="true"),f(1)},children:[e.jsx(Oe,{id:"filter-known",className:"mt-1.5",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部"}),e.jsx(le,{value:"true",children:"已认识"}),e.jsx(le,{value:"false",children:"未认识"})]})]})]}),e.jsxs("div",{children:[e.jsx(E,{htmlFor:"filter-platform",children:"平台"}),e.jsxs(Le,{value:b||"all",onValueChange:J=>{L(J==="all"?void 0:J),f(1)},children:[e.jsx(Oe,{id:"filter-platform",className:"mt-1.5",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部平台"}),Ne.map(J=>e.jsxs(le,{value:J,children:[J," (",Z.platforms[J],")"]},J))]})]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 mt-4 pt-4 border-t",children:[e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:ce.size>0&&e.jsxs("span",{children:["已选择 ",ce.size," 个人物"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Le,{value:p.toString(),onValueChange:J=>{g(parseInt(J)),f(1),de(new Set)},children:[e.jsx(Oe,{id:"page-size",className:"w-20",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"10",children:"10"}),e.jsx(le,{value:"20",children:"20"}),e.jsx(le,{value:"50",children:"50"}),e.jsx(le,{value:"100",children:"100"})]})]}),ce.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>de(new Set),children:"取消选择"}),e.jsxs(k,{variant:"destructive",size:"sm",onClick:ye,children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(wl,{children:[e.jsx(_l,{children:e.jsxs(nt,{children:[e.jsx(Qe,{className:"w-12",children:e.jsx(Xs,{checked:l.length>0&&ce.size===l.length,onCheckedChange:V,"aria-label":"全选"})}),e.jsx(Qe,{children:"状态"}),e.jsx(Qe,{children:"名称"}),e.jsx(Qe,{children:"昵称"}),e.jsx(Qe,{children:"平台"}),e.jsx(Qe,{children:"用户ID"}),e.jsx(Qe,{children:"最后更新"}),e.jsx(Qe,{className:"text-right",children:"操作"})]})}),e.jsx(Sl,{children:i?e.jsx(nt,{children:e.jsx(Ie,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):l.length===0?e.jsx(nt,{children:e.jsx(Ie,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):l.map(J=>e.jsxs(nt,{children:[e.jsx(Ie,{children:e.jsx(Xs,{checked:ce.has(J.person_id),onCheckedChange:()=>Se(J.person_id),"aria-label":`选择 ${J.person_name||J.nickname||J.user_id}`})}),e.jsx(Ie,{children:e.jsx("div",{className:B("inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium",J.is_known?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-400"),children:J.is_known?"已认识":"未认识"})}),e.jsx(Ie,{className:"font-medium",children:J.person_name||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ie,{children:J.nickname||"-"}),e.jsx(Ie,{children:J.platform}),e.jsx(Ie,{className:"font-mono text-sm",children:J.user_id}),e.jsx(Ie,{className:"text-sm text-muted-foreground",children:ke(J.last_know)}),e.jsx(Ie,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(k,{variant:"default",size:"sm",onClick:()=>U(J),children:[e.jsx(Xt,{className:"h-4 w-4 mr-1"}),"详情"]}),e.jsxs(k,{variant:"default",size:"sm",onClick:()=>$(J),children:[e.jsx(En,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsxs(k,{size:"sm",onClick:()=>M(J),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},J.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:i?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):l.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):l.map(J=>e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3 overflow-hidden",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Xs,{checked:ce.has(J.person_id),onCheckedChange:()=>Se(J.person_id),className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:B("inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium mb-2",J.is_known?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-400"),children:J.is_known?"已认识":"未认识"}),e.jsx("h3",{className:"font-semibold text-sm line-clamp-1 w-full break-all",children:J.person_name||e.jsx("span",{className:"text-muted-foreground",children:"未命名"})}),J.nickname&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-1 w-full break-all",children:["昵称: ",J.nickname]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"平台"}),e.jsx("p",{className:"font-medium text-xs",children:J.platform})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"用户ID"}),e.jsx("p",{className:"font-mono text-xs truncate",title:J.user_id,children:J.user_id})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"最后更新"}),e.jsx("p",{className:"text-xs",children:ke(J.last_know)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>U(J),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(Xt,{className:"h-3 w-3 mr-1"}),"查看"]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>$(J),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(En,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>M(J),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(ns,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},J.id))}),u>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",u," 条记录,第 ",h," / ",Math.ceil(u/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(zr,{className:"h-4 w-4"})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Wa,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"上一页"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{type:"number",value:pe,onChange:J=>je(J.target.value),onKeyDown:J=>J.key==="Enter"&&ue(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(u/p)}),e.jsx(k,{variant:"outline",size:"sm",onClick:ue,disabled:!pe,className:"h-8",children:"跳转"})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(u/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(u/p)),disabled:h>=Math.ceil(u/p),className:"hidden sm:flex",children:e.jsx(Dr,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(y4,{person:D,open:F,onOpenChange:O}),e.jsx(w4,{person:D,open:S,onOpenChange:C,onSuccess:()=>{Y(),H(),C(!1)}}),e.jsx(gs,{open:!!P,onOpenChange:()=>M(null),children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认删除"}),e.jsxs(hs,{children:['确定要删除人物信息 "',P?.person_name||P?.nickname||P?.user_id,'" 吗? 此操作不可撤销。']})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:()=>P&&_e(P),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(gs,{open:be,onOpenChange:me,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"确认批量删除"}),e.jsxs(hs,{children:["确定要删除选中的 ",ce.size," 个人物信息吗? 此操作不可撤销。"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{children:"取消"}),e.jsx(fs,{onClick:W,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})})]})}function y4({person:l,open:n,onOpenChange:i}){if(!l)return null;const c=u=>u?new Date(u*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Rs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"人物详情"}),e.jsxs(Zs,{children:["查看 ",l.person_name||l.nickname||l.user_id," 的完整信息"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(jl,{icon:kr,label:"人物名称",value:l.person_name}),e.jsx(jl,{icon:Wl,label:"昵称",value:l.nickname}),e.jsx(jl,{icon:Er,label:"用户ID",value:l.user_id,mono:!0}),e.jsx(jl,{icon:Er,label:"人物ID",value:l.person_id,mono:!0}),e.jsx(jl,{label:"平台",value:l.platform}),e.jsx(jl,{label:"状态",value:l.is_known?"已认识":"未认识"})]}),l.name_reason&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:"名称设定原因"}),e.jsx("p",{className:"mt-1 text-sm",children:l.name_reason})]}),l.memory_points&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:"个人印象"}),e.jsx("p",{className:"mt-1 text-sm whitespace-pre-wrap",children:l.memory_points})]}),l.group_nick_name&&l.group_nick_name.length>0&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(E,{className:"text-xs text-muted-foreground",children:"群昵称"}),e.jsx("div",{className:"mt-2 space-y-1",children:l.group_nick_name.map((u,x)=>e.jsxs("div",{className:"text-sm flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:u.group_id}),e.jsx("span",{children:"→"}),e.jsx("span",{children:u.group_nick_name})]},x))})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(jl,{icon:Nl,label:"认识时间",value:c(l.know_times)}),e.jsx(jl,{icon:Nl,label:"首次记录",value:c(l.know_since)}),e.jsx(jl,{icon:Nl,label:"最后更新",value:c(l.last_know)})]})]}),e.jsx(rt,{children:e.jsx(k,{onClick:()=>i(!1),children:"关闭"})})]})})}function jl({icon:l,label:n,value:i,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(E,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[l&&e.jsx(l,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:B("text-sm",c&&"font-mono",!i&&"text-muted-foreground"),children:i||"-"})]})}function w4({person:l,open:n,onOpenChange:i,onSuccess:c}){const[u,x]=m.useState({}),[h,f]=m.useState(!1),{toast:p}=et();m.useEffect(()=>{l&&x({person_name:l.person_name||"",name_reason:l.name_reason||"",nickname:l.nickname||"",memory_points:l.memory_points||"",is_known:l.is_known})},[l]);const g=async()=>{if(l)try{f(!0),await g4(l.person_id,u),p({title:"保存成功",description:"人物信息已更新"}),c()}catch(v){p({title:"保存失败",description:v instanceof Error?v.message:"无法更新人物信息",variant:"destructive"})}finally{f(!1)}};return l?e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Rs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"编辑人物信息"}),e.jsxs(Zs,{children:["修改 ",l.person_name||l.nickname||l.user_id," 的信息"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"person_name",children:"人物名称"}),e.jsx(re,{id:"person_name",value:u.person_name||"",onChange:v=>x({...u,person_name:v.target.value}),placeholder:"为这个人设置一个名称"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"nickname",children:"昵称"}),e.jsx(re,{id:"nickname",value:u.nickname||"",onChange:v=>x({...u,nickname:v.target.value}),placeholder:"昵称"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"name_reason",children:"名称设定原因"}),e.jsx(Ys,{id:"name_reason",value:u.name_reason||"",onChange:v=>x({...u,name_reason:v.target.value}),placeholder:"为什么这样称呼这个人?",rows:2})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"memory_points",children:"个人印象"}),e.jsx(Ys,{id:"memory_points",value:u.memory_points||"",onChange:v=>x({...u,memory_points:v.target.value}),placeholder:"对这个人的印象和记忆点...",rows:4})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{children:[e.jsx(E,{htmlFor:"is_known",className:"text-base font-medium",children:"已认识"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"标记是否已经认识这个人"})]}),e.jsx(Pe,{id:"is_known",checked:u.is_known,onCheckedChange:v=>x({...u,is_known:v})})]})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(k,{onClick:g,disabled:h,children:h?"保存中...":"保存"})]})]})}):null}var _4=x1();const hg=t0(_4),qm="/api/webui";async function S4(l=100,n="all"){const i=`${qm}/knowledge/graph?limit=${l}&node_type=${n}`,c=await fetch(i);if(!c.ok)throw new Error(`获取知识图谱失败: ${c.status}`);return c.json()}async function C4(){const l=await fetch(`${qm}/knowledge/stats`);if(!l.ok)throw new Error("获取知识图谱统计信息失败");return l.json()}async function k4(l){const n=await fetch(`${qm}/knowledge/search?query=${encodeURIComponent(l)}`);if(!n.ok)throw new Error("搜索知识节点失败");return n.json()}const xv=m.memo(({data:l})=>e.jsxs("div",{className:"px-4 py-2 shadow-md rounded-lg bg-gradient-to-br from-blue-500 to-blue-600 border-2 border-blue-700 min-w-[120px]",children:[e.jsx(ko,{type:"target",position:To.Top}),e.jsx("div",{className:"font-semibold text-white text-sm truncate max-w-[200px]",title:l.content,children:l.label}),e.jsx(ko,{type:"source",position:To.Bottom})]}));xv.displayName="EntityNode";const hv=m.memo(({data:l})=>e.jsxs("div",{className:"px-3 py-2 shadow-md rounded-md bg-gradient-to-br from-green-500 to-green-600 border-2 border-green-700 min-w-[100px]",children:[e.jsx(ko,{type:"target",position:To.Top}),e.jsx("div",{className:"font-medium text-white text-xs truncate max-w-[150px]",title:l.content,children:l.label}),e.jsx(ko,{type:"source",position:To.Bottom})]}));hv.displayName="ParagraphNode";const T4={entity:xv,paragraph:hv};function E4(l,n){const i=new hg.graphlib.Graph;i.setDefaultEdgeLabel(()=>({})),i.setGraph({rankdir:"TB",ranksep:100,nodesep:80});const c=[],u=[];return l.forEach(x=>{i.setNode(x.id,{width:150,height:50})}),n.forEach(x=>{i.setEdge(x.source,x.target)}),hg.layout(i),l.forEach(x=>{const h=i.node(x.id);c.push({id:x.id,type:x.type,position:{x:h.x-75,y:h.y-25},data:{label:x.content.slice(0,20)+(x.content.length>20?"...":""),content:x.content}})}),n.forEach((x,h)=>{const f={id:`edge-${h}`,source:x.source,target:x.target,animated:l.length<=200&&x.weight>5,style:{strokeWidth:Math.min(x.weight/2,5),opacity:.6}};x.weight>10&&l.length<100&&(f.label=`${x.weight.toFixed(0)}`),u.push(f)}),{nodes:c,edges:u}}function M4(){const l=ua(),[n,i]=m.useState(!1),[c,u]=m.useState(null),[x,h]=m.useState(""),[f,p]=m.useState("all"),[g,v]=m.useState(50),[N,y]=m.useState("50"),[w,b]=m.useState(!1),[L,D]=m.useState(!0),[T,F]=m.useState(!1),[O,S]=m.useState(!1),[C,P,M]=h1([]),[Z,G,ce]=f1([]),[de,be]=m.useState(0),[me,pe]=m.useState(null),[je,A]=m.useState(null),{toast:Y}=et(),H=m.useCallback(W=>W.type==="entity"?"#6366f1":W.type==="paragraph"?"#10b981":"#6b7280",[]),U=m.useCallback(async(W=!1)=>{try{if(!W&&g>200){S(!0);return}i(!0);const[ue,ke]=await Promise.all([S4(g,f),C4()]);if(u(ke),ue.nodes.length===0){Y({title:"提示",description:"知识库为空,请先导入知识数据"}),P([]),G([]);return}const{nodes:J,edges:ee}=E4(ue.nodes,ue.edges);P(J),G(ee),be(J.length),ke&&ke.total_nodes>g&&Y({title:"提示",description:`知识图谱包含 ${ke.total_nodes} 个节点,当前显示 ${J.length} 个`}),Y({title:"加载成功",description:`已加载 ${J.length} 个节点,${ee.length} 条边`})}catch(ue){console.error("加载知识图谱失败:",ue),Y({title:"加载失败",description:ue instanceof Error?ue.message:"未知错误",variant:"destructive"})}finally{i(!1)}},[g,f,Y]),$=m.useCallback(async()=>{if(!x.trim()){Y({title:"提示",description:"请输入搜索关键词"});return}try{const W=await k4(x);if(W.length===0){Y({title:"未找到",description:"没有找到匹配的节点"});return}const ue=new Set(W.map(ke=>ke.id));P(ke=>ke.map(J=>({...J,style:{...J.style,opacity:ue.has(J.id)?1:.3,filter:ue.has(J.id)?"brightness(1.2)":"brightness(0.8)"}}))),Y({title:"搜索完成",description:`找到 ${W.length} 个匹配节点`})}catch(W){console.error("搜索失败:",W),Y({title:"搜索失败",description:W instanceof Error?W.message:"未知错误",variant:"destructive"})}},[x,Y]),_e=m.useCallback(()=>{P(W=>W.map(ue=>({...ue,style:{...ue.style,opacity:1,filter:"brightness(1)"}})))},[]),Ne=m.useCallback(()=>{D(!1),F(!0),U()},[U]),Se=m.useCallback(()=>{S(!1),setTimeout(()=>{U(!0)},0)},[U]),V=m.useCallback((W,ue)=>{C.find(J=>J.id===ue.id)&&pe({id:ue.id,type:ue.type,content:ue.data.content})},[C]);m.useEffect(()=>{L||T&&U()},[g,f,L,T]);const ye=m.useCallback((W,ue)=>{const ke=C.find(De=>De.id===ue.source),J=C.find(De=>De.id===ue.target),ee=Z.find(De=>De.id===ue.id);ke&&J&&ee&&A({source:{id:ke.id,type:ke.type,content:ke.data.content},target:{id:J.id,type:J.type,content:J.data.content},edge:{source:ue.source,target:ue.target,weight:parseFloat(ue.label||"0")}})},[C,Z]);return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex-shrink-0 p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"麦麦知识库图谱"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"可视化知识实体与关系网络"})]}),c&&e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(Te,{variant:"outline",className:"gap-1",children:[e.jsx(Cr,{className:"h-3 w-3"}),"节点: ",c.total_nodes]}),e.jsxs(Te,{variant:"outline",className:"gap-1",children:[e.jsx(vj,{className:"h-3 w-3"}),"边: ",c.total_edges]}),e.jsxs(Te,{variant:"outline",className:"gap-1",children:[e.jsx(Jt,{className:"h-3 w-3"}),"实体: ",c.entity_nodes]}),e.jsxs(Te,{variant:"outline",className:"gap-1",children:[e.jsx(Ha,{className:"h-3 w-3"}),"段落: ",c.paragraph_nodes]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 mt-4",children:[e.jsxs("div",{className:"flex-1 flex gap-2",children:[e.jsx(re,{placeholder:"搜索节点内容...",value:x,onChange:W=>h(W.target.value),onKeyDown:W=>W.key==="Enter"&&$(),className:"flex-1"}),e.jsx(k,{onClick:$,size:"sm",children:e.jsx(Vt,{className:"h-4 w-4"})}),e.jsx(k,{onClick:_e,variant:"outline",size:"sm",children:"重置"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Le,{value:f,onValueChange:W=>p(W),children:[e.jsx(Oe,{className:"w-[120px]",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部节点"}),e.jsx(le,{value:"entity",children:"仅实体"}),e.jsx(le,{value:"paragraph",children:"仅段落"})]})]}),e.jsxs(Le,{value:g===1e4?"all":w?"custom":g.toString(),onValueChange:W=>{W==="custom"?(b(!0),y(g.toString())):W==="all"?(b(!1),v(1e4)):(b(!1),v(Number(W)))},children:[e.jsx(Oe,{className:"w-[120px]",children:e.jsx(Ue,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"50",children:"50 节点"}),e.jsx(le,{value:"100",children:"100 节点"}),e.jsx(le,{value:"200",children:"200 节点"}),e.jsx(le,{value:"500",children:"500 节点"}),e.jsx(le,{value:"1000",children:"1000 节点"}),e.jsx(le,{value:"all",children:"全部 (最多10000)"}),e.jsx(le,{value:"custom",children:"自定义..."})]})]}),w&&e.jsx(re,{type:"number",min:"50",value:N,onChange:W=>y(W.target.value),onBlur:()=>{const W=parseInt(N);!isNaN(W)&&W>=50?v(W):(y("50"),v(50))},onKeyDown:W=>{if(W.key==="Enter"){const ue=parseInt(N);!isNaN(ue)&&ue>=50?v(ue):(y("50"),v(50))}},placeholder:"最少50个",className:"w-[120px]"}),e.jsx(k,{onClick:()=>U(),variant:"outline",size:"sm",disabled:n,children:e.jsx(zt,{className:B("h-4 w-4",n&&"animate-spin")})})]})]})]}),e.jsx("div",{className:"flex-1 relative",children:n?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(zt,{className:"h-8 w-8 animate-spin mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"加载知识图谱中..."})]})}):C.length===0?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Cr,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"知识库为空"}),e.jsx("p",{className:"text-muted-foreground",children:"请先导入知识数据"})]})}):e.jsxs(p1,{nodes:C,edges:Z,onNodesChange:M,onEdgesChange:ce,onNodeClick:V,onEdgeClick:ye,nodeTypes:T4,fitView:!0,minZoom:.05,maxZoom:1.5,defaultViewport:{x:0,y:0,zoom:.5},elevateNodesOnSelect:de<=500,nodesDraggable:de<=1e3,attributionPosition:"bottom-left",children:[e.jsx(g1,{variant:j1.Dots,gap:12,size:1}),e.jsx(v1,{}),de<=500&&e.jsx(N1,{nodeColor:H,nodeBorderRadius:8,pannable:!0,zoomable:!0}),e.jsxs(b1,{position:"top-right",className:"bg-background/95 backdrop-blur-sm rounded-lg border p-3 shadow-lg",children:[e.jsx("div",{className:"text-sm font-semibold mb-2",children:"图例"}),e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded bg-gradient-to-br from-blue-500 to-blue-600 border-2 border-blue-700"}),e.jsx("span",{children:"实体节点"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded bg-gradient-to-br from-green-500 to-green-600 border-2 border-green-700"}),e.jsx("span",{children:"段落节点"})]}),de>200&&e.jsxs("div",{className:"mt-2 pt-2 border-t text-yellow-600 dark:text-yellow-500",children:[e.jsx("div",{className:"font-semibold",children:"性能模式"}),e.jsx("div",{children:"已禁用动画"}),de>500&&e.jsx("div",{children:"已禁用缩略图"})]})]})]})]})}),e.jsx(Is,{open:!!me,onOpenChange:W=>!W&&pe(null),children:e.jsxs(Rs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(Ls,{children:e.jsx(Us,{children:"节点详情"})}),me&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"类型"}),e.jsx("div",{className:"mt-1",children:e.jsx(Te,{variant:me.type==="entity"?"default":"secondary",children:me.type==="entity"?"🏷️ 实体":"📄 段落"})})]})}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"ID"}),e.jsx("code",{className:"mt-1 block p-2 bg-muted rounded text-xs break-all",children:me.id})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"内容"}),e.jsx(Je,{className:"mt-1 h-40 p-3 bg-muted rounded",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:me.content})})]})]})]})}),e.jsx(Is,{open:!!je,onOpenChange:W=>!W&&A(null),children:e.jsxs(Rs,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsx(Ls,{children:e.jsx(Us,{children:"边详情"})}),je&&e.jsx(Je,{className:"flex-1 pr-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0 p-3 bg-blue-50 dark:bg-blue-950 rounded border-2 border-blue-200 dark:border-blue-800",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"源节点"}),e.jsx("div",{className:"font-medium text-sm mb-2 truncate",children:je.source.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[je.source.id.slice(0,40),"..."]})]}),e.jsx("div",{className:"text-2xl text-muted-foreground flex-shrink-0",children:"→"}),e.jsxs("div",{className:"flex-1 min-w-0 p-3 bg-green-50 dark:bg-green-950 rounded border-2 border-green-200 dark:border-green-800",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"目标节点"}),e.jsx("div",{className:"font-medium text-sm mb-2 truncate",children:je.target.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[je.target.id.slice(0,40),"..."]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"权重"}),e.jsx("div",{className:"mt-1",children:e.jsx(Te,{variant:"outline",className:"text-base font-mono",children:je.edge.weight.toFixed(4)})})]})]})})]})}),e.jsx(gs,{open:L,onOpenChange:D,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"加载知识图谱"}),e.jsxs(hs,{children:["知识图谱的动态展示会消耗较多系统资源。",e.jsx("br",{}),"确定要加载知识图谱吗?"]})]}),e.jsxs(ms,{children:[e.jsx(ps,{onClick:()=>l({to:"/"}),children:"取消 (返回首页)"}),e.jsx(fs,{onClick:Ne,children:"确认加载"})]})]})}),e.jsx(gs,{open:O,onOpenChange:S,children:e.jsxs(ds,{children:[e.jsxs(us,{children:[e.jsx(xs,{children:"⚠️ 节点数量较多"}),e.jsx(hs,{asChild:!0,children:e.jsxs("div",{children:[e.jsxs("p",{children:["您正在尝试加载 ",e.jsx("strong",{className:"text-orange-600",children:g>=1e4?"全部 (最多10000个)":g})," 个节点。"]}),e.jsx("p",{className:"mt-4",children:"节点数量过多可能导致:"}),e.jsxs("ul",{className:"list-disc list-inside mt-2 space-y-1",children:[e.jsx("li",{children:"页面加载时间较长"}),e.jsx("li",{children:"浏览器卡顿或崩溃"}),e.jsx("li",{children:"系统资源占用过高"})]}),e.jsx("p",{className:"mt-4",children:"建议先选择较少的节点数量 (50-200 个)。"})]})})]}),e.jsxs(ms,{children:[e.jsx(ps,{onClick:()=>{S(!1),g>200&&(v(50),b(!1))},children:"取消"}),e.jsx(fs,{onClick:Se,className:"bg-orange-600 hover:bg-orange-700",children:"我了解风险,继续加载"})]})]})})]})}function A4(){return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsx("div",{className:"flex-none border-b bg-card/50 px-6 py-4",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"麦麦知识库管理"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"管理和组织麦麦的知识库内容"})]})})}),e.jsx("div",{className:"flex-1 overflow-auto p-6",children:e.jsx("div",{className:"mx-auto max-w-4xl",children:e.jsxs(ze,{children:[e.jsxs(ts,{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-20 w-20 items-center justify-center rounded-full bg-primary/10",children:e.jsx(Cr,{className:"h-10 w-10 text-primary"})}),e.jsx(ls,{className:"text-2xl",children:"麦麦知识库管理"}),e.jsx(Vs,{className:"text-base",children:"功能开发中,敬请期待"})]}),e.jsx(Ye,{className:"text-center text-sm text-muted-foreground",children:e.jsx("p",{children:"此功能将提供知识库的创建、编辑、导入和管理能力"})})]})})})]})}function fg({className:l,classNames:n,showOutsideDays:i=!0,captionLayout:c="label",buttonVariant:u="ghost",formatters:x,components:h,...f}){const p=Lj();return e.jsx(r1,{showOutsideDays:i,className:B("bg-background group/calendar p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,l),captionLayout:c,formatters:{formatMonthDropdown:g=>g.toLocaleString("default",{month:"short"}),...x},classNames:{root:B("w-fit",p.root),months:B("relative flex flex-col gap-4 md:flex-row",p.months),month:B("flex w-full flex-col gap-4",p.month),nav:B("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",p.nav),button_previous:B(Mr({variant:u}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",p.button_previous),button_next:B(Mr({variant:u}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",p.button_next),month_caption:B("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",p.month_caption),dropdowns:B("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",p.dropdowns),dropdown_root:B("has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border",p.dropdown_root),dropdown:B("bg-popover absolute inset-0 opacity-0",p.dropdown),caption_label:B("select-none font-medium",c==="label"?"text-sm":"[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5",p.caption_label),table:"w-full border-collapse",weekdays:B("flex",p.weekdays),weekday:B("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",p.weekday),week:B("mt-2 flex w-full",p.week),week_number_header:B("w-[--cell-size] select-none",p.week_number_header),week_number:B("text-muted-foreground select-none text-[0.8rem]",p.week_number),day:B("group/day relative aspect-square h-full w-full select-none p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md",p.day),range_start:B("bg-accent rounded-l-md",p.range_start),range_middle:B("rounded-none",p.range_middle),range_end:B("bg-accent rounded-r-md",p.range_end),today:B("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",p.today),outside:B("text-muted-foreground aria-selected:text-muted-foreground",p.outside),disabled:B("text-muted-foreground opacity-50",p.disabled),hidden:B("invisible",p.hidden),...n},components:{Root:({className:g,rootRef:v,...N})=>e.jsx("div",{"data-slot":"calendar",ref:v,className:B(g),...N}),Chevron:({className:g,orientation:v,...N})=>v==="left"?e.jsx(Wa,{className:B("size-4",g),...N}):v==="right"?e.jsx(ba,{className:B("size-4",g),...N}):e.jsx(Oa,{className:B("size-4",g),...N}),DayButton:z4,WeekNumber:({children:g,...v})=>e.jsx("td",{...v,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:g})}),...h},...f})}function z4({className:l,day:n,modifiers:i,...c}){const u=Lj(),x=m.useRef(null);return m.useEffect(()=>{i.focused&&x.current?.focus()},[i.focused]),e.jsx(k,{ref:x,variant:"ghost",size:"icon","data-day":n.date.toLocaleDateString(),"data-selected-single":i.selected&&!i.range_start&&!i.range_end&&!i.range_middle,"data-range-start":i.range_start,"data-range-end":i.range_end,"data-range-middle":i.range_middle,className:B("data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 flex aspect-square h-auto w-full min-w-[--cell-size] flex-col gap-1 font-normal leading-none data-[range-end=true]:rounded-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] [&>span]:text-xs [&>span]:opacity-70",u.day,l),...c})}const po={xs:{label:"小",rowHeight:28,class:"text-[10px] sm:text-xs"},sm:{label:"中",rowHeight:36,class:"text-xs sm:text-sm"},base:{label:"大",rowHeight:44,class:"text-sm sm:text-base"}};function D4(){const[l,n]=m.useState([]),[i,c]=m.useState(""),[u,x]=m.useState("all"),[h,f]=m.useState("all"),[p,g]=m.useState(void 0),[v,N]=m.useState(void 0),[y,w]=m.useState(!0),[b,L]=m.useState(!1),[D,T]=m.useState("xs"),[F,O]=m.useState(4),[S,C]=m.useState(!1),P=m.useRef(null);m.useEffect(()=>{const $=wn.getAllLogs();n($);const _e=wn.onLog(()=>{n(wn.getAllLogs())}),Ne=wn.onConnectionChange(Se=>{L(Se)});return()=>{_e(),Ne()}},[]);const M=m.useMemo(()=>{const $=new Set(l.map(_e=>_e.module).filter(_e=>_e&&_e.trim()!==""));return Array.from($).sort()},[l]),Z=$=>{switch($){case"DEBUG":return"text-muted-foreground";case"INFO":return"text-blue-500 dark:text-blue-400";case"WARNING":return"text-yellow-600 dark:text-yellow-500";case"ERROR":return"text-red-600 dark:text-red-500";case"CRITICAL":return"text-red-700 dark:text-red-400 font-bold";default:return"text-foreground"}},G=$=>{switch($){case"DEBUG":return"bg-gray-800/30 dark:bg-gray-800/50";case"INFO":return"bg-blue-900/20 dark:bg-blue-500/20";case"WARNING":return"bg-yellow-900/20 dark:bg-yellow-500/20";case"ERROR":return"bg-red-900/20 dark:bg-red-500/20";case"CRITICAL":return"bg-red-900/30 dark:bg-red-600/30";default:return"bg-gray-800/20 dark:bg-gray-800/30"}},ce=()=>{window.location.reload()},de=()=>{wn.clearLogs(),n([])},be=()=>{const $=je.map(V=>`${V.timestamp} [${V.level.padEnd(8)}] [${V.module}] ${V.message}`).join(` `),_e=new Blob([$],{type:"text/plain;charset=utf-8"}),Ne=URL.createObjectURL(_e),Se=document.createElement("a");Se.href=Ne,Se.download=`logs-${lm(new Date,"yyyy-MM-dd-HHmmss")}.txt`,Se.click(),URL.revokeObjectURL(Ne)},me=()=>{w(!y)},pe=()=>{g(void 0),N(void 0)},je=m.useMemo(()=>l.filter($=>{const _e=i===""||$.message.toLowerCase().includes(i.toLowerCase())||$.module.toLowerCase().includes(i.toLowerCase()),Ne=u==="all"||$.level===u,Se=h==="all"||$.module===h;let V=!0;if(p||v){const ye=new Date($.timestamp);if(p){const W=new Date(p);W.setHours(0,0,0,0),V=V&&ye>=W}if(v){const W=new Date(v);W.setHours(23,59,59,999),V=V&&ye<=W}}return _e&&Ne&&Se&&V}),[l,i,u,h,p,v]),A=po[D].rowHeight+F,Y=Qy({count:je.length,getScrollElement:()=>P.current,estimateSize:()=>A,overscan:50}),H=m.useRef(!1),U=m.useRef(je.length);return m.useEffect(()=>{const $=P.current;if(!$)return;const _e=()=>{if(H.current)return;const{scrollTop:Ne,scrollHeight:Se,clientHeight:V}=$,ye=Se-Ne-V;ye>100&&y?w(!1):ye<50&&!y&&w(!0)};return $.addEventListener("scroll",_e,{passive:!0}),()=>$.removeEventListener("scroll",_e)},[y]),m.useEffect(()=>{const $=je.length>U.current;U.current=je.length,y&&je.length>0&&$&&(H.current=!0,Y.scrollToIndex(je.length-1,{align:"end",behavior:"auto"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{H.current=!1})}))},[je.length,y,Y]),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-shrink-0 space-y-2 sm:space-y-3 p-2 sm:p-3 lg:p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg sm:text-xl lg:text-2xl font-bold",children:"日志查看器"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 hidden sm:block",children:"实时查看和分析麦麦运行日志"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:B("h-2 w-2 sm:h-2.5 sm:w-2.5 rounded-full",b?"bg-green-500 animate-pulse":"bg-red-500")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:b?"已连接":"未连接"})]})]}),e.jsx(ze,{className:"p-2 sm:p-3",children:e.jsx(Gi,{open:S,onOpenChange:C,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 relative min-w-0",children:[e.jsx(Vt,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(re,{placeholder:"搜索日志...",value:i,onChange:$=>c($.target.value),className:"pl-8 h-8 text-xs sm:text-sm"})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs(k,{variant:y?"default":"outline",size:"sm",onClick:me,className:"h-8 px-2",title:y?"自动滚动":"已暂停",children:[y?e.jsx(Lw,{className:"h-3.5 w-3.5"}):e.jsx(Uw,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden sm:inline",children:y?"滚动":"暂停"})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:de,className:"h-8 px-2",title:"清空日志",children:[e.jsx(ns,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden md:inline",children:"清空"})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:be,className:"h-8 px-2 hidden sm:flex",title:"导出日志",children:[e.jsx(Yt,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden lg:inline",children:"导出"})]}),e.jsx(qi,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",className:"h-8 px-2",title:S?"收起筛选":"展开筛选",children:[e.jsx(No,{className:"h-3.5 w-3.5"}),S?e.jsx(Tr,{className:"h-3.5 w-3.5 ml-1"}):e.jsx(Oa,{className:"h-3.5 w-3.5 ml-1"})]})})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground text-center sm:text-right -mt-1",children:[e.jsxs("span",{className:"font-mono",children:[je.length," / ",l.length]}),e.jsx("span",{className:"ml-1",children:"条日志"})]}),e.jsxs(Fi,{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(Le,{value:u,onValueChange:x,children:[e.jsxs(Oe,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(No,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Ue,{placeholder:"级别"})]}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部级别"}),e.jsx(le,{value:"DEBUG",children:"DEBUG"}),e.jsx(le,{value:"INFO",children:"INFO"}),e.jsx(le,{value:"WARNING",children:"WARNING"}),e.jsx(le,{value:"ERROR",children:"ERROR"}),e.jsx(le,{value:"CRITICAL",children:"CRITICAL"})]})]}),e.jsxs(Le,{value:h,onValueChange:f,children:[e.jsxs(Oe,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(No,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Ue,{placeholder:"模块"})]}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部模块"}),M.map($=>e.jsx(le,{value:$,children:$},$))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(Xa,{children:[e.jsx(Za,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",className:B("w-full sm:flex-1 justify-start text-left font-normal h-8",!p&&"text-muted-foreground"),children:[e.jsx(Gp,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:p?lm(p,"PP",{locale:ho}):"开始日期"})]})}),e.jsx(Ia,{className:"w-auto p-0",align:"start",children:e.jsx(fg,{mode:"single",selected:p,onSelect:g,initialFocus:!0,locale:ho})})]}),e.jsxs(Xa,{children:[e.jsx(Za,{asChild:!0,children:e.jsxs(k,{variant:"outline",size:"sm",className:B("w-full sm:flex-1 justify-start text-left font-normal h-8",!v&&"text-muted-foreground"),children:[e.jsx(Gp,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:v?lm(v,"PP",{locale:ho}):"结束日期"})]})}),e.jsx(Ia,{className:"w-auto p-0",align:"start",children:e.jsx(fg,{mode:"single",selected:v,onSelect:N,initialFocus:!0,locale:ho})})]}),(p||v)&&e.jsxs(k,{variant:"outline",size:"sm",onClick:pe,className:"w-full sm:w-auto h-8",children:[e.jsx(Da,{className:"h-3.5 w-3.5 sm:mr-1"}),e.jsx("span",{className:"text-xs",children:"清除"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Bw,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"字号"})]}),e.jsx("div",{className:"flex gap-1",children:Object.keys(po).map($=>e.jsx(k,{variant:D===$?"default":"outline",size:"sm",onClick:()=>T($),className:"h-6 px-2 text-xs",children:po[$].label},$))})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-1 max-w-[200px]",children:[e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:"行距"}),e.jsx(Na,{value:[F],onValueChange:([$])=>O($),min:0,max:12,step:2,className:"flex-1"}),e.jsxs("span",{className:"text-xs text-muted-foreground w-7",children:[F,"px"]})]}),e.jsxs("div",{className:"flex gap-2 sm:hidden",children:[e.jsxs(k,{variant:"outline",size:"sm",onClick:ce,className:"flex-1 h-8",children:[e.jsx(zt,{className:"h-3.5 w-3.5 mr-1"}),e.jsx("span",{className:"text-xs",children:"刷新"})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:be,className:"flex-1 h-8",children:[e.jsx(Yt,{className:"h-3.5 w-3.5 mr-1"}),e.jsx("span",{className:"text-xs",children:"导出"})]})]})]})]})]})})})]}),e.jsx("div",{className:"flex-1 min-h-0 px-2 sm:px-3 lg:px-4 pb-2 sm:pb-3 lg:pb-4",children:e.jsx(ze,{className:"bg-black dark:bg-gray-950 border-gray-800 dark:border-gray-900 h-full overflow-hidden",children:e.jsx("div",{ref:P,className:B("h-full overflow-auto","[&::-webkit-scrollbar]:w-2.5","[&::-webkit-scrollbar-track]:bg-transparent","[&::-webkit-scrollbar-thumb]:bg-border [&::-webkit-scrollbar-thumb]:rounded-full","[&::-webkit-scrollbar-thumb:hover]:bg-border/80"),children:e.jsx("div",{className:B("p-2 sm:p-3 font-mono relative",po[D].class),style:{height:`${Y.getTotalSize()}px`},children:je.length===0?e.jsx("div",{className:"text-gray-500 dark:text-gray-600 text-center py-8 text-xs sm:text-sm",children:"暂无日志数据"}):Y.getVirtualItems().map($=>{const _e=je[$.index];return e.jsxs("div",{"data-index":$.index,ref:Y.measureElement,className:B("absolute top-0 left-0 w-full px-2 sm:px-3 rounded hover:bg-white/5 transition-colors",G(_e.level)),style:{transform:`translateY(${$.start}px)`,paddingTop:`${F/2}px`,paddingBottom:`${F/2}px`},children:[e.jsxs("div",{className:"flex flex-col gap-0.5 sm:hidden",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-600 text-[10px]",children:_e.timestamp}),e.jsxs("span",{className:B("font-semibold text-[10px]",Z(_e.level)),children:["[",_e.level,"]"]})]}),e.jsx("div",{className:"text-cyan-400 dark:text-cyan-500 truncate text-[10px]",children:_e.module}),e.jsx("div",{className:"text-gray-300 dark:text-gray-400 whitespace-pre-wrap break-words text-[10px]",children:_e.message})]}),e.jsxs("div",{className:"hidden sm:flex gap-2 items-start",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-600 flex-shrink-0 w-[130px] lg:w-[160px]",children:_e.timestamp}),e.jsxs("span",{className:B("flex-shrink-0 w-[65px] lg:w-[75px] font-semibold",Z(_e.level)),children:["[",_e.level,"]"]}),e.jsx("span",{className:"text-cyan-400 dark:text-cyan-500 flex-shrink-0 w-[100px] lg:w-[130px] truncate",children:_e.module}),e.jsx("span",{className:"text-gray-300 dark:text-gray-400 flex-1 whitespace-pre-wrap break-words",children:_e.message})]})]},$.key)})})})})})]})}const O4="Mai-with-u",R4="plugin-repo",L4="main",U4="plugin_details.json";async function B4(){try{const l=await we("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:O4,repo:R4,branch:L4,file_path:U4})});if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const n=await l.json();if(!n.success||!n.data)throw new Error(n.error||"获取插件列表失败");return JSON.parse(n.data).filter(u=>!u?.id||!u?.manifest?(console.warn("跳过无效插件数据:",u),!1):!u.manifest.name||!u.manifest.version?(console.warn("跳过缺少必需字段的插件:",u.id),!1):!0).map(u=>({id:u.id,manifest:{manifest_version:u.manifest.manifest_version||1,name:u.manifest.name,version:u.manifest.version,description:u.manifest.description||"",author:u.manifest.author||{name:"Unknown"},license:u.manifest.license||"Unknown",host_application:u.manifest.host_application||{min_version:"0.0.0"},homepage_url:u.manifest.homepage_url,repository_url:u.manifest.repository_url,keywords:u.manifest.keywords||[],categories:u.manifest.categories||[],default_locale:u.manifest.default_locale||"zh-CN",locales_path:u.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!1,published_at:new Date().toISOString(),updated_at:new Date().toISOString()}))}catch(l){throw console.error("Failed to fetch plugin list:",l),l}}async function $4(){try{const l=await we("/api/webui/plugins/git-status");if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return await l.json()}catch(l){return console.error("Failed to check Git status:",l),{installed:!1,error:"无法检测 Git 安装状态"}}}async function H4(){try{const l=await we("/api/webui/plugins/version");if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return await l.json()}catch(l){return console.error("Failed to get Maimai version:",l),{version:"0.0.0",version_major:0,version_minor:0,version_patch:0}}}function I4(l,n,i){const c=l.split(".").map(f=>parseInt(f)||0),u=c[0]||0,x=c[1]||0,h=c[2]||0;if(i.version_majorparseInt(N)||0),p=f[0]||0,g=f[1]||0,v=f[2]||0;if(i.version_major>p||i.version_major===p&&i.version_minor>g||i.version_major===p&&i.version_minor===g&&i.version_patch>v)return!1}return!0}async function P4(){try{const l=await we("/api/webui/ws-token");if(!l.ok)return console.error("获取 WebSocket token 失败:",l.status),null;const n=await l.json();return n.success&&n.token?n.token:null}catch(l){return console.error("获取 WebSocket token 失败:",l),null}}async function G4(l,n){const i=await P4();if(!i)return console.warn("无法获取 WebSocket token,可能未登录"),null;const c=window.location.protocol==="https:"?"wss:":"ws:",u=window.location.host,x=`${c}//${u}/api/webui/ws/plugin-progress?token=${encodeURIComponent(i)}`;try{const h=new WebSocket(x);return h.onopen=()=>{console.log("Plugin progress WebSocket connected");const f=setInterval(()=>{h.readyState===WebSocket.OPEN?h.send("ping"):clearInterval(f)},3e4)},h.onmessage=f=>{try{if(f.data==="pong")return;const p=JSON.parse(f.data);l(p)}catch(p){console.error("Failed to parse progress data:",p)}},h.onerror=f=>{console.error("Plugin progress WebSocket error:",f),n?.(f)},h.onclose=()=>{console.log("Plugin progress WebSocket disconnected")},h}catch(h){return console.error("创建 WebSocket 连接失败:",h),null}}async function zi(){try{const l=await we("/api/webui/plugins/installed",{headers:Os()});if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const n=await l.json();if(!n.success)throw new Error(n.message||"获取已安装插件列表失败");return n.plugins||[]}catch(l){return console.error("Failed to get installed plugins:",l),[]}}function go(l,n){return n.some(i=>i.id===l)}function jo(l,n){const i=n.find(c=>c.id===l);if(i)return i.manifest?.version||i.version}async function q4(l,n,i="main"){const c=await we("/api/webui/plugins/install",{method:"POST",body:JSON.stringify({plugin_id:l,repository_url:n,branch:i})});if(!c.ok){const u=await c.json();throw new Error(u.detail||"安装失败")}return await c.json()}async function F4(l){const n=await we("/api/webui/plugins/uninstall",{method:"POST",body:JSON.stringify({plugin_id:l})});if(!n.ok){const i=await n.json();throw new Error(i.detail||"卸载失败")}return await n.json()}async function V4(l,n,i="main"){const c=await we("/api/webui/plugins/update",{method:"POST",body:JSON.stringify({plugin_id:l,repository_url:n,branch:i})});if(!c.ok){const u=await c.json();throw new Error(u.detail||"更新失败")}return await c.json()}async function K4(l){const n=await we(`/api/webui/plugins/config/${l}/schema`,{headers:Os()});if(!n.ok){const c=await n.text();try{const u=JSON.parse(c);throw new Error(u.detail||"获取配置 Schema 失败")}catch{throw new Error(`获取配置 Schema 失败 (${n.status})`)}}const i=await n.json();if(!i.success)throw new Error(i.message||"获取配置 Schema 失败");return i.schema}async function Q4(l){const n=await we(`/api/webui/plugins/config/${l}`,{headers:Os()});if(!n.ok){const c=await n.text();try{const u=JSON.parse(c);throw new Error(u.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${n.status})`)}}const i=await n.json();if(!i.success)throw new Error(i.message||"获取配置失败");return i.config}async function Y4(l){const n=await we(`/api/webui/plugins/config/${l}/raw`,{headers:Os()});if(!n.ok){const c=await n.text();try{const u=JSON.parse(c);throw new Error(u.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${n.status})`)}}const i=await n.json();if(!i.success)throw new Error(i.message||"获取配置失败");return i.config}async function J4(l,n){const i=await we(`/api/webui/plugins/config/${l}`,{method:"PUT",headers:Os(),body:JSON.stringify({config:n})});if(!i.ok){const c=await i.json();throw new Error(c.detail||"保存配置失败")}return await i.json()}async function X4(l,n){const i=await we(`/api/webui/plugins/config/${l}/raw`,{method:"PUT",headers:Os(),body:JSON.stringify({config:n})});if(!i.ok){const c=await i.json();throw new Error(c.detail||"保存配置失败")}return await i.json()}async function Z4(l){const n=await we(`/api/webui/plugins/config/${l}/reset`,{method:"POST",headers:Os()});if(!n.ok){const i=await n.json();throw new Error(i.detail||"重置配置失败")}return await n.json()}async function W4(l){const n=await we(`/api/webui/plugins/config/${l}/toggle`,{method:"POST",headers:Os()});if(!n.ok){const i=await n.json();throw new Error(i.detail||"切换状态失败")}return await n.json()}const Yi="https://maibot-plugin-stats.maibot-webui.workers.dev";async function fv(l){try{const n=await fetch(`${Yi}/stats/${l}`);return n.ok?await n.json():(console.error("Failed to fetch plugin stats:",n.statusText),null)}catch(n){return console.error("Error fetching plugin stats:",n),null}}async function eC(l,n){try{const i=n||Fm(),c=await fetch(`${Yi}/stats/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,user_id:i})}),u=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...u}:{success:!1,error:u.error||"点赞失败"}}catch(i){return console.error("Error liking plugin:",i),{success:!1,error:"网络错误"}}}async function sC(l,n){try{const i=n||Fm(),c=await fetch(`${Yi}/stats/dislike`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,user_id:i})}),u=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...u}:{success:!1,error:u.error||"点踩失败"}}catch(i){return console.error("Error disliking plugin:",i),{success:!1,error:"网络错误"}}}async function tC(l,n,i,c){if(n<1||n>5)return{success:!1,error:"评分必须在 1-5 之间"};try{const u=c||Fm(),x=await fetch(`${Yi}/stats/rate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,rating:n,comment:i,user_id:u})}),h=await x.json();return x.status===429?{success:!1,error:"每天最多评分 3 次"}:x.ok?{success:!0,...h}:{success:!1,error:h.error||"评分失败"}}catch(u){return console.error("Error rating plugin:",u),{success:!1,error:"网络错误"}}}async function aC(l){try{const n=await fetch(`${Yi}/stats/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l})}),i=await n.json();return n.status===429?(console.warn("Download recording rate limited"),{success:!0}):n.ok?{success:!0,...i}:(console.error("Failed to record download:",i.error),{success:!1,error:i.error})}catch(n){return console.error("Error recording download:",n),{success:!1,error:"网络错误"}}}function lC(){const l=navigator,n=[navigator.userAgent,navigator.language,navigator.languages?.join(",")||"",navigator.platform,navigator.hardwareConcurrency||0,screen.width,screen.height,screen.colorDepth,screen.pixelDepth,new Date().getTimezoneOffset(),Intl.DateTimeFormat().resolvedOptions().timeZone,navigator.maxTouchPoints||0,l.deviceMemory||0].join("|");let i=0;for(let c=0;c{x(!0);const T=await fv(l);T&&c(T),x(!1)};m.useEffect(()=>{w()},[l]);const b=async()=>{const T=await eC(l);T.success?(y({title:"已点赞",description:"感谢你的支持!"}),w()):y({title:"点赞失败",description:T.error||"未知错误",variant:"destructive"})},L=async()=>{const T=await sC(l);T.success?(y({title:"已反馈",description:"感谢你的反馈!"}),w()):y({title:"操作失败",description:T.error||"未知错误",variant:"destructive"})},D=async()=>{if(h===0){y({title:"请选择评分",description:"至少选择 1 颗星",variant:"destructive"});return}const T=await tC(l,h,p||void 0);T.success?(y({title:"评分成功",description:"感谢你的评价!"}),N(!1),f(0),g(""),w()):y({title:"评分失败",description:T.error||"未知错误",variant:"destructive"})};return u?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(vl,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]})]}):i?n?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",title:`下载量: ${i.downloads.toLocaleString()}`,children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx("span",{children:i.downloads.toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`评分: ${i.rating.toFixed(1)} (${i.rating_count} 条评价)`,children:[e.jsx(vl,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:i.rating.toFixed(1)})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`点赞数: ${i.likes}`,children:[e.jsx(rm,{className:"h-4 w-4"}),e.jsx("span",{children:i.likes})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Yt,{className:"h-5 w-5 text-muted-foreground mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.downloads.toLocaleString()}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"下载量"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(vl,{className:"h-5 w-5 text-yellow-400 mb-1 fill-yellow-400"}),e.jsx("span",{className:"text-2xl font-bold",children:i.rating.toFixed(1)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[i.rating_count," 条评价"]})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(rm,{className:"h-5 w-5 text-green-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.likes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点赞"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(qp,{className:"h-5 w-5 text-red-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.dislikes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点踩"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(k,{variant:"outline",size:"sm",onClick:b,children:[e.jsx(rm,{className:"h-4 w-4 mr-1"}),"点赞"]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:L,children:[e.jsx(qp,{className:"h-4 w-4 mr-1"}),"点踩"]}),e.jsxs(Is,{open:v,onOpenChange:N,children:[e.jsx(Bo,{asChild:!0,children:e.jsxs(k,{variant:"default",size:"sm",children:[e.jsx(vl,{className:"h-4 w-4 mr-1"}),"评分"]})}),e.jsxs(Rs,{children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"为插件评分"}),e.jsx(Zs,{children:"分享你的使用体验,帮助其他用户"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx("div",{className:"flex gap-2",children:[1,2,3,4,5].map(T=>e.jsx("button",{onClick:()=>f(T),className:"focus:outline-none",children:e.jsx(vl,{className:`h-8 w-8 transition-colors ${T<=h?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-yellow-300"}`})},T))}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h===0&&"点击星星进行评分",h===1&&"很差",h===2&&"一般",h===3&&"还行",h===4&&"不错",h===5&&"非常好"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"评论(可选)"}),e.jsx(Ys,{value:p,onChange:T=>g(T.target.value),placeholder:"分享你的使用体验...",rows:4,maxLength:500}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 text-right",children:[p.length," / 500"]})]})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>N(!1),children:"取消"}),e.jsx(k,{onClick:D,disabled:h===0,children:"提交评分"})]})]})]})]}),i.recent_ratings&&i.recent_ratings.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"最近评价"}),e.jsx("div",{className:"space-y-3",children:i.recent_ratings.map((T,F)=>e.jsxs("div",{className:"p-3 rounded-lg border bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"flex gap-1",children:[1,2,3,4,5].map(O=>e.jsx(vl,{className:`h-3 w-3 ${O<=T.rating?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},O))}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(T.created_at).toLocaleDateString()})]}),T.comment&&e.jsx("p",{className:"text-sm text-muted-foreground",children:T.comment})]},F))})]})]}):null}const pg={"Group Management":"群组管理","Entertainment & Interaction":"娱乐互动","Utility Tools":"实用工具","Content Generation":"内容生成",Multimedia:"多媒体","External Integration":"外部集成","Data Analysis & Insights":"数据分析与洞察",Other:"其他"};function rC(){return e.jsx(Dn,{children:e.jsx(iC,{})})}function iC(){const l=ua(),{triggerRestart:n,isRestarting:i}=sn(),[c,u]=m.useState(null),[x,h]=m.useState(""),[f,p]=m.useState("all"),[g,v]=m.useState("all"),[N,y]=m.useState(!0),[w,b]=m.useState([]),[L,D]=m.useState(!0),[T,F]=m.useState(null),[O,S]=m.useState(null),[C,P]=m.useState(null),[M,Z]=m.useState(null),[,G]=m.useState([]),[ce,de]=m.useState({}),[be,me]=m.useState(!1),[pe,je]=m.useState(null),[A,Y]=m.useState("main"),[H,U]=m.useState(""),[$,_e]=m.useState("preset"),[Ne,Se]=m.useState(!1),{toast:V}=et(),ye=async ae=>{const Ee=ae.map(async Me=>{try{const Ze=await fv(Me.id);return{id:Me.id,stats:Ze}}catch(Ze){return console.warn(`Failed to load stats for ${Me.id}:`,Ze),{id:Me.id,stats:null}}}),ie=await Promise.all(Ee),ve={};ie.forEach(({id:Me,stats:Ze})=>{Ze&&(ve[Me]=Ze)}),de(ve)};m.useEffect(()=>{let ae=null,Ee=!1;return(async()=>{if(ae=await G4(ve=>{Ee||(P(ve),ve.stage==="success"?setTimeout(()=>{Ee||P(null)},2e3):ve.stage==="error"&&(D(!1),F(ve.error||"加载失败")))},ve=>{console.error("WebSocket error:",ve),Ee||V({title:"WebSocket 连接失败",description:"无法实时显示加载进度",variant:"destructive"})}),await new Promise(ve=>{if(!ae){ve();return}const Me=()=>{ae&&ae.readyState===WebSocket.OPEN?(console.log("WebSocket connected, starting to load plugins"),ve()):ae&&ae.readyState===WebSocket.CLOSED?(console.warn("WebSocket closed before loading plugins"),ve()):setTimeout(Me,100)};Me()}),!Ee){const ve=await $4();S(ve),ve.installed||V({title:"Git 未安装",description:ve.error||"请先安装 Git 才能使用插件安装功能",variant:"destructive"})}if(!Ee){const ve=await H4();Z(ve)}if(!Ee)try{D(!0),F(null);const ve=await B4();if(!Ee){const Me=await zi();G(Me);const Ze=ve.map(js=>{const Ot=go(js.id,Me),rs=jo(js.id,Me);return{...js,installed:Ot,installed_version:rs}});for(const js of Me)!Ze.some(rs=>rs.id===js.id)&&js.manifest&&Ze.push({id:js.id,manifest:{manifest_version:js.manifest.manifest_version||1,name:js.manifest.name,version:js.manifest.version,description:js.manifest.description||"",author:js.manifest.author,license:js.manifest.license||"Unknown",host_application:js.manifest.host_application,homepage_url:js.manifest.homepage_url,repository_url:js.manifest.repository_url,keywords:js.manifest.keywords||[],categories:js.manifest.categories||[],default_locale:js.manifest.default_locale||"zh-CN",locales_path:js.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!0,installed_version:js.manifest.version,published_at:new Date().toISOString(),updated_at:new Date().toISOString()});b(Ze),ye(Ze)}}catch(ve){if(!Ee){const Me=ve instanceof Error?ve.message:"加载插件列表失败";F(Me),V({title:"加载失败",description:Me,variant:"destructive"})}}finally{Ee||D(!1)}})(),()=>{Ee=!0,ae&&ae.close()}},[V]);const W=ae=>{if(!ae.installed&&M&&!ue(ae))return e.jsxs(Te,{variant:"destructive",className:"gap-1",children:[e.jsx(Dt,{className:"h-3 w-3"}),"不兼容"]});if(ae.installed){const Ee=ae.installed_version?.trim(),ie=ae.manifest.version?.trim();if(Ee!==ie){const ve=Ee?.split(".").map(Number)||[0,0,0],Me=ie?.split(".").map(Number)||[0,0,0];for(let Ze=0;Ze<3;Ze++){if((Me[Ze]||0)>(ve[Ze]||0))return e.jsxs(Te,{variant:"outline",className:"gap-1 text-orange-600 border-orange-600",children:[e.jsx(Dt,{className:"h-3 w-3"}),"可更新"]});if((Me[Ze]||0)<(ve[Ze]||0))break}}return e.jsxs(Te,{variant:"default",className:"gap-1",children:[e.jsx(oa,{className:"h-3 w-3"}),"已安装"]})}return null},ue=ae=>!M||!ae.manifest?.host_application?!0:I4(ae.manifest.host_application.min_version,ae.manifest.host_application.max_version,M),ke=ae=>{if(!ae.installed||!ae.installed_version||!ae.manifest?.version)return!1;const Ee=ae.installed_version.trim(),ie=ae.manifest.version.trim();if(Ee===ie)return!1;const ve=Ee.split(".").map(Number),Me=ie.split(".").map(Number);for(let Ze=0;Ze<3;Ze++){if((Me[Ze]||0)>(ve[Ze]||0))return!0;if((Me[Ze]||0)<(ve[Ze]||0))return!1}return!1},J=w.filter(ae=>{if(!ae.manifest)return console.warn("[过滤] 跳过无 manifest 的插件:",ae.id),!1;const Ee=x===""||ae.manifest.name?.toLowerCase().includes(x.toLowerCase())||ae.manifest.description?.toLowerCase().includes(x.toLowerCase())||ae.manifest.keywords&&ae.manifest.keywords.some(Ze=>Ze.toLowerCase().includes(x.toLowerCase())),ie=f==="all"||ae.manifest.categories&&ae.manifest.categories.includes(f);let ve=!0;g==="installed"?ve=ae.installed===!0:g==="updates"&&(ve=ae.installed===!0&&ke(ae));const Me=!N||!M||ue(ae);return Ee&&ie&&ve&&Me}),ee=()=>{u(null)},De=ae=>{if(!O?.installed){V({title:"无法安装",description:"Git 未安装",variant:"destructive"});return}if(M&&!ue(ae)){V({title:"无法安装",description:"插件与当前麦麦版本不兼容",variant:"destructive"});return}je(ae),Y("main"),U(""),_e("preset"),Se(!1),me(!0)},Fe=async()=>{if(!pe)return;const ae=$==="custom"?H:A;if(!ae||ae.trim()===""){V({title:"分支名称不能为空",variant:"destructive"});return}try{me(!1),await q4(pe.id,pe.manifest.repository_url||"",ae),aC(pe.id).catch(ie=>{console.warn("Failed to record download:",ie)}),V({title:"安装成功",description:`${pe.manifest.name} 已成功安装`});const Ee=await zi();G(Ee),b(ie=>ie.map(ve=>{if(ve.id===pe.id){const Me=go(ve.id,Ee),Ze=jo(ve.id,Ee);return{...ve,installed:Me,installed_version:Ze}}return ve}))}catch(Ee){V({title:"安装失败",description:Ee instanceof Error?Ee.message:"未知错误",variant:"destructive"})}finally{je(null)}},ge=async ae=>{try{await F4(ae.id),V({title:"卸载成功",description:`${ae.manifest.name} 已成功卸载`});const Ee=await zi();G(Ee),b(ie=>ie.map(ve=>{if(ve.id===ae.id){const Me=go(ve.id,Ee),Ze=jo(ve.id,Ee);return{...ve,installed:Me,installed_version:Ze}}return ve}))}catch(Ee){V({title:"卸载失败",description:Ee instanceof Error?Ee.message:"未知错误",variant:"destructive"})}},as=async ae=>{if(!O?.installed){V({title:"无法更新",description:"Git 未安装",variant:"destructive"});return}try{const Ee=await V4(ae.id,ae.manifest.repository_url||"","main");V({title:"更新成功",description:`${ae.manifest.name} 已从 ${Ee.old_version} 更新到 ${Ee.new_version}`});const ie=await zi();G(ie),b(ve=>ve.map(Me=>{if(Me.id===ae.id){const Ze=go(Me.id,ie),js=jo(Me.id,ie);return{...Me,installed:Ze,installed_version:js}}return Me}))}catch(Ee){V({title:"更新失败",description:Ee instanceof Error?Ee.message:"未知错误",variant:"destructive"})}};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件市场"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"浏览和管理麦麦的插件"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(k,{variant:"outline",onClick:()=>n(),disabled:i,children:[e.jsx(Nj,{className:`h-4 w-4 mr-2 ${i?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(k,{onClick:()=>l({to:"/plugin-mirrors"}),children:[e.jsx($w,{className:"h-4 w-4 mr-2"}),"配置镜像源"]})]})]}),e.jsx(ze,{className:"border-blue-200 bg-blue-50 dark:bg-blue-950/20 dark:border-blue-900",children:e.jsx(Ye,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Jt,{className:"h-4 w-4 text-blue-600 flex-shrink-0"}),e.jsxs("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:["安装、卸载或更新插件后,需要",e.jsx("span",{className:"font-semibold",children:"重启麦麦"}),"才能使更改生效"]})]})})}),O&&!O.installed&&e.jsxs(ze,{className:"border-orange-600 bg-orange-50 dark:bg-orange-950/20",children:[e.jsx(ts,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Qt,{className:"h-5 w-5 text-orange-600"}),e.jsxs("div",{children:[e.jsx(ls,{className:"text-lg text-orange-900 dark:text-orange-100",children:"Git 未安装"}),e.jsx(Vs,{className:"text-orange-800 dark:text-orange-200",children:O.error||"请先安装 Git 才能使用插件安装功能"})]})]})}),e.jsx(Ye,{children:e.jsxs("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:["您可以从 ",e.jsx("a",{href:"https://git-scm.com/downloads",target:"_blank",rel:"noopener noreferrer",className:"underline font-medium",children:"git-scm.com"})," 下载并安装 Git。 安装完成后,请重启麦麦应用。"]})})]}),e.jsx(ze,{className:"p-4",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(Vt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(re,{placeholder:"搜索插件...",value:x,onChange:ae=>h(ae.target.value),className:"pl-9"})]}),e.jsxs(Le,{value:f,onValueChange:p,children:[e.jsx(Oe,{className:"w-full sm:w-[200px]",children:e.jsx(Ue,{placeholder:"选择分类"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部分类"}),e.jsx(le,{value:"Group Management",children:"群组管理"}),e.jsx(le,{value:"Entertainment & Interaction",children:"娱乐互动"}),e.jsx(le,{value:"Utility Tools",children:"实用工具"}),e.jsx(le,{value:"Content Generation",children:"内容生成"}),e.jsx(le,{value:"Multimedia",children:"多媒体"}),e.jsx(le,{value:"External Integration",children:"外部集成"}),e.jsx(le,{value:"Data Analysis & Insights",children:"数据分析与洞察"}),e.jsx(le,{value:"Other",children:"其他"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xs,{id:"compatible-only",checked:N,onCheckedChange:ae=>y(ae===!0)}),e.jsx("label",{htmlFor:"compatible-only",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer",children:"只显示兼容当前版本的插件"})]})]})}),e.jsx(da,{value:g,onValueChange:v,className:"w-full",children:e.jsxs(Zt,{className:"grid w-full grid-cols-3",children:[e.jsxs(Xe,{value:"all",children:["全部插件 (",w.filter(ae=>{if(!ae.manifest)return!1;const Ee=x===""||ae.manifest.name?.toLowerCase().includes(x.toLowerCase())||ae.manifest.description?.toLowerCase().includes(x.toLowerCase())||ae.manifest.keywords&&ae.manifest.keywords.some(Me=>Me.toLowerCase().includes(x.toLowerCase())),ie=f==="all"||ae.manifest.categories&&ae.manifest.categories.includes(f),ve=!N||!M||ue(ae);return Ee&&ie&&ve}).length,")"]}),e.jsxs(Xe,{value:"installed",children:["已安装 (",w.filter(ae=>{if(!ae.manifest)return!1;const Ee=x===""||ae.manifest.name?.toLowerCase().includes(x.toLowerCase())||ae.manifest.description?.toLowerCase().includes(x.toLowerCase())||ae.manifest.keywords&&ae.manifest.keywords.some(Me=>Me.toLowerCase().includes(x.toLowerCase())),ie=f==="all"||ae.manifest.categories&&ae.manifest.categories.includes(f),ve=!N||!M||ue(ae);return ae.installed&&Ee&&ie&&ve}).length,")"]}),e.jsxs(Xe,{value:"updates",children:["可更新 (",w.filter(ae=>{if(!ae.manifest)return!1;const Ee=x===""||ae.manifest.name?.toLowerCase().includes(x.toLowerCase())||ae.manifest.description?.toLowerCase().includes(x.toLowerCase())||ae.manifest.keywords&&ae.manifest.keywords.some(Me=>Me.toLowerCase().includes(x.toLowerCase())),ie=f==="all"||ae.manifest.categories&&ae.manifest.categories.includes(f),ve=!N||!M||ue(ae);return ae.installed&&ke(ae)&&Ee&&ie&&ve}).length,")"]})]})}),C&&C.stage==="loading"&&C.operation==="fetch"&&e.jsx(ze,{className:"p-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Js,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm font-medium",children:"加载插件列表"})]}),e.jsxs("span",{className:"text-sm font-medium",children:[C.progress,"%"]})]}),e.jsx(Mn,{value:C.progress,className:"h-2"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:C.message}),C.total_plugins>0&&e.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:["已加载 ",C.loaded_plugins," / ",C.total_plugins," 个插件"]})]})}),C&&C.stage==="error"&&C.error&&e.jsx(ze,{className:"border-destructive bg-destructive/10",children:e.jsx(ts,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Qt,{className:"h-5 w-5 text-destructive"}),e.jsxs("div",{children:[e.jsx(ls,{className:"text-lg text-destructive",children:"加载失败"}),e.jsx(Vs,{className:"text-destructive/80",children:C.error})]})]})})}),L?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(Js,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件列表中..."})]}):T?e.jsx(ze,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Qt,{className:"h-12 w-12 text-destructive mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"加载失败"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:T}),e.jsx(k,{onClick:()=>window.location.reload(),children:"重新加载"})]})}):J.length===0?e.jsx(ze,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Vt,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"未找到插件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:x||f!=="all"?"尝试调整搜索条件或筛选器":"暂无可用插件"})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:J.map(ae=>e.jsxs(ze,{className:"flex flex-col hover:shadow-lg transition-shadow h-full",children:[e.jsxs(ts,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx(ls,{className:"text-xl",children:ae.manifest?.name||ae.id}),e.jsxs("div",{className:"flex flex-col gap-1",children:[ae.manifest?.categories&&ae.manifest.categories[0]&&e.jsx(Te,{variant:"secondary",className:"text-xs whitespace-nowrap",children:pg[ae.manifest.categories[0]]||ae.manifest.categories[0]}),W(ae)]})]}),e.jsx(Vs,{className:"line-clamp-2",children:ae.manifest?.description||"无描述"})]}),e.jsx(Ye,{className:"flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Yt,{className:"h-4 w-4"}),e.jsx("span",{children:(ce[ae.id]?.downloads??ae.downloads??0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(vl,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:(ce[ae.id]?.rating??ae.rating??0).toFixed(1)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ae.manifest?.keywords&&ae.manifest.keywords.slice(0,3).map(Ee=>e.jsx(Te,{variant:"outline",className:"text-xs",children:Ee},Ee)),ae.manifest?.keywords&&ae.manifest.keywords.length>3&&e.jsxs(Te,{variant:"outline",className:"text-xs",children:["+",ae.manifest.keywords.length-3]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground pt-2 border-t space-y-1",children:[e.jsxs("div",{children:["v",ae.manifest?.version||"unknown"," · ",ae.manifest?.author?.name||"Unknown"]}),ae.manifest?.host_application&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:"支持:"}),e.jsxs("span",{className:"font-medium",children:[ae.manifest.host_application.min_version,ae.manifest.host_application.max_version?` - ${ae.manifest.host_application.max_version}`:" - 最新版本"]})]})]})]})}),e.jsx(Lo,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center justify-end gap-2 w-full",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>u(ae),children:"查看详情"}),ae.installed?ke(ae)?e.jsxs(k,{size:"sm",disabled:!O?.installed,title:O?.installed?void 0:"Git 未安装",onClick:()=>as(ae),children:[e.jsx(zt,{className:"h-4 w-4 mr-1"}),"更新"]}):e.jsxs(k,{variant:"destructive",size:"sm",disabled:!O?.installed,title:O?.installed?void 0:"Git 未安装",onClick:()=>ge(ae),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"卸载"]}):e.jsxs(k,{size:"sm",disabled:!O?.installed||C?.operation==="install"||M!==null&&!ue(ae),title:O?.installed?M!==null&&!ue(ae)?`不兼容当前版本 (需要 ${ae.manifest?.host_application?.min_version||"未知"}${ae.manifest?.host_application?.max_version?` - ${ae.manifest.host_application.max_version}`:"+"},当前 ${M?.version})`:void 0:"Git 未安装",onClick:()=>De(ae),children:[e.jsx(Yt,{className:"h-4 w-4 mr-1"}),C?.operation==="install"&&C?.plugin_id===ae.id?"安装中...":"安装"]})]})}),C&&(C.stage==="loading"||C.stage==="success"||C.stage==="error")&&C.operation!=="fetch"&&C.plugin_id===ae.id&&e.jsx("div",{className:"px-6 pb-4 -mt-2",children:e.jsxs("div",{className:`space-y-2 p-3 rounded-lg border ${C.stage==="success"?"bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-900":C.stage==="error"?"bg-red-50 dark:bg-red-950/20 border-red-200 dark:border-red-900":"bg-muted/50"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[C.stage==="loading"?e.jsx(Js,{className:"h-3 w-3 animate-spin"}):C.stage==="success"?e.jsx(oa,{className:"h-3 w-3 text-green-600"}):e.jsx(Dt,{className:"h-3 w-3 text-red-600"}),e.jsx("span",{className:`text-xs font-medium ${C.stage==="success"?"text-green-700 dark:text-green-300":C.stage==="error"?"text-red-700 dark:text-red-300":""}`,children:C.stage==="loading"?e.jsxs(e.Fragment,{children:[C.operation==="install"&&"正在安装",C.operation==="uninstall"&&"正在卸载",C.operation==="update"&&"正在更新"]}):C.stage==="success"?e.jsxs(e.Fragment,{children:[C.operation==="install"&&"安装完成",C.operation==="uninstall"&&"卸载完成",C.operation==="update"&&"更新完成"]}):e.jsxs(e.Fragment,{children:[C.operation==="install"&&"安装失败",C.operation==="uninstall"&&"卸载失败",C.operation==="update"&&"更新失败"]})})]}),C.stage!=="error"&&e.jsxs("span",{className:`text-xs font-medium ${C.stage==="success"?"text-green-700 dark:text-green-300":""}`,children:[C.progress,"%"]})]}),C.stage!=="error"&&e.jsx(Mn,{value:C.progress,className:`h-1.5 ${C.stage==="success"?"[&>div]:bg-green-500":""}`}),e.jsx("div",{className:`text-xs ${C.stage==="success"?"text-green-600 dark:text-green-400 truncate":C.stage==="error"?"text-red-600 dark:text-red-400":"text-muted-foreground truncate"}`,children:C.stage==="error"?C.error||C.message||"操作失败":C.message})]})})]},ae.id))}),e.jsx(Is,{open:c!==null,onOpenChange:ee,children:c&&c.manifest&&e.jsx(Rs,{className:"max-w-2xl max-h-[80vh] p-0 flex flex-col",children:e.jsx(Je,{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-6",children:[e.jsx(Ls,{children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx(Us,{className:"text-2xl",children:c.manifest.name}),e.jsxs(Zs,{children:["作者: ",c.manifest.author?.name||"Unknown",c.manifest.author?.url&&e.jsx("a",{href:c.manifest.author.url,target:"_blank",rel:"noopener noreferrer",className:"ml-2 text-primary hover:underline",children:e.jsx(vo,{className:"h-3 w-3 inline"})})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[c.manifest.categories&&c.manifest.categories[0]&&e.jsx(Te,{variant:"secondary",children:pg[c.manifest.categories[0]]||c.manifest.categories[0]}),W(c)]})]})}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(nC,{pluginId:c.id}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"版本"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["v",c.manifest?.version||"unknown"]}),c.installed&&c.installed_version&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["已安装: v",c.installed_version]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"下载量"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:(ce[c.id]?.downloads??c.downloads??0).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"评分"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(vl,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(ce[c.id]?.rating??c.rating??0).toFixed(1)," (",ce[c.id]?.rating_count??c.review_count??0,")"]})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"许可证"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c.manifest.license||"Unknown"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"支持版本"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[c.manifest.host_application?.min_version||"未知",c.manifest.host_application?.max_version?` - ${c.manifest.host_application.max_version}`:" - 最新版本"]})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"关键词"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:c.manifest.keywords&&c.manifest.keywords.map(ae=>e.jsx(Te,{variant:"outline",children:ae},ae))})]}),c.detailed_description&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"详细说明"}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-line",children:c.detailed_description})]}),!c.detailed_description&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"说明"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c.manifest.description||"无描述"})]}),e.jsxs("div",{className:"space-y-2",children:[c.manifest.homepage_url&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"主页: "}),e.jsx("a",{href:c.manifest.homepage_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:c.manifest.homepage_url})]}),c.manifest.repository_url&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"仓库: "}),e.jsx("a",{href:c.manifest.repository_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:c.manifest.repository_url})]})]})]}),e.jsxs(rt,{children:[c.manifest.homepage_url&&e.jsxs(k,{onClick:()=>window.open(c.manifest.homepage_url,"_blank"),children:[e.jsx(vo,{className:"h-4 w-4 mr-2"}),"访问主页"]}),c.manifest.repository_url&&e.jsxs(k,{variant:"outline",onClick:()=>window.open(c.manifest.repository_url,"_blank"),children:[e.jsx(vo,{className:"h-4 w-4 mr-2"}),"查看仓库"]})]})]})})})}),e.jsx(Is,{open:be,onOpenChange:me,children:e.jsxs(Rs,{children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"安装插件"}),e.jsxs(Zs,{children:["安装 ",pe?.manifest.name]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["版本: ",pe?.manifest.version]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["作者: ",typeof pe?.manifest.author=="string"?pe.manifest.author:pe?.manifest.author?.name]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xs,{id:"advanced-options",checked:Ne,onCheckedChange:ae=>Se(ae)}),e.jsx("label",{htmlFor:"advanced-options",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"高级选项"})]}),Ne&&e.jsx("div",{className:"space-y-4 p-4 border rounded-lg",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"分支选择"}),e.jsxs(da,{value:$,onValueChange:ae=>_e(ae),children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2",children:[e.jsx(Xe,{value:"preset",className:"text-xs",children:"预设分支"}),e.jsx(Xe,{value:"custom",className:"text-xs",children:"自定义分支"})]}),$==="preset"&&e.jsx("div",{className:"mt-3",children:e.jsxs(Le,{value:A,onValueChange:Y,children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:"选择分支"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"main",children:"main (默认)"}),e.jsx(le,{value:"master",children:"master"}),e.jsx(le,{value:"dev",children:"dev (开发版)"}),e.jsx(le,{value:"develop",children:"develop"}),e.jsx(le,{value:"beta",children:"beta (测试版)"}),e.jsx(le,{value:"stable",children:"stable (稳定版)"})]})]})}),$==="custom"&&e.jsxs("div",{className:"space-y-2 mt-3",children:[e.jsx("input",{type:"text",className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",placeholder:"输入分支名称,例如: feature/new-feature",value:H,onChange:ae=>U(ae.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"输入 Git 分支名称、标签或提交哈希"})]})]})]})}),!Ne&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"将从默认分支 (main) 安装插件"})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>me(!1),children:"取消"}),e.jsxs(k,{onClick:Fe,children:[e.jsx(Yt,{className:"h-4 w-4 mr-2"}),"安装"]})]})]})}),e.jsx(On,{})]})})}function cC(){return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsx("div",{className:"mb-4 sm:mb-6",children:e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(bj,{className:"h-8 w-8",strokeWidth:2}),"模型分配预设市场"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"浏览和下载社区共享的模型分配预设配置"})]})})}),e.jsx(Je,{className:"flex-1",children:e.jsx("div",{className:"flex items-center justify-center h-[calc(100vh-12rem)]",children:e.jsxs(ze,{className:"max-w-2xl w-full border-dashed",children:[e.jsxs(ts,{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(ca,{className:"h-16 w-16 text-muted-foreground"})}),e.jsx(ls,{className:"text-2xl",children:"功能开发中"}),e.jsx(Vs,{className:"text-base",children:"模型分配预设市场功能正在开发中,敬请期待!"})]}),e.jsx(Ye,{children:e.jsxs("div",{className:"space-y-3 text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-foreground",children:"📦 即将推出的功能:"}),e.jsxs("ul",{className:"space-y-2 ml-6",children:[e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"浏览社区共享的模型分配预设配置"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"一键下载和应用预设配置"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"分享自己的模型分配方案"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"预设配置评分和评论系统"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"根据使用场景智能推荐配置"})]})]})]})})]})})})]})}function oC({field:l,value:n,onChange:i}){const[c,u]=m.useState(!1);switch(l.ui_type){case"switch":return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(E,{children:l.label}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]}),e.jsx(Pe,{checked:!!n,onCheckedChange:i,disabled:l.disabled})]});case"number":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:l.label}),e.jsx(re,{type:"number",value:n??l.default,onChange:x=>i(parseFloat(x.target.value)||0),min:l.min,max:l.max,step:l.step??1,placeholder:l.placeholder,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"slider":return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{children:l.label}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n??l.default})]}),e.jsx(Na,{value:[n??l.default],onValueChange:x=>i(x[0]),min:l.min??0,max:l.max??100,step:l.step??1,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"select":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:l.label}),e.jsxs(Le,{value:String(n??l.default),onValueChange:i,disabled:l.disabled,children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:l.placeholder??"请选择"})}),e.jsx(Re,{children:l.choices?.map(x=>e.jsx(le,{value:String(x),children:String(x)},String(x)))})]}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"textarea":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:l.label}),e.jsx(Ys,{value:n??l.default,onChange:x=>i(x.target.value),placeholder:l.placeholder,rows:l.rows??3,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"password":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:l.label}),e.jsxs("div",{className:"relative",children:[e.jsx(re,{type:c?"text":"password",value:n??"",onChange:x=>i(x.target.value),placeholder:l.placeholder,disabled:l.disabled,className:"pr-10"}),e.jsx(k,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3",onClick:()=>u(!c),children:c?e.jsx(Bi,{className:"h-4 w-4"}):e.jsx(Xt,{className:"h-4 w-4"})})]}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"list":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:l.label}),e.jsx(i_,{value:Array.isArray(n)?n:[],onChange:x=>i(x),itemType:l.item_type??"string",itemFields:l.item_fields,minItems:l.min_items,maxItems:l.max_items,disabled:l.disabled,placeholder:l.placeholder}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"text":default:return e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:l.label}),e.jsx(re,{type:"text",value:n??l.default??"",onChange:x=>i(x.target.value),placeholder:l.placeholder,maxLength:l.max_length,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]})}}function gg({section:l,config:n,onChange:i}){const[c,u]=m.useState(!l.collapsed),x=Object.entries(l.fields).filter(([,h])=>!h.hidden).sort(([,h],[,f])=>h.order-f.order);return e.jsx(Gi,{open:c,onOpenChange:u,children:e.jsxs(ze,{children:[e.jsx(qi,{asChild:!0,children:e.jsxs(ts,{className:"cursor-pointer hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c?e.jsx(Oa,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(ba,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(ls,{className:"text-lg",children:l.title})]}),e.jsxs(Te,{variant:"secondary",className:"text-xs",children:[x.length," 项"]})]}),l.description&&e.jsx(Vs,{className:"ml-6",children:l.description})]})}),e.jsx(Fi,{children:e.jsx(Ye,{className:"space-y-4 pt-0",children:x.map(([h,f])=>e.jsx(oC,{field:f,value:n[l.name]?.[h],onChange:p=>i(l.name,h,p),sectionName:l.name},h))})})]})})}function dC({plugin:l,onBack:n}){const{toast:i}=et(),{triggerRestart:c,isRestarting:u}=sn(),[x,h]=m.useState("visual"),[f,p]=m.useState(null),[g,v]=m.useState({}),[N,y]=m.useState({}),[w,b]=m.useState(""),[L,D]=m.useState(""),[T,F]=m.useState(!0),[O,S]=m.useState(!1),[C,P]=m.useState(!1),[M,Z]=m.useState(!1),[G,ce]=m.useState(!1),de=m.useCallback(async()=>{F(!0);try{const[H,U,$]=await Promise.all([K4(l.id),Q4(l.id),Y4(l.id)]);p(H),v(U),y(JSON.parse(JSON.stringify(U))),b($),D($)}catch(H){i({title:"加载配置失败",description:H instanceof Error?H.message:"未知错误",variant:"destructive"})}finally{F(!1)}},[l.id,i]);m.useEffect(()=>{de()},[de]),m.useEffect(()=>{P(x==="visual"?JSON.stringify(g)!==JSON.stringify(N):w!==L)},[g,N,w,L,x]);const be=(H,U,$)=>{v(_e=>({..._e,[H]:{..._e[H]||{},[U]:$}}))},me=async()=>{S(!0);try{if(x==="source"){try{ov(w)}catch(H){Z(!0),i({title:"TOML 格式错误",description:H instanceof Error?H.message:"无法解析 TOML 配置,请检查语法",variant:"destructive"}),S(!1);return}await X4(l.id,w),D(w),Z(!1)}else await J4(l.id,g),y(JSON.parse(JSON.stringify(g)));i({title:"配置已保存",description:"更改将在插件重新加载后生效"})}catch(H){i({title:"保存失败",description:H instanceof Error?H.message:"未知错误",variant:"destructive"})}finally{S(!1)}},pe=async()=>{try{await Z4(l.id),i({title:"配置已重置",description:"下次加载插件时将使用默认配置"}),ce(!1),de()}catch(H){i({title:"重置失败",description:H instanceof Error?H.message:"未知错误",variant:"destructive"})}},je=async()=>{try{const H=await W4(l.id);i({title:H.message,description:H.note}),de()}catch(H){i({title:"切换状态失败",description:H instanceof Error?H.message:"未知错误",variant:"destructive"})}};if(T)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(Js,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!f)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 space-y-4",children:[e.jsx(Dt,{className:"h-12 w-12 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"无法加载配置"}),e.jsxs(k,{onClick:n,variant:"outline",children:[e.jsx(en,{className:"h-4 w-4 mr-2"}),"返回"]})]});const A=Object.values(f.sections).sort((H,U)=>H.order-U.order),Y=g.plugin?.enabled!==!1;return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(k,{variant:"ghost",size:"icon",onClick:n,children:e.jsx(en,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:f.plugin_info.name||l.manifest.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(Te,{variant:Y?"default":"secondary",children:Y?"已启用":"已禁用"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["v",f.plugin_info.version||l.manifest.version]})]})]})]}),e.jsxs("div",{className:"flex gap-2 ml-10 sm:ml-0",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>h(x==="visual"?"source":"visual"),children:x==="visual"?e.jsxs(e.Fragment,{children:[e.jsx(pj,{className:"h-4 w-4 mr-2"}),"源代码"]}):e.jsxs(e.Fragment,{children:[e.jsx(fj,{className:"h-4 w-4 mr-2"}),"可视化"]})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>c(),disabled:u,children:[e.jsx(Nj,{className:`h-4 w-4 mr-2 ${u?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:je,children:[e.jsx(Vi,{className:"h-4 w-4 mr-2"}),Y?"禁用":"启用"]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>ce(!0),children:[e.jsx(Ui,{className:"h-4 w-4 mr-2"}),"重置"]}),e.jsxs(k,{size:"sm",onClick:me,disabled:!C||O,children:[O?e.jsx(Js,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ki,{className:"h-4 w-4 mr-2"}),"保存"]})]})]}),C&&e.jsx(ze,{className:"border-orange-200 bg-orange-50 dark:bg-orange-950/20 dark:border-orange-900",children:e.jsx(Ye,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Jt,{className:"h-4 w-4 text-orange-600"}),e.jsx("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:"有未保存的更改"})]})})}),x==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(gt,{children:[e.jsx(Dt,{className:"h-4 w-4"}),e.jsxs(jt,{children:[e.jsx("strong",{children:"源代码模式(高级功能):"}),"直接编辑 TOML 配置文件。保存时会验证格式,只有格式正确才能保存。",M&&e.jsx("span",{className:"text-destructive font-semibold ml-2",children:"⚠️ 上次保存失败,请检查 TOML 格式"})]})]}),e.jsx(Xj,{value:w,onChange:H=>{b(H),M&&Z(!1)},language:"toml",theme:"dark",height:"calc(100vh - 350px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),x==="visual"&&e.jsx(e.Fragment,{children:f.layout.type==="tabs"&&f.layout.tabs.length>0?e.jsxs(da,{defaultValue:f.layout.tabs[0]?.id,children:[e.jsx(Zt,{children:f.layout.tabs.map(H=>e.jsxs(Xe,{value:H.id,children:[H.title,H.badge&&e.jsx(Te,{variant:"secondary",className:"ml-2 text-xs",children:H.badge})]},H.id))}),f.layout.tabs.map(H=>e.jsx(ys,{value:H.id,className:"space-y-4 mt-4",children:H.sections.map(U=>{const $=f.sections[U];return $?e.jsx(gg,{section:$,config:g,onChange:be},U):null})},H.id))]}):e.jsx("div",{className:"space-y-4",children:A.map(H=>e.jsx(gg,{section:H,config:g,onChange:be},H.name))})}),e.jsx(Is,{open:G,onOpenChange:ce,children:e.jsxs(Rs,{children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"确认重置配置"}),e.jsx(Zs,{children:"这将删除当前配置文件,下次加载插件时将使用默认配置。此操作不可撤销。"})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>ce(!1),children:"取消"}),e.jsx(k,{variant:"destructive",onClick:pe,children:"确认重置"})]})]})})]})}function uC(){return e.jsx(Dn,{children:e.jsx(mC,{})})}function mC(){const{toast:l}=et(),[n,i]=m.useState([]),[c,u]=m.useState(!0),[x,h]=m.useState(""),[f,p]=m.useState(null),g=async()=>{u(!0);try{const b=await zi();i(b)}catch(b){l({title:"加载插件列表失败",description:b instanceof Error?b.message:"未知错误",variant:"destructive"})}finally{u(!1)}};m.useEffect(()=>{g()},[]);const N=n.filter(b=>{const L=x.toLowerCase();return b.id.toLowerCase().includes(L)||b.manifest.name.toLowerCase().includes(L)||b.manifest.description?.toLowerCase().includes(L)}).filter((b,L,D)=>L===D.findIndex(T=>T.id===b.id)),y=n.length,w=0;return f?e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"h-full",children:e.jsx("div",{className:"p-4 sm:p-6",children:e.jsx(dC,{plugin:f,onBack:()=>p(null)})})}),e.jsx(On,{})]}):e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理和配置已安装的插件"})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:g,children:[e.jsx(zt,{className:`h-4 w-4 mr-2 ${c?"animate-spin":""}`}),"刷新"]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 xs:grid-cols-2 lg:grid-cols-3",children:[e.jsxs(ze,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ls,{className:"text-sm font-medium",children:"已安装插件"}),e.jsx(ca,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Ye,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n.length}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:c?"正在加载...":"个插件"})]})]}),e.jsxs(ze,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ls,{className:"text-sm font-medium",children:"已启用"}),e.jsx(oa,{className:"h-4 w-4 text-green-600"})]}),e.jsxs(Ye,{children:[e.jsx("div",{className:"text-2xl font-bold",children:y}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"运行中的插件"})]})]}),e.jsxs(ze,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ls,{className:"text-sm font-medium",children:"已禁用"}),e.jsx(Dt,{className:"h-4 w-4 text-orange-600"})]}),e.jsxs(Ye,{children:[e.jsx("div",{className:"text-2xl font-bold",children:w}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"未激活的插件"})]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Vt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(re,{placeholder:"搜索插件...",value:x,onChange:b=>h(b.target.value),className:"pl-9"})]}),e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"已安装的插件"}),e.jsx(Vs,{children:"点击插件查看和编辑配置"})]}),e.jsx(Ye,{children:c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Js,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):N.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 space-y-4",children:[e.jsx(ca,{className:"h-16 w-16 text-muted-foreground/50"}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("p",{className:"text-lg font-medium text-muted-foreground",children:x?"没有找到匹配的插件":"暂无已安装的插件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:x?"尝试其他搜索关键词":"前往插件市场安装插件"})]})]}):e.jsx("div",{className:"space-y-2",children:N.map(b=>e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg border hover:bg-muted/50 cursor-pointer transition-colors",onClick:()=>p(b),children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"h-10 w-10 rounded-lg bg-primary/10 flex items-center justify-center flex-shrink-0",children:e.jsx(ca,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-medium truncate",children:b.manifest.name}),e.jsxs(Te,{variant:"secondary",className:"text-xs flex-shrink-0",children:["v",b.manifest.version]})]}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:b.manifest.description||"暂无描述"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(k,{variant:"ghost",size:"sm",children:e.jsx(zn,{className:"h-4 w-4"})}),e.jsx(ba,{className:"h-4 w-4 text-muted-foreground"})]})]},b.id))})})]})]})})}function xC(){const l=ua(),{toast:n}=et(),[i,c]=m.useState([]),[u,x]=m.useState(!0),[h,f]=m.useState(null),[p,g]=m.useState(null),[v,N]=m.useState(!1),[y,w]=m.useState(!1),[b,L]=m.useState({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),D=m.useCallback(async()=>{try{x(!0),f(null);const M=await we("/api/webui/plugins/mirrors");if(!M.ok)throw new Error("获取镜像源列表失败");const Z=await M.json();c(Z.mirrors||[])}catch(M){const Z=M instanceof Error?M.message:"加载镜像源失败";f(Z),n({title:"加载失败",description:Z,variant:"destructive"})}finally{x(!1)}},[n]);m.useEffect(()=>{D()},[D]);const T=async()=>{try{const M=await we("/api/webui/plugins/mirrors",{method:"POST",body:JSON.stringify(b)});if(!M.ok){const Z=await M.json();throw new Error(Z.detail||"添加镜像源失败")}n({title:"添加成功",description:"镜像源已添加"}),N(!1),L({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),D()}catch(M){n({title:"添加失败",description:M instanceof Error?M.message:"未知错误",variant:"destructive"})}},F=async()=>{if(p)try{if(!(await we(`/api/webui/plugins/mirrors/${p.id}`,{method:"PUT",body:JSON.stringify({name:b.name,raw_prefix:b.raw_prefix,clone_prefix:b.clone_prefix,enabled:b.enabled,priority:b.priority})})).ok)throw new Error("更新镜像源失败");n({title:"更新成功",description:"镜像源已更新"}),w(!1),g(null),D()}catch(M){n({title:"更新失败",description:M instanceof Error?M.message:"未知错误",variant:"destructive"})}},O=async M=>{if(confirm("确定要删除这个镜像源吗?"))try{if(!(await we(`/api/webui/plugins/mirrors/${M}`,{method:"DELETE"})).ok)throw new Error("删除镜像源失败");n({title:"删除成功",description:"镜像源已删除"}),D()}catch(Z){n({title:"删除失败",description:Z instanceof Error?Z.message:"未知错误",variant:"destructive"})}},S=async M=>{try{if(!(await we(`/api/webui/plugins/mirrors/${M.id}`,{method:"PUT",body:JSON.stringify({enabled:!M.enabled})})).ok)throw new Error("更新状态失败");D()}catch(Z){n({title:"更新失败",description:Z instanceof Error?Z.message:"未知错误",variant:"destructive"})}},C=M=>{g(M),L({id:M.id,name:M.name,raw_prefix:M.raw_prefix,clone_prefix:M.clone_prefix,enabled:M.enabled,priority:M.priority}),w(!0)},P=async(M,Z)=>{const G=Z==="up"?M.priority-1:M.priority+1;if(!(G<1))try{if(!(await we(`/api/webui/plugins/mirrors/${M.id}`,{method:"PUT",body:JSON.stringify({priority:G})})).ok)throw new Error("更新优先级失败");D()}catch(ce){n({title:"更新失败",description:ce instanceof Error?ce.message:"未知错误",variant:"destructive"})}};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(k,{variant:"ghost",size:"icon",onClick:()=>l({to:"/plugins"}),children:e.jsx(en,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"镜像源配置"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"管理 Git 克隆和文件下载的镜像源"})]})]}),e.jsxs(k,{onClick:()=>N(!0),children:[e.jsx(lt,{className:"h-4 w-4 mr-2"}),"添加镜像源"]})]}),u?e.jsx(ze,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Js,{className:"h-8 w-8 animate-spin text-primary"})})}):h?e.jsx(ze,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Qt,{className:"h-12 w-12 text-destructive mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"加载失败"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:h}),e.jsx(k,{onClick:D,children:"重新加载"})]})}):e.jsxs(ze,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(wl,{children:[e.jsx(_l,{children:e.jsxs(nt,{children:[e.jsx(Qe,{children:"状态"}),e.jsx(Qe,{children:"名称"}),e.jsx(Qe,{children:"ID"}),e.jsx(Qe,{children:"优先级"}),e.jsx(Qe,{className:"text-right",children:"操作"})]})}),e.jsx(Sl,{children:i.map(M=>e.jsxs(nt,{children:[e.jsx(Ie,{children:e.jsx(Pe,{checked:M.enabled,onCheckedChange:()=>S(M)})}),e.jsx(Ie,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:M.name}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Raw: ",M.raw_prefix]})]})}),e.jsx(Ie,{children:e.jsx(Te,{variant:"outline",children:M.id})}),e.jsx(Ie,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono",children:M.priority}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(k,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>P(M,"up"),disabled:M.priority===1,children:e.jsx(Tr,{className:"h-3 w-3"})}),e.jsx(k,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>P(M,"down"),children:e.jsx(Oa,{className:"h-3 w-3"})})]})]})}),e.jsx(Ie,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(k,{variant:"ghost",size:"icon",onClick:()=>C(M),children:e.jsx(Cn,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon",onClick:()=>O(M.id),children:e.jsx(ns,{className:"h-4 w-4 text-destructive"})})]})})]},M.id))})]})}),e.jsx("div",{className:"md:hidden p-4 space-y-4",children:i.map(M=>e.jsx(ze,{className:"p-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold",children:M.name}),M.enabled&&e.jsx(Te,{variant:"default",className:"text-xs",children:"启用"})]}),e.jsx(Te,{variant:"outline",className:"mt-1 text-xs",children:M.id})]}),e.jsx(Pe,{checked:M.enabled,onCheckedChange:()=>S(M)})]}),e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"Raw: "}),e.jsx("span",{className:"break-all",children:M.raw_prefix})]}),e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"优先级: "}),e.jsx("span",{className:"font-mono",children:M.priority})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t",children:[e.jsxs(k,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>C(M),children:[e.jsx(Cn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>P(M,"up"),disabled:M.priority===1,children:e.jsx(Tr,{className:"h-4 w-4"})}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>P(M,"down"),children:e.jsx(Oa,{className:"h-4 w-4"})}),e.jsx(k,{variant:"destructive",size:"sm",onClick:()=>O(M.id),children:e.jsx(ns,{className:"h-4 w-4"})})]})]})},M.id))})]}),e.jsx(Is,{open:v,onOpenChange:N,children:e.jsxs(Rs,{className:"max-w-lg",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"添加镜像源"}),e.jsx(Zs,{children:"添加新的 Git 镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"add-id",children:"镜像源 ID *"}),e.jsx(re,{id:"add-id",placeholder:"例如: my-mirror",value:b.id,onChange:M=>L({...b,id:M.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"add-name",children:"名称 *"}),e.jsx(re,{id:"add-name",placeholder:"例如: 我的镜像源",value:b.name,onChange:M=>L({...b,name:M.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"add-raw",children:"Raw 文件前缀 *"}),e.jsx(re,{id:"add-raw",placeholder:"https://example.com/raw",value:b.raw_prefix,onChange:M=>L({...b,raw_prefix:M.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"add-clone",children:"克隆前缀 *"}),e.jsx(re,{id:"add-clone",placeholder:"https://example.com/clone",value:b.clone_prefix,onChange:M=>L({...b,clone_prefix:M.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"add-priority",children:"优先级"}),e.jsx(re,{id:"add-priority",type:"number",min:"1",value:b.priority,onChange:M=>L({...b,priority:parseInt(M.target.value)||1})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"数字越小优先级越高"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"add-enabled",checked:b.enabled,onCheckedChange:M=>L({...b,enabled:M})}),e.jsx(E,{htmlFor:"add-enabled",children:"启用此镜像源"})]})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>N(!1),children:"取消"}),e.jsx(k,{onClick:T,children:"添加"})]})]})}),e.jsx(Is,{open:y,onOpenChange:w,children:e.jsxs(Rs,{className:"max-w-lg",children:[e.jsxs(Ls,{children:[e.jsx(Us,{children:"编辑镜像源"}),e.jsx(Zs,{children:"修改镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:"镜像源 ID"}),e.jsx(re,{value:b.id,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"edit-name",children:"名称 *"}),e.jsx(re,{id:"edit-name",value:b.name,onChange:M=>L({...b,name:M.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"edit-raw",children:"Raw 文件前缀 *"}),e.jsx(re,{id:"edit-raw",value:b.raw_prefix,onChange:M=>L({...b,raw_prefix:M.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"edit-clone",children:"克隆前缀 *"}),e.jsx(re,{id:"edit-clone",value:b.clone_prefix,onChange:M=>L({...b,clone_prefix:M.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"edit-priority",children:"优先级"}),e.jsx(re,{id:"edit-priority",type:"number",min:"1",value:b.priority,onChange:M=>L({...b,priority:parseInt(M.target.value)||1})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"数字越小优先级越高"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Pe,{id:"edit-enabled",checked:b.enabled,onCheckedChange:M=>L({...b,enabled:M})}),e.jsx(E,{htmlFor:"edit-enabled",children:"启用此镜像源"})]})]}),e.jsxs(rt,{children:[e.jsx(k,{variant:"outline",onClick:()=>w(!1),children:"取消"}),e.jsx(k,{onClick:F,children:"保存"})]})]})})]})})}const Di=m.forwardRef(({className:l,...n},i)=>e.jsx(Ug,{ref:i,className:B("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",l),...n}));Di.displayName=Ug.displayName;const hC=m.forwardRef(({className:l,...n},i)=>e.jsx(Bg,{ref:i,className:B("aspect-square h-full w-full",l),...n}));hC.displayName=Bg.displayName;const Oi=m.forwardRef(({className:l,...n},i)=>e.jsx($g,{ref:i,className:B("flex h-full w-full items-center justify-center rounded-full bg-muted",l),...n}));Oi.displayName=$g.displayName;function fC(){return"webui_"+Math.random().toString(36).substr(2,9)+"_"+Date.now().toString(36)}function pC(){const l="maibot_webui_user_id";let n=localStorage.getItem(l);return n||(n=fC(),localStorage.setItem(l,n)),n}function gC(){return localStorage.getItem("maibot_webui_user_name")||"WebUI用户"}function jC(l){localStorage.setItem("maibot_webui_user_name",l)}const pv="maibot_webui_virtual_tabs";function vC(){try{const l=localStorage.getItem(pv);if(l)return JSON.parse(l)}catch(l){console.error("[Chat] 加载虚拟标签页失败:",l)}return[]}function jg(l){try{localStorage.setItem(pv,JSON.stringify(l))}catch(n){console.error("[Chat] 保存虚拟标签页失败:",n)}}function NC({segment:l}){switch(l.type){case"text":return e.jsx("span",{className:"whitespace-pre-wrap",children:String(l.data)});case"image":case"emoji":return e.jsx("img",{src:String(l.data),alt:l.type==="emoji"?"表情包":"图片",className:B("rounded-lg max-w-full",l.type==="emoji"?"max-h-32":"max-h-64"),loading:"lazy",onError:n=>{const i=n.target;i.style.display="none",i.parentElement?.insertAdjacentHTML("beforeend",`[${l.type==="emoji"?"表情包":"图片"}加载失败]`)}});case"voice":return e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("audio",{controls:!0,src:String(l.data),className:"max-w-[200px] h-8",children:"您的浏览器不支持音频播放"})});case"video":return e.jsx("video",{controls:!0,src:String(l.data),className:"rounded-lg max-w-full max-h-64",children:"您的浏览器不支持视频播放"});case"face":return e.jsxs("span",{className:"text-muted-foreground",children:["[表情:",String(l.data),"]"]});case"music":return e.jsx("span",{className:"text-muted-foreground",children:"[音乐分享]"});case"file":return e.jsxs("span",{className:"text-muted-foreground",children:["[文件: ",String(l.data),"]"]});case"reply":return e.jsx("span",{className:"text-muted-foreground text-xs",children:"[回复消息]"});case"forward":return e.jsx("span",{className:"text-muted-foreground",children:"[转发消息]"});case"unknown":default:return e.jsxs("span",{className:"text-muted-foreground",children:["[",l.original_type||"未知消息","]"]})}}function bC({message:l,isBot:n}){return l.message_type==="rich"&&l.segments&&l.segments.length>0?e.jsx("div",{className:"flex flex-col gap-2",children:l.segments.map((i,c)=>e.jsx(NC,{segment:i},c))}):e.jsx("span",{className:"whitespace-pre-wrap",children:l.content})}function yC(){const l={id:"webui-default",type:"webui",label:"WebUI",messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}},n=()=>{const Ge=vC().map(He=>{const Ve=He.virtualConfig;return!Ve.groupId&&Ve.platform&&Ve.userId&&(Ve.groupId=`webui_virtual_group_${Ve.platform}_${Ve.userId}`),{id:He.id,type:"virtual",label:He.label,virtualConfig:Ve,messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}}});return[l,...Ge]},[i,c]=m.useState(n),[u,x]=m.useState("webui-default"),h=i.find(Q=>Q.id===u)||i[0],[f,p]=m.useState(""),[g,v]=m.useState(!1),[N,y]=m.useState(!0),[w,b]=m.useState(gC()),[L,D]=m.useState(!1),[T,F]=m.useState(""),[O,S]=m.useState(!1),[C,P]=m.useState([]),[M,Z]=m.useState([]),[G,ce]=m.useState(!1),[de,be]=m.useState(!1),[me,pe]=m.useState(""),[je,A]=m.useState({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),Y=m.useRef(pC()),H=m.useRef(new Map),U=m.useRef(null),$=m.useRef(new Map),_e=m.useRef(0),Ne=m.useRef(new Map),{toast:Se}=et(),V=Q=>(_e.current+=1,`${Q}-${Date.now()}-${_e.current}-${Math.random().toString(36).substr(2,9)}`),ye=m.useCallback((Q,Ge)=>{c(He=>He.map(Ve=>Ve.id===Q?{...Ve,...Ge}:Ve))},[]),W=m.useCallback((Q,Ge)=>{c(He=>He.map(Ve=>Ve.id===Q?{...Ve,messages:[...Ve.messages,Ge]}:Ve))},[]),ue=m.useCallback(()=>{U.current?.scrollIntoView({behavior:"smooth"})},[]);m.useEffect(()=>{ue()},[h?.messages,ue]);const ke=m.useCallback(async()=>{ce(!0);try{const Q=await we("/api/chat/platforms");if(console.log("[Chat] 平台列表响应:",Q.status,Q.headers.get("content-type")),Q.ok){const Ge=Q.headers.get("content-type");if(Ge&&Ge.includes("application/json")){const He=await Q.json();console.log("[Chat] 平台列表数据:",He),P(He.platforms||[])}else{const He=await Q.text();console.error("[Chat] 获取平台列表失败: 非 JSON 响应:",He.substring(0,200)),Se({title:"连接失败",description:"无法连接到后端服务,请确保 MaiBot 已启动",variant:"destructive"})}}else console.error("[Chat] 获取平台列表失败: HTTP",Q.status),Se({title:"获取平台失败",description:`服务器返回错误: ${Q.status}`,variant:"destructive"})}catch(Q){console.error("[Chat] 获取平台列表失败:",Q),Se({title:"网络错误",description:"无法连接到后端服务",variant:"destructive"})}finally{ce(!1)}},[Se]),J=m.useCallback(async(Q,Ge)=>{be(!0);try{const He=new URLSearchParams;Q&&He.append("platform",Q),Ge&&He.append("search",Ge),He.append("limit","50");const Ve=await we(`/api/chat/persons?${He.toString()}`);if(Ve.ok){const Bs=Ve.headers.get("content-type");if(Bs&&Bs.includes("application/json")){const Ce=await Ve.json();Z(Ce.persons||[])}else console.error("[Chat] 获取用户列表失败: 后端返回非 JSON 响应")}}catch(He){console.error("[Chat] 获取用户列表失败:",He)}finally{be(!1)}},[]);m.useEffect(()=>{je.platform&&J(je.platform,me)},[je.platform,me,J]);const ee=m.useCallback(async(Q,Ge)=>{y(!0);try{const He=new URLSearchParams;He.append("user_id",Y.current),He.append("limit","50"),Ge&&He.append("group_id",Ge);const Ve=`/api/chat/history?${He.toString()}`;console.log("[Chat] 正在加载历史消息:",Ve);const Bs=await we(Ve);if(Bs.ok){const Ce=await Bs.text();try{const cs=JSON.parse(Ce);if(cs.messages&&cs.messages.length>0){const Es=cs.messages.map(es=>({id:es.id,type:es.type,content:es.content,timestamp:es.timestamp,sender:{name:es.sender_name||(es.is_bot?"麦麦":"WebUI用户"),user_id:es.user_id,is_bot:es.is_bot}}));ye(Q,{messages:Es});const zs=Ne.current.get(Q)||new Set;Es.forEach(es=>{if(es.type==="bot"){const We=`bot-${es.content}-${Math.floor(es.timestamp*1e3)}`;zs.add(We)}}),Ne.current.set(Q,zs)}}catch(cs){console.error("[Chat] JSON 解析失败:",cs)}}}catch(He){console.error("[Chat] 加载历史消息失败:",He)}finally{y(!1)}},[ye]),De=m.useCallback(async(Q,Ge,He)=>{const Ve=H.current.get(Q);if(Ve?.readyState===WebSocket.OPEN||Ve?.readyState===WebSocket.CONNECTING){console.log(`[Tab ${Q}] WebSocket 已存在,跳过连接`);return}v(!0);let Bs=null;try{const zs=await we("/api/webui/ws-token");if(zs.ok){const es=await zs.json();if(es.success&&es.token)Bs=es.token;else{console.warn(`[Tab ${Q}] 获取 WebSocket token 失败: ${es.message||"未登录"}`),v(!1);return}}}catch(zs){console.error(`[Tab ${Q}] 获取 WebSocket token 失败:`,zs),v(!1);return}if(!Bs){v(!1);return}const Ce=window.location.protocol==="https:"?"wss:":"ws:",cs=new URLSearchParams;cs.append("token",Bs),Ge==="virtual"&&He?(cs.append("user_id",He.userId),cs.append("user_name",He.userName),cs.append("platform",He.platform),cs.append("person_id",He.personId),cs.append("group_name",He.groupName||"WebUI虚拟群聊"),He.groupId&&cs.append("group_id",He.groupId)):(cs.append("user_id",Y.current),cs.append("user_name",w));const Es=`${Ce}//${window.location.host}/api/chat/ws?${cs.toString()}`;console.log(`[Tab ${Q}] 正在连接 WebSocket:`,Es);try{const zs=new WebSocket(Es);H.current.set(Q,zs),zs.onopen=()=>{ye(Q,{isConnected:!0}),v(!1),console.log(`[Tab ${Q}] WebSocket 已连接`)},zs.onmessage=es=>{try{const We=JSON.parse(es.data);switch(We.type){case"session_info":ye(Q,{sessionInfo:{session_id:We.session_id,user_id:We.user_id,user_name:We.user_name,bot_name:We.bot_name}});break;case"system":W(Q,{id:V("sys"),type:"system",content:We.content||"",timestamp:We.timestamp||Date.now()/1e3});break;case"user_message":{const vs=We.sender?.user_id,mt=Ge==="virtual"&&He?He.userId:Y.current;console.log(`[Tab ${Q}] 收到 user_message, sender: ${vs}, current: ${mt}`);const Rt=vs?vs.replace(/^webui_user_/,""):"",it=mt?mt.replace(/^webui_user_/,""):"";if(Rt&&it&&Rt===it){console.log(`[Tab ${Q}] 跳过自己的消息(user_id 匹配)`);break}const ss=Ne.current.get(Q)||new Set,St=`user-${We.content}-${Math.floor((We.timestamp||0)*1e3)}`;if(ss.has(St)){console.log(`[Tab ${Q}] 跳过自己的消息(内容去重)`);break}if(ss.add(St),Ne.current.set(Q,ss),ss.size>100){const $t=ss.values().next().value;$t&&ss.delete($t)}W(Q,{id:We.message_id||V("user"),type:"user",content:We.content||"",timestamp:We.timestamp||Date.now()/1e3,sender:We.sender});break}case"bot_message":{ye(Q,{isTyping:!1});const vs=Ne.current.get(Q)||new Set,mt=`bot-${We.content}-${Math.floor((We.timestamp||0)*1e3)}`;if(vs.has(mt))break;if(vs.add(mt),Ne.current.set(Q,vs),vs.size>100){const Rt=vs.values().next().value;Rt&&vs.delete(Rt)}c(Rt=>Rt.map(it=>{if(it.id!==Q)return it;const ss=it.messages.filter($t=>$t.type!=="thinking"),St={id:V("bot"),type:"bot",content:We.content||"",message_type:We.message_type==="rich"?"rich":"text",segments:We.segments,timestamp:We.timestamp||Date.now()/1e3,sender:We.sender};return{...it,messages:[...ss,St]}}));break}case"typing":ye(Q,{isTyping:We.is_typing||!1});break;case"error":c(vs=>vs.map(mt=>{if(mt.id!==Q)return mt;const Rt=mt.messages.filter(it=>it.type!=="thinking");return{...mt,messages:[...Rt,{id:V("error"),type:"error",content:We.content||"发生错误",timestamp:We.timestamp||Date.now()/1e3}]}})),Se({title:"错误",description:We.content,variant:"destructive"});break;case"pong":break;case"history":{const vs=We.messages||[];if(vs.length>0){const mt=Ne.current.get(Q)||new Set,Rt=vs.map(it=>{const ss=it.is_bot||!1,St=it.id||V(ss?"bot":"user"),$t=`${ss?"bot":"user"}-${it.content}-${Math.floor(it.timestamp*1e3)}`;return mt.add($t),{id:St,type:ss?"bot":"user",content:it.content,timestamp:it.timestamp,sender:{name:it.sender_name||(ss?"麦麦":"用户"),user_id:it.sender_id,is_bot:ss}}});Ne.current.set(Q,mt),ye(Q,{messages:Rt}),console.log(`[Tab ${Q}] 已加载 ${Rt.length} 条历史消息`)}break}default:console.log("未知消息类型:",We.type)}}catch(We){console.error("解析消息失败:",We)}},zs.onclose=()=>{ye(Q,{isConnected:!1}),v(!1),H.current.delete(Q),console.log(`[Tab ${Q}] WebSocket 已断开`);const es=$.current.get(Q);es&&clearTimeout(es);const We=window.setTimeout(()=>{if(!Fe.current){const vs=i.find(mt=>mt.id===Q);vs&&De(Q,vs.type,vs.virtualConfig)}},5e3);$.current.set(Q,We)},zs.onerror=es=>{console.error(`[Tab ${Q}] WebSocket 错误:`,es),v(!1)}}catch(zs){console.error(`[Tab ${Q}] 创建 WebSocket 失败:`,zs),v(!1)}},[w,ye,W,Se,i]),Fe=m.useRef(!1);m.useEffect(()=>{Fe.current=!1;const Q=H.current,Ge=$.current,He=Ne.current;ee("webui-default");const Ve=setTimeout(()=>{Fe.current||(De("webui-default","webui"),i.forEach(Ce=>{Ce.type==="virtual"&&Ce.virtualConfig&&(He.set(Ce.id,new Set),setTimeout(()=>{Fe.current||De(Ce.id,"virtual",Ce.virtualConfig)},200))}))},100),Bs=setInterval(()=>{Q.forEach(Ce=>{Ce.readyState===WebSocket.OPEN&&Ce.send(JSON.stringify({type:"ping"}))})},3e4);return()=>{Fe.current=!0,clearTimeout(Ve),clearInterval(Bs),Ge.forEach(Ce=>{clearTimeout(Ce)}),Ge.clear(),Q.forEach(Ce=>{Ce.close()}),Q.clear()}},[]);const ge=m.useCallback(()=>{const Q=H.current.get(u);if(!f.trim()||!Q||Q.readyState!==WebSocket.OPEN)return;const Ge=h?.type==="virtual"&&h.virtualConfig?.userName||w,He=f.trim(),Ve=Date.now()/1e3;Q.send(JSON.stringify({type:"message",content:He,user_name:Ge}));const Bs=Ne.current.get(u)||new Set,Ce=`user-${He}-${Math.floor(Ve*1e3)}`;if(Bs.add(Ce),Ne.current.set(u,Bs),Bs.size>100){const zs=Bs.values().next().value;zs&&Bs.delete(zs)}const cs={id:V("user"),type:"user",content:He,timestamp:Ve,sender:{name:Ge,is_bot:!1}};W(u,cs);const Es={id:V("thinking"),type:"thinking",content:"",timestamp:Ve+.001,sender:{name:h?.sessionInfo.bot_name||"麦麦",is_bot:!0}};W(u,Es),p("")},[f,w,u,h,W]),as=Q=>{Q.key==="Enter"&&!Q.shiftKey&&(Q.preventDefault(),ge())},ae=()=>{F(w),D(!0)},Ee=()=>{const Q=T.trim()||"WebUI用户";b(Q),jC(Q),D(!1);const Ge=H.current.get(u);Ge?.readyState===WebSocket.OPEN&&Ge.send(JSON.stringify({type:"update_nickname",user_name:Q}))},ie=()=>{F(""),D(!1)},ve=Q=>new Date(Q*1e3).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),Me=()=>{const Q=H.current.get(u);Q&&(Q.close(),H.current.delete(u)),De(u,h?.type||"webui",h?.virtualConfig)},Ze=()=>{A({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),pe(""),ke(),S(!0)},js=()=>{if(!je.platform||!je.personId){Se({title:"配置不完整",description:"请选择平台和用户",variant:"destructive"});return}const Q=`webui_virtual_group_${je.platform}_${je.userId}`,Ge=`virtual-${je.platform}-${je.userId}-${Date.now()}`,He=je.userName||je.userId,Ve={id:Ge,type:"virtual",label:He,virtualConfig:{...je,groupId:Q},messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}};c(Bs=>{const Ce=[...Bs,Ve],cs=Ce.filter(Es=>Es.type==="virtual"&&Es.virtualConfig).map(Es=>({id:Es.id,label:Es.label,virtualConfig:Es.virtualConfig,createdAt:Date.now()}));return jg(cs),Ce}),x(Ge),S(!1),Ne.current.set(Ge,new Set),setTimeout(()=>{De(Ge,"virtual",je)},100),Se({title:"虚拟身份标签页",description:`已创建 ${He} 的对话`})},Ot=(Q,Ge)=>{if(Ge?.stopPropagation(),Q==="webui-default")return;const He=H.current.get(Q);He&&(He.close(),H.current.delete(Q));const Ve=$.current.get(Q);Ve&&(clearTimeout(Ve),$.current.delete(Q)),Ne.current.delete(Q),c(Bs=>{const Ce=Bs.filter(Es=>Es.id!==Q),cs=Ce.filter(Es=>Es.type==="virtual"&&Es.virtualConfig).map(Es=>({id:Es.id,label:Es.label,virtualConfig:Es.virtualConfig,createdAt:Date.now()}));return jg(cs),Ce}),u===Q&&x("webui-default")},rs=Q=>{x(Q)},Ps=Q=>{A(Ge=>({...Ge,personId:Q.person_id,userId:Q.user_id,userName:Q.nickname||Q.person_name}))};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx(Is,{open:O,onOpenChange:S,children:e.jsxs(Rs,{className:"sm:max-w-[500px] max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsxs(Ls,{children:[e.jsxs(Us,{className:"flex items-center gap-2",children:[e.jsx(im,{className:"h-5 w-5"}),"新建虚拟身份对话"]}),e.jsx(Zs,{children:"选择一个麦麦已认识的用户,以该用户的身份与麦麦对话。麦麦将使用她对该用户的记忆和认知来回应。"})]}),e.jsxs("div",{className:"space-y-4 flex-1 overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(_m,{className:"h-4 w-4"}),"选择平台"]}),e.jsxs(Le,{value:je.platform,onValueChange:Q=>{A(Ge=>({...Ge,platform:Q,personId:"",userId:"",userName:""})),Z([])},children:[e.jsx(Oe,{disabled:G,children:e.jsx(Ue,{placeholder:G?"加载中...":"选择平台"})}),e.jsx(Re,{children:C.map(Q=>e.jsxs(le,{value:Q.platform,children:[Q.platform," (",Q.count," 人)"]},Q.platform))})]})]}),je.platform&&e.jsxs("div",{className:"space-y-2 flex-1 overflow-hidden flex flex-col",children:[e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(Sm,{className:"h-4 w-4"}),"选择用户"]}),e.jsxs("div",{className:"relative",children:[e.jsx(Vt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(re,{placeholder:"搜索用户名...",value:me,onChange:Q=>pe(Q.target.value),className:"pl-9"})]}),e.jsx(Je,{className:"h-[250px] border rounded-md",children:e.jsx("div",{className:"p-2",children:de?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Js,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):M.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[e.jsx(Sm,{className:"h-8 w-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"没有找到用户"})]}):e.jsx("div",{className:"space-y-1",children:M.map(Q=>e.jsxs("button",{onClick:()=>Ps(Q),className:B("w-full flex items-center gap-3 p-2 rounded-md text-left transition-colors",je.personId===Q.person_id?"bg-primary text-primary-foreground":"hover:bg-muted"),children:[e.jsx(Di,{className:"h-8 w-8 shrink-0",children:e.jsx(Oi,{className:B("text-xs",je.personId===Q.person_id?"bg-primary-foreground/20":"bg-muted"),children:(Q.nickname||Q.person_name||"?").charAt(0)})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium truncate",children:Q.nickname||Q.person_name}),e.jsxs("div",{className:B("text-xs truncate",je.personId===Q.person_id?"text-primary-foreground/70":"text-muted-foreground"),children:["ID: ",Q.user_id,Q.is_known&&" · 已认识"]})]})]},Q.person_id))})})})]}),je.personId&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{children:"虚拟群名(可选)"}),e.jsx(re,{placeholder:"WebUI虚拟群聊",value:je.groupName,onChange:Q=>A(Ge=>({...Ge,groupName:Q.target.value}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦会认为这是一个名为此名称的群聊"})]})]}),e.jsxs(rt,{className:"gap-2 sm:gap-0",children:[e.jsx(k,{variant:"outline",onClick:()=>S(!1),children:"取消"}),e.jsx(k,{onClick:js,disabled:!je.platform||!je.personId,children:"创建对话"})]})]})}),e.jsx("div",{className:"shrink-0 border-b bg-muted/30",children:e.jsx("div",{className:"max-w-4xl mx-auto px-2 sm:px-4",children:e.jsxs("div",{className:"flex items-center gap-1 overflow-x-auto py-1.5 scrollbar-thin",children:[i.map(Q=>e.jsxs("div",{className:B("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm whitespace-nowrap transition-colors cursor-pointer","hover:bg-muted",u===Q.id?"bg-background shadow-sm border":"text-muted-foreground"),onClick:()=>rs(Q.id),children:[Q.type==="webui"?e.jsx(Wl,{className:"h-3.5 w-3.5"}):e.jsx(im,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"max-w-[100px] truncate",children:Q.label}),e.jsx("span",{className:B("w-1.5 h-1.5 rounded-full",Q.isConnected?"bg-green-500":"bg-muted-foreground/50")}),Q.id!=="webui-default"&&e.jsx("span",{onClick:Ge=>Ot(Q.id,Ge),className:"ml-0.5 p-0.5 rounded hover:bg-muted-foreground/20 cursor-pointer",role:"button",tabIndex:0,onKeyDown:Ge=>{(Ge.key==="Enter"||Ge.key===" ")&&(Ge.preventDefault(),Ot(Q.id,Ge))},children:e.jsx(Da,{className:"h-3 w-3"})})]},Q.id)),e.jsx("button",{onClick:Ze,className:"flex items-center gap-1 px-2 py-1.5 rounded-md text-sm text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",title:"新建虚拟身份对话",children:e.jsx(lt,{className:"h-3.5 w-3.5"})})]})})}),e.jsx("div",{className:"shrink-0 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60",children:e.jsxs("div",{className:"p-3 sm:p-4 max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 min-w-0",children:[e.jsx(Di,{className:"h-8 w-8 sm:h-10 sm:w-10 shrink-0",children:e.jsx(Oi,{className:"bg-primary/10 text-primary",children:e.jsx(Mi,{className:"h-4 w-4 sm:h-5 sm:w-5"})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-base sm:text-lg font-semibold truncate",children:h?.sessionInfo.bot_name||"麦麦"}),e.jsx("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:h?.isConnected?e.jsxs(e.Fragment,{children:[e.jsx(Hw,{className:"h-3 w-3 text-green-500"}),e.jsx("span",{className:"text-green-600 dark:text-green-400",children:"已连接"})]}):g?e.jsxs(e.Fragment,{children:[e.jsx(Js,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"连接中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Iw,{className:"h-3 w-3 text-red-500"}),e.jsx("span",{className:"text-red-600 dark:text-red-400",children:"未连接"})]})})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[N&&e.jsx(Js,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:Me,disabled:g,title:"重新连接",children:e.jsx(zt,{className:B("h-4 w-4",g&&"animate-spin")})})]})]}),e.jsx("div",{className:"hidden sm:flex items-center gap-2 mt-2 text-sm text-muted-foreground",children:h?.type==="virtual"&&h.virtualConfig?e.jsxs(e.Fragment,{children:[e.jsx(im,{className:"h-3 w-3 text-primary"}),e.jsx("span",{children:"虚拟身份:"}),e.jsx("span",{className:"font-medium text-primary",children:h.virtualConfig.userName}),e.jsxs("span",{className:"text-xs",children:["(",h.virtualConfig.platform,")"]}),h.virtualConfig.groupName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1",children:"·"}),e.jsxs("span",{className:"text-xs",children:["群:",h.virtualConfig.groupName]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(kr,{className:"h-3 w-3"}),e.jsx("span",{children:"当前身份:"}),L?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{value:T,onChange:Q=>F(Q.target.value),onKeyDown:Q=>{Q.key==="Enter"&&Ee(),Q.key==="Escape"&&ie()},className:"h-7 w-32",placeholder:"输入昵称",autoFocus:!0}),e.jsx(k,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:Ee,children:"保存"}),e.jsx(k,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:ie,children:"取消"})]}):e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-foreground",children:w}),e.jsx(k,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:ae,title:"修改昵称",children:e.jsx(Pw,{className:"h-3 w-3"})})]})]})})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"p-3 sm:p-4 max-w-4xl mx-auto space-y-3 sm:space-y-4",children:[h?.messages.length===0&&!N&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(Mi,{className:"h-12 w-12 mb-4 opacity-50"}),e.jsxs("p",{className:"text-sm",children:["开始与 ",h?.sessionInfo.bot_name||"麦麦"," 对话吧!"]})]}),h?.messages.map(Q=>e.jsxs("div",{className:B("flex gap-2 sm:gap-3",Q.type==="user"&&"flex-row-reverse",Q.type==="system"&&"justify-center",Q.type==="error"&&"justify-center"),children:[Q.type==="system"&&e.jsx("div",{className:"text-xs text-muted-foreground bg-muted/50 px-3 py-1 rounded-full max-w-[90%]",children:Q.content}),Q.type==="error"&&e.jsx("div",{className:"text-xs text-red-600 dark:text-red-400 bg-red-100 dark:bg-red-900/30 px-3 py-1 rounded-full max-w-[90%]",children:Q.content}),Q.type==="thinking"&&e.jsxs(e.Fragment,{children:[e.jsx(Di,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(Oi,{className:"bg-primary/10 text-primary",children:e.jsx(Mi,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})}),e.jsxs("div",{className:"flex flex-col gap-1 max-w-[75%] sm:max-w-[70%]",children:[e.jsx("div",{className:"flex items-center gap-2 text-[10px] sm:text-xs text-muted-foreground",children:e.jsx("span",{className:"hidden sm:inline",children:Q.sender?.name||h?.sessionInfo.bot_name})}),e.jsx("div",{className:"bg-muted rounded-2xl rounded-tl-sm px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("span",{className:"w-2 h-2 bg-primary/60 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"w-2 h-2 bg-primary/60 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("span",{className:"w-2 h-2 bg-primary/60 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]}),e.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:"思考中..."})]})})]})]}),(Q.type==="user"||Q.type==="bot")&&e.jsxs(e.Fragment,{children:[e.jsx(Di,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(Oi,{className:B("text-xs",Q.type==="bot"?"bg-primary/10 text-primary":"bg-secondary text-secondary-foreground"),children:Q.type==="bot"?e.jsx(Mi,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}):e.jsx(kr,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})}),e.jsxs("div",{className:B("flex flex-col gap-1 max-w-[75%] sm:max-w-[70%]",Q.type==="user"&&"items-end"),children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] sm:text-xs text-muted-foreground",children:[e.jsx("span",{className:"hidden sm:inline",children:Q.sender?.name||(Q.type==="bot"?h?.sessionInfo.bot_name:w)}),e.jsx("span",{children:ve(Q.timestamp)})]}),e.jsx("div",{className:B("rounded-2xl px-3 py-2 text-sm break-words",Q.type==="bot"?"bg-muted rounded-tl-sm":"bg-primary text-primary-foreground rounded-tr-sm"),children:e.jsx(bC,{message:Q,isBot:Q.type==="bot"})})]})]})]},Q.id)),e.jsx("div",{ref:U})]})})}),e.jsx("div",{className:"shrink-0 border-t bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60",children:e.jsx("div",{className:"p-3 sm:p-4 max-w-4xl mx-auto",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(re,{value:f,onChange:Q=>p(Q.target.value),onKeyDown:as,placeholder:h?.isConnected?"输入消息...":"等待连接...",disabled:!h?.isConnected,className:"flex-1 h-10 sm:h-10"}),e.jsx(k,{onClick:ge,disabled:!h?.isConnected||!f.trim(),size:"icon",className:"h-10 w-10 shrink-0",children:e.jsx(Gw,{className:"h-4 w-4"})})]})})})]})}var Vm="Radio",[wC,gv]=Do(Vm),[_C,SC]=wC(Vm),jv=m.forwardRef((l,n)=>{const{__scopeRadio:i,name:c,checked:u=!1,required:x,disabled:h,value:f="on",onCheck:p,form:g,...v}=l,[N,y]=m.useState(null),w=Oo(n,D=>y(D)),b=m.useRef(!1),L=N?g||!!N.closest("form"):!0;return e.jsxs(_C,{scope:i,checked:u,disabled:h,children:[e.jsx(An.button,{type:"button",role:"radio","aria-checked":u,"data-state":yv(u),"data-disabled":h?"":void 0,disabled:h,value:f,...v,ref:w,onClick:Zl(l.onClick,D=>{u||p?.(),L&&(b.current=D.isPropagationStopped(),b.current||D.stopPropagation())})}),L&&e.jsx(bv,{control:N,bubbles:!b.current,name:c,value:f,checked:u,required:x,disabled:h,form:g,style:{transform:"translateX(-100%)"}})]})});jv.displayName=Vm;var vv="RadioIndicator",Nv=m.forwardRef((l,n)=>{const{__scopeRadio:i,forceMount:c,...u}=l,x=SC(vv,i);return e.jsx(ow,{present:c||x.checked,children:e.jsx(An.span,{"data-state":yv(x.checked),"data-disabled":x.disabled?"":void 0,...u,ref:n})})});Nv.displayName=vv;var CC="RadioBubbleInput",bv=m.forwardRef(({__scopeRadio:l,control:n,checked:i,bubbles:c=!0,...u},x)=>{const h=m.useRef(null),f=Oo(h,x),p=dw(i),g=uw(n);return m.useEffect(()=>{const v=h.current;if(!v)return;const N=window.HTMLInputElement.prototype,w=Object.getOwnPropertyDescriptor(N,"checked").set;if(p!==i&&w){const b=new Event("click",{bubbles:c});w.call(v,i),v.dispatchEvent(b)}},[p,i,c]),e.jsx(An.input,{type:"radio","aria-hidden":!0,defaultChecked:i,...u,tabIndex:-1,ref:f,style:{...u.style,...g,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});bv.displayName=CC;function yv(l){return l?"checked":"unchecked"}var kC=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],qo="RadioGroup",[TC]=Do(qo,[Hg,gv]),wv=Hg(),_v=gv(),[EC,MC]=TC(qo),Sv=m.forwardRef((l,n)=>{const{__scopeRadioGroup:i,name:c,defaultValue:u,value:x,required:h=!1,disabled:f=!1,orientation:p,dir:g,loop:v=!0,onValueChange:N,...y}=l,w=wv(i),b=tj(g),[L,D]=zo({prop:x,defaultProp:u??null,onChange:N,caller:qo});return e.jsx(EC,{scope:i,name:c,required:h,disabled:f,value:L,onValueChange:D,children:e.jsx(w0,{asChild:!0,...w,orientation:p,dir:b,loop:v,children:e.jsx(An.div,{role:"radiogroup","aria-required":h,"aria-orientation":p,"data-disabled":f?"":void 0,dir:b,...y,ref:n})})})});Sv.displayName=qo;var Cv="RadioGroupItem",kv=m.forwardRef((l,n)=>{const{__scopeRadioGroup:i,disabled:c,...u}=l,x=MC(Cv,i),h=x.disabled||c,f=wv(i),p=_v(i),g=m.useRef(null),v=Oo(n,g),N=x.value===u.value,y=m.useRef(!1);return m.useEffect(()=>{const w=L=>{kC.includes(L.key)&&(y.current=!0)},b=()=>y.current=!1;return document.addEventListener("keydown",w),document.addEventListener("keyup",b),()=>{document.removeEventListener("keydown",w),document.removeEventListener("keyup",b)}},[]),e.jsx(_0,{asChild:!0,...f,focusable:!h,active:N,children:e.jsx(jv,{disabled:h,required:x.required,checked:N,...p,...u,name:x.name,ref:v,onCheck:()=>x.onValueChange(u.value),onKeyDown:Zl(w=>{w.key==="Enter"&&w.preventDefault()}),onFocus:Zl(u.onFocus,()=>{y.current&&g.current?.click()})})})});kv.displayName=Cv;var AC="RadioGroupIndicator",Tv=m.forwardRef((l,n)=>{const{__scopeRadioGroup:i,...c}=l,u=_v(i);return e.jsx(Nv,{...u,...c,ref:n})});Tv.displayName=AC;var Ev=Sv,Mv=kv,zC=Tv;const Km=m.forwardRef(({className:l,...n},i)=>e.jsx(Ev,{className:B("grid gap-2",l),...n,ref:i}));Km.displayName=Ev.displayName;const Mo=m.forwardRef(({className:l,...n},i)=>e.jsx(Mv,{ref:i,className:B("aspect-square h-4 w-4 rounded-full border border-primary text-primary shadow focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",l),...n,children:e.jsx(zC,{className:"flex items-center justify-center",children:e.jsx(yj,{className:"h-2.5 w-2.5 fill-current text-current"})})}));Mo.displayName=Mv.displayName;function DC({question:l,value:n,onChange:i,error:c,disabled:u=!1}){const[x,h]=m.useState(null),f=u||l.readOnly,p=()=>{switch(l.type){case"single":return e.jsx(Km,{value:n||"",onValueChange:i,disabled:f,className:"space-y-2",children:l.options?.map(g=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Mo,{value:g.value,id:`${l.id}-${g.id}`}),e.jsx(E,{htmlFor:`${l.id}-${g.id}`,className:"cursor-pointer font-normal",children:g.label})]},g.id))});case"multiple":{const g=n||[];return e.jsxs("div",{className:"space-y-2",children:[l.options?.map(v=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xs,{id:`${l.id}-${v.id}`,checked:g.includes(v.value),disabled:f||l.maxSelections!==void 0&&g.length>=l.maxSelections&&!g.includes(v.value),onCheckedChange:N=>{i(N?[...g,v.value]:g.filter(y=>y!==v.value))}}),e.jsx(E,{htmlFor:`${l.id}-${v.id}`,className:"cursor-pointer font-normal",children:v.label})]},v.id)),l.maxSelections&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["最多选择 ",l.maxSelections," 项"]})]})}case"text":return e.jsx(re,{value:n||"",onChange:g=>i(g.target.value),placeholder:l.placeholder||"请输入...",disabled:f,readOnly:l.readOnly,maxLength:l.maxLength,className:B(l.readOnly&&"bg-muted cursor-not-allowed")});case"textarea":return e.jsxs("div",{className:"space-y-1",children:[e.jsx(Ys,{value:n||"",onChange:g=>i(g.target.value),placeholder:l.placeholder||"请输入...",disabled:f,readOnly:l.readOnly,maxLength:l.maxLength,rows:4,className:B(l.readOnly&&"bg-muted cursor-not-allowed")}),l.maxLength&&e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[(n||"").length," / ",l.maxLength]})]});case"rating":{const g=n||0,v=x!==null?x:g;return e.jsxs("div",{className:"flex items-center gap-1",children:[[1,2,3,4,5].map(N=>e.jsx("button",{type:"button",disabled:f,className:B("p-1 transition-colors focus:outline-none focus:ring-2 focus:ring-ring rounded",f&&"cursor-not-allowed opacity-50"),onMouseEnter:()=>!f&&h(N),onMouseLeave:()=>h(null),onClick:()=>!f&&i(N),children:e.jsx(vl,{className:B("h-6 w-6 transition-colors",N<=v?"fill-yellow-400 text-yellow-400":"text-muted-foreground")})},N)),g>0&&e.jsxs("span",{className:"ml-2 text-sm text-muted-foreground",children:[g," / 5"]})]})}case"scale":{const g=l.min??1,v=l.max??10,N=l.step??1,y=n??g;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Na,{value:[y],onValueChange:([w])=>i(w),min:g,max:v,step:N,disabled:f}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:l.minLabel||g}),e.jsx("span",{className:"font-medium text-foreground",children:y}),e.jsx("span",{children:l.maxLabel||v})]})]})}case"dropdown":return e.jsxs(Le,{value:n||"",onValueChange:i,disabled:f,children:[e.jsx(Oe,{children:e.jsx(Ue,{placeholder:l.placeholder||"请选择..."})}),e.jsx(Re,{children:l.options?.map(g=>e.jsx(le,{value:g.value,children:g.label},g.id))})]});default:return e.jsx("div",{className:"text-muted-foreground",children:"不支持的问题类型"})}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(E,{className:"text-base font-medium",children:[l.title,l.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),l.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:l.description})]}),p(),c&&e.jsx("p",{className:"text-sm text-destructive",children:c})]})}const Av="https://maibot-plugin-stats.maibot-webui.workers.dev";function zv(){const l="maibot_user_id";let n=localStorage.getItem(l);if(!n){const i=Math.random().toString(36).substring(2,10),c=Date.now().toString(36),u=Math.random().toString(36).substring(2,10);n=`fp_${i}_${c}_${u}`,localStorage.setItem(l,n)}return n}async function OC(l,n,i,c){try{const u=c?.userId||zv(),x={surveyId:l,surveyVersion:n,userId:u,answers:i,submittedAt:new Date().toISOString(),allowMultiple:c?.allowMultiple,metadata:{userAgent:navigator.userAgent,language:navigator.language}},h=await fetch(`${Av}/survey/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)}),f=await h.json();return h.status===429?{success:!1,error:"提交过于频繁,请稍后再试"}:h.status===409?{success:!1,error:f.error||"你已经提交过这份问卷了"}:h.ok?{success:!0,submissionId:f.submissionId,message:f.message}:{success:!1,error:f.error||"提交失败"}}catch(u){return console.error("Error submitting survey:",u),{success:!1,error:"网络错误"}}}async function RC(l,n){try{const i=n||zv(),c=new URLSearchParams({user_id:i,survey_id:l}),u=await fetch(`${Av}/survey/check?${c}`);return u.ok?{success:!0,hasSubmitted:(await u.json()).hasSubmitted}:{success:!1,error:(await u.json()).error||"检查失败"}}catch(i){return console.error("Error checking submission:",i),{success:!1,error:"网络错误"}}}function Dv({config:l,initialAnswers:n,onSubmitSuccess:i,onSubmitError:c,showProgress:u=!0,paginateQuestions:x=!1,className:h}){const f=m.useCallback(()=>!n||n.length===0?{}:n.reduce((H,U)=>(H[U.questionId]=U.value,H),{}),[n]),[p,g]=m.useState(()=>f()),[v,N]=m.useState({}),[y,w]=m.useState(0),[b,L]=m.useState(!1),[D,T]=m.useState(!1),[F,O]=m.useState(null),[S,C]=m.useState(null),[P,M]=m.useState(!1),[Z,G]=m.useState(!0);m.useEffect(()=>{n&&n.length>0&&g(H=>({...H,...f()}))},[n,f]),m.useEffect(()=>{(async()=>{if(!l.settings?.allowMultiple){const U=await RC(l.id);U.success&&U.hasSubmitted&&M(!0)}G(!1)})()},[l.id,l.settings?.allowMultiple]);const ce=m.useCallback(()=>{const H=new Date;return!(l.settings?.startTime&&new Date(l.settings.startTime)>H||l.settings?.endTime&&new Date(l.settings.endTime){const U=p[H.id];return U==null?!1:Array.isArray(U)?U.length>0:typeof U=="string"?U.trim()!=="":!0}).length,be=de/l.questions.length*100,me=m.useCallback((H,U)=>{g($=>({...$,[H]:U})),N($=>{const _e={...$};return delete _e[H],_e})},[]),pe=m.useCallback(()=>{const H={};for(const U of l.questions){if(U.required){const $=p[U.id];if($==null){H[U.id]="此题为必填项";continue}if(Array.isArray($)&&$.length===0){H[U.id]="请至少选择一项";continue}if(typeof $=="string"&&$.trim()===""){H[U.id]="此题为必填项";continue}}U.minLength&&typeof p[U.id]=="string"&&p[U.id].length{if(!pe()){if(x){const H=l.questions.findIndex(U=>v[U.id]);H>=0&&w(H)}return}L(!0),O(null);try{const H=l.questions.filter($=>p[$.id]!==void 0).map($=>({questionId:$.id,value:p[$.id]})),U=await OC(l.id,l.version,H,{allowMultiple:l.settings?.allowMultiple});if(U.success&&U.submissionId)T(!0),C(U.submissionId),i?.(U.submissionId);else{const $=U.error||"提交失败";O($),c?.($)}}catch(H){const U=H instanceof Error?H.message:"提交失败";O(U),c?.(U)}finally{L(!1)}},[pe,x,l,p,v,i,c]),A=m.useCallback(H=>{H>=0&&He.jsxs("div",{className:B("p-4 rounded-lg border bg-card",v[H.id]?"border-destructive bg-destructive/5":"border-border"),children:[x&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:["问题 ",y+1," / ",l.questions.length]}),!x&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:[U+1,"."]}),e.jsx(DC,{question:H,value:p[H.id],onChange:$=>me(H.id,$),error:v[H.id],disabled:b})]},H.id)),F&&e.jsxs(gt,{variant:"destructive",children:[e.jsx(Dt,{className:"h-4 w-4"}),e.jsx(jt,{children:F})]}),e.jsx("div",{className:"flex justify-between items-center py-4",children:x?e.jsxs(e.Fragment,{children:[e.jsxs(k,{variant:"outline",onClick:()=>A(y-1),disabled:y===0||b,children:[e.jsx(Wa,{className:"h-4 w-4 mr-1"}),"上一题"]}),y===l.questions.length-1?e.jsxs(k,{onClick:je,disabled:b,children:[b&&e.jsx(Js,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]}):e.jsxs(k,{onClick:()=>A(y+1),disabled:b,children:["下一题",e.jsx(ba,{className:"h-4 w-4 ml-1"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:Object.keys(v).length>0&&e.jsxs("span",{className:"text-destructive",children:["还有 ",Object.keys(v).length," 个必填项未完成"]})}),e.jsxs(k,{onClick:je,disabled:b,size:"lg",children:[b&&e.jsx(Js,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]})]})})]})})]})}const LC={id:"webui-feedback-v1",version:"1.0.0",title:"麦麦 WebUI 使用反馈问卷",description:"感谢您使用麦麦 WebUI!您的反馈将帮助我们不断改进产品体验。",questions:[{id:"webui_version",type:"text",title:"你正在使用的 WebUI 版本",description:"此项由系统自动填写",required:!0,readOnly:!0,placeholder:"自动检测中..."},{id:"ui_design_satisfaction",type:"single",title:"你觉得当前的 WebUI 界面设计如何?",required:!0,options:[{id:"very_satisfied",label:"非常满意",value:"very_satisfied"},{id:"satisfied",label:"满意",value:"satisfied"},{id:"neutral",label:"一般",value:"neutral"},{id:"dissatisfied",label:"不满意",value:"dissatisfied"},{id:"very_dissatisfied",label:"非常不满意",value:"very_dissatisfied"}]},{id:"problems_encountered",type:"multiple",title:"你在使用 WebUI 时遇到过哪些问题?",description:"可多选",required:!0,options:[{id:"lag",label:"界面卡顿",value:"lag"},{id:"incomplete",label:"功能不完整",value:"incomplete"},{id:"complex",label:"操作复杂",value:"complex"},{id:"bugs",label:"存在 Bug",value:"bugs"},{id:"none",label:"没有遇到问题",value:"none"},{id:"other",label:"其他",value:"other"}]},{id:"problems_other",type:"text",title:'如选择"其他",请说明遇到的问题',required:!1,placeholder:"请描述你遇到的其他问题...",maxLength:500},{id:"useful_features",type:"textarea",title:"你觉得哪些功能是最有用的?",required:!0,placeholder:"请分享你认为最有价值的功能...",maxLength:1e3},{id:"feature_requests",type:"textarea",title:"你希望在未来的版本中增加哪些功能?",required:!0,placeholder:"请告诉我们你期望的新功能...",maxLength:1e3},{id:"overall_satisfaction",type:"single",title:"你对麦麦 WebUI 的整体满意度如何?",required:!0,options:[{id:"very_satisfied",label:"非常满意",value:"very_satisfied"},{id:"satisfied",label:"满意",value:"satisfied"},{id:"neutral",label:"一般",value:"neutral"},{id:"dissatisfied",label:"不满意",value:"dissatisfied"},{id:"very_dissatisfied",label:"非常不满意",value:"very_dissatisfied"}]},{id:"would_recommend",type:"single",title:"你愿意推荐麦麦 WebUI 给其他人使用吗?",required:!0,options:[{id:"yes",label:"是",value:"yes"},{id:"no",label:"否",value:"no"}]},{id:"other_suggestions",type:"textarea",title:"其他建议或意见",description:"此项为选填",required:!1,placeholder:"如果你有任何其他想法或建议,请在此分享...",maxLength:2e3}],settings:{allowMultiple:!1,thankYouMessage:"感谢你的反馈!你的意见对我们非常重要,我们会认真考虑每一条建议。"}},UC={id:"maibot-feedback-v1",version:"1.0.0",title:"麦麦使用体验反馈问卷",description:"感谢您使用麦麦!您的反馈将帮助我们打造更好的 AI 伙伴。",questions:[{id:"maibot_version",type:"text",title:"你正在使用的麦麦版本",description:"此项由系统自动填写",required:!0,readOnly:!0,placeholder:"自动检测中..."},{id:"improvement_areas",type:"textarea",title:"你认为麦麦还有哪些部分可以改进?",required:!0,placeholder:"请分享你认为可以改进的方面...",maxLength:1e3},{id:"problems_encountered",type:"multiple",title:"你在使用麦麦时遇到过哪些问题?",description:"可多选",required:!0,options:[{id:"incomplete",label:"功能不完整",value:"incomplete"},{id:"slow_response",label:"响应速度慢",value:"slow_response"},{id:"complex",label:"操作复杂",value:"complex"},{id:"unstable",label:"运行不稳定",value:"unstable"},{id:"config_difficult",label:"配置困难",value:"config_difficult"},{id:"none",label:"没有遇到问题",value:"none"},{id:"other",label:"其他",value:"other"}]},{id:"problems_other",type:"text",title:'如选择"其他",请说明遇到的问题',required:!1,placeholder:"请描述你遇到的其他问题...",maxLength:500},{id:"helpful_features",type:"textarea",title:"你觉得麦麦的哪些功能对你最有帮助?",required:!0,placeholder:"请分享对你最有帮助的功能...",maxLength:1e3},{id:"feature_requests",type:"textarea",title:"你希望在未来的版本中增加哪些功能?",required:!0,placeholder:"请告诉我们你期望的新功能...",maxLength:1e3},{id:"overall_satisfaction",type:"single",title:"你对麦麦的整体满意度如何?",required:!0,options:[{id:"very_satisfied",label:"非常满意",value:"very_satisfied"},{id:"satisfied",label:"满意",value:"satisfied"},{id:"neutral",label:"一般",value:"neutral"},{id:"dissatisfied",label:"不满意",value:"dissatisfied"},{id:"very_dissatisfied",label:"非常不满意",value:"very_dissatisfied"}]},{id:"would_recommend",type:"single",title:"你愿意推荐麦麦给其他人使用吗?",required:!0,options:[{id:"yes",label:"是",value:"yes"},{id:"no",label:"否",value:"no"}]},{id:"other_suggestions",type:"textarea",title:"其他建议或意见",description:"此项为选填",required:!1,placeholder:"如果你有任何其他想法或建议,请在此分享...",maxLength:2e3}],settings:{allowMultiple:!1,thankYouMessage:"感谢你的反馈!你的意见对麦麦的成长非常重要,我们会认真考虑每一条建议。"}};function BC(){const[l,n]=m.useState(!0),i=m.useMemo(()=>JSON.parse(JSON.stringify(LC)),[]);m.useEffect(()=>{n(!1)},[]);const c=m.useMemo(()=>[{questionId:"webui_version",value:`v${Uo}`}],[]),u=m.useCallback(h=>{console.log("WebUI Survey submitted:",h)},[]),x=m.useCallback(h=>{console.error("WebUI Survey submission error:",h)},[]);return l?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(Js,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):i?e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 shrink-0",children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(wj,{className:"h-8 w-8",strokeWidth:2}),"WebUI 使用反馈问卷"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"感谢您的反馈,帮助我们持续改进产品体验"})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Dv,{config:i,initialAnswers:c,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:u,onSubmitError:x})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(gt,{variant:"destructive",className:"max-w-md",children:[e.jsx(Dt,{className:"h-4 w-4"}),e.jsx(jt,{children:"无法加载问卷配置"})]}),e.jsx(k,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}function $C(){const[l,n]=m.useState(null),[i,c]=m.useState(!0),[u,x]=m.useState("未知版本");m.useEffect(()=>{(async()=>{try{const N=await D1();x(N.version||"未知版本")}catch(N){console.error("Failed to get MaiBot version:",N),x("获取失败")}const v=JSON.parse(JSON.stringify(UC));n(v),c(!1)})()},[]);const h=m.useMemo(()=>[{questionId:"maibot_version",value:u}],[u]),f=m.useCallback(g=>{console.log("MaiBot Survey submitted:",g)},[]),p=m.useCallback(g=>{console.error("MaiBot Survey submission error:",g)},[]);return i?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(Js,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):l?e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 shrink-0",children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(wj,{className:"h-8 w-8",strokeWidth:2}),"麦麦使用体验反馈问卷"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"感谢您的反馈,帮助我们打造更好的 AI 伙伴"})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Dv,{config:l,initialAnswers:h,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:f,onSubmitError:p})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(gt,{variant:"destructive",className:"max-w-md",children:[e.jsx(Dt,{className:"h-4 w-4"}),e.jsx(jt,{children:"无法加载问卷配置"})]}),e.jsx(k,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}var Fo="DropdownMenu",[HC]=Do(Fo,[Ig]),Wt=Ig(),[IC,Ov]=HC(Fo),Rv=l=>{const{__scopeDropdownMenu:n,children:i,dir:c,open:u,defaultOpen:x,onOpenChange:h,modal:f=!0}=l,p=Wt(n),g=m.useRef(null),[v,N]=zo({prop:u,defaultProp:x??!1,onChange:h,caller:Fo});return e.jsx(IC,{scope:n,triggerId:wm(),triggerRef:g,contentId:wm(),open:v,onOpenChange:N,onOpenToggle:m.useCallback(()=>N(y=>!y),[N]),modal:f,children:e.jsx(R0,{...p,open:v,onOpenChange:N,dir:c,modal:f,children:i})})};Rv.displayName=Fo;var Lv="DropdownMenuTrigger",Uv=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,disabled:c=!1,...u}=l,x=Ov(Lv,i),h=Wt(i);return e.jsx(L0,{asChild:!0,...h,children:e.jsx(An.button,{type:"button",id:x.triggerId,"aria-haspopup":"menu","aria-expanded":x.open,"aria-controls":x.open?x.contentId:void 0,"data-state":x.open?"open":"closed","data-disabled":c?"":void 0,disabled:c,...u,ref:mw(n,x.triggerRef),onPointerDown:Zl(l.onPointerDown,f=>{!c&&f.button===0&&f.ctrlKey===!1&&(x.onOpenToggle(),x.open||f.preventDefault())}),onKeyDown:Zl(l.onKeyDown,f=>{c||(["Enter"," "].includes(f.key)&&x.onOpenToggle(),f.key==="ArrowDown"&&x.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(f.key)&&f.preventDefault())})})})});Uv.displayName=Lv;var PC="DropdownMenuPortal",Bv=l=>{const{__scopeDropdownMenu:n,...i}=l,c=Wt(n);return e.jsx(k0,{...c,...i})};Bv.displayName=PC;var $v="DropdownMenuContent",Hv=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Ov($v,i),x=Wt(i),h=m.useRef(!1);return e.jsx(T0,{id:u.contentId,"aria-labelledby":u.triggerId,...x,...c,ref:n,onCloseAutoFocus:Zl(l.onCloseAutoFocus,f=>{h.current||u.triggerRef.current?.focus(),h.current=!1,f.preventDefault()}),onInteractOutside:Zl(l.onInteractOutside,f=>{const p=f.detail.originalEvent,g=p.button===0&&p.ctrlKey===!0,v=p.button===2||g;(!u.modal||v)&&(h.current=!0)}),style:{...l.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Hv.displayName=$v;var GC="DropdownMenuGroup",qC=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Wt(i);return e.jsx(U0,{...u,...c,ref:n})});qC.displayName=GC;var FC="DropdownMenuLabel",Iv=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Wt(i);return e.jsx(D0,{...u,...c,ref:n})});Iv.displayName=FC;var VC="DropdownMenuItem",Pv=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Wt(i);return e.jsx(E0,{...u,...c,ref:n})});Pv.displayName=VC;var KC="DropdownMenuCheckboxItem",Gv=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Wt(i);return e.jsx(M0,{...u,...c,ref:n})});Gv.displayName=KC;var QC="DropdownMenuRadioGroup",YC=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Wt(i);return e.jsx(B0,{...u,...c,ref:n})});YC.displayName=QC;var JC="DropdownMenuRadioItem",qv=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Wt(i);return e.jsx(z0,{...u,...c,ref:n})});qv.displayName=JC;var XC="DropdownMenuItemIndicator",Fv=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Wt(i);return e.jsx(A0,{...u,...c,ref:n})});Fv.displayName=XC;var ZC="DropdownMenuSeparator",Vv=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Wt(i);return e.jsx(O0,{...u,...c,ref:n})});Vv.displayName=ZC;var WC="DropdownMenuArrow",ek=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Wt(i);return e.jsx($0,{...u,...c,ref:n})});ek.displayName=WC;var sk="DropdownMenuSubTrigger",Kv=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Wt(i);return e.jsx(S0,{...u,...c,ref:n})});Kv.displayName=sk;var tk="DropdownMenuSubContent",Qv=m.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=Wt(i);return e.jsx(C0,{...u,...c,ref:n,style:{...l.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Qv.displayName=tk;var ak=Rv,lk=Uv,nk=Bv,Yv=Hv,Jv=Iv,Xv=Pv,Zv=Gv,Wv=qv,eN=Fv,sN=Vv,tN=Kv,aN=Qv;const rk=ak,ik=lk,ck=m.forwardRef(({className:l,inset:n,children:i,...c},u)=>e.jsxs(tN,{ref:u,className:B("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",n&&"pl-8",l),...c,children:[i,e.jsx(ba,{className:"ml-auto h-4 w-4"})]}));ck.displayName=tN.displayName;const ok=m.forwardRef(({className:l,...n},i)=>e.jsx(aN,{ref:i,className:B("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",l),...n}));ok.displayName=aN.displayName;const lN=m.forwardRef(({className:l,sideOffset:n=4,...i},c)=>e.jsx(nk,{children:e.jsx(Yv,{ref:c,sideOffset:n,className:B("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",l),...i})}));lN.displayName=Yv.displayName;const nN=m.forwardRef(({className:l,inset:n,...i},c)=>e.jsx(Xv,{ref:c,className:B("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n&&"pl-8",l),...i}));nN.displayName=Xv.displayName;const dk=m.forwardRef(({className:l,children:n,checked:i,...c},u)=>e.jsxs(Zv,{ref:u,className:B("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",l),checked:i,...c,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(eN,{children:e.jsx(_t,{className:"h-4 w-4"})})}),n]}));dk.displayName=Zv.displayName;const uk=m.forwardRef(({className:l,children:n,...i},c)=>e.jsxs(Wv,{ref:c,className:B("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",l),...i,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(eN,{children:e.jsx(yj,{className:"h-2 w-2 fill-current"})})}),n]}));uk.displayName=Wv.displayName;const mk=m.forwardRef(({className:l,inset:n,...i},c)=>e.jsx(Jv,{ref:c,className:B("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",l),...i}));mk.displayName=Jv.displayName;const xk=m.forwardRef(({className:l,...n},i)=>e.jsx(sN,{ref:i,className:B("-mx-1 my-1 h-px bg-muted",l),...n}));xk.displayName=sN.displayName;const rN=({className:l,...n})=>e.jsx("nav",{role:"navigation","aria-label":"pagination",className:B("mx-auto flex w-full justify-center",l),...n});rN.displayName="Pagination";const iN=m.forwardRef(({className:l,...n},i)=>e.jsx("ul",{ref:i,className:B("flex flex-row items-center gap-1",l),...n}));iN.displayName="PaginationContent";const wo=m.forwardRef(({className:l,...n},i)=>e.jsx("li",{ref:i,className:B("",l),...n}));wo.displayName="PaginationItem";const Vo=({className:l,isActive:n,size:i="icon",...c})=>e.jsx("a",{"aria-current":n?"page":void 0,className:B(Mr({variant:n?"outline":"ghost",size:i}),l),...c});Vo.displayName="PaginationLink";const cN=({className:l,...n})=>e.jsxs(Vo,{"aria-label":"Go to previous page",size:"default",className:B("gap-1 pl-2.5",l),...n,children:[e.jsx(Wa,{className:"h-4 w-4"}),e.jsx("span",{children:"上一页"})]});cN.displayName="PaginationPrevious";const oN=({className:l,...n})=>e.jsxs(Vo,{"aria-label":"Go to next page",size:"default",className:B("gap-1 pr-2.5",l),...n,children:[e.jsx("span",{children:"下一页"}),e.jsx(ba,{className:"h-4 w-4"})]});oN.displayName="PaginationNext";const ym=[{value:"created_at",label:"最新发布",icon:Nl},{value:"downloads",label:"下载最多",icon:Yt},{value:"likes",label:"最受欢迎",icon:So}];function hk(){const l=ua(),[n,i]=m.useState([]),[c,u]=m.useState(!0),[x,h]=m.useState(""),[f,p]=m.useState("downloads"),[g,v]=m.useState(1),[N,y]=m.useState(1),[w,b]=m.useState(0),[L,D]=m.useState(new Set),[T,F]=m.useState(new Set),O=rv(),S=m.useCallback(async()=>{u(!0);try{const G=await T_({status:"approved",page:g,page_size:12,search:x||void 0,sort_by:f,sort_order:"desc"});i(G.packs),y(G.total_pages),b(G.total);const ce=new Set;for(const de of G.packs)await nv(de.id,O)&&ce.add(de.id);D(ce)}catch(G){console.error("加载 Pack 列表失败:",G),Ft({title:"加载 Pack 列表失败",variant:"destructive"})}finally{u(!1)}},[g,x,f,O]);m.useEffect(()=>{S()},[S]);const C=G=>{G.preventDefault(),v(1),S()},P=async G=>{if(!T.has(G)){F(ce=>new Set(ce).add(G));try{const ce=await lv(G,O);D(de=>{const be=new Set(de);return ce.liked?be.add(G):be.delete(G),be}),i(de=>de.map(be=>be.id===G?{...be,likes:ce.likes}:be))}catch(ce){console.error("点赞失败:",ce),Ft({title:"点赞失败",variant:"destructive"})}finally{F(ce=>{const de=new Set(ce);return de.delete(G),de})}}},M=G=>{l({to:"/config/pack-market/$packId",params:{packId:G}})},Z=ym.find(G=>G.value===f)||ym[0];return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsx("div",{className:"mb-4 sm:mb-6",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(ca,{className:"h-8 w-8",strokeWidth:2}),"配置模板市场"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"浏览和应用社区分享的模型配置模板,快速配置你的 MaiBot"})]}),e.jsxs(k,{variant:"outline",onClick:S,disabled:c,className:"gap-2",children:[e.jsx(zt,{className:`h-4 w-4 ${c?"animate-spin":""}`}),"刷新"]})]})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-4 flex-wrap",children:[e.jsx("form",{onSubmit:C,className:"flex-1 min-w-[200px] max-w-md",children:e.jsxs("div",{className:"relative",children:[e.jsx(Vt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(re,{placeholder:"搜索模板名称、描述...",value:x,onChange:G=>h(G.target.value),className:"pl-10"})]})}),e.jsxs(rk,{children:[e.jsx(ik,{asChild:!0,children:e.jsxs(k,{variant:"outline",className:"min-w-[140px] gap-2",children:[e.jsx(qw,{className:"w-4 h-4"}),Z.label,e.jsx(Oa,{className:"w-4 h-4 ml-auto"})]})}),e.jsx(lN,{align:"end",children:ym.map(G=>e.jsxs(nN,{onClick:()=>{p(G.value),v(1)},children:[e.jsx(G.icon,{className:"w-4 h-4 mr-2"}),G.label]},G.value))})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共找到 ",e.jsx("span",{className:"font-medium text-foreground",children:w})," 个模板"]}),c?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((G,ce)=>e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(Qs,{className:"h-6 w-3/4"}),e.jsx(Qs,{className:"h-4 w-full mt-2"})]}),e.jsx(Ye,{children:e.jsx(Qs,{className:"h-20 w-full"})}),e.jsx(Lo,{children:e.jsx(Qs,{className:"h-9 w-full"})})]},ce))}):n.length===0?e.jsx(ze,{className:"py-12",children:e.jsxs(Ye,{className:"text-center text-muted-foreground",children:[e.jsx(ca,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{className:"text-lg font-medium",children:"暂无模板"}),e.jsx("p",{className:"mt-1",children:"还没有人分享配置模板,快来分享第一个吧!"})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:n.map(G=>e.jsx(fk,{pack:G,liked:L.has(G.id),liking:T.has(G.id),onLike:()=>P(G.id),onView:()=>M(G.id)},G.id))}),N>1&&e.jsx(rN,{children:e.jsxs(iN,{children:[e.jsx(wo,{children:e.jsx(cN,{onClick:()=>v(G=>Math.max(1,G-1)),className:g===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:N},(G,ce)=>ce+1).filter(G=>G===1||G===N||Math.abs(G-g)<=1).map((G,ce,de)=>{const be=ce>0&&G-de[ce-1]>1;return e.jsxs(wo,{children:[be&&e.jsx("span",{className:"px-2",children:"..."}),e.jsx(Vo,{onClick:()=>v(G),isActive:G===g,className:"cursor-pointer",children:G})]},G)}),e.jsx(wo,{children:e.jsx(oN,{onClick:()=>v(G=>Math.min(N,G+1)),className:g===N?"pointer-events-none opacity-50":"cursor-pointer"})})]})})]})})]})}function fk({pack:l,liked:n,liking:i,onLike:c,onView:u}){const x=h=>new Date(h).toLocaleDateString("zh-CN",{year:"numeric",month:"short",day:"numeric"});return e.jsxs(ze,{className:"flex flex-col hover:shadow-md transition-shadow",children:[e.jsxs(ts,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx(ls,{className:"text-lg line-clamp-1",children:l.name}),e.jsxs(Te,{variant:"secondary",className:"text-xs",children:["v",l.version]})]}),e.jsx(Vs,{className:"line-clamp-2 min-h-[40px]",children:l.description})]}),e.jsxs(Ye,{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(kr,{className:"w-3.5 h-3.5"}),l.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Nl,{className:"w-3.5 h-3.5"}),x(l.created_at)]})]}),e.jsxs("div",{className:"flex gap-4 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"提供商数量",children:[e.jsx(yl,{className:"w-3.5 h-3.5"}),l.provider_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"模型数量",children:[e.jsx(kn,{className:"w-3.5 h-3.5"}),l.model_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"任务配置数",children:[e.jsx(Tn,{className:"w-3.5 h-3.5"}),l.task_count]})]}),l.tags&&l.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[l.tags.slice(0,3).map(h=>e.jsxs(Te,{variant:"outline",className:"text-xs",children:[e.jsx(Rm,{className:"w-2.5 h-2.5 mr-1"}),h]},h)),l.tags.length>3&&e.jsxs(Te,{variant:"outline",className:"text-xs",children:["+",l.tags.length-3]})]})]}),e.jsx(Lo,{className:"pt-3 border-t",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-3 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Yt,{className:"w-4 h-4"}),l.downloads]}),e.jsxs("button",{onClick:h=>{h.stopPropagation(),c()},disabled:i,className:`flex items-center gap-1 transition-colors ${n?"text-red-500":"hover:text-red-500"} ${i?"opacity-50":""}`,children:[e.jsx(So,{className:`w-4 h-4 ${n?"fill-current":""}`}),l.likes]})]}),e.jsx(k,{size:"sm",onClick:u,children:"查看详情"})]})})]})}var Pa="Accordion",pk=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[Qm,gk,jk]=xw(Pa),[Ko]=Do(Pa,[jk,Pg]),Ym=Pg(),dN=Ts.forwardRef((l,n)=>{const{type:i,...c}=l,u=c,x=c;return e.jsx(Qm.Provider,{scope:l.__scopeAccordion,children:i==="multiple"?e.jsx(yk,{...x,ref:n}):e.jsx(bk,{...u,ref:n})})});dN.displayName=Pa;var[uN,vk]=Ko(Pa),[mN,Nk]=Ko(Pa,{collapsible:!1}),bk=Ts.forwardRef((l,n)=>{const{value:i,defaultValue:c,onValueChange:u=()=>{},collapsible:x=!1,...h}=l,[f,p]=zo({prop:i,defaultProp:c??"",onChange:u,caller:Pa});return e.jsx(uN,{scope:l.__scopeAccordion,value:Ts.useMemo(()=>f?[f]:[],[f]),onItemOpen:p,onItemClose:Ts.useCallback(()=>x&&p(""),[x,p]),children:e.jsx(mN,{scope:l.__scopeAccordion,collapsible:x,children:e.jsx(xN,{...h,ref:n})})})}),yk=Ts.forwardRef((l,n)=>{const{value:i,defaultValue:c,onValueChange:u=()=>{},...x}=l,[h,f]=zo({prop:i,defaultProp:c??[],onChange:u,caller:Pa}),p=Ts.useCallback(v=>f((N=[])=>[...N,v]),[f]),g=Ts.useCallback(v=>f((N=[])=>N.filter(y=>y!==v)),[f]);return e.jsx(uN,{scope:l.__scopeAccordion,value:h,onItemOpen:p,onItemClose:g,children:e.jsx(mN,{scope:l.__scopeAccordion,collapsible:!0,children:e.jsx(xN,{...x,ref:n})})})}),[wk,Qo]=Ko(Pa),xN=Ts.forwardRef((l,n)=>{const{__scopeAccordion:i,disabled:c,dir:u,orientation:x="vertical",...h}=l,f=Ts.useRef(null),p=Oo(f,n),g=gk(i),N=tj(u)==="ltr",y=Zl(l.onKeyDown,w=>{if(!pk.includes(w.key))return;const b=w.target,L=g().filter(Z=>!Z.ref.current?.disabled),D=L.findIndex(Z=>Z.ref.current===b),T=L.length;if(D===-1)return;w.preventDefault();let F=D;const O=0,S=T-1,C=()=>{F=D+1,F>S&&(F=O)},P=()=>{F=D-1,F{const{__scopeAccordion:i,value:c,...u}=l,x=Qo(Ao,i),h=vk(Ao,i),f=Ym(i),p=wm(),g=c&&h.value.includes(c)||!1,v=x.disabled||l.disabled;return e.jsx(_k,{scope:i,open:g,disabled:v,triggerId:p,children:e.jsx(Lg,{"data-orientation":x.orientation,"data-state":NN(g),...f,...u,ref:n,disabled:v,open:g,onOpenChange:N=>{N?h.onItemOpen(c):h.onItemClose(c)}})})});hN.displayName=Ao;var fN="AccordionHeader",pN=Ts.forwardRef((l,n)=>{const{__scopeAccordion:i,...c}=l,u=Qo(Pa,i),x=Jm(fN,i);return e.jsx(An.h3,{"data-orientation":u.orientation,"data-state":NN(x.open),"data-disabled":x.disabled?"":void 0,...c,ref:n})});pN.displayName=fN;var Mm="AccordionTrigger",gN=Ts.forwardRef((l,n)=>{const{__scopeAccordion:i,...c}=l,u=Qo(Pa,i),x=Jm(Mm,i),h=Nk(Mm,i),f=Ym(i);return e.jsx(Qm.ItemSlot,{scope:i,children:e.jsx(H0,{"aria-disabled":x.open&&!h.collapsible||void 0,"data-orientation":u.orientation,id:x.triggerId,...f,...c,ref:n})})});gN.displayName=Mm;var jN="AccordionContent",vN=Ts.forwardRef((l,n)=>{const{__scopeAccordion:i,...c}=l,u=Qo(Pa,i),x=Jm(jN,i),h=Ym(i);return e.jsx(I0,{role:"region","aria-labelledby":x.triggerId,"data-orientation":u.orientation,...h,...c,ref:n,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...l.style}})});vN.displayName=jN;function NN(l){return l?"open":"closed"}var Sk=dN,Ck=hN,kk=pN,bN=gN,yN=vN;const Tk=Sk,wN=m.forwardRef(({className:l,...n},i)=>e.jsx(Ck,{ref:i,className:B("border-b",l),...n}));wN.displayName="AccordionItem";const _N=m.forwardRef(({className:l,children:n,...i},c)=>e.jsx(kk,{className:"flex",children:e.jsxs(bN,{ref:c,className:B("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",l),...i,children:[n,e.jsx(Oa,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));_N.displayName=bN.displayName;const SN=m.forwardRef(({className:l,children:n,...i},c)=>e.jsx(yN,{ref:c,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...i,children:e.jsx("div",{className:B("pb-4 pt-0",l),children:n})}));SN.displayName=yN.displayName;const Ek={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",lpmm_qa:"问答模型"};function Mk(){const{packId:l}=MN.useParams(),n=ua(),[i,c]=m.useState(null),[u,x]=m.useState(!0),[h,f]=m.useState(!1),[p,g]=m.useState(!1),[v,N]=m.useState(!1),[y,w]=m.useState(1),[b,L]=m.useState(null),[D,T]=m.useState(!1),[F,O]=m.useState(!1),[S,C]=m.useState({apply_providers:!0,apply_models:!0,apply_task_config:!0,task_mode:"append",selected_providers:void 0,selected_models:void 0,selected_tasks:void 0}),[P,M]=m.useState({}),[Z,G]=m.useState({}),ce=rv(),de=m.useCallback(async()=>{if(l){x(!0);try{const A=await E_(l);c(A);const Y=await nv(l,ce);f(Y)}catch(A){console.error("加载 Pack 失败:",A),Ft({title:"加载模板失败",variant:"destructive"})}finally{x(!1)}}},[l,ce]);m.useEffect(()=>{de()},[de]);const be=async()=>{if(!(!l||p)){g(!0);try{const A=await lv(l,ce);f(A.liked),i&&c({...i,likes:A.likes})}catch(A){console.error("点赞失败:",A),Ft({title:"点赞失败",variant:"destructive"})}finally{g(!1)}}},me=async()=>{if(i){N(!0),w(1),T(!0);try{const A=await z_(i);L(A);const Y={};for(const U of A.existing_providers)Y[U.pack_provider.name]=U.local_providers[0].name;M(Y);const H={};for(const U of A.new_providers)H[U.name]="";G(H)}catch(A){console.error("检测冲突失败:",A),Ft({title:"检测配置冲突失败",variant:"destructive"}),N(!1)}finally{T(!1)}}},pe=async()=>{if(i){if(S.apply_providers&&b){for(const A of b.new_providers)if(!Z[A.name]){Ft({title:`请填写提供商 "${A.name}" 的 API Key`,variant:"destructive"});return}}O(!0);try{await D_(i,S,P,Z),await A_(i.id,ce),c({...i,downloads:i.downloads+1}),Ft({title:"配置模板应用成功!"}),N(!1)}catch(A){console.error("应用 Pack 失败:",A),Ft({title:A instanceof Error?A.message:"应用配置失败",variant:"destructive"})}finally{O(!1)}}},je=A=>new Date(A).toLocaleDateString("zh-CN",{year:"numeric",month:"long",day:"numeric"});return u?e.jsx(zk,{}):i?e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs(k,{variant:"ghost",size:"sm",onClick:()=>n({to:"/config/pack-market"}),className:"gap-2",children:[e.jsx(en,{className:"w-4 h-4"}),"返回市场"]}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-6",children:[e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ca,{className:"w-10 h-10 text-primary mt-1"}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[i.name,e.jsxs(Te,{variant:"secondary",children:["v",i.version]})]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:i.description})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(kr,{className:"w-4 h-4"}),i.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Nl,{className:"w-4 h-4"}),je(i.created_at)]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Yt,{className:"w-4 h-4"}),i.downloads," 次下载"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(So,{className:`w-4 h-4 ${h?"fill-red-500 text-red-500":""}`}),i.likes," 赞"]})]}),i.tags&&i.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:i.tags.map(A=>e.jsxs(Te,{variant:"outline",children:[e.jsx(Rm,{className:"w-3 h-3 mr-1"}),A]},A))})]}),e.jsxs("div",{className:"flex flex-col gap-2 min-w-[160px]",children:[e.jsxs(k,{size:"lg",onClick:me,children:[e.jsx(Yt,{className:"w-4 h-4 mr-2"}),"应用模板"]}),e.jsxs(k,{variant:"outline",onClick:be,disabled:p,className:h?"text-red-500 border-red-200":"",children:[e.jsx(So,{className:`w-4 h-4 mr-2 ${h?"fill-current":""}`}),h?"已点赞":"点赞"]})]})]}),e.jsx(Or,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(ze,{children:e.jsxs(Ye,{className:"flex items-center gap-3 py-4",children:[e.jsx(yl,{className:"w-8 h-8 text-blue-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:i.providers.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"API 提供商"})]})]})}),e.jsx(ze,{children:e.jsxs(Ye,{className:"flex items-center gap-3 py-4",children:[e.jsx(kn,{className:"w-8 h-8 text-green-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:i.models.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"模型配置"})]})]})}),e.jsx(ze,{children:e.jsxs(Ye,{className:"flex items-center gap-3 py-4",children:[e.jsx(Tn,{className:"w-8 h-8 text-purple-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:Object.keys(i.task_config).length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"任务配置"})]})]})})]}),e.jsxs(da,{defaultValue:"providers",className:"space-y-4",children:[e.jsxs(Zt,{children:[e.jsxs(Xe,{value:"providers",children:[e.jsx(yl,{className:"w-4 h-4 mr-2"}),"提供商 (",i.providers.length,")"]}),e.jsxs(Xe,{value:"models",children:[e.jsx(kn,{className:"w-4 h-4 mr-2"}),"模型 (",i.models.length,")"]}),e.jsxs(Xe,{value:"tasks",children:[e.jsx(Tn,{className:"w-4 h-4 mr-2"}),"任务配置 (",Object.keys(i.task_config).length,")"]})]}),e.jsx(ys,{value:"providers",children:e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"API 提供商"}),e.jsx(Vs,{children:"模板中包含的 API 提供商配置(不含 API Key)"})]}),e.jsx(Ye,{children:e.jsxs(wl,{children:[e.jsx(_l,{children:e.jsxs(nt,{children:[e.jsx(Qe,{children:"名称"}),e.jsx(Qe,{children:"Base URL"}),e.jsx(Qe,{children:"类型"})]})}),e.jsx(Sl,{children:i.providers.map(A=>e.jsxs(nt,{children:[e.jsx(Ie,{className:"font-medium",children:A.name}),e.jsx(Ie,{className:"text-muted-foreground font-mono text-sm",children:A.base_url}),e.jsx(Ie,{children:e.jsx(Te,{variant:"outline",children:A.client_type})})]},A.name))})]})})]})}),e.jsx(ys,{value:"models",children:e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"模型配置"}),e.jsx(Vs,{children:"模板中包含的模型配置"})]}),e.jsx(Ye,{children:e.jsxs(wl,{children:[e.jsx(_l,{children:e.jsxs(nt,{children:[e.jsx(Qe,{children:"模型名称"}),e.jsx(Qe,{children:"标识符"}),e.jsx(Qe,{children:"提供商"}),e.jsx(Qe,{className:"text-right",children:"价格 (入/出)"})]})}),e.jsx(Sl,{children:i.models.map(A=>e.jsxs(nt,{children:[e.jsx(Ie,{className:"font-medium",children:A.name}),e.jsx(Ie,{className:"text-muted-foreground font-mono text-sm",children:A.model_identifier}),e.jsx(Ie,{children:A.api_provider}),e.jsxs(Ie,{className:"text-right text-muted-foreground",children:["¥",A.price_in," / ¥",A.price_out]})]},A.name))})]})})]})}),e.jsx(ys,{value:"tasks",children:e.jsxs(ze,{children:[e.jsxs(ts,{children:[e.jsx(ls,{children:"任务配置"}),e.jsx(Vs,{children:"模板中各任务类型的模型分配"})]}),e.jsx(Ye,{children:e.jsx(Tk,{type:"multiple",className:"w-full",children:Object.entries(i.task_config).map(([A,Y])=>e.jsxs(wN,{value:A,children:[e.jsx(_N,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(zn,{className:"w-4 h-4"}),Ek[A]||A,e.jsxs(Te,{variant:"secondary",className:"ml-2",children:[Y.model_list.length," 个模型"]})]})}),e.jsx(SN,{children:e.jsxs("div",{className:"space-y-2 pl-6",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"分配的模型:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Y.model_list.map(H=>e.jsx(Te,{variant:"outline",children:H},H))}),Y.temperature!==void 0&&e.jsxs("div",{className:"text-sm",children:["Temperature: ",e.jsx("span",{className:"font-mono",children:Y.temperature})]}),Y.max_tokens!==void 0&&e.jsxs("div",{className:"text-sm",children:["Max Tokens: ",e.jsx("span",{className:"font-mono",children:Y.max_tokens})]})]})})]},A))})})]})})]}),e.jsx(Ak,{open:v,onOpenChange:N,pack:i,step:y,setStep:w,conflicts:b,detectingConflicts:D,applying:F,options:S,setOptions:C,_providerMapping:P,_setProviderMapping:M,newProviderApiKeys:Z,setNewProviderApiKeys:G,onApply:pe})]})})}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ca,{className:"w-16 h-16 mx-auto mb-4 opacity-50"}),e.jsx("h2",{className:"text-xl font-semibold",children:"模板不存在"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"该配置模板可能已被删除或尚未通过审核"}),e.jsxs(k,{className:"mt-4",onClick:()=>n({to:"/config/pack-market"}),children:[e.jsx(en,{className:"w-4 h-4 mr-2"}),"返回市场"]})]})}function Ak({open:l,onOpenChange:n,pack:i,step:c,setStep:u,conflicts:x,detectingConflicts:h,applying:f,options:p,setOptions:g,_providerMapping:v,_setProviderMapping:N,newProviderApiKeys:y,setNewProviderApiKeys:w,onApply:b}){return e.jsx(Is,{open:l,onOpenChange:n,children:e.jsxs(Rs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ls,{children:[e.jsxs(Us,{className:"flex items-center gap-2",children:[e.jsx(ca,{className:"w-5 h-5"}),"应用配置模板"]}),e.jsxs(Zs,{children:["步骤 ",c," / ",3,":",c===1&&"选择要应用的内容",c===2&&"配置提供商映射",c===3&&"确认并应用"]})]}),h?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(Js,{className:"w-8 h-8 mx-auto animate-spin text-primary"}),e.jsx("p",{className:"mt-4 text-muted-foreground",children:"正在检测配置冲突..."})]}):e.jsxs(e.Fragment,{children:[c===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xs,{id:"apply_providers",checked:p.apply_providers,onCheckedChange:D=>g({...p,apply_providers:D})}),e.jsxs(E,{htmlFor:"apply_providers",className:"flex items-center gap-2",children:[e.jsx(yl,{className:"w-4 h-4"}),"应用提供商配置 (",i.providers.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xs,{id:"apply_models",checked:p.apply_models,onCheckedChange:D=>g({...p,apply_models:D})}),e.jsxs(E,{htmlFor:"apply_models",className:"flex items-center gap-2",children:[e.jsx(kn,{className:"w-4 h-4"}),"应用模型配置 (",i.models.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xs,{id:"apply_task_config",checked:p.apply_task_config,onCheckedChange:D=>g({...p,apply_task_config:D})}),e.jsxs(E,{htmlFor:"apply_task_config",className:"flex items-center gap-2",children:[e.jsx(Tn,{className:"w-4 h-4"}),"应用任务配置 (",Object.keys(i.task_config).length," 个)"]})]})]}),p.apply_task_config&&e.jsxs("div",{className:"pl-6 space-y-2 border-l-2 border-muted",children:[e.jsx(E,{className:"text-sm font-medium",children:"任务配置应用模式"}),e.jsxs(Km,{value:p.task_mode,onValueChange:D=>g({...p,task_mode:D}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Mo,{value:"append",id:"mode_append"}),e.jsx(E,{htmlFor:"mode_append",className:"font-normal",children:"追加模式 - 将模板中的模型添加到现有配置"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Mo,{value:"replace",id:"mode_replace"}),e.jsx(E,{htmlFor:"mode_replace",className:"font-normal",children:"替换模式 - 用模板配置完全替换现有配置"})]})]})]})]}),c===2&&x&&e.jsxs("div",{className:"space-y-4",children:[p.apply_providers&&x.existing_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(gt,{children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsx(_n,{children:"发现已有的提供商"}),e.jsx(jt,{children:"以下提供商的 URL 与您本地配置中的提供商匹配,将自动使用本地提供商:"})]}),e.jsx("div",{className:"space-y-2",children:x.existing_providers.map(({pack_provider:D,local_providers:T})=>e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-lg",children:[e.jsx(_t,{className:"w-4 h-4 text-green-500 flex-shrink-0"}),e.jsx("span",{className:"font-medium flex-shrink-0",children:D.name}),e.jsx(ba,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),T.length===1?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground",children:T[0].name}),e.jsx(Te,{variant:"outline",className:"ml-auto",children:"URL 匹配"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Le,{value:v[D.name]||T[0].name,onValueChange:F=>N({...v,[D.name]:F}),children:[e.jsx(Oe,{className:"w-[200px]",children:e.jsx(Ue,{})}),e.jsx(Re,{children:T.map(F=>e.jsx(le,{value:F.name,children:F.name},F.name))})]}),e.jsxs(Te,{variant:"outline",className:"ml-auto",children:[T.length," 个匹配"]})]})]},D.name))})]}),p.apply_providers&&x.new_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(gt,{variant:"destructive",children:[e.jsx(Qt,{className:"h-4 w-4"}),e.jsx(_n,{children:"需要配置 API Key"}),e.jsx(jt,{children:"以下提供商在您的本地配置中不存在,需要填写 API Key:"})]}),e.jsx("div",{className:"space-y-4",children:x.new_providers.map(D=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Am,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"font-medium",children:D.name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",D.base_url,")"]})]}),e.jsx(re,{type:"password",placeholder:`输入 ${D.name} 的 API Key`,value:y[D.name]||"",onChange:T=>w({...y,[D.name]:T.target.value})})]},D.name))})]}),(!p.apply_providers||x.existing_providers.length===0&&x.new_providers.length===0)&&e.jsxs(gt,{children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsx(_n,{children:"无需配置"}),e.jsx(jt,{children:"模板中没有提供商配置,或您选择不应用提供商。"})]})]}),c===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(gt,{children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsx(_n,{children:"确认应用"}),e.jsx(jt,{children:"请确认以下将要应用的内容:"})]}),e.jsxs("div",{className:"space-y-2",children:[p.apply_providers&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(_t,{className:"w-4 h-4 text-green-500"}),e.jsx(yl,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",i.providers.length," 个提供商配置"]})]}),p.apply_models&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(_t,{className:"w-4 h-4 text-green-500"}),e.jsx(kn,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",i.models.length," 个模型配置"]})]}),p.apply_task_config&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(_t,{className:"w-4 h-4 text-green-500"}),e.jsx(Tn,{className:"w-4 h-4"}),e.jsxs("span",{children:[p.task_mode==="append"?"追加":"替换"," ",Object.keys(i.task_config).length," 个任务配置"]})]})]}),x&&x.new_providers.length>0&&e.jsxs(gt,{variant:"destructive",children:[e.jsx(Qt,{className:"h-4 w-4"}),e.jsxs(jt,{children:["将添加 ",x.new_providers.length," 个新提供商,请确保已填写正确的 API Key。"]})]})]})]}),e.jsxs(rt,{className:"flex justify-between",children:[e.jsx("div",{children:c>1&&!h&&e.jsx(k,{variant:"outline",onClick:()=>u(c-1),disabled:f,children:"上一步"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{variant:"outline",onClick:()=>n(!1),disabled:f,children:"取消"}),c<3?e.jsx(k,{onClick:()=>u(c+1),disabled:h,children:"下一步"}):e.jsxs(k,{onClick:b,disabled:f,children:[f&&e.jsx(Js,{className:"w-4 h-4 mr-2 animate-spin"}),"应用模板"]})]})]})]})})}function zk(){return e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(Qs,{className:"h-9 w-24"}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-6",children:[e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Qs,{className:"w-10 h-10"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(Qs,{className:"h-8 w-2/3"}),e.jsx(Qs,{className:"h-4 w-full"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsx(Qs,{className:"h-4 w-24"}),e.jsx(Qs,{className:"h-4 w-32"}),e.jsx(Qs,{className:"h-4 w-28"}),e.jsx(Qs,{className:"h-4 w-20"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(Qs,{className:"h-6 w-20"}),e.jsx(Qs,{className:"h-6 w-24"}),e.jsx(Qs,{className:"h-6 w-16"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 min-w-[160px]",children:[e.jsx(Qs,{className:"h-10 w-full"}),e.jsx(Qs,{className:"h-10 w-full"})]})]}),e.jsx(Qs,{className:"h-px w-full"}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(Qs,{className:"h-24"}),e.jsx(Qs,{className:"h-24"}),e.jsx(Qs,{className:"h-24"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Qs,{className:"h-10 w-32"}),e.jsx(Qs,{className:"h-10 w-32"}),e.jsx(Qs,{className:"h-10 w-32"})]}),e.jsx(Qs,{className:"h-96 w-full"})]})]})})})}function Dk(){const l=ua(),[n,i]=m.useState(!0);return m.useEffect(()=>{let c=!1;return(async()=>{try{const x=await Hi();!c&&!x&&l({to:"/auth"})}catch{c||l({to:"/auth"})}finally{c||i(!1)}})(),()=>{c=!0}},[l]),{checking:n}}async function Ok(){return await Hi()}const Rk=Ar("pointer-events-none inline-flex select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono font-medium opacity-100",{variants:{size:{sm:"h-5 text-[10px]",default:"h-6 text-xs",lg:"h-7 text-sm"}},defaultVariants:{size:"default"}}),CN=m.forwardRef(({className:l,size:n,abbrTitle:i,children:c,...u},x)=>e.jsx("kbd",{className:B(Rk({size:n,className:l})),ref:x,...u,children:i?e.jsx("abbr",{title:i,children:c}):c}));CN.displayName="Kbd";const Lk=[{icon:Ro,title:"首页",description:"查看仪表板概览",path:"/",category:"概览"},{icon:Ha,title:"麦麦主程序配置",description:"配置麦麦的核心设置",path:"/config/bot",category:"配置"},{icon:yl,title:"麦麦模型提供商配置",description:"配置模型提供商",path:"/config/modelProvider",category:"配置"},{icon:_j,title:"麦麦模型配置",description:"配置模型参数",path:"/config/model",category:"配置"},{icon:zm,title:"表情包管理",description:"管理麦麦的表情包",path:"/resource/emoji",category:"资源"},{icon:Wl,title:"表达方式管理",description:"管理麦麦的表达方式",path:"/resource/expression",category:"资源"},{icon:Sj,title:"人物信息管理",description:"管理人物信息",path:"/resource/person",category:"资源"},{icon:Er,title:"黑话管理",description:"管理麦麦学习到的黑话和俚语",path:"/resource/jargon",category:"资源"},{icon:Fw,title:"统计信息",description:"查看使用统计",path:"/statistics",category:"监控"},{icon:ca,title:"插件市场",description:"浏览和安装插件",path:"/plugins",category:"扩展"},{icon:Dm,title:"日志查看器",description:"查看系统日志",path:"/logs",category:"监控"},{icon:zn,title:"系统设置",description:"配置系统参数",path:"/settings",category:"系统"}];function Uk({open:l,onOpenChange:n}){const[i,c]=m.useState(""),[u,x]=m.useState(0),h=ua(),f=Lk.filter(v=>v.title.toLowerCase().includes(i.toLowerCase())||v.description.toLowerCase().includes(i.toLowerCase())||v.category.toLowerCase().includes(i.toLowerCase())),p=m.useCallback(v=>{h({to:v}),n(!1),c(""),x(0)},[h,n]),g=m.useCallback(v=>{v.key==="ArrowDown"?(v.preventDefault(),x(N=>(N+1)%f.length)):v.key==="ArrowUp"?(v.preventDefault(),x(N=>(N-1+f.length)%f.length)):v.key==="Enter"&&f[u]&&(v.preventDefault(),p(f[u].path))},[f,u,p]);return e.jsx(Is,{open:l,onOpenChange:n,children:e.jsxs(Rs,{className:"max-w-2xl p-0 gap-0",children:[e.jsxs(Ls,{className:"px-4 pt-4 pb-0",children:[e.jsx(Us,{className:"sr-only",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx(Vt,{className:"absolute left-3 top-1/2 h-5 w-5 -translate-y-1/2 text-muted-foreground"}),e.jsx(re,{value:i,onChange:v=>{c(v.target.value),x(0)},onKeyDown:g,placeholder:"搜索页面...",className:"h-12 pl-11 text-base border-0 focus-visible:ring-0 shadow-none",autoFocus:!0})]})]}),e.jsx("div",{className:"border-t",children:e.jsx(Je,{className:"h-[400px]",children:f.length>0?e.jsx("div",{className:"p-2",children:f.map((v,N)=>{const y=v.icon;return e.jsxs("button",{onClick:()=>p(v.path),onMouseEnter:()=>x(N),className:B("w-full flex items-center gap-3 px-3 py-2.5 rounded-md text-left transition-colors",N===u?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[e.jsx(y,{className:"h-5 w-5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:v.title}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:v.description})]}),e.jsx("div",{className:"text-xs text-muted-foreground px-2 py-1 bg-muted rounded",children:v.category})]},v.path)})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(Vt,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i?"未找到匹配的页面":"输入关键词开始搜索"})]})})}),e.jsx("div",{className:"border-t px-4 py-3 flex items-center justify-between text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↑"}),e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↓"}),"导航"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Enter"}),"选择"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Esc"}),"关闭"]})]})})]})})}function Bk(){const l=window.location.protocol==="http:",n=window.location.hostname.toLowerCase(),i=n==="localhost"||n==="127.0.0.1"||n==="::1",c=sessionStorage.getItem("http-warning-dismissed")==="true",[u,x]=m.useState(l&&!i&&!c),[h,f]=m.useState(!1),p=()=>{f(!0),x(!1),sessionStorage.setItem("http-warning-dismissed","true")};return!u||h?null:e.jsx("div",{className:"relative bg-amber-500/10 border-b border-amber-500/20 backdrop-blur-sm",children:e.jsx("div",{className:"container mx-auto px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx(Qt,{className:"h-5 w-5 text-amber-600 dark:text-amber-500 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("p",{className:"text-sm font-medium text-amber-900 dark:text-amber-100",children:[e.jsx("span",{className:"font-semibold",children:"安全警告:"}),"您正在使用 ",e.jsx("strong",{children:"HTTP"})," 访问 MaiBot WebUI"]}),e.jsx("p",{className:"text-xs text-amber-800 dark:text-amber-200 mt-1",children:"如果这是公网服务器,您的数据(包括 Token、聊天记录等)可能在传输过程中被窃取。强烈建议使用 HTTPS 访问或仅在本地网络使用。"})]})]}),e.jsx(k,{variant:"ghost",size:"icon",onClick:p,className:"h-8 w-8 text-amber-700 hover:text-amber-900 dark:text-amber-400 dark:hover:text-amber-200 flex-shrink-0","aria-label":"关闭警告",children:e.jsx(Da,{className:"h-4 w-4"})})]})})})}function $k(){const[l,n]=m.useState(0),[i,c]=m.useState(!1),u=m.useRef(null);m.useEffect(()=>{const g=v=>{const N=v.target;if(N.scrollHeight>N.clientHeight+100){u.current=N;const y=N.scrollTop,w=N.scrollHeight-N.clientHeight,b=w>0?y/w*100:0;n(b),c(y>300)}};return window.addEventListener("scroll",g,{capture:!0,passive:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})},[]);const x=()=>{u.current?.scrollTo({top:0,behavior:"smooth"})},h=18,f=2*Math.PI*h,p=f-l/100*f;return e.jsx("div",{className:B("fixed bottom-24 right-8 z-50 transition-all duration-500 ease-in-out transform",i?"translate-x-0 opacity-100":"translate-x-32 opacity-0 pointer-events-none"),children:e.jsxs(k,{variant:"outline",size:"icon",className:B("relative h-12 w-12 rounded-full shadow-xl","bg-background/80 backdrop-blur-md border-border/50","hover:bg-accent hover:scale-110 hover:shadow-2xl hover:border-primary/50","transition-all duration-300","group"),onClick:x,"aria-label":"回到顶部",children:[e.jsxs("svg",{className:"absolute inset-0 h-full w-full -rotate-90 transform p-1",viewBox:"0 0 44 44",children:[e.jsx("circle",{className:"text-muted-foreground/10",strokeWidth:"3",stroke:"currentColor",fill:"transparent",r:h,cx:"22",cy:"22"}),e.jsx("circle",{className:"text-primary transition-all duration-100 ease-out",strokeWidth:"3",strokeDasharray:f,strokeDashoffset:p,strokeLinecap:"round",stroke:"currentColor",fill:"transparent",r:h,cx:"22",cy:"22"})]}),e.jsx(Vw,{className:"h-5 w-5 text-primary transition-transform duration-300 group-hover:-translate-y-1 group-hover:scale-110",strokeWidth:2.5}),e.jsx("div",{className:"absolute inset-0 rounded-full bg-primary/5 opacity-0 group-hover:opacity-100 transition-opacity duration-300"})]})})}const Hk=fw,Ik=pw,Pk=gw,kN=m.forwardRef(({className:l,sideOffset:n=4,...i},c)=>e.jsx(hw,{children:e.jsx(aj,{ref:c,sideOffset:n,className:B("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",l),...i})}));kN.displayName=aj.displayName;function Gk({children:l}){const{checking:n}=Dk(),[i,c]=m.useState(!0),[u,x]=m.useState(!1),[h,f]=m.useState(!1),{theme:p,setTheme:g}=Lm(),v=Yy();if(m.useEffect(()=>{const L=D=>{(D.metaKey||D.ctrlKey)&&D.key==="k"&&(D.preventDefault(),f(!0))};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[]),n)return e.jsx("div",{className:"flex h-screen items-center justify-center bg-background",children:e.jsx("div",{className:"text-muted-foreground",children:"正在验证登录状态..."})});const N=[{title:"概览",items:[{icon:Ro,label:"首页",path:"/"}]},{title:"麦麦配置编辑",items:[{icon:Ha,label:"麦麦主程序配置",path:"/config/bot"},{icon:yl,label:"AI模型厂商配置",path:"/config/modelProvider",tourId:"sidebar-model-provider"},{icon:_j,label:"模型管理与分配",path:"/config/model",tourId:"sidebar-model-management"},{icon:Fp,label:"麦麦适配器配置",path:"/config/adapter"}]},{title:"麦麦资源管理",items:[{icon:zm,label:"表情包管理",path:"/resource/emoji"},{icon:Wl,label:"表达方式管理",path:"/resource/expression"},{icon:Er,label:"黑话管理",path:"/resource/jargon"},{icon:Sj,label:"人物信息管理",path:"/resource/person"},{icon:vj,label:"知识库图谱可视化",path:"/resource/knowledge-graph"},{icon:Cr,label:"麦麦知识库管理",path:"/resource/knowledge-base"}]},{title:"扩展与监控",items:[{icon:ca,label:"插件市场",path:"/plugins"},{icon:bj,label:"配置模板市场",path:"/config/pack-market"},{icon:Fp,label:"插件配置",path:"/plugin-config"},{icon:Dm,label:"日志查看器",path:"/logs"},{icon:Wl,label:"本地聊天室",path:"/chat"}]},{title:"系统",items:[{icon:zn,label:"系统设置",path:"/settings"}]}],w=p==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":p,b=async()=>{await k1()};return e.jsx(Hk,{delayDuration:300,children:e.jsxs("div",{className:"flex h-screen overflow-hidden",children:[e.jsxs("aside",{className:B("fixed inset-y-0 left-0 z-50 flex flex-col border-r bg-card transition-all duration-300 lg:relative lg:z-0","w-64 lg:w-auto",i?"lg:w-64":"lg:w-16",u?"translate-x-0":"-translate-x-full lg:translate-x-0"),children:[e.jsx("div",{className:"flex h-16 items-center border-b px-4",children:e.jsxs("div",{className:B("relative flex items-center justify-center flex-1 transition-all overflow-hidden","lg:flex-1",!i&&"lg:flex-none lg:w-8"),children:[e.jsxs("div",{className:B("flex items-baseline gap-2",!i&&"lg:hidden"),children:[e.jsx("span",{className:"font-bold text-xl text-primary-gradient whitespace-nowrap",children:"MaiBot WebUI"}),e.jsx("span",{className:"text-xs text-primary/60 whitespace-nowrap",children:X1()})]}),!i&&e.jsx("span",{className:"hidden lg:block font-bold text-primary-gradient text-2xl",children:"M"})]})}),e.jsx(Je,{className:B("flex-1 overflow-x-hidden",!i&&"lg:w-16"),children:e.jsx("nav",{className:B("p-4",!i&&"lg:p-2 lg:w-16"),children:e.jsx("ul",{className:B("space-y-6",!i&&"lg:space-y-3 lg:w-full"),children:N.map((L,D)=>e.jsxs("li",{children:[e.jsx("div",{className:B("px-3 h-[1.25rem]","mb-2",!i&&"lg:mb-1 lg:invisible"),children:e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground/60 whitespace-nowrap",children:L.title})}),!i&&D>0&&e.jsx("div",{className:"hidden lg:block mb-2 border-t border-border"}),e.jsx("ul",{className:"space-y-1",children:L.items.map(T=>{const F=v({to:T.path}),O=T.icon,S=e.jsxs(e.Fragment,{children:[F&&e.jsx("div",{className:"absolute left-0 top-1/2 h-8 w-1 -translate-y-1/2 rounded-r-full bg-primary transition-opacity duration-300"}),e.jsxs("div",{className:B("flex items-center transition-all duration-300",i?"gap-3":"gap-3 lg:gap-0"),children:[e.jsx(O,{className:B("h-5 w-5 flex-shrink-0",F&&"text-primary"),strokeWidth:2,fill:"none"}),e.jsx("span",{className:B("text-sm font-medium whitespace-nowrap transition-all duration-300",F&&"font-semibold",i?"opacity-100 max-w-[200px]":"opacity-100 max-w-[200px] lg:opacity-0 lg:max-w-0 lg:overflow-hidden"),children:T.label})]})]});return e.jsx("li",{className:"relative",children:e.jsxs(Ik,{children:[e.jsx(Pk,{asChild:!0,children:e.jsx(br,{to:T.path,"data-tour":T.tourId,className:B("relative flex items-center rounded-lg py-2 transition-all duration-300","hover:bg-accent hover:text-accent-foreground",F?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground",i?"px-3":"px-3 lg:px-0 lg:justify-center lg:w-12 lg:mx-auto"),onClick:()=>x(!1),children:S})}),!i&&e.jsx(kN,{side:"right",className:"hidden lg:block",children:e.jsx("p",{children:T.label})})]})},T.path)})})]},L.title))})})})]}),u&&e.jsx("div",{className:"fixed inset-0 z-40 bg-black/50 lg:hidden",onClick:()=>x(!1)}),e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(Bk,{}),e.jsxs("header",{className:"flex h-16 items-center justify-between border-b bg-card/80 backdrop-blur-md px-4 sticky top-0 z-10",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:()=>x(!u),className:"rounded-lg p-2 hover:bg-accent lg:hidden",children:e.jsx(Kw,{className:"h-5 w-5"})}),e.jsx("button",{onClick:()=>c(!i),className:"hidden rounded-lg p-2 hover:bg-accent lg:block",title:i?"收起侧边栏":"展开侧边栏",children:e.jsx(Wa,{className:B("h-5 w-5 transition-transform",!i&&"rotate-180")})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>f(!0),className:"relative hidden md:flex items-center w-64 h-9 pl-9 pr-16 bg-background/50 border rounded-md hover:bg-accent/50 transition-colors text-left",children:[e.jsx(Vt,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"搜索..."}),e.jsxs(CN,{size:"sm",className:"absolute right-2 top-1/2 -translate-y-1/2",children:[e.jsx("span",{className:"text-xs",children:"⌘"}),"K"]})]}),e.jsx(Uk,{open:h,onOpenChange:f}),e.jsxs(k,{variant:"ghost",size:"sm",onClick:()=>window.open("https://docs.mai-mai.org","_blank"),className:"gap-2",title:"查看麦麦文档",children:[e.jsx(Qw,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"麦麦文档"})]}),e.jsx("button",{onClick:L=>{P1(w==="dark"?"light":"dark",g,L)},className:"rounded-lg p-2 hover:bg-accent",title:w==="dark"?"切换到浅色模式":"切换到深色模式",children:w==="dark"?e.jsx(uj,{className:"h-5 w-5"}):e.jsx(mj,{className:"h-5 w-5"})}),e.jsx("div",{className:"h-6 w-px bg-border"}),e.jsxs(k,{variant:"ghost",size:"sm",onClick:b,className:"gap-2",title:"登出系统",children:[e.jsx(Yw,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"登出"})]})]})]}),e.jsx("main",{className:"flex-1 overflow-hidden bg-background",children:l}),e.jsx($k,{})]})]})})}function qk(l){const n=l.split(` `).slice(1),i=[];for(const c of n){const u=c.trim();if(!u.startsWith("at "))continue;const x=u.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);x?i.push({functionName:x[1]||"",fileName:x[2],lineNumber:x[3],columnNumber:x[4],raw:u}):i.push({functionName:"",fileName:"",lineNumber:"",columnNumber:"",raw:u})}return i}function Fk({error:l,errorInfo:n}){const[i,c]=m.useState(!0),[u,x]=m.useState(!1),[h,f]=m.useState(!1),p=l.stack?qk(l.stack):[],g=async()=>{const v=` Error: ${l.name} Message: ${l.message} Stack Trace: ${l.stack||"No stack trace available"} Component Stack: ${n?.componentStack||"No component stack available"} URL: ${window.location.href} User Agent: ${navigator.userAgent} Time: ${new Date().toISOString()} `.trim();try{await navigator.clipboard.writeText(v),f(!0),setTimeout(()=>f(!1),2e3)}catch(N){console.error("Failed to copy:",N)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(gt,{variant:"destructive",className:"border-red-500/50 bg-red-500/10",children:[e.jsx(Qt,{className:"h-4 w-4"}),e.jsxs(jt,{className:"font-mono text-sm",children:[e.jsxs("span",{className:"font-semibold",children:[l.name,":"]})," ",l.message]})]}),p.length>0&&e.jsxs(Gi,{open:i,onOpenChange:c,children:[e.jsx(qi,{asChild:!0,children:e.jsxs(k,{variant:"ghost",className:"w-full justify-between p-3 h-auto",children:[e.jsxs("span",{className:"font-semibold text-sm flex items-center gap-2",children:[e.jsx(Jw,{className:"h-4 w-4"}),"Stack Trace (",p.length," frames)"]}),i?e.jsx(Tr,{className:"h-4 w-4"}):e.jsx(Oa,{className:"h-4 w-4"})]})}),e.jsx(Fi,{children:e.jsx(Je,{className:"h-[280px] rounded-md border bg-muted/30",children:e.jsx("div",{className:"p-3 space-y-1",children:p.map((v,N)=>e.jsx("div",{className:"font-mono text-xs p-2 rounded hover:bg-muted/50 transition-colors",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("span",{className:"text-muted-foreground w-6 text-right flex-shrink-0",children:[N+1,"."]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-primary font-medium",children:v.functionName}),v.fileName&&e.jsxs("div",{className:"text-muted-foreground mt-0.5 break-all",children:[v.fileName,v.lineNumber&&e.jsxs("span",{className:"text-yellow-600 dark:text-yellow-400",children:[":",v.lineNumber,":",v.columnNumber]})]})]})]})},N))})})})]}),n?.componentStack&&e.jsxs(Gi,{open:u,onOpenChange:x,children:[e.jsx(qi,{asChild:!0,children:e.jsxs(k,{variant:"ghost",className:"w-full justify-between p-3 h-auto",children:[e.jsxs("span",{className:"font-semibold text-sm flex items-center gap-2",children:[e.jsx(Qt,{className:"h-4 w-4"}),"Component Stack"]}),u?e.jsx(Tr,{className:"h-4 w-4"}):e.jsx(Oa,{className:"h-4 w-4"})]})}),e.jsx(Fi,{children:e.jsx(Je,{className:"h-[200px] rounded-md border bg-muted/30",children:e.jsx("pre",{className:"p-3 font-mono text-xs whitespace-pre-wrap text-muted-foreground",children:n.componentStack})})})]}),e.jsx(k,{variant:"outline",size:"sm",onClick:g,className:"w-full",children:h?e.jsxs(e.Fragment,{children:[e.jsx(_t,{className:"mr-2 h-4 w-4 text-green-500"}),"已复制到剪贴板"]}):e.jsxs(e.Fragment,{children:[e.jsx(_o,{className:"mr-2 h-4 w-4"}),"复制错误信息"]})})]})}function TN({error:l,errorInfo:n}){const i=()=>{window.location.href="/"},c=()=>{window.location.reload()};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(ze,{className:"w-full max-w-2xl shadow-lg",children:[e.jsxs(ts,{className:"text-center pb-2",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/30 mb-4",children:e.jsx(Qt,{className:"h-8 w-8 text-red-600 dark:text-red-400"})}),e.jsx(ls,{className:"text-2xl font-bold",children:"页面出现了问题"}),e.jsx(Vs,{className:"text-base mt-2",children:"应用程序遇到了意外错误。您可以尝试刷新页面或返回首页。"})]}),e.jsxs(Ye,{className:"space-y-4",children:[e.jsx(Fk,{error:l,errorInfo:n}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 pt-2",children:[e.jsxs(k,{onClick:c,className:"flex-1",children:[e.jsx(zt,{className:"mr-2 h-4 w-4"}),"刷新页面"]}),e.jsxs(k,{onClick:i,variant:"outline",className:"flex-1",children:[e.jsx(Ro,{className:"mr-2 h-4 w-4"}),"返回首页"]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground pt-2",children:"如果问题持续存在,请将错误信息复制并反馈给开发者"})]})]})})}class Vk extends m.Component{constructor(n){super(n),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,i){console.error("ErrorBoundary caught an error:",n,i),this.setState({errorInfo:i})}handleReset=()=>{this.setState({hasError:!1,error:null,errorInfo:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?this.props.fallback:e.jsx(TN,{error:this.state.error,errorInfo:this.state.errorInfo}):this.props.children}}function EN({error:l}){return e.jsx(TN,{error:l,errorInfo:null})}const Ji=Jy({component:()=>e.jsxs(e.Fragment,{children:[e.jsx(vg,{}),!1]}),beforeLoad:()=>{if(window.location.pathname==="/"&&!Ok())throw Zy({to:"/auth"})}}),Kk=Ws({getParentRoute:()=>Ji,path:"/auth",component:h2}),Qk=Ws({getParentRoute:()=>Ji,path:"/setup",component:M2}),ut=Ws({getParentRoute:()=>Ji,id:"protected",component:()=>e.jsx(Gk,{children:e.jsx(vg,{})}),errorComponent:({error:l})=>e.jsx(EN,{error:l})}),Yk=Ws({getParentRoute:()=>ut,path:"/",component:B1}),Jk=Ws({getParentRoute:()=>ut,path:"/config/bot",component:d_}),Xk=Ws({getParentRoute:()=>ut,path:"/config/modelProvider",component:y_}),Zk=Ws({getParentRoute:()=>ut,path:"/config/model",component:Q_}),Wk=Ws({getParentRoute:()=>ut,path:"/config/adapter",component:pS}),e3=Ws({getParentRoute:()=>ut,path:"/resource/emoji",component:$S}),s3=Ws({getParentRoute:()=>ut,path:"/resource/expression",component:XS}),t3=Ws({getParentRoute:()=>ut,path:"/resource/person",component:b4}),a3=Ws({getParentRoute:()=>ut,path:"/resource/jargon",component:u4}),l3=Ws({getParentRoute:()=>ut,path:"/resource/knowledge-graph",component:M4}),n3=Ws({getParentRoute:()=>ut,path:"/resource/knowledge-base",component:A4}),r3=Ws({getParentRoute:()=>ut,path:"/logs",component:D4}),i3=Ws({getParentRoute:()=>ut,path:"/chat",component:yC}),c3=Ws({getParentRoute:()=>ut,path:"/plugins",component:rC}),o3=Ws({getParentRoute:()=>ut,path:"/model-presets",component:cC}),d3=Ws({getParentRoute:()=>ut,path:"/plugin-config",component:uC}),u3=Ws({getParentRoute:()=>ut,path:"/plugin-mirrors",component:xC}),m3=Ws({getParentRoute:()=>ut,path:"/settings",component:i2}),x3=Ws({getParentRoute:()=>ut,path:"/config/pack-market",component:hk}),MN=Ws({getParentRoute:()=>ut,path:"/config/pack-market/$packId",component:Mk}),h3=Ws({getParentRoute:()=>ut,path:"/survey/webui-feedback",component:BC}),f3=Ws({getParentRoute:()=>ut,path:"/survey/maibot-feedback",component:$C}),p3=Ws({getParentRoute:()=>Ji,path:"*",component:Qj}),g3=Ji.addChildren([Kk,Qk,ut.addChildren([Yk,Jk,Xk,Zk,Wk,e3,s3,a3,t3,l3,n3,c3,o3,d3,u3,r3,i3,m3,x3,MN,h3,f3]),p3]),j3=Xy({routeTree:g3,defaultNotFoundComponent:Qj,defaultErrorComponent:({error:l})=>e.jsx(EN,{error:l})});function v3({children:l,defaultTheme:n="system",storageKey:i="ui-theme",...c}){const[u,x]=m.useState(()=>localStorage.getItem(i)||n);m.useEffect(()=>{const f=window.document.documentElement;if(f.classList.remove("light","dark"),u==="system"){const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";f.classList.add(p);return}f.classList.add(u)},[u]),m.useEffect(()=>{const f=localStorage.getItem("accent-color");if(f){const p=document.documentElement,v={blue:{hsl:"221.2 83.2% 53.3%",darkHsl:"217.2 91.2% 59.8%",gradient:null},purple:{hsl:"271 91% 65%",darkHsl:"270 95% 75%",gradient:null},green:{hsl:"142 71% 45%",darkHsl:"142 76% 36%",gradient:null},orange:{hsl:"25 95% 53%",darkHsl:"20 90% 48%",gradient:null},pink:{hsl:"330 81% 60%",darkHsl:"330 85% 70%",gradient:null},red:{hsl:"0 84% 60%",darkHsl:"0 90% 70%",gradient:null},"gradient-sunset":{hsl:"15 95% 60%",darkHsl:"15 95% 65%",gradient:"linear-gradient(135deg, hsl(25 95% 53%) 0%, hsl(330 81% 60%) 100%)"},"gradient-ocean":{hsl:"200 90% 55%",darkHsl:"200 90% 60%",gradient:"linear-gradient(135deg, hsl(221.2 83.2% 53.3%) 0%, hsl(189 94% 43%) 100%)"},"gradient-forest":{hsl:"150 70% 45%",darkHsl:"150 75% 40%",gradient:"linear-gradient(135deg, hsl(142 71% 45%) 0%, hsl(158 64% 52%) 100%)"},"gradient-aurora":{hsl:"310 85% 65%",darkHsl:"310 90% 70%",gradient:"linear-gradient(135deg, hsl(271 91% 65%) 0%, hsl(330 81% 60%) 100%)"},"gradient-fire":{hsl:"15 95% 55%",darkHsl:"15 95% 60%",gradient:"linear-gradient(135deg, hsl(0 84% 60%) 0%, hsl(25 95% 53%) 100%)"},"gradient-twilight":{hsl:"250 90% 60%",darkHsl:"250 95% 65%",gradient:"linear-gradient(135deg, hsl(239 84% 67%) 0%, hsl(271 91% 65%) 100%)"}}[f];v&&(p.style.setProperty("--primary",v.hsl),v.gradient?(p.style.setProperty("--primary-gradient",v.gradient),p.classList.add("has-gradient")):(p.style.removeProperty("--primary-gradient"),p.classList.remove("has-gradient")))}},[]);const h={theme:u,setTheme:f=>{localStorage.setItem(i,f),x(f)}};return e.jsx(Pj.Provider,{...c,value:h,children:l})}function N3({children:l,defaultEnabled:n=!0,defaultWavesEnabled:i=!0,storageKey:c="enable-animations",wavesStorageKey:u="enable-waves-background"}){const[x,h]=m.useState(()=>{const v=localStorage.getItem(c);return v!==null?v==="true":n}),[f,p]=m.useState(()=>{const v=localStorage.getItem(u);return v!==null?v==="true":i});m.useEffect(()=>{const v=document.documentElement;x?v.classList.remove("no-animations"):v.classList.add("no-animations"),localStorage.setItem(c,String(x))},[x,c]),m.useEffect(()=>{localStorage.setItem(u,String(f))},[f,u]);const g={enableAnimations:x,setEnableAnimations:h,enableWavesBackground:f,setEnableWavesBackground:p};return e.jsx(Gj.Provider,{value:g,children:l})}const b3=jw,AN=m.forwardRef(({className:l,...n},i)=>e.jsx(lj,{ref:i,className:B("fixed bottom-0 right-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:max-w-[420px] gap-2",l),...n}));AN.displayName=lj.displayName;const y3=Ar("group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-slide-in-from-right data-[state=open]:animate-fade-in data-[state=closed]:animate-slide-out-to-right data-[state=closed]:animate-fade-out data-[swipe=end]:animate-slide-out-to-right",{variants:{variant:{default:"border bg-primary/5 text-foreground backdrop-blur-sm",destructive:"destructive group border-destructive bg-destructive/10 text-destructive-foreground backdrop-blur-sm"}},defaultVariants:{variant:"default"}}),zN=m.forwardRef(({className:l,variant:n,...i},c)=>e.jsx(nj,{ref:c,className:B(y3({variant:n}),l),...i}));zN.displayName=nj.displayName;const w3=m.forwardRef(({className:l,...n},i)=>e.jsx(rj,{ref:i,className:B("inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",l),...n}));w3.displayName=rj.displayName;const DN=m.forwardRef(({className:l,...n},i)=>e.jsx(ij,{ref:i,className:B("absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",l),"toast-close":"",...n,children:e.jsx(Da,{className:"h-4 w-4"})}));DN.displayName=ij.displayName;const ON=m.forwardRef(({className:l,...n},i)=>e.jsx(cj,{ref:i,className:B("text-sm font-semibold [&+div]:text-xs",l),...n}));ON.displayName=cj.displayName;const RN=m.forwardRef(({className:l,...n},i)=>e.jsx(oj,{ref:i,className:B("text-sm opacity-90",l),...n}));RN.displayName=oj.displayName;function _3(){const{toasts:l}=et();return e.jsxs(b3,{children:[l.map(function({id:n,title:i,description:c,action:u,...x}){return e.jsxs(zN,{...x,children:[e.jsxs("div",{className:"grid gap-1",children:[i&&e.jsx(ON,{children:i}),c&&e.jsx(RN,{children:c})]}),u,e.jsx(DN,{})]},n)}),e.jsx(AN,{})]})}C1.createRoot(document.getElementById("root")).render(e.jsx(m.StrictMode,{children:e.jsx(Vk,{children:e.jsx(v3,{defaultTheme:"system",children:e.jsx(N3,{children:e.jsxs(p_,{children:[e.jsx(Wy,{router:j3}),e.jsx(v_,{}),e.jsx(_3,{})]})})})})}));