From 352790f9362a0553af20177cf806267cead66888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com> Date: Sat, 3 Jan 2026 13:29:04 +0800 Subject: [PATCH] WebUI 96d3be292d81fe04928c482f811477aec2fb324d --- webui/dist/assets/index-3QvZgDlg.js | 91 +++++++++++++++++++++++++++++ webui/dist/assets/index-DC6giT2e.js | 91 ----------------------------- webui/dist/index.html | 2 +- 3 files changed, 92 insertions(+), 92 deletions(-) create mode 100644 webui/dist/assets/index-3QvZgDlg.js delete mode 100644 webui/dist/assets/index-DC6giT2e.js diff --git a/webui/dist/assets/index-3QvZgDlg.js b/webui/dist/assets/index-3QvZgDlg.js new file mode 100644 index 00000000..51a769d6 --- /dev/null +++ b/webui/dist/assets/index-3QvZgDlg.js @@ -0,0 +1,91 @@ +import{r as m,j as e,L as Fn,e as ca,R as Rs,b as Q0,f as Y0,g as J0,h as X0,k as Z0,l as Qs,m as W0,n as ew,O as rj,o as sw}from"./router-9vIXuQkh.js";import{a as tw,b as aw,g as lw}from"./react-vendor-BmxF9s7Q.js";import{N as nw,c as rw,O as Wr,P as iw,g as Tm}from"./utils-BqoaXoQ1.js";import{L as ij,T as cj,C as oj,R as cw,a as dj,V as ow,b as dw,S as uj,c as uw,d as mj,I as mw,e as xj,f as xw,g as hj,h as hw,i as fw,j as pw,O as fj,P as gw,k as pj,l as gj,D as jj,A as vj,m as Nj,n as jw,o as vw,p as bj,q as Nw,r as yj,s as bw,t as yw,u as wj,v as ww,w as _w,x as _j,y as Sj,F as kj,z as Cj,B as Sw,E as kw,G as Tj,H as Cw,J as Tw,K as Ew,M as Mw,N as Aw,Q as zw,U as Rw,W as Dw,X as Ow,Y as Lw,Z as Uw,_ as $w,$ as Bw,a0 as Pw,a1 as Iw,a2 as Ej,a3 as Fw,a4 as Hw}from"./radix-extra-DmmnfeQE.js";import{R as Mj,T as Aj,L as Vw,g as Gw,C as Qi,X as Yi,Y as Hr,h as qw,B as Uo,j as Ji,P as Kw,k as Qw,l as Yw}from"./charts-simvewUa.js";import{S as Jw,O as zj,o as Xw,C as Rj,p as Zw,T as Dj,D as Oj,R as Ww,q as e_,H as Lj,I as s_,J as Uj,K as t_,L as $j,M as Bj,N as a_,Q as Pj,V as l_,U as Ij,X as Fj,Y as n_,Z as r_,_ as Hj,$ as i_,a0 as c_,a1 as Vj,e as Gj,f as sd,c as td,P as Zn,d as ad,b as gn,h as o_,l as d_,m as u_,u as qm,r as m_,a as x_,a2 as h_,a3 as qj,a4 as f_,a5 as p_,a6 as g_,a7 as Kj,a8 as Qj,a9 as Yj,aa as Jj,ab as Xj,ac as Zj,ad as j_}from"./radix-core-DyJi0yyw.js";import{R as dt,a as lc,C as _t,b as pt,L as zs,X as Aa,c as Ct,d as za,e as Qr,f as Da,g as Wt,E as v_,h as na,i as Ka,S as Tt,B as Vn,U as jn,P as hc,Z as el,j as Wj,F as Ea,k as N_,l as vn,m as b_,M as Ra,A as sx,D as y_,n as Yr,T as tx,o as w_,p as ev,I as Ft,q as Jt,r as Fo,s as nc,t as ia,H as __,u as ns,v as Xt,w as rc,x as ax,y as ec,z as bg,K as lx,G as sv,J as S_,N as $o,O as k_,Q as ld,V as C_,W as T_,Y as nd,_ as Ma,$ as et,a0 as nx,a1 as tv,a2 as fc,a3 as av,a4 as lv,a5 as Kn,a6 as Nn,a7 as bn,a8 as rx,a9 as nv,aa as ra,ab as Ll,ac as Qn,ad as Yn,ae as rd,af as E_,ag as M_,ah as A_,ai as ix,aj as Bo,ak as Jn,al as z_,am as Jr,an as Ho,ao as R_,ap as Vo,aq as ic,ar as rv,as as D_,at as O_,au as Go,av as L_,aw as cx,ax as U_,ay as yg,az as $_,aA as B_,aB as iv,aC as P_,aD as mn,aE as cv,aF as Em,aG as wg,aH as I_,aI as Mm,aJ as F_,aK as H_,aL as V_,aM as G_,aN as ov,aO as q_,aP as Xr,aQ as K_,aR as Q_,aS as dv,aT as uv,aU as Y_,aV as J_,aW as _g,aX as X_,aY as Z_,aZ as W_,a_ as e1,a$ as s1}from"./icons-9Z4kBNLK.js";import{S as t1,p as a1,j as l1,a as n1,E as Sg,R as r1,o as i1}from"./codemirror-TZqPU532.js";import{u as mv,a as qo,s as xv,K as hv,P as fv,b as pv,D as gv,c as jv,S as vv,v as c1,d as Nv,C as bv,h as o1}from"./dnd-BiPfFtVp.js";import{_ as ja,c as d1,g as yv,D as u1,z as Ro}from"./misc-CJqnlRwD.js";import{D as m1,U as x1}from"./uppy-DFP_VzYR.js";import{M as h1,r as f1,a as p1,b as g1}from"./markdown-CKA5gBQ9.js";import{c as j1,H as Ko,P as Qo,u as v1,d as N1,R as b1,B as y1,e as w1,C as _1,M as S1,f as k1}from"./reactflow-DtsZHOR4.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const d of document.querySelectorAll('link[rel="modulepreload"]'))c(d);new MutationObserver(d=>{for(const u of d)if(u.type==="childList")for(const h of u.addedNodes)h.tagName==="LINK"&&h.rel==="modulepreload"&&c(h)}).observe(document,{childList:!0,subtree:!0});function r(d){const u={};return d.integrity&&(u.integrity=d.integrity),d.referrerPolicy&&(u.referrerPolicy=d.referrerPolicy),d.crossOrigin==="use-credentials"?u.credentials="include":d.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function c(d){if(d.ep)return;d.ep=!0;const u=r(d);fetch(d.href,u)}})();var Am={exports:{}},Gi={},zm={exports:{}},Rm={};var kg;function C1(){return kg||(kg=1,(function(a){function n(R,Y){var $=R.length;R.push(Y);e:for(;0<$;){var ue=$-1>>>1,G=R[ue];if(0>>1;ued(Te,$))qd(B,Te)?(R[ue]=B,R[q]=$,ue=q):(R[ue]=Te,R[fe]=$,ue=fe);else if(qd(B,$))R[ue]=B,R[q]=$,ue=q;else break e}}return Y}function d(R,Y){var $=R.sortIndex-Y.sortIndex;return $!==0?$:R.id-Y.id}if(a.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var u=performance;a.unstable_now=function(){return u.now()}}else{var h=Date,f=h.now();a.unstable_now=function(){return h.now()-f}}var p=[],g=[],N=1,v=null,w=3,b=!1,y=!1,A=!1,z=!1,S=typeof setTimeout=="function"?setTimeout:null,U=typeof clearTimeout=="function"?clearTimeout:null,E=typeof setImmediate<"u"?setImmediate:null;function C(R){for(var Y=r(g);Y!==null;){if(Y.callback===null)c(g);else if(Y.startTime<=R)c(g),Y.sortIndex=Y.expirationTime,n(p,Y);else break;Y=r(g)}}function D(R){if(A=!1,C(R),!y)if(r(p)!==null)y=!0,I||(I=!0,je());else{var Y=r(g);Y!==null&&ge(D,Y.startTime-R)}}var I=!1,O=-1,X=5,L=-1;function oe(){return z?!0:!(a.unstable_now()-LR&&oe());){var ue=v.callback;if(typeof ue=="function"){v.callback=null,w=v.priorityLevel;var G=ue(v.expirationTime<=R);if(R=a.unstable_now(),typeof G=="function"){v.callback=G,C(R),Y=!0;break s}v===r(p)&&c(p),C(R)}else c(p);v=r(p)}if(v!==null)Y=!0;else{var Se=r(g);Se!==null&&ge(D,Se.startTime-R),Y=!1}}break e}finally{v=null,w=$,b=!1}Y=void 0}}finally{Y?je():I=!1}}}var je;if(typeof E=="function")je=function(){E(Ne)};else if(typeof MessageChannel<"u"){var de=new MessageChannel,he=de.port2;de.port1.onmessage=Ne,je=function(){he.postMessage(null)}}else je=function(){S(Ne,0)};function ge(R,Y){O=S(function(){R(a.unstable_now())},Y)}a.unstable_IdlePriority=5,a.unstable_ImmediatePriority=1,a.unstable_LowPriority=4,a.unstable_NormalPriority=3,a.unstable_Profiling=null,a.unstable_UserBlockingPriority=2,a.unstable_cancelCallback=function(R){R.callback=null},a.unstable_forceFrameRate=function(R){0>R||125ue?(R.sortIndex=$,n(g,R),r(p)===null&&R===r(g)&&(A?(U(O),O=-1):A=!0,ge(D,$-ue))):(R.sortIndex=G,n(p,R),y||b||(y=!0,I||(I=!0,je()))),R},a.unstable_shouldYield=oe,a.unstable_wrapCallback=function(R){var Y=w;return function(){var $=w;w=Y;try{return R.apply(this,arguments)}finally{w=$}}}})(Rm)),Rm}var Cg;function T1(){return Cg||(Cg=1,zm.exports=C1()),zm.exports}var Tg;function E1(){if(Tg)return Gi;Tg=1;var a=T1(),n=tw(),r=aw();function c(s){var t="https://react.dev/errors/"+s;if(1G||(s.current=ue[G],ue[G]=null,G--)}function Te(s,t){G++,ue[G]=s.current,s.current=t}var q=Se(null),B=Se(null),M=Se(null),Q=Se(null);function Ae(s,t){switch(Te(M,t),Te(B,s),Te(q,null),t.nodeType){case 9:case 11:s=(s=t.documentElement)&&(s=s.namespaceURI)?Vp(s):0;break;default:if(s=t.tagName,t=t.namespaceURI)t=Vp(t),s=Gp(t,s);else switch(s){case"svg":s=1;break;case"math":s=2;break;default:s=0}}fe(q),Te(q,s)}function ee(){fe(q),fe(B),fe(M)}function J(s){s.memoizedState!==null&&Te(Q,s);var t=q.current,l=Gp(t,s.type);t!==l&&(Te(B,s),Te(q,l))}function $e(s){B.current===s&&(fe(q),fe(B)),Q.current===s&&(fe(Q),Ii._currentValue=$)}var H,se;function Ue(s){if(H===void 0)try{throw Error()}catch(l){var t=l.stack.trim().match(/\n( *(at )?)/);H=t&&t[1]||"",se=-1)":-1o||P[i]!==ne[o]){var ve=` +`+P[i].replace(" at new "," at ");return s.displayName&&ve.includes("")&&(ve=ve.replace("",s.displayName)),ve}while(1<=i&&0<=o);break}}}finally{ie=!1,Error.prepareStackTrace=l}return(l=s?s.displayName||s.name:"")?Ue(l):""}function me(s,t){switch(s.tag){case 26:case 27:case 5:return Ue(s.type);case 16:return Ue("Lazy");case 13:return s.child!==t&&t!==null?Ue("Suspense Fallback"):Ue("Suspense");case 19:return Ue("SuspenseList");case 0:case 15:return Ee(s.type,!1);case 11:return Ee(s.type.render,!1);case 1:return Ee(s.type,!0);case 31:return Ue("Activity");default:return""}}function ze(s){try{var t="",l=null;do t+=me(s,l),l=s,s=s.return;while(s);return t}catch(i){return` +Error generating stack: `+i.message+` +`+i.stack}}var rs=Object.prototype.hasOwnProperty,Ut=a.unstable_scheduleCallback,aa=a.unstable_cancelCallback,Ja=a.unstable_shouldYield,Ht=a.unstable_requestPaint,mt=a.unstable_now,K=a.unstable_getCurrentPriorityLevel,qe=a.unstable_ImmediatePriority,Qe=a.unstable_UserBlockingPriority,es=a.unstable_NormalPriority,Us=a.unstable_LowPriority,as=a.unstable_IdlePriority,Cs=a.log,Re=a.unstable_setDisableYieldValue,bs=null,ls=null;function ss(s){if(typeof Cs=="function"&&Re(s),ls&&typeof ls.setStrictMode=="function")try{ls.setStrictMode(bs,s)}catch{}}var ys=Math.clz32?Math.clz32:tt,gt=Math.log,$t=Math.LN2;function tt(s){return s>>>=0,s===0?32:31-(gt(s)/$t|0)|0}var Ms=256,Et=262144,Bt=4194304;function Oa(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 ll(s,t,l){var i=s.pendingLanes;if(i===0)return 0;var o=0,x=s.suspendedLanes,j=s.pingedLanes;s=s.warmLanes;var k=i&134217727;return k!==0?(i=k&~x,i!==0?o=Oa(i):(j&=k,j!==0?o=Oa(j):l||(l=k&~s,l!==0&&(o=Oa(l))))):(k=i&~x,k!==0?o=Oa(k):j!==0?o=Oa(j):l||(l=i&~s,l!==0&&(o=Oa(l)))),o===0?0:t!==0&&t!==o&&(t&x)===0&&(x=o&-o,l=t&-t,x>=l||x===32&&(l&4194048)!==0)?t:o}function xl(s,t){return(s.pendingLanes&~(s.suspendedLanes&~s.pingedLanes)&t)===0}function sr(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 te(){var s=Bt;return Bt<<=1,(Bt&62914560)===0&&(Bt=4194304),s}function we(s){for(var t=[],l=0;31>l;l++)t.push(s);return t}function Le(s,t){s.pendingLanes|=t,t!==268435456&&(s.suspendedLanes=0,s.pingedLanes=0,s.warmLanes=0)}function Fs(s,t,l,i,o,x){var j=s.pendingLanes;s.pendingLanes=l,s.suspendedLanes=0,s.pingedLanes=0,s.warmLanes=0,s.expiredLanes&=l,s.entangledLanes&=l,s.errorRecoveryDisabledLanes&=l,s.shellSuspendCounter=0;var k=s.entanglements,P=s.expirationTimes,ne=s.hiddenUpdates;for(l=j&~l;0"u")return null;try{return s.activeElement||s.body}catch{return s.body}}var Fb=/[\n"\\]/g;function Ua(s){return s.replace(Fb,function(t){return"\\"+t.charCodeAt(0).toString(16)+" "})}function yd(s,t,l,i,o,x,j,k){s.name="",j!=null&&typeof j!="function"&&typeof j!="symbol"&&typeof j!="boolean"?s.type=j:s.removeAttribute("type"),t!=null?j==="number"?(t===0&&s.value===""||s.value!=t)&&(s.value=""+La(t)):s.value!==""+La(t)&&(s.value=""+La(t)):j!=="submit"&&j!=="reset"||s.removeAttribute("value"),t!=null?wd(s,j,La(t)):l!=null?wd(s,j,La(l)):i!=null&&s.removeAttribute("value"),o==null&&x!=null&&(s.defaultChecked=!!x),o!=null&&(s.checked=o&&typeof o!="function"&&typeof o!="symbol"),k!=null&&typeof k!="function"&&typeof k!="symbol"&&typeof k!="boolean"?s.name=""+La(k):s.removeAttribute("name")}function Ux(s,t,l,i,o,x,j,k){if(x!=null&&typeof x!="function"&&typeof x!="symbol"&&typeof x!="boolean"&&(s.type=x),t!=null||l!=null){if(!(x!=="submit"&&x!=="reset"||t!=null)){bd(s);return}l=l!=null?""+La(l):"",t=t!=null?""+La(t):l,k||t===s.value||(s.value=t),s.defaultValue=t}i=i??o,i=typeof i!="function"&&typeof i!="symbol"&&!!i,s.checked=k?s.checked:!!i,s.defaultChecked=!!i,j!=null&&typeof j!="function"&&typeof j!="symbol"&&typeof j!="boolean"&&(s.name=j),bd(s)}function wd(s,t,l){t==="number"&&yc(s.ownerDocument)===s||s.defaultValue===""+l||(s.defaultValue=""+l)}function ir(s,t,l,i){if(s=s.options,t){t={};for(var o=0;o"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Td=!1;if(pl)try{var ni={};Object.defineProperty(ni,"passive",{get:function(){Td=!0}}),window.addEventListener("test",ni,ni),window.removeEventListener("test",ni,ni)}catch{Td=!1}var Fl=null,Ed=null,_c=null;function Vx(){if(_c)return _c;var s,t=Ed,l=t.length,i,o="value"in Fl?Fl.value:Fl.textContent,x=o.length;for(s=0;s=ci),Jx=" ",Xx=!1;function Zx(s,t){switch(s){case"keyup":return py.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Wx(s){return s=s.detail,typeof s=="object"&&"data"in s?s.data:null}var ur=!1;function jy(s,t){switch(s){case"compositionend":return Wx(t);case"keypress":return t.which!==32?null:(Xx=!0,Jx);case"textInput":return s=t.data,s===Jx&&Xx?null:s;default:return null}}function vy(s,t){if(ur)return s==="compositionend"||!Dd&&Zx(s,t)?(s=Vx(),_c=Ed=Fl=null,ur=!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:l,offset:t-s};s=i}e:{for(;l;){if(l.nextSibling){l=l.nextSibling;break e}l=l.parentNode}l=void 0}l=ih(l)}}function oh(s,t){return s&&t?s===t?!0:s&&s.nodeType===3?!1:t&&t.nodeType===3?oh(s,t.parentNode):"contains"in s?s.contains(t):s.compareDocumentPosition?!!(s.compareDocumentPosition(t)&16):!1:!1}function dh(s){s=s!=null&&s.ownerDocument!=null&&s.ownerDocument.defaultView!=null?s.ownerDocument.defaultView:window;for(var t=yc(s.document);t instanceof s.HTMLIFrameElement;){try{var l=typeof t.contentWindow.location.href=="string"}catch{l=!1}if(l)s=t.contentWindow;else break;t=yc(s.document)}return t}function Ud(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 Cy=pl&&"documentMode"in document&&11>=document.documentMode,mr=null,$d=null,mi=null,Bd=!1;function uh(s,t,l){var i=l.window===l?l.document:l.nodeType===9?l:l.ownerDocument;Bd||mr==null||mr!==yc(i)||(i=mr,"selectionStart"in i&&Ud(i)?i={start:i.selectionStart,end:i.selectionEnd}:(i=(i.ownerDocument&&i.ownerDocument.defaultView||window).getSelection(),i={anchorNode:i.anchorNode,anchorOffset:i.anchorOffset,focusNode:i.focusNode,focusOffset:i.focusOffset}),mi&&ui(mi,i)||(mi=i,i=jo($d,"onSelect"),0>=j,o-=j,nl=1<<32-ys(t)+o|l<ds?(Es=Ge,Ge=null):Es=Ge.sibling;var Bs=ce(Z,Ge,ae[ds],be);if(Bs===null){Ge===null&&(Ge=Es);break}s&&Ge&&Bs.alternate===null&&t(Z,Ge),V=x(Bs,V,ds),$s===null?Ye=Bs:$s.sibling=Bs,$s=Bs,Ge=Es}if(ds===ae.length)return l(Z,Ge),As&&jl(Z,ds),Ye;if(Ge===null){for(;dsds?(Es=Ge,Ge=null):Es=Ge.sibling;var un=ce(Z,Ge,Bs.value,be);if(un===null){Ge===null&&(Ge=Es);break}s&&Ge&&un.alternate===null&&t(Z,Ge),V=x(un,V,ds),$s===null?Ye=un:$s.sibling=un,$s=un,Ge=Es}if(Bs.done)return l(Z,Ge),As&&jl(Z,ds),Ye;if(Ge===null){for(;!Bs.done;ds++,Bs=ae.next())Bs=ye(Z,Bs.value,be),Bs!==null&&(V=x(Bs,V,ds),$s===null?Ye=Bs:$s.sibling=Bs,$s=Bs);return As&&jl(Z,ds),Ye}for(Ge=i(Ge);!Bs.done;ds++,Bs=ae.next())Bs=xe(Ge,Z,ds,Bs.value,be),Bs!==null&&(s&&Bs.alternate!==null&&Ge.delete(Bs.key===null?ds:Bs.key),V=x(Bs,V,ds),$s===null?Ye=Bs:$s.sibling=Bs,$s=Bs);return s&&Ge.forEach(function(K0){return t(Z,K0)}),As&&jl(Z,ds),Ye}function Zs(Z,V,ae,be){if(typeof ae=="object"&&ae!==null&&ae.type===A&&ae.key===null&&(ae=ae.props.children),typeof ae=="object"&&ae!==null){switch(ae.$$typeof){case b:e:{for(var Ye=ae.key;V!==null;){if(V.key===Ye){if(Ye=ae.type,Ye===A){if(V.tag===7){l(Z,V.sibling),be=o(V,ae.props.children),be.return=Z,Z=be;break e}}else if(V.elementType===Ye||typeof Ye=="object"&&Ye!==null&&Ye.$$typeof===X&&On(Ye)===V.type){l(Z,V.sibling),be=o(V,ae.props),ji(be,ae),be.return=Z,Z=be;break e}l(Z,V);break}else t(Z,V);V=V.sibling}ae.type===A?(be=Mn(ae.props.children,Z.mode,be,ae.key),be.return=Z,Z=be):(be=Dc(ae.type,ae.key,ae.props,null,Z.mode,be),ji(be,ae),be.return=Z,Z=be)}return j(Z);case y:e:{for(Ye=ae.key;V!==null;){if(V.key===Ye)if(V.tag===4&&V.stateNode.containerInfo===ae.containerInfo&&V.stateNode.implementation===ae.implementation){l(Z,V.sibling),be=o(V,ae.children||[]),be.return=Z,Z=be;break e}else{l(Z,V);break}else t(Z,V);V=V.sibling}be=qd(ae,Z.mode,be),be.return=Z,Z=be}return j(Z);case X:return ae=On(ae),Zs(Z,V,ae,be)}if(ge(ae))return He(Z,V,ae,be);if(je(ae)){if(Ye=je(ae),typeof Ye!="function")throw Error(c(150));return ae=Ye.call(ae),Ze(Z,V,ae,be)}if(typeof ae.then=="function")return Zs(Z,V,Ic(ae),be);if(ae.$$typeof===E)return Zs(Z,V,Uc(Z,ae),be);Fc(Z,ae)}return typeof ae=="string"&&ae!==""||typeof ae=="number"||typeof ae=="bigint"?(ae=""+ae,V!==null&&V.tag===6?(l(Z,V.sibling),be=o(V,ae),be.return=Z,Z=be):(l(Z,V),be=Gd(ae,Z.mode,be),be.return=Z,Z=be),j(Z)):l(Z,V)}return function(Z,V,ae,be){try{gi=0;var Ye=Zs(Z,V,ae,be);return wr=null,Ye}catch(Ge){if(Ge===yr||Ge===Bc)throw Ge;var $s=ba(29,Ge,null,Z.mode);return $s.lanes=be,$s.return=Z,$s}finally{}}}var Un=Dh(!0),Oh=Dh(!1),Kl=!1;function lu(s){s.updateQueue={baseState:s.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function nu(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 Ql(s){return{lane:s,tag:0,payload:null,callback:null,next:null}}function Yl(s,t,l){var i=s.updateQueue;if(i===null)return null;if(i=i.shared,(Is&2)!==0){var o=i.pending;return o===null?t.next=t:(t.next=o.next,o.next=t),i.pending=t,t=Rc(s),jh(s,null,l),t}return zc(s,i,t,l),Rc(s)}function vi(s,t,l){if(t=t.updateQueue,t!==null&&(t=t.shared,(l&4194048)!==0)){var i=t.lanes;i&=s.pendingLanes,l|=i,t.lanes=l,ea(s,l)}}function ru(s,t){var l=s.updateQueue,i=s.alternate;if(i!==null&&(i=i.updateQueue,l===i)){var o=null,x=null;if(l=l.firstBaseUpdate,l!==null){do{var j={lane:l.lane,tag:l.tag,payload:l.payload,callback:null,next:null};x===null?o=x=j:x=x.next=j,l=l.next}while(l!==null);x===null?o=x=t:x=x.next=t}else o=x=t;l={baseState:i.baseState,firstBaseUpdate:o,lastBaseUpdate:x,shared:i.shared,callbacks:i.callbacks},s.updateQueue=l;return}s=l.lastBaseUpdate,s===null?l.firstBaseUpdate=t:s.next=t,l.lastBaseUpdate=t}var iu=!1;function Ni(){if(iu){var s=br;if(s!==null)throw s}}function bi(s,t,l,i){iu=!1;var o=s.updateQueue;Kl=!1;var x=o.firstBaseUpdate,j=o.lastBaseUpdate,k=o.shared.pending;if(k!==null){o.shared.pending=null;var P=k,ne=P.next;P.next=null,j===null?x=ne:j.next=ne,j=P;var ve=s.alternate;ve!==null&&(ve=ve.updateQueue,k=ve.lastBaseUpdate,k!==j&&(k===null?ve.firstBaseUpdate=ne:k.next=ne,ve.lastBaseUpdate=P))}if(x!==null){var ye=o.baseState;j=0,ve=ne=P=null,k=x;do{var ce=k.lane&-536870913,xe=ce!==k.lane;if(xe?(Ts&ce)===ce:(i&ce)===ce){ce!==0&&ce===Nr&&(iu=!0),ve!==null&&(ve=ve.next={lane:0,tag:k.tag,payload:k.payload,callback:null,next:null});e:{var He=s,Ze=k;ce=t;var Zs=l;switch(Ze.tag){case 1:if(He=Ze.payload,typeof He=="function"){ye=He.call(Zs,ye,ce);break e}ye=He;break e;case 3:He.flags=He.flags&-65537|128;case 0:if(He=Ze.payload,ce=typeof He=="function"?He.call(Zs,ye,ce):He,ce==null)break e;ye=v({},ye,ce);break e;case 2:Kl=!0}}ce=k.callback,ce!==null&&(s.flags|=64,xe&&(s.flags|=8192),xe=o.callbacks,xe===null?o.callbacks=[ce]:xe.push(ce))}else xe={lane:ce,tag:k.tag,payload:k.payload,callback:k.callback,next:null},ve===null?(ne=ve=xe,P=ye):ve=ve.next=xe,j|=ce;if(k=k.next,k===null){if(k=o.shared.pending,k===null)break;xe=k,k=xe.next,xe.next=null,o.lastBaseUpdate=xe,o.shared.pending=null}}while(!0);ve===null&&(P=ye),o.baseState=P,o.firstBaseUpdate=ne,o.lastBaseUpdate=ve,x===null&&(o.shared.lanes=0),en|=j,s.lanes=j,s.memoizedState=ye}}function Lh(s,t){if(typeof s!="function")throw Error(c(191,s));s.call(t)}function Uh(s,t){var l=s.callbacks;if(l!==null)for(s.callbacks=null,s=0;sx?x:8;var j=R.T,k={};R.T=k,ku(s,!1,t,l);try{var P=o(),ne=R.S;if(ne!==null&&ne(k,P),P!==null&&typeof P=="object"&&typeof P.then=="function"){var ve=Ly(P,i);_i(s,t,ve,ka(s))}else _i(s,t,i,ka(s))}catch(ye){_i(s,t,{then:function(){},status:"rejected",reason:ye},ka())}finally{Y.p=x,j!==null&&k.types!==null&&(j.types=k.types),R.T=j}}function Fy(){}function _u(s,t,l,i){if(s.tag!==5)throw Error(c(476));var o=pf(s).queue;ff(s,o,t,$,l===null?Fy:function(){return gf(s),l(i)})}function pf(s){var t=s.memoizedState;if(t!==null)return t;t={memoizedState:$,baseState:$,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:yl,lastRenderedState:$},next:null};var l={};return t.next={memoizedState:l,baseState:l,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:yl,lastRenderedState:l},next:null},s.memoizedState=t,s=s.alternate,s!==null&&(s.memoizedState=t),t}function gf(s){var t=pf(s);t.next===null&&(t=s.alternate.memoizedState),_i(s,t.next.queue,{},ka())}function Su(){return Gt(Ii)}function jf(){return kt().memoizedState}function vf(){return kt().memoizedState}function Hy(s){for(var t=s.return;t!==null;){switch(t.tag){case 24:case 3:var l=ka();s=Ql(l);var i=Yl(t,s,l);i!==null&&(fa(i,t,l),vi(i,t,l)),t={cache:eu()},s.payload=t;return}t=t.return}}function Vy(s,t,l){var i=ka();l={lane:i,revertLane:0,gesture:null,action:l,hasEagerState:!1,eagerState:null,next:null},Zc(s)?bf(t,l):(l=Hd(s,t,l,i),l!==null&&(fa(l,s,i),yf(l,t,i)))}function Nf(s,t,l){var i=ka();_i(s,t,l,i)}function _i(s,t,l,i){var o={lane:i,revertLane:0,gesture:null,action:l,hasEagerState:!1,eagerState:null,next:null};if(Zc(s))bf(t,o);else{var x=s.alternate;if(s.lanes===0&&(x===null||x.lanes===0)&&(x=t.lastRenderedReducer,x!==null))try{var j=t.lastRenderedState,k=x(j,l);if(o.hasEagerState=!0,o.eagerState=k,Na(k,j))return zc(s,t,o,0),Ws===null&&Ac(),!1}catch{}finally{}if(l=Hd(s,t,o,i),l!==null)return fa(l,s,i),yf(l,t,i),!0}return!1}function ku(s,t,l,i){if(i={lane:2,revertLane:lm(),gesture:null,action:i,hasEagerState:!1,eagerState:null,next:null},Zc(s)){if(t)throw Error(c(479))}else t=Hd(s,l,i,2),t!==null&&fa(t,s,2)}function Zc(s){var t=s.alternate;return s===cs||t!==null&&t===cs}function bf(s,t){Sr=Gc=!0;var l=s.pending;l===null?t.next=t:(t.next=l.next,l.next=t),s.pending=t}function yf(s,t,l){if((l&4194048)!==0){var i=t.lanes;i&=s.pendingLanes,l|=i,t.lanes=l,ea(s,l)}}var Si={readContext:Gt,use:Qc,useCallback:vt,useContext:vt,useEffect:vt,useImperativeHandle:vt,useLayoutEffect:vt,useInsertionEffect:vt,useMemo:vt,useReducer:vt,useRef:vt,useState:vt,useDebugValue:vt,useDeferredValue:vt,useTransition:vt,useSyncExternalStore:vt,useId:vt,useHostTransitionStatus:vt,useFormState:vt,useActionState:vt,useOptimistic:vt,useMemoCache:vt,useCacheRefresh:vt};Si.useEffectEvent=vt;var wf={readContext:Gt,use:Qc,useCallback:function(s,t){return la().memoizedState=[s,t===void 0?null:t],s},useContext:Gt,useEffect:nf,useImperativeHandle:function(s,t,l){l=l!=null?l.concat([s]):null,Jc(4194308,4,df.bind(null,t,s),l)},useLayoutEffect:function(s,t){return Jc(4194308,4,s,t)},useInsertionEffect:function(s,t){Jc(4,2,s,t)},useMemo:function(s,t){var l=la();t=t===void 0?null:t;var i=s();if($n){ss(!0);try{s()}finally{ss(!1)}}return l.memoizedState=[i,t],i},useReducer:function(s,t,l){var i=la();if(l!==void 0){var o=l(t);if($n){ss(!0);try{l(t)}finally{ss(!1)}}}else o=t;return i.memoizedState=i.baseState=o,s={pending:null,lanes:0,dispatch:null,lastRenderedReducer:s,lastRenderedState:o},i.queue=s,s=s.dispatch=Vy.bind(null,cs,s),[i.memoizedState,s]},useRef:function(s){var t=la();return s={current:s},t.memoizedState=s},useState:function(s){s=vu(s);var t=s.queue,l=Nf.bind(null,cs,t);return t.dispatch=l,[s.memoizedState,l]},useDebugValue:yu,useDeferredValue:function(s,t){var l=la();return wu(l,s,t)},useTransition:function(){var s=vu(!1);return s=ff.bind(null,cs,s.queue,!0,!1),la().memoizedState=s,[!1,s]},useSyncExternalStore:function(s,t,l){var i=cs,o=la();if(As){if(l===void 0)throw Error(c(407));l=l()}else{if(l=t(),Ws===null)throw Error(c(349));(Ts&127)!==0||Hh(i,t,l)}o.memoizedState=l;var x={value:l,getSnapshot:t};return o.queue=x,nf(Gh.bind(null,i,x,s),[s]),i.flags|=2048,Cr(9,{destroy:void 0},Vh.bind(null,i,x,l,t),null),l},useId:function(){var s=la(),t=Ws.identifierPrefix;if(As){var l=rl,i=nl;l=(i&~(1<<32-ys(i)-1)).toString(32)+l,t="_"+t+"R_"+l,l=qc++,0<\/script>",x=x.removeChild(x.firstChild);break;case"select":x=typeof i.is=="string"?j.createElement("select",{is:i.is}):j.createElement("select"),i.multiple?x.multiple=!0:i.size&&(x.size=i.size);break;default:x=typeof i.is=="string"?j.createElement(o,{is:i.is}):j.createElement(o)}}x[js]=t,x[is]=i;e:for(j=t.child;j!==null;){if(j.tag===5||j.tag===6)x.appendChild(j.stateNode);else if(j.tag!==4&&j.tag!==27&&j.child!==null){j.child.return=j,j=j.child;continue}if(j===t)break e;for(;j.sibling===null;){if(j.return===null||j.return===t)break e;j=j.return}j.sibling.return=j.return,j=j.sibling}t.stateNode=x;e:switch(Kt(x,o,i),o){case"button":case"input":case"select":case"textarea":i=!!i.autoFocus;break e;case"img":i=!0;break e;default:i=!1}i&&_l(t)}}return ct(t),Pu(t,t.type,s===null?null:s.memoizedProps,t.pendingProps,l),null;case 6:if(s&&t.stateNode!=null)s.memoizedProps!==i&&_l(t);else{if(typeof i!="string"&&t.stateNode===null)throw Error(c(166));if(s=M.current,jr(t)){if(s=t.stateNode,l=t.memoizedProps,i=null,o=Vt,o!==null)switch(o.tag){case 27:case 5:i=o.memoizedProps}s[js]=t,s=!!(s.nodeValue===l||i!==null&&i.suppressHydrationWarning===!0||Fp(s.nodeValue,l)),s||Gl(t,!0)}else s=vo(s).createTextNode(i),s[js]=t,t.stateNode=s}return ct(t),null;case 31:if(l=t.memoizedState,s===null||s.memoizedState!==null){if(i=jr(t),l!==null){if(s===null){if(!i)throw Error(c(318));if(s=t.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(c(557));s[js]=t}else An(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;ct(t),s=!1}else l=Jd(),s!==null&&s.memoizedState!==null&&(s.memoizedState.hydrationErrors=l),s=!0;if(!s)return t.flags&256?(wa(t),t):(wa(t),null);if((t.flags&128)!==0)throw Error(c(558))}return ct(t),null;case 13:if(i=t.memoizedState,s===null||s.memoizedState!==null&&s.memoizedState.dehydrated!==null){if(o=jr(t),i!==null&&i.dehydrated!==null){if(s===null){if(!o)throw Error(c(318));if(o=t.memoizedState,o=o!==null?o.dehydrated:null,!o)throw Error(c(317));o[js]=t}else An(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;ct(t),o=!1}else o=Jd(),s!==null&&s.memoizedState!==null&&(s.memoizedState.hydrationErrors=o),o=!0;if(!o)return t.flags&256?(wa(t),t):(wa(t),null)}return wa(t),(t.flags&128)!==0?(t.lanes=l,t):(l=i!==null,s=s!==null&&s.memoizedState!==null,l&&(i=t.child,o=null,i.alternate!==null&&i.alternate.memoizedState!==null&&i.alternate.memoizedState.cachePool!==null&&(o=i.alternate.memoizedState.cachePool.pool),x=null,i.memoizedState!==null&&i.memoizedState.cachePool!==null&&(x=i.memoizedState.cachePool.pool),x!==o&&(i.flags|=2048)),l!==s&&l&&(t.child.flags|=8192),ao(t,t.updateQueue),ct(t),null);case 4:return ee(),s===null&&cm(t.stateNode.containerInfo),ct(t),null;case 10:return Nl(t.type),ct(t),null;case 19:if(fe(St),i=t.memoizedState,i===null)return ct(t),null;if(o=(t.flags&128)!==0,x=i.rendering,x===null)if(o)Ci(i,!1);else{if(Nt!==0||s!==null&&(s.flags&128)!==0)for(s=t.child;s!==null;){if(x=Vc(s),x!==null){for(t.flags|=128,Ci(i,!1),s=x.updateQueue,t.updateQueue=s,ao(t,s),t.subtreeFlags=0,s=l,l=t.child;l!==null;)vh(l,s),l=l.sibling;return Te(St,St.current&1|2),As&&jl(t,i.treeForkCount),t.child}s=s.sibling}i.tail!==null&&mt()>co&&(t.flags|=128,o=!0,Ci(i,!1),t.lanes=4194304)}else{if(!o)if(s=Vc(x),s!==null){if(t.flags|=128,o=!0,s=s.updateQueue,t.updateQueue=s,ao(t,s),Ci(i,!0),i.tail===null&&i.tailMode==="hidden"&&!x.alternate&&!As)return ct(t),null}else 2*mt()-i.renderingStartTime>co&&l!==536870912&&(t.flags|=128,o=!0,Ci(i,!1),t.lanes=4194304);i.isBackwards?(x.sibling=t.child,t.child=x):(s=i.last,s!==null?s.sibling=x:t.child=x,i.last=x)}return i.tail!==null?(s=i.tail,i.rendering=s,i.tail=s.sibling,i.renderingStartTime=mt(),s.sibling=null,l=St.current,Te(St,o?l&1|2:l&1),As&&jl(t,i.treeForkCount),s):(ct(t),null);case 22:case 23:return wa(t),ou(),i=t.memoizedState!==null,s!==null?s.memoizedState!==null!==i&&(t.flags|=8192):i&&(t.flags|=8192),i?(l&536870912)!==0&&(t.flags&128)===0&&(ct(t),t.subtreeFlags&6&&(t.flags|=8192)):ct(t),l=t.updateQueue,l!==null&&ao(t,l.retryQueue),l=null,s!==null&&s.memoizedState!==null&&s.memoizedState.cachePool!==null&&(l=s.memoizedState.cachePool.pool),i=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(i=t.memoizedState.cachePool.pool),i!==l&&(t.flags|=2048),s!==null&&fe(Dn),null;case 24:return l=null,s!==null&&(l=s.memoizedState.cache),t.memoizedState.cache!==l&&(t.flags|=2048),Nl(Mt),ct(t),null;case 25:return null;case 30:return null}throw Error(c(156,t.tag))}function Yy(s,t){switch(Qd(t),t.tag){case 1:return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 3:return Nl(Mt),ee(),s=t.flags,(s&65536)!==0&&(s&128)===0?(t.flags=s&-65537|128,t):null;case 26:case 27:case 5:return $e(t),null;case 31:if(t.memoizedState!==null){if(wa(t),t.alternate===null)throw Error(c(340));An()}return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 13:if(wa(t),s=t.memoizedState,s!==null&&s.dehydrated!==null){if(t.alternate===null)throw Error(c(340));An()}return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 19:return fe(St),null;case 4:return ee(),null;case 10:return Nl(t.type),null;case 22:case 23:return wa(t),ou(),s!==null&&fe(Dn),s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 24:return Nl(Mt),null;case 25:return null;default:return null}}function Kf(s,t){switch(Qd(t),t.tag){case 3:Nl(Mt),ee();break;case 26:case 27:case 5:$e(t);break;case 4:ee();break;case 31:t.memoizedState!==null&&wa(t);break;case 13:wa(t);break;case 19:fe(St);break;case 10:Nl(t.type);break;case 22:case 23:wa(t),ou(),s!==null&&fe(Dn);break;case 24:Nl(Mt)}}function Ti(s,t){try{var l=t.updateQueue,i=l!==null?l.lastEffect:null;if(i!==null){var o=i.next;l=o;do{if((l.tag&s)===s){i=void 0;var x=l.create,j=l.inst;i=x(),j.destroy=i}l=l.next}while(l!==o)}}catch(k){Gs(t,t.return,k)}}function Zl(s,t,l){try{var i=t.updateQueue,o=i!==null?i.lastEffect:null;if(o!==null){var x=o.next;i=x;do{if((i.tag&s)===s){var j=i.inst,k=j.destroy;if(k!==void 0){j.destroy=void 0,o=t;var P=l,ne=k;try{ne()}catch(ve){Gs(o,P,ve)}}}i=i.next}while(i!==x)}}catch(ve){Gs(t,t.return,ve)}}function Qf(s){var t=s.updateQueue;if(t!==null){var l=s.stateNode;try{Uh(t,l)}catch(i){Gs(s,s.return,i)}}}function Yf(s,t,l){l.props=Bn(s.type,s.memoizedProps),l.state=s.memoizedState;try{l.componentWillUnmount()}catch(i){Gs(s,t,i)}}function Ei(s,t){try{var l=s.ref;if(l!==null){switch(s.tag){case 26:case 27:case 5:var i=s.stateNode;break;case 30:i=s.stateNode;break;default:i=s.stateNode}typeof l=="function"?s.refCleanup=l(i):l.current=i}}catch(o){Gs(s,t,o)}}function il(s,t){var l=s.ref,i=s.refCleanup;if(l!==null)if(typeof i=="function")try{i()}catch(o){Gs(s,t,o)}finally{s.refCleanup=null,s=s.alternate,s!=null&&(s.refCleanup=null)}else if(typeof l=="function")try{l(null)}catch(o){Gs(s,t,o)}else l.current=null}function Jf(s){var t=s.type,l=s.memoizedProps,i=s.stateNode;try{e:switch(t){case"button":case"input":case"select":case"textarea":l.autoFocus&&i.focus();break e;case"img":l.src?i.src=l.src:l.srcSet&&(i.srcset=l.srcSet)}}catch(o){Gs(s,s.return,o)}}function Iu(s,t,l){try{var i=s.stateNode;g0(i,s.type,l,t),i[is]=t}catch(o){Gs(s,s.return,o)}}function Xf(s){return s.tag===5||s.tag===3||s.tag===26||s.tag===27&&nn(s.type)||s.tag===4}function Fu(s){e:for(;;){for(;s.sibling===null;){if(s.return===null||Xf(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&&nn(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 Hu(s,t,l){var i=s.tag;if(i===5||i===6)s=s.stateNode,t?(l.nodeType===9?l.body:l.nodeName==="HTML"?l.ownerDocument.body:l).insertBefore(s,t):(t=l.nodeType===9?l.body:l.nodeName==="HTML"?l.ownerDocument.body:l,t.appendChild(s),l=l._reactRootContainer,l!=null||t.onclick!==null||(t.onclick=fl));else if(i!==4&&(i===27&&nn(s.type)&&(l=s.stateNode,t=null),s=s.child,s!==null))for(Hu(s,t,l),s=s.sibling;s!==null;)Hu(s,t,l),s=s.sibling}function lo(s,t,l){var i=s.tag;if(i===5||i===6)s=s.stateNode,t?l.insertBefore(s,t):l.appendChild(s);else if(i!==4&&(i===27&&nn(s.type)&&(l=s.stateNode),s=s.child,s!==null))for(lo(s,t,l),s=s.sibling;s!==null;)lo(s,t,l),s=s.sibling}function Zf(s){var t=s.stateNode,l=s.memoizedProps;try{for(var i=s.type,o=t.attributes;o.length;)t.removeAttributeNode(o[0]);Kt(t,i,l),t[js]=s,t[is]=l}catch(x){Gs(s,s.return,x)}}var Sl=!1,Rt=!1,Vu=!1,Wf=typeof WeakSet=="function"?WeakSet:Set,It=null;function Jy(s,t){if(s=s.containerInfo,um=ko,s=dh(s),Ud(s)){if("selectionStart"in s)var l={start:s.selectionStart,end:s.selectionEnd};else e:{l=(l=s.ownerDocument)&&l.defaultView||window;var i=l.getSelection&&l.getSelection();if(i&&i.rangeCount!==0){l=i.anchorNode;var o=i.anchorOffset,x=i.focusNode;i=i.focusOffset;try{l.nodeType,x.nodeType}catch{l=null;break e}var j=0,k=-1,P=-1,ne=0,ve=0,ye=s,ce=null;s:for(;;){for(var xe;ye!==l||o!==0&&ye.nodeType!==3||(k=j+o),ye!==x||i!==0&&ye.nodeType!==3||(P=j+i),ye.nodeType===3&&(j+=ye.nodeValue.length),(xe=ye.firstChild)!==null;)ce=ye,ye=xe;for(;;){if(ye===s)break s;if(ce===l&&++ne===o&&(k=j),ce===x&&++ve===i&&(P=j),(xe=ye.nextSibling)!==null)break;ye=ce,ce=ye.parentNode}ye=xe}l=k===-1||P===-1?null:{start:k,end:P}}else l=null}l=l||{start:0,end:0}}else l=null;for(mm={focusedElem:s,selectionRange:l},ko=!1,It=t;It!==null;)if(t=It,s=t.child,(t.subtreeFlags&1028)!==0&&s!==null)s.return=t,It=s;else for(;It!==null;){switch(t=It,x=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(l=0;l title"))),Kt(x,i,l),x[js]=s,Pt(x),i=x;break e;case"link":var j=ng("link","href",o).get(i+(l.href||""));if(j){for(var k=0;kZs&&(j=Zs,Zs=Ze,Ze=j);var Z=ch(k,Ze),V=ch(k,Zs);if(Z&&V&&(xe.rangeCount!==1||xe.anchorNode!==Z.node||xe.anchorOffset!==Z.offset||xe.focusNode!==V.node||xe.focusOffset!==V.offset)){var ae=ye.createRange();ae.setStart(Z.node,Z.offset),xe.removeAllRanges(),Ze>Zs?(xe.addRange(ae),xe.extend(V.node,V.offset)):(ae.setEnd(V.node,V.offset),xe.addRange(ae))}}}}for(ye=[],xe=k;xe=xe.parentNode;)xe.nodeType===1&&ye.push({element:xe,left:xe.scrollLeft,top:xe.scrollTop});for(typeof k.focus=="function"&&k.focus(),k=0;kl?32:l,R.T=null,l=Xu,Xu=null;var x=tn,j=Ml;if(Ot=0,zr=tn=null,Ml=0,(Is&6)!==0)throw Error(c(331));var k=Is;if(Is|=4,dp(x.current),ip(x,x.current,j,l),Is=k,Oi(0,!1),ls&&typeof ls.onPostCommitFiberRoot=="function")try{ls.onPostCommitFiberRoot(bs,x)}catch{}return!0}finally{Y.p=o,R.T=i,Tp(s,t)}}function Mp(s,t,l){t=Ba(l,t),t=Mu(s.stateNode,t,2),s=Yl(s,t,2),s!==null&&(Le(s,2),cl(s))}function Gs(s,t,l){if(s.tag===3)Mp(s,s,l);else for(;t!==null;){if(t.tag===3){Mp(t,s,l);break}else if(t.tag===1){var i=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof i.componentDidCatch=="function"&&(sn===null||!sn.has(i))){s=Ba(l,s),l=Af(2),i=Yl(t,l,2),i!==null&&(zf(l,i,t,s),Le(i,2),cl(i));break}}t=t.return}}function sm(s,t,l){var i=s.pingCache;if(i===null){i=s.pingCache=new Wy;var o=new Set;i.set(t,o)}else o=i.get(t),o===void 0&&(o=new Set,i.set(t,o));o.has(l)||(Ku=!0,o.add(l),s=l0.bind(null,s,t,l),t.then(s,s))}function l0(s,t,l){var i=s.pingCache;i!==null&&i.delete(t),s.pingedLanes|=s.suspendedLanes&l,s.warmLanes&=~l,Ws===s&&(Ts&l)===l&&(Nt===4||Nt===3&&(Ts&62914560)===Ts&&300>mt()-io?(Is&2)===0&&Rr(s,0):Qu|=l,Ar===Ts&&(Ar=0)),cl(s)}function Ap(s,t){t===0&&(t=te()),s=En(s,t),s!==null&&(Le(s,t),cl(s))}function n0(s){var t=s.memoizedState,l=0;t!==null&&(l=t.retryLane),Ap(s,l)}function r0(s,t){var l=0;switch(s.tag){case 31:case 13:var i=s.stateNode,o=s.memoizedState;o!==null&&(l=o.retryLane);break;case 19:i=s.stateNode;break;case 22:i=s.stateNode._retryCache;break;default:throw Error(c(314))}i!==null&&i.delete(t),Ap(s,l)}function i0(s,t){return Ut(s,t)}var fo=null,Or=null,tm=!1,po=!1,am=!1,ln=0;function cl(s){s!==Or&&s.next===null&&(Or===null?fo=Or=s:Or=Or.next=s),po=!0,tm||(tm=!0,o0())}function Oi(s,t){if(!am&&po){am=!0;do for(var l=!1,i=fo;i!==null;){if(s!==0){var o=i.pendingLanes;if(o===0)var x=0;else{var j=i.suspendedLanes,k=i.pingedLanes;x=(1<<31-ys(42|s)+1)-1,x&=o&~(j&~k),x=x&201326741?x&201326741|1:x?x|2:0}x!==0&&(l=!0,Op(i,x))}else x=Ts,x=ll(i,i===Ws?x:0,i.cancelPendingCommit!==null||i.timeoutHandle!==-1),(x&3)===0||xl(i,x)||(l=!0,Op(i,x));i=i.next}while(l);am=!1}}function c0(){zp()}function zp(){po=tm=!1;var s=0;ln!==0&&v0()&&(s=ln);for(var t=mt(),l=null,i=fo;i!==null;){var o=i.next,x=Rp(i,t);x===0?(i.next=null,l===null?fo=o:l.next=o,o===null&&(Or=l)):(l=i,(s!==0||(x&3)!==0)&&(po=!0)),i=o}Ot!==0&&Ot!==5||Oi(s),ln!==0&&(ln=0)}function Rp(s,t){for(var l=s.suspendedLanes,i=s.pingedLanes,o=s.expirationTimes,x=s.pendingLanes&-62914561;0k)break;var ve=P.transferSize,ye=P.initiatorType;ve&&Hp(ye)&&(P=P.responseEnd,j+=ve*(P"u"?null:document;function sg(s,t,l){var i=Lr;if(i&&typeof t=="string"&&t){var o=Ua(t);o='link[rel="'+s+'"][href="'+o+'"]',typeof l=="string"&&(o+='[crossorigin="'+l+'"]'),eg.has(o)||(eg.add(o),s={rel:s,crossOrigin:l,href:t},i.querySelector(o)===null&&(t=i.createElement("link"),Kt(t,"link",s),Pt(t),i.head.appendChild(t)))}}function T0(s){Al.D(s),sg("dns-prefetch",s,null)}function E0(s,t){Al.C(s,t),sg("preconnect",s,t)}function M0(s,t,l){Al.L(s,t,l);var i=Lr;if(i&&s&&t){var o='link[rel="preload"][as="'+Ua(t)+'"]';t==="image"&&l&&l.imageSrcSet?(o+='[imagesrcset="'+Ua(l.imageSrcSet)+'"]',typeof l.imageSizes=="string"&&(o+='[imagesizes="'+Ua(l.imageSizes)+'"]')):o+='[href="'+Ua(s)+'"]';var x=o;switch(t){case"style":x=Ur(s);break;case"script":x=$r(s)}Ga.has(x)||(s=v({rel:"preload",href:t==="image"&&l&&l.imageSrcSet?void 0:s,as:t},l),Ga.set(x,s),i.querySelector(o)!==null||t==="style"&&i.querySelector(Bi(x))||t==="script"&&i.querySelector(Pi(x))||(t=i.createElement("link"),Kt(t,"link",s),Pt(t),i.head.appendChild(t)))}}function A0(s,t){Al.m(s,t);var l=Lr;if(l&&s){var i=t&&typeof t.as=="string"?t.as:"script",o='link[rel="modulepreload"][as="'+Ua(i)+'"][href="'+Ua(s)+'"]',x=o;switch(i){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":x=$r(s)}if(!Ga.has(x)&&(s=v({rel:"modulepreload",href:s},t),Ga.set(x,s),l.querySelector(o)===null)){switch(i){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(l.querySelector(Pi(x)))return}i=l.createElement("link"),Kt(i,"link",s),Pt(i),l.head.appendChild(i)}}}function z0(s,t,l){Al.S(s,t,l);var i=Lr;if(i&&s){var o=nr(i).hoistableStyles,x=Ur(s);t=t||"default";var j=o.get(x);if(!j){var k={loading:0,preload:null};if(j=i.querySelector(Bi(x)))k.loading=5;else{s=v({rel:"stylesheet",href:s,"data-precedence":t},l),(l=Ga.get(x))&&vm(s,l);var P=j=i.createElement("link");Pt(P),Kt(P,"link",s),P._p=new Promise(function(ne,ve){P.onload=ne,P.onerror=ve}),P.addEventListener("load",function(){k.loading|=1}),P.addEventListener("error",function(){k.loading|=2}),k.loading|=4,bo(j,t,i)}j={type:"stylesheet",instance:j,count:1,state:k},o.set(x,j)}}}function R0(s,t){Al.X(s,t);var l=Lr;if(l&&s){var i=nr(l).hoistableScripts,o=$r(s),x=i.get(o);x||(x=l.querySelector(Pi(o)),x||(s=v({src:s,async:!0},t),(t=Ga.get(o))&&Nm(s,t),x=l.createElement("script"),Pt(x),Kt(x,"link",s),l.head.appendChild(x)),x={type:"script",instance:x,count:1,state:null},i.set(o,x))}}function D0(s,t){Al.M(s,t);var l=Lr;if(l&&s){var i=nr(l).hoistableScripts,o=$r(s),x=i.get(o);x||(x=l.querySelector(Pi(o)),x||(s=v({src:s,async:!0,type:"module"},t),(t=Ga.get(o))&&Nm(s,t),x=l.createElement("script"),Pt(x),Kt(x,"link",s),l.head.appendChild(x)),x={type:"script",instance:x,count:1,state:null},i.set(o,x))}}function tg(s,t,l,i){var o=(o=M.current)?No(o):null;if(!o)throw Error(c(446));switch(s){case"meta":case"title":return null;case"style":return typeof l.precedence=="string"&&typeof l.href=="string"?(t=Ur(l.href),l=nr(o).hoistableStyles,i=l.get(t),i||(i={type:"style",instance:null,count:0,state:null},l.set(t,i)),i):{type:"void",instance:null,count:0,state:null};case"link":if(l.rel==="stylesheet"&&typeof l.href=="string"&&typeof l.precedence=="string"){s=Ur(l.href);var x=nr(o).hoistableStyles,j=x.get(s);if(j||(o=o.ownerDocument||o,j={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},x.set(s,j),(x=o.querySelector(Bi(s)))&&!x._p&&(j.instance=x,j.state.loading=5),Ga.has(s)||(l={rel:"preload",as:"style",href:l.href,crossOrigin:l.crossOrigin,integrity:l.integrity,media:l.media,hrefLang:l.hrefLang,referrerPolicy:l.referrerPolicy},Ga.set(s,l),x||O0(o,s,l,j.state))),t&&i===null)throw Error(c(528,""));return j}if(t&&i!==null)throw Error(c(529,""));return null;case"script":return t=l.async,l=l.src,typeof l=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=$r(l),l=nr(o).hoistableScripts,i=l.get(t),i||(i={type:"script",instance:null,count:0,state:null},l.set(t,i)),i):{type:"void",instance:null,count:0,state:null};default:throw Error(c(444,s))}}function Ur(s){return'href="'+Ua(s)+'"'}function Bi(s){return'link[rel="stylesheet"]['+s+"]"}function ag(s){return v({},s,{"data-precedence":s.precedence,precedence:null})}function O0(s,t,l,i){s.querySelector('link[rel="preload"][as="style"]['+t+"]")?i.loading=1:(t=s.createElement("link"),i.preload=t,t.addEventListener("load",function(){return i.loading|=1}),t.addEventListener("error",function(){return i.loading|=2}),Kt(t,"link",l),Pt(t),s.head.appendChild(t))}function $r(s){return'[src="'+Ua(s)+'"]'}function Pi(s){return"script[async]"+s}function lg(s,t,l){if(t.count++,t.instance===null)switch(t.type){case"style":var i=s.querySelector('style[data-href~="'+Ua(l.href)+'"]');if(i)return t.instance=i,Pt(i),i;var o=v({},l,{"data-href":l.href,"data-precedence":l.precedence,href:null,precedence:null});return i=(s.ownerDocument||s).createElement("style"),Pt(i),Kt(i,"style",o),bo(i,l.precedence,s),t.instance=i;case"stylesheet":o=Ur(l.href);var x=s.querySelector(Bi(o));if(x)return t.state.loading|=4,t.instance=x,Pt(x),x;i=ag(l),(o=Ga.get(o))&&vm(i,o),x=(s.ownerDocument||s).createElement("link"),Pt(x);var j=x;return j._p=new Promise(function(k,P){j.onload=k,j.onerror=P}),Kt(x,"link",i),t.state.loading|=4,bo(x,l.precedence,s),t.instance=x;case"script":return x=$r(l.src),(o=s.querySelector(Pi(x)))?(t.instance=o,Pt(o),o):(i=l,(o=Ga.get(x))&&(i=v({},l),Nm(i,o)),s=s.ownerDocument||s,o=s.createElement("script"),Pt(o),Kt(o,"link",i),s.head.appendChild(o),t.instance=o);case"void":return null;default:throw Error(c(443,t.type))}else t.type==="stylesheet"&&(t.state.loading&4)===0&&(i=t.instance,t.state.loading|=4,bo(i,l.precedence,s));return t.instance}function bo(s,t,l){for(var i=l.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),o=i.length?i[i.length-1]:null,x=o,j=0;j title"):null)}function L0(s,t,l){if(l===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 ig(s){return!(s.type==="stylesheet"&&(s.state.loading&3)===0)}function U0(s,t,l,i){if(l.type==="stylesheet"&&(typeof i.media!="string"||matchMedia(i.media).matches!==!1)&&(l.state.loading&4)===0){if(l.instance===null){var o=Ur(i.href),x=t.querySelector(Bi(o));if(x){t=x._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(s.count++,s=wo.bind(s),t.then(s,s)),l.state.loading|=4,l.instance=x,Pt(x);return}x=t.ownerDocument||t,i=ag(i),(o=Ga.get(o))&&vm(i,o),x=x.createElement("link"),Pt(x);var j=x;j._p=new Promise(function(k,P){j.onload=k,j.onerror=P}),Kt(x,"link",i),l.instance=x}s.stylesheets===null&&(s.stylesheets=new Map),s.stylesheets.set(l,t),(t=l.state.preload)&&(l.state.loading&3)===0&&(s.count++,l=wo.bind(s),t.addEventListener("load",l),t.addEventListener("error",l))}}var bm=0;function $0(s,t){return s.stylesheets&&s.count===0&&So(s,s.stylesheets),0bm?50:800)+t);return s.unsuspend=l,function(){s.unsuspend=null,clearTimeout(i),clearTimeout(o)}}:null}function wo(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)So(this,this.stylesheets);else if(this.unsuspend){var s=this.unsuspend;this.unsuspend=null,s()}}}var _o=null;function So(s,t){s.stylesheets=null,s.unsuspend!==null&&(s.count++,_o=new Map,t.forEach(B0,s),_o=null,wo.call(s))}function B0(s,t){if(!(t.state.loading&4)){var l=_o.get(s);if(l)var i=l.get(null);else{l=new Map,_o.set(s,l);for(var o=s.querySelectorAll("link[data-precedence],style[data-precedence]"),x=0;x"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(a)}catch(n){console.error(n)}}return a(),Am.exports=E1(),Am.exports}var A1=M1();function F(...a){return nw(rw(a))}const Ce=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:F("rounded-xl border bg-card text-card-foreground shadow",a),...n}));Ce.displayName="Card";const De=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:F("flex flex-col space-y-1.5 p-6",a),...n}));De.displayName="CardHeader";const Oe=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:F("font-semibold leading-none tracking-tight",a),...n}));Oe.displayName="CardTitle";const os=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:F("text-sm text-muted-foreground",a),...n}));os.displayName="CardDescription";const Me=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:F("p-6 pt-0",a),...n}));Me.displayName="CardContent";const id=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:F("flex items-center p-6 pt-0",a),...n}));id.displayName="CardFooter";const ta=cw,Zt=m.forwardRef(({className:a,...n},r)=>e.jsx(ij,{ref:r,className:F("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",a),...n}));Zt.displayName=ij.displayName;const Xe=m.forwardRef(({className:a,...n},r)=>e.jsx(cj,{ref:r,className:F("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",a),...n}));Xe.displayName=cj.displayName;const ws=m.forwardRef(({className:a,...n},r)=>e.jsx(oj,{ref:r,className:F("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",a),...n}));ws.displayName=oj.displayName;const Je=m.forwardRef(({className:a,children:n,viewportRef:r,...c},d)=>e.jsxs(dj,{ref:d,className:F("relative overflow-hidden",a),...c,children:[e.jsx(ow,{ref:r,className:"h-full w-full rounded-[inherit]",children:n}),e.jsx(Km,{}),e.jsx(Km,{orientation:"horizontal"}),e.jsx(dw,{})]}));Je.displayName=dj.displayName;const Km=m.forwardRef(({className:a,orientation:n="vertical",...r},c)=>e.jsx(uj,{ref:c,orientation:n,className:F("flex touch-none select-none transition-colors",n==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",n==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",a),...r,children:e.jsx(uw,{className:"relative flex-1 rounded-full bg-border"})}));Km.displayName=uj.displayName;function vs({className:a,...n}){return e.jsx("div",{className:F("animate-pulse rounded-md bg-primary/10",a),...n})}const Xn=m.forwardRef(({className:a,value:n,...r},c)=>e.jsx(mj,{ref:c,className:F("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",a),...r,children:e.jsx(mw,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(n||0)}%)`}})}));Xn.displayName=mj.displayName;async function _e(a,n){const c=n?.body instanceof FormData?{...n?.headers}:{"Content-Type":"application/json",...n?.headers},d={...n,credentials:"include",headers:c},u=await fetch(a,d);if(u.status===401)throw window.location.href="/auth",new Error("认证失败,请重新登录");return u}function Hs(){return{"Content-Type":"application/json"}}async function z1(){try{await fetch("/api/webui/auth/logout",{method:"POST",credentials:"include"})}catch(a){console.error("登出请求失败:",a)}window.location.href="/auth"}async function cc(){try{return(await(await fetch("/api/webui/auth/check",{method:"GET",credentials:"include"})).json()).authenticated===!0}catch{return!1}}const R1={light:"",dark:".dark"},wv=m.createContext(null);function _v(){const a=m.useContext(wv);if(!a)throw new Error("useChart must be used within a ");return a}const Vr=m.forwardRef(({id:a,className:n,children:r,config:c,...d},u)=>{const h=m.useId(),f=`chart-${a||h.replace(/:/g,"")}`;return e.jsx(wv.Provider,{value:{config:c},children:e.jsxs("div",{"data-chart":f,ref:u,className:F("flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",n),...d,children:[e.jsx(D1,{id:f,config:c}),e.jsx(Mj,{children:r})]})})});Vr.displayName="Chart";const D1=({id:a,config:n})=>{const r=Object.entries(n).filter(([,c])=>c.theme||c.color);return r.length?e.jsx("style",{dangerouslySetInnerHTML:{__html:Object.entries(R1).map(([c,d])=>` +${d} [data-chart=${a}] { +${r.map(([u,h])=>{const f=h.theme?.[c]||h.color;return f?` --color-${u}: ${f};`:null}).join(` +`)} +} +`).join(` +`)}}):null},qi=Aj,Gr=m.forwardRef(({active:a,payload:n,className:r,indicator:c="dot",hideLabel:d=!1,hideIndicator:u=!1,label:h,labelFormatter:f,labelClassName:p,formatter:g,color:N,nameKey:v,labelKey:w},b)=>{const{config:y}=_v(),A=m.useMemo(()=>{if(d||!n?.length)return null;const[S]=n,U=`${w||S?.dataKey||S?.name||"value"}`,E=Qm(y,S,U),C=!w&&typeof h=="string"?y[h]?.label||h:E?.label;return f?e.jsx("div",{className:F("font-medium",p),children:f(C,n)}):C?e.jsx("div",{className:F("font-medium",p),children:C}):null},[h,f,n,d,p,y,w]);if(!a||!n?.length)return null;const z=n.length===1&&c!=="dot";return e.jsxs("div",{ref:b,className:F("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",r),children:[z?null:A,e.jsx("div",{className:"grid gap-1.5",children:n.filter(S=>S.type!=="none").map((S,U)=>{const E=`${v||S.name||S.dataKey||"value"}`,C=Qm(y,S,E),D=N||S.payload.fill||S.color;return e.jsx("div",{className:F("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",c==="dot"&&"items-center"),children:g&&S?.value!==void 0&&S.name?g(S.value,S.name,S,U,S.payload):e.jsxs(e.Fragment,{children:[C?.icon?e.jsx(C.icon,{}):!u&&e.jsx("div",{className:F("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":c==="dot","w-1":c==="line","w-0 border-[1.5px] border-dashed bg-transparent":c==="dashed","my-0.5":z&&c==="dashed"}),style:{"--color-bg":D,"--color-border":D}}),e.jsxs("div",{className:F("flex flex-1 justify-between leading-none",z?"items-end":"items-center"),children:[e.jsxs("div",{className:"grid gap-1.5",children:[z?A:null,e.jsx("span",{className:"text-muted-foreground",children:C?.label||S.name})]}),S.value&&e.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:S.value.toLocaleString()})]})]})},S.dataKey)})})]})});Gr.displayName="ChartTooltip";const O1=Vw,Sv=m.forwardRef(({className:a,hideIcon:n=!1,payload:r,verticalAlign:c="bottom",nameKey:d},u)=>{const{config:h}=_v();return r?.length?e.jsx("div",{ref:u,className:F("flex items-center justify-center gap-4",c==="top"?"pb-3":"pt-3",a),children:r.filter(f=>f.type!=="none").map(f=>{const p=`${d||f.dataKey||"value"}`,g=Qm(h,f,p);return e.jsxs("div",{className:F("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[g?.icon&&!n?e.jsx(g.icon,{}):e.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:f.color}}),g?.label]},f.value)})}):null});Sv.displayName="ChartLegend";function Qm(a,n,r){if(typeof n!="object"||n===null)return;const c="payload"in n&&typeof n.payload=="object"&&n.payload!==null?n.payload:void 0;let d=r;return r in n&&typeof n[r]=="string"?d=n[r]:c&&r in c&&typeof c[r]=="string"&&(d=c[r]),d in a?a[d]:a[r]}const Zr=Wr("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"}}),_=m.forwardRef(({className:a,variant:n,size:r,asChild:c=!1,...d},u)=>{const h=c?Jw:"button";return e.jsx(h,{className:F(Zr({variant:n,size:r,className:a})),ref:u,...d})});_.displayName="Button";const L1=Wr("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 ke({className:a,variant:n,...r}){return e.jsx("div",{className:F(L1({variant:n}),a),...r})}async function U1(){const a=await _e("/api/webui/system/restart",{method:"POST",headers:Hs()});if(!a.ok){const n=await a.json();throw new Error(n.detail||"重启失败")}return await a.json()}async function $1(){const a=await _e("/api/webui/system/status",{method:"GET",headers:Hs()});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取状态失败")}return await a.json()}const Pr={INITIAL_DELAY:3e3,CHECK_INTERVAL:2e3,CHECK_TIMEOUT:3e3,MAX_ATTEMPTS:60,PROGRESS_INTERVAL:200,SUCCESS_REDIRECT_DELAY:1500},kv=m.createContext(null);function Wn({children:a,onRestartComplete:n,onRestartFailed:r,healthCheckUrl:c="/api/webui/system/status",maxAttempts:d=Pr.MAX_ATTEMPTS}){const[u,h]=m.useState({status:"idle",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:d}),f=m.useRef({}),p=m.useCallback(()=>{const A=f.current;A.progress&&(clearInterval(A.progress),A.progress=void 0),A.elapsed&&(clearInterval(A.elapsed),A.elapsed=void 0),A.check&&(clearTimeout(A.check),A.check=void 0)},[]),g=m.useCallback(()=>{p(),h({status:"idle",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:d})},[p,d]),N=m.useCallback(async()=>{try{const A=new AbortController,z=setTimeout(()=>A.abort(),Pr.CHECK_TIMEOUT),S=await fetch(c,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"include",signal:A.signal});return clearTimeout(z),S.ok}catch{return!1}},[c]),v=m.useCallback(()=>{let A=0;const z=async()=>{if(A++,h(U=>({...U,status:"checking",checkAttempts:A})),await N())p(),h(U=>({...U,status:"success",progress:100})),setTimeout(()=>{n?.(),window.location.href="/auth"},Pr.SUCCESS_REDIRECT_DELAY);else if(A>=d){p();const U=`健康检查超时 (${A}/${d})`;h(E=>({...E,status:"failed",error:U})),r?.(U)}else{const U=setTimeout(z,Pr.CHECK_INTERVAL);f.current.check=U}};z()},[N,p,d,n,r]),w=m.useCallback(()=>{h(A=>({...A,status:"checking",checkAttempts:0,error:void 0})),v()},[v]),b=m.useCallback(async A=>{const{delay:z=0,skipApiCall:S=!1}=A??{};if(u.status!=="idle"&&u.status!=="failed")return;if(p(),h({status:"requesting",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:d}),z>0&&await new Promise(C=>setTimeout(C,z)),S)h(C=>({...C,status:"restarting"}));else try{h(C=>({...C,status:"restarting"})),await Promise.race([U1(),new Promise(C=>setTimeout(C,5e3))])}catch{}const U=setInterval(()=>{h(C=>({...C,progress:C.progress>=90?C.progress:C.progress+1}))},Pr.PROGRESS_INTERVAL),E=setInterval(()=>{h(C=>({...C,elapsedTime:C.elapsedTime+1}))},1e3);f.current.progress=U,f.current.elapsed=E,setTimeout(()=>{v()},Pr.INITIAL_DELAY)},[u.status,p,d,v]),y={state:u,isRestarting:u.status!=="idle",triggerRestart:b,resetState:g,retryHealthCheck:w};return e.jsx(kv.Provider,{value:y,children:a})}function yn(){const a=m.useContext(kv);if(!a)throw new Error("useRestart must be used within a RestartProvider");return a}function B1(){try{return yn()}catch{return null}}const P1=(a,n,r,c,d)=>({idle:{icon:null,title:"",description:"",tip:""},requesting:{icon:e.jsx(zs,{className:"h-16 w-16 text-primary animate-spin"}),title:c??"准备重启",description:d??"正在发送重启请求...",tip:"🔄 正在准备重启麦麦..."},restarting:{icon:e.jsx(zs,{className:"h-16 w-16 text-primary animate-spin"}),title:c??"正在重启麦麦",description:d??"请稍候,麦麦正在重启中...",tip:"🔄 配置已保存,正在重启主程序..."},checking:{icon:e.jsx(zs,{className:"h-16 w-16 text-primary animate-spin"}),title:"检查服务状态",description:`等待服务恢复... (${n}/${r})`,tip:"⏳ 正在等待服务恢复,请勿关闭页面..."},success:{icon:e.jsx(pt,{className:"h-16 w-16 text-green-500"}),title:"重启成功",description:"正在跳转到登录页面...",tip:"✅ 配置已生效,服务运行正常"},failed:{icon:e.jsx(_t,{className:"h-16 w-16 text-destructive"}),title:"重启超时",description:"服务未能在预期时间内恢复",tip:"⚠️ 如果长时间无响应,请尝试手动重启"}})[a];function er({visible:a,onComplete:n,onFailed:r,title:c,description:d,showAnimation:u=!0,className:h}){const f=B1();return(f?f.isRestarting:a)?f?e.jsx(Cv,{state:f.state,onRetry:f.retryHealthCheck,onComplete:n,onFailed:r,title:c,description:d,showAnimation:u,className:h}):e.jsx(I1,{onComplete:n,onFailed:r,title:c,description:d,showAnimation:u,className:h}):null}function Cv({state:a,onRetry:n,onComplete:r,onFailed:c,title:d,description:u,showAnimation:h,className:f}){const{status:p,progress:g,elapsedTime:N,checkAttempts:v,maxAttempts:w}=a;m.useEffect(()=>{p==="success"&&r?r():p==="failed"&&c&&c()},[p,r,c]);const b=P1(p,v,w,d,u),y=A=>{const z=Math.floor(A/60),S=A%60;return`${z}:${S.toString().padStart(2,"0")}`};return e.jsxs("div",{className:F("fixed inset-0 bg-background/95 backdrop-blur-sm z-50 flex items-center justify-center",f),children:[h&&e.jsx(F1,{}),e.jsxs("div",{className:"max-w-md w-full mx-4 space-y-8 relative z-10",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsxs("div",{className:"relative",children:[b.icon,(p==="restarting"||p==="checking")&&e.jsx("div",{className:"absolute inset-0 rounded-full bg-primary/20 animate-ping"})]}),e.jsx("h2",{className:"text-2xl font-bold",children:b.title}),e.jsx("p",{className:"text-muted-foreground text-center",children:b.description})]}),p!=="failed"&&p!=="idle"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Xn,{value:g,className:"h-2"}),e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:[g,"%"]}),e.jsxs("span",{children:["已用时: ",y(N)]})]})]}),e.jsx("div",{className:"bg-muted/50 rounded-lg p-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:b.tip})}),p==="failed"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(_,{onClick:()=>window.location.reload(),variant:"default",className:"flex-1",children:[e.jsx(dt,{className:"mr-2 h-4 w-4"}),"刷新页面"]}),e.jsxs(_,{onClick:n,variant:"secondary",className:"flex-1",children:[e.jsx(lc,{className:"mr-2 h-4 w-4"}),"重试检测"]})]})]})]})}function I1({onComplete:a,onFailed:n,title:r,description:c,showAnimation:d,className:u}){const[h,f]=m.useState({status:"restarting",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:60}),p=m.useCallback(()=>{let g=0;const N=60,v=async()=>{g++,f(w=>({...w,status:"checking",checkAttempts:g}));try{if((await fetch("/api/webui/system/status",{method:"GET",signal:AbortSignal.timeout(3e3)})).ok){f(b=>({...b,status:"success",progress:100})),setTimeout(()=>{a?.(),window.location.href="/auth"},1500);return}}catch{}g>=N?(f(w=>({...w,status:"failed"})),n?.()):setTimeout(v,2e3)};v()},[a,n]);return m.useEffect(()=>{const g=setInterval(()=>{f(w=>({...w,progress:w.progress>=90?w.progress:w.progress+1}))},200),N=setInterval(()=>{f(w=>({...w,elapsedTime:w.elapsedTime+1}))},1e3),v=setTimeout(()=>{p()},3e3);return()=>{clearInterval(g),clearInterval(N),clearTimeout(v)}},[p]),e.jsx(Cv,{state:h,onRetry:p,onComplete:a,onFailed:n,title:r,description:c,showAnimation:d,className:u})}function F1(){return e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsxs("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[600px] h-[600px]",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border border-primary/10 animate-[ping_3s_ease-in-out_infinite]"}),e.jsx("div",{className:"absolute inset-8 rounded-full border border-primary/10 animate-[ping_3s_ease-in-out_infinite_0.5s]"}),e.jsx("div",{className:"absolute inset-16 rounded-full border border-primary/10 animate-[ping_3s_ease-in-out_infinite_1s]"})]}),e.jsx("div",{className:"absolute top-1/4 left-1/4 w-2 h-2 bg-primary/20 rounded-full animate-bounce"}),e.jsx("div",{className:"absolute top-3/4 right-1/4 w-3 h-3 bg-primary/15 rounded-full animate-bounce delay-150"}),e.jsx("div",{className:"absolute top-1/2 right-1/3 w-2 h-2 bg-primary/20 rounded-full animate-bounce delay-300"})]})}const Ps=Ww,cd=e_,H1=Xw,Tv=m.forwardRef(({className:a,...n},r)=>e.jsx(zj,{ref:r,className:F("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",a),...n}));Tv.displayName=zj.displayName;const Ds=m.forwardRef(({className:a,children:n,preventOutsideClose:r=!1,...c},d)=>e.jsxs(H1,{children:[e.jsx(Tv,{}),e.jsxs(Rj,{ref:d,className:F("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",a),onPointerDownOutside:r?u=>u.preventDefault():void 0,onInteractOutside:r?u=>u.preventDefault():void 0,...c,children:[n,e.jsxs(Zw,{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(Aa,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Ds.displayName=Rj.displayName;const Os=({className:a,...n})=>e.jsx("div",{className:F("flex flex-col space-y-1.5 text-center sm:text-left",a),...n});Os.displayName="DialogHeader";const st=({className:a,...n})=>e.jsx("div",{className:F("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",a),...n});st.displayName="DialogFooter";const Ls=m.forwardRef(({className:a,...n},r)=>e.jsx(Dj,{ref:r,className:F("text-lg font-semibold leading-none tracking-tight",a),...n}));Ls.displayName=Dj.displayName;const Ks=m.forwardRef(({className:a,...n},r)=>e.jsx(Oj,{ref:r,className:F("text-sm text-muted-foreground",a),...n}));Ks.displayName=Oj.displayName;const le=m.forwardRef(({className:a,type:n,...r},c)=>e.jsx("input",{type:n,className:F("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",a),ref:c,...r}));le.displayName="Input";const qs=m.forwardRef(({className:a,...n},r)=>e.jsx(Lj,{ref:r,className:F("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",a),...n,children:e.jsx(s_,{className:F("grid place-content-center text-current"),children:e.jsx(Ct,{className:"h-4 w-4"})})}));qs.displayName=Lj.displayName;const Ie=i_,Fe=c_,Be=m.forwardRef(({className:a,children:n,...r},c)=>e.jsxs(Uj,{ref:c,className:F("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",a),...r,children:[n,e.jsx(t_,{asChild:!0,children:e.jsx(za,{className:"h-4 w-4 opacity-50"})})]}));Be.displayName=Uj.displayName;const Ev=m.forwardRef(({className:a,...n},r)=>e.jsx($j,{ref:r,className:F("flex cursor-default items-center justify-center py-1",a),...n,children:e.jsx(Qr,{className:"h-4 w-4"})}));Ev.displayName=$j.displayName;const Mv=m.forwardRef(({className:a,...n},r)=>e.jsx(Bj,{ref:r,className:F("flex cursor-default items-center justify-center py-1",a),...n,children:e.jsx(za,{className:"h-4 w-4"})}));Mv.displayName=Bj.displayName;const Pe=m.forwardRef(({className:a,children:n,position:r="popper",...c},d)=>e.jsx(a_,{children:e.jsxs(Pj,{ref:d,className:F("relative z-[100] max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-hidden rounded-md border border-border bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",r==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",a),position:r,...c,children:[e.jsx(Ev,{}),e.jsx(l_,{className:F("p-1",r==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),e.jsx(Mv,{})]})}));Pe.displayName=Pj.displayName;const V1=m.forwardRef(({className:a,...n},r)=>e.jsx(Ij,{ref:r,className:F("px-2 py-1.5 text-sm font-semibold",a),...n}));V1.displayName=Ij.displayName;const W=m.forwardRef(({className:a,children:n,...r},c)=>e.jsxs(Fj,{ref:c,className:F("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",a),...r,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(n_,{children:e.jsx(Ct,{className:"h-4 w-4"})})}),e.jsx(r_,{children:n})]}));W.displayName=Fj.displayName;const G1=m.forwardRef(({className:a,...n},r)=>e.jsx(Hj,{ref:r,className:F("-mx-1 my-1 h-px bg-muted",a),...n}));G1.displayName=Hj.displayName;const ox=({className:a,...n})=>e.jsx("nav",{role:"navigation","aria-label":"pagination",className:F("mx-auto flex w-full justify-center",a),...n});ox.displayName="Pagination";const dx=m.forwardRef(({className:a,...n},r)=>e.jsx("ul",{ref:r,className:F("flex flex-row items-center gap-1",a),...n}));dx.displayName="PaginationContent";const qn=m.forwardRef(({className:a,...n},r)=>e.jsx("li",{ref:r,className:F("",a),...n}));qn.displayName="PaginationItem";const pc=({className:a,isActive:n,size:r="icon",...c})=>e.jsx("a",{"aria-current":n?"page":void 0,className:F(Zr({variant:n?"outline":"ghost",size:r}),a),...c});pc.displayName="PaginationLink";const Av=({className:a,...n})=>e.jsxs(pc,{"aria-label":"Go to previous page",size:"default",className:F("gap-1 pl-2.5",a),...n,children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{children:"上一页"})]});Av.displayName="PaginationPrevious";const zv=({className:a,...n})=>e.jsxs(pc,{"aria-label":"Go to next page",size:"default",className:F("gap-1 pr-2.5",a),...n,children:[e.jsx("span",{children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4"})]});zv.displayName="PaginationNext";const Rv=({className:a,...n})=>e.jsxs("span",{"aria-hidden":!0,className:F("flex h-9 w-9 items-center justify-center",a),...n,children:[e.jsx(v_,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More pages"})]});Rv.displayName="PaginationEllipsis";const q1=5,K1=5e3;let Dm=0;function Q1(){return Dm=(Dm+1)%Number.MAX_SAFE_INTEGER,Dm.toString()}const Om=new Map,Mg=a=>{if(Om.has(a))return;const n=setTimeout(()=>{Om.delete(a),sc({type:"REMOVE_TOAST",toastId:a})},K1);Om.set(a,n)},Y1=(a,n)=>{switch(n.type){case"ADD_TOAST":return{...a,toasts:[n.toast,...a.toasts].slice(0,q1)};case"UPDATE_TOAST":return{...a,toasts:a.toasts.map(r=>r.id===n.toast.id?{...r,...n.toast}:r)};case"DISMISS_TOAST":{const{toastId:r}=n;return r?Mg(r):a.toasts.forEach(c=>{Mg(c.id)}),{...a,toasts:a.toasts.map(c=>c.id===r||r===void 0?{...c,open:!1}:c)}}case"REMOVE_TOAST":return n.toastId===void 0?{...a,toasts:[]}:{...a,toasts:a.toasts.filter(r=>r.id!==n.toastId)}}},Po=[];let Io={toasts:[]};function sc(a){Io=Y1(Io,a),Po.forEach(n=>{n(Io)})}function Qt({...a}){const n=Q1(),r=d=>sc({type:"UPDATE_TOAST",toast:{...d,id:n}}),c=()=>sc({type:"DISMISS_TOAST",toastId:n});return sc({type:"ADD_TOAST",toast:{...a,id:n,open:!0,onOpenChange:d=>{d||c()}}}),{id:n,dismiss:c,update:r}}function Ys(){const[a,n]=m.useState(Io);return m.useEffect(()=>(Po.push(n),()=>{const r=Po.indexOf(n);r>-1&&Po.splice(r,1)}),[a]),{...a,toast:Qt,dismiss:r=>sc({type:"DISMISS_TOAST",toastId:r})}}const tl="/api/webui/expression";async function ux(){const a=await _e(`${tl}/chats`,{});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取聊天列表失败")}return a.json()}async function J1(a){const n=new URLSearchParams;a.page&&n.append("page",a.page.toString()),a.page_size&&n.append("page_size",a.page_size.toString()),a.search&&n.append("search",a.search),a.chat_id&&n.append("chat_id",a.chat_id);const r=await _e(`${tl}/list?${n}`,{});if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取表达方式列表失败")}return r.json()}async function X1(a){const n=await _e(`${tl}/${a}`,{});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取表达方式详情失败")}return n.json()}async function Z1(a){const n=await _e(`${tl}/`,{method:"POST",body:JSON.stringify(a)});if(!n.ok){const r=await n.json();throw new Error(r.detail||"创建表达方式失败")}return n.json()}async function W1(a,n){const r=await _e(`${tl}/${a}`,{method:"PATCH",body:JSON.stringify(n)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"更新表达方式失败")}return r.json()}async function e2(a){const n=await _e(`${tl}/${a}`,{method:"DELETE"});if(!n.ok){const r=await n.json();throw new Error(r.detail||"删除表达方式失败")}return n.json()}async function s2(a){const n=await _e(`${tl}/batch/delete`,{method:"POST",body:JSON.stringify({ids:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"批量删除表达方式失败")}return n.json()}async function t2(){const a=await _e(`${tl}/stats/summary`,{});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取统计数据失败")}return a.json()}async function mx(){const a=await _e(`${tl}/review/stats`);if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取审核统计失败")}return a.json()}async function a2(a){const n=new URLSearchParams;a.page&&n.append("page",a.page.toString()),a.page_size&&n.append("page_size",a.page_size.toString()),a.filter_type&&n.append("filter_type",a.filter_type),a.search&&n.append("search",a.search),a.chat_id&&n.append("chat_id",a.chat_id);const r=await _e(`${tl}/review/list?${n}`);if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取审核列表失败")}return r.json()}async function Ag(a){const n=await _e(`${tl}/review/batch`,{method:"POST",body:JSON.stringify({items:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"批量审核失败")}return n.json()}function Dv({open:a,onOpenChange:n}){const[r,c]=m.useState(null),[d,u]=m.useState([]),[h,f]=m.useState(!1),[p,g]=m.useState(!1),[N,v]=m.useState(0),[w,b]=m.useState(1),[y,A]=m.useState(20),[z,S]=m.useState(""),[U,E]=m.useState("unchecked"),[C,D]=m.useState(""),[I,O]=m.useState(""),[X,L]=m.useState(new Set),[oe,Ne]=m.useState(new Set),[je,de]=m.useState(new Map),{toast:he}=Ys(),ge=m.useCallback(async()=>{try{g(!0);const J=await mx();c(J)}catch(J){console.error("加载统计失败:",J)}finally{g(!1)}},[]),R=m.useCallback(async()=>{try{f(!0);const J=await a2({page:w,page_size:y,filter_type:U,search:C||void 0});u(J.data),v(J.total)}catch(J){he({title:"加载失败",description:J instanceof Error?J.message:"无法加载列表",variant:"destructive"})}finally{f(!1)}},[w,y,U,C,he]),Y=m.useCallback(async()=>{try{const J=await ux();if(J?.data){const $e=new Map;J.data.forEach(H=>{$e.set(H.chat_id,H.chat_name)}),de($e)}}catch(J){console.error("加载聊天名称失败:",J)}},[]);m.useEffect(()=>{a&&(ge(),R(),Y())},[a,ge,R,Y]),m.useEffect(()=>{b(1),L(new Set)},[U,C]);const $=()=>{D(I),b(1)},ue=J=>je.get(J)||J,G=async(J,$e)=>{try{Ne(se=>new Set(se).add(J));const H=await Ag([{id:J,rejected:$e,require_unchecked:U==="unchecked"}]);H.results[0]?.success?(he({title:$e?"已拒绝":"已通过",description:`表达方式 #${J} ${$e?"已拒绝":"已通过"}`}),R(),ge()):he({title:"操作失败",description:H.results[0]?.message||"未知错误",variant:"destructive"})}catch(H){he({title:"操作失败",description:H instanceof Error?H.message:"未知错误",variant:"destructive"})}finally{Ne(H=>{const se=new Set(H);return se.delete(J),se})}},Se=async J=>{if(X.size===0){he({title:"请选择",description:"请先选择要审核的表达方式",variant:"destructive"});return}try{f(!0);const $e=Array.from(X).map(se=>({id:se,rejected:J,require_unchecked:U==="unchecked"})),H=await Ag($e);he({title:"批量审核完成",description:`成功 ${H.succeeded} 条,失败 ${H.failed} 条`,variant:H.failed>0?"destructive":"default"}),L(new Set),R(),ge()}catch($e){he({title:"批量审核失败",description:$e instanceof Error?$e.message:"未知错误",variant:"destructive"})}finally{f(!1)}},fe=()=>{X.size===d.length?L(new Set):L(new Set(d.map(J=>J.id)))},Te=J=>{L($e=>{const H=new Set($e);return H.has(J)?H.delete(J):H.add(J),H})},q=J=>J?new Date(J*1e3).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):"-",B=J=>J.checked?J.rejected?e.jsxs(ke,{variant:"destructive",className:"gap-1",children:[e.jsx(Ka,{className:"h-3 w-3"}),"已拒绝"]}):e.jsxs(ke,{variant:"default",className:"gap-1 bg-green-600",children:[e.jsx(pt,{className:"h-3 w-3"}),"已通过"]}):e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(na,{className:"h-3 w-3"}),"待审核"]}),M=J=>J?J==="ai"?e.jsxs(ke,{variant:"secondary",className:"gap-1 text-xs",children:[e.jsx(Vn,{className:"h-3 w-3"}),"AI"]}):e.jsxs(ke,{variant:"secondary",className:"gap-1 text-xs",children:[e.jsx(jn,{className:"h-3 w-3"}),"人工"]}):null,Q=Math.ceil(N/y),Ae=()=>{const J=[];if(Q<=7)for(let $e=1;$e<=Q;$e++)J.push($e);else{J.push(1),w>3&&J.push("ellipsis");const $e=Math.max(2,w-1),H=Math.min(Q-1,w+1);for(let se=$e;se<=H;se++)J.push(se);w1&&J.push(Q)}return J},ee=()=>{const J=parseInt(z,10);!isNaN(J)&&J>=1&&J<=Q&&(b(J),S(""))};return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-5xl w-[95vw] sm:w-full h-[90vh] sm:h-[85vh] flex flex-col p-0",children:[e.jsxs(Os,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-4 border-b shrink-0",children:[e.jsx(Ls,{className:"text-lg sm:text-xl",children:"表达方式审核"}),e.jsx(Ks,{className:"text-xs sm:text-sm",children:"审核麦麦学习到的表达方式。通过审核的项目才会被使用(可在配置中调整),被拒绝的项目永远不会被使用。"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 sm:gap-3 mt-4",children:[e.jsxs("div",{className:"rounded-lg border p-2 sm:p-3 text-center",children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-orange-500",children:p?"-":r?.unchecked??0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"待审核"})]}),e.jsxs("div",{className:"rounded-lg border p-2 sm:p-3 text-center",children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-green-500",children:p?"-":r?.passed??0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"已通过"})]}),e.jsxs("div",{className:"rounded-lg border p-2 sm:p-3 text-center",children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-red-500",children:p?"-":r?.rejected??0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"已拒绝"})]}),e.jsxs("div",{className:"rounded-lg border p-2 sm:p-3 text-center",children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-blue-500",children:p?"-":r?.total??0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"总计"})]})]})]}),e.jsxs("div",{className:"px-4 sm:px-6 py-3 border-b shrink-0 space-y-3",children:[e.jsx(ta,{value:U,onValueChange:J=>E(J),className:"w-full",children:e.jsxs(Zt,{className:"grid w-full grid-cols-4",children:[e.jsxs(Xe,{value:"unchecked",className:"gap-1 text-xs sm:text-sm px-1 sm:px-3",children:[e.jsx(na,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"待审核"}),e.jsx("span",{className:"sm:hidden",children:"待审"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r?.unchecked??0,")"]})]}),e.jsxs(Xe,{value:"passed",className:"gap-1 text-xs sm:text-sm px-1 sm:px-3",children:[e.jsx(pt,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"已通过"}),e.jsx("span",{className:"sm:hidden",children:"通过"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r?.passed??0,")"]})]}),e.jsxs(Xe,{value:"rejected",className:"gap-1 text-xs sm:text-sm px-1 sm:px-3",children:[e.jsx(Ka,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"已拒绝"}),e.jsx("span",{className:"sm:hidden",children:"拒绝"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r?.rejected??0,")"]})]}),e.jsxs(Xe,{value:"all",className:"gap-1 text-xs sm:text-sm px-1 sm:px-3",children:[e.jsx("span",{children:"全部"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r?.total??0,")"]})]})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(le,{placeholder:"搜索情景或风格...",value:I,onChange:J=>O(J.target.value),onKeyDown:J=>J.key==="Enter"&&$(),className:"pl-9"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"icon",onClick:$,children:e.jsx(Tt,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"icon",onClick:()=>{R(),ge()},disabled:h,children:e.jsx(dt,{className:F("h-4 w-4",h&&"animate-spin")})})]}),U==="unchecked"&&X.size>0&&e.jsxs("div",{className:"flex items-center gap-2 w-full sm:w-auto",children:[e.jsxs(_,{variant:"default",size:"sm",className:"bg-green-600 hover:bg-green-700 flex-1 sm:flex-none",onClick:()=>Se(!1),disabled:h,children:[e.jsx(pt,{className:"h-4 w-4 mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"批量通过"}),e.jsx("span",{className:"sm:hidden",children:"通过"}),"(",X.size,")"]}),e.jsxs(_,{variant:"destructive",size:"sm",className:"flex-1 sm:flex-none",onClick:()=>Se(!0),disabled:h,children:[e.jsx(Ka,{className:"h-4 w-4 mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"批量拒绝"}),e.jsx("span",{className:"sm:hidden",children:"拒绝"}),"(",X.size,")"]})]})]})]}),e.jsx(Je,{className:"flex-1 px-4 sm:px-6",children:h&&d.length===0?e.jsx("div",{className:"flex items-center justify-center h-40",children:e.jsx(dt,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):d.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-40 text-muted-foreground",children:[e.jsx(_t,{className:"h-8 w-8 mb-2"}),e.jsx("p",{children:"没有找到表达方式"})]}):e.jsxs("div",{className:"space-y-2 py-2",children:[U==="unchecked"&&d.length>0&&e.jsxs("div",{className:"flex items-center gap-2 py-2 px-3 rounded-lg bg-muted/50",children:[e.jsx(qs,{checked:X.size===d.length&&d.length>0,onCheckedChange:fe}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["全选当前页 (",d.length," 条)"]})]}),d.map(J=>e.jsx("div",{className:F("rounded-lg border p-3 sm:p-4 space-y-2 sm:space-y-3 transition-colors",X.has(J.id)&&"bg-accent border-primary",oe.has(J.id)&&"opacity-50"),children:e.jsxs("div",{className:"flex items-start gap-2 sm:gap-3",children:[U==="unchecked"&&e.jsx(qs,{checked:X.has(J.id),onCheckedChange:()=>Te(J.id),disabled:oe.has(J.id),className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"情景:"}),e.jsx("p",{className:"text-sm font-medium break-words",children:J.situation})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"风格:"}),e.jsx("p",{className:"text-sm text-muted-foreground break-words",children:J.style})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1 sm:gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["#",J.id]}),e.jsx("span",{children:"·"}),e.jsx("span",{title:ue(J.chat_id),className:"truncate max-w-24 sm:max-w-32",children:ue(J.chat_id)}),e.jsx("span",{children:"·"}),e.jsx("span",{children:q(J.create_date)}),e.jsxs("div",{className:"flex items-center gap-1",children:[B(J),M(J.modified_by)]})]})]}),e.jsx("div",{className:"flex flex-col gap-1 sm:gap-2 shrink-0",children:U==="unchecked"?e.jsxs(e.Fragment,{children:[e.jsxs(_,{size:"sm",variant:"outline",className:"text-green-600 hover:text-green-700 hover:bg-green-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>G(J.id,!1),disabled:oe.has(J.id),children:[e.jsx(pt,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"通过"})]}),e.jsxs(_,{size:"sm",variant:"outline",className:"text-red-600 hover:text-red-700 hover:bg-red-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>G(J.id,!0),disabled:oe.has(J.id),children:[e.jsx(Ka,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"拒绝"})]})]}):U==="passed"?e.jsxs(_,{size:"sm",variant:"outline",className:"text-red-600 hover:text-red-700 hover:bg-red-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>G(J.id,!0),disabled:oe.has(J.id),children:[e.jsx(Ka,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"改为拒绝"})]}):U==="rejected"?e.jsxs(_,{size:"sm",variant:"outline",className:"text-green-600 hover:text-green-700 hover:bg-green-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>G(J.id,!1),disabled:oe.has(J.id),children:[e.jsx(pt,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"改为通过"})]}):e.jsx(e.Fragment,{children:J.rejected?e.jsxs(_,{size:"sm",variant:"outline",className:"text-green-600 hover:text-green-700 hover:bg-green-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>G(J.id,!1),disabled:oe.has(J.id),children:[e.jsx(pt,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"改为通过"})]}):J.checked?e.jsxs(_,{size:"sm",variant:"outline",className:"text-red-600 hover:text-red-700 hover:bg-red-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>G(J.id,!0),disabled:oe.has(J.id),children:[e.jsx(Ka,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"改为拒绝"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(_,{size:"sm",variant:"outline",className:"text-green-600 hover:text-green-700 hover:bg-green-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>G(J.id,!1),disabled:oe.has(J.id),children:[e.jsx(pt,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"通过"})]}),e.jsxs(_,{size:"sm",variant:"outline",className:"text-red-600 hover:text-red-700 hover:bg-red-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>G(J.id,!0),disabled:oe.has(J.id),children:[e.jsx(Ka,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"拒绝"})]})]})})})]})},J.id))]})}),e.jsxs("div",{className:"px-4 sm:px-6 py-3 border-t shrink-0 flex flex-col sm:flex-row items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("span",{className:"hidden sm:inline",children:"每页"}),e.jsxs(Ie,{value:y.toString(),onValueChange:J=>{A(parseInt(J,10)),b(1)},children:[e.jsx(Be,{className:"w-[70px] h-8",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"10",children:"10"}),e.jsx(W,{value:"20",children:"20"}),e.jsx(W,{value:"50",children:"50"}),e.jsx(W,{value:"100",children:"100"})]})]}),e.jsx("span",{className:"hidden sm:inline",children:"条"}),e.jsxs("span",{className:"text-muted-foreground",children:["共 ",N," 条"]})]}),e.jsx(ox,{className:"mx-0 w-auto",children:e.jsxs(dx,{children:[e.jsx(qn,{children:e.jsx(_,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>b(J=>Math.max(1,J-1)),disabled:w<=1||h,children:e.jsx(Da,{className:"h-4 w-4"})})}),Ae().map((J,$e)=>e.jsx(qn,{children:J==="ellipsis"?e.jsx(Rv,{}):e.jsx(pc,{href:"#",isActive:J===w,onClick:H=>{H.preventDefault(),b(J)},className:"h-8 w-8 cursor-pointer",children:J})},$e)),e.jsx(qn,{children:e.jsx(_,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>b(J=>Math.min(Q,J+1)),disabled:w>=Q||h,children:e.jsx(Wt,{className:"h-4 w-4"})})})]})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"跳至"}),e.jsx(le,{type:"number",min:1,max:Q,value:z,onChange:J=>S(J.target.value),onKeyDown:J=>J.key==="Enter"&&ee(),className:"w-16 h-8 text-center",placeholder:w.toString()}),e.jsx("span",{className:"text-muted-foreground",children:"页"}),e.jsx(_,{variant:"outline",size:"sm",className:"h-8",onClick:ee,disabled:h,children:"跳转"})]})]})]})})}function l2(){return e.jsx(Wn,{children:e.jsx(r2,{})})}const n2=a=>{const n=[];for(let r=0;r(I.current=!0,()=>{I.current=!1,O.current&&(clearInterval(O.current),O.current=null)}),[]);const X=m.useCallback(async()=>{try{const M=await mx();I.current&&E(M.unchecked)}catch(M){console.error("获取审核统计失败:",M)}},[]),L=m.useCallback(async()=>{try{b(!0);const M=await iw.get("https://v1.hitokoto.cn/?c=a&c=b&c=c&c=d&c=h&c=i&c=k");I.current&&v({hitokoto:M.data.hitokoto,from:M.data.from||M.data.from_who||"未知"})}catch(M){console.error("获取一言失败:",M),I.current&&v({hitokoto:"人生就像一盒巧克力,你永远不知道下一颗是什么味道。",from:"阿甘正传"})}finally{I.current&&b(!1)}},[]),oe=m.useCallback(async()=>{try{const M=await _e("/api/webui/system/status");if(!I.current)return;if(M.ok){const Q=await M.json();A(Q)}else A(null)}catch(M){console.error("获取机器人状态失败:",M),I.current&&A(null)}},[]),Ne=async()=>{await C()},je=m.useCallback(async()=>{try{const M=await _e(`/api/webui/statistics/dashboard?hours=${h}`);if(!I.current)return;if(M.ok){const Q=await M.json();n(Q)}c(!1),u(100)}catch(M){console.error("Failed to fetch dashboard data:",M),I.current&&(c(!1),u(100))}},[h]);if(m.useEffect(()=>{if(!r)return;u(0);const M=setTimeout(()=>u(15),200),Q=setTimeout(()=>u(30),800),Ae=setTimeout(()=>u(45),2e3),ee=setTimeout(()=>u(60),4e3),J=setTimeout(()=>u(75),6500),$e=setTimeout(()=>u(85),9e3),H=setTimeout(()=>u(92),11e3);return()=>{clearTimeout(M),clearTimeout(Q),clearTimeout(Ae),clearTimeout(ee),clearTimeout(J),clearTimeout($e),clearTimeout(H)}},[r]),m.useEffect(()=>{je(),L(),oe(),X()},[je,L,oe,X]),m.useEffect(()=>{if(O.current&&(clearInterval(O.current),O.current=null),!!p)return O.current=setInterval(()=>{I.current&&(je(),oe())},3e4),()=>{O.current&&(clearInterval(O.current),O.current=null)}},[p,je,oe]),r||!a)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(dt,{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(Xn,{value:d,className:"h-2"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[d,"%"]})]})]})});const{summary:de,model_stats:he=[],hourly_data:ge=[],daily_data:R=[],recent_activity:Y=[]}=a,$=de??{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},ue=M=>{const Q=Math.floor(M/3600),Ae=Math.floor(M%3600/60);return`${Q}小时${Ae}分钟`},G=M=>{const Q=M.toLocaleString("zh-CN");return M>=1e9?{display:`${(M/1e9).toFixed(2)}B`,exact:Q,needsExact:!0}:M>=1e6?{display:`${(M/1e6).toFixed(2)}M`,exact:Q,needsExact:!0}:M>=1e4?{display:`${(M/1e3).toFixed(1)}K`,exact:Q,needsExact:!0}:M>=1e3?{display:`${(M/1e3).toFixed(2)}K`,exact:Q,needsExact:!0}:{display:Q,exact:Q,needsExact:!1}},Se=M=>{const Q=`¥${M.toLocaleString("zh-CN",{minimumFractionDigits:2,maximumFractionDigits:2})}`;return M>=1e6?{display:`¥${(M/1e6).toFixed(2)}M`,exact:Q,needsExact:!0}:M>=1e4?{display:`¥${(M/1e3).toFixed(1)}K`,exact:Q,needsExact:!0}:M>=1e3?{display:`¥${(M/1e3).toFixed(2)}K`,exact:Q,needsExact:!0}:{display:Q,exact:Q,needsExact:!1}},fe=M=>new Date(M).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),Te=n2(he.length),q=he.map((M,Q)=>({name:M.model_name,value:M.request_count,fill:Te[Q]})),B={requests:{label:"请求数",color:"hsl(var(--chart-1))"},cost:{label:"花费(¥)",color:"hsl(var(--chart-2))"},tokens:{label:"Tokens",color:"hsl(var(--chart-3))"}};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"实时监控面板"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"麦麦运行状态和统计数据一览"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ta,{value:h.toString(),onValueChange:M=>f(Number(M)),children:e.jsxs(Zt,{className:"grid grid-cols-3 w-full sm:w-auto",children:[e.jsx(Xe,{value:"24",children:"24小时"}),e.jsx(Xe,{value:"168",children:"7天"}),e.jsx(Xe,{value:"720",children:"30天"})]})}),e.jsxs(_,{variant:p?"default":"outline",size:"sm",onClick:()=>g(!p),className:"gap-2",children:[e.jsx(dt,{className:`h-4 w-4 ${p?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"自动刷新"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:je,children:e.jsx(dt,{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:[w?e.jsx(vs,{className:"h-5 flex-1"}):N?e.jsxs("p",{className:"flex-1 text-sm text-muted-foreground italic truncate",children:['"',N.hitokoto,'" —— ',N.from]}):null,e.jsx(_,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:L,disabled:w,children:e.jsx(dt,{className:`h-3.5 w-3.5 ${w?"animate-spin":""}`})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-3",children:[e.jsxs(Ce,{className:"lg:col-span-1",children:[e.jsx(De,{className:"pb-3",children:e.jsxs(Oe,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(hc,{className:"h-4 w-4"}),"麦麦状态"]})}),e.jsx(Me,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:y?.running?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-3 w-3 rounded-full bg-green-500 animate-pulse"}),e.jsxs(ke,{variant:"outline",className:"text-green-600 border-green-300 bg-green-50",children:[e.jsx(pt,{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(ke,{variant:"outline",className:"text-red-600 border-red-300 bg-red-50",children:[e.jsx(_t,{className:"h-3 w-3 mr-1"}),"已停止"]})]})}),y&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("span",{children:["v",y.version]}),e.jsx("span",{className:"mx-2",children:"|"}),e.jsxs("span",{children:["运行 ",ue(y.uptime)]})]})]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{className:"pb-3",children:e.jsxs(Oe,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(el,{className:"h-4 w-4"}),"快速操作"]})}),e.jsx(Me,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:Ne,disabled:D,className:"gap-2",children:[e.jsx(lc,{className:`h-4 w-4 ${D?"animate-spin":""}`}),D?"重启中...":"重启麦麦"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>S(!0),className:"gap-2",children:[e.jsx(Wj,{className:"h-4 w-4"}),"表达审核",U>0&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 text-xs rounded-full bg-orange-500 text-white",children:U>99?"99+":U})]}),e.jsx(_,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Fn,{to:"/logs",children:[e.jsx(Ea,{className:"h-4 w-4"}),"查看日志"]})}),e.jsx(_,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Fn,{to:"/plugins",children:[e.jsx(N_,{className:"h-4 w-4"}),"插件管理"]})}),e.jsx(_,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Fn,{to:"/settings",children:[e.jsx(vn,{className:"h-4 w-4"}),"系统设置"]})})]})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"pb-3",children:[e.jsxs(Oe,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(b_,{className:"h-4 w-4"}),"反馈问卷"]}),e.jsx(os,{className:"text-xs",children:"帮助我们改进产品体验"})]}),e.jsx(Me,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Fn,{to:"/survey/webui-feedback",children:[e.jsx(Ea,{className:"h-4 w-4"}),"WebUI 反馈"]})}),e.jsx(_,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Fn,{to:"/survey/maibot-feedback",children:[e.jsx(Ra,{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(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"总请求数"}),e.jsx(sx,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[G($.total_requests).display,G($.total_requests).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",G($.total_requests).exact,")"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["最近",h<48?h+"小时":Math.floor(h/24)+"天"]})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"总花费"}),e.jsx(y_,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[Se($.total_cost).display,Se($.total_cost).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",Se($.total_cost).exact,")"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:$.cost_per_hour>0?`¥${$.cost_per_hour.toFixed(2)}/小时`:"暂无数据"})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"Token消耗"}),e.jsx(Yr,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[G($.total_tokens).display,G($.total_tokens).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",G($.total_tokens).exact,")"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:$.tokens_per_hour>0?`${G($.tokens_per_hour).display}/小时`:"暂无数据"})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"平均响应"}),e.jsx(el,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[$.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(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"在线时长"}),e.jsx(na,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Me,{children:e.jsxs("div",{className:"text-xl font-bold",children:[ue($.online_time),e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",$.online_time.toLocaleString(),"秒)"]})]})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"消息处理"}),e.jsx(Ra,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsxs("div",{className:"text-xl font-bold",children:[G($.total_messages).display,G($.total_messages).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",G($.total_messages).exact,")"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["回复 ",G($.total_replies).display,G($.total_replies).needsExact&&e.jsxs("span",{children:["(",G($.total_replies).exact,")"]})," 条"]})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"成本效率"}),e.jsx(tx,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsx("div",{className:"text-xl font-bold",children:$.total_messages>0?`¥${($.total_cost/$.total_messages*100).toFixed(2)}`:"¥0.00"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"每100条消息"})]})]})]}),e.jsxs(ta,{defaultValue:"trends",className:"space-y-4",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2 sm:grid-cols-4",children:[e.jsx(Xe,{value:"trends",children:"趋势"}),e.jsx(Xe,{value:"models",children:"模型"}),e.jsx(Xe,{value:"activity",children:"活动"}),e.jsx(Xe,{value:"daily",children:"日统计"})]}),e.jsxs(ws,{value:"trends",className:"space-y-4",children:[e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"请求趋势"}),e.jsxs(os,{children:["最近",h,"小时的请求量变化"]})]}),e.jsx(Me,{children:e.jsx(Vr,{config:B,className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(Gw,{data:ge,children:[e.jsx(Qi,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Yi,{dataKey:"timestamp",tickFormatter:M=>fe(M),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Hr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(qi,{content:e.jsx(Gr,{labelFormatter:M=>fe(M)})}),e.jsx(qw,{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(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"花费趋势"}),e.jsx(os,{children:"API调用成本变化"})]}),e.jsx(Me,{children:e.jsx(Vr,{config:B,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(Uo,{data:ge,children:[e.jsx(Qi,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Yi,{dataKey:"timestamp",tickFormatter:M=>fe(M),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Hr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(qi,{content:e.jsx(Gr,{labelFormatter:M=>fe(M)})}),e.jsx(Ji,{dataKey:"cost",fill:"var(--color-cost)"})]})})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"Token消耗"}),e.jsx(os,{children:"Token使用量变化"})]}),e.jsx(Me,{children:e.jsx(Vr,{config:B,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(Uo,{data:ge,children:[e.jsx(Qi,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Yi,{dataKey:"timestamp",tickFormatter:M=>fe(M),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Hr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(qi,{content:e.jsx(Gr,{labelFormatter:M=>fe(M)})}),e.jsx(Ji,{dataKey:"tokens",fill:"var(--color-tokens)"})]})})})]})]})]}),e.jsx(ws,{value:"models",className:"space-y-4",children:e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"模型请求分布"}),e.jsxs(os,{children:["各模型使用占比 (共 ",he.length," 个模型)"]})]}),e.jsx(Me,{children:e.jsx(Vr,{config:Object.fromEntries(he.map((M,Q)=>[M.model_name,{label:M.model_name,color:Te[Q]}])),className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(Kw,{children:[e.jsx(qi,{content:e.jsx(Gr,{})}),e.jsx(Qw,{data:q,cx:"50%",cy:"50%",labelLine:!1,label:({name:M,percent:Q})=>Q&&Q<.05?"":`${M} ${Q?(Q*100).toFixed(0):0}%`,outerRadius:100,dataKey:"value",children:q.map((M,Q)=>e.jsx(Yw,{fill:M.fill},`cell-${Q}`))})]})})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"模型详细统计"}),e.jsx(os,{children:"请求数、花费和性能"})]}),e.jsx(Me,{children:e.jsx(Je,{className:"h-[300px] sm:h-[400px]",children:e.jsx("div",{className:"space-y-3",children:he.map((M,Q)=>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:M.model_name}),e.jsx("div",{className:"w-3 h-3 rounded-full ml-2 flex-shrink-0",style:{backgroundColor:`hsl(var(--chart-${Q%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:M.request_count.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1 font-medium",children:["¥",M.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:[(M.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:[M.avg_response_time.toFixed(2),"s"]})]})]})]},Q))})})})]})]})}),e.jsx(ws,{value:"activity",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"最近活动"}),e.jsx(os,{children:"最新的API调用记录"})]}),e.jsx(Me,{children:e.jsx(Je,{className:"h-[400px] sm:h-[500px]",children:e.jsx("div",{className:"space-y-2",children:Y.map((M,Q)=>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:M.model}),e.jsx("div",{className:"text-xs text-muted-foreground",children:M.request_type})]}),e.jsx("div",{className:"text-xs text-muted-foreground flex-shrink-0",children:fe(M.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:M.tokens})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1",children:["¥",M.cost.toFixed(4)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"耗时:"}),e.jsxs("span",{className:"ml-1",children:[M.time_cost.toFixed(2),"s"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"状态:"}),e.jsx("span",{className:`ml-1 ${M.status==="success"?"text-green-600":"text-red-600"}`,children:M.status})]})]})]},Q))})})})]})}),e.jsx(ws,{value:"daily",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"每日统计"}),e.jsx(os,{children:"最近7天的数据汇总"})]}),e.jsx(Me,{children:e.jsx(Vr,{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(Uo,{data:R,children:[e.jsx(Qi,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Yi,{dataKey:"timestamp",tickFormatter:M=>{const Q=new Date(M);return`${Q.getMonth()+1}/${Q.getDate()}`},stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Hr,{yAxisId:"left",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Hr,{yAxisId:"right",orientation:"right",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(qi,{content:e.jsx(Gr,{labelFormatter:M=>new Date(M).toLocaleDateString("zh-CN")})}),e.jsx(O1,{content:e.jsx(Sv,{})}),e.jsx(Ji,{yAxisId:"left",dataKey:"requests",fill:"var(--color-requests)"}),e.jsx(Ji,{yAxisId:"right",dataKey:"cost",fill:"var(--color-cost)"})]})})})]})})]}),e.jsx(er,{}),e.jsx(Dv,{open:z,onOpenChange:M=>{S(M),M||X()}})]})})}const i2={theme:"system",setTheme:()=>null},Ov=m.createContext(i2),xx=()=>{const a=m.useContext(Ov);if(a===void 0)throw new Error("useTheme must be used within a ThemeProvider");return a},c2=(a,n,r)=>{const c=document.documentElement.classList.contains("no-animations");if(!document.startViewTransition||c){n(a);return}const d=r.clientX,u=r.clientY,h=Math.hypot(Math.max(d,innerWidth-d),Math.max(u,innerHeight-u));document.startViewTransition(()=>{n(a)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${d}px ${u}px)`,`circle(${h}px at ${d}px ${u}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},Lv=m.createContext(void 0),Uv=()=>{const a=m.useContext(Lv);if(a===void 0)throw new Error("useAnimation must be used within an AnimationProvider");return a},Ve=m.forwardRef(({className:a,...n},r)=>e.jsx(xj,{className:F("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",a),...n,ref:r,children:e.jsx(xw,{className:F("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")})}));Ve.displayName=xj.displayName;const o2=Wr("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),T=m.forwardRef(({className:a,...n},r)=>e.jsx(Vj,{ref:r,className:F(o2(),a),...n}));T.displayName=Vj.displayName;const d2=[{id:"minLength",label:"长度至少 10 位",description:"Token 长度必须大于等于 10 个字符",validate:a=>a.length>=10},{id:"hasUppercase",label:"包含大写字母",description:"至少包含一个大写字母 (A-Z)",validate:a=>/[A-Z]/.test(a)},{id:"hasLowercase",label:"包含小写字母",description:"至少包含一个小写字母 (a-z)",validate:a=>/[a-z]/.test(a)},{id:"hasSpecialChar",label:"包含特殊符号",description:"至少包含一个特殊符号 (!@#$%^&*()_+-=[]{}|;:,.<>?/)",validate:a=>/[!@#$%^&*()_+\-=[\]{}|;:,.<>?/]/.test(a)}];function u2(a){const n=d2.map(c=>({id:c.id,label:c.label,description:c.description,passed:c.validate(a)}));return{isValid:n.every(c=>c.passed),rules:n}}const od="0.12.2",hx="MaiBot Dashboard",m2=`${hx} v${od}`,x2=(a="v")=>`${a}${od}`,pa={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"},dl={theme:"system",accentColor:"blue",enableAnimations:!0,enableWavesBackground:!0,logCacheSize:1e3,logAutoScroll:!0,logFontSize:"xs",logLineSpacing:4,dataSyncInterval:30,wsReconnectInterval:3e3,wsMaxReconnectAttempts:10};function yt(a){const n=$v(a),r=localStorage.getItem(n);if(r===null)return dl[a];const c=dl[a];if(typeof c=="boolean")return r==="true";if(typeof c=="number"){const d=parseFloat(r);return isNaN(d)?c:d}return r}function qr(a,n){const r=$v(a);localStorage.setItem(r,String(n)),window.dispatchEvent(new CustomEvent("maibot-settings-change",{detail:{key:a,value:n}}))}function h2(){return{theme:yt("theme"),accentColor:yt("accentColor"),enableAnimations:yt("enableAnimations"),enableWavesBackground:yt("enableWavesBackground"),logCacheSize:yt("logCacheSize"),logAutoScroll:yt("logAutoScroll"),logFontSize:yt("logFontSize"),logLineSpacing:yt("logLineSpacing"),dataSyncInterval:yt("dataSyncInterval"),wsReconnectInterval:yt("wsReconnectInterval"),wsMaxReconnectAttempts:yt("wsMaxReconnectAttempts")}}function f2(){const a=h2(),n=localStorage.getItem(pa.COMPLETED_TOURS),r=n?JSON.parse(n):[];return{...a,completedTours:r}}function p2(a){const n=[],r=[];for(const[c,d]of Object.entries(a)){if(c==="completedTours"){Array.isArray(d)?(localStorage.setItem(pa.COMPLETED_TOURS,JSON.stringify(d)),n.push("completedTours")):r.push("completedTours");continue}if(c in dl){const u=c,h=dl[u];if(typeof d==typeof h){if(u==="theme"&&!["light","dark","system"].includes(d)){r.push(c);continue}if(u==="logFontSize"&&!["xs","sm","base"].includes(d)){r.push(c);continue}qr(u,d),n.push(c)}else r.push(c)}else r.push(c)}return{success:n.length>0,imported:n,skipped:r}}function g2(){for(const a of Object.keys(dl))qr(a,dl[a]);localStorage.removeItem(pa.COMPLETED_TOURS),window.dispatchEvent(new CustomEvent("maibot-settings-reset"))}function j2(){const a=[],n=[],r=[];for(let c=0;cc.size-r.size),{used:a,items:localStorage.length,details:n}}function v2(a){if(a===0)return"0 B";const n=1024,r=["B","KB","MB"],c=Math.floor(Math.log(a)/Math.log(n));return parseFloat((a/Math.pow(n,c)).toFixed(2))+" "+r[c]}function $v(a){return{theme:pa.THEME,accentColor:pa.ACCENT_COLOR,enableAnimations:pa.ENABLE_ANIMATIONS,enableWavesBackground:pa.ENABLE_WAVES_BACKGROUND,logCacheSize:pa.LOG_CACHE_SIZE,logAutoScroll:pa.LOG_AUTO_SCROLL,logFontSize:pa.LOG_FONT_SIZE,logLineSpacing:pa.LOG_LINE_SPACING,dataSyncInterval:pa.DATA_SYNC_INTERVAL,wsReconnectInterval:pa.WS_RECONNECT_INTERVAL,wsMaxReconnectAttempts:pa.WS_MAX_RECONNECT_ATTEMPTS}[a]}const Qa=m.forwardRef(({className:a,...n},r)=>e.jsxs(hj,{ref:r,className:F("relative flex w-full touch-none select-none items-center",a),...n,children:[e.jsx(hw,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(fw,{className:"absolute h-full bg-primary"})}),e.jsx(pw,{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"})]}));Qa.displayName=hj.displayName;class N2{ws=null;reconnectTimeout=null;reconnectAttempts=0;heartbeatInterval=null;logCallbacks=new Set;connectionCallbacks=new Set;isConnected=!1;logCache=[];getMaxCacheSize(){return yt("logCacheSize")}getMaxReconnectAttempts(){return yt("wsMaxReconnectAttempts")}getReconnectInterval(){return yt("wsReconnectInterval")}getWebSocketUrl(n){let r;{const c=window.location.protocol==="https:"?"wss:":"ws:",d=window.location.host;r=`${c}//${d}/ws/logs`}return n?`${r}?token=${encodeURIComponent(n)}`:r}async getWsToken(){try{const n=await _e("/api/webui/ws-token",{method:"GET",credentials:"include"});if(!n.ok)return console.error("获取 WebSocket token 失败:",n.status),null;const r=await n.json();return r.success&&r.token?r.token:null}catch(n){return console.error("获取 WebSocket token 失败:",n),null}}async connect(){if(this.ws?.readyState===WebSocket.OPEN||this.ws?.readyState===WebSocket.CONNECTING)return;if(window.location.pathname==="/auth"){console.log("📡 在登录页面,跳过 WebSocket 连接");return}if(!await cc()){console.log("📡 未登录,跳过 WebSocket 连接");return}const r=await this.getWsToken();if(!r){console.log("📡 无法获取 WebSocket token,跳过连接");return}const c=this.getWebSocketUrl(r);try{this.ws=new WebSocket(c),this.ws.onopen=()=>{this.isConnected=!0,this.reconnectAttempts=0,this.notifyConnection(!0),this.startHeartbeat()},this.ws.onmessage=d=>{try{if(d.data==="pong")return;const u=JSON.parse(d.data);this.notifyLog(u)}catch(u){console.error("解析日志消息失败:",u)}},this.ws.onerror=d=>{console.error("❌ WebSocket 错误:",d),this.isConnected=!1,this.notifyConnection(!1)},this.ws.onclose=()=>{this.isConnected=!1,this.notifyConnection(!1),this.stopHeartbeat(),this.attemptReconnect()}}catch(d){console.error("创建 WebSocket 连接失败:",d),this.attemptReconnect()}}attemptReconnect(){const n=this.getMaxReconnectAttempts();if(this.reconnectAttempts>=n)return;this.reconnectAttempts+=1;const r=this.getReconnectInterval(),c=Math.min(r*this.reconnectAttempts,3e4);this.reconnectTimeout=window.setTimeout(()=>{this.connect()},c)}startHeartbeat(){this.heartbeatInterval=window.setInterval(()=>{this.ws?.readyState===WebSocket.OPEN&&this.ws.send("ping")},3e4)}stopHeartbeat(){this.heartbeatInterval!==null&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null)}disconnect(){this.reconnectTimeout!==null&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.stopHeartbeat(),this.ws&&(this.ws.close(),this.ws=null),this.isConnected=!1,this.reconnectAttempts=0}onLog(n){return this.logCallbacks.add(n),()=>this.logCallbacks.delete(n)}onConnectionChange(n){return this.connectionCallbacks.add(n),n(this.isConnected),()=>this.connectionCallbacks.delete(n)}notifyLog(n){if(!this.logCache.some(c=>c.id===n.id)){this.logCache.push(n);const c=this.getMaxCacheSize();this.logCache.length>c&&(this.logCache=this.logCache.slice(-c)),this.logCallbacks.forEach(d=>{try{d(n)}catch(u){console.error("日志回调执行失败:",u)}})}}notifyConnection(n){this.connectionCallbacks.forEach(r=>{try{r(n)}catch(c){console.error("连接状态回调执行失败:",c)}})}getAllLogs(){return[...this.logCache]}clearLogs(){this.logCache=[]}getConnectionStatus(){return this.isConnected}}const Hn=new N2;typeof window<"u"&&setTimeout(()=>{Hn.connect()},100);const Ns=jw,wt=vw,b2=gw,Bv=m.forwardRef(({className:a,...n},r)=>e.jsx(fj,{className:F("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",a),...n,ref:r}));Bv.displayName=fj.displayName;const us=m.forwardRef(({className:a,...n},r)=>e.jsxs(b2,{children:[e.jsx(Bv,{}),e.jsx(pj,{ref:r,className:F("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",a),...n})]}));us.displayName=pj.displayName;const ms=({className:a,...n})=>e.jsx("div",{className:F("flex flex-col space-y-2 text-center sm:text-left",a),...n});ms.displayName="AlertDialogHeader";const xs=({className:a,...n})=>e.jsx("div",{className:F("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",a),...n});xs.displayName="AlertDialogFooter";const hs=m.forwardRef(({className:a,...n},r)=>e.jsx(gj,{ref:r,className:F("text-lg font-semibold",a),...n}));hs.displayName=gj.displayName;const fs=m.forwardRef(({className:a,...n},r)=>e.jsx(jj,{ref:r,className:F("text-sm text-muted-foreground",a),...n}));fs.displayName=jj.displayName;const ps=m.forwardRef(({className:a,variant:n,...r},c)=>e.jsx(vj,{ref:c,className:F(Zr({variant:n}),a),...r}));ps.displayName=vj.displayName;const gs=m.forwardRef(({className:a,...n},r)=>e.jsx(Nj,{ref:r,className:F(Zr({variant:"outline"}),"mt-2 sm:mt-0",a),...n}));gs.displayName=Nj.displayName;function y2(){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(ta,{defaultValue:"appearance",className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2 sm:grid-cols-4 gap-0.5 sm:gap-1 h-auto p-1",children:[e.jsxs(Xe,{value:"appearance",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(w_,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"外观"})]}),e.jsxs(Xe,{value:"security",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(ev,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"安全"})]}),e.jsxs(Xe,{value:"other",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(vn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"其他"})]}),e.jsxs(Xe,{value:"about",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(Ft,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"关于"})]})]}),e.jsxs(Je,{className:"h-[calc(100vh-240px)] sm:h-[calc(100vh-280px)] mt-4 sm:mt-6",children:[e.jsx(ws,{value:"appearance",className:"mt-0",children:e.jsx(w2,{})}),e.jsx(ws,{value:"security",className:"mt-0",children:e.jsx(_2,{})}),e.jsx(ws,{value:"other",className:"mt-0",children:e.jsx(S2,{})}),e.jsx(ws,{value:"about",className:"mt-0",children:e.jsx(k2,{})})]})]})]})}function Rg(a){const n=document.documentElement,c={blue:{hsl:"221.2 83.2% 53.3%",darkHsl:"217.2 91.2% 59.8%",gradient:null},purple:{hsl:"271 91% 65%",darkHsl:"270 95% 75%",gradient:null},green:{hsl:"142 71% 45%",darkHsl:"142 76% 36%",gradient:null},orange:{hsl:"25 95% 53%",darkHsl:"20 90% 48%",gradient:null},pink:{hsl:"330 81% 60%",darkHsl:"330 85% 70%",gradient:null},red:{hsl:"0 84% 60%",darkHsl:"0 90% 70%",gradient:null},"gradient-sunset":{hsl:"15 95% 60%",darkHsl:"15 95% 65%",gradient:"linear-gradient(135deg, hsl(25 95% 53%) 0%, hsl(330 81% 60%) 100%)"},"gradient-ocean":{hsl:"200 90% 55%",darkHsl:"200 90% 60%",gradient:"linear-gradient(135deg, hsl(221.2 83.2% 53.3%) 0%, hsl(189 94% 43%) 100%)"},"gradient-forest":{hsl:"150 70% 45%",darkHsl:"150 75% 40%",gradient:"linear-gradient(135deg, hsl(142 71% 45%) 0%, hsl(158 64% 52%) 100%)"},"gradient-aurora":{hsl:"310 85% 65%",darkHsl:"310 90% 70%",gradient:"linear-gradient(135deg, hsl(271 91% 65%) 0%, hsl(330 81% 60%) 100%)"},"gradient-fire":{hsl:"15 95% 55%",darkHsl:"15 95% 60%",gradient:"linear-gradient(135deg, hsl(0 84% 60%) 0%, hsl(25 95% 53%) 100%)"},"gradient-twilight":{hsl:"250 90% 60%",darkHsl:"250 95% 65%",gradient:"linear-gradient(135deg, hsl(239 84% 67%) 0%, hsl(271 91% 65%) 100%)"}}[a];if(c)n.style.setProperty("--primary",c.hsl),c.gradient?(n.style.setProperty("--primary-gradient",c.gradient),n.classList.add("has-gradient")):(n.style.removeProperty("--primary-gradient"),n.classList.remove("has-gradient"));else if(a.startsWith("#")){const d=u=>{u=u.replace("#","");const h=parseInt(u.substring(0,2),16)/255,f=parseInt(u.substring(2,4),16)/255,p=parseInt(u.substring(4,6),16)/255,g=Math.max(h,f,p),N=Math.min(h,f,p);let v=0,w=0;const b=(g+N)/2;if(g!==N){const y=g-N;switch(w=b>.5?y/(2-g-N):y/(g+N),g){case h:v=((f-p)/y+(flocalStorage.getItem("accent-color")||"blue");m.useEffect(()=>{const g=localStorage.getItem("accent-color")||"blue";Rg(g)},[]);const p=g=>{f(g),localStorage.setItem("accent-color",g),Rg(g)};return e.jsxs("div",{className:"space-y-6 sm:space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题模式"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4",children:[e.jsx(Lm,{value:"light",current:a,onChange:n,label:"浅色",description:"始终使用浅色主题"}),e.jsx(Lm,{value:"dark",current:a,onChange:n,label:"深色",description:"始终使用深色主题"}),e.jsx(Lm,{value:"system",current:a,onChange:n,label:"跟随系统",description:"根据系统设置自动切换"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题色"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"单色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(qa,{value:"blue",current:h,onChange:p,label:"蓝色",colorClass:"bg-blue-500"}),e.jsx(qa,{value:"purple",current:h,onChange:p,label:"紫色",colorClass:"bg-purple-500"}),e.jsx(qa,{value:"green",current:h,onChange:p,label:"绿色",colorClass:"bg-green-500"}),e.jsx(qa,{value:"orange",current:h,onChange:p,label:"橙色",colorClass:"bg-orange-500"}),e.jsx(qa,{value:"pink",current:h,onChange:p,label:"粉色",colorClass:"bg-pink-500"}),e.jsx(qa,{value:"red",current:h,onChange:p,label:"红色",colorClass:"bg-red-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"渐变色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(qa,{value:"gradient-sunset",current:h,onChange:p,label:"日落",colorClass:"bg-gradient-to-r from-orange-500 to-pink-500"}),e.jsx(qa,{value:"gradient-ocean",current:h,onChange:p,label:"海洋",colorClass:"bg-gradient-to-r from-blue-500 to-cyan-500"}),e.jsx(qa,{value:"gradient-forest",current:h,onChange:p,label:"森林",colorClass:"bg-gradient-to-r from-green-500 to-emerald-500"}),e.jsx(qa,{value:"gradient-aurora",current:h,onChange:p,label:"极光",colorClass:"bg-gradient-to-r from-purple-500 to-pink-500"}),e.jsx(qa,{value:"gradient-fire",current:h,onChange:p,label:"烈焰",colorClass:"bg-gradient-to-r from-red-500 to-orange-500"}),e.jsx(qa,{value:"gradient-twilight",current:h,onChange:p,label:"暮光",colorClass:"bg-gradient-to-r from-indigo-500 to-purple-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"自定义颜色"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 sm:gap-4",children:[e.jsx("div",{className:"flex-1",children:e.jsx("input",{type:"color",value:h.startsWith("#")?h:"#3b82f6",onChange:g=>p(g.target.value),className:"h-10 sm:h-12 w-full rounded-lg border-2 border-border cursor-pointer",title:"选择自定义颜色"})}),e.jsx("div",{className:"flex-1",children:e.jsx(le,{type:"text",value:h,onChange:g=>p(g.target.value),placeholder:"#3b82f6",className:"font-mono text-sm"})})]}),e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground mt-2",children:"点击色块选择颜色,或手动输入 HEX 颜色代码"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"动画效果"}),e.jsxs("div",{className:"space-y-2 sm:space-y-3",children:[e.jsx("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(T,{htmlFor:"animations",className:"text-base font-medium cursor-pointer",children:"启用动画效果"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后将禁用所有过渡动画和特效,提升性能"})]}),e.jsx(Ve,{id:"animations",checked:r,onCheckedChange:c})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(T,{htmlFor:"waves-background",className:"text-base font-medium cursor-pointer",children:"登录页波浪背景"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后登录页将使用纯色背景,适合低性能设备"})]}),e.jsx(Ve,{id:"waves-background",checked:d,onCheckedChange:u})]})})]})]})]})}function _2(){const a=ca(),[n,r]=m.useState(""),[c,d]=m.useState(""),[u,h]=m.useState(!1),[f,p]=m.useState(!1),[g,N]=m.useState(!1),[v,w]=m.useState(!1),[b,y]=m.useState(!1),[A,z]=m.useState(!1),[S,U]=m.useState(""),[E,C]=m.useState(!1),{toast:D}=Ys(),I=m.useMemo(()=>u2(c),[c]),O=async de=>{if(!n){D({title:"无法复制",description:"Token 存储在安全 Cookie 中,请重新生成以获取新 Token",variant:"destructive"});return}try{await navigator.clipboard.writeText(de),y(!0),D({title:"复制成功",description:"Token 已复制到剪贴板"}),setTimeout(()=>y(!1),2e3)}catch{D({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},X=async()=>{if(!c.trim()){D({title:"输入错误",description:"请输入新的 Token",variant:"destructive"});return}if(!I.isValid){const de=I.rules.filter(he=>!he.passed).map(he=>he.label).join(", ");D({title:"格式错误",description:`Token 不符合要求: ${de}`,variant:"destructive"});return}N(!0);try{const de=await fetch("/api/webui/auth/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({new_token:c.trim()})}),he=await de.json();de.ok&&he.success?(d(""),r(c.trim()),D({title:"更新成功",description:"Access Token 已更新,即将跳转到登录页"}),setTimeout(()=>{a({to:"/auth"})},1500)):D({title:"更新失败",description:he.message||"无法更新 Token",variant:"destructive"})}catch(de){console.error("更新 Token 错误:",de),D({title:"更新失败",description:"连接服务器失败",variant:"destructive"})}finally{N(!1)}},L=async()=>{w(!0);try{const de=await fetch("/api/webui/auth/regenerate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"}),he=await de.json();de.ok&&he.success?(r(he.token),U(he.token),z(!0),C(!1),D({title:"生成成功",description:"新的 Access Token 已生成,请及时保存"})):D({title:"生成失败",description:he.message||"无法生成新 Token",variant:"destructive"})}catch(de){console.error("生成 Token 错误:",de),D({title:"生成失败",description:"连接服务器失败",variant:"destructive"})}finally{w(!1)}},oe=async()=>{try{await navigator.clipboard.writeText(S),C(!0),D({title:"复制成功",description:"Token 已复制到剪贴板"})}catch{D({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},Ne=()=>{z(!1),setTimeout(()=>{U(""),C(!1)},300),setTimeout(()=>{a({to:"/auth"})},500)},je=de=>{de||Ne()};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(Ps,{open:A,onOpenChange:je,children:e.jsxs(Ds,{className:"sm:max-w-md",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(Jt,{className:"h-5 w-5 text-yellow-500"}),"新的 Access Token"]}),e.jsx(Ks,{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(T,{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:S})]}),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(Jt,{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(_,{variant:"outline",onClick:oe,className:"gap-2",children:E?e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"h-4 w-4 text-green-500"}),"已复制"]}):e.jsxs(e.Fragment,{children:[e.jsx(Fo,{className:"h-4 w-4"}),"复制 Token"]})}),e.jsx(_,{onClick:Ne,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(T,{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(le,{id:"current-token",type:u?"text":"password",value:n||"••••••••••••••••••••••••••••••••",readOnly:!0,className:"pr-10 font-mono text-sm",placeholder:"Token 存储在安全 Cookie 中"}),e.jsx("button",{onClick:()=>{n?h(!u):D({title:"无法查看",description:'Token 存储在安全 Cookie 中,如需新 Token 请点击"重新生成"'})},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:u?"隐藏":"显示",children:u?e.jsx(nc,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(ia,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(_,{variant:"outline",size:"icon",onClick:()=>O(n),title:"复制到剪贴板",className:"flex-shrink-0",disabled:!n,children:b?e.jsx(Ct,{className:"h-4 w-4 text-green-500"}):e.jsx(Fo,{className:"h-4 w-4"})}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{variant:"outline",disabled:v,className:"gap-2 flex-1 sm:flex-none",children:[e.jsx(dt,{className:F("h-4 w-4",v&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:"重新生成"}),e.jsx("span",{className:"sm:hidden",children:"生成"})]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重新生成 Token"}),e.jsx(fs,{children:"这将生成一个新的 64 位安全令牌,并使当前 Token 立即失效。 您需要使用新 Token 重新登录系统。此操作不可撤销,确定要继续吗?"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:L,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(T,{htmlFor:"new-token",className:"text-sm",children:"新的访问令牌"}),e.jsxs("div",{className:"relative",children:[e.jsx(le,{id:"new-token",type:f?"text":"password",value:c,onChange:de=>d(de.target.value),className:"pr-10 font-mono text-sm",placeholder:"输入自定义 Token"}),e.jsx("button",{onClick:()=>p(!f),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:f?"隐藏":"显示",children:f?e.jsx(nc,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(ia,{className:"h-4 w-4 text-muted-foreground"})})]}),c&&e.jsxs("div",{className:"mt-3 space-y-2 p-3 rounded-lg bg-muted/50",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Token 安全要求:"}),e.jsx("div",{className:"space-y-1.5",children:I.rules.map(de=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[de.passed?e.jsx(pt,{className:"h-4 w-4 text-green-500 flex-shrink-0"}):e.jsx(Ka,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:F(de.passed?"text-green-600 dark:text-green-400":"text-muted-foreground"),children:de.label})]},de.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(Ct,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:"Token 格式正确,可以使用"})]})})]})]}),e.jsx(_,{onClick:X,disabled:g||!I.isValid||!c,className:"w-full sm:w-auto",children:g?"更新中...":"更新自定义 Token"})]})]}),e.jsxs("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3 sm:p-4",children:[e.jsx("h4",{className:"text-sm sm:text-base font-semibold text-yellow-900 dark:text-yellow-200 mb-2",children:"安全提示"}),e.jsxs("ul",{className:"text-xs sm:text-sm text-yellow-800 dark:text-yellow-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"重新生成 Token 会创建系统随机生成的 64 位安全令牌"}),e.jsx("li",{children:"自定义 Token 必须满足所有安全要求才能使用"}),e.jsx("li",{children:"更新 Token 后,旧的 Token 将立即失效"}),e.jsx("li",{children:"请在安全的环境下查看和复制 Token"}),e.jsx("li",{children:"如果怀疑 Token 泄露,请立即重新生成或更新"}),e.jsx("li",{children:"建议使用系统生成的 Token 以获得最高安全性"})]})]})]})}function S2(){const a=ca(),{toast:n}=Ys(),[r,c]=m.useState(!1),[d,u]=m.useState(!1),[h,f]=m.useState(()=>yt("logCacheSize")),[p,g]=m.useState(()=>yt("wsReconnectInterval")),[N,v]=m.useState(()=>yt("wsMaxReconnectAttempts")),[w,b]=m.useState(()=>yt("dataSyncInterval")),[y,A]=m.useState(()=>zg()),[z,S]=m.useState(!1),[U,E]=m.useState(!1),C=m.useRef(null);if(d)throw new Error("这是一个手动触发的测试错误,用于验证错误边界组件是否正常工作。");const D=()=>{A(zg())},I=R=>{const Y=R[0];f(Y),qr("logCacheSize",Y)},O=R=>{const Y=R[0];g(Y),qr("wsReconnectInterval",Y)},X=R=>{const Y=R[0];v(Y),qr("wsMaxReconnectAttempts",Y)},L=R=>{const Y=R[0];b(Y),qr("dataSyncInterval",Y)},oe=()=>{Hn.clearLogs(),n({title:"日志已清除",description:"日志缓存已清空"})},Ne=()=>{const R=j2();D(),n({title:"缓存已清除",description:`已清除 ${R.clearedKeys.length} 项缓存数据`})},je=()=>{S(!0);try{const R=f2(),Y=JSON.stringify(R,null,2),$=new Blob([Y],{type:"application/json"}),ue=URL.createObjectURL($),G=document.createElement("a");G.href=ue,G.download=`maibot-webui-settings-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(G),G.click(),document.body.removeChild(G),URL.revokeObjectURL(ue),n({title:"导出成功",description:"设置已导出为 JSON 文件"})}catch(R){console.error("导出设置失败:",R),n({title:"导出失败",description:"无法导出设置",variant:"destructive"})}finally{S(!1)}},de=R=>{const Y=R.target.files?.[0];if(!Y)return;E(!0);const $=new FileReader;$.onload=ue=>{try{const G=ue.target?.result,Se=JSON.parse(G),fe=p2(Se);fe.success?(f(yt("logCacheSize")),g(yt("wsReconnectInterval")),v(yt("wsMaxReconnectAttempts")),b(yt("dataSyncInterval")),D(),n({title:"导入成功",description:`成功导入 ${fe.imported.length} 项设置${fe.skipped.length>0?`,跳过 ${fe.skipped.length} 项`:""}`}),(fe.imported.includes("theme")||fe.imported.includes("accentColor"))&&n({title:"提示",description:"部分设置需要刷新页面才能完全生效"})):n({title:"导入失败",description:"没有有效的设置项可导入",variant:"destructive"})}catch(G){console.error("导入设置失败:",G),n({title:"导入失败",description:"文件格式无效",variant:"destructive"})}finally{E(!1),C.current&&(C.current.value="")}},$.readAsText(Y)},he=()=>{g2(),f(dl.logCacheSize),g(dl.wsReconnectInterval),v(dl.wsMaxReconnectAttempts),b(dl.dataSyncInterval),D(),n({title:"已重置",description:"所有设置已恢复为默认值,刷新页面以应用更改"})},ge=async()=>{c(!0);try{const R=await _e("/api/webui/setup/reset",{method:"POST"}),Y=await R.json();R.ok&&Y.success?(n({title:"重置成功",description:"即将进入初次配置向导"}),setTimeout(()=>{a({to:"/setup"})},1e3)):n({title:"重置失败",description:Y.message||"无法重置配置状态",variant:"destructive"})}catch(R){console.error("重置配置状态错误:",R),n({title:"重置失败",description:"连接服务器失败",variant:"destructive"})}finally{c(!1)}};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(Yr,{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(__,{className:"h-4 w-4"}),"本地存储使用"]}),e.jsx(_,{variant:"ghost",size:"sm",onClick:D,className:"h-7 px-2",children:e.jsx(dt,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:v2(y.used)}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[y.items," 个存储项"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{className:"text-sm font-medium",children:"日志缓存大小"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h," 条"]})]}),e.jsx(Qa,{value:[h],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(T,{className:"text-sm font-medium",children:"首页数据刷新间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[w," 秒"]})]}),e.jsx(Qa,{value:[w],onValueChange:L,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(T,{className:"text-sm font-medium",children:"WebSocket 重连间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[p/1e3," 秒"]})]}),e.jsx(Qa,{value:[p],onValueChange:O,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(T,{className:"text-sm font-medium",children:"WebSocket 最大重连次数"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[N," 次"]})]}),e.jsx(Qa,{value:[N],onValueChange:X,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(_,{variant:"outline",size:"sm",onClick:oe,className:"gap-2",children:[e.jsx(ns,{className:"h-4 w-4"}),"清除日志缓存"]}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(ns,{className:"h-4 w-4"}),"清除本地缓存"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认清除本地缓存"}),e.jsx(fs,{children:"这将清除所有本地缓存的设置和数据(不包括登录凭证)。 您可能需要重新配置部分偏好设置。确定要继续吗?"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:Ne,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(Xt,{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(_,{variant:"outline",onClick:je,disabled:z,className:"gap-2",children:[e.jsx(Xt,{className:"h-4 w-4"}),z?"导出中...":"导出设置"]}),e.jsx("input",{ref:C,type:"file",accept:".json",onChange:de,className:"hidden"}),e.jsxs(_,{variant:"outline",onClick:()=>C.current?.click(),disabled:U,className:"gap-2",children:[e.jsx(rc,{className:"h-4 w-4"}),U?"导入中...":"导入设置"]})]}),e.jsx("div",{className:"pt-2 border-t",children:e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"gap-2 text-destructive hover:text-destructive",children:[e.jsx(lc,{className:"h-4 w-4"}),"重置所有设置为默认值"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重置所有设置"}),e.jsx(fs,{children:"这将把所有界面设置恢复为默认值,包括主题、颜色、动画等偏好设置。 此操作不会影响您的登录状态。确定要继续吗?"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:he,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(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{variant:"outline",disabled:r,className:"gap-2",children:[e.jsx(lc,{className:F("h-4 w-4",r&&"animate-spin")}),"重新进行初次配置"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重新配置"}),e.jsx(fs,{children:"这将带您重新进入初次配置向导。您可以重新设置系统的基础配置项。确定要继续吗?"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:ge,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(Jt,{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(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{variant:"destructive",className:"gap-2",children:[e.jsx(Jt,{className:"h-4 w-4"}),"触发测试错误"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认触发错误"}),e.jsx(fs,{children:"这将手动触发一个 React 错误,用于测试错误边界组件的显示效果。 页面将显示错误界面,您可以通过刷新页面或点击返回首页来恢复。"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>u(!0),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认触发"})]})]})]})]})]})]})}function k2(){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:F("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:["关于 ",hx]}),e.jsxs("div",{className:"space-y-2 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("p",{children:["版本: ",od]}),e.jsx("p",{children:"麦麦(MaiBot)的现代化 Web 管理界面"})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"作者"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"MaiBot 核心"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"Mai-with-u"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"WebUI"}),e.jsxs("p",{className:"text-xs sm:text-sm text-muted-foreground",children:["Mai-with-u ",e.jsx("a",{href:"https://github.com/DrSmoothl",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"@MotricSeven"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"技术栈"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"前端框架"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"React 19.2.0"}),e.jsx("li",{children:"TypeScript 5.7.2"}),e.jsx("li",{children:"Vite 6.0.7"}),e.jsx("li",{children:"TanStack Router 1.94.2"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"UI 组件"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"shadcn/ui"}),e.jsx("li",{children:"Radix UI"}),e.jsx("li",{children:"Tailwind CSS 3.4.17"}),e.jsx("li",{children:"Lucide Icons"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"后端"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Python 3.12+"}),e.jsx("li",{children:"FastAPI"}),e.jsx("li",{children:"Uvicorn"}),e.jsx("li",{children:"WebSocket"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"构建工具"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Bun / npm"}),e.jsx("li",{children:"ESLint 9.17.0"}),e.jsx("li",{children:"PostCSS"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"开源库感谢"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mb-3",children:"本项目使用了以下优秀的开源库,感谢他们的贡献:"}),e.jsx(Je,{className:"h-[300px] sm:h-[400px]",children:e.jsxs("div",{className:"space-y-4 pr-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"UI 框架与组件"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(ft,{name:"React",description:"用户界面构建库",license:"MIT"}),e.jsx(ft,{name:"shadcn/ui",description:"优雅的 React 组件库",license:"MIT"}),e.jsx(ft,{name:"Radix UI",description:"无样式的可访问组件库",license:"MIT"}),e.jsx(ft,{name:"Tailwind CSS",description:"实用优先的 CSS 框架",license:"MIT"}),e.jsx(ft,{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(ft,{name:"TanStack Router",description:"类型安全的路由库",license:"MIT"}),e.jsx(ft,{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(ft,{name:"React Hook Form",description:"高性能表单库",license:"MIT"}),e.jsx(ft,{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(ft,{name:"clsx",description:"条件 className 构建工具",license:"MIT"}),e.jsx(ft,{name:"tailwind-merge",description:"Tailwind 类名合并工具",license:"MIT"}),e.jsx(ft,{name:"class-variance-authority",description:"组件变体管理",license:"Apache-2.0"}),e.jsx(ft,{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(ft,{name:"Framer Motion",description:"React 动画库",license:"MIT"}),e.jsx(ft,{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(ft,{name:"FastAPI",description:"现代化 Python Web 框架",license:"MIT"}),e.jsx(ft,{name:"Uvicorn",description:"ASGI 服务器",license:"BSD-3-Clause"}),e.jsx(ft,{name:"Pydantic",description:"数据验证库",license:"MIT"}),e.jsx(ft,{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(ft,{name:"TypeScript",description:"JavaScript 的超集",license:"Apache-2.0"}),e.jsx(ft,{name:"Vite",description:"下一代前端构建工具",license:"MIT"}),e.jsx(ft,{name:"ESLint",description:"JavaScript 代码检查工具",license:"MIT"}),e.jsx(ft,{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 ft({name:a,description:n,license:r}){return e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg border bg-muted/30 p-2.5 sm:p-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-foreground truncate",children:a}),e.jsx("p",{className:"text-muted-foreground text-xs mt-0.5",children:n})]}),e.jsx("span",{className:"inline-flex items-center rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary flex-shrink-0",children:r})]})}function Lm({value:a,current:n,onChange:r,label:c,description:d}){const u=n===a;return e.jsxs("button",{onClick:()=>r(a),className:F("relative rounded-lg border-2 p-3 sm:p-4 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",u?"border-primary bg-accent":"border-border"),children:[u&&e.jsx("div",{className:"absolute top-2 right-2 sm:top-3 sm:right-3 h-2 w-2 rounded-full bg-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm sm:text-base font-medium",children:c}),e.jsx("div",{className:"text-[10px] sm:text-xs text-muted-foreground",children:d})]}),e.jsxs("div",{className:"mt-2 sm:mt-3 flex gap-1",children:[a==="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"})]}),a==="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"})]}),a==="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 qa({value:a,current:n,onChange:r,label:c,colorClass:d}){const u=n===a;return e.jsxs("button",{onClick:()=>r(a),className:F("relative rounded-lg border-2 p-2 sm:p-3 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",u?"border-primary bg-accent":"border-border"),children:[u&&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:F("h-8 w-8 sm:h-10 sm:w-10 rounded-full",d)}),e.jsx("div",{className:"text-[10px] sm:text-xs font-medium text-center",children:c})]})]})}const C2=Date.now()%1e6;class T2{grad3;p;perm;constructor(n=0){this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.p=[];for(let r=0;r<256;r++)this.p[r]=Math.floor(Math.random()*256);this.perm=[];for(let r=0;r<512;r++)this.perm[r]=this.p[r&255]}dot(n,r,c){return n[0]*r+n[1]*c}mix(n,r,c){return(1-c)*n+c*r}fade(n){return n*n*n*(n*(n*6-15)+10)}perlin2(n,r){const c=Math.floor(n)&255,d=Math.floor(r)&255;n-=Math.floor(n),r-=Math.floor(r);const u=this.fade(n),h=this.fade(r),f=this.perm[c]+d,p=this.perm[f],g=this.perm[f+1],N=this.perm[c+1]+d,v=this.perm[N],w=this.perm[N+1];return this.mix(this.mix(this.dot(this.grad3[p%12],n,r),this.dot(this.grad3[v%12],n-1,r),u),this.mix(this.dot(this.grad3[g%12],n,r-1),this.dot(this.grad3[w%12],n-1,r-1),u),h)}}function Dg(){const a=m.useRef(null),n=m.useRef(null),r=m.useRef(void 0),[c]=m.useState(()=>new T2(C2)),d=m.useRef({mouse:{x:-10,y:0,lx:0,ly:0,sx:0,sy:0,v:0,vs:0,a:0,set:!1},lines:[],paths:[],noise:c,bounding:null});return m.useEffect(()=>{const u=n.current,h=a.current;if(!u||!h)return;const f=d.current;f.noise=c;const p=()=>{const z=u.getBoundingClientRect();f.bounding=z,h.style.width=`${z.width}px`,h.style.height=`${z.height}px`},g=()=>{if(!f.bounding)return;const{width:z,height:S}=f.bounding;f.lines=[],f.paths.forEach(oe=>oe.remove()),f.paths=[];const U=10,E=32,C=z+200,D=S+30,I=Math.ceil(C/U),O=Math.ceil(D/E),X=(z-U*I)/2,L=(S-E*O)/2;for(let oe=0;oe<=I;oe++){const Ne=[];for(let de=0;de<=O;de++){const he={x:X+U*oe,y:L+E*de,wave:{x:0,y:0},cursor:{x:0,y:0,vx:0,vy:0}};Ne.push(he)}const je=document.createElementNS("http://www.w3.org/2000/svg","path");h.appendChild(je),f.paths.push(je),f.lines.push(Ne)}},N=z=>{const{lines:S,mouse:U,noise:E}=f;S.forEach(C=>{C.forEach(D=>{const I=E.perlin2((D.x+z*.0125)*.002,(D.y+z*.005)*.0015)*12;D.wave.x=Math.cos(I)*32,D.wave.y=Math.sin(I)*16;const O=D.x-U.sx,X=D.y-U.sy,L=Math.hypot(O,X),oe=Math.max(175,U.vs);if(L{const U={x:z.x+z.wave.x+(S?z.cursor.x:0),y:z.y+z.wave.y+(S?z.cursor.y:0)};return U.x=Math.round(U.x*10)/10,U.y=Math.round(U.y*10)/10,U},w=()=>{const{lines:z,paths:S}=f;z.forEach((U,E)=>{let C=v(U[0],!1),D=`M ${C.x} ${C.y}`;U.forEach((I,O)=>{const X=O===U.length-1;C=v(I,!X),D+=`L ${C.x} ${C.y}`}),S[E].setAttribute("d",D)})},b=z=>{const{mouse:S}=f;S.sx+=(S.x-S.sx)*.1,S.sy+=(S.y-S.sy)*.1;const U=S.x-S.lx,E=S.y-S.ly,C=Math.hypot(U,E);S.v=C,S.vs+=(C-S.vs)*.1,S.vs=Math.min(100,S.vs),S.lx=S.x,S.ly=S.y,S.a=Math.atan2(E,U),u&&(u.style.setProperty("--x",`${S.sx}px`),u.style.setProperty("--y",`${S.sy}px`)),N(z),w(),r.current=requestAnimationFrame(b)},y=z=>{if(!f.bounding)return;const{mouse:S}=f;S.x=z.pageX-f.bounding.left,S.y=z.pageY-f.bounding.top+window.scrollY,S.set||(S.sx=S.x,S.sy=S.y,S.lx=S.x,S.ly=S.y,S.set=!0)},A=()=>{p(),g()};return p(),g(),window.addEventListener("resize",A),window.addEventListener("mousemove",y),r.current=requestAnimationFrame(b),()=>{window.removeEventListener("resize",A),window.removeEventListener("mousemove",y),r.current&&cancelAnimationFrame(r.current)}},[c]),e.jsxs("div",{ref:n,className:"waves-background",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden",pointerEvents:"none"},children:[e.jsx("div",{className:"waves-cursor",style:{position:"absolute",top:0,left:0,width:"0.5rem",height:"0.5rem",background:"hsl(var(--primary) / 0.3)",borderRadius:"50%",transform:"translate3d(calc(var(--x, -0.5rem) - 50%), calc(var(--y, 50%) - 50%), 0)",willChange:"transform",pointerEvents:"none"}}),e.jsx("svg",{ref:a,style:{display:"block",width:"100%",height:"100%"},children:e.jsx("style",{children:` + path { + fill: none; + stroke: hsl(var(--primary) / 0.20); + stroke-width: 1px; + } + `})})]})}function E2(){const[a,n]=m.useState(""),[r,c]=m.useState(!1),[d,u]=m.useState(""),[h,f]=m.useState(!0),p=ca(),{enableWavesBackground:g,setEnableWavesBackground:N}=Uv(),{theme:v,setTheme:w}=xx();m.useEffect(()=>{(async()=>{try{await cc()&&p({to:"/"})}catch{}finally{f(!1)}})()},[p]);const y=v==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":v,A=()=>{w(y==="dark"?"light":"dark")},z=async S=>{if(S.preventDefault(),u(""),!a.trim()){u("请输入 Access Token");return}c(!0),console.log("开始验证 token...");try{const U=await fetch("/api/webui/auth/verify",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({token:a.trim()})});console.log("Token 验证响应状态:",U.status);const E=await U.json();if(console.log("Token 验证响应数据:",E),U.ok&&E.valid){console.log("Token 验证成功,准备跳转..."),console.log("is_first_setup:",E.is_first_setup),await new Promise(D=>setTimeout(D,100));const C=await cc();console.log("跳转前认证状态检查:",C),E.is_first_setup?(console.log("跳转到首次配置页面"),p({to:"/setup"})):(console.log("跳转到首页"),p({to:"/"}))}else console.error("Token 验证失败:",E.message),u(E.message||"Token 验证失败,请检查后重试")}catch(U){console.error("Token 验证错误:",U),u("连接服务器失败,请检查网络连接")}finally{c(!1)}};return h?e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[g&&e.jsx(Dg,{}),e.jsx("div",{className:"text-muted-foreground",children:"正在检查登录状态..."})]}):e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[g&&e.jsx(Dg,{}),e.jsxs(Ce,{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:A,className:"absolute right-4 top-4 rounded-lg p-2 hover:bg-accent transition-colors z-10 text-foreground",title:y==="dark"?"切换到浅色模式":"切换到深色模式",children:y==="dark"?e.jsx(ax,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"}):e.jsx(ec,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"})}),e.jsxs(De,{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(bg,{className:"h-8 w-8 text-primary",strokeWidth:2,fill:"none"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-2xl font-bold",children:"欢迎使用 MaiBot"}),e.jsx(os,{className:"text-base",children:"请输入您的 Access Token 以继续访问系统"})]})]}),e.jsx(Me,{children:e.jsxs("form",{onSubmit:z,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"token",className:"text-sm font-medium",children:"Access Token"}),e.jsxs("div",{className:"relative",children:[e.jsx(lx,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground",strokeWidth:2,fill:"none"}),e.jsx(le,{id:"token",type:"password",placeholder:"请输入您的 Access Token",value:a,onChange:S=>n(S.target.value),className:F("pl-10",d&&"border-red-500 focus-visible:ring-red-500"),disabled:r,autoFocus:!0,autoComplete:"off"})]})]}),d&&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(_t,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{children:d})]}),e.jsx(_,{type:"submit",className:"w-full",disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"验证中..."]}):"验证并进入"}),e.jsxs(Ps,{children:[e.jsx(cd,{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(sv,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我没有 Token,我该去哪里获得 Token?"]})}),e.jsxs(Ds,{className:"sm:max-w-md",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(bg,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"如何获取 Access Token"]}),e.jsx(Ks,{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(S_,{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(Ea,{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(_t,{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(Ns,{children:[e.jsx(wt,{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(el,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我觉得这个界面很卡怎么办?"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsxs(hs,{className:"flex items-center gap-2",children:[e.jsx(el,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"关闭背景动画"]}),e.jsx(fs,{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(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>N(!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:m2})})]})}const ot=m.forwardRef(({className:a,...n},r)=>e.jsx("textarea",{className:F("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","custom-scrollbar",a),ref:r,...n}));ot.displayName="Textarea";const Yt=m.forwardRef(({className:a,orientation:n="horizontal",decorative:r=!0,...c},d)=>e.jsx(bj,{ref:d,decorative:r,orientation:n,className:F("shrink-0 bg-border",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",a),...c}));Yt.displayName=bj.displayName;function M2({config:a,onChange:n}){const r=d=>{d.trim()&&!a.alias_names.includes(d.trim())&&n({...a,alias_names:[...a.alias_names,d.trim()]})},c=d=>{n({...a,alias_names:a.alias_names.filter((u,h)=>h!==d)})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"qq_account",children:"QQ账号 *"}),e.jsx(le,{id:"qq_account",type:"number",placeholder:"请输入机器人的QQ账号",value:a.qq_account||"",onChange:d=>n({...a,qq_account:Number(d.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人登录使用的QQ账号"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"nickname",children:"昵称 *"}),e.jsx(le,{id:"nickname",placeholder:"请输入机器人的昵称",value:a.nickname,onChange:d=>n({...a,nickname:d.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人的主要称呼名称"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{children:"别名"}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:a.alias_names.map((d,u)=>e.jsxs(ke,{variant:"secondary",className:"gap-1",children:[d,e.jsx("button",{type:"button",onClick:()=>c(u),className:"ml-1 hover:text-destructive",children:e.jsx(Aa,{className:"h-3 w-3"})})]},u))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(le,{id:"alias_input",placeholder:"输入别名后按回车添加",onKeyPress:d=>{d.key==="Enter"&&(r(d.target.value),d.target.value="")}}),e.jsx(_,{type:"button",variant:"outline",onClick:()=>{const d=document.getElementById("alias_input");d&&(r(d.value),d.value="")},children:"添加"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人的其他称呼,可以添加多个"})]})]})}function A2({config:a,onChange:n}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"personality",children:"人格特征 *"}),e.jsx(ot,{id:"personality",placeholder:"描述机器人的人格特质和身份特征(建议120字以内)",value:a.personality,onChange:r=>n({...a,personality:r.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:是一个女大学生,现在在读大二,会刷贴吧"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"reply_style",children:"表达风格 *"}),e.jsx(ot,{id:"reply_style",placeholder:"描述机器人说话的表达风格、表达习惯",value:a.reply_style,onChange:r=>n({...a,reply_style:r.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:回复平淡一些,简短一些,说中文,参考贴吧、知乎和微博的回复风格"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"interest",children:"兴趣 *"}),e.jsx(ot,{id:"interest",placeholder:"描述机器人感兴趣的话题",value:a.interest,onChange:r=>n({...a,interest:r.target.value}),rows:2}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"会影响机器人对什么话题进行回复"})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"plan_style",children:"群聊说话规则 *"}),e.jsx(ot,{id:"plan_style",placeholder:"机器人在群聊中的行为风格和规则",value:a.plan_style,onChange:r=>n({...a,plan_style:r.target.value}),rows:4}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在群聊中如何行动,例如回复频率、条件等"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"private_plan_style",children:"私聊说话规则 *"}),e.jsx(ot,{id:"private_plan_style",placeholder:"机器人在私聊中的行为风格和规则",value:a.private_plan_style,onChange:r=>n({...a,private_plan_style:r.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在私聊中的行为方式"})]})]})}function z2({config:a,onChange:n}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(a.emoji_chance*100).toFixed(0),"%"]})]}),e.jsx(le,{id:"emoji_chance",type:"range",min:"0",max:"1",step:"0.1",value:a.emoji_chance,onChange:r=>n({...a,emoji_chance:Number(r.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人发送表情包的概率"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"max_reg_num",children:"最大表情包数量"}),e.jsx(le,{id:"max_reg_num",type:"number",min:"1",max:"200",value:a.max_reg_num,onChange:r=>n({...a,max_reg_num:Number(r.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人最多保存的表情包数量"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"do_replace",children:"达到最大数量时替换"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"开启后会删除旧表情包,关闭则不再收集新表情包"})]}),e.jsx(Ve,{id:"do_replace",checked:a.do_replace,onCheckedChange:r=>n({...a,do_replace:r})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(le,{id:"check_interval",type:"number",min:"1",max:"120",value:a.check_interval,onChange:r=>n({...a,check_interval:Number(r.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"检查表情包注册、破损、删除的时间间隔"})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"steal_emoji",children:"偷取表情包"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人将一些表情包据为己有"})]}),e.jsx(Ve,{id:"steal_emoji",checked:a.steal_emoji,onCheckedChange:r=>n({...a,steal_emoji:r})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"content_filtration",children:"启用表情包过滤"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只保存符合要求的表情包"})]}),e.jsx(Ve,{id:"content_filtration",checked:a.content_filtration,onCheckedChange:r=>n({...a,content_filtration:r})})]}),a.content_filtration&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(le,{id:"filtration_prompt",placeholder:"例如:符合公序良俗",value:a.filtration_prompt,onChange:r=>n({...a,filtration_prompt:r.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"描述表情包应该符合的要求"})]})]})}function R2({config:a,onChange:n}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"enable_tool",children:"启用工具系统"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人使用各种工具增强功能"})]}),e.jsx(Ve,{id:"enable_tool",checked:a.enable_tool,onCheckedChange:r=>n({...a,enable_tool:r})})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"all_global",children:"启用全局黑话模式"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人学习和使用群组黑话"})]}),e.jsx(Ve,{id:"all_global",checked:a.all_global,onCheckedChange:r=>n({...a,all_global:r})})]})]})}function D2({config:a,onChange:n}){const[r,c]=m.useState(!1);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"rounded-lg bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5",children:e.jsx("svg",{className:"h-5 w-5 text-blue-600 dark:text-blue-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsxs("div",{className:"flex-1 text-sm",children:[e.jsx("p",{className:"font-medium text-blue-900 dark:text-blue-100 mb-1",children:"关于硅基流动 (SiliconFlow)"}),e.jsx("p",{className:"text-blue-700 dark:text-blue-300 mb-2",children:"硅基流动提供了完整的模型覆盖,包括 DeepSeek V3、Qwen、视觉模型、语音识别和嵌入模型。 只需一个 API Key 即可使用麦麦的所有功能!"}),e.jsxs("a",{href:"https://cloud.siliconflow.cn",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-blue-600 dark:text-blue-400 hover:underline font-medium",children:["前往硅基流动获取 API Key",e.jsx($o,{className:"h-3 w-3"})]})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"siliconflow_api_key",children:"SiliconFlow API Key *"}),e.jsxs("div",{className:"relative",children:[e.jsx(le,{id:"siliconflow_api_key",type:r?"text":"password",placeholder:"sk-...",value:a.api_key,onChange:d=>n({api_key:d.target.value}),className:"font-mono pr-10"}),e.jsx(_,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",onClick:()=>c(!r),children:r?e.jsx(nc,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(ia,{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 O2(){const a=await _e("/api/webui/config/bot",{method:"GET",headers:Hs()});if(!a.ok)throw new Error("读取Bot配置失败");const r=(await a.json()).config.bot||{};return{qq_account:r.qq_account||0,nickname:r.nickname||"",alias_names:r.alias_names||[]}}async function L2(){const a=await _e("/api/webui/config/bot",{method:"GET",headers:Hs()});if(!a.ok)throw new Error("读取人格配置失败");const r=(await a.json()).config.personality||{};return{personality:r.personality||"",reply_style:r.reply_style||"",interest:r.interest||"",plan_style:r.plan_style||"",private_plan_style:r.private_plan_style||""}}async function U2(){const a=await _e("/api/webui/config/bot",{method:"GET",headers:Hs()});if(!a.ok)throw new Error("读取表情包配置失败");const r=(await a.json()).config.emoji||{};return{emoji_chance:r.emoji_chance??.4,max_reg_num:r.max_reg_num??40,do_replace:r.do_replace??!0,check_interval:r.check_interval??10,steal_emoji:r.steal_emoji??!0,content_filtration:r.content_filtration??!1,filtration_prompt:r.filtration_prompt||""}}async function $2(){const a=await _e("/api/webui/config/bot",{method:"GET",headers:Hs()});if(!a.ok)throw new Error("读取其他配置失败");const r=(await a.json()).config,c=r.tool||{},d=r.expression||{};return{enable_tool:c.enable_tool??!0,all_global:d.all_global_jargon??!0}}async function B2(){const a=await _e("/api/webui/config/model",{method:"GET",headers:Hs()});if(!a.ok)throw new Error("读取模型配置失败");return{api_key:((await a.json()).config.api_providers||[]).find(u=>u.name==="SiliconFlow")?.api_key||""}}async function P2(a){const n=await _e("/api/webui/config/bot/section/bot",{method:"POST",headers:Hs(),body:JSON.stringify(a)});if(!n.ok){const r=await n.json();throw new Error(r.detail||"保存Bot基础配置失败")}return await n.json()}async function I2(a){const n=await _e("/api/webui/config/bot/section/personality",{method:"POST",headers:Hs(),body:JSON.stringify(a)});if(!n.ok){const r=await n.json();throw new Error(r.detail||"保存人格配置失败")}return await n.json()}async function F2(a){const n=await _e("/api/webui/config/bot/section/emoji",{method:"POST",headers:Hs(),body:JSON.stringify(a)});if(!n.ok){const r=await n.json();throw new Error(r.detail||"保存表情包配置失败")}return await n.json()}async function H2(a){const n=[];n.push(_e("/api/webui/config/bot/section/tool",{method:"POST",headers:Hs(),body:JSON.stringify({enable_tool:a.enable_tool})})),n.push(_e("/api/webui/config/bot/section/expression",{method:"POST",headers:Hs(),body:JSON.stringify({all_global_jargon:a.all_global})}));const r=await Promise.all(n);for(const c of r)if(!c.ok){const d=await c.json();throw new Error(d.detail||"保存其他配置失败")}return{success:!0}}async function V2(a){const n=await _e("/api/webui/config/model",{method:"GET",headers:Hs()});if(!n.ok)throw new Error("读取模型配置失败");const c=(await n.json()).config,d=c.api_providers||[],u=d.findIndex(p=>p.name==="SiliconFlow");u>=0?d[u]={...d[u],api_key:a.api_key}:d.push({name:"SiliconFlow",base_url:"https://api.siliconflow.cn/v1",api_key:a.api_key,client_type:"openai",max_retry:3,timeout:120,retry_interval:5});const h={...c,api_providers:d},f=await _e("/api/webui/config/model",{method:"POST",headers:Hs(),body:JSON.stringify(h)});if(!f.ok){const p=await f.json();throw new Error(p.detail||"保存模型配置失败")}return await f.json()}async function Og(){const a=await _e("/api/webui/setup/complete",{method:"POST"});if(!a.ok){const n=await a.json();throw new Error(n.message||"标记配置完成失败")}return await a.json()}function G2(){return e.jsx(Wn,{children:e.jsx(q2,{})})}function q2(){const a=ca(),{toast:n}=Ys(),{triggerRestart:r}=yn(),[c,d]=m.useState(0),[u,h]=m.useState(!1),[f,p]=m.useState(!1),[g,N]=m.useState(!0),[v,w]=m.useState({qq_account:0,nickname:"",alias_names:[]}),[b,y]=m.useState({personality:"是一个女大学生,现在在读大二,会刷贴吧。",reply_style:"请回复的平淡一些,简短一些,说中文,不要刻意突出自身学科背景。可以参考贴吧,知乎和微博的回复风格。",interest:"对技术相关话题,游戏和动漫相关话题感兴趣,也对日常话题感兴趣,不喜欢太过沉重严肃的话题",plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 +2.如果相同的内容已经被执行,请不要重复执行 +3.请控制你的发言频率,不要太过频繁的发言 +4.如果有人对你感到厌烦,请减少回复 +5.如果有人对你进行攻击,或者情绪激动,请你以合适的方法应对`,private_plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 +2.如果相同的内容已经被执行,请不要重复执行 +3.某句话如果已经被回复过,不要重复回复`}),[A,z]=m.useState({emoji_chance:.4,max_reg_num:40,do_replace:!0,check_interval:10,steal_emoji:!0,content_filtration:!1,filtration_prompt:"符合公序良俗"}),[S,U]=m.useState({enable_tool:!0,all_global:!0}),[E,C]=m.useState({api_key:""}),D=[{id:"bot-basic",title:"Bot基础",description:"配置机器人的基本信息",icon:Vn},{id:"personality",title:"人格配置",description:"定义机器人的性格和说话风格",icon:jn},{id:"emoji",title:"表情包",description:"配置表情包相关设置",icon:ld},{id:"other",title:"其他设置",description:"工具、情绪系统等配置",icon:vn},{id:"siliconflow",title:"API配置",description:"配置硅基流动API密钥",icon:lx}],I=(c+1)/D.length*100;m.useEffect(()=>{(async()=>{try{N(!0);const[he,ge,R,Y,$]=await Promise.all([O2(),L2(),U2(),$2(),B2()]);w(he),y(ge),z(R),U(Y),C($)}catch(he){n({title:"加载配置失败",description:he instanceof Error?he.message:"无法加载现有配置,将使用默认值",variant:"destructive"})}finally{N(!1)}})()},[n]);const O=async()=>{p(!0);try{switch(c){case 0:await P2(v);break;case 1:await I2(b);break;case 2:await F2(A);break;case 3:await H2(S);break;case 4:await V2(E);break}return n({title:"保存成功",description:`${D[c].title}配置已保存`}),!0}catch(de){return n({title:"保存失败",description:de instanceof Error?de.message:"未知错误",variant:"destructive"}),!1}finally{p(!1)}},X=async()=>{await O()&&c{c>0&&d(c-1)},oe=async()=>{h(!0);try{if(!await O()){h(!1);return}await Og(),n({title:"配置完成",description:"麦麦正在重启以应用新配置..."}),await r()}catch(de){n({title:"配置失败",description:de instanceof Error?de.message:"未知错误",variant:"destructive"})}finally{h(!1)}},Ne=async()=>{try{await Og(),a({to:"/"})}catch(de){n({title:"跳过失败",description:de instanceof Error?de.message:"未知错误",variant:"destructive"})}},je=()=>{switch(c){case 0:return e.jsx(M2,{config:v,onChange:w});case 1:return e.jsx(A2,{config:b,onChange:y});case 2:return e.jsx(z2,{config:A,onChange:z});case 3:return e.jsx(R2,{config:S,onChange:U});case 4:return e.jsx(D2,{config:E,onChange:C});default:return null}};return e.jsxs("div",{className:"relative flex min-h-screen flex-col items-center justify-center overflow-hidden bg-gradient-to-br from-primary/5 via-background to-secondary/5 p-4 md:p-6",children:[e.jsx(er,{}),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(k_,{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:["让我们一起完成 ",hx," 的初始配置"]})]}),e.jsxs("div",{className:"mb-6 md:mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between text-xs md:text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["步骤 ",c+1," / ",D.length]}),e.jsxs("span",{className:"font-medium text-primary",children:[Math.round(I),"%"]})]}),e.jsx(Xn,{value:I,className:"h-2"})]}),e.jsx("div",{className:"mb-6 md:mb-8 flex justify-between",children:D.map((de,he)=>{const ge=de.icon;return e.jsxs("div",{className:F("flex flex-1 flex-col items-center gap-1 md:gap-2",hea({to:"/"}),className:"gap-2 w-full sm:w-auto",children:[e.jsx(nd,{className:"h-4 w-4"}),"返回首页"]}),e.jsxs(_,{size:"lg",variant:"outline",onClick:()=>window.history.back(),className:"gap-2 w-full sm:w-auto",children:[e.jsx(Ma,{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 K2=Rs.memo(function({config:n,onChange:r}){const c=n.platforms||[],d=n.alias_names||[],u=()=>{r({...n,platforms:[...c,""]})},h=v=>{r({...n,platforms:c.filter((w,b)=>b!==v)})},f=(v,w)=>{const b=[...c];b[v]=w,r({...n,platforms:b})},p=()=>{r({...n,alias_names:[...d,""]})},g=v=>{r({...n,alias_names:d.filter((w,b)=>b!==v)})},N=(v,w)=>{const b=[...d];b[v]=w,r({...n,alias_names:b})};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(T,{htmlFor:"platform",children:"平台"}),e.jsx(le,{id:"platform",value:n.platform,onChange:v=>r({...n,platform:v.target.value}),placeholder:"qq"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"qq_account",children:"QQ账号"}),e.jsx(le,{id:"qq_account",value:n.qq_account,onChange:v=>r({...n,qq_account:v.target.value}),placeholder:"123456789"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"nickname",children:"昵称"}),e.jsx(le,{id:"nickname",value:n.nickname,onChange:v=>r({...n,nickname:v.target.value}),placeholder:"麦麦"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"别名"}),e.jsxs(_,{onClick:p,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[d.map((v,w)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(le,{value:v,onChange:b=>N(w,b.target.value),placeholder:"小麦"}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除别名 "',v||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>g(w),children:"删除"})]})]})]})]},w)),d.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(T,{children:"其他平台账号"}),e.jsxs(_,{onClick:u,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[c.map((v,w)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(le,{value:v,onChange:b=>f(w,b.target.value),placeholder:"wx:114514"}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除平台账号 "',v||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>h(w),children:"删除"})]})]})]})]},w)),c.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无其他平台账号"})]})]})]})]})})}),Q2=Rs.memo(function({config:n,onChange:r}){const c=()=>{r({...n,states:[...n.states,""]})},d=h=>{r({...n,states:n.states.filter((f,p)=>p!==h)})},u=(h,f)=>{const p=[...n.states];p[h]=f,r({...n,states:p})};return e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"人格设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"personality",children:"人格特质"}),e.jsx(ot,{id:"personality",value:n.personality,onChange:h=>r({...n,personality:h.target.value}),placeholder:"描述人格特质和身份特征(建议120字以内)",rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"建议120字以内,描述人格特质和身份特征"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"多重人格"}),e.jsxs(_,{onClick:c,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加人格"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"可以定义多个不同的人格状态,麦麦会随机切换"}),e.jsx("div",{className:"space-y-2",children:n.states.map((h,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ot,{value:h,onChange:p=>u(f,p.target.value),placeholder:"描述一个人格状态",rows:2}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsx(fs,{children:"确定要删除这个人格状态吗?此操作无法撤销。"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>d(f),children:"删除"})]})]})]})]},f))})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"state_probability",children:"替换为多重人格概率"}),e.jsx(le,{id:"state_probability",type:"number",step:"0.1",min:"0",max:"1",value:n.state_probability,onChange:h=>r({...n,state_probability:parseFloat(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"每次构建人格时,用多重人格替换主人格的概率(0.0-1.0)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"reply_style",children:"表达风格"}),e.jsx(ot,{id:"reply_style",value:n.reply_style,onChange:h=>r({...n,reply_style:h.target.value}),placeholder:"描述说话的表达风格和习惯",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"plan_style",children:"说话规则与行为风格"}),e.jsx(ot,{id:"plan_style",value:n.plan_style,onChange:h=>r({...n,plan_style:h.target.value}),placeholder:"麦麦的说话规则和行为风格",rows:5})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"visual_style",children:"识图规则"}),e.jsx(ot,{id:"visual_style",value:n.visual_style,onChange:h=>r({...n,visual_style:h.target.value}),placeholder:"识图时的处理规则",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"private_plan_style",children:"私聊规则"}),e.jsx(ot,{id:"private_plan_style",value:n.private_plan_style,onChange:h=>r({...n,private_plan_style:h.target.value}),placeholder:"私聊的说话规则和行为风格",rows:4})]})]})]})})}),ul=bw,ml=yw,sl=m.forwardRef(({className:a,align:n="center",sideOffset:r=4,...c},d)=>e.jsx(Nw,{children:e.jsx(yj,{ref:d,align:n,sideOffset:r,className:F("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]",a),...c})}));sl.displayName=yj.displayName;const Y2=Rs.memo(function({value:n,onChange:r}){const c=m.useMemo(()=>{const b=n.split("-");if(b.length===2){const[y,A]=b,[z,S]=y.split(":"),[U,E]=A.split(":");return{startHour:z?z.padStart(2,"0"):"00",startMinute:S?S.padStart(2,"0"):"00",endHour:U?U.padStart(2,"0"):"23",endMinute:E?E.padStart(2,"0"):"59"}}return{startHour:"00",startMinute:"00",endHour:"23",endMinute:"59"}},[n]),[d,u]=m.useState(c.startHour),[h,f]=m.useState(c.startMinute),[p,g]=m.useState(c.endHour),[N,v]=m.useState(c.endMinute);m.useEffect(()=>{u(c.startHour),f(c.startMinute),g(c.endHour),v(c.endMinute)},[c]);const w=(b,y,A,z)=>{const S=`${b}:${y}-${A}:${z}`;r(S)};return e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",className:"w-full justify-start font-mono text-sm",children:[e.jsx(na,{className:"h-4 w-4 mr-2"}),n||"选择时间段"]})}),e.jsx(sl,{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(T,{className:"text-xs",children:"小时"}),e.jsxs(Ie,{value:d,onValueChange:b=>{u(b),w(b,h,p,N)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsx(Pe,{children:Array.from({length:24},(b,y)=>y).map(b=>e.jsx(W,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"分钟"}),e.jsxs(Ie,{value:h,onValueChange:b=>{f(b),w(d,b,p,N)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsx(Pe,{children:Array.from({length:60},(b,y)=>y).map(b=>e.jsx(W,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm mb-3",children:"结束时间"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:gap-3",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"小时"}),e.jsxs(Ie,{value:p,onValueChange:b=>{g(b),w(d,h,b,N)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsx(Pe,{children:Array.from({length:24},(b,y)=>y).map(b=>e.jsx(W,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"分钟"}),e.jsxs(Ie,{value:N,onValueChange:b=>{v(b),w(d,h,p,b)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsx(Pe,{children:Array.from({length:60},(b,y)=>y).map(b=>e.jsx(W,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]})]})]})]})})]})}),J2=Rs.memo(function({rule:n}){const r=`{ target = "${n.target}", time = "${n.time}", value = ${n.value.toFixed(1)} }`;return e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",children:[e.jsx(ia,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(sl,{className:"w-80 sm:w-96",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:r}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})}),X2=Rs.memo(function({config:n,onChange:r}){const c=()=>{r({...n,talk_value_rules:[...n.talk_value_rules,{target:"",time:"00:00-23:59",value:1}]})},d=h=>{r({...n,talk_value_rules:n.talk_value_rules.filter((f,p)=>p!==h)})},u=(h,f,p)=>{const g=[...n.talk_value_rules];g[h]={...g[h],[f]:p},r({...n,talk_value_rules:g})};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"聊天设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"talk_value",children:"聊天频率(基础值)"}),e.jsx(le,{id:"talk_value",type:"number",step:"0.1",min:"0",max:"1",value:n.talk_value,onChange:h=>r({...n,talk_value:parseFloat(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"越小越沉默,范围 0-1"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"think_mode",children:"思考模式"}),e.jsxs(Ie,{value:n.think_mode||"classic",onValueChange:h=>r({...n,think_mode:h}),children:[e.jsx(Be,{id:"think_mode",children:e.jsx(Fe,{placeholder:"选择思考模式"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"classic",children:"经典模式 - 浅度思考和回复"}),e.jsx(W,{value:"deep",children:"深度模式 - 进行深度思考和回复"}),e.jsx(W,{value:"dynamic",children:"动态模式 - 自动选择思考深度"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"控制麦麦的思考深度。经典模式回复快但简单;深度模式更深入但较慢;动态模式根据情况自动选择"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"mentioned_bot_reply",checked:n.mentioned_bot_reply,onCheckedChange:h=>r({...n,mentioned_bot_reply:h})}),e.jsx(T,{htmlFor:"mentioned_bot_reply",className:"cursor-pointer",children:"启用提及必回复"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"max_context_size",children:"上下文长度"}),e.jsx(le,{id:"max_context_size",type:"number",min:"1",value:n.max_context_size,onChange:h=>r({...n,max_context_size:parseInt(h.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"planner_smooth",children:"规划器平滑"}),e.jsx(le,{id:"planner_smooth",type:"number",step:"1",min:"0",value:n.planner_smooth,onChange:h=>r({...n,planner_smooth:parseFloat(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"增大数值会减小 planner 负荷,推荐 1-5,0 为关闭"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"plan_reply_log_max_per_chat",children:"每个聊天流最大日志数量"}),e.jsx(le,{id:"plan_reply_log_max_per_chat",type:"number",step:"1",min:"100",value:n.plan_reply_log_max_per_chat??1024,onChange:h=>r({...n,plan_reply_log_max_per_chat:parseInt(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"每个聊天流保存的 Plan/Reply 日志最大数量,超过此数量时会自动删除最老的日志"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"llm_quote",checked:n.llm_quote??!1,onCheckedChange:h=>r({...n,llm_quote:h})}),e.jsx(T,{htmlFor:"llm_quote",className:"cursor-pointer",children:"启用 LLM 控制引用"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2 ml-10",children:"启用后,LLM 可以决定是否在回复时引用消息"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"enable_talk_value_rules",checked:n.enable_talk_value_rules,onCheckedChange:h=>r({...n,enable_talk_value_rules:h})}),e.jsx(T,{htmlFor:"enable_talk_value_rules",className:"cursor-pointer",children:"启用动态发言频率规则"})]})]})]}),n.enable_talk_value_rules&&e.jsxs("div",{className:"border-t pt-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-semibold",children:"动态发言频率规则"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"按时段或聊天流ID调整发言频率,优先匹配具体聊天,再匹配全局规则"})]}),e.jsxs(_,{onClick:c,size:"sm",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),n.talk_value_rules&&n.talk_value_rules.length>0?e.jsx("div",{className:"space-y-4",children:n.talk_value_rules.map((h,f)=>e.jsxs("div",{className:"rounded-lg border p-4 bg-muted/50 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:["规则 #",f+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J2,{rule:h}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{variant:"ghost",size:"sm",children:e.jsx(ns,{className:"h-4 w-4 text-destructive"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除规则 #",f+1," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>d(f),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(Ie,{value:h.target===""?"global":"specific",onValueChange:p=>{p==="global"?u(f,"target",""):u(f,"target","qq::group")},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"global",children:"全局配置"}),e.jsx(W,{value:"specific",children:"详细配置"})]})]})]}),h.target!==""&&(()=>{const p=h.target.split(":"),g=p[0]||"qq",N=p[1]||"",v=p[2]||"group";return e.jsxs("div",{className:"grid gap-4 p-3 sm:p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Ie,{value:g,onValueChange:w=>{u(f,"target",`${w}:${N}:${v}`)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"qq",children:"QQ"}),e.jsx(W,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(le,{value:N,onChange:w=>{u(f,"target",`${g}:${w.target.value}:${v}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Ie,{value:v,onValueChange:w=>{u(f,"target",`${g}:${N}:${w}`)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"group",children:"群组(group)"}),e.jsx(W,{value:"private",children:"私聊(private)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前聊天流 ID:",h.target||"(未设置)"]})]})})(),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"时间段 (Time)"}),e.jsx(Y2,{value:h.time,onChange:p=>u(f,"time",p)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"支持跨夜区间,例如 23:00-02:00"})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{htmlFor:`rule-value-${f}`,className:"text-xs font-medium",children:"发言频率值 (Value)"}),e.jsx(le,{id:`rule-value-${f}`,type:"number",step:"0.01",min:"0.01",max:"1",value:h.value,onChange:p=>{const g=parseFloat(p.target.value);isNaN(g)||u(f,"value",Math.max(.01,Math.min(1,g)))},className:"w-20 h-8 text-xs"})]}),e.jsx(Qa,{value:[h.value],onValueChange:p=>u(f,"value",p[0]),min:.01,max:1,step:.01,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"0.01 (极少发言)"}),e.jsx("span",{children:"0.5"}),e.jsx("span",{children:"1.0 (正常)"})]})]})]})]},f))}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:e.jsx("p",{className:"text-sm",children:'暂无规则,点击"添加规则"按钮创建'})}),e.jsxs("div",{className:"mt-4 p-4 bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800 rounded-lg",children:[e.jsx("h5",{className:"text-sm font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"📝 规则说明"}),e.jsxs("ul",{className:"text-xs text-blue-800 dark:text-blue-200 space-y-1",children:[e.jsxs("li",{children:["• ",e.jsx("strong",{children:"Target 为空"}),":全局规则,对所有聊天生效"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"Target 指定"}),":仅对特定聊天流生效(格式:platform:id:type)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"优先级"}),":先匹配具体聊天流规则,再匹配全局规则"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"时间支持跨夜"}),":例如 23:00-02:00 表示晚上11点到次日凌晨2点"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"数值范围"}),":建议 0-1,0 表示完全沉默,1 表示正常发言"]})]})]})]})]})}),Z2=Rs.memo(function({config:n,onChange:r}){const c=S=>{if(!S||!S.includes(":"))return{platform:"qq",userId:""};const[U,E]=S.split(":");return{platform:U,userId:E}},{platform:d,userId:u}=c(n.dream_send),[h,f]=m.useState(d),[p,g]=m.useState(u),N=S=>{const[U,E]=S.split("-");return{startTime:U||"09:00",endTime:E||"22:00"}},v=(S,U)=>{const E=U?`${S}:${U}`:"";r({...n,dream_send:E})},w=S=>{f(S),v(S,p)},b=S=>{g(S),v(h,S)},y=()=>{r({...n,dream_time_ranges:[...n.dream_time_ranges,"09:00-22:00"]})},A=S=>{r({...n,dream_time_ranges:n.dream_time_ranges.filter((U,E)=>E!==S)})},z=(S,U,E)=>{const C=[...n.dream_time_ranges],D=N(C[S]);U==="startTime"?D.startTime=E:D.endTime=E,C[S]=`${D.startTime}-${D.endTime}`,r({...n,dream_time_ranges:C})};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"做梦配置"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"interval_minutes",children:"做梦时间间隔(分钟)"}),e.jsx(le,{id:"interval_minutes",type:"number",min:"1",value:n.interval_minutes,onChange:S=>r({...n,interval_minutes:Number(S.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"默认30分钟"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"max_iterations",children:"做梦最大轮次"}),e.jsx(le,{id:"max_iterations",type:"number",min:"1",value:n.max_iterations,onChange:S=>r({...n,max_iterations:Number(S.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"默认20轮"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"first_delay_seconds",children:"首次做梦延迟(秒)"}),e.jsx(le,{id:"first_delay_seconds",type:"number",min:"0",value:n.first_delay_seconds,onChange:S=>r({...n,first_delay_seconds:Number(S.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"程序启动后首次做梦前的延迟时间,默认60秒"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"做梦结果推送目标"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Ie,{value:h,onValueChange:w,children:[e.jsx(Be,{className:"w-[120px]",children:e.jsx(Fe,{placeholder:"选择平台"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"qq",children:"QQ"}),e.jsx(W,{value:"wx",children:"微信"}),e.jsx(W,{value:"webui",children:"WebUI"})]})]}),e.jsx(le,{type:"text",placeholder:"输入用户ID (例如: 123456)",value:p,onChange:S=>b(S.target.value),className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"选择平台并输入用户ID,做梦结束后将梦境发送给该用户。用户ID为空则不推送"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"做梦时间段配置"}),e.jsx(_,{type:"button",size:"sm",onClick:y,children:"添加时间段"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"设置允许做梦的时间段,支持跨夜区间(如 23:00 到次日 02:00)。列表为空则全天允许做梦"}),e.jsxs("div",{className:"space-y-2",children:[n.dream_time_ranges.map((S,U)=>{const{startTime:E,endTime:C}=N(S);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{type:"time",value:E,onChange:D=>z(U,"startTime",D.target.value),className:"w-[140px]"}),e.jsx("span",{className:"text-muted-foreground",children:"至"}),e.jsx(le,{type:"time",value:C,onChange:D=>z(U,"endTime",D.target.value),className:"w-[140px]"}),e.jsx(_,{type:"button",variant:"ghost",size:"icon",onClick:()=>A(U),children:e.jsx(Aa,{className:"h-4 w-4"})})]},U)}),n.dream_time_ranges.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"当前配置为全天允许做梦"})]})]})]})}),W2=Rs.memo(function({config:n,onChange:r}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.enable,onCheckedChange:c=>r({...n,enable:c})}),e.jsx(T,{className:"cursor-pointer",children:"启用 LPMM 知识库"})]}),n.enable&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"LPMM 模式"}),e.jsxs(Ie,{value:n.lpmm_mode,onValueChange:c=>r({...n,lpmm_mode:c}),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择 LPMM 模式"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"classic",children:"经典模式"}),e.jsx(W,{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(T,{children:"同义词搜索 TopK"}),e.jsx(le,{type:"number",min:"1",value:n.rag_synonym_search_top_k,onChange:c=>r({...n,rag_synonym_search_top_k:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"同义词阈值"}),e.jsx(le,{type:"number",step:"0.1",min:"0",max:"1",value:n.rag_synonym_threshold,onChange:c=>r({...n,rag_synonym_threshold:parseFloat(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"实体提取线程数"}),e.jsx(le,{type:"number",min:"1",value:n.info_extraction_workers,onChange:c=>r({...n,info_extraction_workers:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"嵌入向量维度"}),e.jsx(le,{type:"number",min:"1",value:n.embedding_dimension,onChange:c=>r({...n,embedding_dimension:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"嵌入并发线程数"}),e.jsx(le,{type:"number",min:"1",value:n.max_embedding_workers,onChange:c=>r({...n,max_embedding_workers:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"每批嵌入条数"}),e.jsx(le,{type:"number",min:"1",value:n.embedding_chunk_size,onChange:c=>r({...n,embedding_chunk_size:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"同义实体数上限"}),e.jsx(le,{type:"number",min:"1",value:n.max_synonym_entities,onChange:c=>r({...n,max_synonym_entities:parseInt(c.target.value)})})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.enable_ppr,onCheckedChange:c=>r({...n,enable_ppr:c})}),e.jsx(T,{className:"cursor-pointer",children:"启用 PPR (低配机器可关闭)"})]})]})]})]})}),eS=Rs.memo(function({config:n,onChange:r}){const[c,d]=m.useState(""),[u,h]=m.useState("WARNING"),f=()=>{c&&!n.suppress_libraries.includes(c)&&(r({...n,suppress_libraries:[...n.suppress_libraries,c]}),d(""))},p=y=>{r({...n,suppress_libraries:n.suppress_libraries.filter(A=>A!==y)})},g=()=>{c&&!n.library_log_levels[c]&&(r({...n,library_log_levels:{...n.library_log_levels,[c]:u}}),d(""),h("WARNING"))},N=y=>{const A={...n.library_log_levels};delete A[y],r({...n,library_log_levels:A})},v=["DEBUG","INFO","WARNING","ERROR","CRITICAL"],w=["FULL","compact","lite"],b=["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(T,{children:"日期格式"}),e.jsx(le,{value:n.date_style,onChange:y=>r({...n,date_style:y.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(T,{children:"日志级别样式"}),e.jsxs(Ie,{value:n.log_level_style,onValueChange:y=>r({...n,log_level_style:y}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsx(Pe,{children:w.map(y=>e.jsx(W,{value:y,children:y},y))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"日志文本颜色"}),e.jsxs(Ie,{value:n.color_text,onValueChange:y=>r({...n,color_text:y}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsx(Pe,{children:b.map(y=>e.jsx(W,{value:y,children:y},y))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"全局日志级别"}),e.jsxs(Ie,{value:n.log_level,onValueChange:y=>r({...n,log_level:y}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsx(Pe,{children:v.map(y=>e.jsx(W,{value:y,children:y},y))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"控制台日志级别"}),e.jsxs(Ie,{value:n.console_log_level,onValueChange:y=>r({...n,console_log_level:y}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsx(Pe,{children:v.map(y=>e.jsx(W,{value:y,children:y},y))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"文件日志级别"}),e.jsxs(Ie,{value:n.file_log_level,onValueChange:y=>r({...n,file_log_level:y}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsx(Pe,{children:v.map(y=>e.jsx(W,{value:y,children:y},y))})]})]})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"mb-2 block",children:"完全屏蔽的库"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(le,{value:c,onChange:y=>d(y.target.value),placeholder:"输入库名",className:"flex-1",onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),f())}}),e.jsx(_,{onClick:f,size:"sm",className:"flex-shrink-0",children:e.jsx(et,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:n.suppress_libraries.map(y=>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:y}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0",onClick:()=>p(y),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},y))})]}),e.jsxs("div",{children:[e.jsx(T,{className:"mb-2 block",children:"特定库的日志级别"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(le,{value:c,onChange:y=>d(y.target.value),placeholder:"输入库名",className:"flex-1"}),e.jsxs(Ie,{value:u,onValueChange:h,children:[e.jsx(Be,{className:"w-32",children:e.jsx(Fe,{})}),e.jsx(Pe,{children:v.map(y=>e.jsx(W,{value:y,children:y},y))})]}),e.jsx(_,{onClick:g,size:"sm",children:e.jsx(et,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:Object.entries(n.library_log_levels).map(([y,A])=>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:y}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:A}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>N(y),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]})]},y))})]})]})}),sS=Rs.memo(function({config:n,onChange:r}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"调试配置"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否在日志中显示提示词"})]}),e.jsx(Ve,{checked:n.show_prompt,onCheckedChange:c=>r({...n,show_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示回复器 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的提示词"})]}),e.jsx(Ve,{checked:n.show_replyer_prompt,onCheckedChange:c=>r({...n,show_replyer_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示回复器推理"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的推理过程"})]}),e.jsx(Ve,{checked:n.show_replyer_reasoning,onCheckedChange:c=>r({...n,show_replyer_reasoning:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示 Jargon Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示术语相关的提示词"})]}),e.jsx(Ve,{checked:n.show_jargon_prompt,onCheckedChange:c=>r({...n,show_jargon_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示记忆检索 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示记忆检索相关的提示词"})]}),e.jsx(Ve,{checked:n.show_memory_prompt,onCheckedChange:c=>r({...n,show_memory_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示 Planner Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 Planner 的提示词和原始返回结果"})]}),e.jsx(Ve,{checked:n.show_planner_prompt,onCheckedChange:c=>r({...n,show_planner_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示 LPMM 相关文段"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 LPMM 知识库找到的相关文段日志"})]}),e.jsx(Ve,{checked:n.show_lpmm_paragraph,onCheckedChange:c=>r({...n,show_lpmm_paragraph:c})})]})]})]})}),tS=Rs.memo(function({config:n,onChange:r}){const[c,d]=m.useState(""),[u,h]=m.useState(""),f=()=>{c&&!n.auth_token.includes(c)&&(r({...n,auth_token:[...n.auth_token,c]}),d(""))},p=v=>{r({...n,auth_token:n.auth_token.filter((w,b)=>b!==v)})},g=()=>{u&&!n.api_server_allowed_api_keys.includes(u)&&(r({...n,api_server_allowed_api_keys:[...n.api_server_allowed_api_keys,u]}),h(""))},N=v=>{r({...n,api_server_allowed_api_keys:n.api_server_allowed_api_keys.filter((w,b)=>b!==v)})};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"旧版 API 认证令牌"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"用于旧版 API 验证,为空则不启用验证"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(le,{value:c,onChange:v=>d(v.target.value),placeholder:"输入认证令牌",onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),f())}}),e.jsx(_,{onClick:f,size:"sm",children:e.jsx(et,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:n.auth_token.map((v,w)=>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:v}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>p(w),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},w))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"新版 API Server 配置"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"启用新版 API Server"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否启用额外的新版 API Server(额外监听端口)"})]}),e.jsx(Ve,{checked:n.enable_api_server,onCheckedChange:v=>r({...n,enable_api_server:v})})]}),n.enable_api_server&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"主机地址"}),e.jsx(le,{value:n.api_server_host,onChange:v=>r({...n,api_server_host:v.target.value}),placeholder:"0.0.0.0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"端口号"}),e.jsx(le,{type:"number",value:n.api_server_port,onChange:v=>r({...n,api_server_port:parseInt(v.target.value)}),placeholder:"8090"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.api_server_use_wss,onCheckedChange:v=>r({...n,api_server_use_wss:v})}),e.jsx(T,{children:"启用 WSS 安全连接"})]}),n.api_server_use_wss&&e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"SSL 证书文件路径"}),e.jsx(le,{value:n.api_server_cert_file,onChange:v=>r({...n,api_server_cert_file:v.target.value}),placeholder:"cert.pem"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"SSL 密钥文件路径"}),e.jsx(le,{value:n.api_server_key_file,onChange:v=>r({...n,api_server_key_file:v.target.value}),placeholder:"key.pem"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"mb-2 block",children:"允许的 API Key 列表"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"为空则允许所有连接"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(le,{value:u,onChange:v=>h(v.target.value),placeholder:"输入 API Key",onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),g())}}),e.jsx(_,{onClick:g,size:"sm",children:e.jsx(et,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:n.api_server_allowed_api_keys.map((v,w)=>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:v}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>N(w),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},w))})]})]})]})]})]})}),aS=Rs.memo(function({config:n,onChange:r}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"统计信息"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"启用统计信息发送"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"发送匿名统计信息,帮助我们了解全球有多少只麦麦在运行"})]}),e.jsx(Ve,{checked:n.enable,onCheckedChange:c=>r({...n,enable:c})})]})]})}),lS=Rs.memo(function({emojiConfig:n,memoryConfig:r,toolConfig:c,voiceConfig:d,onEmojiChange:u,onMemoryChange:h,onToolChange:f,onVoiceChange:p}){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:"space-y-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"enable_tool",checked:c.enable_tool,onCheckedChange:g=>f({...c,enable_tool:g})}),e.jsx(T,{htmlFor:"enable_tool",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 pt-2",children:[e.jsx(Ve,{id:"enable_asr",checked:d.enable_asr,onCheckedChange:g=>p({...d,enable_asr:g})}),e.jsx(T,{htmlFor:"enable_asr",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(T,{htmlFor:"max_agent_iterations",children:"记忆思考深度"}),e.jsx(le,{id:"max_agent_iterations",type:"number",min:"1",value:r.max_agent_iterations,onChange:g=>h({...r,max_agent_iterations:parseInt(g.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"最低为 1(不深入思考)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"agent_timeout_seconds",children:"最长回忆时间(秒)"}),e.jsx(le,{id:"agent_timeout_seconds",type:"number",min:"1",step:"0.1",value:r.agent_timeout_seconds??120,onChange:g=>h({...r,agent_timeout_seconds:parseFloat(g.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(Ve,{id:"enable_jargon_detection",checked:r.enable_jargon_detection??!0,onCheckedChange:g=>h({...r,enable_jargon_detection:g})}),e.jsx(T,{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(Ve,{id:"global_memory",checked:r.global_memory??!1,onCheckedChange:g=>h({...r,global_memory:g})}),e.jsx(T,{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(T,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsx(le,{id:"emoji_chance",type:"number",step:"0.1",min:"0",max:"1",value:n.emoji_chance,onChange:g=>u({...n,emoji_chance:parseFloat(g.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"范围 0-1,越大越容易发送表情包"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"max_reg_num",children:"最大注册数量"}),e.jsx(le,{id:"max_reg_num",type:"number",min:"1",value:n.max_reg_num,onChange:g=>u({...n,max_reg_num:parseInt(g.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦最多可以注册的表情包数量"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(le,{id:"check_interval",type:"number",min:"1",value:n.check_interval,onChange:g=>u({...n,check_interval:parseInt(g.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(Ve,{id:"do_replace",checked:n.do_replace,onCheckedChange:g=>u({...n,do_replace:g})}),e.jsx(T,{htmlFor:"do_replace",className:"cursor-pointer",children:"达到最大数量时替换表情包"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"steal_emoji",checked:n.steal_emoji,onCheckedChange:g=>u({...n,steal_emoji:g})}),e.jsx(T,{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(Ve,{id:"content_filtration",checked:n.content_filtration,onCheckedChange:g=>u({...n,content_filtration:g})}),e.jsx(T,{htmlFor:"content_filtration",className:"cursor-pointer",children:"启用表情包过滤"})]}),n.content_filtration&&e.jsxs("div",{className:"grid gap-2 pl-6 border-l-2 border-primary/20",children:[e.jsx(T,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(le,{id:"filtration_prompt",value:n.filtration_prompt,onChange:g=>u({...n,filtration_prompt:g.target.value}),placeholder:"符合公序良俗"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只有符合此要求的表情包才会被保存"})]})]})]})})]})}),nS=Rs.memo(function({member:n,groupIndex:r,memberIndex:c,availableChatIds:d,onUpdate:u,onRemove:h}){const f=d.includes(n)||n==="*",[p,g]=m.useState(!f);return e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 flex gap-2",children:p?e.jsxs(e.Fragment,{children:[e.jsx(le,{value:n,onChange:N=>u(r,c,N.target.value),placeholder:'输入 "*" 或 "qq:123456:group"',className:"flex-1"}),d.length>0&&e.jsx(_,{size:"sm",variant:"outline",onClick:()=>g(!1),title:"切换到下拉选择",children:"下拉"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Ie,{value:n,onValueChange:N=>u(r,c,N),children:[e.jsx(Be,{className:"flex-1",children:e.jsx(Fe,{placeholder:"选择聊天流"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"*",children:"* (全局共享)"}),d.map((N,v)=>e.jsx(W,{value:N,children:N},v))]})]}),e.jsx(_,{size:"sm",variant:"outline",onClick:()=>g(!0),title:"切换到手动输入",children:"输入"})]})}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除组成员 "',n||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>h(r,c),children:"删除"})]})]})]})]})}),rS=Rs.memo(function({config:n,onChange:r}){const c=()=>{r({...n,learning_list:[...n.learning_list,["","enable","enable","1.0"]]})},d=w=>{r({...n,learning_list:n.learning_list.filter((b,y)=>y!==w)})},u=(w,b,y)=>{const A=[...n.learning_list];A[w][b]=y,r({...n,learning_list:A})},h=({rule:w})=>{const b=`["${w[0]}", "${w[1]}", "${w[2]}", "${w[3]}"]`;return e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",children:[e.jsx(ia,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(sl,{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:b}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},f=()=>{r({...n,expression_groups:[...n.expression_groups,[]]})},p=w=>{r({...n,expression_groups:n.expression_groups.filter((b,y)=>y!==w)})},g=w=>{const b=[...n.expression_groups];b[w]=[...b[w],""],r({...n,expression_groups:b})},N=(w,b)=>{const y=[...n.expression_groups];y[w]=y[w].filter((A,z)=>z!==b),r({...n,expression_groups:y})},v=(w,b,y)=>{const A=[...n.expression_groups];A[w][b]=y,r({...n,expression_groups:A})};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-4",children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"黑话设置"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"all_global_jargon",checked:n.all_global_jargon??!1,onCheckedChange:w=>r({...n,all_global_jargon:w})}),e.jsx(T,{htmlFor:"all_global_jargon",className:"cursor-pointer",children:"全局黑话模式"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"开启后,新增的黑话将默认设为全局(所有聊天流共享)。关闭后,已记录的全局黑话不会改变,需要手动删除。"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"enable_jargon_explanation",checked:n.enable_jargon_explanation??!0,onCheckedChange:w=>r({...n,enable_jargon_explanation:w})}),e.jsx(T,{htmlFor:"enable_jargon_explanation",className:"cursor-pointer",children:"启用黑话解释"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"在回复前尝试对上下文中的黑话进行解释。关闭可减少一次LLM调用,仅影响回复前的黑话匹配与解释,不影响黑话学习。"})]}),e.jsxs("div",{children:[e.jsx(T,{htmlFor:"jargon_mode",children:"黑话解释来源模式"}),e.jsxs(Ie,{value:n.jargon_mode??"context",onValueChange:w=>r({...n,jargon_mode:w}),children:[e.jsx(Be,{id:"jargon_mode",className:"mt-2",children:e.jsx(Fe,{placeholder:"选择黑话解释来源"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"context",children:"上下文模式(自动匹配黑话)"}),e.jsx(W,{value:"planner",children:"Planner模式(使用unknown_words列表)"})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["上下文模式:使用上下文自动匹配黑话并解释",e.jsx("br",{}),"Planner模式:仅使用Planner在reply动作中给出的unknown_words列表进行黑话检索"]})]})]}),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(_,{onClick:c,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),e.jsxs("div",{className:"space-y-4",children:[n.learning_list.map((w,b)=>{const y=n.learning_list.some((C,D)=>D!==b&&C[0]===""),A=w[0]==="",z=w[0].split(":"),S=z[0]||"qq",U=z[1]||"",E=z[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:["规则 ",b+1," ",A&&"(全局配置)"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{rule:w}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除学习规则 ",b+1," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>d(b),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(Ie,{value:A?"global":"specific",onValueChange:C=>{C==="global"?u(b,0,""):u(b,0,"qq::group")},disabled:y&&!A,children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"global",children:"全局配置"}),e.jsx(W,{value:"specific",disabled:y&&!A,children:"详细配置"})]})]}),y&&!A&&e.jsx("p",{className:"text-xs text-amber-600",children:"已存在全局配置,无法创建新的全局配置"})]}),!A&&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(T,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Ie,{value:S,onValueChange:C=>{u(b,0,`${C}:${U}:${E}`)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"qq",children:"QQ"}),e.jsx(W,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(le,{value:U,onChange:C=>{u(b,0,`${S}:${C.target.value}:${E}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Ie,{value:E,onValueChange:C=>{u(b,0,`${S}:${U}:${C}`)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"group",children:"群组(group)"}),e.jsx(W,{value:"private",children:"私聊(private)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前聊天流 ID:",w[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(T,{className:"text-xs font-medium",children:"使用学到的表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦使用从聊天中学到的表达方式"})]}),e.jsx(Ve,{checked:w[1]==="enable",onCheckedChange:C=>u(b,1,C?"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(T,{className:"text-xs font-medium",children:"学习表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦从聊天中学习新的表达方式"})]}),e.jsx(Ve,{checked:w[2]==="enable",onCheckedChange:C=>u(b,2,C?"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(T,{className:"text-xs font-medium",children:"启用黑话学习"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦在此聊天流中学习和记录黑话"})]}),e.jsx(Ve,{checked:w[3]==="true"||w[3]==="enable",onCheckedChange:C=>u(b,3,C?"true":"false")})]})})]})]},b)}),n.learning_list.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无学习规则,点击"添加规则"开始配置'})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{className:"space-y-6",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("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"expression_self_reflect",className:"cursor-pointer font-medium",children:"自动表达优化"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后,麦麦会自动检查并优化表达方式,无需管理员手动干预"})]}),e.jsx(Ve,{id:"expression_self_reflect",checked:n.expression_self_reflect??!1,onCheckedChange:w=>r({...n,expression_self_reflect:w})})]}),n.expression_self_reflect&&e.jsxs("div",{className:"space-y-4 pl-4 border-l-2 border-primary/20",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"expression_auto_check_interval",children:"自动检查间隔(秒)"}),e.jsx(le,{id:"expression_auto_check_interval",type:"number",min:"60",value:n.expression_auto_check_interval??3600,onChange:w=>r({...n,expression_auto_check_interval:parseInt(w.target.value)||3600})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"表达方式自动检查的间隔时间(单位:秒),默认值:3600秒(1小时)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"expression_auto_check_count",children:"每次检查数量"}),e.jsx(le,{id:"expression_auto_check_count",type:"number",min:"1",max:"100",value:n.expression_auto_check_count??10,onChange:w=>r({...n,expression_auto_check_count:parseInt(w.target.value)||10})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"每次自动检查时随机选取的表达方式数量,默认值:10条"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"自定义评估标准"}),e.jsxs(_,{onClick:()=>{r({...n,expression_auto_check_custom_criteria:[...n.expression_auto_check_custom_criteria||[],""]})},size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加标准"]})]}),e.jsxs("div",{className:"space-y-2",children:[(n.expression_auto_check_custom_criteria||[]).map((w,b)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(le,{value:w,onChange:y=>{const A=[...n.expression_auto_check_custom_criteria||[]];A[b]=y.target.value,r({...n,expression_auto_check_custom_criteria:A})},placeholder:"输入评估标准,例如:是否符合角色人设",className:"flex-1"}),e.jsx(_,{onClick:()=>{r({...n,expression_auto_check_custom_criteria:(n.expression_auto_check_custom_criteria||[]).filter((y,A)=>A!==b)})},size:"icon",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})]},b)),(!n.expression_auto_check_custom_criteria||n.expression_auto_check_custom_criteria.length===0)&&e.jsx("div",{className:"text-center py-4 text-muted-foreground text-sm",children:'暂无自定义标准,点击"添加标准"开始配置'})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这些标准会被添加到评估提示词中,作为额外的评估要求"})]})]})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"expression_checked_only",className:"cursor-pointer font-medium",children:"仅使用已审核通过的表达方式"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"开启后,只有通过审核(已检查)的项目会被使用;关闭时,未审核的项目也会被使用。无论开关状态,被拒绝的项目永远不会被使用。"})]}),e.jsx(Ve,{id:"expression_checked_only",checked:n.expression_checked_only??!1,onCheckedChange:w=>r({...n,expression_checked_only:w})})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"expression_manual_reflect",className:"cursor-pointer font-medium",children:"手动表达优化"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后,麦麦会主动向管理员询问表达方式是否合适"})]}),e.jsx(Ve,{id:"expression_manual_reflect",checked:n.expression_manual_reflect??!1,onCheckedChange:w=>r({...n,expression_manual_reflect:w})})]}),n.expression_manual_reflect&&e.jsxs("div",{className:"space-y-4 pl-4 border-l-2 border-primary/20",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 b=(n.manual_reflect_operator_id||"").split(":"),y=b[0]||"qq",A=b[1]||"",z=b[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(T,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Ie,{value:y,onValueChange:S=>{r({...n,manual_reflect_operator_id:`${S}:${A}:${z}`})},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"qq",children:"QQ"}),e.jsx(W,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"用户/群 ID"}),e.jsx(le,{value:A,onChange:S=>{r({...n,manual_reflect_operator_id:`${y}:${S.target.value}:${z}`})},placeholder:"输入 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Ie,{value:z,onValueChange:S=>{r({...n,manual_reflect_operator_id:`${y}:${A}:${S}`})},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"private",children:"私聊(private)"}),e.jsx(W,{value:"group",children:"群组(group)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前操作员 ID:",n.manual_reflect_operator_id||"(未设置)"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'手动表达优化操作员ID,格式:platform:id:type (例如 "qq:123456:private" 或 "qq:654321:group")'})]})})()})]}),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(_,{onClick:()=>{r({...n,allow_reflect:[...n.allow_reflect||[],"qq::group"]})},size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加聊天流"]})]}),e.jsxs("div",{className:"space-y-2",children:[(n.allow_reflect||[]).map((w,b)=>{const y=w.split(":"),A=y[0]||"qq",z=y[1]||"",S=y[2]||"group";return e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-muted/50",children:[e.jsxs(Ie,{value:A,onValueChange:U=>{const E=[...n.allow_reflect];E[b]=`${U}:${z}:${S}`,r({...n,allow_reflect:E})},children:[e.jsx(Be,{className:"w-24",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"qq",children:"QQ"}),e.jsx(W,{value:"wx",children:"微信"})]})]}),e.jsx(le,{value:z,onChange:U=>{const E=[...n.allow_reflect];E[b]=`${A}:${U.target.value}:${S}`,r({...n,allow_reflect:E})},placeholder:"ID",className:"flex-1 font-mono text-sm"}),e.jsxs(Ie,{value:S,onValueChange:U=>{const E=[...n.allow_reflect];E[b]=`${A}:${z}:${U}`,r({...n,allow_reflect:E})},children:[e.jsx(Be,{className:"w-32",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"group",children:"群组"}),e.jsx(W,{value:"private",children:"私聊"})]})]}),e.jsx(_,{onClick:()=>{r({...n,allow_reflect:n.allow_reflect.filter((U,E)=>E!==b)})},size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})]},b)}),(!n.allow_reflect||n.allow_reflect.length===0)&&e.jsx("div",{className:"text-center py-4 text-muted-foreground text-sm",children:"列表为空,所有聊天流都可以进行表达反思"})]})]})]})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"表达共享组配置"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"配置不同聊天流之间如何共享学到的表达方式"})]}),e.jsxs(_,{onClick:f,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加共享组"]})]}),e.jsxs("div",{className:"space-y-4",children:[n.expression_groups.map((w,b)=>{const y=n.learning_list.map(A=>A[0]).filter(A=>A!=="");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:["共享组 ",b+1,w.length===1&&w[0]==="*"&&"(全局共享)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_,{onClick:()=>g(b),size:"sm",variant:"outline",children:e.jsx(et,{className:"h-4 w-4"})}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除共享组 ",b+1," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>p(b),children:"删除"})]})]})]})]})]}),e.jsx("div",{className:"space-y-2",children:w.map((A,z)=>e.jsx(nS,{member:A,groupIndex:b,memberIndex:z,availableChatIds:y,onUpdate:v,onRemove:N},`${b}-${z}`))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'提示:可以从下拉框选择已配置的聊天流,或手动输入。输入 "*" 启用全局共享'})]},b)}),n.expression_groups.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无共享组,点击"添加共享组"开始配置'})]})]})})]})});function iS({regex:a,reaction:n,onRegexChange:r,onReactionChange:c}){const[d,u]=m.useState(!1),[h,f]=m.useState(""),[p,g]=m.useState(null),[N,v]=m.useState(""),[w,b]=m.useState({}),[y,A]=m.useState(""),z=m.useRef(null),[S,U]=m.useState("build"),E=O=>O.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),C=(O,X=0)=>{const L=z.current;if(!L)return;const oe=L.selectionStart||0,Ne=L.selectionEnd||0,je=a.substring(0,oe)+O+a.substring(Ne);r(je),setTimeout(()=>{const de=oe+O.length+X;L.setSelectionRange(de,de),L.focus()},0)};m.useEffect(()=>{if(!a||!h){p!==null&&g(null),Object.keys(w).length>0&&b({}),y!==n&&A(n),N!==""&&v("");return}try{const O=E(a),X=new RegExp(O,"g"),L=h.match(X);g(L),v("");const Ne=new RegExp(O).exec(h);if(Ne&&Ne.groups){b(Ne.groups);let je=n;Object.entries(Ne.groups).forEach(([de,he])=>{je=je.replace(new RegExp(`\\[${de}\\]`,"g"),he||"")}),A(je)}else b({}),A(n)}catch(O){v(O.message),g(null),b({}),A(n)}},[a,h,n,p,w,y,N]);const D=()=>{if(!h||!p||p.length===0)return e.jsx("span",{className:"text-muted-foreground",children:h||"请输入测试文本"});try{const O=E(a),X=new RegExp(O,"g");let L=0;const oe=[];let Ne;for(;(Ne=X.exec(h))!==null;)Ne.index>L&&oe.push(e.jsx("span",{children:h.substring(L,Ne.index)},`text-${L}`)),oe.push(e.jsx("span",{className:"bg-yellow-200 dark:bg-yellow-900 font-semibold",children:Ne[0]},`match-${Ne.index}`)),L=Ne.index+Ne[0].length;return L)",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(Ps,{open:d,onOpenChange:u,children:[e.jsx(cd,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",children:[e.jsx(nx,{className:"h-4 w-4 mr-1"}),"正则编辑器"]})}),e.jsxs(Ds,{className:"max-w-[95vw] sm:max-w-[900px] max-h-[90vh]",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"正则表达式编辑器"}),e.jsx(Ks,{className:"text-sm",children:"使用可视化工具构建正则表达式,并实时测试效果"})]}),e.jsx(Je,{className:"max-h-[calc(90vh-120px)]",children:e.jsxs(ta,{value:S,onValueChange:O=>U(O),className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2",children:[e.jsx(Xe,{value:"build",children:"🔧 构建器"}),e.jsx(Xe,{value:"test",children:"🧪 测试器"})]}),e.jsxs(ws,{value:"build",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"正则表达式"}),e.jsx(le,{ref:z,value:a,onChange:O=>r(O.target.value),className:"font-mono text-sm",placeholder:"点击下方按钮构建正则表达式..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"Reaction 内容"}),e.jsx(ot,{value:n,onChange:O=>c(O.target.value),placeholder:"使用 [捕获组名] 引用捕获的内容...",rows:3,className:"text-sm"})]}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[I.map(O=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-xs font-semibold text-primary",children:O.category}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:O.items.map(X=>e.jsx(_,{variant:"outline",size:"sm",className:"justify-start h-auto py-2 px-3",onClick:()=>C(X.pattern,X.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:X.label}),e.jsx("code",{className:"ml-auto text-xs bg-muted px-1.5 py-0.5 rounded font-mono",children:X.pattern})]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-0.5",children:X.desc})]})},X.label))})]},O.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(_,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>r("^(?P\\S{1,20})是这样的$"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsxs("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:["^(?P\\S","{1,20}",")是这样的$"]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"匹配「某事物是这样的」并捕获事物名称"})]})}),e.jsx(_,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>r("(?:[^,。.\\s]+,\\s*)?我(?:也)?[没沒]要求你\\s*(?P.+?)[.。,,]?$"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsx("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:"(?:[^,。.\\s]+,\\s*)?我(?:也)?[没沒]要求你\\s*(?P.+?)[.。,,]?$"}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"匹配「我没要求你做某事」并捕获具体行为"})]})}),e.jsx(_,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>r("(?P.+?)(?:是|为什么|怎么)"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsx("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:"(?P.+?)(?:是|为什么|怎么)"}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"捕获问题主题词"})]})})]})]})]}),e.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3 space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-blue-900 dark:text-blue-100",children:"💡 使用提示"}),e.jsxs("ul",{className:"text-xs text-blue-700 dark:text-blue-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"点击输入框设置光标位置,然后点击按钮插入模式"}),e.jsxs("li",{children:["命名捕获组格式:",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"(?P<名称>模式)"})]}),e.jsxs("li",{children:["在 reaction 中使用 ",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"[名称]"})," 引用捕获的内容"]}),e.jsx("li",{children:"切换到测试器标签页验证正则表达式效果"})]})]})]}),e.jsxs(ws,{value:"test",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"当前正则表达式"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:a||"(未设置)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"test-text",className:"text-sm font-medium",children:"测试文本"}),e.jsx(ot,{id:"test-text",value:h,onChange:O=>f(O.target.value),placeholder:`在此输入要测试的文本... +例如:打游戏是这样的`,className:"min-h-[100px] text-sm"})]}),N&&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:N})]}),!N&&h&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:p&&p.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-green-500"}),e.jsxs("span",{className:"text-sm font-medium text-green-600 dark:text-green-400",children:["匹配成功 (",p.length," 处)"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-gray-400"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"无匹配"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"匹配高亮"}),e.jsx(Je,{className:"h-40 rounded-md bg-muted p-3",children:e.jsx("div",{className:"text-sm break-words",children:D()})})]}),Object.keys(w).length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"命名捕获组"}),e.jsx(Je,{className:"h-32 rounded-md border p-3",children:e.jsx("div",{className:"space-y-2",children:Object.entries(w).map(([O,X])=>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:["[",O,"]"]}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("span",{className:"font-mono bg-muted px-2 py-0.5 rounded",children:X})]},O))})})]}),Object.keys(w).length>0&&n&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"Reaction 替换预览"}),e.jsx(Je,{className:"h-48 rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3",children:e.jsx("div",{className:"text-sm break-words",children:y})}),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 cS=Rs.memo(function({keywordReactionConfig:n,responsePostProcessConfig:r,chineseTypoConfig:c,responseSplitterConfig:d,onKeywordReactionChange:u,onResponsePostProcessChange:h,onChineseTypoChange:f,onResponseSplitterChange:p}){const g=()=>{u({...n,regex_rules:[...n.regex_rules,{regex:[""],reaction:""}]})},N=C=>{u({...n,regex_rules:n.regex_rules.filter((D,I)=>I!==C)})},v=(C,D,I)=>{const O=[...n.regex_rules];D==="regex"&&typeof I=="string"?O[C]={...O[C],regex:[I]}:D==="reaction"&&typeof I=="string"&&(O[C]={...O[C],reaction:I}),u({...n,regex_rules:O})},w=()=>{u({...n,keyword_rules:[...n.keyword_rules,{keywords:[],reaction:""}]})},b=C=>{u({...n,keyword_rules:n.keyword_rules.filter((D,I)=>I!==C)})},y=(C,D,I)=>{const O=[...n.keyword_rules];typeof I=="string"&&(O[C]={...O[C],reaction:I}),u({...n,keyword_rules:O})},A=C=>{const D=[...n.keyword_rules];D[C]={...D[C],keywords:[...D[C].keywords||[],""]},u({...n,keyword_rules:D})},z=(C,D)=>{const I=[...n.keyword_rules];I[C]={...I[C],keywords:(I[C].keywords||[]).filter((O,X)=>X!==D)},u({...n,keyword_rules:I})},S=(C,D,I)=>{const O=[...n.keyword_rules],X=[...O[C].keywords||[]];X[D]=I,O[C]={...O[C],keywords:X},u({...n,keyword_rules:O})},U=({rule:C})=>{const D=`{ regex = [${(C.regex||[]).map(I=>`"${I}"`).join(", ")}], reaction = "${C.reaction}" }`;return e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",children:[e.jsx(ia,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(sl,{className:"w-[95vw] sm:w-[500px]",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx(Je,{className:"h-60 rounded-md bg-muted p-3",children:e.jsx("pre",{className:"font-mono text-xs break-all",children:D})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},E=({rule:C})=>{const D=`[[keyword_reaction.keyword_rules]] +keywords = [${(C.keywords||[]).map(I=>`"${I}"`).join(", ")}] +reaction = "${C.reaction}"`;return e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",children:[e.jsx(ia,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(sl,{className:"w-[95vw] sm:w-[500px]",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx(Je,{className:"h-60 rounded-md bg-muted p-3",children:e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all",children:D})}),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(_,{onClick:g,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加正则规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[n.regex_rules.map((C,D)=>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:["正则规则 ",D+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(iS,{regex:C.regex&&C.regex[0]||"",reaction:C.reaction,onRegexChange:I=>v(D,"regex",I),onReactionChange:I=>v(D,"reaction",I)}),e.jsx(U,{rule:C}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除正则规则 ",D+1," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>N(D),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"正则表达式(Python 语法)"}),e.jsx(le,{value:C.regex&&C.regex[0]||"",onChange:I=>v(D,"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(T,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(ot,{value:C.reaction,onChange:I=>v(D,"reaction",I.target.value),placeholder:`触发后麦麦的反应... +可以使用 [捕获组名] 来引用正则表达式中的内容`,rows:3,className:"text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"使用 [捕获组名] 引用正则表达式中的命名捕获组,例如 [n] 会被替换为捕获的内容"})]})]})]},D)),n.regex_rules.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无正则规则,点击"添加正则规则"开始配置'})]})]}),e.jsxs("div",{className:"space-y-4 border-t pt-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-semibold",children:"关键词规则"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"使用关键词列表匹配消息内容"})]}),e.jsxs(_,{onClick:w,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加关键词规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[n.keyword_rules.map((C,D)=>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:["关键词规则 ",D+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{rule:C}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除关键词规则 ",D+1," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>b(D),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(T,{className:"text-xs font-medium",children:"关键词列表"}),e.jsxs(_,{onClick:()=>A(D),size:"sm",variant:"ghost",children:[e.jsx(et,{className:"h-3 w-3 mr-1"}),"添加关键词"]})]}),e.jsxs("div",{className:"space-y-2",children:[(C.keywords||[]).map((I,O)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{value:I,onChange:X=>S(D,O,X.target.value),placeholder:"关键词",className:"flex-1"}),e.jsx(_,{onClick:()=>z(D,O),size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})]},O)),(!C.keywords||C.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(T,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(ot,{value:C.reaction,onChange:I=>y(D,"reaction",I.target.value),placeholder:"触发后麦麦的反应...",rows:3,className:"text-sm"})]})]})]},D)),n.keyword_rules.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无关键词规则,点击"添加关键词规则"开始配置'})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"回复后处理配置"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"enable_response_post_process",checked:r.enable_response_post_process,onCheckedChange:C=>h({...r,enable_response_post_process:C})}),e.jsx(T,{htmlFor:"enable_response_post_process",className:"cursor-pointer",children:"启用回复后处理"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"包括错别字生成器和回复分割器"})]}),r.enable_response_post_process&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t pt-6 space-y-4",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-4",children:[e.jsx(Ve,{id:"enable_chinese_typo",checked:c.enable,onCheckedChange:C=>f({...c,enable:C})}),e.jsx(T,{htmlFor:"enable_chinese_typo",className:"cursor-pointer font-semibold",children:"中文错别字生成器"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"为回复添加随机错别字,让麦麦的回复更自然"}),c.enable&&e.jsxs("div",{className:"grid gap-4 pl-6 border-l-2 border-primary/20",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"error_rate",className:"text-xs font-medium",children:"单字替换概率"}),e.jsx(le,{id:"error_rate",type:"number",step:"0.001",min:"0",max:"1",value:c.error_rate,onChange:C=>f({...c,error_rate:parseFloat(C.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"min_freq",className:"text-xs font-medium",children:"最小字频阈值"}),e.jsx(le,{id:"min_freq",type:"number",min:"0",value:c.min_freq,onChange:C=>f({...c,min_freq:parseInt(C.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"tone_error_rate",className:"text-xs font-medium",children:"声调错误概率"}),e.jsx(le,{id:"tone_error_rate",type:"number",step:"0.01",min:"0",max:"1",value:c.tone_error_rate,onChange:C=>f({...c,tone_error_rate:parseFloat(C.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"word_replace_rate",className:"text-xs font-medium",children:"整词替换概率"}),e.jsx(le,{id:"word_replace_rate",type:"number",step:"0.001",min:"0",max:"1",value:c.word_replace_rate,onChange:C=>f({...c,word_replace_rate:parseFloat(C.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(Ve,{id:"enable_response_splitter",checked:d.enable,onCheckedChange:C=>p({...d,enable:C})}),e.jsx(T,{htmlFor:"enable_response_splitter",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(T,{htmlFor:"max_length",className:"text-xs font-medium",children:"最大长度"}),e.jsx(le,{id:"max_length",type:"number",min:"1",value:d.max_length,onChange:C=>p({...d,max_length:parseInt(C.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"回复允许的最大字符数"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"max_sentence_num",className:"text-xs font-medium",children:"最大句子数"}),e.jsx(le,{id:"max_sentence_num",type:"number",min:"1",value:d.max_sentence_num,onChange:C=>p({...d,max_sentence_num:parseInt(C.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(Ve,{id:"enable_kaomoji_protection",checked:d.enable_kaomoji_protection,onCheckedChange:C=>p({...d,enable_kaomoji_protection:C})}),e.jsx(T,{htmlFor:"enable_kaomoji_protection",className:"cursor-pointer",children:"启用颜文字保护"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"enable_overflow_return_all",checked:d.enable_overflow_return_all,onCheckedChange:C=>p({...d,enable_overflow_return_all:C})}),e.jsx(T,{htmlFor:"enable_overflow_return_all",className:"cursor-pointer",children:"超出时一次性返回全部"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"当句子数量超出限制时,合并后一次性返回所有内容"})]})]})})]})]})]})}),oS=Rs.memo(function({config:n,onChange:r}){const[c,d]=m.useState(""),[u,h]=m.useState(""),[f,p]=m.useState(!1),g=n.allowed_ips?n.allowed_ips.split(",").map(S=>S.trim()).filter(S=>S):[],N=n.trusted_proxies?n.trusted_proxies.split(",").map(S=>S.trim()).filter(S=>S):[],v=()=>{if(!c.trim())return;const S=[...g,c.trim()];r({...n,allowed_ips:S.join(",")}),d("")},w=S=>{const U=g.filter((E,C)=>C!==S);r({...n,allowed_ips:U.join(",")})},b=()=>{if(!u.trim())return;const S=[...N,u.trim()];r({...n,trusted_proxies:S.join(",")}),h("")},y=S=>{const U=N.filter((E,C)=>C!==S);r({...n,trusted_proxies:U.join(",")})},A=S=>{!S&&n.enabled?p(!0):r({...n,enabled:S})},z=()=>{r({...n,enabled:!1}),p(!1)};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"WebUI 服务配置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.enabled,onCheckedChange:A}),e.jsx(T,{className:"cursor-pointer",children:"启用 WebUI"})]}),n.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"运行模式"}),e.jsxs(Ie,{value:n.mode,onValueChange:S=>r({...n,mode:S}),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择运行模式"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"development",children:"开发模式"}),e.jsx(W,{value:"production",children:"生产模式"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"注意: WebUI 的监听地址和端口请在 .env 文件中配置 WEBUI_HOST 和 WEBUI_PORT"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"防爬虫模式"}),e.jsxs(Ie,{value:n.anti_crawler_mode,onValueChange:S=>r({...n,anti_crawler_mode:S}),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择防爬虫模式"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"false",children:"禁用"}),e.jsx(W,{value:"basic",children:"基础(只记录不阻止)"}),e.jsx(W,{value:"loose",children:"宽松"}),e.jsx(W,{value:"strict",children:"严格"})]})]})]}),e.jsxs("div",{className:"grid gap-2 sm:col-span-2",children:[e.jsx(T,{children:"IP 白名单"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(le,{value:c,onChange:S=>d(S.target.value),onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),v())},placeholder:"输入IP地址后按回车或点击添加"}),e.jsx(_,{type:"button",size:"sm",onClick:v,disabled:!c.trim(),children:e.jsx(et,{className:"h-4 w-4"})})]}),g.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:g.map((S,U)=>e.jsxs(ke,{variant:"secondary",className:"flex items-center gap-1",children:[S,e.jsx("button",{type:"button",onClick:()=>w(U),className:"ml-1 hover:bg-destructive/20 rounded-full p-0.5",children:e.jsx(Aa,{className:"h-3 w-3"})})]},U))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"支持精确IP、CIDR格式和通配符(如:127.0.0.1、192.168.1.0/24)"})]}),e.jsxs("div",{className:"grid gap-2 sm:col-span-2",children:[e.jsx(T,{children:"信任的代理 IP"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(le,{value:u,onChange:S=>h(S.target.value),onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),b())},placeholder:"输入代理IP后按回车或点击添加"}),e.jsx(_,{type:"button",size:"sm",onClick:b,disabled:!u.trim(),children:e.jsx(et,{className:"h-4 w-4"})})]}),N.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:N.map((S,U)=>e.jsxs(ke,{variant:"secondary",className:"flex items-center gap-1",children:[S,e.jsx("button",{type:"button",onClick:()=>y(U),className:"ml-1 hover:bg-destructive/20 rounded-full p-0.5",children:e.jsx(Aa,{className:"h-3 w-3"})})]},U))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只有来自这些IP的X-Forwarded-For头才被信任"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.trust_xff,onCheckedChange:S=>r({...n,trust_xff:S})}),e.jsx(T,{className:"cursor-pointer",children:"启用 X-Forwarded-For 代理解析"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.secure_cookie,onCheckedChange:S=>r({...n,secure_cookie:S})}),e.jsx(T,{className:"cursor-pointer",children:"启用安全 Cookie(仅 HTTPS)"})]})]})]}),e.jsx(Ns,{open:f,onOpenChange:p,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"警告:即将关闭 WebUI"}),e.jsxs(fs,{children:["关闭 WebUI 后,在您下次重启麦麦之前,WebUI 界面将无法访问。",e.jsx("br",{}),e.jsx("br",{}),"您需要通过修改配置文件或命令行重新启用 WebUI 才能再次访问此界面。",e.jsx("br",{}),e.jsx("br",{}),"确定要关闭 WebUI 吗?"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{variant:"destructive",onClick:z,children:"确认关闭"})]})]})})]})}),wn="/api/webui/config";async function Lg(){const n=await(await _e(`${wn}/bot`)).json();if(!n.success)throw new Error("获取配置数据失败");return n.config}async function xn(){const n=await(await _e(`${wn}/model`)).json();if(!n.success)throw new Error("获取模型配置数据失败");return n.config}async function Ug(a){const r=await(await _e(`${wn}/bot`,{method:"POST",body:JSON.stringify(a)})).json();if(!r.success)throw new Error(r.message||"保存配置失败")}async function dS(){const n=await(await _e(`${wn}/bot/raw`)).json();if(!n.success)throw new Error("获取配置源代码失败");return n.content}async function uS(a){const r=await(await _e(`${wn}/bot/raw`,{method:"POST",body:JSON.stringify({raw_content:a})})).json();if(!r.success)throw new Error(r.message||"保存配置失败")}async function tc(a){const r=await(await _e(`${wn}/model`,{method:"POST",body:JSON.stringify(a)})).json();if(!r.success)throw new Error(r.message||"保存配置失败")}async function mS(a,n){const c=await(await _e(`${wn}/bot/section/${a}`,{method:"POST",body:JSON.stringify(n)})).json();if(!c.success)throw new Error(c.message||`保存配置节 ${a} 失败`)}async function Ym(a,n){const c=await(await _e(`${wn}/model/section/${a}`,{method:"POST",body:JSON.stringify(n)})).json();if(!c.success)throw new Error(c.message||`保存配置节 ${a} 失败`)}async function xS(a,n="openai",r="/models"){const c=new URLSearchParams({provider_name:a,parser:n,endpoint:r}),d=await _e(`/api/webui/models/list?${c}`);if(!d.ok){const h=await d.json().catch(()=>({}));throw new Error(h.detail||`获取模型列表失败 (${d.status})`)}const u=await d.json();if(!u.success)throw new Error("获取模型列表失败");return u.models}async function hS(a){const n=new URLSearchParams({provider_name:a}),r=await _e(`/api/webui/models/test-connection-by-name?${n}`,{method:"POST"});if(!r.ok){const c=await r.json().catch(()=>({}));throw new Error(c.detail||`测试连接失败 (${r.status})`)}return await r.json()}const fS=Wr("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"}}),at=m.forwardRef(({className:a,variant:n,...r},c)=>e.jsx("div",{ref:c,role:"alert",className:F(fS({variant:n}),a),...r}));at.displayName="Alert";const Gn=m.forwardRef(({className:a,...n},r)=>e.jsx("h5",{ref:r,className:F("mb-1 font-medium leading-none tracking-tight",a),...n}));Gn.displayName="AlertTitle";const lt=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:F("text-sm [&_p]:leading-relaxed",a),...n}));lt.displayName="AlertDescription";const pS={name:"toml",startState:function(){return{inString:!1,stringType:"",lhs:!0,inArray:0}},token:function(a,n){let r;if(!n.inString&&(r=a.match(/^('''|"""|'|")/))&&(n.stringType=r[0],n.inString=!0),a.sol()&&!n.inString&&n.inArray===0&&(n.lhs=!0),n.inString){for(;n.inString;)if(a.match(n.stringType))n.inString=!1;else if(a.peek()==="\\")a.next(),a.next();else{if(a.eol())break;a.match(/^.[^\\\"\']*/)}return n.lhs?"property":"string"}else{if(n.inArray&&a.peek()==="]")return a.next(),n.inArray--,"bracket";if(n.lhs&&a.peek()==="["&&a.skipTo("]"))return a.next(),a.peek()==="]"&&a.next(),"atom";if(a.peek()==="#")return a.skipToEnd(),"comment";if(a.eatSpace())return null;if(n.lhs&&a.eatWhile(function(c){return c!="="&&c!=" "}))return"property";if(n.lhs&&a.peek()==="=")return a.next(),n.lhs=!1,null;if(!n.lhs&&a.match(/^\d\d\d\d[\d\-\:\.T]*Z/))return"atom";if(!n.lhs&&(a.match("true")||a.match("false")))return"atom";if(!n.lhs&&a.peek()==="[")return n.inArray++,a.next(),"bracket";if(!n.lhs&&a.match(/^\-?\d+(?:\.\d+)?/))return"number";a.eatSpace()||a.next()}return null},languageData:{commentTokens:{line:"#"}}},gS={python:[a1()],json:[l1(),n1()],toml:[t1.define(pS)],text:[]};function Iv({value:a,onChange:n,language:r="text",readOnly:c=!1,height:d="400px",minHeight:u,maxHeight:h,placeholder:f,theme:p="dark",className:g=""}){const[N,v]=m.useState(!1);if(m.useEffect(()=>{v(!0)},[]),!N)return e.jsx("div",{className:`rounded-md border bg-muted animate-pulse ${g}`,style:{height:d,minHeight:u,maxHeight:h}});const w=[...gS[r]||[],Sg.lineWrapping];return c&&w.push(Sg.editable.of(!1)),e.jsx("div",{className:`rounded-md overflow-hidden border ${g}`,children:e.jsx(r1,{value:a,height:d,minHeight:u,maxHeight:h,theme:p==="dark"?i1:void 0,extensions:w,onChange:n,placeholder:f,basicSetup:{lineNumbers:!0,highlightActiveLineGutter:!0,highlightSpecialChars:!0,history:!0,foldGutter:!0,drawSelection:!0,dropCursor:!0,allowMultipleSelections:!0,indentOnInput:!0,syntaxHighlighting:!0,bracketMatching:!0,closeBrackets:!0,autocompletion:!0,rectangularSelection:!0,crosshairCursor:!0,highlightActiveLine:!0,highlightSelectionMatches:!0,closeBracketsKeymap:!0,defaultKeymap:!0,searchKeymap:!0,historyKeymap:!0,foldKeymap:!0,completionKeymap:!0,lintKeymap:!0}})})}function jS({id:a,index:n,itemType:r,itemFields:c,value:d,onChange:u,onRemove:h,disabled:f,canRemove:p,placeholder:g}){const{attributes:N,listeners:v,setNodeRef:w,transform:b,transition:y,isDragging:A}=Nv({id:a,disabled:f}),z={transform:bv.Transform.toString(b),transition:y};return e.jsxs("div",{ref:w,style:z,className:F("flex items-start gap-2 group",A&&"opacity-50 z-50"),children:[e.jsx("button",{type:"button",className:F("flex-shrink-0 p-2 cursor-grab active:cursor-grabbing","text-muted-foreground hover:text-foreground transition-colors","opacity-0 group-hover:opacity-100 focus:opacity-100",f&&"cursor-not-allowed opacity-30"),...N,...v,children:e.jsx(tv,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1 min-w-0",children:r==="object"&&c?e.jsx(vS,{value:d,onChange:u,fields:c,disabled:f}):r==="number"?e.jsx(le,{type:"number",value:d??"",onChange:S=>u(parseFloat(S.target.value)||0),placeholder:g??`第 ${n+1} 项`,disabled:f,className:"font-mono"}):e.jsx(le,{type:"text",value:d??"",onChange:S=>u(S.target.value),placeholder:g??`第 ${n+1} 项`,disabled:f})}),e.jsx(_,{type:"button",variant:"ghost",size:"icon",onClick:h,disabled:f||!p,className:F("flex-shrink-0 text-muted-foreground hover:text-destructive","opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity"),children:e.jsx(ns,{className:"h-4 w-4"})})]})}function vS({value:a,onChange:n,fields:r,disabled:c}){const d=m.useCallback((h,f)=>{n({...a,[h]:f})},[a,n]),u=(h,f)=>{const p=a?.[h];if(f.type==="boolean"||f.type==="switch")return e.jsxs("div",{className:"flex items-center justify-between py-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(Ve,{checked:!!(p??f.default),onCheckedChange:g=>d(h,g),disabled:c})]});if(f.type==="slider"||f.type==="number"&&f.min!=null&&f.max!=null){const g=p??f.default??f.min??0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx("span",{className:"text-xs text-muted-foreground",children:g})]}),e.jsx(Qa,{value:[g],onValueChange:N=>d(h,N[0]),min:f.min??0,max:f.max??100,step:f.step??1,disabled:c,className:"py-1"})]})}return f.type==="select"&&f.choices?e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsxs(Ie,{value:String(p??f.default??""),onValueChange:g=>d(h,g),disabled:c,children:[e.jsx(Be,{className:"h-8 text-sm",children:e.jsx(Fe,{placeholder:f.placeholder??"请选择"})}),e.jsx(Pe,{children:f.choices.map(g=>e.jsx(W,{value:String(g),children:String(g)},String(g)))})]})]}):f.type==="number"?e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(le,{type:"number",value:p??f.default??"",onChange:g=>d(h,parseFloat(g.target.value)||0),placeholder:f.placeholder,disabled:c,className:"h-8 text-sm"})]}):e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(le,{type:"text",value:p??f.default??"",onChange:g=>d(h,g.target.value),placeholder:f.placeholder,disabled:c,className:"h-8 text-sm"})]})};return e.jsx(Ce,{className:"p-3 space-y-2 bg-muted/30",children:Object.entries(r).map(([h,f])=>e.jsx("div",{children:u(h,f)},h))})}function NS({value:a,onChange:n,itemType:r="string",itemFields:c,minItems:d,maxItems:u,disabled:h,placeholder:f}){const p=m.useMemo(()=>Array.isArray(a)?a:typeof a=="string"&&a.trim()?a.split(",").map(E=>E.trim()):[],[a]),[g]=m.useState(()=>new Map),N=m.useCallback(E=>(g.has(E)||g.set(E,`item-${Date.now()}-${E}-${Math.random().toString(36).slice(2)}`),g.get(E)),[g]),v=m.useMemo(()=>{const E=[];for(let C=0;C{const{active:C,over:D}=E;if(D&&C.id!==D.id){const I=v.indexOf(C.id),O=v.indexOf(D.id),X=pv(p,I,O);n(X)}},[p,v,n]),y=m.useCallback(()=>{if(u!=null&&p.length>=u)return;let E;r==="object"&&c?E=Object.fromEntries(Object.entries(c).map(([C,D])=>[C,D.default??""])):r==="number"?E=0:E="",n([...p,E])},[p,u,r,c,n]),A=m.useCallback((E,C)=>{const D=[...p];D[E]=C,n(D)},[p,n]),z=m.useCallback(E=>{if(d!=null&&p.length<=d)return;const C=p.filter((D,I)=>I!==E);g.delete(E),n(C)},[p,d,g,n]),S=u==null||p.lengthd;return e.jsxs("div",{className:"space-y-2",children:[p.length===0?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-4 justify-center border border-dashed rounded-md",children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsx("span",{children:"暂无数据,点击下方按钮添加"})]}):e.jsx(gv,{sensors:w,collisionDetection:jv,onDragEnd:b,children:e.jsx(vv,{items:v,strategy:c1,children:e.jsx("div",{className:"space-y-2",children:p.map((E,C)=>e.jsx(jS,{id:v[C],index:C,itemType:r,itemFields:c,value:E,onChange:D=>A(C,D),onRemove:()=>z(C),disabled:h,canRemove:U,placeholder:f},v[C]))})})}),e.jsxs(_,{type:"button",variant:"outline",size:"sm",onClick:y,disabled:h||!S,className:"w-full",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加项目",u!==void 0&&e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",p.length,"/",u,")"]})]}),(d!=null||u!=null)&&(d!==null||u!==null)&&e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:d!=null&&u!=null?`允许 ${d} - ${u} 项`:d!=null?`至少 ${d} 项`:`最多 ${u} 项`})]})}function fx({content:a,className:n=""}){return e.jsx("div",{className:`prose prose-sm dark:prose-invert max-w-none ${n}`,children:e.jsx(h1,{remarkPlugins:[p1,g1],rehypePlugins:[f1],components:{code({inline:r,className:c,children:d,...u}){return r?e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-sm font-mono",...u,children:d}):e.jsx("code",{className:`${c} block bg-muted p-4 rounded-lg overflow-x-auto`,...u,children:d})},table({children:r,...c}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{className:"border-collapse border border-border",...c,children:r})})},th({children:r,...c}){return e.jsx("th",{className:"border border-border bg-muted px-4 py-2 text-left font-semibold",...c,children:r})},td({children:r,...c}){return e.jsx("td",{className:"border border-border px-4 py-2",...c,children:r})},a({children:r,...c}){return e.jsx("a",{className:"text-primary hover:underline",target:"_blank",rel:"noopener noreferrer",...c,children:r})},blockquote({children:r,...c}){return e.jsx("blockquote",{className:"border-l-4 border-primary pl-4 italic text-muted-foreground",...c,children:r})},h1({children:r,...c}){return e.jsx("h1",{className:"text-3xl font-bold mt-6 mb-4",...c,children:r})},h2({children:r,...c}){return e.jsx("h2",{className:"text-2xl font-bold mt-5 mb-3",...c,children:r})},h3({children:r,...c}){return e.jsx("h3",{className:"text-xl font-bold mt-4 mb-2",...c,children:r})},h4({children:r,...c}){return e.jsx("h4",{className:"text-lg font-semibold mt-3 mb-2",...c,children:r})},ul({children:r,...c}){return e.jsx("ul",{className:"list-disc list-inside space-y-1 my-2",...c,children:r})},ol({children:r,...c}){return e.jsx("ol",{className:"list-decimal list-inside space-y-1 my-2",...c,children:r})},p({children:r,...c}){return e.jsx("p",{className:"my-2 leading-relaxed",...c,children:r})},hr({...r}){return e.jsx("hr",{className:"my-4 border-border",...r})}},children:a})})}function bS(a,n,r,c={}){const{debounceMs:d=2e3,onSaveSuccess:u,onSaveError:h}=c,f=m.useRef(null),p=m.useCallback(async(w,b)=>{try{n(!0),await mS(w,b),r(!1),u?.()}catch(y){console.error(`自动保存 ${w} 失败:`,y),r(!0),h?.(y instanceof Error?y:new Error(String(y)))}finally{n(!1)}},[n,r,u,h]),g=m.useCallback((w,b)=>{a||(r(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{p(w,b)},d))},[a,r,p,d]),N=m.useCallback(async(w,b)=>{f.current&&(clearTimeout(f.current),f.current=null),await p(w,b)},[p]),v=m.useCallback(()=>{f.current&&(clearTimeout(f.current),f.current=null)},[]);return m.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]),{triggerAutoSave:g,saveNow:N,cancelPendingAutoSave:v}}function Lt(a,n,r,c){m.useEffect(()=>{a&&!r&&c(n,a)},[a])}const yS=500;function wS(){return e.jsx(Wn,{children:e.jsx(_S,{})})}function _S(){const[a,n]=m.useState(!0),[r,c]=m.useState(!1),[d,u]=m.useState(!1),[h,f]=m.useState(!1),[p,g]=m.useState("visual"),[N,v]=m.useState(""),[w,b]=m.useState(!1),{toast:y}=Ys(),{triggerRestart:A,isRestarting:z}=yn(),[S,U]=m.useState(null),[E,C]=m.useState(null),[D,I]=m.useState(null),[O,X]=m.useState(null),[L,oe]=m.useState(null),[Ne,je]=m.useState(null),[de,he]=m.useState(null),[ge,R]=m.useState(null),[Y,$]=m.useState(null),[ue,G]=m.useState(null),[Se,fe]=m.useState(null),[Te,q]=m.useState(null),[B,M]=m.useState(null),[Q,Ae]=m.useState(null),[ee,J]=m.useState(null),[$e,H]=m.useState(null),[se,Ue]=m.useState(null),[ie,Ee]=m.useState(null),[me,ze]=m.useState(null),rs=m.useRef(!0),Ut=m.useRef({}),aa=m.useCallback(Re=>{Ut.current=Re,U(Re.bot),C(Re.personality);const bs=Re.chat;bs.talk_value_rules||(bs.talk_value_rules=[]),I(bs),X(Re.expression),oe(Re.emoji),je(Re.memory),he(Re.tool),R(Re.voice),$(Re.dream),G(Re.lpmm_knowledge),fe(Re.keyword_reaction),q(Re.response_post_process),M(Re.chinese_typo),Ae(Re.response_splitter),J(Re.log),H(Re.debug),Ue(Re.maim_message),Ee(Re.telemetry),ze(Re.webui)},[]),Ja=m.useCallback(()=>({...Ut.current,bot:S,personality:E,chat:D,expression:O,emoji:L,memory:Ne,tool:de,voice:ge,dream:Y,lpmm_knowledge:ue,keyword_reaction:Se,response_post_process:Te,chinese_typo:B,response_splitter:Q,log:ee,debug:$e,maim_message:se,telemetry:ie,webui:me}),[S,E,D,O,L,Ne,de,ge,Y,ue,Se,Te,B,Q,ee,$e,se,ie,me]),Ht=m.useCallback(async()=>{try{const bs=(await dS()).replace(/"([^"]*)"/g,(ls,ss)=>`"${ss.replace(/\\n/g,` +`).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}"`);v(bs),b(!1)}catch(Re){y({variant:"destructive",title:"加载失败",description:Re instanceof Error?Re.message:"加载源代码失败"})}},[y]),mt=m.useCallback(async()=>{try{n(!0);const Re=await Lg();aa(Re),f(!1),rs.current=!1,await Ht()}catch(Re){console.error("加载配置失败:",Re),y({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}finally{n(!1)}},[y,Ht,aa]);m.useEffect(()=>{mt()},[mt]);const{triggerAutoSave:K,cancelPendingAutoSave:qe}=bS(rs.current,u,f);Lt(S,"bot",rs.current,K),Lt(E,"personality",rs.current,K),Lt(D,"chat",rs.current,K),Lt(O,"expression",rs.current,K),Lt(L,"emoji",rs.current,K),Lt(Ne,"memory",rs.current,K),Lt(de,"tool",rs.current,K),Lt(ge,"voice",rs.current,K),Lt(Y,"dream",rs.current,K),Lt(ue,"lpmm_knowledge",rs.current,K),Lt(Se,"keyword_reaction",rs.current,K),Lt(Te,"response_post_process",rs.current,K),Lt(B,"chinese_typo",rs.current,K),Lt(Q,"response_splitter",rs.current,K),Lt(ee,"log",rs.current,K),Lt($e,"debug",rs.current,K),Lt(se,"maim_message",rs.current,K),Lt(ie,"telemetry",rs.current,K),Lt(me,"webui",rs.current,K);const Qe=async()=>{try{c(!0);const Re=N.replace(/"([^"]*)"/g,(bs,ls)=>`"${ls.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")}"`);await uS(Re),f(!1),b(!1),y({title:"保存成功",description:"配置已保存"}),await mt()}catch(Re){b(!0),y({variant:"destructive",title:"保存失败",description:Re instanceof Error?Re.message:"保存配置失败"})}finally{c(!1)}},es=async Re=>{if(h){y({variant:"destructive",title:"切换失败",description:"请先保存当前更改"});return}if(g(Re),Re==="source")await Ht();else try{const bs=await Lg();aa(bs),f(!1)}catch(bs){console.error("加载配置失败:",bs),y({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}},Us=async()=>{try{c(!0),qe(),await Ug(Ja()),f(!1),y({title:"保存成功",description:"麦麦主程序配置已保存"})}catch(Re){console.error("保存配置失败:",Re),y({title:"保存失败",description:Re.message,variant:"destructive"})}finally{c(!1)}},as=async()=>{await A()},Cs=async()=>{try{c(!0),qe(),await Ug(Ja()),f(!1),y({title:"保存成功",description:"配置已保存,即将重启麦麦..."}),await new Promise(Re=>setTimeout(Re,yS)),await as()}catch(Re){console.error("保存失败:",Re),y({title:"保存失败",description:Re.message,variant:"destructive"})}finally{c(!1)}};return a?e.jsx(Je,{className:"h-full",children:e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})})}):e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:gap-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl sm:text-2xl md:text-3xl font-bold",children:"麦麦主程序配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-xs sm:text-sm",children:"管理麦麦的核心功能和行为设置"})]}),e.jsxs("div",{className:"flex gap-2 flex-shrink-0",children:[e.jsxs(_,{onClick:p==="visual"?Us:Qe,disabled:r||d||!h||z,size:"sm",variant:"outline",className:"w-20 sm:w-24",children:[e.jsx(fc,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{className:"ml-1 truncate text-xs sm:text-sm",children:r?"保存中":d?"自动":h?"保存":"已保存"})]}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{disabled:r||d||z,size:"sm",className:"w-20 sm:w-28",children:[e.jsx(hc,{className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"ml-1 truncate text-xs sm:text-sm",children:z?"重启中":h?"保存重启":"重启"})]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重启麦麦?"}),e.jsx(fs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:h?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:h?Cs:as,children:h?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsx("div",{className:"flex",children:e.jsx(ta,{value:p,onValueChange:Re=>es(Re),className:"w-full",children:e.jsxs(Zt,{className:"h-8 sm:h-9 w-full grid grid-cols-2",children:[e.jsxs(Xe,{value:"visual",className:"text-xs sm:text-sm",children:[e.jsx(av,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"可视化编辑"]}),e.jsxs(Xe,{value:"source",className:"text-xs sm:text-sm",children:[e.jsx(lv,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"源代码编辑"]})]})})})]}),e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsxs(lt,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),p==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsxs(lt,{children:[e.jsx("strong",{children:"源代码模式(高级功能):"}),"直接编辑 TOML 配置文件。此功能仅适用于熟悉 TOML 语法的高级用户。保存时会在后端验证格式,只有格式完全正确才能保存。",w&&e.jsx("span",{className:"text-destructive font-semibold ml-2",children:"⚠️ 上次保存失败,请检查 TOML 格式"})]})]}),e.jsx(Iv,{value:N,onChange:Re=>{v(Re),f(!0),w&&b(!1)},language:"toml",theme:"dark",height:"calc(100vh - 280px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),p==="visual"&&e.jsx(e.Fragment,{children:e.jsxs(ta,{defaultValue:"bot",className:"w-full",children:[e.jsxs(Zt,{className:"flex flex-wrap h-auto gap-1 p-1 sm:grid sm:grid-cols-5 lg:grid-cols-10",children:[e.jsx(Xe,{value:"bot",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"基本信息"}),e.jsx(Xe,{value:"personality",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"人格"}),e.jsx(Xe,{value:"chat",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"聊天"}),e.jsx(Xe,{value:"expression",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"表达"}),e.jsx(Xe,{value:"features",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"功能"}),e.jsx(Xe,{value:"processing",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"处理"}),e.jsx(Xe,{value:"dream",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"做梦"}),e.jsx(Xe,{value:"lpmm",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"知识库"}),e.jsx(Xe,{value:"webui",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"WebUI"}),e.jsx(Xe,{value:"other",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"其他"})]}),e.jsx(ws,{value:"bot",className:"space-y-4",children:S&&e.jsx(K2,{config:S,onChange:U})}),e.jsx(ws,{value:"personality",className:"space-y-4",children:E&&e.jsx(Q2,{config:E,onChange:C})}),e.jsx(ws,{value:"chat",className:"space-y-4",children:D&&e.jsx(X2,{config:D,onChange:I})}),e.jsx(ws,{value:"expression",className:"space-y-4",children:O&&e.jsx(rS,{config:O,onChange:X})}),e.jsx(ws,{value:"features",className:"space-y-4",children:L&&Ne&&de&&ge&&e.jsx(lS,{emojiConfig:L,memoryConfig:Ne,toolConfig:de,voiceConfig:ge,onEmojiChange:oe,onMemoryChange:je,onToolChange:he,onVoiceChange:R})}),e.jsx(ws,{value:"processing",className:"space-y-4",children:Se&&Te&&B&&Q&&e.jsx(cS,{keywordReactionConfig:Se,responsePostProcessConfig:Te,chineseTypoConfig:B,responseSplitterConfig:Q,onKeywordReactionChange:fe,onResponsePostProcessChange:q,onChineseTypoChange:M,onResponseSplitterChange:Ae})}),e.jsx(ws,{value:"dream",className:"space-y-4",children:Y&&e.jsx(Z2,{config:Y,onChange:$})}),e.jsx(ws,{value:"lpmm",className:"space-y-4",children:ue&&e.jsx(W2,{config:ue,onChange:G})}),e.jsx(ws,{value:"webui",className:"space-y-4",children:me&&e.jsx(oS,{config:me,onChange:ze})}),e.jsxs(ws,{value:"other",className:"space-y-4",children:[ee&&e.jsx(eS,{config:ee,onChange:J}),$e&&e.jsx(sS,{config:$e,onChange:H}),se&&e.jsx(tS,{config:se,onChange:Ue}),ie&&e.jsx(aS,{config:ie,onChange:Ee})]})]})}),e.jsx(er,{})]})})}const Ul=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:r,className:F("w-full caption-bottom text-sm",a),...n})}));Ul.displayName="Table";const $l=m.forwardRef(({className:a,...n},r)=>e.jsx("thead",{ref:r,className:F("[&_tr]:border-b",a),...n}));$l.displayName="TableHeader";const Bl=m.forwardRef(({className:a,...n},r)=>e.jsx("tbody",{ref:r,className:F("[&_tr:last-child]:border-0",a),...n}));Bl.displayName="TableBody";const SS=m.forwardRef(({className:a,...n},r)=>e.jsx("tfoot",{ref:r,className:F("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",a),...n}));SS.displayName="TableFooter";const ut=m.forwardRef(({className:a,...n},r)=>e.jsx("tr",{ref:r,className:F("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",a),...n}));ut.displayName="TableRow";const We=m.forwardRef(({className:a,...n},r)=>e.jsx("th",{ref:r,className:F("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",a),...n}));We.displayName="TableHead";const Ke=m.forwardRef(({className:a,...n},r)=>e.jsx("td",{ref:r,className:F("px-4 py-3 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",a),...n}));Ke.displayName="TableCell";const kS=m.forwardRef(({className:a,...n},r)=>e.jsx("caption",{ref:r,className:F("mt-4 text-sm text-muted-foreground",a),...n}));kS.displayName="TableCaption";const dd=m.forwardRef(({className:a,...n},r)=>e.jsx(ja,{ref:r,className:F("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",a),...n}));dd.displayName=ja.displayName;const ud=m.forwardRef(({className:a,...n},r)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(Tt,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(ja.Input,{ref:r,className:F("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",a),...n})]}));ud.displayName=ja.Input.displayName;const md=m.forwardRef(({className:a,...n},r)=>e.jsx(ja.List,{ref:r,className:F("max-h-[300px] overflow-y-auto overflow-x-hidden",a),...n}));md.displayName=ja.List.displayName;const xd=m.forwardRef((a,n)=>e.jsx(ja.Empty,{ref:n,className:"py-6 text-center text-sm",...a}));xd.displayName=ja.Empty.displayName;const oc=m.forwardRef(({className:a,...n},r)=>e.jsx(ja.Group,{ref:r,className:F("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",a),...n}));oc.displayName=ja.Group.displayName;const CS=m.forwardRef(({className:a,...n},r)=>e.jsx(ja.Separator,{ref:r,className:F("-mx-1 h-px bg-border",a),...n}));CS.displayName=ja.Separator.displayName;const dc=m.forwardRef(({className:a,...n},r)=>e.jsx(ja.Item,{ref:r,className:F("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",a),...n}));dc.displayName=ja.Item.displayName;const Fv=m.createContext(null),Hv="maibot-completed-tours";function TS(){try{const a=localStorage.getItem(Hv);return a?new Set(JSON.parse(a)):new Set}catch{return new Set}}function $g(a){localStorage.setItem(Hv,JSON.stringify([...a]))}function ES({children:a}){const[n,r]=m.useState({activeTourId:null,stepIndex:0,isRunning:!1}),[c]=m.useState(()=>new Map),[d,u]=m.useState(TS),[,h]=m.useState(0),f=m.useCallback((E,C)=>{c.set(E,C),h(D=>D+1)},[c]),p=m.useCallback(E=>{c.delete(E),r(C=>C.activeTourId===E?{...C,activeTourId:null,isRunning:!1,stepIndex:0}:C)},[c]),g=m.useCallback((E,C=0)=>{c.has(E)&&r({activeTourId:E,stepIndex:C,isRunning:!0})},[c]),N=m.useCallback(()=>{r(E=>({...E,isRunning:!1}))},[]),v=m.useCallback(E=>{r(C=>({...C,stepIndex:E}))},[]),w=m.useCallback(()=>{r(E=>({...E,stepIndex:E.stepIndex+1}))},[]),b=m.useCallback(()=>{r(E=>({...E,stepIndex:Math.max(0,E.stepIndex-1)}))},[]),y=m.useCallback(()=>n.activeTourId?c.get(n.activeTourId)||[]:[],[n.activeTourId,c]),A=m.useCallback(E=>{u(C=>{const D=new Set(C);return D.add(E),$g(D),D})},[]),z=m.useCallback(E=>{const{action:C,index:D,status:I,type:O}=E,X=["finished","skipped"];if(C==="close"){r(L=>({...L,isRunning:!1,stepIndex:0}));return}X.includes(I)?r(L=>(I==="finished"&&L.activeTourId&&setTimeout(()=>A(L.activeTourId),0),{...L,isRunning:!1,stepIndex:0})):O==="step:after"&&(C==="next"?r(L=>({...L,stepIndex:D+1})):C==="prev"&&r(L=>({...L,stepIndex:D-1})))},[A]),S=m.useCallback(E=>d.has(E),[d]),U=m.useCallback(E=>{u(C=>{const D=new Set(C);return D.delete(E),$g(D),D})},[]);return e.jsx(Fv.Provider,{value:{state:n,tours:c,registerTour:f,unregisterTour:p,startTour:g,stopTour:N,goToStep:v,nextStep:w,prevStep:b,getCurrentSteps:y,handleJoyrideCallback:z,isTourCompleted:S,markTourCompleted:A,resetTourCompleted:U},children:a})}function px(){const a=m.useContext(Fv);if(!a)throw new Error("useTour must be used within a TourProvider");return a}const MS={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)"}},AS={back:"上一步",close:"关闭",last:"完成",next:"下一步",nextLabelWithProgress:"下一步 ({step}/{steps})",open:"打开对话框",skip:"跳过"};function zS(){const{state:a,getCurrentSteps:n,handleJoyrideCallback:r}=px(),c=n(),[d,u]=m.useState(!1),h=m.useRef(a.stepIndex),f=m.useRef(null);m.useEffect(()=>{h.current!==a.stepIndex&&(u(!1),h.current=a.stepIndex)},[a.stepIndex]),m.useEffect(()=>{if(!a.isRunning||c.length===0){u(!1);return}const v=c[a.stepIndex];if(!v){u(!1);return}const w=v.target;if(w==="body"){u(!0);return}u(!1);const b=setTimeout(()=>{const y=()=>{const U=document.querySelector(w);if(U){const E=U.getBoundingClientRect();if(E.width>0&&E.height>0)return!0}return!1};if(y()){setTimeout(()=>u(!0),100);return}const A=setInterval(()=>{y()&&(clearInterval(A),setTimeout(()=>u(!0),100))},100),z=setTimeout(()=>{clearInterval(A),u(!0)},5e3),S=()=>{clearInterval(A),clearTimeout(z)};f.current=S},150);return()=>{clearTimeout(b),f.current&&(f.current(),f.current=null)}},[a.isRunning,a.stepIndex,c]);const[p,g]=m.useState(null);if(m.useEffect(()=>{let v=document.getElementById("tour-portal-container");return v||(v=document.createElement("div"),v.id="tour-portal-container",v.style.cssText="position: fixed; top: 0; left: 0; z-index: 99999; pointer-events: none;",document.body.appendChild(v)),g(v),()=>{}},[]),!a.isRunning||c.length===0||!d)return null;const N=e.jsx(d1,{steps:c,stepIndex:a.stepIndex,run:a.isRunning,continuous:!0,showSkipButton:!0,showProgress:!0,disableOverlayClose:!0,disableScrolling:!1,disableScrollParentFix:!1,callback:r,styles:MS,locale:AS,scrollOffset:80,scrollToFirstStep:!0,floaterProps:{styles:{floater:{zIndex:99999}},disableAnimation:!0}},`tour-step-${a.stepIndex}`);return p?Q0.createPortal(N,p):N}const ol="model-assignment-tour",Vv=[{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}],Gv={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"},Xi=[{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 Bg(a){return a?a.replace(/\/+$/,"").toLowerCase():""}function RS(a){if(!a)return null;const n=Bg(a);return Xi.find(r=>r.id!=="custom"&&Bg(r.base_url)===n)||null}const Do=a=>({...a,max_retry:a.max_retry??2,timeout:a.timeout??30,retry_interval:a.retry_interval??10}),DS=(a,n=[],r=null)=>{const c={};return a?(a.name?.trim()?n.some((u,h)=>r!==null&&h===r?!1:u.name.trim().toLowerCase()===a.name.trim().toLowerCase())&&(c.name="提供商名称已存在,请使用其他名称"):c.name="请输入提供商名称",a.base_url?.trim()||(c.base_url="请输入基础 URL"),a.api_key?.trim()||(c.api_key="请输入 API Key"),{isValid:Object.keys(c).length===0,errors:c}):{isValid:!1,errors:{name:"提供商数据为空"}}};function OS(){return e.jsx(Wn,{children:e.jsx(LS,{})})}function LS(){const[a,n]=m.useState([]),[r,c]=m.useState(!0),[d,u]=m.useState(!1),[h,f]=m.useState(!1),[p,g]=m.useState(!1),[N,v]=m.useState(!1),[w,b]=m.useState(null),[y,A]=m.useState(null),[z,S]=m.useState("custom"),[U,E]=m.useState(!1),[C,D]=m.useState(!1),[I,O]=m.useState(null),[X,L]=m.useState(!1),[oe,Ne]=m.useState(""),[je,de]=m.useState(new Set),[he,ge]=m.useState(!1),[R,Y]=m.useState(1),[$,ue]=m.useState(20),[G,Se]=m.useState(""),[fe,Te]=m.useState({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),[q,B]=m.useState({}),[M,Q]=m.useState(new Set),[Ae,ee]=m.useState(new Map),{toast:J}=Ys(),$e=ca(),{state:H,goToStep:se,registerTour:Ue}=px(),{triggerRestart:ie,isRestarting:Ee}=yn(),me=m.useRef(null),ze=m.useRef(!0);m.useEffect(()=>{Ue(ol,Vv)},[Ue]),m.useEffect(()=>{if(H.activeTourId===ol&&H.isRunning){const te=Gv[H.stepIndex];te&&!window.location.pathname.endsWith(te.replace("/config/",""))&&$e({to:te})}},[H.stepIndex,H.activeTourId,H.isRunning,$e]);const rs=m.useRef(H.stepIndex);m.useEffect(()=>{if(H.activeTourId===ol&&H.isRunning){const te=rs.current,we=H.stepIndex;te>=3&&te<=9&&we<3&&v(!1),te>=10&&we>=3&&we<=9&&(B({}),S("custom"),b({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10}),A(null),L(!1),v(!0)),rs.current=we}},[H.stepIndex,H.activeTourId,H.isRunning]),m.useEffect(()=>{if(H.activeTourId!==ol||!H.isRunning)return;const te=we=>{const Le=we.target,Fs=H.stepIndex;Fs===2&&Le.closest('[data-tour="add-provider-button"]')?setTimeout(()=>se(3),300):Fs===9&&Le.closest('[data-tour="provider-cancel-button"]')&&setTimeout(()=>se(10),300)};return document.addEventListener("click",te,!0),()=>document.removeEventListener("click",te,!0)},[H,se]),m.useEffect(()=>{Ut()},[]);const Ut=async()=>{try{c(!0);const te=await xn();n(te.api_providers||[]),g(!1),ze.current=!1}catch(te){console.error("加载配置失败:",te)}finally{c(!1)}},aa=async()=>{await ie()},Ja=async()=>{try{u(!0),me.current&&clearTimeout(me.current);const te=a.map(rt=>({...rt,max_retry:rt.max_retry??2,timeout:rt.timeout??30,retry_interval:rt.retry_interval??10})),{shouldProceed:we}=await Ht(te,"restart");if(!we){u(!1);return}const Le=await xn(),Fs=new Set(te.map(rt=>rt.name)),ea=(Le.models||[]).filter(rt=>Fs.has(rt.api_provider));Le.api_providers=te,Le.models=ea,await tc(Le),g(!1),J({title:"保存成功",description:"正在重启麦麦..."}),await aa()}catch(te){console.error("保存配置失败:",te),J({title:"保存失败",description:te.message,variant:"destructive"}),u(!1)}},Ht=m.useCallback(async(te,we="auto")=>{try{const Le=await xn(),Fs=new Set(a.map(xt=>xt.name)),Dt=new Set(te.map(xt=>xt.name)),ea=Array.from(Fs).filter(xt=>!Dt.has(xt));if(ea.length===0)return{shouldProceed:!0,providers:te};const sa=(Le.models||[]).filter(xt=>ea.includes(xt.api_provider));return sa.length===0?{shouldProceed:!0,providers:te}:(Te({isOpen:!0,providersToDelete:ea,affectedModels:sa,pendingProviders:te,context:we,oldProviders:[...a]}),{shouldProceed:!1,providers:te})}catch(Le){return console.error("检查删除影响失败:",Le),{shouldProceed:!0,providers:te}}},[a]),mt=async()=>{try{(fe.context==="auto"?f:u)(!0),Te(xt=>({...xt,isOpen:!1}));const we=await xn(),Le=fe.pendingProviders.map(Do),Fs=new Set(Le.map(xt=>xt.name)),ea=(we.models||[]).filter(xt=>Fs.has(xt.api_provider)),rt=new Set(fe.affectedModels.map(xt=>xt.name)),sa=we.model_task_config;sa&&Object.keys(sa).forEach(xt=>{const re=sa[xt];re&&Array.isArray(re.model_list)&&(re.model_list=re.model_list.filter(pe=>!rt.has(pe)))}),we.api_providers=Le,we.models=ea,we.model_task_config=sa,await tc(we),n(fe.pendingProviders),g(!1),J({title:"删除成功",description:`已删除 ${fe.providersToDelete.length} 个提供商和 ${fe.affectedModels.length} 个关联模型`}),Te({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),de(new Set),fe.context==="restart"&&await aa()}catch(te){console.error("删除失败:",te),J({title:"删除失败",description:te.message,variant:"destructive"})}finally{fe.context==="auto"?f(!1):u(!1)}},K=()=>{fe.oldProviders.length>0&&n(fe.oldProviders),Te({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),g(!1)},qe=m.useCallback(async te=>{if(ze.current)return;const{shouldProceed:we}=await Ht(te,"auto");if(!we){g(!0);return}try{f(!0);const Le=te.map(Do);await Ym("api_providers",Le),g(!1)}catch(Le){console.error("自动保存失败:",Le),J({title:"自动保存失败",description:Le.message,variant:"destructive"}),g(!0)}finally{f(!1)}},[a,Ht]);m.useEffect(()=>{if(!ze.current)return g(!0),me.current&&clearTimeout(me.current),me.current=setTimeout(()=>{qe(a)},2e3),()=>{me.current&&clearTimeout(me.current)}},[a,qe]);const Qe=async()=>{try{u(!0),me.current&&clearTimeout(me.current);const te=a.map(Do),{shouldProceed:we}=await Ht(te,"manual");if(!we){u(!1);return}const Le=await xn(),Fs=new Set(te.map(rt=>rt.name)),Dt=Le.models||[],ea=Dt.filter(rt=>{const sa=Fs.has(rt.api_provider);return sa||console.warn(`模型 "${rt.name}" 引用了已删除的提供商 "${rt.api_provider}",将被移除`),sa});if(Dt.length!==ea.length){const rt=Dt.length-ea.length;J({title:"注意",description:`已自动移除 ${rt} 个引用已删除提供商的模型`,variant:"default"})}console.log("发送的 providers 数据:",te),Le.api_providers=te,Le.models=ea,console.log("完整配置数据:",Le),await tc(Le),g(!1),J({title:"保存成功",description:"模型提供商配置已保存"})}catch(te){console.error("保存配置失败:",te),J({title:"保存失败",description:te.message,variant:"destructive"})}finally{u(!1)}},es=(te,we)=>{if(B({}),te){const Le=Xi.find(Fs=>Fs.base_url===te.base_url&&Fs.client_type===te.client_type);S(Le?.id||"custom"),b(te)}else S("custom"),b({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10});A(we),L(!1),v(!0)},Us=m.useCallback(te=>{S(te),E(!1);const we=Xi.find(Le=>Le.id===te);we&&we.id!=="custom"?b(Le=>({...Le,name:we.name,base_url:we.base_url,client_type:we.client_type})):we?.id==="custom"&&b(Le=>({...Le,name:"",base_url:"",client_type:"openai"}))},[]),as=m.useMemo(()=>z!=="custom",[z]),Cs=m.useCallback(async()=>{if(w?.api_key)try{await navigator.clipboard.writeText(w.api_key),J({title:"复制成功",description:"API Key 已复制到剪贴板"})}catch{J({title:"复制失败",description:"无法访问剪贴板",variant:"destructive"})}},[w?.api_key,J]),Re=()=>{if(!w)return;const{isValid:te,errors:we}=DS(w,a,y);if(!te){B(we);return}B({});const Le=Do(w);if(y!==null){const Fs=[...a];Fs[y]=Le,n(Fs)}else n([...a,Le]);v(!1),b(null),A(null)},bs=te=>{if(!te&&w){const we={...w,max_retry:w.max_retry??2,timeout:w.timeout??30,retry_interval:w.retry_interval??10};b(we)}v(te)},ls=te=>{O(te),D(!0)},ss=async()=>{if(I!==null){const te=a.filter((Le,Fs)=>Fs!==I),{shouldProceed:we}=await Ht(te,"manual");we&&(n(te),J({title:"删除成功",description:"提供商已从列表中移除"}))}D(!1),O(null)},ys=te=>{const we=new Set(je);we.has(te)?we.delete(te):we.add(te),de(we)},gt=()=>{if(je.size===Ms.length)de(new Set);else{const te=Ms.map((we,Le)=>a.findIndex(Fs=>Fs===Ms[Le]));de(new Set(te))}},$t=()=>{if(je.size===0){J({title:"提示",description:"请先选择要删除的提供商",variant:"default"});return}ge(!0)},tt=async()=>{const te=a.filter((Le,Fs)=>!je.has(Fs)),{shouldProceed:we}=await Ht(te,"manual");we&&(n(te),de(new Set),J({title:"批量删除成功",description:`已删除 ${je.size} 个提供商`})),ge(!1)},Ms=m.useMemo(()=>{if(!oe)return a;const te=oe.toLowerCase();return a.filter(we=>we.name.toLowerCase().includes(te)||we.base_url.toLowerCase().includes(te)||we.client_type.toLowerCase().includes(te))},[a,oe]),{totalPages:Et,paginatedProviders:Bt}=m.useMemo(()=>{const te=Math.ceil(Ms.length/$),we=Ms.slice((R-1)*$,R*$);return{totalPages:te,paginatedProviders:we}},[Ms,R,$]),Oa=m.useCallback(()=>{const te=parseInt(G);te>=1&&te<=Et&&(Y(te),Se(""))},[G,Et]),ll=async te=>{Q(we=>new Set(we).add(te));try{const we=await hS(te);ee(Le=>new Map(Le).set(te,we)),we.network_ok?we.api_key_valid===!0?J({title:"连接正常",description:`${te} 网络连接正常,API Key 有效 (${we.latency_ms}ms)`}):we.api_key_valid===!1?J({title:"连接正常但 Key 无效",description:`${te} 网络连接正常,但 API Key 无效或已过期`,variant:"destructive"}):J({title:"网络连接正常",description:`${te} 可以访问 (${we.latency_ms}ms)`}):J({title:"连接失败",description:we.error||"无法连接到提供商",variant:"destructive"})}catch(we){J({title:"测试失败",description:we.message,variant:"destructive"})}finally{Q(we=>{const Le=new Set(we);return Le.delete(te),Le})}},xl=async()=>{for(const te of a)await ll(te.name)},sr=te=>{const we=M.has(te),Le=Ae.get(te);return we?e.jsxs(ke,{variant:"secondary",className:"gap-1",children:[e.jsx(zs,{className:"h-3 w-3 animate-spin"}),"测试中"]}):Le?Le.network_ok?Le.api_key_valid===!0?e.jsxs(ke,{className:"gap-1 bg-green-600 hover:bg-green-700",children:[e.jsx(pt,{className:"h-3 w-3"}),"正常"]}):Le.api_key_valid===!1?e.jsxs(ke,{variant:"destructive",className:"gap-1",children:[e.jsx(_t,{className:"h-3 w-3"}),"Key无效"]}):e.jsxs(ke,{className:"gap-1 bg-blue-600 hover:bg-blue-700",children:[e.jsx(pt,{className:"h-3 w-3"}),"可访问"]}):e.jsxs(ke,{variant:"destructive",className:"gap-1",children:[e.jsx(Ka,{className:"h-3 w-3"}),"离线"]}):null};return r?e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})}):e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"AI模型厂商配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理 AI 模型厂商的 API 配置"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[je.size>0&&e.jsxs(_,{onClick:$t,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(ns,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",je.size,")"]}),e.jsxs(_,{onClick:xl,size:"sm",variant:"outline",className:"w-full sm:w-auto",disabled:a.length===0||M.size>0,children:[e.jsx(el,{className:"mr-2 h-4 w-4"}),M.size>0?`测试中 (${M.size})`:"测试全部"]}),e.jsxs(_,{onClick:()=>es(null,null),size:"sm",className:"w-full sm:w-auto","data-tour":"add-provider-button",children:[e.jsx(et,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"添加提供商"]}),e.jsxs(_,{onClick:Qe,disabled:d||h||!p||Ee,size:"sm",variant:"outline",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(fc,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),d?"保存中...":h?"自动保存中...":p?"保存配置":"已保存"]}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{disabled:d||h||Ee,size:"sm",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(hc,{className:"mr-2 h-4 w-4"}),Ee?"重启中...":p?"保存并重启":"重启麦麦"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重启麦麦?"}),e.jsx(fs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:p?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:p?Ja:aa,children:p?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsxs(lt,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),e.jsxs(Je,{className:"h-[calc(100vh-260px)]",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-2 mb-4",children:[e.jsxs("div",{className:"relative w-full sm:flex-1 sm:max-w-sm",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(le,{placeholder:"搜索提供商名称、URL 或类型...",value:oe,onChange:te=>Ne(te.target.value),className:"pl-9"})]}),oe&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",Ms.length," 个结果"]})]}),e.jsx("div",{className:"md:hidden space-y-3",children:Ms.length===0?e.jsx("div",{className:"text-center text-muted-foreground py-8 rounded-lg border bg-card",children:oe?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'}):Bt.map((te,we)=>{const Le=a.findIndex(Fs=>Fs===te);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:te.name}),sr(te.name)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 break-all",children:te.base_url})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>ll(te.name),disabled:M.has(te.name),title:"测试连接",children:M.has(te.name)?e.jsx(zs,{className:"h-4 w-4 animate-spin"}):e.jsx(el,{className:"h-4 w-4"})}),e.jsx(_,{variant:"default",size:"sm",onClick:()=>es(te,Le),children:e.jsx(Kn,{className:"h-4 w-4",strokeWidth:2,fill:"none"})}),e.jsx(_,{size:"sm",onClick:()=>ls(Le),className:"bg-red-600 hover:bg-red-700 text-white",children:e.jsx(ns,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"客户端类型"}),e.jsx("p",{className:"font-medium",children:te.client_type})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"最大重试"}),e.jsx("p",{className:"font-medium",children:te.max_retry})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"超时(秒)"}),e.jsx("p",{className:"font-medium",children:te.timeout})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"重试间隔(秒)"}),e.jsx("p",{className:"font-medium",children:te.retry_interval})]})]})]},we)})}),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(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:je.size===Ms.length&&Ms.length>0,onCheckedChange:gt})}),e.jsx(We,{children:"状态"}),e.jsx(We,{children:"名称"}),e.jsx(We,{children:"基础URL"}),e.jsx(We,{children:"客户端类型"}),e.jsx(We,{className:"text-right",children:"最大重试"}),e.jsx(We,{className:"text-right",children:"超时(秒)"}),e.jsx(We,{className:"text-right",children:"重试间隔(秒)"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:Bt.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:9,className:"text-center text-muted-foreground py-8",children:oe?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'})}):Bt.map((te,we)=>{const Le=a.findIndex(Fs=>Fs===te);return e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(qs,{checked:je.has(Le),onCheckedChange:()=>ys(Le)})}),e.jsx(Ke,{children:sr(te.name)||e.jsx(ke,{variant:"outline",className:"text-muted-foreground",children:"未测试"})}),e.jsx(Ke,{className:"font-medium",children:te.name}),e.jsx(Ke,{className:"max-w-xs truncate",title:te.base_url,children:te.base_url}),e.jsx(Ke,{children:te.client_type}),e.jsx(Ke,{className:"text-right",children:te.max_retry}),e.jsx(Ke,{className:"text-right",children:te.timeout}),e.jsx(Ke,{className:"text-right",children:te.retry_interval}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>ll(te.name),disabled:M.has(te.name),title:"测试连接",children:M.has(te.name)?e.jsx(zs,{className:"h-4 w-4 animate-spin"}):e.jsx(el,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"default",size:"sm",onClick:()=>es(te,Le),children:[e.jsx(Kn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>ls(Le),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},we)})})]})})}),Ms.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(T,{htmlFor:"page-size-provider",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ie,{value:$.toString(),onValueChange:te=>{ue(parseInt(te)),Y(1),de(new Set)},children:[e.jsx(Be,{id:"page-size-provider",className:"w-20",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"10",children:"10"}),e.jsx(W,{value:"20",children:"20"}),e.jsx(W,{value:"50",children:"50"}),e.jsx(W,{value:"100",children:"100"})]})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(R-1)*$+1," 到"," ",Math.min(R*$,Ms.length)," 条,共 ",Ms.length," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>Y(1),disabled:R===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>Y(te=>Math.max(1,te-1)),disabled:R===1,children:[e.jsx(Da,{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(le,{type:"number",value:G,onChange:te=>Se(te.target.value),onKeyDown:te=>te.key==="Enter"&&Oa(),placeholder:R.toString(),className:"w-16 h-8 text-center",min:1,max:Et}),e.jsx(_,{variant:"outline",size:"sm",onClick:Oa,disabled:!G,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>Y(te=>te+1),disabled:R>=Et,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>Y(Et),disabled:R>=Et,className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]}),e.jsx(Ps,{open:N,onOpenChange:bs,children:e.jsxs(Ds,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"provider-dialog",preventOutsideClose:H.isRunning,children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:y!==null?"编辑提供商":"添加提供商"}),e.jsx(Ks,{children:"配置 API 提供商的连接信息和参数"})]}),e.jsxs("form",{onSubmit:te=>{te.preventDefault(),Re()},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(T,{htmlFor:"template",children:"提供商模板"}),e.jsxs(ul,{open:U,onOpenChange:E,children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",role:"combobox","aria-expanded":U,className:"w-full justify-between",children:[z?Xi.find(te=>te.id===z)?.display_name:"选择提供商模板...",e.jsx(rx,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(sl,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(dd,{children:[e.jsx(ud,{placeholder:"搜索提供商模板..."}),e.jsx(Je,{className:"h-[300px]",children:e.jsxs(md,{className:"max-h-none overflow-visible",children:[e.jsx(xd,{children:"未找到匹配的模板"}),e.jsx(oc,{children:Xi.map(te=>e.jsxs(dc,{value:te.display_name,onSelect:()=>Us(te.id),children:[e.jsx(Ct,{className:`mr-2 h-4 w-4 ${z===te.id?"opacity-100":"opacity-0"}`}),te.display_name]},te.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(T,{htmlFor:"name",className:q.name?"text-destructive":"",children:"名称 *"}),e.jsx(le,{id:"name",value:w?.name||"",onChange:te=>{b(we=>we?{...we,name:te.target.value}:null),q.name&&B(we=>({...we,name:void 0}))},placeholder:"例如: DeepSeek, SiliconFlow",className:q.name?"border-destructive focus-visible:ring-destructive":""}),q.name&&e.jsx("p",{className:"text-xs text-destructive",children:q.name})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"provider-url-input",children:[e.jsx(T,{htmlFor:"base_url",className:q.base_url?"text-destructive":"",children:"基础 URL *"}),e.jsx(le,{id:"base_url",value:w?.base_url||"",onChange:te=>{b(we=>we?{...we,base_url:te.target.value}:null),q.base_url&&B(we=>({...we,base_url:void 0}))},placeholder:"https://api.example.com/v1",disabled:as,className:`${as?"bg-muted cursor-not-allowed":""} ${q.base_url?"border-destructive focus-visible:ring-destructive":""}`}),q.base_url&&e.jsx("p",{className:"text-xs text-destructive",children:q.base_url}),as&&!q.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(T,{htmlFor:"api_key",className:q.api_key?"text-destructive":"",children:"API Key *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(le,{id:"api_key",type:X?"text":"password",value:w?.api_key||"",onChange:te=>{b(we=>we?{...we,api_key:te.target.value}:null),q.api_key&&B(we=>({...we,api_key:void 0}))},placeholder:"sk-...",className:`flex-1 ${q.api_key?"border-destructive focus-visible:ring-destructive":""}`}),e.jsx(_,{type:"button",variant:"outline",size:"icon",onClick:()=>L(!X),title:X?"隐藏密钥":"显示密钥",children:X?e.jsx(nc,{className:"h-4 w-4"}):e.jsx(ia,{className:"h-4 w-4"})}),e.jsx(_,{type:"button",variant:"outline",size:"icon",onClick:Cs,title:"复制密钥",children:e.jsx(Fo,{className:"h-4 w-4"})})]}),q.api_key&&e.jsx("p",{className:"text-xs text-destructive",children:q.api_key})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"client_type",children:"客户端类型"}),e.jsxs(Ie,{value:w?.client_type||"openai",onValueChange:te=>b(we=>we?{...we,client_type:te}:null),disabled:as,children:[e.jsx(Be,{id:"client_type",className:as?"bg-muted cursor-not-allowed":"",children:e.jsx(Fe,{placeholder:"选择客户端类型"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"openai",children:"OpenAI"}),e.jsx(W,{value:"gemini",children:"Gemini"})]})]}),as&&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(T,{htmlFor:"max_retry",children:"最大重试"}),e.jsx(le,{id:"max_retry",type:"number",min:"0",value:w?.max_retry??"",onChange:te=>{const we=te.target.value===""?null:parseInt(te.target.value);b(Le=>Le?{...Le,max_retry:we}:null)},placeholder:"默认: 2"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"timeout",children:"超时(秒)"}),e.jsx(le,{id:"timeout",type:"number",min:"1",value:w?.timeout??"",onChange:te=>{const we=te.target.value===""?null:parseInt(te.target.value);b(Le=>Le?{...Le,timeout:we}:null)},placeholder:"默认: 30"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"retry_interval",children:"重试间隔(秒)"}),e.jsx(le,{id:"retry_interval",type:"number",min:"1",value:w?.retry_interval??"",onChange:te=>{const we=te.target.value===""?null:parseInt(te.target.value);b(Le=>Le?{...Le,retry_interval:we}:null)},placeholder:"默认: 10"})]})]})]}),e.jsxs(st,{children:[e.jsx(_,{type:"button",variant:"outline",onClick:()=>v(!1),"data-tour":"provider-cancel-button",children:"取消"}),e.jsx(_,{type:"submit","data-tour":"provider-save-button",children:"保存"})]})]})]})}),e.jsx(Ns,{open:C,onOpenChange:D,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除提供商 "',I!==null?a[I]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:ss,children:"删除"})]})]})}),e.jsx(Ns,{open:he,onOpenChange:ge,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["确定要删除选中的 ",je.size," 个提供商吗? 此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:tt,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),e.jsx(Ns,{open:fe.isOpen,onOpenChange:te=>Te(we=>({...we,isOpen:te})),children:e.jsxs(us,{className:"max-w-2xl",children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除提供商"}),e.jsx(fs,{asChild:!0,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{children:["您即将删除以下提供商:",e.jsx("strong",{className:"text-foreground ml-1",children:fe.providersToDelete.join(", ")})]}),e.jsxs("p",{className:"text-yellow-600 dark:text-yellow-500 font-medium",children:["⚠️ 此操作将同时删除 ",fe.affectedModels.length," 个关联的模型:"]}),e.jsx(Je,{className:"h-32 w-full rounded border p-3",children:e.jsx("div",{className:"space-y-1",children:fe.affectedModels.map((te,we)=>e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:"•"}),e.jsx("span",{className:"ml-2 font-medium",children:te.name}),e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",te.model_identifier,")"]})]},we))})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"这些模型将从模型列表和所有任务分配中移除。此操作无法撤销。"})]})})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:K,children:"取消"}),e.jsx(ps,{onClick:mt,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})}),e.jsx(er,{})]})}function ac(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).substring(2,11)}`}function Um(a){return a===null?"null":Array.isArray(a)?"array":typeof a=="object"?"object":typeof a=="boolean"?"boolean":typeof a=="number"?"number":"string"}function Jm(a){return Object.entries(a).map(([n,r])=>{const c=Um(r),d={id:ac(),key:n,value:r,type:c,expanded:!0};return c==="object"&&r&&typeof r=="object"?d.children=Jm(r):c==="array"&&Array.isArray(r)&&(d.children=r.map((u,h)=>{const f=Um(u),p={id:ac(),key:String(h),value:u,type:f,expanded:!0};return f==="object"&&u&&typeof u=="object"?p.children=Jm(u):f==="array"&&Array.isArray(u)&&(p.children=u.map((g,N)=>({id:ac(),key:String(N),value:g,type:Um(g),expanded:!0}))),p})),d})}function Xm(a){const n={};for(const r of a)r.key.trim()&&(r.type==="object"&&r.children?n[r.key]=Xm(r.children):r.type==="array"&&r.children?n[r.key]=r.children.map(c=>c.type==="object"&&c.children?Xm(c.children):c.type==="array"&&c.children?c.children.map(d=>d.value):c.value):r.type==="null"?n[r.key]=null:n[r.key]=r.value);return n}function Pg(a,n){switch(n){case"boolean":return a==="true";case"number":{const r=parseFloat(a);return isNaN(r)?0:r}case"null":return null;default:return a}}function qv({node:a,level:n,onUpdate:r,onRemove:c,onAddChild:d,onToggleExpand:u}){const h=a.type==="object"||a.type==="array",f=a.children&&a.children.length>0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"grid gap-2 items-center",style:{gridTemplateColumns:h?"32px 1fr 90px 64px":"32px 1fr 1fr 90px 32px",paddingLeft:`${n*20}px`},children:[e.jsx(_,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>u(a.id),disabled:!h||!f,children:h&&f?a.expanded?e.jsx(za,{className:"h-4 w-4"}):e.jsx(Wt,{className:"h-4 w-4"}):e.jsx("span",{className:"w-4"})}),e.jsx(le,{value:a.key,onChange:p=>r(a.id,"key",p.target.value),placeholder:"key",className:"h-8 text-sm"}),!h&&e.jsx(e.Fragment,{children:a.type==="boolean"?e.jsxs("div",{className:"flex items-center h-8 px-3 border rounded-md bg-background",children:[e.jsx(Ve,{checked:a.value===!0,onCheckedChange:p=>r(a.id,"value",p)}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:a.value?"true":"false"})]}):a.type==="null"?e.jsx("div",{className:"flex items-center h-8 px-3 border rounded-md bg-muted text-sm text-muted-foreground",children:"null"}):e.jsx(le,{type:a.type==="number"?"number":"text",value:a.value,onChange:p=>r(a.id,"value",p.target.value),placeholder:"value",className:"h-8 text-sm",step:a.type==="number"?"any":void 0})}),e.jsxs(Ie,{value:a.type,onValueChange:p=>r(a.id,"type",p),children:[e.jsx(Be,{className:"h-8 text-xs",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"string",children:"字符串"}),e.jsx(W,{value:"number",children:"数字"}),e.jsx(W,{value:"boolean",children:"布尔"}),e.jsx(W,{value:"null",children:"Null"}),e.jsx(W,{value:"object",children:"对象"}),e.jsx(W,{value:"array",children:"数组"})]})]}),e.jsxs("div",{className:"flex gap-1 justify-end",children:[h&&e.jsx(_,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-primary",onClick:()=>d(a.id),title:"添加子项",children:e.jsx(et,{className:"h-4 w-4"})}),e.jsx(_,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>c(a.id),title:"删除",children:e.jsx(ns,{className:"h-4 w-4"})})]})]}),h&&a.expanded&&a.children&&a.children.length>0&&e.jsx("div",{className:"space-y-1",children:a.children.map(p=>e.jsx(qv,{node:p,level:n+1,onUpdate:r,onRemove:c,onAddChild:d,onToggleExpand:u},p.id))})]})}function US({value:a,onChange:n,placeholder:r="添加参数..."}){const[c,d]=m.useState(()=>Jm(a||{})),u=m.useCallback(v=>{d(v),n(Xm(v))},[n]),h=m.useCallback(()=>{const v={id:ac(),key:"",value:"",type:"string",expanded:!1};u([...c,v])},[c,u]),f=m.useCallback((v,w,b)=>{const y=A=>A.map(z=>{if(z.id===v)if(w==="type"){const S=b;if(S==="object")return{...z,type:S,value:{},children:[]};if(S==="array")return{...z,type:S,value:[],children:[]};if(S==="null")return{...z,type:S,value:null};{const U=Pg(String(z.value),S);return{...z,type:S,value:U,children:void 0}}}else if(w==="value"){const S=Pg(String(b),z.type);return{...z,value:S}}else return{...z,[w]:String(b)};return z.children?{...z,children:y(z.children)}:z});u(y(c))},[c,u]),p=m.useCallback(v=>{const w=b=>b.filter(y=>y.id!==v).map(y=>y.children?{...y,children:w(y.children)}:y);u(w(c))},[c,u]),g=m.useCallback(v=>{const w=b=>b.map(y=>{if(y.id===v){const A={id:ac(),key:y.type==="array"?String(y.children?.length||0):"",value:"",type:"string",expanded:!0};return{...y,children:[...y.children||[],A]}}return y.children?{...y,children:w(y.children)}:y});u(w(c))},[c,u]),N=m.useCallback(v=>{const w=b=>b.map(y=>y.id===v?{...y,expanded:!y.expanded}:y.children?{...y,children:w(y.children)}:y);d(w(c))},[c]);return e.jsxs("div",{className:"h-full flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[c.length," 个参数"]}),e.jsxs(_,{type:"button",size:"sm",variant:"outline",onClick:h,className:"h-7 text-xs",children:[e.jsx(et,{className:"h-3 w-3 mr-1"}),"添加参数"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto space-y-1",children:c.length===0?e.jsx("div",{className:"text-sm text-muted-foreground text-center py-4 border border-dashed rounded-md",children:r}):e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"grid gap-2 text-xs text-muted-foreground px-1 sticky top-0 bg-background z-10",style:{gridTemplateColumns:"32px 1fr 1fr 90px 32px"},children:[e.jsx("span",{}),e.jsx("span",{children:"键名"}),e.jsx("span",{children:"值"}),e.jsx("span",{children:"类型"}),e.jsx("span",{})]}),c.map(v=>e.jsx(qv,{node:v,level:0,onUpdate:f,onRemove:p,onAddChild:g,onToggleExpand:N},v.id))]})})]})}function Ig(a){if(!a.trim())return{valid:!0,parsed:{}};try{const n=JSON.parse(a);return typeof n!="object"||n===null||Array.isArray(n)?{valid:!1,error:"必须是一个 JSON 对象 {}"}:{valid:!0,parsed:n}}catch{return{valid:!1,error:"JSON 格式错误"}}}function $S({value:a,onChange:n,className:r,placeholder:c="添加额外参数..."}){const[d,u]=m.useState("list"),h=m.useMemo(()=>Object.keys(a||{}).length>0?JSON.stringify(a,null,2):"",[a]),[f,p]=m.useState(h),[g,N]=m.useState(null);m.useEffect(()=>{p(h)},[h]);const v=m.useMemo(()=>{const y=Ig(f);return y.valid&&y.parsed?{success:!0,data:y.parsed}:{success:!1,data:{}}},[f]),w=m.useCallback(y=>{const A=y;A==="json"&&d==="list"&&(p(Object.keys(a).length>0?JSON.stringify(a,null,2):""),N(null)),u(A)},[d,a]),b=m.useCallback(y=>{p(y);const A=Ig(y);A.valid&&A.parsed?(N(null),n(A.parsed)):N(A.error||"JSON 格式错误")},[n]);return e.jsx("div",{className:F("h-full flex flex-col",r),children:e.jsxs(ta,{value:d,onValueChange:w,className:"w-full flex-1 flex flex-col",children:[e.jsxs(Zt,{className:"h-8 p-0.5 bg-muted/60 w-fit",children:[e.jsx(Xe,{value:"list",className:"h-7 px-3 text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"可视化编辑"}),e.jsx(Xe,{value:"json",className:"h-7 px-3 text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"JSON 编辑"})]}),e.jsx(ws,{value:"list",className:"mt-2 flex-1 flex flex-col overflow-hidden data-[state=inactive]:hidden data-[state=inactive]:h-0",children:e.jsx(US,{value:a,onChange:n,placeholder:c})}),e.jsx(ws,{value:"json",className:"mt-2 flex-1 flex flex-col overflow-hidden data-[state=inactive]:hidden data-[state=inactive]:h-0",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col gap-2 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"编辑"}),g?e.jsxs("div",{className:"flex items-center gap-1 text-xs text-destructive",children:[e.jsx(_t,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate max-w-[150px]",children:g})]}):f.trim()&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-green-600 dark:text-green-400",children:[e.jsx(Ct,{className:"h-3 w-3"}),e.jsx("span",{children:"有效"})]})]}),e.jsx(ot,{value:f,onChange:y=>b(y.target.value),placeholder:`{ + "key": "value" +}`,className:F("font-mono text-sm flex-1 resize-none",g&&"border-destructive focus-visible:ring-destructive")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"支持任意 JSON 类型(包括嵌套对象和数组)"})]}),e.jsxs("div",{className:"flex flex-col gap-2 overflow-hidden",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"预览"}),e.jsx("div",{className:"flex-1 rounded-md border bg-muted/30 p-3 overflow-auto",children:v.success&&Object.keys(v.data).length>0?e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-words",children:JSON.stringify(v.data,null,2)}):v.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 BS({open:a,onOpenChange:n,value:r,onChange:c}){const[d,u]=m.useState(r),h=g=>{g&&u(r),n(g)},f=()=>{c(d),n(!1)},p=()=>{u(r),n(!1)};return e.jsx(Ps,{open:a,onOpenChange:h,children:e.jsxs(Ds,{className:"max-w-3xl h-[70vh] flex flex-col",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑额外参数"}),e.jsx(Ks,{children:"配置模型调用时的额外参数,支持嵌套对象和数组"})]}),e.jsx("div",{className:"flex-1 overflow-hidden min-h-0",children:e.jsx($S,{value:d,onChange:u,placeholder:"添加额外参数(如 thinking、top_p 等)..."})}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:p,children:"取消"}),e.jsx(_,{onClick:f,children:"保存"})]})]})})}const ei="https://maibot-plugin-stats.maibot-webui.workers.dev";async function PS(a){const n=new URLSearchParams;a?.status&&n.set("status",a.status),a?.page&&n.set("page",a.page.toString()),a?.page_size&&n.set("page_size",a.page_size.toString()),a?.search&&n.set("search",a.search),a?.sort_by&&n.set("sort_by",a.sort_by),a?.sort_order&&n.set("sort_order",a.sort_order);const r=await fetch(`${ei}/pack?${n.toString()}`);if(!r.ok)throw new Error(`获取 Pack 列表失败: ${r.status}`);return r.json()}async function IS(a){const n=await fetch(`${ei}/pack/${a}`);if(!n.ok)throw new Error(`获取 Pack 失败: ${n.status}`);const r=await n.json();if(!r.success)throw new Error(r.error||"获取 Pack 失败");return r.pack}async function FS(a){const r=await(await fetch(`${ei}/pack`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})).json();if(!r.success)throw new Error(r.error||"创建 Pack 失败");return r}async function HS(a,n){await fetch(`${ei}/pack/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pack_id:a,user_id:n})})}async function Kv(a,n){const c=await(await fetch(`${ei}/pack/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pack_id:a,user_id:n})})).json();if(!c.success)throw new Error(c.error||"点赞失败");return{likes:c.likes,liked:c.liked}}async function Qv(a,n){return(await(await fetch(`${ei}/pack/like/check?pack_id=${a}&user_id=${n}`)).json()).liked||!1}async function VS(a){const n=await _e("/api/webui/config/model");if(!n.ok)throw new Error("获取当前模型配置失败");const r=await n.json(),c=r.config||r;console.log("=== Pack Conflict Detection ==="),console.log("Pack providers:",a.providers),console.log("Local providers:",c.api_providers);const d={existing_providers:[],new_providers:[],conflicting_models:[]},u=c.api_providers||[];for(const f of a.providers){console.log(` +Checking pack provider: ${f.name}`),console.log(` Pack URL: ${f.base_url}`),console.log(` Normalized: ${$m(f.base_url)}`);const p=u.filter(g=>{const N=$m(g.base_url),v=$m(f.base_url);return console.log(` Comparing with local "${g.name}": ${g.base_url}`),console.log(` Local normalized: ${N}`),console.log(` Match: ${N===v}`),N===v});p.length>0?(console.log(` ✓ Matched with ${p.length} local provider(s):`,p.map(g=>g.name).join(", ")),d.existing_providers.push({pack_provider:f,local_providers:p.map(g=>({name:g.name,base_url:g.base_url}))})):(console.log(" ✗ No match found - will need API key"),d.new_providers.push(f))}const h=c.models||[];console.log(` +=== Model Conflict Detection ===`);for(const f of a.models){const p=h.find(g=>g.name===f.name);p&&(console.log(`Model conflict: ${f.name}`),d.conflicting_models.push({pack_model:f.name,local_model:p.name}))}return console.log(` +=== Detection Summary ===`),console.log(`Existing providers: ${d.existing_providers.length}`),console.log(`New providers: ${d.new_providers.length}`),console.log(`Conflicting models: ${d.conflicting_models.length}`),console.log(`=========================== +`),d}async function GS(a,n,r,c){const d=await _e("/api/webui/config/model");if(!d.ok)throw new Error("获取当前模型配置失败");const u=await d.json(),h=u.config||u;if(n.apply_providers){const p=n.selected_providers?a.providers.filter(g=>n.selected_providers.includes(g.name)):a.providers;for(const g of p){if(r[g.name])continue;const N=c[g.name];if(!N)throw new Error(`提供商 "${g.name}" 缺少 API Key`);const v={...g,api_key:N},w=h.api_providers.findIndex(b=>b.name===g.name);w>=0?h.api_providers[w]=v:h.api_providers.push(v)}}if(n.apply_models){const p=n.selected_models?a.models.filter(g=>n.selected_models.includes(g.name)):a.models;for(const g of p){const N=r[g.api_provider]||g.api_provider,v={...g,api_provider:N},w=h.models.findIndex(b=>b.name===g.name);w>=0?h.models[w]=v:h.models.push(v)}}if(n.apply_task_config){const p=n.selected_tasks||Object.keys(a.task_config);for(const g of p){const N=a.task_config[g];if(!N)continue;const v=new Set(n.selected_models||a.models.map(y=>y.name)),w=N.model_list.filter(y=>v.has(y));if(w.length===0)continue;const b={...N,model_list:w};if(n.task_mode==="replace")h.model_task_config[g]=b;else{const y=h.model_task_config[g];if(y){const A=[...new Set([...y.model_list,...w])];h.model_task_config[g]={...y,model_list:A}}else h.model_task_config[g]=b}}}if(!(await _e("/api/webui/config/model",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)})).ok)throw new Error("保存配置失败")}async function qS(a){const n=await _e("/api/webui/config/model");if(!n.ok)throw new Error("获取当前模型配置失败");const r=await n.json();if(!r.success||!r.config)throw new Error("获取配置失败");const c=r.config;let d=(c.api_providers||[]).map(g=>({name:g.name,base_url:g.base_url,client_type:g.client_type,max_retry:g.max_retry,timeout:g.timeout,retry_interval:g.retry_interval}));a.selectedProviders&&(d=d.filter(g=>a.selectedProviders.includes(g.name)));let u=c.models||[];a.selectedModels&&(u=u.filter(g=>a.selectedModels.includes(g.name)));const h={},f=c.model_task_config||{},p=a.selectedTasks||Object.keys(f);for(const g of p)f[g]&&(h[g]=f[g]);return{providers:d,models:u,task_config:h}}function $m(a){try{const n=new URL(a);return`${n.protocol}//${n.host}${n.pathname}`.replace(/\/$/,"").toLowerCase()}catch{return a.toLowerCase().replace(/\/$/,"")}}function Yv(){const a="maibot_pack_user_id";let n=localStorage.getItem(a);return n||(n="pack_user_"+Math.random().toString(36).substring(2,15),localStorage.setItem(a,n)),n}const KS={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",lpmm_qa:"问答模型"},QS=["官方推荐","性价比","高性能","免费模型","国内可用","海外模型","OpenAI","Claude","Gemini","国产模型","多模态","轻量级"];function YS({trigger:a}){const[n,r]=m.useState(!1),[c,d]=m.useState(1),[u,h]=m.useState(!1),[f,p]=m.useState(!1),[g,N]=m.useState([]),[v,w]=m.useState([]),[b,y]=m.useState({}),[A,z]=m.useState(new Set),[S,U]=m.useState(new Set),[E,C]=m.useState(new Set),[D,I]=m.useState(""),[O,X]=m.useState(""),[L,oe]=m.useState(""),[Ne,je]=m.useState([]);m.useEffect(()=>{n&&c===1&&de()},[n,c]);const de=async()=>{h(!0);try{const q=await qS({name:"",description:"",author:""});N(q.providers),w(q.models),y(q.task_config),z(new Set(q.providers.map(B=>B.name))),U(new Set(q.models.map(B=>B.name))),C(new Set(Object.keys(q.task_config)))}catch(q){console.error("加载配置失败:",q),Qt({title:"加载当前配置失败",variant:"destructive"})}finally{h(!1)}},he=q=>{const B=new Set(A),M=new Set(S),Q=new Set(E);B.has(q)?(B.delete(q),v.filter(ee=>ee.api_provider===q).forEach(ee=>M.delete(ee.name)),Object.entries(b).forEach(([ee,J])=>{J.model_list&&(J.model_list.some(H=>M.has(H))||Q.delete(ee))})):(B.add(q),v.filter(ee=>ee.api_provider===q).forEach(ee=>M.add(ee.name)),Object.entries(b).forEach(([ee,J])=>{J.model_list&&J.model_list.some(H=>{const se=v.find(Ue=>Ue.name===H);return se&&se.api_provider===q})&&Q.add(ee)})),z(B),U(M),C(Q)},ge=q=>{const B=new Set(S),M=new Set(E);B.has(q)?(B.delete(q),Object.entries(b).forEach(([Q,Ae])=>{Ae.model_list&&(Ae.model_list.some(J=>B.has(J))||M.delete(Q))})):(B.add(q),Object.entries(b).forEach(([Q,Ae])=>{Ae.model_list&&Ae.model_list.includes(q)&&M.add(Q)})),U(B),C(M)},R=q=>{const B=new Set(E);B.has(q)?B.delete(q):B.add(q),C(B)},Y=q=>{Ne.includes(q)?je(Ne.filter(B=>B!==q)):Ne.length<5?je([...Ne,q]):Qt({title:"最多选择 5 个标签",variant:"destructive"})},$=()=>{A.size===g.length?z(new Set):z(new Set(g.map(q=>q.name)))},ue=()=>{S.size===v.length?U(new Set):U(new Set(v.map(q=>q.name)))},G=()=>{const q=Object.keys(b);E.size===q.length?C(new Set):C(new Set(q))},Se=async()=>{if(!D.trim()){Qt({title:"请输入模板名称",variant:"destructive"});return}if(!O.trim()){Qt({title:"请输入模板描述",variant:"destructive"});return}if(!L.trim()){Qt({title:"请输入作者名称",variant:"destructive"});return}if(A.size===0&&S.size===0&&E.size===0){Qt({title:"请至少选择一项配置",variant:"destructive"});return}p(!0);try{const q=g.filter(Q=>A.has(Q.name)),B=v.filter(Q=>S.has(Q.name)),M={};for(const[Q,Ae]of Object.entries(b))E.has(Q)&&(M[Q]=Ae);await FS({name:D.trim(),description:O.trim(),author:L.trim(),tags:Ne,providers:q,models:B,task_config:M}),Qt({title:"模板已提交审核,审核通过后将显示在市场中"}),r(!1),fe()}catch(q){console.error("提交失败:",q),Qt({title:q instanceof Error?q.message:"提交失败",variant:"destructive"})}finally{p(!1)}},fe=()=>{d(1),I(""),X(""),oe(""),je([]),z(new Set),U(new Set),C(new Set)},Te=2;return e.jsxs(Ps,{open:n,onOpenChange:r,children:[e.jsx(cd,{asChild:!0,children:a||e.jsxs(_,{variant:"outline",children:[e.jsx(nv,{className:"w-4 h-4 mr-2"}),"分享配置"]})}),e.jsxs(Ds,{className:"max-w-2xl max-h-[85vh] flex flex-col",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(ra,{className:"w-5 h-5"}),"分享配置模板"]}),e.jsxs(Ks,{children:["步骤 ",c," / ",Te,":",c===1&&"选择要分享的配置",c===2&&"填写模板信息"]})]}),e.jsx(Je,{className:"h-[calc(85vh-220px)] pr-4",children:u?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(zs,{className:"w-8 h-8 mx-auto animate-spin text-primary"}),e.jsx("p",{className:"mt-4 text-muted-foreground",children:"正在加载当前配置..."})]}):e.jsxs(e.Fragment,{children:[c===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(Gn,{children:"安全提示"}),e.jsxs(lt,{children:["分享的配置将",e.jsx("strong",{children:"不包含"})," API Key,其他用户需要自行配置。"]})]}),e.jsxs(ta,{defaultValue:"providers",className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-3",children:[e.jsxs(Xe,{value:"providers",children:[e.jsx(Ll,{className:"w-4 h-4 mr-2"}),"API 提供商",e.jsxs(ke,{variant:"secondary",className:"ml-2",children:[A.size,"/",g.length]})]}),e.jsxs(Xe,{value:"models",children:[e.jsx(Qn,{className:"w-4 h-4 mr-2"}),"模型配置",e.jsxs(ke,{variant:"secondary",className:"ml-2",children:[S.size,"/",v.length]})]}),e.jsxs(Xe,{value:"tasks",children:[e.jsx(Yn,{className:"w-4 h-4 mr-2"}),"任务配置",e.jsxs(ke,{variant:"secondary",className:"ml-2",children:[E.size,"/",Object.keys(b).length]})]})]}),e.jsx(ws,{value:"providers",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:$,children:A.size===g.length?"取消全选":"全选"})}),g.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无提供商配置"}):g.map(q=>e.jsxs("div",{className:"flex items-center space-x-2 p-2 rounded hover:bg-muted",children:[e.jsx(qs,{id:`provider-${q.name}`,checked:A.has(q.name),onCheckedChange:()=>he(q.name)}),e.jsxs(T,{htmlFor:`provider-${q.name}`,className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:q.name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:q.base_url})]}),e.jsx(ke,{variant:"outline",className:"text-xs",children:q.client_type})]},q.name))]})}),e.jsx(ws,{value:"models",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:ue,children:S.size===v.length?"取消全选":"全选"})}),v.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无模型配置"}):v.map(q=>e.jsxs("div",{className:"flex items-center space-x-2 p-2 rounded hover:bg-muted",children:[e.jsx(qs,{id:`model-${q.name}`,checked:S.has(q.name),onCheckedChange:()=>ge(q.name)}),e.jsxs(T,{htmlFor:`model-${q.name}`,className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:q.name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:q.model_identifier})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:q.api_provider})]},q.name))]})}),e.jsx(ws,{value:"tasks",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:G,children:E.size===Object.keys(b).length?"取消全选":"全选"})}),Object.keys(b).length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无任务配置"}):Object.entries(b).map(([q,B])=>e.jsxs("div",{className:"space-y-2 p-2 rounded hover:bg-muted",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:`task-${q}`,checked:E.has(q),onCheckedChange:()=>R(q)}),e.jsx(T,{htmlFor:`task-${q}`,className:"flex-1 cursor-pointer",children:e.jsx("span",{className:"font-medium",children:KS[q]||q})}),e.jsxs(ke,{variant:"outline",className:"text-xs",children:[B.model_list.length," 个模型"]})]}),B.model_list&&B.model_list.length>0&&e.jsx("div",{className:"ml-6 flex flex-wrap gap-1",children:B.model_list.map(M=>{const Q=v.find(ee=>ee.name===M),Ae=S.has(M);return e.jsxs(ke,{variant:Ae?"default":"outline",className:"text-xs cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>ge(M),children:[M,Q&&e.jsxs("span",{className:"ml-1 opacity-70",children:["(",Q.api_provider,")"]})]},M)})})]},q))]})})]})]}),c===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-4 text-sm p-3 bg-muted rounded-lg",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ll,{className:"w-4 h-4"}),A.size," 个提供商"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Qn,{className:"w-4 h-4"}),S.size," 个模型"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Yn,{className:"w-4 h-4"}),E.size," 个任务"]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-name",children:"模板名称 *"}),e.jsx(le,{id:"pack-name",placeholder:"例如:高性价比国产模型配置",value:D,onChange:q=>I(q.target.value),maxLength:50}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[D.length,"/50"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-description",children:"模板描述 *"}),e.jsx(ot,{id:"pack-description",placeholder:"详细描述这个配置模板的特点、适用场景等...",value:O,onChange:q=>X(q.target.value),rows:4,maxLength:500}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[O.length,"/500"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-author",children:"作者名称 *"}),e.jsx(le,{id:"pack-author",placeholder:"你的昵称或 ID",value:L,onChange:q=>oe(q.target.value),maxLength:30})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"标签(可选,最多 5 个)"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:QS.map(q=>e.jsxs(ke,{variant:Ne.includes(q)?"default":"outline",className:"cursor-pointer transition-colors",onClick:()=>Y(q),children:[Ne.includes(q)&&e.jsx(Ct,{className:"w-3 h-3 mr-1"}),e.jsx(rd,{className:"w-3 h-3 mr-1"}),q]},q))})]})]}),e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(Gn,{children:"审核说明"}),e.jsx(lt,{children:"提交后需要经过审核才能在市场中展示。审核通常在 1-3 个工作日内完成。"})]})]})]})}),e.jsxs(st,{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:c>1&&e.jsx(_,{variant:"outline",onClick:()=>d(c-1),disabled:f,children:"上一步"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_,{variant:"outline",onClick:()=>{r(!1),fe()},disabled:f,children:"取消"}),cd(c+1),disabled:u||A.size===0&&S.size===0&&E.size===0,children:"下一步"}):e.jsxs(_,{onClick:Se,disabled:f,children:[f&&e.jsx(zs,{className:"w-4 h-4 mr-2 animate-spin"}),"提交审核"]})]})]})]})]})}function JS({value:a,label:n,onRemove:r}){const{attributes:c,listeners:d,setNodeRef:u,transform:h,transition:f,isDragging:p}=Nv({id:a}),g={transform:bv.Transform.toString(h),transition:f,opacity:p?.5:1},N=w=>{w.preventDefault(),w.stopPropagation(),r(a)},v=w=>{w.stopPropagation()};return e.jsx("div",{ref:u,style:g,className:F("inline-flex items-center gap-1",p&&"shadow-lg"),children:e.jsxs(ke,{variant:"secondary",className:"cursor-move hover:bg-secondary/80 flex items-center gap-1",children:[e.jsx("div",{...c,...d,className:"cursor-grab active:cursor-grabbing flex items-center",children:e.jsx(tv,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx("span",{children:n}),e.jsx("span",{role:"button",tabIndex:0,className:"ml-1 rounded-sm hover:bg-destructive/20 focus:outline-none focus:ring-1 focus:ring-destructive cursor-pointer",onClick:N,onPointerDown:v,onMouseDown:w=>w.stopPropagation(),onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),N(w))},children:e.jsx(Aa,{className:"h-3 w-3 hover:text-destructive",strokeWidth:2,fill:"none"})})]})})}function XS({options:a,selected:n,onChange:r,placeholder:c="选择选项...",emptyText:d="未找到选项",className:u}){const[h,f]=m.useState(!1),p=mv(qo(fv,{activationConstraint:{distance:8}}),qo(hv,{coordinateGetter:xv})),g=w=>{n.includes(w)?r(n.filter(b=>b!==w)):r([...n,w])},N=w=>{r(n.filter(b=>b!==w))},v=w=>{const{active:b,over:y}=w;if(y&&b.id!==y.id){const A=n.indexOf(b.id),z=n.indexOf(y.id);r(pv(n,A,z))}};return e.jsxs(ul,{open:h,onOpenChange:f,children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",role:"combobox","aria-expanded":h,className:F("w-full justify-between min-h-10 h-auto",u),children:[e.jsx(gv,{sensors:p,collisionDetection:jv,onDragEnd:v,children:e.jsx(vv,{items:n,strategy:o1,children:e.jsx("div",{className:"flex gap-1 flex-wrap flex-1",children:n.length===0?e.jsx("span",{className:"text-muted-foreground",children:c}):n.map(w=>{const b=a.find(y=>y.value===w);return e.jsx(JS,{value:w,label:b?.label||w,onRemove:N},w)})})})}),e.jsx(rx,{className:"ml-2 h-4 w-4 shrink-0 opacity-50",strokeWidth:2,fill:"none"})]})}),e.jsx(sl,{className:"w-full p-0",align:"start",children:e.jsxs(dd,{children:[e.jsx(ud,{placeholder:"搜索...",className:"h-9"}),e.jsxs(md,{children:[e.jsx(xd,{children:d}),e.jsx(oc,{children:a.map(w=>{const b=n.includes(w.value);return e.jsxs(dc,{value:w.value,onSelect:()=>g(w.value),children:[e.jsx("div",{className:F("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",b?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ct,{className:"h-3 w-3",strokeWidth:2,fill:"none"})}),e.jsx("span",{children:w.label})]},w.value)})})]})]})})]})}const zl=Rs.memo(function({title:n,description:r,taskConfig:c,modelNames:d,onChange:u,hideTemperature:h=!1,hideMaxTokens:f=!1,dataTour:p}){const g=N=>{u("model_list",N)};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-base sm:text-lg",children:n}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:r})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":p,children:[e.jsx(T,{children:"模型列表"}),e.jsx(XS,{options:d.map(N=>({label:N,value:N})),selected:c.model_list||[],onChange:g,placeholder:"选择模型...",emptyText:"暂无可用模型"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[!h&&e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"温度"}),e.jsx(le,{type:"number",step:"0.1",min:"0",max:"1",value:c.temperature??.3,onChange:N=>{const v=parseFloat(N.target.value);!isNaN(v)&&v>=0&&v<=1&&u("temperature",v)},className:"w-20 h-8 text-sm"})]}),e.jsx(Qa,{value:[c.temperature??.3],onValueChange:N=>u("temperature",N[0]),min:0,max:1,step:.1,className:"w-full"})]}),!f&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"最大 Token"}),e.jsx(le,{type:"number",step:"1",min:"1",value:c.max_tokens??1024,onChange:N=>u("max_tokens",parseInt(N.target.value))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"慢请求阈值 (秒)"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"超时警告"})]}),e.jsx(le,{type:"number",step:"1",min:"1",value:c.slow_threshold??15,onChange:N=>{const v=parseInt(N.target.value);!isNaN(v)&&v>=1&&u("slow_threshold",v)},placeholder:"15"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"模型响应时间超过此阈值将输出警告日志"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"模型选择策略"}),e.jsxs(Ie,{value:c.selection_strategy??"balance",onValueChange:N=>u("selection_strategy",N),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择模型选择策略"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"balance",children:"负载均衡(balance)"}),e.jsx(W,{value:"random",children:"随机选择(random)"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"负载均衡:优先选择使用次数少的模型。随机选择:完全随机从模型列表中选择"})]})]})]})}),ZS=Rs.memo(function({paginatedModels:n,allModels:r,onEdit:c,onDelete:d,isModelUsed:u,searchQuery:h}){return n.length===0?e.jsx("div",{className:"md:hidden text-center text-muted-foreground py-8 rounded-lg border bg-card",children:h?"未找到匹配的模型":"暂无模型配置"}):e.jsx("div",{className:"md:hidden space-y-3",children:n.map((f,p)=>{const g=r.findIndex(v=>v===f),N=u(f.name);return e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold text-base",children:f.name}),e.jsx(ke,{variant:N?"default":"secondary",className:N?"bg-green-600 hover:bg-green-700":"",children:N?"已使用":"未使用"})]}),e.jsx("p",{className:"text-xs text-muted-foreground break-all",title:f.model_identifier,children:f.model_identifier})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>c(f,g),children:[e.jsx(Kn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>d(g),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"提供商"}),e.jsx("p",{className:"font-medium",children:f.api_provider})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"模型温度"}),e.jsx("p",{className:"font-medium",children:f.temperature!=null?f.temperature:e.jsx("span",{className:"text-muted-foreground",children:"默认"})})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输入价格"}),e.jsxs("p",{className:"font-medium",children:["¥",f.price_in,"/M"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输出价格"}),e.jsxs("p",{className:"font-medium",children:["¥",f.price_out,"/M"]})]})]})]},p)})})}),WS=Rs.memo(function({paginatedModels:n,allModels:r,filteredModels:c,selectedModels:d,onEdit:u,onDelete:h,onToggleSelection:f,onToggleSelectAll:p,isModelUsed:g,searchQuery:N}){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(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:d.size===c.length&&c.length>0,onCheckedChange:p})}),e.jsx(We,{className:"w-24",children:"使用状态"}),e.jsx(We,{children:"模型名称"}),e.jsx(We,{children:"模型标识符"}),e.jsx(We,{children:"提供商"}),e.jsx(We,{className:"text-center",children:"温度"}),e.jsx(We,{className:"text-right",children:"输入价格"}),e.jsx(We,{className:"text-right",children:"输出价格"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:n.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:9,className:"text-center text-muted-foreground py-8",children:N?"未找到匹配的模型":"暂无模型配置"})}):n.map((v,w)=>{const b=r.findIndex(A=>A===v),y=g(v.name);return e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(qs,{checked:d.has(b),onCheckedChange:()=>f(b)})}),e.jsx(Ke,{children:e.jsx(ke,{variant:y?"default":"secondary",className:y?"bg-green-600 hover:bg-green-700":"",children:y?"已使用":"未使用"})}),e.jsx(Ke,{className:"font-medium",children:v.name}),e.jsx(Ke,{className:"max-w-xs truncate",title:v.model_identifier,children:v.model_identifier}),e.jsx(Ke,{children:v.api_provider}),e.jsx(Ke,{className:"text-center",children:v.temperature!=null?v.temperature:e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsxs(Ke,{className:"text-right",children:["¥",v.price_in,"/M"]}),e.jsxs(Ke,{className:"text-right",children:["¥",v.price_out,"/M"]}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>u(v,b),children:[e.jsx(Kn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>h(b),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},w)})})]})})})}),e4=300*1e3,Fg=new Map,s4=[10,20,50,100],t4=Rs.memo(function({page:n,pageSize:r,totalItems:c,jumpToPage:d,onPageChange:u,onPageSizeChange:h,onJumpToPageChange:f,onJumpToPage:p,onSelectionClear:g}){const N=Math.ceil(c/r),v=b=>{h(parseInt(b)),u(1),g?.()},w=b=>{b.key==="Enter"&&p()};return c===0?null:e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{htmlFor:"page-size-model",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ie,{value:r.toString(),onValueChange:v,children:[e.jsx(Be,{id:"page-size-model",className:"w-20",children:e.jsx(Fe,{})}),e.jsx(Pe,{children:s4.map(b=>e.jsx(W,{value:b.toString(),children:b},b))})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(n-1)*r+1," 到"," ",Math.min(n*r,c)," 条,共 ",c," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>u(1),disabled:n===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>u(Math.max(1,n-1)),disabled:n===1,children:[e.jsx(Da,{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(le,{type:"number",value:d,onChange:b=>f(b.target.value),onKeyDown:w,placeholder:n.toString(),className:"w-16 h-8 text-center",min:1,max:N}),e.jsx(_,{variant:"outline",size:"sm",onClick:p,disabled:!d,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>u(n+1),disabled:n>=N,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>u(N),disabled:n>=N,className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})});function a4(a){const{models:n,taskConfig:r,debounceMs:c=2e3,onSavingChange:d,onUnsavedChange:u}=a,h=m.useRef(null),f=m.useRef(null),p=m.useRef(!0),g=m.useCallback(()=>{h.current&&(clearTimeout(h.current),h.current=null),f.current&&(clearTimeout(f.current),f.current=null)},[]),N=m.useCallback(b=>{const y={model_identifier:b.model_identifier,name:b.name,api_provider:b.api_provider,price_in:b.price_in??0,price_out:b.price_out??0,force_stream_mode:b.force_stream_mode??!1,extra_params:b.extra_params??{}};return b.temperature!=null&&(y.temperature=b.temperature),b.max_tokens!=null&&(y.max_tokens=b.max_tokens),y},[]),v=m.useCallback(async b=>{try{d?.(!0);const y=b.map(N);await Ym("models",y),u?.(!1)}catch(y){console.error("自动保存模型列表失败:",y),u?.(!0)}finally{d?.(!1)}},[d,u,N]),w=m.useCallback(async b=>{try{d?.(!0),await Ym("model_task_config",b),u?.(!1)}catch(y){console.error("自动保存任务配置失败:",y),u?.(!0)}finally{d?.(!1)}},[d,u]);return m.useEffect(()=>{if(!p.current)return u?.(!0),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{v(n)},c),()=>{h.current&&clearTimeout(h.current)}},[n,v,c,u]),m.useEffect(()=>{if(!(p.current||!r))return u?.(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{w(r)},c),()=>{f.current&&clearTimeout(f.current)}},[r,w,c,u]),m.useEffect(()=>()=>{g()},[g]),{clearTimers:g,initialLoadRef:p}}function l4(a={}){const{onCloseEditDialog:n}=a,r=ca(),{registerTour:c,startTour:d,state:u,goToStep:h}=px(),f=m.useRef(u.stepIndex);return m.useEffect(()=>{c(ol,Vv)},[c]),m.useEffect(()=>{if(u.activeTourId===ol&&u.isRunning){const g=Gv[u.stepIndex];g&&!window.location.pathname.endsWith(g.replace("/config/",""))&&r({to:g})}},[u.stepIndex,u.activeTourId,u.isRunning,r]),m.useEffect(()=>{if(u.activeTourId===ol&&u.isRunning){const g=f.current,N=u.stepIndex;g>=12&&g<=17&&N<12&&n?.(),f.current=N}},[u.stepIndex,u.activeTourId,u.isRunning,n]),m.useEffect(()=>{if(u.activeTourId!==ol||!u.isRunning)return;const g=N=>{const v=N.target,w=u.stepIndex;w===2&&v.closest('[data-tour="add-provider-button"]')?setTimeout(()=>h(3),300):w===9&&v.closest('[data-tour="provider-cancel-button"]')?setTimeout(()=>h(10),300):w===11&&v.closest('[data-tour="add-model-button"]')?setTimeout(()=>h(12),300):w===17&&v.closest('[data-tour="model-cancel-button"]')?setTimeout(()=>h(18),300):w===18&&v.closest('[data-tour="tasks-tab-trigger"]')&&setTimeout(()=>h(19),300)};return document.addEventListener("click",g,!0),()=>document.removeEventListener("click",g,!0)},[u,h]),{startTour:m.useCallback(()=>{d(ol)},[d]),isRunning:u.isRunning&&u.activeTourId===ol,stepIndex:u.stepIndex}}function n4(a){const{getProviderConfig:n}=a,[r,c]=m.useState([]),[d,u]=m.useState(!1),[h,f]=m.useState(null),[p,g]=m.useState(null),N=m.useCallback(()=>{c([]),f(null),g(null)},[]),v=m.useCallback(async(w,b=!1)=>{const y=n(w);if(!y?.base_url){c([]),g(null),f('提供商配置不完整,请先在"模型提供商配置"中配置');return}if(!y.api_key){c([]),g(null),f('该提供商未配置 API Key,请先在"模型提供商配置"中填写');return}const A=RS(y.base_url);if(g(A),!A?.modelFetcher){c([]),f(null);return}const z=`${w}:${y.base_url}`,S=Fg.get(z);if(!b&&S&&Date.now()-S.timestampE(!1)}),{clearTimers:Ht,initialLoadRef:mt}=a4({models:a,taskConfig:p,onSavingChange:A,onUnsavedChange:S}),K=m.useCallback((re,pe)=>{if(!re)return;const ts=new Set(pe.map(va=>va.name)),js=[],is=[],jt=[{key:"utils",label:"工具模型"},{key:"tool_use",label:"工具调用模型"},{key:"replyer",label:"回复模型"},{key:"planner",label:"规划器模型"},{key:"vlm",label:"视觉模型"},{key:"voice",label:"语音模型"},{key:"embedding",label:"嵌入模型"},{key:"lpmm_entity_extract",label:"LPMM实体抽取"},{key:"lpmm_rdf_build",label:"LPMM关系构建"}];for(const{key:va,label:Il}of jt){const tr=re[va];if(!tr)continue;if(!tr.model_list||tr.model_list.length===0){is.push(Il);continue}const ti=tr.model_list.filter(_n=>!ts.has(_n));ti.length>0&&js.push({taskName:Il,invalidModels:ti})}se(js),ie(is)},[]),qe=m.useCallback(async()=>{try{v(!0);const re=await xn(),pe=re.models||[];n(pe),f(pe.map(jt=>jt.name));const ts=re.api_providers||[];c(ts.map(jt=>jt.name)),u(ts);const js=re.model_task_config||null;g(js),K(js,pe);const is=js?.embedding?.model_list||[];J.current=[...is],S(!1),mt.current=!1}catch(re){console.error("加载配置失败:",re)}finally{v(!1)}},[mt,K]);m.useEffect(()=>{qe()},[qe]);const Qe=m.useCallback(re=>d.find(pe=>pe.name===re),[d]),{availableModels:es,fetchingModels:Us,modelFetchError:as,matchedTemplate:Cs,fetchModelsForProvider:Re,clearModels:bs}=n4({getProviderConfig:Qe});m.useEffect(()=>{U&&C?.api_provider&&Re(C.api_provider)},[U,C?.api_provider,Re]);const ls=async()=>{await rs()},ss=m.useCallback(()=>{if(!p)return;const re=new Set(a.map(js=>js.name)),pe={...p},ts=Object.keys(pe);for(const js of ts){const is=pe[js];is&&is.model_list&&(is.model_list=is.model_list.filter(jt=>re.has(jt)))}g(pe),se([]),ze({title:"清理完成",description:"已删除所有无效的模型引用"})},[p,a,ze]),ys=re=>{const pe={model_identifier:re.model_identifier,name:re.name,api_provider:re.api_provider,price_in:re.price_in??0,price_out:re.price_out??0,force_stream_mode:re.force_stream_mode??!1,extra_params:re.extra_params??{}};return re.temperature!=null&&(pe.temperature=re.temperature),re.max_tokens!=null&&(pe.max_tokens=re.max_tokens),pe},gt=async()=>{try{b(!0),Ht();const re=await xn();re.models=a.map(ys),re.model_task_config=p,await tc(re),S(!1),ze({title:"保存成功",description:"正在重启麦麦..."}),await ls()}catch(re){console.error("保存配置失败:",re),ze({title:"保存失败",description:re.message,variant:"destructive"}),b(!1)}},$t=async()=>{try{b(!0),Ht();const re=await xn();re.models=a.map(ys),re.model_task_config=p,await tc(re),S(!1),ze({title:"保存成功",description:"模型配置已保存"}),await qe()}catch(re){console.error("保存配置失败:",re),ze({title:"保存失败",description:re.message,variant:"destructive"})}finally{b(!1)}},tt=(re,pe)=>{me({}),D(re||{model_identifier:"",name:"",api_provider:r[0]||"",price_in:0,price_out:0,temperature:null,max_tokens:null,force_stream_mode:!1,extra_params:{}}),O(pe),E(!0)},Ms=()=>{if(!C)return;const re={};if(C.name?.trim()?a.some((jt,va)=>I!==null&&va===I?!1:jt.name.trim().toLowerCase()===C.name.trim().toLowerCase())&&(re.name="模型名称已存在,请使用其他名称"):re.name="请输入模型名称",C.api_provider?.trim()||(re.api_provider="请选择 API 提供商"),C.model_identifier?.trim()||(re.model_identifier="请输入模型标识符"),Object.keys(re).length>0){me(re);return}me({});const pe={model_identifier:C.model_identifier,name:C.name,api_provider:C.api_provider,price_in:C.price_in??0,price_out:C.price_out??0,force_stream_mode:C.force_stream_mode??!1,extra_params:C.extra_params??{}};C.temperature!=null&&(pe.temperature=C.temperature),C.max_tokens!=null&&(pe.max_tokens=C.max_tokens);let ts,js=null;if(I!==null?(js=a[I].name,ts=[...a],ts[I]=pe):ts=[...a,pe],n(ts),f(ts.map(is=>is.name)),js&&js!==pe.name&&p){const is=jt=>jt.map(va=>va===js?pe.name:va);g({...p,utils:{...p.utils,model_list:is(p.utils?.model_list||[])},tool_use:{...p.tool_use,model_list:is(p.tool_use?.model_list||[])},replyer:{...p.replyer,model_list:is(p.replyer?.model_list||[])},planner:{...p.planner,model_list:is(p.planner?.model_list||[])},vlm:{...p.vlm,model_list:is(p.vlm?.model_list||[])},voice:{...p.voice,model_list:is(p.voice?.model_list||[])},embedding:{...p.embedding,model_list:is(p.embedding?.model_list||[])},lpmm_entity_extract:{...p.lpmm_entity_extract,model_list:is(p.lpmm_entity_extract?.model_list||[])},lpmm_rdf_build:{...p.lpmm_rdf_build,model_list:is(p.lpmm_rdf_build?.model_list||[])}})}E(!1),D(null),O(null),ze({title:I!==null?"模型已更新":"模型已添加",description:'配置将在 2 秒后自动保存,或点击右上角"保存配置"按钮立即保存'})},Et=re=>{if(!re&&C){const pe={...C,price_in:C.price_in??0,price_out:C.price_out??0};D(pe)}E(re)},Bt=re=>{de(re),Ne(!0)},Oa=()=>{if(je!==null){const re=a.filter((pe,ts)=>ts!==je);n(re),f(re.map(pe=>pe.name)),K(p,re),ze({title:"删除成功",description:'配置将在 2 秒后自动保存,或点击右上角"保存配置"按钮立即保存'})}Ne(!1),de(null)},ll=re=>{const pe=new Set(R);pe.has(re)?pe.delete(re):pe.add(re),Y(pe)},xl=()=>{if(R.size===Dt.length)Y(new Set);else{const re=Dt.map((pe,ts)=>a.findIndex(js=>js===Dt[ts]));Y(new Set(re))}},sr=()=>{if(R.size===0){ze({title:"提示",description:"请先选择要删除的模型",variant:"default"});return}ue(!0)},te=()=>{const re=R.size,pe=a.filter((ts,js)=>!R.has(js));n(pe),f(pe.map(ts=>ts.name)),K(p,pe),Y(new Set),ue(!1),ze({title:"批量删除成功",description:`已删除 ${re} 个模型,配置将在 2 秒后自动保存`})},we=(re,pe,ts)=>{if(!p)return;if(re==="embedding"&&pe==="model_list"&&Array.isArray(ts)){const is=J.current,jt=ts;if((is.length!==jt.length||is.some(Il=>!jt.includes(Il))||jt.some(Il=>!is.includes(Il)))&&is.length>0){$e.current={field:pe,value:ts},ee(!0);return}}const js={...p,[re]:{...p[re],[pe]:ts}};g(js),K(js,a),re==="embedding"&&pe==="model_list"&&Array.isArray(ts)&&(J.current=[...ts])},Le=()=>{if(!p||!$e.current)return;const{field:re,value:pe}=$e.current,ts={...p,embedding:{...p.embedding,[re]:pe}};g(ts),K(ts,a),re==="model_list"&&Array.isArray(pe)&&(J.current=[...pe]),$e.current=null,ee(!1),ze({title:"嵌入模型已更新",description:"建议重新生成知识库向量以确保最佳匹配精度"})},Fs=()=>{$e.current=null,ee(!1)},Dt=a.filter(re=>{if(!he)return!0;const pe=he.toLowerCase();return re.name.toLowerCase().includes(pe)||re.model_identifier.toLowerCase().includes(pe)||re.api_provider.toLowerCase().includes(pe)}),ea=Math.ceil(Dt.length/fe),rt=Dt.slice((G-1)*fe,G*fe),sa=()=>{const re=parseInt(q);re>=1&&re<=ea&&(Se(re),B(""))},xt=re=>p?[p.utils?.model_list||[],p.tool_use?.model_list||[],p.replyer?.model_list||[],p.planner?.model_list||[],p.vlm?.model_list||[],p.voice?.model_list||[],p.embedding?.model_list||[],p.lpmm_entity_extract?.model_list||[],p.lpmm_rdf_build?.model_list||[]].some(ts=>ts.includes(re)):!1;return N?e.jsx(Je,{className:"h-full",children:e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})})}):e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"模型管理与分配"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"添加模型并为模型分配功能"})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(YS,{trigger:e.jsxs(_,{variant:"outline",size:"sm",className:"flex-1 sm:flex-none",children:[e.jsx(nv,{className:"mr-2 h-4 w-4"}),"分享配置"]})}),e.jsxs(_,{onClick:$t,disabled:w||y||!z||Ut,size:"sm",variant:"outline",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(fc,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),w?"保存中...":y?"自动保存中...":z?"保存配置":"已保存"]}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{disabled:w||y||Ut,size:"sm",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(hc,{className:"mr-2 h-4 w-4"}),Ut?"重启中...":z?"保存并重启":"重启麦麦"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重启麦麦?"}),e.jsx(fs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:z?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:z?gt:ls,children:z?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsxs(lt,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),H.length>0&&e.jsxs(at,{variant:"destructive",children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(lt,{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("strong",{children:"检测到无效的模型引用"}),e.jsx("div",{className:"mt-2 space-y-1",children:H.map(({taskName:re,invalidModels:pe})=>e.jsxs("div",{className:"text-sm",children:[e.jsx("strong",{children:re})," 引用了不存在的模型: ",pe.join(", ")]},re))})]}),e.jsx(_,{variant:"outline",size:"sm",className:"shrink-0 bg-background hover:bg-accent",onClick:ss,children:"一键清理"})]})]}),Ue.length>0&&e.jsxs(at,{variant:"default",className:"border-yellow-500/50 bg-yellow-500/10",children:[e.jsx(Jt,{className:"h-4 w-4 text-yellow-600"}),e.jsxs(lt,{children:[e.jsx("strong",{className:"text-yellow-600",children:"以下任务未配置模型"}),e.jsxs("div",{className:"mt-2 text-sm",children:[Ue.join("、")," 还未分配模型,这些功能将无法正常工作。"]})]})]}),e.jsxs(at,{className:"hidden lg:flex border-primary/30 bg-primary/5 cursor-pointer hover:bg-primary/10 transition-colors",onClick:aa,children:[e.jsx(E_,{className:"h-4 w-4 text-primary"}),e.jsxs(lt,{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[e.jsx("strong",{className:"text-primary",children:"新手引导:"}),"不知道如何配置模型?点击这里开始学习如何为麦麦的组件分配模型。"]}),e.jsx(_,{variant:"outline",size:"sm",className:"ml-4 shrink-0",children:"开始引导"})]})]}),e.jsxs(ta,{defaultValue:"models",className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full max-w-full sm:max-w-md grid-cols-2",children:[e.jsx(Xe,{value:"models",children:"添加模型"}),e.jsx(Xe,{value:"tasks","data-tour":"tasks-tab-trigger",children:"为模型分配功能"})]}),e.jsxs(ws,{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:[R.size>0&&e.jsxs(_,{onClick:sr,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(ns,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",R.size,")"]}),e.jsxs(_,{onClick:()=>tt(null,null),size:"sm",variant:"outline",className:"w-full sm:w-auto","data-tour":"add-model-button",children:[e.jsx(et,{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(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(le,{placeholder:"搜索模型名称、标识符或提供商...",value:he,onChange:re=>ge(re.target.value),className:"pl-9"})]}),he&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",Dt.length," 个结果"]})]}),e.jsx(ZS,{paginatedModels:rt,allModels:a,onEdit:tt,onDelete:Bt,isModelUsed:xt,searchQuery:he}),e.jsx(WS,{paginatedModels:rt,allModels:a,filteredModels:Dt,selectedModels:R,onEdit:tt,onDelete:Bt,onToggleSelection:ll,onToggleSelectAll:xl,isModelUsed:xt,searchQuery:he}),e.jsx(t4,{page:G,pageSize:fe,totalItems:Dt.length,jumpToPage:q,onPageChange:Se,onPageSizeChange:Te,onJumpToPageChange:B,onJumpToPage:sa,onSelectionClear:()=>Y(new Set)})]}),e.jsxs(ws,{value:"tasks",className:"space-y-6 mt-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"为不同的任务配置使用的模型和参数"}),p&&e.jsxs("div",{className:"grid gap-4 sm:gap-6",children:[e.jsx(zl,{title:"组件模型 (utils)",description:"用于表情包、取名、关系、情绪变化等组件",taskConfig:p.utils,modelNames:h,onChange:(re,pe)=>we("utils",re,pe),dataTour:"task-model-select"}),e.jsx(zl,{title:"工具调用模型 (tool_use)",description:"需要使用支持工具调用的模型",taskConfig:p.tool_use,modelNames:h,onChange:(re,pe)=>we("tool_use",re,pe)}),e.jsx(zl,{title:"首要回复模型 (replyer)",description:"用于表达器和表达方式学习",taskConfig:p.replyer,modelNames:h,onChange:(re,pe)=>we("replyer",re,pe)}),e.jsx(zl,{title:"决策模型 (planner)",description:"负责决定麦麦该什么时候回复",taskConfig:p.planner,modelNames:h,onChange:(re,pe)=>we("planner",re,pe)}),e.jsx(zl,{title:"图像识别模型 (vlm)",description:"视觉语言模型",taskConfig:p.vlm,modelNames:h,onChange:(re,pe)=>we("vlm",re,pe),hideTemperature:!0}),e.jsx(zl,{title:"语音识别模型 (voice)",description:"语音转文字",taskConfig:p.voice,modelNames:h,onChange:(re,pe)=>we("voice",re,pe),hideTemperature:!0,hideMaxTokens:!0}),e.jsx(zl,{title:"嵌入模型 (embedding)",description:"用于向量化",taskConfig:p.embedding,modelNames:h,onChange:(re,pe)=>we("embedding",re,pe),hideTemperature:!0,hideMaxTokens:!0}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库模型"}),e.jsx(zl,{title:"实体提取模型 (lpmm_entity_extract)",description:"从文本中提取实体",taskConfig:p.lpmm_entity_extract,modelNames:h,onChange:(re,pe)=>we("lpmm_entity_extract",re,pe)}),e.jsx(zl,{title:"RDF 构建模型 (lpmm_rdf_build)",description:"构建知识图谱",taskConfig:p.lpmm_rdf_build,modelNames:h,onChange:(re,pe)=>we("lpmm_rdf_build",re,pe)})]})]})]})]}),e.jsx(Ps,{open:U,onOpenChange:Et,children:e.jsxs(Ds,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"model-dialog",preventOutsideClose:Ja,children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:I!==null?"编辑模型":"添加模型"}),e.jsx(Ks,{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(T,{htmlFor:"model_name",className:Ee.name?"text-destructive":"",children:"模型名称 *"}),e.jsx(le,{id:"model_name",value:C?.name||"",onChange:re=>{D(pe=>pe?{...pe,name:re.target.value}:null),Ee.name&&me(pe=>({...pe,name:void 0}))},placeholder:"例如: qwen3-30b",className:Ee.name?"border-destructive focus-visible:ring-destructive":""}),Ee.name?e.jsx("p",{className:"text-xs text-destructive",children:Ee.name}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于在任务配置中引用此模型"})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-provider-select",children:[e.jsx(T,{htmlFor:"api_provider",className:Ee.api_provider?"text-destructive":"",children:"API 提供商 *"}),e.jsxs(Ie,{value:C?.api_provider||"",onValueChange:re=>{D(pe=>pe?{...pe,api_provider:re}:null),bs(),Ee.api_provider&&me(pe=>({...pe,api_provider:void 0}))},children:[e.jsx(Be,{id:"api_provider",className:Ee.api_provider?"border-destructive focus-visible:ring-destructive":"",children:e.jsx(Fe,{placeholder:"选择提供商"})}),e.jsx(Pe,{children:r.map(re=>e.jsx(W,{value:re,children:re},re))})]}),Ee.api_provider&&e.jsx("p",{className:"text-xs text-destructive",children:Ee.api_provider})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-identifier-input",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{htmlFor:"model_identifier",className:Ee.model_identifier?"text-destructive":"",children:"模型标识符 *"}),Cs?.modelFetcher&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{variant:"secondary",className:"text-xs",children:Cs.display_name}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-6 px-2",onClick:()=>C?.api_provider&&Re(C.api_provider,!0),disabled:Us,children:Us?e.jsx(zs,{className:"h-3 w-3 animate-spin"}):e.jsx(dt,{className:"h-3 w-3"})})]})]}),Cs?.modelFetcher?e.jsxs(ul,{open:M,onOpenChange:Q,children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",role:"combobox","aria-expanded":M,className:"w-full justify-between font-normal",disabled:Us||!!as,children:[Us?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(zs,{className:"h-4 w-4 animate-spin"}),"正在获取模型列表..."]}):as?e.jsx("span",{className:"text-muted-foreground text-sm",children:"点击下方输入框手动填写"}):C?.model_identifier?e.jsx("span",{className:"truncate",children:C.model_identifier}):e.jsx("span",{className:"text-muted-foreground",children:"搜索或选择模型..."}),e.jsx(rx,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(sl,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(dd,{children:[e.jsx(ud,{placeholder:"搜索模型..."}),e.jsx(Je,{className:"h-[300px]",children:e.jsxs(md,{className:"max-h-none overflow-visible",children:[e.jsx(xd,{children:as?e.jsxs("div",{className:"py-4 px-2 text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:as}),!as.includes("API Key")&&e.jsx(_,{variant:"link",size:"sm",onClick:()=>C?.api_provider&&Re(C.api_provider,!0),children:"重试"})]}):"未找到匹配的模型"}),e.jsx(oc,{heading:"可用模型",children:es.map(re=>e.jsxs(dc,{value:re.id,onSelect:()=>{D(pe=>pe?{...pe,model_identifier:re.id}:null),Q(!1)},children:[e.jsx(Ct,{className:`mr-2 h-4 w-4 ${C?.model_identifier===re.id?"opacity-100":"opacity-0"}`}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:re.id}),re.name!==re.id&&e.jsx("span",{className:"text-xs text-muted-foreground",children:re.name})]})]},re.id))}),e.jsx(oc,{heading:"手动输入",children:e.jsxs(dc,{value:"__manual_input__",onSelect:()=>{Q(!1)},children:[e.jsx(Kn,{className:"mr-2 h-4 w-4"}),"手动输入模型标识符..."]})})]})})]})})]}):e.jsx(le,{id:"model_identifier",value:C?.model_identifier||"",onChange:re=>{D(pe=>pe?{...pe,model_identifier:re.target.value}:null),Ee.model_identifier&&me(pe=>({...pe,model_identifier:void 0}))},placeholder:"Qwen/Qwen3-30B-A3B-Instruct-2507",className:Ee.model_identifier?"border-destructive focus-visible:ring-destructive":""}),Ee.model_identifier&&e.jsx("p",{className:"text-xs text-destructive",children:Ee.model_identifier}),as&&Cs?.modelFetcher&&!Ee.model_identifier&&e.jsxs(at,{variant:"destructive",className:"mt-2 py-2",children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(lt,{className:"text-xs",children:as})]}),Cs?.modelFetcher&&e.jsx(le,{value:C?.model_identifier||"",onChange:re=>{D(pe=>pe?{...pe,model_identifier:re.target.value}:null),Ee.model_identifier&&me(pe=>({...pe,model_identifier:void 0}))},placeholder:"或手动输入模型标识符",className:`mt-2 ${Ee.model_identifier?"border-destructive focus-visible:ring-destructive":""}`}),!Ee.model_identifier&&e.jsx("p",{className:"text-xs text-muted-foreground",children:as?'请手动输入模型标识符,或前往"模型提供商配置"检查 API Key':Cs?.modelFetcher?`已识别为 ${Cs.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(T,{htmlFor:"price_in",children:"输入价格 (¥/M token)"}),e.jsx(le,{id:"price_in",type:"number",step:"0.1",min:"0",value:C?.price_in??"",onChange:re=>{const pe=re.target.value===""?null:parseFloat(re.target.value);D(ts=>ts?{...ts,price_in:pe}:null)},placeholder:"默认: 0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"price_out",children:"输出价格 (¥/M token)"}),e.jsx(le,{id:"price_out",type:"number",step:"0.1",min:"0",value:C?.price_out??"",onChange:re=>{const pe=re.target.value===""?null:parseFloat(re.target.value);D(ts=>ts?{...ts,price_out:pe}: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(T,{htmlFor:"enable_model_temperature",className:"cursor-pointer",children:"自定义模型温度"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务温度配置"})]}),e.jsx(Ve,{id:"enable_model_temperature",checked:C?.temperature!=null,onCheckedChange:re=>{D(re?pe=>pe?{...pe,temperature:.5}:null:pe=>pe?{...pe,temperature:null}:null)}})]}),C?.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(T,{className:"text-sm",children:"温度值"}),e.jsx("span",{className:"text-sm font-medium tabular-nums",children:C.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(Qa,{value:[C.temperature],onValueChange:re=>D(pe=>pe?{...pe,temperature:re[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(T,{htmlFor:"enable_model_max_tokens",className:"cursor-pointer",children:"自定义最大 Token"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务最大 Token 配置"})]}),e.jsx(Ve,{id:"enable_model_max_tokens",checked:C?.max_tokens!=null,onCheckedChange:re=>{D(re?pe=>pe?{...pe,max_tokens:2048}:null:pe=>pe?{...pe,max_tokens:null}:null)}})]}),C?.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(T,{className:"text-sm",children:"最大 Token 数"}),e.jsx(le,{type:"number",min:"1",max:"128000",value:C.max_tokens,onChange:re=>{const pe=parseInt(re.target.value);!isNaN(pe)&&pe>=1&&D(ts=>ts?{...ts,max_tokens:pe}: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(Ve,{id:"force_stream_mode",checked:C?.force_stream_mode||!1,onCheckedChange:re=>D(pe=>pe?{...pe,force_stream_mode:re}:null)}),e.jsx(T,{htmlFor:"force_stream_mode",className:"cursor-pointer",children:"强制流式输出模式"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"额外参数"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(_,{type:"button",variant:"outline",size:"sm",className:"flex-1 justify-start h-9",onClick:()=>L(!0),children:[e.jsx(vn,{className:"h-4 w-4 mr-2"}),Object.keys(C?.extra_params||{}).length>0?e.jsxs("span",{children:["已配置 ",Object.keys(C?.extra_params||{}).length," 个参数"]}):e.jsx("span",{className:"text-muted-foreground",children:"未配置额外参数"})]})}),Object.keys(C?.extra_params||{}).length>0&&e.jsxs("div",{className:"text-xs text-muted-foreground px-1",children:[Object.keys(C?.extra_params||{}).slice(0,3).map(re=>e.jsx("span",{className:"inline-block mr-2",children:e.jsx("code",{className:"px-1.5 py-0.5 bg-muted rounded",children:re})},re)),Object.keys(C?.extra_params||{}).length>3&&e.jsx("span",{children:"..."})]})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>E(!1),"data-tour":"model-cancel-button",children:"取消"}),e.jsx(_,{onClick:Ms,"data-tour":"model-save-button",children:"保存"})]})]})}),e.jsx(Ns,{open:oe,onOpenChange:Ne,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除模型 "',je!==null?a[je]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:Oa,children:"删除"})]})]})}),e.jsx(Ns,{open:$,onOpenChange:ue,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["确定要删除选中的 ",R.size," 个模型吗? 此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:te,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),e.jsx(Ns,{open:Ae,onOpenChange:ee,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsxs(hs,{className:"flex items-center gap-2",children:[e.jsx(Jt,{className:"h-5 w-5 text-amber-500"}),"更换嵌入模型警告"]}),e.jsx(fs,{asChild:!0,children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"注意:"}),"更换嵌入模型可能会影响知识库的匹配精度!"]}),e.jsxs("ul",{className:"space-y-2 ml-4 list-disc text-muted-foreground",children:[e.jsx("li",{children:"不同的嵌入模型会产生不同的向量表示"}),e.jsx("li",{children:"这可能导致现有知识库的检索结果不准确"}),e.jsx("li",{children:"建议更换嵌入模型后重新生成所有知识库的向量"})]}),e.jsx("p",{className:"text-foreground font-medium",children:"确定要更换嵌入模型吗?"})]})})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:Fs,children:"取消"}),e.jsx(ps,{onClick:Le,className:"bg-amber-600 hover:bg-amber-700",children:"确认更换"})]})]})}),e.jsx(BS,{open:X,onOpenChange:L,value:C?.extra_params||{},onChange:re=>D(pe=>pe?{...pe,extra_params:re}:null)}),e.jsx(er,{})]})})}const uc=wj,mc=ww,xc=_w,hd="/api/webui/config";async function c4(){const n=await(await _e(`${hd}/adapter-config/path`)).json();return!n.success||!n.path?null:{path:n.path,lastModified:n.lastModified}}async function Hg(a){const r=await(await _e(`${hd}/adapter-config/path`,{method:"POST",headers:Hs(),body:JSON.stringify({path:a})})).json();if(!r.success)throw new Error(r.message||"保存路径失败")}async function Vg(a){const r=await(await _e(`${hd}/adapter-config?path=${encodeURIComponent(a)}`)).json();if(!r.success)throw new Error("读取配置文件失败");return r.content}async function Gg(a,n){const c=await(await _e(`${hd}/adapter-config`,{method:"POST",headers:Hs(),body:JSON.stringify({path:a,content:n})})).json();if(!c.success)throw new Error(c.message||"保存配置失败")}const bt={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"}},Bm={oneclick:{name:"一键包",description:"使用一键包部署的适配器配置",path:"../MaiBot-Napcat-Adapter/config.toml",icon:ra},docker:{name:"Docker",description:"Docker Compose 部署的适配器配置",path:"/MaiMBot/adapters-config/config.toml",icon:M_}};function o4(a,n){let r=a.slice(0,n).split(/\r\n|\n|\r/g);return[r.length,r.pop().length+1]}function d4(a,n,r){let c=a.split(/\r\n|\n|\r/g),d="",u=(Math.log10(n+1)|0)+1;for(let h=n-1;h<=n+1;h++){let f=c[h-1];f&&(d+=h.toString().padEnd(u," "),d+=": ",d+=f,d+=` +`,h===n&&(d+=" ".repeat(u+r+2),d+=`^ +`))}return d}class ks extends Error{line;column;codeblock;constructor(n,r){const[c,d]=o4(r.toml,r.ptr),u=d4(r.toml,c,d);super(`Invalid TOML document: ${n} + +${u}`,r),this.line=c,this.column=d,this.codeblock=u}}function u4(a,n){let r=0;for(;a[n-++r]==="\\";);return--r&&r%2}function Yo(a,n=0,r=a.length){let c=a.indexOf(` +`,n);return a[c-1]==="\r"&&c--,c<=r?c:-1}function gx(a,n){for(let r=n;r-1&&r!=="'"&&u4(a,n));return n>-1&&(n+=c.length,c.length>1&&(a[n]===r&&n++,a[n]===r&&n++)),n}let m4=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}:\d{2}(?:\.\d+)?)?(Z|[-+]\d{2}:\d{2})?$/i;class Kr extends Date{#s=!1;#t=!1;#e=null;constructor(n){let r=!0,c=!0,d="Z";if(typeof n=="string"){let u=n.match(m4);u?(u[1]||(r=!1,n=`0000-01-01T${n}`),c=!!u[2],c&&n[10]===" "&&(n=n.replace(" ","T")),u[2]&&+u[2]>23?n="":(d=u[3]||null,n=n.toUpperCase(),!d&&c&&(n+="Z"))):n=""}super(n),isNaN(this.getTime())||(this.#s=r,this.#t=c,this.#e=d)}isDateTime(){return this.#s&&this.#t}isLocal(){return!this.#s||!this.#t||!this.#e}isDate(){return this.#s&&!this.#t}isTime(){return this.#t&&!this.#s}isValid(){return this.#s||this.#t}toISOString(){let n=super.toISOString();if(this.isDate())return n.slice(0,10);if(this.isTime())return n.slice(11,23);if(this.#e===null)return n.slice(0,-1);if(this.#e==="Z")return n;let r=+this.#e.slice(1,3)*60+ +this.#e.slice(4,6);return r=this.#e[0]==="-"?r:-r,new Date(this.getTime()-r*6e4).toISOString().slice(0,-1)+this.#e}static wrapAsOffsetDateTime(n,r="Z"){let c=new Kr(n);return c.#e=r,c}static wrapAsLocalDateTime(n){let r=new Kr(n);return r.#e=null,r}static wrapAsLocalDate(n){let r=new Kr(n);return r.#t=!1,r.#e=null,r}static wrapAsLocalTime(n){let r=new Kr(n);return r.#s=!1,r.#e=null,r}}let x4=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,h4=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,f4=/^[+-]?0[0-9_]/,p4=/^[0-9a-f]{4,8}$/i,Kg={b:"\b",t:" ",n:` +`,f:"\f",r:"\r",'"':'"',"\\":"\\"};function Xv(a,n=0,r=a.length){let c=a[n]==="'",d=a[n++]===a[n]&&a[n]===a[n+1];d&&(r-=2,a[n+=2]==="\r"&&n++,a[n]===` +`&&n++);let u=0,h,f="",p=n;for(;n-1&&(gx(a,u),d=d.slice(0,u));let h=d.trimEnd();if(!c){let f=d.indexOf(` +`,h.length);if(f>-1)throw new ks("newlines are not allowed in inline tables",{toml:a,ptr:n+f})}return[h,u]}function jx(a,n,r,c,d){if(c===0)throw new ks("document contains excessively nested structures. aborting.",{toml:a,ptr:n});let u=a[n];if(u==="["||u==="{"){let[p,g]=u==="["?b4(a,n,c,d):N4(a,n,c,d),N=r?qg(a,g,",",r):g;if(g-N&&r==="}"){let v=Yo(a,g,N);if(v>-1)throw new ks("newlines are not allowed in inline tables",{toml:a,ptr:v})}return[p,N]}let h;if(u==='"'||u==="'"){h=Jv(a,n);let p=Xv(a,n,h);if(r){if(h=Ol(a,h,r!=="]"),a[h]&&a[h]!==","&&a[h]!==r&&a[h]!==` +`&&a[h]!=="\r")throw new ks("unexpected character encountered",{toml:a,ptr:h});h+=+(a[h]===",")}return[p,h]}h=qg(a,n,",",r);let f=j4(a,n,h-+(a[h-1]===","),r==="]");if(!f[0])throw new ks("incomplete key-value declaration: no value specified",{toml:a,ptr:n});return r&&f[1]>-1&&(h=Ol(a,n+f[1]),h+=+(a[h]===",")),[g4(f[0],a,n,d),h]}let v4=/^[a-zA-Z0-9-_]+[ \t]*$/;function Zm(a,n,r="="){let c=n-1,d=[],u=a.indexOf(r,n);if(u<0)throw new ks("incomplete key-value: cannot find end of key",{toml:a,ptr:n});do{let h=a[n=++c];if(h!==" "&&h!==" ")if(h==='"'||h==="'"){if(h===a[n+1]&&h===a[n+2])throw new ks("multiline strings are not allowed in keys",{toml:a,ptr:n});let f=Jv(a,n);if(f<0)throw new ks("unfinished string encountered",{toml:a,ptr:n});c=a.indexOf(".",f);let p=a.slice(f,c<0||c>u?u:c),g=Yo(p);if(g>-1)throw new ks("newlines are not allowed in keys",{toml:a,ptr:n+c+g});if(p.trimStart())throw new ks("found extra tokens after the string part",{toml:a,ptr:f});if(uu?u:c);if(!v4.test(f))throw new ks("only letter, numbers, dashes and underscores are allowed in keys",{toml:a,ptr:n});d.push(f.trimEnd())}}while(c+1&&cd===""||d===null||d===void 0?u:d,r={inner:{version:n(a.inner.version,bt.inner.version)},nickname:{nickname:n(a.nickname.nickname,bt.nickname.nickname)},napcat_server:{host:n(a.napcat_server.host,bt.napcat_server.host),port:n(a.napcat_server.port||0,bt.napcat_server.port),token:n(a.napcat_server.token,bt.napcat_server.token),heartbeat_interval:n(a.napcat_server.heartbeat_interval||0,bt.napcat_server.heartbeat_interval)},maibot_server:{host:n(a.maibot_server.host,bt.maibot_server.host),port:n(a.maibot_server.port||0,bt.maibot_server.port)},chat:{group_list_type:n(a.chat.group_list_type,bt.chat.group_list_type),group_list:a.chat.group_list||[],private_list_type:n(a.chat.private_list_type,bt.chat.private_list_type),private_list:a.chat.private_list||[],ban_user_id:a.chat.ban_user_id||[],ban_qq_bot:a.chat.ban_qq_bot??bt.chat.ban_qq_bot,enable_poke:a.chat.enable_poke??bt.chat.enable_poke},voice:{use_tts:a.voice.use_tts??bt.voice.use_tts},debug:{level:n(a.debug.level,bt.debug.level)}};let c=k4(r);return c=C4(c),c}catch(n){throw console.error("TOML 生成失败:",n),new Error(`无法生成 TOML 文件: ${n instanceof Error?n.message:"未知错误"}`)}}function C4(a){const n=a.split(` +`),r=[];for(let c=0;c"|?*\x00-\x1F]/.test(a)?{valid:!1,error:"路径包含非法字符"}:{valid:!0,error:""}}function T4(){const[a,n]=m.useState("upload"),[r,c]=m.useState(null),[d,u]=m.useState(""),[h,f]=m.useState(""),[p,g]=m.useState("oneclick"),[N,v]=m.useState(""),[w,b]=m.useState(!1),[y,A]=m.useState(!1),[z,S]=m.useState(!1),[U,E]=m.useState(!1),[C,D]=m.useState(null),[I,O]=m.useState(!1),X=m.useRef(null),{toast:L}=Ys(),oe=m.useRef(null),Ne=M=>{if(f(M),M.trim()){const Q=Fm(M);v(Q.error)}else v("")},je=m.useCallback(async M=>{const Q=Bm[M];A(!0);try{const Ae=await Vg(Q.path),ee=Pm(Ae);c(ee),g(M),f(Q.path),await Hg(Q.path),L({title:"加载成功",description:`已从${Q.name}预设加载配置`})}catch(Ae){console.error("加载预设配置失败:",Ae),L({title:"加载失败",description:Ae instanceof Error?Ae.message:"无法读取预设配置文件",variant:"destructive"})}finally{A(!1)}},[L]),de=m.useCallback(async M=>{const Q=Fm(M);if(!Q.valid){v(Q.error),L({title:"路径无效",description:Q.error,variant:"destructive"});return}v(""),A(!0);try{const Ae=await Vg(M),ee=Pm(Ae);c(ee),f(M),await Hg(M),L({title:"加载成功",description:"已从配置文件加载"})}catch(Ae){console.error("加载配置失败:",Ae),L({title:"加载失败",description:Ae instanceof Error?Ae.message:"无法读取配置文件",variant:"destructive"})}finally{A(!1)}},[L]);m.useEffect(()=>{(async()=>{try{const Q=await c4();if(Q&&Q.path){f(Q.path);const Ae=Object.entries(Bm).find(([,ee])=>ee.path===Q.path);Ae?(n("preset"),g(Ae[0]),await je(Ae[0])):(n("path"),await de(Q.path))}}catch(Q){console.error("加载保存的路径失败:",Q)}})()},[de,je]);const he=m.useCallback(M=>{a!=="path"&&a!=="preset"||!h||(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(async()=>{b(!0);try{const Q=Im(M);await Gg(h,Q),L({title:"自动保存成功",description:"配置已保存到文件"})}catch(Q){console.error("自动保存失败:",Q),L({title:"自动保存失败",description:Q instanceof Error?Q.message:"保存配置失败",variant:"destructive"})}finally{b(!1)}},1e3))},[a,h,L]),ge=async()=>{if(!r||!h)return;const M=Fm(h);if(!M.valid){L({title:"保存失败",description:M.error,variant:"destructive"});return}b(!0);try{const Q=Im(r);await Gg(h,Q),L({title:"保存成功",description:"配置已保存到文件"})}catch(Q){console.error("保存失败:",Q),L({title:"保存失败",description:Q instanceof Error?Q.message:"保存配置失败",variant:"destructive"})}finally{b(!1)}},R=async()=>{h&&await de(h)},Y=M=>{if(M!==a){if(r){D(M),S(!0);return}$(M)}},$=M=>{c(null),u(""),v(""),n(M),M==="preset"&&je("oneclick"),L({title:"已切换模式",description:{upload:"现在可以上传配置文件",path:"现在可以指定配置文件路径",preset:"现在可以使用预设配置"}[M]})},ue=()=>{C&&($(C),D(null)),S(!1)},G=()=>{if(r){E(!0);return}Se()},Se=()=>{f(""),c(null),v(""),L({title:"已清空",description:"路径和配置已清空"})},fe=()=>{Se(),E(!1)},Te=M=>{const Q=M.target.files?.[0];if(!Q)return;const Ae=new FileReader;Ae.onload=ee=>{try{const J=ee.target?.result,$e=Pm(J);c($e),u(Q.name),L({title:"上传成功",description:`已加载配置文件:${Q.name}`})}catch(J){console.error("解析配置文件失败:",J),L({title:"解析失败",description:"配置文件格式错误,请检查文件内容",variant:"destructive"})}},Ae.readAsText(Q)},q=()=>{if(!r)return;const M=Im(r),Q=new Blob([M],{type:"text/plain;charset=utf-8"}),Ae=URL.createObjectURL(Q),ee=document.createElement("a");ee.href=Ae,ee.download=d||"config.toml",document.body.appendChild(ee),ee.click(),document.body.removeChild(ee),URL.revokeObjectURL(Ae),L({title:"下载成功",description:"配置文件已下载,请手动覆盖并重启适配器"})},B=()=>{c(JSON.parse(JSON.stringify(bt))),u("config.toml"),L({title:"已加载默认配置",description:"可以开始编辑配置"})};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"麦麦适配器配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理麦麦的 QQ 适配器的配置文件"})]})}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg border border-amber-500/50 bg-amber-500/10 text-amber-700 dark:text-amber-400",children:[e.jsx(_t,{className:"h-4 w-4 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm",children:"适配器配置保存之后使用 WebUI 的重启功能适配器并不会重启,需要手动重启适配器。"})]}),e.jsx(uc,{open:I,onOpenChange:O,children:e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Oe,{children:"工作模式"}),e.jsx(os,{children:"选择配置文件的管理方式"})]}),e.jsx(mc,{asChild:!0,children:e.jsxs(_,{variant:"ghost",size:"sm",className:"w-9 p-0",children:[e.jsx(za,{className:`h-4 w-4 transition-transform duration-200 ${I?"transform rotate-180":""}`}),e.jsx("span",{className:"sr-only",children:"切换"})]})})]})}),e.jsx(xc,{children:e.jsxs(Me,{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 ${a==="preset"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>Y("preset"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(ra,{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 ${a==="upload"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>Y("upload"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(rc,{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 ${a==="path"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>Y("path"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(A_,{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:"指定配置文件路径,自动加载和保存"})]})]})})]}),a==="preset"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsx(T,{className:"text-sm md:text-base",children:"选择部署方式"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(Bm).map(([M,Q])=>{const Ae=Q.icon,ee=p===M;return e.jsx("div",{className:`border-2 rounded-lg p-3 cursor-pointer transition-all ${ee?"border-primary bg-primary/5":"border-muted hover:border-primary/50"}`,onClick:()=>{g(M),je(M)},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ae,{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:Q.name}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:Q.description}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-mono break-all",children:Q.path})]})]})},M)})})]}),a==="path"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{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(le,{id:"config-path",value:h,onChange:M=>Ne(M.target.value),placeholder:"例: C:\\Adapter\\config.toml",className:`text-sm ${N?"border-destructive":""}`}),N&&e.jsx("p",{className:"text-xs text-destructive",children:N})]}),e.jsx(_,{onClick:()=>de(h),disabled:y||!h||!!N,className:"w-full sm:w-auto",children:y?e.jsxs(e.Fragment,{children:[e.jsx(dt,{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(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(lt,{children:a==="preset"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"预设模式:"}),"选择预设的部署方式,配置会自动加载,修改后 1 秒自动保存",w&&" (正在保存...)"]}):a==="upload"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"上传文件模式:"}),"上传配置文件 → 在线编辑 → 下载文件 → 手动覆盖并重启适配器"]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"指定路径模式:"}),"指定配置文件路径后,配置会自动加载,修改后 1 秒自动保存",w&&" (正在保存...)"]})})]}),a==="upload"&&!r&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 w-full",children:[e.jsx("input",{ref:X,type:"file",accept:".toml",className:"hidden",onChange:Te}),e.jsxs(_,{onClick:()=>X.current?.click(),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(rc,{className:"mr-2 h-4 w-4"}),"上传配置"]}),e.jsxs(_,{onClick:B,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Ea,{className:"mr-2 h-4 w-4"}),"使用默认配置"]})]}),a==="upload"&&r&&e.jsx("div",{className:"flex gap-2",children:e.jsxs(_,{onClick:q,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Xt,{className:"mr-2 h-4 w-4"}),"下载配置"]})}),(a==="preset"||a==="path")&&r&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs(_,{onClick:ge,size:"sm",disabled:w||!!N,className:"w-full sm:w-auto",children:[e.jsx(fc,{className:"mr-2 h-4 w-4"}),w?"保存中...":"立即保存"]}),e.jsxs(_,{onClick:R,size:"sm",variant:"outline",disabled:y,className:"w-full sm:w-auto",children:[e.jsx(dt,{className:`mr-2 h-4 w-4 ${y?"animate-spin":""}`}),"刷新"]}),a==="path"&&e.jsxs(_,{onClick:G,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(ns,{className:"mr-2 h-4 w-4"}),"清空路径"]})]}),r?e.jsxs(ta,{defaultValue:"napcat",className:"w-full",children:[e.jsx("div",{className:"overflow-x-auto -mx-4 px-4 sm:mx-0 sm:px-0",children:e.jsxs(Zt,{className:"inline-flex w-auto min-w-full sm:grid sm:w-full sm:grid-cols-5",children:[e.jsxs(Xe,{value:"napcat",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"Napcat 连接"}),e.jsx("span",{className:"sm:hidden",children:"Napcat"})]}),e.jsxs(Xe,{value:"maibot",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"麦麦连接"}),e.jsx("span",{className:"sm:hidden",children:"麦麦"})]}),e.jsxs(Xe,{value:"chat",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"聊天控制"}),e.jsx("span",{className:"sm:hidden",children:"聊天"})]}),e.jsxs(Xe,{value:"voice",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"语音设置"}),e.jsx("span",{className:"sm:hidden",children:"语音"})]}),e.jsx(Xe,{value:"debug",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:"调试"})]})}),e.jsx(ws,{value:"napcat",className:"space-y-4",children:e.jsx(E4,{config:r,onChange:M=>{c(M),he(M)}})}),e.jsx(ws,{value:"maibot",className:"space-y-4",children:e.jsx(M4,{config:r,onChange:M=>{c(M),he(M)}})}),e.jsx(ws,{value:"chat",className:"space-y-4",children:e.jsx(A4,{config:r,onChange:M=>{c(M),he(M)}})}),e.jsx(ws,{value:"voice",className:"space-y-4",children:e.jsx(z4,{config:r,onChange:M=>{c(M),he(M)}})}),e.jsx(ws,{value:"debug",className:"space-y-4",children:e.jsx(R4,{config:r,onChange:M=>{c(M),he(M)}})})]}):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(Ea,{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:a==="preset"?"请选择预设的部署方式":a==="upload"?"请上传现有配置文件,或使用默认配置开始编辑":"请指定配置文件路径并点击加载按钮"})]})]})}),e.jsx(Ns,{open:z,onOpenChange:S,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认切换模式"}),e.jsxs(fs,{children:["切换模式将清空当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-destructive font-medium",children:"请确保已保存重要配置"})]})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:()=>{S(!1),D(null)},children:"取消"}),e.jsx(ps,{onClick:ue,children:"确认切换"})]})]})}),e.jsx(Ns,{open:U,onOpenChange:E,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认清空路径"}),e.jsxs(fs,{children:["清空路径将清除当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-muted-foreground text-sm",children:"此操作不会删除配置文件,只是清除界面中的配置"})]})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:()=>E(!1),children:"取消"}),e.jsx(ps,{onClick:fe,className:"bg-destructive hover:bg-destructive/90",children:"确认清空"})]})]})})]})})}function E4({config:a,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"Napcat WebSocket 服务设置"}),e.jsxs("div",{className:"grid gap-3 md:gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(le,{id:"napcat-host",value:a.napcat_server.host,onChange:r=>n({...a,napcat_server:{...a.napcat_server,host:r.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的主机地址"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(le,{id:"napcat-port",type:"number",value:a.napcat_server.port||"",onChange:r=>n({...a,napcat_server:{...a.napcat_server,port:r.target.value?parseInt(r.target.value):0}}),placeholder:"8095",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的端口(留空使用默认值 8095)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-token",className:"text-sm md:text-base",children:"访问令牌(Token)"}),e.jsx(le,{id:"napcat-token",type:"password",value:a.napcat_server.token,onChange:r=>n({...a,napcat_server:{...a.napcat_server,token:r.target.value}}),placeholder:"留空表示无需令牌",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的访问令牌,若无则留空"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-heartbeat",className:"text-sm md:text-base",children:"心跳间隔(秒)"}),e.jsx(le,{id:"napcat-heartbeat",type:"number",value:a.napcat_server.heartbeat_interval||"",onChange:r=>n({...a,napcat_server:{...a.napcat_server,heartbeat_interval:r.target.value?parseInt(r.target.value):0}}),placeholder:"30",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"与 Napcat 设置的心跳间隔保持一致(留空使用默认值 30)"})]})]})]})})}function M4({config:a,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"麦麦 WebSocket 服务设置"}),e.jsxs("div",{className:"grid gap-3 md:gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"maibot-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(le,{id:"maibot-host",value:a.maibot_server.host,onChange:r=>n({...a,maibot_server:{...a.maibot_server,host:r.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 HOST 字段"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"maibot-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(le,{id:"maibot-port",type:"number",value:a.maibot_server.port||"",onChange:r=>n({...a,maibot_server:{...a.maibot_server,port:r.target.value?parseInt(r.target.value):0}}),placeholder:"8000",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 PORT 字段(留空使用默认值 8000)"})]})]})]})})}function A4({config:a,onChange:n}){const r=u=>{const h={...a};u==="group"?h.chat.group_list=[...h.chat.group_list,0]:u==="private"?h.chat.private_list=[...h.chat.private_list,0]:h.chat.ban_user_id=[...h.chat.ban_user_id,0],n(h)},c=(u,h)=>{const f={...a};u==="group"?f.chat.group_list=f.chat.group_list.filter((p,g)=>g!==h):u==="private"?f.chat.private_list=f.chat.private_list.filter((p,g)=>g!==h):f.chat.ban_user_id=f.chat.ban_user_id.filter((p,g)=>g!==h),n(f)},d=(u,h,f)=>{const p={...a};u==="group"?p.chat.group_list[h]=f:u==="private"?p.chat.private_list[h]=f:p.chat.ban_user_id[h]=f,n(p)};return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"聊天黑白名单功能"}),e.jsxs("div",{className:"grid gap-4 md:gap-6",children:[e.jsxs("div",{className:"space-y-3 md:space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-sm md:text-base",children:"群组名单类型"}),e.jsxs(Ie,{value:a.chat.group_list_type,onValueChange:u=>n({...a,chat:{...a.chat,group_list_type:u}}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(W,{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(T,{className:"text-sm md:text-base",children:"群组列表"}),e.jsxs(_,{onClick:()=>r("group"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ea,{className:"mr-1 h-4 w-4"}),"添加群号"]})]}),a.chat.group_list.map((u,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(le,{type:"number",value:u,onChange:f=>d("group",h,parseInt(f.target.value)||0),placeholder:"输入群号",className:"text-sm md:text-base"}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除群号 ",u," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>c("group",h),children:"删除"})]})]})]})]},h)),a.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(T,{className:"text-sm md:text-base",children:"私聊名单类型"}),e.jsxs(Ie,{value:a.chat.private_list_type,onValueChange:u=>n({...a,chat:{...a.chat,private_list_type:u}}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(W,{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(T,{className:"text-sm md:text-base",children:"私聊列表"}),e.jsxs(_,{onClick:()=>r("private"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ea,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),a.chat.private_list.map((u,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(le,{type:"number",value:u,onChange:f=>d("private",h,parseInt(f.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除用户 ",u," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>c("private",h),children:"删除"})]})]})]})]},h)),a.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(T,{className:"text-sm md:text-base",children:"全局禁止名单"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"名单中的用户无法进行任何聊天"})]}),e.jsxs(_,{onClick:()=>r("ban"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ea,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),a.chat.ban_user_id.map((u,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(le,{type:"number",value:u,onChange:f=>d("ban",h,parseInt(f.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要从全局禁止名单中删除用户 ",u," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>c("ban",h),children:"删除"})]})]})]})]},h)),a.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(T,{className:"text-sm md:text-base",children:"屏蔽QQ官方机器人"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否屏蔽来自QQ官方机器人的消息"})]}),e.jsx(Ve,{checked:a.chat.ban_qq_bot,onCheckedChange:u=>n({...a,chat:{...a.chat,ban_qq_bot:u}})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-sm md:text-base",children:"启用戳一戳功能"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否响应戳一戳消息"})]}),e.jsx(Ve,{checked:a.chat.enable_poke,onCheckedChange:u=>n({...a,chat:{...a.chat,enable_poke:u}})})]})]})]})})}function z4({config:a,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"发送语音设置"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-sm md:text-base",children:"使用 TTS 语音"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"请确保已配置 TTS 并有对应的适配器"})]}),e.jsx(Ve,{checked:a.voice.use_tts,onCheckedChange:r=>n({...a,voice:{use_tts:r}})})]})]})})}function R4({config:a,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"调试设置"}),e.jsx("div",{className:"grid gap-3 md:gap-4",children:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-sm md:text-base",children:"日志等级"}),e.jsxs(Ie,{value:a.debug.level,onValueChange:r=>n({...a,debug:{level:r}}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"DEBUG",children:"DEBUG(调试)"}),e.jsx(W,{value:"INFO",children:"INFO(信息)"}),e.jsx(W,{value:"WARNING",children:"WARNING(警告)"}),e.jsx(W,{value:"ERROR",children:"ERROR(错误)"}),e.jsx(W,{value:"CRITICAL",children:"CRITICAL(严重)"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"设置适配器的日志输出等级"})]})})]})})}const D4=["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"],O4=/^(aria-|data-)/,eN=a=>Object.fromEntries(Object.entries(a).filter(([n])=>O4.test(n)||D4.includes(n)));function L4(a,n){const r=eN(a);return Object.keys(a).some(c=>!Object.hasOwn(r,c)&&a[c]!==n[c])}class U4 extends m.Component{container;plugin;componentDidMount(){this.installPlugin()}componentDidUpdate(n){if(n.uppy!==this.props.uppy)this.uninstallPlugin(n),this.installPlugin();else if(L4(this.props,n)){const{uppy:r,...c}={...this.props,target:this.container};this.plugin.setOptions(c)}}componentWillUnmount(){this.uninstallPlugin()}installPlugin(){const{uppy:n,...r}={id:"Dashboard",...this.props,inline:!0,target:this.container};n.use(m1,r),this.plugin=n.getPlugin(r.id)}uninstallPlugin(n=this.props){const{uppy:r}=n;r.removePlugin(this.plugin)}render(){return m.createElement("div",{className:"uppy-Container",ref:n=>{this.container=n},...eN(this.props)})}}function $4({src:a,alt:n="表情包",className:r,maxRetries:c=5,retryInterval:d=1500}){const[u,h]=m.useState("loading"),[f,p]=m.useState(0),[g,N]=m.useState(null),[v,w]=m.useState(a);a!==v&&(h("loading"),p(0),N(null),w(a));const b=m.useCallback(async()=>{try{const y=await fetch(a,{credentials:"include"});if(y.status===202){h("generating"),f{p(S=>S+1)},d):h("error");return}if(!y.ok){h("error");return}const A=await y.blob(),z=URL.createObjectURL(A);N(z),h("loaded")}catch(y){console.error("加载缩略图失败:",y),h("error")}},[a,f,c,d]);return m.useEffect(()=>{b()},[b]),m.useEffect(()=>()=>{g&&URL.revokeObjectURL(g)},[g]),u==="loading"||u==="generating"?e.jsx(vs,{className:F("w-full h-full",r)}):u==="error"||!g?e.jsx("div",{className:F("w-full h-full flex items-center justify-center bg-muted",r),children:e.jsx(ix,{className:"h-8 w-8 text-muted-foreground"})}):e.jsx("img",{src:g,alt:n,className:F("w-full h-full object-contain",r)})}function B4({children:a,className:n}){return e.jsx(fx,{content:a,className:n})}const Ya="/api/webui/emoji";async function P4(a){const n=new URLSearchParams;a.page&&n.append("page",a.page.toString()),a.page_size&&n.append("page_size",a.page_size.toString()),a.search&&n.append("search",a.search),a.is_registered!==void 0&&n.append("is_registered",a.is_registered.toString()),a.is_banned!==void 0&&n.append("is_banned",a.is_banned.toString()),a.format&&n.append("format",a.format),a.sort_by&&n.append("sort_by",a.sort_by),a.sort_order&&n.append("sort_order",a.sort_order);const r=await _e(`${Ya}/list?${n}`,{});if(!r.ok)throw new Error(`获取表情包列表失败: ${r.statusText}`);return r.json()}async function I4(a){const n=await _e(`${Ya}/${a}`,{});if(!n.ok)throw new Error(`获取表情包详情失败: ${n.statusText}`);return n.json()}async function F4(a,n){const r=await _e(`${Ya}/${a}`,{method:"PATCH",body:JSON.stringify(n)});if(!r.ok)throw new Error(`更新表情包失败: ${r.statusText}`);return r.json()}async function H4(a){const n=await _e(`${Ya}/${a}`,{method:"DELETE"});if(!n.ok)throw new Error(`删除表情包失败: ${n.statusText}`);return n.json()}async function V4(){const a=await _e(`${Ya}/stats/summary`,{});if(!a.ok)throw new Error(`获取统计数据失败: ${a.statusText}`);return a.json()}async function G4(a){const n=await _e(`${Ya}/${a}/register`,{method:"POST"});if(!n.ok)throw new Error(`注册表情包失败: ${n.statusText}`);return n.json()}async function q4(a){const n=await _e(`${Ya}/${a}/ban`,{method:"POST"});if(!n.ok)throw new Error(`封禁表情包失败: ${n.statusText}`);return n.json()}function K4(a,n=!1){return n?`${Ya}/${a}/thumbnail?original=true`:`${Ya}/${a}/thumbnail`}function Q4(a){return`${Ya}/${a}/thumbnail?original=true`}async function Y4(a){const n=await _e(`${Ya}/batch/delete`,{method:"POST",body:JSON.stringify({emoji_ids:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"批量删除失败")}return n.json()}function J4(){return`${Ya}/upload`}function X4(){const[a,n]=m.useState([]),[r,c]=m.useState(null),[d,u]=m.useState(!1),[h,f]=m.useState(1),[p,g]=m.useState(0),[N,v]=m.useState(20),[w,b]=m.useState("all"),[y,A]=m.useState("all"),[z,S]=m.useState("all"),[U,E]=m.useState("usage_count"),[C,D]=m.useState("desc"),[I,O]=m.useState(null),[X,L]=m.useState(!1),[oe,Ne]=m.useState(!1),[je,de]=m.useState(!1),[he,ge]=m.useState(new Set),[R,Y]=m.useState(!1),[$,ue]=m.useState(""),[G,Se]=m.useState("medium"),[fe,Te]=m.useState(!1),{toast:q}=Ys(),B=m.useCallback(async()=>{try{u(!0);const me=await P4({page:h,page_size:N,is_registered:w==="all"?void 0:w==="registered",is_banned:y==="all"?void 0:y==="banned",format:z==="all"?void 0:z,sort_by:U,sort_order:C});n(me.data),g(me.total)}catch(me){const ze=me instanceof Error?me.message:"加载表情包列表失败";q({title:"错误",description:ze,variant:"destructive"})}finally{u(!1)}},[h,N,w,y,z,U,C,q]),M=async()=>{try{const me=await V4();c(me.data)}catch(me){console.error("加载统计数据失败:",me)}};m.useEffect(()=>{B()},[B]),m.useEffect(()=>{M()},[]);const Q=async me=>{try{const ze=await I4(me.id);O(ze.data),L(!0)}catch(ze){const rs=ze instanceof Error?ze.message:"加载详情失败";q({title:"错误",description:rs,variant:"destructive"})}},Ae=me=>{O(me),Ne(!0)},ee=me=>{O(me),de(!0)},J=async()=>{if(I)try{await H4(I.id),q({title:"成功",description:"表情包已删除"}),de(!1),O(null),B(),M()}catch(me){const ze=me instanceof Error?me.message:"删除失败";q({title:"错误",description:ze,variant:"destructive"})}},$e=async me=>{try{await G4(me.id),q({title:"成功",description:"表情包已注册"}),B(),M()}catch(ze){const rs=ze instanceof Error?ze.message:"注册失败";q({title:"错误",description:rs,variant:"destructive"})}},H=async me=>{try{await q4(me.id),q({title:"成功",description:"表情包已封禁"}),B(),M()}catch(ze){const rs=ze instanceof Error?ze.message:"封禁失败";q({title:"错误",description:rs,variant:"destructive"})}},se=me=>{const ze=new Set(he);ze.has(me)?ze.delete(me):ze.add(me),ge(ze)},Ue=async()=>{try{const me=await Y4(Array.from(he));q({title:"批量删除完成",description:me.message}),ge(new Set),Y(!1),B(),M()}catch(me){q({title:"批量删除失败",description:me instanceof Error?me.message:"批量删除失败",variant:"destructive"})}},ie=()=>{const me=parseInt($),ze=Math.ceil(p/N);me>=1&&me<=ze?(f(me),ue("")):q({title:"无效的页码",description:`请输入1-${ze}之间的页码`,variant:"destructive"})},Ee=r?.formats?Object.keys(r.formats):[];return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"表情包管理"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"管理麦麦的表情包资源"})]}),e.jsxs(_,{onClick:()=>Te(!0),className:"gap-2",children:[e.jsx(rc,{className:"h-4 w-4"}),"上传表情包"]})]}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[r&&e.jsxs("div",{className:"grid gap-4 grid-cols-2 lg:grid-cols-4",children:[e.jsx(Ce,{children:e.jsxs(De,{className:"pb-2",children:[e.jsx(os,{children:"总数"}),e.jsx(Oe,{className:"text-2xl",children:r.total})]})}),e.jsx(Ce,{children:e.jsxs(De,{className:"pb-2",children:[e.jsx(os,{children:"已注册"}),e.jsx(Oe,{className:"text-2xl text-green-600",children:r.registered})]})}),e.jsx(Ce,{children:e.jsxs(De,{className:"pb-2",children:[e.jsx(os,{children:"已封禁"}),e.jsx(Oe,{className:"text-2xl text-red-600",children:r.banned})]})}),e.jsx(Ce,{children:e.jsxs(De,{className:"pb-2",children:[e.jsx(os,{children:"未注册"}),e.jsx(Oe,{className:"text-2xl text-gray-600",children:r.unregistered})]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx(Bo,{className:"h-5 w-5"}),"筛选和排序"]})}),e.jsxs(Me,{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(T,{children:"排序方式"}),e.jsxs(Ie,{value:`${U}-${C}`,onValueChange:me=>{const[ze,rs]=me.split("-");E(ze),D(rs),f(1)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"usage_count-desc",children:"使用次数 (多→少)"}),e.jsx(W,{value:"usage_count-asc",children:"使用次数 (少→多)"}),e.jsx(W,{value:"register_time-desc",children:"注册时间 (新→旧)"}),e.jsx(W,{value:"register_time-asc",children:"注册时间 (旧→新)"}),e.jsx(W,{value:"record_time-desc",children:"记录时间 (新→旧)"}),e.jsx(W,{value:"record_time-asc",children:"记录时间 (旧→新)"}),e.jsx(W,{value:"last_used_time-desc",children:"最后使用 (新→旧)"}),e.jsx(W,{value:"last_used_time-asc",children:"最后使用 (旧→新)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"注册状态"}),e.jsxs(Ie,{value:w,onValueChange:me=>{b(me),f(1)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"all",children:"全部"}),e.jsx(W,{value:"registered",children:"已注册"}),e.jsx(W,{value:"unregistered",children:"未注册"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"封禁状态"}),e.jsxs(Ie,{value:y,onValueChange:me=>{A(me),f(1)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"all",children:"全部"}),e.jsx(W,{value:"banned",children:"已封禁"}),e.jsx(W,{value:"unbanned",children:"未封禁"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"格式"}),e.jsxs(Ie,{value:z,onValueChange:me=>{S(me),f(1)},children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"all",children:"全部"}),Ee.map(me=>e.jsxs(W,{value:me,children:[me.toUpperCase()," (",r?.formats[me],")"]},me))]})]})]})]}),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:[he.size>0&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["已选择 ",he.size," 个表情包"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"text-sm whitespace-nowrap",children:"卡片大小"}),e.jsxs(Ie,{value:G,onValueChange:me=>Se(me),children:[e.jsx(Be,{className:"w-24",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"small",children:"小"}),e.jsx(W,{value:"medium",children:"中"}),e.jsx(W,{value:"large",children:"大"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{htmlFor:"emoji-page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ie,{value:N.toString(),onValueChange:me=>{v(parseInt(me)),f(1),ge(new Set)},children:[e.jsx(Be,{id:"emoji-page-size",className:"w-20",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"20",children:"20"}),e.jsx(W,{value:"40",children:"40"}),e.jsx(W,{value:"60",children:"60"}),e.jsx(W,{value:"100",children:"100"})]})]}),he.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>ge(new Set),children:"取消选择"}),e.jsxs(_,{variant:"destructive",size:"sm",onClick:()=>Y(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsxs(_,{variant:"outline",size:"sm",onClick:B,disabled:d,children:[e.jsx(dt,{className:`h-4 w-4 mr-2 ${d?"animate-spin":""}`}),"刷新"]})})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"表情包列表"}),e.jsxs(os,{children:["共 ",p," 个表情包,当前第 ",h," 页"]})]}),e.jsxs(Me,{children:[a.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"暂无数据"}):e.jsx("div",{className:`grid gap-3 ${G==="small"?"grid-cols-3 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10":G==="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:a.map(me=>e.jsxs("div",{className:`group relative rounded-lg border bg-card overflow-hidden hover:ring-2 hover:ring-primary transition-all cursor-pointer ${he.has(me.id)?"ring-2 ring-primary bg-primary/5":""}`,onClick:()=>se(me.id),children:[e.jsx("div",{className:`absolute top-1 left-1 z-10 transition-opacity ${he.has(me.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 ${he.has(me.id)?"bg-primary border-primary text-primary-foreground":"bg-background/80 border-muted-foreground/50"}`,children:he.has(me.id)&&e.jsx(pt,{className:"h-3 w-3"})})}),e.jsxs("div",{className:"absolute top-1 right-1 z-10 flex flex-col gap-0.5",children:[me.is_registered&&e.jsx(ke,{variant:"default",className:"bg-green-600 text-[10px] px-1 py-0",children:"已注册"}),me.is_banned&&e.jsx(ke,{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 ${G==="small"?"p-1":G==="medium"?"p-2":"p-3"}`,children:e.jsx($4,{src:K4(me.id),alt:"表情包"})}),e.jsxs("div",{className:`border-t bg-card ${G==="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(ke,{variant:"outline",className:"text-[10px] px-1 py-0",children:me.format.toUpperCase()}),e.jsxs("span",{className:"font-mono",children:[me.usage_count,"次"]})]}),e.jsxs("div",{className:`flex gap-1 justify-center opacity-0 group-hover:opacity-100 transition-opacity ${G==="small"?"flex-wrap":""}`,children:[e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:ze=>{ze.stopPropagation(),Ae(me)},title:"编辑",children:e.jsx(Jn,{className:"h-3 w-3"})}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:ze=>{ze.stopPropagation(),Q(me)},title:"详情",children:e.jsx(Ft,{className:"h-3 w-3"})}),!me.is_registered&&e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6 text-green-600 hover:text-green-700",onClick:ze=>{ze.stopPropagation(),$e(me)},title:"注册",children:e.jsx(pt,{className:"h-3 w-3"})}),!me.is_banned&&e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6 text-orange-600 hover:text-orange-700",onClick:ze=>{ze.stopPropagation(),H(me)},title:"封禁",children:e.jsx(z_,{className:"h-3 w-3"})}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6 text-red-600 hover:text-red-700",onClick:ze=>{ze.stopPropagation(),ee(me)},title:"删除",children:e.jsx(ns,{className:"h-3 w-3"})})]})]})]},me.id))}),p>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["显示 ",(h-1)*N+1," 到"," ",Math.min(h*N,p)," 条,共 ",p," 条"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(me=>Math.max(1,me-1)),disabled:h===1,children:[e.jsx(Da,{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(le,{type:"number",value:$,onChange:me=>ue(me.target.value),onKeyDown:me=>me.key==="Enter"&&ie(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(p/N)}),e.jsx(_,{variant:"outline",size:"sm",onClick:ie,disabled:!$,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(me=>me+1),disabled:h>=Math.ceil(p/N),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(p/N)),disabled:h>=Math.ceil(p/N),className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]})]}),e.jsx(Z4,{emoji:I,open:X,onOpenChange:L}),e.jsx(W4,{emoji:I,open:oe,onOpenChange:Ne,onSuccess:()=>{B(),M()}}),e.jsx(ek,{open:fe,onOpenChange:Te,onSuccess:()=>{B(),M()}})]})}),e.jsx(Ns,{open:R,onOpenChange:Y,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["你确定要删除选中的 ",he.size," 个表情包吗?此操作不可撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:Ue,children:"确认删除"})]})]})}),e.jsx(Ps,{open:je,onOpenChange:de,children:e.jsxs(Ds,{children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"确认删除"}),e.jsx(Ks,{children:"确定要删除这个表情包吗?此操作无法撤销。"})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>de(!1),children:"取消"}),e.jsx(_,{variant:"destructive",onClick:J,children:"删除"})]})]})})]})}function Z4({emoji:a,open:n,onOpenChange:r}){if(!a)return null;const c=d=>d?new Date(d*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[90vh]",children:[e.jsx(Os,{children:e.jsx(Ls,{children:"表情包详情"})}),e.jsx(Je,{className:"max-h-[calc(90vh-8rem)] pr-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-32 h-32 bg-muted rounded-lg flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:Q4(a.id),alt:a.description||"表情包",className:"w-full h-full object-cover",onError:d=>{const u=d.target;u.style.display="none";const h=u.parentElement;h&&(h.innerHTML='')}})})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"ID"}),e.jsx("div",{className:"mt-1 font-mono",children:a.id})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"格式"}),e.jsx("div",{className:"mt-1",children:e.jsx(ke,{variant:"outline",children:a.format.toUpperCase()})})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"文件路径"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:a.full_path})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"哈希值"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:a.emoji_hash})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"描述"}),a.description?e.jsx("div",{className:"mt-1 rounded-lg border bg-muted/50 p-3",children:e.jsx(B4,{className:"prose-sm",children:a.description})}):e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"-"})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"情绪"}),e.jsx("div",{className:"mt-1",children:a.emotion?e.jsx("span",{className:"text-sm",children:a.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(T,{className:"text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[a.is_registered&&e.jsx(ke,{variant:"default",className:"bg-green-600",children:"已注册"}),a.is_banned&&e.jsx(ke,{variant:"destructive",children:"已封禁"}),!a.is_registered&&!a.is_banned&&e.jsx(ke,{variant:"outline",children:"未注册"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"使用次数"}),e.jsx("div",{className:"mt-1 font-mono text-lg",children:a.usage_count})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"记录时间"}),e.jsx("div",{className:"mt-1 text-sm",children:c(a.record_time)})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"注册时间"}),e.jsx("div",{className:"mt-1 text-sm",children:c(a.register_time)})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"最后使用"}),e.jsx("div",{className:"mt-1 text-sm",children:c(a.last_used_time)})]})]})})]})})}function W4({emoji:a,open:n,onOpenChange:r,onSuccess:c}){const[d,u]=m.useState(""),[h,f]=m.useState(!1),[p,g]=m.useState(!1),[N,v]=m.useState(!1),{toast:w}=Ys();m.useEffect(()=>{a&&(u(a.emotion||""),f(a.is_registered),g(a.is_banned))},[a]);const b=async()=>{if(a)try{v(!0);const y=d.split(/[,,]/).map(A=>A.trim()).filter(Boolean).join(",");await F4(a.id,{emotion:y||void 0,is_registered:h,is_banned:p}),w({title:"成功",description:"表情包信息已更新"}),r(!1),c()}catch(y){const A=y instanceof Error?y.message:"保存失败";w({title:"错误",description:A,variant:"destructive"})}finally{v(!1)}};return a?e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑表情包"}),e.jsx(Ks,{children:"修改表情包的情绪和状态信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(T,{children:"情绪"}),e.jsx(ot,{value:d,onChange:y=>u(y.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(qs,{id:"is_registered",checked:h,onCheckedChange:y=>{y===!0?(f(!0),g(!1)):f(!1)}}),e.jsx(T,{htmlFor:"is_registered",className:"cursor-pointer",children:"已注册"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"is_banned",checked:p,onCheckedChange:y=>{y===!0?(g(!0),f(!1)):g(!1)}}),e.jsx(T,{htmlFor:"is_banned",className:"cursor-pointer",children:"已封禁"})]})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:b,disabled:N,children:N?"保存中...":"保存"})]})]})}):null}function ek({open:a,onOpenChange:n,onSuccess:r}){const[c,d]=m.useState("select"),[u,h]=m.useState([]),[f,p]=m.useState(null),[g,N]=m.useState(!1),{toast:v}=Ys(),w=m.useMemo(()=>new x1({id:"emoji-uploader",autoProceed:!1,restrictions:{maxFileSize:10485760,allowedFileTypes:["image/jpeg","image/png","image/gif","image/webp"],maxNumberOfFiles:20},locale:{pluralize:()=>0,strings:{addMoreFiles:"添加更多文件",addingMoreFiles:"正在添加更多文件",allowedFileTypes:"允许的文件类型:%{types}",cancel:"取消",closeModal:"关闭",complete:"完成",connectedToInternet:"已连接到互联网",copyLink:"复制链接",copyLinkToClipboardFallback:"复制下方链接",copyLinkToClipboardSuccess:"链接已复制到剪贴板",dashboardTitle:"选择文件",dashboardWindowTitle:"文件选择窗口(按 ESC 关闭)",done:"完成",dropHereOr:"拖放文件到这里或 %{browse}",dropHint:"将文件拖放到此处",dropPasteFiles:"将文件拖放到这里或 %{browseFiles}",dropPasteFolders:"将文件拖放到这里或 %{browseFolders}",dropPasteBoth:"将文件拖放到这里,%{browseFiles} 或 %{browseFolders}",dropPasteImportFiles:"将文件拖放到这里,%{browseFiles} 或从以下位置导入:",dropPasteImportFolders:"将文件拖放到这里,%{browseFolders} 或从以下位置导入:",dropPasteImportBoth:"将文件拖放到这里,%{browseFiles},%{browseFolders} 或从以下位置导入:",editFile:"编辑文件",editing:"正在编辑 %{file}",emptyFolderAdded:"未从空文件夹添加文件",exceedsSize:"%{file} 超过了最大允许大小 %{size}",failedToUpload:"上传 %{file} 失败",fileSource:"文件来源:%{name}",filesUploadedOfTotal:{0:"已上传 %{complete} / %{smart_count} 个文件",1:"已上传 %{complete} / %{smart_count} 个文件"},filter:"筛选",finishEditingFile:"完成编辑文件",folderAdded:{0:"已从 %{folder} 添加 %{smart_count} 个文件",1:"已从 %{folder} 添加 %{smart_count} 个文件"},generatingThumbnails:"正在生成缩略图...",import:"导入",importFiles:"从以下位置导入文件:",importFrom:"从 %{name} 导入",loading:"加载中...",logOut:"登出",myDevice:"我的设备",noFilesFound:"这里没有文件或文件夹",noInternetConnection:"无网络连接",openFolderNamed:"打开文件夹 %{name}",pause:"暂停",pauseUpload:"暂停上传",paused:"已暂停",poweredBy:"技术支持:%{uppy}",processingXFiles:{0:"正在处理 %{smart_count} 个文件",1:"正在处理 %{smart_count} 个文件"},recording:"录制中",removeFile:"移除文件",resetFilter:"重置筛选",resume:"继续",resumeUpload:"继续上传",retry:"重试",retryUpload:"重试上传",save:"保存",saveChanges:"保存更改",selectFileNamed:"选择文件 %{name}",selectX:{0:"选择 %{smart_count}",1:"选择 %{smart_count}"},smile:"笑一个!",startRecording:"开始录制视频",stopRecording:"停止录制视频",takePicture:"拍照",timedOut:"上传已停滞 %{seconds} 秒,正在中止。",upload:"下一步",uploadComplete:"上传完成",uploadFailed:"上传失败",uploadPaused:"上传已暂停",uploadXFiles:{0:"下一步(%{smart_count} 个文件)",1:"下一步(%{smart_count} 个文件)"},uploadXNewFiles:{0:"下一步(+%{smart_count} 个文件)",1:"下一步(+%{smart_count} 个文件)"},uploading:"正在上传",uploadingXFiles:{0:"正在上传 %{smart_count} 个文件",1:"正在上传 %{smart_count} 个文件"},xFilesSelected:{0:"已选择 %{smart_count} 个文件",1:"已选择 %{smart_count} 个文件"},xMoreFilesAdded:{0:"又添加了 %{smart_count} 个文件",1:"又添加了 %{smart_count} 个文件"},xTimeLeft:"剩余 %{time}",youCanOnlyUploadFileTypes:"您只能上传:%{types}",youCanOnlyUploadX:{0:"您只能上传 %{smart_count} 个文件",1:"您只能上传 %{smart_count} 个文件"},youHaveToAtLeastSelectX:{0:"您至少需要选择 %{smart_count} 个文件",1:"您至少需要选择 %{smart_count} 个文件"},browseFiles:"浏览文件",browseFolders:"浏览文件夹",cancelUpload:"取消上传",addMore:"添加更多",back:"返回",editFileWithFilename:"编辑文件 %{file}"}}}),[]);m.useEffect(()=>{const I=()=>{const O=w.getFiles();if(O.length===0)return;const X=O.map(L=>({id:L.id,name:L.name,previewUrl:L.preview||URL.createObjectURL(L.data),emotion:"",description:"",isRegistered:!0,file:L.data}));h(X),O.length===1?(p(X[0].id),d("edit-single")):d("edit-multiple")};return w.on("upload",I),()=>{w.off("upload",I)}},[w]),m.useEffect(()=>{a||(w.cancelAll(),d("select"),h([]),p(null),N(!1))},[a,w]);const b=m.useCallback((I,O)=>{h(X=>X.map(L=>L.id===I?{...L,...O}:L))},[]),y=m.useCallback(I=>I.emotion.trim().length>0,[]),A=m.useMemo(()=>u.length>0&&u.every(y),[u,y]),z=m.useMemo(()=>u.find(I=>I.id===f)||null,[u,f]),S=m.useCallback(()=>{(c==="edit-single"||c==="edit-multiple")&&(d("select"),h([]),p(null))},[c]),U=m.useCallback(async()=>{if(!A){v({title:"请填写必填项",description:"每个表情包的情感标签都是必填的",variant:"destructive"});return}N(!0);let I=0,O=0;try{for(const X of u){const L=new FormData;L.append("file",X.file),L.append("emotion",X.emotion),L.append("description",X.description),L.append("is_registered",X.isRegistered.toString());try{(await _e(J4(),{method:"POST",body:L})).ok?I++:O++}catch{O++}}O===0?(v({title:"上传成功",description:`成功上传 ${I} 个表情包`}),n(!1),r()):(v({title:"部分上传失败",description:`成功 ${I} 个,失败 ${O} 个`,variant:"destructive"}),r())}finally{N(!1)}},[A,u,v,n,r]),E=()=>e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"border rounded-lg overflow-hidden w-full",children:e.jsx(U4,{uppy:w,proudlyDisplayPoweredByUppy:!1,hideProgressDetails:!0,height:350,width:"100%",theme:"auto",note:"支持 JPG、PNG、GIF、WebP 格式,最多 20 个文件"})})}),C=()=>{const I=u[0];return I?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:S,children:[e.jsx(Ma,{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(T,{htmlFor:"single-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(le,{id:"single-emotion",value:I.emotion,onChange:O=>b(I.id,{emotion:O.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(T,{htmlFor:"single-description",children:"描述"}),e.jsx(le,{id:"single-description",value:I.description,onChange:O=>b(I.id,{description:O.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"single-is-registered",checked:I.isRegistered,onCheckedChange:O=>b(I.id,{isRegistered:O===!0})}),e.jsx(T,{htmlFor:"single-is-registered",className:"cursor-pointer",children:"上传后立即注册(可被麦麦使用)"})]})]})]}),e.jsx(st,{children:e.jsx(_,{onClick:U,disabled:!A||g,children:g?"上传中...":"上传"})})]}):null},D=()=>{const I=u.filter(y).length,O=u.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(_,{variant:"ghost",size:"sm",onClick:S,children:[e.jsx(Ma,{className:"h-4 w-4 mr-1"}),"返回"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["编辑表情包信息(",I,"/",O," 已完成)"]})]}),e.jsx(ke,{variant:A?"default":"secondary",children:A?e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"h-3 w-3 mr-1"}),"全部完成"]}):e.jsxs(e.Fragment,{children:[e.jsx(Aa,{className:"h-3 w-3 mr-1"}),"未完成"]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Je,{className:"h-[350px] pr-2",children:e.jsx("div",{className:"space-y-2",children:u.map(X=>{const L=y(X),oe=f===X.id;return e.jsxs("div",{onClick:()=>p(X.id),className:` + flex items-center gap-3 p-3 rounded-lg border-2 cursor-pointer transition-all + ${oe?"ring-2 ring-primary":""} + ${L?"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:X.previewUrl,alt:X.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:X.name}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:X.emotion||"未填写情感标签"})]}),L?e.jsx(pt,{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"})]},X.id)})})}),e.jsx("div",{className:"border rounded-lg p-4",children:z?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:z.previewUrl,alt:z.name,className:"max-w-full max-h-full object-contain"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:z.name}),y(z)&&e.jsxs(ke,{variant:"outline",className:"text-green-600 border-green-600",children:[e.jsx(Ct,{className:"h-3 w-3 mr-1"}),"已完成"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"multi-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(le,{id:"multi-emotion",value:z.emotion,onChange:X=>b(z.id,{emotion:X.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:z.emotion.trim()?"":"border-destructive"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"multi-description",children:"描述"}),e.jsx(le,{id:"multi-description",value:z.description,onChange:X=>b(z.id,{description:X.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"multi-is-registered",checked:z.isRegistered,onCheckedChange:X=>b(z.id,{isRegistered:X===!0})}),e.jsx(T,{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(ix,{className:"h-12 w-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"点击左侧卡片编辑"})]})})})]}),e.jsx(st,{children:e.jsx(_,{onClick:U,disabled:!A||g,children:g?"上传中...":`上传全部 (${O})`})})]})};return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-3xl max-h-[90vh] overflow-hidden",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(rc,{className:"h-5 w-5"}),c==="select"&&"上传表情包 - 选择文件",c==="edit-single"&&"上传表情包 - 填写信息",c==="edit-multiple"&&"上传表情包 - 批量编辑"]}),e.jsxs(Ks,{children:[c==="select"&&"支持 JPG、PNG、GIF、WebP 格式,单个文件最大 10MB,可同时上传多个文件",c==="edit-single"&&"请填写表情包的情感标签(必填)和描述",c==="edit-multiple"&&"点击左侧卡片编辑每个表情包的信息,情感标签为必填项"]})]}),e.jsxs("div",{className:"overflow-y-auto pr-1",children:[c==="select"&&E(),c==="edit-single"&&C(),c==="edit-multiple"&&D()]})]})})}function sk(){const[a,n]=m.useState([]),[r,c]=m.useState(!0),[d,u]=m.useState(0),[h,f]=m.useState(1),[p,g]=m.useState(20),[N,v]=m.useState(""),[w,b]=m.useState(null),[y,A]=m.useState(!1),[z,S]=m.useState(!1),[U,E]=m.useState(!1),[C,D]=m.useState(null),[I,O]=m.useState(new Set),[X,L]=m.useState(!1),[oe,Ne]=m.useState(""),[je,de]=m.useState({total:0,recent_7days:0,chat_count:0,top_chats:{}}),[he,ge]=m.useState([]),[R,Y]=m.useState(new Map),[$,ue]=m.useState(!1),[G,Se]=m.useState(0),{toast:fe}=Ys(),Te=async()=>{try{c(!0);const ie=await J1({page:h,page_size:p,search:N||void 0});n(ie.data),u(ie.total)}catch(ie){fe({title:"加载失败",description:ie instanceof Error?ie.message:"无法加载表达方式",variant:"destructive"})}finally{c(!1)}},q=async()=>{try{const ie=await t2();ie?.data&&de(ie.data)}catch(ie){console.error("加载统计数据失败:",ie)}},B=async()=>{try{const ie=await mx();Se(ie.unchecked)}catch(ie){console.error("加载审核统计失败:",ie)}},M=async()=>{try{const ie=await ux();if(ie?.data){ge(ie.data);const Ee=new Map;ie.data.forEach(me=>{Ee.set(me.chat_id,me.chat_name)}),Y(Ee)}}catch(ie){console.error("加载聊天列表失败:",ie)}},Q=ie=>R.get(ie)||ie;m.useEffect(()=>{Te(),B(),q(),M()},[h,p,N]);const Ae=async ie=>{try{const Ee=await X1(ie.id);b(Ee.data),A(!0)}catch(Ee){fe({title:"加载详情失败",description:Ee instanceof Error?Ee.message:"无法加载表达方式详情",variant:"destructive"})}},ee=ie=>{b(ie),S(!0)},J=async ie=>{try{await e2(ie.id),fe({title:"删除成功",description:`已删除表达方式: ${ie.situation}`}),D(null),Te(),q()}catch(Ee){fe({title:"删除失败",description:Ee instanceof Error?Ee.message:"无法删除表达方式",variant:"destructive"})}},$e=ie=>{const Ee=new Set(I);Ee.has(ie)?Ee.delete(ie):Ee.add(ie),O(Ee)},H=()=>{I.size===a.length&&a.length>0?O(new Set):O(new Set(a.map(ie=>ie.id)))},se=async()=>{try{await s2(Array.from(I)),fe({title:"批量删除成功",description:`已删除 ${I.size} 个表达方式`}),O(new Set),L(!1),Te(),q()}catch(ie){fe({title:"批量删除失败",description:ie instanceof Error?ie.message:"无法批量删除表达方式",variant:"destructive"})}},Ue=()=>{const ie=parseInt(oe),Ee=Math.ceil(d/p);ie>=1&&ie<=Ee?(f(ie),Ne("")):fe({title:"无效的页码",description:`请输入1-${Ee}之间的页码`,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(Ra,{className:"h-8 w-8",strokeWidth:2}),"表达方式管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦的表达方式和话术模板"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(_,{variant:"outline",onClick:()=>ue(!0),className:"gap-2",children:[e.jsx(Wj,{className:"h-4 w-4"}),"人工审核",G>0&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 text-xs rounded-full bg-orange-500 text-white",children:G>99?"99+":G})]}),e.jsxs(_,{onClick:()=>E(!0),className:"gap-2",children:[e.jsx(et,{className:"h-4 w-4"}),"新增表达方式"]})]})]})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"总数量"}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:je.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:je.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:je.chat_count})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx(T,{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(Tt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(le,{id:"search",placeholder:"搜索情境、风格或上下文...",value:N,onChange:ie=>v(ie.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(T,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ie,{value:p.toString(),onValueChange:ie=>{g(parseInt(ie)),f(1),O(new Set)},children:[e.jsx(Be,{id:"page-size",className:"w-20",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"10",children:"10"}),e.jsx(W,{value:"20",children:"20"}),e.jsx(W,{value:"50",children:"50"}),e.jsx(W,{value:"100",children:"100"})]})]}),I.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(new Set),children:"取消选择"}),e.jsxs(_,{variant:"destructive",size:"sm",onClick:()=>L(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:I.size===a.length&&a.length>0,onCheckedChange:H})}),e.jsx(We,{children:"情境"}),e.jsx(We,{children:"风格"}),e.jsx(We,{children:"聊天"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:r?e.jsx(ut,{children:e.jsx(Ke,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):a.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):a.map(ie=>e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(qs,{checked:I.has(ie.id),onCheckedChange:()=>$e(ie.id)})}),e.jsx(Ke,{className:"font-medium max-w-xs truncate",children:ie.situation}),e.jsx(Ke,{className:"max-w-xs truncate",children:ie.style}),e.jsx(Ke,{className:"max-w-[200px] truncate",title:Q(ie.chat_id),style:{wordBreak:"keep-all"},children:e.jsx("span",{className:"whitespace-nowrap overflow-hidden text-ellipsis block",children:Q(ie.chat_id)})}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>ee(ie),children:[e.jsx(Jn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>Ae(ie),title:"查看详情",children:e.jsx(ia,{className:"h-4 w-4"})}),e.jsxs(_,{size:"sm",onClick:()=>D(ie),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},ie.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):a.map(ie=>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(qs,{checked:I.has(ie.id),onCheckedChange:()=>$e(ie.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:ie.situation,children:ie.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:ie.style,children:ie.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:Q(ie.chat_id),style:{wordBreak:"keep-all"},children:Q(ie.chat_id)})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>ee(ie),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(Jn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>Ae(ie),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:e.jsx(ia,{className:"h-3 w-3"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>D(ie),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(ns,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},ie.id))}),d>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:["共 ",d," 条记录,第 ",h," / ",Math.ceil(d/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Da,{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(le,{type:"number",value:oe,onChange:ie=>Ne(ie.target.value),onKeyDown:ie=>ie.key==="Enter"&&Ue(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(d/p)}),e.jsx(_,{variant:"outline",size:"sm",onClick:Ue,disabled:!oe,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(d/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(d/p)),disabled:h>=Math.ceil(d/p),className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(tk,{expression:w,open:y,onOpenChange:A,chatNameMap:R}),e.jsx(ak,{open:U,onOpenChange:E,chatList:he,onSuccess:()=>{Te(),q(),E(!1)}}),e.jsx(lk,{expression:w,open:z,onOpenChange:S,chatList:he,onSuccess:()=>{Te(),q(),S(!1)}}),e.jsx(Ns,{open:!!C,onOpenChange:()=>D(null),children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除表达方式 "',C?.situation,'" 吗? 此操作不可撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>C&&J(C),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(nk,{open:X,onOpenChange:L,onConfirm:se,count:I.size}),e.jsx(Dv,{open:$,onOpenChange:ie=>{ue(ie),ie||(Te(),q(),B())}})]})}function tk({expression:a,open:n,onOpenChange:r,chatNameMap:c}){if(!a)return null;const d=h=>h?new Date(h*1e3).toLocaleString("zh-CN"):"-",u=h=>c.get(h)||h;return e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"表达方式详情"}),e.jsx(Ks,{children:"查看表达方式的完整信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ki,{label:"情境",value:a.situation}),e.jsx(Ki,{label:"风格",value:a.style}),e.jsx(Ki,{label:"聊天",value:u(a.chat_id)}),e.jsx(Ki,{icon:Jr,label:"记录ID",value:a.id.toString(),mono:!0})]}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsx(Ki,{icon:na,label:"创建时间",value:d(a.create_date)})}),e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-4",children:[e.jsx(T,{className:"text-xs text-muted-foreground mb-3 block",children:"状态标记"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:F("flex h-8 w-8 items-center justify-center rounded-full",a.checked?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-400 dark:bg-gray-800 dark:text-gray-600"),children:a.checked?e.jsx(pt,{className:"h-5 w-5"}):e.jsx(Ho,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"已检查"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.checked?"已通过审核":"未审核"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:F("flex h-8 w-8 items-center justify-center rounded-full",a.rejected?"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400":"bg-gray-100 text-gray-400 dark:bg-gray-800 dark:text-gray-600"),children:a.rejected?e.jsx(Ka,{className:"h-5 w-5"}):e.jsx(Ho,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"已拒绝"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.rejected?"不会被使用":"正常"})]})]})]})]})]}),e.jsx(st,{children:e.jsx(_,{onClick:()=>r(!1),children:"关闭"})})]})})}function Ki({icon:a,label:n,value:r,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[a&&e.jsx(a,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:F("text-sm",c&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function ak({open:a,onOpenChange:n,chatList:r,onSuccess:c}){const[d,u]=m.useState({situation:"",style:"",chat_id:""}),[h,f]=m.useState(!1),{toast:p}=Ys(),g=async()=>{if(!d.situation||!d.style||!d.chat_id){p({title:"验证失败",description:"请填写必填字段:情境、风格和聊天",variant:"destructive"});return}try{f(!0),await Z1(d),p({title:"创建成功",description:"表达方式已创建"}),u({situation:"",style:"",chat_id:""}),c()}catch(N){p({title:"创建失败",description:N instanceof Error?N.message:"无法创建表达方式",variant:"destructive"})}finally{f(!1)}};return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"新增表达方式"}),e.jsx(Ks,{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(T,{htmlFor:"situation",children:["情境 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(le,{id:"situation",value:d.situation,onChange:N=>u({...d,situation:N.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"style",children:["风格 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(le,{id:"style",value:d.style,onChange:N=>u({...d,style:N.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Ie,{value:d.chat_id,onValueChange:N=>u({...d,chat_id:N}),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择关联的聊天"})}),e.jsx(Pe,{children:r.map(N=>e.jsx(W,{value:N.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[N.chat_name,N.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},N.chat_id))})]})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>n(!1),children:"取消"}),e.jsx(_,{onClick:g,disabled:h,children:h?"创建中...":"创建"})]})]})})}function lk({expression:a,open:n,onOpenChange:r,chatList:c,onSuccess:d}){const[u,h]=m.useState({}),[f,p]=m.useState(!1),{toast:g}=Ys();m.useEffect(()=>{a&&h({situation:a.situation,style:a.style,chat_id:a.chat_id,checked:a.checked,rejected:a.rejected})},[a]);const N=async()=>{if(a)try{p(!0),await W1(a.id,u),g({title:"保存成功",description:"表达方式已更新"}),d()}catch(v){g({title:"保存失败",description:v instanceof Error?v.message:"无法更新表达方式",variant:"destructive"})}finally{p(!1)}};return a?e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑表达方式"}),e.jsx(Ks,{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(T,{htmlFor:"edit_situation",children:"情境"}),e.jsx(le,{id:"edit_situation",value:u.situation||"",onChange:v=>h({...u,situation:v.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_style",children:"风格"}),e.jsx(le,{id:"edit_style",value:u.style||"",onChange:v=>h({...u,style:v.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Ie,{value:u.chat_id||"",onValueChange:v=>h({...u,chat_id:v}),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择关联的聊天"})}),e.jsx(Pe,{children:c.map(v=>e.jsx(W,{value:v.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[v.chat_name,v.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},v.chat_id))})]})]}),e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(lt,{className:"text-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{children:e.jsx("strong",{children:"状态标记说明:"})}),e.jsx("p",{children:"• 已检查:表示该表达方式已通过审核(可由AI自动检查或人工审核)"}),e.jsx("p",{children:"• 已拒绝:表示该表达方式被标记为不合适,将永远不会被使用"}),e.jsxs("p",{className:"text-muted-foreground mt-2",children:['根据配置中"仅使用已审核通过的表达方式"设置:',e.jsx("br",{}),"• 开启时:只有通过审核(已检查)的项目会被使用",e.jsx("br",{}),"• 关闭时:未审核的项目也会被使用"]})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between space-x-2 rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{htmlFor:"edit_checked",className:"text-sm font-medium",children:"已检查"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"已通过审核"})]}),e.jsx(Ve,{id:"edit_checked",checked:u.checked??!1,onCheckedChange:v=>h({...u,checked:v})})]}),e.jsxs("div",{className:"flex items-center justify-between space-x-2 rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{htmlFor:"edit_rejected",className:"text-sm font-medium",children:"已拒绝"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"不会被使用"})]}),e.jsx(Ve,{id:"edit_rejected",checked:u.rejected??!1,onCheckedChange:v=>h({...u,rejected:v})})]})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:N,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}function nk({open:a,onOpenChange:n,onConfirm:r,count:c}){return e.jsx(Ns,{open:a,onOpenChange:n,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["您即将删除 ",c," 个表达方式,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:r,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})}const Pl="/api/webui/jargon";async function rk(){const a=await _e(`${Pl}/chats`,{});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取聊天列表失败")}return a.json()}async function ik(a){const n=new URLSearchParams;a.page&&n.append("page",a.page.toString()),a.page_size&&n.append("page_size",a.page_size.toString()),a.search&&n.append("search",a.search),a.chat_id&&n.append("chat_id",a.chat_id),a.is_jargon!==void 0&&a.is_jargon!==null&&n.append("is_jargon",a.is_jargon.toString()),a.is_global!==void 0&&n.append("is_global",a.is_global.toString());const r=await _e(`${Pl}/list?${n}`,{});if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取黑话列表失败")}return r.json()}async function ck(a){const n=await _e(`${Pl}/${a}`,{});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取黑话详情失败")}return n.json()}async function ok(a){const n=await _e(`${Pl}/`,{method:"POST",body:JSON.stringify(a)});if(!n.ok){const r=await n.json();throw new Error(r.detail||"创建黑话失败")}return n.json()}async function dk(a,n){const r=await _e(`${Pl}/${a}`,{method:"PATCH",body:JSON.stringify(n)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"更新黑话失败")}return r.json()}async function uk(a){const n=await _e(`${Pl}/${a}`,{method:"DELETE"});if(!n.ok){const r=await n.json();throw new Error(r.detail||"删除黑话失败")}return n.json()}async function mk(a){const n=await _e(`${Pl}/batch/delete`,{method:"POST",body:JSON.stringify({ids:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"批量删除黑话失败")}return n.json()}async function xk(){const a=await _e(`${Pl}/stats/summary`,{});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取黑话统计失败")}return a.json()}async function hk(a,n){const r=new URLSearchParams;a.forEach(d=>r.append("ids",d.toString())),r.append("is_jargon",n.toString());const c=await _e(`${Pl}/batch/set-jargon?${r}`,{method:"POST"});if(!c.ok){const d=await c.json();throw new Error(d.detail||"批量设置黑话状态失败")}return c.json()}function fk(){const[a,n]=m.useState([]),[r,c]=m.useState(!0),[d,u]=m.useState(0),[h,f]=m.useState(1),[p,g]=m.useState(20),[N,v]=m.useState(""),[w,b]=m.useState("all"),[y,A]=m.useState("all"),[z,S]=m.useState(null),[U,E]=m.useState(!1),[C,D]=m.useState(!1),[I,O]=m.useState(!1),[X,L]=m.useState(null),[oe,Ne]=m.useState(new Set),[je,de]=m.useState(!1),[he,ge]=m.useState(""),[R,Y]=m.useState({total:0,confirmed_jargon:0,confirmed_not_jargon:0,pending:0,global_count:0,complete_count:0,chat_count:0,top_chats:{}}),[$,ue]=m.useState([]),{toast:G}=Ys(),Se=async()=>{try{c(!0);const se=await ik({page:h,page_size:p,search:N||void 0,chat_id:w==="all"?void 0:w,is_jargon:y==="all"?void 0:y==="true"?!0:y==="false"?!1:void 0});n(se.data),u(se.total)}catch(se){G({title:"加载失败",description:se instanceof Error?se.message:"无法加载黑话列表",variant:"destructive"})}finally{c(!1)}},fe=async()=>{try{const se=await xk();se?.data&&Y(se.data)}catch(se){console.error("加载统计数据失败:",se)}},Te=async()=>{try{const se=await rk();se?.data&&ue(se.data)}catch(se){console.error("加载聊天列表失败:",se)}};m.useEffect(()=>{Se(),fe(),Te()},[h,p,N,w,y]);const q=async se=>{try{const Ue=await ck(se.id);S(Ue.data),E(!0)}catch(Ue){G({title:"加载详情失败",description:Ue instanceof Error?Ue.message:"无法加载黑话详情",variant:"destructive"})}},B=se=>{S(se),D(!0)},M=async se=>{try{await uk(se.id),G({title:"删除成功",description:`已删除黑话: ${se.content}`}),L(null),Se(),fe()}catch(Ue){G({title:"删除失败",description:Ue instanceof Error?Ue.message:"无法删除黑话",variant:"destructive"})}},Q=se=>{const Ue=new Set(oe);Ue.has(se)?Ue.delete(se):Ue.add(se),Ne(Ue)},Ae=()=>{oe.size===a.length&&a.length>0?Ne(new Set):Ne(new Set(a.map(se=>se.id)))},ee=async()=>{try{await mk(Array.from(oe)),G({title:"批量删除成功",description:`已删除 ${oe.size} 个黑话`}),Ne(new Set),de(!1),Se(),fe()}catch(se){G({title:"批量删除失败",description:se instanceof Error?se.message:"无法批量删除黑话",variant:"destructive"})}},J=async se=>{try{await hk(Array.from(oe),se),G({title:"操作成功",description:`已将 ${oe.size} 个词条设为${se?"黑话":"非黑话"}`}),Ne(new Set),Se(),fe()}catch(Ue){G({title:"操作失败",description:Ue instanceof Error?Ue.message:"批量设置失败",variant:"destructive"})}},$e=()=>{const se=parseInt(he),Ue=Math.ceil(d/p);se>=1&&se<=Ue?(f(se),ge("")):G({title:"无效的页码",description:`请输入1-${Ue}之间的页码`,variant:"destructive"})},H=se=>se===!0?e.jsxs(ke,{variant:"default",className:"bg-green-600 hover:bg-green-700",children:[e.jsx(Ct,{className:"h-3 w-3 mr-1"}),"是黑话"]}):se===!1?e.jsxs(ke,{variant:"secondary",children:[e.jsx(Aa,{className:"h-3 w-3 mr-1"}),"非黑话"]}):e.jsxs(ke,{variant:"outline",children:[e.jsx(sv,{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(R_,{className:"h-8 w-8",strokeWidth:2}),"黑话管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦学习到的黑话和俚语"})]}),e.jsxs(_,{onClick:()=>O(!0),className:"gap-2",children:[e.jsx(et,{className:"h-4 w-4"}),"新增黑话"]})]})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-7 gap-3",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"总数量"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1",children:R.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:R.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:R.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:R.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:R.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:R.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:R.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(T,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(le,{id:"search",placeholder:"搜索内容、含义...",value:N,onChange:se=>v(se.target.value),className:"pl-9"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{children:"聊天筛选"}),e.jsxs(Ie,{value:w,onValueChange:b,children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"全部聊天"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"all",children:"全部聊天"}),$.map(se=>e.jsx(W,{value:se.chat_id,children:se.chat_name},se.chat_id))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{children:"状态筛选"}),e.jsxs(Ie,{value:y,onValueChange:A,children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"全部状态"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"all",children:"全部状态"}),e.jsx(W,{value:"true",children:"是黑话"}),e.jsx(W,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{htmlFor:"page-size",children:"每页显示"}),e.jsxs(Ie,{value:p.toString(),onValueChange:se=>{g(parseInt(se)),f(1),Ne(new Set)},children:[e.jsx(Be,{id:"page-size",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"10",children:"10"}),e.jsx(W,{value:"20",children:"20"}),e.jsx(W,{value:"50",children:"50"}),e.jsx(W,{value:"100",children:"100"})]})]})]})]}),oe.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:["已选择 ",oe.size," 个"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>J(!0),children:[e.jsx(Ct,{className:"h-4 w-4 mr-1"}),"标记为黑话"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>J(!1),children:[e.jsx(Aa,{className:"h-4 w-4 mr-1"}),"标记为非黑话"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>Ne(new Set),children:"取消选择"}),e.jsxs(_,{variant:"destructive",size:"sm",onClick:()=>de(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:oe.size===a.length&&a.length>0,onCheckedChange:Ae})}),e.jsx(We,{children:"内容"}),e.jsx(We,{children:"含义"}),e.jsx(We,{children:"聊天"}),e.jsx(We,{children:"状态"}),e.jsx(We,{className:"text-center",children:"次数"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:r?e.jsx(ut,{children:e.jsx(Ke,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):a.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):a.map(se=>e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(qs,{checked:oe.has(se.id),onCheckedChange:()=>Q(se.id)})}),e.jsx(Ke,{className:"font-medium max-w-[200px]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[se.is_global&&e.jsx("span",{title:"全局黑话",children:e.jsx(Vo,{className:"h-4 w-4 text-blue-500 flex-shrink-0"})}),e.jsx("span",{className:"truncate",title:se.content,children:se.content})]})}),e.jsx(Ke,{className:"max-w-[200px] truncate",title:se.meaning||"",children:se.meaning||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ke,{className:"max-w-[150px] truncate",title:se.chat_name||se.chat_id,children:se.chat_name||se.chat_id}),e.jsx(Ke,{children:H(se.is_jargon)}),e.jsx(Ke,{className:"text-center",children:se.count}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>B(se),children:[e.jsx(Jn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>q(se),title:"查看详情",children:e.jsx(ia,{className:"h-4 w-4"})}),e.jsxs(_,{size:"sm",onClick:()=>L(se),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},se.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):a.map(se=>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(qs,{checked:oe.has(se.id),onCheckedChange:()=>Q(se.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:[se.is_global&&e.jsx(Vo,{className:"h-4 w-4 text-blue-500 flex-shrink-0"}),e.jsx("h3",{className:"font-semibold text-sm break-all",children:se.content})]}),se.meaning&&e.jsx("p",{className:"text-sm text-muted-foreground break-all",children:se.meaning}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:[H(se.is_jargon),e.jsxs("span",{className:"text-muted-foreground",children:["次数: ",se.count]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:["聊天: ",se.chat_name||se.chat_id]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>B(se),className:"text-xs px-2 py-1 h-auto",children:[e.jsx(Jn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>q(se),className:"text-xs px-2 py-1 h-auto",children:e.jsx(ia,{className:"h-3 w-3"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>L(se),className:"text-xs px-2 py-1 h-auto text-destructive hover:text-destructive",children:[e.jsx(ns,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},se.id))}),d>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:["共 ",d," 条记录,第 ",h," / ",Math.ceil(d/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Da,{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(le,{type:"number",value:he,onChange:se=>ge(se.target.value),onKeyDown:se=>se.key==="Enter"&&$e(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(d/p)}),e.jsx(_,{variant:"outline",size:"sm",onClick:$e,disabled:!he,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(d/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(d/p)),disabled:h>=Math.ceil(d/p),className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(pk,{jargon:z,open:U,onOpenChange:E}),e.jsx(gk,{open:I,onOpenChange:O,chatList:$,onSuccess:()=>{Se(),fe(),O(!1)}}),e.jsx(jk,{jargon:z,open:C,onOpenChange:D,chatList:$,onSuccess:()=>{Se(),fe(),D(!1)}}),e.jsx(Ns,{open:!!X,onOpenChange:()=>L(null),children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除黑话 "',X?.content,'" 吗?此操作不可撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>X&&M(X),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(Ns,{open:je,onOpenChange:de,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["您即将删除 ",oe.size," 个黑话,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:ee,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})]})}function pk({jargon:a,open:n,onOpenChange:r}){return a?e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"黑话详情"}),e.jsx(Ks,{children:"查看黑话的完整信息"})]}),e.jsx(Je,{className:"h-full pr-4",children:e.jsxs("div",{className:"space-y-4 pb-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Hm,{icon:Jr,label:"记录ID",value:a.id.toString(),mono:!0}),e.jsx(Hm,{label:"使用次数",value:a.count.toString()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"内容"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all whitespace-pre-wrap",children:a.content})]}),a.raw_content&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"原始内容"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:(()=>{try{const c=JSON.parse(a.raw_content);return Array.isArray(c)?c.map((d,u)=>e.jsxs("div",{children:[u>0&&e.jsx("hr",{className:"my-3 border-border"}),e.jsx("div",{className:"whitespace-pre-wrap",children:d})]},u)):e.jsx("div",{className:"whitespace-pre-wrap",children:a.raw_content})}catch{return e.jsx("div",{className:"whitespace-pre-wrap",children:a.raw_content})}})()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"含义"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:a.meaning?e.jsx(fx,{content:a.meaning}):"-"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Hm,{label:"聊天",value:a.chat_name||a.chat_id}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"flex items-center gap-2",children:[a.is_jargon===!0&&e.jsx(ke,{variant:"default",className:"bg-green-600",children:"是黑话"}),a.is_jargon===!1&&e.jsx(ke,{variant:"secondary",children:"非黑话"}),a.is_jargon===null&&e.jsx(ke,{variant:"outline",children:"未判定"}),a.is_global&&e.jsx(ke,{variant:"outline",className:"border-blue-500 text-blue-500",children:"全局"}),a.is_complete&&e.jsx(ke,{variant:"outline",className:"border-purple-500 text-purple-500",children:"推断完成"})]})]})]}),a.inference_with_context&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{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:a.inference_with_context})]}),a.inference_content_only&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{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:a.inference_content_only})]})]})}),e.jsx(st,{className:"flex-shrink-0",children:e.jsx(_,{onClick:()=>r(!1),children:"关闭"})})]})}):null}function Hm({icon:a,label:n,value:r,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[a&&e.jsx(a,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:F("text-sm",c&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function gk({open:a,onOpenChange:n,chatList:r,onSuccess:c}){const[d,u]=m.useState({content:"",meaning:"",chat_id:"",is_global:!1}),[h,f]=m.useState(!1),{toast:p}=Ys(),g=async()=>{if(!d.content||!d.chat_id){p({title:"验证失败",description:"请填写必填字段:内容和聊天",variant:"destructive"});return}try{f(!0),await ok(d),p({title:"创建成功",description:"黑话已创建"}),u({content:"",meaning:"",chat_id:"",is_global:!1}),c()}catch(N){p({title:"创建失败",description:N instanceof Error?N.message:"无法创建黑话",variant:"destructive"})}finally{f(!1)}};return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"新增黑话"}),e.jsx(Ks,{children:"创建新的黑话记录"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"content",children:["内容 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(le,{id:"content",value:d.content,onChange:N=>u({...d,content:N.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"meaning",children:"含义"}),e.jsx(ot,{id:"meaning",value:d.meaning||"",onChange:N=>u({...d,meaning:N.target.value}),placeholder:"输入黑话含义(可选)",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Ie,{value:d.chat_id,onValueChange:N=>u({...d,chat_id:N}),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择关联的聊天"})}),e.jsx(Pe,{children:r.map(N=>e.jsx(W,{value:N.chat_id,children:N.chat_name},N.chat_id))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"is_global",checked:d.is_global,onCheckedChange:N=>u({...d,is_global:N})}),e.jsx(T,{htmlFor:"is_global",children:"设为全局黑话"})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>n(!1),children:"取消"}),e.jsx(_,{onClick:g,disabled:h,children:h?"创建中...":"创建"})]})]})})}function jk({jargon:a,open:n,onOpenChange:r,chatList:c,onSuccess:d}){const[u,h]=m.useState({}),[f,p]=m.useState(!1),{toast:g}=Ys();m.useEffect(()=>{a&&h({content:a.content,meaning:a.meaning||"",chat_id:a.stream_id||a.chat_id,is_global:a.is_global,is_jargon:a.is_jargon})},[a]);const N=async()=>{if(a)try{p(!0),await dk(a.id,u),g({title:"保存成功",description:"黑话已更新"}),d()}catch(v){g({title:"保存失败",description:v instanceof Error?v.message:"无法更新黑话",variant:"destructive"})}finally{p(!1)}};return a?e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑黑话"}),e.jsx(Ks,{children:"修改黑话的信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_content",children:"内容"}),e.jsx(le,{id:"edit_content",value:u.content||"",onChange:v=>h({...u,content:v.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_meaning",children:"含义"}),e.jsx(ot,{id:"edit_meaning",value:u.meaning||"",onChange:v=>h({...u,meaning:v.target.value}),placeholder:"输入黑话含义",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Ie,{value:u.chat_id||"",onValueChange:v=>h({...u,chat_id:v}),children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择关联的聊天"})}),e.jsx(Pe,{children:c.map(v=>e.jsx(W,{value:v.chat_id,children:v.chat_name},v.chat_id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"黑话状态"}),e.jsxs(Ie,{value:u.is_jargon===null?"null":u.is_jargon?.toString()||"null",onValueChange:v=>h({...u,is_jargon:v==="null"?null:v==="true"}),children:[e.jsx(Be,{children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"null",children:"未判定"}),e.jsx(W,{value:"true",children:"是黑话"}),e.jsx(W,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"edit_is_global",checked:u.is_global,onCheckedChange:v=>h({...u,is_global:v})}),e.jsx(T,{htmlFor:"edit_is_global",children:"全局黑话"})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:N,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}const si="/api/webui/person";async function vk(a){const n=new URLSearchParams;a.page&&n.append("page",a.page.toString()),a.page_size&&n.append("page_size",a.page_size.toString()),a.search&&n.append("search",a.search),a.is_known!==void 0&&n.append("is_known",a.is_known.toString()),a.platform&&n.append("platform",a.platform);const r=await _e(`${si}/list?${n}`,{headers:Hs()});if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取人物列表失败")}return r.json()}async function Nk(a){const n=await _e(`${si}/${a}`,{headers:Hs()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取人物详情失败")}return n.json()}async function bk(a,n){const r=await _e(`${si}/${a}`,{method:"PATCH",headers:Hs(),body:JSON.stringify(n)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"更新人物信息失败")}return r.json()}async function yk(a){const n=await _e(`${si}/${a}`,{method:"DELETE",headers:Hs()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"删除人物信息失败")}return n.json()}async function wk(){const a=await _e(`${si}/stats/summary`,{headers:Hs()});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取统计数据失败")}return a.json()}async function _k(a){const n=await _e(`${si}/batch/delete`,{method:"POST",headers:Hs(),body:JSON.stringify({person_ids:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"批量删除失败")}return n.json()}function Sk(){const[a,n]=m.useState([]),[r,c]=m.useState(!0),[d,u]=m.useState(0),[h,f]=m.useState(1),[p,g]=m.useState(20),[N,v]=m.useState(""),[w,b]=m.useState(void 0),[y,A]=m.useState(void 0),[z,S]=m.useState(null),[U,E]=m.useState(!1),[C,D]=m.useState(!1),[I,O]=m.useState(null),[X,L]=m.useState({total:0,known:0,unknown:0,platforms:{}}),[oe,Ne]=m.useState(new Set),[je,de]=m.useState(!1),[he,ge]=m.useState(""),{toast:R}=Ys(),Y=async()=>{try{c(!0);const ee=await vk({page:h,page_size:p,search:N||void 0,is_known:w,platform:y});n(ee.data),u(ee.total)}catch(ee){R({title:"加载失败",description:ee instanceof Error?ee.message:"无法加载人物信息",variant:"destructive"})}finally{c(!1)}},$=async()=>{try{const ee=await wk();ee?.data&&L(ee.data)}catch(ee){console.error("加载统计数据失败:",ee)}};m.useEffect(()=>{Y(),$()},[h,p,N,w,y]);const ue=async ee=>{try{const J=await Nk(ee.person_id);S(J.data),E(!0)}catch(J){R({title:"加载详情失败",description:J instanceof Error?J.message:"无法加载人物详情",variant:"destructive"})}},G=ee=>{S(ee),D(!0)},Se=async ee=>{try{await yk(ee.person_id),R({title:"删除成功",description:`已删除人物信息: ${ee.person_name||ee.nickname||ee.user_id}`}),O(null),Y(),$()}catch(J){R({title:"删除失败",description:J instanceof Error?J.message:"无法删除人物信息",variant:"destructive"})}},fe=m.useMemo(()=>Object.keys(X.platforms),[X.platforms]),Te=ee=>{const J=new Set(oe);J.has(ee)?J.delete(ee):J.add(ee),Ne(J)},q=()=>{oe.size===a.length&&a.length>0?Ne(new Set):Ne(new Set(a.map(ee=>ee.person_id)))},B=()=>{if(oe.size===0){R({title:"未选择任何人物",description:"请先选择要删除的人物",variant:"destructive"});return}de(!0)},M=async()=>{try{const ee=await _k(Array.from(oe));R({title:"批量删除完成",description:ee.message}),Ne(new Set),de(!1),Y(),$()}catch(ee){R({title:"批量删除失败",description:ee instanceof Error?ee.message:"批量删除失败",variant:"destructive"})}},Q=()=>{const ee=parseInt(he),J=Math.ceil(d/p);ee>=1&&ee<=J?(f(ee),ge("")):R({title:"无效的页码",description:`请输入1-${J}之间的页码`,variant:"destructive"})},Ae=ee=>ee?new Date(ee*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(ic,{className:"h-8 w-8",strokeWidth:2}),"人物信息管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦认识的所有人物信息"})]})})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"总人数"}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:X.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:X.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:X.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(T,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx(Tt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(le,{id:"search",placeholder:"搜索名称、昵称或用户ID...",value:N,onChange:ee=>v(ee.target.value),className:"pl-9"})]})]}),e.jsxs("div",{children:[e.jsx(T,{htmlFor:"filter-known",children:"认识状态"}),e.jsxs(Ie,{value:w===void 0?"all":w.toString(),onValueChange:ee=>{b(ee==="all"?void 0:ee==="true"),f(1)},children:[e.jsx(Be,{id:"filter-known",className:"mt-1.5",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"all",children:"全部"}),e.jsx(W,{value:"true",children:"已认识"}),e.jsx(W,{value:"false",children:"未认识"})]})]})]}),e.jsxs("div",{children:[e.jsx(T,{htmlFor:"filter-platform",children:"平台"}),e.jsxs(Ie,{value:y||"all",onValueChange:ee=>{A(ee==="all"?void 0:ee),f(1)},children:[e.jsx(Be,{id:"filter-platform",className:"mt-1.5",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"all",children:"全部平台"}),fe.map(ee=>e.jsxs(W,{value:ee,children:[ee," (",X.platforms[ee],")"]},ee))]})]})]})]}),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:oe.size>0&&e.jsxs("span",{children:["已选择 ",oe.size," 个人物"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Ie,{value:p.toString(),onValueChange:ee=>{g(parseInt(ee)),f(1),Ne(new Set)},children:[e.jsx(Be,{id:"page-size",className:"w-20",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"10",children:"10"}),e.jsx(W,{value:"20",children:"20"}),e.jsx(W,{value:"50",children:"50"}),e.jsx(W,{value:"100",children:"100"})]})]}),oe.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>Ne(new Set),children:"取消选择"}),e.jsxs(_,{variant:"destructive",size:"sm",onClick:B,children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:a.length>0&&oe.size===a.length,onCheckedChange:q,"aria-label":"全选"})}),e.jsx(We,{children:"状态"}),e.jsx(We,{children:"名称"}),e.jsx(We,{children:"昵称"}),e.jsx(We,{children:"平台"}),e.jsx(We,{children:"用户ID"}),e.jsx(We,{children:"最后更新"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:r?e.jsx(ut,{children:e.jsx(Ke,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):a.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):a.map(ee=>e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(qs,{checked:oe.has(ee.person_id),onCheckedChange:()=>Te(ee.person_id),"aria-label":`选择 ${ee.person_name||ee.nickname||ee.user_id}`})}),e.jsx(Ke,{children:e.jsx("div",{className:F("inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium",ee.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:ee.is_known?"已认识":"未认识"})}),e.jsx(Ke,{className:"font-medium",children:ee.person_name||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ke,{children:ee.nickname||"-"}),e.jsx(Ke,{children:ee.platform}),e.jsx(Ke,{className:"font-mono text-sm",children:ee.user_id}),e.jsx(Ke,{className:"text-sm text-muted-foreground",children:Ae(ee.last_know)}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>ue(ee),children:[e.jsx(ia,{className:"h-4 w-4 mr-1"}),"详情"]}),e.jsxs(_,{variant:"default",size:"sm",onClick:()=>G(ee),children:[e.jsx(Jn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>O(ee),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},ee.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):a.map(ee=>e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3 overflow-hidden",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(qs,{checked:oe.has(ee.person_id),onCheckedChange:()=>Te(ee.person_id),className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:F("inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium mb-2",ee.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:ee.is_known?"已认识":"未认识"}),e.jsx("h3",{className:"font-semibold text-sm line-clamp-1 w-full break-all",children:ee.person_name||e.jsx("span",{className:"text-muted-foreground",children:"未命名"})}),ee.nickname&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-1 w-full break-all",children:["昵称: ",ee.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:ee.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:ee.user_id,children:ee.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:Ae(ee.last_know)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>ue(ee),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(ia,{className:"h-3 w-3 mr-1"}),"查看"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>G(ee),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(Jn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>O(ee),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(ns,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},ee.id))}),d>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:["共 ",d," 条记录,第 ",h," / ",Math.ceil(d/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Da,{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(le,{type:"number",value:he,onChange:ee=>ge(ee.target.value),onKeyDown:ee=>ee.key==="Enter"&&Q(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(d/p)}),e.jsx(_,{variant:"outline",size:"sm",onClick:Q,disabled:!he,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(d/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(d/p)),disabled:h>=Math.ceil(d/p),className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(kk,{person:z,open:U,onOpenChange:E}),e.jsx(Ck,{person:z,open:C,onOpenChange:D,onSuccess:()=>{Y(),$(),D(!1)}}),e.jsx(Ns,{open:!!I,onOpenChange:()=>O(null),children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除人物信息 "',I?.person_name||I?.nickname||I?.user_id,'" 吗? 此操作不可撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>I&&Se(I),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(Ns,{open:je,onOpenChange:de,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["确定要删除选中的 ",oe.size," 个人物信息吗? 此操作不可撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:M,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})})]})}function kk({person:a,open:n,onOpenChange:r}){if(!a)return null;const c=d=>d?new Date(d*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"人物详情"}),e.jsxs(Ks,{children:["查看 ",a.person_name||a.nickname||a.user_id," 的完整信息"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Rl,{icon:jn,label:"人物名称",value:a.person_name}),e.jsx(Rl,{icon:Ra,label:"昵称",value:a.nickname}),e.jsx(Rl,{icon:Jr,label:"用户ID",value:a.user_id,mono:!0}),e.jsx(Rl,{icon:Jr,label:"人物ID",value:a.person_id,mono:!0}),e.jsx(Rl,{label:"平台",value:a.platform}),e.jsx(Rl,{label:"状态",value:a.is_known?"已认识":"未认识"})]}),a.name_reason&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"名称设定原因"}),e.jsx("p",{className:"mt-1 text-sm",children:a.name_reason})]}),a.memory_points&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"个人印象"}),e.jsx("p",{className:"mt-1 text-sm whitespace-pre-wrap",children:a.memory_points})]}),a.group_nick_name&&a.group_nick_name.length>0&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"群昵称"}),e.jsx("div",{className:"mt-2 space-y-1",children:a.group_nick_name.map((d,u)=>e.jsxs("div",{className:"text-sm flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:d.group_id}),e.jsx("span",{children:"→"}),e.jsx("span",{children:d.group_nick_name})]},u))})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(Rl,{icon:na,label:"认识时间",value:c(a.know_times)}),e.jsx(Rl,{icon:na,label:"首次记录",value:c(a.know_since)}),e.jsx(Rl,{icon:na,label:"最后更新",value:c(a.last_know)})]})]}),e.jsx(st,{children:e.jsx(_,{onClick:()=>r(!1),children:"关闭"})})]})})}function Rl({icon:a,label:n,value:r,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[a&&e.jsx(a,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:F("text-sm",c&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function Ck({person:a,open:n,onOpenChange:r,onSuccess:c}){const[d,u]=m.useState({}),[h,f]=m.useState(!1),{toast:p}=Ys();m.useEffect(()=>{a&&u({person_name:a.person_name||"",name_reason:a.name_reason||"",nickname:a.nickname||"",is_known:a.is_known})},[a]);const g=async()=>{if(a)try{f(!0),await bk(a.person_id,d),p({title:"保存成功",description:"人物信息已更新"}),c()}catch(N){p({title:"保存失败",description:N instanceof Error?N.message:"无法更新人物信息",variant:"destructive"})}finally{f(!1)}};return a?e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑人物信息"}),e.jsxs(Ks,{children:["修改 ",a.person_name||a.nickname||a.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(T,{htmlFor:"person_name",children:"人物名称"}),e.jsx(le,{id:"person_name",value:d.person_name||"",onChange:N=>u({...d,person_name:N.target.value}),placeholder:"为这个人设置一个名称"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"nickname",children:"昵称"}),e.jsx(le,{id:"nickname",value:d.nickname||"",onChange:N=>u({...d,nickname:N.target.value}),placeholder:"昵称"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"name_reason",children:"名称设定原因"}),e.jsx(ot,{id:"name_reason",value:d.name_reason||"",onChange:N=>u({...d,name_reason:N.target.value}),placeholder:"为什么这样称呼这个人?",rows:2})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{children:[e.jsx(T,{htmlFor:"is_known",className:"text-base font-medium",children:"已认识"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"标记是否已经认识这个人"})]}),e.jsx(Ve,{id:"is_known",checked:d.is_known,onCheckedChange:N=>u({...d,is_known:N})})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:g,disabled:h,children:h?"保存中...":"保存"})]})]})}):null}var Tk=j1();const Yg=lw(Tk),yx="/api/webui";async function Ek(a=100,n="all"){const r=`${yx}/knowledge/graph?limit=${a}&node_type=${n}`,c=await fetch(r);if(!c.ok)throw new Error(`获取知识图谱失败: ${c.status}`);return c.json()}async function Mk(){const a=await fetch(`${yx}/knowledge/stats`);if(!a.ok)throw new Error("获取知识图谱统计信息失败");return a.json()}async function Ak(a){const n=await fetch(`${yx}/knowledge/search?query=${encodeURIComponent(a)}`);if(!n.ok)throw new Error("搜索知识节点失败");return n.json()}const sN=m.memo(({data:a})=>e.jsxs("div",{className:"px-4 py-2 shadow-md rounded-lg bg-gradient-to-br from-blue-500 to-blue-600 border-2 border-blue-700 min-w-[120px]",children:[e.jsx(Ko,{type:"target",position:Qo.Top}),e.jsx("div",{className:"font-semibold text-white text-sm truncate max-w-[200px]",title:a.content,children:a.label}),e.jsx(Ko,{type:"source",position:Qo.Bottom})]}));sN.displayName="EntityNode";const tN=m.memo(({data:a})=>e.jsxs("div",{className:"px-3 py-2 shadow-md rounded-md bg-gradient-to-br from-green-500 to-green-600 border-2 border-green-700 min-w-[100px]",children:[e.jsx(Ko,{type:"target",position:Qo.Top}),e.jsx("div",{className:"font-medium text-white text-xs truncate max-w-[150px]",title:a.content,children:a.label}),e.jsx(Ko,{type:"source",position:Qo.Bottom})]}));tN.displayName="ParagraphNode";const zk={entity:sN,paragraph:tN};function Rk(a,n){const r=new Yg.graphlib.Graph;r.setDefaultEdgeLabel(()=>({})),r.setGraph({rankdir:"TB",ranksep:100,nodesep:80});const c=[],d=[];return a.forEach(u=>{r.setNode(u.id,{width:150,height:50})}),n.forEach(u=>{r.setEdge(u.source,u.target)}),Yg.layout(r),a.forEach(u=>{const h=r.node(u.id);c.push({id:u.id,type:u.type,position:{x:h.x-75,y:h.y-25},data:{label:u.content.slice(0,20)+(u.content.length>20?"...":""),content:u.content}})}),n.forEach((u,h)=>{const f={id:`edge-${h}`,source:u.source,target:u.target,animated:a.length<=200&&u.weight>5,style:{strokeWidth:Math.min(u.weight/2,5),opacity:.6}};u.weight>10&&a.length<100&&(f.label=`${u.weight.toFixed(0)}`),d.push(f)}),{nodes:c,edges:d}}function Dk(){const a=ca(),[n,r]=m.useState(!1),[c,d]=m.useState(null),[u,h]=m.useState(""),[f,p]=m.useState("all"),[g,N]=m.useState(50),[v,w]=m.useState("50"),[b,y]=m.useState(!1),[A,z]=m.useState(!0),[S,U]=m.useState(!1),[E,C]=m.useState(!1),[D,I,O]=v1([]),[X,L,oe]=N1([]),[Ne,je]=m.useState(0),[de,he]=m.useState(null),[ge,R]=m.useState(null),{toast:Y}=Ys(),$=m.useCallback(M=>M.type==="entity"?"#6366f1":M.type==="paragraph"?"#10b981":"#6b7280",[]),ue=m.useCallback(async(M=!1)=>{try{if(!M&&g>200){C(!0);return}r(!0);const[Q,Ae]=await Promise.all([Ek(g,f),Mk()]);if(d(Ae),Q.nodes.length===0){Y({title:"提示",description:"知识库为空,请先导入知识数据"}),I([]),L([]);return}const{nodes:ee,edges:J}=Rk(Q.nodes,Q.edges);I(ee),L(J),je(ee.length),Ae&&Ae.total_nodes>g&&Y({title:"提示",description:`知识图谱包含 ${Ae.total_nodes} 个节点,当前显示 ${ee.length} 个`}),Y({title:"加载成功",description:`已加载 ${ee.length} 个节点,${J.length} 条边`})}catch(Q){console.error("加载知识图谱失败:",Q),Y({title:"加载失败",description:Q instanceof Error?Q.message:"未知错误",variant:"destructive"})}finally{r(!1)}},[g,f,Y]),G=m.useCallback(async()=>{if(!u.trim()){Y({title:"提示",description:"请输入搜索关键词"});return}try{const M=await Ak(u);if(M.length===0){Y({title:"未找到",description:"没有找到匹配的节点"});return}const Q=new Set(M.map(Ae=>Ae.id));I(Ae=>Ae.map(ee=>({...ee,style:{...ee.style,opacity:Q.has(ee.id)?1:.3,filter:Q.has(ee.id)?"brightness(1.2)":"brightness(0.8)"}}))),Y({title:"搜索完成",description:`找到 ${M.length} 个匹配节点`})}catch(M){console.error("搜索失败:",M),Y({title:"搜索失败",description:M instanceof Error?M.message:"未知错误",variant:"destructive"})}},[u,Y]),Se=m.useCallback(()=>{I(M=>M.map(Q=>({...Q,style:{...Q.style,opacity:1,filter:"brightness(1)"}})))},[]),fe=m.useCallback(()=>{z(!1),U(!0),ue()},[ue]),Te=m.useCallback(()=>{C(!1),setTimeout(()=>{ue(!0)},0)},[ue]),q=m.useCallback((M,Q)=>{D.find(ee=>ee.id===Q.id)&&he({id:Q.id,type:Q.type,content:Q.data.content})},[D]);m.useEffect(()=>{A||S&&ue()},[g,f,A,S]);const B=m.useCallback((M,Q)=>{const Ae=D.find($e=>$e.id===Q.source),ee=D.find($e=>$e.id===Q.target),J=X.find($e=>$e.id===Q.id);Ae&&ee&&J&&R({source:{id:Ae.id,type:Ae.type,content:Ae.data.content},target:{id:ee.id,type:ee.type,content:ee.data.content},edge:{source:Q.source,target:Q.target,weight:parseFloat(Q.label||"0")}})},[D,X]);return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex-shrink-0 p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"麦麦知识库图谱"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"可视化知识实体与关系网络"})]}),c&&e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(Yr,{className:"h-3 w-3"}),"节点: ",c.total_nodes]}),e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(rv,{className:"h-3 w-3"}),"边: ",c.total_edges]}),e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(Ft,{className:"h-3 w-3"}),"实体: ",c.entity_nodes]}),e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(Ea,{className:"h-3 w-3"}),"段落: ",c.paragraph_nodes]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 mt-4",children:[e.jsxs("div",{className:"flex-1 flex gap-2",children:[e.jsx(le,{placeholder:"搜索节点内容...",value:u,onChange:M=>h(M.target.value),onKeyDown:M=>M.key==="Enter"&&G(),className:"flex-1"}),e.jsx(_,{onClick:G,size:"sm",children:e.jsx(Tt,{className:"h-4 w-4"})}),e.jsx(_,{onClick:Se,variant:"outline",size:"sm",children:"重置"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Ie,{value:f,onValueChange:M=>p(M),children:[e.jsx(Be,{className:"w-[120px]",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"all",children:"全部节点"}),e.jsx(W,{value:"entity",children:"仅实体"}),e.jsx(W,{value:"paragraph",children:"仅段落"})]})]}),e.jsxs(Ie,{value:g===1e4?"all":b?"custom":g.toString(),onValueChange:M=>{M==="custom"?(y(!0),w(g.toString())):M==="all"?(y(!1),N(1e4)):(y(!1),N(Number(M)))},children:[e.jsx(Be,{className:"w-[120px]",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"50",children:"50 节点"}),e.jsx(W,{value:"100",children:"100 节点"}),e.jsx(W,{value:"200",children:"200 节点"}),e.jsx(W,{value:"500",children:"500 节点"}),e.jsx(W,{value:"1000",children:"1000 节点"}),e.jsx(W,{value:"all",children:"全部 (最多10000)"}),e.jsx(W,{value:"custom",children:"自定义..."})]})]}),b&&e.jsx(le,{type:"number",min:"50",value:v,onChange:M=>w(M.target.value),onBlur:()=>{const M=parseInt(v);!isNaN(M)&&M>=50?N(M):(w("50"),N(50))},onKeyDown:M=>{if(M.key==="Enter"){const Q=parseInt(v);!isNaN(Q)&&Q>=50?N(Q):(w("50"),N(50))}},placeholder:"最少50个",className:"w-[120px]"}),e.jsx(_,{onClick:()=>ue(),variant:"outline",size:"sm",disabled:n,children:e.jsx(dt,{className:F("h-4 w-4",n&&"animate-spin")})})]})]})]}),e.jsx("div",{className:"flex-1 relative",children:n?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(dt,{className:"h-8 w-8 animate-spin mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"加载知识图谱中..."})]})}):D.length===0?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Yr,{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(b1,{nodes:D,edges:X,onNodesChange:O,onEdgesChange:oe,onNodeClick:q,onEdgeClick:B,nodeTypes:zk,fitView:!0,minZoom:.05,maxZoom:1.5,defaultViewport:{x:0,y:0,zoom:.5},elevateNodesOnSelect:Ne<=500,nodesDraggable:Ne<=1e3,attributionPosition:"bottom-left",children:[e.jsx(y1,{variant:w1.Dots,gap:12,size:1}),e.jsx(_1,{}),Ne<=500&&e.jsx(S1,{nodeColor:$,nodeBorderRadius:8,pannable:!0,zoomable:!0}),e.jsxs(k1,{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:"段落节点"})]}),Ne>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:"已禁用动画"}),Ne>500&&e.jsx("div",{children:"已禁用缩略图"})]})]})]})]})}),e.jsx(Ps,{open:!!de,onOpenChange:M=>!M&&he(null),children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(Os,{children:e.jsx(Ls,{children:"节点详情"})}),de&&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(ke,{variant:de.type==="entity"?"default":"secondary",children:de.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:de.id})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"内容"}),e.jsx(Je,{className:"mt-1 h-40 p-3 bg-muted rounded",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:de.content})})]})]})]})}),e.jsx(Ps,{open:!!ge,onOpenChange:M=>!M&&R(null),children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsx(Os,{children:e.jsx(Ls,{children:"边详情"})}),ge&&e.jsx(Je,{className:"flex-1 pr-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0 p-3 bg-blue-50 dark:bg-blue-950 rounded border-2 border-blue-200 dark:border-blue-800",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"源节点"}),e.jsx("div",{className:"font-medium text-sm mb-2 truncate",children:ge.source.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[ge.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:ge.target.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[ge.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(ke,{variant:"outline",className:"text-base font-mono",children:ge.edge.weight.toFixed(4)})})]})]})})]})}),e.jsx(Ns,{open:A,onOpenChange:z,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"加载知识图谱"}),e.jsxs(fs,{children:["知识图谱的动态展示会消耗较多系统资源。",e.jsx("br",{}),"确定要加载知识图谱吗?"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:()=>a({to:"/"}),children:"取消 (返回首页)"}),e.jsx(ps,{onClick:fe,children:"确认加载"})]})]})}),e.jsx(Ns,{open:E,onOpenChange:C,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"⚠️ 节点数量较多"}),e.jsx(fs,{asChild:!0,children:e.jsxs("div",{children:[e.jsxs("p",{children:["您正在尝试加载 ",e.jsx("strong",{className:"text-orange-600",children:g>=1e4?"全部 (最多10000个)":g})," 个节点。"]}),e.jsx("p",{className:"mt-4",children:"节点数量过多可能导致:"}),e.jsxs("ul",{className:"list-disc list-inside mt-2 space-y-1",children:[e.jsx("li",{children:"页面加载时间较长"}),e.jsx("li",{children:"浏览器卡顿或崩溃"}),e.jsx("li",{children:"系统资源占用过高"})]}),e.jsx("p",{className:"mt-4",children:"建议先选择较少的节点数量 (50-200 个)。"})]})})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:()=>{C(!1),g>200&&(N(50),y(!1))},children:"取消"}),e.jsx(ps,{onClick:Te,className:"bg-orange-600 hover:bg-orange-700",children:"我了解风险,继续加载"})]})]})})]})}function Ok(){return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsx("div",{className:"flex-none border-b bg-card/50 px-6 py-4",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"麦麦知识库管理"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"管理和组织麦麦的知识库内容"})]})})}),e.jsx("div",{className:"flex-1 overflow-auto p-6",children:e.jsx("div",{className:"mx-auto max-w-4xl",children:e.jsxs(Ce,{children:[e.jsxs(De,{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-20 w-20 items-center justify-center rounded-full bg-primary/10",children:e.jsx(Yr,{className:"h-10 w-10 text-primary"})}),e.jsx(Oe,{className:"text-2xl",children:"麦麦知识库管理"}),e.jsx(os,{className:"text-base",children:"功能开发中,敬请期待"})]}),e.jsx(Me,{className:"text-center text-sm text-muted-foreground",children:e.jsx("p",{children:"此功能将提供知识库的创建、编辑、导入和管理能力"})})]})})})]})}function Jg({className:a,classNames:n,showOutsideDays:r=!0,captionLayout:c="label",buttonVariant:d="ghost",formatters:u,components:h,...f}){const p=yv();return e.jsx(u1,{showOutsideDays:r,className:F("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`,a),captionLayout:c,formatters:{formatMonthDropdown:g=>g.toLocaleString("default",{month:"short"}),...u},classNames:{root:F("w-fit",p.root),months:F("relative flex flex-col gap-4 md:flex-row",p.months),month:F("flex w-full flex-col gap-4",p.month),nav:F("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",p.nav),button_previous:F(Zr({variant:d}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",p.button_previous),button_next:F(Zr({variant:d}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",p.button_next),month_caption:F("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",p.month_caption),dropdowns:F("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",p.dropdowns),dropdown_root:F("has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border",p.dropdown_root),dropdown:F("bg-popover absolute inset-0 opacity-0",p.dropdown),caption_label:F("select-none font-medium",c==="label"?"text-sm":"[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5",p.caption_label),table:"w-full border-collapse",weekdays:F("flex",p.weekdays),weekday:F("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",p.weekday),week:F("mt-2 flex w-full",p.week),week_number_header:F("w-[--cell-size] select-none",p.week_number_header),week_number:F("text-muted-foreground select-none text-[0.8rem]",p.week_number),day:F("group/day relative aspect-square h-full w-full select-none p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md",p.day),range_start:F("bg-accent rounded-l-md",p.range_start),range_middle:F("rounded-none",p.range_middle),range_end:F("bg-accent rounded-r-md",p.range_end),today:F("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",p.today),outside:F("text-muted-foreground aria-selected:text-muted-foreground",p.outside),disabled:F("text-muted-foreground opacity-50",p.disabled),hidden:F("invisible",p.hidden),...n},components:{Root:({className:g,rootRef:N,...v})=>e.jsx("div",{"data-slot":"calendar",ref:N,className:F(g),...v}),Chevron:({className:g,orientation:N,...v})=>N==="left"?e.jsx(Da,{className:F("size-4",g),...v}):N==="right"?e.jsx(Wt,{className:F("size-4",g),...v}):e.jsx(za,{className:F("size-4",g),...v}),DayButton:Lk,WeekNumber:({children:g,...N})=>e.jsx("td",{...N,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:g})}),...h},...f})}function Lk({className:a,day:n,modifiers:r,...c}){const d=yv(),u=m.useRef(null);return m.useEffect(()=>{r.focused&&u.current?.focus()},[r.focused]),e.jsx(_,{ref:u,variant:"ghost",size:"icon","data-day":n.date.toLocaleDateString(),"data-selected-single":r.selected&&!r.range_start&&!r.range_end&&!r.range_middle,"data-range-start":r.range_start,"data-range-end":r.range_end,"data-range-middle":r.range_middle,className:F("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",d.day,a),...c})}const Oo={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 Uk(){const[a,n]=m.useState([]),[r,c]=m.useState(""),[d,u]=m.useState("all"),[h,f]=m.useState("all"),[p,g]=m.useState(void 0),[N,v]=m.useState(void 0),[w,b]=m.useState(!0),[y,A]=m.useState(!1),[z,S]=m.useState("xs"),[U,E]=m.useState(4),[C,D]=m.useState(!1),I=m.useRef(null);m.useEffect(()=>{const G=Hn.getAllLogs();n(G);const Se=Hn.onLog(()=>{n(Hn.getAllLogs())}),fe=Hn.onConnectionChange(Te=>{A(Te)});return()=>{Se(),fe()}},[]);const O=m.useMemo(()=>{const G=new Set(a.map(Se=>Se.module).filter(Se=>Se&&Se.trim()!==""));return Array.from(G).sort()},[a]),X=G=>{switch(G){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"}},L=G=>{switch(G){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"}},oe=()=>{window.location.reload()},Ne=()=>{Hn.clearLogs(),n([])},je=()=>{const G=ge.map(q=>`${q.timestamp} [${q.level.padEnd(8)}] [${q.module}] ${q.message}`).join(` +`),Se=new Blob([G],{type:"text/plain;charset=utf-8"}),fe=URL.createObjectURL(Se),Te=document.createElement("a");Te.href=fe,Te.download=`logs-${Tm(new Date,"yyyy-MM-dd-HHmmss")}.txt`,Te.click(),URL.revokeObjectURL(fe)},de=()=>{b(!w)},he=()=>{g(void 0),v(void 0)},ge=m.useMemo(()=>a.filter(G=>{const Se=r===""||G.message.toLowerCase().includes(r.toLowerCase())||G.module.toLowerCase().includes(r.toLowerCase()),fe=d==="all"||G.level===d,Te=h==="all"||G.module===h;let q=!0;if(p||N){const B=new Date(G.timestamp);if(p){const M=new Date(p);M.setHours(0,0,0,0),q=q&&B>=M}if(N){const M=new Date(N);M.setHours(23,59,59,999),q=q&&B<=M}}return Se&&fe&&Te&&q}),[a,r,d,h,p,N]),R=Oo[z].rowHeight+U,Y=Y0({count:ge.length,getScrollElement:()=>I.current,estimateSize:()=>R,overscan:50}),$=m.useRef(!1),ue=m.useRef(ge.length);return m.useEffect(()=>{const G=I.current;if(!G)return;const Se=()=>{if($.current)return;const{scrollTop:fe,scrollHeight:Te,clientHeight:q}=G,B=Te-fe-q;B>100&&w?b(!1):B<50&&!w&&b(!0)};return G.addEventListener("scroll",Se,{passive:!0}),()=>G.removeEventListener("scroll",Se)},[w]),m.useEffect(()=>{const G=ge.length>ue.current;ue.current=ge.length,w&&ge.length>0&&G&&($.current=!0,Y.scrollToIndex(ge.length-1,{align:"end",behavior:"auto"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{$.current=!1})}))},[ge.length,w,Y]),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-shrink-0 space-y-2 sm:space-y-3 p-2 sm:p-3 lg:p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg sm:text-xl lg:text-2xl font-bold",children:"日志查看器"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 hidden sm:block",children:"实时查看和分析麦麦运行日志"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:F("h-2 w-2 sm:h-2.5 sm:w-2.5 rounded-full",y?"bg-green-500 animate-pulse":"bg-red-500")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:y?"已连接":"未连接"})]})]}),e.jsx(Ce,{className:"p-2 sm:p-3",children:e.jsx(uc,{open:C,onOpenChange:D,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 relative min-w-0",children:[e.jsx(Tt,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(le,{placeholder:"搜索日志...",value:r,onChange:G=>c(G.target.value),className:"pl-8 h-8 text-xs sm:text-sm"})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs(_,{variant:w?"default":"outline",size:"sm",onClick:de,className:"h-8 px-2",title:w?"自动滚动":"已暂停",children:[w?e.jsx(D_,{className:"h-3.5 w-3.5"}):e.jsx(O_,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden sm:inline",children:w?"滚动":"暂停"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:Ne,className:"h-8 px-2",title:"清空日志",children:[e.jsx(ns,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden md:inline",children:"清空"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:je,className:"h-8 px-2 hidden sm:flex",title:"导出日志",children:[e.jsx(Xt,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden lg:inline",children:"导出"})]}),e.jsx(mc,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"h-8 px-2",title:C?"收起筛选":"展开筛选",children:[e.jsx(Bo,{className:"h-3.5 w-3.5"}),C?e.jsx(Qr,{className:"h-3.5 w-3.5 ml-1"}):e.jsx(za,{className:"h-3.5 w-3.5 ml-1"})]})})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground text-center sm:text-right -mt-1",children:[e.jsxs("span",{className:"font-mono",children:[ge.length," / ",a.length]}),e.jsx("span",{className:"ml-1",children:"条日志"})]}),e.jsxs(xc,{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(Ie,{value:d,onValueChange:u,children:[e.jsxs(Be,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(Bo,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Fe,{placeholder:"级别"})]}),e.jsxs(Pe,{children:[e.jsx(W,{value:"all",children:"全部级别"}),e.jsx(W,{value:"DEBUG",children:"DEBUG"}),e.jsx(W,{value:"INFO",children:"INFO"}),e.jsx(W,{value:"WARNING",children:"WARNING"}),e.jsx(W,{value:"ERROR",children:"ERROR"}),e.jsx(W,{value:"CRITICAL",children:"CRITICAL"})]})]}),e.jsxs(Ie,{value:h,onValueChange:f,children:[e.jsxs(Be,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(Bo,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Fe,{placeholder:"模块"})]}),e.jsxs(Pe,{children:[e.jsx(W,{value:"all",children:"全部模块"}),O.map(G=>e.jsx(W,{value:G,children:G},G))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:F("w-full sm:flex-1 justify-start text-left font-normal h-8",!p&&"text-muted-foreground"),children:[e.jsx(Go,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:p?Tm(p,"PP",{locale:Ro}):"开始日期"})]})}),e.jsx(sl,{className:"w-auto p-0",align:"start",children:e.jsx(Jg,{mode:"single",selected:p,onSelect:g,initialFocus:!0,locale:Ro})})]}),e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:F("w-full sm:flex-1 justify-start text-left font-normal h-8",!N&&"text-muted-foreground"),children:[e.jsx(Go,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:N?Tm(N,"PP",{locale:Ro}):"结束日期"})]})}),e.jsx(sl,{className:"w-auto p-0",align:"start",children:e.jsx(Jg,{mode:"single",selected:N,onSelect:v,initialFocus:!0,locale:Ro})})]}),(p||N)&&e.jsxs(_,{variant:"outline",size:"sm",onClick:he,className:"w-full sm:w-auto h-8",children:[e.jsx(Aa,{className:"h-3.5 w-3.5 sm:mr-1"}),e.jsx("span",{className:"text-xs",children:"清除"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(L_,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"字号"})]}),e.jsx("div",{className:"flex gap-1",children:Object.keys(Oo).map(G=>e.jsx(_,{variant:z===G?"default":"outline",size:"sm",onClick:()=>S(G),className:"h-6 px-2 text-xs",children:Oo[G].label},G))})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-1 max-w-[200px]",children:[e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:"行距"}),e.jsx(Qa,{value:[U],onValueChange:([G])=>E(G),min:0,max:12,step:2,className:"flex-1"}),e.jsxs("span",{className:"text-xs text-muted-foreground w-7",children:[U,"px"]})]}),e.jsxs("div",{className:"flex gap-2 sm:hidden",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:oe,className:"flex-1 h-8",children:[e.jsx(dt,{className:"h-3.5 w-3.5 mr-1"}),e.jsx("span",{className:"text-xs",children:"刷新"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:je,className:"flex-1 h-8",children:[e.jsx(Xt,{className:"h-3.5 w-3.5 mr-1"}),e.jsx("span",{className:"text-xs",children:"导出"})]})]})]})]})]})})})]}),e.jsx("div",{className:"flex-1 min-h-0 px-2 sm:px-3 lg:px-4 pb-2 sm:pb-3 lg:pb-4",children:e.jsx(Ce,{className:"bg-black dark:bg-gray-950 border-gray-800 dark:border-gray-900 h-full overflow-hidden",children:e.jsx("div",{ref:I,className:F("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:F("p-2 sm:p-3 font-mono relative",Oo[z].class),style:{height:`${Y.getTotalSize()}px`},children:ge.length===0?e.jsx("div",{className:"text-gray-500 dark:text-gray-600 text-center py-8 text-xs sm:text-sm",children:"暂无日志数据"}):Y.getVirtualItems().map(G=>{const Se=ge[G.index];return e.jsxs("div",{"data-index":G.index,ref:Y.measureElement,className:F("absolute top-0 left-0 w-full px-2 sm:px-3 rounded hover:bg-white/5 transition-colors",L(Se.level)),style:{transform:`translateY(${G.start}px)`,paddingTop:`${U/2}px`,paddingBottom:`${U/2}px`},children:[e.jsxs("div",{className:"flex flex-col gap-0.5 sm:hidden",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-600 text-[10px]",children:Se.timestamp}),e.jsxs("span",{className:F("font-semibold text-[10px]",X(Se.level)),children:["[",Se.level,"]"]})]}),e.jsx("div",{className:"text-cyan-400 dark:text-cyan-500 truncate text-[10px]",children:Se.module}),e.jsx("div",{className:"text-gray-300 dark:text-gray-400 whitespace-pre-wrap break-words text-[10px]",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:F("flex-shrink-0 w-[65px] lg:w-[75px] font-semibold",X(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})]})]},G.key)})})})})})]})}async function $k(){return(await _e("/api/planner/overview")).json()}async function Bk(a,n=1,r=20,c){const d=new URLSearchParams({page:n.toString(),page_size:r.toString()});return c&&d.append("search",c),(await _e(`/api/planner/chat/${a}/logs?${d}`)).json()}async function Pk(a,n){return(await _e(`/api/planner/log/${a}/${n}`)).json()}async function Ik(){return(await _e("/api/replier/overview")).json()}async function Fk(a,n=1,r=20,c){const d=new URLSearchParams({page:n.toString(),page_size:r.toString()});return c&&d.append("search",c),(await _e(`/api/replier/chat/${a}/logs?${d}`)).json()}async function Hk(a,n){return(await _e(`/api/replier/log/${a}/${n}`)).json()}function aN(){const[a,n]=m.useState(new Map),[r,c]=m.useState(!0),d=m.useCallback(async()=>{try{c(!0);const h=await ux();if(h?.data){const f=new Map;h.data.forEach(p=>{f.set(p.chat_id,p.chat_name)}),n(f)}}catch(h){console.error("加载聊天列表失败:",h)}finally{c(!1)}},[]);m.useEffect(()=>{d()},[d]);const u=m.useCallback(h=>a.get(h)||h,[a]);return{chatNameMap:a,getChatName:u,loading:r,reload:d}}function Jo(a){return new Date(a*1e3).toLocaleString("zh-CN")}function lN(a){const r=Date.now()/1e3-a;return r<60?"刚刚":r<3600?`${Math.floor(r/60)} 分钟前`:r<86400?`${Math.floor(r/3600)} 小时前`:`${Math.floor(r/86400)} 天前`}function nN(a,n,r=1e4){m.useEffect(()=>{if(!a)return;const c=setInterval(n,r);return()=>clearInterval(c)},[a,n,r])}function Vk({autoRefresh:a,refreshKey:n}){const[r,c]=m.useState("overview"),[d,u]=m.useState(null),{getChatName:h}=aN(),[f,p]=m.useState(null),[g,N]=m.useState(!0),[v,w]=m.useState(null),[b,y]=m.useState(!1),[A,z]=m.useState(1),[S,U]=m.useState(20),[E,C]=m.useState(""),[D,I]=m.useState(""),[O,X]=m.useState(""),[L,oe]=m.useState(null),[Ne,je]=m.useState(!1),[de,he]=m.useState(!1),ge=m.useCallback(async()=>{try{N(!0);const B=await $k();p(B)}catch(B){console.error("加载规划器总览失败:",B)}finally{N(!1)}},[]),R=m.useCallback(async()=>{if(d)try{y(!0);const B=await Bk(d.chat_id,A,S,D||void 0);w(B)}catch(B){console.error("加载聊天日志失败:",B)}finally{y(!1)}},[d,A,S,D]);m.useEffect(()=>{ge()},[ge]),m.useEffect(()=>{n>0&&(r==="overview"?ge():R())},[n,r,ge,R]),m.useEffect(()=>{r==="chat-logs"&&d&&R()},[r,d,R]),nN(a,m.useCallback(()=>{r==="overview"?ge():R()},[r,ge,R]));const Y=B=>{u(B),z(1),I(""),X(""),c("chat-logs")},$=()=>{c("overview"),u(null),w(null),I(""),X("")},ue=()=>{I(O),z(1)},G=()=>{X(""),I(""),z(1)},Se=async(B,M)=>{try{he(!0),je(!0);const Q=await Pk(B,M);oe(Q)}catch(Q){console.error("加载计划详情失败:",Q)}finally{he(!1)}},fe=B=>{U(Number(B)),z(1)},Te=()=>{const B=parseInt(E),M=v?Math.ceil(v.total/v.page_size):0;!isNaN(B)&&B>=1&&B<=M&&(z(B),C(""))},q=v?Math.ceil(v.total/v.page_size):0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:r==="overview"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"聊天数量"}),e.jsx(Ra,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Me,{children:g?e.jsx(vs,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_chats||0})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"计划总数"}),e.jsx(tx,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Me,{children:g?e.jsx(vs,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_plans||0})})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"聊天列表"}),e.jsx(os,{children:"点击查看该聊天的所有计划记录"})]}),e.jsx(Me,{children:g?e.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:[...Array(6)].map((B,M)=>e.jsx(vs,{className:"h-24 w-full"},M))}):f?.chats&&f.chats.length>0?e.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:f.chats.map(B=>e.jsxs("div",{className:"border rounded-lg p-4 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>Y(B),children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ra,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm truncate max-w-[180px]",title:h(B.chat_id),children:h(B.chat_id)})]}),e.jsx(ke,{variant:"secondary",children:B.plan_count})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["最后活动: ",lN(B.latest_timestamp)]})]},B.chat_id))}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无聊天记录"})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-4 mb-4",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:$,children:[e.jsx(Ma,{className:"h-4 w-4 mr-2"}),"返回聊天列表"]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["当前聊天: ",e.jsx("span",{className:"font-medium",children:d?h(d.chat_id):""}),e.jsx("span",{className:"mx-2",children:"•"}),"共 ",v?.total||0," 条计划记录"]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(Oe,{children:"计划执行记录"}),e.jsx(os,{children:d?h(d.chat_id):""})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(le,{placeholder:"搜索提示词内容...",value:O,onChange:B=>X(B.target.value),onKeyDown:B=>B.key==="Enter"&&ue(),className:"w-full sm:w-48"}),e.jsx(_,{variant:"outline",size:"icon",onClick:ue,children:e.jsx(Tt,{className:"h-4 w-4"})}),D&&e.jsx(_,{variant:"ghost",size:"sm",onClick:G,children:"清除"})]}),e.jsxs(Ie,{value:S.toString(),onValueChange:fe,children:[e.jsx(Be,{className:"w-full sm:w-32",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"10",children:"10条/页"}),e.jsx(W,{value:"20",children:"20条/页"}),e.jsx(W,{value:"50",children:"50条/页"}),e.jsx(W,{value:"100",children:"100条/页"})]})]})]})]}),D&&e.jsxs("div",{className:"text-sm text-muted-foreground mt-2",children:["搜索关键词: ",e.jsxs("span",{className:"font-medium",children:['"',D,'"']})]})]}),e.jsx(Me,{children:b?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((B,M)=>e.jsx(vs,{className:"h-20 w-full"},M))}):v?.data&&v.data.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-2",children:v.data.map(B=>e.jsxs("div",{className:"border rounded-lg p-3 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>Se(B.chat_id,B.filename),children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:Jo(B.timestamp)}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs(ke,{variant:"secondary",className:"text-xs",children:[B.action_count," 个动作"]}),e.jsxs(ke,{variant:"outline",className:"text-xs",children:[B.total_plan_ms.toFixed(0),"ms"]})]})]}),B.action_types&&B.action_types.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:B.action_types.map((M,Q)=>e.jsx(ke,{variant:"outline",className:"text-xs bg-blue-50 dark:bg-blue-950 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-800",children:M},Q))}),e.jsx("p",{className:"text-sm line-clamp-2",children:B.reasoning_preview||"无推理内容"})]},B.filename))}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-3 mt-4 pt-4 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",v.total," 条记录,第 ",A," / ",q," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>z(1),disabled:A===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>z(B=>Math.max(1,B-1)),disabled:A===1,children:e.jsx(Da,{className:"h-4 w-4"})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2",children:[e.jsx(le,{type:"number",min:1,max:q,value:E,onChange:B=>C(B.target.value),onKeyDown:B=>B.key==="Enter"&&Te(),placeholder:"跳转",className:"w-20 h-8"}),e.jsx(_,{size:"sm",variant:"outline",onClick:Te,children:"跳转"})]}),e.jsxs("span",{className:"sm:hidden text-sm text-muted-foreground",children:[A,"/",q]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>z(B=>Math.min(q,B+1)),disabled:A===q,children:e.jsx(Wt,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>z(q),disabled:A===q,className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无计划记录"})})]})]})}),e.jsx(Ps,{open:Ne,onOpenChange:je,children:e.jsxs(Ds,{className:"max-w-4xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(Ea,{className:"h-5 w-5"}),"计划执行详情"]}),e.jsx(Ks,{children:"查看麦麦的详细计划推理过程和执行动作"})]}),e.jsx(Je,{className:"h-full pr-4",children:e.jsx("div",{className:"space-y-6 pb-4",children:de?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((B,M)=>e.jsx(vs,{className:"h-24 w-full"},M))}):L?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(na,{className:"h-4 w-4"}),"基本信息"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 p-4 bg-muted/50 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"聊天"}),e.jsx("div",{className:"text-sm",title:L.chat_id,children:h(L.chat_id)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"时间戳"}),e.jsx("div",{className:"text-sm",children:Jo(L.timestamp)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"类型"}),e.jsx(ke,{variant:"outline",children:L.type})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"动作数量"}),e.jsxs(ke,{children:[L.actions.length," 个动作"]})]})]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(el,{className:"h-4 w-4"}),"性能统计"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"提示词构建"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.prompt_build_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"LLM 推理"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.llm_duration_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"总计划时间"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.total_plan_ms?.toFixed(2)||0,"ms"]})})]})]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(cx,{className:"h-4 w-4"}),"推理过程"]}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:L.reasoning||"无推理内容"})})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(U_,{className:"h-4 w-4"}),"执行动作 (",L.actions.length,")"]}),e.jsx("div",{className:"space-y-3",children:L.actions.map((B,M)=>e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-3",children:e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ke,{variant:"default",children:["动作 ",M+1]}),e.jsx(ke,{variant:"outline",children:B.action_type})]})})}),e.jsxs(Me,{className:"p-4 pt-0 space-y-3",children:[B.reasoning&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"推理依据"}),e.jsx("p",{className:"text-sm bg-muted/30 p-2 rounded",children:typeof B.reasoning=="string"?B.reasoning:JSON.stringify(B.reasoning)})]}),B.action_message&&e.jsxs("div",{className:"overflow-hidden",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"动作消息"}),typeof B.action_message=="string"?e.jsx("p",{className:"text-sm bg-muted/30 p-2 rounded break-all whitespace-pre-wrap",children:B.action_message}):e.jsx("pre",{className:"text-xs bg-muted/30 p-2 rounded overflow-x-auto whitespace-pre-wrap break-all",children:JSON.stringify(B.action_message,null,2)})]}),B.action_data&&Object.keys(B.action_data).length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"动作数据"}),e.jsx("pre",{className:"text-xs bg-muted/30 p-2 rounded overflow-x-auto",children:JSON.stringify(B.action_data,null,2)})]}),B.action_reasoning&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"动作推理"}),e.jsx("p",{className:"text-sm bg-muted/30 p-2 rounded",children:typeof B.action_reasoning=="string"?B.action_reasoning:JSON.stringify(B.action_reasoning)})]})]})]},M))})]}),e.jsx(Yt,{}),L.raw_output&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"原始输出"}),e.jsxs("details",{className:"group",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-muted-foreground hover:text-foreground",children:"点击展开查看完整原始输出"}),e.jsx("div",{className:"mt-2 p-4 bg-muted/50 rounded-lg",children:e.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:L.raw_output})})]})]}),L.prompt&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"完整提示词"}),e.jsxs("details",{className:"group",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-muted-foreground hover:text-foreground",children:"点击展开查看完整提示词"}),e.jsx("div",{className:"mt-2 p-4 bg-muted/50 rounded-lg",children:e.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:L.prompt})})]})]})]}):e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"无数据"})})})}),e.jsx(st,{className:"flex-shrink-0",children:e.jsx(_,{onClick:()=>je(!1),children:"关闭"})})]})})]})}function Gk({autoRefresh:a,refreshKey:n}){const[r,c]=m.useState("overview"),[d,u]=m.useState(null),{getChatName:h}=aN(),[f,p]=m.useState(null),[g,N]=m.useState(!0),[v,w]=m.useState(null),[b,y]=m.useState(!1),[A,z]=m.useState(1),[S,U]=m.useState(20),[E,C]=m.useState(""),[D,I]=m.useState(""),[O,X]=m.useState(""),[L,oe]=m.useState(null),[Ne,je]=m.useState(!1),[de,he]=m.useState(!1),ge=m.useCallback(async()=>{try{N(!0);const B=await Ik();p(B)}catch(B){console.error("加载回复器总览失败:",B)}finally{N(!1)}},[]),R=m.useCallback(async()=>{if(d)try{y(!0);const B=await Fk(d.chat_id,A,S,D||void 0);w(B)}catch(B){console.error("加载聊天日志失败:",B)}finally{y(!1)}},[d,A,S,D]);m.useEffect(()=>{ge()},[ge]),m.useEffect(()=>{n>0&&(r==="overview"?ge():R())},[n,r,ge,R]),m.useEffect(()=>{r==="chat-logs"&&d&&R()},[r,d,R]),nN(a,m.useCallback(()=>{r==="overview"?ge():R()},[r,ge,R]));const Y=B=>{u(B),z(1),I(""),X(""),c("chat-logs")},$=()=>{c("overview"),u(null),w(null),I(""),X("")},ue=()=>{I(O),z(1)},G=()=>{X(""),I(""),z(1)},Se=async(B,M)=>{try{he(!0),je(!0);const Q=await Hk(B,M);oe(Q)}catch(Q){console.error("加载回复详情失败:",Q)}finally{he(!1)}},fe=B=>{U(Number(B)),z(1)},Te=()=>{const B=parseInt(E),M=v?Math.ceil(v.total/v.page_size):0;!isNaN(B)&&B>=1&&B<=M&&(z(B),C(""))},q=v?Math.ceil(v.total/v.page_size):0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:r==="overview"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"聊天数量"}),e.jsx(Ra,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Me,{children:g?e.jsx(vs,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_chats||0})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"回复总数"}),e.jsx(tx,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Me,{children:g?e.jsx(vs,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_replies||0})})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"聊天列表"}),e.jsx(os,{children:"点击查看该聊天的所有回复记录"})]}),e.jsx(Me,{children:g?e.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:[...Array(6)].map((B,M)=>e.jsx(vs,{className:"h-24 w-full"},M))}):f?.chats&&f.chats.length>0?e.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:f.chats.map(B=>e.jsxs("div",{className:"border rounded-lg p-4 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>Y(B),children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ra,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm truncate max-w-[180px]",title:h(B.chat_id),children:h(B.chat_id)})]}),e.jsx(ke,{variant:"secondary",children:B.reply_count})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["最后活动: ",lN(B.latest_timestamp)]})]},B.chat_id))}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无聊天记录"})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-4 mb-4",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:$,children:[e.jsx(Ma,{className:"h-4 w-4 mr-2"}),"返回聊天列表"]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["当前聊天: ",e.jsx("span",{className:"font-medium",children:d?h(d.chat_id):""}),e.jsx("span",{className:"mx-2",children:"•"}),"共 ",v?.total||0," 条回复记录"]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(Oe,{children:"回复生成记录"}),e.jsx(os,{children:d?h(d.chat_id):""})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(le,{placeholder:"搜索提示词内容...",value:O,onChange:B=>X(B.target.value),onKeyDown:B=>B.key==="Enter"&&ue(),className:"w-full sm:w-48"}),e.jsx(_,{variant:"outline",size:"icon",onClick:ue,children:e.jsx(Tt,{className:"h-4 w-4"})}),D&&e.jsx(_,{variant:"ghost",size:"sm",onClick:G,children:"清除"})]}),e.jsxs(Ie,{value:S.toString(),onValueChange:fe,children:[e.jsx(Be,{className:"w-full sm:w-32",children:e.jsx(Fe,{})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"10",children:"10条/页"}),e.jsx(W,{value:"20",children:"20条/页"}),e.jsx(W,{value:"50",children:"50条/页"}),e.jsx(W,{value:"100",children:"100条/页"})]})]})]})]}),D&&e.jsxs("div",{className:"text-sm text-muted-foreground mt-2",children:["搜索关键词: ",e.jsxs("span",{className:"font-medium",children:['"',D,'"']})]})]}),e.jsx(Me,{children:b?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((B,M)=>e.jsx(vs,{className:"h-20 w-full"},M))}):v?.data&&v.data.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-2",children:v.data.map(B=>e.jsxs("div",{className:"border rounded-lg p-3 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>Se(B.chat_id,B.filename),children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:Jo(B.timestamp)}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[B.success?e.jsxs(ke,{variant:"default",className:"text-xs bg-green-600",children:[e.jsx(yg,{className:"h-3 w-3 mr-1"}),"成功"]}):e.jsxs(ke,{variant:"destructive",className:"text-xs",children:[e.jsx(Ka,{className:"h-3 w-3 mr-1"}),"失败"]}),e.jsx(ke,{variant:"outline",className:"text-xs",children:B.model}),e.jsxs(ke,{variant:"secondary",className:"text-xs",children:[B.overall_ms.toFixed(0),"ms"]})]})]}),e.jsx("p",{className:"text-sm line-clamp-2",children:B.output_preview||"无输出内容"})]},B.filename))}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-3 mt-4 pt-4 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",v.total," 条记录,第 ",A," / ",q," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>z(1),disabled:A===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>z(B=>Math.max(1,B-1)),disabled:A===1,children:e.jsx(Da,{className:"h-4 w-4"})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2",children:[e.jsx(le,{type:"number",min:1,max:q,value:E,onChange:B=>C(B.target.value),onKeyDown:B=>B.key==="Enter"&&Te(),placeholder:"跳转",className:"w-20 h-8"}),e.jsx(_,{size:"sm",variant:"outline",onClick:Te,children:"跳转"})]}),e.jsxs("span",{className:"sm:hidden text-sm text-muted-foreground",children:[A,"/",q]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>z(B=>Math.min(q,B+1)),disabled:A===q,children:e.jsx(Wt,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>z(q),disabled:A===q,className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无回复记录"})})]})]})}),e.jsx(Ps,{open:Ne,onOpenChange:je,children:e.jsxs(Ds,{className:"max-w-4xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(Ea,{className:"h-5 w-5"}),"回复生成详情"]}),e.jsx(Ks,{children:"查看麦麦的详细回复生成过程"})]}),e.jsx(Je,{className:"h-full pr-4",children:e.jsx("div",{className:"space-y-6 pb-4",children:de?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((B,M)=>e.jsx(vs,{className:"h-24 w-full"},M))}):L?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(na,{className:"h-4 w-4"}),"基本信息"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 p-4 bg-muted/50 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"聊天"}),e.jsx("div",{className:"text-sm",title:L.chat_id,children:h(L.chat_id)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"时间戳"}),e.jsx("div",{className:"text-sm",children:Jo(L.timestamp)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"状态"}),L.success?e.jsxs(ke,{variant:"default",className:"bg-green-600",children:[e.jsx(yg,{className:"h-3 w-3 mr-1"}),"成功"]}):e.jsxs(ke,{variant:"destructive",children:[e.jsx(Ka,{className:"h-3 w-3 mr-1"}),"失败"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"思考深度"}),e.jsxs(ke,{variant:"outline",children:["Level ",L.think_level]})]})]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx($_,{className:"h-4 w-4"}),"模型信息"]}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx(ke,{variant:"secondary",className:"text-sm",children:L.model})})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(el,{className:"h-4 w-4"}),"性能统计"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"提示词构建"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.prompt_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"LLM 推理"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.llm_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"总耗时"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[L.timing.overall_ms?.toFixed(2)||0,"ms"]})})]})]}),L.timing.timing_logs&&L.timing.timing_logs.length>0&&e.jsxs("div",{className:"mt-3 p-3 bg-muted/30 rounded-lg",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-2",children:"耗时详情"}),e.jsx("div",{className:"space-y-1",children:L.timing.timing_logs.map((B,M)=>e.jsx("div",{className:"text-xs text-muted-foreground",children:B},M))})]}),L.timing.almost_zero&&e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"近乎零耗时: "}),L.timing.almost_zero]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(cx,{className:"h-4 w-4"}),"回复输出"]}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:L.output||"无输出内容"})})]}),L.processed_output&&L.processed_output.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"处理后的输出"}),e.jsx("div",{className:"space-y-2",children:L.processed_output.map((B,M)=>e.jsx("div",{className:"p-3 bg-muted/30 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:B})},M))})]})]}),L.reasoning&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"推理过程"}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:L.reasoning})})]})]}),L.error&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-destructive",children:"错误信息"}),e.jsx("div",{className:"p-4 bg-destructive/10 rounded-lg border border-destructive/20",children:e.jsx("p",{className:"text-sm text-destructive whitespace-pre-wrap",children:L.error})})]})]}),L.prompt&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"完整提示词"}),e.jsxs("details",{className:"group",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-muted-foreground hover:text-foreground",children:"点击展开查看完整提示词"}),e.jsx("div",{className:"mt-2 p-4 bg-muted/50 rounded-lg",children:e.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:L.prompt})})]})]})]})]}):e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"无数据"})})})}),e.jsx(st,{className:"flex-shrink-0",children:e.jsx(_,{onClick:()=>je(!1),children:"关闭"})})]})})]})}function qk(){const[a,n]=m.useState("planner"),[r,c]=m.useState(!1),[d,u]=m.useState(0),h=m.useCallback(()=>{u(f=>f+1)},[]);return 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 items-center gap-2",children:[e.jsxs(_,{variant:r?"default":"outline",size:"sm",onClick:()=>c(!r),children:[e.jsx(dt,{className:`h-4 w-4 mr-2 ${r?"animate-spin":""}`}),r?"自动刷新中":"自动刷新"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:h,children:e.jsx(dt,{className:"h-4 w-4"})})]})]}),e.jsxs(ta,{value:a,onValueChange:f=>n(f),className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2 gap-0.5 sm:gap-1 h-auto p-1",children:[e.jsxs(Xe,{value:"planner",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(sx,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"计划器监控"})]}),e.jsxs(Xe,{value:"replier",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(B_,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"回复器监控"})]})]}),e.jsxs(Je,{className:"h-[calc(100vh-240px)] sm:h-[calc(100vh-280px)] mt-4 sm:mt-6",children:[e.jsx(ws,{value:"planner",className:"mt-0",children:e.jsx(Vk,{autoRefresh:r,refreshKey:d})}),e.jsx(ws,{value:"replier",className:"mt-0",children:e.jsx(Gk,{autoRefresh:r,refreshKey:d})})]})]})]})}const Kk="Mai-with-u",Qk="plugin-repo",Yk="main",Jk="plugin_details.json";async function Xk(){try{const a=await _e("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:Kk,repo:Qk,branch:Yk,file_path:Jk})});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const n=await a.json();if(!n.success||!n.data)throw new Error(n.error||"获取插件列表失败");return JSON.parse(n.data).filter(d=>!d?.id||!d?.manifest?(console.warn("跳过无效插件数据:",d),!1):!d.manifest.name||!d.manifest.version?(console.warn("跳过缺少必需字段的插件:",d.id),!1):!0).map(d=>({id:d.id,manifest:{manifest_version:d.manifest.manifest_version||1,name:d.manifest.name,version:d.manifest.version,description:d.manifest.description||"",author:d.manifest.author||{name:"Unknown"},license:d.manifest.license||"Unknown",host_application:d.manifest.host_application||{min_version:"0.0.0"},homepage_url:d.manifest.homepage_url,repository_url:d.manifest.repository_url,keywords:d.manifest.keywords||[],categories:d.manifest.categories||[],default_locale:d.manifest.default_locale||"zh-CN",locales_path:d.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!1,published_at:new Date().toISOString(),updated_at:new Date().toISOString()}))}catch(a){throw console.error("Failed to fetch plugin list:",a),a}}async function rN(){try{const a=await _e("/api/webui/plugins/git-status");if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return await a.json()}catch(a){return console.error("Failed to check Git status:",a),{installed:!1,error:"无法检测 Git 安装状态"}}}async function iN(){try{const a=await _e("/api/webui/plugins/version");if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return await a.json()}catch(a){return console.error("Failed to get Maimai version:",a),{version:"0.0.0",version_major:0,version_minor:0,version_patch:0}}}function cN(a,n,r){const c=a.split(".").map(f=>parseInt(f)||0),d=c[0]||0,u=c[1]||0,h=c[2]||0;if(r.version_majorparseInt(v)||0),p=f[0]||0,g=f[1]||0,N=f[2]||0;if(r.version_major>p||r.version_major===p&&r.version_minor>g||r.version_major===p&&r.version_minor===g&&r.version_patch>N)return!1}return!0}async function Zk(){try{const a=await _e("/api/webui/ws-token");if(!a.ok)return console.error("获取 WebSocket token 失败:",a.status),null;const n=await a.json();return n.success&&n.token?n.token:null}catch(a){return console.error("获取 WebSocket token 失败:",a),null}}async function Wk(a,n){const r=await Zk();if(!r)return console.warn("无法获取 WebSocket token,可能未登录"),null;const c=window.location.protocol==="https:"?"wss:":"ws:",d=window.location.host,u=`${c}//${d}/api/webui/ws/plugin-progress?token=${encodeURIComponent(r)}`;try{const h=new WebSocket(u);return h.onopen=()=>{console.log("Plugin progress WebSocket connected");const f=setInterval(()=>{h.readyState===WebSocket.OPEN?h.send("ping"):clearInterval(f)},3e4)},h.onmessage=f=>{try{if(f.data==="pong")return;const p=JSON.parse(f.data);a(p)}catch(p){console.error("Failed to parse progress data:",p)}},h.onerror=f=>{console.error("Plugin progress WebSocket error:",f),n?.(f)},h.onclose=()=>{console.log("Plugin progress WebSocket disconnected")},h}catch(h){return console.error("创建 WebSocket 连接失败:",h),null}}async function Dl(){try{const a=await _e("/api/webui/plugins/installed",{headers:Hs()});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const n=await a.json();if(!n.success)throw new Error(n.message||"获取已安装插件列表失败");return n.plugins||[]}catch(a){return console.error("Failed to get installed plugins:",a),[]}}function hn(a,n){return n.some(r=>r.id===a)}function fn(a,n){const r=n.find(c=>c.id===a);if(r)return r.manifest?.version||r.version}async function oN(a,n,r="main"){const c=await _e("/api/webui/plugins/install",{method:"POST",body:JSON.stringify({plugin_id:a,repository_url:n,branch:r})});if(!c.ok){const d=await c.json();throw new Error(d.detail||"安装失败")}return await c.json()}async function dN(a){const n=await _e("/api/webui/plugins/uninstall",{method:"POST",body:JSON.stringify({plugin_id:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"卸载失败")}return await n.json()}async function uN(a,n,r="main"){const c=await _e("/api/webui/plugins/update",{method:"POST",body:JSON.stringify({plugin_id:a,repository_url:n,branch:r})});if(!c.ok){const d=await c.json();throw new Error(d.detail||"更新失败")}return await c.json()}async function eC(a){const n=await _e(`/api/webui/plugins/config/${a}/schema`,{headers:Hs()});if(!n.ok){const c=await n.text();try{const d=JSON.parse(c);throw new Error(d.detail||"获取配置 Schema 失败")}catch{throw new Error(`获取配置 Schema 失败 (${n.status})`)}}const r=await n.json();if(!r.success)throw new Error(r.message||"获取配置 Schema 失败");return r.schema}async function sC(a){const n=await _e(`/api/webui/plugins/config/${a}`,{headers:Hs()});if(!n.ok){const c=await n.text();try{const d=JSON.parse(c);throw new Error(d.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${n.status})`)}}const r=await n.json();if(!r.success)throw new Error(r.message||"获取配置失败");return r.config}async function tC(a){const n=await _e(`/api/webui/plugins/config/${a}/raw`,{headers:Hs()});if(!n.ok){const c=await n.text();try{const d=JSON.parse(c);throw new Error(d.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${n.status})`)}}const r=await n.json();if(!r.success)throw new Error(r.message||"获取配置失败");return r.config}async function aC(a,n){const r=await _e(`/api/webui/plugins/config/${a}`,{method:"PUT",headers:Hs(),body:JSON.stringify({config:n})});if(!r.ok){const c=await r.json();throw new Error(c.detail||"保存配置失败")}return await r.json()}async function lC(a,n){const r=await _e(`/api/webui/plugins/config/${a}/raw`,{method:"PUT",headers:Hs(),body:JSON.stringify({config:n})});if(!r.ok){const c=await r.json();throw new Error(c.detail||"保存配置失败")}return await r.json()}async function nC(a){const n=await _e(`/api/webui/plugins/config/${a}/reset`,{method:"POST",headers:Hs()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"重置配置失败")}return await n.json()}async function rC(a){const n=await _e(`/api/webui/plugins/config/${a}/toggle`,{method:"POST",headers:Hs()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"切换状态失败")}return await n.json()}const jc="https://maibot-plugin-stats.maibot-webui.workers.dev";async function mN(a){try{const n=await fetch(`${jc}/stats/${a}`);return n.ok?await n.json():(console.error("Failed to fetch plugin stats:",n.statusText),null)}catch(n){return console.error("Error fetching plugin stats:",n),null}}async function iC(a,n){try{const r=n||wx(),c=await fetch(`${jc}/stats/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a,user_id:r})}),d=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...d}:{success:!1,error:d.error||"点赞失败"}}catch(r){return console.error("Error liking plugin:",r),{success:!1,error:"网络错误"}}}async function cC(a,n){try{const r=n||wx(),c=await fetch(`${jc}/stats/dislike`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a,user_id:r})}),d=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...d}:{success:!1,error:d.error||"点踩失败"}}catch(r){return console.error("Error disliking plugin:",r),{success:!1,error:"网络错误"}}}async function oC(a,n,r,c){if(n<1||n>5)return{success:!1,error:"评分必须在 1-5 之间"};try{const d=c||wx(),u=await fetch(`${jc}/stats/rate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a,rating:n,comment:r,user_id:d})}),h=await u.json();return u.status===429?{success:!1,error:"每天最多评分 3 次"}:u.ok?{success:!0,...h}:{success:!1,error:h.error||"评分失败"}}catch(d){return console.error("Error rating plugin:",d),{success:!1,error:"网络错误"}}}async function xN(a){try{const n=await fetch(`${jc}/stats/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a})}),r=await n.json();return n.status===429?(console.warn("Download recording rate limited"),{success:!0}):n.ok?{success:!0,...r}:(console.error("Failed to record download:",r.error),{success:!1,error:r.error})}catch(n){return console.error("Error recording download:",n),{success:!1,error:"网络错误"}}}function dC(){const a=navigator,n=[navigator.userAgent,navigator.language,navigator.languages?.join(",")||"",navigator.platform,navigator.hardwareConcurrency||0,screen.width,screen.height,screen.colorDepth,screen.pixelDepth,new Date().getTimezoneOffset(),Intl.DateTimeFormat().resolvedOptions().timeZone,navigator.maxTouchPoints||0,a.deviceMemory||0].join("|");let r=0;for(let c=0;c{const se=H.map(async Ee=>{try{const me=await mN(Ee.id);return{id:Ee.id,stats:me}}catch(me){return console.warn(`Failed to load stats for ${Ee.id}:`,me),{id:Ee.id,stats:null}}}),Ue=await Promise.all(se),ie={};Ue.forEach(({id:Ee,stats:me})=>{me&&(ie[Ee]=me)}),L(ie)};m.useEffect(()=>{let H=null,se=!1;return(async()=>{if(H=await Wk(ie=>{se||(C(ie),ie.stage==="success"?setTimeout(()=>{se||C(null)},2e3):ie.stage==="error"&&(y(!1),z(ie.error||"加载失败")))},ie=>{console.error("WebSocket error:",ie),se||fe({title:"WebSocket 连接失败",description:"无法实时显示加载进度",variant:"destructive"})}),await new Promise(ie=>{if(!H){ie();return}const Ee=()=>{H&&H.readyState===WebSocket.OPEN?(console.log("WebSocket connected, starting to load plugins"),ie()):H&&H.readyState===WebSocket.CLOSED?(console.warn("WebSocket closed before loading plugins"),ie()):setTimeout(Ee,100)};Ee()}),!se){const ie=await rN();U(ie),ie.installed||fe({title:"Git 未安装",description:ie.error||"请先安装 Git 才能使用插件安装功能",variant:"destructive"})}if(!se){const ie=await iN();I(ie)}if(!se)try{y(!0),z(null);const ie=await Xk();if(!se){const Ee=await Dl();O(Ee);const me=ie.map(ze=>{const rs=hn(ze.id,Ee),Ut=fn(ze.id,Ee);return{...ze,installed:rs,installed_version:Ut}});for(const ze of Ee)!me.some(Ut=>Ut.id===ze.id)&&ze.manifest&&me.push({id:ze.id,manifest:{manifest_version:ze.manifest.manifest_version||1,name:ze.manifest.name,version:ze.manifest.version,description:ze.manifest.description||"",author:ze.manifest.author,license:ze.manifest.license||"Unknown",host_application:ze.manifest.host_application,homepage_url:ze.manifest.homepage_url,repository_url:ze.manifest.repository_url,keywords:ze.manifest.keywords||[],categories:ze.manifest.categories||[],default_locale:ze.manifest.default_locale||"zh-CN",locales_path:ze.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!0,installed_version:ze.manifest.version,published_at:new Date().toISOString(),updated_at:new Date().toISOString()});w(me),Te(me)}}catch(ie){if(!se){const Ee=ie instanceof Error?ie.message:"加载插件列表失败";z(Ee),fe({title:"加载失败",description:Ee,variant:"destructive"})}}finally{se||y(!1)}})(),()=>{se=!0,H&&H.close()}},[fe]);const q=H=>{if(!H.installed&&D&&!B(H))return e.jsxs(ke,{variant:"destructive",className:"gap-1",children:[e.jsx(_t,{className:"h-3 w-3"}),"不兼容"]});if(H.installed){const se=H.installed_version?.trim(),Ue=H.manifest.version?.trim();if(se!==Ue){const ie=se?.split(".").map(Number)||[0,0,0],Ee=Ue?.split(".").map(Number)||[0,0,0];for(let me=0;me<3;me++){if((Ee[me]||0)>(ie[me]||0))return e.jsxs(ke,{variant:"outline",className:"gap-1 text-orange-600 border-orange-600",children:[e.jsx(_t,{className:"h-3 w-3"}),"可更新"]});if((Ee[me]||0)<(ie[me]||0))break}}return e.jsxs(ke,{variant:"default",className:"gap-1",children:[e.jsx(pt,{className:"h-3 w-3"}),"已安装"]})}return null},B=H=>!D||!H.manifest?.host_application?!0:cN(H.manifest.host_application.min_version,H.manifest.host_application.max_version,D),M=H=>{if(!H.installed||!H.installed_version||!H.manifest?.version)return!1;const se=H.installed_version.trim(),Ue=H.manifest.version.trim();if(se===Ue)return!1;const ie=se.split(".").map(Number),Ee=Ue.split(".").map(Number);for(let me=0;me<3;me++){if((Ee[me]||0)>(ie[me]||0))return!0;if((Ee[me]||0)<(ie[me]||0))return!1}return!1},Q=v.filter(H=>{if(!H.manifest)return console.warn("[过滤] 跳过无 manifest 的插件:",H.id),!1;const se=c===""||H.manifest.name?.toLowerCase().includes(c.toLowerCase())||H.manifest.description?.toLowerCase().includes(c.toLowerCase())||H.manifest.keywords&&H.manifest.keywords.some(me=>me.toLowerCase().includes(c.toLowerCase())),Ue=u==="all"||H.manifest.categories&&H.manifest.categories.includes(u);let ie=!0;f==="installed"?ie=H.installed===!0:f==="updates"&&(ie=H.installed===!0&&M(H));const Ee=!g||!D||B(H);return se&&Ue&&ie&&Ee}),Ae=H=>{if(!S?.installed){fe({title:"无法安装",description:"Git 未安装",variant:"destructive"});return}if(D&&!B(H)){fe({title:"无法安装",description:"插件与当前麦麦版本不兼容",variant:"destructive"});return}de(H),ge("main"),Y(""),ue("preset"),Se(!1),Ne(!0)},ee=async()=>{if(!je)return;const H=$==="custom"?R:he;if(!H||H.trim()===""){fe({title:"分支名称不能为空",variant:"destructive"});return}try{Ne(!1),await oN(je.id,je.manifest.repository_url||"",H),xN(je.id).catch(Ue=>{console.warn("Failed to record download:",Ue)}),fe({title:"安装成功",description:`${je.manifest.name} 已成功安装`});const se=await Dl();O(se),w(Ue=>Ue.map(ie=>{if(ie.id===je.id){const Ee=hn(ie.id,se),me=fn(ie.id,se);return{...ie,installed:Ee,installed_version:me}}return ie}))}catch(se){fe({title:"安装失败",description:se instanceof Error?se.message:"未知错误",variant:"destructive"})}finally{de(null)}},J=async H=>{try{await dN(H.id),fe({title:"卸载成功",description:`${H.manifest.name} 已成功卸载`});const se=await Dl();O(se),w(Ue=>Ue.map(ie=>{if(ie.id===H.id){const Ee=hn(ie.id,se),me=fn(ie.id,se);return{...ie,installed:Ee,installed_version:me}}return ie}))}catch(se){fe({title:"卸载失败",description:se instanceof Error?se.message:"未知错误",variant:"destructive"})}},$e=async H=>{if(!S?.installed){fe({title:"无法更新",description:"Git 未安装",variant:"destructive"});return}try{const se=await uN(H.id,H.manifest.repository_url||"","main");fe({title:"更新成功",description:`${H.manifest.name} 已从 ${se.old_version} 更新到 ${se.new_version}`});const Ue=await Dl();O(Ue),w(ie=>ie.map(Ee=>{if(Ee.id===H.id){const me=hn(Ee.id,Ue),ze=fn(Ee.id,Ue);return{...Ee,installed:me,installed_version:ze}}return Ee}))}catch(se){fe({title:"更新失败",description:se instanceof Error?se.message:"未知错误",variant:"destructive"})}};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件市场"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"浏览和管理麦麦的插件"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(_,{variant:"outline",onClick:()=>n(),disabled:r,children:[e.jsx(iv,{className:`h-4 w-4 mr-2 ${r?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(_,{onClick:()=>a({to:"/plugin-mirrors"}),children:[e.jsx(P_,{className:"h-4 w-4 mr-2"}),"配置镜像源"]})]})]}),e.jsx(Ce,{className:"border-blue-200 bg-blue-50 dark:bg-blue-950/20 dark:border-blue-900",children:e.jsx(Me,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ft,{className:"h-4 w-4 text-blue-600 flex-shrink-0"}),e.jsxs("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:["安装、卸载或更新插件后,需要",e.jsx("span",{className:"font-semibold",children:"重启麦麦"}),"才能使更改生效"]})]})})}),S&&!S.installed&&e.jsxs(Ce,{className:"border-orange-600 bg-orange-50 dark:bg-orange-950/20",children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jt,{className:"h-5 w-5 text-orange-600"}),e.jsxs("div",{children:[e.jsx(Oe,{className:"text-lg text-orange-900 dark:text-orange-100",children:"Git 未安装"}),e.jsx(os,{className:"text-orange-800 dark:text-orange-200",children:S.error||"请先安装 Git 才能使用插件安装功能"})]})]})}),e.jsx(Me,{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(Ce,{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(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(le,{placeholder:"搜索插件...",value:c,onChange:H=>d(H.target.value),className:"pl-9"})]}),e.jsxs(Ie,{value:u,onValueChange:h,children:[e.jsx(Be,{className:"w-full sm:w-[200px]",children:e.jsx(Fe,{placeholder:"选择分类"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"all",children:"全部分类"}),e.jsx(W,{value:"Group Management",children:"群组管理"}),e.jsx(W,{value:"Entertainment & Interaction",children:"娱乐互动"}),e.jsx(W,{value:"Utility Tools",children:"实用工具"}),e.jsx(W,{value:"Content Generation",children:"内容生成"}),e.jsx(W,{value:"Multimedia",children:"多媒体"}),e.jsx(W,{value:"External Integration",children:"外部集成"}),e.jsx(W,{value:"Data Analysis & Insights",children:"数据分析与洞察"}),e.jsx(W,{value:"Other",children:"其他"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"compatible-only",checked:g,onCheckedChange:H=>N(H===!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(ta,{value:f,onValueChange:p,className:"w-full",children:e.jsxs(Zt,{className:"grid w-full grid-cols-3",children:[e.jsxs(Xe,{value:"all",children:["全部插件 (",v.filter(H=>{if(!H.manifest)return!1;const se=c===""||H.manifest.name?.toLowerCase().includes(c.toLowerCase())||H.manifest.description?.toLowerCase().includes(c.toLowerCase())||H.manifest.keywords&&H.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=u==="all"||H.manifest.categories&&H.manifest.categories.includes(u),ie=!g||!D||B(H);return se&&Ue&&ie}).length,")"]}),e.jsxs(Xe,{value:"installed",children:["已安装 (",v.filter(H=>{if(!H.manifest)return!1;const se=c===""||H.manifest.name?.toLowerCase().includes(c.toLowerCase())||H.manifest.description?.toLowerCase().includes(c.toLowerCase())||H.manifest.keywords&&H.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=u==="all"||H.manifest.categories&&H.manifest.categories.includes(u),ie=!g||!D||B(H);return H.installed&&se&&Ue&&ie}).length,")"]}),e.jsxs(Xe,{value:"updates",children:["可更新 (",v.filter(H=>{if(!H.manifest)return!1;const se=c===""||H.manifest.name?.toLowerCase().includes(c.toLowerCase())||H.manifest.description?.toLowerCase().includes(c.toLowerCase())||H.manifest.keywords&&H.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=u==="all"||H.manifest.categories&&H.manifest.categories.includes(u),ie=!g||!D||B(H);return H.installed&&M(H)&&se&&Ue&&ie}).length,")"]})]})}),E&&E.stage==="loading"&&E.operation==="fetch"&&e.jsx(Ce,{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(zs,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm font-medium",children:"加载插件列表"})]}),e.jsxs("span",{className:"text-sm font-medium",children:[E.progress,"%"]})]}),e.jsx(Xn,{value:E.progress,className:"h-2"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:E.message}),E.total_plugins>0&&e.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:["已加载 ",E.loaded_plugins," / ",E.total_plugins," 个插件"]})]})}),E&&E.stage==="error"&&E.error&&e.jsx(Ce,{className:"border-destructive bg-destructive/10",children:e.jsx(De,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jt,{className:"h-5 w-5 text-destructive"}),e.jsxs("div",{children:[e.jsx(Oe,{className:"text-lg text-destructive",children:"加载失败"}),e.jsx(os,{className:"text-destructive/80",children:E.error})]})]})})}),b?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件列表中..."})]}):A?e.jsx(Ce,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Jt,{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:A}),e.jsx(_,{onClick:()=>window.location.reload(),children:"重新加载"})]})}):Q.length===0?e.jsx(Ce,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Tt,{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:c||u!=="all"?"尝试调整搜索条件或筛选器":"暂无可用插件"})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:Q.map(H=>e.jsxs(Ce,{className:"flex flex-col hover:shadow-lg transition-shadow h-full",children:[e.jsxs(De,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx(Oe,{className:"text-xl",children:H.manifest?.name||H.id}),e.jsxs("div",{className:"flex flex-col gap-1",children:[H.manifest?.categories&&H.manifest.categories[0]&&e.jsx(ke,{variant:"secondary",className:"text-xs whitespace-nowrap",children:uC[H.manifest.categories[0]]||H.manifest.categories[0]}),q(H)]})]}),e.jsx(os,{className:"line-clamp-2",children:H.manifest?.description||"无描述"})]}),e.jsx(Me,{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(Xt,{className:"h-4 w-4"}),e.jsx("span",{children:(X[H.id]?.downloads??H.downloads??0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(mn,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:(X[H.id]?.rating??H.rating??0).toFixed(1)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[H.manifest?.keywords&&H.manifest.keywords.slice(0,3).map(se=>e.jsx(ke,{variant:"outline",className:"text-xs",children:se},se)),H.manifest?.keywords&&H.manifest.keywords.length>3&&e.jsxs(ke,{variant:"outline",className:"text-xs",children:["+",H.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",H.manifest?.version||"unknown"," · ",H.manifest?.author?.name||"Unknown"]}),H.manifest?.host_application&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:"支持:"}),e.jsxs("span",{className:"font-medium",children:[H.manifest.host_application.min_version,H.manifest.host_application.max_version?` - ${H.manifest.host_application.max_version}`:" - 最新版本"]})]})]})]})}),e.jsx(id,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center justify-end gap-2 w-full",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>a({to:"/plugin-detail",search:{pluginId:H.id}}),children:"查看详情"}),H.installed?M(H)?e.jsxs(_,{size:"sm",disabled:!S?.installed,title:S?.installed?void 0:"Git 未安装",onClick:()=>$e(H),children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"更新"]}):e.jsxs(_,{variant:"destructive",size:"sm",disabled:!S?.installed,title:S?.installed?void 0:"Git 未安装",onClick:()=>J(H),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"卸载"]}):e.jsxs(_,{size:"sm",disabled:!S?.installed||E?.operation==="install"||D!==null&&!B(H),title:S?.installed?D!==null&&!B(H)?`不兼容当前版本 (需要 ${H.manifest?.host_application?.min_version||"未知"}${H.manifest?.host_application?.max_version?` - ${H.manifest.host_application.max_version}`:"+"},当前 ${D?.version})`:void 0:"Git 未安装",onClick:()=>Ae(H),children:[e.jsx(Xt,{className:"h-4 w-4 mr-1"}),E?.operation==="install"&&E?.plugin_id===H.id?"安装中...":"安装"]})]})}),E&&(E.stage==="loading"||E.stage==="success"||E.stage==="error")&&E.operation!=="fetch"&&E.plugin_id===H.id&&e.jsx("div",{className:"px-6 pb-4 -mt-2",children:e.jsxs("div",{className:`space-y-2 p-3 rounded-lg border ${E.stage==="success"?"bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-900":E.stage==="error"?"bg-red-50 dark:bg-red-950/20 border-red-200 dark:border-red-900":"bg-muted/50"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[E.stage==="loading"?e.jsx(zs,{className:"h-3 w-3 animate-spin"}):E.stage==="success"?e.jsx(pt,{className:"h-3 w-3 text-green-600"}):e.jsx(_t,{className:"h-3 w-3 text-red-600"}),e.jsx("span",{className:`text-xs font-medium ${E.stage==="success"?"text-green-700 dark:text-green-300":E.stage==="error"?"text-red-700 dark:text-red-300":""}`,children:E.stage==="loading"?e.jsxs(e.Fragment,{children:[E.operation==="install"&&"正在安装",E.operation==="uninstall"&&"正在卸载",E.operation==="update"&&"正在更新"]}):E.stage==="success"?e.jsxs(e.Fragment,{children:[E.operation==="install"&&"安装完成",E.operation==="uninstall"&&"卸载完成",E.operation==="update"&&"更新完成"]}):e.jsxs(e.Fragment,{children:[E.operation==="install"&&"安装失败",E.operation==="uninstall"&&"卸载失败",E.operation==="update"&&"更新失败"]})})]}),E.stage!=="error"&&e.jsxs("span",{className:`text-xs font-medium ${E.stage==="success"?"text-green-700 dark:text-green-300":""}`,children:[E.progress,"%"]})]}),E.stage!=="error"&&e.jsx(Xn,{value:E.progress,className:`h-1.5 ${E.stage==="success"?"[&>div]:bg-green-500":""}`}),e.jsx("div",{className:`text-xs ${E.stage==="success"?"text-green-600 dark:text-green-400 truncate":E.stage==="error"?"text-red-600 dark:text-red-400":"text-muted-foreground truncate"}`,children:E.stage==="error"?E.error||E.message||"操作失败":E.message})]})})]},H.id))}),e.jsx(Ps,{open:oe,onOpenChange:Ne,children:e.jsxs(Ds,{children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"安装插件"}),e.jsxs(Ks,{children:["安装 ",je?.manifest.name]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["版本: ",je?.manifest.version]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["作者: ",typeof je?.manifest.author=="string"?je.manifest.author:je?.manifest.author?.name]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"advanced-options",checked:G,onCheckedChange:H=>Se(H)}),e.jsx("label",{htmlFor:"advanced-options",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"高级选项"})]}),G&&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(ta,{value:$,onValueChange:H=>ue(H),children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2",children:[e.jsx(Xe,{value:"preset",className:"text-xs",children:"预设分支"}),e.jsx(Xe,{value:"custom",className:"text-xs",children:"自定义分支"})]}),$==="preset"&&e.jsx("div",{className:"mt-3",children:e.jsxs(Ie,{value:he,onValueChange:ge,children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:"选择分支"})}),e.jsxs(Pe,{children:[e.jsx(W,{value:"main",children:"main (默认)"}),e.jsx(W,{value:"master",children:"master"}),e.jsx(W,{value:"dev",children:"dev (开发版)"}),e.jsx(W,{value:"develop",children:"develop"}),e.jsx(W,{value:"beta",children:"beta (测试版)"}),e.jsx(W,{value:"stable",children:"stable (稳定版)"})]})]})}),$==="custom"&&e.jsxs("div",{className:"space-y-2 mt-3",children:[e.jsx("input",{type:"text",className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",placeholder:"输入分支名称,例如: feature/new-feature",value:R,onChange:H=>Y(H.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"输入 Git 分支名称、标签或提交哈希"})]})]})]})}),!G&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"将从默认分支 (main) 安装插件"})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>Ne(!1),children:"取消"}),e.jsxs(_,{onClick:ee,children:[e.jsx(Xt,{className:"h-4 w-4 mr-2"}),"安装"]})]})]})}),e.jsx(er,{})]})})}function hC(){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(cv,{className:"h-8 w-8",strokeWidth:2}),"模型分配预设市场"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"浏览和下载社区共享的模型分配预设配置"})]})})}),e.jsx(Je,{className:"flex-1",children:e.jsx("div",{className:"flex items-center justify-center h-[calc(100vh-12rem)]",children:e.jsxs(Ce,{className:"max-w-2xl w-full border-dashed",children:[e.jsxs(De,{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(ra,{className:"h-16 w-16 text-muted-foreground"})}),e.jsx(Oe,{className:"text-2xl",children:"功能开发中"}),e.jsx(os,{className:"text-base",children:"模型分配预设市场功能正在开发中,敬请期待!"})]}),e.jsx(Me,{children:e.jsxs("div",{className:"space-y-3 text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-foreground",children:"📦 即将推出的功能:"}),e.jsxs("ul",{className:"space-y-2 ml-6",children:[e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"浏览社区共享的模型分配预设配置"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"一键下载和应用预设配置"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"分享自己的模型分配方案"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"预设配置评分和评论系统"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"根据使用场景智能推荐配置"})]})]})]})})]})})})]})}function fC({field:a,value:n,onChange:r}){const[c,d]=m.useState(!1);switch(a.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(T,{children:a.label}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]}),e.jsx(Ve,{checked:!!n,onCheckedChange:r,disabled:a.disabled})]});case"number":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(le,{type:"number",value:n??a.default,onChange:u=>r(parseFloat(u.target.value)||0),min:a.min,max:a.max,step:a.step??1,placeholder:a.placeholder,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"slider":return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:a.label}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n??a.default})]}),e.jsx(Qa,{value:[n??a.default],onValueChange:u=>r(u[0]),min:a.min??0,max:a.max??100,step:a.step??1,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"select":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsxs(Ie,{value:String(n??a.default),onValueChange:r,disabled:a.disabled,children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:a.placeholder??"请选择"})}),e.jsx(Pe,{children:a.choices?.map(u=>e.jsx(W,{value:String(u),children:String(u)},String(u)))})]}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"textarea":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(ot,{value:n??a.default,onChange:u=>r(u.target.value),placeholder:a.placeholder,rows:a.rows??3,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"password":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsxs("div",{className:"relative",children:[e.jsx(le,{type:c?"text":"password",value:n??"",onChange:u=>r(u.target.value),placeholder:a.placeholder,disabled:a.disabled,className:"pr-10"}),e.jsx(_,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3",onClick:()=>d(!c),children:c?e.jsx(nc,{className:"h-4 w-4"}):e.jsx(ia,{className:"h-4 w-4"})})]}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"list":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(NS,{value:Array.isArray(n)?n:[],onChange:u=>r(u),itemType:a.item_type??"string",itemFields:a.item_fields,minItems:a.min_items,maxItems:a.max_items,disabled:a.disabled,placeholder:a.placeholder}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"text":default:return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(le,{type:"text",value:n??a.default??"",onChange:u=>r(u.target.value),placeholder:a.placeholder,maxLength:a.max_length,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]})}}function Xg({section:a,config:n,onChange:r}){const[c,d]=m.useState(!a.collapsed),u=Object.entries(a.fields).filter(([,h])=>!h.hidden).sort(([,h],[,f])=>h.order-f.order);return e.jsx(uc,{open:c,onOpenChange:d,children:e.jsxs(Ce,{children:[e.jsx(mc,{asChild:!0,children:e.jsxs(De,{className:"cursor-pointer hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c?e.jsx(za,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Wt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(Oe,{className:"text-lg",children:a.title})]}),e.jsxs(ke,{variant:"secondary",className:"text-xs",children:[u.length," 项"]})]}),a.description&&e.jsx(os,{className:"ml-6",children:a.description})]})}),e.jsx(xc,{children:e.jsx(Me,{className:"space-y-4 pt-0",children:u.map(([h,f])=>e.jsx(fC,{field:f,value:n[a.name]?.[h],onChange:p=>r(a.name,h,p),sectionName:a.name},h))})})]})})}function pC({plugin:a,onBack:n}){const{toast:r}=Ys(),{triggerRestart:c,isRestarting:d}=yn(),[u,h]=m.useState("visual"),[f,p]=m.useState(null),[g,N]=m.useState({}),[v,w]=m.useState({}),[b,y]=m.useState(""),[A,z]=m.useState(""),[S,U]=m.useState(!0),[E,C]=m.useState(!1),[D,I]=m.useState(!1),[O,X]=m.useState(!1),[L,oe]=m.useState(!1),Ne=m.useCallback(async()=>{U(!0);try{const[$,ue,G]=await Promise.all([eC(a.id),sC(a.id),tC(a.id)]);p($),N(ue),w(JSON.parse(JSON.stringify(ue))),y(G),z(G)}catch($){r({title:"加载配置失败",description:$ instanceof Error?$.message:"未知错误",variant:"destructive"})}finally{U(!1)}},[a.id,r]);m.useEffect(()=>{Ne()},[Ne]),m.useEffect(()=>{I(u==="visual"?JSON.stringify(g)!==JSON.stringify(v):b!==A)},[g,v,b,A,u]);const je=($,ue,G)=>{N(Se=>({...Se,[$]:{...Se[$]||{},[ue]:G}}))},de=async()=>{C(!0);try{if(u==="source"){try{Zv(b)}catch($){X(!0),r({title:"TOML 格式错误",description:$ instanceof Error?$.message:"无法解析 TOML 配置,请检查语法",variant:"destructive"}),C(!1);return}await lC(a.id,b),z(b),X(!1)}else await aC(a.id,g),w(JSON.parse(JSON.stringify(g)));r({title:"配置已保存",description:"更改将在插件重新加载后生效"})}catch($){r({title:"保存失败",description:$ instanceof Error?$.message:"未知错误",variant:"destructive"})}finally{C(!1)}},he=async()=>{try{await nC(a.id),r({title:"配置已重置",description:"下次加载插件时将使用默认配置"}),oe(!1),Ne()}catch($){r({title:"重置失败",description:$ instanceof Error?$.message:"未知错误",variant:"destructive"})}},ge=async()=>{try{const $=await rC(a.id);r({title:$.message,description:$.note}),Ne()}catch($){r({title:"切换状态失败",description:$ instanceof Error?$.message:"未知错误",variant:"destructive"})}};if(S)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!f)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 space-y-4",children:[e.jsx(_t,{className:"h-12 w-12 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"无法加载配置"}),e.jsxs(_,{onClick:n,variant:"outline",children:[e.jsx(Ma,{className:"h-4 w-4 mr-2"}),"返回"]})]});const R=Object.values(f.sections).sort(($,ue)=>$.order-ue.order),Y=g.plugin?.enabled!==!1;return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:n,children:e.jsx(Ma,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:f.plugin_info.name||a.manifest.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(ke,{variant:Y?"default":"secondary",children:Y?"已启用":"已禁用"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["v",f.plugin_info.version||a.manifest.version]})]})]})]}),e.jsxs("div",{className:"flex gap-2 ml-10 sm:ml-0",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>h(u==="visual"?"source":"visual"),children:u==="visual"?e.jsxs(e.Fragment,{children:[e.jsx(lv,{className:"h-4 w-4 mr-2"}),"源代码"]}):e.jsxs(e.Fragment,{children:[e.jsx(av,{className:"h-4 w-4 mr-2"}),"可视化"]})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>c(),disabled:d,children:[e.jsx(iv,{className:`h-4 w-4 mr-2 ${d?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:ge,children:[e.jsx(hc,{className:"h-4 w-4 mr-2"}),Y?"禁用":"启用"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>oe(!0),children:[e.jsx(lc,{className:"h-4 w-4 mr-2"}),"重置"]}),e.jsxs(_,{size:"sm",onClick:de,disabled:!D||E,children:[E?e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(fc,{className:"h-4 w-4 mr-2"}),"保存"]})]})]}),D&&e.jsx(Ce,{className:"border-orange-200 bg-orange-50 dark:bg-orange-950/20 dark:border-orange-900",children:e.jsx(Me,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ft,{className:"h-4 w-4 text-orange-600"}),e.jsx("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:"有未保存的更改"})]})})}),u==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsxs(lt,{children:[e.jsx("strong",{children:"源代码模式(高级功能):"}),"直接编辑 TOML 配置文件。保存时会验证格式,只有格式正确才能保存。",O&&e.jsx("span",{className:"text-destructive font-semibold ml-2",children:"⚠️ 上次保存失败,请检查 TOML 格式"})]})]}),e.jsx(Iv,{value:b,onChange:$=>{y($),O&&X(!1)},language:"toml",theme:"dark",height:"calc(100vh - 350px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),u==="visual"&&e.jsxs(e.Fragment,{children:[e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsxs(lt,{children:[e.jsx("strong",{children:"提示:"}),"如果插件当前未加载或未启用,WebUI 适配器的高级插件可视化编辑功能可能会不可用。 请确保插件已启用并成功加载后,再进行配置编辑。"]})]}),f.layout.type==="tabs"&&f.layout.tabs.length>0?e.jsxs(ta,{defaultValue:f.layout.tabs[0]?.id,children:[e.jsx(Zt,{children:f.layout.tabs.map($=>e.jsxs(Xe,{value:$.id,children:[$.title,$.badge&&e.jsx(ke,{variant:"secondary",className:"ml-2 text-xs",children:$.badge})]},$.id))}),f.layout.tabs.map($=>e.jsx(ws,{value:$.id,className:"space-y-4 mt-4",children:$.sections.map(ue=>{const G=f.sections[ue];return G?e.jsx(Xg,{section:G,config:g,onChange:je},ue):null})},$.id))]}):e.jsx("div",{className:"space-y-4",children:R.map($=>e.jsx(Xg,{section:$,config:g,onChange:je},$.name))})]}),e.jsx(Ps,{open:L,onOpenChange:oe,children:e.jsxs(Ds,{children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"确认重置配置"}),e.jsx(Ks,{children:"这将删除当前配置文件,下次加载插件时将使用默认配置。此操作不可撤销。"})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>oe(!1),children:"取消"}),e.jsx(_,{variant:"destructive",onClick:he,children:"确认重置"})]})]})})]})}function gC(){return e.jsx(Wn,{children:e.jsx(jC,{})})}function jC(){const{toast:a}=Ys(),[n,r]=m.useState([]),[c,d]=m.useState(!0),[u,h]=m.useState(""),[f,p]=m.useState(null),g=async()=>{d(!0);try{const y=await Dl();r(y)}catch(y){a({title:"加载插件列表失败",description:y instanceof Error?y.message:"未知错误",variant:"destructive"})}finally{d(!1)}};m.useEffect(()=>{g()},[]);const v=n.filter(y=>{const A=u.toLowerCase();return y.id.toLowerCase().includes(A)||y.manifest.name.toLowerCase().includes(A)||y.manifest.description?.toLowerCase().includes(A)}).filter((y,A,z)=>A===z.findIndex(S=>S.id===y.id)),w=n.length,b=0;return f?e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"h-full",children:e.jsx("div",{className:"p-4 sm:p-6",children:e.jsx(pC,{plugin:f,onBack:()=>p(null)})})}),e.jsx(er,{})]}):e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理和配置已安装的插件"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:g,children:[e.jsx(dt,{className:`h-4 w-4 mr-2 ${c?"animate-spin":""}`}),"刷新"]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 xs:grid-cols-2 lg:grid-cols-3",children:[e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"已安装插件"}),e.jsx(ra,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n.length}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:c?"正在加载...":"个插件"})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"已启用"}),e.jsx(pt,{className:"h-4 w-4 text-green-600"})]}),e.jsxs(Me,{children:[e.jsx("div",{className:"text-2xl font-bold",children:w}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"运行中的插件"})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"已禁用"}),e.jsx(_t,{className:"h-4 w-4 text-orange-600"})]}),e.jsxs(Me,{children:[e.jsx("div",{className:"text-2xl font-bold",children:b}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"未激活的插件"})]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(le,{placeholder:"搜索插件...",value:u,onChange:y=>h(y.target.value),className:"pl-9"})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"已安装的插件"}),e.jsx(os,{children:"点击插件查看和编辑配置"})]}),e.jsx(Me,{children:c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):v.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 space-y-4",children:[e.jsx(ra,{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:u?"没有找到匹配的插件":"暂无已安装的插件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u?"尝试其他搜索关键词":"前往插件市场安装插件"})]})]}):e.jsx("div",{className:"space-y-2",children:v.map(y=>e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg border hover:bg-muted/50 cursor-pointer transition-colors",onClick:()=>p(y),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(ra,{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:y.manifest.name}),e.jsxs(ke,{variant:"secondary",className:"text-xs flex-shrink-0",children:["v",y.manifest.version]})]}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:y.manifest.description||"暂无描述"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(_,{variant:"ghost",size:"sm",children:e.jsx(vn,{className:"h-4 w-4"})}),e.jsx(Wt,{className:"h-4 w-4 text-muted-foreground"})]})]},y.id))})})]})]})})}function vC(){const a=ca(),{toast:n}=Ys(),[r,c]=m.useState([]),[d,u]=m.useState(!0),[h,f]=m.useState(null),[p,g]=m.useState(null),[N,v]=m.useState(!1),[w,b]=m.useState(!1),[y,A]=m.useState({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),z=m.useCallback(async()=>{try{u(!0),f(null);const O=await _e("/api/webui/plugins/mirrors");if(!O.ok)throw new Error("获取镜像源列表失败");const X=await O.json();c(X.mirrors||[])}catch(O){const X=O instanceof Error?O.message:"加载镜像源失败";f(X),n({title:"加载失败",description:X,variant:"destructive"})}finally{u(!1)}},[n]);m.useEffect(()=>{z()},[z]);const S=async()=>{try{const O=await _e("/api/webui/plugins/mirrors",{method:"POST",body:JSON.stringify(y)});if(!O.ok){const X=await O.json();throw new Error(X.detail||"添加镜像源失败")}n({title:"添加成功",description:"镜像源已添加"}),v(!1),A({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),z()}catch(O){n({title:"添加失败",description:O instanceof Error?O.message:"未知错误",variant:"destructive"})}},U=async()=>{if(p)try{if(!(await _e(`/api/webui/plugins/mirrors/${p.id}`,{method:"PUT",body:JSON.stringify({name:y.name,raw_prefix:y.raw_prefix,clone_prefix:y.clone_prefix,enabled:y.enabled,priority:y.priority})})).ok)throw new Error("更新镜像源失败");n({title:"更新成功",description:"镜像源已更新"}),b(!1),g(null),z()}catch(O){n({title:"更新失败",description:O instanceof Error?O.message:"未知错误",variant:"destructive"})}},E=async O=>{if(confirm("确定要删除这个镜像源吗?"))try{if(!(await _e(`/api/webui/plugins/mirrors/${O}`,{method:"DELETE"})).ok)throw new Error("删除镜像源失败");n({title:"删除成功",description:"镜像源已删除"}),z()}catch(X){n({title:"删除失败",description:X instanceof Error?X.message:"未知错误",variant:"destructive"})}},C=async O=>{try{if(!(await _e(`/api/webui/plugins/mirrors/${O.id}`,{method:"PUT",body:JSON.stringify({enabled:!O.enabled})})).ok)throw new Error("更新状态失败");z()}catch(X){n({title:"更新失败",description:X instanceof Error?X.message:"未知错误",variant:"destructive"})}},D=O=>{g(O),A({id:O.id,name:O.name,raw_prefix:O.raw_prefix,clone_prefix:O.clone_prefix,enabled:O.enabled,priority:O.priority}),b(!0)},I=async(O,X)=>{const L=X==="up"?O.priority-1:O.priority+1;if(!(L<1))try{if(!(await _e(`/api/webui/plugins/mirrors/${O.id}`,{method:"PUT",body:JSON.stringify({priority:L})})).ok)throw new Error("更新优先级失败");z()}catch(oe){n({title:"更新失败",description:oe instanceof Error?oe.message:"未知错误",variant:"destructive"})}};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>a({to:"/plugins"}),children:e.jsx(Ma,{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(_,{onClick:()=>v(!0),children:[e.jsx(et,{className:"h-4 w-4 mr-2"}),"添加镜像源"]})]}),d?e.jsx(Ce,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(zs,{className:"h-8 w-8 animate-spin text-primary"})})}):h?e.jsx(Ce,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Jt,{className:"h-12 w-12 text-destructive mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"加载失败"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:h}),e.jsx(_,{onClick:z,children:"重新加载"})]})}):e.jsxs(Ce,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{children:"状态"}),e.jsx(We,{children:"名称"}),e.jsx(We,{children:"ID"}),e.jsx(We,{children:"优先级"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:r.map(O=>e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(Ve,{checked:O.enabled,onCheckedChange:()=>C(O)})}),e.jsx(Ke,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:O.name}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Raw: ",O.raw_prefix]})]})}),e.jsx(Ke,{children:e.jsx(ke,{variant:"outline",children:O.id})}),e.jsx(Ke,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono",children:O.priority}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(_,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>I(O,"up"),disabled:O.priority===1,children:e.jsx(Qr,{className:"h-3 w-3"})}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>I(O,"down"),children:e.jsx(za,{className:"h-3 w-3"})})]})]})}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>D(O),children:e.jsx(Kn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>E(O.id),children:e.jsx(ns,{className:"h-4 w-4 text-destructive"})})]})})]},O.id))})]})}),e.jsx("div",{className:"md:hidden p-4 space-y-4",children:r.map(O=>e.jsx(Ce,{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:O.name}),O.enabled&&e.jsx(ke,{variant:"default",className:"text-xs",children:"启用"})]}),e.jsx(ke,{variant:"outline",className:"mt-1 text-xs",children:O.id})]}),e.jsx(Ve,{checked:O.enabled,onCheckedChange:()=>C(O)})]}),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:O.raw_prefix})]}),e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"优先级: "}),e.jsx("span",{className:"font-mono",children:O.priority})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t",children:[e.jsxs(_,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>D(O),children:[e.jsx(Kn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>I(O,"up"),disabled:O.priority===1,children:e.jsx(Qr,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>I(O,"down"),children:e.jsx(za,{className:"h-4 w-4"})}),e.jsx(_,{variant:"destructive",size:"sm",onClick:()=>E(O.id),children:e.jsx(ns,{className:"h-4 w-4"})})]})]})},O.id))})]}),e.jsx(Ps,{open:N,onOpenChange:v,children:e.jsxs(Ds,{className:"max-w-lg",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"添加镜像源"}),e.jsx(Ks,{children:"添加新的 Git 镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-id",children:"镜像源 ID *"}),e.jsx(le,{id:"add-id",placeholder:"例如: my-mirror",value:y.id,onChange:O=>A({...y,id:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-name",children:"名称 *"}),e.jsx(le,{id:"add-name",placeholder:"例如: 我的镜像源",value:y.name,onChange:O=>A({...y,name:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-raw",children:"Raw 文件前缀 *"}),e.jsx(le,{id:"add-raw",placeholder:"https://example.com/raw",value:y.raw_prefix,onChange:O=>A({...y,raw_prefix:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-clone",children:"克隆前缀 *"}),e.jsx(le,{id:"add-clone",placeholder:"https://example.com/clone",value:y.clone_prefix,onChange:O=>A({...y,clone_prefix:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-priority",children:"优先级"}),e.jsx(le,{id:"add-priority",type:"number",min:"1",value:y.priority,onChange:O=>A({...y,priority:parseInt(O.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(Ve,{id:"add-enabled",checked:y.enabled,onCheckedChange:O=>A({...y,enabled:O})}),e.jsx(T,{htmlFor:"add-enabled",children:"启用此镜像源"})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>v(!1),children:"取消"}),e.jsx(_,{onClick:S,children:"添加"})]})]})}),e.jsx(Ps,{open:w,onOpenChange:b,children:e.jsxs(Ds,{className:"max-w-lg",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑镜像源"}),e.jsx(Ks,{children:"修改镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"镜像源 ID"}),e.jsx(le,{value:y.id,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-name",children:"名称 *"}),e.jsx(le,{id:"edit-name",value:y.name,onChange:O=>A({...y,name:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-raw",children:"Raw 文件前缀 *"}),e.jsx(le,{id:"edit-raw",value:y.raw_prefix,onChange:O=>A({...y,raw_prefix:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-clone",children:"克隆前缀 *"}),e.jsx(le,{id:"edit-clone",value:y.clone_prefix,onChange:O=>A({...y,clone_prefix:O.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-priority",children:"优先级"}),e.jsx(le,{id:"edit-priority",type:"number",min:"1",value:y.priority,onChange:O=>A({...y,priority:parseInt(O.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(Ve,{id:"edit-enabled",checked:y.enabled,onCheckedChange:O=>A({...y,enabled:O})}),e.jsx(T,{htmlFor:"edit-enabled",children:"启用此镜像源"})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>b(!1),children:"取消"}),e.jsx(_,{onClick:U,children:"保存"})]})]})})]})})}function NC({pluginId:a,compact:n=!1}){const[r,c]=m.useState(null),[d,u]=m.useState(!0),[h,f]=m.useState(0),[p,g]=m.useState(""),[N,v]=m.useState(!1),{toast:w}=Ys(),b=async()=>{u(!0);const S=await mN(a);S&&c(S),u(!1)};m.useEffect(()=>{b()},[a]);const y=async()=>{const S=await iC(a);S.success?(w({title:"已点赞",description:"感谢你的支持!"}),b()):w({title:"点赞失败",description:S.error||"未知错误",variant:"destructive"})},A=async()=>{const S=await cC(a);S.success?(w({title:"已反馈",description:"感谢你的反馈!"}),b()):w({title:"操作失败",description:S.error||"未知错误",variant:"destructive"})},z=async()=>{if(h===0){w({title:"请选择评分",description:"至少选择 1 颗星",variant:"destructive"});return}const S=await oC(a,h,p||void 0);S.success?(w({title:"评分成功",description:"感谢你的评价!"}),v(!1),f(0),g(""),b()):w({title:"评分失败",description:S.error||"未知错误",variant:"destructive"})};return d?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(Xt,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(mn,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]})]}):r?n?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",title:`下载量: ${r.downloads.toLocaleString()}`,children:[e.jsx(Xt,{className:"h-4 w-4"}),e.jsx("span",{children:r.downloads.toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`评分: ${r.rating.toFixed(1)} (${r.rating_count} 条评价)`,children:[e.jsx(mn,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:r.rating.toFixed(1)})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`点赞数: ${r.likes}`,children:[e.jsx(Em,{className:"h-4 w-4"}),e.jsx("span",{children:r.likes})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Xt,{className:"h-5 w-5 text-muted-foreground mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.downloads.toLocaleString()}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"下载量"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(mn,{className:"h-5 w-5 text-yellow-400 mb-1 fill-yellow-400"}),e.jsx("span",{className:"text-2xl font-bold",children:r.rating.toFixed(1)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[r.rating_count," 条评价"]})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Em,{className:"h-5 w-5 text-green-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.likes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点赞"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(wg,{className:"h-5 w-5 text-red-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.dislikes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点踩"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:y,children:[e.jsx(Em,{className:"h-4 w-4 mr-1"}),"点赞"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:A,children:[e.jsx(wg,{className:"h-4 w-4 mr-1"}),"点踩"]}),e.jsxs(Ps,{open:N,onOpenChange:v,children:[e.jsx(cd,{asChild:!0,children:e.jsxs(_,{variant:"default",size:"sm",children:[e.jsx(mn,{className:"h-4 w-4 mr-1"}),"评分"]})}),e.jsxs(Ds,{children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"为插件评分"}),e.jsx(Ks,{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(S=>e.jsx("button",{onClick:()=>f(S),className:"focus:outline-none",children:e.jsx(mn,{className:`h-8 w-8 transition-colors ${S<=h?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-yellow-300"}`})},S))}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h===0&&"点击星星进行评分",h===1&&"很差",h===2&&"一般",h===3&&"还行",h===4&&"不错",h===5&&"非常好"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"评论(可选)"}),e.jsx(ot,{value:p,onChange:S=>g(S.target.value),placeholder:"分享你的使用体验...",rows:4,maxLength:500}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 text-right",children:[p.length," / 500"]})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>v(!1),children:"取消"}),e.jsx(_,{onClick:z,disabled:h===0,children:"提交评分"})]})]})]})]}),r.recent_ratings&&r.recent_ratings.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"最近评价"}),e.jsx("div",{className:"space-y-3",children:r.recent_ratings.map((S,U)=>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(E=>e.jsx(mn,{className:`h-3 w-3 ${E<=S.rating?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},E))}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(S.created_at).toLocaleDateString()})]}),S.comment&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.comment})]},U))})]})]}):null}const bC={"Group Management":"群组管理","Entertainment & Interaction":"娱乐互动","Utility Tools":"实用工具","Content Generation":"内容生成",Multimedia:"多媒体","External Integration":"外部集成","Data Analysis & Insights":"数据分析与洞察",Other:"其他"};function yC(){const a=ca(),n=J0({strict:!1}),{toast:r}=Ys(),[c,d]=m.useState(null),[u,h]=m.useState(""),[f,p]=m.useState(!0),[g,N]=m.useState(!0),[v,w]=m.useState(null),[b,y]=m.useState(null),[A,z]=m.useState(null),[S,U]=m.useState(!1),[E,C]=m.useState(),[D,I]=m.useState(!1);m.useEffect(()=>{(async()=>{if(!n.pluginId){w("缺少插件 ID"),p(!1);return}try{p(!0),w(null);const he=await _e("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:"Mai-with-u",repo:"plugin-repo",branch:"main",file_path:"plugin_details.json"})});if(!he.ok)throw new Error("获取插件列表失败");const ge=await he.json();if(!ge.success||!ge.data)throw new Error(ge.error||"获取插件列表失败");const Y=JSON.parse(ge.data).find(fe=>fe.id===n.pluginId);if(!Y)throw new Error("未找到该插件");const $={id:Y.id,manifest:Y.manifest,downloads:0,rating:0,review_count:0,installed:!1,published_at:new Date().toISOString(),updated_at:new Date().toISOString()};d($);const[ue,G,Se]=await Promise.all([rN(),iN(),Dl()]);y(ue),z(G),U(hn(n.pluginId,Se)),C(fn(n.pluginId,Se))}catch(he){w(he instanceof Error?he.message:"加载失败")}finally{p(!1)}})()},[n.pluginId]),m.useEffect(()=>{(async()=>{if(!c?.manifest?.repository_url){N(!1);return}try{if(N(!0),S&&n.pluginId)try{const G=await _e(`/api/webui/plugins/local-readme/${n.pluginId}`);if(G.ok){const Se=await G.json();if(Se.success&&Se.data){h(Se.data),N(!1);return}}}catch(G){console.log("本地 README 获取失败,尝试远程获取:",G)}const he=c.manifest.repository_url.match(/github\.com\/([^/]+)\/([^/\s]+)/);if(!he){h("无法解析仓库地址");return}const[,ge,R]=he,Y=R.replace(/\.git$/,""),$=await _e("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:ge,repo:Y,branch:"main",file_path:"README.md"})});if(!$.ok)throw new Error("获取 README 失败");const ue=await $.json();ue.success&&ue.data?h(ue.data):h("该插件暂无 README 文档")}catch(he){console.error("加载 README 失败:",he),h("加载 README 失败")}finally{N(!1)}})()},[c,S,n.pluginId]);const O=()=>!c||!S||!E?!1:E!==c.manifest.version,X=()=>!c||!A?!0:cN(c.manifest.host_application.min_version,c.manifest.host_application.max_version,A),L=async()=>{if(!(!c||!b?.installed))try{I(!0),await oN(c.id,c.manifest.repository_url||"","main"),xN(c.id).catch(he=>{console.warn("Failed to record download:",he)}),r({title:"安装成功",description:`${c.manifest.name} 已成功安装`});const de=await Dl();U(hn(c.id,de)),C(fn(c.id,de))}catch(de){r({title:"安装失败",description:de instanceof Error?de.message:"未知错误",variant:"destructive"})}finally{I(!1)}},oe=async()=>{if(c)try{I(!0),await dN(c.id),r({title:"卸载成功",description:`${c.manifest.name} 已成功卸载`});const de=await Dl();U(hn(c.id,de)),C(fn(c.id,de))}catch(de){r({title:"卸载失败",description:de instanceof Error?de.message:"未知错误",variant:"destructive"})}finally{I(!1)}},Ne=async()=>{if(!(!c||!b?.installed))try{I(!0);const de=await uN(c.id,c.manifest.repository_url||"","main");r({title:"更新成功",description:`${c.manifest.name} 已从 ${de.old_version} 更新到 ${de.new_version}`});const he=await Dl();U(hn(c.id,he)),C(fn(c.id,he))}catch(de){r({title:"更新失败",description:de instanceof Error?de.message:"未知错误",variant:"destructive"})}finally{I(!1)}};if(f)return e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>a({to:"/plugins"}),children:e.jsx(Ma,{className:"h-5 w-5"})}),e.jsx("div",{children:e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件详情"})})]}),e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件信息中..."})]})]});if(v||!c)return e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>a({to:"/plugins"}),children:e.jsx(Ma,{className:"h-5 w-5"})}),e.jsx("div",{children:e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件详情"})})]}),e.jsx(Ce,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(_t,{className:"h-12 w-12 text-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:v}),e.jsx(_,{onClick:()=>a({to:"/plugins"}),children:"返回插件列表"})]})})]});const je=X();return 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",{className:"flex items-center gap-3",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>a({to:"/plugins"}),className:"shrink-0",children:e.jsx(Ma,{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-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:c.manifest.name})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:S?e.jsxs(e.Fragment,{children:[O()?e.jsx(_,{disabled:!b?.installed||D,onClick:Ne,title:b?.installed?void 0:"Git 未安装",children:D?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"更新中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(dt,{className:"h-4 w-4 mr-2"}),"更新"]})}):null,e.jsx(_,{variant:"destructive",disabled:!b?.installed||D,onClick:oe,title:b?.installed?void 0:"Git 未安装",children:D?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"卸载中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ns,{className:"h-4 w-4 mr-2"}),"卸载"]})})]}):e.jsx(_,{disabled:!b?.installed||!je||D,onClick:L,title:b?.installed?je?void 0:`不兼容当前版本 (需要 ${c.manifest.host_application.min_version}${c.manifest.host_application.max_version?` - ${c.manifest.host_application.max_version}`:"+"},当前 ${A?.version})`:"Git 未安装",children:D?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"安装中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Xt,{className:"h-4 w-4 mr-2"}),"安装"]})})})]}),e.jsx(Je,{className:"h-[calc(100vh-200px)] sm:h-[calc(100vh-220px)]",children:e.jsxs("div",{className:"space-y-6 pr-4",children:[e.jsx(Ce,{children:e.jsx(De,{children:e.jsx("div",{className:"flex items-start justify-between gap-4",children:e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx(Oe,{className:"text-2xl",children:c.manifest.name}),e.jsxs(ke,{variant:"secondary",className:"text-sm",children:["v",c.manifest.version]}),S&&e.jsxs(ke,{variant:"default",className:"text-sm",children:[e.jsx(pt,{className:"h-3 w-3 mr-1"}),"已安装 ",E&&`(v${E})`]}),O()&&e.jsxs(ke,{variant:"outline",className:"text-sm border-orange-500 text-orange-500",children:[e.jsx(dt,{className:"h-3 w-3 mr-1"}),"可更新"]}),!je&&e.jsxs(ke,{variant:"destructive",className:"text-sm",children:[e.jsx(_t,{className:"h-3 w-3 mr-1"}),"不兼容"]})]}),e.jsx(os,{className:"text-base",children:c.manifest.description})]})})})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-1 space-y-6",children:[e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{className:"text-lg",children:"统计信息"})}),e.jsx(Me,{children:e.jsx(NC,{pluginId:c.id})})]}),e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{className:"text-lg",children:"基本信息"})}),e.jsx(Me,{className:"space-y-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(jn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"作者:"}),e.jsx("span",{className:"font-medium",children:c.manifest.author?.name||"Unknown"}),c.manifest.author?.url&&e.jsx("a",{href:c.manifest.author.url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:e.jsx($o,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ra,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"版本:"}),e.jsxs("span",{className:"font-medium",children:["v",c.manifest.version]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ev,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"许可证:"}),e.jsx("span",{className:"font-medium",children:c.manifest.license})]}),c.manifest.homepage_url&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Vo,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"主页:"}),e.jsxs("a",{href:c.manifest.homepage_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline flex items-center gap-1",children:["访问",e.jsx($o,{className:"h-3 w-3"})]})]}),c.manifest.repository_url&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(I_,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"仓库:"}),e.jsxs("a",{href:c.manifest.repository_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline flex items-center gap-1",children:["GitHub",e.jsx($o,{className:"h-3 w-3"})]})]}),e.jsxs("div",{className:"pt-2 border-t",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm mb-2",children:[e.jsx(Ft,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"支持版本:"})]}),e.jsxs("div",{className:"text-sm pl-6 font-medium",children:[c.manifest.host_application.min_version,c.manifest.host_application.max_version?` - ${c.manifest.host_application.max_version}`:" - 最新版本"]})]})]})})]}),(c.manifest.categories||c.manifest.keywords)&&e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{className:"text-lg",children:"分类与标签"})}),e.jsxs(Me,{className:"space-y-4",children:[c.manifest.categories&&c.manifest.categories.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"分类"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:c.manifest.categories.map(de=>e.jsx(ke,{variant:"secondary",children:bC[de]||de},de))})]}),c.manifest.keywords&&c.manifest.keywords.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"标签"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:c.manifest.keywords.map(de=>e.jsxs(ke,{variant:"outline",className:"text-xs",children:[e.jsx(rd,{className:"h-3 w-3 mr-1"}),de]},de))})]})]})]})]}),e.jsxs(Ce,{className:"lg:col-span-2",children:[e.jsx(De,{children:e.jsx(Oe,{className:"text-lg",children:"插件说明"})}),e.jsx(Me,{children:e.jsx(Je,{className:"h-[600px] pr-4",children:g?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(zs,{className:"h-6 w-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-sm text-muted-foreground",children:"加载说明文档中..."})]}):u?e.jsx(fx,{content:u}):e.jsx("div",{className:"text-center text-muted-foreground py-12",children:"暂无说明文档"})})})]})]})]})})]})}const Zi=m.forwardRef(({className:a,...n},r)=>e.jsx(_j,{ref:r,className:F("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",a),...n}));Zi.displayName=_j.displayName;const wC=m.forwardRef(({className:a,...n},r)=>e.jsx(Sj,{ref:r,className:F("aspect-square h-full w-full",a),...n}));wC.displayName=Sj.displayName;const Wi=m.forwardRef(({className:a,...n},r)=>e.jsx(kj,{ref:r,className:F("flex h-full w-full items-center justify-center rounded-full bg-muted",a),...n}));Wi.displayName=kj.displayName;function _C(){return"webui_"+Math.random().toString(36).substr(2,9)+"_"+Date.now().toString(36)}function SC(){const a="maibot_webui_user_id";let n=localStorage.getItem(a);return n||(n=_C(),localStorage.setItem(a,n)),n}function kC(){return localStorage.getItem("maibot_webui_user_name")||"WebUI用户"}function CC(a){localStorage.setItem("maibot_webui_user_name",a)}const hN="maibot_webui_virtual_tabs";function TC(){try{const a=localStorage.getItem(hN);if(a)return JSON.parse(a)}catch(a){console.error("[Chat] 加载虚拟标签页失败:",a)}return[]}function Zg(a){try{localStorage.setItem(hN,JSON.stringify(a))}catch(n){console.error("[Chat] 保存虚拟标签页失败:",n)}}function EC({segment:a}){switch(a.type){case"text":return e.jsx("span",{className:"whitespace-pre-wrap",children:String(a.data)});case"image":case"emoji":return e.jsx("img",{src:String(a.data),alt:a.type==="emoji"?"表情包":"图片",className:F("rounded-lg max-w-full",a.type==="emoji"?"max-h-32":"max-h-64"),loading:"lazy",onError:n=>{const r=n.target;r.style.display="none",r.parentElement?.insertAdjacentHTML("beforeend",`[${a.type==="emoji"?"表情包":"图片"}加载失败]`)}});case"voice":return e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("audio",{controls:!0,src:String(a.data),className:"max-w-[200px] h-8",children:"您的浏览器不支持音频播放"})});case"video":return e.jsx("video",{controls:!0,src:String(a.data),className:"rounded-lg max-w-full max-h-64",children:"您的浏览器不支持视频播放"});case"face":return e.jsxs("span",{className:"text-muted-foreground",children:["[表情:",String(a.data),"]"]});case"music":return e.jsx("span",{className:"text-muted-foreground",children:"[音乐分享]"});case"file":return e.jsxs("span",{className:"text-muted-foreground",children:["[文件: ",String(a.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:["[",a.original_type||"未知消息","]"]})}}function MC({message:a,isBot:n}){return a.message_type==="rich"&&a.segments&&a.segments.length>0?e.jsx("div",{className:"flex flex-col gap-2",children:a.segments.map((r,c)=>e.jsx(EC,{segment:r},c))}):e.jsx("span",{className:"whitespace-pre-wrap",children:a.content})}function AC(){const a={id:"webui-default",type:"webui",label:"WebUI",messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}},n=()=>{const qe=TC().map(Qe=>{const es=Qe.virtualConfig;return!es.groupId&&es.platform&&es.userId&&(es.groupId=`webui_virtual_group_${es.platform}_${es.userId}`),{id:Qe.id,type:"virtual",label:Qe.label,virtualConfig:es,messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}}});return[a,...qe]},[r,c]=m.useState(n),[d,u]=m.useState("webui-default"),h=r.find(K=>K.id===d)||r[0],[f,p]=m.useState(""),[g,N]=m.useState(!1),[v,w]=m.useState(!0),[b,y]=m.useState(kC()),[A,z]=m.useState(!1),[S,U]=m.useState(""),[E,C]=m.useState(!1),[D,I]=m.useState([]),[O,X]=m.useState([]),[L,oe]=m.useState(!1),[Ne,je]=m.useState(!1),[de,he]=m.useState(""),[ge,R]=m.useState({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),Y=m.useRef(SC()),$=m.useRef(new Map),ue=m.useRef(null),G=m.useRef(new Map),Se=m.useRef(0),fe=m.useRef(new Map),{toast:Te}=Ys(),q=K=>(Se.current+=1,`${K}-${Date.now()}-${Se.current}-${Math.random().toString(36).substr(2,9)}`),B=m.useCallback((K,qe)=>{c(Qe=>Qe.map(es=>es.id===K?{...es,...qe}:es))},[]),M=m.useCallback((K,qe)=>{c(Qe=>Qe.map(es=>es.id===K?{...es,messages:[...es.messages,qe]}:es))},[]),Q=m.useCallback(()=>{ue.current?.scrollIntoView({behavior:"smooth"})},[]);m.useEffect(()=>{Q()},[h?.messages,Q]);const Ae=m.useCallback(async()=>{oe(!0);try{const K=await _e("/api/chat/platforms");if(console.log("[Chat] 平台列表响应:",K.status,K.headers.get("content-type")),K.ok){const qe=K.headers.get("content-type");if(qe&&qe.includes("application/json")){const Qe=await K.json();console.log("[Chat] 平台列表数据:",Qe),I(Qe.platforms||[])}else{const Qe=await K.text();console.error("[Chat] 获取平台列表失败: 非 JSON 响应:",Qe.substring(0,200)),Te({title:"连接失败",description:"无法连接到后端服务,请确保 MaiBot 已启动",variant:"destructive"})}}else console.error("[Chat] 获取平台列表失败: HTTP",K.status),Te({title:"获取平台失败",description:`服务器返回错误: ${K.status}`,variant:"destructive"})}catch(K){console.error("[Chat] 获取平台列表失败:",K),Te({title:"网络错误",description:"无法连接到后端服务",variant:"destructive"})}finally{oe(!1)}},[Te]),ee=m.useCallback(async(K,qe)=>{je(!0);try{const Qe=new URLSearchParams;K&&Qe.append("platform",K),qe&&Qe.append("search",qe),Qe.append("limit","50");const es=await _e(`/api/chat/persons?${Qe.toString()}`);if(es.ok){const Us=es.headers.get("content-type");if(Us&&Us.includes("application/json")){const as=await es.json();X(as.persons||[])}else console.error("[Chat] 获取用户列表失败: 后端返回非 JSON 响应")}}catch(Qe){console.error("[Chat] 获取用户列表失败:",Qe)}finally{je(!1)}},[]);m.useEffect(()=>{ge.platform&&ee(ge.platform,de)},[ge.platform,de,ee]);const J=m.useCallback(async(K,qe)=>{w(!0);try{const Qe=new URLSearchParams;Qe.append("user_id",Y.current),Qe.append("limit","50"),qe&&Qe.append("group_id",qe);const es=`/api/chat/history?${Qe.toString()}`;console.log("[Chat] 正在加载历史消息:",es);const Us=await _e(es);if(Us.ok){const as=await Us.text();try{const Cs=JSON.parse(as);if(Cs.messages&&Cs.messages.length>0){const Re=Cs.messages.map(ls=>({id:ls.id,type:ls.type,content:ls.content,timestamp:ls.timestamp,sender:{name:ls.sender_name||(ls.is_bot?"麦麦":"WebUI用户"),user_id:ls.user_id,is_bot:ls.is_bot}}));B(K,{messages:Re});const bs=fe.current.get(K)||new Set;Re.forEach(ls=>{if(ls.type==="bot"){const ss=`bot-${ls.content}-${Math.floor(ls.timestamp*1e3)}`;bs.add(ss)}}),fe.current.set(K,bs)}}catch(Cs){console.error("[Chat] JSON 解析失败:",Cs)}}}catch(Qe){console.error("[Chat] 加载历史消息失败:",Qe)}finally{w(!1)}},[B]),$e=m.useCallback(async(K,qe,Qe)=>{const es=$.current.get(K);if(es?.readyState===WebSocket.OPEN||es?.readyState===WebSocket.CONNECTING){console.log(`[Tab ${K}] WebSocket 已存在,跳过连接`);return}N(!0);let Us=null;try{const bs=await _e("/api/webui/ws-token");if(bs.ok){const ls=await bs.json();if(ls.success&&ls.token)Us=ls.token;else{console.warn(`[Tab ${K}] 获取 WebSocket token 失败: ${ls.message||"未登录"}`),N(!1);return}}}catch(bs){console.error(`[Tab ${K}] 获取 WebSocket token 失败:`,bs),N(!1);return}if(!Us){N(!1);return}const as=window.location.protocol==="https:"?"wss:":"ws:",Cs=new URLSearchParams;Cs.append("token",Us),qe==="virtual"&&Qe?(Cs.append("user_id",Qe.userId),Cs.append("user_name",Qe.userName),Cs.append("platform",Qe.platform),Cs.append("person_id",Qe.personId),Cs.append("group_name",Qe.groupName||"WebUI虚拟群聊"),Qe.groupId&&Cs.append("group_id",Qe.groupId)):(Cs.append("user_id",Y.current),Cs.append("user_name",b));const Re=`${as}//${window.location.host}/api/chat/ws?${Cs.toString()}`;console.log(`[Tab ${K}] 正在连接 WebSocket:`,Re);try{const bs=new WebSocket(Re);$.current.set(K,bs),bs.onopen=()=>{B(K,{isConnected:!0}),N(!1),console.log(`[Tab ${K}] WebSocket 已连接`)},bs.onmessage=ls=>{try{const ss=JSON.parse(ls.data);switch(ss.type){case"session_info":B(K,{sessionInfo:{session_id:ss.session_id,user_id:ss.user_id,user_name:ss.user_name,bot_name:ss.bot_name}});break;case"system":M(K,{id:q("sys"),type:"system",content:ss.content||"",timestamp:ss.timestamp||Date.now()/1e3});break;case"user_message":{const ys=ss.sender?.user_id,gt=qe==="virtual"&&Qe?Qe.userId:Y.current;console.log(`[Tab ${K}] 收到 user_message, sender: ${ys}, current: ${gt}`);const $t=ys?ys.replace(/^webui_user_/,""):"",tt=gt?gt.replace(/^webui_user_/,""):"";if($t&&tt&&$t===tt){console.log(`[Tab ${K}] 跳过自己的消息(user_id 匹配)`);break}const Ms=fe.current.get(K)||new Set,Et=`user-${ss.content}-${Math.floor((ss.timestamp||0)*1e3)}`;if(Ms.has(Et)){console.log(`[Tab ${K}] 跳过自己的消息(内容去重)`);break}if(Ms.add(Et),fe.current.set(K,Ms),Ms.size>100){const Bt=Ms.values().next().value;Bt&&Ms.delete(Bt)}M(K,{id:ss.message_id||q("user"),type:"user",content:ss.content||"",timestamp:ss.timestamp||Date.now()/1e3,sender:ss.sender});break}case"bot_message":{B(K,{isTyping:!1});const ys=fe.current.get(K)||new Set,gt=`bot-${ss.content}-${Math.floor((ss.timestamp||0)*1e3)}`;if(ys.has(gt))break;if(ys.add(gt),fe.current.set(K,ys),ys.size>100){const $t=ys.values().next().value;$t&&ys.delete($t)}c($t=>$t.map(tt=>{if(tt.id!==K)return tt;const Ms=tt.messages.filter(Bt=>Bt.type!=="thinking"),Et={id:q("bot"),type:"bot",content:ss.content||"",message_type:ss.message_type==="rich"?"rich":"text",segments:ss.segments,timestamp:ss.timestamp||Date.now()/1e3,sender:ss.sender};return{...tt,messages:[...Ms,Et]}}));break}case"typing":B(K,{isTyping:ss.is_typing||!1});break;case"error":c(ys=>ys.map(gt=>{if(gt.id!==K)return gt;const $t=gt.messages.filter(tt=>tt.type!=="thinking");return{...gt,messages:[...$t,{id:q("error"),type:"error",content:ss.content||"发生错误",timestamp:ss.timestamp||Date.now()/1e3}]}})),Te({title:"错误",description:ss.content,variant:"destructive"});break;case"pong":break;case"history":{const ys=ss.messages||[];if(ys.length>0){const gt=fe.current.get(K)||new Set,$t=ys.map(tt=>{const Ms=tt.is_bot||!1,Et=tt.id||q(Ms?"bot":"user"),Bt=`${Ms?"bot":"user"}-${tt.content}-${Math.floor(tt.timestamp*1e3)}`;return gt.add(Bt),{id:Et,type:Ms?"bot":"user",content:tt.content,timestamp:tt.timestamp,sender:{name:tt.sender_name||(Ms?"麦麦":"用户"),user_id:tt.sender_id,is_bot:Ms}}});fe.current.set(K,gt),B(K,{messages:$t}),console.log(`[Tab ${K}] 已加载 ${$t.length} 条历史消息`)}break}default:console.log("未知消息类型:",ss.type)}}catch(ss){console.error("解析消息失败:",ss)}},bs.onclose=()=>{B(K,{isConnected:!1}),N(!1),$.current.delete(K),console.log(`[Tab ${K}] WebSocket 已断开`);const ls=G.current.get(K);ls&&clearTimeout(ls);const ss=window.setTimeout(()=>{if(!H.current){const ys=r.find(gt=>gt.id===K);ys&&$e(K,ys.type,ys.virtualConfig)}},5e3);G.current.set(K,ss)},bs.onerror=ls=>{console.error(`[Tab ${K}] WebSocket 错误:`,ls),N(!1)}}catch(bs){console.error(`[Tab ${K}] 创建 WebSocket 失败:`,bs),N(!1)}},[b,B,M,Te,r]),H=m.useRef(!1);m.useEffect(()=>{H.current=!1;const K=$.current,qe=G.current,Qe=fe.current;J("webui-default");const es=setTimeout(()=>{H.current||($e("webui-default","webui"),r.forEach(as=>{as.type==="virtual"&&as.virtualConfig&&(Qe.set(as.id,new Set),setTimeout(()=>{H.current||$e(as.id,"virtual",as.virtualConfig)},200))}))},100),Us=setInterval(()=>{K.forEach(as=>{as.readyState===WebSocket.OPEN&&as.send(JSON.stringify({type:"ping"}))})},3e4);return()=>{H.current=!0,clearTimeout(es),clearInterval(Us),qe.forEach(as=>{clearTimeout(as)}),qe.clear(),K.forEach(as=>{as.close()}),K.clear()}},[]);const se=m.useCallback(()=>{const K=$.current.get(d);if(!f.trim()||!K||K.readyState!==WebSocket.OPEN)return;const qe=h?.type==="virtual"&&h.virtualConfig?.userName||b,Qe=f.trim(),es=Date.now()/1e3;K.send(JSON.stringify({type:"message",content:Qe,user_name:qe}));const Us=fe.current.get(d)||new Set,as=`user-${Qe}-${Math.floor(es*1e3)}`;if(Us.add(as),fe.current.set(d,Us),Us.size>100){const bs=Us.values().next().value;bs&&Us.delete(bs)}const Cs={id:q("user"),type:"user",content:Qe,timestamp:es,sender:{name:qe,is_bot:!1}};M(d,Cs);const Re={id:q("thinking"),type:"thinking",content:"",timestamp:es+.001,sender:{name:h?.sessionInfo.bot_name||"麦麦",is_bot:!0}};M(d,Re),p("")},[f,b,d,h,M]),Ue=K=>{K.key==="Enter"&&!K.shiftKey&&(K.preventDefault(),se())},ie=()=>{U(b),z(!0)},Ee=()=>{const K=S.trim()||"WebUI用户";y(K),CC(K),z(!1);const qe=$.current.get(d);qe?.readyState===WebSocket.OPEN&&qe.send(JSON.stringify({type:"update_nickname",user_name:K}))},me=()=>{U(""),z(!1)},ze=K=>new Date(K*1e3).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),rs=()=>{const K=$.current.get(d);K&&(K.close(),$.current.delete(d)),$e(d,h?.type||"webui",h?.virtualConfig)},Ut=()=>{R({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),he(""),Ae(),C(!0)},aa=()=>{if(!ge.platform||!ge.personId){Te({title:"配置不完整",description:"请选择平台和用户",variant:"destructive"});return}const K=`webui_virtual_group_${ge.platform}_${ge.userId}`,qe=`virtual-${ge.platform}-${ge.userId}-${Date.now()}`,Qe=ge.userName||ge.userId,es={id:qe,type:"virtual",label:Qe,virtualConfig:{...ge,groupId:K},messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}};c(Us=>{const as=[...Us,es],Cs=as.filter(Re=>Re.type==="virtual"&&Re.virtualConfig).map(Re=>({id:Re.id,label:Re.label,virtualConfig:Re.virtualConfig,createdAt:Date.now()}));return Zg(Cs),as}),u(qe),C(!1),fe.current.set(qe,new Set),setTimeout(()=>{$e(qe,"virtual",ge)},100),Te({title:"虚拟身份标签页",description:`已创建 ${Qe} 的对话`})},Ja=(K,qe)=>{if(qe?.stopPropagation(),K==="webui-default")return;const Qe=$.current.get(K);Qe&&(Qe.close(),$.current.delete(K));const es=G.current.get(K);es&&(clearTimeout(es),G.current.delete(K)),fe.current.delete(K),c(Us=>{const as=Us.filter(Re=>Re.id!==K),Cs=as.filter(Re=>Re.type==="virtual"&&Re.virtualConfig).map(Re=>({id:Re.id,label:Re.label,virtualConfig:Re.virtualConfig,createdAt:Date.now()}));return Zg(Cs),as}),d===K&&u("webui-default")},Ht=K=>{u(K)},mt=K=>{R(qe=>({...qe,personId:K.person_id,userId:K.user_id,userName:K.nickname||K.person_name}))};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx(Ps,{open:E,onOpenChange:C,children:e.jsxs(Ds,{className:"sm:max-w-[500px] max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(Mm,{className:"h-5 w-5"}),"新建虚拟身份对话"]}),e.jsx(Ks,{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(T,{className:"flex items-center gap-2",children:[e.jsx(Vo,{className:"h-4 w-4"}),"选择平台"]}),e.jsxs(Ie,{value:ge.platform,onValueChange:K=>{R(qe=>({...qe,platform:K,personId:"",userId:"",userName:""})),X([])},children:[e.jsx(Be,{disabled:L,children:e.jsx(Fe,{placeholder:L?"加载中...":"选择平台"})}),e.jsx(Pe,{children:D.map(K=>e.jsxs(W,{value:K.platform,children:[K.platform," (",K.count," 人)"]},K.platform))})]})]}),ge.platform&&e.jsxs("div",{className:"space-y-2 flex-1 overflow-hidden flex flex-col",children:[e.jsxs(T,{className:"flex items-center gap-2",children:[e.jsx(ic,{className:"h-4 w-4"}),"选择用户"]}),e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(le,{placeholder:"搜索用户名...",value:de,onChange:K=>he(K.target.value),className:"pl-9"})]}),e.jsx(Je,{className:"h-[250px] border rounded-md",children:e.jsx("div",{className:"p-2",children:Ne?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(zs,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):O.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[e.jsx(ic,{className:"h-8 w-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"没有找到用户"})]}):e.jsx("div",{className:"space-y-1",children:O.map(K=>e.jsxs("button",{onClick:()=>mt(K),className:F("w-full flex items-center gap-3 p-2 rounded-md text-left transition-colors",ge.personId===K.person_id?"bg-primary text-primary-foreground":"hover:bg-muted"),children:[e.jsx(Zi,{className:"h-8 w-8 shrink-0",children:e.jsx(Wi,{className:F("text-xs",ge.personId===K.person_id?"bg-primary-foreground/20":"bg-muted"),children:(K.nickname||K.person_name||"?").charAt(0)})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium truncate",children:K.nickname||K.person_name}),e.jsxs("div",{className:F("text-xs truncate",ge.personId===K.person_id?"text-primary-foreground/70":"text-muted-foreground"),children:["ID: ",K.user_id,K.is_known&&" · 已认识"]})]})]},K.person_id))})})})]}),ge.personId&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"虚拟群名(可选)"}),e.jsx(le,{placeholder:"WebUI虚拟群聊",value:ge.groupName,onChange:K=>R(qe=>({...qe,groupName:K.target.value}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦会认为这是一个名为此名称的群聊"})]})]}),e.jsxs(st,{className:"gap-2 sm:gap-0",children:[e.jsx(_,{variant:"outline",onClick:()=>C(!1),children:"取消"}),e.jsx(_,{onClick:aa,disabled:!ge.platform||!ge.personId,children:"创建对话"})]})]})}),e.jsx("div",{className:"shrink-0 border-b bg-muted/30",children:e.jsx("div",{className:"max-w-4xl mx-auto px-2 sm:px-4",children:e.jsxs("div",{className:"flex items-center gap-1 overflow-x-auto py-1.5 scrollbar-thin",children:[r.map(K=>e.jsxs("div",{className:F("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm whitespace-nowrap transition-colors cursor-pointer","hover:bg-muted",d===K.id?"bg-background shadow-sm border":"text-muted-foreground"),onClick:()=>Ht(K.id),children:[K.type==="webui"?e.jsx(Ra,{className:"h-3.5 w-3.5"}):e.jsx(Mm,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"max-w-[100px] truncate",children:K.label}),e.jsx("span",{className:F("w-1.5 h-1.5 rounded-full",K.isConnected?"bg-green-500":"bg-muted-foreground/50")}),K.id!=="webui-default"&&e.jsx("span",{onClick:qe=>Ja(K.id,qe),className:"ml-0.5 p-0.5 rounded hover:bg-muted-foreground/20 cursor-pointer",role:"button",tabIndex:0,onKeyDown:qe=>{(qe.key==="Enter"||qe.key===" ")&&(qe.preventDefault(),Ja(K.id,qe))},children:e.jsx(Aa,{className:"h-3 w-3"})})]},K.id)),e.jsx("button",{onClick:Ut,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(et,{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(Zi,{className:"h-8 w-8 sm:h-10 sm:w-10 shrink-0",children:e.jsx(Wi,{className:"bg-primary/10 text-primary",children:e.jsx(Vn,{className:"h-4 w-4 sm:h-5 sm:w-5"})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-base sm:text-lg font-semibold truncate",children:h?.sessionInfo.bot_name||"麦麦"}),e.jsx("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:h?.isConnected?e.jsxs(e.Fragment,{children:[e.jsx(F_,{className:"h-3 w-3 text-green-500"}),e.jsx("span",{className:"text-green-600 dark:text-green-400",children:"已连接"})]}):g?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"连接中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(H_,{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:[v&&e.jsx(zs,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:rs,disabled:g,title:"重新连接",children:e.jsx(dt,{className:F("h-4 w-4",g&&"animate-spin")})})]})]}),e.jsx("div",{className:"hidden sm:flex items-center gap-2 mt-2 text-sm text-muted-foreground",children:h?.type==="virtual"&&h.virtualConfig?e.jsxs(e.Fragment,{children:[e.jsx(Mm,{className:"h-3 w-3 text-primary"}),e.jsx("span",{children:"虚拟身份:"}),e.jsx("span",{className:"font-medium text-primary",children:h.virtualConfig.userName}),e.jsxs("span",{className:"text-xs",children:["(",h.virtualConfig.platform,")"]}),h.virtualConfig.groupName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1",children:"·"}),e.jsxs("span",{className:"text-xs",children:["群:",h.virtualConfig.groupName]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(jn,{className:"h-3 w-3"}),e.jsx("span",{children:"当前身份:"}),A?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{value:S,onChange:K=>U(K.target.value),onKeyDown:K=>{K.key==="Enter"&&Ee(),K.key==="Escape"&&me()},className:"h-7 w-32",placeholder:"输入昵称",autoFocus:!0}),e.jsx(_,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:Ee,children:"保存"}),e.jsx(_,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:me,children:"取消"})]}):e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-foreground",children:b}),e.jsx(_,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:ie,title:"修改昵称",children:e.jsx(V_,{className:"h-3 w-3"})})]})]})})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"p-3 sm:p-4 max-w-4xl mx-auto space-y-3 sm:space-y-4",children:[h?.messages.length===0&&!v&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(Vn,{className:"h-12 w-12 mb-4 opacity-50"}),e.jsxs("p",{className:"text-sm",children:["开始与 ",h?.sessionInfo.bot_name||"麦麦"," 对话吧!"]})]}),h?.messages.map(K=>e.jsxs("div",{className:F("flex gap-2 sm:gap-3",K.type==="user"&&"flex-row-reverse",K.type==="system"&&"justify-center",K.type==="error"&&"justify-center"),children:[K.type==="system"&&e.jsx("div",{className:"text-xs text-muted-foreground bg-muted/50 px-3 py-1 rounded-full max-w-[90%]",children:K.content}),K.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:K.content}),K.type==="thinking"&&e.jsxs(e.Fragment,{children:[e.jsx(Zi,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(Wi,{className:"bg-primary/10 text-primary",children:e.jsx(Vn,{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:K.sender?.name||h?.sessionInfo.bot_name})}),e.jsx("div",{className:"bg-muted rounded-2xl rounded-tl-sm px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("span",{className:"w-2 h-2 bg-primary/60 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"w-2 h-2 bg-primary/60 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("span",{className:"w-2 h-2 bg-primary/60 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]}),e.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:"思考中..."})]})})]})]}),(K.type==="user"||K.type==="bot")&&e.jsxs(e.Fragment,{children:[e.jsx(Zi,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(Wi,{className:F("text-xs",K.type==="bot"?"bg-primary/10 text-primary":"bg-secondary text-secondary-foreground"),children:K.type==="bot"?e.jsx(Vn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}):e.jsx(jn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})}),e.jsxs("div",{className:F("flex flex-col gap-1 max-w-[75%] sm:max-w-[70%]",K.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:K.sender?.name||(K.type==="bot"?h?.sessionInfo.bot_name:b)}),e.jsx("span",{children:ze(K.timestamp)})]}),e.jsx("div",{className:F("rounded-2xl px-3 py-2 text-sm break-words",K.type==="bot"?"bg-muted rounded-tl-sm":"bg-primary text-primary-foreground rounded-tr-sm"),children:e.jsx(MC,{message:K,isBot:K.type==="bot"})})]})]})]},K.id)),e.jsx("div",{ref:ue})]})})}),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(le,{value:f,onChange:K=>p(K.target.value),onKeyDown:Ue,placeholder:h?.isConnected?"输入消息...":"等待连接...",disabled:!h?.isConnected,className:"flex-1 h-10 sm:h-10"}),e.jsx(_,{onClick:se,disabled:!h?.isConnected||!f.trim(),size:"icon",className:"h-10 w-10 shrink-0",children:e.jsx(G_,{className:"h-4 w-4"})})]})})})]})}var _x="Radio",[zC,fN]=td(_x),[RC,DC]=zC(_x),pN=m.forwardRef((a,n)=>{const{__scopeRadio:r,name:c,checked:d=!1,required:u,disabled:h,value:f="on",onCheck:p,form:g,...N}=a,[v,w]=m.useState(null),b=ad(n,z=>w(z)),y=m.useRef(!1),A=v?g||!!v.closest("form"):!0;return e.jsxs(RC,{scope:r,checked:d,disabled:h,children:[e.jsx(Zn.button,{type:"button",role:"radio","aria-checked":d,"data-state":NN(d),"data-disabled":h?"":void 0,disabled:h,value:f,...N,ref:b,onClick:gn(a.onClick,z=>{d||p?.(),A&&(y.current=z.isPropagationStopped(),y.current||z.stopPropagation())})}),A&&e.jsx(vN,{control:v,bubbles:!y.current,name:c,value:f,checked:d,required:u,disabled:h,form:g,style:{transform:"translateX(-100%)"}})]})});pN.displayName=_x;var gN="RadioIndicator",jN=m.forwardRef((a,n)=>{const{__scopeRadio:r,forceMount:c,...d}=a,u=DC(gN,r);return e.jsx(o_,{present:c||u.checked,children:e.jsx(Zn.span,{"data-state":NN(u.checked),"data-disabled":u.disabled?"":void 0,...d,ref:n})})});jN.displayName=gN;var OC="RadioBubbleInput",vN=m.forwardRef(({__scopeRadio:a,control:n,checked:r,bubbles:c=!0,...d},u)=>{const h=m.useRef(null),f=ad(h,u),p=d_(r),g=u_(n);return m.useEffect(()=>{const N=h.current;if(!N)return;const v=window.HTMLInputElement.prototype,b=Object.getOwnPropertyDescriptor(v,"checked").set;if(p!==r&&b){const y=new Event("click",{bubbles:c});b.call(N,r),N.dispatchEvent(y)}},[p,r,c]),e.jsx(Zn.input,{type:"radio","aria-hidden":!0,defaultChecked:r,...d,tabIndex:-1,ref:f,style:{...d.style,...g,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});vN.displayName=OC;function NN(a){return a?"checked":"unchecked"}var LC=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],fd="RadioGroup",[UC]=td(fd,[Cj,fN]),bN=Cj(),yN=fN(),[$C,BC]=UC(fd),wN=m.forwardRef((a,n)=>{const{__scopeRadioGroup:r,name:c,defaultValue:d,value:u,required:h=!1,disabled:f=!1,orientation:p,dir:g,loop:N=!0,onValueChange:v,...w}=a,b=bN(r),y=Gj(g),[A,z]=sd({prop:u,defaultProp:d??null,onChange:v,caller:fd});return e.jsx($C,{scope:r,name:c,required:h,disabled:f,value:A,onValueChange:z,children:e.jsx(Sw,{asChild:!0,...b,orientation:p,dir:y,loop:N,children:e.jsx(Zn.div,{role:"radiogroup","aria-required":h,"aria-orientation":p,"data-disabled":f?"":void 0,dir:y,...w,ref:n})})})});wN.displayName=fd;var _N="RadioGroupItem",SN=m.forwardRef((a,n)=>{const{__scopeRadioGroup:r,disabled:c,...d}=a,u=BC(_N,r),h=u.disabled||c,f=bN(r),p=yN(r),g=m.useRef(null),N=ad(n,g),v=u.value===d.value,w=m.useRef(!1);return m.useEffect(()=>{const b=A=>{LC.includes(A.key)&&(w.current=!0)},y=()=>w.current=!1;return document.addEventListener("keydown",b),document.addEventListener("keyup",y),()=>{document.removeEventListener("keydown",b),document.removeEventListener("keyup",y)}},[]),e.jsx(kw,{asChild:!0,...f,focusable:!h,active:v,children:e.jsx(pN,{disabled:h,required:u.required,checked:v,...p,...d,name:u.name,ref:N,onCheck:()=>u.onValueChange(d.value),onKeyDown:gn(b=>{b.key==="Enter"&&b.preventDefault()}),onFocus:gn(d.onFocus,()=>{w.current&&g.current?.click()})})})});SN.displayName=_N;var PC="RadioGroupIndicator",kN=m.forwardRef((a,n)=>{const{__scopeRadioGroup:r,...c}=a,d=yN(r);return e.jsx(jN,{...d,...c,ref:n})});kN.displayName=PC;var CN=wN,TN=SN,IC=kN;const Sx=m.forwardRef(({className:a,...n},r)=>e.jsx(CN,{className:F("grid gap-2",a),...n,ref:r}));Sx.displayName=CN.displayName;const Xo=m.forwardRef(({className:a,...n},r)=>e.jsx(TN,{ref:r,className:F("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",a),...n,children:e.jsx(IC,{className:"flex items-center justify-center",children:e.jsx(Ho,{className:"h-2.5 w-2.5 fill-current text-current"})})}));Xo.displayName=TN.displayName;function FC({question:a,value:n,onChange:r,error:c,disabled:d=!1}){const[u,h]=m.useState(null),f=d||a.readOnly,p=()=>{switch(a.type){case"single":return e.jsx(Sx,{value:n||"",onValueChange:r,disabled:f,className:"space-y-2",children:a.options?.map(g=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xo,{value:g.value,id:`${a.id}-${g.id}`}),e.jsx(T,{htmlFor:`${a.id}-${g.id}`,className:"cursor-pointer font-normal",children:g.label})]},g.id))});case"multiple":{const g=n||[];return e.jsxs("div",{className:"space-y-2",children:[a.options?.map(N=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:`${a.id}-${N.id}`,checked:g.includes(N.value),disabled:f||a.maxSelections!==void 0&&g.length>=a.maxSelections&&!g.includes(N.value),onCheckedChange:v=>{r(v?[...g,N.value]:g.filter(w=>w!==N.value))}}),e.jsx(T,{htmlFor:`${a.id}-${N.id}`,className:"cursor-pointer font-normal",children:N.label})]},N.id)),a.maxSelections&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["最多选择 ",a.maxSelections," 项"]})]})}case"text":return e.jsx(le,{value:n||"",onChange:g=>r(g.target.value),placeholder:a.placeholder||"请输入...",disabled:f,readOnly:a.readOnly,maxLength:a.maxLength,className:F(a.readOnly&&"bg-muted cursor-not-allowed")});case"textarea":return e.jsxs("div",{className:"space-y-1",children:[e.jsx(ot,{value:n||"",onChange:g=>r(g.target.value),placeholder:a.placeholder||"请输入...",disabled:f,readOnly:a.readOnly,maxLength:a.maxLength,rows:4,className:F(a.readOnly&&"bg-muted cursor-not-allowed")}),a.maxLength&&e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[(n||"").length," / ",a.maxLength]})]});case"rating":{const g=n||0,N=u!==null?u:g;return e.jsxs("div",{className:"flex items-center gap-1",children:[[1,2,3,4,5].map(v=>e.jsx("button",{type:"button",disabled:f,className:F("p-1 transition-colors focus:outline-none focus:ring-2 focus:ring-ring rounded",f&&"cursor-not-allowed opacity-50"),onMouseEnter:()=>!f&&h(v),onMouseLeave:()=>h(null),onClick:()=>!f&&r(v),children:e.jsx(mn,{className:F("h-6 w-6 transition-colors",v<=N?"fill-yellow-400 text-yellow-400":"text-muted-foreground")})},v)),g>0&&e.jsxs("span",{className:"ml-2 text-sm text-muted-foreground",children:[g," / 5"]})]})}case"scale":{const g=a.min??1,N=a.max??10,v=a.step??1,w=n??g;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Qa,{value:[w],onValueChange:([b])=>r(b),min:g,max:N,step:v,disabled:f}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:a.minLabel||g}),e.jsx("span",{className:"font-medium text-foreground",children:w}),e.jsx("span",{children:a.maxLabel||N})]})]})}case"dropdown":return e.jsxs(Ie,{value:n||"",onValueChange:r,disabled:f,children:[e.jsx(Be,{children:e.jsx(Fe,{placeholder:a.placeholder||"请选择..."})}),e.jsx(Pe,{children:a.options?.map(g=>e.jsx(W,{value:g.value,children:g.label},g.id))})]});default:return e.jsx("div",{className:"text-muted-foreground",children:"不支持的问题类型"})}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-base font-medium",children:[a.title,a.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),a.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:a.description})]}),p(),c&&e.jsx("p",{className:"text-sm text-destructive",children:c})]})}const EN="https://maibot-plugin-stats.maibot-webui.workers.dev";function MN(){const a="maibot_user_id";let n=localStorage.getItem(a);if(!n){const r=Math.random().toString(36).substring(2,10),c=Date.now().toString(36),d=Math.random().toString(36).substring(2,10);n=`fp_${r}_${c}_${d}`,localStorage.setItem(a,n)}return n}async function HC(a,n,r,c){try{const d=c?.userId||MN(),u={surveyId:a,surveyVersion:n,userId:d,answers:r,submittedAt:new Date().toISOString(),allowMultiple:c?.allowMultiple,metadata:{userAgent:navigator.userAgent,language:navigator.language}},h=await fetch(`${EN}/survey/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)}),f=await h.json();return h.status===429?{success:!1,error:"提交过于频繁,请稍后再试"}:h.status===409?{success:!1,error:f.error||"你已经提交过这份问卷了"}:h.ok?{success:!0,submissionId:f.submissionId,message:f.message}:{success:!1,error:f.error||"提交失败"}}catch(d){return console.error("Error submitting survey:",d),{success:!1,error:"网络错误"}}}async function VC(a,n){try{const r=n||MN(),c=new URLSearchParams({user_id:r,survey_id:a}),d=await fetch(`${EN}/survey/check?${c}`);return d.ok?{success:!0,hasSubmitted:(await d.json()).hasSubmitted}:{success:!1,error:(await d.json()).error||"检查失败"}}catch(r){return console.error("Error checking submission:",r),{success:!1,error:"网络错误"}}}function AN({config:a,initialAnswers:n,onSubmitSuccess:r,onSubmitError:c,showProgress:d=!0,paginateQuestions:u=!1,className:h}){const f=m.useCallback(()=>!n||n.length===0?{}:n.reduce(($,ue)=>($[ue.questionId]=ue.value,$),{}),[n]),[p,g]=m.useState(()=>f()),[N,v]=m.useState({}),[w,b]=m.useState(0),[y,A]=m.useState(!1),[z,S]=m.useState(!1),[U,E]=m.useState(null),[C,D]=m.useState(null),[I,O]=m.useState(!1),[X,L]=m.useState(!0);m.useEffect(()=>{n&&n.length>0&&g($=>({...$,...f()}))},[n,f]),m.useEffect(()=>{(async()=>{if(!a.settings?.allowMultiple){const ue=await VC(a.id);ue.success&&ue.hasSubmitted&&O(!0)}L(!1)})()},[a.id,a.settings?.allowMultiple]);const oe=m.useCallback(()=>{const $=new Date;return!(a.settings?.startTime&&new Date(a.settings.startTime)>$||a.settings?.endTime&&new Date(a.settings.endTime)<$)},[a.settings?.startTime,a.settings?.endTime]),Ne=a.questions.filter($=>{const ue=p[$.id];return ue==null?!1:Array.isArray(ue)?ue.length>0:typeof ue=="string"?ue.trim()!=="":!0}).length,je=Ne/a.questions.length*100,de=m.useCallback(($,ue)=>{g(G=>({...G,[$]:ue})),v(G=>{const Se={...G};return delete Se[$],Se})},[]),he=m.useCallback(()=>{const $={};for(const ue of a.questions){if(ue.required){const G=p[ue.id];if(G==null){$[ue.id]="此题为必填项";continue}if(Array.isArray(G)&&G.length===0){$[ue.id]="请至少选择一项";continue}if(typeof G=="string"&&G.trim()===""){$[ue.id]="此题为必填项";continue}}ue.minLength&&typeof p[ue.id]=="string"&&p[ue.id].length{if(!he()){if(u){const $=a.questions.findIndex(ue=>N[ue.id]);$>=0&&b($)}return}A(!0),E(null);try{const $=a.questions.filter(G=>p[G.id]!==void 0).map(G=>({questionId:G.id,value:p[G.id]})),ue=await HC(a.id,a.version,$,{allowMultiple:a.settings?.allowMultiple});if(ue.success&&ue.submissionId)S(!0),D(ue.submissionId),r?.(ue.submissionId);else{const G=ue.error||"提交失败";E(G),c?.(G)}}catch($){const ue=$ instanceof Error?$.message:"提交失败";E(ue),c?.(ue)}finally{A(!1)}},[he,u,a,p,N,r,c]),R=m.useCallback($=>{$>=0&&$e.jsxs("div",{className:F("p-4 rounded-lg border bg-card",N[$.id]?"border-destructive bg-destructive/5":"border-border"),children:[u&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:["问题 ",w+1," / ",a.questions.length]}),!u&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:[ue+1,"."]}),e.jsx(FC,{question:$,value:p[$.id],onChange:G=>de($.id,G),error:N[$.id],disabled:y})]},$.id)),U&&e.jsxs(at,{variant:"destructive",children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsx(lt,{children:U})]}),e.jsx("div",{className:"flex justify-between items-center py-4",children:u?e.jsxs(e.Fragment,{children:[e.jsxs(_,{variant:"outline",onClick:()=>R(w-1),disabled:w===0||y,children:[e.jsx(Da,{className:"h-4 w-4 mr-1"}),"上一题"]}),w===a.questions.length-1?e.jsxs(_,{onClick:ge,disabled:y,children:[y&&e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]}):e.jsxs(_,{onClick:()=>R(w+1),disabled:y,children:["下一题",e.jsx(Wt,{className:"h-4 w-4 ml-1"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:Object.keys(N).length>0&&e.jsxs("span",{className:"text-destructive",children:["还有 ",Object.keys(N).length," 个必填项未完成"]})}),e.jsxs(_,{onClick:ge,disabled:y,size:"lg",children:[y&&e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]})]})})]})})]})}const GC={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:"感谢你的反馈!你的意见对我们非常重要,我们会认真考虑每一条建议。"}},qC={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 KC(){const[a,n]=m.useState(!0),r=m.useMemo(()=>JSON.parse(JSON.stringify(GC)),[]);m.useEffect(()=>{n(!1)},[]);const c=m.useMemo(()=>[{questionId:"webui_version",value:`v${od}`}],[]),d=m.useCallback(h=>{console.log("WebUI Survey submitted:",h)},[]),u=m.useCallback(h=>{console.error("WebUI Survey submission error:",h)},[]);return a?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):r?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(ov,{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(AN,{config:r,initialAnswers:c,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:d,onSubmitError:u})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(at,{variant:"destructive",className:"max-w-md",children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsx(lt,{children:"无法加载问卷配置"})]}),e.jsx(_,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}function QC(){const[a,n]=m.useState(null),[r,c]=m.useState(!0),[d,u]=m.useState("未知版本");m.useEffect(()=>{(async()=>{try{const v=await $1();u(v.version||"未知版本")}catch(v){console.error("Failed to get MaiBot version:",v),u("获取失败")}const N=JSON.parse(JSON.stringify(qC));n(N),c(!1)})()},[]);const h=m.useMemo(()=>[{questionId:"maibot_version",value:d}],[d]),f=m.useCallback(g=>{console.log("MaiBot Survey submitted:",g)},[]),p=m.useCallback(g=>{console.error("MaiBot Survey submission error:",g)},[]);return r?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):a?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(ov,{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(AN,{config:a,initialAnswers:h,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:f,onSubmitError:p})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(at,{variant:"destructive",className:"max-w-md",children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsx(lt,{children:"无法加载问卷配置"})]}),e.jsx(_,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}async function YC(a=2025){const n=await _e(`/api/webui/annual-report/full?year=${a}`);if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取年度报告失败")}return n.json()}function JC(a,n){if(a.match(/^[a-z]+:\/\//i))return a;if(a.match(/^\/\//))return window.location.protocol+a;if(a.match(/^[a-z]+:/i))return a;const r=document.implementation.createHTMLDocument(),c=r.createElement("base"),d=r.createElement("a");return r.head.appendChild(c),r.body.appendChild(d),n&&(c.href=n),d.href=a,d.href}const XC=(()=>{let a=0;const n=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(a+=1,`u${n()}${a}`)})();function pn(a){const n=[];for(let r=0,c=a.length;rCa||a.height>Ca)&&(a.width>Ca&&a.height>Ca?a.width>a.height?(a.height*=Ca/a.width,a.width=Ca):(a.width*=Ca/a.height,a.height=Ca):a.width>Ca?(a.height*=Ca/a.width,a.width=Ca):(a.width*=Ca/a.height,a.height=Ca))}function Wo(a){return new Promise((n,r)=>{const c=new Image;c.onload=()=>{c.decode().then(()=>{requestAnimationFrame(()=>n(c))})},c.onerror=r,c.crossOrigin="anonymous",c.decoding="async",c.src=a})}async function t3(a){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(a)).then(encodeURIComponent).then(n=>`data:image/svg+xml;charset=utf-8,${n}`)}async function a3(a,n,r){const c="http://www.w3.org/2000/svg",d=document.createElementNS(c,"svg"),u=document.createElementNS(c,"foreignObject");return d.setAttribute("width",`${n}`),d.setAttribute("height",`${r}`),d.setAttribute("viewBox",`0 0 ${n} ${r}`),u.setAttribute("width","100%"),u.setAttribute("height","100%"),u.setAttribute("x","0"),u.setAttribute("y","0"),u.setAttribute("externalResourcesRequired","true"),d.appendChild(u),u.appendChild(a),t3(d)}const ga=(a,n)=>{if(a instanceof n)return!0;const r=Object.getPrototypeOf(a);return r===null?!1:r.constructor.name===n.name||ga(r,n)};function l3(a){const n=a.getPropertyValue("content");return`${a.cssText} content: '${n.replace(/'|"/g,"")}';`}function n3(a,n){return zN(n).map(r=>{const c=a.getPropertyValue(r),d=a.getPropertyPriority(r);return`${r}: ${c}${d?" !important":""};`}).join(" ")}function r3(a,n,r,c){const d=`.${a}:${n}`,u=r.cssText?l3(r):n3(r,c);return document.createTextNode(`${d}{${u}}`)}function Wg(a,n,r,c){const d=window.getComputedStyle(a,r),u=d.getPropertyValue("content");if(u===""||u==="none")return;const h=XC();try{n.className=`${n.className} ${h}`}catch{return}const f=document.createElement("style");f.appendChild(r3(h,r,d,c)),n.appendChild(f)}function i3(a,n,r){Wg(a,n,":before",r),Wg(a,n,":after",r)}const ej="application/font-woff",sj="image/jpeg",c3={woff:ej,woff2:ej,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:sj,jpeg:sj,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function o3(a){const n=/\.([^./]*?)$/g.exec(a);return n?n[1]:""}function kx(a){const n=o3(a).toLowerCase();return c3[n]||""}function d3(a){return a.split(/,/)[1]}function Wm(a){return a.search(/^(data:)/)!==-1}function u3(a,n){return`data:${n};base64,${a}`}async function DN(a,n,r){const c=await fetch(a,n);if(c.status===404)throw new Error(`Resource "${c.url}" not found`);const d=await c.blob();return new Promise((u,h)=>{const f=new FileReader;f.onerror=h,f.onloadend=()=>{try{u(r({res:c,result:f.result}))}catch(p){h(p)}},f.readAsDataURL(d)})}const Vm={};function m3(a,n,r){let c=a.replace(/\?.*/,"");return r&&(c=a),/ttf|otf|eot|woff2?/i.test(c)&&(c=c.replace(/.*\//,"")),n?`[${n}]${c}`:c}async function Cx(a,n,r){const c=m3(a,n,r.includeQueryParams);if(Vm[c]!=null)return Vm[c];r.cacheBust&&(a+=(/\?/.test(a)?"&":"?")+new Date().getTime());let d;try{const u=await DN(a,r.fetchRequestInit,({res:h,result:f})=>(n||(n=h.headers.get("Content-Type")||""),d3(f)));d=u3(u,n)}catch(u){d=r.imagePlaceholder||"";let h=`Failed to fetch resource: ${a}`;u&&(h=typeof u=="string"?u:u.message),h&&console.warn(h)}return Vm[c]=d,d}async function x3(a){const n=a.toDataURL();return n==="data:,"?a.cloneNode(!1):Wo(n)}async function h3(a,n){if(a.currentSrc){const u=document.createElement("canvas"),h=u.getContext("2d");u.width=a.clientWidth,u.height=a.clientHeight,h?.drawImage(a,0,0,u.width,u.height);const f=u.toDataURL();return Wo(f)}const r=a.poster,c=kx(r),d=await Cx(r,c,n);return Wo(d)}async function f3(a,n){var r;try{if(!((r=a?.contentDocument)===null||r===void 0)&&r.body)return await pd(a.contentDocument.body,n,!0)}catch{}return a.cloneNode(!1)}async function p3(a,n){return ga(a,HTMLCanvasElement)?x3(a):ga(a,HTMLVideoElement)?h3(a,n):ga(a,HTMLIFrameElement)?f3(a,n):a.cloneNode(ON(a))}const g3=a=>a.tagName!=null&&a.tagName.toUpperCase()==="SLOT",ON=a=>a.tagName!=null&&a.tagName.toUpperCase()==="SVG";async function j3(a,n,r){var c,d;if(ON(n))return n;let u=[];return g3(a)&&a.assignedNodes?u=pn(a.assignedNodes()):ga(a,HTMLIFrameElement)&&(!((c=a.contentDocument)===null||c===void 0)&&c.body)?u=pn(a.contentDocument.body.childNodes):u=pn(((d=a.shadowRoot)!==null&&d!==void 0?d:a).childNodes),u.length===0||ga(a,HTMLVideoElement)||await u.reduce((h,f)=>h.then(()=>pd(f,r)).then(p=>{p&&n.appendChild(p)}),Promise.resolve()),n}function v3(a,n,r){const c=n.style;if(!c)return;const d=window.getComputedStyle(a);d.cssText?(c.cssText=d.cssText,c.transformOrigin=d.transformOrigin):zN(r).forEach(u=>{let h=d.getPropertyValue(u);u==="font-size"&&h.endsWith("px")&&(h=`${Math.floor(parseFloat(h.substring(0,h.length-2)))-.1}px`),ga(a,HTMLIFrameElement)&&u==="display"&&h==="inline"&&(h="block"),u==="d"&&n.getAttribute("d")&&(h=`path(${n.getAttribute("d")})`),c.setProperty(u,h,d.getPropertyPriority(u))})}function N3(a,n){ga(a,HTMLTextAreaElement)&&(n.innerHTML=a.value),ga(a,HTMLInputElement)&&n.setAttribute("value",a.value)}function b3(a,n){if(ga(a,HTMLSelectElement)){const c=Array.from(n.children).find(d=>a.value===d.getAttribute("value"));c&&c.setAttribute("selected","")}}function y3(a,n,r){return ga(n,Element)&&(v3(a,n,r),i3(a,n,r),N3(a,n),b3(a,n)),n}async function w3(a,n){const r=a.querySelectorAll?a.querySelectorAll("use"):[];if(r.length===0)return a;const c={};for(let u=0;up3(c,n)).then(c=>j3(a,c,n)).then(c=>y3(a,c,n)).then(c=>w3(c,n))}const LN=/url\((['"]?)([^'"]+?)\1\)/g,_3=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,S3=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function k3(a){const n=a.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${n})(['"]?\\))`,"g")}function C3(a){const n=[];return a.replace(LN,(r,c,d)=>(n.push(d),r)),n.filter(r=>!Wm(r))}async function T3(a,n,r,c,d){try{const u=r?JC(n,r):n,h=kx(n);let f;return d||(f=await Cx(u,h,c)),a.replace(k3(n),`$1${f}$3`)}catch{}return a}function E3(a,{preferredFontFormat:n}){return n?a.replace(S3,r=>{for(;;){const[c,,d]=_3.exec(r)||[];if(!d)return"";if(d===n)return`src: ${c};`}}):a}function UN(a){return a.search(LN)!==-1}async function $N(a,n,r){if(!UN(a))return a;const c=E3(a,r);return C3(c).reduce((u,h)=>u.then(f=>T3(f,h,n,r)),Promise.resolve(c))}async function Fr(a,n,r){var c;const d=(c=n.style)===null||c===void 0?void 0:c.getPropertyValue(a);if(d){const u=await $N(d,null,r);return n.style.setProperty(a,u,n.style.getPropertyPriority(a)),!0}return!1}async function M3(a,n){await Fr("background",a,n)||await Fr("background-image",a,n),await Fr("mask",a,n)||await Fr("-webkit-mask",a,n)||await Fr("mask-image",a,n)||await Fr("-webkit-mask-image",a,n)}async function A3(a,n){const r=ga(a,HTMLImageElement);if(!(r&&!Wm(a.src))&&!(ga(a,SVGImageElement)&&!Wm(a.href.baseVal)))return;const c=r?a.src:a.href.baseVal,d=await Cx(c,kx(c),n);await new Promise((u,h)=>{a.onload=u,a.onerror=n.onImageErrorHandler?(...p)=>{try{u(n.onImageErrorHandler(...p))}catch(g){h(g)}}:h;const f=a;f.decode&&(f.decode=u),f.loading==="lazy"&&(f.loading="eager"),r?(a.srcset="",a.src=d):a.href.baseVal=d})}async function z3(a,n){const c=pn(a.childNodes).map(d=>BN(d,n));await Promise.all(c).then(()=>a)}async function BN(a,n){ga(a,Element)&&(await M3(a,n),await A3(a,n),await z3(a,n))}function R3(a,n){const{style:r}=a;n.backgroundColor&&(r.backgroundColor=n.backgroundColor),n.width&&(r.width=`${n.width}px`),n.height&&(r.height=`${n.height}px`);const c=n.style;return c!=null&&Object.keys(c).forEach(d=>{r[d]=c[d]}),a}const tj={};async function aj(a){let n=tj[a];if(n!=null)return n;const c=await(await fetch(a)).text();return n={url:a,cssText:c},tj[a]=n,n}async function lj(a,n){let r=a.cssText;const c=/url\(["']?([^"')]+)["']?\)/g,u=(r.match(/url\([^)]+\)/g)||[]).map(async h=>{let f=h.replace(c,"$1");return f.startsWith("https://")||(f=new URL(f,a.url).href),DN(f,n.fetchRequestInit,({result:p})=>(r=r.replace(h,`url(${p})`),[h,p]))});return Promise.all(u).then(()=>r)}function nj(a){if(a==null)return[];const n=[],r=/(\/\*[\s\S]*?\*\/)/gi;let c=a.replace(r,"");const d=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const p=d.exec(c);if(p===null)break;n.push(p[0])}c=c.replace(d,"");const u=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,h="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",f=new RegExp(h,"gi");for(;;){let p=u.exec(c);if(p===null){if(p=f.exec(c),p===null)break;u.lastIndex=f.lastIndex}else f.lastIndex=u.lastIndex;n.push(p[0])}return n}async function D3(a,n){const r=[],c=[];return a.forEach(d=>{if("cssRules"in d)try{pn(d.cssRules||[]).forEach((u,h)=>{if(u.type===CSSRule.IMPORT_RULE){let f=h+1;const p=u.href,g=aj(p).then(N=>lj(N,n)).then(N=>nj(N).forEach(v=>{try{d.insertRule(v,v.startsWith("@import")?f+=1:d.cssRules.length)}catch(w){console.error("Error inserting rule from remote css",{rule:v,error:w})}})).catch(N=>{console.error("Error loading remote css",N.toString())});c.push(g)}})}catch(u){const h=a.find(f=>f.href==null)||document.styleSheets[0];d.href!=null&&c.push(aj(d.href).then(f=>lj(f,n)).then(f=>nj(f).forEach(p=>{h.insertRule(p,h.cssRules.length)})).catch(f=>{console.error("Error loading remote stylesheet",f)})),console.error("Error inlining remote css file",u)}}),Promise.all(c).then(()=>(a.forEach(d=>{if("cssRules"in d)try{pn(d.cssRules||[]).forEach(u=>{r.push(u)})}catch(u){console.error(`Error while reading CSS rules from ${d.href}`,u)}}),r))}function O3(a){return a.filter(n=>n.type===CSSRule.FONT_FACE_RULE).filter(n=>UN(n.style.getPropertyValue("src")))}async function L3(a,n){if(a.ownerDocument==null)throw new Error("Provided element is not within a Document");const r=pn(a.ownerDocument.styleSheets),c=await D3(r,n);return O3(c)}function PN(a){return a.trim().replace(/["']/g,"")}function U3(a){const n=new Set;function r(c){(c.style.fontFamily||getComputedStyle(c).fontFamily).split(",").forEach(u=>{n.add(PN(u))}),Array.from(c.children).forEach(u=>{u instanceof HTMLElement&&r(u)})}return r(a),n}async function $3(a,n){const r=await L3(a,n),c=U3(a);return(await Promise.all(r.filter(u=>c.has(PN(u.style.fontFamily))).map(u=>{const h=u.parentStyleSheet?u.parentStyleSheet.href:null;return $N(u.cssText,h,n)}))).join(` +`)}async function B3(a,n){const r=n.fontEmbedCSS!=null?n.fontEmbedCSS:n.skipFonts?null:await $3(a,n);if(r){const c=document.createElement("style"),d=document.createTextNode(r);c.appendChild(d),a.firstChild?a.insertBefore(c,a.firstChild):a.appendChild(c)}}async function P3(a,n={}){const{width:r,height:c}=RN(a,n),d=await pd(a,n,!0);return await B3(d,n),await BN(d,n),R3(d,n),await a3(d,r,c)}async function I3(a,n={}){const{width:r,height:c}=RN(a,n),d=await P3(a,n),u=await Wo(d),h=document.createElement("canvas"),f=h.getContext("2d"),p=n.pixelRatio||e3(),g=n.canvasWidth||r,N=n.canvasHeight||c;return h.width=g*p,h.height=N*p,n.skipAutoScale||s3(h),h.style.width=`${g}`,h.style.height=`${N}`,n.backgroundColor&&(f.fillStyle=n.backgroundColor,f.fillRect(0,0,h.width,h.height)),f.drawImage(u,0,0,h.width,h.height),h}async function F3(a,n={}){return(await I3(a,n)).toDataURL()}const Lo=["#0088FE","#00C49F","#FFBB28","#FF8042","#8884d8","#82ca9d"];function H3(a){return a>=8760?"相当于全年无休,7x24小时在线!":a>=5e3?"相当于一位全职员工的年工作时长":a>=2e3?"相当于看完了 1000 部电影":a>=1e3?"相当于环球飞行 80 次":a>=500?"相当于读完了 100 本书":a>=100?"相当于马拉松跑了 25 次":"虽然不多,但每一刻都很珍贵"}function V3(a){return a>=1e3?"夜深人静时的知心好友":a>=500?"午夜场的常客":a>=100?"偶尔熬夜的小伙伴":a>=50?"深夜有时也会陪你聊聊":"早睡早起,健康作息"}function G3(a){const n=a/1e6;return n>=100?"思考量堪比一座图书馆":n>=50?"相当于写了一部百科全书":n>=10?"脑细胞估计消耗了不少":n>=1?"也算是费了一番脑筋":"轻轻松松,游刃有余"}function q3(a){return a>=1e3?"这钱够吃一年的泡面了":a>=500?"相当于买了一台游戏机":a>=100?"够请大家喝几杯奶茶":a>=50?"一顿火锅的钱":a>=10?"几杯咖啡的价格":"省钱小能手"}function K3(a){return a>=80?"沉默是金,惜字如金":a>=60?"话不多但句句到位":a>=40?"该说的时候才开口":a>=20?"能聊的都聊了":"话痨本痨,有问必答"}function Q3(a){return a>=1e4?"眼睛都快看花了":a>=5e3?"堪比专业摄影师的阅片量":a>=1e3?"看图小达人":a>=500?"图片鉴赏家":a>=100?"偶尔欣赏一下美图":"图片?有空再看"}function Y3(a){return a>=500?"在不断的纠正中成长":a>=200?"学习永无止境":a>=100?"虚心接受,积极改正":a>=50?"偶尔也会犯错":a>=10?"表现还算不错":"完美表达,无需纠正"}function J3(a){return a>=1?"这次思考的价值堪比一顿大餐!":a>=.5?"为了这个问题,我可是认真思考了!":a>=.1?"下了点功夫,值得的!":a>=.01?"花了点小钱,但很值得":"小小思考,不足挂齿"}function X3(a,n){return a>=100?"这句话简直是万能钥匙!":a>=50?"百试不爽的经典回复":a>=20?`${n}的口头禅`:a>=10?"常用语录之一":"偶尔用用的小确幸"}function Z3(a,n){return a?n>=1e3?"深夜的守护者,黑暗中的光芒":n>=500?"月亮是我的好朋友":n>=100?"越夜越精神,夜晚才是主场":"偶尔熬夜,享受宁静时光":n<=10?"作息规律,健康生活的典范":n<=50?"早睡早起,偶尔也会熬个夜":"虽然是早起鸟,但也会守候深夜"}function W3(a){return a>=1e3?"忙到飞起,键盘都要冒烟了":a>=500?"这天简直是话痨附体":a>=200?"社交达人上线":a>=100?"比平时活跃不少":a>=50?"小忙一下":"还算轻松的一天"}function e5(){const[a]=m.useState(2025),[n,r]=m.useState(null),[c,d]=m.useState(!0),[u,h]=m.useState(!1),[f,p]=m.useState(null),g=m.useRef(null),{toast:N}=Ys(),v=m.useCallback(async()=>{try{d(!0),p(null);const b=await YC(a);r(b)}catch(b){p(b instanceof Error?b:new Error("获取年度报告失败"))}finally{d(!1)}},[a]),w=m.useCallback(async()=>{if(!(!g.current||!n)){h(!0),N({title:"正在生成图片",description:"请稍候..."});try{const b=g.current,y=getComputedStyle(document.documentElement),A=y.getPropertyValue("--background").trim()?`hsl(${y.getPropertyValue("--background").trim()})`:document.documentElement.classList.contains("dark")?"#0a0a0a":"#ffffff",z=b.style.width,S=b.style.maxWidth;b.style.width="1024px",b.style.maxWidth="1024px";const U=await F3(b,{quality:1,pixelRatio:2,backgroundColor:A,cacheBust:!0,filter:C=>!(C instanceof HTMLElement&&C.hasAttribute("data-export-btn"))});b.style.width=z,b.style.maxWidth=S;const E=document.createElement("a");E.download=`${n.bot_name}_${n.year}_年度总结.png`,E.href=U,E.click(),N({title:"导出成功",description:"年度报告已保存为图片"})}catch(b){console.error("导出图片失败:",b),N({title:"导出失败",description:"请重试",variant:"destructive"})}finally{h(!1)}}},[n,N]);return m.useEffect(()=>{v()},[v]),c?e.jsx(s5,{}):f?e.jsxs("div",{className:"flex h-screen items-center justify-center text-red-500",children:["获取年度报告失败: ",f.message]}):n?e.jsx(Je,{className:"h-[calc(100vh-4rem)]",children:e.jsx("div",{className:"min-h-screen bg-gradient-to-b from-background to-muted/50 p-4 md:p-8 print:p-0",ref:g,children:e.jsxs("div",{className:"mx-auto max-w-5xl space-y-8 print:space-y-4",children:[e.jsxs("header",{className:"relative overflow-hidden rounded-3xl bg-primary p-8 text-primary-foreground shadow-2xl print:rounded-none print:shadow-none",children:[e.jsx("div",{className:"absolute right-4 top-4 z-20 print:hidden","data-export-btn":!0,children:e.jsx(_,{variant:"secondary",size:"sm",onClick:w,disabled:u,className:"gap-2 bg-white/20 hover:bg-white/30 text-white border-white/30",children:u?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-4 w-4 animate-spin"}),"导出中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Xt,{className:"h-4 w-4"}),"保存图片"]})})}),e.jsxs("div",{className:"relative z-10 flex flex-col items-center text-center",children:[e.jsx(Vn,{className:"mb-4 h-16 w-16 animate-bounce"}),e.jsxs("h1",{className:"text-4xl font-bold tracking-tighter sm:text-6xl",children:[n.bot_name," ",n.year," 年度总结"]}),e.jsx("p",{className:"mt-4 max-w-2xl text-lg opacity-90",children:"连接与成长 · Connection & Growth"}),e.jsxs("div",{className:"mt-6 flex items-center gap-2 text-sm opacity-75",children:[e.jsx(Go,{className:"h-4 w-4"}),e.jsxs("span",{children:["生成时间: ",n.generated_at]})]})]}),e.jsx("div",{className:"absolute -right-20 -top-20 h-64 w-64 rounded-full bg-white/10 blur-3xl"}),e.jsx("div",{className:"absolute -bottom-20 -left-20 h-64 w-64 rounded-full bg-white/10 blur-3xl"})]}),e.jsxs("section",{className:"space-y-4 break-inside-avoid",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xl font-bold text-primary",children:[e.jsx(na,{className:"h-8 w-8"}),e.jsx("h2",{children:"时光足迹"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsx(Ta,{title:"年度在线时长",value:`${n.time_footprint.total_online_hours} 小时`,description:H3(n.time_footprint.total_online_hours),icon:e.jsx(na,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"最忙碌的一天",value:n.time_footprint.busiest_day||"N/A",description:W3(n.time_footprint.busiest_day_count),icon:e.jsx(Go,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"深夜互动 (0-4点)",value:`${n.time_footprint.midnight_chat_count} 次`,description:V3(n.time_footprint.midnight_chat_count),icon:e.jsx(ec,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"作息属性",value:n.time_footprint.is_night_owl?"夜猫子":"早起鸟",description:Z3(n.time_footprint.is_night_owl,n.time_footprint.midnight_chat_count),icon:n.time_footprint.is_night_owl?e.jsx(ec,{className:"h-4 w-4"}):e.jsx(ax,{className:"h-4 w-4"})})]}),e.jsxs(Ce,{className:"overflow-hidden",children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"24小时活跃时钟"}),e.jsxs(os,{children:[n.bot_name,"在一天中各个时段的活跃程度"]})]}),e.jsx(Me,{className:"h-[300px]",children:e.jsx(Mj,{width:"100%",height:"100%",children:e.jsxs(Uo,{data:n.time_footprint.hourly_distribution.map((b,y)=>({hour:`${y}点`,count:b})),children:[e.jsx(Qi,{strokeDasharray:"3 3",vertical:!1}),e.jsx(Yi,{dataKey:"hour"}),e.jsx(Hr,{}),e.jsx(Aj,{contentStyle:{borderRadius:"8px",border:"none",boxShadow:"0 4px 12px rgba(0,0,0,0.1)"},cursor:{fill:"transparent"}}),e.jsx(Ji,{dataKey:"count",fill:"hsl(var(--primary))",radius:[4,4,0,0]})]})})})]}),n.time_footprint.first_message_time&&e.jsx(Ce,{className:"bg-muted/30 border-dashed",children:e.jsxs(Me,{className:"flex flex-col items-center justify-center p-6 text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-2",children:"2025年的故事开始于"}),e.jsx("div",{className:"text-xl font-bold text-primary mb-1",children:n.time_footprint.first_message_time}),e.jsxs("p",{className:"text-lg",children:[e.jsx("span",{className:"font-semibold text-foreground",children:n.time_footprint.first_message_user})," 说:",e.jsxs("span",{className:"italic text-muted-foreground",children:['"',n.time_footprint.first_message_content,'"']})]})]})})]}),e.jsxs("section",{className:"space-y-4 break-inside-avoid",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xl font-bold text-primary",children:[e.jsx(ic,{className:"h-8 w-8"}),e.jsx("h2",{children:"社交网络"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(Ta,{title:"社交圈子",value:`${n.social_network.total_groups} 个群组`,description:`${n.bot_name}加入的群组总数`,icon:e.jsx(ic,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"被呼叫次数",value:`${n.social_network.at_count+n.social_network.mentioned_count} 次`,description:"我的名字被大家频繁提起",icon:e.jsx(q_,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"最长情陪伴",value:n.social_network.longest_companion_user||"N/A",description:`始终都在,已陪伴 ${n.social_network.longest_companion_days} 天`,icon:e.jsx(Xr,{className:"h-4 w-4 text-red-500"})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{children:"话痨群组 TOP5"})}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-3",children:n.social_network.top_groups.length>0?n.social_network.top_groups.map((b,y)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ke,{variant:y===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:y+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:b.group_name}),b.is_webui&&e.jsx(ke,{variant:"outline",className:"text-xs px-1.5 py-0 h-5 bg-blue-50 text-blue-600 border-blue-200",children:"WebUI"})]}),e.jsxs("span",{className:"text-muted-foreground text-sm shrink-0",children:[b.message_count," 条消息"]})]},b.group_id)):e.jsx("div",{className:"text-center text-muted-foreground py-4",children:"暂无数据"})})})]}),e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{children:"年度最佳损友 TOP5"})}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-3",children:n.social_network.top_users.length>0?n.social_network.top_users.map((b,y)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ke,{variant:y===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:y+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:b.user_nickname}),b.is_webui&&e.jsx(ke,{variant:"outline",className:"text-xs px-1.5 py-0 h-5 bg-blue-50 text-blue-600 border-blue-200",children:"WebUI"})]}),e.jsxs("span",{className:"text-muted-foreground text-sm shrink-0",children:[b.message_count," 次互动"]})]},b.user_id)):e.jsx("div",{className:"text-center text-muted-foreground py-4",children:"暂无数据"})})})]})]})]}),e.jsxs("section",{className:"space-y-4 break-inside-avoid",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xl font-bold text-primary",children:[e.jsx(cx,{className:"h-8 w-8"}),e.jsx("h2",{children:"最强大脑"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsx(Ta,{title:"年度 Token 消耗",value:(n.brain_power.total_tokens/1e6).toFixed(2)+" M",description:G3(n.brain_power.total_tokens),icon:e.jsx(el,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"年度总花费",value:`$${n.brain_power.total_cost.toFixed(2)}`,description:q3(n.brain_power.total_cost),icon:e.jsx("span",{className:"font-bold",children:"$"})}),e.jsx(Ta,{title:"高冷指数",value:`${n.brain_power.silence_rate}%`,description:K3(n.brain_power.silence_rate),icon:e.jsx(ec,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"最高兴趣值",value:n.brain_power.max_interest_value??"N/A",description:n.brain_power.max_interest_time?`出现在 ${n.brain_power.max_interest_time}`:"暂无数据",icon:e.jsx(Xr,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{children:"模型偏好分布"})}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-3",children:n.brain_power.model_distribution.slice(0,5).map((b,y)=>{const A=n.brain_power.model_distribution[0]?.count||1,z=Math.round(b.count/A*100);return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"font-medium truncate max-w-[200px]",children:b.model}),e.jsxs("span",{className:"text-muted-foreground",children:[b.count.toLocaleString()," 次"]})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-secondary",children:e.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${z}%`,backgroundColor:Lo[y%Lo.length]}})})]},b.model)})})})]}),n.brain_power.top_reply_models&&n.brain_power.top_reply_models.length>0&&e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"最喜欢的回复模型 TOP5"}),e.jsxs(os,{children:[n.bot_name,"用来回复消息的模型偏好"]})]}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-3",children:n.brain_power.top_reply_models.map((b,y)=>{const A=n.brain_power.top_reply_models[0]?.count||1,z=Math.round(b.count/A*100);return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"font-medium truncate max-w-[200px]",children:b.model}),e.jsxs("span",{className:"text-muted-foreground",children:[b.count.toLocaleString()," 次"]})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-secondary",children:e.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${z}%`,backgroundColor:Lo[y%Lo.length]}})})]},b.model)})})})]}),n.brain_power.top_token_consumers&&n.brain_power.top_token_consumers.length>0&&e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"烧钱大户 TOP3"}),e.jsx(os,{children:"谁消耗了最多的 API 额度"})]}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-6",children:n.brain_power.top_token_consumers.map(b=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm font-medium",children:[e.jsxs("span",{children:["用户 ",b.user_id]}),e.jsxs("span",{children:["$",b.cost.toFixed(2)]})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-secondary",children:e.jsx("div",{className:"h-full bg-primary transition-all duration-500",style:{width:`${b.cost/(n.brain_power.top_token_consumers[0]?.cost||1)*100}%`}})})]},b.user_id))})})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{className:"bg-gradient-to-br from-amber-50 to-orange-50 dark:from-amber-950/20 dark:to-orange-950/20",children:[e.jsx(De,{children:e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"💰"}),"最昂贵的一次思考"]})}),e.jsxs(Me,{className:"text-center",children:[e.jsxs("div",{className:"text-4xl font-bold text-amber-600 dark:text-amber-400",children:["$",n.brain_power.most_expensive_cost.toFixed(4)]}),n.brain_power.most_expensive_time&&e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["发生在 ",n.brain_power.most_expensive_time]}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:J3(n.brain_power.most_expensive_cost)})]})]}),e.jsxs(Ce,{className:"bg-gradient-to-br from-indigo-50 to-blue-50 dark:from-indigo-950/20 dark:to-blue-950/20",children:[e.jsx(De,{children:e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"🧠"}),"思考深度"]})}),e.jsxs(Me,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-center",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-indigo-600 dark:text-indigo-400",children:n.brain_power.avg_reasoning_length?.toFixed(0)||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"平均思考字数"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-blue-600 dark:text-blue-400",children:n.brain_power.max_reasoning_length?.toLocaleString()||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"最长思考字数"})]})]}),n.brain_power.max_reasoning_time&&e.jsxs("p",{className:"mt-4 text-center text-xs text-muted-foreground",children:["最深沉的思考发生在 ",n.brain_power.max_reasoning_time]})]})]})]})]}),e.jsxs("section",{className:"space-y-4 break-inside-avoid",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xl font-bold text-primary",children:[e.jsx(ld,{className:"h-8 w-8"}),e.jsx("h2",{children:"个性与表达"})]}),(n.expression_vibe.late_night_reply||n.expression_vibe.favorite_reply)&&e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[n.expression_vibe.late_night_reply&&e.jsxs(Ce,{className:"bg-gradient-to-br from-indigo-50 to-violet-50 dark:from-indigo-950/20 dark:to-violet-950/20",children:[e.jsxs(De,{children:[e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"🌙"}),"深夜还在回复"]}),e.jsxs(os,{children:["凌晨 ",n.expression_vibe.late_night_reply.time,",",n.bot_name,"还在回复..."]})]}),e.jsxs(Me,{className:"text-center",children:[e.jsxs("p",{className:"text-lg italic text-muted-foreground",children:['"',n.expression_vibe.late_night_reply.content,'"']}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:"是有什么心事吗?"})]})]}),n.expression_vibe.favorite_reply&&e.jsxs(Ce,{className:"bg-gradient-to-br from-rose-50 to-pink-50 dark:from-rose-950/20 dark:to-pink-950/20",children:[e.jsxs(De,{children:[e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"💬"}),"最喜欢的回复"]}),e.jsxs(os,{children:["使用了 ",n.expression_vibe.favorite_reply.count," 次"]})]}),e.jsxs(Me,{className:"text-center",children:[e.jsxs("p",{className:"text-lg font-medium text-primary",children:['"',n.expression_vibe.favorite_reply.content,'"']}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:X3(n.expression_vibe.favorite_reply.count,n.bot_name)})]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{className:"bg-gradient-to-br from-pink-50 to-purple-50 dark:from-pink-950/20 dark:to-purple-950/20",children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"使用最多的表情包 TOP3"}),e.jsx(os,{children:"年度最爱的表情包们"})]}),e.jsx(Me,{children:n.expression_vibe.top_emojis&&n.expression_vibe.top_emojis.length>0?e.jsx("div",{className:"flex justify-center gap-4",children:n.expression_vibe.top_emojis.slice(0,3).map((b,y)=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:`/api/webui/emoji/${b.id}/thumbnail?original=true`,alt:`TOP ${y+1}`,className:"h-24 w-24 rounded-lg object-cover shadow-md transition-transform hover:scale-105"}),e.jsx(ke,{className:F("absolute -top-2 -right-2",y===0?"bg-yellow-500":y===1?"bg-gray-400":"bg-amber-700"),children:y+1})]}),e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:[b.usage_count," 次"]})]},b.id))}):e.jsx("div",{className:"flex h-32 items-center justify-center text-muted-foreground",children:"暂无数据"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"印象最深刻的表达风格"}),e.jsxs(os,{children:[n.bot_name,"最常使用的表达方式"]})]}),e.jsx(Me,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:n.expression_vibe.top_expressions.map((b,y)=>e.jsxs(ke,{variant:"outline",className:F("px-3 py-1 text-sm",y===0&&"border-primary bg-primary/10 text-primary text-base px-4 py-2"),children:[b.style," (",b.count,")"]},b.style))})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ta,{title:"图片鉴赏",value:`${n.expression_vibe.image_processed_count} 张`,description:Q3(n.expression_vibe.image_processed_count),icon:e.jsx(ix,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"成长的足迹",value:`${n.expression_vibe.rejected_expression_count} 次`,description:Y3(n.expression_vibe.rejected_expression_count),icon:e.jsx(el,{className:"h-4 w-4"})})]})]})]}),n.expression_vibe.action_types.length>0&&e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"⚡"}),"行动派"]}),e.jsx(os,{children:"除了聊天,我还帮大家做了这些事"})]}),e.jsx(Me,{children:e.jsx("div",{className:"flex flex-wrap gap-3",children:n.expression_vibe.action_types.map(b=>e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-primary/10 px-4 py-2",children:[e.jsx("span",{className:"font-medium text-primary",children:b.action}),e.jsxs(ke,{variant:"secondary",children:[b.count," 次"]})]},b.action))})})]})]}),e.jsxs("section",{className:"space-y-4 break-inside-avoid",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xl font-bold text-primary",children:[e.jsx(K_,{className:"h-8 w-8"}),e.jsx("h2",{children:"趣味成就"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs(Ce,{className:"col-span-1 md:col-span-2",children:[e.jsxs(De,{children:[e.jsx(Oe,{children:'新学到的"黑话"'}),e.jsxs(os,{children:["今年我学会了 ",n.achievements.new_jargon_count," 个新词"]})]}),e.jsx(Me,{children:e.jsx("div",{className:"flex flex-wrap gap-3",children:n.achievements.sample_jargons.map(b=>e.jsxs("div",{className:"group relative rounded-lg border bg-card p-3 shadow-sm transition-all hover:shadow-md",children:[e.jsx("div",{className:"font-bold text-primary",children:b.content}),e.jsx("div",{className:"text-xs text-muted-foreground mt-1 line-clamp-2 max-w-[200px]",children:b.meaning||"暂无解释"})]},b.content))})})]}),e.jsx(Ce,{className:"flex flex-col justify-center items-center bg-primary text-primary-foreground",children:e.jsxs(Me,{className:"flex flex-col items-center justify-center p-6 text-center",children:[e.jsx(Ra,{className:"h-12 w-12 mb-4 opacity-80"}),e.jsx("div",{className:"text-4xl font-bold mb-2",children:n.achievements.total_messages.toLocaleString()}),e.jsx("div",{className:"text-sm opacity-80",children:"年度总消息数"}),e.jsxs("div",{className:"mt-4 text-xs opacity-60",children:["其中回复了 ",n.achievements.total_replies.toLocaleString()," 次"]})]})})]})]}),e.jsxs("footer",{className:"mt-12 text-center text-muted-foreground",children:[e.jsx("p",{children:"MaiBot 2025 Annual Report"}),e.jsx("p",{className:"text-sm",children:"Generated with ❤️ by MaiBot Team"})]})]})})}):null}function Ta({title:a,value:n,description:r,icon:c}){return e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:a}),e.jsx("div",{className:"text-muted-foreground",children:c})]}),e.jsxs(Me,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]})]})}function s5(){return e.jsxs("div",{className:"container mx-auto space-y-8 p-8",children:[e.jsx(vs,{className:"h-64 w-full rounded-3xl"}),e.jsx("div",{className:"grid gap-4 md:grid-cols-4",children:[...Array(4)].map((a,n)=>e.jsx(vs,{className:"h-32 w-full"},n))}),e.jsx(vs,{className:"h-96 w-full"})]})}var gd="DropdownMenu",[t5]=td(gd,[Tj]),oa=Tj(),[a5,IN]=t5(gd),FN=a=>{const{__scopeDropdownMenu:n,children:r,dir:c,open:d,defaultOpen:u,onOpenChange:h,modal:f=!0}=a,p=oa(n),g=m.useRef(null),[N,v]=sd({prop:d,defaultProp:u??!1,onChange:h,caller:gd});return e.jsx(a5,{scope:n,triggerId:qm(),triggerRef:g,contentId:qm(),open:N,onOpenChange:v,onOpenToggle:m.useCallback(()=>v(w=>!w),[v]),modal:f,children:e.jsx(Uw,{...p,open:N,onOpenChange:v,dir:c,modal:f,children:r})})};FN.displayName=gd;var HN="DropdownMenuTrigger",VN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,disabled:c=!1,...d}=a,u=IN(HN,r),h=oa(r);return e.jsx($w,{asChild:!0,...h,children:e.jsx(Zn.button,{type:"button",id:u.triggerId,"aria-haspopup":"menu","aria-expanded":u.open,"aria-controls":u.open?u.contentId:void 0,"data-state":u.open?"open":"closed","data-disabled":c?"":void 0,disabled:c,...d,ref:m_(n,u.triggerRef),onPointerDown:gn(a.onPointerDown,f=>{!c&&f.button===0&&f.ctrlKey===!1&&(u.onOpenToggle(),u.open||f.preventDefault())}),onKeyDown:gn(a.onKeyDown,f=>{c||(["Enter"," "].includes(f.key)&&u.onOpenToggle(),f.key==="ArrowDown"&&u.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(f.key)&&f.preventDefault())})})})});VN.displayName=HN;var l5="DropdownMenuPortal",GN=a=>{const{__scopeDropdownMenu:n,...r}=a,c=oa(n);return e.jsx(Ew,{...c,...r})};GN.displayName=l5;var qN="DropdownMenuContent",KN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=IN(qN,r),u=oa(r),h=m.useRef(!1);return e.jsx(Mw,{id:d.contentId,"aria-labelledby":d.triggerId,...u,...c,ref:n,onCloseAutoFocus:gn(a.onCloseAutoFocus,f=>{h.current||d.triggerRef.current?.focus(),h.current=!1,f.preventDefault()}),onInteractOutside:gn(a.onInteractOutside,f=>{const p=f.detail.originalEvent,g=p.button===0&&p.ctrlKey===!0,N=p.button===2||g;(!d.modal||N)&&(h.current=!0)}),style:{...a.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});KN.displayName=qN;var n5="DropdownMenuGroup",r5=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Bw,{...d,...c,ref:n})});r5.displayName=n5;var i5="DropdownMenuLabel",QN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Ow,{...d,...c,ref:n})});QN.displayName=i5;var c5="DropdownMenuItem",YN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Aw,{...d,...c,ref:n})});YN.displayName=c5;var o5="DropdownMenuCheckboxItem",JN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(zw,{...d,...c,ref:n})});JN.displayName=o5;var d5="DropdownMenuRadioGroup",u5=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Pw,{...d,...c,ref:n})});u5.displayName=d5;var m5="DropdownMenuRadioItem",XN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Dw,{...d,...c,ref:n})});XN.displayName=m5;var x5="DropdownMenuItemIndicator",ZN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Rw,{...d,...c,ref:n})});ZN.displayName=x5;var h5="DropdownMenuSeparator",WN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Lw,{...d,...c,ref:n})});WN.displayName=h5;var f5="DropdownMenuArrow",p5=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Iw,{...d,...c,ref:n})});p5.displayName=f5;var g5="DropdownMenuSubTrigger",eb=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Cw,{...d,...c,ref:n})});eb.displayName=g5;var j5="DropdownMenuSubContent",sb=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Tw,{...d,...c,ref:n,style:{...a.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});sb.displayName=j5;var v5=FN,N5=VN,b5=GN,tb=KN,ab=QN,lb=YN,nb=JN,rb=XN,ib=ZN,cb=WN,ob=eb,db=sb;const y5=v5,w5=N5,_5=m.forwardRef(({className:a,inset:n,children:r,...c},d)=>e.jsxs(ob,{ref:d,className:F("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",n&&"pl-8",a),...c,children:[r,e.jsx(Wt,{className:"ml-auto h-4 w-4"})]}));_5.displayName=ob.displayName;const S5=m.forwardRef(({className:a,...n},r)=>e.jsx(db,{ref:r,className:F("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...n}));S5.displayName=db.displayName;const ub=m.forwardRef(({className:a,sideOffset:n=4,...r},c)=>e.jsx(b5,{children:e.jsx(tb,{ref:c,sideOffset:n,className:F("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...r})}));ub.displayName=tb.displayName;const mb=m.forwardRef(({className:a,inset:n,...r},c)=>e.jsx(lb,{ref:c,className:F("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n&&"pl-8",a),...r}));mb.displayName=lb.displayName;const k5=m.forwardRef(({className:a,children:n,checked:r,...c},d)=>e.jsxs(nb,{ref:d,className:F("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),checked:r,...c,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(ib,{children:e.jsx(Ct,{className:"h-4 w-4"})})}),n]}));k5.displayName=nb.displayName;const C5=m.forwardRef(({className:a,children:n,...r},c)=>e.jsxs(rb,{ref:c,className:F("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(ib,{children:e.jsx(Ho,{className:"h-2 w-2 fill-current"})})}),n]}));C5.displayName=rb.displayName;const T5=m.forwardRef(({className:a,inset:n,...r},c)=>e.jsx(ab,{ref:c,className:F("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",a),...r}));T5.displayName=ab.displayName;const E5=m.forwardRef(({className:a,...n},r)=>e.jsx(cb,{ref:r,className:F("-mx-1 my-1 h-px bg-muted",a),...n}));E5.displayName=cb.displayName;const Gm=[{value:"created_at",label:"最新发布",icon:na},{value:"downloads",label:"下载最多",icon:Xt},{value:"likes",label:"最受欢迎",icon:Xr}];function M5(){const a=ca(),[n,r]=m.useState([]),[c,d]=m.useState(!0),[u,h]=m.useState(""),[f,p]=m.useState("downloads"),[g,N]=m.useState(1),[v,w]=m.useState(1),[b,y]=m.useState(0),[A,z]=m.useState(new Set),[S,U]=m.useState(new Set),E=Yv(),C=m.useCallback(async()=>{d(!0);try{const L=await PS({status:"approved",page:g,page_size:12,search:u||void 0,sort_by:f,sort_order:"desc"});r(L.packs),w(L.total_pages),y(L.total);const oe=new Set;for(const Ne of L.packs)await Qv(Ne.id,E)&&oe.add(Ne.id);z(oe)}catch(L){console.error("加载 Pack 列表失败:",L),Qt({title:"加载 Pack 列表失败",variant:"destructive"})}finally{d(!1)}},[g,u,f,E]);m.useEffect(()=>{C()},[C]);const D=L=>{L.preventDefault(),N(1),C()},I=async L=>{if(!S.has(L)){U(oe=>new Set(oe).add(L));try{const oe=await Kv(L,E);z(Ne=>{const je=new Set(Ne);return oe.liked?je.add(L):je.delete(L),je}),r(Ne=>Ne.map(je=>je.id===L?{...je,likes:oe.likes}:je))}catch(oe){console.error("点赞失败:",oe),Qt({title:"点赞失败",variant:"destructive"})}finally{U(oe=>{const Ne=new Set(oe);return Ne.delete(L),Ne})}}},O=L=>{a({to:"/config/pack-market/$packId",params:{packId:L}})},X=Gm.find(L=>L.value===f)||Gm[0];return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsx("div",{className:"mb-4 sm:mb-6",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(ra,{className:"h-8 w-8",strokeWidth:2}),"配置模板市场"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"浏览和应用社区分享的模型配置模板,快速配置你的 MaiBot"})]}),e.jsxs(_,{variant:"outline",onClick:C,disabled:c,className:"gap-2",children:[e.jsx(dt,{className:`h-4 w-4 ${c?"animate-spin":""}`}),"刷新"]})]})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-4 flex-wrap",children:[e.jsx("form",{onSubmit:D,className:"flex-1 min-w-[200px] max-w-md",children:e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(le,{placeholder:"搜索模板名称、描述...",value:u,onChange:L=>h(L.target.value),className:"pl-10"})]})}),e.jsxs(y5,{children:[e.jsx(w5,{asChild:!0,children:e.jsxs(_,{variant:"outline",className:"min-w-[140px] gap-2",children:[e.jsx(Q_,{className:"w-4 h-4"}),X.label,e.jsx(za,{className:"w-4 h-4 ml-auto"})]})}),e.jsx(ub,{align:"end",children:Gm.map(L=>e.jsxs(mb,{onClick:()=>{p(L.value),N(1)},children:[e.jsx(L.icon,{className:"w-4 h-4 mr-2"}),L.label]},L.value))})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共找到 ",e.jsx("span",{className:"font-medium text-foreground",children:b})," 个模板"]}),c?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((L,oe)=>e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(vs,{className:"h-6 w-3/4"}),e.jsx(vs,{className:"h-4 w-full mt-2"})]}),e.jsx(Me,{children:e.jsx(vs,{className:"h-20 w-full"})}),e.jsx(id,{children:e.jsx(vs,{className:"h-9 w-full"})})]},oe))}):n.length===0?e.jsx(Ce,{className:"py-12",children:e.jsxs(Me,{className:"text-center text-muted-foreground",children:[e.jsx(ra,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{className:"text-lg font-medium",children:"暂无模板"}),e.jsx("p",{className:"mt-1",children:"还没有人分享配置模板,快来分享第一个吧!"})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:n.map(L=>e.jsx(A5,{pack:L,liked:A.has(L.id),liking:S.has(L.id),onLike:()=>I(L.id),onView:()=>O(L.id)},L.id))}),v>1&&e.jsx(ox,{children:e.jsxs(dx,{children:[e.jsx(qn,{children:e.jsx(Av,{onClick:()=>N(L=>Math.max(1,L-1)),className:g===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:v},(L,oe)=>oe+1).filter(L=>L===1||L===v||Math.abs(L-g)<=1).map((L,oe,Ne)=>{const je=oe>0&&L-Ne[oe-1]>1;return e.jsxs(qn,{children:[je&&e.jsx("span",{className:"px-2",children:"..."}),e.jsx(pc,{onClick:()=>N(L),isActive:L===g,className:"cursor-pointer",children:L})]},L)}),e.jsx(qn,{children:e.jsx(zv,{onClick:()=>N(L=>Math.min(v,L+1)),className:g===v?"pointer-events-none opacity-50":"cursor-pointer"})})]})})]})})]})}function A5({pack:a,liked:n,liking:r,onLike:c,onView:d}){const u=h=>new Date(h).toLocaleDateString("zh-CN",{year:"numeric",month:"short",day:"numeric"});return e.jsxs(Ce,{className:"flex flex-col hover:shadow-md transition-shadow",children:[e.jsxs(De,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx(Oe,{className:"text-lg line-clamp-1",children:a.name}),e.jsxs(ke,{variant:"secondary",className:"text-xs",children:["v",a.version]})]}),e.jsx(os,{className:"line-clamp-2 min-h-[40px]",children:a.description})]}),e.jsxs(Me,{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(jn,{className:"w-3.5 h-3.5"}),a.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(na,{className:"w-3.5 h-3.5"}),u(a.created_at)]})]}),e.jsxs("div",{className:"flex gap-4 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"提供商数量",children:[e.jsx(Ll,{className:"w-3.5 h-3.5"}),a.provider_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"模型数量",children:[e.jsx(Qn,{className:"w-3.5 h-3.5"}),a.model_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"任务配置数",children:[e.jsx(Yn,{className:"w-3.5 h-3.5"}),a.task_count]})]}),a.tags&&a.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(h=>e.jsxs(ke,{variant:"outline",className:"text-xs",children:[e.jsx(rd,{className:"w-2.5 h-2.5 mr-1"}),h]},h)),a.tags.length>3&&e.jsxs(ke,{variant:"outline",className:"text-xs",children:["+",a.tags.length-3]})]})]}),e.jsx(id,{className:"pt-3 border-t",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-3 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Xt,{className:"w-4 h-4"}),a.downloads]}),e.jsxs("button",{onClick:h=>{h.stopPropagation(),c()},disabled:r,className:`flex items-center gap-1 transition-colors ${n?"text-red-500":"hover:text-red-500"} ${r?"opacity-50":""}`,children:[e.jsx(Xr,{className:`w-4 h-4 ${n?"fill-current":""}`}),a.likes]})]}),e.jsx(_,{size:"sm",onClick:d,children:"查看详情"})]})})]})}var al="Accordion",z5=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[Tx,R5,D5]=x_(al),[jd]=td(al,[D5,Ej]),Ex=Ej(),xb=Rs.forwardRef((a,n)=>{const{type:r,...c}=a,d=c,u=c;return e.jsx(Tx.Provider,{scope:a.__scopeAccordion,children:r==="multiple"?e.jsx($5,{...u,ref:n}):e.jsx(U5,{...d,ref:n})})});xb.displayName=al;var[hb,O5]=jd(al),[fb,L5]=jd(al,{collapsible:!1}),U5=Rs.forwardRef((a,n)=>{const{value:r,defaultValue:c,onValueChange:d=()=>{},collapsible:u=!1,...h}=a,[f,p]=sd({prop:r,defaultProp:c??"",onChange:d,caller:al});return e.jsx(hb,{scope:a.__scopeAccordion,value:Rs.useMemo(()=>f?[f]:[],[f]),onItemOpen:p,onItemClose:Rs.useCallback(()=>u&&p(""),[u,p]),children:e.jsx(fb,{scope:a.__scopeAccordion,collapsible:u,children:e.jsx(pb,{...h,ref:n})})})}),$5=Rs.forwardRef((a,n)=>{const{value:r,defaultValue:c,onValueChange:d=()=>{},...u}=a,[h,f]=sd({prop:r,defaultProp:c??[],onChange:d,caller:al}),p=Rs.useCallback(N=>f((v=[])=>[...v,N]),[f]),g=Rs.useCallback(N=>f((v=[])=>v.filter(w=>w!==N)),[f]);return e.jsx(hb,{scope:a.__scopeAccordion,value:h,onItemOpen:p,onItemClose:g,children:e.jsx(fb,{scope:a.__scopeAccordion,collapsible:!0,children:e.jsx(pb,{...u,ref:n})})})}),[B5,vd]=jd(al),pb=Rs.forwardRef((a,n)=>{const{__scopeAccordion:r,disabled:c,dir:d,orientation:u="vertical",...h}=a,f=Rs.useRef(null),p=ad(f,n),g=R5(r),v=Gj(d)==="ltr",w=gn(a.onKeyDown,b=>{if(!z5.includes(b.key))return;const y=b.target,A=g().filter(X=>!X.ref.current?.disabled),z=A.findIndex(X=>X.ref.current===y),S=A.length;if(z===-1)return;b.preventDefault();let U=z;const E=0,C=S-1,D=()=>{U=z+1,U>C&&(U=E)},I=()=>{U=z-1,U{const{__scopeAccordion:r,value:c,...d}=a,u=vd(ed,r),h=O5(ed,r),f=Ex(r),p=qm(),g=c&&h.value.includes(c)||!1,N=u.disabled||a.disabled;return e.jsx(P5,{scope:r,open:g,disabled:N,triggerId:p,children:e.jsx(wj,{"data-orientation":u.orientation,"data-state":wb(g),...f,...d,ref:n,disabled:N,open:g,onOpenChange:v=>{v?h.onItemOpen(c):h.onItemClose(c)}})})});gb.displayName=ed;var jb="AccordionHeader",vb=Rs.forwardRef((a,n)=>{const{__scopeAccordion:r,...c}=a,d=vd(al,r),u=Mx(jb,r);return e.jsx(Zn.h3,{"data-orientation":d.orientation,"data-state":wb(u.open),"data-disabled":u.disabled?"":void 0,...c,ref:n})});vb.displayName=jb;var ex="AccordionTrigger",Nb=Rs.forwardRef((a,n)=>{const{__scopeAccordion:r,...c}=a,d=vd(al,r),u=Mx(ex,r),h=L5(ex,r),f=Ex(r);return e.jsx(Tx.ItemSlot,{scope:r,children:e.jsx(Fw,{"aria-disabled":u.open&&!h.collapsible||void 0,"data-orientation":d.orientation,id:u.triggerId,...f,...c,ref:n})})});Nb.displayName=ex;var bb="AccordionContent",yb=Rs.forwardRef((a,n)=>{const{__scopeAccordion:r,...c}=a,d=vd(al,r),u=Mx(bb,r),h=Ex(r);return e.jsx(Hw,{role:"region","aria-labelledby":u.triggerId,"data-orientation":d.orientation,...h,...c,ref:n,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...a.style}})});yb.displayName=bb;function wb(a){return a?"open":"closed"}var I5=xb,F5=gb,H5=vb,_b=Nb,Sb=yb;const V5=I5,kb=m.forwardRef(({className:a,...n},r)=>e.jsx(F5,{ref:r,className:F("border-b",a),...n}));kb.displayName="AccordionItem";const Cb=m.forwardRef(({className:a,children:n,...r},c)=>e.jsx(H5,{className:"flex",children:e.jsxs(_b,{ref:c,className:F("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",a),...r,children:[n,e.jsx(za,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));Cb.displayName=_b.displayName;const Tb=m.forwardRef(({className:a,children:n,...r},c)=>e.jsx(Sb,{ref:c,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...r,children:e.jsx("div",{className:F("pb-4 pt-0",a),children:n})}));Tb.displayName=Sb.displayName;const G5={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",lpmm_qa:"问答模型"};function q5(){const{packId:a}=Rb.useParams(),n=ca(),[r,c]=m.useState(null),[d,u]=m.useState(!0),[h,f]=m.useState(!1),[p,g]=m.useState(!1),[N,v]=m.useState(!1),[w,b]=m.useState(1),[y,A]=m.useState(null),[z,S]=m.useState(!1),[U,E]=m.useState(!1),[C,D]=m.useState({apply_providers:!0,apply_models:!0,apply_task_config:!0,task_mode:"append",selected_providers:void 0,selected_models:void 0,selected_tasks:void 0}),[I,O]=m.useState({}),[X,L]=m.useState({}),oe=Yv(),Ne=m.useCallback(async()=>{if(a){u(!0);try{const R=await IS(a);c(R);const Y=await Qv(a,oe);f(Y)}catch(R){console.error("加载 Pack 失败:",R),Qt({title:"加载模板失败",variant:"destructive"})}finally{u(!1)}}},[a,oe]);m.useEffect(()=>{Ne()},[Ne]);const je=async()=>{if(!(!a||p)){g(!0);try{const R=await Kv(a,oe);f(R.liked),r&&c({...r,likes:R.likes})}catch(R){console.error("点赞失败:",R),Qt({title:"点赞失败",variant:"destructive"})}finally{g(!1)}}},de=async()=>{if(r){v(!0),b(1),S(!0);try{const R=await VS(r);A(R);const Y={};for(const ue of R.existing_providers)Y[ue.pack_provider.name]=ue.local_providers[0].name;O(Y);const $={};for(const ue of R.new_providers)$[ue.name]="";L($)}catch(R){console.error("检测冲突失败:",R),Qt({title:"检测配置冲突失败",variant:"destructive"}),v(!1)}finally{S(!1)}}},he=async()=>{if(r){if(C.apply_providers&&y){for(const R of y.new_providers)if(!X[R.name]){Qt({title:`请填写提供商 "${R.name}" 的 API Key`,variant:"destructive"});return}}E(!0);try{await GS(r,C,I,X),await HS(r.id,oe),c({...r,downloads:r.downloads+1}),Qt({title:"配置模板应用成功!"}),v(!1)}catch(R){console.error("应用 Pack 失败:",R),Qt({title:R instanceof Error?R.message:"应用配置失败",variant:"destructive"})}finally{E(!1)}}},ge=R=>new Date(R).toLocaleDateString("zh-CN",{year:"numeric",month:"long",day:"numeric"});return d?e.jsx(Q5,{}):r?e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:()=>n({to:"/config/pack-market"}),className:"gap-2",children:[e.jsx(Ma,{className:"w-4 h-4"}),"返回市场"]}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-6",children:[e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ra,{className:"w-10 h-10 text-primary mt-1"}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[r.name,e.jsxs(ke,{variant:"secondary",children:["v",r.version]})]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:r.description})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(jn,{className:"w-4 h-4"}),r.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(na,{className:"w-4 h-4"}),ge(r.created_at)]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Xt,{className:"w-4 h-4"}),r.downloads," 次下载"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Xr,{className:`w-4 h-4 ${h?"fill-red-500 text-red-500":""}`}),r.likes," 赞"]})]}),r.tags&&r.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:r.tags.map(R=>e.jsxs(ke,{variant:"outline",children:[e.jsx(rd,{className:"w-3 h-3 mr-1"}),R]},R))})]}),e.jsxs("div",{className:"flex flex-col gap-2 min-w-[160px]",children:[e.jsxs(_,{size:"lg",onClick:de,children:[e.jsx(Xt,{className:"w-4 h-4 mr-2"}),"应用模板"]}),e.jsxs(_,{variant:"outline",onClick:je,disabled:p,className:h?"text-red-500 border-red-200":"",children:[e.jsx(Xr,{className:`w-4 h-4 mr-2 ${h?"fill-current":""}`}),h?"已点赞":"点赞"]})]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(Ce,{children:e.jsxs(Me,{className:"flex items-center gap-3 py-4",children:[e.jsx(Ll,{className:"w-8 h-8 text-blue-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r.providers.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"API 提供商"})]})]})}),e.jsx(Ce,{children:e.jsxs(Me,{className:"flex items-center gap-3 py-4",children:[e.jsx(Qn,{className:"w-8 h-8 text-green-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r.models.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"模型配置"})]})]})}),e.jsx(Ce,{children:e.jsxs(Me,{className:"flex items-center gap-3 py-4",children:[e.jsx(Yn,{className:"w-8 h-8 text-purple-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:Object.keys(r.task_config).length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"任务配置"})]})]})})]}),e.jsxs(ta,{defaultValue:"providers",className:"space-y-4",children:[e.jsxs(Zt,{className:"w-full sm:w-auto grid grid-cols-3 sm:flex",children:[e.jsxs(Xe,{value:"providers",className:"gap-1 sm:gap-2",children:[e.jsx(Ll,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"提供商"}),e.jsx("span",{className:"sm:hidden",children:"提供商"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r.providers.length,")"]})]}),e.jsxs(Xe,{value:"models",className:"gap-1 sm:gap-2",children:[e.jsx(Qn,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"模型"}),e.jsx("span",{className:"sm:hidden",children:"模型"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r.models.length,")"]})]}),e.jsxs(Xe,{value:"tasks",className:"gap-1 sm:gap-2",children:[e.jsx(Yn,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"任务配置"}),e.jsx("span",{className:"sm:hidden",children:"任务"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",Object.keys(r.task_config).length,")"]})]})]}),e.jsx(ws,{value:"providers",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"API 提供商"}),e.jsx(os,{children:"模板中包含的 API 提供商配置(不含 API Key)"})]}),e.jsx(Me,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{children:"名称"}),e.jsx(We,{children:"Base URL"}),e.jsx(We,{children:"类型"})]})}),e.jsx(Bl,{children:r.providers.map(R=>e.jsxs(ut,{children:[e.jsx(Ke,{className:"font-medium whitespace-nowrap",children:R.name}),e.jsx(Ke,{className:"text-muted-foreground font-mono text-sm max-w-[200px] truncate",children:R.base_url}),e.jsx(Ke,{children:e.jsx(ke,{variant:"outline",children:R.client_type})})]},R.name))})]})})})]})}),e.jsx(ws,{value:"models",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"模型配置"}),e.jsx(os,{children:"模板中包含的模型配置"})]}),e.jsx(Me,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{children:"模型名称"}),e.jsx(We,{children:"标识符"}),e.jsx(We,{children:"提供商"}),e.jsx(We,{className:"text-right",children:"价格 (入/出)"})]})}),e.jsx(Bl,{children:r.models.map(R=>e.jsxs(ut,{children:[e.jsx(Ke,{className:"font-medium whitespace-nowrap",children:R.name}),e.jsx(Ke,{className:"text-muted-foreground font-mono text-sm max-w-[150px] truncate",children:R.model_identifier}),e.jsx(Ke,{className:"whitespace-nowrap",children:R.api_provider}),e.jsxs(Ke,{className:"text-right text-muted-foreground whitespace-nowrap",children:["¥",R.price_in," / ¥",R.price_out]})]},R.name))})]})})})]})}),e.jsx(ws,{value:"tasks",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"任务配置"}),e.jsx(os,{children:"模板中各任务类型的模型分配"})]}),e.jsx(Me,{children:e.jsx(V5,{type:"multiple",className:"w-full",children:Object.entries(r.task_config).map(([R,Y])=>e.jsxs(kb,{value:R,children:[e.jsx(Cb,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vn,{className:"w-4 h-4"}),G5[R]||R,e.jsxs(ke,{variant:"secondary",className:"ml-2",children:[Y.model_list.length," 个模型"]})]})}),e.jsx(Tb,{children:e.jsxs("div",{className:"space-y-2 pl-6",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"分配的模型:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Y.model_list.map($=>e.jsx(ke,{variant:"outline",children:$},$))}),Y.temperature!==void 0&&e.jsxs("div",{className:"text-sm",children:["Temperature: ",e.jsx("span",{className:"font-mono",children:Y.temperature})]}),Y.max_tokens!==void 0&&e.jsxs("div",{className:"text-sm",children:["Max Tokens: ",e.jsx("span",{className:"font-mono",children:Y.max_tokens})]})]})})]},R))})})]})})]}),e.jsx(K5,{open:N,onOpenChange:v,pack:r,step:w,setStep:b,conflicts:y,detectingConflicts:z,applying:U,options:C,setOptions:D,_providerMapping:I,_setProviderMapping:O,newProviderApiKeys:X,setNewProviderApiKeys:L,onApply:he})]})})}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ra,{className:"w-16 h-16 mx-auto mb-4 opacity-50"}),e.jsx("h2",{className:"text-xl font-semibold",children:"模板不存在"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"该配置模板可能已被删除或尚未通过审核"}),e.jsxs(_,{className:"mt-4",onClick:()=>n({to:"/config/pack-market"}),children:[e.jsx(Ma,{className:"w-4 h-4 mr-2"}),"返回市场"]})]})}function K5({open:a,onOpenChange:n,pack:r,step:c,setStep:d,conflicts:u,detectingConflicts:h,applying:f,options:p,setOptions:g,_providerMapping:N,_setProviderMapping:v,newProviderApiKeys:w,setNewProviderApiKeys:b,onApply:y}){return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(ra,{className:"w-5 h-5"}),"应用配置模板"]}),e.jsxs(Ks,{children:["步骤 ",c," / ",3,":",c===1&&"选择要应用的内容",c===2&&"配置提供商映射",c===3&&"确认并应用"]})]}),h?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(zs,{className:"w-8 h-8 mx-auto animate-spin text-primary"}),e.jsx("p",{className:"mt-4 text-muted-foreground",children:"正在检测配置冲突..."})]}):e.jsxs(e.Fragment,{children:[c===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"apply_providers",checked:p.apply_providers,onCheckedChange:z=>g({...p,apply_providers:z})}),e.jsxs(T,{htmlFor:"apply_providers",className:"flex items-center gap-2",children:[e.jsx(Ll,{className:"w-4 h-4"}),"应用提供商配置 (",r.providers.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"apply_models",checked:p.apply_models,onCheckedChange:z=>g({...p,apply_models:z})}),e.jsxs(T,{htmlFor:"apply_models",className:"flex items-center gap-2",children:[e.jsx(Qn,{className:"w-4 h-4"}),"应用模型配置 (",r.models.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"apply_task_config",checked:p.apply_task_config,onCheckedChange:z=>g({...p,apply_task_config:z})}),e.jsxs(T,{htmlFor:"apply_task_config",className:"flex items-center gap-2",children:[e.jsx(Yn,{className:"w-4 h-4"}),"应用任务配置 (",Object.keys(r.task_config).length," 个)"]})]})]}),p.apply_task_config&&e.jsxs("div",{className:"pl-6 space-y-2 border-l-2 border-muted",children:[e.jsx(T,{className:"text-sm font-medium",children:"任务配置应用模式"}),e.jsxs(Sx,{value:p.task_mode,onValueChange:z=>g({...p,task_mode:z}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xo,{value:"append",id:"mode_append"}),e.jsx(T,{htmlFor:"mode_append",className:"font-normal",children:"追加模式 - 将模板中的模型添加到现有配置"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xo,{value:"replace",id:"mode_replace"}),e.jsx(T,{htmlFor:"mode_replace",className:"font-normal",children:"替换模式 - 用模板配置完全替换现有配置"})]})]})]})]}),c===2&&u&&e.jsxs("div",{className:"space-y-4",children:[p.apply_providers&&u.existing_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(Gn,{children:"发现已有的提供商"}),e.jsx(lt,{children:"以下提供商的 URL 与您本地配置中的提供商匹配,将自动使用本地提供商:"})]}),e.jsx("div",{className:"space-y-2",children:u.existing_providers.map(({pack_provider:z,local_providers:S})=>e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-lg",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500 flex-shrink-0"}),e.jsx("span",{className:"font-medium flex-shrink-0",children:z.name}),e.jsx(Wt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),S.length===1?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground",children:S[0].name}),e.jsx(ke,{variant:"outline",className:"ml-auto",children:"URL 匹配"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Ie,{value:N[z.name]||S[0].name,onValueChange:U=>v({...N,[z.name]:U}),children:[e.jsx(Be,{className:"w-[200px]",children:e.jsx(Fe,{})}),e.jsx(Pe,{children:S.map(U=>e.jsx(W,{value:U.name,children:U.name},U.name))})]}),e.jsxs(ke,{variant:"outline",className:"ml-auto",children:[S.length," 个匹配"]})]})]},z.name))})]}),p.apply_providers&&u.new_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(at,{variant:"destructive",children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsx(Gn,{children:"需要配置 API Key"}),e.jsx(lt,{children:"以下提供商在您的本地配置中不存在,需要填写 API Key:"})]}),e.jsx("div",{className:"space-y-4",children:u.new_providers.map(z=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(lx,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"font-medium",children:z.name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",z.base_url,")"]})]}),e.jsx(le,{type:"password",placeholder:`输入 ${z.name} 的 API Key`,value:w[z.name]||"",onChange:S=>b({...w,[z.name]:S.target.value})})]},z.name))})]}),(!p.apply_providers||u.existing_providers.length===0&&u.new_providers.length===0)&&e.jsxs(at,{children:[e.jsx(Ct,{className:"h-4 w-4"}),e.jsx(Gn,{children:"无需配置"}),e.jsx(lt,{children:"模板中没有提供商配置,或您选择不应用提供商。"})]})]}),c===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(Gn,{children:"确认应用"}),e.jsx(lt,{children:"请确认以下将要应用的内容:"})]}),e.jsxs("div",{className:"space-y-2",children:[p.apply_providers&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500"}),e.jsx(Ll,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",r.providers.length," 个提供商配置"]})]}),p.apply_models&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500"}),e.jsx(Qn,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",r.models.length," 个模型配置"]})]}),p.apply_task_config&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500"}),e.jsx(Yn,{className:"w-4 h-4"}),e.jsxs("span",{children:[p.task_mode==="append"?"追加":"替换"," ",Object.keys(r.task_config).length," 个任务配置"]})]})]}),u&&u.new_providers.length>0&&e.jsxs(at,{variant:"destructive",children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(lt,{children:["将添加 ",u.new_providers.length," 个新提供商,请确保已填写正确的 API Key。"]})]})]})]}),e.jsxs(st,{className:"flex justify-between",children:[e.jsx("div",{children:c>1&&!h&&e.jsx(_,{variant:"outline",onClick:()=>d(c-1),disabled:f,children:"上一步"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_,{variant:"outline",onClick:()=>n(!1),disabled:f,children:"取消"}),c<3?e.jsx(_,{onClick:()=>d(c+1),disabled:h,children:"下一步"}):e.jsxs(_,{onClick:y,disabled:f,children:[f&&e.jsx(zs,{className:"w-4 h-4 mr-2 animate-spin"}),"应用模板"]})]})]})]})})}function Q5(){return e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(vs,{className:"h-9 w-24"}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-6",children:[e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(vs,{className:"w-10 h-10"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(vs,{className:"h-8 w-2/3"}),e.jsx(vs,{className:"h-4 w-full"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsx(vs,{className:"h-4 w-24"}),e.jsx(vs,{className:"h-4 w-32"}),e.jsx(vs,{className:"h-4 w-28"}),e.jsx(vs,{className:"h-4 w-20"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(vs,{className:"h-6 w-20"}),e.jsx(vs,{className:"h-6 w-24"}),e.jsx(vs,{className:"h-6 w-16"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 min-w-[160px]",children:[e.jsx(vs,{className:"h-10 w-full"}),e.jsx(vs,{className:"h-10 w-full"})]})]}),e.jsx(vs,{className:"h-px w-full"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(vs,{className:"h-24"}),e.jsx(vs,{className:"h-24"}),e.jsx(vs,{className:"h-24"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(vs,{className:"h-10 w-32"}),e.jsx(vs,{className:"h-10 w-32"}),e.jsx(vs,{className:"h-10 w-32"})]}),e.jsx(vs,{className:"h-96 w-full"})]})]})})})}function Y5(){const a=ca(),[n,r]=m.useState(!0);return m.useEffect(()=>{let c=!1;return(async()=>{try{const u=await cc();!c&&!u&&a({to:"/auth"})}catch{c||a({to:"/auth"})}finally{c||r(!1)}})(),()=>{c=!0}},[a]),{checking:n}}async function J5(){return await cc()}const X5=Wr("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"}}),Eb=m.forwardRef(({className:a,size:n,abbrTitle:r,children:c,...d},u)=>e.jsx("kbd",{className:F(X5({size:n,className:a})),ref:u,...d,children:r?e.jsx("abbr",{title:r,children:c}):c}));Eb.displayName="Kbd";const Z5=[{icon:nd,title:"首页",description:"查看仪表板概览",path:"/",category:"概览"},{icon:Ea,title:"麦麦主程序配置",description:"配置麦麦的核心设置",path:"/config/bot",category:"配置"},{icon:Ll,title:"麦麦模型提供商配置",description:"配置模型提供商",path:"/config/modelProvider",category:"配置"},{icon:dv,title:"麦麦模型配置",description:"配置模型参数",path:"/config/model",category:"配置"},{icon:ld,title:"表情包管理",description:"管理麦麦的表情包",path:"/resource/emoji",category:"资源"},{icon:Ra,title:"表达方式管理",description:"管理麦麦的表达方式",path:"/resource/expression",category:"资源"},{icon:uv,title:"人物信息管理",description:"管理人物信息",path:"/resource/person",category:"资源"},{icon:Jr,title:"黑话管理",description:"管理麦麦学习到的黑话和俚语",path:"/resource/jargon",category:"资源"},{icon:Y_,title:"统计信息",description:"查看使用统计",path:"/statistics",category:"监控"},{icon:ra,title:"插件市场",description:"浏览和安装插件",path:"/plugins",category:"扩展"},{icon:nx,title:"日志查看器",description:"查看系统日志",path:"/logs",category:"监控"},{icon:vn,title:"系统设置",description:"配置系统参数",path:"/settings",category:"系统"}];function W5({open:a,onOpenChange:n}){const[r,c]=m.useState(""),[d,u]=m.useState(0),h=ca(),f=Z5.filter(N=>N.title.toLowerCase().includes(r.toLowerCase())||N.description.toLowerCase().includes(r.toLowerCase())||N.category.toLowerCase().includes(r.toLowerCase())),p=m.useCallback(N=>{h({to:N}),n(!1),c(""),u(0)},[h,n]),g=m.useCallback(N=>{N.key==="ArrowDown"?(N.preventDefault(),u(v=>(v+1)%f.length)):N.key==="ArrowUp"?(N.preventDefault(),u(v=>(v-1+f.length)%f.length)):N.key==="Enter"&&f[d]&&(N.preventDefault(),p(f[d].path))},[f,d,p]);return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-2xl p-0 gap-0",children:[e.jsxs(Os,{className:"px-4 pt-4 pb-0",children:[e.jsx(Ls,{className:"sr-only",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 h-5 w-5 -translate-y-1/2 text-muted-foreground"}),e.jsx(le,{value:r,onChange:N=>{c(N.target.value),u(0)},onKeyDown:g,placeholder:"搜索页面...",className:"h-12 pl-11 text-base border-0 focus-visible:ring-0 shadow-none",autoFocus:!0})]})]}),e.jsx("div",{className:"border-t",children:e.jsx(Je,{className:"h-[400px]",children:f.length>0?e.jsx("div",{className:"p-2",children:f.map((N,v)=>{const w=N.icon;return e.jsxs("button",{onClick:()=>p(N.path),onMouseEnter:()=>u(v),className:F("w-full flex items-center gap-3 px-3 py-2.5 rounded-md text-left transition-colors",v===d?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[e.jsx(w,{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:N.title}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:N.description})]}),e.jsx("div",{className:"text-xs text-muted-foreground px-2 py-1 bg-muted rounded",children:N.category})]},N.path)})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(Tt,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r?"未找到匹配的页面":"输入关键词开始搜索"})]})})}),e.jsx("div",{className:"border-t px-4 py-3 flex items-center justify-between text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↑"}),e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↓"}),"导航"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Enter"}),"选择"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Esc"}),"关闭"]})]})})]})})}function eT(){const a=window.location.protocol==="http:",n=window.location.hostname.toLowerCase(),r=n==="localhost"||n==="127.0.0.1"||n==="::1",c=sessionStorage.getItem("http-warning-dismissed")==="true",[d,u]=m.useState(a&&!r&&!c),[h,f]=m.useState(!1),p=()=>{f(!0),u(!1),sessionStorage.setItem("http-warning-dismissed","true")};return!d||h?null:e.jsx("div",{className:"relative bg-amber-500/10 border-b border-amber-500/20 backdrop-blur-sm",children:e.jsx("div",{className:"container mx-auto px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx(Jt,{className:"h-5 w-5 text-amber-600 dark:text-amber-500 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("p",{className:"text-sm font-medium text-amber-900 dark:text-amber-100",children:[e.jsx("span",{className:"font-semibold",children:"安全警告:"}),"您正在使用 ",e.jsx("strong",{children:"HTTP"})," 访问 MaiBot WebUI"]}),e.jsx("p",{className:"text-xs text-amber-800 dark:text-amber-200 mt-1",children:"如果这是公网服务器,您的数据(包括 Token、聊天记录等)可能在传输过程中被窃取。强烈建议使用 HTTPS 访问或仅在本地网络使用。"})]})]}),e.jsx(_,{variant:"ghost",size:"icon",onClick:p,className:"h-8 w-8 text-amber-700 hover:text-amber-900 dark:text-amber-400 dark:hover:text-amber-200 flex-shrink-0","aria-label":"关闭警告",children:e.jsx(Aa,{className:"h-4 w-4"})})]})})})}function sT(){const[a,n]=m.useState(0),[r,c]=m.useState(!1),d=m.useRef(null);m.useEffect(()=>{const g=N=>{const v=N.target;if(v.scrollHeight>v.clientHeight+100){d.current=v;const w=v.scrollTop,b=v.scrollHeight-v.clientHeight,y=b>0?w/b*100:0;n(y),c(w>300)}};return window.addEventListener("scroll",g,{capture:!0,passive:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})},[]);const u=()=>{d.current?.scrollTo({top:0,behavior:"smooth"})},h=18,f=2*Math.PI*h,p=f-a/100*f;return e.jsx("div",{className:F("fixed bottom-24 right-8 z-50 transition-all duration-500 ease-in-out transform",r?"translate-x-0 opacity-100":"translate-x-32 opacity-0 pointer-events-none"),children:e.jsxs(_,{variant:"outline",size:"icon",className:F("relative h-12 w-12 rounded-full shadow-xl","bg-background/80 backdrop-blur-md border-border/50","hover:bg-accent hover:scale-110 hover:shadow-2xl hover:border-primary/50","transition-all duration-300","group"),onClick:u,"aria-label":"回到顶部",children:[e.jsxs("svg",{className:"absolute inset-0 h-full w-full -rotate-90 transform p-1",viewBox:"0 0 44 44",children:[e.jsx("circle",{className:"text-muted-foreground/10",strokeWidth:"3",stroke:"currentColor",fill:"transparent",r:h,cx:"22",cy:"22"}),e.jsx("circle",{className:"text-primary transition-all duration-100 ease-out",strokeWidth:"3",strokeDasharray:f,strokeDashoffset:p,strokeLinecap:"round",stroke:"currentColor",fill:"transparent",r:h,cx:"22",cy:"22"})]}),e.jsx(J_,{className:"h-5 w-5 text-primary transition-transform duration-300 group-hover:-translate-y-1 group-hover:scale-110",strokeWidth:2.5}),e.jsx("div",{className:"absolute inset-0 rounded-full bg-primary/5 opacity-0 group-hover:opacity-100 transition-opacity duration-300"})]})})}const tT=f_,aT=p_,lT=g_,Mb=m.forwardRef(({className:a,sideOffset:n=4,...r},c)=>e.jsx(h_,{children:e.jsx(qj,{ref:c,sideOffset:n,className:F("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]",a),...r})}));Mb.displayName=qj.displayName;function nT({children:a}){const{checking:n}=Y5(),[r,c]=m.useState(!0),[d,u]=m.useState(!1),[h,f]=m.useState(!1),[p,g]=m.useState(!1),{theme:N,setTheme:v}=xx(),w=X0();if(m.useEffect(()=>{if(r)g(!1);else{const S=setTimeout(()=>{g(!0)},350);return()=>clearTimeout(S)}},[r]),m.useEffect(()=>{const S=U=>{(U.metaKey||U.ctrlKey)&&U.key==="k"&&(U.preventDefault(),f(!0))};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[]),n)return e.jsx("div",{className:"flex h-screen items-center justify-center bg-background",children:e.jsx("div",{className:"text-muted-foreground",children:"正在验证登录状态..."})});const b=[{title:"概览",items:[{icon:nd,label:"首页",path:"/"}]},{title:"麦麦配置编辑",items:[{icon:Ea,label:"麦麦主程序配置",path:"/config/bot"},{icon:Ll,label:"AI模型厂商配置",path:"/config/modelProvider",tourId:"sidebar-model-provider"},{icon:dv,label:"模型管理与分配",path:"/config/model",tourId:"sidebar-model-management"},{icon:_g,label:"麦麦适配器配置",path:"/config/adapter"}]},{title:"麦麦资源管理",items:[{icon:ld,label:"表情包管理",path:"/resource/emoji"},{icon:Ra,label:"表达方式管理",path:"/resource/expression"},{icon:Jr,label:"黑话管理",path:"/resource/jargon"},{icon:uv,label:"人物信息管理",path:"/resource/person"},{icon:rv,label:"知识库图谱可视化",path:"/resource/knowledge-graph"},{icon:Yr,label:"麦麦知识库管理",path:"/resource/knowledge-base"}]},{title:"扩展与监控",items:[{icon:ra,label:"插件市场",path:"/plugins"},{icon:cv,label:"配置模板市场",path:"/config/pack-market"},{icon:_g,label:"插件配置",path:"/plugin-config"},{icon:nx,label:"日志查看器",path:"/logs"},{icon:sx,label:"计划器&回复器监控",path:"/planner-monitor"},{icon:Ra,label:"本地聊天室",path:"/chat"}]},{title:"系统",items:[{icon:vn,label:"系统设置",path:"/settings"}]}],A=N==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":N,z=async()=>{await z1()};return e.jsx(tT,{delayDuration:300,children:e.jsxs("div",{className:"flex h-screen overflow-hidden",children:[e.jsxs("aside",{className:F("fixed inset-y-0 left-0 z-50 flex flex-col border-r bg-card transition-all duration-300 lg:relative lg:z-0","w-64 lg:w-auto",r?"lg:w-64":"lg:w-16",d?"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:F("relative flex items-center justify-center flex-1 transition-all overflow-hidden","lg:flex-1",!r&&"lg:flex-none lg:w-8"),children:[e.jsxs("div",{className:F("flex items-baseline gap-2",!r&&"lg:hidden"),children:[e.jsx("span",{className:"font-bold text-xl text-primary-gradient whitespace-nowrap",children:"MaiBot WebUI"}),e.jsx("span",{className:"text-xs text-primary/60 whitespace-nowrap",children:x2()})]}),!r&&e.jsx("span",{className:"hidden lg:block font-bold text-primary-gradient text-2xl",children:"M"})]})}),e.jsx(Je,{className:F("flex-1 overflow-x-hidden",!r&&"lg:w-16"),children:e.jsx("nav",{className:F("p-4",!r&&"lg:p-2 lg:w-16"),children:e.jsx("ul",{className:F("space-y-6",!r&&"lg:space-y-3 lg:w-full"),children:b.map((S,U)=>e.jsxs("li",{children:[e.jsx("div",{className:F("px-3 h-[1.25rem]","mb-2",!r&&"lg:mb-1 lg:invisible"),children:e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground/60 whitespace-nowrap",children:S.title})}),!r&&U>0&&e.jsx("div",{className:"hidden lg:block mb-2 border-t border-border"}),e.jsx("ul",{className:"space-y-1",children:S.items.map(E=>{const C=w({to:E.path}),D=E.icon,I=e.jsxs(e.Fragment,{children:[C&&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:F("flex items-center transition-all duration-300",r?"gap-3":"gap-3 lg:gap-0"),children:[e.jsx(D,{className:F("h-5 w-5 flex-shrink-0",C&&"text-primary"),strokeWidth:2,fill:"none"}),e.jsx("span",{className:F("text-sm font-medium whitespace-nowrap transition-all duration-300",C&&"font-semibold",r?"opacity-100 max-w-[200px]":"opacity-100 max-w-[200px] lg:opacity-0 lg:max-w-0 lg:overflow-hidden"),children:E.label})]})]});return e.jsx("li",{className:"relative",children:e.jsxs(aT,{children:[e.jsx(lT,{asChild:!0,children:e.jsx(Fn,{to:E.path,"data-tour":E.tourId,className:F("relative flex items-center rounded-lg py-2 transition-all duration-300","hover:bg-accent hover:text-accent-foreground",C?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground",r?"px-3":"px-3 lg:px-0 lg:justify-center lg:w-12 lg:mx-auto"),onClick:()=>u(!1),children:I})}),p&&e.jsx(Mb,{side:"right",className:"hidden lg:block",children:e.jsx("p",{children:E.label})})]})},E.path)})})]},S.title))})})})]}),d&&e.jsx("div",{className:"fixed inset-0 z-40 bg-black/50 lg:hidden",onClick:()=>u(!1)}),e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(eT,{}),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:()=>u(!d),className:"rounded-lg p-2 hover:bg-accent lg:hidden",children:e.jsx(X_,{className:"h-5 w-5"})}),e.jsx("button",{onClick:()=>c(!r),className:"hidden rounded-lg p-2 hover:bg-accent lg:block",title:r?"收起侧边栏":"展开侧边栏",children:e.jsx(Da,{className:F("h-5 w-5 transition-transform",!r&&"rotate-180")})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fn,{to:"/annual-report",children:e.jsxs(_,{variant:"ghost",size:"sm",className:"gap-2 bg-gradient-to-r from-pink-500/10 to-purple-500/10 hover:from-pink-500/20 hover:to-purple-500/20 border border-pink-500/20",title:"查看年度总结",children:[e.jsx(Z_,{className:"h-4 w-4 text-pink-500"}),e.jsx("span",{className:"hidden sm:inline bg-gradient-to-r from-pink-500 to-purple-500 bg-clip-text text-transparent font-medium",children:"2025 年度总结"})]})}),e.jsxs("button",{onClick:()=>f(!0),className:"relative hidden md:flex items-center w-64 h-9 pl-9 pr-16 bg-background/50 border rounded-md hover:bg-accent/50 transition-colors text-left",children:[e.jsx(Tt,{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(Eb,{size:"sm",className:"absolute right-2 top-1/2 -translate-y-1/2",children:[e.jsx("span",{className:"text-xs",children:"⌘"}),"K"]})]}),e.jsx(W5,{open:h,onOpenChange:f}),e.jsxs(_,{variant:"ghost",size:"sm",onClick:()=>window.open("https://docs.mai-mai.org","_blank"),className:"gap-2",title:"查看麦麦文档",children:[e.jsx(W_,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"麦麦文档"})]}),e.jsx("button",{onClick:S=>{c2(A==="dark"?"light":"dark",v,S)},className:"rounded-lg p-2 hover:bg-accent",title:A==="dark"?"切换到浅色模式":"切换到深色模式",children:A==="dark"?e.jsx(ax,{className:"h-5 w-5"}):e.jsx(ec,{className:"h-5 w-5"})}),e.jsx("div",{className:"h-6 w-px bg-border"}),e.jsxs(_,{variant:"ghost",size:"sm",onClick:z,className:"gap-2",title:"登出系统",children:[e.jsx(e1,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"登出"})]})]})]}),e.jsx("main",{className:"flex-1 overflow-hidden bg-background",children:a}),e.jsx(sT,{})]})]})})}function rT(a){const n=a.split(` +`).slice(1),r=[];for(const c of n){const d=c.trim();if(!d.startsWith("at "))continue;const u=d.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);u?r.push({functionName:u[1]||"",fileName:u[2],lineNumber:u[3],columnNumber:u[4],raw:d}):r.push({functionName:"",fileName:"",lineNumber:"",columnNumber:"",raw:d})}return r}function iT({error:a,errorInfo:n}){const[r,c]=m.useState(!0),[d,u]=m.useState(!1),[h,f]=m.useState(!1),p=a.stack?rT(a.stack):[],g=async()=>{const N=` +Error: ${a.name} +Message: ${a.message} + +Stack Trace: +${a.stack||"No stack trace available"} + +Component Stack: +${n?.componentStack||"No component stack available"} + +URL: ${window.location.href} +User Agent: ${navigator.userAgent} +Time: ${new Date().toISOString()} + `.trim();try{await navigator.clipboard.writeText(N),f(!0),setTimeout(()=>f(!1),2e3)}catch(v){console.error("Failed to copy:",v)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{variant:"destructive",className:"border-red-500/50 bg-red-500/10",children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(lt,{className:"font-mono text-sm",children:[e.jsxs("span",{className:"font-semibold",children:[a.name,":"]})," ",a.message]})]}),p.length>0&&e.jsxs(uc,{open:r,onOpenChange:c,children:[e.jsx(mc,{asChild:!0,children:e.jsxs(_,{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(s1,{className:"h-4 w-4"}),"Stack Trace (",p.length," frames)"]}),r?e.jsx(Qr,{className:"h-4 w-4"}):e.jsx(za,{className:"h-4 w-4"})]})}),e.jsx(xc,{children:e.jsx(Je,{className:"h-[280px] rounded-md border bg-muted/30",children:e.jsx("div",{className:"p-3 space-y-1",children:p.map((N,v)=>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:[v+1,"."]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-primary font-medium",children:N.functionName}),N.fileName&&e.jsxs("div",{className:"text-muted-foreground mt-0.5 break-all",children:[N.fileName,N.lineNumber&&e.jsxs("span",{className:"text-yellow-600 dark:text-yellow-400",children:[":",N.lineNumber,":",N.columnNumber]})]})]})]})},v))})})})]}),n?.componentStack&&e.jsxs(uc,{open:d,onOpenChange:u,children:[e.jsx(mc,{asChild:!0,children:e.jsxs(_,{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(Jt,{className:"h-4 w-4"}),"Component Stack"]}),d?e.jsx(Qr,{className:"h-4 w-4"}):e.jsx(za,{className:"h-4 w-4"})]})}),e.jsx(xc,{children:e.jsx(Je,{className:"h-[200px] rounded-md border bg-muted/30",children:e.jsx("pre",{className:"p-3 font-mono text-xs whitespace-pre-wrap text-muted-foreground",children:n.componentStack})})})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:g,className:"w-full",children:h?e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"mr-2 h-4 w-4 text-green-500"}),"已复制到剪贴板"]}):e.jsxs(e.Fragment,{children:[e.jsx(Fo,{className:"mr-2 h-4 w-4"}),"复制错误信息"]})})]})}function Ab({error:a,errorInfo:n}){const r=()=>{window.location.href="/"},c=()=>{window.location.reload()};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(Ce,{className:"w-full max-w-2xl shadow-lg",children:[e.jsxs(De,{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(Jt,{className:"h-8 w-8 text-red-600 dark:text-red-400"})}),e.jsx(Oe,{className:"text-2xl font-bold",children:"页面出现了问题"}),e.jsx(os,{className:"text-base mt-2",children:"应用程序遇到了意外错误。您可以尝试刷新页面或返回首页。"})]}),e.jsxs(Me,{className:"space-y-4",children:[e.jsx(iT,{error:a,errorInfo:n}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 pt-2",children:[e.jsxs(_,{onClick:c,className:"flex-1",children:[e.jsx(dt,{className:"mr-2 h-4 w-4"}),"刷新页面"]}),e.jsxs(_,{onClick:r,variant:"outline",className:"flex-1",children:[e.jsx(nd,{className:"mr-2 h-4 w-4"}),"返回首页"]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground pt-2",children:"如果问题持续存在,请将错误信息复制并反馈给开发者"})]})]})})}class cT extends m.Component{constructor(n){super(n),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,r){console.error("ErrorBoundary caught an error:",n,r),this.setState({errorInfo:r})}handleReset=()=>{this.setState({hasError:!1,error:null,errorInfo:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?this.props.fallback:e.jsx(Ab,{error:this.state.error,errorInfo:this.state.errorInfo}):this.props.children}}function zb({error:a}){return e.jsx(Ab,{error:a,errorInfo:null})}const vc=Z0({component:()=>e.jsxs(e.Fragment,{children:[e.jsx(rj,{}),!1]}),beforeLoad:()=>{if(window.location.pathname==="/"&&!J5())throw ew({to:"/auth"})}}),oT=Qs({getParentRoute:()=>vc,path:"/auth",component:E2}),dT=Qs({getParentRoute:()=>vc,path:"/setup",component:G2}),nt=Qs({getParentRoute:()=>vc,id:"protected",component:()=>e.jsx(nT,{children:e.jsx(rj,{})}),errorComponent:({error:a})=>e.jsx(zb,{error:a})}),uT=Qs({getParentRoute:()=>nt,path:"/",component:l2}),mT=Qs({getParentRoute:()=>nt,path:"/config/bot",component:wS}),xT=Qs({getParentRoute:()=>nt,path:"/config/modelProvider",component:OS}),hT=Qs({getParentRoute:()=>nt,path:"/config/model",component:r4}),fT=Qs({getParentRoute:()=>nt,path:"/config/adapter",component:T4}),pT=Qs({getParentRoute:()=>nt,path:"/resource/emoji",component:X4}),gT=Qs({getParentRoute:()=>nt,path:"/resource/expression",component:sk}),jT=Qs({getParentRoute:()=>nt,path:"/resource/person",component:Sk}),vT=Qs({getParentRoute:()=>nt,path:"/resource/jargon",component:fk}),NT=Qs({getParentRoute:()=>nt,path:"/resource/knowledge-graph",component:Dk}),bT=Qs({getParentRoute:()=>nt,path:"/resource/knowledge-base",component:Ok}),yT=Qs({getParentRoute:()=>nt,path:"/logs",component:Uk}),wT=Qs({getParentRoute:()=>nt,path:"/planner-monitor",component:qk}),_T=Qs({getParentRoute:()=>nt,path:"/chat",component:AC}),ST=Qs({getParentRoute:()=>nt,path:"/plugins",component:mC}),kT=Qs({getParentRoute:()=>nt,path:"/plugin-detail",component:yC}),CT=Qs({getParentRoute:()=>nt,path:"/model-presets",component:hC}),TT=Qs({getParentRoute:()=>nt,path:"/plugin-config",component:gC}),ET=Qs({getParentRoute:()=>nt,path:"/plugin-mirrors",component:vC}),MT=Qs({getParentRoute:()=>nt,path:"/settings",component:y2}),AT=Qs({getParentRoute:()=>nt,path:"/config/pack-market",component:M5}),Rb=Qs({getParentRoute:()=>nt,path:"/config/pack-market/$packId",component:q5}),zT=Qs({getParentRoute:()=>nt,path:"/survey/webui-feedback",component:KC}),RT=Qs({getParentRoute:()=>nt,path:"/survey/maibot-feedback",component:QC}),DT=Qs({getParentRoute:()=>nt,path:"/annual-report",component:e5}),OT=Qs({getParentRoute:()=>vc,path:"*",component:Pv}),LT=vc.addChildren([oT,dT,nt.addChildren([uT,mT,xT,hT,fT,pT,gT,vT,jT,NT,bT,ST,kT,CT,TT,ET,yT,wT,_T,MT,AT,Rb,zT,RT,DT]),OT]),UT=W0({routeTree:LT,defaultNotFoundComponent:Pv,defaultErrorComponent:({error:a})=>e.jsx(zb,{error:a})});function $T({children:a,defaultTheme:n="system",storageKey:r="ui-theme",...c}){const[d,u]=m.useState(()=>localStorage.getItem(r)||n);m.useEffect(()=>{const f=window.document.documentElement;if(f.classList.remove("light","dark"),d==="system"){const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";f.classList.add(p);return}f.classList.add(d)},[d]),m.useEffect(()=>{const f=localStorage.getItem("accent-color");if(f){const p=document.documentElement,N={blue:{hsl:"221.2 83.2% 53.3%",darkHsl:"217.2 91.2% 59.8%",gradient:null},purple:{hsl:"271 91% 65%",darkHsl:"270 95% 75%",gradient:null},green:{hsl:"142 71% 45%",darkHsl:"142 76% 36%",gradient:null},orange:{hsl:"25 95% 53%",darkHsl:"20 90% 48%",gradient:null},pink:{hsl:"330 81% 60%",darkHsl:"330 85% 70%",gradient:null},red:{hsl:"0 84% 60%",darkHsl:"0 90% 70%",gradient:null},"gradient-sunset":{hsl:"15 95% 60%",darkHsl:"15 95% 65%",gradient:"linear-gradient(135deg, hsl(25 95% 53%) 0%, hsl(330 81% 60%) 100%)"},"gradient-ocean":{hsl:"200 90% 55%",darkHsl:"200 90% 60%",gradient:"linear-gradient(135deg, hsl(221.2 83.2% 53.3%) 0%, hsl(189 94% 43%) 100%)"},"gradient-forest":{hsl:"150 70% 45%",darkHsl:"150 75% 40%",gradient:"linear-gradient(135deg, hsl(142 71% 45%) 0%, hsl(158 64% 52%) 100%)"},"gradient-aurora":{hsl:"310 85% 65%",darkHsl:"310 90% 70%",gradient:"linear-gradient(135deg, hsl(271 91% 65%) 0%, hsl(330 81% 60%) 100%)"},"gradient-fire":{hsl:"15 95% 55%",darkHsl:"15 95% 60%",gradient:"linear-gradient(135deg, hsl(0 84% 60%) 0%, hsl(25 95% 53%) 100%)"},"gradient-twilight":{hsl:"250 90% 60%",darkHsl:"250 95% 65%",gradient:"linear-gradient(135deg, hsl(239 84% 67%) 0%, hsl(271 91% 65%) 100%)"}}[f];N&&(p.style.setProperty("--primary",N.hsl),N.gradient?(p.style.setProperty("--primary-gradient",N.gradient),p.classList.add("has-gradient")):(p.style.removeProperty("--primary-gradient"),p.classList.remove("has-gradient")))}},[]);const h={theme:d,setTheme:f=>{localStorage.setItem(r,f),u(f)}};return e.jsx(Ov.Provider,{...c,value:h,children:a})}function BT({children:a,defaultEnabled:n=!0,defaultWavesEnabled:r=!0,storageKey:c="enable-animations",wavesStorageKey:d="enable-waves-background"}){const[u,h]=m.useState(()=>{const N=localStorage.getItem(c);return N!==null?N==="true":n}),[f,p]=m.useState(()=>{const N=localStorage.getItem(d);return N!==null?N==="true":r});m.useEffect(()=>{const N=document.documentElement;u?N.classList.remove("no-animations"):N.classList.add("no-animations"),localStorage.setItem(c,String(u))},[u,c]),m.useEffect(()=>{localStorage.setItem(d,String(f))},[f,d]);const g={enableAnimations:u,setEnableAnimations:h,enableWavesBackground:f,setEnableWavesBackground:p};return e.jsx(Lv.Provider,{value:g,children:a})}const PT=j_,Db=m.forwardRef(({className:a,...n},r)=>e.jsx(Kj,{ref:r,className:F("fixed bottom-0 right-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:max-w-[420px] gap-2",a),...n}));Db.displayName=Kj.displayName;const IT=Wr("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"}}),Ob=m.forwardRef(({className:a,variant:n,...r},c)=>e.jsx(Qj,{ref:c,className:F(IT({variant:n}),a),...r}));Ob.displayName=Qj.displayName;const FT=m.forwardRef(({className:a,...n},r)=>e.jsx(Yj,{ref:r,className:F("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",a),...n}));FT.displayName=Yj.displayName;const Lb=m.forwardRef(({className:a,...n},r)=>e.jsx(Jj,{ref:r,className:F("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",a),"toast-close":"",...n,children:e.jsx(Aa,{className:"h-4 w-4"})}));Lb.displayName=Jj.displayName;const Ub=m.forwardRef(({className:a,...n},r)=>e.jsx(Xj,{ref:r,className:F("text-sm font-semibold [&+div]:text-xs",a),...n}));Ub.displayName=Xj.displayName;const $b=m.forwardRef(({className:a,...n},r)=>e.jsx(Zj,{ref:r,className:F("text-sm opacity-90",a),...n}));$b.displayName=Zj.displayName;function HT(){const{toasts:a}=Ys();return e.jsxs(PT,{children:[a.map(function({id:n,title:r,description:c,action:d,...u}){return e.jsxs(Ob,{...u,children:[e.jsxs("div",{className:"grid gap-1",children:[r&&e.jsx(Ub,{children:r}),c&&e.jsx($b,{children:c})]}),d,e.jsx(Lb,{})]},n)}),e.jsx(Db,{})]})}A1.createRoot(document.getElementById("root")).render(e.jsx(m.StrictMode,{children:e.jsx(cT,{children:e.jsx($T,{defaultTheme:"system",children:e.jsx(BT,{children:e.jsxs(ES,{children:[e.jsx(sw,{router:UT}),e.jsx(zS,{}),e.jsx(HT,{})]})})})})})); diff --git a/webui/dist/assets/index-DC6giT2e.js b/webui/dist/assets/index-DC6giT2e.js deleted file mode 100644 index 67f24e49..00000000 --- a/webui/dist/assets/index-DC6giT2e.js +++ /dev/null @@ -1,91 +0,0 @@ -import{r as m,j as e,L as Fn,e as ca,R as Rs,b as Q0,f as Y0,g as J0,h as X0,k as Z0,l as Qs,m as W0,n as ew,O as rj,o as sw}from"./router-9vIXuQkh.js";import{a as tw,b as aw,g as lw}from"./react-vendor-BmxF9s7Q.js";import{N as nw,c as rw,O as Wr,P as iw,g as Tm}from"./utils-BqoaXoQ1.js";import{L as ij,T as cj,C as oj,R as cw,a as dj,V as ow,b as dw,S as uj,c as uw,d as mj,I as mw,e as xj,f as xw,g as hj,h as hw,i as fw,j as pw,O as fj,P as gw,k as pj,l as gj,D as jj,A as vj,m as Nj,n as jw,o as vw,p as bj,q as Nw,r as yj,s as bw,t as yw,u as wj,v as ww,w as _w,x as _j,y as Sj,F as kj,z as Cj,B as Sw,E as kw,G as Tj,H as Cw,J as Tw,K as Ew,M as Mw,N as Aw,Q as zw,U as Rw,W as Dw,X as Ow,Y as Lw,Z as Uw,_ as $w,$ as Bw,a0 as Pw,a1 as Iw,a2 as Ej,a3 as Fw,a4 as Hw}from"./radix-extra-DmmnfeQE.js";import{R as Mj,T as Aj,L as Vw,g as Gw,C as Qi,X as Yi,Y as Hr,h as qw,B as Uo,j as Ji,P as Kw,k as Qw,l as Yw}from"./charts-simvewUa.js";import{S as Jw,O as zj,o as Xw,C as Rj,p as Zw,T as Dj,D as Oj,R as Ww,q as e_,H as Lj,I as s_,J as Uj,K as t_,L as $j,M as Bj,N as a_,Q as Pj,V as l_,U as Ij,X as Fj,Y as n_,Z as r_,_ as Hj,$ as i_,a0 as c_,a1 as Vj,e as Gj,f as sd,c as td,P as Zn,d as ad,b as gn,h as o_,l as d_,m as u_,u as qm,r as m_,a as x_,a2 as h_,a3 as qj,a4 as f_,a5 as p_,a6 as g_,a7 as Kj,a8 as Qj,a9 as Yj,aa as Jj,ab as Xj,ac as Zj,ad as j_}from"./radix-core-DyJi0yyw.js";import{R as dt,a as lc,C as _t,b as pt,L as zs,X as Aa,c as Ct,d as za,e as Qr,f as Da,g as Wt,E as v_,h as na,i as Ka,S as Tt,B as Vn,U as jn,P as hc,Z as el,j as Wj,F as Ea,k as N_,l as vn,m as b_,M as Ra,A as sx,D as y_,n as Yr,T as tx,o as w_,p as ev,I as Ft,q as Jt,r as Fo,s as nc,t as ia,H as __,u as ns,v as Xt,w as rc,x as ax,y as ec,z as bg,K as lx,G as sv,J as S_,N as $o,O as k_,Q as ld,V as C_,W as T_,Y as nd,_ as Ma,$ as et,a0 as nx,a1 as tv,a2 as fc,a3 as av,a4 as lv,a5 as Kn,a6 as Nn,a7 as bn,a8 as rx,a9 as nv,aa as ra,ab as Ll,ac as Qn,ad as Yn,ae as rd,af as E_,ag as M_,ah as A_,ai as ix,aj as Bo,ak as Jn,al as z_,am as Jr,an as Ho,ao as R_,ap as Vo,aq as ic,ar as rv,as as D_,at as O_,au as Go,av as L_,aw as cx,ax as U_,ay as yg,az as $_,aA as B_,aB as iv,aC as P_,aD as mn,aE as cv,aF as Em,aG as wg,aH as I_,aI as Mm,aJ as F_,aK as H_,aL as V_,aM as G_,aN as ov,aO as q_,aP as Xr,aQ as K_,aR as Q_,aS as dv,aT as uv,aU as Y_,aV as J_,aW as _g,aX as X_,aY as Z_,aZ as W_,a_ as e1,a$ as s1}from"./icons-9Z4kBNLK.js";import{S as t1,p as a1,j as l1,a as n1,E as Sg,R as r1,o as i1}from"./codemirror-TZqPU532.js";import{u as mv,a as qo,s as xv,K as hv,P as fv,b as pv,D as gv,c as jv,S as vv,v as c1,d as Nv,C as bv,h as o1}from"./dnd-BiPfFtVp.js";import{_ as ja,c as d1,g as yv,D as u1,z as Ro}from"./misc-CJqnlRwD.js";import{D as m1,U as x1}from"./uppy-DFP_VzYR.js";import{M as h1,r as f1,a as p1,b as g1}from"./markdown-CKA5gBQ9.js";import{c as j1,H as Ko,P as Qo,u as v1,d as N1,R as b1,B as y1,e as w1,C as _1,M as S1,f as k1}from"./reactflow-DtsZHOR4.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const d of document.querySelectorAll('link[rel="modulepreload"]'))c(d);new MutationObserver(d=>{for(const u of d)if(u.type==="childList")for(const h of u.addedNodes)h.tagName==="LINK"&&h.rel==="modulepreload"&&c(h)}).observe(document,{childList:!0,subtree:!0});function r(d){const u={};return d.integrity&&(u.integrity=d.integrity),d.referrerPolicy&&(u.referrerPolicy=d.referrerPolicy),d.crossOrigin==="use-credentials"?u.credentials="include":d.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function c(d){if(d.ep)return;d.ep=!0;const u=r(d);fetch(d.href,u)}})();var Am={exports:{}},Gi={},zm={exports:{}},Rm={};var kg;function C1(){return kg||(kg=1,(function(a){function n(M,K){var P=M.length;M.push(K);e:for(;0>>1,Q=M[ue];if(0>>1;ued(Te,P))zd(D,Te)?(M[ue]=D,M[z]=P,ue=z):(M[ue]=Te,M[pe]=P,ue=pe);else if(zd(D,P))M[ue]=D,M[z]=P,ue=z;else break e}}return K}function d(M,K){var P=M.sortIndex-K.sortIndex;return P!==0?P:M.id-K.id}if(a.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var u=performance;a.unstable_now=function(){return u.now()}}else{var h=Date,f=h.now();a.unstable_now=function(){return h.now()-f}}var p=[],g=[],N=1,v=null,w=3,b=!1,y=!1,O=!1,R=!1,S=typeof setTimeout=="function"?setTimeout:null,B=typeof clearTimeout=="function"?clearTimeout:null,E=typeof setImmediate<"u"?setImmediate:null;function C(M){for(var K=r(g);K!==null;){if(K.callback===null)c(g);else if(K.startTime<=M)c(g),K.sortIndex=K.expirationTime,n(p,K);else break;K=r(g)}}function A(M){if(O=!1,C(M),!y)if(r(p)!==null)y=!0,F||(F=!0,je());else{var K=r(g);K!==null&&ge(A,K.startTime-M)}}var F=!1,L=-1,J=5,U=-1;function oe(){return R?!0:!(a.unstable_now()-UM&&oe());){var ue=v.callback;if(typeof ue=="function"){v.callback=null,w=v.priorityLevel;var Q=ue(v.expirationTime<=M);if(M=a.unstable_now(),typeof Q=="function"){v.callback=Q,C(M),K=!0;break s}v===r(p)&&c(p),C(M)}else c(p);v=r(p)}if(v!==null)K=!0;else{var Se=r(g);Se!==null&&ge(A,Se.startTime-M),K=!1}}break e}finally{v=null,w=P,b=!1}K=void 0}}finally{K?je():F=!1}}}var je;if(typeof E=="function")je=function(){E(Ne)};else if(typeof MessageChannel<"u"){var re=new MessageChannel,fe=re.port2;re.port1.onmessage=Ne,je=function(){fe.postMessage(null)}}else je=function(){S(Ne,0)};function ge(M,K){L=S(function(){M(a.unstable_now())},K)}a.unstable_IdlePriority=5,a.unstable_ImmediatePriority=1,a.unstable_LowPriority=4,a.unstable_NormalPriority=3,a.unstable_Profiling=null,a.unstable_UserBlockingPriority=2,a.unstable_cancelCallback=function(M){M.callback=null},a.unstable_forceFrameRate=function(M){0>M||125ue?(M.sortIndex=P,n(g,M),r(p)===null&&M===r(g)&&(O?(B(L),L=-1):O=!0,ge(A,P-ue))):(M.sortIndex=Q,n(p,M),y||b||(y=!0,F||(F=!0,je()))),M},a.unstable_shouldYield=oe,a.unstable_wrapCallback=function(M){var K=w;return function(){var P=w;w=K;try{return M.apply(this,arguments)}finally{w=P}}}})(Rm)),Rm}var Cg;function T1(){return Cg||(Cg=1,zm.exports=C1()),zm.exports}var Tg;function E1(){if(Tg)return Gi;Tg=1;var a=T1(),n=tw(),r=aw();function c(s){var t="https://react.dev/errors/"+s;if(1Q||(s.current=ue[Q],ue[Q]=null,Q--)}function Te(s,t){Q++,ue[Q]=s.current,s.current=t}var z=Se(null),D=Se(null),G=Se(null),de=Se(null);function Re(s,t){switch(Te(G,t),Te(D,s),Te(z,null),t.nodeType){case 9:case 11:s=(s=t.documentElement)&&(s=s.namespaceURI)?Vp(s):0;break;default:if(s=t.tagName,t=t.namespaceURI)t=Vp(t),s=Gp(t,s);else switch(s){case"svg":s=1;break;case"math":s=2;break;default:s=0}}pe(z),Te(z,s)}function W(){pe(z),pe(D),pe(G)}function Y(s){s.memoizedState!==null&&Te(de,s);var t=z.current,l=Gp(t,s.type);t!==l&&(Te(D,s),Te(z,l))}function Fe(s){D.current===s&&(pe(z),pe(D)),de.current===s&&(pe(de),Ii._currentValue=P)}var H,ee;function Ue(s){if(H===void 0)try{throw Error()}catch(l){var t=l.stack.trim().match(/\n( *(at )?)/);H=t&&t[1]||"",ee=-1)":-1o||$[i]!==le[o]){var ve=` -`+$[i].replace(" at new "," at ");return s.displayName&&ve.includes("")&&(ve=ve.replace("",s.displayName)),ve}while(1<=i&&0<=o);break}}}finally{ie=!1,Error.prepareStackTrace=l}return(l=s?s.displayName||s.name:"")?Ue(l):""}function me(s,t){switch(s.tag){case 26:case 27:case 5:return Ue(s.type);case 16:return Ue("Lazy");case 13:return s.child!==t&&t!==null?Ue("Suspense Fallback"):Ue("Suspense");case 19:return Ue("SuspenseList");case 0:case 15:return Ee(s.type,!1);case 11:return Ee(s.type.render,!1);case 1:return Ee(s.type,!0);case 31:return Ue("Activity");default:return""}}function Ae(s){try{var t="",l=null;do t+=me(s,l),l=s,s=s.return;while(s);return t}catch(i){return` -Error generating stack: `+i.message+` -`+i.stack}}var rs=Object.prototype.hasOwnProperty,Ut=a.unstable_scheduleCallback,aa=a.unstable_cancelCallback,Ja=a.unstable_shouldYield,Ht=a.unstable_requestPaint,mt=a.unstable_now,q=a.unstable_getCurrentPriorityLevel,qe=a.unstable_ImmediatePriority,Qe=a.unstable_UserBlockingPriority,es=a.unstable_NormalPriority,Us=a.unstable_LowPriority,as=a.unstable_IdlePriority,Cs=a.log,ze=a.unstable_setDisableYieldValue,bs=null,ls=null;function ss(s){if(typeof Cs=="function"&&ze(s),ls&&typeof ls.setStrictMode=="function")try{ls.setStrictMode(bs,s)}catch{}}var ys=Math.clz32?Math.clz32:tt,gt=Math.log,$t=Math.LN2;function tt(s){return s>>>=0,s===0?32:31-(gt(s)/$t|0)|0}var Ms=256,Et=262144,Bt=4194304;function Oa(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 ll(s,t,l){var i=s.pendingLanes;if(i===0)return 0;var o=0,x=s.suspendedLanes,j=s.pingedLanes;s=s.warmLanes;var k=i&134217727;return k!==0?(i=k&~x,i!==0?o=Oa(i):(j&=k,j!==0?o=Oa(j):l||(l=k&~s,l!==0&&(o=Oa(l))))):(k=i&~x,k!==0?o=Oa(k):j!==0?o=Oa(j):l||(l=i&~s,l!==0&&(o=Oa(l)))),o===0?0:t!==0&&t!==o&&(t&x)===0&&(x=o&-o,l=t&-t,x>=l||x===32&&(l&4194048)!==0)?t:o}function xl(s,t){return(s.pendingLanes&~(s.suspendedLanes&~s.pingedLanes)&t)===0}function sr(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 se(){var s=Bt;return Bt<<=1,(Bt&62914560)===0&&(Bt=4194304),s}function we(s){for(var t=[],l=0;31>l;l++)t.push(s);return t}function Le(s,t){s.pendingLanes|=t,t!==268435456&&(s.suspendedLanes=0,s.pingedLanes=0,s.warmLanes=0)}function Fs(s,t,l,i,o,x){var j=s.pendingLanes;s.pendingLanes=l,s.suspendedLanes=0,s.pingedLanes=0,s.warmLanes=0,s.expiredLanes&=l,s.entangledLanes&=l,s.errorRecoveryDisabledLanes&=l,s.shellSuspendCounter=0;var k=s.entanglements,$=s.expirationTimes,le=s.hiddenUpdates;for(l=j&~l;0"u")return null;try{return s.activeElement||s.body}catch{return s.body}}var Fb=/[\n"\\]/g;function Ua(s){return s.replace(Fb,function(t){return"\\"+t.charCodeAt(0).toString(16)+" "})}function yd(s,t,l,i,o,x,j,k){s.name="",j!=null&&typeof j!="function"&&typeof j!="symbol"&&typeof j!="boolean"?s.type=j:s.removeAttribute("type"),t!=null?j==="number"?(t===0&&s.value===""||s.value!=t)&&(s.value=""+La(t)):s.value!==""+La(t)&&(s.value=""+La(t)):j!=="submit"&&j!=="reset"||s.removeAttribute("value"),t!=null?wd(s,j,La(t)):l!=null?wd(s,j,La(l)):i!=null&&s.removeAttribute("value"),o==null&&x!=null&&(s.defaultChecked=!!x),o!=null&&(s.checked=o&&typeof o!="function"&&typeof o!="symbol"),k!=null&&typeof k!="function"&&typeof k!="symbol"&&typeof k!="boolean"?s.name=""+La(k):s.removeAttribute("name")}function Ux(s,t,l,i,o,x,j,k){if(x!=null&&typeof x!="function"&&typeof x!="symbol"&&typeof x!="boolean"&&(s.type=x),t!=null||l!=null){if(!(x!=="submit"&&x!=="reset"||t!=null)){bd(s);return}l=l!=null?""+La(l):"",t=t!=null?""+La(t):l,k||t===s.value||(s.value=t),s.defaultValue=t}i=i??o,i=typeof i!="function"&&typeof i!="symbol"&&!!i,s.checked=k?s.checked:!!i,s.defaultChecked=!!i,j!=null&&typeof j!="function"&&typeof j!="symbol"&&typeof j!="boolean"&&(s.name=j),bd(s)}function wd(s,t,l){t==="number"&&yc(s.ownerDocument)===s||s.defaultValue===""+l||(s.defaultValue=""+l)}function ir(s,t,l,i){if(s=s.options,t){t={};for(var o=0;o"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Td=!1;if(pl)try{var ni={};Object.defineProperty(ni,"passive",{get:function(){Td=!0}}),window.addEventListener("test",ni,ni),window.removeEventListener("test",ni,ni)}catch{Td=!1}var Fl=null,Ed=null,_c=null;function Vx(){if(_c)return _c;var s,t=Ed,l=t.length,i,o="value"in Fl?Fl.value:Fl.textContent,x=o.length;for(s=0;s=ci),Jx=" ",Xx=!1;function Zx(s,t){switch(s){case"keyup":return py.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Wx(s){return s=s.detail,typeof s=="object"&&"data"in s?s.data:null}var ur=!1;function jy(s,t){switch(s){case"compositionend":return Wx(t);case"keypress":return t.which!==32?null:(Xx=!0,Jx);case"textInput":return s=t.data,s===Jx&&Xx?null:s;default:return null}}function vy(s,t){if(ur)return s==="compositionend"||!Dd&&Zx(s,t)?(s=Vx(),_c=Ed=Fl=null,ur=!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:l,offset:t-s};s=i}e:{for(;l;){if(l.nextSibling){l=l.nextSibling;break e}l=l.parentNode}l=void 0}l=ih(l)}}function oh(s,t){return s&&t?s===t?!0:s&&s.nodeType===3?!1:t&&t.nodeType===3?oh(s,t.parentNode):"contains"in s?s.contains(t):s.compareDocumentPosition?!!(s.compareDocumentPosition(t)&16):!1:!1}function dh(s){s=s!=null&&s.ownerDocument!=null&&s.ownerDocument.defaultView!=null?s.ownerDocument.defaultView:window;for(var t=yc(s.document);t instanceof s.HTMLIFrameElement;){try{var l=typeof t.contentWindow.location.href=="string"}catch{l=!1}if(l)s=t.contentWindow;else break;t=yc(s.document)}return t}function Ud(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 Cy=pl&&"documentMode"in document&&11>=document.documentMode,mr=null,$d=null,mi=null,Bd=!1;function uh(s,t,l){var i=l.window===l?l.document:l.nodeType===9?l:l.ownerDocument;Bd||mr==null||mr!==yc(i)||(i=mr,"selectionStart"in i&&Ud(i)?i={start:i.selectionStart,end:i.selectionEnd}:(i=(i.ownerDocument&&i.ownerDocument.defaultView||window).getSelection(),i={anchorNode:i.anchorNode,anchorOffset:i.anchorOffset,focusNode:i.focusNode,focusOffset:i.focusOffset}),mi&&ui(mi,i)||(mi=i,i=jo($d,"onSelect"),0>=j,o-=j,nl=1<<32-ys(t)+o|l<ds?(Es=Ge,Ge=null):Es=Ge.sibling;var Bs=ce(X,Ge,te[ds],be);if(Bs===null){Ge===null&&(Ge=Es);break}s&&Ge&&Bs.alternate===null&&t(X,Ge),V=x(Bs,V,ds),$s===null?Ye=Bs:$s.sibling=Bs,$s=Bs,Ge=Es}if(ds===te.length)return l(X,Ge),As&&jl(X,ds),Ye;if(Ge===null){for(;dsds?(Es=Ge,Ge=null):Es=Ge.sibling;var un=ce(X,Ge,Bs.value,be);if(un===null){Ge===null&&(Ge=Es);break}s&&Ge&&un.alternate===null&&t(X,Ge),V=x(un,V,ds),$s===null?Ye=un:$s.sibling=un,$s=un,Ge=Es}if(Bs.done)return l(X,Ge),As&&jl(X,ds),Ye;if(Ge===null){for(;!Bs.done;ds++,Bs=te.next())Bs=ye(X,Bs.value,be),Bs!==null&&(V=x(Bs,V,ds),$s===null?Ye=Bs:$s.sibling=Bs,$s=Bs);return As&&jl(X,ds),Ye}for(Ge=i(Ge);!Bs.done;ds++,Bs=te.next())Bs=xe(Ge,X,ds,Bs.value,be),Bs!==null&&(s&&Bs.alternate!==null&&Ge.delete(Bs.key===null?ds:Bs.key),V=x(Bs,V,ds),$s===null?Ye=Bs:$s.sibling=Bs,$s=Bs);return s&&Ge.forEach(function(K0){return t(X,K0)}),As&&jl(X,ds),Ye}function Zs(X,V,te,be){if(typeof te=="object"&&te!==null&&te.type===O&&te.key===null&&(te=te.props.children),typeof te=="object"&&te!==null){switch(te.$$typeof){case b:e:{for(var Ye=te.key;V!==null;){if(V.key===Ye){if(Ye=te.type,Ye===O){if(V.tag===7){l(X,V.sibling),be=o(V,te.props.children),be.return=X,X=be;break e}}else if(V.elementType===Ye||typeof Ye=="object"&&Ye!==null&&Ye.$$typeof===J&&On(Ye)===V.type){l(X,V.sibling),be=o(V,te.props),ji(be,te),be.return=X,X=be;break e}l(X,V);break}else t(X,V);V=V.sibling}te.type===O?(be=Mn(te.props.children,X.mode,be,te.key),be.return=X,X=be):(be=Dc(te.type,te.key,te.props,null,X.mode,be),ji(be,te),be.return=X,X=be)}return j(X);case y:e:{for(Ye=te.key;V!==null;){if(V.key===Ye)if(V.tag===4&&V.stateNode.containerInfo===te.containerInfo&&V.stateNode.implementation===te.implementation){l(X,V.sibling),be=o(V,te.children||[]),be.return=X,X=be;break e}else{l(X,V);break}else t(X,V);V=V.sibling}be=qd(te,X.mode,be),be.return=X,X=be}return j(X);case J:return te=On(te),Zs(X,V,te,be)}if(ge(te))return He(X,V,te,be);if(je(te)){if(Ye=je(te),typeof Ye!="function")throw Error(c(150));return te=Ye.call(te),Ze(X,V,te,be)}if(typeof te.then=="function")return Zs(X,V,Ic(te),be);if(te.$$typeof===E)return Zs(X,V,Uc(X,te),be);Fc(X,te)}return typeof te=="string"&&te!==""||typeof te=="number"||typeof te=="bigint"?(te=""+te,V!==null&&V.tag===6?(l(X,V.sibling),be=o(V,te),be.return=X,X=be):(l(X,V),be=Gd(te,X.mode,be),be.return=X,X=be),j(X)):l(X,V)}return function(X,V,te,be){try{gi=0;var Ye=Zs(X,V,te,be);return wr=null,Ye}catch(Ge){if(Ge===yr||Ge===Bc)throw Ge;var $s=ba(29,Ge,null,X.mode);return $s.lanes=be,$s.return=X,$s}finally{}}}var Un=Dh(!0),Oh=Dh(!1),Kl=!1;function lu(s){s.updateQueue={baseState:s.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function nu(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 Ql(s){return{lane:s,tag:0,payload:null,callback:null,next:null}}function Yl(s,t,l){var i=s.updateQueue;if(i===null)return null;if(i=i.shared,(Is&2)!==0){var o=i.pending;return o===null?t.next=t:(t.next=o.next,o.next=t),i.pending=t,t=Rc(s),jh(s,null,l),t}return zc(s,i,t,l),Rc(s)}function vi(s,t,l){if(t=t.updateQueue,t!==null&&(t=t.shared,(l&4194048)!==0)){var i=t.lanes;i&=s.pendingLanes,l|=i,t.lanes=l,ea(s,l)}}function ru(s,t){var l=s.updateQueue,i=s.alternate;if(i!==null&&(i=i.updateQueue,l===i)){var o=null,x=null;if(l=l.firstBaseUpdate,l!==null){do{var j={lane:l.lane,tag:l.tag,payload:l.payload,callback:null,next:null};x===null?o=x=j:x=x.next=j,l=l.next}while(l!==null);x===null?o=x=t:x=x.next=t}else o=x=t;l={baseState:i.baseState,firstBaseUpdate:o,lastBaseUpdate:x,shared:i.shared,callbacks:i.callbacks},s.updateQueue=l;return}s=l.lastBaseUpdate,s===null?l.firstBaseUpdate=t:s.next=t,l.lastBaseUpdate=t}var iu=!1;function Ni(){if(iu){var s=br;if(s!==null)throw s}}function bi(s,t,l,i){iu=!1;var o=s.updateQueue;Kl=!1;var x=o.firstBaseUpdate,j=o.lastBaseUpdate,k=o.shared.pending;if(k!==null){o.shared.pending=null;var $=k,le=$.next;$.next=null,j===null?x=le:j.next=le,j=$;var ve=s.alternate;ve!==null&&(ve=ve.updateQueue,k=ve.lastBaseUpdate,k!==j&&(k===null?ve.firstBaseUpdate=le:k.next=le,ve.lastBaseUpdate=$))}if(x!==null){var ye=o.baseState;j=0,ve=le=$=null,k=x;do{var ce=k.lane&-536870913,xe=ce!==k.lane;if(xe?(Ts&ce)===ce:(i&ce)===ce){ce!==0&&ce===Nr&&(iu=!0),ve!==null&&(ve=ve.next={lane:0,tag:k.tag,payload:k.payload,callback:null,next:null});e:{var He=s,Ze=k;ce=t;var Zs=l;switch(Ze.tag){case 1:if(He=Ze.payload,typeof He=="function"){ye=He.call(Zs,ye,ce);break e}ye=He;break e;case 3:He.flags=He.flags&-65537|128;case 0:if(He=Ze.payload,ce=typeof He=="function"?He.call(Zs,ye,ce):He,ce==null)break e;ye=v({},ye,ce);break e;case 2:Kl=!0}}ce=k.callback,ce!==null&&(s.flags|=64,xe&&(s.flags|=8192),xe=o.callbacks,xe===null?o.callbacks=[ce]:xe.push(ce))}else xe={lane:ce,tag:k.tag,payload:k.payload,callback:k.callback,next:null},ve===null?(le=ve=xe,$=ye):ve=ve.next=xe,j|=ce;if(k=k.next,k===null){if(k=o.shared.pending,k===null)break;xe=k,k=xe.next,xe.next=null,o.lastBaseUpdate=xe,o.shared.pending=null}}while(!0);ve===null&&($=ye),o.baseState=$,o.firstBaseUpdate=le,o.lastBaseUpdate=ve,x===null&&(o.shared.lanes=0),en|=j,s.lanes=j,s.memoizedState=ye}}function Lh(s,t){if(typeof s!="function")throw Error(c(191,s));s.call(t)}function Uh(s,t){var l=s.callbacks;if(l!==null)for(s.callbacks=null,s=0;sx?x:8;var j=M.T,k={};M.T=k,ku(s,!1,t,l);try{var $=o(),le=M.S;if(le!==null&&le(k,$),$!==null&&typeof $=="object"&&typeof $.then=="function"){var ve=Ly($,i);_i(s,t,ve,ka(s))}else _i(s,t,i,ka(s))}catch(ye){_i(s,t,{then:function(){},status:"rejected",reason:ye},ka())}finally{K.p=x,j!==null&&k.types!==null&&(j.types=k.types),M.T=j}}function Fy(){}function _u(s,t,l,i){if(s.tag!==5)throw Error(c(476));var o=pf(s).queue;ff(s,o,t,P,l===null?Fy:function(){return gf(s),l(i)})}function pf(s){var t=s.memoizedState;if(t!==null)return t;t={memoizedState:P,baseState:P,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:yl,lastRenderedState:P},next:null};var l={};return t.next={memoizedState:l,baseState:l,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:yl,lastRenderedState:l},next:null},s.memoizedState=t,s=s.alternate,s!==null&&(s.memoizedState=t),t}function gf(s){var t=pf(s);t.next===null&&(t=s.alternate.memoizedState),_i(s,t.next.queue,{},ka())}function Su(){return Gt(Ii)}function jf(){return kt().memoizedState}function vf(){return kt().memoizedState}function Hy(s){for(var t=s.return;t!==null;){switch(t.tag){case 24:case 3:var l=ka();s=Ql(l);var i=Yl(t,s,l);i!==null&&(fa(i,t,l),vi(i,t,l)),t={cache:eu()},s.payload=t;return}t=t.return}}function Vy(s,t,l){var i=ka();l={lane:i,revertLane:0,gesture:null,action:l,hasEagerState:!1,eagerState:null,next:null},Zc(s)?bf(t,l):(l=Hd(s,t,l,i),l!==null&&(fa(l,s,i),yf(l,t,i)))}function Nf(s,t,l){var i=ka();_i(s,t,l,i)}function _i(s,t,l,i){var o={lane:i,revertLane:0,gesture:null,action:l,hasEagerState:!1,eagerState:null,next:null};if(Zc(s))bf(t,o);else{var x=s.alternate;if(s.lanes===0&&(x===null||x.lanes===0)&&(x=t.lastRenderedReducer,x!==null))try{var j=t.lastRenderedState,k=x(j,l);if(o.hasEagerState=!0,o.eagerState=k,Na(k,j))return zc(s,t,o,0),Ws===null&&Ac(),!1}catch{}finally{}if(l=Hd(s,t,o,i),l!==null)return fa(l,s,i),yf(l,t,i),!0}return!1}function ku(s,t,l,i){if(i={lane:2,revertLane:lm(),gesture:null,action:i,hasEagerState:!1,eagerState:null,next:null},Zc(s)){if(t)throw Error(c(479))}else t=Hd(s,l,i,2),t!==null&&fa(t,s,2)}function Zc(s){var t=s.alternate;return s===cs||t!==null&&t===cs}function bf(s,t){Sr=Gc=!0;var l=s.pending;l===null?t.next=t:(t.next=l.next,l.next=t),s.pending=t}function yf(s,t,l){if((l&4194048)!==0){var i=t.lanes;i&=s.pendingLanes,l|=i,t.lanes=l,ea(s,l)}}var Si={readContext:Gt,use:Qc,useCallback:vt,useContext:vt,useEffect:vt,useImperativeHandle:vt,useLayoutEffect:vt,useInsertionEffect:vt,useMemo:vt,useReducer:vt,useRef:vt,useState:vt,useDebugValue:vt,useDeferredValue:vt,useTransition:vt,useSyncExternalStore:vt,useId:vt,useHostTransitionStatus:vt,useFormState:vt,useActionState:vt,useOptimistic:vt,useMemoCache:vt,useCacheRefresh:vt};Si.useEffectEvent=vt;var wf={readContext:Gt,use:Qc,useCallback:function(s,t){return la().memoizedState=[s,t===void 0?null:t],s},useContext:Gt,useEffect:nf,useImperativeHandle:function(s,t,l){l=l!=null?l.concat([s]):null,Jc(4194308,4,df.bind(null,t,s),l)},useLayoutEffect:function(s,t){return Jc(4194308,4,s,t)},useInsertionEffect:function(s,t){Jc(4,2,s,t)},useMemo:function(s,t){var l=la();t=t===void 0?null:t;var i=s();if($n){ss(!0);try{s()}finally{ss(!1)}}return l.memoizedState=[i,t],i},useReducer:function(s,t,l){var i=la();if(l!==void 0){var o=l(t);if($n){ss(!0);try{l(t)}finally{ss(!1)}}}else o=t;return i.memoizedState=i.baseState=o,s={pending:null,lanes:0,dispatch:null,lastRenderedReducer:s,lastRenderedState:o},i.queue=s,s=s.dispatch=Vy.bind(null,cs,s),[i.memoizedState,s]},useRef:function(s){var t=la();return s={current:s},t.memoizedState=s},useState:function(s){s=vu(s);var t=s.queue,l=Nf.bind(null,cs,t);return t.dispatch=l,[s.memoizedState,l]},useDebugValue:yu,useDeferredValue:function(s,t){var l=la();return wu(l,s,t)},useTransition:function(){var s=vu(!1);return s=ff.bind(null,cs,s.queue,!0,!1),la().memoizedState=s,[!1,s]},useSyncExternalStore:function(s,t,l){var i=cs,o=la();if(As){if(l===void 0)throw Error(c(407));l=l()}else{if(l=t(),Ws===null)throw Error(c(349));(Ts&127)!==0||Hh(i,t,l)}o.memoizedState=l;var x={value:l,getSnapshot:t};return o.queue=x,nf(Gh.bind(null,i,x,s),[s]),i.flags|=2048,Cr(9,{destroy:void 0},Vh.bind(null,i,x,l,t),null),l},useId:function(){var s=la(),t=Ws.identifierPrefix;if(As){var l=rl,i=nl;l=(i&~(1<<32-ys(i)-1)).toString(32)+l,t="_"+t+"R_"+l,l=qc++,0<\/script>",x=x.removeChild(x.firstChild);break;case"select":x=typeof i.is=="string"?j.createElement("select",{is:i.is}):j.createElement("select"),i.multiple?x.multiple=!0:i.size&&(x.size=i.size);break;default:x=typeof i.is=="string"?j.createElement(o,{is:i.is}):j.createElement(o)}}x[js]=t,x[is]=i;e:for(j=t.child;j!==null;){if(j.tag===5||j.tag===6)x.appendChild(j.stateNode);else if(j.tag!==4&&j.tag!==27&&j.child!==null){j.child.return=j,j=j.child;continue}if(j===t)break e;for(;j.sibling===null;){if(j.return===null||j.return===t)break e;j=j.return}j.sibling.return=j.return,j=j.sibling}t.stateNode=x;e:switch(Kt(x,o,i),o){case"button":case"input":case"select":case"textarea":i=!!i.autoFocus;break e;case"img":i=!0;break e;default:i=!1}i&&_l(t)}}return ct(t),Pu(t,t.type,s===null?null:s.memoizedProps,t.pendingProps,l),null;case 6:if(s&&t.stateNode!=null)s.memoizedProps!==i&&_l(t);else{if(typeof i!="string"&&t.stateNode===null)throw Error(c(166));if(s=G.current,jr(t)){if(s=t.stateNode,l=t.memoizedProps,i=null,o=Vt,o!==null)switch(o.tag){case 27:case 5:i=o.memoizedProps}s[js]=t,s=!!(s.nodeValue===l||i!==null&&i.suppressHydrationWarning===!0||Fp(s.nodeValue,l)),s||Gl(t,!0)}else s=vo(s).createTextNode(i),s[js]=t,t.stateNode=s}return ct(t),null;case 31:if(l=t.memoizedState,s===null||s.memoizedState!==null){if(i=jr(t),l!==null){if(s===null){if(!i)throw Error(c(318));if(s=t.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(c(557));s[js]=t}else An(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;ct(t),s=!1}else l=Jd(),s!==null&&s.memoizedState!==null&&(s.memoizedState.hydrationErrors=l),s=!0;if(!s)return t.flags&256?(wa(t),t):(wa(t),null);if((t.flags&128)!==0)throw Error(c(558))}return ct(t),null;case 13:if(i=t.memoizedState,s===null||s.memoizedState!==null&&s.memoizedState.dehydrated!==null){if(o=jr(t),i!==null&&i.dehydrated!==null){if(s===null){if(!o)throw Error(c(318));if(o=t.memoizedState,o=o!==null?o.dehydrated:null,!o)throw Error(c(317));o[js]=t}else An(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;ct(t),o=!1}else o=Jd(),s!==null&&s.memoizedState!==null&&(s.memoizedState.hydrationErrors=o),o=!0;if(!o)return t.flags&256?(wa(t),t):(wa(t),null)}return wa(t),(t.flags&128)!==0?(t.lanes=l,t):(l=i!==null,s=s!==null&&s.memoizedState!==null,l&&(i=t.child,o=null,i.alternate!==null&&i.alternate.memoizedState!==null&&i.alternate.memoizedState.cachePool!==null&&(o=i.alternate.memoizedState.cachePool.pool),x=null,i.memoizedState!==null&&i.memoizedState.cachePool!==null&&(x=i.memoizedState.cachePool.pool),x!==o&&(i.flags|=2048)),l!==s&&l&&(t.child.flags|=8192),ao(t,t.updateQueue),ct(t),null);case 4:return W(),s===null&&cm(t.stateNode.containerInfo),ct(t),null;case 10:return Nl(t.type),ct(t),null;case 19:if(pe(St),i=t.memoizedState,i===null)return ct(t),null;if(o=(t.flags&128)!==0,x=i.rendering,x===null)if(o)Ci(i,!1);else{if(Nt!==0||s!==null&&(s.flags&128)!==0)for(s=t.child;s!==null;){if(x=Vc(s),x!==null){for(t.flags|=128,Ci(i,!1),s=x.updateQueue,t.updateQueue=s,ao(t,s),t.subtreeFlags=0,s=l,l=t.child;l!==null;)vh(l,s),l=l.sibling;return Te(St,St.current&1|2),As&&jl(t,i.treeForkCount),t.child}s=s.sibling}i.tail!==null&&mt()>co&&(t.flags|=128,o=!0,Ci(i,!1),t.lanes=4194304)}else{if(!o)if(s=Vc(x),s!==null){if(t.flags|=128,o=!0,s=s.updateQueue,t.updateQueue=s,ao(t,s),Ci(i,!0),i.tail===null&&i.tailMode==="hidden"&&!x.alternate&&!As)return ct(t),null}else 2*mt()-i.renderingStartTime>co&&l!==536870912&&(t.flags|=128,o=!0,Ci(i,!1),t.lanes=4194304);i.isBackwards?(x.sibling=t.child,t.child=x):(s=i.last,s!==null?s.sibling=x:t.child=x,i.last=x)}return i.tail!==null?(s=i.tail,i.rendering=s,i.tail=s.sibling,i.renderingStartTime=mt(),s.sibling=null,l=St.current,Te(St,o?l&1|2:l&1),As&&jl(t,i.treeForkCount),s):(ct(t),null);case 22:case 23:return wa(t),ou(),i=t.memoizedState!==null,s!==null?s.memoizedState!==null!==i&&(t.flags|=8192):i&&(t.flags|=8192),i?(l&536870912)!==0&&(t.flags&128)===0&&(ct(t),t.subtreeFlags&6&&(t.flags|=8192)):ct(t),l=t.updateQueue,l!==null&&ao(t,l.retryQueue),l=null,s!==null&&s.memoizedState!==null&&s.memoizedState.cachePool!==null&&(l=s.memoizedState.cachePool.pool),i=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(i=t.memoizedState.cachePool.pool),i!==l&&(t.flags|=2048),s!==null&&pe(Dn),null;case 24:return l=null,s!==null&&(l=s.memoizedState.cache),t.memoizedState.cache!==l&&(t.flags|=2048),Nl(Mt),ct(t),null;case 25:return null;case 30:return null}throw Error(c(156,t.tag))}function Yy(s,t){switch(Qd(t),t.tag){case 1:return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 3:return Nl(Mt),W(),s=t.flags,(s&65536)!==0&&(s&128)===0?(t.flags=s&-65537|128,t):null;case 26:case 27:case 5:return Fe(t),null;case 31:if(t.memoizedState!==null){if(wa(t),t.alternate===null)throw Error(c(340));An()}return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 13:if(wa(t),s=t.memoizedState,s!==null&&s.dehydrated!==null){if(t.alternate===null)throw Error(c(340));An()}return s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 19:return pe(St),null;case 4:return W(),null;case 10:return Nl(t.type),null;case 22:case 23:return wa(t),ou(),s!==null&&pe(Dn),s=t.flags,s&65536?(t.flags=s&-65537|128,t):null;case 24:return Nl(Mt),null;case 25:return null;default:return null}}function Kf(s,t){switch(Qd(t),t.tag){case 3:Nl(Mt),W();break;case 26:case 27:case 5:Fe(t);break;case 4:W();break;case 31:t.memoizedState!==null&&wa(t);break;case 13:wa(t);break;case 19:pe(St);break;case 10:Nl(t.type);break;case 22:case 23:wa(t),ou(),s!==null&&pe(Dn);break;case 24:Nl(Mt)}}function Ti(s,t){try{var l=t.updateQueue,i=l!==null?l.lastEffect:null;if(i!==null){var o=i.next;l=o;do{if((l.tag&s)===s){i=void 0;var x=l.create,j=l.inst;i=x(),j.destroy=i}l=l.next}while(l!==o)}}catch(k){Gs(t,t.return,k)}}function Zl(s,t,l){try{var i=t.updateQueue,o=i!==null?i.lastEffect:null;if(o!==null){var x=o.next;i=x;do{if((i.tag&s)===s){var j=i.inst,k=j.destroy;if(k!==void 0){j.destroy=void 0,o=t;var $=l,le=k;try{le()}catch(ve){Gs(o,$,ve)}}}i=i.next}while(i!==x)}}catch(ve){Gs(t,t.return,ve)}}function Qf(s){var t=s.updateQueue;if(t!==null){var l=s.stateNode;try{Uh(t,l)}catch(i){Gs(s,s.return,i)}}}function Yf(s,t,l){l.props=Bn(s.type,s.memoizedProps),l.state=s.memoizedState;try{l.componentWillUnmount()}catch(i){Gs(s,t,i)}}function Ei(s,t){try{var l=s.ref;if(l!==null){switch(s.tag){case 26:case 27:case 5:var i=s.stateNode;break;case 30:i=s.stateNode;break;default:i=s.stateNode}typeof l=="function"?s.refCleanup=l(i):l.current=i}}catch(o){Gs(s,t,o)}}function il(s,t){var l=s.ref,i=s.refCleanup;if(l!==null)if(typeof i=="function")try{i()}catch(o){Gs(s,t,o)}finally{s.refCleanup=null,s=s.alternate,s!=null&&(s.refCleanup=null)}else if(typeof l=="function")try{l(null)}catch(o){Gs(s,t,o)}else l.current=null}function Jf(s){var t=s.type,l=s.memoizedProps,i=s.stateNode;try{e:switch(t){case"button":case"input":case"select":case"textarea":l.autoFocus&&i.focus();break e;case"img":l.src?i.src=l.src:l.srcSet&&(i.srcset=l.srcSet)}}catch(o){Gs(s,s.return,o)}}function Iu(s,t,l){try{var i=s.stateNode;g0(i,s.type,l,t),i[is]=t}catch(o){Gs(s,s.return,o)}}function Xf(s){return s.tag===5||s.tag===3||s.tag===26||s.tag===27&&nn(s.type)||s.tag===4}function Fu(s){e:for(;;){for(;s.sibling===null;){if(s.return===null||Xf(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&&nn(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 Hu(s,t,l){var i=s.tag;if(i===5||i===6)s=s.stateNode,t?(l.nodeType===9?l.body:l.nodeName==="HTML"?l.ownerDocument.body:l).insertBefore(s,t):(t=l.nodeType===9?l.body:l.nodeName==="HTML"?l.ownerDocument.body:l,t.appendChild(s),l=l._reactRootContainer,l!=null||t.onclick!==null||(t.onclick=fl));else if(i!==4&&(i===27&&nn(s.type)&&(l=s.stateNode,t=null),s=s.child,s!==null))for(Hu(s,t,l),s=s.sibling;s!==null;)Hu(s,t,l),s=s.sibling}function lo(s,t,l){var i=s.tag;if(i===5||i===6)s=s.stateNode,t?l.insertBefore(s,t):l.appendChild(s);else if(i!==4&&(i===27&&nn(s.type)&&(l=s.stateNode),s=s.child,s!==null))for(lo(s,t,l),s=s.sibling;s!==null;)lo(s,t,l),s=s.sibling}function Zf(s){var t=s.stateNode,l=s.memoizedProps;try{for(var i=s.type,o=t.attributes;o.length;)t.removeAttributeNode(o[0]);Kt(t,i,l),t[js]=s,t[is]=l}catch(x){Gs(s,s.return,x)}}var Sl=!1,Rt=!1,Vu=!1,Wf=typeof WeakSet=="function"?WeakSet:Set,It=null;function Jy(s,t){if(s=s.containerInfo,um=ko,s=dh(s),Ud(s)){if("selectionStart"in s)var l={start:s.selectionStart,end:s.selectionEnd};else e:{l=(l=s.ownerDocument)&&l.defaultView||window;var i=l.getSelection&&l.getSelection();if(i&&i.rangeCount!==0){l=i.anchorNode;var o=i.anchorOffset,x=i.focusNode;i=i.focusOffset;try{l.nodeType,x.nodeType}catch{l=null;break e}var j=0,k=-1,$=-1,le=0,ve=0,ye=s,ce=null;s:for(;;){for(var xe;ye!==l||o!==0&&ye.nodeType!==3||(k=j+o),ye!==x||i!==0&&ye.nodeType!==3||($=j+i),ye.nodeType===3&&(j+=ye.nodeValue.length),(xe=ye.firstChild)!==null;)ce=ye,ye=xe;for(;;){if(ye===s)break s;if(ce===l&&++le===o&&(k=j),ce===x&&++ve===i&&($=j),(xe=ye.nextSibling)!==null)break;ye=ce,ce=ye.parentNode}ye=xe}l=k===-1||$===-1?null:{start:k,end:$}}else l=null}l=l||{start:0,end:0}}else l=null;for(mm={focusedElem:s,selectionRange:l},ko=!1,It=t;It!==null;)if(t=It,s=t.child,(t.subtreeFlags&1028)!==0&&s!==null)s.return=t,It=s;else for(;It!==null;){switch(t=It,x=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(l=0;l title"))),Kt(x,i,l),x[js]=s,Pt(x),i=x;break e;case"link":var j=ng("link","href",o).get(i+(l.href||""));if(j){for(var k=0;kZs&&(j=Zs,Zs=Ze,Ze=j);var X=ch(k,Ze),V=ch(k,Zs);if(X&&V&&(xe.rangeCount!==1||xe.anchorNode!==X.node||xe.anchorOffset!==X.offset||xe.focusNode!==V.node||xe.focusOffset!==V.offset)){var te=ye.createRange();te.setStart(X.node,X.offset),xe.removeAllRanges(),Ze>Zs?(xe.addRange(te),xe.extend(V.node,V.offset)):(te.setEnd(V.node,V.offset),xe.addRange(te))}}}}for(ye=[],xe=k;xe=xe.parentNode;)xe.nodeType===1&&ye.push({element:xe,left:xe.scrollLeft,top:xe.scrollTop});for(typeof k.focus=="function"&&k.focus(),k=0;kl?32:l,M.T=null,l=Xu,Xu=null;var x=tn,j=Ml;if(Ot=0,zr=tn=null,Ml=0,(Is&6)!==0)throw Error(c(331));var k=Is;if(Is|=4,dp(x.current),ip(x,x.current,j,l),Is=k,Oi(0,!1),ls&&typeof ls.onPostCommitFiberRoot=="function")try{ls.onPostCommitFiberRoot(bs,x)}catch{}return!0}finally{K.p=o,M.T=i,Tp(s,t)}}function Mp(s,t,l){t=Ba(l,t),t=Mu(s.stateNode,t,2),s=Yl(s,t,2),s!==null&&(Le(s,2),cl(s))}function Gs(s,t,l){if(s.tag===3)Mp(s,s,l);else for(;t!==null;){if(t.tag===3){Mp(t,s,l);break}else if(t.tag===1){var i=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof i.componentDidCatch=="function"&&(sn===null||!sn.has(i))){s=Ba(l,s),l=Af(2),i=Yl(t,l,2),i!==null&&(zf(l,i,t,s),Le(i,2),cl(i));break}}t=t.return}}function sm(s,t,l){var i=s.pingCache;if(i===null){i=s.pingCache=new Wy;var o=new Set;i.set(t,o)}else o=i.get(t),o===void 0&&(o=new Set,i.set(t,o));o.has(l)||(Ku=!0,o.add(l),s=l0.bind(null,s,t,l),t.then(s,s))}function l0(s,t,l){var i=s.pingCache;i!==null&&i.delete(t),s.pingedLanes|=s.suspendedLanes&l,s.warmLanes&=~l,Ws===s&&(Ts&l)===l&&(Nt===4||Nt===3&&(Ts&62914560)===Ts&&300>mt()-io?(Is&2)===0&&Rr(s,0):Qu|=l,Ar===Ts&&(Ar=0)),cl(s)}function Ap(s,t){t===0&&(t=se()),s=En(s,t),s!==null&&(Le(s,t),cl(s))}function n0(s){var t=s.memoizedState,l=0;t!==null&&(l=t.retryLane),Ap(s,l)}function r0(s,t){var l=0;switch(s.tag){case 31:case 13:var i=s.stateNode,o=s.memoizedState;o!==null&&(l=o.retryLane);break;case 19:i=s.stateNode;break;case 22:i=s.stateNode._retryCache;break;default:throw Error(c(314))}i!==null&&i.delete(t),Ap(s,l)}function i0(s,t){return Ut(s,t)}var fo=null,Or=null,tm=!1,po=!1,am=!1,ln=0;function cl(s){s!==Or&&s.next===null&&(Or===null?fo=Or=s:Or=Or.next=s),po=!0,tm||(tm=!0,o0())}function Oi(s,t){if(!am&&po){am=!0;do for(var l=!1,i=fo;i!==null;){if(s!==0){var o=i.pendingLanes;if(o===0)var x=0;else{var j=i.suspendedLanes,k=i.pingedLanes;x=(1<<31-ys(42|s)+1)-1,x&=o&~(j&~k),x=x&201326741?x&201326741|1:x?x|2:0}x!==0&&(l=!0,Op(i,x))}else x=Ts,x=ll(i,i===Ws?x:0,i.cancelPendingCommit!==null||i.timeoutHandle!==-1),(x&3)===0||xl(i,x)||(l=!0,Op(i,x));i=i.next}while(l);am=!1}}function c0(){zp()}function zp(){po=tm=!1;var s=0;ln!==0&&v0()&&(s=ln);for(var t=mt(),l=null,i=fo;i!==null;){var o=i.next,x=Rp(i,t);x===0?(i.next=null,l===null?fo=o:l.next=o,o===null&&(Or=l)):(l=i,(s!==0||(x&3)!==0)&&(po=!0)),i=o}Ot!==0&&Ot!==5||Oi(s),ln!==0&&(ln=0)}function Rp(s,t){for(var l=s.suspendedLanes,i=s.pingedLanes,o=s.expirationTimes,x=s.pendingLanes&-62914561;0k)break;var ve=$.transferSize,ye=$.initiatorType;ve&&Hp(ye)&&($=$.responseEnd,j+=ve*($"u"?null:document;function sg(s,t,l){var i=Lr;if(i&&typeof t=="string"&&t){var o=Ua(t);o='link[rel="'+s+'"][href="'+o+'"]',typeof l=="string"&&(o+='[crossorigin="'+l+'"]'),eg.has(o)||(eg.add(o),s={rel:s,crossOrigin:l,href:t},i.querySelector(o)===null&&(t=i.createElement("link"),Kt(t,"link",s),Pt(t),i.head.appendChild(t)))}}function T0(s){Al.D(s),sg("dns-prefetch",s,null)}function E0(s,t){Al.C(s,t),sg("preconnect",s,t)}function M0(s,t,l){Al.L(s,t,l);var i=Lr;if(i&&s&&t){var o='link[rel="preload"][as="'+Ua(t)+'"]';t==="image"&&l&&l.imageSrcSet?(o+='[imagesrcset="'+Ua(l.imageSrcSet)+'"]',typeof l.imageSizes=="string"&&(o+='[imagesizes="'+Ua(l.imageSizes)+'"]')):o+='[href="'+Ua(s)+'"]';var x=o;switch(t){case"style":x=Ur(s);break;case"script":x=$r(s)}Ga.has(x)||(s=v({rel:"preload",href:t==="image"&&l&&l.imageSrcSet?void 0:s,as:t},l),Ga.set(x,s),i.querySelector(o)!==null||t==="style"&&i.querySelector(Bi(x))||t==="script"&&i.querySelector(Pi(x))||(t=i.createElement("link"),Kt(t,"link",s),Pt(t),i.head.appendChild(t)))}}function A0(s,t){Al.m(s,t);var l=Lr;if(l&&s){var i=t&&typeof t.as=="string"?t.as:"script",o='link[rel="modulepreload"][as="'+Ua(i)+'"][href="'+Ua(s)+'"]',x=o;switch(i){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":x=$r(s)}if(!Ga.has(x)&&(s=v({rel:"modulepreload",href:s},t),Ga.set(x,s),l.querySelector(o)===null)){switch(i){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(l.querySelector(Pi(x)))return}i=l.createElement("link"),Kt(i,"link",s),Pt(i),l.head.appendChild(i)}}}function z0(s,t,l){Al.S(s,t,l);var i=Lr;if(i&&s){var o=nr(i).hoistableStyles,x=Ur(s);t=t||"default";var j=o.get(x);if(!j){var k={loading:0,preload:null};if(j=i.querySelector(Bi(x)))k.loading=5;else{s=v({rel:"stylesheet",href:s,"data-precedence":t},l),(l=Ga.get(x))&&vm(s,l);var $=j=i.createElement("link");Pt($),Kt($,"link",s),$._p=new Promise(function(le,ve){$.onload=le,$.onerror=ve}),$.addEventListener("load",function(){k.loading|=1}),$.addEventListener("error",function(){k.loading|=2}),k.loading|=4,bo(j,t,i)}j={type:"stylesheet",instance:j,count:1,state:k},o.set(x,j)}}}function R0(s,t){Al.X(s,t);var l=Lr;if(l&&s){var i=nr(l).hoistableScripts,o=$r(s),x=i.get(o);x||(x=l.querySelector(Pi(o)),x||(s=v({src:s,async:!0},t),(t=Ga.get(o))&&Nm(s,t),x=l.createElement("script"),Pt(x),Kt(x,"link",s),l.head.appendChild(x)),x={type:"script",instance:x,count:1,state:null},i.set(o,x))}}function D0(s,t){Al.M(s,t);var l=Lr;if(l&&s){var i=nr(l).hoistableScripts,o=$r(s),x=i.get(o);x||(x=l.querySelector(Pi(o)),x||(s=v({src:s,async:!0,type:"module"},t),(t=Ga.get(o))&&Nm(s,t),x=l.createElement("script"),Pt(x),Kt(x,"link",s),l.head.appendChild(x)),x={type:"script",instance:x,count:1,state:null},i.set(o,x))}}function tg(s,t,l,i){var o=(o=G.current)?No(o):null;if(!o)throw Error(c(446));switch(s){case"meta":case"title":return null;case"style":return typeof l.precedence=="string"&&typeof l.href=="string"?(t=Ur(l.href),l=nr(o).hoistableStyles,i=l.get(t),i||(i={type:"style",instance:null,count:0,state:null},l.set(t,i)),i):{type:"void",instance:null,count:0,state:null};case"link":if(l.rel==="stylesheet"&&typeof l.href=="string"&&typeof l.precedence=="string"){s=Ur(l.href);var x=nr(o).hoistableStyles,j=x.get(s);if(j||(o=o.ownerDocument||o,j={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},x.set(s,j),(x=o.querySelector(Bi(s)))&&!x._p&&(j.instance=x,j.state.loading=5),Ga.has(s)||(l={rel:"preload",as:"style",href:l.href,crossOrigin:l.crossOrigin,integrity:l.integrity,media:l.media,hrefLang:l.hrefLang,referrerPolicy:l.referrerPolicy},Ga.set(s,l),x||O0(o,s,l,j.state))),t&&i===null)throw Error(c(528,""));return j}if(t&&i!==null)throw Error(c(529,""));return null;case"script":return t=l.async,l=l.src,typeof l=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=$r(l),l=nr(o).hoistableScripts,i=l.get(t),i||(i={type:"script",instance:null,count:0,state:null},l.set(t,i)),i):{type:"void",instance:null,count:0,state:null};default:throw Error(c(444,s))}}function Ur(s){return'href="'+Ua(s)+'"'}function Bi(s){return'link[rel="stylesheet"]['+s+"]"}function ag(s){return v({},s,{"data-precedence":s.precedence,precedence:null})}function O0(s,t,l,i){s.querySelector('link[rel="preload"][as="style"]['+t+"]")?i.loading=1:(t=s.createElement("link"),i.preload=t,t.addEventListener("load",function(){return i.loading|=1}),t.addEventListener("error",function(){return i.loading|=2}),Kt(t,"link",l),Pt(t),s.head.appendChild(t))}function $r(s){return'[src="'+Ua(s)+'"]'}function Pi(s){return"script[async]"+s}function lg(s,t,l){if(t.count++,t.instance===null)switch(t.type){case"style":var i=s.querySelector('style[data-href~="'+Ua(l.href)+'"]');if(i)return t.instance=i,Pt(i),i;var o=v({},l,{"data-href":l.href,"data-precedence":l.precedence,href:null,precedence:null});return i=(s.ownerDocument||s).createElement("style"),Pt(i),Kt(i,"style",o),bo(i,l.precedence,s),t.instance=i;case"stylesheet":o=Ur(l.href);var x=s.querySelector(Bi(o));if(x)return t.state.loading|=4,t.instance=x,Pt(x),x;i=ag(l),(o=Ga.get(o))&&vm(i,o),x=(s.ownerDocument||s).createElement("link"),Pt(x);var j=x;return j._p=new Promise(function(k,$){j.onload=k,j.onerror=$}),Kt(x,"link",i),t.state.loading|=4,bo(x,l.precedence,s),t.instance=x;case"script":return x=$r(l.src),(o=s.querySelector(Pi(x)))?(t.instance=o,Pt(o),o):(i=l,(o=Ga.get(x))&&(i=v({},l),Nm(i,o)),s=s.ownerDocument||s,o=s.createElement("script"),Pt(o),Kt(o,"link",i),s.head.appendChild(o),t.instance=o);case"void":return null;default:throw Error(c(443,t.type))}else t.type==="stylesheet"&&(t.state.loading&4)===0&&(i=t.instance,t.state.loading|=4,bo(i,l.precedence,s));return t.instance}function bo(s,t,l){for(var i=l.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),o=i.length?i[i.length-1]:null,x=o,j=0;j title"):null)}function L0(s,t,l){if(l===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 ig(s){return!(s.type==="stylesheet"&&(s.state.loading&3)===0)}function U0(s,t,l,i){if(l.type==="stylesheet"&&(typeof i.media!="string"||matchMedia(i.media).matches!==!1)&&(l.state.loading&4)===0){if(l.instance===null){var o=Ur(i.href),x=t.querySelector(Bi(o));if(x){t=x._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(s.count++,s=wo.bind(s),t.then(s,s)),l.state.loading|=4,l.instance=x,Pt(x);return}x=t.ownerDocument||t,i=ag(i),(o=Ga.get(o))&&vm(i,o),x=x.createElement("link"),Pt(x);var j=x;j._p=new Promise(function(k,$){j.onload=k,j.onerror=$}),Kt(x,"link",i),l.instance=x}s.stylesheets===null&&(s.stylesheets=new Map),s.stylesheets.set(l,t),(t=l.state.preload)&&(l.state.loading&3)===0&&(s.count++,l=wo.bind(s),t.addEventListener("load",l),t.addEventListener("error",l))}}var bm=0;function $0(s,t){return s.stylesheets&&s.count===0&&So(s,s.stylesheets),0bm?50:800)+t);return s.unsuspend=l,function(){s.unsuspend=null,clearTimeout(i),clearTimeout(o)}}:null}function wo(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)So(this,this.stylesheets);else if(this.unsuspend){var s=this.unsuspend;this.unsuspend=null,s()}}}var _o=null;function So(s,t){s.stylesheets=null,s.unsuspend!==null&&(s.count++,_o=new Map,t.forEach(B0,s),_o=null,wo.call(s))}function B0(s,t){if(!(t.state.loading&4)){var l=_o.get(s);if(l)var i=l.get(null);else{l=new Map,_o.set(s,l);for(var o=s.querySelectorAll("link[data-precedence],style[data-precedence]"),x=0;x"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(a)}catch(n){console.error(n)}}return a(),Am.exports=E1(),Am.exports}var A1=M1();function I(...a){return nw(rw(a))}const Ce=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:I("rounded-xl border bg-card text-card-foreground shadow",a),...n}));Ce.displayName="Card";const De=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:I("flex flex-col space-y-1.5 p-6",a),...n}));De.displayName="CardHeader";const Oe=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:I("font-semibold leading-none tracking-tight",a),...n}));Oe.displayName="CardTitle";const os=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:I("text-sm text-muted-foreground",a),...n}));os.displayName="CardDescription";const Me=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:I("p-6 pt-0",a),...n}));Me.displayName="CardContent";const id=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:I("flex items-center p-6 pt-0",a),...n}));id.displayName="CardFooter";const ta=cw,Zt=m.forwardRef(({className:a,...n},r)=>e.jsx(ij,{ref:r,className:I("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",a),...n}));Zt.displayName=ij.displayName;const Xe=m.forwardRef(({className:a,...n},r)=>e.jsx(cj,{ref:r,className:I("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",a),...n}));Xe.displayName=cj.displayName;const ws=m.forwardRef(({className:a,...n},r)=>e.jsx(oj,{ref:r,className:I("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",a),...n}));ws.displayName=oj.displayName;const Je=m.forwardRef(({className:a,children:n,viewportRef:r,...c},d)=>e.jsxs(dj,{ref:d,className:I("relative overflow-hidden",a),...c,children:[e.jsx(ow,{ref:r,className:"h-full w-full rounded-[inherit]",children:n}),e.jsx(Km,{}),e.jsx(Km,{orientation:"horizontal"}),e.jsx(dw,{})]}));Je.displayName=dj.displayName;const Km=m.forwardRef(({className:a,orientation:n="vertical",...r},c)=>e.jsx(uj,{ref:c,orientation:n,className:I("flex touch-none select-none transition-colors",n==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",n==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",a),...r,children:e.jsx(uw,{className:"relative flex-1 rounded-full bg-border"})}));Km.displayName=uj.displayName;function vs({className:a,...n}){return e.jsx("div",{className:I("animate-pulse rounded-md bg-primary/10",a),...n})}const Xn=m.forwardRef(({className:a,value:n,...r},c)=>e.jsx(mj,{ref:c,className:I("relative h-2 w-full overflow-hidden rounded-full bg-primary/20",a),...r,children:e.jsx(mw,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(n||0)}%)`}})}));Xn.displayName=mj.displayName;async function _e(a,n){const c=n?.body instanceof FormData?{...n?.headers}:{"Content-Type":"application/json",...n?.headers},d={...n,credentials:"include",headers:c},u=await fetch(a,d);if(u.status===401)throw window.location.href="/auth",new Error("认证失败,请重新登录");return u}function Hs(){return{"Content-Type":"application/json"}}async function z1(){try{await fetch("/api/webui/auth/logout",{method:"POST",credentials:"include"})}catch(a){console.error("登出请求失败:",a)}window.location.href="/auth"}async function cc(){try{return(await(await fetch("/api/webui/auth/check",{method:"GET",credentials:"include"})).json()).authenticated===!0}catch{return!1}}const R1={light:"",dark:".dark"},wv=m.createContext(null);function _v(){const a=m.useContext(wv);if(!a)throw new Error("useChart must be used within a ");return a}const Vr=m.forwardRef(({id:a,className:n,children:r,config:c,...d},u)=>{const h=m.useId(),f=`chart-${a||h.replace(/:/g,"")}`;return e.jsx(wv.Provider,{value:{config:c},children:e.jsxs("div",{"data-chart":f,ref:u,className:I("flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",n),...d,children:[e.jsx(D1,{id:f,config:c}),e.jsx(Mj,{children:r})]})})});Vr.displayName="Chart";const D1=({id:a,config:n})=>{const r=Object.entries(n).filter(([,c])=>c.theme||c.color);return r.length?e.jsx("style",{dangerouslySetInnerHTML:{__html:Object.entries(R1).map(([c,d])=>` -${d} [data-chart=${a}] { -${r.map(([u,h])=>{const f=h.theme?.[c]||h.color;return f?` --color-${u}: ${f};`:null}).join(` -`)} -} -`).join(` -`)}}):null},qi=Aj,Gr=m.forwardRef(({active:a,payload:n,className:r,indicator:c="dot",hideLabel:d=!1,hideIndicator:u=!1,label:h,labelFormatter:f,labelClassName:p,formatter:g,color:N,nameKey:v,labelKey:w},b)=>{const{config:y}=_v(),O=m.useMemo(()=>{if(d||!n?.length)return null;const[S]=n,B=`${w||S?.dataKey||S?.name||"value"}`,E=Qm(y,S,B),C=!w&&typeof h=="string"?y[h]?.label||h:E?.label;return f?e.jsx("div",{className:I("font-medium",p),children:f(C,n)}):C?e.jsx("div",{className:I("font-medium",p),children:C}):null},[h,f,n,d,p,y,w]);if(!a||!n?.length)return null;const R=n.length===1&&c!=="dot";return e.jsxs("div",{ref:b,className:I("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",r),children:[R?null:O,e.jsx("div",{className:"grid gap-1.5",children:n.filter(S=>S.type!=="none").map((S,B)=>{const E=`${v||S.name||S.dataKey||"value"}`,C=Qm(y,S,E),A=N||S.payload.fill||S.color;return e.jsx("div",{className:I("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",c==="dot"&&"items-center"),children:g&&S?.value!==void 0&&S.name?g(S.value,S.name,S,B,S.payload):e.jsxs(e.Fragment,{children:[C?.icon?e.jsx(C.icon,{}):!u&&e.jsx("div",{className:I("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":c==="dot","w-1":c==="line","w-0 border-[1.5px] border-dashed bg-transparent":c==="dashed","my-0.5":R&&c==="dashed"}),style:{"--color-bg":A,"--color-border":A}}),e.jsxs("div",{className:I("flex flex-1 justify-between leading-none",R?"items-end":"items-center"),children:[e.jsxs("div",{className:"grid gap-1.5",children:[R?O:null,e.jsx("span",{className:"text-muted-foreground",children:C?.label||S.name})]}),S.value&&e.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:S.value.toLocaleString()})]})]})},S.dataKey)})})]})});Gr.displayName="ChartTooltip";const O1=Vw,Sv=m.forwardRef(({className:a,hideIcon:n=!1,payload:r,verticalAlign:c="bottom",nameKey:d},u)=>{const{config:h}=_v();return r?.length?e.jsx("div",{ref:u,className:I("flex items-center justify-center gap-4",c==="top"?"pb-3":"pt-3",a),children:r.filter(f=>f.type!=="none").map(f=>{const p=`${d||f.dataKey||"value"}`,g=Qm(h,f,p);return e.jsxs("div",{className:I("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[g?.icon&&!n?e.jsx(g.icon,{}):e.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:f.color}}),g?.label]},f.value)})}):null});Sv.displayName="ChartLegend";function Qm(a,n,r){if(typeof n!="object"||n===null)return;const c="payload"in n&&typeof n.payload=="object"&&n.payload!==null?n.payload:void 0;let d=r;return r in n&&typeof n[r]=="string"?d=n[r]:c&&r in c&&typeof c[r]=="string"&&(d=c[r]),d in a?a[d]:a[r]}const Zr=Wr("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"}}),_=m.forwardRef(({className:a,variant:n,size:r,asChild:c=!1,...d},u)=>{const h=c?Jw:"button";return e.jsx(h,{className:I(Zr({variant:n,size:r,className:a})),ref:u,...d})});_.displayName="Button";const L1=Wr("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 ke({className:a,variant:n,...r}){return e.jsx("div",{className:I(L1({variant:n}),a),...r})}async function U1(){const a=await _e("/api/webui/system/restart",{method:"POST",headers:Hs()});if(!a.ok){const n=await a.json();throw new Error(n.detail||"重启失败")}return await a.json()}async function $1(){const a=await _e("/api/webui/system/status",{method:"GET",headers:Hs()});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取状态失败")}return await a.json()}const Pr={INITIAL_DELAY:3e3,CHECK_INTERVAL:2e3,CHECK_TIMEOUT:3e3,MAX_ATTEMPTS:60,PROGRESS_INTERVAL:200,SUCCESS_REDIRECT_DELAY:1500},kv=m.createContext(null);function Wn({children:a,onRestartComplete:n,onRestartFailed:r,healthCheckUrl:c="/api/webui/system/status",maxAttempts:d=Pr.MAX_ATTEMPTS}){const[u,h]=m.useState({status:"idle",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:d}),[f,p]=m.useState({}),g=m.useCallback(()=>{f.progress&&clearInterval(f.progress),f.elapsed&&clearInterval(f.elapsed),f.check&&clearTimeout(f.check),p({})},[f]),N=m.useCallback(()=>{g(),h({status:"idle",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:d})},[g,d]),v=m.useCallback(async()=>{try{const R=new AbortController,S=setTimeout(()=>R.abort(),Pr.CHECK_TIMEOUT),B=await fetch(c,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"include",signal:R.signal});return clearTimeout(S),B.ok}catch{return!1}},[c]),w=m.useCallback(()=>{let R=0;const S=async()=>{if(R++,h(E=>({...E,status:"checking",checkAttempts:R})),await v())g(),h(E=>({...E,status:"success",progress:100})),setTimeout(()=>{n?.(),window.location.href="/auth"},Pr.SUCCESS_REDIRECT_DELAY);else if(R>=d){g();const E=`健康检查超时 (${R}/${d})`;h(C=>({...C,status:"failed",error:E})),r?.(E)}else{const E=setTimeout(S,Pr.CHECK_INTERVAL);p(C=>({...C,check:E}))}};S()},[v,g,d,n,r]),b=m.useCallback(()=>{h(R=>({...R,status:"checking",checkAttempts:0,error:void 0})),w()},[w]),y=m.useCallback(async R=>{const{delay:S=0,skipApiCall:B=!1}=R??{};if(u.status!=="idle"&&u.status!=="failed")return;if(g(),h({status:"requesting",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:d}),S>0&&await new Promise(A=>setTimeout(A,S)),B)h(A=>({...A,status:"restarting"}));else try{h(A=>({...A,status:"restarting"})),await Promise.race([U1(),new Promise(A=>setTimeout(A,5e3))])}catch{}const E=setInterval(()=>{h(A=>({...A,progress:A.progress>=90?A.progress:A.progress+1}))},Pr.PROGRESS_INTERVAL),C=setInterval(()=>{h(A=>({...A,elapsedTime:A.elapsedTime+1}))},1e3);p({progress:E,elapsed:C}),setTimeout(()=>{w()},Pr.INITIAL_DELAY)},[u.status,g,d,w]),O={state:u,isRestarting:u.status!=="idle",triggerRestart:y,resetState:N,retryHealthCheck:b};return e.jsx(kv.Provider,{value:O,children:a})}function yn(){const a=m.useContext(kv);if(!a)throw new Error("useRestart must be used within a RestartProvider");return a}function B1(){try{return yn()}catch{return null}}const P1=(a,n,r,c,d)=>({idle:{icon:null,title:"",description:"",tip:""},requesting:{icon:e.jsx(zs,{className:"h-16 w-16 text-primary animate-spin"}),title:c??"准备重启",description:d??"正在发送重启请求...",tip:"🔄 正在准备重启麦麦..."},restarting:{icon:e.jsx(zs,{className:"h-16 w-16 text-primary animate-spin"}),title:c??"正在重启麦麦",description:d??"请稍候,麦麦正在重启中...",tip:"🔄 配置已保存,正在重启主程序..."},checking:{icon:e.jsx(zs,{className:"h-16 w-16 text-primary animate-spin"}),title:"检查服务状态",description:`等待服务恢复... (${n}/${r})`,tip:"⏳ 正在等待服务恢复,请勿关闭页面..."},success:{icon:e.jsx(pt,{className:"h-16 w-16 text-green-500"}),title:"重启成功",description:"正在跳转到登录页面...",tip:"✅ 配置已生效,服务运行正常"},failed:{icon:e.jsx(_t,{className:"h-16 w-16 text-destructive"}),title:"重启超时",description:"服务未能在预期时间内恢复",tip:"⚠️ 如果长时间无响应,请尝试手动重启"}})[a];function er({visible:a,onComplete:n,onFailed:r,title:c,description:d,showAnimation:u=!0,className:h}){const f=B1();return(f?f.isRestarting:a)?f?e.jsx(Cv,{state:f.state,onRetry:f.retryHealthCheck,onComplete:n,onFailed:r,title:c,description:d,showAnimation:u,className:h}):e.jsx(I1,{onComplete:n,onFailed:r,title:c,description:d,showAnimation:u,className:h}):null}function Cv({state:a,onRetry:n,onComplete:r,onFailed:c,title:d,description:u,showAnimation:h,className:f}){const{status:p,progress:g,elapsedTime:N,checkAttempts:v,maxAttempts:w}=a;m.useEffect(()=>{p==="success"&&r?r():p==="failed"&&c&&c()},[p,r,c]);const b=P1(p,v,w,d,u),y=O=>{const R=Math.floor(O/60),S=O%60;return`${R}:${S.toString().padStart(2,"0")}`};return e.jsxs("div",{className:I("fixed inset-0 bg-background/95 backdrop-blur-sm z-50 flex items-center justify-center",f),children:[h&&e.jsx(F1,{}),e.jsxs("div",{className:"max-w-md w-full mx-4 space-y-8 relative z-10",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsxs("div",{className:"relative",children:[b.icon,(p==="restarting"||p==="checking")&&e.jsx("div",{className:"absolute inset-0 rounded-full bg-primary/20 animate-ping"})]}),e.jsx("h2",{className:"text-2xl font-bold",children:b.title}),e.jsx("p",{className:"text-muted-foreground text-center",children:b.description})]}),p!=="failed"&&p!=="idle"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Xn,{value:g,className:"h-2"}),e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:[g,"%"]}),e.jsxs("span",{children:["已用时: ",y(N)]})]})]}),e.jsx("div",{className:"bg-muted/50 rounded-lg p-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:b.tip})}),p==="failed"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(_,{onClick:()=>window.location.reload(),variant:"default",className:"flex-1",children:[e.jsx(dt,{className:"mr-2 h-4 w-4"}),"刷新页面"]}),e.jsxs(_,{onClick:n,variant:"secondary",className:"flex-1",children:[e.jsx(lc,{className:"mr-2 h-4 w-4"}),"重试检测"]})]})]})]})}function I1({onComplete:a,onFailed:n,title:r,description:c,showAnimation:d,className:u}){const[h,f]=m.useState({status:"restarting",progress:0,elapsedTime:0,checkAttempts:0,maxAttempts:60}),p=m.useCallback(()=>{let g=0;const N=60,v=async()=>{g++,f(w=>({...w,status:"checking",checkAttempts:g}));try{if((await fetch("/api/webui/system/status",{method:"GET",signal:AbortSignal.timeout(3e3)})).ok){f(b=>({...b,status:"success",progress:100})),setTimeout(()=>{a?.(),window.location.href="/auth"},1500);return}}catch{}g>=N?(f(w=>({...w,status:"failed"})),n?.()):setTimeout(v,2e3)};v()},[a,n]);return m.useEffect(()=>{const g=setInterval(()=>{f(w=>({...w,progress:w.progress>=90?w.progress:w.progress+1}))},200),N=setInterval(()=>{f(w=>({...w,elapsedTime:w.elapsedTime+1}))},1e3),v=setTimeout(()=>{p()},3e3);return()=>{clearInterval(g),clearInterval(N),clearTimeout(v)}},[p]),e.jsx(Cv,{state:h,onRetry:p,onComplete:a,onFailed:n,title:r,description:c,showAnimation:d,className:u})}function F1(){return e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsxs("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[600px] h-[600px]",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border border-primary/10 animate-[ping_3s_ease-in-out_infinite]"}),e.jsx("div",{className:"absolute inset-8 rounded-full border border-primary/10 animate-[ping_3s_ease-in-out_infinite_0.5s]"}),e.jsx("div",{className:"absolute inset-16 rounded-full border border-primary/10 animate-[ping_3s_ease-in-out_infinite_1s]"})]}),e.jsx("div",{className:"absolute top-1/4 left-1/4 w-2 h-2 bg-primary/20 rounded-full animate-bounce"}),e.jsx("div",{className:"absolute top-3/4 right-1/4 w-3 h-3 bg-primary/15 rounded-full animate-bounce delay-150"}),e.jsx("div",{className:"absolute top-1/2 right-1/3 w-2 h-2 bg-primary/20 rounded-full animate-bounce delay-300"})]})}const Ps=Ww,cd=e_,H1=Xw,Tv=m.forwardRef(({className:a,...n},r)=>e.jsx(zj,{ref:r,className:I("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",a),...n}));Tv.displayName=zj.displayName;const Ds=m.forwardRef(({className:a,children:n,preventOutsideClose:r=!1,...c},d)=>e.jsxs(H1,{children:[e.jsx(Tv,{}),e.jsxs(Rj,{ref:d,className:I("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",a),onPointerDownOutside:r?u=>u.preventDefault():void 0,onInteractOutside:r?u=>u.preventDefault():void 0,...c,children:[n,e.jsxs(Zw,{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(Aa,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Ds.displayName=Rj.displayName;const Os=({className:a,...n})=>e.jsx("div",{className:I("flex flex-col space-y-1.5 text-center sm:text-left",a),...n});Os.displayName="DialogHeader";const st=({className:a,...n})=>e.jsx("div",{className:I("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",a),...n});st.displayName="DialogFooter";const Ls=m.forwardRef(({className:a,...n},r)=>e.jsx(Dj,{ref:r,className:I("text-lg font-semibold leading-none tracking-tight",a),...n}));Ls.displayName=Dj.displayName;const Ks=m.forwardRef(({className:a,...n},r)=>e.jsx(Oj,{ref:r,className:I("text-sm text-muted-foreground",a),...n}));Ks.displayName=Oj.displayName;const ae=m.forwardRef(({className:a,type:n,...r},c)=>e.jsx("input",{type:n,className:I("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",a),ref:c,...r}));ae.displayName="Input";const qs=m.forwardRef(({className:a,...n},r)=>e.jsx(Lj,{ref:r,className:I("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",a),...n,children:e.jsx(s_,{className:I("grid place-content-center text-current"),children:e.jsx(Ct,{className:"h-4 w-4"})})}));qs.displayName=Lj.displayName;const Pe=i_,Ie=c_,$e=m.forwardRef(({className:a,children:n,...r},c)=>e.jsxs(Uj,{ref:c,className:I("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",a),...r,children:[n,e.jsx(t_,{asChild:!0,children:e.jsx(za,{className:"h-4 w-4 opacity-50"})})]}));$e.displayName=Uj.displayName;const Ev=m.forwardRef(({className:a,...n},r)=>e.jsx($j,{ref:r,className:I("flex cursor-default items-center justify-center py-1",a),...n,children:e.jsx(Qr,{className:"h-4 w-4"})}));Ev.displayName=$j.displayName;const Mv=m.forwardRef(({className:a,...n},r)=>e.jsx(Bj,{ref:r,className:I("flex cursor-default items-center justify-center py-1",a),...n,children:e.jsx(za,{className:"h-4 w-4"})}));Mv.displayName=Bj.displayName;const Be=m.forwardRef(({className:a,children:n,position:r="popper",...c},d)=>e.jsx(a_,{children:e.jsxs(Pj,{ref:d,className:I("relative z-[100] max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-hidden rounded-md border border-border bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",r==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",a),position:r,...c,children:[e.jsx(Ev,{}),e.jsx(l_,{className:I("p-1",r==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),e.jsx(Mv,{})]})}));Be.displayName=Pj.displayName;const V1=m.forwardRef(({className:a,...n},r)=>e.jsx(Ij,{ref:r,className:I("px-2 py-1.5 text-sm font-semibold",a),...n}));V1.displayName=Ij.displayName;const Z=m.forwardRef(({className:a,children:n,...r},c)=>e.jsxs(Fj,{ref:c,className:I("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",a),...r,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(n_,{children:e.jsx(Ct,{className:"h-4 w-4"})})}),e.jsx(r_,{children:n})]}));Z.displayName=Fj.displayName;const G1=m.forwardRef(({className:a,...n},r)=>e.jsx(Hj,{ref:r,className:I("-mx-1 my-1 h-px bg-muted",a),...n}));G1.displayName=Hj.displayName;const ox=({className:a,...n})=>e.jsx("nav",{role:"navigation","aria-label":"pagination",className:I("mx-auto flex w-full justify-center",a),...n});ox.displayName="Pagination";const dx=m.forwardRef(({className:a,...n},r)=>e.jsx("ul",{ref:r,className:I("flex flex-row items-center gap-1",a),...n}));dx.displayName="PaginationContent";const qn=m.forwardRef(({className:a,...n},r)=>e.jsx("li",{ref:r,className:I("",a),...n}));qn.displayName="PaginationItem";const pc=({className:a,isActive:n,size:r="icon",...c})=>e.jsx("a",{"aria-current":n?"page":void 0,className:I(Zr({variant:n?"outline":"ghost",size:r}),a),...c});pc.displayName="PaginationLink";const Av=({className:a,...n})=>e.jsxs(pc,{"aria-label":"Go to previous page",size:"default",className:I("gap-1 pl-2.5",a),...n,children:[e.jsx(Da,{className:"h-4 w-4"}),e.jsx("span",{children:"上一页"})]});Av.displayName="PaginationPrevious";const zv=({className:a,...n})=>e.jsxs(pc,{"aria-label":"Go to next page",size:"default",className:I("gap-1 pr-2.5",a),...n,children:[e.jsx("span",{children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4"})]});zv.displayName="PaginationNext";const Rv=({className:a,...n})=>e.jsxs("span",{"aria-hidden":!0,className:I("flex h-9 w-9 items-center justify-center",a),...n,children:[e.jsx(v_,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More pages"})]});Rv.displayName="PaginationEllipsis";const q1=5,K1=5e3;let Dm=0;function Q1(){return Dm=(Dm+1)%Number.MAX_SAFE_INTEGER,Dm.toString()}const Om=new Map,Mg=a=>{if(Om.has(a))return;const n=setTimeout(()=>{Om.delete(a),sc({type:"REMOVE_TOAST",toastId:a})},K1);Om.set(a,n)},Y1=(a,n)=>{switch(n.type){case"ADD_TOAST":return{...a,toasts:[n.toast,...a.toasts].slice(0,q1)};case"UPDATE_TOAST":return{...a,toasts:a.toasts.map(r=>r.id===n.toast.id?{...r,...n.toast}:r)};case"DISMISS_TOAST":{const{toastId:r}=n;return r?Mg(r):a.toasts.forEach(c=>{Mg(c.id)}),{...a,toasts:a.toasts.map(c=>c.id===r||r===void 0?{...c,open:!1}:c)}}case"REMOVE_TOAST":return n.toastId===void 0?{...a,toasts:[]}:{...a,toasts:a.toasts.filter(r=>r.id!==n.toastId)}}},Po=[];let Io={toasts:[]};function sc(a){Io=Y1(Io,a),Po.forEach(n=>{n(Io)})}function Qt({...a}){const n=Q1(),r=d=>sc({type:"UPDATE_TOAST",toast:{...d,id:n}}),c=()=>sc({type:"DISMISS_TOAST",toastId:n});return sc({type:"ADD_TOAST",toast:{...a,id:n,open:!0,onOpenChange:d=>{d||c()}}}),{id:n,dismiss:c,update:r}}function Ys(){const[a,n]=m.useState(Io);return m.useEffect(()=>(Po.push(n),()=>{const r=Po.indexOf(n);r>-1&&Po.splice(r,1)}),[a]),{...a,toast:Qt,dismiss:r=>sc({type:"DISMISS_TOAST",toastId:r})}}const tl="/api/webui/expression";async function ux(){const a=await _e(`${tl}/chats`,{});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取聊天列表失败")}return a.json()}async function J1(a){const n=new URLSearchParams;a.page&&n.append("page",a.page.toString()),a.page_size&&n.append("page_size",a.page_size.toString()),a.search&&n.append("search",a.search),a.chat_id&&n.append("chat_id",a.chat_id);const r=await _e(`${tl}/list?${n}`,{});if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取表达方式列表失败")}return r.json()}async function X1(a){const n=await _e(`${tl}/${a}`,{});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取表达方式详情失败")}return n.json()}async function Z1(a){const n=await _e(`${tl}/`,{method:"POST",body:JSON.stringify(a)});if(!n.ok){const r=await n.json();throw new Error(r.detail||"创建表达方式失败")}return n.json()}async function W1(a,n){const r=await _e(`${tl}/${a}`,{method:"PATCH",body:JSON.stringify(n)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"更新表达方式失败")}return r.json()}async function e2(a){const n=await _e(`${tl}/${a}`,{method:"DELETE"});if(!n.ok){const r=await n.json();throw new Error(r.detail||"删除表达方式失败")}return n.json()}async function s2(a){const n=await _e(`${tl}/batch/delete`,{method:"POST",body:JSON.stringify({ids:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"批量删除表达方式失败")}return n.json()}async function t2(){const a=await _e(`${tl}/stats/summary`,{});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取统计数据失败")}return a.json()}async function mx(){const a=await _e(`${tl}/review/stats`);if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取审核统计失败")}return a.json()}async function a2(a){const n=new URLSearchParams;a.page&&n.append("page",a.page.toString()),a.page_size&&n.append("page_size",a.page_size.toString()),a.filter_type&&n.append("filter_type",a.filter_type),a.search&&n.append("search",a.search),a.chat_id&&n.append("chat_id",a.chat_id);const r=await _e(`${tl}/review/list?${n}`);if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取审核列表失败")}return r.json()}async function Ag(a){const n=await _e(`${tl}/review/batch`,{method:"POST",body:JSON.stringify({items:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"批量审核失败")}return n.json()}function Dv({open:a,onOpenChange:n}){const[r,c]=m.useState(null),[d,u]=m.useState([]),[h,f]=m.useState(!1),[p,g]=m.useState(!1),[N,v]=m.useState(0),[w,b]=m.useState(1),[y,O]=m.useState(20),[R,S]=m.useState(""),[B,E]=m.useState("unchecked"),[C,A]=m.useState(""),[F,L]=m.useState(""),[J,U]=m.useState(new Set),[oe,Ne]=m.useState(new Set),[je,re]=m.useState(new Map),{toast:fe}=Ys(),ge=m.useCallback(async()=>{try{g(!0);const Y=await mx();c(Y)}catch(Y){console.error("加载统计失败:",Y)}finally{g(!1)}},[]),M=m.useCallback(async()=>{try{f(!0);const Y=await a2({page:w,page_size:y,filter_type:B,search:C||void 0});u(Y.data),v(Y.total)}catch(Y){fe({title:"加载失败",description:Y instanceof Error?Y.message:"无法加载列表",variant:"destructive"})}finally{f(!1)}},[w,y,B,C,fe]),K=m.useCallback(async()=>{try{const Y=await ux();if(Y?.data){const Fe=new Map;Y.data.forEach(H=>{Fe.set(H.chat_id,H.chat_name)}),re(Fe)}}catch(Y){console.error("加载聊天名称失败:",Y)}},[]);m.useEffect(()=>{a&&(ge(),M(),K())},[a,ge,M,K]),m.useEffect(()=>{b(1),U(new Set)},[B,C]);const P=()=>{A(F),b(1)},ue=Y=>je.get(Y)||Y,Q=async(Y,Fe)=>{try{Ne(ee=>new Set(ee).add(Y));const H=await Ag([{id:Y,rejected:Fe,require_unchecked:B==="unchecked"}]);H.results[0]?.success?(fe({title:Fe?"已拒绝":"已通过",description:`表达方式 #${Y} ${Fe?"已拒绝":"已通过"}`}),M(),ge()):fe({title:"操作失败",description:H.results[0]?.message||"未知错误",variant:"destructive"})}catch(H){fe({title:"操作失败",description:H instanceof Error?H.message:"未知错误",variant:"destructive"})}finally{Ne(H=>{const ee=new Set(H);return ee.delete(Y),ee})}},Se=async Y=>{if(J.size===0){fe({title:"请选择",description:"请先选择要审核的表达方式",variant:"destructive"});return}try{f(!0);const Fe=Array.from(J).map(ee=>({id:ee,rejected:Y,require_unchecked:B==="unchecked"})),H=await Ag(Fe);fe({title:"批量审核完成",description:`成功 ${H.succeeded} 条,失败 ${H.failed} 条`,variant:H.failed>0?"destructive":"default"}),U(new Set),M(),ge()}catch(Fe){fe({title:"批量审核失败",description:Fe instanceof Error?Fe.message:"未知错误",variant:"destructive"})}finally{f(!1)}},pe=()=>{J.size===d.length?U(new Set):U(new Set(d.map(Y=>Y.id)))},Te=Y=>{U(Fe=>{const H=new Set(Fe);return H.has(Y)?H.delete(Y):H.add(Y),H})},z=Y=>Y?new Date(Y*1e3).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):"-",D=Y=>Y.checked?Y.rejected?e.jsxs(ke,{variant:"destructive",className:"gap-1",children:[e.jsx(Ka,{className:"h-3 w-3"}),"已拒绝"]}):e.jsxs(ke,{variant:"default",className:"gap-1 bg-green-600",children:[e.jsx(pt,{className:"h-3 w-3"}),"已通过"]}):e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(na,{className:"h-3 w-3"}),"待审核"]}),G=Y=>Y?Y==="ai"?e.jsxs(ke,{variant:"secondary",className:"gap-1 text-xs",children:[e.jsx(Vn,{className:"h-3 w-3"}),"AI"]}):e.jsxs(ke,{variant:"secondary",className:"gap-1 text-xs",children:[e.jsx(jn,{className:"h-3 w-3"}),"人工"]}):null,de=Math.ceil(N/y),Re=()=>{const Y=[];if(de<=7)for(let Fe=1;Fe<=de;Fe++)Y.push(Fe);else{Y.push(1),w>3&&Y.push("ellipsis");const Fe=Math.max(2,w-1),H=Math.min(de-1,w+1);for(let ee=Fe;ee<=H;ee++)Y.push(ee);w1&&Y.push(de)}return Y},W=()=>{const Y=parseInt(R,10);!isNaN(Y)&&Y>=1&&Y<=de&&(b(Y),S(""))};return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-5xl w-[95vw] sm:w-full h-[90vh] sm:h-[85vh] flex flex-col p-0",children:[e.jsxs(Os,{className:"px-4 sm:px-6 pt-4 sm:pt-6 pb-4 border-b shrink-0",children:[e.jsx(Ls,{className:"text-lg sm:text-xl",children:"表达方式审核"}),e.jsx(Ks,{className:"text-xs sm:text-sm",children:"审核麦麦学习到的表达方式。通过审核的项目才会被使用(可在配置中调整),被拒绝的项目永远不会被使用。"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 sm:gap-3 mt-4",children:[e.jsxs("div",{className:"rounded-lg border p-2 sm:p-3 text-center",children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-orange-500",children:p?"-":r?.unchecked??0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"待审核"})]}),e.jsxs("div",{className:"rounded-lg border p-2 sm:p-3 text-center",children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-green-500",children:p?"-":r?.passed??0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"已通过"})]}),e.jsxs("div",{className:"rounded-lg border p-2 sm:p-3 text-center",children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-red-500",children:p?"-":r?.rejected??0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"已拒绝"})]}),e.jsxs("div",{className:"rounded-lg border p-2 sm:p-3 text-center",children:[e.jsx("div",{className:"text-xl sm:text-2xl font-bold text-blue-500",children:p?"-":r?.total??0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"总计"})]})]})]}),e.jsxs("div",{className:"px-4 sm:px-6 py-3 border-b shrink-0 space-y-3",children:[e.jsx(ta,{value:B,onValueChange:Y=>E(Y),className:"w-full",children:e.jsxs(Zt,{className:"grid w-full grid-cols-4",children:[e.jsxs(Xe,{value:"unchecked",className:"gap-1 text-xs sm:text-sm px-1 sm:px-3",children:[e.jsx(na,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"待审核"}),e.jsx("span",{className:"sm:hidden",children:"待审"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r?.unchecked??0,")"]})]}),e.jsxs(Xe,{value:"passed",className:"gap-1 text-xs sm:text-sm px-1 sm:px-3",children:[e.jsx(pt,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"已通过"}),e.jsx("span",{className:"sm:hidden",children:"通过"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r?.passed??0,")"]})]}),e.jsxs(Xe,{value:"rejected",className:"gap-1 text-xs sm:text-sm px-1 sm:px-3",children:[e.jsx(Ka,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"已拒绝"}),e.jsx("span",{className:"sm:hidden",children:"拒绝"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r?.rejected??0,")"]})]}),e.jsxs(Xe,{value:"all",className:"gap-1 text-xs sm:text-sm px-1 sm:px-3",children:[e.jsx("span",{children:"全部"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r?.total??0,")"]})]})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ae,{placeholder:"搜索情景或风格...",value:F,onChange:Y=>L(Y.target.value),onKeyDown:Y=>Y.key==="Enter"&&P(),className:"pl-9"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"icon",onClick:P,children:e.jsx(Tt,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"icon",onClick:()=>{M(),ge()},disabled:h,children:e.jsx(dt,{className:I("h-4 w-4",h&&"animate-spin")})})]}),B==="unchecked"&&J.size>0&&e.jsxs("div",{className:"flex items-center gap-2 w-full sm:w-auto",children:[e.jsxs(_,{variant:"default",size:"sm",className:"bg-green-600 hover:bg-green-700 flex-1 sm:flex-none",onClick:()=>Se(!1),disabled:h,children:[e.jsx(pt,{className:"h-4 w-4 mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"批量通过"}),e.jsx("span",{className:"sm:hidden",children:"通过"}),"(",J.size,")"]}),e.jsxs(_,{variant:"destructive",size:"sm",className:"flex-1 sm:flex-none",onClick:()=>Se(!0),disabled:h,children:[e.jsx(Ka,{className:"h-4 w-4 mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"批量拒绝"}),e.jsx("span",{className:"sm:hidden",children:"拒绝"}),"(",J.size,")"]})]})]})]}),e.jsx(Je,{className:"flex-1 px-4 sm:px-6",children:h&&d.length===0?e.jsx("div",{className:"flex items-center justify-center h-40",children:e.jsx(dt,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):d.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-40 text-muted-foreground",children:[e.jsx(_t,{className:"h-8 w-8 mb-2"}),e.jsx("p",{children:"没有找到表达方式"})]}):e.jsxs("div",{className:"space-y-2 py-2",children:[B==="unchecked"&&d.length>0&&e.jsxs("div",{className:"flex items-center gap-2 py-2 px-3 rounded-lg bg-muted/50",children:[e.jsx(qs,{checked:J.size===d.length&&d.length>0,onCheckedChange:pe}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["全选当前页 (",d.length," 条)"]})]}),d.map(Y=>e.jsx("div",{className:I("rounded-lg border p-3 sm:p-4 space-y-2 sm:space-y-3 transition-colors",J.has(Y.id)&&"bg-accent border-primary",oe.has(Y.id)&&"opacity-50"),children:e.jsxs("div",{className:"flex items-start gap-2 sm:gap-3",children:[B==="unchecked"&&e.jsx(qs,{checked:J.has(Y.id),onCheckedChange:()=>Te(Y.id),disabled:oe.has(Y.id),className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"情景:"}),e.jsx("p",{className:"text-sm font-medium break-words",children:Y.situation})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"风格:"}),e.jsx("p",{className:"text-sm text-muted-foreground break-words",children:Y.style})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1 sm:gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["#",Y.id]}),e.jsx("span",{children:"·"}),e.jsx("span",{title:ue(Y.chat_id),className:"truncate max-w-24 sm:max-w-32",children:ue(Y.chat_id)}),e.jsx("span",{children:"·"}),e.jsx("span",{children:z(Y.create_date)}),e.jsxs("div",{className:"flex items-center gap-1",children:[D(Y),G(Y.modified_by)]})]})]}),e.jsx("div",{className:"flex flex-col gap-1 sm:gap-2 shrink-0",children:B==="unchecked"?e.jsxs(e.Fragment,{children:[e.jsxs(_,{size:"sm",variant:"outline",className:"text-green-600 hover:text-green-700 hover:bg-green-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>Q(Y.id,!1),disabled:oe.has(Y.id),children:[e.jsx(pt,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"通过"})]}),e.jsxs(_,{size:"sm",variant:"outline",className:"text-red-600 hover:text-red-700 hover:bg-red-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>Q(Y.id,!0),disabled:oe.has(Y.id),children:[e.jsx(Ka,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"拒绝"})]})]}):B==="passed"?e.jsxs(_,{size:"sm",variant:"outline",className:"text-red-600 hover:text-red-700 hover:bg-red-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>Q(Y.id,!0),disabled:oe.has(Y.id),children:[e.jsx(Ka,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"改为拒绝"})]}):B==="rejected"?e.jsxs(_,{size:"sm",variant:"outline",className:"text-green-600 hover:text-green-700 hover:bg-green-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>Q(Y.id,!1),disabled:oe.has(Y.id),children:[e.jsx(pt,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"改为通过"})]}):e.jsx(e.Fragment,{children:Y.rejected?e.jsxs(_,{size:"sm",variant:"outline",className:"text-green-600 hover:text-green-700 hover:bg-green-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>Q(Y.id,!1),disabled:oe.has(Y.id),children:[e.jsx(pt,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"改为通过"})]}):Y.checked?e.jsxs(_,{size:"sm",variant:"outline",className:"text-red-600 hover:text-red-700 hover:bg-red-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>Q(Y.id,!0),disabled:oe.has(Y.id),children:[e.jsx(Ka,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"改为拒绝"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(_,{size:"sm",variant:"outline",className:"text-green-600 hover:text-green-700 hover:bg-green-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>Q(Y.id,!1),disabled:oe.has(Y.id),children:[e.jsx(pt,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"通过"})]}),e.jsxs(_,{size:"sm",variant:"outline",className:"text-red-600 hover:text-red-700 hover:bg-red-50 h-8 sm:h-9 px-2 sm:px-3",onClick:()=>Q(Y.id,!0),disabled:oe.has(Y.id),children:[e.jsx(Ka,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"拒绝"})]})]})})})]})},Y.id))]})}),e.jsxs("div",{className:"px-4 sm:px-6 py-3 border-t shrink-0 flex flex-col sm:flex-row items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("span",{className:"hidden sm:inline",children:"每页"}),e.jsxs(Pe,{value:y.toString(),onValueChange:Y=>{O(parseInt(Y,10)),b(1)},children:[e.jsx($e,{className:"w-[70px] h-8",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"10",children:"10"}),e.jsx(Z,{value:"20",children:"20"}),e.jsx(Z,{value:"50",children:"50"}),e.jsx(Z,{value:"100",children:"100"})]})]}),e.jsx("span",{className:"hidden sm:inline",children:"条"}),e.jsxs("span",{className:"text-muted-foreground",children:["共 ",N," 条"]})]}),e.jsx(ox,{className:"mx-0 w-auto",children:e.jsxs(dx,{children:[e.jsx(qn,{children:e.jsx(_,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>b(Y=>Math.max(1,Y-1)),disabled:w<=1||h,children:e.jsx(Da,{className:"h-4 w-4"})})}),Re().map((Y,Fe)=>e.jsx(qn,{children:Y==="ellipsis"?e.jsx(Rv,{}):e.jsx(pc,{href:"#",isActive:Y===w,onClick:H=>{H.preventDefault(),b(Y)},className:"h-8 w-8 cursor-pointer",children:Y})},Fe)),e.jsx(qn,{children:e.jsx(_,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>b(Y=>Math.min(de,Y+1)),disabled:w>=de||h,children:e.jsx(Wt,{className:"h-4 w-4"})})})]})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"跳至"}),e.jsx(ae,{type:"number",min:1,max:de,value:R,onChange:Y=>S(Y.target.value),onKeyDown:Y=>Y.key==="Enter"&&W(),className:"w-16 h-8 text-center",placeholder:w.toString()}),e.jsx("span",{className:"text-muted-foreground",children:"页"}),e.jsx(_,{variant:"outline",size:"sm",className:"h-8",onClick:W,disabled:h,children:"跳转"})]})]})]})})}function l2(){return e.jsx(Wn,{children:e.jsx(r2,{})})}const n2=a=>{const n=[];for(let r=0;r{try{const z=await mx();E(z.unchecked)}catch(z){console.error("获取审核统计失败:",z)}},[]),L=m.useCallback(async()=>{try{b(!0);const z=await iw.get("https://v1.hitokoto.cn/?c=a&c=b&c=c&c=d&c=h&c=i&c=k");v({hitokoto:z.data.hitokoto,from:z.data.from||z.data.from_who||"未知"})}catch(z){console.error("获取一言失败:",z),v({hitokoto:"人生就像一盒巧克力,你永远不知道下一颗是什么味道。",from:"阿甘正传"})}finally{b(!1)}},[]),J=m.useCallback(async()=>{try{const z=await _e("/api/webui/system/status");if(z.ok){const D=await z.json();O(D)}else O(null)}catch(z){console.error("获取机器人状态失败:",z),O(null)}},[]),U=async()=>{await C()},oe=m.useCallback(async()=>{try{const z=await _e(`/api/webui/statistics/dashboard?hours=${h}`);if(z.ok){const D=await z.json();n(D)}c(!1),u(100)}catch(z){console.error("Failed to fetch dashboard data:",z),c(!1),u(100)}},[h]);if(m.useEffect(()=>{if(!r)return;u(0);const z=setTimeout(()=>u(15),200),D=setTimeout(()=>u(30),800),G=setTimeout(()=>u(45),2e3),de=setTimeout(()=>u(60),4e3),Re=setTimeout(()=>u(75),6500),W=setTimeout(()=>u(85),9e3),Y=setTimeout(()=>u(92),11e3);return()=>{clearTimeout(z),clearTimeout(D),clearTimeout(G),clearTimeout(de),clearTimeout(Re),clearTimeout(W),clearTimeout(Y)}},[r]),m.useEffect(()=>{oe(),L(),J(),F()},[oe,L,J,F]),m.useEffect(()=>{if(!p)return;const z=setInterval(()=>{oe(),J()},3e4);return()=>clearInterval(z)},[p,oe,J]),r||!a)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(dt,{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(Xn,{value:d,className:"h-2"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[d,"%"]})]})]})});const{summary:Ne,model_stats:je=[],hourly_data:re=[],daily_data:fe=[],recent_activity:ge=[]}=a,M=Ne??{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},K=z=>{const D=Math.floor(z/3600),G=Math.floor(z%3600/60);return`${D}小时${G}分钟`},P=z=>{const D=z.toLocaleString("zh-CN");return z>=1e9?{display:`${(z/1e9).toFixed(2)}B`,exact:D,needsExact:!0}:z>=1e6?{display:`${(z/1e6).toFixed(2)}M`,exact:D,needsExact:!0}:z>=1e4?{display:`${(z/1e3).toFixed(1)}K`,exact:D,needsExact:!0}:z>=1e3?{display:`${(z/1e3).toFixed(2)}K`,exact:D,needsExact:!0}:{display:D,exact:D,needsExact:!1}},ue=z=>{const D=`¥${z.toLocaleString("zh-CN",{minimumFractionDigits:2,maximumFractionDigits:2})}`;return z>=1e6?{display:`¥${(z/1e6).toFixed(2)}M`,exact:D,needsExact:!0}:z>=1e4?{display:`¥${(z/1e3).toFixed(1)}K`,exact:D,needsExact:!0}:z>=1e3?{display:`¥${(z/1e3).toFixed(2)}K`,exact:D,needsExact:!0}:{display:D,exact:D,needsExact:!1}},Q=z=>new Date(z).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),Se=n2(je.length),pe=je.map((z,D)=>({name:z.model_name,value:z.request_count,fill:Se[D]})),Te={requests:{label:"请求数",color:"hsl(var(--chart-1))"},cost:{label:"花费(¥)",color:"hsl(var(--chart-2))"},tokens:{label:"Tokens",color:"hsl(var(--chart-3))"}};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"实时监控面板"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"麦麦运行状态和统计数据一览"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ta,{value:h.toString(),onValueChange:z=>f(Number(z)),children:e.jsxs(Zt,{className:"grid grid-cols-3 w-full sm:w-auto",children:[e.jsx(Xe,{value:"24",children:"24小时"}),e.jsx(Xe,{value:"168",children:"7天"}),e.jsx(Xe,{value:"720",children:"30天"})]})}),e.jsxs(_,{variant:p?"default":"outline",size:"sm",onClick:()=>g(!p),className:"gap-2",children:[e.jsx(dt,{className:`h-4 w-4 ${p?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"自动刷新"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:oe,children:e.jsx(dt,{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:[w?e.jsx(vs,{className:"h-5 flex-1"}):N?e.jsxs("p",{className:"flex-1 text-sm text-muted-foreground italic truncate",children:['"',N.hitokoto,'" —— ',N.from]}):null,e.jsx(_,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:L,disabled:w,children:e.jsx(dt,{className:`h-3.5 w-3.5 ${w?"animate-spin":""}`})})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-3",children:[e.jsxs(Ce,{className:"lg:col-span-1",children:[e.jsx(De,{className:"pb-3",children:e.jsxs(Oe,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(hc,{className:"h-4 w-4"}),"麦麦状态"]})}),e.jsx(Me,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:y?.running?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-3 w-3 rounded-full bg-green-500 animate-pulse"}),e.jsxs(ke,{variant:"outline",className:"text-green-600 border-green-300 bg-green-50",children:[e.jsx(pt,{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(ke,{variant:"outline",className:"text-red-600 border-red-300 bg-red-50",children:[e.jsx(_t,{className:"h-3 w-3 mr-1"}),"已停止"]})]})}),y&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("span",{children:["v",y.version]}),e.jsx("span",{className:"mx-2",children:"|"}),e.jsxs("span",{children:["运行 ",K(y.uptime)]})]})]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{className:"pb-3",children:e.jsxs(Oe,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(el,{className:"h-4 w-4"}),"快速操作"]})}),e.jsx(Me,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:U,disabled:A,className:"gap-2",children:[e.jsx(lc,{className:`h-4 w-4 ${A?"animate-spin":""}`}),A?"重启中...":"重启麦麦"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>S(!0),className:"gap-2",children:[e.jsx(Wj,{className:"h-4 w-4"}),"表达审核",B>0&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 text-xs rounded-full bg-orange-500 text-white",children:B>99?"99+":B})]}),e.jsx(_,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Fn,{to:"/logs",children:[e.jsx(Ea,{className:"h-4 w-4"}),"查看日志"]})}),e.jsx(_,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Fn,{to:"/plugins",children:[e.jsx(N_,{className:"h-4 w-4"}),"插件管理"]})}),e.jsx(_,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Fn,{to:"/settings",children:[e.jsx(vn,{className:"h-4 w-4"}),"系统设置"]})})]})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"pb-3",children:[e.jsxs(Oe,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(b_,{className:"h-4 w-4"}),"反馈问卷"]}),e.jsx(os,{className:"text-xs",children:"帮助我们改进产品体验"})]}),e.jsx(Me,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Fn,{to:"/survey/webui-feedback",children:[e.jsx(Ea,{className:"h-4 w-4"}),"WebUI 反馈"]})}),e.jsx(_,{variant:"outline",size:"sm",asChild:!0,className:"gap-2",children:e.jsxs(Fn,{to:"/survey/maibot-feedback",children:[e.jsx(Ra,{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(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"总请求数"}),e.jsx(sx,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[P(M.total_requests).display,P(M.total_requests).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",P(M.total_requests).exact,")"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["最近",h<48?h+"小时":Math.floor(h/24)+"天"]})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"总花费"}),e.jsx(y_,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[ue(M.total_cost).display,ue(M.total_cost).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",ue(M.total_cost).exact,")"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:M.cost_per_hour>0?`¥${M.cost_per_hour.toFixed(2)}/小时`:"暂无数据"})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"Token消耗"}),e.jsx(Yr,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[P(M.total_tokens).display,P(M.total_tokens).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",P(M.total_tokens).exact,")"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:M.tokens_per_hour>0?`${P(M.tokens_per_hour).display}/小时`:"暂无数据"})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"平均响应"}),e.jsx(el,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[M.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(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"在线时长"}),e.jsx(na,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Me,{children:e.jsxs("div",{className:"text-xl font-bold",children:[K(M.online_time),e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",M.online_time.toLocaleString(),"秒)"]})]})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"消息处理"}),e.jsx(Ra,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsxs("div",{className:"text-xl font-bold",children:[P(M.total_messages).display,P(M.total_messages).needsExact&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground ml-1",children:["(",P(M.total_messages).exact,")"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["回复 ",P(M.total_replies).display,P(M.total_replies).needsExact&&e.jsxs("span",{children:["(",P(M.total_replies).exact,")"]})," 条"]})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"成本效率"}),e.jsx(tx,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsx("div",{className:"text-xl font-bold",children:M.total_messages>0?`¥${(M.total_cost/M.total_messages*100).toFixed(2)}`:"¥0.00"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"每100条消息"})]})]})]}),e.jsxs(ta,{defaultValue:"trends",className:"space-y-4",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2 sm:grid-cols-4",children:[e.jsx(Xe,{value:"trends",children:"趋势"}),e.jsx(Xe,{value:"models",children:"模型"}),e.jsx(Xe,{value:"activity",children:"活动"}),e.jsx(Xe,{value:"daily",children:"日统计"})]}),e.jsxs(ws,{value:"trends",className:"space-y-4",children:[e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"请求趋势"}),e.jsxs(os,{children:["最近",h,"小时的请求量变化"]})]}),e.jsx(Me,{children:e.jsx(Vr,{config:Te,className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(Gw,{data:re,children:[e.jsx(Qi,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Yi,{dataKey:"timestamp",tickFormatter:z=>Q(z),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Hr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(qi,{content:e.jsx(Gr,{labelFormatter:z=>Q(z)})}),e.jsx(qw,{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(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"花费趋势"}),e.jsx(os,{children:"API调用成本变化"})]}),e.jsx(Me,{children:e.jsx(Vr,{config:Te,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(Uo,{data:re,children:[e.jsx(Qi,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Yi,{dataKey:"timestamp",tickFormatter:z=>Q(z),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Hr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(qi,{content:e.jsx(Gr,{labelFormatter:z=>Q(z)})}),e.jsx(Ji,{dataKey:"cost",fill:"var(--color-cost)"})]})})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"Token消耗"}),e.jsx(os,{children:"Token使用量变化"})]}),e.jsx(Me,{children:e.jsx(Vr,{config:Te,className:"h-[250px] sm:h-[300px] w-full aspect-auto",children:e.jsxs(Uo,{data:re,children:[e.jsx(Qi,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Yi,{dataKey:"timestamp",tickFormatter:z=>Q(z),angle:-45,textAnchor:"end",height:60,stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Hr,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(qi,{content:e.jsx(Gr,{labelFormatter:z=>Q(z)})}),e.jsx(Ji,{dataKey:"tokens",fill:"var(--color-tokens)"})]})})})]})]})]}),e.jsx(ws,{value:"models",className:"space-y-4",children:e.jsxs("div",{className:"grid gap-4 grid-cols-1 lg:grid-cols-2",children:[e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"模型请求分布"}),e.jsxs(os,{children:["各模型使用占比 (共 ",je.length," 个模型)"]})]}),e.jsx(Me,{children:e.jsx(Vr,{config:Object.fromEntries(je.map((z,D)=>[z.model_name,{label:z.model_name,color:Se[D]}])),className:"h-[300px] sm:h-[400px] w-full aspect-auto",children:e.jsxs(Kw,{children:[e.jsx(qi,{content:e.jsx(Gr,{})}),e.jsx(Qw,{data:pe,cx:"50%",cy:"50%",labelLine:!1,label:({name:z,percent:D})=>D&&D<.05?"":`${z} ${D?(D*100).toFixed(0):0}%`,outerRadius:100,dataKey:"value",children:pe.map((z,D)=>e.jsx(Yw,{fill:z.fill},`cell-${D}`))})]})})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"模型详细统计"}),e.jsx(os,{children:"请求数、花费和性能"})]}),e.jsx(Me,{children:e.jsx(Je,{className:"h-[300px] sm:h-[400px]",children:e.jsx("div",{className:"space-y-3",children:je.map((z,D)=>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:z.model_name}),e.jsx("div",{className:"w-3 h-3 rounded-full ml-2 flex-shrink-0",style:{backgroundColor:`hsl(var(--chart-${D%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:z.request_count.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1 font-medium",children:["¥",z.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:[(z.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:[z.avg_response_time.toFixed(2),"s"]})]})]})]},D))})})})]})]})}),e.jsx(ws,{value:"activity",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"最近活动"}),e.jsx(os,{children:"最新的API调用记录"})]}),e.jsx(Me,{children:e.jsx(Je,{className:"h-[400px] sm:h-[500px]",children:e.jsx("div",{className:"space-y-2",children:ge.map((z,D)=>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:z.model}),e.jsx("div",{className:"text-xs text-muted-foreground",children:z.request_type})]}),e.jsx("div",{className:"text-xs text-muted-foreground flex-shrink-0",children:Q(z.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:z.tokens})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"花费:"}),e.jsxs("span",{className:"ml-1",children:["¥",z.cost.toFixed(4)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"耗时:"}),e.jsxs("span",{className:"ml-1",children:[z.time_cost.toFixed(2),"s"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"状态:"}),e.jsx("span",{className:`ml-1 ${z.status==="success"?"text-green-600":"text-red-600"}`,children:z.status})]})]})]},D))})})})]})}),e.jsx(ws,{value:"daily",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"每日统计"}),e.jsx(os,{children:"最近7天的数据汇总"})]}),e.jsx(Me,{children:e.jsx(Vr,{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(Uo,{data:fe,children:[e.jsx(Qi,{strokeDasharray:"3 3",stroke:"hsl(var(--muted-foreground) / 0.2)"}),e.jsx(Yi,{dataKey:"timestamp",tickFormatter:z=>{const D=new Date(z);return`${D.getMonth()+1}/${D.getDate()}`},stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Hr,{yAxisId:"left",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Hr,{yAxisId:"right",orientation:"right",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(qi,{content:e.jsx(Gr,{labelFormatter:z=>new Date(z).toLocaleDateString("zh-CN")})}),e.jsx(O1,{content:e.jsx(Sv,{})}),e.jsx(Ji,{yAxisId:"left",dataKey:"requests",fill:"var(--color-requests)"}),e.jsx(Ji,{yAxisId:"right",dataKey:"cost",fill:"var(--color-cost)"})]})})})]})})]}),e.jsx(er,{}),e.jsx(Dv,{open:R,onOpenChange:z=>{S(z),z||F()}})]})})}const i2={theme:"system",setTheme:()=>null},Ov=m.createContext(i2),xx=()=>{const a=m.useContext(Ov);if(a===void 0)throw new Error("useTheme must be used within a ThemeProvider");return a},c2=(a,n,r)=>{const c=document.documentElement.classList.contains("no-animations");if(!document.startViewTransition||c){n(a);return}const d=r.clientX,u=r.clientY,h=Math.hypot(Math.max(d,innerWidth-d),Math.max(u,innerHeight-u));document.startViewTransition(()=>{n(a)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${d}px ${u}px)`,`circle(${h}px at ${d}px ${u}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},Lv=m.createContext(void 0),Uv=()=>{const a=m.useContext(Lv);if(a===void 0)throw new Error("useAnimation must be used within an AnimationProvider");return a},Ve=m.forwardRef(({className:a,...n},r)=>e.jsx(xj,{className:I("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",a),...n,ref:r,children:e.jsx(xw,{className:I("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")})}));Ve.displayName=xj.displayName;const o2=Wr("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),T=m.forwardRef(({className:a,...n},r)=>e.jsx(Vj,{ref:r,className:I(o2(),a),...n}));T.displayName=Vj.displayName;const d2=[{id:"minLength",label:"长度至少 10 位",description:"Token 长度必须大于等于 10 个字符",validate:a=>a.length>=10},{id:"hasUppercase",label:"包含大写字母",description:"至少包含一个大写字母 (A-Z)",validate:a=>/[A-Z]/.test(a)},{id:"hasLowercase",label:"包含小写字母",description:"至少包含一个小写字母 (a-z)",validate:a=>/[a-z]/.test(a)},{id:"hasSpecialChar",label:"包含特殊符号",description:"至少包含一个特殊符号 (!@#$%^&*()_+-=[]{}|;:,.<>?/)",validate:a=>/[!@#$%^&*()_+\-=[\]{}|;:,.<>?/]/.test(a)}];function u2(a){const n=d2.map(c=>({id:c.id,label:c.label,description:c.description,passed:c.validate(a)}));return{isValid:n.every(c=>c.passed),rules:n}}const od="0.12.1",hx="MaiBot Dashboard",m2=`${hx} v${od}`,x2=(a="v")=>`${a}${od}`,pa={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"},dl={theme:"system",accentColor:"blue",enableAnimations:!0,enableWavesBackground:!0,logCacheSize:1e3,logAutoScroll:!0,logFontSize:"xs",logLineSpacing:4,dataSyncInterval:30,wsReconnectInterval:3e3,wsMaxReconnectAttempts:10};function yt(a){const n=$v(a),r=localStorage.getItem(n);if(r===null)return dl[a];const c=dl[a];if(typeof c=="boolean")return r==="true";if(typeof c=="number"){const d=parseFloat(r);return isNaN(d)?c:d}return r}function qr(a,n){const r=$v(a);localStorage.setItem(r,String(n)),window.dispatchEvent(new CustomEvent("maibot-settings-change",{detail:{key:a,value:n}}))}function h2(){return{theme:yt("theme"),accentColor:yt("accentColor"),enableAnimations:yt("enableAnimations"),enableWavesBackground:yt("enableWavesBackground"),logCacheSize:yt("logCacheSize"),logAutoScroll:yt("logAutoScroll"),logFontSize:yt("logFontSize"),logLineSpacing:yt("logLineSpacing"),dataSyncInterval:yt("dataSyncInterval"),wsReconnectInterval:yt("wsReconnectInterval"),wsMaxReconnectAttempts:yt("wsMaxReconnectAttempts")}}function f2(){const a=h2(),n=localStorage.getItem(pa.COMPLETED_TOURS),r=n?JSON.parse(n):[];return{...a,completedTours:r}}function p2(a){const n=[],r=[];for(const[c,d]of Object.entries(a)){if(c==="completedTours"){Array.isArray(d)?(localStorage.setItem(pa.COMPLETED_TOURS,JSON.stringify(d)),n.push("completedTours")):r.push("completedTours");continue}if(c in dl){const u=c,h=dl[u];if(typeof d==typeof h){if(u==="theme"&&!["light","dark","system"].includes(d)){r.push(c);continue}if(u==="logFontSize"&&!["xs","sm","base"].includes(d)){r.push(c);continue}qr(u,d),n.push(c)}else r.push(c)}else r.push(c)}return{success:n.length>0,imported:n,skipped:r}}function g2(){for(const a of Object.keys(dl))qr(a,dl[a]);localStorage.removeItem(pa.COMPLETED_TOURS),window.dispatchEvent(new CustomEvent("maibot-settings-reset"))}function j2(){const a=[],n=[],r=[];for(let c=0;cc.size-r.size),{used:a,items:localStorage.length,details:n}}function v2(a){if(a===0)return"0 B";const n=1024,r=["B","KB","MB"],c=Math.floor(Math.log(a)/Math.log(n));return parseFloat((a/Math.pow(n,c)).toFixed(2))+" "+r[c]}function $v(a){return{theme:pa.THEME,accentColor:pa.ACCENT_COLOR,enableAnimations:pa.ENABLE_ANIMATIONS,enableWavesBackground:pa.ENABLE_WAVES_BACKGROUND,logCacheSize:pa.LOG_CACHE_SIZE,logAutoScroll:pa.LOG_AUTO_SCROLL,logFontSize:pa.LOG_FONT_SIZE,logLineSpacing:pa.LOG_LINE_SPACING,dataSyncInterval:pa.DATA_SYNC_INTERVAL,wsReconnectInterval:pa.WS_RECONNECT_INTERVAL,wsMaxReconnectAttempts:pa.WS_MAX_RECONNECT_ATTEMPTS}[a]}const Qa=m.forwardRef(({className:a,...n},r)=>e.jsxs(hj,{ref:r,className:I("relative flex w-full touch-none select-none items-center",a),...n,children:[e.jsx(hw,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(fw,{className:"absolute h-full bg-primary"})}),e.jsx(pw,{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"})]}));Qa.displayName=hj.displayName;class N2{ws=null;reconnectTimeout=null;reconnectAttempts=0;heartbeatInterval=null;logCallbacks=new Set;connectionCallbacks=new Set;isConnected=!1;logCache=[];getMaxCacheSize(){return yt("logCacheSize")}getMaxReconnectAttempts(){return yt("wsMaxReconnectAttempts")}getReconnectInterval(){return yt("wsReconnectInterval")}getWebSocketUrl(n){let r;{const c=window.location.protocol==="https:"?"wss:":"ws:",d=window.location.host;r=`${c}//${d}/ws/logs`}return n?`${r}?token=${encodeURIComponent(n)}`:r}async getWsToken(){try{const n=await _e("/api/webui/ws-token",{method:"GET",credentials:"include"});if(!n.ok)return console.error("获取 WebSocket token 失败:",n.status),null;const r=await n.json();return r.success&&r.token?r.token:null}catch(n){return console.error("获取 WebSocket token 失败:",n),null}}async connect(){if(this.ws?.readyState===WebSocket.OPEN||this.ws?.readyState===WebSocket.CONNECTING)return;if(window.location.pathname==="/auth"){console.log("📡 在登录页面,跳过 WebSocket 连接");return}if(!await cc()){console.log("📡 未登录,跳过 WebSocket 连接");return}const r=await this.getWsToken();if(!r){console.log("📡 无法获取 WebSocket token,跳过连接");return}const c=this.getWebSocketUrl(r);try{this.ws=new WebSocket(c),this.ws.onopen=()=>{this.isConnected=!0,this.reconnectAttempts=0,this.notifyConnection(!0),this.startHeartbeat()},this.ws.onmessage=d=>{try{if(d.data==="pong")return;const u=JSON.parse(d.data);this.notifyLog(u)}catch(u){console.error("解析日志消息失败:",u)}},this.ws.onerror=d=>{console.error("❌ WebSocket 错误:",d),this.isConnected=!1,this.notifyConnection(!1)},this.ws.onclose=()=>{this.isConnected=!1,this.notifyConnection(!1),this.stopHeartbeat(),this.attemptReconnect()}}catch(d){console.error("创建 WebSocket 连接失败:",d),this.attemptReconnect()}}attemptReconnect(){const n=this.getMaxReconnectAttempts();if(this.reconnectAttempts>=n)return;this.reconnectAttempts+=1;const r=this.getReconnectInterval(),c=Math.min(r*this.reconnectAttempts,3e4);this.reconnectTimeout=window.setTimeout(()=>{this.connect()},c)}startHeartbeat(){this.heartbeatInterval=window.setInterval(()=>{this.ws?.readyState===WebSocket.OPEN&&this.ws.send("ping")},3e4)}stopHeartbeat(){this.heartbeatInterval!==null&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null)}disconnect(){this.reconnectTimeout!==null&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.stopHeartbeat(),this.ws&&(this.ws.close(),this.ws=null),this.isConnected=!1,this.reconnectAttempts=0}onLog(n){return this.logCallbacks.add(n),()=>this.logCallbacks.delete(n)}onConnectionChange(n){return this.connectionCallbacks.add(n),n(this.isConnected),()=>this.connectionCallbacks.delete(n)}notifyLog(n){if(!this.logCache.some(c=>c.id===n.id)){this.logCache.push(n);const c=this.getMaxCacheSize();this.logCache.length>c&&(this.logCache=this.logCache.slice(-c)),this.logCallbacks.forEach(d=>{try{d(n)}catch(u){console.error("日志回调执行失败:",u)}})}}notifyConnection(n){this.connectionCallbacks.forEach(r=>{try{r(n)}catch(c){console.error("连接状态回调执行失败:",c)}})}getAllLogs(){return[...this.logCache]}clearLogs(){this.logCache=[]}getConnectionStatus(){return this.isConnected}}const Hn=new N2;typeof window<"u"&&setTimeout(()=>{Hn.connect()},100);const Ns=jw,wt=vw,b2=gw,Bv=m.forwardRef(({className:a,...n},r)=>e.jsx(fj,{className:I("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",a),...n,ref:r}));Bv.displayName=fj.displayName;const us=m.forwardRef(({className:a,...n},r)=>e.jsxs(b2,{children:[e.jsx(Bv,{}),e.jsx(pj,{ref:r,className:I("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",a),...n})]}));us.displayName=pj.displayName;const ms=({className:a,...n})=>e.jsx("div",{className:I("flex flex-col space-y-2 text-center sm:text-left",a),...n});ms.displayName="AlertDialogHeader";const xs=({className:a,...n})=>e.jsx("div",{className:I("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",a),...n});xs.displayName="AlertDialogFooter";const hs=m.forwardRef(({className:a,...n},r)=>e.jsx(gj,{ref:r,className:I("text-lg font-semibold",a),...n}));hs.displayName=gj.displayName;const fs=m.forwardRef(({className:a,...n},r)=>e.jsx(jj,{ref:r,className:I("text-sm text-muted-foreground",a),...n}));fs.displayName=jj.displayName;const ps=m.forwardRef(({className:a,variant:n,...r},c)=>e.jsx(vj,{ref:c,className:I(Zr({variant:n}),a),...r}));ps.displayName=vj.displayName;const gs=m.forwardRef(({className:a,...n},r)=>e.jsx(Nj,{ref:r,className:I(Zr({variant:"outline"}),"mt-2 sm:mt-0",a),...n}));gs.displayName=Nj.displayName;function y2(){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(ta,{defaultValue:"appearance",className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2 sm:grid-cols-4 gap-0.5 sm:gap-1 h-auto p-1",children:[e.jsxs(Xe,{value:"appearance",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(w_,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"外观"})]}),e.jsxs(Xe,{value:"security",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(ev,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"安全"})]}),e.jsxs(Xe,{value:"other",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(vn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"其他"})]}),e.jsxs(Xe,{value:"about",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(Ft,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"关于"})]})]}),e.jsxs(Je,{className:"h-[calc(100vh-240px)] sm:h-[calc(100vh-280px)] mt-4 sm:mt-6",children:[e.jsx(ws,{value:"appearance",className:"mt-0",children:e.jsx(w2,{})}),e.jsx(ws,{value:"security",className:"mt-0",children:e.jsx(_2,{})}),e.jsx(ws,{value:"other",className:"mt-0",children:e.jsx(S2,{})}),e.jsx(ws,{value:"about",className:"mt-0",children:e.jsx(k2,{})})]})]})]})}function Rg(a){const n=document.documentElement,c={blue:{hsl:"221.2 83.2% 53.3%",darkHsl:"217.2 91.2% 59.8%",gradient:null},purple:{hsl:"271 91% 65%",darkHsl:"270 95% 75%",gradient:null},green:{hsl:"142 71% 45%",darkHsl:"142 76% 36%",gradient:null},orange:{hsl:"25 95% 53%",darkHsl:"20 90% 48%",gradient:null},pink:{hsl:"330 81% 60%",darkHsl:"330 85% 70%",gradient:null},red:{hsl:"0 84% 60%",darkHsl:"0 90% 70%",gradient:null},"gradient-sunset":{hsl:"15 95% 60%",darkHsl:"15 95% 65%",gradient:"linear-gradient(135deg, hsl(25 95% 53%) 0%, hsl(330 81% 60%) 100%)"},"gradient-ocean":{hsl:"200 90% 55%",darkHsl:"200 90% 60%",gradient:"linear-gradient(135deg, hsl(221.2 83.2% 53.3%) 0%, hsl(189 94% 43%) 100%)"},"gradient-forest":{hsl:"150 70% 45%",darkHsl:"150 75% 40%",gradient:"linear-gradient(135deg, hsl(142 71% 45%) 0%, hsl(158 64% 52%) 100%)"},"gradient-aurora":{hsl:"310 85% 65%",darkHsl:"310 90% 70%",gradient:"linear-gradient(135deg, hsl(271 91% 65%) 0%, hsl(330 81% 60%) 100%)"},"gradient-fire":{hsl:"15 95% 55%",darkHsl:"15 95% 60%",gradient:"linear-gradient(135deg, hsl(0 84% 60%) 0%, hsl(25 95% 53%) 100%)"},"gradient-twilight":{hsl:"250 90% 60%",darkHsl:"250 95% 65%",gradient:"linear-gradient(135deg, hsl(239 84% 67%) 0%, hsl(271 91% 65%) 100%)"}}[a];if(c)n.style.setProperty("--primary",c.hsl),c.gradient?(n.style.setProperty("--primary-gradient",c.gradient),n.classList.add("has-gradient")):(n.style.removeProperty("--primary-gradient"),n.classList.remove("has-gradient"));else if(a.startsWith("#")){const d=u=>{u=u.replace("#","");const h=parseInt(u.substring(0,2),16)/255,f=parseInt(u.substring(2,4),16)/255,p=parseInt(u.substring(4,6),16)/255,g=Math.max(h,f,p),N=Math.min(h,f,p);let v=0,w=0;const b=(g+N)/2;if(g!==N){const y=g-N;switch(w=b>.5?y/(2-g-N):y/(g+N),g){case h:v=((f-p)/y+(flocalStorage.getItem("accent-color")||"blue");m.useEffect(()=>{const g=localStorage.getItem("accent-color")||"blue";Rg(g)},[]);const p=g=>{f(g),localStorage.setItem("accent-color",g),Rg(g)};return e.jsxs("div",{className:"space-y-6 sm:space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题模式"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4",children:[e.jsx(Lm,{value:"light",current:a,onChange:n,label:"浅色",description:"始终使用浅色主题"}),e.jsx(Lm,{value:"dark",current:a,onChange:n,label:"深色",description:"始终使用深色主题"}),e.jsx(Lm,{value:"system",current:a,onChange:n,label:"跟随系统",description:"根据系统设置自动切换"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"主题色"}),e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"单色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(qa,{value:"blue",current:h,onChange:p,label:"蓝色",colorClass:"bg-blue-500"}),e.jsx(qa,{value:"purple",current:h,onChange:p,label:"紫色",colorClass:"bg-purple-500"}),e.jsx(qa,{value:"green",current:h,onChange:p,label:"绿色",colorClass:"bg-green-500"}),e.jsx(qa,{value:"orange",current:h,onChange:p,label:"橙色",colorClass:"bg-orange-500"}),e.jsx(qa,{value:"pink",current:h,onChange:p,label:"粉色",colorClass:"bg-pink-500"}),e.jsx(qa,{value:"red",current:h,onChange:p,label:"红色",colorClass:"bg-red-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"渐变色"}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2 sm:gap-3",children:[e.jsx(qa,{value:"gradient-sunset",current:h,onChange:p,label:"日落",colorClass:"bg-gradient-to-r from-orange-500 to-pink-500"}),e.jsx(qa,{value:"gradient-ocean",current:h,onChange:p,label:"海洋",colorClass:"bg-gradient-to-r from-blue-500 to-cyan-500"}),e.jsx(qa,{value:"gradient-forest",current:h,onChange:p,label:"森林",colorClass:"bg-gradient-to-r from-green-500 to-emerald-500"}),e.jsx(qa,{value:"gradient-aurora",current:h,onChange:p,label:"极光",colorClass:"bg-gradient-to-r from-purple-500 to-pink-500"}),e.jsx(qa,{value:"gradient-fire",current:h,onChange:p,label:"烈焰",colorClass:"bg-gradient-to-r from-red-500 to-orange-500"}),e.jsx(qa,{value:"gradient-twilight",current:h,onChange:p,label:"暮光",colorClass:"bg-gradient-to-r from-indigo-500 to-purple-500"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs sm:text-sm font-medium mb-2 sm:mb-3",children:"自定义颜色"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 sm:gap-4",children:[e.jsx("div",{className:"flex-1",children:e.jsx("input",{type:"color",value:h.startsWith("#")?h:"#3b82f6",onChange:g=>p(g.target.value),className:"h-10 sm:h-12 w-full rounded-lg border-2 border-border cursor-pointer",title:"选择自定义颜色"})}),e.jsx("div",{className:"flex-1",children:e.jsx(ae,{type:"text",value:h,onChange:g=>p(g.target.value),placeholder:"#3b82f6",className:"font-mono text-sm"})})]}),e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground mt-2",children:"点击色块选择颜色,或手动输入 HEX 颜色代码"})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"动画效果"}),e.jsxs("div",{className:"space-y-2 sm:space-y-3",children:[e.jsx("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(T,{htmlFor:"animations",className:"text-base font-medium cursor-pointer",children:"启用动画效果"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后将禁用所有过渡动画和特效,提升性能"})]}),e.jsx(Ve,{id:"animations",checked:r,onCheckedChange:c})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5 flex-1",children:[e.jsx(T,{htmlFor:"waves-background",className:"text-base font-medium cursor-pointer",children:"登录页波浪背景"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"关闭后登录页将使用纯色背景,适合低性能设备"})]}),e.jsx(Ve,{id:"waves-background",checked:d,onCheckedChange:u})]})})]})]})]})}function _2(){const a=ca(),[n,r]=m.useState(""),[c,d]=m.useState(""),[u,h]=m.useState(!1),[f,p]=m.useState(!1),[g,N]=m.useState(!1),[v,w]=m.useState(!1),[b,y]=m.useState(!1),[O,R]=m.useState(!1),[S,B]=m.useState(""),[E,C]=m.useState(!1),{toast:A}=Ys(),F=m.useMemo(()=>u2(c),[c]),L=async re=>{if(!n){A({title:"无法复制",description:"Token 存储在安全 Cookie 中,请重新生成以获取新 Token",variant:"destructive"});return}try{await navigator.clipboard.writeText(re),y(!0),A({title:"复制成功",description:"Token 已复制到剪贴板"}),setTimeout(()=>y(!1),2e3)}catch{A({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},J=async()=>{if(!c.trim()){A({title:"输入错误",description:"请输入新的 Token",variant:"destructive"});return}if(!F.isValid){const re=F.rules.filter(fe=>!fe.passed).map(fe=>fe.label).join(", ");A({title:"格式错误",description:`Token 不符合要求: ${re}`,variant:"destructive"});return}N(!0);try{const re=await fetch("/api/webui/auth/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({new_token:c.trim()})}),fe=await re.json();re.ok&&fe.success?(d(""),r(c.trim()),A({title:"更新成功",description:"Access Token 已更新,即将跳转到登录页"}),setTimeout(()=>{a({to:"/auth"})},1500)):A({title:"更新失败",description:fe.message||"无法更新 Token",variant:"destructive"})}catch(re){console.error("更新 Token 错误:",re),A({title:"更新失败",description:"连接服务器失败",variant:"destructive"})}finally{N(!1)}},U=async()=>{w(!0);try{const re=await fetch("/api/webui/auth/regenerate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"}),fe=await re.json();re.ok&&fe.success?(r(fe.token),B(fe.token),R(!0),C(!1),A({title:"生成成功",description:"新的 Access Token 已生成,请及时保存"})):A({title:"生成失败",description:fe.message||"无法生成新 Token",variant:"destructive"})}catch(re){console.error("生成 Token 错误:",re),A({title:"生成失败",description:"连接服务器失败",variant:"destructive"})}finally{w(!1)}},oe=async()=>{try{await navigator.clipboard.writeText(S),C(!0),A({title:"复制成功",description:"Token 已复制到剪贴板"})}catch{A({title:"复制失败",description:"请手动复制 Token",variant:"destructive"})}},Ne=()=>{R(!1),setTimeout(()=>{B(""),C(!1)},300),setTimeout(()=>{a({to:"/auth"})},500)},je=re=>{re||Ne()};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(Ps,{open:O,onOpenChange:je,children:e.jsxs(Ds,{className:"sm:max-w-md",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(Jt,{className:"h-5 w-5 text-yellow-500"}),"新的 Access Token"]}),e.jsx(Ks,{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(T,{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:S})]}),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(Jt,{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(_,{variant:"outline",onClick:oe,className:"gap-2",children:E?e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"h-4 w-4 text-green-500"}),"已复制"]}):e.jsxs(e.Fragment,{children:[e.jsx(Fo,{className:"h-4 w-4"}),"复制 Token"]})}),e.jsx(_,{onClick:Ne,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(T,{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(ae,{id:"current-token",type:u?"text":"password",value:n||"••••••••••••••••••••••••••••••••",readOnly:!0,className:"pr-10 font-mono text-sm",placeholder:"Token 存储在安全 Cookie 中"}),e.jsx("button",{onClick:()=>{n?h(!u):A({title:"无法查看",description:'Token 存储在安全 Cookie 中,如需新 Token 请点击"重新生成"'})},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:u?"隐藏":"显示",children:u?e.jsx(nc,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(ia,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(_,{variant:"outline",size:"icon",onClick:()=>L(n),title:"复制到剪贴板",className:"flex-shrink-0",disabled:!n,children:b?e.jsx(Ct,{className:"h-4 w-4 text-green-500"}):e.jsx(Fo,{className:"h-4 w-4"})}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{variant:"outline",disabled:v,className:"gap-2 flex-1 sm:flex-none",children:[e.jsx(dt,{className:I("h-4 w-4",v&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:"重新生成"}),e.jsx("span",{className:"sm:hidden",children:"生成"})]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重新生成 Token"}),e.jsx(fs,{children:"这将生成一个新的 64 位安全令牌,并使当前 Token 立即失效。 您需要使用新 Token 重新登录系统。此操作不可撤销,确定要继续吗?"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:U,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(T,{htmlFor:"new-token",className:"text-sm",children:"新的访问令牌"}),e.jsxs("div",{className:"relative",children:[e.jsx(ae,{id:"new-token",type:f?"text":"password",value:c,onChange:re=>d(re.target.value),className:"pr-10 font-mono text-sm",placeholder:"输入自定义 Token"}),e.jsx("button",{onClick:()=>p(!f),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 hover:bg-accent rounded",title:f?"隐藏":"显示",children:f?e.jsx(nc,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(ia,{className:"h-4 w-4 text-muted-foreground"})})]}),c&&e.jsxs("div",{className:"mt-3 space-y-2 p-3 rounded-lg bg-muted/50",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Token 安全要求:"}),e.jsx("div",{className:"space-y-1.5",children:F.rules.map(re=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[re.passed?e.jsx(pt,{className:"h-4 w-4 text-green-500 flex-shrink-0"}):e.jsx(Ka,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:I(re.passed?"text-green-600 dark:text-green-400":"text-muted-foreground"),children:re.label})]},re.id))}),F.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(Ct,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:"Token 格式正确,可以使用"})]})})]})]}),e.jsx(_,{onClick:J,disabled:g||!F.isValid||!c,className:"w-full sm:w-auto",children:g?"更新中...":"更新自定义 Token"})]})]}),e.jsxs("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3 sm:p-4",children:[e.jsx("h4",{className:"text-sm sm:text-base font-semibold text-yellow-900 dark:text-yellow-200 mb-2",children:"安全提示"}),e.jsxs("ul",{className:"text-xs sm:text-sm text-yellow-800 dark:text-yellow-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"重新生成 Token 会创建系统随机生成的 64 位安全令牌"}),e.jsx("li",{children:"自定义 Token 必须满足所有安全要求才能使用"}),e.jsx("li",{children:"更新 Token 后,旧的 Token 将立即失效"}),e.jsx("li",{children:"请在安全的环境下查看和复制 Token"}),e.jsx("li",{children:"如果怀疑 Token 泄露,请立即重新生成或更新"}),e.jsx("li",{children:"建议使用系统生成的 Token 以获得最高安全性"})]})]})]})}function S2(){const a=ca(),{toast:n}=Ys(),[r,c]=m.useState(!1),[d,u]=m.useState(!1),[h,f]=m.useState(()=>yt("logCacheSize")),[p,g]=m.useState(()=>yt("wsReconnectInterval")),[N,v]=m.useState(()=>yt("wsMaxReconnectAttempts")),[w,b]=m.useState(()=>yt("dataSyncInterval")),[y,O]=m.useState(()=>zg()),[R,S]=m.useState(!1),[B,E]=m.useState(!1),C=m.useRef(null);if(d)throw new Error("这是一个手动触发的测试错误,用于验证错误边界组件是否正常工作。");const A=()=>{O(zg())},F=M=>{const K=M[0];f(K),qr("logCacheSize",K)},L=M=>{const K=M[0];g(K),qr("wsReconnectInterval",K)},J=M=>{const K=M[0];v(K),qr("wsMaxReconnectAttempts",K)},U=M=>{const K=M[0];b(K),qr("dataSyncInterval",K)},oe=()=>{Hn.clearLogs(),n({title:"日志已清除",description:"日志缓存已清空"})},Ne=()=>{const M=j2();A(),n({title:"缓存已清除",description:`已清除 ${M.clearedKeys.length} 项缓存数据`})},je=()=>{S(!0);try{const M=f2(),K=JSON.stringify(M,null,2),P=new Blob([K],{type:"application/json"}),ue=URL.createObjectURL(P),Q=document.createElement("a");Q.href=ue,Q.download=`maibot-webui-settings-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(Q),Q.click(),document.body.removeChild(Q),URL.revokeObjectURL(ue),n({title:"导出成功",description:"设置已导出为 JSON 文件"})}catch(M){console.error("导出设置失败:",M),n({title:"导出失败",description:"无法导出设置",variant:"destructive"})}finally{S(!1)}},re=M=>{const K=M.target.files?.[0];if(!K)return;E(!0);const P=new FileReader;P.onload=ue=>{try{const Q=ue.target?.result,Se=JSON.parse(Q),pe=p2(Se);pe.success?(f(yt("logCacheSize")),g(yt("wsReconnectInterval")),v(yt("wsMaxReconnectAttempts")),b(yt("dataSyncInterval")),A(),n({title:"导入成功",description:`成功导入 ${pe.imported.length} 项设置${pe.skipped.length>0?`,跳过 ${pe.skipped.length} 项`:""}`}),(pe.imported.includes("theme")||pe.imported.includes("accentColor"))&&n({title:"提示",description:"部分设置需要刷新页面才能完全生效"})):n({title:"导入失败",description:"没有有效的设置项可导入",variant:"destructive"})}catch(Q){console.error("导入设置失败:",Q),n({title:"导入失败",description:"文件格式无效",variant:"destructive"})}finally{E(!1),C.current&&(C.current.value="")}},P.readAsText(K)},fe=()=>{g2(),f(dl.logCacheSize),g(dl.wsReconnectInterval),v(dl.wsMaxReconnectAttempts),b(dl.dataSyncInterval),A(),n({title:"已重置",description:"所有设置已恢复为默认值,刷新页面以应用更改"})},ge=async()=>{c(!0);try{const M=await _e("/api/webui/setup/reset",{method:"POST"}),K=await M.json();M.ok&&K.success?(n({title:"重置成功",description:"即将进入初次配置向导"}),setTimeout(()=>{a({to:"/setup"})},1e3)):n({title:"重置失败",description:K.message||"无法重置配置状态",variant:"destructive"})}catch(M){console.error("重置配置状态错误:",M),n({title:"重置失败",description:"连接服务器失败",variant:"destructive"})}finally{c(!1)}};return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(Yr,{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(__,{className:"h-4 w-4"}),"本地存储使用"]}),e.jsx(_,{variant:"ghost",size:"sm",onClick:A,className:"h-7 px-2",children:e.jsx(dt,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:v2(y.used)}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[y.items," 个存储项"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{className:"text-sm font-medium",children:"日志缓存大小"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h," 条"]})]}),e.jsx(Qa,{value:[h],onValueChange:F,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(T,{className:"text-sm font-medium",children:"首页数据刷新间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[w," 秒"]})]}),e.jsx(Qa,{value:[w],onValueChange:U,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(T,{className:"text-sm font-medium",children:"WebSocket 重连间隔"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[p/1e3," 秒"]})]}),e.jsx(Qa,{value:[p],onValueChange:L,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(T,{className:"text-sm font-medium",children:"WebSocket 最大重连次数"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[N," 次"]})]}),e.jsx(Qa,{value:[N],onValueChange:J,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(_,{variant:"outline",size:"sm",onClick:oe,className:"gap-2",children:[e.jsx(ns,{className:"h-4 w-4"}),"清除日志缓存"]}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(ns,{className:"h-4 w-4"}),"清除本地缓存"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认清除本地缓存"}),e.jsx(fs,{children:"这将清除所有本地缓存的设置和数据(不包括登录凭证)。 您可能需要重新配置部分偏好设置。确定要继续吗?"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:Ne,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(Xt,{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(_,{variant:"outline",onClick:je,disabled:R,className:"gap-2",children:[e.jsx(Xt,{className:"h-4 w-4"}),R?"导出中...":"导出设置"]}),e.jsx("input",{ref:C,type:"file",accept:".json",onChange:re,className:"hidden"}),e.jsxs(_,{variant:"outline",onClick:()=>C.current?.click(),disabled:B,className:"gap-2",children:[e.jsx(rc,{className:"h-4 w-4"}),B?"导入中...":"导入设置"]})]}),e.jsx("div",{className:"pt-2 border-t",children:e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"gap-2 text-destructive hover:text-destructive",children:[e.jsx(lc,{className:"h-4 w-4"}),"重置所有设置为默认值"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重置所有设置"}),e.jsx(fs,{children:"这将把所有界面设置恢复为默认值,包括主题、颜色、动画等偏好设置。 此操作不会影响您的登录状态。确定要继续吗?"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:fe,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(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{variant:"outline",disabled:r,className:"gap-2",children:[e.jsx(lc,{className:I("h-4 w-4",r&&"animate-spin")}),"重新进行初次配置"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重新配置"}),e.jsx(fs,{children:"这将带您重新进入初次配置向导。您可以重新设置系统的基础配置项。确定要继续吗?"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:ge,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(Jt,{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(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{variant:"destructive",className:"gap-2",children:[e.jsx(Jt,{className:"h-4 w-4"}),"触发测试错误"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认触发错误"}),e.jsx(fs,{children:"这将手动触发一个 React 错误,用于测试错误边界组件的显示效果。 页面将显示错误界面,您可以通过刷新页面或点击返回首页来恢复。"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>u(!0),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认触发"})]})]})]})]})]})]})}function k2(){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:I("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:["关于 ",hx]}),e.jsxs("div",{className:"space-y-2 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("p",{children:["版本: ",od]}),e.jsx("p",{children:"麦麦(MaiBot)的现代化 Web 管理界面"})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"作者"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"MaiBot 核心"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground",children:"Mai-with-u"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"WebUI"}),e.jsxs("p",{className:"text-xs sm:text-sm text-muted-foreground",children:["Mai-with-u ",e.jsx("a",{href:"https://github.com/DrSmoothl",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"@MotricSeven"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"技术栈"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"前端框架"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"React 19.2.0"}),e.jsx("li",{children:"TypeScript 5.7.2"}),e.jsx("li",{children:"Vite 6.0.7"}),e.jsx("li",{children:"TanStack Router 1.94.2"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"UI 组件"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"shadcn/ui"}),e.jsx("li",{children:"Radix UI"}),e.jsx("li",{children:"Tailwind CSS 3.4.17"}),e.jsx("li",{children:"Lucide Icons"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"后端"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Python 3.12+"}),e.jsx("li",{children:"FastAPI"}),e.jsx("li",{children:"Uvicorn"}),e.jsx("li",{children:"WebSocket"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground",children:"构建工具"}),e.jsxs("ul",{className:"space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"Bun / npm"}),e.jsx("li",{children:"ESLint 9.17.0"}),e.jsx("li",{children:"PostCSS"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6",children:[e.jsx("h3",{className:"text-base sm:text-lg font-semibold mb-3 sm:mb-4",children:"开源库感谢"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mb-3",children:"本项目使用了以下优秀的开源库,感谢他们的贡献:"}),e.jsx(Je,{className:"h-[300px] sm:h-[400px]",children:e.jsxs("div",{className:"space-y-4 pr-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"UI 框架与组件"}),e.jsxs("div",{className:"grid gap-2 text-xs sm:text-sm",children:[e.jsx(ft,{name:"React",description:"用户界面构建库",license:"MIT"}),e.jsx(ft,{name:"shadcn/ui",description:"优雅的 React 组件库",license:"MIT"}),e.jsx(ft,{name:"Radix UI",description:"无样式的可访问组件库",license:"MIT"}),e.jsx(ft,{name:"Tailwind CSS",description:"实用优先的 CSS 框架",license:"MIT"}),e.jsx(ft,{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(ft,{name:"TanStack Router",description:"类型安全的路由库",license:"MIT"}),e.jsx(ft,{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(ft,{name:"React Hook Form",description:"高性能表单库",license:"MIT"}),e.jsx(ft,{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(ft,{name:"clsx",description:"条件 className 构建工具",license:"MIT"}),e.jsx(ft,{name:"tailwind-merge",description:"Tailwind 类名合并工具",license:"MIT"}),e.jsx(ft,{name:"class-variance-authority",description:"组件变体管理",license:"Apache-2.0"}),e.jsx(ft,{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(ft,{name:"Framer Motion",description:"React 动画库",license:"MIT"}),e.jsx(ft,{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(ft,{name:"FastAPI",description:"现代化 Python Web 框架",license:"MIT"}),e.jsx(ft,{name:"Uvicorn",description:"ASGI 服务器",license:"BSD-3-Clause"}),e.jsx(ft,{name:"Pydantic",description:"数据验证库",license:"MIT"}),e.jsx(ft,{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(ft,{name:"TypeScript",description:"JavaScript 的超集",license:"Apache-2.0"}),e.jsx(ft,{name:"Vite",description:"下一代前端构建工具",license:"MIT"}),e.jsx(ft,{name:"ESLint",description:"JavaScript 代码检查工具",license:"MIT"}),e.jsx(ft,{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 ft({name:a,description:n,license:r}){return e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg border bg-muted/30 p-2.5 sm:p-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-foreground truncate",children:a}),e.jsx("p",{className:"text-muted-foreground text-xs mt-0.5",children:n})]}),e.jsx("span",{className:"inline-flex items-center rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary flex-shrink-0",children:r})]})}function Lm({value:a,current:n,onChange:r,label:c,description:d}){const u=n===a;return e.jsxs("button",{onClick:()=>r(a),className:I("relative rounded-lg border-2 p-3 sm:p-4 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",u?"border-primary bg-accent":"border-border"),children:[u&&e.jsx("div",{className:"absolute top-2 right-2 sm:top-3 sm:right-3 h-2 w-2 rounded-full bg-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm sm:text-base font-medium",children:c}),e.jsx("div",{className:"text-[10px] sm:text-xs text-muted-foreground",children:d})]}),e.jsxs("div",{className:"mt-2 sm:mt-3 flex gap-1",children:[a==="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"})]}),a==="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"})]}),a==="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 qa({value:a,current:n,onChange:r,label:c,colorClass:d}){const u=n===a;return e.jsxs("button",{onClick:()=>r(a),className:I("relative rounded-lg border-2 p-2 sm:p-3 text-left transition-all","hover:border-primary/50 hover:bg-accent/50",u?"border-primary bg-accent":"border-border"),children:[u&&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:I("h-8 w-8 sm:h-10 sm:w-10 rounded-full",d)}),e.jsx("div",{className:"text-[10px] sm:text-xs font-medium text-center",children:c})]})]})}const C2=Date.now()%1e6;class T2{grad3;p;perm;constructor(n=0){this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.p=[];for(let r=0;r<256;r++)this.p[r]=Math.floor(Math.random()*256);this.perm=[];for(let r=0;r<512;r++)this.perm[r]=this.p[r&255]}dot(n,r,c){return n[0]*r+n[1]*c}mix(n,r,c){return(1-c)*n+c*r}fade(n){return n*n*n*(n*(n*6-15)+10)}perlin2(n,r){const c=Math.floor(n)&255,d=Math.floor(r)&255;n-=Math.floor(n),r-=Math.floor(r);const u=this.fade(n),h=this.fade(r),f=this.perm[c]+d,p=this.perm[f],g=this.perm[f+1],N=this.perm[c+1]+d,v=this.perm[N],w=this.perm[N+1];return this.mix(this.mix(this.dot(this.grad3[p%12],n,r),this.dot(this.grad3[v%12],n-1,r),u),this.mix(this.dot(this.grad3[g%12],n,r-1),this.dot(this.grad3[w%12],n-1,r-1),u),h)}}function Dg(){const a=m.useRef(null),n=m.useRef(null),r=m.useRef(void 0),[c]=m.useState(()=>new T2(C2)),d=m.useRef({mouse:{x:-10,y:0,lx:0,ly:0,sx:0,sy:0,v:0,vs:0,a:0,set:!1},lines:[],paths:[],noise:c,bounding:null});return m.useEffect(()=>{const u=n.current,h=a.current;if(!u||!h)return;const f=d.current;f.noise=c;const p=()=>{const R=u.getBoundingClientRect();f.bounding=R,h.style.width=`${R.width}px`,h.style.height=`${R.height}px`},g=()=>{if(!f.bounding)return;const{width:R,height:S}=f.bounding;f.lines=[],f.paths.forEach(oe=>oe.remove()),f.paths=[];const B=10,E=32,C=R+200,A=S+30,F=Math.ceil(C/B),L=Math.ceil(A/E),J=(R-B*F)/2,U=(S-E*L)/2;for(let oe=0;oe<=F;oe++){const Ne=[];for(let re=0;re<=L;re++){const fe={x:J+B*oe,y:U+E*re,wave:{x:0,y:0},cursor:{x:0,y:0,vx:0,vy:0}};Ne.push(fe)}const je=document.createElementNS("http://www.w3.org/2000/svg","path");h.appendChild(je),f.paths.push(je),f.lines.push(Ne)}},N=R=>{const{lines:S,mouse:B,noise:E}=f;S.forEach(C=>{C.forEach(A=>{const F=E.perlin2((A.x+R*.0125)*.002,(A.y+R*.005)*.0015)*12;A.wave.x=Math.cos(F)*32,A.wave.y=Math.sin(F)*16;const L=A.x-B.sx,J=A.y-B.sy,U=Math.hypot(L,J),oe=Math.max(175,B.vs);if(U{const B={x:R.x+R.wave.x+(S?R.cursor.x:0),y:R.y+R.wave.y+(S?R.cursor.y:0)};return B.x=Math.round(B.x*10)/10,B.y=Math.round(B.y*10)/10,B},w=()=>{const{lines:R,paths:S}=f;R.forEach((B,E)=>{let C=v(B[0],!1),A=`M ${C.x} ${C.y}`;B.forEach((F,L)=>{const J=L===B.length-1;C=v(F,!J),A+=`L ${C.x} ${C.y}`}),S[E].setAttribute("d",A)})},b=R=>{const{mouse:S}=f;S.sx+=(S.x-S.sx)*.1,S.sy+=(S.y-S.sy)*.1;const B=S.x-S.lx,E=S.y-S.ly,C=Math.hypot(B,E);S.v=C,S.vs+=(C-S.vs)*.1,S.vs=Math.min(100,S.vs),S.lx=S.x,S.ly=S.y,S.a=Math.atan2(E,B),u&&(u.style.setProperty("--x",`${S.sx}px`),u.style.setProperty("--y",`${S.sy}px`)),N(R),w(),r.current=requestAnimationFrame(b)},y=R=>{if(!f.bounding)return;const{mouse:S}=f;S.x=R.pageX-f.bounding.left,S.y=R.pageY-f.bounding.top+window.scrollY,S.set||(S.sx=S.x,S.sy=S.y,S.lx=S.x,S.ly=S.y,S.set=!0)},O=()=>{p(),g()};return p(),g(),window.addEventListener("resize",O),window.addEventListener("mousemove",y),r.current=requestAnimationFrame(b),()=>{window.removeEventListener("resize",O),window.removeEventListener("mousemove",y),r.current&&cancelAnimationFrame(r.current)}},[c]),e.jsxs("div",{ref:n,className:"waves-background",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden",pointerEvents:"none"},children:[e.jsx("div",{className:"waves-cursor",style:{position:"absolute",top:0,left:0,width:"0.5rem",height:"0.5rem",background:"hsl(var(--primary) / 0.3)",borderRadius:"50%",transform:"translate3d(calc(var(--x, -0.5rem) - 50%), calc(var(--y, 50%) - 50%), 0)",willChange:"transform",pointerEvents:"none"}}),e.jsx("svg",{ref:a,style:{display:"block",width:"100%",height:"100%"},children:e.jsx("style",{children:` - path { - fill: none; - stroke: hsl(var(--primary) / 0.20); - stroke-width: 1px; - } - `})})]})}function E2(){const[a,n]=m.useState(""),[r,c]=m.useState(!1),[d,u]=m.useState(""),[h,f]=m.useState(!0),p=ca(),{enableWavesBackground:g,setEnableWavesBackground:N}=Uv(),{theme:v,setTheme:w}=xx();m.useEffect(()=>{(async()=>{try{await cc()&&p({to:"/"})}catch{}finally{f(!1)}})()},[p]);const y=v==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":v,O=()=>{w(y==="dark"?"light":"dark")},R=async S=>{if(S.preventDefault(),u(""),!a.trim()){u("请输入 Access Token");return}c(!0),console.log("开始验证 token...");try{const B=await fetch("/api/webui/auth/verify",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({token:a.trim()})});console.log("Token 验证响应状态:",B.status);const E=await B.json();if(console.log("Token 验证响应数据:",E),B.ok&&E.valid){console.log("Token 验证成功,准备跳转..."),console.log("is_first_setup:",E.is_first_setup),await new Promise(A=>setTimeout(A,100));const C=await cc();console.log("跳转前认证状态检查:",C),E.is_first_setup?(console.log("跳转到首次配置页面"),p({to:"/setup"})):(console.log("跳转到首页"),p({to:"/"}))}else console.error("Token 验证失败:",E.message),u(E.message||"Token 验证失败,请检查后重试")}catch(B){console.error("Token 验证错误:",B),u("连接服务器失败,请检查网络连接")}finally{c(!1)}};return h?e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[g&&e.jsx(Dg,{}),e.jsx("div",{className:"text-muted-foreground",children:"正在检查登录状态..."})]}):e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[g&&e.jsx(Dg,{}),e.jsxs(Ce,{className:"relative z-10 w-full max-w-md shadow-2xl backdrop-blur-xl bg-card/80 border-border/50",children:[e.jsx("button",{onClick:O,className:"absolute right-4 top-4 rounded-lg p-2 hover:bg-accent transition-colors z-10 text-foreground",title:y==="dark"?"切换到浅色模式":"切换到深色模式",children:y==="dark"?e.jsx(ax,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"}):e.jsx(ec,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"})}),e.jsxs(De,{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(bg,{className:"h-8 w-8 text-primary",strokeWidth:2,fill:"none"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-2xl font-bold",children:"欢迎使用 MaiBot"}),e.jsx(os,{className:"text-base",children:"请输入您的 Access Token 以继续访问系统"})]})]}),e.jsx(Me,{children:e.jsxs("form",{onSubmit:R,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"token",className:"text-sm font-medium",children:"Access Token"}),e.jsxs("div",{className:"relative",children:[e.jsx(lx,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground",strokeWidth:2,fill:"none"}),e.jsx(ae,{id:"token",type:"password",placeholder:"请输入您的 Access Token",value:a,onChange:S=>n(S.target.value),className:I("pl-10",d&&"border-red-500 focus-visible:ring-red-500"),disabled:r,autoFocus:!0,autoComplete:"off"})]})]}),d&&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(_t,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{children:d})]}),e.jsx(_,{type:"submit",className:"w-full",disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"验证中..."]}):"验证并进入"}),e.jsxs(Ps,{children:[e.jsx(cd,{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(sv,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我没有 Token,我该去哪里获得 Token?"]})}),e.jsxs(Ds,{className:"sm:max-w-md",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(bg,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"如何获取 Access Token"]}),e.jsx(Ks,{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(S_,{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(Ea,{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(_t,{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(Ns,{children:[e.jsx(wt,{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(el,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),"我觉得这个界面很卡怎么办?"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsxs(hs,{className:"flex items-center gap-2",children:[e.jsx(el,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),"关闭背景动画"]}),e.jsx(fs,{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(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>N(!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:m2})})]})}const ot=m.forwardRef(({className:a,...n},r)=>e.jsx("textarea",{className:I("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","custom-scrollbar",a),ref:r,...n}));ot.displayName="Textarea";const Yt=m.forwardRef(({className:a,orientation:n="horizontal",decorative:r=!0,...c},d)=>e.jsx(bj,{ref:d,decorative:r,orientation:n,className:I("shrink-0 bg-border",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",a),...c}));Yt.displayName=bj.displayName;function M2({config:a,onChange:n}){const r=d=>{d.trim()&&!a.alias_names.includes(d.trim())&&n({...a,alias_names:[...a.alias_names,d.trim()]})},c=d=>{n({...a,alias_names:a.alias_names.filter((u,h)=>h!==d)})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"qq_account",children:"QQ账号 *"}),e.jsx(ae,{id:"qq_account",type:"number",placeholder:"请输入机器人的QQ账号",value:a.qq_account||"",onChange:d=>n({...a,qq_account:Number(d.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人登录使用的QQ账号"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"nickname",children:"昵称 *"}),e.jsx(ae,{id:"nickname",placeholder:"请输入机器人的昵称",value:a.nickname,onChange:d=>n({...a,nickname:d.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人的主要称呼名称"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{children:"别名"}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:a.alias_names.map((d,u)=>e.jsxs(ke,{variant:"secondary",className:"gap-1",children:[d,e.jsx("button",{type:"button",onClick:()=>c(u),className:"ml-1 hover:text-destructive",children:e.jsx(Aa,{className:"h-3 w-3"})})]},u))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{id:"alias_input",placeholder:"输入别名后按回车添加",onKeyPress:d=>{d.key==="Enter"&&(r(d.target.value),d.target.value="")}}),e.jsx(_,{type:"button",variant:"outline",onClick:()=>{const d=document.getElementById("alias_input");d&&(r(d.value),d.value="")},children:"添加"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人的其他称呼,可以添加多个"})]})]})}function A2({config:a,onChange:n}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"personality",children:"人格特征 *"}),e.jsx(ot,{id:"personality",placeholder:"描述机器人的人格特质和身份特征(建议120字以内)",value:a.personality,onChange:r=>n({...a,personality:r.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:是一个女大学生,现在在读大二,会刷贴吧"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"reply_style",children:"表达风格 *"}),e.jsx(ot,{id:"reply_style",placeholder:"描述机器人说话的表达风格、表达习惯",value:a.reply_style,onChange:r=>n({...a,reply_style:r.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"例如:回复平淡一些,简短一些,说中文,参考贴吧、知乎和微博的回复风格"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"interest",children:"兴趣 *"}),e.jsx(ot,{id:"interest",placeholder:"描述机器人感兴趣的话题",value:a.interest,onChange:r=>n({...a,interest:r.target.value}),rows:2}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"会影响机器人对什么话题进行回复"})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"plan_style",children:"群聊说话规则 *"}),e.jsx(ot,{id:"plan_style",placeholder:"机器人在群聊中的行为风格和规则",value:a.plan_style,onChange:r=>n({...a,plan_style:r.target.value}),rows:4}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在群聊中如何行动,例如回复频率、条件等"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"private_plan_style",children:"私聊说话规则 *"}),e.jsx(ot,{id:"private_plan_style",placeholder:"机器人在私聊中的行为风格和规则",value:a.private_plan_style,onChange:r=>n({...a,private_plan_style:r.target.value}),rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"定义机器人在私聊中的行为方式"})]})]})}function z2({config:a,onChange:n}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(a.emoji_chance*100).toFixed(0),"%"]})]}),e.jsx(ae,{id:"emoji_chance",type:"range",min:"0",max:"1",step:"0.1",value:a.emoji_chance,onChange:r=>n({...a,emoji_chance:Number(r.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人发送表情包的概率"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"max_reg_num",children:"最大表情包数量"}),e.jsx(ae,{id:"max_reg_num",type:"number",min:"1",max:"200",value:a.max_reg_num,onChange:r=>n({...a,max_reg_num:Number(r.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"机器人最多保存的表情包数量"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"do_replace",children:"达到最大数量时替换"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"开启后会删除旧表情包,关闭则不再收集新表情包"})]}),e.jsx(Ve,{id:"do_replace",checked:a.do_replace,onCheckedChange:r=>n({...a,do_replace:r})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(ae,{id:"check_interval",type:"number",min:"1",max:"120",value:a.check_interval,onChange:r=>n({...a,check_interval:Number(r.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"检查表情包注册、破损、删除的时间间隔"})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"steal_emoji",children:"偷取表情包"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人将一些表情包据为己有"})]}),e.jsx(Ve,{id:"steal_emoji",checked:a.steal_emoji,onCheckedChange:r=>n({...a,steal_emoji:r})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"content_filtration",children:"启用表情包过滤"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只保存符合要求的表情包"})]}),e.jsx(Ve,{id:"content_filtration",checked:a.content_filtration,onCheckedChange:r=>n({...a,content_filtration:r})})]}),a.content_filtration&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(ae,{id:"filtration_prompt",placeholder:"例如:符合公序良俗",value:a.filtration_prompt,onChange:r=>n({...a,filtration_prompt:r.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"描述表情包应该符合的要求"})]})]})}function R2({config:a,onChange:n}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"enable_tool",children:"启用工具系统"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人使用各种工具增强功能"})]}),e.jsx(Ve,{id:"enable_tool",checked:a.enable_tool,onCheckedChange:r=>n({...a,enable_tool:r})})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"all_global",children:"启用全局黑话模式"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"允许机器人学习和使用群组黑话"})]}),e.jsx(Ve,{id:"all_global",checked:a.all_global,onCheckedChange:r=>n({...a,all_global:r})})]})]})}function D2({config:a,onChange:n}){const[r,c]=m.useState(!1);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"rounded-lg bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5",children:e.jsx("svg",{className:"h-5 w-5 text-blue-600 dark:text-blue-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsxs("div",{className:"flex-1 text-sm",children:[e.jsx("p",{className:"font-medium text-blue-900 dark:text-blue-100 mb-1",children:"关于硅基流动 (SiliconFlow)"}),e.jsx("p",{className:"text-blue-700 dark:text-blue-300 mb-2",children:"硅基流动提供了完整的模型覆盖,包括 DeepSeek V3、Qwen、视觉模型、语音识别和嵌入模型。 只需一个 API Key 即可使用麦麦的所有功能!"}),e.jsxs("a",{href:"https://cloud.siliconflow.cn",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-blue-600 dark:text-blue-400 hover:underline font-medium",children:["前往硅基流动获取 API Key",e.jsx($o,{className:"h-3 w-3"})]})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{htmlFor:"siliconflow_api_key",children:"SiliconFlow API Key *"}),e.jsxs("div",{className:"relative",children:[e.jsx(ae,{id:"siliconflow_api_key",type:r?"text":"password",placeholder:"sk-...",value:a.api_key,onChange:d=>n({api_key:d.target.value}),className:"font-mono pr-10"}),e.jsx(_,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",onClick:()=>c(!r),children:r?e.jsx(nc,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(ia,{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 O2(){const a=await _e("/api/webui/config/bot",{method:"GET",headers:Hs()});if(!a.ok)throw new Error("读取Bot配置失败");const r=(await a.json()).config.bot||{};return{qq_account:r.qq_account||0,nickname:r.nickname||"",alias_names:r.alias_names||[]}}async function L2(){const a=await _e("/api/webui/config/bot",{method:"GET",headers:Hs()});if(!a.ok)throw new Error("读取人格配置失败");const r=(await a.json()).config.personality||{};return{personality:r.personality||"",reply_style:r.reply_style||"",interest:r.interest||"",plan_style:r.plan_style||"",private_plan_style:r.private_plan_style||""}}async function U2(){const a=await _e("/api/webui/config/bot",{method:"GET",headers:Hs()});if(!a.ok)throw new Error("读取表情包配置失败");const r=(await a.json()).config.emoji||{};return{emoji_chance:r.emoji_chance??.4,max_reg_num:r.max_reg_num??40,do_replace:r.do_replace??!0,check_interval:r.check_interval??10,steal_emoji:r.steal_emoji??!0,content_filtration:r.content_filtration??!1,filtration_prompt:r.filtration_prompt||""}}async function $2(){const a=await _e("/api/webui/config/bot",{method:"GET",headers:Hs()});if(!a.ok)throw new Error("读取其他配置失败");const r=(await a.json()).config,c=r.tool||{},d=r.expression||{};return{enable_tool:c.enable_tool??!0,all_global:d.all_global_jargon??!0}}async function B2(){const a=await _e("/api/webui/config/model",{method:"GET",headers:Hs()});if(!a.ok)throw new Error("读取模型配置失败");return{api_key:((await a.json()).config.api_providers||[]).find(u=>u.name==="SiliconFlow")?.api_key||""}}async function P2(a){const n=await _e("/api/webui/config/bot/section/bot",{method:"POST",headers:Hs(),body:JSON.stringify(a)});if(!n.ok){const r=await n.json();throw new Error(r.detail||"保存Bot基础配置失败")}return await n.json()}async function I2(a){const n=await _e("/api/webui/config/bot/section/personality",{method:"POST",headers:Hs(),body:JSON.stringify(a)});if(!n.ok){const r=await n.json();throw new Error(r.detail||"保存人格配置失败")}return await n.json()}async function F2(a){const n=await _e("/api/webui/config/bot/section/emoji",{method:"POST",headers:Hs(),body:JSON.stringify(a)});if(!n.ok){const r=await n.json();throw new Error(r.detail||"保存表情包配置失败")}return await n.json()}async function H2(a){const n=[];n.push(_e("/api/webui/config/bot/section/tool",{method:"POST",headers:Hs(),body:JSON.stringify({enable_tool:a.enable_tool})})),n.push(_e("/api/webui/config/bot/section/expression",{method:"POST",headers:Hs(),body:JSON.stringify({all_global_jargon:a.all_global})}));const r=await Promise.all(n);for(const c of r)if(!c.ok){const d=await c.json();throw new Error(d.detail||"保存其他配置失败")}return{success:!0}}async function V2(a){const n=await _e("/api/webui/config/model",{method:"GET",headers:Hs()});if(!n.ok)throw new Error("读取模型配置失败");const c=(await n.json()).config,d=c.api_providers||[],u=d.findIndex(p=>p.name==="SiliconFlow");u>=0?d[u]={...d[u],api_key:a.api_key}:d.push({name:"SiliconFlow",base_url:"https://api.siliconflow.cn/v1",api_key:a.api_key,client_type:"openai",max_retry:3,timeout:120,retry_interval:5});const h={...c,api_providers:d},f=await _e("/api/webui/config/model",{method:"POST",headers:Hs(),body:JSON.stringify(h)});if(!f.ok){const p=await f.json();throw new Error(p.detail||"保存模型配置失败")}return await f.json()}async function Og(){const a=await _e("/api/webui/setup/complete",{method:"POST"});if(!a.ok){const n=await a.json();throw new Error(n.message||"标记配置完成失败")}return await a.json()}function G2(){return e.jsx(Wn,{children:e.jsx(q2,{})})}function q2(){const a=ca(),{toast:n}=Ys(),{triggerRestart:r}=yn(),[c,d]=m.useState(0),[u,h]=m.useState(!1),[f,p]=m.useState(!1),[g,N]=m.useState(!0),[v,w]=m.useState({qq_account:0,nickname:"",alias_names:[]}),[b,y]=m.useState({personality:"是一个女大学生,现在在读大二,会刷贴吧。",reply_style:"请回复的平淡一些,简短一些,说中文,不要刻意突出自身学科背景。可以参考贴吧,知乎和微博的回复风格。",interest:"对技术相关话题,游戏和动漫相关话题感兴趣,也对日常话题感兴趣,不喜欢太过沉重严肃的话题",plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 -2.如果相同的内容已经被执行,请不要重复执行 -3.请控制你的发言频率,不要太过频繁的发言 -4.如果有人对你感到厌烦,请减少回复 -5.如果有人对你进行攻击,或者情绪激动,请你以合适的方法应对`,private_plan_style:`1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 -2.如果相同的内容已经被执行,请不要重复执行 -3.某句话如果已经被回复过,不要重复回复`}),[O,R]=m.useState({emoji_chance:.4,max_reg_num:40,do_replace:!0,check_interval:10,steal_emoji:!0,content_filtration:!1,filtration_prompt:"符合公序良俗"}),[S,B]=m.useState({enable_tool:!0,all_global:!0}),[E,C]=m.useState({api_key:""}),A=[{id:"bot-basic",title:"Bot基础",description:"配置机器人的基本信息",icon:Vn},{id:"personality",title:"人格配置",description:"定义机器人的性格和说话风格",icon:jn},{id:"emoji",title:"表情包",description:"配置表情包相关设置",icon:ld},{id:"other",title:"其他设置",description:"工具、情绪系统等配置",icon:vn},{id:"siliconflow",title:"API配置",description:"配置硅基流动API密钥",icon:lx}],F=(c+1)/A.length*100;m.useEffect(()=>{(async()=>{try{N(!0);const[fe,ge,M,K,P]=await Promise.all([O2(),L2(),U2(),$2(),B2()]);w(fe),y(ge),R(M),B(K),C(P)}catch(fe){n({title:"加载配置失败",description:fe instanceof Error?fe.message:"无法加载现有配置,将使用默认值",variant:"destructive"})}finally{N(!1)}})()},[n]);const L=async()=>{p(!0);try{switch(c){case 0:await P2(v);break;case 1:await I2(b);break;case 2:await F2(O);break;case 3:await H2(S);break;case 4:await V2(E);break}return n({title:"保存成功",description:`${A[c].title}配置已保存`}),!0}catch(re){return n({title:"保存失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"}),!1}finally{p(!1)}},J=async()=>{await L()&&c{c>0&&d(c-1)},oe=async()=>{h(!0);try{if(!await L()){h(!1);return}await Og(),n({title:"配置完成",description:"麦麦正在重启以应用新配置..."}),await r()}catch(re){n({title:"配置失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"})}finally{h(!1)}},Ne=async()=>{try{await Og(),a({to:"/"})}catch(re){n({title:"跳过失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"})}},je=()=>{switch(c){case 0:return e.jsx(M2,{config:v,onChange:w});case 1:return e.jsx(A2,{config:b,onChange:y});case 2:return e.jsx(z2,{config:O,onChange:R});case 3:return e.jsx(R2,{config:S,onChange:B});case 4:return e.jsx(D2,{config:E,onChange:C});default:return null}};return e.jsxs("div",{className:"relative flex min-h-screen flex-col items-center justify-center overflow-hidden bg-gradient-to-br from-primary/5 via-background to-secondary/5 p-4 md:p-6",children:[e.jsx(er,{}),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(k_,{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:["让我们一起完成 ",hx," 的初始配置"]})]}),e.jsxs("div",{className:"mb-6 md:mb-8",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between text-xs md:text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["步骤 ",c+1," / ",A.length]}),e.jsxs("span",{className:"font-medium text-primary",children:[Math.round(F),"%"]})]}),e.jsx(Xn,{value:F,className:"h-2"})]}),e.jsx("div",{className:"mb-6 md:mb-8 flex justify-between",children:A.map((re,fe)=>{const ge=re.icon;return e.jsxs("div",{className:I("flex flex-1 flex-col items-center gap-1 md:gap-2",fea({to:"/"}),className:"gap-2 w-full sm:w-auto",children:[e.jsx(nd,{className:"h-4 w-4"}),"返回首页"]}),e.jsxs(_,{size:"lg",variant:"outline",onClick:()=>window.history.back(),className:"gap-2 w-full sm:w-auto",children:[e.jsx(Ma,{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 K2=Rs.memo(function({config:n,onChange:r}){const c=n.platforms||[],d=n.alias_names||[],u=()=>{r({...n,platforms:[...c,""]})},h=v=>{r({...n,platforms:c.filter((w,b)=>b!==v)})},f=(v,w)=>{const b=[...c];b[v]=w,r({...n,platforms:b})},p=()=>{r({...n,alias_names:[...d,""]})},g=v=>{r({...n,alias_names:d.filter((w,b)=>b!==v)})},N=(v,w)=>{const b=[...d];b[v]=w,r({...n,alias_names:b})};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(T,{htmlFor:"platform",children:"平台"}),e.jsx(ae,{id:"platform",value:n.platform,onChange:v=>r({...n,platform:v.target.value}),placeholder:"qq"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"qq_account",children:"QQ账号"}),e.jsx(ae,{id:"qq_account",value:n.qq_account,onChange:v=>r({...n,qq_account:v.target.value}),placeholder:"123456789"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"nickname",children:"昵称"}),e.jsx(ae,{id:"nickname",value:n.nickname,onChange:v=>r({...n,nickname:v.target.value}),placeholder:"麦麦"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"别名"}),e.jsxs(_,{onClick:p,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[d.map((v,w)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{value:v,onChange:b=>N(w,b.target.value),placeholder:"小麦"}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除别名 "',v||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>g(w),children:"删除"})]})]})]})]},w)),d.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(T,{children:"其他平台账号"}),e.jsxs(_,{onClick:u,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加"]})]}),e.jsxs("div",{className:"space-y-2",children:[c.map((v,w)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{value:v,onChange:b=>f(w,b.target.value),placeholder:"wx:114514"}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除平台账号 "',v||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>h(w),children:"删除"})]})]})]})]},w)),c.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"暂无其他平台账号"})]})]})]})]})})}),Q2=Rs.memo(function({config:n,onChange:r}){const c=()=>{r({...n,states:[...n.states,""]})},d=h=>{r({...n,states:n.states.filter((f,p)=>p!==h)})},u=(h,f)=>{const p=[...n.states];p[h]=f,r({...n,states:p})};return e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"人格设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"personality",children:"人格特质"}),e.jsx(ot,{id:"personality",value:n.personality,onChange:h=>r({...n,personality:h.target.value}),placeholder:"描述人格特质和身份特征(建议120字以内)",rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"建议120字以内,描述人格特质和身份特征"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"多重人格"}),e.jsxs(_,{onClick:c,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加人格"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"可以定义多个不同的人格状态,麦麦会随机切换"}),e.jsx("div",{className:"space-y-2",children:n.states.map((h,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ot,{value:h,onChange:p=>u(f,p.target.value),placeholder:"描述一个人格状态",rows:2}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsx(fs,{children:"确定要删除这个人格状态吗?此操作无法撤销。"})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>d(f),children:"删除"})]})]})]})]},f))})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"state_probability",children:"替换为多重人格概率"}),e.jsx(ae,{id:"state_probability",type:"number",step:"0.1",min:"0",max:"1",value:n.state_probability,onChange:h=>r({...n,state_probability:parseFloat(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"每次构建人格时,用多重人格替换主人格的概率(0.0-1.0)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"reply_style",children:"表达风格"}),e.jsx(ot,{id:"reply_style",value:n.reply_style,onChange:h=>r({...n,reply_style:h.target.value}),placeholder:"描述说话的表达风格和习惯",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"plan_style",children:"说话规则与行为风格"}),e.jsx(ot,{id:"plan_style",value:n.plan_style,onChange:h=>r({...n,plan_style:h.target.value}),placeholder:"麦麦的说话规则和行为风格",rows:5})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"visual_style",children:"识图规则"}),e.jsx(ot,{id:"visual_style",value:n.visual_style,onChange:h=>r({...n,visual_style:h.target.value}),placeholder:"识图时的处理规则",rows:3})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"private_plan_style",children:"私聊规则"}),e.jsx(ot,{id:"private_plan_style",value:n.private_plan_style,onChange:h=>r({...n,private_plan_style:h.target.value}),placeholder:"私聊的说话规则和行为风格",rows:4})]})]})]})})}),ul=bw,ml=yw,sl=m.forwardRef(({className:a,align:n="center",sideOffset:r=4,...c},d)=>e.jsx(Nw,{children:e.jsx(yj,{ref:d,align:n,sideOffset:r,className:I("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]",a),...c})}));sl.displayName=yj.displayName;const Y2=Rs.memo(function({value:n,onChange:r}){const c=m.useMemo(()=>{const b=n.split("-");if(b.length===2){const[y,O]=b,[R,S]=y.split(":"),[B,E]=O.split(":");return{startHour:R?R.padStart(2,"0"):"00",startMinute:S?S.padStart(2,"0"):"00",endHour:B?B.padStart(2,"0"):"23",endMinute:E?E.padStart(2,"0"):"59"}}return{startHour:"00",startMinute:"00",endHour:"23",endMinute:"59"}},[n]),[d,u]=m.useState(c.startHour),[h,f]=m.useState(c.startMinute),[p,g]=m.useState(c.endHour),[N,v]=m.useState(c.endMinute);m.useEffect(()=>{u(c.startHour),f(c.startMinute),g(c.endHour),v(c.endMinute)},[c]);const w=(b,y,O,R)=>{const S=`${b}:${y}-${O}:${R}`;r(S)};return e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",className:"w-full justify-start font-mono text-sm",children:[e.jsx(na,{className:"h-4 w-4 mr-2"}),n||"选择时间段"]})}),e.jsx(sl,{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(T,{className:"text-xs",children:"小时"}),e.jsxs(Pe,{value:d,onValueChange:b=>{u(b),w(b,h,p,N)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsx(Be,{children:Array.from({length:24},(b,y)=>y).map(b=>e.jsx(Z,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"分钟"}),e.jsxs(Pe,{value:h,onValueChange:b=>{f(b),w(d,b,p,N)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsx(Be,{children:Array.from({length:60},(b,y)=>y).map(b=>e.jsx(Z,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm mb-3",children:"结束时间"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:gap-3",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"小时"}),e.jsxs(Pe,{value:p,onValueChange:b=>{g(b),w(d,h,b,N)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsx(Be,{children:Array.from({length:24},(b,y)=>y).map(b=>e.jsx(Z,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs",children:"分钟"}),e.jsxs(Pe,{value:N,onValueChange:b=>{v(b),w(d,h,p,b)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsx(Be,{children:Array.from({length:60},(b,y)=>y).map(b=>e.jsx(Z,{value:b.toString().padStart(2,"0"),children:b.toString().padStart(2,"0")},b))})]})]})]})]})]})})]})}),J2=Rs.memo(function({rule:n}){const r=`{ target = "${n.target}", time = "${n.time}", value = ${n.value.toFixed(1)} }`;return e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",children:[e.jsx(ia,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(sl,{className:"w-80 sm:w-96",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:r}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})}),X2=Rs.memo(function({config:n,onChange:r}){const c=()=>{r({...n,talk_value_rules:[...n.talk_value_rules,{target:"",time:"00:00-23:59",value:1}]})},d=h=>{r({...n,talk_value_rules:n.talk_value_rules.filter((f,p)=>p!==h)})},u=(h,f,p)=>{const g=[...n.talk_value_rules];g[h]={...g[h],[f]:p},r({...n,talk_value_rules:g})};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"聊天设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"talk_value",children:"聊天频率(基础值)"}),e.jsx(ae,{id:"talk_value",type:"number",step:"0.1",min:"0",max:"1",value:n.talk_value,onChange:h=>r({...n,talk_value:parseFloat(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"越小越沉默,范围 0-1"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"think_mode",children:"思考模式"}),e.jsxs(Pe,{value:n.think_mode||"classic",onValueChange:h=>r({...n,think_mode:h}),children:[e.jsx($e,{id:"think_mode",children:e.jsx(Ie,{placeholder:"选择思考模式"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"classic",children:"经典模式 - 浅度思考和回复"}),e.jsx(Z,{value:"deep",children:"深度模式 - 进行深度思考和回复"}),e.jsx(Z,{value:"dynamic",children:"动态模式 - 自动选择思考深度"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"控制麦麦的思考深度。经典模式回复快但简单;深度模式更深入但较慢;动态模式根据情况自动选择"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"mentioned_bot_reply",checked:n.mentioned_bot_reply,onCheckedChange:h=>r({...n,mentioned_bot_reply:h})}),e.jsx(T,{htmlFor:"mentioned_bot_reply",className:"cursor-pointer",children:"启用提及必回复"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"max_context_size",children:"上下文长度"}),e.jsx(ae,{id:"max_context_size",type:"number",min:"1",value:n.max_context_size,onChange:h=>r({...n,max_context_size:parseInt(h.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"planner_smooth",children:"规划器平滑"}),e.jsx(ae,{id:"planner_smooth",type:"number",step:"1",min:"0",value:n.planner_smooth,onChange:h=>r({...n,planner_smooth:parseFloat(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"增大数值会减小 planner 负荷,推荐 1-5,0 为关闭"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"plan_reply_log_max_per_chat",children:"每个聊天流最大日志数量"}),e.jsx(ae,{id:"plan_reply_log_max_per_chat",type:"number",step:"1",min:"100",value:n.plan_reply_log_max_per_chat??1024,onChange:h=>r({...n,plan_reply_log_max_per_chat:parseInt(h.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"每个聊天流保存的 Plan/Reply 日志最大数量,超过此数量时会自动删除最老的日志"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"llm_quote",checked:n.llm_quote??!1,onCheckedChange:h=>r({...n,llm_quote:h})}),e.jsx(T,{htmlFor:"llm_quote",className:"cursor-pointer",children:"启用 LLM 控制引用"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2 ml-10",children:"启用后,LLM 可以决定是否在回复时引用消息"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"enable_talk_value_rules",checked:n.enable_talk_value_rules,onCheckedChange:h=>r({...n,enable_talk_value_rules:h})}),e.jsx(T,{htmlFor:"enable_talk_value_rules",className:"cursor-pointer",children:"启用动态发言频率规则"})]})]})]}),n.enable_talk_value_rules&&e.jsxs("div",{className:"border-t pt-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-semibold",children:"动态发言频率规则"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"按时段或聊天流ID调整发言频率,优先匹配具体聊天,再匹配全局规则"})]}),e.jsxs(_,{onClick:c,size:"sm",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),n.talk_value_rules&&n.talk_value_rules.length>0?e.jsx("div",{className:"space-y-4",children:n.talk_value_rules.map((h,f)=>e.jsxs("div",{className:"rounded-lg border p-4 bg-muted/50 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:["规则 #",f+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J2,{rule:h}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{variant:"ghost",size:"sm",children:e.jsx(ns,{className:"h-4 w-4 text-destructive"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除规则 #",f+1," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>d(f),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(Pe,{value:h.target===""?"global":"specific",onValueChange:p=>{p==="global"?u(f,"target",""):u(f,"target","qq::group")},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"global",children:"全局配置"}),e.jsx(Z,{value:"specific",children:"详细配置"})]})]})]}),h.target!==""&&(()=>{const p=h.target.split(":"),g=p[0]||"qq",N=p[1]||"",v=p[2]||"group";return e.jsxs("div",{className:"grid gap-4 p-3 sm:p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Pe,{value:g,onValueChange:w=>{u(f,"target",`${w}:${N}:${v}`)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"qq",children:"QQ"}),e.jsx(Z,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(ae,{value:N,onChange:w=>{u(f,"target",`${g}:${w.target.value}:${v}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Pe,{value:v,onValueChange:w=>{u(f,"target",`${g}:${N}:${w}`)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"group",children:"群组(group)"}),e.jsx(Z,{value:"private",children:"私聊(private)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前聊天流 ID:",h.target||"(未设置)"]})]})})(),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"时间段 (Time)"}),e.jsx(Y2,{value:h.time,onChange:p=>u(f,"time",p)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"支持跨夜区间,例如 23:00-02:00"})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{htmlFor:`rule-value-${f}`,className:"text-xs font-medium",children:"发言频率值 (Value)"}),e.jsx(ae,{id:`rule-value-${f}`,type:"number",step:"0.01",min:"0.01",max:"1",value:h.value,onChange:p=>{const g=parseFloat(p.target.value);isNaN(g)||u(f,"value",Math.max(.01,Math.min(1,g)))},className:"w-20 h-8 text-xs"})]}),e.jsx(Qa,{value:[h.value],onValueChange:p=>u(f,"value",p[0]),min:.01,max:1,step:.01,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"0.01 (极少发言)"}),e.jsx("span",{children:"0.5"}),e.jsx("span",{children:"1.0 (正常)"})]})]})]})]},f))}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:e.jsx("p",{className:"text-sm",children:'暂无规则,点击"添加规则"按钮创建'})}),e.jsxs("div",{className:"mt-4 p-4 bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800 rounded-lg",children:[e.jsx("h5",{className:"text-sm font-semibold text-blue-900 dark:text-blue-100 mb-2",children:"📝 规则说明"}),e.jsxs("ul",{className:"text-xs text-blue-800 dark:text-blue-200 space-y-1",children:[e.jsxs("li",{children:["• ",e.jsx("strong",{children:"Target 为空"}),":全局规则,对所有聊天生效"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"Target 指定"}),":仅对特定聊天流生效(格式:platform:id:type)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"优先级"}),":先匹配具体聊天流规则,再匹配全局规则"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"时间支持跨夜"}),":例如 23:00-02:00 表示晚上11点到次日凌晨2点"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"数值范围"}),":建议 0-1,0 表示完全沉默,1 表示正常发言"]})]})]})]})]})}),Z2=Rs.memo(function({config:n,onChange:r}){const c=S=>{if(!S||!S.includes(":"))return{platform:"qq",userId:""};const[B,E]=S.split(":");return{platform:B,userId:E}},{platform:d,userId:u}=c(n.dream_send),[h,f]=m.useState(d),[p,g]=m.useState(u),N=S=>{const[B,E]=S.split("-");return{startTime:B||"09:00",endTime:E||"22:00"}},v=(S,B)=>{const E=B?`${S}:${B}`:"";r({...n,dream_send:E})},w=S=>{f(S),v(S,p)},b=S=>{g(S),v(h,S)},y=()=>{r({...n,dream_time_ranges:[...n.dream_time_ranges,"09:00-22:00"]})},O=S=>{r({...n,dream_time_ranges:n.dream_time_ranges.filter((B,E)=>E!==S)})},R=(S,B,E)=>{const C=[...n.dream_time_ranges],A=N(C[S]);B==="startTime"?A.startTime=E:A.endTime=E,C[S]=`${A.startTime}-${A.endTime}`,r({...n,dream_time_ranges:C})};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"做梦配置"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"interval_minutes",children:"做梦时间间隔(分钟)"}),e.jsx(ae,{id:"interval_minutes",type:"number",min:"1",value:n.interval_minutes,onChange:S=>r({...n,interval_minutes:Number(S.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"默认30分钟"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"max_iterations",children:"做梦最大轮次"}),e.jsx(ae,{id:"max_iterations",type:"number",min:"1",value:n.max_iterations,onChange:S=>r({...n,max_iterations:Number(S.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"默认20轮"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"first_delay_seconds",children:"首次做梦延迟(秒)"}),e.jsx(ae,{id:"first_delay_seconds",type:"number",min:"0",value:n.first_delay_seconds,onChange:S=>r({...n,first_delay_seconds:Number(S.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"程序启动后首次做梦前的延迟时间,默认60秒"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"做梦结果推送目标"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Pe,{value:h,onValueChange:w,children:[e.jsx($e,{className:"w-[120px]",children:e.jsx(Ie,{placeholder:"选择平台"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"qq",children:"QQ"}),e.jsx(Z,{value:"wx",children:"微信"}),e.jsx(Z,{value:"webui",children:"WebUI"})]})]}),e.jsx(ae,{type:"text",placeholder:"输入用户ID (例如: 123456)",value:p,onChange:S=>b(S.target.value),className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"选择平台并输入用户ID,做梦结束后将梦境发送给该用户。用户ID为空则不推送"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"做梦时间段配置"}),e.jsx(_,{type:"button",size:"sm",onClick:y,children:"添加时间段"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"设置允许做梦的时间段,支持跨夜区间(如 23:00 到次日 02:00)。列表为空则全天允许做梦"}),e.jsxs("div",{className:"space-y-2",children:[n.dream_time_ranges.map((S,B)=>{const{startTime:E,endTime:C}=N(S);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{type:"time",value:E,onChange:A=>R(B,"startTime",A.target.value),className:"w-[140px]"}),e.jsx("span",{className:"text-muted-foreground",children:"至"}),e.jsx(ae,{type:"time",value:C,onChange:A=>R(B,"endTime",A.target.value),className:"w-[140px]"}),e.jsx(_,{type:"button",variant:"ghost",size:"icon",onClick:()=>O(B),children:e.jsx(Aa,{className:"h-4 w-4"})})]},B)}),n.dream_time_ranges.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"当前配置为全天允许做梦"})]})]})]})}),W2=Rs.memo(function({config:n,onChange:r}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库设置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.enable,onCheckedChange:c=>r({...n,enable:c})}),e.jsx(T,{className:"cursor-pointer",children:"启用 LPMM 知识库"})]}),n.enable&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"LPMM 模式"}),e.jsxs(Pe,{value:n.lpmm_mode,onValueChange:c=>r({...n,lpmm_mode:c}),children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:"选择 LPMM 模式"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"classic",children:"经典模式"}),e.jsx(Z,{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(T,{children:"同义词搜索 TopK"}),e.jsx(ae,{type:"number",min:"1",value:n.rag_synonym_search_top_k,onChange:c=>r({...n,rag_synonym_search_top_k:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"同义词阈值"}),e.jsx(ae,{type:"number",step:"0.1",min:"0",max:"1",value:n.rag_synonym_threshold,onChange:c=>r({...n,rag_synonym_threshold:parseFloat(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"实体提取线程数"}),e.jsx(ae,{type:"number",min:"1",value:n.info_extraction_workers,onChange:c=>r({...n,info_extraction_workers:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"嵌入向量维度"}),e.jsx(ae,{type:"number",min:"1",value:n.embedding_dimension,onChange:c=>r({...n,embedding_dimension:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"嵌入并发线程数"}),e.jsx(ae,{type:"number",min:"1",value:n.max_embedding_workers,onChange:c=>r({...n,max_embedding_workers:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"每批嵌入条数"}),e.jsx(ae,{type:"number",min:"1",value:n.embedding_chunk_size,onChange:c=>r({...n,embedding_chunk_size:parseInt(c.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"同义实体数上限"}),e.jsx(ae,{type:"number",min:"1",value:n.max_synonym_entities,onChange:c=>r({...n,max_synonym_entities:parseInt(c.target.value)})})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.enable_ppr,onCheckedChange:c=>r({...n,enable_ppr:c})}),e.jsx(T,{className:"cursor-pointer",children:"启用 PPR (低配机器可关闭)"})]})]})]})]})}),eS=Rs.memo(function({config:n,onChange:r}){const[c,d]=m.useState(""),[u,h]=m.useState("WARNING"),f=()=>{c&&!n.suppress_libraries.includes(c)&&(r({...n,suppress_libraries:[...n.suppress_libraries,c]}),d(""))},p=y=>{r({...n,suppress_libraries:n.suppress_libraries.filter(O=>O!==y)})},g=()=>{c&&!n.library_log_levels[c]&&(r({...n,library_log_levels:{...n.library_log_levels,[c]:u}}),d(""),h("WARNING"))},N=y=>{const O={...n.library_log_levels};delete O[y],r({...n,library_log_levels:O})},v=["DEBUG","INFO","WARNING","ERROR","CRITICAL"],w=["FULL","compact","lite"],b=["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(T,{children:"日期格式"}),e.jsx(ae,{value:n.date_style,onChange:y=>r({...n,date_style:y.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(T,{children:"日志级别样式"}),e.jsxs(Pe,{value:n.log_level_style,onValueChange:y=>r({...n,log_level_style:y}),children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsx(Be,{children:w.map(y=>e.jsx(Z,{value:y,children:y},y))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"日志文本颜色"}),e.jsxs(Pe,{value:n.color_text,onValueChange:y=>r({...n,color_text:y}),children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsx(Be,{children:b.map(y=>e.jsx(Z,{value:y,children:y},y))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"全局日志级别"}),e.jsxs(Pe,{value:n.log_level,onValueChange:y=>r({...n,log_level:y}),children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsx(Be,{children:v.map(y=>e.jsx(Z,{value:y,children:y},y))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"控制台日志级别"}),e.jsxs(Pe,{value:n.console_log_level,onValueChange:y=>r({...n,console_log_level:y}),children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsx(Be,{children:v.map(y=>e.jsx(Z,{value:y,children:y},y))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"文件日志级别"}),e.jsxs(Pe,{value:n.file_log_level,onValueChange:y=>r({...n,file_log_level:y}),children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsx(Be,{children:v.map(y=>e.jsx(Z,{value:y,children:y},y))})]})]})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"mb-2 block",children:"完全屏蔽的库"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ae,{value:c,onChange:y=>d(y.target.value),placeholder:"输入库名",className:"flex-1",onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),f())}}),e.jsx(_,{onClick:f,size:"sm",className:"flex-shrink-0",children:e.jsx(et,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:n.suppress_libraries.map(y=>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:y}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0",onClick:()=>p(y),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},y))})]}),e.jsxs("div",{children:[e.jsx(T,{className:"mb-2 block",children:"特定库的日志级别"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ae,{value:c,onChange:y=>d(y.target.value),placeholder:"输入库名",className:"flex-1"}),e.jsxs(Pe,{value:u,onValueChange:h,children:[e.jsx($e,{className:"w-32",children:e.jsx(Ie,{})}),e.jsx(Be,{children:v.map(y=>e.jsx(Z,{value:y,children:y},y))})]}),e.jsx(_,{onClick:g,size:"sm",children:e.jsx(et,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:Object.entries(n.library_log_levels).map(([y,O])=>e.jsxs("div",{className:"flex items-center justify-between bg-secondary px-3 py-2 rounded-md",children:[e.jsx("span",{className:"text-sm font-medium",children:y}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:O}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>N(y),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]})]},y))})]})]})}),sS=Rs.memo(function({config:n,onChange:r}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"调试配置"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否在日志中显示提示词"})]}),e.jsx(Ve,{checked:n.show_prompt,onCheckedChange:c=>r({...n,show_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示回复器 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的提示词"})]}),e.jsx(Ve,{checked:n.show_replyer_prompt,onCheckedChange:c=>r({...n,show_replyer_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示回复器推理"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示回复器的推理过程"})]}),e.jsx(Ve,{checked:n.show_replyer_reasoning,onCheckedChange:c=>r({...n,show_replyer_reasoning:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示 Jargon Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示术语相关的提示词"})]}),e.jsx(Ve,{checked:n.show_jargon_prompt,onCheckedChange:c=>r({...n,show_jargon_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示记忆检索 Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示记忆检索相关的提示词"})]}),e.jsx(Ve,{checked:n.show_memory_prompt,onCheckedChange:c=>r({...n,show_memory_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示 Planner Prompt"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 Planner 的提示词和原始返回结果"})]}),e.jsx(Ve,{checked:n.show_planner_prompt,onCheckedChange:c=>r({...n,show_planner_prompt:c})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"显示 LPMM 相关文段"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否显示 LPMM 知识库找到的相关文段日志"})]}),e.jsx(Ve,{checked:n.show_lpmm_paragraph,onCheckedChange:c=>r({...n,show_lpmm_paragraph:c})})]})]})]})}),tS=Rs.memo(function({config:n,onChange:r}){const[c,d]=m.useState(""),[u,h]=m.useState(""),f=()=>{c&&!n.auth_token.includes(c)&&(r({...n,auth_token:[...n.auth_token,c]}),d(""))},p=v=>{r({...n,auth_token:n.auth_token.filter((w,b)=>b!==v)})},g=()=>{u&&!n.api_server_allowed_api_keys.includes(u)&&(r({...n,api_server_allowed_api_keys:[...n.api_server_allowed_api_keys,u]}),h(""))},N=v=>{r({...n,api_server_allowed_api_keys:n.api_server_allowed_api_keys.filter((w,b)=>b!==v)})};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"旧版 API 认证令牌"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"用于旧版 API 验证,为空则不启用验证"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ae,{value:c,onChange:v=>d(v.target.value),placeholder:"输入认证令牌",onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),f())}}),e.jsx(_,{onClick:f,size:"sm",children:e.jsx(et,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:n.auth_token.map((v,w)=>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:v}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>p(w),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},w))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"新版 API Server 配置"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"启用新版 API Server"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"是否启用额外的新版 API Server(额外监听端口)"})]}),e.jsx(Ve,{checked:n.enable_api_server,onCheckedChange:v=>r({...n,enable_api_server:v})})]}),n.enable_api_server&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"主机地址"}),e.jsx(ae,{value:n.api_server_host,onChange:v=>r({...n,api_server_host:v.target.value}),placeholder:"0.0.0.0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"端口号"}),e.jsx(ae,{type:"number",value:n.api_server_port,onChange:v=>r({...n,api_server_port:parseInt(v.target.value)}),placeholder:"8090"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.api_server_use_wss,onCheckedChange:v=>r({...n,api_server_use_wss:v})}),e.jsx(T,{children:"启用 WSS 安全连接"})]}),n.api_server_use_wss&&e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"SSL 证书文件路径"}),e.jsx(ae,{value:n.api_server_cert_file,onChange:v=>r({...n,api_server_cert_file:v.target.value}),placeholder:"cert.pem"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"SSL 密钥文件路径"}),e.jsx(ae,{value:n.api_server_key_file,onChange:v=>r({...n,api_server_key_file:v.target.value}),placeholder:"key.pem"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"mb-2 block",children:"允许的 API Key 列表"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"为空则允许所有连接"}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(ae,{value:u,onChange:v=>h(v.target.value),placeholder:"输入 API Key",onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),g())}}),e.jsx(_,{onClick:g,size:"sm",children:e.jsx(et,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]}),e.jsx("div",{className:"space-y-2",children:n.api_server_allowed_api_keys.map((v,w)=>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:v}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>N(w),children:e.jsx(ns,{className:"h-3 w-3",strokeWidth:2,fill:"none"})})]},w))})]})]})]})]})]})}),aS=Rs.memo(function({config:n,onChange:r}){return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"统计信息"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:"启用统计信息发送"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"发送匿名统计信息,帮助我们了解全球有多少只麦麦在运行"})]}),e.jsx(Ve,{checked:n.enable,onCheckedChange:c=>r({...n,enable:c})})]})]})}),lS=Rs.memo(function({emojiConfig:n,memoryConfig:r,toolConfig:c,voiceConfig:d,onEmojiChange:u,onMemoryChange:h,onToolChange:f,onVoiceChange:p}){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:"space-y-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"enable_tool",checked:c.enable_tool,onCheckedChange:g=>f({...c,enable_tool:g})}),e.jsx(T,{htmlFor:"enable_tool",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 pt-2",children:[e.jsx(Ve,{id:"enable_asr",checked:d.enable_asr,onCheckedChange:g=>p({...d,enable_asr:g})}),e.jsx(T,{htmlFor:"enable_asr",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(T,{htmlFor:"max_agent_iterations",children:"记忆思考深度"}),e.jsx(ae,{id:"max_agent_iterations",type:"number",min:"1",value:r.max_agent_iterations,onChange:g=>h({...r,max_agent_iterations:parseInt(g.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"最低为 1(不深入思考)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"agent_timeout_seconds",children:"最长回忆时间(秒)"}),e.jsx(ae,{id:"agent_timeout_seconds",type:"number",min:"1",step:"0.1",value:r.agent_timeout_seconds??120,onChange:g=>h({...r,agent_timeout_seconds:parseFloat(g.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(Ve,{id:"enable_jargon_detection",checked:r.enable_jargon_detection??!0,onCheckedChange:g=>h({...r,enable_jargon_detection:g})}),e.jsx(T,{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(Ve,{id:"global_memory",checked:r.global_memory??!1,onCheckedChange:g=>h({...r,global_memory:g})}),e.jsx(T,{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(T,{htmlFor:"emoji_chance",children:"表情包激活概率"}),e.jsx(ae,{id:"emoji_chance",type:"number",step:"0.1",min:"0",max:"1",value:n.emoji_chance,onChange:g=>u({...n,emoji_chance:parseFloat(g.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"范围 0-1,越大越容易发送表情包"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"max_reg_num",children:"最大注册数量"}),e.jsx(ae,{id:"max_reg_num",type:"number",min:"1",value:n.max_reg_num,onChange:g=>u({...n,max_reg_num:parseInt(g.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦最多可以注册的表情包数量"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"check_interval",children:"检查间隔(分钟)"}),e.jsx(ae,{id:"check_interval",type:"number",min:"1",value:n.check_interval,onChange:g=>u({...n,check_interval:parseInt(g.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(Ve,{id:"do_replace",checked:n.do_replace,onCheckedChange:g=>u({...n,do_replace:g})}),e.jsx(T,{htmlFor:"do_replace",className:"cursor-pointer",children:"达到最大数量时替换表情包"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"steal_emoji",checked:n.steal_emoji,onCheckedChange:g=>u({...n,steal_emoji:g})}),e.jsx(T,{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(Ve,{id:"content_filtration",checked:n.content_filtration,onCheckedChange:g=>u({...n,content_filtration:g})}),e.jsx(T,{htmlFor:"content_filtration",className:"cursor-pointer",children:"启用表情包过滤"})]}),n.content_filtration&&e.jsxs("div",{className:"grid gap-2 pl-6 border-l-2 border-primary/20",children:[e.jsx(T,{htmlFor:"filtration_prompt",children:"过滤要求"}),e.jsx(ae,{id:"filtration_prompt",value:n.filtration_prompt,onChange:g=>u({...n,filtration_prompt:g.target.value}),placeholder:"符合公序良俗"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只有符合此要求的表情包才会被保存"})]})]})]})})]})}),nS=Rs.memo(function({member:n,groupIndex:r,memberIndex:c,availableChatIds:d,onUpdate:u,onRemove:h}){const f=d.includes(n)||n==="*",[p,g]=m.useState(!f);return e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 flex gap-2",children:p?e.jsxs(e.Fragment,{children:[e.jsx(ae,{value:n,onChange:N=>u(r,c,N.target.value),placeholder:'输入 "*" 或 "qq:123456:group"',className:"flex-1"}),d.length>0&&e.jsx(_,{size:"sm",variant:"outline",onClick:()=>g(!1),title:"切换到下拉选择",children:"下拉"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Pe,{value:n,onValueChange:N=>u(r,c,N),children:[e.jsx($e,{className:"flex-1",children:e.jsx(Ie,{placeholder:"选择聊天流"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"*",children:"* (全局共享)"}),d.map((N,v)=>e.jsx(Z,{value:N,children:N},v))]})]}),e.jsx(_,{size:"sm",variant:"outline",onClick:()=>g(!0),title:"切换到手动输入",children:"输入"})]})}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除组成员 "',n||"(空)",'" 吗?此操作无法撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>h(r,c),children:"删除"})]})]})]})]})}),rS=Rs.memo(function({config:n,onChange:r}){const c=()=>{r({...n,learning_list:[...n.learning_list,["","enable","enable","1.0"]]})},d=w=>{r({...n,learning_list:n.learning_list.filter((b,y)=>y!==w)})},u=(w,b,y)=>{const O=[...n.learning_list];O[w][b]=y,r({...n,learning_list:O})},h=({rule:w})=>{const b=`["${w[0]}", "${w[1]}", "${w[2]}", "${w[3]}"]`;return e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",children:[e.jsx(ia,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(sl,{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:b}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},f=()=>{r({...n,expression_groups:[...n.expression_groups,[]]})},p=w=>{r({...n,expression_groups:n.expression_groups.filter((b,y)=>y!==w)})},g=w=>{const b=[...n.expression_groups];b[w]=[...b[w],""],r({...n,expression_groups:b})},N=(w,b)=>{const y=[...n.expression_groups];y[w]=y[w].filter((O,R)=>R!==b),r({...n,expression_groups:y})},v=(w,b,y)=>{const O=[...n.expression_groups];O[w][b]=y,r({...n,expression_groups:O})};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-4",children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"黑话设置"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"all_global_jargon",checked:n.all_global_jargon??!1,onCheckedChange:w=>r({...n,all_global_jargon:w})}),e.jsx(T,{htmlFor:"all_global_jargon",className:"cursor-pointer",children:"全局黑话模式"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"开启后,新增的黑话将默认设为全局(所有聊天流共享)。关闭后,已记录的全局黑话不会改变,需要手动删除。"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"enable_jargon_explanation",checked:n.enable_jargon_explanation??!0,onCheckedChange:w=>r({...n,enable_jargon_explanation:w})}),e.jsx(T,{htmlFor:"enable_jargon_explanation",className:"cursor-pointer",children:"启用黑话解释"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"在回复前尝试对上下文中的黑话进行解释。关闭可减少一次LLM调用,仅影响回复前的黑话匹配与解释,不影响黑话学习。"})]}),e.jsxs("div",{children:[e.jsx(T,{htmlFor:"jargon_mode",children:"黑话解释来源模式"}),e.jsxs(Pe,{value:n.jargon_mode??"context",onValueChange:w=>r({...n,jargon_mode:w}),children:[e.jsx($e,{id:"jargon_mode",className:"mt-2",children:e.jsx(Ie,{placeholder:"选择黑话解释来源"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"context",children:"上下文模式(自动匹配黑话)"}),e.jsx(Z,{value:"planner",children:"Planner模式(使用unknown_words列表)"})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["上下文模式:使用上下文自动匹配黑话并解释",e.jsx("br",{}),"Planner模式:仅使用Planner在reply动作中给出的unknown_words列表进行黑话检索"]})]})]}),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(_,{onClick:c,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加规则"]})]}),e.jsxs("div",{className:"space-y-4",children:[n.learning_list.map((w,b)=>{const y=n.learning_list.some((C,A)=>A!==b&&C[0]===""),O=w[0]==="",R=w[0].split(":"),S=R[0]||"qq",B=R[1]||"",E=R[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:["规则 ",b+1," ",O&&"(全局配置)"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{rule:w}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除学习规则 ",b+1," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>d(b),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"配置类型"}),e.jsxs(Pe,{value:O?"global":"specific",onValueChange:C=>{C==="global"?u(b,0,""):u(b,0,"qq::group")},disabled:y&&!O,children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"global",children:"全局配置"}),e.jsx(Z,{value:"specific",disabled:y&&!O,children:"详细配置"})]})]}),y&&!O&&e.jsx("p",{className:"text-xs text-amber-600",children:"已存在全局配置,无法创建新的全局配置"})]}),!O&&e.jsxs("div",{className:"grid gap-4 p-3 sm:p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Pe,{value:S,onValueChange:C=>{u(b,0,`${C}:${B}:${E}`)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"qq",children:"QQ"}),e.jsx(Z,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"群 ID"}),e.jsx(ae,{value:B,onChange:C=>{u(b,0,`${S}:${C.target.value}:${E}`)},placeholder:"输入群 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Pe,{value:E,onValueChange:C=>{u(b,0,`${S}:${B}:${C}`)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"group",children:"群组(group)"}),e.jsx(Z,{value:"private",children:"私聊(private)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前聊天流 ID:",w[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(T,{className:"text-xs font-medium",children:"使用学到的表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦使用从聊天中学到的表达方式"})]}),e.jsx(Ve,{checked:w[1]==="enable",onCheckedChange:C=>u(b,1,C?"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(T,{className:"text-xs font-medium",children:"学习表达"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦从聊天中学习新的表达方式"})]}),e.jsx(Ve,{checked:w[2]==="enable",onCheckedChange:C=>u(b,2,C?"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(T,{className:"text-xs font-medium",children:"启用黑话学习"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"允许麦麦在此聊天流中学习和记录黑话"})]}),e.jsx(Ve,{checked:w[3]==="true"||w[3]==="enable",onCheckedChange:C=>u(b,3,C?"true":"false")})]})})]})]},b)}),n.learning_list.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无学习规则,点击"添加规则"开始配置'})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{className:"space-y-6",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("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"expression_self_reflect",className:"cursor-pointer font-medium",children:"自动表达优化"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后,麦麦会自动检查并优化表达方式,无需管理员手动干预"})]}),e.jsx(Ve,{id:"expression_self_reflect",checked:n.expression_self_reflect??!1,onCheckedChange:w=>r({...n,expression_self_reflect:w})})]}),n.expression_self_reflect&&e.jsxs("div",{className:"space-y-4 pl-4 border-l-2 border-primary/20",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"expression_auto_check_interval",children:"自动检查间隔(秒)"}),e.jsx(ae,{id:"expression_auto_check_interval",type:"number",min:"60",value:n.expression_auto_check_interval??3600,onChange:w=>r({...n,expression_auto_check_interval:parseInt(w.target.value)||3600})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"表达方式自动检查的间隔时间(单位:秒),默认值:3600秒(1小时)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"expression_auto_check_count",children:"每次检查数量"}),e.jsx(ae,{id:"expression_auto_check_count",type:"number",min:"1",max:"100",value:n.expression_auto_check_count??10,onChange:w=>r({...n,expression_auto_check_count:parseInt(w.target.value)||10})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"每次自动检查时随机选取的表达方式数量,默认值:10条"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"自定义评估标准"}),e.jsxs(_,{onClick:()=>{r({...n,expression_auto_check_custom_criteria:[...n.expression_auto_check_custom_criteria||[],""]})},size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加标准"]})]}),e.jsxs("div",{className:"space-y-2",children:[(n.expression_auto_check_custom_criteria||[]).map((w,b)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{value:w,onChange:y=>{const O=[...n.expression_auto_check_custom_criteria||[]];O[b]=y.target.value,r({...n,expression_auto_check_custom_criteria:O})},placeholder:"输入评估标准,例如:是否符合角色人设",className:"flex-1"}),e.jsx(_,{onClick:()=>{r({...n,expression_auto_check_custom_criteria:(n.expression_auto_check_custom_criteria||[]).filter((y,O)=>O!==b)})},size:"icon",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})]},b)),(!n.expression_auto_check_custom_criteria||n.expression_auto_check_custom_criteria.length===0)&&e.jsx("div",{className:"text-center py-4 text-muted-foreground text-sm",children:'暂无自定义标准,点击"添加标准"开始配置'})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这些标准会被添加到评估提示词中,作为额外的评估要求"})]})]})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"expression_checked_only",className:"cursor-pointer font-medium",children:"仅使用已审核通过的表达方式"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"开启后,只有通过审核(已检查)的项目会被使用;关闭时,未审核的项目也会被使用。无论开关状态,被拒绝的项目永远不会被使用。"})]}),e.jsx(Ve,{id:"expression_checked_only",checked:n.expression_checked_only??!1,onCheckedChange:w=>r({...n,expression_checked_only:w})})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{htmlFor:"expression_manual_reflect",className:"cursor-pointer font-medium",children:"手动表达优化"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后,麦麦会主动向管理员询问表达方式是否合适"})]}),e.jsx(Ve,{id:"expression_manual_reflect",checked:n.expression_manual_reflect??!1,onCheckedChange:w=>r({...n,expression_manual_reflect:w})})]}),n.expression_manual_reflect&&e.jsxs("div",{className:"space-y-4 pl-4 border-l-2 border-primary/20",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 b=(n.manual_reflect_operator_id||"").split(":"),y=b[0]||"qq",O=b[1]||"",R=b[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(T,{className:"text-xs font-medium",children:"平台"}),e.jsxs(Pe,{value:y,onValueChange:S=>{r({...n,manual_reflect_operator_id:`${S}:${O}:${R}`})},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"qq",children:"QQ"}),e.jsx(Z,{value:"wx",children:"微信"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"用户/群 ID"}),e.jsx(ae,{value:O,onChange:S=>{r({...n,manual_reflect_operator_id:`${y}:${S.target.value}:${R}`})},placeholder:"输入 ID",className:"font-mono text-sm"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"类型"}),e.jsxs(Pe,{value:R,onValueChange:S=>{r({...n,manual_reflect_operator_id:`${y}:${O}:${S}`})},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"private",children:"私聊(private)"}),e.jsx(Z,{value:"group",children:"群组(group)"})]})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["当前操作员 ID:",n.manual_reflect_operator_id||"(未设置)"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'手动表达优化操作员ID,格式:platform:id:type (例如 "qq:123456:private" 或 "qq:654321:group")'})]})})()})]}),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(_,{onClick:()=>{r({...n,allow_reflect:[...n.allow_reflect||[],"qq::group"]})},size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加聊天流"]})]}),e.jsxs("div",{className:"space-y-2",children:[(n.allow_reflect||[]).map((w,b)=>{const y=w.split(":"),O=y[0]||"qq",R=y[1]||"",S=y[2]||"group";return e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-muted/50",children:[e.jsxs(Pe,{value:O,onValueChange:B=>{const E=[...n.allow_reflect];E[b]=`${B}:${R}:${S}`,r({...n,allow_reflect:E})},children:[e.jsx($e,{className:"w-24",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"qq",children:"QQ"}),e.jsx(Z,{value:"wx",children:"微信"})]})]}),e.jsx(ae,{value:R,onChange:B=>{const E=[...n.allow_reflect];E[b]=`${O}:${B.target.value}:${S}`,r({...n,allow_reflect:E})},placeholder:"ID",className:"flex-1 font-mono text-sm"}),e.jsxs(Pe,{value:S,onValueChange:B=>{const E=[...n.allow_reflect];E[b]=`${O}:${R}:${B}`,r({...n,allow_reflect:E})},children:[e.jsx($e,{className:"w-32",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"group",children:"群组"}),e.jsx(Z,{value:"private",children:"私聊"})]})]}),e.jsx(_,{onClick:()=>{r({...n,allow_reflect:n.allow_reflect.filter((B,E)=>E!==b)})},size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})]},b)}),(!n.allow_reflect||n.allow_reflect.length===0)&&e.jsx("div",{className:"text-center py-4 text-muted-foreground text-sm",children:"列表为空,所有聊天流都可以进行表达反思"})]})]})]})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"表达共享组配置"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"配置不同聊天流之间如何共享学到的表达方式"})]}),e.jsxs(_,{onClick:f,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加共享组"]})]}),e.jsxs("div",{className:"space-y-4",children:[n.expression_groups.map((w,b)=>{const y=n.learning_list.map(O=>O[0]).filter(O=>O!=="");return e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["共享组 ",b+1,w.length===1&&w[0]==="*"&&"(全局共享)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_,{onClick:()=>g(b),size:"sm",variant:"outline",children:e.jsx(et,{className:"h-4 w-4"})}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除共享组 ",b+1," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>p(b),children:"删除"})]})]})]})]})]}),e.jsx("div",{className:"space-y-2",children:w.map((O,R)=>e.jsx(nS,{member:O,groupIndex:b,memberIndex:R,availableChatIds:y,onUpdate:v,onRemove:N},`${b}-${R}`))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'提示:可以从下拉框选择已配置的聊天流,或手动输入。输入 "*" 启用全局共享'})]},b)}),n.expression_groups.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无共享组,点击"添加共享组"开始配置'})]})]})})]})});function iS({regex:a,reaction:n,onRegexChange:r,onReactionChange:c}){const[d,u]=m.useState(!1),[h,f]=m.useState(""),[p,g]=m.useState(null),[N,v]=m.useState(""),[w,b]=m.useState({}),[y,O]=m.useState(""),R=m.useRef(null),[S,B]=m.useState("build"),E=L=>L.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),C=(L,J=0)=>{const U=R.current;if(!U)return;const oe=U.selectionStart||0,Ne=U.selectionEnd||0,je=a.substring(0,oe)+L+a.substring(Ne);r(je),setTimeout(()=>{const re=oe+L.length+J;U.setSelectionRange(re,re),U.focus()},0)};m.useEffect(()=>{if(!a||!h){p!==null&&g(null),Object.keys(w).length>0&&b({}),y!==n&&O(n),N!==""&&v("");return}try{const L=E(a),J=new RegExp(L,"g"),U=h.match(J);g(U),v("");const Ne=new RegExp(L).exec(h);if(Ne&&Ne.groups){b(Ne.groups);let je=n;Object.entries(Ne.groups).forEach(([re,fe])=>{je=je.replace(new RegExp(`\\[${re}\\]`,"g"),fe||"")}),O(je)}else b({}),O(n)}catch(L){v(L.message),g(null),b({}),O(n)}},[a,h,n,p,w,y,N]);const A=()=>{if(!h||!p||p.length===0)return e.jsx("span",{className:"text-muted-foreground",children:h||"请输入测试文本"});try{const L=E(a),J=new RegExp(L,"g");let U=0;const oe=[];let Ne;for(;(Ne=J.exec(h))!==null;)Ne.index>U&&oe.push(e.jsx("span",{children:h.substring(U,Ne.index)},`text-${U}`)),oe.push(e.jsx("span",{className:"bg-yellow-200 dark:bg-yellow-900 font-semibold",children:Ne[0]},`match-${Ne.index}`)),U=Ne.index+Ne[0].length;return U)",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(Ps,{open:d,onOpenChange:u,children:[e.jsx(cd,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",children:[e.jsx(nx,{className:"h-4 w-4 mr-1"}),"正则编辑器"]})}),e.jsxs(Ds,{className:"max-w-[95vw] sm:max-w-[900px] max-h-[90vh]",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"正则表达式编辑器"}),e.jsx(Ks,{className:"text-sm",children:"使用可视化工具构建正则表达式,并实时测试效果"})]}),e.jsx(Je,{className:"max-h-[calc(90vh-120px)]",children:e.jsxs(ta,{value:S,onValueChange:L=>B(L),className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2",children:[e.jsx(Xe,{value:"build",children:"🔧 构建器"}),e.jsx(Xe,{value:"test",children:"🧪 测试器"})]}),e.jsxs(ws,{value:"build",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"正则表达式"}),e.jsx(ae,{ref:R,value:a,onChange:L=>r(L.target.value),className:"font-mono text-sm",placeholder:"点击下方按钮构建正则表达式..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"Reaction 内容"}),e.jsx(ot,{value:n,onChange:L=>c(L.target.value),placeholder:"使用 [捕获组名] 引用捕获的内容...",rows:3,className:"text-sm"})]}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[F.map(L=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-xs font-semibold text-primary",children:L.category}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:L.items.map(J=>e.jsx(_,{variant:"outline",size:"sm",className:"justify-start h-auto py-2 px-3",onClick:()=>C(J.pattern,J.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:J.label}),e.jsx("code",{className:"ml-auto text-xs bg-muted px-1.5 py-0.5 rounded font-mono",children:J.pattern})]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-0.5",children:J.desc})]})},J.label))})]},L.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(_,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>r("^(?P\\S{1,20})是这样的$"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsxs("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:["^(?P\\S","{1,20}",")是这样的$"]}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"匹配「某事物是这样的」并捕获事物名称"})]})}),e.jsx(_,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>r("(?:[^,。.\\s]+,\\s*)?我(?:也)?[没沒]要求你\\s*(?P.+?)[.。,,]?$"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsx("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:"(?:[^,。.\\s]+,\\s*)?我(?:也)?[没沒]要求你\\s*(?P.+?)[.。,,]?$"}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"匹配「我没要求你做某事」并捕获具体行为"})]})}),e.jsx(_,{variant:"outline",size:"sm",className:"w-full justify-start h-auto py-2 px-3",onClick:()=>r("(?P.+?)(?:是|为什么|怎么)"),children:e.jsxs("div",{className:"flex flex-col items-start w-full",children:[e.jsx("code",{className:"text-xs font-mono bg-muted px-2 py-1 rounded w-full overflow-x-auto",children:"(?P.+?)(?:是|为什么|怎么)"}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"捕获问题主题词"})]})})]})]})]}),e.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3 space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-blue-900 dark:text-blue-100",children:"💡 使用提示"}),e.jsxs("ul",{className:"text-xs text-blue-700 dark:text-blue-300 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"点击输入框设置光标位置,然后点击按钮插入模式"}),e.jsxs("li",{children:["命名捕获组格式:",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"(?P<名称>模式)"})]}),e.jsxs("li",{children:["在 reaction 中使用 ",e.jsx("code",{className:"bg-blue-100 dark:bg-blue-900 px-1 rounded",children:"[名称]"})," 引用捕获的内容"]}),e.jsx("li",{children:"切换到测试器标签页验证正则表达式效果"})]})]})]}),e.jsxs(ws,{value:"test",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"当前正则表达式"}),e.jsx("div",{className:"rounded-md bg-muted p-3 font-mono text-xs break-all",children:a||"(未设置)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"test-text",className:"text-sm font-medium",children:"测试文本"}),e.jsx(ot,{id:"test-text",value:h,onChange:L=>f(L.target.value),placeholder:`在此输入要测试的文本... -例如:打游戏是这样的`,className:"min-h-[100px] text-sm"})]}),N&&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:N})]}),!N&&h&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:p&&p.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-green-500"}),e.jsxs("span",{className:"text-sm font-medium text-green-600 dark:text-green-400",children:["匹配成功 (",p.length," 处)"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-gray-400"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"无匹配"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"匹配高亮"}),e.jsx(Je,{className:"h-40 rounded-md bg-muted p-3",children:e.jsx("div",{className:"text-sm break-words",children:A()})})]}),Object.keys(w).length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"命名捕获组"}),e.jsx(Je,{className:"h-32 rounded-md border p-3",children:e.jsx("div",{className:"space-y-2",children:Object.entries(w).map(([L,J])=>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:["[",L,"]"]}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("span",{className:"font-mono bg-muted px-2 py-0.5 rounded",children:J})]},L))})})]}),Object.keys(w).length>0&&n&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"Reaction 替换预览"}),e.jsx(Je,{className:"h-48 rounded-md bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 p-3",children:e.jsx("div",{className:"text-sm break-words",children:y})}),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 cS=Rs.memo(function({keywordReactionConfig:n,responsePostProcessConfig:r,chineseTypoConfig:c,responseSplitterConfig:d,onKeywordReactionChange:u,onResponsePostProcessChange:h,onChineseTypoChange:f,onResponseSplitterChange:p}){const g=()=>{u({...n,regex_rules:[...n.regex_rules,{regex:[""],reaction:""}]})},N=C=>{u({...n,regex_rules:n.regex_rules.filter((A,F)=>F!==C)})},v=(C,A,F)=>{const L=[...n.regex_rules];A==="regex"&&typeof F=="string"?L[C]={...L[C],regex:[F]}:A==="reaction"&&typeof F=="string"&&(L[C]={...L[C],reaction:F}),u({...n,regex_rules:L})},w=()=>{u({...n,keyword_rules:[...n.keyword_rules,{keywords:[],reaction:""}]})},b=C=>{u({...n,keyword_rules:n.keyword_rules.filter((A,F)=>F!==C)})},y=(C,A,F)=>{const L=[...n.keyword_rules];typeof F=="string"&&(L[C]={...L[C],reaction:F}),u({...n,keyword_rules:L})},O=C=>{const A=[...n.keyword_rules];A[C]={...A[C],keywords:[...A[C].keywords||[],""]},u({...n,keyword_rules:A})},R=(C,A)=>{const F=[...n.keyword_rules];F[C]={...F[C],keywords:(F[C].keywords||[]).filter((L,J)=>J!==A)},u({...n,keyword_rules:F})},S=(C,A,F)=>{const L=[...n.keyword_rules],J=[...L[C].keywords||[]];J[A]=F,L[C]={...L[C],keywords:J},u({...n,keyword_rules:L})},B=({rule:C})=>{const A=`{ regex = [${(C.regex||[]).map(F=>`"${F}"`).join(", ")}], reaction = "${C.reaction}" }`;return e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",children:[e.jsx(ia,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(sl,{className:"w-[95vw] sm:w-[500px]",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx(Je,{className:"h-60 rounded-md bg-muted p-3",children:e.jsx("pre",{className:"font-mono text-xs break-all",children:A})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"这是保存到 bot_config.toml 文件中的格式"})]})})]})},E=({rule:C})=>{const A=`[[keyword_reaction.keyword_rules]] -keywords = [${(C.keywords||[]).map(F=>`"${F}"`).join(", ")}] -reaction = "${C.reaction}"`;return e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",children:[e.jsx(ia,{className:"h-4 w-4 mr-1"}),"预览"]})}),e.jsx(sl,{className:"w-[95vw] sm:w-[500px]",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"配置预览"}),e.jsx(Je,{className:"h-60 rounded-md bg-muted p-3",children:e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all",children:A})}),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(_,{onClick:g,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加正则规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[n.regex_rules.map((C,A)=>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:["正则规则 ",A+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(iS,{regex:C.regex&&C.regex[0]||"",reaction:C.reaction,onRegexChange:F=>v(A,"regex",F),onReactionChange:F=>v(A,"reaction",F)}),e.jsx(B,{rule:C}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除正则规则 ",A+1," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>N(A),children:"删除"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-xs font-medium",children:"正则表达式(Python 语法)"}),e.jsx(ae,{value:C.regex&&C.regex[0]||"",onChange:F=>v(A,"regex",F.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(T,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(ot,{value:C.reaction,onChange:F=>v(A,"reaction",F.target.value),placeholder:`触发后麦麦的反应... -可以使用 [捕获组名] 来引用正则表达式中的内容`,rows:3,className:"text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"使用 [捕获组名] 引用正则表达式中的命名捕获组,例如 [n] 会被替换为捕获的内容"})]})]})]},A)),n.regex_rules.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无正则规则,点击"添加正则规则"开始配置'})]})]}),e.jsxs("div",{className:"space-y-4 border-t pt-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-semibold",children:"关键词规则"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"使用关键词列表匹配消息内容"})]}),e.jsxs(_,{onClick:w,size:"sm",variant:"outline",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加关键词规则"]})]}),e.jsxs("div",{className:"space-y-3",children:[n.keyword_rules.map((C,A)=>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:["关键词规则 ",A+1]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{rule:C}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除关键词规则 ",A+1," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>b(A),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(T,{className:"text-xs font-medium",children:"关键词列表"}),e.jsxs(_,{onClick:()=>O(A),size:"sm",variant:"ghost",children:[e.jsx(et,{className:"h-3 w-3 mr-1"}),"添加关键词"]})]}),e.jsxs("div",{className:"space-y-2",children:[(C.keywords||[]).map((F,L)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{value:F,onChange:J=>S(A,L,J.target.value),placeholder:"关键词",className:"flex-1"}),e.jsx(_,{onClick:()=>R(A,L),size:"sm",variant:"ghost",children:e.jsx(ns,{className:"h-4 w-4"})})]},L)),(!C.keywords||C.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(T,{className:"text-xs font-medium",children:"反应内容"}),e.jsx(ot,{value:C.reaction,onChange:F=>y(A,"reaction",F.target.value),placeholder:"触发后麦麦的反应...",rows:3,className:"text-sm"})]})]})]},A)),n.keyword_rules.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无关键词规则,点击"添加关键词规则"开始配置'})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"回复后处理配置"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"enable_response_post_process",checked:r.enable_response_post_process,onCheckedChange:C=>h({...r,enable_response_post_process:C})}),e.jsx(T,{htmlFor:"enable_response_post_process",className:"cursor-pointer",children:"启用回复后处理"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"包括错别字生成器和回复分割器"})]}),r.enable_response_post_process&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t pt-6 space-y-4",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-4",children:[e.jsx(Ve,{id:"enable_chinese_typo",checked:c.enable,onCheckedChange:C=>f({...c,enable:C})}),e.jsx(T,{htmlFor:"enable_chinese_typo",className:"cursor-pointer font-semibold",children:"中文错别字生成器"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"为回复添加随机错别字,让麦麦的回复更自然"}),c.enable&&e.jsxs("div",{className:"grid gap-4 pl-6 border-l-2 border-primary/20",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"error_rate",className:"text-xs font-medium",children:"单字替换概率"}),e.jsx(ae,{id:"error_rate",type:"number",step:"0.001",min:"0",max:"1",value:c.error_rate,onChange:C=>f({...c,error_rate:parseFloat(C.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"min_freq",className:"text-xs font-medium",children:"最小字频阈值"}),e.jsx(ae,{id:"min_freq",type:"number",min:"0",value:c.min_freq,onChange:C=>f({...c,min_freq:parseInt(C.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"tone_error_rate",className:"text-xs font-medium",children:"声调错误概率"}),e.jsx(ae,{id:"tone_error_rate",type:"number",step:"0.01",min:"0",max:"1",value:c.tone_error_rate,onChange:C=>f({...c,tone_error_rate:parseFloat(C.target.value)})})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"word_replace_rate",className:"text-xs font-medium",children:"整词替换概率"}),e.jsx(ae,{id:"word_replace_rate",type:"number",step:"0.001",min:"0",max:"1",value:c.word_replace_rate,onChange:C=>f({...c,word_replace_rate:parseFloat(C.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(Ve,{id:"enable_response_splitter",checked:d.enable,onCheckedChange:C=>p({...d,enable:C})}),e.jsx(T,{htmlFor:"enable_response_splitter",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(T,{htmlFor:"max_length",className:"text-xs font-medium",children:"最大长度"}),e.jsx(ae,{id:"max_length",type:"number",min:"1",value:d.max_length,onChange:C=>p({...d,max_length:parseInt(C.target.value)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"回复允许的最大字符数"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"max_sentence_num",className:"text-xs font-medium",children:"最大句子数"}),e.jsx(ae,{id:"max_sentence_num",type:"number",min:"1",value:d.max_sentence_num,onChange:C=>p({...d,max_sentence_num:parseInt(C.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(Ve,{id:"enable_kaomoji_protection",checked:d.enable_kaomoji_protection,onCheckedChange:C=>p({...d,enable_kaomoji_protection:C})}),e.jsx(T,{htmlFor:"enable_kaomoji_protection",className:"cursor-pointer",children:"启用颜文字保护"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"enable_overflow_return_all",checked:d.enable_overflow_return_all,onCheckedChange:C=>p({...d,enable_overflow_return_all:C})}),e.jsx(T,{htmlFor:"enable_overflow_return_all",className:"cursor-pointer",children:"超出时一次性返回全部"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:"当句子数量超出限制时,合并后一次性返回所有内容"})]})]})})]})]})]})}),oS=Rs.memo(function({config:n,onChange:r}){const[c,d]=m.useState(""),[u,h]=m.useState(""),[f,p]=m.useState(!1),g=n.allowed_ips?n.allowed_ips.split(",").map(S=>S.trim()).filter(S=>S):[],N=n.trusted_proxies?n.trusted_proxies.split(",").map(S=>S.trim()).filter(S=>S):[],v=()=>{if(!c.trim())return;const S=[...g,c.trim()];r({...n,allowed_ips:S.join(",")}),d("")},w=S=>{const B=g.filter((E,C)=>C!==S);r({...n,allowed_ips:B.join(",")})},b=()=>{if(!u.trim())return;const S=[...N,u.trim()];r({...n,trusted_proxies:S.join(",")}),h("")},y=S=>{const B=N.filter((E,C)=>C!==S);r({...n,trusted_proxies:B.join(",")})},O=S=>{!S&&n.enabled?p(!0):r({...n,enabled:S})},R=()=>{r({...n,enabled:!1}),p(!1)};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"WebUI 服务配置"}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.enabled,onCheckedChange:O}),e.jsx(T,{className:"cursor-pointer",children:"启用 WebUI"})]}),n.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"运行模式"}),e.jsxs(Pe,{value:n.mode,onValueChange:S=>r({...n,mode:S}),children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:"选择运行模式"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"development",children:"开发模式"}),e.jsx(Z,{value:"production",children:"生产模式"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"注意: WebUI 的监听地址和端口请在 .env 文件中配置 WEBUI_HOST 和 WEBUI_PORT"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"防爬虫模式"}),e.jsxs(Pe,{value:n.anti_crawler_mode,onValueChange:S=>r({...n,anti_crawler_mode:S}),children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:"选择防爬虫模式"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"false",children:"禁用"}),e.jsx(Z,{value:"basic",children:"基础(只记录不阻止)"}),e.jsx(Z,{value:"loose",children:"宽松"}),e.jsx(Z,{value:"strict",children:"严格"})]})]})]}),e.jsxs("div",{className:"grid gap-2 sm:col-span-2",children:[e.jsx(T,{children:"IP 白名单"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{value:c,onChange:S=>d(S.target.value),onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),v())},placeholder:"输入IP地址后按回车或点击添加"}),e.jsx(_,{type:"button",size:"sm",onClick:v,disabled:!c.trim(),children:e.jsx(et,{className:"h-4 w-4"})})]}),g.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:g.map((S,B)=>e.jsxs(ke,{variant:"secondary",className:"flex items-center gap-1",children:[S,e.jsx("button",{type:"button",onClick:()=>w(B),className:"ml-1 hover:bg-destructive/20 rounded-full p-0.5",children:e.jsx(Aa,{className:"h-3 w-3"})})]},B))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"支持精确IP、CIDR格式和通配符(如:127.0.0.1、192.168.1.0/24)"})]}),e.jsxs("div",{className:"grid gap-2 sm:col-span-2",children:[e.jsx(T,{children:"信任的代理 IP"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{value:u,onChange:S=>h(S.target.value),onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),b())},placeholder:"输入代理IP后按回车或点击添加"}),e.jsx(_,{type:"button",size:"sm",onClick:b,disabled:!u.trim(),children:e.jsx(et,{className:"h-4 w-4"})})]}),N.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:N.map((S,B)=>e.jsxs(ke,{variant:"secondary",className:"flex items-center gap-1",children:[S,e.jsx("button",{type:"button",onClick:()=>y(B),className:"ml-1 hover:bg-destructive/20 rounded-full p-0.5",children:e.jsx(Aa,{className:"h-3 w-3"})})]},B))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"只有来自这些IP的X-Forwarded-For头才被信任"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.trust_xff,onCheckedChange:S=>r({...n,trust_xff:S})}),e.jsx(T,{className:"cursor-pointer",children:"启用 X-Forwarded-For 代理解析"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{checked:n.secure_cookie,onCheckedChange:S=>r({...n,secure_cookie:S})}),e.jsx(T,{className:"cursor-pointer",children:"启用安全 Cookie(仅 HTTPS)"})]})]})]}),e.jsx(Ns,{open:f,onOpenChange:p,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"警告:即将关闭 WebUI"}),e.jsxs(fs,{children:["关闭 WebUI 后,在您下次重启麦麦之前,WebUI 界面将无法访问。",e.jsx("br",{}),e.jsx("br",{}),"您需要通过修改配置文件或命令行重新启用 WebUI 才能再次访问此界面。",e.jsx("br",{}),e.jsx("br",{}),"确定要关闭 WebUI 吗?"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{variant:"destructive",onClick:R,children:"确认关闭"})]})]})})]})}),wn="/api/webui/config";async function Lg(){const n=await(await _e(`${wn}/bot`)).json();if(!n.success)throw new Error("获取配置数据失败");return n.config}async function xn(){const n=await(await _e(`${wn}/model`)).json();if(!n.success)throw new Error("获取模型配置数据失败");return n.config}async function Ug(a){const r=await(await _e(`${wn}/bot`,{method:"POST",body:JSON.stringify(a)})).json();if(!r.success)throw new Error(r.message||"保存配置失败")}async function dS(){const n=await(await _e(`${wn}/bot/raw`)).json();if(!n.success)throw new Error("获取配置源代码失败");return n.content}async function uS(a){const r=await(await _e(`${wn}/bot/raw`,{method:"POST",body:JSON.stringify({raw_content:a})})).json();if(!r.success)throw new Error(r.message||"保存配置失败")}async function tc(a){const r=await(await _e(`${wn}/model`,{method:"POST",body:JSON.stringify(a)})).json();if(!r.success)throw new Error(r.message||"保存配置失败")}async function mS(a,n){const c=await(await _e(`${wn}/bot/section/${a}`,{method:"POST",body:JSON.stringify(n)})).json();if(!c.success)throw new Error(c.message||`保存配置节 ${a} 失败`)}async function Ym(a,n){const c=await(await _e(`${wn}/model/section/${a}`,{method:"POST",body:JSON.stringify(n)})).json();if(!c.success)throw new Error(c.message||`保存配置节 ${a} 失败`)}async function xS(a,n="openai",r="/models"){const c=new URLSearchParams({provider_name:a,parser:n,endpoint:r}),d=await _e(`/api/webui/models/list?${c}`);if(!d.ok){const h=await d.json().catch(()=>({}));throw new Error(h.detail||`获取模型列表失败 (${d.status})`)}const u=await d.json();if(!u.success)throw new Error("获取模型列表失败");return u.models}async function hS(a){const n=new URLSearchParams({provider_name:a}),r=await _e(`/api/webui/models/test-connection-by-name?${n}`,{method:"POST"});if(!r.ok){const c=await r.json().catch(()=>({}));throw new Error(c.detail||`测试连接失败 (${r.status})`)}return await r.json()}const fS=Wr("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"}}),at=m.forwardRef(({className:a,variant:n,...r},c)=>e.jsx("div",{ref:c,role:"alert",className:I(fS({variant:n}),a),...r}));at.displayName="Alert";const Gn=m.forwardRef(({className:a,...n},r)=>e.jsx("h5",{ref:r,className:I("mb-1 font-medium leading-none tracking-tight",a),...n}));Gn.displayName="AlertTitle";const lt=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{ref:r,className:I("text-sm [&_p]:leading-relaxed",a),...n}));lt.displayName="AlertDescription";const pS={name:"toml",startState:function(){return{inString:!1,stringType:"",lhs:!0,inArray:0}},token:function(a,n){let r;if(!n.inString&&(r=a.match(/^('''|"""|'|")/))&&(n.stringType=r[0],n.inString=!0),a.sol()&&!n.inString&&n.inArray===0&&(n.lhs=!0),n.inString){for(;n.inString;)if(a.match(n.stringType))n.inString=!1;else if(a.peek()==="\\")a.next(),a.next();else{if(a.eol())break;a.match(/^.[^\\\"\']*/)}return n.lhs?"property":"string"}else{if(n.inArray&&a.peek()==="]")return a.next(),n.inArray--,"bracket";if(n.lhs&&a.peek()==="["&&a.skipTo("]"))return a.next(),a.peek()==="]"&&a.next(),"atom";if(a.peek()==="#")return a.skipToEnd(),"comment";if(a.eatSpace())return null;if(n.lhs&&a.eatWhile(function(c){return c!="="&&c!=" "}))return"property";if(n.lhs&&a.peek()==="=")return a.next(),n.lhs=!1,null;if(!n.lhs&&a.match(/^\d\d\d\d[\d\-\:\.T]*Z/))return"atom";if(!n.lhs&&(a.match("true")||a.match("false")))return"atom";if(!n.lhs&&a.peek()==="[")return n.inArray++,a.next(),"bracket";if(!n.lhs&&a.match(/^\-?\d+(?:\.\d+)?/))return"number";a.eatSpace()||a.next()}return null},languageData:{commentTokens:{line:"#"}}},gS={python:[a1()],json:[l1(),n1()],toml:[t1.define(pS)],text:[]};function Iv({value:a,onChange:n,language:r="text",readOnly:c=!1,height:d="400px",minHeight:u,maxHeight:h,placeholder:f,theme:p="dark",className:g=""}){const[N,v]=m.useState(!1);if(m.useEffect(()=>{v(!0)},[]),!N)return e.jsx("div",{className:`rounded-md border bg-muted animate-pulse ${g}`,style:{height:d,minHeight:u,maxHeight:h}});const w=[...gS[r]||[],Sg.lineWrapping];return c&&w.push(Sg.editable.of(!1)),e.jsx("div",{className:`rounded-md overflow-hidden border ${g}`,children:e.jsx(r1,{value:a,height:d,minHeight:u,maxHeight:h,theme:p==="dark"?i1:void 0,extensions:w,onChange:n,placeholder:f,basicSetup:{lineNumbers:!0,highlightActiveLineGutter:!0,highlightSpecialChars:!0,history:!0,foldGutter:!0,drawSelection:!0,dropCursor:!0,allowMultipleSelections:!0,indentOnInput:!0,syntaxHighlighting:!0,bracketMatching:!0,closeBrackets:!0,autocompletion:!0,rectangularSelection:!0,crosshairCursor:!0,highlightActiveLine:!0,highlightSelectionMatches:!0,closeBracketsKeymap:!0,defaultKeymap:!0,searchKeymap:!0,historyKeymap:!0,foldKeymap:!0,completionKeymap:!0,lintKeymap:!0}})})}function jS({id:a,index:n,itemType:r,itemFields:c,value:d,onChange:u,onRemove:h,disabled:f,canRemove:p,placeholder:g}){const{attributes:N,listeners:v,setNodeRef:w,transform:b,transition:y,isDragging:O}=Nv({id:a,disabled:f}),R={transform:bv.Transform.toString(b),transition:y};return e.jsxs("div",{ref:w,style:R,className:I("flex items-start gap-2 group",O&&"opacity-50 z-50"),children:[e.jsx("button",{type:"button",className:I("flex-shrink-0 p-2 cursor-grab active:cursor-grabbing","text-muted-foreground hover:text-foreground transition-colors","opacity-0 group-hover:opacity-100 focus:opacity-100",f&&"cursor-not-allowed opacity-30"),...N,...v,children:e.jsx(tv,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1 min-w-0",children:r==="object"&&c?e.jsx(vS,{value:d,onChange:u,fields:c,disabled:f}):r==="number"?e.jsx(ae,{type:"number",value:d??"",onChange:S=>u(parseFloat(S.target.value)||0),placeholder:g??`第 ${n+1} 项`,disabled:f,className:"font-mono"}):e.jsx(ae,{type:"text",value:d??"",onChange:S=>u(S.target.value),placeholder:g??`第 ${n+1} 项`,disabled:f})}),e.jsx(_,{type:"button",variant:"ghost",size:"icon",onClick:h,disabled:f||!p,className:I("flex-shrink-0 text-muted-foreground hover:text-destructive","opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity"),children:e.jsx(ns,{className:"h-4 w-4"})})]})}function vS({value:a,onChange:n,fields:r,disabled:c}){const d=m.useCallback((h,f)=>{n({...a,[h]:f})},[a,n]),u=(h,f)=>{const p=a?.[h];if(f.type==="boolean"||f.type==="switch")return e.jsxs("div",{className:"flex items-center justify-between py-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(Ve,{checked:!!(p??f.default),onCheckedChange:g=>d(h,g),disabled:c})]});if(f.type==="slider"||f.type==="number"&&f.min!=null&&f.max!=null){const g=p??f.default??f.min??0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx("span",{className:"text-xs text-muted-foreground",children:g})]}),e.jsx(Qa,{value:[g],onValueChange:N=>d(h,N[0]),min:f.min??0,max:f.max??100,step:f.step??1,disabled:c,className:"py-1"})]})}return f.type==="select"&&f.choices?e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsxs(Pe,{value:String(p??f.default??""),onValueChange:g=>d(h,g),disabled:c,children:[e.jsx($e,{className:"h-8 text-sm",children:e.jsx(Ie,{placeholder:f.placeholder??"请选择"})}),e.jsx(Be,{children:f.choices.map(g=>e.jsx(Z,{value:String(g),children:String(g)},String(g)))})]})]}):f.type==="number"?e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(ae,{type:"number",value:p??f.default??"",onChange:g=>d(h,parseFloat(g.target.value)||0),placeholder:f.placeholder,disabled:c,className:"h-8 text-sm"})]}):e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:f.label??h}),e.jsx(ae,{type:"text",value:p??f.default??"",onChange:g=>d(h,g.target.value),placeholder:f.placeholder,disabled:c,className:"h-8 text-sm"})]})};return e.jsx(Ce,{className:"p-3 space-y-2 bg-muted/30",children:Object.entries(r).map(([h,f])=>e.jsx("div",{children:u(h,f)},h))})}function NS({value:a,onChange:n,itemType:r="string",itemFields:c,minItems:d,maxItems:u,disabled:h,placeholder:f}){const p=m.useMemo(()=>Array.isArray(a)?a:typeof a=="string"&&a.trim()?a.split(",").map(E=>E.trim()):[],[a]),[g]=m.useState(()=>new Map),N=m.useCallback(E=>(g.has(E)||g.set(E,`item-${Date.now()}-${E}-${Math.random().toString(36).slice(2)}`),g.get(E)),[g]),v=m.useMemo(()=>{const E=[];for(let C=0;C{const{active:C,over:A}=E;if(A&&C.id!==A.id){const F=v.indexOf(C.id),L=v.indexOf(A.id),J=pv(p,F,L);n(J)}},[p,v,n]),y=m.useCallback(()=>{if(u!=null&&p.length>=u)return;let E;r==="object"&&c?E=Object.fromEntries(Object.entries(c).map(([C,A])=>[C,A.default??""])):r==="number"?E=0:E="",n([...p,E])},[p,u,r,c,n]),O=m.useCallback((E,C)=>{const A=[...p];A[E]=C,n(A)},[p,n]),R=m.useCallback(E=>{if(d!=null&&p.length<=d)return;const C=p.filter((A,F)=>F!==E);g.delete(E),n(C)},[p,d,g,n]),S=u==null||p.lengthd;return e.jsxs("div",{className:"space-y-2",children:[p.length===0?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-4 justify-center border border-dashed rounded-md",children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsx("span",{children:"暂无数据,点击下方按钮添加"})]}):e.jsx(gv,{sensors:w,collisionDetection:jv,onDragEnd:b,children:e.jsx(vv,{items:v,strategy:c1,children:e.jsx("div",{className:"space-y-2",children:p.map((E,C)=>e.jsx(jS,{id:v[C],index:C,itemType:r,itemFields:c,value:E,onChange:A=>O(C,A),onRemove:()=>R(C),disabled:h,canRemove:B,placeholder:f},v[C]))})})}),e.jsxs(_,{type:"button",variant:"outline",size:"sm",onClick:y,disabled:h||!S,className:"w-full",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"添加项目",u!==void 0&&e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",p.length,"/",u,")"]})]}),(d!=null||u!=null)&&(d!==null||u!==null)&&e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:d!=null&&u!=null?`允许 ${d} - ${u} 项`:d!=null?`至少 ${d} 项`:`最多 ${u} 项`})]})}function fx({content:a,className:n=""}){return e.jsx("div",{className:`prose prose-sm dark:prose-invert max-w-none ${n}`,children:e.jsx(h1,{remarkPlugins:[p1,g1],rehypePlugins:[f1],components:{code({inline:r,className:c,children:d,...u}){return r?e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-sm font-mono",...u,children:d}):e.jsx("code",{className:`${c} block bg-muted p-4 rounded-lg overflow-x-auto`,...u,children:d})},table({children:r,...c}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{className:"border-collapse border border-border",...c,children:r})})},th({children:r,...c}){return e.jsx("th",{className:"border border-border bg-muted px-4 py-2 text-left font-semibold",...c,children:r})},td({children:r,...c}){return e.jsx("td",{className:"border border-border px-4 py-2",...c,children:r})},a({children:r,...c}){return e.jsx("a",{className:"text-primary hover:underline",target:"_blank",rel:"noopener noreferrer",...c,children:r})},blockquote({children:r,...c}){return e.jsx("blockquote",{className:"border-l-4 border-primary pl-4 italic text-muted-foreground",...c,children:r})},h1({children:r,...c}){return e.jsx("h1",{className:"text-3xl font-bold mt-6 mb-4",...c,children:r})},h2({children:r,...c}){return e.jsx("h2",{className:"text-2xl font-bold mt-5 mb-3",...c,children:r})},h3({children:r,...c}){return e.jsx("h3",{className:"text-xl font-bold mt-4 mb-2",...c,children:r})},h4({children:r,...c}){return e.jsx("h4",{className:"text-lg font-semibold mt-3 mb-2",...c,children:r})},ul({children:r,...c}){return e.jsx("ul",{className:"list-disc list-inside space-y-1 my-2",...c,children:r})},ol({children:r,...c}){return e.jsx("ol",{className:"list-decimal list-inside space-y-1 my-2",...c,children:r})},p({children:r,...c}){return e.jsx("p",{className:"my-2 leading-relaxed",...c,children:r})},hr({...r}){return e.jsx("hr",{className:"my-4 border-border",...r})}},children:a})})}function bS(a,n,r,c={}){const{debounceMs:d=2e3,onSaveSuccess:u,onSaveError:h}=c,f=m.useRef(null),p=m.useCallback(async(w,b)=>{try{n(!0),await mS(w,b),r(!1),u?.()}catch(y){console.error(`自动保存 ${w} 失败:`,y),r(!0),h?.(y instanceof Error?y:new Error(String(y)))}finally{n(!1)}},[n,r,u,h]),g=m.useCallback((w,b)=>{a||(r(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{p(w,b)},d))},[a,r,p,d]),N=m.useCallback(async(w,b)=>{f.current&&(clearTimeout(f.current),f.current=null),await p(w,b)},[p]),v=m.useCallback(()=>{f.current&&(clearTimeout(f.current),f.current=null)},[]);return m.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]),{triggerAutoSave:g,saveNow:N,cancelPendingAutoSave:v}}function Lt(a,n,r,c){m.useEffect(()=>{a&&!r&&c(n,a)},[a])}const yS=500;function wS(){return e.jsx(Wn,{children:e.jsx(_S,{})})}function _S(){const[a,n]=m.useState(!0),[r,c]=m.useState(!1),[d,u]=m.useState(!1),[h,f]=m.useState(!1),[p,g]=m.useState("visual"),[N,v]=m.useState(""),[w,b]=m.useState(!1),{toast:y}=Ys(),{triggerRestart:O,isRestarting:R}=yn(),[S,B]=m.useState(null),[E,C]=m.useState(null),[A,F]=m.useState(null),[L,J]=m.useState(null),[U,oe]=m.useState(null),[Ne,je]=m.useState(null),[re,fe]=m.useState(null),[ge,M]=m.useState(null),[K,P]=m.useState(null),[ue,Q]=m.useState(null),[Se,pe]=m.useState(null),[Te,z]=m.useState(null),[D,G]=m.useState(null),[de,Re]=m.useState(null),[W,Y]=m.useState(null),[Fe,H]=m.useState(null),[ee,Ue]=m.useState(null),[ie,Ee]=m.useState(null),[me,Ae]=m.useState(null),rs=m.useRef(!0),Ut=m.useRef({}),aa=m.useCallback(ze=>{Ut.current=ze,B(ze.bot),C(ze.personality);const bs=ze.chat;bs.talk_value_rules||(bs.talk_value_rules=[]),F(bs),J(ze.expression),oe(ze.emoji),je(ze.memory),fe(ze.tool),M(ze.voice),P(ze.dream),Q(ze.lpmm_knowledge),pe(ze.keyword_reaction),z(ze.response_post_process),G(ze.chinese_typo),Re(ze.response_splitter),Y(ze.log),H(ze.debug),Ue(ze.maim_message),Ee(ze.telemetry),Ae(ze.webui)},[]),Ja=m.useCallback(()=>({...Ut.current,bot:S,personality:E,chat:A,expression:L,emoji:U,memory:Ne,tool:re,voice:ge,dream:K,lpmm_knowledge:ue,keyword_reaction:Se,response_post_process:Te,chinese_typo:D,response_splitter:de,log:W,debug:Fe,maim_message:ee,telemetry:ie,webui:me}),[S,E,A,L,U,Ne,re,ge,K,ue,Se,Te,D,de,W,Fe,ee,ie,me]),Ht=m.useCallback(async()=>{try{const bs=(await dS()).replace(/"([^"]*)"/g,(ls,ss)=>`"${ss.replace(/\\n/g,` -`).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}"`);v(bs),b(!1)}catch(ze){y({variant:"destructive",title:"加载失败",description:ze instanceof Error?ze.message:"加载源代码失败"})}},[y]),mt=m.useCallback(async()=>{try{n(!0);const ze=await Lg();aa(ze),f(!1),rs.current=!1,await Ht()}catch(ze){console.error("加载配置失败:",ze),y({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}finally{n(!1)}},[y,Ht,aa]);m.useEffect(()=>{mt()},[mt]);const{triggerAutoSave:q,cancelPendingAutoSave:qe}=bS(rs.current,u,f);Lt(S,"bot",rs.current,q),Lt(E,"personality",rs.current,q),Lt(A,"chat",rs.current,q),Lt(L,"expression",rs.current,q),Lt(U,"emoji",rs.current,q),Lt(Ne,"memory",rs.current,q),Lt(re,"tool",rs.current,q),Lt(ge,"voice",rs.current,q),Lt(K,"dream",rs.current,q),Lt(ue,"lpmm_knowledge",rs.current,q),Lt(Se,"keyword_reaction",rs.current,q),Lt(Te,"response_post_process",rs.current,q),Lt(D,"chinese_typo",rs.current,q),Lt(de,"response_splitter",rs.current,q),Lt(W,"log",rs.current,q),Lt(Fe,"debug",rs.current,q),Lt(ee,"maim_message",rs.current,q),Lt(ie,"telemetry",rs.current,q),Lt(me,"webui",rs.current,q);const Qe=async()=>{try{c(!0);const ze=N.replace(/"([^"]*)"/g,(bs,ls)=>`"${ls.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")}"`);await uS(ze),f(!1),b(!1),y({title:"保存成功",description:"配置已保存"}),await mt()}catch(ze){b(!0),y({variant:"destructive",title:"保存失败",description:ze instanceof Error?ze.message:"保存配置失败"})}finally{c(!1)}},es=async ze=>{if(h){y({variant:"destructive",title:"切换失败",description:"请先保存当前更改"});return}if(g(ze),ze==="source")await Ht();else try{const bs=await Lg();aa(bs),f(!1)}catch(bs){console.error("加载配置失败:",bs),y({title:"加载失败",description:"无法加载配置文件",variant:"destructive"})}},Us=async()=>{try{c(!0),qe(),await Ug(Ja()),f(!1),y({title:"保存成功",description:"麦麦主程序配置已保存"})}catch(ze){console.error("保存配置失败:",ze),y({title:"保存失败",description:ze.message,variant:"destructive"})}finally{c(!1)}},as=async()=>{await O()},Cs=async()=>{try{c(!0),qe(),await Ug(Ja()),f(!1),y({title:"保存成功",description:"配置已保存,即将重启麦麦..."}),await new Promise(ze=>setTimeout(ze,yS)),await as()}catch(ze){console.error("保存失败:",ze),y({title:"保存失败",description:ze.message,variant:"destructive"})}finally{c(!1)}};return a?e.jsx(Je,{className:"h-full",children:e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})})}):e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:gap-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl sm:text-2xl md:text-3xl font-bold",children:"麦麦主程序配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-xs sm:text-sm",children:"管理麦麦的核心功能和行为设置"})]}),e.jsxs("div",{className:"flex gap-2 flex-shrink-0",children:[e.jsxs(_,{onClick:p==="visual"?Us:Qe,disabled:r||d||!h||R,size:"sm",variant:"outline",className:"w-20 sm:w-24",children:[e.jsx(fc,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{className:"ml-1 truncate text-xs sm:text-sm",children:r?"保存中":d?"自动":h?"保存":"已保存"})]}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{disabled:r||d||R,size:"sm",className:"w-20 sm:w-28",children:[e.jsx(hc,{className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"ml-1 truncate text-xs sm:text-sm",children:R?"重启中":h?"保存重启":"重启"})]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重启麦麦?"}),e.jsx(fs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:h?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:h?Cs:as,children:h?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsx("div",{className:"flex",children:e.jsx(ta,{value:p,onValueChange:ze=>es(ze),className:"w-full",children:e.jsxs(Zt,{className:"h-8 sm:h-9 w-full grid grid-cols-2",children:[e.jsxs(Xe,{value:"visual",className:"text-xs sm:text-sm",children:[e.jsx(av,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"可视化编辑"]}),e.jsxs(Xe,{value:"source",className:"text-xs sm:text-sm",children:[e.jsx(lv,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1"}),"源代码编辑"]})]})})})]}),e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsxs(lt,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),p==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsxs(lt,{children:[e.jsx("strong",{children:"源代码模式(高级功能):"}),"直接编辑 TOML 配置文件。此功能仅适用于熟悉 TOML 语法的高级用户。保存时会在后端验证格式,只有格式完全正确才能保存。",w&&e.jsx("span",{className:"text-destructive font-semibold ml-2",children:"⚠️ 上次保存失败,请检查 TOML 格式"})]})]}),e.jsx(Iv,{value:N,onChange:ze=>{v(ze),f(!0),w&&b(!1)},language:"toml",theme:"dark",height:"calc(100vh - 280px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),p==="visual"&&e.jsx(e.Fragment,{children:e.jsxs(ta,{defaultValue:"bot",className:"w-full",children:[e.jsxs(Zt,{className:"flex flex-wrap h-auto gap-1 p-1 sm:grid sm:grid-cols-5 lg:grid-cols-10",children:[e.jsx(Xe,{value:"bot",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"基本信息"}),e.jsx(Xe,{value:"personality",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"人格"}),e.jsx(Xe,{value:"chat",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"聊天"}),e.jsx(Xe,{value:"expression",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"表达"}),e.jsx(Xe,{value:"features",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"功能"}),e.jsx(Xe,{value:"processing",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"处理"}),e.jsx(Xe,{value:"dream",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"做梦"}),e.jsx(Xe,{value:"lpmm",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"知识库"}),e.jsx(Xe,{value:"webui",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"WebUI"}),e.jsx(Xe,{value:"other",className:"text-xs px-2 py-1.5 sm:px-3 sm:py-2 data-[state=active]:shadow-sm",children:"其他"})]}),e.jsx(ws,{value:"bot",className:"space-y-4",children:S&&e.jsx(K2,{config:S,onChange:B})}),e.jsx(ws,{value:"personality",className:"space-y-4",children:E&&e.jsx(Q2,{config:E,onChange:C})}),e.jsx(ws,{value:"chat",className:"space-y-4",children:A&&e.jsx(X2,{config:A,onChange:F})}),e.jsx(ws,{value:"expression",className:"space-y-4",children:L&&e.jsx(rS,{config:L,onChange:J})}),e.jsx(ws,{value:"features",className:"space-y-4",children:U&&Ne&&re&&ge&&e.jsx(lS,{emojiConfig:U,memoryConfig:Ne,toolConfig:re,voiceConfig:ge,onEmojiChange:oe,onMemoryChange:je,onToolChange:fe,onVoiceChange:M})}),e.jsx(ws,{value:"processing",className:"space-y-4",children:Se&&Te&&D&&de&&e.jsx(cS,{keywordReactionConfig:Se,responsePostProcessConfig:Te,chineseTypoConfig:D,responseSplitterConfig:de,onKeywordReactionChange:pe,onResponsePostProcessChange:z,onChineseTypoChange:G,onResponseSplitterChange:Re})}),e.jsx(ws,{value:"dream",className:"space-y-4",children:K&&e.jsx(Z2,{config:K,onChange:P})}),e.jsx(ws,{value:"lpmm",className:"space-y-4",children:ue&&e.jsx(W2,{config:ue,onChange:Q})}),e.jsx(ws,{value:"webui",className:"space-y-4",children:me&&e.jsx(oS,{config:me,onChange:Ae})}),e.jsxs(ws,{value:"other",className:"space-y-4",children:[W&&e.jsx(eS,{config:W,onChange:Y}),Fe&&e.jsx(sS,{config:Fe,onChange:H}),ee&&e.jsx(tS,{config:ee,onChange:Ue}),ie&&e.jsx(aS,{config:ie,onChange:Ee})]})]})}),e.jsx(er,{})]})})}const Ul=m.forwardRef(({className:a,...n},r)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:r,className:I("w-full caption-bottom text-sm",a),...n})}));Ul.displayName="Table";const $l=m.forwardRef(({className:a,...n},r)=>e.jsx("thead",{ref:r,className:I("[&_tr]:border-b",a),...n}));$l.displayName="TableHeader";const Bl=m.forwardRef(({className:a,...n},r)=>e.jsx("tbody",{ref:r,className:I("[&_tr:last-child]:border-0",a),...n}));Bl.displayName="TableBody";const SS=m.forwardRef(({className:a,...n},r)=>e.jsx("tfoot",{ref:r,className:I("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",a),...n}));SS.displayName="TableFooter";const ut=m.forwardRef(({className:a,...n},r)=>e.jsx("tr",{ref:r,className:I("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",a),...n}));ut.displayName="TableRow";const We=m.forwardRef(({className:a,...n},r)=>e.jsx("th",{ref:r,className:I("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",a),...n}));We.displayName="TableHead";const Ke=m.forwardRef(({className:a,...n},r)=>e.jsx("td",{ref:r,className:I("px-4 py-3 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",a),...n}));Ke.displayName="TableCell";const kS=m.forwardRef(({className:a,...n},r)=>e.jsx("caption",{ref:r,className:I("mt-4 text-sm text-muted-foreground",a),...n}));kS.displayName="TableCaption";const dd=m.forwardRef(({className:a,...n},r)=>e.jsx(ja,{ref:r,className:I("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",a),...n}));dd.displayName=ja.displayName;const ud=m.forwardRef(({className:a,...n},r)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(Tt,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(ja.Input,{ref:r,className:I("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",a),...n})]}));ud.displayName=ja.Input.displayName;const md=m.forwardRef(({className:a,...n},r)=>e.jsx(ja.List,{ref:r,className:I("max-h-[300px] overflow-y-auto overflow-x-hidden",a),...n}));md.displayName=ja.List.displayName;const xd=m.forwardRef((a,n)=>e.jsx(ja.Empty,{ref:n,className:"py-6 text-center text-sm",...a}));xd.displayName=ja.Empty.displayName;const oc=m.forwardRef(({className:a,...n},r)=>e.jsx(ja.Group,{ref:r,className:I("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",a),...n}));oc.displayName=ja.Group.displayName;const CS=m.forwardRef(({className:a,...n},r)=>e.jsx(ja.Separator,{ref:r,className:I("-mx-1 h-px bg-border",a),...n}));CS.displayName=ja.Separator.displayName;const dc=m.forwardRef(({className:a,...n},r)=>e.jsx(ja.Item,{ref:r,className:I("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",a),...n}));dc.displayName=ja.Item.displayName;const Fv=m.createContext(null),Hv="maibot-completed-tours";function TS(){try{const a=localStorage.getItem(Hv);return a?new Set(JSON.parse(a)):new Set}catch{return new Set}}function $g(a){localStorage.setItem(Hv,JSON.stringify([...a]))}function ES({children:a}){const[n,r]=m.useState({activeTourId:null,stepIndex:0,isRunning:!1}),[c]=m.useState(()=>new Map),[d,u]=m.useState(TS),[,h]=m.useState(0),f=m.useCallback((E,C)=>{c.set(E,C),h(A=>A+1)},[c]),p=m.useCallback(E=>{c.delete(E),r(C=>C.activeTourId===E?{...C,activeTourId:null,isRunning:!1,stepIndex:0}:C)},[c]),g=m.useCallback((E,C=0)=>{c.has(E)&&r({activeTourId:E,stepIndex:C,isRunning:!0})},[c]),N=m.useCallback(()=>{r(E=>({...E,isRunning:!1}))},[]),v=m.useCallback(E=>{r(C=>({...C,stepIndex:E}))},[]),w=m.useCallback(()=>{r(E=>({...E,stepIndex:E.stepIndex+1}))},[]),b=m.useCallback(()=>{r(E=>({...E,stepIndex:Math.max(0,E.stepIndex-1)}))},[]),y=m.useCallback(()=>n.activeTourId?c.get(n.activeTourId)||[]:[],[n.activeTourId,c]),O=m.useCallback(E=>{u(C=>{const A=new Set(C);return A.add(E),$g(A),A})},[]),R=m.useCallback(E=>{const{action:C,index:A,status:F,type:L}=E,J=["finished","skipped"];if(C==="close"){r(U=>({...U,isRunning:!1,stepIndex:0}));return}J.includes(F)?r(U=>(F==="finished"&&U.activeTourId&&setTimeout(()=>O(U.activeTourId),0),{...U,isRunning:!1,stepIndex:0})):L==="step:after"&&(C==="next"?r(U=>({...U,stepIndex:A+1})):C==="prev"&&r(U=>({...U,stepIndex:A-1})))},[O]),S=m.useCallback(E=>d.has(E),[d]),B=m.useCallback(E=>{u(C=>{const A=new Set(C);return A.delete(E),$g(A),A})},[]);return e.jsx(Fv.Provider,{value:{state:n,tours:c,registerTour:f,unregisterTour:p,startTour:g,stopTour:N,goToStep:v,nextStep:w,prevStep:b,getCurrentSteps:y,handleJoyrideCallback:R,isTourCompleted:S,markTourCompleted:O,resetTourCompleted:B},children:a})}function px(){const a=m.useContext(Fv);if(!a)throw new Error("useTour must be used within a TourProvider");return a}const MS={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)"}},AS={back:"上一步",close:"关闭",last:"完成",next:"下一步",nextLabelWithProgress:"下一步 ({step}/{steps})",open:"打开对话框",skip:"跳过"};function zS(){const{state:a,getCurrentSteps:n,handleJoyrideCallback:r}=px(),c=n(),[d,u]=m.useState(!1),h=m.useRef(a.stepIndex),f=m.useRef(null);m.useEffect(()=>{h.current!==a.stepIndex&&(u(!1),h.current=a.stepIndex)},[a.stepIndex]),m.useEffect(()=>{if(!a.isRunning||c.length===0){u(!1);return}const v=c[a.stepIndex];if(!v){u(!1);return}const w=v.target;if(w==="body"){u(!0);return}u(!1);const b=setTimeout(()=>{const y=()=>{const B=document.querySelector(w);if(B){const E=B.getBoundingClientRect();if(E.width>0&&E.height>0)return!0}return!1};if(y()){setTimeout(()=>u(!0),100);return}const O=setInterval(()=>{y()&&(clearInterval(O),setTimeout(()=>u(!0),100))},100),R=setTimeout(()=>{clearInterval(O),u(!0)},5e3),S=()=>{clearInterval(O),clearTimeout(R)};f.current=S},150);return()=>{clearTimeout(b),f.current&&(f.current(),f.current=null)}},[a.isRunning,a.stepIndex,c]);const[p,g]=m.useState(null);if(m.useEffect(()=>{let v=document.getElementById("tour-portal-container");return v||(v=document.createElement("div"),v.id="tour-portal-container",v.style.cssText="position: fixed; top: 0; left: 0; z-index: 99999; pointer-events: none;",document.body.appendChild(v)),g(v),()=>{}},[]),!a.isRunning||c.length===0||!d)return null;const N=e.jsx(d1,{steps:c,stepIndex:a.stepIndex,run:a.isRunning,continuous:!0,showSkipButton:!0,showProgress:!0,disableOverlayClose:!0,disableScrolling:!1,disableScrollParentFix:!1,callback:r,styles:MS,locale:AS,scrollOffset:80,scrollToFirstStep:!0,floaterProps:{styles:{floater:{zIndex:99999}},disableAnimation:!0}},`tour-step-${a.stepIndex}`);return p?Q0.createPortal(N,p):N}const ol="model-assignment-tour",Vv=[{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}],Gv={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"},Xi=[{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 Bg(a){return a?a.replace(/\/+$/,"").toLowerCase():""}function RS(a){if(!a)return null;const n=Bg(a);return Xi.find(r=>r.id!=="custom"&&Bg(r.base_url)===n)||null}const Do=a=>({...a,max_retry:a.max_retry??2,timeout:a.timeout??30,retry_interval:a.retry_interval??10}),DS=(a,n=[],r=null)=>{const c={};return a?(a.name?.trim()?n.some((u,h)=>r!==null&&h===r?!1:u.name.trim().toLowerCase()===a.name.trim().toLowerCase())&&(c.name="提供商名称已存在,请使用其他名称"):c.name="请输入提供商名称",a.base_url?.trim()||(c.base_url="请输入基础 URL"),a.api_key?.trim()||(c.api_key="请输入 API Key"),{isValid:Object.keys(c).length===0,errors:c}):{isValid:!1,errors:{name:"提供商数据为空"}}};function OS(){return e.jsx(Wn,{children:e.jsx(LS,{})})}function LS(){const[a,n]=m.useState([]),[r,c]=m.useState(!0),[d,u]=m.useState(!1),[h,f]=m.useState(!1),[p,g]=m.useState(!1),[N,v]=m.useState(!1),[w,b]=m.useState(null),[y,O]=m.useState(null),[R,S]=m.useState("custom"),[B,E]=m.useState(!1),[C,A]=m.useState(!1),[F,L]=m.useState(null),[J,U]=m.useState(!1),[oe,Ne]=m.useState(""),[je,re]=m.useState(new Set),[fe,ge]=m.useState(!1),[M,K]=m.useState(1),[P,ue]=m.useState(20),[Q,Se]=m.useState(""),[pe,Te]=m.useState({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),[z,D]=m.useState({}),[G,de]=m.useState(new Set),[Re,W]=m.useState(new Map),{toast:Y}=Ys(),Fe=ca(),{state:H,goToStep:ee,registerTour:Ue}=px(),{triggerRestart:ie,isRestarting:Ee}=yn(),me=m.useRef(null),Ae=m.useRef(!0);m.useEffect(()=>{Ue(ol,Vv)},[Ue]),m.useEffect(()=>{if(H.activeTourId===ol&&H.isRunning){const se=Gv[H.stepIndex];se&&!window.location.pathname.endsWith(se.replace("/config/",""))&&Fe({to:se})}},[H.stepIndex,H.activeTourId,H.isRunning,Fe]);const rs=m.useRef(H.stepIndex);m.useEffect(()=>{if(H.activeTourId===ol&&H.isRunning){const se=rs.current,we=H.stepIndex;se>=3&&se<=9&&we<3&&v(!1),se>=10&&we>=3&&we<=9&&(D({}),S("custom"),b({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10}),O(null),U(!1),v(!0)),rs.current=we}},[H.stepIndex,H.activeTourId,H.isRunning]),m.useEffect(()=>{if(H.activeTourId!==ol||!H.isRunning)return;const se=we=>{const Le=we.target,Fs=H.stepIndex;Fs===2&&Le.closest('[data-tour="add-provider-button"]')?setTimeout(()=>ee(3),300):Fs===9&&Le.closest('[data-tour="provider-cancel-button"]')&&setTimeout(()=>ee(10),300)};return document.addEventListener("click",se,!0),()=>document.removeEventListener("click",se,!0)},[H,ee]),m.useEffect(()=>{Ut()},[]);const Ut=async()=>{try{c(!0);const se=await xn();n(se.api_providers||[]),g(!1),Ae.current=!1}catch(se){console.error("加载配置失败:",se)}finally{c(!1)}},aa=async()=>{await ie()},Ja=async()=>{try{u(!0),me.current&&clearTimeout(me.current);const se=a.map(rt=>({...rt,max_retry:rt.max_retry??2,timeout:rt.timeout??30,retry_interval:rt.retry_interval??10})),{shouldProceed:we}=await Ht(se,"restart");if(!we){u(!1);return}const Le=await xn(),Fs=new Set(se.map(rt=>rt.name)),ea=(Le.models||[]).filter(rt=>Fs.has(rt.api_provider));Le.api_providers=se,Le.models=ea,await tc(Le),g(!1),Y({title:"保存成功",description:"正在重启麦麦..."}),await aa()}catch(se){console.error("保存配置失败:",se),Y({title:"保存失败",description:se.message,variant:"destructive"}),u(!1)}},Ht=m.useCallback(async(se,we="auto")=>{try{const Le=await xn(),Fs=new Set(a.map(xt=>xt.name)),Dt=new Set(se.map(xt=>xt.name)),ea=Array.from(Fs).filter(xt=>!Dt.has(xt));if(ea.length===0)return{shouldProceed:!0,providers:se};const sa=(Le.models||[]).filter(xt=>ea.includes(xt.api_provider));return sa.length===0?{shouldProceed:!0,providers:se}:(Te({isOpen:!0,providersToDelete:ea,affectedModels:sa,pendingProviders:se,context:we,oldProviders:[...a]}),{shouldProceed:!1,providers:se})}catch(Le){return console.error("检查删除影响失败:",Le),{shouldProceed:!0,providers:se}}},[a]),mt=async()=>{try{(pe.context==="auto"?f:u)(!0),Te(xt=>({...xt,isOpen:!1}));const we=await xn(),Le=pe.pendingProviders.map(Do),Fs=new Set(Le.map(xt=>xt.name)),ea=(we.models||[]).filter(xt=>Fs.has(xt.api_provider)),rt=new Set(pe.affectedModels.map(xt=>xt.name)),sa=we.model_task_config;sa&&Object.keys(sa).forEach(xt=>{const ne=sa[xt];ne&&Array.isArray(ne.model_list)&&(ne.model_list=ne.model_list.filter(he=>!rt.has(he)))}),we.api_providers=Le,we.models=ea,we.model_task_config=sa,await tc(we),n(pe.pendingProviders),g(!1),Y({title:"删除成功",description:`已删除 ${pe.providersToDelete.length} 个提供商和 ${pe.affectedModels.length} 个关联模型`}),Te({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),re(new Set),pe.context==="restart"&&await aa()}catch(se){console.error("删除失败:",se),Y({title:"删除失败",description:se.message,variant:"destructive"})}finally{pe.context==="auto"?f(!1):u(!1)}},q=()=>{pe.oldProviders.length>0&&n(pe.oldProviders),Te({isOpen:!1,providersToDelete:[],affectedModels:[],pendingProviders:[],context:"auto",oldProviders:[]}),g(!1)},qe=m.useCallback(async se=>{if(Ae.current)return;const{shouldProceed:we}=await Ht(se,"auto");if(!we){g(!0);return}try{f(!0);const Le=se.map(Do);await Ym("api_providers",Le),g(!1)}catch(Le){console.error("自动保存失败:",Le),Y({title:"自动保存失败",description:Le.message,variant:"destructive"}),g(!0)}finally{f(!1)}},[a,Ht]);m.useEffect(()=>{if(!Ae.current)return g(!0),me.current&&clearTimeout(me.current),me.current=setTimeout(()=>{qe(a)},2e3),()=>{me.current&&clearTimeout(me.current)}},[a,qe]);const Qe=async()=>{try{u(!0),me.current&&clearTimeout(me.current);const se=a.map(Do),{shouldProceed:we}=await Ht(se,"manual");if(!we){u(!1);return}const Le=await xn(),Fs=new Set(se.map(rt=>rt.name)),Dt=Le.models||[],ea=Dt.filter(rt=>{const sa=Fs.has(rt.api_provider);return sa||console.warn(`模型 "${rt.name}" 引用了已删除的提供商 "${rt.api_provider}",将被移除`),sa});if(Dt.length!==ea.length){const rt=Dt.length-ea.length;Y({title:"注意",description:`已自动移除 ${rt} 个引用已删除提供商的模型`,variant:"default"})}console.log("发送的 providers 数据:",se),Le.api_providers=se,Le.models=ea,console.log("完整配置数据:",Le),await tc(Le),g(!1),Y({title:"保存成功",description:"模型提供商配置已保存"})}catch(se){console.error("保存配置失败:",se),Y({title:"保存失败",description:se.message,variant:"destructive"})}finally{u(!1)}},es=(se,we)=>{if(D({}),se){const Le=Xi.find(Fs=>Fs.base_url===se.base_url&&Fs.client_type===se.client_type);S(Le?.id||"custom"),b(se)}else S("custom"),b({name:"",base_url:"",api_key:"",client_type:"openai",max_retry:2,timeout:30,retry_interval:10});O(we),U(!1),v(!0)},Us=m.useCallback(se=>{S(se),E(!1);const we=Xi.find(Le=>Le.id===se);we&&we.id!=="custom"?b(Le=>({...Le,name:we.name,base_url:we.base_url,client_type:we.client_type})):we?.id==="custom"&&b(Le=>({...Le,name:"",base_url:"",client_type:"openai"}))},[]),as=m.useMemo(()=>R!=="custom",[R]),Cs=m.useCallback(async()=>{if(w?.api_key)try{await navigator.clipboard.writeText(w.api_key),Y({title:"复制成功",description:"API Key 已复制到剪贴板"})}catch{Y({title:"复制失败",description:"无法访问剪贴板",variant:"destructive"})}},[w?.api_key,Y]),ze=()=>{if(!w)return;const{isValid:se,errors:we}=DS(w,a,y);if(!se){D(we);return}D({});const Le=Do(w);if(y!==null){const Fs=[...a];Fs[y]=Le,n(Fs)}else n([...a,Le]);v(!1),b(null),O(null)},bs=se=>{if(!se&&w){const we={...w,max_retry:w.max_retry??2,timeout:w.timeout??30,retry_interval:w.retry_interval??10};b(we)}v(se)},ls=se=>{L(se),A(!0)},ss=async()=>{if(F!==null){const se=a.filter((Le,Fs)=>Fs!==F),{shouldProceed:we}=await Ht(se,"manual");we&&(n(se),Y({title:"删除成功",description:"提供商已从列表中移除"}))}A(!1),L(null)},ys=se=>{const we=new Set(je);we.has(se)?we.delete(se):we.add(se),re(we)},gt=()=>{if(je.size===Ms.length)re(new Set);else{const se=Ms.map((we,Le)=>a.findIndex(Fs=>Fs===Ms[Le]));re(new Set(se))}},$t=()=>{if(je.size===0){Y({title:"提示",description:"请先选择要删除的提供商",variant:"default"});return}ge(!0)},tt=async()=>{const se=a.filter((Le,Fs)=>!je.has(Fs)),{shouldProceed:we}=await Ht(se,"manual");we&&(n(se),re(new Set),Y({title:"批量删除成功",description:`已删除 ${je.size} 个提供商`})),ge(!1)},Ms=m.useMemo(()=>{if(!oe)return a;const se=oe.toLowerCase();return a.filter(we=>we.name.toLowerCase().includes(se)||we.base_url.toLowerCase().includes(se)||we.client_type.toLowerCase().includes(se))},[a,oe]),{totalPages:Et,paginatedProviders:Bt}=m.useMemo(()=>{const se=Math.ceil(Ms.length/P),we=Ms.slice((M-1)*P,M*P);return{totalPages:se,paginatedProviders:we}},[Ms,M,P]),Oa=m.useCallback(()=>{const se=parseInt(Q);se>=1&&se<=Et&&(K(se),Se(""))},[Q,Et]),ll=async se=>{de(we=>new Set(we).add(se));try{const we=await hS(se);W(Le=>new Map(Le).set(se,we)),we.network_ok?we.api_key_valid===!0?Y({title:"连接正常",description:`${se} 网络连接正常,API Key 有效 (${we.latency_ms}ms)`}):we.api_key_valid===!1?Y({title:"连接正常但 Key 无效",description:`${se} 网络连接正常,但 API Key 无效或已过期`,variant:"destructive"}):Y({title:"网络连接正常",description:`${se} 可以访问 (${we.latency_ms}ms)`}):Y({title:"连接失败",description:we.error||"无法连接到提供商",variant:"destructive"})}catch(we){Y({title:"测试失败",description:we.message,variant:"destructive"})}finally{de(we=>{const Le=new Set(we);return Le.delete(se),Le})}},xl=async()=>{for(const se of a)await ll(se.name)},sr=se=>{const we=G.has(se),Le=Re.get(se);return we?e.jsxs(ke,{variant:"secondary",className:"gap-1",children:[e.jsx(zs,{className:"h-3 w-3 animate-spin"}),"测试中"]}):Le?Le.network_ok?Le.api_key_valid===!0?e.jsxs(ke,{className:"gap-1 bg-green-600 hover:bg-green-700",children:[e.jsx(pt,{className:"h-3 w-3"}),"正常"]}):Le.api_key_valid===!1?e.jsxs(ke,{variant:"destructive",className:"gap-1",children:[e.jsx(_t,{className:"h-3 w-3"}),"Key无效"]}):e.jsxs(ke,{className:"gap-1 bg-blue-600 hover:bg-blue-700",children:[e.jsx(pt,{className:"h-3 w-3"}),"可访问"]}):e.jsxs(ke,{variant:"destructive",className:"gap-1",children:[e.jsx(Ka,{className:"h-3 w-3"}),"离线"]}):null};return r?e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})}):e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"AI模型厂商配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理 AI 模型厂商的 API 配置"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[je.size>0&&e.jsxs(_,{onClick:$t,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(ns,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",je.size,")"]}),e.jsxs(_,{onClick:xl,size:"sm",variant:"outline",className:"w-full sm:w-auto",disabled:a.length===0||G.size>0,children:[e.jsx(el,{className:"mr-2 h-4 w-4"}),G.size>0?`测试中 (${G.size})`:"测试全部"]}),e.jsxs(_,{onClick:()=>es(null,null),size:"sm",className:"w-full sm:w-auto","data-tour":"add-provider-button",children:[e.jsx(et,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"添加提供商"]}),e.jsxs(_,{onClick:Qe,disabled:d||h||!p||Ee,size:"sm",variant:"outline",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(fc,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),d?"保存中...":h?"自动保存中...":p?"保存配置":"已保存"]}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{disabled:d||h||Ee,size:"sm",className:"w-full sm:w-auto sm:min-w-[120px]",children:[e.jsx(hc,{className:"mr-2 h-4 w-4"}),Ee?"重启中...":p?"保存并重启":"重启麦麦"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重启麦麦?"}),e.jsx(fs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:p?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:p?Ja:aa,children:p?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsxs(lt,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),e.jsxs(Je,{className:"h-[calc(100vh-260px)]",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-2 mb-4",children:[e.jsxs("div",{className:"relative w-full sm:flex-1 sm:max-w-sm",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ae,{placeholder:"搜索提供商名称、URL 或类型...",value:oe,onChange:se=>Ne(se.target.value),className:"pl-9"})]}),oe&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",Ms.length," 个结果"]})]}),e.jsx("div",{className:"md:hidden space-y-3",children:Ms.length===0?e.jsx("div",{className:"text-center text-muted-foreground py-8 rounded-lg border bg-card",children:oe?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'}):Bt.map((se,we)=>{const Le=a.findIndex(Fs=>Fs===se);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:se.name}),sr(se.name)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 break-all",children:se.base_url})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>ll(se.name),disabled:G.has(se.name),title:"测试连接",children:G.has(se.name)?e.jsx(zs,{className:"h-4 w-4 animate-spin"}):e.jsx(el,{className:"h-4 w-4"})}),e.jsx(_,{variant:"default",size:"sm",onClick:()=>es(se,Le),children:e.jsx(Kn,{className:"h-4 w-4",strokeWidth:2,fill:"none"})}),e.jsx(_,{size:"sm",onClick:()=>ls(Le),className:"bg-red-600 hover:bg-red-700 text-white",children:e.jsx(ns,{className:"h-4 w-4",strokeWidth:2,fill:"none"})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"客户端类型"}),e.jsx("p",{className:"font-medium",children:se.client_type})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"最大重试"}),e.jsx("p",{className:"font-medium",children:se.max_retry})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"超时(秒)"}),e.jsx("p",{className:"font-medium",children:se.timeout})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"重试间隔(秒)"}),e.jsx("p",{className:"font-medium",children:se.retry_interval})]})]})]},we)})}),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(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:je.size===Ms.length&&Ms.length>0,onCheckedChange:gt})}),e.jsx(We,{children:"状态"}),e.jsx(We,{children:"名称"}),e.jsx(We,{children:"基础URL"}),e.jsx(We,{children:"客户端类型"}),e.jsx(We,{className:"text-right",children:"最大重试"}),e.jsx(We,{className:"text-right",children:"超时(秒)"}),e.jsx(We,{className:"text-right",children:"重试间隔(秒)"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:Bt.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:9,className:"text-center text-muted-foreground py-8",children:oe?"未找到匹配的提供商":'暂无提供商配置,点击"添加提供商"开始配置'})}):Bt.map((se,we)=>{const Le=a.findIndex(Fs=>Fs===se);return e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(qs,{checked:je.has(Le),onCheckedChange:()=>ys(Le)})}),e.jsx(Ke,{children:sr(se.name)||e.jsx(ke,{variant:"outline",className:"text-muted-foreground",children:"未测试"})}),e.jsx(Ke,{className:"font-medium",children:se.name}),e.jsx(Ke,{className:"max-w-xs truncate",title:se.base_url,children:se.base_url}),e.jsx(Ke,{children:se.client_type}),e.jsx(Ke,{className:"text-right",children:se.max_retry}),e.jsx(Ke,{className:"text-right",children:se.timeout}),e.jsx(Ke,{className:"text-right",children:se.retry_interval}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>ll(se.name),disabled:G.has(se.name),title:"测试连接",children:G.has(se.name)?e.jsx(zs,{className:"h-4 w-4 animate-spin"}):e.jsx(el,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"default",size:"sm",onClick:()=>es(se,Le),children:[e.jsx(Kn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>ls(Le),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},we)})})]})})}),Ms.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(T,{htmlFor:"page-size-provider",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Pe,{value:P.toString(),onValueChange:se=>{ue(parseInt(se)),K(1),re(new Set)},children:[e.jsx($e,{id:"page-size-provider",className:"w-20",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"10",children:"10"}),e.jsx(Z,{value:"20",children:"20"}),e.jsx(Z,{value:"50",children:"50"}),e.jsx(Z,{value:"100",children:"100"})]})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(M-1)*P+1," 到"," ",Math.min(M*P,Ms.length)," 条,共 ",Ms.length," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>K(1),disabled:M===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>K(se=>Math.max(1,se-1)),disabled:M===1,children:[e.jsx(Da,{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(ae,{type:"number",value:Q,onChange:se=>Se(se.target.value),onKeyDown:se=>se.key==="Enter"&&Oa(),placeholder:M.toString(),className:"w-16 h-8 text-center",min:1,max:Et}),e.jsx(_,{variant:"outline",size:"sm",onClick:Oa,disabled:!Q,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>K(se=>se+1),disabled:M>=Et,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>K(Et),disabled:M>=Et,className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]}),e.jsx(Ps,{open:N,onOpenChange:bs,children:e.jsxs(Ds,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"provider-dialog",preventOutsideClose:H.isRunning,children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:y!==null?"编辑提供商":"添加提供商"}),e.jsx(Ks,{children:"配置 API 提供商的连接信息和参数"})]}),e.jsxs("form",{onSubmit:se=>{se.preventDefault(),ze()},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(T,{htmlFor:"template",children:"提供商模板"}),e.jsxs(ul,{open:B,onOpenChange:E,children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",role:"combobox","aria-expanded":B,className:"w-full justify-between",children:[R?Xi.find(se=>se.id===R)?.display_name:"选择提供商模板...",e.jsx(rx,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(sl,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(dd,{children:[e.jsx(ud,{placeholder:"搜索提供商模板..."}),e.jsx(Je,{className:"h-[300px]",children:e.jsxs(md,{className:"max-h-none overflow-visible",children:[e.jsx(xd,{children:"未找到匹配的模板"}),e.jsx(oc,{children:Xi.map(se=>e.jsxs(dc,{value:se.display_name,onSelect:()=>Us(se.id),children:[e.jsx(Ct,{className:`mr-2 h-4 w-4 ${R===se.id?"opacity-100":"opacity-0"}`}),se.display_name]},se.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(T,{htmlFor:"name",className:z.name?"text-destructive":"",children:"名称 *"}),e.jsx(ae,{id:"name",value:w?.name||"",onChange:se=>{b(we=>we?{...we,name:se.target.value}:null),z.name&&D(we=>({...we,name:void 0}))},placeholder:"例如: DeepSeek, SiliconFlow",className:z.name?"border-destructive focus-visible:ring-destructive":""}),z.name&&e.jsx("p",{className:"text-xs text-destructive",children:z.name})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"provider-url-input",children:[e.jsx(T,{htmlFor:"base_url",className:z.base_url?"text-destructive":"",children:"基础 URL *"}),e.jsx(ae,{id:"base_url",value:w?.base_url||"",onChange:se=>{b(we=>we?{...we,base_url:se.target.value}:null),z.base_url&&D(we=>({...we,base_url:void 0}))},placeholder:"https://api.example.com/v1",disabled:as,className:`${as?"bg-muted cursor-not-allowed":""} ${z.base_url?"border-destructive focus-visible:ring-destructive":""}`}),z.base_url&&e.jsx("p",{className:"text-xs text-destructive",children:z.base_url}),as&&!z.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(T,{htmlFor:"api_key",className:z.api_key?"text-destructive":"",children:"API Key *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{id:"api_key",type:J?"text":"password",value:w?.api_key||"",onChange:se=>{b(we=>we?{...we,api_key:se.target.value}:null),z.api_key&&D(we=>({...we,api_key:void 0}))},placeholder:"sk-...",className:`flex-1 ${z.api_key?"border-destructive focus-visible:ring-destructive":""}`}),e.jsx(_,{type:"button",variant:"outline",size:"icon",onClick:()=>U(!J),title:J?"隐藏密钥":"显示密钥",children:J?e.jsx(nc,{className:"h-4 w-4"}):e.jsx(ia,{className:"h-4 w-4"})}),e.jsx(_,{type:"button",variant:"outline",size:"icon",onClick:Cs,title:"复制密钥",children:e.jsx(Fo,{className:"h-4 w-4"})})]}),z.api_key&&e.jsx("p",{className:"text-xs text-destructive",children:z.api_key})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"client_type",children:"客户端类型"}),e.jsxs(Pe,{value:w?.client_type||"openai",onValueChange:se=>b(we=>we?{...we,client_type:se}:null),disabled:as,children:[e.jsx($e,{id:"client_type",className:as?"bg-muted cursor-not-allowed":"",children:e.jsx(Ie,{placeholder:"选择客户端类型"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"openai",children:"OpenAI"}),e.jsx(Z,{value:"gemini",children:"Gemini"})]})]}),as&&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(T,{htmlFor:"max_retry",children:"最大重试"}),e.jsx(ae,{id:"max_retry",type:"number",min:"0",value:w?.max_retry??"",onChange:se=>{const we=se.target.value===""?null:parseInt(se.target.value);b(Le=>Le?{...Le,max_retry:we}:null)},placeholder:"默认: 2"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"timeout",children:"超时(秒)"}),e.jsx(ae,{id:"timeout",type:"number",min:"1",value:w?.timeout??"",onChange:se=>{const we=se.target.value===""?null:parseInt(se.target.value);b(Le=>Le?{...Le,timeout:we}:null)},placeholder:"默认: 30"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"retry_interval",children:"重试间隔(秒)"}),e.jsx(ae,{id:"retry_interval",type:"number",min:"1",value:w?.retry_interval??"",onChange:se=>{const we=se.target.value===""?null:parseInt(se.target.value);b(Le=>Le?{...Le,retry_interval:we}:null)},placeholder:"默认: 10"})]})]})]}),e.jsxs(st,{children:[e.jsx(_,{type:"button",variant:"outline",onClick:()=>v(!1),"data-tour":"provider-cancel-button",children:"取消"}),e.jsx(_,{type:"submit","data-tour":"provider-save-button",children:"保存"})]})]})]})}),e.jsx(Ns,{open:C,onOpenChange:A,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除提供商 "',F!==null?a[F]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:ss,children:"删除"})]})]})}),e.jsx(Ns,{open:fe,onOpenChange:ge,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["确定要删除选中的 ",je.size," 个提供商吗? 此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:tt,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),e.jsx(Ns,{open:pe.isOpen,onOpenChange:se=>Te(we=>({...we,isOpen:se})),children:e.jsxs(us,{className:"max-w-2xl",children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除提供商"}),e.jsx(fs,{asChild:!0,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{children:["您即将删除以下提供商:",e.jsx("strong",{className:"text-foreground ml-1",children:pe.providersToDelete.join(", ")})]}),e.jsxs("p",{className:"text-yellow-600 dark:text-yellow-500 font-medium",children:["⚠️ 此操作将同时删除 ",pe.affectedModels.length," 个关联的模型:"]}),e.jsx(Je,{className:"h-32 w-full rounded border p-3",children:e.jsx("div",{className:"space-y-1",children:pe.affectedModels.map((se,we)=>e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:"•"}),e.jsx("span",{className:"ml-2 font-medium",children:se.name}),e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",se.model_identifier,")"]})]},we))})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"这些模型将从模型列表和所有任务分配中移除。此操作无法撤销。"})]})})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:q,children:"取消"}),e.jsx(ps,{onClick:mt,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})}),e.jsx(er,{})]})}function ac(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).substring(2,11)}`}function Um(a){return a===null?"null":Array.isArray(a)?"array":typeof a=="object"?"object":typeof a=="boolean"?"boolean":typeof a=="number"?"number":"string"}function Jm(a){return Object.entries(a).map(([n,r])=>{const c=Um(r),d={id:ac(),key:n,value:r,type:c,expanded:!0};return c==="object"&&r&&typeof r=="object"?d.children=Jm(r):c==="array"&&Array.isArray(r)&&(d.children=r.map((u,h)=>{const f=Um(u),p={id:ac(),key:String(h),value:u,type:f,expanded:!0};return f==="object"&&u&&typeof u=="object"?p.children=Jm(u):f==="array"&&Array.isArray(u)&&(p.children=u.map((g,N)=>({id:ac(),key:String(N),value:g,type:Um(g),expanded:!0}))),p})),d})}function Xm(a){const n={};for(const r of a)r.key.trim()&&(r.type==="object"&&r.children?n[r.key]=Xm(r.children):r.type==="array"&&r.children?n[r.key]=r.children.map(c=>c.type==="object"&&c.children?Xm(c.children):c.type==="array"&&c.children?c.children.map(d=>d.value):c.value):r.type==="null"?n[r.key]=null:n[r.key]=r.value);return n}function Pg(a,n){switch(n){case"boolean":return a==="true";case"number":{const r=parseFloat(a);return isNaN(r)?0:r}case"null":return null;default:return a}}function qv({node:a,level:n,onUpdate:r,onRemove:c,onAddChild:d,onToggleExpand:u}){const h=a.type==="object"||a.type==="array",f=a.children&&a.children.length>0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"grid gap-2 items-center",style:{gridTemplateColumns:h?"32px 1fr 90px 64px":"32px 1fr 1fr 90px 32px",paddingLeft:`${n*20}px`},children:[e.jsx(_,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>u(a.id),disabled:!h||!f,children:h&&f?a.expanded?e.jsx(za,{className:"h-4 w-4"}):e.jsx(Wt,{className:"h-4 w-4"}):e.jsx("span",{className:"w-4"})}),e.jsx(ae,{value:a.key,onChange:p=>r(a.id,"key",p.target.value),placeholder:"key",className:"h-8 text-sm"}),!h&&e.jsx(e.Fragment,{children:a.type==="boolean"?e.jsxs("div",{className:"flex items-center h-8 px-3 border rounded-md bg-background",children:[e.jsx(Ve,{checked:a.value===!0,onCheckedChange:p=>r(a.id,"value",p)}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:a.value?"true":"false"})]}):a.type==="null"?e.jsx("div",{className:"flex items-center h-8 px-3 border rounded-md bg-muted text-sm text-muted-foreground",children:"null"}):e.jsx(ae,{type:a.type==="number"?"number":"text",value:a.value,onChange:p=>r(a.id,"value",p.target.value),placeholder:"value",className:"h-8 text-sm",step:a.type==="number"?"any":void 0})}),e.jsxs(Pe,{value:a.type,onValueChange:p=>r(a.id,"type",p),children:[e.jsx($e,{className:"h-8 text-xs",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"string",children:"字符串"}),e.jsx(Z,{value:"number",children:"数字"}),e.jsx(Z,{value:"boolean",children:"布尔"}),e.jsx(Z,{value:"null",children:"Null"}),e.jsx(Z,{value:"object",children:"对象"}),e.jsx(Z,{value:"array",children:"数组"})]})]}),e.jsxs("div",{className:"flex gap-1 justify-end",children:[h&&e.jsx(_,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-primary",onClick:()=>d(a.id),title:"添加子项",children:e.jsx(et,{className:"h-4 w-4"})}),e.jsx(_,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>c(a.id),title:"删除",children:e.jsx(ns,{className:"h-4 w-4"})})]})]}),h&&a.expanded&&a.children&&a.children.length>0&&e.jsx("div",{className:"space-y-1",children:a.children.map(p=>e.jsx(qv,{node:p,level:n+1,onUpdate:r,onRemove:c,onAddChild:d,onToggleExpand:u},p.id))})]})}function US({value:a,onChange:n,placeholder:r="添加参数..."}){const[c,d]=m.useState(()=>Jm(a||{})),u=m.useCallback(v=>{d(v),n(Xm(v))},[n]),h=m.useCallback(()=>{const v={id:ac(),key:"",value:"",type:"string",expanded:!1};u([...c,v])},[c,u]),f=m.useCallback((v,w,b)=>{const y=O=>O.map(R=>{if(R.id===v)if(w==="type"){const S=b;if(S==="object")return{...R,type:S,value:{},children:[]};if(S==="array")return{...R,type:S,value:[],children:[]};if(S==="null")return{...R,type:S,value:null};{const B=Pg(String(R.value),S);return{...R,type:S,value:B,children:void 0}}}else if(w==="value"){const S=Pg(String(b),R.type);return{...R,value:S}}else return{...R,[w]:String(b)};return R.children?{...R,children:y(R.children)}:R});u(y(c))},[c,u]),p=m.useCallback(v=>{const w=b=>b.filter(y=>y.id!==v).map(y=>y.children?{...y,children:w(y.children)}:y);u(w(c))},[c,u]),g=m.useCallback(v=>{const w=b=>b.map(y=>{if(y.id===v){const O={id:ac(),key:y.type==="array"?String(y.children?.length||0):"",value:"",type:"string",expanded:!0};return{...y,children:[...y.children||[],O]}}return y.children?{...y,children:w(y.children)}:y});u(w(c))},[c,u]),N=m.useCallback(v=>{const w=b=>b.map(y=>y.id===v?{...y,expanded:!y.expanded}:y.children?{...y,children:w(y.children)}:y);d(w(c))},[c]);return e.jsxs("div",{className:"h-full flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[c.length," 个参数"]}),e.jsxs(_,{type:"button",size:"sm",variant:"outline",onClick:h,className:"h-7 text-xs",children:[e.jsx(et,{className:"h-3 w-3 mr-1"}),"添加参数"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto space-y-1",children:c.length===0?e.jsx("div",{className:"text-sm text-muted-foreground text-center py-4 border border-dashed rounded-md",children:r}):e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"grid gap-2 text-xs text-muted-foreground px-1 sticky top-0 bg-background z-10",style:{gridTemplateColumns:"32px 1fr 1fr 90px 32px"},children:[e.jsx("span",{}),e.jsx("span",{children:"键名"}),e.jsx("span",{children:"值"}),e.jsx("span",{children:"类型"}),e.jsx("span",{})]}),c.map(v=>e.jsx(qv,{node:v,level:0,onUpdate:f,onRemove:p,onAddChild:g,onToggleExpand:N},v.id))]})})]})}function Ig(a){if(!a.trim())return{valid:!0,parsed:{}};try{const n=JSON.parse(a);return typeof n!="object"||n===null||Array.isArray(n)?{valid:!1,error:"必须是一个 JSON 对象 {}"}:{valid:!0,parsed:n}}catch{return{valid:!1,error:"JSON 格式错误"}}}function $S({value:a,onChange:n,className:r,placeholder:c="添加额外参数..."}){const[d,u]=m.useState("list"),h=m.useMemo(()=>Object.keys(a||{}).length>0?JSON.stringify(a,null,2):"",[a]),[f,p]=m.useState(h),[g,N]=m.useState(null);m.useEffect(()=>{p(h)},[h]);const v=m.useMemo(()=>{const y=Ig(f);return y.valid&&y.parsed?{success:!0,data:y.parsed}:{success:!1,data:{}}},[f]),w=m.useCallback(y=>{const O=y;O==="json"&&d==="list"&&(p(Object.keys(a).length>0?JSON.stringify(a,null,2):""),N(null)),u(O)},[d,a]),b=m.useCallback(y=>{p(y);const O=Ig(y);O.valid&&O.parsed?(N(null),n(O.parsed)):N(O.error||"JSON 格式错误")},[n]);return e.jsx("div",{className:I("h-full flex flex-col",r),children:e.jsxs(ta,{value:d,onValueChange:w,className:"w-full flex-1 flex flex-col",children:[e.jsxs(Zt,{className:"h-8 p-0.5 bg-muted/60 w-fit",children:[e.jsx(Xe,{value:"list",className:"h-7 px-3 text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"可视化编辑"}),e.jsx(Xe,{value:"json",className:"h-7 px-3 text-xs data-[state=active]:bg-background data-[state=active]:shadow-sm",children:"JSON 编辑"})]}),e.jsx(ws,{value:"list",className:"mt-2 flex-1 flex flex-col overflow-hidden data-[state=inactive]:hidden data-[state=inactive]:h-0",children:e.jsx(US,{value:a,onChange:n,placeholder:c})}),e.jsx(ws,{value:"json",className:"mt-2 flex-1 flex flex-col overflow-hidden data-[state=inactive]:hidden data-[state=inactive]:h-0",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col gap-2 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"编辑"}),g?e.jsxs("div",{className:"flex items-center gap-1 text-xs text-destructive",children:[e.jsx(_t,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate max-w-[150px]",children:g})]}):f.trim()&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-green-600 dark:text-green-400",children:[e.jsx(Ct,{className:"h-3 w-3"}),e.jsx("span",{children:"有效"})]})]}),e.jsx(ot,{value:f,onChange:y=>b(y.target.value),placeholder:`{ - "key": "value" -}`,className:I("font-mono text-sm flex-1 resize-none",g&&"border-destructive focus-visible:ring-destructive")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"支持任意 JSON 类型(包括嵌套对象和数组)"})]}),e.jsxs("div",{className:"flex flex-col gap-2 overflow-hidden",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"预览"}),e.jsx("div",{className:"flex-1 rounded-md border bg-muted/30 p-3 overflow-auto",children:v.success&&Object.keys(v.data).length>0?e.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap break-words",children:JSON.stringify(v.data,null,2)}):v.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 BS({open:a,onOpenChange:n,value:r,onChange:c}){const[d,u]=m.useState(r),h=g=>{g&&u(r),n(g)},f=()=>{c(d),n(!1)},p=()=>{u(r),n(!1)};return e.jsx(Ps,{open:a,onOpenChange:h,children:e.jsxs(Ds,{className:"max-w-3xl h-[70vh] flex flex-col",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑额外参数"}),e.jsx(Ks,{children:"配置模型调用时的额外参数,支持嵌套对象和数组"})]}),e.jsx("div",{className:"flex-1 overflow-hidden min-h-0",children:e.jsx($S,{value:d,onChange:u,placeholder:"添加额外参数(如 thinking、top_p 等)..."})}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:p,children:"取消"}),e.jsx(_,{onClick:f,children:"保存"})]})]})})}const ei="https://maibot-plugin-stats.maibot-webui.workers.dev";async function PS(a){const n=new URLSearchParams;a?.status&&n.set("status",a.status),a?.page&&n.set("page",a.page.toString()),a?.page_size&&n.set("page_size",a.page_size.toString()),a?.search&&n.set("search",a.search),a?.sort_by&&n.set("sort_by",a.sort_by),a?.sort_order&&n.set("sort_order",a.sort_order);const r=await fetch(`${ei}/pack?${n.toString()}`);if(!r.ok)throw new Error(`获取 Pack 列表失败: ${r.status}`);return r.json()}async function IS(a){const n=await fetch(`${ei}/pack/${a}`);if(!n.ok)throw new Error(`获取 Pack 失败: ${n.status}`);const r=await n.json();if(!r.success)throw new Error(r.error||"获取 Pack 失败");return r.pack}async function FS(a){const r=await(await fetch(`${ei}/pack`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})).json();if(!r.success)throw new Error(r.error||"创建 Pack 失败");return r}async function HS(a,n){await fetch(`${ei}/pack/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pack_id:a,user_id:n})})}async function Kv(a,n){const c=await(await fetch(`${ei}/pack/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pack_id:a,user_id:n})})).json();if(!c.success)throw new Error(c.error||"点赞失败");return{likes:c.likes,liked:c.liked}}async function Qv(a,n){return(await(await fetch(`${ei}/pack/like/check?pack_id=${a}&user_id=${n}`)).json()).liked||!1}async function VS(a){const n=await _e("/api/webui/config/model");if(!n.ok)throw new Error("获取当前模型配置失败");const r=await n.json(),c=r.config||r;console.log("=== Pack Conflict Detection ==="),console.log("Pack providers:",a.providers),console.log("Local providers:",c.api_providers);const d={existing_providers:[],new_providers:[],conflicting_models:[]},u=c.api_providers||[];for(const f of a.providers){console.log(` -Checking pack provider: ${f.name}`),console.log(` Pack URL: ${f.base_url}`),console.log(` Normalized: ${$m(f.base_url)}`);const p=u.filter(g=>{const N=$m(g.base_url),v=$m(f.base_url);return console.log(` Comparing with local "${g.name}": ${g.base_url}`),console.log(` Local normalized: ${N}`),console.log(` Match: ${N===v}`),N===v});p.length>0?(console.log(` ✓ Matched with ${p.length} local provider(s):`,p.map(g=>g.name).join(", ")),d.existing_providers.push({pack_provider:f,local_providers:p.map(g=>({name:g.name,base_url:g.base_url}))})):(console.log(" ✗ No match found - will need API key"),d.new_providers.push(f))}const h=c.models||[];console.log(` -=== Model Conflict Detection ===`);for(const f of a.models){const p=h.find(g=>g.name===f.name);p&&(console.log(`Model conflict: ${f.name}`),d.conflicting_models.push({pack_model:f.name,local_model:p.name}))}return console.log(` -=== Detection Summary ===`),console.log(`Existing providers: ${d.existing_providers.length}`),console.log(`New providers: ${d.new_providers.length}`),console.log(`Conflicting models: ${d.conflicting_models.length}`),console.log(`=========================== -`),d}async function GS(a,n,r,c){const d=await _e("/api/webui/config/model");if(!d.ok)throw new Error("获取当前模型配置失败");const u=await d.json(),h=u.config||u;if(n.apply_providers){const p=n.selected_providers?a.providers.filter(g=>n.selected_providers.includes(g.name)):a.providers;for(const g of p){if(r[g.name])continue;const N=c[g.name];if(!N)throw new Error(`提供商 "${g.name}" 缺少 API Key`);const v={...g,api_key:N},w=h.api_providers.findIndex(b=>b.name===g.name);w>=0?h.api_providers[w]=v:h.api_providers.push(v)}}if(n.apply_models){const p=n.selected_models?a.models.filter(g=>n.selected_models.includes(g.name)):a.models;for(const g of p){const N=r[g.api_provider]||g.api_provider,v={...g,api_provider:N},w=h.models.findIndex(b=>b.name===g.name);w>=0?h.models[w]=v:h.models.push(v)}}if(n.apply_task_config){const p=n.selected_tasks||Object.keys(a.task_config);for(const g of p){const N=a.task_config[g];if(!N)continue;const v=new Set(n.selected_models||a.models.map(y=>y.name)),w=N.model_list.filter(y=>v.has(y));if(w.length===0)continue;const b={...N,model_list:w};if(n.task_mode==="replace")h.model_task_config[g]=b;else{const y=h.model_task_config[g];if(y){const O=[...new Set([...y.model_list,...w])];h.model_task_config[g]={...y,model_list:O}}else h.model_task_config[g]=b}}}if(!(await _e("/api/webui/config/model",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)})).ok)throw new Error("保存配置失败")}async function qS(a){const n=await _e("/api/webui/config/model");if(!n.ok)throw new Error("获取当前模型配置失败");const r=await n.json();if(!r.success||!r.config)throw new Error("获取配置失败");const c=r.config;let d=(c.api_providers||[]).map(g=>({name:g.name,base_url:g.base_url,client_type:g.client_type,max_retry:g.max_retry,timeout:g.timeout,retry_interval:g.retry_interval}));a.selectedProviders&&(d=d.filter(g=>a.selectedProviders.includes(g.name)));let u=c.models||[];a.selectedModels&&(u=u.filter(g=>a.selectedModels.includes(g.name)));const h={},f=c.model_task_config||{},p=a.selectedTasks||Object.keys(f);for(const g of p)f[g]&&(h[g]=f[g]);return{providers:d,models:u,task_config:h}}function $m(a){try{const n=new URL(a);return`${n.protocol}//${n.host}${n.pathname}`.replace(/\/$/,"").toLowerCase()}catch{return a.toLowerCase().replace(/\/$/,"")}}function Yv(){const a="maibot_pack_user_id";let n=localStorage.getItem(a);return n||(n="pack_user_"+Math.random().toString(36).substring(2,15),localStorage.setItem(a,n)),n}const KS={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",lpmm_qa:"问答模型"},QS=["官方推荐","性价比","高性能","免费模型","国内可用","海外模型","OpenAI","Claude","Gemini","国产模型","多模态","轻量级"];function YS({trigger:a}){const[n,r]=m.useState(!1),[c,d]=m.useState(1),[u,h]=m.useState(!1),[f,p]=m.useState(!1),[g,N]=m.useState([]),[v,w]=m.useState([]),[b,y]=m.useState({}),[O,R]=m.useState(new Set),[S,B]=m.useState(new Set),[E,C]=m.useState(new Set),[A,F]=m.useState(""),[L,J]=m.useState(""),[U,oe]=m.useState(""),[Ne,je]=m.useState([]);m.useEffect(()=>{n&&c===1&&re()},[n,c]);const re=async()=>{h(!0);try{const z=await qS({name:"",description:"",author:""});N(z.providers),w(z.models),y(z.task_config),R(new Set(z.providers.map(D=>D.name))),B(new Set(z.models.map(D=>D.name))),C(new Set(Object.keys(z.task_config)))}catch(z){console.error("加载配置失败:",z),Qt({title:"加载当前配置失败",variant:"destructive"})}finally{h(!1)}},fe=z=>{const D=new Set(O),G=new Set(S),de=new Set(E);D.has(z)?(D.delete(z),v.filter(W=>W.api_provider===z).forEach(W=>G.delete(W.name)),Object.entries(b).forEach(([W,Y])=>{Y.model_list&&(Y.model_list.some(H=>G.has(H))||de.delete(W))})):(D.add(z),v.filter(W=>W.api_provider===z).forEach(W=>G.add(W.name)),Object.entries(b).forEach(([W,Y])=>{Y.model_list&&Y.model_list.some(H=>{const ee=v.find(Ue=>Ue.name===H);return ee&&ee.api_provider===z})&&de.add(W)})),R(D),B(G),C(de)},ge=z=>{const D=new Set(S),G=new Set(E);D.has(z)?(D.delete(z),Object.entries(b).forEach(([de,Re])=>{Re.model_list&&(Re.model_list.some(Y=>D.has(Y))||G.delete(de))})):(D.add(z),Object.entries(b).forEach(([de,Re])=>{Re.model_list&&Re.model_list.includes(z)&&G.add(de)})),B(D),C(G)},M=z=>{const D=new Set(E);D.has(z)?D.delete(z):D.add(z),C(D)},K=z=>{Ne.includes(z)?je(Ne.filter(D=>D!==z)):Ne.length<5?je([...Ne,z]):Qt({title:"最多选择 5 个标签",variant:"destructive"})},P=()=>{O.size===g.length?R(new Set):R(new Set(g.map(z=>z.name)))},ue=()=>{S.size===v.length?B(new Set):B(new Set(v.map(z=>z.name)))},Q=()=>{const z=Object.keys(b);E.size===z.length?C(new Set):C(new Set(z))},Se=async()=>{if(!A.trim()){Qt({title:"请输入模板名称",variant:"destructive"});return}if(!L.trim()){Qt({title:"请输入模板描述",variant:"destructive"});return}if(!U.trim()){Qt({title:"请输入作者名称",variant:"destructive"});return}if(O.size===0&&S.size===0&&E.size===0){Qt({title:"请至少选择一项配置",variant:"destructive"});return}p(!0);try{const z=g.filter(de=>O.has(de.name)),D=v.filter(de=>S.has(de.name)),G={};for(const[de,Re]of Object.entries(b))E.has(de)&&(G[de]=Re);await FS({name:A.trim(),description:L.trim(),author:U.trim(),tags:Ne,providers:z,models:D,task_config:G}),Qt({title:"模板已提交审核,审核通过后将显示在市场中"}),r(!1),pe()}catch(z){console.error("提交失败:",z),Qt({title:z instanceof Error?z.message:"提交失败",variant:"destructive"})}finally{p(!1)}},pe=()=>{d(1),F(""),J(""),oe(""),je([]),R(new Set),B(new Set),C(new Set)},Te=2;return e.jsxs(Ps,{open:n,onOpenChange:r,children:[e.jsx(cd,{asChild:!0,children:a||e.jsxs(_,{variant:"outline",children:[e.jsx(nv,{className:"w-4 h-4 mr-2"}),"分享配置"]})}),e.jsxs(Ds,{className:"max-w-2xl max-h-[85vh] flex flex-col",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(ra,{className:"w-5 h-5"}),"分享配置模板"]}),e.jsxs(Ks,{children:["步骤 ",c," / ",Te,":",c===1&&"选择要分享的配置",c===2&&"填写模板信息"]})]}),e.jsx(Je,{className:"h-[calc(85vh-220px)] pr-4",children:u?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(zs,{className:"w-8 h-8 mx-auto animate-spin text-primary"}),e.jsx("p",{className:"mt-4 text-muted-foreground",children:"正在加载当前配置..."})]}):e.jsxs(e.Fragment,{children:[c===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(Gn,{children:"安全提示"}),e.jsxs(lt,{children:["分享的配置将",e.jsx("strong",{children:"不包含"})," API Key,其他用户需要自行配置。"]})]}),e.jsxs(ta,{defaultValue:"providers",className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-3",children:[e.jsxs(Xe,{value:"providers",children:[e.jsx(Ll,{className:"w-4 h-4 mr-2"}),"API 提供商",e.jsxs(ke,{variant:"secondary",className:"ml-2",children:[O.size,"/",g.length]})]}),e.jsxs(Xe,{value:"models",children:[e.jsx(Qn,{className:"w-4 h-4 mr-2"}),"模型配置",e.jsxs(ke,{variant:"secondary",className:"ml-2",children:[S.size,"/",v.length]})]}),e.jsxs(Xe,{value:"tasks",children:[e.jsx(Yn,{className:"w-4 h-4 mr-2"}),"任务配置",e.jsxs(ke,{variant:"secondary",className:"ml-2",children:[E.size,"/",Object.keys(b).length]})]})]}),e.jsx(ws,{value:"providers",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:P,children:O.size===g.length?"取消全选":"全选"})}),g.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无提供商配置"}):g.map(z=>e.jsxs("div",{className:"flex items-center space-x-2 p-2 rounded hover:bg-muted",children:[e.jsx(qs,{id:`provider-${z.name}`,checked:O.has(z.name),onCheckedChange:()=>fe(z.name)}),e.jsxs(T,{htmlFor:`provider-${z.name}`,className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:z.name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:z.base_url})]}),e.jsx(ke,{variant:"outline",className:"text-xs",children:z.client_type})]},z.name))]})}),e.jsx(ws,{value:"models",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:ue,children:S.size===v.length?"取消全选":"全选"})}),v.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无模型配置"}):v.map(z=>e.jsxs("div",{className:"flex items-center space-x-2 p-2 rounded hover:bg-muted",children:[e.jsx(qs,{id:`model-${z.name}`,checked:S.has(z.name),onCheckedChange:()=>ge(z.name)}),e.jsxs(T,{htmlFor:`model-${z.name}`,className:"flex-1 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:z.name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:z.model_identifier})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:z.api_provider})]},z.name))]})}),e.jsx(ws,{value:"tasks",className:"space-y-2 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"ghost",size:"sm",onClick:Q,children:E.size===Object.keys(b).length?"取消全选":"全选"})}),Object.keys(b).length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-2",children:"暂无任务配置"}):Object.entries(b).map(([z,D])=>e.jsxs("div",{className:"space-y-2 p-2 rounded hover:bg-muted",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:`task-${z}`,checked:E.has(z),onCheckedChange:()=>M(z)}),e.jsx(T,{htmlFor:`task-${z}`,className:"flex-1 cursor-pointer",children:e.jsx("span",{className:"font-medium",children:KS[z]||z})}),e.jsxs(ke,{variant:"outline",className:"text-xs",children:[D.model_list.length," 个模型"]})]}),D.model_list&&D.model_list.length>0&&e.jsx("div",{className:"ml-6 flex flex-wrap gap-1",children:D.model_list.map(G=>{const de=v.find(W=>W.name===G),Re=S.has(G);return e.jsxs(ke,{variant:Re?"default":"outline",className:"text-xs cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>ge(G),children:[G,de&&e.jsxs("span",{className:"ml-1 opacity-70",children:["(",de.api_provider,")"]})]},G)})})]},z))]})})]})]}),c===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-4 text-sm p-3 bg-muted rounded-lg",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ll,{className:"w-4 h-4"}),O.size," 个提供商"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Qn,{className:"w-4 h-4"}),S.size," 个模型"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Yn,{className:"w-4 h-4"}),E.size," 个任务"]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-name",children:"模板名称 *"}),e.jsx(ae,{id:"pack-name",placeholder:"例如:高性价比国产模型配置",value:A,onChange:z=>F(z.target.value),maxLength:50}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[A.length,"/50"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-description",children:"模板描述 *"}),e.jsx(ot,{id:"pack-description",placeholder:"详细描述这个配置模板的特点、适用场景等...",value:L,onChange:z=>J(z.target.value),rows:4,maxLength:500}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[L.length,"/500"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"pack-author",children:"作者名称 *"}),e.jsx(ae,{id:"pack-author",placeholder:"你的昵称或 ID",value:U,onChange:z=>oe(z.target.value),maxLength:30})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"标签(可选,最多 5 个)"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:QS.map(z=>e.jsxs(ke,{variant:Ne.includes(z)?"default":"outline",className:"cursor-pointer transition-colors",onClick:()=>K(z),children:[Ne.includes(z)&&e.jsx(Ct,{className:"w-3 h-3 mr-1"}),e.jsx(rd,{className:"w-3 h-3 mr-1"}),z]},z))})]})]}),e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(Gn,{children:"审核说明"}),e.jsx(lt,{children:"提交后需要经过审核才能在市场中展示。审核通常在 1-3 个工作日内完成。"})]})]})]})}),e.jsxs(st,{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:c>1&&e.jsx(_,{variant:"outline",onClick:()=>d(c-1),disabled:f,children:"上一步"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_,{variant:"outline",onClick:()=>{r(!1),pe()},disabled:f,children:"取消"}),cd(c+1),disabled:u||O.size===0&&S.size===0&&E.size===0,children:"下一步"}):e.jsxs(_,{onClick:Se,disabled:f,children:[f&&e.jsx(zs,{className:"w-4 h-4 mr-2 animate-spin"}),"提交审核"]})]})]})]})]})}function JS({value:a,label:n,onRemove:r}){const{attributes:c,listeners:d,setNodeRef:u,transform:h,transition:f,isDragging:p}=Nv({id:a}),g={transform:bv.Transform.toString(h),transition:f,opacity:p?.5:1},N=w=>{w.preventDefault(),w.stopPropagation(),r(a)},v=w=>{w.stopPropagation()};return e.jsx("div",{ref:u,style:g,className:I("inline-flex items-center gap-1",p&&"shadow-lg"),children:e.jsxs(ke,{variant:"secondary",className:"cursor-move hover:bg-secondary/80 flex items-center gap-1",children:[e.jsx("div",{...c,...d,className:"cursor-grab active:cursor-grabbing flex items-center",children:e.jsx(tv,{className:"h-3 w-3 text-muted-foreground"})}),e.jsx("span",{children:n}),e.jsx("span",{role:"button",tabIndex:0,className:"ml-1 rounded-sm hover:bg-destructive/20 focus:outline-none focus:ring-1 focus:ring-destructive cursor-pointer",onClick:N,onPointerDown:v,onMouseDown:w=>w.stopPropagation(),onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),N(w))},children:e.jsx(Aa,{className:"h-3 w-3 hover:text-destructive",strokeWidth:2,fill:"none"})})]})})}function XS({options:a,selected:n,onChange:r,placeholder:c="选择选项...",emptyText:d="未找到选项",className:u}){const[h,f]=m.useState(!1),p=mv(qo(fv,{activationConstraint:{distance:8}}),qo(hv,{coordinateGetter:xv})),g=w=>{n.includes(w)?r(n.filter(b=>b!==w)):r([...n,w])},N=w=>{r(n.filter(b=>b!==w))},v=w=>{const{active:b,over:y}=w;if(y&&b.id!==y.id){const O=n.indexOf(b.id),R=n.indexOf(y.id);r(pv(n,O,R))}};return e.jsxs(ul,{open:h,onOpenChange:f,children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",role:"combobox","aria-expanded":h,className:I("w-full justify-between min-h-10 h-auto",u),children:[e.jsx(gv,{sensors:p,collisionDetection:jv,onDragEnd:v,children:e.jsx(vv,{items:n,strategy:o1,children:e.jsx("div",{className:"flex gap-1 flex-wrap flex-1",children:n.length===0?e.jsx("span",{className:"text-muted-foreground",children:c}):n.map(w=>{const b=a.find(y=>y.value===w);return e.jsx(JS,{value:w,label:b?.label||w,onRemove:N},w)})})})}),e.jsx(rx,{className:"ml-2 h-4 w-4 shrink-0 opacity-50",strokeWidth:2,fill:"none"})]})}),e.jsx(sl,{className:"w-full p-0",align:"start",children:e.jsxs(dd,{children:[e.jsx(ud,{placeholder:"搜索...",className:"h-9"}),e.jsxs(md,{children:[e.jsx(xd,{children:d}),e.jsx(oc,{children:a.map(w=>{const b=n.includes(w.value);return e.jsxs(dc,{value:w.value,onSelect:()=>g(w.value),children:[e.jsx("div",{className:I("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",b?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(Ct,{className:"h-3 w-3",strokeWidth:2,fill:"none"})}),e.jsx("span",{children:w.label})]},w.value)})})]})]})})]})}const zl=Rs.memo(function({title:n,description:r,taskConfig:c,modelNames:d,onChange:u,hideTemperature:h=!1,hideMaxTokens:f=!1,dataTour:p}){const g=N=>{u("model_list",N)};return e.jsxs("div",{className:"rounded-lg border bg-card p-4 sm:p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-base sm:text-lg",children:n}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:r})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-2","data-tour":p,children:[e.jsx(T,{children:"模型列表"}),e.jsx(XS,{options:d.map(N=>({label:N,value:N})),selected:c.model_list||[],onChange:g,placeholder:"选择模型...",emptyText:"暂无可用模型"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[!h&&e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"温度"}),e.jsx(ae,{type:"number",step:"0.1",min:"0",max:"1",value:c.temperature??.3,onChange:N=>{const v=parseFloat(N.target.value);!isNaN(v)&&v>=0&&v<=1&&u("temperature",v)},className:"w-20 h-8 text-sm"})]}),e.jsx(Qa,{value:[c.temperature??.3],onValueChange:N=>u("temperature",N[0]),min:0,max:1,step:.1,className:"w-full"})]}),!f&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"最大 Token"}),e.jsx(ae,{type:"number",step:"1",min:"1",value:c.max_tokens??1024,onChange:N=>u("max_tokens",parseInt(N.target.value))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:"慢请求阈值 (秒)"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"超时警告"})]}),e.jsx(ae,{type:"number",step:"1",min:"1",value:c.slow_threshold??15,onChange:N=>{const v=parseInt(N.target.value);!isNaN(v)&&v>=1&&u("slow_threshold",v)},placeholder:"15"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"模型响应时间超过此阈值将输出警告日志"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{children:"模型选择策略"}),e.jsxs(Pe,{value:c.selection_strategy??"balance",onValueChange:N=>u("selection_strategy",N),children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:"选择模型选择策略"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"balance",children:"负载均衡(balance)"}),e.jsx(Z,{value:"random",children:"随机选择(random)"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"负载均衡:优先选择使用次数少的模型。随机选择:完全随机从模型列表中选择"})]})]})]})}),ZS=Rs.memo(function({paginatedModels:n,allModels:r,onEdit:c,onDelete:d,isModelUsed:u,searchQuery:h}){return n.length===0?e.jsx("div",{className:"md:hidden text-center text-muted-foreground py-8 rounded-lg border bg-card",children:h?"未找到匹配的模型":"暂无模型配置"}):e.jsx("div",{className:"md:hidden space-y-3",children:n.map((f,p)=>{const g=r.findIndex(v=>v===f),N=u(f.name);return e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold text-base",children:f.name}),e.jsx(ke,{variant:N?"default":"secondary",className:N?"bg-green-600 hover:bg-green-700":"",children:N?"已使用":"未使用"})]}),e.jsx("p",{className:"text-xs text-muted-foreground break-all",title:f.model_identifier,children:f.model_identifier})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>c(f,g),children:[e.jsx(Kn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>d(g),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"提供商"}),e.jsx("p",{className:"font-medium",children:f.api_provider})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"模型温度"}),e.jsx("p",{className:"font-medium",children:f.temperature!=null?f.temperature:e.jsx("span",{className:"text-muted-foreground",children:"默认"})})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输入价格"}),e.jsxs("p",{className:"font-medium",children:["¥",f.price_in,"/M"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"输出价格"}),e.jsxs("p",{className:"font-medium",children:["¥",f.price_out,"/M"]})]})]})]},p)})})}),WS=Rs.memo(function({paginatedModels:n,allModels:r,filteredModels:c,selectedModels:d,onEdit:u,onDelete:h,onToggleSelection:f,onToggleSelectAll:p,isModelUsed:g,searchQuery:N}){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(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:d.size===c.length&&c.length>0,onCheckedChange:p})}),e.jsx(We,{className:"w-24",children:"使用状态"}),e.jsx(We,{children:"模型名称"}),e.jsx(We,{children:"模型标识符"}),e.jsx(We,{children:"提供商"}),e.jsx(We,{className:"text-center",children:"温度"}),e.jsx(We,{className:"text-right",children:"输入价格"}),e.jsx(We,{className:"text-right",children:"输出价格"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:n.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:9,className:"text-center text-muted-foreground py-8",children:N?"未找到匹配的模型":"暂无模型配置"})}):n.map((v,w)=>{const b=r.findIndex(O=>O===v),y=g(v.name);return e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(qs,{checked:d.has(b),onCheckedChange:()=>f(b)})}),e.jsx(Ke,{children:e.jsx(ke,{variant:y?"default":"secondary",className:y?"bg-green-600 hover:bg-green-700":"",children:y?"已使用":"未使用"})}),e.jsx(Ke,{className:"font-medium",children:v.name}),e.jsx(Ke,{className:"max-w-xs truncate",title:v.model_identifier,children:v.model_identifier}),e.jsx(Ke,{children:v.api_provider}),e.jsx(Ke,{className:"text-center",children:v.temperature!=null?v.temperature:e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsxs(Ke,{className:"text-right",children:["¥",v.price_in,"/M"]}),e.jsxs(Ke,{className:"text-right",children:["¥",v.price_out,"/M"]}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>u(v,b),children:[e.jsx(Kn,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>h(b),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1",strokeWidth:2,fill:"none"}),"删除"]})]})})]},w)})})]})})})}),e4=300*1e3,Fg=new Map,s4=[10,20,50,100],t4=Rs.memo(function({page:n,pageSize:r,totalItems:c,jumpToPage:d,onPageChange:u,onPageSizeChange:h,onJumpToPageChange:f,onJumpToPage:p,onSelectionClear:g}){const N=Math.ceil(c/r),v=b=>{h(parseInt(b)),u(1),g?.()},w=b=>{b.key==="Enter"&&p()};return c===0?null:e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{htmlFor:"page-size-model",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Pe,{value:r.toString(),onValueChange:v,children:[e.jsx($e,{id:"page-size-model",className:"w-20",children:e.jsx(Ie,{})}),e.jsx(Be,{children:s4.map(b=>e.jsx(Z,{value:b.toString(),children:b},b))})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["显示 ",(n-1)*r+1," 到"," ",Math.min(n*r,c)," 条,共 ",c," 条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>u(1),disabled:n===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>u(Math.max(1,n-1)),disabled:n===1,children:[e.jsx(Da,{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(ae,{type:"number",value:d,onChange:b=>f(b.target.value),onKeyDown:w,placeholder:n.toString(),className:"w-16 h-8 text-center",min:1,max:N}),e.jsx(_,{variant:"outline",size:"sm",onClick:p,disabled:!d,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>u(n+1),disabled:n>=N,children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>u(N),disabled:n>=N,className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})});function a4(a){const{models:n,taskConfig:r,debounceMs:c=2e3,onSavingChange:d,onUnsavedChange:u}=a,h=m.useRef(null),f=m.useRef(null),p=m.useRef(!0),g=m.useCallback(()=>{h.current&&(clearTimeout(h.current),h.current=null),f.current&&(clearTimeout(f.current),f.current=null)},[]),N=m.useCallback(b=>{const y={model_identifier:b.model_identifier,name:b.name,api_provider:b.api_provider,price_in:b.price_in??0,price_out:b.price_out??0,force_stream_mode:b.force_stream_mode??!1,extra_params:b.extra_params??{}};return b.temperature!=null&&(y.temperature=b.temperature),b.max_tokens!=null&&(y.max_tokens=b.max_tokens),y},[]),v=m.useCallback(async b=>{try{d?.(!0);const y=b.map(N);await Ym("models",y),u?.(!1)}catch(y){console.error("自动保存模型列表失败:",y),u?.(!0)}finally{d?.(!1)}},[d,u,N]),w=m.useCallback(async b=>{try{d?.(!0),await Ym("model_task_config",b),u?.(!1)}catch(y){console.error("自动保存任务配置失败:",y),u?.(!0)}finally{d?.(!1)}},[d,u]);return m.useEffect(()=>{if(!p.current)return u?.(!0),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{v(n)},c),()=>{h.current&&clearTimeout(h.current)}},[n,v,c,u]),m.useEffect(()=>{if(!(p.current||!r))return u?.(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{w(r)},c),()=>{f.current&&clearTimeout(f.current)}},[r,w,c,u]),m.useEffect(()=>()=>{g()},[g]),{clearTimers:g,initialLoadRef:p}}function l4(a={}){const{onCloseEditDialog:n}=a,r=ca(),{registerTour:c,startTour:d,state:u,goToStep:h}=px(),f=m.useRef(u.stepIndex);return m.useEffect(()=>{c(ol,Vv)},[c]),m.useEffect(()=>{if(u.activeTourId===ol&&u.isRunning){const g=Gv[u.stepIndex];g&&!window.location.pathname.endsWith(g.replace("/config/",""))&&r({to:g})}},[u.stepIndex,u.activeTourId,u.isRunning,r]),m.useEffect(()=>{if(u.activeTourId===ol&&u.isRunning){const g=f.current,N=u.stepIndex;g>=12&&g<=17&&N<12&&n?.(),f.current=N}},[u.stepIndex,u.activeTourId,u.isRunning,n]),m.useEffect(()=>{if(u.activeTourId!==ol||!u.isRunning)return;const g=N=>{const v=N.target,w=u.stepIndex;w===2&&v.closest('[data-tour="add-provider-button"]')?setTimeout(()=>h(3),300):w===9&&v.closest('[data-tour="provider-cancel-button"]')?setTimeout(()=>h(10),300):w===11&&v.closest('[data-tour="add-model-button"]')?setTimeout(()=>h(12),300):w===17&&v.closest('[data-tour="model-cancel-button"]')?setTimeout(()=>h(18),300):w===18&&v.closest('[data-tour="tasks-tab-trigger"]')&&setTimeout(()=>h(19),300)};return document.addEventListener("click",g,!0),()=>document.removeEventListener("click",g,!0)},[u,h]),{startTour:m.useCallback(()=>{d(ol)},[d]),isRunning:u.isRunning&&u.activeTourId===ol,stepIndex:u.stepIndex}}function n4(a){const{getProviderConfig:n}=a,[r,c]=m.useState([]),[d,u]=m.useState(!1),[h,f]=m.useState(null),[p,g]=m.useState(null),N=m.useCallback(()=>{c([]),f(null),g(null)},[]),v=m.useCallback(async(w,b=!1)=>{const y=n(w);if(!y?.base_url){c([]),g(null),f('提供商配置不完整,请先在"模型提供商配置"中配置');return}if(!y.api_key){c([]),g(null),f('该提供商未配置 API Key,请先在"模型提供商配置"中填写');return}const O=RS(y.base_url);if(g(O),!O?.modelFetcher){c([]),f(null);return}const R=`${w}:${y.base_url}`,S=Fg.get(R);if(!b&&S&&Date.now()-S.timestampE(!1)}),{clearTimers:Ht,initialLoadRef:mt}=a4({models:a,taskConfig:p,onSavingChange:O,onUnsavedChange:S}),q=m.useCallback((ne,he)=>{if(!ne)return;const ts=new Set(he.map(va=>va.name)),js=[],is=[],jt=[{key:"utils",label:"工具模型"},{key:"tool_use",label:"工具调用模型"},{key:"replyer",label:"回复模型"},{key:"planner",label:"规划器模型"},{key:"vlm",label:"视觉模型"},{key:"voice",label:"语音模型"},{key:"embedding",label:"嵌入模型"},{key:"lpmm_entity_extract",label:"LPMM实体抽取"},{key:"lpmm_rdf_build",label:"LPMM关系构建"}];for(const{key:va,label:Il}of jt){const tr=ne[va];if(!tr)continue;if(!tr.model_list||tr.model_list.length===0){is.push(Il);continue}const ti=tr.model_list.filter(_n=>!ts.has(_n));ti.length>0&&js.push({taskName:Il,invalidModels:ti})}ee(js),ie(is)},[]),qe=m.useCallback(async()=>{try{v(!0);const ne=await xn(),he=ne.models||[];n(he),f(he.map(jt=>jt.name));const ts=ne.api_providers||[];c(ts.map(jt=>jt.name)),u(ts);const js=ne.model_task_config||null;g(js),q(js,he);const is=js?.embedding?.model_list||[];Y.current=[...is],S(!1),mt.current=!1}catch(ne){console.error("加载配置失败:",ne)}finally{v(!1)}},[mt,q]);m.useEffect(()=>{qe()},[qe]);const Qe=m.useCallback(ne=>d.find(he=>he.name===ne),[d]),{availableModels:es,fetchingModels:Us,modelFetchError:as,matchedTemplate:Cs,fetchModelsForProvider:ze,clearModels:bs}=n4({getProviderConfig:Qe});m.useEffect(()=>{B&&C?.api_provider&&ze(C.api_provider)},[B,C?.api_provider,ze]);const ls=async()=>{await rs()},ss=m.useCallback(()=>{if(!p)return;const ne=new Set(a.map(js=>js.name)),he={...p},ts=Object.keys(he);for(const js of ts){const is=he[js];is&&is.model_list&&(is.model_list=is.model_list.filter(jt=>ne.has(jt)))}g(he),ee([]),Ae({title:"清理完成",description:"已删除所有无效的模型引用"})},[p,a,Ae]),ys=ne=>{const he={model_identifier:ne.model_identifier,name:ne.name,api_provider:ne.api_provider,price_in:ne.price_in??0,price_out:ne.price_out??0,force_stream_mode:ne.force_stream_mode??!1,extra_params:ne.extra_params??{}};return ne.temperature!=null&&(he.temperature=ne.temperature),ne.max_tokens!=null&&(he.max_tokens=ne.max_tokens),he},gt=async()=>{try{b(!0),Ht();const ne=await xn();ne.models=a.map(ys),ne.model_task_config=p,await tc(ne),S(!1),Ae({title:"保存成功",description:"正在重启麦麦..."}),await ls()}catch(ne){console.error("保存配置失败:",ne),Ae({title:"保存失败",description:ne.message,variant:"destructive"}),b(!1)}},$t=async()=>{try{b(!0),Ht();const ne=await xn();ne.models=a.map(ys),ne.model_task_config=p,await tc(ne),S(!1),Ae({title:"保存成功",description:"模型配置已保存"}),await qe()}catch(ne){console.error("保存配置失败:",ne),Ae({title:"保存失败",description:ne.message,variant:"destructive"})}finally{b(!1)}},tt=(ne,he)=>{me({}),A(ne||{model_identifier:"",name:"",api_provider:r[0]||"",price_in:0,price_out:0,temperature:null,max_tokens:null,force_stream_mode:!1,extra_params:{}}),L(he),E(!0)},Ms=()=>{if(!C)return;const ne={};if(C.name?.trim()?a.some((jt,va)=>F!==null&&va===F?!1:jt.name.trim().toLowerCase()===C.name.trim().toLowerCase())&&(ne.name="模型名称已存在,请使用其他名称"):ne.name="请输入模型名称",C.api_provider?.trim()||(ne.api_provider="请选择 API 提供商"),C.model_identifier?.trim()||(ne.model_identifier="请输入模型标识符"),Object.keys(ne).length>0){me(ne);return}me({});const he={model_identifier:C.model_identifier,name:C.name,api_provider:C.api_provider,price_in:C.price_in??0,price_out:C.price_out??0,force_stream_mode:C.force_stream_mode??!1,extra_params:C.extra_params??{}};C.temperature!=null&&(he.temperature=C.temperature),C.max_tokens!=null&&(he.max_tokens=C.max_tokens);let ts,js=null;if(F!==null?(js=a[F].name,ts=[...a],ts[F]=he):ts=[...a,he],n(ts),f(ts.map(is=>is.name)),js&&js!==he.name&&p){const is=jt=>jt.map(va=>va===js?he.name:va);g({...p,utils:{...p.utils,model_list:is(p.utils?.model_list||[])},tool_use:{...p.tool_use,model_list:is(p.tool_use?.model_list||[])},replyer:{...p.replyer,model_list:is(p.replyer?.model_list||[])},planner:{...p.planner,model_list:is(p.planner?.model_list||[])},vlm:{...p.vlm,model_list:is(p.vlm?.model_list||[])},voice:{...p.voice,model_list:is(p.voice?.model_list||[])},embedding:{...p.embedding,model_list:is(p.embedding?.model_list||[])},lpmm_entity_extract:{...p.lpmm_entity_extract,model_list:is(p.lpmm_entity_extract?.model_list||[])},lpmm_rdf_build:{...p.lpmm_rdf_build,model_list:is(p.lpmm_rdf_build?.model_list||[])}})}E(!1),A(null),L(null),Ae({title:F!==null?"模型已更新":"模型已添加",description:'配置将在 2 秒后自动保存,或点击右上角"保存配置"按钮立即保存'})},Et=ne=>{if(!ne&&C){const he={...C,price_in:C.price_in??0,price_out:C.price_out??0};A(he)}E(ne)},Bt=ne=>{re(ne),Ne(!0)},Oa=()=>{if(je!==null){const ne=a.filter((he,ts)=>ts!==je);n(ne),f(ne.map(he=>he.name)),q(p,ne),Ae({title:"删除成功",description:'配置将在 2 秒后自动保存,或点击右上角"保存配置"按钮立即保存'})}Ne(!1),re(null)},ll=ne=>{const he=new Set(M);he.has(ne)?he.delete(ne):he.add(ne),K(he)},xl=()=>{if(M.size===Dt.length)K(new Set);else{const ne=Dt.map((he,ts)=>a.findIndex(js=>js===Dt[ts]));K(new Set(ne))}},sr=()=>{if(M.size===0){Ae({title:"提示",description:"请先选择要删除的模型",variant:"default"});return}ue(!0)},se=()=>{const ne=M.size,he=a.filter((ts,js)=>!M.has(js));n(he),f(he.map(ts=>ts.name)),q(p,he),K(new Set),ue(!1),Ae({title:"批量删除成功",description:`已删除 ${ne} 个模型,配置将在 2 秒后自动保存`})},we=(ne,he,ts)=>{if(!p)return;if(ne==="embedding"&&he==="model_list"&&Array.isArray(ts)){const is=Y.current,jt=ts;if((is.length!==jt.length||is.some(Il=>!jt.includes(Il))||jt.some(Il=>!is.includes(Il)))&&is.length>0){Fe.current={field:he,value:ts},W(!0);return}}const js={...p,[ne]:{...p[ne],[he]:ts}};g(js),q(js,a),ne==="embedding"&&he==="model_list"&&Array.isArray(ts)&&(Y.current=[...ts])},Le=()=>{if(!p||!Fe.current)return;const{field:ne,value:he}=Fe.current,ts={...p,embedding:{...p.embedding,[ne]:he}};g(ts),q(ts,a),ne==="model_list"&&Array.isArray(he)&&(Y.current=[...he]),Fe.current=null,W(!1),Ae({title:"嵌入模型已更新",description:"建议重新生成知识库向量以确保最佳匹配精度"})},Fs=()=>{Fe.current=null,W(!1)},Dt=a.filter(ne=>{if(!fe)return!0;const he=fe.toLowerCase();return ne.name.toLowerCase().includes(he)||ne.model_identifier.toLowerCase().includes(he)||ne.api_provider.toLowerCase().includes(he)}),ea=Math.ceil(Dt.length/pe),rt=Dt.slice((Q-1)*pe,Q*pe),sa=()=>{const ne=parseInt(z);ne>=1&&ne<=ea&&(Se(ne),D(""))},xt=ne=>p?[p.utils?.model_list||[],p.tool_use?.model_list||[],p.replyer?.model_list||[],p.planner?.model_list||[],p.vlm?.model_list||[],p.voice?.model_list||[],p.embedding?.model_list||[],p.lpmm_entity_extract?.model_list||[],p.lpmm_rdf_build?.model_list||[]].some(ts=>ts.includes(ne)):!1;return N?e.jsx(Je,{className:"h-full",children:e.jsx("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"加载中..."})})})}):e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"模型管理与分配"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"添加模型并为模型分配功能"})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsx(YS,{trigger:e.jsxs(_,{variant:"outline",size:"sm",className:"flex-1 sm:flex-none",children:[e.jsx(nv,{className:"mr-2 h-4 w-4"}),"分享配置"]})}),e.jsxs(_,{onClick:$t,disabled:w||y||!R||Ut,size:"sm",variant:"outline",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(fc,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),w?"保存中...":y?"自动保存中...":R?"保存配置":"已保存"]}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsxs(_,{disabled:w||y||Ut,size:"sm",className:"flex-1 sm:flex-none sm:min-w-[120px]",children:[e.jsx(hc,{className:"mr-2 h-4 w-4"}),Ut?"重启中...":R?"保存并重启":"重启麦麦"]})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认重启麦麦?"}),e.jsx(fs,{asChild:!0,children:e.jsx("div",{children:e.jsx("p",{children:R?"当前有未保存的配置更改。点击确认将先保存配置,然后重启麦麦使新配置生效。重启过程中麦麦将暂时离线。":"即将重启麦麦主程序。重启过程中麦麦将暂时离线,配置将在重启后生效。"})})})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:R?gt:ls,children:R?"保存并重启":"确认重启"})]})]})]})]})]}),e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsxs(lt,{children:["配置更新后需要",e.jsx("strong",{children:"重启麦麦"}),'才能生效。你可以点击右上角的"保存并重启"按钮一键完成保存和重启。']})]}),H.length>0&&e.jsxs(at,{variant:"destructive",children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(lt,{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("strong",{children:"检测到无效的模型引用"}),e.jsx("div",{className:"mt-2 space-y-1",children:H.map(({taskName:ne,invalidModels:he})=>e.jsxs("div",{className:"text-sm",children:[e.jsx("strong",{children:ne})," 引用了不存在的模型: ",he.join(", ")]},ne))})]}),e.jsx(_,{variant:"outline",size:"sm",className:"shrink-0 bg-background hover:bg-accent",onClick:ss,children:"一键清理"})]})]}),Ue.length>0&&e.jsxs(at,{variant:"default",className:"border-yellow-500/50 bg-yellow-500/10",children:[e.jsx(Jt,{className:"h-4 w-4 text-yellow-600"}),e.jsxs(lt,{children:[e.jsx("strong",{className:"text-yellow-600",children:"以下任务未配置模型"}),e.jsxs("div",{className:"mt-2 text-sm",children:[Ue.join("、")," 还未分配模型,这些功能将无法正常工作。"]})]})]}),e.jsxs(at,{className:"hidden lg:flex border-primary/30 bg-primary/5 cursor-pointer hover:bg-primary/10 transition-colors",onClick:aa,children:[e.jsx(E_,{className:"h-4 w-4 text-primary"}),e.jsxs(lt,{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[e.jsx("strong",{className:"text-primary",children:"新手引导:"}),"不知道如何配置模型?点击这里开始学习如何为麦麦的组件分配模型。"]}),e.jsx(_,{variant:"outline",size:"sm",className:"ml-4 shrink-0",children:"开始引导"})]})]}),e.jsxs(ta,{defaultValue:"models",className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full max-w-full sm:max-w-md grid-cols-2",children:[e.jsx(Xe,{value:"models",children:"添加模型"}),e.jsx(Xe,{value:"tasks","data-tour":"tasks-tab-trigger",children:"为模型分配功能"})]}),e.jsxs(ws,{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:[M.size>0&&e.jsxs(_,{onClick:sr,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(ns,{className:"mr-2 h-4 w-4",strokeWidth:2,fill:"none"}),"批量删除 (",M.size,")"]}),e.jsxs(_,{onClick:()=>tt(null,null),size:"sm",variant:"outline",className:"w-full sm:w-auto","data-tour":"add-model-button",children:[e.jsx(et,{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(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ae,{placeholder:"搜索模型名称、标识符或提供商...",value:fe,onChange:ne=>ge(ne.target.value),className:"pl-9"})]}),fe&&e.jsxs("p",{className:"text-sm text-muted-foreground whitespace-nowrap",children:["找到 ",Dt.length," 个结果"]})]}),e.jsx(ZS,{paginatedModels:rt,allModels:a,onEdit:tt,onDelete:Bt,isModelUsed:xt,searchQuery:fe}),e.jsx(WS,{paginatedModels:rt,allModels:a,filteredModels:Dt,selectedModels:M,onEdit:tt,onDelete:Bt,onToggleSelection:ll,onToggleSelectAll:xl,isModelUsed:xt,searchQuery:fe}),e.jsx(t4,{page:Q,pageSize:pe,totalItems:Dt.length,jumpToPage:z,onPageChange:Se,onPageSizeChange:Te,onJumpToPageChange:D,onJumpToPage:sa,onSelectionClear:()=>K(new Set)})]}),e.jsxs(ws,{value:"tasks",className:"space-y-6 mt-0",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"为不同的任务配置使用的模型和参数"}),p&&e.jsxs("div",{className:"grid gap-4 sm:gap-6",children:[e.jsx(zl,{title:"组件模型 (utils)",description:"用于表情包、取名、关系、情绪变化等组件",taskConfig:p.utils,modelNames:h,onChange:(ne,he)=>we("utils",ne,he),dataTour:"task-model-select"}),e.jsx(zl,{title:"工具调用模型 (tool_use)",description:"需要使用支持工具调用的模型",taskConfig:p.tool_use,modelNames:h,onChange:(ne,he)=>we("tool_use",ne,he)}),e.jsx(zl,{title:"首要回复模型 (replyer)",description:"用于表达器和表达方式学习",taskConfig:p.replyer,modelNames:h,onChange:(ne,he)=>we("replyer",ne,he)}),e.jsx(zl,{title:"决策模型 (planner)",description:"负责决定麦麦该什么时候回复",taskConfig:p.planner,modelNames:h,onChange:(ne,he)=>we("planner",ne,he)}),e.jsx(zl,{title:"图像识别模型 (vlm)",description:"视觉语言模型",taskConfig:p.vlm,modelNames:h,onChange:(ne,he)=>we("vlm",ne,he),hideTemperature:!0}),e.jsx(zl,{title:"语音识别模型 (voice)",description:"语音转文字",taskConfig:p.voice,modelNames:h,onChange:(ne,he)=>we("voice",ne,he),hideTemperature:!0,hideMaxTokens:!0}),e.jsx(zl,{title:"嵌入模型 (embedding)",description:"用于向量化",taskConfig:p.embedding,modelNames:h,onChange:(ne,he)=>we("embedding",ne,he),hideTemperature:!0,hideMaxTokens:!0}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"LPMM 知识库模型"}),e.jsx(zl,{title:"实体提取模型 (lpmm_entity_extract)",description:"从文本中提取实体",taskConfig:p.lpmm_entity_extract,modelNames:h,onChange:(ne,he)=>we("lpmm_entity_extract",ne,he)}),e.jsx(zl,{title:"RDF 构建模型 (lpmm_rdf_build)",description:"构建知识图谱",taskConfig:p.lpmm_rdf_build,modelNames:h,onChange:(ne,he)=>we("lpmm_rdf_build",ne,he)})]})]})]})]}),e.jsx(Ps,{open:B,onOpenChange:Et,children:e.jsxs(Ds,{className:"max-w-[95vw] sm:max-w-2xl max-h-[90vh] overflow-y-auto","data-tour":"model-dialog",preventOutsideClose:Ja,children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:F!==null?"编辑模型":"添加模型"}),e.jsx(Ks,{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(T,{htmlFor:"model_name",className:Ee.name?"text-destructive":"",children:"模型名称 *"}),e.jsx(ae,{id:"model_name",value:C?.name||"",onChange:ne=>{A(he=>he?{...he,name:ne.target.value}:null),Ee.name&&me(he=>({...he,name:void 0}))},placeholder:"例如: qwen3-30b",className:Ee.name?"border-destructive focus-visible:ring-destructive":""}),Ee.name?e.jsx("p",{className:"text-xs text-destructive",children:Ee.name}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于在任务配置中引用此模型"})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-provider-select",children:[e.jsx(T,{htmlFor:"api_provider",className:Ee.api_provider?"text-destructive":"",children:"API 提供商 *"}),e.jsxs(Pe,{value:C?.api_provider||"",onValueChange:ne=>{A(he=>he?{...he,api_provider:ne}:null),bs(),Ee.api_provider&&me(he=>({...he,api_provider:void 0}))},children:[e.jsx($e,{id:"api_provider",className:Ee.api_provider?"border-destructive focus-visible:ring-destructive":"",children:e.jsx(Ie,{placeholder:"选择提供商"})}),e.jsx(Be,{children:r.map(ne=>e.jsx(Z,{value:ne,children:ne},ne))})]}),Ee.api_provider&&e.jsx("p",{className:"text-xs text-destructive",children:Ee.api_provider})]}),e.jsxs("div",{className:"grid gap-2","data-tour":"model-identifier-input",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{htmlFor:"model_identifier",className:Ee.model_identifier?"text-destructive":"",children:"模型标识符 *"}),Cs?.modelFetcher&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{variant:"secondary",className:"text-xs",children:Cs.display_name}),e.jsx(_,{variant:"ghost",size:"sm",className:"h-6 px-2",onClick:()=>C?.api_provider&&ze(C.api_provider,!0),disabled:Us,children:Us?e.jsx(zs,{className:"h-3 w-3 animate-spin"}):e.jsx(dt,{className:"h-3 w-3"})})]})]}),Cs?.modelFetcher?e.jsxs(ul,{open:G,onOpenChange:de,children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",role:"combobox","aria-expanded":G,className:"w-full justify-between font-normal",disabled:Us||!!as,children:[Us?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(zs,{className:"h-4 w-4 animate-spin"}),"正在获取模型列表..."]}):as?e.jsx("span",{className:"text-muted-foreground text-sm",children:"点击下方输入框手动填写"}):C?.model_identifier?e.jsx("span",{className:"truncate",children:C.model_identifier}):e.jsx("span",{className:"text-muted-foreground",children:"搜索或选择模型..."}),e.jsx(rx,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(sl,{className:"p-0",align:"start",style:{width:"var(--radix-popover-trigger-width)"},children:e.jsxs(dd,{children:[e.jsx(ud,{placeholder:"搜索模型..."}),e.jsx(Je,{className:"h-[300px]",children:e.jsxs(md,{className:"max-h-none overflow-visible",children:[e.jsx(xd,{children:as?e.jsxs("div",{className:"py-4 px-2 text-center space-y-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:as}),!as.includes("API Key")&&e.jsx(_,{variant:"link",size:"sm",onClick:()=>C?.api_provider&&ze(C.api_provider,!0),children:"重试"})]}):"未找到匹配的模型"}),e.jsx(oc,{heading:"可用模型",children:es.map(ne=>e.jsxs(dc,{value:ne.id,onSelect:()=>{A(he=>he?{...he,model_identifier:ne.id}:null),de(!1)},children:[e.jsx(Ct,{className:`mr-2 h-4 w-4 ${C?.model_identifier===ne.id?"opacity-100":"opacity-0"}`}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:ne.id}),ne.name!==ne.id&&e.jsx("span",{className:"text-xs text-muted-foreground",children:ne.name})]})]},ne.id))}),e.jsx(oc,{heading:"手动输入",children:e.jsxs(dc,{value:"__manual_input__",onSelect:()=>{de(!1)},children:[e.jsx(Kn,{className:"mr-2 h-4 w-4"}),"手动输入模型标识符..."]})})]})})]})})]}):e.jsx(ae,{id:"model_identifier",value:C?.model_identifier||"",onChange:ne=>{A(he=>he?{...he,model_identifier:ne.target.value}:null),Ee.model_identifier&&me(he=>({...he,model_identifier:void 0}))},placeholder:"Qwen/Qwen3-30B-A3B-Instruct-2507",className:Ee.model_identifier?"border-destructive focus-visible:ring-destructive":""}),Ee.model_identifier&&e.jsx("p",{className:"text-xs text-destructive",children:Ee.model_identifier}),as&&Cs?.modelFetcher&&!Ee.model_identifier&&e.jsxs(at,{variant:"destructive",className:"mt-2 py-2",children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(lt,{className:"text-xs",children:as})]}),Cs?.modelFetcher&&e.jsx(ae,{value:C?.model_identifier||"",onChange:ne=>{A(he=>he?{...he,model_identifier:ne.target.value}:null),Ee.model_identifier&&me(he=>({...he,model_identifier:void 0}))},placeholder:"或手动输入模型标识符",className:`mt-2 ${Ee.model_identifier?"border-destructive focus-visible:ring-destructive":""}`}),!Ee.model_identifier&&e.jsx("p",{className:"text-xs text-muted-foreground",children:as?'请手动输入模型标识符,或前往"模型提供商配置"检查 API Key':Cs?.modelFetcher?`已识别为 ${Cs.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(T,{htmlFor:"price_in",children:"输入价格 (¥/M token)"}),e.jsx(ae,{id:"price_in",type:"number",step:"0.1",min:"0",value:C?.price_in??"",onChange:ne=>{const he=ne.target.value===""?null:parseFloat(ne.target.value);A(ts=>ts?{...ts,price_in:he}:null)},placeholder:"默认: 0"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"price_out",children:"输出价格 (¥/M token)"}),e.jsx(ae,{id:"price_out",type:"number",step:"0.1",min:"0",value:C?.price_out??"",onChange:ne=>{const he=ne.target.value===""?null:parseFloat(ne.target.value);A(ts=>ts?{...ts,price_out:he}: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(T,{htmlFor:"enable_model_temperature",className:"cursor-pointer",children:"自定义模型温度"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务温度配置"})]}),e.jsx(Ve,{id:"enable_model_temperature",checked:C?.temperature!=null,onCheckedChange:ne=>{A(ne?he=>he?{...he,temperature:.5}:null:he=>he?{...he,temperature:null}:null)}})]}),C?.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(T,{className:"text-sm",children:"温度值"}),e.jsx("span",{className:"text-sm font-medium tabular-nums",children:C.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(Qa,{value:[C.temperature],onValueChange:ne=>A(he=>he?{...he,temperature:ne[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(T,{htmlFor:"enable_model_max_tokens",className:"cursor-pointer",children:"自定义最大 Token"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"启用后将覆盖「为模型分配功能」中的任务最大 Token 配置"})]}),e.jsx(Ve,{id:"enable_model_max_tokens",checked:C?.max_tokens!=null,onCheckedChange:ne=>{A(ne?he=>he?{...he,max_tokens:2048}:null:he=>he?{...he,max_tokens:null}:null)}})]}),C?.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(T,{className:"text-sm",children:"最大 Token 数"}),e.jsx(ae,{type:"number",min:"1",max:"128000",value:C.max_tokens,onChange:ne=>{const he=parseInt(ne.target.value);!isNaN(he)&&he>=1&&A(ts=>ts?{...ts,max_tokens:he}: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(Ve,{id:"force_stream_mode",checked:C?.force_stream_mode||!1,onCheckedChange:ne=>A(he=>he?{...he,force_stream_mode:ne}:null)}),e.jsx(T,{htmlFor:"force_stream_mode",className:"cursor-pointer",children:"强制流式输出模式"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"额外参数"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(_,{type:"button",variant:"outline",size:"sm",className:"flex-1 justify-start h-9",onClick:()=>U(!0),children:[e.jsx(vn,{className:"h-4 w-4 mr-2"}),Object.keys(C?.extra_params||{}).length>0?e.jsxs("span",{children:["已配置 ",Object.keys(C?.extra_params||{}).length," 个参数"]}):e.jsx("span",{className:"text-muted-foreground",children:"未配置额外参数"})]})}),Object.keys(C?.extra_params||{}).length>0&&e.jsxs("div",{className:"text-xs text-muted-foreground px-1",children:[Object.keys(C?.extra_params||{}).slice(0,3).map(ne=>e.jsx("span",{className:"inline-block mr-2",children:e.jsx("code",{className:"px-1.5 py-0.5 bg-muted rounded",children:ne})},ne)),Object.keys(C?.extra_params||{}).length>3&&e.jsx("span",{children:"..."})]})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>E(!1),"data-tour":"model-cancel-button",children:"取消"}),e.jsx(_,{onClick:Ms,"data-tour":"model-save-button",children:"保存"})]})]})}),e.jsx(Ns,{open:oe,onOpenChange:Ne,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除模型 "',je!==null?a[je]?.name:"",'" 吗? 此操作无法撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:Oa,children:"删除"})]})]})}),e.jsx(Ns,{open:P,onOpenChange:ue,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["确定要删除选中的 ",M.size," 个模型吗? 此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:se,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})}),e.jsx(Ns,{open:Re,onOpenChange:W,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsxs(hs,{className:"flex items-center gap-2",children:[e.jsx(Jt,{className:"h-5 w-5 text-amber-500"}),"更换嵌入模型警告"]}),e.jsx(fs,{asChild:!0,children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"注意:"}),"更换嵌入模型可能会影响知识库的匹配精度!"]}),e.jsxs("ul",{className:"space-y-2 ml-4 list-disc text-muted-foreground",children:[e.jsx("li",{children:"不同的嵌入模型会产生不同的向量表示"}),e.jsx("li",{children:"这可能导致现有知识库的检索结果不准确"}),e.jsx("li",{children:"建议更换嵌入模型后重新生成所有知识库的向量"})]}),e.jsx("p",{className:"text-foreground font-medium",children:"确定要更换嵌入模型吗?"})]})})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:Fs,children:"取消"}),e.jsx(ps,{onClick:Le,className:"bg-amber-600 hover:bg-amber-700",children:"确认更换"})]})]})}),e.jsx(BS,{open:J,onOpenChange:U,value:C?.extra_params||{},onChange:ne=>A(he=>he?{...he,extra_params:ne}:null)}),e.jsx(er,{})]})})}const uc=wj,mc=ww,xc=_w,hd="/api/webui/config";async function c4(){const n=await(await _e(`${hd}/adapter-config/path`)).json();return!n.success||!n.path?null:{path:n.path,lastModified:n.lastModified}}async function Hg(a){const r=await(await _e(`${hd}/adapter-config/path`,{method:"POST",headers:Hs(),body:JSON.stringify({path:a})})).json();if(!r.success)throw new Error(r.message||"保存路径失败")}async function Vg(a){const r=await(await _e(`${hd}/adapter-config?path=${encodeURIComponent(a)}`)).json();if(!r.success)throw new Error("读取配置文件失败");return r.content}async function Gg(a,n){const c=await(await _e(`${hd}/adapter-config`,{method:"POST",headers:Hs(),body:JSON.stringify({path:a,content:n})})).json();if(!c.success)throw new Error(c.message||"保存配置失败")}const bt={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"}},Bm={oneclick:{name:"一键包",description:"使用一键包部署的适配器配置",path:"../MaiBot-Napcat-Adapter/config.toml",icon:ra},docker:{name:"Docker",description:"Docker Compose 部署的适配器配置",path:"/MaiMBot/adapters-config/config.toml",icon:M_}};function o4(a,n){let r=a.slice(0,n).split(/\r\n|\n|\r/g);return[r.length,r.pop().length+1]}function d4(a,n,r){let c=a.split(/\r\n|\n|\r/g),d="",u=(Math.log10(n+1)|0)+1;for(let h=n-1;h<=n+1;h++){let f=c[h-1];f&&(d+=h.toString().padEnd(u," "),d+=": ",d+=f,d+=` -`,h===n&&(d+=" ".repeat(u+r+2),d+=`^ -`))}return d}class ks extends Error{line;column;codeblock;constructor(n,r){const[c,d]=o4(r.toml,r.ptr),u=d4(r.toml,c,d);super(`Invalid TOML document: ${n} - -${u}`,r),this.line=c,this.column=d,this.codeblock=u}}function u4(a,n){let r=0;for(;a[n-++r]==="\\";);return--r&&r%2}function Yo(a,n=0,r=a.length){let c=a.indexOf(` -`,n);return a[c-1]==="\r"&&c--,c<=r?c:-1}function gx(a,n){for(let r=n;r-1&&r!=="'"&&u4(a,n));return n>-1&&(n+=c.length,c.length>1&&(a[n]===r&&n++,a[n]===r&&n++)),n}let m4=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}:\d{2}(?:\.\d+)?)?(Z|[-+]\d{2}:\d{2})?$/i;class Kr extends Date{#s=!1;#t=!1;#e=null;constructor(n){let r=!0,c=!0,d="Z";if(typeof n=="string"){let u=n.match(m4);u?(u[1]||(r=!1,n=`0000-01-01T${n}`),c=!!u[2],c&&n[10]===" "&&(n=n.replace(" ","T")),u[2]&&+u[2]>23?n="":(d=u[3]||null,n=n.toUpperCase(),!d&&c&&(n+="Z"))):n=""}super(n),isNaN(this.getTime())||(this.#s=r,this.#t=c,this.#e=d)}isDateTime(){return this.#s&&this.#t}isLocal(){return!this.#s||!this.#t||!this.#e}isDate(){return this.#s&&!this.#t}isTime(){return this.#t&&!this.#s}isValid(){return this.#s||this.#t}toISOString(){let n=super.toISOString();if(this.isDate())return n.slice(0,10);if(this.isTime())return n.slice(11,23);if(this.#e===null)return n.slice(0,-1);if(this.#e==="Z")return n;let r=+this.#e.slice(1,3)*60+ +this.#e.slice(4,6);return r=this.#e[0]==="-"?r:-r,new Date(this.getTime()-r*6e4).toISOString().slice(0,-1)+this.#e}static wrapAsOffsetDateTime(n,r="Z"){let c=new Kr(n);return c.#e=r,c}static wrapAsLocalDateTime(n){let r=new Kr(n);return r.#e=null,r}static wrapAsLocalDate(n){let r=new Kr(n);return r.#t=!1,r.#e=null,r}static wrapAsLocalTime(n){let r=new Kr(n);return r.#s=!1,r.#e=null,r}}let x4=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,h4=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,f4=/^[+-]?0[0-9_]/,p4=/^[0-9a-f]{4,8}$/i,Kg={b:"\b",t:" ",n:` -`,f:"\f",r:"\r",'"':'"',"\\":"\\"};function Xv(a,n=0,r=a.length){let c=a[n]==="'",d=a[n++]===a[n]&&a[n]===a[n+1];d&&(r-=2,a[n+=2]==="\r"&&n++,a[n]===` -`&&n++);let u=0,h,f="",p=n;for(;n-1&&(gx(a,u),d=d.slice(0,u));let h=d.trimEnd();if(!c){let f=d.indexOf(` -`,h.length);if(f>-1)throw new ks("newlines are not allowed in inline tables",{toml:a,ptr:n+f})}return[h,u]}function jx(a,n,r,c,d){if(c===0)throw new ks("document contains excessively nested structures. aborting.",{toml:a,ptr:n});let u=a[n];if(u==="["||u==="{"){let[p,g]=u==="["?b4(a,n,c,d):N4(a,n,c,d),N=r?qg(a,g,",",r):g;if(g-N&&r==="}"){let v=Yo(a,g,N);if(v>-1)throw new ks("newlines are not allowed in inline tables",{toml:a,ptr:v})}return[p,N]}let h;if(u==='"'||u==="'"){h=Jv(a,n);let p=Xv(a,n,h);if(r){if(h=Ol(a,h,r!=="]"),a[h]&&a[h]!==","&&a[h]!==r&&a[h]!==` -`&&a[h]!=="\r")throw new ks("unexpected character encountered",{toml:a,ptr:h});h+=+(a[h]===",")}return[p,h]}h=qg(a,n,",",r);let f=j4(a,n,h-+(a[h-1]===","),r==="]");if(!f[0])throw new ks("incomplete key-value declaration: no value specified",{toml:a,ptr:n});return r&&f[1]>-1&&(h=Ol(a,n+f[1]),h+=+(a[h]===",")),[g4(f[0],a,n,d),h]}let v4=/^[a-zA-Z0-9-_]+[ \t]*$/;function Zm(a,n,r="="){let c=n-1,d=[],u=a.indexOf(r,n);if(u<0)throw new ks("incomplete key-value: cannot find end of key",{toml:a,ptr:n});do{let h=a[n=++c];if(h!==" "&&h!==" ")if(h==='"'||h==="'"){if(h===a[n+1]&&h===a[n+2])throw new ks("multiline strings are not allowed in keys",{toml:a,ptr:n});let f=Jv(a,n);if(f<0)throw new ks("unfinished string encountered",{toml:a,ptr:n});c=a.indexOf(".",f);let p=a.slice(f,c<0||c>u?u:c),g=Yo(p);if(g>-1)throw new ks("newlines are not allowed in keys",{toml:a,ptr:n+c+g});if(p.trimStart())throw new ks("found extra tokens after the string part",{toml:a,ptr:f});if(uu?u:c);if(!v4.test(f))throw new ks("only letter, numbers, dashes and underscores are allowed in keys",{toml:a,ptr:n});d.push(f.trimEnd())}}while(c+1&&cd===""||d===null||d===void 0?u:d,r={inner:{version:n(a.inner.version,bt.inner.version)},nickname:{nickname:n(a.nickname.nickname,bt.nickname.nickname)},napcat_server:{host:n(a.napcat_server.host,bt.napcat_server.host),port:n(a.napcat_server.port||0,bt.napcat_server.port),token:n(a.napcat_server.token,bt.napcat_server.token),heartbeat_interval:n(a.napcat_server.heartbeat_interval||0,bt.napcat_server.heartbeat_interval)},maibot_server:{host:n(a.maibot_server.host,bt.maibot_server.host),port:n(a.maibot_server.port||0,bt.maibot_server.port)},chat:{group_list_type:n(a.chat.group_list_type,bt.chat.group_list_type),group_list:a.chat.group_list||[],private_list_type:n(a.chat.private_list_type,bt.chat.private_list_type),private_list:a.chat.private_list||[],ban_user_id:a.chat.ban_user_id||[],ban_qq_bot:a.chat.ban_qq_bot??bt.chat.ban_qq_bot,enable_poke:a.chat.enable_poke??bt.chat.enable_poke},voice:{use_tts:a.voice.use_tts??bt.voice.use_tts},debug:{level:n(a.debug.level,bt.debug.level)}};let c=k4(r);return c=C4(c),c}catch(n){throw console.error("TOML 生成失败:",n),new Error(`无法生成 TOML 文件: ${n instanceof Error?n.message:"未知错误"}`)}}function C4(a){const n=a.split(` -`),r=[];for(let c=0;c"|?*\x00-\x1F]/.test(a)?{valid:!1,error:"路径包含非法字符"}:{valid:!0,error:""}}function T4(){const[a,n]=m.useState("upload"),[r,c]=m.useState(null),[d,u]=m.useState(""),[h,f]=m.useState(""),[p,g]=m.useState("oneclick"),[N,v]=m.useState(""),[w,b]=m.useState(!1),[y,O]=m.useState(!1),[R,S]=m.useState(!1),[B,E]=m.useState(!1),[C,A]=m.useState(null),[F,L]=m.useState(!1),J=m.useRef(null),{toast:U}=Ys(),oe=m.useRef(null),Ne=G=>{if(f(G),G.trim()){const de=Fm(G);v(de.error)}else v("")},je=m.useCallback(async G=>{const de=Bm[G];O(!0);try{const Re=await Vg(de.path),W=Pm(Re);c(W),g(G),f(de.path),await Hg(de.path),U({title:"加载成功",description:`已从${de.name}预设加载配置`})}catch(Re){console.error("加载预设配置失败:",Re),U({title:"加载失败",description:Re instanceof Error?Re.message:"无法读取预设配置文件",variant:"destructive"})}finally{O(!1)}},[U]),re=m.useCallback(async G=>{const de=Fm(G);if(!de.valid){v(de.error),U({title:"路径无效",description:de.error,variant:"destructive"});return}v(""),O(!0);try{const Re=await Vg(G),W=Pm(Re);c(W),f(G),await Hg(G),U({title:"加载成功",description:"已从配置文件加载"})}catch(Re){console.error("加载配置失败:",Re),U({title:"加载失败",description:Re instanceof Error?Re.message:"无法读取配置文件",variant:"destructive"})}finally{O(!1)}},[U]);m.useEffect(()=>{(async()=>{try{const de=await c4();if(de&&de.path){f(de.path);const Re=Object.entries(Bm).find(([,W])=>W.path===de.path);Re?(n("preset"),g(Re[0]),await je(Re[0])):(n("path"),await re(de.path))}}catch(de){console.error("加载保存的路径失败:",de)}})()},[re,je]);const fe=m.useCallback(G=>{a!=="path"&&a!=="preset"||!h||(oe.current&&clearTimeout(oe.current),oe.current=setTimeout(async()=>{b(!0);try{const de=Im(G);await Gg(h,de),U({title:"自动保存成功",description:"配置已保存到文件"})}catch(de){console.error("自动保存失败:",de),U({title:"自动保存失败",description:de instanceof Error?de.message:"保存配置失败",variant:"destructive"})}finally{b(!1)}},1e3))},[a,h,U]),ge=async()=>{if(!r||!h)return;const G=Fm(h);if(!G.valid){U({title:"保存失败",description:G.error,variant:"destructive"});return}b(!0);try{const de=Im(r);await Gg(h,de),U({title:"保存成功",description:"配置已保存到文件"})}catch(de){console.error("保存失败:",de),U({title:"保存失败",description:de instanceof Error?de.message:"保存配置失败",variant:"destructive"})}finally{b(!1)}},M=async()=>{h&&await re(h)},K=G=>{if(G!==a){if(r){A(G),S(!0);return}P(G)}},P=G=>{c(null),u(""),v(""),n(G),G==="preset"&&je("oneclick"),U({title:"已切换模式",description:{upload:"现在可以上传配置文件",path:"现在可以指定配置文件路径",preset:"现在可以使用预设配置"}[G]})},ue=()=>{C&&(P(C),A(null)),S(!1)},Q=()=>{if(r){E(!0);return}Se()},Se=()=>{f(""),c(null),v(""),U({title:"已清空",description:"路径和配置已清空"})},pe=()=>{Se(),E(!1)},Te=G=>{const de=G.target.files?.[0];if(!de)return;const Re=new FileReader;Re.onload=W=>{try{const Y=W.target?.result,Fe=Pm(Y);c(Fe),u(de.name),U({title:"上传成功",description:`已加载配置文件:${de.name}`})}catch(Y){console.error("解析配置文件失败:",Y),U({title:"解析失败",description:"配置文件格式错误,请检查文件内容",variant:"destructive"})}},Re.readAsText(de)},z=()=>{if(!r)return;const G=Im(r),de=new Blob([G],{type:"text/plain;charset=utf-8"}),Re=URL.createObjectURL(de),W=document.createElement("a");W.href=Re,W.download=d||"config.toml",document.body.appendChild(W),W.click(),document.body.removeChild(W),URL.revokeObjectURL(Re),U({title:"下载成功",description:"配置文件已下载,请手动覆盖并重启适配器"})},D=()=>{c(JSON.parse(JSON.stringify(bt))),u("config.toml"),U({title:"已加载默认配置",description:"可以开始编辑配置"})};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"麦麦适配器配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理麦麦的 QQ 适配器的配置文件"})]})}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg border border-amber-500/50 bg-amber-500/10 text-amber-700 dark:text-amber-400",children:[e.jsx(_t,{className:"h-4 w-4 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-sm",children:"适配器配置保存之后使用 WebUI 的重启功能适配器并不会重启,需要手动重启适配器。"})]}),e.jsx(uc,{open:F,onOpenChange:L,children:e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Oe,{children:"工作模式"}),e.jsx(os,{children:"选择配置文件的管理方式"})]}),e.jsx(mc,{asChild:!0,children:e.jsxs(_,{variant:"ghost",size:"sm",className:"w-9 p-0",children:[e.jsx(za,{className:`h-4 w-4 transition-transform duration-200 ${F?"transform rotate-180":""}`}),e.jsx("span",{className:"sr-only",children:"切换"})]})})]})}),e.jsx(xc,{children:e.jsxs(Me,{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 ${a==="preset"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>K("preset"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(ra,{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 ${a==="upload"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>K("upload"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(rc,{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 ${a==="path"?"border-primary bg-primary/5":"border-muted hover:border-primary/50 active:border-primary/70"}`,onClick:()=>K("path"),children:e.jsxs("div",{className:"flex items-start gap-2 md:gap-3",children:[e.jsx(A_,{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:"指定配置文件路径,自动加载和保存"})]})]})})]}),a==="preset"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsx(T,{className:"text-sm md:text-base",children:"选择部署方式"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(Bm).map(([G,de])=>{const Re=de.icon,W=p===G;return e.jsx("div",{className:`border-2 rounded-lg p-3 cursor-pointer transition-all ${W?"border-primary bg-primary/5":"border-muted hover:border-primary/50"}`,onClick:()=>{g(G),je(G)},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Re,{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:de.name}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:de.description}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-mono break-all",children:de.path})]})]})},G)})})]}),a==="path"&&e.jsxs("div",{className:"space-y-3 pt-2 border-t",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{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(ae,{id:"config-path",value:h,onChange:G=>Ne(G.target.value),placeholder:"例: C:\\Adapter\\config.toml",className:`text-sm ${N?"border-destructive":""}`}),N&&e.jsx("p",{className:"text-xs text-destructive",children:N})]}),e.jsx(_,{onClick:()=>re(h),disabled:y||!h||!!N,className:"w-full sm:w-auto",children:y?e.jsxs(e.Fragment,{children:[e.jsx(dt,{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(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(lt,{children:a==="preset"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"预设模式:"}),"选择预设的部署方式,配置会自动加载,修改后 1 秒自动保存",w&&" (正在保存...)"]}):a==="upload"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"上传文件模式:"}),"上传配置文件 → 在线编辑 → 下载文件 → 手动覆盖并重启适配器"]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"指定路径模式:"}),"指定配置文件路径后,配置会自动加载,修改后 1 秒自动保存",w&&" (正在保存...)"]})})]}),a==="upload"&&!r&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 w-full",children:[e.jsx("input",{ref:J,type:"file",accept:".toml",className:"hidden",onChange:Te}),e.jsxs(_,{onClick:()=>J.current?.click(),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(rc,{className:"mr-2 h-4 w-4"}),"上传配置"]}),e.jsxs(_,{onClick:D,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Ea,{className:"mr-2 h-4 w-4"}),"使用默认配置"]})]}),a==="upload"&&r&&e.jsx("div",{className:"flex gap-2",children:e.jsxs(_,{onClick:z,size:"sm",className:"w-full sm:w-auto",children:[e.jsx(Xt,{className:"mr-2 h-4 w-4"}),"下载配置"]})}),(a==="preset"||a==="path")&&r&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs(_,{onClick:ge,size:"sm",disabled:w||!!N,className:"w-full sm:w-auto",children:[e.jsx(fc,{className:"mr-2 h-4 w-4"}),w?"保存中...":"立即保存"]}),e.jsxs(_,{onClick:M,size:"sm",variant:"outline",disabled:y,className:"w-full sm:w-auto",children:[e.jsx(dt,{className:`mr-2 h-4 w-4 ${y?"animate-spin":""}`}),"刷新"]}),a==="path"&&e.jsxs(_,{onClick:Q,size:"sm",variant:"destructive",className:"w-full sm:w-auto",children:[e.jsx(ns,{className:"mr-2 h-4 w-4"}),"清空路径"]})]}),r?e.jsxs(ta,{defaultValue:"napcat",className:"w-full",children:[e.jsx("div",{className:"overflow-x-auto -mx-4 px-4 sm:mx-0 sm:px-0",children:e.jsxs(Zt,{className:"inline-flex w-auto min-w-full sm:grid sm:w-full sm:grid-cols-5",children:[e.jsxs(Xe,{value:"napcat",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"Napcat 连接"}),e.jsx("span",{className:"sm:hidden",children:"Napcat"})]}),e.jsxs(Xe,{value:"maibot",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"麦麦连接"}),e.jsx("span",{className:"sm:hidden",children:"麦麦"})]}),e.jsxs(Xe,{value:"chat",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"聊天控制"}),e.jsx("span",{className:"sm:hidden",children:"聊天"})]}),e.jsxs(Xe,{value:"voice",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:[e.jsx("span",{className:"hidden sm:inline",children:"语音设置"}),e.jsx("span",{className:"sm:hidden",children:"语音"})]}),e.jsx(Xe,{value:"debug",className:"flex-shrink-0 text-xs sm:text-sm whitespace-nowrap",children:"调试"})]})}),e.jsx(ws,{value:"napcat",className:"space-y-4",children:e.jsx(E4,{config:r,onChange:G=>{c(G),fe(G)}})}),e.jsx(ws,{value:"maibot",className:"space-y-4",children:e.jsx(M4,{config:r,onChange:G=>{c(G),fe(G)}})}),e.jsx(ws,{value:"chat",className:"space-y-4",children:e.jsx(A4,{config:r,onChange:G=>{c(G),fe(G)}})}),e.jsx(ws,{value:"voice",className:"space-y-4",children:e.jsx(z4,{config:r,onChange:G=>{c(G),fe(G)}})}),e.jsx(ws,{value:"debug",className:"space-y-4",children:e.jsx(R4,{config:r,onChange:G=>{c(G),fe(G)}})})]}):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(Ea,{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:a==="preset"?"请选择预设的部署方式":a==="upload"?"请上传现有配置文件,或使用默认配置开始编辑":"请指定配置文件路径并点击加载按钮"})]})]})}),e.jsx(Ns,{open:R,onOpenChange:S,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认切换模式"}),e.jsxs(fs,{children:["切换模式将清空当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-destructive font-medium",children:"请确保已保存重要配置"})]})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:()=>{S(!1),A(null)},children:"取消"}),e.jsx(ps,{onClick:ue,children:"确认切换"})]})]})}),e.jsx(Ns,{open:B,onOpenChange:E,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认清空路径"}),e.jsxs(fs,{children:["清空路径将清除当前配置,确定要继续吗?",e.jsx("br",{}),e.jsx("span",{className:"text-muted-foreground text-sm",children:"此操作不会删除配置文件,只是清除界面中的配置"})]})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:()=>E(!1),children:"取消"}),e.jsx(ps,{onClick:pe,className:"bg-destructive hover:bg-destructive/90",children:"确认清空"})]})]})})]})})}function E4({config:a,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"Napcat WebSocket 服务设置"}),e.jsxs("div",{className:"grid gap-3 md:gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(ae,{id:"napcat-host",value:a.napcat_server.host,onChange:r=>n({...a,napcat_server:{...a.napcat_server,host:r.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的主机地址"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(ae,{id:"napcat-port",type:"number",value:a.napcat_server.port||"",onChange:r=>n({...a,napcat_server:{...a.napcat_server,port:r.target.value?parseInt(r.target.value):0}}),placeholder:"8095",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的端口(留空使用默认值 8095)"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-token",className:"text-sm md:text-base",children:"访问令牌(Token)"}),e.jsx(ae,{id:"napcat-token",type:"password",value:a.napcat_server.token,onChange:r=>n({...a,napcat_server:{...a.napcat_server,token:r.target.value}}),placeholder:"留空表示无需令牌",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Napcat 设定的访问令牌,若无则留空"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"napcat-heartbeat",className:"text-sm md:text-base",children:"心跳间隔(秒)"}),e.jsx(ae,{id:"napcat-heartbeat",type:"number",value:a.napcat_server.heartbeat_interval||"",onChange:r=>n({...a,napcat_server:{...a.napcat_server,heartbeat_interval:r.target.value?parseInt(r.target.value):0}}),placeholder:"30",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"与 Napcat 设置的心跳间隔保持一致(留空使用默认值 30)"})]})]})]})})}function M4({config:a,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"麦麦 WebSocket 服务设置"}),e.jsxs("div",{className:"grid gap-3 md:gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"maibot-host",className:"text-sm md:text-base",children:"主机地址"}),e.jsx(ae,{id:"maibot-host",value:a.maibot_server.host,onChange:r=>n({...a,maibot_server:{...a.maibot_server,host:r.target.value}}),placeholder:"localhost",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 HOST 字段"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{htmlFor:"maibot-port",className:"text-sm md:text-base",children:"端口"}),e.jsx(ae,{id:"maibot-port",type:"number",value:a.maibot_server.port||"",onChange:r=>n({...a,maibot_server:{...a.maibot_server,port:r.target.value?parseInt(r.target.value):0}}),placeholder:"8000",className:"text-sm md:text-base"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦在 .env 文件中设置的 PORT 字段(留空使用默认值 8000)"})]})]})]})})}function A4({config:a,onChange:n}){const r=u=>{const h={...a};u==="group"?h.chat.group_list=[...h.chat.group_list,0]:u==="private"?h.chat.private_list=[...h.chat.private_list,0]:h.chat.ban_user_id=[...h.chat.ban_user_id,0],n(h)},c=(u,h)=>{const f={...a};u==="group"?f.chat.group_list=f.chat.group_list.filter((p,g)=>g!==h):u==="private"?f.chat.private_list=f.chat.private_list.filter((p,g)=>g!==h):f.chat.ban_user_id=f.chat.ban_user_id.filter((p,g)=>g!==h),n(f)},d=(u,h,f)=>{const p={...a};u==="group"?p.chat.group_list[h]=f:u==="private"?p.chat.private_list[h]=f:p.chat.ban_user_id[h]=f,n(p)};return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"聊天黑白名单功能"}),e.jsxs("div",{className:"grid gap-4 md:gap-6",children:[e.jsxs("div",{className:"space-y-3 md:space-y-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-sm md:text-base",children:"群组名单类型"}),e.jsxs(Pe,{value:a.chat.group_list_type,onValueChange:u=>n({...a,chat:{...a.chat,group_list_type:u}}),children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(Z,{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(T,{className:"text-sm md:text-base",children:"群组列表"}),e.jsxs(_,{onClick:()=>r("group"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ea,{className:"mr-1 h-4 w-4"}),"添加群号"]})]}),a.chat.group_list.map((u,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{type:"number",value:u,onChange:f=>d("group",h,parseInt(f.target.value)||0),placeholder:"输入群号",className:"text-sm md:text-base"}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除群号 ",u," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>c("group",h),children:"删除"})]})]})]})]},h)),a.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(T,{className:"text-sm md:text-base",children:"私聊名单类型"}),e.jsxs(Pe,{value:a.chat.private_list_type,onValueChange:u=>n({...a,chat:{...a.chat,private_list_type:u}}),children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"whitelist",children:"白名单(仅名单内可聊天)"}),e.jsx(Z,{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(T,{className:"text-sm md:text-base",children:"私聊列表"}),e.jsxs(_,{onClick:()=>r("private"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ea,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),a.chat.private_list.map((u,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{type:"number",value:u,onChange:f=>d("private",h,parseInt(f.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要删除用户 ",u," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>c("private",h),children:"删除"})]})]})]})]},h)),a.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(T,{className:"text-sm md:text-base",children:"全局禁止名单"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"名单中的用户无法进行任何聊天"})]}),e.jsxs(_,{onClick:()=>r("ban"),size:"sm",variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Ea,{className:"mr-1 h-4 w-4"}),"添加用户"]})]}),a.chat.ban_user_id.map((u,h)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ae,{type:"number",value:u,onChange:f=>d("ban",h,parseInt(f.target.value)||0),placeholder:"输入QQ号",className:"text-sm md:text-base"}),e.jsxs(Ns,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(_,{size:"icon",variant:"outline",children:e.jsx(ns,{className:"h-4 w-4"})})}),e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:["确定要从全局禁止名单中删除用户 ",u," 吗?此操作无法撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>c("ban",h),children:"删除"})]})]})]})]},h)),a.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(T,{className:"text-sm md:text-base",children:"屏蔽QQ官方机器人"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否屏蔽来自QQ官方机器人的消息"})]}),e.jsx(Ve,{checked:a.chat.ban_qq_bot,onCheckedChange:u=>n({...a,chat:{...a.chat,ban_qq_bot:u}})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-sm md:text-base",children:"启用戳一戳功能"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"是否响应戳一戳消息"})]}),e.jsx(Ve,{checked:a.chat.enable_poke,onCheckedChange:u=>n({...a,chat:{...a.chat,enable_poke:u}})})]})]})]})})}function z4({config:a,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"发送语音设置"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-sm md:text-base",children:"使用 TTS 语音"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"请确保已配置 TTS 并有对应的适配器"})]}),e.jsx(Ve,{checked:a.voice.use_tts,onCheckedChange:r=>n({...a,voice:{use_tts:r}})})]})]})})}function R4({config:a,onChange:n}){return e.jsx("div",{className:"rounded-lg border bg-card p-4 md:p-6 space-y-4 md:space-y-6",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base md:text-lg font-semibold mb-3 md:mb-4",children:"调试设置"}),e.jsx("div",{className:"grid gap-3 md:gap-4",children:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T,{className:"text-sm md:text-base",children:"日志等级"}),e.jsxs(Pe,{value:a.debug.level,onValueChange:r=>n({...a,debug:{level:r}}),children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"DEBUG",children:"DEBUG(调试)"}),e.jsx(Z,{value:"INFO",children:"INFO(信息)"}),e.jsx(Z,{value:"WARNING",children:"WARNING(警告)"}),e.jsx(Z,{value:"ERROR",children:"ERROR(错误)"}),e.jsx(Z,{value:"CRITICAL",children:"CRITICAL(严重)"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"设置适配器的日志输出等级"})]})})]})})}const D4=["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"],O4=/^(aria-|data-)/,eN=a=>Object.fromEntries(Object.entries(a).filter(([n])=>O4.test(n)||D4.includes(n)));function L4(a,n){const r=eN(a);return Object.keys(a).some(c=>!Object.hasOwn(r,c)&&a[c]!==n[c])}class U4 extends m.Component{container;plugin;componentDidMount(){this.installPlugin()}componentDidUpdate(n){if(n.uppy!==this.props.uppy)this.uninstallPlugin(n),this.installPlugin();else if(L4(this.props,n)){const{uppy:r,...c}={...this.props,target:this.container};this.plugin.setOptions(c)}}componentWillUnmount(){this.uninstallPlugin()}installPlugin(){const{uppy:n,...r}={id:"Dashboard",...this.props,inline:!0,target:this.container};n.use(m1,r),this.plugin=n.getPlugin(r.id)}uninstallPlugin(n=this.props){const{uppy:r}=n;r.removePlugin(this.plugin)}render(){return m.createElement("div",{className:"uppy-Container",ref:n=>{this.container=n},...eN(this.props)})}}function $4({src:a,alt:n="表情包",className:r,maxRetries:c=5,retryInterval:d=1500}){const[u,h]=m.useState("loading"),[f,p]=m.useState(0),[g,N]=m.useState(null),[v,w]=m.useState(a);a!==v&&(h("loading"),p(0),N(null),w(a));const b=m.useCallback(async()=>{try{const y=await fetch(a,{credentials:"include"});if(y.status===202){h("generating"),f{p(S=>S+1)},d):h("error");return}if(!y.ok){h("error");return}const O=await y.blob(),R=URL.createObjectURL(O);N(R),h("loaded")}catch(y){console.error("加载缩略图失败:",y),h("error")}},[a,f,c,d]);return m.useEffect(()=>{b()},[b]),m.useEffect(()=>()=>{g&&URL.revokeObjectURL(g)},[g]),u==="loading"||u==="generating"?e.jsx(vs,{className:I("w-full h-full",r)}):u==="error"||!g?e.jsx("div",{className:I("w-full h-full flex items-center justify-center bg-muted",r),children:e.jsx(ix,{className:"h-8 w-8 text-muted-foreground"})}):e.jsx("img",{src:g,alt:n,className:I("w-full h-full object-contain",r)})}function B4({children:a,className:n}){return e.jsx(fx,{content:a,className:n})}const Ya="/api/webui/emoji";async function P4(a){const n=new URLSearchParams;a.page&&n.append("page",a.page.toString()),a.page_size&&n.append("page_size",a.page_size.toString()),a.search&&n.append("search",a.search),a.is_registered!==void 0&&n.append("is_registered",a.is_registered.toString()),a.is_banned!==void 0&&n.append("is_banned",a.is_banned.toString()),a.format&&n.append("format",a.format),a.sort_by&&n.append("sort_by",a.sort_by),a.sort_order&&n.append("sort_order",a.sort_order);const r=await _e(`${Ya}/list?${n}`,{});if(!r.ok)throw new Error(`获取表情包列表失败: ${r.statusText}`);return r.json()}async function I4(a){const n=await _e(`${Ya}/${a}`,{});if(!n.ok)throw new Error(`获取表情包详情失败: ${n.statusText}`);return n.json()}async function F4(a,n){const r=await _e(`${Ya}/${a}`,{method:"PATCH",body:JSON.stringify(n)});if(!r.ok)throw new Error(`更新表情包失败: ${r.statusText}`);return r.json()}async function H4(a){const n=await _e(`${Ya}/${a}`,{method:"DELETE"});if(!n.ok)throw new Error(`删除表情包失败: ${n.statusText}`);return n.json()}async function V4(){const a=await _e(`${Ya}/stats/summary`,{});if(!a.ok)throw new Error(`获取统计数据失败: ${a.statusText}`);return a.json()}async function G4(a){const n=await _e(`${Ya}/${a}/register`,{method:"POST"});if(!n.ok)throw new Error(`注册表情包失败: ${n.statusText}`);return n.json()}async function q4(a){const n=await _e(`${Ya}/${a}/ban`,{method:"POST"});if(!n.ok)throw new Error(`封禁表情包失败: ${n.statusText}`);return n.json()}function K4(a,n=!1){return n?`${Ya}/${a}/thumbnail?original=true`:`${Ya}/${a}/thumbnail`}function Q4(a){return`${Ya}/${a}/thumbnail?original=true`}async function Y4(a){const n=await _e(`${Ya}/batch/delete`,{method:"POST",body:JSON.stringify({emoji_ids:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"批量删除失败")}return n.json()}function J4(){return`${Ya}/upload`}function X4(){const[a,n]=m.useState([]),[r,c]=m.useState(null),[d,u]=m.useState(!1),[h,f]=m.useState(1),[p,g]=m.useState(0),[N,v]=m.useState(20),[w,b]=m.useState("all"),[y,O]=m.useState("all"),[R,S]=m.useState("all"),[B,E]=m.useState("usage_count"),[C,A]=m.useState("desc"),[F,L]=m.useState(null),[J,U]=m.useState(!1),[oe,Ne]=m.useState(!1),[je,re]=m.useState(!1),[fe,ge]=m.useState(new Set),[M,K]=m.useState(!1),[P,ue]=m.useState(""),[Q,Se]=m.useState("medium"),[pe,Te]=m.useState(!1),{toast:z}=Ys(),D=m.useCallback(async()=>{try{u(!0);const me=await P4({page:h,page_size:N,is_registered:w==="all"?void 0:w==="registered",is_banned:y==="all"?void 0:y==="banned",format:R==="all"?void 0:R,sort_by:B,sort_order:C});n(me.data),g(me.total)}catch(me){const Ae=me instanceof Error?me.message:"加载表情包列表失败";z({title:"错误",description:Ae,variant:"destructive"})}finally{u(!1)}},[h,N,w,y,R,B,C,z]),G=async()=>{try{const me=await V4();c(me.data)}catch(me){console.error("加载统计数据失败:",me)}};m.useEffect(()=>{D()},[D]),m.useEffect(()=>{G()},[]);const de=async me=>{try{const Ae=await I4(me.id);L(Ae.data),U(!0)}catch(Ae){const rs=Ae instanceof Error?Ae.message:"加载详情失败";z({title:"错误",description:rs,variant:"destructive"})}},Re=me=>{L(me),Ne(!0)},W=me=>{L(me),re(!0)},Y=async()=>{if(F)try{await H4(F.id),z({title:"成功",description:"表情包已删除"}),re(!1),L(null),D(),G()}catch(me){const Ae=me instanceof Error?me.message:"删除失败";z({title:"错误",description:Ae,variant:"destructive"})}},Fe=async me=>{try{await G4(me.id),z({title:"成功",description:"表情包已注册"}),D(),G()}catch(Ae){const rs=Ae instanceof Error?Ae.message:"注册失败";z({title:"错误",description:rs,variant:"destructive"})}},H=async me=>{try{await q4(me.id),z({title:"成功",description:"表情包已封禁"}),D(),G()}catch(Ae){const rs=Ae instanceof Error?Ae.message:"封禁失败";z({title:"错误",description:rs,variant:"destructive"})}},ee=me=>{const Ae=new Set(fe);Ae.has(me)?Ae.delete(me):Ae.add(me),ge(Ae)},Ue=async()=>{try{const me=await Y4(Array.from(fe));z({title:"批量删除完成",description:me.message}),ge(new Set),K(!1),D(),G()}catch(me){z({title:"批量删除失败",description:me instanceof Error?me.message:"批量删除失败",variant:"destructive"})}},ie=()=>{const me=parseInt(P),Ae=Math.ceil(p/N);me>=1&&me<=Ae?(f(me),ue("")):z({title:"无效的页码",description:`请输入1-${Ae}之间的页码`,variant:"destructive"})},Ee=r?.formats?Object.keys(r.formats):[];return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"表情包管理"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"管理麦麦的表情包资源"})]}),e.jsxs(_,{onClick:()=>Te(!0),className:"gap-2",children:[e.jsx(rc,{className:"h-4 w-4"}),"上传表情包"]})]}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[r&&e.jsxs("div",{className:"grid gap-4 grid-cols-2 lg:grid-cols-4",children:[e.jsx(Ce,{children:e.jsxs(De,{className:"pb-2",children:[e.jsx(os,{children:"总数"}),e.jsx(Oe,{className:"text-2xl",children:r.total})]})}),e.jsx(Ce,{children:e.jsxs(De,{className:"pb-2",children:[e.jsx(os,{children:"已注册"}),e.jsx(Oe,{className:"text-2xl text-green-600",children:r.registered})]})}),e.jsx(Ce,{children:e.jsxs(De,{className:"pb-2",children:[e.jsx(os,{children:"已封禁"}),e.jsx(Oe,{className:"text-2xl text-red-600",children:r.banned})]})}),e.jsx(Ce,{children:e.jsxs(De,{className:"pb-2",children:[e.jsx(os,{children:"未注册"}),e.jsx(Oe,{className:"text-2xl text-gray-600",children:r.unregistered})]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx(Bo,{className:"h-5 w-5"}),"筛选和排序"]})}),e.jsxs(Me,{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(T,{children:"排序方式"}),e.jsxs(Pe,{value:`${B}-${C}`,onValueChange:me=>{const[Ae,rs]=me.split("-");E(Ae),A(rs),f(1)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"usage_count-desc",children:"使用次数 (多→少)"}),e.jsx(Z,{value:"usage_count-asc",children:"使用次数 (少→多)"}),e.jsx(Z,{value:"register_time-desc",children:"注册时间 (新→旧)"}),e.jsx(Z,{value:"register_time-asc",children:"注册时间 (旧→新)"}),e.jsx(Z,{value:"record_time-desc",children:"记录时间 (新→旧)"}),e.jsx(Z,{value:"record_time-asc",children:"记录时间 (旧→新)"}),e.jsx(Z,{value:"last_used_time-desc",children:"最后使用 (新→旧)"}),e.jsx(Z,{value:"last_used_time-asc",children:"最后使用 (旧→新)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"注册状态"}),e.jsxs(Pe,{value:w,onValueChange:me=>{b(me),f(1)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部"}),e.jsx(Z,{value:"registered",children:"已注册"}),e.jsx(Z,{value:"unregistered",children:"未注册"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"封禁状态"}),e.jsxs(Pe,{value:y,onValueChange:me=>{O(me),f(1)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部"}),e.jsx(Z,{value:"banned",children:"已封禁"}),e.jsx(Z,{value:"unbanned",children:"未封禁"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"格式"}),e.jsxs(Pe,{value:R,onValueChange:me=>{S(me),f(1)},children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部"}),Ee.map(me=>e.jsxs(Z,{value:me,children:[me.toUpperCase()," (",r?.formats[me],")"]},me))]})]})]})]}),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:[fe.size>0&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["已选择 ",fe.size," 个表情包"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"text-sm whitespace-nowrap",children:"卡片大小"}),e.jsxs(Pe,{value:Q,onValueChange:me=>Se(me),children:[e.jsx($e,{className:"w-24",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"small",children:"小"}),e.jsx(Z,{value:"medium",children:"中"}),e.jsx(Z,{value:"large",children:"大"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{htmlFor:"emoji-page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Pe,{value:N.toString(),onValueChange:me=>{v(parseInt(me)),f(1),ge(new Set)},children:[e.jsx($e,{id:"emoji-page-size",className:"w-20",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"20",children:"20"}),e.jsx(Z,{value:"40",children:"40"}),e.jsx(Z,{value:"60",children:"60"}),e.jsx(Z,{value:"100",children:"100"})]})]}),fe.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>ge(new Set),children:"取消选择"}),e.jsxs(_,{variant:"destructive",size:"sm",onClick:()=>K(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsxs(_,{variant:"outline",size:"sm",onClick:D,disabled:d,children:[e.jsx(dt,{className:`h-4 w-4 mr-2 ${d?"animate-spin":""}`}),"刷新"]})})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"表情包列表"}),e.jsxs(os,{children:["共 ",p," 个表情包,当前第 ",h," 页"]})]}),e.jsxs(Me,{children:[a.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"暂无数据"}):e.jsx("div",{className:`grid gap-3 ${Q==="small"?"grid-cols-3 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10":Q==="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:a.map(me=>e.jsxs("div",{className:`group relative rounded-lg border bg-card overflow-hidden hover:ring-2 hover:ring-primary transition-all cursor-pointer ${fe.has(me.id)?"ring-2 ring-primary bg-primary/5":""}`,onClick:()=>ee(me.id),children:[e.jsx("div",{className:`absolute top-1 left-1 z-10 transition-opacity ${fe.has(me.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 ${fe.has(me.id)?"bg-primary border-primary text-primary-foreground":"bg-background/80 border-muted-foreground/50"}`,children:fe.has(me.id)&&e.jsx(pt,{className:"h-3 w-3"})})}),e.jsxs("div",{className:"absolute top-1 right-1 z-10 flex flex-col gap-0.5",children:[me.is_registered&&e.jsx(ke,{variant:"default",className:"bg-green-600 text-[10px] px-1 py-0",children:"已注册"}),me.is_banned&&e.jsx(ke,{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 ${Q==="small"?"p-1":Q==="medium"?"p-2":"p-3"}`,children:e.jsx($4,{src:K4(me.id),alt:"表情包"})}),e.jsxs("div",{className:`border-t bg-card ${Q==="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(ke,{variant:"outline",className:"text-[10px] px-1 py-0",children:me.format.toUpperCase()}),e.jsxs("span",{className:"font-mono",children:[me.usage_count,"次"]})]}),e.jsxs("div",{className:`flex gap-1 justify-center opacity-0 group-hover:opacity-100 transition-opacity ${Q==="small"?"flex-wrap":""}`,children:[e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:Ae=>{Ae.stopPropagation(),Re(me)},title:"编辑",children:e.jsx(Jn,{className:"h-3 w-3"})}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:Ae=>{Ae.stopPropagation(),de(me)},title:"详情",children:e.jsx(Ft,{className:"h-3 w-3"})}),!me.is_registered&&e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6 text-green-600 hover:text-green-700",onClick:Ae=>{Ae.stopPropagation(),Fe(me)},title:"注册",children:e.jsx(pt,{className:"h-3 w-3"})}),!me.is_banned&&e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6 text-orange-600 hover:text-orange-700",onClick:Ae=>{Ae.stopPropagation(),H(me)},title:"封禁",children:e.jsx(z_,{className:"h-3 w-3"})}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-6 w-6 text-red-600 hover:text-red-700",onClick:Ae=>{Ae.stopPropagation(),W(me)},title:"删除",children:e.jsx(ns,{className:"h-3 w-3"})})]})]})]},me.id))}),p>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 mt-4",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["显示 ",(h-1)*N+1," 到"," ",Math.min(h*N,p)," 条,共 ",p," 条"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(me=>Math.max(1,me-1)),disabled:h===1,children:[e.jsx(Da,{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(ae,{type:"number",value:P,onChange:me=>ue(me.target.value),onKeyDown:me=>me.key==="Enter"&&ie(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(p/N)}),e.jsx(_,{variant:"outline",size:"sm",onClick:ie,disabled:!P,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(me=>me+1),disabled:h>=Math.ceil(p/N),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(p/N)),disabled:h>=Math.ceil(p/N),className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]})]}),e.jsx(Z4,{emoji:F,open:J,onOpenChange:U}),e.jsx(W4,{emoji:F,open:oe,onOpenChange:Ne,onSuccess:()=>{D(),G()}}),e.jsx(ek,{open:pe,onOpenChange:Te,onSuccess:()=>{D(),G()}})]})}),e.jsx(Ns,{open:M,onOpenChange:K,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["你确定要删除选中的 ",fe.size," 个表情包吗?此操作不可撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:Ue,children:"确认删除"})]})]})}),e.jsx(Ps,{open:je,onOpenChange:re,children:e.jsxs(Ds,{children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"确认删除"}),e.jsx(Ks,{children:"确定要删除这个表情包吗?此操作无法撤销。"})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>re(!1),children:"取消"}),e.jsx(_,{variant:"destructive",onClick:Y,children:"删除"})]})]})})]})}function Z4({emoji:a,open:n,onOpenChange:r}){if(!a)return null;const c=d=>d?new Date(d*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[90vh]",children:[e.jsx(Os,{children:e.jsx(Ls,{children:"表情包详情"})}),e.jsx(Je,{className:"max-h-[calc(90vh-8rem)] pr-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-32 h-32 bg-muted rounded-lg flex items-center justify-center overflow-hidden",children:e.jsx("img",{src:Q4(a.id),alt:a.description||"表情包",className:"w-full h-full object-cover",onError:d=>{const u=d.target;u.style.display="none";const h=u.parentElement;h&&(h.innerHTML='')}})})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"ID"}),e.jsx("div",{className:"mt-1 font-mono",children:a.id})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"格式"}),e.jsx("div",{className:"mt-1",children:e.jsx(ke,{variant:"outline",children:a.format.toUpperCase()})})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"文件路径"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:a.full_path})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"哈希值"}),e.jsx("div",{className:"mt-1 font-mono text-sm break-all bg-muted p-2 rounded",children:a.emoji_hash})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"描述"}),a.description?e.jsx("div",{className:"mt-1 rounded-lg border bg-muted/50 p-3",children:e.jsx(B4,{className:"prose-sm",children:a.description})}):e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"-"})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"情绪"}),e.jsx("div",{className:"mt-1",children:a.emotion?e.jsx("span",{className:"text-sm",children:a.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(T,{className:"text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[a.is_registered&&e.jsx(ke,{variant:"default",className:"bg-green-600",children:"已注册"}),a.is_banned&&e.jsx(ke,{variant:"destructive",children:"已封禁"}),!a.is_registered&&!a.is_banned&&e.jsx(ke,{variant:"outline",children:"未注册"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"使用次数"}),e.jsx("div",{className:"mt-1 font-mono text-lg",children:a.usage_count})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"记录时间"}),e.jsx("div",{className:"mt-1 text-sm",children:c(a.record_time)})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"注册时间"}),e.jsx("div",{className:"mt-1 text-sm",children:c(a.register_time)})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-muted-foreground",children:"最后使用"}),e.jsx("div",{className:"mt-1 text-sm",children:c(a.last_used_time)})]})]})})]})})}function W4({emoji:a,open:n,onOpenChange:r,onSuccess:c}){const[d,u]=m.useState(""),[h,f]=m.useState(!1),[p,g]=m.useState(!1),[N,v]=m.useState(!1),{toast:w}=Ys();m.useEffect(()=>{a&&(u(a.emotion||""),f(a.is_registered),g(a.is_banned))},[a]);const b=async()=>{if(a)try{v(!0);const y=d.split(/[,,]/).map(O=>O.trim()).filter(Boolean).join(",");await F4(a.id,{emotion:y||void 0,is_registered:h,is_banned:p}),w({title:"成功",description:"表情包信息已更新"}),r(!1),c()}catch(y){const O=y instanceof Error?y.message:"保存失败";w({title:"错误",description:O,variant:"destructive"})}finally{v(!1)}};return a?e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑表情包"}),e.jsx(Ks,{children:"修改表情包的情绪和状态信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(T,{children:"情绪"}),e.jsx(ot,{value:d,onChange:y=>u(y.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(qs,{id:"is_registered",checked:h,onCheckedChange:y=>{y===!0?(f(!0),g(!1)):f(!1)}}),e.jsx(T,{htmlFor:"is_registered",className:"cursor-pointer",children:"已注册"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"is_banned",checked:p,onCheckedChange:y=>{y===!0?(g(!0),f(!1)):g(!1)}}),e.jsx(T,{htmlFor:"is_banned",className:"cursor-pointer",children:"已封禁"})]})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:b,disabled:N,children:N?"保存中...":"保存"})]})]})}):null}function ek({open:a,onOpenChange:n,onSuccess:r}){const[c,d]=m.useState("select"),[u,h]=m.useState([]),[f,p]=m.useState(null),[g,N]=m.useState(!1),{toast:v}=Ys(),w=m.useMemo(()=>new x1({id:"emoji-uploader",autoProceed:!1,restrictions:{maxFileSize:10485760,allowedFileTypes:["image/jpeg","image/png","image/gif","image/webp"],maxNumberOfFiles:20},locale:{pluralize:()=>0,strings:{addMoreFiles:"添加更多文件",addingMoreFiles:"正在添加更多文件",allowedFileTypes:"允许的文件类型:%{types}",cancel:"取消",closeModal:"关闭",complete:"完成",connectedToInternet:"已连接到互联网",copyLink:"复制链接",copyLinkToClipboardFallback:"复制下方链接",copyLinkToClipboardSuccess:"链接已复制到剪贴板",dashboardTitle:"选择文件",dashboardWindowTitle:"文件选择窗口(按 ESC 关闭)",done:"完成",dropHereOr:"拖放文件到这里或 %{browse}",dropHint:"将文件拖放到此处",dropPasteFiles:"将文件拖放到这里或 %{browseFiles}",dropPasteFolders:"将文件拖放到这里或 %{browseFolders}",dropPasteBoth:"将文件拖放到这里,%{browseFiles} 或 %{browseFolders}",dropPasteImportFiles:"将文件拖放到这里,%{browseFiles} 或从以下位置导入:",dropPasteImportFolders:"将文件拖放到这里,%{browseFolders} 或从以下位置导入:",dropPasteImportBoth:"将文件拖放到这里,%{browseFiles},%{browseFolders} 或从以下位置导入:",editFile:"编辑文件",editing:"正在编辑 %{file}",emptyFolderAdded:"未从空文件夹添加文件",exceedsSize:"%{file} 超过了最大允许大小 %{size}",failedToUpload:"上传 %{file} 失败",fileSource:"文件来源:%{name}",filesUploadedOfTotal:{0:"已上传 %{complete} / %{smart_count} 个文件",1:"已上传 %{complete} / %{smart_count} 个文件"},filter:"筛选",finishEditingFile:"完成编辑文件",folderAdded:{0:"已从 %{folder} 添加 %{smart_count} 个文件",1:"已从 %{folder} 添加 %{smart_count} 个文件"},generatingThumbnails:"正在生成缩略图...",import:"导入",importFiles:"从以下位置导入文件:",importFrom:"从 %{name} 导入",loading:"加载中...",logOut:"登出",myDevice:"我的设备",noFilesFound:"这里没有文件或文件夹",noInternetConnection:"无网络连接",openFolderNamed:"打开文件夹 %{name}",pause:"暂停",pauseUpload:"暂停上传",paused:"已暂停",poweredBy:"技术支持:%{uppy}",processingXFiles:{0:"正在处理 %{smart_count} 个文件",1:"正在处理 %{smart_count} 个文件"},recording:"录制中",removeFile:"移除文件",resetFilter:"重置筛选",resume:"继续",resumeUpload:"继续上传",retry:"重试",retryUpload:"重试上传",save:"保存",saveChanges:"保存更改",selectFileNamed:"选择文件 %{name}",selectX:{0:"选择 %{smart_count}",1:"选择 %{smart_count}"},smile:"笑一个!",startRecording:"开始录制视频",stopRecording:"停止录制视频",takePicture:"拍照",timedOut:"上传已停滞 %{seconds} 秒,正在中止。",upload:"下一步",uploadComplete:"上传完成",uploadFailed:"上传失败",uploadPaused:"上传已暂停",uploadXFiles:{0:"下一步(%{smart_count} 个文件)",1:"下一步(%{smart_count} 个文件)"},uploadXNewFiles:{0:"下一步(+%{smart_count} 个文件)",1:"下一步(+%{smart_count} 个文件)"},uploading:"正在上传",uploadingXFiles:{0:"正在上传 %{smart_count} 个文件",1:"正在上传 %{smart_count} 个文件"},xFilesSelected:{0:"已选择 %{smart_count} 个文件",1:"已选择 %{smart_count} 个文件"},xMoreFilesAdded:{0:"又添加了 %{smart_count} 个文件",1:"又添加了 %{smart_count} 个文件"},xTimeLeft:"剩余 %{time}",youCanOnlyUploadFileTypes:"您只能上传:%{types}",youCanOnlyUploadX:{0:"您只能上传 %{smart_count} 个文件",1:"您只能上传 %{smart_count} 个文件"},youHaveToAtLeastSelectX:{0:"您至少需要选择 %{smart_count} 个文件",1:"您至少需要选择 %{smart_count} 个文件"},browseFiles:"浏览文件",browseFolders:"浏览文件夹",cancelUpload:"取消上传",addMore:"添加更多",back:"返回",editFileWithFilename:"编辑文件 %{file}"}}}),[]);m.useEffect(()=>{const F=()=>{const L=w.getFiles();if(L.length===0)return;const J=L.map(U=>({id:U.id,name:U.name,previewUrl:U.preview||URL.createObjectURL(U.data),emotion:"",description:"",isRegistered:!0,file:U.data}));h(J),L.length===1?(p(J[0].id),d("edit-single")):d("edit-multiple")};return w.on("upload",F),()=>{w.off("upload",F)}},[w]),m.useEffect(()=>{a||(w.cancelAll(),d("select"),h([]),p(null),N(!1))},[a,w]);const b=m.useCallback((F,L)=>{h(J=>J.map(U=>U.id===F?{...U,...L}:U))},[]),y=m.useCallback(F=>F.emotion.trim().length>0,[]),O=m.useMemo(()=>u.length>0&&u.every(y),[u,y]),R=m.useMemo(()=>u.find(F=>F.id===f)||null,[u,f]),S=m.useCallback(()=>{(c==="edit-single"||c==="edit-multiple")&&(d("select"),h([]),p(null))},[c]),B=m.useCallback(async()=>{if(!O){v({title:"请填写必填项",description:"每个表情包的情感标签都是必填的",variant:"destructive"});return}N(!0);let F=0,L=0;try{for(const J of u){const U=new FormData;U.append("file",J.file),U.append("emotion",J.emotion),U.append("description",J.description),U.append("is_registered",J.isRegistered.toString());try{(await _e(J4(),{method:"POST",body:U})).ok?F++:L++}catch{L++}}L===0?(v({title:"上传成功",description:`成功上传 ${F} 个表情包`}),n(!1),r()):(v({title:"部分上传失败",description:`成功 ${F} 个,失败 ${L} 个`,variant:"destructive"}),r())}finally{N(!1)}},[O,u,v,n,r]),E=()=>e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"border rounded-lg overflow-hidden w-full",children:e.jsx(U4,{uppy:w,proudlyDisplayPoweredByUppy:!1,hideProgressDetails:!0,height:350,width:"100%",theme:"auto",note:"支持 JPG、PNG、GIF、WebP 格式,最多 20 个文件"})})}),C=()=>{const F=u[0];return F?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:S,children:[e.jsx(Ma,{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:F.previewUrl,alt:F.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:F.name})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"single-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ae,{id:"single-emotion",value:F.emotion,onChange:L=>b(F.id,{emotion:L.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:F.emotion.trim()?"":"border-destructive"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"用于情感匹配,多个标签用逗号分隔"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"single-description",children:"描述"}),e.jsx(ae,{id:"single-description",value:F.description,onChange:L=>b(F.id,{description:L.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"single-is-registered",checked:F.isRegistered,onCheckedChange:L=>b(F.id,{isRegistered:L===!0})}),e.jsx(T,{htmlFor:"single-is-registered",className:"cursor-pointer",children:"上传后立即注册(可被麦麦使用)"})]})]})]}),e.jsx(st,{children:e.jsx(_,{onClick:B,disabled:!O||g,children:g?"上传中...":"上传"})})]}):null},A=()=>{const F=u.filter(y).length,L=u.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(_,{variant:"ghost",size:"sm",onClick:S,children:[e.jsx(Ma,{className:"h-4 w-4 mr-1"}),"返回"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["编辑表情包信息(",F,"/",L," 已完成)"]})]}),e.jsx(ke,{variant:O?"default":"secondary",children:O?e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"h-3 w-3 mr-1"}),"全部完成"]}):e.jsxs(e.Fragment,{children:[e.jsx(Aa,{className:"h-3 w-3 mr-1"}),"未完成"]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Je,{className:"h-[350px] pr-2",children:e.jsx("div",{className:"space-y-2",children:u.map(J=>{const U=y(J),oe=f===J.id;return e.jsxs("div",{onClick:()=>p(J.id),className:` - flex items-center gap-3 p-3 rounded-lg border-2 cursor-pointer transition-all - ${oe?"ring-2 ring-primary":""} - ${U?"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:J.previewUrl,alt:J.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:J.name}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:J.emotion||"未填写情感标签"})]}),U?e.jsx(pt,{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"})]},J.id)})})}),e.jsx("div",{className:"border rounded-lg p-4",children:R?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:R.previewUrl,alt:R.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:R.name}),y(R)&&e.jsxs(ke,{variant:"outline",className:"text-green-600 border-green-600",children:[e.jsx(Ct,{className:"h-3 w-3 mr-1"}),"已完成"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"multi-emotion",children:["情感标签 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ae,{id:"multi-emotion",value:R.emotion,onChange:J=>b(R.id,{emotion:J.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:R.emotion.trim()?"":"border-destructive"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"multi-description",children:"描述"}),e.jsx(ae,{id:"multi-description",value:R.description,onChange:J=>b(R.id,{description:J.target.value}),placeholder:"输入表情包描述..."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"multi-is-registered",checked:R.isRegistered,onCheckedChange:J=>b(R.id,{isRegistered:J===!0})}),e.jsx(T,{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(ix,{className:"h-12 w-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"点击左侧卡片编辑"})]})})})]}),e.jsx(st,{children:e.jsx(_,{onClick:B,disabled:!O||g,children:g?"上传中...":`上传全部 (${L})`})})]})};return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-3xl max-h-[90vh] overflow-hidden",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(rc,{className:"h-5 w-5"}),c==="select"&&"上传表情包 - 选择文件",c==="edit-single"&&"上传表情包 - 填写信息",c==="edit-multiple"&&"上传表情包 - 批量编辑"]}),e.jsxs(Ks,{children:[c==="select"&&"支持 JPG、PNG、GIF、WebP 格式,单个文件最大 10MB,可同时上传多个文件",c==="edit-single"&&"请填写表情包的情感标签(必填)和描述",c==="edit-multiple"&&"点击左侧卡片编辑每个表情包的信息,情感标签为必填项"]})]}),e.jsxs("div",{className:"overflow-y-auto pr-1",children:[c==="select"&&E(),c==="edit-single"&&C(),c==="edit-multiple"&&A()]})]})})}function sk(){const[a,n]=m.useState([]),[r,c]=m.useState(!0),[d,u]=m.useState(0),[h,f]=m.useState(1),[p,g]=m.useState(20),[N,v]=m.useState(""),[w,b]=m.useState(null),[y,O]=m.useState(!1),[R,S]=m.useState(!1),[B,E]=m.useState(!1),[C,A]=m.useState(null),[F,L]=m.useState(new Set),[J,U]=m.useState(!1),[oe,Ne]=m.useState(""),[je,re]=m.useState({total:0,recent_7days:0,chat_count:0,top_chats:{}}),[fe,ge]=m.useState([]),[M,K]=m.useState(new Map),[P,ue]=m.useState(!1),[Q,Se]=m.useState(0),{toast:pe}=Ys(),Te=async()=>{try{c(!0);const ie=await J1({page:h,page_size:p,search:N||void 0});n(ie.data),u(ie.total)}catch(ie){pe({title:"加载失败",description:ie instanceof Error?ie.message:"无法加载表达方式",variant:"destructive"})}finally{c(!1)}},z=async()=>{try{const ie=await t2();ie?.data&&re(ie.data)}catch(ie){console.error("加载统计数据失败:",ie)}},D=async()=>{try{const ie=await mx();Se(ie.unchecked)}catch(ie){console.error("加载审核统计失败:",ie)}},G=async()=>{try{const ie=await ux();if(ie?.data){ge(ie.data);const Ee=new Map;ie.data.forEach(me=>{Ee.set(me.chat_id,me.chat_name)}),K(Ee)}}catch(ie){console.error("加载聊天列表失败:",ie)}},de=ie=>M.get(ie)||ie;m.useEffect(()=>{Te(),D(),z(),G()},[h,p,N]);const Re=async ie=>{try{const Ee=await X1(ie.id);b(Ee.data),O(!0)}catch(Ee){pe({title:"加载详情失败",description:Ee instanceof Error?Ee.message:"无法加载表达方式详情",variant:"destructive"})}},W=ie=>{b(ie),S(!0)},Y=async ie=>{try{await e2(ie.id),pe({title:"删除成功",description:`已删除表达方式: ${ie.situation}`}),A(null),Te(),z()}catch(Ee){pe({title:"删除失败",description:Ee instanceof Error?Ee.message:"无法删除表达方式",variant:"destructive"})}},Fe=ie=>{const Ee=new Set(F);Ee.has(ie)?Ee.delete(ie):Ee.add(ie),L(Ee)},H=()=>{F.size===a.length&&a.length>0?L(new Set):L(new Set(a.map(ie=>ie.id)))},ee=async()=>{try{await s2(Array.from(F)),pe({title:"批量删除成功",description:`已删除 ${F.size} 个表达方式`}),L(new Set),U(!1),Te(),z()}catch(ie){pe({title:"批量删除失败",description:ie instanceof Error?ie.message:"无法批量删除表达方式",variant:"destructive"})}},Ue=()=>{const ie=parseInt(oe),Ee=Math.ceil(d/p);ie>=1&&ie<=Ee?(f(ie),Ne("")):pe({title:"无效的页码",description:`请输入1-${Ee}之间的页码`,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(Ra,{className:"h-8 w-8",strokeWidth:2}),"表达方式管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦的表达方式和话术模板"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(_,{variant:"outline",onClick:()=>ue(!0),className:"gap-2",children:[e.jsx(Wj,{className:"h-4 w-4"}),"人工审核",Q>0&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 text-xs rounded-full bg-orange-500 text-white",children:Q>99?"99+":Q})]}),e.jsxs(_,{onClick:()=>E(!0),className:"gap-2",children:[e.jsx(et,{className:"h-4 w-4"}),"新增表达方式"]})]})]})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"总数量"}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:je.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:je.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:je.chat_count})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx(T,{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(Tt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ae,{id:"search",placeholder:"搜索情境、风格或上下文...",value:N,onChange:ie=>v(ie.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:F.size>0&&e.jsxs("span",{children:["已选择 ",F.size," 个表达方式"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Pe,{value:p.toString(),onValueChange:ie=>{g(parseInt(ie)),f(1),L(new Set)},children:[e.jsx($e,{id:"page-size",className:"w-20",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"10",children:"10"}),e.jsx(Z,{value:"20",children:"20"}),e.jsx(Z,{value:"50",children:"50"}),e.jsx(Z,{value:"100",children:"100"})]})]}),F.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>L(new Set),children:"取消选择"}),e.jsxs(_,{variant:"destructive",size:"sm",onClick:()=>U(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:F.size===a.length&&a.length>0,onCheckedChange:H})}),e.jsx(We,{children:"情境"}),e.jsx(We,{children:"风格"}),e.jsx(We,{children:"聊天"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:r?e.jsx(ut,{children:e.jsx(Ke,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):a.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):a.map(ie=>e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(qs,{checked:F.has(ie.id),onCheckedChange:()=>Fe(ie.id)})}),e.jsx(Ke,{className:"font-medium max-w-xs truncate",children:ie.situation}),e.jsx(Ke,{className:"max-w-xs truncate",children:ie.style}),e.jsx(Ke,{className:"max-w-[200px] truncate",title:de(ie.chat_id),style:{wordBreak:"keep-all"},children:e.jsx("span",{className:"whitespace-nowrap overflow-hidden text-ellipsis block",children:de(ie.chat_id)})}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>W(ie),children:[e.jsx(Jn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>Re(ie),title:"查看详情",children:e.jsx(ia,{className:"h-4 w-4"})}),e.jsxs(_,{size:"sm",onClick:()=>A(ie),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},ie.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):a.map(ie=>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(qs,{checked:F.has(ie.id),onCheckedChange:()=>Fe(ie.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:ie.situation,children:ie.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:ie.style,children:ie.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:de(ie.chat_id),style:{wordBreak:"keep-all"},children:de(ie.chat_id)})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>W(ie),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(Jn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>Re(ie),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:e.jsx(ia,{className:"h-3 w-3"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>A(ie),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(ns,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},ie.id))}),d>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:["共 ",d," 条记录,第 ",h," / ",Math.ceil(d/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Da,{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(ae,{type:"number",value:oe,onChange:ie=>Ne(ie.target.value),onKeyDown:ie=>ie.key==="Enter"&&Ue(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(d/p)}),e.jsx(_,{variant:"outline",size:"sm",onClick:Ue,disabled:!oe,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(d/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(d/p)),disabled:h>=Math.ceil(d/p),className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(tk,{expression:w,open:y,onOpenChange:O,chatNameMap:M}),e.jsx(ak,{open:B,onOpenChange:E,chatList:fe,onSuccess:()=>{Te(),z(),E(!1)}}),e.jsx(lk,{expression:w,open:R,onOpenChange:S,chatList:fe,onSuccess:()=>{Te(),z(),S(!1)}}),e.jsx(Ns,{open:!!C,onOpenChange:()=>A(null),children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除表达方式 "',C?.situation,'" 吗? 此操作不可撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>C&&Y(C),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(nk,{open:J,onOpenChange:U,onConfirm:ee,count:F.size}),e.jsx(Dv,{open:P,onOpenChange:ie=>{ue(ie),ie||(Te(),z(),D())}})]})}function tk({expression:a,open:n,onOpenChange:r,chatNameMap:c}){if(!a)return null;const d=h=>h?new Date(h*1e3).toLocaleString("zh-CN"):"-",u=h=>c.get(h)||h;return e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"表达方式详情"}),e.jsx(Ks,{children:"查看表达方式的完整信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ki,{label:"情境",value:a.situation}),e.jsx(Ki,{label:"风格",value:a.style}),e.jsx(Ki,{label:"聊天",value:u(a.chat_id)}),e.jsx(Ki,{icon:Jr,label:"记录ID",value:a.id.toString(),mono:!0})]}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsx(Ki,{icon:na,label:"创建时间",value:d(a.create_date)})}),e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-4",children:[e.jsx(T,{className:"text-xs text-muted-foreground mb-3 block",children:"状态标记"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:I("flex h-8 w-8 items-center justify-center rounded-full",a.checked?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-400 dark:bg-gray-800 dark:text-gray-600"),children:a.checked?e.jsx(pt,{className:"h-5 w-5"}):e.jsx(Ho,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"已检查"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.checked?"已通过审核":"未审核"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:I("flex h-8 w-8 items-center justify-center rounded-full",a.rejected?"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400":"bg-gray-100 text-gray-400 dark:bg-gray-800 dark:text-gray-600"),children:a.rejected?e.jsx(Ka,{className:"h-5 w-5"}):e.jsx(Ho,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"已拒绝"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.rejected?"不会被使用":"正常"})]})]})]})]})]}),e.jsx(st,{children:e.jsx(_,{onClick:()=>r(!1),children:"关闭"})})]})})}function Ki({icon:a,label:n,value:r,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[a&&e.jsx(a,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:I("text-sm",c&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function ak({open:a,onOpenChange:n,chatList:r,onSuccess:c}){const[d,u]=m.useState({situation:"",style:"",chat_id:""}),[h,f]=m.useState(!1),{toast:p}=Ys(),g=async()=>{if(!d.situation||!d.style||!d.chat_id){p({title:"验证失败",description:"请填写必填字段:情境、风格和聊天",variant:"destructive"});return}try{f(!0),await Z1(d),p({title:"创建成功",description:"表达方式已创建"}),u({situation:"",style:"",chat_id:""}),c()}catch(N){p({title:"创建失败",description:N instanceof Error?N.message:"无法创建表达方式",variant:"destructive"})}finally{f(!1)}};return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"新增表达方式"}),e.jsx(Ks,{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(T,{htmlFor:"situation",children:["情境 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ae,{id:"situation",value:d.situation,onChange:N=>u({...d,situation:N.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"style",children:["风格 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ae,{id:"style",value:d.style,onChange:N=>u({...d,style:N.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Pe,{value:d.chat_id,onValueChange:N=>u({...d,chat_id:N}),children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:"选择关联的聊天"})}),e.jsx(Be,{children:r.map(N=>e.jsx(Z,{value:N.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[N.chat_name,N.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},N.chat_id))})]})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>n(!1),children:"取消"}),e.jsx(_,{onClick:g,disabled:h,children:h?"创建中...":"创建"})]})]})})}function lk({expression:a,open:n,onOpenChange:r,chatList:c,onSuccess:d}){const[u,h]=m.useState({}),[f,p]=m.useState(!1),{toast:g}=Ys();m.useEffect(()=>{a&&h({situation:a.situation,style:a.style,chat_id:a.chat_id,checked:a.checked,rejected:a.rejected})},[a]);const N=async()=>{if(a)try{p(!0),await W1(a.id,u),g({title:"保存成功",description:"表达方式已更新"}),d()}catch(v){g({title:"保存失败",description:v instanceof Error?v.message:"无法更新表达方式",variant:"destructive"})}finally{p(!1)}};return a?e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑表达方式"}),e.jsx(Ks,{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(T,{htmlFor:"edit_situation",children:"情境"}),e.jsx(ae,{id:"edit_situation",value:u.situation||"",onChange:v=>h({...u,situation:v.target.value}),placeholder:"描述使用场景"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_style",children:"风格"}),e.jsx(ae,{id:"edit_style",value:u.style||"",onChange:v=>h({...u,style:v.target.value}),placeholder:"描述表达风格"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Pe,{value:u.chat_id||"",onValueChange:v=>h({...u,chat_id:v}),children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:"选择关联的聊天"})}),e.jsx(Be,{children:c.map(v=>e.jsx(Z,{value:v.chat_id,children:e.jsxs("span",{className:"truncate",style:{wordBreak:"keep-all"},children:[v.chat_name,v.is_group&&e.jsx("span",{className:"text-muted-foreground ml-1",children:"(群聊)"})]})},v.chat_id))})]})]}),e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(lt,{className:"text-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{children:e.jsx("strong",{children:"状态标记说明:"})}),e.jsx("p",{children:"• 已检查:表示该表达方式已通过审核(可由AI自动检查或人工审核)"}),e.jsx("p",{children:"• 已拒绝:表示该表达方式被标记为不合适,将永远不会被使用"}),e.jsxs("p",{className:"text-muted-foreground mt-2",children:['根据配置中"仅使用已审核通过的表达方式"设置:',e.jsx("br",{}),"• 开启时:只有通过审核(已检查)的项目会被使用",e.jsx("br",{}),"• 关闭时:未审核的项目也会被使用"]})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between space-x-2 rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{htmlFor:"edit_checked",className:"text-sm font-medium",children:"已检查"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"已通过审核"})]}),e.jsx(Ve,{id:"edit_checked",checked:u.checked??!1,onCheckedChange:v=>h({...u,checked:v})})]}),e.jsxs("div",{className:"flex items-center justify-between space-x-2 rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{htmlFor:"edit_rejected",className:"text-sm font-medium",children:"已拒绝"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"不会被使用"})]}),e.jsx(Ve,{id:"edit_rejected",checked:u.rejected??!1,onCheckedChange:v=>h({...u,rejected:v})})]})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:N,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}function nk({open:a,onOpenChange:n,onConfirm:r,count:c}){return e.jsx(Ns,{open:a,onOpenChange:n,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["您即将删除 ",c," 个表达方式,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:r,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})}const Pl="/api/webui/jargon";async function rk(){const a=await _e(`${Pl}/chats`,{});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取聊天列表失败")}return a.json()}async function ik(a){const n=new URLSearchParams;a.page&&n.append("page",a.page.toString()),a.page_size&&n.append("page_size",a.page_size.toString()),a.search&&n.append("search",a.search),a.chat_id&&n.append("chat_id",a.chat_id),a.is_jargon!==void 0&&a.is_jargon!==null&&n.append("is_jargon",a.is_jargon.toString()),a.is_global!==void 0&&n.append("is_global",a.is_global.toString());const r=await _e(`${Pl}/list?${n}`,{});if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取黑话列表失败")}return r.json()}async function ck(a){const n=await _e(`${Pl}/${a}`,{});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取黑话详情失败")}return n.json()}async function ok(a){const n=await _e(`${Pl}/`,{method:"POST",body:JSON.stringify(a)});if(!n.ok){const r=await n.json();throw new Error(r.detail||"创建黑话失败")}return n.json()}async function dk(a,n){const r=await _e(`${Pl}/${a}`,{method:"PATCH",body:JSON.stringify(n)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"更新黑话失败")}return r.json()}async function uk(a){const n=await _e(`${Pl}/${a}`,{method:"DELETE"});if(!n.ok){const r=await n.json();throw new Error(r.detail||"删除黑话失败")}return n.json()}async function mk(a){const n=await _e(`${Pl}/batch/delete`,{method:"POST",body:JSON.stringify({ids:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"批量删除黑话失败")}return n.json()}async function xk(){const a=await _e(`${Pl}/stats/summary`,{});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取黑话统计失败")}return a.json()}async function hk(a,n){const r=new URLSearchParams;a.forEach(d=>r.append("ids",d.toString())),r.append("is_jargon",n.toString());const c=await _e(`${Pl}/batch/set-jargon?${r}`,{method:"POST"});if(!c.ok){const d=await c.json();throw new Error(d.detail||"批量设置黑话状态失败")}return c.json()}function fk(){const[a,n]=m.useState([]),[r,c]=m.useState(!0),[d,u]=m.useState(0),[h,f]=m.useState(1),[p,g]=m.useState(20),[N,v]=m.useState(""),[w,b]=m.useState("all"),[y,O]=m.useState("all"),[R,S]=m.useState(null),[B,E]=m.useState(!1),[C,A]=m.useState(!1),[F,L]=m.useState(!1),[J,U]=m.useState(null),[oe,Ne]=m.useState(new Set),[je,re]=m.useState(!1),[fe,ge]=m.useState(""),[M,K]=m.useState({total:0,confirmed_jargon:0,confirmed_not_jargon:0,pending:0,global_count:0,complete_count:0,chat_count:0,top_chats:{}}),[P,ue]=m.useState([]),{toast:Q}=Ys(),Se=async()=>{try{c(!0);const ee=await ik({page:h,page_size:p,search:N||void 0,chat_id:w==="all"?void 0:w,is_jargon:y==="all"?void 0:y==="true"?!0:y==="false"?!1:void 0});n(ee.data),u(ee.total)}catch(ee){Q({title:"加载失败",description:ee instanceof Error?ee.message:"无法加载黑话列表",variant:"destructive"})}finally{c(!1)}},pe=async()=>{try{const ee=await xk();ee?.data&&K(ee.data)}catch(ee){console.error("加载统计数据失败:",ee)}},Te=async()=>{try{const ee=await rk();ee?.data&&ue(ee.data)}catch(ee){console.error("加载聊天列表失败:",ee)}};m.useEffect(()=>{Se(),pe(),Te()},[h,p,N,w,y]);const z=async ee=>{try{const Ue=await ck(ee.id);S(Ue.data),E(!0)}catch(Ue){Q({title:"加载详情失败",description:Ue instanceof Error?Ue.message:"无法加载黑话详情",variant:"destructive"})}},D=ee=>{S(ee),A(!0)},G=async ee=>{try{await uk(ee.id),Q({title:"删除成功",description:`已删除黑话: ${ee.content}`}),U(null),Se(),pe()}catch(Ue){Q({title:"删除失败",description:Ue instanceof Error?Ue.message:"无法删除黑话",variant:"destructive"})}},de=ee=>{const Ue=new Set(oe);Ue.has(ee)?Ue.delete(ee):Ue.add(ee),Ne(Ue)},Re=()=>{oe.size===a.length&&a.length>0?Ne(new Set):Ne(new Set(a.map(ee=>ee.id)))},W=async()=>{try{await mk(Array.from(oe)),Q({title:"批量删除成功",description:`已删除 ${oe.size} 个黑话`}),Ne(new Set),re(!1),Se(),pe()}catch(ee){Q({title:"批量删除失败",description:ee instanceof Error?ee.message:"无法批量删除黑话",variant:"destructive"})}},Y=async ee=>{try{await hk(Array.from(oe),ee),Q({title:"操作成功",description:`已将 ${oe.size} 个词条设为${ee?"黑话":"非黑话"}`}),Ne(new Set),Se(),pe()}catch(Ue){Q({title:"操作失败",description:Ue instanceof Error?Ue.message:"批量设置失败",variant:"destructive"})}},Fe=()=>{const ee=parseInt(fe),Ue=Math.ceil(d/p);ee>=1&&ee<=Ue?(f(ee),ge("")):Q({title:"无效的页码",description:`请输入1-${Ue}之间的页码`,variant:"destructive"})},H=ee=>ee===!0?e.jsxs(ke,{variant:"default",className:"bg-green-600 hover:bg-green-700",children:[e.jsx(Ct,{className:"h-3 w-3 mr-1"}),"是黑话"]}):ee===!1?e.jsxs(ke,{variant:"secondary",children:[e.jsx(Aa,{className:"h-3 w-3 mr-1"}),"非黑话"]}):e.jsxs(ke,{variant:"outline",children:[e.jsx(sv,{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(R_,{className:"h-8 w-8",strokeWidth:2}),"黑话管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦学习到的黑话和俚语"})]}),e.jsxs(_,{onClick:()=>L(!0),className:"gap-2",children:[e.jsx(et,{className:"h-4 w-4"}),"新增黑话"]})]})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-7 gap-3",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-3 sm:p-4",children:[e.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground",children:"总数量"}),e.jsx("div",{className:"text-xl sm:text-2xl font-bold mt-1",children:M.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:M.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:M.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:M.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:M.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:M.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:M.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(T,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ae,{id:"search",placeholder:"搜索内容、含义...",value:N,onChange:ee=>v(ee.target.value),className:"pl-9"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{children:"聊天筛选"}),e.jsxs(Pe,{value:w,onValueChange:b,children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:"全部聊天"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部聊天"}),P.map(ee=>e.jsx(Z,{value:ee.chat_id,children:ee.chat_name},ee.chat_id))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{children:"状态筛选"}),e.jsxs(Pe,{value:y,onValueChange:O,children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:"全部状态"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部状态"}),e.jsx(Z,{value:"true",children:"是黑话"}),e.jsx(Z,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{htmlFor:"page-size",children:"每页显示"}),e.jsxs(Pe,{value:p.toString(),onValueChange:ee=>{g(parseInt(ee)),f(1),Ne(new Set)},children:[e.jsx($e,{id:"page-size",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"10",children:"10"}),e.jsx(Z,{value:"20",children:"20"}),e.jsx(Z,{value:"50",children:"50"}),e.jsx(Z,{value:"100",children:"100"})]})]})]})]}),oe.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:["已选择 ",oe.size," 个"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>Y(!0),children:[e.jsx(Ct,{className:"h-4 w-4 mr-1"}),"标记为黑话"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>Y(!1),children:[e.jsx(Aa,{className:"h-4 w-4 mr-1"}),"标记为非黑话"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>Ne(new Set),children:"取消选择"}),e.jsxs(_,{variant:"destructive",size:"sm",onClick:()=>re(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:oe.size===a.length&&a.length>0,onCheckedChange:Re})}),e.jsx(We,{children:"内容"}),e.jsx(We,{children:"含义"}),e.jsx(We,{children:"聊天"}),e.jsx(We,{children:"状态"}),e.jsx(We,{className:"text-center",children:"次数"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:r?e.jsx(ut,{children:e.jsx(Ke,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):a.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):a.map(ee=>e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(qs,{checked:oe.has(ee.id),onCheckedChange:()=>de(ee.id)})}),e.jsx(Ke,{className:"font-medium max-w-[200px]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[ee.is_global&&e.jsx("span",{title:"全局黑话",children:e.jsx(Vo,{className:"h-4 w-4 text-blue-500 flex-shrink-0"})}),e.jsx("span",{className:"truncate",title:ee.content,children:ee.content})]})}),e.jsx(Ke,{className:"max-w-[200px] truncate",title:ee.meaning||"",children:ee.meaning||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ke,{className:"max-w-[150px] truncate",title:ee.chat_name||ee.chat_id,children:ee.chat_name||ee.chat_id}),e.jsx(Ke,{children:H(ee.is_jargon)}),e.jsx(Ke,{className:"text-center",children:ee.count}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>D(ee),children:[e.jsx(Jn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>z(ee),title:"查看详情",children:e.jsx(ia,{className:"h-4 w-4"})}),e.jsxs(_,{size:"sm",onClick:()=>U(ee),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},ee.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):a.map(ee=>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(qs,{checked:oe.has(ee.id),onCheckedChange:()=>de(ee.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:[ee.is_global&&e.jsx(Vo,{className:"h-4 w-4 text-blue-500 flex-shrink-0"}),e.jsx("h3",{className:"font-semibold text-sm break-all",children:ee.content})]}),ee.meaning&&e.jsx("p",{className:"text-sm text-muted-foreground break-all",children:ee.meaning}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:[H(ee.is_jargon),e.jsxs("span",{className:"text-muted-foreground",children:["次数: ",ee.count]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:["聊天: ",ee.chat_name||ee.chat_id]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>D(ee),className:"text-xs px-2 py-1 h-auto",children:[e.jsx(Jn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>z(ee),className:"text-xs px-2 py-1 h-auto",children:e.jsx(ia,{className:"h-3 w-3"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>U(ee),className:"text-xs px-2 py-1 h-auto text-destructive hover:text-destructive",children:[e.jsx(ns,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},ee.id))}),d>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:["共 ",d," 条记录,第 ",h," / ",Math.ceil(d/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Da,{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(ae,{type:"number",value:fe,onChange:ee=>ge(ee.target.value),onKeyDown:ee=>ee.key==="Enter"&&Fe(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(d/p)}),e.jsx(_,{variant:"outline",size:"sm",onClick:Fe,disabled:!fe,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(d/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(d/p)),disabled:h>=Math.ceil(d/p),className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(pk,{jargon:R,open:B,onOpenChange:E}),e.jsx(gk,{open:F,onOpenChange:L,chatList:P,onSuccess:()=>{Se(),pe(),L(!1)}}),e.jsx(jk,{jargon:R,open:C,onOpenChange:A,chatList:P,onSuccess:()=>{Se(),pe(),A(!1)}}),e.jsx(Ns,{open:!!J,onOpenChange:()=>U(null),children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除黑话 "',J?.content,'" 吗?此操作不可撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>J&&G(J),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(Ns,{open:je,onOpenChange:re,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["您即将删除 ",oe.size," 个黑话,此操作无法撤销。确定要继续吗?"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:W,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})]})}function pk({jargon:a,open:n,onOpenChange:r}){return a?e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"黑话详情"}),e.jsx(Ks,{children:"查看黑话的完整信息"})]}),e.jsx(Je,{className:"h-full pr-4",children:e.jsxs("div",{className:"space-y-4 pb-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Hm,{icon:Jr,label:"记录ID",value:a.id.toString(),mono:!0}),e.jsx(Hm,{label:"使用次数",value:a.count.toString()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"内容"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all whitespace-pre-wrap",children:a.content})]}),a.raw_content&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"原始内容"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:(()=>{try{const c=JSON.parse(a.raw_content);return Array.isArray(c)?c.map((d,u)=>e.jsxs("div",{children:[u>0&&e.jsx("hr",{className:"my-3 border-border"}),e.jsx("div",{className:"whitespace-pre-wrap",children:d})]},u)):e.jsx("div",{className:"whitespace-pre-wrap",children:a.raw_content})}catch{return e.jsx("div",{className:"whitespace-pre-wrap",children:a.raw_content})}})()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"含义"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:a.meaning?e.jsx(fx,{content:a.meaning}):"-"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Hm,{label:"聊天",value:a.chat_name||a.chat_id}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"状态"}),e.jsxs("div",{className:"flex items-center gap-2",children:[a.is_jargon===!0&&e.jsx(ke,{variant:"default",className:"bg-green-600",children:"是黑话"}),a.is_jargon===!1&&e.jsx(ke,{variant:"secondary",children:"非黑话"}),a.is_jargon===null&&e.jsx(ke,{variant:"outline",children:"未判定"}),a.is_global&&e.jsx(ke,{variant:"outline",className:"border-blue-500 text-blue-500",children:"全局"}),a.is_complete&&e.jsx(ke,{variant:"outline",className:"border-purple-500 text-purple-500",children:"推断完成"})]})]})]}),a.inference_with_context&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{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:a.inference_with_context})]}),a.inference_content_only&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{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:a.inference_content_only})]})]})}),e.jsx(st,{className:"flex-shrink-0",children:e.jsx(_,{onClick:()=>r(!1),children:"关闭"})})]})}):null}function Hm({icon:a,label:n,value:r,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[a&&e.jsx(a,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:I("text-sm",c&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function gk({open:a,onOpenChange:n,chatList:r,onSuccess:c}){const[d,u]=m.useState({content:"",meaning:"",chat_id:"",is_global:!1}),[h,f]=m.useState(!1),{toast:p}=Ys(),g=async()=>{if(!d.content||!d.chat_id){p({title:"验证失败",description:"请填写必填字段:内容和聊天",variant:"destructive"});return}try{f(!0),await ok(d),p({title:"创建成功",description:"黑话已创建"}),u({content:"",meaning:"",chat_id:"",is_global:!1}),c()}catch(N){p({title:"创建失败",description:N instanceof Error?N.message:"无法创建黑话",variant:"destructive"})}finally{f(!1)}};return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"新增黑话"}),e.jsx(Ks,{children:"创建新的黑话记录"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"content",children:["内容 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ae,{id:"content",value:d.content,onChange:N=>u({...d,content:N.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"meaning",children:"含义"}),e.jsx(ot,{id:"meaning",value:d.meaning||"",onChange:N=>u({...d,meaning:N.target.value}),placeholder:"输入黑话含义(可选)",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"chat_id",children:["聊天 ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(Pe,{value:d.chat_id,onValueChange:N=>u({...d,chat_id:N}),children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:"选择关联的聊天"})}),e.jsx(Be,{children:r.map(N=>e.jsx(Z,{value:N.chat_id,children:N.chat_name},N.chat_id))})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"is_global",checked:d.is_global,onCheckedChange:N=>u({...d,is_global:N})}),e.jsx(T,{htmlFor:"is_global",children:"设为全局黑话"})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>n(!1),children:"取消"}),e.jsx(_,{onClick:g,disabled:h,children:h?"创建中...":"创建"})]})]})})}function jk({jargon:a,open:n,onOpenChange:r,chatList:c,onSuccess:d}){const[u,h]=m.useState({}),[f,p]=m.useState(!1),{toast:g}=Ys();m.useEffect(()=>{a&&h({content:a.content,meaning:a.meaning||"",chat_id:a.stream_id||a.chat_id,is_global:a.is_global,is_jargon:a.is_jargon})},[a]);const N=async()=>{if(a)try{p(!0),await dk(a.id,u),g({title:"保存成功",description:"黑话已更新"}),d()}catch(v){g({title:"保存失败",description:v instanceof Error?v.message:"无法更新黑话",variant:"destructive"})}finally{p(!1)}};return a?e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑黑话"}),e.jsx(Ks,{children:"修改黑话的信息"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_content",children:"内容"}),e.jsx(ae,{id:"edit_content",value:u.content||"",onChange:v=>h({...u,content:v.target.value}),placeholder:"输入黑话内容"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_meaning",children:"含义"}),e.jsx(ot,{id:"edit_meaning",value:u.meaning||"",onChange:v=>h({...u,meaning:v.target.value}),placeholder:"输入黑话含义",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit_chat_id",children:"聊天"}),e.jsxs(Pe,{value:u.chat_id||"",onValueChange:v=>h({...u,chat_id:v}),children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:"选择关联的聊天"})}),e.jsx(Be,{children:c.map(v=>e.jsx(Z,{value:v.chat_id,children:v.chat_name},v.chat_id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"黑话状态"}),e.jsxs(Pe,{value:u.is_jargon===null?"null":u.is_jargon?.toString()||"null",onValueChange:v=>h({...u,is_jargon:v==="null"?null:v==="true"}),children:[e.jsx($e,{children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"null",children:"未判定"}),e.jsx(Z,{value:"true",children:"是黑话"}),e.jsx(Z,{value:"false",children:"非黑话"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ve,{id:"edit_is_global",checked:u.is_global,onCheckedChange:v=>h({...u,is_global:v})}),e.jsx(T,{htmlFor:"edit_is_global",children:"全局黑话"})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:N,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}const si="/api/webui/person";async function vk(a){const n=new URLSearchParams;a.page&&n.append("page",a.page.toString()),a.page_size&&n.append("page_size",a.page_size.toString()),a.search&&n.append("search",a.search),a.is_known!==void 0&&n.append("is_known",a.is_known.toString()),a.platform&&n.append("platform",a.platform);const r=await _e(`${si}/list?${n}`,{headers:Hs()});if(!r.ok){const c=await r.json();throw new Error(c.detail||"获取人物列表失败")}return r.json()}async function Nk(a){const n=await _e(`${si}/${a}`,{headers:Hs()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取人物详情失败")}return n.json()}async function bk(a,n){const r=await _e(`${si}/${a}`,{method:"PATCH",headers:Hs(),body:JSON.stringify(n)});if(!r.ok){const c=await r.json();throw new Error(c.detail||"更新人物信息失败")}return r.json()}async function yk(a){const n=await _e(`${si}/${a}`,{method:"DELETE",headers:Hs()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"删除人物信息失败")}return n.json()}async function wk(){const a=await _e(`${si}/stats/summary`,{headers:Hs()});if(!a.ok){const n=await a.json();throw new Error(n.detail||"获取统计数据失败")}return a.json()}async function _k(a){const n=await _e(`${si}/batch/delete`,{method:"POST",headers:Hs(),body:JSON.stringify({person_ids:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"批量删除失败")}return n.json()}function Sk(){const[a,n]=m.useState([]),[r,c]=m.useState(!0),[d,u]=m.useState(0),[h,f]=m.useState(1),[p,g]=m.useState(20),[N,v]=m.useState(""),[w,b]=m.useState(void 0),[y,O]=m.useState(void 0),[R,S]=m.useState(null),[B,E]=m.useState(!1),[C,A]=m.useState(!1),[F,L]=m.useState(null),[J,U]=m.useState({total:0,known:0,unknown:0,platforms:{}}),[oe,Ne]=m.useState(new Set),[je,re]=m.useState(!1),[fe,ge]=m.useState(""),{toast:M}=Ys(),K=async()=>{try{c(!0);const W=await vk({page:h,page_size:p,search:N||void 0,is_known:w,platform:y});n(W.data),u(W.total)}catch(W){M({title:"加载失败",description:W instanceof Error?W.message:"无法加载人物信息",variant:"destructive"})}finally{c(!1)}},P=async()=>{try{const W=await wk();W?.data&&U(W.data)}catch(W){console.error("加载统计数据失败:",W)}};m.useEffect(()=>{K(),P()},[h,p,N,w,y]);const ue=async W=>{try{const Y=await Nk(W.person_id);S(Y.data),E(!0)}catch(Y){M({title:"加载详情失败",description:Y instanceof Error?Y.message:"无法加载人物详情",variant:"destructive"})}},Q=W=>{S(W),A(!0)},Se=async W=>{try{await yk(W.person_id),M({title:"删除成功",description:`已删除人物信息: ${W.person_name||W.nickname||W.user_id}`}),L(null),K(),P()}catch(Y){M({title:"删除失败",description:Y instanceof Error?Y.message:"无法删除人物信息",variant:"destructive"})}},pe=m.useMemo(()=>Object.keys(J.platforms),[J.platforms]),Te=W=>{const Y=new Set(oe);Y.has(W)?Y.delete(W):Y.add(W),Ne(Y)},z=()=>{oe.size===a.length&&a.length>0?Ne(new Set):Ne(new Set(a.map(W=>W.person_id)))},D=()=>{if(oe.size===0){M({title:"未选择任何人物",description:"请先选择要删除的人物",variant:"destructive"});return}re(!0)},G=async()=>{try{const W=await _k(Array.from(oe));M({title:"批量删除完成",description:W.message}),Ne(new Set),re(!1),K(),P()}catch(W){M({title:"批量删除失败",description:W instanceof Error?W.message:"批量删除失败",variant:"destructive"})}},de=()=>{const W=parseInt(fe),Y=Math.ceil(d/p);W>=1&&W<=Y?(f(W),ge("")):M({title:"无效的页码",description:`请输入1-${Y}之间的页码`,variant:"destructive"})},Re=W=>W?new Date(W*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(ic,{className:"h-8 w-8",strokeWidth:2}),"人物信息管理"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"管理麦麦认识的所有人物信息"})]})})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 pr-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"总人数"}),e.jsx("div",{className:"text-2xl font-bold mt-1",children:J.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:J.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:J.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(T,{htmlFor:"search",children:"搜索"}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx(Tt,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ae,{id:"search",placeholder:"搜索名称、昵称或用户ID...",value:N,onChange:W=>v(W.target.value),className:"pl-9"})]})]}),e.jsxs("div",{children:[e.jsx(T,{htmlFor:"filter-known",children:"认识状态"}),e.jsxs(Pe,{value:w===void 0?"all":w.toString(),onValueChange:W=>{b(W==="all"?void 0:W==="true"),f(1)},children:[e.jsx($e,{id:"filter-known",className:"mt-1.5",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部"}),e.jsx(Z,{value:"true",children:"已认识"}),e.jsx(Z,{value:"false",children:"未认识"})]})]})]}),e.jsxs("div",{children:[e.jsx(T,{htmlFor:"filter-platform",children:"平台"}),e.jsxs(Pe,{value:y||"all",onValueChange:W=>{O(W==="all"?void 0:W),f(1)},children:[e.jsx($e,{id:"filter-platform",className:"mt-1.5",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部平台"}),pe.map(W=>e.jsxs(Z,{value:W,children:[W," (",J.platforms[W],")"]},W))]})]})]})]}),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:oe.size>0&&e.jsxs("span",{children:["已选择 ",oe.size," 个人物"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{htmlFor:"page-size",className:"text-sm whitespace-nowrap",children:"每页显示"}),e.jsxs(Pe,{value:p.toString(),onValueChange:W=>{g(parseInt(W)),f(1),Ne(new Set)},children:[e.jsx($e,{id:"page-size",className:"w-20",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"10",children:"10"}),e.jsx(Z,{value:"20",children:"20"}),e.jsx(Z,{value:"50",children:"50"}),e.jsx(Z,{value:"100",children:"100"})]})]}),oe.size>0&&e.jsxs(e.Fragment,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>Ne(new Set),children:"取消选择"}),e.jsxs(_,{variant:"destructive",size:"sm",onClick:D,children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"批量删除"]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border bg-card",children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:a.length>0&&oe.size===a.length,onCheckedChange:z,"aria-label":"全选"})}),e.jsx(We,{children:"状态"}),e.jsx(We,{children:"名称"}),e.jsx(We,{children:"昵称"}),e.jsx(We,{children:"平台"}),e.jsx(We,{children:"用户ID"}),e.jsx(We,{children:"最后更新"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:r?e.jsx(ut,{children:e.jsx(Ke,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):a.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):a.map(W=>e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(qs,{checked:oe.has(W.person_id),onCheckedChange:()=>Te(W.person_id),"aria-label":`选择 ${W.person_name||W.nickname||W.user_id}`})}),e.jsx(Ke,{children:e.jsx("div",{className:I("inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium",W.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:W.is_known?"已认识":"未认识"})}),e.jsx(Ke,{className:"font-medium",children:W.person_name||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ke,{children:W.nickname||"-"}),e.jsx(Ke,{children:W.platform}),e.jsx(Ke,{className:"font-mono text-sm",children:W.user_id}),e.jsx(Ke,{className:"text-sm text-muted-foreground",children:Re(W.last_know)}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(_,{variant:"default",size:"sm",onClick:()=>ue(W),children:[e.jsx(ia,{className:"h-4 w-4 mr-1"}),"详情"]}),e.jsxs(_,{variant:"default",size:"sm",onClick:()=>Q(W),children:[e.jsx(Jn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsxs(_,{size:"sm",onClick:()=>L(W),className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"删除"]})]})})]},W.id))})]})}),e.jsx("div",{className:"md:hidden space-y-3 p-4",children:r?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):a.map(W=>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(qs,{checked:oe.has(W.person_id),onCheckedChange:()=>Te(W.person_id),className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:I("inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium mb-2",W.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:W.is_known?"已认识":"未认识"}),e.jsx("h3",{className:"font-semibold text-sm line-clamp-1 w-full break-all",children:W.person_name||e.jsx("span",{className:"text-muted-foreground",children:"未命名"})}),W.nickname&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-1 w-full break-all",children:["昵称: ",W.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:W.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:W.user_id,children:W.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(W.last_know)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-2 border-t overflow-hidden",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>ue(W),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(ia,{className:"h-3 w-3 mr-1"}),"查看"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>Q(W),className:"text-xs px-2 py-1 h-auto flex-shrink-0",children:[e.jsx(Jn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>L(W),className:"text-xs px-2 py-1 h-auto flex-shrink-0 text-destructive hover:text-destructive",children:[e.jsx(ns,{className:"h-3 w-3 mr-1"}),"删除"]})]})]},W.id))}),d>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:["共 ",d," 条记录,第 ",h," / ",Math.ceil(d/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Da,{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(ae,{type:"number",value:fe,onChange:W=>ge(W.target.value),onKeyDown:W=>W.key==="Enter"&&de(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(d/p)}),e.jsx(_,{variant:"outline",size:"sm",onClick:de,disabled:!fe,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(d/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Wt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(d/p)),disabled:h>=Math.ceil(d/p),className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(kk,{person:R,open:B,onOpenChange:E}),e.jsx(Ck,{person:R,open:C,onOpenChange:A,onSuccess:()=>{K(),P(),A(!1)}}),e.jsx(Ns,{open:!!F,onOpenChange:()=>L(null),children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除人物信息 "',F?.person_name||F?.nickname||F?.user_id,'" 吗? 此操作不可撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>F&&Se(F),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"删除"})]})]})}),e.jsx(Ns,{open:je,onOpenChange:re,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认批量删除"}),e.jsxs(fs,{children:["确定要删除选中的 ",oe.size," 个人物信息吗? 此操作不可撤销。"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:G,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})})]})}function kk({person:a,open:n,onOpenChange:r}){if(!a)return null;const c=d=>d?new Date(d*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"人物详情"}),e.jsxs(Ks,{children:["查看 ",a.person_name||a.nickname||a.user_id," 的完整信息"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Rl,{icon:jn,label:"人物名称",value:a.person_name}),e.jsx(Rl,{icon:Ra,label:"昵称",value:a.nickname}),e.jsx(Rl,{icon:Jr,label:"用户ID",value:a.user_id,mono:!0}),e.jsx(Rl,{icon:Jr,label:"人物ID",value:a.person_id,mono:!0}),e.jsx(Rl,{label:"平台",value:a.platform}),e.jsx(Rl,{label:"状态",value:a.is_known?"已认识":"未认识"})]}),a.name_reason&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"名称设定原因"}),e.jsx("p",{className:"mt-1 text-sm",children:a.name_reason})]}),a.memory_points&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"个人印象"}),e.jsx("p",{className:"mt-1 text-sm whitespace-pre-wrap",children:a.memory_points})]}),a.group_nick_name&&a.group_nick_name.length>0&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"群昵称"}),e.jsx("div",{className:"mt-2 space-y-1",children:a.group_nick_name.map((d,u)=>e.jsxs("div",{className:"text-sm flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:d.group_id}),e.jsx("span",{children:"→"}),e.jsx("span",{children:d.group_nick_name})]},u))})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(Rl,{icon:na,label:"认识时间",value:c(a.know_times)}),e.jsx(Rl,{icon:na,label:"首次记录",value:c(a.know_since)}),e.jsx(Rl,{icon:na,label:"最后更新",value:c(a.last_know)})]})]}),e.jsx(st,{children:e.jsx(_,{onClick:()=>r(!1),children:"关闭"})})]})})}function Rl({icon:a,label:n,value:r,mono:c=!1}){return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[a&&e.jsx(a,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:I("text-sm",c&&"font-mono",!r&&"text-muted-foreground"),children:r||"-"})]})}function Ck({person:a,open:n,onOpenChange:r,onSuccess:c}){const[d,u]=m.useState({}),[h,f]=m.useState(!1),{toast:p}=Ys();m.useEffect(()=>{a&&u({person_name:a.person_name||"",name_reason:a.name_reason||"",nickname:a.nickname||"",is_known:a.is_known})},[a]);const g=async()=>{if(a)try{f(!0),await bk(a.person_id,d),p({title:"保存成功",description:"人物信息已更新"}),c()}catch(N){p({title:"保存失败",description:N instanceof Error?N.message:"无法更新人物信息",variant:"destructive"})}finally{f(!1)}};return a?e.jsx(Ps,{open:n,onOpenChange:r,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑人物信息"}),e.jsxs(Ks,{children:["修改 ",a.person_name||a.nickname||a.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(T,{htmlFor:"person_name",children:"人物名称"}),e.jsx(ae,{id:"person_name",value:d.person_name||"",onChange:N=>u({...d,person_name:N.target.value}),placeholder:"为这个人设置一个名称"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"nickname",children:"昵称"}),e.jsx(ae,{id:"nickname",value:d.nickname||"",onChange:N=>u({...d,nickname:N.target.value}),placeholder:"昵称"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"name_reason",children:"名称设定原因"}),e.jsx(ot,{id:"name_reason",value:d.name_reason||"",onChange:N=>u({...d,name_reason:N.target.value}),placeholder:"为什么这样称呼这个人?",rows:2})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{children:[e.jsx(T,{htmlFor:"is_known",className:"text-base font-medium",children:"已认识"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"标记是否已经认识这个人"})]}),e.jsx(Ve,{id:"is_known",checked:d.is_known,onCheckedChange:N=>u({...d,is_known:N})})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>r(!1),children:"取消"}),e.jsx(_,{onClick:g,disabled:h,children:h?"保存中...":"保存"})]})]})}):null}var Tk=j1();const Yg=lw(Tk),yx="/api/webui";async function Ek(a=100,n="all"){const r=`${yx}/knowledge/graph?limit=${a}&node_type=${n}`,c=await fetch(r);if(!c.ok)throw new Error(`获取知识图谱失败: ${c.status}`);return c.json()}async function Mk(){const a=await fetch(`${yx}/knowledge/stats`);if(!a.ok)throw new Error("获取知识图谱统计信息失败");return a.json()}async function Ak(a){const n=await fetch(`${yx}/knowledge/search?query=${encodeURIComponent(a)}`);if(!n.ok)throw new Error("搜索知识节点失败");return n.json()}const sN=m.memo(({data:a})=>e.jsxs("div",{className:"px-4 py-2 shadow-md rounded-lg bg-gradient-to-br from-blue-500 to-blue-600 border-2 border-blue-700 min-w-[120px]",children:[e.jsx(Ko,{type:"target",position:Qo.Top}),e.jsx("div",{className:"font-semibold text-white text-sm truncate max-w-[200px]",title:a.content,children:a.label}),e.jsx(Ko,{type:"source",position:Qo.Bottom})]}));sN.displayName="EntityNode";const tN=m.memo(({data:a})=>e.jsxs("div",{className:"px-3 py-2 shadow-md rounded-md bg-gradient-to-br from-green-500 to-green-600 border-2 border-green-700 min-w-[100px]",children:[e.jsx(Ko,{type:"target",position:Qo.Top}),e.jsx("div",{className:"font-medium text-white text-xs truncate max-w-[150px]",title:a.content,children:a.label}),e.jsx(Ko,{type:"source",position:Qo.Bottom})]}));tN.displayName="ParagraphNode";const zk={entity:sN,paragraph:tN};function Rk(a,n){const r=new Yg.graphlib.Graph;r.setDefaultEdgeLabel(()=>({})),r.setGraph({rankdir:"TB",ranksep:100,nodesep:80});const c=[],d=[];return a.forEach(u=>{r.setNode(u.id,{width:150,height:50})}),n.forEach(u=>{r.setEdge(u.source,u.target)}),Yg.layout(r),a.forEach(u=>{const h=r.node(u.id);c.push({id:u.id,type:u.type,position:{x:h.x-75,y:h.y-25},data:{label:u.content.slice(0,20)+(u.content.length>20?"...":""),content:u.content}})}),n.forEach((u,h)=>{const f={id:`edge-${h}`,source:u.source,target:u.target,animated:a.length<=200&&u.weight>5,style:{strokeWidth:Math.min(u.weight/2,5),opacity:.6}};u.weight>10&&a.length<100&&(f.label=`${u.weight.toFixed(0)}`),d.push(f)}),{nodes:c,edges:d}}function Dk(){const a=ca(),[n,r]=m.useState(!1),[c,d]=m.useState(null),[u,h]=m.useState(""),[f,p]=m.useState("all"),[g,N]=m.useState(50),[v,w]=m.useState("50"),[b,y]=m.useState(!1),[O,R]=m.useState(!0),[S,B]=m.useState(!1),[E,C]=m.useState(!1),[A,F,L]=v1([]),[J,U,oe]=N1([]),[Ne,je]=m.useState(0),[re,fe]=m.useState(null),[ge,M]=m.useState(null),{toast:K}=Ys(),P=m.useCallback(G=>G.type==="entity"?"#6366f1":G.type==="paragraph"?"#10b981":"#6b7280",[]),ue=m.useCallback(async(G=!1)=>{try{if(!G&&g>200){C(!0);return}r(!0);const[de,Re]=await Promise.all([Ek(g,f),Mk()]);if(d(Re),de.nodes.length===0){K({title:"提示",description:"知识库为空,请先导入知识数据"}),F([]),U([]);return}const{nodes:W,edges:Y}=Rk(de.nodes,de.edges);F(W),U(Y),je(W.length),Re&&Re.total_nodes>g&&K({title:"提示",description:`知识图谱包含 ${Re.total_nodes} 个节点,当前显示 ${W.length} 个`}),K({title:"加载成功",description:`已加载 ${W.length} 个节点,${Y.length} 条边`})}catch(de){console.error("加载知识图谱失败:",de),K({title:"加载失败",description:de instanceof Error?de.message:"未知错误",variant:"destructive"})}finally{r(!1)}},[g,f,K]),Q=m.useCallback(async()=>{if(!u.trim()){K({title:"提示",description:"请输入搜索关键词"});return}try{const G=await Ak(u);if(G.length===0){K({title:"未找到",description:"没有找到匹配的节点"});return}const de=new Set(G.map(Re=>Re.id));F(Re=>Re.map(W=>({...W,style:{...W.style,opacity:de.has(W.id)?1:.3,filter:de.has(W.id)?"brightness(1.2)":"brightness(0.8)"}}))),K({title:"搜索完成",description:`找到 ${G.length} 个匹配节点`})}catch(G){console.error("搜索失败:",G),K({title:"搜索失败",description:G instanceof Error?G.message:"未知错误",variant:"destructive"})}},[u,K]),Se=m.useCallback(()=>{F(G=>G.map(de=>({...de,style:{...de.style,opacity:1,filter:"brightness(1)"}})))},[]),pe=m.useCallback(()=>{R(!1),B(!0),ue()},[ue]),Te=m.useCallback(()=>{C(!1),setTimeout(()=>{ue(!0)},0)},[ue]),z=m.useCallback((G,de)=>{A.find(W=>W.id===de.id)&&fe({id:de.id,type:de.type,content:de.data.content})},[A]);m.useEffect(()=>{O||S&&ue()},[g,f,O,S]);const D=m.useCallback((G,de)=>{const Re=A.find(Fe=>Fe.id===de.source),W=A.find(Fe=>Fe.id===de.target),Y=J.find(Fe=>Fe.id===de.id);Re&&W&&Y&&M({source:{id:Re.id,type:Re.type,content:Re.data.content},target:{id:W.id,type:W.type,content:W.data.content},edge:{source:de.source,target:de.target,weight:parseFloat(de.label||"0")}})},[A,J]);return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex-shrink-0 p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"麦麦知识库图谱"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"可视化知识实体与关系网络"})]}),c&&e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(Yr,{className:"h-3 w-3"}),"节点: ",c.total_nodes]}),e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(rv,{className:"h-3 w-3"}),"边: ",c.total_edges]}),e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(Ft,{className:"h-3 w-3"}),"实体: ",c.entity_nodes]}),e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(Ea,{className:"h-3 w-3"}),"段落: ",c.paragraph_nodes]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 mt-4",children:[e.jsxs("div",{className:"flex-1 flex gap-2",children:[e.jsx(ae,{placeholder:"搜索节点内容...",value:u,onChange:G=>h(G.target.value),onKeyDown:G=>G.key==="Enter"&&Q(),className:"flex-1"}),e.jsx(_,{onClick:Q,size:"sm",children:e.jsx(Tt,{className:"h-4 w-4"})}),e.jsx(_,{onClick:Se,variant:"outline",size:"sm",children:"重置"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Pe,{value:f,onValueChange:G=>p(G),children:[e.jsx($e,{className:"w-[120px]",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部节点"}),e.jsx(Z,{value:"entity",children:"仅实体"}),e.jsx(Z,{value:"paragraph",children:"仅段落"})]})]}),e.jsxs(Pe,{value:g===1e4?"all":b?"custom":g.toString(),onValueChange:G=>{G==="custom"?(y(!0),w(g.toString())):G==="all"?(y(!1),N(1e4)):(y(!1),N(Number(G)))},children:[e.jsx($e,{className:"w-[120px]",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"50",children:"50 节点"}),e.jsx(Z,{value:"100",children:"100 节点"}),e.jsx(Z,{value:"200",children:"200 节点"}),e.jsx(Z,{value:"500",children:"500 节点"}),e.jsx(Z,{value:"1000",children:"1000 节点"}),e.jsx(Z,{value:"all",children:"全部 (最多10000)"}),e.jsx(Z,{value:"custom",children:"自定义..."})]})]}),b&&e.jsx(ae,{type:"number",min:"50",value:v,onChange:G=>w(G.target.value),onBlur:()=>{const G=parseInt(v);!isNaN(G)&&G>=50?N(G):(w("50"),N(50))},onKeyDown:G=>{if(G.key==="Enter"){const de=parseInt(v);!isNaN(de)&&de>=50?N(de):(w("50"),N(50))}},placeholder:"最少50个",className:"w-[120px]"}),e.jsx(_,{onClick:()=>ue(),variant:"outline",size:"sm",disabled:n,children:e.jsx(dt,{className:I("h-4 w-4",n&&"animate-spin")})})]})]})]}),e.jsx("div",{className:"flex-1 relative",children:n?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(dt,{className:"h-8 w-8 animate-spin mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"加载知识图谱中..."})]})}):A.length===0?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Yr,{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(b1,{nodes:A,edges:J,onNodesChange:L,onEdgesChange:oe,onNodeClick:z,onEdgeClick:D,nodeTypes:zk,fitView:!0,minZoom:.05,maxZoom:1.5,defaultViewport:{x:0,y:0,zoom:.5},elevateNodesOnSelect:Ne<=500,nodesDraggable:Ne<=1e3,attributionPosition:"bottom-left",children:[e.jsx(y1,{variant:w1.Dots,gap:12,size:1}),e.jsx(_1,{}),Ne<=500&&e.jsx(S1,{nodeColor:P,nodeBorderRadius:8,pannable:!0,zoomable:!0}),e.jsxs(k1,{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:"段落节点"})]}),Ne>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:"已禁用动画"}),Ne>500&&e.jsx("div",{children:"已禁用缩略图"})]})]})]})]})}),e.jsx(Ps,{open:!!re,onOpenChange:G=>!G&&fe(null),children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(Os,{children:e.jsx(Ls,{children:"节点详情"})}),re&&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(ke,{variant:re.type==="entity"?"default":"secondary",children:re.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:re.id})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-muted-foreground",children:"内容"}),e.jsx(Je,{className:"mt-1 h-40 p-3 bg-muted rounded",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:re.content})})]})]})]})}),e.jsx(Ps,{open:!!ge,onOpenChange:G=>!G&&M(null),children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsx(Os,{children:e.jsx(Ls,{children:"边详情"})}),ge&&e.jsx(Je,{className:"flex-1 pr-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0 p-3 bg-blue-50 dark:bg-blue-950 rounded border-2 border-blue-200 dark:border-blue-800",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"源节点"}),e.jsx("div",{className:"font-medium text-sm mb-2 truncate",children:ge.source.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[ge.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:ge.target.content}),e.jsxs("code",{className:"text-xs text-muted-foreground truncate block",children:[ge.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(ke,{variant:"outline",className:"text-base font-mono",children:ge.edge.weight.toFixed(4)})})]})]})})]})}),e.jsx(Ns,{open:O,onOpenChange:R,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"加载知识图谱"}),e.jsxs(fs,{children:["知识图谱的动态展示会消耗较多系统资源。",e.jsx("br",{}),"确定要加载知识图谱吗?"]})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:()=>a({to:"/"}),children:"取消 (返回首页)"}),e.jsx(ps,{onClick:pe,children:"确认加载"})]})]})}),e.jsx(Ns,{open:E,onOpenChange:C,children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"⚠️ 节点数量较多"}),e.jsx(fs,{asChild:!0,children:e.jsxs("div",{children:[e.jsxs("p",{children:["您正在尝试加载 ",e.jsx("strong",{className:"text-orange-600",children:g>=1e4?"全部 (最多10000个)":g})," 个节点。"]}),e.jsx("p",{className:"mt-4",children:"节点数量过多可能导致:"}),e.jsxs("ul",{className:"list-disc list-inside mt-2 space-y-1",children:[e.jsx("li",{children:"页面加载时间较长"}),e.jsx("li",{children:"浏览器卡顿或崩溃"}),e.jsx("li",{children:"系统资源占用过高"})]}),e.jsx("p",{className:"mt-4",children:"建议先选择较少的节点数量 (50-200 个)。"})]})})]}),e.jsxs(xs,{children:[e.jsx(gs,{onClick:()=>{C(!1),g>200&&(N(50),y(!1))},children:"取消"}),e.jsx(ps,{onClick:Te,className:"bg-orange-600 hover:bg-orange-700",children:"我了解风险,继续加载"})]})]})})]})}function Ok(){return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsx("div",{className:"flex-none border-b bg-card/50 px-6 py-4",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"麦麦知识库管理"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"管理和组织麦麦的知识库内容"})]})})}),e.jsx("div",{className:"flex-1 overflow-auto p-6",children:e.jsx("div",{className:"mx-auto max-w-4xl",children:e.jsxs(Ce,{children:[e.jsxs(De,{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-20 w-20 items-center justify-center rounded-full bg-primary/10",children:e.jsx(Yr,{className:"h-10 w-10 text-primary"})}),e.jsx(Oe,{className:"text-2xl",children:"麦麦知识库管理"}),e.jsx(os,{className:"text-base",children:"功能开发中,敬请期待"})]}),e.jsx(Me,{className:"text-center text-sm text-muted-foreground",children:e.jsx("p",{children:"此功能将提供知识库的创建、编辑、导入和管理能力"})})]})})})]})}function Jg({className:a,classNames:n,showOutsideDays:r=!0,captionLayout:c="label",buttonVariant:d="ghost",formatters:u,components:h,...f}){const p=yv();return e.jsx(u1,{showOutsideDays:r,className:I("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`,a),captionLayout:c,formatters:{formatMonthDropdown:g=>g.toLocaleString("default",{month:"short"}),...u},classNames:{root:I("w-fit",p.root),months:I("relative flex flex-col gap-4 md:flex-row",p.months),month:I("flex w-full flex-col gap-4",p.month),nav:I("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",p.nav),button_previous:I(Zr({variant:d}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",p.button_previous),button_next:I(Zr({variant:d}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",p.button_next),month_caption:I("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",p.month_caption),dropdowns:I("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",p.dropdowns),dropdown_root:I("has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border",p.dropdown_root),dropdown:I("bg-popover absolute inset-0 opacity-0",p.dropdown),caption_label:I("select-none font-medium",c==="label"?"text-sm":"[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5",p.caption_label),table:"w-full border-collapse",weekdays:I("flex",p.weekdays),weekday:I("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",p.weekday),week:I("mt-2 flex w-full",p.week),week_number_header:I("w-[--cell-size] select-none",p.week_number_header),week_number:I("text-muted-foreground select-none text-[0.8rem]",p.week_number),day:I("group/day relative aspect-square h-full w-full select-none p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md",p.day),range_start:I("bg-accent rounded-l-md",p.range_start),range_middle:I("rounded-none",p.range_middle),range_end:I("bg-accent rounded-r-md",p.range_end),today:I("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",p.today),outside:I("text-muted-foreground aria-selected:text-muted-foreground",p.outside),disabled:I("text-muted-foreground opacity-50",p.disabled),hidden:I("invisible",p.hidden),...n},components:{Root:({className:g,rootRef:N,...v})=>e.jsx("div",{"data-slot":"calendar",ref:N,className:I(g),...v}),Chevron:({className:g,orientation:N,...v})=>N==="left"?e.jsx(Da,{className:I("size-4",g),...v}):N==="right"?e.jsx(Wt,{className:I("size-4",g),...v}):e.jsx(za,{className:I("size-4",g),...v}),DayButton:Lk,WeekNumber:({children:g,...N})=>e.jsx("td",{...N,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:g})}),...h},...f})}function Lk({className:a,day:n,modifiers:r,...c}){const d=yv(),u=m.useRef(null);return m.useEffect(()=>{r.focused&&u.current?.focus()},[r.focused]),e.jsx(_,{ref:u,variant:"ghost",size:"icon","data-day":n.date.toLocaleDateString(),"data-selected-single":r.selected&&!r.range_start&&!r.range_end&&!r.range_middle,"data-range-start":r.range_start,"data-range-end":r.range_end,"data-range-middle":r.range_middle,className:I("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",d.day,a),...c})}const Oo={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 Uk(){const[a,n]=m.useState([]),[r,c]=m.useState(""),[d,u]=m.useState("all"),[h,f]=m.useState("all"),[p,g]=m.useState(void 0),[N,v]=m.useState(void 0),[w,b]=m.useState(!0),[y,O]=m.useState(!1),[R,S]=m.useState("xs"),[B,E]=m.useState(4),[C,A]=m.useState(!1),F=m.useRef(null);m.useEffect(()=>{const Q=Hn.getAllLogs();n(Q);const Se=Hn.onLog(()=>{n(Hn.getAllLogs())}),pe=Hn.onConnectionChange(Te=>{O(Te)});return()=>{Se(),pe()}},[]);const L=m.useMemo(()=>{const Q=new Set(a.map(Se=>Se.module).filter(Se=>Se&&Se.trim()!==""));return Array.from(Q).sort()},[a]),J=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"}},U=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"}},oe=()=>{window.location.reload()},Ne=()=>{Hn.clearLogs(),n([])},je=()=>{const Q=ge.map(z=>`${z.timestamp} [${z.level.padEnd(8)}] [${z.module}] ${z.message}`).join(` -`),Se=new Blob([Q],{type:"text/plain;charset=utf-8"}),pe=URL.createObjectURL(Se),Te=document.createElement("a");Te.href=pe,Te.download=`logs-${Tm(new Date,"yyyy-MM-dd-HHmmss")}.txt`,Te.click(),URL.revokeObjectURL(pe)},re=()=>{b(!w)},fe=()=>{g(void 0),v(void 0)},ge=m.useMemo(()=>a.filter(Q=>{const Se=r===""||Q.message.toLowerCase().includes(r.toLowerCase())||Q.module.toLowerCase().includes(r.toLowerCase()),pe=d==="all"||Q.level===d,Te=h==="all"||Q.module===h;let z=!0;if(p||N){const D=new Date(Q.timestamp);if(p){const G=new Date(p);G.setHours(0,0,0,0),z=z&&D>=G}if(N){const G=new Date(N);G.setHours(23,59,59,999),z=z&&D<=G}}return Se&&pe&&Te&&z}),[a,r,d,h,p,N]),M=Oo[R].rowHeight+B,K=Y0({count:ge.length,getScrollElement:()=>F.current,estimateSize:()=>M,overscan:50}),P=m.useRef(!1),ue=m.useRef(ge.length);return m.useEffect(()=>{const Q=F.current;if(!Q)return;const Se=()=>{if(P.current)return;const{scrollTop:pe,scrollHeight:Te,clientHeight:z}=Q,D=Te-pe-z;D>100&&w?b(!1):D<50&&!w&&b(!0)};return Q.addEventListener("scroll",Se,{passive:!0}),()=>Q.removeEventListener("scroll",Se)},[w]),m.useEffect(()=>{const Q=ge.length>ue.current;ue.current=ge.length,w&&ge.length>0&&Q&&(P.current=!0,K.scrollToIndex(ge.length-1,{align:"end",behavior:"auto"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{P.current=!1})}))},[ge.length,w,K]),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-shrink-0 space-y-2 sm:space-y-3 p-2 sm:p-3 lg:p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg sm:text-xl lg:text-2xl font-bold",children:"日志查看器"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 hidden sm:block",children:"实时查看和分析麦麦运行日志"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:I("h-2 w-2 sm:h-2.5 sm:w-2.5 rounded-full",y?"bg-green-500 animate-pulse":"bg-red-500")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:y?"已连接":"未连接"})]})]}),e.jsx(Ce,{className:"p-2 sm:p-3",children:e.jsx(uc,{open:C,onOpenChange:A,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 relative min-w-0",children:[e.jsx(Tt,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(ae,{placeholder:"搜索日志...",value:r,onChange:Q=>c(Q.target.value),className:"pl-8 h-8 text-xs sm:text-sm"})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs(_,{variant:w?"default":"outline",size:"sm",onClick:re,className:"h-8 px-2",title:w?"自动滚动":"已暂停",children:[w?e.jsx(D_,{className:"h-3.5 w-3.5"}):e.jsx(O_,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden sm:inline",children:w?"滚动":"暂停"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:Ne,className:"h-8 px-2",title:"清空日志",children:[e.jsx(ns,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden md:inline",children:"清空"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:je,className:"h-8 px-2 hidden sm:flex",title:"导出日志",children:[e.jsx(Xt,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden lg:inline",children:"导出"})]}),e.jsx(mc,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"h-8 px-2",title:C?"收起筛选":"展开筛选",children:[e.jsx(Bo,{className:"h-3.5 w-3.5"}),C?e.jsx(Qr,{className:"h-3.5 w-3.5 ml-1"}):e.jsx(za,{className:"h-3.5 w-3.5 ml-1"})]})})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground text-center sm:text-right -mt-1",children:[e.jsxs("span",{className:"font-mono",children:[ge.length," / ",a.length]}),e.jsx("span",{className:"ml-1",children:"条日志"})]}),e.jsxs(xc,{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(Pe,{value:d,onValueChange:u,children:[e.jsxs($e,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(Bo,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Ie,{placeholder:"级别"})]}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部级别"}),e.jsx(Z,{value:"DEBUG",children:"DEBUG"}),e.jsx(Z,{value:"INFO",children:"INFO"}),e.jsx(Z,{value:"WARNING",children:"WARNING"}),e.jsx(Z,{value:"ERROR",children:"ERROR"}),e.jsx(Z,{value:"CRITICAL",children:"CRITICAL"})]})]}),e.jsxs(Pe,{value:h,onValueChange:f,children:[e.jsxs($e,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(Bo,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Ie,{placeholder:"模块"})]}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部模块"}),L.map(Q=>e.jsx(Z,{value:Q,children:Q},Q))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:I("w-full sm:flex-1 justify-start text-left font-normal h-8",!p&&"text-muted-foreground"),children:[e.jsx(Go,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:p?Tm(p,"PP",{locale:Ro}):"开始日期"})]})}),e.jsx(sl,{className:"w-auto p-0",align:"start",children:e.jsx(Jg,{mode:"single",selected:p,onSelect:g,initialFocus:!0,locale:Ro})})]}),e.jsxs(ul,{children:[e.jsx(ml,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:I("w-full sm:flex-1 justify-start text-left font-normal h-8",!N&&"text-muted-foreground"),children:[e.jsx(Go,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:N?Tm(N,"PP",{locale:Ro}):"结束日期"})]})}),e.jsx(sl,{className:"w-auto p-0",align:"start",children:e.jsx(Jg,{mode:"single",selected:N,onSelect:v,initialFocus:!0,locale:Ro})})]}),(p||N)&&e.jsxs(_,{variant:"outline",size:"sm",onClick:fe,className:"w-full sm:w-auto h-8",children:[e.jsx(Aa,{className:"h-3.5 w-3.5 sm:mr-1"}),e.jsx("span",{className:"text-xs",children:"清除"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(L_,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"字号"})]}),e.jsx("div",{className:"flex gap-1",children:Object.keys(Oo).map(Q=>e.jsx(_,{variant:R===Q?"default":"outline",size:"sm",onClick:()=>S(Q),className:"h-6 px-2 text-xs",children:Oo[Q].label},Q))})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-1 max-w-[200px]",children:[e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:"行距"}),e.jsx(Qa,{value:[B],onValueChange:([Q])=>E(Q),min:0,max:12,step:2,className:"flex-1"}),e.jsxs("span",{className:"text-xs text-muted-foreground w-7",children:[B,"px"]})]}),e.jsxs("div",{className:"flex gap-2 sm:hidden",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:oe,className:"flex-1 h-8",children:[e.jsx(dt,{className:"h-3.5 w-3.5 mr-1"}),e.jsx("span",{className:"text-xs",children:"刷新"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:je,className:"flex-1 h-8",children:[e.jsx(Xt,{className:"h-3.5 w-3.5 mr-1"}),e.jsx("span",{className:"text-xs",children:"导出"})]})]})]})]})]})})})]}),e.jsx("div",{className:"flex-1 min-h-0 px-2 sm:px-3 lg:px-4 pb-2 sm:pb-3 lg:pb-4",children:e.jsx(Ce,{className:"bg-black dark:bg-gray-950 border-gray-800 dark:border-gray-900 h-full overflow-hidden",children:e.jsx("div",{ref:F,className:I("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:I("p-2 sm:p-3 font-mono relative",Oo[R].class),style:{height:`${K.getTotalSize()}px`},children:ge.length===0?e.jsx("div",{className:"text-gray-500 dark:text-gray-600 text-center py-8 text-xs sm:text-sm",children:"暂无日志数据"}):K.getVirtualItems().map(Q=>{const Se=ge[Q.index];return e.jsxs("div",{"data-index":Q.index,ref:K.measureElement,className:I("absolute top-0 left-0 w-full px-2 sm:px-3 rounded hover:bg-white/5 transition-colors",U(Se.level)),style:{transform:`translateY(${Q.start}px)`,paddingTop:`${B/2}px`,paddingBottom:`${B/2}px`},children:[e.jsxs("div",{className:"flex flex-col gap-0.5 sm:hidden",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-600 text-[10px]",children:Se.timestamp}),e.jsxs("span",{className:I("font-semibold text-[10px]",J(Se.level)),children:["[",Se.level,"]"]})]}),e.jsx("div",{className:"text-cyan-400 dark:text-cyan-500 truncate text-[10px]",children:Se.module}),e.jsx("div",{className:"text-gray-300 dark:text-gray-400 whitespace-pre-wrap break-words text-[10px]",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:I("flex-shrink-0 w-[65px] lg:w-[75px] font-semibold",J(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)})})})})})]})}async function $k(){return(await _e("/api/planner/overview")).json()}async function Bk(a,n=1,r=20,c){const d=new URLSearchParams({page:n.toString(),page_size:r.toString()});return c&&d.append("search",c),(await _e(`/api/planner/chat/${a}/logs?${d}`)).json()}async function Pk(a,n){return(await _e(`/api/planner/log/${a}/${n}`)).json()}async function Ik(){return(await _e("/api/replier/overview")).json()}async function Fk(a,n=1,r=20,c){const d=new URLSearchParams({page:n.toString(),page_size:r.toString()});return c&&d.append("search",c),(await _e(`/api/replier/chat/${a}/logs?${d}`)).json()}async function Hk(a,n){return(await _e(`/api/replier/log/${a}/${n}`)).json()}function aN(){const[a,n]=m.useState(new Map),[r,c]=m.useState(!0),d=m.useCallback(async()=>{try{c(!0);const h=await ux();if(h?.data){const f=new Map;h.data.forEach(p=>{f.set(p.chat_id,p.chat_name)}),n(f)}}catch(h){console.error("加载聊天列表失败:",h)}finally{c(!1)}},[]);m.useEffect(()=>{d()},[d]);const u=m.useCallback(h=>a.get(h)||h,[a]);return{chatNameMap:a,getChatName:u,loading:r,reload:d}}function Jo(a){return new Date(a*1e3).toLocaleString("zh-CN")}function lN(a){const r=Date.now()/1e3-a;return r<60?"刚刚":r<3600?`${Math.floor(r/60)} 分钟前`:r<86400?`${Math.floor(r/3600)} 小时前`:`${Math.floor(r/86400)} 天前`}function nN(a,n,r=1e4){m.useEffect(()=>{if(!a)return;const c=setInterval(n,r);return()=>clearInterval(c)},[a,n,r])}function Vk({autoRefresh:a,refreshKey:n}){const[r,c]=m.useState("overview"),[d,u]=m.useState(null),{getChatName:h}=aN(),[f,p]=m.useState(null),[g,N]=m.useState(!0),[v,w]=m.useState(null),[b,y]=m.useState(!1),[O,R]=m.useState(1),[S,B]=m.useState(20),[E,C]=m.useState(""),[A,F]=m.useState(""),[L,J]=m.useState(""),[U,oe]=m.useState(null),[Ne,je]=m.useState(!1),[re,fe]=m.useState(!1),ge=m.useCallback(async()=>{try{N(!0);const D=await $k();p(D)}catch(D){console.error("加载规划器总览失败:",D)}finally{N(!1)}},[]),M=m.useCallback(async()=>{if(d)try{y(!0);const D=await Bk(d.chat_id,O,S,A||void 0);w(D)}catch(D){console.error("加载聊天日志失败:",D)}finally{y(!1)}},[d,O,S,A]);m.useEffect(()=>{ge()},[ge]),m.useEffect(()=>{n>0&&(r==="overview"?ge():M())},[n,r,ge,M]),m.useEffect(()=>{r==="chat-logs"&&d&&M()},[r,d,M]),nN(a,m.useCallback(()=>{r==="overview"?ge():M()},[r,ge,M]));const K=D=>{u(D),R(1),F(""),J(""),c("chat-logs")},P=()=>{c("overview"),u(null),w(null),F(""),J("")},ue=()=>{F(L),R(1)},Q=()=>{J(""),F(""),R(1)},Se=async(D,G)=>{try{fe(!0),je(!0);const de=await Pk(D,G);oe(de)}catch(de){console.error("加载计划详情失败:",de)}finally{fe(!1)}},pe=D=>{B(Number(D)),R(1)},Te=()=>{const D=parseInt(E),G=v?Math.ceil(v.total/v.page_size):0;!isNaN(D)&&D>=1&&D<=G&&(R(D),C(""))},z=v?Math.ceil(v.total/v.page_size):0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:r==="overview"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"聊天数量"}),e.jsx(Ra,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Me,{children:g?e.jsx(vs,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_chats||0})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"计划总数"}),e.jsx(tx,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Me,{children:g?e.jsx(vs,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_plans||0})})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"聊天列表"}),e.jsx(os,{children:"点击查看该聊天的所有计划记录"})]}),e.jsx(Me,{children:g?e.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:[...Array(6)].map((D,G)=>e.jsx(vs,{className:"h-24 w-full"},G))}):f?.chats&&f.chats.length>0?e.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:f.chats.map(D=>e.jsxs("div",{className:"border rounded-lg p-4 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>K(D),children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ra,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm truncate max-w-[180px]",title:h(D.chat_id),children:h(D.chat_id)})]}),e.jsx(ke,{variant:"secondary",children:D.plan_count})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["最后活动: ",lN(D.latest_timestamp)]})]},D.chat_id))}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无聊天记录"})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-4 mb-4",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:P,children:[e.jsx(Ma,{className:"h-4 w-4 mr-2"}),"返回聊天列表"]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["当前聊天: ",e.jsx("span",{className:"font-medium",children:d?h(d.chat_id):""}),e.jsx("span",{className:"mx-2",children:"•"}),"共 ",v?.total||0," 条计划记录"]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(Oe,{children:"计划执行记录"}),e.jsx(os,{children:d?h(d.chat_id):""})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ae,{placeholder:"搜索提示词内容...",value:L,onChange:D=>J(D.target.value),onKeyDown:D=>D.key==="Enter"&&ue(),className:"w-full sm:w-48"}),e.jsx(_,{variant:"outline",size:"icon",onClick:ue,children:e.jsx(Tt,{className:"h-4 w-4"})}),A&&e.jsx(_,{variant:"ghost",size:"sm",onClick:Q,children:"清除"})]}),e.jsxs(Pe,{value:S.toString(),onValueChange:pe,children:[e.jsx($e,{className:"w-full sm:w-32",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"10",children:"10条/页"}),e.jsx(Z,{value:"20",children:"20条/页"}),e.jsx(Z,{value:"50",children:"50条/页"}),e.jsx(Z,{value:"100",children:"100条/页"})]})]})]})]}),A&&e.jsxs("div",{className:"text-sm text-muted-foreground mt-2",children:["搜索关键词: ",e.jsxs("span",{className:"font-medium",children:['"',A,'"']})]})]}),e.jsx(Me,{children:b?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((D,G)=>e.jsx(vs,{className:"h-20 w-full"},G))}):v?.data&&v.data.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-2",children:v.data.map(D=>e.jsxs("div",{className:"border rounded-lg p-3 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>Se(D.chat_id,D.filename),children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:Jo(D.timestamp)}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs(ke,{variant:"secondary",className:"text-xs",children:[D.action_count," 个动作"]}),e.jsxs(ke,{variant:"outline",className:"text-xs",children:[D.total_plan_ms.toFixed(0),"ms"]})]})]}),D.action_types&&D.action_types.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:D.action_types.map((G,de)=>e.jsx(ke,{variant:"outline",className:"text-xs bg-blue-50 dark:bg-blue-950 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-800",children:G},de))}),e.jsx("p",{className:"text-sm line-clamp-2",children:D.reasoning_preview||"无推理内容"})]},D.filename))}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-3 mt-4 pt-4 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",v.total," 条记录,第 ",O," / ",z," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>R(1),disabled:O===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>R(D=>Math.max(1,D-1)),disabled:O===1,children:e.jsx(Da,{className:"h-4 w-4"})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2",children:[e.jsx(ae,{type:"number",min:1,max:z,value:E,onChange:D=>C(D.target.value),onKeyDown:D=>D.key==="Enter"&&Te(),placeholder:"跳转",className:"w-20 h-8"}),e.jsx(_,{size:"sm",variant:"outline",onClick:Te,children:"跳转"})]}),e.jsxs("span",{className:"sm:hidden text-sm text-muted-foreground",children:[O,"/",z]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>R(D=>Math.min(z,D+1)),disabled:O===z,children:e.jsx(Wt,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>R(z),disabled:O===z,className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无计划记录"})})]})]})}),e.jsx(Ps,{open:Ne,onOpenChange:je,children:e.jsxs(Ds,{className:"max-w-4xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(Ea,{className:"h-5 w-5"}),"计划执行详情"]}),e.jsx(Ks,{children:"查看麦麦的详细计划推理过程和执行动作"})]}),e.jsx(Je,{className:"h-full pr-4",children:e.jsx("div",{className:"space-y-6 pb-4",children:re?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((D,G)=>e.jsx(vs,{className:"h-24 w-full"},G))}):U?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(na,{className:"h-4 w-4"}),"基本信息"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 p-4 bg-muted/50 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"聊天"}),e.jsx("div",{className:"text-sm",title:U.chat_id,children:h(U.chat_id)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"时间戳"}),e.jsx("div",{className:"text-sm",children:Jo(U.timestamp)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"类型"}),e.jsx(ke,{variant:"outline",children:U.type})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"动作数量"}),e.jsxs(ke,{children:[U.actions.length," 个动作"]})]})]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(el,{className:"h-4 w-4"}),"性能统计"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"提示词构建"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[U.timing.prompt_build_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"LLM 推理"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[U.timing.llm_duration_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"总计划时间"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[U.timing.total_plan_ms?.toFixed(2)||0,"ms"]})})]})]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(cx,{className:"h-4 w-4"}),"推理过程"]}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:U.reasoning||"无推理内容"})})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(U_,{className:"h-4 w-4"}),"执行动作 (",U.actions.length,")"]}),e.jsx("div",{className:"space-y-3",children:U.actions.map((D,G)=>e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-3",children:e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ke,{variant:"default",children:["动作 ",G+1]}),e.jsx(ke,{variant:"outline",children:D.action_type})]})})}),e.jsxs(Me,{className:"p-4 pt-0 space-y-3",children:[D.reasoning&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"推理依据"}),e.jsx("p",{className:"text-sm bg-muted/30 p-2 rounded",children:typeof D.reasoning=="string"?D.reasoning:JSON.stringify(D.reasoning)})]}),D.action_message&&e.jsxs("div",{className:"overflow-hidden",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"动作消息"}),typeof D.action_message=="string"?e.jsx("p",{className:"text-sm bg-muted/30 p-2 rounded break-all whitespace-pre-wrap",children:D.action_message}):e.jsx("pre",{className:"text-xs bg-muted/30 p-2 rounded overflow-x-auto whitespace-pre-wrap break-all",children:JSON.stringify(D.action_message,null,2)})]}),D.action_data&&Object.keys(D.action_data).length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"动作数据"}),e.jsx("pre",{className:"text-xs bg-muted/30 p-2 rounded overflow-x-auto",children:JSON.stringify(D.action_data,null,2)})]}),D.action_reasoning&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"动作推理"}),e.jsx("p",{className:"text-sm bg-muted/30 p-2 rounded",children:typeof D.action_reasoning=="string"?D.action_reasoning:JSON.stringify(D.action_reasoning)})]})]})]},G))})]}),e.jsx(Yt,{}),U.raw_output&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"原始输出"}),e.jsxs("details",{className:"group",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-muted-foreground hover:text-foreground",children:"点击展开查看完整原始输出"}),e.jsx("div",{className:"mt-2 p-4 bg-muted/50 rounded-lg",children:e.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:U.raw_output})})]})]}),U.prompt&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"完整提示词"}),e.jsxs("details",{className:"group",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-muted-foreground hover:text-foreground",children:"点击展开查看完整提示词"}),e.jsx("div",{className:"mt-2 p-4 bg-muted/50 rounded-lg",children:e.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:U.prompt})})]})]})]}):e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"无数据"})})})}),e.jsx(st,{className:"flex-shrink-0",children:e.jsx(_,{onClick:()=>je(!1),children:"关闭"})})]})})]})}function Gk({autoRefresh:a,refreshKey:n}){const[r,c]=m.useState("overview"),[d,u]=m.useState(null),{getChatName:h}=aN(),[f,p]=m.useState(null),[g,N]=m.useState(!0),[v,w]=m.useState(null),[b,y]=m.useState(!1),[O,R]=m.useState(1),[S,B]=m.useState(20),[E,C]=m.useState(""),[A,F]=m.useState(""),[L,J]=m.useState(""),[U,oe]=m.useState(null),[Ne,je]=m.useState(!1),[re,fe]=m.useState(!1),ge=m.useCallback(async()=>{try{N(!0);const D=await Ik();p(D)}catch(D){console.error("加载回复器总览失败:",D)}finally{N(!1)}},[]),M=m.useCallback(async()=>{if(d)try{y(!0);const D=await Fk(d.chat_id,O,S,A||void 0);w(D)}catch(D){console.error("加载聊天日志失败:",D)}finally{y(!1)}},[d,O,S,A]);m.useEffect(()=>{ge()},[ge]),m.useEffect(()=>{n>0&&(r==="overview"?ge():M())},[n,r,ge,M]),m.useEffect(()=>{r==="chat-logs"&&d&&M()},[r,d,M]),nN(a,m.useCallback(()=>{r==="overview"?ge():M()},[r,ge,M]));const K=D=>{u(D),R(1),F(""),J(""),c("chat-logs")},P=()=>{c("overview"),u(null),w(null),F(""),J("")},ue=()=>{F(L),R(1)},Q=()=>{J(""),F(""),R(1)},Se=async(D,G)=>{try{fe(!0),je(!0);const de=await Hk(D,G);oe(de)}catch(de){console.error("加载回复详情失败:",de)}finally{fe(!1)}},pe=D=>{B(Number(D)),R(1)},Te=()=>{const D=parseInt(E),G=v?Math.ceil(v.total/v.page_size):0;!isNaN(D)&&D>=1&&D<=G&&(R(D),C(""))},z=v?Math.ceil(v.total/v.page_size):0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:r==="overview"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"聊天数量"}),e.jsx(Ra,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Me,{children:g?e.jsx(vs,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_chats||0})})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"回复总数"}),e.jsx(tx,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(Me,{children:g?e.jsx(vs,{className:"h-8 w-16"}):e.jsx("div",{className:"text-2xl font-bold",children:f?.total_replies||0})})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"聊天列表"}),e.jsx(os,{children:"点击查看该聊天的所有回复记录"})]}),e.jsx(Me,{children:g?e.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:[...Array(6)].map((D,G)=>e.jsx(vs,{className:"h-24 w-full"},G))}):f?.chats&&f.chats.length>0?e.jsx("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:f.chats.map(D=>e.jsxs("div",{className:"border rounded-lg p-4 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>K(D),children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ra,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm truncate max-w-[180px]",title:h(D.chat_id),children:h(D.chat_id)})]}),e.jsx(ke,{variant:"secondary",children:D.reply_count})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["最后活动: ",lN(D.latest_timestamp)]})]},D.chat_id))}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无聊天记录"})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-4 mb-4",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:P,children:[e.jsx(Ma,{className:"h-4 w-4 mr-2"}),"返回聊天列表"]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["当前聊天: ",e.jsx("span",{className:"font-medium",children:d?h(d.chat_id):""}),e.jsx("span",{className:"mx-2",children:"•"}),"共 ",v?.total||0," 条回复记录"]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(Oe,{children:"回复生成记录"}),e.jsx(os,{children:d?h(d.chat_id):""})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ae,{placeholder:"搜索提示词内容...",value:L,onChange:D=>J(D.target.value),onKeyDown:D=>D.key==="Enter"&&ue(),className:"w-full sm:w-48"}),e.jsx(_,{variant:"outline",size:"icon",onClick:ue,children:e.jsx(Tt,{className:"h-4 w-4"})}),A&&e.jsx(_,{variant:"ghost",size:"sm",onClick:Q,children:"清除"})]}),e.jsxs(Pe,{value:S.toString(),onValueChange:pe,children:[e.jsx($e,{className:"w-full sm:w-32",children:e.jsx(Ie,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"10",children:"10条/页"}),e.jsx(Z,{value:"20",children:"20条/页"}),e.jsx(Z,{value:"50",children:"50条/页"}),e.jsx(Z,{value:"100",children:"100条/页"})]})]})]})]}),A&&e.jsxs("div",{className:"text-sm text-muted-foreground mt-2",children:["搜索关键词: ",e.jsxs("span",{className:"font-medium",children:['"',A,'"']})]})]}),e.jsx(Me,{children:b?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((D,G)=>e.jsx(vs,{className:"h-20 w-full"},G))}):v?.data&&v.data.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-2",children:v.data.map(D=>e.jsxs("div",{className:"border rounded-lg p-3 hover:bg-accent/50 transition-colors cursor-pointer",onClick:()=>Se(D.chat_id,D.filename),children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:Jo(D.timestamp)}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[D.success?e.jsxs(ke,{variant:"default",className:"text-xs bg-green-600",children:[e.jsx(yg,{className:"h-3 w-3 mr-1"}),"成功"]}):e.jsxs(ke,{variant:"destructive",className:"text-xs",children:[e.jsx(Ka,{className:"h-3 w-3 mr-1"}),"失败"]}),e.jsx(ke,{variant:"outline",className:"text-xs",children:D.model}),e.jsxs(ke,{variant:"secondary",className:"text-xs",children:[D.overall_ms.toFixed(0),"ms"]})]})]}),e.jsx("p",{className:"text-sm line-clamp-2",children:D.output_preview||"无输出内容"})]},D.filename))}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-3 mt-4 pt-4 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",v.total," 条记录,第 ",O," / ",z," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>R(1),disabled:O===1,className:"hidden sm:flex",children:e.jsx(Nn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>R(D=>Math.max(1,D-1)),disabled:O===1,children:e.jsx(Da,{className:"h-4 w-4"})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2",children:[e.jsx(ae,{type:"number",min:1,max:z,value:E,onChange:D=>C(D.target.value),onKeyDown:D=>D.key==="Enter"&&Te(),placeholder:"跳转",className:"w-20 h-8"}),e.jsx(_,{size:"sm",variant:"outline",onClick:Te,children:"跳转"})]}),e.jsxs("span",{className:"sm:hidden text-sm text-muted-foreground",children:[O,"/",z]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>R(D=>Math.min(z,D+1)),disabled:O===z,children:e.jsx(Wt,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>R(z),disabled:O===z,className:"hidden sm:flex",children:e.jsx(bn,{className:"h-4 w-4"})})]})]})]}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无回复记录"})})]})]})}),e.jsx(Ps,{open:Ne,onOpenChange:je,children:e.jsxs(Ds,{className:"max-w-4xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(Ea,{className:"h-5 w-5"}),"回复生成详情"]}),e.jsx(Ks,{children:"查看麦麦的详细回复生成过程"})]}),e.jsx(Je,{className:"h-full pr-4",children:e.jsx("div",{className:"space-y-6 pb-4",children:re?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((D,G)=>e.jsx(vs,{className:"h-24 w-full"},G))}):U?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(na,{className:"h-4 w-4"}),"基本信息"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 p-4 bg-muted/50 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"聊天"}),e.jsx("div",{className:"text-sm",title:U.chat_id,children:h(U.chat_id)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"时间戳"}),e.jsx("div",{className:"text-sm",children:Jo(U.timestamp)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"状态"}),U.success?e.jsxs(ke,{variant:"default",className:"bg-green-600",children:[e.jsx(yg,{className:"h-3 w-3 mr-1"}),"成功"]}):e.jsxs(ke,{variant:"destructive",children:[e.jsx(Ka,{className:"h-3 w-3 mr-1"}),"失败"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"思考深度"}),e.jsxs(ke,{variant:"outline",children:["Level ",U.think_level]})]})]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx($_,{className:"h-4 w-4"}),"模型信息"]}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx(ke,{variant:"secondary",className:"text-sm",children:U.model})})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(el,{className:"h-4 w-4"}),"性能统计"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"提示词构建"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[U.timing.prompt_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"LLM 推理"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[U.timing.llm_ms?.toFixed(2)||0,"ms"]})})]}),e.jsxs(Ce,{children:[e.jsx(De,{className:"p-4 pb-2",children:e.jsx(Oe,{className:"text-xs text-muted-foreground",children:"总耗时"})}),e.jsx(Me,{className:"p-4 pt-0",children:e.jsxs("div",{className:"text-xl font-bold",children:[U.timing.overall_ms?.toFixed(2)||0,"ms"]})})]})]}),U.timing.timing_logs&&U.timing.timing_logs.length>0&&e.jsxs("div",{className:"mt-3 p-3 bg-muted/30 rounded-lg",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-2",children:"耗时详情"}),e.jsx("div",{className:"space-y-1",children:U.timing.timing_logs.map((D,G)=>e.jsx("div",{className:"text-xs text-muted-foreground",children:D},G))})]}),U.timing.almost_zero&&e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"近乎零耗时: "}),U.timing.almost_zero]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(cx,{className:"h-4 w-4"}),"回复输出"]}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:U.output||"无输出内容"})})]}),U.processed_output&&U.processed_output.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"处理后的输出"}),e.jsx("div",{className:"space-y-2",children:U.processed_output.map((D,G)=>e.jsx("div",{className:"p-3 bg-muted/30 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:D})},G))})]})]}),U.reasoning&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"推理过程"}),e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:U.reasoning})})]})]}),U.error&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-destructive",children:"错误信息"}),e.jsx("div",{className:"p-4 bg-destructive/10 rounded-lg border border-destructive/20",children:e.jsx("p",{className:"text-sm text-destructive whitespace-pre-wrap",children:U.error})})]})]}),U.prompt&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"完整提示词"}),e.jsxs("details",{className:"group",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-muted-foreground hover:text-foreground",children:"点击展开查看完整提示词"}),e.jsx("div",{className:"mt-2 p-4 bg-muted/50 rounded-lg",children:e.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:U.prompt})})]})]})]})]}):e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"无数据"})})})}),e.jsx(st,{className:"flex-shrink-0",children:e.jsx(_,{onClick:()=>je(!1),children:"关闭"})})]})})]})}function qk(){const[a,n]=m.useState("planner"),[r,c]=m.useState(!1),[d,u]=m.useState(0),h=m.useCallback(()=>{u(f=>f+1)},[]);return 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 items-center gap-2",children:[e.jsxs(_,{variant:r?"default":"outline",size:"sm",onClick:()=>c(!r),children:[e.jsx(dt,{className:`h-4 w-4 mr-2 ${r?"animate-spin":""}`}),r?"自动刷新中":"自动刷新"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:h,children:e.jsx(dt,{className:"h-4 w-4"})})]})]}),e.jsxs(ta,{value:a,onValueChange:f=>n(f),className:"w-full",children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2 gap-0.5 sm:gap-1 h-auto p-1",children:[e.jsxs(Xe,{value:"planner",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(sx,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"计划器监控"})]}),e.jsxs(Xe,{value:"replier",className:"gap-1 sm:gap-2 text-xs sm:text-sm px-2 sm:px-3 py-2",children:[e.jsx(B_,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4",strokeWidth:2,fill:"none"}),e.jsx("span",{children:"回复器监控"})]})]}),e.jsxs(Je,{className:"h-[calc(100vh-240px)] sm:h-[calc(100vh-280px)] mt-4 sm:mt-6",children:[e.jsx(ws,{value:"planner",className:"mt-0",children:e.jsx(Vk,{autoRefresh:r,refreshKey:d})}),e.jsx(ws,{value:"replier",className:"mt-0",children:e.jsx(Gk,{autoRefresh:r,refreshKey:d})})]})]})]})}const Kk="Mai-with-u",Qk="plugin-repo",Yk="main",Jk="plugin_details.json";async function Xk(){try{const a=await _e("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:Kk,repo:Qk,branch:Yk,file_path:Jk})});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const n=await a.json();if(!n.success||!n.data)throw new Error(n.error||"获取插件列表失败");return JSON.parse(n.data).filter(d=>!d?.id||!d?.manifest?(console.warn("跳过无效插件数据:",d),!1):!d.manifest.name||!d.manifest.version?(console.warn("跳过缺少必需字段的插件:",d.id),!1):!0).map(d=>({id:d.id,manifest:{manifest_version:d.manifest.manifest_version||1,name:d.manifest.name,version:d.manifest.version,description:d.manifest.description||"",author:d.manifest.author||{name:"Unknown"},license:d.manifest.license||"Unknown",host_application:d.manifest.host_application||{min_version:"0.0.0"},homepage_url:d.manifest.homepage_url,repository_url:d.manifest.repository_url,keywords:d.manifest.keywords||[],categories:d.manifest.categories||[],default_locale:d.manifest.default_locale||"zh-CN",locales_path:d.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!1,published_at:new Date().toISOString(),updated_at:new Date().toISOString()}))}catch(a){throw console.error("Failed to fetch plugin list:",a),a}}async function rN(){try{const a=await _e("/api/webui/plugins/git-status");if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return await a.json()}catch(a){return console.error("Failed to check Git status:",a),{installed:!1,error:"无法检测 Git 安装状态"}}}async function iN(){try{const a=await _e("/api/webui/plugins/version");if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);return await a.json()}catch(a){return console.error("Failed to get Maimai version:",a),{version:"0.0.0",version_major:0,version_minor:0,version_patch:0}}}function cN(a,n,r){const c=a.split(".").map(f=>parseInt(f)||0),d=c[0]||0,u=c[1]||0,h=c[2]||0;if(r.version_majorparseInt(v)||0),p=f[0]||0,g=f[1]||0,N=f[2]||0;if(r.version_major>p||r.version_major===p&&r.version_minor>g||r.version_major===p&&r.version_minor===g&&r.version_patch>N)return!1}return!0}async function Zk(){try{const a=await _e("/api/webui/ws-token");if(!a.ok)return console.error("获取 WebSocket token 失败:",a.status),null;const n=await a.json();return n.success&&n.token?n.token:null}catch(a){return console.error("获取 WebSocket token 失败:",a),null}}async function Wk(a,n){const r=await Zk();if(!r)return console.warn("无法获取 WebSocket token,可能未登录"),null;const c=window.location.protocol==="https:"?"wss:":"ws:",d=window.location.host,u=`${c}//${d}/api/webui/ws/plugin-progress?token=${encodeURIComponent(r)}`;try{const h=new WebSocket(u);return h.onopen=()=>{console.log("Plugin progress WebSocket connected");const f=setInterval(()=>{h.readyState===WebSocket.OPEN?h.send("ping"):clearInterval(f)},3e4)},h.onmessage=f=>{try{if(f.data==="pong")return;const p=JSON.parse(f.data);a(p)}catch(p){console.error("Failed to parse progress data:",p)}},h.onerror=f=>{console.error("Plugin progress WebSocket error:",f),n?.(f)},h.onclose=()=>{console.log("Plugin progress WebSocket disconnected")},h}catch(h){return console.error("创建 WebSocket 连接失败:",h),null}}async function Dl(){try{const a=await _e("/api/webui/plugins/installed",{headers:Hs()});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const n=await a.json();if(!n.success)throw new Error(n.message||"获取已安装插件列表失败");return n.plugins||[]}catch(a){return console.error("Failed to get installed plugins:",a),[]}}function hn(a,n){return n.some(r=>r.id===a)}function fn(a,n){const r=n.find(c=>c.id===a);if(r)return r.manifest?.version||r.version}async function oN(a,n,r="main"){const c=await _e("/api/webui/plugins/install",{method:"POST",body:JSON.stringify({plugin_id:a,repository_url:n,branch:r})});if(!c.ok){const d=await c.json();throw new Error(d.detail||"安装失败")}return await c.json()}async function dN(a){const n=await _e("/api/webui/plugins/uninstall",{method:"POST",body:JSON.stringify({plugin_id:a})});if(!n.ok){const r=await n.json();throw new Error(r.detail||"卸载失败")}return await n.json()}async function uN(a,n,r="main"){const c=await _e("/api/webui/plugins/update",{method:"POST",body:JSON.stringify({plugin_id:a,repository_url:n,branch:r})});if(!c.ok){const d=await c.json();throw new Error(d.detail||"更新失败")}return await c.json()}async function eC(a){const n=await _e(`/api/webui/plugins/config/${a}/schema`,{headers:Hs()});if(!n.ok){const c=await n.text();try{const d=JSON.parse(c);throw new Error(d.detail||"获取配置 Schema 失败")}catch{throw new Error(`获取配置 Schema 失败 (${n.status})`)}}const r=await n.json();if(!r.success)throw new Error(r.message||"获取配置 Schema 失败");return r.schema}async function sC(a){const n=await _e(`/api/webui/plugins/config/${a}`,{headers:Hs()});if(!n.ok){const c=await n.text();try{const d=JSON.parse(c);throw new Error(d.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${n.status})`)}}const r=await n.json();if(!r.success)throw new Error(r.message||"获取配置失败");return r.config}async function tC(a){const n=await _e(`/api/webui/plugins/config/${a}/raw`,{headers:Hs()});if(!n.ok){const c=await n.text();try{const d=JSON.parse(c);throw new Error(d.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${n.status})`)}}const r=await n.json();if(!r.success)throw new Error(r.message||"获取配置失败");return r.config}async function aC(a,n){const r=await _e(`/api/webui/plugins/config/${a}`,{method:"PUT",headers:Hs(),body:JSON.stringify({config:n})});if(!r.ok){const c=await r.json();throw new Error(c.detail||"保存配置失败")}return await r.json()}async function lC(a,n){const r=await _e(`/api/webui/plugins/config/${a}/raw`,{method:"PUT",headers:Hs(),body:JSON.stringify({config:n})});if(!r.ok){const c=await r.json();throw new Error(c.detail||"保存配置失败")}return await r.json()}async function nC(a){const n=await _e(`/api/webui/plugins/config/${a}/reset`,{method:"POST",headers:Hs()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"重置配置失败")}return await n.json()}async function rC(a){const n=await _e(`/api/webui/plugins/config/${a}/toggle`,{method:"POST",headers:Hs()});if(!n.ok){const r=await n.json();throw new Error(r.detail||"切换状态失败")}return await n.json()}const jc="https://maibot-plugin-stats.maibot-webui.workers.dev";async function mN(a){try{const n=await fetch(`${jc}/stats/${a}`);return n.ok?await n.json():(console.error("Failed to fetch plugin stats:",n.statusText),null)}catch(n){return console.error("Error fetching plugin stats:",n),null}}async function iC(a,n){try{const r=n||wx(),c=await fetch(`${jc}/stats/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a,user_id:r})}),d=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...d}:{success:!1,error:d.error||"点赞失败"}}catch(r){return console.error("Error liking plugin:",r),{success:!1,error:"网络错误"}}}async function cC(a,n){try{const r=n||wx(),c=await fetch(`${jc}/stats/dislike`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a,user_id:r})}),d=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...d}:{success:!1,error:d.error||"点踩失败"}}catch(r){return console.error("Error disliking plugin:",r),{success:!1,error:"网络错误"}}}async function oC(a,n,r,c){if(n<1||n>5)return{success:!1,error:"评分必须在 1-5 之间"};try{const d=c||wx(),u=await fetch(`${jc}/stats/rate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a,rating:n,comment:r,user_id:d})}),h=await u.json();return u.status===429?{success:!1,error:"每天最多评分 3 次"}:u.ok?{success:!0,...h}:{success:!1,error:h.error||"评分失败"}}catch(d){return console.error("Error rating plugin:",d),{success:!1,error:"网络错误"}}}async function xN(a){try{const n=await fetch(`${jc}/stats/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:a})}),r=await n.json();return n.status===429?(console.warn("Download recording rate limited"),{success:!0}):n.ok?{success:!0,...r}:(console.error("Failed to record download:",r.error),{success:!1,error:r.error})}catch(n){return console.error("Error recording download:",n),{success:!1,error:"网络错误"}}}function dC(){const a=navigator,n=[navigator.userAgent,navigator.language,navigator.languages?.join(",")||"",navigator.platform,navigator.hardwareConcurrency||0,screen.width,screen.height,screen.colorDepth,screen.pixelDepth,new Date().getTimezoneOffset(),Intl.DateTimeFormat().resolvedOptions().timeZone,navigator.maxTouchPoints||0,a.deviceMemory||0].join("|");let r=0;for(let c=0;c{const ee=H.map(async Ee=>{try{const me=await mN(Ee.id);return{id:Ee.id,stats:me}}catch(me){return console.warn(`Failed to load stats for ${Ee.id}:`,me),{id:Ee.id,stats:null}}}),Ue=await Promise.all(ee),ie={};Ue.forEach(({id:Ee,stats:me})=>{me&&(ie[Ee]=me)}),U(ie)};m.useEffect(()=>{let H=null,ee=!1;return(async()=>{if(H=await Wk(ie=>{ee||(C(ie),ie.stage==="success"?setTimeout(()=>{ee||C(null)},2e3):ie.stage==="error"&&(y(!1),R(ie.error||"加载失败")))},ie=>{console.error("WebSocket error:",ie),ee||pe({title:"WebSocket 连接失败",description:"无法实时显示加载进度",variant:"destructive"})}),await new Promise(ie=>{if(!H){ie();return}const Ee=()=>{H&&H.readyState===WebSocket.OPEN?(console.log("WebSocket connected, starting to load plugins"),ie()):H&&H.readyState===WebSocket.CLOSED?(console.warn("WebSocket closed before loading plugins"),ie()):setTimeout(Ee,100)};Ee()}),!ee){const ie=await rN();B(ie),ie.installed||pe({title:"Git 未安装",description:ie.error||"请先安装 Git 才能使用插件安装功能",variant:"destructive"})}if(!ee){const ie=await iN();F(ie)}if(!ee)try{y(!0),R(null);const ie=await Xk();if(!ee){const Ee=await Dl();L(Ee);const me=ie.map(Ae=>{const rs=hn(Ae.id,Ee),Ut=fn(Ae.id,Ee);return{...Ae,installed:rs,installed_version:Ut}});for(const Ae of Ee)!me.some(Ut=>Ut.id===Ae.id)&&Ae.manifest&&me.push({id:Ae.id,manifest:{manifest_version:Ae.manifest.manifest_version||1,name:Ae.manifest.name,version:Ae.manifest.version,description:Ae.manifest.description||"",author:Ae.manifest.author,license:Ae.manifest.license||"Unknown",host_application:Ae.manifest.host_application,homepage_url:Ae.manifest.homepage_url,repository_url:Ae.manifest.repository_url,keywords:Ae.manifest.keywords||[],categories:Ae.manifest.categories||[],default_locale:Ae.manifest.default_locale||"zh-CN",locales_path:Ae.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!0,installed_version:Ae.manifest.version,published_at:new Date().toISOString(),updated_at:new Date().toISOString()});w(me),Te(me)}}catch(ie){if(!ee){const Ee=ie instanceof Error?ie.message:"加载插件列表失败";R(Ee),pe({title:"加载失败",description:Ee,variant:"destructive"})}}finally{ee||y(!1)}})(),()=>{ee=!0,H&&H.close()}},[pe]);const z=H=>{if(!H.installed&&A&&!D(H))return e.jsxs(ke,{variant:"destructive",className:"gap-1",children:[e.jsx(_t,{className:"h-3 w-3"}),"不兼容"]});if(H.installed){const ee=H.installed_version?.trim(),Ue=H.manifest.version?.trim();if(ee!==Ue){const ie=ee?.split(".").map(Number)||[0,0,0],Ee=Ue?.split(".").map(Number)||[0,0,0];for(let me=0;me<3;me++){if((Ee[me]||0)>(ie[me]||0))return e.jsxs(ke,{variant:"outline",className:"gap-1 text-orange-600 border-orange-600",children:[e.jsx(_t,{className:"h-3 w-3"}),"可更新"]});if((Ee[me]||0)<(ie[me]||0))break}}return e.jsxs(ke,{variant:"default",className:"gap-1",children:[e.jsx(pt,{className:"h-3 w-3"}),"已安装"]})}return null},D=H=>!A||!H.manifest?.host_application?!0:cN(H.manifest.host_application.min_version,H.manifest.host_application.max_version,A),G=H=>{if(!H.installed||!H.installed_version||!H.manifest?.version)return!1;const ee=H.installed_version.trim(),Ue=H.manifest.version.trim();if(ee===Ue)return!1;const ie=ee.split(".").map(Number),Ee=Ue.split(".").map(Number);for(let me=0;me<3;me++){if((Ee[me]||0)>(ie[me]||0))return!0;if((Ee[me]||0)<(ie[me]||0))return!1}return!1},de=v.filter(H=>{if(!H.manifest)return console.warn("[过滤] 跳过无 manifest 的插件:",H.id),!1;const ee=c===""||H.manifest.name?.toLowerCase().includes(c.toLowerCase())||H.manifest.description?.toLowerCase().includes(c.toLowerCase())||H.manifest.keywords&&H.manifest.keywords.some(me=>me.toLowerCase().includes(c.toLowerCase())),Ue=u==="all"||H.manifest.categories&&H.manifest.categories.includes(u);let ie=!0;f==="installed"?ie=H.installed===!0:f==="updates"&&(ie=H.installed===!0&&G(H));const Ee=!g||!A||D(H);return ee&&Ue&&ie&&Ee}),Re=H=>{if(!S?.installed){pe({title:"无法安装",description:"Git 未安装",variant:"destructive"});return}if(A&&!D(H)){pe({title:"无法安装",description:"插件与当前麦麦版本不兼容",variant:"destructive"});return}re(H),ge("main"),K(""),ue("preset"),Se(!1),Ne(!0)},W=async()=>{if(!je)return;const H=P==="custom"?M:fe;if(!H||H.trim()===""){pe({title:"分支名称不能为空",variant:"destructive"});return}try{Ne(!1),await oN(je.id,je.manifest.repository_url||"",H),xN(je.id).catch(Ue=>{console.warn("Failed to record download:",Ue)}),pe({title:"安装成功",description:`${je.manifest.name} 已成功安装`});const ee=await Dl();L(ee),w(Ue=>Ue.map(ie=>{if(ie.id===je.id){const Ee=hn(ie.id,ee),me=fn(ie.id,ee);return{...ie,installed:Ee,installed_version:me}}return ie}))}catch(ee){pe({title:"安装失败",description:ee instanceof Error?ee.message:"未知错误",variant:"destructive"})}finally{re(null)}},Y=async H=>{try{await dN(H.id),pe({title:"卸载成功",description:`${H.manifest.name} 已成功卸载`});const ee=await Dl();L(ee),w(Ue=>Ue.map(ie=>{if(ie.id===H.id){const Ee=hn(ie.id,ee),me=fn(ie.id,ee);return{...ie,installed:Ee,installed_version:me}}return ie}))}catch(ee){pe({title:"卸载失败",description:ee instanceof Error?ee.message:"未知错误",variant:"destructive"})}},Fe=async H=>{if(!S?.installed){pe({title:"无法更新",description:"Git 未安装",variant:"destructive"});return}try{const ee=await uN(H.id,H.manifest.repository_url||"","main");pe({title:"更新成功",description:`${H.manifest.name} 已从 ${ee.old_version} 更新到 ${ee.new_version}`});const Ue=await Dl();L(Ue),w(ie=>ie.map(Ee=>{if(Ee.id===H.id){const me=hn(Ee.id,Ue),Ae=fn(Ee.id,Ue);return{...Ee,installed:me,installed_version:Ae}}return Ee}))}catch(ee){pe({title:"更新失败",description:ee instanceof Error?ee.message:"未知错误",variant:"destructive"})}};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件市场"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"浏览和管理麦麦的插件"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(_,{variant:"outline",onClick:()=>n(),disabled:r,children:[e.jsx(iv,{className:`h-4 w-4 mr-2 ${r?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(_,{onClick:()=>a({to:"/plugin-mirrors"}),children:[e.jsx(P_,{className:"h-4 w-4 mr-2"}),"配置镜像源"]})]})]}),e.jsx(Ce,{className:"border-blue-200 bg-blue-50 dark:bg-blue-950/20 dark:border-blue-900",children:e.jsx(Me,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ft,{className:"h-4 w-4 text-blue-600 flex-shrink-0"}),e.jsxs("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:["安装、卸载或更新插件后,需要",e.jsx("span",{className:"font-semibold",children:"重启麦麦"}),"才能使更改生效"]})]})})}),S&&!S.installed&&e.jsxs(Ce,{className:"border-orange-600 bg-orange-50 dark:bg-orange-950/20",children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jt,{className:"h-5 w-5 text-orange-600"}),e.jsxs("div",{children:[e.jsx(Oe,{className:"text-lg text-orange-900 dark:text-orange-100",children:"Git 未安装"}),e.jsx(os,{className:"text-orange-800 dark:text-orange-200",children:S.error||"请先安装 Git 才能使用插件安装功能"})]})]})}),e.jsx(Me,{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(Ce,{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(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ae,{placeholder:"搜索插件...",value:c,onChange:H=>d(H.target.value),className:"pl-9"})]}),e.jsxs(Pe,{value:u,onValueChange:h,children:[e.jsx($e,{className:"w-full sm:w-[200px]",children:e.jsx(Ie,{placeholder:"选择分类"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部分类"}),e.jsx(Z,{value:"Group Management",children:"群组管理"}),e.jsx(Z,{value:"Entertainment & Interaction",children:"娱乐互动"}),e.jsx(Z,{value:"Utility Tools",children:"实用工具"}),e.jsx(Z,{value:"Content Generation",children:"内容生成"}),e.jsx(Z,{value:"Multimedia",children:"多媒体"}),e.jsx(Z,{value:"External Integration",children:"外部集成"}),e.jsx(Z,{value:"Data Analysis & Insights",children:"数据分析与洞察"}),e.jsx(Z,{value:"Other",children:"其他"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"compatible-only",checked:g,onCheckedChange:H=>N(H===!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(ta,{value:f,onValueChange:p,className:"w-full",children:e.jsxs(Zt,{className:"grid w-full grid-cols-3",children:[e.jsxs(Xe,{value:"all",children:["全部插件 (",v.filter(H=>{if(!H.manifest)return!1;const ee=c===""||H.manifest.name?.toLowerCase().includes(c.toLowerCase())||H.manifest.description?.toLowerCase().includes(c.toLowerCase())||H.manifest.keywords&&H.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=u==="all"||H.manifest.categories&&H.manifest.categories.includes(u),ie=!g||!A||D(H);return ee&&Ue&&ie}).length,")"]}),e.jsxs(Xe,{value:"installed",children:["已安装 (",v.filter(H=>{if(!H.manifest)return!1;const ee=c===""||H.manifest.name?.toLowerCase().includes(c.toLowerCase())||H.manifest.description?.toLowerCase().includes(c.toLowerCase())||H.manifest.keywords&&H.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=u==="all"||H.manifest.categories&&H.manifest.categories.includes(u),ie=!g||!A||D(H);return H.installed&&ee&&Ue&&ie}).length,")"]}),e.jsxs(Xe,{value:"updates",children:["可更新 (",v.filter(H=>{if(!H.manifest)return!1;const ee=c===""||H.manifest.name?.toLowerCase().includes(c.toLowerCase())||H.manifest.description?.toLowerCase().includes(c.toLowerCase())||H.manifest.keywords&&H.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=u==="all"||H.manifest.categories&&H.manifest.categories.includes(u),ie=!g||!A||D(H);return H.installed&&G(H)&&ee&&Ue&&ie}).length,")"]})]})}),E&&E.stage==="loading"&&E.operation==="fetch"&&e.jsx(Ce,{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(zs,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm font-medium",children:"加载插件列表"})]}),e.jsxs("span",{className:"text-sm font-medium",children:[E.progress,"%"]})]}),e.jsx(Xn,{value:E.progress,className:"h-2"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:E.message}),E.total_plugins>0&&e.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:["已加载 ",E.loaded_plugins," / ",E.total_plugins," 个插件"]})]})}),E&&E.stage==="error"&&E.error&&e.jsx(Ce,{className:"border-destructive bg-destructive/10",children:e.jsx(De,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jt,{className:"h-5 w-5 text-destructive"}),e.jsxs("div",{children:[e.jsx(Oe,{className:"text-lg text-destructive",children:"加载失败"}),e.jsx(os,{className:"text-destructive/80",children:E.error})]})]})})}),b?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件列表中..."})]}):O?e.jsx(Ce,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Jt,{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:O}),e.jsx(_,{onClick:()=>window.location.reload(),children:"重新加载"})]})}):de.length===0?e.jsx(Ce,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Tt,{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:c||u!=="all"?"尝试调整搜索条件或筛选器":"暂无可用插件"})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:de.map(H=>e.jsxs(Ce,{className:"flex flex-col hover:shadow-lg transition-shadow h-full",children:[e.jsxs(De,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx(Oe,{className:"text-xl",children:H.manifest?.name||H.id}),e.jsxs("div",{className:"flex flex-col gap-1",children:[H.manifest?.categories&&H.manifest.categories[0]&&e.jsx(ke,{variant:"secondary",className:"text-xs whitespace-nowrap",children:uC[H.manifest.categories[0]]||H.manifest.categories[0]}),z(H)]})]}),e.jsx(os,{className:"line-clamp-2",children:H.manifest?.description||"无描述"})]}),e.jsx(Me,{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(Xt,{className:"h-4 w-4"}),e.jsx("span",{children:(J[H.id]?.downloads??H.downloads??0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(mn,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:(J[H.id]?.rating??H.rating??0).toFixed(1)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[H.manifest?.keywords&&H.manifest.keywords.slice(0,3).map(ee=>e.jsx(ke,{variant:"outline",className:"text-xs",children:ee},ee)),H.manifest?.keywords&&H.manifest.keywords.length>3&&e.jsxs(ke,{variant:"outline",className:"text-xs",children:["+",H.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",H.manifest?.version||"unknown"," · ",H.manifest?.author?.name||"Unknown"]}),H.manifest?.host_application&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:"支持:"}),e.jsxs("span",{className:"font-medium",children:[H.manifest.host_application.min_version,H.manifest.host_application.max_version?` - ${H.manifest.host_application.max_version}`:" - 最新版本"]})]})]})]})}),e.jsx(id,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center justify-end gap-2 w-full",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>a({to:"/plugin-detail",search:{pluginId:H.id}}),children:"查看详情"}),H.installed?G(H)?e.jsxs(_,{size:"sm",disabled:!S?.installed,title:S?.installed?void 0:"Git 未安装",onClick:()=>Fe(H),children:[e.jsx(dt,{className:"h-4 w-4 mr-1"}),"更新"]}):e.jsxs(_,{variant:"destructive",size:"sm",disabled:!S?.installed,title:S?.installed?void 0:"Git 未安装",onClick:()=>Y(H),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"卸载"]}):e.jsxs(_,{size:"sm",disabled:!S?.installed||E?.operation==="install"||A!==null&&!D(H),title:S?.installed?A!==null&&!D(H)?`不兼容当前版本 (需要 ${H.manifest?.host_application?.min_version||"未知"}${H.manifest?.host_application?.max_version?` - ${H.manifest.host_application.max_version}`:"+"},当前 ${A?.version})`:void 0:"Git 未安装",onClick:()=>Re(H),children:[e.jsx(Xt,{className:"h-4 w-4 mr-1"}),E?.operation==="install"&&E?.plugin_id===H.id?"安装中...":"安装"]})]})}),E&&(E.stage==="loading"||E.stage==="success"||E.stage==="error")&&E.operation!=="fetch"&&E.plugin_id===H.id&&e.jsx("div",{className:"px-6 pb-4 -mt-2",children:e.jsxs("div",{className:`space-y-2 p-3 rounded-lg border ${E.stage==="success"?"bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-900":E.stage==="error"?"bg-red-50 dark:bg-red-950/20 border-red-200 dark:border-red-900":"bg-muted/50"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[E.stage==="loading"?e.jsx(zs,{className:"h-3 w-3 animate-spin"}):E.stage==="success"?e.jsx(pt,{className:"h-3 w-3 text-green-600"}):e.jsx(_t,{className:"h-3 w-3 text-red-600"}),e.jsx("span",{className:`text-xs font-medium ${E.stage==="success"?"text-green-700 dark:text-green-300":E.stage==="error"?"text-red-700 dark:text-red-300":""}`,children:E.stage==="loading"?e.jsxs(e.Fragment,{children:[E.operation==="install"&&"正在安装",E.operation==="uninstall"&&"正在卸载",E.operation==="update"&&"正在更新"]}):E.stage==="success"?e.jsxs(e.Fragment,{children:[E.operation==="install"&&"安装完成",E.operation==="uninstall"&&"卸载完成",E.operation==="update"&&"更新完成"]}):e.jsxs(e.Fragment,{children:[E.operation==="install"&&"安装失败",E.operation==="uninstall"&&"卸载失败",E.operation==="update"&&"更新失败"]})})]}),E.stage!=="error"&&e.jsxs("span",{className:`text-xs font-medium ${E.stage==="success"?"text-green-700 dark:text-green-300":""}`,children:[E.progress,"%"]})]}),E.stage!=="error"&&e.jsx(Xn,{value:E.progress,className:`h-1.5 ${E.stage==="success"?"[&>div]:bg-green-500":""}`}),e.jsx("div",{className:`text-xs ${E.stage==="success"?"text-green-600 dark:text-green-400 truncate":E.stage==="error"?"text-red-600 dark:text-red-400":"text-muted-foreground truncate"}`,children:E.stage==="error"?E.error||E.message||"操作失败":E.message})]})})]},H.id))}),e.jsx(Ps,{open:oe,onOpenChange:Ne,children:e.jsxs(Ds,{children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"安装插件"}),e.jsxs(Ks,{children:["安装 ",je?.manifest.name]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["版本: ",je?.manifest.version]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["作者: ",typeof je?.manifest.author=="string"?je.manifest.author:je?.manifest.author?.name]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"advanced-options",checked:Q,onCheckedChange:H=>Se(H)}),e.jsx("label",{htmlFor:"advanced-options",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"高级选项"})]}),Q&&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(ta,{value:P,onValueChange:H=>ue(H),children:[e.jsxs(Zt,{className:"grid w-full grid-cols-2",children:[e.jsx(Xe,{value:"preset",className:"text-xs",children:"预设分支"}),e.jsx(Xe,{value:"custom",className:"text-xs",children:"自定义分支"})]}),P==="preset"&&e.jsx("div",{className:"mt-3",children:e.jsxs(Pe,{value:fe,onValueChange:ge,children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:"选择分支"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"main",children:"main (默认)"}),e.jsx(Z,{value:"master",children:"master"}),e.jsx(Z,{value:"dev",children:"dev (开发版)"}),e.jsx(Z,{value:"develop",children:"develop"}),e.jsx(Z,{value:"beta",children:"beta (测试版)"}),e.jsx(Z,{value:"stable",children:"stable (稳定版)"})]})]})}),P==="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:M,onChange:H=>K(H.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"输入 Git 分支名称、标签或提交哈希"})]})]})]})}),!Q&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"将从默认分支 (main) 安装插件"})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>Ne(!1),children:"取消"}),e.jsxs(_,{onClick:W,children:[e.jsx(Xt,{className:"h-4 w-4 mr-2"}),"安装"]})]})]})}),e.jsx(er,{})]})})}function hC(){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(cv,{className:"h-8 w-8",strokeWidth:2}),"模型分配预设市场"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"浏览和下载社区共享的模型分配预设配置"})]})})}),e.jsx(Je,{className:"flex-1",children:e.jsx("div",{className:"flex items-center justify-center h-[calc(100vh-12rem)]",children:e.jsxs(Ce,{className:"max-w-2xl w-full border-dashed",children:[e.jsxs(De,{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(ra,{className:"h-16 w-16 text-muted-foreground"})}),e.jsx(Oe,{className:"text-2xl",children:"功能开发中"}),e.jsx(os,{className:"text-base",children:"模型分配预设市场功能正在开发中,敬请期待!"})]}),e.jsx(Me,{children:e.jsxs("div",{className:"space-y-3 text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-foreground",children:"📦 即将推出的功能:"}),e.jsxs("ul",{className:"space-y-2 ml-6",children:[e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"浏览社区共享的模型分配预设配置"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"一键下载和应用预设配置"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"分享自己的模型分配方案"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"预设配置评分和评论系统"})]}),e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"•"}),e.jsx("span",{children:"根据使用场景智能推荐配置"})]})]})]})})]})})})]})}function fC({field:a,value:n,onChange:r}){const[c,d]=m.useState(!1);switch(a.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(T,{children:a.label}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]}),e.jsx(Ve,{checked:!!n,onCheckedChange:r,disabled:a.disabled})]});case"number":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(ae,{type:"number",value:n??a.default,onChange:u=>r(parseFloat(u.target.value)||0),min:a.min,max:a.max,step:a.step??1,placeholder:a.placeholder,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"slider":return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:a.label}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n??a.default})]}),e.jsx(Qa,{value:[n??a.default],onValueChange:u=>r(u[0]),min:a.min??0,max:a.max??100,step:a.step??1,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"select":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsxs(Pe,{value:String(n??a.default),onValueChange:r,disabled:a.disabled,children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:a.placeholder??"请选择"})}),e.jsx(Be,{children:a.choices?.map(u=>e.jsx(Z,{value:String(u),children:String(u)},String(u)))})]}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"textarea":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(ot,{value:n??a.default,onChange:u=>r(u.target.value),placeholder:a.placeholder,rows:a.rows??3,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"password":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsxs("div",{className:"relative",children:[e.jsx(ae,{type:c?"text":"password",value:n??"",onChange:u=>r(u.target.value),placeholder:a.placeholder,disabled:a.disabled,className:"pr-10"}),e.jsx(_,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3",onClick:()=>d(!c),children:c?e.jsx(nc,{className:"h-4 w-4"}):e.jsx(ia,{className:"h-4 w-4"})})]}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"list":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(NS,{value:Array.isArray(n)?n:[],onChange:u=>r(u),itemType:a.item_type??"string",itemFields:a.item_fields,minItems:a.min_items,maxItems:a.max_items,disabled:a.disabled,placeholder:a.placeholder}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]});case"text":default:return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:a.label}),e.jsx(ae,{type:"text",value:n??a.default??"",onChange:u=>r(u.target.value),placeholder:a.placeholder,maxLength:a.max_length,disabled:a.disabled}),a.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.hint})]})}}function Xg({section:a,config:n,onChange:r}){const[c,d]=m.useState(!a.collapsed),u=Object.entries(a.fields).filter(([,h])=>!h.hidden).sort(([,h],[,f])=>h.order-f.order);return e.jsx(uc,{open:c,onOpenChange:d,children:e.jsxs(Ce,{children:[e.jsx(mc,{asChild:!0,children:e.jsxs(De,{className:"cursor-pointer hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c?e.jsx(za,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Wt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(Oe,{className:"text-lg",children:a.title})]}),e.jsxs(ke,{variant:"secondary",className:"text-xs",children:[u.length," 项"]})]}),a.description&&e.jsx(os,{className:"ml-6",children:a.description})]})}),e.jsx(xc,{children:e.jsx(Me,{className:"space-y-4 pt-0",children:u.map(([h,f])=>e.jsx(fC,{field:f,value:n[a.name]?.[h],onChange:p=>r(a.name,h,p),sectionName:a.name},h))})})]})})}function pC({plugin:a,onBack:n}){const{toast:r}=Ys(),{triggerRestart:c,isRestarting:d}=yn(),[u,h]=m.useState("visual"),[f,p]=m.useState(null),[g,N]=m.useState({}),[v,w]=m.useState({}),[b,y]=m.useState(""),[O,R]=m.useState(""),[S,B]=m.useState(!0),[E,C]=m.useState(!1),[A,F]=m.useState(!1),[L,J]=m.useState(!1),[U,oe]=m.useState(!1),Ne=m.useCallback(async()=>{B(!0);try{const[P,ue,Q]=await Promise.all([eC(a.id),sC(a.id),tC(a.id)]);p(P),N(ue),w(JSON.parse(JSON.stringify(ue))),y(Q),R(Q)}catch(P){r({title:"加载配置失败",description:P instanceof Error?P.message:"未知错误",variant:"destructive"})}finally{B(!1)}},[a.id,r]);m.useEffect(()=>{Ne()},[Ne]),m.useEffect(()=>{F(u==="visual"?JSON.stringify(g)!==JSON.stringify(v):b!==O)},[g,v,b,O,u]);const je=(P,ue,Q)=>{N(Se=>({...Se,[P]:{...Se[P]||{},[ue]:Q}}))},re=async()=>{C(!0);try{if(u==="source"){try{Zv(b)}catch(P){J(!0),r({title:"TOML 格式错误",description:P instanceof Error?P.message:"无法解析 TOML 配置,请检查语法",variant:"destructive"}),C(!1);return}await lC(a.id,b),R(b),J(!1)}else await aC(a.id,g),w(JSON.parse(JSON.stringify(g)));r({title:"配置已保存",description:"更改将在插件重新加载后生效"})}catch(P){r({title:"保存失败",description:P instanceof Error?P.message:"未知错误",variant:"destructive"})}finally{C(!1)}},fe=async()=>{try{await nC(a.id),r({title:"配置已重置",description:"下次加载插件时将使用默认配置"}),oe(!1),Ne()}catch(P){r({title:"重置失败",description:P instanceof Error?P.message:"未知错误",variant:"destructive"})}},ge=async()=>{try{const P=await rC(a.id);r({title:P.message,description:P.note}),Ne()}catch(P){r({title:"切换状态失败",description:P instanceof Error?P.message:"未知错误",variant:"destructive"})}};if(S)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!f)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 space-y-4",children:[e.jsx(_t,{className:"h-12 w-12 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"无法加载配置"}),e.jsxs(_,{onClick:n,variant:"outline",children:[e.jsx(Ma,{className:"h-4 w-4 mr-2"}),"返回"]})]});const M=Object.values(f.sections).sort((P,ue)=>P.order-ue.order),K=g.plugin?.enabled!==!1;return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:n,children:e.jsx(Ma,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:f.plugin_info.name||a.manifest.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(ke,{variant:K?"default":"secondary",children:K?"已启用":"已禁用"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["v",f.plugin_info.version||a.manifest.version]})]})]})]}),e.jsxs("div",{className:"flex gap-2 ml-10 sm:ml-0",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>h(u==="visual"?"source":"visual"),children:u==="visual"?e.jsxs(e.Fragment,{children:[e.jsx(lv,{className:"h-4 w-4 mr-2"}),"源代码"]}):e.jsxs(e.Fragment,{children:[e.jsx(av,{className:"h-4 w-4 mr-2"}),"可视化"]})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>c(),disabled:d,children:[e.jsx(iv,{className:`h-4 w-4 mr-2 ${d?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:ge,children:[e.jsx(hc,{className:"h-4 w-4 mr-2"}),K?"禁用":"启用"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>oe(!0),children:[e.jsx(lc,{className:"h-4 w-4 mr-2"}),"重置"]}),e.jsxs(_,{size:"sm",onClick:re,disabled:!A||E,children:[E?e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(fc,{className:"h-4 w-4 mr-2"}),"保存"]})]})]}),A&&e.jsx(Ce,{className:"border-orange-200 bg-orange-50 dark:bg-orange-950/20 dark:border-orange-900",children:e.jsx(Me,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ft,{className:"h-4 w-4 text-orange-600"}),e.jsx("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:"有未保存的更改"})]})})}),u==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsxs(lt,{children:[e.jsx("strong",{children:"源代码模式(高级功能):"}),"直接编辑 TOML 配置文件。保存时会验证格式,只有格式正确才能保存。",L&&e.jsx("span",{className:"text-destructive font-semibold ml-2",children:"⚠️ 上次保存失败,请检查 TOML 格式"})]})]}),e.jsx(Iv,{value:b,onChange:P=>{y(P),L&&J(!1)},language:"toml",theme:"dark",height:"calc(100vh - 350px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),u==="visual"&&e.jsxs(e.Fragment,{children:[e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsxs(lt,{children:[e.jsx("strong",{children:"提示:"}),"如果插件当前未加载或未启用,WebUI 适配器的高级插件可视化编辑功能可能会不可用。 请确保插件已启用并成功加载后,再进行配置编辑。"]})]}),f.layout.type==="tabs"&&f.layout.tabs.length>0?e.jsxs(ta,{defaultValue:f.layout.tabs[0]?.id,children:[e.jsx(Zt,{children:f.layout.tabs.map(P=>e.jsxs(Xe,{value:P.id,children:[P.title,P.badge&&e.jsx(ke,{variant:"secondary",className:"ml-2 text-xs",children:P.badge})]},P.id))}),f.layout.tabs.map(P=>e.jsx(ws,{value:P.id,className:"space-y-4 mt-4",children:P.sections.map(ue=>{const Q=f.sections[ue];return Q?e.jsx(Xg,{section:Q,config:g,onChange:je},ue):null})},P.id))]}):e.jsx("div",{className:"space-y-4",children:M.map(P=>e.jsx(Xg,{section:P,config:g,onChange:je},P.name))})]}),e.jsx(Ps,{open:U,onOpenChange:oe,children:e.jsxs(Ds,{children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"确认重置配置"}),e.jsx(Ks,{children:"这将删除当前配置文件,下次加载插件时将使用默认配置。此操作不可撤销。"})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>oe(!1),children:"取消"}),e.jsx(_,{variant:"destructive",onClick:fe,children:"确认重置"})]})]})})]})}function gC(){return e.jsx(Wn,{children:e.jsx(jC,{})})}function jC(){const{toast:a}=Ys(),[n,r]=m.useState([]),[c,d]=m.useState(!0),[u,h]=m.useState(""),[f,p]=m.useState(null),g=async()=>{d(!0);try{const y=await Dl();r(y)}catch(y){a({title:"加载插件列表失败",description:y instanceof Error?y.message:"未知错误",variant:"destructive"})}finally{d(!1)}};m.useEffect(()=>{g()},[]);const v=n.filter(y=>{const O=u.toLowerCase();return y.id.toLowerCase().includes(O)||y.manifest.name.toLowerCase().includes(O)||y.manifest.description?.toLowerCase().includes(O)}).filter((y,O,R)=>O===R.findIndex(S=>S.id===y.id)),w=n.length,b=0;return f?e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"h-full",children:e.jsx("div",{className:"p-4 sm:p-6",children:e.jsx(pC,{plugin:f,onBack:()=>p(null)})})}),e.jsx(er,{})]}):e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理和配置已安装的插件"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:g,children:[e.jsx(dt,{className:`h-4 w-4 mr-2 ${c?"animate-spin":""}`}),"刷新"]})]}),e.jsxs("div",{className:"grid gap-4 grid-cols-1 xs:grid-cols-2 lg:grid-cols-3",children:[e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"已安装插件"}),e.jsx(ra,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Me,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n.length}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:c?"正在加载...":"个插件"})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"已启用"}),e.jsx(pt,{className:"h-4 w-4 text-green-600"})]}),e.jsxs(Me,{children:[e.jsx("div",{className:"text-2xl font-bold",children:w}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"运行中的插件"})]})]}),e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:"已禁用"}),e.jsx(_t,{className:"h-4 w-4 text-orange-600"})]}),e.jsxs(Me,{children:[e.jsx("div",{className:"text-2xl font-bold",children:b}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"未激活的插件"})]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ae,{placeholder:"搜索插件...",value:u,onChange:y=>h(y.target.value),className:"pl-9"})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"已安装的插件"}),e.jsx(os,{children:"点击插件查看和编辑配置"})]}),e.jsx(Me,{children:c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):v.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 space-y-4",children:[e.jsx(ra,{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:u?"没有找到匹配的插件":"暂无已安装的插件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u?"尝试其他搜索关键词":"前往插件市场安装插件"})]})]}):e.jsx("div",{className:"space-y-2",children:v.map(y=>e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg border hover:bg-muted/50 cursor-pointer transition-colors",onClick:()=>p(y),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(ra,{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:y.manifest.name}),e.jsxs(ke,{variant:"secondary",className:"text-xs flex-shrink-0",children:["v",y.manifest.version]})]}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:y.manifest.description||"暂无描述"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(_,{variant:"ghost",size:"sm",children:e.jsx(vn,{className:"h-4 w-4"})}),e.jsx(Wt,{className:"h-4 w-4 text-muted-foreground"})]})]},y.id))})})]})]})})}function vC(){const a=ca(),{toast:n}=Ys(),[r,c]=m.useState([]),[d,u]=m.useState(!0),[h,f]=m.useState(null),[p,g]=m.useState(null),[N,v]=m.useState(!1),[w,b]=m.useState(!1),[y,O]=m.useState({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),R=m.useCallback(async()=>{try{u(!0),f(null);const L=await _e("/api/webui/plugins/mirrors");if(!L.ok)throw new Error("获取镜像源列表失败");const J=await L.json();c(J.mirrors||[])}catch(L){const J=L instanceof Error?L.message:"加载镜像源失败";f(J),n({title:"加载失败",description:J,variant:"destructive"})}finally{u(!1)}},[n]);m.useEffect(()=>{R()},[R]);const S=async()=>{try{const L=await _e("/api/webui/plugins/mirrors",{method:"POST",body:JSON.stringify(y)});if(!L.ok){const J=await L.json();throw new Error(J.detail||"添加镜像源失败")}n({title:"添加成功",description:"镜像源已添加"}),v(!1),O({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),R()}catch(L){n({title:"添加失败",description:L instanceof Error?L.message:"未知错误",variant:"destructive"})}},B=async()=>{if(p)try{if(!(await _e(`/api/webui/plugins/mirrors/${p.id}`,{method:"PUT",body:JSON.stringify({name:y.name,raw_prefix:y.raw_prefix,clone_prefix:y.clone_prefix,enabled:y.enabled,priority:y.priority})})).ok)throw new Error("更新镜像源失败");n({title:"更新成功",description:"镜像源已更新"}),b(!1),g(null),R()}catch(L){n({title:"更新失败",description:L instanceof Error?L.message:"未知错误",variant:"destructive"})}},E=async L=>{if(confirm("确定要删除这个镜像源吗?"))try{if(!(await _e(`/api/webui/plugins/mirrors/${L}`,{method:"DELETE"})).ok)throw new Error("删除镜像源失败");n({title:"删除成功",description:"镜像源已删除"}),R()}catch(J){n({title:"删除失败",description:J instanceof Error?J.message:"未知错误",variant:"destructive"})}},C=async L=>{try{if(!(await _e(`/api/webui/plugins/mirrors/${L.id}`,{method:"PUT",body:JSON.stringify({enabled:!L.enabled})})).ok)throw new Error("更新状态失败");R()}catch(J){n({title:"更新失败",description:J instanceof Error?J.message:"未知错误",variant:"destructive"})}},A=L=>{g(L),O({id:L.id,name:L.name,raw_prefix:L.raw_prefix,clone_prefix:L.clone_prefix,enabled:L.enabled,priority:L.priority}),b(!0)},F=async(L,J)=>{const U=J==="up"?L.priority-1:L.priority+1;if(!(U<1))try{if(!(await _e(`/api/webui/plugins/mirrors/${L.id}`,{method:"PUT",body:JSON.stringify({priority:U})})).ok)throw new Error("更新优先级失败");R()}catch(oe){n({title:"更新失败",description:oe instanceof Error?oe.message:"未知错误",variant:"destructive"})}};return e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>a({to:"/plugins"}),children:e.jsx(Ma,{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(_,{onClick:()=>v(!0),children:[e.jsx(et,{className:"h-4 w-4 mr-2"}),"添加镜像源"]})]}),d?e.jsx(Ce,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(zs,{className:"h-8 w-8 animate-spin text-primary"})})}):h?e.jsx(Ce,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Jt,{className:"h-12 w-12 text-destructive mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"加载失败"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:h}),e.jsx(_,{onClick:R,children:"重新加载"})]})}):e.jsxs(Ce,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{children:"状态"}),e.jsx(We,{children:"名称"}),e.jsx(We,{children:"ID"}),e.jsx(We,{children:"优先级"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Bl,{children:r.map(L=>e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(Ve,{checked:L.enabled,onCheckedChange:()=>C(L)})}),e.jsx(Ke,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:L.name}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Raw: ",L.raw_prefix]})]})}),e.jsx(Ke,{children:e.jsx(ke,{variant:"outline",children:L.id})}),e.jsx(Ke,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono",children:L.priority}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(_,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>F(L,"up"),disabled:L.priority===1,children:e.jsx(Qr,{className:"h-3 w-3"})}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>F(L,"down"),children:e.jsx(za,{className:"h-3 w-3"})})]})]})}),e.jsx(Ke,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>A(L),children:e.jsx(Kn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>E(L.id),children:e.jsx(ns,{className:"h-4 w-4 text-destructive"})})]})})]},L.id))})]})}),e.jsx("div",{className:"md:hidden p-4 space-y-4",children:r.map(L=>e.jsx(Ce,{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:L.name}),L.enabled&&e.jsx(ke,{variant:"default",className:"text-xs",children:"启用"})]}),e.jsx(ke,{variant:"outline",className:"mt-1 text-xs",children:L.id})]}),e.jsx(Ve,{checked:L.enabled,onCheckedChange:()=>C(L)})]}),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:L.raw_prefix})]}),e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"优先级: "}),e.jsx("span",{className:"font-mono",children:L.priority})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t",children:[e.jsxs(_,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>A(L),children:[e.jsx(Kn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>F(L,"up"),disabled:L.priority===1,children:e.jsx(Qr,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>F(L,"down"),children:e.jsx(za,{className:"h-4 w-4"})}),e.jsx(_,{variant:"destructive",size:"sm",onClick:()=>E(L.id),children:e.jsx(ns,{className:"h-4 w-4"})})]})]})},L.id))})]}),e.jsx(Ps,{open:N,onOpenChange:v,children:e.jsxs(Ds,{className:"max-w-lg",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"添加镜像源"}),e.jsx(Ks,{children:"添加新的 Git 镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-id",children:"镜像源 ID *"}),e.jsx(ae,{id:"add-id",placeholder:"例如: my-mirror",value:y.id,onChange:L=>O({...y,id:L.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-name",children:"名称 *"}),e.jsx(ae,{id:"add-name",placeholder:"例如: 我的镜像源",value:y.name,onChange:L=>O({...y,name:L.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-raw",children:"Raw 文件前缀 *"}),e.jsx(ae,{id:"add-raw",placeholder:"https://example.com/raw",value:y.raw_prefix,onChange:L=>O({...y,raw_prefix:L.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-clone",children:"克隆前缀 *"}),e.jsx(ae,{id:"add-clone",placeholder:"https://example.com/clone",value:y.clone_prefix,onChange:L=>O({...y,clone_prefix:L.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"add-priority",children:"优先级"}),e.jsx(ae,{id:"add-priority",type:"number",min:"1",value:y.priority,onChange:L=>O({...y,priority:parseInt(L.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(Ve,{id:"add-enabled",checked:y.enabled,onCheckedChange:L=>O({...y,enabled:L})}),e.jsx(T,{htmlFor:"add-enabled",children:"启用此镜像源"})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>v(!1),children:"取消"}),e.jsx(_,{onClick:S,children:"添加"})]})]})}),e.jsx(Ps,{open:w,onOpenChange:b,children:e.jsxs(Ds,{className:"max-w-lg",children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"编辑镜像源"}),e.jsx(Ks,{children:"修改镜像源配置"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"镜像源 ID"}),e.jsx(ae,{value:y.id,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-name",children:"名称 *"}),e.jsx(ae,{id:"edit-name",value:y.name,onChange:L=>O({...y,name:L.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-raw",children:"Raw 文件前缀 *"}),e.jsx(ae,{id:"edit-raw",value:y.raw_prefix,onChange:L=>O({...y,raw_prefix:L.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-clone",children:"克隆前缀 *"}),e.jsx(ae,{id:"edit-clone",value:y.clone_prefix,onChange:L=>O({...y,clone_prefix:L.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"edit-priority",children:"优先级"}),e.jsx(ae,{id:"edit-priority",type:"number",min:"1",value:y.priority,onChange:L=>O({...y,priority:parseInt(L.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(Ve,{id:"edit-enabled",checked:y.enabled,onCheckedChange:L=>O({...y,enabled:L})}),e.jsx(T,{htmlFor:"edit-enabled",children:"启用此镜像源"})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>b(!1),children:"取消"}),e.jsx(_,{onClick:B,children:"保存"})]})]})})]})})}function NC({pluginId:a,compact:n=!1}){const[r,c]=m.useState(null),[d,u]=m.useState(!0),[h,f]=m.useState(0),[p,g]=m.useState(""),[N,v]=m.useState(!1),{toast:w}=Ys(),b=async()=>{u(!0);const S=await mN(a);S&&c(S),u(!1)};m.useEffect(()=>{b()},[a]);const y=async()=>{const S=await iC(a);S.success?(w({title:"已点赞",description:"感谢你的支持!"}),b()):w({title:"点赞失败",description:S.error||"未知错误",variant:"destructive"})},O=async()=>{const S=await cC(a);S.success?(w({title:"已反馈",description:"感谢你的反馈!"}),b()):w({title:"操作失败",description:S.error||"未知错误",variant:"destructive"})},R=async()=>{if(h===0){w({title:"请选择评分",description:"至少选择 1 颗星",variant:"destructive"});return}const S=await oC(a,h,p||void 0);S.success?(w({title:"评分成功",description:"感谢你的评价!"}),v(!1),f(0),g(""),b()):w({title:"评分失败",description:S.error||"未知错误",variant:"destructive"})};return d?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(Xt,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(mn,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]})]}):r?n?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",title:`下载量: ${r.downloads.toLocaleString()}`,children:[e.jsx(Xt,{className:"h-4 w-4"}),e.jsx("span",{children:r.downloads.toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`评分: ${r.rating.toFixed(1)} (${r.rating_count} 条评价)`,children:[e.jsx(mn,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:r.rating.toFixed(1)})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`点赞数: ${r.likes}`,children:[e.jsx(Em,{className:"h-4 w-4"}),e.jsx("span",{children:r.likes})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Xt,{className:"h-5 w-5 text-muted-foreground mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.downloads.toLocaleString()}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"下载量"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(mn,{className:"h-5 w-5 text-yellow-400 mb-1 fill-yellow-400"}),e.jsx("span",{className:"text-2xl font-bold",children:r.rating.toFixed(1)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[r.rating_count," 条评价"]})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(Em,{className:"h-5 w-5 text-green-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.likes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点赞"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(wg,{className:"h-5 w-5 text-red-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:r.dislikes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点踩"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:y,children:[e.jsx(Em,{className:"h-4 w-4 mr-1"}),"点赞"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:O,children:[e.jsx(wg,{className:"h-4 w-4 mr-1"}),"点踩"]}),e.jsxs(Ps,{open:N,onOpenChange:v,children:[e.jsx(cd,{asChild:!0,children:e.jsxs(_,{variant:"default",size:"sm",children:[e.jsx(mn,{className:"h-4 w-4 mr-1"}),"评分"]})}),e.jsxs(Ds,{children:[e.jsxs(Os,{children:[e.jsx(Ls,{children:"为插件评分"}),e.jsx(Ks,{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(S=>e.jsx("button",{onClick:()=>f(S),className:"focus:outline-none",children:e.jsx(mn,{className:`h-8 w-8 transition-colors ${S<=h?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-yellow-300"}`})},S))}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h===0&&"点击星星进行评分",h===1&&"很差",h===2&&"一般",h===3&&"还行",h===4&&"不错",h===5&&"非常好"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"评论(可选)"}),e.jsx(ot,{value:p,onChange:S=>g(S.target.value),placeholder:"分享你的使用体验...",rows:4,maxLength:500}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 text-right",children:[p.length," / 500"]})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>v(!1),children:"取消"}),e.jsx(_,{onClick:R,disabled:h===0,children:"提交评分"})]})]})]})]}),r.recent_ratings&&r.recent_ratings.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"最近评价"}),e.jsx("div",{className:"space-y-3",children:r.recent_ratings.map((S,B)=>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(E=>e.jsx(mn,{className:`h-3 w-3 ${E<=S.rating?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},E))}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(S.created_at).toLocaleDateString()})]}),S.comment&&e.jsx("p",{className:"text-sm text-muted-foreground",children:S.comment})]},B))})]})]}):null}const bC={"Group Management":"群组管理","Entertainment & Interaction":"娱乐互动","Utility Tools":"实用工具","Content Generation":"内容生成",Multimedia:"多媒体","External Integration":"外部集成","Data Analysis & Insights":"数据分析与洞察",Other:"其他"};function yC(){const a=ca(),n=J0({strict:!1}),{toast:r}=Ys(),[c,d]=m.useState(null),[u,h]=m.useState(""),[f,p]=m.useState(!0),[g,N]=m.useState(!0),[v,w]=m.useState(null),[b,y]=m.useState(null),[O,R]=m.useState(null),[S,B]=m.useState(!1),[E,C]=m.useState(),[A,F]=m.useState(!1);m.useEffect(()=>{(async()=>{if(!n.pluginId){w("缺少插件 ID"),p(!1);return}try{p(!0),w(null);const fe=await _e("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:"Mai-with-u",repo:"plugin-repo",branch:"main",file_path:"plugin_details.json"})});if(!fe.ok)throw new Error("获取插件列表失败");const ge=await fe.json();if(!ge.success||!ge.data)throw new Error(ge.error||"获取插件列表失败");const K=JSON.parse(ge.data).find(pe=>pe.id===n.pluginId);if(!K)throw new Error("未找到该插件");const P={id:K.id,manifest:K.manifest,downloads:0,rating:0,review_count:0,installed:!1,published_at:new Date().toISOString(),updated_at:new Date().toISOString()};d(P);const[ue,Q,Se]=await Promise.all([rN(),iN(),Dl()]);y(ue),R(Q),B(hn(n.pluginId,Se)),C(fn(n.pluginId,Se))}catch(fe){w(fe instanceof Error?fe.message:"加载失败")}finally{p(!1)}})()},[n.pluginId]),m.useEffect(()=>{(async()=>{if(!c?.manifest?.repository_url){N(!1);return}try{if(N(!0),S&&n.pluginId)try{const Q=await _e(`/api/webui/plugins/local-readme/${n.pluginId}`);if(Q.ok){const Se=await Q.json();if(Se.success&&Se.data){h(Se.data),N(!1);return}}}catch(Q){console.log("本地 README 获取失败,尝试远程获取:",Q)}const fe=c.manifest.repository_url.match(/github\.com\/([^/]+)\/([^/\s]+)/);if(!fe){h("无法解析仓库地址");return}const[,ge,M]=fe,K=M.replace(/\.git$/,""),P=await _e("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:ge,repo:K,branch:"main",file_path:"README.md"})});if(!P.ok)throw new Error("获取 README 失败");const ue=await P.json();ue.success&&ue.data?h(ue.data):h("该插件暂无 README 文档")}catch(fe){console.error("加载 README 失败:",fe),h("加载 README 失败")}finally{N(!1)}})()},[c,S,n.pluginId]);const L=()=>!c||!S||!E?!1:E!==c.manifest.version,J=()=>!c||!O?!0:cN(c.manifest.host_application.min_version,c.manifest.host_application.max_version,O),U=async()=>{if(!(!c||!b?.installed))try{F(!0),await oN(c.id,c.manifest.repository_url||"","main"),xN(c.id).catch(fe=>{console.warn("Failed to record download:",fe)}),r({title:"安装成功",description:`${c.manifest.name} 已成功安装`});const re=await Dl();B(hn(c.id,re)),C(fn(c.id,re))}catch(re){r({title:"安装失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"})}finally{F(!1)}},oe=async()=>{if(c)try{F(!0),await dN(c.id),r({title:"卸载成功",description:`${c.manifest.name} 已成功卸载`});const re=await Dl();B(hn(c.id,re)),C(fn(c.id,re))}catch(re){r({title:"卸载失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"})}finally{F(!1)}},Ne=async()=>{if(!(!c||!b?.installed))try{F(!0);const re=await uN(c.id,c.manifest.repository_url||"","main");r({title:"更新成功",description:`${c.manifest.name} 已从 ${re.old_version} 更新到 ${re.new_version}`});const fe=await Dl();B(hn(c.id,fe)),C(fn(c.id,fe))}catch(re){r({title:"更新失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"})}finally{F(!1)}};if(f)return e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>a({to:"/plugins"}),children:e.jsx(Ma,{className:"h-5 w-5"})}),e.jsx("div",{children:e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件详情"})})]}),e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件信息中..."})]})]});if(v||!c)return e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>a({to:"/plugins"}),children:e.jsx(Ma,{className:"h-5 w-5"})}),e.jsx("div",{children:e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件详情"})})]}),e.jsx(Ce,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(_t,{className:"h-12 w-12 text-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:v}),e.jsx(_,{onClick:()=>a({to:"/plugins"}),children:"返回插件列表"})]})})]});const je=J();return 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",{className:"flex items-center gap-3",children:[e.jsx(_,{variant:"ghost",size:"icon",onClick:()=>a({to:"/plugins"}),className:"shrink-0",children:e.jsx(Ma,{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-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:c.manifest.name})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:S?e.jsxs(e.Fragment,{children:[L()?e.jsx(_,{disabled:!b?.installed||A,onClick:Ne,title:b?.installed?void 0:"Git 未安装",children:A?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"更新中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(dt,{className:"h-4 w-4 mr-2"}),"更新"]})}):null,e.jsx(_,{variant:"destructive",disabled:!b?.installed||A,onClick:oe,title:b?.installed?void 0:"Git 未安装",children:A?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"卸载中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ns,{className:"h-4 w-4 mr-2"}),"卸载"]})})]}):e.jsx(_,{disabled:!b?.installed||!je||A,onClick:U,title:b?.installed?je?void 0:`不兼容当前版本 (需要 ${c.manifest.host_application.min_version}${c.manifest.host_application.max_version?` - ${c.manifest.host_application.max_version}`:"+"},当前 ${O?.version})`:"Git 未安装",children:A?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"安装中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Xt,{className:"h-4 w-4 mr-2"}),"安装"]})})})]}),e.jsx(Je,{className:"h-[calc(100vh-200px)] sm:h-[calc(100vh-220px)]",children:e.jsxs("div",{className:"space-y-6 pr-4",children:[e.jsx(Ce,{children:e.jsx(De,{children:e.jsx("div",{className:"flex items-start justify-between gap-4",children:e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx(Oe,{className:"text-2xl",children:c.manifest.name}),e.jsxs(ke,{variant:"secondary",className:"text-sm",children:["v",c.manifest.version]}),S&&e.jsxs(ke,{variant:"default",className:"text-sm",children:[e.jsx(pt,{className:"h-3 w-3 mr-1"}),"已安装 ",E&&`(v${E})`]}),L()&&e.jsxs(ke,{variant:"outline",className:"text-sm border-orange-500 text-orange-500",children:[e.jsx(dt,{className:"h-3 w-3 mr-1"}),"可更新"]}),!je&&e.jsxs(ke,{variant:"destructive",className:"text-sm",children:[e.jsx(_t,{className:"h-3 w-3 mr-1"}),"不兼容"]})]}),e.jsx(os,{className:"text-base",children:c.manifest.description})]})})})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-1 space-y-6",children:[e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{className:"text-lg",children:"统计信息"})}),e.jsx(Me,{children:e.jsx(NC,{pluginId:c.id})})]}),e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{className:"text-lg",children:"基本信息"})}),e.jsx(Me,{className:"space-y-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(jn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"作者:"}),e.jsx("span",{className:"font-medium",children:c.manifest.author?.name||"Unknown"}),c.manifest.author?.url&&e.jsx("a",{href:c.manifest.author.url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:e.jsx($o,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ra,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"版本:"}),e.jsxs("span",{className:"font-medium",children:["v",c.manifest.version]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ev,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"许可证:"}),e.jsx("span",{className:"font-medium",children:c.manifest.license})]}),c.manifest.homepage_url&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Vo,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"主页:"}),e.jsxs("a",{href:c.manifest.homepage_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline flex items-center gap-1",children:["访问",e.jsx($o,{className:"h-3 w-3"})]})]}),c.manifest.repository_url&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(I_,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"仓库:"}),e.jsxs("a",{href:c.manifest.repository_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline flex items-center gap-1",children:["GitHub",e.jsx($o,{className:"h-3 w-3"})]})]}),e.jsxs("div",{className:"pt-2 border-t",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm mb-2",children:[e.jsx(Ft,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"支持版本:"})]}),e.jsxs("div",{className:"text-sm pl-6 font-medium",children:[c.manifest.host_application.min_version,c.manifest.host_application.max_version?` - ${c.manifest.host_application.max_version}`:" - 最新版本"]})]})]})})]}),(c.manifest.categories||c.manifest.keywords)&&e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{className:"text-lg",children:"分类与标签"})}),e.jsxs(Me,{className:"space-y-4",children:[c.manifest.categories&&c.manifest.categories.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"分类"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:c.manifest.categories.map(re=>e.jsx(ke,{variant:"secondary",children:bC[re]||re},re))})]}),c.manifest.keywords&&c.manifest.keywords.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"标签"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:c.manifest.keywords.map(re=>e.jsxs(ke,{variant:"outline",className:"text-xs",children:[e.jsx(rd,{className:"h-3 w-3 mr-1"}),re]},re))})]})]})]})]}),e.jsxs(Ce,{className:"lg:col-span-2",children:[e.jsx(De,{children:e.jsx(Oe,{className:"text-lg",children:"插件说明"})}),e.jsx(Me,{children:e.jsx(Je,{className:"h-[600px] pr-4",children:g?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(zs,{className:"h-6 w-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-sm text-muted-foreground",children:"加载说明文档中..."})]}):u?e.jsx(fx,{content:u}):e.jsx("div",{className:"text-center text-muted-foreground py-12",children:"暂无说明文档"})})})]})]})]})})]})}const Zi=m.forwardRef(({className:a,...n},r)=>e.jsx(_j,{ref:r,className:I("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",a),...n}));Zi.displayName=_j.displayName;const wC=m.forwardRef(({className:a,...n},r)=>e.jsx(Sj,{ref:r,className:I("aspect-square h-full w-full",a),...n}));wC.displayName=Sj.displayName;const Wi=m.forwardRef(({className:a,...n},r)=>e.jsx(kj,{ref:r,className:I("flex h-full w-full items-center justify-center rounded-full bg-muted",a),...n}));Wi.displayName=kj.displayName;function _C(){return"webui_"+Math.random().toString(36).substr(2,9)+"_"+Date.now().toString(36)}function SC(){const a="maibot_webui_user_id";let n=localStorage.getItem(a);return n||(n=_C(),localStorage.setItem(a,n)),n}function kC(){return localStorage.getItem("maibot_webui_user_name")||"WebUI用户"}function CC(a){localStorage.setItem("maibot_webui_user_name",a)}const hN="maibot_webui_virtual_tabs";function TC(){try{const a=localStorage.getItem(hN);if(a)return JSON.parse(a)}catch(a){console.error("[Chat] 加载虚拟标签页失败:",a)}return[]}function Zg(a){try{localStorage.setItem(hN,JSON.stringify(a))}catch(n){console.error("[Chat] 保存虚拟标签页失败:",n)}}function EC({segment:a}){switch(a.type){case"text":return e.jsx("span",{className:"whitespace-pre-wrap",children:String(a.data)});case"image":case"emoji":return e.jsx("img",{src:String(a.data),alt:a.type==="emoji"?"表情包":"图片",className:I("rounded-lg max-w-full",a.type==="emoji"?"max-h-32":"max-h-64"),loading:"lazy",onError:n=>{const r=n.target;r.style.display="none",r.parentElement?.insertAdjacentHTML("beforeend",`[${a.type==="emoji"?"表情包":"图片"}加载失败]`)}});case"voice":return e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("audio",{controls:!0,src:String(a.data),className:"max-w-[200px] h-8",children:"您的浏览器不支持音频播放"})});case"video":return e.jsx("video",{controls:!0,src:String(a.data),className:"rounded-lg max-w-full max-h-64",children:"您的浏览器不支持视频播放"});case"face":return e.jsxs("span",{className:"text-muted-foreground",children:["[表情:",String(a.data),"]"]});case"music":return e.jsx("span",{className:"text-muted-foreground",children:"[音乐分享]"});case"file":return e.jsxs("span",{className:"text-muted-foreground",children:["[文件: ",String(a.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:["[",a.original_type||"未知消息","]"]})}}function MC({message:a,isBot:n}){return a.message_type==="rich"&&a.segments&&a.segments.length>0?e.jsx("div",{className:"flex flex-col gap-2",children:a.segments.map((r,c)=>e.jsx(EC,{segment:r},c))}):e.jsx("span",{className:"whitespace-pre-wrap",children:a.content})}function AC(){const a={id:"webui-default",type:"webui",label:"WebUI",messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}},n=()=>{const qe=TC().map(Qe=>{const es=Qe.virtualConfig;return!es.groupId&&es.platform&&es.userId&&(es.groupId=`webui_virtual_group_${es.platform}_${es.userId}`),{id:Qe.id,type:"virtual",label:Qe.label,virtualConfig:es,messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}}});return[a,...qe]},[r,c]=m.useState(n),[d,u]=m.useState("webui-default"),h=r.find(q=>q.id===d)||r[0],[f,p]=m.useState(""),[g,N]=m.useState(!1),[v,w]=m.useState(!0),[b,y]=m.useState(kC()),[O,R]=m.useState(!1),[S,B]=m.useState(""),[E,C]=m.useState(!1),[A,F]=m.useState([]),[L,J]=m.useState([]),[U,oe]=m.useState(!1),[Ne,je]=m.useState(!1),[re,fe]=m.useState(""),[ge,M]=m.useState({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),K=m.useRef(SC()),P=m.useRef(new Map),ue=m.useRef(null),Q=m.useRef(new Map),Se=m.useRef(0),pe=m.useRef(new Map),{toast:Te}=Ys(),z=q=>(Se.current+=1,`${q}-${Date.now()}-${Se.current}-${Math.random().toString(36).substr(2,9)}`),D=m.useCallback((q,qe)=>{c(Qe=>Qe.map(es=>es.id===q?{...es,...qe}:es))},[]),G=m.useCallback((q,qe)=>{c(Qe=>Qe.map(es=>es.id===q?{...es,messages:[...es.messages,qe]}:es))},[]),de=m.useCallback(()=>{ue.current?.scrollIntoView({behavior:"smooth"})},[]);m.useEffect(()=>{de()},[h?.messages,de]);const Re=m.useCallback(async()=>{oe(!0);try{const q=await _e("/api/chat/platforms");if(console.log("[Chat] 平台列表响应:",q.status,q.headers.get("content-type")),q.ok){const qe=q.headers.get("content-type");if(qe&&qe.includes("application/json")){const Qe=await q.json();console.log("[Chat] 平台列表数据:",Qe),F(Qe.platforms||[])}else{const Qe=await q.text();console.error("[Chat] 获取平台列表失败: 非 JSON 响应:",Qe.substring(0,200)),Te({title:"连接失败",description:"无法连接到后端服务,请确保 MaiBot 已启动",variant:"destructive"})}}else console.error("[Chat] 获取平台列表失败: HTTP",q.status),Te({title:"获取平台失败",description:`服务器返回错误: ${q.status}`,variant:"destructive"})}catch(q){console.error("[Chat] 获取平台列表失败:",q),Te({title:"网络错误",description:"无法连接到后端服务",variant:"destructive"})}finally{oe(!1)}},[Te]),W=m.useCallback(async(q,qe)=>{je(!0);try{const Qe=new URLSearchParams;q&&Qe.append("platform",q),qe&&Qe.append("search",qe),Qe.append("limit","50");const es=await _e(`/api/chat/persons?${Qe.toString()}`);if(es.ok){const Us=es.headers.get("content-type");if(Us&&Us.includes("application/json")){const as=await es.json();J(as.persons||[])}else console.error("[Chat] 获取用户列表失败: 后端返回非 JSON 响应")}}catch(Qe){console.error("[Chat] 获取用户列表失败:",Qe)}finally{je(!1)}},[]);m.useEffect(()=>{ge.platform&&W(ge.platform,re)},[ge.platform,re,W]);const Y=m.useCallback(async(q,qe)=>{w(!0);try{const Qe=new URLSearchParams;Qe.append("user_id",K.current),Qe.append("limit","50"),qe&&Qe.append("group_id",qe);const es=`/api/chat/history?${Qe.toString()}`;console.log("[Chat] 正在加载历史消息:",es);const Us=await _e(es);if(Us.ok){const as=await Us.text();try{const Cs=JSON.parse(as);if(Cs.messages&&Cs.messages.length>0){const ze=Cs.messages.map(ls=>({id:ls.id,type:ls.type,content:ls.content,timestamp:ls.timestamp,sender:{name:ls.sender_name||(ls.is_bot?"麦麦":"WebUI用户"),user_id:ls.user_id,is_bot:ls.is_bot}}));D(q,{messages:ze});const bs=pe.current.get(q)||new Set;ze.forEach(ls=>{if(ls.type==="bot"){const ss=`bot-${ls.content}-${Math.floor(ls.timestamp*1e3)}`;bs.add(ss)}}),pe.current.set(q,bs)}}catch(Cs){console.error("[Chat] JSON 解析失败:",Cs)}}}catch(Qe){console.error("[Chat] 加载历史消息失败:",Qe)}finally{w(!1)}},[D]),Fe=m.useCallback(async(q,qe,Qe)=>{const es=P.current.get(q);if(es?.readyState===WebSocket.OPEN||es?.readyState===WebSocket.CONNECTING){console.log(`[Tab ${q}] WebSocket 已存在,跳过连接`);return}N(!0);let Us=null;try{const bs=await _e("/api/webui/ws-token");if(bs.ok){const ls=await bs.json();if(ls.success&&ls.token)Us=ls.token;else{console.warn(`[Tab ${q}] 获取 WebSocket token 失败: ${ls.message||"未登录"}`),N(!1);return}}}catch(bs){console.error(`[Tab ${q}] 获取 WebSocket token 失败:`,bs),N(!1);return}if(!Us){N(!1);return}const as=window.location.protocol==="https:"?"wss:":"ws:",Cs=new URLSearchParams;Cs.append("token",Us),qe==="virtual"&&Qe?(Cs.append("user_id",Qe.userId),Cs.append("user_name",Qe.userName),Cs.append("platform",Qe.platform),Cs.append("person_id",Qe.personId),Cs.append("group_name",Qe.groupName||"WebUI虚拟群聊"),Qe.groupId&&Cs.append("group_id",Qe.groupId)):(Cs.append("user_id",K.current),Cs.append("user_name",b));const ze=`${as}//${window.location.host}/api/chat/ws?${Cs.toString()}`;console.log(`[Tab ${q}] 正在连接 WebSocket:`,ze);try{const bs=new WebSocket(ze);P.current.set(q,bs),bs.onopen=()=>{D(q,{isConnected:!0}),N(!1),console.log(`[Tab ${q}] WebSocket 已连接`)},bs.onmessage=ls=>{try{const ss=JSON.parse(ls.data);switch(ss.type){case"session_info":D(q,{sessionInfo:{session_id:ss.session_id,user_id:ss.user_id,user_name:ss.user_name,bot_name:ss.bot_name}});break;case"system":G(q,{id:z("sys"),type:"system",content:ss.content||"",timestamp:ss.timestamp||Date.now()/1e3});break;case"user_message":{const ys=ss.sender?.user_id,gt=qe==="virtual"&&Qe?Qe.userId:K.current;console.log(`[Tab ${q}] 收到 user_message, sender: ${ys}, current: ${gt}`);const $t=ys?ys.replace(/^webui_user_/,""):"",tt=gt?gt.replace(/^webui_user_/,""):"";if($t&&tt&&$t===tt){console.log(`[Tab ${q}] 跳过自己的消息(user_id 匹配)`);break}const Ms=pe.current.get(q)||new Set,Et=`user-${ss.content}-${Math.floor((ss.timestamp||0)*1e3)}`;if(Ms.has(Et)){console.log(`[Tab ${q}] 跳过自己的消息(内容去重)`);break}if(Ms.add(Et),pe.current.set(q,Ms),Ms.size>100){const Bt=Ms.values().next().value;Bt&&Ms.delete(Bt)}G(q,{id:ss.message_id||z("user"),type:"user",content:ss.content||"",timestamp:ss.timestamp||Date.now()/1e3,sender:ss.sender});break}case"bot_message":{D(q,{isTyping:!1});const ys=pe.current.get(q)||new Set,gt=`bot-${ss.content}-${Math.floor((ss.timestamp||0)*1e3)}`;if(ys.has(gt))break;if(ys.add(gt),pe.current.set(q,ys),ys.size>100){const $t=ys.values().next().value;$t&&ys.delete($t)}c($t=>$t.map(tt=>{if(tt.id!==q)return tt;const Ms=tt.messages.filter(Bt=>Bt.type!=="thinking"),Et={id:z("bot"),type:"bot",content:ss.content||"",message_type:ss.message_type==="rich"?"rich":"text",segments:ss.segments,timestamp:ss.timestamp||Date.now()/1e3,sender:ss.sender};return{...tt,messages:[...Ms,Et]}}));break}case"typing":D(q,{isTyping:ss.is_typing||!1});break;case"error":c(ys=>ys.map(gt=>{if(gt.id!==q)return gt;const $t=gt.messages.filter(tt=>tt.type!=="thinking");return{...gt,messages:[...$t,{id:z("error"),type:"error",content:ss.content||"发生错误",timestamp:ss.timestamp||Date.now()/1e3}]}})),Te({title:"错误",description:ss.content,variant:"destructive"});break;case"pong":break;case"history":{const ys=ss.messages||[];if(ys.length>0){const gt=pe.current.get(q)||new Set,$t=ys.map(tt=>{const Ms=tt.is_bot||!1,Et=tt.id||z(Ms?"bot":"user"),Bt=`${Ms?"bot":"user"}-${tt.content}-${Math.floor(tt.timestamp*1e3)}`;return gt.add(Bt),{id:Et,type:Ms?"bot":"user",content:tt.content,timestamp:tt.timestamp,sender:{name:tt.sender_name||(Ms?"麦麦":"用户"),user_id:tt.sender_id,is_bot:Ms}}});pe.current.set(q,gt),D(q,{messages:$t}),console.log(`[Tab ${q}] 已加载 ${$t.length} 条历史消息`)}break}default:console.log("未知消息类型:",ss.type)}}catch(ss){console.error("解析消息失败:",ss)}},bs.onclose=()=>{D(q,{isConnected:!1}),N(!1),P.current.delete(q),console.log(`[Tab ${q}] WebSocket 已断开`);const ls=Q.current.get(q);ls&&clearTimeout(ls);const ss=window.setTimeout(()=>{if(!H.current){const ys=r.find(gt=>gt.id===q);ys&&Fe(q,ys.type,ys.virtualConfig)}},5e3);Q.current.set(q,ss)},bs.onerror=ls=>{console.error(`[Tab ${q}] WebSocket 错误:`,ls),N(!1)}}catch(bs){console.error(`[Tab ${q}] 创建 WebSocket 失败:`,bs),N(!1)}},[b,D,G,Te,r]),H=m.useRef(!1);m.useEffect(()=>{H.current=!1;const q=P.current,qe=Q.current,Qe=pe.current;Y("webui-default");const es=setTimeout(()=>{H.current||(Fe("webui-default","webui"),r.forEach(as=>{as.type==="virtual"&&as.virtualConfig&&(Qe.set(as.id,new Set),setTimeout(()=>{H.current||Fe(as.id,"virtual",as.virtualConfig)},200))}))},100),Us=setInterval(()=>{q.forEach(as=>{as.readyState===WebSocket.OPEN&&as.send(JSON.stringify({type:"ping"}))})},3e4);return()=>{H.current=!0,clearTimeout(es),clearInterval(Us),qe.forEach(as=>{clearTimeout(as)}),qe.clear(),q.forEach(as=>{as.close()}),q.clear()}},[]);const ee=m.useCallback(()=>{const q=P.current.get(d);if(!f.trim()||!q||q.readyState!==WebSocket.OPEN)return;const qe=h?.type==="virtual"&&h.virtualConfig?.userName||b,Qe=f.trim(),es=Date.now()/1e3;q.send(JSON.stringify({type:"message",content:Qe,user_name:qe}));const Us=pe.current.get(d)||new Set,as=`user-${Qe}-${Math.floor(es*1e3)}`;if(Us.add(as),pe.current.set(d,Us),Us.size>100){const bs=Us.values().next().value;bs&&Us.delete(bs)}const Cs={id:z("user"),type:"user",content:Qe,timestamp:es,sender:{name:qe,is_bot:!1}};G(d,Cs);const ze={id:z("thinking"),type:"thinking",content:"",timestamp:es+.001,sender:{name:h?.sessionInfo.bot_name||"麦麦",is_bot:!0}};G(d,ze),p("")},[f,b,d,h,G]),Ue=q=>{q.key==="Enter"&&!q.shiftKey&&(q.preventDefault(),ee())},ie=()=>{B(b),R(!0)},Ee=()=>{const q=S.trim()||"WebUI用户";y(q),CC(q),R(!1);const qe=P.current.get(d);qe?.readyState===WebSocket.OPEN&&qe.send(JSON.stringify({type:"update_nickname",user_name:q}))},me=()=>{B(""),R(!1)},Ae=q=>new Date(q*1e3).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),rs=()=>{const q=P.current.get(d);q&&(q.close(),P.current.delete(d)),Fe(d,h?.type||"webui",h?.virtualConfig)},Ut=()=>{M({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),fe(""),Re(),C(!0)},aa=()=>{if(!ge.platform||!ge.personId){Te({title:"配置不完整",description:"请选择平台和用户",variant:"destructive"});return}const q=`webui_virtual_group_${ge.platform}_${ge.userId}`,qe=`virtual-${ge.platform}-${ge.userId}-${Date.now()}`,Qe=ge.userName||ge.userId,es={id:qe,type:"virtual",label:Qe,virtualConfig:{...ge,groupId:q},messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}};c(Us=>{const as=[...Us,es],Cs=as.filter(ze=>ze.type==="virtual"&&ze.virtualConfig).map(ze=>({id:ze.id,label:ze.label,virtualConfig:ze.virtualConfig,createdAt:Date.now()}));return Zg(Cs),as}),u(qe),C(!1),pe.current.set(qe,new Set),setTimeout(()=>{Fe(qe,"virtual",ge)},100),Te({title:"虚拟身份标签页",description:`已创建 ${Qe} 的对话`})},Ja=(q,qe)=>{if(qe?.stopPropagation(),q==="webui-default")return;const Qe=P.current.get(q);Qe&&(Qe.close(),P.current.delete(q));const es=Q.current.get(q);es&&(clearTimeout(es),Q.current.delete(q)),pe.current.delete(q),c(Us=>{const as=Us.filter(ze=>ze.id!==q),Cs=as.filter(ze=>ze.type==="virtual"&&ze.virtualConfig).map(ze=>({id:ze.id,label:ze.label,virtualConfig:ze.virtualConfig,createdAt:Date.now()}));return Zg(Cs),as}),d===q&&u("webui-default")},Ht=q=>{u(q)},mt=q=>{M(qe=>({...qe,personId:q.person_id,userId:q.user_id,userName:q.nickname||q.person_name}))};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx(Ps,{open:E,onOpenChange:C,children:e.jsxs(Ds,{className:"sm:max-w-[500px] max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(Mm,{className:"h-5 w-5"}),"新建虚拟身份对话"]}),e.jsx(Ks,{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(T,{className:"flex items-center gap-2",children:[e.jsx(Vo,{className:"h-4 w-4"}),"选择平台"]}),e.jsxs(Pe,{value:ge.platform,onValueChange:q=>{M(qe=>({...qe,platform:q,personId:"",userId:"",userName:""})),J([])},children:[e.jsx($e,{disabled:U,children:e.jsx(Ie,{placeholder:U?"加载中...":"选择平台"})}),e.jsx(Be,{children:A.map(q=>e.jsxs(Z,{value:q.platform,children:[q.platform," (",q.count," 人)"]},q.platform))})]})]}),ge.platform&&e.jsxs("div",{className:"space-y-2 flex-1 overflow-hidden flex flex-col",children:[e.jsxs(T,{className:"flex items-center gap-2",children:[e.jsx(ic,{className:"h-4 w-4"}),"选择用户"]}),e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ae,{placeholder:"搜索用户名...",value:re,onChange:q=>fe(q.target.value),className:"pl-9"})]}),e.jsx(Je,{className:"h-[250px] border rounded-md",children:e.jsx("div",{className:"p-2",children:Ne?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(zs,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):L.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[e.jsx(ic,{className:"h-8 w-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"没有找到用户"})]}):e.jsx("div",{className:"space-y-1",children:L.map(q=>e.jsxs("button",{onClick:()=>mt(q),className:I("w-full flex items-center gap-3 p-2 rounded-md text-left transition-colors",ge.personId===q.person_id?"bg-primary text-primary-foreground":"hover:bg-muted"),children:[e.jsx(Zi,{className:"h-8 w-8 shrink-0",children:e.jsx(Wi,{className:I("text-xs",ge.personId===q.person_id?"bg-primary-foreground/20":"bg-muted"),children:(q.nickname||q.person_name||"?").charAt(0)})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-medium truncate",children:q.nickname||q.person_name}),e.jsxs("div",{className:I("text-xs truncate",ge.personId===q.person_id?"text-primary-foreground/70":"text-muted-foreground"),children:["ID: ",q.user_id,q.is_known&&" · 已认识"]})]})]},q.person_id))})})})]}),ge.personId&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"虚拟群名(可选)"}),e.jsx(ae,{placeholder:"WebUI虚拟群聊",value:ge.groupName,onChange:q=>M(qe=>({...qe,groupName:q.target.value}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"麦麦会认为这是一个名为此名称的群聊"})]})]}),e.jsxs(st,{className:"gap-2 sm:gap-0",children:[e.jsx(_,{variant:"outline",onClick:()=>C(!1),children:"取消"}),e.jsx(_,{onClick:aa,disabled:!ge.platform||!ge.personId,children:"创建对话"})]})]})}),e.jsx("div",{className:"shrink-0 border-b bg-muted/30",children:e.jsx("div",{className:"max-w-4xl mx-auto px-2 sm:px-4",children:e.jsxs("div",{className:"flex items-center gap-1 overflow-x-auto py-1.5 scrollbar-thin",children:[r.map(q=>e.jsxs("div",{className:I("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm whitespace-nowrap transition-colors cursor-pointer","hover:bg-muted",d===q.id?"bg-background shadow-sm border":"text-muted-foreground"),onClick:()=>Ht(q.id),children:[q.type==="webui"?e.jsx(Ra,{className:"h-3.5 w-3.5"}):e.jsx(Mm,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"max-w-[100px] truncate",children:q.label}),e.jsx("span",{className:I("w-1.5 h-1.5 rounded-full",q.isConnected?"bg-green-500":"bg-muted-foreground/50")}),q.id!=="webui-default"&&e.jsx("span",{onClick:qe=>Ja(q.id,qe),className:"ml-0.5 p-0.5 rounded hover:bg-muted-foreground/20 cursor-pointer",role:"button",tabIndex:0,onKeyDown:qe=>{(qe.key==="Enter"||qe.key===" ")&&(qe.preventDefault(),Ja(q.id,qe))},children:e.jsx(Aa,{className:"h-3 w-3"})})]},q.id)),e.jsx("button",{onClick:Ut,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(et,{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(Zi,{className:"h-8 w-8 sm:h-10 sm:w-10 shrink-0",children:e.jsx(Wi,{className:"bg-primary/10 text-primary",children:e.jsx(Vn,{className:"h-4 w-4 sm:h-5 sm:w-5"})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-base sm:text-lg font-semibold truncate",children:h?.sessionInfo.bot_name||"麦麦"}),e.jsx("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:h?.isConnected?e.jsxs(e.Fragment,{children:[e.jsx(F_,{className:"h-3 w-3 text-green-500"}),e.jsx("span",{className:"text-green-600 dark:text-green-400",children:"已连接"})]}):g?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"连接中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(H_,{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:[v&&e.jsx(zs,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:rs,disabled:g,title:"重新连接",children:e.jsx(dt,{className:I("h-4 w-4",g&&"animate-spin")})})]})]}),e.jsx("div",{className:"hidden sm:flex items-center gap-2 mt-2 text-sm text-muted-foreground",children:h?.type==="virtual"&&h.virtualConfig?e.jsxs(e.Fragment,{children:[e.jsx(Mm,{className:"h-3 w-3 text-primary"}),e.jsx("span",{children:"虚拟身份:"}),e.jsx("span",{className:"font-medium text-primary",children:h.virtualConfig.userName}),e.jsxs("span",{className:"text-xs",children:["(",h.virtualConfig.platform,")"]}),h.virtualConfig.groupName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1",children:"·"}),e.jsxs("span",{className:"text-xs",children:["群:",h.virtualConfig.groupName]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(jn,{className:"h-3 w-3"}),e.jsx("span",{children:"当前身份:"}),O?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{value:S,onChange:q=>B(q.target.value),onKeyDown:q=>{q.key==="Enter"&&Ee(),q.key==="Escape"&&me()},className:"h-7 w-32",placeholder:"输入昵称",autoFocus:!0}),e.jsx(_,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:Ee,children:"保存"}),e.jsx(_,{size:"sm",variant:"ghost",className:"h-7 px-2",onClick:me,children:"取消"})]}):e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-foreground",children:b}),e.jsx(_,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:ie,title:"修改昵称",children:e.jsx(V_,{className:"h-3 w-3"})})]})]})})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(Je,{className:"h-full",children:e.jsxs("div",{className:"p-3 sm:p-4 max-w-4xl mx-auto space-y-3 sm:space-y-4",children:[h?.messages.length===0&&!v&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(Vn,{className:"h-12 w-12 mb-4 opacity-50"}),e.jsxs("p",{className:"text-sm",children:["开始与 ",h?.sessionInfo.bot_name||"麦麦"," 对话吧!"]})]}),h?.messages.map(q=>e.jsxs("div",{className:I("flex gap-2 sm:gap-3",q.type==="user"&&"flex-row-reverse",q.type==="system"&&"justify-center",q.type==="error"&&"justify-center"),children:[q.type==="system"&&e.jsx("div",{className:"text-xs text-muted-foreground bg-muted/50 px-3 py-1 rounded-full max-w-[90%]",children:q.content}),q.type==="error"&&e.jsx("div",{className:"text-xs text-red-600 dark:text-red-400 bg-red-100 dark:bg-red-900/30 px-3 py-1 rounded-full max-w-[90%]",children:q.content}),q.type==="thinking"&&e.jsxs(e.Fragment,{children:[e.jsx(Zi,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(Wi,{className:"bg-primary/10 text-primary",children:e.jsx(Vn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})}),e.jsxs("div",{className:"flex flex-col gap-1 max-w-[75%] sm:max-w-[70%]",children:[e.jsx("div",{className:"flex items-center gap-2 text-[10px] sm:text-xs text-muted-foreground",children:e.jsx("span",{className:"hidden sm:inline",children:q.sender?.name||h?.sessionInfo.bot_name})}),e.jsx("div",{className:"bg-muted rounded-2xl rounded-tl-sm px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("span",{className:"w-2 h-2 bg-primary/60 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"w-2 h-2 bg-primary/60 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("span",{className:"w-2 h-2 bg-primary/60 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]}),e.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:"思考中..."})]})})]})]}),(q.type==="user"||q.type==="bot")&&e.jsxs(e.Fragment,{children:[e.jsx(Zi,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(Wi,{className:I("text-xs",q.type==="bot"?"bg-primary/10 text-primary":"bg-secondary text-secondary-foreground"),children:q.type==="bot"?e.jsx(Vn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}):e.jsx(jn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})}),e.jsxs("div",{className:I("flex flex-col gap-1 max-w-[75%] sm:max-w-[70%]",q.type==="user"&&"items-end"),children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] sm:text-xs text-muted-foreground",children:[e.jsx("span",{className:"hidden sm:inline",children:q.sender?.name||(q.type==="bot"?h?.sessionInfo.bot_name:b)}),e.jsx("span",{children:Ae(q.timestamp)})]}),e.jsx("div",{className:I("rounded-2xl px-3 py-2 text-sm break-words",q.type==="bot"?"bg-muted rounded-tl-sm":"bg-primary text-primary-foreground rounded-tr-sm"),children:e.jsx(MC,{message:q,isBot:q.type==="bot"})})]})]})]},q.id)),e.jsx("div",{ref:ue})]})})}),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(ae,{value:f,onChange:q=>p(q.target.value),onKeyDown:Ue,placeholder:h?.isConnected?"输入消息...":"等待连接...",disabled:!h?.isConnected,className:"flex-1 h-10 sm:h-10"}),e.jsx(_,{onClick:ee,disabled:!h?.isConnected||!f.trim(),size:"icon",className:"h-10 w-10 shrink-0",children:e.jsx(G_,{className:"h-4 w-4"})})]})})})]})}var _x="Radio",[zC,fN]=td(_x),[RC,DC]=zC(_x),pN=m.forwardRef((a,n)=>{const{__scopeRadio:r,name:c,checked:d=!1,required:u,disabled:h,value:f="on",onCheck:p,form:g,...N}=a,[v,w]=m.useState(null),b=ad(n,R=>w(R)),y=m.useRef(!1),O=v?g||!!v.closest("form"):!0;return e.jsxs(RC,{scope:r,checked:d,disabled:h,children:[e.jsx(Zn.button,{type:"button",role:"radio","aria-checked":d,"data-state":NN(d),"data-disabled":h?"":void 0,disabled:h,value:f,...N,ref:b,onClick:gn(a.onClick,R=>{d||p?.(),O&&(y.current=R.isPropagationStopped(),y.current||R.stopPropagation())})}),O&&e.jsx(vN,{control:v,bubbles:!y.current,name:c,value:f,checked:d,required:u,disabled:h,form:g,style:{transform:"translateX(-100%)"}})]})});pN.displayName=_x;var gN="RadioIndicator",jN=m.forwardRef((a,n)=>{const{__scopeRadio:r,forceMount:c,...d}=a,u=DC(gN,r);return e.jsx(o_,{present:c||u.checked,children:e.jsx(Zn.span,{"data-state":NN(u.checked),"data-disabled":u.disabled?"":void 0,...d,ref:n})})});jN.displayName=gN;var OC="RadioBubbleInput",vN=m.forwardRef(({__scopeRadio:a,control:n,checked:r,bubbles:c=!0,...d},u)=>{const h=m.useRef(null),f=ad(h,u),p=d_(r),g=u_(n);return m.useEffect(()=>{const N=h.current;if(!N)return;const v=window.HTMLInputElement.prototype,b=Object.getOwnPropertyDescriptor(v,"checked").set;if(p!==r&&b){const y=new Event("click",{bubbles:c});b.call(N,r),N.dispatchEvent(y)}},[p,r,c]),e.jsx(Zn.input,{type:"radio","aria-hidden":!0,defaultChecked:r,...d,tabIndex:-1,ref:f,style:{...d.style,...g,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});vN.displayName=OC;function NN(a){return a?"checked":"unchecked"}var LC=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],fd="RadioGroup",[UC]=td(fd,[Cj,fN]),bN=Cj(),yN=fN(),[$C,BC]=UC(fd),wN=m.forwardRef((a,n)=>{const{__scopeRadioGroup:r,name:c,defaultValue:d,value:u,required:h=!1,disabled:f=!1,orientation:p,dir:g,loop:N=!0,onValueChange:v,...w}=a,b=bN(r),y=Gj(g),[O,R]=sd({prop:u,defaultProp:d??null,onChange:v,caller:fd});return e.jsx($C,{scope:r,name:c,required:h,disabled:f,value:O,onValueChange:R,children:e.jsx(Sw,{asChild:!0,...b,orientation:p,dir:y,loop:N,children:e.jsx(Zn.div,{role:"radiogroup","aria-required":h,"aria-orientation":p,"data-disabled":f?"":void 0,dir:y,...w,ref:n})})})});wN.displayName=fd;var _N="RadioGroupItem",SN=m.forwardRef((a,n)=>{const{__scopeRadioGroup:r,disabled:c,...d}=a,u=BC(_N,r),h=u.disabled||c,f=bN(r),p=yN(r),g=m.useRef(null),N=ad(n,g),v=u.value===d.value,w=m.useRef(!1);return m.useEffect(()=>{const b=O=>{LC.includes(O.key)&&(w.current=!0)},y=()=>w.current=!1;return document.addEventListener("keydown",b),document.addEventListener("keyup",y),()=>{document.removeEventListener("keydown",b),document.removeEventListener("keyup",y)}},[]),e.jsx(kw,{asChild:!0,...f,focusable:!h,active:v,children:e.jsx(pN,{disabled:h,required:u.required,checked:v,...p,...d,name:u.name,ref:N,onCheck:()=>u.onValueChange(d.value),onKeyDown:gn(b=>{b.key==="Enter"&&b.preventDefault()}),onFocus:gn(d.onFocus,()=>{w.current&&g.current?.click()})})})});SN.displayName=_N;var PC="RadioGroupIndicator",kN=m.forwardRef((a,n)=>{const{__scopeRadioGroup:r,...c}=a,d=yN(r);return e.jsx(jN,{...d,...c,ref:n})});kN.displayName=PC;var CN=wN,TN=SN,IC=kN;const Sx=m.forwardRef(({className:a,...n},r)=>e.jsx(CN,{className:I("grid gap-2",a),...n,ref:r}));Sx.displayName=CN.displayName;const Xo=m.forwardRef(({className:a,...n},r)=>e.jsx(TN,{ref:r,className:I("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",a),...n,children:e.jsx(IC,{className:"flex items-center justify-center",children:e.jsx(Ho,{className:"h-2.5 w-2.5 fill-current text-current"})})}));Xo.displayName=TN.displayName;function FC({question:a,value:n,onChange:r,error:c,disabled:d=!1}){const[u,h]=m.useState(null),f=d||a.readOnly,p=()=>{switch(a.type){case"single":return e.jsx(Sx,{value:n||"",onValueChange:r,disabled:f,className:"space-y-2",children:a.options?.map(g=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xo,{value:g.value,id:`${a.id}-${g.id}`}),e.jsx(T,{htmlFor:`${a.id}-${g.id}`,className:"cursor-pointer font-normal",children:g.label})]},g.id))});case"multiple":{const g=n||[];return e.jsxs("div",{className:"space-y-2",children:[a.options?.map(N=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:`${a.id}-${N.id}`,checked:g.includes(N.value),disabled:f||a.maxSelections!==void 0&&g.length>=a.maxSelections&&!g.includes(N.value),onCheckedChange:v=>{r(v?[...g,N.value]:g.filter(w=>w!==N.value))}}),e.jsx(T,{htmlFor:`${a.id}-${N.id}`,className:"cursor-pointer font-normal",children:N.label})]},N.id)),a.maxSelections&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["最多选择 ",a.maxSelections," 项"]})]})}case"text":return e.jsx(ae,{value:n||"",onChange:g=>r(g.target.value),placeholder:a.placeholder||"请输入...",disabled:f,readOnly:a.readOnly,maxLength:a.maxLength,className:I(a.readOnly&&"bg-muted cursor-not-allowed")});case"textarea":return e.jsxs("div",{className:"space-y-1",children:[e.jsx(ot,{value:n||"",onChange:g=>r(g.target.value),placeholder:a.placeholder||"请输入...",disabled:f,readOnly:a.readOnly,maxLength:a.maxLength,rows:4,className:I(a.readOnly&&"bg-muted cursor-not-allowed")}),a.maxLength&&e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[(n||"").length," / ",a.maxLength]})]});case"rating":{const g=n||0,N=u!==null?u:g;return e.jsxs("div",{className:"flex items-center gap-1",children:[[1,2,3,4,5].map(v=>e.jsx("button",{type:"button",disabled:f,className:I("p-1 transition-colors focus:outline-none focus:ring-2 focus:ring-ring rounded",f&&"cursor-not-allowed opacity-50"),onMouseEnter:()=>!f&&h(v),onMouseLeave:()=>h(null),onClick:()=>!f&&r(v),children:e.jsx(mn,{className:I("h-6 w-6 transition-colors",v<=N?"fill-yellow-400 text-yellow-400":"text-muted-foreground")})},v)),g>0&&e.jsxs("span",{className:"ml-2 text-sm text-muted-foreground",children:[g," / 5"]})]})}case"scale":{const g=a.min??1,N=a.max??10,v=a.step??1,w=n??g;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Qa,{value:[w],onValueChange:([b])=>r(b),min:g,max:N,step:v,disabled:f}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:a.minLabel||g}),e.jsx("span",{className:"font-medium text-foreground",children:w}),e.jsx("span",{children:a.maxLabel||N})]})]})}case"dropdown":return e.jsxs(Pe,{value:n||"",onValueChange:r,disabled:f,children:[e.jsx($e,{children:e.jsx(Ie,{placeholder:a.placeholder||"请选择..."})}),e.jsx(Be,{children:a.options?.map(g=>e.jsx(Z,{value:g.value,children:g.label},g.id))})]});default:return e.jsx("div",{className:"text-muted-foreground",children:"不支持的问题类型"})}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(T,{className:"text-base font-medium",children:[a.title,a.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),a.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:a.description})]}),p(),c&&e.jsx("p",{className:"text-sm text-destructive",children:c})]})}const EN="https://maibot-plugin-stats.maibot-webui.workers.dev";function MN(){const a="maibot_user_id";let n=localStorage.getItem(a);if(!n){const r=Math.random().toString(36).substring(2,10),c=Date.now().toString(36),d=Math.random().toString(36).substring(2,10);n=`fp_${r}_${c}_${d}`,localStorage.setItem(a,n)}return n}async function HC(a,n,r,c){try{const d=c?.userId||MN(),u={surveyId:a,surveyVersion:n,userId:d,answers:r,submittedAt:new Date().toISOString(),allowMultiple:c?.allowMultiple,metadata:{userAgent:navigator.userAgent,language:navigator.language}},h=await fetch(`${EN}/survey/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)}),f=await h.json();return h.status===429?{success:!1,error:"提交过于频繁,请稍后再试"}:h.status===409?{success:!1,error:f.error||"你已经提交过这份问卷了"}:h.ok?{success:!0,submissionId:f.submissionId,message:f.message}:{success:!1,error:f.error||"提交失败"}}catch(d){return console.error("Error submitting survey:",d),{success:!1,error:"网络错误"}}}async function VC(a,n){try{const r=n||MN(),c=new URLSearchParams({user_id:r,survey_id:a}),d=await fetch(`${EN}/survey/check?${c}`);return d.ok?{success:!0,hasSubmitted:(await d.json()).hasSubmitted}:{success:!1,error:(await d.json()).error||"检查失败"}}catch(r){return console.error("Error checking submission:",r),{success:!1,error:"网络错误"}}}function AN({config:a,initialAnswers:n,onSubmitSuccess:r,onSubmitError:c,showProgress:d=!0,paginateQuestions:u=!1,className:h}){const f=m.useCallback(()=>!n||n.length===0?{}:n.reduce((P,ue)=>(P[ue.questionId]=ue.value,P),{}),[n]),[p,g]=m.useState(()=>f()),[N,v]=m.useState({}),[w,b]=m.useState(0),[y,O]=m.useState(!1),[R,S]=m.useState(!1),[B,E]=m.useState(null),[C,A]=m.useState(null),[F,L]=m.useState(!1),[J,U]=m.useState(!0);m.useEffect(()=>{n&&n.length>0&&g(P=>({...P,...f()}))},[n,f]),m.useEffect(()=>{(async()=>{if(!a.settings?.allowMultiple){const ue=await VC(a.id);ue.success&&ue.hasSubmitted&&L(!0)}U(!1)})()},[a.id,a.settings?.allowMultiple]);const oe=m.useCallback(()=>{const P=new Date;return!(a.settings?.startTime&&new Date(a.settings.startTime)>P||a.settings?.endTime&&new Date(a.settings.endTime){const ue=p[P.id];return ue==null?!1:Array.isArray(ue)?ue.length>0:typeof ue=="string"?ue.trim()!=="":!0}).length,je=Ne/a.questions.length*100,re=m.useCallback((P,ue)=>{g(Q=>({...Q,[P]:ue})),v(Q=>{const Se={...Q};return delete Se[P],Se})},[]),fe=m.useCallback(()=>{const P={};for(const ue of a.questions){if(ue.required){const Q=p[ue.id];if(Q==null){P[ue.id]="此题为必填项";continue}if(Array.isArray(Q)&&Q.length===0){P[ue.id]="请至少选择一项";continue}if(typeof Q=="string"&&Q.trim()===""){P[ue.id]="此题为必填项";continue}}ue.minLength&&typeof p[ue.id]=="string"&&p[ue.id].length{if(!fe()){if(u){const P=a.questions.findIndex(ue=>N[ue.id]);P>=0&&b(P)}return}O(!0),E(null);try{const P=a.questions.filter(Q=>p[Q.id]!==void 0).map(Q=>({questionId:Q.id,value:p[Q.id]})),ue=await HC(a.id,a.version,P,{allowMultiple:a.settings?.allowMultiple});if(ue.success&&ue.submissionId)S(!0),A(ue.submissionId),r?.(ue.submissionId);else{const Q=ue.error||"提交失败";E(Q),c?.(Q)}}catch(P){const ue=P instanceof Error?P.message:"提交失败";E(ue),c?.(ue)}finally{O(!1)}},[fe,u,a,p,N,r,c]),M=m.useCallback(P=>{P>=0&&Pe.jsxs("div",{className:I("p-4 rounded-lg border bg-card",N[P.id]?"border-destructive bg-destructive/5":"border-border"),children:[u&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:["问题 ",w+1," / ",a.questions.length]}),!u&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:[ue+1,"."]}),e.jsx(FC,{question:P,value:p[P.id],onChange:Q=>re(P.id,Q),error:N[P.id],disabled:y})]},P.id)),B&&e.jsxs(at,{variant:"destructive",children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsx(lt,{children:B})]}),e.jsx("div",{className:"flex justify-between items-center py-4",children:u?e.jsxs(e.Fragment,{children:[e.jsxs(_,{variant:"outline",onClick:()=>M(w-1),disabled:w===0||y,children:[e.jsx(Da,{className:"h-4 w-4 mr-1"}),"上一题"]}),w===a.questions.length-1?e.jsxs(_,{onClick:ge,disabled:y,children:[y&&e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]}):e.jsxs(_,{onClick:()=>M(w+1),disabled:y,children:["下一题",e.jsx(Wt,{className:"h-4 w-4 ml-1"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:Object.keys(N).length>0&&e.jsxs("span",{className:"text-destructive",children:["还有 ",Object.keys(N).length," 个必填项未完成"]})}),e.jsxs(_,{onClick:ge,disabled:y,size:"lg",children:[y&&e.jsx(zs,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]})]})})]})})]})}const GC={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:"感谢你的反馈!你的意见对我们非常重要,我们会认真考虑每一条建议。"}},qC={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 KC(){const[a,n]=m.useState(!0),r=m.useMemo(()=>JSON.parse(JSON.stringify(GC)),[]);m.useEffect(()=>{n(!1)},[]);const c=m.useMemo(()=>[{questionId:"webui_version",value:`v${od}`}],[]),d=m.useCallback(h=>{console.log("WebUI Survey submitted:",h)},[]),u=m.useCallback(h=>{console.error("WebUI Survey submission error:",h)},[]);return a?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):r?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(ov,{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(AN,{config:r,initialAnswers:c,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:d,onSubmitError:u})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(at,{variant:"destructive",className:"max-w-md",children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsx(lt,{children:"无法加载问卷配置"})]}),e.jsx(_,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}function QC(){const[a,n]=m.useState(null),[r,c]=m.useState(!0),[d,u]=m.useState("未知版本");m.useEffect(()=>{(async()=>{try{const v=await $1();u(v.version||"未知版本")}catch(v){console.error("Failed to get MaiBot version:",v),u("获取失败")}const N=JSON.parse(JSON.stringify(qC));n(N),c(!1)})()},[]);const h=m.useMemo(()=>[{questionId:"maibot_version",value:d}],[d]),f=m.useCallback(g=>{console.log("MaiBot Survey submitted:",g)},[]),p=m.useCallback(g=>{console.error("MaiBot Survey submission error:",g)},[]);return r?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(zs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):a?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(ov,{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(AN,{config:a,initialAnswers:h,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:f,onSubmitError:p})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(at,{variant:"destructive",className:"max-w-md",children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsx(lt,{children:"无法加载问卷配置"})]}),e.jsx(_,{variant:"outline",onClick:()=>window.location.reload(),children:"重试"})]})}async function YC(a=2025){const n=await _e(`/api/webui/annual-report/full?year=${a}`);if(!n.ok){const r=await n.json();throw new Error(r.detail||"获取年度报告失败")}return n.json()}function JC(a,n){if(a.match(/^[a-z]+:\/\//i))return a;if(a.match(/^\/\//))return window.location.protocol+a;if(a.match(/^[a-z]+:/i))return a;const r=document.implementation.createHTMLDocument(),c=r.createElement("base"),d=r.createElement("a");return r.head.appendChild(c),r.body.appendChild(d),n&&(c.href=n),d.href=a,d.href}const XC=(()=>{let a=0;const n=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(a+=1,`u${n()}${a}`)})();function pn(a){const n=[];for(let r=0,c=a.length;rCa||a.height>Ca)&&(a.width>Ca&&a.height>Ca?a.width>a.height?(a.height*=Ca/a.width,a.width=Ca):(a.width*=Ca/a.height,a.height=Ca):a.width>Ca?(a.height*=Ca/a.width,a.width=Ca):(a.width*=Ca/a.height,a.height=Ca))}function Wo(a){return new Promise((n,r)=>{const c=new Image;c.onload=()=>{c.decode().then(()=>{requestAnimationFrame(()=>n(c))})},c.onerror=r,c.crossOrigin="anonymous",c.decoding="async",c.src=a})}async function t3(a){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(a)).then(encodeURIComponent).then(n=>`data:image/svg+xml;charset=utf-8,${n}`)}async function a3(a,n,r){const c="http://www.w3.org/2000/svg",d=document.createElementNS(c,"svg"),u=document.createElementNS(c,"foreignObject");return d.setAttribute("width",`${n}`),d.setAttribute("height",`${r}`),d.setAttribute("viewBox",`0 0 ${n} ${r}`),u.setAttribute("width","100%"),u.setAttribute("height","100%"),u.setAttribute("x","0"),u.setAttribute("y","0"),u.setAttribute("externalResourcesRequired","true"),d.appendChild(u),u.appendChild(a),t3(d)}const ga=(a,n)=>{if(a instanceof n)return!0;const r=Object.getPrototypeOf(a);return r===null?!1:r.constructor.name===n.name||ga(r,n)};function l3(a){const n=a.getPropertyValue("content");return`${a.cssText} content: '${n.replace(/'|"/g,"")}';`}function n3(a,n){return zN(n).map(r=>{const c=a.getPropertyValue(r),d=a.getPropertyPriority(r);return`${r}: ${c}${d?" !important":""};`}).join(" ")}function r3(a,n,r,c){const d=`.${a}:${n}`,u=r.cssText?l3(r):n3(r,c);return document.createTextNode(`${d}{${u}}`)}function Wg(a,n,r,c){const d=window.getComputedStyle(a,r),u=d.getPropertyValue("content");if(u===""||u==="none")return;const h=XC();try{n.className=`${n.className} ${h}`}catch{return}const f=document.createElement("style");f.appendChild(r3(h,r,d,c)),n.appendChild(f)}function i3(a,n,r){Wg(a,n,":before",r),Wg(a,n,":after",r)}const ej="application/font-woff",sj="image/jpeg",c3={woff:ej,woff2:ej,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:sj,jpeg:sj,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function o3(a){const n=/\.([^./]*?)$/g.exec(a);return n?n[1]:""}function kx(a){const n=o3(a).toLowerCase();return c3[n]||""}function d3(a){return a.split(/,/)[1]}function Wm(a){return a.search(/^(data:)/)!==-1}function u3(a,n){return`data:${n};base64,${a}`}async function DN(a,n,r){const c=await fetch(a,n);if(c.status===404)throw new Error(`Resource "${c.url}" not found`);const d=await c.blob();return new Promise((u,h)=>{const f=new FileReader;f.onerror=h,f.onloadend=()=>{try{u(r({res:c,result:f.result}))}catch(p){h(p)}},f.readAsDataURL(d)})}const Vm={};function m3(a,n,r){let c=a.replace(/\?.*/,"");return r&&(c=a),/ttf|otf|eot|woff2?/i.test(c)&&(c=c.replace(/.*\//,"")),n?`[${n}]${c}`:c}async function Cx(a,n,r){const c=m3(a,n,r.includeQueryParams);if(Vm[c]!=null)return Vm[c];r.cacheBust&&(a+=(/\?/.test(a)?"&":"?")+new Date().getTime());let d;try{const u=await DN(a,r.fetchRequestInit,({res:h,result:f})=>(n||(n=h.headers.get("Content-Type")||""),d3(f)));d=u3(u,n)}catch(u){d=r.imagePlaceholder||"";let h=`Failed to fetch resource: ${a}`;u&&(h=typeof u=="string"?u:u.message),h&&console.warn(h)}return Vm[c]=d,d}async function x3(a){const n=a.toDataURL();return n==="data:,"?a.cloneNode(!1):Wo(n)}async function h3(a,n){if(a.currentSrc){const u=document.createElement("canvas"),h=u.getContext("2d");u.width=a.clientWidth,u.height=a.clientHeight,h?.drawImage(a,0,0,u.width,u.height);const f=u.toDataURL();return Wo(f)}const r=a.poster,c=kx(r),d=await Cx(r,c,n);return Wo(d)}async function f3(a,n){var r;try{if(!((r=a?.contentDocument)===null||r===void 0)&&r.body)return await pd(a.contentDocument.body,n,!0)}catch{}return a.cloneNode(!1)}async function p3(a,n){return ga(a,HTMLCanvasElement)?x3(a):ga(a,HTMLVideoElement)?h3(a,n):ga(a,HTMLIFrameElement)?f3(a,n):a.cloneNode(ON(a))}const g3=a=>a.tagName!=null&&a.tagName.toUpperCase()==="SLOT",ON=a=>a.tagName!=null&&a.tagName.toUpperCase()==="SVG";async function j3(a,n,r){var c,d;if(ON(n))return n;let u=[];return g3(a)&&a.assignedNodes?u=pn(a.assignedNodes()):ga(a,HTMLIFrameElement)&&(!((c=a.contentDocument)===null||c===void 0)&&c.body)?u=pn(a.contentDocument.body.childNodes):u=pn(((d=a.shadowRoot)!==null&&d!==void 0?d:a).childNodes),u.length===0||ga(a,HTMLVideoElement)||await u.reduce((h,f)=>h.then(()=>pd(f,r)).then(p=>{p&&n.appendChild(p)}),Promise.resolve()),n}function v3(a,n,r){const c=n.style;if(!c)return;const d=window.getComputedStyle(a);d.cssText?(c.cssText=d.cssText,c.transformOrigin=d.transformOrigin):zN(r).forEach(u=>{let h=d.getPropertyValue(u);u==="font-size"&&h.endsWith("px")&&(h=`${Math.floor(parseFloat(h.substring(0,h.length-2)))-.1}px`),ga(a,HTMLIFrameElement)&&u==="display"&&h==="inline"&&(h="block"),u==="d"&&n.getAttribute("d")&&(h=`path(${n.getAttribute("d")})`),c.setProperty(u,h,d.getPropertyPriority(u))})}function N3(a,n){ga(a,HTMLTextAreaElement)&&(n.innerHTML=a.value),ga(a,HTMLInputElement)&&n.setAttribute("value",a.value)}function b3(a,n){if(ga(a,HTMLSelectElement)){const c=Array.from(n.children).find(d=>a.value===d.getAttribute("value"));c&&c.setAttribute("selected","")}}function y3(a,n,r){return ga(n,Element)&&(v3(a,n,r),i3(a,n,r),N3(a,n),b3(a,n)),n}async function w3(a,n){const r=a.querySelectorAll?a.querySelectorAll("use"):[];if(r.length===0)return a;const c={};for(let u=0;up3(c,n)).then(c=>j3(a,c,n)).then(c=>y3(a,c,n)).then(c=>w3(c,n))}const LN=/url\((['"]?)([^'"]+?)\1\)/g,_3=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,S3=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function k3(a){const n=a.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${n})(['"]?\\))`,"g")}function C3(a){const n=[];return a.replace(LN,(r,c,d)=>(n.push(d),r)),n.filter(r=>!Wm(r))}async function T3(a,n,r,c,d){try{const u=r?JC(n,r):n,h=kx(n);let f;return d||(f=await Cx(u,h,c)),a.replace(k3(n),`$1${f}$3`)}catch{}return a}function E3(a,{preferredFontFormat:n}){return n?a.replace(S3,r=>{for(;;){const[c,,d]=_3.exec(r)||[];if(!d)return"";if(d===n)return`src: ${c};`}}):a}function UN(a){return a.search(LN)!==-1}async function $N(a,n,r){if(!UN(a))return a;const c=E3(a,r);return C3(c).reduce((u,h)=>u.then(f=>T3(f,h,n,r)),Promise.resolve(c))}async function Fr(a,n,r){var c;const d=(c=n.style)===null||c===void 0?void 0:c.getPropertyValue(a);if(d){const u=await $N(d,null,r);return n.style.setProperty(a,u,n.style.getPropertyPriority(a)),!0}return!1}async function M3(a,n){await Fr("background",a,n)||await Fr("background-image",a,n),await Fr("mask",a,n)||await Fr("-webkit-mask",a,n)||await Fr("mask-image",a,n)||await Fr("-webkit-mask-image",a,n)}async function A3(a,n){const r=ga(a,HTMLImageElement);if(!(r&&!Wm(a.src))&&!(ga(a,SVGImageElement)&&!Wm(a.href.baseVal)))return;const c=r?a.src:a.href.baseVal,d=await Cx(c,kx(c),n);await new Promise((u,h)=>{a.onload=u,a.onerror=n.onImageErrorHandler?(...p)=>{try{u(n.onImageErrorHandler(...p))}catch(g){h(g)}}:h;const f=a;f.decode&&(f.decode=u),f.loading==="lazy"&&(f.loading="eager"),r?(a.srcset="",a.src=d):a.href.baseVal=d})}async function z3(a,n){const c=pn(a.childNodes).map(d=>BN(d,n));await Promise.all(c).then(()=>a)}async function BN(a,n){ga(a,Element)&&(await M3(a,n),await A3(a,n),await z3(a,n))}function R3(a,n){const{style:r}=a;n.backgroundColor&&(r.backgroundColor=n.backgroundColor),n.width&&(r.width=`${n.width}px`),n.height&&(r.height=`${n.height}px`);const c=n.style;return c!=null&&Object.keys(c).forEach(d=>{r[d]=c[d]}),a}const tj={};async function aj(a){let n=tj[a];if(n!=null)return n;const c=await(await fetch(a)).text();return n={url:a,cssText:c},tj[a]=n,n}async function lj(a,n){let r=a.cssText;const c=/url\(["']?([^"')]+)["']?\)/g,u=(r.match(/url\([^)]+\)/g)||[]).map(async h=>{let f=h.replace(c,"$1");return f.startsWith("https://")||(f=new URL(f,a.url).href),DN(f,n.fetchRequestInit,({result:p})=>(r=r.replace(h,`url(${p})`),[h,p]))});return Promise.all(u).then(()=>r)}function nj(a){if(a==null)return[];const n=[],r=/(\/\*[\s\S]*?\*\/)/gi;let c=a.replace(r,"");const d=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const p=d.exec(c);if(p===null)break;n.push(p[0])}c=c.replace(d,"");const u=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,h="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",f=new RegExp(h,"gi");for(;;){let p=u.exec(c);if(p===null){if(p=f.exec(c),p===null)break;u.lastIndex=f.lastIndex}else f.lastIndex=u.lastIndex;n.push(p[0])}return n}async function D3(a,n){const r=[],c=[];return a.forEach(d=>{if("cssRules"in d)try{pn(d.cssRules||[]).forEach((u,h)=>{if(u.type===CSSRule.IMPORT_RULE){let f=h+1;const p=u.href,g=aj(p).then(N=>lj(N,n)).then(N=>nj(N).forEach(v=>{try{d.insertRule(v,v.startsWith("@import")?f+=1:d.cssRules.length)}catch(w){console.error("Error inserting rule from remote css",{rule:v,error:w})}})).catch(N=>{console.error("Error loading remote css",N.toString())});c.push(g)}})}catch(u){const h=a.find(f=>f.href==null)||document.styleSheets[0];d.href!=null&&c.push(aj(d.href).then(f=>lj(f,n)).then(f=>nj(f).forEach(p=>{h.insertRule(p,h.cssRules.length)})).catch(f=>{console.error("Error loading remote stylesheet",f)})),console.error("Error inlining remote css file",u)}}),Promise.all(c).then(()=>(a.forEach(d=>{if("cssRules"in d)try{pn(d.cssRules||[]).forEach(u=>{r.push(u)})}catch(u){console.error(`Error while reading CSS rules from ${d.href}`,u)}}),r))}function O3(a){return a.filter(n=>n.type===CSSRule.FONT_FACE_RULE).filter(n=>UN(n.style.getPropertyValue("src")))}async function L3(a,n){if(a.ownerDocument==null)throw new Error("Provided element is not within a Document");const r=pn(a.ownerDocument.styleSheets),c=await D3(r,n);return O3(c)}function PN(a){return a.trim().replace(/["']/g,"")}function U3(a){const n=new Set;function r(c){(c.style.fontFamily||getComputedStyle(c).fontFamily).split(",").forEach(u=>{n.add(PN(u))}),Array.from(c.children).forEach(u=>{u instanceof HTMLElement&&r(u)})}return r(a),n}async function $3(a,n){const r=await L3(a,n),c=U3(a);return(await Promise.all(r.filter(u=>c.has(PN(u.style.fontFamily))).map(u=>{const h=u.parentStyleSheet?u.parentStyleSheet.href:null;return $N(u.cssText,h,n)}))).join(` -`)}async function B3(a,n){const r=n.fontEmbedCSS!=null?n.fontEmbedCSS:n.skipFonts?null:await $3(a,n);if(r){const c=document.createElement("style"),d=document.createTextNode(r);c.appendChild(d),a.firstChild?a.insertBefore(c,a.firstChild):a.appendChild(c)}}async function P3(a,n={}){const{width:r,height:c}=RN(a,n),d=await pd(a,n,!0);return await B3(d,n),await BN(d,n),R3(d,n),await a3(d,r,c)}async function I3(a,n={}){const{width:r,height:c}=RN(a,n),d=await P3(a,n),u=await Wo(d),h=document.createElement("canvas"),f=h.getContext("2d"),p=n.pixelRatio||e3(),g=n.canvasWidth||r,N=n.canvasHeight||c;return h.width=g*p,h.height=N*p,n.skipAutoScale||s3(h),h.style.width=`${g}`,h.style.height=`${N}`,n.backgroundColor&&(f.fillStyle=n.backgroundColor,f.fillRect(0,0,h.width,h.height)),f.drawImage(u,0,0,h.width,h.height),h}async function F3(a,n={}){return(await I3(a,n)).toDataURL()}const Lo=["#0088FE","#00C49F","#FFBB28","#FF8042","#8884d8","#82ca9d"];function H3(a){return a>=8760?"相当于全年无休,7x24小时在线!":a>=5e3?"相当于一位全职员工的年工作时长":a>=2e3?"相当于看完了 1000 部电影":a>=1e3?"相当于环球飞行 80 次":a>=500?"相当于读完了 100 本书":a>=100?"相当于马拉松跑了 25 次":"虽然不多,但每一刻都很珍贵"}function V3(a){return a>=1e3?"夜深人静时的知心好友":a>=500?"午夜场的常客":a>=100?"偶尔熬夜的小伙伴":a>=50?"深夜有时也会陪你聊聊":"早睡早起,健康作息"}function G3(a){const n=a/1e6;return n>=100?"思考量堪比一座图书馆":n>=50?"相当于写了一部百科全书":n>=10?"脑细胞估计消耗了不少":n>=1?"也算是费了一番脑筋":"轻轻松松,游刃有余"}function q3(a){return a>=1e3?"这钱够吃一年的泡面了":a>=500?"相当于买了一台游戏机":a>=100?"够请大家喝几杯奶茶":a>=50?"一顿火锅的钱":a>=10?"几杯咖啡的价格":"省钱小能手"}function K3(a){return a>=80?"沉默是金,惜字如金":a>=60?"话不多但句句到位":a>=40?"该说的时候才开口":a>=20?"能聊的都聊了":"话痨本痨,有问必答"}function Q3(a){return a>=1e4?"眼睛都快看花了":a>=5e3?"堪比专业摄影师的阅片量":a>=1e3?"看图小达人":a>=500?"图片鉴赏家":a>=100?"偶尔欣赏一下美图":"图片?有空再看"}function Y3(a){return a>=500?"在不断的纠正中成长":a>=200?"学习永无止境":a>=100?"虚心接受,积极改正":a>=50?"偶尔也会犯错":a>=10?"表现还算不错":"完美表达,无需纠正"}function J3(a){return a>=1?"这次思考的价值堪比一顿大餐!":a>=.5?"为了这个问题,我可是认真思考了!":a>=.1?"下了点功夫,值得的!":a>=.01?"花了点小钱,但很值得":"小小思考,不足挂齿"}function X3(a,n){return a>=100?"这句话简直是万能钥匙!":a>=50?"百试不爽的经典回复":a>=20?`${n}的口头禅`:a>=10?"常用语录之一":"偶尔用用的小确幸"}function Z3(a,n){return a?n>=1e3?"深夜的守护者,黑暗中的光芒":n>=500?"月亮是我的好朋友":n>=100?"越夜越精神,夜晚才是主场":"偶尔熬夜,享受宁静时光":n<=10?"作息规律,健康生活的典范":n<=50?"早睡早起,偶尔也会熬个夜":"虽然是早起鸟,但也会守候深夜"}function W3(a){return a>=1e3?"忙到飞起,键盘都要冒烟了":a>=500?"这天简直是话痨附体":a>=200?"社交达人上线":a>=100?"比平时活跃不少":a>=50?"小忙一下":"还算轻松的一天"}function e5(){const[a]=m.useState(2025),[n,r]=m.useState(null),[c,d]=m.useState(!0),[u,h]=m.useState(!1),[f,p]=m.useState(null),g=m.useRef(null),{toast:N}=Ys(),v=m.useCallback(async()=>{try{d(!0),p(null);const b=await YC(a);r(b)}catch(b){p(b instanceof Error?b:new Error("获取年度报告失败"))}finally{d(!1)}},[a]),w=m.useCallback(async()=>{if(!(!g.current||!n)){h(!0),N({title:"正在生成图片",description:"请稍候..."});try{const b=g.current,y=getComputedStyle(document.documentElement),O=y.getPropertyValue("--background").trim()?`hsl(${y.getPropertyValue("--background").trim()})`:document.documentElement.classList.contains("dark")?"#0a0a0a":"#ffffff",R=b.style.width,S=b.style.maxWidth;b.style.width="1024px",b.style.maxWidth="1024px";const B=await F3(b,{quality:1,pixelRatio:2,backgroundColor:O,cacheBust:!0,filter:C=>!(C instanceof HTMLElement&&C.hasAttribute("data-export-btn"))});b.style.width=R,b.style.maxWidth=S;const E=document.createElement("a");E.download=`${n.bot_name}_${n.year}_年度总结.png`,E.href=B,E.click(),N({title:"导出成功",description:"年度报告已保存为图片"})}catch(b){console.error("导出图片失败:",b),N({title:"导出失败",description:"请重试",variant:"destructive"})}finally{h(!1)}}},[n,N]);return m.useEffect(()=>{v()},[v]),c?e.jsx(s5,{}):f?e.jsxs("div",{className:"flex h-screen items-center justify-center text-red-500",children:["获取年度报告失败: ",f.message]}):n?e.jsx(Je,{className:"h-[calc(100vh-4rem)]",children:e.jsx("div",{className:"min-h-screen bg-gradient-to-b from-background to-muted/50 p-4 md:p-8 print:p-0",ref:g,children:e.jsxs("div",{className:"mx-auto max-w-5xl space-y-8 print:space-y-4",children:[e.jsxs("header",{className:"relative overflow-hidden rounded-3xl bg-primary p-8 text-primary-foreground shadow-2xl print:rounded-none print:shadow-none",children:[e.jsx("div",{className:"absolute right-4 top-4 z-20 print:hidden","data-export-btn":!0,children:e.jsx(_,{variant:"secondary",size:"sm",onClick:w,disabled:u,className:"gap-2 bg-white/20 hover:bg-white/30 text-white border-white/30",children:u?e.jsxs(e.Fragment,{children:[e.jsx(zs,{className:"h-4 w-4 animate-spin"}),"导出中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Xt,{className:"h-4 w-4"}),"保存图片"]})})}),e.jsxs("div",{className:"relative z-10 flex flex-col items-center text-center",children:[e.jsx(Vn,{className:"mb-4 h-16 w-16 animate-bounce"}),e.jsxs("h1",{className:"text-4xl font-bold tracking-tighter sm:text-6xl",children:[n.bot_name," ",n.year," 年度总结"]}),e.jsx("p",{className:"mt-4 max-w-2xl text-lg opacity-90",children:"连接与成长 · Connection & Growth"}),e.jsxs("div",{className:"mt-6 flex items-center gap-2 text-sm opacity-75",children:[e.jsx(Go,{className:"h-4 w-4"}),e.jsxs("span",{children:["生成时间: ",n.generated_at]})]})]}),e.jsx("div",{className:"absolute -right-20 -top-20 h-64 w-64 rounded-full bg-white/10 blur-3xl"}),e.jsx("div",{className:"absolute -bottom-20 -left-20 h-64 w-64 rounded-full bg-white/10 blur-3xl"})]}),e.jsxs("section",{className:"space-y-4 break-inside-avoid",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xl font-bold text-primary",children:[e.jsx(na,{className:"h-8 w-8"}),e.jsx("h2",{children:"时光足迹"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsx(Ta,{title:"年度在线时长",value:`${n.time_footprint.total_online_hours} 小时`,description:H3(n.time_footprint.total_online_hours),icon:e.jsx(na,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"最忙碌的一天",value:n.time_footprint.busiest_day||"N/A",description:W3(n.time_footprint.busiest_day_count),icon:e.jsx(Go,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"深夜互动 (0-4点)",value:`${n.time_footprint.midnight_chat_count} 次`,description:V3(n.time_footprint.midnight_chat_count),icon:e.jsx(ec,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"作息属性",value:n.time_footprint.is_night_owl?"夜猫子":"早起鸟",description:Z3(n.time_footprint.is_night_owl,n.time_footprint.midnight_chat_count),icon:n.time_footprint.is_night_owl?e.jsx(ec,{className:"h-4 w-4"}):e.jsx(ax,{className:"h-4 w-4"})})]}),e.jsxs(Ce,{className:"overflow-hidden",children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"24小时活跃时钟"}),e.jsxs(os,{children:[n.bot_name,"在一天中各个时段的活跃程度"]})]}),e.jsx(Me,{className:"h-[300px]",children:e.jsx(Mj,{width:"100%",height:"100%",children:e.jsxs(Uo,{data:n.time_footprint.hourly_distribution.map((b,y)=>({hour:`${y}点`,count:b})),children:[e.jsx(Qi,{strokeDasharray:"3 3",vertical:!1}),e.jsx(Yi,{dataKey:"hour"}),e.jsx(Hr,{}),e.jsx(Aj,{contentStyle:{borderRadius:"8px",border:"none",boxShadow:"0 4px 12px rgba(0,0,0,0.1)"},cursor:{fill:"transparent"}}),e.jsx(Ji,{dataKey:"count",fill:"hsl(var(--primary))",radius:[4,4,0,0]})]})})})]}),n.time_footprint.first_message_time&&e.jsx(Ce,{className:"bg-muted/30 border-dashed",children:e.jsxs(Me,{className:"flex flex-col items-center justify-center p-6 text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-2",children:"2025年的故事开始于"}),e.jsx("div",{className:"text-xl font-bold text-primary mb-1",children:n.time_footprint.first_message_time}),e.jsxs("p",{className:"text-lg",children:[e.jsx("span",{className:"font-semibold text-foreground",children:n.time_footprint.first_message_user})," 说:",e.jsxs("span",{className:"italic text-muted-foreground",children:['"',n.time_footprint.first_message_content,'"']})]})]})})]}),e.jsxs("section",{className:"space-y-4 break-inside-avoid",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xl font-bold text-primary",children:[e.jsx(ic,{className:"h-8 w-8"}),e.jsx("h2",{children:"社交网络"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(Ta,{title:"社交圈子",value:`${n.social_network.total_groups} 个群组`,description:`${n.bot_name}加入的群组总数`,icon:e.jsx(ic,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"被呼叫次数",value:`${n.social_network.at_count+n.social_network.mentioned_count} 次`,description:"我的名字被大家频繁提起",icon:e.jsx(q_,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"最长情陪伴",value:n.social_network.longest_companion_user||"N/A",description:`始终都在,已陪伴 ${n.social_network.longest_companion_days} 天`,icon:e.jsx(Xr,{className:"h-4 w-4 text-red-500"})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{children:"话痨群组 TOP5"})}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-3",children:n.social_network.top_groups.length>0?n.social_network.top_groups.map((b,y)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ke,{variant:y===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:y+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:b.group_name}),b.is_webui&&e.jsx(ke,{variant:"outline",className:"text-xs px-1.5 py-0 h-5 bg-blue-50 text-blue-600 border-blue-200",children:"WebUI"})]}),e.jsxs("span",{className:"text-muted-foreground text-sm shrink-0",children:[b.message_count," 条消息"]})]},b.group_id)):e.jsx("div",{className:"text-center text-muted-foreground py-4",children:"暂无数据"})})})]}),e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{children:"年度最佳损友 TOP5"})}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-3",children:n.social_network.top_users.length>0?n.social_network.top_users.map((b,y)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ke,{variant:y===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:y+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:b.user_nickname}),b.is_webui&&e.jsx(ke,{variant:"outline",className:"text-xs px-1.5 py-0 h-5 bg-blue-50 text-blue-600 border-blue-200",children:"WebUI"})]}),e.jsxs("span",{className:"text-muted-foreground text-sm shrink-0",children:[b.message_count," 次互动"]})]},b.user_id)):e.jsx("div",{className:"text-center text-muted-foreground py-4",children:"暂无数据"})})})]})]})]}),e.jsxs("section",{className:"space-y-4 break-inside-avoid",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xl font-bold text-primary",children:[e.jsx(cx,{className:"h-8 w-8"}),e.jsx("h2",{children:"最强大脑"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsx(Ta,{title:"年度 Token 消耗",value:(n.brain_power.total_tokens/1e6).toFixed(2)+" M",description:G3(n.brain_power.total_tokens),icon:e.jsx(el,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"年度总花费",value:`$${n.brain_power.total_cost.toFixed(2)}`,description:q3(n.brain_power.total_cost),icon:e.jsx("span",{className:"font-bold",children:"$"})}),e.jsx(Ta,{title:"高冷指数",value:`${n.brain_power.silence_rate}%`,description:K3(n.brain_power.silence_rate),icon:e.jsx(ec,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"最高兴趣值",value:n.brain_power.max_interest_value??"N/A",description:n.brain_power.max_interest_time?`出现在 ${n.brain_power.max_interest_time}`:"暂无数据",icon:e.jsx(Xr,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Oe,{children:"模型偏好分布"})}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-3",children:n.brain_power.model_distribution.slice(0,5).map((b,y)=>{const O=n.brain_power.model_distribution[0]?.count||1,R=Math.round(b.count/O*100);return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"font-medium truncate max-w-[200px]",children:b.model}),e.jsxs("span",{className:"text-muted-foreground",children:[b.count.toLocaleString()," 次"]})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-secondary",children:e.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${R}%`,backgroundColor:Lo[y%Lo.length]}})})]},b.model)})})})]}),n.brain_power.top_reply_models&&n.brain_power.top_reply_models.length>0&&e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"最喜欢的回复模型 TOP5"}),e.jsxs(os,{children:[n.bot_name,"用来回复消息的模型偏好"]})]}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-3",children:n.brain_power.top_reply_models.map((b,y)=>{const O=n.brain_power.top_reply_models[0]?.count||1,R=Math.round(b.count/O*100);return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"font-medium truncate max-w-[200px]",children:b.model}),e.jsxs("span",{className:"text-muted-foreground",children:[b.count.toLocaleString()," 次"]})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-secondary",children:e.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${R}%`,backgroundColor:Lo[y%Lo.length]}})})]},b.model)})})})]}),n.brain_power.top_token_consumers&&n.brain_power.top_token_consumers.length>0&&e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"烧钱大户 TOP3"}),e.jsx(os,{children:"谁消耗了最多的 API 额度"})]}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-6",children:n.brain_power.top_token_consumers.map(b=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm font-medium",children:[e.jsxs("span",{children:["用户 ",b.user_id]}),e.jsxs("span",{children:["$",b.cost.toFixed(2)]})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-secondary",children:e.jsx("div",{className:"h-full bg-primary transition-all duration-500",style:{width:`${b.cost/(n.brain_power.top_token_consumers[0]?.cost||1)*100}%`}})})]},b.user_id))})})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{className:"bg-gradient-to-br from-amber-50 to-orange-50 dark:from-amber-950/20 dark:to-orange-950/20",children:[e.jsx(De,{children:e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"💰"}),"最昂贵的一次思考"]})}),e.jsxs(Me,{className:"text-center",children:[e.jsxs("div",{className:"text-4xl font-bold text-amber-600 dark:text-amber-400",children:["$",n.brain_power.most_expensive_cost.toFixed(4)]}),n.brain_power.most_expensive_time&&e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["发生在 ",n.brain_power.most_expensive_time]}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:J3(n.brain_power.most_expensive_cost)})]})]}),e.jsxs(Ce,{className:"bg-gradient-to-br from-indigo-50 to-blue-50 dark:from-indigo-950/20 dark:to-blue-950/20",children:[e.jsx(De,{children:e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"🧠"}),"思考深度"]})}),e.jsxs(Me,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-center",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-indigo-600 dark:text-indigo-400",children:n.brain_power.avg_reasoning_length?.toFixed(0)||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"平均思考字数"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-blue-600 dark:text-blue-400",children:n.brain_power.max_reasoning_length?.toLocaleString()||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"最长思考字数"})]})]}),n.brain_power.max_reasoning_time&&e.jsxs("p",{className:"mt-4 text-center text-xs text-muted-foreground",children:["最深沉的思考发生在 ",n.brain_power.max_reasoning_time]})]})]})]})]}),e.jsxs("section",{className:"space-y-4 break-inside-avoid",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xl font-bold text-primary",children:[e.jsx(ld,{className:"h-8 w-8"}),e.jsx("h2",{children:"个性与表达"})]}),(n.expression_vibe.late_night_reply||n.expression_vibe.favorite_reply)&&e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[n.expression_vibe.late_night_reply&&e.jsxs(Ce,{className:"bg-gradient-to-br from-indigo-50 to-violet-50 dark:from-indigo-950/20 dark:to-violet-950/20",children:[e.jsxs(De,{children:[e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"🌙"}),"深夜还在回复"]}),e.jsxs(os,{children:["凌晨 ",n.expression_vibe.late_night_reply.time,",",n.bot_name,"还在回复..."]})]}),e.jsxs(Me,{className:"text-center",children:[e.jsxs("p",{className:"text-lg italic text-muted-foreground",children:['"',n.expression_vibe.late_night_reply.content,'"']}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:"是有什么心事吗?"})]})]}),n.expression_vibe.favorite_reply&&e.jsxs(Ce,{className:"bg-gradient-to-br from-rose-50 to-pink-50 dark:from-rose-950/20 dark:to-pink-950/20",children:[e.jsxs(De,{children:[e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"💬"}),"最喜欢的回复"]}),e.jsxs(os,{children:["使用了 ",n.expression_vibe.favorite_reply.count," 次"]})]}),e.jsxs(Me,{className:"text-center",children:[e.jsxs("p",{className:"text-lg font-medium text-primary",children:['"',n.expression_vibe.favorite_reply.content,'"']}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:X3(n.expression_vibe.favorite_reply.count,n.bot_name)})]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(Ce,{className:"bg-gradient-to-br from-pink-50 to-purple-50 dark:from-pink-950/20 dark:to-purple-950/20",children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"使用最多的表情包 TOP3"}),e.jsx(os,{children:"年度最爱的表情包们"})]}),e.jsx(Me,{children:n.expression_vibe.top_emojis&&n.expression_vibe.top_emojis.length>0?e.jsx("div",{className:"flex justify-center gap-4",children:n.expression_vibe.top_emojis.slice(0,3).map((b,y)=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:`/api/webui/emoji/${b.id}/thumbnail?original=true`,alt:`TOP ${y+1}`,className:"h-24 w-24 rounded-lg object-cover shadow-md transition-transform hover:scale-105"}),e.jsx(ke,{className:I("absolute -top-2 -right-2",y===0?"bg-yellow-500":y===1?"bg-gray-400":"bg-amber-700"),children:y+1})]}),e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:[b.usage_count," 次"]})]},b.id))}):e.jsx("div",{className:"flex h-32 items-center justify-center text-muted-foreground",children:"暂无数据"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"印象最深刻的表达风格"}),e.jsxs(os,{children:[n.bot_name,"最常使用的表达方式"]})]}),e.jsx(Me,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:n.expression_vibe.top_expressions.map((b,y)=>e.jsxs(ke,{variant:"outline",className:I("px-3 py-1 text-sm",y===0&&"border-primary bg-primary/10 text-primary text-base px-4 py-2"),children:[b.style," (",b.count,")"]},b.style))})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ta,{title:"图片鉴赏",value:`${n.expression_vibe.image_processed_count} 张`,description:Q3(n.expression_vibe.image_processed_count),icon:e.jsx(ix,{className:"h-4 w-4"})}),e.jsx(Ta,{title:"成长的足迹",value:`${n.expression_vibe.rejected_expression_count} 次`,description:Y3(n.expression_vibe.rejected_expression_count),icon:e.jsx(el,{className:"h-4 w-4"})})]})]})]}),n.expression_vibe.action_types.length>0&&e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsxs(Oe,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:"⚡"}),"行动派"]}),e.jsx(os,{children:"除了聊天,我还帮大家做了这些事"})]}),e.jsx(Me,{children:e.jsx("div",{className:"flex flex-wrap gap-3",children:n.expression_vibe.action_types.map(b=>e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-primary/10 px-4 py-2",children:[e.jsx("span",{className:"font-medium text-primary",children:b.action}),e.jsxs(ke,{variant:"secondary",children:[b.count," 次"]})]},b.action))})})]})]}),e.jsxs("section",{className:"space-y-4 break-inside-avoid",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xl font-bold text-primary",children:[e.jsx(K_,{className:"h-8 w-8"}),e.jsx("h2",{children:"趣味成就"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs(Ce,{className:"col-span-1 md:col-span-2",children:[e.jsxs(De,{children:[e.jsx(Oe,{children:'新学到的"黑话"'}),e.jsxs(os,{children:["今年我学会了 ",n.achievements.new_jargon_count," 个新词"]})]}),e.jsx(Me,{children:e.jsx("div",{className:"flex flex-wrap gap-3",children:n.achievements.sample_jargons.map(b=>e.jsxs("div",{className:"group relative rounded-lg border bg-card p-3 shadow-sm transition-all hover:shadow-md",children:[e.jsx("div",{className:"font-bold text-primary",children:b.content}),e.jsx("div",{className:"text-xs text-muted-foreground mt-1 line-clamp-2 max-w-[200px]",children:b.meaning||"暂无解释"})]},b.content))})})]}),e.jsx(Ce,{className:"flex flex-col justify-center items-center bg-primary text-primary-foreground",children:e.jsxs(Me,{className:"flex flex-col items-center justify-center p-6 text-center",children:[e.jsx(Ra,{className:"h-12 w-12 mb-4 opacity-80"}),e.jsx("div",{className:"text-4xl font-bold mb-2",children:n.achievements.total_messages.toLocaleString()}),e.jsx("div",{className:"text-sm opacity-80",children:"年度总消息数"}),e.jsxs("div",{className:"mt-4 text-xs opacity-60",children:["其中回复了 ",n.achievements.total_replies.toLocaleString()," 次"]})]})})]})]}),e.jsxs("footer",{className:"mt-12 text-center text-muted-foreground",children:[e.jsx("p",{children:"MaiBot 2025 Annual Report"}),e.jsx("p",{className:"text-sm",children:"Generated with ❤️ by MaiBot Team"})]})]})})}):null}function Ta({title:a,value:n,description:r,icon:c}){return e.jsxs(Ce,{children:[e.jsxs(De,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Oe,{className:"text-sm font-medium",children:a}),e.jsx("div",{className:"text-muted-foreground",children:c})]}),e.jsxs(Me,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]})]})}function s5(){return e.jsxs("div",{className:"container mx-auto space-y-8 p-8",children:[e.jsx(vs,{className:"h-64 w-full rounded-3xl"}),e.jsx("div",{className:"grid gap-4 md:grid-cols-4",children:[...Array(4)].map((a,n)=>e.jsx(vs,{className:"h-32 w-full"},n))}),e.jsx(vs,{className:"h-96 w-full"})]})}var gd="DropdownMenu",[t5]=td(gd,[Tj]),oa=Tj(),[a5,IN]=t5(gd),FN=a=>{const{__scopeDropdownMenu:n,children:r,dir:c,open:d,defaultOpen:u,onOpenChange:h,modal:f=!0}=a,p=oa(n),g=m.useRef(null),[N,v]=sd({prop:d,defaultProp:u??!1,onChange:h,caller:gd});return e.jsx(a5,{scope:n,triggerId:qm(),triggerRef:g,contentId:qm(),open:N,onOpenChange:v,onOpenToggle:m.useCallback(()=>v(w=>!w),[v]),modal:f,children:e.jsx(Uw,{...p,open:N,onOpenChange:v,dir:c,modal:f,children:r})})};FN.displayName=gd;var HN="DropdownMenuTrigger",VN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,disabled:c=!1,...d}=a,u=IN(HN,r),h=oa(r);return e.jsx($w,{asChild:!0,...h,children:e.jsx(Zn.button,{type:"button",id:u.triggerId,"aria-haspopup":"menu","aria-expanded":u.open,"aria-controls":u.open?u.contentId:void 0,"data-state":u.open?"open":"closed","data-disabled":c?"":void 0,disabled:c,...d,ref:m_(n,u.triggerRef),onPointerDown:gn(a.onPointerDown,f=>{!c&&f.button===0&&f.ctrlKey===!1&&(u.onOpenToggle(),u.open||f.preventDefault())}),onKeyDown:gn(a.onKeyDown,f=>{c||(["Enter"," "].includes(f.key)&&u.onOpenToggle(),f.key==="ArrowDown"&&u.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(f.key)&&f.preventDefault())})})})});VN.displayName=HN;var l5="DropdownMenuPortal",GN=a=>{const{__scopeDropdownMenu:n,...r}=a,c=oa(n);return e.jsx(Ew,{...c,...r})};GN.displayName=l5;var qN="DropdownMenuContent",KN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=IN(qN,r),u=oa(r),h=m.useRef(!1);return e.jsx(Mw,{id:d.contentId,"aria-labelledby":d.triggerId,...u,...c,ref:n,onCloseAutoFocus:gn(a.onCloseAutoFocus,f=>{h.current||d.triggerRef.current?.focus(),h.current=!1,f.preventDefault()}),onInteractOutside:gn(a.onInteractOutside,f=>{const p=f.detail.originalEvent,g=p.button===0&&p.ctrlKey===!0,N=p.button===2||g;(!d.modal||N)&&(h.current=!0)}),style:{...a.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});KN.displayName=qN;var n5="DropdownMenuGroup",r5=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Bw,{...d,...c,ref:n})});r5.displayName=n5;var i5="DropdownMenuLabel",QN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Ow,{...d,...c,ref:n})});QN.displayName=i5;var c5="DropdownMenuItem",YN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Aw,{...d,...c,ref:n})});YN.displayName=c5;var o5="DropdownMenuCheckboxItem",JN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(zw,{...d,...c,ref:n})});JN.displayName=o5;var d5="DropdownMenuRadioGroup",u5=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Pw,{...d,...c,ref:n})});u5.displayName=d5;var m5="DropdownMenuRadioItem",XN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Dw,{...d,...c,ref:n})});XN.displayName=m5;var x5="DropdownMenuItemIndicator",ZN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Rw,{...d,...c,ref:n})});ZN.displayName=x5;var h5="DropdownMenuSeparator",WN=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Lw,{...d,...c,ref:n})});WN.displayName=h5;var f5="DropdownMenuArrow",p5=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Iw,{...d,...c,ref:n})});p5.displayName=f5;var g5="DropdownMenuSubTrigger",eb=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Cw,{...d,...c,ref:n})});eb.displayName=g5;var j5="DropdownMenuSubContent",sb=m.forwardRef((a,n)=>{const{__scopeDropdownMenu:r,...c}=a,d=oa(r);return e.jsx(Tw,{...d,...c,ref:n,style:{...a.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});sb.displayName=j5;var v5=FN,N5=VN,b5=GN,tb=KN,ab=QN,lb=YN,nb=JN,rb=XN,ib=ZN,cb=WN,ob=eb,db=sb;const y5=v5,w5=N5,_5=m.forwardRef(({className:a,inset:n,children:r,...c},d)=>e.jsxs(ob,{ref:d,className:I("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",n&&"pl-8",a),...c,children:[r,e.jsx(Wt,{className:"ml-auto h-4 w-4"})]}));_5.displayName=ob.displayName;const S5=m.forwardRef(({className:a,...n},r)=>e.jsx(db,{ref:r,className:I("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...n}));S5.displayName=db.displayName;const ub=m.forwardRef(({className:a,sideOffset:n=4,...r},c)=>e.jsx(b5,{children:e.jsx(tb,{ref:c,sideOffset:n,className:I("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...r})}));ub.displayName=tb.displayName;const mb=m.forwardRef(({className:a,inset:n,...r},c)=>e.jsx(lb,{ref:c,className:I("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n&&"pl-8",a),...r}));mb.displayName=lb.displayName;const k5=m.forwardRef(({className:a,children:n,checked:r,...c},d)=>e.jsxs(nb,{ref:d,className:I("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),checked:r,...c,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(ib,{children:e.jsx(Ct,{className:"h-4 w-4"})})}),n]}));k5.displayName=nb.displayName;const C5=m.forwardRef(({className:a,children:n,...r},c)=>e.jsxs(rb,{ref:c,className:I("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),...r,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(ib,{children:e.jsx(Ho,{className:"h-2 w-2 fill-current"})})}),n]}));C5.displayName=rb.displayName;const T5=m.forwardRef(({className:a,inset:n,...r},c)=>e.jsx(ab,{ref:c,className:I("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",a),...r}));T5.displayName=ab.displayName;const E5=m.forwardRef(({className:a,...n},r)=>e.jsx(cb,{ref:r,className:I("-mx-1 my-1 h-px bg-muted",a),...n}));E5.displayName=cb.displayName;const Gm=[{value:"created_at",label:"最新发布",icon:na},{value:"downloads",label:"下载最多",icon:Xt},{value:"likes",label:"最受欢迎",icon:Xr}];function M5(){const a=ca(),[n,r]=m.useState([]),[c,d]=m.useState(!0),[u,h]=m.useState(""),[f,p]=m.useState("downloads"),[g,N]=m.useState(1),[v,w]=m.useState(1),[b,y]=m.useState(0),[O,R]=m.useState(new Set),[S,B]=m.useState(new Set),E=Yv(),C=m.useCallback(async()=>{d(!0);try{const U=await PS({status:"approved",page:g,page_size:12,search:u||void 0,sort_by:f,sort_order:"desc"});r(U.packs),w(U.total_pages),y(U.total);const oe=new Set;for(const Ne of U.packs)await Qv(Ne.id,E)&&oe.add(Ne.id);R(oe)}catch(U){console.error("加载 Pack 列表失败:",U),Qt({title:"加载 Pack 列表失败",variant:"destructive"})}finally{d(!1)}},[g,u,f,E]);m.useEffect(()=>{C()},[C]);const A=U=>{U.preventDefault(),N(1),C()},F=async U=>{if(!S.has(U)){B(oe=>new Set(oe).add(U));try{const oe=await Kv(U,E);R(Ne=>{const je=new Set(Ne);return oe.liked?je.add(U):je.delete(U),je}),r(Ne=>Ne.map(je=>je.id===U?{...je,likes:oe.likes}:je))}catch(oe){console.error("点赞失败:",oe),Qt({title:"点赞失败",variant:"destructive"})}finally{B(oe=>{const Ne=new Set(oe);return Ne.delete(U),Ne})}}},L=U=>{a({to:"/config/pack-market/$packId",params:{packId:U}})},J=Gm.find(U=>U.value===f)||Gm[0];return e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsx("div",{className:"mb-4 sm:mb-6",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(ra,{className:"h-8 w-8",strokeWidth:2}),"配置模板市场"]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm sm:text-base",children:"浏览和应用社区分享的模型配置模板,快速配置你的 MaiBot"})]}),e.jsxs(_,{variant:"outline",onClick:C,disabled:c,className:"gap-2",children:[e.jsx(dt,{className:`h-4 w-4 ${c?"animate-spin":""}`}),"刷新"]})]})}),e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-4 flex-wrap",children:[e.jsx("form",{onSubmit:A,className:"flex-1 min-w-[200px] max-w-md",children:e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(ae,{placeholder:"搜索模板名称、描述...",value:u,onChange:U=>h(U.target.value),className:"pl-10"})]})}),e.jsxs(y5,{children:[e.jsx(w5,{asChild:!0,children:e.jsxs(_,{variant:"outline",className:"min-w-[140px] gap-2",children:[e.jsx(Q_,{className:"w-4 h-4"}),J.label,e.jsx(za,{className:"w-4 h-4 ml-auto"})]})}),e.jsx(ub,{align:"end",children:Gm.map(U=>e.jsxs(mb,{onClick:()=>{p(U.value),N(1)},children:[e.jsx(U.icon,{className:"w-4 h-4 mr-2"}),U.label]},U.value))})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共找到 ",e.jsx("span",{className:"font-medium text-foreground",children:b})," 个模板"]}),c?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((U,oe)=>e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(vs,{className:"h-6 w-3/4"}),e.jsx(vs,{className:"h-4 w-full mt-2"})]}),e.jsx(Me,{children:e.jsx(vs,{className:"h-20 w-full"})}),e.jsx(id,{children:e.jsx(vs,{className:"h-9 w-full"})})]},oe))}):n.length===0?e.jsx(Ce,{className:"py-12",children:e.jsxs(Me,{className:"text-center text-muted-foreground",children:[e.jsx(ra,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{className:"text-lg font-medium",children:"暂无模板"}),e.jsx("p",{className:"mt-1",children:"还没有人分享配置模板,快来分享第一个吧!"})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:n.map(U=>e.jsx(A5,{pack:U,liked:O.has(U.id),liking:S.has(U.id),onLike:()=>F(U.id),onView:()=>L(U.id)},U.id))}),v>1&&e.jsx(ox,{children:e.jsxs(dx,{children:[e.jsx(qn,{children:e.jsx(Av,{onClick:()=>N(U=>Math.max(1,U-1)),className:g===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:v},(U,oe)=>oe+1).filter(U=>U===1||U===v||Math.abs(U-g)<=1).map((U,oe,Ne)=>{const je=oe>0&&U-Ne[oe-1]>1;return e.jsxs(qn,{children:[je&&e.jsx("span",{className:"px-2",children:"..."}),e.jsx(pc,{onClick:()=>N(U),isActive:U===g,className:"cursor-pointer",children:U})]},U)}),e.jsx(qn,{children:e.jsx(zv,{onClick:()=>N(U=>Math.min(v,U+1)),className:g===v?"pointer-events-none opacity-50":"cursor-pointer"})})]})})]})})]})}function A5({pack:a,liked:n,liking:r,onLike:c,onView:d}){const u=h=>new Date(h).toLocaleDateString("zh-CN",{year:"numeric",month:"short",day:"numeric"});return e.jsxs(Ce,{className:"flex flex-col hover:shadow-md transition-shadow",children:[e.jsxs(De,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx(Oe,{className:"text-lg line-clamp-1",children:a.name}),e.jsxs(ke,{variant:"secondary",className:"text-xs",children:["v",a.version]})]}),e.jsx(os,{className:"line-clamp-2 min-h-[40px]",children:a.description})]}),e.jsxs(Me,{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(jn,{className:"w-3.5 h-3.5"}),a.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(na,{className:"w-3.5 h-3.5"}),u(a.created_at)]})]}),e.jsxs("div",{className:"flex gap-4 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"提供商数量",children:[e.jsx(Ll,{className:"w-3.5 h-3.5"}),a.provider_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"模型数量",children:[e.jsx(Qn,{className:"w-3.5 h-3.5"}),a.model_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"任务配置数",children:[e.jsx(Yn,{className:"w-3.5 h-3.5"}),a.task_count]})]}),a.tags&&a.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(h=>e.jsxs(ke,{variant:"outline",className:"text-xs",children:[e.jsx(rd,{className:"w-2.5 h-2.5 mr-1"}),h]},h)),a.tags.length>3&&e.jsxs(ke,{variant:"outline",className:"text-xs",children:["+",a.tags.length-3]})]})]}),e.jsx(id,{className:"pt-3 border-t",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-3 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Xt,{className:"w-4 h-4"}),a.downloads]}),e.jsxs("button",{onClick:h=>{h.stopPropagation(),c()},disabled:r,className:`flex items-center gap-1 transition-colors ${n?"text-red-500":"hover:text-red-500"} ${r?"opacity-50":""}`,children:[e.jsx(Xr,{className:`w-4 h-4 ${n?"fill-current":""}`}),a.likes]})]}),e.jsx(_,{size:"sm",onClick:d,children:"查看详情"})]})})]})}var al="Accordion",z5=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[Tx,R5,D5]=x_(al),[jd]=td(al,[D5,Ej]),Ex=Ej(),xb=Rs.forwardRef((a,n)=>{const{type:r,...c}=a,d=c,u=c;return e.jsx(Tx.Provider,{scope:a.__scopeAccordion,children:r==="multiple"?e.jsx($5,{...u,ref:n}):e.jsx(U5,{...d,ref:n})})});xb.displayName=al;var[hb,O5]=jd(al),[fb,L5]=jd(al,{collapsible:!1}),U5=Rs.forwardRef((a,n)=>{const{value:r,defaultValue:c,onValueChange:d=()=>{},collapsible:u=!1,...h}=a,[f,p]=sd({prop:r,defaultProp:c??"",onChange:d,caller:al});return e.jsx(hb,{scope:a.__scopeAccordion,value:Rs.useMemo(()=>f?[f]:[],[f]),onItemOpen:p,onItemClose:Rs.useCallback(()=>u&&p(""),[u,p]),children:e.jsx(fb,{scope:a.__scopeAccordion,collapsible:u,children:e.jsx(pb,{...h,ref:n})})})}),$5=Rs.forwardRef((a,n)=>{const{value:r,defaultValue:c,onValueChange:d=()=>{},...u}=a,[h,f]=sd({prop:r,defaultProp:c??[],onChange:d,caller:al}),p=Rs.useCallback(N=>f((v=[])=>[...v,N]),[f]),g=Rs.useCallback(N=>f((v=[])=>v.filter(w=>w!==N)),[f]);return e.jsx(hb,{scope:a.__scopeAccordion,value:h,onItemOpen:p,onItemClose:g,children:e.jsx(fb,{scope:a.__scopeAccordion,collapsible:!0,children:e.jsx(pb,{...u,ref:n})})})}),[B5,vd]=jd(al),pb=Rs.forwardRef((a,n)=>{const{__scopeAccordion:r,disabled:c,dir:d,orientation:u="vertical",...h}=a,f=Rs.useRef(null),p=ad(f,n),g=R5(r),v=Gj(d)==="ltr",w=gn(a.onKeyDown,b=>{if(!z5.includes(b.key))return;const y=b.target,O=g().filter(J=>!J.ref.current?.disabled),R=O.findIndex(J=>J.ref.current===y),S=O.length;if(R===-1)return;b.preventDefault();let B=R;const E=0,C=S-1,A=()=>{B=R+1,B>C&&(B=E)},F=()=>{B=R-1,B{const{__scopeAccordion:r,value:c,...d}=a,u=vd(ed,r),h=O5(ed,r),f=Ex(r),p=qm(),g=c&&h.value.includes(c)||!1,N=u.disabled||a.disabled;return e.jsx(P5,{scope:r,open:g,disabled:N,triggerId:p,children:e.jsx(wj,{"data-orientation":u.orientation,"data-state":wb(g),...f,...d,ref:n,disabled:N,open:g,onOpenChange:v=>{v?h.onItemOpen(c):h.onItemClose(c)}})})});gb.displayName=ed;var jb="AccordionHeader",vb=Rs.forwardRef((a,n)=>{const{__scopeAccordion:r,...c}=a,d=vd(al,r),u=Mx(jb,r);return e.jsx(Zn.h3,{"data-orientation":d.orientation,"data-state":wb(u.open),"data-disabled":u.disabled?"":void 0,...c,ref:n})});vb.displayName=jb;var ex="AccordionTrigger",Nb=Rs.forwardRef((a,n)=>{const{__scopeAccordion:r,...c}=a,d=vd(al,r),u=Mx(ex,r),h=L5(ex,r),f=Ex(r);return e.jsx(Tx.ItemSlot,{scope:r,children:e.jsx(Fw,{"aria-disabled":u.open&&!h.collapsible||void 0,"data-orientation":d.orientation,id:u.triggerId,...f,...c,ref:n})})});Nb.displayName=ex;var bb="AccordionContent",yb=Rs.forwardRef((a,n)=>{const{__scopeAccordion:r,...c}=a,d=vd(al,r),u=Mx(bb,r),h=Ex(r);return e.jsx(Hw,{role:"region","aria-labelledby":u.triggerId,"data-orientation":d.orientation,...h,...c,ref:n,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...a.style}})});yb.displayName=bb;function wb(a){return a?"open":"closed"}var I5=xb,F5=gb,H5=vb,_b=Nb,Sb=yb;const V5=I5,kb=m.forwardRef(({className:a,...n},r)=>e.jsx(F5,{ref:r,className:I("border-b",a),...n}));kb.displayName="AccordionItem";const Cb=m.forwardRef(({className:a,children:n,...r},c)=>e.jsx(H5,{className:"flex",children:e.jsxs(_b,{ref:c,className:I("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",a),...r,children:[n,e.jsx(za,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));Cb.displayName=_b.displayName;const Tb=m.forwardRef(({className:a,children:n,...r},c)=>e.jsx(Sb,{ref:c,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...r,children:e.jsx("div",{className:I("pb-4 pt-0",a),children:n})}));Tb.displayName=Sb.displayName;const G5={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",lpmm_qa:"问答模型"};function q5(){const{packId:a}=Rb.useParams(),n=ca(),[r,c]=m.useState(null),[d,u]=m.useState(!0),[h,f]=m.useState(!1),[p,g]=m.useState(!1),[N,v]=m.useState(!1),[w,b]=m.useState(1),[y,O]=m.useState(null),[R,S]=m.useState(!1),[B,E]=m.useState(!1),[C,A]=m.useState({apply_providers:!0,apply_models:!0,apply_task_config:!0,task_mode:"append",selected_providers:void 0,selected_models:void 0,selected_tasks:void 0}),[F,L]=m.useState({}),[J,U]=m.useState({}),oe=Yv(),Ne=m.useCallback(async()=>{if(a){u(!0);try{const M=await IS(a);c(M);const K=await Qv(a,oe);f(K)}catch(M){console.error("加载 Pack 失败:",M),Qt({title:"加载模板失败",variant:"destructive"})}finally{u(!1)}}},[a,oe]);m.useEffect(()=>{Ne()},[Ne]);const je=async()=>{if(!(!a||p)){g(!0);try{const M=await Kv(a,oe);f(M.liked),r&&c({...r,likes:M.likes})}catch(M){console.error("点赞失败:",M),Qt({title:"点赞失败",variant:"destructive"})}finally{g(!1)}}},re=async()=>{if(r){v(!0),b(1),S(!0);try{const M=await VS(r);O(M);const K={};for(const ue of M.existing_providers)K[ue.pack_provider.name]=ue.local_providers[0].name;L(K);const P={};for(const ue of M.new_providers)P[ue.name]="";U(P)}catch(M){console.error("检测冲突失败:",M),Qt({title:"检测配置冲突失败",variant:"destructive"}),v(!1)}finally{S(!1)}}},fe=async()=>{if(r){if(C.apply_providers&&y){for(const M of y.new_providers)if(!J[M.name]){Qt({title:`请填写提供商 "${M.name}" 的 API Key`,variant:"destructive"});return}}E(!0);try{await GS(r,C,F,J),await HS(r.id,oe),c({...r,downloads:r.downloads+1}),Qt({title:"配置模板应用成功!"}),v(!1)}catch(M){console.error("应用 Pack 失败:",M),Qt({title:M instanceof Error?M.message:"应用配置失败",variant:"destructive"})}finally{E(!1)}}},ge=M=>new Date(M).toLocaleDateString("zh-CN",{year:"numeric",month:"long",day:"numeric"});return d?e.jsx(Q5,{}):r?e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:()=>n({to:"/config/pack-market"}),className:"gap-2",children:[e.jsx(Ma,{className:"w-4 h-4"}),"返回市场"]}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-6",children:[e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ra,{className:"w-10 h-10 text-primary mt-1"}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[r.name,e.jsxs(ke,{variant:"secondary",children:["v",r.version]})]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:r.description})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(jn,{className:"w-4 h-4"}),r.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(na,{className:"w-4 h-4"}),ge(r.created_at)]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Xt,{className:"w-4 h-4"}),r.downloads," 次下载"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Xr,{className:`w-4 h-4 ${h?"fill-red-500 text-red-500":""}`}),r.likes," 赞"]})]}),r.tags&&r.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:r.tags.map(M=>e.jsxs(ke,{variant:"outline",children:[e.jsx(rd,{className:"w-3 h-3 mr-1"}),M]},M))})]}),e.jsxs("div",{className:"flex flex-col gap-2 min-w-[160px]",children:[e.jsxs(_,{size:"lg",onClick:re,children:[e.jsx(Xt,{className:"w-4 h-4 mr-2"}),"应用模板"]}),e.jsxs(_,{variant:"outline",onClick:je,disabled:p,className:h?"text-red-500 border-red-200":"",children:[e.jsx(Xr,{className:`w-4 h-4 mr-2 ${h?"fill-current":""}`}),h?"已点赞":"点赞"]})]})]}),e.jsx(Yt,{}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(Ce,{children:e.jsxs(Me,{className:"flex items-center gap-3 py-4",children:[e.jsx(Ll,{className:"w-8 h-8 text-blue-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r.providers.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"API 提供商"})]})]})}),e.jsx(Ce,{children:e.jsxs(Me,{className:"flex items-center gap-3 py-4",children:[e.jsx(Qn,{className:"w-8 h-8 text-green-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r.models.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"模型配置"})]})]})}),e.jsx(Ce,{children:e.jsxs(Me,{className:"flex items-center gap-3 py-4",children:[e.jsx(Yn,{className:"w-8 h-8 text-purple-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:Object.keys(r.task_config).length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"任务配置"})]})]})})]}),e.jsxs(ta,{defaultValue:"providers",className:"space-y-4",children:[e.jsxs(Zt,{className:"w-full sm:w-auto grid grid-cols-3 sm:flex",children:[e.jsxs(Xe,{value:"providers",className:"gap-1 sm:gap-2",children:[e.jsx(Ll,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"提供商"}),e.jsx("span",{className:"sm:hidden",children:"提供商"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r.providers.length,")"]})]}),e.jsxs(Xe,{value:"models",className:"gap-1 sm:gap-2",children:[e.jsx(Qn,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"模型"}),e.jsx("span",{className:"sm:hidden",children:"模型"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",r.models.length,")"]})]}),e.jsxs(Xe,{value:"tasks",className:"gap-1 sm:gap-2",children:[e.jsx(Yn,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"任务配置"}),e.jsx("span",{className:"sm:hidden",children:"任务"}),e.jsxs("span",{className:"hidden sm:inline",children:["(",Object.keys(r.task_config).length,")"]})]})]}),e.jsx(ws,{value:"providers",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"API 提供商"}),e.jsx(os,{children:"模板中包含的 API 提供商配置(不含 API Key)"})]}),e.jsx(Me,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{children:"名称"}),e.jsx(We,{children:"Base URL"}),e.jsx(We,{children:"类型"})]})}),e.jsx(Bl,{children:r.providers.map(M=>e.jsxs(ut,{children:[e.jsx(Ke,{className:"font-medium whitespace-nowrap",children:M.name}),e.jsx(Ke,{className:"text-muted-foreground font-mono text-sm max-w-[200px] truncate",children:M.base_url}),e.jsx(Ke,{children:e.jsx(ke,{variant:"outline",children:M.client_type})})]},M.name))})]})})})]})}),e.jsx(ws,{value:"models",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"模型配置"}),e.jsx(os,{children:"模板中包含的模型配置"})]}),e.jsx(Me,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Ul,{children:[e.jsx($l,{children:e.jsxs(ut,{children:[e.jsx(We,{children:"模型名称"}),e.jsx(We,{children:"标识符"}),e.jsx(We,{children:"提供商"}),e.jsx(We,{className:"text-right",children:"价格 (入/出)"})]})}),e.jsx(Bl,{children:r.models.map(M=>e.jsxs(ut,{children:[e.jsx(Ke,{className:"font-medium whitespace-nowrap",children:M.name}),e.jsx(Ke,{className:"text-muted-foreground font-mono text-sm max-w-[150px] truncate",children:M.model_identifier}),e.jsx(Ke,{className:"whitespace-nowrap",children:M.api_provider}),e.jsxs(Ke,{className:"text-right text-muted-foreground whitespace-nowrap",children:["¥",M.price_in," / ¥",M.price_out]})]},M.name))})]})})})]})}),e.jsx(ws,{value:"tasks",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Oe,{children:"任务配置"}),e.jsx(os,{children:"模板中各任务类型的模型分配"})]}),e.jsx(Me,{children:e.jsx(V5,{type:"multiple",className:"w-full",children:Object.entries(r.task_config).map(([M,K])=>e.jsxs(kb,{value:M,children:[e.jsx(Cb,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vn,{className:"w-4 h-4"}),G5[M]||M,e.jsxs(ke,{variant:"secondary",className:"ml-2",children:[K.model_list.length," 个模型"]})]})}),e.jsx(Tb,{children:e.jsxs("div",{className:"space-y-2 pl-6",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"分配的模型:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:K.model_list.map(P=>e.jsx(ke,{variant:"outline",children:P},P))}),K.temperature!==void 0&&e.jsxs("div",{className:"text-sm",children:["Temperature: ",e.jsx("span",{className:"font-mono",children:K.temperature})]}),K.max_tokens!==void 0&&e.jsxs("div",{className:"text-sm",children:["Max Tokens: ",e.jsx("span",{className:"font-mono",children:K.max_tokens})]})]})})]},M))})})]})})]}),e.jsx(K5,{open:N,onOpenChange:v,pack:r,step:w,setStep:b,conflicts:y,detectingConflicts:R,applying:B,options:C,setOptions:A,_providerMapping:F,_setProviderMapping:L,newProviderApiKeys:J,setNewProviderApiKeys:U,onApply:fe})]})})}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ra,{className:"w-16 h-16 mx-auto mb-4 opacity-50"}),e.jsx("h2",{className:"text-xl font-semibold",children:"模板不存在"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"该配置模板可能已被删除或尚未通过审核"}),e.jsxs(_,{className:"mt-4",onClick:()=>n({to:"/config/pack-market"}),children:[e.jsx(Ma,{className:"w-4 h-4 mr-2"}),"返回市场"]})]})}function K5({open:a,onOpenChange:n,pack:r,step:c,setStep:d,conflicts:u,detectingConflicts:h,applying:f,options:p,setOptions:g,_providerMapping:N,_setProviderMapping:v,newProviderApiKeys:w,setNewProviderApiKeys:b,onApply:y}){return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Os,{children:[e.jsxs(Ls,{className:"flex items-center gap-2",children:[e.jsx(ra,{className:"w-5 h-5"}),"应用配置模板"]}),e.jsxs(Ks,{children:["步骤 ",c," / ",3,":",c===1&&"选择要应用的内容",c===2&&"配置提供商映射",c===3&&"确认并应用"]})]}),h?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(zs,{className:"w-8 h-8 mx-auto animate-spin text-primary"}),e.jsx("p",{className:"mt-4 text-muted-foreground",children:"正在检测配置冲突..."})]}):e.jsxs(e.Fragment,{children:[c===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"apply_providers",checked:p.apply_providers,onCheckedChange:R=>g({...p,apply_providers:R})}),e.jsxs(T,{htmlFor:"apply_providers",className:"flex items-center gap-2",children:[e.jsx(Ll,{className:"w-4 h-4"}),"应用提供商配置 (",r.providers.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"apply_models",checked:p.apply_models,onCheckedChange:R=>g({...p,apply_models:R})}),e.jsxs(T,{htmlFor:"apply_models",className:"flex items-center gap-2",children:[e.jsx(Qn,{className:"w-4 h-4"}),"应用模型配置 (",r.models.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"apply_task_config",checked:p.apply_task_config,onCheckedChange:R=>g({...p,apply_task_config:R})}),e.jsxs(T,{htmlFor:"apply_task_config",className:"flex items-center gap-2",children:[e.jsx(Yn,{className:"w-4 h-4"}),"应用任务配置 (",Object.keys(r.task_config).length," 个)"]})]})]}),p.apply_task_config&&e.jsxs("div",{className:"pl-6 space-y-2 border-l-2 border-muted",children:[e.jsx(T,{className:"text-sm font-medium",children:"任务配置应用模式"}),e.jsxs(Sx,{value:p.task_mode,onValueChange:R=>g({...p,task_mode:R}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xo,{value:"append",id:"mode_append"}),e.jsx(T,{htmlFor:"mode_append",className:"font-normal",children:"追加模式 - 将模板中的模型添加到现有配置"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Xo,{value:"replace",id:"mode_replace"}),e.jsx(T,{htmlFor:"mode_replace",className:"font-normal",children:"替换模式 - 用模板配置完全替换现有配置"})]})]})]})]}),c===2&&u&&e.jsxs("div",{className:"space-y-4",children:[p.apply_providers&&u.existing_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(Gn,{children:"发现已有的提供商"}),e.jsx(lt,{children:"以下提供商的 URL 与您本地配置中的提供商匹配,将自动使用本地提供商:"})]}),e.jsx("div",{className:"space-y-2",children:u.existing_providers.map(({pack_provider:R,local_providers:S})=>e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-lg",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500 flex-shrink-0"}),e.jsx("span",{className:"font-medium flex-shrink-0",children:R.name}),e.jsx(Wt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),S.length===1?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground",children:S[0].name}),e.jsx(ke,{variant:"outline",className:"ml-auto",children:"URL 匹配"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Pe,{value:N[R.name]||S[0].name,onValueChange:B=>v({...N,[R.name]:B}),children:[e.jsx($e,{className:"w-[200px]",children:e.jsx(Ie,{})}),e.jsx(Be,{children:S.map(B=>e.jsx(Z,{value:B.name,children:B.name},B.name))})]}),e.jsxs(ke,{variant:"outline",className:"ml-auto",children:[S.length," 个匹配"]})]})]},R.name))})]}),p.apply_providers&&u.new_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(at,{variant:"destructive",children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsx(Gn,{children:"需要配置 API Key"}),e.jsx(lt,{children:"以下提供商在您的本地配置中不存在,需要填写 API Key:"})]}),e.jsx("div",{className:"space-y-4",children:u.new_providers.map(R=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(lx,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"font-medium",children:R.name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",R.base_url,")"]})]}),e.jsx(ae,{type:"password",placeholder:`输入 ${R.name} 的 API Key`,value:w[R.name]||"",onChange:S=>b({...w,[R.name]:S.target.value})})]},R.name))})]}),(!p.apply_providers||u.existing_providers.length===0&&u.new_providers.length===0)&&e.jsxs(at,{children:[e.jsx(Ct,{className:"h-4 w-4"}),e.jsx(Gn,{children:"无需配置"}),e.jsx(lt,{children:"模板中没有提供商配置,或您选择不应用提供商。"})]})]}),c===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{children:[e.jsx(Ft,{className:"h-4 w-4"}),e.jsx(Gn,{children:"确认应用"}),e.jsx(lt,{children:"请确认以下将要应用的内容:"})]}),e.jsxs("div",{className:"space-y-2",children:[p.apply_providers&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500"}),e.jsx(Ll,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",r.providers.length," 个提供商配置"]})]}),p.apply_models&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500"}),e.jsx(Qn,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",r.models.length," 个模型配置"]})]}),p.apply_task_config&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500"}),e.jsx(Yn,{className:"w-4 h-4"}),e.jsxs("span",{children:[p.task_mode==="append"?"追加":"替换"," ",Object.keys(r.task_config).length," 个任务配置"]})]})]}),u&&u.new_providers.length>0&&e.jsxs(at,{variant:"destructive",children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(lt,{children:["将添加 ",u.new_providers.length," 个新提供商,请确保已填写正确的 API Key。"]})]})]})]}),e.jsxs(st,{className:"flex justify-between",children:[e.jsx("div",{children:c>1&&!h&&e.jsx(_,{variant:"outline",onClick:()=>d(c-1),disabled:f,children:"上一步"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_,{variant:"outline",onClick:()=>n(!1),disabled:f,children:"取消"}),c<3?e.jsx(_,{onClick:()=>d(c+1),disabled:h,children:"下一步"}):e.jsxs(_,{onClick:y,disabled:f,children:[f&&e.jsx(zs,{className:"w-4 h-4 mr-2 animate-spin"}),"应用模板"]})]})]})]})})}function Q5(){return e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(vs,{className:"h-9 w-24"}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-6",children:[e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(vs,{className:"w-10 h-10"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(vs,{className:"h-8 w-2/3"}),e.jsx(vs,{className:"h-4 w-full"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsx(vs,{className:"h-4 w-24"}),e.jsx(vs,{className:"h-4 w-32"}),e.jsx(vs,{className:"h-4 w-28"}),e.jsx(vs,{className:"h-4 w-20"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(vs,{className:"h-6 w-20"}),e.jsx(vs,{className:"h-6 w-24"}),e.jsx(vs,{className:"h-6 w-16"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 min-w-[160px]",children:[e.jsx(vs,{className:"h-10 w-full"}),e.jsx(vs,{className:"h-10 w-full"})]})]}),e.jsx(vs,{className:"h-px w-full"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(vs,{className:"h-24"}),e.jsx(vs,{className:"h-24"}),e.jsx(vs,{className:"h-24"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(vs,{className:"h-10 w-32"}),e.jsx(vs,{className:"h-10 w-32"}),e.jsx(vs,{className:"h-10 w-32"})]}),e.jsx(vs,{className:"h-96 w-full"})]})]})})})}function Y5(){const a=ca(),[n,r]=m.useState(!0);return m.useEffect(()=>{let c=!1;return(async()=>{try{const u=await cc();!c&&!u&&a({to:"/auth"})}catch{c||a({to:"/auth"})}finally{c||r(!1)}})(),()=>{c=!0}},[a]),{checking:n}}async function J5(){return await cc()}const X5=Wr("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"}}),Eb=m.forwardRef(({className:a,size:n,abbrTitle:r,children:c,...d},u)=>e.jsx("kbd",{className:I(X5({size:n,className:a})),ref:u,...d,children:r?e.jsx("abbr",{title:r,children:c}):c}));Eb.displayName="Kbd";const Z5=[{icon:nd,title:"首页",description:"查看仪表板概览",path:"/",category:"概览"},{icon:Ea,title:"麦麦主程序配置",description:"配置麦麦的核心设置",path:"/config/bot",category:"配置"},{icon:Ll,title:"麦麦模型提供商配置",description:"配置模型提供商",path:"/config/modelProvider",category:"配置"},{icon:dv,title:"麦麦模型配置",description:"配置模型参数",path:"/config/model",category:"配置"},{icon:ld,title:"表情包管理",description:"管理麦麦的表情包",path:"/resource/emoji",category:"资源"},{icon:Ra,title:"表达方式管理",description:"管理麦麦的表达方式",path:"/resource/expression",category:"资源"},{icon:uv,title:"人物信息管理",description:"管理人物信息",path:"/resource/person",category:"资源"},{icon:Jr,title:"黑话管理",description:"管理麦麦学习到的黑话和俚语",path:"/resource/jargon",category:"资源"},{icon:Y_,title:"统计信息",description:"查看使用统计",path:"/statistics",category:"监控"},{icon:ra,title:"插件市场",description:"浏览和安装插件",path:"/plugins",category:"扩展"},{icon:nx,title:"日志查看器",description:"查看系统日志",path:"/logs",category:"监控"},{icon:vn,title:"系统设置",description:"配置系统参数",path:"/settings",category:"系统"}];function W5({open:a,onOpenChange:n}){const[r,c]=m.useState(""),[d,u]=m.useState(0),h=ca(),f=Z5.filter(N=>N.title.toLowerCase().includes(r.toLowerCase())||N.description.toLowerCase().includes(r.toLowerCase())||N.category.toLowerCase().includes(r.toLowerCase())),p=m.useCallback(N=>{h({to:N}),n(!1),c(""),u(0)},[h,n]),g=m.useCallback(N=>{N.key==="ArrowDown"?(N.preventDefault(),u(v=>(v+1)%f.length)):N.key==="ArrowUp"?(N.preventDefault(),u(v=>(v-1+f.length)%f.length)):N.key==="Enter"&&f[d]&&(N.preventDefault(),p(f[d].path))},[f,d,p]);return e.jsx(Ps,{open:a,onOpenChange:n,children:e.jsxs(Ds,{className:"max-w-2xl p-0 gap-0",children:[e.jsxs(Os,{className:"px-4 pt-4 pb-0",children:[e.jsx(Ls,{className:"sr-only",children:"搜索"}),e.jsxs("div",{className:"relative",children:[e.jsx(Tt,{className:"absolute left-3 top-1/2 h-5 w-5 -translate-y-1/2 text-muted-foreground"}),e.jsx(ae,{value:r,onChange:N=>{c(N.target.value),u(0)},onKeyDown:g,placeholder:"搜索页面...",className:"h-12 pl-11 text-base border-0 focus-visible:ring-0 shadow-none",autoFocus:!0})]})]}),e.jsx("div",{className:"border-t",children:e.jsx(Je,{className:"h-[400px]",children:f.length>0?e.jsx("div",{className:"p-2",children:f.map((N,v)=>{const w=N.icon;return e.jsxs("button",{onClick:()=>p(N.path),onMouseEnter:()=>u(v),className:I("w-full flex items-center gap-3 px-3 py-2.5 rounded-md text-left transition-colors",v===d?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[e.jsx(w,{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:N.title}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:N.description})]}),e.jsx("div",{className:"text-xs text-muted-foreground px-2 py-1 bg-muted rounded",children:N.category})]},N.path)})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(Tt,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r?"未找到匹配的页面":"输入关键词开始搜索"})]})})}),e.jsx("div",{className:"border-t px-4 py-3 flex items-center justify-between text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↑"}),e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↓"}),"导航"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Enter"}),"选择"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Esc"}),"关闭"]})]})})]})})}function eT(){const a=window.location.protocol==="http:",n=window.location.hostname.toLowerCase(),r=n==="localhost"||n==="127.0.0.1"||n==="::1",c=sessionStorage.getItem("http-warning-dismissed")==="true",[d,u]=m.useState(a&&!r&&!c),[h,f]=m.useState(!1),p=()=>{f(!0),u(!1),sessionStorage.setItem("http-warning-dismissed","true")};return!d||h?null:e.jsx("div",{className:"relative bg-amber-500/10 border-b border-amber-500/20 backdrop-blur-sm",children:e.jsx("div",{className:"container mx-auto px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx(Jt,{className:"h-5 w-5 text-amber-600 dark:text-amber-500 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("p",{className:"text-sm font-medium text-amber-900 dark:text-amber-100",children:[e.jsx("span",{className:"font-semibold",children:"安全警告:"}),"您正在使用 ",e.jsx("strong",{children:"HTTP"})," 访问 MaiBot WebUI"]}),e.jsx("p",{className:"text-xs text-amber-800 dark:text-amber-200 mt-1",children:"如果这是公网服务器,您的数据(包括 Token、聊天记录等)可能在传输过程中被窃取。强烈建议使用 HTTPS 访问或仅在本地网络使用。"})]})]}),e.jsx(_,{variant:"ghost",size:"icon",onClick:p,className:"h-8 w-8 text-amber-700 hover:text-amber-900 dark:text-amber-400 dark:hover:text-amber-200 flex-shrink-0","aria-label":"关闭警告",children:e.jsx(Aa,{className:"h-4 w-4"})})]})})})}function sT(){const[a,n]=m.useState(0),[r,c]=m.useState(!1),d=m.useRef(null);m.useEffect(()=>{const g=N=>{const v=N.target;if(v.scrollHeight>v.clientHeight+100){d.current=v;const w=v.scrollTop,b=v.scrollHeight-v.clientHeight,y=b>0?w/b*100:0;n(y),c(w>300)}};return window.addEventListener("scroll",g,{capture:!0,passive:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})},[]);const u=()=>{d.current?.scrollTo({top:0,behavior:"smooth"})},h=18,f=2*Math.PI*h,p=f-a/100*f;return e.jsx("div",{className:I("fixed bottom-24 right-8 z-50 transition-all duration-500 ease-in-out transform",r?"translate-x-0 opacity-100":"translate-x-32 opacity-0 pointer-events-none"),children:e.jsxs(_,{variant:"outline",size:"icon",className:I("relative h-12 w-12 rounded-full shadow-xl","bg-background/80 backdrop-blur-md border-border/50","hover:bg-accent hover:scale-110 hover:shadow-2xl hover:border-primary/50","transition-all duration-300","group"),onClick:u,"aria-label":"回到顶部",children:[e.jsxs("svg",{className:"absolute inset-0 h-full w-full -rotate-90 transform p-1",viewBox:"0 0 44 44",children:[e.jsx("circle",{className:"text-muted-foreground/10",strokeWidth:"3",stroke:"currentColor",fill:"transparent",r:h,cx:"22",cy:"22"}),e.jsx("circle",{className:"text-primary transition-all duration-100 ease-out",strokeWidth:"3",strokeDasharray:f,strokeDashoffset:p,strokeLinecap:"round",stroke:"currentColor",fill:"transparent",r:h,cx:"22",cy:"22"})]}),e.jsx(J_,{className:"h-5 w-5 text-primary transition-transform duration-300 group-hover:-translate-y-1 group-hover:scale-110",strokeWidth:2.5}),e.jsx("div",{className:"absolute inset-0 rounded-full bg-primary/5 opacity-0 group-hover:opacity-100 transition-opacity duration-300"})]})})}const tT=f_,aT=p_,lT=g_,Mb=m.forwardRef(({className:a,sideOffset:n=4,...r},c)=>e.jsx(h_,{children:e.jsx(qj,{ref:c,sideOffset:n,className:I("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]",a),...r})}));Mb.displayName=qj.displayName;function nT({children:a}){const{checking:n}=Y5(),[r,c]=m.useState(!0),[d,u]=m.useState(!1),[h,f]=m.useState(!1),[p,g]=m.useState(!1),{theme:N,setTheme:v}=xx(),w=X0();if(m.useEffect(()=>{if(r)g(!1);else{const S=setTimeout(()=>{g(!0)},350);return()=>clearTimeout(S)}},[r]),m.useEffect(()=>{const S=B=>{(B.metaKey||B.ctrlKey)&&B.key==="k"&&(B.preventDefault(),f(!0))};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[]),n)return e.jsx("div",{className:"flex h-screen items-center justify-center bg-background",children:e.jsx("div",{className:"text-muted-foreground",children:"正在验证登录状态..."})});const b=[{title:"概览",items:[{icon:nd,label:"首页",path:"/"}]},{title:"麦麦配置编辑",items:[{icon:Ea,label:"麦麦主程序配置",path:"/config/bot"},{icon:Ll,label:"AI模型厂商配置",path:"/config/modelProvider",tourId:"sidebar-model-provider"},{icon:dv,label:"模型管理与分配",path:"/config/model",tourId:"sidebar-model-management"},{icon:_g,label:"麦麦适配器配置",path:"/config/adapter"}]},{title:"麦麦资源管理",items:[{icon:ld,label:"表情包管理",path:"/resource/emoji"},{icon:Ra,label:"表达方式管理",path:"/resource/expression"},{icon:Jr,label:"黑话管理",path:"/resource/jargon"},{icon:uv,label:"人物信息管理",path:"/resource/person"},{icon:rv,label:"知识库图谱可视化",path:"/resource/knowledge-graph"},{icon:Yr,label:"麦麦知识库管理",path:"/resource/knowledge-base"}]},{title:"扩展与监控",items:[{icon:ra,label:"插件市场",path:"/plugins"},{icon:cv,label:"配置模板市场",path:"/config/pack-market"},{icon:_g,label:"插件配置",path:"/plugin-config"},{icon:nx,label:"日志查看器",path:"/logs"},{icon:sx,label:"计划器&回复器监控",path:"/planner-monitor"},{icon:Ra,label:"本地聊天室",path:"/chat"}]},{title:"系统",items:[{icon:vn,label:"系统设置",path:"/settings"}]}],O=N==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":N,R=async()=>{await z1()};return e.jsx(tT,{delayDuration:300,children:e.jsxs("div",{className:"flex h-screen overflow-hidden",children:[e.jsxs("aside",{className:I("fixed inset-y-0 left-0 z-50 flex flex-col border-r bg-card transition-all duration-300 lg:relative lg:z-0","w-64 lg:w-auto",r?"lg:w-64":"lg:w-16",d?"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:I("relative flex items-center justify-center flex-1 transition-all overflow-hidden","lg:flex-1",!r&&"lg:flex-none lg:w-8"),children:[e.jsxs("div",{className:I("flex items-baseline gap-2",!r&&"lg:hidden"),children:[e.jsx("span",{className:"font-bold text-xl text-primary-gradient whitespace-nowrap",children:"MaiBot WebUI"}),e.jsx("span",{className:"text-xs text-primary/60 whitespace-nowrap",children:x2()})]}),!r&&e.jsx("span",{className:"hidden lg:block font-bold text-primary-gradient text-2xl",children:"M"})]})}),e.jsx(Je,{className:I("flex-1 overflow-x-hidden",!r&&"lg:w-16"),children:e.jsx("nav",{className:I("p-4",!r&&"lg:p-2 lg:w-16"),children:e.jsx("ul",{className:I("space-y-6",!r&&"lg:space-y-3 lg:w-full"),children:b.map((S,B)=>e.jsxs("li",{children:[e.jsx("div",{className:I("px-3 h-[1.25rem]","mb-2",!r&&"lg:mb-1 lg:invisible"),children:e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground/60 whitespace-nowrap",children:S.title})}),!r&&B>0&&e.jsx("div",{className:"hidden lg:block mb-2 border-t border-border"}),e.jsx("ul",{className:"space-y-1",children:S.items.map(E=>{const C=w({to:E.path}),A=E.icon,F=e.jsxs(e.Fragment,{children:[C&&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:I("flex items-center transition-all duration-300",r?"gap-3":"gap-3 lg:gap-0"),children:[e.jsx(A,{className:I("h-5 w-5 flex-shrink-0",C&&"text-primary"),strokeWidth:2,fill:"none"}),e.jsx("span",{className:I("text-sm font-medium whitespace-nowrap transition-all duration-300",C&&"font-semibold",r?"opacity-100 max-w-[200px]":"opacity-100 max-w-[200px] lg:opacity-0 lg:max-w-0 lg:overflow-hidden"),children:E.label})]})]});return e.jsx("li",{className:"relative",children:e.jsxs(aT,{children:[e.jsx(lT,{asChild:!0,children:e.jsx(Fn,{to:E.path,"data-tour":E.tourId,className:I("relative flex items-center rounded-lg py-2 transition-all duration-300","hover:bg-accent hover:text-accent-foreground",C?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground",r?"px-3":"px-3 lg:px-0 lg:justify-center lg:w-12 lg:mx-auto"),onClick:()=>u(!1),children:F})}),p&&e.jsx(Mb,{side:"right",className:"hidden lg:block",children:e.jsx("p",{children:E.label})})]})},E.path)})})]},S.title))})})})]}),d&&e.jsx("div",{className:"fixed inset-0 z-40 bg-black/50 lg:hidden",onClick:()=>u(!1)}),e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(eT,{}),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:()=>u(!d),className:"rounded-lg p-2 hover:bg-accent lg:hidden",children:e.jsx(X_,{className:"h-5 w-5"})}),e.jsx("button",{onClick:()=>c(!r),className:"hidden rounded-lg p-2 hover:bg-accent lg:block",title:r?"收起侧边栏":"展开侧边栏",children:e.jsx(Da,{className:I("h-5 w-5 transition-transform",!r&&"rotate-180")})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fn,{to:"/annual-report",children:e.jsxs(_,{variant:"ghost",size:"sm",className:"gap-2 bg-gradient-to-r from-pink-500/10 to-purple-500/10 hover:from-pink-500/20 hover:to-purple-500/20 border border-pink-500/20",title:"查看年度总结",children:[e.jsx(Z_,{className:"h-4 w-4 text-pink-500"}),e.jsx("span",{className:"hidden sm:inline bg-gradient-to-r from-pink-500 to-purple-500 bg-clip-text text-transparent font-medium",children:"2025 年度总结"})]})}),e.jsxs("button",{onClick:()=>f(!0),className:"relative hidden md:flex items-center w-64 h-9 pl-9 pr-16 bg-background/50 border rounded-md hover:bg-accent/50 transition-colors text-left",children:[e.jsx(Tt,{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(Eb,{size:"sm",className:"absolute right-2 top-1/2 -translate-y-1/2",children:[e.jsx("span",{className:"text-xs",children:"⌘"}),"K"]})]}),e.jsx(W5,{open:h,onOpenChange:f}),e.jsxs(_,{variant:"ghost",size:"sm",onClick:()=>window.open("https://docs.mai-mai.org","_blank"),className:"gap-2",title:"查看麦麦文档",children:[e.jsx(W_,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"麦麦文档"})]}),e.jsx("button",{onClick:S=>{c2(O==="dark"?"light":"dark",v,S)},className:"rounded-lg p-2 hover:bg-accent",title:O==="dark"?"切换到浅色模式":"切换到深色模式",children:O==="dark"?e.jsx(ax,{className:"h-5 w-5"}):e.jsx(ec,{className:"h-5 w-5"})}),e.jsx("div",{className:"h-6 w-px bg-border"}),e.jsxs(_,{variant:"ghost",size:"sm",onClick:R,className:"gap-2",title:"登出系统",children:[e.jsx(e1,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"登出"})]})]})]}),e.jsx("main",{className:"flex-1 overflow-hidden bg-background",children:a}),e.jsx(sT,{})]})]})})}function rT(a){const n=a.split(` -`).slice(1),r=[];for(const c of n){const d=c.trim();if(!d.startsWith("at "))continue;const u=d.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);u?r.push({functionName:u[1]||"",fileName:u[2],lineNumber:u[3],columnNumber:u[4],raw:d}):r.push({functionName:"",fileName:"",lineNumber:"",columnNumber:"",raw:d})}return r}function iT({error:a,errorInfo:n}){const[r,c]=m.useState(!0),[d,u]=m.useState(!1),[h,f]=m.useState(!1),p=a.stack?rT(a.stack):[],g=async()=>{const N=` -Error: ${a.name} -Message: ${a.message} - -Stack Trace: -${a.stack||"No stack trace available"} - -Component Stack: -${n?.componentStack||"No component stack available"} - -URL: ${window.location.href} -User Agent: ${navigator.userAgent} -Time: ${new Date().toISOString()} - `.trim();try{await navigator.clipboard.writeText(N),f(!0),setTimeout(()=>f(!1),2e3)}catch(v){console.error("Failed to copy:",v)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{variant:"destructive",className:"border-red-500/50 bg-red-500/10",children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(lt,{className:"font-mono text-sm",children:[e.jsxs("span",{className:"font-semibold",children:[a.name,":"]})," ",a.message]})]}),p.length>0&&e.jsxs(uc,{open:r,onOpenChange:c,children:[e.jsx(mc,{asChild:!0,children:e.jsxs(_,{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(s1,{className:"h-4 w-4"}),"Stack Trace (",p.length," frames)"]}),r?e.jsx(Qr,{className:"h-4 w-4"}):e.jsx(za,{className:"h-4 w-4"})]})}),e.jsx(xc,{children:e.jsx(Je,{className:"h-[280px] rounded-md border bg-muted/30",children:e.jsx("div",{className:"p-3 space-y-1",children:p.map((N,v)=>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:[v+1,"."]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-primary font-medium",children:N.functionName}),N.fileName&&e.jsxs("div",{className:"text-muted-foreground mt-0.5 break-all",children:[N.fileName,N.lineNumber&&e.jsxs("span",{className:"text-yellow-600 dark:text-yellow-400",children:[":",N.lineNumber,":",N.columnNumber]})]})]})]})},v))})})})]}),n?.componentStack&&e.jsxs(uc,{open:d,onOpenChange:u,children:[e.jsx(mc,{asChild:!0,children:e.jsxs(_,{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(Jt,{className:"h-4 w-4"}),"Component Stack"]}),d?e.jsx(Qr,{className:"h-4 w-4"}):e.jsx(za,{className:"h-4 w-4"})]})}),e.jsx(xc,{children:e.jsx(Je,{className:"h-[200px] rounded-md border bg-muted/30",children:e.jsx("pre",{className:"p-3 font-mono text-xs whitespace-pre-wrap text-muted-foreground",children:n.componentStack})})})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:g,className:"w-full",children:h?e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"mr-2 h-4 w-4 text-green-500"}),"已复制到剪贴板"]}):e.jsxs(e.Fragment,{children:[e.jsx(Fo,{className:"mr-2 h-4 w-4"}),"复制错误信息"]})})]})}function Ab({error:a,errorInfo:n}){const r=()=>{window.location.href="/"},c=()=>{window.location.reload()};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(Ce,{className:"w-full max-w-2xl shadow-lg",children:[e.jsxs(De,{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(Jt,{className:"h-8 w-8 text-red-600 dark:text-red-400"})}),e.jsx(Oe,{className:"text-2xl font-bold",children:"页面出现了问题"}),e.jsx(os,{className:"text-base mt-2",children:"应用程序遇到了意外错误。您可以尝试刷新页面或返回首页。"})]}),e.jsxs(Me,{className:"space-y-4",children:[e.jsx(iT,{error:a,errorInfo:n}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 pt-2",children:[e.jsxs(_,{onClick:c,className:"flex-1",children:[e.jsx(dt,{className:"mr-2 h-4 w-4"}),"刷新页面"]}),e.jsxs(_,{onClick:r,variant:"outline",className:"flex-1",children:[e.jsx(nd,{className:"mr-2 h-4 w-4"}),"返回首页"]})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground pt-2",children:"如果问题持续存在,请将错误信息复制并反馈给开发者"})]})]})})}class cT extends m.Component{constructor(n){super(n),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,r){console.error("ErrorBoundary caught an error:",n,r),this.setState({errorInfo:r})}handleReset=()=>{this.setState({hasError:!1,error:null,errorInfo:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?this.props.fallback:e.jsx(Ab,{error:this.state.error,errorInfo:this.state.errorInfo}):this.props.children}}function zb({error:a}){return e.jsx(Ab,{error:a,errorInfo:null})}const vc=Z0({component:()=>e.jsxs(e.Fragment,{children:[e.jsx(rj,{}),!1]}),beforeLoad:()=>{if(window.location.pathname==="/"&&!J5())throw ew({to:"/auth"})}}),oT=Qs({getParentRoute:()=>vc,path:"/auth",component:E2}),dT=Qs({getParentRoute:()=>vc,path:"/setup",component:G2}),nt=Qs({getParentRoute:()=>vc,id:"protected",component:()=>e.jsx(nT,{children:e.jsx(rj,{})}),errorComponent:({error:a})=>e.jsx(zb,{error:a})}),uT=Qs({getParentRoute:()=>nt,path:"/",component:l2}),mT=Qs({getParentRoute:()=>nt,path:"/config/bot",component:wS}),xT=Qs({getParentRoute:()=>nt,path:"/config/modelProvider",component:OS}),hT=Qs({getParentRoute:()=>nt,path:"/config/model",component:r4}),fT=Qs({getParentRoute:()=>nt,path:"/config/adapter",component:T4}),pT=Qs({getParentRoute:()=>nt,path:"/resource/emoji",component:X4}),gT=Qs({getParentRoute:()=>nt,path:"/resource/expression",component:sk}),jT=Qs({getParentRoute:()=>nt,path:"/resource/person",component:Sk}),vT=Qs({getParentRoute:()=>nt,path:"/resource/jargon",component:fk}),NT=Qs({getParentRoute:()=>nt,path:"/resource/knowledge-graph",component:Dk}),bT=Qs({getParentRoute:()=>nt,path:"/resource/knowledge-base",component:Ok}),yT=Qs({getParentRoute:()=>nt,path:"/logs",component:Uk}),wT=Qs({getParentRoute:()=>nt,path:"/planner-monitor",component:qk}),_T=Qs({getParentRoute:()=>nt,path:"/chat",component:AC}),ST=Qs({getParentRoute:()=>nt,path:"/plugins",component:mC}),kT=Qs({getParentRoute:()=>nt,path:"/plugin-detail",component:yC}),CT=Qs({getParentRoute:()=>nt,path:"/model-presets",component:hC}),TT=Qs({getParentRoute:()=>nt,path:"/plugin-config",component:gC}),ET=Qs({getParentRoute:()=>nt,path:"/plugin-mirrors",component:vC}),MT=Qs({getParentRoute:()=>nt,path:"/settings",component:y2}),AT=Qs({getParentRoute:()=>nt,path:"/config/pack-market",component:M5}),Rb=Qs({getParentRoute:()=>nt,path:"/config/pack-market/$packId",component:q5}),zT=Qs({getParentRoute:()=>nt,path:"/survey/webui-feedback",component:KC}),RT=Qs({getParentRoute:()=>nt,path:"/survey/maibot-feedback",component:QC}),DT=Qs({getParentRoute:()=>nt,path:"/annual-report",component:e5}),OT=Qs({getParentRoute:()=>vc,path:"*",component:Pv}),LT=vc.addChildren([oT,dT,nt.addChildren([uT,mT,xT,hT,fT,pT,gT,vT,jT,NT,bT,ST,kT,CT,TT,ET,yT,wT,_T,MT,AT,Rb,zT,RT,DT]),OT]),UT=W0({routeTree:LT,defaultNotFoundComponent:Pv,defaultErrorComponent:({error:a})=>e.jsx(zb,{error:a})});function $T({children:a,defaultTheme:n="system",storageKey:r="ui-theme",...c}){const[d,u]=m.useState(()=>localStorage.getItem(r)||n);m.useEffect(()=>{const f=window.document.documentElement;if(f.classList.remove("light","dark"),d==="system"){const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";f.classList.add(p);return}f.classList.add(d)},[d]),m.useEffect(()=>{const f=localStorage.getItem("accent-color");if(f){const p=document.documentElement,N={blue:{hsl:"221.2 83.2% 53.3%",darkHsl:"217.2 91.2% 59.8%",gradient:null},purple:{hsl:"271 91% 65%",darkHsl:"270 95% 75%",gradient:null},green:{hsl:"142 71% 45%",darkHsl:"142 76% 36%",gradient:null},orange:{hsl:"25 95% 53%",darkHsl:"20 90% 48%",gradient:null},pink:{hsl:"330 81% 60%",darkHsl:"330 85% 70%",gradient:null},red:{hsl:"0 84% 60%",darkHsl:"0 90% 70%",gradient:null},"gradient-sunset":{hsl:"15 95% 60%",darkHsl:"15 95% 65%",gradient:"linear-gradient(135deg, hsl(25 95% 53%) 0%, hsl(330 81% 60%) 100%)"},"gradient-ocean":{hsl:"200 90% 55%",darkHsl:"200 90% 60%",gradient:"linear-gradient(135deg, hsl(221.2 83.2% 53.3%) 0%, hsl(189 94% 43%) 100%)"},"gradient-forest":{hsl:"150 70% 45%",darkHsl:"150 75% 40%",gradient:"linear-gradient(135deg, hsl(142 71% 45%) 0%, hsl(158 64% 52%) 100%)"},"gradient-aurora":{hsl:"310 85% 65%",darkHsl:"310 90% 70%",gradient:"linear-gradient(135deg, hsl(271 91% 65%) 0%, hsl(330 81% 60%) 100%)"},"gradient-fire":{hsl:"15 95% 55%",darkHsl:"15 95% 60%",gradient:"linear-gradient(135deg, hsl(0 84% 60%) 0%, hsl(25 95% 53%) 100%)"},"gradient-twilight":{hsl:"250 90% 60%",darkHsl:"250 95% 65%",gradient:"linear-gradient(135deg, hsl(239 84% 67%) 0%, hsl(271 91% 65%) 100%)"}}[f];N&&(p.style.setProperty("--primary",N.hsl),N.gradient?(p.style.setProperty("--primary-gradient",N.gradient),p.classList.add("has-gradient")):(p.style.removeProperty("--primary-gradient"),p.classList.remove("has-gradient")))}},[]);const h={theme:d,setTheme:f=>{localStorage.setItem(r,f),u(f)}};return e.jsx(Ov.Provider,{...c,value:h,children:a})}function BT({children:a,defaultEnabled:n=!0,defaultWavesEnabled:r=!0,storageKey:c="enable-animations",wavesStorageKey:d="enable-waves-background"}){const[u,h]=m.useState(()=>{const N=localStorage.getItem(c);return N!==null?N==="true":n}),[f,p]=m.useState(()=>{const N=localStorage.getItem(d);return N!==null?N==="true":r});m.useEffect(()=>{const N=document.documentElement;u?N.classList.remove("no-animations"):N.classList.add("no-animations"),localStorage.setItem(c,String(u))},[u,c]),m.useEffect(()=>{localStorage.setItem(d,String(f))},[f,d]);const g={enableAnimations:u,setEnableAnimations:h,enableWavesBackground:f,setEnableWavesBackground:p};return e.jsx(Lv.Provider,{value:g,children:a})}const PT=j_,Db=m.forwardRef(({className:a,...n},r)=>e.jsx(Kj,{ref:r,className:I("fixed bottom-0 right-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:max-w-[420px] gap-2",a),...n}));Db.displayName=Kj.displayName;const IT=Wr("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"}}),Ob=m.forwardRef(({className:a,variant:n,...r},c)=>e.jsx(Qj,{ref:c,className:I(IT({variant:n}),a),...r}));Ob.displayName=Qj.displayName;const FT=m.forwardRef(({className:a,...n},r)=>e.jsx(Yj,{ref:r,className:I("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",a),...n}));FT.displayName=Yj.displayName;const Lb=m.forwardRef(({className:a,...n},r)=>e.jsx(Jj,{ref:r,className:I("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",a),"toast-close":"",...n,children:e.jsx(Aa,{className:"h-4 w-4"})}));Lb.displayName=Jj.displayName;const Ub=m.forwardRef(({className:a,...n},r)=>e.jsx(Xj,{ref:r,className:I("text-sm font-semibold [&+div]:text-xs",a),...n}));Ub.displayName=Xj.displayName;const $b=m.forwardRef(({className:a,...n},r)=>e.jsx(Zj,{ref:r,className:I("text-sm opacity-90",a),...n}));$b.displayName=Zj.displayName;function HT(){const{toasts:a}=Ys();return e.jsxs(PT,{children:[a.map(function({id:n,title:r,description:c,action:d,...u}){return e.jsxs(Ob,{...u,children:[e.jsxs("div",{className:"grid gap-1",children:[r&&e.jsx(Ub,{children:r}),c&&e.jsx($b,{children:c})]}),d,e.jsx(Lb,{})]},n)}),e.jsx(Db,{})]})}A1.createRoot(document.getElementById("root")).render(e.jsx(m.StrictMode,{children:e.jsx(cT,{children:e.jsx($T,{defaultTheme:"system",children:e.jsx(BT,{children:e.jsxs(ES,{children:[e.jsx(sw,{router:UT}),e.jsx(zS,{}),e.jsx(HT,{})]})})})})})); diff --git a/webui/dist/index.html b/webui/dist/index.html index 600539d5..de750869 100644 --- a/webui/dist/index.html +++ b/webui/dist/index.html @@ -11,7 +11,7 @@ MaiBot Dashboard - +