diff --git a/webui/dist/assets/index-BUSpK6Uj.js b/webui/dist/assets/index-D0QZyp4g.js similarity index 92% rename from webui/dist/assets/index-BUSpK6Uj.js rename to webui/dist/assets/index-D0QZyp4g.js index b29a7f21..2831b48b 100644 --- a/webui/dist/assets/index-BUSpK6Uj.js +++ b/webui/dist/assets/index-D0QZyp4g.js @@ -73,7 +73,7 @@ ${h}`:x||h}function ZS(l,{maxDepth:n=1e3,numbersAsFloat:i=!1}={}){if(mc(l)!=="ob ${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:O?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-16 h-16 rounded border overflow-hidden bg-muted flex items-center justify-center",children:e.jsx("img",{src:O.previewUrl,alt:O.name,className:"max-w-full max-h-full object-contain"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:O.name}),y(O)&&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:O.emotion,onChange:J=>w(O.id,{emotion:J.target.value}),placeholder:"多个标签用逗号分隔,如:开心,高兴",className:O.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:O.description,onChange:J=>w(O.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:O.isRegistered,onCheckedChange:J=>w(O.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(Xm,{className:"h-12 w-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"点击左侧卡片编辑"})]})})})]}),e.jsx(st,{children:e.jsx(_,{onClick:B,disabled:!R||g,children:g?"上传中...":`上传全部 (${L})`})})]})};return e.jsx(Is,{open:l,onOpenChange:n,children:e.jsxs(Os,{className:"max-w-3xl max-h-[90vh] overflow-hidden",children:[e.jsxs(Ds,{children:[e.jsxs(Rs,{className:"flex items-center gap-2",children:[e.jsx(sc,{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"&&z()]})]})})}function C4(){const[l,n]=d.useState([]),[i,c]=d.useState(!0),[u,x]=d.useState(0),[h,f]=d.useState(1),[p,g]=d.useState(20),[N,v]=d.useState(""),[b,w]=d.useState(null),[y,R]=d.useState(!1),[O,S]=d.useState(!1),[B,E]=d.useState(!1),[C,z]=d.useState(null),[H,L]=d.useState(new Set),[J,U]=d.useState(!1),[oe,Ne]=d.useState(""),[je,re]=d.useState({total:0,recent_7days:0,chat_count:0,top_chats:{}}),[fe,ge]=d.useState([]),[M,K]=d.useState(new Map),[I,ue]=d.useState(!1),[Q,Se]=d.useState(0),{toast:pe}=Zs(),Te=async()=>{try{c(!0);const ie=await y1({page:h,page_size:p,search:N||void 0});n(ie.data),x(ie.total)}catch(ie){pe({title:"加载失败",description:ie instanceof Error?ie.message:"无法加载表达方式",variant:"destructive"})}finally{c(!1)}},A=async()=>{try{const ie=await T1();ie?.data&&re(ie.data)}catch(ie){console.error("加载统计数据失败:",ie)}},D=async()=>{try{const ie=await tx();Se(ie.unchecked)}catch(ie){console.error("加载审核统计失败:",ie)}},V=async()=>{try{const ie=await sx();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;d.useEffect(()=>{Te(),D(),A(),V()},[h,p,N]);const Oe=async ie=>{try{const Ee=await w1(ie.id);w(Ee.data),R(!0)}catch(Ee){pe({title:"加载详情失败",description:Ee instanceof Error?Ee.message:"无法加载表达方式详情",variant:"destructive"})}},W=ie=>{w(ie),S(!0)},Y=async ie=>{try{await k1(ie.id),pe({title:"删除成功",description:`已删除表达方式: ${ie.situation}`}),z(null),Te(),A()}catch(Ee){pe({title:"删除失败",description:Ee instanceof Error?Ee.message:"无法删除表达方式",variant:"destructive"})}},He=ie=>{const Ee=new Set(H);Ee.has(ie)?Ee.delete(ie):Ee.add(ie),L(Ee)},F=()=>{H.size===l.length&&l.length>0?L(new Set):L(new Set(l.map(ie=>ie.id)))},ee=async()=>{try{await C1(Array.from(H)),pe({title:"批量删除成功",description:`已删除 ${H.size} 个表达方式`}),L(new Set),U(!1),Te(),A()}catch(ie){pe({title:"批量删除失败",description:ie instanceof Error?ie.message:"无法批量删除表达方式",variant:"destructive"})}},Ue=()=>{const ie=parseInt(oe),Ee=Math.ceil(u/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(za,{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(Dj,{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:H.size>0&&e.jsxs("span",{children:["已选择 ",H.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),L(new Set)},children:[e.jsx($e,{id:"page-size",className:"w-20",children:e.jsx(Pe,{})}),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"})]})]}),H.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(Rl,{children:[e.jsx(Ll,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:H.size===l.length&&l.length>0,onCheckedChange:F})}),e.jsx(We,{children:"情境"}),e.jsx(We,{children:"风格"}),e.jsx(We,{children:"聊天"}),e.jsx(We,{className:"text-right",children:"操作"})]})}),e.jsx(Ul,{children:i?e.jsx(ut,{children:e.jsx(Ke,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):l.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):l.map(ie=>e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(qs,{checked:H.has(ie.id),onCheckedChange:()=>He(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(Kn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>Oe(ie),title:"查看详情",children:e.jsx(ia,{className:"h-4 w-4"})}),e.jsxs(_,{size:"sm",onClick:()=>z(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:i?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):l.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):l.map(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:H.has(ie.id),onCheckedChange:()=>He(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(Kn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>Oe(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:()=>z(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))}),u>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",u," 条记录,第 ",h," / ",Math.ceil(u/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(gn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Aa,{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(u/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(u/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Zt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(u/p)),disabled:h>=Math.ceil(u/p),className:"hidden sm:flex",children:e.jsx(jn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(T4,{expression:b,open:y,onOpenChange:R,chatNameMap:M}),e.jsx(E4,{open:B,onOpenChange:E,chatList:fe,onSuccess:()=>{Te(),A(),E(!1)}}),e.jsx(M4,{expression:b,open:O,onOpenChange:S,chatList:fe,onSuccess:()=>{Te(),A(),S(!1)}}),e.jsx(Ns,{open:!!C,onOpenChange:()=>z(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(z4,{open:J,onOpenChange:U,onConfirm:ee,count:H.size}),e.jsx(fv,{open:I,onOpenChange:ie=>{ue(ie),ie||(Te(),A(),D())}})]})}function T4({expression:l,open:n,onOpenChange:i,chatNameMap:c}){if(!l)return null;const u=h=>h?new Date(h*1e3).toLocaleString("zh-CN"):"-",x=h=>c.get(h)||h;return e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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(Hi,{label:"情境",value:l.situation}),e.jsx(Hi,{label:"风格",value:l.style}),e.jsx(Hi,{label:"聊天",value:x(l.chat_id)}),e.jsx(Hi,{icon:Vr,label:"记录ID",value:l.id.toString(),mono:!0})]}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsx(Hi,{icon:na,label:"创建时间",value:u(l.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:P("flex h-8 w-8 items-center justify-center rounded-full",l.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:l.checked?e.jsx(pt,{className:"h-5 w-5"}):e.jsx($o,{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:l.checked?"已通过审核":"未审核"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:P("flex h-8 w-8 items-center justify-center rounded-full",l.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:l.rejected?e.jsx(Va,{className:"h-5 w-5"}):e.jsx($o,{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:l.rejected?"不会被使用":"正常"})]})]})]})]})]}),e.jsx(st,{children:e.jsx(_,{onClick:()=>i(!1),children:"关闭"})})]})})}function Hi({icon:l,label:n,value:i,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:[l&&e.jsx(l,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:P("text-sm",c&&"font-mono",!i&&"text-muted-foreground"),children:i||"-"})]})}function E4({open:l,onOpenChange:n,chatList:i,onSuccess:c}){const[u,x]=d.useState({situation:"",style:"",chat_id:""}),[h,f]=d.useState(!1),{toast:p}=Zs(),g=async()=>{if(!u.situation||!u.style||!u.chat_id){p({title:"验证失败",description:"请填写必填字段:情境、风格和聊天",variant:"destructive"});return}try{f(!0),await _1(u),p({title:"创建成功",description:"表达方式已创建"}),x({situation:"",style:"",chat_id:""}),c()}catch(N){p({title:"创建失败",description:N instanceof Error?N.message:"无法创建表达方式",variant:"destructive"})}finally{f(!1)}};return e.jsx(Is,{open:l,onOpenChange:n,children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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:u.situation,onChange:N=>x({...u,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:u.style,onChange:N=>x({...u,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:u.chat_id,onValueChange:N=>x({...u,chat_id:N}),children:[e.jsx($e,{children:e.jsx(Pe,{placeholder:"选择关联的聊天"})}),e.jsx(Be,{children:i.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 M4({expression:l,open:n,onOpenChange:i,chatList:c,onSuccess:u}){const[x,h]=d.useState({}),[f,p]=d.useState(!1),{toast:g}=Zs();d.useEffect(()=>{l&&h({situation:l.situation,style:l.style,chat_id:l.chat_id,checked:l.checked,rejected:l.rejected})},[l]);const N=async()=>{if(l)try{p(!0),await S1(l.id,x),g({title:"保存成功",description:"表达方式已更新"}),u()}catch(v){g({title:"保存失败",description:v instanceof Error?v.message:"无法更新表达方式",variant:"destructive"})}finally{p(!1)}};return l?e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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:x.situation||"",onChange:v=>h({...x,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:x.style||"",onChange:v=>h({...x,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:x.chat_id||"",onValueChange:v=>h({...x,chat_id:v}),children:[e.jsx($e,{children:e.jsx(Pe,{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(Ht,{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(Ge,{id:"edit_checked",checked:x.checked??!1,onCheckedChange:v=>h({...x,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(Ge,{id:"edit_rejected",checked:x.rejected??!1,onCheckedChange:v=>h({...x,rejected:v})})]})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(_,{onClick:N,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}function z4({open:l,onOpenChange:n,onConfirm:i,count:c}){return e.jsx(Ns,{open:l,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:i,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认删除"})]})]})})}const $l="/api/webui/jargon";async function A4(){const l=await _e(`${$l}/chats`,{});if(!l.ok){const n=await l.json();throw new Error(n.detail||"获取聊天列表失败")}return l.json()}async function O4(l){const n=new URLSearchParams;l.page&&n.append("page",l.page.toString()),l.page_size&&n.append("page_size",l.page_size.toString()),l.search&&n.append("search",l.search),l.chat_id&&n.append("chat_id",l.chat_id),l.is_jargon!==void 0&&l.is_jargon!==null&&n.append("is_jargon",l.is_jargon.toString()),l.is_global!==void 0&&n.append("is_global",l.is_global.toString());const i=await _e(`${$l}/list?${n}`,{});if(!i.ok){const c=await i.json();throw new Error(c.detail||"获取黑话列表失败")}return i.json()}async function D4(l){const n=await _e(`${$l}/${l}`,{});if(!n.ok){const i=await n.json();throw new Error(i.detail||"获取黑话详情失败")}return n.json()}async function R4(l){const n=await _e(`${$l}/`,{method:"POST",body:JSON.stringify(l)});if(!n.ok){const i=await n.json();throw new Error(i.detail||"创建黑话失败")}return n.json()}async function L4(l,n){const i=await _e(`${$l}/${l}`,{method:"PATCH",body:JSON.stringify(n)});if(!i.ok){const c=await i.json();throw new Error(c.detail||"更新黑话失败")}return i.json()}async function U4(l){const n=await _e(`${$l}/${l}`,{method:"DELETE"});if(!n.ok){const i=await n.json();throw new Error(i.detail||"删除黑话失败")}return n.json()}async function $4(l){const n=await _e(`${$l}/batch/delete`,{method:"POST",body:JSON.stringify({ids:l})});if(!n.ok){const i=await n.json();throw new Error(i.detail||"批量删除黑话失败")}return n.json()}async function B4(){const l=await _e(`${$l}/stats/summary`,{});if(!l.ok){const n=await l.json();throw new Error(n.detail||"获取黑话统计失败")}return l.json()}async function I4(l,n){const i=new URLSearchParams;l.forEach(u=>i.append("ids",u.toString())),i.append("is_jargon",n.toString());const c=await _e(`${$l}/batch/set-jargon?${i}`,{method:"POST"});if(!c.ok){const u=await c.json();throw new Error(u.detail||"批量设置黑话状态失败")}return c.json()}function P4(){const[l,n]=d.useState([]),[i,c]=d.useState(!0),[u,x]=d.useState(0),[h,f]=d.useState(1),[p,g]=d.useState(20),[N,v]=d.useState(""),[b,w]=d.useState("all"),[y,R]=d.useState("all"),[O,S]=d.useState(null),[B,E]=d.useState(!1),[C,z]=d.useState(!1),[H,L]=d.useState(!1),[J,U]=d.useState(null),[oe,Ne]=d.useState(new Set),[je,re]=d.useState(!1),[fe,ge]=d.useState(""),[M,K]=d.useState({total:0,confirmed_jargon:0,confirmed_not_jargon:0,pending:0,global_count:0,complete_count:0,chat_count:0,top_chats:{}}),[I,ue]=d.useState([]),{toast:Q}=Zs(),Se=async()=>{try{c(!0);const ee=await O4({page:h,page_size:p,search:N||void 0,chat_id:b==="all"?void 0:b,is_jargon:y==="all"?void 0:y==="true"?!0:y==="false"?!1:void 0});n(ee.data),x(ee.total)}catch(ee){Q({title:"加载失败",description:ee instanceof Error?ee.message:"无法加载黑话列表",variant:"destructive"})}finally{c(!1)}},pe=async()=>{try{const ee=await B4();ee?.data&&K(ee.data)}catch(ee){console.error("加载统计数据失败:",ee)}},Te=async()=>{try{const ee=await A4();ee?.data&&ue(ee.data)}catch(ee){console.error("加载聊天列表失败:",ee)}};d.useEffect(()=>{Se(),pe(),Te()},[h,p,N,b,y]);const A=async ee=>{try{const Ue=await D4(ee.id);S(Ue.data),E(!0)}catch(Ue){Q({title:"加载详情失败",description:Ue instanceof Error?Ue.message:"无法加载黑话详情",variant:"destructive"})}},D=ee=>{S(ee),z(!0)},V=async ee=>{try{await U4(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)},Oe=()=>{oe.size===l.length&&l.length>0?Ne(new Set):Ne(new Set(l.map(ee=>ee.id)))},W=async()=>{try{await $4(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 I4(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"})}},He=()=>{const ee=parseInt(fe),Ue=Math.ceil(u/p);ee>=1&&ee<=Ue?(f(ee),ge("")):Q({title:"无效的页码",description:`请输入1-${Ue}之间的页码`,variant:"destructive"})},F=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(Ea,{className:"h-3 w-3 mr-1"}),"非黑话"]}):e.jsxs(ke,{variant:"outline",children:[e.jsx(Lj,{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(n_,{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(Ie,{value:b,onValueChange:w,children:[e.jsx($e,{children:e.jsx(Pe,{placeholder:"全部聊天"})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部聊天"}),I.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(Ie,{value:y,onValueChange:R,children:[e.jsx($e,{children:e.jsx(Pe,{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(Ie,{value:p.toString(),onValueChange:ee=>{g(parseInt(ee)),f(1),Ne(new Set)},children:[e.jsx($e,{id:"page-size",children:e.jsx(Pe,{})}),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(Ea,{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(Rl,{children:[e.jsx(Ll,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:oe.size===l.length&&l.length>0,onCheckedChange:Oe})}),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(Ul,{children:i?e.jsx(ut,{children:e.jsx(Ke,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):l.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):l.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(Bo,{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:F(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(Kn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>A(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:i?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):l.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):l.map(ee=>e.jsxs("div",{className:"rounded-lg border bg-card p-4 space-y-3",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(Bo,{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:[F(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(Kn,{className:"h-3 w-3 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>A(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))}),u>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",u," 条记录,第 ",h," / ",Math.ceil(u/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(gn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Aa,{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"&&He(),placeholder:h.toString(),className:"w-16 h-8 text-center",min:1,max:Math.ceil(u/p)}),e.jsx(_,{variant:"outline",size:"sm",onClick:He,disabled:!fe,className:"h-8",children:"跳转"})]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h+1),disabled:h>=Math.ceil(u/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Zt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(u/p)),disabled:h>=Math.ceil(u/p),className:"hidden sm:flex",children:e.jsx(jn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(H4,{jargon:O,open:B,onOpenChange:E}),e.jsx(F4,{open:H,onOpenChange:L,chatList:I,onSuccess:()=>{Se(),pe(),L(!1)}}),e.jsx(G4,{jargon:O,open:C,onOpenChange:z,chatList:I,onSuccess:()=>{Se(),pe(),z(!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&&V(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 H4({jargon:l,open:n,onOpenChange:i}){return l?e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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(Rm,{icon:Vr,label:"记录ID",value:l.id.toString(),mono:!0}),e.jsx(Rm,{label:"使用次数",value:l.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:l.content})]}),l.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(l.raw_content);return Array.isArray(c)?c.map((u,x)=>e.jsxs("div",{children:[x>0&&e.jsx("hr",{className:"my-3 border-border"}),e.jsx("div",{className:"whitespace-pre-wrap",children:u})]},x)):e.jsx("div",{className:"whitespace-pre-wrap",children:l.raw_content})}catch{return e.jsx("div",{className:"whitespace-pre-wrap",children:l.raw_content})}})()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"含义"}),e.jsx("div",{className:"text-sm p-2 bg-muted rounded break-all",children:l.meaning?e.jsx(nx,{content:l.meaning}):"-"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Rm,{label:"聊天",value:l.chat_name||l.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:[l.is_jargon===!0&&e.jsx(ke,{variant:"default",className:"bg-green-600",children:"是黑话"}),l.is_jargon===!1&&e.jsx(ke,{variant:"secondary",children:"非黑话"}),l.is_jargon===null&&e.jsx(ke,{variant:"outline",children:"未判定"}),l.is_global&&e.jsx(ke,{variant:"outline",className:"border-blue-500 text-blue-500",children:"全局"}),l.is_complete&&e.jsx(ke,{variant:"outline",className:"border-purple-500 text-purple-500",children:"推断完成"})]})]})]}),l.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:l.inference_with_context})]}),l.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:l.inference_content_only})]})]})}),e.jsx(st,{className:"flex-shrink-0",children:e.jsx(_,{onClick:()=>i(!1),children:"关闭"})})]})}):null}function Rm({icon:l,label:n,value:i,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:[l&&e.jsx(l,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:P("text-sm",c&&"font-mono",!i&&"text-muted-foreground"),children:i||"-"})]})}function F4({open:l,onOpenChange:n,chatList:i,onSuccess:c}){const[u,x]=d.useState({content:"",meaning:"",chat_id:"",is_global:!1}),[h,f]=d.useState(!1),{toast:p}=Zs(),g=async()=>{if(!u.content||!u.chat_id){p({title:"验证失败",description:"请填写必填字段:内容和聊天",variant:"destructive"});return}try{f(!0),await R4(u),p({title:"创建成功",description:"黑话已创建"}),x({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(Is,{open:l,onOpenChange:n,children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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:u.content,onChange:N=>x({...u,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:u.meaning||"",onChange:N=>x({...u,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:u.chat_id,onValueChange:N=>x({...u,chat_id:N}),children:[e.jsx($e,{children:e.jsx(Pe,{placeholder:"选择关联的聊天"})}),e.jsx(Be,{children:i.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(Ge,{id:"is_global",checked:u.is_global,onCheckedChange:N=>x({...u,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 G4({jargon:l,open:n,onOpenChange:i,chatList:c,onSuccess:u}){const[x,h]=d.useState({}),[f,p]=d.useState(!1),{toast:g}=Zs();d.useEffect(()=>{l&&h({content:l.content,meaning:l.meaning||"",chat_id:l.stream_id||l.chat_id,is_global:l.is_global,is_jargon:l.is_jargon})},[l]);const N=async()=>{if(l)try{p(!0),await L4(l.id,x),g({title:"保存成功",description:"黑话已更新"}),u()}catch(v){g({title:"保存失败",description:v instanceof Error?v.message:"无法更新黑话",variant:"destructive"})}finally{p(!1)}};return l?e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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:x.content||"",onChange:v=>h({...x,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:x.meaning||"",onChange:v=>h({...x,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:x.chat_id||"",onValueChange:v=>h({...x,chat_id:v}),children:[e.jsx($e,{children:e.jsx(Pe,{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(Ie,{value:x.is_jargon===null?"null":x.is_jargon?.toString()||"null",onValueChange:v=>h({...x,is_jargon:v==="null"?null:v==="true"}),children:[e.jsx($e,{children:e.jsx(Pe,{})}),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(Ge,{id:"edit_is_global",checked:x.is_global,onCheckedChange:v=>h({...x,is_global:v})}),e.jsx(T,{htmlFor:"edit_is_global",children:"全局黑话"})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(_,{onClick:N,disabled:f,children:f?"保存中...":"保存"})]})]})}):null}const Jr="/api/webui/person";async function V4(l){const n=new URLSearchParams;l.page&&n.append("page",l.page.toString()),l.page_size&&n.append("page_size",l.page_size.toString()),l.search&&n.append("search",l.search),l.is_known!==void 0&&n.append("is_known",l.is_known.toString()),l.platform&&n.append("platform",l.platform);const i=await _e(`${Jr}/list?${n}`,{headers:Fs()});if(!i.ok){const c=await i.json();throw new Error(c.detail||"获取人物列表失败")}return i.json()}async function q4(l){const n=await _e(`${Jr}/${l}`,{headers:Fs()});if(!n.ok){const i=await n.json();throw new Error(i.detail||"获取人物详情失败")}return n.json()}async function K4(l,n){const i=await _e(`${Jr}/${l}`,{method:"PATCH",headers:Fs(),body:JSON.stringify(n)});if(!i.ok){const c=await i.json();throw new Error(c.detail||"更新人物信息失败")}return i.json()}async function Q4(l){const n=await _e(`${Jr}/${l}`,{method:"DELETE",headers:Fs()});if(!n.ok){const i=await n.json();throw new Error(i.detail||"删除人物信息失败")}return n.json()}async function Y4(){const l=await _e(`${Jr}/stats/summary`,{headers:Fs()});if(!l.ok){const n=await l.json();throw new Error(n.detail||"获取统计数据失败")}return l.json()}async function J4(l){const n=await _e(`${Jr}/batch/delete`,{method:"POST",headers:Fs(),body:JSON.stringify({person_ids:l})});if(!n.ok){const i=await n.json();throw new Error(i.detail||"批量删除失败")}return n.json()}function X4(){const[l,n]=d.useState([]),[i,c]=d.useState(!0),[u,x]=d.useState(0),[h,f]=d.useState(1),[p,g]=d.useState(20),[N,v]=d.useState(""),[b,w]=d.useState(void 0),[y,R]=d.useState(void 0),[O,S]=d.useState(null),[B,E]=d.useState(!1),[C,z]=d.useState(!1),[H,L]=d.useState(null),[J,U]=d.useState({total:0,known:0,unknown:0,platforms:{}}),[oe,Ne]=d.useState(new Set),[je,re]=d.useState(!1),[fe,ge]=d.useState(""),{toast:M}=Zs(),K=async()=>{try{c(!0);const W=await V4({page:h,page_size:p,search:N||void 0,is_known:b,platform:y});n(W.data),x(W.total)}catch(W){M({title:"加载失败",description:W instanceof Error?W.message:"无法加载人物信息",variant:"destructive"})}finally{c(!1)}},I=async()=>{try{const W=await Y4();W?.data&&U(W.data)}catch(W){console.error("加载统计数据失败:",W)}};d.useEffect(()=>{K(),I()},[h,p,N,b,y]);const ue=async W=>{try{const Y=await q4(W.person_id);S(Y.data),E(!0)}catch(Y){M({title:"加载详情失败",description:Y instanceof Error?Y.message:"无法加载人物详情",variant:"destructive"})}},Q=W=>{S(W),z(!0)},Se=async W=>{try{await Q4(W.person_id),M({title:"删除成功",description:`已删除人物信息: ${W.person_name||W.nickname||W.user_id}`}),L(null),K(),I()}catch(Y){M({title:"删除失败",description:Y instanceof Error?Y.message:"无法删除人物信息",variant:"destructive"})}},pe=d.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)},A=()=>{oe.size===l.length&&l.length>0?Ne(new Set):Ne(new Set(l.map(W=>W.person_id)))},D=()=>{if(oe.size===0){M({title:"未选择任何人物",description:"请先选择要删除的人物",variant:"destructive"});return}re(!0)},V=async()=>{try{const W=await J4(Array.from(oe));M({title:"批量删除完成",description:W.message}),Ne(new Set),re(!1),K(),I()}catch(W){M({title:"批量删除失败",description:W instanceof Error?W.message:"批量删除失败",variant:"destructive"})}},de=()=>{const W=parseInt(fe),Y=Math.ceil(u/p);W>=1&&W<=Y?(f(W),ge("")):M({title:"无效的页码",description:`请输入1-${Y}之间的页码`,variant:"destructive"})},Oe=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(tc,{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(Ie,{value:b===void 0?"all":b.toString(),onValueChange:W=>{w(W==="all"?void 0:W==="true"),f(1)},children:[e.jsx($e,{id:"filter-known",className:"mt-1.5",children:e.jsx(Pe,{})}),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(Ie,{value:y||"all",onValueChange:W=>{R(W==="all"?void 0:W),f(1)},children:[e.jsx($e,{id:"filter-platform",className:"mt-1.5",children:e.jsx(Pe,{})}),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(Ie,{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(Pe,{})}),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(Rl,{children:[e.jsx(Ll,{children:e.jsxs(ut,{children:[e.jsx(We,{className:"w-12",children:e.jsx(qs,{checked:l.length>0&&oe.size===l.length,onCheckedChange:A,"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(Ul,{children:i?e.jsx(ut,{children:e.jsx(Ke,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"加载中..."})}):l.length===0?e.jsx(ut,{children:e.jsx(Ke,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"暂无数据"})}):l.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:P("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:Oe(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(Kn,{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:i?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):l.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无数据"}):l.map(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:P("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:Oe(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(Kn,{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))}),u>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["共 ",u," 条记录,第 ",h," / ",Math.ceil(u/p)," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(1),disabled:h===1,className:"hidden sm:flex",children:e.jsx(gn,{className:"h-4 w-4"})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(h-1),disabled:h===1,children:[e.jsx(Aa,{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(u/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(u/p),children:[e.jsx("span",{className:"hidden sm:inline",children:"下一页"}),e.jsx(Zt,{className:"h-4 w-4 sm:ml-1"})]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>f(Math.ceil(u/p)),disabled:h>=Math.ceil(u/p),className:"hidden sm:flex",children:e.jsx(jn,{className:"h-4 w-4"})})]})]})]})]})}),e.jsx(Z4,{person:O,open:B,onOpenChange:E}),e.jsx(W4,{person:O,open:C,onOpenChange:z,onSuccess:()=>{K(),I(),z(!1)}}),e.jsx(Ns,{open:!!H,onOpenChange:()=>L(null),children:e.jsxs(us,{children:[e.jsxs(ms,{children:[e.jsx(hs,{children:"确认删除"}),e.jsxs(fs,{children:['确定要删除人物信息 "',H?.person_name||H?.nickname||H?.user_id,'" 吗? 此操作不可撤销。']})]}),e.jsxs(xs,{children:[e.jsx(gs,{children:"取消"}),e.jsx(ps,{onClick:()=>H&&Se(H),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:V,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"批量删除"})]})]})})]})}function Z4({person:l,open:n,onOpenChange:i}){if(!l)return null;const c=u=>u?new Date(u*1e3).toLocaleString("zh-CN"):"-";return e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{children:"人物详情"}),e.jsxs(Ks,{children:["查看 ",l.person_name||l.nickname||l.user_id," 的完整信息"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(zl,{icon:fn,label:"人物名称",value:l.person_name}),e.jsx(zl,{icon:za,label:"昵称",value:l.nickname}),e.jsx(zl,{icon:Vr,label:"用户ID",value:l.user_id,mono:!0}),e.jsx(zl,{icon:Vr,label:"人物ID",value:l.person_id,mono:!0}),e.jsx(zl,{label:"平台",value:l.platform}),e.jsx(zl,{label:"状态",value:l.is_known?"已认识":"未认识"})]}),l.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:l.name_reason})]}),l.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:l.memory_points})]}),l.group_nick_name&&l.group_nick_name.length>0&&e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"群昵称"}),e.jsx("div",{className:"mt-2 space-y-1",children:l.group_nick_name.map((u,x)=>e.jsxs("div",{className:"text-sm flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:u.group_id}),e.jsx("span",{children:"→"}),e.jsx("span",{children:u.group_nick_name})]},x))})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(zl,{icon:na,label:"认识时间",value:c(l.know_times)}),e.jsx(zl,{icon:na,label:"首次记录",value:c(l.know_since)}),e.jsx(zl,{icon:na,label:"最后更新",value:c(l.last_know)})]})]}),e.jsx(st,{children:e.jsx(_,{onClick:()=>i(!1),children:"关闭"})})]})})}function zl({icon:l,label:n,value:i,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:[l&&e.jsx(l,{className:"h-3 w-3"}),n]}),e.jsx("div",{className:P("text-sm",c&&"font-mono",!i&&"text-muted-foreground"),children:i||"-"})]})}function W4({person:l,open:n,onOpenChange:i,onSuccess:c}){const[u,x]=d.useState({}),[h,f]=d.useState(!1),{toast:p}=Zs();d.useEffect(()=>{l&&x({person_name:l.person_name||"",name_reason:l.name_reason||"",nickname:l.nickname||"",is_known:l.is_known})},[l]);const g=async()=>{if(l)try{f(!0),await K4(l.person_id,u),p({title:"保存成功",description:"人物信息已更新"}),c()}catch(N){p({title:"保存失败",description:N instanceof Error?N.message:"无法更新人物信息",variant:"destructive"})}finally{f(!1)}};return l?e.jsx(Is,{open:n,onOpenChange:i,children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{children:"编辑人物信息"}),e.jsxs(Ks,{children:["修改 ",l.person_name||l.nickname||l.user_id," 的信息"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"person_name",children:"人物名称"}),e.jsx(ae,{id:"person_name",value:u.person_name||"",onChange:N=>x({...u,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:u.nickname||"",onChange:N=>x({...u,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:u.name_reason||"",onChange:N=>x({...u,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(Ge,{id:"is_known",checked:u.is_known,onCheckedChange:N=>x({...u,is_known:N})})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>i(!1),children:"取消"}),e.jsx(_,{onClick:g,disabled:h,children:h?"保存中...":"保存"})]})]})}):null}var ek=G_();const Ug=M0(ek),mx="/api/webui";async function sk(l=100,n="all"){const i=`${mx}/knowledge/graph?limit=${l}&node_type=${n}`,c=await fetch(i);if(!c.ok)throw new Error(`获取知识图谱失败: ${c.status}`);return c.json()}async function tk(){const l=await fetch(`${mx}/knowledge/stats`);if(!l.ok)throw new Error("获取知识图谱统计信息失败");return l.json()}async function ak(l){const n=await fetch(`${mx}/knowledge/search?query=${encodeURIComponent(l)}`);if(!n.ok)throw new Error("搜索知识节点失败");return n.json()}const Lv=d.memo(({data:l})=>e.jsxs("div",{className:"px-4 py-2 shadow-md rounded-lg bg-gradient-to-br from-blue-500 to-blue-600 border-2 border-blue-700 min-w-[120px]",children:[e.jsx(Ho,{type:"target",position:Fo.Top}),e.jsx("div",{className:"font-semibold text-white text-sm truncate max-w-[200px]",title:l.content,children:l.label}),e.jsx(Ho,{type:"source",position:Fo.Bottom})]}));Lv.displayName="EntityNode";const Uv=d.memo(({data:l})=>e.jsxs("div",{className:"px-3 py-2 shadow-md rounded-md bg-gradient-to-br from-green-500 to-green-600 border-2 border-green-700 min-w-[100px]",children:[e.jsx(Ho,{type:"target",position:Fo.Top}),e.jsx("div",{className:"font-medium text-white text-xs truncate max-w-[150px]",title:l.content,children:l.label}),e.jsx(Ho,{type:"source",position:Fo.Bottom})]}));Uv.displayName="ParagraphNode";const lk={entity:Lv,paragraph:Uv};function nk(l,n){const i=new Ug.graphlib.Graph;i.setDefaultEdgeLabel(()=>({})),i.setGraph({rankdir:"TB",ranksep:100,nodesep:80});const c=[],u=[];return l.forEach(x=>{i.setNode(x.id,{width:150,height:50})}),n.forEach(x=>{i.setEdge(x.source,x.target)}),Ug.layout(i),l.forEach(x=>{const h=i.node(x.id);c.push({id:x.id,type:x.type,position:{x:h.x-75,y:h.y-25},data:{label:x.content.slice(0,20)+(x.content.length>20?"...":""),content:x.content}})}),n.forEach((x,h)=>{const f={id:`edge-${h}`,source:x.source,target:x.target,animated:l.length<=200&&x.weight>5,style:{strokeWidth:Math.min(x.weight/2,5),opacity:.6}};x.weight>10&&l.length<100&&(f.label=`${x.weight.toFixed(0)}`),u.push(f)}),{nodes:c,edges:u}}function rk(){const l=ca(),[n,i]=d.useState(!1),[c,u]=d.useState(null),[x,h]=d.useState(""),[f,p]=d.useState("all"),[g,N]=d.useState(50),[v,b]=d.useState("50"),[w,y]=d.useState(!1),[R,O]=d.useState(!0),[S,B]=d.useState(!1),[E,C]=d.useState(!1),[z,H,L]=V_([]),[J,U,oe]=q_([]),[Ne,je]=d.useState(0),[re,fe]=d.useState(null),[ge,M]=d.useState(null),{toast:K}=Zs(),I=d.useCallback(V=>V.type==="entity"?"#6366f1":V.type==="paragraph"?"#10b981":"#6b7280",[]),ue=d.useCallback(async(V=!1)=>{try{if(!V&&g>200){C(!0);return}i(!0);const[de,Oe]=await Promise.all([sk(g,f),tk()]);if(u(Oe),de.nodes.length===0){K({title:"提示",description:"知识库为空,请先导入知识数据"}),H([]),U([]);return}const{nodes:W,edges:Y}=nk(de.nodes,de.edges);H(W),U(Y),je(W.length),Oe&&Oe.total_nodes>g&&K({title:"提示",description:`知识图谱包含 ${Oe.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{i(!1)}},[g,f,K]),Q=d.useCallback(async()=>{if(!x.trim()){K({title:"提示",description:"请输入搜索关键词"});return}try{const V=await ak(x);if(V.length===0){K({title:"未找到",description:"没有找到匹配的节点"});return}const de=new Set(V.map(Oe=>Oe.id));H(Oe=>Oe.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:`找到 ${V.length} 个匹配节点`})}catch(V){console.error("搜索失败:",V),K({title:"搜索失败",description:V instanceof Error?V.message:"未知错误",variant:"destructive"})}},[x,K]),Se=d.useCallback(()=>{H(V=>V.map(de=>({...de,style:{...de.style,opacity:1,filter:"brightness(1)"}})))},[]),pe=d.useCallback(()=>{O(!1),B(!0),ue()},[ue]),Te=d.useCallback(()=>{C(!1),setTimeout(()=>{ue(!0)},0)},[ue]),A=d.useCallback((V,de)=>{z.find(W=>W.id===de.id)&&fe({id:de.id,type:de.type,content:de.data.content})},[z]);d.useEffect(()=>{R||S&&ue()},[g,f,R,S]);const D=d.useCallback((V,de)=>{const Oe=z.find(He=>He.id===de.source),W=z.find(He=>He.id===de.target),Y=J.find(He=>He.id===de.id);Oe&&W&&Y&&M({source:{id:Oe.id,type:Oe.type,content:Oe.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")}})},[z,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(Gr,{className:"h-3 w-3"}),"节点: ",c.total_nodes]}),e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(Pj,{className:"h-3 w-3"}),"边: ",c.total_edges]}),e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(Ht,{className:"h-3 w-3"}),"实体: ",c.entity_nodes]}),e.jsxs(ke,{variant:"outline",className:"gap-1",children:[e.jsx(Ca,{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:x,onChange:V=>h(V.target.value),onKeyDown:V=>V.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(Ie,{value:f,onValueChange:V=>p(V),children:[e.jsx($e,{className:"w-[120px]",children:e.jsx(Pe,{})}),e.jsxs(Be,{children:[e.jsx(Z,{value:"all",children:"全部节点"}),e.jsx(Z,{value:"entity",children:"仅实体"}),e.jsx(Z,{value:"paragraph",children:"仅段落"})]})]}),e.jsxs(Ie,{value:g===1e4?"all":w?"custom":g.toString(),onValueChange:V=>{V==="custom"?(y(!0),b(g.toString())):V==="all"?(y(!1),N(1e4)):(y(!1),N(Number(V)))},children:[e.jsx($e,{className:"w-[120px]",children:e.jsx(Pe,{})}),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:"自定义..."})]})]}),w&&e.jsx(ae,{type:"number",min:"50",value:v,onChange:V=>b(V.target.value),onBlur:()=>{const V=parseInt(v);!isNaN(V)&&V>=50?N(V):(b("50"),N(50))},onKeyDown:V=>{if(V.key==="Enter"){const de=parseInt(v);!isNaN(de)&&de>=50?N(de):(b("50"),N(50))}},placeholder:"最少50个",className:"w-[120px]"}),e.jsx(_,{onClick:()=>ue(),variant:"outline",size:"sm",disabled:n,children:e.jsx(dt,{className:P("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:"加载知识图谱中..."})]})}):z.length===0?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Gr,{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(K_,{nodes:z,edges:J,onNodesChange:L,onEdgesChange:oe,onNodeClick:A,onEdgeClick:D,nodeTypes:lk,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(Q_,{variant:Y_.Dots,gap:12,size:1}),e.jsx(J_,{}),Ne<=500&&e.jsx(X_,{nodeColor:I,nodeBorderRadius:8,pannable:!0,zoomable:!0}),e.jsxs(Z_,{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(Is,{open:!!re,onOpenChange:V=>!V&&fe(null),children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(Ds,{children:e.jsx(Rs,{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(Is,{open:!!ge,onOpenChange:V=>!V&&M(null),children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsx(Ds,{children:e.jsx(Rs,{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:R,onOpenChange:O,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:()=>l({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 ik(){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(Gr,{className:"h-10 w-10 text-primary"})}),e.jsx(Re,{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 $g({className:l,classNames:n,showOutsideDays:i=!0,captionLayout:c="label",buttonVariant:u="ghost",formatters:x,components:h,...f}){const p=av();return e.jsx(U_,{showOutsideDays:i,className:P("bg-background group/calendar p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,l),captionLayout:c,formatters:{formatMonthDropdown:g=>g.toLocaleString("default",{month:"short"}),...x},classNames:{root:P("w-fit",p.root),months:P("relative flex flex-col gap-4 md:flex-row",p.months),month:P("flex w-full flex-col gap-4",p.month),nav:P("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",p.nav),button_previous:P(Kr({variant:u}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",p.button_previous),button_next:P(Kr({variant:u}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",p.button_next),month_caption:P("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",p.month_caption),dropdowns:P("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",p.dropdowns),dropdown_root:P("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:P("bg-popover absolute inset-0 opacity-0",p.dropdown),caption_label:P("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:P("flex",p.weekdays),weekday:P("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",p.weekday),week:P("mt-2 flex w-full",p.week),week_number_header:P("w-[--cell-size] select-none",p.week_number_header),week_number:P("text-muted-foreground select-none text-[0.8rem]",p.week_number),day:P("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:P("bg-accent rounded-l-md",p.range_start),range_middle:P("rounded-none",p.range_middle),range_end:P("bg-accent rounded-r-md",p.range_end),today:P("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",p.today),outside:P("text-muted-foreground aria-selected:text-muted-foreground",p.outside),disabled:P("text-muted-foreground opacity-50",p.disabled),hidden:P("invisible",p.hidden),...n},components:{Root:({className:g,rootRef:N,...v})=>e.jsx("div",{"data-slot":"calendar",ref:N,className:P(g),...v}),Chevron:({className:g,orientation:N,...v})=>N==="left"?e.jsx(Aa,{className:P("size-4",g),...v}):N==="right"?e.jsx(Zt,{className:P("size-4",g),...v}):e.jsx(Ma,{className:P("size-4",g),...v}),DayButton:ck,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 ck({className:l,day:n,modifiers:i,...c}){const u=av(),x=d.useRef(null);return d.useEffect(()=>{i.focused&&x.current?.focus()},[i.focused]),e.jsx(_,{ref:x,variant:"ghost",size:"icon","data-day":n.date.toLocaleDateString(),"data-selected-single":i.selected&&!i.range_start&&!i.range_end&&!i.range_middle,"data-range-start":i.range_start,"data-range-end":i.range_end,"data-range-middle":i.range_middle,className:P("data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 flex aspect-square h-auto w-full min-w-[--cell-size] flex-col gap-1 font-normal leading-none data-[range-end=true]:rounded-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] [&>span]:text-xs [&>span]:opacity-70",u.day,l),...c})}const Mo={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 ok(){const[l,n]=d.useState([]),[i,c]=d.useState(""),[u,x]=d.useState("all"),[h,f]=d.useState("all"),[p,g]=d.useState(void 0),[N,v]=d.useState(void 0),[b,w]=d.useState(!0),[y,R]=d.useState(!1),[O,S]=d.useState("xs"),[B,E]=d.useState(4),[C,z]=d.useState(!1),H=d.useRef(null);d.useEffect(()=>{const Q=In.getAllLogs();n(Q);const Se=In.onLog(()=>{n(In.getAllLogs())}),pe=In.onConnectionChange(Te=>{R(Te)});return()=>{Se(),pe()}},[]);const L=d.useMemo(()=>{const Q=new Set(l.map(Se=>Se.module).filter(Se=>Se&&Se.trim()!==""));return Array.from(Q).sort()},[l]),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=()=>{In.clearLogs(),n([])},je=()=>{const Q=ge.map(A=>`${A.timestamp} [${A.level.padEnd(8)}] [${A.module}] ${A.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-${Nm(new Date,"yyyy-MM-dd-HHmmss")}.txt`,Te.click(),URL.revokeObjectURL(pe)},re=()=>{w(!b)},fe=()=>{g(void 0),v(void 0)},ge=d.useMemo(()=>l.filter(Q=>{const Se=i===""||Q.message.toLowerCase().includes(i.toLowerCase())||Q.module.toLowerCase().includes(i.toLowerCase()),pe=u==="all"||Q.level===u,Te=h==="all"||Q.module===h;let A=!0;if(p||N){const D=new Date(Q.timestamp);if(p){const V=new Date(p);V.setHours(0,0,0,0),A=A&&D>=V}if(N){const V=new Date(N);V.setHours(23,59,59,999),A=A&&D<=V}}return Se&&pe&&Te&&A}),[l,i,u,h,p,N]),M=Mo[O].rowHeight+B,K=b0({count:ge.length,getScrollElement:()=>H.current,estimateSize:()=>M,overscan:50}),I=d.useRef(!1),ue=d.useRef(ge.length);return d.useEffect(()=>{const Q=H.current;if(!Q)return;const Se=()=>{if(I.current)return;const{scrollTop:pe,scrollHeight:Te,clientHeight:A}=Q,D=Te-pe-A;D>100&&b?w(!1):D<50&&!b&&w(!0)};return Q.addEventListener("scroll",Se,{passive:!0}),()=>Q.removeEventListener("scroll",Se)},[b]),d.useEffect(()=>{const Q=ge.length>ue.current;ue.current=ge.length,b&&ge.length>0&&Q&&(I.current=!0,K.scrollToIndex(ge.length-1,{align:"end",behavior:"auto"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{I.current=!1})}))},[ge.length,b,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:P("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(rc,{open:C,onOpenChange:z,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:i,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:b?"default":"outline",size:"sm",onClick:re,className:"h-8 px-2",title:b?"自动滚动":"已暂停",children:[b?e.jsx(r_,{className:"h-3.5 w-3.5"}):e.jsx(i_,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden sm:inline",children:b?"滚动":"暂停"})]}),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(sa,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden lg:inline",children:"导出"})]}),e.jsx(ic,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"h-8 px-2",title:C?"收起筛选":"展开筛选",children:[e.jsx(Do,{className:"h-3.5 w-3.5"}),C?e.jsx(Fr,{className:"h-3.5 w-3.5 ml-1"}):e.jsx(Ma,{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," / ",l.length]}),e.jsx("span",{className:"ml-1",children:"条日志"})]}),e.jsxs(cc,{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:u,onValueChange:x,children:[e.jsxs($e,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(Do,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Pe,{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(Ie,{value:h,onValueChange:f,children:[e.jsxs($e,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(Do,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Pe,{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(ol,{children:[e.jsx(dl,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:P("w-full sm:flex-1 justify-start text-left font-normal h-8",!p&&"text-muted-foreground"),children:[e.jsx(Io,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:p?Nm(p,"PP",{locale:To}):"开始日期"})]})}),e.jsx(Wa,{className:"w-auto p-0",align:"start",children:e.jsx($g,{mode:"single",selected:p,onSelect:g,initialFocus:!0,locale:To})})]}),e.jsxs(ol,{children:[e.jsx(dl,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:P("w-full sm:flex-1 justify-start text-left font-normal h-8",!N&&"text-muted-foreground"),children:[e.jsx(Io,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:N?Nm(N,"PP",{locale:To}):"结束日期"})]})}),e.jsx(Wa,{className:"w-auto p-0",align:"start",children:e.jsx($g,{mode:"single",selected:N,onSelect:v,initialFocus:!0,locale:To})})]}),(p||N)&&e.jsxs(_,{variant:"outline",size:"sm",onClick:fe,className:"w-full sm:w-auto h-8",children:[e.jsx(Ea,{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(c_,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"字号"})]}),e.jsx("div",{className:"flex gap-1",children:Object.keys(Mo).map(Q=>e.jsx(_,{variant:O===Q?"default":"outline",size:"sm",onClick:()=>S(Q),className:"h-6 px-2 text-xs",children:Mo[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(sa,{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:H,className:P("h-full overflow-auto","[&::-webkit-scrollbar]:w-2.5","[&::-webkit-scrollbar-track]:bg-transparent","[&::-webkit-scrollbar-thumb]:bg-border [&::-webkit-scrollbar-thumb]:rounded-full","[&::-webkit-scrollbar-thumb:hover]:bg-border/80"),children:e.jsx("div",{className:P("p-2 sm:p-3 font-mono relative",Mo[O].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:P("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:P("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:P("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 dk(){return(await _e("/api/planner/overview")).json()}async function uk(l,n=1,i=20,c){const u=new URLSearchParams({page:n.toString(),page_size:i.toString()});return c&&u.append("search",c),(await _e(`/api/planner/chat/${l}/logs?${u}`)).json()}async function mk(l,n){return(await _e(`/api/planner/log/${l}/${n}`)).json()}async function xk(){return(await _e("/api/replier/overview")).json()}async function hk(l,n=1,i=20,c){const u=new URLSearchParams({page:n.toString(),page_size:i.toString()});return c&&u.append("search",c),(await _e(`/api/replier/chat/${l}/logs?${u}`)).json()}async function fk(l,n){return(await _e(`/api/replier/log/${l}/${n}`)).json()}function $v(){const[l,n]=d.useState(new Map),[i,c]=d.useState(!0),u=d.useCallback(async()=>{try{c(!0);const h=await sx();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)}},[]);d.useEffect(()=>{u()},[u]);const x=d.useCallback(h=>l.get(h)||h,[l]);return{chatNameMap:l,getChatName:x,loading:i,reload:u}}function Vo(l){return new Date(l*1e3).toLocaleString("zh-CN")}function Bv(l){const i=Date.now()/1e3-l;return i<60?"刚刚":i<3600?`${Math.floor(i/60)} 分钟前`:i<86400?`${Math.floor(i/3600)} 小时前`:`${Math.floor(i/86400)} 天前`}function Iv(l,n,i=1e4){d.useEffect(()=>{if(!l)return;const c=setInterval(n,i);return()=>clearInterval(c)},[l,n,i])}function pk({autoRefresh:l,refreshKey:n}){const[i,c]=d.useState("overview"),[u,x]=d.useState(null),{getChatName:h}=$v(),[f,p]=d.useState(null),[g,N]=d.useState(!0),[v,b]=d.useState(null),[w,y]=d.useState(!1),[R,O]=d.useState(1),[S,B]=d.useState(20),[E,C]=d.useState(""),[z,H]=d.useState(""),[L,J]=d.useState(""),[U,oe]=d.useState(null),[Ne,je]=d.useState(!1),[re,fe]=d.useState(!1),ge=d.useCallback(async()=>{try{N(!0);const D=await dk();p(D)}catch(D){console.error("加载规划器总览失败:",D)}finally{N(!1)}},[]),M=d.useCallback(async()=>{if(u)try{y(!0);const D=await uk(u.chat_id,R,S,z||void 0);b(D)}catch(D){console.error("加载聊天日志失败:",D)}finally{y(!1)}},[u,R,S,z]);d.useEffect(()=>{ge()},[ge]),d.useEffect(()=>{n>0&&(i==="overview"?ge():M())},[n,i,ge,M]),d.useEffect(()=>{i==="chat-logs"&&u&&M()},[i,u,M]),Iv(l,d.useCallback(()=>{i==="overview"?ge():M()},[i,ge,M]));const K=D=>{x(D),O(1),H(""),J(""),c("chat-logs")},I=()=>{c("overview"),x(null),b(null),H(""),J("")},ue=()=>{H(L),O(1)},Q=()=>{J(""),H(""),O(1)},Se=async(D,V)=>{try{fe(!0),je(!0);const de=await mk(D,V);oe(de)}catch(de){console.error("加载计划详情失败:",de)}finally{fe(!1)}},pe=D=>{B(Number(D)),O(1)},Te=()=>{const D=parseInt(E),V=v?Math.ceil(v.total/v.page_size):0;!isNaN(D)&&D>=1&&D<=V&&(O(D),C(""))},A=v?Math.ceil(v.total/v.page_size):0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:i==="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(Re,{className:"text-sm font-medium",children:"聊天数量"}),e.jsx(za,{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(Re,{className:"text-sm font-medium",children:"计划总数"}),e.jsx(qm,{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(Re,{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,V)=>e.jsx(vs,{className:"h-24 w-full"},V))}):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(za,{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:["最后活动: ",Bv(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:I,children:[e.jsx(Ta,{className:"h-4 w-4 mr-2"}),"返回聊天列表"]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["当前聊天: ",e.jsx("span",{className:"font-medium",children:u?h(u.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(Re,{children:"计划执行记录"}),e.jsx(os,{children:u?h(u.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"})}),z&&e.jsx(_,{variant:"ghost",size:"sm",onClick:Q,children:"清除"})]}),e.jsxs(Ie,{value:S.toString(),onValueChange:pe,children:[e.jsx($e,{className:"w-full sm:w-32",children:e.jsx(Pe,{})}),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条/页"})]})]})]})]}),z&&e.jsxs("div",{className:"text-sm text-muted-foreground mt-2",children:["搜索关键词: ",e.jsxs("span",{className:"font-medium",children:['"',z,'"']})]})]}),e.jsx(Me,{children:w?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((D,V)=>e.jsx(vs,{className:"h-20 w-full"},V))}):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:Vo(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((V,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:V},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," 条记录,第 ",R," / ",A," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(1),disabled:R===1,className:"hidden sm:flex",children:e.jsx(gn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(D=>Math.max(1,D-1)),disabled:R===1,children:e.jsx(Aa,{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:A,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:[R,"/",A]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(D=>Math.min(A,D+1)),disabled:R===A,children:e.jsx(Zt,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(A),disabled:R===A,className:"hidden sm:flex",children:e.jsx(jn,{className:"h-4 w-4"})})]})]})]}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无计划记录"})})]})]})}),e.jsx(Is,{open:Ne,onOpenChange:je,children:e.jsxs(Os,{className:"max-w-4xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Ds,{children:[e.jsxs(Rs,{className:"flex items-center gap-2",children:[e.jsx(Ca,{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,V)=>e.jsx(vs,{className:"h-24 w-full"},V))}):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:Vo(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(Za,{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(Re,{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(Re,{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(Re,{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(Zm,{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(o_,{className:"h-4 w-4"}),"执行动作 (",U.actions.length,")"]}),e.jsx("div",{className:"space-y-3",children:U.actions.map((D,V)=>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:["动作 ",V+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)})]})]})]},V))})]}),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:l,refreshKey:n}){const[i,c]=d.useState("overview"),[u,x]=d.useState(null),{getChatName:h}=$v(),[f,p]=d.useState(null),[g,N]=d.useState(!0),[v,b]=d.useState(null),[w,y]=d.useState(!1),[R,O]=d.useState(1),[S,B]=d.useState(20),[E,C]=d.useState(""),[z,H]=d.useState(""),[L,J]=d.useState(""),[U,oe]=d.useState(null),[Ne,je]=d.useState(!1),[re,fe]=d.useState(!1),ge=d.useCallback(async()=>{try{N(!0);const D=await xk();p(D)}catch(D){console.error("加载回复器总览失败:",D)}finally{N(!1)}},[]),M=d.useCallback(async()=>{if(u)try{y(!0);const D=await hk(u.chat_id,R,S,z||void 0);b(D)}catch(D){console.error("加载聊天日志失败:",D)}finally{y(!1)}},[u,R,S,z]);d.useEffect(()=>{ge()},[ge]),d.useEffect(()=>{n>0&&(i==="overview"?ge():M())},[n,i,ge,M]),d.useEffect(()=>{i==="chat-logs"&&u&&M()},[i,u,M]),Iv(l,d.useCallback(()=>{i==="overview"?ge():M()},[i,ge,M]));const K=D=>{x(D),O(1),H(""),J(""),c("chat-logs")},I=()=>{c("overview"),x(null),b(null),H(""),J("")},ue=()=>{H(L),O(1)},Q=()=>{J(""),H(""),O(1)},Se=async(D,V)=>{try{fe(!0),je(!0);const de=await fk(D,V);oe(de)}catch(de){console.error("加载回复详情失败:",de)}finally{fe(!1)}},pe=D=>{B(Number(D)),O(1)},Te=()=>{const D=parseInt(E),V=v?Math.ceil(v.total/v.page_size):0;!isNaN(D)&&D>=1&&D<=V&&(O(D),C(""))},A=v?Math.ceil(v.total/v.page_size):0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:i==="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(Re,{className:"text-sm font-medium",children:"聊天数量"}),e.jsx(za,{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(Re,{className:"text-sm font-medium",children:"回复总数"}),e.jsx(qm,{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(Re,{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,V)=>e.jsx(vs,{className:"h-24 w-full"},V))}):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(za,{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:["最后活动: ",Bv(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:I,children:[e.jsx(Ta,{className:"h-4 w-4 mr-2"}),"返回聊天列表"]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["当前聊天: ",e.jsx("span",{className:"font-medium",children:u?h(u.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(Re,{children:"回复生成记录"}),e.jsx(os,{children:u?h(u.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"})}),z&&e.jsx(_,{variant:"ghost",size:"sm",onClick:Q,children:"清除"})]}),e.jsxs(Ie,{value:S.toString(),onValueChange:pe,children:[e.jsx($e,{className:"w-full sm:w-32",children:e.jsx(Pe,{})}),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条/页"})]})]})]})]}),z&&e.jsxs("div",{className:"text-sm text-muted-foreground mt-2",children:["搜索关键词: ",e.jsxs("span",{className:"font-medium",children:['"',z,'"']})]})]}),e.jsx(Me,{children:w?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((D,V)=>e.jsx(vs,{className:"h-20 w-full"},V))}):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:Vo(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(dg,{className:"h-3 w-3 mr-1"}),"成功"]}):e.jsxs(ke,{variant:"destructive",className:"text-xs",children:[e.jsx(Va,{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," 条记录,第 ",R," / ",A," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(1),disabled:R===1,className:"hidden sm:flex",children:e.jsx(gn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(D=>Math.max(1,D-1)),disabled:R===1,children:e.jsx(Aa,{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:A,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:[R,"/",A]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(D=>Math.min(A,D+1)),disabled:R===A,children:e.jsx(Zt,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(A),disabled:R===A,className:"hidden sm:flex",children:e.jsx(jn,{className:"h-4 w-4"})})]})]})]}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无回复记录"})})]})]})}),e.jsx(Is,{open:Ne,onOpenChange:je,children:e.jsxs(Os,{className:"max-w-4xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Ds,{children:[e.jsxs(Rs,{className:"flex items-center gap-2",children:[e.jsx(Ca,{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,V)=>e.jsx(vs,{className:"h-24 w-full"},V))}):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:Vo(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(dg,{className:"h-3 w-3 mr-1"}),"成功"]}):e.jsxs(ke,{variant:"destructive",children:[e.jsx(Va,{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(d_,{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(Za,{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(Re,{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(Re,{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(Re,{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,V)=>e.jsx("div",{className:"text-xs text-muted-foreground",children:D},V))})]}),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(Zm,{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,V)=>e.jsx("div",{className:"p-3 bg-muted/30 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:D})},V))})]})]}),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 jk(){const[l,n]=d.useState("planner"),[i,c]=d.useState(!1),[u,x]=d.useState(0),h=d.useCallback(()=>{x(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:i?"default":"outline",size:"sm",onClick:()=>c(!i),children:[e.jsx(dt,{className:`h-4 w-4 mr-2 ${i?"animate-spin":""}`}),i?"自动刷新中":"自动刷新"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:h,children:e.jsx(dt,{className:"h-4 w-4"})})]})]}),e.jsxs(ta,{value:l,onValueChange:f=>n(f),className:"w-full",children:[e.jsxs(Xt,{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(Vm,{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(u_,{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(pk,{autoRefresh:i,refreshKey:u})}),e.jsx(ws,{value:"replier",className:"mt-0",children:e.jsx(gk,{autoRefresh:i,refreshKey:u})})]})]})]})}const vk="Mai-with-u",Nk="plugin-repo",bk="main",yk="plugin_details.json";async function wk(){try{const l=await _e("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:vk,repo:Nk,branch:bk,file_path:yk})});if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const n=await l.json();if(!n.success||!n.data)throw new Error(n.error||"获取插件列表失败");return JSON.parse(n.data).filter(u=>!u?.id||!u?.manifest?(console.warn("跳过无效插件数据:",u),!1):!u.manifest.name||!u.manifest.version?(console.warn("跳过缺少必需字段的插件:",u.id),!1):!0).map(u=>({id:u.id,manifest:{manifest_version:u.manifest.manifest_version||1,name:u.manifest.name,version:u.manifest.version,description:u.manifest.description||"",author:u.manifest.author||{name:"Unknown"},license:u.manifest.license||"Unknown",host_application:u.manifest.host_application||{min_version:"0.0.0"},homepage_url:u.manifest.homepage_url,repository_url:u.manifest.repository_url,keywords:u.manifest.keywords||[],categories:u.manifest.categories||[],default_locale:u.manifest.default_locale||"zh-CN",locales_path:u.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!1,published_at:new Date().toISOString(),updated_at:new Date().toISOString()}))}catch(l){throw console.error("Failed to fetch plugin list:",l),l}}async function Pv(){try{const l=await _e("/api/webui/plugins/git-status");if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return await l.json()}catch(l){return console.error("Failed to check Git status:",l),{installed:!1,error:"无法检测 Git 安装状态"}}}async function Hv(){try{const l=await _e("/api/webui/plugins/version");if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return await l.json()}catch(l){return console.error("Failed to get Maimai version:",l),{version:"0.0.0",version_major:0,version_minor:0,version_patch:0}}}function Fv(l,n,i){const c=l.split(".").map(f=>parseInt(f)||0),u=c[0]||0,x=c[1]||0,h=c[2]||0;if(i.version_majorparseInt(v)||0),p=f[0]||0,g=f[1]||0,N=f[2]||0;if(i.version_major>p||i.version_major===p&&i.version_minor>g||i.version_major===p&&i.version_minor===g&&i.version_patch>N)return!1}return!0}async function _k(){try{const l=await _e("/api/webui/ws-token");if(!l.ok)return console.error("获取 WebSocket token 失败:",l.status),null;const n=await l.json();return n.success&&n.token?n.token:null}catch(l){return console.error("获取 WebSocket token 失败:",l),null}}async function Sk(l,n){const i=await _k();if(!i)return console.warn("无法获取 WebSocket token,可能未登录"),null;const c=window.location.protocol==="https:"?"wss:":"ws:",u=window.location.host,x=`${c}//${u}/api/webui/ws/plugin-progress?token=${encodeURIComponent(i)}`;try{const h=new WebSocket(x);return h.onopen=()=>{console.log("Plugin progress WebSocket connected");const f=setInterval(()=>{h.readyState===WebSocket.OPEN?h.send("ping"):clearInterval(f)},3e4)},h.onmessage=f=>{try{if(f.data==="pong")return;const p=JSON.parse(f.data);l(p)}catch(p){console.error("Failed to parse progress data:",p)}},h.onerror=f=>{console.error("Plugin progress WebSocket error:",f),n?.(f)},h.onclose=()=>{console.log("Plugin progress WebSocket disconnected")},h}catch(h){return console.error("创建 WebSocket 连接失败:",h),null}}async function Al(){try{const l=await _e("/api/webui/plugins/installed",{headers:Fs()});if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const n=await l.json();if(!n.success)throw new Error(n.message||"获取已安装插件列表失败");return n.plugins||[]}catch(l){return console.error("Failed to get installed plugins:",l),[]}}function mn(l,n){return n.some(i=>i.id===l)}function xn(l,n){const i=n.find(c=>c.id===l);if(i)return i.manifest?.version||i.version}async function Gv(l,n,i="main"){const c=await _e("/api/webui/plugins/install",{method:"POST",body:JSON.stringify({plugin_id:l,repository_url:n,branch:i})});if(!c.ok){const u=await c.json();throw new Error(u.detail||"安装失败")}return await c.json()}async function Vv(l){const n=await _e("/api/webui/plugins/uninstall",{method:"POST",body:JSON.stringify({plugin_id:l})});if(!n.ok){const i=await n.json();throw new Error(i.detail||"卸载失败")}return await n.json()}async function qv(l,n,i="main"){const c=await _e("/api/webui/plugins/update",{method:"POST",body:JSON.stringify({plugin_id:l,repository_url:n,branch:i})});if(!c.ok){const u=await c.json();throw new Error(u.detail||"更新失败")}return await c.json()}async function kk(l){const n=await _e(`/api/webui/plugins/config/${l}/schema`,{headers:Fs()});if(!n.ok){const c=await n.text();try{const u=JSON.parse(c);throw new Error(u.detail||"获取配置 Schema 失败")}catch{throw new Error(`获取配置 Schema 失败 (${n.status})`)}}const i=await n.json();if(!i.success)throw new Error(i.message||"获取配置 Schema 失败");return i.schema}async function Ck(l){const n=await _e(`/api/webui/plugins/config/${l}`,{headers:Fs()});if(!n.ok){const c=await n.text();try{const u=JSON.parse(c);throw new Error(u.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${n.status})`)}}const i=await n.json();if(!i.success)throw new Error(i.message||"获取配置失败");return i.config}async function Tk(l){const n=await _e(`/api/webui/plugins/config/${l}/raw`,{headers:Fs()});if(!n.ok){const c=await n.text();try{const u=JSON.parse(c);throw new Error(u.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${n.status})`)}}const i=await n.json();if(!i.success)throw new Error(i.message||"获取配置失败");return i.config}async function Ek(l,n){const i=await _e(`/api/webui/plugins/config/${l}`,{method:"PUT",headers:Fs(),body:JSON.stringify({config:n})});if(!i.ok){const c=await i.json();throw new Error(c.detail||"保存配置失败")}return await i.json()}async function Mk(l,n){const i=await _e(`/api/webui/plugins/config/${l}/raw`,{method:"PUT",headers:Fs(),body:JSON.stringify({config:n})});if(!i.ok){const c=await i.json();throw new Error(c.detail||"保存配置失败")}return await i.json()}async function zk(l){const n=await _e(`/api/webui/plugins/config/${l}/reset`,{method:"POST",headers:Fs()});if(!n.ok){const i=await n.json();throw new Error(i.detail||"重置配置失败")}return await n.json()}async function Ak(l){const n=await _e(`/api/webui/plugins/config/${l}/toggle`,{method:"POST",headers:Fs()});if(!n.ok){const i=await n.json();throw new Error(i.detail||"切换状态失败")}return await n.json()}const xc="https://maibot-plugin-stats.maibot-webui.workers.dev";async function Kv(l){try{const n=await fetch(`${xc}/stats/${l}`);return n.ok?await n.json():(console.error("Failed to fetch plugin stats:",n.statusText),null)}catch(n){return console.error("Error fetching plugin stats:",n),null}}async function Ok(l,n){try{const i=n||xx(),c=await fetch(`${xc}/stats/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,user_id:i})}),u=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...u}:{success:!1,error:u.error||"点赞失败"}}catch(i){return console.error("Error liking plugin:",i),{success:!1,error:"网络错误"}}}async function Dk(l,n){try{const i=n||xx(),c=await fetch(`${xc}/stats/dislike`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,user_id:i})}),u=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...u}:{success:!1,error:u.error||"点踩失败"}}catch(i){return console.error("Error disliking plugin:",i),{success:!1,error:"网络错误"}}}async function Rk(l,n,i,c){if(n<1||n>5)return{success:!1,error:"评分必须在 1-5 之间"};try{const u=c||xx(),x=await fetch(`${xc}/stats/rate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,rating:n,comment:i,user_id:u})}),h=await x.json();return x.status===429?{success:!1,error:"每天最多评分 3 次"}:x.ok?{success:!0,...h}:{success:!1,error:h.error||"评分失败"}}catch(u){return console.error("Error rating plugin:",u),{success:!1,error:"网络错误"}}}async function Qv(l){try{const n=await fetch(`${xc}/stats/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l})}),i=await n.json();return n.status===429?(console.warn("Download recording rate limited"),{success:!0}):n.ok?{success:!0,...i}:(console.error("Failed to record download:",i.error),{success:!1,error:i.error})}catch(n){return console.error("Error recording download:",n),{success:!1,error:"网络错误"}}}function Lk(){const l=navigator,n=[navigator.userAgent,navigator.language,navigator.languages?.join(",")||"",navigator.platform,navigator.hardwareConcurrency||0,screen.width,screen.height,screen.colorDepth,screen.pixelDepth,new Date().getTimezoneOffset(),Intl.DateTimeFormat().resolvedOptions().timeZone,navigator.maxTouchPoints||0,l.deviceMemory||0].join("|");let i=0;for(let c=0;c{const ee=F.map(async Ee=>{try{const me=await Kv(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)};d.useEffect(()=>{let F=null,ee=!1;return(async()=>{if(F=await Sk(ie=>{ee||(C(ie),ie.stage==="success"?setTimeout(()=>{ee||C(null)},2e3):ie.stage==="error"&&(y(!1),O(ie.error||"加载失败")))},ie=>{console.error("WebSocket error:",ie),ee||pe({title:"WebSocket 连接失败",description:"无法实时显示加载进度",variant:"destructive"})}),await new Promise(ie=>{if(!F){ie();return}const Ee=()=>{F&&F.readyState===WebSocket.OPEN?(console.log("WebSocket connected, starting to load plugins"),ie()):F&&F.readyState===WebSocket.CLOSED?(console.warn("WebSocket closed before loading plugins"),ie()):setTimeout(Ee,100)};Ee()}),!ee){const ie=await Pv();B(ie),ie.installed||pe({title:"Git 未安装",description:ie.error||"请先安装 Git 才能使用插件安装功能",variant:"destructive"})}if(!ee){const ie=await Hv();H(ie)}if(!ee)try{y(!0),O(null);const ie=await wk();if(!ee){const Ee=await Al();L(Ee);const me=ie.map(ze=>{const rs=mn(ze.id,Ee),Ut=xn(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()});b(me),Te(me)}}catch(ie){if(!ee){const Ee=ie instanceof Error?ie.message:"加载插件列表失败";O(Ee),pe({title:"加载失败",description:Ee,variant:"destructive"})}}finally{ee||y(!1)}})(),()=>{ee=!0,F&&F.close()}},[pe]);const A=F=>{if(!F.installed&&z&&!D(F))return e.jsxs(ke,{variant:"destructive",className:"gap-1",children:[e.jsx(_t,{className:"h-3 w-3"}),"不兼容"]});if(F.installed){const ee=F.installed_version?.trim(),Ue=F.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=F=>!z||!F.manifest?.host_application?!0:Fv(F.manifest.host_application.min_version,F.manifest.host_application.max_version,z),V=F=>{if(!F.installed||!F.installed_version||!F.manifest?.version)return!1;const ee=F.installed_version.trim(),Ue=F.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(F=>{if(!F.manifest)return console.warn("[过滤] 跳过无 manifest 的插件:",F.id),!1;const ee=c===""||F.manifest.name?.toLowerCase().includes(c.toLowerCase())||F.manifest.description?.toLowerCase().includes(c.toLowerCase())||F.manifest.keywords&&F.manifest.keywords.some(me=>me.toLowerCase().includes(c.toLowerCase())),Ue=x==="all"||F.manifest.categories&&F.manifest.categories.includes(x);let ie=!0;f==="installed"?ie=F.installed===!0:f==="updates"&&(ie=F.installed===!0&&V(F));const Ee=!g||!z||D(F);return ee&&Ue&&ie&&Ee}),Oe=F=>{if(!S?.installed){pe({title:"无法安装",description:"Git 未安装",variant:"destructive"});return}if(z&&!D(F)){pe({title:"无法安装",description:"插件与当前麦麦版本不兼容",variant:"destructive"});return}re(F),ge("main"),K(""),ue("preset"),Se(!1),Ne(!0)},W=async()=>{if(!je)return;const F=I==="custom"?M:fe;if(!F||F.trim()===""){pe({title:"分支名称不能为空",variant:"destructive"});return}try{Ne(!1),await Gv(je.id,je.manifest.repository_url||"",F),Qv(je.id).catch(Ue=>{console.warn("Failed to record download:",Ue)}),pe({title:"安装成功",description:`${je.manifest.name} 已成功安装`});const ee=await Al();L(ee),b(Ue=>Ue.map(ie=>{if(ie.id===je.id){const Ee=mn(ie.id,ee),me=xn(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 F=>{try{await Vv(F.id),pe({title:"卸载成功",description:`${F.manifest.name} 已成功卸载`});const ee=await Al();L(ee),b(Ue=>Ue.map(ie=>{if(ie.id===F.id){const Ee=mn(ie.id,ee),me=xn(ie.id,ee);return{...ie,installed:Ee,installed_version:me}}return ie}))}catch(ee){pe({title:"卸载失败",description:ee instanceof Error?ee.message:"未知错误",variant:"destructive"})}},He=async F=>{if(!S?.installed){pe({title:"无法更新",description:"Git 未安装",variant:"destructive"});return}try{const ee=await qv(F.id,F.manifest.repository_url||"","main");pe({title:"更新成功",description:`${F.manifest.name} 已从 ${ee.old_version} 更新到 ${ee.new_version}`});const Ue=await Al();L(Ue),b(ie=>ie.map(Ee=>{if(Ee.id===F.id){const me=mn(Ee.id,Ue),ze=xn(Ee.id,Ue);return{...Ee,installed:me,installed_version:ze}}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:i,children:[e.jsx(Hj,{className:`h-4 w-4 mr-2 ${i?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(_,{onClick:()=>l({to:"/plugin-mirrors"}),children:[e.jsx(m_,{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(Ht,{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(Re,{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:F=>u(F.target.value),className:"pl-9"})]}),e.jsxs(Ie,{value:x,onValueChange:h,children:[e.jsx($e,{className:"w-full sm:w-[200px]",children:e.jsx(Pe,{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:F=>N(F===!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(Xt,{className:"grid w-full grid-cols-3",children:[e.jsxs(Xe,{value:"all",children:["全部插件 (",v.filter(F=>{if(!F.manifest)return!1;const ee=c===""||F.manifest.name?.toLowerCase().includes(c.toLowerCase())||F.manifest.description?.toLowerCase().includes(c.toLowerCase())||F.manifest.keywords&&F.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=x==="all"||F.manifest.categories&&F.manifest.categories.includes(x),ie=!g||!z||D(F);return ee&&Ue&&ie}).length,")"]}),e.jsxs(Xe,{value:"installed",children:["已安装 (",v.filter(F=>{if(!F.manifest)return!1;const ee=c===""||F.manifest.name?.toLowerCase().includes(c.toLowerCase())||F.manifest.description?.toLowerCase().includes(c.toLowerCase())||F.manifest.keywords&&F.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=x==="all"||F.manifest.categories&&F.manifest.categories.includes(x),ie=!g||!z||D(F);return F.installed&&ee&&Ue&&ie}).length,")"]}),e.jsxs(Xe,{value:"updates",children:["可更新 (",v.filter(F=>{if(!F.manifest)return!1;const ee=c===""||F.manifest.name?.toLowerCase().includes(c.toLowerCase())||F.manifest.description?.toLowerCase().includes(c.toLowerCase())||F.manifest.keywords&&F.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=x==="all"||F.manifest.categories&&F.manifest.categories.includes(x),ie=!g||!z||D(F);return F.installed&&V(F)&&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(Bs,{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(Qn,{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(Re,{className:"text-lg text-destructive",children:"加载失败"}),e.jsx(os,{className:"text-destructive/80",children:E.error})]})]})})}),w?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(Bs,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件列表中..."})]}):R?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:R}),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||x!=="all"?"尝试调整搜索条件或筛选器":"暂无可用插件"})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:de.map(F=>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(Re,{className:"text-xl",children:F.manifest?.name||F.id}),e.jsxs("div",{className:"flex flex-col gap-1",children:[F.manifest?.categories&&F.manifest.categories[0]&&e.jsx(ke,{variant:"secondary",className:"text-xs whitespace-nowrap",children:Uk[F.manifest.categories[0]]||F.manifest.categories[0]}),A(F)]})]}),e.jsx(os,{className:"line-clamp-2",children:F.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(sa,{className:"h-4 w-4"}),e.jsx("span",{children:(J[F.id]?.downloads??F.downloads??0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(dn,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:(J[F.id]?.rating??F.rating??0).toFixed(1)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[F.manifest?.keywords&&F.manifest.keywords.slice(0,3).map(ee=>e.jsx(ke,{variant:"outline",className:"text-xs",children:ee},ee)),F.manifest?.keywords&&F.manifest.keywords.length>3&&e.jsxs(ke,{variant:"outline",className:"text-xs",children:["+",F.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",F.manifest?.version||"unknown"," · ",F.manifest?.author?.name||"Unknown"]}),F.manifest?.host_application&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:"支持:"}),e.jsxs("span",{className:"font-medium",children:[F.manifest.host_application.min_version,F.manifest.host_application.max_version?` - ${F.manifest.host_application.max_version}`:" - 最新版本"]})]})]})]})}),e.jsx(ed,{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:()=>l({to:"/plugin-detail",search:{pluginId:F.id}}),children:"查看详情"}),F.installed?V(F)?e.jsxs(_,{size:"sm",disabled:!S?.installed,title:S?.installed?void 0:"Git 未安装",onClick:()=>He(F),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(F),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"卸载"]}):e.jsxs(_,{size:"sm",disabled:!S?.installed||E?.operation==="install"||z!==null&&!D(F),title:S?.installed?z!==null&&!D(F)?`不兼容当前版本 (需要 ${F.manifest?.host_application?.min_version||"未知"}${F.manifest?.host_application?.max_version?` - ${F.manifest.host_application.max_version}`:"+"},当前 ${z?.version})`:void 0:"Git 未安装",onClick:()=>Oe(F),children:[e.jsx(sa,{className:"h-4 w-4 mr-1"}),E?.operation==="install"&&E?.plugin_id===F.id?"安装中...":"安装"]})]})}),E&&(E.stage==="loading"||E.stage==="success"||E.stage==="error")&&E.operation!=="fetch"&&E.plugin_id===F.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(Bs,{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(Qn,{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})]})})]},F.id))}),e.jsx(Is,{open:oe,onOpenChange:Ne,children:e.jsxs(Os,{children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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:F=>Se(F)}),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:I,onValueChange:F=>ue(F),children:[e.jsxs(Xt,{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:"自定义分支"})]}),I==="preset"&&e.jsx("div",{className:"mt-3",children:e.jsxs(Ie,{value:fe,onValueChange:ge,children:[e.jsx($e,{children:e.jsx(Pe,{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 (稳定版)"})]})]})}),I==="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:F=>K(F.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(sa,{className:"h-4 w-4 mr-2"}),"安装"]})]})]})}),e.jsx(Xn,{})]})})}function Ik(){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(Fj,{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(Re,{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 Pk({field:l,value:n,onChange:i}){const[c,u]=d.useState(!1);switch(l.ui_type){case"switch":return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:l.label}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]}),e.jsx(Ge,{checked:!!n,onCheckedChange:i,disabled:l.disabled})]});case"number":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsx(ae,{type:"number",value:n??l.default,onChange:x=>i(parseFloat(x.target.value)||0),min:l.min,max:l.max,step:l.step??1,placeholder:l.placeholder,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"slider":return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:l.label}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n??l.default})]}),e.jsx(qa,{value:[n??l.default],onValueChange:x=>i(x[0]),min:l.min??0,max:l.max??100,step:l.step??1,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"select":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsxs(Ie,{value:String(n??l.default),onValueChange:i,disabled:l.disabled,children:[e.jsx($e,{children:e.jsx(Pe,{placeholder:l.placeholder??"请选择"})}),e.jsx(Be,{children:l.choices?.map(x=>e.jsx(Z,{value:String(x),children:String(x)},String(x)))})]}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"textarea":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsx(ot,{value:n??l.default,onChange:x=>i(x.target.value),placeholder:l.placeholder,rows:l.rows??3,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"password":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsxs("div",{className:"relative",children:[e.jsx(ae,{type:c?"text":"password",value:n??"",onChange:x=>i(x.target.value),placeholder:l.placeholder,disabled:l.disabled,className:"pr-10"}),e.jsx(_,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3",onClick:()=>u(!c),children:c?e.jsx(ec,{className:"h-4 w-4"}):e.jsx(ia,{className:"h-4 w-4"})})]}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"list":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsx(q2,{value:Array.isArray(n)?n:[],onChange:x=>i(x),itemType:l.item_type??"string",itemFields:l.item_fields,minItems:l.min_items,maxItems:l.max_items,disabled:l.disabled,placeholder:l.placeholder}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"text":default:return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsx(ae,{type:"text",value:n??l.default??"",onChange:x=>i(x.target.value),placeholder:l.placeholder,maxLength:l.max_length,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]})}}function Bg({section:l,config:n,onChange:i}){const[c,u]=d.useState(!l.collapsed),x=Object.entries(l.fields).filter(([,h])=>!h.hidden).sort(([,h],[,f])=>h.order-f.order);return e.jsx(rc,{open:c,onOpenChange:u,children:e.jsxs(Ce,{children:[e.jsx(ic,{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(Ma,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Zt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(Re,{className:"text-lg",children:l.title})]}),e.jsxs(ke,{variant:"secondary",className:"text-xs",children:[x.length," 项"]})]}),l.description&&e.jsx(os,{className:"ml-6",children:l.description})]})}),e.jsx(cc,{children:e.jsx(Me,{className:"space-y-4 pt-0",children:x.map(([h,f])=>e.jsx(Pk,{field:f,value:n[l.name]?.[h],onChange:p=>i(l.name,h,p),sectionName:l.name},h))})})]})})}function Hk({plugin:l,onBack:n}){const{toast:i}=Zs(),{triggerRestart:c,isRestarting:u}=vn(),[x,h]=d.useState("visual"),[f,p]=d.useState(null),[g,N]=d.useState({}),[v,b]=d.useState({}),[w,y]=d.useState(""),[R,O]=d.useState(""),[S,B]=d.useState(!0),[E,C]=d.useState(!1),[z,H]=d.useState(!1),[L,J]=d.useState(!1),[U,oe]=d.useState(!1),Ne=d.useCallback(async()=>{B(!0);try{const[I,ue,Q]=await Promise.all([kk(l.id),Ck(l.id),Tk(l.id)]);p(I),N(ue),b(JSON.parse(JSON.stringify(ue))),y(Q),O(Q)}catch(I){i({title:"加载配置失败",description:I instanceof Error?I.message:"未知错误",variant:"destructive"})}finally{B(!1)}},[l.id,i]);d.useEffect(()=>{Ne()},[Ne]),d.useEffect(()=>{H(x==="visual"?JSON.stringify(g)!==JSON.stringify(v):w!==R)},[g,v,w,R,x]);const je=(I,ue,Q)=>{N(Se=>({...Se,[I]:{...Se[I]||{},[ue]:Q}}))},re=async()=>{C(!0);try{if(x==="source"){try{Ov(w)}catch(I){J(!0),i({title:"TOML 格式错误",description:I instanceof Error?I.message:"无法解析 TOML 配置,请检查语法",variant:"destructive"}),C(!1);return}await Mk(l.id,w),O(w),J(!1)}else await Ek(l.id,g),b(JSON.parse(JSON.stringify(g)));i({title:"配置已保存",description:"更改将在插件重新加载后生效"})}catch(I){i({title:"保存失败",description:I instanceof Error?I.message:"未知错误",variant:"destructive"})}finally{C(!1)}},fe=async()=>{try{await zk(l.id),i({title:"配置已重置",description:"下次加载插件时将使用默认配置"}),oe(!1),Ne()}catch(I){i({title:"重置失败",description:I instanceof Error?I.message:"未知错误",variant:"destructive"})}},ge=async()=>{try{const I=await Ak(l.id);i({title:I.message,description:I.note}),Ne()}catch(I){i({title:"切换状态失败",description:I instanceof Error?I.message:"未知错误",variant:"destructive"})}};if(S)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(Bs,{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(Ta,{className:"h-4 w-4 mr-2"}),"返回"]})]});const M=Object.values(f.sections).sort((I,ue)=>I.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(Ta,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:f.plugin_info.name||l.manifest.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(ke,{variant:K?"default":"secondary",children:K?"已启用":"已禁用"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["v",f.plugin_info.version||l.manifest.version]})]})]})]}),e.jsxs("div",{className:"flex gap-2 ml-10 sm:ml-0",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>h(x==="visual"?"source":"visual"),children:x==="visual"?e.jsxs(e.Fragment,{children:[e.jsx(Bj,{className:"h-4 w-4 mr-2"}),"源代码"]}):e.jsxs(e.Fragment,{children:[e.jsx($j,{className:"h-4 w-4 mr-2"}),"可视化"]})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>c(),disabled:u,children:[e.jsx(Hj,{className:`h-4 w-4 mr-2 ${u?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:ge,children:[e.jsx(oc,{className:"h-4 w-4 mr-2"}),K?"禁用":"启用"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>oe(!0),children:[e.jsx(Wi,{className:"h-4 w-4 mr-2"}),"重置"]}),e.jsxs(_,{size:"sm",onClick:re,disabled:!z||E,children:[E?e.jsx(Bs,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(dc,{className:"h-4 w-4 mr-2"}),"保存"]})]})]}),z&&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(Ht,{className:"h-4 w-4 text-orange-600"}),e.jsx("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:"有未保存的更改"})]})})}),x==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(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(yv,{value:w,onChange:I=>{y(I),L&&J(!1)},language:"toml",theme:"dark",height:"calc(100vh - 350px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),x==="visual"&&e.jsxs(e.Fragment,{children:[e.jsxs(at,{children:[e.jsx(Ht,{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(Xt,{children:f.layout.tabs.map(I=>e.jsxs(Xe,{value:I.id,children:[I.title,I.badge&&e.jsx(ke,{variant:"secondary",className:"ml-2 text-xs",children:I.badge})]},I.id))}),f.layout.tabs.map(I=>e.jsx(ws,{value:I.id,className:"space-y-4 mt-4",children:I.sections.map(ue=>{const Q=f.sections[ue];return Q?e.jsx(Bg,{section:Q,config:g,onChange:je},ue):null})},I.id))]}):e.jsx("div",{className:"space-y-4",children:M.map(I=>e.jsx(Bg,{section:I,config:g,onChange:je},I.name))})]}),e.jsx(Is,{open:U,onOpenChange:oe,children:e.jsxs(Os,{children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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 Fk(){return e.jsx(Jn,{children:e.jsx(Gk,{})})}function Gk(){const{toast:l}=Zs(),[n,i]=d.useState([]),[c,u]=d.useState(!0),[x,h]=d.useState(""),[f,p]=d.useState(null),g=async()=>{u(!0);try{const y=await Al();i(y)}catch(y){l({title:"加载插件列表失败",description:y instanceof Error?y.message:"未知错误",variant:"destructive"})}finally{u(!1)}};d.useEffect(()=>{g()},[]);const v=n.filter(y=>{const R=x.toLowerCase();return y.id.toLowerCase().includes(R)||y.manifest.name.toLowerCase().includes(R)||y.manifest.description?.toLowerCase().includes(R)}).filter((y,R,O)=>R===O.findIndex(S=>S.id===y.id)),b=n.length,w=0;return f?e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"h-full",children:e.jsx("div",{className:"p-4 sm:p-6",children:e.jsx(Hk,{plugin:f,onBack:()=>p(null)})})}),e.jsx(Xn,{})]}):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(Re,{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(Re,{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:b}),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(Re,{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:w}),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:x,onChange:y=>h(y.target.value),className:"pl-9"})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Re,{children:"已安装的插件"}),e.jsx(os,{children:"点击插件查看和编辑配置"})]}),e.jsx(Me,{children:c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Bs,{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:x?"没有找到匹配的插件":"暂无已安装的插件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:x?"尝试其他搜索关键词":"前往插件市场安装插件"})]})]}):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(pn,{className:"h-4 w-4"})}),e.jsx(Zt,{className:"h-4 w-4 text-muted-foreground"})]})]},y.id))})})]})]})})}function Vk(){const l=ca(),{toast:n}=Zs(),[i,c]=d.useState([]),[u,x]=d.useState(!0),[h,f]=d.useState(null),[p,g]=d.useState(null),[N,v]=d.useState(!1),[b,w]=d.useState(!1),[y,R]=d.useState({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),O=d.useCallback(async()=>{try{x(!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{x(!1)}},[n]);d.useEffect(()=>{O()},[O]);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),R({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),O()}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:"镜像源已更新"}),w(!1),g(null),O()}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:"镜像源已删除"}),O()}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("更新状态失败");O()}catch(J){n({title:"更新失败",description:J instanceof Error?J.message:"未知错误",variant:"destructive"})}},z=L=>{g(L),R({id:L.id,name:L.name,raw_prefix:L.raw_prefix,clone_prefix:L.clone_prefix,enabled:L.enabled,priority:L.priority}),w(!0)},H=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("更新优先级失败");O()}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:()=>l({to:"/plugins"}),children:e.jsx(Ta,{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"}),"添加镜像源"]})]}),u?e.jsx(Ce,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Bs,{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:O,children:"重新加载"})]})}):e.jsxs(Ce,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(Rl,{children:[e.jsx(Ll,{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(Ul,{children:i.map(L=>e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(Ge,{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:()=>H(L,"up"),disabled:L.priority===1,children:e.jsx(Fr,{className:"h-3 w-3"})}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>H(L,"down"),children:e.jsx(Ma,{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:()=>z(L),children:e.jsx(Gn,{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:i.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(Ge,{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:()=>z(L),children:[e.jsx(Gn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>H(L,"up"),disabled:L.priority===1,children:e.jsx(Fr,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>H(L,"down"),children:e.jsx(Ma,{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(Is,{open:N,onOpenChange:v,children:e.jsxs(Os,{className:"max-w-lg",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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=>R({...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=>R({...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=>R({...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=>R({...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=>R({...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(Ge,{id:"add-enabled",checked:y.enabled,onCheckedChange:L=>R({...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(Is,{open:b,onOpenChange:w,children:e.jsxs(Os,{className:"max-w-lg",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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=>R({...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=>R({...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=>R({...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=>R({...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(Ge,{id:"edit-enabled",checked:y.enabled,onCheckedChange:L=>R({...y,enabled:L})}),e.jsx(T,{htmlFor:"edit-enabled",children:"启用此镜像源"})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>w(!1),children:"取消"}),e.jsx(_,{onClick:B,children:"保存"})]})]})})]})})}function qk({pluginId:l,compact:n=!1}){const[i,c]=d.useState(null),[u,x]=d.useState(!0),[h,f]=d.useState(0),[p,g]=d.useState(""),[N,v]=d.useState(!1),{toast:b}=Zs(),w=async()=>{x(!0);const S=await Kv(l);S&&c(S),x(!1)};d.useEffect(()=>{w()},[l]);const y=async()=>{const S=await Ok(l);S.success?(b({title:"已点赞",description:"感谢你的支持!"}),w()):b({title:"点赞失败",description:S.error||"未知错误",variant:"destructive"})},R=async()=>{const S=await Dk(l);S.success?(b({title:"已反馈",description:"感谢你的反馈!"}),w()):b({title:"操作失败",description:S.error||"未知错误",variant:"destructive"})},O=async()=>{if(h===0){b({title:"请选择评分",description:"至少选择 1 颗星",variant:"destructive"});return}const S=await Rk(l,h,p||void 0);S.success?(b({title:"评分成功",description:"感谢你的评价!"}),v(!1),f(0),g(""),w()):b({title:"评分失败",description:S.error||"未知错误",variant:"destructive"})};return u?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(sa,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(dn,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]})]}):i?n?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",title:`下载量: ${i.downloads.toLocaleString()}`,children:[e.jsx(sa,{className:"h-4 w-4"}),e.jsx("span",{children:i.downloads.toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`评分: ${i.rating.toFixed(1)} (${i.rating_count} 条评价)`,children:[e.jsx(dn,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:i.rating.toFixed(1)})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`点赞数: ${i.likes}`,children:[e.jsx(bm,{className:"h-4 w-4"}),e.jsx("span",{children:i.likes})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(sa,{className:"h-5 w-5 text-muted-foreground mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.downloads.toLocaleString()}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"下载量"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(dn,{className:"h-5 w-5 text-yellow-400 mb-1 fill-yellow-400"}),e.jsx("span",{className:"text-2xl font-bold",children:i.rating.toFixed(1)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[i.rating_count," 条评价"]})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(bm,{className:"h-5 w-5 text-green-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.likes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点赞"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(ug,{className:"h-5 w-5 text-red-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.dislikes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点踩"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:y,children:[e.jsx(bm,{className:"h-4 w-4 mr-1"}),"点赞"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:R,children:[e.jsx(ug,{className:"h-4 w-4 mr-1"}),"点踩"]}),e.jsxs(Is,{open:N,onOpenChange:v,children:[e.jsx(sd,{asChild:!0,children:e.jsxs(_,{variant:"default",size:"sm",children:[e.jsx(dn,{className:"h-4 w-4 mr-1"}),"评分"]})}),e.jsxs(Os,{children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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(dn,{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:O,disabled:h===0,children:"提交评分"})]})]})]})]}),i.recent_ratings&&i.recent_ratings.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"最近评价"}),e.jsx("div",{className:"space-y-3",children:i.recent_ratings.map((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(dn,{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 Kk={"Group Management":"群组管理","Entertainment & Interaction":"娱乐互动","Utility Tools":"实用工具","Content Generation":"内容生成",Multimedia:"多媒体","External Integration":"外部集成","Data Analysis & Insights":"数据分析与洞察",Other:"其他"};function Qk(){const l=ca(),n=y0({strict:!1}),{toast:i}=Zs(),[c,u]=d.useState(null),[x,h]=d.useState(""),[f,p]=d.useState(!0),[g,N]=d.useState(!0),[v,b]=d.useState(null),[w,y]=d.useState(null),[R,O]=d.useState(null),[S,B]=d.useState(!1),[E,C]=d.useState(),[z,H]=d.useState(!1);d.useEffect(()=>{(async()=>{if(!n.pluginId){b("缺少插件 ID"),p(!1);return}try{p(!0),b(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 I={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()};u(I);const[ue,Q,Se]=await Promise.all([Pv(),Hv(),Al()]);y(ue),O(Q),B(mn(n.pluginId,Se)),C(xn(n.pluginId,Se))}catch(fe){b(fe instanceof Error?fe.message:"加载失败")}finally{p(!1)}})()},[n.pluginId]),d.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$/,""),I=await _e("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:ge,repo:K,branch:"main",file_path:"README.md"})});if(!I.ok)throw new Error("获取 README 失败");const ue=await I.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||!R?!0:Fv(c.manifest.host_application.min_version,c.manifest.host_application.max_version,R),U=async()=>{if(!(!c||!w?.installed))try{H(!0),await Gv(c.id,c.manifest.repository_url||"","main"),Qv(c.id).catch(fe=>{console.warn("Failed to record download:",fe)}),i({title:"安装成功",description:`${c.manifest.name} 已成功安装`});const re=await Al();B(mn(c.id,re)),C(xn(c.id,re))}catch(re){i({title:"安装失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"})}finally{H(!1)}},oe=async()=>{if(c)try{H(!0),await Vv(c.id),i({title:"卸载成功",description:`${c.manifest.name} 已成功卸载`});const re=await Al();B(mn(c.id,re)),C(xn(c.id,re))}catch(re){i({title:"卸载失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"})}finally{H(!1)}},Ne=async()=>{if(!(!c||!w?.installed))try{H(!0);const re=await qv(c.id,c.manifest.repository_url||"","main");i({title:"更新成功",description:`${c.manifest.name} 已从 ${re.old_version} 更新到 ${re.new_version}`});const fe=await Al();B(mn(c.id,fe)),C(xn(c.id,fe))}catch(re){i({title:"更新失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"})}finally{H(!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:()=>l({to:"/plugins"}),children:e.jsx(Ta,{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(Bs,{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:()=>l({to:"/plugins"}),children:e.jsx(Ta,{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:()=>l({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:()=>l({to:"/plugins"}),className:"shrink-0",children:e.jsx(Ta,{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:!w?.installed||z,onClick:Ne,title:w?.installed?void 0:"Git 未安装",children:z?e.jsxs(e.Fragment,{children:[e.jsx(Bs,{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:!w?.installed||z,onClick:oe,title:w?.installed?void 0:"Git 未安装",children:z?e.jsxs(e.Fragment,{children:[e.jsx(Bs,{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:!w?.installed||!je||z,onClick:U,title:w?.installed?je?void 0:`不兼容当前版本 (需要 ${c.manifest.host_application.min_version}${c.manifest.host_application.max_version?` - ${c.manifest.host_application.max_version}`:"+"},当前 ${R?.version})`:"Git 未安装",children:z?e.jsxs(e.Fragment,{children:[e.jsx(Bs,{className:"h-4 w-4 mr-2 animate-spin"}),"安装中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(sa,{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(Re,{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(Re,{className:"text-lg",children:"统计信息"})}),e.jsx(Me,{children:e.jsx(qk,{pluginId:c.id})})]}),e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Re,{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(fn,{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(Oo,{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(Rj,{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(Bo,{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(Oo,{className:"h-3 w-3"})]})]}),c.manifest.repository_url&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(x_,{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(Oo,{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(Ht,{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(Re,{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:Kk[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(Wo,{className:"h-3 w-3 mr-1"}),re]},re))})]})]})]})]}),e.jsxs(Ce,{className:"lg:col-span-2",children:[e.jsx(De,{children:e.jsx(Re,{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(Bs,{className:"h-6 w-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-sm text-muted-foreground",children:"加载说明文档中..."})]}):x?e.jsx(nx,{content:x}):e.jsx("div",{className:"text-center text-muted-foreground py-12",children:"暂无说明文档"})})})]})]})]})})]})}const Ki=d.forwardRef(({className:l,...n},i)=>e.jsx(nj,{ref:i,className:P("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",l),...n}));Ki.displayName=nj.displayName;const Yk=d.forwardRef(({className:l,...n},i)=>e.jsx(rj,{ref:i,className:P("aspect-square h-full w-full",l),...n}));Yk.displayName=rj.displayName;const Qi=d.forwardRef(({className:l,...n},i)=>e.jsx(ij,{ref:i,className:P("flex h-full w-full items-center justify-center rounded-full bg-muted",l),...n}));Qi.displayName=ij.displayName;function Jk(){return"webui_"+Math.random().toString(36).substr(2,9)+"_"+Date.now().toString(36)}function Xk(){const l="maibot_webui_user_id";let n=localStorage.getItem(l);return n||(n=Jk(),localStorage.setItem(l,n)),n}function Zk(){return localStorage.getItem("maibot_webui_user_name")||"WebUI用户"}function Wk(l){localStorage.setItem("maibot_webui_user_name",l)}const Yv="maibot_webui_virtual_tabs";function eC(){try{const l=localStorage.getItem(Yv);if(l)return JSON.parse(l)}catch(l){console.error("[Chat] 加载虚拟标签页失败:",l)}return[]}function Ig(l){try{localStorage.setItem(Yv,JSON.stringify(l))}catch(n){console.error("[Chat] 保存虚拟标签页失败:",n)}}function sC({segment:l}){switch(l.type){case"text":return e.jsx("span",{className:"whitespace-pre-wrap",children:String(l.data)});case"image":case"emoji":return e.jsx("img",{src:String(l.data),alt:l.type==="emoji"?"表情包":"图片",className:P("rounded-lg max-w-full",l.type==="emoji"?"max-h-32":"max-h-64"),loading:"lazy",onError:n=>{const i=n.target;i.style.display="none",i.parentElement?.insertAdjacentHTML("beforeend",`[${l.type==="emoji"?"表情包":"图片"}加载失败]`)}});case"voice":return e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("audio",{controls:!0,src:String(l.data),className:"max-w-[200px] h-8",children:"您的浏览器不支持音频播放"})});case"video":return e.jsx("video",{controls:!0,src:String(l.data),className:"rounded-lg max-w-full max-h-64",children:"您的浏览器不支持视频播放"});case"face":return e.jsxs("span",{className:"text-muted-foreground",children:["[表情:",String(l.data),"]"]});case"music":return e.jsx("span",{className:"text-muted-foreground",children:"[音乐分享]"});case"file":return e.jsxs("span",{className:"text-muted-foreground",children:["[文件: ",String(l.data),"]"]});case"reply":return e.jsx("span",{className:"text-muted-foreground text-xs",children:"[回复消息]"});case"forward":return e.jsx("span",{className:"text-muted-foreground",children:"[转发消息]"});case"unknown":default:return e.jsxs("span",{className:"text-muted-foreground",children:["[",l.original_type||"未知消息","]"]})}}function tC({message:l,isBot:n}){return l.message_type==="rich"&&l.segments&&l.segments.length>0?e.jsx("div",{className:"flex flex-col gap-2",children:l.segments.map((i,c)=>e.jsx(sC,{segment:i},c))}):e.jsx("span",{className:"whitespace-pre-wrap",children:l.content})}function aC(){const l={id:"webui-default",type:"webui",label:"WebUI",messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}},n=()=>{const qe=eC().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[l,...qe]},[i,c]=d.useState(n),[u,x]=d.useState("webui-default"),h=i.find(q=>q.id===u)||i[0],[f,p]=d.useState(""),[g,N]=d.useState(!1),[v,b]=d.useState(!0),[w,y]=d.useState(Zk()),[R,O]=d.useState(!1),[S,B]=d.useState(""),[E,C]=d.useState(!1),[z,H]=d.useState([]),[L,J]=d.useState([]),[U,oe]=d.useState(!1),[Ne,je]=d.useState(!1),[re,fe]=d.useState(""),[ge,M]=d.useState({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),K=d.useRef(Xk()),I=d.useRef(new Map),ue=d.useRef(null),Q=d.useRef(new Map),Se=d.useRef(0),pe=d.useRef(new Map),{toast:Te}=Zs(),A=q=>(Se.current+=1,`${q}-${Date.now()}-${Se.current}-${Math.random().toString(36).substr(2,9)}`),D=d.useCallback((q,qe)=>{c(Qe=>Qe.map(es=>es.id===q?{...es,...qe}:es))},[]),V=d.useCallback((q,qe)=>{c(Qe=>Qe.map(es=>es.id===q?{...es,messages:[...es.messages,qe]}:es))},[]),de=d.useCallback(()=>{ue.current?.scrollIntoView({behavior:"smooth"})},[]);d.useEffect(()=>{de()},[h?.messages,de]);const Oe=d.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),H(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=d.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 Ls=es.headers.get("content-type");if(Ls&&Ls.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)}},[]);d.useEffect(()=>{ge.platform&&W(ge.platform,re)},[ge.platform,re,W]);const Y=d.useCallback(async(q,qe)=>{b(!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 Ls=await _e(es);if(Ls.ok){const as=await Ls.text();try{const Cs=JSON.parse(as);if(Cs.messages&&Cs.messages.length>0){const Ae=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:Ae});const bs=pe.current.get(q)||new Set;Ae.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{b(!1)}},[D]),He=d.useCallback(async(q,qe,Qe)=>{const es=I.current.get(q);if(es?.readyState===WebSocket.OPEN||es?.readyState===WebSocket.CONNECTING){console.log(`[Tab ${q}] WebSocket 已存在,跳过连接`);return}N(!0);let Ls=null;try{const bs=await _e("/api/webui/ws-token");if(bs.ok){const ls=await bs.json();if(ls.success&&ls.token)Ls=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(!Ls){N(!1);return}const as=window.location.protocol==="https:"?"wss:":"ws:",Cs=new URLSearchParams;Cs.append("token",Ls),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",w));const Ae=`${as}//${window.location.host}/api/chat/ws?${Cs.toString()}`;console.log(`[Tab ${q}] 正在连接 WebSocket:`,Ae);try{const bs=new WebSocket(Ae);I.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":V(q,{id:A("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)}V(q,{id:ss.message_id||A("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:A("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:A("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||A(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),I.current.delete(q),console.log(`[Tab ${q}] WebSocket 已断开`);const ls=Q.current.get(q);ls&&clearTimeout(ls);const ss=window.setTimeout(()=>{if(!F.current){const ys=i.find(gt=>gt.id===q);ys&&He(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)}},[w,D,V,Te,i]),F=d.useRef(!1);d.useEffect(()=>{F.current=!1;const q=I.current,qe=Q.current,Qe=pe.current;Y("webui-default");const es=setTimeout(()=>{F.current||(He("webui-default","webui"),i.forEach(as=>{as.type==="virtual"&&as.virtualConfig&&(Qe.set(as.id,new Set),setTimeout(()=>{F.current||He(as.id,"virtual",as.virtualConfig)},200))}))},100),Ls=setInterval(()=>{q.forEach(as=>{as.readyState===WebSocket.OPEN&&as.send(JSON.stringify({type:"ping"}))})},3e4);return()=>{F.current=!0,clearTimeout(es),clearInterval(Ls),qe.forEach(as=>{clearTimeout(as)}),qe.clear(),q.forEach(as=>{as.close()}),q.clear()}},[]);const ee=d.useCallback(()=>{const q=I.current.get(u);if(!f.trim()||!q||q.readyState!==WebSocket.OPEN)return;const qe=h?.type==="virtual"&&h.virtualConfig?.userName||w,Qe=f.trim(),es=Date.now()/1e3;q.send(JSON.stringify({type:"message",content:Qe,user_name:qe}));const Ls=pe.current.get(u)||new Set,as=`user-${Qe}-${Math.floor(es*1e3)}`;if(Ls.add(as),pe.current.set(u,Ls),Ls.size>100){const bs=Ls.values().next().value;bs&&Ls.delete(bs)}const Cs={id:A("user"),type:"user",content:Qe,timestamp:es,sender:{name:qe,is_bot:!1}};V(u,Cs);const Ae={id:A("thinking"),type:"thinking",content:"",timestamp:es+.001,sender:{name:h?.sessionInfo.bot_name||"麦麦",is_bot:!0}};V(u,Ae),p("")},[f,w,u,h,V]),Ue=q=>{q.key==="Enter"&&!q.shiftKey&&(q.preventDefault(),ee())},ie=()=>{B(w),O(!0)},Ee=()=>{const q=S.trim()||"WebUI用户";y(q),Wk(q),O(!1);const qe=I.current.get(u);qe?.readyState===WebSocket.OPEN&&qe.send(JSON.stringify({type:"update_nickname",user_name:q}))},me=()=>{B(""),O(!1)},ze=q=>new Date(q*1e3).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),rs=()=>{const q=I.current.get(u);q&&(q.close(),I.current.delete(u)),He(u,h?.type||"webui",h?.virtualConfig)},Ut=()=>{M({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),fe(""),Oe(),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(Ls=>{const as=[...Ls,es],Cs=as.filter(Ae=>Ae.type==="virtual"&&Ae.virtualConfig).map(Ae=>({id:Ae.id,label:Ae.label,virtualConfig:Ae.virtualConfig,createdAt:Date.now()}));return Ig(Cs),as}),x(qe),C(!1),pe.current.set(qe,new Set),setTimeout(()=>{He(qe,"virtual",ge)},100),Te({title:"虚拟身份标签页",description:`已创建 ${Qe} 的对话`})},Qa=(q,qe)=>{if(qe?.stopPropagation(),q==="webui-default")return;const Qe=I.current.get(q);Qe&&(Qe.close(),I.current.delete(q));const es=Q.current.get(q);es&&(clearTimeout(es),Q.current.delete(q)),pe.current.delete(q),c(Ls=>{const as=Ls.filter(Ae=>Ae.id!==q),Cs=as.filter(Ae=>Ae.type==="virtual"&&Ae.virtualConfig).map(Ae=>({id:Ae.id,label:Ae.label,virtualConfig:Ae.virtualConfig,createdAt:Date.now()}));return Ig(Cs),as}),u===q&&x("webui-default")},Ft=q=>{x(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(Is,{open:E,onOpenChange:C,children:e.jsxs(Os,{className:"sm:max-w-[500px] max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsxs(Ds,{children:[e.jsxs(Rs,{className:"flex items-center gap-2",children:[e.jsx(ym,{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(Bo,{className:"h-4 w-4"}),"选择平台"]}),e.jsxs(Ie,{value:ge.platform,onValueChange:q=>{M(qe=>({...qe,platform:q,personId:"",userId:"",userName:""})),J([])},children:[e.jsx($e,{disabled:U,children:e.jsx(Pe,{placeholder:U?"加载中...":"选择平台"})}),e.jsx(Be,{children:z.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(tc,{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(Bs,{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(tc,{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:P("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(Ki,{className:"h-8 w-8 shrink-0",children:e.jsx(Qi,{className:P("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:P("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:[i.map(q=>e.jsxs("div",{className:P("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm whitespace-nowrap transition-colors cursor-pointer","hover:bg-muted",u===q.id?"bg-background shadow-sm border":"text-muted-foreground"),onClick:()=>Ft(q.id),children:[q.type==="webui"?e.jsx(za,{className:"h-3.5 w-3.5"}):e.jsx(ym,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"max-w-[100px] truncate",children:q.label}),e.jsx("span",{className:P("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=>Qa(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(),Qa(q.id,qe))},children:e.jsx(Ea,{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(Ki,{className:"h-8 w-8 sm:h-10 sm:w-10 shrink-0",children:e.jsx(Qi,{className:"bg-primary/10 text-primary",children:e.jsx(Pn,{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(h_,{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(Bs,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"连接中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(f_,{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(Bs,{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:P("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(ym,{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(fn,{className:"h-3 w-3"}),e.jsx("span",{children:"当前身份:"}),R?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:w}),e.jsx(_,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:ie,title:"修改昵称",children:e.jsx(p_,{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(Pn,{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:P("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(Ki,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(Qi,{className:"bg-primary/10 text-primary",children:e.jsx(Pn,{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(Ki,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(Qi,{className:P("text-xs",q.type==="bot"?"bg-primary/10 text-primary":"bg-secondary text-secondary-foreground"),children:q.type==="bot"?e.jsx(Pn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}):e.jsx(fn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})}),e.jsxs("div",{className:P("flex flex-col gap-1 max-w-[75%] sm:max-w-[70%]",q.type==="user"&&"items-end"),children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] sm:text-xs text-muted-foreground",children:[e.jsx("span",{className:"hidden sm:inline",children:q.sender?.name||(q.type==="bot"?h?.sessionInfo.bot_name:w)}),e.jsx("span",{children:ze(q.timestamp)})]}),e.jsx("div",{className:P("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(tC,{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 hx="Radio",[lC,Jv]=Yo(hx),[nC,rC]=lC(hx),Xv=d.forwardRef((l,n)=>{const{__scopeRadio:i,name:c,checked:u=!1,required:x,disabled:h,value:f="on",onCheck:p,form:g,...N}=l,[v,b]=d.useState(null),w=Jo(n,O=>b(O)),y=d.useRef(!1),R=v?g||!!v.closest("form"):!0;return e.jsxs(nC,{scope:i,checked:u,disabled:h,children:[e.jsx(Yn.button,{type:"button",role:"radio","aria-checked":u,"data-state":sN(u),"data-disabled":h?"":void 0,disabled:h,value:f,...N,ref:w,onClick:hn(l.onClick,O=>{u||p?.(),R&&(y.current=O.isPropagationStopped(),y.current||O.stopPropagation())})}),R&&e.jsx(eN,{control:v,bubbles:!y.current,name:c,value:f,checked:u,required:x,disabled:h,form:g,style:{transform:"translateX(-100%)"}})]})});Xv.displayName=hx;var Zv="RadioIndicator",Wv=d.forwardRef((l,n)=>{const{__scopeRadio:i,forceMount:c,...u}=l,x=rC(Zv,i);return e.jsx(Rw,{present:c||x.checked,children:e.jsx(Yn.span,{"data-state":sN(x.checked),"data-disabled":x.disabled?"":void 0,...u,ref:n})})});Wv.displayName=Zv;var iC="RadioBubbleInput",eN=d.forwardRef(({__scopeRadio:l,control:n,checked:i,bubbles:c=!0,...u},x)=>{const h=d.useRef(null),f=Jo(h,x),p=Lw(i),g=Uw(n);return d.useEffect(()=>{const N=h.current;if(!N)return;const v=window.HTMLInputElement.prototype,w=Object.getOwnPropertyDescriptor(v,"checked").set;if(p!==i&&w){const y=new Event("click",{bubbles:c});w.call(N,i),N.dispatchEvent(y)}},[p,i,c]),e.jsx(Yn.input,{type:"radio","aria-hidden":!0,defaultChecked:i,...u,tabIndex:-1,ref:f,style:{...u.style,...g,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});eN.displayName=iC;function sN(l){return l?"checked":"unchecked"}var cC=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],cd="RadioGroup",[oC]=Yo(cd,[cj,Jv]),tN=cj(),aN=Jv(),[dC,uC]=oC(cd),lN=d.forwardRef((l,n)=>{const{__scopeRadioGroup:i,name:c,defaultValue:u,value:x,required:h=!1,disabled:f=!1,orientation:p,dir:g,loop:N=!0,onValueChange:v,...b}=l,w=tN(i),y=kj(g),[R,O]=Qo({prop:x,defaultProp:u??null,onChange:v,caller:cd});return e.jsx(dC,{scope:i,name:c,required:h,disabled:f,value:R,onValueChange:O,children:e.jsx(X0,{asChild:!0,...w,orientation:p,dir:y,loop:N,children:e.jsx(Yn.div,{role:"radiogroup","aria-required":h,"aria-orientation":p,"data-disabled":f?"":void 0,dir:y,...b,ref:n})})})});lN.displayName=cd;var nN="RadioGroupItem",rN=d.forwardRef((l,n)=>{const{__scopeRadioGroup:i,disabled:c,...u}=l,x=uC(nN,i),h=x.disabled||c,f=tN(i),p=aN(i),g=d.useRef(null),N=Jo(n,g),v=x.value===u.value,b=d.useRef(!1);return d.useEffect(()=>{const w=R=>{cC.includes(R.key)&&(b.current=!0)},y=()=>b.current=!1;return document.addEventListener("keydown",w),document.addEventListener("keyup",y),()=>{document.removeEventListener("keydown",w),document.removeEventListener("keyup",y)}},[]),e.jsx(Z0,{asChild:!0,...f,focusable:!h,active:v,children:e.jsx(Xv,{disabled:h,required:x.required,checked:v,...p,...u,name:x.name,ref:N,onCheck:()=>x.onValueChange(u.value),onKeyDown:hn(w=>{w.key==="Enter"&&w.preventDefault()}),onFocus:hn(u.onFocus,()=>{b.current&&g.current?.click()})})})});rN.displayName=nN;var mC="RadioGroupIndicator",iN=d.forwardRef((l,n)=>{const{__scopeRadioGroup:i,...c}=l,u=aN(i);return e.jsx(Wv,{...u,...c,ref:n})});iN.displayName=mC;var cN=lN,oN=rN,xC=iN;const fx=d.forwardRef(({className:l,...n},i)=>e.jsx(cN,{className:P("grid gap-2",l),...n,ref:i}));fx.displayName=cN.displayName;const qo=d.forwardRef(({className:l,...n},i)=>e.jsx(oN,{ref:i,className:P("aspect-square h-4 w-4 rounded-full border border-primary text-primary shadow focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",l),...n,children:e.jsx(xC,{className:"flex items-center justify-center",children:e.jsx($o,{className:"h-2.5 w-2.5 fill-current text-current"})})}));qo.displayName=oN.displayName;function hC({question:l,value:n,onChange:i,error:c,disabled:u=!1}){const[x,h]=d.useState(null),f=u||l.readOnly,p=()=>{switch(l.type){case"single":return e.jsx(fx,{value:n||"",onValueChange:i,disabled:f,className:"space-y-2",children:l.options?.map(g=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qo,{value:g.value,id:`${l.id}-${g.id}`}),e.jsx(T,{htmlFor:`${l.id}-${g.id}`,className:"cursor-pointer font-normal",children:g.label})]},g.id))});case"multiple":{const g=n||[];return e.jsxs("div",{className:"space-y-2",children:[l.options?.map(N=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:`${l.id}-${N.id}`,checked:g.includes(N.value),disabled:f||l.maxSelections!==void 0&&g.length>=l.maxSelections&&!g.includes(N.value),onCheckedChange:v=>{i(v?[...g,N.value]:g.filter(b=>b!==N.value))}}),e.jsx(T,{htmlFor:`${l.id}-${N.id}`,className:"cursor-pointer font-normal",children:N.label})]},N.id)),l.maxSelections&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["最多选择 ",l.maxSelections," 项"]})]})}case"text":return e.jsx(ae,{value:n||"",onChange:g=>i(g.target.value),placeholder:l.placeholder||"请输入...",disabled:f,readOnly:l.readOnly,maxLength:l.maxLength,className:P(l.readOnly&&"bg-muted cursor-not-allowed")});case"textarea":return e.jsxs("div",{className:"space-y-1",children:[e.jsx(ot,{value:n||"",onChange:g=>i(g.target.value),placeholder:l.placeholder||"请输入...",disabled:f,readOnly:l.readOnly,maxLength:l.maxLength,rows:4,className:P(l.readOnly&&"bg-muted cursor-not-allowed")}),l.maxLength&&e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[(n||"").length," / ",l.maxLength]})]});case"rating":{const g=n||0,N=x!==null?x: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:P("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&&i(v),children:e.jsx(dn,{className:P("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=l.min??1,N=l.max??10,v=l.step??1,b=n??g;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(qa,{value:[b],onValueChange:([w])=>i(w),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:l.minLabel||g}),e.jsx("span",{className:"font-medium text-foreground",children:b}),e.jsx("span",{children:l.maxLabel||N})]})]})}case"dropdown":return e.jsxs(Ie,{value:n||"",onValueChange:i,disabled:f,children:[e.jsx($e,{children:e.jsx(Pe,{placeholder:l.placeholder||"请选择..."})}),e.jsx(Be,{children:l.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:[l.title,l.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),l.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:l.description})]}),p(),c&&e.jsx("p",{className:"text-sm text-destructive",children:c})]})}const dN="https://maibot-plugin-stats.maibot-webui.workers.dev";function uN(){const l="maibot_user_id";let n=localStorage.getItem(l);if(!n){const i=Math.random().toString(36).substring(2,10),c=Date.now().toString(36),u=Math.random().toString(36).substring(2,10);n=`fp_${i}_${c}_${u}`,localStorage.setItem(l,n)}return n}async function fC(l,n,i,c){try{const u=c?.userId||uN(),x={surveyId:l,surveyVersion:n,userId:u,answers:i,submittedAt:new Date().toISOString(),allowMultiple:c?.allowMultiple,metadata:{userAgent:navigator.userAgent,language:navigator.language}},h=await fetch(`${dN}/survey/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)}),f=await h.json();return h.status===429?{success:!1,error:"提交过于频繁,请稍后再试"}:h.status===409?{success:!1,error:f.error||"你已经提交过这份问卷了"}:h.ok?{success:!0,submissionId:f.submissionId,message:f.message}:{success:!1,error:f.error||"提交失败"}}catch(u){return console.error("Error submitting survey:",u),{success:!1,error:"网络错误"}}}async function pC(l,n){try{const i=n||uN(),c=new URLSearchParams({user_id:i,survey_id:l}),u=await fetch(`${dN}/survey/check?${c}`);return u.ok?{success:!0,hasSubmitted:(await u.json()).hasSubmitted}:{success:!1,error:(await u.json()).error||"检查失败"}}catch(i){return console.error("Error checking submission:",i),{success:!1,error:"网络错误"}}}function mN({config:l,initialAnswers:n,onSubmitSuccess:i,onSubmitError:c,showProgress:u=!0,paginateQuestions:x=!1,className:h}){const f=d.useCallback(()=>!n||n.length===0?{}:n.reduce((I,ue)=>(I[ue.questionId]=ue.value,I),{}),[n]),[p,g]=d.useState(()=>f()),[N,v]=d.useState({}),[b,w]=d.useState(0),[y,R]=d.useState(!1),[O,S]=d.useState(!1),[B,E]=d.useState(null),[C,z]=d.useState(null),[H,L]=d.useState(!1),[J,U]=d.useState(!0);d.useEffect(()=>{n&&n.length>0&&g(I=>({...I,...f()}))},[n,f]),d.useEffect(()=>{(async()=>{if(!l.settings?.allowMultiple){const ue=await pC(l.id);ue.success&&ue.hasSubmitted&&L(!0)}U(!1)})()},[l.id,l.settings?.allowMultiple]);const oe=d.useCallback(()=>{const I=new Date;return!(l.settings?.startTime&&new Date(l.settings.startTime)>I||l.settings?.endTime&&new Date(l.settings.endTime){const ue=p[I.id];return ue==null?!1:Array.isArray(ue)?ue.length>0:typeof ue=="string"?ue.trim()!=="":!0}).length,je=Ne/l.questions.length*100,re=d.useCallback((I,ue)=>{g(Q=>({...Q,[I]:ue})),v(Q=>{const Se={...Q};return delete Se[I],Se})},[]),fe=d.useCallback(()=>{const I={};for(const ue of l.questions){if(ue.required){const Q=p[ue.id];if(Q==null){I[ue.id]="此题为必填项";continue}if(Array.isArray(Q)&&Q.length===0){I[ue.id]="请至少选择一项";continue}if(typeof Q=="string"&&Q.trim()===""){I[ue.id]="此题为必填项";continue}}ue.minLength&&typeof p[ue.id]=="string"&&p[ue.id].length{if(!fe()){if(x){const I=l.questions.findIndex(ue=>N[ue.id]);I>=0&&w(I)}return}R(!0),E(null);try{const I=l.questions.filter(Q=>p[Q.id]!==void 0).map(Q=>({questionId:Q.id,value:p[Q.id]})),ue=await fC(l.id,l.version,I,{allowMultiple:l.settings?.allowMultiple});if(ue.success&&ue.submissionId)S(!0),z(ue.submissionId),i?.(ue.submissionId);else{const Q=ue.error||"提交失败";E(Q),c?.(Q)}}catch(I){const ue=I instanceof Error?I.message:"提交失败";E(ue),c?.(ue)}finally{R(!1)}},[fe,x,l,p,N,i,c]),M=d.useCallback(I=>{I>=0&&Ie.jsxs("div",{className:P("p-4 rounded-lg border bg-card",N[I.id]?"border-destructive bg-destructive/5":"border-border"),children:[x&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:["问题 ",b+1," / ",l.questions.length]}),!x&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:[ue+1,"."]}),e.jsx(hC,{question:I,value:p[I.id],onChange:Q=>re(I.id,Q),error:N[I.id],disabled:y})]},I.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:x?e.jsxs(e.Fragment,{children:[e.jsxs(_,{variant:"outline",onClick:()=>M(b-1),disabled:b===0||y,children:[e.jsx(Aa,{className:"h-4 w-4 mr-1"}),"上一题"]}),b===l.questions.length-1?e.jsxs(_,{onClick:ge,disabled:y,children:[y&&e.jsx(Bs,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]}):e.jsxs(_,{onClick:()=>M(b+1),disabled:y,children:["下一题",e.jsx(Zt,{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(Bs,{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:"感谢你的反馈!你的意见对我们非常重要,我们会认真考虑每一条建议。"}},jC={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 vC(){const[l,n]=d.useState(!0),i=d.useMemo(()=>JSON.parse(JSON.stringify(gC)),[]);d.useEffect(()=>{n(!1)},[]);const c=d.useMemo(()=>[{questionId:"webui_version",value:`v${td}`}],[]),u=d.useCallback(h=>{console.log("WebUI Survey submitted:",h)},[]),x=d.useCallback(h=>{console.error("WebUI Survey submission error:",h)},[]);return l?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(Bs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):i?e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 shrink-0",children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(Gj,{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(mN,{config:i,initialAnswers:c,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:u,onSubmitError:x})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(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 NC(){const[l,n]=d.useState(null),[i,c]=d.useState(!0),[u,x]=d.useState("未知版本");d.useEffect(()=>{(async()=>{try{const v=await d1();x(v.version||"未知版本")}catch(v){console.error("Failed to get MaiBot version:",v),x("获取失败")}const N=JSON.parse(JSON.stringify(jC));n(N),c(!1)})()},[]);const h=d.useMemo(()=>[{questionId:"maibot_version",value:u}],[u]),f=d.useCallback(g=>{console.log("MaiBot Survey submitted:",g)},[]),p=d.useCallback(g=>{console.error("MaiBot Survey submission error:",g)},[]);return i?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(Bs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):l?e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 shrink-0",children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(Gj,{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(mN,{config:l,initialAnswers:h,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:f,onSubmitError:p})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(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 bC(l=2025){const n=await _e(`/api/webui/annual-report/full?year=${l}`);if(!n.ok){const i=await n.json();throw new Error(i.detail||"获取年度报告失败")}return n.json()}const zo=["#0088FE","#00C49F","#FFBB28","#FF8042","#8884d8","#82ca9d"];function yC(l){return l>=8760?"相当于全年无休,7x24小时在线!":l>=5e3?"相当于一位全职员工的年工作时长":l>=2e3?"相当于看完了 1000 部电影":l>=1e3?"相当于环球飞行 80 次":l>=500?"相当于读完了 100 本书":l>=100?"相当于马拉松跑了 25 次":"虽然不多,但每一刻都很珍贵"}function wC(l){return l>=1e3?"夜深人静时的知心好友":l>=500?"午夜场的常客":l>=100?"偶尔熬夜的小伙伴":l>=50?"深夜有时也会陪你聊聊":"早睡早起,健康作息"}function _C(l){const n=l/1e6;return n>=100?"思考量堪比一座图书馆":n>=50?"相当于写了一部百科全书":n>=10?"脑细胞估计消耗了不少":n>=1?"也算是费了一番脑筋":"轻轻松松,游刃有余"}function SC(l){return l>=1e3?"这钱够吃一年的泡面了":l>=500?"相当于买了一台游戏机":l>=100?"够请大家喝几杯奶茶":l>=50?"一顿火锅的钱":l>=10?"几杯咖啡的价格":"省钱小能手"}function kC(l){return l>=80?"沉默是金,惜字如金":l>=60?"话不多但句句到位":l>=40?"该说的时候才开口":l>=20?"能聊的都聊了":"话痨本痨,有问必答"}function CC(l){return l>=1e4?"眼睛都快看花了":l>=5e3?"堪比专业摄影师的阅片量":l>=1e3?"看图小达人":l>=500?"图片鉴赏家":l>=100?"偶尔欣赏一下美图":"图片?有空再看"}function TC(l){return l>=500?"在不断的纠正中成长":l>=200?"学习永无止境":l>=100?"虚心接受,积极改正":l>=50?"偶尔也会犯错":l>=10?"表现还算不错":"完美表达,无需纠正"}function EC(l){return l>=1?"这次思考的价值堪比一顿大餐!":l>=.5?"为了这个问题,我可是认真思考了!":l>=.1?"下了点功夫,值得的!":l>=.01?"花了点小钱,但很值得":"小小思考,不足挂齿"}function MC(l){return l>=100?"这句话简直是万能钥匙!":l>=50?"百试不爽的经典回复":l>=20?"麦麦的口头禅":l>=10?"常用语录之一":"偶尔用用的小确幸"}function zC(l,n){return l?n>=1e3?"深夜的守护者,黑暗中的光芒":n>=500?"月亮是我的好朋友":n>=100?"越夜越精神,夜晚才是主场":"偶尔熬夜,享受宁静时光":n<=10?"作息规律,健康生活的典范":n<=50?"早睡早起,偶尔也会熬个夜":"虽然是早起鸟,但也会守候深夜"}function AC(l){return l>=1e3?"忙到飞起,键盘都要冒烟了":l>=500?"这天简直是话痨附体":l>=200?"社交达人上线":l>=100?"比平时活跃不少":l>=50?"小忙一下":"还算轻松的一天"}function OC(){const[l]=d.useState(2025),[n,i]=d.useState(null),[c,u]=d.useState(!0),[x,h]=d.useState(null),f=d.useRef(null),p=d.useCallback(async()=>{try{u(!0),h(null);const g=await bC(l);i(g)}catch(g){h(g instanceof Error?g:new Error("获取年度报告失败"))}finally{u(!1)}},[l]);return d.useEffect(()=>{p()},[p]),c?e.jsx(DC,{}):x?e.jsxs("div",{className:"flex h-screen items-center justify-center text-red-500",children:["获取年度报告失败: ",x.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",children:e.jsxs("div",{className:"mx-auto max-w-5xl space-y-8 print:space-y-4",ref:f,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.jsxs("div",{className:"relative z-10 flex flex-col items-center text-center",children:[e.jsx(Pn,{className:"mb-4 h-16 w-16 animate-bounce"}),e.jsxs("h1",{className:"text-4xl font-bold tracking-tighter sm:text-6xl",children:["麦麦 ",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(Io,{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(ka,{title:"年度在线时长",value:`${n.time_footprint.total_online_hours} 小时`,description:yC(n.time_footprint.total_online_hours),icon:e.jsx(na,{className:"h-4 w-4"})}),e.jsx(ka,{title:"最忙碌的一天",value:n.time_footprint.busiest_day||"N/A",description:AC(n.time_footprint.busiest_day_count),icon:e.jsx(Io,{className:"h-4 w-4"})}),e.jsx(ka,{title:"深夜互动 (0-4点)",value:`${n.time_footprint.midnight_chat_count} 次`,description:wC(n.time_footprint.midnight_chat_count),icon:e.jsx(Yi,{className:"h-4 w-4"})}),e.jsx(ka,{title:"作息属性",value:n.time_footprint.is_night_owl?"夜猫子":"早起鸟",description:zC(n.time_footprint.is_night_owl,n.time_footprint.midnight_chat_count),icon:n.time_footprint.is_night_owl?e.jsx(Yi,{className:"h-4 w-4"}):e.jsx(Km,{className:"h-4 w-4"})})]}),e.jsxs(Ce,{className:"overflow-hidden",children:[e.jsxs(De,{children:[e.jsx(Re,{children:"24小时活跃时钟"}),e.jsx(os,{children:"麦麦在一天中各个时段的活跃程度"})]}),e.jsx(Me,{className:"h-[300px]",children:e.jsx(uj,{width:"100%",height:"100%",children:e.jsxs(Ao,{data:n.time_footprint.hourly_distribution.map((g,N)=>({hour:`${N}点`,count:g})),children:[e.jsx(Fi,{strokeDasharray:"3 3",vertical:!1}),e.jsx(Gi,{dataKey:"hour"}),e.jsx($r,{}),e.jsx(mj,{contentStyle:{borderRadius:"8px",border:"none",boxShadow:"0 4px 12px rgba(0,0,0,0.1)"},cursor:{fill:"transparent"}}),e.jsx(Vi,{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(tc,{className:"h-8 w-8"}),e.jsx("h2",{children:"社交网络"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(ka,{title:"社交圈子",value:`${n.social_network.total_groups} 个群组`,description:"麦麦加入的群组总数",icon:e.jsx(tc,{className:"h-4 w-4"})}),e.jsx(ka,{title:"被呼叫次数",value:`${n.social_network.at_count+n.social_network.mentioned_count} 次`,description:"我的名字被大家频繁提起",icon:e.jsx(j_,{className:"h-4 w-4"})}),e.jsx(ka,{title:"最长情陪伴",value:n.social_network.longest_companion_user||"N/A",description:`始终都在,已陪伴 ${n.social_network.longest_companion_days} 天`,icon:e.jsx(qr,{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(Re,{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((g,N)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ke,{variant:N===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:N+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:g.group_name}),g.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:[g.message_count," 条消息"]})]},g.group_id)):e.jsx("div",{className:"text-center text-muted-foreground py-4",children:"暂无数据"})})})]}),e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Re,{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((g,N)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ke,{variant:N===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:N+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:g.user_nickname}),g.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:[g.message_count," 次互动"]})]},g.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(Zm,{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(ka,{title:"年度 Token 消耗",value:(n.brain_power.total_tokens/1e6).toFixed(2)+" M",description:_C(n.brain_power.total_tokens),icon:e.jsx(Za,{className:"h-4 w-4"})}),e.jsx(ka,{title:"年度总花费",value:`$${n.brain_power.total_cost.toFixed(2)}`,description:SC(n.brain_power.total_cost),icon:e.jsx("span",{className:"font-bold",children:"$"})}),e.jsx(ka,{title:"高冷指数",value:`${n.brain_power.silence_rate}%`,description:kC(n.brain_power.silence_rate),icon:e.jsx(Yi,{className:"h-4 w-4"})}),e.jsx(ka,{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(qr,{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(Re,{children:"模型偏好分布"})}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-3",children:n.brain_power.model_distribution.slice(0,5).map((g,N)=>{const v=n.brain_power.model_distribution[0]?.count||1,b=Math.round(g.count/v*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:g.model}),e.jsxs("span",{className:"text-muted-foreground",children:[g.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:`${b}%`,backgroundColor:zo[N%zo.length]}})})]},g.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(Re,{children:"最喜欢的回复模型 TOP5"}),e.jsx(os,{children:"麦麦用来回复消息的模型偏好"})]}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-3",children:n.brain_power.top_reply_models.map((g,N)=>{const v=n.brain_power.top_reply_models[0]?.count||1,b=Math.round(g.count/v*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:g.model}),e.jsxs("span",{className:"text-muted-foreground",children:[g.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:`${b}%`,backgroundColor:zo[N%zo.length]}})})]},g.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(Re,{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(g=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm font-medium",children:[e.jsxs("span",{children:["用户 ",g.user_id]}),e.jsxs("span",{children:["$",g.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:`${g.cost/(n.brain_power.top_token_consumers[0]?.cost||1)*100}%`}})})]},g.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(Re,{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:EC(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(Re,{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(Xo,{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(Re,{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,",麦麦还在回复..."]})]}),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(Re,{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:MC(n.expression_vibe.favorite_reply.count)})]})]})]}),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(Re,{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((g,N)=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:`/api/webui/emoji/${g.id}/thumbnail?original=true`,alt:`TOP ${N+1}`,className:"h-24 w-24 rounded-lg object-cover shadow-md transition-transform hover:scale-105"}),e.jsx(ke,{className:P("absolute -top-2 -right-2",N===0?"bg-yellow-500":N===1?"bg-gray-400":"bg-amber-700"),children:N+1})]}),e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:[g.usage_count," 次"]})]},g.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(Re,{children:"印象最深刻的表达风格"}),e.jsx(os,{children:"麦麦最常使用的表达方式"})]}),e.jsx(Me,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:n.expression_vibe.top_expressions.map((g,N)=>e.jsxs(ke,{variant:"outline",className:P("px-3 py-1 text-sm",N===0&&"border-primary bg-primary/10 text-primary text-base px-4 py-2"),children:[g.style," (",g.count,")"]},g.style))})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(ka,{title:"图片鉴赏",value:`${n.expression_vibe.image_processed_count} 张`,description:CC(n.expression_vibe.image_processed_count),icon:e.jsx(Xm,{className:"h-4 w-4"})}),e.jsx(ka,{title:"成长的足迹",value:`${n.expression_vibe.rejected_expression_count} 次`,description:TC(n.expression_vibe.rejected_expression_count),icon:e.jsx(Za,{className:"h-4 w-4"})})]})]})]}),n.expression_vibe.action_types.length>0&&e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsxs(Re,{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(g=>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:g.action}),e.jsxs(ke,{variant:"secondary",children:[g.count," 次"]})]},g.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(v_,{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(Re,{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(g=>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:g.content}),e.jsx("div",{className:"text-xs text-muted-foreground mt-1 line-clamp-2 max-w-[200px]",children:g.meaning||"暂无解释"})]},g.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(za,{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 ka({title:l,value:n,description:i,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(Re,{className:"text-sm font-medium",children:l}),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:i})]})]})}function DC(){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((l,n)=>e.jsx(vs,{className:"h-32 w-full"},n))}),e.jsx(vs,{className:"h-96 w-full"})]})}var od="DropdownMenu",[RC]=Yo(od,[oj]),oa=oj(),[LC,xN]=RC(od),hN=l=>{const{__scopeDropdownMenu:n,children:i,dir:c,open:u,defaultOpen:x,onOpenChange:h,modal:f=!0}=l,p=oa(n),g=d.useRef(null),[N,v]=Qo({prop:u,defaultProp:x??!1,onChange:h,caller:od});return e.jsx(LC,{scope:n,triggerId:Um(),triggerRef:g,contentId:Um(),open:N,onOpenChange:v,onOpenToggle:d.useCallback(()=>v(b=>!b),[v]),modal:f,children:e.jsx(ow,{...p,open:N,onOpenChange:v,dir:c,modal:f,children:i})})};hN.displayName=od;var fN="DropdownMenuTrigger",pN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,disabled:c=!1,...u}=l,x=xN(fN,i),h=oa(i);return e.jsx(dw,{asChild:!0,...h,children:e.jsx(Yn.button,{type:"button",id:x.triggerId,"aria-haspopup":"menu","aria-expanded":x.open,"aria-controls":x.open?x.contentId:void 0,"data-state":x.open?"open":"closed","data-disabled":c?"":void 0,disabled:c,...u,ref:$w(n,x.triggerRef),onPointerDown:hn(l.onPointerDown,f=>{!c&&f.button===0&&f.ctrlKey===!1&&(x.onOpenToggle(),x.open||f.preventDefault())}),onKeyDown:hn(l.onKeyDown,f=>{c||(["Enter"," "].includes(f.key)&&x.onOpenToggle(),f.key==="ArrowDown"&&x.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(f.key)&&f.preventDefault())})})})});pN.displayName=fN;var UC="DropdownMenuPortal",gN=l=>{const{__scopeDropdownMenu:n,...i}=l,c=oa(n);return e.jsx(sw,{...c,...i})};gN.displayName=UC;var jN="DropdownMenuContent",vN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=xN(jN,i),x=oa(i),h=d.useRef(!1);return e.jsx(tw,{id:u.contentId,"aria-labelledby":u.triggerId,...x,...c,ref:n,onCloseAutoFocus:hn(l.onCloseAutoFocus,f=>{h.current||u.triggerRef.current?.focus(),h.current=!1,f.preventDefault()}),onInteractOutside:hn(l.onInteractOutside,f=>{const p=f.detail.originalEvent,g=p.button===0&&p.ctrlKey===!0,N=p.button===2||g;(!u.modal||N)&&(h.current=!0)}),style:{...l.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});vN.displayName=jN;var $C="DropdownMenuGroup",BC=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(uw,{...u,...c,ref:n})});BC.displayName=$C;var IC="DropdownMenuLabel",NN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(iw,{...u,...c,ref:n})});NN.displayName=IC;var PC="DropdownMenuItem",bN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(aw,{...u,...c,ref:n})});bN.displayName=PC;var HC="DropdownMenuCheckboxItem",yN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(lw,{...u,...c,ref:n})});yN.displayName=HC;var FC="DropdownMenuRadioGroup",GC=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(mw,{...u,...c,ref:n})});GC.displayName=FC;var VC="DropdownMenuRadioItem",wN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(rw,{...u,...c,ref:n})});wN.displayName=VC;var qC="DropdownMenuItemIndicator",_N=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(nw,{...u,...c,ref:n})});_N.displayName=qC;var KC="DropdownMenuSeparator",SN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(cw,{...u,...c,ref:n})});SN.displayName=KC;var QC="DropdownMenuArrow",YC=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(xw,{...u,...c,ref:n})});YC.displayName=QC;var JC="DropdownMenuSubTrigger",kN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(W0,{...u,...c,ref:n})});kN.displayName=JC;var XC="DropdownMenuSubContent",CN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(ew,{...u,...c,ref:n,style:{...l.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});CN.displayName=XC;var ZC=hN,WC=pN,e3=gN,TN=vN,EN=NN,MN=bN,zN=yN,AN=wN,ON=_N,DN=SN,RN=kN,LN=CN;const s3=ZC,t3=WC,a3=d.forwardRef(({className:l,inset:n,children:i,...c},u)=>e.jsxs(RN,{ref:u,className:P("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",n&&"pl-8",l),...c,children:[i,e.jsx(Zt,{className:"ml-auto h-4 w-4"})]}));a3.displayName=RN.displayName;const l3=d.forwardRef(({className:l,...n},i)=>e.jsx(LN,{ref:i,className:P("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",l),...n}));l3.displayName=LN.displayName;const UN=d.forwardRef(({className:l,sideOffset:n=4,...i},c)=>e.jsx(e3,{children:e.jsx(TN,{ref:c,sideOffset:n,className:P("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",l),...i})}));UN.displayName=TN.displayName;const $N=d.forwardRef(({className:l,inset:n,...i},c)=>e.jsx(MN,{ref:c,className:P("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n&&"pl-8",l),...i}));$N.displayName=MN.displayName;const n3=d.forwardRef(({className:l,children:n,checked:i,...c},u)=>e.jsxs(zN,{ref:u,className:P("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",l),checked:i,...c,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(ON,{children:e.jsx(Ct,{className:"h-4 w-4"})})}),n]}));n3.displayName=zN.displayName;const r3=d.forwardRef(({className:l,children:n,...i},c)=>e.jsxs(AN,{ref:c,className:P("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",l),...i,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(ON,{children:e.jsx($o,{className:"h-2 w-2 fill-current"})})}),n]}));r3.displayName=AN.displayName;const i3=d.forwardRef(({className:l,inset:n,...i},c)=>e.jsx(EN,{ref:c,className:P("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",l),...i}));i3.displayName=EN.displayName;const c3=d.forwardRef(({className:l,...n},i)=>e.jsx(DN,{ref:i,className:P("-mx-1 my-1 h-px bg-muted",l),...n}));c3.displayName=DN.displayName;const Lm=[{value:"created_at",label:"最新发布",icon:na},{value:"downloads",label:"下载最多",icon:sa},{value:"likes",label:"最受欢迎",icon:qr}];function o3(){const l=ca(),[n,i]=d.useState([]),[c,u]=d.useState(!0),[x,h]=d.useState(""),[f,p]=d.useState("downloads"),[g,N]=d.useState(1),[v,b]=d.useState(1),[w,y]=d.useState(0),[R,O]=d.useState(new Set),[S,B]=d.useState(new Set),E=Mv(),C=d.useCallback(async()=>{u(!0);try{const U=await mS({status:"approved",page:g,page_size:12,search:x||void 0,sort_by:f,sort_order:"desc"});i(U.packs),b(U.total_pages),y(U.total);const oe=new Set;for(const Ne of U.packs)await Ev(Ne.id,E)&&oe.add(Ne.id);O(oe)}catch(U){console.error("加载 Pack 列表失败:",U),Qt({title:"加载 Pack 列表失败",variant:"destructive"})}finally{u(!1)}},[g,x,f,E]);d.useEffect(()=>{C()},[C]);const z=U=>{U.preventDefault(),N(1),C()},H=async U=>{if(!S.has(U)){B(oe=>new Set(oe).add(U));try{const oe=await Tv(U,E);O(Ne=>{const je=new Set(Ne);return oe.liked?je.add(U):je.delete(U),je}),i(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=>{l({to:"/config/pack-market/$packId",params:{packId:U}})},J=Lm.find(U=>U.value===f)||Lm[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:z,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:x,onChange:U=>h(U.target.value),className:"pl-10"})]})}),e.jsxs(s3,{children:[e.jsx(t3,{asChild:!0,children:e.jsxs(_,{variant:"outline",className:"min-w-[140px] gap-2",children:[e.jsx(N_,{className:"w-4 h-4"}),J.label,e.jsx(Ma,{className:"w-4 h-4 ml-auto"})]})}),e.jsx(UN,{align:"end",children:Lm.map(U=>e.jsxs($N,{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:w})," 个模板"]}),c?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((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(ed,{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(d3,{pack:U,liked:R.has(U.id),liking:S.has(U.id),onLike:()=>H(U.id),onView:()=>L(U.id)},U.id))}),v>1&&e.jsx(Wm,{children:e.jsxs(ex,{children:[e.jsx(Fn,{children:e.jsx(mv,{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(Fn,{children:[je&&e.jsx("span",{className:"px-2",children:"..."}),e.jsx(uc,{onClick:()=>N(U),isActive:U===g,className:"cursor-pointer",children:U})]},U)}),e.jsx(Fn,{children:e.jsx(xv,{onClick:()=>N(U=>Math.min(v,U+1)),className:g===v?"pointer-events-none opacity-50":"cursor-pointer"})})]})})]})})]})}function d3({pack:l,liked:n,liking:i,onLike:c,onView:u}){const x=h=>new Date(h).toLocaleDateString("zh-CN",{year:"numeric",month:"short",day:"numeric"});return e.jsxs(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(Re,{className:"text-lg line-clamp-1",children:l.name}),e.jsxs(ke,{variant:"secondary",className:"text-xs",children:["v",l.version]})]}),e.jsx(os,{className:"line-clamp-2 min-h-[40px]",children:l.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(fn,{className:"w-3.5 h-3.5"}),l.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(na,{className:"w-3.5 h-3.5"}),x(l.created_at)]})]}),e.jsxs("div",{className:"flex gap-4 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"提供商数量",children:[e.jsx(Dl,{className:"w-3.5 h-3.5"}),l.provider_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"模型数量",children:[e.jsx(Vn,{className:"w-3.5 h-3.5"}),l.model_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"任务配置数",children:[e.jsx(qn,{className:"w-3.5 h-3.5"}),l.task_count]})]}),l.tags&&l.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[l.tags.slice(0,3).map(h=>e.jsxs(ke,{variant:"outline",className:"text-xs",children:[e.jsx(Wo,{className:"w-2.5 h-2.5 mr-1"}),h]},h)),l.tags.length>3&&e.jsxs(ke,{variant:"outline",className:"text-xs",children:["+",l.tags.length-3]})]})]}),e.jsx(ed,{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(sa,{className:"w-4 h-4"}),l.downloads]}),e.jsxs("button",{onClick:h=>{h.stopPropagation(),c()},disabled:i,className:`flex items-center gap-1 transition-colors ${n?"text-red-500":"hover:text-red-500"} ${i?"opacity-50":""}`,children:[e.jsx(qr,{className:`w-4 h-4 ${n?"fill-current":""}`}),l.likes]})]}),e.jsx(_,{size:"sm",onClick:u,children:"查看详情"})]})})]})}var sl="Accordion",u3=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[px,m3,x3]=Bw(sl),[dd]=Yo(sl,[x3,dj]),gx=dj(),BN=As.forwardRef((l,n)=>{const{type:i,...c}=l,u=c,x=c;return e.jsx(px.Provider,{scope:l.__scopeAccordion,children:i==="multiple"?e.jsx(g3,{...x,ref:n}):e.jsx(p3,{...u,ref:n})})});BN.displayName=sl;var[IN,h3]=dd(sl),[PN,f3]=dd(sl,{collapsible:!1}),p3=As.forwardRef((l,n)=>{const{value:i,defaultValue:c,onValueChange:u=()=>{},collapsible:x=!1,...h}=l,[f,p]=Qo({prop:i,defaultProp:c??"",onChange:u,caller:sl});return e.jsx(IN,{scope:l.__scopeAccordion,value:As.useMemo(()=>f?[f]:[],[f]),onItemOpen:p,onItemClose:As.useCallback(()=>x&&p(""),[x,p]),children:e.jsx(PN,{scope:l.__scopeAccordion,collapsible:x,children:e.jsx(HN,{...h,ref:n})})})}),g3=As.forwardRef((l,n)=>{const{value:i,defaultValue:c,onValueChange:u=()=>{},...x}=l,[h,f]=Qo({prop:i,defaultProp:c??[],onChange:u,caller:sl}),p=As.useCallback(N=>f((v=[])=>[...v,N]),[f]),g=As.useCallback(N=>f((v=[])=>v.filter(b=>b!==N)),[f]);return e.jsx(IN,{scope:l.__scopeAccordion,value:h,onItemOpen:p,onItemClose:g,children:e.jsx(PN,{scope:l.__scopeAccordion,collapsible:!0,children:e.jsx(HN,{...x,ref:n})})})}),[j3,ud]=dd(sl),HN=As.forwardRef((l,n)=>{const{__scopeAccordion:i,disabled:c,dir:u,orientation:x="vertical",...h}=l,f=As.useRef(null),p=Jo(f,n),g=m3(i),v=kj(u)==="ltr",b=hn(l.onKeyDown,w=>{if(!u3.includes(w.key))return;const y=w.target,R=g().filter(J=>!J.ref.current?.disabled),O=R.findIndex(J=>J.ref.current===y),S=R.length;if(O===-1)return;w.preventDefault();let B=O;const E=0,C=S-1,z=()=>{B=O+1,B>C&&(B=E)},H=()=>{B=O-1,B{const{__scopeAccordion:i,value:c,...u}=l,x=ud(Ko,i),h=h3(Ko,i),f=gx(i),p=Um(),g=c&&h.value.includes(c)||!1,N=x.disabled||l.disabled;return e.jsx(v3,{scope:i,open:g,disabled:N,triggerId:p,children:e.jsx(lj,{"data-orientation":x.orientation,"data-state":YN(g),...f,...u,ref:n,disabled:N,open:g,onOpenChange:v=>{v?h.onItemOpen(c):h.onItemClose(c)}})})});FN.displayName=Ko;var GN="AccordionHeader",VN=As.forwardRef((l,n)=>{const{__scopeAccordion:i,...c}=l,u=ud(sl,i),x=jx(GN,i);return e.jsx(Yn.h3,{"data-orientation":u.orientation,"data-state":YN(x.open),"data-disabled":x.disabled?"":void 0,...c,ref:n})});VN.displayName=GN;var Gm="AccordionTrigger",qN=As.forwardRef((l,n)=>{const{__scopeAccordion:i,...c}=l,u=ud(sl,i),x=jx(Gm,i),h=f3(Gm,i),f=gx(i);return e.jsx(px.ItemSlot,{scope:i,children:e.jsx(hw,{"aria-disabled":x.open&&!h.collapsible||void 0,"data-orientation":u.orientation,id:x.triggerId,...f,...c,ref:n})})});qN.displayName=Gm;var KN="AccordionContent",QN=As.forwardRef((l,n)=>{const{__scopeAccordion:i,...c}=l,u=ud(sl,i),x=jx(KN,i),h=gx(i);return e.jsx(fw,{role:"region","aria-labelledby":x.triggerId,"data-orientation":u.orientation,...h,...c,ref:n,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...l.style}})});QN.displayName=KN;function YN(l){return l?"open":"closed"}var N3=BN,b3=FN,y3=VN,JN=qN,XN=QN;const w3=N3,ZN=d.forwardRef(({className:l,...n},i)=>e.jsx(b3,{ref:i,className:P("border-b",l),...n}));ZN.displayName="AccordionItem";const WN=d.forwardRef(({className:l,children:n,...i},c)=>e.jsx(y3,{className:"flex",children:e.jsxs(JN,{ref:c,className:P("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",l),...i,children:[n,e.jsx(Ma,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));WN.displayName=JN.displayName;const eb=d.forwardRef(({className:l,children:n,...i},c)=>e.jsx(XN,{ref:c,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...i,children:e.jsx("div",{className:P("pb-4 pt-0",l),children:n})}));eb.displayName=XN.displayName;const _3={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",lpmm_qa:"问答模型"};function S3(){const{packId:l}=nb.useParams(),n=ca(),[i,c]=d.useState(null),[u,x]=d.useState(!0),[h,f]=d.useState(!1),[p,g]=d.useState(!1),[N,v]=d.useState(!1),[b,w]=d.useState(1),[y,R]=d.useState(null),[O,S]=d.useState(!1),[B,E]=d.useState(!1),[C,z]=d.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}),[H,L]=d.useState({}),[J,U]=d.useState({}),oe=Mv(),Ne=d.useCallback(async()=>{if(l){x(!0);try{const M=await xS(l);c(M);const K=await Ev(l,oe);f(K)}catch(M){console.error("加载 Pack 失败:",M),Qt({title:"加载模板失败",variant:"destructive"})}finally{x(!1)}}},[l,oe]);d.useEffect(()=>{Ne()},[Ne]);const je=async()=>{if(!(!l||p)){g(!0);try{const M=await Tv(l,oe);f(M.liked),i&&c({...i,likes:M.likes})}catch(M){console.error("点赞失败:",M),Qt({title:"点赞失败",variant:"destructive"})}finally{g(!1)}}},re=async()=>{if(i){v(!0),w(1),S(!0);try{const M=await pS(i);R(M);const K={};for(const ue of M.existing_providers)K[ue.pack_provider.name]=ue.local_providers[0].name;L(K);const I={};for(const ue of M.new_providers)I[ue.name]="";U(I)}catch(M){console.error("检测冲突失败:",M),Qt({title:"检测配置冲突失败",variant:"destructive"}),v(!1)}finally{S(!1)}}},fe=async()=>{if(i){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(i,C,H,J),await fS(i.id,oe),c({...i,downloads:i.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 u?e.jsx(C3,{}):i?e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:()=>n({to:"/config/pack-market"}),className:"gap-2",children:[e.jsx(Ta,{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:[i.name,e.jsxs(ke,{variant:"secondary",children:["v",i.version]})]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:i.description})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(fn,{className:"w-4 h-4"}),i.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(na,{className:"w-4 h-4"}),ge(i.created_at)]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(sa,{className:"w-4 h-4"}),i.downloads," 次下载"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(qr,{className:`w-4 h-4 ${h?"fill-red-500 text-red-500":""}`}),i.likes," 赞"]})]}),i.tags&&i.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:i.tags.map(M=>e.jsxs(ke,{variant:"outline",children:[e.jsx(Wo,{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(sa,{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(qr,{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(Dl,{className:"w-8 h-8 text-blue-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:i.providers.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"API 提供商"})]})]})}),e.jsx(Ce,{children:e.jsxs(Me,{className:"flex items-center gap-3 py-4",children:[e.jsx(Vn,{className:"w-8 h-8 text-green-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:i.models.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"模型配置"})]})]})}),e.jsx(Ce,{children:e.jsxs(Me,{className:"flex items-center gap-3 py-4",children:[e.jsx(qn,{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(i.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(Xt,{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(Dl,{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:["(",i.providers.length,")"]})]}),e.jsxs(Xe,{value:"models",className:"gap-1 sm:gap-2",children:[e.jsx(Vn,{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:["(",i.models.length,")"]})]}),e.jsxs(Xe,{value:"tasks",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:["(",Object.keys(i.task_config).length,")"]})]})]}),e.jsx(ws,{value:"providers",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Re,{children:"API 提供商"}),e.jsx(os,{children:"模板中包含的 API 提供商配置(不含 API Key)"})]}),e.jsx(Me,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Rl,{children:[e.jsx(Ll,{children:e.jsxs(ut,{children:[e.jsx(We,{children:"名称"}),e.jsx(We,{children:"Base URL"}),e.jsx(We,{children:"类型"})]})}),e.jsx(Ul,{children:i.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(Re,{children:"模型配置"}),e.jsx(os,{children:"模板中包含的模型配置"})]}),e.jsx(Me,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Rl,{children:[e.jsx(Ll,{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(Ul,{children:i.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(Re,{children:"任务配置"}),e.jsx(os,{children:"模板中各任务类型的模型分配"})]}),e.jsx(Me,{children:e.jsx(w3,{type:"multiple",className:"w-full",children:Object.entries(i.task_config).map(([M,K])=>e.jsxs(ZN,{value:M,children:[e.jsx(WN,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pn,{className:"w-4 h-4"}),_3[M]||M,e.jsxs(ke,{variant:"secondary",className:"ml-2",children:[K.model_list.length," 个模型"]})]})}),e.jsx(eb,{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(I=>e.jsx(ke,{variant:"outline",children:I},I))}),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(k3,{open:N,onOpenChange:v,pack:i,step:b,setStep:w,conflicts:y,detectingConflicts:O,applying:B,options:C,setOptions:z,_providerMapping:H,_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(Ta,{className:"w-4 h-4 mr-2"}),"返回市场"]})]})}function k3({open:l,onOpenChange:n,pack:i,step:c,setStep:u,conflicts:x,detectingConflicts:h,applying:f,options:p,setOptions:g,_providerMapping:N,_setProviderMapping:v,newProviderApiKeys:b,setNewProviderApiKeys:w,onApply:y}){return e.jsx(Is,{open:l,onOpenChange:n,children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ds,{children:[e.jsxs(Rs,{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(Bs,{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:O=>g({...p,apply_providers:O})}),e.jsxs(T,{htmlFor:"apply_providers",className:"flex items-center gap-2",children:[e.jsx(Dl,{className:"w-4 h-4"}),"应用提供商配置 (",i.providers.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"apply_models",checked:p.apply_models,onCheckedChange:O=>g({...p,apply_models:O})}),e.jsxs(T,{htmlFor:"apply_models",className:"flex items-center gap-2",children:[e.jsx(Vn,{className:"w-4 h-4"}),"应用模型配置 (",i.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:O=>g({...p,apply_task_config:O})}),e.jsxs(T,{htmlFor:"apply_task_config",className:"flex items-center gap-2",children:[e.jsx(qn,{className:"w-4 h-4"}),"应用任务配置 (",Object.keys(i.task_config).length," 个)"]})]})]}),p.apply_task_config&&e.jsxs("div",{className:"pl-6 space-y-2 border-l-2 border-muted",children:[e.jsx(T,{className:"text-sm font-medium",children:"任务配置应用模式"}),e.jsxs(fx,{value:p.task_mode,onValueChange:O=>g({...p,task_mode:O}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qo,{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(qo,{value:"replace",id:"mode_replace"}),e.jsx(T,{htmlFor:"mode_replace",className:"font-normal",children:"替换模式 - 用模板配置完全替换现有配置"})]})]})]})]}),c===2&&x&&e.jsxs("div",{className:"space-y-4",children:[p.apply_providers&&x.existing_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(at,{children:[e.jsx(Ht,{className:"h-4 w-4"}),e.jsx(Hn,{children:"发现已有的提供商"}),e.jsx(lt,{children:"以下提供商的 URL 与您本地配置中的提供商匹配,将自动使用本地提供商:"})]}),e.jsx("div",{className:"space-y-2",children:x.existing_providers.map(({pack_provider:O,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:O.name}),e.jsx(Zt,{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[O.name]||S[0].name,onValueChange:B=>v({...N,[O.name]:B}),children:[e.jsx($e,{className:"w-[200px]",children:e.jsx(Pe,{})}),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," 个匹配"]})]})]},O.name))})]}),p.apply_providers&&x.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(Hn,{children:"需要配置 API Key"}),e.jsx(lt,{children:"以下提供商在您的本地配置中不存在,需要填写 API Key:"})]}),e.jsx("div",{className:"space-y-4",children:x.new_providers.map(O=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qm,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"font-medium",children:O.name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",O.base_url,")"]})]}),e.jsx(ae,{type:"password",placeholder:`输入 ${O.name} 的 API Key`,value:b[O.name]||"",onChange:S=>w({...b,[O.name]:S.target.value})})]},O.name))})]}),(!p.apply_providers||x.existing_providers.length===0&&x.new_providers.length===0)&&e.jsxs(at,{children:[e.jsx(Ct,{className:"h-4 w-4"}),e.jsx(Hn,{children:"无需配置"}),e.jsx(lt,{children:"模板中没有提供商配置,或您选择不应用提供商。"})]})]}),c===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{children:[e.jsx(Ht,{className:"h-4 w-4"}),e.jsx(Hn,{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(Dl,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",i.providers.length," 个提供商配置"]})]}),p.apply_models&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500"}),e.jsx(Vn,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",i.models.length," 个模型配置"]})]}),p.apply_task_config&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500"}),e.jsx(qn,{className:"w-4 h-4"}),e.jsxs("span",{children:[p.task_mode==="append"?"追加":"替换"," ",Object.keys(i.task_config).length," 个任务配置"]})]})]}),x&&x.new_providers.length>0&&e.jsxs(at,{variant:"destructive",children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(lt,{children:["将添加 ",x.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:()=>u(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:()=>u(c+1),disabled:h,children:"下一步"}):e.jsxs(_,{onClick:y,disabled:f,children:[f&&e.jsx(Bs,{className:"w-4 h-4 mr-2 animate-spin"}),"应用模板"]})]})]})]})})}function C3(){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 T3(){const l=ca(),[n,i]=d.useState(!0);return d.useEffect(()=>{let c=!1;return(async()=>{try{const x=await ac();!c&&!x&&l({to:"/auth"})}catch{c||l({to:"/auth"})}finally{c||i(!1)}})(),()=>{c=!0}},[l]),{checking:n}}async function E3(){return await ac()}const M3=Qr("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"}}),sb=d.forwardRef(({className:l,size:n,abbrTitle:i,children:c,...u},x)=>e.jsx("kbd",{className:P(M3({size:n,className:l})),ref:x,...u,children:i?e.jsx("abbr",{title:i,children:c}):c}));sb.displayName="Kbd";const z3=[{icon:Zo,title:"首页",description:"查看仪表板概览",path:"/",category:"概览"},{icon:Ca,title:"麦麦主程序配置",description:"配置麦麦的核心设置",path:"/config/bot",category:"配置"},{icon:Dl,title:"麦麦模型提供商配置",description:"配置模型提供商",path:"/config/modelProvider",category:"配置"},{icon:Vj,title:"麦麦模型配置",description:"配置模型参数",path:"/config/model",category:"配置"},{icon:Xo,title:"表情包管理",description:"管理麦麦的表情包",path:"/resource/emoji",category:"资源"},{icon:za,title:"表达方式管理",description:"管理麦麦的表达方式",path:"/resource/expression",category:"资源"},{icon:qj,title:"人物信息管理",description:"管理人物信息",path:"/resource/person",category:"资源"},{icon:Vr,title:"黑话管理",description:"管理麦麦学习到的黑话和俚语",path:"/resource/jargon",category:"资源"},{icon:b_,title:"统计信息",description:"查看使用统计",path:"/statistics",category:"监控"},{icon:ra,title:"插件市场",description:"浏览和安装插件",path:"/plugins",category:"扩展"},{icon:Ym,title:"日志查看器",description:"查看系统日志",path:"/logs",category:"监控"},{icon:pn,title:"系统设置",description:"配置系统参数",path:"/settings",category:"系统"}];function A3({open:l,onOpenChange:n}){const[i,c]=d.useState(""),[u,x]=d.useState(0),h=ca(),f=z3.filter(N=>N.title.toLowerCase().includes(i.toLowerCase())||N.description.toLowerCase().includes(i.toLowerCase())||N.category.toLowerCase().includes(i.toLowerCase())),p=d.useCallback(N=>{h({to:N}),n(!1),c(""),x(0)},[h,n]),g=d.useCallback(N=>{N.key==="ArrowDown"?(N.preventDefault(),x(v=>(v+1)%f.length)):N.key==="ArrowUp"?(N.preventDefault(),x(v=>(v-1+f.length)%f.length)):N.key==="Enter"&&f[u]&&(N.preventDefault(),p(f[u].path))},[f,u,p]);return e.jsx(Is,{open:l,onOpenChange:n,children:e.jsxs(Os,{className:"max-w-2xl p-0 gap-0",children:[e.jsxs(Ds,{className:"px-4 pt-4 pb-0",children:[e.jsx(Rs,{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:i,onChange:N=>{c(N.target.value),x(0)},onKeyDown:g,placeholder:"搜索页面...",className:"h-12 pl-11 text-base border-0 focus-visible:ring-0 shadow-none",autoFocus:!0})]})]}),e.jsx("div",{className:"border-t",children:e.jsx(Je,{className:"h-[400px]",children:f.length>0?e.jsx("div",{className:"p-2",children:f.map((N,v)=>{const b=N.icon;return e.jsxs("button",{onClick:()=>p(N.path),onMouseEnter:()=>x(v),className:P("w-full flex items-center gap-3 px-3 py-2.5 rounded-md text-left transition-colors",v===u?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[e.jsx(b,{className:"h-5 w-5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children: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:i?"未找到匹配的页面":"输入关键词开始搜索"})]})})}),e.jsx("div",{className:"border-t px-4 py-3 flex items-center justify-between text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↑"}),e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↓"}),"导航"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Enter"}),"选择"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Esc"}),"关闭"]})]})})]})})}function O3(){const l=window.location.protocol==="http:",n=window.location.hostname.toLowerCase(),i=n==="localhost"||n==="127.0.0.1"||n==="::1",c=sessionStorage.getItem("http-warning-dismissed")==="true",[u,x]=d.useState(l&&!i&&!c),[h,f]=d.useState(!1),p=()=>{f(!0),x(!1),sessionStorage.setItem("http-warning-dismissed","true")};return!u||h?null:e.jsx("div",{className:"relative bg-amber-500/10 border-b border-amber-500/20 backdrop-blur-sm",children:e.jsx("div",{className:"container mx-auto px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx(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(Ea,{className:"h-4 w-4"})})]})})})}function D3(){const[l,n]=d.useState(0),[i,c]=d.useState(!1),u=d.useRef(null);d.useEffect(()=>{const g=N=>{const v=N.target;if(v.scrollHeight>v.clientHeight+100){u.current=v;const b=v.scrollTop,w=v.scrollHeight-v.clientHeight,y=w>0?b/w*100:0;n(y),c(b>300)}};return window.addEventListener("scroll",g,{capture:!0,passive:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})},[]);const x=()=>{u.current?.scrollTo({top:0,behavior:"smooth"})},h=18,f=2*Math.PI*h,p=f-l/100*f;return e.jsx("div",{className:P("fixed bottom-24 right-8 z-50 transition-all duration-500 ease-in-out transform",i?"translate-x-0 opacity-100":"translate-x-32 opacity-0 pointer-events-none"),children:e.jsxs(_,{variant:"outline",size:"icon",className:P("relative h-12 w-12 rounded-full shadow-xl","bg-background/80 backdrop-blur-md border-border/50","hover:bg-accent hover:scale-110 hover:shadow-2xl hover:border-primary/50","transition-all duration-300","group"),onClick:x,"aria-label":"回到顶部",children:[e.jsxs("svg",{className:"absolute inset-0 h-full w-full -rotate-90 transform p-1",viewBox:"0 0 44 44",children:[e.jsx("circle",{className:"text-muted-foreground/10",strokeWidth:"3",stroke:"currentColor",fill:"transparent",r:h,cx:"22",cy:"22"}),e.jsx("circle",{className:"text-primary transition-all duration-100 ease-out",strokeWidth:"3",strokeDasharray:f,strokeDashoffset:p,strokeLinecap:"round",stroke:"currentColor",fill:"transparent",r:h,cx:"22",cy:"22"})]}),e.jsx(y_,{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 R3=Pw,L3=Hw,U3=Fw,tb=d.forwardRef(({className:l,sideOffset:n=4,...i},c)=>e.jsx(Iw,{children:e.jsx(Cj,{ref:c,sideOffset:n,className:P("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",l),...i})}));tb.displayName=Cj.displayName;function $3({children:l}){const{checking:n}=T3(),[i,c]=d.useState(!0),[u,x]=d.useState(!1),[h,f]=d.useState(!1),[p,g]=d.useState(!1),{theme:N,setTheme:v}=ax(),b=w0();if(d.useEffect(()=>{if(i)g(!1);else{const S=setTimeout(()=>{g(!0)},350);return()=>clearTimeout(S)}},[i]),d.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 w=[{title:"概览",items:[{icon:Zo,label:"首页",path:"/"}]},{title:"麦麦配置编辑",items:[{icon:Ca,label:"麦麦主程序配置",path:"/config/bot"},{icon:Dl,label:"AI模型厂商配置",path:"/config/modelProvider",tourId:"sidebar-model-provider"},{icon:Vj,label:"模型管理与分配",path:"/config/model",tourId:"sidebar-model-management"},{icon:mg,label:"麦麦适配器配置",path:"/config/adapter"}]},{title:"麦麦资源管理",items:[{icon:Xo,label:"表情包管理",path:"/resource/emoji"},{icon:za,label:"表达方式管理",path:"/resource/expression"},{icon:Vr,label:"黑话管理",path:"/resource/jargon"},{icon:qj,label:"人物信息管理",path:"/resource/person"},{icon:Pj,label:"知识库图谱可视化",path:"/resource/knowledge-graph"},{icon:Gr,label:"麦麦知识库管理",path:"/resource/knowledge-base"}]},{title:"扩展与监控",items:[{icon:ra,label:"插件市场",path:"/plugins"},{icon:Fj,label:"配置模板市场",path:"/config/pack-market"},{icon:mg,label:"插件配置",path:"/plugin-config"},{icon:Ym,label:"日志查看器",path:"/logs"},{icon:Vm,label:"计划器&回复器监控",path:"/planner-monitor"},{icon:za,label:"本地聊天室",path:"/chat"}]},{title:"系统",items:[{icon:pn,label:"系统设置",path:"/settings"}]}],R=N==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":N,O=async()=>{await l1()};return e.jsx(R3,{delayDuration:300,children:e.jsxs("div",{className:"flex h-screen overflow-hidden",children:[e.jsxs("aside",{className:P("fixed inset-y-0 left-0 z-50 flex flex-col border-r bg-card transition-all duration-300 lg:relative lg:z-0","w-64 lg:w-auto",i?"lg:w-64":"lg:w-16",u?"translate-x-0":"-translate-x-full lg:translate-x-0"),children:[e.jsx("div",{className:"flex h-16 items-center border-b px-4",children:e.jsxs("div",{className:P("relative flex items-center justify-center flex-1 transition-all overflow-hidden","lg:flex-1",!i&&"lg:flex-none lg:w-8"),children:[e.jsxs("div",{className:P("flex items-baseline gap-2",!i&&"lg:hidden"),children:[e.jsx("span",{className:"font-bold text-xl text-primary-gradient whitespace-nowrap",children:"MaiBot WebUI"}),e.jsx("span",{className:"text-xs text-primary/60 whitespace-nowrap",children:B1()})]}),!i&&e.jsx("span",{className:"hidden lg:block font-bold text-primary-gradient text-2xl",children:"M"})]})}),e.jsx(Je,{className:P("flex-1 overflow-x-hidden",!i&&"lg:w-16"),children:e.jsx("nav",{className:P("p-4",!i&&"lg:p-2 lg:w-16"),children:e.jsx("ul",{className:P("space-y-6",!i&&"lg:space-y-3 lg:w-full"),children:w.map((S,B)=>e.jsxs("li",{children:[e.jsx("div",{className:P("px-3 h-[1.25rem]","mb-2",!i&&"lg:mb-1 lg:invisible"),children:e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground/60 whitespace-nowrap",children:S.title})}),!i&&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=b({to:E.path}),z=E.icon,H=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:P("flex items-center transition-all duration-300",i?"gap-3":"gap-3 lg:gap-0"),children:[e.jsx(z,{className:P("h-5 w-5 flex-shrink-0",C&&"text-primary"),strokeWidth:2,fill:"none"}),e.jsx("span",{className:P("text-sm font-medium whitespace-nowrap transition-all duration-300",C&&"font-semibold",i?"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(L3,{children:[e.jsx(U3,{asChild:!0,children:e.jsx(Bn,{to:E.path,"data-tour":E.tourId,className:P("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",i?"px-3":"px-3 lg:px-0 lg:justify-center lg:w-12 lg:mx-auto"),onClick:()=>x(!1),children:H})}),p&&e.jsx(tb,{side:"right",className:"hidden lg:block",children:e.jsx("p",{children:E.label})})]})},E.path)})})]},S.title))})})})]}),u&&e.jsx("div",{className:"fixed inset-0 z-40 bg-black/50 lg:hidden",onClick:()=>x(!1)}),e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(O3,{}),e.jsxs("header",{className:"flex h-16 items-center justify-between border-b bg-card/80 backdrop-blur-md px-4 sticky top-0 z-10",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:()=>x(!u),className:"rounded-lg p-2 hover:bg-accent lg:hidden",children:e.jsx(w_,{className:"h-5 w-5"})}),e.jsx("button",{onClick:()=>c(!i),className:"hidden rounded-lg p-2 hover:bg-accent lg:block",title:i?"收起侧边栏":"展开侧边栏",children:e.jsx(Aa,{className:P("h-5 w-5 transition-transform",!i&&"rotate-180")})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Bn,{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(__,{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(sb,{size:"sm",className:"absolute right-2 top-1/2 -translate-y-1/2",children:[e.jsx("span",{className:"text-xs",children:"⌘"}),"K"]})]}),e.jsx(A3,{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(S_,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"麦麦文档"})]}),e.jsx("button",{onClick:S=>{D1(R==="dark"?"light":"dark",v,S)},className:"rounded-lg p-2 hover:bg-accent",title:R==="dark"?"切换到浅色模式":"切换到深色模式",children:R==="dark"?e.jsx(Km,{className:"h-5 w-5"}):e.jsx(Yi,{className:"h-5 w-5"})}),e.jsx("div",{className:"h-6 w-px bg-border"}),e.jsxs(_,{variant:"ghost",size:"sm",onClick:O,className:"gap-2",title:"登出系统",children:[e.jsx(k_,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"登出"})]})]})]}),e.jsx("main",{className:"flex-1 overflow-hidden bg-background",children:l}),e.jsx(D3,{})]})]})})}function B3(l){const n=l.split(` +`),Se=new Blob([Q],{type:"text/plain;charset=utf-8"}),pe=URL.createObjectURL(Se),Te=document.createElement("a");Te.href=pe,Te.download=`logs-${Nm(new Date,"yyyy-MM-dd-HHmmss")}.txt`,Te.click(),URL.revokeObjectURL(pe)},re=()=>{w(!b)},fe=()=>{g(void 0),v(void 0)},ge=d.useMemo(()=>l.filter(Q=>{const Se=i===""||Q.message.toLowerCase().includes(i.toLowerCase())||Q.module.toLowerCase().includes(i.toLowerCase()),pe=u==="all"||Q.level===u,Te=h==="all"||Q.module===h;let A=!0;if(p||N){const D=new Date(Q.timestamp);if(p){const V=new Date(p);V.setHours(0,0,0,0),A=A&&D>=V}if(N){const V=new Date(N);V.setHours(23,59,59,999),A=A&&D<=V}}return Se&&pe&&Te&&A}),[l,i,u,h,p,N]),M=Mo[O].rowHeight+B,K=b0({count:ge.length,getScrollElement:()=>H.current,estimateSize:()=>M,overscan:50}),I=d.useRef(!1),ue=d.useRef(ge.length);return d.useEffect(()=>{const Q=H.current;if(!Q)return;const Se=()=>{if(I.current)return;const{scrollTop:pe,scrollHeight:Te,clientHeight:A}=Q,D=Te-pe-A;D>100&&b?w(!1):D<50&&!b&&w(!0)};return Q.addEventListener("scroll",Se,{passive:!0}),()=>Q.removeEventListener("scroll",Se)},[b]),d.useEffect(()=>{const Q=ge.length>ue.current;ue.current=ge.length,b&&ge.length>0&&Q&&(I.current=!0,K.scrollToIndex(ge.length-1,{align:"end",behavior:"auto"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{I.current=!1})}))},[ge.length,b,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:P("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(rc,{open:C,onOpenChange:z,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:i,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:b?"default":"outline",size:"sm",onClick:re,className:"h-8 px-2",title:b?"自动滚动":"已暂停",children:[b?e.jsx(r_,{className:"h-3.5 w-3.5"}):e.jsx(i_,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden sm:inline",children:b?"滚动":"暂停"})]}),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(sa,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden lg:inline",children:"导出"})]}),e.jsx(ic,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"h-8 px-2",title:C?"收起筛选":"展开筛选",children:[e.jsx(Do,{className:"h-3.5 w-3.5"}),C?e.jsx(Fr,{className:"h-3.5 w-3.5 ml-1"}):e.jsx(Ma,{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," / ",l.length]}),e.jsx("span",{className:"ml-1",children:"条日志"})]}),e.jsxs(cc,{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:u,onValueChange:x,children:[e.jsxs($e,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(Do,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Pe,{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(Ie,{value:h,onValueChange:f,children:[e.jsxs($e,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(Do,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(Pe,{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(ol,{children:[e.jsx(dl,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:P("w-full sm:flex-1 justify-start text-left font-normal h-8",!p&&"text-muted-foreground"),children:[e.jsx(Io,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:p?Nm(p,"PP",{locale:To}):"开始日期"})]})}),e.jsx(Wa,{className:"w-auto p-0",align:"start",children:e.jsx($g,{mode:"single",selected:p,onSelect:g,initialFocus:!0,locale:To})})]}),e.jsxs(ol,{children:[e.jsx(dl,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:P("w-full sm:flex-1 justify-start text-left font-normal h-8",!N&&"text-muted-foreground"),children:[e.jsx(Io,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:N?Nm(N,"PP",{locale:To}):"结束日期"})]})}),e.jsx(Wa,{className:"w-auto p-0",align:"start",children:e.jsx($g,{mode:"single",selected:N,onSelect:v,initialFocus:!0,locale:To})})]}),(p||N)&&e.jsxs(_,{variant:"outline",size:"sm",onClick:fe,className:"w-full sm:w-auto h-8",children:[e.jsx(Ea,{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(c_,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"字号"})]}),e.jsx("div",{className:"flex gap-1",children:Object.keys(Mo).map(Q=>e.jsx(_,{variant:O===Q?"default":"outline",size:"sm",onClick:()=>S(Q),className:"h-6 px-2 text-xs",children:Mo[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(sa,{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:H,className:P("h-full overflow-auto","[&::-webkit-scrollbar]:w-2.5","[&::-webkit-scrollbar-track]:bg-transparent","[&::-webkit-scrollbar-thumb]:bg-border [&::-webkit-scrollbar-thumb]:rounded-full","[&::-webkit-scrollbar-thumb:hover]:bg-border/80"),children:e.jsx("div",{className:P("p-2 sm:p-3 font-mono relative",Mo[O].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:P("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:P("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:P("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 dk(){return(await _e("/api/planner/overview")).json()}async function uk(l,n=1,i=20,c){const u=new URLSearchParams({page:n.toString(),page_size:i.toString()});return c&&u.append("search",c),(await _e(`/api/planner/chat/${l}/logs?${u}`)).json()}async function mk(l,n){return(await _e(`/api/planner/log/${l}/${n}`)).json()}async function xk(){return(await _e("/api/replier/overview")).json()}async function hk(l,n=1,i=20,c){const u=new URLSearchParams({page:n.toString(),page_size:i.toString()});return c&&u.append("search",c),(await _e(`/api/replier/chat/${l}/logs?${u}`)).json()}async function fk(l,n){return(await _e(`/api/replier/log/${l}/${n}`)).json()}function $v(){const[l,n]=d.useState(new Map),[i,c]=d.useState(!0),u=d.useCallback(async()=>{try{c(!0);const h=await sx();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)}},[]);d.useEffect(()=>{u()},[u]);const x=d.useCallback(h=>l.get(h)||h,[l]);return{chatNameMap:l,getChatName:x,loading:i,reload:u}}function Vo(l){return new Date(l*1e3).toLocaleString("zh-CN")}function Bv(l){const i=Date.now()/1e3-l;return i<60?"刚刚":i<3600?`${Math.floor(i/60)} 分钟前`:i<86400?`${Math.floor(i/3600)} 小时前`:`${Math.floor(i/86400)} 天前`}function Iv(l,n,i=1e4){d.useEffect(()=>{if(!l)return;const c=setInterval(n,i);return()=>clearInterval(c)},[l,n,i])}function pk({autoRefresh:l,refreshKey:n}){const[i,c]=d.useState("overview"),[u,x]=d.useState(null),{getChatName:h}=$v(),[f,p]=d.useState(null),[g,N]=d.useState(!0),[v,b]=d.useState(null),[w,y]=d.useState(!1),[R,O]=d.useState(1),[S,B]=d.useState(20),[E,C]=d.useState(""),[z,H]=d.useState(""),[L,J]=d.useState(""),[U,oe]=d.useState(null),[Ne,je]=d.useState(!1),[re,fe]=d.useState(!1),ge=d.useCallback(async()=>{try{N(!0);const D=await dk();p(D)}catch(D){console.error("加载规划器总览失败:",D)}finally{N(!1)}},[]),M=d.useCallback(async()=>{if(u)try{y(!0);const D=await uk(u.chat_id,R,S,z||void 0);b(D)}catch(D){console.error("加载聊天日志失败:",D)}finally{y(!1)}},[u,R,S,z]);d.useEffect(()=>{ge()},[ge]),d.useEffect(()=>{n>0&&(i==="overview"?ge():M())},[n,i,ge,M]),d.useEffect(()=>{i==="chat-logs"&&u&&M()},[i,u,M]),Iv(l,d.useCallback(()=>{i==="overview"?ge():M()},[i,ge,M]));const K=D=>{x(D),O(1),H(""),J(""),c("chat-logs")},I=()=>{c("overview"),x(null),b(null),H(""),J("")},ue=()=>{H(L),O(1)},Q=()=>{J(""),H(""),O(1)},Se=async(D,V)=>{try{fe(!0),je(!0);const de=await mk(D,V);oe(de)}catch(de){console.error("加载计划详情失败:",de)}finally{fe(!1)}},pe=D=>{B(Number(D)),O(1)},Te=()=>{const D=parseInt(E),V=v?Math.ceil(v.total/v.page_size):0;!isNaN(D)&&D>=1&&D<=V&&(O(D),C(""))},A=v?Math.ceil(v.total/v.page_size):0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:i==="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(Re,{className:"text-sm font-medium",children:"聊天数量"}),e.jsx(za,{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(Re,{className:"text-sm font-medium",children:"计划总数"}),e.jsx(qm,{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(Re,{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,V)=>e.jsx(vs,{className:"h-24 w-full"},V))}):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(za,{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:["最后活动: ",Bv(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:I,children:[e.jsx(Ta,{className:"h-4 w-4 mr-2"}),"返回聊天列表"]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["当前聊天: ",e.jsx("span",{className:"font-medium",children:u?h(u.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(Re,{children:"计划执行记录"}),e.jsx(os,{children:u?h(u.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"})}),z&&e.jsx(_,{variant:"ghost",size:"sm",onClick:Q,children:"清除"})]}),e.jsxs(Ie,{value:S.toString(),onValueChange:pe,children:[e.jsx($e,{className:"w-full sm:w-32",children:e.jsx(Pe,{})}),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条/页"})]})]})]})]}),z&&e.jsxs("div",{className:"text-sm text-muted-foreground mt-2",children:["搜索关键词: ",e.jsxs("span",{className:"font-medium",children:['"',z,'"']})]})]}),e.jsx(Me,{children:w?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((D,V)=>e.jsx(vs,{className:"h-20 w-full"},V))}):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:Vo(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((V,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:V},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," 条记录,第 ",R," / ",A," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(1),disabled:R===1,className:"hidden sm:flex",children:e.jsx(gn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(D=>Math.max(1,D-1)),disabled:R===1,children:e.jsx(Aa,{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:A,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:[R,"/",A]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(D=>Math.min(A,D+1)),disabled:R===A,children:e.jsx(Zt,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(A),disabled:R===A,className:"hidden sm:flex",children:e.jsx(jn,{className:"h-4 w-4"})})]})]})]}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无计划记录"})})]})]})}),e.jsx(Is,{open:Ne,onOpenChange:je,children:e.jsxs(Os,{className:"max-w-4xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Ds,{children:[e.jsxs(Rs,{className:"flex items-center gap-2",children:[e.jsx(Ca,{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,V)=>e.jsx(vs,{className:"h-24 w-full"},V))}):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:Vo(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(Za,{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(Re,{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(Re,{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(Re,{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(Zm,{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(o_,{className:"h-4 w-4"}),"执行动作 (",U.actions.length,")"]}),e.jsx("div",{className:"space-y-3",children:U.actions.map((D,V)=>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:["动作 ",V+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)})]})]})]},V))})]}),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:l,refreshKey:n}){const[i,c]=d.useState("overview"),[u,x]=d.useState(null),{getChatName:h}=$v(),[f,p]=d.useState(null),[g,N]=d.useState(!0),[v,b]=d.useState(null),[w,y]=d.useState(!1),[R,O]=d.useState(1),[S,B]=d.useState(20),[E,C]=d.useState(""),[z,H]=d.useState(""),[L,J]=d.useState(""),[U,oe]=d.useState(null),[Ne,je]=d.useState(!1),[re,fe]=d.useState(!1),ge=d.useCallback(async()=>{try{N(!0);const D=await xk();p(D)}catch(D){console.error("加载回复器总览失败:",D)}finally{N(!1)}},[]),M=d.useCallback(async()=>{if(u)try{y(!0);const D=await hk(u.chat_id,R,S,z||void 0);b(D)}catch(D){console.error("加载聊天日志失败:",D)}finally{y(!1)}},[u,R,S,z]);d.useEffect(()=>{ge()},[ge]),d.useEffect(()=>{n>0&&(i==="overview"?ge():M())},[n,i,ge,M]),d.useEffect(()=>{i==="chat-logs"&&u&&M()},[i,u,M]),Iv(l,d.useCallback(()=>{i==="overview"?ge():M()},[i,ge,M]));const K=D=>{x(D),O(1),H(""),J(""),c("chat-logs")},I=()=>{c("overview"),x(null),b(null),H(""),J("")},ue=()=>{H(L),O(1)},Q=()=>{J(""),H(""),O(1)},Se=async(D,V)=>{try{fe(!0),je(!0);const de=await fk(D,V);oe(de)}catch(de){console.error("加载回复详情失败:",de)}finally{fe(!1)}},pe=D=>{B(Number(D)),O(1)},Te=()=>{const D=parseInt(E),V=v?Math.ceil(v.total/v.page_size):0;!isNaN(D)&&D>=1&&D<=V&&(O(D),C(""))},A=v?Math.ceil(v.total/v.page_size):0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:i==="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(Re,{className:"text-sm font-medium",children:"聊天数量"}),e.jsx(za,{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(Re,{className:"text-sm font-medium",children:"回复总数"}),e.jsx(qm,{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(Re,{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,V)=>e.jsx(vs,{className:"h-24 w-full"},V))}):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(za,{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:["最后活动: ",Bv(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:I,children:[e.jsx(Ta,{className:"h-4 w-4 mr-2"}),"返回聊天列表"]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["当前聊天: ",e.jsx("span",{className:"font-medium",children:u?h(u.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(Re,{children:"回复生成记录"}),e.jsx(os,{children:u?h(u.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"})}),z&&e.jsx(_,{variant:"ghost",size:"sm",onClick:Q,children:"清除"})]}),e.jsxs(Ie,{value:S.toString(),onValueChange:pe,children:[e.jsx($e,{className:"w-full sm:w-32",children:e.jsx(Pe,{})}),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条/页"})]})]})]})]}),z&&e.jsxs("div",{className:"text-sm text-muted-foreground mt-2",children:["搜索关键词: ",e.jsxs("span",{className:"font-medium",children:['"',z,'"']})]})]}),e.jsx(Me,{children:w?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((D,V)=>e.jsx(vs,{className:"h-20 w-full"},V))}):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:Vo(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(dg,{className:"h-3 w-3 mr-1"}),"成功"]}):e.jsxs(ke,{variant:"destructive",className:"text-xs",children:[e.jsx(Va,{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," 条记录,第 ",R," / ",A," 页"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(1),disabled:R===1,className:"hidden sm:flex",children:e.jsx(gn,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(D=>Math.max(1,D-1)),disabled:R===1,children:e.jsx(Aa,{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:A,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:[R,"/",A]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(D=>Math.min(A,D+1)),disabled:R===A,children:e.jsx(Zt,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>O(A),disabled:R===A,className:"hidden sm:flex",children:e.jsx(jn,{className:"h-4 w-4"})})]})]})]}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"暂无回复记录"})})]})]})}),e.jsx(Is,{open:Ne,onOpenChange:je,children:e.jsxs(Os,{className:"max-w-4xl max-h-[80vh] grid grid-rows-[auto_1fr_auto] overflow-hidden",children:[e.jsxs(Ds,{children:[e.jsxs(Rs,{className:"flex items-center gap-2",children:[e.jsx(Ca,{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,V)=>e.jsx(vs,{className:"h-24 w-full"},V))}):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:Vo(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(dg,{className:"h-3 w-3 mr-1"}),"成功"]}):e.jsxs(ke,{variant:"destructive",children:[e.jsx(Va,{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(d_,{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(Za,{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(Re,{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(Re,{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(Re,{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,V)=>e.jsx("div",{className:"text-xs text-muted-foreground",children:D},V))})]}),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(Zm,{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,V)=>e.jsx("div",{className:"p-3 bg-muted/30 rounded-lg",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:D})},V))})]})]}),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 jk(){const[l,n]=d.useState("planner"),[i,c]=d.useState(!1),[u,x]=d.useState(0),h=d.useCallback(()=>{x(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:i?"default":"outline",size:"sm",onClick:()=>c(!i),children:[e.jsx(dt,{className:`h-4 w-4 mr-2 ${i?"animate-spin":""}`}),i?"自动刷新中":"自动刷新"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:h,children:e.jsx(dt,{className:"h-4 w-4"})})]})]}),e.jsxs(ta,{value:l,onValueChange:f=>n(f),className:"w-full",children:[e.jsxs(Xt,{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(Vm,{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(u_,{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(pk,{autoRefresh:i,refreshKey:u})}),e.jsx(ws,{value:"replier",className:"mt-0",children:e.jsx(gk,{autoRefresh:i,refreshKey:u})})]})]})]})}const vk="Mai-with-u",Nk="plugin-repo",bk="main",yk="plugin_details.json";async function wk(){try{const l=await _e("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:vk,repo:Nk,branch:bk,file_path:yk})});if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const n=await l.json();if(!n.success||!n.data)throw new Error(n.error||"获取插件列表失败");return JSON.parse(n.data).filter(u=>!u?.id||!u?.manifest?(console.warn("跳过无效插件数据:",u),!1):!u.manifest.name||!u.manifest.version?(console.warn("跳过缺少必需字段的插件:",u.id),!1):!0).map(u=>({id:u.id,manifest:{manifest_version:u.manifest.manifest_version||1,name:u.manifest.name,version:u.manifest.version,description:u.manifest.description||"",author:u.manifest.author||{name:"Unknown"},license:u.manifest.license||"Unknown",host_application:u.manifest.host_application||{min_version:"0.0.0"},homepage_url:u.manifest.homepage_url,repository_url:u.manifest.repository_url,keywords:u.manifest.keywords||[],categories:u.manifest.categories||[],default_locale:u.manifest.default_locale||"zh-CN",locales_path:u.manifest.locales_path},downloads:0,rating:0,review_count:0,installed:!1,published_at:new Date().toISOString(),updated_at:new Date().toISOString()}))}catch(l){throw console.error("Failed to fetch plugin list:",l),l}}async function Pv(){try{const l=await _e("/api/webui/plugins/git-status");if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return await l.json()}catch(l){return console.error("Failed to check Git status:",l),{installed:!1,error:"无法检测 Git 安装状态"}}}async function Hv(){try{const l=await _e("/api/webui/plugins/version");if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return await l.json()}catch(l){return console.error("Failed to get Maimai version:",l),{version:"0.0.0",version_major:0,version_minor:0,version_patch:0}}}function Fv(l,n,i){const c=l.split(".").map(f=>parseInt(f)||0),u=c[0]||0,x=c[1]||0,h=c[2]||0;if(i.version_majorparseInt(v)||0),p=f[0]||0,g=f[1]||0,N=f[2]||0;if(i.version_major>p||i.version_major===p&&i.version_minor>g||i.version_major===p&&i.version_minor===g&&i.version_patch>N)return!1}return!0}async function _k(){try{const l=await _e("/api/webui/ws-token");if(!l.ok)return console.error("获取 WebSocket token 失败:",l.status),null;const n=await l.json();return n.success&&n.token?n.token:null}catch(l){return console.error("获取 WebSocket token 失败:",l),null}}async function Sk(l,n){const i=await _k();if(!i)return console.warn("无法获取 WebSocket token,可能未登录"),null;const c=window.location.protocol==="https:"?"wss:":"ws:",u=window.location.host,x=`${c}//${u}/api/webui/ws/plugin-progress?token=${encodeURIComponent(i)}`;try{const h=new WebSocket(x);return h.onopen=()=>{console.log("Plugin progress WebSocket connected");const f=setInterval(()=>{h.readyState===WebSocket.OPEN?h.send("ping"):clearInterval(f)},3e4)},h.onmessage=f=>{try{if(f.data==="pong")return;const p=JSON.parse(f.data);l(p)}catch(p){console.error("Failed to parse progress data:",p)}},h.onerror=f=>{console.error("Plugin progress WebSocket error:",f),n?.(f)},h.onclose=()=>{console.log("Plugin progress WebSocket disconnected")},h}catch(h){return console.error("创建 WebSocket 连接失败:",h),null}}async function Al(){try{const l=await _e("/api/webui/plugins/installed",{headers:Fs()});if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const n=await l.json();if(!n.success)throw new Error(n.message||"获取已安装插件列表失败");return n.plugins||[]}catch(l){return console.error("Failed to get installed plugins:",l),[]}}function mn(l,n){return n.some(i=>i.id===l)}function xn(l,n){const i=n.find(c=>c.id===l);if(i)return i.manifest?.version||i.version}async function Gv(l,n,i="main"){const c=await _e("/api/webui/plugins/install",{method:"POST",body:JSON.stringify({plugin_id:l,repository_url:n,branch:i})});if(!c.ok){const u=await c.json();throw new Error(u.detail||"安装失败")}return await c.json()}async function Vv(l){const n=await _e("/api/webui/plugins/uninstall",{method:"POST",body:JSON.stringify({plugin_id:l})});if(!n.ok){const i=await n.json();throw new Error(i.detail||"卸载失败")}return await n.json()}async function qv(l,n,i="main"){const c=await _e("/api/webui/plugins/update",{method:"POST",body:JSON.stringify({plugin_id:l,repository_url:n,branch:i})});if(!c.ok){const u=await c.json();throw new Error(u.detail||"更新失败")}return await c.json()}async function kk(l){const n=await _e(`/api/webui/plugins/config/${l}/schema`,{headers:Fs()});if(!n.ok){const c=await n.text();try{const u=JSON.parse(c);throw new Error(u.detail||"获取配置 Schema 失败")}catch{throw new Error(`获取配置 Schema 失败 (${n.status})`)}}const i=await n.json();if(!i.success)throw new Error(i.message||"获取配置 Schema 失败");return i.schema}async function Ck(l){const n=await _e(`/api/webui/plugins/config/${l}`,{headers:Fs()});if(!n.ok){const c=await n.text();try{const u=JSON.parse(c);throw new Error(u.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${n.status})`)}}const i=await n.json();if(!i.success)throw new Error(i.message||"获取配置失败");return i.config}async function Tk(l){const n=await _e(`/api/webui/plugins/config/${l}/raw`,{headers:Fs()});if(!n.ok){const c=await n.text();try{const u=JSON.parse(c);throw new Error(u.detail||"获取配置失败")}catch{throw new Error(`获取配置失败 (${n.status})`)}}const i=await n.json();if(!i.success)throw new Error(i.message||"获取配置失败");return i.config}async function Ek(l,n){const i=await _e(`/api/webui/plugins/config/${l}`,{method:"PUT",headers:Fs(),body:JSON.stringify({config:n})});if(!i.ok){const c=await i.json();throw new Error(c.detail||"保存配置失败")}return await i.json()}async function Mk(l,n){const i=await _e(`/api/webui/plugins/config/${l}/raw`,{method:"PUT",headers:Fs(),body:JSON.stringify({config:n})});if(!i.ok){const c=await i.json();throw new Error(c.detail||"保存配置失败")}return await i.json()}async function zk(l){const n=await _e(`/api/webui/plugins/config/${l}/reset`,{method:"POST",headers:Fs()});if(!n.ok){const i=await n.json();throw new Error(i.detail||"重置配置失败")}return await n.json()}async function Ak(l){const n=await _e(`/api/webui/plugins/config/${l}/toggle`,{method:"POST",headers:Fs()});if(!n.ok){const i=await n.json();throw new Error(i.detail||"切换状态失败")}return await n.json()}const xc="https://maibot-plugin-stats.maibot-webui.workers.dev";async function Kv(l){try{const n=await fetch(`${xc}/stats/${l}`);return n.ok?await n.json():(console.error("Failed to fetch plugin stats:",n.statusText),null)}catch(n){return console.error("Error fetching plugin stats:",n),null}}async function Ok(l,n){try{const i=n||xx(),c=await fetch(`${xc}/stats/like`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,user_id:i})}),u=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...u}:{success:!1,error:u.error||"点赞失败"}}catch(i){return console.error("Error liking plugin:",i),{success:!1,error:"网络错误"}}}async function Dk(l,n){try{const i=n||xx(),c=await fetch(`${xc}/stats/dislike`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,user_id:i})}),u=await c.json();return c.status===429?{success:!1,error:"操作过于频繁,请稍后再试"}:c.ok?{success:!0,...u}:{success:!1,error:u.error||"点踩失败"}}catch(i){return console.error("Error disliking plugin:",i),{success:!1,error:"网络错误"}}}async function Rk(l,n,i,c){if(n<1||n>5)return{success:!1,error:"评分必须在 1-5 之间"};try{const u=c||xx(),x=await fetch(`${xc}/stats/rate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l,rating:n,comment:i,user_id:u})}),h=await x.json();return x.status===429?{success:!1,error:"每天最多评分 3 次"}:x.ok?{success:!0,...h}:{success:!1,error:h.error||"评分失败"}}catch(u){return console.error("Error rating plugin:",u),{success:!1,error:"网络错误"}}}async function Qv(l){try{const n=await fetch(`${xc}/stats/download`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plugin_id:l})}),i=await n.json();return n.status===429?(console.warn("Download recording rate limited"),{success:!0}):n.ok?{success:!0,...i}:(console.error("Failed to record download:",i.error),{success:!1,error:i.error})}catch(n){return console.error("Error recording download:",n),{success:!1,error:"网络错误"}}}function Lk(){const l=navigator,n=[navigator.userAgent,navigator.language,navigator.languages?.join(",")||"",navigator.platform,navigator.hardwareConcurrency||0,screen.width,screen.height,screen.colorDepth,screen.pixelDepth,new Date().getTimezoneOffset(),Intl.DateTimeFormat().resolvedOptions().timeZone,navigator.maxTouchPoints||0,l.deviceMemory||0].join("|");let i=0;for(let c=0;c{const ee=F.map(async Ee=>{try{const me=await Kv(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)};d.useEffect(()=>{let F=null,ee=!1;return(async()=>{if(F=await Sk(ie=>{ee||(C(ie),ie.stage==="success"?setTimeout(()=>{ee||C(null)},2e3):ie.stage==="error"&&(y(!1),O(ie.error||"加载失败")))},ie=>{console.error("WebSocket error:",ie),ee||pe({title:"WebSocket 连接失败",description:"无法实时显示加载进度",variant:"destructive"})}),await new Promise(ie=>{if(!F){ie();return}const Ee=()=>{F&&F.readyState===WebSocket.OPEN?(console.log("WebSocket connected, starting to load plugins"),ie()):F&&F.readyState===WebSocket.CLOSED?(console.warn("WebSocket closed before loading plugins"),ie()):setTimeout(Ee,100)};Ee()}),!ee){const ie=await Pv();B(ie),ie.installed||pe({title:"Git 未安装",description:ie.error||"请先安装 Git 才能使用插件安装功能",variant:"destructive"})}if(!ee){const ie=await Hv();H(ie)}if(!ee)try{y(!0),O(null);const ie=await wk();if(!ee){const Ee=await Al();L(Ee);const me=ie.map(ze=>{const rs=mn(ze.id,Ee),Ut=xn(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()});b(me),Te(me)}}catch(ie){if(!ee){const Ee=ie instanceof Error?ie.message:"加载插件列表失败";O(Ee),pe({title:"加载失败",description:Ee,variant:"destructive"})}}finally{ee||y(!1)}})(),()=>{ee=!0,F&&F.close()}},[pe]);const A=F=>{if(!F.installed&&z&&!D(F))return e.jsxs(ke,{variant:"destructive",className:"gap-1",children:[e.jsx(_t,{className:"h-3 w-3"}),"不兼容"]});if(F.installed){const ee=F.installed_version?.trim(),Ue=F.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=F=>!z||!F.manifest?.host_application?!0:Fv(F.manifest.host_application.min_version,F.manifest.host_application.max_version,z),V=F=>{if(!F.installed||!F.installed_version||!F.manifest?.version)return!1;const ee=F.installed_version.trim(),Ue=F.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(F=>{if(!F.manifest)return console.warn("[过滤] 跳过无 manifest 的插件:",F.id),!1;const ee=c===""||F.manifest.name?.toLowerCase().includes(c.toLowerCase())||F.manifest.description?.toLowerCase().includes(c.toLowerCase())||F.manifest.keywords&&F.manifest.keywords.some(me=>me.toLowerCase().includes(c.toLowerCase())),Ue=x==="all"||F.manifest.categories&&F.manifest.categories.includes(x);let ie=!0;f==="installed"?ie=F.installed===!0:f==="updates"&&(ie=F.installed===!0&&V(F));const Ee=!g||!z||D(F);return ee&&Ue&&ie&&Ee}),Oe=F=>{if(!S?.installed){pe({title:"无法安装",description:"Git 未安装",variant:"destructive"});return}if(z&&!D(F)){pe({title:"无法安装",description:"插件与当前麦麦版本不兼容",variant:"destructive"});return}re(F),ge("main"),K(""),ue("preset"),Se(!1),Ne(!0)},W=async()=>{if(!je)return;const F=I==="custom"?M:fe;if(!F||F.trim()===""){pe({title:"分支名称不能为空",variant:"destructive"});return}try{Ne(!1),await Gv(je.id,je.manifest.repository_url||"",F),Qv(je.id).catch(Ue=>{console.warn("Failed to record download:",Ue)}),pe({title:"安装成功",description:`${je.manifest.name} 已成功安装`});const ee=await Al();L(ee),b(Ue=>Ue.map(ie=>{if(ie.id===je.id){const Ee=mn(ie.id,ee),me=xn(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 F=>{try{await Vv(F.id),pe({title:"卸载成功",description:`${F.manifest.name} 已成功卸载`});const ee=await Al();L(ee),b(Ue=>Ue.map(ie=>{if(ie.id===F.id){const Ee=mn(ie.id,ee),me=xn(ie.id,ee);return{...ie,installed:Ee,installed_version:me}}return ie}))}catch(ee){pe({title:"卸载失败",description:ee instanceof Error?ee.message:"未知错误",variant:"destructive"})}},He=async F=>{if(!S?.installed){pe({title:"无法更新",description:"Git 未安装",variant:"destructive"});return}try{const ee=await qv(F.id,F.manifest.repository_url||"","main");pe({title:"更新成功",description:`${F.manifest.name} 已从 ${ee.old_version} 更新到 ${ee.new_version}`});const Ue=await Al();L(Ue),b(ie=>ie.map(Ee=>{if(Ee.id===F.id){const me=mn(Ee.id,Ue),ze=xn(Ee.id,Ue);return{...Ee,installed:me,installed_version:ze}}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:i,children:[e.jsx(Hj,{className:`h-4 w-4 mr-2 ${i?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(_,{onClick:()=>l({to:"/plugin-mirrors"}),children:[e.jsx(m_,{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(Ht,{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(Re,{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:F=>u(F.target.value),className:"pl-9"})]}),e.jsxs(Ie,{value:x,onValueChange:h,children:[e.jsx($e,{className:"w-full sm:w-[200px]",children:e.jsx(Pe,{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:F=>N(F===!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(Xt,{className:"grid w-full grid-cols-3",children:[e.jsxs(Xe,{value:"all",children:["全部插件 (",v.filter(F=>{if(!F.manifest)return!1;const ee=c===""||F.manifest.name?.toLowerCase().includes(c.toLowerCase())||F.manifest.description?.toLowerCase().includes(c.toLowerCase())||F.manifest.keywords&&F.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=x==="all"||F.manifest.categories&&F.manifest.categories.includes(x),ie=!g||!z||D(F);return ee&&Ue&&ie}).length,")"]}),e.jsxs(Xe,{value:"installed",children:["已安装 (",v.filter(F=>{if(!F.manifest)return!1;const ee=c===""||F.manifest.name?.toLowerCase().includes(c.toLowerCase())||F.manifest.description?.toLowerCase().includes(c.toLowerCase())||F.manifest.keywords&&F.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=x==="all"||F.manifest.categories&&F.manifest.categories.includes(x),ie=!g||!z||D(F);return F.installed&&ee&&Ue&&ie}).length,")"]}),e.jsxs(Xe,{value:"updates",children:["可更新 (",v.filter(F=>{if(!F.manifest)return!1;const ee=c===""||F.manifest.name?.toLowerCase().includes(c.toLowerCase())||F.manifest.description?.toLowerCase().includes(c.toLowerCase())||F.manifest.keywords&&F.manifest.keywords.some(Ee=>Ee.toLowerCase().includes(c.toLowerCase())),Ue=x==="all"||F.manifest.categories&&F.manifest.categories.includes(x),ie=!g||!z||D(F);return F.installed&&V(F)&&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(Bs,{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(Qn,{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(Re,{className:"text-lg text-destructive",children:"加载失败"}),e.jsx(os,{className:"text-destructive/80",children:E.error})]})]})})}),w?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(Bs,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"加载插件列表中..."})]}):R?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:R}),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||x!=="all"?"尝试调整搜索条件或筛选器":"暂无可用插件"})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:de.map(F=>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(Re,{className:"text-xl",children:F.manifest?.name||F.id}),e.jsxs("div",{className:"flex flex-col gap-1",children:[F.manifest?.categories&&F.manifest.categories[0]&&e.jsx(ke,{variant:"secondary",className:"text-xs whitespace-nowrap",children:Uk[F.manifest.categories[0]]||F.manifest.categories[0]}),A(F)]})]}),e.jsx(os,{className:"line-clamp-2",children:F.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(sa,{className:"h-4 w-4"}),e.jsx("span",{children:(J[F.id]?.downloads??F.downloads??0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(dn,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:(J[F.id]?.rating??F.rating??0).toFixed(1)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[F.manifest?.keywords&&F.manifest.keywords.slice(0,3).map(ee=>e.jsx(ke,{variant:"outline",className:"text-xs",children:ee},ee)),F.manifest?.keywords&&F.manifest.keywords.length>3&&e.jsxs(ke,{variant:"outline",className:"text-xs",children:["+",F.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",F.manifest?.version||"unknown"," · ",F.manifest?.author?.name||"Unknown"]}),F.manifest?.host_application&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:"支持:"}),e.jsxs("span",{className:"font-medium",children:[F.manifest.host_application.min_version,F.manifest.host_application.max_version?` - ${F.manifest.host_application.max_version}`:" - 最新版本"]})]})]})]})}),e.jsx(ed,{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:()=>l({to:"/plugin-detail",search:{pluginId:F.id}}),children:"查看详情"}),F.installed?V(F)?e.jsxs(_,{size:"sm",disabled:!S?.installed,title:S?.installed?void 0:"Git 未安装",onClick:()=>He(F),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(F),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"卸载"]}):e.jsxs(_,{size:"sm",disabled:!S?.installed||E?.operation==="install"||z!==null&&!D(F),title:S?.installed?z!==null&&!D(F)?`不兼容当前版本 (需要 ${F.manifest?.host_application?.min_version||"未知"}${F.manifest?.host_application?.max_version?` - ${F.manifest.host_application.max_version}`:"+"},当前 ${z?.version})`:void 0:"Git 未安装",onClick:()=>Oe(F),children:[e.jsx(sa,{className:"h-4 w-4 mr-1"}),E?.operation==="install"&&E?.plugin_id===F.id?"安装中...":"安装"]})]})}),E&&(E.stage==="loading"||E.stage==="success"||E.stage==="error")&&E.operation!=="fetch"&&E.plugin_id===F.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(Bs,{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(Qn,{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})]})})]},F.id))}),e.jsx(Is,{open:oe,onOpenChange:Ne,children:e.jsxs(Os,{children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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:F=>Se(F)}),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:I,onValueChange:F=>ue(F),children:[e.jsxs(Xt,{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:"自定义分支"})]}),I==="preset"&&e.jsx("div",{className:"mt-3",children:e.jsxs(Ie,{value:fe,onValueChange:ge,children:[e.jsx($e,{children:e.jsx(Pe,{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 (稳定版)"})]})]})}),I==="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:F=>K(F.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(sa,{className:"h-4 w-4 mr-2"}),"安装"]})]})]})}),e.jsx(Xn,{})]})})}function Ik(){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(Fj,{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(Re,{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 Pk({field:l,value:n,onChange:i}){const[c,u]=d.useState(!1);switch(l.ui_type){case"switch":return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{children:l.label}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]}),e.jsx(Ge,{checked:!!n,onCheckedChange:i,disabled:l.disabled})]});case"number":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsx(ae,{type:"number",value:n??l.default,onChange:x=>i(parseFloat(x.target.value)||0),min:l.min,max:l.max,step:l.step??1,placeholder:l.placeholder,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"slider":return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T,{children:l.label}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n??l.default})]}),e.jsx(qa,{value:[n??l.default],onValueChange:x=>i(x[0]),min:l.min??0,max:l.max??100,step:l.step??1,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"select":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsxs(Ie,{value:String(n??l.default),onValueChange:i,disabled:l.disabled,children:[e.jsx($e,{children:e.jsx(Pe,{placeholder:l.placeholder??"请选择"})}),e.jsx(Be,{children:l.choices?.map(x=>e.jsx(Z,{value:String(x),children:String(x)},String(x)))})]}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"textarea":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsx(ot,{value:n??l.default,onChange:x=>i(x.target.value),placeholder:l.placeholder,rows:l.rows??3,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"password":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsxs("div",{className:"relative",children:[e.jsx(ae,{type:c?"text":"password",value:n??"",onChange:x=>i(x.target.value),placeholder:l.placeholder,disabled:l.disabled,className:"pr-10"}),e.jsx(_,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3",onClick:()=>u(!c),children:c?e.jsx(ec,{className:"h-4 w-4"}):e.jsx(ia,{className:"h-4 w-4"})})]}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"list":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsx(q2,{value:Array.isArray(n)?n:[],onChange:x=>i(x),itemType:l.item_type??"string",itemFields:l.item_fields,minItems:l.min_items,maxItems:l.max_items,disabled:l.disabled,placeholder:l.placeholder}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]});case"text":default:return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:l.label}),e.jsx(ae,{type:"text",value:n??l.default??"",onChange:x=>i(x.target.value),placeholder:l.placeholder,maxLength:l.max_length,disabled:l.disabled}),l.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.hint})]})}}function Bg({section:l,config:n,onChange:i}){const[c,u]=d.useState(!l.collapsed),x=Object.entries(l.fields).filter(([,h])=>!h.hidden).sort(([,h],[,f])=>h.order-f.order);return e.jsx(rc,{open:c,onOpenChange:u,children:e.jsxs(Ce,{children:[e.jsx(ic,{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(Ma,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Zt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(Re,{className:"text-lg",children:l.title})]}),e.jsxs(ke,{variant:"secondary",className:"text-xs",children:[x.length," 项"]})]}),l.description&&e.jsx(os,{className:"ml-6",children:l.description})]})}),e.jsx(cc,{children:e.jsx(Me,{className:"space-y-4 pt-0",children:x.map(([h,f])=>e.jsx(Pk,{field:f,value:n[l.name]?.[h],onChange:p=>i(l.name,h,p),sectionName:l.name},h))})})]})})}function Hk({plugin:l,onBack:n}){const{toast:i}=Zs(),{triggerRestart:c,isRestarting:u}=vn(),[x,h]=d.useState("visual"),[f,p]=d.useState(null),[g,N]=d.useState({}),[v,b]=d.useState({}),[w,y]=d.useState(""),[R,O]=d.useState(""),[S,B]=d.useState(!0),[E,C]=d.useState(!1),[z,H]=d.useState(!1),[L,J]=d.useState(!1),[U,oe]=d.useState(!1),Ne=d.useCallback(async()=>{B(!0);try{const[I,ue,Q]=await Promise.all([kk(l.id),Ck(l.id),Tk(l.id)]);p(I),N(ue),b(JSON.parse(JSON.stringify(ue))),y(Q),O(Q)}catch(I){i({title:"加载配置失败",description:I instanceof Error?I.message:"未知错误",variant:"destructive"})}finally{B(!1)}},[l.id,i]);d.useEffect(()=>{Ne()},[Ne]),d.useEffect(()=>{H(x==="visual"?JSON.stringify(g)!==JSON.stringify(v):w!==R)},[g,v,w,R,x]);const je=(I,ue,Q)=>{N(Se=>({...Se,[I]:{...Se[I]||{},[ue]:Q}}))},re=async()=>{C(!0);try{if(x==="source"){try{Ov(w)}catch(I){J(!0),i({title:"TOML 格式错误",description:I instanceof Error?I.message:"无法解析 TOML 配置,请检查语法",variant:"destructive"}),C(!1);return}await Mk(l.id,w),O(w),J(!1)}else await Ek(l.id,g),b(JSON.parse(JSON.stringify(g)));i({title:"配置已保存",description:"更改将在插件重新加载后生效"})}catch(I){i({title:"保存失败",description:I instanceof Error?I.message:"未知错误",variant:"destructive"})}finally{C(!1)}},fe=async()=>{try{await zk(l.id),i({title:"配置已重置",description:"下次加载插件时将使用默认配置"}),oe(!1),Ne()}catch(I){i({title:"重置失败",description:I instanceof Error?I.message:"未知错误",variant:"destructive"})}},ge=async()=>{try{const I=await Ak(l.id);i({title:I.message,description:I.note}),Ne()}catch(I){i({title:"切换状态失败",description:I instanceof Error?I.message:"未知错误",variant:"destructive"})}};if(S)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(Bs,{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(Ta,{className:"h-4 w-4 mr-2"}),"返回"]})]});const M=Object.values(f.sections).sort((I,ue)=>I.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(Ta,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:f.plugin_info.name||l.manifest.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(ke,{variant:K?"default":"secondary",children:K?"已启用":"已禁用"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["v",f.plugin_info.version||l.manifest.version]})]})]})]}),e.jsxs("div",{className:"flex gap-2 ml-10 sm:ml-0",children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>h(x==="visual"?"source":"visual"),children:x==="visual"?e.jsxs(e.Fragment,{children:[e.jsx(Bj,{className:"h-4 w-4 mr-2"}),"源代码"]}):e.jsxs(e.Fragment,{children:[e.jsx($j,{className:"h-4 w-4 mr-2"}),"可视化"]})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>c(),disabled:u,children:[e.jsx(Hj,{className:`h-4 w-4 mr-2 ${u?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:ge,children:[e.jsx(oc,{className:"h-4 w-4 mr-2"}),K?"禁用":"启用"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>oe(!0),children:[e.jsx(Wi,{className:"h-4 w-4 mr-2"}),"重置"]}),e.jsxs(_,{size:"sm",onClick:re,disabled:!z||E,children:[E?e.jsx(Bs,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(dc,{className:"h-4 w-4 mr-2"}),"保存"]})]})]}),z&&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(Ht,{className:"h-4 w-4 text-orange-600"}),e.jsx("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:"有未保存的更改"})]})})}),x==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(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(yv,{value:w,onChange:I=>{y(I),L&&J(!1)},language:"toml",theme:"dark",height:"calc(100vh - 350px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),x==="visual"&&e.jsxs(e.Fragment,{children:[e.jsxs(at,{children:[e.jsx(Ht,{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(Xt,{children:f.layout.tabs.map(I=>e.jsxs(Xe,{value:I.id,children:[I.title,I.badge&&e.jsx(ke,{variant:"secondary",className:"ml-2 text-xs",children:I.badge})]},I.id))}),f.layout.tabs.map(I=>e.jsx(ws,{value:I.id,className:"space-y-4 mt-4",children:I.sections.map(ue=>{const Q=f.sections[ue];return Q?e.jsx(Bg,{section:Q,config:g,onChange:je},ue):null})},I.id))]}):e.jsx("div",{className:"space-y-4",children:M.map(I=>e.jsx(Bg,{section:I,config:g,onChange:je},I.name))})]}),e.jsx(Is,{open:U,onOpenChange:oe,children:e.jsxs(Os,{children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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 Fk(){return e.jsx(Jn,{children:e.jsx(Gk,{})})}function Gk(){const{toast:l}=Zs(),[n,i]=d.useState([]),[c,u]=d.useState(!0),[x,h]=d.useState(""),[f,p]=d.useState(null),g=async()=>{u(!0);try{const y=await Al();i(y)}catch(y){l({title:"加载插件列表失败",description:y instanceof Error?y.message:"未知错误",variant:"destructive"})}finally{u(!1)}};d.useEffect(()=>{g()},[]);const v=n.filter(y=>{const R=x.toLowerCase();return y.id.toLowerCase().includes(R)||y.manifest.name.toLowerCase().includes(R)||y.manifest.description?.toLowerCase().includes(R)}).filter((y,R,O)=>R===O.findIndex(S=>S.id===y.id)),b=n.length,w=0;return f?e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"h-full",children:e.jsx("div",{className:"p-4 sm:p-6",children:e.jsx(Hk,{plugin:f,onBack:()=>p(null)})})}),e.jsx(Xn,{})]}):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(Re,{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(Re,{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:b}),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(Re,{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:w}),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:x,onChange:y=>h(y.target.value),className:"pl-9"})]}),e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Re,{children:"已安装的插件"}),e.jsx(os,{children:"点击插件查看和编辑配置"})]}),e.jsx(Me,{children:c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Bs,{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:x?"没有找到匹配的插件":"暂无已安装的插件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:x?"尝试其他搜索关键词":"前往插件市场安装插件"})]})]}):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(pn,{className:"h-4 w-4"})}),e.jsx(Zt,{className:"h-4 w-4 text-muted-foreground"})]})]},y.id))})})]})]})})}function Vk(){const l=ca(),{toast:n}=Zs(),[i,c]=d.useState([]),[u,x]=d.useState(!0),[h,f]=d.useState(null),[p,g]=d.useState(null),[N,v]=d.useState(!1),[b,w]=d.useState(!1),[y,R]=d.useState({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),O=d.useCallback(async()=>{try{x(!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{x(!1)}},[n]);d.useEffect(()=>{O()},[O]);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),R({id:"",name:"",raw_prefix:"",clone_prefix:"",enabled:!0,priority:1}),O()}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:"镜像源已更新"}),w(!1),g(null),O()}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:"镜像源已删除"}),O()}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("更新状态失败");O()}catch(J){n({title:"更新失败",description:J instanceof Error?J.message:"未知错误",variant:"destructive"})}},z=L=>{g(L),R({id:L.id,name:L.name,raw_prefix:L.raw_prefix,clone_prefix:L.clone_prefix,enabled:L.enabled,priority:L.priority}),w(!0)},H=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("更新优先级失败");O()}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:()=>l({to:"/plugins"}),children:e.jsx(Ta,{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"}),"添加镜像源"]})]}),u?e.jsx(Ce,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Bs,{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:O,children:"重新加载"})]})}):e.jsxs(Ce,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(Rl,{children:[e.jsx(Ll,{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(Ul,{children:i.map(L=>e.jsxs(ut,{children:[e.jsx(Ke,{children:e.jsx(Ge,{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:()=>H(L,"up"),disabled:L.priority===1,children:e.jsx(Fr,{className:"h-3 w-3"})}),e.jsx(_,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:()=>H(L,"down"),children:e.jsx(Ma,{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:()=>z(L),children:e.jsx(Gn,{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:i.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(Ge,{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:()=>z(L),children:[e.jsx(Gn,{className:"h-4 w-4 mr-1"}),"编辑"]}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>H(L,"up"),disabled:L.priority===1,children:e.jsx(Fr,{className:"h-4 w-4"})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>H(L,"down"),children:e.jsx(Ma,{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(Is,{open:N,onOpenChange:v,children:e.jsxs(Os,{className:"max-w-lg",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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=>R({...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=>R({...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=>R({...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=>R({...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=>R({...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(Ge,{id:"add-enabled",checked:y.enabled,onCheckedChange:L=>R({...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(Is,{open:b,onOpenChange:w,children:e.jsxs(Os,{className:"max-w-lg",children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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=>R({...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=>R({...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=>R({...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=>R({...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(Ge,{id:"edit-enabled",checked:y.enabled,onCheckedChange:L=>R({...y,enabled:L})}),e.jsx(T,{htmlFor:"edit-enabled",children:"启用此镜像源"})]})]}),e.jsxs(st,{children:[e.jsx(_,{variant:"outline",onClick:()=>w(!1),children:"取消"}),e.jsx(_,{onClick:B,children:"保存"})]})]})})]})})}function qk({pluginId:l,compact:n=!1}){const[i,c]=d.useState(null),[u,x]=d.useState(!0),[h,f]=d.useState(0),[p,g]=d.useState(""),[N,v]=d.useState(!1),{toast:b}=Zs(),w=async()=>{x(!0);const S=await Kv(l);S&&c(S),x(!1)};d.useEffect(()=>{w()},[l]);const y=async()=>{const S=await Ok(l);S.success?(b({title:"已点赞",description:"感谢你的支持!"}),w()):b({title:"点赞失败",description:S.error||"未知错误",variant:"destructive"})},R=async()=>{const S=await Dk(l);S.success?(b({title:"已反馈",description:"感谢你的反馈!"}),w()):b({title:"操作失败",description:S.error||"未知错误",variant:"destructive"})},O=async()=>{if(h===0){b({title:"请选择评分",description:"至少选择 1 颗星",variant:"destructive"});return}const S=await Rk(l,h,p||void 0);S.success?(b({title:"评分成功",description:"感谢你的评价!"}),v(!1),f(0),g(""),w()):b({title:"评分失败",description:S.error||"未知错误",variant:"destructive"})};return u?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(sa,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(dn,{className:"h-4 w-4"}),e.jsx("span",{children:"-"})]})]}):i?n?e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",title:`下载量: ${i.downloads.toLocaleString()}`,children:[e.jsx(sa,{className:"h-4 w-4"}),e.jsx("span",{children:i.downloads.toLocaleString()})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`评分: ${i.rating.toFixed(1)} (${i.rating_count} 条评价)`,children:[e.jsx(dn,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{children:i.rating.toFixed(1)})]}),e.jsxs("div",{className:"flex items-center gap-1",title:`点赞数: ${i.likes}`,children:[e.jsx(bm,{className:"h-4 w-4"}),e.jsx("span",{children:i.likes})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(sa,{className:"h-5 w-5 text-muted-foreground mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.downloads.toLocaleString()}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"下载量"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(dn,{className:"h-5 w-5 text-yellow-400 mb-1 fill-yellow-400"}),e.jsx("span",{className:"text-2xl font-bold",children:i.rating.toFixed(1)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[i.rating_count," 条评价"]})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(bm,{className:"h-5 w-5 text-green-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.likes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点赞"})]}),e.jsxs("div",{className:"flex flex-col items-center p-3 rounded-lg border bg-card",children:[e.jsx(ug,{className:"h-5 w-5 text-red-500 mb-1"}),e.jsx("span",{className:"text-2xl font-bold",children:i.dislikes}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"点踩"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(_,{variant:"outline",size:"sm",onClick:y,children:[e.jsx(bm,{className:"h-4 w-4 mr-1"}),"点赞"]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:R,children:[e.jsx(ug,{className:"h-4 w-4 mr-1"}),"点踩"]}),e.jsxs(Is,{open:N,onOpenChange:v,children:[e.jsx(sd,{asChild:!0,children:e.jsxs(_,{variant:"default",size:"sm",children:[e.jsx(dn,{className:"h-4 w-4 mr-1"}),"评分"]})}),e.jsxs(Os,{children:[e.jsxs(Ds,{children:[e.jsx(Rs,{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(dn,{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:O,disabled:h===0,children:"提交评分"})]})]})]})]}),i.recent_ratings&&i.recent_ratings.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"最近评价"}),e.jsx("div",{className:"space-y-3",children:i.recent_ratings.map((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(dn,{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 Kk={"Group Management":"群组管理","Entertainment & Interaction":"娱乐互动","Utility Tools":"实用工具","Content Generation":"内容生成",Multimedia:"多媒体","External Integration":"外部集成","Data Analysis & Insights":"数据分析与洞察",Other:"其他"};function Qk(){const l=ca(),n=y0({strict:!1}),{toast:i}=Zs(),[c,u]=d.useState(null),[x,h]=d.useState(""),[f,p]=d.useState(!0),[g,N]=d.useState(!0),[v,b]=d.useState(null),[w,y]=d.useState(null),[R,O]=d.useState(null),[S,B]=d.useState(!1),[E,C]=d.useState(),[z,H]=d.useState(!1);d.useEffect(()=>{(async()=>{if(!n.pluginId){b("缺少插件 ID"),p(!1);return}try{p(!0),b(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 I={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()};u(I);const[ue,Q,Se]=await Promise.all([Pv(),Hv(),Al()]);y(ue),O(Q),B(mn(n.pluginId,Se)),C(xn(n.pluginId,Se))}catch(fe){b(fe instanceof Error?fe.message:"加载失败")}finally{p(!1)}})()},[n.pluginId]),d.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$/,""),I=await _e("/api/webui/plugins/fetch-raw",{method:"POST",body:JSON.stringify({owner:ge,repo:K,branch:"main",file_path:"README.md"})});if(!I.ok)throw new Error("获取 README 失败");const ue=await I.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||!R?!0:Fv(c.manifest.host_application.min_version,c.manifest.host_application.max_version,R),U=async()=>{if(!(!c||!w?.installed))try{H(!0),await Gv(c.id,c.manifest.repository_url||"","main"),Qv(c.id).catch(fe=>{console.warn("Failed to record download:",fe)}),i({title:"安装成功",description:`${c.manifest.name} 已成功安装`});const re=await Al();B(mn(c.id,re)),C(xn(c.id,re))}catch(re){i({title:"安装失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"})}finally{H(!1)}},oe=async()=>{if(c)try{H(!0),await Vv(c.id),i({title:"卸载成功",description:`${c.manifest.name} 已成功卸载`});const re=await Al();B(mn(c.id,re)),C(xn(c.id,re))}catch(re){i({title:"卸载失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"})}finally{H(!1)}},Ne=async()=>{if(!(!c||!w?.installed))try{H(!0);const re=await qv(c.id,c.manifest.repository_url||"","main");i({title:"更新成功",description:`${c.manifest.name} 已从 ${re.old_version} 更新到 ${re.new_version}`});const fe=await Al();B(mn(c.id,fe)),C(xn(c.id,fe))}catch(re){i({title:"更新失败",description:re instanceof Error?re.message:"未知错误",variant:"destructive"})}finally{H(!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:()=>l({to:"/plugins"}),children:e.jsx(Ta,{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(Bs,{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:()=>l({to:"/plugins"}),children:e.jsx(Ta,{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:()=>l({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:()=>l({to:"/plugins"}),className:"shrink-0",children:e.jsx(Ta,{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:!w?.installed||z,onClick:Ne,title:w?.installed?void 0:"Git 未安装",children:z?e.jsxs(e.Fragment,{children:[e.jsx(Bs,{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:!w?.installed||z,onClick:oe,title:w?.installed?void 0:"Git 未安装",children:z?e.jsxs(e.Fragment,{children:[e.jsx(Bs,{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:!w?.installed||!je||z,onClick:U,title:w?.installed?je?void 0:`不兼容当前版本 (需要 ${c.manifest.host_application.min_version}${c.manifest.host_application.max_version?` - ${c.manifest.host_application.max_version}`:"+"},当前 ${R?.version})`:"Git 未安装",children:z?e.jsxs(e.Fragment,{children:[e.jsx(Bs,{className:"h-4 w-4 mr-2 animate-spin"}),"安装中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(sa,{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(Re,{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(Re,{className:"text-lg",children:"统计信息"})}),e.jsx(Me,{children:e.jsx(qk,{pluginId:c.id})})]}),e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Re,{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(fn,{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(Oo,{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(Rj,{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(Bo,{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(Oo,{className:"h-3 w-3"})]})]}),c.manifest.repository_url&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(x_,{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(Oo,{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(Ht,{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(Re,{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:Kk[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(Wo,{className:"h-3 w-3 mr-1"}),re]},re))})]})]})]})]}),e.jsxs(Ce,{className:"lg:col-span-2",children:[e.jsx(De,{children:e.jsx(Re,{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(Bs,{className:"h-6 w-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-sm text-muted-foreground",children:"加载说明文档中..."})]}):x?e.jsx(nx,{content:x}):e.jsx("div",{className:"text-center text-muted-foreground py-12",children:"暂无说明文档"})})})]})]})]})})]})}const Ki=d.forwardRef(({className:l,...n},i)=>e.jsx(nj,{ref:i,className:P("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",l),...n}));Ki.displayName=nj.displayName;const Yk=d.forwardRef(({className:l,...n},i)=>e.jsx(rj,{ref:i,className:P("aspect-square h-full w-full",l),...n}));Yk.displayName=rj.displayName;const Qi=d.forwardRef(({className:l,...n},i)=>e.jsx(ij,{ref:i,className:P("flex h-full w-full items-center justify-center rounded-full bg-muted",l),...n}));Qi.displayName=ij.displayName;function Jk(){return"webui_"+Math.random().toString(36).substr(2,9)+"_"+Date.now().toString(36)}function Xk(){const l="maibot_webui_user_id";let n=localStorage.getItem(l);return n||(n=Jk(),localStorage.setItem(l,n)),n}function Zk(){return localStorage.getItem("maibot_webui_user_name")||"WebUI用户"}function Wk(l){localStorage.setItem("maibot_webui_user_name",l)}const Yv="maibot_webui_virtual_tabs";function eC(){try{const l=localStorage.getItem(Yv);if(l)return JSON.parse(l)}catch(l){console.error("[Chat] 加载虚拟标签页失败:",l)}return[]}function Ig(l){try{localStorage.setItem(Yv,JSON.stringify(l))}catch(n){console.error("[Chat] 保存虚拟标签页失败:",n)}}function sC({segment:l}){switch(l.type){case"text":return e.jsx("span",{className:"whitespace-pre-wrap",children:String(l.data)});case"image":case"emoji":return e.jsx("img",{src:String(l.data),alt:l.type==="emoji"?"表情包":"图片",className:P("rounded-lg max-w-full",l.type==="emoji"?"max-h-32":"max-h-64"),loading:"lazy",onError:n=>{const i=n.target;i.style.display="none",i.parentElement?.insertAdjacentHTML("beforeend",`[${l.type==="emoji"?"表情包":"图片"}加载失败]`)}});case"voice":return e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("audio",{controls:!0,src:String(l.data),className:"max-w-[200px] h-8",children:"您的浏览器不支持音频播放"})});case"video":return e.jsx("video",{controls:!0,src:String(l.data),className:"rounded-lg max-w-full max-h-64",children:"您的浏览器不支持视频播放"});case"face":return e.jsxs("span",{className:"text-muted-foreground",children:["[表情:",String(l.data),"]"]});case"music":return e.jsx("span",{className:"text-muted-foreground",children:"[音乐分享]"});case"file":return e.jsxs("span",{className:"text-muted-foreground",children:["[文件: ",String(l.data),"]"]});case"reply":return e.jsx("span",{className:"text-muted-foreground text-xs",children:"[回复消息]"});case"forward":return e.jsx("span",{className:"text-muted-foreground",children:"[转发消息]"});case"unknown":default:return e.jsxs("span",{className:"text-muted-foreground",children:["[",l.original_type||"未知消息","]"]})}}function tC({message:l,isBot:n}){return l.message_type==="rich"&&l.segments&&l.segments.length>0?e.jsx("div",{className:"flex flex-col gap-2",children:l.segments.map((i,c)=>e.jsx(sC,{segment:i},c))}):e.jsx("span",{className:"whitespace-pre-wrap",children:l.content})}function aC(){const l={id:"webui-default",type:"webui",label:"WebUI",messages:[],isConnected:!1,isTyping:!1,sessionInfo:{}},n=()=>{const qe=eC().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[l,...qe]},[i,c]=d.useState(n),[u,x]=d.useState("webui-default"),h=i.find(q=>q.id===u)||i[0],[f,p]=d.useState(""),[g,N]=d.useState(!1),[v,b]=d.useState(!0),[w,y]=d.useState(Zk()),[R,O]=d.useState(!1),[S,B]=d.useState(""),[E,C]=d.useState(!1),[z,H]=d.useState([]),[L,J]=d.useState([]),[U,oe]=d.useState(!1),[Ne,je]=d.useState(!1),[re,fe]=d.useState(""),[ge,M]=d.useState({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),K=d.useRef(Xk()),I=d.useRef(new Map),ue=d.useRef(null),Q=d.useRef(new Map),Se=d.useRef(0),pe=d.useRef(new Map),{toast:Te}=Zs(),A=q=>(Se.current+=1,`${q}-${Date.now()}-${Se.current}-${Math.random().toString(36).substr(2,9)}`),D=d.useCallback((q,qe)=>{c(Qe=>Qe.map(es=>es.id===q?{...es,...qe}:es))},[]),V=d.useCallback((q,qe)=>{c(Qe=>Qe.map(es=>es.id===q?{...es,messages:[...es.messages,qe]}:es))},[]),de=d.useCallback(()=>{ue.current?.scrollIntoView({behavior:"smooth"})},[]);d.useEffect(()=>{de()},[h?.messages,de]);const Oe=d.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),H(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=d.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 Ls=es.headers.get("content-type");if(Ls&&Ls.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)}},[]);d.useEffect(()=>{ge.platform&&W(ge.platform,re)},[ge.platform,re,W]);const Y=d.useCallback(async(q,qe)=>{b(!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 Ls=await _e(es);if(Ls.ok){const as=await Ls.text();try{const Cs=JSON.parse(as);if(Cs.messages&&Cs.messages.length>0){const Ae=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:Ae});const bs=pe.current.get(q)||new Set;Ae.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{b(!1)}},[D]),He=d.useCallback(async(q,qe,Qe)=>{const es=I.current.get(q);if(es?.readyState===WebSocket.OPEN||es?.readyState===WebSocket.CONNECTING){console.log(`[Tab ${q}] WebSocket 已存在,跳过连接`);return}N(!0);let Ls=null;try{const bs=await _e("/api/webui/ws-token");if(bs.ok){const ls=await bs.json();if(ls.success&&ls.token)Ls=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(!Ls){N(!1);return}const as=window.location.protocol==="https:"?"wss:":"ws:",Cs=new URLSearchParams;Cs.append("token",Ls),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",w));const Ae=`${as}//${window.location.host}/api/chat/ws?${Cs.toString()}`;console.log(`[Tab ${q}] 正在连接 WebSocket:`,Ae);try{const bs=new WebSocket(Ae);I.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":V(q,{id:A("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)}V(q,{id:ss.message_id||A("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:A("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:A("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||A(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),I.current.delete(q),console.log(`[Tab ${q}] WebSocket 已断开`);const ls=Q.current.get(q);ls&&clearTimeout(ls);const ss=window.setTimeout(()=>{if(!F.current){const ys=i.find(gt=>gt.id===q);ys&&He(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)}},[w,D,V,Te,i]),F=d.useRef(!1);d.useEffect(()=>{F.current=!1;const q=I.current,qe=Q.current,Qe=pe.current;Y("webui-default");const es=setTimeout(()=>{F.current||(He("webui-default","webui"),i.forEach(as=>{as.type==="virtual"&&as.virtualConfig&&(Qe.set(as.id,new Set),setTimeout(()=>{F.current||He(as.id,"virtual",as.virtualConfig)},200))}))},100),Ls=setInterval(()=>{q.forEach(as=>{as.readyState===WebSocket.OPEN&&as.send(JSON.stringify({type:"ping"}))})},3e4);return()=>{F.current=!0,clearTimeout(es),clearInterval(Ls),qe.forEach(as=>{clearTimeout(as)}),qe.clear(),q.forEach(as=>{as.close()}),q.clear()}},[]);const ee=d.useCallback(()=>{const q=I.current.get(u);if(!f.trim()||!q||q.readyState!==WebSocket.OPEN)return;const qe=h?.type==="virtual"&&h.virtualConfig?.userName||w,Qe=f.trim(),es=Date.now()/1e3;q.send(JSON.stringify({type:"message",content:Qe,user_name:qe}));const Ls=pe.current.get(u)||new Set,as=`user-${Qe}-${Math.floor(es*1e3)}`;if(Ls.add(as),pe.current.set(u,Ls),Ls.size>100){const bs=Ls.values().next().value;bs&&Ls.delete(bs)}const Cs={id:A("user"),type:"user",content:Qe,timestamp:es,sender:{name:qe,is_bot:!1}};V(u,Cs);const Ae={id:A("thinking"),type:"thinking",content:"",timestamp:es+.001,sender:{name:h?.sessionInfo.bot_name||"麦麦",is_bot:!0}};V(u,Ae),p("")},[f,w,u,h,V]),Ue=q=>{q.key==="Enter"&&!q.shiftKey&&(q.preventDefault(),ee())},ie=()=>{B(w),O(!0)},Ee=()=>{const q=S.trim()||"WebUI用户";y(q),Wk(q),O(!1);const qe=I.current.get(u);qe?.readyState===WebSocket.OPEN&&qe.send(JSON.stringify({type:"update_nickname",user_name:q}))},me=()=>{B(""),O(!1)},ze=q=>new Date(q*1e3).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),rs=()=>{const q=I.current.get(u);q&&(q.close(),I.current.delete(u)),He(u,h?.type||"webui",h?.virtualConfig)},Ut=()=>{M({platform:"",personId:"",userId:"",userName:"",groupName:"",groupId:""}),fe(""),Oe(),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(Ls=>{const as=[...Ls,es],Cs=as.filter(Ae=>Ae.type==="virtual"&&Ae.virtualConfig).map(Ae=>({id:Ae.id,label:Ae.label,virtualConfig:Ae.virtualConfig,createdAt:Date.now()}));return Ig(Cs),as}),x(qe),C(!1),pe.current.set(qe,new Set),setTimeout(()=>{He(qe,"virtual",ge)},100),Te({title:"虚拟身份标签页",description:`已创建 ${Qe} 的对话`})},Qa=(q,qe)=>{if(qe?.stopPropagation(),q==="webui-default")return;const Qe=I.current.get(q);Qe&&(Qe.close(),I.current.delete(q));const es=Q.current.get(q);es&&(clearTimeout(es),Q.current.delete(q)),pe.current.delete(q),c(Ls=>{const as=Ls.filter(Ae=>Ae.id!==q),Cs=as.filter(Ae=>Ae.type==="virtual"&&Ae.virtualConfig).map(Ae=>({id:Ae.id,label:Ae.label,virtualConfig:Ae.virtualConfig,createdAt:Date.now()}));return Ig(Cs),as}),u===q&&x("webui-default")},Ft=q=>{x(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(Is,{open:E,onOpenChange:C,children:e.jsxs(Os,{className:"sm:max-w-[500px] max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsxs(Ds,{children:[e.jsxs(Rs,{className:"flex items-center gap-2",children:[e.jsx(ym,{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(Bo,{className:"h-4 w-4"}),"选择平台"]}),e.jsxs(Ie,{value:ge.platform,onValueChange:q=>{M(qe=>({...qe,platform:q,personId:"",userId:"",userName:""})),J([])},children:[e.jsx($e,{disabled:U,children:e.jsx(Pe,{placeholder:U?"加载中...":"选择平台"})}),e.jsx(Be,{children:z.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(tc,{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(Bs,{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(tc,{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:P("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(Ki,{className:"h-8 w-8 shrink-0",children:e.jsx(Qi,{className:P("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:P("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:[i.map(q=>e.jsxs("div",{className:P("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm whitespace-nowrap transition-colors cursor-pointer","hover:bg-muted",u===q.id?"bg-background shadow-sm border":"text-muted-foreground"),onClick:()=>Ft(q.id),children:[q.type==="webui"?e.jsx(za,{className:"h-3.5 w-3.5"}):e.jsx(ym,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"max-w-[100px] truncate",children:q.label}),e.jsx("span",{className:P("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=>Qa(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(),Qa(q.id,qe))},children:e.jsx(Ea,{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(Ki,{className:"h-8 w-8 sm:h-10 sm:w-10 shrink-0",children:e.jsx(Qi,{className:"bg-primary/10 text-primary",children:e.jsx(Pn,{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(h_,{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(Bs,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"连接中..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(f_,{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(Bs,{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:P("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(ym,{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(fn,{className:"h-3 w-3"}),e.jsx("span",{children:"当前身份:"}),R?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:w}),e.jsx(_,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:ie,title:"修改昵称",children:e.jsx(p_,{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(Pn,{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:P("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(Ki,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(Qi,{className:"bg-primary/10 text-primary",children:e.jsx(Pn,{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(Ki,{className:"h-7 w-7 sm:h-8 sm:w-8 shrink-0",children:e.jsx(Qi,{className:P("text-xs",q.type==="bot"?"bg-primary/10 text-primary":"bg-secondary text-secondary-foreground"),children:q.type==="bot"?e.jsx(Pn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}):e.jsx(fn,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})}),e.jsxs("div",{className:P("flex flex-col gap-1 max-w-[75%] sm:max-w-[70%]",q.type==="user"&&"items-end"),children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] sm:text-xs text-muted-foreground",children:[e.jsx("span",{className:"hidden sm:inline",children:q.sender?.name||(q.type==="bot"?h?.sessionInfo.bot_name:w)}),e.jsx("span",{children:ze(q.timestamp)})]}),e.jsx("div",{className:P("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(tC,{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 hx="Radio",[lC,Jv]=Yo(hx),[nC,rC]=lC(hx),Xv=d.forwardRef((l,n)=>{const{__scopeRadio:i,name:c,checked:u=!1,required:x,disabled:h,value:f="on",onCheck:p,form:g,...N}=l,[v,b]=d.useState(null),w=Jo(n,O=>b(O)),y=d.useRef(!1),R=v?g||!!v.closest("form"):!0;return e.jsxs(nC,{scope:i,checked:u,disabled:h,children:[e.jsx(Yn.button,{type:"button",role:"radio","aria-checked":u,"data-state":sN(u),"data-disabled":h?"":void 0,disabled:h,value:f,...N,ref:w,onClick:hn(l.onClick,O=>{u||p?.(),R&&(y.current=O.isPropagationStopped(),y.current||O.stopPropagation())})}),R&&e.jsx(eN,{control:v,bubbles:!y.current,name:c,value:f,checked:u,required:x,disabled:h,form:g,style:{transform:"translateX(-100%)"}})]})});Xv.displayName=hx;var Zv="RadioIndicator",Wv=d.forwardRef((l,n)=>{const{__scopeRadio:i,forceMount:c,...u}=l,x=rC(Zv,i);return e.jsx(Rw,{present:c||x.checked,children:e.jsx(Yn.span,{"data-state":sN(x.checked),"data-disabled":x.disabled?"":void 0,...u,ref:n})})});Wv.displayName=Zv;var iC="RadioBubbleInput",eN=d.forwardRef(({__scopeRadio:l,control:n,checked:i,bubbles:c=!0,...u},x)=>{const h=d.useRef(null),f=Jo(h,x),p=Lw(i),g=Uw(n);return d.useEffect(()=>{const N=h.current;if(!N)return;const v=window.HTMLInputElement.prototype,w=Object.getOwnPropertyDescriptor(v,"checked").set;if(p!==i&&w){const y=new Event("click",{bubbles:c});w.call(N,i),N.dispatchEvent(y)}},[p,i,c]),e.jsx(Yn.input,{type:"radio","aria-hidden":!0,defaultChecked:i,...u,tabIndex:-1,ref:f,style:{...u.style,...g,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});eN.displayName=iC;function sN(l){return l?"checked":"unchecked"}var cC=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],cd="RadioGroup",[oC]=Yo(cd,[cj,Jv]),tN=cj(),aN=Jv(),[dC,uC]=oC(cd),lN=d.forwardRef((l,n)=>{const{__scopeRadioGroup:i,name:c,defaultValue:u,value:x,required:h=!1,disabled:f=!1,orientation:p,dir:g,loop:N=!0,onValueChange:v,...b}=l,w=tN(i),y=kj(g),[R,O]=Qo({prop:x,defaultProp:u??null,onChange:v,caller:cd});return e.jsx(dC,{scope:i,name:c,required:h,disabled:f,value:R,onValueChange:O,children:e.jsx(X0,{asChild:!0,...w,orientation:p,dir:y,loop:N,children:e.jsx(Yn.div,{role:"radiogroup","aria-required":h,"aria-orientation":p,"data-disabled":f?"":void 0,dir:y,...b,ref:n})})})});lN.displayName=cd;var nN="RadioGroupItem",rN=d.forwardRef((l,n)=>{const{__scopeRadioGroup:i,disabled:c,...u}=l,x=uC(nN,i),h=x.disabled||c,f=tN(i),p=aN(i),g=d.useRef(null),N=Jo(n,g),v=x.value===u.value,b=d.useRef(!1);return d.useEffect(()=>{const w=R=>{cC.includes(R.key)&&(b.current=!0)},y=()=>b.current=!1;return document.addEventListener("keydown",w),document.addEventListener("keyup",y),()=>{document.removeEventListener("keydown",w),document.removeEventListener("keyup",y)}},[]),e.jsx(Z0,{asChild:!0,...f,focusable:!h,active:v,children:e.jsx(Xv,{disabled:h,required:x.required,checked:v,...p,...u,name:x.name,ref:N,onCheck:()=>x.onValueChange(u.value),onKeyDown:hn(w=>{w.key==="Enter"&&w.preventDefault()}),onFocus:hn(u.onFocus,()=>{b.current&&g.current?.click()})})})});rN.displayName=nN;var mC="RadioGroupIndicator",iN=d.forwardRef((l,n)=>{const{__scopeRadioGroup:i,...c}=l,u=aN(i);return e.jsx(Wv,{...u,...c,ref:n})});iN.displayName=mC;var cN=lN,oN=rN,xC=iN;const fx=d.forwardRef(({className:l,...n},i)=>e.jsx(cN,{className:P("grid gap-2",l),...n,ref:i}));fx.displayName=cN.displayName;const qo=d.forwardRef(({className:l,...n},i)=>e.jsx(oN,{ref:i,className:P("aspect-square h-4 w-4 rounded-full border border-primary text-primary shadow focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",l),...n,children:e.jsx(xC,{className:"flex items-center justify-center",children:e.jsx($o,{className:"h-2.5 w-2.5 fill-current text-current"})})}));qo.displayName=oN.displayName;function hC({question:l,value:n,onChange:i,error:c,disabled:u=!1}){const[x,h]=d.useState(null),f=u||l.readOnly,p=()=>{switch(l.type){case"single":return e.jsx(fx,{value:n||"",onValueChange:i,disabled:f,className:"space-y-2",children:l.options?.map(g=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qo,{value:g.value,id:`${l.id}-${g.id}`}),e.jsx(T,{htmlFor:`${l.id}-${g.id}`,className:"cursor-pointer font-normal",children:g.label})]},g.id))});case"multiple":{const g=n||[];return e.jsxs("div",{className:"space-y-2",children:[l.options?.map(N=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:`${l.id}-${N.id}`,checked:g.includes(N.value),disabled:f||l.maxSelections!==void 0&&g.length>=l.maxSelections&&!g.includes(N.value),onCheckedChange:v=>{i(v?[...g,N.value]:g.filter(b=>b!==N.value))}}),e.jsx(T,{htmlFor:`${l.id}-${N.id}`,className:"cursor-pointer font-normal",children:N.label})]},N.id)),l.maxSelections&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["最多选择 ",l.maxSelections," 项"]})]})}case"text":return e.jsx(ae,{value:n||"",onChange:g=>i(g.target.value),placeholder:l.placeholder||"请输入...",disabled:f,readOnly:l.readOnly,maxLength:l.maxLength,className:P(l.readOnly&&"bg-muted cursor-not-allowed")});case"textarea":return e.jsxs("div",{className:"space-y-1",children:[e.jsx(ot,{value:n||"",onChange:g=>i(g.target.value),placeholder:l.placeholder||"请输入...",disabled:f,readOnly:l.readOnly,maxLength:l.maxLength,rows:4,className:P(l.readOnly&&"bg-muted cursor-not-allowed")}),l.maxLength&&e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[(n||"").length," / ",l.maxLength]})]});case"rating":{const g=n||0,N=x!==null?x: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:P("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&&i(v),children:e.jsx(dn,{className:P("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=l.min??1,N=l.max??10,v=l.step??1,b=n??g;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(qa,{value:[b],onValueChange:([w])=>i(w),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:l.minLabel||g}),e.jsx("span",{className:"font-medium text-foreground",children:b}),e.jsx("span",{children:l.maxLabel||N})]})]})}case"dropdown":return e.jsxs(Ie,{value:n||"",onValueChange:i,disabled:f,children:[e.jsx($e,{children:e.jsx(Pe,{placeholder:l.placeholder||"请选择..."})}),e.jsx(Be,{children:l.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:[l.title,l.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),l.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:l.description})]}),p(),c&&e.jsx("p",{className:"text-sm text-destructive",children:c})]})}const dN="https://maibot-plugin-stats.maibot-webui.workers.dev";function uN(){const l="maibot_user_id";let n=localStorage.getItem(l);if(!n){const i=Math.random().toString(36).substring(2,10),c=Date.now().toString(36),u=Math.random().toString(36).substring(2,10);n=`fp_${i}_${c}_${u}`,localStorage.setItem(l,n)}return n}async function fC(l,n,i,c){try{const u=c?.userId||uN(),x={surveyId:l,surveyVersion:n,userId:u,answers:i,submittedAt:new Date().toISOString(),allowMultiple:c?.allowMultiple,metadata:{userAgent:navigator.userAgent,language:navigator.language}},h=await fetch(`${dN}/survey/submit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)}),f=await h.json();return h.status===429?{success:!1,error:"提交过于频繁,请稍后再试"}:h.status===409?{success:!1,error:f.error||"你已经提交过这份问卷了"}:h.ok?{success:!0,submissionId:f.submissionId,message:f.message}:{success:!1,error:f.error||"提交失败"}}catch(u){return console.error("Error submitting survey:",u),{success:!1,error:"网络错误"}}}async function pC(l,n){try{const i=n||uN(),c=new URLSearchParams({user_id:i,survey_id:l}),u=await fetch(`${dN}/survey/check?${c}`);return u.ok?{success:!0,hasSubmitted:(await u.json()).hasSubmitted}:{success:!1,error:(await u.json()).error||"检查失败"}}catch(i){return console.error("Error checking submission:",i),{success:!1,error:"网络错误"}}}function mN({config:l,initialAnswers:n,onSubmitSuccess:i,onSubmitError:c,showProgress:u=!0,paginateQuestions:x=!1,className:h}){const f=d.useCallback(()=>!n||n.length===0?{}:n.reduce((I,ue)=>(I[ue.questionId]=ue.value,I),{}),[n]),[p,g]=d.useState(()=>f()),[N,v]=d.useState({}),[b,w]=d.useState(0),[y,R]=d.useState(!1),[O,S]=d.useState(!1),[B,E]=d.useState(null),[C,z]=d.useState(null),[H,L]=d.useState(!1),[J,U]=d.useState(!0);d.useEffect(()=>{n&&n.length>0&&g(I=>({...I,...f()}))},[n,f]),d.useEffect(()=>{(async()=>{if(!l.settings?.allowMultiple){const ue=await pC(l.id);ue.success&&ue.hasSubmitted&&L(!0)}U(!1)})()},[l.id,l.settings?.allowMultiple]);const oe=d.useCallback(()=>{const I=new Date;return!(l.settings?.startTime&&new Date(l.settings.startTime)>I||l.settings?.endTime&&new Date(l.settings.endTime){const ue=p[I.id];return ue==null?!1:Array.isArray(ue)?ue.length>0:typeof ue=="string"?ue.trim()!=="":!0}).length,je=Ne/l.questions.length*100,re=d.useCallback((I,ue)=>{g(Q=>({...Q,[I]:ue})),v(Q=>{const Se={...Q};return delete Se[I],Se})},[]),fe=d.useCallback(()=>{const I={};for(const ue of l.questions){if(ue.required){const Q=p[ue.id];if(Q==null){I[ue.id]="此题为必填项";continue}if(Array.isArray(Q)&&Q.length===0){I[ue.id]="请至少选择一项";continue}if(typeof Q=="string"&&Q.trim()===""){I[ue.id]="此题为必填项";continue}}ue.minLength&&typeof p[ue.id]=="string"&&p[ue.id].length{if(!fe()){if(x){const I=l.questions.findIndex(ue=>N[ue.id]);I>=0&&w(I)}return}R(!0),E(null);try{const I=l.questions.filter(Q=>p[Q.id]!==void 0).map(Q=>({questionId:Q.id,value:p[Q.id]})),ue=await fC(l.id,l.version,I,{allowMultiple:l.settings?.allowMultiple});if(ue.success&&ue.submissionId)S(!0),z(ue.submissionId),i?.(ue.submissionId);else{const Q=ue.error||"提交失败";E(Q),c?.(Q)}}catch(I){const ue=I instanceof Error?I.message:"提交失败";E(ue),c?.(ue)}finally{R(!1)}},[fe,x,l,p,N,i,c]),M=d.useCallback(I=>{I>=0&&Ie.jsxs("div",{className:P("p-4 rounded-lg border bg-card",N[I.id]?"border-destructive bg-destructive/5":"border-border"),children:[x&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:["问题 ",b+1," / ",l.questions.length]}),!x&&e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:[ue+1,"."]}),e.jsx(hC,{question:I,value:p[I.id],onChange:Q=>re(I.id,Q),error:N[I.id],disabled:y})]},I.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:x?e.jsxs(e.Fragment,{children:[e.jsxs(_,{variant:"outline",onClick:()=>M(b-1),disabled:b===0||y,children:[e.jsx(Aa,{className:"h-4 w-4 mr-1"}),"上一题"]}),b===l.questions.length-1?e.jsxs(_,{onClick:ge,disabled:y,children:[y&&e.jsx(Bs,{className:"h-4 w-4 mr-2 animate-spin"}),"提交问卷"]}):e.jsxs(_,{onClick:()=>M(b+1),disabled:y,children:["下一题",e.jsx(Zt,{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(Bs,{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:"感谢你的反馈!你的意见对我们非常重要,我们会认真考虑每一条建议。"}},jC={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 vC(){const[l,n]=d.useState(!0),i=d.useMemo(()=>JSON.parse(JSON.stringify(gC)),[]);d.useEffect(()=>{n(!1)},[]);const c=d.useMemo(()=>[{questionId:"webui_version",value:`v${td}`}],[]),u=d.useCallback(h=>{console.log("WebUI Survey submitted:",h)},[]),x=d.useCallback(h=>{console.error("WebUI Survey submission error:",h)},[]);return l?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(Bs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):i?e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 shrink-0",children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(Gj,{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(mN,{config:i,initialAnswers:c,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:u,onSubmitError:x})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(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 NC(){const[l,n]=d.useState(null),[i,c]=d.useState(!0),[u,x]=d.useState("未知版本");d.useEffect(()=>{(async()=>{try{const v=await d1();x(v.version||"未知版本")}catch(v){console.error("Failed to get MaiBot version:",v),x("获取失败")}const N=JSON.parse(JSON.stringify(jC));n(N),c(!1)})()},[]);const h=d.useMemo(()=>[{questionId:"maibot_version",value:u}],[u]),f=d.useCallback(g=>{console.log("MaiBot Survey submitted:",g)},[]),p=d.useCallback(g=>{console.error("MaiBot Survey submission error:",g)},[]);return i?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(Bs,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):l?e.jsxs("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6 shrink-0",children:[e.jsxs("h1",{className:"text-2xl sm:text-3xl font-bold flex items-center gap-2",children:[e.jsx(Gj,{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(mN,{config:l,initialAnswers:h,showProgress:!0,paginateQuestions:!1,onSubmitSuccess:f,onSubmitError:p})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsxs(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 bC(l=2025){const n=await _e(`/api/webui/annual-report/full?year=${l}`);if(!n.ok){const i=await n.json();throw new Error(i.detail||"获取年度报告失败")}return n.json()}const zo=["#0088FE","#00C49F","#FFBB28","#FF8042","#8884d8","#82ca9d"];function yC(l){return l>=8760?"相当于全年无休,7x24小时在线!":l>=5e3?"相当于一位全职员工的年工作时长":l>=2e3?"相当于看完了 1000 部电影":l>=1e3?"相当于环球飞行 80 次":l>=500?"相当于读完了 100 本书":l>=100?"相当于马拉松跑了 25 次":"虽然不多,但每一刻都很珍贵"}function wC(l){return l>=1e3?"夜深人静时的知心好友":l>=500?"午夜场的常客":l>=100?"偶尔熬夜的小伙伴":l>=50?"深夜有时也会陪你聊聊":"早睡早起,健康作息"}function _C(l){const n=l/1e6;return n>=100?"思考量堪比一座图书馆":n>=50?"相当于写了一部百科全书":n>=10?"脑细胞估计消耗了不少":n>=1?"也算是费了一番脑筋":"轻轻松松,游刃有余"}function SC(l){return l>=1e3?"这钱够吃一年的泡面了":l>=500?"相当于买了一台游戏机":l>=100?"够请大家喝几杯奶茶":l>=50?"一顿火锅的钱":l>=10?"几杯咖啡的价格":"省钱小能手"}function kC(l){return l>=80?"沉默是金,惜字如金":l>=60?"话不多但句句到位":l>=40?"该说的时候才开口":l>=20?"能聊的都聊了":"话痨本痨,有问必答"}function CC(l){return l>=1e4?"眼睛都快看花了":l>=5e3?"堪比专业摄影师的阅片量":l>=1e3?"看图小达人":l>=500?"图片鉴赏家":l>=100?"偶尔欣赏一下美图":"图片?有空再看"}function TC(l){return l>=500?"在不断的纠正中成长":l>=200?"学习永无止境":l>=100?"虚心接受,积极改正":l>=50?"偶尔也会犯错":l>=10?"表现还算不错":"完美表达,无需纠正"}function EC(l){return l>=1?"这次思考的价值堪比一顿大餐!":l>=.5?"为了这个问题,我可是认真思考了!":l>=.1?"下了点功夫,值得的!":l>=.01?"花了点小钱,但很值得":"小小思考,不足挂齿"}function MC(l,n){return l>=100?"这句话简直是万能钥匙!":l>=50?"百试不爽的经典回复":l>=20?`${n}的口头禅`:l>=10?"常用语录之一":"偶尔用用的小确幸"}function zC(l,n){return l?n>=1e3?"深夜的守护者,黑暗中的光芒":n>=500?"月亮是我的好朋友":n>=100?"越夜越精神,夜晚才是主场":"偶尔熬夜,享受宁静时光":n<=10?"作息规律,健康生活的典范":n<=50?"早睡早起,偶尔也会熬个夜":"虽然是早起鸟,但也会守候深夜"}function AC(l){return l>=1e3?"忙到飞起,键盘都要冒烟了":l>=500?"这天简直是话痨附体":l>=200?"社交达人上线":l>=100?"比平时活跃不少":l>=50?"小忙一下":"还算轻松的一天"}function OC(){const[l]=d.useState(2025),[n,i]=d.useState(null),[c,u]=d.useState(!0),[x,h]=d.useState(null),f=d.useRef(null),p=d.useCallback(async()=>{try{u(!0),h(null);const g=await bC(l);i(g)}catch(g){h(g instanceof Error?g:new Error("获取年度报告失败"))}finally{u(!1)}},[l]);return d.useEffect(()=>{p()},[p]),c?e.jsx(DC,{}):x?e.jsxs("div",{className:"flex h-screen items-center justify-center text-red-500",children:["获取年度报告失败: ",x.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",children:e.jsxs("div",{className:"mx-auto max-w-5xl space-y-8 print:space-y-4",ref:f,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.jsxs("div",{className:"relative z-10 flex flex-col items-center text-center",children:[e.jsx(Pn,{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(Io,{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(ka,{title:"年度在线时长",value:`${n.time_footprint.total_online_hours} 小时`,description:yC(n.time_footprint.total_online_hours),icon:e.jsx(na,{className:"h-4 w-4"})}),e.jsx(ka,{title:"最忙碌的一天",value:n.time_footprint.busiest_day||"N/A",description:AC(n.time_footprint.busiest_day_count),icon:e.jsx(Io,{className:"h-4 w-4"})}),e.jsx(ka,{title:"深夜互动 (0-4点)",value:`${n.time_footprint.midnight_chat_count} 次`,description:wC(n.time_footprint.midnight_chat_count),icon:e.jsx(Yi,{className:"h-4 w-4"})}),e.jsx(ka,{title:"作息属性",value:n.time_footprint.is_night_owl?"夜猫子":"早起鸟",description:zC(n.time_footprint.is_night_owl,n.time_footprint.midnight_chat_count),icon:n.time_footprint.is_night_owl?e.jsx(Yi,{className:"h-4 w-4"}):e.jsx(Km,{className:"h-4 w-4"})})]}),e.jsxs(Ce,{className:"overflow-hidden",children:[e.jsxs(De,{children:[e.jsx(Re,{children:"24小时活跃时钟"}),e.jsxs(os,{children:[n.bot_name,"在一天中各个时段的活跃程度"]})]}),e.jsx(Me,{className:"h-[300px]",children:e.jsx(uj,{width:"100%",height:"100%",children:e.jsxs(Ao,{data:n.time_footprint.hourly_distribution.map((g,N)=>({hour:`${N}点`,count:g})),children:[e.jsx(Fi,{strokeDasharray:"3 3",vertical:!1}),e.jsx(Gi,{dataKey:"hour"}),e.jsx($r,{}),e.jsx(mj,{contentStyle:{borderRadius:"8px",border:"none",boxShadow:"0 4px 12px rgba(0,0,0,0.1)"},cursor:{fill:"transparent"}}),e.jsx(Vi,{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(tc,{className:"h-8 w-8"}),e.jsx("h2",{children:"社交网络"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(ka,{title:"社交圈子",value:`${n.social_network.total_groups} 个群组`,description:`${n.bot_name}加入的群组总数`,icon:e.jsx(tc,{className:"h-4 w-4"})}),e.jsx(ka,{title:"被呼叫次数",value:`${n.social_network.at_count+n.social_network.mentioned_count} 次`,description:"我的名字被大家频繁提起",icon:e.jsx(j_,{className:"h-4 w-4"})}),e.jsx(ka,{title:"最长情陪伴",value:n.social_network.longest_companion_user||"N/A",description:`始终都在,已陪伴 ${n.social_network.longest_companion_days} 天`,icon:e.jsx(qr,{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(Re,{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((g,N)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ke,{variant:N===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:N+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:g.group_name}),g.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:[g.message_count," 条消息"]})]},g.group_id)):e.jsx("div",{className:"text-center text-muted-foreground py-4",children:"暂无数据"})})})]}),e.jsxs(Ce,{children:[e.jsx(De,{children:e.jsx(Re,{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((g,N)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ke,{variant:N===0?"default":"secondary",className:"h-6 w-6 rounded-full p-0 flex items-center justify-center shrink-0",children:N+1}),e.jsx("span",{className:"font-medium truncate max-w-[120px]",children:g.user_nickname}),g.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:[g.message_count," 次互动"]})]},g.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(Zm,{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(ka,{title:"年度 Token 消耗",value:(n.brain_power.total_tokens/1e6).toFixed(2)+" M",description:_C(n.brain_power.total_tokens),icon:e.jsx(Za,{className:"h-4 w-4"})}),e.jsx(ka,{title:"年度总花费",value:`$${n.brain_power.total_cost.toFixed(2)}`,description:SC(n.brain_power.total_cost),icon:e.jsx("span",{className:"font-bold",children:"$"})}),e.jsx(ka,{title:"高冷指数",value:`${n.brain_power.silence_rate}%`,description:kC(n.brain_power.silence_rate),icon:e.jsx(Yi,{className:"h-4 w-4"})}),e.jsx(ka,{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(qr,{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(Re,{children:"模型偏好分布"})}),e.jsx(Me,{children:e.jsx("div",{className:"space-y-3",children:n.brain_power.model_distribution.slice(0,5).map((g,N)=>{const v=n.brain_power.model_distribution[0]?.count||1,b=Math.round(g.count/v*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:g.model}),e.jsxs("span",{className:"text-muted-foreground",children:[g.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:`${b}%`,backgroundColor:zo[N%zo.length]}})})]},g.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(Re,{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((g,N)=>{const v=n.brain_power.top_reply_models[0]?.count||1,b=Math.round(g.count/v*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:g.model}),e.jsxs("span",{className:"text-muted-foreground",children:[g.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:`${b}%`,backgroundColor:zo[N%zo.length]}})})]},g.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(Re,{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(g=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm font-medium",children:[e.jsxs("span",{children:["用户 ",g.user_id]}),e.jsxs("span",{children:["$",g.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:`${g.cost/(n.brain_power.top_token_consumers[0]?.cost||1)*100}%`}})})]},g.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(Re,{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:EC(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(Re,{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(Xo,{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(Re,{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(Re,{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:MC(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(Re,{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((g,N)=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:`/api/webui/emoji/${g.id}/thumbnail?original=true`,alt:`TOP ${N+1}`,className:"h-24 w-24 rounded-lg object-cover shadow-md transition-transform hover:scale-105"}),e.jsx(ke,{className:P("absolute -top-2 -right-2",N===0?"bg-yellow-500":N===1?"bg-gray-400":"bg-amber-700"),children:N+1})]}),e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:[g.usage_count," 次"]})]},g.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(Re,{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((g,N)=>e.jsxs(ke,{variant:"outline",className:P("px-3 py-1 text-sm",N===0&&"border-primary bg-primary/10 text-primary text-base px-4 py-2"),children:[g.style," (",g.count,")"]},g.style))})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(ka,{title:"图片鉴赏",value:`${n.expression_vibe.image_processed_count} 张`,description:CC(n.expression_vibe.image_processed_count),icon:e.jsx(Xm,{className:"h-4 w-4"})}),e.jsx(ka,{title:"成长的足迹",value:`${n.expression_vibe.rejected_expression_count} 次`,description:TC(n.expression_vibe.rejected_expression_count),icon:e.jsx(Za,{className:"h-4 w-4"})})]})]})]}),n.expression_vibe.action_types.length>0&&e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsxs(Re,{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(g=>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:g.action}),e.jsxs(ke,{variant:"secondary",children:[g.count," 次"]})]},g.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(v_,{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(Re,{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(g=>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:g.content}),e.jsx("div",{className:"text-xs text-muted-foreground mt-1 line-clamp-2 max-w-[200px]",children:g.meaning||"暂无解释"})]},g.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(za,{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 ka({title:l,value:n,description:i,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(Re,{className:"text-sm font-medium",children:l}),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:i})]})]})}function DC(){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((l,n)=>e.jsx(vs,{className:"h-32 w-full"},n))}),e.jsx(vs,{className:"h-96 w-full"})]})}var od="DropdownMenu",[RC]=Yo(od,[oj]),oa=oj(),[LC,xN]=RC(od),hN=l=>{const{__scopeDropdownMenu:n,children:i,dir:c,open:u,defaultOpen:x,onOpenChange:h,modal:f=!0}=l,p=oa(n),g=d.useRef(null),[N,v]=Qo({prop:u,defaultProp:x??!1,onChange:h,caller:od});return e.jsx(LC,{scope:n,triggerId:Um(),triggerRef:g,contentId:Um(),open:N,onOpenChange:v,onOpenToggle:d.useCallback(()=>v(b=>!b),[v]),modal:f,children:e.jsx(ow,{...p,open:N,onOpenChange:v,dir:c,modal:f,children:i})})};hN.displayName=od;var fN="DropdownMenuTrigger",pN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,disabled:c=!1,...u}=l,x=xN(fN,i),h=oa(i);return e.jsx(dw,{asChild:!0,...h,children:e.jsx(Yn.button,{type:"button",id:x.triggerId,"aria-haspopup":"menu","aria-expanded":x.open,"aria-controls":x.open?x.contentId:void 0,"data-state":x.open?"open":"closed","data-disabled":c?"":void 0,disabled:c,...u,ref:$w(n,x.triggerRef),onPointerDown:hn(l.onPointerDown,f=>{!c&&f.button===0&&f.ctrlKey===!1&&(x.onOpenToggle(),x.open||f.preventDefault())}),onKeyDown:hn(l.onKeyDown,f=>{c||(["Enter"," "].includes(f.key)&&x.onOpenToggle(),f.key==="ArrowDown"&&x.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(f.key)&&f.preventDefault())})})})});pN.displayName=fN;var UC="DropdownMenuPortal",gN=l=>{const{__scopeDropdownMenu:n,...i}=l,c=oa(n);return e.jsx(sw,{...c,...i})};gN.displayName=UC;var jN="DropdownMenuContent",vN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=xN(jN,i),x=oa(i),h=d.useRef(!1);return e.jsx(tw,{id:u.contentId,"aria-labelledby":u.triggerId,...x,...c,ref:n,onCloseAutoFocus:hn(l.onCloseAutoFocus,f=>{h.current||u.triggerRef.current?.focus(),h.current=!1,f.preventDefault()}),onInteractOutside:hn(l.onInteractOutside,f=>{const p=f.detail.originalEvent,g=p.button===0&&p.ctrlKey===!0,N=p.button===2||g;(!u.modal||N)&&(h.current=!0)}),style:{...l.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});vN.displayName=jN;var $C="DropdownMenuGroup",BC=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(uw,{...u,...c,ref:n})});BC.displayName=$C;var IC="DropdownMenuLabel",NN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(iw,{...u,...c,ref:n})});NN.displayName=IC;var PC="DropdownMenuItem",bN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(aw,{...u,...c,ref:n})});bN.displayName=PC;var HC="DropdownMenuCheckboxItem",yN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(lw,{...u,...c,ref:n})});yN.displayName=HC;var FC="DropdownMenuRadioGroup",GC=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(mw,{...u,...c,ref:n})});GC.displayName=FC;var VC="DropdownMenuRadioItem",wN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(rw,{...u,...c,ref:n})});wN.displayName=VC;var qC="DropdownMenuItemIndicator",_N=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(nw,{...u,...c,ref:n})});_N.displayName=qC;var KC="DropdownMenuSeparator",SN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(cw,{...u,...c,ref:n})});SN.displayName=KC;var QC="DropdownMenuArrow",YC=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(xw,{...u,...c,ref:n})});YC.displayName=QC;var JC="DropdownMenuSubTrigger",kN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(W0,{...u,...c,ref:n})});kN.displayName=JC;var XC="DropdownMenuSubContent",CN=d.forwardRef((l,n)=>{const{__scopeDropdownMenu:i,...c}=l,u=oa(i);return e.jsx(ew,{...u,...c,ref:n,style:{...l.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});CN.displayName=XC;var ZC=hN,WC=pN,e3=gN,TN=vN,EN=NN,MN=bN,zN=yN,AN=wN,ON=_N,DN=SN,RN=kN,LN=CN;const s3=ZC,t3=WC,a3=d.forwardRef(({className:l,inset:n,children:i,...c},u)=>e.jsxs(RN,{ref:u,className:P("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",n&&"pl-8",l),...c,children:[i,e.jsx(Zt,{className:"ml-auto h-4 w-4"})]}));a3.displayName=RN.displayName;const l3=d.forwardRef(({className:l,...n},i)=>e.jsx(LN,{ref:i,className:P("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",l),...n}));l3.displayName=LN.displayName;const UN=d.forwardRef(({className:l,sideOffset:n=4,...i},c)=>e.jsx(e3,{children:e.jsx(TN,{ref:c,sideOffset:n,className:P("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",l),...i})}));UN.displayName=TN.displayName;const $N=d.forwardRef(({className:l,inset:n,...i},c)=>e.jsx(MN,{ref:c,className:P("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n&&"pl-8",l),...i}));$N.displayName=MN.displayName;const n3=d.forwardRef(({className:l,children:n,checked:i,...c},u)=>e.jsxs(zN,{ref:u,className:P("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",l),checked:i,...c,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(ON,{children:e.jsx(Ct,{className:"h-4 w-4"})})}),n]}));n3.displayName=zN.displayName;const r3=d.forwardRef(({className:l,children:n,...i},c)=>e.jsxs(AN,{ref:c,className:P("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",l),...i,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(ON,{children:e.jsx($o,{className:"h-2 w-2 fill-current"})})}),n]}));r3.displayName=AN.displayName;const i3=d.forwardRef(({className:l,inset:n,...i},c)=>e.jsx(EN,{ref:c,className:P("px-2 py-1.5 text-sm font-semibold",n&&"pl-8",l),...i}));i3.displayName=EN.displayName;const c3=d.forwardRef(({className:l,...n},i)=>e.jsx(DN,{ref:i,className:P("-mx-1 my-1 h-px bg-muted",l),...n}));c3.displayName=DN.displayName;const Lm=[{value:"created_at",label:"最新发布",icon:na},{value:"downloads",label:"下载最多",icon:sa},{value:"likes",label:"最受欢迎",icon:qr}];function o3(){const l=ca(),[n,i]=d.useState([]),[c,u]=d.useState(!0),[x,h]=d.useState(""),[f,p]=d.useState("downloads"),[g,N]=d.useState(1),[v,b]=d.useState(1),[w,y]=d.useState(0),[R,O]=d.useState(new Set),[S,B]=d.useState(new Set),E=Mv(),C=d.useCallback(async()=>{u(!0);try{const U=await mS({status:"approved",page:g,page_size:12,search:x||void 0,sort_by:f,sort_order:"desc"});i(U.packs),b(U.total_pages),y(U.total);const oe=new Set;for(const Ne of U.packs)await Ev(Ne.id,E)&&oe.add(Ne.id);O(oe)}catch(U){console.error("加载 Pack 列表失败:",U),Qt({title:"加载 Pack 列表失败",variant:"destructive"})}finally{u(!1)}},[g,x,f,E]);d.useEffect(()=>{C()},[C]);const z=U=>{U.preventDefault(),N(1),C()},H=async U=>{if(!S.has(U)){B(oe=>new Set(oe).add(U));try{const oe=await Tv(U,E);O(Ne=>{const je=new Set(Ne);return oe.liked?je.add(U):je.delete(U),je}),i(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=>{l({to:"/config/pack-market/$packId",params:{packId:U}})},J=Lm.find(U=>U.value===f)||Lm[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:z,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:x,onChange:U=>h(U.target.value),className:"pl-10"})]})}),e.jsxs(s3,{children:[e.jsx(t3,{asChild:!0,children:e.jsxs(_,{variant:"outline",className:"min-w-[140px] gap-2",children:[e.jsx(N_,{className:"w-4 h-4"}),J.label,e.jsx(Ma,{className:"w-4 h-4 ml-auto"})]})}),e.jsx(UN,{align:"end",children:Lm.map(U=>e.jsxs($N,{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:w})," 个模板"]}),c?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((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(ed,{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(d3,{pack:U,liked:R.has(U.id),liking:S.has(U.id),onLike:()=>H(U.id),onView:()=>L(U.id)},U.id))}),v>1&&e.jsx(Wm,{children:e.jsxs(ex,{children:[e.jsx(Fn,{children:e.jsx(mv,{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(Fn,{children:[je&&e.jsx("span",{className:"px-2",children:"..."}),e.jsx(uc,{onClick:()=>N(U),isActive:U===g,className:"cursor-pointer",children:U})]},U)}),e.jsx(Fn,{children:e.jsx(xv,{onClick:()=>N(U=>Math.min(v,U+1)),className:g===v?"pointer-events-none opacity-50":"cursor-pointer"})})]})})]})})]})}function d3({pack:l,liked:n,liking:i,onLike:c,onView:u}){const x=h=>new Date(h).toLocaleDateString("zh-CN",{year:"numeric",month:"short",day:"numeric"});return e.jsxs(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(Re,{className:"text-lg line-clamp-1",children:l.name}),e.jsxs(ke,{variant:"secondary",className:"text-xs",children:["v",l.version]})]}),e.jsx(os,{className:"line-clamp-2 min-h-[40px]",children:l.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(fn,{className:"w-3.5 h-3.5"}),l.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(na,{className:"w-3.5 h-3.5"}),x(l.created_at)]})]}),e.jsxs("div",{className:"flex gap-4 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"提供商数量",children:[e.jsx(Dl,{className:"w-3.5 h-3.5"}),l.provider_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"模型数量",children:[e.jsx(Vn,{className:"w-3.5 h-3.5"}),l.model_count]}),e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",title:"任务配置数",children:[e.jsx(qn,{className:"w-3.5 h-3.5"}),l.task_count]})]}),l.tags&&l.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[l.tags.slice(0,3).map(h=>e.jsxs(ke,{variant:"outline",className:"text-xs",children:[e.jsx(Wo,{className:"w-2.5 h-2.5 mr-1"}),h]},h)),l.tags.length>3&&e.jsxs(ke,{variant:"outline",className:"text-xs",children:["+",l.tags.length-3]})]})]}),e.jsx(ed,{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(sa,{className:"w-4 h-4"}),l.downloads]}),e.jsxs("button",{onClick:h=>{h.stopPropagation(),c()},disabled:i,className:`flex items-center gap-1 transition-colors ${n?"text-red-500":"hover:text-red-500"} ${i?"opacity-50":""}`,children:[e.jsx(qr,{className:`w-4 h-4 ${n?"fill-current":""}`}),l.likes]})]}),e.jsx(_,{size:"sm",onClick:u,children:"查看详情"})]})})]})}var sl="Accordion",u3=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[px,m3,x3]=Bw(sl),[dd]=Yo(sl,[x3,dj]),gx=dj(),BN=As.forwardRef((l,n)=>{const{type:i,...c}=l,u=c,x=c;return e.jsx(px.Provider,{scope:l.__scopeAccordion,children:i==="multiple"?e.jsx(g3,{...x,ref:n}):e.jsx(p3,{...u,ref:n})})});BN.displayName=sl;var[IN,h3]=dd(sl),[PN,f3]=dd(sl,{collapsible:!1}),p3=As.forwardRef((l,n)=>{const{value:i,defaultValue:c,onValueChange:u=()=>{},collapsible:x=!1,...h}=l,[f,p]=Qo({prop:i,defaultProp:c??"",onChange:u,caller:sl});return e.jsx(IN,{scope:l.__scopeAccordion,value:As.useMemo(()=>f?[f]:[],[f]),onItemOpen:p,onItemClose:As.useCallback(()=>x&&p(""),[x,p]),children:e.jsx(PN,{scope:l.__scopeAccordion,collapsible:x,children:e.jsx(HN,{...h,ref:n})})})}),g3=As.forwardRef((l,n)=>{const{value:i,defaultValue:c,onValueChange:u=()=>{},...x}=l,[h,f]=Qo({prop:i,defaultProp:c??[],onChange:u,caller:sl}),p=As.useCallback(N=>f((v=[])=>[...v,N]),[f]),g=As.useCallback(N=>f((v=[])=>v.filter(b=>b!==N)),[f]);return e.jsx(IN,{scope:l.__scopeAccordion,value:h,onItemOpen:p,onItemClose:g,children:e.jsx(PN,{scope:l.__scopeAccordion,collapsible:!0,children:e.jsx(HN,{...x,ref:n})})})}),[j3,ud]=dd(sl),HN=As.forwardRef((l,n)=>{const{__scopeAccordion:i,disabled:c,dir:u,orientation:x="vertical",...h}=l,f=As.useRef(null),p=Jo(f,n),g=m3(i),v=kj(u)==="ltr",b=hn(l.onKeyDown,w=>{if(!u3.includes(w.key))return;const y=w.target,R=g().filter(J=>!J.ref.current?.disabled),O=R.findIndex(J=>J.ref.current===y),S=R.length;if(O===-1)return;w.preventDefault();let B=O;const E=0,C=S-1,z=()=>{B=O+1,B>C&&(B=E)},H=()=>{B=O-1,B{const{__scopeAccordion:i,value:c,...u}=l,x=ud(Ko,i),h=h3(Ko,i),f=gx(i),p=Um(),g=c&&h.value.includes(c)||!1,N=x.disabled||l.disabled;return e.jsx(v3,{scope:i,open:g,disabled:N,triggerId:p,children:e.jsx(lj,{"data-orientation":x.orientation,"data-state":YN(g),...f,...u,ref:n,disabled:N,open:g,onOpenChange:v=>{v?h.onItemOpen(c):h.onItemClose(c)}})})});FN.displayName=Ko;var GN="AccordionHeader",VN=As.forwardRef((l,n)=>{const{__scopeAccordion:i,...c}=l,u=ud(sl,i),x=jx(GN,i);return e.jsx(Yn.h3,{"data-orientation":u.orientation,"data-state":YN(x.open),"data-disabled":x.disabled?"":void 0,...c,ref:n})});VN.displayName=GN;var Gm="AccordionTrigger",qN=As.forwardRef((l,n)=>{const{__scopeAccordion:i,...c}=l,u=ud(sl,i),x=jx(Gm,i),h=f3(Gm,i),f=gx(i);return e.jsx(px.ItemSlot,{scope:i,children:e.jsx(hw,{"aria-disabled":x.open&&!h.collapsible||void 0,"data-orientation":u.orientation,id:x.triggerId,...f,...c,ref:n})})});qN.displayName=Gm;var KN="AccordionContent",QN=As.forwardRef((l,n)=>{const{__scopeAccordion:i,...c}=l,u=ud(sl,i),x=jx(KN,i),h=gx(i);return e.jsx(fw,{role:"region","aria-labelledby":x.triggerId,"data-orientation":u.orientation,...h,...c,ref:n,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...l.style}})});QN.displayName=KN;function YN(l){return l?"open":"closed"}var N3=BN,b3=FN,y3=VN,JN=qN,XN=QN;const w3=N3,ZN=d.forwardRef(({className:l,...n},i)=>e.jsx(b3,{ref:i,className:P("border-b",l),...n}));ZN.displayName="AccordionItem";const WN=d.forwardRef(({className:l,children:n,...i},c)=>e.jsx(y3,{className:"flex",children:e.jsxs(JN,{ref:c,className:P("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",l),...i,children:[n,e.jsx(Ma,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));WN.displayName=JN.displayName;const eb=d.forwardRef(({className:l,children:n,...i},c)=>e.jsx(XN,{ref:c,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...i,children:e.jsx("div",{className:P("pb-4 pt-0",l),children:n})}));eb.displayName=XN.displayName;const _3={utils:"通用工具",utils_small:"轻量工具",tool_use:"工具调用",replyer:"回复生成",planner:"规划推理",vlm:"视觉模型",voice:"语音处理",embedding:"向量嵌入",lpmm_entity_extract:"实体提取",lpmm_rdf_build:"RDF构建",lpmm_qa:"问答模型"};function S3(){const{packId:l}=nb.useParams(),n=ca(),[i,c]=d.useState(null),[u,x]=d.useState(!0),[h,f]=d.useState(!1),[p,g]=d.useState(!1),[N,v]=d.useState(!1),[b,w]=d.useState(1),[y,R]=d.useState(null),[O,S]=d.useState(!1),[B,E]=d.useState(!1),[C,z]=d.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}),[H,L]=d.useState({}),[J,U]=d.useState({}),oe=Mv(),Ne=d.useCallback(async()=>{if(l){x(!0);try{const M=await xS(l);c(M);const K=await Ev(l,oe);f(K)}catch(M){console.error("加载 Pack 失败:",M),Qt({title:"加载模板失败",variant:"destructive"})}finally{x(!1)}}},[l,oe]);d.useEffect(()=>{Ne()},[Ne]);const je=async()=>{if(!(!l||p)){g(!0);try{const M=await Tv(l,oe);f(M.liked),i&&c({...i,likes:M.likes})}catch(M){console.error("点赞失败:",M),Qt({title:"点赞失败",variant:"destructive"})}finally{g(!1)}}},re=async()=>{if(i){v(!0),w(1),S(!0);try{const M=await pS(i);R(M);const K={};for(const ue of M.existing_providers)K[ue.pack_provider.name]=ue.local_providers[0].name;L(K);const I={};for(const ue of M.new_providers)I[ue.name]="";U(I)}catch(M){console.error("检测冲突失败:",M),Qt({title:"检测配置冲突失败",variant:"destructive"}),v(!1)}finally{S(!1)}}},fe=async()=>{if(i){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(i,C,H,J),await fS(i.id,oe),c({...i,downloads:i.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 u?e.jsx(C3,{}):i?e.jsx("div",{className:"h-[calc(100vh-4rem)] flex flex-col p-4 sm:p-6",children:e.jsx(Je,{className:"flex-1",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:()=>n({to:"/config/pack-market"}),className:"gap-2",children:[e.jsx(Ta,{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:[i.name,e.jsxs(ke,{variant:"secondary",children:["v",i.version]})]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:i.description})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(fn,{className:"w-4 h-4"}),i.author]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(na,{className:"w-4 h-4"}),ge(i.created_at)]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(sa,{className:"w-4 h-4"}),i.downloads," 次下载"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(qr,{className:`w-4 h-4 ${h?"fill-red-500 text-red-500":""}`}),i.likes," 赞"]})]}),i.tags&&i.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:i.tags.map(M=>e.jsxs(ke,{variant:"outline",children:[e.jsx(Wo,{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(sa,{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(qr,{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(Dl,{className:"w-8 h-8 text-blue-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:i.providers.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"API 提供商"})]})]})}),e.jsx(Ce,{children:e.jsxs(Me,{className:"flex items-center gap-3 py-4",children:[e.jsx(Vn,{className:"w-8 h-8 text-green-500 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:i.models.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"模型配置"})]})]})}),e.jsx(Ce,{children:e.jsxs(Me,{className:"flex items-center gap-3 py-4",children:[e.jsx(qn,{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(i.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(Xt,{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(Dl,{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:["(",i.providers.length,")"]})]}),e.jsxs(Xe,{value:"models",className:"gap-1 sm:gap-2",children:[e.jsx(Vn,{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:["(",i.models.length,")"]})]}),e.jsxs(Xe,{value:"tasks",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:["(",Object.keys(i.task_config).length,")"]})]})]}),e.jsx(ws,{value:"providers",children:e.jsxs(Ce,{children:[e.jsxs(De,{children:[e.jsx(Re,{children:"API 提供商"}),e.jsx(os,{children:"模板中包含的 API 提供商配置(不含 API Key)"})]}),e.jsx(Me,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Rl,{children:[e.jsx(Ll,{children:e.jsxs(ut,{children:[e.jsx(We,{children:"名称"}),e.jsx(We,{children:"Base URL"}),e.jsx(We,{children:"类型"})]})}),e.jsx(Ul,{children:i.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(Re,{children:"模型配置"}),e.jsx(os,{children:"模板中包含的模型配置"})]}),e.jsx(Me,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Rl,{children:[e.jsx(Ll,{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(Ul,{children:i.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(Re,{children:"任务配置"}),e.jsx(os,{children:"模板中各任务类型的模型分配"})]}),e.jsx(Me,{children:e.jsx(w3,{type:"multiple",className:"w-full",children:Object.entries(i.task_config).map(([M,K])=>e.jsxs(ZN,{value:M,children:[e.jsx(WN,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pn,{className:"w-4 h-4"}),_3[M]||M,e.jsxs(ke,{variant:"secondary",className:"ml-2",children:[K.model_list.length," 个模型"]})]})}),e.jsx(eb,{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(I=>e.jsx(ke,{variant:"outline",children:I},I))}),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(k3,{open:N,onOpenChange:v,pack:i,step:b,setStep:w,conflicts:y,detectingConflicts:O,applying:B,options:C,setOptions:z,_providerMapping:H,_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(Ta,{className:"w-4 h-4 mr-2"}),"返回市场"]})]})}function k3({open:l,onOpenChange:n,pack:i,step:c,setStep:u,conflicts:x,detectingConflicts:h,applying:f,options:p,setOptions:g,_providerMapping:N,_setProviderMapping:v,newProviderApiKeys:b,setNewProviderApiKeys:w,onApply:y}){return e.jsx(Is,{open:l,onOpenChange:n,children:e.jsxs(Os,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ds,{children:[e.jsxs(Rs,{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(Bs,{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:O=>g({...p,apply_providers:O})}),e.jsxs(T,{htmlFor:"apply_providers",className:"flex items-center gap-2",children:[e.jsx(Dl,{className:"w-4 h-4"}),"应用提供商配置 (",i.providers.length," 个)"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qs,{id:"apply_models",checked:p.apply_models,onCheckedChange:O=>g({...p,apply_models:O})}),e.jsxs(T,{htmlFor:"apply_models",className:"flex items-center gap-2",children:[e.jsx(Vn,{className:"w-4 h-4"}),"应用模型配置 (",i.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:O=>g({...p,apply_task_config:O})}),e.jsxs(T,{htmlFor:"apply_task_config",className:"flex items-center gap-2",children:[e.jsx(qn,{className:"w-4 h-4"}),"应用任务配置 (",Object.keys(i.task_config).length," 个)"]})]})]}),p.apply_task_config&&e.jsxs("div",{className:"pl-6 space-y-2 border-l-2 border-muted",children:[e.jsx(T,{className:"text-sm font-medium",children:"任务配置应用模式"}),e.jsxs(fx,{value:p.task_mode,onValueChange:O=>g({...p,task_mode:O}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qo,{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(qo,{value:"replace",id:"mode_replace"}),e.jsx(T,{htmlFor:"mode_replace",className:"font-normal",children:"替换模式 - 用模板配置完全替换现有配置"})]})]})]})]}),c===2&&x&&e.jsxs("div",{className:"space-y-4",children:[p.apply_providers&&x.existing_providers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(at,{children:[e.jsx(Ht,{className:"h-4 w-4"}),e.jsx(Hn,{children:"发现已有的提供商"}),e.jsx(lt,{children:"以下提供商的 URL 与您本地配置中的提供商匹配,将自动使用本地提供商:"})]}),e.jsx("div",{className:"space-y-2",children:x.existing_providers.map(({pack_provider:O,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:O.name}),e.jsx(Zt,{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[O.name]||S[0].name,onValueChange:B=>v({...N,[O.name]:B}),children:[e.jsx($e,{className:"w-[200px]",children:e.jsx(Pe,{})}),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," 个匹配"]})]})]},O.name))})]}),p.apply_providers&&x.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(Hn,{children:"需要配置 API Key"}),e.jsx(lt,{children:"以下提供商在您的本地配置中不存在,需要填写 API Key:"})]}),e.jsx("div",{className:"space-y-4",children:x.new_providers.map(O=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qm,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"font-medium",children:O.name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",O.base_url,")"]})]}),e.jsx(ae,{type:"password",placeholder:`输入 ${O.name} 的 API Key`,value:b[O.name]||"",onChange:S=>w({...b,[O.name]:S.target.value})})]},O.name))})]}),(!p.apply_providers||x.existing_providers.length===0&&x.new_providers.length===0)&&e.jsxs(at,{children:[e.jsx(Ct,{className:"h-4 w-4"}),e.jsx(Hn,{children:"无需配置"}),e.jsx(lt,{children:"模板中没有提供商配置,或您选择不应用提供商。"})]})]}),c===3&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(at,{children:[e.jsx(Ht,{className:"h-4 w-4"}),e.jsx(Hn,{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(Dl,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",i.providers.length," 个提供商配置"]})]}),p.apply_models&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500"}),e.jsx(Vn,{className:"w-4 h-4"}),e.jsxs("span",{children:["应用 ",i.models.length," 个模型配置"]})]}),p.apply_task_config&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ct,{className:"w-4 h-4 text-green-500"}),e.jsx(qn,{className:"w-4 h-4"}),e.jsxs("span",{children:[p.task_mode==="append"?"追加":"替换"," ",Object.keys(i.task_config).length," 个任务配置"]})]})]}),x&&x.new_providers.length>0&&e.jsxs(at,{variant:"destructive",children:[e.jsx(Jt,{className:"h-4 w-4"}),e.jsxs(lt,{children:["将添加 ",x.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:()=>u(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:()=>u(c+1),disabled:h,children:"下一步"}):e.jsxs(_,{onClick:y,disabled:f,children:[f&&e.jsx(Bs,{className:"w-4 h-4 mr-2 animate-spin"}),"应用模板"]})]})]})]})})}function C3(){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 T3(){const l=ca(),[n,i]=d.useState(!0);return d.useEffect(()=>{let c=!1;return(async()=>{try{const x=await ac();!c&&!x&&l({to:"/auth"})}catch{c||l({to:"/auth"})}finally{c||i(!1)}})(),()=>{c=!0}},[l]),{checking:n}}async function E3(){return await ac()}const M3=Qr("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"}}),sb=d.forwardRef(({className:l,size:n,abbrTitle:i,children:c,...u},x)=>e.jsx("kbd",{className:P(M3({size:n,className:l})),ref:x,...u,children:i?e.jsx("abbr",{title:i,children:c}):c}));sb.displayName="Kbd";const z3=[{icon:Zo,title:"首页",description:"查看仪表板概览",path:"/",category:"概览"},{icon:Ca,title:"麦麦主程序配置",description:"配置麦麦的核心设置",path:"/config/bot",category:"配置"},{icon:Dl,title:"麦麦模型提供商配置",description:"配置模型提供商",path:"/config/modelProvider",category:"配置"},{icon:Vj,title:"麦麦模型配置",description:"配置模型参数",path:"/config/model",category:"配置"},{icon:Xo,title:"表情包管理",description:"管理麦麦的表情包",path:"/resource/emoji",category:"资源"},{icon:za,title:"表达方式管理",description:"管理麦麦的表达方式",path:"/resource/expression",category:"资源"},{icon:qj,title:"人物信息管理",description:"管理人物信息",path:"/resource/person",category:"资源"},{icon:Vr,title:"黑话管理",description:"管理麦麦学习到的黑话和俚语",path:"/resource/jargon",category:"资源"},{icon:b_,title:"统计信息",description:"查看使用统计",path:"/statistics",category:"监控"},{icon:ra,title:"插件市场",description:"浏览和安装插件",path:"/plugins",category:"扩展"},{icon:Ym,title:"日志查看器",description:"查看系统日志",path:"/logs",category:"监控"},{icon:pn,title:"系统设置",description:"配置系统参数",path:"/settings",category:"系统"}];function A3({open:l,onOpenChange:n}){const[i,c]=d.useState(""),[u,x]=d.useState(0),h=ca(),f=z3.filter(N=>N.title.toLowerCase().includes(i.toLowerCase())||N.description.toLowerCase().includes(i.toLowerCase())||N.category.toLowerCase().includes(i.toLowerCase())),p=d.useCallback(N=>{h({to:N}),n(!1),c(""),x(0)},[h,n]),g=d.useCallback(N=>{N.key==="ArrowDown"?(N.preventDefault(),x(v=>(v+1)%f.length)):N.key==="ArrowUp"?(N.preventDefault(),x(v=>(v-1+f.length)%f.length)):N.key==="Enter"&&f[u]&&(N.preventDefault(),p(f[u].path))},[f,u,p]);return e.jsx(Is,{open:l,onOpenChange:n,children:e.jsxs(Os,{className:"max-w-2xl p-0 gap-0",children:[e.jsxs(Ds,{className:"px-4 pt-4 pb-0",children:[e.jsx(Rs,{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:i,onChange:N=>{c(N.target.value),x(0)},onKeyDown:g,placeholder:"搜索页面...",className:"h-12 pl-11 text-base border-0 focus-visible:ring-0 shadow-none",autoFocus:!0})]})]}),e.jsx("div",{className:"border-t",children:e.jsx(Je,{className:"h-[400px]",children:f.length>0?e.jsx("div",{className:"p-2",children:f.map((N,v)=>{const b=N.icon;return e.jsxs("button",{onClick:()=>p(N.path),onMouseEnter:()=>x(v),className:P("w-full flex items-center gap-3 px-3 py-2.5 rounded-md text-left transition-colors",v===u?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[e.jsx(b,{className:"h-5 w-5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children: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:i?"未找到匹配的页面":"输入关键词开始搜索"})]})})}),e.jsx("div",{className:"border-t px-4 py-3 flex items-center justify-between text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↑"}),e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"↓"}),"导航"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Enter"}),"选择"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("kbd",{className:"px-1.5 py-0.5 bg-muted rounded border",children:"Esc"}),"关闭"]})]})})]})})}function O3(){const l=window.location.protocol==="http:",n=window.location.hostname.toLowerCase(),i=n==="localhost"||n==="127.0.0.1"||n==="::1",c=sessionStorage.getItem("http-warning-dismissed")==="true",[u,x]=d.useState(l&&!i&&!c),[h,f]=d.useState(!1),p=()=>{f(!0),x(!1),sessionStorage.setItem("http-warning-dismissed","true")};return!u||h?null:e.jsx("div",{className:"relative bg-amber-500/10 border-b border-amber-500/20 backdrop-blur-sm",children:e.jsx("div",{className:"container mx-auto px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsx(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(Ea,{className:"h-4 w-4"})})]})})})}function D3(){const[l,n]=d.useState(0),[i,c]=d.useState(!1),u=d.useRef(null);d.useEffect(()=>{const g=N=>{const v=N.target;if(v.scrollHeight>v.clientHeight+100){u.current=v;const b=v.scrollTop,w=v.scrollHeight-v.clientHeight,y=w>0?b/w*100:0;n(y),c(b>300)}};return window.addEventListener("scroll",g,{capture:!0,passive:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})},[]);const x=()=>{u.current?.scrollTo({top:0,behavior:"smooth"})},h=18,f=2*Math.PI*h,p=f-l/100*f;return e.jsx("div",{className:P("fixed bottom-24 right-8 z-50 transition-all duration-500 ease-in-out transform",i?"translate-x-0 opacity-100":"translate-x-32 opacity-0 pointer-events-none"),children:e.jsxs(_,{variant:"outline",size:"icon",className:P("relative h-12 w-12 rounded-full shadow-xl","bg-background/80 backdrop-blur-md border-border/50","hover:bg-accent hover:scale-110 hover:shadow-2xl hover:border-primary/50","transition-all duration-300","group"),onClick:x,"aria-label":"回到顶部",children:[e.jsxs("svg",{className:"absolute inset-0 h-full w-full -rotate-90 transform p-1",viewBox:"0 0 44 44",children:[e.jsx("circle",{className:"text-muted-foreground/10",strokeWidth:"3",stroke:"currentColor",fill:"transparent",r:h,cx:"22",cy:"22"}),e.jsx("circle",{className:"text-primary transition-all duration-100 ease-out",strokeWidth:"3",strokeDasharray:f,strokeDashoffset:p,strokeLinecap:"round",stroke:"currentColor",fill:"transparent",r:h,cx:"22",cy:"22"})]}),e.jsx(y_,{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 R3=Pw,L3=Hw,U3=Fw,tb=d.forwardRef(({className:l,sideOffset:n=4,...i},c)=>e.jsx(Iw,{children:e.jsx(Cj,{ref:c,sideOffset:n,className:P("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",l),...i})}));tb.displayName=Cj.displayName;function $3({children:l}){const{checking:n}=T3(),[i,c]=d.useState(!0),[u,x]=d.useState(!1),[h,f]=d.useState(!1),[p,g]=d.useState(!1),{theme:N,setTheme:v}=ax(),b=w0();if(d.useEffect(()=>{if(i)g(!1);else{const S=setTimeout(()=>{g(!0)},350);return()=>clearTimeout(S)}},[i]),d.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 w=[{title:"概览",items:[{icon:Zo,label:"首页",path:"/"}]},{title:"麦麦配置编辑",items:[{icon:Ca,label:"麦麦主程序配置",path:"/config/bot"},{icon:Dl,label:"AI模型厂商配置",path:"/config/modelProvider",tourId:"sidebar-model-provider"},{icon:Vj,label:"模型管理与分配",path:"/config/model",tourId:"sidebar-model-management"},{icon:mg,label:"麦麦适配器配置",path:"/config/adapter"}]},{title:"麦麦资源管理",items:[{icon:Xo,label:"表情包管理",path:"/resource/emoji"},{icon:za,label:"表达方式管理",path:"/resource/expression"},{icon:Vr,label:"黑话管理",path:"/resource/jargon"},{icon:qj,label:"人物信息管理",path:"/resource/person"},{icon:Pj,label:"知识库图谱可视化",path:"/resource/knowledge-graph"},{icon:Gr,label:"麦麦知识库管理",path:"/resource/knowledge-base"}]},{title:"扩展与监控",items:[{icon:ra,label:"插件市场",path:"/plugins"},{icon:Fj,label:"配置模板市场",path:"/config/pack-market"},{icon:mg,label:"插件配置",path:"/plugin-config"},{icon:Ym,label:"日志查看器",path:"/logs"},{icon:Vm,label:"计划器&回复器监控",path:"/planner-monitor"},{icon:za,label:"本地聊天室",path:"/chat"}]},{title:"系统",items:[{icon:pn,label:"系统设置",path:"/settings"}]}],R=N==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":N,O=async()=>{await l1()};return e.jsx(R3,{delayDuration:300,children:e.jsxs("div",{className:"flex h-screen overflow-hidden",children:[e.jsxs("aside",{className:P("fixed inset-y-0 left-0 z-50 flex flex-col border-r bg-card transition-all duration-300 lg:relative lg:z-0","w-64 lg:w-auto",i?"lg:w-64":"lg:w-16",u?"translate-x-0":"-translate-x-full lg:translate-x-0"),children:[e.jsx("div",{className:"flex h-16 items-center border-b px-4",children:e.jsxs("div",{className:P("relative flex items-center justify-center flex-1 transition-all overflow-hidden","lg:flex-1",!i&&"lg:flex-none lg:w-8"),children:[e.jsxs("div",{className:P("flex items-baseline gap-2",!i&&"lg:hidden"),children:[e.jsx("span",{className:"font-bold text-xl text-primary-gradient whitespace-nowrap",children:"MaiBot WebUI"}),e.jsx("span",{className:"text-xs text-primary/60 whitespace-nowrap",children:B1()})]}),!i&&e.jsx("span",{className:"hidden lg:block font-bold text-primary-gradient text-2xl",children:"M"})]})}),e.jsx(Je,{className:P("flex-1 overflow-x-hidden",!i&&"lg:w-16"),children:e.jsx("nav",{className:P("p-4",!i&&"lg:p-2 lg:w-16"),children:e.jsx("ul",{className:P("space-y-6",!i&&"lg:space-y-3 lg:w-full"),children:w.map((S,B)=>e.jsxs("li",{children:[e.jsx("div",{className:P("px-3 h-[1.25rem]","mb-2",!i&&"lg:mb-1 lg:invisible"),children:e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground/60 whitespace-nowrap",children:S.title})}),!i&&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=b({to:E.path}),z=E.icon,H=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:P("flex items-center transition-all duration-300",i?"gap-3":"gap-3 lg:gap-0"),children:[e.jsx(z,{className:P("h-5 w-5 flex-shrink-0",C&&"text-primary"),strokeWidth:2,fill:"none"}),e.jsx("span",{className:P("text-sm font-medium whitespace-nowrap transition-all duration-300",C&&"font-semibold",i?"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(L3,{children:[e.jsx(U3,{asChild:!0,children:e.jsx(Bn,{to:E.path,"data-tour":E.tourId,className:P("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",i?"px-3":"px-3 lg:px-0 lg:justify-center lg:w-12 lg:mx-auto"),onClick:()=>x(!1),children:H})}),p&&e.jsx(tb,{side:"right",className:"hidden lg:block",children:e.jsx("p",{children:E.label})})]})},E.path)})})]},S.title))})})})]}),u&&e.jsx("div",{className:"fixed inset-0 z-40 bg-black/50 lg:hidden",onClick:()=>x(!1)}),e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx(O3,{}),e.jsxs("header",{className:"flex h-16 items-center justify-between border-b bg-card/80 backdrop-blur-md px-4 sticky top-0 z-10",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:()=>x(!u),className:"rounded-lg p-2 hover:bg-accent lg:hidden",children:e.jsx(w_,{className:"h-5 w-5"})}),e.jsx("button",{onClick:()=>c(!i),className:"hidden rounded-lg p-2 hover:bg-accent lg:block",title:i?"收起侧边栏":"展开侧边栏",children:e.jsx(Aa,{className:P("h-5 w-5 transition-transform",!i&&"rotate-180")})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Bn,{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(__,{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(sb,{size:"sm",className:"absolute right-2 top-1/2 -translate-y-1/2",children:[e.jsx("span",{className:"text-xs",children:"⌘"}),"K"]})]}),e.jsx(A3,{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(S_,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"麦麦文档"})]}),e.jsx("button",{onClick:S=>{D1(R==="dark"?"light":"dark",v,S)},className:"rounded-lg p-2 hover:bg-accent",title:R==="dark"?"切换到浅色模式":"切换到深色模式",children:R==="dark"?e.jsx(Km,{className:"h-5 w-5"}):e.jsx(Yi,{className:"h-5 w-5"})}),e.jsx("div",{className:"h-6 w-px bg-border"}),e.jsxs(_,{variant:"ghost",size:"sm",onClick:O,className:"gap-2",title:"登出系统",children:[e.jsx(k_,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"登出"})]})]})]}),e.jsx("main",{className:"flex-1 overflow-hidden bg-background",children:l}),e.jsx(D3,{})]})]})})}function B3(l){const n=l.split(` `).slice(1),i=[];for(const c of n){const u=c.trim();if(!u.startsWith("at "))continue;const x=u.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);x?i.push({functionName:x[1]||"",fileName:x[2],lineNumber:x[3],columnNumber:x[4],raw:u}):i.push({functionName:"",fileName:"",lineNumber:"",columnNumber:"",raw:u})}return i}function I3({error:l,errorInfo:n}){const[i,c]=d.useState(!0),[u,x]=d.useState(!1),[h,f]=d.useState(!1),p=l.stack?B3(l.stack):[],g=async()=>{const N=` Error: ${l.name} Message: ${l.message} diff --git a/webui/dist/index.html b/webui/dist/index.html index c2f00b81..64400b26 100644 --- a/webui/dist/index.html +++ b/webui/dist/index.html @@ -11,7 +11,7 @@ MaiBot Dashboard - +