import{r as m,j as e,L as ci,e as ka,R as Ct,b as jN,f as vN,g as bN,h as NN,k as lt,l as yN,m as wN,O as Vp,n as _N}from"./router-Bz250laD.js";import{a as SN,b as CN,g as kN}from"./react-vendor-BmxF9s7Q.js";import{N as TN,c as EN,O as gi,P as zN,g as Du}from"./utils-BXc2jIuz.js";import{L as Fp,T as Ip,C as Qp,R as MN,a as Yp,V as AN,b as ON,S as Kp,c as DN,d as Xp,I as RN,e as Pp,f as LN,g as Jp,h as UN,i as BN,j as HN,O as Zp,P as $N,k as Wp,l as eg,D as sg,A as tg,m as ag,n as qN,o as GN,p as lg,q as VN,r as ng,s as FN,t as IN,u as QN,v as YN,w as KN,x as ig,y as rg,F as cg,z as og,B as XN,E as PN}from"./radix-extra-DDK-u9dm.js";import{R as JN,T as ZN,L as WN,g as ey,C as Xc,X as Pc,Y as ur,h as sy,B as Ru,j as Jc,P as ty,k as ay,l as ly}from"./charts-DbiuC1q1.js";import{S as ny,G as dg,O as ug,o as iy,C as mg,p as ry,T as xg,D as hg,R as cy,q as oy,H as fg,I as dy,J as pg,K as gg,L as uy,M as jg,V as my,N as vg,Q as bg,U as xy,X as hy,Y as Ng,Z as fy,_ as py,$ as yg,a0 as gy,e as jy,f as vy,c as wg,P as fo,d as nm,b as Zu,h as by,l as Ny,m as yy,a1 as wy,a2 as _g,a3 as _y,a4 as Sy,a5 as Cy,a6 as Sg,a7 as Cg,a8 as kg,a9 as Tg,aa as Eg,ab as zg,ac as ky}from"./radix-core-9dEfQl-6.js";import{R as At,a as yr,C as Ot,b as aa,L as tt,P as Mr,Z as hn,F as Aa,c as Ty,S as ji,d as Ey,M as Fl,A as zy,D as My,e as ro,f as xi,T as Ay,X as fl,g as Oy,h as Dy,I as Ra,i as Oa,j as ea,k as co,E as wr,l as Gt,m as Mg,H as Ry,n as es,o as Da,U as _r,p as Ag,q as Og,r as xp,K as Dg,s as Rg,t as Ly,u as ao,v as Uy,B as fr,w as oo,x as im,y as By,z as Hy,G as $t,J as po,N as hi,O as ut,Q as Fa,V as fi,W as rm,Y as Lg,_ as Ar,$ as $y,a0 as qy,a1 as fn,a2 as vi,a3 as pl,a4 as Ya,a5 as bi,a6 as cm,a7 as Gy,a8 as Vy,a9 as Vl,aa as Fy,ab as Ug,ac as lo,ad as pn,ae as Iy,af as pi,ag as Qy,ah as Wu,ai as em,aj as Bg,ak as Yy,al as Ky,am as hp,an as Xy,ao as xl,ap as Lu,aq as fp,ar as Hg,as as Py,at as $g,au as Uu,av as Jy,aw as Zy,ax as Wy,ay as e0,az as s0,aA as qg,aB as Gg,aC as Vg,aD as Fg,aE as t0,aF as pp,aG as a0,aH as l0,aI as n0,aJ as i0}from"./icons-B6qV_tuI.js";import{S as r0,p as c0,j as o0,a as d0,E as gp,R as u0,o as m0}from"./codemirror-BEE0n9kQ.js";import{u as Ig,a as uo,s as Qg,K as Yg,P as Kg,b as Xg,D as Pg,c as Jg,S as Zg,v as x0,d as Wg,C as ej,h as h0}from"./dnd-B_gmzEl7.js";import{_ as la,c as f0,g as sj,D as p0,z as Zc}from"./misc-CKjrIrIJ.js";import{D as g0,U as j0}from"./uppy-BMZiFQyG.js";import{M as v0,r as b0,a as N0,b as y0}from"./markdown-kUhwkcQP.js";import{c as w0,H as mo,P as xo,u as _0,d as S0,R as C0,B as k0,e as T0,C as E0,M as z0,f as M0}from"./reactflow-DLoXAt4c.js";(function(){const i=document.createElement("link").relList;if(i&&i.supports&&i.supports("modulepreload"))return;for(const u of document.querySelectorAll('link[rel="modulepreload"]'))o(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"&&o(h)}).observe(document,{childList:!0,subtree:!0});function r(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 o(u){if(u.ep)return;u.ep=!0;const x=r(u);fetch(u.href,x)}})();var Bu={exports:{}},mr={},Hu={exports:{}},$u={};var jp;function A0(){return jp||(jp=1,(function(l){function i(U,P){var X=U.length;U.push(P);e:for(;0>>1,B=U[L];if(0>>1;L<_e;){var Ne=2*(L+1)-1,Ce=U[Ne],ve=Ne+1,ze=U[ve];if(0>u(Ce,X))veu(ze,Ce)?(U[L]=ze,U[ve]=X,L=ve):(U[L]=Ce,U[Ne]=X,L=Ne);else if(veu(ze,X))U[L]=ze,U[ve]=X,L=ve;else break e}}return P}function u(U,P){var X=U.sortIndex-P.sortIndex;return X!==0?X:U.id-P.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 g=[],j=[],v=1,y=null,b=3,S=!1,w=!1,O=!1,A=!1,D=typeof setTimeout=="function"?setTimeout:null,V=typeof clearTimeout=="function"?clearTimeout:null,z=typeof setImmediate<"u"?setImmediate:null;function _(U){for(var P=r(j);P!==null;){if(P.callback===null)o(j);else if(P.startTime<=U)o(j),P.sortIndex=P.expirationTime,i(g,P);else break;P=r(j)}}function T(U){if(O=!1,_(U),!w)if(r(g)!==null)w=!0,$||($=!0,Se());else{var P=r(j);P!==null&&be(T,P.startTime-U)}}var $=!1,E=-1,se=5,te=-1;function ne(){return A?!0:!(l.unstable_now()-teU&&ne());){var L=y.callback;if(typeof L=="function"){y.callback=null,b=y.priorityLevel;var B=L(y.expirationTime<=U);if(U=l.unstable_now(),typeof B=="function"){y.callback=B,_(U),P=!0;break s}y===r(g)&&o(g),_(U)}else o(g);y=r(g)}if(y!==null)P=!0;else{var _e=r(j);_e!==null&&be(T,_e.startTime-U),P=!1}}break e}finally{y=null,b=X,S=!1}P=void 0}}finally{P?Se():$=!1}}}var Se;if(typeof z=="function")Se=function(){z(ue)};else if(typeof MessageChannel<"u"){var oe=new MessageChannel,je=oe.port2;oe.port1.onmessage=ue,Se=function(){je.postMessage(null)}}else Se=function(){D(ue,0)};function be(U,P){E=D(function(){U(l.unstable_now())},P)}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(U){U.callback=null},l.unstable_forceFrameRate=function(U){0>U||125L?(U.sortIndex=X,i(j,U),r(g)===null&&U===r(j)&&(O?(V(E),E=-1):O=!0,be(T,X-L))):(U.sortIndex=B,i(g,U),w||S||(w=!0,$||($=!0,Se()))),U},l.unstable_shouldYield=ne,l.unstable_wrapCallback=function(U){var P=b;return function(){var X=b;b=P;try{return U.apply(this,arguments)}finally{b=X}}}})($u)),$u}var vp;function O0(){return vp||(vp=1,Hu.exports=A0()),Hu.exports}var bp;function D0(){if(bp)return mr;bp=1;var l=O0(),i=SN(),r=CN();function o(s){var t="https://react.dev/errors/"+s;if(1B||(s.current=L[B],L[B]=null,B--)}function Ce(s,t){B++,L[B]=s.current,s.current=t}var ve=_e(null),ze=_e(null),Q=_e(null),xe=_e(null);function Te(s,t){switch(Ce(Q,t),Ce(ze,s),Ce(ve,null),t.nodeType){case 9:case 11:s=(s=t.documentElement)&&(s=s.namespaceURI)?Lf(s):0;break;default:if(s=t.tagName,t=t.namespaceURI)t=Lf(t),s=Uf(t,s);else switch(s){case"svg":s=1;break;case"math":s=2;break;default:s=0}}Ne(ve),Ce(ve,s)}function J(){Ne(ve),Ne(ze),Ne(Q)}function le(s){s.memoizedState!==null&&Ce(xe,s);var t=ve.current,a=Uf(t,s.type);t!==a&&(Ce(ze,s),Ce(ve,a))}function qe(s){ze.current===s&&(Ne(ve),Ne(ze)),xe.current===s&&(Ne(xe),rr._currentValue=X)}var We,fe;function ls(s){if(We===void 0)try{throw Error()}catch(a){var t=a.stack.trim().match(/\n( *(at )?)/);We=t&&t[1]||"",fe=-1)":-1c||M[n]!==K[c]){var ce=` `+M[n].replace(" at new "," at ");return s.displayName&&ce.includes("")&&(ce=ce.replace("",s.displayName)),ce}while(1<=n&&0<=c);break}}}finally{G=!1,Error.prepareStackTrace=a}return(a=s?s.displayName||s.name:"")?ls(a):""}function re(s,t){switch(s.tag){case 26:case 27:case 5:return ls(s.type);case 16:return ls("Lazy");case 13:return s.child!==t&&t!==null?ls("Suspense Fallback"):ls("Suspense");case 19:return ls("SuspenseList");case 0:case 15:return Me(s.type,!1);case 11:return Me(s.type.render,!1);case 1:return Me(s.type,!0);case 31:return ls("Activity");default:return""}}function pe(s){try{var t="",a=null;do t+=re(s,a),a=s,s=s.return;while(s);return t}catch(n){return` Error generating stack: `+n.message+` `+n.stack}}var Ee=Object.prototype.hasOwnProperty,Ie=l.unstable_scheduleCallback,$e=l.unstable_cancelCallback,Vt=l.unstable_shouldYield,_t=l.unstable_requestPaint,nt=l.unstable_now,F=l.unstable_getCurrentPriorityLevel,He=l.unstable_ImmediatePriority,De=l.unstable_UserBlockingPriority,ye=l.unstable_NormalPriority,ps=l.unstable_LowPriority,ss=l.unstable_IdlePriority,Es=l.log,Ms=l.unstable_setDisableYieldValue,Ls=null,ts=null;function Pe(s){if(typeof Es=="function"&&Ms(s),ts&&typeof ts.setStrictMode=="function")try{ts.setStrictMode(Ls,s)}catch{}}var Xe=Math.clz32?Math.clz32:Xs,Os=Math.log,kt=Math.LN2;function Xs(s){return s>>>=0,s===0?32:31-(Os(s)/kt|0)|0}var Ss=256,xt=262144,W=4194304;function de(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 ys(s,t,a){var n=s.pendingLanes;if(n===0)return 0;var c=0,d=s.suspendedLanes,p=s.pingedLanes;s=s.warmLanes;var N=n&134217727;return N!==0?(n=N&~d,n!==0?c=de(n):(p&=N,p!==0?c=de(p):a||(a=N&~s,a!==0&&(c=de(a))))):(N=n&~d,N!==0?c=de(N):p!==0?c=de(p):a||(a=n&~s,a!==0&&(c=de(a)))),c===0?0:t!==0&&t!==c&&(t&d)===0&&(d=c&-c,a=t&-t,d>=a||d===32&&(a&4194048)!==0)?t:c}function Tt(s,t){return(s.pendingLanes&~(s.suspendedLanes&~s.pingedLanes)&t)===0}function Et(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 I(){var s=W;return W<<=1,(W&62914560)===0&&(W=4194304),s}function ge(s){for(var t=[],a=0;31>a;a++)t.push(s);return t}function ke(s,t){s.pendingLanes|=t,t!==268435456&&(s.suspendedLanes=0,s.pingedLanes=0,s.warmLanes=0)}function Us(s,t,a,n,c,d){var p=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 N=s.entanglements,M=s.expirationTimes,K=s.hiddenUpdates;for(a=p&~a;0"u")return null;try{return s.activeElement||s.body}catch{return s.body}}var mv=/[\n"\\]/g;function fa(s){return s.replace(mv,function(t){return"\\"+t.charCodeAt(0).toString(16)+" "})}function To(s,t,a,n,c,d,p,N){s.name="",p!=null&&typeof p!="function"&&typeof p!="symbol"&&typeof p!="boolean"?s.type=p:s.removeAttribute("type"),t!=null?p==="number"?(t===0&&s.value===""||s.value!=t)&&(s.value=""+ha(t)):s.value!==""+ha(t)&&(s.value=""+ha(t)):p!=="submit"&&p!=="reset"||s.removeAttribute("value"),t!=null?Eo(s,p,ha(t)):a!=null?Eo(s,p,ha(a)):n!=null&&s.removeAttribute("value"),c==null&&d!=null&&(s.defaultChecked=!!d),c!=null&&(s.checked=c&&typeof c!="function"&&typeof c!="symbol"),N!=null&&typeof N!="function"&&typeof N!="symbol"&&typeof N!="boolean"?s.name=""+ha(N):s.removeAttribute("name")}function Em(s,t,a,n,c,d,p,N){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)){ko(s);return}a=a!=null?""+ha(a):"",t=t!=null?""+ha(t):a,N||t===s.value||(s.value=t),s.defaultValue=t}n=n??c,n=typeof n!="function"&&typeof n!="symbol"&&!!n,s.checked=N?s.checked:!!n,s.defaultChecked=!!n,p!=null&&typeof p!="function"&&typeof p!="symbol"&&typeof p!="boolean"&&(s.name=p),ko(s)}function Eo(s,t,a){t==="number"&&Hr(s.ownerDocument)===s||s.defaultValue===""+a||(s.defaultValue=""+a)}function Tn(s,t,a,n){if(s=s.options,t){t={};for(var c=0;c"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Do=!1;if(Pa)try{var Si={};Object.defineProperty(Si,"passive",{get:function(){Do=!0}}),window.addEventListener("test",Si,Si),window.removeEventListener("test",Si,Si)}catch{Do=!1}var vl=null,Ro=null,qr=null;function Lm(){if(qr)return qr;var s,t=Ro,a=t.length,n,c="value"in vl?vl.value:vl.textContent,d=c.length;for(s=0;s=Ti),Gm=" ",Vm=!1;function Fm(s,t){switch(s){case"keyup":return $v.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Im(s){return s=s.detail,typeof s=="object"&&"data"in s?s.data:null}var An=!1;function Gv(s,t){switch(s){case"compositionend":return Im(t);case"keypress":return t.which!==32?null:(Vm=!0,Gm);case"textInput":return s=t.data,s===Gm&&Vm?null:s;default:return null}}function Vv(s,t){if(An)return s==="compositionend"||!$o&&Fm(s,t)?(s=Lm(),qr=Ro=vl=null,An=!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=n}e:{for(;a;){if(a.nextSibling){a=a.nextSibling;break e}a=a.parentNode}a=void 0}a=Wm(a)}}function sx(s,t){return s&&t?s===t?!0:s&&s.nodeType===3?!1:t&&t.nodeType===3?sx(s,t.parentNode):"contains"in s?s.contains(t):s.compareDocumentPosition?!!(s.compareDocumentPosition(t)&16):!1:!1}function tx(s){s=s!=null&&s.ownerDocument!=null&&s.ownerDocument.defaultView!=null?s.ownerDocument.defaultView:window;for(var t=Hr(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=Hr(s.document)}return t}function Vo(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 Jv=Pa&&"documentMode"in document&&11>=document.documentMode,On=null,Fo=null,Ai=null,Io=!1;function ax(s,t,a){var n=a.window===a?a.document:a.nodeType===9?a:a.ownerDocument;Io||On==null||On!==Hr(n)||(n=On,"selectionStart"in n&&Vo(n)?n={start:n.selectionStart,end:n.selectionEnd}:(n=(n.ownerDocument&&n.ownerDocument.defaultView||window).getSelection(),n={anchorNode:n.anchorNode,anchorOffset:n.anchorOffset,focusNode:n.focusNode,focusOffset:n.focusOffset}),Ai&&Mi(Ai,n)||(Ai=n,n=Dc(Fo,"onSelect"),0>=p,c-=p,Ba=1<<32-Xe(t)+c|a<ns?(_s=Oe,Oe=null):_s=Oe.sibling;var Ts=Z(q,Oe,Y[ns],me);if(Ts===null){Oe===null&&(Oe=_s);break}s&&Oe&&Ts.alternate===null&&t(q,Oe),R=d(Ts,R,ns),ks===null?Ge=Ts:ks.sibling=Ts,ks=Ts,Oe=_s}if(ns===Y.length)return a(q,Oe),Cs&&Za(q,ns),Ge;if(Oe===null){for(;nsns?(_s=Oe,Oe=null):_s=Oe.sibling;var ql=Z(q,Oe,Ts.value,me);if(ql===null){Oe===null&&(Oe=_s);break}s&&Oe&&ql.alternate===null&&t(q,Oe),R=d(ql,R,ns),ks===null?Ge=ql:ks.sibling=ql,ks=ql,Oe=_s}if(Ts.done)return a(q,Oe),Cs&&Za(q,ns),Ge;if(Oe===null){for(;!Ts.done;ns++,Ts=Y.next())Ts=he(q,Ts.value,me),Ts!==null&&(R=d(Ts,R,ns),ks===null?Ge=Ts:ks.sibling=Ts,ks=Ts);return Cs&&Za(q,ns),Ge}for(Oe=n(Oe);!Ts.done;ns++,Ts=Y.next())Ts=ae(Oe,q,ns,Ts.value,me),Ts!==null&&(s&&Ts.alternate!==null&&Oe.delete(Ts.key===null?ns:Ts.key),R=d(Ts,R,ns),ks===null?Ge=Ts:ks.sibling=Ts,ks=Ts);return s&&Oe.forEach(function(gN){return t(q,gN)}),Cs&&Za(q,ns),Ge}function $s(q,R,Y,me){if(typeof Y=="object"&&Y!==null&&Y.type===O&&Y.key===null&&(Y=Y.props.children),typeof Y=="object"&&Y!==null){switch(Y.$$typeof){case S:e:{for(var Ge=Y.key;R!==null;){if(R.key===Ge){if(Ge=Y.type,Ge===O){if(R.tag===7){a(q,R.sibling),me=c(R,Y.props.children),me.return=q,q=me;break e}}else if(R.elementType===Ge||typeof Ge=="object"&&Ge!==null&&Ge.$$typeof===se&&nn(Ge)===R.type){a(q,R.sibling),me=c(R,Y.props),Bi(me,Y),me.return=q,q=me;break e}a(q,R);break}else t(q,R);R=R.sibling}Y.type===O?(me=en(Y.props.children,q.mode,me,Y.key),me.return=q,q=me):(me=Jr(Y.type,Y.key,Y.props,null,q.mode,me),Bi(me,Y),me.return=q,q=me)}return p(q);case w:e:{for(Ge=Y.key;R!==null;){if(R.key===Ge)if(R.tag===4&&R.stateNode.containerInfo===Y.containerInfo&&R.stateNode.implementation===Y.implementation){a(q,R.sibling),me=c(R,Y.children||[]),me.return=q,q=me;break e}else{a(q,R);break}else t(q,R);R=R.sibling}me=Zo(Y,q.mode,me),me.return=q,q=me}return p(q);case se:return Y=nn(Y),$s(q,R,Y,me)}if(be(Y))return Ae(q,R,Y,me);if(Se(Y)){if(Ge=Se(Y),typeof Ge!="function")throw Error(o(150));return Y=Ge.call(Y),Ke(q,R,Y,me)}if(typeof Y.then=="function")return $s(q,R,lc(Y),me);if(Y.$$typeof===z)return $s(q,R,ec(q,Y),me);nc(q,Y)}return typeof Y=="string"&&Y!==""||typeof Y=="number"||typeof Y=="bigint"?(Y=""+Y,R!==null&&R.tag===6?(a(q,R.sibling),me=c(R,Y),me.return=q,q=me):(a(q,R),me=Jo(Y,q.mode,me),me.return=q,q=me),p(q)):a(q,R)}return function(q,R,Y,me){try{Ui=0;var Ge=$s(q,R,Y,me);return Fn=null,Ge}catch(Oe){if(Oe===Vn||Oe===tc)throw Oe;var ks=ia(29,Oe,null,q.mode);return ks.lanes=me,ks.return=q,ks}finally{}}}var cn=Cx(!0),kx=Cx(!1),_l=!1;function dd(s){s.updateQueue={baseState:s.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function ud(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 Sl(s){return{lane:s,tag:0,payload:null,callback:null,next:null}}function Cl(s,t,a){var n=s.updateQueue;if(n===null)return null;if(n=n.shared,(zs&2)!==0){var c=n.pending;return c===null?t.next=t:(t.next=c.next,c.next=t),n.pending=t,t=Pr(s),dx(s,null,a),t}return Xr(s,n,t,a),Pr(s)}function Hi(s,t,a){if(t=t.updateQueue,t!==null&&(t=t.shared,(a&4194048)!==0)){var n=t.lanes;n&=s.pendingLanes,a|=n,t.lanes=a,Ft(s,a)}}function md(s,t){var a=s.updateQueue,n=s.alternate;if(n!==null&&(n=n.updateQueue,a===n)){var c=null,d=null;if(a=a.firstBaseUpdate,a!==null){do{var p={lane:a.lane,tag:a.tag,payload:a.payload,callback:null,next:null};d===null?c=d=p:d=d.next=p,a=a.next}while(a!==null);d===null?c=d=t:d=d.next=t}else c=d=t;a={baseState:n.baseState,firstBaseUpdate:c,lastBaseUpdate:d,shared:n.shared,callbacks:n.callbacks},s.updateQueue=a;return}s=a.lastBaseUpdate,s===null?a.firstBaseUpdate=t:s.next=t,a.lastBaseUpdate=t}var xd=!1;function $i(){if(xd){var s=Gn;if(s!==null)throw s}}function qi(s,t,a,n){xd=!1;var c=s.updateQueue;_l=!1;var d=c.firstBaseUpdate,p=c.lastBaseUpdate,N=c.shared.pending;if(N!==null){c.shared.pending=null;var M=N,K=M.next;M.next=null,p===null?d=K:p.next=K,p=M;var ce=s.alternate;ce!==null&&(ce=ce.updateQueue,N=ce.lastBaseUpdate,N!==p&&(N===null?ce.firstBaseUpdate=K:N.next=K,ce.lastBaseUpdate=M))}if(d!==null){var he=c.baseState;p=0,ce=K=M=null,N=d;do{var Z=N.lane&-536870913,ae=Z!==N.lane;if(ae?(ws&Z)===Z:(n&Z)===Z){Z!==0&&Z===qn&&(xd=!0),ce!==null&&(ce=ce.next={lane:0,tag:N.tag,payload:N.payload,callback:null,next:null});e:{var Ae=s,Ke=N;Z=t;var $s=a;switch(Ke.tag){case 1:if(Ae=Ke.payload,typeof Ae=="function"){he=Ae.call($s,he,Z);break e}he=Ae;break e;case 3:Ae.flags=Ae.flags&-65537|128;case 0:if(Ae=Ke.payload,Z=typeof Ae=="function"?Ae.call($s,he,Z):Ae,Z==null)break e;he=y({},he,Z);break e;case 2:_l=!0}}Z=N.callback,Z!==null&&(s.flags|=64,ae&&(s.flags|=8192),ae=c.callbacks,ae===null?c.callbacks=[Z]:ae.push(Z))}else ae={lane:Z,tag:N.tag,payload:N.payload,callback:N.callback,next:null},ce===null?(K=ce=ae,M=he):ce=ce.next=ae,p|=Z;if(N=N.next,N===null){if(N=c.shared.pending,N===null)break;ae=N,N=ae.next,ae.next=null,c.lastBaseUpdate=ae,c.shared.pending=null}}while(!0);ce===null&&(M=he),c.baseState=M,c.firstBaseUpdate=K,c.lastBaseUpdate=ce,d===null&&(c.shared.lanes=0),Ml|=p,s.lanes=p,s.memoizedState=he}}function Tx(s,t){if(typeof s!="function")throw Error(o(191,s));s.call(t)}function Ex(s,t){var a=s.callbacks;if(a!==null)for(s.callbacks=null,s=0;sd?d:8;var p=U.T,N={};U.T=N,Ad(s,!1,t,a);try{var M=c(),K=U.S;if(K!==null&&K(N,M),M!==null&&typeof M=="object"&&typeof M.then=="function"){var ce=ib(M,n);Fi(s,t,ce,ua(s))}else Fi(s,t,n,ua(s))}catch(he){Fi(s,t,{then:function(){},status:"rejected",reason:he},ua())}finally{P.p=d,p!==null&&N.types!==null&&(p.types=N.types),U.T=p}}function mb(){}function zd(s,t,a,n){if(s.tag!==5)throw Error(o(476));var c=rh(s).queue;ih(s,c,t,X,a===null?mb:function(){return ch(s),a(n)})}function rh(s){var t=s.memoizedState;if(t!==null)return t;t={memoizedState:X,baseState:X,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:tl,lastRenderedState:X},next:null};var a={};return t.next={memoizedState:a,baseState:a,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:tl,lastRenderedState:a},next:null},s.memoizedState=t,s=s.alternate,s!==null&&(s.memoizedState=t),t}function ch(s){var t=rh(s);t.next===null&&(t=s.alternate.memoizedState),Fi(s,t.next.queue,{},ua())}function Md(){return Lt(rr)}function oh(){return pt().memoizedState}function dh(){return pt().memoizedState}function xb(s){for(var t=s.return;t!==null;){switch(t.tag){case 24:case 3:var a=ua();s=Sl(a);var n=Cl(t,s,a);n!==null&&(Zt(n,t,a),Hi(n,t,a)),t={cache:id()},s.payload=t;return}t=t.return}}function hb(s,t,a){var n=ua();a={lane:n,revertLane:0,gesture:null,action:a,hasEagerState:!1,eagerState:null,next:null},fc(s)?mh(t,a):(a=Xo(s,t,a,n),a!==null&&(Zt(a,s,n),xh(a,t,n)))}function uh(s,t,a){var n=ua();Fi(s,t,a,n)}function Fi(s,t,a,n){var c={lane:n,revertLane:0,gesture:null,action:a,hasEagerState:!1,eagerState:null,next:null};if(fc(s))mh(t,c);else{var d=s.alternate;if(s.lanes===0&&(d===null||d.lanes===0)&&(d=t.lastRenderedReducer,d!==null))try{var p=t.lastRenderedState,N=d(p,a);if(c.hasEagerState=!0,c.eagerState=N,na(N,p))return Xr(s,t,c,0),Fs===null&&Kr(),!1}catch{}finally{}if(a=Xo(s,t,c,n),a!==null)return Zt(a,s,n),xh(a,t,n),!0}return!1}function Ad(s,t,a,n){if(n={lane:2,revertLane:du(),gesture:null,action:n,hasEagerState:!1,eagerState:null,next:null},fc(s)){if(t)throw Error(o(479))}else t=Xo(s,a,n,2),t!==null&&Zt(t,s,2)}function fc(s){var t=s.alternate;return s===as||t!==null&&t===as}function mh(s,t){Qn=cc=!0;var a=s.pending;a===null?t.next=t:(t.next=a.next,a.next=t),s.pending=t}function xh(s,t,a){if((a&4194048)!==0){var n=t.lanes;n&=s.pendingLanes,a|=n,t.lanes=a,Ft(s,a)}}var Ii={readContext:Lt,use:uc,useCallback:rt,useContext:rt,useEffect:rt,useImperativeHandle:rt,useLayoutEffect:rt,useInsertionEffect:rt,useMemo:rt,useReducer:rt,useRef:rt,useState:rt,useDebugValue:rt,useDeferredValue:rt,useTransition:rt,useSyncExternalStore:rt,useId:rt,useHostTransitionStatus:rt,useFormState:rt,useActionState:rt,useOptimistic:rt,useMemoCache:rt,useCacheRefresh:rt};Ii.useEffectEvent=rt;var hh={readContext:Lt,use:uc,useCallback:function(s,t){return qt().memoizedState=[s,t===void 0?null:t],s},useContext:Lt,useEffect:Jx,useImperativeHandle:function(s,t,a){a=a!=null?a.concat([s]):null,xc(4194308,4,sh.bind(null,t,s),a)},useLayoutEffect:function(s,t){return xc(4194308,4,s,t)},useInsertionEffect:function(s,t){xc(4,2,s,t)},useMemo:function(s,t){var a=qt();t=t===void 0?null:t;var n=s();if(on){Pe(!0);try{s()}finally{Pe(!1)}}return a.memoizedState=[n,t],n},useReducer:function(s,t,a){var n=qt();if(a!==void 0){var c=a(t);if(on){Pe(!0);try{a(t)}finally{Pe(!1)}}}else c=t;return n.memoizedState=n.baseState=c,s={pending:null,lanes:0,dispatch:null,lastRenderedReducer:s,lastRenderedState:c},n.queue=s,s=s.dispatch=hb.bind(null,as,s),[n.memoizedState,s]},useRef:function(s){var t=qt();return s={current:s},t.memoizedState=s},useState:function(s){s=Sd(s);var t=s.queue,a=uh.bind(null,as,t);return t.dispatch=a,[s.memoizedState,a]},useDebugValue:Td,useDeferredValue:function(s,t){var a=qt();return Ed(a,s,t)},useTransition:function(){var s=Sd(!1);return s=ih.bind(null,as,s.queue,!0,!1),qt().memoizedState=s,[!1,s]},useSyncExternalStore:function(s,t,a){var n=as,c=qt();if(Cs){if(a===void 0)throw Error(o(407));a=a()}else{if(a=t(),Fs===null)throw Error(o(349));(ws&127)!==0||Rx(n,t,a)}c.memoizedState=a;var d={value:a,getSnapshot:t};return c.queue=d,Jx(Ux.bind(null,n,d,s),[s]),n.flags|=2048,Kn(9,{destroy:void 0},Lx.bind(null,n,d,a,t),null),a},useId:function(){var s=qt(),t=Fs.identifierPrefix;if(Cs){var a=Ha,n=Ba;a=(n&~(1<<32-Xe(n)-1)).toString(32)+a,t="_"+t+"R_"+a,a=oc++,0<\/script>",d=d.removeChild(d.firstChild);break;case"select":d=typeof n.is=="string"?p.createElement("select",{is:n.is}):p.createElement("select"),n.multiple?d.multiple=!0:n.size&&(d.size=n.size);break;default:d=typeof n.is=="string"?p.createElement(c,{is:n.is}):p.createElement(c)}}d[Dt]=t,d[Qt]=n;e:for(p=t.child;p!==null;){if(p.tag===5||p.tag===6)d.appendChild(p.stateNode);else if(p.tag!==4&&p.tag!==27&&p.child!==null){p.child.return=p,p=p.child;continue}if(p===t)break e;for(;p.sibling===null;){if(p.return===null||p.return===t)break e;p=p.return}p.sibling.return=p.return,p=p.sibling}t.stateNode=d;e:switch(Bt(d,c,n),c){case"button":case"input":case"select":case"textarea":n=!!n.autoFocus;break e;case"img":n=!0;break e;default:n=!1}n&&ll(t)}}return Js(t),Qd(t,t.type,s===null?null:s.memoizedProps,t.pendingProps,a),null;case 6:if(s&&t.stateNode!=null)s.memoizedProps!==n&&ll(t);else{if(typeof n!="string"&&t.stateNode===null)throw Error(o(166));if(s=Q.current,Hn(t)){if(s=t.stateNode,a=t.memoizedProps,n=null,c=Rt,c!==null)switch(c.tag){case 27:case 5:n=c.memoizedProps}s[Dt]=t,s=!!(s.nodeValue===a||n!==null&&n.suppressHydrationWarning===!0||Df(s.nodeValue,a)),s||yl(t,!0)}else s=Rc(s).createTextNode(n),s[Dt]=t,t.stateNode=s}return Js(t),null;case 31:if(a=t.memoizedState,s===null||s.memoizedState!==null){if(n=Hn(t),a!==null){if(s===null){if(!n)throw Error(o(318));if(s=t.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(o(557));s[Dt]=t}else sn(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;Js(t),s=!1}else a=td(),s!==null&&s.memoizedState!==null&&(s.memoizedState.hydrationErrors=a),s=!0;if(!s)return t.flags&256?(ca(t),t):(ca(t),null);if((t.flags&128)!==0)throw Error(o(558))}return Js(t),null;case 13:if(n=t.memoizedState,s===null||s.memoizedState!==null&&s.memoizedState.dehydrated!==null){if(c=Hn(t),n!==null&&n.dehydrated!==null){if(s===null){if(!c)throw Error(o(318));if(c=t.memoizedState,c=c!==null?c.dehydrated:null,!c)throw Error(o(317));c[Dt]=t}else sn(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;Js(t),c=!1}else c=td(),s!==null&&s.memoizedState!==null&&(s.memoizedState.hydrationErrors=c),c=!0;if(!c)return t.flags&256?(ca(t),t):(ca(t),null)}return ca(t),(t.flags&128)!==0?(t.lanes=a,t):(a=n!==null,s=s!==null&&s.memoizedState!==null,a&&(n=t.child,c=null,n.alternate!==null&&n.alternate.memoizedState!==null&&n.alternate.memoizedState.cachePool!==null&&(c=n.alternate.memoizedState.cachePool.pool),d=null,n.memoizedState!==null&&n.memoizedState.cachePool!==null&&(d=n.memoizedState.cachePool.pool),d!==c&&(n.flags|=2048)),a!==s&&a&&(t.child.flags|=8192),bc(t,t.updateQueue),Js(t),null);case 4:return J(),s===null&&hu(t.stateNode.containerInfo),Js(t),null;case 10:return el(t.type),Js(t),null;case 19:if(Ne(ft),n=t.memoizedState,n===null)return Js(t),null;if(c=(t.flags&128)!==0,d=n.rendering,d===null)if(c)Yi(n,!1);else{if(ct!==0||s!==null&&(s.flags&128)!==0)for(s=t.child;s!==null;){if(d=rc(s),d!==null){for(t.flags|=128,Yi(n,!1),s=d.updateQueue,t.updateQueue=s,bc(t,s),t.subtreeFlags=0,s=a,a=t.child;a!==null;)ux(a,s),a=a.sibling;return Ce(ft,ft.current&1|2),Cs&&Za(t,n.treeForkCount),t.child}s=s.sibling}n.tail!==null&&nt()>Sc&&(t.flags|=128,c=!0,Yi(n,!1),t.lanes=4194304)}else{if(!c)if(s=rc(d),s!==null){if(t.flags|=128,c=!0,s=s.updateQueue,t.updateQueue=s,bc(t,s),Yi(n,!0),n.tail===null&&n.tailMode==="hidden"&&!d.alternate&&!Cs)return Js(t),null}else 2*nt()-n.renderingStartTime>Sc&&a!==536870912&&(t.flags|=128,c=!0,Yi(n,!1),t.lanes=4194304);n.isBackwards?(d.sibling=t.child,t.child=d):(s=n.last,s!==null?s.sibling=d:t.child=d,n.last=d)}return n.tail!==null?(s=n.tail,n.rendering=s,n.tail=s.sibling,n.renderingStartTime=nt(),s.sibling=null,a=ft.current,Ce(ft,c?a&1|2:a&1),Cs&&Za(t,n.treeForkCount),s):(Js(t),null);case 22:case 23:return ca(t),fd(),n=t.memoizedState!==null,s!==null?s.memoizedState!==null!==n&&(t.flags|=8192):n&&(t.flags|=8192),n?(a&536870912)!==0&&(t.flags&128)===0&&(Js(t),t.subtreeFlags&6&&(t.flags|=8192)):Js(t),a=t.updateQueue,a!==null&&bc(t,a.retryQueue),a=null,s!==null&&s.memoizedState!==null&&s.memoizedState.cachePool!==null&&(a=s.memoizedState.cachePool.pool),n=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(n=t.memoizedState.cachePool.pool),n!==a&&(t.flags|=2048),s!==null&&Ne(ln),null;case 24:return a=null,s!==null&&(a=s.memoizedState.cache),t.memoizedState.cache!==a&&(t.flags|=2048),el(vt),Js(t),null;case 25:return null;case 30:return null}throw Error(o(156,t.tag))}function vb(s,t){switch(ed(t),t.tag){case 1:return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 3:return el(vt),J(),s=t.flags,(s&65536)!==0&&(s&128)===0?(t.flags=s&-65537|128,t):null;case 26:case 27:case 5:return qe(t),null;case 31:if(t.memoizedState!==null){if(ca(t),t.alternate===null)throw Error(o(340));sn()}return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 13:if(ca(t),s=t.memoizedState,s!==null&&s.dehydrated!==null){if(t.alternate===null)throw Error(o(340));sn()}return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 19:return Ne(ft),null;case 4:return J(),null;case 10:return el(t.type),null;case 22:case 23:return ca(t),fd(),s!==null&&Ne(ln),s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 24:return el(vt),null;case 25:return null;default:return null}}function Bh(s,t){switch(ed(t),t.tag){case 3:el(vt),J();break;case 26:case 27:case 5:qe(t);break;case 4:J();break;case 31:t.memoizedState!==null&&ca(t);break;case 13:ca(t);break;case 19:Ne(ft);break;case 10:el(t.type);break;case 22:case 23:ca(t),fd(),s!==null&&Ne(ln);break;case 24:el(vt)}}function Ki(s,t){try{var a=t.updateQueue,n=a!==null?a.lastEffect:null;if(n!==null){var c=n.next;a=c;do{if((a.tag&s)===s){n=void 0;var d=a.create,p=a.inst;n=d(),p.destroy=n}a=a.next}while(a!==c)}}catch(N){Rs(t,t.return,N)}}function El(s,t,a){try{var n=t.updateQueue,c=n!==null?n.lastEffect:null;if(c!==null){var d=c.next;n=d;do{if((n.tag&s)===s){var p=n.inst,N=p.destroy;if(N!==void 0){p.destroy=void 0,c=t;var M=a,K=N;try{K()}catch(ce){Rs(c,M,ce)}}}n=n.next}while(n!==d)}}catch(ce){Rs(t,t.return,ce)}}function Hh(s){var t=s.updateQueue;if(t!==null){var a=s.stateNode;try{Ex(t,a)}catch(n){Rs(s,s.return,n)}}}function $h(s,t,a){a.props=dn(s.type,s.memoizedProps),a.state=s.memoizedState;try{a.componentWillUnmount()}catch(n){Rs(s,t,n)}}function Xi(s,t){try{var a=s.ref;if(a!==null){switch(s.tag){case 26:case 27:case 5:var n=s.stateNode;break;case 30:n=s.stateNode;break;default:n=s.stateNode}typeof a=="function"?s.refCleanup=a(n):a.current=n}}catch(c){Rs(s,t,c)}}function $a(s,t){var a=s.ref,n=s.refCleanup;if(a!==null)if(typeof n=="function")try{n()}catch(c){Rs(s,t,c)}finally{s.refCleanup=null,s=s.alternate,s!=null&&(s.refCleanup=null)}else if(typeof a=="function")try{a(null)}catch(c){Rs(s,t,c)}else a.current=null}function qh(s){var t=s.type,a=s.memoizedProps,n=s.stateNode;try{e:switch(t){case"button":case"input":case"select":case"textarea":a.autoFocus&&n.focus();break e;case"img":a.src?n.src=a.src:a.srcSet&&(n.srcset=a.srcSet)}}catch(c){Rs(s,s.return,c)}}function Yd(s,t,a){try{var n=s.stateNode;qb(n,s.type,a,t),n[Qt]=t}catch(c){Rs(s,s.return,c)}}function Gh(s){return s.tag===5||s.tag===3||s.tag===26||s.tag===27&&Ll(s.type)||s.tag===4}function Kd(s){e:for(;;){for(;s.sibling===null;){if(s.return===null||Gh(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&&Ll(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 Xd(s,t,a){var n=s.tag;if(n===5||n===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=Xa));else if(n!==4&&(n===27&&Ll(s.type)&&(a=s.stateNode,t=null),s=s.child,s!==null))for(Xd(s,t,a),s=s.sibling;s!==null;)Xd(s,t,a),s=s.sibling}function Nc(s,t,a){var n=s.tag;if(n===5||n===6)s=s.stateNode,t?a.insertBefore(s,t):a.appendChild(s);else if(n!==4&&(n===27&&Ll(s.type)&&(a=s.stateNode),s=s.child,s!==null))for(Nc(s,t,a),s=s.sibling;s!==null;)Nc(s,t,a),s=s.sibling}function Vh(s){var t=s.stateNode,a=s.memoizedProps;try{for(var n=s.type,c=t.attributes;c.length;)t.removeAttributeNode(c[0]);Bt(t,n,a),t[Dt]=s,t[Qt]=a}catch(d){Rs(s,s.return,d)}}var nl=!1,yt=!1,Pd=!1,Fh=typeof WeakSet=="function"?WeakSet:Set,Mt=null;function bb(s,t){if(s=s.containerInfo,gu=Gc,s=tx(s),Vo(s)){if("selectionStart"in s)var a={start:s.selectionStart,end:s.selectionEnd};else e:{a=(a=s.ownerDocument)&&a.defaultView||window;var n=a.getSelection&&a.getSelection();if(n&&n.rangeCount!==0){a=n.anchorNode;var c=n.anchorOffset,d=n.focusNode;n=n.focusOffset;try{a.nodeType,d.nodeType}catch{a=null;break e}var p=0,N=-1,M=-1,K=0,ce=0,he=s,Z=null;s:for(;;){for(var ae;he!==a||c!==0&&he.nodeType!==3||(N=p+c),he!==d||n!==0&&he.nodeType!==3||(M=p+n),he.nodeType===3&&(p+=he.nodeValue.length),(ae=he.firstChild)!==null;)Z=he,he=ae;for(;;){if(he===s)break s;if(Z===a&&++K===c&&(N=p),Z===d&&++ce===n&&(M=p),(ae=he.nextSibling)!==null)break;he=Z,Z=he.parentNode}he=ae}a=N===-1||M===-1?null:{start:N,end:M}}else a=null}a=a||{start:0,end:0}}else a=null;for(ju={focusedElem:s,selectionRange:a},Gc=!1,Mt=t;Mt!==null;)if(t=Mt,s=t.child,(t.subtreeFlags&1028)!==0&&s!==null)s.return=t,Mt=s;else for(;Mt!==null;){switch(t=Mt,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"))),Bt(d,n,a),d[Dt]=s,zt(d),n=d;break e;case"link":var p=Jf("link","href",c).get(n+(a.href||""));if(p){for(var N=0;N$s&&(p=$s,$s=Ke,Ke=p);var q=ex(N,Ke),R=ex(N,$s);if(q&&R&&(ae.rangeCount!==1||ae.anchorNode!==q.node||ae.anchorOffset!==q.offset||ae.focusNode!==R.node||ae.focusOffset!==R.offset)){var Y=he.createRange();Y.setStart(q.node,q.offset),ae.removeAllRanges(),Ke>$s?(ae.addRange(Y),ae.extend(R.node,R.offset)):(Y.setEnd(R.node,R.offset),ae.addRange(Y))}}}}for(he=[],ae=N;ae=ae.parentNode;)ae.nodeType===1&&he.push({element:ae,left:ae.scrollLeft,top:ae.scrollTop});for(typeof N.focus=="function"&&N.focus(),N=0;Na?32:a,U.T=null,a=au,au=null;var d=Ol,p=dl;if(St=0,Wn=Ol=null,dl=0,(zs&6)!==0)throw Error(o(331));var N=zs;if(zs|=4,sf(d.current),Zh(d,d.current,p,a),zs=N,sr(0,!1),ts&&typeof ts.onPostCommitFiberRoot=="function")try{ts.onPostCommitFiberRoot(Ls,d)}catch{}return!0}finally{P.p=c,U.T=n,bf(s,t)}}function yf(s,t,a){t=ga(a,t),t=Ld(s.stateNode,t,2),s=Cl(s,t,2),s!==null&&(ke(s,2),qa(s))}function Rs(s,t,a){if(s.tag===3)yf(s,s,a);else for(;t!==null;){if(t.tag===3){yf(t,s,a);break}else if(t.tag===1){var n=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof n.componentDidCatch=="function"&&(Al===null||!Al.has(n))){s=ga(a,s),a=yh(2),n=Cl(t,a,2),n!==null&&(wh(a,n,t,s),ke(n,2),qa(n));break}}t=t.return}}function ru(s,t,a){var n=s.pingCache;if(n===null){n=s.pingCache=new wb;var c=new Set;n.set(t,c)}else c=n.get(t),c===void 0&&(c=new Set,n.set(t,c));c.has(a)||(Wd=!0,c.add(a),s=Tb.bind(null,s,t,a),t.then(s,s))}function Tb(s,t,a){var n=s.pingCache;n!==null&&n.delete(t),s.pingedLanes|=s.suspendedLanes&a,s.warmLanes&=~a,Fs===s&&(ws&a)===a&&(ct===4||ct===3&&(ws&62914560)===ws&&300>nt()-_c?(zs&2)===0&&ei(s,0):eu|=a,Zn===ws&&(Zn=0)),qa(s)}function wf(s,t){t===0&&(t=I()),s=Wl(s,t),s!==null&&(ke(s,t),qa(s))}function Eb(s){var t=s.memoizedState,a=0;t!==null&&(a=t.retryLane),wf(s,a)}function zb(s,t){var a=0;switch(s.tag){case 31:case 13:var n=s.stateNode,c=s.memoizedState;c!==null&&(a=c.retryLane);break;case 19:n=s.stateNode;break;case 22:n=s.stateNode._retryCache;break;default:throw Error(o(314))}n!==null&&n.delete(t),wf(s,a)}function Mb(s,t){return Ie(s,t)}var Mc=null,ti=null,cu=!1,Ac=!1,ou=!1,Rl=0;function qa(s){s!==ti&&s.next===null&&(ti===null?Mc=ti=s:ti=ti.next=s),Ac=!0,cu||(cu=!0,Ob())}function sr(s,t){if(!ou&&Ac){ou=!0;do for(var a=!1,n=Mc;n!==null;){if(s!==0){var c=n.pendingLanes;if(c===0)var d=0;else{var p=n.suspendedLanes,N=n.pingedLanes;d=(1<<31-Xe(42|s)+1)-1,d&=c&~(p&~N),d=d&201326741?d&201326741|1:d?d|2:0}d!==0&&(a=!0,kf(n,d))}else d=ws,d=ys(n,n===Fs?d:0,n.cancelPendingCommit!==null||n.timeoutHandle!==-1),(d&3)===0||Tt(n,d)||(a=!0,kf(n,d));n=n.next}while(a);ou=!1}}function Ab(){_f()}function _f(){Ac=cu=!1;var s=0;Rl!==0&&Vb()&&(s=Rl);for(var t=nt(),a=null,n=Mc;n!==null;){var c=n.next,d=Sf(n,t);d===0?(n.next=null,a===null?Mc=c:a.next=c,c===null&&(ti=a)):(a=n,(s!==0||(d&3)!==0)&&(Ac=!0)),n=c}St!==0&&St!==5||sr(s),Rl!==0&&(Rl=0)}function Sf(s,t){for(var a=s.suspendedLanes,n=s.pingedLanes,c=s.expirationTimes,d=s.pendingLanes&-62914561;0N)break;var ce=M.transferSize,he=M.initiatorType;ce&&Rf(he)&&(M=M.responseEnd,p+=ce*(M"u"?null:document;function Yf(s,t,a){var n=ai;if(n&&typeof t=="string"&&t){var c=fa(t);c='link[rel="'+s+'"][href="'+c+'"]',typeof a=="string"&&(c+='[crossorigin="'+a+'"]'),Qf.has(c)||(Qf.add(c),s={rel:s,crossOrigin:a,href:t},n.querySelector(c)===null&&(t=n.createElement("link"),Bt(t,"link",s),zt(t),n.head.appendChild(t)))}}function Zb(s){ul.D(s),Yf("dns-prefetch",s,null)}function Wb(s,t){ul.C(s,t),Yf("preconnect",s,t)}function eN(s,t,a){ul.L(s,t,a);var n=ai;if(n&&s&&t){var c='link[rel="preload"][as="'+fa(t)+'"]';t==="image"&&a&&a.imageSrcSet?(c+='[imagesrcset="'+fa(a.imageSrcSet)+'"]',typeof a.imageSizes=="string"&&(c+='[imagesizes="'+fa(a.imageSizes)+'"]')):c+='[href="'+fa(s)+'"]';var d=c;switch(t){case"style":d=li(s);break;case"script":d=ni(s)}wa.has(d)||(s=y({rel:"preload",href:t==="image"&&a&&a.imageSrcSet?void 0:s,as:t},a),wa.set(d,s),n.querySelector(c)!==null||t==="style"&&n.querySelector(nr(d))||t==="script"&&n.querySelector(ir(d))||(t=n.createElement("link"),Bt(t,"link",s),zt(t),n.head.appendChild(t)))}}function sN(s,t){ul.m(s,t);var a=ai;if(a&&s){var n=t&&typeof t.as=="string"?t.as:"script",c='link[rel="modulepreload"][as="'+fa(n)+'"][href="'+fa(s)+'"]',d=c;switch(n){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":d=ni(s)}if(!wa.has(d)&&(s=y({rel:"modulepreload",href:s},t),wa.set(d,s),a.querySelector(c)===null)){switch(n){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(a.querySelector(ir(d)))return}n=a.createElement("link"),Bt(n,"link",s),zt(n),a.head.appendChild(n)}}}function tN(s,t,a){ul.S(s,t,a);var n=ai;if(n&&s){var c=Cn(n).hoistableStyles,d=li(s);t=t||"default";var p=c.get(d);if(!p){var N={loading:0,preload:null};if(p=n.querySelector(nr(d)))N.loading=5;else{s=y({rel:"stylesheet",href:s,"data-precedence":t},a),(a=wa.get(d))&&Su(s,a);var M=p=n.createElement("link");zt(M),Bt(M,"link",s),M._p=new Promise(function(K,ce){M.onload=K,M.onerror=ce}),M.addEventListener("load",function(){N.loading|=1}),M.addEventListener("error",function(){N.loading|=2}),N.loading|=4,Uc(p,t,n)}p={type:"stylesheet",instance:p,count:1,state:N},c.set(d,p)}}}function aN(s,t){ul.X(s,t);var a=ai;if(a&&s){var n=Cn(a).hoistableScripts,c=ni(s),d=n.get(c);d||(d=a.querySelector(ir(c)),d||(s=y({src:s,async:!0},t),(t=wa.get(c))&&Cu(s,t),d=a.createElement("script"),zt(d),Bt(d,"link",s),a.head.appendChild(d)),d={type:"script",instance:d,count:1,state:null},n.set(c,d))}}function lN(s,t){ul.M(s,t);var a=ai;if(a&&s){var n=Cn(a).hoistableScripts,c=ni(s),d=n.get(c);d||(d=a.querySelector(ir(c)),d||(s=y({src:s,async:!0,type:"module"},t),(t=wa.get(c))&&Cu(s,t),d=a.createElement("script"),zt(d),Bt(d,"link",s),a.head.appendChild(d)),d={type:"script",instance:d,count:1,state:null},n.set(c,d))}}function Kf(s,t,a,n){var c=(c=Q.current)?Lc(c):null;if(!c)throw Error(o(446));switch(s){case"meta":case"title":return null;case"style":return typeof a.precedence=="string"&&typeof a.href=="string"?(t=li(a.href),a=Cn(c).hoistableStyles,n=a.get(t),n||(n={type:"style",instance:null,count:0,state:null},a.set(t,n)),n):{type:"void",instance:null,count:0,state:null};case"link":if(a.rel==="stylesheet"&&typeof a.href=="string"&&typeof a.precedence=="string"){s=li(a.href);var d=Cn(c).hoistableStyles,p=d.get(s);if(p||(c=c.ownerDocument||c,p={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},d.set(s,p),(d=c.querySelector(nr(s)))&&!d._p&&(p.instance=d,p.state.loading=5),wa.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},wa.set(s,a),d||nN(c,s,a,p.state))),t&&n===null)throw Error(o(528,""));return p}if(t&&n!==null)throw Error(o(529,""));return null;case"script":return t=a.async,a=a.src,typeof a=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=ni(a),a=Cn(c).hoistableScripts,n=a.get(t),n||(n={type:"script",instance:null,count:0,state:null},a.set(t,n)),n):{type:"void",instance:null,count:0,state:null};default:throw Error(o(444,s))}}function li(s){return'href="'+fa(s)+'"'}function nr(s){return'link[rel="stylesheet"]['+s+"]"}function Xf(s){return y({},s,{"data-precedence":s.precedence,precedence:null})}function nN(s,t,a,n){s.querySelector('link[rel="preload"][as="style"]['+t+"]")?n.loading=1:(t=s.createElement("link"),n.preload=t,t.addEventListener("load",function(){return n.loading|=1}),t.addEventListener("error",function(){return n.loading|=2}),Bt(t,"link",a),zt(t),s.head.appendChild(t))}function ni(s){return'[src="'+fa(s)+'"]'}function ir(s){return"script[async]"+s}function Pf(s,t,a){if(t.count++,t.instance===null)switch(t.type){case"style":var n=s.querySelector('style[data-href~="'+fa(a.href)+'"]');if(n)return t.instance=n,zt(n),n;var c=y({},a,{"data-href":a.href,"data-precedence":a.precedence,href:null,precedence:null});return n=(s.ownerDocument||s).createElement("style"),zt(n),Bt(n,"style",c),Uc(n,a.precedence,s),t.instance=n;case"stylesheet":c=li(a.href);var d=s.querySelector(nr(c));if(d)return t.state.loading|=4,t.instance=d,zt(d),d;n=Xf(a),(c=wa.get(c))&&Su(n,c),d=(s.ownerDocument||s).createElement("link"),zt(d);var p=d;return p._p=new Promise(function(N,M){p.onload=N,p.onerror=M}),Bt(d,"link",n),t.state.loading|=4,Uc(d,a.precedence,s),t.instance=d;case"script":return d=ni(a.src),(c=s.querySelector(ir(d)))?(t.instance=c,zt(c),c):(n=a,(c=wa.get(d))&&(n=y({},a),Cu(n,c)),s=s.ownerDocument||s,c=s.createElement("script"),zt(c),Bt(c,"link",n),s.head.appendChild(c),t.instance=c);case"void":return null;default:throw Error(o(443,t.type))}else t.type==="stylesheet"&&(t.state.loading&4)===0&&(n=t.instance,t.state.loading|=4,Uc(n,a.precedence,s));return t.instance}function Uc(s,t,a){for(var n=a.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),c=n.length?n[n.length-1]:null,d=c,p=0;p title"):null)}function iN(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 Wf(s){return!(s.type==="stylesheet"&&(s.state.loading&3)===0)}function rN(s,t,a,n){if(a.type==="stylesheet"&&(typeof n.media!="string"||matchMedia(n.media).matches!==!1)&&(a.state.loading&4)===0){if(a.instance===null){var c=li(n.href),d=t.querySelector(nr(c));if(d){t=d._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(s.count++,s=Hc.bind(s),t.then(s,s)),a.state.loading|=4,a.instance=d,zt(d);return}d=t.ownerDocument||t,n=Xf(n),(c=wa.get(c))&&Su(n,c),d=d.createElement("link"),zt(d);var p=d;p._p=new Promise(function(N,M){p.onload=N,p.onerror=M}),Bt(d,"link",n),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=Hc.bind(s),t.addEventListener("load",a),t.addEventListener("error",a))}}var ku=0;function cN(s,t){return s.stylesheets&&s.count===0&&qc(s,s.stylesheets),0ku?50:800)+t);return s.unsuspend=a,function(){s.unsuspend=null,clearTimeout(n),clearTimeout(c)}}:null}function Hc(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)qc(this,this.stylesheets);else if(this.unsuspend){var s=this.unsuspend;this.unsuspend=null,s()}}}var $c=null;function qc(s,t){s.stylesheets=null,s.unsuspend!==null&&(s.count++,$c=new Map,t.forEach(oN,s),$c=null,Hc.call(s))}function oN(s,t){if(!(t.state.loading&4)){var a=$c.get(s);if(a)var n=a.get(null);else{a=new Map,$c.set(s,a);for(var c=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(i){console.error(i)}}return l(),Bu.exports=D0(),Bu.exports}var L0=R0();function H(...l){return TN(EN(l))}const Ve=m.forwardRef(({className:l,...i},r)=>e.jsx("div",{ref:r,className:H("rounded-xl border bg-card text-card-foreground shadow",l),...i}));Ve.displayName="Card";const rs=m.forwardRef(({className:l,...i},r)=>e.jsx("div",{ref:r,className:H("flex flex-col space-y-1.5 p-6",l),...i}));rs.displayName="CardHeader";const cs=m.forwardRef(({className:l,...i},r)=>e.jsx("div",{ref:r,className:H("font-semibold leading-none tracking-tight",l),...i}));cs.displayName="CardTitle";const st=m.forwardRef(({className:l,...i},r)=>e.jsx("div",{ref:r,className:H("text-sm text-muted-foreground",l),...i}));st.displayName="CardDescription";const gs=m.forwardRef(({className:l,...i},r)=>e.jsx("div",{ref:r,className:H("p-6 pt-0",l),...i}));gs.displayName="CardContent";const tj=m.forwardRef(({className:l,...i},r)=>e.jsx("div",{ref:r,className:H("flex items-center p-6 pt-0",l),...i}));tj.displayName="CardFooter";const Sa=MN,xa=m.forwardRef(({className:l,...i},r)=>e.jsx(Fp,{ref:r,className:H("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",l),...i}));xa.displayName=Fp.displayName;const is=m.forwardRef(({className:l,...i},r)=>e.jsx(Ip,{ref:r,className:H("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),...i}));is.displayName=Ip.displayName;const As=m.forwardRef(({className:l,...i},r)=>e.jsx(Qp,{ref:r,className:H("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),...i}));As.displayName=Qp.displayName;const Ze=m.forwardRef(({className:l,children:i,viewportRef:r,...o},u)=>e.jsxs(Yp,{ref:u,className:H("relative overflow-hidden",l),...o,children:[e.jsx(AN,{ref:r,className:"h-full w-full rounded-[inherit]",children:i}),e.jsx(sm,{}),e.jsx(sm,{orientation:"horizontal"}),e.jsx(ON,{})]}));Ze.displayName=Yp.displayName;const sm=m.forwardRef(({className:l,orientation:i="vertical",...r},o)=>e.jsx(Kp,{ref:o,orientation:i,className:H("flex touch-none select-none transition-colors",i==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",i==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",l),...r,children:e.jsx(DN,{className:"relative flex-1 rounded-full bg-border"})}));sm.displayName=Kp.displayName;function aj({className:l,...i}){return e.jsx("div",{className:H("animate-pulse rounded-md bg-primary/10",l),...i})}const gn=m.forwardRef(({className:l,value:i,...r},o)=>e.jsx(Xp,{ref:o,className:H("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",l),...r,children:e.jsx(RN,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(i||0)}%)`}})}));gn.displayName=Xp.displayName;async function we(l,i){const o=i?.body instanceof FormData?{...i?.headers}:{"Content-Type":"application/json",...i?.headers},u={...i,credentials:"include",headers:o},x=await fetch(l,u);if(x.status===401)throw window.location.href="/auth",new Error("认证失败,请重新登录");return x}function Is(){return{"Content-Type":"application/json"}}async function U0(){try{await fetch("/api/webui/auth/logout",{method:"POST",credentials:"include"})}catch(l){console.error("登出请求失败:",l)}window.location.href="/auth"}async function om(){try{return(await(await fetch("/api/webui/auth/check",{method:"GET",credentials:"include"})).json()).authenticated===!0}catch{return!1}}const B0={light:"",dark:".dark"},lj=m.createContext(null);function nj(){const l=m.useContext(lj);if(!l)throw new Error("useChart must be used within a ");return l}const oi=m.forwardRef(({id:l,className:i,children:r,config:o,...u},x)=>{const h=m.useId(),f=`chart-${l||h.replace(/:/g,"")}`;return e.jsx(lj.Provider,{value:{config:o},children:e.jsxs("div",{"data-chart":f,ref:x,className:H("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",i),...u,children:[e.jsx(H0,{id:f,config:o}),e.jsx(JN,{children:r})]})})});oi.displayName="Chart";const H0=({id:l,config:i})=>{const r=Object.entries(i).filter(([,o])=>o.theme||o.color);return r.length?e.jsx("style",{dangerouslySetInnerHTML:{__html:Object.entries(B0).map(([o,u])=>` ${u} [data-chart=${l}] { ${r.map(([x,h])=>{const f=h.theme?.[o]||h.color;return f?` --color-${x}: ${f};`:null}).join(` `)} } `).join(` `)}}):null},xr=ZN,di=m.forwardRef(({active:l,payload:i,className:r,indicator:o="dot",hideLabel:u=!1,hideIndicator:x=!1,label:h,labelFormatter:f,labelClassName:g,formatter:j,color:v,nameKey:y,labelKey:b},S)=>{const{config:w}=nj(),O=m.useMemo(()=>{if(u||!i?.length)return null;const[D]=i,V=`${b||D?.dataKey||D?.name||"value"}`,z=tm(w,D,V),_=!b&&typeof h=="string"?w[h]?.label||h:z?.label;return f?e.jsx("div",{className:H("font-medium",g),children:f(_,i)}):_?e.jsx("div",{className:H("font-medium",g),children:_}):null},[h,f,i,u,g,w,b]);if(!l||!i?.length)return null;const A=i.length===1&&o!=="dot";return e.jsxs("div",{ref:S,className:H("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",r),children:[A?null:O,e.jsx("div",{className:"grid gap-1.5",children:i.filter(D=>D.type!=="none").map((D,V)=>{const z=`${y||D.name||D.dataKey||"value"}`,_=tm(w,D,z),T=v||D.payload.fill||D.color;return e.jsx("div",{className:H("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",o==="dot"&&"items-center"),children:j&&D?.value!==void 0&&D.name?j(D.value,D.name,D,V,D.payload):e.jsxs(e.Fragment,{children:[_?.icon?e.jsx(_.icon,{}):!x&&e.jsx("div",{className:H("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":o==="dot","w-1":o==="line","w-0 border-[1.5px] border-dashed bg-transparent":o==="dashed","my-0.5":A&&o==="dashed"}),style:{"--color-bg":T,"--color-border":T}}),e.jsxs("div",{className:H("flex flex-1 justify-between leading-none",A?"items-end":"items-center"),children:[e.jsxs("div",{className:"grid gap-1.5",children:[A?O:null,e.jsx("span",{className:"text-muted-foreground",children:_?.label||D.name})]}),D.value&&e.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:D.value.toLocaleString()})]})]})},D.dataKey)})})]})});di.displayName="ChartTooltip";const $0=WN,ij=m.forwardRef(({className:l,hideIcon:i=!1,payload:r,verticalAlign:o="bottom",nameKey:u},x)=>{const{config:h}=nj();return r?.length?e.jsx("div",{ref:x,className:H("flex items-center justify-center gap-4",o==="top"?"pb-3":"pt-3",l),children:r.filter(f=>f.type!=="none").map(f=>{const g=`${u||f.dataKey||"value"}`,j=tm(h,f,g);return e.jsxs("div",{className:H("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[j?.icon&&!i?e.jsx(j.icon,{}):e.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:f.color}}),j?.label]},f.value)})}):null});ij.displayName="ChartLegend";function tm(l,i,r){if(typeof i!="object"||i===null)return;const o="payload"in i&&typeof i.payload=="object"&&i.payload!==null?i.payload:void 0;let u=r;return r in i&&typeof i[r]=="string"?u=i[r]:o&&r in o&&typeof o[r]=="string"&&(u=o[r]),u in l?l[u]:l[r]}const Sr=gi("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"}}),C=m.forwardRef(({className:l,variant:i,size:r,asChild:o=!1,...u},x)=>{const h=o?ny:"button";return e.jsx(h,{className:H(Sr({variant:i,size:r,className:l})),ref:x,...u})});C.displayName="Button";const q0=gi("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 Ye({className:l,variant:i,...r}){return e.jsx("div",{className:H(q0({variant:i}),l),...r})}async function G0(){const l=await we("/api/webui/system/restart",{method:"POST",headers:Is()});if(!l.ok){const i=await l.json();throw new Error(i.detail||"重启失败")}return await l.json()}async function V0(){const l=await we("/api/webui/system/status",{method:"GET",headers:Is()});if(!l.ok){const i=await l.json();throw new Error(i.detail||"获取状态失败")}return await l.json()}const ri={INITIAL_DELAY:3e3,CHECK_INTERVAL:2e3,CHECK_TIMEOUT:3e3,MAX_ATTEMPTS:60,PROGRESS_INTERVAL:200,SUCCESS_REDIRECT_DELAY:1500},rj=m.createContext(null);function jn({children:l,onRestartComplete:i,onRestartFailed:r,healthCheckUrl:o="/api/webui/system/status",maxAttempts:u=ri.MAX_ATTEMPTS}){const[x,h]=m.useState({status:"idle",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:u}),[f,g]=m.useState({}),j=m.useCallback(()=>{f.progress&&clearInterval(f.progress),f.elapsed&&clearInterval(f.elapsed),f.check&&clearTimeout(f.check),g({})},[f]),v=m.useCallback(()=>{j(),h({status:"idle",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:u})},[j,u]),y=m.useCallback(async()=>{try{const A=new AbortController,D=setTimeout(()=>A.abort(),ri.CHECK_TIMEOUT),V=await fetch(o,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"include",signal:A.signal});return clearTimeout(D),V.ok}catch{return!1}},[o]),b=m.useCallback(()=>{let A=0;const D=async()=>{if(A++,h(z=>({...z,status:"checking",checkAttempts:A})),await y())j(),h(z=>({...z,status:"success",progress:100})),setTimeout(()=>{i?.(),window.location.href="/auth"},ri.SUCCESS_REDIRECT_DELAY);else if(A>=u){j();const z=`健康检查超时 (${A}/${u})`;h(_=>({..._,status:"failed",error:z})),r?.(z)}else{const z=setTimeout(D,ri.CHECK_INTERVAL);g(_=>({..._,check:z}))}};D()},[y,j,u,i,r]),S=m.useCallback(()=>{h(A=>({...A,status:"checking",checkAttempts:0,error:void 0})),b()},[b]),w=m.useCallback(async A=>{const{delay:D=0,skipApiCall:V=!1}=A??{};if(x.status!=="idle"&&x.status!=="failed")return;if(j(),h({status:"requesting",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:u}),D>0&&await new Promise(T=>setTimeout(T,D)),V)h(T=>({...T,status:"restarting"}));else try{h(T=>({...T,status:"restarting"})),await Promise.race([G0(),new Promise(T=>setTimeout(T,5e3))])}catch{}const z=setInterval(()=>{h(T=>({...T,progress:T.progress>=90?T.progress:T.progress+1}))},ri.PROGRESS_INTERVAL),_=setInterval(()=>{h(T=>({...T,elapsedTime:T.elapsedTime+1}))},1e3);g({progress:z,elapsed:_}),setTimeout(()=>{b()},ri.INITIAL_DELAY)},[x.status,j,u,b]),O={state:x,isRestarting:x.status!=="idle",triggerRestart:w,resetState:v,retryHealthCheck:S};return e.jsx(rj.Provider,{value:O,children:l})}function Il(){const l=m.useContext(rj);if(!l)throw new Error("useRestart must be used within a RestartProvider");return l}const F0=(l,i,r,o,u)=>({idle:{icon:null,title:"",description:"",tip:""},requesting:{icon:e.jsx(tt,{className:"h-16 w-16 text-primary animate-spin"}),title:o??"准备重启",description:u??"正在发送重启请求...",tip:"🔄 正在准备重启麦麦..."},restarting:{icon:e.jsx(tt,{className:"h-16 w-16 text-primary animate-spin"}),title:o??"正在重启麦麦",description:u??"请稍候,麦麦正在重启中...",tip:"🔄 配置已保存,正在重启主程序..."},checking:{icon:e.jsx(tt,{className:"h-16 w-16 text-primary animate-spin"}),title:"检查服务状态",description:`等待服务恢复... (${i}/${r})`,tip:"⏳ 正在等待服务恢复,请勿关闭页面..."},success:{icon:e.jsx(aa,{className:"h-16 w-16 text-green-500"}),title:"重启成功",description:"正在跳转到登录页面...",tip:"✅ 配置已生效,服务运行正常"},failed:{icon:e.jsx(Ot,{className:"h-16 w-16 text-destructive"}),title:"重启超时",description:"服务未能在预期时间内恢复",tip:"⚠️ 如果长时间无响应,请尝试手动重启"}})[l];function vn({visible:l,onComplete:i,onFailed:r,title:o,description:u,showAnimation:x=!0,className:h}){let f=null;try{f=Il()}catch{}return(f?f.isRestarting:l)?f?e.jsx(cj,{state:f.state,onRetry:f.retryHealthCheck,onComplete:i,onFailed:r,title:o,description:u,showAnimation:x,className:h}):e.jsx(I0,{onComplete:i,onFailed:r,title:o,description:u,showAnimation:x,className:h}):null}function cj({state:l,onRetry:i,onComplete:r,onFailed:o,title:u,description:x,showAnimation:h,className:f}){const{status:g,progress:j,elapsedTime:v,checkAttempts:y,maxAttempts:b}=l;m.useEffect(()=>{g==="success"&&r?r():g==="failed"&&o&&o()},[g,r,o]);const S=F0(g,y,b,u,x),w=O=>{const A=Math.floor(O/60),D=O%60;return`${A}:${D.toString().padStart(2,"0")}`};return e.jsxs("div",{className:H("fixed inset-0 bg-background/95 backdrop-blur-sm z-50 flex items-center justify-center",f),children:[h&&e.jsx(Q0,{}),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:[S.icon,(g==="restarting"||g==="checking")&&e.jsx("div",{className:"absolute inset-0 rounded-full bg-primary/20 animate-ping"})]}),e.jsx("h2",{className:"text-2xl font-bold",children:S.title}),e.jsx("p",{className:"text-muted-foreground text-center",children:S.description})]}),g!=="failed"&&g!=="idle"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(gn,{value:j,className:"h-2"}),e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:[j,"%"]}),e.jsxs("span",{children:["已用时: ",w(v)]})]})]}),e.jsx("div",{className:"bg-muted/50 rounded-lg p-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:S.tip})}),g==="failed"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{onClick:()=>window.location.reload(),variant:"default",className:"flex-1",children:[e.jsx(At,{className:"mr-2 h-4 w-4"}),"刷新页面"]}),e.jsxs(C,{onClick:i,variant:"secondary",className:"flex-1",children:[e.jsx(yr,{className:"mr-2 h-4 w-4"}),"重试检测"]})]})]})]})}function I0({onComplete:l,onFailed:i,title:r,description:o,showAnimation:u,className:x}){const[h,f]=m.useState({status:"restarting",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:60}),g=m.useCallback(()=>{let j=0;const v=60,y=async()=>{j++,f(b=>({...b,status:"checking",checkAttempts:j}));try{if((await fetch("/api/webui/system/status",{method:"GET",signal:AbortSignal.timeout(3e3)})).ok){f(S=>({...S,status:"success",progress:100})),setTimeout(()=>{l?.(),window.location.href="/auth"},1500);return}}catch{}j>=v?(f(b=>({...b,status:"failed"})),i?.()):setTimeout(y,2e3)};y()},[l,i]);return m.useEffect(()=>{const j=setInterval(()=>{f(b=>({...b,progress:b.progress>=90?b.progress:b.progress+1}))},200),v=setInterval(()=>{f(b=>({...b,elapsedTime:b.elapsedTime+1}))},1e3),y=setTimeout(()=>{g()},3e3);return()=>{clearInterval(j),clearInterval(v),clearTimeout(y)}},[g]),e.jsx(cj,{state:h,onRetry:g,onComplete:l,onFailed:i,title:r,description:o,showAnimation:u,className:x})}function Q0(){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 Y0(){return e.jsx(jn,{children:e.jsx(X0,{})})}const K0=l=>{const i=[];for(let r=0;r{try{S(!0);const L=await zN.get("https://v1.hitokoto.cn/?c=a&c=b&c=c&c=d&c=h&c=i&c=k");y({hitokoto:L.data.hitokoto,from:L.data.from||L.data.from_who||"未知"})}catch(L){console.error("获取一言失败:",L),y({hitokoto:"人生就像一盒巧克力,你永远不知道下一颗是什么味道。",from:"阿甘正传"})}finally{S(!1)}},[]),z=m.useCallback(async()=>{try{const L=await we("/api/webui/system/status");if(L.ok){const B=await L.json();O(B)}else O(null)}catch(L){console.error("获取机器人状态失败:",L),O(null)}},[]),_=async()=>{await A()},T=m.useCallback(async()=>{try{const L=await we(`/api/webui/statistics/dashboard?hours=${h}`);if(L.ok){const B=await L.json();i(B)}o(!1),x(100)}catch(L){console.error("Failed to fetch dashboard data:",L),o(!1),x(100)}},[h]);if(m.useEffect(()=>{if(!r)return;x(0);const L=setTimeout(()=>x(15),200),B=setTimeout(()=>x(30),800),_e=setTimeout(()=>x(45),2e3),Ne=setTimeout(()=>x(60),4e3),Ce=setTimeout(()=>x(75),6500),ve=setTimeout(()=>x(85),9e3),ze=setTimeout(()=>x(92),11e3);return()=>{clearTimeout(L),clearTimeout(B),clearTimeout(_e),clearTimeout(Ne),clearTimeout(Ce),clearTimeout(ve),clearTimeout(ze)}},[r]),m.useEffect(()=>{T(),V(),z()},[T,V,z]),m.useEffect(()=>{if(!g)return;const L=setInterval(()=>{T(),z()},3e4);return()=>clearInterval(L)},[g,T,z]),r||!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(At,{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(gn,{value:u,className:"h-2"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[u,"%"]})]})]})});const{summary:$,model_stats:E=[],hourly_data:se=[],daily_data:te=[],recent_activity:ne=[]}=l,ue=$??{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},Se=L=>{const B=Math.floor(L/3600),_e=Math.floor(L%3600/60);return`${B}小时${_e}分钟`},oe=L=>{const B=L.toLocaleString("zh-CN");return L>=1e9?{display:`${(L/1e9).toFixed(2)}B`,exact:B,needsExact:!0}:L>=1e6?{display:`${(L/1e6).toFixed(2)}M`,exact:B,needsExact:!0}:L>=1e4?{display:`${(L/1e3).toFixed(1)}K`,exact:B,needsExact:!0}:L>=1e3?{display:`${(L/1e3).toFixed(2)}K`,exact:B,needsExact:!0}:{display:B,exact:B,needsExact:!1}},je=L=>{const B=`¥${L.toLocaleString("zh-CN",{minimumFractionDigits:2,maximumFractionDigits:2})}`;return L>=1e6?{display:`¥${(L/1e6).toFixed(2)}M`,exact:B,needsExact:!0}:L>=1e4?{display:`¥${(L/1e3).toFixed(1)}K`,exact:B,needsExact:!0}:L>=1e3?{display:`¥${(L/1e3).toFixed(2)}K`,exact:B,needsExact:!0}:{display:B,exact:B,needsExact:!1}},be=L=>new Date(L).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),U=K0(E.length),P=E.map((L,B)=>({name:L.model_name,value:L.request_count,fill:U[B]})),X={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(Ze,{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(Sa,{value:h.toString(),onValueChange:L=>f(Number(L)),children:e.jsxs(xa,{className:"grid grid-cols-3 w-full sm:w-auto",children:[e.jsx(is,{value:"24",children:"24小时"}),e.jsx(is,{value:"168",children:"7天"}),e.jsx(is,{value:"720",children:"30天"})]})}),e.jsxs(C,{variant:g?"default":"outline",size:"sm",onClick:()=>j(!g),className:"gap-2",children:[e.jsx(At,{className:`h-4 w-4 ${g?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"自动刷新"})]}),e.jsx(C,{variant:"outline",size:"sm",onClick:T,children:e.jsx(At,{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:[b?e.jsx(aj,{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(C,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:V,disabled:b,children:e.jsx(At,{className:`h-3.5 w-3.5 ${b?"animate-spin":""}`})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-3",children:[e.jsxs(Ve,{className:"lg:col-span-1",children:[e.jsx(rs,{className:"pb-3",children:e.jsxs(cs,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Mr,{className:"h-4 w-4"}),"麦麦状态"]})}),e.jsx(gs,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:w?.running?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-3 w-3 rounded-full bg-green-500 animate-pulse"}),e.jsxs(Ye,{variant:"outline",className:"text-green-600 border-green-300 bg-green-50",children:[e.jsx(aa,{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(Ye,{variant:"outline",className:"text-red-600 border-red-300 bg-red-50",children:[e.jsx(Ot,{className:"h-3 w-3 mr-1"}),"已停止"]})]})}),w&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("span",{children:["v",w.version]}),e.jsx("span",{className:"mx-2",children:"|"}),e.jsxs("span",{children:["运行 ",Se(w.uptime)]})]})]})})]}),e.jsxs(Ve,{children:[e.jsx(rs,{className:"pb-3",children:e.jsxs(cs,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(hn,{className:"h-4 w-4"}),"快速操作"]})}),e.jsx(gs,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:_,disabled:D,className:"gap-2",children:[e.jsx(yr,{className:`h-4 w-4 ${D?"animate-spin":""}`}),D?"重启中...":"重启麦麦"]}),e.jsx(C,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(ci,{to:"/logs",children:[e.jsx(Aa,{className:"h-4 w-4"}),"查看日志"]})}),e.jsx(C,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(ci,{to:"/plugins",children:[e.jsx(Ty,{className:"h-4 w-4"}),"插件管理"]})}),e.jsx(C,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(ci,{to:"/settings",children:[e.jsx(ji,{className:"h-4 w-4"}),"系统设置"]})})]})})]}),e.jsxs(Ve,{children:[e.jsxs(rs,{className:"pb-3",children:[e.jsxs(cs,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Ey,{className:"h-4 w-4"}),"反馈问卷"]}),e.jsx(st,{className:"text-xs",children:"帮助我们改进产品体验"})]}),e.jsx(gs,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(ci,{to:"/survey/webui-feedback",children:[e.jsx(Aa,{className:"h-4 w-4"}),"WebUI 反馈"]})}),e.jsx(C,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(ci,{to:"/survey/maibot-feedback",children:[e.jsx(Fl,{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(Ve,{children:[e.jsxs(rs,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(cs,{className:"text-sm font-medium",children:"总请求数"}),e.jsx(zy,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(gs,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[oe(ue.total_requests).display,oe(ue.total_requests).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",oe(ue.total_requests).exact,")"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["最近",h<48?h+"小时":Math.floor(h/24)+"天"]})]})]}),e.jsxs(Ve,{children:[e.jsxs(rs,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(cs,{className:"text-sm font-medium",children:"总花费"}),e.jsx(My,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(gs,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[je(ue.total_cost).display,je(ue.total_cost).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",je(ue.total_cost).exact,")"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:ue.cost_per_hour>0?`¥${ue.cost_per_hour.toFixed(2)}/小时`:"暂无数据"})]})]}),e.jsxs(Ve,{children:[e.jsxs(rs,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(cs,{className:"text-sm font-medium",children:"Token消耗"}),e.jsx(ro,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(gs,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[oe(ue.total_tokens).display,oe(ue.total_tokens).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",oe(ue.total_tokens).exact,")"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:ue.tokens_per_hour>0?`${oe(ue.tokens_per_hour).display}/小时`:"暂无数据"})]})]}),e.jsxs(Ve,{children:[e.jsxs(rs,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(cs,{className:"text-sm font-medium",children:"平均响应"}),e.jsx(hn,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(gs,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[ue.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(Ve,{children:[e.jsxs(rs,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(cs,{className:"text-sm font-medium",children:"在线时长"}),e.jsx(xi,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(gs,{children:e.jsxs("div",{className:"text-xl font-bold",children:[Se(ue.online_time),e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",ue.online_time.toLocaleString(),"秒)"]})]})})]}),e.jsxs(Ve,{children:[e.jsxs(rs,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(cs,{className:"text-sm font-medium",children:"消息处理"}),e.jsx(Fl,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(gs,{children:[e.jsxs("div",{className:"text-xl font-bold",children:[oe(ue.total_messages).display,oe(ue.total_messages).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",oe(ue.total_messages).exact,")"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["回复 ",oe(ue.total_replies).display,oe(ue.total_replies).needsExact&&e.jsxs("span",{children:["(",oe(ue.total_replies).exact,")"]})," 条"]})]})]}),e.jsxs(Ve,{children:[e.jsxs(rs,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(cs,{className:"text-sm font-medium",children:"成本效率"}),e.jsx(Ay,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(gs,{children:[e.jsx("div",{className:"text-xl font-bold",children:ue.total_messages>0?`¥${(ue.total_cost/ue.total_messages*100).toFixed(2)}`:"¥0.00"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"每100条消息"})]})]})]}),e.jsxs(Sa,{defaultValue:"trends",className:"space-y-4",children:[e.jsxs(xa,{className:"grid w-full grid-cols-2 sm:grid-cols-4",children:[e.jsx(is,{value:"trends",children:"趋势"}),e.jsx(is,{value:"models",children:"模型"}),e.jsx(is,{value:"activity",children:"活动"}),e.jsx(is,{value:"daily",children:"日统计"})]}),e.jsxs(As,{value:"trends",className:"space-y-4",children:[e.jsxs(Ve,{children:[e.jsxs(rs,{children:[e.jsx(cs,{children:"请求趋势"}),e.jsxs(st,{children:["最近",h,"小时的请求量变化"]})]}),e.jsx(gs,{children:e.jsx(oi,{config:X,className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(ey,{data:se,children:[e.jsx(Xc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Pc,{dataKey:"timestamp",tickFormatter:L=>be(L),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ur,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(xr,{content:e.jsx(di,{labelFormatter:L=>be(L)})}),e.jsx(sy,{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(Ve,{children:[e.jsxs(rs,{children:[e.jsx(cs,{children:"花费趋势"}),e.jsx(st,{children:"API调用成本变化"})]}),e.jsx(gs,{children:e.jsx(oi,{config:X,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(Ru,{data:se,children:[e.jsx(Xc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Pc,{dataKey:"timestamp",tickFormatter:L=>be(L),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ur,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(xr,{content:e.jsx(di,{labelFormatter:L=>be(L)})}),e.jsx(Jc,{dataKey:"cost",fill:"var(--color-cost)"})]})})})]}),e.jsxs(Ve,{children:[e.jsxs(rs,{children:[e.jsx(cs,{children:"Token消耗"}),e.jsx(st,{children:"Token使用量变化"})]}),e.jsx(gs,{children:e.jsx(oi,{config:X,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(Ru,{data:se,children:[e.jsx(Xc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Pc,{dataKey:"timestamp",tickFormatter:L=>be(L),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ur,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(xr,{content:e.jsx(di,{labelFormatter:L=>be(L)})}),e.jsx(Jc,{dataKey:"tokens",fill:"var(--color-tokens)"})]})})})]})]})]}),e.jsx(As,{value:"models",className:"space-y-4",children:e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(Ve,{children:[e.jsxs(rs,{children:[e.jsx(cs,{children:"模型请求分布"}),e.jsxs(st,{children:["各模型使用占比 (共 ",E.length," 个模型)"]})]}),e.jsx(gs,{children:e.jsx(oi,{config:Object.fromEntries(E.map((L,B)=>[L.model_name,{label:L.model_name,color:U[B]}])),className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(ty,{children:[e.jsx(xr,{content:e.jsx(di,{})}),e.jsx(ay,{data:P,cx:"50%",cy:"50%",labelLine:!1,label:({name:L,percent:B})=>B&&B<.05?"":`${L} ${B?(B*100).toFixed(0):0}%`,outerRadius:100,dataKey:"value",children:P.map((L,B)=>e.jsx(ly,{fill:L.fill},`cell-${B}`))})]})})})]}),e.jsxs(Ve,{children:[e.jsxs(rs,{children:[e.jsx(cs,{children:"模型详细统计"}),e.jsx(st,{children:"请求数、花费和性能"})]}),e.jsx(gs,{children:e.jsx(Ze,{className:"h-[300px] sm:h-[400px]",children:e.jsx("div",{className:"space-y-3",children:E.map((L,B)=>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:L.model_name}),e.jsx("div",{className:"w-3 h-3 rounded-full ml-2 flex-shrink-0",style:{backgroundColor:`hsl(var(--chart-${B%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:L.request_count.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1 font-medium",children:["¥",L.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:[(L.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:[L.avg_response_time.toFixed(2),"s"]})]})]})]},B))})})})]})]})}),e.jsx(As,{value:"activity",children:e.jsxs(Ve,{children:[e.jsxs(rs,{children:[e.jsx(cs,{children:"最近活动"}),e.jsx(st,{children:"最新的API调用记录"})]}),e.jsx(gs,{children:e.jsx(Ze,{className:"h-[400px] sm:h-[500px]",children:e.jsx("div",{className:"space-y-2",children:ne.map((L,B)=>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:L.model}),e.jsx("div",{className:"text-xs text-muted-foreground",children:L.request_type})]}),e.jsx("div",{className:"text-xs text-muted-foreground flex-shrink-0",children:be(L.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:L.tokens})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1",children:["¥",L.cost.toFixed(4)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"耗时:"}),e.jsxs("span",{className:"ml-1",children:[L.time_cost.toFixed(2),"s"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"状态:"}),e.jsx("span",{className:`ml-1 ${L.status==="success"?"text-green-600":"text-red-600"}`,children:L.status})]})]})]},B))})})})]})}),e.jsx(As,{value:"daily",children:e.jsxs(Ve,{children:[e.jsxs(rs,{children:[e.jsx(cs,{children:"每日统计"}),e.jsx(st,{children:"最近7天的数据汇总"})]}),e.jsx(gs,{children:e.jsx(oi,{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(Ru,{data:te,children:[e.jsx(Xc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Pc,{dataKey:"timestamp",tickFormatter:L=>{const B=new Date(L);return`${B.getMonth()+1}/${B.getDate()}`},stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ur,{yAxisId:"left",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ur,{yAxisId:"right",orientation:"right",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(xr,{content:e.jsx(di,{labelFormatter:L=>new Date(L).toLocaleDateString("zh-CN")})}),e.jsx($0,{content:e.jsx(ij,{})}),e.jsx(Jc,{yAxisId:"left",dataKey:"requests",fill:"var(--color-requests)"}),e.jsx(Jc,{yAxisId:"right",dataKey:"cost",fill:"var(--color-cost)"})]})})})]})})]}),e.jsx(vn,{})]})})}const P0={theme:"system",setTheme:()=>null},oj=m.createContext(P0),dm=()=>{const l=m.useContext(oj);if(l===void 0)throw new Error("useTheme must be used within a ThemeProvider");return l},J0=(l,i,r)=>{const o=document.documentElement.classList.contains("no-animations");if(!document.startViewTransition||o){i(l);return}const u=r.clientX,x=r.clientY,h=Math.hypot(Math.max(u,innerWidth-u),Math.max(x,innerHeight-x));document.startViewTransition(()=>{i(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)"})})},dj=m.createContext(void 0),uj=()=>{const l=m.useContext(dj);if(l===void 0)throw new Error("useAnimation must be used within an AnimationProvider");return l},Fe=m.forwardRef(({className:l,...i},r)=>e.jsx(Pp,{className:H("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),...i,ref:r,children:e.jsx(LN,{className:H("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")})}));Fe.displayName=Pp.displayName;const Z0=gi("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),k=m.forwardRef(({className:l,...i},r)=>e.jsx(dg,{ref:r,className:H(Z0(),l),...i}));k.displayName=dg.displayName;const ie=m.forwardRef(({className:l,type:i,...r},o)=>e.jsx("input",{type:i,className:H("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:o,...r}));ie.displayName="Input";const W0=5,ew=5e3;let qu=0;function sw(){return qu=(qu+1)%Number.MAX_SAFE_INTEGER,qu.toString()}const Gu=new Map,yp=l=>{if(Gu.has(l))return;const i=setTimeout(()=>{Gu.delete(l),br({type:"REMOVE_TOAST",toastId:l})},ew);Gu.set(l,i)},tw=(l,i)=>{switch(i.type){case"ADD_TOAST":return{...l,toasts:[i.toast,...l.toasts].slice(0,W0)};case"UPDATE_TOAST":return{...l,toasts:l.toasts.map(r=>r.id===i.toast.id?{...r,...i.toast}:r)};case"DISMISS_TOAST":{const{toastId:r}=i;return r?yp(r):l.toasts.forEach(o=>{yp(o.id)}),{...l,toasts:l.toasts.map(o=>o.id===r||r===void 0?{...o,open:!1}:o)}}case"REMOVE_TOAST":return i.toastId===void 0?{...l,toasts:[]}:{...l,toasts:l.toasts.filter(r=>r.id!==i.toastId)}}},no=[];let io={toasts:[]};function br(l){io=tw(io,l),no.forEach(i=>{i(io)})}function aw({...l}){const i=sw(),r=u=>br({type:"UPDATE_TOAST",toast:{...u,id:i}}),o=()=>br({type:"DISMISS_TOAST",toastId:i});return br({type:"ADD_TOAST",toast:{...l,id:i,open:!0,onOpenChange:u=>{u||o()}}}),{id:i,dismiss:o,update:r}}function Ks(){const[l,i]=m.useState(io);return m.useEffect(()=>(no.push(i),()=>{const r=no.indexOf(i);r>-1&&no.splice(r,1)}),[l]),{...l,toast:aw,dismiss:r=>br({type:"DISMISS_TOAST",toastId:r})}}const lw=[{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 nw(l){const i=lw.map(o=>({id:o.id,label:o.label,description:o.description,passed:o.validate(l)}));return{isValid:i.every(o=>o.passed),rules:i}}const go="0.12.0 Beta",um="MaiBot Dashboard",iw=`${um} v${go}`,rw=(l="v")=>`${l}${go}`,Wt={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"},Va={theme:"system",accentColor:"blue",enableAnimations:!0,enableWavesBackground:!0,logCacheSize:1e3,logAutoScroll:!0,logFontSize:"xs",logLineSpacing:4,dataSyncInterval:30,wsReconnectInterval:3e3,wsMaxReconnectAttempts:10};function dt(l){const i=mj(l),r=localStorage.getItem(i);if(r===null)return Va[l];const o=Va[l];if(typeof o=="boolean")return r==="true";if(typeof o=="number"){const u=parseFloat(r);return isNaN(u)?o:u}return r}function ui(l,i){const r=mj(l);localStorage.setItem(r,String(i)),window.dispatchEvent(new CustomEvent("maibot-settings-change",{detail:{key:l,value:i}}))}function cw(){return{theme:dt("theme"),accentColor:dt("accentColor"),enableAnimations:dt("enableAnimations"),enableWavesBackground:dt("enableWavesBackground"),logCacheSize:dt("logCacheSize"),logAutoScroll:dt("logAutoScroll"),logFontSize:dt("logFontSize"),logLineSpacing:dt("logLineSpacing"),dataSyncInterval:dt("dataSyncInterval"),wsReconnectInterval:dt("wsReconnectInterval"),wsMaxReconnectAttempts:dt("wsMaxReconnectAttempts")}}function ow(){const l=cw(),i=localStorage.getItem(Wt.COMPLETED_TOURS),r=i?JSON.parse(i):[];return{...l,completedTours:r}}function dw(l){const i=[],r=[];for(const[o,u]of Object.entries(l)){if(o==="completedTours"){Array.isArray(u)?(localStorage.setItem(Wt.COMPLETED_TOURS,JSON.stringify(u)),i.push("completedTours")):r.push("completedTours");continue}if(o in Va){const x=o,h=Va[x];if(typeof u==typeof h){if(x==="theme"&&!["light","dark","system"].includes(u)){r.push(o);continue}if(x==="logFontSize"&&!["xs","sm","base"].includes(u)){r.push(o);continue}ui(x,u),i.push(o)}else r.push(o)}else r.push(o)}return{success:i.length>0,imported:i,skipped:r}}function uw(){for(const l of Object.keys(Va))ui(l,Va[l]);localStorage.removeItem(Wt.COMPLETED_TOURS),window.dispatchEvent(new CustomEvent("maibot-settings-reset"))}function mw(){const l=[],i=[],r=[];for(let o=0;oo.size-r.size),{used:l,items:localStorage.length,details:i}}function xw(l){if(l===0)return"0 B";const i=1024,r=["B","KB","MB"],o=Math.floor(Math.log(l)/Math.log(i));return parseFloat((l/Math.pow(i,o)).toFixed(2))+" "+r[o]}function mj(l){return{theme:Wt.THEME,accentColor:Wt.ACCENT_COLOR,enableAnimations:Wt.ENABLE_ANIMATIONS,enableWavesBackground:Wt.ENABLE_WAVES_BACKGROUND,logCacheSize:Wt.LOG_CACHE_SIZE,logAutoScroll:Wt.LOG_AUTO_SCROLL,logFontSize:Wt.LOG_FONT_SIZE,logLineSpacing:Wt.LOG_LINE_SPACING,dataSyncInterval:Wt.DATA_SYNC_INTERVAL,wsReconnectInterval:Wt.WS_RECONNECT_INTERVAL,wsMaxReconnectAttempts:Wt.WS_MAX_RECONNECT_ATTEMPTS}[l]}const ma=m.forwardRef(({className:l,...i},r)=>e.jsxs(Jp,{ref:r,className:H("relative flex w-full touch-none select-none items-center",l),...i,children:[e.jsx(UN,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(BN,{className:"absolute h-full bg-primary"})}),e.jsx(HN,{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"})]}));ma.displayName=Jp.displayName;class hw{ws=null;reconnectTimeout=null;reconnectAttempts=0;heartbeatInterval=null;logCallbacks=new Set;connectionCallbacks=new Set;isConnected=!1;logCache=[];getMaxCacheSize(){return dt("logCacheSize")}getMaxReconnectAttempts(){return dt("wsMaxReconnectAttempts")}getReconnectInterval(){return dt("wsReconnectInterval")}getWebSocketUrl(i){let r;{const o=window.location.protocol==="https:"?"wss:":"ws:",u=window.location.host;r=`${o}//${u}/ws/logs`}return i?`${r}?token=${encodeURIComponent(i)}`:r}async getWsToken(){try{const i=await we("/api/webui/ws-token",{method:"GET",credentials:"include"});if(!i.ok)return console.error("获取 WebSocket token 失败:",i.status),null;const r=await i.json();return r.success&&r.token?r.token:null}catch(i){return console.error("获取 WebSocket token 失败:",i),null}}async connect(){if(this.ws?.readyState===WebSocket.OPEN||this.ws?.readyState===WebSocket.CONNECTING)return;const i=await this.getWsToken(),r=this.getWebSocketUrl(i||void 0);try{this.ws=new WebSocket(r),this.ws.onopen=()=>{this.isConnected=!0,this.reconnectAttempts=0,this.notifyConnection(!0),this.startHeartbeat()},this.ws.onmessage=o=>{try{if(o.data==="pong")return;const u=JSON.parse(o.data);this.notifyLog(u)}catch(u){console.error("解析日志消息失败:",u)}},this.ws.onerror=o=>{console.error("❌ WebSocket 错误:",o),this.isConnected=!1,this.notifyConnection(!1)},this.ws.onclose=()=>{this.isConnected=!1,this.notifyConnection(!1),this.stopHeartbeat(),this.attemptReconnect()}}catch(o){console.error("创建 WebSocket 连接失败:",o),this.attemptReconnect()}}attemptReconnect(){const i=this.getMaxReconnectAttempts();if(this.reconnectAttempts>=i)return;this.reconnectAttempts+=1;const r=this.getReconnectInterval(),o=Math.min(r*this.reconnectAttempts,3e4);this.reconnectTimeout=window.setTimeout(()=>{this.connect()},o)}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(i){return this.logCallbacks.add(i),()=>this.logCallbacks.delete(i)}onConnectionChange(i){return this.connectionCallbacks.add(i),i(this.isConnected),()=>this.connectionCallbacks.delete(i)}notifyLog(i){if(!this.logCache.some(o=>o.id===i.id)){this.logCache.push(i);const o=this.getMaxCacheSize();this.logCache.length>o&&(this.logCache=this.logCache.slice(-o)),this.logCallbacks.forEach(u=>{try{u(i)}catch(x){console.error("日志回调执行失败:",x)}})}}notifyConnection(i){this.connectionCallbacks.forEach(r=>{try{r(i)}catch(o){console.error("连接状态回调执行失败:",o)}})}getAllLogs(){return[...this.logCache]}clearLogs(){this.logCache=[]}getConnectionStatus(){return this.isConnected}}const xn=new hw;typeof window<"u"&&setTimeout(()=>{xn.connect()},100);const Qs=cy,mm=oy,fw=iy,xj=m.forwardRef(({className:l,...i},r)=>e.jsx(ug,{ref:r,className:H("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),...i}));xj.displayName=ug.displayName;const qs=m.forwardRef(({className:l,children:i,preventOutsideClose:r=!1,...o},u)=>e.jsxs(fw,{children:[e.jsx(xj,{}),e.jsxs(mg,{ref:u,className:H("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:r?x=>x.preventDefault():void 0,onInteractOutside:r?x=>x.preventDefault():void 0,...o,children:[i,e.jsxs(ry,{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(fl,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));qs.displayName=mg.displayName;const Gs=({className:l,...i})=>e.jsx("div",{className:H("flex flex-col space-y-1.5 text-center sm:text-left",l),...i});Gs.displayName="DialogHeader";const at=({className:l,...i})=>e.jsx("div",{className:H("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",l),...i});at.displayName="DialogFooter";const Vs=m.forwardRef(({className:l,...i},r)=>e.jsx(xg,{ref:r,className:H("text-lg font-semibold leading-none tracking-tight",l),...i}));Vs.displayName=xg.displayName;const Ws=m.forwardRef(({className:l,...i},r)=>e.jsx(hg,{ref:r,className:H("text-sm text-muted-foreground",l),...i}));Ws.displayName=hg.displayName;const js=qN,mt=GN,pw=$N,hj=m.forwardRef(({className:l,...i},r)=>e.jsx(Zp,{className:H("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),...i,ref:r}));hj.displayName=Zp.displayName;const os=m.forwardRef(({className:l,...i},r)=>e.jsxs(pw,{children:[e.jsx(hj,{}),e.jsx(Wp,{ref:r,className:H("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),...i})]}));os.displayName=Wp.displayName;const ds=({className:l,...i})=>e.jsx("div",{className:H("flex flex-col space-y-2 text-center sm:text-left",l),...i});ds.displayName="AlertDialogHeader";const us=({className:l,...i})=>e.jsx("div",{className:H("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",l),...i});us.displayName="AlertDialogFooter";const ms=m.forwardRef(({className:l,...i},r)=>e.jsx(eg,{ref:r,className:H("text-lg font-semibold",l),...i}));ms.displayName=eg.displayName;const xs=m.forwardRef(({className:l,...i},r)=>e.jsx(sg,{ref:r,className:H("text-sm text-muted-foreground",l),...i}));xs.displayName=sg.displayName;const hs=m.forwardRef(({className:l,...i},r)=>e.jsx(tg,{ref:r,className:H(Sr(),l),...i}));hs.displayName=tg.displayName;const fs=m.forwardRef(({className:l,...i},r)=>e.jsx(ag,{ref:r,className:H(Sr({variant:"outline"}),"mt-2 sm:mt-0",l),...i}));fs.displayName=ag.displayName;function gw(){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(Sa,{defaultValue:"appearance",className:"w-full",children:[e.jsxs(xa,{className:"grid w-full grid-cols-2 sm:grid-cols-4 gap-0.5 sm:gap-1 h-auto p-1",children:[e.jsxs(is,{value:"appearance",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(Oy,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"外观"})]}),e.jsxs(is,{value:"security",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(Dy,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"安全"})]}),e.jsxs(is,{value:"other",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(ji,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"其他"})]}),e.jsxs(is,{value:"about",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(Ra,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"关于"})]})]}),e.jsxs(Ze,{className:"h-[calc(100vh-240px)] sm:h-[calc(100vh-280px)] mt-4 sm:mt-6",children:[e.jsx(As,{value:"appearance",className:"mt-0",children:e.jsx(jw,{})}),e.jsx(As,{value:"security",className:"mt-0",children:e.jsx(vw,{})}),e.jsx(As,{value:"other",className:"mt-0",children:e.jsx(bw,{})}),e.jsx(As,{value:"about",className:"mt-0",children:e.jsx(Nw,{})})]})]})]})}function _p(l){const i=document.documentElement,o={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(o)i.style.setProperty("--primary",o.hsl),o.gradient?(i.style.setProperty("--primary-gradient",o.gradient),i.classList.add("has-gradient")):(i.style.removeProperty("--primary-gradient"),i.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,g=parseInt(x.substring(4,6),16)/255,j=Math.max(h,f,g),v=Math.min(h,f,g);let y=0,b=0;const S=(j+v)/2;if(j!==v){const w=j-v;switch(b=S>.5?w/(2-j-v):w/(j+v),j){case h:y=((f-g)/w+(flocalStorage.getItem("accent-color")||"blue");m.useEffect(()=>{const j=localStorage.getItem("accent-color")||"blue";_p(j)},[]);const g=j=>{f(j),localStorage.setItem("accent-color",j),_p(j)};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(Vu,{value:"light",current:l,onChange:i,label:"浅色",description:"始终使用浅色主题"}),e.jsx(Vu,{value:"dark",current:l,onChange:i,label:"深色",description:"始终使用深色主题"}),e.jsx(Vu,{value:"system",current:l,onChange:i,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(_a,{value:"blue",current:h,onChange:g,label:"蓝色",colorClass:"bg-blue-500"}),e.jsx(_a,{value:"purple",current:h,onChange:g,label:"紫色",colorClass:"bg-purple-500"}),e.jsx(_a,{value:"green",current:h,onChange:g,label:"绿色",colorClass:"bg-green-500"}),e.jsx(_a,{value:"orange",current:h,onChange:g,label:"橙色",colorClass:"bg-orange-500"}),e.jsx(_a,{value:"pink",current:h,onChange:g,label:"粉色",colorClass:"bg-pink-500"}),e.jsx(_a,{value:"red",current:h,onChange:g,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(_a,{value:"gradient-sunset",current:h,onChange:g,label:"日落",colorClass:"bg-gradient-to-r from-orange-500 to-pink-500"}),e.jsx(_a,{value:"gradient-ocean",current:h,onChange:g,label:"海洋",colorClass:"bg-gradient-to-r from-blue-500 to-cyan-500"}),e.jsx(_a,{value:"gradient-forest",current:h,onChange:g,label:"森林",colorClass:"bg-gradient-to-r from-green-500 to-emerald-500"}),e.jsx(_a,{value:"gradient-aurora",current:h,onChange:g,label:"极光",colorClass:"bg-gradient-to-r from-purple-500 to-pink-500"}),e.jsx(_a,{value:"gradient-fire",current:h,onChange:g,label:"烈焰",colorClass:"bg-gradient-to-r from-red-500 to-orange-500"}),e.jsx(_a,{value:"gradient-twilight",current:h,onChange:g,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:j=>g(j.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(ie,{type:"text",value:h,onChange:j=>g(j.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(k,{htmlFor:"animations",className:"text-base font-medium cursor-pointer",children:"启用动画效果"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后将禁用所有过渡动画和特效,提升性能"})]}),e.jsx(Fe,{id:"animations",checked:r,onCheckedChange:o})]})}),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(k,{htmlFor:"waves-background",className:"text-base font-medium cursor-pointer",children:"登录页波浪背景"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后登录页将使用纯色背景,适合低性能设备"})]}),e.jsx(Fe,{id:"waves-background",checked:u,onCheckedChange:x})]})})]})]})]})}function vw(){const l=ka(),[i,r]=m.useState(""),[o,u]=m.useState(""),[x,h]=m.useState(!1),[f,g]=m.useState(!1),[j,v]=m.useState(!1),[y,b]=m.useState(!1),[S,w]=m.useState(!1),[O,A]=m.useState(!1),[D,V]=m.useState(""),[z,_]=m.useState(!1),{toast:T}=Ks(),$=m.useMemo(()=>nw(o),[o]),E=async oe=>{if(!i){T({title:"无法复制",description:"Token 存储在安全 Cookie 中,请重新生成以获取新 Token",variant:"destructive"});return}try{await navigator.clipboard.writeText(oe),w(!0),T({title:"复制成功",description:"Token 已复制到剪贴板"}),setTimeout(()=>w(!1),2e3)}catch{T({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},se=async()=>{if(!o.trim()){T({title:"输入错误",description:"请输入新的 Token",variant:"destructive"});return}if(!$.isValid){const oe=$.rules.filter(je=>!je.passed).map(je=>je.label).join(", ");T({title:"格式错误",description:`Token 不符合要求: ${oe}`,variant:"destructive"});return}v(!0);try{const oe=await fetch("/api/webui/auth/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({new_token:o.trim()})}),je=await oe.json();oe.ok&&je.success?(u(""),r(o.trim()),T({title:"更新成功",description:"Access Token 已更新,即将跳转到登录页"}),setTimeout(()=>{l({to:"/auth"})},1500)):T({title:"更新失败",description:je.message||"无法更新 Token",variant:"destructive"})}catch(oe){console.error("更新 Token 错误:",oe),T({title:"更新失败",description:"连接服务器失败",variant:"destructive"})}finally{v(!1)}},te=async()=>{b(!0);try{const oe=await fetch("/api/webui/auth/regenerate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"}),je=await oe.json();oe.ok&&je.success?(r(je.token),V(je.token),A(!0),_(!1),T({title:"生成成功",description:"新的 Access Token 已生成,请及时保存"})):T({title:"生成失败",description:je.message||"无法生成新 Token",variant:"destructive"})}catch(oe){console.error("生成 Token 错误:",oe),T({title:"生成失败",description:"连接服务器失败",variant:"destructive"})}finally{b(!1)}},ne=async()=>{try{await navigator.clipboard.writeText(D),_(!0),T({title:"复制成功",description:"Token 已复制到剪贴板"})}catch{T({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},ue=()=>{A(!1),setTimeout(()=>{V(""),_(!1)},300),setTimeout(()=>{l({to:"/auth"})},500)},Se=oe=>{oe||ue()};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(Qs,{open:O,onOpenChange:Se,children:e.jsxs(qs,{className:"sm:max-w-md",children:[e.jsxs(Gs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(Oa,{className:"h-5 w-5 text-yellow-500"}),"新的 Access Token"]}),e.jsx(Ws,{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(k,{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:D})]}),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(Oa,{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(at,{className:"gap-2 sm:gap-0",children:[e.jsx(C,{variant:"outline",onClick:ne,className:"gap-2",children:z?e.jsxs(e.Fragment,{children:[e.jsx(ea,{className:"h-4 w-4 text-green-500"}),"已复制"]}):e.jsxs(e.Fragment,{children:[e.jsx(co,{className:"h-4 w-4"}),"复制 Token"]})}),e.jsx(C,{onClick:ue,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(k,{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(ie,{id:"current-token",type:x?"text":"password",value:i||"••••••••••••••••••••••••••••••••",readOnly:!0,className:"pr-10 font-mono text-sm",placeholder:"Token 存储在安全 Cookie 中"}),e.jsx("button",{onClick:()=>{i?h(!x):T({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(wr,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Gt,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(C,{variant:"outline",size:"icon",onClick:()=>E(i),title:"复制到剪贴板",className:"flex-shrink-0",disabled:!i,children:S?e.jsx(ea,{className:"h-4 w-4 text-green-500"}):e.jsx(co,{className:"h-4 w-4"})}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsxs(C,{variant:"outline",disabled:y,className:"gap-2 flex-1 sm:flex-none",children:[e.jsx(At,{className:H("h-4 w-4",y&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:"重新生成"}),e.jsx("span",{className:"sm:hidden",children:"生成"})]})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认重新生成 Token"}),e.jsx(xs,{children:"这将生成一个新的 64 位安全令牌,并使当前 Token 立即失效。 您需要使用新 Token 重新登录系统。此操作不可撤销,确定要继续吗?"})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:te,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(k,{htmlFor:"new-token",className:"text-sm",children:"新的访问令牌"}),e.jsxs("div",{className:"relative",children:[e.jsx(ie,{id:"new-token",type:f?"text":"password",value:o,onChange:oe=>u(oe.target.value),className:"pr-10 font-mono text-sm",placeholder:"输入自定义 Token"}),e.jsx("button",{onClick:()=>g(!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(wr,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Gt,{className:"h-4 w-4 text-muted-foreground"})})]}),o&&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:$.rules.map(oe=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[oe.passed?e.jsx(aa,{className:"h-4 w-4 text-green-500 flex-shrink-0"}):e.jsx(Mg,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:H(oe.passed?"text-green-600 dark:text-green-400":"text-muted-foreground"),children:oe.label})]},oe.id))}),$.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(ea,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:"Token 格式正确,可以使用"})]})})]})]}),e.jsx(C,{onClick:se,disabled:j||!$.isValid||!o,className:"w-full sm:w-auto",children:j?"更新中...":"更新自定义 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 bw(){const l=ka(),{toast:i}=Ks(),[r,o]=m.useState(!1),[u,x]=m.useState(!1),[h,f]=m.useState(()=>dt("logCacheSize")),[g,j]=m.useState(()=>dt("wsReconnectInterval")),[v,y]=m.useState(()=>dt("wsMaxReconnectAttempts")),[b,S]=m.useState(()=>dt("dataSyncInterval")),[w,O]=m.useState(()=>wp()),[A,D]=m.useState(!1),[V,z]=m.useState(!1),_=m.useRef(null);if(u)throw new Error("这是一个手动触发的测试错误,用于验证错误边界组件是否正常工作。");const T=()=>{O(wp())},$=U=>{const P=U[0];f(P),ui("logCacheSize",P)},E=U=>{const P=U[0];j(P),ui("wsReconnectInterval",P)},se=U=>{const P=U[0];y(P),ui("wsMaxReconnectAttempts",P)},te=U=>{const P=U[0];S(P),ui("dataSyncInterval",P)},ne=()=>{xn.clearLogs(),i({title:"日志已清除",description:"日志缓存已清空"})},ue=()=>{const U=mw();T(),i({title:"缓存已清除",description:`已清除 ${U.clearedKeys.length} 项缓存数据`})},Se=()=>{D(!0);try{const U=ow(),P=JSON.stringify(U,null,2),X=new Blob([P],{type:"application/json"}),L=URL.createObjectURL(X),B=document.createElement("a");B.href=L,B.download=`maibot-webui-settings-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(B),B.click(),document.body.removeChild(B),URL.revokeObjectURL(L),i({title:"导出成功",description:"设置已导出为 JSON 文件"})}catch(U){console.error("导出设置失败:",U),i({title:"导出失败",description:"无法导出设置",variant:"destructive"})}finally{D(!1)}},oe=U=>{const P=U.target.files?.[0];if(!P)return;z(!0);const X=new FileReader;X.onload=L=>{try{const B=L.target?.result,_e=JSON.parse(B),Ne=dw(_e);Ne.success?(f(dt("logCacheSize")),j(dt("wsReconnectInterval")),y(dt("wsMaxReconnectAttempts")),S(dt("dataSyncInterval")),T(),i({title:"导入成功",description:`成功导入 ${Ne.imported.length} 项设置${Ne.skipped.length>0?`,跳过 ${Ne.skipped.length} 项`:""}`}),(Ne.imported.includes("theme")||Ne.imported.includes("accentColor"))&&i({title:"提示",description:"部分设置需要刷新页面才能完全生效"})):i({title:"导入失败",description:"没有有效的设置项可导入",variant:"destructive"})}catch(B){console.error("导入设置失败:",B),i({title:"导入失败",description:"文件格式无效",variant:"destructive"})}finally{z(!1),_.current&&(_.current.value="")}},X.readAsText(P)},je=()=>{uw(),f(Va.logCacheSize),j(Va.wsReconnectInterval),y(Va.wsMaxReconnectAttempts),S(Va.dataSyncInterval),T(),i({title:"已重置",description:"所有设置已恢复为默认值,刷新页面以应用更改"})},be=async()=>{o(!0);try{const U=await we("/api/webui/setup/reset",{method:"POST"}),P=await U.json();U.ok&&P.success?(i({title:"重置成功",description:"即将进入初次配置向导"}),setTimeout(()=>{l({to:"/setup"})},1e3)):i({title:"重置失败",description:P.message||"无法重置配置状态",variant:"destructive"})}catch(U){console.error("重置配置状态错误:",U),i({title:"重置失败",description:"连接服务器失败",variant:"destructive"})}finally{o(!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(ro,{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(Ry,{className:"h-4 w-4"}),"本地存储使用"]}),e.jsx(C,{variant:"ghost",size:"sm",onClick:T,className:"h-7 px-2",children:e.jsx(At,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:xw(w.used)}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[w.items," 个存储项"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(k,{className:"text-sm font-medium",children:"日志缓存大小"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h," 条"]})]}),e.jsx(ma,{value:[h],onValueChange:$,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(k,{className:"text-sm font-medium",children:"首页数据刷新间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[b," 秒"]})]}),e.jsx(ma,{value:[b],onValueChange:te,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(k,{className:"text-sm font-medium",children:"WebSocket 重连间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[g/1e3," 秒"]})]}),e.jsx(ma,{value:[g],onValueChange:E,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(k,{className:"text-sm font-medium",children:"WebSocket 最大重连次数"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[v," 次"]})]}),e.jsx(ma,{value:[v],onValueChange:se,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(C,{variant:"outline",size:"sm",onClick:ne,className:"gap-2",children:[e.jsx(es,{className:"h-4 w-4"}),"清除日志缓存"]}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(es,{className:"h-4 w-4"}),"清除本地缓存"]})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认清除本地缓存"}),e.jsx(xs,{children:"这将清除所有本地缓存的设置和数据(不包括登录凭证)。 您可能需要重新配置部分偏好设置。确定要继续吗?"})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:ue,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(Da,{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(C,{variant:"outline",onClick:Se,disabled:A,className:"gap-2",children:[e.jsx(Da,{className:"h-4 w-4"}),A?"导出中...":"导出设置"]}),e.jsx("input",{ref:_,type:"file",accept:".json",onChange:oe,className:"hidden"}),e.jsxs(C,{variant:"outline",onClick:()=>_.current?.click(),disabled:V,className:"gap-2",children:[e.jsx(_r,{className:"h-4 w-4"}),V?"导入中...":"导入设置"]})]}),e.jsx("div",{className:"pt-2 border-t",children:e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",className:"gap-2 text-destructive hover:text-destructive",children:[e.jsx(yr,{className:"h-4 w-4"}),"重置所有设置为默认值"]})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认重置所有设置"}),e.jsx(xs,{children:"这将把所有界面设置恢复为默认值,包括主题、颜色、动画等偏好设置。 此操作不会影响您的登录状态。确定要继续吗?"})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:je,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(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsxs(C,{variant:"outline",disabled:r,className:"gap-2",children:[e.jsx(yr,{className:H("h-4 w-4",r&&"animate-spin")}),"重新进行初次配置"]})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认重新配置"}),e.jsx(xs,{children:"这将带您重新进入初次配置向导。您可以重新设置系统的基础配置项。确定要继续吗?"})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:be,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(Oa,{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(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsxs(C,{variant:"destructive",className:"gap-2",children:[e.jsx(Oa,{className:"h-4 w-4"}),"触发测试错误"]})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认触发错误"}),e.jsx(xs,{children:"这将手动触发一个 React 错误,用于测试错误边界组件的显示效果。 页面将显示错误界面,您可以通过刷新页面或点击返回首页来恢复。"})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>x(!0),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认触发"})]})]})]})]})]})]})}function Nw(){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:H("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:["版本: ",go]}),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(Ze,{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(et,{name:"React",description:"用户界面构建库",license:"MIT"}),e.jsx(et,{name:"shadcn/ui",description:"优雅的 React 组件库",license:"MIT"}),e.jsx(et,{name:"Radix UI",description:"无样式的可访问组件库",license:"MIT"}),e.jsx(et,{name:"Tailwind CSS",description:"实用优先的 CSS 框架",license:"MIT"}),e.jsx(et,{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(et,{name:"TanStack Router",description:"类型安全的路由库",license:"MIT"}),e.jsx(et,{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(et,{name:"React Hook Form",description:"高性能表单库",license:"MIT"}),e.jsx(et,{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(et,{name:"clsx",description:"条件 className 构建工具",license:"MIT"}),e.jsx(et,{name:"tailwind-merge",description:"Tailwind 类名合并工具",license:"MIT"}),e.jsx(et,{name:"class-variance-authority",description:"组件变体管理",license:"Apache-2.0"}),e.jsx(et,{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(et,{name:"Framer Motion",description:"React 动画库",license:"MIT"}),e.jsx(et,{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(et,{name:"FastAPI",description:"现代化 Python Web 框架",license:"MIT"}),e.jsx(et,{name:"Uvicorn",description:"ASGI 服务器",license:"BSD-3-Clause"}),e.jsx(et,{name:"Pydantic",description:"数据验证库",license:"MIT"}),e.jsx(et,{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(et,{name:"TypeScript",description:"JavaScript 的超集",license:"Apache-2.0"}),e.jsx(et,{name:"Vite",description:"下一代前端构建工具",license:"MIT"}),e.jsx(et,{name:"ESLint",description:"JavaScript 代码检查工具",license:"MIT"}),e.jsx(et,{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 et({name:l,description:i,license:r}){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:i})]}),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:r})]})}function Vu({value:l,current:i,onChange:r,label:o,description:u}){const x=i===l;return e.jsxs("button",{onClick:()=>r(l),className:H("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:o}),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 _a({value:l,current:i,onChange:r,label:o,colorClass:u}){const x=i===l;return e.jsxs("button",{onClick:()=>r(l),className:H("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:H("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:o})]})]})}class yw{grad3;p;perm;constructor(i=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 r=0;r<256;r++)this.p[r]=Math.floor(Math.random()*256);this.perm=[];for(let r=0;r<512;r++)this.perm[r]=this.p[r&255]}dot(i,r,o){return i[0]*r+i[1]*o}mix(i,r,o){return(1-o)*i+o*r}fade(i){return i*i*i*(i*(i*6-15)+10)}perlin2(i,r){const o=Math.floor(i)&255,u=Math.floor(r)&255;i-=Math.floor(i),r-=Math.floor(r);const x=this.fade(i),h=this.fade(r),f=this.perm[o]+u,g=this.perm[f],j=this.perm[f+1],v=this.perm[o+1]+u,y=this.perm[v],b=this.perm[v+1];return this.mix(this.mix(this.dot(this.grad3[g%12],i,r),this.dot(this.grad3[y%12],i-1,r),x),this.mix(this.dot(this.grad3[j%12],i,r-1),this.dot(this.grad3[b%12],i-1,r-1),x),h)}}function Sp(){const l=m.useRef(null),i=m.useRef(null),r=m.useRef(void 0),o=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:new yw(Math.random()),bounding:null});return m.useEffect(()=>{const u=i.current,x=l.current;if(!u||!x)return;const h=o.current,f=()=>{const O=u.getBoundingClientRect();h.bounding=O,x.style.width=`${O.width}px`,x.style.height=`${O.height}px`},g=()=>{if(!h.bounding)return;const{width:O,height:A}=h.bounding;h.lines=[],h.paths.forEach(te=>te.remove()),h.paths=[];const D=10,V=32,z=O+200,_=A+30,T=Math.ceil(z/D),$=Math.ceil(_/V),E=(O-D*T)/2,se=(A-V*$)/2;for(let te=0;te<=T;te++){const ne=[];for(let Se=0;Se<=$;Se++){const oe={x:E+D*te,y:se+V*Se,wave:{x:0,y:0},cursor:{x:0,y:0,vx:0,vy:0}};ne.push(oe)}const ue=document.createElementNS("http://www.w3.org/2000/svg","path");x.appendChild(ue),h.paths.push(ue),h.lines.push(ne)}},j=O=>{const{lines:A,mouse:D,noise:V}=h;A.forEach(z=>{z.forEach(_=>{const T=V.perlin2((_.x+O*.0125)*.002,(_.y+O*.005)*.0015)*12;_.wave.x=Math.cos(T)*32,_.wave.y=Math.sin(T)*16;const $=_.x-D.sx,E=_.y-D.sy,se=Math.hypot($,E),te=Math.max(175,D.vs);if(se{const D={x:O.x+O.wave.x+(A?O.cursor.x:0),y:O.y+O.wave.y+(A?O.cursor.y:0)};return D.x=Math.round(D.x*10)/10,D.y=Math.round(D.y*10)/10,D},y=()=>{const{lines:O,paths:A}=h;O.forEach((D,V)=>{let z=v(D[0],!1),_=`M ${z.x} ${z.y}`;D.forEach((T,$)=>{const E=$===D.length-1;z=v(T,!E),_+=`L ${z.x} ${z.y}`}),A[V].setAttribute("d",_)})},b=O=>{const{mouse:A}=h;A.sx+=(A.x-A.sx)*.1,A.sy+=(A.y-A.sy)*.1;const D=A.x-A.lx,V=A.y-A.ly,z=Math.hypot(D,V);A.v=z,A.vs+=(z-A.vs)*.1,A.vs=Math.min(100,A.vs),A.lx=A.x,A.ly=A.y,A.a=Math.atan2(V,D),u&&(u.style.setProperty("--x",`${A.sx}px`),u.style.setProperty("--y",`${A.sy}px`)),j(O),y(),r.current=requestAnimationFrame(b)},S=O=>{if(!h.bounding)return;const{mouse:A}=h;A.x=O.pageX-h.bounding.left,A.y=O.pageY-h.bounding.top+window.scrollY,A.set||(A.sx=A.x,A.sy=A.y,A.lx=A.x,A.ly=A.y,A.set=!0)},w=()=>{f(),g()};return f(),g(),window.addEventListener("resize",w),window.addEventListener("mousemove",S),r.current=requestAnimationFrame(b),()=>{window.removeEventListener("resize",w),window.removeEventListener("mousemove",S),r.current&&cancelAnimationFrame(r.current)}},[]),e.jsxs("div",{ref:i,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 ww(){const[l,i]=m.useState(""),[r,o]=m.useState(!1),[u,x]=m.useState(""),[h,f]=m.useState(!0),g=ka(),{enableWavesBackground:j,setEnableWavesBackground:v}=uj(),{theme:y,setTheme:b}=dm();m.useEffect(()=>{(async()=>{try{await om()&&g({to:"/"})}catch{}finally{f(!1)}})()},[g]);const w=y==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":y,O=()=>{b(w==="dark"?"light":"dark")},A=async D=>{if(D.preventDefault(),x(""),!l.trim()){x("请输入 Access Token");return}o(!0);try{const V=await fetch("/api/webui/auth/verify",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({token:l.trim()})}),z=await V.json();V.ok&&z.valid?z.is_first_setup?g({to:"/setup"}):g({to:"/"}):x(z.message||"Token 验证失败,请检查后重试")}catch(V){console.error("Token 验证错误:",V),x("连接服务器失败,请检查网络连接")}finally{o(!1)}};return h?e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[j&&e.jsx(Sp,{}),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:[j&&e.jsx(Sp,{}),e.jsxs(Ve,{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:O,className:"absolute right-4 top-4 rounded-lg p-2 hover:bg-accent transition-colors z-10 text-foreground",title:w==="dark"?"切换到浅色模式":"切换到深色模式",children:w==="dark"?e.jsx(Ag,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"}):e.jsx(Og,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"})}),e.jsxs(rs,{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(xp,{className:"h-8 w-8 text-primary",strokeWidth:2,fill:"none"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(cs,{className:"text-2xl font-bold",children:"欢迎使用 MaiBot"}),e.jsx(st,{className:"text-base",children:"请输入您的 Access Token 以继续访问系统"})]})]}),e.jsx(gs,{children:e.jsxs("form",{onSubmit:A,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"token",className:"text-sm font-medium",children:"Access Token"}),e.jsxs("div",{className:"relative",children:[e.jsx(Dg,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground",strokeWidth:2,fill:"none"}),e.jsx(ie,{id:"token",type:"password",placeholder:"请输入您的 Access Token",value:l,onChange:D=>i(D.target.value),className:H("pl-10",u&&"border-red-500 focus-visible:ring-red-500"),disabled:r,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(Ot,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{children:u})]}),e.jsx(C,{type:"submit",className:"w-full",disabled:r,children:r?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(Qs,{children:[e.jsx(mm,{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(Rg,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我没有 Token,我该去哪里获得 Token?"]})}),e.jsxs(qs,{className:"sm:max-w-md",children:[e.jsxs(Gs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(xp,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"如何获取 Access Token"]}),e.jsx(Ws,{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(Ly,{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(Aa,{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(Ot,{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(js,{children:[e.jsx(mt,{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(hn,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我觉得这个界面很卡怎么办?"]})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsxs(ms,{className:"flex items-center gap-2",children:[e.jsx(hn,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"关闭背景动画"]}),e.jsx(xs,{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(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{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:iw})})]})}const Ys=m.forwardRef(({className:l,...i},r)=>e.jsx("textarea",{className:H("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:r,...i}));Ys.displayName="Textarea";const jo=m.forwardRef(({className:l,orientation:i="horizontal",decorative:r=!0,...o},u)=>e.jsx(lg,{ref:u,decorative:r,orientation:i,className:H("shrink-0 bg-border",i==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",l),...o}));jo.displayName=lg.displayName;function _w({config:l,onChange:i}){const r=u=>{u.trim()&&!l.alias_names.includes(u.trim())&&i({...l,alias_names:[...l.alias_names,u.trim()]})},o=u=>{i({...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(k,{htmlFor:"qq_account",children:"QQ账号 *"}),e.jsx(ie,{id:"qq_account",type:"number",placeholder:"请输入机器人的QQ账号",value:l.qq_account||"",onChange:u=>i({...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(k,{htmlFor:"nickname",children:"昵称 *"}),e.jsx(ie,{id:"nickname",placeholder:"请输入机器人的昵称",value:l.nickname,onChange:u=>i({...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(k,{children:"别名"}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:l.alias_names.map((u,x)=>e.jsxs(Ye,{variant:"secondary",className:"gap-1",children:[u,e.jsx("button",{type:"button",onClick:()=>o(x),className:"ml-1 hover:text-destructive",children:e.jsx(fl,{className:"h-3 w-3"})})]},x))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{id:"alias_input",placeholder:"输入别名后按回车添加",onKeyPress:u=>{u.key==="Enter"&&(r(u.target.value),u.target.value="")}}),e.jsx(C,{type:"button",variant:"outline",onClick:()=>{const u=document.getElementById("alias_input");u&&(r(u.value),u.value="")},children:"添加"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人的其他称呼,可以添加多个"})]})]})}function Sw({config:l,onChange:i}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(k,{htmlFor:"personality",children:"人格特征 *"}),e.jsx(Ys,{id:"personality",placeholder:"描述机器人的人格特质和身份特征(建议120字以内)",value:l.personality,onChange:r=>i({...l,personality:r.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:是一个女大学生,现在在读大二,会刷贴吧"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(k,{htmlFor:"reply_style",children:"表达风格 *"}),e.jsx(Ys,{id:"reply_style",placeholder:"描述机器人说话的表达风格、表达习惯",value:l.reply_style,onChange:r=>i({...l,reply_style:r.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:回复平淡一些,简短一些,说中文,参考贴吧、知乎和微博的回复风格"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(k,{htmlFor:"interest",children:"兴趣 *"}),e.jsx(Ys,{id:"interest",placeholder:"描述机器人感兴趣的话题",value:l.interest,onChange:r=>i({...l,interest:r.target.value}),rows:2}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"会影响机器人对什么话题进行回复"})]}),e.jsx(jo,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(k,{htmlFor:"plan_style",children:"群聊说话规则 *"}),e.jsx(Ys,{id:"plan_style",placeholder:"机器人在群聊中的行为风格和规则",value:l.plan_style,onChange:r=>i({...l,plan_style:r.target.value}),rows:4}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在群聊中如何行动,例如回复频率、条件等"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(k,{htmlFor:"private_plan_style",children:"私聊说话规则 *"}),e.jsx(Ys,{id:"private_plan_style",placeholder:"机器人在私聊中的行为风格和规则",value:l.private_plan_style,onChange:r=>i({...l,private_plan_style:r.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在私聊中的行为方式"})]})]})}function Cw({config:l,onChange:i}){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(k,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(l.emoji_chance*100).toFixed(0),"%"]})]}),e.jsx(ie,{id:"emoji_chance",type:"range",min:"0",max:"1",step:"0.1",value:l.emoji_chance,onChange:r=>i({...l,emoji_chance:Number(r.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人发送表情包的概率"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(k,{htmlFor:"max_reg_num",children:"最大表情包数量"}),e.jsx(ie,{id:"max_reg_num",type:"number",min:"1",max:"200",value:l.max_reg_num,onChange:r=>i({...l,max_reg_num:Number(r.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(k,{htmlFor:"do_replace",children:"达到最大数量时替换"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"开启后会删除旧表情包,关闭则不再收集新表情包"})]}),e.jsx(Fe,{id:"do_replace",checked:l.do_replace,onCheckedChange:r=>i({...l,do_replace:r})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(k,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(ie,{id:"check_interval",type:"number",min:"1",max:"120",value:l.check_interval,onChange:r=>i({...l,check_interval:Number(r.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"检查表情包注册、破损、删除的时间间隔"})]}),e.jsx(jo,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{htmlFor:"steal_emoji",children:"偷取表情包"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人将一些表情包据为己有"})]}),e.jsx(Fe,{id:"steal_emoji",checked:l.steal_emoji,onCheckedChange:r=>i({...l,steal_emoji:r})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{htmlFor:"content_filtration",children:"启用表情包过滤"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只保存符合要求的表情包"})]}),e.jsx(Fe,{id:"content_filtration",checked:l.content_filtration,onCheckedChange:r=>i({...l,content_filtration:r})})]}),l.content_filtration&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(k,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(ie,{id:"filtration_prompt",placeholder:"例如:符合公序良俗",value:l.filtration_prompt,onChange:r=>i({...l,filtration_prompt:r.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"描述表情包应该符合的要求"})]})]})}function kw({config:l,onChange:i}){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(k,{htmlFor:"enable_tool",children:"启用工具系统"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人使用各种工具增强功能"})]}),e.jsx(Fe,{id:"enable_tool",checked:l.enable_tool,onCheckedChange:r=>i({...l,enable_tool:r})})]}),e.jsx(jo,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{htmlFor:"all_global",children:"启用全局黑话模式"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人学习和使用群组黑话"})]}),e.jsx(Fe,{id:"all_global",checked:l.all_global,onCheckedChange:r=>i({...l,all_global:r})})]})]})}function Tw({config:l,onChange:i}){const[r,o]=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(ao,{className:"h-3 w-3"})]})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(k,{htmlFor:"siliconflow_api_key",children:"SiliconFlow API Key *"}),e.jsxs("div",{className:"relative",children:[e.jsx(ie,{id:"siliconflow_api_key",type:r?"text":"password",placeholder:"sk-...",value:l.api_key,onChange:u=>i({api_key:u.target.value}),className:"font-mono pr-10"}),e.jsx(C,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",onClick:()=>o(!r),children:r?e.jsx(wr,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Gt,{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 Ew(){const l=await we("/api/webui/config/bot",{method:"GET",headers:Is()});if(!l.ok)throw new Error("读取Bot配置失败");const r=(await l.json()).config.bot||{};return{qq_account:r.qq_account||0,nickname:r.nickname||"",alias_names:r.alias_names||[]}}async function zw(){const l=await we("/api/webui/config/bot",{method:"GET",headers:Is()});if(!l.ok)throw new Error("读取人格配置失败");const r=(await l.json()).config.personality||{};return{personality:r.personality||"",reply_style:r.reply_style||"",interest:r.interest||"",plan_style:r.plan_style||"",private_plan_style:r.private_plan_style||""}}async function Mw(){const l=await we("/api/webui/config/bot",{method:"GET",headers:Is()});if(!l.ok)throw new Error("读取表情包配置失败");const r=(await l.json()).config.emoji||{};return{emoji_chance:r.emoji_chance??.4,max_reg_num:r.max_reg_num??40,do_replace:r.do_replace??!0,check_interval:r.check_interval??10,steal_emoji:r.steal_emoji??!0,content_filtration:r.content_filtration??!1,filtration_prompt:r.filtration_prompt||""}}async function Aw(){const l=await we("/api/webui/config/bot",{method:"GET",headers:Is()});if(!l.ok)throw new Error("读取其他配置失败");const r=(await l.json()).config,o=r.tool||{},u=r.expression||{};return{enable_tool:o.enable_tool??!0,all_global:u.all_global_jargon??!0}}async function Ow(){const l=await we("/api/webui/config/model",{method:"GET",headers:Is()});if(!l.ok)throw new Error("读取模型配置失败");return{api_key:((await l.json()).config.api_providers||[]).find(x=>x.name==="SiliconFlow")?.api_key||""}}async function Dw(l){const i=await we("/api/webui/config/bot/section/bot",{method:"POST",headers:Is(),body:JSON.stringify(l)});if(!i.ok){const r=await i.json();throw new Error(r.detail||"保存Bot基础配置失败")}return await i.json()}async function Rw(l){const i=await we("/api/webui/config/bot/section/personality",{method:"POST",headers:Is(),body:JSON.stringify(l)});if(!i.ok){const r=await i.json();throw new Error(r.detail||"保存人格配置失败")}return await i.json()}async function Lw(l){const i=await we("/api/webui/config/bot/section/emoji",{method:"POST",headers:Is(),body:JSON.stringify(l)});if(!i.ok){const r=await i.json();throw new Error(r.detail||"保存表情包配置失败")}return await i.json()}async function Uw(l){const i=[];i.push(we("/api/webui/config/bot/section/tool",{method:"POST",headers:Is(),body:JSON.stringify({enable_tool:l.enable_tool})})),i.push(we("/api/webui/config/bot/section/expression",{method:"POST",headers:Is(),body:JSON.stringify({all_global_jargon:l.all_global})}));const r=await Promise.all(i);for(const o of r)if(!o.ok){const u=await o.json();throw new Error(u.detail||"保存其他配置失败")}return{success:!0}}async function Bw(l){const i=await we("/api/webui/config/model",{method:"GET",headers:Is()});if(!i.ok)throw new Error("读取模型配置失败");const o=(await i.json()).config,u=o.api_providers||[],x=u.findIndex(g=>g.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={...o,api_providers:u},f=await we("/api/webui/config/model",{method:"POST",headers:Is(),body:JSON.stringify(h)});if(!f.ok){const g=await f.json();throw new Error(g.detail||"保存模型配置失败")}return await f.json()}async function Cp(){const l=await we("/api/webui/setup/complete",{method:"POST"});if(!l.ok){const i=await l.json();throw new Error(i.message||"标记配置完成失败")}return await l.json()}function Hw(){return e.jsx(jn,{children:e.jsx($w,{})})}function $w(){const l=ka(),{toast:i}=Ks(),{triggerRestart:r}=Il(),[o,u]=m.useState(0),[x,h]=m.useState(!1),[f,g]=m.useState(!1),[j,v]=m.useState(!0),[y,b]=m.useState({qq_account:0,nickname:"",alias_names:[]}),[S,w]=m.useState({personality:"是一个女大学生,现在在读大二,会刷贴吧。",reply_style:"请回复的平淡一些,简短一些,说中文,不要刻意突出自身学科背景。可以参考贴吧,知乎和微博的回复风格。",interest:"对技术相关话题,游戏和动漫相关话题感兴趣,也对日常话题感兴趣,不喜欢太过沉重严肃的话题",plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 2.如果相同的内容已经被执行,请不要重复执行 3.请控制你的发言频率,不要太过频繁的发言 4.如果有人对你感到厌烦,请减少回复 5.如果有人对你进行攻击,或者情绪激动,请你以合适的方法应对`,private_plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 2.如果相同的内容已经被执行,请不要重复执行 3.某句话如果已经被回复过,不要重复回复`}),[O,A]=m.useState({emoji_chance:.4,max_reg_num:40,do_replace:!0,check_interval:10,steal_emoji:!0,content_filtration:!1,filtration_prompt:"符合公序良俗"}),[D,V]=m.useState({enable_tool:!0,all_global:!0}),[z,_]=m.useState({api_key:""}),T=[{id:"bot-basic",title:"Bot基础",description:"配置机器人的基本信息",icon:fr},{id:"personality",title:"人格配置",description:"定义机器人的性格和说话风格",icon:oo},{id:"emoji",title:"表情包",description:"配置表情包相关设置",icon:im},{id:"other",title:"其他设置",description:"工具、情绪系统等配置",icon:ji},{id:"siliconflow",title:"API配置",description:"配置硅基流动API密钥",icon:Dg}],$=(o+1)/T.length*100;m.useEffect(()=>{(async()=>{try{v(!0);const[je,be,U,P,X]=await Promise.all([Ew(),zw(),Mw(),Aw(),Ow()]);b(je),w(be),A(U),V(P),_(X)}catch(je){i({title:"加载配置失败",description:je instanceof Error?je.message:"无法加载现有配置,将使用默认值",variant:"destructive"})}finally{v(!1)}})()},[i]);const E=async()=>{g(!0);try{switch(o){case 0:await Dw(y);break;case 1:await Rw(S);break;case 2:await Lw(O);break;case 3:await Uw(D);break;case 4:await Bw(z);break}return i({title:"保存成功",description:`${T[o].title}配置已保存`}),!0}catch(oe){return i({title:"保存失败",description:oe instanceof Error?oe.message:"未知错误",variant:"destructive"}),!1}finally{g(!1)}},se=async()=>{await E()&&o{o>0&&u(o-1)},ne=async()=>{h(!0);try{if(!await E()){h(!1);return}await Cp(),i({title:"配置完成",description:"麦麦正在重启以应用新配置..."}),await r()}catch(oe){i({title:"配置失败",description:oe instanceof Error?oe.message:"未知错误",variant:"destructive"})}finally{h(!1)}},ue=async()=>{try{await Cp(),l({to:"/"})}catch(oe){i({title:"跳过失败",description:oe instanceof Error?oe.message:"未知错误",variant:"destructive"})}},Se=()=>{switch(o){case 0:return e.jsx(_w,{config:y,onChange:b});case 1:return e.jsx(Sw,{config:S,onChange:w});case 2:return e.jsx(Cw,{config:O,onChange:A});case 3:return e.jsx(kw,{config:D,onChange:V});case 4:return e.jsx(Tw,{config:z,onChange:_});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(vn,{}),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"})]}),j?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(Uy,{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:["步骤 ",o+1," / ",T.length]}),e.jsxs("span",{className:"font-medium text-primary",children:[Math.round($),"%"]})]}),e.jsx(gn,{value:$,className:"h-2"})]}),e.jsx("div",{className:"mb-6 md:mb-8 flex justify-between",children:T.map((oe,je)=>{const be=oe.icon;return e.jsxs("div",{className:H("flex flex-1 flex-col items-center gap-1 md:gap-2",jel({to:"/"}),className:"gap-2 w-full sm:w-auto",children:[e.jsx(po,{className:"h-4 w-4"}),"返回首页"]}),e.jsxs(C,{size:"lg",variant:"outline",onClick:()=>window.history.back(),className:"gap-2 w-full sm:w-auto",children:[e.jsx(hi,{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 qw=Ct.memo(function({config:i,onChange:r}){const o=()=>{r({...i,platforms:[...i.platforms,""]})},u=j=>{r({...i,platforms:i.platforms.filter((v,y)=>y!==j)})},x=(j,v)=>{const y=[...i.platforms];y[j]=v,r({...i,platforms:y})},h=()=>{r({...i,alias_names:[...i.alias_names,""]})},f=j=>{r({...i,alias_names:i.alias_names.filter((v,y)=>y!==j)})},g=(j,v)=>{const y=[...i.alias_names];y[j]=v,r({...i,alias_names:y})};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(k,{htmlFor:"platform",children:"平台"}),e.jsx(ie,{id:"platform",value:i.platform,onChange:j=>r({...i,platform:j.target.value}),placeholder:"qq"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"qq_account",children:"QQ账号"}),e.jsx(ie,{id:"qq_account",value:i.qq_account,onChange:j=>r({...i,qq_account:j.target.value}),placeholder:"123456789"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"nickname",children:"昵称"}),e.jsx(ie,{id:"nickname",value:i.nickname,onChange:j=>r({...i,nickname:j.target.value}),placeholder:"麦麦"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(k,{children:"其他平台账号"}),e.jsxs(C,{onClick:o,size:"sm",variant:"outline",children:[e.jsx(ut,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[i.platforms.map((j,v)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{value:j,onChange:y=>x(v,y.target.value),placeholder:"wx:114514"}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{size:"icon",variant:"outline",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:['确定要删除平台账号 "',j||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>u(v),children:"删除"})]})]})]})]},v)),i.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(k,{children:"别名"}),e.jsxs(C,{onClick:h,size:"sm",variant:"outline",children:[e.jsx(ut,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[i.alias_names.map((j,v)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{value:j,onChange:y=>g(v,y.target.value),placeholder:"小麦"}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{size:"icon",variant:"outline",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:['确定要删除别名 "',j||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>f(v),children:"删除"})]})]})]})]},v)),i.alias_names.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无别名"})]})]})]})]})})}),Gw=Ct.memo(function({config:i,onChange:r}){const o=()=>{r({...i,states:[...i.states,""]})},u=h=>{r({...i,states:i.states.filter((f,g)=>g!==h)})},x=(h,f)=>{const g=[...i.states];g[h]=f,r({...i,states:g})};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(k,{htmlFor:"personality",children:"人格特质"}),e.jsx(Ys,{id:"personality",value:i.personality,onChange:h=>r({...i,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(k,{htmlFor:"reply_style",children:"表达风格"}),e.jsx(Ys,{id:"reply_style",value:i.reply_style,onChange:h=>r({...i,reply_style:h.target.value}),placeholder:"描述说话的表达风格和习惯",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"interest",children:"兴趣"}),e.jsx(Ys,{id:"interest",value:i.interest,onChange:h=>r({...i,interest:h.target.value}),placeholder:"会影响麦麦对什么话题进行回复",rows:2})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"plan_style",children:"说话规则与行为风格"}),e.jsx(Ys,{id:"plan_style",value:i.plan_style,onChange:h=>r({...i,plan_style:h.target.value}),placeholder:"麦麦的说话规则和行为风格",rows:5})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"visual_style",children:"识图规则"}),e.jsx(Ys,{id:"visual_style",value:i.visual_style,onChange:h=>r({...i,visual_style:h.target.value}),placeholder:"识图时的处理规则",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"private_plan_style",children:"私聊规则"}),e.jsx(Ys,{id:"private_plan_style",value:i.private_plan_style,onChange:h=>r({...i,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(k,{children:"状态列表(人格多样性)"}),e.jsxs(C,{onClick:o,size:"sm",variant:"outline",children:[e.jsx(ut,{className:"h-4 w-4 mr-1"}),"添加状态"]})]}),e.jsx("div",{className:"space-y-2",children:i.states.map((h,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ys,{value:h,onChange:g=>x(f,g.target.value),placeholder:"描述一个人格状态",rows:2}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{size:"icon",variant:"outline",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsx(xs,{children:"确定要删除这个人格状态吗?此操作无法撤销。"})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>u(f),children:"删除"})]})]})]})]},f))})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"state_probability",children:"状态替换概率"}),e.jsx(ie,{id:"state_probability",type:"number",step:"0.1",min:"0",max:"1",value:i.state_probability,onChange:h=>r({...i,state_probability:parseFloat(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"每次构建人格时替换 personality 的概率(0.0-1.0)"})]})]})]})})}),Ue=fy,Be=py,Re=m.forwardRef(({className:l,children:i,...r},o)=>e.jsxs(fg,{ref:o,className:H("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),...r,children:[i,e.jsx(dy,{asChild:!0,children:e.jsx(Fa,{className:"h-4 w-4 opacity-50"})})]}));Re.displayName=fg.displayName;const pj=m.forwardRef(({className:l,...i},r)=>e.jsx(pg,{ref:r,className:H("flex cursor-default items-center justify-center py-1",l),...i,children:e.jsx(fi,{className:"h-4 w-4"})}));pj.displayName=pg.displayName;const gj=m.forwardRef(({className:l,...i},r)=>e.jsx(gg,{ref:r,className:H("flex cursor-default items-center justify-center py-1",l),...i,children:e.jsx(Fa,{className:"h-4 w-4"})}));gj.displayName=gg.displayName;const Le=m.forwardRef(({className:l,children:i,position:r="popper",...o},u)=>e.jsx(uy,{children:e.jsxs(jg,{ref:u,className:H("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]",r==="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:r,...o,children:[e.jsx(pj,{}),e.jsx(my,{className:H("p-1",r==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:i}),e.jsx(gj,{})]})}));Le.displayName=jg.displayName;const Vw=m.forwardRef(({className:l,...i},r)=>e.jsx(vg,{ref:r,className:H("px-2 py-1.5 text-sm font-semibold",l),...i}));Vw.displayName=vg.displayName;const ee=m.forwardRef(({className:l,children:i,...r},o)=>e.jsxs(bg,{ref:o,className:H("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),...r,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(xy,{children:e.jsx(ea,{className:"h-4 w-4"})})}),e.jsx(hy,{children:i})]}));ee.displayName=bg.displayName;const Fw=m.forwardRef(({className:l,...i},r)=>e.jsx(Ng,{ref:r,className:H("-mx-1 my-1 h-px bg-muted",l),...i}));Fw.displayName=Ng.displayName;const Ia=FN,Qa=IN,La=m.forwardRef(({className:l,align:i="center",sideOffset:r=4,...o},u)=>e.jsx(VN,{children:e.jsx(ng,{ref:u,align:i,sideOffset:r,className:H("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),...o})}));La.displayName=ng.displayName;const Iw=Ct.memo(function({value:i,onChange:r}){const[o,u]=m.useState("00"),[x,h]=m.useState("00"),[f,g]=m.useState("23"),[j,v]=m.useState("59");m.useEffect(()=>{const b=i.split("-");if(b.length===2){const[S,w]=b,[O,A]=S.split(":"),[D,V]=w.split(":");O&&u(O.padStart(2,"0")),A&&h(A.padStart(2,"0")),D&&g(D.padStart(2,"0")),V&&v(V.padStart(2,"0"))}},[i]);const y=(b,S,w,O)=>{const A=`${b}:${S}-${w}:${O}`;r(A)};return e.jsxs(Ia,{children:[e.jsx(Qa,{asChild:!0,children:e.jsxs(C,{variant:"outline",className:"w-full justify-start font-mono text-sm",children:[e.jsx(xi,{className:"h-4 w-4 mr-2"}),i||"选择时间段"]})}),e.jsx(La,{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(k,{className:"text-xs",children:"小时"}),e.jsxs(Ue,{value:o,onValueChange:b=>{u(b),y(b,x,f,j)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsx(Le,{children:Array.from({length:24},(b,S)=>S).map(b=>e.jsx(ee,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-xs",children:"分钟"}),e.jsxs(Ue,{value:x,onValueChange:b=>{h(b),y(o,b,f,j)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsx(Le,{children:Array.from({length:60},(b,S)=>S).map(b=>e.jsx(ee,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]})]})]}),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(k,{className:"text-xs",children:"小时"}),e.jsxs(Ue,{value:f,onValueChange:b=>{g(b),y(o,x,b,j)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsx(Le,{children:Array.from({length:24},(b,S)=>S).map(b=>e.jsx(ee,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-xs",children:"分钟"}),e.jsxs(Ue,{value:j,onValueChange:b=>{v(b),y(o,x,f,b)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsx(Le,{children:Array.from({length:60},(b,S)=>S).map(b=>e.jsx(ee,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]})]})]})]})})]})}),Qw=Ct.memo(function({rule:i}){const r=`{ target = "${i.target}", time = "${i.time}", value = ${i.value.toFixed(1)} }`;return e.jsxs(Ia,{children:[e.jsx(Qa,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",children:[e.jsx(Gt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(La,{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:r}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})}),Yw=Ct.memo(function({config:i,onChange:r}){const o=()=>{r({...i,talk_value_rules:[...i.talk_value_rules,{target:"",time:"00:00-23:59",value:1}]})},u=h=>{r({...i,talk_value_rules:i.talk_value_rules.filter((f,g)=>g!==h)})},x=(h,f,g)=>{const j=[...i.talk_value_rules];j[h]={...j[h],[f]:g},r({...i,talk_value_rules:j})};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(k,{htmlFor:"talk_value",children:"聊天频率(基础值)"}),e.jsx(ie,{id:"talk_value",type:"number",step:"0.1",min:"0",max:"1",value:i.talk_value,onChange:h=>r({...i,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(Fe,{id:"mentioned_bot_reply",checked:i.mentioned_bot_reply,onCheckedChange:h=>r({...i,mentioned_bot_reply:h})}),e.jsx(k,{htmlFor:"mentioned_bot_reply",className:"cursor-pointer",children:"启用提及必回复"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"max_context_size",children:"上下文长度"}),e.jsx(ie,{id:"max_context_size",type:"number",min:"1",value:i.max_context_size,onChange:h=>r({...i,max_context_size:parseInt(h.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"planner_smooth",children:"规划器平滑"}),e.jsx(ie,{id:"planner_smooth",type:"number",step:"1",min:"0",value:i.planner_smooth,onChange:h=>r({...i,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(Fe,{id:"enable_talk_value_rules",checked:i.enable_talk_value_rules,onCheckedChange:h=>r({...i,enable_talk_value_rules:h})}),e.jsx(k,{htmlFor:"enable_talk_value_rules",className:"cursor-pointer",children:"启用动态发言频率规则"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Fe,{id:"include_planner_reasoning",checked:i.include_planner_reasoning,onCheckedChange:h=>r({...i,include_planner_reasoning:h})}),e.jsx(k,{htmlFor:"include_planner_reasoning",className:"cursor-pointer",children:"将 planner 推理加入 replyer"})]})]})]}),i.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(C,{onClick:o,size:"sm",children:[e.jsx(ut,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),i.talk_value_rules&&i.talk_value_rules.length>0?e.jsx("div",{className:"space-y-4",children:i.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(Qw,{rule:h}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"sm",children:e.jsx(es,{className:"h-4 w-4 text-destructive"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:["确定要删除规则 #",f+1," 吗?此操作无法撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>u(f),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(Ue,{value:h.target===""?"global":"specific",onValueChange:g=>{g==="global"?x(f,"target",""):x(f,"target","qq::group")},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"global",children:"全局配置"}),e.jsx(ee,{value:"specific",children:"详细配置"})]})]})]}),h.target!==""&&(()=>{const g=h.target.split(":"),j=g[0]||"qq",v=g[1]||"",y=g[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(k,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Ue,{value:j,onValueChange:b=>{x(f,"target",`${b}:${v}:${y}`)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"qq",children:"QQ"}),e.jsx(ee,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(ie,{value:v,onChange:b=>{x(f,"target",`${j}:${b.target.value}:${y}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Ue,{value:y,onValueChange:b=>{x(f,"target",`${j}:${v}:${b}`)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"group",children:"群组(group)"}),e.jsx(ee,{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(k,{className:"text-xs font-medium",children:"时间段 (Time)"}),e.jsx(Iw,{value:h.time,onChange:g=>x(f,"time",g)}),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(k,{htmlFor:`rule-value-${f}`,className:"text-xs font-medium",children:"发言频率值 (Value)"}),e.jsx(ie,{id:`rule-value-${f}`,type:"number",step:"0.01",min:"0.01",max:"1",value:h.value,onChange:g=>{const j=parseFloat(g.target.value);isNaN(j)||x(f,"value",Math.max(.01,Math.min(1,j)))},className:"w-20 h-8 text-xs"})]}),e.jsx(ma,{value:[h.value],onValueChange:g=>x(f,"value",g[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 表示正常发言"]})]})]})]})]})}),Kw=Ct.memo(function({config:i,onChange:r}){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(Fe,{checked:i.enable_asr,onCheckedChange:o=>r({...i,enable_asr:o})}),e.jsx(k,{className:"cursor-pointer",children:"启用语音识别"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后麦麦可以识别语音消息,需要配置语音识别模型"})]})}),Xw=Ct.memo(function({config:i,onChange:r}){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(Fe,{checked:i.enable,onCheckedChange:o=>r({...i,enable:o})}),e.jsx(k,{className:"cursor-pointer",children:"启用 LPMM 知识库"})]}),i.enable&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"LPMM 模式"}),e.jsxs(Ue,{value:i.lpmm_mode,onValueChange:o=>r({...i,lpmm_mode:o}),children:[e.jsx(Re,{children:e.jsx(Be,{placeholder:"选择 LPMM 模式"})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"classic",children:"经典模式"}),e.jsx(ee,{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(k,{children:"同义词搜索 TopK"}),e.jsx(ie,{type:"number",min:"1",value:i.rag_synonym_search_top_k,onChange:o=>r({...i,rag_synonym_search_top_k:parseInt(o.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"同义词阈值"}),e.jsx(ie,{type:"number",step:"0.1",min:"0",max:"1",value:i.rag_synonym_threshold,onChange:o=>r({...i,rag_synonym_threshold:parseFloat(o.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"实体提取线程数"}),e.jsx(ie,{type:"number",min:"1",value:i.info_extraction_workers,onChange:o=>r({...i,info_extraction_workers:parseInt(o.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"嵌入向量维度"}),e.jsx(ie,{type:"number",min:"1",value:i.embedding_dimension,onChange:o=>r({...i,embedding_dimension:parseInt(o.target.value)})})]})]})]})]})]})}),Pw=Ct.memo(function({config:i,onChange:r}){const[o,u]=m.useState(""),[x,h]=m.useState("WARNING"),f=()=>{o&&!i.suppress_libraries.includes(o)&&(r({...i,suppress_libraries:[...i.suppress_libraries,o]}),u(""))},g=w=>{r({...i,suppress_libraries:i.suppress_libraries.filter(O=>O!==w)})},j=()=>{o&&!i.library_log_levels[o]&&(r({...i,library_log_levels:{...i.library_log_levels,[o]:x}}),u(""),h("WARNING"))},v=w=>{const O={...i.library_log_levels};delete O[w],r({...i,library_log_levels:O})},y=["DEBUG","INFO","WARNING","ERROR","CRITICAL"],b=["FULL","compact","lite"],S=["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(k,{children:"日期格式"}),e.jsx(ie,{value:i.date_style,onChange:w=>r({...i,date_style:w.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(k,{children:"日志级别样式"}),e.jsxs(Ue,{value:i.log_level_style,onValueChange:w=>r({...i,log_level_style:w}),children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsx(Le,{children:b.map(w=>e.jsx(ee,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"日志文本颜色"}),e.jsxs(Ue,{value:i.color_text,onValueChange:w=>r({...i,color_text:w}),children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsx(Le,{children:S.map(w=>e.jsx(ee,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"全局日志级别"}),e.jsxs(Ue,{value:i.log_level,onValueChange:w=>r({...i,log_level:w}),children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsx(Le,{children:y.map(w=>e.jsx(ee,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"控制台日志级别"}),e.jsxs(Ue,{value:i.console_log_level,onValueChange:w=>r({...i,console_log_level:w}),children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsx(Le,{children:y.map(w=>e.jsx(ee,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"文件日志级别"}),e.jsxs(Ue,{value:i.file_log_level,onValueChange:w=>r({...i,file_log_level:w}),children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsx(Le,{children:y.map(w=>e.jsx(ee,{value:w,children:w},w))})]})]})]})]}),e.jsxs("div",{children:[e.jsx(k,{className:"mb-2 block",children:"完全屏蔽的库"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ie,{value:o,onChange:w=>u(w.target.value),placeholder:"输入库名",className:"flex-1",onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),f())}}),e.jsx(C,{onClick:f,size:"sm",className:"flex-shrink-0",children:e.jsx(ut,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:i.suppress_libraries.map(w=>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:w}),e.jsx(C,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0",onClick:()=>g(w),children:e.jsx(es,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},w))})]}),e.jsxs("div",{children:[e.jsx(k,{className:"mb-2 block",children:"特定库的日志级别"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ie,{value:o,onChange:w=>u(w.target.value),placeholder:"输入库名",className:"flex-1"}),e.jsxs(Ue,{value:x,onValueChange:h,children:[e.jsx(Re,{className:"w-32",children:e.jsx(Be,{})}),e.jsx(Le,{children:y.map(w=>e.jsx(ee,{value:w,children:w},w))})]}),e.jsx(C,{onClick:j,size:"sm",children:e.jsx(ut,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:Object.entries(i.library_log_levels).map(([w,O])=>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:w}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:O}),e.jsx(C,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>v(w),children:e.jsx(es,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]})]},w))})]})]})}),Jw=Ct.memo(function({config:i,onChange:r}){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(k,{children:"显示 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否在日志中显示提示词"})]}),e.jsx(Fe,{checked:i.show_prompt,onCheckedChange:o=>r({...i,show_prompt:o})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(k,{children:"显示回复器 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的提示词"})]}),e.jsx(Fe,{checked:i.show_replyer_prompt,onCheckedChange:o=>r({...i,show_replyer_prompt:o})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(k,{children:"显示回复器推理"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的推理过程"})]}),e.jsx(Fe,{checked:i.show_replyer_reasoning,onCheckedChange:o=>r({...i,show_replyer_reasoning:o})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(k,{children:"显示 Jargon Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示术语相关的提示词"})]}),e.jsx(Fe,{checked:i.show_jargon_prompt,onCheckedChange:o=>r({...i,show_jargon_prompt:o})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(k,{children:"显示记忆检索 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示记忆检索相关的提示词"})]}),e.jsx(Fe,{checked:i.show_memory_prompt,onCheckedChange:o=>r({...i,show_memory_prompt:o})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(k,{children:"显示 Planner Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 Planner 的提示词和原始返回结果"})]}),e.jsx(Fe,{checked:i.show_planner_prompt,onCheckedChange:o=>r({...i,show_planner_prompt:o})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(k,{children:"显示 LPMM 相关文段"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 LPMM 知识库找到的相关文段日志"})]}),e.jsx(Fe,{checked:i.show_lpmm_paragraph,onCheckedChange:o=>r({...i,show_lpmm_paragraph:o})})]})]})]})}),Zw=Ct.memo(function({config:i,onChange:r}){const[o,u]=m.useState(""),x=()=>{o&&!i.auth_token.includes(o)&&(r({...i,auth_token:[...i.auth_token,o]}),u(""))},h=f=>{r({...i,auth_token:i.auth_token.filter((g,j)=>j!==f)})};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:"MaimMessage 服务配置"}),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(k,{children:"启用自定义服务器"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否使用自定义的 MaimMessage 服务器"})]}),e.jsx(Fe,{checked:i.use_custom,onCheckedChange:f=>r({...i,use_custom:f})})]}),i.use_custom&&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(k,{children:"主机地址"}),e.jsx(ie,{value:i.host,onChange:f=>r({...i,host:f.target.value}),placeholder:"127.0.0.1"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"端口号"}),e.jsx(ie,{type:"number",value:i.port,onChange:f=>r({...i,port:parseInt(f.target.value)}),placeholder:"8090"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"连接模式"}),e.jsxs(Ue,{value:i.mode,onValueChange:f=>r({...i,mode:f}),children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"ws",children:"WebSocket (ws)"}),e.jsx(ee,{value:"tcp",children:"TCP"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Fe,{checked:i.use_wss,onCheckedChange:f=>r({...i,use_wss:f}),disabled:i.mode!=="ws"}),e.jsx(k,{children:"使用 WSS 安全连接"})]})]}),i.use_wss&&i.mode==="ws"&&e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"SSL 证书文件路径"}),e.jsx(ie,{value:i.cert_file,onChange:f=>r({...i,cert_file:f.target.value}),placeholder:"cert.pem"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"SSL 密钥文件路径"}),e.jsx(ie,{value:i.key_file,onChange:f=>r({...i,key_file:f.target.value}),placeholder:"key.pem"})]})]})]})]})]}),e.jsxs("div",{children:[e.jsx(k,{className:"mb-2 block",children:"认证令牌"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"用于 API 验证,为空则不启用验证"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ie,{value:o,onChange:f=>u(f.target.value),placeholder:"输入认证令牌",onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),x())}}),e.jsx(C,{onClick:x,size:"sm",children:e.jsx(ut,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:i.auth_token.map((f,g)=>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:f}),e.jsx(C,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>h(g),children:e.jsx(es,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},g))})]})]})}),Ww=Ct.memo(function({config:i,onChange:r}){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(k,{children:"启用统计信息发送"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"发送匿名统计信息,帮助我们了解全球有多少只麦麦在运行"})]}),e.jsx(Fe,{checked:i.enable,onCheckedChange:o=>r({...i,enable:o})})]})]})}),e1=Ct.memo(function({emojiConfig:i,memoryConfig:r,toolConfig:o,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(Fe,{id:"enable_tool",checked:o.enable_tool,onCheckedChange:f=>h({...o,enable_tool:f})}),e.jsx(k,{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(k,{htmlFor:"max_agent_iterations",children:"记忆思考深度"}),e.jsx(ie,{id:"max_agent_iterations",type:"number",min:"1",value:r.max_agent_iterations,onChange:f=>x({...r,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(k,{htmlFor:"agent_timeout_seconds",children:"最长回忆时间(秒)"}),e.jsx(ie,{id:"agent_timeout_seconds",type:"number",min:"1",step:"0.1",value:r.agent_timeout_seconds??120,onChange:f=>x({...r,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(Fe,{id:"enable_jargon_detection",checked:r.enable_jargon_detection??!0,onCheckedChange:f=>x({...r,enable_jargon_detection:f})}),e.jsx(k,{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(Fe,{id:"global_memory",checked:r.global_memory??!1,onCheckedChange:f=>x({...r,global_memory:f})}),e.jsx(k,{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(k,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsx(ie,{id:"emoji_chance",type:"number",step:"0.1",min:"0",max:"1",value:i.emoji_chance,onChange:f=>u({...i,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(k,{htmlFor:"max_reg_num",children:"最大注册数量"}),e.jsx(ie,{id:"max_reg_num",type:"number",min:"1",value:i.max_reg_num,onChange:f=>u({...i,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(k,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(ie,{id:"check_interval",type:"number",min:"1",value:i.check_interval,onChange:f=>u({...i,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(Fe,{id:"do_replace",checked:i.do_replace,onCheckedChange:f=>u({...i,do_replace:f})}),e.jsx(k,{htmlFor:"do_replace",className:"cursor-pointer",children:"达到最大数量时替换表情包"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Fe,{id:"steal_emoji",checked:i.steal_emoji,onCheckedChange:f=>u({...i,steal_emoji:f})}),e.jsx(k,{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(Fe,{id:"content_filtration",checked:i.content_filtration,onCheckedChange:f=>u({...i,content_filtration:f})}),e.jsx(k,{htmlFor:"content_filtration",className:"cursor-pointer",children:"启用表情包过滤"})]}),i.content_filtration&&e.jsxs("div",{className:"grid gap-2 pl-6 border-l-2 border-primary/20",children:[e.jsx(k,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(ie,{id:"filtration_prompt",value:i.filtration_prompt,onChange:f=>u({...i,filtration_prompt:f.target.value}),placeholder:"符合公序良俗"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只有符合此要求的表情包才会被保存"})]})]})]})})]})}),s1=Ct.memo(function({member:i,groupIndex:r,memberIndex:o,availableChatIds:u,onUpdate:x,onRemove:h}){const f=u.includes(i)||i==="*",[g,j]=m.useState(!f);return e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 flex gap-2",children:g?e.jsxs(e.Fragment,{children:[e.jsx(ie,{value:i,onChange:v=>x(r,o,v.target.value),placeholder:'输入 "*" 或 "qq:123456:group"',className:"flex-1"}),u.length>0&&e.jsx(C,{size:"sm",variant:"outline",onClick:()=>j(!1),title:"切换到下拉选择",children:"下拉"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Ue,{value:i,onValueChange:v=>x(r,o,v),children:[e.jsx(Re,{className:"flex-1",children:e.jsx(Be,{placeholder:"选择聊天流"})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"*",children:"* (全局共享)"}),u.map((v,y)=>e.jsx(ee,{value:v,children:v},y))]})]}),e.jsx(C,{size:"sm",variant:"outline",onClick:()=>j(!0),title:"切换到手动输入",children:"输入"})]})}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{size:"icon",variant:"outline",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:['确定要删除组成员 "',i||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>h(r,o),children:"删除"})]})]})]})]})}),t1=Ct.memo(function({config:i,onChange:r}){const o=()=>{r({...i,learning_list:[...i.learning_list,["","enable","enable","1.0"]]})},u=b=>{r({...i,learning_list:i.learning_list.filter((S,w)=>w!==b)})},x=(b,S,w)=>{const O=[...i.learning_list];O[b][S]=w,r({...i,learning_list:O})},h=({rule:b})=>{const S=`["${b[0]}", "${b[1]}", "${b[2]}", "${b[3]}"]`;return e.jsxs(Ia,{children:[e.jsx(Qa,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",children:[e.jsx(Gt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(La,{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:S}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},f=()=>{r({...i,expression_groups:[...i.expression_groups,[]]})},g=b=>{r({...i,expression_groups:i.expression_groups.filter((S,w)=>w!==b)})},j=b=>{const S=[...i.expression_groups];S[b]=[...S[b],""],r({...i,expression_groups:S})},v=(b,S)=>{const w=[...i.expression_groups];w[b]=w[b].filter((O,A)=>A!==S),r({...i,expression_groups:w})},y=(b,S,w)=>{const O=[...i.expression_groups];O[b][S]=w,r({...i,expression_groups:O})};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(C,{onClick:o,size:"sm",variant:"outline",children:[e.jsx(ut,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),e.jsxs("div",{className:"space-y-4",children:[i.learning_list.map((b,S)=>{const w=i.learning_list.some((_,T)=>T!==S&&_[0]===""),O=b[0]==="",A=b[0].split(":"),D=A[0]||"qq",V=A[1]||"",z=A[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:["规则 ",S+1," ",O&&"(全局配置)"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{rule:b}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{size:"sm",variant:"ghost",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:["确定要删除学习规则 ",S+1," 吗?此操作无法撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>u(S),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(Ue,{value:O?"global":"specific",onValueChange:_=>{_==="global"?x(S,0,""):x(S,0,"qq::group")},disabled:w&&!O,children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"global",children:"全局配置"}),e.jsx(ee,{value:"specific",disabled:w&&!O,children:"详细配置"})]})]}),w&&!O&&e.jsx("p",{className:"text-xs text-amber-600",children:"已存在全局配置,无法创建新的全局配置"})]}),!O&&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(k,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Ue,{value:D,onValueChange:_=>{x(S,0,`${_}:${V}:${z}`)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"qq",children:"QQ"}),e.jsx(ee,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(ie,{value:V,onChange:_=>{x(S,0,`${D}:${_.target.value}:${z}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Ue,{value:z,onValueChange:_=>{x(S,0,`${D}:${V}:${_}`)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"group",children:"群组(group)"}),e.jsx(ee,{value:"private",children:"私聊(private)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前聊天流 ID:",b[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(k,{className:"text-xs font-medium",children:"使用学到的表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦使用从聊天中学到的表达方式"})]}),e.jsx(Fe,{checked:b[1]==="enable",onCheckedChange:_=>x(S,1,_?"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(k,{className:"text-xs font-medium",children:"学习表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦从聊天中学习新的表达方式"})]}),e.jsx(Fe,{checked:b[2]==="enable",onCheckedChange:_=>x(S,2,_?"enable":"disable")})]})}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(k,{className:"text-xs font-medium",children:"学习强度"}),e.jsx(ie,{type:"number",step:"0.1",min:"0",max:"5",value:b[3],onChange:_=>{const T=parseFloat(_.target.value);isNaN(T)||x(S,3,Math.max(0,Math.min(5,T)).toFixed(1))},className:"w-20 h-8 text-xs"})]}),e.jsx(ma,{value:[parseFloat(b[3])||1],onValueChange:_=>x(S,3,_[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/学习强度(秒)"})]})]})]},S)}),i.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(Fe,{checked:i.reflect,onCheckedChange:b=>r({...i,reflect:b})})]}),i.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 S=(i.reflect_operator_id||"").split(":"),w=S[0]||"qq",O=S[1]||"",A=S[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(k,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Ue,{value:w,onValueChange:D=>{r({...i,reflect_operator_id:`${D}:${O}:${A}`})},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"qq",children:"QQ"}),e.jsx(ee,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{className:"text-xs font-medium",children:"用户/群 ID"}),e.jsx(ie,{value:O,onChange:D=>{r({...i,reflect_operator_id:`${w}:${D.target.value}:${A}`})},placeholder:"输入 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Ue,{value:A,onValueChange:D=>{r({...i,reflect_operator_id:`${w}:${O}:${D}`})},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"private",children:"私聊(private)"}),e.jsx(ee,{value:"group",children:"群组(group)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前操作员 ID:",i.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(C,{onClick:()=>{r({...i,allow_reflect:[...i.allow_reflect||[],"qq::group"]})},size:"sm",variant:"outline",children:[e.jsx(ut,{className:"h-4 w-4 mr-1"}),"添加聊天流"]})]}),e.jsxs("div",{className:"space-y-2",children:[(i.allow_reflect||[]).map((b,S)=>{const w=b.split(":"),O=w[0]||"qq",A=w[1]||"",D=w[2]||"group";return e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-muted/50",children:[e.jsxs(Ue,{value:O,onValueChange:V=>{const z=[...i.allow_reflect];z[S]=`${V}:${A}:${D}`,r({...i,allow_reflect:z})},children:[e.jsx(Re,{className:"w-24",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"qq",children:"QQ"}),e.jsx(ee,{value:"wx",children:"微信"})]})]}),e.jsx(ie,{value:A,onChange:V=>{const z=[...i.allow_reflect];z[S]=`${O}:${V.target.value}:${D}`,r({...i,allow_reflect:z})},placeholder:"ID",className:"flex-1 font-mono text-sm"}),e.jsxs(Ue,{value:D,onValueChange:V=>{const z=[...i.allow_reflect];z[S]=`${O}:${A}:${V}`,r({...i,allow_reflect:z})},children:[e.jsx(Re,{className:"w-32",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"group",children:"群组"}),e.jsx(ee,{value:"private",children:"私聊"})]})]}),e.jsx(C,{onClick:()=>{r({...i,allow_reflect:i.allow_reflect.filter((V,z)=>z!==S)})},size:"sm",variant:"ghost",children:e.jsx(es,{className:"h-4 w-4"})})]},S)}),(!i.allow_reflect||i.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(C,{onClick:f,size:"sm",variant:"outline",children:[e.jsx(ut,{className:"h-4 w-4 mr-1"}),"添加共享组"]})]}),e.jsxs("div",{className:"space-y-4",children:[i.expression_groups.map((b,S)=>{const w=i.learning_list.map(O=>O[0]).filter(O=>O!=="");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:["共享组 ",S+1,b.length===1&&b[0]==="*"&&"(全局共享)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(C,{onClick:()=>j(S),size:"sm",variant:"outline",children:e.jsx(ut,{className:"h-4 w-4"})}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{size:"sm",variant:"ghost",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:["确定要删除共享组 ",S+1," 吗?此操作无法撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>g(S),children:"删除"})]})]})]})]})]}),e.jsx("div",{className:"space-y-2",children:b.map((O,A)=>e.jsx(s1,{member:O,groupIndex:S,memberIndex:A,availableChatIds:w,onUpdate:y,onRemove:v},`${S}-${A}`))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'提示:可以从下拉框选择已配置的聊天流,或手动输入。输入 "*" 启用全局共享'})]},S)}),i.expression_groups.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-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(Fe,{id:"all_global_jargon",checked:i.all_global_jargon??!1,onCheckedChange:b=>r({...i,all_global_jargon:b})}),e.jsx(k,{htmlFor:"all_global_jargon",className:"cursor-pointer",children:"全局黑话模式"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"开启后,新增的黑话将默认设为全局(所有聊天流共享)。关闭后,已记录的全局黑话不会改变,需要手动删除。"})]})})]})});function a1({regex:l,reaction:i,onRegexChange:r,onReactionChange:o}){const[u,x]=m.useState(!1),[h,f]=m.useState(""),[g,j]=m.useState(null),[v,y]=m.useState(""),[b,S]=m.useState({}),[w,O]=m.useState(""),A=m.useRef(null),[D,V]=m.useState("build"),z=E=>E.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),_=(E,se=0)=>{const te=A.current;if(!te)return;const ne=te.selectionStart||0,ue=te.selectionEnd||0,Se=l.substring(0,ne)+E+l.substring(ue);r(Se),setTimeout(()=>{const oe=ne+E.length+se;te.setSelectionRange(oe,oe),te.focus()},0)};m.useEffect(()=>{if(!l||!h){j(null),S({}),O(i),y("");return}try{const E=z(l),se=new RegExp(E,"g"),te=h.match(se);j(te),y("");const ue=new RegExp(E).exec(h);if(ue&&ue.groups){S(ue.groups);let Se=i;Object.entries(ue.groups).forEach(([oe,je])=>{Se=Se.replace(new RegExp(`\\[${oe}\\]`,"g"),je||"")}),O(Se)}else S({}),O(i)}catch(E){y(E.message),j(null),S({}),O(i)}},[l,h,i]);const T=()=>{if(!h||!g||g.length===0)return e.jsx("span",{className:"text-muted-foreground",children:h||"请输入测试文本"});try{const E=z(l),se=new RegExp(E,"g");let te=0;const ne=[];let ue;for(;(ue=se.exec(h))!==null;)ue.index>te&&ne.push(e.jsx("span",{children:h.substring(te,ue.index)},`text-${te}`)),ne.push(e.jsx("span",{className:"bg-yellow-200 dark:bg-yellow-900 font-semibold",children:ue[0]},`match-${ue.index}`)),te=ue.index+ue[0].length;return te)",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(Qs,{open:u,onOpenChange:x,children:[e.jsx(mm,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",children:[e.jsx(rm,{className:"h-4 w-4 mr-1"}),"正则编辑器"]})}),e.jsxs(qs,{className:"max-w-[95vw] sm:max-w-[900px] max-h-[90vh]",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"正则表达式编辑器"}),e.jsx(Ws,{className:"text-sm",children:"使用可视化工具构建正则表达式,并实时测试效果"})]}),e.jsx(Ze,{className:"max-h-[calc(90vh-120px)]",children:e.jsxs(Sa,{value:D,onValueChange:E=>V(E),className:"w-full",children:[e.jsxs(xa,{className:"grid w-full grid-cols-2",children:[e.jsx(is,{value:"build",children:"🔧 构建器"}),e.jsx(is,{value:"test",children:"🧪 测试器"})]}),e.jsxs(As,{value:"build",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{className:"text-sm font-medium",children:"正则表达式"}),e.jsx(ie,{ref:A,value:l,onChange:E=>r(E.target.value),className:"font-mono text-sm",placeholder:"点击下方按钮构建正则表达式..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{className:"text-sm font-medium",children:"Reaction 内容"}),e.jsx(Ys,{value:i,onChange:E=>o(E.target.value),placeholder:"使用 [捕获组名] 引用捕获的内容...",rows:3,className:"text-sm"})]}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[$.map(E=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-xs font-semibold text-primary",children:E.category}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:E.items.map(se=>e.jsx(C,{variant:"outline",size:"sm",className:"justify-start h-auto py-2 px-3",onClick:()=>_(se.pattern,se.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:se.label}),e.jsx("code",{className:"ml-auto text-xs bg-muted px-1.5 py-0.5 rounded font-mono",children:se.pattern})]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-0.5",children:se.desc})]})},se.label))})]},E.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(C,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>r("^(?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(C,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>r("(?:[^,。.\\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(C,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>r("(?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(As,{value:"test",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{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(k,{htmlFor:"test-text",className:"text-sm font-medium",children:"测试文本"}),e.jsx(Ys,{id:"test-text",value:h,onChange:E=>f(E.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:g&&g.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:["匹配成功 (",g.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(k,{className:"text-sm font-medium",children:"匹配高亮"}),e.jsx(Ze,{className:"h-40 rounded-md bg-muted p-3",children:e.jsx("div",{className:"text-sm break-words",children:T()})})]}),Object.keys(b).length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{className:"text-sm font-medium",children:"命名捕获组"}),e.jsx(Ze,{className:"h-32 rounded-md border p-3",children:e.jsx("div",{className:"space-y-2",children:Object.entries(b).map(([E,se])=>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:["[",E,"]"]}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("span",{className:"font-mono bg-muted px-2 py-0.5 rounded",children:se})]},E))})})]}),Object.keys(b).length>0&&i&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{className:"text-sm font-medium",children:"Reaction 替换预览"}),e.jsx(Ze,{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:w})}),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 l1=Ct.memo(function({keywordReactionConfig:i,responsePostProcessConfig:r,chineseTypoConfig:o,responseSplitterConfig:u,onKeywordReactionChange:x,onResponsePostProcessChange:h,onChineseTypoChange:f,onResponseSplitterChange:g}){const j=()=>{x({...i,regex_rules:[...i.regex_rules,{regex:[""],reaction:""}]})},v=_=>{x({...i,regex_rules:i.regex_rules.filter((T,$)=>$!==_)})},y=(_,T,$)=>{const E=[...i.regex_rules];T==="regex"&&typeof $=="string"?E[_]={...E[_],regex:[$]}:T==="reaction"&&typeof $=="string"&&(E[_]={...E[_],reaction:$}),x({...i,regex_rules:E})},b=()=>{x({...i,keyword_rules:[...i.keyword_rules,{keywords:[],reaction:""}]})},S=_=>{x({...i,keyword_rules:i.keyword_rules.filter((T,$)=>$!==_)})},w=(_,T,$)=>{const E=[...i.keyword_rules];typeof $=="string"&&(E[_]={...E[_],reaction:$}),x({...i,keyword_rules:E})},O=_=>{const T=[...i.keyword_rules];T[_]={...T[_],keywords:[...T[_].keywords||[],""]},x({...i,keyword_rules:T})},A=(_,T)=>{const $=[...i.keyword_rules];$[_]={...$[_],keywords:($[_].keywords||[]).filter((E,se)=>se!==T)},x({...i,keyword_rules:$})},D=(_,T,$)=>{const E=[...i.keyword_rules],se=[...E[_].keywords||[]];se[T]=$,E[_]={...E[_],keywords:se},x({...i,keyword_rules:E})},V=({rule:_})=>{const T=`{ regex = [${(_.regex||[]).map($=>`"${$}"`).join(", ")}], reaction = "${_.reaction}" }`;return e.jsxs(Ia,{children:[e.jsx(Qa,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",children:[e.jsx(Gt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(La,{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(Ze,{className:"h-60 rounded-md bg-muted p-3",children:e.jsx("pre",{className:"font-mono text-xs break-all",children:T})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},z=({rule:_})=>{const T=`[[keyword_reaction.keyword_rules]] keywords = [${(_.keywords||[]).map($=>`"${$}"`).join(", ")}] reaction = "${_.reaction}"`;return e.jsxs(Ia,{children:[e.jsx(Qa,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",children:[e.jsx(Gt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(La,{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(Ze,{className:"h-60 rounded-md bg-muted p-3",children:e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all",children:T})}),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(C,{onClick:j,size:"sm",variant:"outline",children:[e.jsx(ut,{className:"h-4 w-4 mr-1"}),"添加正则规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[i.regex_rules.map((_,T)=>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:["正则规则 ",T+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a1,{regex:_.regex&&_.regex[0]||"",reaction:_.reaction,onRegexChange:$=>y(T,"regex",$),onReactionChange:$=>y(T,"reaction",$)}),e.jsx(V,{rule:_}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{size:"sm",variant:"ghost",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:["确定要删除正则规则 ",T+1," 吗?此操作无法撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>v(T),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{className:"text-xs font-medium",children:"正则表达式(Python 语法)"}),e.jsx(ie,{value:_.regex&&_.regex[0]||"",onChange:$=>y(T,"regex",$.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(k,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(Ys,{value:_.reaction,onChange:$=>y(T,"reaction",$.target.value),placeholder:`触发后麦麦的反应... 可以使用 [捕获组名] 来引用正则表达式中的内容`,rows:3,className:"text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"使用 [捕获组名] 引用正则表达式中的命名捕获组,例如 [n] 会被替换为捕获的内容"})]})]})]},T)),i.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(C,{onClick:b,size:"sm",variant:"outline",children:[e.jsx(ut,{className:"h-4 w-4 mr-1"}),"添加关键词规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[i.keyword_rules.map((_,T)=>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:["关键词规则 ",T+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{rule:_}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{size:"sm",variant:"ghost",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:["确定要删除关键词规则 ",T+1," 吗?此操作无法撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>S(T),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(k,{className:"text-xs font-medium",children:"关键词列表"}),e.jsxs(C,{onClick:()=>O(T),size:"sm",variant:"ghost",children:[e.jsx(ut,{className:"h-3 w-3 mr-1"}),"添加关键词"]})]}),e.jsxs("div",{className:"space-y-2",children:[(_.keywords||[]).map(($,E)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{value:$,onChange:se=>D(T,E,se.target.value),placeholder:"关键词",className:"flex-1"}),e.jsx(C,{onClick:()=>A(T,E),size:"sm",variant:"ghost",children:e.jsx(es,{className:"h-4 w-4"})})]},E)),(!_.keywords||_.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(k,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(Ys,{value:_.reaction,onChange:$=>w(T,"reaction",$.target.value),placeholder:"触发后麦麦的反应...",rows:3,className:"text-sm"})]})]})]},T)),i.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(Fe,{id:"enable_response_post_process",checked:r.enable_response_post_process,onCheckedChange:_=>h({...r,enable_response_post_process:_})}),e.jsx(k,{htmlFor:"enable_response_post_process",className:"cursor-pointer",children:"启用回复后处理"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"包括错别字生成器和回复分割器"})]}),r.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(Fe,{id:"enable_chinese_typo",checked:o.enable,onCheckedChange:_=>f({...o,enable:_})}),e.jsx(k,{htmlFor:"enable_chinese_typo",className:"cursor-pointer font-semibold",children:"中文错别字生成器"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"为回复添加随机错别字,让麦麦的回复更自然"}),o.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(k,{htmlFor:"error_rate",className:"text-xs font-medium",children:"单字替换概率"}),e.jsx(ie,{id:"error_rate",type:"number",step:"0.001",min:"0",max:"1",value:o.error_rate,onChange:_=>f({...o,error_rate:parseFloat(_.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"min_freq",className:"text-xs font-medium",children:"最小字频阈值"}),e.jsx(ie,{id:"min_freq",type:"number",min:"0",value:o.min_freq,onChange:_=>f({...o,min_freq:parseInt(_.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"tone_error_rate",className:"text-xs font-medium",children:"声调错误概率"}),e.jsx(ie,{id:"tone_error_rate",type:"number",step:"0.01",min:"0",max:"1",value:o.tone_error_rate,onChange:_=>f({...o,tone_error_rate:parseFloat(_.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"word_replace_rate",className:"text-xs font-medium",children:"整词替换概率"}),e.jsx(ie,{id:"word_replace_rate",type:"number",step:"0.001",min:"0",max:"1",value:o.word_replace_rate,onChange:_=>f({...o,word_replace_rate:parseFloat(_.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(Fe,{id:"enable_response_splitter",checked:u.enable,onCheckedChange:_=>g({...u,enable:_})}),e.jsx(k,{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(k,{htmlFor:"max_length",className:"text-xs font-medium",children:"最大长度"}),e.jsx(ie,{id:"max_length",type:"number",min:"1",value:u.max_length,onChange:_=>g({...u,max_length:parseInt(_.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"回复允许的最大字符数"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"max_sentence_num",className:"text-xs font-medium",children:"最大句子数"}),e.jsx(ie,{id:"max_sentence_num",type:"number",min:"1",value:u.max_sentence_num,onChange:_=>g({...u,max_sentence_num:parseInt(_.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(Fe,{id:"enable_kaomoji_protection",checked:u.enable_kaomoji_protection,onCheckedChange:_=>g({...u,enable_kaomoji_protection:_})}),e.jsx(k,{htmlFor:"enable_kaomoji_protection",className:"cursor-pointer",children:"启用颜文字保护"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Fe,{id:"enable_overflow_return_all",checked:u.enable_overflow_return_all,onCheckedChange:_=>g({...u,enable_overflow_return_all:_})}),e.jsx(k,{htmlFor:"enable_overflow_return_all",className:"cursor-pointer",children:"超出时一次性返回全部"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"当句子数量超出限制时,合并后一次性返回所有内容"})]})]})})]})]})]})}),Ql="/api/webui/config";async function kp(){const i=await(await we(`${Ql}/bot`)).json();if(!i.success)throw new Error("获取配置数据失败");return i.config}async function Gl(){const i=await(await we(`${Ql}/model`)).json();if(!i.success)throw new Error("获取模型配置数据失败");return i.config}async function Tp(l){const r=await(await we(`${Ql}/bot`,{method:"POST",body:JSON.stringify(l)})).json();if(!r.success)throw new Error(r.message||"保存配置失败")}async function n1(){const i=await(await we(`${Ql}/bot/raw`)).json();if(!i.success)throw new Error("获取配置源代码失败");return i.content}async function i1(l){const r=await(await we(`${Ql}/bot/raw`,{method:"POST",body:JSON.stringify({raw_content:l})})).json();if(!r.success)throw new Error(r.message||"保存配置失败")}async function Nr(l){const r=await(await we(`${Ql}/model`,{method:"POST",body:JSON.stringify(l)})).json();if(!r.success)throw new Error(r.message||"保存配置失败")}async function r1(l,i){const o=await(await we(`${Ql}/bot/section/${l}`,{method:"POST",body:JSON.stringify(i)})).json();if(!o.success)throw new Error(o.message||`保存配置节 ${l} 失败`)}async function am(l,i){const o=await(await we(`${Ql}/model/section/${l}`,{method:"POST",body:JSON.stringify(i)})).json();if(!o.success)throw new Error(o.message||`保存配置节 ${l} 失败`)}async function c1(l,i="openai",r="/models"){const o=new URLSearchParams({provider_name:l,parser:i,endpoint:r}),u=await we(`/api/webui/models/list?${o}`);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 o1(l){const i=new URLSearchParams({provider_name:l}),r=await we(`/api/webui/models/test-connection-by-name?${i}`,{method:"POST"});if(!r.ok){const o=await r.json().catch(()=>({}));throw new Error(o.detail||`测试连接失败 (${r.status})`)}return await r.json()}const d1=gi("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"}}),sa=m.forwardRef(({className:l,variant:i,...r},o)=>e.jsx("div",{ref:o,role:"alert",className:H(d1({variant:i}),l),...r}));sa.displayName="Alert";const u1=m.forwardRef(({className:l,...i},r)=>e.jsx("h5",{ref:r,className:H("mb-1 font-medium leading-none tracking-tight",l),...i}));u1.displayName="AlertTitle";const ta=m.forwardRef(({className:l,...i},r)=>e.jsx("div",{ref:r,className:H("text-sm [&_p]:leading-relaxed",l),...i}));ta.displayName="AlertDescription";const m1={name:"toml",startState:function(){return{inString:!1,stringType:"",lhs:!0,inArray:0}},token:function(l,i){let r;if(!i.inString&&(r=l.match(/^('''|"""|'|")/))&&(i.stringType=r[0],i.inString=!0),l.sol()&&!i.inString&&i.inArray===0&&(i.lhs=!0),i.inString){for(;i.inString;)if(l.match(i.stringType))i.inString=!1;else if(l.peek()==="\\")l.next(),l.next();else{if(l.eol())break;l.match(/^.[^\\\"\']*/)}return i.lhs?"property":"string"}else{if(i.inArray&&l.peek()==="]")return l.next(),i.inArray--,"bracket";if(i.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(i.lhs&&l.eatWhile(function(o){return o!="="&&o!=" "}))return"property";if(i.lhs&&l.peek()==="=")return l.next(),i.lhs=!1,null;if(!i.lhs&&l.match(/^\d\d\d\d[\d\-\:\.T]*Z/))return"atom";if(!i.lhs&&(l.match("true")||l.match("false")))return"atom";if(!i.lhs&&l.peek()==="[")return i.inArray++,l.next(),"bracket";if(!i.lhs&&l.match(/^\-?\d+(?:\.\d+)?/))return"number";l.eatSpace()||l.next()}return null},languageData:{commentTokens:{line:"#"}}},x1={python:[c0()],json:[o0(),d0()],toml:[r0.define(m1)],text:[]};function h1({value:l,onChange:i,language:r="text",readOnly:o=!1,height:u="400px",minHeight:x,maxHeight:h,placeholder:f,theme:g="dark",className:j=""}){const[v,y]=m.useState(!1);if(m.useEffect(()=>{y(!0)},[]),!v)return e.jsx("div",{className:`rounded-md border bg-muted animate-pulse ${j}`,style:{height:u,minHeight:x,maxHeight:h}});const b=[...x1[r]||[],gp.lineWrapping];return o&&b.push(gp.editable.of(!1)),e.jsx("div",{className:`rounded-md overflow-hidden border ${j}`,children:e.jsx(u0,{value:l,height:u,minHeight:x,maxHeight:h,theme:g==="dark"?m0:void 0,extensions:b,onChange:i,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 f1({id:l,index:i,itemType:r,itemFields:o,value:u,onChange:x,onRemove:h,disabled:f,canRemove:g,placeholder:j}){const{attributes:v,listeners:y,setNodeRef:b,transform:S,transition:w,isDragging:O}=Wg({id:l,disabled:f}),A={transform:ej.Transform.toString(S),transition:w};return e.jsxs("div",{ref:b,style:A,className:H("flex items-start gap-2 group",O&&"opacity-50 z-50"),children:[e.jsx("button",{type:"button",className:H("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,...y,children:e.jsx(Lg,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1 min-w-0",children:r==="object"&&o?e.jsx(p1,{value:u,onChange:x,fields:o,disabled:f}):r==="number"?e.jsx(ie,{type:"number",value:u??"",onChange:D=>x(parseFloat(D.target.value)||0),placeholder:j??`第 ${i+1} 项`,disabled:f,className:"font-mono"}):e.jsx(ie,{type:"text",value:u??"",onChange:D=>x(D.target.value),placeholder:j??`第 ${i+1} 项`,disabled:f})}),e.jsx(C,{type:"button",variant:"ghost",size:"icon",onClick:h,disabled:f||!g,className:H("flex-shrink-0 text-muted-foreground hover:text-destructive","opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity"),children:e.jsx(es,{className:"h-4 w-4"})})]})}function p1({value:l,onChange:i,fields:r,disabled:o}){const u=m.useCallback((h,f)=>{i({...l,[h]:f})},[l,i]),x=(h,f)=>{const g=l?.[h];if(f.type==="boolean"||f.type==="switch")return e.jsxs("div",{className:"flex items-center justify-between py-1",children:[e.jsx(k,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(Fe,{checked:!!(g??f.default),onCheckedChange:j=>u(h,j),disabled:o})]});if(f.type==="slider"||f.type==="number"&&f.min!=null&&f.max!=null){const j=g??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(k,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx("span",{className:"text-xs text-muted-foreground",children:j})]}),e.jsx(ma,{value:[j],onValueChange:v=>u(h,v[0]),min:f.min??0,max:f.max??100,step:f.step??1,disabled:o,className:"py-1"})]})}return f.type==="select"&&f.choices?e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsxs(Ue,{value:String(g??f.default??""),onValueChange:j=>u(h,j),disabled:o,children:[e.jsx(Re,{className:"h-8 text-sm",children:e.jsx(Be,{placeholder:f.placeholder??"请选择"})}),e.jsx(Le,{children:f.choices.map(j=>e.jsx(ee,{value:String(j),children:String(j)},String(j)))})]})]}):f.type==="number"?e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(ie,{type:"number",value:g??f.default??"",onChange:j=>u(h,parseFloat(j.target.value)||0),placeholder:f.placeholder,disabled:o,className:"h-8 text-sm"})]}):e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(ie,{type:"text",value:g??f.default??"",onChange:j=>u(h,j.target.value),placeholder:f.placeholder,disabled:o,className:"h-8 text-sm"})]})};return e.jsx(Ve,{className:"p-3 space-y-2 bg-muted/30",children:Object.entries(r).map(([h,f])=>e.jsx("div",{children:x(h,f)},h))})}function g1({value:l,onChange:i,itemType:r="string",itemFields:o,minItems:u,maxItems:x,disabled:h,placeholder:f}){const g=m.useMemo(()=>Array.isArray(l)?l:typeof l=="string"&&l.trim()?l.split(",").map(z=>z.trim()):[],[l]),[j]=m.useState(()=>new Map),v=m.useCallback(z=>(j.has(z)||j.set(z,`item-${Date.now()}-${z}-${Math.random().toString(36).slice(2)}`),j.get(z)),[j]),y=m.useMemo(()=>{const z=[];for(let _=0;_{const{active:_,over:T}=z;if(T&&_.id!==T.id){const $=y.indexOf(_.id),E=y.indexOf(T.id),se=Xg(g,$,E);i(se)}},[g,y,i]),w=m.useCallback(()=>{if(x!=null&&g.length>=x)return;let z;r==="object"&&o?z=Object.fromEntries(Object.entries(o).map(([_,T])=>[_,T.default??""])):r==="number"?z=0:z="",i([...g,z])},[g,x,r,o,i]),O=m.useCallback((z,_)=>{const T=[...g];T[z]=_,i(T)},[g,i]),A=m.useCallback(z=>{if(u!=null&&g.length<=u)return;const _=g.filter((T,$)=>$!==z);j.delete(z),i(_)},[g,u,j,i]),D=x==null||g.lengthu;return e.jsxs("div",{className:"space-y-2",children:[g.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(Ot,{className:"h-4 w-4"}),e.jsx("span",{children:"暂无数据,点击下方按钮添加"})]}):e.jsx(Pg,{sensors:b,collisionDetection:Jg,onDragEnd:S,children:e.jsx(Zg,{items:y,strategy:x0,children:e.jsx("div",{className:"space-y-2",children:g.map((z,_)=>e.jsx(f1,{id:y[_],index:_,itemType:r,itemFields:o,value:z,onChange:T=>O(_,T),onRemove:()=>A(_),disabled:h,canRemove:V,placeholder:f},y[_]))})})}),e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:w,disabled:h||!D,className:"w-full",children:[e.jsx(ut,{className:"h-4 w-4 mr-1"}),"添加项目",x!==void 0&&e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",g.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 j1(l,i,r,o={}){const{debounceMs:u=2e3,onSaveSuccess:x,onSaveError:h}=o,f=m.useRef(null),g=m.useCallback(async(b,S)=>{try{i(!0),await r1(b,S),r(!1),x?.()}catch(w){console.error(`自动保存 ${b} 失败:`,w),r(!0),h?.(w instanceof Error?w:new Error(String(w)))}finally{i(!1)}},[i,r,x,h]),j=m.useCallback((b,S)=>{l||(r(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{g(b,S)},u))},[l,r,g,u]),v=m.useCallback(async(b,S)=>{f.current&&(clearTimeout(f.current),f.current=null),await g(b,S)},[g]),y=m.useCallback(()=>{f.current&&(clearTimeout(f.current),f.current=null)},[]);return m.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]),{triggerAutoSave:j,saveNow:v,cancelPendingAutoSave:y}}function Ht(l,i,r,o){m.useEffect(()=>{l&&!r&&o(i,l)},[l])}const v1=500;function b1(){return e.jsx(jn,{children:e.jsx(N1,{})})}function N1(){const[l,i]=m.useState(!0),[r,o]=m.useState(!1),[u,x]=m.useState(!1),[h,f]=m.useState(!1),[g,j]=m.useState("visual"),[v,y]=m.useState(""),[b,S]=m.useState(!1),{toast:w}=Ks(),{triggerRestart:O,isRestarting:A}=Il(),[D,V]=m.useState(null),[z,_]=m.useState(null),[T,$]=m.useState(null),[E,se]=m.useState(null),[te,ne]=m.useState(null),[ue,Se]=m.useState(null),[oe,je]=m.useState(null),[be,U]=m.useState(null),[P,X]=m.useState(null),[L,B]=m.useState(null),[_e,Ne]=m.useState(null),[Ce,ve]=m.useState(null),[ze,Q]=m.useState(null),[xe,Te]=m.useState(null),[J,le]=m.useState(null),[qe,We]=m.useState(null),[fe,ls]=m.useState(null),G=m.useRef(!0),Me=m.useRef({}),re=m.useCallback(ye=>{Me.current=ye,V(ye.bot),_(ye.personality);const ps=ye.chat;ps.talk_value_rules||(ps.talk_value_rules=[]),$(ps),se(ye.expression),ne(ye.emoji),Se(ye.memory),je(ye.tool),U(ye.voice),X(ye.lpmm_knowledge),B(ye.keyword_reaction),Ne(ye.response_post_process),ve(ye.chinese_typo),Q(ye.response_splitter),Te(ye.log),le(ye.debug),We(ye.maim_message),ls(ye.telemetry)},[]),pe=m.useCallback(()=>({...Me.current,bot:D,personality:z,chat:T,expression:E,emoji:te,memory:ue,tool:oe,voice:be,lpmm_knowledge:P,keyword_reaction:L,response_post_process:_e,chinese_typo:Ce,response_splitter:ze,log:xe,debug:J,maim_message:qe,telemetry:fe}),[D,z,T,E,te,ue,oe,be,P,L,_e,Ce,ze,xe,J,qe,fe]),Ee=m.useCallback(async()=>{try{const ps=(await n1()).replace(/"([^"]*)"/g,(ss,Es)=>`"${Es.replace(/\\n/g,` `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}"`);y(ps),S(!1)}catch(ye){w({variant:"destructive",title:"加载失败",description:ye instanceof Error?ye.message:"加载源代码失败"})}},[w]),Ie=m.useCallback(async()=>{try{i(!0);const ye=await kp();re(ye),f(!1),G.current=!1,await Ee()}catch(ye){console.error("加载配置失败:",ye),w({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}finally{i(!1)}},[w,Ee,re]);m.useEffect(()=>{Ie()},[Ie]);const{triggerAutoSave:$e,cancelPendingAutoSave:Vt}=j1(G.current,x,f);Ht(D,"bot",G.current,$e),Ht(z,"personality",G.current,$e),Ht(T,"chat",G.current,$e),Ht(E,"expression",G.current,$e),Ht(te,"emoji",G.current,$e),Ht(ue,"memory",G.current,$e),Ht(oe,"tool",G.current,$e),Ht(be,"voice",G.current,$e),Ht(P,"lpmm_knowledge",G.current,$e),Ht(L,"keyword_reaction",G.current,$e),Ht(_e,"response_post_process",G.current,$e),Ht(Ce,"chinese_typo",G.current,$e),Ht(ze,"response_splitter",G.current,$e),Ht(xe,"log",G.current,$e),Ht(J,"debug",G.current,$e),Ht(qe,"maim_message",G.current,$e),Ht(fe,"telemetry",G.current,$e);const _t=async()=>{try{o(!0);const ye=v.replace(/"([^"]*)"/g,(ps,ss)=>`"${ss.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")}"`);await i1(ye),f(!1),S(!1),w({title:"保存成功",description:"配置已保存"}),await Ie()}catch(ye){S(!0),w({variant:"destructive",title:"保存失败",description:ye instanceof Error?ye.message:"保存配置失败"})}finally{o(!1)}},nt=async ye=>{if(h){w({variant:"destructive",title:"切换失败",description:"请先保存当前更改"});return}if(j(ye),ye==="source")await Ee();else try{const ps=await kp();re(ps),f(!1)}catch(ps){console.error("加载配置失败:",ps),w({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}},F=async()=>{try{o(!0),Vt(),await Tp(pe()),f(!1),w({title:"保存成功",description:"麦麦主程序配置已保存"})}catch(ye){console.error("保存配置失败:",ye),w({title:"保存失败",description:ye.message,variant:"destructive"})}finally{o(!1)}},He=async()=>{await O()},De=async()=>{try{o(!0),Vt(),await Tp(pe()),f(!1),w({title:"保存成功",description:"配置已保存,即将重启麦麦..."}),await new Promise(ye=>setTimeout(ye,v1)),await He()}catch(ye){console.error("保存失败:",ye),w({title:"保存失败",description:ye.message,variant:"destructive"})}finally{o(!1)}};return l?e.jsx(Ze,{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(Ze,{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(C,{onClick:g==="visual"?F:_t,disabled:r||u||!h||A,size:"sm",variant:"outline",className:"w-20 sm:w-24",children:[e.jsx(Ar,{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:r?"保存中":u?"自动":h?"保存":"已保存"})]}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsxs(C,{disabled:r||u||A,size:"sm",className:"w-20 sm:w-28",children:[e.jsx(Mr,{className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"ml-1 truncate text-xs sm:text-sm",children:A?"重启中":h?"保存重启":"重启"})]})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认重启麦麦?"}),e.jsx(xs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:h?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:h?De:He,children:h?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsx("div",{className:"flex",children:e.jsx(Sa,{value:g,onValueChange:ye=>nt(ye),className:"w-full",children:e.jsxs(xa,{className:"h-8 sm:h-9 w-full grid grid-cols-2",children:[e.jsxs(is,{value:"visual",className:"text-xs sm:text-sm",children:[e.jsx($y,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"可视化编辑"]}),e.jsxs(is,{value:"source",className:"text-xs sm:text-sm",children:[e.jsx(qy,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"源代码编辑"]})]})})})]}),e.jsxs(sa,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(ta,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),g==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(sa,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(ta,{children:[e.jsx("strong",{children:"源代码模式(高级功能):"}),"直接编辑 TOML 配置文件。此功能仅适用于熟悉 TOML 语法的高级用户。保存时会在后端验证格式,只有格式完全正确才能保存。",b&&e.jsx("span",{className:"text-destructive font-semibold ml-2",children:"⚠️ 上次保存失败,请检查 TOML 格式"})]})]}),e.jsx(h1,{value:v,onChange:ye=>{y(ye),f(!0),b&&S(!1)},language:"toml",theme:"dark",height:"calc(100vh - 280px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),g==="visual"&&e.jsx(e.Fragment,{children:e.jsxs(Sa,{defaultValue:"bot",className:"w-full",children:[e.jsxs(xa,{className:"flex flex-wrap h-auto gap-1 p-1 sm:grid sm:grid-cols-5 lg:grid-cols-9",children:[e.jsx(is,{value:"bot",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"基本信息"}),e.jsx(is,{value:"personality",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"人格"}),e.jsx(is,{value:"chat",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"聊天"}),e.jsx(is,{value:"expression",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"表达"}),e.jsx(is,{value:"features",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"功能"}),e.jsx(is,{value:"processing",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"处理"}),e.jsx(is,{value:"voice",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"语音"}),e.jsx(is,{value:"lpmm",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"知识库"}),e.jsx(is,{value:"other",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"其他"})]}),e.jsx(As,{value:"bot",className:"space-y-4",children:D&&e.jsx(qw,{config:D,onChange:V})}),e.jsx(As,{value:"personality",className:"space-y-4",children:z&&e.jsx(Gw,{config:z,onChange:_})}),e.jsx(As,{value:"chat",className:"space-y-4",children:T&&e.jsx(Yw,{config:T,onChange:$})}),e.jsx(As,{value:"expression",className:"space-y-4",children:E&&e.jsx(t1,{config:E,onChange:se})}),e.jsx(As,{value:"features",className:"space-y-4",children:te&&ue&&oe&&e.jsx(e1,{emojiConfig:te,memoryConfig:ue,toolConfig:oe,onEmojiChange:ne,onMemoryChange:Se,onToolChange:je})}),e.jsx(As,{value:"processing",className:"space-y-4",children:L&&_e&&Ce&&ze&&e.jsx(l1,{keywordReactionConfig:L,responsePostProcessConfig:_e,chineseTypoConfig:Ce,responseSplitterConfig:ze,onKeywordReactionChange:B,onResponsePostProcessChange:Ne,onChineseTypoChange:ve,onResponseSplitterChange:Q})}),e.jsx(As,{value:"voice",className:"space-y-4",children:be&&e.jsx(Kw,{config:be,onChange:U})}),e.jsx(As,{value:"lpmm",className:"space-y-4",children:P&&e.jsx(Xw,{config:P,onChange:X})}),e.jsxs(As,{value:"other",className:"space-y-4",children:[xe&&e.jsx(Pw,{config:xe,onChange:Te}),J&&e.jsx(Jw,{config:J,onChange:le}),qe&&e.jsx(Zw,{config:qe,onChange:We}),fe&&e.jsx(Ww,{config:fe,onChange:ls})]})]})}),e.jsx(vn,{})]})})}const bn=m.forwardRef(({className:l,...i},r)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:r,className:H("w-full caption-bottom text-sm",l),...i})}));bn.displayName="Table";const Nn=m.forwardRef(({className:l,...i},r)=>e.jsx("thead",{ref:r,className:H("[&_tr]:border-b",l),...i}));Nn.displayName="TableHeader";const yn=m.forwardRef(({className:l,...i},r)=>e.jsx("tbody",{ref:r,className:H("[&_tr:last-child]:border-0",l),...i}));yn.displayName="TableBody";const y1=m.forwardRef(({className:l,...i},r)=>e.jsx("tfoot",{ref:r,className:H("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",l),...i}));y1.displayName="TableFooter";const gt=m.forwardRef(({className:l,...i},r)=>e.jsx("tr",{ref:r,className:H("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",l),...i}));gt.displayName="TableRow";const Je=m.forwardRef(({className:l,...i},r)=>e.jsx("th",{ref:r,className:H("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",l),...i}));Je.displayName="TableHead";const Qe=m.forwardRef(({className:l,...i},r)=>e.jsx("td",{ref:r,className:H("px-4 py-3 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",l),...i}));Qe.displayName="TableCell";const w1=m.forwardRef(({className:l,...i},r)=>e.jsx("caption",{ref:r,className:H("mt-4 text-sm text-muted-foreground",l),...i}));w1.displayName="TableCaption";const vo=m.forwardRef(({className:l,...i},r)=>e.jsx(la,{ref:r,className:H("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",l),...i}));vo.displayName=la.displayName;const bo=m.forwardRef(({className:l,...i},r)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx($t,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(la.Input,{ref:r,className:H("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),...i})]}));bo.displayName=la.Input.displayName;const No=m.forwardRef(({className:l,...i},r)=>e.jsx(la.List,{ref:r,className:H("max-h-[300px] overflow-y-auto overflow-x-hidden",l),...i}));No.displayName=la.List.displayName;const yo=m.forwardRef((l,i)=>e.jsx(la.Empty,{ref:i,className:"py-6 text-center text-sm",...l}));yo.displayName=la.Empty.displayName;const Cr=m.forwardRef(({className:l,...i},r)=>e.jsx(la.Group,{ref:r,className:H("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),...i}));Cr.displayName=la.Group.displayName;const _1=m.forwardRef(({className:l,...i},r)=>e.jsx(la.Separator,{ref:r,className:H("-mx-1 h-px bg-border",l),...i}));_1.displayName=la.Separator.displayName;const kr=m.forwardRef(({className:l,...i},r)=>e.jsx(la.Item,{ref:r,className:H("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),...i}));kr.displayName=la.Item.displayName;const jt=m.forwardRef(({className:l,...i},r)=>e.jsx(yg,{ref:r,className:H("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),...i,children:e.jsx(gy,{className:H("grid place-content-center text-current"),children:e.jsx(ea,{className:"h-4 w-4"})})}));jt.displayName=yg.displayName;const jj=m.createContext(null),vj="maibot-completed-tours";function S1(){try{const l=localStorage.getItem(vj);return l?new Set(JSON.parse(l)):new Set}catch{return new Set}}function Ep(l){localStorage.setItem(vj,JSON.stringify([...l]))}function C1({children:l}){const[i,r]=m.useState({activeTourId:null,stepIndex:0,isRunning:!1}),o=m.useRef(new Map),[,u]=m.useState(0),[x,h]=m.useState(S1),f=m.useCallback((z,_)=>{o.current.set(z,_),u(T=>T+1)},[]),g=m.useCallback(z=>{o.current.delete(z),r(_=>_.activeTourId===z?{..._,activeTourId:null,isRunning:!1,stepIndex:0}:_)},[]),j=m.useCallback((z,_=0)=>{o.current.has(z)&&r({activeTourId:z,stepIndex:_,isRunning:!0})},[]),v=m.useCallback(()=>{r(z=>({...z,isRunning:!1}))},[]),y=m.useCallback(z=>{r(_=>({..._,stepIndex:z}))},[]),b=m.useCallback(()=>{r(z=>({...z,stepIndex:z.stepIndex+1}))},[]),S=m.useCallback(()=>{r(z=>({...z,stepIndex:Math.max(0,z.stepIndex-1)}))},[]),w=m.useCallback(()=>i.activeTourId?o.current.get(i.activeTourId)||[]:[],[i.activeTourId]),O=m.useCallback(z=>{h(_=>{const T=new Set(_);return T.add(z),Ep(T),T})},[]),A=m.useCallback(z=>{const{action:_,index:T,status:$,type:E}=z,se=["finished","skipped"];if(_==="close"){r(te=>({...te,isRunning:!1,stepIndex:0}));return}se.includes($)?r(te=>($==="finished"&&te.activeTourId&&setTimeout(()=>O(te.activeTourId),0),{...te,isRunning:!1,stepIndex:0})):E==="step:after"&&(_==="next"?r(te=>({...te,stepIndex:T+1})):_==="prev"&&r(te=>({...te,stepIndex:T-1})))},[O]),D=m.useCallback(z=>x.has(z),[x]),V=m.useCallback(z=>{h(_=>{const T=new Set(_);return T.delete(z),Ep(T),T})},[]);return e.jsx(jj.Provider,{value:{state:i,tours:o.current,registerTour:f,unregisterTour:g,startTour:j,stopTour:v,goToStep:y,nextStep:b,prevStep:S,getCurrentSteps:w,handleJoyrideCallback:A,isTourCompleted:D,markTourCompleted:O,resetTourCompleted:V},children:l})}function xm(){const l=m.useContext(jj);if(!l)throw new Error("useTour must be used within a TourProvider");return l}const k1={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)"}},T1={back:"上一步",close:"关闭",last:"完成",next:"下一步",nextLabelWithProgress:"下一步 ({step}/{steps})",open:"打开对话框",skip:"跳过"};function E1(){const{state:l,getCurrentSteps:i,handleJoyrideCallback:r}=xm(),o=i(),[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||o.length===0){x(!1);return}const v=o[l.stepIndex];if(!v){x(!1);return}const y=v.target;if(y==="body"){x(!0);return}x(!1);const b=setTimeout(()=>{const S=()=>{const D=document.querySelector(y);if(D){const V=D.getBoundingClientRect();if(V.width>0&&V.height>0)return!0}return!1};if(S()){setTimeout(()=>x(!0),100);return}const w=setInterval(()=>{S()&&(clearInterval(w),setTimeout(()=>x(!0),100))},100),O=setTimeout(()=>{clearInterval(w),x(!0)},5e3),A=()=>{clearInterval(w),clearTimeout(O)};f.current=A},150);return()=>{clearTimeout(b),f.current&&(f.current(),f.current=null)}},[l.isRunning,l.stepIndex,o]);const g=m.useRef(null);if(m.useEffect(()=>{let v=document.getElementById("tour-portal-container");return v||(v=document.createElement("div"),v.id="tour-portal-container",v.style.cssText="position: fixed; top: 0; left: 0; z-index: 99999; pointer-events: none;",document.body.appendChild(v)),g.current=v,()=>{}},[]),!l.isRunning||o.length===0||!u)return null;const j=e.jsx(f0,{steps:o,stepIndex:l.stepIndex,run:l.isRunning,continuous:!0,showSkipButton:!0,showProgress:!0,disableOverlayClose:!0,disableScrolling:!1,disableScrollParentFix:!1,callback:r,styles:k1,locale:T1,scrollOffset:80,scrollToFirstStep:!0,floaterProps:{styles:{floater:{zIndex:99999}},disableAnimation:!0}},`tour-step-${l.stepIndex}`);return g.current?jN.createPortal(j,g.current):j}const Ga="model-assignment-tour",bj=[{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}],Nj={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"},pr=[{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 zp(l){return l?l.replace(/\/+$/,"").toLowerCase():""}function z1(l){if(!l)return null;const i=zp(l);return pr.find(r=>r.id!=="custom"&&zp(r.base_url)===i)||null}const Wc=l=>({...l,max_retry:l.max_retry??2,timeout:l.timeout??30,retry_interval:l.retry_interval??10}),M1=l=>{const i={};return l?(l.name?.trim()||(i.name="请输入提供商名称"),l.base_url?.trim()||(i.base_url="请输入基础 URL"),l.api_key?.trim()||(i.api_key="请输入 API Key"),{isValid:Object.keys(i).length===0,errors:i}):{isValid:!1,errors:{name:"提供商数据为空"}}};function A1(){return e.jsx(jn,{children:e.jsx(O1,{})})}function O1(){const[l,i]=m.useState([]),[r,o]=m.useState(!0),[u,x]=m.useState(!1),[h,f]=m.useState(!1),[g,j]=m.useState(!1),[v,y]=m.useState(!1),[b,S]=m.useState(null),[w,O]=m.useState(null),[A,D]=m.useState("custom"),[V,z]=m.useState(!1),[_,T]=m.useState(!1),[$,E]=m.useState(null),[se,te]=m.useState(!1),[ne,ue]=m.useState(""),[Se,oe]=m.useState(new Set),[je,be]=m.useState(!1),[U,P]=m.useState(1),[X,L]=m.useState(20),[B,_e]=m.useState(""),[Ne,Ce]=m.useState({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),[ve,ze]=m.useState({}),[Q,xe]=m.useState(new Set),[Te,J]=m.useState(new Map),{toast:le}=Ks(),qe=ka(),{state:We,goToStep:fe,registerTour:ls}=xm(),{triggerRestart:G,isRestarting:Me}=Il(),re=m.useRef(null),pe=m.useRef(!0);m.useEffect(()=>{ls(Ga,bj)},[ls]),m.useEffect(()=>{if(We.activeTourId===Ga&&We.isRunning){const I=Nj[We.stepIndex];I&&!window.location.pathname.endsWith(I.replace("/config/",""))&&qe({to:I})}},[We.stepIndex,We.activeTourId,We.isRunning,qe]);const Ee=m.useRef(We.stepIndex);m.useEffect(()=>{if(We.activeTourId===Ga&&We.isRunning){const I=Ee.current,ge=We.stepIndex;I>=3&&I<=9&&ge<3&&y(!1),I>=10&&ge>=3&&ge<=9&&(ze({}),D("custom"),S({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10}),O(null),te(!1),y(!0)),Ee.current=ge}},[We.stepIndex,We.activeTourId,We.isRunning]),m.useEffect(()=>{if(We.activeTourId!==Ga||!We.isRunning)return;const I=ge=>{const ke=ge.target,Us=We.stepIndex;Us===2&&ke.closest('[data-tour="add-provider-button"]')?setTimeout(()=>fe(3),300):Us===9&&ke.closest('[data-tour="provider-cancel-button"]')&&setTimeout(()=>fe(10),300)};return document.addEventListener("click",I,!0),()=>document.removeEventListener("click",I,!0)},[We,fe]),m.useEffect(()=>{Ie()},[]);const Ie=async()=>{try{o(!0);const I=await Gl();i(I.api_providers||[]),j(!1),pe.current=!1}catch(I){console.error("加载配置失败:",I)}finally{o(!1)}},$e=async()=>{await G()},Vt=async()=>{try{x(!0),re.current&&clearTimeout(re.current);const I=l.map(it=>({...it,max_retry:it.max_retry??2,timeout:it.timeout??30,retry_interval:it.retry_interval??10})),{shouldProceed:ge}=await _t(I,"restart");if(!ge){x(!1);return}const ke=await Gl(),Us=new Set(I.map(it=>it.name)),Ft=(ke.models||[]).filter(it=>Us.has(it.api_provider));ke.api_providers=I,ke.models=Ft,await Nr(ke),j(!1),le({title:"保存成功",description:"正在重启麦麦..."}),await $e()}catch(I){console.error("保存配置失败:",I),le({title:"保存失败",description:I.message,variant:"destructive"}),x(!1)}},_t=m.useCallback(async(I,ge="auto")=>{try{const ke=await Gl(),Us=new Set(l.map(ht=>ht.name)),Ua=new Set(I.map(ht=>ht.name)),Ft=Array.from(Us).filter(ht=>!Ua.has(ht));if(Ft.length===0)return{shouldProceed:!0,providers:I};const It=(ke.models||[]).filter(ht=>Ft.includes(ht.api_provider));return It.length===0?{shouldProceed:!0,providers:I}:(Ce({isOpen:!0,providersToDelete:Ft,affectedModels:It,pendingProviders:I,context:ge,oldProviders:[...l]}),{shouldProceed:!1,providers:I})}catch(ke){return console.error("检查删除影响失败:",ke),{shouldProceed:!0,providers:I}}},[l]),nt=async()=>{try{(Ne.context==="auto"?f:x)(!0),Ce(ht=>({...ht,isOpen:!1}));const ge=await Gl(),ke=Ne.pendingProviders.map(Wc),Us=new Set(ke.map(ht=>ht.name)),Ft=(ge.models||[]).filter(ht=>Us.has(ht.api_provider)),it=new Set(Ne.affectedModels.map(ht=>ht.name)),It=ge.model_task_config;It&&Object.keys(It).forEach(ht=>{const Kl=It[ht];Kl&&Array.isArray(Kl.model_list)&&(Kl.model_list=Kl.model_list.filter(Lr=>!it.has(Lr)))}),ge.api_providers=ke,ge.models=Ft,ge.model_task_config=It,await Nr(ge),i(Ne.pendingProviders),j(!1),le({title:"删除成功",description:`已删除 ${Ne.providersToDelete.length} 个提供商和 ${Ne.affectedModels.length} 个关联模型`}),Ce({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),oe(new Set),Ne.context==="restart"&&await $e()}catch(I){console.error("删除失败:",I),le({title:"删除失败",description:I.message,variant:"destructive"})}finally{Ne.context==="auto"?f(!1):x(!1)}},F=()=>{Ne.oldProviders.length>0&&i(Ne.oldProviders),Ce({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),j(!1)},He=m.useCallback(async I=>{if(pe.current)return;const{shouldProceed:ge}=await _t(I,"auto");if(!ge){j(!0);return}try{f(!0);const ke=I.map(Wc);await am("api_providers",ke),j(!1)}catch(ke){console.error("自动保存失败:",ke),le({title:"自动保存失败",description:ke.message,variant:"destructive"}),j(!0)}finally{f(!1)}},[l,_t]);m.useEffect(()=>{if(!pe.current)return j(!0),re.current&&clearTimeout(re.current),re.current=setTimeout(()=>{He(l)},2e3),()=>{re.current&&clearTimeout(re.current)}},[l,He]);const De=async()=>{try{x(!0),re.current&&clearTimeout(re.current);const I=l.map(Wc),{shouldProceed:ge}=await _t(I,"manual");if(!ge){x(!1);return}const ke=await Gl(),Us=new Set(I.map(it=>it.name)),Ua=ke.models||[],Ft=Ua.filter(it=>{const It=Us.has(it.api_provider);return It||console.warn(`模型 "${it.name}" 引用了已删除的提供商 "${it.api_provider}",将被移除`),It});if(Ua.length!==Ft.length){const it=Ua.length-Ft.length;le({title:"注意",description:`已自动移除 ${it} 个引用已删除提供商的模型`,variant:"default"})}console.log("发送的 providers 数据:",I),ke.api_providers=I,ke.models=Ft,console.log("完整配置数据:",ke),await Nr(ke),j(!1),le({title:"保存成功",description:"模型提供商配置已保存"})}catch(I){console.error("保存配置失败:",I),le({title:"保存失败",description:I.message,variant:"destructive"})}finally{x(!1)}},ye=(I,ge)=>{if(ze({}),I){const ke=pr.find(Us=>Us.base_url===I.base_url&&Us.client_type===I.client_type);D(ke?.id||"custom"),S(I)}else D("custom"),S({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10});O(ge),te(!1),y(!0)},ps=m.useCallback(I=>{D(I),z(!1);const ge=pr.find(ke=>ke.id===I);ge&&ge.id!=="custom"?S(ke=>({...ke,name:ge.name,base_url:ge.base_url,client_type:ge.client_type})):ge?.id==="custom"&&S(ke=>({...ke,name:"",base_url:"",client_type:"openai"}))},[]),ss=m.useMemo(()=>A!=="custom",[A]),Es=m.useCallback(async()=>{if(b?.api_key)try{await navigator.clipboard.writeText(b.api_key),le({title:"复制成功",description:"API Key 已复制到剪贴板"})}catch{le({title:"复制失败",description:"无法访问剪贴板",variant:"destructive"})}},[b?.api_key,le]),Ms=()=>{if(!b)return;const{isValid:I,errors:ge}=M1(b);if(!I){ze(ge);return}ze({});const ke=Wc(b);if(w!==null){const Us=[...l];Us[w]=ke,i(Us)}else i([...l,ke]);y(!1),S(null),O(null)},Ls=I=>{if(!I&&b){const ge={...b,max_retry:b.max_retry??2,timeout:b.timeout??30,retry_interval:b.retry_interval??10};S(ge)}y(I)},ts=I=>{E(I),T(!0)},Pe=async()=>{if($!==null){const I=l.filter((ke,Us)=>Us!==$),{shouldProceed:ge}=await _t(I,"manual");ge&&(i(I),le({title:"删除成功",description:"提供商已从列表中移除"}))}T(!1),E(null)},Xe=I=>{const ge=new Set(Se);ge.has(I)?ge.delete(I):ge.add(I),oe(ge)},Os=()=>{if(Se.size===Ss.length)oe(new Set);else{const I=Ss.map((ge,ke)=>l.findIndex(Us=>Us===Ss[ke]));oe(new Set(I))}},kt=()=>{if(Se.size===0){le({title:"提示",description:"请先选择要删除的提供商",variant:"default"});return}be(!0)},Xs=async()=>{const I=l.filter((ke,Us)=>!Se.has(Us)),{shouldProceed:ge}=await _t(I,"manual");ge&&(i(I),oe(new Set),le({title:"批量删除成功",description:`已删除 ${Se.size} 个提供商`})),be(!1)},Ss=m.useMemo(()=>{if(!ne)return l;const I=ne.toLowerCase();return l.filter(ge=>ge.name.toLowerCase().includes(I)||ge.base_url.toLowerCase().includes(I)||ge.client_type.toLowerCase().includes(I))},[l,ne]),{totalPages:xt,paginatedProviders:W}=m.useMemo(()=>{const I=Math.ceil(Ss.length/X),ge=Ss.slice((U-1)*X,U*X);return{totalPages:I,paginatedProviders:ge}},[Ss,U,X]),de=m.useCallback(()=>{const I=parseInt(B);I>=1&&I<=xt&&(P(I),_e(""))},[B,xt]),ys=async I=>{xe(ge=>new Set(ge).add(I));try{const ge=await o1(I);J(ke=>new Map(ke).set(I,ge)),ge.network_ok?ge.api_key_valid===!0?le({title:"连接正常",description:`${I} 网络连接正常,API Key 有效 (${ge.latency_ms}ms)`}):ge.api_key_valid===!1?le({title:"连接正常但 Key 无效",description:`${I} 网络连接正常,但 API Key 无效或已过期`,variant:"destructive"}):le({title:"网络连接正常",description:`${I} 可以访问 (${ge.latency_ms}ms)`}):le({title:"连接失败",description:ge.error||"无法连接到提供商",variant:"destructive"})}catch(ge){le({title:"测试失败",description:ge.message,variant:"destructive"})}finally{xe(ge=>{const ke=new Set(ge);return ke.delete(I),ke})}},Tt=async()=>{for(const I of l)await ys(I.name)},Et=I=>{const ge=Q.has(I),ke=Te.get(I);return ge?e.jsxs(Ye,{variant:"secondary",className:"gap-1",children:[e.jsx(tt,{className:"h-3 w-3 animate-spin"}),"测试中"]}):ke?ke.network_ok?ke.api_key_valid===!0?e.jsxs(Ye,{className:"gap-1 bg-green-600 hover:bg-green-700",children:[e.jsx(aa,{className:"h-3 w-3"}),"正常"]}):ke.api_key_valid===!1?e.jsxs(Ye,{variant:"destructive",className:"gap-1",children:[e.jsx(Ot,{className:"h-3 w-3"}),"Key无效"]}):e.jsxs(Ye,{className:"gap-1 bg-blue-600 hover:bg-blue-700",children:[e.jsx(aa,{className:"h-3 w-3"}),"可访问"]}):e.jsxs(Ye,{variant:"destructive",className:"gap-1",children:[e.jsx(Mg,{className:"h-3 w-3"}),"离线"]}):null};return r?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:[Se.size>0&&e.jsxs(C,{onClick:kt,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(es,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",Se.size,")"]}),e.jsxs(C,{onClick:Tt,size:"sm",variant:"outline",className:"w-full sm:w-auto",disabled:l.length===0||Q.size>0,children:[e.jsx(hn,{className:"mr-2 h-4 w-4"}),Q.size>0?`测试中 (${Q.size})`:"测试全部"]}),e.jsxs(C,{onClick:()=>ye(null,null),size:"sm",className:"w-full sm:w-auto","data-tour":"add-provider-button",children:[e.jsx(ut,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"添加提供商"]}),e.jsxs(C,{onClick:De,disabled:u||h||!g||Me,size:"sm",variant:"outline",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(Ar,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),u?"保存中...":h?"自动保存中...":g?"保存配置":"已保存"]}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsxs(C,{disabled:u||h||Me,size:"sm",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(Mr,{className:"mr-2 h-4 w-4"}),Me?"重启中...":g?"保存并重启":"重启麦麦"]})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认重启麦麦?"}),e.jsx(xs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:g?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:g?Vt:$e,children:g?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(sa,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(ta,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),e.jsxs(Ze,{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($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"搜索提供商名称、URL 或类型...",value:ne,onChange:I=>ue(I.target.value),className:"pl-9"})]}),ne&&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:ne?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'}):W.map((I,ge)=>{const ke=l.findIndex(Us=>Us===I);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:I.name}),Et(I.name)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 break-all",children:I.base_url})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>ys(I.name),disabled:Q.has(I.name),title:"测试连接",children:Q.has(I.name)?e.jsx(tt,{className:"h-4 w-4 animate-spin"}):e.jsx(hn,{className:"h-4 w-4"})}),e.jsx(C,{variant:"default",size:"sm",onClick:()=>ye(I,ke),children:e.jsx(fn,{className:"h-4 w-4",strokeWidth:2,fill:"none"})}),e.jsx(C,{size:"sm",onClick:()=>ts(ke),className:"bg-red-600 hover:bg-red-700 text-white",children:e.jsx(es,{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:I.client_type})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"最大重试"}),e.jsx("p",{className:"font-medium",children:I.max_retry})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"超时(秒)"}),e.jsx("p",{className:"font-medium",children:I.timeout})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"重试间隔(秒)"}),e.jsx("p",{className:"font-medium",children:I.retry_interval})]})]})]},ge)})}),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(bn,{children:[e.jsx(Nn,{children:e.jsxs(gt,{children:[e.jsx(Je,{className:"w-12",children:e.jsx(jt,{checked:Se.size===Ss.length&&Ss.length>0,onCheckedChange:Os})}),e.jsx(Je,{children:"状态"}),e.jsx(Je,{children:"名称"}),e.jsx(Je,{children:"基础URL"}),e.jsx(Je,{children:"客户端类型"}),e.jsx(Je,{className:"text-right",children:"最大重试"}),e.jsx(Je,{className:"text-right",children:"超时(秒)"}),e.jsx(Je,{className:"text-right",children:"重试间隔(秒)"}),e.jsx(Je,{className:"text-right",children:"操作"})]})}),e.jsx(yn,{children:W.length===0?e.jsx(gt,{children:e.jsx(Qe,{colSpan:9,className:"text-center text-muted-foreground py-8",children:ne?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'})}):W.map((I,ge)=>{const ke=l.findIndex(Us=>Us===I);return e.jsxs(gt,{children:[e.jsx(Qe,{children:e.jsx(jt,{checked:Se.has(ke),onCheckedChange:()=>Xe(ke)})}),e.jsx(Qe,{children:Et(I.name)||e.jsx(Ye,{variant:"outline",className:"text-muted-foreground",children:"未测试"})}),e.jsx(Qe,{className:"font-medium",children:I.name}),e.jsx(Qe,{className:"max-w-xs truncate",title:I.base_url,children:I.base_url}),e.jsx(Qe,{children:I.client_type}),e.jsx(Qe,{className:"text-right",children:I.max_retry}),e.jsx(Qe,{className:"text-right",children:I.timeout}),e.jsx(Qe,{className:"text-right",children:I.retry_interval}),e.jsx(Qe,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>ys(I.name),disabled:Q.has(I.name),title:"测试连接",children:Q.has(I.name)?e.jsx(tt,{className:"h-4 w-4 animate-spin"}):e.jsx(hn,{className:"h-4 w-4"})}),e.jsxs(C,{variant:"default",size:"sm",onClick:()=>ye(I,ke),children:[e.jsx(fn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(C,{size:"sm",onClick:()=>ts(ke),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(es,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},ge)})})]})})}),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(k,{htmlFor:"page-size-provider",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ue,{value:X.toString(),onValueChange:I=>{L(parseInt(I)),P(1),oe(new Set)},children:[e.jsx(Re,{id:"page-size-provider",className:"w-20",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"10",children:"10"}),e.jsx(ee,{value:"20",children:"20"}),e.jsx(ee,{value:"50",children:"50"}),e.jsx(ee,{value:"100",children:"100"})]})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(U-1)*X+1," 到"," ",Math.min(U*X,Ss.length)," 条,共 ",Ss.length," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>P(1),disabled:U===1,className:"hidden sm:flex",children:e.jsx(vi,{className:"h-4 w-4"})}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>P(I=>Math.max(1,I-1)),disabled:U===1,children:[e.jsx(pl,{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(ie,{type:"number",value:B,onChange:I=>_e(I.target.value),onKeyDown:I=>I.key==="Enter"&&de(),placeholder:U.toString(),className:"w-16 h-8 text-center",min:1,max:xt}),e.jsx(C,{variant:"outline",size:"sm",onClick:de,disabled:!B,className:"h-8",children:"跳转"})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>P(I=>I+1),disabled:U>=xt,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ya,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>P(xt),disabled:U>=xt,className:"hidden sm:flex",children:e.jsx(bi,{className:"h-4 w-4"})})]})]})]}),e.jsx(Qs,{open:v,onOpenChange:Ls,children:e.jsxs(qs,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"provider-dialog",preventOutsideClose:We.isRunning,children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:w!==null?"编辑提供商":"添加提供商"}),e.jsx(Ws,{children:"配置 API 提供商的连接信息和参数"})]}),e.jsxs("form",{onSubmit:I=>{I.preventDefault(),Ms()},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(k,{htmlFor:"template",children:"提供商模板"}),e.jsxs(Ia,{open:V,onOpenChange:z,children:[e.jsx(Qa,{asChild:!0,children:e.jsxs(C,{variant:"outline",role:"combobox","aria-expanded":V,className:"w-full justify-between",children:[A?pr.find(I=>I.id===A)?.display_name:"选择提供商模板...",e.jsx(cm,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(La,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(vo,{children:[e.jsx(bo,{placeholder:"搜索提供商模板..."}),e.jsx(Ze,{className:"h-[300px]",children:e.jsxs(No,{className:"max-h-none overflow-visible",children:[e.jsx(yo,{children:"未找到匹配的模板"}),e.jsx(Cr,{children:pr.map(I=>e.jsxs(kr,{value:I.display_name,onSelect:()=>ps(I.id),children:[e.jsx(ea,{className:`mr-2 h-4 w-4 ${A===I.id?"opacity-100":"opacity-0"}`}),I.display_name]},I.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(k,{htmlFor:"name",className:ve.name?"text-destructive":"",children:"名称 *"}),e.jsx(ie,{id:"name",value:b?.name||"",onChange:I=>{S(ge=>ge?{...ge,name:I.target.value}:null),ve.name&&ze(ge=>({...ge,name:void 0}))},placeholder:"例如: DeepSeek, SiliconFlow",className:ve.name?"border-destructive focus-visible:ring-destructive":""}),ve.name&&e.jsx("p",{className:"text-xs text-destructive",children:ve.name})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"provider-url-input",children:[e.jsx(k,{htmlFor:"base_url",className:ve.base_url?"text-destructive":"",children:"基础 URL *"}),e.jsx(ie,{id:"base_url",value:b?.base_url||"",onChange:I=>{S(ge=>ge?{...ge,base_url:I.target.value}:null),ve.base_url&&ze(ge=>({...ge,base_url:void 0}))},placeholder:"https://api.example.com/v1",disabled:ss,className:`${ss?"bg-muted cursor-not-allowed":""} ${ve.base_url?"border-destructive focus-visible:ring-destructive":""}`}),ve.base_url&&e.jsx("p",{className:"text-xs text-destructive",children:ve.base_url}),ss&&!ve.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(k,{htmlFor:"api_key",className:ve.api_key?"text-destructive":"",children:"API Key *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{id:"api_key",type:se?"text":"password",value:b?.api_key||"",onChange:I=>{S(ge=>ge?{...ge,api_key:I.target.value}:null),ve.api_key&&ze(ge=>({...ge,api_key:void 0}))},placeholder:"sk-...",className:`flex-1 ${ve.api_key?"border-destructive focus-visible:ring-destructive":""}`}),e.jsx(C,{type:"button",variant:"outline",size:"icon",onClick:()=>te(!se),title:se?"隐藏密钥":"显示密钥",children:se?e.jsx(wr,{className:"h-4 w-4"}):e.jsx(Gt,{className:"h-4 w-4"})}),e.jsx(C,{type:"button",variant:"outline",size:"icon",onClick:Es,title:"复制密钥",children:e.jsx(co,{className:"h-4 w-4"})})]}),ve.api_key&&e.jsx("p",{className:"text-xs text-destructive",children:ve.api_key})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"client_type",children:"客户端类型"}),e.jsxs(Ue,{value:b?.client_type||"openai",onValueChange:I=>S(ge=>ge?{...ge,client_type:I}:null),disabled:ss,children:[e.jsx(Re,{id:"client_type",className:ss?"bg-muted cursor-not-allowed":"",children:e.jsx(Be,{placeholder:"选择客户端类型"})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"openai",children:"OpenAI"}),e.jsx(ee,{value:"gemini",children:"Gemini"})]})]}),ss&&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(k,{htmlFor:"max_retry",children:"最大重试"}),e.jsx(ie,{id:"max_retry",type:"number",min:"0",value:b?.max_retry??"",onChange:I=>{const ge=I.target.value===""?null:parseInt(I.target.value);S(ke=>ke?{...ke,max_retry:ge}:null)},placeholder:"默认: 2"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"timeout",children:"超时(秒)"}),e.jsx(ie,{id:"timeout",type:"number",min:"1",value:b?.timeout??"",onChange:I=>{const ge=I.target.value===""?null:parseInt(I.target.value);S(ke=>ke?{...ke,timeout:ge}:null)},placeholder:"默认: 30"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"retry_interval",children:"重试间隔(秒)"}),e.jsx(ie,{id:"retry_interval",type:"number",min:"1",value:b?.retry_interval??"",onChange:I=>{const ge=I.target.value===""?null:parseInt(I.target.value);S(ke=>ke?{...ke,retry_interval:ge}:null)},placeholder:"默认: 10"})]})]})]}),e.jsxs(at,{children:[e.jsx(C,{type:"button",variant:"outline",onClick:()=>y(!1),"data-tour":"provider-cancel-button",children:"取消"}),e.jsx(C,{type:"submit","data-tour":"provider-save-button",children:"保存"})]})]})]})}),e.jsx(js,{open:_,onOpenChange:T,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:['确定要删除提供商 "',$!==null?l[$]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:Pe,children:"删除"})]})]})}),e.jsx(js,{open:je,onOpenChange:be,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认批量删除"}),e.jsxs(xs,{children:["确定要删除选中的 ",Se.size," 个提供商吗? 此操作无法撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:Xs,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),e.jsx(js,{open:Ne.isOpen,onOpenChange:I=>Ce(ge=>({...ge,isOpen:I})),children:e.jsxs(os,{className:"max-w-2xl",children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除提供商"}),e.jsx(xs,{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(Ze,{className:"h-32 w-full rounded border p-3",children:e.jsx("div",{className:"space-y-1",children:Ne.affectedModels.map((I,ge)=>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:I.name}),e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",I.model_identifier,")"]})]},ge))})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"这些模型将从模型列表和所有任务分配中移除。此操作无法撤销。"})]})})]}),e.jsxs(us,{children:[e.jsx(fs,{onClick:F,children:"取消"}),e.jsx(hs,{onClick:nt,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})}),e.jsx(vn,{})]})}function yj(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).substring(2,11)}`}function wj(l){return typeof l=="boolean"?"boolean":typeof l=="number"?"number":"string"}function D1(l,i){switch(i){case"boolean":return l==="true";case"number":{const r=parseFloat(l);return isNaN(r)?0:r}default:return l}}function Fu(l){return Object.entries(l).map(([i,r])=>({id:yj(),key:i,value:r,type:wj(r)}))}function Iu(l){const i={};for(const r of l)r.key.trim()&&(i[r.key.trim()]=r.value);return i}function Qu(l){if(!l.trim())return{valid:!0,parsed:{}};try{const i=JSON.parse(l);if(typeof i!="object"||i===null||Array.isArray(i))return{valid:!1,error:"必须是一个 JSON 对象 {}"};for(const[r,o]of Object.entries(i))if(o!==null&&!["string","number","boolean"].includes(typeof o))return{valid:!1,error:`键 "${r}" 的值类型不支持(仅支持 string/number/boolean)`};return{valid:!0,parsed:i}}catch{return{valid:!1,error:"JSON 格式错误"}}}function R1(l){switch(l){case"boolean":return"布尔";case"number":return"数字";default:return"字符串"}}function L1(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 U1({value:l,onChange:i,className:r,placeholder:o="添加额外参数..."}){const[u,x]=m.useState("list"),[h,f]=m.useState(()=>Fu(l||{})),[g,j]=m.useState(()=>Object.keys(l||{}).length>0?JSON.stringify(l,null,2):""),[v,y]=m.useState(null);m.useEffect(()=>{const V=Fu(l||{});f(V),j(Object.keys(l||{}).length>0?JSON.stringify(l,null,2):"")},[l]);const b=m.useMemo(()=>{const V=Qu(g);return V.valid&&V.parsed?{success:!0,data:V.parsed}:{success:!1,data:{}}},[g]),S=m.useCallback(V=>{const z=V;if(z==="json"&&u==="list"){const _=Iu(h);j(Object.keys(_).length>0?JSON.stringify(_,null,2):""),y(null)}else if(z==="list"&&u==="json"){const _=Qu(g);_.valid&&_.parsed&&(f(Fu(_.parsed)),y(null))}x(z)},[u,h,g]),w=m.useCallback(()=>{const V={id:yj(),key:"",value:"",type:"string"},z=[...h,V];f(z)},[h]),O=m.useCallback(V=>{const z=h.filter(_=>_.id!==V);f(z),i(Iu(z))},[h,i]),A=m.useCallback((V,z,_)=>{const T=h.map($=>{if($.id!==V)return $;if(z==="type"){const E=_;let se;return E==="boolean"?se=$.value==="true"||$.value===!0:E==="number"?se=typeof $.value=="number"?$.value:parseFloat(String($.value))||0:se=String($.value),{...$,type:E,value:se}}else return z==="value"?{...$,value:D1(_,$.type)}:{...$,[z]:_}});f(T),i(Iu(T))},[h,i]),D=m.useCallback(V=>{j(V);const z=Qu(V);z.valid&&z.parsed?(y(null),i(z.parsed)):y(z.error||"JSON 格式错误")},[i]);return e.jsxs("div",{className:H("space-y-3",r),children:[e.jsx(k,{className:"text-sm font-medium",children:"额外参数"}),e.jsxs(Sa,{value:u,onValueChange:S,className:"w-full",children:[e.jsxs(xa,{className:"h-8 p-0.5 bg-muted/60",children:[e.jsx(is,{value:"list",className:"h-7 px-3 text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"键值对"}),e.jsx(is,{value:"json",className:"h-7 px-3 text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"JSON"})]}),e.jsxs(As,{value:"list",className:"mt-3 space-y-2",children:[h.length===0?e.jsx("div",{className:"text-sm text-muted-foreground text-center py-4 border border-dashed rounded-md",children:o}):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",{})]}),h.map(V=>e.jsxs("div",{className:"grid grid-cols-[1fr_1fr_90px_32px] gap-2 items-center",children:[e.jsx(ie,{value:V.key,onChange:z=>A(V.id,"key",z.target.value),placeholder:"key",className:"h-8 text-sm"}),V.type==="boolean"?e.jsxs("div",{className:"flex items-center h-8 px-3 border rounded-md bg-background",children:[e.jsx(Fe,{checked:V.value===!0,onCheckedChange:z=>A(V.id,"value",String(z))}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:V.value?"true":"false"})]}):e.jsx(ie,{type:V.type==="number"?"number":"text",value:V.value,onChange:z=>A(V.id,"value",z.target.value),placeholder:"value",className:"h-8 text-sm",step:V.type==="number"?"any":void 0}),e.jsxs(Ue,{value:V.type,onValueChange:z=>A(V.id,"type",z),children:[e.jsx(Re,{className:"h-8 text-xs",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"string",children:"字符串"}),e.jsx(ee,{value:"number",children:"数字"}),e.jsx(ee,{value:"boolean",children:"布尔"})]})]}),e.jsx(C,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>O(V.id),children:e.jsx(es,{className:"h-4 w-4"})})]},V.id))]}),e.jsxs(C,{type:"button",variant:"outline",size:"sm",className:"w-full h-8",onClick:w,children:[e.jsx(ut,{className:"h-4 w-4 mr-1"}),"添加参数"]})]}),e.jsx(As,{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:"编辑"}),v?e.jsxs("div",{className:"flex items-center gap-1 text-xs text-destructive",children:[e.jsx(Ot,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate max-w-[150px]",children:v})]}):g.trim()&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-green-600 dark:text-green-400",children:[e.jsx(ea,{className:"h-3 w-3"}),e.jsx("span",{children:"有效"})]})]}),e.jsx(Ys,{value:g,onChange:V=>D(V.target.value),placeholder:`{ "key": "value" }`,className:H("font-mono text-sm min-h-[140px] h-[140px] resize-y flex-1",v&&"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(([V,z])=>{const _=wj(z);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:V}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("span",{className:H("font-mono",_==="boolean"&&(z?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"),_==="number"&&"text-blue-600 dark:text-blue-400",_==="string"&&"text-amber-600 dark:text-amber-400"),children:_==="string"?`"${z}"`:String(z)}),e.jsx(Ye,{variant:"secondary",className:H("h-5 text-[10px] px-1.5",L1(_)),children:R1(_)})]},V)})}):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:"实时预览解析结果"})]})]})})]})]})}function B1({value:l,label:i,onRemove:r}){const{attributes:o,listeners:u,setNodeRef:x,transform:h,transition:f,isDragging:g}=Wg({id:l}),j={transform:ej.Transform.toString(h),transition:f,opacity:g?.5:1},v=b=>{b.preventDefault(),b.stopPropagation(),r(l)},y=b=>{b.stopPropagation()};return e.jsx("div",{ref:x,style:j,className:H("inline-flex items-center gap-1",g&&"shadow-lg"),children:e.jsxs(Ye,{variant:"secondary",className:"cursor-move hover:bg-secondary/80 flex items-center gap-1",children:[e.jsx("div",{...o,...u,className:"cursor-grab active:cursor-grabbing flex items-center",children:e.jsx(Lg,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx("span",{children:i}),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:y,onMouseDown:b=>b.stopPropagation(),children:e.jsx(fl,{className:"h-3 w-3 cursor-pointer hover:text-destructive",strokeWidth:2,fill:"none"})})]})})}function H1({options:l,selected:i,onChange:r,placeholder:o="选择选项...",emptyText:u="未找到选项",className:x}){const[h,f]=m.useState(!1),g=Ig(uo(Kg,{activationConstraint:{distance:8}}),uo(Yg,{coordinateGetter:Qg})),j=b=>{i.includes(b)?r(i.filter(S=>S!==b)):r([...i,b])},v=b=>{r(i.filter(S=>S!==b))},y=b=>{const{active:S,over:w}=b;if(w&&S.id!==w.id){const O=i.indexOf(S.id),A=i.indexOf(w.id);r(Xg(i,O,A))}};return e.jsxs(Ia,{open:h,onOpenChange:f,children:[e.jsx(Qa,{asChild:!0,children:e.jsxs(C,{variant:"outline",role:"combobox","aria-expanded":h,className:H("w-full justify-between min-h-10 h-auto",x),children:[e.jsx(Pg,{sensors:g,collisionDetection:Jg,onDragEnd:y,children:e.jsx(Zg,{items:i,strategy:h0,children:e.jsx("div",{className:"flex gap-1 flex-wrap flex-1",children:i.length===0?e.jsx("span",{className:"text-muted-foreground",children:o}):i.map(b=>{const S=l.find(w=>w.value===b);return e.jsx(B1,{value:b,label:S?.label||b,onRemove:v},b)})})})}),e.jsx(cm,{className:"ml-2 h-4 w-4 shrink-0 opacity-50",strokeWidth:2,fill:"none"})]})}),e.jsx(La,{className:"w-full p-0",align:"start",children:e.jsxs(vo,{children:[e.jsx(bo,{placeholder:"搜索...",className:"h-9"}),e.jsxs(No,{children:[e.jsx(yo,{children:u}),e.jsx(Cr,{children:l.map(b=>{const S=i.includes(b.value);return e.jsxs(kr,{value:b.value,onSelect:()=>j(b.value),children:[e.jsx("div",{className:H("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",S?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(ea,{className:"h-3 w-3",strokeWidth:2,fill:"none"})}),e.jsx("span",{children:b.label})]},b.value)})})]})]})})]})}const Ma=Ct.memo(function({title:i,description:r,taskConfig:o,modelNames:u,onChange:x,hideTemperature:h=!1,hideMaxTokens:f=!1,dataTour:g}){const j=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:i}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:r})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":g,children:[e.jsx(k,{children:"模型列表"}),e.jsx(H1,{options:u.map(v=>({label:v,value:v})),selected:o.model_list||[],onChange:j,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(k,{children:"温度"}),e.jsx(ie,{type:"number",step:"0.1",min:"0",max:"1",value:o.temperature??.3,onChange:v=>{const y=parseFloat(v.target.value);!isNaN(y)&&y>=0&&y<=1&&x("temperature",y)},className:"w-20 h-8 text-sm"})]}),e.jsx(ma,{value:[o.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(k,{children:"最大 Token"}),e.jsx(ie,{type:"number",step:"1",min:"1",value:o.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(k,{children:"慢请求阈值 (秒)"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"超时警告"})]}),e.jsx(ie,{type:"number",step:"1",min:"1",value:o.slow_threshold??15,onChange:v=>{const y=parseInt(v.target.value);!isNaN(y)&&y>=1&&x("slow_threshold",y)},placeholder:"15"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"模型响应时间超过此阈值将输出警告日志"})]})]})]})}),$1=Ct.memo(function({paginatedModels:i,allModels:r,onEdit:o,onDelete:u,isModelUsed:x,searchQuery:h}){return i.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:i.map((f,g)=>{const j=r.findIndex(y=>y===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(Ye,{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(C,{variant:"default",size:"sm",onClick:()=>o(f,j),children:[e.jsx(fn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(C,{size:"sm",onClick:()=>u(j),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(es,{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"]})]})]})]},g)})})}),q1=Ct.memo(function({paginatedModels:i,allModels:r,filteredModels:o,selectedModels:u,onEdit:x,onDelete:h,onToggleSelection:f,onToggleSelectAll:g,isModelUsed:j,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(bn,{children:[e.jsx(Nn,{children:e.jsxs(gt,{children:[e.jsx(Je,{className:"w-12",children:e.jsx(jt,{checked:u.size===o.length&&o.length>0,onCheckedChange:g})}),e.jsx(Je,{className:"w-24",children:"使用状态"}),e.jsx(Je,{children:"模型名称"}),e.jsx(Je,{children:"模型标识符"}),e.jsx(Je,{children:"提供商"}),e.jsx(Je,{className:"text-center",children:"温度"}),e.jsx(Je,{className:"text-right",children:"输入价格"}),e.jsx(Je,{className:"text-right",children:"输出价格"}),e.jsx(Je,{className:"text-right",children:"操作"})]})}),e.jsx(yn,{children:i.length===0?e.jsx(gt,{children:e.jsx(Qe,{colSpan:9,className:"text-center text-muted-foreground py-8",children:v?"未找到匹配的模型":"暂无模型配置"})}):i.map((y,b)=>{const S=r.findIndex(O=>O===y),w=j(y.name);return e.jsxs(gt,{children:[e.jsx(Qe,{children:e.jsx(jt,{checked:u.has(S),onCheckedChange:()=>f(S)})}),e.jsx(Qe,{children:e.jsx(Ye,{variant:w?"default":"secondary",className:w?"bg-green-600 hover:bg-green-700":"",children:w?"已使用":"未使用"})}),e.jsx(Qe,{className:"font-medium",children:y.name}),e.jsx(Qe,{className:"max-w-xs truncate",title:y.model_identifier,children:y.model_identifier}),e.jsx(Qe,{children:y.api_provider}),e.jsx(Qe,{className:"text-center",children:y.temperature!=null?y.temperature:e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsxs(Qe,{className:"text-right",children:["¥",y.price_in,"/M"]}),e.jsxs(Qe,{className:"text-right",children:["¥",y.price_out,"/M"]}),e.jsx(Qe,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(C,{variant:"default",size:"sm",onClick:()=>x(y,S),children:[e.jsx(fn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(C,{size:"sm",onClick:()=>h(S),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(es,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},b)})})]})})})}),G1=300*1e3,Mp=new Map,V1=[10,20,50,100],F1=Ct.memo(function({page:i,pageSize:r,totalItems:o,jumpToPage:u,onPageChange:x,onPageSizeChange:h,onJumpToPageChange:f,onJumpToPage:g,onSelectionClear:j}){const v=Math.ceil(o/r),y=S=>{h(parseInt(S)),x(1),j?.()},b=S=>{S.key==="Enter"&&g()};return o===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(k,{htmlFor:"page-size-model",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ue,{value:r.toString(),onValueChange:y,children:[e.jsx(Re,{id:"page-size-model",className:"w-20",children:e.jsx(Be,{})}),e.jsx(Le,{children:V1.map(S=>e.jsx(ee,{value:S.toString(),children:S},S))})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(i-1)*r+1," 到"," ",Math.min(i*r,o)," 条,共 ",o," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>x(1),disabled:i===1,className:"hidden sm:flex",children:e.jsx(vi,{className:"h-4 w-4"})}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>x(Math.max(1,i-1)),disabled:i===1,children:[e.jsx(pl,{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(ie,{type:"number",value:u,onChange:S=>f(S.target.value),onKeyDown:b,placeholder:i.toString(),className:"w-16 h-8 text-center",min:1,max:v}),e.jsx(C,{variant:"outline",size:"sm",onClick:g,disabled:!u,className:"h-8",children:"跳转"})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>x(i+1),disabled:i>=v,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ya,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>x(v),disabled:i>=v,className:"hidden sm:flex",children:e.jsx(bi,{className:"h-4 w-4"})})]})]})});function I1(l){const{models:i,taskConfig:r,debounceMs:o=2e3,onSavingChange:u,onUnsavedChange:x}=l,h=m.useRef(null),f=m.useRef(null),g=m.useRef(!0),j=m.useCallback(()=>{h.current&&(clearTimeout(h.current),h.current=null),f.current&&(clearTimeout(f.current),f.current=null)},[]),v=m.useCallback(S=>{const w={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??{}};return S.temperature!=null&&(w.temperature=S.temperature),S.max_tokens!=null&&(w.max_tokens=S.max_tokens),w},[]),y=m.useCallback(async S=>{try{u?.(!0);const w=S.map(v);await am("models",w),x?.(!1)}catch(w){console.error("自动保存模型列表失败:",w),x?.(!0)}finally{u?.(!1)}},[u,x,v]),b=m.useCallback(async S=>{try{u?.(!0),await am("model_task_config",S),x?.(!1)}catch(w){console.error("自动保存任务配置失败:",w),x?.(!0)}finally{u?.(!1)}},[u,x]);return m.useEffect(()=>{if(!g.current)return x?.(!0),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{y(i)},o),()=>{h.current&&clearTimeout(h.current)}},[i,y,o,x]),m.useEffect(()=>{if(!(g.current||!r))return x?.(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{b(r)},o),()=>{f.current&&clearTimeout(f.current)}},[r,b,o,x]),m.useEffect(()=>()=>{j()},[j]),{clearTimers:j,initialLoadRef:g}}function Q1(l={}){const{onCloseEditDialog:i}=l,r=ka(),{registerTour:o,startTour:u,state:x,goToStep:h}=xm(),f=m.useRef(x.stepIndex);return m.useEffect(()=>{o(Ga,bj)},[o]),m.useEffect(()=>{if(x.activeTourId===Ga&&x.isRunning){const j=Nj[x.stepIndex];j&&!window.location.pathname.endsWith(j.replace("/config/",""))&&r({to:j})}},[x.stepIndex,x.activeTourId,x.isRunning,r]),m.useEffect(()=>{if(x.activeTourId===Ga&&x.isRunning){const j=f.current,v=x.stepIndex;j>=12&&j<=17&&v<12&&i?.(),f.current=v}},[x.stepIndex,x.activeTourId,x.isRunning,i]),m.useEffect(()=>{if(x.activeTourId!==Ga||!x.isRunning)return;const j=v=>{const y=v.target,b=x.stepIndex;b===2&&y.closest('[data-tour="add-provider-button"]')?setTimeout(()=>h(3),300):b===9&&y.closest('[data-tour="provider-cancel-button"]')?setTimeout(()=>h(10),300):b===11&&y.closest('[data-tour="add-model-button"]')?setTimeout(()=>h(12),300):b===17&&y.closest('[data-tour="model-cancel-button"]')?setTimeout(()=>h(18),300):b===18&&y.closest('[data-tour="tasks-tab-trigger"]')&&setTimeout(()=>h(19),300)};return document.addEventListener("click",j,!0),()=>document.removeEventListener("click",j,!0)},[x,h]),{startTour:m.useCallback(()=>{u(Ga)},[u]),isRunning:x.isRunning&&x.activeTourId===Ga,stepIndex:x.stepIndex}}function Y1(l){const{getProviderConfig:i}=l,[r,o]=m.useState([]),[u,x]=m.useState(!1),[h,f]=m.useState(null),[g,j]=m.useState(null),v=m.useCallback(()=>{o([]),f(null),j(null)},[]),y=m.useCallback(async(b,S=!1)=>{const w=i(b);if(!w?.base_url){o([]),j(null),f('提供商配置不完整,请先在"模型提供商配置"中配置');return}if(!w.api_key){o([]),j(null),f('该提供商未配置 API Key,请先在"模型提供商配置"中填写');return}const O=z1(w.base_url);if(j(O),!O?.modelFetcher){o([]),f(null);return}const A=`${b}:${w.base_url}`,D=Mp.get(A);if(!S&&D&&Date.now()-D.timestampz(!1)}),{clearTimers:fe,initialLoadRef:ls}=I1({models:l,taskConfig:g,onSavingChange:O,onUnsavedChange:D}),G=m.useCallback(async()=>{try{y(!0);const W=await Gl(),de=W.models||[];i(de),f(de.map(Tt=>Tt.name));const ys=W.api_providers||[];o(ys.map(Tt=>Tt.name)),x(ys),j(W.model_task_config||null),D(!1),ls.current=!1}catch(W){console.error("加载配置失败:",W)}finally{y(!1)}},[ls]);m.useEffect(()=>{G()},[G]);const Me=m.useCallback(W=>u.find(de=>de.name===W),[u]),{availableModels:re,fetchingModels:pe,modelFetchError:Ee,matchedTemplate:Ie,fetchModelsForProvider:$e,clearModels:Vt}=Y1({getProviderConfig:Me});m.useEffect(()=>{V&&_?.api_provider&&$e(_.api_provider)},[V,_?.api_provider,$e]);const _t=async()=>{await J()},nt=W=>{const de={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&&(de.temperature=W.temperature),W.max_tokens!=null&&(de.max_tokens=W.max_tokens),de},F=async()=>{try{S(!0),fe();const W=await Gl();W.models=l.map(nt),W.model_task_config=g,await Nr(W),D(!1),Te({title:"保存成功",description:"正在重启麦麦..."}),await _t()}catch(W){console.error("保存配置失败:",W),Te({title:"保存失败",description:W.message,variant:"destructive"}),S(!1)}},He=async()=>{try{S(!0),fe();const W=await Gl();W.models=l.map(nt),W.model_task_config=g,await Nr(W),D(!1),Te({title:"保存成功",description:"模型配置已保存"}),await G()}catch(W){console.error("保存配置失败:",W),Te({title:"保存失败",description:W.message,variant:"destructive"})}finally{S(!1)}},De=(W,de)=>{xe({}),T(W||{model_identifier:"",name:"",api_provider:r[0]||"",price_in:0,price_out:0,temperature:null,max_tokens:null,force_stream_mode:!1,extra_params:{}}),E(de),z(!0)},ye=()=>{if(!_)return;const W={};if(_.name?.trim()||(W.name="请输入模型名称"),_.api_provider?.trim()||(W.api_provider="请选择 API 提供商"),_.model_identifier?.trim()||(W.model_identifier="请输入模型标识符"),Object.keys(W).length>0){xe(W);return}xe({});const de={model_identifier:_.model_identifier,name:_.name,api_provider:_.api_provider,price_in:_.price_in??0,price_out:_.price_out??0,force_stream_mode:_.force_stream_mode??!1,extra_params:_.extra_params??{}};_.temperature!=null&&(de.temperature=_.temperature),_.max_tokens!=null&&(de.max_tokens=_.max_tokens);let ys,Tt=null;if($!==null?(Tt=l[$].name,ys=[...l],ys[$]=de):ys=[...l,de],i(ys),f(ys.map(Et=>Et.name)),Tt&&Tt!==de.name&&g){const Et=I=>I.map(ge=>ge===Tt?de.name:ge);j({...g,utils:{...g.utils,model_list:Et(g.utils?.model_list||[])},utils_small:{...g.utils_small,model_list:Et(g.utils_small?.model_list||[])},tool_use:{...g.tool_use,model_list:Et(g.tool_use?.model_list||[])},replyer:{...g.replyer,model_list:Et(g.replyer?.model_list||[])},planner:{...g.planner,model_list:Et(g.planner?.model_list||[])},vlm:{...g.vlm,model_list:Et(g.vlm?.model_list||[])},voice:{...g.voice,model_list:Et(g.voice?.model_list||[])},embedding:{...g.embedding,model_list:Et(g.embedding?.model_list||[])},lpmm_entity_extract:{...g.lpmm_entity_extract,model_list:Et(g.lpmm_entity_extract?.model_list||[])},lpmm_rdf_build:{...g.lpmm_rdf_build,model_list:Et(g.lpmm_rdf_build?.model_list||[])},lpmm_qa:{...g.lpmm_qa,model_list:Et(g.lpmm_qa?.model_list||[])}})}z(!1),T(null),E(null)},ps=W=>{if(!W&&_){const de={..._,price_in:_.price_in??0,price_out:_.price_out??0};T(de)}z(W)},ss=W=>{ue(W),te(!0)},Es=()=>{if(ne!==null){const W=l.filter((de,ys)=>ys!==ne);i(W),f(W.map(de=>de.name)),Te({title:"删除成功",description:"模型已从列表中移除"})}te(!1),ue(null)},Ms=W=>{const de=new Set(je);de.has(W)?de.delete(W):de.add(W),be(de)},Ls=()=>{if(je.size===Os.length)be(new Set);else{const W=Os.map((de,ys)=>l.findIndex(Tt=>Tt===Os[ys]));be(new Set(W))}},ts=()=>{if(je.size===0){Te({title:"提示",description:"请先选择要删除的模型",variant:"default"});return}P(!0)},Pe=()=>{const W=l.filter((de,ys)=>!je.has(ys));i(W),f(W.map(de=>de.name)),be(new Set),P(!1),Te({title:"批量删除成功",description:`已删除 ${je.size} 个模型`})},Xe=(W,de,ys)=>{g&&j({...g,[W]:{...g[W],[de]:ys}})},Os=l.filter(W=>{if(!Se)return!0;const de=Se.toLowerCase();return W.name.toLowerCase().includes(de)||W.model_identifier.toLowerCase().includes(de)||W.api_provider.toLowerCase().includes(de)}),kt=Math.ceil(Os.length/B),Xs=Os.slice((X-1)*B,X*B),Ss=()=>{const W=parseInt(Ne);W>=1&&W<=kt&&(L(W),Ce(""))},xt=W=>g?[g.utils?.model_list||[],g.utils_small?.model_list||[],g.tool_use?.model_list||[],g.replyer?.model_list||[],g.planner?.model_list||[],g.vlm?.model_list||[],g.voice?.model_list||[],g.embedding?.model_list||[],g.lpmm_entity_extract?.model_list||[],g.lpmm_rdf_build?.model_list||[],g.lpmm_qa?.model_list||[]].some(ys=>ys.includes(W)):!1;return v?e.jsx(Ze,{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(Ze,{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.jsxs(C,{onClick:He,disabled:b||w||!A||le,size:"sm",variant:"outline",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(Ar,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),b?"保存中...":w?"自动保存中...":A?"保存配置":"已保存"]}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsxs(C,{disabled:b||w||le,size:"sm",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(Mr,{className:"mr-2 h-4 w-4"}),le?"重启中...":A?"保存并重启":"重启麦麦"]})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认重启麦麦?"}),e.jsx(xs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:A?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:A?F:_t,children:A?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(sa,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(ta,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),e.jsxs(sa,{className:"hidden lg:flex border-primary/30 bg-primary/5 cursor-pointer hover:bg-primary/10 transition-colors",onClick:qe,children:[e.jsx(Gy,{className:"h-4 w-4 text-primary"}),e.jsxs(ta,{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[e.jsx("strong",{className:"text-primary",children:"新手引导:"}),"不知道如何配置模型?点击这里开始学习如何为麦麦的组件分配模型。"]}),e.jsx(C,{variant:"outline",size:"sm",className:"ml-4 shrink-0",children:"开始引导"})]})]}),e.jsxs(Sa,{defaultValue:"models",className:"w-full",children:[e.jsxs(xa,{className:"grid w-full max-w-full sm:max-w-md grid-cols-2",children:[e.jsx(is,{value:"models",children:"添加模型"}),e.jsx(is,{value:"tasks","data-tour":"tasks-tab-trigger",children:"为模型分配功能"})]}),e.jsxs(As,{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:[je.size>0&&e.jsxs(C,{onClick:ts,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(es,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",je.size,")"]}),e.jsxs(C,{onClick:()=>De(null,null),size:"sm",variant:"outline",className:"w-full sm:w-auto","data-tour":"add-model-button",children:[e.jsx(ut,{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($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"搜索模型名称、标识符或提供商...",value:Se,onChange:W=>oe(W.target.value),className:"pl-9"})]}),Se&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",Os.length," 个结果"]})]}),e.jsx($1,{paginatedModels:Xs,allModels:l,onEdit:De,onDelete:ss,isModelUsed:xt,searchQuery:Se}),e.jsx(q1,{paginatedModels:Xs,allModels:l,filteredModels:Os,selectedModels:je,onEdit:De,onDelete:ss,onToggleSelection:Ms,onToggleSelectAll:Ls,isModelUsed:xt,searchQuery:Se}),e.jsx(F1,{page:X,pageSize:B,totalItems:Os.length,jumpToPage:Ne,onPageChange:L,onPageSizeChange:_e,onJumpToPageChange:Ce,onJumpToPage:Ss,onSelectionClear:()=>be(new Set)})]}),e.jsxs(As,{value:"tasks",className:"space-y-6 mt-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"为不同的任务配置使用的模型和参数"}),g&&e.jsxs("div",{className:"grid gap-4 sm:gap-6",children:[e.jsx(Ma,{title:"组件模型 (utils)",description:"用于表情包、取名、关系、情绪变化等组件",taskConfig:g.utils,modelNames:h,onChange:(W,de)=>Xe("utils",W,de),dataTour:"task-model-select"}),e.jsx(Ma,{title:"组件小模型 (utils_small)",description:"消耗量较大的组件,建议使用速度较快的小模型",taskConfig:g.utils_small,modelNames:h,onChange:(W,de)=>Xe("utils_small",W,de)}),e.jsx(Ma,{title:"工具调用模型 (tool_use)",description:"需要使用支持工具调用的模型",taskConfig:g.tool_use,modelNames:h,onChange:(W,de)=>Xe("tool_use",W,de)}),e.jsx(Ma,{title:"首要回复模型 (replyer)",description:"用于表达器和表达方式学习",taskConfig:g.replyer,modelNames:h,onChange:(W,de)=>Xe("replyer",W,de)}),e.jsx(Ma,{title:"决策模型 (planner)",description:"负责决定麦麦该什么时候回复",taskConfig:g.planner,modelNames:h,onChange:(W,de)=>Xe("planner",W,de)}),e.jsx(Ma,{title:"图像识别模型 (vlm)",description:"视觉语言模型",taskConfig:g.vlm,modelNames:h,onChange:(W,de)=>Xe("vlm",W,de),hideTemperature:!0}),e.jsx(Ma,{title:"语音识别模型 (voice)",description:"语音转文字",taskConfig:g.voice,modelNames:h,onChange:(W,de)=>Xe("voice",W,de),hideTemperature:!0,hideMaxTokens:!0}),e.jsx(Ma,{title:"嵌入模型 (embedding)",description:"用于向量化",taskConfig:g.embedding,modelNames:h,onChange:(W,de)=>Xe("embedding",W,de),hideTemperature:!0,hideMaxTokens:!0}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库模型"}),e.jsx(Ma,{title:"实体提取模型 (lpmm_entity_extract)",description:"从文本中提取实体",taskConfig:g.lpmm_entity_extract,modelNames:h,onChange:(W,de)=>Xe("lpmm_entity_extract",W,de)}),e.jsx(Ma,{title:"RDF 构建模型 (lpmm_rdf_build)",description:"构建知识图谱",taskConfig:g.lpmm_rdf_build,modelNames:h,onChange:(W,de)=>Xe("lpmm_rdf_build",W,de)}),e.jsx(Ma,{title:"问答模型 (lpmm_qa)",description:"知识库问答",taskConfig:g.lpmm_qa,modelNames:h,onChange:(W,de)=>Xe("lpmm_qa",W,de)})]})]})]})]}),e.jsx(Qs,{open:V,onOpenChange:ps,children:e.jsxs(qs,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"model-dialog",preventOutsideClose:We,children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:$!==null?"编辑模型":"添加模型"}),e.jsx(Ws,{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(k,{htmlFor:"model_name",className:Q.name?"text-destructive":"",children:"模型名称 *"}),e.jsx(ie,{id:"model_name",value:_?.name||"",onChange:W=>{T(de=>de?{...de,name:W.target.value}:null),Q.name&&xe(de=>({...de,name:void 0}))},placeholder:"例如: qwen3-30b",className:Q.name?"border-destructive focus-visible:ring-destructive":""}),Q.name?e.jsx("p",{className:"text-xs text-destructive",children:Q.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(k,{htmlFor:"api_provider",className:Q.api_provider?"text-destructive":"",children:"API 提供商 *"}),e.jsxs(Ue,{value:_?.api_provider||"",onValueChange:W=>{T(de=>de?{...de,api_provider:W}:null),Vt(),Q.api_provider&&xe(de=>({...de,api_provider:void 0}))},children:[e.jsx(Re,{id:"api_provider",className:Q.api_provider?"border-destructive focus-visible:ring-destructive":"",children:e.jsx(Be,{placeholder:"选择提供商"})}),e.jsx(Le,{children:r.map(W=>e.jsx(ee,{value:W,children:W},W))})]}),Q.api_provider&&e.jsx("p",{className:"text-xs text-destructive",children:Q.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(k,{htmlFor:"model_identifier",className:Q.model_identifier?"text-destructive":"",children:"模型标识符 *"}),Ie?.modelFetcher&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ye,{variant:"secondary",className:"text-xs",children:Ie.display_name}),e.jsx(C,{variant:"ghost",size:"sm",className:"h-6 px-2",onClick:()=>_?.api_provider&&$e(_.api_provider,!0),disabled:pe,children:pe?e.jsx(tt,{className:"h-3 w-3 animate-spin"}):e.jsx(At,{className:"h-3 w-3"})})]})]}),Ie?.modelFetcher?e.jsxs(Ia,{open:ve,onOpenChange:ze,children:[e.jsx(Qa,{asChild:!0,children:e.jsxs(C,{variant:"outline",role:"combobox","aria-expanded":ve,className:"w-full justify-between font-normal",disabled:pe||!!Ee,children:[pe?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(tt,{className:"h-4 w-4 animate-spin"}),"正在获取模型列表..."]}):Ee?e.jsx("span",{className:"text-muted-foreground text-sm",children:"点击下方输入框手动填写"}):_?.model_identifier?e.jsx("span",{className:"truncate",children:_.model_identifier}):e.jsx("span",{className:"text-muted-foreground",children:"搜索或选择模型..."}),e.jsx(cm,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(La,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(vo,{children:[e.jsx(bo,{placeholder:"搜索模型..."}),e.jsx(Ze,{className:"h-[300px]",children:e.jsxs(No,{className:"max-h-none overflow-visible",children:[e.jsx(yo,{children:Ee?e.jsxs("div",{className:"py-4 px-2 text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:Ee}),!Ee.includes("API Key")&&e.jsx(C,{variant:"link",size:"sm",onClick:()=>_?.api_provider&&$e(_.api_provider,!0),children:"重试"})]}):"未找到匹配的模型"}),e.jsx(Cr,{heading:"可用模型",children:re.map(W=>e.jsxs(kr,{value:W.id,onSelect:()=>{T(de=>de?{...de,model_identifier:W.id}:null),ze(!1)},children:[e.jsx(ea,{className:`mr-2 h-4 w-4 ${_?.model_identifier===W.id?"opacity-100":"opacity-0"}`}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:W.id}),W.name!==W.id&&e.jsx("span",{className:"text-xs text-muted-foreground",children:W.name})]})]},W.id))}),e.jsx(Cr,{heading:"手动输入",children:e.jsxs(kr,{value:"__manual_input__",onSelect:()=>{ze(!1)},children:[e.jsx(fn,{className:"mr-2 h-4 w-4"}),"手动输入模型标识符..."]})})]})})]})})]}):e.jsx(ie,{id:"model_identifier",value:_?.model_identifier||"",onChange:W=>{T(de=>de?{...de,model_identifier:W.target.value}:null),Q.model_identifier&&xe(de=>({...de,model_identifier:void 0}))},placeholder:"Qwen/Qwen3-30B-A3B-Instruct-2507",className:Q.model_identifier?"border-destructive focus-visible:ring-destructive":""}),Q.model_identifier&&e.jsx("p",{className:"text-xs text-destructive",children:Q.model_identifier}),Ee&&Ie?.modelFetcher&&!Q.model_identifier&&e.jsxs(sa,{variant:"destructive",className:"mt-2 py-2",children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsx(ta,{className:"text-xs",children:Ee})]}),Ie?.modelFetcher&&e.jsx(ie,{value:_?.model_identifier||"",onChange:W=>{T(de=>de?{...de,model_identifier:W.target.value}:null),Q.model_identifier&&xe(de=>({...de,model_identifier:void 0}))},placeholder:"或手动输入模型标识符",className:`mt-2 ${Q.model_identifier?"border-destructive focus-visible:ring-destructive":""}`}),!Q.model_identifier&&e.jsx("p",{className:"text-xs text-muted-foreground",children:Ee?'请手动输入模型标识符,或前往"模型提供商配置"检查 API Key':Ie?.modelFetcher?`已识别为 ${Ie.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(k,{htmlFor:"price_in",children:"输入价格 (¥/M token)"}),e.jsx(ie,{id:"price_in",type:"number",step:"0.1",min:"0",value:_?.price_in??"",onChange:W=>{const de=W.target.value===""?null:parseFloat(W.target.value);T(ys=>ys?{...ys,price_in:de}:null)},placeholder:"默认: 0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"price_out",children:"输出价格 (¥/M token)"}),e.jsx(ie,{id:"price_out",type:"number",step:"0.1",min:"0",value:_?.price_out??"",onChange:W=>{const de=W.target.value===""?null:parseFloat(W.target.value);T(ys=>ys?{...ys,price_out:de}: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(k,{htmlFor:"enable_model_temperature",className:"cursor-pointer",children:"自定义模型温度"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务温度配置"})]}),e.jsx(Fe,{id:"enable_model_temperature",checked:_?.temperature!=null,onCheckedChange:W=>{T(W?de=>de?{...de,temperature:.5}:null:de=>de?{...de,temperature:null}:null)}})]}),_?.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(k,{className:"text-sm",children:"温度值"}),e.jsx("span",{className:"text-sm font-medium tabular-nums",children:_.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(ma,{value:[_.temperature],onValueChange:W=>T(de=>de?{...de,temperature:W[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(k,{htmlFor:"enable_model_max_tokens",className:"cursor-pointer",children:"自定义最大 Token"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务最大 Token 配置"})]}),e.jsx(Fe,{id:"enable_model_max_tokens",checked:_?.max_tokens!=null,onCheckedChange:W=>{T(W?de=>de?{...de,max_tokens:2048}:null:de=>de?{...de,max_tokens:null}:null)}})]}),_?.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(k,{className:"text-sm",children:"最大 Token 数"}),e.jsx(ie,{type:"number",min:"1",max:"128000",value:_.max_tokens,onChange:W=>{const de=parseInt(W.target.value);!isNaN(de)&&de>=1&&T(ys=>ys?{...ys,max_tokens:de}: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(Fe,{id:"force_stream_mode",checked:_?.force_stream_mode||!1,onCheckedChange:W=>T(de=>de?{...de,force_stream_mode:W}:null)}),e.jsx(k,{htmlFor:"force_stream_mode",className:"cursor-pointer",children:"强制流式输出模式"})]}),e.jsx(U1,{value:_?.extra_params||{},onChange:W=>T(de=>de?{...de,extra_params:W}:null),placeholder:"添加额外参数(如 enable_thinking、top_p 等)..."})]}),e.jsxs(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>z(!1),"data-tour":"model-cancel-button",children:"取消"}),e.jsx(C,{onClick:ye,"data-tour":"model-save-button",children:"保存"})]})]})}),e.jsx(js,{open:se,onOpenChange:te,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:['确定要删除模型 "',ne!==null?l[ne]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:Es,children:"删除"})]})]})}),e.jsx(js,{open:U,onOpenChange:P,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认批量删除"}),e.jsxs(xs,{children:["确定要删除选中的 ",je.size," 个模型吗? 此操作无法撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:Pe,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),e.jsx(vn,{})]})})}const Tr=QN,Er=YN,zr=KN,wo="/api/webui/config";async function P1(){const i=await(await we(`${wo}/adapter-config/path`)).json();return!i.success||!i.path?null:{path:i.path,lastModified:i.lastModified}}async function Ap(l){const r=await(await we(`${wo}/adapter-config/path`,{method:"POST",headers:Is(),body:JSON.stringify({path:l})})).json();if(!r.success)throw new Error(r.message||"保存路径失败")}async function Op(l){const r=await(await we(`${wo}/adapter-config?path=${encodeURIComponent(l)}`)).json();if(!r.success)throw new Error("读取配置文件失败");return r.content}async function Dp(l,i){const o=await(await we(`${wo}/adapter-config`,{method:"POST",headers:Is(),body:JSON.stringify({path:l,content:i})})).json();if(!o.success)throw new Error(o.message||"保存配置失败")}const ot={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"}},Yu={oneclick:{name:"一键包",description:"使用一键包部署的适配器配置",path:"../MaiBot-Napcat-Adapter/config.toml",icon:Vl},docker:{name:"Docker",description:"Docker Compose 部署的适配器配置",path:"/MaiMBot/adapters-config/config.toml",icon:Vy}};function J1(l,i){let r=l.slice(0,i).split(/\r\n|\n|\r/g);return[r.length,r.pop().length+1]}function Z1(l,i,r){let o=l.split(/\r\n|\n|\r/g),u="",x=(Math.log10(i+1)|0)+1;for(let h=i-1;h<=i+1;h++){let f=o[h-1];f&&(u+=h.toString().padEnd(x," "),u+=": ",u+=f,u+=` `,h===i&&(u+=" ".repeat(x+r+2),u+=`^ `))}return u}class Ns extends Error{line;column;codeblock;constructor(i,r){const[o,u]=J1(r.toml,r.ptr),x=Z1(r.toml,o,u);super(`Invalid TOML document: ${i} ${x}`,r),this.line=o,this.column=u,this.codeblock=x}}function W1(l,i){let r=0;for(;l[i-++r]==="\\";);return--r&&r%2}function ho(l,i=0,r=l.length){let o=l.indexOf(` `,i);return l[o-1]==="\r"&&o--,o<=r?o:-1}function hm(l,i){for(let r=i;r-1&&r!=="'"&&W1(l,i));return i>-1&&(i+=o.length,o.length>1&&(l[i]===r&&i++,l[i]===r&&i++)),i}let e2=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}:\d{2}(?:\.\d+)?)?(Z|[-+]\d{2}:\d{2})?$/i;class mi extends Date{#s=!1;#t=!1;#e=null;constructor(i){let r=!0,o=!0,u="Z";if(typeof i=="string"){let x=i.match(e2);x?(x[1]||(r=!1,i=`0000-01-01T${i}`),o=!!x[2],o&&i[10]===" "&&(i=i.replace(" ","T")),x[2]&&+x[2]>23?i="":(u=x[3]||null,i=i.toUpperCase(),!u&&o&&(i+="Z"))):i=""}super(i),isNaN(this.getTime())||(this.#s=r,this.#t=o,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 i=super.toISOString();if(this.isDate())return i.slice(0,10);if(this.isTime())return i.slice(11,23);if(this.#e===null)return i.slice(0,-1);if(this.#e==="Z")return i;let r=+this.#e.slice(1,3)*60+ +this.#e.slice(4,6);return r=this.#e[0]==="-"?r:-r,new Date(this.getTime()-r*6e4).toISOString().slice(0,-1)+this.#e}static wrapAsOffsetDateTime(i,r="Z"){let o=new mi(i);return o.#e=r,o}static wrapAsLocalDateTime(i){let r=new mi(i);return r.#e=null,r}static wrapAsLocalDate(i){let r=new mi(i);return r.#t=!1,r.#e=null,r}static wrapAsLocalTime(i){let r=new mi(i);return r.#s=!1,r.#e=null,r}}let s2=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,t2=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,a2=/^[+-]?0[0-9_]/,l2=/^[0-9a-f]{4,8}$/i,Lp={b:"\b",t:" ",n:` `,f:"\f",r:"\r",'"':'"',"\\":"\\"};function Sj(l,i=0,r=l.length){let o=l[i]==="'",u=l[i++]===l[i]&&l[i]===l[i+1];u&&(r-=2,l[i+=2]==="\r"&&i++,l[i]===` `&&i++);let x=0,h,f="",g=i;for(;i-1&&(hm(l,x),u=u.slice(0,x));let h=u.trimEnd();if(!o){let f=u.indexOf(` `,h.length);if(f>-1)throw new Ns("newlines are not allowed in inline tables",{toml:l,ptr:i+f})}return[h,x]}function fm(l,i,r,o,u){if(o===0)throw new Ns("document contains excessively nested structures. aborting.",{toml:l,ptr:i});let x=l[i];if(x==="["||x==="{"){let[g,j]=x==="["?o2(l,i,o,u):c2(l,i,o,u),v=r?Rp(l,j,",",r):j;if(j-v&&r==="}"){let y=ho(l,j,v);if(y>-1)throw new Ns("newlines are not allowed in inline tables",{toml:l,ptr:y})}return[g,v]}let h;if(x==='"'||x==="'"){h=_j(l,i);let g=Sj(l,i,h);if(r){if(h=hl(l,h,r!=="]"),l[h]&&l[h]!==","&&l[h]!==r&&l[h]!==` `&&l[h]!=="\r")throw new Ns("unexpected character encountered",{toml:l,ptr:h});h+=+(l[h]===",")}return[g,h]}h=Rp(l,i,",",r);let f=i2(l,i,h-+(l[h-1]===","),r==="]");if(!f[0])throw new Ns("incomplete key-value declaration: no value specified",{toml:l,ptr:i});return r&&f[1]>-1&&(h=hl(l,i+f[1]),h+=+(l[h]===",")),[n2(f[0],l,i,u),h]}let r2=/^[a-zA-Z0-9-_]+[ \t]*$/;function lm(l,i,r="="){let o=i-1,u=[],x=l.indexOf(r,i);if(x<0)throw new Ns("incomplete key-value: cannot find end of key",{toml:l,ptr:i});do{let h=l[i=++o];if(h!==" "&&h!==" ")if(h==='"'||h==="'"){if(h===l[i+1]&&h===l[i+2])throw new Ns("multiline strings are not allowed in keys",{toml:l,ptr:i});let f=_j(l,i);if(f<0)throw new Ns("unfinished string encountered",{toml:l,ptr:i});o=l.indexOf(".",f);let g=l.slice(f,o<0||o>x?x:o),j=ho(g);if(j>-1)throw new Ns("newlines are not allowed in keys",{toml:l,ptr:i+o+j});if(g.trimStart())throw new Ns("found extra tokens after the string part",{toml:l,ptr:f});if(xx?x:o);if(!r2.test(f))throw new Ns("only letter, numbers, dashes and underscores are allowed in keys",{toml:l,ptr:i});u.push(f.trimEnd())}}while(o+1&&ou===""||u===null||u===void 0?x:u,r={inner:{version:i(l.inner.version,ot.inner.version)},nickname:{nickname:i(l.nickname.nickname,ot.nickname.nickname)},napcat_server:{host:i(l.napcat_server.host,ot.napcat_server.host),port:i(l.napcat_server.port||0,ot.napcat_server.port),token:i(l.napcat_server.token,ot.napcat_server.token),heartbeat_interval:i(l.napcat_server.heartbeat_interval||0,ot.napcat_server.heartbeat_interval)},maibot_server:{host:i(l.maibot_server.host,ot.maibot_server.host),port:i(l.maibot_server.port||0,ot.maibot_server.port)},chat:{group_list_type:i(l.chat.group_list_type,ot.chat.group_list_type),group_list:l.chat.group_list||[],private_list_type:i(l.chat.private_list_type,ot.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??ot.chat.ban_qq_bot,enable_poke:l.chat.enable_poke??ot.chat.enable_poke},voice:{use_tts:l.voice.use_tts??ot.voice.use_tts},debug:{level:i(l.debug.level,ot.debug.level)}};let o=f2(r);return o=p2(o),o}catch(i){throw console.error("TOML 生成失败:",i),new Error(`无法生成 TOML 文件: ${i instanceof Error?i.message:"未知错误"}`)}}function p2(l){const i=l.split(` `),r=[];for(let o=0;o"|?*\x00-\x1F]/.test(l)?{valid:!1,error:"路径包含非法字符"}:{valid:!0,error:""}}function g2(){const[l,i]=m.useState("upload"),[r,o]=m.useState(null),[u,x]=m.useState(""),[h,f]=m.useState(""),[g,j]=m.useState("oneclick"),[v,y]=m.useState(""),[b,S]=m.useState(!1),[w,O]=m.useState(!1),[A,D]=m.useState(!1),[V,z]=m.useState(!1),[_,T]=m.useState(null),[$,E]=m.useState(!1),se=m.useRef(null),{toast:te}=Ks(),ne=m.useRef(null),ue=Q=>{if(f(Q),Q.trim()){const xe=Pu(Q);y(xe.error)}else y("")},Se=m.useCallback(async Q=>{const xe=Yu[Q];O(!0);try{const Te=await Op(xe.path),J=Ku(Te);o(J),j(Q),f(xe.path),await Ap(xe.path),te({title:"加载成功",description:`已从${xe.name}预设加载配置`})}catch(Te){console.error("加载预设配置失败:",Te),te({title:"加载失败",description:Te instanceof Error?Te.message:"无法读取预设配置文件",variant:"destructive"})}finally{O(!1)}},[te]),oe=m.useCallback(async Q=>{const xe=Pu(Q);if(!xe.valid){y(xe.error),te({title:"路径无效",description:xe.error,variant:"destructive"});return}y(""),O(!0);try{const Te=await Op(Q),J=Ku(Te);o(J),f(Q),await Ap(Q),te({title:"加载成功",description:"已从配置文件加载"})}catch(Te){console.error("加载配置失败:",Te),te({title:"加载失败",description:Te instanceof Error?Te.message:"无法读取配置文件",variant:"destructive"})}finally{O(!1)}},[te]);m.useEffect(()=>{(async()=>{try{const xe=await P1();if(xe&&xe.path){f(xe.path);const Te=Object.entries(Yu).find(([,J])=>J.path===xe.path);Te?(i("preset"),j(Te[0]),await Se(Te[0])):(i("path"),await oe(xe.path))}}catch(xe){console.error("加载保存的路径失败:",xe)}})()},[oe,Se]);const je=m.useCallback(Q=>{l!=="path"&&l!=="preset"||!h||(ne.current&&clearTimeout(ne.current),ne.current=setTimeout(async()=>{S(!0);try{const xe=Xu(Q);await Dp(h,xe),te({title:"自动保存成功",description:"配置已保存到文件"})}catch(xe){console.error("自动保存失败:",xe),te({title:"自动保存失败",description:xe instanceof Error?xe.message:"保存配置失败",variant:"destructive"})}finally{S(!1)}},1e3))},[l,h,te]),be=async()=>{if(!r||!h)return;const Q=Pu(h);if(!Q.valid){te({title:"保存失败",description:Q.error,variant:"destructive"});return}S(!0);try{const xe=Xu(r);await Dp(h,xe),te({title:"保存成功",description:"配置已保存到文件"})}catch(xe){console.error("保存失败:",xe),te({title:"保存失败",description:xe instanceof Error?xe.message:"保存配置失败",variant:"destructive"})}finally{S(!1)}},U=async()=>{h&&await oe(h)},P=Q=>{if(Q!==l){if(r){T(Q),D(!0);return}X(Q)}},X=Q=>{o(null),x(""),y(""),i(Q),Q==="preset"&&Se("oneclick"),te({title:"已切换模式",description:{upload:"现在可以上传配置文件",path:"现在可以指定配置文件路径",preset:"现在可以使用预设配置"}[Q]})},L=()=>{_&&(X(_),T(null)),D(!1)},B=()=>{if(r){z(!0);return}_e()},_e=()=>{f(""),o(null),y(""),te({title:"已清空",description:"路径和配置已清空"})},Ne=()=>{_e(),z(!1)},Ce=Q=>{const xe=Q.target.files?.[0];if(!xe)return;const Te=new FileReader;Te.onload=J=>{try{const le=J.target?.result,qe=Ku(le);o(qe),x(xe.name),te({title:"上传成功",description:`已加载配置文件:${xe.name}`})}catch(le){console.error("解析配置文件失败:",le),te({title:"解析失败",description:"配置文件格式错误,请检查文件内容",variant:"destructive"})}},Te.readAsText(xe)},ve=()=>{if(!r)return;const Q=Xu(r),xe=new Blob([Q],{type:"text/plain;charset=utf-8"}),Te=URL.createObjectURL(xe),J=document.createElement("a");J.href=Te,J.download=u||"config.toml",document.body.appendChild(J),J.click(),document.body.removeChild(J),URL.revokeObjectURL(Te),te({title:"下载成功",description:"配置文件已下载,请手动覆盖并重启适配器"})},ze=()=>{o(JSON.parse(JSON.stringify(ot))),x("config.toml"),te({title:"已加载默认配置",description:"可以开始编辑配置"})};return e.jsx(Ze,{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(Ot,{className:"h-4 w-4 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm",children:"适配器配置保存之后使用 WebUI 的重启功能适配器并不会重启,需要手动重启适配器。"})]}),e.jsx(Tr,{open:$,onOpenChange:E,children:e.jsxs(Ve,{children:[e.jsx(rs,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(cs,{children:"工作模式"}),e.jsx(st,{children:"选择配置文件的管理方式"})]}),e.jsx(Er,{asChild:!0,children:e.jsxs(C,{variant:"ghost",size:"sm",className:"w-9 p-0",children:[e.jsx(Fa,{className:`h-4 w-4 transition-transform duration-200 ${$?"transform rotate-180":""}`}),e.jsx("span",{className:"sr-only",children:"切换"})]})})]})}),e.jsx(zr,{children:e.jsxs(gs,{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:()=>P("preset"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(Vl,{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:()=>P("upload"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(_r,{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:()=>P("path"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(Fy,{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(k,{className:"text-sm md:text-base",children:"选择部署方式"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(Yu).map(([Q,xe])=>{const Te=xe.icon,J=g===Q;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:()=>{j(Q),Se(Q)},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Te,{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:xe.name}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:xe.description}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-mono break-all",children:xe.path})]})]})},Q)})})]}),l==="path"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{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(ie,{id:"config-path",value:h,onChange:Q=>ue(Q.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(C,{onClick:()=>oe(h),disabled:w||!h||!!v,className:"w-full sm:w-auto",children:w?e.jsxs(e.Fragment,{children:[e.jsx(At,{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(sa,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsx(ta,{children:l==="preset"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"预设模式:"}),"选择预设的部署方式,配置会自动加载,修改后 1 秒自动保存",b&&" (正在保存...)"]}):l==="upload"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"上传文件模式:"}),"上传配置文件 → 在线编辑 → 下载文件 → 手动覆盖并重启适配器"]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"指定路径模式:"}),"指定配置文件路径后,配置会自动加载,修改后 1 秒自动保存",b&&" (正在保存...)"]})})]}),l==="upload"&&!r&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 w-full",children:[e.jsx("input",{ref:se,type:"file",accept:".toml",className:"hidden",onChange:Ce}),e.jsxs(C,{onClick:()=>se.current?.click(),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(_r,{className:"mr-2 h-4 w-4"}),"上传配置"]}),e.jsxs(C,{onClick:ze,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Aa,{className:"mr-2 h-4 w-4"}),"使用默认配置"]})]}),l==="upload"&&r&&e.jsx("div",{className:"flex gap-2",children:e.jsxs(C,{onClick:ve,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Da,{className:"mr-2 h-4 w-4"}),"下载配置"]})}),(l==="preset"||l==="path")&&r&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs(C,{onClick:be,size:"sm",disabled:b||!!v,className:"w-full sm:w-auto",children:[e.jsx(Ar,{className:"mr-2 h-4 w-4"}),b?"保存中...":"立即保存"]}),e.jsxs(C,{onClick:U,size:"sm",variant:"outline",disabled:w,className:"w-full sm:w-auto",children:[e.jsx(At,{className:`mr-2 h-4 w-4 ${w?"animate-spin":""}`}),"刷新"]}),l==="path"&&e.jsxs(C,{onClick:B,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(es,{className:"mr-2 h-4 w-4"}),"清空路径"]})]}),r?e.jsxs(Sa,{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(xa,{className:"inline-flex w-auto min-w-full sm:grid sm:w-full sm:grid-cols-5",children:[e.jsxs(is,{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(is,{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(is,{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(is,{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(is,{value:"debug",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:"调试"})]})}),e.jsx(As,{value:"napcat",className:"space-y-4",children:e.jsx(j2,{config:r,onChange:Q=>{o(Q),je(Q)}})}),e.jsx(As,{value:"maibot",className:"space-y-4",children:e.jsx(v2,{config:r,onChange:Q=>{o(Q),je(Q)}})}),e.jsx(As,{value:"chat",className:"space-y-4",children:e.jsx(b2,{config:r,onChange:Q=>{o(Q),je(Q)}})}),e.jsx(As,{value:"voice",className:"space-y-4",children:e.jsx(N2,{config:r,onChange:Q=>{o(Q),je(Q)}})}),e.jsx(As,{value:"debug",className:"space-y-4",children:e.jsx(y2,{config:r,onChange:Q=>{o(Q),je(Q)}})})]}):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(Aa,{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(js,{open:A,onOpenChange:D,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认切换模式"}),e.jsxs(xs,{children:["切换模式将清空当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-destructive font-medium",children:"请确保已保存重要配置"})]})]}),e.jsxs(us,{children:[e.jsx(fs,{onClick:()=>{D(!1),T(null)},children:"取消"}),e.jsx(hs,{onClick:L,children:"确认切换"})]})]})}),e.jsx(js,{open:V,onOpenChange:z,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认清空路径"}),e.jsxs(xs,{children:["清空路径将清除当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-muted-foreground text-sm",children:"此操作不会删除配置文件,只是清除界面中的配置"})]})]}),e.jsxs(us,{children:[e.jsx(fs,{onClick:()=>z(!1),children:"取消"}),e.jsx(hs,{onClick:Ne,className:"bg-destructive hover:bg-destructive/90",children:"确认清空"})]})]})})]})})}function j2({config:l,onChange:i}){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(k,{htmlFor:"napcat-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(ie,{id:"napcat-host",value:l.napcat_server.host,onChange:r=>i({...l,napcat_server:{...l.napcat_server,host:r.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(k,{htmlFor:"napcat-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(ie,{id:"napcat-port",type:"number",value:l.napcat_server.port||"",onChange:r=>i({...l,napcat_server:{...l.napcat_server,port:r.target.value?parseInt(r.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(k,{htmlFor:"napcat-token",className:"text-sm md:text-base",children:"访问令牌(Token)"}),e.jsx(ie,{id:"napcat-token",type:"password",value:l.napcat_server.token,onChange:r=>i({...l,napcat_server:{...l.napcat_server,token:r.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(k,{htmlFor:"napcat-heartbeat",className:"text-sm md:text-base",children:"心跳间隔(秒)"}),e.jsx(ie,{id:"napcat-heartbeat",type:"number",value:l.napcat_server.heartbeat_interval||"",onChange:r=>i({...l,napcat_server:{...l.napcat_server,heartbeat_interval:r.target.value?parseInt(r.target.value):0}}),placeholder:"30",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"与 Napcat 设置的心跳间隔保持一致(留空使用默认值 30)"})]})]})]})})}function v2({config:l,onChange:i}){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(k,{htmlFor:"maibot-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(ie,{id:"maibot-host",value:l.maibot_server.host,onChange:r=>i({...l,maibot_server:{...l.maibot_server,host:r.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(k,{htmlFor:"maibot-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(ie,{id:"maibot-port",type:"number",value:l.maibot_server.port||"",onChange:r=>i({...l,maibot_server:{...l.maibot_server,port:r.target.value?parseInt(r.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 b2({config:l,onChange:i}){const r=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],i(h)},o=(x,h)=>{const f={...l};x==="group"?f.chat.group_list=f.chat.group_list.filter((g,j)=>j!==h):x==="private"?f.chat.private_list=f.chat.private_list.filter((g,j)=>j!==h):f.chat.ban_user_id=f.chat.ban_user_id.filter((g,j)=>j!==h),i(f)},u=(x,h,f)=>{const g={...l};x==="group"?g.chat.group_list[h]=f:x==="private"?g.chat.private_list[h]=f:g.chat.ban_user_id[h]=f,i(g)};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(k,{className:"text-sm md:text-base",children:"群组名单类型"}),e.jsxs(Ue,{value:l.chat.group_list_type,onValueChange:x=>i({...l,chat:{...l.chat,group_list_type:x}}),children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(ee,{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(k,{className:"text-sm md:text-base",children:"群组列表"}),e.jsxs(C,{onClick:()=>r("group"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Aa,{className:"mr-1 h-4 w-4"}),"添加群号"]})]}),l.chat.group_list.map((x,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{type:"number",value:x,onChange:f=>u("group",h,parseInt(f.target.value)||0),placeholder:"输入群号",className:"text-sm md:text-base"}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{size:"icon",variant:"outline",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:["确定要删除群号 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>o("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(k,{className:"text-sm md:text-base",children:"私聊名单类型"}),e.jsxs(Ue,{value:l.chat.private_list_type,onValueChange:x=>i({...l,chat:{...l.chat,private_list_type:x}}),children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(ee,{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(k,{className:"text-sm md:text-base",children:"私聊列表"}),e.jsxs(C,{onClick:()=>r("private"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Aa,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),l.chat.private_list.map((x,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{type:"number",value:x,onChange:f=>u("private",h,parseInt(f.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{size:"icon",variant:"outline",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:["确定要删除用户 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>o("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(k,{className:"text-sm md:text-base",children:"全局禁止名单"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"名单中的用户无法进行任何聊天"})]}),e.jsxs(C,{onClick:()=>r("ban"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Aa,{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(ie,{type:"number",value:x,onChange:f=>u("ban",h,parseInt(f.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(js,{children:[e.jsx(mt,{asChild:!0,children:e.jsx(C,{size:"icon",variant:"outline",children:e.jsx(es,{className:"h-4 w-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:["确定要从全局禁止名单中删除用户 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>o("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(k,{className:"text-sm md:text-base",children:"屏蔽QQ官方机器人"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否屏蔽来自QQ官方机器人的消息"})]}),e.jsx(Fe,{checked:l.chat.ban_qq_bot,onCheckedChange:x=>i({...l,chat:{...l.chat,ban_qq_bot:x}})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-sm md:text-base",children:"启用戳一戳功能"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否响应戳一戳消息"})]}),e.jsx(Fe,{checked:l.chat.enable_poke,onCheckedChange:x=>i({...l,chat:{...l.chat,enable_poke:x}})})]})]})]})})}function N2({config:l,onChange:i}){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(k,{className:"text-sm md:text-base",children:"使用 TTS 语音"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"请确保已配置 TTS 并有对应的适配器"})]}),e.jsx(Fe,{checked:l.voice.use_tts,onCheckedChange:r=>i({...l,voice:{use_tts:r}})})]})]})})}function y2({config:l,onChange:i}){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(k,{className:"text-sm md:text-base",children:"日志等级"}),e.jsxs(Ue,{value:l.debug.level,onValueChange:r=>i({...l,debug:{level:r}}),children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"DEBUG",children:"DEBUG(调试)"}),e.jsx(ee,{value:"INFO",children:"INFO(信息)"}),e.jsx(ee,{value:"WARNING",children:"WARNING(警告)"}),e.jsx(ee,{value:"ERROR",children:"ERROR(错误)"}),e.jsx(ee,{value:"CRITICAL",children:"CRITICAL(严重)"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"设置适配器的日志输出等级"})]})})]})})}const w2=["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"],_2=/^(aria-|data-)/,kj=l=>Object.fromEntries(Object.entries(l).filter(([i])=>_2.test(i)||w2.includes(i)));function S2(l,i){const r=kj(l);return Object.keys(l).some(o=>!Object.hasOwn(r,o)&&l[o]!==i[o])}class C2 extends m.Component{container;plugin;componentDidMount(){this.installPlugin()}componentDidUpdate(i){if(i.uppy!==this.props.uppy)this.uninstallPlugin(i),this.installPlugin();else if(S2(this.props,i)){const{uppy:r,...o}={...this.props,target:this.container};this.plugin.setOptions(o)}}componentWillUnmount(){this.uninstallPlugin()}installPlugin(){const{uppy:i,...r}={id:"Dashboard",...this.props,inline:!0,target:this.container};i.use(g0,r),this.plugin=i.getPlugin(r.id)}uninstallPlugin(i=this.props){const{uppy:r}=i;r.removePlugin(this.plugin)}render(){return m.createElement("div",{className:"uppy-Container",ref:i=>{this.container=i},...kj(this.props)})}}function k2({src:l,alt:i="表情包",className:r,maxRetries:o=5,retryInterval:u=1500}){const[x,h]=m.useState("loading"),[f,g]=m.useState(0),[j,v]=m.useState(null),y=m.useCallback(async()=>{try{const b=await fetch(l,{credentials:"include"});if(b.status===202){h("generating"),f{g(O=>O+1)},u):h("error");return}if(!b.ok){h("error");return}const S=await b.blob(),w=URL.createObjectURL(S);v(w),h("loaded")}catch(b){console.error("加载缩略图失败:",b),h("error")}},[l,f,o,u]);return m.useEffect(()=>{h("loading"),g(0),v(null)},[l]),m.useEffect(()=>{y()},[y]),m.useEffect(()=>()=>{j&&URL.revokeObjectURL(j)},[j]),x==="loading"||x==="generating"?e.jsx(aj,{className:H("w-full h-full",r)}):x==="error"||!j?e.jsx("div",{className:H("w-full h-full flex items-center justify-center bg-muted",r),children:e.jsx(Ug,{className:"h-8 w-8 text-muted-foreground"})}):e.jsx("img",{src:j,alt:i,className:H("w-full h-full object-contain",r)})}function Tj({content:l,className:i=""}){return e.jsx("div",{className:`prose prose-sm dark:prose-invert max-w-none ${i}`,children:e.jsx(v0,{remarkPlugins:[N0,y0],rehypePlugins:[b0],components:{code({inline:r,className:o,children:u,...x}){return r?e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-sm font-mono",...x,children:u}):e.jsx("code",{className:`${o} block bg-muted p-4 rounded-lg overflow-x-auto`,...x,children:u})},table({children:r,...o}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{className:"border-collapse border border-border",...o,children:r})})},th({children:r,...o}){return e.jsx("th",{className:"border border-border bg-muted px-4 py-2 text-left font-semibold",...o,children:r})},td({children:r,...o}){return e.jsx("td",{className:"border border-border px-4 py-2",...o,children:r})},a({children:r,...o}){return e.jsx("a",{className:"text-primary hover:underline",target:"_blank",rel:"noopener noreferrer",...o,children:r})},blockquote({children:r,...o}){return e.jsx("blockquote",{className:"border-l-4 border-primary pl-4 italic text-muted-foreground",...o,children:r})},h1({children:r,...o}){return e.jsx("h1",{className:"text-3xl font-bold mt-6 mb-4",...o,children:r})},h2({children:r,...o}){return e.jsx("h2",{className:"text-2xl font-bold mt-5 mb-3",...o,children:r})},h3({children:r,...o}){return e.jsx("h3",{className:"text-xl font-bold mt-4 mb-2",...o,children:r})},h4({children:r,...o}){return e.jsx("h4",{className:"text-lg font-semibold mt-3 mb-2",...o,children:r})},ul({children:r,...o}){return e.jsx("ul",{className:"list-disc list-inside space-y-1 my-2",...o,children:r})},ol({children:r,...o}){return e.jsx("ol",{className:"list-decimal list-inside space-y-1 my-2",...o,children:r})},p({children:r,...o}){return e.jsx("p",{className:"my-2 leading-relaxed",...o,children:r})},hr({...r}){return e.jsx("hr",{className:"my-4 border-border",...r})}},children:l})})}function T2({children:l,className:i}){return e.jsx(Tj,{content:l,className:i})}const Ca="/api/webui/emoji";async function E2(l){const i=new URLSearchParams;l.page&&i.append("page",l.page.toString()),l.page_size&&i.append("page_size",l.page_size.toString()),l.search&&i.append("search",l.search),l.is_registered!==void 0&&i.append("is_registered",l.is_registered.toString()),l.is_banned!==void 0&&i.append("is_banned",l.is_banned.toString()),l.format&&i.append("format",l.format),l.sort_by&&i.append("sort_by",l.sort_by),l.sort_order&&i.append("sort_order",l.sort_order);const r=await we(`${Ca}/list?${i}`,{});if(!r.ok)throw new Error(`获取表情包列表失败: ${r.statusText}`);return r.json()}async function z2(l){const i=await we(`${Ca}/${l}`,{});if(!i.ok)throw new Error(`获取表情包详情失败: ${i.statusText}`);return i.json()}async function M2(l,i){const r=await we(`${Ca}/${l}`,{method:"PATCH",body:JSON.stringify(i)});if(!r.ok)throw new Error(`更新表情包失败: ${r.statusText}`);return r.json()}async function A2(l){const i=await we(`${Ca}/${l}`,{method:"DELETE"});if(!i.ok)throw new Error(`删除表情包失败: ${i.statusText}`);return i.json()}async function O2(){const l=await we(`${Ca}/stats/summary`,{});if(!l.ok)throw new Error(`获取统计数据失败: ${l.statusText}`);return l.json()}async function D2(l){const i=await we(`${Ca}/${l}/register`,{method:"POST"});if(!i.ok)throw new Error(`注册表情包失败: ${i.statusText}`);return i.json()}async function R2(l){const i=await we(`${Ca}/${l}/ban`,{method:"POST"});if(!i.ok)throw new Error(`封禁表情包失败: ${i.statusText}`);return i.json()}function L2(l,i=!1){return i?`${Ca}/${l}/thumbnail?original=true`:`${Ca}/${l}/thumbnail`}function U2(l){return`${Ca}/${l}/thumbnail?original=true`}async function B2(l){const i=await we(`${Ca}/batch/delete`,{method:"POST",body:JSON.stringify({emoji_ids:l})});if(!i.ok){const r=await i.json();throw new Error(r.detail||"批量删除失败")}return i.json()}function H2(){return`${Ca}/upload`}function $2(){const[l,i]=m.useState([]),[r,o]=m.useState(null),[u,x]=m.useState(!1),[h,f]=m.useState(1),[g,j]=m.useState(0),[v,y]=m.useState(20),[b,S]=m.useState("all"),[w,O]=m.useState("all"),[A,D]=m.useState("all"),[V,z]=m.useState("usage_count"),[_,T]=m.useState("desc"),[$,E]=m.useState(null),[se,te]=m.useState(!1),[ne,ue]=m.useState(!1),[Se,oe]=m.useState(!1),[je,be]=m.useState(new Set),[U,P]=m.useState(!1),[X,L]=m.useState(""),[B,_e]=m.useState("medium"),[Ne,Ce]=m.useState(!1),{toast:ve}=Ks(),ze=m.useCallback(async()=>{try{x(!0);const re=await E2({page:h,page_size:v,is_registered:b==="all"?void 0:b==="registered",is_banned:w==="all"?void 0:w==="banned",format:A==="all"?void 0:A,sort_by:V,sort_order:_});i(re.data),j(re.total)}catch(re){const pe=re instanceof Error?re.message:"加载表情包列表失败";ve({title:"错误",description:pe,variant:"destructive"})}finally{x(!1)}},[h,v,b,w,A,V,_,ve]),Q=async()=>{try{const re=await O2();o(re.data)}catch(re){console.error("加载统计数据失败:",re)}};m.useEffect(()=>{ze()},[ze]),m.useEffect(()=>{Q()},[]);const xe=async re=>{try{const pe=await z2(re.id);E(pe.data),te(!0)}catch(pe){const Ee=pe instanceof Error?pe.message:"加载详情失败";ve({title:"错误",description:Ee,variant:"destructive"})}},Te=re=>{E(re),ue(!0)},J=re=>{E(re),oe(!0)},le=async()=>{if($)try{await A2($.id),ve({title:"成功",description:"表情包已删除"}),oe(!1),E(null),ze(),Q()}catch(re){const pe=re instanceof Error?re.message:"删除失败";ve({title:"错误",description:pe,variant:"destructive"})}},qe=async re=>{try{await D2(re.id),ve({title:"成功",description:"表情包已注册"}),ze(),Q()}catch(pe){const Ee=pe instanceof Error?pe.message:"注册失败";ve({title:"错误",description:Ee,variant:"destructive"})}},We=async re=>{try{await R2(re.id),ve({title:"成功",description:"表情包已封禁"}),ze(),Q()}catch(pe){const Ee=pe instanceof Error?pe.message:"封禁失败";ve({title:"错误",description:Ee,variant:"destructive"})}},fe=re=>{const pe=new Set(je);pe.has(re)?pe.delete(re):pe.add(re),be(pe)},ls=async()=>{try{const re=await B2(Array.from(je));ve({title:"批量删除完成",description:re.message}),be(new Set),P(!1),ze(),Q()}catch(re){ve({title:"批量删除失败",description:re instanceof Error?re.message:"批量删除失败",variant:"destructive"})}},G=()=>{const re=parseInt(X),pe=Math.ceil(g/v);re>=1&&re<=pe?(f(re),L("")):ve({title:"无效的页码",description:`请输入1-${pe}之间的页码`,variant:"destructive"})},Me=r?.formats?Object.keys(r.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(C,{onClick:()=>Ce(!0),className:"gap-2",children:[e.jsx(_r,{className:"h-4 w-4"}),"上传表情包"]})]}),e.jsx(Ze,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[r&&e.jsxs("div",{className:"grid gap-4 grid-cols-2 lg:grid-cols-4",children:[e.jsx(Ve,{children:e.jsxs(rs,{className:"pb-2",children:[e.jsx(st,{children:"总数"}),e.jsx(cs,{className:"text-2xl",children:r.total})]})}),e.jsx(Ve,{children:e.jsxs(rs,{className:"pb-2",children:[e.jsx(st,{children:"已注册"}),e.jsx(cs,{className:"text-2xl text-green-600",children:r.registered})]})}),e.jsx(Ve,{children:e.jsxs(rs,{className:"pb-2",children:[e.jsx(st,{children:"已封禁"}),e.jsx(cs,{className:"text-2xl text-red-600",children:r.banned})]})}),e.jsx(Ve,{children:e.jsxs(rs,{className:"pb-2",children:[e.jsx(st,{children:"未注册"}),e.jsx(cs,{className:"text-2xl text-gray-600",children:r.unregistered})]})})]}),e.jsxs(Ve,{children:[e.jsx(rs,{children:e.jsxs(cs,{className:"flex items-center gap-2",children:[e.jsx(lo,{className:"h-5 w-5"}),"筛选和排序"]})}),e.jsxs(gs,{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(k,{children:"排序方式"}),e.jsxs(Ue,{value:`${V}-${_}`,onValueChange:re=>{const[pe,Ee]=re.split("-");z(pe),T(Ee),f(1)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"usage_count-desc",children:"使用次数 (多→少)"}),e.jsx(ee,{value:"usage_count-asc",children:"使用次数 (少→多)"}),e.jsx(ee,{value:"register_time-desc",children:"注册时间 (新→旧)"}),e.jsx(ee,{value:"register_time-asc",children:"注册时间 (旧→新)"}),e.jsx(ee,{value:"record_time-desc",children:"记录时间 (新→旧)"}),e.jsx(ee,{value:"record_time-asc",children:"记录时间 (旧→新)"}),e.jsx(ee,{value:"last_used_time-desc",children:"最后使用 (新→旧)"}),e.jsx(ee,{value:"last_used_time-asc",children:"最后使用 (旧→新)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"注册状态"}),e.jsxs(Ue,{value:b,onValueChange:re=>{S(re),f(1)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"all",children:"全部"}),e.jsx(ee,{value:"registered",children:"已注册"}),e.jsx(ee,{value:"unregistered",children:"未注册"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"封禁状态"}),e.jsxs(Ue,{value:w,onValueChange:re=>{O(re),f(1)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"all",children:"全部"}),e.jsx(ee,{value:"banned",children:"已封禁"}),e.jsx(ee,{value:"unbanned",children:"未封禁"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"格式"}),e.jsxs(Ue,{value:A,onValueChange:re=>{D(re),f(1)},children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"all",children:"全部"}),Me.map(re=>e.jsxs(ee,{value:re,children:[re.toUpperCase()," (",r?.formats[re],")"]},re))]})]})]})]}),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:[je.size>0&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["已选择 ",je.size," 个表情包"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{className:"text-sm whitespace-nowrap",children:"卡片大小"}),e.jsxs(Ue,{value:B,onValueChange:re=>_e(re),children:[e.jsx(Re,{className:"w-24",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"small",children:"小"}),e.jsx(ee,{value:"medium",children:"中"}),e.jsx(ee,{value:"large",children:"大"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{htmlFor:"emoji-page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ue,{value:v.toString(),onValueChange:re=>{y(parseInt(re)),f(1),be(new Set)},children:[e.jsx(Re,{id:"emoji-page-size",className:"w-20",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"20",children:"20"}),e.jsx(ee,{value:"40",children:"40"}),e.jsx(ee,{value:"60",children:"60"}),e.jsx(ee,{value:"100",children:"100"})]})]}),je.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>be(new Set),children:"取消选择"}),e.jsxs(C,{variant:"destructive",size:"sm",onClick:()=>P(!0),children:[e.jsx(es,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsxs(C,{variant:"outline",size:"sm",onClick:ze,disabled:u,children:[e.jsx(At,{className:`h-4 w-4 mr-2 ${u?"animate-spin":""}`}),"刷新"]})})]})]}),e.jsxs(Ve,{children:[e.jsxs(rs,{children:[e.jsx(cs,{children:"表情包列表"}),e.jsxs(st,{children:["共 ",g," 个表情包,当前第 ",h," 页"]})]}),e.jsxs(gs,{children:[l.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"暂无数据"}):e.jsx("div",{className:`grid gap-3 ${B==="small"?"grid-cols-3 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10":B==="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(re=>e.jsxs("div",{className:`group relative rounded-lg border bg-card overflow-hidden hover:ring-2 hover:ring-primary transition-all cursor-pointer ${je.has(re.id)?"ring-2 ring-primary bg-primary/5":""}`,onClick:()=>fe(re.id),children:[e.jsx("div",{className:`absolute top-1 left-1 z-10 transition-opacity ${je.has(re.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 ${je.has(re.id)?"bg-primary border-primary text-primary-foreground":"bg-background/80 border-muted-foreground/50"}`,children:je.has(re.id)&&e.jsx(aa,{className:"h-3 w-3"})})}),e.jsxs("div",{className:"absolute top-1 right-1 z-10 flex flex-col gap-0.5",children:[re.is_registered&&e.jsx(Ye,{variant:"default",className:"bg-green-600 text-[10px] px-1 py-0",children:"已注册"}),re.is_banned&&e.jsx(Ye,{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 ${B==="small"?"p-1":B==="medium"?"p-2":"p-3"}`,children:e.jsx(k2,{src:L2(re.id),alt:"表情包"})}),e.jsxs("div",{className:`border-t bg-card ${B==="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(Ye,{variant:"outline",className:"text-[10px] px-1 py-0",children:re.format.toUpperCase()}),e.jsxs("span",{className:"font-mono",children:[re.usage_count,"次"]})]}),e.jsxs("div",{className:`flex gap-1 justify-center opacity-0 group-hover:opacity-100 transition-opacity ${B==="small"?"flex-wrap":""}`,children:[e.jsx(C,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:pe=>{pe.stopPropagation(),Te(re)},title:"编辑",children:e.jsx(pn,{className:"h-3 w-3"})}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:pe=>{pe.stopPropagation(),xe(re)},title:"详情",children:e.jsx(Ra,{className:"h-3 w-3"})}),!re.is_registered&&e.jsx(C,{variant:"ghost",size:"icon",className:"h-6 w-6 text-green-600 hover:text-green-700",onClick:pe=>{pe.stopPropagation(),qe(re)},title:"注册",children:e.jsx(aa,{className:"h-3 w-3"})}),!re.is_banned&&e.jsx(C,{variant:"ghost",size:"icon",className:"h-6 w-6 text-orange-600 hover:text-orange-700",onClick:pe=>{pe.stopPropagation(),We(re)},title:"封禁",children:e.jsx(Iy,{className:"h-3 w-3"})}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-6 w-6 text-red-600 hover:text-red-700",onClick:pe=>{pe.stopPropagation(),J(re)},title:"删除",children:e.jsx(es,{className:"h-3 w-3"})})]})]})]},re.id))}),g>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,g)," 条,共 ",g," 条"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(vi,{className:"h-4 w-4"})}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>f(re=>Math.max(1,re-1)),disabled:h===1,children:[e.jsx(pl,{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(ie,{type:"number",value:X,onChange:re=>L(re.target.value),onKeyDown:re=>re.key==="Enter"&&G(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(g/v)}),e.jsx(C,{variant:"outline",size:"sm",onClick:G,disabled:!X,className:"h-8",children:"跳转"})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>f(re=>re+1),disabled:h>=Math.ceil(g/v),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ya,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(g/v)),disabled:h>=Math.ceil(g/v),className:"hidden sm:flex",children:e.jsx(bi,{className:"h-4 w-4"})})]})]})]})]}),e.jsx(q2,{emoji:$,open:se,onOpenChange:te}),e.jsx(G2,{emoji:$,open:ne,onOpenChange:ue,onSuccess:()=>{ze(),Q()}}),e.jsx(V2,{open:Ne,onOpenChange:Ce,onSuccess:()=>{ze(),Q()}})]})}),e.jsx(js,{open:U,onOpenChange:P,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认批量删除"}),e.jsxs(xs,{children:["你确定要删除选中的 ",je.size," 个表情包吗?此操作不可撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:ls,children:"确认删除"})]})]})}),e.jsx(Qs,{open:Se,onOpenChange:oe,children:e.jsxs(qs,{children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"确认删除"}),e.jsx(Ws,{children:"确定要删除这个表情包吗?此操作无法撤销。"})]}),e.jsxs(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>oe(!1),children:"取消"}),e.jsx(C,{variant:"destructive",onClick:le,children:"删除"})]})]})})]})}function q2({emoji:l,open:i,onOpenChange:r}){if(!l)return null;const o=u=>u?new Date(u*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Qs,{open:i,onOpenChange:r,children:e.jsxs(qs,{className:"max-w-2xl max-h-[90vh]",children:[e.jsx(Gs,{children:e.jsx(Vs,{children:"表情包详情"})}),e.jsx(Ze,{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:U2(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(k,{className:"text-muted-foreground",children:"ID"}),e.jsx("div",{className:"mt-1 font-mono",children:l.id})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-muted-foreground",children:"格式"}),e.jsx("div",{className:"mt-1",children:e.jsx(Ye,{variant:"outline",children:l.format.toUpperCase()})})]})]}),e.jsxs("div",{children:[e.jsx(k,{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(k,{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(k,{className:"text-muted-foreground",children:"描述"}),l.description?e.jsx("div",{className:"mt-1 rounded-lg border bg-muted/50 p-3",children:e.jsx(T2,{className:"prose-sm",children:l.description})}):e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"-"})]}),e.jsxs("div",{children:[e.jsx(k,{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(k,{className:"text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[l.is_registered&&e.jsx(Ye,{variant:"default",className:"bg-green-600",children:"已注册"}),l.is_banned&&e.jsx(Ye,{variant:"destructive",children:"已封禁"}),!l.is_registered&&!l.is_banned&&e.jsx(Ye,{variant:"outline",children:"未注册"})]})]}),e.jsxs("div",{children:[e.jsx(k,{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(k,{className:"text-muted-foreground",children:"记录时间"}),e.jsx("div",{className:"mt-1 text-sm",children:o(l.record_time)})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-muted-foreground",children:"注册时间"}),e.jsx("div",{className:"mt-1 text-sm",children:o(l.register_time)})]})]}),e.jsxs("div",{children:[e.jsx(k,{className:"text-muted-foreground",children:"最后使用"}),e.jsx("div",{className:"mt-1 text-sm",children:o(l.last_used_time)})]})]})})]})})}function G2({emoji:l,open:i,onOpenChange:r,onSuccess:o}){const[u,x]=m.useState(""),[h,f]=m.useState(!1),[g,j]=m.useState(!1),[v,y]=m.useState(!1),{toast:b}=Ks();m.useEffect(()=>{l&&(x(l.emotion||""),f(l.is_registered),j(l.is_banned))},[l]);const S=async()=>{if(l)try{y(!0);const w=u.split(/[,,]/).map(O=>O.trim()).filter(Boolean).join(",");await M2(l.id,{emotion:w||void 0,is_registered:h,is_banned:g}),b({title:"成功",description:"表情包信息已更新"}),r(!1),o()}catch(w){const O=w instanceof Error?w.message:"保存失败";b({title:"错误",description:O,variant:"destructive"})}finally{y(!1)}};return l?e.jsx(Qs,{open:i,onOpenChange:r,children:e.jsxs(qs,{className:"max-w-2xl",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"编辑表情包"}),e.jsx(Ws,{children:"修改表情包的情绪和状态信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(k,{children:"情绪"}),e.jsx(Ys,{value:u,onChange:w=>x(w.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(jt,{id:"is_registered",checked:h,onCheckedChange:w=>{w===!0?(f(!0),j(!1)):f(!1)}}),e.jsx(k,{htmlFor:"is_registered",className:"cursor-pointer",children:"已注册"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(jt,{id:"is_banned",checked:g,onCheckedChange:w=>{w===!0?(j(!0),f(!1)):j(!1)}}),e.jsx(k,{htmlFor:"is_banned",className:"cursor-pointer",children:"已封禁"})]})]})]}),e.jsxs(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(C,{onClick:S,disabled:v,children:v?"保存中...":"保存"})]})]})}):null}function V2({open:l,onOpenChange:i,onSuccess:r}){const[o,u]=m.useState("select"),[x,h]=m.useState([]),[f,g]=m.useState(null),[j,v]=m.useState(!1),{toast:y}=Ks(),b=m.useMemo(()=>new j0({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 $=()=>{const E=b.getFiles();if(E.length===0)return;const se=E.map(te=>({id:te.id,name:te.name,previewUrl:te.preview||URL.createObjectURL(te.data),emotion:"",description:"",isRegistered:!0,file:te.data}));h(se),E.length===1?(g(se[0].id),u("edit-single")):u("edit-multiple")};return b.on("upload",$),()=>{b.off("upload",$)}},[b]),m.useEffect(()=>{l||(b.cancelAll(),u("select"),h([]),g(null),v(!1))},[l,b]);const S=m.useCallback(($,E)=>{h(se=>se.map(te=>te.id===$?{...te,...E}:te))},[]),w=m.useCallback($=>$.emotion.trim().length>0,[]),O=m.useMemo(()=>x.length>0&&x.every(w),[x,w]),A=m.useMemo(()=>x.find($=>$.id===f)||null,[x,f]),D=m.useCallback(()=>{(o==="edit-single"||o==="edit-multiple")&&(u("select"),h([]),g(null))},[o]),V=m.useCallback(async()=>{if(!O){y({title:"请填写必填项",description:"每个表情包的情感标签都是必填的",variant:"destructive"});return}v(!0);let $=0,E=0;try{for(const se of x){const te=new FormData;te.append("file",se.file),te.append("emotion",se.emotion),te.append("description",se.description),te.append("is_registered",se.isRegistered.toString());try{(await we(H2(),{method:"POST",body:te})).ok?$++:E++}catch{E++}}E===0?(y({title:"上传成功",description:`成功上传 ${$} 个表情包`}),i(!1),r()):(y({title:"部分上传失败",description:`成功 ${$} 个,失败 ${E} 个`,variant:"destructive"}),r())}finally{v(!1)}},[O,x,y,i,r]),z=()=>e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"border rounded-lg overflow-hidden w-full",children:e.jsx(C2,{uppy:b,proudlyDisplayPoweredByUppy:!1,hideProgressDetails:!0,height:350,width:"100%",theme:"auto",note:"支持 JPG、PNG、GIF、WebP 格式,最多 20 个文件"})})}),_=()=>{const $=x[0];return $?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(C,{variant:"ghost",size:"sm",onClick:D,children:[e.jsx(hi,{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:$.previewUrl,alt:$.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:$.name})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{htmlFor:"single-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ie,{id:"single-emotion",value:$.emotion,onChange:E=>S($.id,{emotion:E.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:$.emotion.trim()?"":"border-destructive"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于情感匹配,多个标签用逗号分隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"single-description",children:"描述"}),e.jsx(ie,{id:"single-description",value:$.description,onChange:E=>S($.id,{description:E.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(jt,{id:"single-is-registered",checked:$.isRegistered,onCheckedChange:E=>S($.id,{isRegistered:E===!0})}),e.jsx(k,{htmlFor:"single-is-registered",className:"cursor-pointer",children:"上传后立即注册(可被麦麦使用)"})]})]})]}),e.jsx(at,{children:e.jsx(C,{onClick:V,disabled:!O||j,children:j?"上传中...":"上传"})})]}):null},T=()=>{const $=x.filter(w).length,E=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(C,{variant:"ghost",size:"sm",onClick:D,children:[e.jsx(hi,{className:"h-4 w-4 mr-1"}),"返回"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["编辑表情包信息(",$,"/",E," 已完成)"]})]}),e.jsx(Ye,{variant:O?"default":"secondary",children:O?e.jsxs(e.Fragment,{children:[e.jsx(ea,{className:"h-3 w-3 mr-1"}),"全部完成"]}):e.jsxs(e.Fragment,{children:[e.jsx(fl,{className:"h-3 w-3 mr-1"}),"未完成"]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ze,{className:"h-[350px] pr-2",children:e.jsx("div",{className:"space-y-2",children:x.map(se=>{const te=w(se),ne=f===se.id;return e.jsxs("div",{onClick:()=>g(se.id),className:` flex items-center gap-3 p-3 rounded-lg border-2 cursor-pointer transition-all ${ne?"ring-2 ring-primary":""} ${te?"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:se.previewUrl,alt:se.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:se.name}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:se.emotion||"未填写情感标签"})]}),te?e.jsx(aa,{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"})]},se.id)})})}),e.jsx("div",{className:"border rounded-lg p-4",children:A?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:A.previewUrl,alt:A.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:A.name}),w(A)&&e.jsxs(Ye,{variant:"outline",className:"text-green-600 border-green-600",children:[e.jsx(ea,{className:"h-3 w-3 mr-1"}),"已完成"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{htmlFor:"multi-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ie,{id:"multi-emotion",value:A.emotion,onChange:se=>S(A.id,{emotion:se.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:A.emotion.trim()?"":"border-destructive"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"multi-description",children:"描述"}),e.jsx(ie,{id:"multi-description",value:A.description,onChange:se=>S(A.id,{description:se.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(jt,{id:"multi-is-registered",checked:A.isRegistered,onCheckedChange:se=>S(A.id,{isRegistered:se===!0})}),e.jsx(k,{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(Ug,{className:"h-12 w-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"点击左侧卡片编辑"})]})})})]}),e.jsx(at,{children:e.jsx(C,{onClick:V,disabled:!O||j,children:j?"上传中...":`上传全部 (${E})`})})]})};return e.jsx(Qs,{open:l,onOpenChange:i,children:e.jsxs(qs,{className:"max-w-3xl max-h-[90vh] overflow-hidden",children:[e.jsxs(Gs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(_r,{className:"h-5 w-5"}),o==="select"&&"上传表情包 - 选择文件",o==="edit-single"&&"上传表情包 - 填写信息",o==="edit-multiple"&&"上传表情包 - 批量编辑"]}),e.jsxs(Ws,{children:[o==="select"&&"支持 JPG、PNG、GIF、WebP 格式,单个文件最大 10MB,可同时上传多个文件",o==="edit-single"&&"请填写表情包的情感标签(必填)和描述",o==="edit-multiple"&&"点击左侧卡片编辑每个表情包的信息,情感标签为必填项"]})]}),e.jsxs("div",{className:"overflow-y-auto pr-1",children:[o==="select"&&z(),o==="edit-single"&&_(),o==="edit-multiple"&&T()]})]})})}const Yl="/api/webui/expression";async function F2(){const l=await we(`${Yl}/chats`,{});if(!l.ok){const i=await l.json();throw new Error(i.detail||"获取聊天列表失败")}return l.json()}async function I2(l){const i=new URLSearchParams;l.page&&i.append("page",l.page.toString()),l.page_size&&i.append("page_size",l.page_size.toString()),l.search&&i.append("search",l.search),l.chat_id&&i.append("chat_id",l.chat_id);const r=await we(`${Yl}/list?${i}`,{});if(!r.ok){const o=await r.json();throw new Error(o.detail||"获取表达方式列表失败")}return r.json()}async function Q2(l){const i=await we(`${Yl}/${l}`,{});if(!i.ok){const r=await i.json();throw new Error(r.detail||"获取表达方式详情失败")}return i.json()}async function Y2(l){const i=await we(`${Yl}/`,{method:"POST",body:JSON.stringify(l)});if(!i.ok){const r=await i.json();throw new Error(r.detail||"创建表达方式失败")}return i.json()}async function K2(l,i){const r=await we(`${Yl}/${l}`,{method:"PATCH",body:JSON.stringify(i)});if(!r.ok){const o=await r.json();throw new Error(o.detail||"更新表达方式失败")}return r.json()}async function X2(l){const i=await we(`${Yl}/${l}`,{method:"DELETE"});if(!i.ok){const r=await i.json();throw new Error(r.detail||"删除表达方式失败")}return i.json()}async function P2(l){const i=await we(`${Yl}/batch/delete`,{method:"POST",body:JSON.stringify({ids:l})});if(!i.ok){const r=await i.json();throw new Error(r.detail||"批量删除表达方式失败")}return i.json()}async function J2(){const l=await we(`${Yl}/stats/summary`,{});if(!l.ok){const i=await l.json();throw new Error(i.detail||"获取统计数据失败")}return l.json()}function Z2(){const[l,i]=m.useState([]),[r,o]=m.useState(!0),[u,x]=m.useState(0),[h,f]=m.useState(1),[g,j]=m.useState(20),[v,y]=m.useState(""),[b,S]=m.useState(null),[w,O]=m.useState(!1),[A,D]=m.useState(!1),[V,z]=m.useState(!1),[_,T]=m.useState(null),[$,E]=m.useState(new Set),[se,te]=m.useState(!1),[ne,ue]=m.useState(""),[Se,oe]=m.useState({total:0,recent_7days:0,chat_count:0,top_chats:{}}),[je,be]=m.useState([]),[U,P]=m.useState(new Map),{toast:X}=Ks(),L=async()=>{try{o(!0);const le=await I2({page:h,page_size:g,search:v||void 0});i(le.data),x(le.total)}catch(le){X({title:"加载失败",description:le instanceof Error?le.message:"无法加载表达方式",variant:"destructive"})}finally{o(!1)}},B=async()=>{try{const le=await J2();le?.data&&oe(le.data)}catch(le){console.error("加载统计数据失败:",le)}},_e=async()=>{try{const le=await F2();if(le?.data){be(le.data);const qe=new Map;le.data.forEach(We=>{qe.set(We.chat_id,We.chat_name)}),P(qe)}}catch(le){console.error("加载聊天列表失败:",le)}},Ne=le=>U.get(le)||le;m.useEffect(()=>{L(),B(),_e()},[h,g,v]);const Ce=async le=>{try{const qe=await Q2(le.id);S(qe.data),O(!0)}catch(qe){X({title:"加载详情失败",description:qe instanceof Error?qe.message:"无法加载表达方式详情",variant:"destructive"})}},ve=le=>{S(le),D(!0)},ze=async le=>{try{await X2(le.id),X({title:"删除成功",description:`已删除表达方式: ${le.situation}`}),T(null),L(),B()}catch(qe){X({title:"删除失败",description:qe instanceof Error?qe.message:"无法删除表达方式",variant:"destructive"})}},Q=le=>{const qe=new Set($);qe.has(le)?qe.delete(le):qe.add(le),E(qe)},xe=()=>{$.size===l.length&&l.length>0?E(new Set):E(new Set(l.map(le=>le.id)))},Te=async()=>{try{await P2(Array.from($)),X({title:"批量删除成功",description:`已删除 ${$.size} 个表达方式`}),E(new Set),te(!1),L(),B()}catch(le){X({title:"批量删除失败",description:le instanceof Error?le.message:"无法批量删除表达方式",variant:"destructive"})}},J=()=>{const le=parseInt(ne),qe=Math.ceil(u/g);le>=1&&le<=qe?(f(le),ue("")):X({title:"无效的页码",description:`请输入1-${qe}之间的页码`,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(Fl,{className:"h-8 w-8",strokeWidth:2}),"表达方式管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦的表达方式和话术模板"})]}),e.jsxs(C,{onClick:()=>z(!0),className:"gap-2",children:[e.jsx(ut,{className:"h-4 w-4"}),"新增表达方式"]})]})}),e.jsx(Ze,{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:Se.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:Se.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:Se.chat_count})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx(k,{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($t,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{id:"search",placeholder:"搜索情境、风格或上下文...",value:v,onChange:le=>y(le.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:$.size>0&&e.jsxs("span",{children:["已选择 ",$.size," 个表达方式"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ue,{value:g.toString(),onValueChange:le=>{j(parseInt(le)),f(1),E(new Set)},children:[e.jsx(Re,{id:"page-size",className:"w-20",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"10",children:"10"}),e.jsx(ee,{value:"20",children:"20"}),e.jsx(ee,{value:"50",children:"50"}),e.jsx(ee,{value:"100",children:"100"})]})]}),$.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>E(new Set),children:"取消选择"}),e.jsxs(C,{variant:"destructive",size:"sm",onClick:()=>te(!0),children:[e.jsx(es,{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(bn,{children:[e.jsx(Nn,{children:e.jsxs(gt,{children:[e.jsx(Je,{className:"w-12",children:e.jsx(jt,{checked:$.size===l.length&&l.length>0,onCheckedChange:xe})}),e.jsx(Je,{children:"情境"}),e.jsx(Je,{children:"风格"}),e.jsx(Je,{children:"聊天"}),e.jsx(Je,{className:"text-right",children:"操作"})]})}),e.jsx(yn,{children:r?e.jsx(gt,{children:e.jsx(Qe,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):l.length===0?e.jsx(gt,{children:e.jsx(Qe,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):l.map(le=>e.jsxs(gt,{children:[e.jsx(Qe,{children:e.jsx(jt,{checked:$.has(le.id),onCheckedChange:()=>Q(le.id)})}),e.jsx(Qe,{className:"font-medium max-w-xs truncate",children:le.situation}),e.jsx(Qe,{className:"max-w-xs truncate",children:le.style}),e.jsx(Qe,{className:"max-w-[200px] truncate",title:Ne(le.chat_id),style:{wordBreak:"keep-all"},children:e.jsx("span",{className:"whitespace-nowrap overflow-hidden text-ellipsis block",children:Ne(le.chat_id)})}),e.jsx(Qe,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(C,{variant:"default",size:"sm",onClick:()=>ve(le),children:[e.jsx(pn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(C,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>Ce(le),title:"查看详情",children:e.jsx(Gt,{className:"h-4 w-4"})}),e.jsxs(C,{size:"sm",onClick:()=>T(le),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(es,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},le.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?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(le=>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(jt,{checked:$.has(le.id),onCheckedChange:()=>Q(le.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:le.situation,children:le.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:le.style,children:le.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(le.chat_id),style:{wordBreak:"keep-all"},children:Ne(le.chat_id)})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>ve(le),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(pn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>Ce(le),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:e.jsx(Gt,{className:"h-3 w-3"})}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>T(le),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(es,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},le.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/g)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(vi,{className:"h-4 w-4"})}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(pl,{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(ie,{type:"number",value:ne,onChange:le=>ue(le.target.value),onKeyDown:le=>le.key==="Enter"&&J(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(u/g)}),e.jsx(C,{variant:"outline",size:"sm",onClick:J,disabled:!ne,className:"h-8",children:"跳转"})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(u/g),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ya,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(u/g)),disabled:h>=Math.ceil(u/g),className:"hidden sm:flex",children:e.jsx(bi,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(W2,{expression:b,open:w,onOpenChange:O,chatNameMap:U}),e.jsx(e_,{open:V,onOpenChange:z,chatList:je,onSuccess:()=>{L(),B(),z(!1)}}),e.jsx(s_,{expression:b,open:A,onOpenChange:D,chatList:je,onSuccess:()=>{L(),B(),D(!1)}}),e.jsx(js,{open:!!_,onOpenChange:()=>T(null),children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:['确定要删除表达方式 "',_?.situation,'" 吗? 此操作不可撤销。']})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>_&&ze(_),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(t_,{open:se,onOpenChange:te,onConfirm:Te,count:$.size})]})}function W2({expression:l,open:i,onOpenChange:r,chatNameMap:o}){if(!l)return null;const u=h=>h?new Date(h*1e3).toLocaleString("zh-CN"):"-",x=h=>o.get(h)||h;return e.jsx(Qs,{open:i,onOpenChange:r,children:e.jsxs(qs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"表达方式详情"}),e.jsx(Ws,{children:"查看表达方式的完整信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(hr,{label:"情境",value:l.situation}),e.jsx(hr,{label:"风格",value:l.style}),e.jsx(hr,{label:"聊天",value:x(l.chat_id)}),e.jsx(hr,{icon:pi,label:"记录ID",value:l.id.toString(),mono:!0})]}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsx(hr,{icon:xi,label:"创建时间",value:u(l.create_date)})})]}),e.jsx(at,{children:e.jsx(C,{onClick:()=>r(!1),children:"关闭"})})]})})}function hr({icon:l,label:i,value:r,mono:o=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(k,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[l&&e.jsx(l,{className:"h-3 w-3"}),i]}),e.jsx("div",{className:H("text-sm",o&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function e_({open:l,onOpenChange:i,chatList:r,onSuccess:o}){const[u,x]=m.useState({situation:"",style:"",chat_id:""}),[h,f]=m.useState(!1),{toast:g}=Ks(),j=async()=>{if(!u.situation||!u.style||!u.chat_id){g({title:"验证失败",description:"请填写必填字段:情境、风格和聊天",variant:"destructive"});return}try{f(!0),await Y2(u),g({title:"创建成功",description:"表达方式已创建"}),x({situation:"",style:"",chat_id:""}),o()}catch(v){g({title:"创建失败",description:v instanceof Error?v.message:"无法创建表达方式",variant:"destructive"})}finally{f(!1)}};return e.jsx(Qs,{open:l,onOpenChange:i,children:e.jsxs(qs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"新增表达方式"}),e.jsx(Ws,{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(k,{htmlFor:"situation",children:["情境 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ie,{id:"situation",value:u.situation,onChange:v=>x({...u,situation:v.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{htmlFor:"style",children:["风格 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ie,{id:"style",value:u.style,onChange:v=>x({...u,style:v.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Ue,{value:u.chat_id,onValueChange:v=>x({...u,chat_id:v}),children:[e.jsx(Re,{children:e.jsx(Be,{placeholder:"选择关联的聊天"})}),e.jsx(Le,{children:r.map(v=>e.jsx(ee,{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(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(C,{onClick:j,disabled:h,children:h?"创建中...":"创建"})]})]})})}function s_({expression:l,open:i,onOpenChange:r,chatList:o,onSuccess:u}){const[x,h]=m.useState({}),[f,g]=m.useState(!1),{toast:j}=Ks();m.useEffect(()=>{l&&h({situation:l.situation,style:l.style,chat_id:l.chat_id})},[l]);const v=async()=>{if(l)try{g(!0),await K2(l.id,x),j({title:"保存成功",description:"表达方式已更新"}),u()}catch(y){j({title:"保存失败",description:y instanceof Error?y.message:"无法更新表达方式",variant:"destructive"})}finally{g(!1)}};return l?e.jsx(Qs,{open:i,onOpenChange:r,children:e.jsxs(qs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"编辑表达方式"}),e.jsx(Ws,{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(k,{htmlFor:"edit_situation",children:"情境"}),e.jsx(ie,{id:"edit_situation",value:x.situation||"",onChange:y=>h({...x,situation:y.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"edit_style",children:"风格"}),e.jsx(ie,{id:"edit_style",value:x.style||"",onChange:y=>h({...x,style:y.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Ue,{value:x.chat_id||"",onValueChange:y=>h({...x,chat_id:y}),children:[e.jsx(Re,{children:e.jsx(Be,{placeholder:"选择关联的聊天"})}),e.jsx(Le,{children:o.map(y=>e.jsx(ee,{value:y.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[y.chat_name,y.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},y.chat_id))})]})]})]}),e.jsxs(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(C,{onClick:v,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}function t_({open:l,onOpenChange:i,onConfirm:r,count:o}){return e.jsx(js,{open:l,onOpenChange:i,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认批量删除"}),e.jsxs(xs,{children:["您即将删除 ",o," 个表达方式,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:r,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})}const gl="/api/webui/jargon";async function a_(){const l=await we(`${gl}/chats`,{});if(!l.ok){const i=await l.json();throw new Error(i.detail||"获取聊天列表失败")}return l.json()}async function l_(l){const i=new URLSearchParams;l.page&&i.append("page",l.page.toString()),l.page_size&&i.append("page_size",l.page_size.toString()),l.search&&i.append("search",l.search),l.chat_id&&i.append("chat_id",l.chat_id),l.is_jargon!==void 0&&l.is_jargon!==null&&i.append("is_jargon",l.is_jargon.toString()),l.is_global!==void 0&&i.append("is_global",l.is_global.toString());const r=await we(`${gl}/list?${i}`,{});if(!r.ok){const o=await r.json();throw new Error(o.detail||"获取黑话列表失败")}return r.json()}async function n_(l){const i=await we(`${gl}/${l}`,{});if(!i.ok){const r=await i.json();throw new Error(r.detail||"获取黑话详情失败")}return i.json()}async function i_(l){const i=await we(`${gl}/`,{method:"POST",body:JSON.stringify(l)});if(!i.ok){const r=await i.json();throw new Error(r.detail||"创建黑话失败")}return i.json()}async function r_(l,i){const r=await we(`${gl}/${l}`,{method:"PATCH",body:JSON.stringify(i)});if(!r.ok){const o=await r.json();throw new Error(o.detail||"更新黑话失败")}return r.json()}async function c_(l){const i=await we(`${gl}/${l}`,{method:"DELETE"});if(!i.ok){const r=await i.json();throw new Error(r.detail||"删除黑话失败")}return i.json()}async function o_(l){const i=await we(`${gl}/batch/delete`,{method:"POST",body:JSON.stringify({ids:l})});if(!i.ok){const r=await i.json();throw new Error(r.detail||"批量删除黑话失败")}return i.json()}async function d_(){const l=await we(`${gl}/stats/summary`,{});if(!l.ok){const i=await l.json();throw new Error(i.detail||"获取黑话统计失败")}return l.json()}async function u_(l,i){const r=new URLSearchParams;l.forEach(u=>r.append("ids",u.toString())),r.append("is_jargon",i.toString());const o=await we(`${gl}/batch/set-jargon?${r}`,{method:"POST"});if(!o.ok){const u=await o.json();throw new Error(u.detail||"批量设置黑话状态失败")}return o.json()}function m_(){const[l,i]=m.useState([]),[r,o]=m.useState(!0),[u,x]=m.useState(0),[h,f]=m.useState(1),[g,j]=m.useState(20),[v,y]=m.useState(""),[b,S]=m.useState("all"),[w,O]=m.useState("all"),[A,D]=m.useState(null),[V,z]=m.useState(!1),[_,T]=m.useState(!1),[$,E]=m.useState(!1),[se,te]=m.useState(null),[ne,ue]=m.useState(new Set),[Se,oe]=m.useState(!1),[je,be]=m.useState(""),[U,P]=m.useState({total:0,confirmed_jargon:0,confirmed_not_jargon:0,pending:0,global_count:0,complete_count:0,chat_count:0,top_chats:{}}),[X,L]=m.useState([]),{toast:B}=Ks(),_e=async()=>{try{o(!0);const fe=await l_({page:h,page_size:g,search:v||void 0,chat_id:b==="all"?void 0:b,is_jargon:w==="all"?void 0:w==="true"?!0:w==="false"?!1:void 0});i(fe.data),x(fe.total)}catch(fe){B({title:"加载失败",description:fe instanceof Error?fe.message:"无法加载黑话列表",variant:"destructive"})}finally{o(!1)}},Ne=async()=>{try{const fe=await d_();fe?.data&&P(fe.data)}catch(fe){console.error("加载统计数据失败:",fe)}},Ce=async()=>{try{const fe=await a_();fe?.data&&L(fe.data)}catch(fe){console.error("加载聊天列表失败:",fe)}};m.useEffect(()=>{_e(),Ne(),Ce()},[h,g,v,b,w]);const ve=async fe=>{try{const ls=await n_(fe.id);D(ls.data),z(!0)}catch(ls){B({title:"加载详情失败",description:ls instanceof Error?ls.message:"无法加载黑话详情",variant:"destructive"})}},ze=fe=>{D(fe),T(!0)},Q=async fe=>{try{await c_(fe.id),B({title:"删除成功",description:`已删除黑话: ${fe.content}`}),te(null),_e(),Ne()}catch(ls){B({title:"删除失败",description:ls instanceof Error?ls.message:"无法删除黑话",variant:"destructive"})}},xe=fe=>{const ls=new Set(ne);ls.has(fe)?ls.delete(fe):ls.add(fe),ue(ls)},Te=()=>{ne.size===l.length&&l.length>0?ue(new Set):ue(new Set(l.map(fe=>fe.id)))},J=async()=>{try{await o_(Array.from(ne)),B({title:"批量删除成功",description:`已删除 ${ne.size} 个黑话`}),ue(new Set),oe(!1),_e(),Ne()}catch(fe){B({title:"批量删除失败",description:fe instanceof Error?fe.message:"无法批量删除黑话",variant:"destructive"})}},le=async fe=>{try{await u_(Array.from(ne),fe),B({title:"操作成功",description:`已将 ${ne.size} 个词条设为${fe?"黑话":"非黑话"}`}),ue(new Set),_e(),Ne()}catch(ls){B({title:"操作失败",description:ls instanceof Error?ls.message:"批量设置失败",variant:"destructive"})}},qe=()=>{const fe=parseInt(je),ls=Math.ceil(u/g);fe>=1&&fe<=ls?(f(fe),be("")):B({title:"无效的页码",description:`请输入1-${ls}之间的页码`,variant:"destructive"})},We=fe=>fe===!0?e.jsxs(Ye,{variant:"default",className:"bg-green-600 hover:bg-green-700",children:[e.jsx(ea,{className:"h-3 w-3 mr-1"}),"是黑话"]}):fe===!1?e.jsxs(Ye,{variant:"secondary",children:[e.jsx(fl,{className:"h-3 w-3 mr-1"}),"非黑话"]}):e.jsxs(Ye,{variant:"outline",children:[e.jsx(Rg,{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(Qy,{className:"h-8 w-8",strokeWidth:2}),"黑话管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦学习到的黑话和俚语"})]}),e.jsxs(C,{onClick:()=>E(!0),className:"gap-2",children:[e.jsx(ut,{className:"h-4 w-4"}),"新增黑话"]})]})}),e.jsx(Ze,{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:U.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:U.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:U.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:U.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:U.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:U.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:U.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(k,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{id:"search",placeholder:"搜索内容、含义...",value:v,onChange:fe=>y(fe.target.value),className:"pl-9"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(k,{children:"聊天筛选"}),e.jsxs(Ue,{value:b,onValueChange:S,children:[e.jsx(Re,{children:e.jsx(Be,{placeholder:"全部聊天"})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"all",children:"全部聊天"}),X.map(fe=>e.jsx(ee,{value:fe.chat_id,children:fe.chat_name},fe.chat_id))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(k,{children:"状态筛选"}),e.jsxs(Ue,{value:w,onValueChange:O,children:[e.jsx(Re,{children:e.jsx(Be,{placeholder:"全部状态"})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"all",children:"全部状态"}),e.jsx(ee,{value:"true",children:"是黑话"}),e.jsx(ee,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(k,{htmlFor:"page-size",children:"每页显示"}),e.jsxs(Ue,{value:g.toString(),onValueChange:fe=>{j(parseInt(fe)),f(1),ue(new Set)},children:[e.jsx(Re,{id:"page-size",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"10",children:"10"}),e.jsx(ee,{value:"20",children:"20"}),e.jsx(ee,{value:"50",children:"50"}),e.jsx(ee,{value:"100",children:"100"})]})]})]})]}),ne.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:["已选择 ",ne.size," 个"]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>le(!0),children:[e.jsx(ea,{className:"h-4 w-4 mr-1"}),"标记为黑话"]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>le(!1),children:[e.jsx(fl,{className:"h-4 w-4 mr-1"}),"标记为非黑话"]}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>ue(new Set),children:"取消选择"}),e.jsxs(C,{variant:"destructive",size:"sm",onClick:()=>oe(!0),children:[e.jsx(es,{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(bn,{children:[e.jsx(Nn,{children:e.jsxs(gt,{children:[e.jsx(Je,{className:"w-12",children:e.jsx(jt,{checked:ne.size===l.length&&l.length>0,onCheckedChange:Te})}),e.jsx(Je,{children:"内容"}),e.jsx(Je,{children:"含义"}),e.jsx(Je,{children:"聊天"}),e.jsx(Je,{children:"状态"}),e.jsx(Je,{className:"text-center",children:"次数"}),e.jsx(Je,{className:"text-right",children:"操作"})]})}),e.jsx(yn,{children:r?e.jsx(gt,{children:e.jsx(Qe,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):l.length===0?e.jsx(gt,{children:e.jsx(Qe,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):l.map(fe=>e.jsxs(gt,{children:[e.jsx(Qe,{children:e.jsx(jt,{checked:ne.has(fe.id),onCheckedChange:()=>xe(fe.id)})}),e.jsx(Qe,{className:"font-medium max-w-[200px]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[fe.is_global&&e.jsx("span",{title:"全局黑话",children:e.jsx(Wu,{className:"h-4 w-4 text-blue-500 flex-shrink-0"})}),e.jsx("span",{className:"truncate",title:fe.content,children:fe.content})]})}),e.jsx(Qe,{className:"max-w-[200px] truncate",title:fe.meaning||"",children:fe.meaning||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Qe,{className:"max-w-[150px] truncate",title:fe.chat_name||fe.chat_id,children:fe.chat_name||fe.chat_id}),e.jsx(Qe,{children:We(fe.is_jargon)}),e.jsx(Qe,{className:"text-center",children:fe.count}),e.jsx(Qe,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(C,{variant:"default",size:"sm",onClick:()=>ze(fe),children:[e.jsx(pn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(C,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>ve(fe),title:"查看详情",children:e.jsx(Gt,{className:"h-4 w-4"})}),e.jsxs(C,{size:"sm",onClick:()=>te(fe),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(es,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},fe.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?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(fe=>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(jt,{checked:ne.has(fe.id),onCheckedChange:()=>xe(fe.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:[fe.is_global&&e.jsx(Wu,{className:"h-4 w-4 text-blue-500 flex-shrink-0"}),e.jsx("h3",{className:"font-semibold text-sm break-all",children:fe.content})]}),fe.meaning&&e.jsx("p",{className:"text-sm text-muted-foreground break-all",children:fe.meaning}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:[We(fe.is_jargon),e.jsxs("span",{className:"text-muted-foreground",children:["次数: ",fe.count]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:["聊天: ",fe.chat_name||fe.chat_id]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>ze(fe),className:"text-xs px-2 py-1 h-auto",children:[e.jsx(pn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>ve(fe),className:"text-xs px-2 py-1 h-auto",children:e.jsx(Gt,{className:"h-3 w-3"})}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>te(fe),className:"text-xs px-2 py-1 h-auto text-destructive hover:text-destructive",children:[e.jsx(es,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},fe.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/g)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(vi,{className:"h-4 w-4"})}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(pl,{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(ie,{type:"number",value:je,onChange:fe=>be(fe.target.value),onKeyDown:fe=>fe.key==="Enter"&&qe(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(u/g)}),e.jsx(C,{variant:"outline",size:"sm",onClick:qe,disabled:!je,className:"h-8",children:"跳转"})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(u/g),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ya,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(u/g)),disabled:h>=Math.ceil(u/g),className:"hidden sm:flex",children:e.jsx(bi,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(x_,{jargon:A,open:V,onOpenChange:z}),e.jsx(h_,{open:$,onOpenChange:E,chatList:X,onSuccess:()=>{_e(),Ne(),E(!1)}}),e.jsx(f_,{jargon:A,open:_,onOpenChange:T,chatList:X,onSuccess:()=>{_e(),Ne(),T(!1)}}),e.jsx(js,{open:!!se,onOpenChange:()=>te(null),children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:['确定要删除黑话 "',se?.content,'" 吗?此操作不可撤销。']})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>se&&Q(se),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(js,{open:Se,onOpenChange:oe,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认批量删除"}),e.jsxs(xs,{children:["您即将删除 ",ne.size," 个黑话,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:J,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})]})}function x_({jargon:l,open:i,onOpenChange:r}){return l?e.jsx(Qs,{open:i,onOpenChange:r,children:e.jsxs(qs,{className:"max-w-2xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"黑话详情"}),e.jsx(Ws,{children:"查看黑话的完整信息"})]}),e.jsx(Ze,{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(Ju,{icon:pi,label:"记录ID",value:l.id.toString(),mono:!0}),e.jsx(Ju,{label:"使用次数",value:l.count.toString()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{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(k,{className:"text-xs text-muted-foreground",children:"原始内容"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:(()=>{try{const o=JSON.parse(l.raw_content);return Array.isArray(o)?o.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(k,{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(Tj,{content:l.meaning}):"-"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ju,{label:"聊天",value:l.chat_name||l.chat_id}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"flex items-center gap-2",children:[l.is_jargon===!0&&e.jsx(Ye,{variant:"default",className:"bg-green-600",children:"是黑话"}),l.is_jargon===!1&&e.jsx(Ye,{variant:"secondary",children:"非黑话"}),l.is_jargon===null&&e.jsx(Ye,{variant:"outline",children:"未判定"}),l.is_global&&e.jsx(Ye,{variant:"outline",className:"border-blue-500 text-blue-500",children:"全局"}),l.is_complete&&e.jsx(Ye,{variant:"outline",className:"border-purple-500 text-purple-500",children:"推断完成"})]})]})]}),l.inference_with_context&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{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(k,{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(at,{className:"flex-shrink-0",children:e.jsx(C,{onClick:()=>r(!1),children:"关闭"})})]})}):null}function Ju({icon:l,label:i,value:r,mono:o=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(k,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[l&&e.jsx(l,{className:"h-3 w-3"}),i]}),e.jsx("div",{className:H("text-sm",o&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function h_({open:l,onOpenChange:i,chatList:r,onSuccess:o}){const[u,x]=m.useState({content:"",meaning:"",chat_id:"",is_global:!1}),[h,f]=m.useState(!1),{toast:g}=Ks(),j=async()=>{if(!u.content||!u.chat_id){g({title:"验证失败",description:"请填写必填字段:内容和聊天",variant:"destructive"});return}try{f(!0),await i_(u),g({title:"创建成功",description:"黑话已创建"}),x({content:"",meaning:"",chat_id:"",is_global:!1}),o()}catch(v){g({title:"创建失败",description:v instanceof Error?v.message:"无法创建黑话",variant:"destructive"})}finally{f(!1)}};return e.jsx(Qs,{open:l,onOpenChange:i,children:e.jsxs(qs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"新增黑话"}),e.jsx(Ws,{children:"创建新的黑话记录"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{htmlFor:"content",children:["内容 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ie,{id:"content",value:u.content,onChange:v=>x({...u,content:v.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{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(k,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Ue,{value:u.chat_id,onValueChange:v=>x({...u,chat_id:v}),children:[e.jsx(Re,{children:e.jsx(Be,{placeholder:"选择关联的聊天"})}),e.jsx(Le,{children:r.map(v=>e.jsx(ee,{value:v.chat_id,children:v.chat_name},v.chat_id))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Fe,{id:"is_global",checked:u.is_global,onCheckedChange:v=>x({...u,is_global:v})}),e.jsx(k,{htmlFor:"is_global",children:"设为全局黑话"})]})]}),e.jsxs(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(C,{onClick:j,disabled:h,children:h?"创建中...":"创建"})]})]})})}function f_({jargon:l,open:i,onOpenChange:r,chatList:o,onSuccess:u}){const[x,h]=m.useState({}),[f,g]=m.useState(!1),{toast:j}=Ks();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{g(!0),await r_(l.id,x),j({title:"保存成功",description:"黑话已更新"}),u()}catch(y){j({title:"保存失败",description:y instanceof Error?y.message:"无法更新黑话",variant:"destructive"})}finally{g(!1)}};return l?e.jsx(Qs,{open:i,onOpenChange:r,children:e.jsxs(qs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"编辑黑话"}),e.jsx(Ws,{children:"修改黑话的信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"edit_content",children:"内容"}),e.jsx(ie,{id:"edit_content",value:x.content||"",onChange:y=>h({...x,content:y.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"edit_meaning",children:"含义"}),e.jsx(Ys,{id:"edit_meaning",value:x.meaning||"",onChange:y=>h({...x,meaning:y.target.value}),placeholder:"输入黑话含义",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Ue,{value:x.chat_id||"",onValueChange:y=>h({...x,chat_id:y}),children:[e.jsx(Re,{children:e.jsx(Be,{placeholder:"选择关联的聊天"})}),e.jsx(Le,{children:o.map(y=>e.jsx(ee,{value:y.chat_id,children:y.chat_name},y.chat_id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"黑话状态"}),e.jsxs(Ue,{value:x.is_jargon===null?"null":x.is_jargon?.toString()||"null",onValueChange:y=>h({...x,is_jargon:y==="null"?null:y==="true"}),children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"null",children:"未判定"}),e.jsx(ee,{value:"true",children:"是黑话"}),e.jsx(ee,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Fe,{id:"edit_is_global",checked:x.is_global,onCheckedChange:y=>h({...x,is_global:y})}),e.jsx(k,{htmlFor:"edit_is_global",children:"全局黑话"})]})]}),e.jsxs(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(C,{onClick:v,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}const Ni="/api/webui/person";async function p_(l){const i=new URLSearchParams;l.page&&i.append("page",l.page.toString()),l.page_size&&i.append("page_size",l.page_size.toString()),l.search&&i.append("search",l.search),l.is_known!==void 0&&i.append("is_known",l.is_known.toString()),l.platform&&i.append("platform",l.platform);const r=await we(`${Ni}/list?${i}`,{headers:Is()});if(!r.ok){const o=await r.json();throw new Error(o.detail||"获取人物列表失败")}return r.json()}async function g_(l){const i=await we(`${Ni}/${l}`,{headers:Is()});if(!i.ok){const r=await i.json();throw new Error(r.detail||"获取人物详情失败")}return i.json()}async function j_(l,i){const r=await we(`${Ni}/${l}`,{method:"PATCH",headers:Is(),body:JSON.stringify(i)});if(!r.ok){const o=await r.json();throw new Error(o.detail||"更新人物信息失败")}return r.json()}async function v_(l){const i=await we(`${Ni}/${l}`,{method:"DELETE",headers:Is()});if(!i.ok){const r=await i.json();throw new Error(r.detail||"删除人物信息失败")}return i.json()}async function b_(){const l=await we(`${Ni}/stats/summary`,{headers:Is()});if(!l.ok){const i=await l.json();throw new Error(i.detail||"获取统计数据失败")}return l.json()}async function N_(l){const i=await we(`${Ni}/batch/delete`,{method:"POST",headers:Is(),body:JSON.stringify({person_ids:l})});if(!i.ok){const r=await i.json();throw new Error(r.detail||"批量删除失败")}return i.json()}function y_(){const[l,i]=m.useState([]),[r,o]=m.useState(!0),[u,x]=m.useState(0),[h,f]=m.useState(1),[g,j]=m.useState(20),[v,y]=m.useState(""),[b,S]=m.useState(void 0),[w,O]=m.useState(void 0),[A,D]=m.useState(null),[V,z]=m.useState(!1),[_,T]=m.useState(!1),[$,E]=m.useState(null),[se,te]=m.useState({total:0,known:0,unknown:0,platforms:{}}),[ne,ue]=m.useState(new Set),[Se,oe]=m.useState(!1),[je,be]=m.useState(""),{toast:U}=Ks(),P=async()=>{try{o(!0);const J=await p_({page:h,page_size:g,search:v||void 0,is_known:b,platform:w});i(J.data),x(J.total)}catch(J){U({title:"加载失败",description:J instanceof Error?J.message:"无法加载人物信息",variant:"destructive"})}finally{o(!1)}},X=async()=>{try{const J=await b_();J?.data&&te(J.data)}catch(J){console.error("加载统计数据失败:",J)}};m.useEffect(()=>{P(),X()},[h,g,v,b,w]);const L=async J=>{try{const le=await g_(J.person_id);D(le.data),z(!0)}catch(le){U({title:"加载详情失败",description:le instanceof Error?le.message:"无法加载人物详情",variant:"destructive"})}},B=J=>{D(J),T(!0)},_e=async J=>{try{await v_(J.person_id),U({title:"删除成功",description:`已删除人物信息: ${J.person_name||J.nickname||J.user_id}`}),E(null),P(),X()}catch(le){U({title:"删除失败",description:le instanceof Error?le.message:"无法删除人物信息",variant:"destructive"})}},Ne=m.useMemo(()=>Object.keys(se.platforms),[se.platforms]),Ce=J=>{const le=new Set(ne);le.has(J)?le.delete(J):le.add(J),ue(le)},ve=()=>{ne.size===l.length&&l.length>0?ue(new Set):ue(new Set(l.map(J=>J.person_id)))},ze=()=>{if(ne.size===0){U({title:"未选择任何人物",description:"请先选择要删除的人物",variant:"destructive"});return}oe(!0)},Q=async()=>{try{const J=await N_(Array.from(ne));U({title:"批量删除完成",description:J.message}),ue(new Set),oe(!1),P(),X()}catch(J){U({title:"批量删除失败",description:J instanceof Error?J.message:"批量删除失败",variant:"destructive"})}},xe=()=>{const J=parseInt(je),le=Math.ceil(u/g);J>=1&&J<=le?(f(J),be("")):U({title:"无效的页码",description:`请输入1-${le}之间的页码`,variant:"destructive"})},Te=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(em,{className:"h-8 w-8",strokeWidth:2}),"人物信息管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦认识的所有人物信息"})]})})}),e.jsx(Ze,{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:se.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:se.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:se.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(k,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx($t,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{id:"search",placeholder:"搜索名称、昵称或用户ID...",value:v,onChange:J=>y(J.target.value),className:"pl-9"})]})]}),e.jsxs("div",{children:[e.jsx(k,{htmlFor:"filter-known",children:"认识状态"}),e.jsxs(Ue,{value:b===void 0?"all":b.toString(),onValueChange:J=>{S(J==="all"?void 0:J==="true"),f(1)},children:[e.jsx(Re,{id:"filter-known",className:"mt-1.5",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"all",children:"全部"}),e.jsx(ee,{value:"true",children:"已认识"}),e.jsx(ee,{value:"false",children:"未认识"})]})]})]}),e.jsxs("div",{children:[e.jsx(k,{htmlFor:"filter-platform",children:"平台"}),e.jsxs(Ue,{value:w||"all",onValueChange:J=>{O(J==="all"?void 0:J),f(1)},children:[e.jsx(Re,{id:"filter-platform",className:"mt-1.5",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"all",children:"全部平台"}),Ne.map(J=>e.jsxs(ee,{value:J,children:[J," (",se.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:ne.size>0&&e.jsxs("span",{children:["已选择 ",ne.size," 个人物"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ue,{value:g.toString(),onValueChange:J=>{j(parseInt(J)),f(1),ue(new Set)},children:[e.jsx(Re,{id:"page-size",className:"w-20",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"10",children:"10"}),e.jsx(ee,{value:"20",children:"20"}),e.jsx(ee,{value:"50",children:"50"}),e.jsx(ee,{value:"100",children:"100"})]})]}),ne.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>ue(new Set),children:"取消选择"}),e.jsxs(C,{variant:"destructive",size:"sm",onClick:ze,children:[e.jsx(es,{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(bn,{children:[e.jsx(Nn,{children:e.jsxs(gt,{children:[e.jsx(Je,{className:"w-12",children:e.jsx(jt,{checked:l.length>0&&ne.size===l.length,onCheckedChange:ve,"aria-label":"全选"})}),e.jsx(Je,{children:"状态"}),e.jsx(Je,{children:"名称"}),e.jsx(Je,{children:"昵称"}),e.jsx(Je,{children:"平台"}),e.jsx(Je,{children:"用户ID"}),e.jsx(Je,{children:"最后更新"}),e.jsx(Je,{className:"text-right",children:"操作"})]})}),e.jsx(yn,{children:r?e.jsx(gt,{children:e.jsx(Qe,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):l.length===0?e.jsx(gt,{children:e.jsx(Qe,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):l.map(J=>e.jsxs(gt,{children:[e.jsx(Qe,{children:e.jsx(jt,{checked:ne.has(J.person_id),onCheckedChange:()=>Ce(J.person_id),"aria-label":`选择 ${J.person_name||J.nickname||J.user_id}`})}),e.jsx(Qe,{children:e.jsx("div",{className:H("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(Qe,{className:"font-medium",children:J.person_name||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Qe,{children:J.nickname||"-"}),e.jsx(Qe,{children:J.platform}),e.jsx(Qe,{className:"font-mono text-sm",children:J.user_id}),e.jsx(Qe,{className:"text-sm text-muted-foreground",children:Te(J.last_know)}),e.jsx(Qe,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(C,{variant:"default",size:"sm",onClick:()=>L(J),children:[e.jsx(Gt,{className:"h-4 w-4 mr-1"}),"详情"]}),e.jsxs(C,{variant:"default",size:"sm",onClick:()=>B(J),children:[e.jsx(pn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsxs(C,{size:"sm",onClick:()=>E(J),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(es,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},J.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?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(jt,{checked:ne.has(J.person_id),onCheckedChange:()=>Ce(J.person_id),className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:H("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:Te(J.last_know)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>L(J),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(Gt,{className:"h-3 w-3 mr-1"}),"查看"]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>B(J),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(pn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>E(J),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(es,{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/g)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(vi,{className:"h-4 w-4"})}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(pl,{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(ie,{type:"number",value:je,onChange:J=>be(J.target.value),onKeyDown:J=>J.key==="Enter"&&xe(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(u/g)}),e.jsx(C,{variant:"outline",size:"sm",onClick:xe,disabled:!je,className:"h-8",children:"跳转"})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(u/g),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ya,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(u/g)),disabled:h>=Math.ceil(u/g),className:"hidden sm:flex",children:e.jsx(bi,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(w_,{person:A,open:V,onOpenChange:z}),e.jsx(__,{person:A,open:_,onOpenChange:T,onSuccess:()=>{P(),X(),T(!1)}}),e.jsx(js,{open:!!$,onOpenChange:()=>E(null),children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认删除"}),e.jsxs(xs,{children:['确定要删除人物信息 "',$?.person_name||$?.nickname||$?.user_id,'" 吗? 此操作不可撤销。']})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:()=>$&&_e($),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(js,{open:Se,onOpenChange:oe,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"确认批量删除"}),e.jsxs(xs,{children:["确定要删除选中的 ",ne.size," 个人物信息吗? 此操作不可撤销。"]})]}),e.jsxs(us,{children:[e.jsx(fs,{children:"取消"}),e.jsx(hs,{onClick:Q,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})})]})}function w_({person:l,open:i,onOpenChange:r}){if(!l)return null;const o=u=>u?new Date(u*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Qs,{open:i,onOpenChange:r,children:e.jsxs(qs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"人物详情"}),e.jsxs(Ws,{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(ml,{icon:oo,label:"人物名称",value:l.person_name}),e.jsx(ml,{icon:Fl,label:"昵称",value:l.nickname}),e.jsx(ml,{icon:pi,label:"用户ID",value:l.user_id,mono:!0}),e.jsx(ml,{icon:pi,label:"人物ID",value:l.person_id,mono:!0}),e.jsx(ml,{label:"平台",value:l.platform}),e.jsx(ml,{label:"状态",value:l.is_known?"已认识":"未认识"})]}),l.name_reason&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(k,{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(k,{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(k,{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(ml,{icon:xi,label:"认识时间",value:o(l.know_times)}),e.jsx(ml,{icon:xi,label:"首次记录",value:o(l.know_since)}),e.jsx(ml,{icon:xi,label:"最后更新",value:o(l.last_know)})]})]}),e.jsx(at,{children:e.jsx(C,{onClick:()=>r(!1),children:"关闭"})})]})})}function ml({icon:l,label:i,value:r,mono:o=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(k,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[l&&e.jsx(l,{className:"h-3 w-3"}),i]}),e.jsx("div",{className:H("text-sm",o&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function __({person:l,open:i,onOpenChange:r,onSuccess:o}){const[u,x]=m.useState({}),[h,f]=m.useState(!1),{toast:g}=Ks();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 j=async()=>{if(l)try{f(!0),await j_(l.person_id,u),g({title:"保存成功",description:"人物信息已更新"}),o()}catch(v){g({title:"保存失败",description:v instanceof Error?v.message:"无法更新人物信息",variant:"destructive"})}finally{f(!1)}};return l?e.jsx(Qs,{open:i,onOpenChange:r,children:e.jsxs(qs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"编辑人物信息"}),e.jsxs(Ws,{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(k,{htmlFor:"person_name",children:"人物名称"}),e.jsx(ie,{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(k,{htmlFor:"nickname",children:"昵称"}),e.jsx(ie,{id:"nickname",value:u.nickname||"",onChange:v=>x({...u,nickname:v.target.value}),placeholder:"昵称"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{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(k,{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(k,{htmlFor:"is_known",className:"text-base font-medium",children:"已认识"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"标记是否已经认识这个人"})]}),e.jsx(Fe,{id:"is_known",checked:u.is_known,onCheckedChange:v=>x({...u,is_known:v})})]})]}),e.jsxs(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(C,{onClick:j,disabled:h,children:h?"保存中...":"保存"})]})]})}):null}var S_=w0();const Bp=kN(S_),vm="/api/webui";async function C_(l=100,i="all"){const r=`${vm}/knowledge/graph?limit=${l}&node_type=${i}`,o=await fetch(r);if(!o.ok)throw new Error(`获取知识图谱失败: ${o.status}`);return o.json()}async function k_(){const l=await fetch(`${vm}/knowledge/stats`);if(!l.ok)throw new Error("获取知识图谱统计信息失败");return l.json()}async function T_(l){const i=await fetch(`${vm}/knowledge/search?query=${encodeURIComponent(l)}`);if(!i.ok)throw new Error("搜索知识节点失败");return i.json()}const Ej=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(mo,{type:"target",position:xo.Top}),e.jsx("div",{className:"font-semibold text-white text-sm truncate max-w-[200px]",title:l.content,children:l.label}),e.jsx(mo,{type:"source",position:xo.Bottom})]}));Ej.displayName="EntityNode";const zj=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(mo,{type:"target",position:xo.Top}),e.jsx("div",{className:"font-medium text-white text-xs truncate max-w-[150px]",title:l.content,children:l.label}),e.jsx(mo,{type:"source",position:xo.Bottom})]}));zj.displayName="ParagraphNode";const E_={entity:Ej,paragraph:zj};function z_(l,i){const r=new Bp.graphlib.Graph;r.setDefaultEdgeLabel(()=>({})),r.setGraph({rankdir:"TB",ranksep:100,nodesep:80});const o=[],u=[];return l.forEach(x=>{r.setNode(x.id,{width:150,height:50})}),i.forEach(x=>{r.setEdge(x.source,x.target)}),Bp.layout(r),l.forEach(x=>{const h=r.node(x.id);o.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}})}),i.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:o,edges:u}}function M_(){const l=ka(),[i,r]=m.useState(!1),[o,u]=m.useState(null),[x,h]=m.useState(""),[f,g]=m.useState("all"),[j,v]=m.useState(50),[y,b]=m.useState("50"),[S,w]=m.useState(!1),[O,A]=m.useState(!0),[D,V]=m.useState(!1),[z,_]=m.useState(!1),[T,$,E]=_0([]),[se,te,ne]=S0([]),[ue,Se]=m.useState(0),[oe,je]=m.useState(null),[be,U]=m.useState(null),{toast:P}=Ks(),X=m.useCallback(Q=>Q.type==="entity"?"#6366f1":Q.type==="paragraph"?"#10b981":"#6b7280",[]),L=m.useCallback(async(Q=!1)=>{try{if(!Q&&j>200){_(!0);return}r(!0);const[xe,Te]=await Promise.all([C_(j,f),k_()]);if(u(Te),xe.nodes.length===0){P({title:"提示",description:"知识库为空,请先导入知识数据"}),$([]),te([]);return}const{nodes:J,edges:le}=z_(xe.nodes,xe.edges);$(J),te(le),Se(J.length),Te&&Te.total_nodes>j&&P({title:"提示",description:`知识图谱包含 ${Te.total_nodes} 个节点,当前显示 ${J.length} 个`}),P({title:"加载成功",description:`已加载 ${J.length} 个节点,${le.length} 条边`})}catch(xe){console.error("加载知识图谱失败:",xe),P({title:"加载失败",description:xe instanceof Error?xe.message:"未知错误",variant:"destructive"})}finally{r(!1)}},[j,f,P]),B=m.useCallback(async()=>{if(!x.trim()){P({title:"提示",description:"请输入搜索关键词"});return}try{const Q=await T_(x);if(Q.length===0){P({title:"未找到",description:"没有找到匹配的节点"});return}const xe=new Set(Q.map(Te=>Te.id));$(Te=>Te.map(J=>({...J,style:{...J.style,opacity:xe.has(J.id)?1:.3,filter:xe.has(J.id)?"brightness(1.2)":"brightness(0.8)"}}))),P({title:"搜索完成",description:`找到 ${Q.length} 个匹配节点`})}catch(Q){console.error("搜索失败:",Q),P({title:"搜索失败",description:Q instanceof Error?Q.message:"未知错误",variant:"destructive"})}},[x,P]),_e=m.useCallback(()=>{$(Q=>Q.map(xe=>({...xe,style:{...xe.style,opacity:1,filter:"brightness(1)"}})))},[]),Ne=m.useCallback(()=>{A(!1),V(!0),L()},[L]),Ce=m.useCallback(()=>{_(!1),setTimeout(()=>{L(!0)},0)},[L]),ve=m.useCallback((Q,xe)=>{T.find(J=>J.id===xe.id)&&je({id:xe.id,type:xe.type,content:xe.data.content})},[T]);m.useEffect(()=>{O||D&&L()},[j,f,O,D]);const ze=m.useCallback((Q,xe)=>{const Te=T.find(qe=>qe.id===xe.source),J=T.find(qe=>qe.id===xe.target),le=se.find(qe=>qe.id===xe.id);Te&&J&&le&&U({source:{id:Te.id,type:Te.type,content:Te.data.content},target:{id:J.id,type:J.type,content:J.data.content},edge:{source:xe.source,target:xe.target,weight:parseFloat(xe.label||"0")}})},[T,se]);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:"可视化知识实体与关系网络"})]}),o&&e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(Ye,{variant:"outline",className:"gap-1",children:[e.jsx(ro,{className:"h-3 w-3"}),"节点: ",o.total_nodes]}),e.jsxs(Ye,{variant:"outline",className:"gap-1",children:[e.jsx(Bg,{className:"h-3 w-3"}),"边: ",o.total_edges]}),e.jsxs(Ye,{variant:"outline",className:"gap-1",children:[e.jsx(Ra,{className:"h-3 w-3"}),"实体: ",o.entity_nodes]}),e.jsxs(Ye,{variant:"outline",className:"gap-1",children:[e.jsx(Aa,{className:"h-3 w-3"}),"段落: ",o.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(ie,{placeholder:"搜索节点内容...",value:x,onChange:Q=>h(Q.target.value),onKeyDown:Q=>Q.key==="Enter"&&B(),className:"flex-1"}),e.jsx(C,{onClick:B,size:"sm",children:e.jsx($t,{className:"h-4 w-4"})}),e.jsx(C,{onClick:_e,variant:"outline",size:"sm",children:"重置"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Ue,{value:f,onValueChange:Q=>g(Q),children:[e.jsx(Re,{className:"w-[120px]",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"all",children:"全部节点"}),e.jsx(ee,{value:"entity",children:"仅实体"}),e.jsx(ee,{value:"paragraph",children:"仅段落"})]})]}),e.jsxs(Ue,{value:j===1e4?"all":S?"custom":j.toString(),onValueChange:Q=>{Q==="custom"?(w(!0),b(j.toString())):Q==="all"?(w(!1),v(1e4)):(w(!1),v(Number(Q)))},children:[e.jsx(Re,{className:"w-[120px]",children:e.jsx(Be,{})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"50",children:"50 节点"}),e.jsx(ee,{value:"100",children:"100 节点"}),e.jsx(ee,{value:"200",children:"200 节点"}),e.jsx(ee,{value:"500",children:"500 节点"}),e.jsx(ee,{value:"1000",children:"1000 节点"}),e.jsx(ee,{value:"all",children:"全部 (最多10000)"}),e.jsx(ee,{value:"custom",children:"自定义..."})]})]}),S&&e.jsx(ie,{type:"number",min:"50",value:y,onChange:Q=>b(Q.target.value),onBlur:()=>{const Q=parseInt(y);!isNaN(Q)&&Q>=50?v(Q):(b("50"),v(50))},onKeyDown:Q=>{if(Q.key==="Enter"){const xe=parseInt(y);!isNaN(xe)&&xe>=50?v(xe):(b("50"),v(50))}},placeholder:"最少50个",className:"w-[120px]"}),e.jsx(C,{onClick:()=>L(),variant:"outline",size:"sm",disabled:i,children:e.jsx(At,{className:H("h-4 w-4",i&&"animate-spin")})})]})]})]}),e.jsx("div",{className:"flex-1 relative",children:i?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(At,{className:"h-8 w-8 animate-spin mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"加载知识图谱中..."})]})}):T.length===0?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ro,{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(C0,{nodes:T,edges:se,onNodesChange:E,onEdgesChange:ne,onNodeClick:ve,onEdgeClick:ze,nodeTypes:E_,fitView:!0,minZoom:.05,maxZoom:1.5,defaultViewport:{x:0,y:0,zoom:.5},elevateNodesOnSelect:ue<=500,nodesDraggable:ue<=1e3,attributionPosition:"bottom-left",children:[e.jsx(k0,{variant:T0.Dots,gap:12,size:1}),e.jsx(E0,{}),ue<=500&&e.jsx(z0,{nodeColor:X,nodeBorderRadius:8,pannable:!0,zoomable:!0}),e.jsxs(M0,{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:"段落节点"})]}),ue>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:"已禁用动画"}),ue>500&&e.jsx("div",{children:"已禁用缩略图"})]})]})]})]})}),e.jsx(Qs,{open:!!oe,onOpenChange:Q=>!Q&&je(null),children:e.jsxs(qs,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(Gs,{children:e.jsx(Vs,{children:"节点详情"})}),oe&&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(Ye,{variant:oe.type==="entity"?"default":"secondary",children:oe.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:oe.id})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"内容"}),e.jsx(Ze,{className:"mt-1 h-40 p-3 bg-muted rounded",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:oe.content})})]})]})]})}),e.jsx(Qs,{open:!!be,onOpenChange:Q=>!Q&&U(null),children:e.jsxs(qs,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsx(Gs,{children:e.jsx(Vs,{children:"边详情"})}),be&&e.jsx(Ze,{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:be.source.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[be.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:be.target.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[be.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(Ye,{variant:"outline",className:"text-base font-mono",children:be.edge.weight.toFixed(4)})})]})]})})]})}),e.jsx(js,{open:O,onOpenChange:A,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"加载知识图谱"}),e.jsxs(xs,{children:["知识图谱的动态展示会消耗较多系统资源。",e.jsx("br",{}),"确定要加载知识图谱吗?"]})]}),e.jsxs(us,{children:[e.jsx(fs,{onClick:()=>l({to:"/"}),children:"取消 (返回首页)"}),e.jsx(hs,{onClick:Ne,children:"确认加载"})]})]})}),e.jsx(js,{open:z,onOpenChange:_,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"⚠️ 节点数量较多"}),e.jsx(xs,{asChild:!0,children:e.jsxs("div",{children:[e.jsxs("p",{children:["您正在尝试加载 ",e.jsx("strong",{className:"text-orange-600",children:j>=1e4?"全部 (最多10000个)":j})," 个节点。"]}),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(us,{children:[e.jsx(fs,{onClick:()=>{_(!1),j>200&&(v(50),w(!1))},children:"取消"}),e.jsx(hs,{onClick:Ce,className:"bg-orange-600 hover:bg-orange-700",children:"我了解风险,继续加载"})]})]})})]})}function Hp({className:l,classNames:i,showOutsideDays:r=!0,captionLayout:o="label",buttonVariant:u="ghost",formatters:x,components:h,...f}){const g=sj();return e.jsx(p0,{showOutsideDays:r,className:H("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:o,formatters:{formatMonthDropdown:j=>j.toLocaleString("default",{month:"short"}),...x},classNames:{root:H("w-fit",g.root),months:H("relative flex flex-col gap-4 md:flex-row",g.months),month:H("flex w-full flex-col gap-4",g.month),nav:H("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",g.nav),button_previous:H(Sr({variant:u}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",g.button_previous),button_next:H(Sr({variant:u}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",g.button_next),month_caption:H("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",g.month_caption),dropdowns:H("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",g.dropdowns),dropdown_root:H("has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border",g.dropdown_root),dropdown:H("bg-popover absolute inset-0 opacity-0",g.dropdown),caption_label:H("select-none font-medium",o==="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",g.caption_label),table:"w-full border-collapse",weekdays:H("flex",g.weekdays),weekday:H("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",g.weekday),week:H("mt-2 flex w-full",g.week),week_number_header:H("w-[--cell-size] select-none",g.week_number_header),week_number:H("text-muted-foreground select-none text-[0.8rem]",g.week_number),day:H("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",g.day),range_start:H("bg-accent rounded-l-md",g.range_start),range_middle:H("rounded-none",g.range_middle),range_end:H("bg-accent rounded-r-md",g.range_end),today:H("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",g.today),outside:H("text-muted-foreground aria-selected:text-muted-foreground",g.outside),disabled:H("text-muted-foreground opacity-50",g.disabled),hidden:H("invisible",g.hidden),...i},components:{Root:({className:j,rootRef:v,...y})=>e.jsx("div",{"data-slot":"calendar",ref:v,className:H(j),...y}),Chevron:({className:j,orientation:v,...y})=>v==="left"?e.jsx(pl,{className:H("size-4",j),...y}):v==="right"?e.jsx(Ya,{className:H("size-4",j),...y}):e.jsx(Fa,{className:H("size-4",j),...y}),DayButton:A_,WeekNumber:({children:j,...v})=>e.jsx("td",{...v,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:j})}),...h},...f})}function A_({className:l,day:i,modifiers:r,...o}){const u=sj(),x=m.useRef(null);return m.useEffect(()=>{r.focused&&x.current?.focus()},[r.focused]),e.jsx(C,{ref:x,variant:"ghost",size:"icon","data-day":i.date.toLocaleDateString(),"data-selected-single":r.selected&&!r.range_start&&!r.range_end&&!r.range_middle,"data-range-start":r.range_start,"data-range-end":r.range_end,"data-range-middle":r.range_middle,className:H("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),...o})}const eo={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 O_(){const[l,i]=m.useState([]),[r,o]=m.useState(""),[u,x]=m.useState("all"),[h,f]=m.useState("all"),[g,j]=m.useState(void 0),[v,y]=m.useState(void 0),[b,S]=m.useState(!0),[w,O]=m.useState(!1),[A,D]=m.useState("xs"),[V,z]=m.useState(4),[_,T]=m.useState(!1),$=m.useRef(null);m.useEffect(()=>{const B=xn.getAllLogs();i(B);const _e=xn.onLog(()=>{i(xn.getAllLogs())}),Ne=xn.onConnectionChange(Ce=>{O(Ce)});return()=>{_e(),Ne()}},[]);const E=m.useMemo(()=>{const B=new Set(l.map(_e=>_e.module).filter(_e=>_e&&_e.trim()!==""));return Array.from(B).sort()},[l]),se=B=>{switch(B){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"}},te=B=>{switch(B){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"}},ne=()=>{window.location.reload()},ue=()=>{xn.clearLogs(),i([])},Se=()=>{const B=be.map(ve=>`${ve.timestamp} [${ve.level.padEnd(8)}] [${ve.module}] ${ve.message}`).join(` `),_e=new Blob([B],{type:"text/plain;charset=utf-8"}),Ne=URL.createObjectURL(_e),Ce=document.createElement("a");Ce.href=Ne,Ce.download=`logs-${Du(new Date,"yyyy-MM-dd-HHmmss")}.txt`,Ce.click(),URL.revokeObjectURL(Ne)},oe=()=>{S(!b)},je=()=>{j(void 0),y(void 0)},be=m.useMemo(()=>l.filter(B=>{const _e=r===""||B.message.toLowerCase().includes(r.toLowerCase())||B.module.toLowerCase().includes(r.toLowerCase()),Ne=u==="all"||B.level===u,Ce=h==="all"||B.module===h;let ve=!0;if(g||v){const ze=new Date(B.timestamp);if(g){const Q=new Date(g);Q.setHours(0,0,0,0),ve=ve&&ze>=Q}if(v){const Q=new Date(v);Q.setHours(23,59,59,999),ve=ve&&ze<=Q}}return _e&&Ne&&Ce&&ve}),[l,r,u,h,g,v]),U=eo[A].rowHeight+V,P=vN({count:be.length,getScrollElement:()=>$.current,estimateSize:()=>U,overscan:50}),X=m.useRef(!1),L=m.useRef(be.length);return m.useEffect(()=>{const B=$.current;if(!B)return;const _e=()=>{if(X.current)return;const{scrollTop:Ne,scrollHeight:Ce,clientHeight:ve}=B,ze=Ce-Ne-ve;ze>100&&b?S(!1):ze<50&&!b&&S(!0)};return B.addEventListener("scroll",_e,{passive:!0}),()=>B.removeEventListener("scroll",_e)},[b]),m.useEffect(()=>{const B=be.length>L.current;L.current=be.length,b&&be.length>0&&B&&(X.current=!0,P.scrollToIndex(be.length-1,{align:"end",behavior:"auto"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{X.current=!1})}))},[be.length,b,P]),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:H("h-2 w-2 sm:h-2.5 sm:w-2.5 rounded-full",w?"bg-green-500 animate-pulse":"bg-red-500")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:w?"已连接":"未连接"})]})]}),e.jsx(Ve,{className:"p-2 sm:p-3",children:e.jsx(Tr,{open:_,onOpenChange:T,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($t,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(ie,{placeholder:"搜索日志...",value:r,onChange:B=>o(B.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(C,{variant:b?"default":"outline",size:"sm",onClick:oe,className:"h-8 px-2",title:b?"自动滚动":"已暂停",children:[b?e.jsx(Yy,{className:"h-3.5 w-3.5"}):e.jsx(Ky,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden sm:inline",children:b?"滚动":"暂停"})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:ue,className:"h-8 px-2",title:"清空日志",children:[e.jsx(es,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden md:inline",children:"清空"})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:Se,className:"h-8 px-2 hidden sm:flex",title:"导出日志",children:[e.jsx(Da,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden lg:inline",children:"导出"})]}),e.jsx(Er,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",className:"h-8 px-2",title:_?"收起筛选":"展开筛选",children:[e.jsx(lo,{className:"h-3.5 w-3.5"}),_?e.jsx(fi,{className:"h-3.5 w-3.5 ml-1"}):e.jsx(Fa,{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:[be.length," / ",l.length]}),e.jsx("span",{className:"ml-1",children:"条日志"})]}),e.jsxs(zr,{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(Ue,{value:u,onValueChange:x,children:[e.jsxs(Re,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(lo,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Be,{placeholder:"级别"})]}),e.jsxs(Le,{children:[e.jsx(ee,{value:"all",children:"全部级别"}),e.jsx(ee,{value:"DEBUG",children:"DEBUG"}),e.jsx(ee,{value:"INFO",children:"INFO"}),e.jsx(ee,{value:"WARNING",children:"WARNING"}),e.jsx(ee,{value:"ERROR",children:"ERROR"}),e.jsx(ee,{value:"CRITICAL",children:"CRITICAL"})]})]}),e.jsxs(Ue,{value:h,onValueChange:f,children:[e.jsxs(Re,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(lo,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Be,{placeholder:"模块"})]}),e.jsxs(Le,{children:[e.jsx(ee,{value:"all",children:"全部模块"}),E.map(B=>e.jsx(ee,{value:B,children:B},B))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(Ia,{children:[e.jsx(Qa,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",className:H("w-full sm:flex-1 justify-start text-left font-normal h-8",!g&&"text-muted-foreground"),children:[e.jsx(hp,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:g?Du(g,"PP",{locale:Zc}):"开始日期"})]})}),e.jsx(La,{className:"w-auto p-0",align:"start",children:e.jsx(Hp,{mode:"single",selected:g,onSelect:j,initialFocus:!0,locale:Zc})})]}),e.jsxs(Ia,{children:[e.jsx(Qa,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",className:H("w-full sm:flex-1 justify-start text-left font-normal h-8",!v&&"text-muted-foreground"),children:[e.jsx(hp,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:v?Du(v,"PP",{locale:Zc}):"结束日期"})]})}),e.jsx(La,{className:"w-auto p-0",align:"start",children:e.jsx(Hp,{mode:"single",selected:v,onSelect:y,initialFocus:!0,locale:Zc})})]}),(g||v)&&e.jsxs(C,{variant:"outline",size:"sm",onClick:je,className:"w-full sm:w-auto h-8",children:[e.jsx(fl,{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(Xy,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"字号"})]}),e.jsx("div",{className:"flex gap-1",children:Object.keys(eo).map(B=>e.jsx(C,{variant:A===B?"default":"outline",size:"sm",onClick:()=>D(B),className:"h-6 px-2 text-xs",children:eo[B].label},B))})]}),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(ma,{value:[V],onValueChange:([B])=>z(B),min:0,max:12,step:2,className:"flex-1"}),e.jsxs("span",{className:"text-xs text-muted-foreground w-7",children:[V,"px"]})]}),e.jsxs("div",{className:"flex gap-2 sm:hidden",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:ne,className:"flex-1 h-8",children:[e.jsx(At,{className:"h-3.5 w-3.5 mr-1"}),e.jsx("span",{className:"text-xs",children:"刷新"})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:Se,className:"flex-1 h-8",children:[e.jsx(Da,{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(Ve,{className:"bg-black dark:bg-gray-950 border-gray-800 dark:border-gray-900 h-full overflow-hidden",children:e.jsx("div",{ref:$,className:H("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:H("p-2 sm:p-3 font-mono relative",eo[A].class),style:{height:`${P.getTotalSize()}px`},children:be.length===0?e.jsx("div",{className:"text-gray-500 dark:text-gray-600 text-center py-8 text-xs sm:text-sm",children:"暂无日志数据"}):P.getVirtualItems().map(B=>{const _e=be[B.index];return e.jsxs("div",{"data-index":B.index,ref:P.measureElement,className:H("absolute top-0 left-0 w-full px-2 sm:px-3 rounded hover:bg-white/5 transition-colors",te(_e.level)),style:{transform:`translateY(${B.start}px)`,paddingTop:`${V/2}px`,paddingBottom:`${V/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:H("font-semibold text-[10px]",se(_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:H("flex-shrink-0 w-[65px] lg:w-[75px] font-semibold",se(_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})]})]},B.key)})})})})})]})}const D_="Mai-with-u",R_="plugin-repo",L_="main",U_="plugin_details.json";async function B_(){try{const l=await we("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:D_,repo:R_,branch:L_,file_path:U_})});if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const i=await l.json();if(!i.success||!i.data)throw new Error(i.error||"获取插件列表失败");return JSON.parse(i.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 H_(){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 $_(){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 q_(l,i,r){const o=l.split(".").map(f=>parseInt(f)||0),u=o[0]||0,x=o[1]||0,h=o[2]||0;if(r.version_majorparseInt(y)||0),g=f[0]||0,j=f[1]||0,v=f[2]||0;if(r.version_major>g||r.version_major===g&&r.version_minor>j||r.version_major===g&&r.version_minor===j&&r.version_patch>v)return!1}return!0}async function G_(){try{const l=await we("/api/webui/ws-token");if(!l.ok)return console.error("获取 WebSocket token 失败:",l.status),null;const i=await l.json();return i.success&&i.token?i.token:null}catch(l){return console.error("获取 WebSocket token 失败:",l),null}}async function V_(l,i){const r=await G_(),o=window.location.protocol==="https:"?"wss:":"ws:",u=window.location.host;let x=`${o}//${u}/api/webui/ws/plugin-progress`;r&&(x+=`?token=${encodeURIComponent(r)}`);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 g=JSON.parse(f.data);l(g)}catch(g){console.error("Failed to parse progress data:",g)}},h.onerror=f=>{console.error("Plugin progress WebSocket error:",f),i?.(f)},h.onclose=()=>{console.log("Plugin progress WebSocket disconnected")},h}catch(h){return console.error("创建 WebSocket 连接失败:",h),null}}async function gr(){try{const l=await we("/api/webui/plugins/installed",{headers:Is()});if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const i=await l.json();if(!i.success)throw new Error(i.message||"获取已安装插件列表失败");return i.plugins||[]}catch(l){return console.error("Failed to get installed plugins:",l),[]}}function so(l,i){return i.some(r=>r.id===l)}function to(l,i){const r=i.find(o=>o.id===l);if(r)return r.manifest?.version||r.version}async function F_(l,i,r="main"){const o=await we("/api/webui/plugins/install",{method:"POST",body:JSON.stringify({plugin_id:l,repository_url:i,branch:r})});if(!o.ok){const u=await o.json();throw new Error(u.detail||"安装失败")}return await o.json()}async function I_(l){const i=await we("/api/webui/plugins/uninstall",{method:"POST",body:JSON.stringify({plugin_id:l})});if(!i.ok){const r=await i.json();throw new Error(r.detail||"卸载失败")}return await i.json()}async function Q_(l,i,r="main"){const o=await we("/api/webui/plugins/update",{method:"POST",body:JSON.stringify({plugin_id:l,repository_url:i,branch:r})});if(!o.ok){const u=await o.json();throw new Error(u.detail||"更新失败")}return await o.json()}async function Y_(l){const i=await we(`/api/webui/plugins/config/${l}/schema`,{headers:Is()});if(!i.ok){const o=await i.json();throw new Error(o.detail||"获取配置 Schema 失败")}const r=await i.json();if(!r.success)throw new Error(r.message||"获取配置 Schema 失败");return r.schema}async function K_(l){const i=await we(`/api/webui/plugins/config/${l}`,{headers:Is()});if(!i.ok){const o=await i.json();throw new Error(o.detail||"获取配置失败")}const r=await i.json();if(!r.success)throw new Error(r.message||"获取配置失败");return r.config}async function X_(l,i){const r=await we(`/api/webui/plugins/config/${l}`,{method:"PUT",body:JSON.stringify({config:i})});if(!r.ok){const o=await r.json();throw new Error(o.detail||"保存配置失败")}return await r.json()}async function P_(l){const i=await we(`/api/webui/plugins/config/${l}/reset`,{method:"POST",headers:Is()});if(!i.ok){const r=await i.json();throw new Error(r.detail||"重置配置失败")}return await i.json()}async function J_(l){const i=await we(`/api/webui/plugins/config/${l}/toggle`,{method:"POST",headers:Is()});if(!i.ok){const r=await i.json();throw new Error(r.detail||"切换状态失败")}return await i.json()}const Dr="https://maibot-plugin-stats.maibot-webui.workers.dev";async function Mj(l){try{const i=await fetch(`${Dr}/stats/${l}`);return i.ok?await i.json():(console.error("Failed to fetch plugin stats:",i.statusText),null)}catch(i){return console.error("Error fetching plugin stats:",i),null}}async function Z_(l,i){try{const r=i||bm(),o=await fetch(`${Dr}/stats/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,user_id:r})}),u=await o.json();return o.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:o.ok?{success:!0,...u}:{success:!1,error:u.error||"点赞失败"}}catch(r){return console.error("Error liking plugin:",r),{success:!1,error:"网络错误"}}}async function W_(l,i){try{const r=i||bm(),o=await fetch(`${Dr}/stats/dislike`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,user_id:r})}),u=await o.json();return o.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:o.ok?{success:!0,...u}:{success:!1,error:u.error||"点踩失败"}}catch(r){return console.error("Error disliking plugin:",r),{success:!1,error:"网络错误"}}}async function eS(l,i,r,o){if(i<1||i>5)return{success:!1,error:"评分必须在 1-5 之间"};try{const u=o||bm(),x=await fetch(`${Dr}/stats/rate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,rating:i,comment:r,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 sS(l){try{const i=await fetch(`${Dr}/stats/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l})}),r=await i.json();return i.status===429?(console.warn("Download recording rate limited"),{success:!0}):i.ok?{success:!0,...r}:(console.error("Failed to record download:",r.error),{success:!1,error:r.error})}catch(i){return console.error("Error recording download:",i),{success:!1,error:"网络错误"}}}function tS(){const l=navigator,i=[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 r=0;for(let o=0;o{x(!0);const D=await Mj(l);D&&o(D),x(!1)};m.useEffect(()=>{S()},[l]);const w=async()=>{const D=await Z_(l);D.success?(b({title:"已点赞",description:"感谢你的支持!"}),S()):b({title:"点赞失败",description:D.error||"未知错误",variant:"destructive"})},O=async()=>{const D=await W_(l);D.success?(b({title:"已反馈",description:"感谢你的反馈!"}),S()):b({title:"操作失败",description:D.error||"未知错误",variant:"destructive"})},A=async()=>{if(h===0){b({title:"请选择评分",description:"至少选择 1 颗星",variant:"destructive"});return}const D=await eS(l,h,g||void 0);D.success?(b({title:"评分成功",description:"感谢你的评价!"}),y(!1),f(0),j(""),S()):b({title:"评分失败",description:D.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(Da,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(xl,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]})]}):r?i?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:`下载量: ${r.downloads.toLocaleString()}`,children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{children:r.downloads.toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`评分: ${r.rating.toFixed(1)} (${r.rating_count} 条评价)`,children:[e.jsx(xl,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:r.rating.toFixed(1)})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`点赞数: ${r.likes}`,children:[e.jsx(Lu,{className:"h-4 w-4"}),e.jsx("span",{children:r.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(Da,{className:"h-5 w-5 text-muted-foreground mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.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(xl,{className:"h-5 w-5 text-yellow-400 mb-1 fill-yellow-400"}),e.jsx("span",{className:"text-2xl font-bold",children:r.rating.toFixed(1)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[r.rating_count," 条评价"]})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Lu,{className:"h-5 w-5 text-green-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.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(fp,{className:"h-5 w-5 text-red-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.dislikes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点踩"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:w,children:[e.jsx(Lu,{className:"h-4 w-4 mr-1"}),"点赞"]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:O,children:[e.jsx(fp,{className:"h-4 w-4 mr-1"}),"点踩"]}),e.jsxs(Qs,{open:v,onOpenChange:y,children:[e.jsx(mm,{asChild:!0,children:e.jsxs(C,{variant:"default",size:"sm",children:[e.jsx(xl,{className:"h-4 w-4 mr-1"}),"评分"]})}),e.jsxs(qs,{children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"为插件评分"}),e.jsx(Ws,{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(D=>e.jsx("button",{onClick:()=>f(D),className:"focus:outline-none",children:e.jsx(xl,{className:`h-8 w-8 transition-colors ${D<=h?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-yellow-300"}`})},D))}),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:g,onChange:D=>j(D.target.value),placeholder:"分享你的使用体验...",rows:4,maxLength:500}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 text-right",children:[g.length," / 500"]})]})]}),e.jsxs(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>y(!1),children:"取消"}),e.jsx(C,{onClick:A,disabled:h===0,children:"提交评分"})]})]})]})]}),r.recent_ratings&&r.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:r.recent_ratings.map((D,V)=>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(z=>e.jsx(xl,{className:`h-3 w-3 ${z<=D.rating?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},z))}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(D.created_at).toLocaleDateString()})]}),D.comment&&e.jsx("p",{className:"text-sm text-muted-foreground",children:D.comment})]},V))})]})]}):null}const $p={"Group Management":"群组管理","Entertainment & Interaction":"娱乐互动","Utility Tools":"实用工具","Content Generation":"内容生成",Multimedia:"多媒体","External Integration":"外部集成","Data Analysis & Insights":"数据分析与洞察",Other:"其他"};function lS(){return e.jsx(jn,{children:e.jsx(nS,{})})}function nS(){const l=ka(),{triggerRestart:i,isRestarting:r}=Il(),[o,u]=m.useState(null),[x,h]=m.useState(""),[f,g]=m.useState("all"),[j,v]=m.useState("all"),[y,b]=m.useState(!0),[S,w]=m.useState([]),[O,A]=m.useState(!0),[D,V]=m.useState(null),[z,_]=m.useState(null),[T,$]=m.useState(null),[E,se]=m.useState(null),[,te]=m.useState([]),[ne,ue]=m.useState({}),[Se,oe]=m.useState(!1),[je,be]=m.useState(null),[U,P]=m.useState("main"),[X,L]=m.useState(""),[B,_e]=m.useState("preset"),[Ne,Ce]=m.useState(!1),{toast:ve}=Ks(),ze=async G=>{const Me=G.map(async Ee=>{try{const Ie=await Mj(Ee.id);return{id:Ee.id,stats:Ie}}catch(Ie){return console.warn(`Failed to load stats for ${Ee.id}:`,Ie),{id:Ee.id,stats:null}}}),re=await Promise.all(Me),pe={};re.forEach(({id:Ee,stats:Ie})=>{Ie&&(pe[Ee]=Ie)}),ue(pe)};m.useEffect(()=>{let G=null,Me=!1;return(async()=>{if(G=await V_(pe=>{Me||($(pe),pe.stage==="success"?setTimeout(()=>{Me||$(null)},2e3):pe.stage==="error"&&(A(!1),V(pe.error||"加载失败")))},pe=>{console.error("WebSocket error:",pe),Me||ve({title:"WebSocket 连接失败",description:"无法实时显示加载进度",variant:"destructive"})}),await new Promise(pe=>{if(!G){pe();return}const Ee=()=>{G&&G.readyState===WebSocket.OPEN?(console.log("WebSocket connected, starting to load plugins"),pe()):G&&G.readyState===WebSocket.CLOSED?(console.warn("WebSocket closed before loading plugins"),pe()):setTimeout(Ee,100)};Ee()}),!Me){const pe=await H_();_(pe),pe.installed||ve({title:"Git 未安装",description:pe.error||"请先安装 Git 才能使用插件安装功能",variant:"destructive"})}if(!Me){const pe=await $_();se(pe)}if(!Me)try{A(!0),V(null);const pe=await B_();if(!Me){const Ee=await gr();te(Ee);const Ie=pe.map($e=>{const Vt=so($e.id,Ee),_t=to($e.id,Ee);return{...$e,installed:Vt,installed_version:_t}});for(const $e of Ee)!Ie.some(_t=>_t.id===$e.id)&&$e.manifest&&Ie.push({id:$e.id,manifest:{manifest_version:$e.manifest.manifest_version||1,name:$e.manifest.name,version:$e.manifest.version,description:$e.manifest.description||"",author:$e.manifest.author,license:$e.manifest.license||"Unknown",host_application:$e.manifest.host_application,homepage_url:$e.manifest.homepage_url,repository_url:$e.manifest.repository_url,keywords:$e.manifest.keywords||[],categories:$e.manifest.categories||[],default_locale:$e.manifest.default_locale||"zh-CN",locales_path:$e.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!0,installed_version:$e.manifest.version,published_at:new Date().toISOString(),updated_at:new Date().toISOString()});w(Ie),ze(Ie)}}catch(pe){if(!Me){const Ee=pe instanceof Error?pe.message:"加载插件列表失败";V(Ee),ve({title:"加载失败",description:Ee,variant:"destructive"})}}finally{Me||A(!1)}})(),()=>{Me=!0,G&&G.close()}},[ve]);const Q=G=>{if(!G.installed&&E&&!xe(G))return e.jsxs(Ye,{variant:"destructive",className:"gap-1",children:[e.jsx(Ot,{className:"h-3 w-3"}),"不兼容"]});if(G.installed){const Me=G.installed_version?.trim(),re=G.manifest.version?.trim();if(Me!==re){const pe=Me?.split(".").map(Number)||[0,0,0],Ee=re?.split(".").map(Number)||[0,0,0];for(let Ie=0;Ie<3;Ie++){if((Ee[Ie]||0)>(pe[Ie]||0))return e.jsxs(Ye,{variant:"outline",className:"gap-1 text-orange-600 border-orange-600",children:[e.jsx(Ot,{className:"h-3 w-3"}),"可更新"]});if((Ee[Ie]||0)<(pe[Ie]||0))break}}return e.jsxs(Ye,{variant:"default",className:"gap-1",children:[e.jsx(aa,{className:"h-3 w-3"}),"已安装"]})}return null},xe=G=>!E||!G.manifest?.host_application?!0:q_(G.manifest.host_application.min_version,G.manifest.host_application.max_version,E),Te=G=>{if(!G.installed||!G.installed_version||!G.manifest?.version)return!1;const Me=G.installed_version.trim(),re=G.manifest.version.trim();if(Me===re)return!1;const pe=Me.split(".").map(Number),Ee=re.split(".").map(Number);for(let Ie=0;Ie<3;Ie++){if((Ee[Ie]||0)>(pe[Ie]||0))return!0;if((Ee[Ie]||0)<(pe[Ie]||0))return!1}return!1},J=S.filter(G=>{if(!G.manifest)return console.warn("[过滤] 跳过无 manifest 的插件:",G.id),!1;const Me=x===""||G.manifest.name?.toLowerCase().includes(x.toLowerCase())||G.manifest.description?.toLowerCase().includes(x.toLowerCase())||G.manifest.keywords&&G.manifest.keywords.some(Ie=>Ie.toLowerCase().includes(x.toLowerCase())),re=f==="all"||G.manifest.categories&&G.manifest.categories.includes(f);let pe=!0;j==="installed"?pe=G.installed===!0:j==="updates"&&(pe=G.installed===!0&&Te(G));const Ee=!y||!E||xe(G);return Me&&re&&pe&&Ee}),le=()=>{u(null)},qe=G=>{if(!z?.installed){ve({title:"无法安装",description:"Git 未安装",variant:"destructive"});return}if(E&&!xe(G)){ve({title:"无法安装",description:"插件与当前麦麦版本不兼容",variant:"destructive"});return}be(G),P("main"),L(""),_e("preset"),Ce(!1),oe(!0)},We=async()=>{if(!je)return;const G=B==="custom"?X:U;if(!G||G.trim()===""){ve({title:"分支名称不能为空",variant:"destructive"});return}try{oe(!1),await F_(je.id,je.manifest.repository_url||"",G),sS(je.id).catch(re=>{console.warn("Failed to record download:",re)}),ve({title:"安装成功",description:`${je.manifest.name} 已成功安装`});const Me=await gr();te(Me),w(re=>re.map(pe=>{if(pe.id===je.id){const Ee=so(pe.id,Me),Ie=to(pe.id,Me);return{...pe,installed:Ee,installed_version:Ie}}return pe}))}catch(Me){ve({title:"安装失败",description:Me instanceof Error?Me.message:"未知错误",variant:"destructive"})}finally{be(null)}},fe=async G=>{try{await I_(G.id),ve({title:"卸载成功",description:`${G.manifest.name} 已成功卸载`});const Me=await gr();te(Me),w(re=>re.map(pe=>{if(pe.id===G.id){const Ee=so(pe.id,Me),Ie=to(pe.id,Me);return{...pe,installed:Ee,installed_version:Ie}}return pe}))}catch(Me){ve({title:"卸载失败",description:Me instanceof Error?Me.message:"未知错误",variant:"destructive"})}},ls=async G=>{if(!z?.installed){ve({title:"无法更新",description:"Git 未安装",variant:"destructive"});return}try{const Me=await Q_(G.id,G.manifest.repository_url||"","main");ve({title:"更新成功",description:`${G.manifest.name} 已从 ${Me.old_version} 更新到 ${Me.new_version}`});const re=await gr();te(re),w(pe=>pe.map(Ee=>{if(Ee.id===G.id){const Ie=so(Ee.id,re),$e=to(Ee.id,re);return{...Ee,installed:Ie,installed_version:$e}}return Ee}))}catch(Me){ve({title:"更新失败",description:Me instanceof Error?Me.message:"未知错误",variant:"destructive"})}};return e.jsx(Ze,{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(C,{variant:"outline",onClick:()=>i(),disabled:r,children:[e.jsx(Hg,{className:`h-4 w-4 mr-2 ${r?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(C,{onClick:()=>l({to:"/plugin-mirrors"}),children:[e.jsx(Py,{className:"h-4 w-4 mr-2"}),"配置镜像源"]})]})]}),e.jsx(Ve,{className:"border-blue-200 bg-blue-50 dark:bg-blue-950/20 dark:border-blue-900",children:e.jsx(gs,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ra,{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:"重启麦麦"}),"才能使更改生效"]})]})})}),z&&!z.installed&&e.jsxs(Ve,{className:"border-orange-600 bg-orange-50 dark:bg-orange-950/20",children:[e.jsx(rs,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Oa,{className:"h-5 w-5 text-orange-600"}),e.jsxs("div",{children:[e.jsx(cs,{className:"text-lg text-orange-900 dark:text-orange-100",children:"Git 未安装"}),e.jsx(st,{className:"text-orange-800 dark:text-orange-200",children:z.error||"请先安装 Git 才能使用插件安装功能"})]})]})}),e.jsx(gs,{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(Ve,{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($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"搜索插件...",value:x,onChange:G=>h(G.target.value),className:"pl-9"})]}),e.jsxs(Ue,{value:f,onValueChange:g,children:[e.jsx(Re,{className:"w-full sm:w-[200px]",children:e.jsx(Be,{placeholder:"选择分类"})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"all",children:"全部分类"}),e.jsx(ee,{value:"Group Management",children:"群组管理"}),e.jsx(ee,{value:"Entertainment & Interaction",children:"娱乐互动"}),e.jsx(ee,{value:"Utility Tools",children:"实用工具"}),e.jsx(ee,{value:"Content Generation",children:"内容生成"}),e.jsx(ee,{value:"Multimedia",children:"多媒体"}),e.jsx(ee,{value:"External Integration",children:"外部集成"}),e.jsx(ee,{value:"Data Analysis & Insights",children:"数据分析与洞察"}),e.jsx(ee,{value:"Other",children:"其他"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(jt,{id:"compatible-only",checked:y,onCheckedChange:G=>b(G===!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(Sa,{value:j,onValueChange:v,className:"w-full",children:e.jsxs(xa,{className:"grid w-full grid-cols-3",children:[e.jsxs(is,{value:"all",children:["全部插件 (",S.filter(G=>{if(!G.manifest)return!1;const Me=x===""||G.manifest.name?.toLowerCase().includes(x.toLowerCase())||G.manifest.description?.toLowerCase().includes(x.toLowerCase())||G.manifest.keywords&&G.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(x.toLowerCase())),re=f==="all"||G.manifest.categories&&G.manifest.categories.includes(f),pe=!y||!E||xe(G);return Me&&re&&pe}).length,")"]}),e.jsxs(is,{value:"installed",children:["已安装 (",S.filter(G=>{if(!G.manifest)return!1;const Me=x===""||G.manifest.name?.toLowerCase().includes(x.toLowerCase())||G.manifest.description?.toLowerCase().includes(x.toLowerCase())||G.manifest.keywords&&G.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(x.toLowerCase())),re=f==="all"||G.manifest.categories&&G.manifest.categories.includes(f),pe=!y||!E||xe(G);return G.installed&&Me&&re&&pe}).length,")"]}),e.jsxs(is,{value:"updates",children:["可更新 (",S.filter(G=>{if(!G.manifest)return!1;const Me=x===""||G.manifest.name?.toLowerCase().includes(x.toLowerCase())||G.manifest.description?.toLowerCase().includes(x.toLowerCase())||G.manifest.keywords&&G.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(x.toLowerCase())),re=f==="all"||G.manifest.categories&&G.manifest.categories.includes(f),pe=!y||!E||xe(G);return G.installed&&Te(G)&&Me&&re&&pe}).length,")"]})]})}),T&&T.stage==="loading"&&T.operation==="fetch"&&e.jsx(Ve,{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(tt,{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:[T.progress,"%"]})]}),e.jsx(gn,{value:T.progress,className:"h-2"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:T.message}),T.total_plugins>0&&e.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:["已加载 ",T.loaded_plugins," / ",T.total_plugins," 个插件"]})]})}),T&&T.stage==="error"&&T.error&&e.jsx(Ve,{className:"border-destructive bg-destructive/10",children:e.jsx(rs,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Oa,{className:"h-5 w-5 text-destructive"}),e.jsxs("div",{children:[e.jsx(cs,{className:"text-lg text-destructive",children:"加载失败"}),e.jsx(st,{className:"text-destructive/80",children:T.error})]})]})})}),O?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(tt,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件列表中..."})]}):D?e.jsx(Ve,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Oa,{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:D}),e.jsx(C,{onClick:()=>window.location.reload(),children:"重新加载"})]})}):J.length===0?e.jsx(Ve,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx($t,{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(G=>e.jsxs(Ve,{className:"flex flex-col hover:shadow-lg transition-shadow h-full",children:[e.jsxs(rs,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx(cs,{className:"text-xl",children:G.manifest?.name||G.id}),e.jsxs("div",{className:"flex flex-col gap-1",children:[G.manifest?.categories&&G.manifest.categories[0]&&e.jsx(Ye,{variant:"secondary",className:"text-xs whitespace-nowrap",children:$p[G.manifest.categories[0]]||G.manifest.categories[0]}),Q(G)]})]}),e.jsx(st,{className:"line-clamp-2",children:G.manifest?.description||"无描述"})]}),e.jsx(gs,{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(Da,{className:"h-4 w-4"}),e.jsx("span",{children:(ne[G.id]?.downloads??G.downloads??0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(xl,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:(ne[G.id]?.rating??G.rating??0).toFixed(1)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[G.manifest?.keywords&&G.manifest.keywords.slice(0,3).map(Me=>e.jsx(Ye,{variant:"outline",className:"text-xs",children:Me},Me)),G.manifest?.keywords&&G.manifest.keywords.length>3&&e.jsxs(Ye,{variant:"outline",className:"text-xs",children:["+",G.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",G.manifest?.version||"unknown"," · ",G.manifest?.author?.name||"Unknown"]}),G.manifest?.host_application&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:"支持:"}),e.jsxs("span",{className:"font-medium",children:[G.manifest.host_application.min_version,G.manifest.host_application.max_version?` - ${G.manifest.host_application.max_version}`:" - 最新版本"]})]})]})]})}),e.jsx(tj,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center justify-end gap-2 w-full",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>u(G),children:"查看详情"}),G.installed?Te(G)?e.jsxs(C,{size:"sm",disabled:!z?.installed,title:z?.installed?void 0:"Git 未安装",onClick:()=>ls(G),children:[e.jsx(At,{className:"h-4 w-4 mr-1"}),"更新"]}):e.jsxs(C,{variant:"destructive",size:"sm",disabled:!z?.installed,title:z?.installed?void 0:"Git 未安装",onClick:()=>fe(G),children:[e.jsx(es,{className:"h-4 w-4 mr-1"}),"卸载"]}):e.jsxs(C,{size:"sm",disabled:!z?.installed||T?.operation==="install"||E!==null&&!xe(G),title:z?.installed?E!==null&&!xe(G)?`不兼容当前版本 (需要 ${G.manifest?.host_application?.min_version||"未知"}${G.manifest?.host_application?.max_version?` - ${G.manifest.host_application.max_version}`:"+"},当前 ${E?.version})`:void 0:"Git 未安装",onClick:()=>qe(G),children:[e.jsx(Da,{className:"h-4 w-4 mr-1"}),T?.operation==="install"&&T?.plugin_id===G.id?"安装中...":"安装"]})]})}),T&&(T.stage==="loading"||T.stage==="success"||T.stage==="error")&&T.operation!=="fetch"&&T.plugin_id===G.id&&e.jsx("div",{className:"px-6 pb-4 -mt-2",children:e.jsxs("div",{className:`space-y-2 p-3 rounded-lg border ${T.stage==="success"?"bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-900":T.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:[T.stage==="loading"?e.jsx(tt,{className:"h-3 w-3 animate-spin"}):T.stage==="success"?e.jsx(aa,{className:"h-3 w-3 text-green-600"}):e.jsx(Ot,{className:"h-3 w-3 text-red-600"}),e.jsx("span",{className:`text-xs font-medium ${T.stage==="success"?"text-green-700 dark:text-green-300":T.stage==="error"?"text-red-700 dark:text-red-300":""}`,children:T.stage==="loading"?e.jsxs(e.Fragment,{children:[T.operation==="install"&&"正在安装",T.operation==="uninstall"&&"正在卸载",T.operation==="update"&&"正在更新"]}):T.stage==="success"?e.jsxs(e.Fragment,{children:[T.operation==="install"&&"安装完成",T.operation==="uninstall"&&"卸载完成",T.operation==="update"&&"更新完成"]}):e.jsxs(e.Fragment,{children:[T.operation==="install"&&"安装失败",T.operation==="uninstall"&&"卸载失败",T.operation==="update"&&"更新失败"]})})]}),T.stage!=="error"&&e.jsxs("span",{className:`text-xs font-medium ${T.stage==="success"?"text-green-700 dark:text-green-300":""}`,children:[T.progress,"%"]})]}),T.stage!=="error"&&e.jsx(gn,{value:T.progress,className:`h-1.5 ${T.stage==="success"?"[&>div]:bg-green-500":""}`}),e.jsx("div",{className:`text-xs ${T.stage==="success"?"text-green-600 dark:text-green-400 truncate":T.stage==="error"?"text-red-600 dark:text-red-400":"text-muted-foreground truncate"}`,children:T.stage==="error"?T.error||T.message||"操作失败":T.message})]})})]},G.id))}),e.jsx(Qs,{open:o!==null,onOpenChange:le,children:o&&o.manifest&&e.jsx(qs,{className:"max-w-2xl max-h-[80vh] p-0 flex flex-col",children:e.jsx(Ze,{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-6",children:[e.jsx(Gs,{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(Vs,{className:"text-2xl",children:o.manifest.name}),e.jsxs(Ws,{children:["作者: ",o.manifest.author?.name||"Unknown",o.manifest.author?.url&&e.jsx("a",{href:o.manifest.author.url,target:"_blank",rel:"noopener noreferrer",className:"ml-2 text-primary hover:underline",children:e.jsx(ao,{className:"h-3 w-3 inline"})})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[o.manifest.categories&&o.manifest.categories[0]&&e.jsx(Ye,{variant:"secondary",children:$p[o.manifest.categories[0]]||o.manifest.categories[0]}),Q(o)]})]})}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(aS,{pluginId:o.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",o.manifest?.version||"unknown"]}),o.installed&&o.installed_version&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["已安装: v",o.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:(ne[o.id]?.downloads??o.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(xl,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(ne[o.id]?.rating??o.rating??0).toFixed(1)," (",ne[o.id]?.rating_count??o.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:o.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:[o.manifest.host_application?.min_version||"未知",o.manifest.host_application?.max_version?` - ${o.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:o.manifest.keywords&&o.manifest.keywords.map(G=>e.jsx(Ye,{variant:"outline",children:G},G))})]}),o.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:o.detailed_description})]}),!o.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:o.manifest.description||"无描述"})]}),e.jsxs("div",{className:"space-y-2",children:[o.manifest.homepage_url&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"主页: "}),e.jsx("a",{href:o.manifest.homepage_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:o.manifest.homepage_url})]}),o.manifest.repository_url&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"仓库: "}),e.jsx("a",{href:o.manifest.repository_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:o.manifest.repository_url})]})]})]}),e.jsxs(at,{children:[o.manifest.homepage_url&&e.jsxs(C,{onClick:()=>window.open(o.manifest.homepage_url,"_blank"),children:[e.jsx(ao,{className:"h-4 w-4 mr-2"}),"访问主页"]}),o.manifest.repository_url&&e.jsxs(C,{variant:"outline",onClick:()=>window.open(o.manifest.repository_url,"_blank"),children:[e.jsx(ao,{className:"h-4 w-4 mr-2"}),"查看仓库"]})]})]})})})}),e.jsx(Qs,{open:Se,onOpenChange:oe,children:e.jsxs(qs,{children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"安装插件"}),e.jsxs(Ws,{children:["安装 ",je?.manifest.name]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["版本: ",je?.manifest.version]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["作者: ",typeof je?.manifest.author=="string"?je.manifest.author:je?.manifest.author?.name]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(jt,{id:"advanced-options",checked:Ne,onCheckedChange:G=>Ce(G)}),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(Sa,{value:B,onValueChange:G=>_e(G),children:[e.jsxs(xa,{className:"grid w-full grid-cols-2",children:[e.jsx(is,{value:"preset",className:"text-xs",children:"预设分支"}),e.jsx(is,{value:"custom",className:"text-xs",children:"自定义分支"})]}),B==="preset"&&e.jsx("div",{className:"mt-3",children:e.jsxs(Ue,{value:U,onValueChange:P,children:[e.jsx(Re,{children:e.jsx(Be,{placeholder:"选择分支"})}),e.jsxs(Le,{children:[e.jsx(ee,{value:"main",children:"main (默认)"}),e.jsx(ee,{value:"master",children:"master"}),e.jsx(ee,{value:"dev",children:"dev (开发版)"}),e.jsx(ee,{value:"develop",children:"develop"}),e.jsx(ee,{value:"beta",children:"beta (测试版)"}),e.jsx(ee,{value:"stable",children:"stable (稳定版)"})]})]})}),B==="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:X,onChange:G=>L(G.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(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>oe(!1),children:"取消"}),e.jsxs(C,{onClick:We,children:[e.jsx(Da,{className:"h-4 w-4 mr-2"}),"安装"]})]})]})}),e.jsx(vn,{})]})})}function iS(){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($g,{className:"h-8 w-8",strokeWidth:2}),"模型分配预设市场"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"浏览和下载社区共享的模型分配预设配置"})]})})}),e.jsx(Ze,{className:"flex-1",children:e.jsx("div",{className:"flex items-center justify-center h-[calc(100vh-12rem)]",children:e.jsxs(Ve,{className:"max-w-2xl w-full border-dashed",children:[e.jsxs(rs,{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(Vl,{className:"h-16 w-16 text-muted-foreground"})}),e.jsx(cs,{className:"text-2xl",children:"功能开发中"}),e.jsx(st,{className:"text-base",children:"模型分配预设市场功能正在开发中,敬请期待!"})]}),e.jsx(gs,{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 rS({field:l,value:i,onChange:r}){const[o,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(k,{children:l.label}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]}),e.jsx(Fe,{checked:!!i,onCheckedChange:r,disabled:l.disabled})]});case"number":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:l.label}),e.jsx(ie,{type:"number",value:i??l.default,onChange:x=>r(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(k,{children:l.label}),e.jsx("span",{className:"text-sm text-muted-foreground",children:i??l.default})]}),e.jsx(ma,{value:[i??l.default],onValueChange:x=>r(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(k,{children:l.label}),e.jsxs(Ue,{value:String(i??l.default),onValueChange:r,disabled:l.disabled,children:[e.jsx(Re,{children:e.jsx(Be,{placeholder:l.placeholder??"请选择"})}),e.jsx(Le,{children:l.choices?.map(x=>e.jsx(ee,{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(k,{children:l.label}),e.jsx(Ys,{value:i??l.default,onChange:x=>r(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(k,{children:l.label}),e.jsxs("div",{className:"relative",children:[e.jsx(ie,{type:o?"text":"password",value:i??"",onChange:x=>r(x.target.value),placeholder:l.placeholder,disabled:l.disabled,className:"pr-10"}),e.jsx(C,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3",onClick:()=>u(!o),children:o?e.jsx(wr,{className:"h-4 w-4"}):e.jsx(Gt,{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(k,{children:l.label}),e.jsx(g1,{value:Array.isArray(i)?i:[],onChange:x=>r(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(k,{children:l.label}),e.jsx(ie,{type:"text",value:i??l.default??"",onChange:x=>r(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 qp({section:l,config:i,onChange:r}){const[o,u]=m.useState(!l.collapsed),x=Object.entries(l.fields).filter(([,h])=>!h.hidden).sort(([,h],[,f])=>h.order-f.order);return e.jsx(Tr,{open:o,onOpenChange:u,children:e.jsxs(Ve,{children:[e.jsx(Er,{asChild:!0,children:e.jsxs(rs,{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:[o?e.jsx(Fa,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Ya,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(cs,{className:"text-lg",children:l.title})]}),e.jsxs(Ye,{variant:"secondary",className:"text-xs",children:[x.length," 项"]})]}),l.description&&e.jsx(st,{className:"ml-6",children:l.description})]})}),e.jsx(zr,{children:e.jsx(gs,{className:"space-y-4 pt-0",children:x.map(([h,f])=>e.jsx(rS,{field:f,value:i[l.name]?.[h],onChange:g=>r(l.name,h,g),sectionName:l.name},h))})})]})})}function cS({plugin:l,onBack:i}){const{toast:r}=Ks(),{triggerRestart:o,isRestarting:u}=Il(),[x,h]=m.useState(null),[f,g]=m.useState({}),[j,v]=m.useState({}),[y,b]=m.useState(!0),[S,w]=m.useState(!1),[O,A]=m.useState(!1),[D,V]=m.useState(!1),z=m.useCallback(async()=>{b(!0);try{const[ne,ue]=await Promise.all([Y_(l.id),K_(l.id)]);h(ne),g(ue),v(JSON.parse(JSON.stringify(ue)))}catch(ne){r({title:"加载配置失败",description:ne instanceof Error?ne.message:"未知错误",variant:"destructive"})}finally{b(!1)}},[l.id,r]);m.useEffect(()=>{z()},[z]),m.useEffect(()=>{A(JSON.stringify(f)!==JSON.stringify(j))},[f,j]);const _=(ne,ue,Se)=>{g(oe=>({...oe,[ne]:{...oe[ne]||{},[ue]:Se}}))},T=async()=>{w(!0);try{await X_(l.id,f),v(JSON.parse(JSON.stringify(f))),r({title:"配置已保存",description:"更改将在插件重新加载后生效"})}catch(ne){r({title:"保存失败",description:ne instanceof Error?ne.message:"未知错误",variant:"destructive"})}finally{w(!1)}},$=async()=>{try{await P_(l.id),r({title:"配置已重置",description:"下次加载插件时将使用默认配置"}),V(!1),z()}catch(ne){r({title:"重置失败",description:ne instanceof Error?ne.message:"未知错误",variant:"destructive"})}},E=async()=>{try{const ne=await J_(l.id);r({title:ne.message,description:ne.note}),z()}catch(ne){r({title:"切换状态失败",description:ne instanceof Error?ne.message:"未知错误",variant:"destructive"})}};if(y)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(tt,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!x)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 space-y-4",children:[e.jsx(Ot,{className:"h-12 w-12 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"无法加载配置"}),e.jsxs(C,{onClick:i,variant:"outline",children:[e.jsx(hi,{className:"h-4 w-4 mr-2"}),"返回"]})]});const se=Object.values(x.sections).sort((ne,ue)=>ne.order-ue.order),te=f.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(C,{variant:"ghost",size:"icon",onClick:i,children:e.jsx(hi,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:x.plugin_info.name||l.manifest.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(Ye,{variant:te?"default":"secondary",children:te?"已启用":"已禁用"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["v",x.plugin_info.version||l.manifest.version]})]})]})]}),e.jsxs("div",{className:"flex gap-2 ml-10 sm:ml-0",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>o(),disabled:u,children:[e.jsx(Hg,{className:`h-4 w-4 mr-2 ${u?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:E,children:[e.jsx(Mr,{className:"h-4 w-4 mr-2"}),te?"禁用":"启用"]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>V(!0),children:[e.jsx(yr,{className:"h-4 w-4 mr-2"}),"重置"]}),e.jsxs(C,{size:"sm",onClick:T,disabled:!O||S,children:[S?e.jsx(tt,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ar,{className:"h-4 w-4 mr-2"}),"保存"]})]})]}),O&&e.jsx(Ve,{className:"border-orange-200 bg-orange-50 dark:bg-orange-950/20 dark:border-orange-900",children:e.jsx(gs,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ra,{className:"h-4 w-4 text-orange-600"}),e.jsx("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:"有未保存的更改"})]})})}),x.layout.type==="tabs"&&x.layout.tabs.length>0?e.jsxs(Sa,{defaultValue:x.layout.tabs[0]?.id,children:[e.jsx(xa,{children:x.layout.tabs.map(ne=>e.jsxs(is,{value:ne.id,children:[ne.title,ne.badge&&e.jsx(Ye,{variant:"secondary",className:"ml-2 text-xs",children:ne.badge})]},ne.id))}),x.layout.tabs.map(ne=>e.jsx(As,{value:ne.id,className:"space-y-4 mt-4",children:ne.sections.map(ue=>{const Se=x.sections[ue];return Se?e.jsx(qp,{section:Se,config:f,onChange:_},ue):null})},ne.id))]}):e.jsx("div",{className:"space-y-4",children:se.map(ne=>e.jsx(qp,{section:ne,config:f,onChange:_},ne.name))}),e.jsx(Qs,{open:D,onOpenChange:V,children:e.jsxs(qs,{children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"确认重置配置"}),e.jsx(Ws,{children:"这将删除当前配置文件,下次加载插件时将使用默认配置。此操作不可撤销。"})]}),e.jsxs(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>V(!1),children:"取消"}),e.jsx(C,{variant:"destructive",onClick:$,children:"确认重置"})]})]})})]})}function oS(){return e.jsx(jn,{children:e.jsx(dS,{})})}function dS(){const{toast:l}=Ks(),[i,r]=m.useState([]),[o,u]=m.useState(!0),[x,h]=m.useState(""),[f,g]=m.useState(null),j=async()=>{u(!0);try{const S=await gr();r(S)}catch(S){l({title:"加载插件列表失败",description:S instanceof Error?S.message:"未知错误",variant:"destructive"})}finally{u(!1)}};m.useEffect(()=>{j()},[]);const v=i.filter(S=>{const w=x.toLowerCase();return S.id.toLowerCase().includes(w)||S.manifest.name.toLowerCase().includes(w)||S.manifest.description?.toLowerCase().includes(w)}),y=i.length,b=0;return f?e.jsxs(e.Fragment,{children:[e.jsx(Ze,{className:"h-full",children:e.jsx("div",{className:"p-4 sm:p-6",children:e.jsx(cS,{plugin:f,onBack:()=>g(null)})})}),e.jsx(vn,{})]}):e.jsx(Ze,{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(C,{variant:"outline",size:"sm",onClick:j,children:[e.jsx(At,{className:`h-4 w-4 mr-2 ${o?"animate-spin":""}`}),"刷新"]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 xs:grid-cols-2 lg:grid-cols-3",children:[e.jsxs(Ve,{children:[e.jsxs(rs,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(cs,{className:"text-sm font-medium",children:"已安装插件"}),e.jsx(Vl,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(gs,{children:[e.jsx("div",{className:"text-2xl font-bold",children:i.length}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:o?"正在加载...":"个插件"})]})]}),e.jsxs(Ve,{children:[e.jsxs(rs,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(cs,{className:"text-sm font-medium",children:"已启用"}),e.jsx(aa,{className:"h-4 w-4 text-green-600"})]}),e.jsxs(gs,{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(Ve,{children:[e.jsxs(rs,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(cs,{className:"text-sm font-medium",children:"已禁用"}),e.jsx(Ot,{className:"h-4 w-4 text-orange-600"})]}),e.jsxs(gs,{children:[e.jsx("div",{className:"text-2xl font-bold",children:b}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"未激活的插件"})]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"搜索插件...",value:x,onChange:S=>h(S.target.value),className:"pl-9"})]}),e.jsxs(Ve,{children:[e.jsxs(rs,{children:[e.jsx(cs,{children:"已安装的插件"}),e.jsx(st,{children:"点击插件查看和编辑配置"})]}),e.jsx(gs,{children:o?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(tt,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):v.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 space-y-4",children:[e.jsx(Vl,{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:v.map(S=>e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg border hover:bg-muted/50 cursor-pointer transition-colors",onClick:()=>g(S),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(Vl,{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:S.manifest.name}),e.jsxs(Ye,{variant:"secondary",className:"text-xs flex-shrink-0",children:["v",S.manifest.version]})]}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:S.manifest.description||"暂无描述"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(C,{variant:"ghost",size:"sm",children:e.jsx(ji,{className:"h-4 w-4"})}),e.jsx(Ya,{className:"h-4 w-4 text-muted-foreground"})]})]},S.id))})})]})]})})}function uS(){const l=ka(),{toast:i}=Ks(),[r,o]=m.useState([]),[u,x]=m.useState(!0),[h,f]=m.useState(null),[g,j]=m.useState(null),[v,y]=m.useState(!1),[b,S]=m.useState(!1),[w,O]=m.useState({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),A=m.useCallback(async()=>{try{x(!0),f(null);const E=await we("/api/webui/plugins/mirrors");if(!E.ok)throw new Error("获取镜像源列表失败");const se=await E.json();o(se.mirrors||[])}catch(E){const se=E instanceof Error?E.message:"加载镜像源失败";f(se),i({title:"加载失败",description:se,variant:"destructive"})}finally{x(!1)}},[i]);m.useEffect(()=>{A()},[A]);const D=async()=>{try{const E=await we("/api/webui/plugins/mirrors",{method:"POST",body:JSON.stringify(w)});if(!E.ok){const se=await E.json();throw new Error(se.detail||"添加镜像源失败")}i({title:"添加成功",description:"镜像源已添加"}),y(!1),O({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),A()}catch(E){i({title:"添加失败",description:E instanceof Error?E.message:"未知错误",variant:"destructive"})}},V=async()=>{if(g)try{if(!(await we(`/api/webui/plugins/mirrors/${g.id}`,{method:"PUT",body:JSON.stringify({name:w.name,raw_prefix:w.raw_prefix,clone_prefix:w.clone_prefix,enabled:w.enabled,priority:w.priority})})).ok)throw new Error("更新镜像源失败");i({title:"更新成功",description:"镜像源已更新"}),S(!1),j(null),A()}catch(E){i({title:"更新失败",description:E instanceof Error?E.message:"未知错误",variant:"destructive"})}},z=async E=>{if(confirm("确定要删除这个镜像源吗?"))try{if(!(await we(`/api/webui/plugins/mirrors/${E}`,{method:"DELETE"})).ok)throw new Error("删除镜像源失败");i({title:"删除成功",description:"镜像源已删除"}),A()}catch(se){i({title:"删除失败",description:se instanceof Error?se.message:"未知错误",variant:"destructive"})}},_=async E=>{try{if(!(await we(`/api/webui/plugins/mirrors/${E.id}`,{method:"PUT",body:JSON.stringify({enabled:!E.enabled})})).ok)throw new Error("更新状态失败");A()}catch(se){i({title:"更新失败",description:se instanceof Error?se.message:"未知错误",variant:"destructive"})}},T=E=>{j(E),O({id:E.id,name:E.name,raw_prefix:E.raw_prefix,clone_prefix:E.clone_prefix,enabled:E.enabled,priority:E.priority}),S(!0)},$=async(E,se)=>{const te=se==="up"?E.priority-1:E.priority+1;if(!(te<1))try{if(!(await we(`/api/webui/plugins/mirrors/${E.id}`,{method:"PUT",body:JSON.stringify({priority:te})})).ok)throw new Error("更新优先级失败");A()}catch(ne){i({title:"更新失败",description:ne instanceof Error?ne.message:"未知错误",variant:"destructive"})}};return e.jsx(Ze,{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(C,{variant:"ghost",size:"icon",onClick:()=>l({to:"/plugins"}),children:e.jsx(hi,{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(C,{onClick:()=>y(!0),children:[e.jsx(ut,{className:"h-4 w-4 mr-2"}),"添加镜像源"]})]}),u?e.jsx(Ve,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(tt,{className:"h-8 w-8 animate-spin text-primary"})})}):h?e.jsx(Ve,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Oa,{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(C,{onClick:A,children:"重新加载"})]})}):e.jsxs(Ve,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(bn,{children:[e.jsx(Nn,{children:e.jsxs(gt,{children:[e.jsx(Je,{children:"状态"}),e.jsx(Je,{children:"名称"}),e.jsx(Je,{children:"ID"}),e.jsx(Je,{children:"优先级"}),e.jsx(Je,{className:"text-right",children:"操作"})]})}),e.jsx(yn,{children:r.map(E=>e.jsxs(gt,{children:[e.jsx(Qe,{children:e.jsx(Fe,{checked:E.enabled,onCheckedChange:()=>_(E)})}),e.jsx(Qe,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:E.name}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Raw: ",E.raw_prefix]})]})}),e.jsx(Qe,{children:e.jsx(Ye,{variant:"outline",children:E.id})}),e.jsx(Qe,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono",children:E.priority}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(C,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>$(E,"up"),disabled:E.priority===1,children:e.jsx(fi,{className:"h-3 w-3"})}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>$(E,"down"),children:e.jsx(Fa,{className:"h-3 w-3"})})]})]})}),e.jsx(Qe,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(C,{variant:"ghost",size:"icon",onClick:()=>T(E),children:e.jsx(fn,{className:"h-4 w-4"})}),e.jsx(C,{variant:"ghost",size:"icon",onClick:()=>z(E.id),children:e.jsx(es,{className:"h-4 w-4 text-destructive"})})]})})]},E.id))})]})}),e.jsx("div",{className:"md:hidden p-4 space-y-4",children:r.map(E=>e.jsx(Ve,{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:E.name}),E.enabled&&e.jsx(Ye,{variant:"default",className:"text-xs",children:"启用"})]}),e.jsx(Ye,{variant:"outline",className:"mt-1 text-xs",children:E.id})]}),e.jsx(Fe,{checked:E.enabled,onCheckedChange:()=>_(E)})]}),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:E.raw_prefix})]}),e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"优先级: "}),e.jsx("span",{className:"font-mono",children:E.priority})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t",children:[e.jsxs(C,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>T(E),children:[e.jsx(fn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>$(E,"up"),disabled:E.priority===1,children:e.jsx(fi,{className:"h-4 w-4"})}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>$(E,"down"),children:e.jsx(Fa,{className:"h-4 w-4"})}),e.jsx(C,{variant:"destructive",size:"sm",onClick:()=>z(E.id),children:e.jsx(es,{className:"h-4 w-4"})})]})]})},E.id))})]}),e.jsx(Qs,{open:v,onOpenChange:y,children:e.jsxs(qs,{className:"max-w-lg",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"添加镜像源"}),e.jsx(Ws,{children:"添加新的 Git 镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"add-id",children:"镜像源 ID *"}),e.jsx(ie,{id:"add-id",placeholder:"例如: my-mirror",value:w.id,onChange:E=>O({...w,id:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"add-name",children:"名称 *"}),e.jsx(ie,{id:"add-name",placeholder:"例如: 我的镜像源",value:w.name,onChange:E=>O({...w,name:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"add-raw",children:"Raw 文件前缀 *"}),e.jsx(ie,{id:"add-raw",placeholder:"https://example.com/raw",value:w.raw_prefix,onChange:E=>O({...w,raw_prefix:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"add-clone",children:"克隆前缀 *"}),e.jsx(ie,{id:"add-clone",placeholder:"https://example.com/clone",value:w.clone_prefix,onChange:E=>O({...w,clone_prefix:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"add-priority",children:"优先级"}),e.jsx(ie,{id:"add-priority",type:"number",min:"1",value:w.priority,onChange:E=>O({...w,priority:parseInt(E.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(Fe,{id:"add-enabled",checked:w.enabled,onCheckedChange:E=>O({...w,enabled:E})}),e.jsx(k,{htmlFor:"add-enabled",children:"启用此镜像源"})]})]}),e.jsxs(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>y(!1),children:"取消"}),e.jsx(C,{onClick:D,children:"添加"})]})]})}),e.jsx(Qs,{open:b,onOpenChange:S,children:e.jsxs(qs,{className:"max-w-lg",children:[e.jsxs(Gs,{children:[e.jsx(Vs,{children:"编辑镜像源"}),e.jsx(Ws,{children:"修改镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"镜像源 ID"}),e.jsx(ie,{value:w.id,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"edit-name",children:"名称 *"}),e.jsx(ie,{id:"edit-name",value:w.name,onChange:E=>O({...w,name:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"edit-raw",children:"Raw 文件前缀 *"}),e.jsx(ie,{id:"edit-raw",value:w.raw_prefix,onChange:E=>O({...w,raw_prefix:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"edit-clone",children:"克隆前缀 *"}),e.jsx(ie,{id:"edit-clone",value:w.clone_prefix,onChange:E=>O({...w,clone_prefix:E.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"edit-priority",children:"优先级"}),e.jsx(ie,{id:"edit-priority",type:"number",min:"1",value:w.priority,onChange:E=>O({...w,priority:parseInt(E.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(Fe,{id:"edit-enabled",checked:w.enabled,onCheckedChange:E=>O({...w,enabled:E})}),e.jsx(k,{htmlFor:"edit-enabled",children:"启用此镜像源"})]})]}),e.jsxs(at,{children:[e.jsx(C,{variant:"outline",onClick:()=>S(!1),children:"取消"}),e.jsx(C,{onClick:V,children:"保存"})]})]})})]})})}const jr=m.forwardRef(({className:l,...i},r)=>e.jsx(ig,{ref:r,className:H("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",l),...i}));jr.displayName=ig.displayName;const mS=m.forwardRef(({className:l,...i},r)=>e.jsx(rg,{ref:r,className:H("aspect-square h-full w-full",l),...i}));mS.displayName=rg.displayName;const vr=m.forwardRef(({className:l,...i},r)=>e.jsx(cg,{ref:r,className:H("flex h-full w-full items-center justify-center rounded-full bg-muted",l),...i}));vr.displayName=cg.displayName;function xS(){return"webui_"+Math.random().toString(36).substr(2,9)+"_"+Date.now().toString(36)}function hS(){const l="maibot_webui_user_id";let i=localStorage.getItem(l);return i||(i=xS(),localStorage.setItem(l,i)),i}function fS(){return localStorage.getItem("maibot_webui_user_name")||"WebUI用户"}function pS(l){localStorage.setItem("maibot_webui_user_name",l)}const Aj="maibot_webui_virtual_tabs";function gS(){try{const l=localStorage.getItem(Aj);if(l)return JSON.parse(l)}catch(l){console.error("[Chat] 加载虚拟标签页失败:",l)}return[]}function Gp(l){try{localStorage.setItem(Aj,JSON.stringify(l))}catch(i){console.error("[Chat] 保存虚拟标签页失败:",i)}}function jS({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:H("rounded-lg max-w-full",l.type==="emoji"?"max-h-32":"max-h-64"),loading:"lazy",onError:i=>{const r=i.target;r.style.display="none",r.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 vS({message:l,isBot:i}){return l.message_type==="rich"&&l.segments&&l.segments.length>0?e.jsx("div",{className:"flex flex-col gap-2",children:l.segments.map((r,o)=>e.jsx(jS,{segment:r},o))}):e.jsx("span",{className:"whitespace-pre-wrap",children:l.content})}function bS(){const l={id:"webui-default",type:"webui",label:"WebUI",messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}},i=()=>{const He=gS().map(De=>{const ye=De.virtualConfig;return!ye.groupId&&ye.platform&&ye.userId&&(ye.groupId=`webui_virtual_group_${ye.platform}_${ye.userId}`),{id:De.id,type:"virtual",label:De.label,virtualConfig:ye,messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}}});return[l,...He]},[r,o]=m.useState(i),[u,x]=m.useState("webui-default"),h=r.find(F=>F.id===u)||r[0],[f,g]=m.useState(""),[j,v]=m.useState(!1),[y,b]=m.useState(!0),[S,w]=m.useState(fS()),[O,A]=m.useState(!1),[D,V]=m.useState(""),[z,_]=m.useState(!1),[T,$]=m.useState([]),[E,se]=m.useState([]),[te,ne]=m.useState(!1),[ue,Se]=m.useState(!1),[oe,je]=m.useState(""),[be,U]=m.useState({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),P=m.useRef(hS()),X=m.useRef(new Map),L=m.useRef(null),B=m.useRef(new Map),_e=m.useRef(0),Ne=m.useRef(new Map),{toast:Ce}=Ks(),ve=F=>(_e.current+=1,`${F}-${Date.now()}-${_e.current}-${Math.random().toString(36).substr(2,9)}`),ze=m.useCallback((F,He)=>{o(De=>De.map(ye=>ye.id===F?{...ye,...He}:ye))},[]),Q=m.useCallback((F,He)=>{o(De=>De.map(ye=>ye.id===F?{...ye,messages:[...ye.messages,He]}:ye))},[]),xe=m.useCallback(()=>{L.current?.scrollIntoView({behavior:"smooth"})},[]);m.useEffect(()=>{xe()},[h?.messages,xe]);const Te=m.useCallback(async()=>{ne(!0);try{const F=await we("/api/chat/platforms");if(console.log("[Chat] 平台列表响应:",F.status,F.headers.get("content-type")),F.ok){const He=F.headers.get("content-type");if(He&&He.includes("application/json")){const De=await F.json();console.log("[Chat] 平台列表数据:",De),$(De.platforms||[])}else{const De=await F.text();console.error("[Chat] 获取平台列表失败: 非 JSON 响应:",De.substring(0,200)),Ce({title:"连接失败",description:"无法连接到后端服务,请确保 MaiBot 已启动",variant:"destructive"})}}else console.error("[Chat] 获取平台列表失败: HTTP",F.status),Ce({title:"获取平台失败",description:`服务器返回错误: ${F.status}`,variant:"destructive"})}catch(F){console.error("[Chat] 获取平台列表失败:",F),Ce({title:"网络错误",description:"无法连接到后端服务",variant:"destructive"})}finally{ne(!1)}},[Ce]),J=m.useCallback(async(F,He)=>{Se(!0);try{const De=new URLSearchParams;F&&De.append("platform",F),He&&De.append("search",He),De.append("limit","50");const ye=await we(`/api/chat/persons?${De.toString()}`);if(ye.ok){const ps=ye.headers.get("content-type");if(ps&&ps.includes("application/json")){const ss=await ye.json();se(ss.persons||[])}else console.error("[Chat] 获取用户列表失败: 后端返回非 JSON 响应")}}catch(De){console.error("[Chat] 获取用户列表失败:",De)}finally{Se(!1)}},[]);m.useEffect(()=>{be.platform&&J(be.platform,oe)},[be.platform,oe,J]);const le=m.useCallback(async(F,He)=>{b(!0);try{const De=new URLSearchParams;De.append("user_id",P.current),De.append("limit","50"),He&&De.append("group_id",He);const ye=`/api/chat/history?${De.toString()}`;console.log("[Chat] 正在加载历史消息:",ye);const ps=await we(ye);if(ps.ok){const ss=await ps.text();try{const Es=JSON.parse(ss);if(Es.messages&&Es.messages.length>0){const Ms=Es.messages.map(ts=>({id:ts.id,type:ts.type,content:ts.content,timestamp:ts.timestamp,sender:{name:ts.sender_name||(ts.is_bot?"麦麦":"WebUI用户"),user_id:ts.user_id,is_bot:ts.is_bot}}));ze(F,{messages:Ms});const Ls=Ne.current.get(F)||new Set;Ms.forEach(ts=>{if(ts.type==="bot"){const Pe=`bot-${ts.content}-${Math.floor(ts.timestamp*1e3)}`;Ls.add(Pe)}}),Ne.current.set(F,Ls)}}catch(Es){console.error("[Chat] JSON 解析失败:",Es)}}}catch(De){console.error("[Chat] 加载历史消息失败:",De)}finally{b(!1)}},[ze]),qe=m.useCallback(async(F,He,De)=>{const ye=X.current.get(F);if(ye?.readyState===WebSocket.OPEN||ye?.readyState===WebSocket.CONNECTING){console.log(`[Tab ${F}] WebSocket 已存在,跳过连接`);return}v(!0);let ps=null;try{const Ls=await we("/api/webui/ws-token");if(Ls.ok){const ts=await Ls.json();ts.success&&ts.token&&(ps=ts.token)}}catch(Ls){console.error(`[Tab ${F}] 获取 WebSocket token 失败:`,Ls)}const ss=window.location.protocol==="https:"?"wss:":"ws:",Es=new URLSearchParams;ps&&Es.append("token",ps),He==="virtual"&&De?(Es.append("user_id",De.userId),Es.append("user_name",De.userName),Es.append("platform",De.platform),Es.append("person_id",De.personId),Es.append("group_name",De.groupName||"WebUI虚拟群聊"),De.groupId&&Es.append("group_id",De.groupId)):(Es.append("user_id",P.current),Es.append("user_name",S));const Ms=`${ss}//${window.location.host}/api/chat/ws?${Es.toString()}`;console.log(`[Tab ${F}] 正在连接 WebSocket:`,Ms);try{const Ls=new WebSocket(Ms);X.current.set(F,Ls),Ls.onopen=()=>{ze(F,{isConnected:!0}),v(!1),console.log(`[Tab ${F}] WebSocket 已连接`)},Ls.onmessage=ts=>{try{const Pe=JSON.parse(ts.data);switch(Pe.type){case"session_info":ze(F,{sessionInfo:{session_id:Pe.session_id,user_id:Pe.user_id,user_name:Pe.user_name,bot_name:Pe.bot_name}});break;case"system":Q(F,{id:ve("sys"),type:"system",content:Pe.content||"",timestamp:Pe.timestamp||Date.now()/1e3});break;case"user_message":{const Xe=Pe.sender?.user_id,Os=He==="virtual"&&De?De.userId:P.current;console.log(`[Tab ${F}] 收到 user_message, sender: ${Xe}, current: ${Os}`);const kt=Xe?Xe.replace(/^webui_user_/,""):"",Xs=Os?Os.replace(/^webui_user_/,""):"";if(kt&&Xs&&kt===Xs){console.log(`[Tab ${F}] 跳过自己的消息(user_id 匹配)`);break}const Ss=Ne.current.get(F)||new Set,xt=`user-${Pe.content}-${Math.floor((Pe.timestamp||0)*1e3)}`;if(Ss.has(xt)){console.log(`[Tab ${F}] 跳过自己的消息(内容去重)`);break}if(Ss.add(xt),Ne.current.set(F,Ss),Ss.size>100){const W=Ss.values().next().value;W&&Ss.delete(W)}Q(F,{id:Pe.message_id||ve("user"),type:"user",content:Pe.content||"",timestamp:Pe.timestamp||Date.now()/1e3,sender:Pe.sender});break}case"bot_message":{ze(F,{isTyping:!1});const Xe=Ne.current.get(F)||new Set,Os=`bot-${Pe.content}-${Math.floor((Pe.timestamp||0)*1e3)}`;if(Xe.has(Os))break;if(Xe.add(Os),Ne.current.set(F,Xe),Xe.size>100){const kt=Xe.values().next().value;kt&&Xe.delete(kt)}o(kt=>kt.map(Xs=>{if(Xs.id!==F)return Xs;const Ss=Xs.messages.filter(W=>W.type!=="thinking"),xt={id:ve("bot"),type:"bot",content:Pe.content||"",message_type:Pe.message_type==="rich"?"rich":"text",segments:Pe.segments,timestamp:Pe.timestamp||Date.now()/1e3,sender:Pe.sender};return{...Xs,messages:[...Ss,xt]}}));break}case"typing":ze(F,{isTyping:Pe.is_typing||!1});break;case"error":o(Xe=>Xe.map(Os=>{if(Os.id!==F)return Os;const kt=Os.messages.filter(Xs=>Xs.type!=="thinking");return{...Os,messages:[...kt,{id:ve("error"),type:"error",content:Pe.content||"发生错误",timestamp:Pe.timestamp||Date.now()/1e3}]}})),Ce({title:"错误",description:Pe.content,variant:"destructive"});break;case"pong":break;case"history":{const Xe=Pe.messages||[];if(Xe.length>0){const Os=Ne.current.get(F)||new Set,kt=Xe.map(Xs=>{const Ss=Xs.is_bot||!1,xt=Xs.id||ve(Ss?"bot":"user"),W=`${Ss?"bot":"user"}-${Xs.content}-${Math.floor(Xs.timestamp*1e3)}`;return Os.add(W),{id:xt,type:Ss?"bot":"user",content:Xs.content,timestamp:Xs.timestamp,sender:{name:Xs.sender_name||(Ss?"麦麦":"用户"),user_id:Xs.sender_id,is_bot:Ss}}});Ne.current.set(F,Os),ze(F,{messages:kt}),console.log(`[Tab ${F}] 已加载 ${kt.length} 条历史消息`)}break}default:console.log("未知消息类型:",Pe.type)}}catch(Pe){console.error("解析消息失败:",Pe)}},Ls.onclose=()=>{ze(F,{isConnected:!1}),v(!1),X.current.delete(F),console.log(`[Tab ${F}] WebSocket 已断开`);const ts=B.current.get(F);ts&&clearTimeout(ts);const Pe=window.setTimeout(()=>{if(!We.current){const Xe=r.find(Os=>Os.id===F);Xe&&qe(F,Xe.type,Xe.virtualConfig)}},5e3);B.current.set(F,Pe)},Ls.onerror=ts=>{console.error(`[Tab ${F}] WebSocket 错误:`,ts),v(!1)}}catch(Ls){console.error(`[Tab ${F}] 创建 WebSocket 失败:`,Ls),v(!1)}},[S,ze,Q,Ce,r]),We=m.useRef(!1);m.useEffect(()=>{We.current=!1;const F=X.current,He=B.current,De=Ne.current;le("webui-default");const ye=setTimeout(()=>{We.current||(qe("webui-default","webui"),r.forEach(ss=>{ss.type==="virtual"&&ss.virtualConfig&&(De.set(ss.id,new Set),setTimeout(()=>{We.current||qe(ss.id,"virtual",ss.virtualConfig)},200))}))},100),ps=setInterval(()=>{F.forEach(ss=>{ss.readyState===WebSocket.OPEN&&ss.send(JSON.stringify({type:"ping"}))})},3e4);return()=>{We.current=!0,clearTimeout(ye),clearInterval(ps),He.forEach(ss=>{clearTimeout(ss)}),He.clear(),F.forEach(ss=>{ss.close()}),F.clear()}},[]);const fe=m.useCallback(()=>{const F=X.current.get(u);if(!f.trim()||!F||F.readyState!==WebSocket.OPEN)return;const He=h?.type==="virtual"&&h.virtualConfig?.userName||S,De=f.trim(),ye=Date.now()/1e3;F.send(JSON.stringify({type:"message",content:De,user_name:He}));const ps=Ne.current.get(u)||new Set,ss=`user-${De}-${Math.floor(ye*1e3)}`;if(ps.add(ss),Ne.current.set(u,ps),ps.size>100){const Ls=ps.values().next().value;Ls&&ps.delete(Ls)}const Es={id:ve("user"),type:"user",content:De,timestamp:ye,sender:{name:He,is_bot:!1}};Q(u,Es);const Ms={id:ve("thinking"),type:"thinking",content:"",timestamp:ye+.001,sender:{name:h?.sessionInfo.bot_name||"麦麦",is_bot:!0}};Q(u,Ms),g("")},[f,S,u,h,Q]),ls=F=>{F.key==="Enter"&&!F.shiftKey&&(F.preventDefault(),fe())},G=()=>{V(S),A(!0)},Me=()=>{const F=D.trim()||"WebUI用户";w(F),pS(F),A(!1);const He=X.current.get(u);He?.readyState===WebSocket.OPEN&&He.send(JSON.stringify({type:"update_nickname",user_name:F}))},re=()=>{V(""),A(!1)},pe=F=>new Date(F*1e3).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),Ee=()=>{const F=X.current.get(u);F&&(F.close(),X.current.delete(u)),qe(u,h?.type||"webui",h?.virtualConfig)},Ie=()=>{U({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),je(""),Te(),_(!0)},$e=()=>{if(!be.platform||!be.personId){Ce({title:"配置不完整",description:"请选择平台和用户",variant:"destructive"});return}const F=`webui_virtual_group_${be.platform}_${be.userId}`,He=`virtual-${be.platform}-${be.userId}-${Date.now()}`,De=be.userName||be.userId,ye={id:He,type:"virtual",label:De,virtualConfig:{...be,groupId:F},messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}};o(ps=>{const ss=[...ps,ye],Es=ss.filter(Ms=>Ms.type==="virtual"&&Ms.virtualConfig).map(Ms=>({id:Ms.id,label:Ms.label,virtualConfig:Ms.virtualConfig,createdAt:Date.now()}));return Gp(Es),ss}),x(He),_(!1),Ne.current.set(He,new Set),setTimeout(()=>{qe(He,"virtual",be)},100),Ce({title:"虚拟身份标签页",description:`已创建 ${De} 的对话`})},Vt=(F,He)=>{if(He?.stopPropagation(),F==="webui-default")return;const De=X.current.get(F);De&&(De.close(),X.current.delete(F));const ye=B.current.get(F);ye&&(clearTimeout(ye),B.current.delete(F)),Ne.current.delete(F),o(ps=>{const ss=ps.filter(Ms=>Ms.id!==F),Es=ss.filter(Ms=>Ms.type==="virtual"&&Ms.virtualConfig).map(Ms=>({id:Ms.id,label:Ms.label,virtualConfig:Ms.virtualConfig,createdAt:Date.now()}));return Gp(Es),ss}),u===F&&x("webui-default")},_t=F=>{x(F)},nt=F=>{U(He=>({...He,personId:F.person_id,userId:F.user_id,userName:F.nickname||F.person_name}))};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx(Qs,{open:z,onOpenChange:_,children:e.jsxs(qs,{className:"sm:max-w-[500px] max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsxs(Gs,{children:[e.jsxs(Vs,{className:"flex items-center gap-2",children:[e.jsx(Uu,{className:"h-5 w-5"}),"新建虚拟身份对话"]}),e.jsx(Ws,{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(k,{className:"flex items-center gap-2",children:[e.jsx(Wu,{className:"h-4 w-4"}),"选择平台"]}),e.jsxs(Ue,{value:be.platform,onValueChange:F=>{U(He=>({...He,platform:F,personId:"",userId:"",userName:""})),se([])},children:[e.jsx(Re,{disabled:te,children:e.jsx(Be,{placeholder:te?"加载中...":"选择平台"})}),e.jsx(Le,{children:T.map(F=>e.jsxs(ee,{value:F.platform,children:[F.platform," (",F.count," 人)"]},F.platform))})]})]}),be.platform&&e.jsxs("div",{className:"space-y-2 flex-1 overflow-hidden flex flex-col",children:[e.jsxs(k,{className:"flex items-center gap-2",children:[e.jsx(em,{className:"h-4 w-4"}),"选择用户"]}),e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"搜索用户名...",value:oe,onChange:F=>je(F.target.value),className:"pl-9"})]}),e.jsx(Ze,{className:"h-[250px] border rounded-md",children:e.jsx("div",{className:"p-2",children:ue?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(tt,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[e.jsx(em,{className:"h-8 w-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"没有找到用户"})]}):e.jsx("div",{className:"space-y-1",children:E.map(F=>e.jsxs("button",{onClick:()=>nt(F),className:H("w-full flex items-center gap-3 p-2 rounded-md text-left transition-colors",be.personId===F.person_id?"bg-primary text-primary-foreground":"hover:bg-muted"),children:[e.jsx(jr,{className:"h-8 w-8 shrink-0",children:e.jsx(vr,{className:H("text-xs",be.personId===F.person_id?"bg-primary-foreground/20":"bg-muted"),children:(F.nickname||F.person_name||"?").charAt(0)})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium truncate",children:F.nickname||F.person_name}),e.jsxs("div",{className:H("text-xs truncate",be.personId===F.person_id?"text-primary-foreground/70":"text-muted-foreground"),children:["ID: ",F.user_id,F.is_known&&" · 已认识"]})]})]},F.person_id))})})})]}),be.personId&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"虚拟群名(可选)"}),e.jsx(ie,{placeholder:"WebUI虚拟群聊",value:be.groupName,onChange:F=>U(He=>({...He,groupName:F.target.value}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦会认为这是一个名为此名称的群聊"})]})]}),e.jsxs(at,{className:"gap-2 sm:gap-0",children:[e.jsx(C,{variant:"outline",onClick:()=>_(!1),children:"取消"}),e.jsx(C,{onClick:$e,disabled:!be.platform||!be.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:[r.map(F=>e.jsxs("div",{className:H("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===F.id?"bg-background shadow-sm border":"text-muted-foreground"),onClick:()=>_t(F.id),children:[F.type==="webui"?e.jsx(Fl,{className:"h-3.5 w-3.5"}):e.jsx(Uu,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"max-w-[100px] truncate",children:F.label}),e.jsx("span",{className:H("w-1.5 h-1.5 rounded-full",F.isConnected?"bg-green-500":"bg-muted-foreground/50")}),F.id!=="webui-default"&&e.jsx("span",{onClick:He=>Vt(F.id,He),className:"ml-0.5 p-0.5 rounded hover:bg-muted-foreground/20 cursor-pointer",role:"button",tabIndex:0,onKeyDown:He=>{(He.key==="Enter"||He.key===" ")&&(He.preventDefault(),Vt(F.id,He))},children:e.jsx(fl,{className:"h-3 w-3"})})]},F.id)),e.jsx("button",{onClick:Ie,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(ut,{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(jr,{className:"h-8 w-8 sm:h-10 sm:w-10 shrink-0",children:e.jsx(vr,{className:"bg-primary/10 text-primary",children:e.jsx(fr,{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(Jy,{className:"h-3 w-3 text-green-500"}),e.jsx("span",{className:"text-green-600 dark:text-green-400",children:"已连接"})]}):j?e.jsxs(e.Fragment,{children:[e.jsx(tt,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"连接中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Zy,{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:[y&&e.jsx(tt,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:Ee,disabled:j,title:"重新连接",children:e.jsx(At,{className:H("h-4 w-4",j&&"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(Uu,{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(oo,{className:"h-3 w-3"}),e.jsx("span",{children:"当前身份:"}),O?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{value:D,onChange:F=>V(F.target.value),onKeyDown:F=>{F.key==="Enter"&&Me(),F.key==="Escape"&&re()},className:"h-7 w-32",placeholder:"输入昵称",autoFocus:!0}),e.jsx(C,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:Me,children:"保存"}),e.jsx(C,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:re,children:"取消"})]}):e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-foreground",children:S}),e.jsx(C,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:G,title:"修改昵称",children:e.jsx(Wy,{className:"h-3 w-3"})})]})]})})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(Ze,{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&&!y&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(fr,{className:"h-12 w-12 mb-4 opacity-50"}),e.jsxs("p",{className:"text-sm",children:["开始与 ",h?.sessionInfo.bot_name||"麦麦"," 对话吧!"]})]}),h?.messages.map(F=>e.jsxs("div",{className:H("flex gap-2 sm:gap-3",F.type==="user"&&"flex-row-reverse",F.type==="system"&&"justify-center",F.type==="error"&&"justify-center"),children:[F.type==="system"&&e.jsx("div",{className:"text-xs text-muted-foreground bg-muted/50 px-3 py-1 rounded-full max-w-[90%]",children:F.content}),F.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:F.content}),F.type==="thinking"&&e.jsxs(e.Fragment,{children:[e.jsx(jr,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(vr,{className:"bg-primary/10 text-primary",children:e.jsx(fr,{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:F.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:"思考中..."})]})})]})]}),(F.type==="user"||F.type==="bot")&&e.jsxs(e.Fragment,{children:[e.jsx(jr,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(vr,{className:H("text-xs",F.type==="bot"?"bg-primary/10 text-primary":"bg-secondary text-secondary-foreground"),children:F.type==="bot"?e.jsx(fr,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}):e.jsx(oo,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})}),e.jsxs("div",{className:H("flex flex-col gap-1 max-w-[75%] sm:max-w-[70%]",F.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:F.sender?.name||(F.type==="bot"?h?.sessionInfo.bot_name:S)}),e.jsx("span",{children:pe(F.timestamp)})]}),e.jsx("div",{className:H("rounded-2xl px-3 py-2 text-sm break-words",F.type==="bot"?"bg-muted rounded-tl-sm":"bg-primary text-primary-foreground rounded-tr-sm"),children:e.jsx(vS,{message:F,isBot:F.type==="bot"})})]})]})]},F.id)),e.jsx("div",{ref:L})]})})}),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(ie,{value:f,onChange:F=>g(F.target.value),onKeyDown:ls,placeholder:h?.isConnected?"输入消息...":"等待连接...",disabled:!h?.isConnected,className:"flex-1 h-10 sm:h-10"}),e.jsx(C,{onClick:fe,disabled:!h?.isConnected||!f.trim(),size:"icon",className:"h-10 w-10 shrink-0",children:e.jsx(e0,{className:"h-4 w-4"})})]})})})]})}var Nm="Radio",[NS,Oj]=wg(Nm),[yS,wS]=NS(Nm),Dj=m.forwardRef((l,i)=>{const{__scopeRadio:r,name:o,checked:u=!1,required:x,disabled:h,value:f="on",onCheck:g,form:j,...v}=l,[y,b]=m.useState(null),S=nm(i,A=>b(A)),w=m.useRef(!1),O=y?j||!!y.closest("form"):!0;return e.jsxs(yS,{scope:r,checked:u,disabled:h,children:[e.jsx(fo.button,{type:"button",role:"radio","aria-checked":u,"data-state":Bj(u),"data-disabled":h?"":void 0,disabled:h,value:f,...v,ref:S,onClick:Zu(l.onClick,A=>{u||g?.(),O&&(w.current=A.isPropagationStopped(),w.current||A.stopPropagation())})}),O&&e.jsx(Uj,{control:y,bubbles:!w.current,name:o,value:f,checked:u,required:x,disabled:h,form:j,style:{transform:"translateX(-100%)"}})]})});Dj.displayName=Nm;var Rj="RadioIndicator",Lj=m.forwardRef((l,i)=>{const{__scopeRadio:r,forceMount:o,...u}=l,x=wS(Rj,r);return e.jsx(by,{present:o||x.checked,children:e.jsx(fo.span,{"data-state":Bj(x.checked),"data-disabled":x.disabled?"":void 0,...u,ref:i})})});Lj.displayName=Rj;var _S="RadioBubbleInput",Uj=m.forwardRef(({__scopeRadio:l,control:i,checked:r,bubbles:o=!0,...u},x)=>{const h=m.useRef(null),f=nm(h,x),g=Ny(r),j=yy(i);return m.useEffect(()=>{const v=h.current;if(!v)return;const y=window.HTMLInputElement.prototype,S=Object.getOwnPropertyDescriptor(y,"checked").set;if(g!==r&&S){const w=new Event("click",{bubbles:o});S.call(v,r),v.dispatchEvent(w)}},[g,r,o]),e.jsx(fo.input,{type:"radio","aria-hidden":!0,defaultChecked:r,...u,tabIndex:-1,ref:f,style:{...u.style,...j,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Uj.displayName=_S;function Bj(l){return l?"checked":"unchecked"}var SS=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],_o="RadioGroup",[CS]=wg(_o,[og,Oj]),Hj=og(),$j=Oj(),[kS,TS]=CS(_o),qj=m.forwardRef((l,i)=>{const{__scopeRadioGroup:r,name:o,defaultValue:u,value:x,required:h=!1,disabled:f=!1,orientation:g,dir:j,loop:v=!0,onValueChange:y,...b}=l,S=Hj(r),w=jy(j),[O,A]=vy({prop:x,defaultProp:u??null,onChange:y,caller:_o});return e.jsx(kS,{scope:r,name:o,required:h,disabled:f,value:O,onValueChange:A,children:e.jsx(XN,{asChild:!0,...S,orientation:g,dir:w,loop:v,children:e.jsx(fo.div,{role:"radiogroup","aria-required":h,"aria-orientation":g,"data-disabled":f?"":void 0,dir:w,...b,ref:i})})})});qj.displayName=_o;var Gj="RadioGroupItem",Vj=m.forwardRef((l,i)=>{const{__scopeRadioGroup:r,disabled:o,...u}=l,x=TS(Gj,r),h=x.disabled||o,f=Hj(r),g=$j(r),j=m.useRef(null),v=nm(i,j),y=x.value===u.value,b=m.useRef(!1);return m.useEffect(()=>{const S=O=>{SS.includes(O.key)&&(b.current=!0)},w=()=>b.current=!1;return document.addEventListener("keydown",S),document.addEventListener("keyup",w),()=>{document.removeEventListener("keydown",S),document.removeEventListener("keyup",w)}},[]),e.jsx(PN,{asChild:!0,...f,focusable:!h,active:y,children:e.jsx(Dj,{disabled:h,required:x.required,checked:y,...g,...u,name:x.name,ref:v,onCheck:()=>x.onValueChange(u.value),onKeyDown:Zu(S=>{S.key==="Enter"&&S.preventDefault()}),onFocus:Zu(u.onFocus,()=>{b.current&&j.current?.click()})})})});Vj.displayName=Gj;var ES="RadioGroupIndicator",Fj=m.forwardRef((l,i)=>{const{__scopeRadioGroup:r,...o}=l,u=$j(r);return e.jsx(Lj,{...u,...o,ref:i})});Fj.displayName=ES;var Ij=qj,Qj=Vj,zS=Fj;const Yj=m.forwardRef(({className:l,...i},r)=>e.jsx(Ij,{className:H("grid gap-2",l),...i,ref:r}));Yj.displayName=Ij.displayName;const Kj=m.forwardRef(({className:l,...i},r)=>e.jsx(Qj,{ref:r,className:H("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),...i,children:e.jsx(zS,{className:"flex items-center justify-center",children:e.jsx(s0,{className:"h-2.5 w-2.5 fill-current text-current"})})}));Kj.displayName=Qj.displayName;function MS({question:l,value:i,onChange:r,error:o,disabled:u=!1}){const[x,h]=m.useState(null),f=u||l.readOnly,g=()=>{switch(l.type){case"single":return e.jsx(Yj,{value:i||"",onValueChange:r,disabled:f,className:"space-y-2",children:l.options?.map(j=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Kj,{value:j.value,id:`${l.id}-${j.id}`}),e.jsx(k,{htmlFor:`${l.id}-${j.id}`,className:"cursor-pointer font-normal",children:j.label})]},j.id))});case"multiple":{const j=i||[];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(jt,{id:`${l.id}-${v.id}`,checked:j.includes(v.value),disabled:f||l.maxSelections!==void 0&&j.length>=l.maxSelections&&!j.includes(v.value),onCheckedChange:y=>{r(y?[...j,v.value]:j.filter(b=>b!==v.value))}}),e.jsx(k,{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(ie,{value:i||"",onChange:j=>r(j.target.value),placeholder:l.placeholder||"请输入...",disabled:f,readOnly:l.readOnly,maxLength:l.maxLength,className:H(l.readOnly&&"bg-muted cursor-not-allowed")});case"textarea":return e.jsxs("div",{className:"space-y-1",children:[e.jsx(Ys,{value:i||"",onChange:j=>r(j.target.value),placeholder:l.placeholder||"请输入...",disabled:f,readOnly:l.readOnly,maxLength:l.maxLength,rows:4,className:H(l.readOnly&&"bg-muted cursor-not-allowed")}),l.maxLength&&e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[(i||"").length," / ",l.maxLength]})]});case"rating":{const j=i||0,v=x!==null?x:j;return e.jsxs("div",{className:"flex items-center gap-1",children:[[1,2,3,4,5].map(y=>e.jsx("button",{type:"button",disabled:f,className:H("p-1 transition-colors focus:outline-none focus:ring-2 focus:ring-ring rounded",f&&"cursor-not-allowed opacity-50"),onMouseEnter:()=>!f&&h(y),onMouseLeave:()=>h(null),onClick:()=>!f&&r(y),children:e.jsx(xl,{className:H("h-6 w-6 transition-colors",y<=v?"fill-yellow-400 text-yellow-400":"text-muted-foreground")})},y)),j>0&&e.jsxs("span",{className:"ml-2 text-sm text-muted-foreground",children:[j," / 5"]})]})}case"scale":{const j=l.min??1,v=l.max??10,y=l.step??1,b=i??j;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(ma,{value:[b],onValueChange:([S])=>r(S),min:j,max:v,step:y,disabled:f}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:l.minLabel||j}),e.jsx("span",{className:"font-medium text-foreground",children:b}),e.jsx("span",{children:l.maxLabel||v})]})]})}case"dropdown":return e.jsxs(Ue,{value:i||"",onValueChange:r,disabled:f,children:[e.jsx(Re,{children:e.jsx(Be,{placeholder:l.placeholder||"请选择..."})}),e.jsx(Le,{children:l.options?.map(j=>e.jsx(ee,{value:j.value,children:j.label},j.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(k,{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})]}),g(),o&&e.jsx("p",{className:"text-sm text-destructive",children:o})]})}const Xj="https://maibot-plugin-stats.maibot-webui.workers.dev";function Pj(){const l="maibot_user_id";let i=localStorage.getItem(l);if(!i){const r=Math.random().toString(36).substring(2,10),o=Date.now().toString(36),u=Math.random().toString(36).substring(2,10);i=`fp_${r}_${o}_${u}`,localStorage.setItem(l,i)}return i}async function AS(l,i,r,o){try{const u=o?.userId||Pj(),x={surveyId:l,surveyVersion:i,userId:u,answers:r,submittedAt:new Date().toISOString(),allowMultiple:o?.allowMultiple,metadata:{userAgent:navigator.userAgent,language:navigator.language}},h=await fetch(`${Xj}/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 OS(l,i){try{const r=i||Pj(),o=new URLSearchParams({user_id:r,survey_id:l}),u=await fetch(`${Xj}/survey/check?${o}`);return u.ok?{success:!0,hasSubmitted:(await u.json()).hasSubmitted}:{success:!1,error:(await u.json()).error||"检查失败"}}catch(r){return console.error("Error checking submission:",r),{success:!1,error:"网络错误"}}}function Jj({config:l,initialAnswers:i,onSubmitSuccess:r,onSubmitError:o,showProgress:u=!0,paginateQuestions:x=!1,className:h}){const f=m.useCallback(()=>!i||i.length===0?{}:i.reduce((X,L)=>(X[L.questionId]=L.value,X),{}),[i]),[g,j]=m.useState(()=>f()),[v,y]=m.useState({}),[b,S]=m.useState(0),[w,O]=m.useState(!1),[A,D]=m.useState(!1),[V,z]=m.useState(null),[_,T]=m.useState(null),[$,E]=m.useState(!1),[se,te]=m.useState(!0);m.useEffect(()=>{i&&i.length>0&&j(X=>({...X,...f()}))},[i,f]),m.useEffect(()=>{(async()=>{if(!l.settings?.allowMultiple){const L=await OS(l.id);L.success&&L.hasSubmitted&&E(!0)}te(!1)})()},[l.id,l.settings?.allowMultiple]);const ne=m.useCallback(()=>{const X=new Date;return!(l.settings?.startTime&&new Date(l.settings.startTime)>X||l.settings?.endTime&&new Date(l.settings.endTime){const L=g[X.id];return L==null?!1:Array.isArray(L)?L.length>0:typeof L=="string"?L.trim()!=="":!0}).length,Se=ue/l.questions.length*100,oe=m.useCallback((X,L)=>{j(B=>({...B,[X]:L})),y(B=>{const _e={...B};return delete _e[X],_e})},[]),je=m.useCallback(()=>{const X={};for(const L of l.questions){if(L.required){const B=g[L.id];if(B==null){X[L.id]="此题为必填项";continue}if(Array.isArray(B)&&B.length===0){X[L.id]="请至少选择一项";continue}if(typeof B=="string"&&B.trim()===""){X[L.id]="此题为必填项";continue}}L.minLength&&typeof g[L.id]=="string"&&g[L.id].length{if(!je()){if(x){const X=l.questions.findIndex(L=>v[L.id]);X>=0&&S(X)}return}O(!0),z(null);try{const X=l.questions.filter(B=>g[B.id]!==void 0).map(B=>({questionId:B.id,value:g[B.id]})),L=await AS(l.id,l.version,X,{allowMultiple:l.settings?.allowMultiple});if(L.success&&L.submissionId)D(!0),T(L.submissionId),r?.(L.submissionId);else{const B=L.error||"提交失败";z(B),o?.(B)}}catch(X){const L=X instanceof Error?X.message:"提交失败";z(L),o?.(L)}finally{O(!1)}},[je,x,l,g,v,r,o]),U=m.useCallback(X=>{X>=0&&Xe.jsxs("div",{className:H("p-4 rounded-lg border bg-card",v[X.id]?"border-destructive bg-destructive/5":"border-border"),children:[x&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:["问题 ",b+1," / ",l.questions.length]}),!x&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:[L+1,"."]}),e.jsx(MS,{question:X,value:g[X.id],onChange:B=>oe(X.id,B),error:v[X.id],disabled:w})]},X.id)),V&&e.jsxs(sa,{variant:"destructive",children:[e.jsx(Ot,{className:"h-4 w-4"}),e.jsx(ta,{children:V})]}),e.jsx("div",{className:"flex justify-between items-center py-4",children:x?e.jsxs(e.Fragment,{children:[e.jsxs(C,{variant:"outline",onClick:()=>U(b-1),disabled:b===0||w,children:[e.jsx(pl,{className:"h-4 w-4 mr-1"}),"上一题"]}),b===l.questions.length-1?e.jsxs(C,{onClick:be,disabled:w,children:[w&&e.jsx(tt,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]}):e.jsxs(C,{onClick:()=>U(b+1),disabled:w,children:["下一题",e.jsx(Ya,{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(C,{onClick:be,disabled:w,size:"lg",children:[w&&e.jsx(tt,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]})]})})]})})]})}const DS={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:"感谢你的反馈!你的意见对我们非常重要,我们会认真考虑每一条建议。"}},RS={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 LS(){const[l,i]=m.useState(null),[r,o]=m.useState(!0);m.useEffect(()=>{const f=JSON.parse(JSON.stringify(DS));i(f),o(!1)},[]);const u=m.useMemo(()=>[{questionId:"webui_version",value:`v${go}`}],[]),x=m.useCallback(f=>{console.log("WebUI Survey submitted:",f)},[]),h=m.useCallback(f=>{console.error("WebUI Survey submission error:",f)},[]);return r?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(tt,{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(qg,{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(Jj,{config:l,initialAnswers:u,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:x,onSubmitError:h})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(sa,{variant:"destructive",className:"max-w-md",children:[e.jsx(Ot,{className:"h-4 w-4"}),e.jsx(ta,{children:"无法加载问卷配置"})]}),e.jsx(C,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}function US(){const[l,i]=m.useState(null),[r,o]=m.useState(!0),[u,x]=m.useState("未知版本");m.useEffect(()=>{(async()=>{try{const y=await V0();x(y.version||"未知版本")}catch(y){console.error("Failed to get MaiBot version:",y),x("获取失败")}const v=JSON.parse(JSON.stringify(RS));i(v),o(!1)})()},[]);const h=m.useMemo(()=>[{questionId:"maibot_version",value:u}],[u]),f=m.useCallback(j=>{console.log("MaiBot Survey submitted:",j)},[]),g=m.useCallback(j=>{console.error("MaiBot Survey submission error:",j)},[]);return r?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(tt,{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(qg,{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(Jj,{config:l,initialAnswers:h,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:f,onSubmitError:g})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(sa,{variant:"destructive",className:"max-w-md",children:[e.jsx(Ot,{className:"h-4 w-4"}),e.jsx(ta,{children:"无法加载问卷配置"})]}),e.jsx(C,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}function BS(){const l=ka(),[i,r]=m.useState(!0);return m.useEffect(()=>{let o=!1;return(async()=>{try{const x=await om();!o&&!x&&l({to:"/auth"})}catch{o||l({to:"/auth"})}finally{o||r(!1)}})(),()=>{o=!0}},[l]),{checking:i}}async function HS(){return await om()}const $S=gi("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"}}),Zj=m.forwardRef(({className:l,size:i,abbrTitle:r,children:o,...u},x)=>e.jsx("kbd",{className:H($S({size:i,className:l})),ref:x,...u,children:r?e.jsx("abbr",{title:r,children:o}):o}));Zj.displayName="Kbd";const qS=[{icon:po,title:"首页",description:"查看仪表板概览",path:"/",category:"概览"},{icon:Aa,title:"麦麦主程序配置",description:"配置麦麦的核心设置",path:"/config/bot",category:"配置"},{icon:Gg,title:"麦麦模型提供商配置",description:"配置模型提供商",path:"/config/modelProvider",category:"配置"},{icon:Vg,title:"麦麦模型配置",description:"配置模型参数",path:"/config/model",category:"配置"},{icon:im,title:"表情包管理",description:"管理麦麦的表情包",path:"/resource/emoji",category:"资源"},{icon:Fl,title:"表达方式管理",description:"管理麦麦的表达方式",path:"/resource/expression",category:"资源"},{icon:Fg,title:"人物信息管理",description:"管理人物信息",path:"/resource/person",category:"资源"},{icon:pi,title:"黑话管理",description:"管理麦麦学习到的黑话和俚语",path:"/resource/jargon",category:"资源"},{icon:t0,title:"统计信息",description:"查看使用统计",path:"/statistics",category:"监控"},{icon:Vl,title:"插件市场",description:"浏览和安装插件",path:"/plugins",category:"扩展"},{icon:rm,title:"日志查看器",description:"查看系统日志",path:"/logs",category:"监控"},{icon:ji,title:"系统设置",description:"配置系统参数",path:"/settings",category:"系统"}];function GS({open:l,onOpenChange:i}){const[r,o]=m.useState(""),[u,x]=m.useState(0),h=ka(),f=qS.filter(v=>v.title.toLowerCase().includes(r.toLowerCase())||v.description.toLowerCase().includes(r.toLowerCase())||v.category.toLowerCase().includes(r.toLowerCase()));m.useEffect(()=>{l&&(o(""),x(0))},[l]);const g=m.useCallback(v=>{h({to:v}),i(!1)},[h,i]),j=m.useCallback(v=>{v.key==="ArrowDown"?(v.preventDefault(),x(y=>(y+1)%f.length)):v.key==="ArrowUp"?(v.preventDefault(),x(y=>(y-1+f.length)%f.length)):v.key==="Enter"&&f[u]&&(v.preventDefault(),g(f[u].path))},[f,u,g]);return e.jsx(Qs,{open:l,onOpenChange:i,children:e.jsxs(qs,{className:"max-w-2xl p-0 gap-0",children:[e.jsxs(Gs,{className:"px-4 pt-4 pb-0",children:[e.jsx(Vs,{className:"sr-only",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-3 top-1/2 h-5 w-5 -translate-y-1/2 text-muted-foreground"}),e.jsx(ie,{value:r,onChange:v=>{o(v.target.value),x(0)},onKeyDown:j,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(Ze,{className:"h-[400px]",children:f.length>0?e.jsx("div",{className:"p-2",children:f.map((v,y)=>{const b=v.icon;return e.jsxs("button",{onClick:()=>g(v.path),onMouseEnter:()=>x(y),className:H("w-full flex items-center gap-3 px-3 py-2.5 rounded-md text-left transition-colors",y===u?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[e.jsx(b,{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($t,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r?"未找到匹配的页面":"输入关键词开始搜索"})]})})}),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"}),"关闭"]})]})})]})})}const VS=_y,FS=Sy,IS=Cy,Wj=m.forwardRef(({className:l,sideOffset:i=4,...r},o)=>e.jsx(wy,{children:e.jsx(_g,{ref:o,sideOffset:i,className:H("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),...r})}));Wj.displayName=_g.displayName;function QS({children:l}){const{checking:i}=BS(),[r,o]=m.useState(!0),[u,x]=m.useState(!1),[h,f]=m.useState(!1),{theme:g,setTheme:j}=dm(),v=bN();if(m.useEffect(()=>{const O=A=>{(A.metaKey||A.ctrlKey)&&A.key==="k"&&(A.preventDefault(),f(!0))};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[]),i)return e.jsx("div",{className:"flex h-screen items-center justify-center bg-background",children:e.jsx("div",{className:"text-muted-foreground",children:"正在验证登录状态..."})});const y=[{title:"概览",items:[{icon:po,label:"首页",path:"/"}]},{title:"麦麦配置编辑",items:[{icon:Aa,label:"麦麦主程序配置",path:"/config/bot"},{icon:Gg,label:"AI模型厂商配置",path:"/config/modelProvider",tourId:"sidebar-model-provider"},{icon:Vg,label:"模型管理与分配",path:"/config/model",tourId:"sidebar-model-management"},{icon:pp,label:"麦麦适配器配置",path:"/config/adapter"}]},{title:"麦麦资源管理",items:[{icon:im,label:"表情包管理",path:"/resource/emoji"},{icon:Fl,label:"表达方式管理",path:"/resource/expression"},{icon:pi,label:"黑话管理",path:"/resource/jargon"},{icon:Fg,label:"人物信息管理",path:"/resource/person"},{icon:Bg,label:"知识库图谱可视化",path:"/resource/knowledge-graph"}]},{title:"扩展与监控",items:[{icon:Vl,label:"插件市场",path:"/plugins"},{icon:$g,label:"模型分配预设市场",path:"/model-presets"},{icon:pp,label:"插件配置",path:"/plugin-config"},{icon:rm,label:"日志查看器",path:"/logs"},{icon:Fl,label:"本地聊天室",path:"/chat"}]},{title:"系统",items:[{icon:ji,label:"系统设置",path:"/settings"}]}],S=g==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":g,w=async()=>{await U0()};return e.jsx(VS,{delayDuration:300,children:e.jsxs("div",{className:"flex h-screen overflow-hidden",children:[e.jsxs("aside",{className:H("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",r?"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:H("relative flex items-center justify-center flex-1 transition-all overflow-hidden","lg:flex-1",!r&&"lg:flex-none lg:w-8"),children:[e.jsxs("div",{className:H("flex items-baseline gap-2",!r&&"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:rw()})]}),!r&&e.jsx("span",{className:"hidden lg:block font-bold text-primary-gradient text-2xl",children:"M"})]})}),e.jsx(Ze,{className:H("flex-1 overflow-x-hidden",!r&&"lg:w-16"),children:e.jsx("nav",{className:H("p-4",!r&&"lg:p-2 lg:w-16"),children:e.jsx("ul",{className:H("space-y-6",!r&&"lg:space-y-3 lg:w-full"),children:y.map((O,A)=>e.jsxs("li",{children:[e.jsx("div",{className:H("px-3 h-[1.25rem]","mb-2",!r&&"lg:mb-1 lg:invisible"),children:e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground/60 whitespace-nowrap",children:O.title})}),!r&&A>0&&e.jsx("div",{className:"hidden lg:block mb-2 border-t border-border"}),e.jsx("ul",{className:"space-y-1",children:O.items.map(D=>{const V=v({to:D.path}),z=D.icon,_=e.jsxs(e.Fragment,{children:[V&&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:H("flex items-center transition-all duration-300",r?"gap-3":"gap-3 lg:gap-0"),children:[e.jsx(z,{className:H("h-5 w-5 flex-shrink-0",V&&"text-primary"),strokeWidth:2,fill:"none"}),e.jsx("span",{className:H("text-sm font-medium whitespace-nowrap transition-all duration-300",V&&"font-semibold",r?"opacity-100 max-w-[200px]":"opacity-100 max-w-[200px] lg:opacity-0 lg:max-w-0 lg:overflow-hidden"),children:D.label})]})]});return e.jsx("li",{className:"relative",children:e.jsxs(FS,{children:[e.jsx(IS,{asChild:!0,children:e.jsx(ci,{to:D.path,"data-tour":D.tourId,className:H("relative flex items-center rounded-lg py-2 transition-all duration-300","hover:bg-accent hover:text-accent-foreground",V?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground",r?"px-3":"px-3 lg:px-0 lg:justify-center lg:w-12 lg:mx-auto"),onClick:()=>x(!1),children:_})}),!r&&e.jsx(Wj,{side:"right",className:"hidden lg:block",children:e.jsx("p",{children:D.label})})]})},D.path)})})]},O.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.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(a0,{className:"h-5 w-5"})}),e.jsx("button",{onClick:()=>o(!r),className:"hidden rounded-lg p-2 hover:bg-accent lg:block",title:r?"收起侧边栏":"展开侧边栏",children:e.jsx(pl,{className:H("h-5 w-5 transition-transform",!r&&"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($t,{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(Zj,{size:"sm",className:"absolute right-2 top-1/2 -translate-y-1/2",children:[e.jsx("span",{className:"text-xs",children:"⌘"}),"K"]})]}),e.jsx(GS,{open:h,onOpenChange:f}),e.jsxs(C,{variant:"ghost",size:"sm",onClick:()=>window.open("https://docs.mai-mai.org","_blank"),className:"gap-2",title:"查看麦麦文档",children:[e.jsx(l0,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"麦麦文档"})]}),e.jsx("button",{onClick:O=>{J0(S==="dark"?"light":"dark",j,O)},className:"rounded-lg p-2 hover:bg-accent",title:S==="dark"?"切换到浅色模式":"切换到深色模式",children:S==="dark"?e.jsx(Ag,{className:"h-5 w-5"}):e.jsx(Og,{className:"h-5 w-5"})}),e.jsx("div",{className:"h-6 w-px bg-border"}),e.jsxs(C,{variant:"ghost",size:"sm",onClick:w,className:"gap-2",title:"登出系统",children:[e.jsx(n0,{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})]})]})})}function YS(l){const i=l.split(` `).slice(1),r=[];for(const o of i){const u=o.trim();if(!u.startsWith("at "))continue;const x=u.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);x?r.push({functionName:x[1]||"",fileName:x[2],lineNumber:x[3],columnNumber:x[4],raw:u}):r.push({functionName:"",fileName:"",lineNumber:"",columnNumber:"",raw:u})}return r}function KS({error:l,errorInfo:i}){const[r,o]=m.useState(!0),[u,x]=m.useState(!1),[h,f]=m.useState(!1),g=l.stack?YS(l.stack):[],j=async()=>{const v=` Error: ${l.name} Message: ${l.message} Stack Trace: ${l.stack||"No stack trace available"} Component Stack: ${i?.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(y){console.error("Failed to copy:",y)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(sa,{variant:"destructive",className:"border-red-500/50 bg-red-500/10",children:[e.jsx(Oa,{className:"h-4 w-4"}),e.jsxs(ta,{className:"font-mono text-sm",children:[e.jsxs("span",{className:"font-semibold",children:[l.name,":"]})," ",l.message]})]}),g.length>0&&e.jsxs(Tr,{open:r,onOpenChange:o,children:[e.jsx(Er,{asChild:!0,children:e.jsxs(C,{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(i0,{className:"h-4 w-4"}),"Stack Trace (",g.length," frames)"]}),r?e.jsx(fi,{className:"h-4 w-4"}):e.jsx(Fa,{className:"h-4 w-4"})]})}),e.jsx(zr,{children:e.jsx(Ze,{className:"h-[280px] rounded-md border bg-muted/30",children:e.jsx("div",{className:"p-3 space-y-1",children:g.map((v,y)=>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:[y+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]})]})]})]})},y))})})})]}),i?.componentStack&&e.jsxs(Tr,{open:u,onOpenChange:x,children:[e.jsx(Er,{asChild:!0,children:e.jsxs(C,{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(Oa,{className:"h-4 w-4"}),"Component Stack"]}),u?e.jsx(fi,{className:"h-4 w-4"}):e.jsx(Fa,{className:"h-4 w-4"})]})}),e.jsx(zr,{children:e.jsx(Ze,{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:i.componentStack})})})]}),e.jsx(C,{variant:"outline",size:"sm",onClick:j,className:"w-full",children:h?e.jsxs(e.Fragment,{children:[e.jsx(ea,{className:"mr-2 h-4 w-4 text-green-500"}),"已复制到剪贴板"]}):e.jsxs(e.Fragment,{children:[e.jsx(co,{className:"mr-2 h-4 w-4"}),"复制错误信息"]})})]})}function ev({error:l,errorInfo:i}){const r=()=>{window.location.href="/"},o=()=>{window.location.reload()};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(Ve,{className:"w-full max-w-2xl shadow-lg",children:[e.jsxs(rs,{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(Oa,{className:"h-8 w-8 text-red-600 dark:text-red-400"})}),e.jsx(cs,{className:"text-2xl font-bold",children:"页面出现了问题"}),e.jsx(st,{className:"text-base mt-2",children:"应用程序遇到了意外错误。您可以尝试刷新页面或返回首页。"})]}),e.jsxs(gs,{className:"space-y-4",children:[e.jsx(KS,{error:l,errorInfo:i}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 pt-2",children:[e.jsxs(C,{onClick:o,className:"flex-1",children:[e.jsx(At,{className:"mr-2 h-4 w-4"}),"刷新页面"]}),e.jsxs(C,{onClick:r,variant:"outline",className:"flex-1",children:[e.jsx(po,{className:"mr-2 h-4 w-4"}),"返回首页"]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground pt-2",children:"如果问题持续存在,请将错误信息复制并反馈给开发者"})]})]})})}class XS extends m.Component{constructor(i){super(i),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(i){return{hasError:!0,error:i}}componentDidCatch(i,r){console.error("ErrorBoundary caught an error:",i,r),this.setState({errorInfo:r})}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(ev,{error:this.state.error,errorInfo:this.state.errorInfo}):this.props.children}}function sv({error:l}){return e.jsx(ev,{error:l,errorInfo:null})}const Rr=NN({component:()=>e.jsxs(e.Fragment,{children:[e.jsx(Vp,{}),!1]}),beforeLoad:()=>{if(window.location.pathname==="/"&&!HS())throw wN({to:"/auth"})}}),PS=lt({getParentRoute:()=>Rr,path:"/auth",component:ww}),JS=lt({getParentRoute:()=>Rr,path:"/setup",component:Hw}),wt=lt({getParentRoute:()=>Rr,id:"protected",component:()=>e.jsx(QS,{children:e.jsx(Vp,{})}),errorComponent:({error:l})=>e.jsx(sv,{error:l})}),ZS=lt({getParentRoute:()=>wt,path:"/",component:Y0}),WS=lt({getParentRoute:()=>wt,path:"/config/bot",component:b1}),e4=lt({getParentRoute:()=>wt,path:"/config/modelProvider",component:A1}),s4=lt({getParentRoute:()=>wt,path:"/config/model",component:K1}),t4=lt({getParentRoute:()=>wt,path:"/config/adapter",component:g2}),a4=lt({getParentRoute:()=>wt,path:"/resource/emoji",component:$2}),l4=lt({getParentRoute:()=>wt,path:"/resource/expression",component:Z2}),n4=lt({getParentRoute:()=>wt,path:"/resource/person",component:y_}),i4=lt({getParentRoute:()=>wt,path:"/resource/jargon",component:m_}),r4=lt({getParentRoute:()=>wt,path:"/resource/knowledge-graph",component:M_}),c4=lt({getParentRoute:()=>wt,path:"/logs",component:O_}),o4=lt({getParentRoute:()=>wt,path:"/chat",component:bS}),d4=lt({getParentRoute:()=>wt,path:"/plugins",component:lS}),u4=lt({getParentRoute:()=>wt,path:"/model-presets",component:iS}),m4=lt({getParentRoute:()=>wt,path:"/plugin-config",component:oS}),x4=lt({getParentRoute:()=>wt,path:"/plugin-mirrors",component:uS}),h4=lt({getParentRoute:()=>wt,path:"/settings",component:gw}),f4=lt({getParentRoute:()=>wt,path:"/survey/webui-feedback",component:LS}),p4=lt({getParentRoute:()=>wt,path:"/survey/maibot-feedback",component:US}),g4=lt({getParentRoute:()=>Rr,path:"*",component:fj}),j4=Rr.addChildren([PS,JS,wt.addChildren([ZS,WS,e4,s4,t4,a4,l4,i4,n4,r4,d4,u4,m4,x4,c4,o4,h4,f4,p4]),g4]),v4=yN({routeTree:j4,defaultNotFoundComponent:fj,defaultErrorComponent:({error:l})=>e.jsx(sv,{error:l})});function b4({children:l,defaultTheme:i="system",storageKey:r="ui-theme",...o}){const[u,x]=m.useState(()=>localStorage.getItem(r)||i);m.useEffect(()=>{const f=window.document.documentElement;if(f.classList.remove("light","dark"),u==="system"){const g=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";f.classList.add(g);return}f.classList.add(u)},[u]),m.useEffect(()=>{const f=localStorage.getItem("accent-color");if(f){const g=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&&(g.style.setProperty("--primary",v.hsl),v.gradient?(g.style.setProperty("--primary-gradient",v.gradient),g.classList.add("has-gradient")):(g.style.removeProperty("--primary-gradient"),g.classList.remove("has-gradient")))}},[]);const h={theme:u,setTheme:f=>{localStorage.setItem(r,f),x(f)}};return e.jsx(oj.Provider,{...o,value:h,children:l})}function N4({children:l,defaultEnabled:i=!0,defaultWavesEnabled:r=!0,storageKey:o="enable-animations",wavesStorageKey:u="enable-waves-background"}){const[x,h]=m.useState(()=>{const v=localStorage.getItem(o);return v!==null?v==="true":i}),[f,g]=m.useState(()=>{const v=localStorage.getItem(u);return v!==null?v==="true":r});m.useEffect(()=>{const v=document.documentElement;x?v.classList.remove("no-animations"):v.classList.add("no-animations"),localStorage.setItem(o,String(x))},[x,o]),m.useEffect(()=>{localStorage.setItem(u,String(f))},[f,u]);const j={enableAnimations:x,setEnableAnimations:h,enableWavesBackground:f,setEnableWavesBackground:g};return e.jsx(dj.Provider,{value:j,children:l})}const y4=ky,tv=m.forwardRef(({className:l,...i},r)=>e.jsx(Sg,{ref:r,className:H("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),...i}));tv.displayName=Sg.displayName;const w4=gi("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"}}),av=m.forwardRef(({className:l,variant:i,...r},o)=>e.jsx(Cg,{ref:o,className:H(w4({variant:i}),l),...r}));av.displayName=Cg.displayName;const _4=m.forwardRef(({className:l,...i},r)=>e.jsx(kg,{ref:r,className:H("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),...i}));_4.displayName=kg.displayName;const lv=m.forwardRef(({className:l,...i},r)=>e.jsx(Tg,{ref:r,className:H("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":"",...i,children:e.jsx(fl,{className:"h-4 w-4"})}));lv.displayName=Tg.displayName;const nv=m.forwardRef(({className:l,...i},r)=>e.jsx(Eg,{ref:r,className:H("text-sm font-semibold [&+div]:text-xs",l),...i}));nv.displayName=Eg.displayName;const iv=m.forwardRef(({className:l,...i},r)=>e.jsx(zg,{ref:r,className:H("text-sm opacity-90",l),...i}));iv.displayName=zg.displayName;function S4(){const{toasts:l}=Ks();return e.jsxs(y4,{children:[l.map(function({id:i,title:r,description:o,action:u,...x}){return e.jsxs(av,{...x,children:[e.jsxs("div",{className:"grid gap-1",children:[r&&e.jsx(nv,{children:r}),o&&e.jsx(iv,{children:o})]}),u,e.jsx(lv,{})]},i)}),e.jsx(tv,{})]})}L0.createRoot(document.getElementById("root")).render(e.jsx(m.StrictMode,{children:e.jsx(XS,{children:e.jsx(b4,{defaultTheme:"system",children:e.jsx(N4,{children:e.jsxs(C1,{children:[e.jsx(_N,{router:v4}),e.jsx(E1,{}),e.jsx(S4,{})]})})})})}));