import{r as u,j as e,L as Kn,e as va,R as bt,b as Ub,f as Bb,g as Hb,h as qb,k as tt,l as Gb,m as $b,O as _p,n as Fb}from"./router-Bz250laD.js";import{a as Vb,b as Qb,g as Ib}from"./react-vendor-BmxF9s7Q.js";import{N as Yb,c as Kb,O as tr,P as Ac,g as ju}from"./utils-BXc2jIuz.js";import{L as Sp,T as Cp,C as kp,R as Xb,a as Tp,V as Jb,b as Zb,S as Ep,c as Pb,d as zp,I as Wb,e as Ap,f as eN,g as Mp,h as sN,i as tN,j as aN,O as Dp,P as lN,k as Op,l as Rp,D as Lp,A as Up,m as Bp,n as nN,o as rN,p as Hp,q as iN,r as qp,s as cN,t as oN,u as dN,v as uN,w as mN,x as Gp,y as $p,F as Fp,z as Vp,B as xN,E as hN}from"./radix-extra-DDK-u9dm.js";import{R as fN,T as pN,L as gN,g as jN,C as Mc,X as Dc,Y as Pr,h as vN,B as vu,j as Oc,P as bN,k as NN,l as yN}from"./charts-DbiuC1q1.js";import{S as wN,G as Qp,O as Ip,o as _N,C as Yp,p as SN,T as Kp,D as Xp,R as CN,q as kN,H as Jp,I as TN,J as Zp,K as Pp,L as EN,M as Wp,V as zN,N as eg,Q as sg,U as AN,X as MN,Y as tg,Z as DN,_ as ON,$ as ag,a0 as RN,e as LN,f as UN,c as lg,P as Xc,d as Fu,b as Du,h as BN,l as HN,m as qN,a1 as GN,a2 as ng,a3 as $N,a4 as FN,a5 as VN,a6 as rg,a7 as ig,a8 as cg,a9 as og,aa as dg,ab as ug,ac as QN}from"./radix-core-9dEfQl-6.js";import{R as zt,P as hi,C as aa,a as At,Z as an,b as $c,F as Sa,c as IN,S as ar,d as YN,M as Rl,A as KN,D as XN,e as Fc,f as Pn,T as JN,X as rl,g as ZN,h as PN,I as Ra,i as Ca,j as Qt,k as Vc,E as ci,l as Rt,m as mg,H as WN,n as We,o as Oa,U as oi,p as xg,q as hg,L as Jf,K as fg,r as pg,s as ey,t as Hc,u as it,v as sy,B as ti,w as Qc,x as Vu,y as ty,z as ay,G as Mt,J as Jc,N as er,O as dt,Q as Ll,V as di,W as Qu,Y as fi,_ as ly,$ as ny,a0 as ln,a1 as lr,a2 as il,a3 as Ba,a4 as nr,a5 as Iu,a6 as ry,a7 as iy,a8 as cy,a9 as Ol,aa as oy,ab as gg,ac as Ou,ad as nn,ae as dy,af as sr,ag as uy,ah as Ru,ai as Lu,aj as jg,ak as Zf,al as my,am as xy,an as hy,ao as nl,ap as bu,aq as Pf,ar as fy,as as vg,at as Nu,au as py,av as gy,aw as jy,ax as vy,ay as by,az as bg,aA as Ng,aB as yg,aC as wg,aD as Ny,aE as Wf,aF as yy,aG as wy,aH as _y,aI as Sy}from"./icons-CwAZotQh.js";import{S as Cy,p as ky,j as Ty,a as Ey,E as ep,R as zy,o as Ay}from"./codemirror-BEE0n9kQ.js";import{_ as Kt,c as My,g as _g,D as Dy,z as Rc}from"./misc-CKjrIrIJ.js";import{u as Oy,a as sp,D as Ry,c as Ly,S as Uy,h as By,b as Hy,s as qy,K as Gy,P as $y,d as Fy,C as Vy}from"./dnd-CHfCzWUK.js";import{D as Qy,U as Iy}from"./uppy-BMZiFQyG.js";import{M as Yy,r as Ky,a as Xy,b as Jy}from"./markdown-kUhwkcQP.js";import{c as Zy,H as Ic,P as Yc,u as Py,d as Wy,R as e0,B as s0,e as t0,C as a0,M as l0,f as n0}from"./reactflow-DLoXAt4c.js";(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const m of document.querySelectorAll('link[rel="modulepreload"]'))d(m);new MutationObserver(m=>{for(const x of m)if(x.type==="childList")for(const f of x.addedNodes)f.tagName==="LINK"&&f.rel==="modulepreload"&&d(f)}).observe(document,{childList:!0,subtree:!0});function i(m){const x={};return m.integrity&&(x.integrity=m.integrity),m.referrerPolicy&&(x.referrerPolicy=m.referrerPolicy),m.crossOrigin==="use-credentials"?x.credentials="include":m.crossOrigin==="anonymous"?x.credentials="omit":x.credentials="same-origin",x}function d(m){if(m.ep)return;m.ep=!0;const x=i(m);fetch(m.href,x)}})();var yu={exports:{}},Wr={},wu={exports:{}},_u={};var tp;function r0(){return tp||(tp=1,(function(n){function r(D,J){var q=D.length;D.push(J);e:for(;0>>1,R=D[se];if(0>>1;sem(_e,q))Cem(ze,_e)?(D[se]=ze,D[Ce]=q,se=Ce):(D[se]=_e,D[me]=q,se=me);else if(Cem(ze,q))D[se]=ze,D[Ce]=q,se=Ce;else break e}}return J}function m(D,J){var q=D.sortIndex-J.sortIndex;return q!==0?q:D.id-J.id}if(n.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var x=performance;n.unstable_now=function(){return x.now()}}else{var f=Date,p=f.now();n.unstable_now=function(){return f.now()-p}}var g=[],b=[],j=1,y=null,N=3,k=!1,w=!1,U=!1,O=!1,B=typeof setTimeout=="function"?setTimeout:null,Y=typeof clearTimeout=="function"?clearTimeout:null,L=typeof setImmediate<"u"?setImmediate:null;function z(D){for(var J=i(b);J!==null;){if(J.callback===null)d(b);else if(J.startTime<=D)d(b),J.sortIndex=J.expirationTime,r(g,J);else break;J=i(b)}}function K(D){if(U=!1,z(D),!w)if(i(g)!==null)w=!0,I||(I=!0,pe());else{var J=i(b);J!==null&&be(K,J.startTime-D)}}var I=!1,T=-1,A=5,te=-1;function fe(){return O?!0:!(n.unstable_now()-teD&&fe());){var se=y.callback;if(typeof se=="function"){y.callback=null,N=y.priorityLevel;var R=se(y.expirationTime<=D);if(D=n.unstable_now(),typeof R=="function"){y.callback=R,z(D),J=!0;break s}y===i(g)&&d(g),z(D)}else d(g);y=i(g)}if(y!==null)J=!0;else{var ue=i(b);ue!==null&&be(K,ue.startTime-D),J=!1}}break e}finally{y=null,N=q,k=!1}J=void 0}}finally{J?pe():I=!1}}}var pe;if(typeof L=="function")pe=function(){L(je)};else if(typeof MessageChannel<"u"){var he=new MessageChannel,ve=he.port2;he.port1.onmessage=je,pe=function(){ve.postMessage(null)}}else pe=function(){B(je,0)};function be(D,J){T=B(function(){D(n.unstable_now())},J)}n.unstable_IdlePriority=5,n.unstable_ImmediatePriority=1,n.unstable_LowPriority=4,n.unstable_NormalPriority=3,n.unstable_Profiling=null,n.unstable_UserBlockingPriority=2,n.unstable_cancelCallback=function(D){D.callback=null},n.unstable_forceFrameRate=function(D){0>D||125se?(D.sortIndex=q,r(b,D),i(g)===null&&D===i(b)&&(U?(Y(T),T=-1):U=!0,be(K,q-se))):(D.sortIndex=R,r(g,D),w||k||(w=!0,I||(I=!0,pe()))),D},n.unstable_shouldYield=fe,n.unstable_wrapCallback=function(D){var J=N;return function(){var q=N;N=J;try{return D.apply(this,arguments)}finally{N=q}}}})(_u)),_u}var ap;function i0(){return ap||(ap=1,wu.exports=r0()),wu.exports}var lp;function c0(){if(lp)return Wr;lp=1;var n=i0(),r=Vb(),i=Qb();function d(s){var t="https://react.dev/errors/"+s;if(1R||(s.current=se[R],se[R]=null,R--)}function _e(s,t){R++,se[R]=s.current,s.current=t}var Ce=ue(null),ze=ue(null),ge=ue(null),ae=ue(null);function re(s,t){switch(_e(ge,t),_e(ze,s),_e(Ce,null),t.nodeType){case 9:case 11:s=(s=t.documentElement)&&(s=s.namespaceURI)?vf(s):0;break;default:if(s=t.tagName,t=t.namespaceURI)t=vf(t),s=bf(t,s);else switch(s){case"svg":s=1;break;case"math":s=2;break;default:s=0}}me(Ce),_e(Ce,s)}function F(){me(Ce),me(ze),me(ge)}function P(s){s.memoizedState!==null&&_e(ae,s);var t=Ce.current,a=bf(t,s.type);t!==a&&(_e(ze,s),_e(Ce,a))}function Te(s){ze.current===s&&(me(Ce),me(ze)),ae.current===s&&(me(ae),Kr._currentValue=q)}var Le,E;function xe(s){if(Le===void 0)try{throw Error()}catch(a){var t=a.stack.trim().match(/\n( *(at )?)/);Le=t&&t[1]||"",E=-1)":-1c||M[l]!==W[c]){var ce=` `+M[l].replace(" at new "," at ");return s.displayName&&ce.includes("")&&(ce=ce.replace("",s.displayName)),ce}while(1<=l&&0<=c);break}}}finally{Ye=!1,Error.prepareStackTrace=a}return(a=s?s.displayName||s.name:"")?xe(a):""}function Q(s,t){switch(s.tag){case 26:case 27:case 5:return xe(s.type);case 16:return xe("Lazy");case 13:return s.child!==t&&t!==null?xe("Suspense Fallback"):xe("Suspense");case 19:return xe("SuspenseList");case 0:case 15:return ke(s.type,!1);case 11:return ke(s.type.render,!1);case 1:return ke(s.type,!0);case 31:return xe("Activity");default:return""}}function Ne(s){try{var t="",a=null;do t+=Q(s,a),a=s,s=s.return;while(s);return t}catch(l){return` Error generating stack: `+l.message+` `+l.stack}}var qe=Object.prototype.hasOwnProperty,Fs=n.unstable_scheduleCallback,ks=n.unstable_cancelCallback,xt=n.unstable_shouldYield,js=n.unstable_requestPaint,Vs=n.unstable_now,X=n.unstable_getCurrentPriorityLevel,He=n.unstable_ImmediatePriority,De=n.unstable_UserBlockingPriority,Ke=n.unstable_NormalPriority,Ns=n.unstable_LowPriority,Je=n.unstable_IdlePriority,Ks=n.log,ye=n.unstable_setDisableYieldValue,_s=null,Ae=null;function vs(s){if(typeof Ks=="function"&&ye(s),Ae&&typeof Ae.setStrictMode=="function")try{Ae.setStrictMode(_s,s)}catch{}}var bs=Math.clz32?Math.clz32:Ss,Nt=Math.log,Xs=Math.LN2;function Ss(s){return s>>>=0,s===0?32:31-(Nt(s)/Xs|0)|0}var Es=256,Js=262144,Ha=4194304;function Lt(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 ol(s,t,a){var l=s.pendingLanes;if(l===0)return 0;var c=0,o=s.suspendedLanes,h=s.pingedLanes;s=s.warmLanes;var v=l&134217727;return v!==0?(l=v&~o,l!==0?c=Lt(l):(h&=v,h!==0?c=Lt(h):a||(a=v&~s,a!==0&&(c=Lt(a))))):(v=l&~o,v!==0?c=Lt(v):h!==0?c=Lt(h):a||(a=l&~s,a!==0&&(c=Lt(a)))),c===0?0:t!==0&&t!==c&&(t&o)===0&&(o=c&-c,a=t&-t,o>=a||o===32&&(a&4194048)!==0)?t:c}function ba(s,t){return(s.pendingLanes&~(s.suspendedLanes&~s.pingedLanes)&t)===0}function _(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 G(){var s=Ha;return Ha<<=1,(Ha&62914560)===0&&(Ha=4194304),s}function we(s){for(var t=[],a=0;31>a;a++)t.push(s);return t}function Ms(s,t){s.pendingLanes|=t,t!==268435456&&(s.suspendedLanes=0,s.pingedLanes=0,s.warmLanes=0)}function Dt(s,t,a,l,c,o){var h=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 v=s.entanglements,M=s.expirationTimes,W=s.hiddenUpdates;for(a=h&~a;0"u")return null;try{return s.activeElement||s.body}catch{return s.body}}var Aj=/[\n"\\]/g;function ra(s){return s.replace(Aj,function(t){return"\\"+t.charCodeAt(0).toString(16)+" "})}function mo(s,t,a,l,c,o,h,v){s.name="",h!=null&&typeof h!="function"&&typeof h!="symbol"&&typeof h!="boolean"?s.type=h:s.removeAttribute("type"),t!=null?h==="number"?(t===0&&s.value===""||s.value!=t)&&(s.value=""+na(t)):s.value!==""+na(t)&&(s.value=""+na(t)):h!=="submit"&&h!=="reset"||s.removeAttribute("value"),t!=null?xo(s,h,na(t)):a!=null?xo(s,h,na(a)):l!=null&&s.removeAttribute("value"),c==null&&o!=null&&(s.defaultChecked=!!o),c!=null&&(s.checked=c&&typeof c!="function"&&typeof c!="symbol"),v!=null&&typeof v!="function"&&typeof v!="symbol"&&typeof v!="boolean"?s.name=""+na(v):s.removeAttribute("name")}function mm(s,t,a,l,c,o,h,v){if(o!=null&&typeof o!="function"&&typeof o!="symbol"&&typeof o!="boolean"&&(s.type=o),t!=null||a!=null){if(!(o!=="submit"&&o!=="reset"||t!=null)){uo(s);return}a=a!=null?""+na(a):"",t=t!=null?""+na(t):a,v||t===s.value||(s.value=t),s.defaultValue=t}l=l??c,l=typeof l!="function"&&typeof l!="symbol"&&!!l,s.checked=v?s.checked:!!l,s.defaultChecked=!!l,h!=null&&typeof h!="function"&&typeof h!="symbol"&&typeof h!="boolean"&&(s.name=h),uo(s)}function xo(s,t,a){t==="number"&&Ni(s.ownerDocument)===s||s.defaultValue===""+a||(s.defaultValue=""+a)}function fn(s,t,a,l){if(s=s.options,t){t={};for(var c=0;c"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),jo=!1;if($a)try{var mr={};Object.defineProperty(mr,"passive",{get:function(){jo=!0}}),window.addEventListener("test",mr,mr),window.removeEventListener("test",mr,mr)}catch{jo=!1}var ul=null,vo=null,wi=null;function vm(){if(wi)return wi;var s,t=vo,a=t.length,l,c="value"in ul?ul.value:ul.textContent,o=c.length;for(s=0;s=fr),Sm=" ",Cm=!1;function km(s,t){switch(s){case"keyup":return nv.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Tm(s){return s=s.detail,typeof s=="object"&&"data"in s?s.data:null}var vn=!1;function iv(s,t){switch(s){case"compositionend":return Tm(t);case"keypress":return t.which!==32?null:(Cm=!0,Sm);case"textInput":return s=t.data,s===Sm&&Cm?null:s;default:return null}}function cv(s,t){if(vn)return s==="compositionend"||!_o&&km(s,t)?(s=vm(),wi=vo=ul=null,vn=!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=l}e:{for(;a;){if(a.nextSibling){a=a.nextSibling;break e}a=a.parentNode}a=void 0}a=Lm(a)}}function Bm(s,t){return s&&t?s===t?!0:s&&s.nodeType===3?!1:t&&t.nodeType===3?Bm(s,t.parentNode):"contains"in s?s.contains(t):s.compareDocumentPosition?!!(s.compareDocumentPosition(t)&16):!1:!1}function Hm(s){s=s!=null&&s.ownerDocument!=null&&s.ownerDocument.defaultView!=null?s.ownerDocument.defaultView:window;for(var t=Ni(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=Ni(s.document)}return t}function ko(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 pv=$a&&"documentMode"in document&&11>=document.documentMode,bn=null,To=null,vr=null,Eo=!1;function qm(s,t,a){var l=a.window===a?a.document:a.nodeType===9?a:a.ownerDocument;Eo||bn==null||bn!==Ni(l)||(l=bn,"selectionStart"in l&&ko(l)?l={start:l.selectionStart,end:l.selectionEnd}:(l=(l.ownerDocument&&l.ownerDocument.defaultView||window).getSelection(),l={anchorNode:l.anchorNode,anchorOffset:l.anchorOffset,focusNode:l.focusNode,focusOffset:l.focusOffset}),vr&&jr(vr,l)||(vr=l,l=pc(To,"onSelect"),0>=h,c-=h,Ta=1<<32-bs(t)+c|a<es?(ps=Me,Me=null):ps=Me.sibling;var ws=ee(V,Me,Z[es],oe);if(ws===null){Me===null&&(Me=ps);break}s&&Me&&ws.alternate===null&&t(V,Me),H=o(ws,H,es),ys===null?Ge=ws:ys.sibling=ws,ys=ws,Me=ps}if(es===Z.length)return a(V,Me),gs&&Va(V,es),Ge;if(Me===null){for(;eses?(ps=Me,Me=null):ps=Me.sibling;var Dl=ee(V,Me,ws.value,oe);if(Dl===null){Me===null&&(Me=ps);break}s&&Me&&Dl.alternate===null&&t(V,Me),H=o(Dl,H,es),ys===null?Ge=Dl:ys.sibling=Dl,ys=Dl,Me=ps}if(ws.done)return a(V,Me),gs&&Va(V,es),Ge;if(Me===null){for(;!ws.done;es++,ws=Z.next())ws=de(V,ws.value,oe),ws!==null&&(H=o(ws,H,es),ys===null?Ge=ws:ys.sibling=ws,ys=ws);return gs&&Va(V,es),Ge}for(Me=l(Me);!ws.done;es++,ws=Z.next())ws=ne(Me,V,es,ws.value,oe),ws!==null&&(s&&ws.alternate!==null&&Me.delete(ws.key===null?es:ws.key),H=o(ws,H,es),ys===null?Ge=ws:ys.sibling=ws,ys=ws);return s&&Me.forEach(function(Lb){return t(V,Lb)}),gs&&Va(V,es),Ge}function Rs(V,H,Z,oe){if(typeof Z=="object"&&Z!==null&&Z.type===U&&Z.key===null&&(Z=Z.props.children),typeof Z=="object"&&Z!==null){switch(Z.$$typeof){case k:e:{for(var Ge=Z.key;H!==null;){if(H.key===Ge){if(Ge=Z.type,Ge===U){if(H.tag===7){a(V,H.sibling),oe=c(H,Z.props.children),oe.return=V,V=oe;break e}}else if(H.elementType===Ge||typeof Ge=="object"&&Ge!==null&&Ge.$$typeof===A&&Xl(Ge)===H.type){a(V,H.sibling),oe=c(H,Z.props),Sr(oe,Z),oe.return=V,V=oe;break e}a(V,H);break}else t(V,H);H=H.sibling}Z.type===U?(oe=Vl(Z.props.children,V.mode,oe,Z.key),oe.return=V,V=oe):(oe=Di(Z.type,Z.key,Z.props,null,V.mode,oe),Sr(oe,Z),oe.return=V,V=oe)}return h(V);case w:e:{for(Ge=Z.key;H!==null;){if(H.key===Ge)if(H.tag===4&&H.stateNode.containerInfo===Z.containerInfo&&H.stateNode.implementation===Z.implementation){a(V,H.sibling),oe=c(H,Z.children||[]),oe.return=V,V=oe;break e}else{a(V,H);break}else t(V,H);H=H.sibling}oe=Lo(Z,V.mode,oe),oe.return=V,V=oe}return h(V);case A:return Z=Xl(Z),Rs(V,H,Z,oe)}if(be(Z))return Ee(V,H,Z,oe);if(pe(Z)){if(Ge=pe(Z),typeof Ge!="function")throw Error(d(150));return Z=Ge.call(Z),Ie(V,H,Z,oe)}if(typeof Z.then=="function")return Rs(V,H,qi(Z),oe);if(Z.$$typeof===L)return Rs(V,H,Li(V,Z),oe);Gi(V,Z)}return typeof Z=="string"&&Z!==""||typeof Z=="number"||typeof Z=="bigint"?(Z=""+Z,H!==null&&H.tag===6?(a(V,H.sibling),oe=c(H,Z),oe.return=V,V=oe):(a(V,H),oe=Ro(Z,V.mode,oe),oe.return=V,V=oe),h(V)):a(V,H)}return function(V,H,Z,oe){try{_r=0;var Ge=Rs(V,H,Z,oe);return An=null,Ge}catch(Me){if(Me===zn||Me===Bi)throw Me;var ys=Jt(29,Me,null,V.mode);return ys.lanes=oe,ys.return=V,ys}finally{}}}var Zl=ox(!0),dx=ox(!1),pl=!1;function Ko(s){s.updateQueue={baseState:s.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Xo(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 gl(s){return{lane:s,tag:0,payload:null,callback:null,next:null}}function jl(s,t,a){var l=s.updateQueue;if(l===null)return null;if(l=l.shared,(Cs&2)!==0){var c=l.pending;return c===null?t.next=t:(t.next=c.next,c.next=t),l.pending=t,t=Mi(s),Ym(s,null,a),t}return Ai(s,l,t,a),Mi(s)}function Cr(s,t,a){if(t=t.updateQueue,t!==null&&(t=t.shared,(a&4194048)!==0)){var l=t.lanes;l&=s.pendingLanes,a|=l,t.lanes=a,cr(s,a)}}function Jo(s,t){var a=s.updateQueue,l=s.alternate;if(l!==null&&(l=l.updateQueue,a===l)){var c=null,o=null;if(a=a.firstBaseUpdate,a!==null){do{var h={lane:a.lane,tag:a.tag,payload:a.payload,callback:null,next:null};o===null?c=o=h:o=o.next=h,a=a.next}while(a!==null);o===null?c=o=t:o=o.next=t}else c=o=t;a={baseState:l.baseState,firstBaseUpdate:c,lastBaseUpdate:o,shared:l.shared,callbacks:l.callbacks},s.updateQueue=a;return}s=a.lastBaseUpdate,s===null?a.firstBaseUpdate=t:s.next=t,a.lastBaseUpdate=t}var Zo=!1;function kr(){if(Zo){var s=En;if(s!==null)throw s}}function Tr(s,t,a,l){Zo=!1;var c=s.updateQueue;pl=!1;var o=c.firstBaseUpdate,h=c.lastBaseUpdate,v=c.shared.pending;if(v!==null){c.shared.pending=null;var M=v,W=M.next;M.next=null,h===null?o=W:h.next=W,h=M;var ce=s.alternate;ce!==null&&(ce=ce.updateQueue,v=ce.lastBaseUpdate,v!==h&&(v===null?ce.firstBaseUpdate=W:v.next=W,ce.lastBaseUpdate=M))}if(o!==null){var de=c.baseState;h=0,ce=W=M=null,v=o;do{var ee=v.lane&-536870913,ne=ee!==v.lane;if(ne?(fs&ee)===ee:(l&ee)===ee){ee!==0&&ee===Tn&&(Zo=!0),ce!==null&&(ce=ce.next={lane:0,tag:v.tag,payload:v.payload,callback:null,next:null});e:{var Ee=s,Ie=v;ee=t;var Rs=a;switch(Ie.tag){case 1:if(Ee=Ie.payload,typeof Ee=="function"){de=Ee.call(Rs,de,ee);break e}de=Ee;break e;case 3:Ee.flags=Ee.flags&-65537|128;case 0:if(Ee=Ie.payload,ee=typeof Ee=="function"?Ee.call(Rs,de,ee):Ee,ee==null)break e;de=y({},de,ee);break e;case 2:pl=!0}}ee=v.callback,ee!==null&&(s.flags|=64,ne&&(s.flags|=8192),ne=c.callbacks,ne===null?c.callbacks=[ee]:ne.push(ee))}else ne={lane:ee,tag:v.tag,payload:v.payload,callback:v.callback,next:null},ce===null?(W=ce=ne,M=de):ce=ce.next=ne,h|=ee;if(v=v.next,v===null){if(v=c.shared.pending,v===null)break;ne=v,v=ne.next,ne.next=null,c.lastBaseUpdate=ne,c.shared.pending=null}}while(!0);ce===null&&(M=de),c.baseState=M,c.firstBaseUpdate=W,c.lastBaseUpdate=ce,o===null&&(c.shared.lanes=0),wl|=h,s.lanes=h,s.memoizedState=de}}function ux(s,t){if(typeof s!="function")throw Error(d(191,s));s.call(t)}function mx(s,t){var a=s.callbacks;if(a!==null)for(s.callbacks=null,s=0;so?o:8;var h=D.T,v={};D.T=v,pd(s,!1,t,a);try{var M=c(),W=D.S;if(W!==null&&W(v,M),M!==null&&typeof M=="object"&&typeof M.then=="function"){var ce=Sv(M,l);Ar(s,t,ce,sa(s))}else Ar(s,t,l,sa(s))}catch(de){Ar(s,t,{then:function(){},status:"rejected",reason:de},sa())}finally{J.p=o,h!==null&&v.types!==null&&(h.types=v.types),D.T=h}}function Av(){}function hd(s,t,a,l){if(s.tag!==5)throw Error(d(476));var c=Vx(s).queue;Fx(s,c,t,q,a===null?Av:function(){return Qx(s),a(l)})}function Vx(s){var t=s.memoizedState;if(t!==null)return t;t={memoizedState:q,baseState:q,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Ka,lastRenderedState:q},next:null};var a={};return t.next={memoizedState:a,baseState:a,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Ka,lastRenderedState:a},next:null},s.memoizedState=t,s=s.alternate,s!==null&&(s.memoizedState=t),t}function Qx(s){var t=Vx(s);t.next===null&&(t=s.alternate.memoizedState),Ar(s,t.next.queue,{},sa())}function fd(){return Ct(Kr)}function Ix(){return ot().memoizedState}function Yx(){return ot().memoizedState}function Mv(s){for(var t=s.return;t!==null;){switch(t.tag){case 24:case 3:var a=sa();s=gl(a);var l=jl(t,s,a);l!==null&&(Ft(l,t,a),Cr(l,t,a)),t={cache:Vo()},s.payload=t;return}t=t.return}}function Dv(s,t,a){var l=sa();a={lane:l,revertLane:0,gesture:null,action:a,hasEagerState:!1,eagerState:null,next:null},Zi(s)?Xx(t,a):(a=Do(s,t,a,l),a!==null&&(Ft(a,s,l),Jx(a,t,l)))}function Kx(s,t,a){var l=sa();Ar(s,t,a,l)}function Ar(s,t,a,l){var c={lane:l,revertLane:0,gesture:null,action:a,hasEagerState:!1,eagerState:null,next:null};if(Zi(s))Xx(t,c);else{var o=s.alternate;if(s.lanes===0&&(o===null||o.lanes===0)&&(o=t.lastRenderedReducer,o!==null))try{var h=t.lastRenderedState,v=o(h,a);if(c.hasEagerState=!0,c.eagerState=v,Xt(v,h))return Ai(s,t,c,0),Hs===null&&zi(),!1}catch{}finally{}if(a=Do(s,t,c,l),a!==null)return Ft(a,s,l),Jx(a,t,l),!0}return!1}function pd(s,t,a,l){if(l={lane:2,revertLane:Kd(),gesture:null,action:l,hasEagerState:!1,eagerState:null,next:null},Zi(s)){if(t)throw Error(d(479))}else t=Do(s,a,l,2),t!==null&&Ft(t,s,2)}function Zi(s){var t=s.alternate;return s===Pe||t!==null&&t===Pe}function Xx(s,t){Dn=Vi=!0;var a=s.pending;a===null?t.next=t:(t.next=a.next,a.next=t),s.pending=t}function Jx(s,t,a){if((a&4194048)!==0){var l=t.lanes;l&=s.pendingLanes,a|=l,t.lanes=a,cr(s,a)}}var Mr={readContext:Ct,use:Yi,useCallback:at,useContext:at,useEffect:at,useImperativeHandle:at,useLayoutEffect:at,useInsertionEffect:at,useMemo:at,useReducer:at,useRef:at,useState:at,useDebugValue:at,useDeferredValue:at,useTransition:at,useSyncExternalStore:at,useId:at,useHostTransitionStatus:at,useFormState:at,useActionState:at,useOptimistic:at,useMemoCache:at,useCacheRefresh:at};Mr.useEffectEvent=at;var Zx={readContext:Ct,use:Yi,useCallback:function(s,t){return Ot().memoizedState=[s,t===void 0?null:t],s},useContext:Ct,useEffect:Ox,useImperativeHandle:function(s,t,a){a=a!=null?a.concat([s]):null,Xi(4194308,4,Bx.bind(null,t,s),a)},useLayoutEffect:function(s,t){return Xi(4194308,4,s,t)},useInsertionEffect:function(s,t){Xi(4,2,s,t)},useMemo:function(s,t){var a=Ot();t=t===void 0?null:t;var l=s();if(Pl){vs(!0);try{s()}finally{vs(!1)}}return a.memoizedState=[l,t],l},useReducer:function(s,t,a){var l=Ot();if(a!==void 0){var c=a(t);if(Pl){vs(!0);try{a(t)}finally{vs(!1)}}}else c=t;return l.memoizedState=l.baseState=c,s={pending:null,lanes:0,dispatch:null,lastRenderedReducer:s,lastRenderedState:c},l.queue=s,s=s.dispatch=Dv.bind(null,Pe,s),[l.memoizedState,s]},useRef:function(s){var t=Ot();return s={current:s},t.memoizedState=s},useState:function(s){s=od(s);var t=s.queue,a=Kx.bind(null,Pe,t);return t.dispatch=a,[s.memoizedState,a]},useDebugValue:md,useDeferredValue:function(s,t){var a=Ot();return xd(a,s,t)},useTransition:function(){var s=od(!1);return s=Fx.bind(null,Pe,s.queue,!0,!1),Ot().memoizedState=s,[!1,s]},useSyncExternalStore:function(s,t,a){var l=Pe,c=Ot();if(gs){if(a===void 0)throw Error(d(407));a=a()}else{if(a=t(),Hs===null)throw Error(d(349));(fs&127)!==0||jx(l,t,a)}c.memoizedState=a;var o={value:a,getSnapshot:t};return c.queue=o,Ox(bx.bind(null,l,o,s),[s]),l.flags|=2048,Rn(9,{destroy:void 0},vx.bind(null,l,o,a,t),null),a},useId:function(){var s=Ot(),t=Hs.identifierPrefix;if(gs){var a=Ea,l=Ta;a=(l&~(1<<32-bs(l)-1)).toString(32)+a,t="_"+t+"R_"+a,a=Qi++,0<\/script>",o=o.removeChild(o.firstChild);break;case"select":o=typeof l.is=="string"?h.createElement("select",{is:l.is}):h.createElement("select"),l.multiple?o.multiple=!0:l.size&&(o.size=l.size);break;default:o=typeof l.is=="string"?h.createElement(c,{is:l.is}):h.createElement(c)}}o[_t]=t,o[Ut]=l;e:for(h=t.child;h!==null;){if(h.tag===5||h.tag===6)o.appendChild(h.stateNode);else if(h.tag!==4&&h.tag!==27&&h.child!==null){h.child.return=h,h=h.child;continue}if(h===t)break e;for(;h.sibling===null;){if(h.return===null||h.return===t)break e;h=h.return}h.sibling.return=h.return,h=h.sibling}t.stateNode=o;e:switch(Tt(o,c,l),c){case"button":case"input":case"select":case"textarea":l=!!l.autoFocus;break e;case"img":l=!0;break e;default:l=!1}l&&Ja(t)}}return Ys(t),zd(t,t.type,s===null?null:s.memoizedProps,t.pendingProps,a),null;case 6:if(s&&t.stateNode!=null)s.memoizedProps!==l&&Ja(t);else{if(typeof l!="string"&&t.stateNode===null)throw Error(d(166));if(s=ge.current,Cn(t)){if(s=t.stateNode,a=t.memoizedProps,l=null,c=St,c!==null)switch(c.tag){case 27:case 5:l=c.memoizedProps}s[_t]=t,s=!!(s.nodeValue===a||l!==null&&l.suppressHydrationWarning===!0||gf(s.nodeValue,a)),s||hl(t,!0)}else s=gc(s).createTextNode(l),s[_t]=t,t.stateNode=s}return Ys(t),null;case 31:if(a=t.memoizedState,s===null||s.memoizedState!==null){if(l=Cn(t),a!==null){if(s===null){if(!l)throw Error(d(318));if(s=t.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(d(557));s[_t]=t}else Ql(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;Ys(t),s=!1}else a=qo(),s!==null&&s.memoizedState!==null&&(s.memoizedState.hydrationErrors=a),s=!0;if(!s)return t.flags&256?(Pt(t),t):(Pt(t),null);if((t.flags&128)!==0)throw Error(d(558))}return Ys(t),null;case 13:if(l=t.memoizedState,s===null||s.memoizedState!==null&&s.memoizedState.dehydrated!==null){if(c=Cn(t),l!==null&&l.dehydrated!==null){if(s===null){if(!c)throw Error(d(318));if(c=t.memoizedState,c=c!==null?c.dehydrated:null,!c)throw Error(d(317));c[_t]=t}else Ql(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;Ys(t),c=!1}else c=qo(),s!==null&&s.memoizedState!==null&&(s.memoizedState.hydrationErrors=c),c=!0;if(!c)return t.flags&256?(Pt(t),t):(Pt(t),null)}return Pt(t),(t.flags&128)!==0?(t.lanes=a,t):(a=l!==null,s=s!==null&&s.memoizedState!==null,a&&(l=t.child,c=null,l.alternate!==null&&l.alternate.memoizedState!==null&&l.alternate.memoizedState.cachePool!==null&&(c=l.alternate.memoizedState.cachePool.pool),o=null,l.memoizedState!==null&&l.memoizedState.cachePool!==null&&(o=l.memoizedState.cachePool.pool),o!==c&&(l.flags|=2048)),a!==s&&a&&(t.child.flags|=8192),tc(t,t.updateQueue),Ys(t),null);case 4:return F(),s===null&&Pd(t.stateNode.containerInfo),Ys(t),null;case 10:return Ia(t.type),Ys(t),null;case 19:if(me(ct),l=t.memoizedState,l===null)return Ys(t),null;if(c=(t.flags&128)!==0,o=l.rendering,o===null)if(c)Or(l,!1);else{if(lt!==0||s!==null&&(s.flags&128)!==0)for(s=t.child;s!==null;){if(o=Fi(s),o!==null){for(t.flags|=128,Or(l,!1),s=o.updateQueue,t.updateQueue=s,tc(t,s),t.subtreeFlags=0,s=a,a=t.child;a!==null;)Km(a,s),a=a.sibling;return _e(ct,ct.current&1|2),gs&&Va(t,l.treeForkCount),t.child}s=s.sibling}l.tail!==null&&Vs()>ic&&(t.flags|=128,c=!0,Or(l,!1),t.lanes=4194304)}else{if(!c)if(s=Fi(o),s!==null){if(t.flags|=128,c=!0,s=s.updateQueue,t.updateQueue=s,tc(t,s),Or(l,!0),l.tail===null&&l.tailMode==="hidden"&&!o.alternate&&!gs)return Ys(t),null}else 2*Vs()-l.renderingStartTime>ic&&a!==536870912&&(t.flags|=128,c=!0,Or(l,!1),t.lanes=4194304);l.isBackwards?(o.sibling=t.child,t.child=o):(s=l.last,s!==null?s.sibling=o:t.child=o,l.last=o)}return l.tail!==null?(s=l.tail,l.rendering=s,l.tail=s.sibling,l.renderingStartTime=Vs(),s.sibling=null,a=ct.current,_e(ct,c?a&1|2:a&1),gs&&Va(t,l.treeForkCount),s):(Ys(t),null);case 22:case 23:return Pt(t),Wo(),l=t.memoizedState!==null,s!==null?s.memoizedState!==null!==l&&(t.flags|=8192):l&&(t.flags|=8192),l?(a&536870912)!==0&&(t.flags&128)===0&&(Ys(t),t.subtreeFlags&6&&(t.flags|=8192)):Ys(t),a=t.updateQueue,a!==null&&tc(t,a.retryQueue),a=null,s!==null&&s.memoizedState!==null&&s.memoizedState.cachePool!==null&&(a=s.memoizedState.cachePool.pool),l=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(l=t.memoizedState.cachePool.pool),l!==a&&(t.flags|=2048),s!==null&&me(Kl),null;case 24:return a=null,s!==null&&(a=s.memoizedState.cache),t.memoizedState.cache!==a&&(t.flags|=2048),Ia(ht),Ys(t),null;case 25:return null;case 30:return null}throw Error(d(156,t.tag))}function Bv(s,t){switch(Bo(t),t.tag){case 1:return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 3:return Ia(ht),F(),s=t.flags,(s&65536)!==0&&(s&128)===0?(t.flags=s&-65537|128,t):null;case 26:case 27:case 5:return Te(t),null;case 31:if(t.memoizedState!==null){if(Pt(t),t.alternate===null)throw Error(d(340));Ql()}return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 13:if(Pt(t),s=t.memoizedState,s!==null&&s.dehydrated!==null){if(t.alternate===null)throw Error(d(340));Ql()}return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 19:return me(ct),null;case 4:return F(),null;case 10:return Ia(t.type),null;case 22:case 23:return Pt(t),Wo(),s!==null&&me(Kl),s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 24:return Ia(ht),null;case 25:return null;default:return null}}function Nh(s,t){switch(Bo(t),t.tag){case 3:Ia(ht),F();break;case 26:case 27:case 5:Te(t);break;case 4:F();break;case 31:t.memoizedState!==null&&Pt(t);break;case 13:Pt(t);break;case 19:me(ct);break;case 10:Ia(t.type);break;case 22:case 23:Pt(t),Wo(),s!==null&&me(Kl);break;case 24:Ia(ht)}}function Rr(s,t){try{var a=t.updateQueue,l=a!==null?a.lastEffect:null;if(l!==null){var c=l.next;a=c;do{if((a.tag&s)===s){l=void 0;var o=a.create,h=a.inst;l=o(),h.destroy=l}a=a.next}while(a!==c)}}catch(v){As(t,t.return,v)}}function Nl(s,t,a){try{var l=t.updateQueue,c=l!==null?l.lastEffect:null;if(c!==null){var o=c.next;l=o;do{if((l.tag&s)===s){var h=l.inst,v=h.destroy;if(v!==void 0){h.destroy=void 0,c=t;var M=a,W=v;try{W()}catch(ce){As(c,M,ce)}}}l=l.next}while(l!==o)}}catch(ce){As(t,t.return,ce)}}function yh(s){var t=s.updateQueue;if(t!==null){var a=s.stateNode;try{mx(t,a)}catch(l){As(s,s.return,l)}}}function wh(s,t,a){a.props=Wl(s.type,s.memoizedProps),a.state=s.memoizedState;try{a.componentWillUnmount()}catch(l){As(s,t,l)}}function Lr(s,t){try{var a=s.ref;if(a!==null){switch(s.tag){case 26:case 27:case 5:var l=s.stateNode;break;case 30:l=s.stateNode;break;default:l=s.stateNode}typeof a=="function"?s.refCleanup=a(l):a.current=l}}catch(c){As(s,t,c)}}function za(s,t){var a=s.ref,l=s.refCleanup;if(a!==null)if(typeof l=="function")try{l()}catch(c){As(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){As(s,t,c)}else a.current=null}function _h(s){var t=s.type,a=s.memoizedProps,l=s.stateNode;try{e:switch(t){case"button":case"input":case"select":case"textarea":a.autoFocus&&l.focus();break e;case"img":a.src?l.src=a.src:a.srcSet&&(l.srcset=a.srcSet)}}catch(c){As(s,s.return,c)}}function Ad(s,t,a){try{var l=s.stateNode;rb(l,s.type,a,t),l[Ut]=t}catch(c){As(s,s.return,c)}}function Sh(s){return s.tag===5||s.tag===3||s.tag===26||s.tag===27&&Tl(s.type)||s.tag===4}function Md(s){e:for(;;){for(;s.sibling===null;){if(s.return===null||Sh(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&&Tl(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 Dd(s,t,a){var l=s.tag;if(l===5||l===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=Ga));else if(l!==4&&(l===27&&Tl(s.type)&&(a=s.stateNode,t=null),s=s.child,s!==null))for(Dd(s,t,a),s=s.sibling;s!==null;)Dd(s,t,a),s=s.sibling}function ac(s,t,a){var l=s.tag;if(l===5||l===6)s=s.stateNode,t?a.insertBefore(s,t):a.appendChild(s);else if(l!==4&&(l===27&&Tl(s.type)&&(a=s.stateNode),s=s.child,s!==null))for(ac(s,t,a),s=s.sibling;s!==null;)ac(s,t,a),s=s.sibling}function Ch(s){var t=s.stateNode,a=s.memoizedProps;try{for(var l=s.type,c=t.attributes;c.length;)t.removeAttributeNode(c[0]);Tt(t,l,a),t[_t]=s,t[Ut]=a}catch(o){As(s,s.return,o)}}var Za=!1,gt=!1,Od=!1,kh=typeof WeakSet=="function"?WeakSet:Set,wt=null;function Hv(s,t){if(s=s.containerInfo,su=_c,s=Hm(s),ko(s)){if("selectionStart"in s)var a={start:s.selectionStart,end:s.selectionEnd};else e:{a=(a=s.ownerDocument)&&a.defaultView||window;var l=a.getSelection&&a.getSelection();if(l&&l.rangeCount!==0){a=l.anchorNode;var c=l.anchorOffset,o=l.focusNode;l=l.focusOffset;try{a.nodeType,o.nodeType}catch{a=null;break e}var h=0,v=-1,M=-1,W=0,ce=0,de=s,ee=null;s:for(;;){for(var ne;de!==a||c!==0&&de.nodeType!==3||(v=h+c),de!==o||l!==0&&de.nodeType!==3||(M=h+l),de.nodeType===3&&(h+=de.nodeValue.length),(ne=de.firstChild)!==null;)ee=de,de=ne;for(;;){if(de===s)break s;if(ee===a&&++W===c&&(v=h),ee===o&&++ce===l&&(M=h),(ne=de.nextSibling)!==null)break;de=ee,ee=de.parentNode}de=ne}a=v===-1||M===-1?null:{start:v,end:M}}else a=null}a=a||{start:0,end:0}}else a=null;for(tu={focusedElem:s,selectionRange:a},_c=!1,wt=t;wt!==null;)if(t=wt,s=t.child,(t.subtreeFlags&1028)!==0&&s!==null)s.return=t,wt=s;else for(;wt!==null;){switch(t=wt,o=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"))),Tt(o,l,a),o[_t]=s,yt(o),l=o;break e;case"link":var h=Of("link","href",c).get(l+(a.href||""));if(h){for(var v=0;vRs&&(h=Rs,Rs=Ie,Ie=h);var V=Um(v,Ie),H=Um(v,Rs);if(V&&H&&(ne.rangeCount!==1||ne.anchorNode!==V.node||ne.anchorOffset!==V.offset||ne.focusNode!==H.node||ne.focusOffset!==H.offset)){var Z=de.createRange();Z.setStart(V.node,V.offset),ne.removeAllRanges(),Ie>Rs?(ne.addRange(Z),ne.extend(H.node,H.offset)):(Z.setEnd(H.node,H.offset),ne.addRange(Z))}}}}for(de=[],ne=v;ne=ne.parentNode;)ne.nodeType===1&&de.push({element:ne,left:ne.scrollLeft,top:ne.scrollTop});for(typeof v.focus=="function"&&v.focus(),v=0;va?32:a,D.T=null,a=Gd,Gd=null;var o=Sl,h=tl;if(vt=0,qn=Sl=null,tl=0,(Cs&6)!==0)throw Error(d(331));var v=Cs;if(Cs|=4,Bh(o.current),Rh(o,o.current,h,a),Cs=v,$r(0,!1),Ae&&typeof Ae.onPostCommitFiberRoot=="function")try{Ae.onPostCommitFiberRoot(_s,o)}catch{}return!0}finally{J.p=c,D.T=l,tf(s,t)}}function lf(s,t,a){t=ca(a,t),t=bd(s.stateNode,t,2),s=jl(s,t,2),s!==null&&(Ms(s,2),Aa(s))}function As(s,t,a){if(s.tag===3)lf(s,s,a);else for(;t!==null;){if(t.tag===3){lf(t,s,a);break}else if(t.tag===1){var l=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof l.componentDidCatch=="function"&&(_l===null||!_l.has(l))){s=ca(a,s),a=nh(2),l=jl(t,a,2),l!==null&&(rh(a,l,t,s),Ms(l,2),Aa(l));break}}t=t.return}}function Qd(s,t,a){var l=s.pingCache;if(l===null){l=s.pingCache=new $v;var c=new Set;l.set(t,c)}else c=l.get(t),c===void 0&&(c=new Set,l.set(t,c));c.has(a)||(Ud=!0,c.add(a),s=Yv.bind(null,s,t,a),t.then(s,s))}function Yv(s,t,a){var l=s.pingCache;l!==null&&l.delete(t),s.pingedLanes|=s.suspendedLanes&a,s.warmLanes&=~a,Hs===s&&(fs&a)===a&&(lt===4||lt===3&&(fs&62914560)===fs&&300>Vs()-rc?(Cs&2)===0&&Gn(s,0):Bd|=a,Hn===fs&&(Hn=0)),Aa(s)}function nf(s,t){t===0&&(t=G()),s=Fl(s,t),s!==null&&(Ms(s,t),Aa(s))}function Kv(s){var t=s.memoizedState,a=0;t!==null&&(a=t.retryLane),nf(s,a)}function Xv(s,t){var a=0;switch(s.tag){case 31:case 13:var l=s.stateNode,c=s.memoizedState;c!==null&&(a=c.retryLane);break;case 19:l=s.stateNode;break;case 22:l=s.stateNode._retryCache;break;default:throw Error(d(314))}l!==null&&l.delete(t),nf(s,a)}function Jv(s,t){return Fs(s,t)}var xc=null,Fn=null,Id=!1,hc=!1,Yd=!1,kl=0;function Aa(s){s!==Fn&&s.next===null&&(Fn===null?xc=Fn=s:Fn=Fn.next=s),hc=!0,Id||(Id=!0,Pv())}function $r(s,t){if(!Yd&&hc){Yd=!0;do for(var a=!1,l=xc;l!==null;){if(s!==0){var c=l.pendingLanes;if(c===0)var o=0;else{var h=l.suspendedLanes,v=l.pingedLanes;o=(1<<31-bs(42|s)+1)-1,o&=c&~(h&~v),o=o&201326741?o&201326741|1:o?o|2:0}o!==0&&(a=!0,df(l,o))}else o=fs,o=ol(l,l===Hs?o:0,l.cancelPendingCommit!==null||l.timeoutHandle!==-1),(o&3)===0||ba(l,o)||(a=!0,df(l,o));l=l.next}while(a);Yd=!1}}function Zv(){rf()}function rf(){hc=Id=!1;var s=0;kl!==0&&cb()&&(s=kl);for(var t=Vs(),a=null,l=xc;l!==null;){var c=l.next,o=cf(l,t);o===0?(l.next=null,a===null?xc=c:a.next=c,c===null&&(Fn=a)):(a=l,(s!==0||(o&3)!==0)&&(hc=!0)),l=c}vt!==0&&vt!==5||$r(s),kl!==0&&(kl=0)}function cf(s,t){for(var a=s.suspendedLanes,l=s.pingedLanes,c=s.expirationTimes,o=s.pendingLanes&-62914561;0v)break;var ce=M.transferSize,de=M.initiatorType;ce&&jf(de)&&(M=M.responseEnd,h+=ce*(M"u"?null:document;function zf(s,t,a){var l=Vn;if(l&&typeof t=="string"&&t){var c=ra(t);c='link[rel="'+s+'"][href="'+c+'"]',typeof a=="string"&&(c+='[crossorigin="'+a+'"]'),Ef.has(c)||(Ef.add(c),s={rel:s,crossOrigin:a,href:t},l.querySelector(c)===null&&(t=l.createElement("link"),Tt(t,"link",s),yt(t),l.head.appendChild(t)))}}function gb(s){al.D(s),zf("dns-prefetch",s,null)}function jb(s,t){al.C(s,t),zf("preconnect",s,t)}function vb(s,t,a){al.L(s,t,a);var l=Vn;if(l&&s&&t){var c='link[rel="preload"][as="'+ra(t)+'"]';t==="image"&&a&&a.imageSrcSet?(c+='[imagesrcset="'+ra(a.imageSrcSet)+'"]',typeof a.imageSizes=="string"&&(c+='[imagesizes="'+ra(a.imageSizes)+'"]')):c+='[href="'+ra(s)+'"]';var o=c;switch(t){case"style":o=Qn(s);break;case"script":o=In(s)}ha.has(o)||(s=y({rel:"preload",href:t==="image"&&a&&a.imageSrcSet?void 0:s,as:t},a),ha.set(o,s),l.querySelector(c)!==null||t==="style"&&l.querySelector(Ir(o))||t==="script"&&l.querySelector(Yr(o))||(t=l.createElement("link"),Tt(t,"link",s),yt(t),l.head.appendChild(t)))}}function bb(s,t){al.m(s,t);var a=Vn;if(a&&s){var l=t&&typeof t.as=="string"?t.as:"script",c='link[rel="modulepreload"][as="'+ra(l)+'"][href="'+ra(s)+'"]',o=c;switch(l){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":o=In(s)}if(!ha.has(o)&&(s=y({rel:"modulepreload",href:s},t),ha.set(o,s),a.querySelector(c)===null)){switch(l){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(a.querySelector(Yr(o)))return}l=a.createElement("link"),Tt(l,"link",s),yt(l),a.head.appendChild(l)}}}function Nb(s,t,a){al.S(s,t,a);var l=Vn;if(l&&s){var c=xn(l).hoistableStyles,o=Qn(s);t=t||"default";var h=c.get(o);if(!h){var v={loading:0,preload:null};if(h=l.querySelector(Ir(o)))v.loading=5;else{s=y({rel:"stylesheet",href:s,"data-precedence":t},a),(a=ha.get(o))&&ou(s,a);var M=h=l.createElement("link");yt(M),Tt(M,"link",s),M._p=new Promise(function(W,ce){M.onload=W,M.onerror=ce}),M.addEventListener("load",function(){v.loading|=1}),M.addEventListener("error",function(){v.loading|=2}),v.loading|=4,vc(h,t,l)}h={type:"stylesheet",instance:h,count:1,state:v},c.set(o,h)}}}function yb(s,t){al.X(s,t);var a=Vn;if(a&&s){var l=xn(a).hoistableScripts,c=In(s),o=l.get(c);o||(o=a.querySelector(Yr(c)),o||(s=y({src:s,async:!0},t),(t=ha.get(c))&&du(s,t),o=a.createElement("script"),yt(o),Tt(o,"link",s),a.head.appendChild(o)),o={type:"script",instance:o,count:1,state:null},l.set(c,o))}}function wb(s,t){al.M(s,t);var a=Vn;if(a&&s){var l=xn(a).hoistableScripts,c=In(s),o=l.get(c);o||(o=a.querySelector(Yr(c)),o||(s=y({src:s,async:!0,type:"module"},t),(t=ha.get(c))&&du(s,t),o=a.createElement("script"),yt(o),Tt(o,"link",s),a.head.appendChild(o)),o={type:"script",instance:o,count:1,state:null},l.set(c,o))}}function Af(s,t,a,l){var c=(c=ge.current)?jc(c):null;if(!c)throw Error(d(446));switch(s){case"meta":case"title":return null;case"style":return typeof a.precedence=="string"&&typeof a.href=="string"?(t=Qn(a.href),a=xn(c).hoistableStyles,l=a.get(t),l||(l={type:"style",instance:null,count:0,state:null},a.set(t,l)),l):{type:"void",instance:null,count:0,state:null};case"link":if(a.rel==="stylesheet"&&typeof a.href=="string"&&typeof a.precedence=="string"){s=Qn(a.href);var o=xn(c).hoistableStyles,h=o.get(s);if(h||(c=c.ownerDocument||c,h={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},o.set(s,h),(o=c.querySelector(Ir(s)))&&!o._p&&(h.instance=o,h.state.loading=5),ha.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},ha.set(s,a),o||_b(c,s,a,h.state))),t&&l===null)throw Error(d(528,""));return h}if(t&&l!==null)throw Error(d(529,""));return null;case"script":return t=a.async,a=a.src,typeof a=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=In(a),a=xn(c).hoistableScripts,l=a.get(t),l||(l={type:"script",instance:null,count:0,state:null},a.set(t,l)),l):{type:"void",instance:null,count:0,state:null};default:throw Error(d(444,s))}}function Qn(s){return'href="'+ra(s)+'"'}function Ir(s){return'link[rel="stylesheet"]['+s+"]"}function Mf(s){return y({},s,{"data-precedence":s.precedence,precedence:null})}function _b(s,t,a,l){s.querySelector('link[rel="preload"][as="style"]['+t+"]")?l.loading=1:(t=s.createElement("link"),l.preload=t,t.addEventListener("load",function(){return l.loading|=1}),t.addEventListener("error",function(){return l.loading|=2}),Tt(t,"link",a),yt(t),s.head.appendChild(t))}function In(s){return'[src="'+ra(s)+'"]'}function Yr(s){return"script[async]"+s}function Df(s,t,a){if(t.count++,t.instance===null)switch(t.type){case"style":var l=s.querySelector('style[data-href~="'+ra(a.href)+'"]');if(l)return t.instance=l,yt(l),l;var c=y({},a,{"data-href":a.href,"data-precedence":a.precedence,href:null,precedence:null});return l=(s.ownerDocument||s).createElement("style"),yt(l),Tt(l,"style",c),vc(l,a.precedence,s),t.instance=l;case"stylesheet":c=Qn(a.href);var o=s.querySelector(Ir(c));if(o)return t.state.loading|=4,t.instance=o,yt(o),o;l=Mf(a),(c=ha.get(c))&&ou(l,c),o=(s.ownerDocument||s).createElement("link"),yt(o);var h=o;return h._p=new Promise(function(v,M){h.onload=v,h.onerror=M}),Tt(o,"link",l),t.state.loading|=4,vc(o,a.precedence,s),t.instance=o;case"script":return o=In(a.src),(c=s.querySelector(Yr(o)))?(t.instance=c,yt(c),c):(l=a,(c=ha.get(o))&&(l=y({},a),du(l,c)),s=s.ownerDocument||s,c=s.createElement("script"),yt(c),Tt(c,"link",l),s.head.appendChild(c),t.instance=c);case"void":return null;default:throw Error(d(443,t.type))}else t.type==="stylesheet"&&(t.state.loading&4)===0&&(l=t.instance,t.state.loading|=4,vc(l,a.precedence,s));return t.instance}function vc(s,t,a){for(var l=a.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),c=l.length?l[l.length-1]:null,o=c,h=0;h title"):null)}function Sb(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 Lf(s){return!(s.type==="stylesheet"&&(s.state.loading&3)===0)}function Cb(s,t,a,l){if(a.type==="stylesheet"&&(typeof l.media!="string"||matchMedia(l.media).matches!==!1)&&(a.state.loading&4)===0){if(a.instance===null){var c=Qn(l.href),o=t.querySelector(Ir(c));if(o){t=o._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(s.count++,s=Nc.bind(s),t.then(s,s)),a.state.loading|=4,a.instance=o,yt(o);return}o=t.ownerDocument||t,l=Mf(l),(c=ha.get(c))&&ou(l,c),o=o.createElement("link"),yt(o);var h=o;h._p=new Promise(function(v,M){h.onload=v,h.onerror=M}),Tt(o,"link",l),a.instance=o}s.stylesheets===null&&(s.stylesheets=new Map),s.stylesheets.set(a,t),(t=a.state.preload)&&(a.state.loading&3)===0&&(s.count++,a=Nc.bind(s),t.addEventListener("load",a),t.addEventListener("error",a))}}var uu=0;function kb(s,t){return s.stylesheets&&s.count===0&&wc(s,s.stylesheets),0uu?50:800)+t);return s.unsuspend=a,function(){s.unsuspend=null,clearTimeout(l),clearTimeout(c)}}:null}function Nc(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)wc(this,this.stylesheets);else if(this.unsuspend){var s=this.unsuspend;this.unsuspend=null,s()}}}var yc=null;function wc(s,t){s.stylesheets=null,s.unsuspend!==null&&(s.count++,yc=new Map,t.forEach(Tb,s),yc=null,Nc.call(s))}function Tb(s,t){if(!(t.state.loading&4)){var a=yc.get(s);if(a)var l=a.get(null);else{a=new Map,yc.set(s,a);for(var c=s.querySelectorAll("link[data-precedence],style[data-precedence]"),o=0;o"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(r){console.error(r)}}return n(),yu.exports=c0(),yu.exports}var d0=o0();function $(...n){return Yb(Kb(n))}const Fe=u.forwardRef(({className:n,...r},i)=>e.jsx("div",{ref:i,className:$("rounded-xl border bg-card text-card-foreground shadow",n),...r}));Fe.displayName="Card";const ts=u.forwardRef(({className:n,...r},i)=>e.jsx("div",{ref:i,className:$("flex flex-col space-y-1.5 p-6",n),...r}));ts.displayName="CardHeader";const as=u.forwardRef(({className:n,...r},i)=>e.jsx("div",{ref:i,className:$("font-semibold leading-none tracking-tight",n),...r}));as.displayName="CardTitle";const et=u.forwardRef(({className:n,...r},i)=>e.jsx("div",{ref:i,className:$("text-sm text-muted-foreground",n),...r}));et.displayName="CardDescription";const xs=u.forwardRef(({className:n,...r},i)=>e.jsx("div",{ref:i,className:$("p-6 pt-0",n),...r}));xs.displayName="CardContent";const Sg=u.forwardRef(({className:n,...r},i)=>e.jsx("div",{ref:i,className:$("flex items-center p-6 pt-0",n),...r}));Sg.displayName="CardFooter";const ga=Xb,la=u.forwardRef(({className:n,...r},i)=>e.jsx(Sp,{ref:i,className:$("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",n),...r}));la.displayName=Sp.displayName;const ss=u.forwardRef(({className:n,...r},i)=>e.jsx(Cp,{ref:i,className:$("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",n),...r}));ss.displayName=Cp.displayName;const Ts=u.forwardRef(({className:n,...r},i)=>e.jsx(kp,{ref:i,className:$("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",n),...r}));Ts.displayName=kp.displayName;const Ze=u.forwardRef(({className:n,children:r,viewportRef:i,...d},m)=>e.jsxs(Tp,{ref:m,className:$("relative overflow-hidden",n),...d,children:[e.jsx(Jb,{ref:i,className:"h-full w-full rounded-[inherit]",children:r}),e.jsx(Uu,{}),e.jsx(Uu,{orientation:"horizontal"}),e.jsx(Zb,{})]}));Ze.displayName=Tp.displayName;const Uu=u.forwardRef(({className:n,orientation:r="vertical",...i},d)=>e.jsx(Ep,{ref:d,orientation:r,className:$("flex touch-none select-none transition-colors",r==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",r==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",n),...i,children:e.jsx(Pb,{className:"relative flex-1 rounded-full bg-border"})}));Uu.displayName=Ep.displayName;function Cg({className:n,...r}){return e.jsx("div",{className:$("animate-pulse rounded-md bg-primary/10",n),...r})}const rr=u.forwardRef(({className:n,value:r,...i},d)=>e.jsx(zp,{ref:d,className:$("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",n),...i,children:e.jsx(Wb,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(r||0)}%)`}})}));rr.displayName=zp.displayName;const u0={light:"",dark:".dark"},kg=u.createContext(null);function Tg(){const n=u.useContext(kg);if(!n)throw new Error("useChart must be used within a ");return n}const Xn=u.forwardRef(({id:n,className:r,children:i,config:d,...m},x)=>{const f=u.useId(),p=`chart-${n||f.replace(/:/g,"")}`;return e.jsx(kg.Provider,{value:{config:d},children:e.jsxs("div",{"data-chart":p,ref:x,className:$("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",r),...m,children:[e.jsx(m0,{id:p,config:d}),e.jsx(fN,{children:i})]})})});Xn.displayName="Chart";const m0=({id:n,config:r})=>{const i=Object.entries(r).filter(([,d])=>d.theme||d.color);return i.length?e.jsx("style",{dangerouslySetInnerHTML:{__html:Object.entries(u0).map(([d,m])=>` ${m} [data-chart=${n}] { ${i.map(([x,f])=>{const p=f.theme?.[d]||f.color;return p?` --color-${x}: ${p};`:null}).join(` `)} } `).join(` `)}}):null},ei=pN,Jn=u.forwardRef(({active:n,payload:r,className:i,indicator:d="dot",hideLabel:m=!1,hideIndicator:x=!1,label:f,labelFormatter:p,labelClassName:g,formatter:b,color:j,nameKey:y,labelKey:N},k)=>{const{config:w}=Tg(),U=u.useMemo(()=>{if(m||!r?.length)return null;const[B]=r,Y=`${N||B?.dataKey||B?.name||"value"}`,L=Bu(w,B,Y),z=!N&&typeof f=="string"?w[f]?.label||f:L?.label;return p?e.jsx("div",{className:$("font-medium",g),children:p(z,r)}):z?e.jsx("div",{className:$("font-medium",g),children:z}):null},[f,p,r,m,g,w,N]);if(!n||!r?.length)return null;const O=r.length===1&&d!=="dot";return e.jsxs("div",{ref:k,className:$("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",i),children:[O?null:U,e.jsx("div",{className:"grid gap-1.5",children:r.filter(B=>B.type!=="none").map((B,Y)=>{const L=`${y||B.name||B.dataKey||"value"}`,z=Bu(w,B,L),K=j||B.payload.fill||B.color;return e.jsx("div",{className:$("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",d==="dot"&&"items-center"),children:b&&B?.value!==void 0&&B.name?b(B.value,B.name,B,Y,B.payload):e.jsxs(e.Fragment,{children:[z?.icon?e.jsx(z.icon,{}):!x&&e.jsx("div",{className:$("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":d==="dot","w-1":d==="line","w-0 border-[1.5px] border-dashed bg-transparent":d==="dashed","my-0.5":O&&d==="dashed"}),style:{"--color-bg":K,"--color-border":K}}),e.jsxs("div",{className:$("flex flex-1 justify-between leading-none",O?"items-end":"items-center"),children:[e.jsxs("div",{className:"grid gap-1.5",children:[O?U:null,e.jsx("span",{className:"text-muted-foreground",children:z?.label||B.name})]}),B.value&&e.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:B.value.toLocaleString()})]})]})},B.dataKey)})})]})});Jn.displayName="ChartTooltip";const x0=gN,Eg=u.forwardRef(({className:n,hideIcon:r=!1,payload:i,verticalAlign:d="bottom",nameKey:m},x)=>{const{config:f}=Tg();return i?.length?e.jsx("div",{ref:x,className:$("flex items-center justify-center gap-4",d==="top"?"pb-3":"pt-3",n),children:i.filter(p=>p.type!=="none").map(p=>{const g=`${m||p.dataKey||"value"}`,b=Bu(f,p,g);return e.jsxs("div",{className:$("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[b?.icon&&!r?e.jsx(b.icon,{}):e.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:p.color}}),b?.label]},p.value)})}):null});Eg.displayName="ChartLegend";function Bu(n,r,i){if(typeof r!="object"||r===null)return;const d="payload"in r&&typeof r.payload=="object"&&r.payload!==null?r.payload:void 0;let m=i;return i in r&&typeof r[i]=="string"?m=r[i]:d&&i in d&&typeof d[i]=="string"&&(m=d[i]),m in n?n[m]:n[i]}const ui=tr("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"}}),S=u.forwardRef(({className:n,variant:r,size:i,asChild:d=!1,...m},x)=>{const f=d?wN:"button";return e.jsx(f,{className:$(ui({variant:r,size:i,className:n})),ref:x,...m})});S.displayName="Button";const h0=tr("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 Qe({className:n,variant:r,...i}){return e.jsx("div",{className:$(h0({variant:r}),n),...i})}const f0=5,p0=5e3;let Su=0;function g0(){return Su=(Su+1)%Number.MAX_SAFE_INTEGER,Su.toString()}const Cu=new Map,rp=n=>{if(Cu.has(n))return;const r=setTimeout(()=>{Cu.delete(n),ii({type:"REMOVE_TOAST",toastId:n})},p0);Cu.set(n,r)},j0=(n,r)=>{switch(r.type){case"ADD_TOAST":return{...n,toasts:[r.toast,...n.toasts].slice(0,f0)};case"UPDATE_TOAST":return{...n,toasts:n.toasts.map(i=>i.id===r.toast.id?{...i,...r.toast}:i)};case"DISMISS_TOAST":{const{toastId:i}=r;return i?rp(i):n.toasts.forEach(d=>{rp(d.id)}),{...n,toasts:n.toasts.map(d=>d.id===i||i===void 0?{...d,open:!1}:d)}}case"REMOVE_TOAST":return r.toastId===void 0?{...n,toasts:[]}:{...n,toasts:n.toasts.filter(i=>i.id!==r.toastId)}}},qc=[];let Gc={toasts:[]};function ii(n){Gc=j0(Gc,n),qc.forEach(r=>{r(Gc)})}function v0({...n}){const r=g0(),i=m=>ii({type:"UPDATE_TOAST",toast:{...m,id:r}}),d=()=>ii({type:"DISMISS_TOAST",toastId:r});return ii({type:"ADD_TOAST",toast:{...n,id:r,open:!0,onOpenChange:m=>{m||d()}}}),{id:r,dismiss:d,update:i}}function $s(){const[n,r]=u.useState(Gc);return u.useEffect(()=>(qc.push(r),()=>{const i=qc.indexOf(r);i>-1&&qc.splice(i,1)}),[n]),{...n,toast:v0,dismiss:i=>ii({type:"DISMISS_TOAST",toastId:i})}}const b0=n=>{const r=[];for(let i=0;i{try{k(!0);const R=await Ac.get("https://v1.hitokoto.cn/?c=a&c=b&c=c&c=d&c=h&c=i&c=k");y({hitokoto:R.data.hitokoto,from:R.data.from||R.data.from_who||"未知"})}catch(R){console.error("获取一言失败:",R),y({hitokoto:"人生就像一盒巧克力,你永远不知道下一颗是什么味道。",from:"阿甘正传"})}finally{k(!1)}},[]),z=u.useCallback(async()=>{try{const R=localStorage.getItem("access-token"),ue=await Ac.get("/api/webui/system/status",{headers:{Authorization:`Bearer ${R}`}});U(ue.data)}catch(R){console.error("获取机器人状态失败:",R),U(null)}},[]),K=async()=>{if(!O)try{B(!0);const R=localStorage.getItem("access-token");await Ac.post("/api/webui/system/restart",{},{headers:{Authorization:`Bearer ${R}`}}),Y({title:"重启中",description:"麦麦正在重启,请稍候..."}),setTimeout(()=>{z(),B(!1)},3e3)}catch(R){console.error("重启失败:",R),Y({title:"重启失败",description:"无法重启麦麦,请检查控制台",variant:"destructive"}),B(!1)}},I=u.useCallback(async()=>{try{const R=localStorage.getItem("access-token"),ue=await Ac.get(`/api/webui/statistics/dashboard?hours=${f}`,{headers:{Authorization:`Bearer ${R}`}});r(ue.data),d(!1),x(100)}catch(R){console.error("Failed to fetch dashboard data:",R),d(!1),x(100)}},[f]);if(u.useEffect(()=>{if(!i)return;x(0);const R=setTimeout(()=>x(15),200),ue=setTimeout(()=>x(30),800),me=setTimeout(()=>x(45),2e3),_e=setTimeout(()=>x(60),4e3),Ce=setTimeout(()=>x(75),6500),ze=setTimeout(()=>x(85),9e3),ge=setTimeout(()=>x(92),11e3);return()=>{clearTimeout(R),clearTimeout(ue),clearTimeout(me),clearTimeout(_e),clearTimeout(Ce),clearTimeout(ze),clearTimeout(ge)}},[i]),u.useEffect(()=>{I(),L(),z()},[I,L,z]),u.useEffect(()=>{if(!g)return;const R=setInterval(()=>{I(),z()},3e4);return()=>clearInterval(R)},[g,I,z]),i||!n)return e.jsx("div",{className:"flex items-center justify-center h-[calc(100vh-200px)]",children:e.jsxs("div",{className:"text-center space-y-6 w-full max-w-md px-4",children:[e.jsx(zt,{className:"h-12 w-12 animate-spin mx-auto text-primary"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-lg font-medium",children:"加载统计数据中..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"正在获取麦麦运行数据"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(rr,{value:m,className:"h-2"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[m,"%"]})]})]})});const{summary:T,model_stats:A=[],hourly_data:te=[],daily_data:fe=[],recent_activity:je=[]}=n,pe=T??{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},he=R=>{const ue=Math.floor(R/3600),me=Math.floor(R%3600/60);return`${ue}小时${me}分钟`},ve=R=>{const ue=R.toLocaleString("zh-CN");return R>=1e9?{display:`${(R/1e9).toFixed(2)}B`,exact:ue,needsExact:!0}:R>=1e6?{display:`${(R/1e6).toFixed(2)}M`,exact:ue,needsExact:!0}:R>=1e4?{display:`${(R/1e3).toFixed(1)}K`,exact:ue,needsExact:!0}:R>=1e3?{display:`${(R/1e3).toFixed(2)}K`,exact:ue,needsExact:!0}:{display:ue,exact:ue,needsExact:!1}},be=R=>{const ue=`¥${R.toLocaleString("zh-CN",{minimumFractionDigits:2,maximumFractionDigits:2})}`;return R>=1e6?{display:`¥${(R/1e6).toFixed(2)}M`,exact:ue,needsExact:!0}:R>=1e4?{display:`¥${(R/1e3).toFixed(1)}K`,exact:ue,needsExact:!0}:R>=1e3?{display:`¥${(R/1e3).toFixed(2)}K`,exact:ue,needsExact:!0}:{display:ue,exact:ue,needsExact:!1}},D=R=>new Date(R).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),J=b0(A.length),q=A.map((R,ue)=>({name:R.model_name,value:R.request_count,fill:J[ue]})),se={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(ga,{value:f.toString(),onValueChange:R=>p(Number(R)),children:e.jsxs(la,{className:"grid grid-cols-3 w-full sm:w-auto",children:[e.jsx(ss,{value:"24",children:"24小时"}),e.jsx(ss,{value:"168",children:"7天"}),e.jsx(ss,{value:"720",children:"30天"})]})}),e.jsxs(S,{variant:g?"default":"outline",size:"sm",onClick:()=>b(!g),className:"gap-2",children:[e.jsx(zt,{className:`h-4 w-4 ${g?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"自动刷新"})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:I,children:e.jsx(zt,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 rounded-lg border border-dashed border-muted-foreground/30 bg-muted/20",children:[N?e.jsx(Cg,{className:"h-5 flex-1"}):j?e.jsxs("p",{className:"flex-1 text-sm text-muted-foreground italic truncate",children:['"',j.hitokoto,'" —— ',j.from]}):null,e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:L,disabled:N,children:e.jsx(zt,{className:`h-3.5 w-3.5 ${N?"animate-spin":""}`})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-3",children:[e.jsxs(Fe,{className:"lg:col-span-1",children:[e.jsx(ts,{className:"pb-3",children:e.jsxs(as,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(hi,{className:"h-4 w-4"}),"麦麦状态"]})}),e.jsx(xs,{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(Qe,{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(Qe,{variant:"outline",className:"text-red-600 border-red-300 bg-red-50",children:[e.jsx(At,{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:["运行 ",he(w.uptime)]})]})]})})]}),e.jsxs(Fe,{children:[e.jsx(ts,{className:"pb-3",children:e.jsxs(as,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(an,{className:"h-4 w-4"}),"快速操作"]})}),e.jsx(xs,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:K,disabled:O,className:"gap-2",children:[e.jsx($c,{className:`h-4 w-4 ${O?"animate-spin":""}`}),O?"重启中...":"重启麦麦"]}),e.jsx(S,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Kn,{to:"/logs",children:[e.jsx(Sa,{className:"h-4 w-4"}),"查看日志"]})}),e.jsx(S,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Kn,{to:"/plugins",children:[e.jsx(IN,{className:"h-4 w-4"}),"插件管理"]})}),e.jsx(S,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Kn,{to:"/settings",children:[e.jsx(ar,{className:"h-4 w-4"}),"系统设置"]})})]})})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{className:"pb-3",children:[e.jsxs(as,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(YN,{className:"h-4 w-4"}),"反馈问卷"]}),e.jsx(et,{className:"text-xs",children:"帮助我们改进产品体验"})]}),e.jsx(xs,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Kn,{to:"/survey/webui-feedback",children:[e.jsx(Sa,{className:"h-4 w-4"}),"WebUI 反馈"]})}),e.jsx(S,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Kn,{to:"/survey/maibot-feedback",children:[e.jsx(Rl,{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(Fe,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(as,{className:"text-sm font-medium",children:"总请求数"}),e.jsx(KN,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(xs,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[ve(pe.total_requests).display,ve(pe.total_requests).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",ve(pe.total_requests).exact,")"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["最近",f<48?f+"小时":Math.floor(f/24)+"天"]})]})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(as,{className:"text-sm font-medium",children:"总花费"}),e.jsx(XN,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(xs,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[be(pe.total_cost).display,be(pe.total_cost).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",be(pe.total_cost).exact,")"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:pe.cost_per_hour>0?`¥${pe.cost_per_hour.toFixed(2)}/小时`:"暂无数据"})]})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(as,{className:"text-sm font-medium",children:"Token消耗"}),e.jsx(Fc,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(xs,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[ve(pe.total_tokens).display,ve(pe.total_tokens).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",ve(pe.total_tokens).exact,")"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:pe.tokens_per_hour>0?`${ve(pe.tokens_per_hour).display}/小时`:"暂无数据"})]})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(as,{className:"text-sm font-medium",children:"平均响应"}),e.jsx(an,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(xs,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[pe.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(Fe,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(as,{className:"text-sm font-medium",children:"在线时长"}),e.jsx(Pn,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(xs,{children:e.jsxs("div",{className:"text-xl font-bold",children:[he(pe.online_time),e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",pe.online_time.toLocaleString(),"秒)"]})]})})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(as,{className:"text-sm font-medium",children:"消息处理"}),e.jsx(Rl,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(xs,{children:[e.jsxs("div",{className:"text-xl font-bold",children:[ve(pe.total_messages).display,ve(pe.total_messages).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",ve(pe.total_messages).exact,")"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["回复 ",ve(pe.total_replies).display,ve(pe.total_replies).needsExact&&e.jsxs("span",{children:["(",ve(pe.total_replies).exact,")"]})," 条"]})]})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(as,{className:"text-sm font-medium",children:"成本效率"}),e.jsx(JN,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(xs,{children:[e.jsx("div",{className:"text-xl font-bold",children:pe.total_messages>0?`¥${(pe.total_cost/pe.total_messages*100).toFixed(2)}`:"¥0.00"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"每100条消息"})]})]})]}),e.jsxs(ga,{defaultValue:"trends",className:"space-y-4",children:[e.jsxs(la,{className:"grid w-full grid-cols-2 sm:grid-cols-4",children:[e.jsx(ss,{value:"trends",children:"趋势"}),e.jsx(ss,{value:"models",children:"模型"}),e.jsx(ss,{value:"activity",children:"活动"}),e.jsx(ss,{value:"daily",children:"日统计"})]}),e.jsxs(Ts,{value:"trends",className:"space-y-4",children:[e.jsxs(Fe,{children:[e.jsxs(ts,{children:[e.jsx(as,{children:"请求趋势"}),e.jsxs(et,{children:["最近",f,"小时的请求量变化"]})]}),e.jsx(xs,{children:e.jsx(Xn,{config:se,className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(jN,{data:te,children:[e.jsx(Mc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Dc,{dataKey:"timestamp",tickFormatter:R=>D(R),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Pr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ei,{content:e.jsx(Jn,{labelFormatter:R=>D(R)})}),e.jsx(vN,{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(Fe,{children:[e.jsxs(ts,{children:[e.jsx(as,{children:"花费趋势"}),e.jsx(et,{children:"API调用成本变化"})]}),e.jsx(xs,{children:e.jsx(Xn,{config:se,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(vu,{data:te,children:[e.jsx(Mc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Dc,{dataKey:"timestamp",tickFormatter:R=>D(R),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Pr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ei,{content:e.jsx(Jn,{labelFormatter:R=>D(R)})}),e.jsx(Oc,{dataKey:"cost",fill:"var(--color-cost)"})]})})})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{children:[e.jsx(as,{children:"Token消耗"}),e.jsx(et,{children:"Token使用量变化"})]}),e.jsx(xs,{children:e.jsx(Xn,{config:se,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(vu,{data:te,children:[e.jsx(Mc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Dc,{dataKey:"timestamp",tickFormatter:R=>D(R),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Pr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ei,{content:e.jsx(Jn,{labelFormatter:R=>D(R)})}),e.jsx(Oc,{dataKey:"tokens",fill:"var(--color-tokens)"})]})})})]})]})]}),e.jsx(Ts,{value:"models",className:"space-y-4",children:e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(Fe,{children:[e.jsxs(ts,{children:[e.jsx(as,{children:"模型请求分布"}),e.jsxs(et,{children:["各模型使用占比 (共 ",A.length," 个模型)"]})]}),e.jsx(xs,{children:e.jsx(Xn,{config:Object.fromEntries(A.map((R,ue)=>[R.model_name,{label:R.model_name,color:J[ue]}])),className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(bN,{children:[e.jsx(ei,{content:e.jsx(Jn,{})}),e.jsx(NN,{data:q,cx:"50%",cy:"50%",labelLine:!1,label:({name:R,percent:ue})=>ue&&ue<.05?"":`${R} ${ue?(ue*100).toFixed(0):0}%`,outerRadius:100,dataKey:"value",children:q.map((R,ue)=>e.jsx(yN,{fill:R.fill},`cell-${ue}`))})]})})})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{children:[e.jsx(as,{children:"模型详细统计"}),e.jsx(et,{children:"请求数、花费和性能"})]}),e.jsx(xs,{children:e.jsx(Ze,{className:"h-[300px] sm:h-[400px]",children:e.jsx("div",{className:"space-y-3",children:A.map((R,ue)=>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:R.model_name}),e.jsx("div",{className:"w-3 h-3 rounded-full ml-2 flex-shrink-0",style:{backgroundColor:`hsl(var(--chart-${ue%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:R.request_count.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1 font-medium",children:["¥",R.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:[(R.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:[R.avg_response_time.toFixed(2),"s"]})]})]})]},ue))})})})]})]})}),e.jsx(Ts,{value:"activity",children:e.jsxs(Fe,{children:[e.jsxs(ts,{children:[e.jsx(as,{children:"最近活动"}),e.jsx(et,{children:"最新的API调用记录"})]}),e.jsx(xs,{children:e.jsx(Ze,{className:"h-[400px] sm:h-[500px]",children:e.jsx("div",{className:"space-y-2",children:je.map((R,ue)=>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:R.model}),e.jsx("div",{className:"text-xs text-muted-foreground",children:R.request_type})]}),e.jsx("div",{className:"text-xs text-muted-foreground flex-shrink-0",children:D(R.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:R.tokens})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1",children:["¥",R.cost.toFixed(4)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"耗时:"}),e.jsxs("span",{className:"ml-1",children:[R.time_cost.toFixed(2),"s"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"状态:"}),e.jsx("span",{className:`ml-1 ${R.status==="success"?"text-green-600":"text-red-600"}`,children:R.status})]})]})]},ue))})})})]})}),e.jsx(Ts,{value:"daily",children:e.jsxs(Fe,{children:[e.jsxs(ts,{children:[e.jsx(as,{children:"每日统计"}),e.jsx(et,{children:"最近7天的数据汇总"})]}),e.jsx(xs,{children:e.jsx(Xn,{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(vu,{data:fe,children:[e.jsx(Mc,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Dc,{dataKey:"timestamp",tickFormatter:R=>{const ue=new Date(R);return`${ue.getMonth()+1}/${ue.getDate()}`},stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Pr,{yAxisId:"left",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Pr,{yAxisId:"right",orientation:"right",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ei,{content:e.jsx(Jn,{labelFormatter:R=>new Date(R).toLocaleDateString("zh-CN")})}),e.jsx(x0,{content:e.jsx(Eg,{})}),e.jsx(Oc,{yAxisId:"left",dataKey:"requests",fill:"var(--color-requests)"}),e.jsx(Oc,{yAxisId:"right",dataKey:"cost",fill:"var(--color-cost)"})]})})})]})})]})]})})}const y0={theme:"system",setTheme:()=>null},zg=u.createContext(y0),Yu=()=>{const n=u.useContext(zg);if(n===void 0)throw new Error("useTheme must be used within a ThemeProvider");return n},w0=(n,r,i)=>{const d=document.documentElement.classList.contains("no-animations");if(!document.startViewTransition||d){r(n);return}const m=i.clientX,x=i.clientY,f=Math.hypot(Math.max(m,innerWidth-m),Math.max(x,innerHeight-x));document.startViewTransition(()=>{r(n)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${m}px ${x}px)`,`circle(${f}px at ${m}px ${x}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},Ag=u.createContext(void 0),Mg=()=>{const n=u.useContext(Ag);if(n===void 0)throw new Error("useAnimation must be used within an AnimationProvider");return n},$e=u.forwardRef(({className:n,...r},i)=>e.jsx(Ap,{className:$("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",n),...r,ref:i,children:e.jsx(eN,{className:$("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")})}));$e.displayName=Ap.displayName;const _0=tr("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),C=u.forwardRef(({className:n,...r},i)=>e.jsx(Qp,{ref:i,className:$(_0(),n),...r}));C.displayName=Qp.displayName;const ie=u.forwardRef(({className:n,type:r,...i},d)=>e.jsx("input",{type:r,className:$("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",n),ref:d,...i}));ie.displayName="Input";const S0=[{id:"minLength",label:"长度至少 10 位",description:"Token 长度必须大于等于 10 个字符",validate:n=>n.length>=10},{id:"hasUppercase",label:"包含大写字母",description:"至少包含一个大写字母 (A-Z)",validate:n=>/[A-Z]/.test(n)},{id:"hasLowercase",label:"包含小写字母",description:"至少包含一个小写字母 (a-z)",validate:n=>/[a-z]/.test(n)},{id:"hasSpecialChar",label:"包含特殊符号",description:"至少包含一个特殊符号 (!@#$%^&*()_+-=[]{}|;:,.<>?/)",validate:n=>/[!@#$%^&*()_+\-=[\]{}|;:,.<>?/]/.test(n)}];function C0(n){const r=S0.map(d=>({id:d.id,label:d.label,description:d.description,passed:d.validate(n)}));return{isValid:r.every(d=>d.passed),rules:r}}const Zc="0.12.0 Beta",Ku="MaiBot Dashboard",k0=`${Ku} v${Zc}`,T0=(n="v")=>`${n}${Zc}`,Vt={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"},Da={theme:"system",accentColor:"blue",enableAnimations:!0,enableWavesBackground:!0,logCacheSize:1e3,logAutoScroll:!0,logFontSize:"xs",logLineSpacing:4,dataSyncInterval:30,wsReconnectInterval:3e3,wsMaxReconnectAttempts:10};function nt(n){const r=Dg(n),i=localStorage.getItem(r);if(i===null)return Da[n];const d=Da[n];if(typeof d=="boolean")return i==="true";if(typeof d=="number"){const m=parseFloat(i);return isNaN(m)?d:m}return i}function Zn(n,r){const i=Dg(n);localStorage.setItem(i,String(r)),window.dispatchEvent(new CustomEvent("maibot-settings-change",{detail:{key:n,value:r}}))}function E0(){return{theme:nt("theme"),accentColor:nt("accentColor"),enableAnimations:nt("enableAnimations"),enableWavesBackground:nt("enableWavesBackground"),logCacheSize:nt("logCacheSize"),logAutoScroll:nt("logAutoScroll"),logFontSize:nt("logFontSize"),logLineSpacing:nt("logLineSpacing"),dataSyncInterval:nt("dataSyncInterval"),wsReconnectInterval:nt("wsReconnectInterval"),wsMaxReconnectAttempts:nt("wsMaxReconnectAttempts")}}function z0(){const n=E0(),r=localStorage.getItem(Vt.COMPLETED_TOURS),i=r?JSON.parse(r):[];return{...n,completedTours:i}}function A0(n){const r=[],i=[];for(const[d,m]of Object.entries(n)){if(d==="completedTours"){Array.isArray(m)?(localStorage.setItem(Vt.COMPLETED_TOURS,JSON.stringify(m)),r.push("completedTours")):i.push("completedTours");continue}if(d in Da){const x=d,f=Da[x];if(typeof m==typeof f){if(x==="theme"&&!["light","dark","system"].includes(m)){i.push(d);continue}if(x==="logFontSize"&&!["xs","sm","base"].includes(m)){i.push(d);continue}Zn(x,m),r.push(d)}else i.push(d)}else i.push(d)}return{success:r.length>0,imported:r,skipped:i}}function M0(){for(const n of Object.keys(Da))Zn(n,Da[n]);localStorage.removeItem(Vt.COMPLETED_TOURS),window.dispatchEvent(new CustomEvent("maibot-settings-reset"))}function D0(){const n=[],r=[],i=[];for(let d=0;dd.size-i.size),{used:n,items:localStorage.length,details:r}}function O0(n){if(n===0)return"0 B";const r=1024,i=["B","KB","MB"],d=Math.floor(Math.log(n)/Math.log(r));return parseFloat((n/Math.pow(r,d)).toFixed(2))+" "+i[d]}function Dg(n){return{theme:Vt.THEME,accentColor:Vt.ACCENT_COLOR,enableAnimations:Vt.ENABLE_ANIMATIONS,enableWavesBackground:Vt.ENABLE_WAVES_BACKGROUND,logCacheSize:Vt.LOG_CACHE_SIZE,logAutoScroll:Vt.LOG_AUTO_SCROLL,logFontSize:Vt.LOG_FONT_SIZE,logLineSpacing:Vt.LOG_LINE_SPACING,dataSyncInterval:Vt.DATA_SYNC_INTERVAL,wsReconnectInterval:Vt.WS_RECONNECT_INTERVAL,wsMaxReconnectAttempts:Vt.WS_MAX_RECONNECT_ATTEMPTS}[n]}const pa=u.forwardRef(({className:n,...r},i)=>e.jsxs(Mp,{ref:i,className:$("relative flex w-full touch-none select-none items-center",n),...r,children:[e.jsx(sN,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(tN,{className:"absolute h-full bg-primary"})}),e.jsx(aN,{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"})]}));pa.displayName=Mp.displayName;class R0{ws=null;reconnectTimeout=null;reconnectAttempts=0;heartbeatInterval=null;logCallbacks=new Set;connectionCallbacks=new Set;isConnected=!1;logCache=[];getMaxCacheSize(){return nt("logCacheSize")}getMaxReconnectAttempts(){return nt("wsMaxReconnectAttempts")}getReconnectInterval(){return nt("wsReconnectInterval")}getWebSocketUrl(){{const r=window.location.protocol==="https:"?"wss:":"ws:",i=window.location.host;return`${r}//${i}/ws/logs`}}connect(){if(this.ws?.readyState===WebSocket.OPEN||this.ws?.readyState===WebSocket.CONNECTING)return;const r=this.getWebSocketUrl();try{this.ws=new WebSocket(r),this.ws.onopen=()=>{this.isConnected=!0,this.reconnectAttempts=0,this.notifyConnection(!0),this.startHeartbeat()},this.ws.onmessage=i=>{try{if(i.data==="pong")return;const d=JSON.parse(i.data);this.notifyLog(d)}catch(d){console.error("解析日志消息失败:",d)}},this.ws.onerror=i=>{console.error("❌ WebSocket 错误:",i),this.isConnected=!1,this.notifyConnection(!1)},this.ws.onclose=()=>{this.isConnected=!1,this.notifyConnection(!1),this.stopHeartbeat(),this.attemptReconnect()}}catch(i){console.error("创建 WebSocket 连接失败:",i),this.attemptReconnect()}}attemptReconnect(){const r=this.getMaxReconnectAttempts();if(this.reconnectAttempts>=r)return;this.reconnectAttempts+=1;const i=this.getReconnectInterval(),d=Math.min(i*this.reconnectAttempts,3e4);this.reconnectTimeout=window.setTimeout(()=>{this.connect()},d)}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(r){return this.logCallbacks.add(r),()=>this.logCallbacks.delete(r)}onConnectionChange(r){return this.connectionCallbacks.add(r),r(this.isConnected),()=>this.connectionCallbacks.delete(r)}notifyLog(r){if(!this.logCache.some(d=>d.id===r.id)){this.logCache.push(r);const d=this.getMaxCacheSize();this.logCache.length>d&&(this.logCache=this.logCache.slice(-d)),this.logCallbacks.forEach(m=>{try{m(r)}catch(x){console.error("日志回调执行失败:",x)}})}}notifyConnection(r){this.connectionCallbacks.forEach(i=>{try{i(r)}catch(d){console.error("连接状态回调执行失败:",d)}})}getAllLogs(){return[...this.logCache]}clearLogs(){this.logCache=[]}getConnectionStatus(){return this.isConnected}}const tn=new R0;typeof window<"u"&&tn.connect();const qs=CN,Xu=kN,L0=_N,Og=u.forwardRef(({className:n,...r},i)=>e.jsx(Ip,{ref:i,className:$("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",n),...r}));Og.displayName=Ip.displayName;const Ls=u.forwardRef(({className:n,children:r,preventOutsideClose:i=!1,...d},m)=>e.jsxs(L0,{children:[e.jsx(Og,{}),e.jsxs(Yp,{ref:m,className:$("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",n),onPointerDownOutside:i?x=>x.preventDefault():void 0,onInteractOutside:i?x=>x.preventDefault():void 0,...d,children:[r,e.jsxs(SN,{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(rl,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Ls.displayName=Yp.displayName;const Us=({className:n,...r})=>e.jsx("div",{className:$("flex flex-col space-y-1.5 text-center sm:text-left",n),...r});Us.displayName="DialogHeader";const st=({className:n,...r})=>e.jsx("div",{className:$("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",n),...r});st.displayName="DialogFooter";const Bs=u.forwardRef(({className:n,...r},i)=>e.jsx(Kp,{ref:i,className:$("text-lg font-semibold leading-none tracking-tight",n),...r}));Bs.displayName=Kp.displayName;const Ps=u.forwardRef(({className:n,...r},i)=>e.jsx(Xp,{ref:i,className:$("text-sm text-muted-foreground",n),...r}));Ps.displayName=Xp.displayName;const hs=nN,rt=rN,U0=lN,Rg=u.forwardRef(({className:n,...r},i)=>e.jsx(Dp,{className:$("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",n),...r,ref:i}));Rg.displayName=Dp.displayName;const ls=u.forwardRef(({className:n,...r},i)=>e.jsxs(U0,{children:[e.jsx(Rg,{}),e.jsx(Op,{ref:i,className:$("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",n),...r})]}));ls.displayName=Op.displayName;const ns=({className:n,...r})=>e.jsx("div",{className:$("flex flex-col space-y-2 text-center sm:text-left",n),...r});ns.displayName="AlertDialogHeader";const rs=({className:n,...r})=>e.jsx("div",{className:$("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",n),...r});rs.displayName="AlertDialogFooter";const is=u.forwardRef(({className:n,...r},i)=>e.jsx(Rp,{ref:i,className:$("text-lg font-semibold",n),...r}));is.displayName=Rp.displayName;const cs=u.forwardRef(({className:n,...r},i)=>e.jsx(Lp,{ref:i,className:$("text-sm text-muted-foreground",n),...r}));cs.displayName=Lp.displayName;const os=u.forwardRef(({className:n,...r},i)=>e.jsx(Up,{ref:i,className:$(ui(),n),...r}));os.displayName=Up.displayName;const ds=u.forwardRef(({className:n,...r},i)=>e.jsx(Bp,{ref:i,className:$(ui({variant:"outline"}),"mt-2 sm:mt-0",n),...r}));ds.displayName=Bp.displayName;function B0(){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(ga,{defaultValue:"appearance",className:"w-full",children:[e.jsxs(la,{className:"grid w-full grid-cols-2 sm:grid-cols-4 gap-0.5 sm:gap-1 h-auto p-1",children:[e.jsxs(ss,{value:"appearance",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(ZN,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"外观"})]}),e.jsxs(ss,{value:"security",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(PN,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"安全"})]}),e.jsxs(ss,{value:"other",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(ar,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"其他"})]}),e.jsxs(ss,{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(Ts,{value:"appearance",className:"mt-0",children:e.jsx(H0,{})}),e.jsx(Ts,{value:"security",className:"mt-0",children:e.jsx(q0,{})}),e.jsx(Ts,{value:"other",className:"mt-0",children:e.jsx(G0,{})}),e.jsx(Ts,{value:"about",className:"mt-0",children:e.jsx($0,{})})]})]})]})}function cp(n){const r=document.documentElement,d={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%)"}}[n];if(d)r.style.setProperty("--primary",d.hsl),d.gradient?(r.style.setProperty("--primary-gradient",d.gradient),r.classList.add("has-gradient")):(r.style.removeProperty("--primary-gradient"),r.classList.remove("has-gradient"));else if(n.startsWith("#")){const m=x=>{x=x.replace("#","");const f=parseInt(x.substring(0,2),16)/255,p=parseInt(x.substring(2,4),16)/255,g=parseInt(x.substring(4,6),16)/255,b=Math.max(f,p,g),j=Math.min(f,p,g);let y=0,N=0;const k=(b+j)/2;if(b!==j){const w=b-j;switch(N=k>.5?w/(2-b-j):w/(b+j),b){case f:y=((p-g)/w+(plocalStorage.getItem("accent-color")||"blue");u.useEffect(()=>{const b=localStorage.getItem("accent-color")||"blue";cp(b)},[]);const g=b=>{p(b),localStorage.setItem("accent-color",b),cp(b)};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(ku,{value:"light",current:n,onChange:r,label:"浅色",description:"始终使用浅色主题"}),e.jsx(ku,{value:"dark",current:n,onChange:r,label:"深色",description:"始终使用深色主题"}),e.jsx(ku,{value:"system",current:n,onChange:r,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(fa,{value:"blue",current:f,onChange:g,label:"蓝色",colorClass:"bg-blue-500"}),e.jsx(fa,{value:"purple",current:f,onChange:g,label:"紫色",colorClass:"bg-purple-500"}),e.jsx(fa,{value:"green",current:f,onChange:g,label:"绿色",colorClass:"bg-green-500"}),e.jsx(fa,{value:"orange",current:f,onChange:g,label:"橙色",colorClass:"bg-orange-500"}),e.jsx(fa,{value:"pink",current:f,onChange:g,label:"粉色",colorClass:"bg-pink-500"}),e.jsx(fa,{value:"red",current:f,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(fa,{value:"gradient-sunset",current:f,onChange:g,label:"日落",colorClass:"bg-gradient-to-r from-orange-500 to-pink-500"}),e.jsx(fa,{value:"gradient-ocean",current:f,onChange:g,label:"海洋",colorClass:"bg-gradient-to-r from-blue-500 to-cyan-500"}),e.jsx(fa,{value:"gradient-forest",current:f,onChange:g,label:"森林",colorClass:"bg-gradient-to-r from-green-500 to-emerald-500"}),e.jsx(fa,{value:"gradient-aurora",current:f,onChange:g,label:"极光",colorClass:"bg-gradient-to-r from-purple-500 to-pink-500"}),e.jsx(fa,{value:"gradient-fire",current:f,onChange:g,label:"烈焰",colorClass:"bg-gradient-to-r from-red-500 to-orange-500"}),e.jsx(fa,{value:"gradient-twilight",current:f,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:f.startsWith("#")?f:"#3b82f6",onChange:b=>g(b.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:f,onChange:b=>g(b.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(C,{htmlFor:"animations",className:"text-base font-medium cursor-pointer",children:"启用动画效果"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后将禁用所有过渡动画和特效,提升性能"})]}),e.jsx($e,{id:"animations",checked:i,onCheckedChange:d})]})}),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(C,{htmlFor:"waves-background",className:"text-base font-medium cursor-pointer",children:"登录页波浪背景"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后登录页将使用纯色背景,适合低性能设备"})]}),e.jsx($e,{id:"waves-background",checked:m,onCheckedChange:x})]})})]})]})]})}function q0(){const n=va(),[r,i]=u.useState(""),[d,m]=u.useState(""),[x,f]=u.useState(!1),[p,g]=u.useState(!1),[b,j]=u.useState(!1),[y,N]=u.useState(!1),[k,w]=u.useState(!1),[U,O]=u.useState(!1),[B,Y]=u.useState(""),[L,z]=u.useState(!1),{toast:K}=$s(),I=u.useMemo(()=>C0(d),[d]),T=async he=>{if(!r){K({title:"无法复制",description:"Token 存储在安全 Cookie 中,请重新生成以获取新 Token",variant:"destructive"});return}try{await navigator.clipboard.writeText(he),w(!0),K({title:"复制成功",description:"Token 已复制到剪贴板"}),setTimeout(()=>w(!1),2e3)}catch{K({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},A=async()=>{if(!d.trim()){K({title:"输入错误",description:"请输入新的 Token",variant:"destructive"});return}if(!I.isValid){const he=I.rules.filter(ve=>!ve.passed).map(ve=>ve.label).join(", ");K({title:"格式错误",description:`Token 不符合要求: ${he}`,variant:"destructive"});return}j(!0);try{const he=await fetch("/api/webui/auth/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({new_token:d.trim()})}),ve=await he.json();he.ok&&ve.success?(m(""),i(d.trim()),K({title:"更新成功",description:"Access Token 已更新,即将跳转到登录页"}),setTimeout(()=>{n({to:"/auth"})},1500)):K({title:"更新失败",description:ve.message||"无法更新 Token",variant:"destructive"})}catch(he){console.error("更新 Token 错误:",he),K({title:"更新失败",description:"连接服务器失败",variant:"destructive"})}finally{j(!1)}},te=async()=>{N(!0);try{const he=await fetch("/api/webui/auth/regenerate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"}),ve=await he.json();he.ok&&ve.success?(i(ve.token),Y(ve.token),O(!0),z(!1),K({title:"生成成功",description:"新的 Access Token 已生成,请及时保存"})):K({title:"生成失败",description:ve.message||"无法生成新 Token",variant:"destructive"})}catch(he){console.error("生成 Token 错误:",he),K({title:"生成失败",description:"连接服务器失败",variant:"destructive"})}finally{N(!1)}},fe=async()=>{try{await navigator.clipboard.writeText(B),z(!0),K({title:"复制成功",description:"Token 已复制到剪贴板"})}catch{K({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},je=()=>{O(!1),setTimeout(()=>{Y(""),z(!1)},300),setTimeout(()=>{n({to:"/auth"})},500)},pe=he=>{he||je()};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(qs,{open:U,onOpenChange:pe,children:e.jsxs(Ls,{className:"sm:max-w-md",children:[e.jsxs(Us,{children:[e.jsxs(Bs,{className:"flex items-center gap-2",children:[e.jsx(Ca,{className:"h-5 w-5 text-yellow-500"}),"新的 Access Token"]}),e.jsx(Ps,{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(C,{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:B})]}),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(Ca,{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(st,{className:"gap-2 sm:gap-0",children:[e.jsx(S,{variant:"outline",onClick:fe,className:"gap-2",children:L?e.jsxs(e.Fragment,{children:[e.jsx(Qt,{className:"h-4 w-4 text-green-500"}),"已复制"]}):e.jsxs(e.Fragment,{children:[e.jsx(Vc,{className:"h-4 w-4"}),"复制 Token"]})}),e.jsx(S,{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:"当前 Access Token"}),e.jsx("div",{className:"space-y-3 sm:space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{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:r||"••••••••••••••••••••••••••••••••",readOnly:!0,className:"pr-10 font-mono text-sm",placeholder:"Token 存储在安全 Cookie 中"}),e.jsx("button",{onClick:()=>{r?f(!x):K({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(ci,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Rt,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(S,{variant:"outline",size:"icon",onClick:()=>T(r),title:"复制到剪贴板",className:"flex-shrink-0",disabled:!r,children:k?e.jsx(Qt,{className:"h-4 w-4 text-green-500"}):e.jsx(Vc,{className:"h-4 w-4"})}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsxs(S,{variant:"outline",disabled:y,className:"gap-2 flex-1 sm:flex-none",children:[e.jsx(zt,{className:$("h-4 w-4",y&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:"重新生成"}),e.jsx("span",{className:"sm:hidden",children:"生成"})]})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认重新生成 Token"}),e.jsx(cs,{children:"这将生成一个新的 64 位安全令牌,并使当前 Token 立即失效。 您需要使用新 Token 重新登录系统。此操作不可撤销,确定要继续吗?"})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{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(C,{htmlFor:"new-token",className:"text-sm",children:"新的访问令牌"}),e.jsxs("div",{className:"relative",children:[e.jsx(ie,{id:"new-token",type:p?"text":"password",value:d,onChange:he=>m(he.target.value),className:"pr-10 font-mono text-sm",placeholder:"输入自定义 Token"}),e.jsx("button",{onClick:()=>g(!p),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:p?"隐藏":"显示",children:p?e.jsx(ci,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Rt,{className:"h-4 w-4 text-muted-foreground"})})]}),d&&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:I.rules.map(he=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[he.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:$(he.passed?"text-green-600 dark:text-green-400":"text-muted-foreground"),children:he.label})]},he.id))}),I.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(Qt,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:"Token 格式正确,可以使用"})]})})]})]}),e.jsx(S,{onClick:A,disabled:b||!I.isValid||!d,className:"w-full sm:w-auto",children:b?"更新中...":"更新自定义 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 G0(){const n=va(),{toast:r}=$s(),[i,d]=u.useState(!1),[m,x]=u.useState(!1),[f,p]=u.useState(()=>nt("logCacheSize")),[g,b]=u.useState(()=>nt("wsReconnectInterval")),[j,y]=u.useState(()=>nt("wsMaxReconnectAttempts")),[N,k]=u.useState(()=>nt("dataSyncInterval")),[w,U]=u.useState(()=>ip()),[O,B]=u.useState(!1),[Y,L]=u.useState(!1),z=u.useRef(null);if(m)throw new Error("这是一个手动触发的测试错误,用于验证错误边界组件是否正常工作。");const K=()=>{U(ip())},I=D=>{const J=D[0];p(J),Zn("logCacheSize",J)},T=D=>{const J=D[0];b(J),Zn("wsReconnectInterval",J)},A=D=>{const J=D[0];y(J),Zn("wsMaxReconnectAttempts",J)},te=D=>{const J=D[0];k(J),Zn("dataSyncInterval",J)},fe=()=>{tn.clearLogs(),r({title:"日志已清除",description:"日志缓存已清空"})},je=()=>{const D=D0();K(),r({title:"缓存已清除",description:`已清除 ${D.clearedKeys.length} 项缓存数据`})},pe=()=>{B(!0);try{const D=z0(),J=JSON.stringify(D,null,2),q=new Blob([J],{type:"application/json"}),se=URL.createObjectURL(q),R=document.createElement("a");R.href=se,R.download=`maibot-webui-settings-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(R),R.click(),document.body.removeChild(R),URL.revokeObjectURL(se),r({title:"导出成功",description:"设置已导出为 JSON 文件"})}catch(D){console.error("导出设置失败:",D),r({title:"导出失败",description:"无法导出设置",variant:"destructive"})}finally{B(!1)}},he=D=>{const J=D.target.files?.[0];if(!J)return;L(!0);const q=new FileReader;q.onload=se=>{try{const R=se.target?.result,ue=JSON.parse(R),me=A0(ue);me.success?(p(nt("logCacheSize")),b(nt("wsReconnectInterval")),y(nt("wsMaxReconnectAttempts")),k(nt("dataSyncInterval")),K(),r({title:"导入成功",description:`成功导入 ${me.imported.length} 项设置${me.skipped.length>0?`,跳过 ${me.skipped.length} 项`:""}`}),(me.imported.includes("theme")||me.imported.includes("accentColor"))&&r({title:"提示",description:"部分设置需要刷新页面才能完全生效"})):r({title:"导入失败",description:"没有有效的设置项可导入",variant:"destructive"})}catch(R){console.error("导入设置失败:",R),r({title:"导入失败",description:"文件格式无效",variant:"destructive"})}finally{L(!1),z.current&&(z.current.value="")}},q.readAsText(J)},ve=()=>{M0(),p(Da.logCacheSize),b(Da.wsReconnectInterval),y(Da.wsMaxReconnectAttempts),k(Da.dataSyncInterval),K(),r({title:"已重置",description:"所有设置已恢复为默认值,刷新页面以应用更改"})},be=async()=>{d(!0);try{const D=localStorage.getItem("access-token"),J=await fetch("/api/webui/setup/reset",{method:"POST",headers:{Authorization:`Bearer ${D}`}}),q=await J.json();J.ok&&q.success?(r({title:"重置成功",description:"即将进入初次配置向导"}),setTimeout(()=>{n({to:"/setup"})},1e3)):r({title:"重置失败",description:q.message||"无法重置配置状态",variant:"destructive"})}catch(D){console.error("重置配置状态错误:",D),r({title:"重置失败",description:"连接服务器失败",variant:"destructive"})}finally{d(!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(Fc,{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(WN,{className:"h-4 w-4"}),"本地存储使用"]}),e.jsx(S,{variant:"ghost",size:"sm",onClick:K,className:"h-7 px-2",children:e.jsx(zt,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:O0(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(C,{className:"text-sm font-medium",children:"日志缓存大小"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[f," 条"]})]}),e.jsx(pa,{value:[f],onValueChange:I,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(C,{className:"text-sm font-medium",children:"首页数据刷新间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[N," 秒"]})]}),e.jsx(pa,{value:[N],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(C,{className:"text-sm font-medium",children:"WebSocket 重连间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[g/1e3," 秒"]})]}),e.jsx(pa,{value:[g],onValueChange:T,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(C,{className:"text-sm font-medium",children:"WebSocket 最大重连次数"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[j," 次"]})]}),e.jsx(pa,{value:[j],onValueChange:A,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(S,{variant:"outline",size:"sm",onClick:fe,className:"gap-2",children:[e.jsx(We,{className:"h-4 w-4"}),"清除日志缓存"]}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsxs(S,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(We,{className:"h-4 w-4"}),"清除本地缓存"]})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认清除本地缓存"}),e.jsx(cs,{children:"这将清除所有本地缓存的设置和数据(不包括登录凭证)。 您可能需要重新配置部分偏好设置。确定要继续吗?"})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:je,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(Oa,{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(S,{variant:"outline",onClick:pe,disabled:O,className:"gap-2",children:[e.jsx(Oa,{className:"h-4 w-4"}),O?"导出中...":"导出设置"]}),e.jsx("input",{ref:z,type:"file",accept:".json",onChange:he,className:"hidden"}),e.jsxs(S,{variant:"outline",onClick:()=>z.current?.click(),disabled:Y,className:"gap-2",children:[e.jsx(oi,{className:"h-4 w-4"}),Y?"导入中...":"导入设置"]})]}),e.jsx("div",{className:"pt-2 border-t",children:e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsxs(S,{variant:"outline",size:"sm",className:"gap-2 text-destructive hover:text-destructive",children:[e.jsx($c,{className:"h-4 w-4"}),"重置所有设置为默认值"]})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认重置所有设置"}),e.jsx(cs,{children:"这将把所有界面设置恢复为默认值,包括主题、颜色、动画等偏好设置。 此操作不会影响您的登录状态。确定要继续吗?"})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:ve,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(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsxs(S,{variant:"outline",disabled:i,className:"gap-2",children:[e.jsx($c,{className:$("h-4 w-4",i&&"animate-spin")}),"重新进行初次配置"]})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认重新配置"}),e.jsx(cs,{children:"这将带您重新进入初次配置向导。您可以重新设置系统的基础配置项。确定要继续吗?"})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{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(Ca,{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(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsxs(S,{variant:"destructive",className:"gap-2",children:[e.jsx(Ca,{className:"h-4 w-4"}),"触发测试错误"]})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认触发错误"}),e.jsx(cs,{children:"这将手动触发一个 React 错误,用于测试错误边界组件的显示效果。 页面将显示错误界面,您可以通过刷新页面或点击返回首页来恢复。"})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>x(!0),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认触发"})]})]})]})]})]})]})}function $0(){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:$("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:["关于 ",Ku]}),e.jsxs("div",{className:"space-y-2 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("p",{children:["版本: ",Zc]}),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(Ws,{name:"React",description:"用户界面构建库",license:"MIT"}),e.jsx(Ws,{name:"shadcn/ui",description:"优雅的 React 组件库",license:"MIT"}),e.jsx(Ws,{name:"Radix UI",description:"无样式的可访问组件库",license:"MIT"}),e.jsx(Ws,{name:"Tailwind CSS",description:"实用优先的 CSS 框架",license:"MIT"}),e.jsx(Ws,{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(Ws,{name:"TanStack Router",description:"类型安全的路由库",license:"MIT"}),e.jsx(Ws,{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(Ws,{name:"React Hook Form",description:"高性能表单库",license:"MIT"}),e.jsx(Ws,{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(Ws,{name:"clsx",description:"条件 className 构建工具",license:"MIT"}),e.jsx(Ws,{name:"tailwind-merge",description:"Tailwind 类名合并工具",license:"MIT"}),e.jsx(Ws,{name:"class-variance-authority",description:"组件变体管理",license:"Apache-2.0"}),e.jsx(Ws,{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(Ws,{name:"Framer Motion",description:"React 动画库",license:"MIT"}),e.jsx(Ws,{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(Ws,{name:"FastAPI",description:"现代化 Python Web 框架",license:"MIT"}),e.jsx(Ws,{name:"Uvicorn",description:"ASGI 服务器",license:"BSD-3-Clause"}),e.jsx(Ws,{name:"Pydantic",description:"数据验证库",license:"MIT"}),e.jsx(Ws,{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(Ws,{name:"TypeScript",description:"JavaScript 的超集",license:"Apache-2.0"}),e.jsx(Ws,{name:"Vite",description:"下一代前端构建工具",license:"MIT"}),e.jsx(Ws,{name:"ESLint",description:"JavaScript 代码检查工具",license:"MIT"}),e.jsx(Ws,{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 Ws({name:n,description:r,license:i}){return e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg border bg-muted/30 p-2.5 sm:p-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-foreground truncate",children:n}),e.jsx("p",{className:"text-muted-foreground text-xs mt-0.5",children:r})]}),e.jsx("span",{className:"inline-flex items-center rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary flex-shrink-0",children:i})]})}function ku({value:n,current:r,onChange:i,label:d,description:m}){const x=r===n;return e.jsxs("button",{onClick:()=>i(n),className:$("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:d}),e.jsx("div",{className:"text-[10px] sm:text-xs text-muted-foreground",children:m})]}),e.jsxs("div",{className:"mt-2 sm:mt-3 flex gap-1",children:[n==="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"})]}),n==="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"})]}),n==="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 fa({value:n,current:r,onChange:i,label:d,colorClass:m}){const x=r===n;return e.jsxs("button",{onClick:()=>i(n),className:$("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-8 w-8 sm:h-10 sm:w-10 rounded-full",m)}),e.jsx("div",{className:"text-[10px] sm:text-xs font-medium text-center",children:d})]})]})}class F0{grad3;p;perm;constructor(r=0){this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.p=[];for(let i=0;i<256;i++)this.p[i]=Math.floor(Math.random()*256);this.perm=[];for(let i=0;i<512;i++)this.perm[i]=this.p[i&255]}dot(r,i,d){return r[0]*i+r[1]*d}mix(r,i,d){return(1-d)*r+d*i}fade(r){return r*r*r*(r*(r*6-15)+10)}perlin2(r,i){const d=Math.floor(r)&255,m=Math.floor(i)&255;r-=Math.floor(r),i-=Math.floor(i);const x=this.fade(r),f=this.fade(i),p=this.perm[d]+m,g=this.perm[p],b=this.perm[p+1],j=this.perm[d+1]+m,y=this.perm[j],N=this.perm[j+1];return this.mix(this.mix(this.dot(this.grad3[g%12],r,i),this.dot(this.grad3[y%12],r-1,i),x),this.mix(this.dot(this.grad3[b%12],r,i-1),this.dot(this.grad3[N%12],r-1,i-1),x),f)}}function op(){const n=u.useRef(null),r=u.useRef(null),i=u.useRef(void 0),d=u.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 F0(Math.random()),bounding:null});return u.useEffect(()=>{const m=r.current,x=n.current;if(!m||!x)return;const f=d.current,p=()=>{const U=m.getBoundingClientRect();f.bounding=U,x.style.width=`${U.width}px`,x.style.height=`${U.height}px`},g=()=>{if(!f.bounding)return;const{width:U,height:O}=f.bounding;f.lines=[],f.paths.forEach(te=>te.remove()),f.paths=[];const B=10,Y=32,L=U+200,z=O+30,K=Math.ceil(L/B),I=Math.ceil(z/Y),T=(U-B*K)/2,A=(O-Y*I)/2;for(let te=0;te<=K;te++){const fe=[];for(let pe=0;pe<=I;pe++){const he={x:T+B*te,y:A+Y*pe,wave:{x:0,y:0},cursor:{x:0,y:0,vx:0,vy:0}};fe.push(he)}const je=document.createElementNS("http://www.w3.org/2000/svg","path");x.appendChild(je),f.paths.push(je),f.lines.push(fe)}},b=U=>{const{lines:O,mouse:B,noise:Y}=f;O.forEach(L=>{L.forEach(z=>{const K=Y.perlin2((z.x+U*.0125)*.002,(z.y+U*.005)*.0015)*12;z.wave.x=Math.cos(K)*32,z.wave.y=Math.sin(K)*16;const I=z.x-B.sx,T=z.y-B.sy,A=Math.hypot(I,T),te=Math.max(175,B.vs);if(A{const B={x:U.x+U.wave.x+(O?U.cursor.x:0),y:U.y+U.wave.y+(O?U.cursor.y:0)};return B.x=Math.round(B.x*10)/10,B.y=Math.round(B.y*10)/10,B},y=()=>{const{lines:U,paths:O}=f;U.forEach((B,Y)=>{let L=j(B[0],!1),z=`M ${L.x} ${L.y}`;B.forEach((K,I)=>{const T=I===B.length-1;L=j(K,!T),z+=`L ${L.x} ${L.y}`}),O[Y].setAttribute("d",z)})},N=U=>{const{mouse:O}=f;O.sx+=(O.x-O.sx)*.1,O.sy+=(O.y-O.sy)*.1;const B=O.x-O.lx,Y=O.y-O.ly,L=Math.hypot(B,Y);O.v=L,O.vs+=(L-O.vs)*.1,O.vs=Math.min(100,O.vs),O.lx=O.x,O.ly=O.y,O.a=Math.atan2(Y,B),m&&(m.style.setProperty("--x",`${O.sx}px`),m.style.setProperty("--y",`${O.sy}px`)),b(U),y(),i.current=requestAnimationFrame(N)},k=U=>{if(!f.bounding)return;const{mouse:O}=f;O.x=U.pageX-f.bounding.left,O.y=U.pageY-f.bounding.top+window.scrollY,O.set||(O.sx=O.x,O.sy=O.y,O.lx=O.x,O.ly=O.y,O.set=!0)},w=()=>{p(),g()};return p(),g(),window.addEventListener("resize",w),window.addEventListener("mousemove",k),i.current=requestAnimationFrame(N),()=>{window.removeEventListener("resize",w),window.removeEventListener("mousemove",k),i.current&&cancelAnimationFrame(i.current)}},[]),e.jsxs("div",{ref:r,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:n,style:{display:"block",width:"100%",height:"100%"},children:e.jsx("style",{children:` path { fill: none; stroke: hsl(var(--primary) / 0.20); stroke-width: 1px; } `})})]})}async function Se(n,r){const i={...r,credentials:"include",headers:{"Content-Type":"application/json",...r?.headers}},d=await fetch(n,i);if(d.status===401)throw window.location.href="/auth",new Error("认证失败,请重新登录");return d}function Gs(){return{"Content-Type":"application/json"}}async function V0(){try{await fetch("/api/webui/auth/logout",{method:"POST",credentials:"include"})}catch(n){console.error("登出请求失败:",n)}window.location.href="/auth"}async function Ju(){try{return(await(await fetch("/api/webui/auth/check",{method:"GET",credentials:"include"})).json()).authenticated===!0}catch{return!1}}function Q0(){const[n,r]=u.useState(""),[i,d]=u.useState(!1),[m,x]=u.useState(""),[f,p]=u.useState(!0),g=va(),{enableWavesBackground:b,setEnableWavesBackground:j}=Mg(),{theme:y,setTheme:N}=Yu();u.useEffect(()=>{(async()=>{try{await Ju()&&g({to:"/"})}catch{}finally{p(!1)}})()},[g]);const w=y==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":y,U=()=>{N(w==="dark"?"light":"dark")},O=async B=>{if(B.preventDefault(),x(""),!n.trim()){x("请输入 Access Token");return}d(!0);try{const Y=await fetch("/api/webui/auth/verify",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({token:n.trim()})}),L=await Y.json();Y.ok&&L.valid?L.is_first_setup?g({to:"/setup"}):g({to:"/"}):x(L.message||"Token 验证失败,请检查后重试")}catch(Y){console.error("Token 验证错误:",Y),x("连接服务器失败,请检查网络连接")}finally{d(!1)}};return f?e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[b&&e.jsx(op,{}),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:[b&&e.jsx(op,{}),e.jsxs(Fe,{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:U,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(xg,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"}):e.jsx(hg,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"})}),e.jsxs(ts,{className:"space-y-4 text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-2xl bg-primary/10",children:e.jsx(Jf,{className:"h-8 w-8 text-primary",strokeWidth:2,fill:"none"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(as,{className:"text-2xl font-bold",children:"欢迎使用 MaiBot"}),e.jsx(et,{className:"text-base",children:"请输入您的 Access Token 以继续访问系统"})]})]}),e.jsx(xs,{children:e.jsxs("form",{onSubmit:O,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"token",className:"text-sm font-medium",children:"Access Token"}),e.jsxs("div",{className:"relative",children:[e.jsx(fg,{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:n,onChange:B=>r(B.target.value),className:$("pl-10",m&&"border-red-500 focus-visible:ring-red-500"),disabled:i,autoFocus:!0,autoComplete:"off"})]})]}),m&&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(At,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{children:m})]}),e.jsx(S,{type:"submit",className:"w-full",disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"验证中..."]}):"验证并进入"}),e.jsxs(qs,{children:[e.jsx(Xu,{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(pg,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我没有 Token,我该去哪里获得 Token?"]})}),e.jsxs(Ls,{className:"sm:max-w-md",children:[e.jsxs(Us,{children:[e.jsxs(Bs,{className:"flex items-center gap-2",children:[e.jsx(Jf,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"如何获取 Access Token"]}),e.jsx(Ps,{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(ey,{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(Sa,{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(At,{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(hs,{children:[e.jsx(rt,{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(an,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我觉得这个界面很卡怎么办?"]})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsxs(is,{className:"flex items-center gap-2",children:[e.jsx(an,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"关闭背景动画"]}),e.jsx(cs,{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(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>j(!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:k0})})]})}const Qs=u.forwardRef(({className:n,...r},i)=>e.jsx("textarea",{className:$("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",n),ref:i,...r}));Qs.displayName="Textarea";const Pc=u.forwardRef(({className:n,orientation:r="horizontal",decorative:i=!0,...d},m)=>e.jsx(Hp,{ref:m,decorative:i,orientation:r,className:$("shrink-0 bg-border",r==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",n),...d}));Pc.displayName=Hp.displayName;function I0({config:n,onChange:r}){const i=m=>{m.trim()&&!n.alias_names.includes(m.trim())&&r({...n,alias_names:[...n.alias_names,m.trim()]})},d=m=>{r({...n,alias_names:n.alias_names.filter((x,f)=>f!==m)})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{htmlFor:"qq_account",children:"QQ账号 *"}),e.jsx(ie,{id:"qq_account",type:"number",placeholder:"请输入机器人的QQ账号",value:n.qq_account||"",onChange:m=>r({...n,qq_account:Number(m.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人登录使用的QQ账号"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{htmlFor:"nickname",children:"昵称 *"}),e.jsx(ie,{id:"nickname",placeholder:"请输入机器人的昵称",value:n.nickname,onChange:m=>r({...n,nickname:m.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人的主要称呼名称"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{children:"别名"}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:n.alias_names.map((m,x)=>e.jsxs(Qe,{variant:"secondary",className:"gap-1",children:[m,e.jsx("button",{type:"button",onClick:()=>d(x),className:"ml-1 hover:text-destructive",children:e.jsx(rl,{className:"h-3 w-3"})})]},x))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{id:"alias_input",placeholder:"输入别名后按回车添加",onKeyPress:m=>{m.key==="Enter"&&(i(m.target.value),m.target.value="")}}),e.jsx(S,{type:"button",variant:"outline",onClick:()=>{const m=document.getElementById("alias_input");m&&(i(m.value),m.value="")},children:"添加"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人的其他称呼,可以添加多个"})]})]})}function Y0({config:n,onChange:r}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{htmlFor:"personality",children:"人格特征 *"}),e.jsx(Qs,{id:"personality",placeholder:"描述机器人的人格特质和身份特征(建议120字以内)",value:n.personality,onChange:i=>r({...n,personality:i.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:是一个女大学生,现在在读大二,会刷贴吧"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{htmlFor:"reply_style",children:"表达风格 *"}),e.jsx(Qs,{id:"reply_style",placeholder:"描述机器人说话的表达风格、表达习惯",value:n.reply_style,onChange:i=>r({...n,reply_style:i.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:回复平淡一些,简短一些,说中文,参考贴吧、知乎和微博的回复风格"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{htmlFor:"interest",children:"兴趣 *"}),e.jsx(Qs,{id:"interest",placeholder:"描述机器人感兴趣的话题",value:n.interest,onChange:i=>r({...n,interest:i.target.value}),rows:2}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"会影响机器人对什么话题进行回复"})]}),e.jsx(Pc,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{htmlFor:"plan_style",children:"群聊说话规则 *"}),e.jsx(Qs,{id:"plan_style",placeholder:"机器人在群聊中的行为风格和规则",value:n.plan_style,onChange:i=>r({...n,plan_style:i.target.value}),rows:4}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在群聊中如何行动,例如回复频率、条件等"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{htmlFor:"private_plan_style",children:"私聊说话规则 *"}),e.jsx(Qs,{id:"private_plan_style",placeholder:"机器人在私聊中的行为风格和规则",value:n.private_plan_style,onChange:i=>r({...n,private_plan_style:i.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在私聊中的行为方式"})]})]})}function K0({config:n,onChange:r}){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(C,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(n.emoji_chance*100).toFixed(0),"%"]})]}),e.jsx(ie,{id:"emoji_chance",type:"range",min:"0",max:"1",step:"0.1",value:n.emoji_chance,onChange:i=>r({...n,emoji_chance:Number(i.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人发送表情包的概率"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{htmlFor:"max_reg_num",children:"最大表情包数量"}),e.jsx(ie,{id:"max_reg_num",type:"number",min:"1",max:"200",value:n.max_reg_num,onChange:i=>r({...n,max_reg_num:Number(i.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人最多保存的表情包数量"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"do_replace",children:"达到最大数量时替换"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"开启后会删除旧表情包,关闭则不再收集新表情包"})]}),e.jsx($e,{id:"do_replace",checked:n.do_replace,onCheckedChange:i=>r({...n,do_replace:i})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(ie,{id:"check_interval",type:"number",min:"1",max:"120",value:n.check_interval,onChange:i=>r({...n,check_interval:Number(i.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"检查表情包注册、破损、删除的时间间隔"})]}),e.jsx(Pc,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"steal_emoji",children:"偷取表情包"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人将一些表情包据为己有"})]}),e.jsx($e,{id:"steal_emoji",checked:n.steal_emoji,onCheckedChange:i=>r({...n,steal_emoji:i})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"content_filtration",children:"启用表情包过滤"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只保存符合要求的表情包"})]}),e.jsx($e,{id:"content_filtration",checked:n.content_filtration,onCheckedChange:i=>r({...n,content_filtration:i})})]}),n.content_filtration&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(ie,{id:"filtration_prompt",placeholder:"例如:符合公序良俗",value:n.filtration_prompt,onChange:i=>r({...n,filtration_prompt:i.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"描述表情包应该符合的要求"})]})]})}function X0({config:n,onChange:r}){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(C,{htmlFor:"enable_tool",children:"启用工具系统"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人使用各种工具增强功能"})]}),e.jsx($e,{id:"enable_tool",checked:n.enable_tool,onCheckedChange:i=>r({...n,enable_tool:i})})]}),e.jsx(Pc,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{htmlFor:"all_global",children:"启用全局黑话模式"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人学习和使用群组黑话"})]}),e.jsx($e,{id:"all_global",checked:n.all_global,onCheckedChange:i=>r({...n,all_global:i})})]})]})}function J0({config:n,onChange:r}){const[i,d]=u.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(Hc,{className:"h-3 w-3"})]})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{htmlFor:"siliconflow_api_key",children:"SiliconFlow API Key *"}),e.jsxs("div",{className:"relative",children:[e.jsx(ie,{id:"siliconflow_api_key",type:i?"text":"password",placeholder:"sk-...",value:n.api_key,onChange:m=>r({api_key:m.target.value}),className:"font-mono pr-10"}),e.jsx(S,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",onClick:()=>d(!i),children:i?e.jsx(ci,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Rt,{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 Z0(){const n=await Se("/api/webui/config/bot",{method:"GET",headers:Gs()});if(!n.ok)throw new Error("读取Bot配置失败");const i=(await n.json()).config.bot||{};return{qq_account:i.qq_account||0,nickname:i.nickname||"",alias_names:i.alias_names||[]}}async function P0(){const n=await Se("/api/webui/config/bot",{method:"GET",headers:Gs()});if(!n.ok)throw new Error("读取人格配置失败");const i=(await n.json()).config.personality||{};return{personality:i.personality||"",reply_style:i.reply_style||"",interest:i.interest||"",plan_style:i.plan_style||"",private_plan_style:i.private_plan_style||""}}async function W0(){const n=await Se("/api/webui/config/bot",{method:"GET",headers:Gs()});if(!n.ok)throw new Error("读取表情包配置失败");const i=(await n.json()).config.emoji||{};return{emoji_chance:i.emoji_chance??.4,max_reg_num:i.max_reg_num??40,do_replace:i.do_replace??!0,check_interval:i.check_interval??10,steal_emoji:i.steal_emoji??!0,content_filtration:i.content_filtration??!1,filtration_prompt:i.filtration_prompt||""}}async function ew(){const n=await Se("/api/webui/config/bot",{method:"GET",headers:Gs()});if(!n.ok)throw new Error("读取其他配置失败");const i=(await n.json()).config,d=i.tool||{},m=i.expression||{};return{enable_tool:d.enable_tool??!0,all_global:m.all_global_jargon??!0}}async function sw(){const n=await Se("/api/webui/config/model",{method:"GET",headers:Gs()});if(!n.ok)throw new Error("读取模型配置失败");return{api_key:((await n.json()).config.api_providers||[]).find(x=>x.name==="SiliconFlow")?.api_key||""}}async function tw(n){const r=await Se("/api/webui/config/bot/section/bot",{method:"POST",headers:Gs(),body:JSON.stringify(n)});if(!r.ok){const i=await r.json();throw new Error(i.detail||"保存Bot基础配置失败")}return await r.json()}async function aw(n){const r=await Se("/api/webui/config/bot/section/personality",{method:"POST",headers:Gs(),body:JSON.stringify(n)});if(!r.ok){const i=await r.json();throw new Error(i.detail||"保存人格配置失败")}return await r.json()}async function lw(n){const r=await Se("/api/webui/config/bot/section/emoji",{method:"POST",headers:Gs(),body:JSON.stringify(n)});if(!r.ok){const i=await r.json();throw new Error(i.detail||"保存表情包配置失败")}return await r.json()}async function nw(n){const r=[];r.push(Se("/api/webui/config/bot/section/tool",{method:"POST",headers:Gs(),body:JSON.stringify({enable_tool:n.enable_tool})})),r.push(Se("/api/webui/config/bot/section/expression",{method:"POST",headers:Gs(),body:JSON.stringify({all_global_jargon:n.all_global})}));const i=await Promise.all(r);for(const d of i)if(!d.ok){const m=await d.json();throw new Error(m.detail||"保存其他配置失败")}return{success:!0}}async function rw(n){const r=await Se("/api/webui/config/model",{method:"GET",headers:Gs()});if(!r.ok)throw new Error("读取模型配置失败");const d=(await r.json()).config,m=d.api_providers||[],x=m.findIndex(g=>g.name==="SiliconFlow");x>=0?m[x]={...m[x],api_key:n.api_key}:m.push({name:"SiliconFlow",base_url:"https://api.siliconflow.cn/v1",api_key:n.api_key,client_type:"openai",max_retry:3,timeout:120,retry_interval:5});const f={...d,api_providers:m},p=await Se("/api/webui/config/model",{method:"POST",headers:Gs(),body:JSON.stringify(f)});if(!p.ok){const g=await p.json();throw new Error(g.detail||"保存模型配置失败")}return await p.json()}async function dp(){const n=localStorage.getItem("access-token"),r=await Se("/api/webui/setup/complete",{method:"POST",headers:{Authorization:`Bearer ${n}`}});if(!r.ok){const i=await r.json();throw new Error(i.message||"标记配置完成失败")}return await r.json()}async function Wc(){const n=await Se("/api/webui/system/restart",{method:"POST",headers:Gs()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"重启失败")}return await n.json()}async function Lg(){const n=await Se("/api/webui/system/status",{method:"GET",headers:Gs()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取状态失败")}return await n.json()}function iw(){const n=va(),{toast:r}=$s(),[i,d]=u.useState(0),[m,x]=u.useState(!1),[f,p]=u.useState(!1),[g,b]=u.useState(!0),[j,y]=u.useState({qq_account:0,nickname:"",alias_names:[]}),[N,k]=u.useState({personality:"是一个女大学生,现在在读大二,会刷贴吧。",reply_style:"请回复的平淡一些,简短一些,说中文,不要刻意突出自身学科背景。可以参考贴吧,知乎和微博的回复风格。",interest:"对技术相关话题,游戏和动漫相关话题感兴趣,也对日常话题感兴趣,不喜欢太过沉重严肃的话题",plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 2.如果相同的内容已经被执行,请不要重复执行 3.请控制你的发言频率,不要太过频繁的发言 4.如果有人对你感到厌烦,请减少回复 5.如果有人对你进行攻击,或者情绪激动,请你以合适的方法应对`,private_plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 2.如果相同的内容已经被执行,请不要重复执行 3.某句话如果已经被回复过,不要重复回复`}),[w,U]=u.useState({emoji_chance:.4,max_reg_num:40,do_replace:!0,check_interval:10,steal_emoji:!0,content_filtration:!1,filtration_prompt:"符合公序良俗"}),[O,B]=u.useState({enable_tool:!0,all_global:!0}),[Y,L]=u.useState({api_key:""}),[z,K]=u.useState(!1),[I,T]=u.useState(""),A=[{id:"bot-basic",title:"Bot基础",description:"配置机器人的基本信息",icon:ti},{id:"personality",title:"人格配置",description:"定义机器人的性格和说话风格",icon:Qc},{id:"emoji",title:"表情包",description:"配置表情包相关设置",icon:Vu},{id:"other",title:"其他设置",description:"工具、情绪系统等配置",icon:ar},{id:"siliconflow",title:"API配置",description:"配置硅基流动API密钥",icon:fg}],te=(i+1)/A.length*100;u.useEffect(()=>{(async()=>{try{b(!0);const[J,q,se,R,ue]=await Promise.all([Z0(),P0(),W0(),ew(),sw()]);y(J),k(q),U(se),B(R),L(ue)}catch(J){r({title:"加载配置失败",description:J instanceof Error?J.message:"无法加载现有配置,将使用默认值",variant:"destructive"})}finally{b(!1)}})()},[r]);const fe=async()=>{p(!0);try{switch(i){case 0:await tw(j);break;case 1:await aw(N);break;case 2:await lw(w);break;case 3:await nw(O);break;case 4:await rw(Y);break}return r({title:"保存成功",description:`${A[i].title}配置已保存`}),!0}catch(D){return r({title:"保存失败",description:D instanceof Error?D.message:"未知错误",variant:"destructive"}),!1}finally{p(!1)}},je=async()=>{await fe()&&i{i>0&&d(i-1)},he=async()=>{x(!0),K(!0);try{if(T("正在保存API配置..."),!await fe()){x(!1),K(!1);return}T("正在完成初始化..."),await dp(),T("正在重启麦麦..."),await Wc(),r({title:"配置完成",description:"麦麦正在重启以应用新配置..."}),T("等待麦麦重启完成...");const J=60;let q=0,se=!1;for(;qsetTimeout(R,1e3));try{(await Lg()).running&&(se=!0,T("重启成功!正在跳转..."))}catch{q++}}if(!se)throw new Error("重启超时,请手动检查麦麦状态");setTimeout(()=>{n({to:"/"})},1e3)}catch(D){K(!1),r({title:"配置失败",description:D instanceof Error?D.message:"未知错误",variant:"destructive"})}finally{x(!1)}},ve=async()=>{try{await dp(),n({to:"/"})}catch(D){r({title:"跳过失败",description:D instanceof Error?D.message:"未知错误",variant:"destructive"})}},be=()=>{switch(i){case 0:return e.jsx(I0,{config:j,onChange:y});case 1:return e.jsx(Y0,{config:N,onChange:k});case 2:return e.jsx(K0,{config:w,onChange:U});case 3:return e.jsx(X0,{config:O,onChange:B});case 4:return e.jsx(J0,{config:Y,onChange:L});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:[z&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",children:e.jsxs("div",{className:"mx-auto flex max-w-md flex-col items-center space-y-6 rounded-lg border bg-card p-8 text-center shadow-lg",children:[e.jsx("div",{className:"flex h-20 w-20 items-center justify-center rounded-full bg-primary/10",children:e.jsx(it,{className:"h-10 w-10 animate-spin text-primary"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"正在重启麦麦"}),e.jsx("p",{className:"text-muted-foreground",children:I})]}),e.jsx("div",{className:"w-full",children:e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-secondary",children:e.jsx("div",{className:"h-full w-full animate-pulse bg-primary",style:{animation:"pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite"}})})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"请稍候,这可能需要一分钟..."})]})}),e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute left-1/4 top-1/4 h-64 w-64 md:h-96 md:w-96 rounded-full bg-primary/5 blur-3xl"}),e.jsx("div",{className:"absolute right-1/4 bottom-1/4 h-64 w-64 md:h-96 md:w-96 rounded-full bg-secondary/5 blur-3xl"})]}),g?e.jsxs("div",{className:"relative z-10 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center",children:e.jsx("div",{className:"h-12 w-12 animate-spin rounded-full border-4 border-primary border-t-transparent"})}),e.jsx("p",{className:"text-lg font-medium",children:"加载配置中..."}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"正在读取现有配置"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative z-10 w-full max-w-4xl",children:[e.jsxs("div",{className:"mb-6 md:mb-8 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 md:h-16 md:w-16 items-center justify-center rounded-2xl bg-primary/10",children:e.jsx(sy,{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:["让我们一起完成 ",Ku," 的初始配置"]})]}),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:["步骤 ",i+1," / ",A.length]}),e.jsxs("span",{className:"font-medium text-primary",children:[Math.round(te),"%"]})]}),e.jsx(rr,{value:te,className:"h-2"})]}),e.jsx("div",{className:"mb-6 md:mb-8 flex justify-between",children:A.map((D,J)=>{const q=D.icon;return e.jsxs("div",{className:$("flex flex-1 flex-col items-center gap-1 md:gap-2",Jn({to:"/"}),className:"gap-2 w-full sm:w-auto",children:[e.jsx(Jc,{className:"h-4 w-4"}),"返回首页"]}),e.jsxs(S,{size:"lg",variant:"outline",onClick:()=>window.history.back(),className:"gap-2 w-full sm:w-auto",children:[e.jsx(er,{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 cw=bt.memo(function({config:r,onChange:i}){const d=()=>{i({...r,platforms:[...r.platforms,""]})},m=b=>{i({...r,platforms:r.platforms.filter((j,y)=>y!==b)})},x=(b,j)=>{const y=[...r.platforms];y[b]=j,i({...r,platforms:y})},f=()=>{i({...r,alias_names:[...r.alias_names,""]})},p=b=>{i({...r,alias_names:r.alias_names.filter((j,y)=>y!==b)})},g=(b,j)=>{const y=[...r.alias_names];y[b]=j,i({...r,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(C,{htmlFor:"platform",children:"平台"}),e.jsx(ie,{id:"platform",value:r.platform,onChange:b=>i({...r,platform:b.target.value}),placeholder:"qq"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"qq_account",children:"QQ账号"}),e.jsx(ie,{id:"qq_account",value:r.qq_account,onChange:b=>i({...r,qq_account:b.target.value}),placeholder:"123456789"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"nickname",children:"昵称"}),e.jsx(ie,{id:"nickname",value:r.nickname,onChange:b=>i({...r,nickname:b.target.value}),placeholder:"麦麦"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(C,{children:"其他平台账号"}),e.jsxs(S,{onClick:d,size:"sm",variant:"outline",children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[r.platforms.map((b,j)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{value:b,onChange:y=>x(j,y.target.value),placeholder:"wx:114514"}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{size:"icon",variant:"outline",children:e.jsx(We,{className:"h-4 w-4"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:['确定要删除平台账号 "',b||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>m(j),children:"删除"})]})]})]})]},j)),r.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(C,{children:"别名"}),e.jsxs(S,{onClick:f,size:"sm",variant:"outline",children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[r.alias_names.map((b,j)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{value:b,onChange:y=>g(j,y.target.value),placeholder:"小麦"}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{size:"icon",variant:"outline",children:e.jsx(We,{className:"h-4 w-4"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:['确定要删除别名 "',b||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>p(j),children:"删除"})]})]})]})]},j)),r.alias_names.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无别名"})]})]})]})]})})}),ow=bt.memo(function({config:r,onChange:i}){const d=()=>{i({...r,states:[...r.states,""]})},m=f=>{i({...r,states:r.states.filter((p,g)=>g!==f)})},x=(f,p)=>{const g=[...r.states];g[f]=p,i({...r,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(C,{htmlFor:"personality",children:"人格特质"}),e.jsx(Qs,{id:"personality",value:r.personality,onChange:f=>i({...r,personality:f.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(C,{htmlFor:"reply_style",children:"表达风格"}),e.jsx(Qs,{id:"reply_style",value:r.reply_style,onChange:f=>i({...r,reply_style:f.target.value}),placeholder:"描述说话的表达风格和习惯",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"interest",children:"兴趣"}),e.jsx(Qs,{id:"interest",value:r.interest,onChange:f=>i({...r,interest:f.target.value}),placeholder:"会影响麦麦对什么话题进行回复",rows:2})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"plan_style",children:"说话规则与行为风格"}),e.jsx(Qs,{id:"plan_style",value:r.plan_style,onChange:f=>i({...r,plan_style:f.target.value}),placeholder:"麦麦的说话规则和行为风格",rows:5})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"visual_style",children:"识图规则"}),e.jsx(Qs,{id:"visual_style",value:r.visual_style,onChange:f=>i({...r,visual_style:f.target.value}),placeholder:"识图时的处理规则",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"private_plan_style",children:"私聊规则"}),e.jsx(Qs,{id:"private_plan_style",value:r.private_plan_style,onChange:f=>i({...r,private_plan_style:f.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(C,{children:"状态列表(人格多样性)"}),e.jsxs(S,{onClick:d,size:"sm",variant:"outline",children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"添加状态"]})]}),e.jsx("div",{className:"space-y-2",children:r.states.map((f,p)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Qs,{value:f,onChange:g=>x(p,g.target.value),placeholder:"描述一个人格状态",rows:2}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{size:"icon",variant:"outline",children:e.jsx(We,{className:"h-4 w-4"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsx(cs,{children:"确定要删除这个人格状态吗?此操作无法撤销。"})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>m(p),children:"删除"})]})]})]})]},p))})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"state_probability",children:"状态替换概率"}),e.jsx(ie,{id:"state_probability",type:"number",step:"0.1",min:"0",max:"1",value:r.state_probability,onChange:f=>i({...r,state_probability:parseFloat(f.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"每次构建人格时替换 personality 的概率(0.0-1.0)"})]})]})]})})}),Ue=DN,Be=ON,Oe=u.forwardRef(({className:n,children:r,...i},d)=>e.jsxs(Jp,{ref:d,className:$("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",n),...i,children:[r,e.jsx(TN,{asChild:!0,children:e.jsx(Ll,{className:"h-4 w-4 opacity-50"})})]}));Oe.displayName=Jp.displayName;const Bg=u.forwardRef(({className:n,...r},i)=>e.jsx(Zp,{ref:i,className:$("flex cursor-default items-center justify-center py-1",n),...r,children:e.jsx(di,{className:"h-4 w-4"})}));Bg.displayName=Zp.displayName;const Hg=u.forwardRef(({className:n,...r},i)=>e.jsx(Pp,{ref:i,className:$("flex cursor-default items-center justify-center py-1",n),...r,children:e.jsx(Ll,{className:"h-4 w-4"})}));Hg.displayName=Pp.displayName;const Re=u.forwardRef(({className:n,children:r,position:i="popper",...d},m)=>e.jsx(EN,{children:e.jsxs(Wp,{ref:m,className:$("relative z-[100] max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-hidden rounded-md border border-border bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",i==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",n),position:i,...d,children:[e.jsx(Bg,{}),e.jsx(zN,{className:$("p-1",i==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:r}),e.jsx(Hg,{})]})}));Re.displayName=Wp.displayName;const dw=u.forwardRef(({className:n,...r},i)=>e.jsx(eg,{ref:i,className:$("px-2 py-1.5 text-sm font-semibold",n),...r}));dw.displayName=eg.displayName;const le=u.forwardRef(({className:n,children:r,...i},d)=>e.jsxs(sg,{ref:d,className:$("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",n),...i,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(AN,{children:e.jsx(Qt,{className:"h-4 w-4"})})}),e.jsx(MN,{children:r})]}));le.displayName=sg.displayName;const uw=u.forwardRef(({className:n,...r},i)=>e.jsx(tg,{ref:i,className:$("-mx-1 my-1 h-px bg-muted",n),...r}));uw.displayName=tg.displayName;const La=cN,Ua=oN,ka=u.forwardRef(({className:n,align:r="center",sideOffset:i=4,...d},m)=>e.jsx(iN,{children:e.jsx(qp,{ref:m,align:r,sideOffset:i,className:$("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]",n),...d})}));ka.displayName=qp.displayName;const mw=bt.memo(function({value:r,onChange:i}){const[d,m]=u.useState("00"),[x,f]=u.useState("00"),[p,g]=u.useState("23"),[b,j]=u.useState("59");u.useEffect(()=>{const N=r.split("-");if(N.length===2){const[k,w]=N,[U,O]=k.split(":"),[B,Y]=w.split(":");U&&m(U.padStart(2,"0")),O&&f(O.padStart(2,"0")),B&&g(B.padStart(2,"0")),Y&&j(Y.padStart(2,"0"))}},[r]);const y=(N,k,w,U)=>{const O=`${N}:${k}-${w}:${U}`;i(O)};return e.jsxs(La,{children:[e.jsx(Ua,{asChild:!0,children:e.jsxs(S,{variant:"outline",className:"w-full justify-start font-mono text-sm",children:[e.jsx(Pn,{className:"h-4 w-4 mr-2"}),r||"选择时间段"]})}),e.jsx(ka,{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(C,{className:"text-xs",children:"小时"}),e.jsxs(Ue,{value:d,onValueChange:N=>{m(N),y(N,x,p,b)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsx(Re,{children:Array.from({length:24},(N,k)=>k).map(N=>e.jsx(le,{value:N.toString().padStart(2,"0"),children:N.toString().padStart(2,"0")},N))})]})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-xs",children:"分钟"}),e.jsxs(Ue,{value:x,onValueChange:N=>{f(N),y(d,N,p,b)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsx(Re,{children:Array.from({length:60},(N,k)=>k).map(N=>e.jsx(le,{value:N.toString().padStart(2,"0"),children:N.toString().padStart(2,"0")},N))})]})]})]})]}),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(C,{className:"text-xs",children:"小时"}),e.jsxs(Ue,{value:p,onValueChange:N=>{g(N),y(d,x,N,b)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsx(Re,{children:Array.from({length:24},(N,k)=>k).map(N=>e.jsx(le,{value:N.toString().padStart(2,"0"),children:N.toString().padStart(2,"0")},N))})]})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-xs",children:"分钟"}),e.jsxs(Ue,{value:b,onValueChange:N=>{j(N),y(d,x,p,N)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsx(Re,{children:Array.from({length:60},(N,k)=>k).map(N=>e.jsx(le,{value:N.toString().padStart(2,"0"),children:N.toString().padStart(2,"0")},N))})]})]})]})]})]})})]})}),xw=bt.memo(function({rule:r}){const i=`{ target = "${r.target}", time = "${r.time}", value = ${r.value.toFixed(1)} }`;return e.jsxs(La,{children:[e.jsx(Ua,{asChild:!0,children:e.jsxs(S,{variant:"outline",size:"sm",children:[e.jsx(Rt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(ka,{className:"w-80 sm:w-96",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:i}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})}),hw=bt.memo(function({config:r,onChange:i}){const d=()=>{i({...r,talk_value_rules:[...r.talk_value_rules,{target:"",time:"00:00-23:59",value:1}]})},m=f=>{i({...r,talk_value_rules:r.talk_value_rules.filter((p,g)=>g!==f)})},x=(f,p,g)=>{const b=[...r.talk_value_rules];b[f]={...b[f],[p]:g},i({...r,talk_value_rules:b})};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(C,{htmlFor:"talk_value",children:"聊天频率(基础值)"}),e.jsx(ie,{id:"talk_value",type:"number",step:"0.1",min:"0",max:"1",value:r.talk_value,onChange:f=>i({...r,talk_value:parseFloat(f.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($e,{id:"mentioned_bot_reply",checked:r.mentioned_bot_reply,onCheckedChange:f=>i({...r,mentioned_bot_reply:f})}),e.jsx(C,{htmlFor:"mentioned_bot_reply",className:"cursor-pointer",children:"启用提及必回复"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"max_context_size",children:"上下文长度"}),e.jsx(ie,{id:"max_context_size",type:"number",min:"1",value:r.max_context_size,onChange:f=>i({...r,max_context_size:parseInt(f.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"planner_smooth",children:"规划器平滑"}),e.jsx(ie,{id:"planner_smooth",type:"number",step:"1",min:"0",value:r.planner_smooth,onChange:f=>i({...r,planner_smooth:parseFloat(f.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($e,{id:"enable_talk_value_rules",checked:r.enable_talk_value_rules,onCheckedChange:f=>i({...r,enable_talk_value_rules:f})}),e.jsx(C,{htmlFor:"enable_talk_value_rules",className:"cursor-pointer",children:"启用动态发言频率规则"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx($e,{id:"include_planner_reasoning",checked:r.include_planner_reasoning,onCheckedChange:f=>i({...r,include_planner_reasoning:f})}),e.jsx(C,{htmlFor:"include_planner_reasoning",className:"cursor-pointer",children:"将 planner 推理加入 replyer"})]})]})]}),r.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(S,{onClick:d,size:"sm",children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),r.talk_value_rules&&r.talk_value_rules.length>0?e.jsx("div",{className:"space-y-4",children:r.talk_value_rules.map((f,p)=>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:["规则 #",p+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xw,{rule:f}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{variant:"ghost",size:"sm",children:e.jsx(We,{className:"h-4 w-4 text-destructive"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:["确定要删除规则 #",p+1," 吗?此操作无法撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>m(p),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(Ue,{value:f.target===""?"global":"specific",onValueChange:g=>{g==="global"?x(p,"target",""):x(p,"target","qq::group")},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"global",children:"全局配置"}),e.jsx(le,{value:"specific",children:"详细配置"})]})]})]}),f.target!==""&&(()=>{const g=f.target.split(":"),b=g[0]||"qq",j=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(C,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Ue,{value:b,onValueChange:N=>{x(p,"target",`${N}:${j}:${y}`)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"qq",children:"QQ"}),e.jsx(le,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(ie,{value:j,onChange:N=>{x(p,"target",`${b}:${N.target.value}:${y}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Ue,{value:y,onValueChange:N=>{x(p,"target",`${b}:${j}:${N}`)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"group",children:"群组(group)"}),e.jsx(le,{value:"private",children:"私聊(private)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前聊天流 ID:",f.target||"(未设置)"]})]})})(),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{className:"text-xs font-medium",children:"时间段 (Time)"}),e.jsx(mw,{value:f.time,onChange:g=>x(p,"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(C,{htmlFor:`rule-value-${p}`,className:"text-xs font-medium",children:"发言频率值 (Value)"}),e.jsx(ie,{id:`rule-value-${p}`,type:"number",step:"0.01",min:"0.01",max:"1",value:f.value,onChange:g=>{const b=parseFloat(g.target.value);isNaN(b)||x(p,"value",Math.max(.01,Math.min(1,b)))},className:"w-20 h-8 text-xs"})]}),e.jsx(pa,{value:[f.value],onValueChange:g=>x(p,"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 (正常)"})]})]})]})]},p))}):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 表示正常发言"]})]})]})]})]})}),fw=bt.memo(function({config:r,onChange:i}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"语音设置"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx($e,{checked:r.enable_asr,onCheckedChange:d=>i({...r,enable_asr:d})}),e.jsx(C,{className:"cursor-pointer",children:"启用语音识别"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后麦麦可以识别语音消息,需要配置语音识别模型"})]})}),pw=bt.memo(function({config:r,onChange:i}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx($e,{checked:r.enable,onCheckedChange:d=>i({...r,enable:d})}),e.jsx(C,{className:"cursor-pointer",children:"启用 LPMM 知识库"})]}),r.enable&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"LPMM 模式"}),e.jsxs(Ue,{value:r.lpmm_mode,onValueChange:d=>i({...r,lpmm_mode:d}),children:[e.jsx(Oe,{children:e.jsx(Be,{placeholder:"选择 LPMM 模式"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"classic",children:"经典模式"}),e.jsx(le,{value:"agent",children:"Agent 模式"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"同义词搜索 TopK"}),e.jsx(ie,{type:"number",min:"1",value:r.rag_synonym_search_top_k,onChange:d=>i({...r,rag_synonym_search_top_k:parseInt(d.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"同义词阈值"}),e.jsx(ie,{type:"number",step:"0.1",min:"0",max:"1",value:r.rag_synonym_threshold,onChange:d=>i({...r,rag_synonym_threshold:parseFloat(d.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"实体提取线程数"}),e.jsx(ie,{type:"number",min:"1",value:r.info_extraction_workers,onChange:d=>i({...r,info_extraction_workers:parseInt(d.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"嵌入向量维度"}),e.jsx(ie,{type:"number",min:"1",value:r.embedding_dimension,onChange:d=>i({...r,embedding_dimension:parseInt(d.target.value)})})]})]})]})]})]})}),gw=bt.memo(function({config:r,onChange:i}){const[d,m]=u.useState(""),[x,f]=u.useState("WARNING"),p=()=>{d&&!r.suppress_libraries.includes(d)&&(i({...r,suppress_libraries:[...r.suppress_libraries,d]}),m(""))},g=w=>{i({...r,suppress_libraries:r.suppress_libraries.filter(U=>U!==w)})},b=()=>{d&&!r.library_log_levels[d]&&(i({...r,library_log_levels:{...r.library_log_levels,[d]:x}}),m(""),f("WARNING"))},j=w=>{const U={...r.library_log_levels};delete U[w],i({...r,library_log_levels:U})},y=["DEBUG","INFO","WARNING","ERROR","CRITICAL"],N=["FULL","compact","lite"],k=["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(C,{children:"日期格式"}),e.jsx(ie,{value:r.date_style,onChange:w=>i({...r,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(C,{children:"日志级别样式"}),e.jsxs(Ue,{value:r.log_level_style,onValueChange:w=>i({...r,log_level_style:w}),children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsx(Re,{children:N.map(w=>e.jsx(le,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"日志文本颜色"}),e.jsxs(Ue,{value:r.color_text,onValueChange:w=>i({...r,color_text:w}),children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsx(Re,{children:k.map(w=>e.jsx(le,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"全局日志级别"}),e.jsxs(Ue,{value:r.log_level,onValueChange:w=>i({...r,log_level:w}),children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsx(Re,{children:y.map(w=>e.jsx(le,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"控制台日志级别"}),e.jsxs(Ue,{value:r.console_log_level,onValueChange:w=>i({...r,console_log_level:w}),children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsx(Re,{children:y.map(w=>e.jsx(le,{value:w,children:w},w))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"文件日志级别"}),e.jsxs(Ue,{value:r.file_log_level,onValueChange:w=>i({...r,file_log_level:w}),children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsx(Re,{children:y.map(w=>e.jsx(le,{value:w,children:w},w))})]})]})]})]}),e.jsxs("div",{children:[e.jsx(C,{className:"mb-2 block",children:"完全屏蔽的库"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ie,{value:d,onChange:w=>m(w.target.value),placeholder:"输入库名",className:"flex-1",onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),p())}}),e.jsx(S,{onClick:p,size:"sm",className:"flex-shrink-0",children:e.jsx(dt,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.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(S,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0",onClick:()=>g(w),children:e.jsx(We,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},w))})]}),e.jsxs("div",{children:[e.jsx(C,{className:"mb-2 block",children:"特定库的日志级别"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ie,{value:d,onChange:w=>m(w.target.value),placeholder:"输入库名",className:"flex-1"}),e.jsxs(Ue,{value:x,onValueChange:f,children:[e.jsx(Oe,{className:"w-32",children:e.jsx(Be,{})}),e.jsx(Re,{children:y.map(w=>e.jsx(le,{value:w,children:w},w))})]}),e.jsx(S,{onClick:b,size:"sm",children:e.jsx(dt,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:Object.entries(r.library_log_levels).map(([w,U])=>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:U}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>j(w),children:e.jsx(We,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]})]},w))})]})]})}),jw=bt.memo(function({config:r,onChange:i}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"调试配置"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{children:"显示 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否在日志中显示提示词"})]}),e.jsx($e,{checked:r.show_prompt,onCheckedChange:d=>i({...r,show_prompt:d})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{children:"显示回复器 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的提示词"})]}),e.jsx($e,{checked:r.show_replyer_prompt,onCheckedChange:d=>i({...r,show_replyer_prompt:d})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{children:"显示回复器推理"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的推理过程"})]}),e.jsx($e,{checked:r.show_replyer_reasoning,onCheckedChange:d=>i({...r,show_replyer_reasoning:d})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{children:"显示 Jargon Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示术语相关的提示词"})]}),e.jsx($e,{checked:r.show_jargon_prompt,onCheckedChange:d=>i({...r,show_jargon_prompt:d})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{children:"显示记忆检索 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示记忆检索相关的提示词"})]}),e.jsx($e,{checked:r.show_memory_prompt,onCheckedChange:d=>i({...r,show_memory_prompt:d})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{children:"显示 Planner Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 Planner 的提示词和原始返回结果"})]}),e.jsx($e,{checked:r.show_planner_prompt,onCheckedChange:d=>i({...r,show_planner_prompt:d})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{children:"显示 LPMM 相关文段"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 LPMM 知识库找到的相关文段日志"})]}),e.jsx($e,{checked:r.show_lpmm_paragraph,onCheckedChange:d=>i({...r,show_lpmm_paragraph:d})})]})]})]})}),vw=bt.memo(function({config:r,onChange:i}){const[d,m]=u.useState(""),x=()=>{d&&!r.auth_token.includes(d)&&(i({...r,auth_token:[...r.auth_token,d]}),m(""))},f=p=>{i({...r,auth_token:r.auth_token.filter((g,b)=>b!==p)})};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(C,{children:"启用自定义服务器"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否使用自定义的 MaimMessage 服务器"})]}),e.jsx($e,{checked:r.use_custom,onCheckedChange:p=>i({...r,use_custom:p})})]}),r.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(C,{children:"主机地址"}),e.jsx(ie,{value:r.host,onChange:p=>i({...r,host:p.target.value}),placeholder:"127.0.0.1"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"端口号"}),e.jsx(ie,{type:"number",value:r.port,onChange:p=>i({...r,port:parseInt(p.target.value)}),placeholder:"8090"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"连接模式"}),e.jsxs(Ue,{value:r.mode,onValueChange:p=>i({...r,mode:p}),children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"ws",children:"WebSocket (ws)"}),e.jsx(le,{value:"tcp",children:"TCP"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx($e,{checked:r.use_wss,onCheckedChange:p=>i({...r,use_wss:p}),disabled:r.mode!=="ws"}),e.jsx(C,{children:"使用 WSS 安全连接"})]})]}),r.use_wss&&r.mode==="ws"&&e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"SSL 证书文件路径"}),e.jsx(ie,{value:r.cert_file,onChange:p=>i({...r,cert_file:p.target.value}),placeholder:"cert.pem"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"SSL 密钥文件路径"}),e.jsx(ie,{value:r.key_file,onChange:p=>i({...r,key_file:p.target.value}),placeholder:"key.pem"})]})]})]})]})]}),e.jsxs("div",{children:[e.jsx(C,{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:d,onChange:p=>m(p.target.value),placeholder:"输入认证令牌",onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),x())}}),e.jsx(S,{onClick:x,size:"sm",children:e.jsx(dt,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:r.auth_token.map((p,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:p}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>f(g),children:e.jsx(We,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},g))})]})]})}),bw=bt.memo(function({config:r,onChange:i}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"统计信息"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(C,{children:"启用统计信息发送"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"发送匿名统计信息,帮助我们了解全球有多少只麦麦在运行"})]}),e.jsx($e,{checked:r.enable,onCheckedChange:d=>i({...r,enable:d})})]})]})}),Nw=bt.memo(function({emojiConfig:r,memoryConfig:i,toolConfig:d,onEmojiChange:m,onMemoryChange:x,onToolChange:f}){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($e,{id:"enable_tool",checked:d.enable_tool,onCheckedChange:p=>f({...d,enable_tool:p})}),e.jsx(C,{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(C,{htmlFor:"max_agent_iterations",children:"记忆思考深度"}),e.jsx(ie,{id:"max_agent_iterations",type:"number",min:"1",value:i.max_agent_iterations,onChange:p=>x({...i,max_agent_iterations:parseInt(p.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"最低为 1(不深入思考)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"agent_timeout_seconds",children:"最长回忆时间(秒)"}),e.jsx(ie,{id:"agent_timeout_seconds",type:"number",min:"1",step:"0.1",value:i.agent_timeout_seconds??120,onChange:p=>x({...i,agent_timeout_seconds:parseFloat(p.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($e,{id:"enable_jargon_detection",checked:i.enable_jargon_detection??!0,onCheckedChange:p=>x({...i,enable_jargon_detection:p})}),e.jsx(C,{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($e,{id:"global_memory",checked:i.global_memory??!1,onCheckedChange:p=>x({...i,global_memory:p})}),e.jsx(C,{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(C,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsx(ie,{id:"emoji_chance",type:"number",step:"0.1",min:"0",max:"1",value:r.emoji_chance,onChange:p=>m({...r,emoji_chance:parseFloat(p.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"范围 0-1,越大越容易发送表情包"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"max_reg_num",children:"最大注册数量"}),e.jsx(ie,{id:"max_reg_num",type:"number",min:"1",value:r.max_reg_num,onChange:p=>m({...r,max_reg_num:parseInt(p.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦最多可以注册的表情包数量"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(ie,{id:"check_interval",type:"number",min:"1",value:r.check_interval,onChange:p=>m({...r,check_interval:parseInt(p.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($e,{id:"do_replace",checked:r.do_replace,onCheckedChange:p=>m({...r,do_replace:p})}),e.jsx(C,{htmlFor:"do_replace",className:"cursor-pointer",children:"达到最大数量时替换表情包"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx($e,{id:"steal_emoji",checked:r.steal_emoji,onCheckedChange:p=>m({...r,steal_emoji:p})}),e.jsx(C,{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($e,{id:"content_filtration",checked:r.content_filtration,onCheckedChange:p=>m({...r,content_filtration:p})}),e.jsx(C,{htmlFor:"content_filtration",className:"cursor-pointer",children:"启用表情包过滤"})]}),r.content_filtration&&e.jsxs("div",{className:"grid gap-2 pl-6 border-l-2 border-primary/20",children:[e.jsx(C,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(ie,{id:"filtration_prompt",value:r.filtration_prompt,onChange:p=>m({...r,filtration_prompt:p.target.value}),placeholder:"符合公序良俗"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只有符合此要求的表情包才会被保存"})]})]})]})})]})}),yw=bt.memo(function({member:r,groupIndex:i,memberIndex:d,availableChatIds:m,onUpdate:x,onRemove:f}){const p=m.includes(r)||r==="*",[g,b]=u.useState(!p);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:r,onChange:j=>x(i,d,j.target.value),placeholder:'输入 "*" 或 "qq:123456:group"',className:"flex-1"}),m.length>0&&e.jsx(S,{size:"sm",variant:"outline",onClick:()=>b(!1),title:"切换到下拉选择",children:"下拉"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Ue,{value:r,onValueChange:j=>x(i,d,j),children:[e.jsx(Oe,{className:"flex-1",children:e.jsx(Be,{placeholder:"选择聊天流"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"*",children:"* (全局共享)"}),m.map((j,y)=>e.jsx(le,{value:j,children:j},y))]})]}),e.jsx(S,{size:"sm",variant:"outline",onClick:()=>b(!0),title:"切换到手动输入",children:"输入"})]})}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{size:"icon",variant:"outline",children:e.jsx(We,{className:"h-4 w-4"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:['确定要删除组成员 "',r||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>f(i,d),children:"删除"})]})]})]})]})}),ww=bt.memo(function({config:r,onChange:i}){const d=()=>{i({...r,learning_list:[...r.learning_list,["","enable","enable","1.0"]]})},m=N=>{i({...r,learning_list:r.learning_list.filter((k,w)=>w!==N)})},x=(N,k,w)=>{const U=[...r.learning_list];U[N][k]=w,i({...r,learning_list:U})},f=({rule:N})=>{const k=`["${N[0]}", "${N[1]}", "${N[2]}", "${N[3]}"]`;return e.jsxs(La,{children:[e.jsx(Ua,{asChild:!0,children:e.jsxs(S,{variant:"outline",size:"sm",children:[e.jsx(Rt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(ka,{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:k}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},p=()=>{i({...r,expression_groups:[...r.expression_groups,[]]})},g=N=>{i({...r,expression_groups:r.expression_groups.filter((k,w)=>w!==N)})},b=N=>{const k=[...r.expression_groups];k[N]=[...k[N],""],i({...r,expression_groups:k})},j=(N,k)=>{const w=[...r.expression_groups];w[N]=w[N].filter((U,O)=>O!==k),i({...r,expression_groups:w})},y=(N,k,w)=>{const U=[...r.expression_groups];U[N][k]=w,i({...r,expression_groups:U})};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(S,{onClick:d,size:"sm",variant:"outline",children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),e.jsxs("div",{className:"space-y-4",children:[r.learning_list.map((N,k)=>{const w=r.learning_list.some((z,K)=>K!==k&&z[0]===""),U=N[0]==="",O=N[0].split(":"),B=O[0]||"qq",Y=O[1]||"",L=O[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:["规则 ",k+1," ",U&&"(全局配置)"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{rule:N}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{size:"sm",variant:"ghost",children:e.jsx(We,{className:"h-4 w-4"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:["确定要删除学习规则 ",k+1," 吗?此操作无法撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>m(k),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(Ue,{value:U?"global":"specific",onValueChange:z=>{z==="global"?x(k,0,""):x(k,0,"qq::group")},disabled:w&&!U,children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"global",children:"全局配置"}),e.jsx(le,{value:"specific",disabled:w&&!U,children:"详细配置"})]})]}),w&&!U&&e.jsx("p",{className:"text-xs text-amber-600",children:"已存在全局配置,无法创建新的全局配置"})]}),!U&&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(C,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Ue,{value:B,onValueChange:z=>{x(k,0,`${z}:${Y}:${L}`)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"qq",children:"QQ"}),e.jsx(le,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(ie,{value:Y,onChange:z=>{x(k,0,`${B}:${z.target.value}:${L}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Ue,{value:L,onValueChange:z=>{x(k,0,`${B}:${Y}:${z}`)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"group",children:"群组(group)"}),e.jsx(le,{value:"private",children:"私聊(private)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前聊天流 ID:",N[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(C,{className:"text-xs font-medium",children:"使用学到的表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦使用从聊天中学到的表达方式"})]}),e.jsx($e,{checked:N[1]==="enable",onCheckedChange:z=>x(k,1,z?"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(C,{className:"text-xs font-medium",children:"学习表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦从聊天中学习新的表达方式"})]}),e.jsx($e,{checked:N[2]==="enable",onCheckedChange:z=>x(k,2,z?"enable":"disable")})]})}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(C,{className:"text-xs font-medium",children:"学习强度"}),e.jsx(ie,{type:"number",step:"0.1",min:"0",max:"5",value:N[3],onChange:z=>{const K=parseFloat(z.target.value);isNaN(K)||x(k,3,Math.max(0,Math.min(5,K)).toFixed(1))},className:"w-20 h-8 text-xs"})]}),e.jsx(pa,{value:[parseFloat(N[3])||1],onValueChange:z=>x(k,3,z[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/学习强度(秒)"})]})]})]},k)}),r.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($e,{checked:r.reflect,onCheckedChange:N=>i({...r,reflect:N})})]}),r.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 k=(r.reflect_operator_id||"").split(":"),w=k[0]||"qq",U=k[1]||"",O=k[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(C,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Ue,{value:w,onValueChange:B=>{i({...r,reflect_operator_id:`${B}:${U}:${O}`})},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"qq",children:"QQ"}),e.jsx(le,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{className:"text-xs font-medium",children:"用户/群 ID"}),e.jsx(ie,{value:U,onChange:B=>{i({...r,reflect_operator_id:`${w}:${B.target.value}:${O}`})},placeholder:"输入 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Ue,{value:O,onValueChange:B=>{i({...r,reflect_operator_id:`${w}:${U}:${B}`})},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"private",children:"私聊(private)"}),e.jsx(le,{value:"group",children:"群组(group)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前操作员 ID:",r.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(S,{onClick:()=>{i({...r,allow_reflect:[...r.allow_reflect||[],"qq::group"]})},size:"sm",variant:"outline",children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"添加聊天流"]})]}),e.jsxs("div",{className:"space-y-2",children:[(r.allow_reflect||[]).map((N,k)=>{const w=N.split(":"),U=w[0]||"qq",O=w[1]||"",B=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:U,onValueChange:Y=>{const L=[...r.allow_reflect];L[k]=`${Y}:${O}:${B}`,i({...r,allow_reflect:L})},children:[e.jsx(Oe,{className:"w-24",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"qq",children:"QQ"}),e.jsx(le,{value:"wx",children:"微信"})]})]}),e.jsx(ie,{value:O,onChange:Y=>{const L=[...r.allow_reflect];L[k]=`${U}:${Y.target.value}:${B}`,i({...r,allow_reflect:L})},placeholder:"ID",className:"flex-1 font-mono text-sm"}),e.jsxs(Ue,{value:B,onValueChange:Y=>{const L=[...r.allow_reflect];L[k]=`${U}:${O}:${Y}`,i({...r,allow_reflect:L})},children:[e.jsx(Oe,{className:"w-32",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"group",children:"群组"}),e.jsx(le,{value:"private",children:"私聊"})]})]}),e.jsx(S,{onClick:()=>{i({...r,allow_reflect:r.allow_reflect.filter((Y,L)=>L!==k)})},size:"sm",variant:"ghost",children:e.jsx(We,{className:"h-4 w-4"})})]},k)}),(!r.allow_reflect||r.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(S,{onClick:p,size:"sm",variant:"outline",children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"添加共享组"]})]}),e.jsxs("div",{className:"space-y-4",children:[r.expression_groups.map((N,k)=>{const w=r.learning_list.map(U=>U[0]).filter(U=>U!=="");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:["共享组 ",k+1,N.length===1&&N[0]==="*"&&"(全局共享)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{onClick:()=>b(k),size:"sm",variant:"outline",children:e.jsx(dt,{className:"h-4 w-4"})}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{size:"sm",variant:"ghost",children:e.jsx(We,{className:"h-4 w-4"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:["确定要删除共享组 ",k+1," 吗?此操作无法撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>g(k),children:"删除"})]})]})]})]})]}),e.jsx("div",{className:"space-y-2",children:N.map((U,O)=>e.jsx(yw,{member:U,groupIndex:k,memberIndex:O,availableChatIds:w,onUpdate:y,onRemove:j},`${k}-${O}`))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'提示:可以从下拉框选择已配置的聊天流,或手动输入。输入 "*" 启用全局共享'})]},k)}),r.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($e,{id:"all_global_jargon",checked:r.all_global_jargon??!1,onCheckedChange:N=>i({...r,all_global_jargon:N})}),e.jsx(C,{htmlFor:"all_global_jargon",className:"cursor-pointer",children:"全局黑话模式"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"开启后,新增的黑话将默认设为全局(所有聊天流共享)。关闭后,已记录的全局黑话不会改变,需要手动删除。"})]})})]})});function _w({regex:n,reaction:r,onRegexChange:i,onReactionChange:d}){const[m,x]=u.useState(!1),[f,p]=u.useState(""),[g,b]=u.useState(null),[j,y]=u.useState(""),[N,k]=u.useState({}),[w,U]=u.useState(""),O=u.useRef(null),[B,Y]=u.useState("build"),L=T=>T.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),z=(T,A=0)=>{const te=O.current;if(!te)return;const fe=te.selectionStart||0,je=te.selectionEnd||0,pe=n.substring(0,fe)+T+n.substring(je);i(pe),setTimeout(()=>{const he=fe+T.length+A;te.setSelectionRange(he,he),te.focus()},0)};u.useEffect(()=>{if(!n||!f){b(null),k({}),U(r),y("");return}try{const T=L(n),A=new RegExp(T,"g"),te=f.match(A);b(te),y("");const je=new RegExp(T).exec(f);if(je&&je.groups){k(je.groups);let pe=r;Object.entries(je.groups).forEach(([he,ve])=>{pe=pe.replace(new RegExp(`\\[${he}\\]`,"g"),ve||"")}),U(pe)}else k({}),U(r)}catch(T){y(T.message),b(null),k({}),U(r)}},[n,f,r]);const K=()=>{if(!f||!g||g.length===0)return e.jsx("span",{className:"text-muted-foreground",children:f||"请输入测试文本"});try{const T=L(n),A=new RegExp(T,"g");let te=0;const fe=[];let je;for(;(je=A.exec(f))!==null;)je.index>te&&fe.push(e.jsx("span",{children:f.substring(te,je.index)},`text-${te}`)),fe.push(e.jsx("span",{className:"bg-yellow-200 dark:bg-yellow-900 font-semibold",children:je[0]},`match-${je.index}`)),te=je.index+je[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:m,onOpenChange:x,children:[e.jsx(Xu,{asChild:!0,children:e.jsxs(S,{variant:"outline",size:"sm",children:[e.jsx(Qu,{className:"h-4 w-4 mr-1"}),"正则编辑器"]})}),e.jsxs(Ls,{className:"max-w-[95vw] sm:max-w-[900px] max-h-[90vh]",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"正则表达式编辑器"}),e.jsx(Ps,{className:"text-sm",children:"使用可视化工具构建正则表达式,并实时测试效果"})]}),e.jsx(Ze,{className:"max-h-[calc(90vh-120px)]",children:e.jsxs(ga,{value:B,onValueChange:T=>Y(T),className:"w-full",children:[e.jsxs(la,{className:"grid w-full grid-cols-2",children:[e.jsx(ss,{value:"build",children:"🔧 构建器"}),e.jsx(ss,{value:"test",children:"🧪 测试器"})]}),e.jsxs(Ts,{value:"build",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{className:"text-sm font-medium",children:"正则表达式"}),e.jsx(ie,{ref:O,value:n,onChange:T=>i(T.target.value),className:"font-mono text-sm",placeholder:"点击下方按钮构建正则表达式..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{className:"text-sm font-medium",children:"Reaction 内容"}),e.jsx(Qs,{value:r,onChange:T=>d(T.target.value),placeholder:"使用 [捕获组名] 引用捕获的内容...",rows:3,className:"text-sm"})]}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[I.map(T=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-xs font-semibold text-primary",children:T.category}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:T.items.map(A=>e.jsx(S,{variant:"outline",size:"sm",className:"justify-start h-auto py-2 px-3",onClick:()=>z(A.pattern,A.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:A.label}),e.jsx("code",{className:"ml-auto text-xs bg-muted px-1.5 py-0.5 rounded font-mono",children:A.pattern})]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-0.5",children:A.desc})]})},A.label))})]},T.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(S,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>i("^(?P\\S{1,20})是这样的$"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsxs("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:["^(?P\\S","{1,20}",")是这样的$"]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"匹配「某事物是这样的」并捕获事物名称"})]})}),e.jsx(S,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>i("(?:[^,。.\\s]+,\\s*)?我(?:也)?[没沒]要求你\\s*(?P.+?)[.。,,]?$"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsx("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:"(?:[^,。.\\s]+,\\s*)?我(?:也)?[没沒]要求你\\s*(?P.+?)[.。,,]?$"}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"匹配「我没要求你做某事」并捕获具体行为"})]})}),e.jsx(S,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>i("(?P.+?)(?:是|为什么|怎么)"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsx("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:"(?P.+?)(?:是|为什么|怎么)"}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"捕获问题主题词"})]})})]})]})]}),e.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3 space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-blue-900 dark:text-blue-100",children:"💡 使用提示"}),e.jsxs("ul",{className:"text-xs text-blue-700 dark:text-blue-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"点击输入框设置光标位置,然后点击按钮插入模式"}),e.jsxs("li",{children:["命名捕获组格式:",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"(?P<名称>模式)"})]}),e.jsxs("li",{children:["在 reaction 中使用 ",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"[名称]"})," 引用捕获的内容"]}),e.jsx("li",{children:"切换到测试器标签页验证正则表达式效果"})]})]})]}),e.jsxs(Ts,{value:"test",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{className:"text-sm font-medium",children:"当前正则表达式"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:n||"(未设置)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"test-text",className:"text-sm font-medium",children:"测试文本"}),e.jsx(Qs,{id:"test-text",value:f,onChange:T=>p(T.target.value),placeholder:`在此输入要测试的文本... 例如:打游戏是这样的`,className:"min-h-[100px] text-sm"})]}),j&&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:j})]}),!j&&f&&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(C,{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:K()})})]}),Object.keys(N).length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{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(N).map(([T,A])=>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:["[",T,"]"]}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("span",{className:"font-mono bg-muted px-2 py-0.5 rounded",children:A})]},T))})})]}),Object.keys(N).length>0&&r&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{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 Sw=bt.memo(function({keywordReactionConfig:r,responsePostProcessConfig:i,chineseTypoConfig:d,responseSplitterConfig:m,onKeywordReactionChange:x,onResponsePostProcessChange:f,onChineseTypoChange:p,onResponseSplitterChange:g}){const b=()=>{x({...r,regex_rules:[...r.regex_rules,{regex:[""],reaction:""}]})},j=z=>{x({...r,regex_rules:r.regex_rules.filter((K,I)=>I!==z)})},y=(z,K,I)=>{const T=[...r.regex_rules];K==="regex"&&typeof I=="string"?T[z]={...T[z],regex:[I]}:K==="reaction"&&typeof I=="string"&&(T[z]={...T[z],reaction:I}),x({...r,regex_rules:T})},N=()=>{x({...r,keyword_rules:[...r.keyword_rules,{keywords:[],reaction:""}]})},k=z=>{x({...r,keyword_rules:r.keyword_rules.filter((K,I)=>I!==z)})},w=(z,K,I)=>{const T=[...r.keyword_rules];typeof I=="string"&&(T[z]={...T[z],reaction:I}),x({...r,keyword_rules:T})},U=z=>{const K=[...r.keyword_rules];K[z]={...K[z],keywords:[...K[z].keywords||[],""]},x({...r,keyword_rules:K})},O=(z,K)=>{const I=[...r.keyword_rules];I[z]={...I[z],keywords:(I[z].keywords||[]).filter((T,A)=>A!==K)},x({...r,keyword_rules:I})},B=(z,K,I)=>{const T=[...r.keyword_rules],A=[...T[z].keywords||[]];A[K]=I,T[z]={...T[z],keywords:A},x({...r,keyword_rules:T})},Y=({rule:z})=>{const K=`{ regex = [${(z.regex||[]).map(I=>`"${I}"`).join(", ")}], reaction = "${z.reaction}" }`;return e.jsxs(La,{children:[e.jsx(Ua,{asChild:!0,children:e.jsxs(S,{variant:"outline",size:"sm",children:[e.jsx(Rt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(ka,{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:K})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},L=({rule:z})=>{const K=`[[keyword_reaction.keyword_rules]] keywords = [${(z.keywords||[]).map(I=>`"${I}"`).join(", ")}] reaction = "${z.reaction}"`;return e.jsxs(La,{children:[e.jsx(Ua,{asChild:!0,children:e.jsxs(S,{variant:"outline",size:"sm",children:[e.jsx(Rt,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(ka,{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:K})}),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(S,{onClick:b,size:"sm",variant:"outline",children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"添加正则规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[r.regex_rules.map((z,K)=>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:["正则规则 ",K+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_w,{regex:z.regex&&z.regex[0]||"",reaction:z.reaction,onRegexChange:I=>y(K,"regex",I),onReactionChange:I=>y(K,"reaction",I)}),e.jsx(Y,{rule:z}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{size:"sm",variant:"ghost",children:e.jsx(We,{className:"h-4 w-4"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:["确定要删除正则规则 ",K+1," 吗?此操作无法撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>j(K),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{className:"text-xs font-medium",children:"正则表达式(Python 语法)"}),e.jsx(ie,{value:z.regex&&z.regex[0]||"",onChange:I=>y(K,"regex",I.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(C,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(Qs,{value:z.reaction,onChange:I=>y(K,"reaction",I.target.value),placeholder:`触发后麦麦的反应... 可以使用 [捕获组名] 来引用正则表达式中的内容`,rows:3,className:"text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"使用 [捕获组名] 引用正则表达式中的命名捕获组,例如 [n] 会被替换为捕获的内容"})]})]})]},K)),r.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(S,{onClick:N,size:"sm",variant:"outline",children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"添加关键词规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[r.keyword_rules.map((z,K)=>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:["关键词规则 ",K+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{rule:z}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{size:"sm",variant:"ghost",children:e.jsx(We,{className:"h-4 w-4"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:["确定要删除关键词规则 ",K+1," 吗?此操作无法撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>k(K),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(C,{className:"text-xs font-medium",children:"关键词列表"}),e.jsxs(S,{onClick:()=>U(K),size:"sm",variant:"ghost",children:[e.jsx(dt,{className:"h-3 w-3 mr-1"}),"添加关键词"]})]}),e.jsxs("div",{className:"space-y-2",children:[(z.keywords||[]).map((I,T)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{value:I,onChange:A=>B(K,T,A.target.value),placeholder:"关键词",className:"flex-1"}),e.jsx(S,{onClick:()=>O(K,T),size:"sm",variant:"ghost",children:e.jsx(We,{className:"h-4 w-4"})})]},T)),(!z.keywords||z.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(C,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(Qs,{value:z.reaction,onChange:I=>w(K,"reaction",I.target.value),placeholder:"触发后麦麦的反应...",rows:3,className:"text-sm"})]})]})]},K)),r.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($e,{id:"enable_response_post_process",checked:i.enable_response_post_process,onCheckedChange:z=>f({...i,enable_response_post_process:z})}),e.jsx(C,{htmlFor:"enable_response_post_process",className:"cursor-pointer",children:"启用回复后处理"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"包括错别字生成器和回复分割器"})]}),i.enable_response_post_process&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t pt-6 space-y-4",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-4",children:[e.jsx($e,{id:"enable_chinese_typo",checked:d.enable,onCheckedChange:z=>p({...d,enable:z})}),e.jsx(C,{htmlFor:"enable_chinese_typo",className:"cursor-pointer font-semibold",children:"中文错别字生成器"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"为回复添加随机错别字,让麦麦的回复更自然"}),d.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(C,{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:d.error_rate,onChange:z=>p({...d,error_rate:parseFloat(z.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"min_freq",className:"text-xs font-medium",children:"最小字频阈值"}),e.jsx(ie,{id:"min_freq",type:"number",min:"0",value:d.min_freq,onChange:z=>p({...d,min_freq:parseInt(z.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{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:d.tone_error_rate,onChange:z=>p({...d,tone_error_rate:parseFloat(z.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{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:d.word_replace_rate,onChange:z=>p({...d,word_replace_rate:parseFloat(z.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($e,{id:"enable_response_splitter",checked:m.enable,onCheckedChange:z=>g({...m,enable:z})}),e.jsx(C,{htmlFor:"enable_response_splitter",className:"cursor-pointer font-semibold",children:"回复分割器"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"控制回复的长度和句子数量"}),m.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(C,{htmlFor:"max_length",className:"text-xs font-medium",children:"最大长度"}),e.jsx(ie,{id:"max_length",type:"number",min:"1",value:m.max_length,onChange:z=>g({...m,max_length:parseInt(z.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"回复允许的最大字符数"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"max_sentence_num",className:"text-xs font-medium",children:"最大句子数"}),e.jsx(ie,{id:"max_sentence_num",type:"number",min:"1",value:m.max_sentence_num,onChange:z=>g({...m,max_sentence_num:parseInt(z.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($e,{id:"enable_kaomoji_protection",checked:m.enable_kaomoji_protection,onCheckedChange:z=>g({...m,enable_kaomoji_protection:z})}),e.jsx(C,{htmlFor:"enable_kaomoji_protection",className:"cursor-pointer",children:"启用颜文字保护"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx($e,{id:"enable_overflow_return_all",checked:m.enable_overflow_return_all,onCheckedChange:z=>g({...m,enable_overflow_return_all:z})}),e.jsx(C,{htmlFor:"enable_overflow_return_all",className:"cursor-pointer",children:"超出时一次性返回全部"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"当句子数量超出限制时,合并后一次性返回所有内容"})]})]})})]})]})]})}),Ul="/api/webui/config";async function up(){const r=await(await Se(`${Ul}/bot`)).json();if(!r.success)throw new Error("获取配置数据失败");return r.config}async function Wn(){const r=await(await Se(`${Ul}/model`)).json();if(!r.success)throw new Error("获取模型配置数据失败");return r.config}async function mp(n){const i=await(await Se(`${Ul}/bot`,{method:"POST",body:JSON.stringify(n)})).json();if(!i.success)throw new Error(i.message||"保存配置失败")}async function Cw(){const r=await(await Se(`${Ul}/bot/raw`)).json();if(!r.success)throw new Error("获取配置源代码失败");return r.content}async function kw(n){const i=await(await Se(`${Ul}/bot/raw`,{method:"POST",body:JSON.stringify({raw_content:n})})).json();if(!i.success)throw new Error(i.message||"保存配置失败")}async function Kc(n){const i=await(await Se(`${Ul}/model`,{method:"POST",body:JSON.stringify(n)})).json();if(!i.success)throw new Error(i.message||"保存配置失败")}async function Tw(n,r){const d=await(await Se(`${Ul}/bot/section/${n}`,{method:"POST",body:JSON.stringify(r)})).json();if(!d.success)throw new Error(d.message||`保存配置节 ${n} 失败`)}async function Hu(n,r){const d=await(await Se(`${Ul}/model/section/${n}`,{method:"POST",body:JSON.stringify(r)})).json();if(!d.success)throw new Error(d.message||`保存配置节 ${n} 失败`)}async function Ew(n,r="openai",i="/models"){const d=new URLSearchParams({provider_name:n,parser:r,endpoint:i}),m=await Se(`/api/webui/models/list?${d}`);if(!m.ok){const f=await m.json().catch(()=>({}));throw new Error(f.detail||`获取模型列表失败 (${m.status})`)}const x=await m.json();if(!x.success)throw new Error("获取模型列表失败");return x.models}async function zw(n){const r=new URLSearchParams({provider_name:n}),i=await Se(`/api/webui/models/test-connection-by-name?${r}`,{method:"POST"});if(!i.ok){const d=await i.json().catch(()=>({}));throw new Error(d.detail||`测试连接失败 (${i.status})`)}return await i.json()}const Aw=tr("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"}}),It=u.forwardRef(({className:n,variant:r,...i},d)=>e.jsx("div",{ref:d,role:"alert",className:$(Aw({variant:r}),n),...i}));It.displayName="Alert";const Mw=u.forwardRef(({className:n,...r},i)=>e.jsx("h5",{ref:i,className:$("mb-1 font-medium leading-none tracking-tight",n),...r}));Mw.displayName="AlertTitle";const Yt=u.forwardRef(({className:n,...r},i)=>e.jsx("div",{ref:i,className:$("text-sm [&_p]:leading-relaxed",n),...r}));Yt.displayName="AlertDescription";function Zu({onRestartComplete:n,onRestartFailed:r}){const[i,d]=u.useState(0),[m,x]=u.useState("restarting"),[f,p]=u.useState(0),[g,b]=u.useState(0);u.useEffect(()=>{const N=setInterval(()=>{d(U=>U>=90?U:U+1)},200),k=setInterval(()=>{p(U=>U+1)},1e3),w=setTimeout(()=>{x("checking"),j()},3e3);return()=>{clearInterval(N),clearInterval(k),clearTimeout(w)}},[]);const j=()=>{const k=async()=>{try{if(b(U=>U+1),(await fetch("/api/webui/system/status",{method:"GET",headers:{"Content-Type":"application/json"},signal:AbortSignal.timeout(3e3)})).ok)d(100),x("success"),setTimeout(()=>{n?.()},1500);else throw new Error("Status check failed")}catch{g<60?setTimeout(k,2e3):(x("failed"),r?.())}};k()},y=N=>{const k=Math.floor(N/60),w=N%60;return`${k}:${w.toString().padStart(2,"0")}`};return e.jsx("div",{className:"fixed inset-0 bg-background/95 backdrop-blur-sm z-50 flex items-center justify-center",children:e.jsxs("div",{className:"max-w-md w-full mx-4 space-y-8",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[m==="restarting"&&e.jsxs(e.Fragment,{children:[e.jsx(it,{className:"h-16 w-16 text-primary animate-spin"}),e.jsx("h2",{className:"text-2xl font-bold",children:"正在重启麦麦"}),e.jsx("p",{className:"text-muted-foreground text-center",children:"请稍候,麦麦正在重启中..."})]}),m==="checking"&&e.jsxs(e.Fragment,{children:[e.jsx(it,{className:"h-16 w-16 text-primary animate-spin"}),e.jsx("h2",{className:"text-2xl font-bold",children:"检查服务状态"}),e.jsxs("p",{className:"text-muted-foreground text-center",children:["等待服务恢复... (尝试 ",g,"/60)"]})]}),m==="success"&&e.jsxs(e.Fragment,{children:[e.jsx(aa,{className:"h-16 w-16 text-green-500"}),e.jsx("h2",{className:"text-2xl font-bold",children:"重启成功"}),e.jsx("p",{className:"text-muted-foreground text-center",children:"正在跳转到登录页面..."})]}),m==="failed"&&e.jsxs(e.Fragment,{children:[e.jsx(At,{className:"h-16 w-16 text-destructive"}),e.jsx("h2",{className:"text-2xl font-bold",children:"重启超时"}),e.jsx("p",{className:"text-muted-foreground text-center",children:"服务未能在预期时间内恢复,请手动检查或刷新页面"})]})]}),m!=="failed"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(rr,{value:i,className:"h-2"}),e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:[i,"%"]}),e.jsxs("span",{children:["已用时: ",y(f)]})]})]}),e.jsx("div",{className:"bg-muted/50 rounded-lg p-4 space-y-2",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[m==="restarting"&&"🔄 配置已保存,正在重启主程序...",m==="checking"&&"⏳ 正在等待服务恢复,请勿关闭页面...",m==="success"&&"✅ 配置已生效,服务运行正常",m==="failed"&&"⚠️ 如果长时间无响应,请尝试手动重启"]})}),m==="failed"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>window.location.reload(),className:"flex-1 px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90",children:"刷新页面"}),e.jsx("button",{onClick:()=>{x("checking"),b(0),j()},className:"flex-1 px-4 py-2 bg-secondary text-secondary-foreground rounded-md hover:bg-secondary/90",children:"重试检测"})]})]})})}const Dw={name:"toml",startState:function(){return{inString:!1,stringType:"",lhs:!0,inArray:0}},token:function(n,r){let i;if(!r.inString&&(i=n.match(/^('''|"""|'|")/))&&(r.stringType=i[0],r.inString=!0),n.sol()&&!r.inString&&r.inArray===0&&(r.lhs=!0),r.inString){for(;r.inString;)if(n.match(r.stringType))r.inString=!1;else if(n.peek()==="\\")n.next(),n.next();else{if(n.eol())break;n.match(/^.[^\\\"\']*/)}return r.lhs?"property":"string"}else{if(r.inArray&&n.peek()==="]")return n.next(),r.inArray--,"bracket";if(r.lhs&&n.peek()==="["&&n.skipTo("]"))return n.next(),n.peek()==="]"&&n.next(),"atom";if(n.peek()==="#")return n.skipToEnd(),"comment";if(n.eatSpace())return null;if(r.lhs&&n.eatWhile(function(d){return d!="="&&d!=" "}))return"property";if(r.lhs&&n.peek()==="=")return n.next(),r.lhs=!1,null;if(!r.lhs&&n.match(/^\d\d\d\d[\d\-\:\.T]*Z/))return"atom";if(!r.lhs&&(n.match("true")||n.match("false")))return"atom";if(!r.lhs&&n.peek()==="[")return r.inArray++,n.next(),"bracket";if(!r.lhs&&n.match(/^\-?\d+(?:\.\d+)?/))return"number";n.eatSpace()||n.next()}return null},languageData:{commentTokens:{line:"#"}}},Ow={python:[ky()],json:[Ty(),Ey()],toml:[Cy.define(Dw)],text:[]};function Rw({value:n,onChange:r,language:i="text",readOnly:d=!1,height:m="400px",minHeight:x,maxHeight:f,placeholder:p,theme:g="dark",className:b=""}){const[j,y]=u.useState(!1);if(u.useEffect(()=>{y(!0)},[]),!j)return e.jsx("div",{className:`rounded-md border bg-muted animate-pulse ${b}`,style:{height:m,minHeight:x,maxHeight:f}});const N=[...Ow[i]||[],ep.lineWrapping];return d&&N.push(ep.editable.of(!1)),e.jsx("div",{className:`rounded-md overflow-hidden border ${b}`,children:e.jsx(zy,{value:n,height:m,minHeight:x,maxHeight:f,theme:g==="dark"?Ay:void 0,extensions:N,onChange:r,placeholder:p,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 Lw(n,r,i,d={}){const{debounceMs:m=2e3,onSaveSuccess:x,onSaveError:f}=d,p=u.useRef(null),g=u.useCallback(async(N,k)=>{try{r(!0),await Tw(N,k),i(!1),x?.()}catch(w){console.error(`自动保存 ${N} 失败:`,w),i(!0),f?.(w instanceof Error?w:new Error(String(w)))}finally{r(!1)}},[r,i,x,f]),b=u.useCallback((N,k)=>{n||(i(!0),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{g(N,k)},m))},[n,i,g,m]),j=u.useCallback(async(N,k)=>{p.current&&(clearTimeout(p.current),p.current=null),await g(N,k)},[g]),y=u.useCallback(()=>{p.current&&(clearTimeout(p.current),p.current=null)},[]);return u.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),{triggerAutoSave:b,saveNow:j,cancelPendingAutoSave:y}}function Et(n,r,i,d){u.useEffect(()=>{n&&!i&&d(r,n)},[n])}const Uw=500;function Bw(){const[n,r]=u.useState(!0),[i,d]=u.useState(!1),[m,x]=u.useState(!1),[f,p]=u.useState(!1),[g,b]=u.useState(!1),[j,y]=u.useState(!1),[N,k]=u.useState("visual"),[w,U]=u.useState(""),[O,B]=u.useState(!1),{toast:Y}=$s(),[L,z]=u.useState(null),[K,I]=u.useState(null),[T,A]=u.useState(null),[te,fe]=u.useState(null),[je,pe]=u.useState(null),[he,ve]=u.useState(null),[be,D]=u.useState(null),[J,q]=u.useState(null),[se,R]=u.useState(null),[ue,me]=u.useState(null),[_e,Ce]=u.useState(null),[ze,ge]=u.useState(null),[ae,re]=u.useState(null),[F,P]=u.useState(null),[Te,Le]=u.useState(null),[E,xe]=u.useState(null),[Ye,ke]=u.useState(null),Q=u.useRef(!0),Ne=u.useRef({}),qe=u.useCallback(ye=>{Ne.current=ye,z(ye.bot),I(ye.personality);const _s=ye.chat;_s.talk_value_rules||(_s.talk_value_rules=[]),A(_s),fe(ye.expression),pe(ye.emoji),ve(ye.memory),D(ye.tool),q(ye.voice),R(ye.lpmm_knowledge),me(ye.keyword_reaction),Ce(ye.response_post_process),ge(ye.chinese_typo),re(ye.response_splitter),P(ye.log),Le(ye.debug),xe(ye.maim_message),ke(ye.telemetry)},[]),Fs=u.useCallback(()=>({...Ne.current,bot:L,personality:K,chat:T,expression:te,emoji:je,memory:he,tool:be,voice:J,lpmm_knowledge:se,keyword_reaction:ue,response_post_process:_e,chinese_typo:ze,response_splitter:ae,log:F,debug:Te,maim_message:E,telemetry:Ye}),[L,K,T,te,je,he,be,J,se,ue,_e,ze,ae,F,Te,E,Ye]),ks=u.useCallback(async()=>{try{const ye=await Cw();U(ye),B(!1)}catch(ye){Y({variant:"destructive",title:"加载失败",description:ye instanceof Error?ye.message:"加载源代码失败"})}},[Y]),xt=u.useCallback(async()=>{try{r(!0);const ye=await up();qe(ye),p(!1),Q.current=!1,await ks()}catch(ye){console.error("加载配置失败:",ye),Y({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}finally{r(!1)}},[Y,ks,qe]);u.useEffect(()=>{xt()},[xt]);const{triggerAutoSave:js,cancelPendingAutoSave:Vs}=Lw(Q.current,x,p);Et(L,"bot",Q.current,js),Et(K,"personality",Q.current,js),Et(T,"chat",Q.current,js),Et(te,"expression",Q.current,js),Et(je,"emoji",Q.current,js),Et(he,"memory",Q.current,js),Et(be,"tool",Q.current,js),Et(J,"voice",Q.current,js),Et(se,"lpmm_knowledge",Q.current,js),Et(ue,"keyword_reaction",Q.current,js),Et(_e,"response_post_process",Q.current,js),Et(ze,"chinese_typo",Q.current,js),Et(ae,"response_splitter",Q.current,js),Et(F,"log",Q.current,js),Et(Te,"debug",Q.current,js),Et(E,"maim_message",Q.current,js),Et(Ye,"telemetry",Q.current,js);const X=async()=>{try{d(!0),await kw(w),p(!1),B(!1),Y({title:"保存成功",description:"配置已保存"}),await xt()}catch(ye){B(!0),Y({variant:"destructive",title:"保存失败",description:ye instanceof Error?ye.message:"保存配置失败"})}finally{d(!1)}},He=async ye=>{if(f){Y({variant:"destructive",title:"切换失败",description:"请先保存当前更改"});return}if(k(ye),ye==="source")await ks();else try{const _s=await up();qe(_s),p(!1)}catch(_s){console.error("加载配置失败:",_s),Y({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}},De=async()=>{try{d(!0),Vs(),await mp(Fs()),p(!1),Y({title:"保存成功",description:"麦麦主程序配置已保存"})}catch(ye){console.error("保存配置失败:",ye),Y({title:"保存失败",description:ye.message,variant:"destructive"})}finally{d(!1)}},Ke=async()=>{try{b(!0),Wc().catch(()=>{}),y(!0)}catch(ye){console.error("重启失败:",ye),y(!1),Y({title:"重启失败",description:"无法发送重启请求,请手动重启",variant:"destructive"}),b(!1)}},Ns=async()=>{try{d(!0),Vs(),await mp(Fs()),p(!1),Y({title:"保存成功",description:"配置已保存,即将重启麦麦..."}),await new Promise(ye=>setTimeout(ye,Uw)),await Ke()}catch(ye){console.error("保存失败:",ye),Y({title:"保存失败",description:ye.message,variant:"destructive"})}finally{d(!1)}},Je=()=>{localStorage.removeItem("access-token"),window.location.href="/auth"},Ks=()=>{y(!1),b(!1),Y({title:"重启失败",description:"服务器未能在预期时间内恢复,请手动检查",variant:"destructive"})};return n?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(S,{onClick:N==="visual"?De:X,disabled:i||m||!f||g,size:"sm",variant:"outline",className:"w-20 sm:w-24",children:[e.jsx(fi,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{className:"ml-1 truncate text-xs sm:text-sm",children:i?"保存中":m?"自动":f?"保存":"已保存"})]}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsxs(S,{disabled:i||m||g,size:"sm",className:"w-20 sm:w-28",children:[e.jsx(hi,{className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"ml-1 truncate text-xs sm:text-sm",children:g?"重启中":f?"保存重启":"重启"})]})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认重启麦麦?"}),e.jsx(cs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:f?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:f?Ns:Ke,children:f?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsx("div",{className:"flex",children:e.jsx(ga,{value:N,onValueChange:ye=>He(ye),className:"w-full",children:e.jsxs(la,{className:"h-8 sm:h-9 w-full grid grid-cols-2",children:[e.jsxs(ss,{value:"visual",className:"text-xs sm:text-sm",children:[e.jsx(ly,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"可视化编辑"]}),e.jsxs(ss,{value:"source",className:"text-xs sm:text-sm",children:[e.jsx(ny,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"源代码编辑"]})]})})})]}),e.jsxs(It,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(Yt,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),N==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(It,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(Yt,{children:[e.jsx("strong",{children:"源代码模式(高级功能):"}),"直接编辑 TOML 配置文件。此功能仅适用于熟悉 TOML 语法的高级用户。保存时会在后端验证格式,只有格式完全正确才能保存。",O&&e.jsx("span",{className:"text-destructive font-semibold ml-2",children:"⚠️ 上次保存失败,请检查 TOML 格式"})]})]}),e.jsx(Rw,{value:w,onChange:ye=>{U(ye),p(!0),O&&B(!1)},language:"toml",theme:"dark",height:"calc(100vh - 280px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),N==="visual"&&e.jsx(e.Fragment,{children:e.jsxs(ga,{defaultValue:"bot",className:"w-full",children:[e.jsxs(la,{className:"flex flex-wrap h-auto gap-1 p-1 sm:grid sm:grid-cols-5 lg:grid-cols-9",children:[e.jsx(ss,{value:"bot",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"基本信息"}),e.jsx(ss,{value:"personality",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"人格"}),e.jsx(ss,{value:"chat",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"聊天"}),e.jsx(ss,{value:"expression",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"表达"}),e.jsx(ss,{value:"features",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"功能"}),e.jsx(ss,{value:"processing",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"处理"}),e.jsx(ss,{value:"voice",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"语音"}),e.jsx(ss,{value:"lpmm",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"知识库"}),e.jsx(ss,{value:"other",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"其他"})]}),e.jsx(Ts,{value:"bot",className:"space-y-4",children:L&&e.jsx(cw,{config:L,onChange:z})}),e.jsx(Ts,{value:"personality",className:"space-y-4",children:K&&e.jsx(ow,{config:K,onChange:I})}),e.jsx(Ts,{value:"chat",className:"space-y-4",children:T&&e.jsx(hw,{config:T,onChange:A})}),e.jsx(Ts,{value:"expression",className:"space-y-4",children:te&&e.jsx(ww,{config:te,onChange:fe})}),e.jsx(Ts,{value:"features",className:"space-y-4",children:je&&he&&be&&e.jsx(Nw,{emojiConfig:je,memoryConfig:he,toolConfig:be,onEmojiChange:pe,onMemoryChange:ve,onToolChange:D})}),e.jsx(Ts,{value:"processing",className:"space-y-4",children:ue&&_e&&ze&&ae&&e.jsx(Sw,{keywordReactionConfig:ue,responsePostProcessConfig:_e,chineseTypoConfig:ze,responseSplitterConfig:ae,onKeywordReactionChange:me,onResponsePostProcessChange:Ce,onChineseTypoChange:ge,onResponseSplitterChange:re})}),e.jsx(Ts,{value:"voice",className:"space-y-4",children:J&&e.jsx(fw,{config:J,onChange:q})}),e.jsx(Ts,{value:"lpmm",className:"space-y-4",children:se&&e.jsx(pw,{config:se,onChange:R})}),e.jsxs(Ts,{value:"other",className:"space-y-4",children:[F&&e.jsx(gw,{config:F,onChange:P}),Te&&e.jsx(jw,{config:Te,onChange:Le}),E&&e.jsx(vw,{config:E,onChange:xe}),Ye&&e.jsx(bw,{config:Ye,onChange:ke})]})]})}),j&&e.jsx(Zu,{onRestartComplete:Je,onRestartFailed:Ks})]})})}const rn=u.forwardRef(({className:n,...r},i)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:i,className:$("w-full caption-bottom text-sm",n),...r})}));rn.displayName="Table";const cn=u.forwardRef(({className:n,...r},i)=>e.jsx("thead",{ref:i,className:$("[&_tr]:border-b",n),...r}));cn.displayName="TableHeader";const on=u.forwardRef(({className:n,...r},i)=>e.jsx("tbody",{ref:i,className:$("[&_tr:last-child]:border-0",n),...r}));on.displayName="TableBody";const Hw=u.forwardRef(({className:n,...r},i)=>e.jsx("tfoot",{ref:i,className:$("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",n),...r}));Hw.displayName="TableFooter";const ut=u.forwardRef(({className:n,...r},i)=>e.jsx("tr",{ref:i,className:$("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",n),...r}));ut.displayName="TableRow";const Xe=u.forwardRef(({className:n,...r},i)=>e.jsx("th",{ref:i,className:$("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",n),...r}));Xe.displayName="TableHead";const Ve=u.forwardRef(({className:n,...r},i)=>e.jsx("td",{ref:i,className:$("px-4 py-3 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",n),...r}));Ve.displayName="TableCell";const qw=u.forwardRef(({className:n,...r},i)=>e.jsx("caption",{ref:i,className:$("mt-4 text-sm text-muted-foreground",n),...r}));qw.displayName="TableCaption";const eo=u.forwardRef(({className:n,...r},i)=>e.jsx(Kt,{ref:i,className:$("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",n),...r}));eo.displayName=Kt.displayName;const so=u.forwardRef(({className:n,...r},i)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(Mt,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(Kt.Input,{ref:i,className:$("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",n),...r})]}));so.displayName=Kt.Input.displayName;const to=u.forwardRef(({className:n,...r},i)=>e.jsx(Kt.List,{ref:i,className:$("max-h-[300px] overflow-y-auto overflow-x-hidden",n),...r}));to.displayName=Kt.List.displayName;const ao=u.forwardRef((n,r)=>e.jsx(Kt.Empty,{ref:r,className:"py-6 text-center text-sm",...n}));ao.displayName=Kt.Empty.displayName;const mi=u.forwardRef(({className:n,...r},i)=>e.jsx(Kt.Group,{ref:i,className:$("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",n),...r}));mi.displayName=Kt.Group.displayName;const Gw=u.forwardRef(({className:n,...r},i)=>e.jsx(Kt.Separator,{ref:i,className:$("-mx-1 h-px bg-border",n),...r}));Gw.displayName=Kt.Separator.displayName;const xi=u.forwardRef(({className:n,...r},i)=>e.jsx(Kt.Item,{ref:i,className:$("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",n),...r}));xi.displayName=Kt.Item.displayName;const mt=u.forwardRef(({className:n,...r},i)=>e.jsx(ag,{ref:i,className:$("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",n),...r,children:e.jsx(RN,{className:$("grid place-content-center text-current"),children:e.jsx(Qt,{className:"h-4 w-4"})})}));mt.displayName=ag.displayName;const qg=u.createContext(null),Gg="maibot-completed-tours";function $w(){try{const n=localStorage.getItem(Gg);return n?new Set(JSON.parse(n)):new Set}catch{return new Set}}function xp(n){localStorage.setItem(Gg,JSON.stringify([...n]))}function Fw({children:n}){const[r,i]=u.useState({activeTourId:null,stepIndex:0,isRunning:!1}),d=u.useRef(new Map),[,m]=u.useState(0),[x,f]=u.useState($w),p=u.useCallback((L,z)=>{d.current.set(L,z),m(K=>K+1)},[]),g=u.useCallback(L=>{d.current.delete(L),i(z=>z.activeTourId===L?{...z,activeTourId:null,isRunning:!1,stepIndex:0}:z)},[]),b=u.useCallback((L,z=0)=>{d.current.has(L)&&i({activeTourId:L,stepIndex:z,isRunning:!0})},[]),j=u.useCallback(()=>{i(L=>({...L,isRunning:!1}))},[]),y=u.useCallback(L=>{i(z=>({...z,stepIndex:L}))},[]),N=u.useCallback(()=>{i(L=>({...L,stepIndex:L.stepIndex+1}))},[]),k=u.useCallback(()=>{i(L=>({...L,stepIndex:Math.max(0,L.stepIndex-1)}))},[]),w=u.useCallback(()=>r.activeTourId?d.current.get(r.activeTourId)||[]:[],[r.activeTourId]),U=u.useCallback(L=>{f(z=>{const K=new Set(z);return K.add(L),xp(K),K})},[]),O=u.useCallback(L=>{const{action:z,index:K,status:I,type:T}=L,A=["finished","skipped"];if(z==="close"){i(te=>({...te,isRunning:!1,stepIndex:0}));return}A.includes(I)?i(te=>(I==="finished"&&te.activeTourId&&setTimeout(()=>U(te.activeTourId),0),{...te,isRunning:!1,stepIndex:0})):T==="step:after"&&(z==="next"?i(te=>({...te,stepIndex:K+1})):z==="prev"&&i(te=>({...te,stepIndex:K-1})))},[U]),B=u.useCallback(L=>x.has(L),[x]),Y=u.useCallback(L=>{f(z=>{const K=new Set(z);return K.delete(L),xp(K),K})},[]);return e.jsx(qg.Provider,{value:{state:r,tours:d.current,registerTour:p,unregisterTour:g,startTour:b,stopTour:j,goToStep:y,nextStep:N,prevStep:k,getCurrentSteps:w,handleJoyrideCallback:O,isTourCompleted:B,markTourCompleted:U,resetTourCompleted:Y},children:n})}function Pu(){const n=u.useContext(qg);if(!n)throw new Error("useTour must be used within a TourProvider");return n}const Vw={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)"}},Qw={back:"上一步",close:"关闭",last:"完成",next:"下一步",nextLabelWithProgress:"下一步 ({step}/{steps})",open:"打开对话框",skip:"跳过"};function Iw(){const{state:n,getCurrentSteps:r,handleJoyrideCallback:i}=Pu(),d=r(),[m,x]=u.useState(!1),f=u.useRef(n.stepIndex),p=u.useRef(null);u.useEffect(()=>{f.current!==n.stepIndex&&(x(!1),f.current=n.stepIndex)},[n.stepIndex]),u.useEffect(()=>{if(!n.isRunning||d.length===0){x(!1);return}const j=d[n.stepIndex];if(!j){x(!1);return}const y=j.target;if(y==="body"){x(!0);return}x(!1);const N=setTimeout(()=>{const k=()=>{const B=document.querySelector(y);if(B){const Y=B.getBoundingClientRect();if(Y.width>0&&Y.height>0)return!0}return!1};if(k()){setTimeout(()=>x(!0),100);return}const w=setInterval(()=>{k()&&(clearInterval(w),setTimeout(()=>x(!0),100))},100),U=setTimeout(()=>{clearInterval(w),x(!0)},5e3),O=()=>{clearInterval(w),clearTimeout(U)};p.current=O},150);return()=>{clearTimeout(N),p.current&&(p.current(),p.current=null)}},[n.isRunning,n.stepIndex,d]);const g=u.useRef(null);if(u.useEffect(()=>{let j=document.getElementById("tour-portal-container");return j||(j=document.createElement("div"),j.id="tour-portal-container",j.style.cssText="position: fixed; top: 0; left: 0; z-index: 99999; pointer-events: none;",document.body.appendChild(j)),g.current=j,()=>{}},[]),!n.isRunning||d.length===0||!m)return null;const b=e.jsx(My,{steps:d,stepIndex:n.stepIndex,run:n.isRunning,continuous:!0,showSkipButton:!0,showProgress:!0,disableOverlayClose:!0,disableScrolling:!1,disableScrollParentFix:!1,callback:i,styles:Vw,locale:Qw,scrollOffset:80,scrollToFirstStep:!0,floaterProps:{styles:{floater:{zIndex:99999}},disableAnimation:!0}},`tour-step-${n.stepIndex}`);return g.current?Ub.createPortal(b,g.current):b}const Ma="model-assignment-tour",$g=[{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}],Fg={0:"/config/model",1:"/config/model",2:"/config/modelProvider",3:"/config/modelProvider",4:"/config/modelProvider",5:"/config/modelProvider",6:"/config/modelProvider",7:"/config/modelProvider",8:"/config/modelProvider",9:"/config/modelProvider",10:"/config/modelProvider",11:"/config/model",12:"/config/model",13:"/config/model",14:"/config/model",15:"/config/model",16:"/config/model",17:"/config/model",18:"/config/model",19:"/config/model"},ai=[{id:"siliconflow",name:"SiliconFlow",base_url:"https://api.siliconflow.cn/v1",client_type:"openai",display_name:"硅基流动 (SiliconFlow)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"deepseek",name:"DeepSeek",base_url:"https://api.deepseek.com",client_type:"openai",display_name:"DeepSeek",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"rinkoai",name:"RinkoAI",base_url:"https://rinkoai.com/v1",client_type:"openai",display_name:"RinkoAI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"zhipu",name:"ZhipuAI",base_url:"https://open.bigmodel.cn/api/paas/v4",client_type:"openai",display_name:"智谱 AI (ZhipuAI / GLM)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"moonshot",name:"Moonshot",base_url:"https://api.moonshot.cn/v1",client_type:"openai",display_name:"月之暗面 (Moonshot / Kimi)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"doubao",name:"Doubao",base_url:"https://ark.cn-beijing.volces.com/api/v3",client_type:"openai",display_name:"字节豆包 (Doubao)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"alibaba",name:"Alibaba",base_url:"https://dashscope.aliyuncs.com/compatible-mode/v1",client_type:"openai",display_name:"阿里云百炼 (Alibaba Qwen)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"baichuan",name:"Baichuan",base_url:"https://api.baichuan-ai.com/v1",client_type:"openai",display_name:"百川智能 (Baichuan)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"minimax",name:"MiniMax",base_url:"https://api.minimax.chat/v1",client_type:"openai",display_name:"MiniMax (海螺 AI)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"stepfun",name:"StepFun",base_url:"https://api.stepfun.com/v1",client_type:"openai",display_name:"阶跃星辰 (StepFun)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"lingyi",name:"Lingyi",base_url:"https://api.lingyiwanwu.com/v1",client_type:"openai",display_name:"零一万物 (Lingyi / Yi)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"openai",name:"OpenAI",base_url:"https://api.openai.com/v1",client_type:"openai",display_name:"OpenAI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"xai",name:"xAI",base_url:"https://api.x.ai/v1",client_type:"openai",display_name:"xAI (Grok)",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"anthropic",name:"Anthropic",base_url:"https://api.anthropic.com/v1",client_type:"openai",display_name:"Anthropic (Claude)"},{id:"gemini",name:"Gemini",base_url:"https://generativelanguage.googleapis.com/v1beta",client_type:"gemini",display_name:"Google Gemini",modelFetcher:{endpoint:"/models",parser:"gemini"}},{id:"cohere",name:"Cohere",base_url:"https://api.cohere.ai/v1",client_type:"openai",display_name:"Cohere"},{id:"groq",name:"Groq",base_url:"https://api.groq.com/openai/v1",client_type:"openai",display_name:"Groq",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"together",name:"Together AI",base_url:"https://api.together.xyz/v1",client_type:"openai",display_name:"Together AI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"fireworks",name:"Fireworks",base_url:"https://api.fireworks.ai/inference/v1",client_type:"openai",display_name:"Fireworks AI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"mistral",name:"Mistral",base_url:"https://api.mistral.ai/v1",client_type:"openai",display_name:"Mistral AI",modelFetcher:{endpoint:"/models",parser:"openai"}},{id:"perplexity",name:"Perplexity",base_url:"https://api.perplexity.ai",client_type:"openai",display_name:"Perplexity AI"},{id:"custom",name:"",base_url:"",client_type:"openai",display_name:"自定义"}];function hp(n){return n?n.replace(/\/+$/,"").toLowerCase():""}function Yw(n){if(!n)return null;const r=hp(n);return ai.find(i=>i.id!=="custom"&&hp(i.base_url)===r)||null}function Kw(){const[n,r]=u.useState([]),[i,d]=u.useState(!0),[m,x]=u.useState(!1),[f,p]=u.useState(!1),[g,b]=u.useState(!1),[j,y]=u.useState(!1),[N,k]=u.useState(!1),[w,U]=u.useState(!1),[O,B]=u.useState(null),[Y,L]=u.useState(null),[z,K]=u.useState("custom"),[I,T]=u.useState(!1),[A,te]=u.useState(!1),[fe,je]=u.useState(null),[pe,he]=u.useState(!1),[ve,be]=u.useState(""),[D,J]=u.useState(new Set),[q,se]=u.useState(!1),[R,ue]=u.useState(1),[me,_e]=u.useState(20),[Ce,ze]=u.useState(""),[ge,ae]=u.useState({}),[re,F]=u.useState(new Set),[P,Te]=u.useState(new Map),{toast:Le}=$s(),E=va(),{state:xe,goToStep:Ye,registerTour:ke}=Pu(),Q=u.useRef(null),Ne=u.useRef(!0);u.useEffect(()=>{ke(Ma,$g)},[ke]),u.useEffect(()=>{if(xe.activeTourId===Ma&&xe.isRunning){const _=Fg[xe.stepIndex];_&&!window.location.pathname.endsWith(_.replace("/config/",""))&&E({to:_})}},[xe.stepIndex,xe.activeTourId,xe.isRunning,E]);const qe=u.useRef(xe.stepIndex);u.useEffect(()=>{if(xe.activeTourId===Ma&&xe.isRunning){const _=qe.current,G=xe.stepIndex;_>=3&&_<=9&&G<3&&U(!1),_>=10&&G>=3&&G<=9&&(ae({}),K("custom"),B({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10}),L(null),he(!1),U(!0)),qe.current=G}},[xe.stepIndex,xe.activeTourId,xe.isRunning]),u.useEffect(()=>{if(xe.activeTourId!==Ma||!xe.isRunning)return;const _=G=>{const we=G.target,Ms=xe.stepIndex;Ms===2&&we.closest('[data-tour="add-provider-button"]')?setTimeout(()=>Ye(3),300):Ms===9&&we.closest('[data-tour="provider-cancel-button"]')&&setTimeout(()=>Ye(10),300)};return document.addEventListener("click",_,!0),()=>document.removeEventListener("click",_,!0)},[xe,Ye]),u.useEffect(()=>{Fs()},[]);const Fs=async()=>{try{d(!0);const _=await Wn();r(_.api_providers||[]),b(!1),Ne.current=!1}catch(_){console.error("加载配置失败:",_)}finally{d(!1)}},ks=async()=>{try{y(!0),Wc().catch(()=>{}),k(!0)}catch(_){console.error("重启失败:",_),k(!1),Le({title:"重启失败",description:"无法发送重启请求,请手动重启",variant:"destructive"}),y(!1)}},xt=async()=>{try{x(!0),Q.current&&clearTimeout(Q.current);const _=await Wn();_.api_providers=n,await Kc(_),b(!1),Le({title:"保存成功",description:"正在重启麦麦..."}),await ks()}catch(_){console.error("保存配置失败:",_),Le({title:"保存失败",description:_.message,variant:"destructive"}),x(!1)}},js=()=>{localStorage.removeItem("access-token"),window.location.href="/auth"},Vs=()=>{k(!1),y(!1),Le({title:"重启超时",description:"服务未能在预期时间内恢复,请手动检查或刷新页面",variant:"destructive"})},X=u.useCallback(async _=>{if(!Ne.current)try{p(!0),await Hu("api_providers",_),b(!1)}catch(G){console.error("自动保存失败:",G),b(!0)}finally{p(!1)}},[]);u.useEffect(()=>{if(!Ne.current)return b(!0),Q.current&&clearTimeout(Q.current),Q.current=setTimeout(()=>{X(n)},2e3),()=>{Q.current&&clearTimeout(Q.current)}},[n,X]);const He=async()=>{try{x(!0),Q.current&&clearTimeout(Q.current);const _=await Wn();_.api_providers=n,await Kc(_),b(!1),Le({title:"保存成功",description:"模型提供商配置已保存"})}catch(_){console.error("保存配置失败:",_),Le({title:"保存失败",description:_.message,variant:"destructive"})}finally{x(!1)}},De=(_,G)=>{if(ae({}),_){const we=ai.find(Ms=>Ms.base_url===_.base_url&&Ms.client_type===_.client_type);K(we?.id||"custom"),B(_)}else K("custom"),B({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10});L(G),he(!1),U(!0)},Ke=_=>{K(_),T(!1);const G=ai.find(we=>we.id===_);G&&G.id!=="custom"?B(we=>({...we,name:G.name,base_url:G.base_url,client_type:G.client_type})):G?.id==="custom"&&B(we=>({...we,name:"",base_url:"",client_type:"openai"}))},Ns=u.useMemo(()=>z!=="custom",[z]),Je=async()=>{if(O?.api_key)try{await navigator.clipboard.writeText(O.api_key),Le({title:"复制成功",description:"API Key 已复制到剪贴板"})}catch{Le({title:"复制失败",description:"无法访问剪贴板",variant:"destructive"})}},Ks=()=>{if(!O)return;const _={};if(O.name?.trim()||(_.name="请输入提供商名称"),O.base_url?.trim()||(_.base_url="请输入基础 URL"),O.api_key?.trim()||(_.api_key="请输入 API Key"),Object.keys(_).length>0){ae(_);return}ae({});const G={...O,max_retry:O.max_retry??2,timeout:O.timeout??30,retry_interval:O.retry_interval??10};if(Y!==null){const we=[...n];we[Y]=G,r(we)}else r([...n,G]);U(!1),B(null),L(null)},ye=_=>{if(!_&&O){const G={...O,max_retry:O.max_retry??2,timeout:O.timeout??30,retry_interval:O.retry_interval??10};B(G)}U(_)},_s=_=>{je(_),te(!0)},Ae=()=>{if(fe!==null){const _=n.filter((G,we)=>we!==fe);r(_),Le({title:"删除成功",description:"提供商已从列表中移除"})}te(!1),je(null)},vs=_=>{const G=new Set(D);G.has(_)?G.delete(_):G.add(_),J(G)},bs=()=>{if(D.size===Ss.length)J(new Set);else{const _=Ss.map((G,we)=>n.findIndex(Ms=>Ms===Ss[we]));J(new Set(_))}},Nt=()=>{if(D.size===0){Le({title:"提示",description:"请先选择要删除的提供商",variant:"default"});return}se(!0)},Xs=()=>{const _=n.filter((G,we)=>!D.has(we));r(_),J(new Set),se(!1),Le({title:"批量删除成功",description:`已删除 ${D.size} 个提供商`})},Ss=n.filter(_=>{if(!ve)return!0;const G=ve.toLowerCase();return _.name.toLowerCase().includes(G)||_.base_url.toLowerCase().includes(G)||_.client_type.toLowerCase().includes(G)}),Es=Math.ceil(Ss.length/me),Js=Ss.slice((R-1)*me,R*me),Ha=()=>{const _=parseInt(Ce);_>=1&&_<=Es&&(ue(_),ze(""))},Lt=async _=>{F(G=>new Set(G).add(_));try{const G=await zw(_);Te(we=>new Map(we).set(_,G)),G.network_ok?G.api_key_valid===!0?Le({title:"连接正常",description:`${_} 网络连接正常,API Key 有效 (${G.latency_ms}ms)`}):G.api_key_valid===!1?Le({title:"连接正常但 Key 无效",description:`${_} 网络连接正常,但 API Key 无效或已过期`,variant:"destructive"}):Le({title:"网络连接正常",description:`${_} 可以访问 (${G.latency_ms}ms)`}):Le({title:"连接失败",description:G.error||"无法连接到提供商",variant:"destructive"})}catch(G){Le({title:"测试失败",description:G.message,variant:"destructive"})}finally{F(G=>{const we=new Set(G);return we.delete(_),we})}},ol=async()=>{for(const _ of n)await Lt(_.name)},ba=_=>{const G=re.has(_),we=P.get(_);return G?e.jsxs(Qe,{variant:"secondary",className:"gap-1",children:[e.jsx(it,{className:"h-3 w-3 animate-spin"}),"测试中"]}):we?we.network_ok?we.api_key_valid===!0?e.jsxs(Qe,{className:"gap-1 bg-green-600 hover:bg-green-700",children:[e.jsx(aa,{className:"h-3 w-3"}),"正常"]}):we.api_key_valid===!1?e.jsxs(Qe,{variant:"destructive",className:"gap-1",children:[e.jsx(At,{className:"h-3 w-3"}),"Key无效"]}):e.jsxs(Qe,{className:"gap-1 bg-blue-600 hover:bg-blue-700",children:[e.jsx(aa,{className:"h-3 w-3"}),"可访问"]}):e.jsxs(Qe,{variant:"destructive",className:"gap-1",children:[e.jsx(mg,{className:"h-3 w-3"}),"离线"]}):null};return i?e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})}):e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"AI模型厂商配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理 AI 模型厂商的 API 配置"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[D.size>0&&e.jsxs(S,{onClick:Nt,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(We,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",D.size,")"]}),e.jsxs(S,{onClick:ol,size:"sm",variant:"outline",className:"w-full sm:w-auto",disabled:n.length===0||re.size>0,children:[e.jsx(an,{className:"mr-2 h-4 w-4"}),re.size>0?`测试中 (${re.size})`:"测试全部"]}),e.jsxs(S,{onClick:()=>De(null,null),size:"sm",className:"w-full sm:w-auto","data-tour":"add-provider-button",children:[e.jsx(dt,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"添加提供商"]}),e.jsxs(S,{onClick:He,disabled:m||f||!g||j,size:"sm",variant:"outline",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(fi,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),m?"保存中...":f?"自动保存中...":g?"保存配置":"已保存"]}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsxs(S,{disabled:m||f||j,size:"sm",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(hi,{className:"mr-2 h-4 w-4"}),j?"重启中...":g?"保存并重启":"重启麦麦"]})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认重启麦麦?"}),e.jsx(cs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:g?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:g?xt:ks,children:g?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(It,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(Yt,{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(Mt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"搜索提供商名称、URL 或类型...",value:ve,onChange:_=>be(_.target.value),className:"pl-9"})]}),ve&&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:ve?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'}):Js.map((_,G)=>{const we=n.findIndex(Ms=>Ms===_);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:_.name}),ba(_.name)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 break-all",children:_.base_url})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>Lt(_.name),disabled:re.has(_.name),title:"测试连接",children:re.has(_.name)?e.jsx(it,{className:"h-4 w-4 animate-spin"}):e.jsx(an,{className:"h-4 w-4"})}),e.jsx(S,{variant:"default",size:"sm",onClick:()=>De(_,we),children:e.jsx(ln,{className:"h-4 w-4",strokeWidth:2,fill:"none"})}),e.jsx(S,{size:"sm",onClick:()=>_s(we),className:"bg-red-600 hover:bg-red-700 text-white",children:e.jsx(We,{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:_.client_type})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"最大重试"}),e.jsx("p",{className:"font-medium",children:_.max_retry})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"超时(秒)"}),e.jsx("p",{className:"font-medium",children:_.timeout})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"重试间隔(秒)"}),e.jsx("p",{className:"font-medium",children:_.retry_interval})]})]})]},G)})}),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(rn,{children:[e.jsx(cn,{children:e.jsxs(ut,{children:[e.jsx(Xe,{className:"w-12",children:e.jsx(mt,{checked:D.size===Ss.length&&Ss.length>0,onCheckedChange:bs})}),e.jsx(Xe,{children:"状态"}),e.jsx(Xe,{children:"名称"}),e.jsx(Xe,{children:"基础URL"}),e.jsx(Xe,{children:"客户端类型"}),e.jsx(Xe,{className:"text-right",children:"最大重试"}),e.jsx(Xe,{className:"text-right",children:"超时(秒)"}),e.jsx(Xe,{className:"text-right",children:"重试间隔(秒)"}),e.jsx(Xe,{className:"text-right",children:"操作"})]})}),e.jsx(on,{children:Js.length===0?e.jsx(ut,{children:e.jsx(Ve,{colSpan:9,className:"text-center text-muted-foreground py-8",children:ve?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'})}):Js.map((_,G)=>{const we=n.findIndex(Ms=>Ms===_);return e.jsxs(ut,{children:[e.jsx(Ve,{children:e.jsx(mt,{checked:D.has(we),onCheckedChange:()=>vs(we)})}),e.jsx(Ve,{children:ba(_.name)||e.jsx(Qe,{variant:"outline",className:"text-muted-foreground",children:"未测试"})}),e.jsx(Ve,{className:"font-medium",children:_.name}),e.jsx(Ve,{className:"max-w-xs truncate",title:_.base_url,children:_.base_url}),e.jsx(Ve,{children:_.client_type}),e.jsx(Ve,{className:"text-right",children:_.max_retry}),e.jsx(Ve,{className:"text-right",children:_.timeout}),e.jsx(Ve,{className:"text-right",children:_.retry_interval}),e.jsx(Ve,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>Lt(_.name),disabled:re.has(_.name),title:"测试连接",children:re.has(_.name)?e.jsx(it,{className:"h-4 w-4 animate-spin"}):e.jsx(an,{className:"h-4 w-4"})}),e.jsxs(S,{variant:"default",size:"sm",onClick:()=>De(_,we),children:[e.jsx(ln,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(S,{size:"sm",onClick:()=>_s(we),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(We,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},G)})})]})})}),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(C,{htmlFor:"page-size-provider",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ue,{value:me.toString(),onValueChange:_=>{_e(parseInt(_)),ue(1),J(new Set)},children:[e.jsx(Oe,{id:"page-size-provider",className:"w-20",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"10",children:"10"}),e.jsx(le,{value:"20",children:"20"}),e.jsx(le,{value:"50",children:"50"}),e.jsx(le,{value:"100",children:"100"})]})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(R-1)*me+1," 到"," ",Math.min(R*me,Ss.length)," 条,共 ",Ss.length," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>ue(1),disabled:R===1,className:"hidden sm:flex",children:e.jsx(lr,{className:"h-4 w-4"})}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>ue(_=>Math.max(1,_-1)),disabled:R===1,children:[e.jsx(il,{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:Ce,onChange:_=>ze(_.target.value),onKeyDown:_=>_.key==="Enter"&&Ha(),placeholder:R.toString(),className:"w-16 h-8 text-center",min:1,max:Es}),e.jsx(S,{variant:"outline",size:"sm",onClick:Ha,disabled:!Ce,className:"h-8",children:"跳转"})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>ue(_=>_+1),disabled:R>=Es,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>ue(Es),disabled:R>=Es,className:"hidden sm:flex",children:e.jsx(nr,{className:"h-4 w-4"})})]})]})]}),e.jsx(qs,{open:w,onOpenChange:ye,children:e.jsxs(Ls,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"provider-dialog",preventOutsideClose:xe.isRunning,children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:Y!==null?"编辑提供商":"添加提供商"}),e.jsx(Ps,{children:"配置 API 提供商的连接信息和参数"})]}),e.jsxs("form",{onSubmit:_=>{_.preventDefault(),Ks()},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(C,{htmlFor:"template",children:"提供商模板"}),e.jsxs(La,{open:I,onOpenChange:T,children:[e.jsx(Ua,{asChild:!0,children:e.jsxs(S,{variant:"outline",role:"combobox","aria-expanded":I,className:"w-full justify-between",children:[z?ai.find(_=>_.id===z)?.display_name:"选择提供商模板...",e.jsx(Iu,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(ka,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(eo,{children:[e.jsx(so,{placeholder:"搜索提供商模板..."}),e.jsx(Ze,{className:"h-[300px]",children:e.jsxs(to,{className:"max-h-none overflow-visible",children:[e.jsx(ao,{children:"未找到匹配的模板"}),e.jsx(mi,{children:ai.map(_=>e.jsxs(xi,{value:_.display_name,onSelect:()=>Ke(_.id),children:[e.jsx(Qt,{className:`mr-2 h-4 w-4 ${z===_.id?"opacity-100":"opacity-0"}`}),_.display_name]},_.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(C,{htmlFor:"name",className:ge.name?"text-destructive":"",children:"名称 *"}),e.jsx(ie,{id:"name",value:O?.name||"",onChange:_=>{B(G=>G?{...G,name:_.target.value}:null),ge.name&&ae(G=>({...G,name:void 0}))},placeholder:"例如: DeepSeek, SiliconFlow",className:ge.name?"border-destructive focus-visible:ring-destructive":""}),ge.name&&e.jsx("p",{className:"text-xs text-destructive",children:ge.name})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"provider-url-input",children:[e.jsx(C,{htmlFor:"base_url",className:ge.base_url?"text-destructive":"",children:"基础 URL *"}),e.jsx(ie,{id:"base_url",value:O?.base_url||"",onChange:_=>{B(G=>G?{...G,base_url:_.target.value}:null),ge.base_url&&ae(G=>({...G,base_url:void 0}))},placeholder:"https://api.example.com/v1",disabled:Ns,className:`${Ns?"bg-muted cursor-not-allowed":""} ${ge.base_url?"border-destructive focus-visible:ring-destructive":""}`}),ge.base_url&&e.jsx("p",{className:"text-xs text-destructive",children:ge.base_url}),Ns&&!ge.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(C,{htmlFor:"api_key",className:ge.api_key?"text-destructive":"",children:"API Key *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{id:"api_key",type:pe?"text":"password",value:O?.api_key||"",onChange:_=>{B(G=>G?{...G,api_key:_.target.value}:null),ge.api_key&&ae(G=>({...G,api_key:void 0}))},placeholder:"sk-...",className:`flex-1 ${ge.api_key?"border-destructive focus-visible:ring-destructive":""}`}),e.jsx(S,{type:"button",variant:"outline",size:"icon",onClick:()=>he(!pe),title:pe?"隐藏密钥":"显示密钥",children:pe?e.jsx(ci,{className:"h-4 w-4"}):e.jsx(Rt,{className:"h-4 w-4"})}),e.jsx(S,{type:"button",variant:"outline",size:"icon",onClick:Je,title:"复制密钥",children:e.jsx(Vc,{className:"h-4 w-4"})})]}),ge.api_key&&e.jsx("p",{className:"text-xs text-destructive",children:ge.api_key})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"client_type",children:"客户端类型"}),e.jsxs(Ue,{value:O?.client_type||"openai",onValueChange:_=>B(G=>G?{...G,client_type:_}:null),disabled:Ns,children:[e.jsx(Oe,{id:"client_type",className:Ns?"bg-muted cursor-not-allowed":"",children:e.jsx(Be,{placeholder:"选择客户端类型"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"openai",children:"OpenAI"}),e.jsx(le,{value:"gemini",children:"Gemini"})]})]}),Ns&&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(C,{htmlFor:"max_retry",children:"最大重试"}),e.jsx(ie,{id:"max_retry",type:"number",min:"0",value:O?.max_retry??"",onChange:_=>{const G=_.target.value===""?null:parseInt(_.target.value);B(we=>we?{...we,max_retry:G}:null)},placeholder:"默认: 2"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"timeout",children:"超时(秒)"}),e.jsx(ie,{id:"timeout",type:"number",min:"1",value:O?.timeout??"",onChange:_=>{const G=_.target.value===""?null:parseInt(_.target.value);B(we=>we?{...we,timeout:G}:null)},placeholder:"默认: 30"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"retry_interval",children:"重试间隔(秒)"}),e.jsx(ie,{id:"retry_interval",type:"number",min:"1",value:O?.retry_interval??"",onChange:_=>{const G=_.target.value===""?null:parseInt(_.target.value);B(we=>we?{...we,retry_interval:G}:null)},placeholder:"默认: 10"})]})]})]}),e.jsxs(st,{children:[e.jsx(S,{type:"button",variant:"outline",onClick:()=>U(!1),"data-tour":"provider-cancel-button",children:"取消"}),e.jsx(S,{type:"submit","data-tour":"provider-save-button",children:"保存"})]})]})]})}),e.jsx(hs,{open:A,onOpenChange:te,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:['确定要删除提供商 "',fe!==null?n[fe]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:Ae,children:"删除"})]})]})}),e.jsx(hs,{open:q,onOpenChange:se,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认批量删除"}),e.jsxs(cs,{children:["确定要删除选中的 ",D.size," 个提供商吗? 此操作无法撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:Xs,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),N&&e.jsx(Zu,{onRestartComplete:js,onRestartFailed:Vs})]})}function Vg(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).substring(2,11)}`}function Qg(n){return typeof n=="boolean"?"boolean":typeof n=="number"?"number":"string"}function Xw(n,r){switch(r){case"boolean":return n==="true";case"number":{const i=parseFloat(n);return isNaN(i)?0:i}default:return n}}function Tu(n){return Object.entries(n).map(([r,i])=>({id:Vg(),key:r,value:i,type:Qg(i)}))}function Eu(n){const r={};for(const i of n)i.key.trim()&&(r[i.key.trim()]=i.value);return r}function zu(n){if(!n.trim())return{valid:!0,parsed:{}};try{const r=JSON.parse(n);if(typeof r!="object"||r===null||Array.isArray(r))return{valid:!1,error:"必须是一个 JSON 对象 {}"};for(const[i,d]of Object.entries(r))if(d!==null&&!["string","number","boolean"].includes(typeof d))return{valid:!1,error:`键 "${i}" 的值类型不支持(仅支持 string/number/boolean)`};return{valid:!0,parsed:r}}catch{return{valid:!1,error:"JSON 格式错误"}}}function Jw(n){switch(n){case"boolean":return"布尔";case"number":return"数字";default:return"字符串"}}function Zw(n){switch(n){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 Pw({value:n,onChange:r,className:i,placeholder:d="添加额外参数..."}){const[m,x]=u.useState("list"),[f,p]=u.useState(()=>Tu(n||{})),[g,b]=u.useState(()=>Object.keys(n||{}).length>0?JSON.stringify(n,null,2):""),[j,y]=u.useState(null);u.useEffect(()=>{const Y=Tu(n||{});p(Y),b(Object.keys(n||{}).length>0?JSON.stringify(n,null,2):"")},[n]);const N=u.useMemo(()=>{const Y=zu(g);return Y.valid&&Y.parsed?{success:!0,data:Y.parsed}:{success:!1,data:{}}},[g]),k=u.useCallback(Y=>{const L=Y;if(L==="json"&&m==="list"){const z=Eu(f);b(Object.keys(z).length>0?JSON.stringify(z,null,2):""),y(null)}else if(L==="list"&&m==="json"){const z=zu(g);z.valid&&z.parsed&&(p(Tu(z.parsed)),y(null))}x(L)},[m,f,g]),w=u.useCallback(()=>{const Y={id:Vg(),key:"",value:"",type:"string"},L=[...f,Y];p(L)},[f]),U=u.useCallback(Y=>{const L=f.filter(z=>z.id!==Y);p(L),r(Eu(L))},[f,r]),O=u.useCallback((Y,L,z)=>{const K=f.map(I=>{if(I.id!==Y)return I;if(L==="type"){const T=z;let A;return T==="boolean"?A=I.value==="true"||I.value===!0:T==="number"?A=typeof I.value=="number"?I.value:parseFloat(String(I.value))||0:A=String(I.value),{...I,type:T,value:A}}else return L==="value"?{...I,value:Xw(z,I.type)}:{...I,[L]:z}});p(K),r(Eu(K))},[f,r]),B=u.useCallback(Y=>{b(Y);const L=zu(Y);L.valid&&L.parsed?(y(null),r(L.parsed)):y(L.error||"JSON 格式错误")},[r]);return e.jsxs("div",{className:$("space-y-3",i),children:[e.jsx(C,{className:"text-sm font-medium",children:"额外参数"}),e.jsxs(ga,{value:m,onValueChange:k,className:"w-full",children:[e.jsxs(la,{className:"h-8 p-0.5 bg-muted/60",children:[e.jsx(ss,{value:"list",className:"h-7 px-3 text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"键值对"}),e.jsx(ss,{value:"json",className:"h-7 px-3 text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"JSON"})]}),e.jsxs(Ts,{value:"list",className:"mt-3 space-y-2",children:[f.length===0?e.jsx("div",{className:"text-sm text-muted-foreground text-center py-4 border border-dashed rounded-md",children:d}):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",{})]}),f.map(Y=>e.jsxs("div",{className:"grid grid-cols-[1fr_1fr_90px_32px] gap-2 items-center",children:[e.jsx(ie,{value:Y.key,onChange:L=>O(Y.id,"key",L.target.value),placeholder:"key",className:"h-8 text-sm"}),Y.type==="boolean"?e.jsxs("div",{className:"flex items-center h-8 px-3 border rounded-md bg-background",children:[e.jsx($e,{checked:Y.value===!0,onCheckedChange:L=>O(Y.id,"value",String(L))}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:Y.value?"true":"false"})]}):e.jsx(ie,{type:Y.type==="number"?"number":"text",value:Y.value,onChange:L=>O(Y.id,"value",L.target.value),placeholder:"value",className:"h-8 text-sm",step:Y.type==="number"?"any":void 0}),e.jsxs(Ue,{value:Y.type,onValueChange:L=>O(Y.id,"type",L),children:[e.jsx(Oe,{className:"h-8 text-xs",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"string",children:"字符串"}),e.jsx(le,{value:"number",children:"数字"}),e.jsx(le,{value:"boolean",children:"布尔"})]})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>U(Y.id),children:e.jsx(We,{className:"h-4 w-4"})})]},Y.id))]}),e.jsxs(S,{type:"button",variant:"outline",size:"sm",className:"w-full h-8",onClick:w,children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"添加参数"]})]}),e.jsx(Ts,{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:"编辑"}),j?e.jsxs("div",{className:"flex items-center gap-1 text-xs text-destructive",children:[e.jsx(At,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate max-w-[150px]",children:j})]}):g.trim()&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-green-600 dark:text-green-400",children:[e.jsx(Qt,{className:"h-3 w-3"}),e.jsx("span",{children:"有效"})]})]}),e.jsx(Qs,{value:g,onChange:Y=>B(Y.target.value),placeholder:`{ "key": "value" }`,className:$("font-mono text-sm min-h-[140px] h-[140px] resize-y flex-1",j&&"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:N.success&&Object.keys(N.data).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(N.data).map(([Y,L])=>{const z=Qg(L);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:Y}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("span",{className:$("font-mono",z==="boolean"&&(L?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400"),z==="number"&&"text-blue-600 dark:text-blue-400",z==="string"&&"text-amber-600 dark:text-amber-400"),children:z==="string"?`"${L}"`:String(L)}),e.jsx(Qe,{variant:"secondary",className:$("h-5 text-[10px] px-1.5",Zw(z)),children:Jw(z)})]},Y)})}):N.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 Ww({value:n,label:r,onRemove:i}){const{attributes:d,listeners:m,setNodeRef:x,transform:f,transition:p,isDragging:g}=Fy({id:n}),b={transform:Vy.Transform.toString(f),transition:p,opacity:g?.5:1},j=N=>{N.preventDefault(),N.stopPropagation(),i(n)},y=N=>{N.stopPropagation()};return e.jsx("div",{ref:x,style:b,className:$("inline-flex items-center gap-1",g&&"shadow-lg"),children:e.jsxs(Qe,{variant:"secondary",className:"cursor-move hover:bg-secondary/80 flex items-center gap-1",children:[e.jsx("div",{...d,...m,className:"cursor-grab active:cursor-grabbing flex items-center",children:e.jsx(ry,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx("span",{children:r}),e.jsx("button",{type:"button",className:"ml-1 rounded-sm hover:bg-destructive/20 focus:outline-none focus:ring-1 focus:ring-destructive",onClick:j,onPointerDown:y,onMouseDown:N=>N.stopPropagation(),children:e.jsx(rl,{className:"h-3 w-3 cursor-pointer hover:text-destructive",strokeWidth:2,fill:"none"})})]})})}function e1({options:n,selected:r,onChange:i,placeholder:d="选择选项...",emptyText:m="未找到选项",className:x}){const[f,p]=u.useState(!1),g=Oy(sp($y,{activationConstraint:{distance:8}}),sp(Gy,{coordinateGetter:qy})),b=N=>{r.includes(N)?i(r.filter(k=>k!==N)):i([...r,N])},j=N=>{i(r.filter(k=>k!==N))},y=N=>{const{active:k,over:w}=N;if(w&&k.id!==w.id){const U=r.indexOf(k.id),O=r.indexOf(w.id);i(Hy(r,U,O))}};return e.jsxs(La,{open:f,onOpenChange:p,children:[e.jsx(Ua,{asChild:!0,children:e.jsxs(S,{variant:"outline",role:"combobox","aria-expanded":f,className:$("w-full justify-between min-h-10 h-auto",x),children:[e.jsx(Ry,{sensors:g,collisionDetection:Ly,onDragEnd:y,children:e.jsx(Uy,{items:r,strategy:By,children:e.jsx("div",{className:"flex gap-1 flex-wrap flex-1",children:r.length===0?e.jsx("span",{className:"text-muted-foreground",children:d}):r.map(N=>{const k=n.find(w=>w.value===N);return e.jsx(Ww,{value:N,label:k?.label||N,onRemove:j},N)})})})}),e.jsx(Iu,{className:"ml-2 h-4 w-4 shrink-0 opacity-50",strokeWidth:2,fill:"none"})]})}),e.jsx(ka,{className:"w-full p-0",align:"start",children:e.jsxs(eo,{children:[e.jsx(so,{placeholder:"搜索...",className:"h-9"}),e.jsxs(to,{children:[e.jsx(ao,{children:m}),e.jsx(mi,{children:n.map(N=>{const k=r.includes(N.value);return e.jsxs(xi,{value:N.value,onSelect:()=>b(N.value),children:[e.jsx("div",{className:$("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",k?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Qt,{className:"h-3 w-3",strokeWidth:2,fill:"none"})}),e.jsx("span",{children:N.label})]},N.value)})})]})]})})]})}const _a=bt.memo(function({title:r,description:i,taskConfig:d,modelNames:m,onChange:x,hideTemperature:f=!1,hideMaxTokens:p=!1,dataTour:g}){const b=j=>{x("model_list",j)};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:r}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:i})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":g,children:[e.jsx(C,{children:"模型列表"}),e.jsx(e1,{options:m.map(j=>({label:j,value:j})),selected:d.model_list||[],onChange:b,placeholder:"选择模型...",emptyText:"暂无可用模型"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[!f&&e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(C,{children:"温度"}),e.jsx(ie,{type:"number",step:"0.1",min:"0",max:"1",value:d.temperature??.3,onChange:j=>{const y=parseFloat(j.target.value);!isNaN(y)&&y>=0&&y<=1&&x("temperature",y)},className:"w-20 h-8 text-sm"})]}),e.jsx(pa,{value:[d.temperature??.3],onValueChange:j=>x("temperature",j[0]),min:0,max:1,step:.1,className:"w-full"})]}),!p&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{children:"最大 Token"}),e.jsx(ie,{type:"number",step:"1",min:"1",value:d.max_tokens??1024,onChange:j=>x("max_tokens",parseInt(j.target.value))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(C,{children:"慢请求阈值 (秒)"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"超时警告"})]}),e.jsx(ie,{type:"number",step:"1",min:"1",value:d.slow_threshold??15,onChange:j=>{const y=parseInt(j.target.value);!isNaN(y)&&y>=1&&x("slow_threshold",y)},placeholder:"15"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"模型响应时间超过此阈值将输出警告日志"})]})]})]})}),s1=bt.memo(function({paginatedModels:r,allModels:i,onEdit:d,onDelete:m,isModelUsed:x,searchQuery:f}){return r.length===0?e.jsx("div",{className:"md:hidden text-center text-muted-foreground py-8 rounded-lg border bg-card",children:f?"未找到匹配的模型":"暂无模型配置"}):e.jsx("div",{className:"md:hidden space-y-3",children:r.map((p,g)=>{const b=i.findIndex(y=>y===p),j=x(p.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:p.name}),e.jsx(Qe,{variant:j?"default":"secondary",className:j?"bg-green-600 hover:bg-green-700":"",children:j?"已使用":"未使用"})]}),e.jsx("p",{className:"text-xs text-muted-foreground break-all",title:p.model_identifier,children:p.model_identifier})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs(S,{variant:"default",size:"sm",onClick:()=>d(p,b),children:[e.jsx(ln,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(S,{size:"sm",onClick:()=>m(b),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(We,{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:p.api_provider})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"模型温度"}),e.jsx("p",{className:"font-medium",children:p.temperature!=null?p.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:["¥",p.price_in,"/M"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输出价格"}),e.jsxs("p",{className:"font-medium",children:["¥",p.price_out,"/M"]})]})]})]},g)})})}),t1=bt.memo(function({paginatedModels:r,allModels:i,filteredModels:d,selectedModels:m,onEdit:x,onDelete:f,onToggleSelection:p,onToggleSelectAll:g,isModelUsed:b,searchQuery:j}){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(rn,{children:[e.jsx(cn,{children:e.jsxs(ut,{children:[e.jsx(Xe,{className:"w-12",children:e.jsx(mt,{checked:m.size===d.length&&d.length>0,onCheckedChange:g})}),e.jsx(Xe,{className:"w-24",children:"使用状态"}),e.jsx(Xe,{children:"模型名称"}),e.jsx(Xe,{children:"模型标识符"}),e.jsx(Xe,{children:"提供商"}),e.jsx(Xe,{className:"text-center",children:"温度"}),e.jsx(Xe,{className:"text-right",children:"输入价格"}),e.jsx(Xe,{className:"text-right",children:"输出价格"}),e.jsx(Xe,{className:"text-right",children:"操作"})]})}),e.jsx(on,{children:r.length===0?e.jsx(ut,{children:e.jsx(Ve,{colSpan:9,className:"text-center text-muted-foreground py-8",children:j?"未找到匹配的模型":"暂无模型配置"})}):r.map((y,N)=>{const k=i.findIndex(U=>U===y),w=b(y.name);return e.jsxs(ut,{children:[e.jsx(Ve,{children:e.jsx(mt,{checked:m.has(k),onCheckedChange:()=>p(k)})}),e.jsx(Ve,{children:e.jsx(Qe,{variant:w?"default":"secondary",className:w?"bg-green-600 hover:bg-green-700":"",children:w?"已使用":"未使用"})}),e.jsx(Ve,{className:"font-medium",children:y.name}),e.jsx(Ve,{className:"max-w-xs truncate",title:y.model_identifier,children:y.model_identifier}),e.jsx(Ve,{children:y.api_provider}),e.jsx(Ve,{className:"text-center",children:y.temperature!=null?y.temperature:e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsxs(Ve,{className:"text-right",children:["¥",y.price_in,"/M"]}),e.jsxs(Ve,{className:"text-right",children:["¥",y.price_out,"/M"]}),e.jsx(Ve,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(S,{variant:"default",size:"sm",onClick:()=>x(y,k),children:[e.jsx(ln,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(S,{size:"sm",onClick:()=>f(k),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(We,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},N)})})]})})})}),a1=300*1e3,fp=new Map,l1=[10,20,50,100],n1=bt.memo(function({page:r,pageSize:i,totalItems:d,jumpToPage:m,onPageChange:x,onPageSizeChange:f,onJumpToPageChange:p,onJumpToPage:g,onSelectionClear:b}){const j=Math.ceil(d/i),y=k=>{f(parseInt(k)),x(1),b?.()},N=k=>{k.key==="Enter"&&g()};return d===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(C,{htmlFor:"page-size-model",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ue,{value:i.toString(),onValueChange:y,children:[e.jsx(Oe,{id:"page-size-model",className:"w-20",children:e.jsx(Be,{})}),e.jsx(Re,{children:l1.map(k=>e.jsx(le,{value:k.toString(),children:k},k))})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(r-1)*i+1," 到"," ",Math.min(r*i,d)," 条,共 ",d," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>x(1),disabled:r===1,className:"hidden sm:flex",children:e.jsx(lr,{className:"h-4 w-4"})}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>x(Math.max(1,r-1)),disabled:r===1,children:[e.jsx(il,{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:m,onChange:k=>p(k.target.value),onKeyDown:N,placeholder:r.toString(),className:"w-16 h-8 text-center",min:1,max:j}),e.jsx(S,{variant:"outline",size:"sm",onClick:g,disabled:!m,className:"h-8",children:"跳转"})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>x(r+1),disabled:r>=j,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>x(j),disabled:r>=j,className:"hidden sm:flex",children:e.jsx(nr,{className:"h-4 w-4"})})]})]})});function r1(n){const{models:r,taskConfig:i,debounceMs:d=2e3,onSavingChange:m,onUnsavedChange:x}=n,f=u.useRef(null),p=u.useRef(null),g=u.useRef(!0),b=u.useCallback(()=>{f.current&&(clearTimeout(f.current),f.current=null),p.current&&(clearTimeout(p.current),p.current=null)},[]),j=u.useCallback(k=>{const w={model_identifier:k.model_identifier,name:k.name,api_provider:k.api_provider,price_in:k.price_in??0,price_out:k.price_out??0,force_stream_mode:k.force_stream_mode??!1,extra_params:k.extra_params??{}};return k.temperature!=null&&(w.temperature=k.temperature),k.max_tokens!=null&&(w.max_tokens=k.max_tokens),w},[]),y=u.useCallback(async k=>{try{m?.(!0);const w=k.map(j);await Hu("models",w),x?.(!1)}catch(w){console.error("自动保存模型列表失败:",w),x?.(!0)}finally{m?.(!1)}},[m,x,j]),N=u.useCallback(async k=>{try{m?.(!0),await Hu("model_task_config",k),x?.(!1)}catch(w){console.error("自动保存任务配置失败:",w),x?.(!0)}finally{m?.(!1)}},[m,x]);return u.useEffect(()=>{if(!g.current)return x?.(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{y(r)},d),()=>{f.current&&clearTimeout(f.current)}},[r,y,d,x]),u.useEffect(()=>{if(!(g.current||!i))return x?.(!0),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{N(i)},d),()=>{p.current&&clearTimeout(p.current)}},[i,N,d,x]),u.useEffect(()=>()=>{b()},[b]),{clearTimers:b,initialLoadRef:g}}function i1(n={}){const{onCloseEditDialog:r}=n,i=va(),{registerTour:d,startTour:m,state:x,goToStep:f}=Pu(),p=u.useRef(x.stepIndex);return u.useEffect(()=>{d(Ma,$g)},[d]),u.useEffect(()=>{if(x.activeTourId===Ma&&x.isRunning){const b=Fg[x.stepIndex];b&&!window.location.pathname.endsWith(b.replace("/config/",""))&&i({to:b})}},[x.stepIndex,x.activeTourId,x.isRunning,i]),u.useEffect(()=>{if(x.activeTourId===Ma&&x.isRunning){const b=p.current,j=x.stepIndex;b>=12&&b<=17&&j<12&&r?.(),p.current=j}},[x.stepIndex,x.activeTourId,x.isRunning,r]),u.useEffect(()=>{if(x.activeTourId!==Ma||!x.isRunning)return;const b=j=>{const y=j.target,N=x.stepIndex;N===2&&y.closest('[data-tour="add-provider-button"]')?setTimeout(()=>f(3),300):N===9&&y.closest('[data-tour="provider-cancel-button"]')?setTimeout(()=>f(10),300):N===11&&y.closest('[data-tour="add-model-button"]')?setTimeout(()=>f(12),300):N===17&&y.closest('[data-tour="model-cancel-button"]')?setTimeout(()=>f(18),300):N===18&&y.closest('[data-tour="tasks-tab-trigger"]')&&setTimeout(()=>f(19),300)};return document.addEventListener("click",b,!0),()=>document.removeEventListener("click",b,!0)},[x,f]),{startTour:u.useCallback(()=>{m(Ma)},[m]),isRunning:x.isRunning&&x.activeTourId===Ma,stepIndex:x.stepIndex}}function c1(n){const{getProviderConfig:r}=n,[i,d]=u.useState([]),[m,x]=u.useState(!1),[f,p]=u.useState(null),[g,b]=u.useState(null),j=u.useCallback(()=>{d([]),p(null),b(null)},[]),y=u.useCallback(async(N,k=!1)=>{const w=r(N);if(!w?.base_url){d([]),b(null),p('提供商配置不完整,请先在"模型提供商配置"中配置');return}if(!w.api_key){d([]),b(null),p('该提供商未配置 API Key,请先在"模型提供商配置"中填写');return}const U=Yw(w.base_url);if(b(U),!U?.modelFetcher){d([]),p(null);return}const O=`${N}:${w.base_url}`,B=fp.get(O);if(!k&&B&&Date.now()-B.timestampT(!1)}),{clearTimers:Ye,initialLoadRef:ke}=r1({models:n,taskConfig:g,onSavingChange:U,onUnsavedChange:B}),Q=u.useCallback(async()=>{try{y(!0);const _=await Wn(),G=_.models||[];r(G),p(G.map(Ms=>Ms.name));const we=_.api_providers||[];d(we.map(Ms=>Ms.name)),x(we),b(_.model_task_config||null),B(!1),ke.current=!1}catch(_){console.error("加载配置失败:",_)}finally{y(!1)}},[ke]);u.useEffect(()=>{Q()},[Q]);const Ne=u.useCallback(_=>m.find(G=>G.name===_),[m]),{availableModels:qe,fetchingModels:Fs,modelFetchError:ks,matchedTemplate:xt,fetchModelsForProvider:js,clearModels:Vs}=c1({getProviderConfig:Ne});u.useEffect(()=>{I&&A?.api_provider&&js(A.api_provider)},[I,A?.api_provider,js]);const X=async()=>{try{L(!0),Wc().catch(()=>{}),K(!0)}catch(_){console.error("重启失败:",_),K(!1),Le({title:"重启失败",description:"无法发送重启请求,请手动重启",variant:"destructive"}),L(!1)}},He=_=>{const G={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??{}};return _.temperature!=null&&(G.temperature=_.temperature),_.max_tokens!=null&&(G.max_tokens=_.max_tokens),G},De=async()=>{try{k(!0),Ye();const _=await Wn();_.models=n.map(He),_.model_task_config=g,await Kc(_),B(!1),Le({title:"保存成功",description:"正在重启麦麦..."}),await X()}catch(_){console.error("保存配置失败:",_),Le({title:"保存失败",description:_.message,variant:"destructive"}),k(!1)}},Ke=()=>{localStorage.removeItem("access-token"),window.location.href="/auth"},Ns=()=>{K(!1),L(!1),Le({title:"重启超时",description:"服务未能在预期时间内恢复,请手动检查或刷新页面",variant:"destructive"})},Je=async()=>{try{k(!0),Ye();const _=await Wn();_.models=n.map(He),_.model_task_config=g,await Kc(_),B(!1),Le({title:"保存成功",description:"模型配置已保存"}),await Q()}catch(_){console.error("保存配置失败:",_),Le({title:"保存失败",description:_.message,variant:"destructive"})}finally{k(!1)}},Ks=(_,G)=>{Te({}),te(_||{model_identifier:"",name:"",api_provider:i[0]||"",price_in:0,price_out:0,temperature:null,max_tokens:null,force_stream_mode:!1,extra_params:{}}),je(G),T(!0)},ye=()=>{if(!A)return;const _={};if(A.name?.trim()||(_.name="请输入模型名称"),A.api_provider?.trim()||(_.api_provider="请选择 API 提供商"),A.model_identifier?.trim()||(_.model_identifier="请输入模型标识符"),Object.keys(_).length>0){Te(_);return}Te({});const G={model_identifier:A.model_identifier,name:A.name,api_provider:A.api_provider,price_in:A.price_in??0,price_out:A.price_out??0,force_stream_mode:A.force_stream_mode??!1,extra_params:A.extra_params??{}};A.temperature!=null&&(G.temperature=A.temperature),A.max_tokens!=null&&(G.max_tokens=A.max_tokens);let we,Ms=null;if(fe!==null?(Ms=n[fe].name,we=[...n],we[fe]=G):we=[...n,G],r(we),p(we.map(Dt=>Dt.name)),Ms&&Ms!==G.name&&g){const Dt=ji=>ji.map(cr=>cr===Ms?G.name:cr);b({...g,utils:{...g.utils,model_list:Dt(g.utils?.model_list||[])},utils_small:{...g.utils_small,model_list:Dt(g.utils_small?.model_list||[])},tool_use:{...g.tool_use,model_list:Dt(g.tool_use?.model_list||[])},replyer:{...g.replyer,model_list:Dt(g.replyer?.model_list||[])},planner:{...g.planner,model_list:Dt(g.planner?.model_list||[])},vlm:{...g.vlm,model_list:Dt(g.vlm?.model_list||[])},voice:{...g.voice,model_list:Dt(g.voice?.model_list||[])},embedding:{...g.embedding,model_list:Dt(g.embedding?.model_list||[])},lpmm_entity_extract:{...g.lpmm_entity_extract,model_list:Dt(g.lpmm_entity_extract?.model_list||[])},lpmm_rdf_build:{...g.lpmm_rdf_build,model_list:Dt(g.lpmm_rdf_build?.model_list||[])},lpmm_qa:{...g.lpmm_qa,model_list:Dt(g.lpmm_qa?.model_list||[])}})}T(!1),te(null),je(null)},_s=_=>{if(!_&&A){const G={...A,price_in:A.price_in??0,price_out:A.price_out??0};te(G)}T(_)},Ae=_=>{be(_),he(!0)},vs=()=>{if(ve!==null){const _=n.filter((G,we)=>we!==ve);r(_),p(_.map(G=>G.name)),Le({title:"删除成功",description:"模型已从列表中移除"})}he(!1),be(null)},bs=_=>{const G=new Set(q);G.has(_)?G.delete(_):G.add(_),se(G)},Nt=()=>{if(q.size===Js.length)se(new Set);else{const _=Js.map((G,we)=>n.findIndex(Ms=>Ms===Js[we]));se(new Set(_))}},Xs=()=>{if(q.size===0){Le({title:"提示",description:"请先选择要删除的模型",variant:"default"});return}ue(!0)},Ss=()=>{const _=n.filter((G,we)=>!q.has(we));r(_),p(_.map(G=>G.name)),se(new Set),ue(!1),Le({title:"批量删除成功",description:`已删除 ${q.size} 个模型`})},Es=(_,G,we)=>{g&&b({...g,[_]:{...g[_],[G]:we}})},Js=n.filter(_=>{if(!D)return!0;const G=D.toLowerCase();return _.name.toLowerCase().includes(G)||_.model_identifier.toLowerCase().includes(G)||_.api_provider.toLowerCase().includes(G)}),Ha=Math.ceil(Js.length/Ce),Lt=Js.slice((me-1)*Ce,me*Ce),ol=()=>{const _=parseInt(ge);_>=1&&_<=Ha&&(_e(_),ae(""))},ba=_=>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(we=>we.includes(_)):!1;return j?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(S,{onClick:Je,disabled:N||w||!O||Y,size:"sm",variant:"outline",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(fi,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),N?"保存中...":w?"自动保存中...":O?"保存配置":"已保存"]}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsxs(S,{disabled:N||w||Y,size:"sm",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(hi,{className:"mr-2 h-4 w-4"}),Y?"重启中...":O?"保存并重启":"重启麦麦"]})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认重启麦麦?"}),e.jsx(cs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:O?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:O?De:X,children:O?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(It,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsxs(Yt,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),e.jsxs(It,{className:"hidden lg:flex border-primary/30 bg-primary/5 cursor-pointer hover:bg-primary/10 transition-colors",onClick:E,children:[e.jsx(iy,{className:"h-4 w-4 text-primary"}),e.jsxs(Yt,{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[e.jsx("strong",{className:"text-primary",children:"新手引导:"}),"不知道如何配置模型?点击这里开始学习如何为麦麦的组件分配模型。"]}),e.jsx(S,{variant:"outline",size:"sm",className:"ml-4 shrink-0",children:"开始引导"})]})]}),e.jsxs(ga,{defaultValue:"models",className:"w-full",children:[e.jsxs(la,{className:"grid w-full max-w-full sm:max-w-md grid-cols-2",children:[e.jsx(ss,{value:"models",children:"添加模型"}),e.jsx(ss,{value:"tasks","data-tour":"tasks-tab-trigger",children:"为模型分配功能"})]}),e.jsxs(Ts,{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:[q.size>0&&e.jsxs(S,{onClick:Xs,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(We,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",q.size,")"]}),e.jsxs(S,{onClick:()=>Ks(null,null),size:"sm",variant:"outline",className:"w-full sm:w-auto","data-tour":"add-model-button",children:[e.jsx(dt,{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(Mt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"搜索模型名称、标识符或提供商...",value:D,onChange:_=>J(_.target.value),className:"pl-9"})]}),D&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",Js.length," 个结果"]})]}),e.jsx(s1,{paginatedModels:Lt,allModels:n,onEdit:Ks,onDelete:Ae,isModelUsed:ba,searchQuery:D}),e.jsx(t1,{paginatedModels:Lt,allModels:n,filteredModels:Js,selectedModels:q,onEdit:Ks,onDelete:Ae,onToggleSelection:bs,onToggleSelectAll:Nt,isModelUsed:ba,searchQuery:D}),e.jsx(n1,{page:me,pageSize:Ce,totalItems:Js.length,jumpToPage:ge,onPageChange:_e,onPageSizeChange:ze,onJumpToPageChange:ae,onJumpToPage:ol,onSelectionClear:()=>se(new Set)})]}),e.jsxs(Ts,{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(_a,{title:"组件模型 (utils)",description:"用于表情包、取名、关系、情绪变化等组件",taskConfig:g.utils,modelNames:f,onChange:(_,G)=>Es("utils",_,G),dataTour:"task-model-select"}),e.jsx(_a,{title:"组件小模型 (utils_small)",description:"消耗量较大的组件,建议使用速度较快的小模型",taskConfig:g.utils_small,modelNames:f,onChange:(_,G)=>Es("utils_small",_,G)}),e.jsx(_a,{title:"工具调用模型 (tool_use)",description:"需要使用支持工具调用的模型",taskConfig:g.tool_use,modelNames:f,onChange:(_,G)=>Es("tool_use",_,G)}),e.jsx(_a,{title:"首要回复模型 (replyer)",description:"用于表达器和表达方式学习",taskConfig:g.replyer,modelNames:f,onChange:(_,G)=>Es("replyer",_,G)}),e.jsx(_a,{title:"决策模型 (planner)",description:"负责决定麦麦该什么时候回复",taskConfig:g.planner,modelNames:f,onChange:(_,G)=>Es("planner",_,G)}),e.jsx(_a,{title:"图像识别模型 (vlm)",description:"视觉语言模型",taskConfig:g.vlm,modelNames:f,onChange:(_,G)=>Es("vlm",_,G),hideTemperature:!0}),e.jsx(_a,{title:"语音识别模型 (voice)",description:"语音转文字",taskConfig:g.voice,modelNames:f,onChange:(_,G)=>Es("voice",_,G),hideTemperature:!0,hideMaxTokens:!0}),e.jsx(_a,{title:"嵌入模型 (embedding)",description:"用于向量化",taskConfig:g.embedding,modelNames:f,onChange:(_,G)=>Es("embedding",_,G),hideTemperature:!0,hideMaxTokens:!0}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库模型"}),e.jsx(_a,{title:"实体提取模型 (lpmm_entity_extract)",description:"从文本中提取实体",taskConfig:g.lpmm_entity_extract,modelNames:f,onChange:(_,G)=>Es("lpmm_entity_extract",_,G)}),e.jsx(_a,{title:"RDF 构建模型 (lpmm_rdf_build)",description:"构建知识图谱",taskConfig:g.lpmm_rdf_build,modelNames:f,onChange:(_,G)=>Es("lpmm_rdf_build",_,G)}),e.jsx(_a,{title:"问答模型 (lpmm_qa)",description:"知识库问答",taskConfig:g.lpmm_qa,modelNames:f,onChange:(_,G)=>Es("lpmm_qa",_,G)})]})]})]})]}),e.jsx(qs,{open:I,onOpenChange:_s,children:e.jsxs(Ls,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"model-dialog",preventOutsideClose:xe,children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:fe!==null?"编辑模型":"添加模型"}),e.jsx(Ps,{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(C,{htmlFor:"model_name",className:P.name?"text-destructive":"",children:"模型名称 *"}),e.jsx(ie,{id:"model_name",value:A?.name||"",onChange:_=>{te(G=>G?{...G,name:_.target.value}:null),P.name&&Te(G=>({...G,name:void 0}))},placeholder:"例如: qwen3-30b",className:P.name?"border-destructive focus-visible:ring-destructive":""}),P.name?e.jsx("p",{className:"text-xs text-destructive",children:P.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(C,{htmlFor:"api_provider",className:P.api_provider?"text-destructive":"",children:"API 提供商 *"}),e.jsxs(Ue,{value:A?.api_provider||"",onValueChange:_=>{te(G=>G?{...G,api_provider:_}:null),Vs(),P.api_provider&&Te(G=>({...G,api_provider:void 0}))},children:[e.jsx(Oe,{id:"api_provider",className:P.api_provider?"border-destructive focus-visible:ring-destructive":"",children:e.jsx(Be,{placeholder:"选择提供商"})}),e.jsx(Re,{children:i.map(_=>e.jsx(le,{value:_,children:_},_))})]}),P.api_provider&&e.jsx("p",{className:"text-xs text-destructive",children:P.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(C,{htmlFor:"model_identifier",className:P.model_identifier?"text-destructive":"",children:"模型标识符 *"}),xt?.modelFetcher&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qe,{variant:"secondary",className:"text-xs",children:xt.display_name}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-6 px-2",onClick:()=>A?.api_provider&&js(A.api_provider,!0),disabled:Fs,children:Fs?e.jsx(it,{className:"h-3 w-3 animate-spin"}):e.jsx(zt,{className:"h-3 w-3"})})]})]}),xt?.modelFetcher?e.jsxs(La,{open:re,onOpenChange:F,children:[e.jsx(Ua,{asChild:!0,children:e.jsxs(S,{variant:"outline",role:"combobox","aria-expanded":re,className:"w-full justify-between font-normal",disabled:Fs||!!ks,children:[Fs?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(it,{className:"h-4 w-4 animate-spin"}),"正在获取模型列表..."]}):ks?e.jsx("span",{className:"text-muted-foreground text-sm",children:"点击下方输入框手动填写"}):A?.model_identifier?e.jsx("span",{className:"truncate",children:A.model_identifier}):e.jsx("span",{className:"text-muted-foreground",children:"搜索或选择模型..."}),e.jsx(Iu,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(ka,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(eo,{children:[e.jsx(so,{placeholder:"搜索模型..."}),e.jsx(Ze,{className:"h-[300px]",children:e.jsxs(to,{className:"max-h-none overflow-visible",children:[e.jsx(ao,{children:ks?e.jsxs("div",{className:"py-4 px-2 text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:ks}),!ks.includes("API Key")&&e.jsx(S,{variant:"link",size:"sm",onClick:()=>A?.api_provider&&js(A.api_provider,!0),children:"重试"})]}):"未找到匹配的模型"}),e.jsx(mi,{heading:"可用模型",children:qe.map(_=>e.jsxs(xi,{value:_.id,onSelect:()=>{te(G=>G?{...G,model_identifier:_.id}:null),F(!1)},children:[e.jsx(Qt,{className:`mr-2 h-4 w-4 ${A?.model_identifier===_.id?"opacity-100":"opacity-0"}`}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:_.id}),_.name!==_.id&&e.jsx("span",{className:"text-xs text-muted-foreground",children:_.name})]})]},_.id))}),e.jsx(mi,{heading:"手动输入",children:e.jsxs(xi,{value:"__manual_input__",onSelect:()=>{F(!1)},children:[e.jsx(ln,{className:"mr-2 h-4 w-4"}),"手动输入模型标识符..."]})})]})})]})})]}):e.jsx(ie,{id:"model_identifier",value:A?.model_identifier||"",onChange:_=>{te(G=>G?{...G,model_identifier:_.target.value}:null),P.model_identifier&&Te(G=>({...G,model_identifier:void 0}))},placeholder:"Qwen/Qwen3-30B-A3B-Instruct-2507",className:P.model_identifier?"border-destructive focus-visible:ring-destructive":""}),P.model_identifier&&e.jsx("p",{className:"text-xs text-destructive",children:P.model_identifier}),ks&&xt?.modelFetcher&&!P.model_identifier&&e.jsxs(It,{variant:"destructive",className:"mt-2 py-2",children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsx(Yt,{className:"text-xs",children:ks})]}),xt?.modelFetcher&&e.jsx(ie,{value:A?.model_identifier||"",onChange:_=>{te(G=>G?{...G,model_identifier:_.target.value}:null),P.model_identifier&&Te(G=>({...G,model_identifier:void 0}))},placeholder:"或手动输入模型标识符",className:`mt-2 ${P.model_identifier?"border-destructive focus-visible:ring-destructive":""}`}),!P.model_identifier&&e.jsx("p",{className:"text-xs text-muted-foreground",children:ks?'请手动输入模型标识符,或前往"模型提供商配置"检查 API Key':xt?.modelFetcher?`已识别为 ${xt.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(C,{htmlFor:"price_in",children:"输入价格 (¥/M token)"}),e.jsx(ie,{id:"price_in",type:"number",step:"0.1",min:"0",value:A?.price_in??"",onChange:_=>{const G=_.target.value===""?null:parseFloat(_.target.value);te(we=>we?{...we,price_in:G}:null)},placeholder:"默认: 0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"price_out",children:"输出价格 (¥/M token)"}),e.jsx(ie,{id:"price_out",type:"number",step:"0.1",min:"0",value:A?.price_out??"",onChange:_=>{const G=_.target.value===""?null:parseFloat(_.target.value);te(we=>we?{...we,price_out:G}: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(C,{htmlFor:"enable_model_temperature",className:"cursor-pointer",children:"自定义模型温度"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务温度配置"})]}),e.jsx($e,{id:"enable_model_temperature",checked:A?.temperature!=null,onCheckedChange:_=>{te(_?G=>G?{...G,temperature:.5}:null:G=>G?{...G,temperature:null}:null)}})]}),A?.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(C,{className:"text-sm",children:"温度值"}),e.jsx("span",{className:"text-sm font-medium tabular-nums",children:A.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(pa,{value:[A.temperature],onValueChange:_=>te(G=>G?{...G,temperature:_[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(C,{htmlFor:"enable_model_max_tokens",className:"cursor-pointer",children:"自定义最大 Token"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务最大 Token 配置"})]}),e.jsx($e,{id:"enable_model_max_tokens",checked:A?.max_tokens!=null,onCheckedChange:_=>{te(_?G=>G?{...G,max_tokens:2048}:null:G=>G?{...G,max_tokens:null}:null)}})]}),A?.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(C,{className:"text-sm",children:"最大 Token 数"}),e.jsx(ie,{type:"number",min:"1",max:"128000",value:A.max_tokens,onChange:_=>{const G=parseInt(_.target.value);!isNaN(G)&&G>=1&&te(we=>we?{...we,max_tokens:G}: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($e,{id:"force_stream_mode",checked:A?.force_stream_mode||!1,onCheckedChange:_=>te(G=>G?{...G,force_stream_mode:_}:null)}),e.jsx(C,{htmlFor:"force_stream_mode",className:"cursor-pointer",children:"强制流式输出模式"})]}),e.jsx(Pw,{value:A?.extra_params||{},onChange:_=>te(G=>G?{...G,extra_params:_}:null),placeholder:"添加额外参数(如 enable_thinking、top_p 等)..."})]}),e.jsxs(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>T(!1),"data-tour":"model-cancel-button",children:"取消"}),e.jsx(S,{onClick:ye,"data-tour":"model-save-button",children:"保存"})]})]})}),e.jsx(hs,{open:pe,onOpenChange:he,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:['确定要删除模型 "',ve!==null?n[ve]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:vs,children:"删除"})]})]})}),e.jsx(hs,{open:R,onOpenChange:ue,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认批量删除"}),e.jsxs(cs,{children:["确定要删除选中的 ",q.size," 个模型吗? 此操作无法撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:Ss,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),z&&e.jsx(Zu,{onRestartComplete:Ke,onRestartFailed:Ns})]})})}const lo="/api/webui/config";async function d1(){const r=await(await Se(`${lo}/adapter-config/path`)).json();return!r.success||!r.path?null:{path:r.path,lastModified:r.lastModified}}async function pp(n){const i=await(await Se(`${lo}/adapter-config/path`,{method:"POST",headers:Gs(),body:JSON.stringify({path:n})})).json();if(!i.success)throw new Error(i.message||"保存路径失败")}async function gp(n){const i=await(await Se(`${lo}/adapter-config?path=${encodeURIComponent(n)}`)).json();if(!i.success)throw new Error("读取配置文件失败");return i.content}async function jp(n,r){const d=await(await Se(`${lo}/adapter-config`,{method:"POST",headers:Gs(),body:JSON.stringify({path:n,content:r})})).json();if(!d.success)throw new Error(d.message||"保存配置失败")}const ta={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"}},Au={oneclick:{name:"一键包",description:"使用一键包部署的适配器配置",path:"../MaiBot-Napcat-Adapter/config.toml",icon:Ol},docker:{name:"Docker",description:"Docker Compose 部署的适配器配置",path:"/MaiMBot/adapters-config/config.toml",icon:cy}};function u1(){const[n,r]=u.useState("upload"),[i,d]=u.useState(null),[m,x]=u.useState(""),[f,p]=u.useState(""),[g,b]=u.useState("oneclick"),[j,y]=u.useState(""),[N,k]=u.useState(!1),[w,U]=u.useState(!1),[O,B]=u.useState(!1),[Y,L]=u.useState(!1),[z,K]=u.useState(null),I=u.useRef(null),{toast:T}=$s(),A=u.useRef(null),te=ae=>{if(!ae.trim())return{valid:!1,error:"路径不能为空"};if(!ae.toLowerCase().endsWith(".toml"))return{valid:!1,error:"文件必须是 .toml 格式"};const re=/^([a-zA-Z]:\\|\\\\[^\\]+\\[^\\]+\\).+\.toml$/i,F=/^(\/|~\/).+\.toml$/i,P=/^(\.{1,2}[\\/]|[^:\\/]).+\.toml$/i,Te=re.test(ae),Le=F.test(ae),E=P.test(ae);return!Te&&!Le&&!E?{valid:!1,error:"路径格式错误"}:/[<>"|?*\x00-\x1F]/.test(ae)?{valid:!1,error:"路径包含非法字符"}:{valid:!0,error:""}},fe=ae=>{if(p(ae),ae.trim()){const re=te(ae);y(re.error)}else y("")},je=u.useCallback(async ae=>{const re=Au[ae];U(!0);try{const F=await gp(re.path),P=me(F);d(P),b(ae),p(re.path),await pp(re.path),T({title:"加载成功",description:`已从${re.name}预设加载配置`})}catch(F){console.error("加载预设配置失败:",F),T({title:"加载失败",description:F instanceof Error?F.message:"无法读取预设配置文件",variant:"destructive"})}finally{U(!1)}},[T]),pe=u.useCallback(async ae=>{const re=te(ae);if(!re.valid){y(re.error),T({title:"路径无效",description:re.error,variant:"destructive"});return}y(""),U(!0);try{const F=await gp(ae),P=me(F);d(P),p(ae),await pp(ae),T({title:"加载成功",description:"已从配置文件加载"})}catch(F){console.error("加载配置失败:",F),T({title:"加载失败",description:F instanceof Error?F.message:"无法读取配置文件",variant:"destructive"})}finally{U(!1)}},[T]);u.useEffect(()=>{(async()=>{try{const re=await d1();if(re&&re.path){p(re.path);const F=Object.entries(Au).find(([,P])=>P.path===re.path);F?(r("preset"),b(F[0]),await je(F[0])):(r("path"),await pe(re.path))}}catch(re){console.error("加载保存的路径失败:",re)}})()},[pe,je]);const he=u.useCallback(ae=>{n!=="path"&&n!=="preset"||!f||(A.current&&clearTimeout(A.current),A.current=setTimeout(async()=>{k(!0);try{const re=_e(ae);await jp(f,re),T({title:"自动保存成功",description:"配置已保存到文件"})}catch(re){console.error("自动保存失败:",re),T({title:"自动保存失败",description:re instanceof Error?re.message:"保存配置失败",variant:"destructive"})}finally{k(!1)}},1e3))},[n,f,T]),ve=async()=>{if(!i||!f)return;const ae=te(f);if(!ae.valid){T({title:"保存失败",description:ae.error,variant:"destructive"});return}k(!0);try{const re=_e(i);await jp(f,re),T({title:"保存成功",description:"配置已保存到文件"})}catch(re){console.error("保存失败:",re),T({title:"保存失败",description:re instanceof Error?re.message:"保存配置失败",variant:"destructive"})}finally{k(!1)}},be=async()=>{f&&await pe(f)},D=ae=>{if(ae!==n){if(i){K(ae),B(!0);return}J(ae)}},J=ae=>{d(null),x(""),y(""),r(ae),ae==="preset"&&je("oneclick"),T({title:"已切换模式",description:{upload:"现在可以上传配置文件",path:"现在可以指定配置文件路径",preset:"现在可以使用预设配置"}[ae]})},q=()=>{z&&(J(z),K(null)),B(!1)},se=()=>{if(i){L(!0);return}R()},R=()=>{p(""),d(null),y(""),T({title:"已清空",description:"路径和配置已清空"})},ue=()=>{R(),L(!1)},me=ae=>{const re=JSON.parse(JSON.stringify(ta)),F=ae.split(` `);let P="";for(const Te of F){const Le=Te.trim();if(!Le||Le.startsWith("#"))continue;const E=Le.match(/^\[(\w+)\]/);if(E){P=E[1];continue}const xe=Le.match(/^(\w+)\s*=\s*(.+)$/);if(xe&&P){const[,Ye,ke]=xe;let Q=ke.trim();const Ne=Q.match(/^("[^"]*")/);if(Ne)Q=Ne[1];else{const Fs=Q.indexOf("#");Fs!==-1&&(Q=Q.substring(0,Fs).trim())}let qe;if(Q==="true")qe=!0;else if(Q==="false")qe=!1;else if(Q.startsWith("[")&&Q.endsWith("]")){const Fs=Q.slice(1,-1).trim();if(Fs){const ks=Fs.split(",").map(js=>{const Vs=js.trim();return isNaN(Number(Vs))?Vs.replace(/"/g,""):Number(Vs)}),xt=typeof ks[0];qe=ks.every(js=>typeof js===xt)?ks:ks.filter(js=>typeof js=="number")}else qe=[]}else Q.startsWith('"')&&Q.endsWith('"')?qe=Q.slice(1,-1):isNaN(Number(Q))?qe=Q.replace(/"/g,""):qe=Number(Q);if(P in re){const Fs=re[P];Fs[Ye]=qe}}}return re},_e=ae=>{const re=[],F=(P,Te)=>P===""||P===null||P===void 0?Te:P;return re.push("[inner]"),re.push(`version = "${F(ae.inner.version,ta.inner.version)}" # 版本号`),re.push("# 请勿修改版本号,除非你知道自己在做什么"),re.push(""),re.push("[nickname] # 现在没用"),re.push(`nickname = "${F(ae.nickname.nickname,ta.nickname.nickname)}"`),re.push(""),re.push("[napcat_server] # Napcat连接的ws服务设置"),re.push(`host = "${F(ae.napcat_server.host,ta.napcat_server.host)}" # Napcat设定的主机地址`),re.push(`port = ${F(ae.napcat_server.port||0,ta.napcat_server.port)} # Napcat设定的端口`),re.push(`token = "${F(ae.napcat_server.token,ta.napcat_server.token)}" # Napcat设定的访问令牌,若无则留空`),re.push(`heartbeat_interval = ${F(ae.napcat_server.heartbeat_interval||0,ta.napcat_server.heartbeat_interval)} # 与Napcat设置的心跳相同(按秒计)`),re.push(""),re.push("[maibot_server] # 连接麦麦的ws服务设置"),re.push(`host = "${F(ae.maibot_server.host,ta.maibot_server.host)}" # 麦麦在.env文件中设置的主机地址,即HOST字段`),re.push(`port = ${F(ae.maibot_server.port||0,ta.maibot_server.port)} # 麦麦在.env文件中设置的端口,即PORT字段`),re.push(""),re.push("[chat] # 黑白名单功能"),re.push(`group_list_type = "${F(ae.chat.group_list_type,ta.chat.group_list_type)}" # 群组名单类型,可选为:whitelist, blacklist`),re.push(`group_list = [${ae.chat.group_list.join(", ")}] # 群组名单`),re.push("# 当group_list_type为whitelist时,只有群组名单中的群组可以聊天"),re.push("# 当group_list_type为blacklist时,群组名单中的任何群组无法聊天"),re.push(`private_list_type = "${F(ae.chat.private_list_type,ta.chat.private_list_type)}" # 私聊名单类型,可选为:whitelist, blacklist`),re.push(`private_list = [${ae.chat.private_list.join(", ")}] # 私聊名单`),re.push("# 当private_list_type为whitelist时,只有私聊名单中的用户可以聊天"),re.push("# 当private_list_type为blacklist时,私聊名单中的任何用户无法聊天"),re.push(`ban_user_id = [${ae.chat.ban_user_id.join(", ")}] # 全局禁止名单(全局禁止名单中的用户无法进行任何聊天)`),re.push(`ban_qq_bot = ${ae.chat.ban_qq_bot} # 是否屏蔽QQ官方机器人`),re.push(`enable_poke = ${ae.chat.enable_poke} # 是否启用戳一戳功能`),re.push(""),re.push("[voice] # 发送语音设置"),re.push(`use_tts = ${ae.voice.use_tts} # 是否使用tts语音(请确保你配置了tts并有对应的adapter)`),re.push(""),re.push("[debug]"),re.push(`level = "${F(ae.debug.level,ta.debug.level)}" # 日志等级(DEBUG, INFO, WARNING, ERROR, CRITICAL)`),re.join(` `)},Ce=ae=>{const re=ae.target.files?.[0];if(!re)return;const F=new FileReader;F.onload=P=>{try{const Te=P.target?.result,Le=me(Te);d(Le),x(re.name),T({title:"上传成功",description:`已加载配置文件:${re.name}`})}catch(Te){console.error("解析配置文件失败:",Te),T({title:"解析失败",description:"配置文件格式错误,请检查文件内容",variant:"destructive"})}},F.readAsText(re)},ze=()=>{if(!i)return;const ae=_e(i),re=new Blob([ae],{type:"text/plain;charset=utf-8"}),F=URL.createObjectURL(re),P=document.createElement("a");P.href=F,P.download=m||"config.toml",document.body.appendChild(P),P.click(),document.body.removeChild(P),URL.revokeObjectURL(F),T({title:"下载成功",description:"配置文件已下载,请手动覆盖并重启适配器"})},ge=()=>{d(JSON.parse(JSON.stringify(ta))),x("config.toml"),T({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(At,{className:"h-4 w-4 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm",children:"适配器配置保存之后使用 WebUI 的重启功能适配器并不会重启,需要手动重启适配器。"})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{children:[e.jsx(as,{children:"工作模式"}),e.jsx(et,{children:"选择配置文件的管理方式"})]}),e.jsxs(xs,{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 ${n==="preset"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>D("preset"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(Ol,{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 ${n==="upload"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>D("upload"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(oi,{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 ${n==="path"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>D("path"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(oy,{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:"指定配置文件路径,自动加载和保存"})]})]})})]}),n==="preset"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsx(C,{className:"text-sm md:text-base",children:"选择部署方式"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(Au).map(([ae,re])=>{const F=re.icon,P=g===ae;return e.jsx("div",{className:`border-2 rounded-lg p-3 cursor-pointer transition-all ${P?"border-primary bg-primary/5":"border-muted hover:border-primary/50"}`,onClick:()=>{b(ae),je(ae)},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(F,{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:re.name}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:re.description}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-mono break-all",children:re.path})]})]})},ae)})})]}),n==="path"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{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:f,onChange:ae=>fe(ae.target.value),placeholder:"例: C:\\Adapter\\config.toml",className:`text-sm ${j?"border-destructive":""}`}),j&&e.jsx("p",{className:"text-xs text-destructive",children:j})]}),e.jsx(S,{onClick:()=>pe(f),disabled:w||!f||!!j,className:"w-full sm:w-auto",children:w?e.jsxs(e.Fragment,{children:[e.jsx(zt,{className:"h-4 w-4 animate-spin mr-2"}),e.jsx("span",{className:"sm:hidden",children:"加载中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sm:hidden",children:"加载配置"}),e.jsx("span",{className:"hidden sm:inline",children:"加载"})]})})]})]}),e.jsxs("details",{className:"rounded-lg bg-muted/50 p-3 group",children:[e.jsxs("summary",{className:"text-xs font-medium cursor-pointer select-none list-none flex items-center justify-between",children:[e.jsx("span",{children:"路径格式说明"}),e.jsx("svg",{className:"h-4 w-4 transition-transform group-open:rotate-180",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),e.jsxs("div",{className:"mt-2 space-y-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"font-mono bg-background px-1.5 py-0.5 rounded text-[10px] md:text-xs whitespace-nowrap",children:"Windows"})}),e.jsxs("div",{className:"pl-2 space-y-0.5 text-[10px] md:text-xs break-all",children:[e.jsx("div",{children:"C:\\Adapter\\config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"D:\\MaiBot\\adapter\\config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"\\\\server\\share\\config.toml"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"font-mono bg-background px-1.5 py-0.5 rounded text-[10px] md:text-xs whitespace-nowrap",children:"Linux"})}),e.jsxs("div",{className:"pl-2 space-y-0.5 text-[10px] md:text-xs break-all",children:[e.jsx("div",{children:"/opt/adapter/config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"/home/user/adapter/config.toml"}),e.jsx("div",{className:"hidden sm:block",children:"~/adapter/config.toml"})]})]}),e.jsx("p",{className:"pt-1 border-t text-[10px] md:text-xs",children:"💡 配置会自动保存到指定文件,修改后 1 秒自动保存"})]})]})]})]})]}),e.jsxs(It,{children:[e.jsx(Ra,{className:"h-4 w-4"}),e.jsx(Yt,{children:n==="preset"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"预设模式:"}),"选择预设的部署方式,配置会自动加载,修改后 1 秒自动保存",N&&" (正在保存...)"]}):n==="upload"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"上传文件模式:"}),"上传配置文件 → 在线编辑 → 下载文件 → 手动覆盖并重启适配器"]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"指定路径模式:"}),"指定配置文件路径后,配置会自动加载,修改后 1 秒自动保存",N&&" (正在保存...)"]})})]}),n==="upload"&&!i&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 w-full",children:[e.jsx("input",{ref:I,type:"file",accept:".toml",className:"hidden",onChange:Ce}),e.jsxs(S,{onClick:()=>I.current?.click(),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(oi,{className:"mr-2 h-4 w-4"}),"上传配置"]}),e.jsxs(S,{onClick:ge,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Sa,{className:"mr-2 h-4 w-4"}),"使用默认配置"]})]}),n==="upload"&&i&&e.jsx("div",{className:"flex gap-2",children:e.jsxs(S,{onClick:ze,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Oa,{className:"mr-2 h-4 w-4"}),"下载配置"]})}),(n==="preset"||n==="path")&&i&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs(S,{onClick:ve,size:"sm",disabled:N||!!j,className:"w-full sm:w-auto",children:[e.jsx(fi,{className:"mr-2 h-4 w-4"}),N?"保存中...":"立即保存"]}),e.jsxs(S,{onClick:be,size:"sm",variant:"outline",disabled:w,className:"w-full sm:w-auto",children:[e.jsx(zt,{className:`mr-2 h-4 w-4 ${w?"animate-spin":""}`}),"刷新"]}),n==="path"&&e.jsxs(S,{onClick:se,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(We,{className:"mr-2 h-4 w-4"}),"清空路径"]})]}),i?e.jsxs(ga,{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(la,{className:"inline-flex w-auto min-w-full sm:grid sm:w-full sm:grid-cols-5",children:[e.jsxs(ss,{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(ss,{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(ss,{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(ss,{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(ss,{value:"debug",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:"调试"})]})}),e.jsx(Ts,{value:"napcat",className:"space-y-4",children:e.jsx(m1,{config:i,onChange:ae=>{d(ae),he(ae)}})}),e.jsx(Ts,{value:"maibot",className:"space-y-4",children:e.jsx(x1,{config:i,onChange:ae=>{d(ae),he(ae)}})}),e.jsx(Ts,{value:"chat",className:"space-y-4",children:e.jsx(h1,{config:i,onChange:ae=>{d(ae),he(ae)}})}),e.jsx(Ts,{value:"voice",className:"space-y-4",children:e.jsx(f1,{config:i,onChange:ae=>{d(ae),he(ae)}})}),e.jsx(Ts,{value:"debug",className:"space-y-4",children:e.jsx(p1,{config:i,onChange:ae=>{d(ae),he(ae)}})})]}):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(Sa,{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:n==="preset"?"请选择预设的部署方式":n==="upload"?"请上传现有配置文件,或使用默认配置开始编辑":"请指定配置文件路径并点击加载按钮"})]})]})}),e.jsx(hs,{open:O,onOpenChange:B,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认切换模式"}),e.jsxs(cs,{children:["切换模式将清空当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-destructive font-medium",children:"请确保已保存重要配置"})]})]}),e.jsxs(rs,{children:[e.jsx(ds,{onClick:()=>{B(!1),K(null)},children:"取消"}),e.jsx(os,{onClick:q,children:"确认切换"})]})]})}),e.jsx(hs,{open:Y,onOpenChange:L,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认清空路径"}),e.jsxs(cs,{children:["清空路径将清除当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-muted-foreground text-sm",children:"此操作不会删除配置文件,只是清除界面中的配置"})]})]}),e.jsxs(rs,{children:[e.jsx(ds,{onClick:()=>L(!1),children:"取消"}),e.jsx(os,{onClick:ue,className:"bg-destructive hover:bg-destructive/90",children:"确认清空"})]})]})})]})})}function m1({config:n,onChange:r}){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(C,{htmlFor:"napcat-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(ie,{id:"napcat-host",value:n.napcat_server.host,onChange:i=>r({...n,napcat_server:{...n.napcat_server,host:i.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的主机地址"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"napcat-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(ie,{id:"napcat-port",type:"number",value:n.napcat_server.port||"",onChange:i=>r({...n,napcat_server:{...n.napcat_server,port:i.target.value?parseInt(i.target.value):0}}),placeholder:"8095",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的端口(留空使用默认值 8095)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"napcat-token",className:"text-sm md:text-base",children:"访问令牌(Token)"}),e.jsx(ie,{id:"napcat-token",type:"password",value:n.napcat_server.token,onChange:i=>r({...n,napcat_server:{...n.napcat_server,token:i.target.value}}),placeholder:"留空表示无需令牌",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的访问令牌,若无则留空"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"napcat-heartbeat",className:"text-sm md:text-base",children:"心跳间隔(秒)"}),e.jsx(ie,{id:"napcat-heartbeat",type:"number",value:n.napcat_server.heartbeat_interval||"",onChange:i=>r({...n,napcat_server:{...n.napcat_server,heartbeat_interval:i.target.value?parseInt(i.target.value):0}}),placeholder:"30",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"与 Napcat 设置的心跳间隔保持一致(留空使用默认值 30)"})]})]})]})})}function x1({config:n,onChange:r}){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(C,{htmlFor:"maibot-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(ie,{id:"maibot-host",value:n.maibot_server.host,onChange:i=>r({...n,maibot_server:{...n.maibot_server,host:i.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 HOST 字段"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(C,{htmlFor:"maibot-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(ie,{id:"maibot-port",type:"number",value:n.maibot_server.port||"",onChange:i=>r({...n,maibot_server:{...n.maibot_server,port:i.target.value?parseInt(i.target.value):0}}),placeholder:"8000",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 PORT 字段(留空使用默认值 8000)"})]})]})]})})}function h1({config:n,onChange:r}){const i=x=>{const f={...n};x==="group"?f.chat.group_list=[...f.chat.group_list,0]:x==="private"?f.chat.private_list=[...f.chat.private_list,0]:f.chat.ban_user_id=[...f.chat.ban_user_id,0],r(f)},d=(x,f)=>{const p={...n};x==="group"?p.chat.group_list=p.chat.group_list.filter((g,b)=>b!==f):x==="private"?p.chat.private_list=p.chat.private_list.filter((g,b)=>b!==f):p.chat.ban_user_id=p.chat.ban_user_id.filter((g,b)=>b!==f),r(p)},m=(x,f,p)=>{const g={...n};x==="group"?g.chat.group_list[f]=p:x==="private"?g.chat.private_list[f]=p:g.chat.ban_user_id[f]=p,r(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(C,{className:"text-sm md:text-base",children:"群组名单类型"}),e.jsxs(Ue,{value:n.chat.group_list_type,onValueChange:x=>r({...n,chat:{...n.chat,group_list_type:x}}),children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(le,{value:"blacklist",children:"黑名单(名单内禁止聊天)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-0",children:[e.jsx(C,{className:"text-sm md:text-base",children:"群组列表"}),e.jsxs(S,{onClick:()=>i("group"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Sa,{className:"mr-1 h-4 w-4"}),"添加群号"]})]}),n.chat.group_list.map((x,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{type:"number",value:x,onChange:p=>m("group",f,parseInt(p.target.value)||0),placeholder:"输入群号",className:"text-sm md:text-base"}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{size:"icon",variant:"outline",children:e.jsx(We,{className:"h-4 w-4"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:["确定要删除群号 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>d("group",f),children:"删除"})]})]})]})]},f)),n.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(C,{className:"text-sm md:text-base",children:"私聊名单类型"}),e.jsxs(Ue,{value:n.chat.private_list_type,onValueChange:x=>r({...n,chat:{...n.chat,private_list_type:x}}),children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(le,{value:"blacklist",children:"黑名单(名单内禁止聊天)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-0",children:[e.jsx(C,{className:"text-sm md:text-base",children:"私聊列表"}),e.jsxs(S,{onClick:()=>i("private"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Sa,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),n.chat.private_list.map((x,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{type:"number",value:x,onChange:p=>m("private",f,parseInt(p.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{size:"icon",variant:"outline",children:e.jsx(We,{className:"h-4 w-4"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:["确定要删除用户 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>d("private",f),children:"删除"})]})]})]})]},f)),n.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(C,{className:"text-sm md:text-base",children:"全局禁止名单"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"名单中的用户无法进行任何聊天"})]}),e.jsxs(S,{onClick:()=>i("ban"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Sa,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),n.chat.ban_user_id.map((x,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ie,{type:"number",value:x,onChange:p=>m("ban",f,parseInt(p.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(hs,{children:[e.jsx(rt,{asChild:!0,children:e.jsx(S,{size:"icon",variant:"outline",children:e.jsx(We,{className:"h-4 w-4"})})}),e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:["确定要从全局禁止名单中删除用户 ",x," 吗?此操作无法撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>d("ban",f),children:"删除"})]})]})]})]},f)),n.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(C,{className:"text-sm md:text-base",children:"屏蔽QQ官方机器人"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否屏蔽来自QQ官方机器人的消息"})]}),e.jsx($e,{checked:n.chat.ban_qq_bot,onCheckedChange:x=>r({...n,chat:{...n.chat,ban_qq_bot:x}})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(C,{className:"text-sm md:text-base",children:"启用戳一戳功能"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否响应戳一戳消息"})]}),e.jsx($e,{checked:n.chat.enable_poke,onCheckedChange:x=>r({...n,chat:{...n.chat,enable_poke:x}})})]})]})]})})}function f1({config:n,onChange:r}){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(C,{className:"text-sm md:text-base",children:"使用 TTS 语音"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"请确保已配置 TTS 并有对应的适配器"})]}),e.jsx($e,{checked:n.voice.use_tts,onCheckedChange:i=>r({...n,voice:{use_tts:i}})})]})]})})}function p1({config:n,onChange:r}){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(C,{className:"text-sm md:text-base",children:"日志等级"}),e.jsxs(Ue,{value:n.debug.level,onValueChange:i=>r({...n,debug:{level:i}}),children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"DEBUG",children:"DEBUG(调试)"}),e.jsx(le,{value:"INFO",children:"INFO(信息)"}),e.jsx(le,{value:"WARNING",children:"WARNING(警告)"}),e.jsx(le,{value:"ERROR",children:"ERROR(错误)"}),e.jsx(le,{value:"CRITICAL",children:"CRITICAL(严重)"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"设置适配器的日志输出等级"})]})})]})})}const g1=["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"],j1=/^(aria-|data-)/,Ig=n=>Object.fromEntries(Object.entries(n).filter(([r])=>j1.test(r)||g1.includes(r)));function v1(n,r){const i=Ig(n);return Object.keys(n).some(d=>!Object.hasOwn(i,d)&&n[d]!==r[d])}class b1 extends u.Component{container;plugin;componentDidMount(){this.installPlugin()}componentDidUpdate(r){if(r.uppy!==this.props.uppy)this.uninstallPlugin(r),this.installPlugin();else if(v1(this.props,r)){const{uppy:i,...d}={...this.props,target:this.container};this.plugin.setOptions(d)}}componentWillUnmount(){this.uninstallPlugin()}installPlugin(){const{uppy:r,...i}={id:"Dashboard",...this.props,inline:!0,target:this.container};r.use(Qy,i),this.plugin=r.getPlugin(i.id)}uninstallPlugin(r=this.props){const{uppy:i}=r;i.removePlugin(this.plugin)}render(){return u.createElement("div",{className:"uppy-Container",ref:r=>{this.container=r},...Ig(this.props)})}}function N1({src:n,alt:r="表情包",className:i,maxRetries:d=5,retryInterval:m=1500}){const[x,f]=u.useState("loading"),[p,g]=u.useState(0),[b,j]=u.useState(null),y=u.useCallback(async()=>{try{const N=await fetch(n,{credentials:"include"});if(N.status===202){f("generating"),p{g(U=>U+1)},m):f("error");return}if(!N.ok){f("error");return}const k=await N.blob(),w=URL.createObjectURL(k);j(w),f("loaded")}catch(N){console.error("加载缩略图失败:",N),f("error")}},[n,p,d,m]);return u.useEffect(()=>{f("loading"),g(0),j(null)},[n]),u.useEffect(()=>{y()},[y]),u.useEffect(()=>()=>{b&&URL.revokeObjectURL(b)},[b]),x==="loading"||x==="generating"?e.jsx(Cg,{className:$("w-full h-full",i)}):x==="error"||!b?e.jsx("div",{className:$("w-full h-full flex items-center justify-center bg-muted",i),children:e.jsx(gg,{className:"h-8 w-8 text-muted-foreground"})}):e.jsx("img",{src:b,alt:r,className:$("w-full h-full object-contain",i)})}function Yg({content:n,className:r=""}){return e.jsx("div",{className:`prose prose-sm dark:prose-invert max-w-none ${r}`,children:e.jsx(Yy,{remarkPlugins:[Xy,Jy],rehypePlugins:[Ky],components:{code({inline:i,className:d,children:m,...x}){return i?e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-sm font-mono",...x,children:m}):e.jsx("code",{className:`${d} block bg-muted p-4 rounded-lg overflow-x-auto`,...x,children:m})},table({children:i,...d}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{className:"border-collapse border border-border",...d,children:i})})},th({children:i,...d}){return e.jsx("th",{className:"border border-border bg-muted px-4 py-2 text-left font-semibold",...d,children:i})},td({children:i,...d}){return e.jsx("td",{className:"border border-border px-4 py-2",...d,children:i})},a({children:i,...d}){return e.jsx("a",{className:"text-primary hover:underline",target:"_blank",rel:"noopener noreferrer",...d,children:i})},blockquote({children:i,...d}){return e.jsx("blockquote",{className:"border-l-4 border-primary pl-4 italic text-muted-foreground",...d,children:i})},h1({children:i,...d}){return e.jsx("h1",{className:"text-3xl font-bold mt-6 mb-4",...d,children:i})},h2({children:i,...d}){return e.jsx("h2",{className:"text-2xl font-bold mt-5 mb-3",...d,children:i})},h3({children:i,...d}){return e.jsx("h3",{className:"text-xl font-bold mt-4 mb-2",...d,children:i})},h4({children:i,...d}){return e.jsx("h4",{className:"text-lg font-semibold mt-3 mb-2",...d,children:i})},ul({children:i,...d}){return e.jsx("ul",{className:"list-disc list-inside space-y-1 my-2",...d,children:i})},ol({children:i,...d}){return e.jsx("ol",{className:"list-decimal list-inside space-y-1 my-2",...d,children:i})},p({children:i,...d}){return e.jsx("p",{className:"my-2 leading-relaxed",...d,children:i})},hr({...i}){return e.jsx("hr",{className:"my-4 border-border",...i})}},children:n})})}function y1({children:n,className:r}){return e.jsx(Yg,{content:n,className:r})}const ja="/api/webui/emoji";async function w1(n){const r=new URLSearchParams;n.page&&r.append("page",n.page.toString()),n.page_size&&r.append("page_size",n.page_size.toString()),n.search&&r.append("search",n.search),n.is_registered!==void 0&&r.append("is_registered",n.is_registered.toString()),n.is_banned!==void 0&&r.append("is_banned",n.is_banned.toString()),n.format&&r.append("format",n.format),n.sort_by&&r.append("sort_by",n.sort_by),n.sort_order&&r.append("sort_order",n.sort_order);const i=await Se(`${ja}/list?${r}`,{});if(!i.ok)throw new Error(`获取表情包列表失败: ${i.statusText}`);return i.json()}async function _1(n){const r=await Se(`${ja}/${n}`,{});if(!r.ok)throw new Error(`获取表情包详情失败: ${r.statusText}`);return r.json()}async function S1(n,r){const i=await Se(`${ja}/${n}`,{method:"PATCH",body:JSON.stringify(r)});if(!i.ok)throw new Error(`更新表情包失败: ${i.statusText}`);return i.json()}async function C1(n){const r=await Se(`${ja}/${n}`,{method:"DELETE"});if(!r.ok)throw new Error(`删除表情包失败: ${r.statusText}`);return r.json()}async function k1(){const n=await Se(`${ja}/stats/summary`,{});if(!n.ok)throw new Error(`获取统计数据失败: ${n.statusText}`);return n.json()}async function T1(n){const r=await Se(`${ja}/${n}/register`,{method:"POST"});if(!r.ok)throw new Error(`注册表情包失败: ${r.statusText}`);return r.json()}async function E1(n){const r=await Se(`${ja}/${n}/ban`,{method:"POST"});if(!r.ok)throw new Error(`封禁表情包失败: ${r.statusText}`);return r.json()}function z1(n,r=!1){return r?`${ja}/${n}/thumbnail?original=true`:`${ja}/${n}/thumbnail`}function A1(n){return`${ja}/${n}/thumbnail?original=true`}async function M1(n){const r=await Se(`${ja}/batch/delete`,{method:"POST",body:JSON.stringify({emoji_ids:n})});if(!r.ok){const i=await r.json();throw new Error(i.detail||"批量删除失败")}return r.json()}function D1(){return`${ja}/upload`}function O1(){const[n,r]=u.useState([]),[i,d]=u.useState(null),[m,x]=u.useState(!1),[f,p]=u.useState(1),[g,b]=u.useState(0),[j,y]=u.useState(20),[N,k]=u.useState("all"),[w,U]=u.useState("all"),[O,B]=u.useState("all"),[Y,L]=u.useState("usage_count"),[z,K]=u.useState("desc"),[I,T]=u.useState(null),[A,te]=u.useState(!1),[fe,je]=u.useState(!1),[pe,he]=u.useState(!1),[ve,be]=u.useState(new Set),[D,J]=u.useState(!1),[q,se]=u.useState(""),[R,ue]=u.useState("medium"),[me,_e]=u.useState(!1),{toast:Ce}=$s(),ze=u.useCallback(async()=>{try{x(!0);const Q=await w1({page:f,page_size:j,is_registered:N==="all"?void 0:N==="registered",is_banned:w==="all"?void 0:w==="banned",format:O==="all"?void 0:O,sort_by:Y,sort_order:z});r(Q.data),b(Q.total)}catch(Q){const Ne=Q instanceof Error?Q.message:"加载表情包列表失败";Ce({title:"错误",description:Ne,variant:"destructive"})}finally{x(!1)}},[f,j,N,w,O,Y,z,Ce]),ge=async()=>{try{const Q=await k1();d(Q.data)}catch(Q){console.error("加载统计数据失败:",Q)}};u.useEffect(()=>{ze()},[ze]),u.useEffect(()=>{ge()},[]);const ae=async Q=>{try{const Ne=await _1(Q.id);T(Ne.data),te(!0)}catch(Ne){const qe=Ne instanceof Error?Ne.message:"加载详情失败";Ce({title:"错误",description:qe,variant:"destructive"})}},re=Q=>{T(Q),je(!0)},F=Q=>{T(Q),he(!0)},P=async()=>{if(I)try{await C1(I.id),Ce({title:"成功",description:"表情包已删除"}),he(!1),T(null),ze(),ge()}catch(Q){const Ne=Q instanceof Error?Q.message:"删除失败";Ce({title:"错误",description:Ne,variant:"destructive"})}},Te=async Q=>{try{await T1(Q.id),Ce({title:"成功",description:"表情包已注册"}),ze(),ge()}catch(Ne){const qe=Ne instanceof Error?Ne.message:"注册失败";Ce({title:"错误",description:qe,variant:"destructive"})}},Le=async Q=>{try{await E1(Q.id),Ce({title:"成功",description:"表情包已封禁"}),ze(),ge()}catch(Ne){const qe=Ne instanceof Error?Ne.message:"封禁失败";Ce({title:"错误",description:qe,variant:"destructive"})}},E=Q=>{const Ne=new Set(ve);Ne.has(Q)?Ne.delete(Q):Ne.add(Q),be(Ne)},xe=async()=>{try{const Q=await M1(Array.from(ve));Ce({title:"批量删除完成",description:Q.message}),be(new Set),J(!1),ze(),ge()}catch(Q){Ce({title:"批量删除失败",description:Q instanceof Error?Q.message:"批量删除失败",variant:"destructive"})}},Ye=()=>{const Q=parseInt(q),Ne=Math.ceil(g/j);Q>=1&&Q<=Ne?(p(Q),se("")):Ce({title:"无效的页码",description:`请输入1-${Ne}之间的页码`,variant:"destructive"})},ke=i?.formats?Object.keys(i.formats):[];return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"表情包管理"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"管理麦麦的表情包资源"})]}),e.jsxs(S,{onClick:()=>_e(!0),className:"gap-2",children:[e.jsx(oi,{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:[i&&e.jsxs("div",{className:"grid gap-4 grid-cols-2 lg:grid-cols-4",children:[e.jsx(Fe,{children:e.jsxs(ts,{className:"pb-2",children:[e.jsx(et,{children:"总数"}),e.jsx(as,{className:"text-2xl",children:i.total})]})}),e.jsx(Fe,{children:e.jsxs(ts,{className:"pb-2",children:[e.jsx(et,{children:"已注册"}),e.jsx(as,{className:"text-2xl text-green-600",children:i.registered})]})}),e.jsx(Fe,{children:e.jsxs(ts,{className:"pb-2",children:[e.jsx(et,{children:"已封禁"}),e.jsx(as,{className:"text-2xl text-red-600",children:i.banned})]})}),e.jsx(Fe,{children:e.jsxs(ts,{className:"pb-2",children:[e.jsx(et,{children:"未注册"}),e.jsx(as,{className:"text-2xl text-gray-600",children:i.unregistered})]})})]}),e.jsxs(Fe,{children:[e.jsx(ts,{children:e.jsxs(as,{className:"flex items-center gap-2",children:[e.jsx(Ou,{className:"h-5 w-5"}),"筛选和排序"]})}),e.jsxs(xs,{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(C,{children:"排序方式"}),e.jsxs(Ue,{value:`${Y}-${z}`,onValueChange:Q=>{const[Ne,qe]=Q.split("-");L(Ne),K(qe),p(1)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"usage_count-desc",children:"使用次数 (多→少)"}),e.jsx(le,{value:"usage_count-asc",children:"使用次数 (少→多)"}),e.jsx(le,{value:"register_time-desc",children:"注册时间 (新→旧)"}),e.jsx(le,{value:"register_time-asc",children:"注册时间 (旧→新)"}),e.jsx(le,{value:"record_time-desc",children:"记录时间 (新→旧)"}),e.jsx(le,{value:"record_time-asc",children:"记录时间 (旧→新)"}),e.jsx(le,{value:"last_used_time-desc",children:"最后使用 (新→旧)"}),e.jsx(le,{value:"last_used_time-asc",children:"最后使用 (旧→新)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"注册状态"}),e.jsxs(Ue,{value:N,onValueChange:Q=>{k(Q),p(1)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部"}),e.jsx(le,{value:"registered",children:"已注册"}),e.jsx(le,{value:"unregistered",children:"未注册"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"封禁状态"}),e.jsxs(Ue,{value:w,onValueChange:Q=>{U(Q),p(1)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部"}),e.jsx(le,{value:"banned",children:"已封禁"}),e.jsx(le,{value:"unbanned",children:"未封禁"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"格式"}),e.jsxs(Ue,{value:O,onValueChange:Q=>{B(Q),p(1)},children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部"}),ke.map(Q=>e.jsxs(le,{value:Q,children:[Q.toUpperCase()," (",i?.formats[Q],")"]},Q))]})]})]})]}),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:[ve.size>0&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["已选择 ",ve.size," 个表情包"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{className:"text-sm whitespace-nowrap",children:"卡片大小"}),e.jsxs(Ue,{value:R,onValueChange:Q=>ue(Q),children:[e.jsx(Oe,{className:"w-24",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"small",children:"小"}),e.jsx(le,{value:"medium",children:"中"}),e.jsx(le,{value:"large",children:"大"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{htmlFor:"emoji-page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ue,{value:j.toString(),onValueChange:Q=>{y(parseInt(Q)),p(1),be(new Set)},children:[e.jsx(Oe,{id:"emoji-page-size",className:"w-20",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"20",children:"20"}),e.jsx(le,{value:"40",children:"40"}),e.jsx(le,{value:"60",children:"60"}),e.jsx(le,{value:"100",children:"100"})]})]}),ve.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>be(new Set),children:"取消选择"}),e.jsxs(S,{variant:"destructive",size:"sm",onClick:()=>J(!0),children:[e.jsx(We,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsxs(S,{variant:"outline",size:"sm",onClick:ze,disabled:m,children:[e.jsx(zt,{className:`h-4 w-4 mr-2 ${m?"animate-spin":""}`}),"刷新"]})})]})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{children:[e.jsx(as,{children:"表情包列表"}),e.jsxs(et,{children:["共 ",g," 个表情包,当前第 ",f," 页"]})]}),e.jsxs(xs,{children:[n.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"暂无数据"}):e.jsx("div",{className:`grid gap-3 ${R==="small"?"grid-cols-3 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10":R==="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:n.map(Q=>e.jsxs("div",{className:`group relative rounded-lg border bg-card overflow-hidden hover:ring-2 hover:ring-primary transition-all cursor-pointer ${ve.has(Q.id)?"ring-2 ring-primary bg-primary/5":""}`,onClick:()=>E(Q.id),children:[e.jsx("div",{className:`absolute top-1 left-1 z-10 transition-opacity ${ve.has(Q.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 ${ve.has(Q.id)?"bg-primary border-primary text-primary-foreground":"bg-background/80 border-muted-foreground/50"}`,children:ve.has(Q.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:[Q.is_registered&&e.jsx(Qe,{variant:"default",className:"bg-green-600 text-[10px] px-1 py-0",children:"已注册"}),Q.is_banned&&e.jsx(Qe,{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 ${R==="small"?"p-1":R==="medium"?"p-2":"p-3"}`,children:e.jsx(N1,{src:z1(Q.id),alt:"表情包"})}),e.jsxs("div",{className:`border-t bg-card ${R==="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(Qe,{variant:"outline",className:"text-[10px] px-1 py-0",children:Q.format.toUpperCase()}),e.jsxs("span",{className:"font-mono",children:[Q.usage_count,"次"]})]}),e.jsxs("div",{className:`flex gap-1 justify-center opacity-0 group-hover:opacity-100 transition-opacity ${R==="small"?"flex-wrap":""}`,children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:Ne=>{Ne.stopPropagation(),re(Q)},title:"编辑",children:e.jsx(nn,{className:"h-3 w-3"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:Ne=>{Ne.stopPropagation(),ae(Q)},title:"详情",children:e.jsx(Ra,{className:"h-3 w-3"})}),!Q.is_registered&&e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 text-green-600 hover:text-green-700",onClick:Ne=>{Ne.stopPropagation(),Te(Q)},title:"注册",children:e.jsx(aa,{className:"h-3 w-3"})}),!Q.is_banned&&e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 text-orange-600 hover:text-orange-700",onClick:Ne=>{Ne.stopPropagation(),Le(Q)},title:"封禁",children:e.jsx(dy,{className:"h-3 w-3"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 text-red-600 hover:text-red-700",onClick:Ne=>{Ne.stopPropagation(),F(Q)},title:"删除",children:e.jsx(We,{className:"h-3 w-3"})})]})]})]},Q.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:["显示 ",(f-1)*j+1," 到"," ",Math.min(f*j,g)," 条,共 ",g," 条"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>p(1),disabled:f===1,className:"hidden sm:flex",children:e.jsx(lr,{className:"h-4 w-4"})}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>p(Q=>Math.max(1,Q-1)),disabled:f===1,children:[e.jsx(il,{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:q,onChange:Q=>se(Q.target.value),onKeyDown:Q=>Q.key==="Enter"&&Ye(),placeholder:f.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(g/j)}),e.jsx(S,{variant:"outline",size:"sm",onClick:Ye,disabled:!q,className:"h-8",children:"跳转"})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>p(Q=>Q+1),disabled:f>=Math.ceil(g/j),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>p(Math.ceil(g/j)),disabled:f>=Math.ceil(g/j),className:"hidden sm:flex",children:e.jsx(nr,{className:"h-4 w-4"})})]})]})]})]}),e.jsx(R1,{emoji:I,open:A,onOpenChange:te}),e.jsx(L1,{emoji:I,open:fe,onOpenChange:je,onSuccess:()=>{ze(),ge()}}),e.jsx(U1,{open:me,onOpenChange:_e,onSuccess:()=>{ze(),ge()}})]})}),e.jsx(hs,{open:D,onOpenChange:J,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认批量删除"}),e.jsxs(cs,{children:["你确定要删除选中的 ",ve.size," 个表情包吗?此操作不可撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:xe,children:"确认删除"})]})]})}),e.jsx(qs,{open:pe,onOpenChange:he,children:e.jsxs(Ls,{children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"确认删除"}),e.jsx(Ps,{children:"确定要删除这个表情包吗?此操作无法撤销。"})]}),e.jsxs(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>he(!1),children:"取消"}),e.jsx(S,{variant:"destructive",onClick:P,children:"删除"})]})]})})]})}function R1({emoji:n,open:r,onOpenChange:i}){if(!n)return null;const d=m=>m?new Date(m*1e3).toLocaleString("zh-CN"):"-";return e.jsx(qs,{open:r,onOpenChange:i,children:e.jsxs(Ls,{className:"max-w-2xl max-h-[90vh]",children:[e.jsx(Us,{children:e.jsx(Bs,{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:A1(n.id),alt:n.description||"表情包",className:"w-full h-full object-cover",onError:m=>{const x=m.target;x.style.display="none";const f=x.parentElement;f&&(f.innerHTML='')}})})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(C,{className:"text-muted-foreground",children:"ID"}),e.jsx("div",{className:"mt-1 font-mono",children:n.id})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-muted-foreground",children:"格式"}),e.jsx("div",{className:"mt-1",children:e.jsx(Qe,{variant:"outline",children:n.format.toUpperCase()})})]})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-muted-foreground",children:"文件路径"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:n.full_path})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-muted-foreground",children:"哈希值"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:n.emoji_hash})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-muted-foreground",children:"描述"}),n.description?e.jsx("div",{className:"mt-1 rounded-lg border bg-muted/50 p-3",children:e.jsx(y1,{className:"prose-sm",children:n.description})}):e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"-"})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-muted-foreground",children:"情绪"}),e.jsx("div",{className:"mt-1",children:n.emotion?e.jsx("span",{className:"text-sm",children:n.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(C,{className:"text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[n.is_registered&&e.jsx(Qe,{variant:"default",className:"bg-green-600",children:"已注册"}),n.is_banned&&e.jsx(Qe,{variant:"destructive",children:"已封禁"}),!n.is_registered&&!n.is_banned&&e.jsx(Qe,{variant:"outline",children:"未注册"})]})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-muted-foreground",children:"使用次数"}),e.jsx("div",{className:"mt-1 font-mono text-lg",children:n.usage_count})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(C,{className:"text-muted-foreground",children:"记录时间"}),e.jsx("div",{className:"mt-1 text-sm",children:d(n.record_time)})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-muted-foreground",children:"注册时间"}),e.jsx("div",{className:"mt-1 text-sm",children:d(n.register_time)})]})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-muted-foreground",children:"最后使用"}),e.jsx("div",{className:"mt-1 text-sm",children:d(n.last_used_time)})]})]})})]})})}function L1({emoji:n,open:r,onOpenChange:i,onSuccess:d}){const[m,x]=u.useState(""),[f,p]=u.useState(!1),[g,b]=u.useState(!1),[j,y]=u.useState(!1),{toast:N}=$s();u.useEffect(()=>{n&&(x(n.emotion||""),p(n.is_registered),b(n.is_banned))},[n]);const k=async()=>{if(n)try{y(!0);const w=m.split(/[,,]/).map(U=>U.trim()).filter(Boolean).join(",");await S1(n.id,{emotion:w||void 0,is_registered:f,is_banned:g}),N({title:"成功",description:"表情包信息已更新"}),i(!1),d()}catch(w){const U=w instanceof Error?w.message:"保存失败";N({title:"错误",description:U,variant:"destructive"})}finally{y(!1)}};return n?e.jsx(qs,{open:r,onOpenChange:i,children:e.jsxs(Ls,{className:"max-w-2xl",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"编辑表情包"}),e.jsx(Ps,{children:"修改表情包的情绪和状态信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(C,{children:"情绪"}),e.jsx(Qs,{value:m,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(mt,{id:"is_registered",checked:f,onCheckedChange:w=>{w===!0?(p(!0),b(!1)):p(!1)}}),e.jsx(C,{htmlFor:"is_registered",className:"cursor-pointer",children:"已注册"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(mt,{id:"is_banned",checked:g,onCheckedChange:w=>{w===!0?(b(!0),p(!1)):b(!1)}}),e.jsx(C,{htmlFor:"is_banned",className:"cursor-pointer",children:"已封禁"})]})]})]}),e.jsxs(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(S,{onClick:k,disabled:j,children:j?"保存中...":"保存"})]})]})}):null}function U1({open:n,onOpenChange:r,onSuccess:i}){const[d,m]=u.useState("select"),[x,f]=u.useState([]),[p,g]=u.useState(null),[b,j]=u.useState(!1),{toast:y}=$s(),N=u.useMemo(()=>new Iy({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}"}}}),[]);u.useEffect(()=>{const I=()=>{const T=N.getFiles();if(T.length===0)return;const A=T.map(te=>({id:te.id,name:te.name,previewUrl:te.preview||URL.createObjectURL(te.data),emotion:"",description:"",isRegistered:!0,file:te.data}));f(A),T.length===1?(g(A[0].id),m("edit-single")):m("edit-multiple")};return N.on("upload",I),()=>{N.off("upload",I)}},[N]),u.useEffect(()=>{n||(N.cancelAll(),m("select"),f([]),g(null),j(!1))},[n,N]);const k=u.useCallback((I,T)=>{f(A=>A.map(te=>te.id===I?{...te,...T}:te))},[]),w=u.useCallback(I=>I.emotion.trim().length>0,[]),U=u.useMemo(()=>x.length>0&&x.every(w),[x,w]),O=u.useMemo(()=>x.find(I=>I.id===p)||null,[x,p]),B=u.useCallback(()=>{(d==="edit-single"||d==="edit-multiple")&&(m("select"),f([]),g(null))},[d]),Y=u.useCallback(async()=>{if(!U){y({title:"请填写必填项",description:"每个表情包的情感标签都是必填的",variant:"destructive"});return}j(!0);const I=localStorage.getItem("access-token")||"";let T=0,A=0;try{for(const te of x){const fe=new FormData;fe.append("file",te.file),fe.append("emotion",te.emotion),fe.append("description",te.description),fe.append("is_registered",te.isRegistered.toString());try{(await fetch(D1(),{method:"POST",headers:{Authorization:`Bearer ${I}`},body:fe})).ok?T++:A++}catch{A++}}A===0?(y({title:"上传成功",description:`成功上传 ${T} 个表情包`}),r(!1),i()):(y({title:"部分上传失败",description:`成功 ${T} 个,失败 ${A} 个`,variant:"destructive"}),i())}finally{j(!1)}},[U,x,y,r,i]),L=()=>e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"border rounded-lg overflow-hidden w-full",children:e.jsx(b1,{uppy:N,proudlyDisplayPoweredByUppy:!1,hideProgressDetails:!0,height:350,width:"100%",theme:"auto",note:"支持 JPG、PNG、GIF、WebP 格式,最多 20 个文件"})})}),z=()=>{const I=x[0];return I?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(S,{variant:"ghost",size:"sm",onClick:B,children:[e.jsx(er,{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:I.previewUrl,alt:I.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:I.name})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{htmlFor:"single-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ie,{id:"single-emotion",value:I.emotion,onChange:T=>k(I.id,{emotion:T.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:I.emotion.trim()?"":"border-destructive"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于情感匹配,多个标签用逗号分隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"single-description",children:"描述"}),e.jsx(ie,{id:"single-description",value:I.description,onChange:T=>k(I.id,{description:T.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(mt,{id:"single-is-registered",checked:I.isRegistered,onCheckedChange:T=>k(I.id,{isRegistered:T===!0})}),e.jsx(C,{htmlFor:"single-is-registered",className:"cursor-pointer",children:"上传后立即注册(可被麦麦使用)"})]})]})]}),e.jsx(st,{children:e.jsx(S,{onClick:Y,disabled:!U||b,children:b?"上传中...":"上传"})})]}):null},K=()=>{const I=x.filter(w).length,T=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(S,{variant:"ghost",size:"sm",onClick:B,children:[e.jsx(er,{className:"h-4 w-4 mr-1"}),"返回"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["编辑表情包信息(",I,"/",T," 已完成)"]})]}),e.jsx(Qe,{variant:U?"default":"secondary",children:U?e.jsxs(e.Fragment,{children:[e.jsx(Qt,{className:"h-3 w-3 mr-1"}),"全部完成"]}):e.jsxs(e.Fragment,{children:[e.jsx(rl,{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(A=>{const te=w(A),fe=p===A.id;return e.jsxs("div",{onClick:()=>g(A.id),className:` flex items-center gap-3 p-3 rounded-lg border-2 cursor-pointer transition-all ${fe?"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: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:"text-sm font-medium truncate",children:A.name}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:A.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"})]},A.id)})})}),e.jsx("div",{className:"border rounded-lg p-4",children:O?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:O.previewUrl,alt:O.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:O.name}),w(O)&&e.jsxs(Qe,{variant:"outline",className:"text-green-600 border-green-600",children:[e.jsx(Qt,{className:"h-3 w-3 mr-1"}),"已完成"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{htmlFor:"multi-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ie,{id:"multi-emotion",value:O.emotion,onChange:A=>k(O.id,{emotion:A.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:O.emotion.trim()?"":"border-destructive"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"multi-description",children:"描述"}),e.jsx(ie,{id:"multi-description",value:O.description,onChange:A=>k(O.id,{description:A.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(mt,{id:"multi-is-registered",checked:O.isRegistered,onCheckedChange:A=>k(O.id,{isRegistered:A===!0})}),e.jsx(C,{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(gg,{className:"h-12 w-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"点击左侧卡片编辑"})]})})})]}),e.jsx(st,{children:e.jsx(S,{onClick:Y,disabled:!U||b,children:b?"上传中...":`上传全部 (${T})`})})]})};return e.jsx(qs,{open:n,onOpenChange:r,children:e.jsxs(Ls,{className:"max-w-3xl max-h-[90vh] overflow-hidden",children:[e.jsxs(Us,{children:[e.jsxs(Bs,{className:"flex items-center gap-2",children:[e.jsx(oi,{className:"h-5 w-5"}),d==="select"&&"上传表情包 - 选择文件",d==="edit-single"&&"上传表情包 - 填写信息",d==="edit-multiple"&&"上传表情包 - 批量编辑"]}),e.jsxs(Ps,{children:[d==="select"&&"支持 JPG、PNG、GIF、WebP 格式,单个文件最大 10MB,可同时上传多个文件",d==="edit-single"&&"请填写表情包的情感标签(必填)和描述",d==="edit-multiple"&&"点击左侧卡片编辑每个表情包的信息,情感标签为必填项"]})]}),e.jsxs("div",{className:"overflow-y-auto pr-1",children:[d==="select"&&L(),d==="edit-single"&&z(),d==="edit-multiple"&&K()]})]})})}const Bl="/api/webui/expression";async function B1(){const n=await Se(`${Bl}/chats`,{});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取聊天列表失败")}return n.json()}async function H1(n){const r=new URLSearchParams;n.page&&r.append("page",n.page.toString()),n.page_size&&r.append("page_size",n.page_size.toString()),n.search&&r.append("search",n.search),n.chat_id&&r.append("chat_id",n.chat_id);const i=await Se(`${Bl}/list?${r}`,{});if(!i.ok){const d=await i.json();throw new Error(d.detail||"获取表达方式列表失败")}return i.json()}async function q1(n){const r=await Se(`${Bl}/${n}`,{});if(!r.ok){const i=await r.json();throw new Error(i.detail||"获取表达方式详情失败")}return r.json()}async function G1(n){const r=await Se(`${Bl}/`,{method:"POST",body:JSON.stringify(n)});if(!r.ok){const i=await r.json();throw new Error(i.detail||"创建表达方式失败")}return r.json()}async function $1(n,r){const i=await Se(`${Bl}/${n}`,{method:"PATCH",body:JSON.stringify(r)});if(!i.ok){const d=await i.json();throw new Error(d.detail||"更新表达方式失败")}return i.json()}async function F1(n){const r=await Se(`${Bl}/${n}`,{method:"DELETE"});if(!r.ok){const i=await r.json();throw new Error(i.detail||"删除表达方式失败")}return r.json()}async function V1(n){const r=await Se(`${Bl}/batch/delete`,{method:"POST",body:JSON.stringify({ids:n})});if(!r.ok){const i=await r.json();throw new Error(i.detail||"批量删除表达方式失败")}return r.json()}async function Q1(){const n=await Se(`${Bl}/stats/summary`,{});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取统计数据失败")}return n.json()}function I1(){const[n,r]=u.useState([]),[i,d]=u.useState(!0),[m,x]=u.useState(0),[f,p]=u.useState(1),[g,b]=u.useState(20),[j,y]=u.useState(""),[N,k]=u.useState(null),[w,U]=u.useState(!1),[O,B]=u.useState(!1),[Y,L]=u.useState(!1),[z,K]=u.useState(null),[I,T]=u.useState(new Set),[A,te]=u.useState(!1),[fe,je]=u.useState(""),[pe,he]=u.useState({total:0,recent_7days:0,chat_count:0,top_chats:{}}),[ve,be]=u.useState([]),[D,J]=u.useState(new Map),{toast:q}=$s(),se=async()=>{try{d(!0);const P=await H1({page:f,page_size:g,search:j||void 0});r(P.data),x(P.total)}catch(P){q({title:"加载失败",description:P instanceof Error?P.message:"无法加载表达方式",variant:"destructive"})}finally{d(!1)}},R=async()=>{try{const P=await Q1();P?.data&&he(P.data)}catch(P){console.error("加载统计数据失败:",P)}},ue=async()=>{try{const P=await B1();if(P?.data){be(P.data);const Te=new Map;P.data.forEach(Le=>{Te.set(Le.chat_id,Le.chat_name)}),J(Te)}}catch(P){console.error("加载聊天列表失败:",P)}},me=P=>D.get(P)||P;u.useEffect(()=>{se(),R(),ue()},[f,g,j]);const _e=async P=>{try{const Te=await q1(P.id);k(Te.data),U(!0)}catch(Te){q({title:"加载详情失败",description:Te instanceof Error?Te.message:"无法加载表达方式详情",variant:"destructive"})}},Ce=P=>{k(P),B(!0)},ze=async P=>{try{await F1(P.id),q({title:"删除成功",description:`已删除表达方式: ${P.situation}`}),K(null),se(),R()}catch(Te){q({title:"删除失败",description:Te instanceof Error?Te.message:"无法删除表达方式",variant:"destructive"})}},ge=P=>{const Te=new Set(I);Te.has(P)?Te.delete(P):Te.add(P),T(Te)},ae=()=>{I.size===n.length&&n.length>0?T(new Set):T(new Set(n.map(P=>P.id)))},re=async()=>{try{await V1(Array.from(I)),q({title:"批量删除成功",description:`已删除 ${I.size} 个表达方式`}),T(new Set),te(!1),se(),R()}catch(P){q({title:"批量删除失败",description:P instanceof Error?P.message:"无法批量删除表达方式",variant:"destructive"})}},F=()=>{const P=parseInt(fe),Te=Math.ceil(m/g);P>=1&&P<=Te?(p(P),je("")):q({title:"无效的页码",description:`请输入1-${Te}之间的页码`,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(Rl,{className:"h-8 w-8",strokeWidth:2}),"表达方式管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦的表达方式和话术模板"})]}),e.jsxs(S,{onClick:()=>L(!0),className:"gap-2",children:[e.jsx(dt,{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:pe.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:pe.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:pe.chat_count})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx(C,{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(Mt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{id:"search",placeholder:"搜索情境、风格或上下文...",value:j,onChange:P=>y(P.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:I.size>0&&e.jsxs("span",{children:["已选择 ",I.size," 个表达方式"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ue,{value:g.toString(),onValueChange:P=>{b(parseInt(P)),p(1),T(new Set)},children:[e.jsx(Oe,{id:"page-size",className:"w-20",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"10",children:"10"}),e.jsx(le,{value:"20",children:"20"}),e.jsx(le,{value:"50",children:"50"}),e.jsx(le,{value:"100",children:"100"})]})]}),I.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>T(new Set),children:"取消选择"}),e.jsxs(S,{variant:"destructive",size:"sm",onClick:()=>te(!0),children:[e.jsx(We,{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(rn,{children:[e.jsx(cn,{children:e.jsxs(ut,{children:[e.jsx(Xe,{className:"w-12",children:e.jsx(mt,{checked:I.size===n.length&&n.length>0,onCheckedChange:ae})}),e.jsx(Xe,{children:"情境"}),e.jsx(Xe,{children:"风格"}),e.jsx(Xe,{children:"聊天"}),e.jsx(Xe,{className:"text-right",children:"操作"})]})}),e.jsx(on,{children:i?e.jsx(ut,{children:e.jsx(Ve,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):n.length===0?e.jsx(ut,{children:e.jsx(Ve,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):n.map(P=>e.jsxs(ut,{children:[e.jsx(Ve,{children:e.jsx(mt,{checked:I.has(P.id),onCheckedChange:()=>ge(P.id)})}),e.jsx(Ve,{className:"font-medium max-w-xs truncate",children:P.situation}),e.jsx(Ve,{className:"max-w-xs truncate",children:P.style}),e.jsx(Ve,{className:"max-w-[200px] truncate",title:me(P.chat_id),style:{wordBreak:"keep-all"},children:e.jsx("span",{className:"whitespace-nowrap overflow-hidden text-ellipsis block",children:me(P.chat_id)})}),e.jsx(Ve,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(S,{variant:"default",size:"sm",onClick:()=>Ce(P),children:[e.jsx(nn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(S,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>_e(P),title:"查看详情",children:e.jsx(Rt,{className:"h-4 w-4"})}),e.jsxs(S,{size:"sm",onClick:()=>K(P),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(We,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},P.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:i?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):n.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):n.map(P=>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(mt,{checked:I.has(P.id),onCheckedChange:()=>ge(P.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:P.situation,children:P.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:P.style,children:P.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:me(P.chat_id),style:{wordBreak:"keep-all"},children:me(P.chat_id)})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>Ce(P),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(nn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>_e(P),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:e.jsx(Rt,{className:"h-3 w-3"})}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>K(P),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(We,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},P.id))}),m>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:["共 ",m," 条记录,第 ",f," / ",Math.ceil(m/g)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>p(1),disabled:f===1,className:"hidden sm:flex",children:e.jsx(lr,{className:"h-4 w-4"})}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>p(f-1),disabled:f===1,children:[e.jsx(il,{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:fe,onChange:P=>je(P.target.value),onKeyDown:P=>P.key==="Enter"&&F(),placeholder:f.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(m/g)}),e.jsx(S,{variant:"outline",size:"sm",onClick:F,disabled:!fe,className:"h-8",children:"跳转"})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>p(f+1),disabled:f>=Math.ceil(m/g),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>p(Math.ceil(m/g)),disabled:f>=Math.ceil(m/g),className:"hidden sm:flex",children:e.jsx(nr,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(Y1,{expression:N,open:w,onOpenChange:U,chatNameMap:D}),e.jsx(K1,{open:Y,onOpenChange:L,chatList:ve,onSuccess:()=>{se(),R(),L(!1)}}),e.jsx(X1,{expression:N,open:O,onOpenChange:B,chatList:ve,onSuccess:()=>{se(),R(),B(!1)}}),e.jsx(hs,{open:!!z,onOpenChange:()=>K(null),children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:['确定要删除表达方式 "',z?.situation,'" 吗? 此操作不可撤销。']})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>z&&ze(z),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(J1,{open:A,onOpenChange:te,onConfirm:re,count:I.size})]})}function Y1({expression:n,open:r,onOpenChange:i,chatNameMap:d}){if(!n)return null;const m=f=>f?new Date(f*1e3).toLocaleString("zh-CN"):"-",x=f=>d.get(f)||f;return e.jsx(qs,{open:r,onOpenChange:i,children:e.jsxs(Ls,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"表达方式详情"}),e.jsx(Ps,{children:"查看表达方式的完整信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(si,{label:"情境",value:n.situation}),e.jsx(si,{label:"风格",value:n.style}),e.jsx(si,{label:"聊天",value:x(n.chat_id)}),e.jsx(si,{icon:sr,label:"记录ID",value:n.id.toString(),mono:!0})]}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsx(si,{icon:Pn,label:"创建时间",value:m(n.create_date)})})]}),e.jsx(st,{children:e.jsx(S,{onClick:()=>i(!1),children:"关闭"})})]})})}function si({icon:n,label:r,value:i,mono:d=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(C,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n&&e.jsx(n,{className:"h-3 w-3"}),r]}),e.jsx("div",{className:$("text-sm",d&&"font-mono",!i&&"text-muted-foreground"),children:i||"-"})]})}function K1({open:n,onOpenChange:r,chatList:i,onSuccess:d}){const[m,x]=u.useState({situation:"",style:"",chat_id:""}),[f,p]=u.useState(!1),{toast:g}=$s(),b=async()=>{if(!m.situation||!m.style||!m.chat_id){g({title:"验证失败",description:"请填写必填字段:情境、风格和聊天",variant:"destructive"});return}try{p(!0),await G1(m),g({title:"创建成功",description:"表达方式已创建"}),x({situation:"",style:"",chat_id:""}),d()}catch(j){g({title:"创建失败",description:j instanceof Error?j.message:"无法创建表达方式",variant:"destructive"})}finally{p(!1)}};return e.jsx(qs,{open:n,onOpenChange:r,children:e.jsxs(Ls,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"新增表达方式"}),e.jsx(Ps,{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(C,{htmlFor:"situation",children:["情境 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ie,{id:"situation",value:m.situation,onChange:j=>x({...m,situation:j.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{htmlFor:"style",children:["风格 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ie,{id:"style",value:m.style,onChange:j=>x({...m,style:j.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Ue,{value:m.chat_id,onValueChange:j=>x({...m,chat_id:j}),children:[e.jsx(Oe,{children:e.jsx(Be,{placeholder:"选择关联的聊天"})}),e.jsx(Re,{children:i.map(j=>e.jsx(le,{value:j.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[j.chat_name,j.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},j.chat_id))})]})]})]}),e.jsxs(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(S,{onClick:b,disabled:f,children:f?"创建中...":"创建"})]})]})})}function X1({expression:n,open:r,onOpenChange:i,chatList:d,onSuccess:m}){const[x,f]=u.useState({}),[p,g]=u.useState(!1),{toast:b}=$s();u.useEffect(()=>{n&&f({situation:n.situation,style:n.style,chat_id:n.chat_id})},[n]);const j=async()=>{if(n)try{g(!0),await $1(n.id,x),b({title:"保存成功",description:"表达方式已更新"}),m()}catch(y){b({title:"保存失败",description:y instanceof Error?y.message:"无法更新表达方式",variant:"destructive"})}finally{g(!1)}};return n?e.jsx(qs,{open:r,onOpenChange:i,children:e.jsxs(Ls,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"编辑表达方式"}),e.jsx(Ps,{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(C,{htmlFor:"edit_situation",children:"情境"}),e.jsx(ie,{id:"edit_situation",value:x.situation||"",onChange:y=>f({...x,situation:y.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"edit_style",children:"风格"}),e.jsx(ie,{id:"edit_style",value:x.style||"",onChange:y=>f({...x,style:y.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Ue,{value:x.chat_id||"",onValueChange:y=>f({...x,chat_id:y}),children:[e.jsx(Oe,{children:e.jsx(Be,{placeholder:"选择关联的聊天"})}),e.jsx(Re,{children:d.map(y=>e.jsx(le,{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(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(S,{onClick:j,disabled:p,children:p?"保存中...":"保存"})]})]})}):null}function J1({open:n,onOpenChange:r,onConfirm:i,count:d}){return e.jsx(hs,{open:n,onOpenChange:r,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认批量删除"}),e.jsxs(cs,{children:["您即将删除 ",d," 个表达方式,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:i,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})}const cl="/api/webui/jargon";async function Z1(){const n=await Se(`${cl}/chats`,{});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取聊天列表失败")}return n.json()}async function P1(n){const r=new URLSearchParams;n.page&&r.append("page",n.page.toString()),n.page_size&&r.append("page_size",n.page_size.toString()),n.search&&r.append("search",n.search),n.chat_id&&r.append("chat_id",n.chat_id),n.is_jargon!==void 0&&n.is_jargon!==null&&r.append("is_jargon",n.is_jargon.toString()),n.is_global!==void 0&&r.append("is_global",n.is_global.toString());const i=await Se(`${cl}/list?${r}`,{});if(!i.ok){const d=await i.json();throw new Error(d.detail||"获取黑话列表失败")}return i.json()}async function W1(n){const r=await Se(`${cl}/${n}`,{});if(!r.ok){const i=await r.json();throw new Error(i.detail||"获取黑话详情失败")}return r.json()}async function e2(n){const r=await Se(`${cl}/`,{method:"POST",body:JSON.stringify(n)});if(!r.ok){const i=await r.json();throw new Error(i.detail||"创建黑话失败")}return r.json()}async function s2(n,r){const i=await Se(`${cl}/${n}`,{method:"PATCH",body:JSON.stringify(r)});if(!i.ok){const d=await i.json();throw new Error(d.detail||"更新黑话失败")}return i.json()}async function t2(n){const r=await Se(`${cl}/${n}`,{method:"DELETE"});if(!r.ok){const i=await r.json();throw new Error(i.detail||"删除黑话失败")}return r.json()}async function a2(n){const r=await Se(`${cl}/batch/delete`,{method:"POST",body:JSON.stringify({ids:n})});if(!r.ok){const i=await r.json();throw new Error(i.detail||"批量删除黑话失败")}return r.json()}async function l2(){const n=await Se(`${cl}/stats/summary`,{});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取黑话统计失败")}return n.json()}async function n2(n,r){const i=new URLSearchParams;n.forEach(m=>i.append("ids",m.toString())),i.append("is_jargon",r.toString());const d=await Se(`${cl}/batch/set-jargon?${i}`,{method:"POST"});if(!d.ok){const m=await d.json();throw new Error(m.detail||"批量设置黑话状态失败")}return d.json()}function r2(){const[n,r]=u.useState([]),[i,d]=u.useState(!0),[m,x]=u.useState(0),[f,p]=u.useState(1),[g,b]=u.useState(20),[j,y]=u.useState(""),[N,k]=u.useState("all"),[w,U]=u.useState("all"),[O,B]=u.useState(null),[Y,L]=u.useState(!1),[z,K]=u.useState(!1),[I,T]=u.useState(!1),[A,te]=u.useState(null),[fe,je]=u.useState(new Set),[pe,he]=u.useState(!1),[ve,be]=u.useState(""),[D,J]=u.useState({total:0,confirmed_jargon:0,confirmed_not_jargon:0,pending:0,global_count:0,complete_count:0,chat_count:0,top_chats:{}}),[q,se]=u.useState([]),{toast:R}=$s(),ue=async()=>{try{d(!0);const E=await P1({page:f,page_size:g,search:j||void 0,chat_id:N==="all"?void 0:N,is_jargon:w==="all"?void 0:w==="true"?!0:w==="false"?!1:void 0});r(E.data),x(E.total)}catch(E){R({title:"加载失败",description:E instanceof Error?E.message:"无法加载黑话列表",variant:"destructive"})}finally{d(!1)}},me=async()=>{try{const E=await l2();E?.data&&J(E.data)}catch(E){console.error("加载统计数据失败:",E)}},_e=async()=>{try{const E=await Z1();E?.data&&se(E.data)}catch(E){console.error("加载聊天列表失败:",E)}};u.useEffect(()=>{ue(),me(),_e()},[f,g,j,N,w]);const Ce=async E=>{try{const xe=await W1(E.id);B(xe.data),L(!0)}catch(xe){R({title:"加载详情失败",description:xe instanceof Error?xe.message:"无法加载黑话详情",variant:"destructive"})}},ze=E=>{B(E),K(!0)},ge=async E=>{try{await t2(E.id),R({title:"删除成功",description:`已删除黑话: ${E.content}`}),te(null),ue(),me()}catch(xe){R({title:"删除失败",description:xe instanceof Error?xe.message:"无法删除黑话",variant:"destructive"})}},ae=E=>{const xe=new Set(fe);xe.has(E)?xe.delete(E):xe.add(E),je(xe)},re=()=>{fe.size===n.length&&n.length>0?je(new Set):je(new Set(n.map(E=>E.id)))},F=async()=>{try{await a2(Array.from(fe)),R({title:"批量删除成功",description:`已删除 ${fe.size} 个黑话`}),je(new Set),he(!1),ue(),me()}catch(E){R({title:"批量删除失败",description:E instanceof Error?E.message:"无法批量删除黑话",variant:"destructive"})}},P=async E=>{try{await n2(Array.from(fe),E),R({title:"操作成功",description:`已将 ${fe.size} 个词条设为${E?"黑话":"非黑话"}`}),je(new Set),ue(),me()}catch(xe){R({title:"操作失败",description:xe instanceof Error?xe.message:"批量设置失败",variant:"destructive"})}},Te=()=>{const E=parseInt(ve),xe=Math.ceil(m/g);E>=1&&E<=xe?(p(E),be("")):R({title:"无效的页码",description:`请输入1-${xe}之间的页码`,variant:"destructive"})},Le=E=>E===!0?e.jsxs(Qe,{variant:"default",className:"bg-green-600 hover:bg-green-700",children:[e.jsx(Qt,{className:"h-3 w-3 mr-1"}),"是黑话"]}):E===!1?e.jsxs(Qe,{variant:"secondary",children:[e.jsx(rl,{className:"h-3 w-3 mr-1"}),"非黑话"]}):e.jsxs(Qe,{variant:"outline",children:[e.jsx(pg,{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(uy,{className:"h-8 w-8",strokeWidth:2}),"黑话管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦学习到的黑话和俚语"})]}),e.jsxs(S,{onClick:()=>T(!0),className:"gap-2",children:[e.jsx(dt,{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:D.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:D.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:D.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:D.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:D.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:D.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:D.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(C,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx(Mt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{id:"search",placeholder:"搜索内容、含义...",value:j,onChange:E=>y(E.target.value),className:"pl-9"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"聊天筛选"}),e.jsxs(Ue,{value:N,onValueChange:k,children:[e.jsx(Oe,{children:e.jsx(Be,{placeholder:"全部聊天"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部聊天"}),q.map(E=>e.jsx(le,{value:E.chat_id,children:E.chat_name},E.chat_id))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"状态筛选"}),e.jsxs(Ue,{value:w,onValueChange:U,children:[e.jsx(Oe,{children:e.jsx(Be,{placeholder:"全部状态"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部状态"}),e.jsx(le,{value:"true",children:"是黑话"}),e.jsx(le,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"page-size",children:"每页显示"}),e.jsxs(Ue,{value:g.toString(),onValueChange:E=>{b(parseInt(E)),p(1),je(new Set)},children:[e.jsx(Oe,{id:"page-size",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"10",children:"10"}),e.jsx(le,{value:"20",children:"20"}),e.jsx(le,{value:"50",children:"50"}),e.jsx(le,{value:"100",children:"100"})]})]})]})]}),fe.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:["已选择 ",fe.size," 个"]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>P(!0),children:[e.jsx(Qt,{className:"h-4 w-4 mr-1"}),"标记为黑话"]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>P(!1),children:[e.jsx(rl,{className:"h-4 w-4 mr-1"}),"标记为非黑话"]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>je(new Set),children:"取消选择"}),e.jsxs(S,{variant:"destructive",size:"sm",onClick:()=>he(!0),children:[e.jsx(We,{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(rn,{children:[e.jsx(cn,{children:e.jsxs(ut,{children:[e.jsx(Xe,{className:"w-12",children:e.jsx(mt,{checked:fe.size===n.length&&n.length>0,onCheckedChange:re})}),e.jsx(Xe,{children:"内容"}),e.jsx(Xe,{children:"含义"}),e.jsx(Xe,{children:"聊天"}),e.jsx(Xe,{children:"状态"}),e.jsx(Xe,{className:"text-center",children:"次数"}),e.jsx(Xe,{className:"text-right",children:"操作"})]})}),e.jsx(on,{children:i?e.jsx(ut,{children:e.jsx(Ve,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):n.length===0?e.jsx(ut,{children:e.jsx(Ve,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):n.map(E=>e.jsxs(ut,{children:[e.jsx(Ve,{children:e.jsx(mt,{checked:fe.has(E.id),onCheckedChange:()=>ae(E.id)})}),e.jsx(Ve,{className:"font-medium max-w-[200px]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[E.is_global&&e.jsx("span",{title:"全局黑话",children:e.jsx(Ru,{className:"h-4 w-4 text-blue-500 flex-shrink-0"})}),e.jsx("span",{className:"truncate",title:E.content,children:E.content})]})}),e.jsx(Ve,{className:"max-w-[200px] truncate",title:E.meaning||"",children:E.meaning||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ve,{className:"max-w-[150px] truncate",title:E.chat_name||E.chat_id,children:E.chat_name||E.chat_id}),e.jsx(Ve,{children:Le(E.is_jargon)}),e.jsx(Ve,{className:"text-center",children:E.count}),e.jsx(Ve,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(S,{variant:"default",size:"sm",onClick:()=>ze(E),children:[e.jsx(nn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(S,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>Ce(E),title:"查看详情",children:e.jsx(Rt,{className:"h-4 w-4"})}),e.jsxs(S,{size:"sm",onClick:()=>te(E),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(We,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},E.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:i?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):n.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):n.map(E=>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(mt,{checked:fe.has(E.id),onCheckedChange:()=>ae(E.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:[E.is_global&&e.jsx(Ru,{className:"h-4 w-4 text-blue-500 flex-shrink-0"}),e.jsx("h3",{className:"font-semibold text-sm break-all",children:E.content})]}),E.meaning&&e.jsx("p",{className:"text-sm text-muted-foreground break-all",children:E.meaning}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:[Le(E.is_jargon),e.jsxs("span",{className:"text-muted-foreground",children:["次数: ",E.count]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:["聊天: ",E.chat_name||E.chat_id]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>ze(E),className:"text-xs px-2 py-1 h-auto",children:[e.jsx(nn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>Ce(E),className:"text-xs px-2 py-1 h-auto",children:e.jsx(Rt,{className:"h-3 w-3"})}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>te(E),className:"text-xs px-2 py-1 h-auto text-destructive hover:text-destructive",children:[e.jsx(We,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},E.id))}),m>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:["共 ",m," 条记录,第 ",f," / ",Math.ceil(m/g)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>p(1),disabled:f===1,className:"hidden sm:flex",children:e.jsx(lr,{className:"h-4 w-4"})}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>p(f-1),disabled:f===1,children:[e.jsx(il,{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:ve,onChange:E=>be(E.target.value),onKeyDown:E=>E.key==="Enter"&&Te(),placeholder:f.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(m/g)}),e.jsx(S,{variant:"outline",size:"sm",onClick:Te,disabled:!ve,className:"h-8",children:"跳转"})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>p(f+1),disabled:f>=Math.ceil(m/g),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>p(Math.ceil(m/g)),disabled:f>=Math.ceil(m/g),className:"hidden sm:flex",children:e.jsx(nr,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(i2,{jargon:O,open:Y,onOpenChange:L}),e.jsx(c2,{open:I,onOpenChange:T,chatList:q,onSuccess:()=>{ue(),me(),T(!1)}}),e.jsx(o2,{jargon:O,open:z,onOpenChange:K,chatList:q,onSuccess:()=>{ue(),me(),K(!1)}}),e.jsx(hs,{open:!!A,onOpenChange:()=>te(null),children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:['确定要删除黑话 "',A?.content,'" 吗?此操作不可撤销。']})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>A&&ge(A),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(hs,{open:pe,onOpenChange:he,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认批量删除"}),e.jsxs(cs,{children:["您即将删除 ",fe.size," 个黑话,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:F,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})]})}function i2({jargon:n,open:r,onOpenChange:i}){return n?e.jsx(qs,{open:r,onOpenChange:i,children:e.jsxs(Ls,{className:"max-w-2xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"黑话详情"}),e.jsx(Ps,{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(Mu,{icon:sr,label:"记录ID",value:n.id.toString(),mono:!0}),e.jsx(Mu,{label:"使用次数",value:n.count.toString()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs text-muted-foreground",children:"内容"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all whitespace-pre-wrap",children:n.content})]}),n.raw_content&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs text-muted-foreground",children:"原始内容"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:(()=>{try{const d=JSON.parse(n.raw_content);return Array.isArray(d)?d.map((m,x)=>e.jsxs("div",{children:[x>0&&e.jsx("hr",{className:"my-3 border-border"}),e.jsx("div",{className:"whitespace-pre-wrap",children:m})]},x)):e.jsx("div",{className:"whitespace-pre-wrap",children:n.raw_content})}catch{return e.jsx("div",{className:"whitespace-pre-wrap",children:n.raw_content})}})()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs text-muted-foreground",children:"含义"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:n.meaning?e.jsx(Yg,{content:n.meaning}):"-"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Mu,{label:"聊天",value:n.chat_name||n.chat_id}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{className:"text-xs text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"flex items-center gap-2",children:[n.is_jargon===!0&&e.jsx(Qe,{variant:"default",className:"bg-green-600",children:"是黑话"}),n.is_jargon===!1&&e.jsx(Qe,{variant:"secondary",children:"非黑话"}),n.is_jargon===null&&e.jsx(Qe,{variant:"outline",children:"未判定"}),n.is_global&&e.jsx(Qe,{variant:"outline",className:"border-blue-500 text-blue-500",children:"全局"}),n.is_complete&&e.jsx(Qe,{variant:"outline",className:"border-purple-500 text-purple-500",children:"推断完成"})]})]})]}),n.inference_with_context&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{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:n.inference_with_context})]}),n.inference_content_only&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(C,{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:n.inference_content_only})]})]})}),e.jsx(st,{className:"flex-shrink-0",children:e.jsx(S,{onClick:()=>i(!1),children:"关闭"})})]})}):null}function Mu({icon:n,label:r,value:i,mono:d=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(C,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n&&e.jsx(n,{className:"h-3 w-3"}),r]}),e.jsx("div",{className:$("text-sm",d&&"font-mono",!i&&"text-muted-foreground"),children:i||"-"})]})}function c2({open:n,onOpenChange:r,chatList:i,onSuccess:d}){const[m,x]=u.useState({content:"",meaning:"",chat_id:"",is_global:!1}),[f,p]=u.useState(!1),{toast:g}=$s(),b=async()=>{if(!m.content||!m.chat_id){g({title:"验证失败",description:"请填写必填字段:内容和聊天",variant:"destructive"});return}try{p(!0),await e2(m),g({title:"创建成功",description:"黑话已创建"}),x({content:"",meaning:"",chat_id:"",is_global:!1}),d()}catch(j){g({title:"创建失败",description:j instanceof Error?j.message:"无法创建黑话",variant:"destructive"})}finally{p(!1)}};return e.jsx(qs,{open:n,onOpenChange:r,children:e.jsxs(Ls,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"新增黑话"}),e.jsx(Ps,{children:"创建新的黑话记录"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{htmlFor:"content",children:["内容 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ie,{id:"content",value:m.content,onChange:j=>x({...m,content:j.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"meaning",children:"含义"}),e.jsx(Qs,{id:"meaning",value:m.meaning||"",onChange:j=>x({...m,meaning:j.target.value}),placeholder:"输入黑话含义(可选)",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Ue,{value:m.chat_id,onValueChange:j=>x({...m,chat_id:j}),children:[e.jsx(Oe,{children:e.jsx(Be,{placeholder:"选择关联的聊天"})}),e.jsx(Re,{children:i.map(j=>e.jsx(le,{value:j.chat_id,children:j.chat_name},j.chat_id))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx($e,{id:"is_global",checked:m.is_global,onCheckedChange:j=>x({...m,is_global:j})}),e.jsx(C,{htmlFor:"is_global",children:"设为全局黑话"})]})]}),e.jsxs(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(S,{onClick:b,disabled:f,children:f?"创建中...":"创建"})]})]})})}function o2({jargon:n,open:r,onOpenChange:i,chatList:d,onSuccess:m}){const[x,f]=u.useState({}),[p,g]=u.useState(!1),{toast:b}=$s();u.useEffect(()=>{n&&f({content:n.content,meaning:n.meaning||"",chat_id:n.stream_id||n.chat_id,is_global:n.is_global,is_jargon:n.is_jargon})},[n]);const j=async()=>{if(n)try{g(!0),await s2(n.id,x),b({title:"保存成功",description:"黑话已更新"}),m()}catch(y){b({title:"保存失败",description:y instanceof Error?y.message:"无法更新黑话",variant:"destructive"})}finally{g(!1)}};return n?e.jsx(qs,{open:r,onOpenChange:i,children:e.jsxs(Ls,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"编辑黑话"}),e.jsx(Ps,{children:"修改黑话的信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"edit_content",children:"内容"}),e.jsx(ie,{id:"edit_content",value:x.content||"",onChange:y=>f({...x,content:y.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"edit_meaning",children:"含义"}),e.jsx(Qs,{id:"edit_meaning",value:x.meaning||"",onChange:y=>f({...x,meaning:y.target.value}),placeholder:"输入黑话含义",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Ue,{value:x.chat_id||"",onValueChange:y=>f({...x,chat_id:y}),children:[e.jsx(Oe,{children:e.jsx(Be,{placeholder:"选择关联的聊天"})}),e.jsx(Re,{children:d.map(y=>e.jsx(le,{value:y.chat_id,children:y.chat_name},y.chat_id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"黑话状态"}),e.jsxs(Ue,{value:x.is_jargon===null?"null":x.is_jargon?.toString()||"null",onValueChange:y=>f({...x,is_jargon:y==="null"?null:y==="true"}),children:[e.jsx(Oe,{children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"null",children:"未判定"}),e.jsx(le,{value:"true",children:"是黑话"}),e.jsx(le,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx($e,{id:"edit_is_global",checked:x.is_global,onCheckedChange:y=>f({...x,is_global:y})}),e.jsx(C,{htmlFor:"edit_is_global",children:"全局黑话"})]})]}),e.jsxs(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(S,{onClick:j,disabled:p,children:p?"保存中...":"保存"})]})]})}):null}const ir="/api/webui/person";async function d2(n){const r=new URLSearchParams;n.page&&r.append("page",n.page.toString()),n.page_size&&r.append("page_size",n.page_size.toString()),n.search&&r.append("search",n.search),n.is_known!==void 0&&r.append("is_known",n.is_known.toString()),n.platform&&r.append("platform",n.platform);const i=await Se(`${ir}/list?${r}`,{headers:Gs()});if(!i.ok){const d=await i.json();throw new Error(d.detail||"获取人物列表失败")}return i.json()}async function u2(n){const r=await Se(`${ir}/${n}`,{headers:Gs()});if(!r.ok){const i=await r.json();throw new Error(i.detail||"获取人物详情失败")}return r.json()}async function m2(n,r){const i=await Se(`${ir}/${n}`,{method:"PATCH",headers:Gs(),body:JSON.stringify(r)});if(!i.ok){const d=await i.json();throw new Error(d.detail||"更新人物信息失败")}return i.json()}async function x2(n){const r=await Se(`${ir}/${n}`,{method:"DELETE",headers:Gs()});if(!r.ok){const i=await r.json();throw new Error(i.detail||"删除人物信息失败")}return r.json()}async function h2(){const n=await Se(`${ir}/stats/summary`,{headers:Gs()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取统计数据失败")}return n.json()}async function f2(n){const r=await Se(`${ir}/batch/delete`,{method:"POST",headers:Gs(),body:JSON.stringify({person_ids:n})});if(!r.ok){const i=await r.json();throw new Error(i.detail||"批量删除失败")}return r.json()}function p2(){const[n,r]=u.useState([]),[i,d]=u.useState(!0),[m,x]=u.useState(0),[f,p]=u.useState(1),[g,b]=u.useState(20),[j,y]=u.useState(""),[N,k]=u.useState(void 0),[w,U]=u.useState(void 0),[O,B]=u.useState(null),[Y,L]=u.useState(!1),[z,K]=u.useState(!1),[I,T]=u.useState(null),[A,te]=u.useState({total:0,known:0,unknown:0,platforms:{}}),[fe,je]=u.useState(new Set),[pe,he]=u.useState(!1),[ve,be]=u.useState(""),{toast:D}=$s(),J=async()=>{try{d(!0);const F=await d2({page:f,page_size:g,search:j||void 0,is_known:N,platform:w});r(F.data),x(F.total)}catch(F){D({title:"加载失败",description:F instanceof Error?F.message:"无法加载人物信息",variant:"destructive"})}finally{d(!1)}},q=async()=>{try{const F=await h2();F?.data&&te(F.data)}catch(F){console.error("加载统计数据失败:",F)}};u.useEffect(()=>{J(),q()},[f,g,j,N,w]);const se=async F=>{try{const P=await u2(F.person_id);B(P.data),L(!0)}catch(P){D({title:"加载详情失败",description:P instanceof Error?P.message:"无法加载人物详情",variant:"destructive"})}},R=F=>{B(F),K(!0)},ue=async F=>{try{await x2(F.person_id),D({title:"删除成功",description:`已删除人物信息: ${F.person_name||F.nickname||F.user_id}`}),T(null),J(),q()}catch(P){D({title:"删除失败",description:P instanceof Error?P.message:"无法删除人物信息",variant:"destructive"})}},me=u.useMemo(()=>Object.keys(A.platforms),[A.platforms]),_e=F=>{const P=new Set(fe);P.has(F)?P.delete(F):P.add(F),je(P)},Ce=()=>{fe.size===n.length&&n.length>0?je(new Set):je(new Set(n.map(F=>F.person_id)))},ze=()=>{if(fe.size===0){D({title:"未选择任何人物",description:"请先选择要删除的人物",variant:"destructive"});return}he(!0)},ge=async()=>{try{const F=await f2(Array.from(fe));D({title:"批量删除完成",description:F.message}),je(new Set),he(!1),J(),q()}catch(F){D({title:"批量删除失败",description:F instanceof Error?F.message:"批量删除失败",variant:"destructive"})}},ae=()=>{const F=parseInt(ve),P=Math.ceil(m/g);F>=1&&F<=P?(p(F),be("")):D({title:"无效的页码",description:`请输入1-${P}之间的页码`,variant:"destructive"})},re=F=>F?new Date(F*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(Lu,{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:A.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:A.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:A.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(C,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx(Mt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{id:"search",placeholder:"搜索名称、昵称或用户ID...",value:j,onChange:F=>y(F.target.value),className:"pl-9"})]})]}),e.jsxs("div",{children:[e.jsx(C,{htmlFor:"filter-known",children:"认识状态"}),e.jsxs(Ue,{value:N===void 0?"all":N.toString(),onValueChange:F=>{k(F==="all"?void 0:F==="true"),p(1)},children:[e.jsx(Oe,{id:"filter-known",className:"mt-1.5",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部"}),e.jsx(le,{value:"true",children:"已认识"}),e.jsx(le,{value:"false",children:"未认识"})]})]})]}),e.jsxs("div",{children:[e.jsx(C,{htmlFor:"filter-platform",children:"平台"}),e.jsxs(Ue,{value:w||"all",onValueChange:F=>{U(F==="all"?void 0:F),p(1)},children:[e.jsx(Oe,{id:"filter-platform",className:"mt-1.5",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部平台"}),me.map(F=>e.jsxs(le,{value:F,children:[F," (",A.platforms[F],")"]},F))]})]})]})]}),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:fe.size>0&&e.jsxs("span",{children:["已选择 ",fe.size," 个人物"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ue,{value:g.toString(),onValueChange:F=>{b(parseInt(F)),p(1),je(new Set)},children:[e.jsx(Oe,{id:"page-size",className:"w-20",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"10",children:"10"}),e.jsx(le,{value:"20",children:"20"}),e.jsx(le,{value:"50",children:"50"}),e.jsx(le,{value:"100",children:"100"})]})]}),fe.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>je(new Set),children:"取消选择"}),e.jsxs(S,{variant:"destructive",size:"sm",onClick:ze,children:[e.jsx(We,{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(rn,{children:[e.jsx(cn,{children:e.jsxs(ut,{children:[e.jsx(Xe,{className:"w-12",children:e.jsx(mt,{checked:n.length>0&&fe.size===n.length,onCheckedChange:Ce,"aria-label":"全选"})}),e.jsx(Xe,{children:"状态"}),e.jsx(Xe,{children:"名称"}),e.jsx(Xe,{children:"昵称"}),e.jsx(Xe,{children:"平台"}),e.jsx(Xe,{children:"用户ID"}),e.jsx(Xe,{children:"最后更新"}),e.jsx(Xe,{className:"text-right",children:"操作"})]})}),e.jsx(on,{children:i?e.jsx(ut,{children:e.jsx(Ve,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):n.length===0?e.jsx(ut,{children:e.jsx(Ve,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):n.map(F=>e.jsxs(ut,{children:[e.jsx(Ve,{children:e.jsx(mt,{checked:fe.has(F.person_id),onCheckedChange:()=>_e(F.person_id),"aria-label":`选择 ${F.person_name||F.nickname||F.user_id}`})}),e.jsx(Ve,{children:e.jsx("div",{className:$("inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium",F.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:F.is_known?"已认识":"未认识"})}),e.jsx(Ve,{className:"font-medium",children:F.person_name||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ve,{children:F.nickname||"-"}),e.jsx(Ve,{children:F.platform}),e.jsx(Ve,{className:"font-mono text-sm",children:F.user_id}),e.jsx(Ve,{className:"text-sm text-muted-foreground",children:re(F.last_know)}),e.jsx(Ve,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(S,{variant:"default",size:"sm",onClick:()=>se(F),children:[e.jsx(Rt,{className:"h-4 w-4 mr-1"}),"详情"]}),e.jsxs(S,{variant:"default",size:"sm",onClick:()=>R(F),children:[e.jsx(nn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsxs(S,{size:"sm",onClick:()=>T(F),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(We,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},F.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:i?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):n.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):n.map(F=>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(mt,{checked:fe.has(F.person_id),onCheckedChange:()=>_e(F.person_id),className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:$("inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium mb-2",F.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:F.is_known?"已认识":"未认识"}),e.jsx("h3",{className:"font-semibold text-sm line-clamp-1 w-full break-all",children:F.person_name||e.jsx("span",{className:"text-muted-foreground",children:"未命名"})}),F.nickname&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-1 w-full break-all",children:["昵称: ",F.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:F.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:F.user_id,children:F.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:re(F.last_know)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>se(F),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(Rt,{className:"h-3 w-3 mr-1"}),"查看"]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>R(F),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(nn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>T(F),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(We,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},F.id))}),m>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:["共 ",m," 条记录,第 ",f," / ",Math.ceil(m/g)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>p(1),disabled:f===1,className:"hidden sm:flex",children:e.jsx(lr,{className:"h-4 w-4"})}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>p(f-1),disabled:f===1,children:[e.jsx(il,{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:ve,onChange:F=>be(F.target.value),onKeyDown:F=>F.key==="Enter"&&ae(),placeholder:f.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(m/g)}),e.jsx(S,{variant:"outline",size:"sm",onClick:ae,disabled:!ve,className:"h-8",children:"跳转"})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>p(f+1),disabled:f>=Math.ceil(m/g),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Ba,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>p(Math.ceil(m/g)),disabled:f>=Math.ceil(m/g),className:"hidden sm:flex",children:e.jsx(nr,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(g2,{person:O,open:Y,onOpenChange:L}),e.jsx(j2,{person:O,open:z,onOpenChange:K,onSuccess:()=>{J(),q(),K(!1)}}),e.jsx(hs,{open:!!I,onOpenChange:()=>T(null),children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认删除"}),e.jsxs(cs,{children:['确定要删除人物信息 "',I?.person_name||I?.nickname||I?.user_id,'" 吗? 此操作不可撤销。']})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:()=>I&&ue(I),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(hs,{open:pe,onOpenChange:he,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"确认批量删除"}),e.jsxs(cs,{children:["确定要删除选中的 ",fe.size," 个人物信息吗? 此操作不可撤销。"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{children:"取消"}),e.jsx(os,{onClick:ge,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})})]})}function g2({person:n,open:r,onOpenChange:i}){if(!n)return null;const d=m=>m?new Date(m*1e3).toLocaleString("zh-CN"):"-";return e.jsx(qs,{open:r,onOpenChange:i,children:e.jsxs(Ls,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"人物详情"}),e.jsxs(Ps,{children:["查看 ",n.person_name||n.nickname||n.user_id," 的完整信息"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(ll,{icon:Qc,label:"人物名称",value:n.person_name}),e.jsx(ll,{icon:Rl,label:"昵称",value:n.nickname}),e.jsx(ll,{icon:sr,label:"用户ID",value:n.user_id,mono:!0}),e.jsx(ll,{icon:sr,label:"人物ID",value:n.person_id,mono:!0}),e.jsx(ll,{label:"平台",value:n.platform}),e.jsx(ll,{label:"状态",value:n.is_known?"已认识":"未认识"})]}),n.name_reason&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(C,{className:"text-xs text-muted-foreground",children:"名称设定原因"}),e.jsx("p",{className:"mt-1 text-sm",children:n.name_reason})]}),n.memory_points&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(C,{className:"text-xs text-muted-foreground",children:"个人印象"}),e.jsx("p",{className:"mt-1 text-sm whitespace-pre-wrap",children:n.memory_points})]}),n.group_nick_name&&n.group_nick_name.length>0&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(C,{className:"text-xs text-muted-foreground",children:"群昵称"}),e.jsx("div",{className:"mt-2 space-y-1",children:n.group_nick_name.map((m,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:m.group_id}),e.jsx("span",{children:"→"}),e.jsx("span",{children:m.group_nick_name})]},x))})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(ll,{icon:Pn,label:"认识时间",value:d(n.know_times)}),e.jsx(ll,{icon:Pn,label:"首次记录",value:d(n.know_since)}),e.jsx(ll,{icon:Pn,label:"最后更新",value:d(n.last_know)})]})]}),e.jsx(st,{children:e.jsx(S,{onClick:()=>i(!1),children:"关闭"})})]})})}function ll({icon:n,label:r,value:i,mono:d=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(C,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n&&e.jsx(n,{className:"h-3 w-3"}),r]}),e.jsx("div",{className:$("text-sm",d&&"font-mono",!i&&"text-muted-foreground"),children:i||"-"})]})}function j2({person:n,open:r,onOpenChange:i,onSuccess:d}){const[m,x]=u.useState({}),[f,p]=u.useState(!1),{toast:g}=$s();u.useEffect(()=>{n&&x({person_name:n.person_name||"",name_reason:n.name_reason||"",nickname:n.nickname||"",memory_points:n.memory_points||"",is_known:n.is_known})},[n]);const b=async()=>{if(n)try{p(!0),await m2(n.person_id,m),g({title:"保存成功",description:"人物信息已更新"}),d()}catch(j){g({title:"保存失败",description:j instanceof Error?j.message:"无法更新人物信息",variant:"destructive"})}finally{p(!1)}};return n?e.jsx(qs,{open:r,onOpenChange:i,children:e.jsxs(Ls,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"编辑人物信息"}),e.jsxs(Ps,{children:["修改 ",n.person_name||n.nickname||n.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(C,{htmlFor:"person_name",children:"人物名称"}),e.jsx(ie,{id:"person_name",value:m.person_name||"",onChange:j=>x({...m,person_name:j.target.value}),placeholder:"为这个人设置一个名称"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"nickname",children:"昵称"}),e.jsx(ie,{id:"nickname",value:m.nickname||"",onChange:j=>x({...m,nickname:j.target.value}),placeholder:"昵称"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"name_reason",children:"名称设定原因"}),e.jsx(Qs,{id:"name_reason",value:m.name_reason||"",onChange:j=>x({...m,name_reason:j.target.value}),placeholder:"为什么这样称呼这个人?",rows:2})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"memory_points",children:"个人印象"}),e.jsx(Qs,{id:"memory_points",value:m.memory_points||"",onChange:j=>x({...m,memory_points:j.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(C,{htmlFor:"is_known",className:"text-base font-medium",children:"已认识"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"标记是否已经认识这个人"})]}),e.jsx($e,{id:"is_known",checked:m.is_known,onCheckedChange:j=>x({...m,is_known:j})})]})]}),e.jsxs(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(S,{onClick:b,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}var v2=Zy();const vp=Ib(v2),Wu="/api/webui";async function b2(n=100,r="all"){const i=`${Wu}/knowledge/graph?limit=${n}&node_type=${r}`,d=await fetch(i);if(!d.ok)throw new Error(`获取知识图谱失败: ${d.status}`);return d.json()}async function N2(){const n=await fetch(`${Wu}/knowledge/stats`);if(!n.ok)throw new Error("获取知识图谱统计信息失败");return n.json()}async function y2(n){const r=await fetch(`${Wu}/knowledge/search?query=${encodeURIComponent(n)}`);if(!r.ok)throw new Error("搜索知识节点失败");return r.json()}const Kg=u.memo(({data:n})=>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(Ic,{type:"target",position:Yc.Top}),e.jsx("div",{className:"font-semibold text-white text-sm truncate max-w-[200px]",title:n.content,children:n.label}),e.jsx(Ic,{type:"source",position:Yc.Bottom})]}));Kg.displayName="EntityNode";const Xg=u.memo(({data:n})=>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(Ic,{type:"target",position:Yc.Top}),e.jsx("div",{className:"font-medium text-white text-xs truncate max-w-[150px]",title:n.content,children:n.label}),e.jsx(Ic,{type:"source",position:Yc.Bottom})]}));Xg.displayName="ParagraphNode";const w2={entity:Kg,paragraph:Xg};function _2(n,r){const i=new vp.graphlib.Graph;i.setDefaultEdgeLabel(()=>({})),i.setGraph({rankdir:"TB",ranksep:100,nodesep:80});const d=[],m=[];return n.forEach(x=>{i.setNode(x.id,{width:150,height:50})}),r.forEach(x=>{i.setEdge(x.source,x.target)}),vp.layout(i),n.forEach(x=>{const f=i.node(x.id);d.push({id:x.id,type:x.type,position:{x:f.x-75,y:f.y-25},data:{label:x.content.slice(0,20)+(x.content.length>20?"...":""),content:x.content}})}),r.forEach((x,f)=>{const p={id:`edge-${f}`,source:x.source,target:x.target,animated:n.length<=200&&x.weight>5,style:{strokeWidth:Math.min(x.weight/2,5),opacity:.6}};x.weight>10&&n.length<100&&(p.label=`${x.weight.toFixed(0)}`),m.push(p)}),{nodes:d,edges:m}}function S2(){const n=va(),[r,i]=u.useState(!1),[d,m]=u.useState(null),[x,f]=u.useState(""),[p,g]=u.useState("all"),[b,j]=u.useState(50),[y,N]=u.useState("50"),[k,w]=u.useState(!1),[U,O]=u.useState(!0),[B,Y]=u.useState(!1),[L,z]=u.useState(!1),[K,I,T]=Py([]),[A,te,fe]=Wy([]),[je,pe]=u.useState(0),[he,ve]=u.useState(null),[be,D]=u.useState(null),{toast:J}=$s(),q=u.useCallback(ge=>ge.type==="entity"?"#6366f1":ge.type==="paragraph"?"#10b981":"#6b7280",[]),se=u.useCallback(async(ge=!1)=>{try{if(!ge&&b>200){z(!0);return}i(!0);const[ae,re]=await Promise.all([b2(b,p),N2()]);if(m(re),ae.nodes.length===0){J({title:"提示",description:"知识库为空,请先导入知识数据"}),I([]),te([]);return}const{nodes:F,edges:P}=_2(ae.nodes,ae.edges);I(F),te(P),pe(F.length),re&&re.total_nodes>b&&J({title:"提示",description:`知识图谱包含 ${re.total_nodes} 个节点,当前显示 ${F.length} 个`}),J({title:"加载成功",description:`已加载 ${F.length} 个节点,${P.length} 条边`})}catch(ae){console.error("加载知识图谱失败:",ae),J({title:"加载失败",description:ae instanceof Error?ae.message:"未知错误",variant:"destructive"})}finally{i(!1)}},[b,p,J]),R=u.useCallback(async()=>{if(!x.trim()){J({title:"提示",description:"请输入搜索关键词"});return}try{const ge=await y2(x);if(ge.length===0){J({title:"未找到",description:"没有找到匹配的节点"});return}const ae=new Set(ge.map(re=>re.id));I(re=>re.map(F=>({...F,style:{...F.style,opacity:ae.has(F.id)?1:.3,filter:ae.has(F.id)?"brightness(1.2)":"brightness(0.8)"}}))),J({title:"搜索完成",description:`找到 ${ge.length} 个匹配节点`})}catch(ge){console.error("搜索失败:",ge),J({title:"搜索失败",description:ge instanceof Error?ge.message:"未知错误",variant:"destructive"})}},[x,J]),ue=u.useCallback(()=>{I(ge=>ge.map(ae=>({...ae,style:{...ae.style,opacity:1,filter:"brightness(1)"}})))},[]),me=u.useCallback(()=>{O(!1),Y(!0),se()},[se]),_e=u.useCallback(()=>{z(!1),setTimeout(()=>{se(!0)},0)},[se]),Ce=u.useCallback((ge,ae)=>{K.find(F=>F.id===ae.id)&&ve({id:ae.id,type:ae.type,content:ae.data.content})},[K]);u.useEffect(()=>{U||B&&se()},[b,p,U,B]);const ze=u.useCallback((ge,ae)=>{const re=K.find(Te=>Te.id===ae.source),F=K.find(Te=>Te.id===ae.target),P=A.find(Te=>Te.id===ae.id);re&&F&&P&&D({source:{id:re.id,type:re.type,content:re.data.content},target:{id:F.id,type:F.type,content:F.data.content},edge:{source:ae.source,target:ae.target,weight:parseFloat(ae.label||"0")}})},[K,A]);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:"可视化知识实体与关系网络"})]}),d&&e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(Qe,{variant:"outline",className:"gap-1",children:[e.jsx(Fc,{className:"h-3 w-3"}),"节点: ",d.total_nodes]}),e.jsxs(Qe,{variant:"outline",className:"gap-1",children:[e.jsx(jg,{className:"h-3 w-3"}),"边: ",d.total_edges]}),e.jsxs(Qe,{variant:"outline",className:"gap-1",children:[e.jsx(Ra,{className:"h-3 w-3"}),"实体: ",d.entity_nodes]}),e.jsxs(Qe,{variant:"outline",className:"gap-1",children:[e.jsx(Sa,{className:"h-3 w-3"}),"段落: ",d.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:ge=>f(ge.target.value),onKeyDown:ge=>ge.key==="Enter"&&R(),className:"flex-1"}),e.jsx(S,{onClick:R,size:"sm",children:e.jsx(Mt,{className:"h-4 w-4"})}),e.jsx(S,{onClick:ue,variant:"outline",size:"sm",children:"重置"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Ue,{value:p,onValueChange:ge=>g(ge),children:[e.jsx(Oe,{className:"w-[120px]",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部节点"}),e.jsx(le,{value:"entity",children:"仅实体"}),e.jsx(le,{value:"paragraph",children:"仅段落"})]})]}),e.jsxs(Ue,{value:b===1e4?"all":k?"custom":b.toString(),onValueChange:ge=>{ge==="custom"?(w(!0),N(b.toString())):ge==="all"?(w(!1),j(1e4)):(w(!1),j(Number(ge)))},children:[e.jsx(Oe,{className:"w-[120px]",children:e.jsx(Be,{})}),e.jsxs(Re,{children:[e.jsx(le,{value:"50",children:"50 节点"}),e.jsx(le,{value:"100",children:"100 节点"}),e.jsx(le,{value:"200",children:"200 节点"}),e.jsx(le,{value:"500",children:"500 节点"}),e.jsx(le,{value:"1000",children:"1000 节点"}),e.jsx(le,{value:"all",children:"全部 (最多10000)"}),e.jsx(le,{value:"custom",children:"自定义..."})]})]}),k&&e.jsx(ie,{type:"number",min:"50",value:y,onChange:ge=>N(ge.target.value),onBlur:()=>{const ge=parseInt(y);!isNaN(ge)&&ge>=50?j(ge):(N("50"),j(50))},onKeyDown:ge=>{if(ge.key==="Enter"){const ae=parseInt(y);!isNaN(ae)&&ae>=50?j(ae):(N("50"),j(50))}},placeholder:"最少50个",className:"w-[120px]"}),e.jsx(S,{onClick:()=>se(),variant:"outline",size:"sm",disabled:r,children:e.jsx(zt,{className:$("h-4 w-4",r&&"animate-spin")})})]})]})]}),e.jsx("div",{className:"flex-1 relative",children:r?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(zt,{className:"h-8 w-8 animate-spin mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"加载知识图谱中..."})]})}):K.length===0?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Fc,{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(e0,{nodes:K,edges:A,onNodesChange:T,onEdgesChange:fe,onNodeClick:Ce,onEdgeClick:ze,nodeTypes:w2,fitView:!0,minZoom:.05,maxZoom:1.5,defaultViewport:{x:0,y:0,zoom:.5},elevateNodesOnSelect:je<=500,nodesDraggable:je<=1e3,attributionPosition:"bottom-left",children:[e.jsx(s0,{variant:t0.Dots,gap:12,size:1}),e.jsx(a0,{}),je<=500&&e.jsx(l0,{nodeColor:q,nodeBorderRadius:8,pannable:!0,zoomable:!0}),e.jsxs(n0,{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:"段落节点"})]}),je>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:"已禁用动画"}),je>500&&e.jsx("div",{children:"已禁用缩略图"})]})]})]})]})}),e.jsx(qs,{open:!!he,onOpenChange:ge=>!ge&&ve(null),children:e.jsxs(Ls,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(Us,{children:e.jsx(Bs,{children:"节点详情"})}),he&&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(Qe,{variant:he.type==="entity"?"default":"secondary",children:he.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:he.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:he.content})})]})]})]})}),e.jsx(qs,{open:!!be,onOpenChange:ge=>!ge&&D(null),children:e.jsxs(Ls,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsx(Us,{children:e.jsx(Bs,{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(Qe,{variant:"outline",className:"text-base font-mono",children:be.edge.weight.toFixed(4)})})]})]})})]})}),e.jsx(hs,{open:U,onOpenChange:O,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"加载知识图谱"}),e.jsxs(cs,{children:["知识图谱的动态展示会消耗较多系统资源。",e.jsx("br",{}),"确定要加载知识图谱吗?"]})]}),e.jsxs(rs,{children:[e.jsx(ds,{onClick:()=>n({to:"/"}),children:"取消 (返回首页)"}),e.jsx(os,{onClick:me,children:"确认加载"})]})]})}),e.jsx(hs,{open:L,onOpenChange:z,children:e.jsxs(ls,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:"⚠️ 节点数量较多"}),e.jsx(cs,{asChild:!0,children:e.jsxs("div",{children:[e.jsxs("p",{children:["您正在尝试加载 ",e.jsx("strong",{className:"text-orange-600",children:b>=1e4?"全部 (最多10000个)":b})," 个节点。"]}),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(rs,{children:[e.jsx(ds,{onClick:()=>{z(!1),b>200&&(j(50),w(!1))},children:"取消"}),e.jsx(os,{onClick:_e,className:"bg-orange-600 hover:bg-orange-700",children:"我了解风险,继续加载"})]})]})})]})}function bp({className:n,classNames:r,showOutsideDays:i=!0,captionLayout:d="label",buttonVariant:m="ghost",formatters:x,components:f,...p}){const g=_g();return e.jsx(Dy,{showOutsideDays:i,className:$("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`,n),captionLayout:d,formatters:{formatMonthDropdown:b=>b.toLocaleString("default",{month:"short"}),...x},classNames:{root:$("w-fit",g.root),months:$("relative flex flex-col gap-4 md:flex-row",g.months),month:$("flex w-full flex-col gap-4",g.month),nav:$("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",g.nav),button_previous:$(ui({variant:m}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",g.button_previous),button_next:$(ui({variant:m}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",g.button_next),month_caption:$("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",g.month_caption),dropdowns:$("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",g.dropdowns),dropdown_root:$("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:$("bg-popover absolute inset-0 opacity-0",g.dropdown),caption_label:$("select-none font-medium",d==="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:$("flex",g.weekdays),weekday:$("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",g.weekday),week:$("mt-2 flex w-full",g.week),week_number_header:$("w-[--cell-size] select-none",g.week_number_header),week_number:$("text-muted-foreground select-none text-[0.8rem]",g.week_number),day:$("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:$("bg-accent rounded-l-md",g.range_start),range_middle:$("rounded-none",g.range_middle),range_end:$("bg-accent rounded-r-md",g.range_end),today:$("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",g.today),outside:$("text-muted-foreground aria-selected:text-muted-foreground",g.outside),disabled:$("text-muted-foreground opacity-50",g.disabled),hidden:$("invisible",g.hidden),...r},components:{Root:({className:b,rootRef:j,...y})=>e.jsx("div",{"data-slot":"calendar",ref:j,className:$(b),...y}),Chevron:({className:b,orientation:j,...y})=>j==="left"?e.jsx(il,{className:$("size-4",b),...y}):j==="right"?e.jsx(Ba,{className:$("size-4",b),...y}):e.jsx(Ll,{className:$("size-4",b),...y}),DayButton:C2,WeekNumber:({children:b,...j})=>e.jsx("td",{...j,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:b})}),...f},...p})}function C2({className:n,day:r,modifiers:i,...d}){const m=_g(),x=u.useRef(null);return u.useEffect(()=>{i.focused&&x.current?.focus()},[i.focused]),e.jsx(S,{ref:x,variant:"ghost",size:"icon","data-day":r.date.toLocaleDateString(),"data-selected-single":i.selected&&!i.range_start&&!i.range_end&&!i.range_middle,"data-range-start":i.range_start,"data-range-end":i.range_end,"data-range-middle":i.range_middle,className:$("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",m.day,n),...d})}const Lc={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 k2(){const[n,r]=u.useState([]),[i,d]=u.useState(""),[m,x]=u.useState("all"),[f,p]=u.useState("all"),[g,b]=u.useState(void 0),[j,y]=u.useState(void 0),[N,k]=u.useState(!0),[w,U]=u.useState(!1),[O,B]=u.useState("xs"),[Y,L]=u.useState(4),z=u.useRef(null);u.useEffect(()=>{const q=tn.getAllLogs();r(q);const se=tn.onLog(()=>{r(tn.getAllLogs())}),R=tn.onConnectionChange(ue=>{U(ue)});return()=>{se(),R()}},[]);const K=u.useMemo(()=>{const q=new Set(n.map(se=>se.module).filter(se=>se&&se.trim()!==""));return Array.from(q).sort()},[n]),I=q=>{switch(q){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"}},T=q=>{switch(q){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"}},A=()=>{window.location.reload()},te=()=>{tn.clearLogs(),r([])},fe=()=>{const q=he.map(me=>`${me.timestamp} [${me.level.padEnd(8)}] [${me.module}] ${me.message}`).join(` `),se=new Blob([q],{type:"text/plain;charset=utf-8"}),R=URL.createObjectURL(se),ue=document.createElement("a");ue.href=R,ue.download=`logs-${ju(new Date,"yyyy-MM-dd-HHmmss")}.txt`,ue.click(),URL.revokeObjectURL(R)},je=()=>{k(!N)},pe=()=>{b(void 0),y(void 0)},he=u.useMemo(()=>n.filter(q=>{const se=i===""||q.message.toLowerCase().includes(i.toLowerCase())||q.module.toLowerCase().includes(i.toLowerCase()),R=m==="all"||q.level===m,ue=f==="all"||q.module===f;let me=!0;if(g||j){const _e=new Date(q.timestamp);if(g){const Ce=new Date(g);Ce.setHours(0,0,0,0),me=me&&_e>=Ce}if(j){const Ce=new Date(j);Ce.setHours(23,59,59,999),me=me&&_e<=Ce}}return se&&R&&ue&&me}),[n,i,m,f,g,j]),ve=Lc[O].rowHeight+Y,be=Bb({count:he.length,getScrollElement:()=>z.current,estimateSize:()=>ve,overscan:50}),D=u.useRef(!1),J=u.useRef(he.length);return u.useEffect(()=>{const q=z.current;if(!q)return;const se=()=>{if(D.current)return;const{scrollTop:R,scrollHeight:ue,clientHeight:me}=q,_e=ue-R-me;_e>100&&N?k(!1):_e<50&&!N&&k(!0)};return q.addEventListener("scroll",se,{passive:!0}),()=>q.removeEventListener("scroll",se)},[N]),u.useEffect(()=>{const q=he.length>J.current;J.current=he.length,N&&he.length>0&&q&&(D.current=!0,be.scrollToIndex(he.length-1,{align:"end",behavior:"auto"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{D.current=!1})}))},[he.length,N,be]),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-shrink-0 space-y-4 p-3 sm:p-4 lg:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl sm:text-2xl lg:text-3xl font-bold",children:"日志查看器"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:"实时查看和分析麦麦运行日志"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:$("h-2.5 w-2.5 sm:h-3 sm:w-3 rounded-full",w?"bg-green-500 animate-pulse":"bg-red-500")}),e.jsx("span",{className:"text-xs sm:text-sm text-muted-foreground",children:w?"已连接":"未连接"})]})]}),e.jsx(Fe,{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:gap-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(Mt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"搜索日志...",value:i,onChange:q=>d(q.target.value),className:"pl-9 h-9 text-sm"})]}),e.jsxs(Ue,{value:m,onValueChange:x,children:[e.jsxs(Oe,{className:"w-full sm:w-[140px] lg:w-[180px] h-9 text-sm",children:[e.jsx(Ou,{className:"h-4 w-4 mr-2"}),e.jsx(Be,{placeholder:"级别"})]}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部级别"}),e.jsx(le,{value:"DEBUG",children:"DEBUG"}),e.jsx(le,{value:"INFO",children:"INFO"}),e.jsx(le,{value:"WARNING",children:"WARNING"}),e.jsx(le,{value:"ERROR",children:"ERROR"}),e.jsx(le,{value:"CRITICAL",children:"CRITICAL"})]})]}),e.jsxs(Ue,{value:f,onValueChange:p,children:[e.jsxs(Oe,{className:"w-full sm:w-[160px] lg:w-[200px] h-9 text-sm",children:[e.jsx(Ou,{className:"h-4 w-4 mr-2"}),e.jsx(Be,{placeholder:"模块"})]}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部模块"}),K.map(q=>e.jsx(le,{value:q,children:q},q))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-4",children:[e.jsxs(La,{children:[e.jsx(Ua,{asChild:!0,children:e.jsxs(S,{variant:"outline",size:"sm",className:$("w-full sm:w-[200px] lg:w-[240px] justify-start text-left font-normal h-9",!g&&"text-muted-foreground"),children:[e.jsx(Zf,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"text-xs sm:text-sm",children:g?ju(g,"PPP",{locale:Rc}):"开始日期"})]})}),e.jsx(ka,{className:"w-auto p-0",align:"start",children:e.jsx(bp,{mode:"single",selected:g,onSelect:b,initialFocus:!0,locale:Rc})})]}),e.jsxs(La,{children:[e.jsx(Ua,{asChild:!0,children:e.jsxs(S,{variant:"outline",size:"sm",className:$("w-full sm:w-[200px] lg:w-[240px] justify-start text-left font-normal h-9",!j&&"text-muted-foreground"),children:[e.jsx(Zf,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"text-xs sm:text-sm",children:j?ju(j,"PPP",{locale:Rc}):"结束日期"})]})}),e.jsx(ka,{className:"w-auto p-0",align:"start",children:e.jsx(bp,{mode:"single",selected:j,onSelect:y,initialFocus:!0,locale:Rc})})]}),(g||j)&&e.jsxs(S,{variant:"outline",size:"sm",onClick:pe,className:"w-full sm:w-auto h-9",children:[e.jsx(rl,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline text-sm",children:"清除时间筛选"}),e.jsx("span",{className:"sm:hidden text-sm",children:"清除"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center",children:[e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(S,{variant:N?"default":"outline",size:"sm",onClick:je,className:"flex-1 sm:flex-none h-9",children:[N?e.jsx(my,{className:"h-4 w-4"}):e.jsx(xy,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2 text-sm",children:N?"自动滚动":"已暂停"})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:A,className:"flex-1 sm:flex-none h-9",children:[e.jsx(zt,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2 text-sm",children:"刷新"})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:te,className:"flex-1 sm:flex-none h-9",children:[e.jsx(We,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2 text-sm",children:"清空"})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:fe,className:"flex-1 sm:flex-none h-9",children:[e.jsx(Oa,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2 text-sm",children:"导出"})]})]}),e.jsx("div",{className:"flex-1 hidden sm:block"}),e.jsxs("div",{className:"text-xs sm:text-sm text-muted-foreground flex items-center justify-center sm:justify-end",children:[e.jsxs("span",{className:"font-mono",children:[he.length," / ",n.length]}),e.jsx("span",{className:"ml-1",children:"条日志"})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-6 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(hy,{className:"h-4 w-4"}),e.jsx("span",{children:"字号"})]}),e.jsx("div",{className:"flex gap-1",children:Object.keys(Lc).map(q=>e.jsx(S,{variant:O===q?"default":"outline",size:"sm",onClick:()=>B(q),className:"h-7 px-3 text-xs",children:Lc[q].label},q))})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-1 max-w-xs",children:[e.jsx("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:"行距"}),e.jsx(pa,{value:[Y],onValueChange:([q])=>L(q),min:0,max:12,step:2,className:"flex-1"}),e.jsxs("span",{className:"text-xs text-muted-foreground w-8",children:[Y,"px"]})]})]})]})})]}),e.jsx("div",{className:"flex-1 min-h-0 px-3 sm:px-4 lg:px-6 pb-3 sm:pb-4 lg:pb-6",children:e.jsx(Fe,{className:"bg-black dark:bg-gray-950 border-gray-800 dark:border-gray-900 h-full overflow-hidden",children:e.jsx("div",{ref:z,className:$("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:$("p-2 sm:p-3 font-mono relative",Lc[O].class),style:{height:`${be.getTotalSize()}px`},children:he.length===0?e.jsx("div",{className:"text-gray-500 dark:text-gray-600 text-center py-8 text-sm",children:"暂无日志数据"}):be.getVirtualItems().map(q=>{const se=he[q.index];return e.jsxs("div",{"data-index":q.index,ref:be.measureElement,className:$("absolute top-0 left-0 w-full px-2 sm:px-3 rounded hover:bg-white/5 transition-colors group",T(se.level)),style:{transform:`translateY(${q.start}px)`,paddingTop:`${Y/2}px`,paddingBottom:`${Y/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",children:se.timestamp}),e.jsxs("span",{className:$("font-semibold",I(se.level)),children:["[",se.level,"]"]})]}),e.jsx("div",{className:"text-cyan-400 dark:text-cyan-500 truncate",children:se.module}),e.jsx("div",{className:"text-gray-300 dark:text-gray-400 whitespace-pre-wrap break-words",children:se.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:se.timestamp}),e.jsxs("span",{className:$("flex-shrink-0 w-[65px] lg:w-[75px] font-semibold",I(se.level)),children:["[",se.level,"]"]}),e.jsx("span",{className:"text-cyan-400 dark:text-cyan-500 flex-shrink-0 w-[100px] lg:w-[130px] truncate",children:se.module}),e.jsx("span",{className:"text-gray-300 dark:text-gray-400 flex-1 whitespace-pre-wrap break-words",children:se.message})]})]},q.key)})})})})})]})}const T2="Mai-with-u",E2="plugin-repo",z2="main",A2="plugin_details.json";async function M2(){try{const n=await Se("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:T2,repo:E2,branch:z2,file_path:A2})});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);const r=await n.json();if(!r.success||!r.data)throw new Error(r.error||"获取插件列表失败");return JSON.parse(r.data).filter(m=>!m?.id||!m?.manifest?(console.warn("跳过无效插件数据:",m),!1):!m.manifest.name||!m.manifest.version?(console.warn("跳过缺少必需字段的插件:",m.id),!1):!0).map(m=>({id:m.id,manifest:{manifest_version:m.manifest.manifest_version||1,name:m.manifest.name,version:m.manifest.version,description:m.manifest.description||"",author:m.manifest.author||{name:"Unknown"},license:m.manifest.license||"Unknown",host_application:m.manifest.host_application||{min_version:"0.0.0"},homepage_url:m.manifest.homepage_url,repository_url:m.manifest.repository_url,keywords:m.manifest.keywords||[],categories:m.manifest.categories||[],default_locale:m.manifest.default_locale||"zh-CN",locales_path:m.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!1,published_at:new Date().toISOString(),updated_at:new Date().toISOString()}))}catch(n){throw console.error("Failed to fetch plugin list:",n),n}}async function D2(){try{const n=await Se("/api/webui/plugins/git-status");if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){return console.error("Failed to check Git status:",n),{installed:!1,error:"无法检测 Git 安装状态"}}}async function O2(){try{const n=await Se("/api/webui/plugins/version");if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return await n.json()}catch(n){return console.error("Failed to get Maimai version:",n),{version:"0.0.0",version_major:0,version_minor:0,version_patch:0}}}function R2(n,r,i){const d=n.split(".").map(p=>parseInt(p)||0),m=d[0]||0,x=d[1]||0,f=d[2]||0;if(i.version_majorparseInt(y)||0),g=p[0]||0,b=p[1]||0,j=p[2]||0;if(i.version_major>g||i.version_major===g&&i.version_minor>b||i.version_major===g&&i.version_minor===b&&i.version_patch>j)return!1}return!0}function L2(n,r){const i=window.location.protocol==="https:"?"wss:":"ws:",d=window.location.host,m=new WebSocket(`${i}//${d}/api/webui/ws/plugin-progress`);return m.onopen=()=>{console.log("Plugin progress WebSocket connected");const x=setInterval(()=>{m.readyState===WebSocket.OPEN?m.send("ping"):clearInterval(x)},3e4)},m.onmessage=x=>{try{if(x.data==="pong")return;const f=JSON.parse(x.data);n(f)}catch(f){console.error("Failed to parse progress data:",f)}},m.onerror=x=>{console.error("Plugin progress WebSocket error:",x),r?.(x)},m.onclose=()=>{console.log("Plugin progress WebSocket disconnected")},m}async function li(){try{const n=await Se("/api/webui/plugins/installed",{headers:Gs()});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);const r=await n.json();if(!r.success)throw new Error(r.message||"获取已安装插件列表失败");return r.plugins||[]}catch(n){return console.error("Failed to get installed plugins:",n),[]}}function Uc(n,r){return r.some(i=>i.id===n)}function Bc(n,r){const i=r.find(d=>d.id===n);if(i)return i.manifest?.version||i.version}async function U2(n,r,i="main"){const d=await Se("/api/webui/plugins/install",{method:"POST",body:JSON.stringify({plugin_id:n,repository_url:r,branch:i})});if(!d.ok){const m=await d.json();throw new Error(m.detail||"安装失败")}return await d.json()}async function B2(n){const r=await Se("/api/webui/plugins/uninstall",{method:"POST",body:JSON.stringify({plugin_id:n})});if(!r.ok){const i=await r.json();throw new Error(i.detail||"卸载失败")}return await r.json()}async function H2(n,r,i="main"){const d=await Se("/api/webui/plugins/update",{method:"POST",body:JSON.stringify({plugin_id:n,repository_url:r,branch:i})});if(!d.ok){const m=await d.json();throw new Error(m.detail||"更新失败")}return await d.json()}async function q2(n){const r=await Se(`/api/webui/plugins/config/${n}/schema`,{headers:Gs()});if(!r.ok){const d=await r.json();throw new Error(d.detail||"获取配置 Schema 失败")}const i=await r.json();if(!i.success)throw new Error(i.message||"获取配置 Schema 失败");return i.schema}async function G2(n){const r=await Se(`/api/webui/plugins/config/${n}`,{headers:Gs()});if(!r.ok){const d=await r.json();throw new Error(d.detail||"获取配置失败")}const i=await r.json();if(!i.success)throw new Error(i.message||"获取配置失败");return i.config}async function $2(n,r){const i=await Se(`/api/webui/plugins/config/${n}`,{method:"PUT",body:JSON.stringify({config:r})});if(!i.ok){const d=await i.json();throw new Error(d.detail||"保存配置失败")}return await i.json()}async function F2(n){const r=await Se(`/api/webui/plugins/config/${n}/reset`,{method:"POST",headers:Gs()});if(!r.ok){const i=await r.json();throw new Error(i.detail||"重置配置失败")}return await r.json()}async function V2(n){const r=await Se(`/api/webui/plugins/config/${n}/toggle`,{method:"POST",headers:Gs()});if(!r.ok){const i=await r.json();throw new Error(i.detail||"切换状态失败")}return await r.json()}const pi="https://maibot-plugin-stats.maibot-webui.workers.dev";async function Jg(n){try{const r=await fetch(`${pi}/stats/${n}`);return r.ok?await r.json():(console.error("Failed to fetch plugin stats:",r.statusText),null)}catch(r){return console.error("Error fetching plugin stats:",r),null}}async function Q2(n,r){try{const i=r||em(),d=await fetch(`${pi}/stats/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:n,user_id:i})}),m=await d.json();return d.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:d.ok?{success:!0,...m}:{success:!1,error:m.error||"点赞失败"}}catch(i){return console.error("Error liking plugin:",i),{success:!1,error:"网络错误"}}}async function I2(n,r){try{const i=r||em(),d=await fetch(`${pi}/stats/dislike`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:n,user_id:i})}),m=await d.json();return d.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:d.ok?{success:!0,...m}:{success:!1,error:m.error||"点踩失败"}}catch(i){return console.error("Error disliking plugin:",i),{success:!1,error:"网络错误"}}}async function Y2(n,r,i,d){if(r<1||r>5)return{success:!1,error:"评分必须在 1-5 之间"};try{const m=d||em(),x=await fetch(`${pi}/stats/rate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:n,rating:r,comment:i,user_id:m})}),f=await x.json();return x.status===429?{success:!1,error:"每天最多评分 3 次"}:x.ok?{success:!0,...f}:{success:!1,error:f.error||"评分失败"}}catch(m){return console.error("Error rating plugin:",m),{success:!1,error:"网络错误"}}}async function K2(n){try{const r=await fetch(`${pi}/stats/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:n})}),i=await r.json();return r.status===429?(console.warn("Download recording rate limited"),{success:!0}):r.ok?{success:!0,...i}:(console.error("Failed to record download:",i.error),{success:!1,error:i.error})}catch(r){return console.error("Error recording download:",r),{success:!1,error:"网络错误"}}}function X2(){const n=navigator,r=[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,n.deviceMemory||0].join("|");let i=0;for(let d=0;d{x(!0);const B=await Jg(n);B&&d(B),x(!1)};u.useEffect(()=>{k()},[n]);const w=async()=>{const B=await Q2(n);B.success?(N({title:"已点赞",description:"感谢你的支持!"}),k()):N({title:"点赞失败",description:B.error||"未知错误",variant:"destructive"})},U=async()=>{const B=await I2(n);B.success?(N({title:"已反馈",description:"感谢你的反馈!"}),k()):N({title:"操作失败",description:B.error||"未知错误",variant:"destructive"})},O=async()=>{if(f===0){N({title:"请选择评分",description:"至少选择 1 颗星",variant:"destructive"});return}const B=await Y2(n,f,g||void 0);B.success?(N({title:"评分成功",description:"感谢你的评价!"}),y(!1),p(0),b(""),k()):N({title:"评分失败",description:B.error||"未知错误",variant:"destructive"})};return m?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(Oa,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(nl,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]})]}):i?r?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",title:`下载量: ${i.downloads.toLocaleString()}`,children:[e.jsx(Oa,{className:"h-4 w-4"}),e.jsx("span",{children:i.downloads.toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`评分: ${i.rating.toFixed(1)} (${i.rating_count} 条评价)`,children:[e.jsx(nl,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:i.rating.toFixed(1)})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`点赞数: ${i.likes}`,children:[e.jsx(bu,{className:"h-4 w-4"}),e.jsx("span",{children:i.likes})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Oa,{className:"h-5 w-5 text-muted-foreground mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.downloads.toLocaleString()}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"下载量"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(nl,{className:"h-5 w-5 text-yellow-400 mb-1 fill-yellow-400"}),e.jsx("span",{className:"text-2xl font-bold",children:i.rating.toFixed(1)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[i.rating_count," 条评价"]})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(bu,{className:"h-5 w-5 text-green-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.likes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点赞"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Pf,{className:"h-5 w-5 text-red-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.dislikes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点踩"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:w,children:[e.jsx(bu,{className:"h-4 w-4 mr-1"}),"点赞"]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:U,children:[e.jsx(Pf,{className:"h-4 w-4 mr-1"}),"点踩"]}),e.jsxs(qs,{open:j,onOpenChange:y,children:[e.jsx(Xu,{asChild:!0,children:e.jsxs(S,{variant:"default",size:"sm",children:[e.jsx(nl,{className:"h-4 w-4 mr-1"}),"评分"]})}),e.jsxs(Ls,{children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"为插件评分"}),e.jsx(Ps,{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(B=>e.jsx("button",{onClick:()=>p(B),className:"focus:outline-none",children:e.jsx(nl,{className:`h-8 w-8 transition-colors ${B<=f?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-yellow-300"}`})},B))}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[f===0&&"点击星星进行评分",f===1&&"很差",f===2&&"一般",f===3&&"还行",f===4&&"不错",f===5&&"非常好"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"评论(可选)"}),e.jsx(Qs,{value:g,onChange:B=>b(B.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(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>y(!1),children:"取消"}),e.jsx(S,{onClick:O,disabled:f===0,children:"提交评分"})]})]})]})]}),i.recent_ratings&&i.recent_ratings.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"最近评价"}),e.jsx("div",{className:"space-y-3",children:i.recent_ratings.map((B,Y)=>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(L=>e.jsx(nl,{className:`h-3 w-3 ${L<=B.rating?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},L))}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(B.created_at).toLocaleDateString()})]}),B.comment&&e.jsx("p",{className:"text-sm text-muted-foreground",children:B.comment})]},Y))})]})]}):null}const Np={"Group Management":"群组管理","Entertainment & Interaction":"娱乐互动","Utility Tools":"实用工具","Content Generation":"内容生成",Multimedia:"多媒体","External Integration":"外部集成","Data Analysis & Insights":"数据分析与洞察",Other:"其他"};function Z2(){const n=va(),[r,i]=u.useState(null),[d,m]=u.useState(""),[x,f]=u.useState("all"),[p,g]=u.useState("all"),[b,j]=u.useState(!0),[y,N]=u.useState([]),[k,w]=u.useState(!0),[U,O]=u.useState(null),[B,Y]=u.useState(null),[L,z]=u.useState(null),[K,I]=u.useState(null),[,T]=u.useState([]),[A,te]=u.useState({}),[fe,je]=u.useState(!1),[pe,he]=u.useState(null),[ve,be]=u.useState("main"),[D,J]=u.useState(""),[q,se]=u.useState("preset"),[R,ue]=u.useState(!1),{toast:me}=$s(),_e=async E=>{const xe=E.map(async Q=>{try{const Ne=await Jg(Q.id);return{id:Q.id,stats:Ne}}catch(Ne){return console.warn(`Failed to load stats for ${Q.id}:`,Ne),{id:Q.id,stats:null}}}),Ye=await Promise.all(xe),ke={};Ye.forEach(({id:Q,stats:Ne})=>{Ne&&(ke[Q]=Ne)}),te(ke)};u.useEffect(()=>{let E=null,xe=!1;return(async()=>{if(E=L2(ke=>{xe||(z(ke),ke.stage==="success"?setTimeout(()=>{xe||z(null)},2e3):ke.stage==="error"&&(w(!1),O(ke.error||"加载失败")))},ke=>{console.error("WebSocket error:",ke),xe||me({title:"WebSocket 连接失败",description:"无法实时显示加载进度",variant:"destructive"})}),await new Promise(ke=>{if(!E){ke();return}const Q=()=>{E&&E.readyState===WebSocket.OPEN?(console.log("WebSocket connected, starting to load plugins"),ke()):E&&E.readyState===WebSocket.CLOSED?(console.warn("WebSocket closed before loading plugins"),ke()):setTimeout(Q,100)};Q()}),!xe){const ke=await D2();Y(ke),ke.installed||me({title:"Git 未安装",description:ke.error||"请先安装 Git 才能使用插件安装功能",variant:"destructive"})}if(!xe){const ke=await O2();I(ke)}if(!xe)try{w(!0),O(null);const ke=await M2();if(!xe){const Q=await li();T(Q);const Ne=ke.map(qe=>{const Fs=Uc(qe.id,Q),ks=Bc(qe.id,Q);return{...qe,installed:Fs,installed_version:ks}});for(const qe of Q)!Ne.some(ks=>ks.id===qe.id)&&qe.manifest&&Ne.push({id:qe.id,manifest:{manifest_version:qe.manifest.manifest_version||1,name:qe.manifest.name,version:qe.manifest.version,description:qe.manifest.description||"",author:qe.manifest.author,license:qe.manifest.license||"Unknown",host_application:qe.manifest.host_application,homepage_url:qe.manifest.homepage_url,repository_url:qe.manifest.repository_url,keywords:qe.manifest.keywords||[],categories:qe.manifest.categories||[],default_locale:qe.manifest.default_locale||"zh-CN",locales_path:qe.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!0,installed_version:qe.manifest.version,published_at:new Date().toISOString(),updated_at:new Date().toISOString()});N(Ne),_e(Ne)}}catch(ke){if(!xe){const Q=ke instanceof Error?ke.message:"加载插件列表失败";O(Q),me({title:"加载失败",description:Q,variant:"destructive"})}}finally{xe||w(!1)}})(),()=>{xe=!0,E&&E.close()}},[me]);const Ce=E=>{if(!E.installed&&K&&!ze(E))return e.jsxs(Qe,{variant:"destructive",className:"gap-1",children:[e.jsx(At,{className:"h-3 w-3"}),"不兼容"]});if(E.installed){const xe=E.installed_version?.trim(),Ye=E.manifest.version?.trim();if(xe!==Ye){const ke=xe?.split(".").map(Number)||[0,0,0],Q=Ye?.split(".").map(Number)||[0,0,0];for(let Ne=0;Ne<3;Ne++){if((Q[Ne]||0)>(ke[Ne]||0))return e.jsxs(Qe,{variant:"outline",className:"gap-1 text-orange-600 border-orange-600",children:[e.jsx(At,{className:"h-3 w-3"}),"可更新"]});if((Q[Ne]||0)<(ke[Ne]||0))break}}return e.jsxs(Qe,{variant:"default",className:"gap-1",children:[e.jsx(aa,{className:"h-3 w-3"}),"已安装"]})}return null},ze=E=>!K||!E.manifest?.host_application?!0:R2(E.manifest.host_application.min_version,E.manifest.host_application.max_version,K),ge=E=>{if(!E.installed||!E.installed_version||!E.manifest?.version)return!1;const xe=E.installed_version.trim(),Ye=E.manifest.version.trim();if(xe===Ye)return!1;const ke=xe.split(".").map(Number),Q=Ye.split(".").map(Number);for(let Ne=0;Ne<3;Ne++){if((Q[Ne]||0)>(ke[Ne]||0))return!0;if((Q[Ne]||0)<(ke[Ne]||0))return!1}return!1},ae=y.filter(E=>{if(!E.manifest)return console.warn("[过滤] 跳过无 manifest 的插件:",E.id),!1;const xe=d===""||E.manifest.name?.toLowerCase().includes(d.toLowerCase())||E.manifest.description?.toLowerCase().includes(d.toLowerCase())||E.manifest.keywords&&E.manifest.keywords.some(Ne=>Ne.toLowerCase().includes(d.toLowerCase())),Ye=x==="all"||E.manifest.categories&&E.manifest.categories.includes(x);let ke=!0;p==="installed"?ke=E.installed===!0:p==="updates"&&(ke=E.installed===!0&&ge(E));const Q=!b||!K||ze(E);return xe&&Ye&&ke&&Q}),re=()=>{i(null)},F=E=>{if(!B?.installed){me({title:"无法安装",description:"Git 未安装",variant:"destructive"});return}if(K&&!ze(E)){me({title:"无法安装",description:"插件与当前麦麦版本不兼容",variant:"destructive"});return}he(E),be("main"),J(""),se("preset"),ue(!1),je(!0)},P=async()=>{if(!pe)return;const E=q==="custom"?D:ve;if(!E||E.trim()===""){me({title:"分支名称不能为空",variant:"destructive"});return}try{je(!1),await U2(pe.id,pe.manifest.repository_url||"",E),K2(pe.id).catch(Ye=>{console.warn("Failed to record download:",Ye)}),me({title:"安装成功",description:`${pe.manifest.name} 已成功安装`});const xe=await li();T(xe),N(Ye=>Ye.map(ke=>{if(ke.id===pe.id){const Q=Uc(ke.id,xe),Ne=Bc(ke.id,xe);return{...ke,installed:Q,installed_version:Ne}}return ke}))}catch(xe){me({title:"安装失败",description:xe instanceof Error?xe.message:"未知错误",variant:"destructive"})}finally{he(null)}},Te=async E=>{try{await B2(E.id),me({title:"卸载成功",description:`${E.manifest.name} 已成功卸载`});const xe=await li();T(xe),N(Ye=>Ye.map(ke=>{if(ke.id===E.id){const Q=Uc(ke.id,xe),Ne=Bc(ke.id,xe);return{...ke,installed:Q,installed_version:Ne}}return ke}))}catch(xe){me({title:"卸载失败",description:xe instanceof Error?xe.message:"未知错误",variant:"destructive"})}},Le=async E=>{if(!B?.installed){me({title:"无法更新",description:"Git 未安装",variant:"destructive"});return}try{const xe=await H2(E.id,E.manifest.repository_url||"","main");me({title:"更新成功",description:`${E.manifest.name} 已从 ${xe.old_version} 更新到 ${xe.new_version}`});const Ye=await li();T(Ye),N(ke=>ke.map(Q=>{if(Q.id===E.id){const Ne=Uc(Q.id,Ye),qe=Bc(Q.id,Ye);return{...Q,installed:Ne,installed_version:qe}}return Q}))}catch(xe){me({title:"更新失败",description:xe instanceof Error?xe.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(S,{onClick:()=>n({to:"/plugin-mirrors"}),children:[e.jsx(fy,{className:"h-4 w-4 mr-2"}),"配置镜像源"]})]}),B&&!B.installed&&e.jsxs(Fe,{className:"border-orange-600 bg-orange-50 dark:bg-orange-950/20",children:[e.jsx(ts,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ca,{className:"h-5 w-5 text-orange-600"}),e.jsxs("div",{children:[e.jsx(as,{className:"text-lg text-orange-900 dark:text-orange-100",children:"Git 未安装"}),e.jsx(et,{className:"text-orange-800 dark:text-orange-200",children:B.error||"请先安装 Git 才能使用插件安装功能"})]})]})}),e.jsx(xs,{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(Fe,{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(Mt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"搜索插件...",value:d,onChange:E=>m(E.target.value),className:"pl-9"})]}),e.jsxs(Ue,{value:x,onValueChange:f,children:[e.jsx(Oe,{className:"w-full sm:w-[200px]",children:e.jsx(Be,{placeholder:"选择分类"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"all",children:"全部分类"}),e.jsx(le,{value:"Group Management",children:"群组管理"}),e.jsx(le,{value:"Entertainment & Interaction",children:"娱乐互动"}),e.jsx(le,{value:"Utility Tools",children:"实用工具"}),e.jsx(le,{value:"Content Generation",children:"内容生成"}),e.jsx(le,{value:"Multimedia",children:"多媒体"}),e.jsx(le,{value:"External Integration",children:"外部集成"}),e.jsx(le,{value:"Data Analysis & Insights",children:"数据分析与洞察"}),e.jsx(le,{value:"Other",children:"其他"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(mt,{id:"compatible-only",checked:b,onCheckedChange:E=>j(E===!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(ga,{value:p,onValueChange:g,className:"w-full",children:e.jsxs(la,{className:"grid w-full grid-cols-3",children:[e.jsxs(ss,{value:"all",children:["全部插件 (",y.filter(E=>{if(!E.manifest)return!1;const xe=d===""||E.manifest.name?.toLowerCase().includes(d.toLowerCase())||E.manifest.description?.toLowerCase().includes(d.toLowerCase())||E.manifest.keywords&&E.manifest.keywords.some(Q=>Q.toLowerCase().includes(d.toLowerCase())),Ye=x==="all"||E.manifest.categories&&E.manifest.categories.includes(x),ke=!b||!K||ze(E);return xe&&Ye&&ke}).length,")"]}),e.jsxs(ss,{value:"installed",children:["已安装 (",y.filter(E=>{if(!E.manifest)return!1;const xe=d===""||E.manifest.name?.toLowerCase().includes(d.toLowerCase())||E.manifest.description?.toLowerCase().includes(d.toLowerCase())||E.manifest.keywords&&E.manifest.keywords.some(Q=>Q.toLowerCase().includes(d.toLowerCase())),Ye=x==="all"||E.manifest.categories&&E.manifest.categories.includes(x),ke=!b||!K||ze(E);return E.installed&&xe&&Ye&&ke}).length,")"]}),e.jsxs(ss,{value:"updates",children:["可更新 (",y.filter(E=>{if(!E.manifest)return!1;const xe=d===""||E.manifest.name?.toLowerCase().includes(d.toLowerCase())||E.manifest.description?.toLowerCase().includes(d.toLowerCase())||E.manifest.keywords&&E.manifest.keywords.some(Q=>Q.toLowerCase().includes(d.toLowerCase())),Ye=x==="all"||E.manifest.categories&&E.manifest.categories.includes(x),ke=!b||!K||ze(E);return E.installed&&ge(E)&&xe&&Ye&&ke}).length,")"]})]})}),L&&L.stage==="loading"&&e.jsx(Fe,{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(it,{className:"h-4 w-4 animate-spin"}),e.jsxs("span",{className:"text-sm font-medium",children:[L.operation==="fetch"&&"加载插件列表",L.operation==="install"&&`安装插件${L.plugin_id?`: ${L.plugin_id}`:""}`,L.operation==="uninstall"&&`卸载插件${L.plugin_id?`: ${L.plugin_id}`:""}`,L.operation==="update"&&`更新插件${L.plugin_id?`: ${L.plugin_id}`:""}`]})]}),e.jsxs("span",{className:"text-sm font-medium",children:[L.progress,"%"]})]}),e.jsx(rr,{value:L.progress,className:"h-2"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:L.message}),L.operation==="fetch"&&L.total_plugins>0&&e.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:["已加载 ",L.loaded_plugins," / ",L.total_plugins," 个插件"]})]})}),L&&L.stage==="error"&&L.error&&e.jsx(Fe,{className:"border-destructive bg-destructive/10",children:e.jsx(ts,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ca,{className:"h-5 w-5 text-destructive"}),e.jsxs("div",{children:[e.jsx(as,{className:"text-lg text-destructive",children:"加载失败"}),e.jsx(et,{className:"text-destructive/80",children:L.error})]})]})})}),k?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(it,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件列表中..."})]}):U?e.jsx(Fe,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Ca,{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:U}),e.jsx(S,{onClick:()=>window.location.reload(),children:"重新加载"})]})}):ae.length===0?e.jsx(Fe,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Mt,{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:d||x!=="all"?"尝试调整搜索条件或筛选器":"暂无可用插件"})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:ae.map(E=>e.jsxs(Fe,{className:"flex flex-col hover:shadow-lg transition-shadow h-full",children:[e.jsxs(ts,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx(as,{className:"text-xl",children:E.manifest?.name||E.id}),e.jsxs("div",{className:"flex flex-col gap-1",children:[E.manifest?.categories&&E.manifest.categories[0]&&e.jsx(Qe,{variant:"secondary",className:"text-xs whitespace-nowrap",children:Np[E.manifest.categories[0]]||E.manifest.categories[0]}),Ce(E)]})]}),e.jsx(et,{className:"line-clamp-2",children:E.manifest?.description||"无描述"})]}),e.jsx(xs,{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(Oa,{className:"h-4 w-4"}),e.jsx("span",{children:(A[E.id]?.downloads??E.downloads??0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(nl,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:(A[E.id]?.rating??E.rating??0).toFixed(1)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[E.manifest?.keywords&&E.manifest.keywords.slice(0,3).map(xe=>e.jsx(Qe,{variant:"outline",className:"text-xs",children:xe},xe)),E.manifest?.keywords&&E.manifest.keywords.length>3&&e.jsxs(Qe,{variant:"outline",className:"text-xs",children:["+",E.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",E.manifest?.version||"unknown"," · ",E.manifest?.author?.name||"Unknown"]}),E.manifest?.host_application&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:"支持:"}),e.jsxs("span",{className:"font-medium",children:[E.manifest.host_application.min_version,E.manifest.host_application.max_version?` - ${E.manifest.host_application.max_version}`:" - 最新版本"]})]})]})]})}),e.jsx(Sg,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center justify-end gap-2 w-full",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>i(E),children:"查看详情"}),E.installed?ge(E)?e.jsxs(S,{size:"sm",disabled:!B?.installed,title:B?.installed?void 0:"Git 未安装",onClick:()=>Le(E),children:[e.jsx(zt,{className:"h-4 w-4 mr-1"}),"更新"]}):e.jsxs(S,{variant:"destructive",size:"sm",disabled:!B?.installed,title:B?.installed?void 0:"Git 未安装",onClick:()=>Te(E),children:[e.jsx(We,{className:"h-4 w-4 mr-1"}),"卸载"]}):e.jsxs(S,{size:"sm",disabled:!B?.installed||L?.operation==="install"||K!==null&&!ze(E),title:B?.installed?K!==null&&!ze(E)?`不兼容当前版本 (需要 ${E.manifest?.host_application?.min_version||"未知"}${E.manifest?.host_application?.max_version?` - ${E.manifest.host_application.max_version}`:"+"},当前 ${K?.version})`:void 0:"Git 未安装",onClick:()=>F(E),children:[e.jsx(Oa,{className:"h-4 w-4 mr-1"}),L?.operation==="install"&&L?.plugin_id===E.id?"安装中...":"安装"]})]})})]},E.id))}),e.jsx(qs,{open:r!==null,onOpenChange:re,children:r&&r.manifest&&e.jsx(Ls,{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(Us,{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(Bs,{className:"text-2xl",children:r.manifest.name}),e.jsxs(Ps,{children:["作者: ",r.manifest.author?.name||"Unknown",r.manifest.author?.url&&e.jsx("a",{href:r.manifest.author.url,target:"_blank",rel:"noopener noreferrer",className:"ml-2 text-primary hover:underline",children:e.jsx(Hc,{className:"h-3 w-3 inline"})})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[r.manifest.categories&&r.manifest.categories[0]&&e.jsx(Qe,{variant:"secondary",children:Np[r.manifest.categories[0]]||r.manifest.categories[0]}),Ce(r)]})]})}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(J2,{pluginId:r.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",r.manifest?.version||"unknown"]}),r.installed&&r.installed_version&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["已安装: v",r.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:(A[r.id]?.downloads??r.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(nl,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(A[r.id]?.rating??r.rating??0).toFixed(1)," (",A[r.id]?.rating_count??r.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:r.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:[r.manifest.host_application?.min_version||"未知",r.manifest.host_application?.max_version?` - ${r.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:r.manifest.keywords&&r.manifest.keywords.map(E=>e.jsx(Qe,{variant:"outline",children:E},E))})]}),r.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:r.detailed_description})]}),!r.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:r.manifest.description||"无描述"})]}),e.jsxs("div",{className:"space-y-2",children:[r.manifest.homepage_url&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"主页: "}),e.jsx("a",{href:r.manifest.homepage_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:r.manifest.homepage_url})]}),r.manifest.repository_url&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"仓库: "}),e.jsx("a",{href:r.manifest.repository_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:r.manifest.repository_url})]})]})]}),e.jsxs(st,{children:[r.manifest.homepage_url&&e.jsxs(S,{onClick:()=>window.open(r.manifest.homepage_url,"_blank"),children:[e.jsx(Hc,{className:"h-4 w-4 mr-2"}),"访问主页"]}),r.manifest.repository_url&&e.jsxs(S,{variant:"outline",onClick:()=>window.open(r.manifest.repository_url,"_blank"),children:[e.jsx(Hc,{className:"h-4 w-4 mr-2"}),"查看仓库"]})]})]})})})}),e.jsx(qs,{open:fe,onOpenChange:je,children:e.jsxs(Ls,{children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"安装插件"}),e.jsxs(Ps,{children:["安装 ",pe?.manifest.name]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["版本: ",pe?.manifest.version]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["作者: ",typeof pe?.manifest.author=="string"?pe.manifest.author:pe?.manifest.author?.name]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(mt,{id:"advanced-options",checked:R,onCheckedChange:E=>ue(E)}),e.jsx("label",{htmlFor:"advanced-options",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"高级选项"})]}),R&&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(ga,{value:q,onValueChange:E=>se(E),children:[e.jsxs(la,{className:"grid w-full grid-cols-2",children:[e.jsx(ss,{value:"preset",className:"text-xs",children:"预设分支"}),e.jsx(ss,{value:"custom",className:"text-xs",children:"自定义分支"})]}),q==="preset"&&e.jsx("div",{className:"mt-3",children:e.jsxs(Ue,{value:ve,onValueChange:be,children:[e.jsx(Oe,{children:e.jsx(Be,{placeholder:"选择分支"})}),e.jsxs(Re,{children:[e.jsx(le,{value:"main",children:"main (默认)"}),e.jsx(le,{value:"master",children:"master"}),e.jsx(le,{value:"dev",children:"dev (开发版)"}),e.jsx(le,{value:"develop",children:"develop"}),e.jsx(le,{value:"beta",children:"beta (测试版)"}),e.jsx(le,{value:"stable",children:"stable (稳定版)"})]})]})}),q==="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:D,onChange:E=>J(E.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"输入 Git 分支名称、标签或提交哈希"})]})]})]})}),!R&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"将从默认分支 (main) 安装插件"})]}),e.jsxs(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>je(!1),children:"取消"}),e.jsxs(S,{onClick:P,children:[e.jsx(Oa,{className:"h-4 w-4 mr-2"}),"安装"]})]})]})})]})})}function P2(){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(vg,{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(Fe,{className:"max-w-2xl w-full border-dashed",children:[e.jsxs(ts,{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(Ol,{className:"h-16 w-16 text-muted-foreground"})}),e.jsx(as,{className:"text-2xl",children:"功能开发中"}),e.jsx(et,{className:"text-base",children:"模型分配预设市场功能正在开发中,敬请期待!"})]}),e.jsx(xs,{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:"根据使用场景智能推荐配置"})]})]})]})})]})})})]})}const qu=dN,Gu=uN,$u=mN;function W2({field:n,value:r,onChange:i}){const[d,m]=u.useState(!1);switch(n.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(C,{children:n.label}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]}),e.jsx($e,{checked:!!r,onCheckedChange:i,disabled:n.disabled})]});case"number":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:n.label}),e.jsx(ie,{type:"number",value:r??n.default,onChange:x=>i(parseFloat(x.target.value)||0),min:n.min,max:n.max,step:n.step??1,placeholder:n.placeholder,disabled:n.disabled}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]});case"slider":return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(C,{children:n.label}),e.jsx("span",{className:"text-sm text-muted-foreground",children:r??n.default})]}),e.jsx(pa,{value:[r??n.default],onValueChange:x=>i(x[0]),min:n.min??0,max:n.max??100,step:n.step??1,disabled:n.disabled}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]});case"select":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:n.label}),e.jsxs(Ue,{value:String(r??n.default),onValueChange:i,disabled:n.disabled,children:[e.jsx(Oe,{children:e.jsx(Be,{placeholder:n.placeholder??"请选择"})}),e.jsx(Re,{children:n.choices?.map(x=>e.jsx(le,{value:String(x),children:String(x)},String(x)))})]}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]});case"textarea":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:n.label}),e.jsx(Qs,{value:r??n.default,onChange:x=>i(x.target.value),placeholder:n.placeholder,rows:n.rows??3,disabled:n.disabled}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]});case"password":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:n.label}),e.jsxs("div",{className:"relative",children:[e.jsx(ie,{type:d?"text":"password",value:r??"",onChange:x=>i(x.target.value),placeholder:n.placeholder,disabled:n.disabled,className:"pr-10"}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3",onClick:()=>m(!d),children:d?e.jsx(ci,{className:"h-4 w-4"}):e.jsx(Rt,{className:"h-4 w-4"})})]}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]});case"text":default:return e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:n.label}),e.jsx(ie,{type:"text",value:r??n.default??"",onChange:x=>i(x.target.value),placeholder:n.placeholder,maxLength:n.max_length,disabled:n.disabled}),n.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n.hint})]})}}function yp({section:n,config:r,onChange:i}){const[d,m]=u.useState(!n.collapsed),x=Object.entries(n.fields).filter(([,f])=>!f.hidden).sort(([,f],[,p])=>f.order-p.order);return e.jsx(qu,{open:d,onOpenChange:m,children:e.jsxs(Fe,{children:[e.jsx(Gu,{asChild:!0,children:e.jsxs(ts,{className:"cursor-pointer hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d?e.jsx(Ll,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Ba,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(as,{className:"text-lg",children:n.title})]}),e.jsxs(Qe,{variant:"secondary",className:"text-xs",children:[x.length," 项"]})]}),n.description&&e.jsx(et,{className:"ml-6",children:n.description})]})}),e.jsx($u,{children:e.jsx(xs,{className:"space-y-4 pt-0",children:x.map(([f,p])=>e.jsx(W2,{field:p,value:r[n.name]?.[f],onChange:g=>i(n.name,f,g),sectionName:n.name},f))})})]})})}function e_({plugin:n,onBack:r}){const{toast:i}=$s(),[d,m]=u.useState(null),[x,f]=u.useState({}),[p,g]=u.useState({}),[b,j]=u.useState(!0),[y,N]=u.useState(!1),[k,w]=u.useState(!1),[U,O]=u.useState(!1),B=u.useCallback(async()=>{j(!0);try{const[A,te]=await Promise.all([q2(n.id),G2(n.id)]);m(A),f(te),g(JSON.parse(JSON.stringify(te)))}catch(A){i({title:"加载配置失败",description:A instanceof Error?A.message:"未知错误",variant:"destructive"})}finally{j(!1)}},[n.id,i]);u.useEffect(()=>{B()},[B]),u.useEffect(()=>{w(JSON.stringify(x)!==JSON.stringify(p))},[x,p]);const Y=(A,te,fe)=>{f(je=>({...je,[A]:{...je[A]||{},[te]:fe}}))},L=async()=>{N(!0);try{await $2(n.id,x),g(JSON.parse(JSON.stringify(x))),i({title:"配置已保存",description:"更改将在插件重新加载后生效"})}catch(A){i({title:"保存失败",description:A instanceof Error?A.message:"未知错误",variant:"destructive"})}finally{N(!1)}},z=async()=>{try{await F2(n.id),i({title:"配置已重置",description:"下次加载插件时将使用默认配置"}),O(!1),B()}catch(A){i({title:"重置失败",description:A instanceof Error?A.message:"未知错误",variant:"destructive"})}},K=async()=>{try{const A=await V2(n.id);i({title:A.message,description:A.note}),B()}catch(A){i({title:"切换状态失败",description:A instanceof Error?A.message:"未知错误",variant:"destructive"})}};if(b)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(it,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!d)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 space-y-4",children:[e.jsx(At,{className:"h-12 w-12 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"无法加载配置"}),e.jsxs(S,{onClick:r,variant:"outline",children:[e.jsx(er,{className:"h-4 w-4 mr-2"}),"返回"]})]});const I=Object.values(d.sections).sort((A,te)=>A.order-te.order),T=x.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(S,{variant:"ghost",size:"icon",onClick:r,children:e.jsx(er,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:d.plugin_info.name||n.manifest.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(Qe,{variant:T?"default":"secondary",children:T?"已启用":"已禁用"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["v",d.plugin_info.version||n.manifest.version]})]})]})]}),e.jsxs("div",{className:"flex gap-2 ml-10 sm:ml-0",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:K,children:[e.jsx(hi,{className:"h-4 w-4 mr-2"}),T?"禁用":"启用"]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>O(!0),children:[e.jsx($c,{className:"h-4 w-4 mr-2"}),"重置"]}),e.jsxs(S,{size:"sm",onClick:L,disabled:!k||y,children:[y?e.jsx(it,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(fi,{className:"h-4 w-4 mr-2"}),"保存"]})]})]}),k&&e.jsx(Fe,{className:"border-orange-200 bg-orange-50 dark:bg-orange-950/20 dark:border-orange-900",children:e.jsx(xs,{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:"有未保存的更改"})]})})}),d.layout.type==="tabs"&&d.layout.tabs.length>0?e.jsxs(ga,{defaultValue:d.layout.tabs[0]?.id,children:[e.jsx(la,{children:d.layout.tabs.map(A=>e.jsxs(ss,{value:A.id,children:[A.title,A.badge&&e.jsx(Qe,{variant:"secondary",className:"ml-2 text-xs",children:A.badge})]},A.id))}),d.layout.tabs.map(A=>e.jsx(Ts,{value:A.id,className:"space-y-4 mt-4",children:A.sections.map(te=>{const fe=d.sections[te];return fe?e.jsx(yp,{section:fe,config:x,onChange:Y},te):null})},A.id))]}):e.jsx("div",{className:"space-y-4",children:I.map(A=>e.jsx(yp,{section:A,config:x,onChange:Y},A.name))}),e.jsx(qs,{open:U,onOpenChange:O,children:e.jsxs(Ls,{children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"确认重置配置"}),e.jsx(Ps,{children:"这将删除当前配置文件,下次加载插件时将使用默认配置。此操作不可撤销。"})]}),e.jsxs(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>O(!1),children:"取消"}),e.jsx(S,{variant:"destructive",onClick:z,children:"确认重置"})]})]})})]})}function s_(){const{toast:n}=$s(),[r,i]=u.useState([]),[d,m]=u.useState(!0),[x,f]=u.useState(""),[p,g]=u.useState(null),b=async()=>{m(!0);try{const k=await li();i(k)}catch(k){n({title:"加载插件列表失败",description:k instanceof Error?k.message:"未知错误",variant:"destructive"})}finally{m(!1)}};u.useEffect(()=>{b()},[]);const j=r.filter(k=>{const w=x.toLowerCase();return k.id.toLowerCase().includes(w)||k.manifest.name.toLowerCase().includes(w)||k.manifest.description?.toLowerCase().includes(w)}),y=r.length,N=0;return p?e.jsx(Ze,{className:"h-full",children:e.jsx("div",{className:"p-4 sm:p-6",children:e.jsx(e_,{plugin:p,onBack:()=>g(null)})})}):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(S,{variant:"outline",size:"sm",onClick:b,children:[e.jsx(zt,{className:`h-4 w-4 mr-2 ${d?"animate-spin":""}`}),"刷新"]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 xs:grid-cols-2 lg:grid-cols-3",children:[e.jsxs(Fe,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(as,{className:"text-sm font-medium",children:"已安装插件"}),e.jsx(Ol,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(xs,{children:[e.jsx("div",{className:"text-2xl font-bold",children:r.length}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:d?"正在加载...":"个插件"})]})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(as,{className:"text-sm font-medium",children:"已启用"}),e.jsx(aa,{className:"h-4 w-4 text-green-600"})]}),e.jsxs(xs,{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(Fe,{children:[e.jsxs(ts,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(as,{className:"text-sm font-medium",children:"已禁用"}),e.jsx(At,{className:"h-4 w-4 text-orange-600"})]}),e.jsxs(xs,{children:[e.jsx("div",{className:"text-2xl font-bold",children:N}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"未激活的插件"})]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Mt,{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:k=>f(k.target.value),className:"pl-9"})]}),e.jsxs(Fe,{children:[e.jsxs(ts,{children:[e.jsx(as,{children:"已安装的插件"}),e.jsx(et,{children:"点击插件查看和编辑配置"})]}),e.jsx(xs,{children:d?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(it,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):j.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 space-y-4",children:[e.jsx(Ol,{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:j.map(k=>e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg border hover:bg-muted/50 cursor-pointer transition-colors",onClick:()=>g(k),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(Ol,{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:k.manifest.name}),e.jsxs(Qe,{variant:"secondary",className:"text-xs flex-shrink-0",children:["v",k.manifest.version]})]}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:k.manifest.description||"暂无描述"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(S,{variant:"ghost",size:"sm",children:e.jsx(ar,{className:"h-4 w-4"})}),e.jsx(Ba,{className:"h-4 w-4 text-muted-foreground"})]})]},k.id))})})]})]})})}function t_(){const n=va(),{toast:r}=$s(),[i,d]=u.useState([]),[m,x]=u.useState(!0),[f,p]=u.useState(null),[g,b]=u.useState(null),[j,y]=u.useState(!1),[N,k]=u.useState(!1),[w,U]=u.useState({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),O=u.useCallback(async()=>{try{x(!0),p(null);const T=localStorage.getItem("access-token"),A=await fetch("/api/webui/plugins/mirrors",{headers:{Authorization:`Bearer ${T}`}});if(!A.ok)throw new Error("获取镜像源列表失败");const te=await A.json();d(te.mirrors||[])}catch(T){const A=T instanceof Error?T.message:"加载镜像源失败";p(A),r({title:"加载失败",description:A,variant:"destructive"})}finally{x(!1)}},[r]);u.useEffect(()=>{O()},[O]);const B=async()=>{try{const T=localStorage.getItem("access-token"),A=await fetch("/api/webui/plugins/mirrors",{method:"POST",headers:{Authorization:`Bearer ${T}`,"Content-Type":"application/json"},body:JSON.stringify(w)});if(!A.ok){const te=await A.json();throw new Error(te.detail||"添加镜像源失败")}r({title:"添加成功",description:"镜像源已添加"}),y(!1),U({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),O()}catch(T){r({title:"添加失败",description:T instanceof Error?T.message:"未知错误",variant:"destructive"})}},Y=async()=>{if(g)try{const T=localStorage.getItem("access-token");if(!(await fetch(`/api/webui/plugins/mirrors/${g.id}`,{method:"PUT",headers:{Authorization:`Bearer ${T}`,"Content-Type":"application/json"},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("更新镜像源失败");r({title:"更新成功",description:"镜像源已更新"}),k(!1),b(null),O()}catch(T){r({title:"更新失败",description:T instanceof Error?T.message:"未知错误",variant:"destructive"})}},L=async T=>{if(confirm("确定要删除这个镜像源吗?"))try{const A=localStorage.getItem("access-token");if(!(await fetch(`/api/webui/plugins/mirrors/${T}`,{method:"DELETE",headers:{Authorization:`Bearer ${A}`}})).ok)throw new Error("删除镜像源失败");r({title:"删除成功",description:"镜像源已删除"}),O()}catch(A){r({title:"删除失败",description:A instanceof Error?A.message:"未知错误",variant:"destructive"})}},z=async T=>{try{const A=localStorage.getItem("access-token");if(!(await fetch(`/api/webui/plugins/mirrors/${T.id}`,{method:"PUT",headers:{Authorization:`Bearer ${A}`,"Content-Type":"application/json"},body:JSON.stringify({enabled:!T.enabled})})).ok)throw new Error("更新状态失败");O()}catch(A){r({title:"更新失败",description:A instanceof Error?A.message:"未知错误",variant:"destructive"})}},K=T=>{b(T),U({id:T.id,name:T.name,raw_prefix:T.raw_prefix,clone_prefix:T.clone_prefix,enabled:T.enabled,priority:T.priority}),k(!0)},I=async(T,A)=>{const te=A==="up"?T.priority-1:T.priority+1;if(!(te<1))try{const fe=localStorage.getItem("access-token");if(!(await fetch(`/api/webui/plugins/mirrors/${T.id}`,{method:"PUT",headers:{Authorization:`Bearer ${fe}`,"Content-Type":"application/json"},body:JSON.stringify({priority:te})})).ok)throw new Error("更新优先级失败");O()}catch(fe){r({title:"更新失败",description:fe instanceof Error?fe.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(S,{variant:"ghost",size:"icon",onClick:()=>n({to:"/plugins"}),children:e.jsx(er,{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(S,{onClick:()=>y(!0),children:[e.jsx(dt,{className:"h-4 w-4 mr-2"}),"添加镜像源"]})]}),m?e.jsx(Fe,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(it,{className:"h-8 w-8 animate-spin text-primary"})})}):f?e.jsx(Fe,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Ca,{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:f}),e.jsx(S,{onClick:O,children:"重新加载"})]})}):e.jsxs(Fe,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(rn,{children:[e.jsx(cn,{children:e.jsxs(ut,{children:[e.jsx(Xe,{children:"状态"}),e.jsx(Xe,{children:"名称"}),e.jsx(Xe,{children:"ID"}),e.jsx(Xe,{children:"优先级"}),e.jsx(Xe,{className:"text-right",children:"操作"})]})}),e.jsx(on,{children:i.map(T=>e.jsxs(ut,{children:[e.jsx(Ve,{children:e.jsx($e,{checked:T.enabled,onCheckedChange:()=>z(T)})}),e.jsx(Ve,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:T.name}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Raw: ",T.raw_prefix]})]})}),e.jsx(Ve,{children:e.jsx(Qe,{variant:"outline",children:T.id})}),e.jsx(Ve,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono",children:T.priority}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>I(T,"up"),disabled:T.priority===1,children:e.jsx(di,{className:"h-3 w-3"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>I(T,"down"),children:e.jsx(Ll,{className:"h-3 w-3"})})]})]})}),e.jsx(Ve,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(S,{variant:"ghost",size:"icon",onClick:()=>K(T),children:e.jsx(ln,{className:"h-4 w-4"})}),e.jsx(S,{variant:"ghost",size:"icon",onClick:()=>L(T.id),children:e.jsx(We,{className:"h-4 w-4 text-destructive"})})]})})]},T.id))})]})}),e.jsx("div",{className:"md:hidden p-4 space-y-4",children:i.map(T=>e.jsx(Fe,{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:T.name}),T.enabled&&e.jsx(Qe,{variant:"default",className:"text-xs",children:"启用"})]}),e.jsx(Qe,{variant:"outline",className:"mt-1 text-xs",children:T.id})]}),e.jsx($e,{checked:T.enabled,onCheckedChange:()=>z(T)})]}),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:T.raw_prefix})]}),e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"优先级: "}),e.jsx("span",{className:"font-mono",children:T.priority})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t",children:[e.jsxs(S,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>K(T),children:[e.jsx(ln,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>I(T,"up"),disabled:T.priority===1,children:e.jsx(di,{className:"h-4 w-4"})}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>I(T,"down"),children:e.jsx(Ll,{className:"h-4 w-4"})}),e.jsx(S,{variant:"destructive",size:"sm",onClick:()=>L(T.id),children:e.jsx(We,{className:"h-4 w-4"})})]})]})},T.id))})]}),e.jsx(qs,{open:j,onOpenChange:y,children:e.jsxs(Ls,{className:"max-w-lg",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"添加镜像源"}),e.jsx(Ps,{children:"添加新的 Git 镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"add-id",children:"镜像源 ID *"}),e.jsx(ie,{id:"add-id",placeholder:"例如: my-mirror",value:w.id,onChange:T=>U({...w,id:T.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"add-name",children:"名称 *"}),e.jsx(ie,{id:"add-name",placeholder:"例如: 我的镜像源",value:w.name,onChange:T=>U({...w,name:T.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"add-raw",children:"Raw 文件前缀 *"}),e.jsx(ie,{id:"add-raw",placeholder:"https://example.com/raw",value:w.raw_prefix,onChange:T=>U({...w,raw_prefix:T.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"add-clone",children:"克隆前缀 *"}),e.jsx(ie,{id:"add-clone",placeholder:"https://example.com/clone",value:w.clone_prefix,onChange:T=>U({...w,clone_prefix:T.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"add-priority",children:"优先级"}),e.jsx(ie,{id:"add-priority",type:"number",min:"1",value:w.priority,onChange:T=>U({...w,priority:parseInt(T.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($e,{id:"add-enabled",checked:w.enabled,onCheckedChange:T=>U({...w,enabled:T})}),e.jsx(C,{htmlFor:"add-enabled",children:"启用此镜像源"})]})]}),e.jsxs(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>y(!1),children:"取消"}),e.jsx(S,{onClick:B,children:"添加"})]})]})}),e.jsx(qs,{open:N,onOpenChange:k,children:e.jsxs(Ls,{className:"max-w-lg",children:[e.jsxs(Us,{children:[e.jsx(Bs,{children:"编辑镜像源"}),e.jsx(Ps,{children:"修改镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"镜像源 ID"}),e.jsx(ie,{value:w.id,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"edit-name",children:"名称 *"}),e.jsx(ie,{id:"edit-name",value:w.name,onChange:T=>U({...w,name:T.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"edit-raw",children:"Raw 文件前缀 *"}),e.jsx(ie,{id:"edit-raw",value:w.raw_prefix,onChange:T=>U({...w,raw_prefix:T.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"edit-clone",children:"克隆前缀 *"}),e.jsx(ie,{id:"edit-clone",value:w.clone_prefix,onChange:T=>U({...w,clone_prefix:T.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"edit-priority",children:"优先级"}),e.jsx(ie,{id:"edit-priority",type:"number",min:"1",value:w.priority,onChange:T=>U({...w,priority:parseInt(T.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($e,{id:"edit-enabled",checked:w.enabled,onCheckedChange:T=>U({...w,enabled:T})}),e.jsx(C,{htmlFor:"edit-enabled",children:"启用此镜像源"})]})]}),e.jsxs(st,{children:[e.jsx(S,{variant:"outline",onClick:()=>k(!1),children:"取消"}),e.jsx(S,{onClick:Y,children:"保存"})]})]})})]})})}const ni=u.forwardRef(({className:n,...r},i)=>e.jsx(Gp,{ref:i,className:$("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",n),...r}));ni.displayName=Gp.displayName;const a_=u.forwardRef(({className:n,...r},i)=>e.jsx($p,{ref:i,className:$("aspect-square h-full w-full",n),...r}));a_.displayName=$p.displayName;const ri=u.forwardRef(({className:n,...r},i)=>e.jsx(Fp,{ref:i,className:$("flex h-full w-full items-center justify-center rounded-full bg-muted",n),...r}));ri.displayName=Fp.displayName;function l_(){return"webui_"+Math.random().toString(36).substr(2,9)+"_"+Date.now().toString(36)}function n_(){const n="maibot_webui_user_id";let r=localStorage.getItem(n);return r||(r=l_(),localStorage.setItem(n,r)),r}function r_(){return localStorage.getItem("maibot_webui_user_name")||"WebUI用户"}function i_(n){localStorage.setItem("maibot_webui_user_name",n)}const Zg="maibot_webui_virtual_tabs";function c_(){try{const n=localStorage.getItem(Zg);if(n)return JSON.parse(n)}catch(n){console.error("[Chat] 加载虚拟标签页失败:",n)}return[]}function wp(n){try{localStorage.setItem(Zg,JSON.stringify(n))}catch(r){console.error("[Chat] 保存虚拟标签页失败:",r)}}function o_({segment:n}){switch(n.type){case"text":return e.jsx("span",{className:"whitespace-pre-wrap",children:String(n.data)});case"image":case"emoji":return e.jsx("img",{src:String(n.data),alt:n.type==="emoji"?"表情包":"图片",className:$("rounded-lg max-w-full",n.type==="emoji"?"max-h-32":"max-h-64"),loading:"lazy",onError:r=>{const i=r.target;i.style.display="none",i.parentElement?.insertAdjacentHTML("beforeend",`[${n.type==="emoji"?"表情包":"图片"}加载失败]`)}});case"voice":return e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("audio",{controls:!0,src:String(n.data),className:"max-w-[200px] h-8",children:"您的浏览器不支持音频播放"})});case"video":return e.jsx("video",{controls:!0,src:String(n.data),className:"rounded-lg max-w-full max-h-64",children:"您的浏览器不支持视频播放"});case"face":return e.jsxs("span",{className:"text-muted-foreground",children:["[表情:",String(n.data),"]"]});case"music":return e.jsx("span",{className:"text-muted-foreground",children:"[音乐分享]"});case"file":return e.jsxs("span",{className:"text-muted-foreground",children:["[文件: ",String(n.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:["[",n.original_type||"未知消息","]"]})}}function d_({message:n,isBot:r}){return n.message_type==="rich"&&n.segments&&n.segments.length>0?e.jsx("div",{className:"flex flex-col gap-2",children:n.segments.map((i,d)=>e.jsx(o_,{segment:i},d))}):e.jsx("span",{className:"whitespace-pre-wrap",children:n.content})}function u_(){const n={id:"webui-default",type:"webui",label:"WebUI",messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}},r=()=>{const He=c_().map(De=>{const Ke=De.virtualConfig;return!Ke.groupId&&Ke.platform&&Ke.userId&&(Ke.groupId=`webui_virtual_group_${Ke.platform}_${Ke.userId}`),{id:De.id,type:"virtual",label:De.label,virtualConfig:Ke,messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}}});return[n,...He]},[i,d]=u.useState(r),[m,x]=u.useState("webui-default"),f=i.find(X=>X.id===m)||i[0],[p,g]=u.useState(""),[b,j]=u.useState(!1),[y,N]=u.useState(!0),[k,w]=u.useState(r_()),[U,O]=u.useState(!1),[B,Y]=u.useState(""),[L,z]=u.useState(!1),[K,I]=u.useState([]),[T,A]=u.useState([]),[te,fe]=u.useState(!1),[je,pe]=u.useState(!1),[he,ve]=u.useState(""),[be,D]=u.useState({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),J=u.useRef(n_()),q=u.useRef(new Map),se=u.useRef(null),R=u.useRef(new Map),ue=u.useRef(0),me=u.useRef(new Map),{toast:_e}=$s(),Ce=X=>(ue.current+=1,`${X}-${Date.now()}-${ue.current}-${Math.random().toString(36).substr(2,9)}`),ze=u.useCallback((X,He)=>{d(De=>De.map(Ke=>Ke.id===X?{...Ke,...He}:Ke))},[]),ge=u.useCallback((X,He)=>{d(De=>De.map(Ke=>Ke.id===X?{...Ke,messages:[...Ke.messages,He]}:Ke))},[]),ae=u.useCallback(()=>{se.current?.scrollIntoView({behavior:"smooth"})},[]);u.useEffect(()=>{ae()},[f?.messages,ae]);const re=u.useCallback(async()=>{fe(!0);try{const X=await Se("/api/chat/platforms");if(console.log("[Chat] 平台列表响应:",X.status,X.headers.get("content-type")),X.ok){const He=X.headers.get("content-type");if(He&&He.includes("application/json")){const De=await X.json();console.log("[Chat] 平台列表数据:",De),I(De.platforms||[])}else{const De=await X.text();console.error("[Chat] 获取平台列表失败: 非 JSON 响应:",De.substring(0,200)),_e({title:"连接失败",description:"无法连接到后端服务,请确保 MaiBot 已启动",variant:"destructive"})}}else console.error("[Chat] 获取平台列表失败: HTTP",X.status),_e({title:"获取平台失败",description:`服务器返回错误: ${X.status}`,variant:"destructive"})}catch(X){console.error("[Chat] 获取平台列表失败:",X),_e({title:"网络错误",description:"无法连接到后端服务",variant:"destructive"})}finally{fe(!1)}},[_e]),F=u.useCallback(async(X,He)=>{pe(!0);try{const De=new URLSearchParams;X&&De.append("platform",X),He&&De.append("search",He),De.append("limit","50");const Ke=await Se(`/api/chat/persons?${De.toString()}`);if(Ke.ok){const Ns=Ke.headers.get("content-type");if(Ns&&Ns.includes("application/json")){const Je=await Ke.json();A(Je.persons||[])}else console.error("[Chat] 获取用户列表失败: 后端返回非 JSON 响应")}}catch(De){console.error("[Chat] 获取用户列表失败:",De)}finally{pe(!1)}},[]);u.useEffect(()=>{be.platform&&F(be.platform,he)},[be.platform,he,F]);const P=u.useCallback(async(X,He)=>{N(!0);try{const De=new URLSearchParams;De.append("user_id",J.current),De.append("limit","50"),He&&De.append("group_id",He);const Ke=`/api/chat/history?${De.toString()}`;console.log("[Chat] 正在加载历史消息:",Ke);const Ns=await Se(Ke);if(Ns.ok){const Je=await Ns.text();try{const Ks=JSON.parse(Je);if(Ks.messages&&Ks.messages.length>0){const ye=Ks.messages.map(Ae=>({id:Ae.id,type:Ae.type,content:Ae.content,timestamp:Ae.timestamp,sender:{name:Ae.sender_name||(Ae.is_bot?"麦麦":"WebUI用户"),user_id:Ae.user_id,is_bot:Ae.is_bot}}));ze(X,{messages:ye});const _s=me.current.get(X)||new Set;ye.forEach(Ae=>{if(Ae.type==="bot"){const vs=`bot-${Ae.content}-${Math.floor(Ae.timestamp*1e3)}`;_s.add(vs)}}),me.current.set(X,_s)}}catch(Ks){console.error("[Chat] JSON 解析失败:",Ks)}}}catch(De){console.error("[Chat] 加载历史消息失败:",De)}finally{N(!1)}},[ze]),Te=u.useCallback((X,He,De)=>{const Ke=q.current.get(X);if(Ke?.readyState===WebSocket.OPEN||Ke?.readyState===WebSocket.CONNECTING){console.log(`[Tab ${X}] WebSocket 已存在,跳过连接`);return}j(!0);const Ns=window.location.protocol==="https:"?"wss:":"ws:",Je=new URLSearchParams;He==="virtual"&&De?(Je.append("user_id",De.userId),Je.append("user_name",De.userName),Je.append("platform",De.platform),Je.append("person_id",De.personId),Je.append("group_name",De.groupName||"WebUI虚拟群聊"),De.groupId&&Je.append("group_id",De.groupId)):(Je.append("user_id",J.current),Je.append("user_name",k));const Ks=`${Ns}//${window.location.host}/api/chat/ws?${Je.toString()}`;console.log(`[Tab ${X}] 正在连接 WebSocket:`,Ks);try{const ye=new WebSocket(Ks);q.current.set(X,ye),ye.onopen=()=>{ze(X,{isConnected:!0}),j(!1),console.log(`[Tab ${X}] WebSocket 已连接`)},ye.onmessage=_s=>{try{const Ae=JSON.parse(_s.data);switch(Ae.type){case"session_info":ze(X,{sessionInfo:{session_id:Ae.session_id,user_id:Ae.user_id,user_name:Ae.user_name,bot_name:Ae.bot_name}});break;case"system":ge(X,{id:Ce("sys"),type:"system",content:Ae.content||"",timestamp:Ae.timestamp||Date.now()/1e3});break;case"user_message":{const vs=Ae.sender?.user_id,bs=He==="virtual"&&De?De.userId:J.current;console.log(`[Tab ${X}] 收到 user_message, sender: ${vs}, current: ${bs}`);const Nt=vs?vs.replace(/^webui_user_/,""):"",Xs=bs?bs.replace(/^webui_user_/,""):"";if(Nt&&Xs&&Nt===Xs){console.log(`[Tab ${X}] 跳过自己的消息(user_id 匹配)`);break}const Ss=me.current.get(X)||new Set,Es=`user-${Ae.content}-${Math.floor((Ae.timestamp||0)*1e3)}`;if(Ss.has(Es)){console.log(`[Tab ${X}] 跳过自己的消息(内容去重)`);break}if(Ss.add(Es),me.current.set(X,Ss),Ss.size>100){const Js=Ss.values().next().value;Js&&Ss.delete(Js)}ge(X,{id:Ae.message_id||Ce("user"),type:"user",content:Ae.content||"",timestamp:Ae.timestamp||Date.now()/1e3,sender:Ae.sender});break}case"bot_message":{ze(X,{isTyping:!1});const vs=me.current.get(X)||new Set,bs=`bot-${Ae.content}-${Math.floor((Ae.timestamp||0)*1e3)}`;if(vs.has(bs))break;if(vs.add(bs),me.current.set(X,vs),vs.size>100){const Nt=vs.values().next().value;Nt&&vs.delete(Nt)}d(Nt=>Nt.map(Xs=>{if(Xs.id!==X)return Xs;const Ss=Xs.messages.filter(Js=>Js.type!=="thinking"),Es={id:Ce("bot"),type:"bot",content:Ae.content||"",message_type:Ae.message_type==="rich"?"rich":"text",segments:Ae.segments,timestamp:Ae.timestamp||Date.now()/1e3,sender:Ae.sender};return{...Xs,messages:[...Ss,Es]}}));break}case"typing":ze(X,{isTyping:Ae.is_typing||!1});break;case"error":d(vs=>vs.map(bs=>{if(bs.id!==X)return bs;const Nt=bs.messages.filter(Xs=>Xs.type!=="thinking");return{...bs,messages:[...Nt,{id:Ce("error"),type:"error",content:Ae.content||"发生错误",timestamp:Ae.timestamp||Date.now()/1e3}]}})),_e({title:"错误",description:Ae.content,variant:"destructive"});break;case"pong":break;case"history":{const vs=Ae.messages||[];if(vs.length>0){const bs=me.current.get(X)||new Set,Nt=vs.map(Xs=>{const Ss=Xs.is_bot||!1,Es=Xs.id||Ce(Ss?"bot":"user"),Js=`${Ss?"bot":"user"}-${Xs.content}-${Math.floor(Xs.timestamp*1e3)}`;return bs.add(Js),{id:Es,type:Ss?"bot":"user",content:Xs.content,timestamp:Xs.timestamp,sender:{name:Xs.sender_name||(Ss?"麦麦":"用户"),user_id:Xs.sender_id,is_bot:Ss}}});me.current.set(X,bs),ze(X,{messages:Nt}),console.log(`[Tab ${X}] 已加载 ${Nt.length} 条历史消息`)}break}default:console.log("未知消息类型:",Ae.type)}}catch(Ae){console.error("解析消息失败:",Ae)}},ye.onclose=()=>{ze(X,{isConnected:!1}),j(!1),q.current.delete(X),console.log(`[Tab ${X}] WebSocket 已断开`);const _s=R.current.get(X);_s&&clearTimeout(_s);const Ae=window.setTimeout(()=>{if(!Le.current){const vs=i.find(bs=>bs.id===X);vs&&Te(X,vs.type,vs.virtualConfig)}},5e3);R.current.set(X,Ae)},ye.onerror=_s=>{console.error(`[Tab ${X}] WebSocket 错误:`,_s),j(!1)}}catch(ye){console.error(`[Tab ${X}] 创建 WebSocket 失败:`,ye),j(!1)}},[k,ze,ge,_e,i]),Le=u.useRef(!1);u.useEffect(()=>{Le.current=!1;const X=q.current,He=R.current,De=me.current;P("webui-default");const Ke=setTimeout(()=>{Le.current||(Te("webui-default","webui"),i.forEach(Je=>{Je.type==="virtual"&&Je.virtualConfig&&(De.set(Je.id,new Set),setTimeout(()=>{Le.current||Te(Je.id,"virtual",Je.virtualConfig)},200))}))},100),Ns=setInterval(()=>{X.forEach(Je=>{Je.readyState===WebSocket.OPEN&&Je.send(JSON.stringify({type:"ping"}))})},3e4);return()=>{Le.current=!0,clearTimeout(Ke),clearInterval(Ns),He.forEach(Je=>{clearTimeout(Je)}),He.clear(),X.forEach(Je=>{Je.close()}),X.clear()}},[]);const E=u.useCallback(()=>{const X=q.current.get(m);if(!p.trim()||!X||X.readyState!==WebSocket.OPEN)return;const He=f?.type==="virtual"&&f.virtualConfig?.userName||k,De=p.trim(),Ke=Date.now()/1e3;X.send(JSON.stringify({type:"message",content:De,user_name:He}));const Ns=me.current.get(m)||new Set,Je=`user-${De}-${Math.floor(Ke*1e3)}`;if(Ns.add(Je),me.current.set(m,Ns),Ns.size>100){const _s=Ns.values().next().value;_s&&Ns.delete(_s)}const Ks={id:Ce("user"),type:"user",content:De,timestamp:Ke,sender:{name:He,is_bot:!1}};ge(m,Ks);const ye={id:Ce("thinking"),type:"thinking",content:"",timestamp:Ke+.001,sender:{name:f?.sessionInfo.bot_name||"麦麦",is_bot:!0}};ge(m,ye),g("")},[p,k,m,f,ge]),xe=X=>{X.key==="Enter"&&!X.shiftKey&&(X.preventDefault(),E())},Ye=()=>{Y(k),O(!0)},ke=()=>{const X=B.trim()||"WebUI用户";w(X),i_(X),O(!1);const He=q.current.get(m);He?.readyState===WebSocket.OPEN&&He.send(JSON.stringify({type:"update_nickname",user_name:X}))},Q=()=>{Y(""),O(!1)},Ne=X=>new Date(X*1e3).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),qe=()=>{const X=q.current.get(m);X&&(X.close(),q.current.delete(m)),Te(m,f?.type||"webui",f?.virtualConfig)},Fs=()=>{D({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),ve(""),re(),z(!0)},ks=()=>{if(!be.platform||!be.personId){_e({title:"配置不完整",description:"请选择平台和用户",variant:"destructive"});return}const X=`webui_virtual_group_${be.platform}_${be.userId}`,He=`virtual-${be.platform}-${be.userId}-${Date.now()}`,De=be.userName||be.userId,Ke={id:He,type:"virtual",label:De,virtualConfig:{...be,groupId:X},messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}};d(Ns=>{const Je=[...Ns,Ke],Ks=Je.filter(ye=>ye.type==="virtual"&&ye.virtualConfig).map(ye=>({id:ye.id,label:ye.label,virtualConfig:ye.virtualConfig,createdAt:Date.now()}));return wp(Ks),Je}),x(He),z(!1),me.current.set(He,new Set),setTimeout(()=>{Te(He,"virtual",be)},100),_e({title:"虚拟身份标签页",description:`已创建 ${De} 的对话`})},xt=(X,He)=>{if(He?.stopPropagation(),X==="webui-default")return;const De=q.current.get(X);De&&(De.close(),q.current.delete(X));const Ke=R.current.get(X);Ke&&(clearTimeout(Ke),R.current.delete(X)),me.current.delete(X),d(Ns=>{const Je=Ns.filter(ye=>ye.id!==X),Ks=Je.filter(ye=>ye.type==="virtual"&&ye.virtualConfig).map(ye=>({id:ye.id,label:ye.label,virtualConfig:ye.virtualConfig,createdAt:Date.now()}));return wp(Ks),Je}),m===X&&x("webui-default")},js=X=>{x(X)},Vs=X=>{D(He=>({...He,personId:X.person_id,userId:X.user_id,userName:X.nickname||X.person_name}))};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx(qs,{open:L,onOpenChange:z,children:e.jsxs(Ls,{className:"sm:max-w-[500px] max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsxs(Us,{children:[e.jsxs(Bs,{className:"flex items-center gap-2",children:[e.jsx(Nu,{className:"h-5 w-5"}),"新建虚拟身份对话"]}),e.jsx(Ps,{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(C,{className:"flex items-center gap-2",children:[e.jsx(Ru,{className:"h-4 w-4"}),"选择平台"]}),e.jsxs(Ue,{value:be.platform,onValueChange:X=>{D(He=>({...He,platform:X,personId:"",userId:"",userName:""})),A([])},children:[e.jsx(Oe,{disabled:te,children:e.jsx(Be,{placeholder:te?"加载中...":"选择平台"})}),e.jsx(Re,{children:K.map(X=>e.jsxs(le,{value:X.platform,children:[X.platform," (",X.count," 人)"]},X.platform))})]})]}),be.platform&&e.jsxs("div",{className:"space-y-2 flex-1 overflow-hidden flex flex-col",children:[e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsx(Lu,{className:"h-4 w-4"}),"选择用户"]}),e.jsxs("div",{className:"relative",children:[e.jsx(Mt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"搜索用户名...",value:he,onChange:X=>ve(X.target.value),className:"pl-9"})]}),e.jsx(Ze,{className:"h-[250px] border rounded-md",children:e.jsx("div",{className:"p-2",children:je?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(it,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):T.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[e.jsx(Lu,{className:"h-8 w-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"没有找到用户"})]}):e.jsx("div",{className:"space-y-1",children:T.map(X=>e.jsxs("button",{onClick:()=>Vs(X),className:$("w-full flex items-center gap-3 p-2 rounded-md text-left transition-colors",be.personId===X.person_id?"bg-primary text-primary-foreground":"hover:bg-muted"),children:[e.jsx(ni,{className:"h-8 w-8 shrink-0",children:e.jsx(ri,{className:$("text-xs",be.personId===X.person_id?"bg-primary-foreground/20":"bg-muted"),children:(X.nickname||X.person_name||"?").charAt(0)})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium truncate",children:X.nickname||X.person_name}),e.jsxs("div",{className:$("text-xs truncate",be.personId===X.person_id?"text-primary-foreground/70":"text-muted-foreground"),children:["ID: ",X.user_id,X.is_known&&" · 已认识"]})]})]},X.person_id))})})})]}),be.personId&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"虚拟群名(可选)"}),e.jsx(ie,{placeholder:"WebUI虚拟群聊",value:be.groupName,onChange:X=>D(He=>({...He,groupName:X.target.value}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦会认为这是一个名为此名称的群聊"})]})]}),e.jsxs(st,{className:"gap-2 sm:gap-0",children:[e.jsx(S,{variant:"outline",onClick:()=>z(!1),children:"取消"}),e.jsx(S,{onClick:ks,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:[i.map(X=>e.jsxs("div",{className:$("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm whitespace-nowrap transition-colors cursor-pointer","hover:bg-muted",m===X.id?"bg-background shadow-sm border":"text-muted-foreground"),onClick:()=>js(X.id),children:[X.type==="webui"?e.jsx(Rl,{className:"h-3.5 w-3.5"}):e.jsx(Nu,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"max-w-[100px] truncate",children:X.label}),e.jsx("span",{className:$("w-1.5 h-1.5 rounded-full",X.isConnected?"bg-green-500":"bg-muted-foreground/50")}),X.id!=="webui-default"&&e.jsx("span",{onClick:He=>xt(X.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(),xt(X.id,He))},children:e.jsx(rl,{className:"h-3 w-3"})})]},X.id)),e.jsx("button",{onClick:Fs,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(dt,{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(ni,{className:"h-8 w-8 sm:h-10 sm:w-10 shrink-0",children:e.jsx(ri,{className:"bg-primary/10 text-primary",children:e.jsx(ti,{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:f?.sessionInfo.bot_name||"麦麦"}),e.jsx("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:f?.isConnected?e.jsxs(e.Fragment,{children:[e.jsx(py,{className:"h-3 w-3 text-green-500"}),e.jsx("span",{className:"text-green-600 dark:text-green-400",children:"已连接"})]}):b?e.jsxs(e.Fragment,{children:[e.jsx(it,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"连接中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(gy,{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(it,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:qe,disabled:b,title:"重新连接",children:e.jsx(zt,{className:$("h-4 w-4",b&&"animate-spin")})})]})]}),e.jsx("div",{className:"hidden sm:flex items-center gap-2 mt-2 text-sm text-muted-foreground",children:f?.type==="virtual"&&f.virtualConfig?e.jsxs(e.Fragment,{children:[e.jsx(Nu,{className:"h-3 w-3 text-primary"}),e.jsx("span",{children:"虚拟身份:"}),e.jsx("span",{className:"font-medium text-primary",children:f.virtualConfig.userName}),e.jsxs("span",{className:"text-xs",children:["(",f.virtualConfig.platform,")"]}),f.virtualConfig.groupName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1",children:"·"}),e.jsxs("span",{className:"text-xs",children:["群:",f.virtualConfig.groupName]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Qc,{className:"h-3 w-3"}),e.jsx("span",{children:"当前身份:"}),U?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{value:B,onChange:X=>Y(X.target.value),onKeyDown:X=>{X.key==="Enter"&&ke(),X.key==="Escape"&&Q()},className:"h-7 w-32",placeholder:"输入昵称",autoFocus:!0}),e.jsx(S,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:ke,children:"保存"}),e.jsx(S,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:Q,children:"取消"})]}):e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-foreground",children:k}),e.jsx(S,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:Ye,title:"修改昵称",children:e.jsx(jy,{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:[f?.messages.length===0&&!y&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(ti,{className:"h-12 w-12 mb-4 opacity-50"}),e.jsxs("p",{className:"text-sm",children:["开始与 ",f?.sessionInfo.bot_name||"麦麦"," 对话吧!"]})]}),f?.messages.map(X=>e.jsxs("div",{className:$("flex gap-2 sm:gap-3",X.type==="user"&&"flex-row-reverse",X.type==="system"&&"justify-center",X.type==="error"&&"justify-center"),children:[X.type==="system"&&e.jsx("div",{className:"text-xs text-muted-foreground bg-muted/50 px-3 py-1 rounded-full max-w-[90%]",children:X.content}),X.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:X.content}),X.type==="thinking"&&e.jsxs(e.Fragment,{children:[e.jsx(ni,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(ri,{className:"bg-primary/10 text-primary",children:e.jsx(ti,{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:X.sender?.name||f?.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:"思考中..."})]})})]})]}),(X.type==="user"||X.type==="bot")&&e.jsxs(e.Fragment,{children:[e.jsx(ni,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(ri,{className:$("text-xs",X.type==="bot"?"bg-primary/10 text-primary":"bg-secondary text-secondary-foreground"),children:X.type==="bot"?e.jsx(ti,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}):e.jsx(Qc,{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%]",X.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:X.sender?.name||(X.type==="bot"?f?.sessionInfo.bot_name:k)}),e.jsx("span",{children:Ne(X.timestamp)})]}),e.jsx("div",{className:$("rounded-2xl px-3 py-2 text-sm break-words",X.type==="bot"?"bg-muted rounded-tl-sm":"bg-primary text-primary-foreground rounded-tr-sm"),children:e.jsx(d_,{message:X,isBot:X.type==="bot"})})]})]})]},X.id)),e.jsx("div",{ref:se})]})})}),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:p,onChange:X=>g(X.target.value),onKeyDown:xe,placeholder:f?.isConnected?"输入消息...":"等待连接...",disabled:!f?.isConnected,className:"flex-1 h-10 sm:h-10"}),e.jsx(S,{onClick:E,disabled:!f?.isConnected||!p.trim(),size:"icon",className:"h-10 w-10 shrink-0",children:e.jsx(vy,{className:"h-4 w-4"})})]})})})]})}var sm="Radio",[m_,Pg]=lg(sm),[x_,h_]=m_(sm),Wg=u.forwardRef((n,r)=>{const{__scopeRadio:i,name:d,checked:m=!1,required:x,disabled:f,value:p="on",onCheck:g,form:b,...j}=n,[y,N]=u.useState(null),k=Fu(r,O=>N(O)),w=u.useRef(!1),U=y?b||!!y.closest("form"):!0;return e.jsxs(x_,{scope:i,checked:m,disabled:f,children:[e.jsx(Xc.button,{type:"button",role:"radio","aria-checked":m,"data-state":aj(m),"data-disabled":f?"":void 0,disabled:f,value:p,...j,ref:k,onClick:Du(n.onClick,O=>{m||g?.(),U&&(w.current=O.isPropagationStopped(),w.current||O.stopPropagation())})}),U&&e.jsx(tj,{control:y,bubbles:!w.current,name:d,value:p,checked:m,required:x,disabled:f,form:b,style:{transform:"translateX(-100%)"}})]})});Wg.displayName=sm;var ej="RadioIndicator",sj=u.forwardRef((n,r)=>{const{__scopeRadio:i,forceMount:d,...m}=n,x=h_(ej,i);return e.jsx(BN,{present:d||x.checked,children:e.jsx(Xc.span,{"data-state":aj(x.checked),"data-disabled":x.disabled?"":void 0,...m,ref:r})})});sj.displayName=ej;var f_="RadioBubbleInput",tj=u.forwardRef(({__scopeRadio:n,control:r,checked:i,bubbles:d=!0,...m},x)=>{const f=u.useRef(null),p=Fu(f,x),g=HN(i),b=qN(r);return u.useEffect(()=>{const j=f.current;if(!j)return;const y=window.HTMLInputElement.prototype,k=Object.getOwnPropertyDescriptor(y,"checked").set;if(g!==i&&k){const w=new Event("click",{bubbles:d});k.call(j,i),j.dispatchEvent(w)}},[g,i,d]),e.jsx(Xc.input,{type:"radio","aria-hidden":!0,defaultChecked:i,...m,tabIndex:-1,ref:p,style:{...m.style,...b,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});tj.displayName=f_;function aj(n){return n?"checked":"unchecked"}var p_=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],no="RadioGroup",[g_]=lg(no,[Vp,Pg]),lj=Vp(),nj=Pg(),[j_,v_]=g_(no),rj=u.forwardRef((n,r)=>{const{__scopeRadioGroup:i,name:d,defaultValue:m,value:x,required:f=!1,disabled:p=!1,orientation:g,dir:b,loop:j=!0,onValueChange:y,...N}=n,k=lj(i),w=LN(b),[U,O]=UN({prop:x,defaultProp:m??null,onChange:y,caller:no});return e.jsx(j_,{scope:i,name:d,required:f,disabled:p,value:U,onValueChange:O,children:e.jsx(xN,{asChild:!0,...k,orientation:g,dir:w,loop:j,children:e.jsx(Xc.div,{role:"radiogroup","aria-required":f,"aria-orientation":g,"data-disabled":p?"":void 0,dir:w,...N,ref:r})})})});rj.displayName=no;var ij="RadioGroupItem",cj=u.forwardRef((n,r)=>{const{__scopeRadioGroup:i,disabled:d,...m}=n,x=v_(ij,i),f=x.disabled||d,p=lj(i),g=nj(i),b=u.useRef(null),j=Fu(r,b),y=x.value===m.value,N=u.useRef(!1);return u.useEffect(()=>{const k=U=>{p_.includes(U.key)&&(N.current=!0)},w=()=>N.current=!1;return document.addEventListener("keydown",k),document.addEventListener("keyup",w),()=>{document.removeEventListener("keydown",k),document.removeEventListener("keyup",w)}},[]),e.jsx(hN,{asChild:!0,...p,focusable:!f,active:y,children:e.jsx(Wg,{disabled:f,required:x.required,checked:y,...g,...m,name:x.name,ref:j,onCheck:()=>x.onValueChange(m.value),onKeyDown:Du(k=>{k.key==="Enter"&&k.preventDefault()}),onFocus:Du(m.onFocus,()=>{N.current&&b.current?.click()})})})});cj.displayName=ij;var b_="RadioGroupIndicator",oj=u.forwardRef((n,r)=>{const{__scopeRadioGroup:i,...d}=n,m=nj(i);return e.jsx(sj,{...m,...d,ref:r})});oj.displayName=b_;var dj=rj,uj=cj,N_=oj;const mj=u.forwardRef(({className:n,...r},i)=>e.jsx(dj,{className:$("grid gap-2",n),...r,ref:i}));mj.displayName=dj.displayName;const xj=u.forwardRef(({className:n,...r},i)=>e.jsx(uj,{ref:i,className:$("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",n),...r,children:e.jsx(N_,{className:"flex items-center justify-center",children:e.jsx(by,{className:"h-2.5 w-2.5 fill-current text-current"})})}));xj.displayName=uj.displayName;function y_({question:n,value:r,onChange:i,error:d,disabled:m=!1}){const[x,f]=u.useState(null),p=m||n.readOnly,g=()=>{switch(n.type){case"single":return e.jsx(mj,{value:r||"",onValueChange:i,disabled:p,className:"space-y-2",children:n.options?.map(b=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(xj,{value:b.value,id:`${n.id}-${b.id}`}),e.jsx(C,{htmlFor:`${n.id}-${b.id}`,className:"cursor-pointer font-normal",children:b.label})]},b.id))});case"multiple":{const b=r||[];return e.jsxs("div",{className:"space-y-2",children:[n.options?.map(j=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(mt,{id:`${n.id}-${j.id}`,checked:b.includes(j.value),disabled:p||n.maxSelections!==void 0&&b.length>=n.maxSelections&&!b.includes(j.value),onCheckedChange:y=>{i(y?[...b,j.value]:b.filter(N=>N!==j.value))}}),e.jsx(C,{htmlFor:`${n.id}-${j.id}`,className:"cursor-pointer font-normal",children:j.label})]},j.id)),n.maxSelections&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["最多选择 ",n.maxSelections," 项"]})]})}case"text":return e.jsx(ie,{value:r||"",onChange:b=>i(b.target.value),placeholder:n.placeholder||"请输入...",disabled:p,readOnly:n.readOnly,maxLength:n.maxLength,className:$(n.readOnly&&"bg-muted cursor-not-allowed")});case"textarea":return e.jsxs("div",{className:"space-y-1",children:[e.jsx(Qs,{value:r||"",onChange:b=>i(b.target.value),placeholder:n.placeholder||"请输入...",disabled:p,readOnly:n.readOnly,maxLength:n.maxLength,rows:4,className:$(n.readOnly&&"bg-muted cursor-not-allowed")}),n.maxLength&&e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[(r||"").length," / ",n.maxLength]})]});case"rating":{const b=r||0,j=x!==null?x:b;return e.jsxs("div",{className:"flex items-center gap-1",children:[[1,2,3,4,5].map(y=>e.jsx("button",{type:"button",disabled:p,className:$("p-1 transition-colors focus:outline-none focus:ring-2 focus:ring-ring rounded",p&&"cursor-not-allowed opacity-50"),onMouseEnter:()=>!p&&f(y),onMouseLeave:()=>f(null),onClick:()=>!p&&i(y),children:e.jsx(nl,{className:$("h-6 w-6 transition-colors",y<=j?"fill-yellow-400 text-yellow-400":"text-muted-foreground")})},y)),b>0&&e.jsxs("span",{className:"ml-2 text-sm text-muted-foreground",children:[b," / 5"]})]})}case"scale":{const b=n.min??1,j=n.max??10,y=n.step??1,N=r??b;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(pa,{value:[N],onValueChange:([k])=>i(k),min:b,max:j,step:y,disabled:p}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:n.minLabel||b}),e.jsx("span",{className:"font-medium text-foreground",children:N}),e.jsx("span",{children:n.maxLabel||j})]})]})}case"dropdown":return e.jsxs(Ue,{value:r||"",onValueChange:i,disabled:p,children:[e.jsx(Oe,{children:e.jsx(Be,{placeholder:n.placeholder||"请选择..."})}),e.jsx(Re,{children:n.options?.map(b=>e.jsx(le,{value:b.value,children:b.label},b.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(C,{className:"text-base font-medium",children:[n.title,n.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),n.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:n.description})]}),g(),d&&e.jsx("p",{className:"text-sm text-destructive",children:d})]})}const hj="https://maibot-plugin-stats.maibot-webui.workers.dev";function fj(){const n="maibot_user_id";let r=localStorage.getItem(n);if(!r){const i=Math.random().toString(36).substring(2,10),d=Date.now().toString(36),m=Math.random().toString(36).substring(2,10);r=`fp_${i}_${d}_${m}`,localStorage.setItem(n,r)}return r}async function w_(n,r,i,d){try{const m=d?.userId||fj(),x={surveyId:n,surveyVersion:r,userId:m,answers:i,submittedAt:new Date().toISOString(),allowMultiple:d?.allowMultiple,metadata:{userAgent:navigator.userAgent,language:navigator.language}},f=await fetch(`${hj}/survey/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)}),p=await f.json();return f.status===429?{success:!1,error:"提交过于频繁,请稍后再试"}:f.status===409?{success:!1,error:p.error||"你已经提交过这份问卷了"}:f.ok?{success:!0,submissionId:p.submissionId,message:p.message}:{success:!1,error:p.error||"提交失败"}}catch(m){return console.error("Error submitting survey:",m),{success:!1,error:"网络错误"}}}async function __(n,r){try{const i=r||fj(),d=new URLSearchParams({user_id:i,survey_id:n}),m=await fetch(`${hj}/survey/check?${d}`);return m.ok?{success:!0,hasSubmitted:(await m.json()).hasSubmitted}:{success:!1,error:(await m.json()).error||"检查失败"}}catch(i){return console.error("Error checking submission:",i),{success:!1,error:"网络错误"}}}function pj({config:n,initialAnswers:r,onSubmitSuccess:i,onSubmitError:d,showProgress:m=!0,paginateQuestions:x=!1,className:f}){const p=u.useCallback(()=>!r||r.length===0?{}:r.reduce((q,se)=>(q[se.questionId]=se.value,q),{}),[r]),[g,b]=u.useState(()=>p()),[j,y]=u.useState({}),[N,k]=u.useState(0),[w,U]=u.useState(!1),[O,B]=u.useState(!1),[Y,L]=u.useState(null),[z,K]=u.useState(null),[I,T]=u.useState(!1),[A,te]=u.useState(!0);u.useEffect(()=>{r&&r.length>0&&b(q=>({...q,...p()}))},[r,p]),u.useEffect(()=>{(async()=>{if(!n.settings?.allowMultiple){const se=await __(n.id);se.success&&se.hasSubmitted&&T(!0)}te(!1)})()},[n.id,n.settings?.allowMultiple]);const fe=u.useCallback(()=>{const q=new Date;return!(n.settings?.startTime&&new Date(n.settings.startTime)>q||n.settings?.endTime&&new Date(n.settings.endTime){const se=g[q.id];return se==null?!1:Array.isArray(se)?se.length>0:typeof se=="string"?se.trim()!=="":!0}).length,pe=je/n.questions.length*100,he=u.useCallback((q,se)=>{b(R=>({...R,[q]:se})),y(R=>{const ue={...R};return delete ue[q],ue})},[]),ve=u.useCallback(()=>{const q={};for(const se of n.questions){if(se.required){const R=g[se.id];if(R==null){q[se.id]="此题为必填项";continue}if(Array.isArray(R)&&R.length===0){q[se.id]="请至少选择一项";continue}if(typeof R=="string"&&R.trim()===""){q[se.id]="此题为必填项";continue}}se.minLength&&typeof g[se.id]=="string"&&g[se.id].length{if(!ve()){if(x){const q=n.questions.findIndex(se=>j[se.id]);q>=0&&k(q)}return}U(!0),L(null);try{const q=n.questions.filter(R=>g[R.id]!==void 0).map(R=>({questionId:R.id,value:g[R.id]})),se=await w_(n.id,n.version,q,{allowMultiple:n.settings?.allowMultiple});if(se.success&&se.submissionId)B(!0),K(se.submissionId),i?.(se.submissionId);else{const R=se.error||"提交失败";L(R),d?.(R)}}catch(q){const se=q instanceof Error?q.message:"提交失败";L(se),d?.(se)}finally{U(!1)}},[ve,x,n,g,j,i,d]),D=u.useCallback(q=>{q>=0&&qe.jsxs("div",{className:$("p-4 rounded-lg border bg-card",j[q.id]?"border-destructive bg-destructive/5":"border-border"),children:[x&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:["问题 ",N+1," / ",n.questions.length]}),!x&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:[se+1,"."]}),e.jsx(y_,{question:q,value:g[q.id],onChange:R=>he(q.id,R),error:j[q.id],disabled:w})]},q.id)),Y&&e.jsxs(It,{variant:"destructive",children:[e.jsx(At,{className:"h-4 w-4"}),e.jsx(Yt,{children:Y})]}),e.jsx("div",{className:"flex justify-between items-center py-4",children:x?e.jsxs(e.Fragment,{children:[e.jsxs(S,{variant:"outline",onClick:()=>D(N-1),disabled:N===0||w,children:[e.jsx(il,{className:"h-4 w-4 mr-1"}),"上一题"]}),N===n.questions.length-1?e.jsxs(S,{onClick:be,disabled:w,children:[w&&e.jsx(it,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]}):e.jsxs(S,{onClick:()=>D(N+1),disabled:w,children:["下一题",e.jsx(Ba,{className:"h-4 w-4 ml-1"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:Object.keys(j).length>0&&e.jsxs("span",{className:"text-destructive",children:["还有 ",Object.keys(j).length," 个必填项未完成"]})}),e.jsxs(S,{onClick:be,disabled:w,size:"lg",children:[w&&e.jsx(it,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]})]})})]})})]})}const S_={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:"感谢你的反馈!你的意见对我们非常重要,我们会认真考虑每一条建议。"}},C_={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 k_(){const[n,r]=u.useState(null),[i,d]=u.useState(!0);u.useEffect(()=>{const p=JSON.parse(JSON.stringify(S_));r(p),d(!1)},[]);const m=u.useMemo(()=>[{questionId:"webui_version",value:`v${Zc}`}],[]),x=u.useCallback(p=>{console.log("WebUI Survey submitted:",p)},[]),f=u.useCallback(p=>{console.error("WebUI Survey submission error:",p)},[]);return i?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(it,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):n?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(bg,{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(pj,{config:n,initialAnswers:m,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:x,onSubmitError:f})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(It,{variant:"destructive",className:"max-w-md",children:[e.jsx(At,{className:"h-4 w-4"}),e.jsx(Yt,{children:"无法加载问卷配置"})]}),e.jsx(S,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}function T_(){const[n,r]=u.useState(null),[i,d]=u.useState(!0),[m,x]=u.useState("未知版本");u.useEffect(()=>{(async()=>{try{const y=await Lg();x(y.version||"未知版本")}catch(y){console.error("Failed to get MaiBot version:",y),x("获取失败")}const j=JSON.parse(JSON.stringify(C_));r(j),d(!1)})()},[]);const f=u.useMemo(()=>[{questionId:"maibot_version",value:m}],[m]),p=u.useCallback(b=>{console.log("MaiBot Survey submitted:",b)},[]),g=u.useCallback(b=>{console.error("MaiBot Survey submission error:",b)},[]);return i?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(it,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):n?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(bg,{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(pj,{config:n,initialAnswers:f,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:p,onSubmitError:g})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(It,{variant:"destructive",className:"max-w-md",children:[e.jsx(At,{className:"h-4 w-4"}),e.jsx(Yt,{children:"无法加载问卷配置"})]}),e.jsx(S,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}function E_(){const n=va(),[r,i]=u.useState(!0);return u.useEffect(()=>{let d=!1;return(async()=>{try{const x=await Ju();!d&&!x&&n({to:"/auth"})}catch{d||n({to:"/auth"})}finally{d||i(!1)}})(),()=>{d=!0}},[n]),{checking:r}}async function z_(){return await Ju()}const A_=tr("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"}}),gj=u.forwardRef(({className:n,size:r,abbrTitle:i,children:d,...m},x)=>e.jsx("kbd",{className:$(A_({size:r,className:n})),ref:x,...m,children:i?e.jsx("abbr",{title:i,children:d}):d}));gj.displayName="Kbd";const M_=[{icon:Jc,title:"首页",description:"查看仪表板概览",path:"/",category:"概览"},{icon:Sa,title:"麦麦主程序配置",description:"配置麦麦的核心设置",path:"/config/bot",category:"配置"},{icon:Ng,title:"麦麦模型提供商配置",description:"配置模型提供商",path:"/config/modelProvider",category:"配置"},{icon:yg,title:"麦麦模型配置",description:"配置模型参数",path:"/config/model",category:"配置"},{icon:Vu,title:"表情包管理",description:"管理麦麦的表情包",path:"/resource/emoji",category:"资源"},{icon:Rl,title:"表达方式管理",description:"管理麦麦的表达方式",path:"/resource/expression",category:"资源"},{icon:wg,title:"人物信息管理",description:"管理人物信息",path:"/resource/person",category:"资源"},{icon:sr,title:"黑话管理",description:"管理麦麦学习到的黑话和俚语",path:"/resource/jargon",category:"资源"},{icon:Ny,title:"统计信息",description:"查看使用统计",path:"/statistics",category:"监控"},{icon:Ol,title:"插件市场",description:"浏览和安装插件",path:"/plugins",category:"扩展"},{icon:Qu,title:"日志查看器",description:"查看系统日志",path:"/logs",category:"监控"},{icon:ar,title:"系统设置",description:"配置系统参数",path:"/settings",category:"系统"}];function D_({open:n,onOpenChange:r}){const[i,d]=u.useState(""),[m,x]=u.useState(0),f=va(),p=M_.filter(j=>j.title.toLowerCase().includes(i.toLowerCase())||j.description.toLowerCase().includes(i.toLowerCase())||j.category.toLowerCase().includes(i.toLowerCase()));u.useEffect(()=>{n&&(d(""),x(0))},[n]);const g=u.useCallback(j=>{f({to:j}),r(!1)},[f,r]),b=u.useCallback(j=>{j.key==="ArrowDown"?(j.preventDefault(),x(y=>(y+1)%p.length)):j.key==="ArrowUp"?(j.preventDefault(),x(y=>(y-1+p.length)%p.length)):j.key==="Enter"&&p[m]&&(j.preventDefault(),g(p[m].path))},[p,m,g]);return e.jsx(qs,{open:n,onOpenChange:r,children:e.jsxs(Ls,{className:"max-w-2xl p-0 gap-0",children:[e.jsxs(Us,{className:"px-4 pt-4 pb-0",children:[e.jsx(Bs,{className:"sr-only",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx(Mt,{className:"absolute left-3 top-1/2 h-5 w-5 -translate-y-1/2 text-muted-foreground"}),e.jsx(ie,{value:i,onChange:j=>{d(j.target.value),x(0)},onKeyDown:b,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:p.length>0?e.jsx("div",{className:"p-2",children:p.map((j,y)=>{const N=j.icon;return e.jsxs("button",{onClick:()=>g(j.path),onMouseEnter:()=>x(y),className:$("w-full flex items-center gap-3 px-3 py-2.5 rounded-md text-left transition-colors",y===m?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[e.jsx(N,{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:j.title}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:j.description})]}),e.jsx("div",{className:"text-xs text-muted-foreground px-2 py-1 bg-muted rounded",children:j.category})]},j.path)})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(Mt,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i?"未找到匹配的页面":"输入关键词开始搜索"})]})})}),e.jsx("div",{className:"border-t px-4 py-3 flex items-center justify-between text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↑"}),e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↓"}),"导航"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Enter"}),"选择"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Esc"}),"关闭"]})]})})]})})}const O_=$N,R_=FN,L_=VN,jj=u.forwardRef(({className:n,sideOffset:r=4,...i},d)=>e.jsx(GN,{children:e.jsx(ng,{ref:d,sideOffset:r,className:$("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]",n),...i})}));jj.displayName=ng.displayName;function U_({children:n}){const{checking:r}=E_(),[i,d]=u.useState(!0),[m,x]=u.useState(!1),[f,p]=u.useState(!1),{theme:g,setTheme:b}=Yu(),j=Hb();if(u.useEffect(()=>{const U=O=>{(O.metaKey||O.ctrlKey)&&O.key==="k"&&(O.preventDefault(),p(!0))};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[]),r)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:Jc,label:"首页",path:"/"}]},{title:"麦麦配置编辑",items:[{icon:Sa,label:"麦麦主程序配置",path:"/config/bot"},{icon:Ng,label:"AI模型厂商配置",path:"/config/modelProvider",tourId:"sidebar-model-provider"},{icon:yg,label:"模型管理与分配",path:"/config/model",tourId:"sidebar-model-management"},{icon:Wf,label:"麦麦适配器配置",path:"/config/adapter"}]},{title:"麦麦资源管理",items:[{icon:Vu,label:"表情包管理",path:"/resource/emoji"},{icon:Rl,label:"表达方式管理",path:"/resource/expression"},{icon:sr,label:"黑话管理",path:"/resource/jargon"},{icon:wg,label:"人物信息管理",path:"/resource/person"},{icon:jg,label:"知识库图谱可视化",path:"/resource/knowledge-graph"}]},{title:"扩展与监控",items:[{icon:Ol,label:"插件市场",path:"/plugins"},{icon:vg,label:"模型分配预设市场",path:"/model-presets"},{icon:Wf,label:"插件配置",path:"/plugin-config"},{icon:Qu,label:"日志查看器",path:"/logs"},{icon:Rl,label:"本地聊天室",path:"/chat"}]},{title:"系统",items:[{icon:ar,label:"系统设置",path:"/settings"}]}],k=g==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":g,w=async()=>{await V0()};return e.jsx(O_,{delayDuration:300,children:e.jsxs("div",{className:"flex h-screen overflow-hidden",children:[e.jsxs("aside",{className:$("fixed inset-y-0 left-0 z-50 flex flex-col border-r bg-card transition-all duration-300 lg:relative lg:z-0","w-64 lg:w-auto",i?"lg:w-64":"lg:w-16",m?"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:$("relative flex items-center justify-center flex-1 transition-all overflow-hidden","lg:flex-1",!i&&"lg:flex-none lg:w-8"),children:[e.jsxs("div",{className:$("flex items-baseline gap-2",!i&&"lg:hidden"),children:[e.jsx("span",{className:"font-bold text-xl text-primary-gradient whitespace-nowrap",children:"MaiBot WebUI"}),e.jsx("span",{className:"text-xs text-primary/60 whitespace-nowrap",children:T0()})]}),!i&&e.jsx("span",{className:"hidden lg:block font-bold text-primary-gradient text-2xl",children:"M"})]})}),e.jsx(Ze,{className:$("flex-1 overflow-x-hidden",!i&&"lg:w-16"),children:e.jsx("nav",{className:$("p-4",!i&&"lg:p-2 lg:w-16"),children:e.jsx("ul",{className:$("space-y-6",!i&&"lg:space-y-3 lg:w-full"),children:y.map((U,O)=>e.jsxs("li",{children:[e.jsx("div",{className:$("px-3 h-[1.25rem]","mb-2",!i&&"lg:mb-1 lg:invisible"),children:e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground/60 whitespace-nowrap",children:U.title})}),!i&&O>0&&e.jsx("div",{className:"hidden lg:block mb-2 border-t border-border"}),e.jsx("ul",{className:"space-y-1",children:U.items.map(B=>{const Y=j({to:B.path}),L=B.icon,z=e.jsxs(e.Fragment,{children:[Y&&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:$("flex items-center transition-all duration-300",i?"gap-3":"gap-3 lg:gap-0"),children:[e.jsx(L,{className:$("h-5 w-5 flex-shrink-0",Y&&"text-primary"),strokeWidth:2,fill:"none"}),e.jsx("span",{className:$("text-sm font-medium whitespace-nowrap transition-all duration-300",Y&&"font-semibold",i?"opacity-100 max-w-[200px]":"opacity-100 max-w-[200px] lg:opacity-0 lg:max-w-0 lg:overflow-hidden"),children:B.label})]})]});return e.jsx("li",{className:"relative",children:e.jsxs(R_,{children:[e.jsx(L_,{asChild:!0,children:e.jsx(Kn,{to:B.path,"data-tour":B.tourId,className:$("relative flex items-center rounded-lg py-2 transition-all duration-300","hover:bg-accent hover:text-accent-foreground",Y?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground",i?"px-3":"px-3 lg:px-0 lg:justify-center lg:w-12 lg:mx-auto"),onClick:()=>x(!1),children:z})}),!i&&e.jsx(jj,{side:"right",className:"hidden lg:block",children:e.jsx("p",{children:B.label})})]})},B.path)})})]},U.title))})})})]}),m&&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(!m),className:"rounded-lg p-2 hover:bg-accent lg:hidden",children:e.jsx(yy,{className:"h-5 w-5"})}),e.jsx("button",{onClick:()=>d(!i),className:"hidden rounded-lg p-2 hover:bg-accent lg:block",title:i?"收起侧边栏":"展开侧边栏",children:e.jsx(il,{className:$("h-5 w-5 transition-transform",!i&&"rotate-180")})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>p(!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(Mt,{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(gj,{size:"sm",className:"absolute right-2 top-1/2 -translate-y-1/2",children:[e.jsx("span",{className:"text-xs",children:"⌘"}),"K"]})]}),e.jsx(D_,{open:f,onOpenChange:p}),e.jsxs(S,{variant:"ghost",size:"sm",onClick:()=>window.open("https://docs.mai-mai.org","_blank"),className:"gap-2",title:"查看麦麦文档",children:[e.jsx(wy,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"麦麦文档"})]}),e.jsx("button",{onClick:U=>{w0(k==="dark"?"light":"dark",b,U)},className:"rounded-lg p-2 hover:bg-accent",title:k==="dark"?"切换到浅色模式":"切换到深色模式",children:k==="dark"?e.jsx(xg,{className:"h-5 w-5"}):e.jsx(hg,{className:"h-5 w-5"})}),e.jsx("div",{className:"h-6 w-px bg-border"}),e.jsxs(S,{variant:"ghost",size:"sm",onClick:w,className:"gap-2",title:"登出系统",children:[e.jsx(_y,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"登出"})]})]})]}),e.jsx("main",{className:"flex-1 overflow-hidden bg-background",children:n})]})]})})}function B_(n){const r=n.split(` `).slice(1),i=[];for(const d of r){const m=d.trim();if(!m.startsWith("at "))continue;const x=m.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);x?i.push({functionName:x[1]||"",fileName:x[2],lineNumber:x[3],columnNumber:x[4],raw:m}):i.push({functionName:"",fileName:"",lineNumber:"",columnNumber:"",raw:m})}return i}function H_({error:n,errorInfo:r}){const[i,d]=u.useState(!0),[m,x]=u.useState(!1),[f,p]=u.useState(!1),g=n.stack?B_(n.stack):[],b=async()=>{const j=` Error: ${n.name} Message: ${n.message} Stack Trace: ${n.stack||"No stack trace available"} Component Stack: ${r?.componentStack||"No component stack available"} URL: ${window.location.href} User Agent: ${navigator.userAgent} Time: ${new Date().toISOString()} `.trim();try{await navigator.clipboard.writeText(j),p(!0),setTimeout(()=>p(!1),2e3)}catch(y){console.error("Failed to copy:",y)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(It,{variant:"destructive",className:"border-red-500/50 bg-red-500/10",children:[e.jsx(Ca,{className:"h-4 w-4"}),e.jsxs(Yt,{className:"font-mono text-sm",children:[e.jsxs("span",{className:"font-semibold",children:[n.name,":"]})," ",n.message]})]}),g.length>0&&e.jsxs(qu,{open:i,onOpenChange:d,children:[e.jsx(Gu,{asChild:!0,children:e.jsxs(S,{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(Sy,{className:"h-4 w-4"}),"Stack Trace (",g.length," frames)"]}),i?e.jsx(di,{className:"h-4 w-4"}):e.jsx(Ll,{className:"h-4 w-4"})]})}),e.jsx($u,{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((j,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:j.functionName}),j.fileName&&e.jsxs("div",{className:"text-muted-foreground mt-0.5 break-all",children:[j.fileName,j.lineNumber&&e.jsxs("span",{className:"text-yellow-600 dark:text-yellow-400",children:[":",j.lineNumber,":",j.columnNumber]})]})]})]})},y))})})})]}),r?.componentStack&&e.jsxs(qu,{open:m,onOpenChange:x,children:[e.jsx(Gu,{asChild:!0,children:e.jsxs(S,{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(Ca,{className:"h-4 w-4"}),"Component Stack"]}),m?e.jsx(di,{className:"h-4 w-4"}):e.jsx(Ll,{className:"h-4 w-4"})]})}),e.jsx($u,{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:r.componentStack})})})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:b,className:"w-full",children:f?e.jsxs(e.Fragment,{children:[e.jsx(Qt,{className:"mr-2 h-4 w-4 text-green-500"}),"已复制到剪贴板"]}):e.jsxs(e.Fragment,{children:[e.jsx(Vc,{className:"mr-2 h-4 w-4"}),"复制错误信息"]})})]})}function vj({error:n,errorInfo:r}){const i=()=>{window.location.href="/"},d=()=>{window.location.reload()};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(Fe,{className:"w-full max-w-2xl shadow-lg",children:[e.jsxs(ts,{className:"text-center pb-2",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/30 mb-4",children:e.jsx(Ca,{className:"h-8 w-8 text-red-600 dark:text-red-400"})}),e.jsx(as,{className:"text-2xl font-bold",children:"页面出现了问题"}),e.jsx(et,{className:"text-base mt-2",children:"应用程序遇到了意外错误。您可以尝试刷新页面或返回首页。"})]}),e.jsxs(xs,{className:"space-y-4",children:[e.jsx(H_,{error:n,errorInfo:r}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 pt-2",children:[e.jsxs(S,{onClick:d,className:"flex-1",children:[e.jsx(zt,{className:"mr-2 h-4 w-4"}),"刷新页面"]}),e.jsxs(S,{onClick:i,variant:"outline",className:"flex-1",children:[e.jsx(Jc,{className:"mr-2 h-4 w-4"}),"返回首页"]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground pt-2",children:"如果问题持续存在,请将错误信息复制并反馈给开发者"})]})]})})}class q_ extends u.Component{constructor(r){super(r),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,i){console.error("ErrorBoundary caught an error:",r,i),this.setState({errorInfo:i})}handleReset=()=>{this.setState({hasError:!1,error:null,errorInfo:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?this.props.fallback:e.jsx(vj,{error:this.state.error,errorInfo:this.state.errorInfo}):this.props.children}}function bj({error:n}){return e.jsx(vj,{error:n,errorInfo:null})}const gi=qb({component:()=>e.jsxs(e.Fragment,{children:[e.jsx(_p,{}),!1]}),beforeLoad:()=>{if(window.location.pathname==="/"&&!z_())throw $b({to:"/auth"})}}),G_=tt({getParentRoute:()=>gi,path:"/auth",component:Q0}),$_=tt({getParentRoute:()=>gi,path:"/setup",component:iw}),jt=tt({getParentRoute:()=>gi,id:"protected",component:()=>e.jsx(U_,{children:e.jsx(_p,{})}),errorComponent:({error:n})=>e.jsx(bj,{error:n})}),F_=tt({getParentRoute:()=>jt,path:"/",component:N0}),V_=tt({getParentRoute:()=>jt,path:"/config/bot",component:Bw}),Q_=tt({getParentRoute:()=>jt,path:"/config/modelProvider",component:Kw}),I_=tt({getParentRoute:()=>jt,path:"/config/model",component:o1}),Y_=tt({getParentRoute:()=>jt,path:"/config/adapter",component:u1}),K_=tt({getParentRoute:()=>jt,path:"/resource/emoji",component:O1}),X_=tt({getParentRoute:()=>jt,path:"/resource/expression",component:I1}),J_=tt({getParentRoute:()=>jt,path:"/resource/person",component:p2}),Z_=tt({getParentRoute:()=>jt,path:"/resource/jargon",component:r2}),P_=tt({getParentRoute:()=>jt,path:"/resource/knowledge-graph",component:S2}),W_=tt({getParentRoute:()=>jt,path:"/logs",component:k2}),eS=tt({getParentRoute:()=>jt,path:"/chat",component:u_}),sS=tt({getParentRoute:()=>jt,path:"/plugins",component:Z2}),tS=tt({getParentRoute:()=>jt,path:"/model-presets",component:P2}),aS=tt({getParentRoute:()=>jt,path:"/plugin-config",component:s_}),lS=tt({getParentRoute:()=>jt,path:"/plugin-mirrors",component:t_}),nS=tt({getParentRoute:()=>jt,path:"/settings",component:B0}),rS=tt({getParentRoute:()=>jt,path:"/survey/webui-feedback",component:k_}),iS=tt({getParentRoute:()=>jt,path:"/survey/maibot-feedback",component:T_}),cS=tt({getParentRoute:()=>gi,path:"*",component:Ug}),oS=gi.addChildren([G_,$_,jt.addChildren([F_,V_,Q_,I_,Y_,K_,X_,Z_,J_,P_,sS,tS,aS,lS,W_,eS,nS,rS,iS]),cS]),dS=Gb({routeTree:oS,defaultNotFoundComponent:Ug,defaultErrorComponent:({error:n})=>e.jsx(bj,{error:n})});function uS({children:n,defaultTheme:r="system",storageKey:i="ui-theme",...d}){const[m,x]=u.useState(()=>localStorage.getItem(i)||r);u.useEffect(()=>{const p=window.document.documentElement;if(p.classList.remove("light","dark"),m==="system"){const g=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";p.classList.add(g);return}p.classList.add(m)},[m]),u.useEffect(()=>{const p=localStorage.getItem("accent-color");if(p){const g=document.documentElement,j={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%)"}}[p];j&&(g.style.setProperty("--primary",j.hsl),j.gradient?(g.style.setProperty("--primary-gradient",j.gradient),g.classList.add("has-gradient")):(g.style.removeProperty("--primary-gradient"),g.classList.remove("has-gradient")))}},[]);const f={theme:m,setTheme:p=>{localStorage.setItem(i,p),x(p)}};return e.jsx(zg.Provider,{...d,value:f,children:n})}function mS({children:n,defaultEnabled:r=!0,defaultWavesEnabled:i=!0,storageKey:d="enable-animations",wavesStorageKey:m="enable-waves-background"}){const[x,f]=u.useState(()=>{const j=localStorage.getItem(d);return j!==null?j==="true":r}),[p,g]=u.useState(()=>{const j=localStorage.getItem(m);return j!==null?j==="true":i});u.useEffect(()=>{const j=document.documentElement;x?j.classList.remove("no-animations"):j.classList.add("no-animations"),localStorage.setItem(d,String(x))},[x,d]),u.useEffect(()=>{localStorage.setItem(m,String(p))},[p,m]);const b={enableAnimations:x,setEnableAnimations:f,enableWavesBackground:p,setEnableWavesBackground:g};return e.jsx(Ag.Provider,{value:b,children:n})}const xS=QN,Nj=u.forwardRef(({className:n,...r},i)=>e.jsx(rg,{ref:i,className:$("fixed bottom-0 right-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:max-w-[420px] gap-2",n),...r}));Nj.displayName=rg.displayName;const hS=tr("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"}}),yj=u.forwardRef(({className:n,variant:r,...i},d)=>e.jsx(ig,{ref:d,className:$(hS({variant:r}),n),...i}));yj.displayName=ig.displayName;const fS=u.forwardRef(({className:n,...r},i)=>e.jsx(cg,{ref:i,className:$("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",n),...r}));fS.displayName=cg.displayName;const wj=u.forwardRef(({className:n,...r},i)=>e.jsx(og,{ref:i,className:$("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",n),"toast-close":"",...r,children:e.jsx(rl,{className:"h-4 w-4"})}));wj.displayName=og.displayName;const _j=u.forwardRef(({className:n,...r},i)=>e.jsx(dg,{ref:i,className:$("text-sm font-semibold [&+div]:text-xs",n),...r}));_j.displayName=dg.displayName;const Sj=u.forwardRef(({className:n,...r},i)=>e.jsx(ug,{ref:i,className:$("text-sm opacity-90",n),...r}));Sj.displayName=ug.displayName;function pS(){const{toasts:n}=$s();return e.jsxs(xS,{children:[n.map(function({id:r,title:i,description:d,action:m,...x}){return e.jsxs(yj,{...x,children:[e.jsxs("div",{className:"grid gap-1",children:[i&&e.jsx(_j,{children:i}),d&&e.jsx(Sj,{children:d})]}),m,e.jsx(wj,{})]},r)}),e.jsx(Nj,{})]})}d0.createRoot(document.getElementById("root")).render(e.jsx(u.StrictMode,{children:e.jsx(q_,{children:e.jsx(uS,{defaultTheme:"system",children:e.jsx(mS,{children:e.jsxs(Fw,{children:[e.jsx(Fb,{router:dS}),e.jsx(Iw,{}),e.jsx(pS,{})]})})})})}));